qib_mad.c 71 KB

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