qib_mad.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542
  1. /*
  2. * Copyright (c) 2012 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
  4. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <rdma/ib_smi.h>
  35. #include "qib.h"
  36. #include "qib_mad.h"
  37. static int reply(struct ib_smp *smp)
  38. {
  39. /*
  40. * The verbs framework will handle the directed/LID route
  41. * packet changes.
  42. */
  43. smp->method = IB_MGMT_METHOD_GET_RESP;
  44. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  45. smp->status |= IB_SMP_DIRECTION;
  46. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  47. }
  48. static int reply_failure(struct ib_smp *smp)
  49. {
  50. /*
  51. * The verbs framework will handle the directed/LID route
  52. * packet changes.
  53. */
  54. smp->method = IB_MGMT_METHOD_GET_RESP;
  55. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  56. smp->status |= IB_SMP_DIRECTION;
  57. return IB_MAD_RESULT_FAILURE | IB_MAD_RESULT_REPLY;
  58. }
  59. static void qib_send_trap(struct qib_ibport *ibp, void *data, unsigned len)
  60. {
  61. struct ib_mad_send_buf *send_buf;
  62. struct ib_mad_agent *agent;
  63. struct ib_smp *smp;
  64. int ret;
  65. unsigned long flags;
  66. unsigned long timeout;
  67. agent = ibp->send_agent;
  68. if (!agent)
  69. return;
  70. /* o14-3.2.1 */
  71. if (!(ppd_from_ibp(ibp)->lflags & QIBL_LINKACTIVE))
  72. return;
  73. /* o14-2 */
  74. if (ibp->trap_timeout && time_before(jiffies, ibp->trap_timeout))
  75. return;
  76. send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
  77. IB_MGMT_MAD_DATA, GFP_ATOMIC,
  78. IB_MGMT_BASE_VERSION);
  79. if (IS_ERR(send_buf))
  80. return;
  81. smp = send_buf->mad;
  82. smp->base_version = IB_MGMT_BASE_VERSION;
  83. smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  84. smp->class_version = 1;
  85. smp->method = IB_MGMT_METHOD_TRAP;
  86. ibp->tid++;
  87. smp->tid = cpu_to_be64(ibp->tid);
  88. smp->attr_id = IB_SMP_ATTR_NOTICE;
  89. /* o14-1: smp->mkey = 0; */
  90. memcpy(smp->data, data, len);
  91. spin_lock_irqsave(&ibp->lock, flags);
  92. if (!ibp->sm_ah) {
  93. if (ibp->sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
  94. struct ib_ah *ah;
  95. ah = qib_create_qp0_ah(ibp, ibp->sm_lid);
  96. if (IS_ERR(ah))
  97. ret = PTR_ERR(ah);
  98. else {
  99. send_buf->ah = ah;
  100. ibp->sm_ah = to_iah(ah);
  101. ret = 0;
  102. }
  103. } else
  104. ret = -EINVAL;
  105. } else {
  106. send_buf->ah = &ibp->sm_ah->ibah;
  107. ret = 0;
  108. }
  109. spin_unlock_irqrestore(&ibp->lock, flags);
  110. if (!ret)
  111. ret = ib_post_send_mad(send_buf, NULL);
  112. if (!ret) {
  113. /* 4.096 usec. */
  114. timeout = (4096 * (1UL << ibp->subnet_timeout)) / 1000;
  115. ibp->trap_timeout = jiffies + usecs_to_jiffies(timeout);
  116. } else {
  117. ib_free_send_mad(send_buf);
  118. ibp->trap_timeout = 0;
  119. }
  120. }
  121. /*
  122. * Send a bad [PQ]_Key trap (ch. 14.3.8).
  123. */
  124. void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
  125. u32 qp1, u32 qp2, __be16 lid1, __be16 lid2)
  126. {
  127. struct ib_mad_notice_attr data;
  128. if (trap_num == IB_NOTICE_TRAP_BAD_PKEY)
  129. ibp->pkey_violations++;
  130. else
  131. ibp->qkey_violations++;
  132. ibp->n_pkt_drops++;
  133. /* Send violation trap */
  134. data.generic_type = IB_NOTICE_TYPE_SECURITY;
  135. data.prod_type_msb = 0;
  136. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  137. data.trap_num = trap_num;
  138. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  139. data.toggle_count = 0;
  140. memset(&data.details, 0, sizeof(data.details));
  141. data.details.ntc_257_258.lid1 = lid1;
  142. data.details.ntc_257_258.lid2 = lid2;
  143. data.details.ntc_257_258.key = cpu_to_be32(key);
  144. data.details.ntc_257_258.sl_qp1 = cpu_to_be32((sl << 28) | qp1);
  145. data.details.ntc_257_258.qp2 = cpu_to_be32(qp2);
  146. qib_send_trap(ibp, &data, sizeof(data));
  147. }
  148. /*
  149. * Send a bad M_Key trap (ch. 14.3.9).
  150. */
  151. static void qib_bad_mkey(struct qib_ibport *ibp, struct ib_smp *smp)
  152. {
  153. struct ib_mad_notice_attr data;
  154. /* Send violation trap */
  155. data.generic_type = IB_NOTICE_TYPE_SECURITY;
  156. data.prod_type_msb = 0;
  157. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  158. data.trap_num = IB_NOTICE_TRAP_BAD_MKEY;
  159. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  160. data.toggle_count = 0;
  161. memset(&data.details, 0, sizeof(data.details));
  162. data.details.ntc_256.lid = data.issuer_lid;
  163. data.details.ntc_256.method = smp->method;
  164. data.details.ntc_256.attr_id = smp->attr_id;
  165. data.details.ntc_256.attr_mod = smp->attr_mod;
  166. data.details.ntc_256.mkey = smp->mkey;
  167. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
  168. u8 hop_cnt;
  169. data.details.ntc_256.dr_slid = smp->dr_slid;
  170. data.details.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE;
  171. hop_cnt = smp->hop_cnt;
  172. if (hop_cnt > ARRAY_SIZE(data.details.ntc_256.dr_rtn_path)) {
  173. data.details.ntc_256.dr_trunc_hop |=
  174. IB_NOTICE_TRAP_DR_TRUNC;
  175. hop_cnt = ARRAY_SIZE(data.details.ntc_256.dr_rtn_path);
  176. }
  177. data.details.ntc_256.dr_trunc_hop |= hop_cnt;
  178. memcpy(data.details.ntc_256.dr_rtn_path, smp->return_path,
  179. hop_cnt);
  180. }
  181. qib_send_trap(ibp, &data, sizeof(data));
  182. }
  183. /*
  184. * Send a Port Capability Mask Changed trap (ch. 14.3.11).
  185. */
  186. void qib_cap_mask_chg(struct qib_ibport *ibp)
  187. {
  188. struct ib_mad_notice_attr data;
  189. data.generic_type = IB_NOTICE_TYPE_INFO;
  190. data.prod_type_msb = 0;
  191. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  192. data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG;
  193. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  194. data.toggle_count = 0;
  195. memset(&data.details, 0, sizeof(data.details));
  196. data.details.ntc_144.lid = data.issuer_lid;
  197. data.details.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags);
  198. qib_send_trap(ibp, &data, sizeof(data));
  199. }
  200. /*
  201. * Send a System Image GUID Changed trap (ch. 14.3.12).
  202. */
  203. void qib_sys_guid_chg(struct qib_ibport *ibp)
  204. {
  205. struct ib_mad_notice_attr data;
  206. data.generic_type = IB_NOTICE_TYPE_INFO;
  207. data.prod_type_msb = 0;
  208. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  209. data.trap_num = IB_NOTICE_TRAP_SYS_GUID_CHG;
  210. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  211. data.toggle_count = 0;
  212. memset(&data.details, 0, sizeof(data.details));
  213. data.details.ntc_145.lid = data.issuer_lid;
  214. data.details.ntc_145.new_sys_guid = ib_qib_sys_image_guid;
  215. qib_send_trap(ibp, &data, sizeof(data));
  216. }
  217. /*
  218. * Send a Node Description Changed trap (ch. 14.3.13).
  219. */
  220. void qib_node_desc_chg(struct qib_ibport *ibp)
  221. {
  222. struct ib_mad_notice_attr data;
  223. data.generic_type = IB_NOTICE_TYPE_INFO;
  224. data.prod_type_msb = 0;
  225. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  226. data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG;
  227. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  228. data.toggle_count = 0;
  229. memset(&data.details, 0, sizeof(data.details));
  230. data.details.ntc_144.lid = data.issuer_lid;
  231. data.details.ntc_144.local_changes = 1;
  232. data.details.ntc_144.change_flags = IB_NOTICE_TRAP_NODE_DESC_CHG;
  233. qib_send_trap(ibp, &data, sizeof(data));
  234. }
  235. static int subn_get_nodedescription(struct ib_smp *smp,
  236. struct ib_device *ibdev)
  237. {
  238. if (smp->attr_mod)
  239. smp->status |= IB_SMP_INVALID_FIELD;
  240. memcpy(smp->data, ibdev->node_desc, sizeof(smp->data));
  241. return reply(smp);
  242. }
  243. static int subn_get_nodeinfo(struct ib_smp *smp, struct ib_device *ibdev,
  244. u8 port)
  245. {
  246. struct ib_node_info *nip = (struct ib_node_info *)&smp->data;
  247. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  248. u32 vendor, majrev, minrev;
  249. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  250. /* GUID 0 is illegal */
  251. if (smp->attr_mod || pidx >= dd->num_pports ||
  252. dd->pport[pidx].guid == 0)
  253. smp->status |= IB_SMP_INVALID_FIELD;
  254. else
  255. nip->port_guid = dd->pport[pidx].guid;
  256. nip->base_version = 1;
  257. nip->class_version = 1;
  258. nip->node_type = 1; /* channel adapter */
  259. nip->num_ports = ibdev->phys_port_cnt;
  260. /* This is already in network order */
  261. nip->sys_guid = ib_qib_sys_image_guid;
  262. nip->node_guid = dd->pport->guid; /* Use first-port GUID as node */
  263. nip->partition_cap = cpu_to_be16(qib_get_npkeys(dd));
  264. nip->device_id = cpu_to_be16(dd->deviceid);
  265. majrev = dd->majrev;
  266. minrev = dd->minrev;
  267. nip->revision = cpu_to_be32((majrev << 16) | minrev);
  268. nip->local_port_num = port;
  269. vendor = dd->vendorid;
  270. nip->vendor_id[0] = QIB_SRC_OUI_1;
  271. nip->vendor_id[1] = QIB_SRC_OUI_2;
  272. nip->vendor_id[2] = QIB_SRC_OUI_3;
  273. return reply(smp);
  274. }
  275. static int subn_get_guidinfo(struct ib_smp *smp, struct ib_device *ibdev,
  276. u8 port)
  277. {
  278. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  279. u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
  280. __be64 *p = (__be64 *) smp->data;
  281. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  282. /* 32 blocks of 8 64-bit GUIDs per block */
  283. memset(smp->data, 0, sizeof(smp->data));
  284. if (startgx == 0 && pidx < dd->num_pports) {
  285. struct qib_pportdata *ppd = dd->pport + pidx;
  286. struct qib_ibport *ibp = &ppd->ibport_data;
  287. __be64 g = ppd->guid;
  288. unsigned i;
  289. /* GUID 0 is illegal */
  290. if (g == 0)
  291. smp->status |= IB_SMP_INVALID_FIELD;
  292. else {
  293. /* The first is a copy of the read-only HW GUID. */
  294. p[0] = g;
  295. for (i = 1; i < QIB_GUIDS_PER_PORT; i++)
  296. p[i] = ibp->guids[i - 1];
  297. }
  298. } else
  299. smp->status |= IB_SMP_INVALID_FIELD;
  300. return reply(smp);
  301. }
  302. static void set_link_width_enabled(struct qib_pportdata *ppd, u32 w)
  303. {
  304. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LWID_ENB, w);
  305. }
  306. static void set_link_speed_enabled(struct qib_pportdata *ppd, u32 s)
  307. {
  308. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_SPD_ENB, s);
  309. }
  310. static int get_overrunthreshold(struct qib_pportdata *ppd)
  311. {
  312. return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH);
  313. }
  314. /**
  315. * set_overrunthreshold - set the overrun threshold
  316. * @ppd: the physical port data
  317. * @n: the new threshold
  318. *
  319. * Note that this will only take effect when the link state changes.
  320. */
  321. static int set_overrunthreshold(struct qib_pportdata *ppd, unsigned n)
  322. {
  323. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH,
  324. (u32)n);
  325. return 0;
  326. }
  327. static int get_phyerrthreshold(struct qib_pportdata *ppd)
  328. {
  329. return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH);
  330. }
  331. /**
  332. * set_phyerrthreshold - set the physical error threshold
  333. * @ppd: the physical port data
  334. * @n: the new threshold
  335. *
  336. * Note that this will only take effect when the link state changes.
  337. */
  338. static int set_phyerrthreshold(struct qib_pportdata *ppd, unsigned n)
  339. {
  340. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH,
  341. (u32)n);
  342. return 0;
  343. }
  344. /**
  345. * get_linkdowndefaultstate - get the default linkdown state
  346. * @ppd: the physical port data
  347. *
  348. * Returns zero if the default is POLL, 1 if the default is SLEEP.
  349. */
  350. static int get_linkdowndefaultstate(struct qib_pportdata *ppd)
  351. {
  352. return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT) ==
  353. IB_LINKINITCMD_SLEEP;
  354. }
  355. static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags)
  356. {
  357. int valid_mkey = 0;
  358. int ret = 0;
  359. /* Is the mkey in the process of expiring? */
  360. if (ibp->mkey_lease_timeout &&
  361. time_after_eq(jiffies, ibp->mkey_lease_timeout)) {
  362. /* Clear timeout and mkey protection field. */
  363. ibp->mkey_lease_timeout = 0;
  364. ibp->mkeyprot = 0;
  365. }
  366. if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->mkey == 0 ||
  367. ibp->mkey == smp->mkey)
  368. valid_mkey = 1;
  369. /* Unset lease timeout on any valid Get/Set/TrapRepress */
  370. if (valid_mkey && ibp->mkey_lease_timeout &&
  371. (smp->method == IB_MGMT_METHOD_GET ||
  372. smp->method == IB_MGMT_METHOD_SET ||
  373. smp->method == IB_MGMT_METHOD_TRAP_REPRESS))
  374. ibp->mkey_lease_timeout = 0;
  375. if (!valid_mkey) {
  376. switch (smp->method) {
  377. case IB_MGMT_METHOD_GET:
  378. /* Bad mkey not a violation below level 2 */
  379. if (ibp->mkeyprot < 2)
  380. break;
  381. case IB_MGMT_METHOD_SET:
  382. case IB_MGMT_METHOD_TRAP_REPRESS:
  383. if (ibp->mkey_violations != 0xFFFF)
  384. ++ibp->mkey_violations;
  385. if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period)
  386. ibp->mkey_lease_timeout = jiffies +
  387. ibp->mkey_lease_period * HZ;
  388. /* Generate a trap notice. */
  389. qib_bad_mkey(ibp, smp);
  390. ret = 1;
  391. }
  392. }
  393. return ret;
  394. }
  395. static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
  396. u8 port)
  397. {
  398. struct qib_devdata *dd;
  399. struct qib_pportdata *ppd;
  400. struct qib_ibport *ibp;
  401. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  402. u8 mtu;
  403. int ret;
  404. u32 state;
  405. u32 port_num = be32_to_cpu(smp->attr_mod);
  406. if (port_num == 0)
  407. port_num = port;
  408. else {
  409. if (port_num > ibdev->phys_port_cnt) {
  410. smp->status |= IB_SMP_INVALID_FIELD;
  411. ret = reply(smp);
  412. goto bail;
  413. }
  414. if (port_num != port) {
  415. ibp = to_iport(ibdev, port_num);
  416. ret = check_mkey(ibp, smp, 0);
  417. if (ret) {
  418. ret = IB_MAD_RESULT_FAILURE;
  419. goto bail;
  420. }
  421. }
  422. }
  423. dd = dd_from_ibdev(ibdev);
  424. /* IB numbers ports from 1, hdw from 0 */
  425. ppd = dd->pport + (port_num - 1);
  426. ibp = &ppd->ibport_data;
  427. /* Clear all fields. Only set the non-zero fields. */
  428. memset(smp->data, 0, sizeof(smp->data));
  429. /* Only return the mkey if the protection field allows it. */
  430. if (!(smp->method == IB_MGMT_METHOD_GET &&
  431. ibp->mkey != smp->mkey &&
  432. ibp->mkeyprot == 1))
  433. pip->mkey = ibp->mkey;
  434. pip->gid_prefix = ibp->gid_prefix;
  435. pip->lid = cpu_to_be16(ppd->lid);
  436. pip->sm_lid = cpu_to_be16(ibp->sm_lid);
  437. pip->cap_mask = cpu_to_be32(ibp->port_cap_flags);
  438. /* pip->diag_code; */
  439. pip->mkey_lease_period = cpu_to_be16(ibp->mkey_lease_period);
  440. pip->local_port_num = port;
  441. pip->link_width_enabled = ppd->link_width_enabled;
  442. pip->link_width_supported = ppd->link_width_supported;
  443. pip->link_width_active = ppd->link_width_active;
  444. state = dd->f_iblink_state(ppd->lastibcstat);
  445. pip->linkspeed_portstate = ppd->link_speed_supported << 4 | state;
  446. pip->portphysstate_linkdown =
  447. (dd->f_ibphys_portstate(ppd->lastibcstat) << 4) |
  448. (get_linkdowndefaultstate(ppd) ? 1 : 2);
  449. pip->mkeyprot_resv_lmc = (ibp->mkeyprot << 6) | ppd->lmc;
  450. pip->linkspeedactive_enabled = (ppd->link_speed_active << 4) |
  451. ppd->link_speed_enabled;
  452. switch (ppd->ibmtu) {
  453. default: /* something is wrong; fall through */
  454. case 4096:
  455. mtu = IB_MTU_4096;
  456. break;
  457. case 2048:
  458. mtu = IB_MTU_2048;
  459. break;
  460. case 1024:
  461. mtu = IB_MTU_1024;
  462. break;
  463. case 512:
  464. mtu = IB_MTU_512;
  465. break;
  466. case 256:
  467. mtu = IB_MTU_256;
  468. break;
  469. }
  470. pip->neighbormtu_mastersmsl = (mtu << 4) | ibp->sm_sl;
  471. pip->vlcap_inittype = ppd->vls_supported << 4; /* InitType = 0 */
  472. pip->vl_high_limit = ibp->vl_high_limit;
  473. pip->vl_arb_high_cap =
  474. dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_CAP);
  475. pip->vl_arb_low_cap =
  476. dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_LOW_CAP);
  477. /* InitTypeReply = 0 */
  478. pip->inittypereply_mtucap = qib_ibmtu ? qib_ibmtu : IB_MTU_4096;
  479. /* HCAs ignore VLStallCount and HOQLife */
  480. /* pip->vlstallcnt_hoqlife; */
  481. pip->operationalvl_pei_peo_fpi_fpo =
  482. dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OP_VLS) << 4;
  483. pip->mkey_violations = cpu_to_be16(ibp->mkey_violations);
  484. /* P_KeyViolations are counted by hardware. */
  485. pip->pkey_violations = cpu_to_be16(ibp->pkey_violations);
  486. pip->qkey_violations = cpu_to_be16(ibp->qkey_violations);
  487. /* Only the hardware GUID is supported for now */
  488. pip->guid_cap = QIB_GUIDS_PER_PORT;
  489. pip->clientrereg_resv_subnetto = ibp->subnet_timeout;
  490. /* 32.768 usec. response time (guessing) */
  491. pip->resv_resptimevalue = 3;
  492. pip->localphyerrors_overrunerrors =
  493. (get_phyerrthreshold(ppd) << 4) |
  494. get_overrunthreshold(ppd);
  495. /* pip->max_credit_hint; */
  496. if (ibp->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
  497. u32 v;
  498. v = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKLATENCY);
  499. pip->link_roundtrip_latency[0] = v >> 16;
  500. pip->link_roundtrip_latency[1] = v >> 8;
  501. pip->link_roundtrip_latency[2] = v;
  502. }
  503. ret = reply(smp);
  504. bail:
  505. return ret;
  506. }
  507. /**
  508. * get_pkeys - return the PKEY table
  509. * @dd: the qlogic_ib device
  510. * @port: the IB port number
  511. * @pkeys: the pkey table is placed here
  512. */
  513. static int get_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys)
  514. {
  515. struct qib_pportdata *ppd = dd->pport + port - 1;
  516. /*
  517. * always a kernel context, no locking needed.
  518. * If we get here with ppd setup, no need to check
  519. * that pd is valid.
  520. */
  521. struct qib_ctxtdata *rcd = dd->rcd[ppd->hw_pidx];
  522. memcpy(pkeys, rcd->pkeys, sizeof(rcd->pkeys));
  523. return 0;
  524. }
  525. static int subn_get_pkeytable(struct ib_smp *smp, struct ib_device *ibdev,
  526. u8 port)
  527. {
  528. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  529. u16 *p = (u16 *) smp->data;
  530. __be16 *q = (__be16 *) smp->data;
  531. /* 64 blocks of 32 16-bit P_Key entries */
  532. memset(smp->data, 0, sizeof(smp->data));
  533. if (startpx == 0) {
  534. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  535. unsigned i, n = qib_get_npkeys(dd);
  536. get_pkeys(dd, port, p);
  537. for (i = 0; i < n; i++)
  538. q[i] = cpu_to_be16(p[i]);
  539. } else
  540. smp->status |= IB_SMP_INVALID_FIELD;
  541. return reply(smp);
  542. }
  543. static int subn_set_guidinfo(struct ib_smp *smp, struct ib_device *ibdev,
  544. u8 port)
  545. {
  546. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  547. u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
  548. __be64 *p = (__be64 *) smp->data;
  549. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  550. /* 32 blocks of 8 64-bit GUIDs per block */
  551. if (startgx == 0 && pidx < dd->num_pports) {
  552. struct qib_pportdata *ppd = dd->pport + pidx;
  553. struct qib_ibport *ibp = &ppd->ibport_data;
  554. unsigned i;
  555. /* The first entry is read-only. */
  556. for (i = 1; i < QIB_GUIDS_PER_PORT; i++)
  557. ibp->guids[i - 1] = p[i];
  558. } else
  559. smp->status |= IB_SMP_INVALID_FIELD;
  560. /* The only GUID we support is the first read-only entry. */
  561. return subn_get_guidinfo(smp, ibdev, port);
  562. }
  563. /**
  564. * subn_set_portinfo - set port information
  565. * @smp: the incoming SM packet
  566. * @ibdev: the infiniband device
  567. * @port: the port on the device
  568. *
  569. * Set Portinfo (see ch. 14.2.5.6).
  570. */
  571. static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
  572. u8 port)
  573. {
  574. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  575. struct ib_event event;
  576. struct qib_devdata *dd;
  577. struct qib_pportdata *ppd;
  578. struct qib_ibport *ibp;
  579. u8 clientrereg = (pip->clientrereg_resv_subnetto & 0x80);
  580. unsigned long flags;
  581. u16 lid, smlid;
  582. u8 lwe;
  583. u8 lse;
  584. u8 state;
  585. u8 vls;
  586. u8 msl;
  587. u16 lstate;
  588. int ret, ore, mtu;
  589. u32 port_num = be32_to_cpu(smp->attr_mod);
  590. if (port_num == 0)
  591. port_num = port;
  592. else {
  593. if (port_num > ibdev->phys_port_cnt)
  594. goto err;
  595. /* Port attributes can only be set on the receiving port */
  596. if (port_num != port)
  597. goto get_only;
  598. }
  599. dd = dd_from_ibdev(ibdev);
  600. /* IB numbers ports from 1, hdw from 0 */
  601. ppd = dd->pport + (port_num - 1);
  602. ibp = &ppd->ibport_data;
  603. event.device = ibdev;
  604. event.element.port_num = port;
  605. ibp->mkey = pip->mkey;
  606. ibp->gid_prefix = pip->gid_prefix;
  607. ibp->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
  608. lid = be16_to_cpu(pip->lid);
  609. /* Must be a valid unicast LID address. */
  610. if (lid == 0 || lid >= QIB_MULTICAST_LID_BASE)
  611. smp->status |= IB_SMP_INVALID_FIELD;
  612. else if (ppd->lid != lid || ppd->lmc != (pip->mkeyprot_resv_lmc & 7)) {
  613. if (ppd->lid != lid)
  614. qib_set_uevent_bits(ppd, _QIB_EVENT_LID_CHANGE_BIT);
  615. if (ppd->lmc != (pip->mkeyprot_resv_lmc & 7))
  616. qib_set_uevent_bits(ppd, _QIB_EVENT_LMC_CHANGE_BIT);
  617. qib_set_lid(ppd, lid, pip->mkeyprot_resv_lmc & 7);
  618. event.event = IB_EVENT_LID_CHANGE;
  619. ib_dispatch_event(&event);
  620. }
  621. smlid = be16_to_cpu(pip->sm_lid);
  622. msl = pip->neighbormtu_mastersmsl & 0xF;
  623. /* Must be a valid unicast LID address. */
  624. if (smlid == 0 || smlid >= QIB_MULTICAST_LID_BASE)
  625. smp->status |= IB_SMP_INVALID_FIELD;
  626. else if (smlid != ibp->sm_lid || msl != ibp->sm_sl) {
  627. spin_lock_irqsave(&ibp->lock, flags);
  628. if (ibp->sm_ah) {
  629. if (smlid != ibp->sm_lid)
  630. ibp->sm_ah->attr.dlid = smlid;
  631. if (msl != ibp->sm_sl)
  632. ibp->sm_ah->attr.sl = msl;
  633. }
  634. spin_unlock_irqrestore(&ibp->lock, flags);
  635. if (smlid != ibp->sm_lid)
  636. ibp->sm_lid = smlid;
  637. if (msl != ibp->sm_sl)
  638. ibp->sm_sl = msl;
  639. event.event = IB_EVENT_SM_CHANGE;
  640. ib_dispatch_event(&event);
  641. }
  642. /* Allow 1x or 4x to be set (see 14.2.6.6). */
  643. lwe = pip->link_width_enabled;
  644. if (lwe) {
  645. if (lwe == 0xFF)
  646. set_link_width_enabled(ppd, ppd->link_width_supported);
  647. else if (lwe >= 16 || (lwe & ~ppd->link_width_supported))
  648. smp->status |= IB_SMP_INVALID_FIELD;
  649. else if (lwe != ppd->link_width_enabled)
  650. set_link_width_enabled(ppd, lwe);
  651. }
  652. lse = pip->linkspeedactive_enabled & 0xF;
  653. if (lse) {
  654. /*
  655. * The IB 1.2 spec. only allows link speed values
  656. * 1, 3, 5, 7, 15. 1.2.1 extended to allow specific
  657. * speeds.
  658. */
  659. if (lse == 15)
  660. set_link_speed_enabled(ppd,
  661. ppd->link_speed_supported);
  662. else if (lse >= 8 || (lse & ~ppd->link_speed_supported))
  663. smp->status |= IB_SMP_INVALID_FIELD;
  664. else if (lse != ppd->link_speed_enabled)
  665. set_link_speed_enabled(ppd, lse);
  666. }
  667. /* Set link down default state. */
  668. switch (pip->portphysstate_linkdown & 0xF) {
  669. case 0: /* NOP */
  670. break;
  671. case 1: /* SLEEP */
  672. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT,
  673. IB_LINKINITCMD_SLEEP);
  674. break;
  675. case 2: /* POLL */
  676. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT,
  677. IB_LINKINITCMD_POLL);
  678. break;
  679. default:
  680. smp->status |= IB_SMP_INVALID_FIELD;
  681. }
  682. ibp->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
  683. ibp->vl_high_limit = pip->vl_high_limit;
  684. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_LIMIT,
  685. ibp->vl_high_limit);
  686. mtu = ib_mtu_enum_to_int((pip->neighbormtu_mastersmsl >> 4) & 0xF);
  687. if (mtu == -1)
  688. smp->status |= IB_SMP_INVALID_FIELD;
  689. else
  690. qib_set_mtu(ppd, mtu);
  691. /* Set operational VLs */
  692. vls = (pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF;
  693. if (vls) {
  694. if (vls > ppd->vls_supported)
  695. smp->status |= IB_SMP_INVALID_FIELD;
  696. else
  697. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OP_VLS, vls);
  698. }
  699. if (pip->mkey_violations == 0)
  700. ibp->mkey_violations = 0;
  701. if (pip->pkey_violations == 0)
  702. ibp->pkey_violations = 0;
  703. if (pip->qkey_violations == 0)
  704. ibp->qkey_violations = 0;
  705. ore = pip->localphyerrors_overrunerrors;
  706. if (set_phyerrthreshold(ppd, (ore >> 4) & 0xF))
  707. smp->status |= IB_SMP_INVALID_FIELD;
  708. if (set_overrunthreshold(ppd, (ore & 0xF)))
  709. smp->status |= IB_SMP_INVALID_FIELD;
  710. ibp->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
  711. /*
  712. * Do the port state change now that the other link parameters
  713. * have been set.
  714. * Changing the port physical state only makes sense if the link
  715. * is down or is being set to down.
  716. */
  717. state = pip->linkspeed_portstate & 0xF;
  718. lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
  719. if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
  720. smp->status |= IB_SMP_INVALID_FIELD;
  721. /*
  722. * Only state changes of DOWN, ARM, and ACTIVE are valid
  723. * and must be in the correct state to take effect (see 7.2.6).
  724. */
  725. switch (state) {
  726. case IB_PORT_NOP:
  727. if (lstate == 0)
  728. break;
  729. /* FALLTHROUGH */
  730. case IB_PORT_DOWN:
  731. if (lstate == 0)
  732. lstate = QIB_IB_LINKDOWN_ONLY;
  733. else if (lstate == 1)
  734. lstate = QIB_IB_LINKDOWN_SLEEP;
  735. else if (lstate == 2)
  736. lstate = QIB_IB_LINKDOWN;
  737. else if (lstate == 3)
  738. lstate = QIB_IB_LINKDOWN_DISABLE;
  739. else {
  740. smp->status |= IB_SMP_INVALID_FIELD;
  741. break;
  742. }
  743. spin_lock_irqsave(&ppd->lflags_lock, flags);
  744. ppd->lflags &= ~QIBL_LINKV;
  745. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  746. qib_set_linkstate(ppd, lstate);
  747. /*
  748. * Don't send a reply if the response would be sent
  749. * through the disabled port.
  750. */
  751. if (lstate == QIB_IB_LINKDOWN_DISABLE && smp->hop_cnt) {
  752. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  753. goto done;
  754. }
  755. qib_wait_linkstate(ppd, QIBL_LINKV, 10);
  756. break;
  757. case IB_PORT_ARMED:
  758. qib_set_linkstate(ppd, QIB_IB_LINKARM);
  759. break;
  760. case IB_PORT_ACTIVE:
  761. qib_set_linkstate(ppd, QIB_IB_LINKACTIVE);
  762. break;
  763. default:
  764. smp->status |= IB_SMP_INVALID_FIELD;
  765. }
  766. if (clientrereg) {
  767. event.event = IB_EVENT_CLIENT_REREGISTER;
  768. ib_dispatch_event(&event);
  769. }
  770. ret = subn_get_portinfo(smp, ibdev, port);
  771. /* restore re-reg bit per o14-12.2.1 */
  772. pip->clientrereg_resv_subnetto |= clientrereg;
  773. goto get_only;
  774. err:
  775. smp->status |= IB_SMP_INVALID_FIELD;
  776. get_only:
  777. ret = subn_get_portinfo(smp, ibdev, port);
  778. done:
  779. return ret;
  780. }
  781. /**
  782. * rm_pkey - decrecment the reference count for the given PKEY
  783. * @dd: the qlogic_ib device
  784. * @key: the PKEY index
  785. *
  786. * Return true if this was the last reference and the hardware table entry
  787. * needs to be changed.
  788. */
  789. static int rm_pkey(struct qib_pportdata *ppd, u16 key)
  790. {
  791. int i;
  792. int ret;
  793. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  794. if (ppd->pkeys[i] != key)
  795. continue;
  796. if (atomic_dec_and_test(&ppd->pkeyrefs[i])) {
  797. ppd->pkeys[i] = 0;
  798. ret = 1;
  799. goto bail;
  800. }
  801. break;
  802. }
  803. ret = 0;
  804. bail:
  805. return ret;
  806. }
  807. /**
  808. * add_pkey - add the given PKEY to the hardware table
  809. * @dd: the qlogic_ib device
  810. * @key: the PKEY
  811. *
  812. * Return an error code if unable to add the entry, zero if no change,
  813. * or 1 if the hardware PKEY register needs to be updated.
  814. */
  815. static int add_pkey(struct qib_pportdata *ppd, u16 key)
  816. {
  817. int i;
  818. u16 lkey = key & 0x7FFF;
  819. int any = 0;
  820. int ret;
  821. if (lkey == 0x7FFF) {
  822. ret = 0;
  823. goto bail;
  824. }
  825. /* Look for an empty slot or a matching PKEY. */
  826. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  827. if (!ppd->pkeys[i]) {
  828. any++;
  829. continue;
  830. }
  831. /* If it matches exactly, try to increment the ref count */
  832. if (ppd->pkeys[i] == key) {
  833. if (atomic_inc_return(&ppd->pkeyrefs[i]) > 1) {
  834. ret = 0;
  835. goto bail;
  836. }
  837. /* Lost the race. Look for an empty slot below. */
  838. atomic_dec(&ppd->pkeyrefs[i]);
  839. any++;
  840. }
  841. /*
  842. * It makes no sense to have both the limited and unlimited
  843. * PKEY set at the same time since the unlimited one will
  844. * disable the limited one.
  845. */
  846. if ((ppd->pkeys[i] & 0x7FFF) == lkey) {
  847. ret = -EEXIST;
  848. goto bail;
  849. }
  850. }
  851. if (!any) {
  852. ret = -EBUSY;
  853. goto bail;
  854. }
  855. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  856. if (!ppd->pkeys[i] &&
  857. atomic_inc_return(&ppd->pkeyrefs[i]) == 1) {
  858. /* for qibstats, etc. */
  859. ppd->pkeys[i] = key;
  860. ret = 1;
  861. goto bail;
  862. }
  863. }
  864. ret = -EBUSY;
  865. bail:
  866. return ret;
  867. }
  868. /**
  869. * set_pkeys - set the PKEY table for ctxt 0
  870. * @dd: the qlogic_ib device
  871. * @port: the IB port number
  872. * @pkeys: the PKEY table
  873. */
  874. static int set_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys)
  875. {
  876. struct qib_pportdata *ppd;
  877. struct qib_ctxtdata *rcd;
  878. int i;
  879. int changed = 0;
  880. /*
  881. * IB port one/two always maps to context zero/one,
  882. * always a kernel context, no locking needed
  883. * If we get here with ppd setup, no need to check
  884. * that rcd is valid.
  885. */
  886. ppd = dd->pport + (port - 1);
  887. rcd = dd->rcd[ppd->hw_pidx];
  888. for (i = 0; i < ARRAY_SIZE(rcd->pkeys); i++) {
  889. u16 key = pkeys[i];
  890. u16 okey = rcd->pkeys[i];
  891. if (key == okey)
  892. continue;
  893. /*
  894. * The value of this PKEY table entry is changing.
  895. * Remove the old entry in the hardware's array of PKEYs.
  896. */
  897. if (okey & 0x7FFF)
  898. changed |= rm_pkey(ppd, okey);
  899. if (key & 0x7FFF) {
  900. int ret = add_pkey(ppd, key);
  901. if (ret < 0)
  902. key = 0;
  903. else
  904. changed |= ret;
  905. }
  906. rcd->pkeys[i] = key;
  907. }
  908. if (changed) {
  909. struct ib_event event;
  910. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0);
  911. event.event = IB_EVENT_PKEY_CHANGE;
  912. event.device = &dd->verbs_dev.ibdev;
  913. event.element.port_num = port;
  914. ib_dispatch_event(&event);
  915. }
  916. return 0;
  917. }
  918. static int subn_set_pkeytable(struct ib_smp *smp, struct ib_device *ibdev,
  919. u8 port)
  920. {
  921. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  922. __be16 *p = (__be16 *) smp->data;
  923. u16 *q = (u16 *) smp->data;
  924. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  925. unsigned i, n = qib_get_npkeys(dd);
  926. for (i = 0; i < n; i++)
  927. q[i] = be16_to_cpu(p[i]);
  928. if (startpx != 0 || set_pkeys(dd, port, q) != 0)
  929. smp->status |= IB_SMP_INVALID_FIELD;
  930. return subn_get_pkeytable(smp, ibdev, port);
  931. }
  932. static int subn_get_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
  933. u8 port)
  934. {
  935. struct qib_ibport *ibp = to_iport(ibdev, port);
  936. u8 *p = (u8 *) smp->data;
  937. unsigned i;
  938. memset(smp->data, 0, sizeof(smp->data));
  939. if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP))
  940. smp->status |= IB_SMP_UNSUP_METHOD;
  941. else
  942. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2)
  943. *p++ = (ibp->sl_to_vl[i] << 4) | ibp->sl_to_vl[i + 1];
  944. return reply(smp);
  945. }
  946. static int subn_set_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
  947. u8 port)
  948. {
  949. struct qib_ibport *ibp = to_iport(ibdev, port);
  950. u8 *p = (u8 *) smp->data;
  951. unsigned i;
  952. if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP)) {
  953. smp->status |= IB_SMP_UNSUP_METHOD;
  954. return reply(smp);
  955. }
  956. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2, p++) {
  957. ibp->sl_to_vl[i] = *p >> 4;
  958. ibp->sl_to_vl[i + 1] = *p & 0xF;
  959. }
  960. qib_set_uevent_bits(ppd_from_ibp(to_iport(ibdev, port)),
  961. _QIB_EVENT_SL2VL_CHANGE_BIT);
  962. return subn_get_sl_to_vl(smp, ibdev, port);
  963. }
  964. static int subn_get_vl_arb(struct ib_smp *smp, struct ib_device *ibdev,
  965. u8 port)
  966. {
  967. unsigned which = be32_to_cpu(smp->attr_mod) >> 16;
  968. struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  969. memset(smp->data, 0, sizeof(smp->data));
  970. if (ppd->vls_supported == IB_VL_VL0)
  971. smp->status |= IB_SMP_UNSUP_METHOD;
  972. else if (which == IB_VLARB_LOWPRI_0_31)
  973. (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB,
  974. smp->data);
  975. else if (which == IB_VLARB_HIGHPRI_0_31)
  976. (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB,
  977. smp->data);
  978. else
  979. smp->status |= IB_SMP_INVALID_FIELD;
  980. return reply(smp);
  981. }
  982. static int subn_set_vl_arb(struct ib_smp *smp, struct ib_device *ibdev,
  983. u8 port)
  984. {
  985. unsigned which = be32_to_cpu(smp->attr_mod) >> 16;
  986. struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  987. if (ppd->vls_supported == IB_VL_VL0)
  988. smp->status |= IB_SMP_UNSUP_METHOD;
  989. else if (which == IB_VLARB_LOWPRI_0_31)
  990. (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB,
  991. smp->data);
  992. else if (which == IB_VLARB_HIGHPRI_0_31)
  993. (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB,
  994. smp->data);
  995. else
  996. smp->status |= IB_SMP_INVALID_FIELD;
  997. return subn_get_vl_arb(smp, ibdev, port);
  998. }
  999. static int subn_trap_repress(struct ib_smp *smp, struct ib_device *ibdev,
  1000. u8 port)
  1001. {
  1002. /*
  1003. * For now, we only send the trap once so no need to process this.
  1004. * o13-6, o13-7,
  1005. * o14-3.a4 The SMA shall not send any message in response to a valid
  1006. * SubnTrapRepress() message.
  1007. */
  1008. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  1009. }
  1010. static int pma_get_classportinfo(struct ib_pma_mad *pmp,
  1011. struct ib_device *ibdev)
  1012. {
  1013. struct ib_class_port_info *p =
  1014. (struct ib_class_port_info *)pmp->data;
  1015. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  1016. memset(pmp->data, 0, sizeof(pmp->data));
  1017. if (pmp->mad_hdr.attr_mod != 0)
  1018. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1019. /* Note that AllPortSelect is not valid */
  1020. p->base_version = 1;
  1021. p->class_version = 1;
  1022. p->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
  1023. /*
  1024. * Set the most significant bit of CM2 to indicate support for
  1025. * congestion statistics
  1026. */
  1027. p->reserved[0] = dd->psxmitwait_supported << 7;
  1028. /*
  1029. * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
  1030. */
  1031. p->resp_time_value = 18;
  1032. return reply((struct ib_smp *) pmp);
  1033. }
  1034. static int pma_get_portsamplescontrol(struct ib_pma_mad *pmp,
  1035. struct ib_device *ibdev, u8 port)
  1036. {
  1037. struct ib_pma_portsamplescontrol *p =
  1038. (struct ib_pma_portsamplescontrol *)pmp->data;
  1039. struct qib_ibdev *dev = to_idev(ibdev);
  1040. struct qib_devdata *dd = dd_from_dev(dev);
  1041. struct qib_ibport *ibp = to_iport(ibdev, port);
  1042. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1043. unsigned long flags;
  1044. u8 port_select = p->port_select;
  1045. memset(pmp->data, 0, sizeof(pmp->data));
  1046. p->port_select = port_select;
  1047. if (pmp->mad_hdr.attr_mod != 0 || port_select != port) {
  1048. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1049. goto bail;
  1050. }
  1051. spin_lock_irqsave(&ibp->lock, flags);
  1052. p->tick = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PMA_TICKS);
  1053. p->sample_status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1054. p->counter_width = 4; /* 32 bit counters */
  1055. p->counter_mask0_9 = COUNTER_MASK0_9;
  1056. p->sample_start = cpu_to_be32(ibp->pma_sample_start);
  1057. p->sample_interval = cpu_to_be32(ibp->pma_sample_interval);
  1058. p->tag = cpu_to_be16(ibp->pma_tag);
  1059. p->counter_select[0] = ibp->pma_counter_select[0];
  1060. p->counter_select[1] = ibp->pma_counter_select[1];
  1061. p->counter_select[2] = ibp->pma_counter_select[2];
  1062. p->counter_select[3] = ibp->pma_counter_select[3];
  1063. p->counter_select[4] = ibp->pma_counter_select[4];
  1064. spin_unlock_irqrestore(&ibp->lock, flags);
  1065. bail:
  1066. return reply((struct ib_smp *) pmp);
  1067. }
  1068. static int pma_set_portsamplescontrol(struct ib_pma_mad *pmp,
  1069. struct ib_device *ibdev, u8 port)
  1070. {
  1071. struct ib_pma_portsamplescontrol *p =
  1072. (struct ib_pma_portsamplescontrol *)pmp->data;
  1073. struct qib_ibdev *dev = to_idev(ibdev);
  1074. struct qib_devdata *dd = dd_from_dev(dev);
  1075. struct qib_ibport *ibp = to_iport(ibdev, port);
  1076. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1077. unsigned long flags;
  1078. u8 status, xmit_flags;
  1079. int ret;
  1080. if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
  1081. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1082. ret = reply((struct ib_smp *) pmp);
  1083. goto bail;
  1084. }
  1085. spin_lock_irqsave(&ibp->lock, flags);
  1086. /* Port Sampling code owns the PS* HW counters */
  1087. xmit_flags = ppd->cong_stats.flags;
  1088. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_SAMPLE;
  1089. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1090. if (status == IB_PMA_SAMPLE_STATUS_DONE ||
  1091. (status == IB_PMA_SAMPLE_STATUS_RUNNING &&
  1092. xmit_flags == IB_PMA_CONG_HW_CONTROL_TIMER)) {
  1093. ibp->pma_sample_start = be32_to_cpu(p->sample_start);
  1094. ibp->pma_sample_interval = be32_to_cpu(p->sample_interval);
  1095. ibp->pma_tag = be16_to_cpu(p->tag);
  1096. ibp->pma_counter_select[0] = p->counter_select[0];
  1097. ibp->pma_counter_select[1] = p->counter_select[1];
  1098. ibp->pma_counter_select[2] = p->counter_select[2];
  1099. ibp->pma_counter_select[3] = p->counter_select[3];
  1100. ibp->pma_counter_select[4] = p->counter_select[4];
  1101. dd->f_set_cntr_sample(ppd, ibp->pma_sample_interval,
  1102. ibp->pma_sample_start);
  1103. }
  1104. spin_unlock_irqrestore(&ibp->lock, flags);
  1105. ret = pma_get_portsamplescontrol(pmp, ibdev, port);
  1106. bail:
  1107. return ret;
  1108. }
  1109. static u64 get_counter(struct qib_ibport *ibp, struct qib_pportdata *ppd,
  1110. __be16 sel)
  1111. {
  1112. u64 ret;
  1113. switch (sel) {
  1114. case IB_PMA_PORT_XMIT_DATA:
  1115. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITDATA);
  1116. break;
  1117. case IB_PMA_PORT_RCV_DATA:
  1118. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVDATA);
  1119. break;
  1120. case IB_PMA_PORT_XMIT_PKTS:
  1121. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITPKTS);
  1122. break;
  1123. case IB_PMA_PORT_RCV_PKTS:
  1124. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVPKTS);
  1125. break;
  1126. case IB_PMA_PORT_XMIT_WAIT:
  1127. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITWAIT);
  1128. break;
  1129. default:
  1130. ret = 0;
  1131. }
  1132. return ret;
  1133. }
  1134. /* This function assumes that the xmit_wait lock is already held */
  1135. static u64 xmit_wait_get_value_delta(struct qib_pportdata *ppd)
  1136. {
  1137. u32 delta;
  1138. delta = get_counter(&ppd->ibport_data, ppd,
  1139. IB_PMA_PORT_XMIT_WAIT);
  1140. return ppd->cong_stats.counter + delta;
  1141. }
  1142. static void cache_hw_sample_counters(struct qib_pportdata *ppd)
  1143. {
  1144. struct qib_ibport *ibp = &ppd->ibport_data;
  1145. ppd->cong_stats.counter_cache.psxmitdata =
  1146. get_counter(ibp, ppd, IB_PMA_PORT_XMIT_DATA);
  1147. ppd->cong_stats.counter_cache.psrcvdata =
  1148. get_counter(ibp, ppd, IB_PMA_PORT_RCV_DATA);
  1149. ppd->cong_stats.counter_cache.psxmitpkts =
  1150. get_counter(ibp, ppd, IB_PMA_PORT_XMIT_PKTS);
  1151. ppd->cong_stats.counter_cache.psrcvpkts =
  1152. get_counter(ibp, ppd, IB_PMA_PORT_RCV_PKTS);
  1153. ppd->cong_stats.counter_cache.psxmitwait =
  1154. get_counter(ibp, ppd, IB_PMA_PORT_XMIT_WAIT);
  1155. }
  1156. static u64 get_cache_hw_sample_counters(struct qib_pportdata *ppd,
  1157. __be16 sel)
  1158. {
  1159. u64 ret;
  1160. switch (sel) {
  1161. case IB_PMA_PORT_XMIT_DATA:
  1162. ret = ppd->cong_stats.counter_cache.psxmitdata;
  1163. break;
  1164. case IB_PMA_PORT_RCV_DATA:
  1165. ret = ppd->cong_stats.counter_cache.psrcvdata;
  1166. break;
  1167. case IB_PMA_PORT_XMIT_PKTS:
  1168. ret = ppd->cong_stats.counter_cache.psxmitpkts;
  1169. break;
  1170. case IB_PMA_PORT_RCV_PKTS:
  1171. ret = ppd->cong_stats.counter_cache.psrcvpkts;
  1172. break;
  1173. case IB_PMA_PORT_XMIT_WAIT:
  1174. ret = ppd->cong_stats.counter_cache.psxmitwait;
  1175. break;
  1176. default:
  1177. ret = 0;
  1178. }
  1179. return ret;
  1180. }
  1181. static int pma_get_portsamplesresult(struct ib_pma_mad *pmp,
  1182. struct ib_device *ibdev, u8 port)
  1183. {
  1184. struct ib_pma_portsamplesresult *p =
  1185. (struct ib_pma_portsamplesresult *)pmp->data;
  1186. struct qib_ibdev *dev = to_idev(ibdev);
  1187. struct qib_devdata *dd = dd_from_dev(dev);
  1188. struct qib_ibport *ibp = to_iport(ibdev, port);
  1189. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1190. unsigned long flags;
  1191. u8 status;
  1192. int i;
  1193. memset(pmp->data, 0, sizeof(pmp->data));
  1194. spin_lock_irqsave(&ibp->lock, flags);
  1195. p->tag = cpu_to_be16(ibp->pma_tag);
  1196. if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
  1197. p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  1198. else {
  1199. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1200. p->sample_status = cpu_to_be16(status);
  1201. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  1202. cache_hw_sample_counters(ppd);
  1203. ppd->cong_stats.counter =
  1204. xmit_wait_get_value_delta(ppd);
  1205. dd->f_set_cntr_sample(ppd,
  1206. QIB_CONG_TIMER_PSINTERVAL, 0);
  1207. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
  1208. }
  1209. }
  1210. for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++)
  1211. p->counter[i] = cpu_to_be32(
  1212. get_cache_hw_sample_counters(
  1213. ppd, ibp->pma_counter_select[i]));
  1214. spin_unlock_irqrestore(&ibp->lock, flags);
  1215. return reply((struct ib_smp *) pmp);
  1216. }
  1217. static int pma_get_portsamplesresult_ext(struct ib_pma_mad *pmp,
  1218. struct ib_device *ibdev, u8 port)
  1219. {
  1220. struct ib_pma_portsamplesresult_ext *p =
  1221. (struct ib_pma_portsamplesresult_ext *)pmp->data;
  1222. struct qib_ibdev *dev = to_idev(ibdev);
  1223. struct qib_devdata *dd = dd_from_dev(dev);
  1224. struct qib_ibport *ibp = to_iport(ibdev, port);
  1225. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1226. unsigned long flags;
  1227. u8 status;
  1228. int i;
  1229. /* Port Sampling code owns the PS* HW counters */
  1230. memset(pmp->data, 0, sizeof(pmp->data));
  1231. spin_lock_irqsave(&ibp->lock, flags);
  1232. p->tag = cpu_to_be16(ibp->pma_tag);
  1233. if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
  1234. p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  1235. else {
  1236. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1237. p->sample_status = cpu_to_be16(status);
  1238. /* 64 bits */
  1239. p->extended_width = cpu_to_be32(0x80000000);
  1240. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  1241. cache_hw_sample_counters(ppd);
  1242. ppd->cong_stats.counter =
  1243. xmit_wait_get_value_delta(ppd);
  1244. dd->f_set_cntr_sample(ppd,
  1245. QIB_CONG_TIMER_PSINTERVAL, 0);
  1246. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
  1247. }
  1248. }
  1249. for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++)
  1250. p->counter[i] = cpu_to_be64(
  1251. get_cache_hw_sample_counters(
  1252. ppd, ibp->pma_counter_select[i]));
  1253. spin_unlock_irqrestore(&ibp->lock, flags);
  1254. return reply((struct ib_smp *) pmp);
  1255. }
  1256. static int pma_get_portcounters(struct ib_pma_mad *pmp,
  1257. struct ib_device *ibdev, u8 port)
  1258. {
  1259. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1260. pmp->data;
  1261. struct qib_ibport *ibp = to_iport(ibdev, port);
  1262. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1263. struct qib_verbs_counters cntrs;
  1264. u8 port_select = p->port_select;
  1265. qib_get_counters(ppd, &cntrs);
  1266. /* Adjust counters for any resets done. */
  1267. cntrs.symbol_error_counter -= ibp->z_symbol_error_counter;
  1268. cntrs.link_error_recovery_counter -=
  1269. ibp->z_link_error_recovery_counter;
  1270. cntrs.link_downed_counter -= ibp->z_link_downed_counter;
  1271. cntrs.port_rcv_errors -= ibp->z_port_rcv_errors;
  1272. cntrs.port_rcv_remphys_errors -= ibp->z_port_rcv_remphys_errors;
  1273. cntrs.port_xmit_discards -= ibp->z_port_xmit_discards;
  1274. cntrs.port_xmit_data -= ibp->z_port_xmit_data;
  1275. cntrs.port_rcv_data -= ibp->z_port_rcv_data;
  1276. cntrs.port_xmit_packets -= ibp->z_port_xmit_packets;
  1277. cntrs.port_rcv_packets -= ibp->z_port_rcv_packets;
  1278. cntrs.local_link_integrity_errors -=
  1279. ibp->z_local_link_integrity_errors;
  1280. cntrs.excessive_buffer_overrun_errors -=
  1281. ibp->z_excessive_buffer_overrun_errors;
  1282. cntrs.vl15_dropped -= ibp->z_vl15_dropped;
  1283. cntrs.vl15_dropped += ibp->n_vl15_dropped;
  1284. memset(pmp->data, 0, sizeof(pmp->data));
  1285. p->port_select = port_select;
  1286. if (pmp->mad_hdr.attr_mod != 0 || port_select != port)
  1287. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1288. if (cntrs.symbol_error_counter > 0xFFFFUL)
  1289. p->symbol_error_counter = cpu_to_be16(0xFFFF);
  1290. else
  1291. p->symbol_error_counter =
  1292. cpu_to_be16((u16)cntrs.symbol_error_counter);
  1293. if (cntrs.link_error_recovery_counter > 0xFFUL)
  1294. p->link_error_recovery_counter = 0xFF;
  1295. else
  1296. p->link_error_recovery_counter =
  1297. (u8)cntrs.link_error_recovery_counter;
  1298. if (cntrs.link_downed_counter > 0xFFUL)
  1299. p->link_downed_counter = 0xFF;
  1300. else
  1301. p->link_downed_counter = (u8)cntrs.link_downed_counter;
  1302. if (cntrs.port_rcv_errors > 0xFFFFUL)
  1303. p->port_rcv_errors = cpu_to_be16(0xFFFF);
  1304. else
  1305. p->port_rcv_errors =
  1306. cpu_to_be16((u16) cntrs.port_rcv_errors);
  1307. if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
  1308. p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
  1309. else
  1310. p->port_rcv_remphys_errors =
  1311. cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
  1312. if (cntrs.port_xmit_discards > 0xFFFFUL)
  1313. p->port_xmit_discards = cpu_to_be16(0xFFFF);
  1314. else
  1315. p->port_xmit_discards =
  1316. cpu_to_be16((u16)cntrs.port_xmit_discards);
  1317. if (cntrs.local_link_integrity_errors > 0xFUL)
  1318. cntrs.local_link_integrity_errors = 0xFUL;
  1319. if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
  1320. cntrs.excessive_buffer_overrun_errors = 0xFUL;
  1321. p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) |
  1322. cntrs.excessive_buffer_overrun_errors;
  1323. if (cntrs.vl15_dropped > 0xFFFFUL)
  1324. p->vl15_dropped = cpu_to_be16(0xFFFF);
  1325. else
  1326. p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
  1327. if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
  1328. p->port_xmit_data = cpu_to_be32(0xFFFFFFFF);
  1329. else
  1330. p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
  1331. if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
  1332. p->port_rcv_data = cpu_to_be32(0xFFFFFFFF);
  1333. else
  1334. p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
  1335. if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
  1336. p->port_xmit_packets = cpu_to_be32(0xFFFFFFFF);
  1337. else
  1338. p->port_xmit_packets =
  1339. cpu_to_be32((u32)cntrs.port_xmit_packets);
  1340. if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
  1341. p->port_rcv_packets = cpu_to_be32(0xFFFFFFFF);
  1342. else
  1343. p->port_rcv_packets =
  1344. cpu_to_be32((u32) cntrs.port_rcv_packets);
  1345. return reply((struct ib_smp *) pmp);
  1346. }
  1347. static int pma_get_portcounters_cong(struct ib_pma_mad *pmp,
  1348. struct ib_device *ibdev, u8 port)
  1349. {
  1350. /* Congestion PMA packets start at offset 24 not 64 */
  1351. struct ib_pma_portcounters_cong *p =
  1352. (struct ib_pma_portcounters_cong *)pmp->reserved;
  1353. struct qib_verbs_counters cntrs;
  1354. struct qib_ibport *ibp = to_iport(ibdev, port);
  1355. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1356. struct qib_devdata *dd = dd_from_ppd(ppd);
  1357. u32 port_select = be32_to_cpu(pmp->mad_hdr.attr_mod) & 0xFF;
  1358. u64 xmit_wait_counter;
  1359. unsigned long flags;
  1360. /*
  1361. * This check is performed only in the GET method because the
  1362. * SET method ends up calling this anyway.
  1363. */
  1364. if (!dd->psxmitwait_supported)
  1365. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  1366. if (port_select != port)
  1367. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1368. qib_get_counters(ppd, &cntrs);
  1369. spin_lock_irqsave(&ppd->ibport_data.lock, flags);
  1370. xmit_wait_counter = xmit_wait_get_value_delta(ppd);
  1371. spin_unlock_irqrestore(&ppd->ibport_data.lock, flags);
  1372. /* Adjust counters for any resets done. */
  1373. cntrs.symbol_error_counter -= ibp->z_symbol_error_counter;
  1374. cntrs.link_error_recovery_counter -=
  1375. ibp->z_link_error_recovery_counter;
  1376. cntrs.link_downed_counter -= ibp->z_link_downed_counter;
  1377. cntrs.port_rcv_errors -= ibp->z_port_rcv_errors;
  1378. cntrs.port_rcv_remphys_errors -=
  1379. ibp->z_port_rcv_remphys_errors;
  1380. cntrs.port_xmit_discards -= ibp->z_port_xmit_discards;
  1381. cntrs.local_link_integrity_errors -=
  1382. ibp->z_local_link_integrity_errors;
  1383. cntrs.excessive_buffer_overrun_errors -=
  1384. ibp->z_excessive_buffer_overrun_errors;
  1385. cntrs.vl15_dropped -= ibp->z_vl15_dropped;
  1386. cntrs.vl15_dropped += ibp->n_vl15_dropped;
  1387. cntrs.port_xmit_data -= ibp->z_port_xmit_data;
  1388. cntrs.port_rcv_data -= ibp->z_port_rcv_data;
  1389. cntrs.port_xmit_packets -= ibp->z_port_xmit_packets;
  1390. cntrs.port_rcv_packets -= ibp->z_port_rcv_packets;
  1391. memset(pmp->reserved, 0, sizeof(pmp->reserved) +
  1392. sizeof(pmp->data));
  1393. /*
  1394. * Set top 3 bits to indicate interval in picoseconds in
  1395. * remaining bits.
  1396. */
  1397. p->port_check_rate =
  1398. cpu_to_be16((QIB_XMIT_RATE_PICO << 13) |
  1399. (dd->psxmitwait_check_rate &
  1400. ~(QIB_XMIT_RATE_PICO << 13)));
  1401. p->port_adr_events = cpu_to_be64(0);
  1402. p->port_xmit_wait = cpu_to_be64(xmit_wait_counter);
  1403. p->port_xmit_data = cpu_to_be64(cntrs.port_xmit_data);
  1404. p->port_rcv_data = cpu_to_be64(cntrs.port_rcv_data);
  1405. p->port_xmit_packets =
  1406. cpu_to_be64(cntrs.port_xmit_packets);
  1407. p->port_rcv_packets =
  1408. cpu_to_be64(cntrs.port_rcv_packets);
  1409. if (cntrs.symbol_error_counter > 0xFFFFUL)
  1410. p->symbol_error_counter = cpu_to_be16(0xFFFF);
  1411. else
  1412. p->symbol_error_counter =
  1413. cpu_to_be16(
  1414. (u16)cntrs.symbol_error_counter);
  1415. if (cntrs.link_error_recovery_counter > 0xFFUL)
  1416. p->link_error_recovery_counter = 0xFF;
  1417. else
  1418. p->link_error_recovery_counter =
  1419. (u8)cntrs.link_error_recovery_counter;
  1420. if (cntrs.link_downed_counter > 0xFFUL)
  1421. p->link_downed_counter = 0xFF;
  1422. else
  1423. p->link_downed_counter =
  1424. (u8)cntrs.link_downed_counter;
  1425. if (cntrs.port_rcv_errors > 0xFFFFUL)
  1426. p->port_rcv_errors = cpu_to_be16(0xFFFF);
  1427. else
  1428. p->port_rcv_errors =
  1429. cpu_to_be16((u16) cntrs.port_rcv_errors);
  1430. if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
  1431. p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
  1432. else
  1433. p->port_rcv_remphys_errors =
  1434. cpu_to_be16(
  1435. (u16)cntrs.port_rcv_remphys_errors);
  1436. if (cntrs.port_xmit_discards > 0xFFFFUL)
  1437. p->port_xmit_discards = cpu_to_be16(0xFFFF);
  1438. else
  1439. p->port_xmit_discards =
  1440. cpu_to_be16((u16)cntrs.port_xmit_discards);
  1441. if (cntrs.local_link_integrity_errors > 0xFUL)
  1442. cntrs.local_link_integrity_errors = 0xFUL;
  1443. if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
  1444. cntrs.excessive_buffer_overrun_errors = 0xFUL;
  1445. p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) |
  1446. cntrs.excessive_buffer_overrun_errors;
  1447. if (cntrs.vl15_dropped > 0xFFFFUL)
  1448. p->vl15_dropped = cpu_to_be16(0xFFFF);
  1449. else
  1450. p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
  1451. return reply((struct ib_smp *)pmp);
  1452. }
  1453. static void qib_snapshot_pmacounters(
  1454. struct qib_ibport *ibp,
  1455. struct qib_pma_counters *pmacounters)
  1456. {
  1457. struct qib_pma_counters *p;
  1458. int cpu;
  1459. memset(pmacounters, 0, sizeof(*pmacounters));
  1460. for_each_possible_cpu(cpu) {
  1461. p = per_cpu_ptr(ibp->pmastats, cpu);
  1462. pmacounters->n_unicast_xmit += p->n_unicast_xmit;
  1463. pmacounters->n_unicast_rcv += p->n_unicast_rcv;
  1464. pmacounters->n_multicast_xmit += p->n_multicast_xmit;
  1465. pmacounters->n_multicast_rcv += p->n_multicast_rcv;
  1466. }
  1467. }
  1468. static int pma_get_portcounters_ext(struct ib_pma_mad *pmp,
  1469. struct ib_device *ibdev, u8 port)
  1470. {
  1471. struct ib_pma_portcounters_ext *p =
  1472. (struct ib_pma_portcounters_ext *)pmp->data;
  1473. struct qib_ibport *ibp = to_iport(ibdev, port);
  1474. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1475. u64 swords, rwords, spkts, rpkts, xwait;
  1476. struct qib_pma_counters pma;
  1477. u8 port_select = p->port_select;
  1478. memset(pmp->data, 0, sizeof(pmp->data));
  1479. p->port_select = port_select;
  1480. if (pmp->mad_hdr.attr_mod != 0 || port_select != port) {
  1481. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1482. goto bail;
  1483. }
  1484. qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait);
  1485. /* Adjust counters for any resets done. */
  1486. swords -= ibp->z_port_xmit_data;
  1487. rwords -= ibp->z_port_rcv_data;
  1488. spkts -= ibp->z_port_xmit_packets;
  1489. rpkts -= ibp->z_port_rcv_packets;
  1490. p->port_xmit_data = cpu_to_be64(swords);
  1491. p->port_rcv_data = cpu_to_be64(rwords);
  1492. p->port_xmit_packets = cpu_to_be64(spkts);
  1493. p->port_rcv_packets = cpu_to_be64(rpkts);
  1494. qib_snapshot_pmacounters(ibp, &pma);
  1495. p->port_unicast_xmit_packets = cpu_to_be64(pma.n_unicast_xmit
  1496. - ibp->z_unicast_xmit);
  1497. p->port_unicast_rcv_packets = cpu_to_be64(pma.n_unicast_rcv
  1498. - ibp->z_unicast_rcv);
  1499. p->port_multicast_xmit_packets = cpu_to_be64(pma.n_multicast_xmit
  1500. - ibp->z_multicast_xmit);
  1501. p->port_multicast_rcv_packets = cpu_to_be64(pma.n_multicast_rcv
  1502. - ibp->z_multicast_rcv);
  1503. bail:
  1504. return reply((struct ib_smp *) pmp);
  1505. }
  1506. static int pma_set_portcounters(struct ib_pma_mad *pmp,
  1507. struct ib_device *ibdev, u8 port)
  1508. {
  1509. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1510. pmp->data;
  1511. struct qib_ibport *ibp = to_iport(ibdev, port);
  1512. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1513. struct qib_verbs_counters cntrs;
  1514. /*
  1515. * Since the HW doesn't support clearing counters, we save the
  1516. * current count and subtract it from future responses.
  1517. */
  1518. qib_get_counters(ppd, &cntrs);
  1519. if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
  1520. ibp->z_symbol_error_counter = cntrs.symbol_error_counter;
  1521. if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
  1522. ibp->z_link_error_recovery_counter =
  1523. cntrs.link_error_recovery_counter;
  1524. if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
  1525. ibp->z_link_downed_counter = cntrs.link_downed_counter;
  1526. if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
  1527. ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
  1528. if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
  1529. ibp->z_port_rcv_remphys_errors =
  1530. cntrs.port_rcv_remphys_errors;
  1531. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
  1532. ibp->z_port_xmit_discards = cntrs.port_xmit_discards;
  1533. if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
  1534. ibp->z_local_link_integrity_errors =
  1535. cntrs.local_link_integrity_errors;
  1536. if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
  1537. ibp->z_excessive_buffer_overrun_errors =
  1538. cntrs.excessive_buffer_overrun_errors;
  1539. if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
  1540. ibp->n_vl15_dropped = 0;
  1541. ibp->z_vl15_dropped = cntrs.vl15_dropped;
  1542. }
  1543. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
  1544. ibp->z_port_xmit_data = cntrs.port_xmit_data;
  1545. if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
  1546. ibp->z_port_rcv_data = cntrs.port_rcv_data;
  1547. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
  1548. ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
  1549. if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
  1550. ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
  1551. return pma_get_portcounters(pmp, ibdev, port);
  1552. }
  1553. static int pma_set_portcounters_cong(struct ib_pma_mad *pmp,
  1554. struct ib_device *ibdev, u8 port)
  1555. {
  1556. struct qib_ibport *ibp = to_iport(ibdev, port);
  1557. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1558. struct qib_devdata *dd = dd_from_ppd(ppd);
  1559. struct qib_verbs_counters cntrs;
  1560. u32 counter_select = (be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24) & 0xFF;
  1561. int ret = 0;
  1562. unsigned long flags;
  1563. qib_get_counters(ppd, &cntrs);
  1564. /* Get counter values before we save them */
  1565. ret = pma_get_portcounters_cong(pmp, ibdev, port);
  1566. if (counter_select & IB_PMA_SEL_CONG_XMIT) {
  1567. spin_lock_irqsave(&ppd->ibport_data.lock, flags);
  1568. ppd->cong_stats.counter = 0;
  1569. dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL,
  1570. 0x0);
  1571. spin_unlock_irqrestore(&ppd->ibport_data.lock, flags);
  1572. }
  1573. if (counter_select & IB_PMA_SEL_CONG_PORT_DATA) {
  1574. ibp->z_port_xmit_data = cntrs.port_xmit_data;
  1575. ibp->z_port_rcv_data = cntrs.port_rcv_data;
  1576. ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
  1577. ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
  1578. }
  1579. if (counter_select & IB_PMA_SEL_CONG_ALL) {
  1580. ibp->z_symbol_error_counter =
  1581. cntrs.symbol_error_counter;
  1582. ibp->z_link_error_recovery_counter =
  1583. cntrs.link_error_recovery_counter;
  1584. ibp->z_link_downed_counter =
  1585. cntrs.link_downed_counter;
  1586. ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
  1587. ibp->z_port_rcv_remphys_errors =
  1588. cntrs.port_rcv_remphys_errors;
  1589. ibp->z_port_xmit_discards =
  1590. cntrs.port_xmit_discards;
  1591. ibp->z_local_link_integrity_errors =
  1592. cntrs.local_link_integrity_errors;
  1593. ibp->z_excessive_buffer_overrun_errors =
  1594. cntrs.excessive_buffer_overrun_errors;
  1595. ibp->n_vl15_dropped = 0;
  1596. ibp->z_vl15_dropped = cntrs.vl15_dropped;
  1597. }
  1598. return ret;
  1599. }
  1600. static int pma_set_portcounters_ext(struct ib_pma_mad *pmp,
  1601. struct ib_device *ibdev, u8 port)
  1602. {
  1603. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1604. pmp->data;
  1605. struct qib_ibport *ibp = to_iport(ibdev, port);
  1606. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1607. u64 swords, rwords, spkts, rpkts, xwait;
  1608. struct qib_pma_counters pma;
  1609. qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait);
  1610. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
  1611. ibp->z_port_xmit_data = swords;
  1612. if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
  1613. ibp->z_port_rcv_data = rwords;
  1614. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
  1615. ibp->z_port_xmit_packets = spkts;
  1616. if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
  1617. ibp->z_port_rcv_packets = rpkts;
  1618. qib_snapshot_pmacounters(ibp, &pma);
  1619. if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
  1620. ibp->z_unicast_xmit = pma.n_unicast_xmit;
  1621. if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
  1622. ibp->z_unicast_rcv = pma.n_unicast_rcv;
  1623. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
  1624. ibp->z_multicast_xmit = pma.n_multicast_xmit;
  1625. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
  1626. ibp->z_multicast_rcv = pma.n_multicast_rcv;
  1627. return pma_get_portcounters_ext(pmp, ibdev, port);
  1628. }
  1629. static int process_subn(struct ib_device *ibdev, int mad_flags,
  1630. u8 port, const struct ib_mad *in_mad,
  1631. struct ib_mad *out_mad)
  1632. {
  1633. struct ib_smp *smp = (struct ib_smp *)out_mad;
  1634. struct qib_ibport *ibp = to_iport(ibdev, port);
  1635. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1636. int ret;
  1637. *out_mad = *in_mad;
  1638. if (smp->class_version != 1) {
  1639. smp->status |= IB_SMP_UNSUP_VERSION;
  1640. ret = reply(smp);
  1641. goto bail;
  1642. }
  1643. ret = check_mkey(ibp, smp, mad_flags);
  1644. if (ret) {
  1645. u32 port_num = be32_to_cpu(smp->attr_mod);
  1646. /*
  1647. * If this is a get/set portinfo, we already check the
  1648. * M_Key if the MAD is for another port and the M_Key
  1649. * is OK on the receiving port. This check is needed
  1650. * to increment the error counters when the M_Key
  1651. * fails to match on *both* ports.
  1652. */
  1653. if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
  1654. (smp->method == IB_MGMT_METHOD_GET ||
  1655. smp->method == IB_MGMT_METHOD_SET) &&
  1656. port_num && port_num <= ibdev->phys_port_cnt &&
  1657. port != port_num)
  1658. (void) check_mkey(to_iport(ibdev, port_num), smp, 0);
  1659. ret = IB_MAD_RESULT_FAILURE;
  1660. goto bail;
  1661. }
  1662. switch (smp->method) {
  1663. case IB_MGMT_METHOD_GET:
  1664. switch (smp->attr_id) {
  1665. case IB_SMP_ATTR_NODE_DESC:
  1666. ret = subn_get_nodedescription(smp, ibdev);
  1667. goto bail;
  1668. case IB_SMP_ATTR_NODE_INFO:
  1669. ret = subn_get_nodeinfo(smp, ibdev, port);
  1670. goto bail;
  1671. case IB_SMP_ATTR_GUID_INFO:
  1672. ret = subn_get_guidinfo(smp, ibdev, port);
  1673. goto bail;
  1674. case IB_SMP_ATTR_PORT_INFO:
  1675. ret = subn_get_portinfo(smp, ibdev, port);
  1676. goto bail;
  1677. case IB_SMP_ATTR_PKEY_TABLE:
  1678. ret = subn_get_pkeytable(smp, ibdev, port);
  1679. goto bail;
  1680. case IB_SMP_ATTR_SL_TO_VL_TABLE:
  1681. ret = subn_get_sl_to_vl(smp, ibdev, port);
  1682. goto bail;
  1683. case IB_SMP_ATTR_VL_ARB_TABLE:
  1684. ret = subn_get_vl_arb(smp, ibdev, port);
  1685. goto bail;
  1686. case IB_SMP_ATTR_SM_INFO:
  1687. if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) {
  1688. ret = IB_MAD_RESULT_SUCCESS |
  1689. IB_MAD_RESULT_CONSUMED;
  1690. goto bail;
  1691. }
  1692. if (ibp->port_cap_flags & IB_PORT_SM) {
  1693. ret = IB_MAD_RESULT_SUCCESS;
  1694. goto bail;
  1695. }
  1696. /* FALLTHROUGH */
  1697. default:
  1698. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1699. ret = reply(smp);
  1700. goto bail;
  1701. }
  1702. case IB_MGMT_METHOD_SET:
  1703. switch (smp->attr_id) {
  1704. case IB_SMP_ATTR_GUID_INFO:
  1705. ret = subn_set_guidinfo(smp, ibdev, port);
  1706. goto bail;
  1707. case IB_SMP_ATTR_PORT_INFO:
  1708. ret = subn_set_portinfo(smp, ibdev, port);
  1709. goto bail;
  1710. case IB_SMP_ATTR_PKEY_TABLE:
  1711. ret = subn_set_pkeytable(smp, ibdev, port);
  1712. goto bail;
  1713. case IB_SMP_ATTR_SL_TO_VL_TABLE:
  1714. ret = subn_set_sl_to_vl(smp, ibdev, port);
  1715. goto bail;
  1716. case IB_SMP_ATTR_VL_ARB_TABLE:
  1717. ret = subn_set_vl_arb(smp, ibdev, port);
  1718. goto bail;
  1719. case IB_SMP_ATTR_SM_INFO:
  1720. if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) {
  1721. ret = IB_MAD_RESULT_SUCCESS |
  1722. IB_MAD_RESULT_CONSUMED;
  1723. goto bail;
  1724. }
  1725. if (ibp->port_cap_flags & IB_PORT_SM) {
  1726. ret = IB_MAD_RESULT_SUCCESS;
  1727. goto bail;
  1728. }
  1729. /* FALLTHROUGH */
  1730. default:
  1731. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1732. ret = reply(smp);
  1733. goto bail;
  1734. }
  1735. case IB_MGMT_METHOD_TRAP_REPRESS:
  1736. if (smp->attr_id == IB_SMP_ATTR_NOTICE)
  1737. ret = subn_trap_repress(smp, ibdev, port);
  1738. else {
  1739. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1740. ret = reply(smp);
  1741. }
  1742. goto bail;
  1743. case IB_MGMT_METHOD_TRAP:
  1744. case IB_MGMT_METHOD_REPORT:
  1745. case IB_MGMT_METHOD_REPORT_RESP:
  1746. case IB_MGMT_METHOD_GET_RESP:
  1747. /*
  1748. * The ib_mad module will call us to process responses
  1749. * before checking for other consumers.
  1750. * Just tell the caller to process it normally.
  1751. */
  1752. ret = IB_MAD_RESULT_SUCCESS;
  1753. goto bail;
  1754. case IB_MGMT_METHOD_SEND:
  1755. if (ib_get_smp_direction(smp) &&
  1756. smp->attr_id == QIB_VENDOR_IPG) {
  1757. ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PORT,
  1758. smp->data[0]);
  1759. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  1760. } else
  1761. ret = IB_MAD_RESULT_SUCCESS;
  1762. goto bail;
  1763. default:
  1764. smp->status |= IB_SMP_UNSUP_METHOD;
  1765. ret = reply(smp);
  1766. }
  1767. bail:
  1768. return ret;
  1769. }
  1770. static int process_perf(struct ib_device *ibdev, u8 port,
  1771. const struct ib_mad *in_mad,
  1772. struct ib_mad *out_mad)
  1773. {
  1774. struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad;
  1775. int ret;
  1776. *out_mad = *in_mad;
  1777. if (pmp->mad_hdr.class_version != 1) {
  1778. pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
  1779. ret = reply((struct ib_smp *) pmp);
  1780. goto bail;
  1781. }
  1782. switch (pmp->mad_hdr.method) {
  1783. case IB_MGMT_METHOD_GET:
  1784. switch (pmp->mad_hdr.attr_id) {
  1785. case IB_PMA_CLASS_PORT_INFO:
  1786. ret = pma_get_classportinfo(pmp, ibdev);
  1787. goto bail;
  1788. case IB_PMA_PORT_SAMPLES_CONTROL:
  1789. ret = pma_get_portsamplescontrol(pmp, ibdev, port);
  1790. goto bail;
  1791. case IB_PMA_PORT_SAMPLES_RESULT:
  1792. ret = pma_get_portsamplesresult(pmp, ibdev, port);
  1793. goto bail;
  1794. case IB_PMA_PORT_SAMPLES_RESULT_EXT:
  1795. ret = pma_get_portsamplesresult_ext(pmp, ibdev, port);
  1796. goto bail;
  1797. case IB_PMA_PORT_COUNTERS:
  1798. ret = pma_get_portcounters(pmp, ibdev, port);
  1799. goto bail;
  1800. case IB_PMA_PORT_COUNTERS_EXT:
  1801. ret = pma_get_portcounters_ext(pmp, ibdev, port);
  1802. goto bail;
  1803. case IB_PMA_PORT_COUNTERS_CONG:
  1804. ret = pma_get_portcounters_cong(pmp, ibdev, port);
  1805. goto bail;
  1806. default:
  1807. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  1808. ret = reply((struct ib_smp *) pmp);
  1809. goto bail;
  1810. }
  1811. case IB_MGMT_METHOD_SET:
  1812. switch (pmp->mad_hdr.attr_id) {
  1813. case IB_PMA_PORT_SAMPLES_CONTROL:
  1814. ret = pma_set_portsamplescontrol(pmp, ibdev, port);
  1815. goto bail;
  1816. case IB_PMA_PORT_COUNTERS:
  1817. ret = pma_set_portcounters(pmp, ibdev, port);
  1818. goto bail;
  1819. case IB_PMA_PORT_COUNTERS_EXT:
  1820. ret = pma_set_portcounters_ext(pmp, ibdev, port);
  1821. goto bail;
  1822. case IB_PMA_PORT_COUNTERS_CONG:
  1823. ret = pma_set_portcounters_cong(pmp, ibdev, port);
  1824. goto bail;
  1825. default:
  1826. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  1827. ret = reply((struct ib_smp *) pmp);
  1828. goto bail;
  1829. }
  1830. case IB_MGMT_METHOD_TRAP:
  1831. case IB_MGMT_METHOD_GET_RESP:
  1832. /*
  1833. * The ib_mad module will call us to process responses
  1834. * before checking for other consumers.
  1835. * Just tell the caller to process it normally.
  1836. */
  1837. ret = IB_MAD_RESULT_SUCCESS;
  1838. goto bail;
  1839. default:
  1840. pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
  1841. ret = reply((struct ib_smp *) pmp);
  1842. }
  1843. bail:
  1844. return ret;
  1845. }
  1846. static int cc_get_classportinfo(struct ib_cc_mad *ccp,
  1847. struct ib_device *ibdev)
  1848. {
  1849. struct ib_cc_classportinfo_attr *p =
  1850. (struct ib_cc_classportinfo_attr *)ccp->mgmt_data;
  1851. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1852. p->base_version = 1;
  1853. p->class_version = 1;
  1854. p->cap_mask = 0;
  1855. /*
  1856. * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
  1857. */
  1858. p->resp_time_value = 18;
  1859. return reply((struct ib_smp *) ccp);
  1860. }
  1861. static int cc_get_congestion_info(struct ib_cc_mad *ccp,
  1862. struct ib_device *ibdev, u8 port)
  1863. {
  1864. struct ib_cc_info_attr *p =
  1865. (struct ib_cc_info_attr *)ccp->mgmt_data;
  1866. struct qib_ibport *ibp = to_iport(ibdev, port);
  1867. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1868. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1869. p->congestion_info = 0;
  1870. p->control_table_cap = ppd->cc_max_table_entries;
  1871. return reply((struct ib_smp *) ccp);
  1872. }
  1873. static int cc_get_congestion_setting(struct ib_cc_mad *ccp,
  1874. struct ib_device *ibdev, u8 port)
  1875. {
  1876. int i;
  1877. struct ib_cc_congestion_setting_attr *p =
  1878. (struct ib_cc_congestion_setting_attr *)ccp->mgmt_data;
  1879. struct qib_ibport *ibp = to_iport(ibdev, port);
  1880. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1881. struct ib_cc_congestion_entry_shadow *entries;
  1882. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1883. spin_lock(&ppd->cc_shadow_lock);
  1884. entries = ppd->congestion_entries_shadow->entries;
  1885. p->port_control = cpu_to_be16(
  1886. ppd->congestion_entries_shadow->port_control);
  1887. p->control_map = cpu_to_be16(
  1888. ppd->congestion_entries_shadow->control_map);
  1889. for (i = 0; i < IB_CC_CCS_ENTRIES; i++) {
  1890. p->entries[i].ccti_increase = entries[i].ccti_increase;
  1891. p->entries[i].ccti_timer = cpu_to_be16(entries[i].ccti_timer);
  1892. p->entries[i].trigger_threshold = entries[i].trigger_threshold;
  1893. p->entries[i].ccti_min = entries[i].ccti_min;
  1894. }
  1895. spin_unlock(&ppd->cc_shadow_lock);
  1896. return reply((struct ib_smp *) ccp);
  1897. }
  1898. static int cc_get_congestion_control_table(struct ib_cc_mad *ccp,
  1899. struct ib_device *ibdev, u8 port)
  1900. {
  1901. struct ib_cc_table_attr *p =
  1902. (struct ib_cc_table_attr *)ccp->mgmt_data;
  1903. struct qib_ibport *ibp = to_iport(ibdev, port);
  1904. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1905. u32 cct_block_index = be32_to_cpu(ccp->attr_mod);
  1906. u32 max_cct_block;
  1907. u32 cct_entry;
  1908. struct ib_cc_table_entry_shadow *entries;
  1909. int i;
  1910. /* Is the table index more than what is supported? */
  1911. if (cct_block_index > IB_CC_TABLE_CAP_DEFAULT - 1)
  1912. goto bail;
  1913. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1914. spin_lock(&ppd->cc_shadow_lock);
  1915. max_cct_block =
  1916. (ppd->ccti_entries_shadow->ccti_last_entry + 1)/IB_CCT_ENTRIES;
  1917. max_cct_block = max_cct_block ? max_cct_block - 1 : 0;
  1918. if (cct_block_index > max_cct_block) {
  1919. spin_unlock(&ppd->cc_shadow_lock);
  1920. goto bail;
  1921. }
  1922. ccp->attr_mod = cpu_to_be32(cct_block_index);
  1923. cct_entry = IB_CCT_ENTRIES * (cct_block_index + 1);
  1924. cct_entry--;
  1925. p->ccti_limit = cpu_to_be16(cct_entry);
  1926. entries = &ppd->ccti_entries_shadow->
  1927. entries[IB_CCT_ENTRIES * cct_block_index];
  1928. cct_entry %= IB_CCT_ENTRIES;
  1929. for (i = 0; i <= cct_entry; i++)
  1930. p->ccti_entries[i].entry = cpu_to_be16(entries[i].entry);
  1931. spin_unlock(&ppd->cc_shadow_lock);
  1932. return reply((struct ib_smp *) ccp);
  1933. bail:
  1934. return reply_failure((struct ib_smp *) ccp);
  1935. }
  1936. static int cc_set_congestion_setting(struct ib_cc_mad *ccp,
  1937. struct ib_device *ibdev, u8 port)
  1938. {
  1939. struct ib_cc_congestion_setting_attr *p =
  1940. (struct ib_cc_congestion_setting_attr *)ccp->mgmt_data;
  1941. struct qib_ibport *ibp = to_iport(ibdev, port);
  1942. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1943. int i;
  1944. ppd->cc_sl_control_map = be16_to_cpu(p->control_map);
  1945. for (i = 0; i < IB_CC_CCS_ENTRIES; i++) {
  1946. ppd->congestion_entries[i].ccti_increase =
  1947. p->entries[i].ccti_increase;
  1948. ppd->congestion_entries[i].ccti_timer =
  1949. be16_to_cpu(p->entries[i].ccti_timer);
  1950. ppd->congestion_entries[i].trigger_threshold =
  1951. p->entries[i].trigger_threshold;
  1952. ppd->congestion_entries[i].ccti_min =
  1953. p->entries[i].ccti_min;
  1954. }
  1955. return reply((struct ib_smp *) ccp);
  1956. }
  1957. static int cc_set_congestion_control_table(struct ib_cc_mad *ccp,
  1958. struct ib_device *ibdev, u8 port)
  1959. {
  1960. struct ib_cc_table_attr *p =
  1961. (struct ib_cc_table_attr *)ccp->mgmt_data;
  1962. struct qib_ibport *ibp = to_iport(ibdev, port);
  1963. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1964. u32 cct_block_index = be32_to_cpu(ccp->attr_mod);
  1965. u32 cct_entry;
  1966. struct ib_cc_table_entry_shadow *entries;
  1967. int i;
  1968. /* Is the table index more than what is supported? */
  1969. if (cct_block_index > IB_CC_TABLE_CAP_DEFAULT - 1)
  1970. goto bail;
  1971. /* If this packet is the first in the sequence then
  1972. * zero the total table entry count.
  1973. */
  1974. if (be16_to_cpu(p->ccti_limit) < IB_CCT_ENTRIES)
  1975. ppd->total_cct_entry = 0;
  1976. cct_entry = (be16_to_cpu(p->ccti_limit))%IB_CCT_ENTRIES;
  1977. /* ccti_limit is 0 to 63 */
  1978. ppd->total_cct_entry += (cct_entry + 1);
  1979. if (ppd->total_cct_entry > ppd->cc_supported_table_entries)
  1980. goto bail;
  1981. ppd->ccti_limit = be16_to_cpu(p->ccti_limit);
  1982. entries = ppd->ccti_entries + (IB_CCT_ENTRIES * cct_block_index);
  1983. for (i = 0; i <= cct_entry; i++)
  1984. entries[i].entry = be16_to_cpu(p->ccti_entries[i].entry);
  1985. spin_lock(&ppd->cc_shadow_lock);
  1986. ppd->ccti_entries_shadow->ccti_last_entry = ppd->total_cct_entry - 1;
  1987. memcpy(ppd->ccti_entries_shadow->entries, ppd->ccti_entries,
  1988. (ppd->total_cct_entry * sizeof(struct ib_cc_table_entry)));
  1989. ppd->congestion_entries_shadow->port_control = IB_CC_CCS_PC_SL_BASED;
  1990. ppd->congestion_entries_shadow->control_map = ppd->cc_sl_control_map;
  1991. memcpy(ppd->congestion_entries_shadow->entries, ppd->congestion_entries,
  1992. IB_CC_CCS_ENTRIES * sizeof(struct ib_cc_congestion_entry));
  1993. spin_unlock(&ppd->cc_shadow_lock);
  1994. return reply((struct ib_smp *) ccp);
  1995. bail:
  1996. return reply_failure((struct ib_smp *) ccp);
  1997. }
  1998. static int check_cc_key(struct qib_ibport *ibp,
  1999. struct ib_cc_mad *ccp, int mad_flags)
  2000. {
  2001. return 0;
  2002. }
  2003. static int process_cc(struct ib_device *ibdev, int mad_flags,
  2004. u8 port, const struct ib_mad *in_mad,
  2005. struct ib_mad *out_mad)
  2006. {
  2007. struct ib_cc_mad *ccp = (struct ib_cc_mad *)out_mad;
  2008. struct qib_ibport *ibp = to_iport(ibdev, port);
  2009. int ret;
  2010. *out_mad = *in_mad;
  2011. if (ccp->class_version != 2) {
  2012. ccp->status |= IB_SMP_UNSUP_VERSION;
  2013. ret = reply((struct ib_smp *)ccp);
  2014. goto bail;
  2015. }
  2016. ret = check_cc_key(ibp, ccp, mad_flags);
  2017. if (ret)
  2018. goto bail;
  2019. switch (ccp->method) {
  2020. case IB_MGMT_METHOD_GET:
  2021. switch (ccp->attr_id) {
  2022. case IB_CC_ATTR_CLASSPORTINFO:
  2023. ret = cc_get_classportinfo(ccp, ibdev);
  2024. goto bail;
  2025. case IB_CC_ATTR_CONGESTION_INFO:
  2026. ret = cc_get_congestion_info(ccp, ibdev, port);
  2027. goto bail;
  2028. case IB_CC_ATTR_CA_CONGESTION_SETTING:
  2029. ret = cc_get_congestion_setting(ccp, ibdev, port);
  2030. goto bail;
  2031. case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
  2032. ret = cc_get_congestion_control_table(ccp, ibdev, port);
  2033. goto bail;
  2034. /* FALLTHROUGH */
  2035. default:
  2036. ccp->status |= IB_SMP_UNSUP_METH_ATTR;
  2037. ret = reply((struct ib_smp *) ccp);
  2038. goto bail;
  2039. }
  2040. case IB_MGMT_METHOD_SET:
  2041. switch (ccp->attr_id) {
  2042. case IB_CC_ATTR_CA_CONGESTION_SETTING:
  2043. ret = cc_set_congestion_setting(ccp, ibdev, port);
  2044. goto bail;
  2045. case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
  2046. ret = cc_set_congestion_control_table(ccp, ibdev, port);
  2047. goto bail;
  2048. /* FALLTHROUGH */
  2049. default:
  2050. ccp->status |= IB_SMP_UNSUP_METH_ATTR;
  2051. ret = reply((struct ib_smp *) ccp);
  2052. goto bail;
  2053. }
  2054. case IB_MGMT_METHOD_GET_RESP:
  2055. /*
  2056. * The ib_mad module will call us to process responses
  2057. * before checking for other consumers.
  2058. * Just tell the caller to process it normally.
  2059. */
  2060. ret = IB_MAD_RESULT_SUCCESS;
  2061. goto bail;
  2062. case IB_MGMT_METHOD_TRAP:
  2063. default:
  2064. ccp->status |= IB_SMP_UNSUP_METHOD;
  2065. ret = reply((struct ib_smp *) ccp);
  2066. }
  2067. bail:
  2068. return ret;
  2069. }
  2070. /**
  2071. * qib_process_mad - process an incoming MAD packet
  2072. * @ibdev: the infiniband device this packet came in on
  2073. * @mad_flags: MAD flags
  2074. * @port: the port number this packet came in on
  2075. * @in_wc: the work completion entry for this packet
  2076. * @in_grh: the global route header for this packet
  2077. * @in_mad: the incoming MAD
  2078. * @out_mad: any outgoing MAD reply
  2079. *
  2080. * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
  2081. * interested in processing.
  2082. *
  2083. * Note that the verbs framework has already done the MAD sanity checks,
  2084. * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  2085. * MADs.
  2086. *
  2087. * This is called by the ib_mad module.
  2088. */
  2089. int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
  2090. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  2091. const struct ib_mad_hdr *in, size_t in_mad_size,
  2092. struct ib_mad_hdr *out, size_t *out_mad_size,
  2093. u16 *out_mad_pkey_index)
  2094. {
  2095. int ret;
  2096. struct qib_ibport *ibp = to_iport(ibdev, port);
  2097. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  2098. const struct ib_mad *in_mad = (const struct ib_mad *)in;
  2099. struct ib_mad *out_mad = (struct ib_mad *)out;
  2100. BUG_ON(in_mad_size != sizeof(*in_mad) ||
  2101. *out_mad_size != sizeof(*out_mad));
  2102. switch (in_mad->mad_hdr.mgmt_class) {
  2103. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  2104. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  2105. ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad);
  2106. goto bail;
  2107. case IB_MGMT_CLASS_PERF_MGMT:
  2108. ret = process_perf(ibdev, port, in_mad, out_mad);
  2109. goto bail;
  2110. case IB_MGMT_CLASS_CONG_MGMT:
  2111. if (!ppd->congestion_entries_shadow ||
  2112. !qib_cc_table_size) {
  2113. ret = IB_MAD_RESULT_SUCCESS;
  2114. goto bail;
  2115. }
  2116. ret = process_cc(ibdev, mad_flags, port, in_mad, out_mad);
  2117. goto bail;
  2118. default:
  2119. ret = IB_MAD_RESULT_SUCCESS;
  2120. }
  2121. bail:
  2122. return ret;
  2123. }
  2124. static void send_handler(struct ib_mad_agent *agent,
  2125. struct ib_mad_send_wc *mad_send_wc)
  2126. {
  2127. ib_free_send_mad(mad_send_wc->send_buf);
  2128. }
  2129. static void xmit_wait_timer_func(unsigned long opaque)
  2130. {
  2131. struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
  2132. struct qib_devdata *dd = dd_from_ppd(ppd);
  2133. unsigned long flags;
  2134. u8 status;
  2135. spin_lock_irqsave(&ppd->ibport_data.lock, flags);
  2136. if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_SAMPLE) {
  2137. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  2138. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  2139. /* save counter cache */
  2140. cache_hw_sample_counters(ppd);
  2141. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
  2142. } else
  2143. goto done;
  2144. }
  2145. ppd->cong_stats.counter = xmit_wait_get_value_delta(ppd);
  2146. dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, 0x0);
  2147. done:
  2148. spin_unlock_irqrestore(&ppd->ibport_data.lock, flags);
  2149. mod_timer(&ppd->cong_stats.timer, jiffies + HZ);
  2150. }
  2151. int qib_create_agents(struct qib_ibdev *dev)
  2152. {
  2153. struct qib_devdata *dd = dd_from_dev(dev);
  2154. struct ib_mad_agent *agent;
  2155. struct qib_ibport *ibp;
  2156. int p;
  2157. int ret;
  2158. for (p = 0; p < dd->num_pports; p++) {
  2159. ibp = &dd->pport[p].ibport_data;
  2160. agent = ib_register_mad_agent(&dev->ibdev, p + 1, IB_QPT_SMI,
  2161. NULL, 0, send_handler,
  2162. NULL, NULL, 0);
  2163. if (IS_ERR(agent)) {
  2164. ret = PTR_ERR(agent);
  2165. goto err;
  2166. }
  2167. /* Initialize xmit_wait structure */
  2168. dd->pport[p].cong_stats.counter = 0;
  2169. init_timer(&dd->pport[p].cong_stats.timer);
  2170. dd->pport[p].cong_stats.timer.function = xmit_wait_timer_func;
  2171. dd->pport[p].cong_stats.timer.data =
  2172. (unsigned long)(&dd->pport[p]);
  2173. dd->pport[p].cong_stats.timer.expires = 0;
  2174. add_timer(&dd->pport[p].cong_stats.timer);
  2175. ibp->send_agent = agent;
  2176. }
  2177. return 0;
  2178. err:
  2179. for (p = 0; p < dd->num_pports; p++) {
  2180. ibp = &dd->pport[p].ibport_data;
  2181. if (ibp->send_agent) {
  2182. agent = ibp->send_agent;
  2183. ibp->send_agent = NULL;
  2184. ib_unregister_mad_agent(agent);
  2185. }
  2186. }
  2187. return ret;
  2188. }
  2189. void qib_free_agents(struct qib_ibdev *dev)
  2190. {
  2191. struct qib_devdata *dd = dd_from_dev(dev);
  2192. struct ib_mad_agent *agent;
  2193. struct qib_ibport *ibp;
  2194. int p;
  2195. for (p = 0; p < dd->num_pports; p++) {
  2196. ibp = &dd->pport[p].ibport_data;
  2197. if (ibp->send_agent) {
  2198. agent = ibp->send_agent;
  2199. ibp->send_agent = NULL;
  2200. ib_unregister_mad_agent(agent);
  2201. }
  2202. if (ibp->sm_ah) {
  2203. ib_destroy_ah(&ibp->sm_ah->ibah);
  2204. ibp->sm_ah = NULL;
  2205. }
  2206. if (dd->pport[p].cong_stats.timer.data)
  2207. del_timer_sync(&dd->pport[p].cong_stats.timer);
  2208. }
  2209. }