ipath_mad.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  1. /*
  2. * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <rdma/ib_smi.h>
  34. #include "ipath_kernel.h"
  35. #include "ipath_verbs.h"
  36. #include "ipath_common.h"
  37. #define IB_SMP_UNSUP_VERSION cpu_to_be16(0x0004)
  38. #define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
  39. #define IB_SMP_UNSUP_METH_ATTR cpu_to_be16(0x000C)
  40. #define IB_SMP_INVALID_FIELD cpu_to_be16(0x001C)
  41. static int reply(struct ib_smp *smp)
  42. {
  43. /*
  44. * The verbs framework will handle the directed/LID route
  45. * packet changes.
  46. */
  47. smp->method = IB_MGMT_METHOD_GET_RESP;
  48. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  49. smp->status |= IB_SMP_DIRECTION;
  50. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  51. }
  52. static int recv_subn_get_nodedescription(struct ib_smp *smp,
  53. struct ib_device *ibdev)
  54. {
  55. if (smp->attr_mod)
  56. smp->status |= IB_SMP_INVALID_FIELD;
  57. strncpy(smp->data, ibdev->node_desc, sizeof(smp->data));
  58. return reply(smp);
  59. }
  60. struct nodeinfo {
  61. u8 base_version;
  62. u8 class_version;
  63. u8 node_type;
  64. u8 num_ports;
  65. __be64 sys_guid;
  66. __be64 node_guid;
  67. __be64 port_guid;
  68. __be16 partition_cap;
  69. __be16 device_id;
  70. __be32 revision;
  71. u8 local_port_num;
  72. u8 vendor_id[3];
  73. } __attribute__ ((packed));
  74. static int recv_subn_get_nodeinfo(struct ib_smp *smp,
  75. struct ib_device *ibdev, u8 port)
  76. {
  77. struct nodeinfo *nip = (struct nodeinfo *)&smp->data;
  78. struct ipath_devdata *dd = to_idev(ibdev)->dd;
  79. u32 vendor, majrev, minrev;
  80. /* GUID 0 is illegal */
  81. if (smp->attr_mod || (dd->ipath_guid == 0))
  82. smp->status |= IB_SMP_INVALID_FIELD;
  83. nip->base_version = 1;
  84. nip->class_version = 1;
  85. nip->node_type = 1; /* channel adapter */
  86. /*
  87. * XXX The num_ports value will need a layer function to get
  88. * the value if we ever have more than one IB port on a chip.
  89. * We will also need to get the GUID for the port.
  90. */
  91. nip->num_ports = ibdev->phys_port_cnt;
  92. /* This is already in network order */
  93. nip->sys_guid = to_idev(ibdev)->sys_image_guid;
  94. nip->node_guid = dd->ipath_guid;
  95. nip->port_guid = dd->ipath_guid;
  96. nip->partition_cap = cpu_to_be16(ipath_get_npkeys(dd));
  97. nip->device_id = cpu_to_be16(dd->ipath_deviceid);
  98. majrev = dd->ipath_majrev;
  99. minrev = dd->ipath_minrev;
  100. nip->revision = cpu_to_be32((majrev << 16) | minrev);
  101. nip->local_port_num = port;
  102. vendor = dd->ipath_vendorid;
  103. nip->vendor_id[0] = IPATH_SRC_OUI_1;
  104. nip->vendor_id[1] = IPATH_SRC_OUI_2;
  105. nip->vendor_id[2] = IPATH_SRC_OUI_3;
  106. return reply(smp);
  107. }
  108. static int recv_subn_get_guidinfo(struct ib_smp *smp,
  109. struct ib_device *ibdev)
  110. {
  111. u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
  112. __be64 *p = (__be64 *) smp->data;
  113. /* 32 blocks of 8 64-bit GUIDs per block */
  114. memset(smp->data, 0, sizeof(smp->data));
  115. /*
  116. * We only support one GUID for now. If this changes, the
  117. * portinfo.guid_cap field needs to be updated too.
  118. */
  119. if (startgx == 0) {
  120. __be64 g = to_idev(ibdev)->dd->ipath_guid;
  121. if (g == 0)
  122. /* GUID 0 is illegal */
  123. smp->status |= IB_SMP_INVALID_FIELD;
  124. else
  125. /* The first is a copy of the read-only HW GUID. */
  126. *p = g;
  127. } else
  128. smp->status |= IB_SMP_INVALID_FIELD;
  129. return reply(smp);
  130. }
  131. static void set_link_width_enabled(struct ipath_devdata *dd, u32 w)
  132. {
  133. (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, w);
  134. }
  135. static void set_link_speed_enabled(struct ipath_devdata *dd, u32 s)
  136. {
  137. (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, s);
  138. }
  139. static int get_overrunthreshold(struct ipath_devdata *dd)
  140. {
  141. return (dd->ipath_ibcctrl >>
  142. INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
  143. INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
  144. }
  145. /**
  146. * set_overrunthreshold - set the overrun threshold
  147. * @dd: the infinipath device
  148. * @n: the new threshold
  149. *
  150. * Note that this will only take effect when the link state changes.
  151. */
  152. static int set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
  153. {
  154. unsigned v;
  155. v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
  156. INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
  157. if (v != n) {
  158. dd->ipath_ibcctrl &=
  159. ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
  160. INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
  161. dd->ipath_ibcctrl |=
  162. (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
  163. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  164. dd->ipath_ibcctrl);
  165. }
  166. return 0;
  167. }
  168. static int get_phyerrthreshold(struct ipath_devdata *dd)
  169. {
  170. return (dd->ipath_ibcctrl >>
  171. INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
  172. INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
  173. }
  174. /**
  175. * set_phyerrthreshold - set the physical error threshold
  176. * @dd: the infinipath device
  177. * @n: the new threshold
  178. *
  179. * Note that this will only take effect when the link state changes.
  180. */
  181. static int set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
  182. {
  183. unsigned v;
  184. v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
  185. INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
  186. if (v != n) {
  187. dd->ipath_ibcctrl &=
  188. ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
  189. INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
  190. dd->ipath_ibcctrl |=
  191. (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
  192. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  193. dd->ipath_ibcctrl);
  194. }
  195. return 0;
  196. }
  197. /**
  198. * get_linkdowndefaultstate - get the default linkdown state
  199. * @dd: the infinipath device
  200. *
  201. * Returns zero if the default is POLL, 1 if the default is SLEEP.
  202. */
  203. static int get_linkdowndefaultstate(struct ipath_devdata *dd)
  204. {
  205. return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
  206. }
  207. static int recv_subn_get_portinfo(struct ib_smp *smp,
  208. struct ib_device *ibdev, u8 port)
  209. {
  210. struct ipath_ibdev *dev;
  211. struct ipath_devdata *dd;
  212. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  213. u16 lid;
  214. u8 ibcstat;
  215. u8 mtu;
  216. int ret;
  217. if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
  218. smp->status |= IB_SMP_INVALID_FIELD;
  219. ret = reply(smp);
  220. goto bail;
  221. }
  222. dev = to_idev(ibdev);
  223. dd = dev->dd;
  224. /* Clear all fields. Only set the non-zero fields. */
  225. memset(smp->data, 0, sizeof(smp->data));
  226. /* Only return the mkey if the protection field allows it. */
  227. if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
  228. dev->mkeyprot == 0)
  229. pip->mkey = dev->mkey;
  230. pip->gid_prefix = dev->gid_prefix;
  231. lid = dd->ipath_lid;
  232. pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
  233. pip->sm_lid = cpu_to_be16(dev->sm_lid);
  234. pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
  235. /* pip->diag_code; */
  236. pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
  237. pip->local_port_num = port;
  238. pip->link_width_enabled = dd->ipath_link_width_enabled;
  239. pip->link_width_supported = dd->ipath_link_width_supported;
  240. pip->link_width_active = dd->ipath_link_width_active;
  241. pip->linkspeed_portstate = dd->ipath_link_speed_supported << 4;
  242. ibcstat = dd->ipath_lastibcstat;
  243. /* map LinkState to IB portinfo values. */
  244. pip->linkspeed_portstate |= ipath_ib_linkstate(dd, ibcstat) + 1;
  245. pip->portphysstate_linkdown =
  246. (ipath_cvt_physportstate[ibcstat & dd->ibcs_lts_mask] << 4) |
  247. (get_linkdowndefaultstate(dd) ? 1 : 2);
  248. pip->mkeyprot_resv_lmc = (dev->mkeyprot << 6) | dd->ipath_lmc;
  249. pip->linkspeedactive_enabled = (dd->ipath_link_speed_active << 4) |
  250. dd->ipath_link_speed_enabled;
  251. switch (dd->ipath_ibmtu) {
  252. case 4096:
  253. mtu = IB_MTU_4096;
  254. break;
  255. case 2048:
  256. mtu = IB_MTU_2048;
  257. break;
  258. case 1024:
  259. mtu = IB_MTU_1024;
  260. break;
  261. case 512:
  262. mtu = IB_MTU_512;
  263. break;
  264. case 256:
  265. mtu = IB_MTU_256;
  266. break;
  267. default: /* oops, something is wrong */
  268. mtu = IB_MTU_2048;
  269. break;
  270. }
  271. pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
  272. pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
  273. pip->vl_high_limit = dev->vl_high_limit;
  274. /* pip->vl_arb_high_cap; // only one VL */
  275. /* pip->vl_arb_low_cap; // only one VL */
  276. /* InitTypeReply = 0 */
  277. /* our mtu cap depends on whether 4K MTU enabled or not */
  278. pip->inittypereply_mtucap = ipath_mtu4096 ? IB_MTU_4096 : IB_MTU_2048;
  279. /* HCAs ignore VLStallCount and HOQLife */
  280. /* pip->vlstallcnt_hoqlife; */
  281. pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
  282. pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
  283. /* P_KeyViolations are counted by hardware. */
  284. pip->pkey_violations =
  285. cpu_to_be16((ipath_get_cr_errpkey(dd) -
  286. dev->z_pkey_violations) & 0xFFFF);
  287. pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
  288. /* Only the hardware GUID is supported for now */
  289. pip->guid_cap = 1;
  290. pip->clientrereg_resv_subnetto = dev->subnet_timeout;
  291. /* 32.768 usec. response time (guessing) */
  292. pip->resv_resptimevalue = 3;
  293. pip->localphyerrors_overrunerrors =
  294. (get_phyerrthreshold(dd) << 4) |
  295. get_overrunthreshold(dd);
  296. /* pip->max_credit_hint; */
  297. if (dev->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
  298. u32 v;
  299. v = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LINKLATENCY);
  300. pip->link_roundtrip_latency[0] = v >> 16;
  301. pip->link_roundtrip_latency[1] = v >> 8;
  302. pip->link_roundtrip_latency[2] = v;
  303. }
  304. ret = reply(smp);
  305. bail:
  306. return ret;
  307. }
  308. /**
  309. * get_pkeys - return the PKEY table for port 0
  310. * @dd: the infinipath device
  311. * @pkeys: the pkey table is placed here
  312. */
  313. static int get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
  314. {
  315. /* always a kernel port, no locking needed */
  316. struct ipath_portdata *pd = dd->ipath_pd[0];
  317. memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
  318. return 0;
  319. }
  320. static int recv_subn_get_pkeytable(struct ib_smp *smp,
  321. struct ib_device *ibdev)
  322. {
  323. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  324. u16 *p = (u16 *) smp->data;
  325. __be16 *q = (__be16 *) smp->data;
  326. /* 64 blocks of 32 16-bit P_Key entries */
  327. memset(smp->data, 0, sizeof(smp->data));
  328. if (startpx == 0) {
  329. struct ipath_ibdev *dev = to_idev(ibdev);
  330. unsigned i, n = ipath_get_npkeys(dev->dd);
  331. get_pkeys(dev->dd, p);
  332. for (i = 0; i < n; i++)
  333. q[i] = cpu_to_be16(p[i]);
  334. } else
  335. smp->status |= IB_SMP_INVALID_FIELD;
  336. return reply(smp);
  337. }
  338. static int recv_subn_set_guidinfo(struct ib_smp *smp,
  339. struct ib_device *ibdev)
  340. {
  341. /* The only GUID we support is the first read-only entry. */
  342. return recv_subn_get_guidinfo(smp, ibdev);
  343. }
  344. /**
  345. * set_linkdowndefaultstate - set the default linkdown state
  346. * @dd: the infinipath device
  347. * @sleep: the new state
  348. *
  349. * Note that this will only take effect when the link state changes.
  350. */
  351. static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
  352. {
  353. if (sleep)
  354. dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
  355. else
  356. dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
  357. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  358. dd->ipath_ibcctrl);
  359. return 0;
  360. }
  361. /**
  362. * recv_subn_set_portinfo - set port information
  363. * @smp: the incoming SM packet
  364. * @ibdev: the infiniband device
  365. * @port: the port on the device
  366. *
  367. * Set Portinfo (see ch. 14.2.5.6).
  368. */
  369. static int recv_subn_set_portinfo(struct ib_smp *smp,
  370. struct ib_device *ibdev, u8 port)
  371. {
  372. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  373. struct ib_event event;
  374. struct ipath_ibdev *dev;
  375. struct ipath_devdata *dd;
  376. char clientrereg = 0;
  377. u16 lid, smlid;
  378. u8 lwe;
  379. u8 lse;
  380. u8 state;
  381. u16 lstate;
  382. u32 mtu;
  383. int ret, ore;
  384. if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
  385. goto err;
  386. dev = to_idev(ibdev);
  387. dd = dev->dd;
  388. event.device = ibdev;
  389. event.element.port_num = port;
  390. dev->mkey = pip->mkey;
  391. dev->gid_prefix = pip->gid_prefix;
  392. dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
  393. lid = be16_to_cpu(pip->lid);
  394. if (dd->ipath_lid != lid ||
  395. dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
  396. /* Must be a valid unicast LID address. */
  397. if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
  398. goto err;
  399. ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
  400. event.event = IB_EVENT_LID_CHANGE;
  401. ib_dispatch_event(&event);
  402. }
  403. smlid = be16_to_cpu(pip->sm_lid);
  404. if (smlid != dev->sm_lid) {
  405. /* Must be a valid unicast LID address. */
  406. if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
  407. goto err;
  408. dev->sm_lid = smlid;
  409. event.event = IB_EVENT_SM_CHANGE;
  410. ib_dispatch_event(&event);
  411. }
  412. /* Allow 1x or 4x to be set (see 14.2.6.6). */
  413. lwe = pip->link_width_enabled;
  414. if (lwe) {
  415. if (lwe == 0xFF)
  416. lwe = dd->ipath_link_width_supported;
  417. else if (lwe >= 16 || (lwe & ~dd->ipath_link_width_supported))
  418. goto err;
  419. set_link_width_enabled(dd, lwe);
  420. }
  421. /* Allow 2.5 or 5.0 Gbs. */
  422. lse = pip->linkspeedactive_enabled & 0xF;
  423. if (lse) {
  424. if (lse == 15)
  425. lse = dd->ipath_link_speed_supported;
  426. else if (lse >= 8 || (lse & ~dd->ipath_link_speed_supported))
  427. goto err;
  428. set_link_speed_enabled(dd, lse);
  429. }
  430. /* Set link down default state. */
  431. switch (pip->portphysstate_linkdown & 0xF) {
  432. case 0: /* NOP */
  433. break;
  434. case 1: /* SLEEP */
  435. if (set_linkdowndefaultstate(dd, 1))
  436. goto err;
  437. break;
  438. case 2: /* POLL */
  439. if (set_linkdowndefaultstate(dd, 0))
  440. goto err;
  441. break;
  442. default:
  443. goto err;
  444. }
  445. dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
  446. dev->vl_high_limit = pip->vl_high_limit;
  447. switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
  448. case IB_MTU_256:
  449. mtu = 256;
  450. break;
  451. case IB_MTU_512:
  452. mtu = 512;
  453. break;
  454. case IB_MTU_1024:
  455. mtu = 1024;
  456. break;
  457. case IB_MTU_2048:
  458. mtu = 2048;
  459. break;
  460. case IB_MTU_4096:
  461. if (!ipath_mtu4096)
  462. goto err;
  463. mtu = 4096;
  464. break;
  465. default:
  466. /* XXX We have already partially updated our state! */
  467. goto err;
  468. }
  469. ipath_set_mtu(dd, mtu);
  470. dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
  471. /* We only support VL0 */
  472. if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
  473. goto err;
  474. if (pip->mkey_violations == 0)
  475. dev->mkey_violations = 0;
  476. /*
  477. * Hardware counter can't be reset so snapshot and subtract
  478. * later.
  479. */
  480. if (pip->pkey_violations == 0)
  481. dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
  482. if (pip->qkey_violations == 0)
  483. dev->qkey_violations = 0;
  484. ore = pip->localphyerrors_overrunerrors;
  485. if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
  486. goto err;
  487. if (set_overrunthreshold(dd, (ore & 0xF)))
  488. goto err;
  489. dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
  490. if (pip->clientrereg_resv_subnetto & 0x80) {
  491. clientrereg = 1;
  492. event.event = IB_EVENT_CLIENT_REREGISTER;
  493. ib_dispatch_event(&event);
  494. }
  495. /*
  496. * Do the port state change now that the other link parameters
  497. * have been set.
  498. * Changing the port physical state only makes sense if the link
  499. * is down or is being set to down.
  500. */
  501. state = pip->linkspeed_portstate & 0xF;
  502. lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
  503. if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
  504. goto err;
  505. /*
  506. * Only state changes of DOWN, ARM, and ACTIVE are valid
  507. * and must be in the correct state to take effect (see 7.2.6).
  508. */
  509. switch (state) {
  510. case IB_PORT_NOP:
  511. if (lstate == 0)
  512. break;
  513. /* FALLTHROUGH */
  514. case IB_PORT_DOWN:
  515. if (lstate == 0)
  516. lstate = IPATH_IB_LINKDOWN_ONLY;
  517. else if (lstate == 1)
  518. lstate = IPATH_IB_LINKDOWN_SLEEP;
  519. else if (lstate == 2)
  520. lstate = IPATH_IB_LINKDOWN;
  521. else if (lstate == 3)
  522. lstate = IPATH_IB_LINKDOWN_DISABLE;
  523. else
  524. goto err;
  525. ipath_set_linkstate(dd, lstate);
  526. if (lstate == IPATH_IB_LINKDOWN_DISABLE) {
  527. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  528. goto done;
  529. }
  530. ipath_wait_linkstate(dd, IPATH_LINKINIT | IPATH_LINKARMED |
  531. IPATH_LINKACTIVE, 1000);
  532. break;
  533. case IB_PORT_ARMED:
  534. ipath_set_linkstate(dd, IPATH_IB_LINKARM);
  535. break;
  536. case IB_PORT_ACTIVE:
  537. ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
  538. break;
  539. default:
  540. /* XXX We have already partially updated our state! */
  541. goto err;
  542. }
  543. ret = recv_subn_get_portinfo(smp, ibdev, port);
  544. if (clientrereg)
  545. pip->clientrereg_resv_subnetto |= 0x80;
  546. goto done;
  547. err:
  548. smp->status |= IB_SMP_INVALID_FIELD;
  549. ret = recv_subn_get_portinfo(smp, ibdev, port);
  550. done:
  551. return ret;
  552. }
  553. /**
  554. * rm_pkey - decrecment the reference count for the given PKEY
  555. * @dd: the infinipath device
  556. * @key: the PKEY index
  557. *
  558. * Return true if this was the last reference and the hardware table entry
  559. * needs to be changed.
  560. */
  561. static int rm_pkey(struct ipath_devdata *dd, u16 key)
  562. {
  563. int i;
  564. int ret;
  565. for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
  566. if (dd->ipath_pkeys[i] != key)
  567. continue;
  568. if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
  569. dd->ipath_pkeys[i] = 0;
  570. ret = 1;
  571. goto bail;
  572. }
  573. break;
  574. }
  575. ret = 0;
  576. bail:
  577. return ret;
  578. }
  579. /**
  580. * add_pkey - add the given PKEY to the hardware table
  581. * @dd: the infinipath device
  582. * @key: the PKEY
  583. *
  584. * Return an error code if unable to add the entry, zero if no change,
  585. * or 1 if the hardware PKEY register needs to be updated.
  586. */
  587. static int add_pkey(struct ipath_devdata *dd, u16 key)
  588. {
  589. int i;
  590. u16 lkey = key & 0x7FFF;
  591. int any = 0;
  592. int ret;
  593. if (lkey == 0x7FFF) {
  594. ret = 0;
  595. goto bail;
  596. }
  597. /* Look for an empty slot or a matching PKEY. */
  598. for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
  599. if (!dd->ipath_pkeys[i]) {
  600. any++;
  601. continue;
  602. }
  603. /* If it matches exactly, try to increment the ref count */
  604. if (dd->ipath_pkeys[i] == key) {
  605. if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
  606. ret = 0;
  607. goto bail;
  608. }
  609. /* Lost the race. Look for an empty slot below. */
  610. atomic_dec(&dd->ipath_pkeyrefs[i]);
  611. any++;
  612. }
  613. /*
  614. * It makes no sense to have both the limited and unlimited
  615. * PKEY set at the same time since the unlimited one will
  616. * disable the limited one.
  617. */
  618. if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
  619. ret = -EEXIST;
  620. goto bail;
  621. }
  622. }
  623. if (!any) {
  624. ret = -EBUSY;
  625. goto bail;
  626. }
  627. for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
  628. if (!dd->ipath_pkeys[i] &&
  629. atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
  630. /* for ipathstats, etc. */
  631. ipath_stats.sps_pkeys[i] = lkey;
  632. dd->ipath_pkeys[i] = key;
  633. ret = 1;
  634. goto bail;
  635. }
  636. }
  637. ret = -EBUSY;
  638. bail:
  639. return ret;
  640. }
  641. /**
  642. * set_pkeys - set the PKEY table for port 0
  643. * @dd: the infinipath device
  644. * @pkeys: the PKEY table
  645. */
  646. static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
  647. {
  648. struct ipath_portdata *pd;
  649. int i;
  650. int changed = 0;
  651. /* always a kernel port, no locking needed */
  652. pd = dd->ipath_pd[0];
  653. for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
  654. u16 key = pkeys[i];
  655. u16 okey = pd->port_pkeys[i];
  656. if (key == okey)
  657. continue;
  658. /*
  659. * The value of this PKEY table entry is changing.
  660. * Remove the old entry in the hardware's array of PKEYs.
  661. */
  662. if (okey & 0x7FFF)
  663. changed |= rm_pkey(dd, okey);
  664. if (key & 0x7FFF) {
  665. int ret = add_pkey(dd, key);
  666. if (ret < 0)
  667. key = 0;
  668. else
  669. changed |= ret;
  670. }
  671. pd->port_pkeys[i] = key;
  672. }
  673. if (changed) {
  674. u64 pkey;
  675. pkey = (u64) dd->ipath_pkeys[0] |
  676. ((u64) dd->ipath_pkeys[1] << 16) |
  677. ((u64) dd->ipath_pkeys[2] << 32) |
  678. ((u64) dd->ipath_pkeys[3] << 48);
  679. ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
  680. (unsigned long long) pkey);
  681. ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
  682. pkey);
  683. }
  684. return 0;
  685. }
  686. static int recv_subn_set_pkeytable(struct ib_smp *smp,
  687. struct ib_device *ibdev)
  688. {
  689. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  690. __be16 *p = (__be16 *) smp->data;
  691. u16 *q = (u16 *) smp->data;
  692. struct ipath_ibdev *dev = to_idev(ibdev);
  693. unsigned i, n = ipath_get_npkeys(dev->dd);
  694. for (i = 0; i < n; i++)
  695. q[i] = be16_to_cpu(p[i]);
  696. if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
  697. smp->status |= IB_SMP_INVALID_FIELD;
  698. return recv_subn_get_pkeytable(smp, ibdev);
  699. }
  700. #define IB_PMA_CLASS_PORT_INFO cpu_to_be16(0x0001)
  701. #define IB_PMA_PORT_SAMPLES_CONTROL cpu_to_be16(0x0010)
  702. #define IB_PMA_PORT_SAMPLES_RESULT cpu_to_be16(0x0011)
  703. #define IB_PMA_PORT_COUNTERS cpu_to_be16(0x0012)
  704. #define IB_PMA_PORT_COUNTERS_EXT cpu_to_be16(0x001D)
  705. #define IB_PMA_PORT_SAMPLES_RESULT_EXT cpu_to_be16(0x001E)
  706. struct ib_perf {
  707. u8 base_version;
  708. u8 mgmt_class;
  709. u8 class_version;
  710. u8 method;
  711. __be16 status;
  712. __be16 unused;
  713. __be64 tid;
  714. __be16 attr_id;
  715. __be16 resv;
  716. __be32 attr_mod;
  717. u8 reserved[40];
  718. u8 data[192];
  719. } __attribute__ ((packed));
  720. struct ib_pma_classportinfo {
  721. u8 base_version;
  722. u8 class_version;
  723. __be16 cap_mask;
  724. u8 reserved[3];
  725. u8 resp_time_value; /* only lower 5 bits */
  726. union ib_gid redirect_gid;
  727. __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
  728. __be16 redirect_lid;
  729. __be16 redirect_pkey;
  730. __be32 redirect_qp; /* only lower 24 bits */
  731. __be32 redirect_qkey;
  732. union ib_gid trap_gid;
  733. __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
  734. __be16 trap_lid;
  735. __be16 trap_pkey;
  736. __be32 trap_hl_qp; /* 8, 24 bits respectively */
  737. __be32 trap_qkey;
  738. } __attribute__ ((packed));
  739. struct ib_pma_portsamplescontrol {
  740. u8 opcode;
  741. u8 port_select;
  742. u8 tick;
  743. u8 counter_width; /* only lower 3 bits */
  744. __be32 counter_mask0_9; /* 2, 10 * 3, bits */
  745. __be16 counter_mask10_14; /* 1, 5 * 3, bits */
  746. u8 sample_mechanisms;
  747. u8 sample_status; /* only lower 2 bits */
  748. __be64 option_mask;
  749. __be64 vendor_mask;
  750. __be32 sample_start;
  751. __be32 sample_interval;
  752. __be16 tag;
  753. __be16 counter_select[15];
  754. } __attribute__ ((packed));
  755. struct ib_pma_portsamplesresult {
  756. __be16 tag;
  757. __be16 sample_status; /* only lower 2 bits */
  758. __be32 counter[15];
  759. } __attribute__ ((packed));
  760. struct ib_pma_portsamplesresult_ext {
  761. __be16 tag;
  762. __be16 sample_status; /* only lower 2 bits */
  763. __be32 extended_width; /* only upper 2 bits */
  764. __be64 counter[15];
  765. } __attribute__ ((packed));
  766. struct ib_pma_portcounters {
  767. u8 reserved;
  768. u8 port_select;
  769. __be16 counter_select;
  770. __be16 symbol_error_counter;
  771. u8 link_error_recovery_counter;
  772. u8 link_downed_counter;
  773. __be16 port_rcv_errors;
  774. __be16 port_rcv_remphys_errors;
  775. __be16 port_rcv_switch_relay_errors;
  776. __be16 port_xmit_discards;
  777. u8 port_xmit_constraint_errors;
  778. u8 port_rcv_constraint_errors;
  779. u8 reserved1;
  780. u8 lli_ebor_errors; /* 4, 4, bits */
  781. __be16 reserved2;
  782. __be16 vl15_dropped;
  783. __be32 port_xmit_data;
  784. __be32 port_rcv_data;
  785. __be32 port_xmit_packets;
  786. __be32 port_rcv_packets;
  787. } __attribute__ ((packed));
  788. #define IB_PMA_SEL_SYMBOL_ERROR cpu_to_be16(0x0001)
  789. #define IB_PMA_SEL_LINK_ERROR_RECOVERY cpu_to_be16(0x0002)
  790. #define IB_PMA_SEL_LINK_DOWNED cpu_to_be16(0x0004)
  791. #define IB_PMA_SEL_PORT_RCV_ERRORS cpu_to_be16(0x0008)
  792. #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS cpu_to_be16(0x0010)
  793. #define IB_PMA_SEL_PORT_XMIT_DISCARDS cpu_to_be16(0x0040)
  794. #define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS cpu_to_be16(0x0200)
  795. #define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS cpu_to_be16(0x0400)
  796. #define IB_PMA_SEL_PORT_VL15_DROPPED cpu_to_be16(0x0800)
  797. #define IB_PMA_SEL_PORT_XMIT_DATA cpu_to_be16(0x1000)
  798. #define IB_PMA_SEL_PORT_RCV_DATA cpu_to_be16(0x2000)
  799. #define IB_PMA_SEL_PORT_XMIT_PACKETS cpu_to_be16(0x4000)
  800. #define IB_PMA_SEL_PORT_RCV_PACKETS cpu_to_be16(0x8000)
  801. struct ib_pma_portcounters_ext {
  802. u8 reserved;
  803. u8 port_select;
  804. __be16 counter_select;
  805. __be32 reserved1;
  806. __be64 port_xmit_data;
  807. __be64 port_rcv_data;
  808. __be64 port_xmit_packets;
  809. __be64 port_rcv_packets;
  810. __be64 port_unicast_xmit_packets;
  811. __be64 port_unicast_rcv_packets;
  812. __be64 port_multicast_xmit_packets;
  813. __be64 port_multicast_rcv_packets;
  814. } __attribute__ ((packed));
  815. #define IB_PMA_SELX_PORT_XMIT_DATA cpu_to_be16(0x0001)
  816. #define IB_PMA_SELX_PORT_RCV_DATA cpu_to_be16(0x0002)
  817. #define IB_PMA_SELX_PORT_XMIT_PACKETS cpu_to_be16(0x0004)
  818. #define IB_PMA_SELX_PORT_RCV_PACKETS cpu_to_be16(0x0008)
  819. #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS cpu_to_be16(0x0010)
  820. #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS cpu_to_be16(0x0020)
  821. #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS cpu_to_be16(0x0040)
  822. #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS cpu_to_be16(0x0080)
  823. static int recv_pma_get_classportinfo(struct ib_perf *pmp)
  824. {
  825. struct ib_pma_classportinfo *p =
  826. (struct ib_pma_classportinfo *)pmp->data;
  827. memset(pmp->data, 0, sizeof(pmp->data));
  828. if (pmp->attr_mod != 0)
  829. pmp->status |= IB_SMP_INVALID_FIELD;
  830. /* Indicate AllPortSelect is valid (only one port anyway) */
  831. p->cap_mask = cpu_to_be16(1 << 8);
  832. p->base_version = 1;
  833. p->class_version = 1;
  834. /*
  835. * Expected response time is 4.096 usec. * 2^18 == 1.073741824
  836. * sec.
  837. */
  838. p->resp_time_value = 18;
  839. return reply((struct ib_smp *) pmp);
  840. }
  841. /*
  842. * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
  843. * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
  844. * We support 5 counters which only count the mandatory quantities.
  845. */
  846. #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
  847. #define COUNTER_MASK0_9 cpu_to_be32(COUNTER_MASK(1, 0) | \
  848. COUNTER_MASK(1, 1) | \
  849. COUNTER_MASK(1, 2) | \
  850. COUNTER_MASK(1, 3) | \
  851. COUNTER_MASK(1, 4))
  852. static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
  853. struct ib_device *ibdev, u8 port)
  854. {
  855. struct ib_pma_portsamplescontrol *p =
  856. (struct ib_pma_portsamplescontrol *)pmp->data;
  857. struct ipath_ibdev *dev = to_idev(ibdev);
  858. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  859. unsigned long flags;
  860. u8 port_select = p->port_select;
  861. memset(pmp->data, 0, sizeof(pmp->data));
  862. p->port_select = port_select;
  863. if (pmp->attr_mod != 0 ||
  864. (port_select != port && port_select != 0xFF))
  865. pmp->status |= IB_SMP_INVALID_FIELD;
  866. /*
  867. * Ticks are 10x the link transfer period which for 2.5Gbs is 4
  868. * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
  869. * intervals are counted in ticks. Since we use Linux timers, that
  870. * count in jiffies, we can't sample for less than 1000 ticks if HZ
  871. * == 1000 (4000 ticks if HZ is 250). link_speed_active returns 2 for
  872. * DDR, 1 for SDR, set the tick to 1 for DDR, 0 for SDR on chips that
  873. * have hardware support for delaying packets.
  874. */
  875. if (crp->cr_psstat)
  876. p->tick = dev->dd->ipath_link_speed_active - 1;
  877. else
  878. p->tick = 250; /* 1 usec. */
  879. p->counter_width = 4; /* 32 bit counters */
  880. p->counter_mask0_9 = COUNTER_MASK0_9;
  881. spin_lock_irqsave(&dev->pending_lock, flags);
  882. if (crp->cr_psstat)
  883. p->sample_status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  884. else
  885. p->sample_status = dev->pma_sample_status;
  886. p->sample_start = cpu_to_be32(dev->pma_sample_start);
  887. p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
  888. p->tag = cpu_to_be16(dev->pma_tag);
  889. p->counter_select[0] = dev->pma_counter_select[0];
  890. p->counter_select[1] = dev->pma_counter_select[1];
  891. p->counter_select[2] = dev->pma_counter_select[2];
  892. p->counter_select[3] = dev->pma_counter_select[3];
  893. p->counter_select[4] = dev->pma_counter_select[4];
  894. spin_unlock_irqrestore(&dev->pending_lock, flags);
  895. return reply((struct ib_smp *) pmp);
  896. }
  897. static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
  898. struct ib_device *ibdev, u8 port)
  899. {
  900. struct ib_pma_portsamplescontrol *p =
  901. (struct ib_pma_portsamplescontrol *)pmp->data;
  902. struct ipath_ibdev *dev = to_idev(ibdev);
  903. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  904. unsigned long flags;
  905. u8 status;
  906. int ret;
  907. if (pmp->attr_mod != 0 ||
  908. (p->port_select != port && p->port_select != 0xFF)) {
  909. pmp->status |= IB_SMP_INVALID_FIELD;
  910. ret = reply((struct ib_smp *) pmp);
  911. goto bail;
  912. }
  913. spin_lock_irqsave(&dev->pending_lock, flags);
  914. if (crp->cr_psstat)
  915. status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  916. else
  917. status = dev->pma_sample_status;
  918. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  919. dev->pma_sample_start = be32_to_cpu(p->sample_start);
  920. dev->pma_sample_interval = be32_to_cpu(p->sample_interval);
  921. dev->pma_tag = be16_to_cpu(p->tag);
  922. dev->pma_counter_select[0] = p->counter_select[0];
  923. dev->pma_counter_select[1] = p->counter_select[1];
  924. dev->pma_counter_select[2] = p->counter_select[2];
  925. dev->pma_counter_select[3] = p->counter_select[3];
  926. dev->pma_counter_select[4] = p->counter_select[4];
  927. if (crp->cr_psstat) {
  928. ipath_write_creg(dev->dd, crp->cr_psinterval,
  929. dev->pma_sample_interval);
  930. ipath_write_creg(dev->dd, crp->cr_psstart,
  931. dev->pma_sample_start);
  932. } else
  933. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
  934. }
  935. spin_unlock_irqrestore(&dev->pending_lock, flags);
  936. ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
  937. bail:
  938. return ret;
  939. }
  940. static u64 get_counter(struct ipath_ibdev *dev,
  941. struct ipath_cregs const *crp,
  942. __be16 sel)
  943. {
  944. u64 ret;
  945. switch (sel) {
  946. case IB_PMA_PORT_XMIT_DATA:
  947. ret = (crp->cr_psxmitdatacount) ?
  948. ipath_read_creg32(dev->dd, crp->cr_psxmitdatacount) :
  949. dev->ipath_sword;
  950. break;
  951. case IB_PMA_PORT_RCV_DATA:
  952. ret = (crp->cr_psrcvdatacount) ?
  953. ipath_read_creg32(dev->dd, crp->cr_psrcvdatacount) :
  954. dev->ipath_rword;
  955. break;
  956. case IB_PMA_PORT_XMIT_PKTS:
  957. ret = (crp->cr_psxmitpktscount) ?
  958. ipath_read_creg32(dev->dd, crp->cr_psxmitpktscount) :
  959. dev->ipath_spkts;
  960. break;
  961. case IB_PMA_PORT_RCV_PKTS:
  962. ret = (crp->cr_psrcvpktscount) ?
  963. ipath_read_creg32(dev->dd, crp->cr_psrcvpktscount) :
  964. dev->ipath_rpkts;
  965. break;
  966. case IB_PMA_PORT_XMIT_WAIT:
  967. ret = (crp->cr_psxmitwaitcount) ?
  968. ipath_read_creg32(dev->dd, crp->cr_psxmitwaitcount) :
  969. dev->ipath_xmit_wait;
  970. break;
  971. default:
  972. ret = 0;
  973. }
  974. return ret;
  975. }
  976. static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
  977. struct ib_device *ibdev)
  978. {
  979. struct ib_pma_portsamplesresult *p =
  980. (struct ib_pma_portsamplesresult *)pmp->data;
  981. struct ipath_ibdev *dev = to_idev(ibdev);
  982. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  983. u8 status;
  984. int i;
  985. memset(pmp->data, 0, sizeof(pmp->data));
  986. p->tag = cpu_to_be16(dev->pma_tag);
  987. if (crp->cr_psstat)
  988. status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  989. else
  990. status = dev->pma_sample_status;
  991. p->sample_status = cpu_to_be16(status);
  992. for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
  993. p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
  994. cpu_to_be32(
  995. get_counter(dev, crp, dev->pma_counter_select[i]));
  996. return reply((struct ib_smp *) pmp);
  997. }
  998. static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
  999. struct ib_device *ibdev)
  1000. {
  1001. struct ib_pma_portsamplesresult_ext *p =
  1002. (struct ib_pma_portsamplesresult_ext *)pmp->data;
  1003. struct ipath_ibdev *dev = to_idev(ibdev);
  1004. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  1005. u8 status;
  1006. int i;
  1007. memset(pmp->data, 0, sizeof(pmp->data));
  1008. p->tag = cpu_to_be16(dev->pma_tag);
  1009. if (crp->cr_psstat)
  1010. status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  1011. else
  1012. status = dev->pma_sample_status;
  1013. p->sample_status = cpu_to_be16(status);
  1014. /* 64 bits */
  1015. p->extended_width = cpu_to_be32(0x80000000);
  1016. for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
  1017. p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
  1018. cpu_to_be64(
  1019. get_counter(dev, crp, dev->pma_counter_select[i]));
  1020. return reply((struct ib_smp *) pmp);
  1021. }
  1022. static int recv_pma_get_portcounters(struct ib_perf *pmp,
  1023. struct ib_device *ibdev, u8 port)
  1024. {
  1025. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1026. pmp->data;
  1027. struct ipath_ibdev *dev = to_idev(ibdev);
  1028. struct ipath_verbs_counters cntrs;
  1029. u8 port_select = p->port_select;
  1030. ipath_get_counters(dev->dd, &cntrs);
  1031. /* Adjust counters for any resets done. */
  1032. cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
  1033. cntrs.link_error_recovery_counter -=
  1034. dev->z_link_error_recovery_counter;
  1035. cntrs.link_downed_counter -= dev->z_link_downed_counter;
  1036. cntrs.port_rcv_errors += dev->rcv_errors;
  1037. cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
  1038. cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
  1039. cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
  1040. cntrs.port_xmit_data -= dev->z_port_xmit_data;
  1041. cntrs.port_rcv_data -= dev->z_port_rcv_data;
  1042. cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
  1043. cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
  1044. cntrs.local_link_integrity_errors -=
  1045. dev->z_local_link_integrity_errors;
  1046. cntrs.excessive_buffer_overrun_errors -=
  1047. dev->z_excessive_buffer_overrun_errors;
  1048. cntrs.vl15_dropped -= dev->z_vl15_dropped;
  1049. cntrs.vl15_dropped += dev->n_vl15_dropped;
  1050. memset(pmp->data, 0, sizeof(pmp->data));
  1051. p->port_select = port_select;
  1052. if (pmp->attr_mod != 0 ||
  1053. (port_select != port && port_select != 0xFF))
  1054. pmp->status |= IB_SMP_INVALID_FIELD;
  1055. if (cntrs.symbol_error_counter > 0xFFFFUL)
  1056. p->symbol_error_counter = cpu_to_be16(0xFFFF);
  1057. else
  1058. p->symbol_error_counter =
  1059. cpu_to_be16((u16)cntrs.symbol_error_counter);
  1060. if (cntrs.link_error_recovery_counter > 0xFFUL)
  1061. p->link_error_recovery_counter = 0xFF;
  1062. else
  1063. p->link_error_recovery_counter =
  1064. (u8)cntrs.link_error_recovery_counter;
  1065. if (cntrs.link_downed_counter > 0xFFUL)
  1066. p->link_downed_counter = 0xFF;
  1067. else
  1068. p->link_downed_counter = (u8)cntrs.link_downed_counter;
  1069. if (cntrs.port_rcv_errors > 0xFFFFUL)
  1070. p->port_rcv_errors = cpu_to_be16(0xFFFF);
  1071. else
  1072. p->port_rcv_errors =
  1073. cpu_to_be16((u16) cntrs.port_rcv_errors);
  1074. if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
  1075. p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
  1076. else
  1077. p->port_rcv_remphys_errors =
  1078. cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
  1079. if (cntrs.port_xmit_discards > 0xFFFFUL)
  1080. p->port_xmit_discards = cpu_to_be16(0xFFFF);
  1081. else
  1082. p->port_xmit_discards =
  1083. cpu_to_be16((u16)cntrs.port_xmit_discards);
  1084. if (cntrs.local_link_integrity_errors > 0xFUL)
  1085. cntrs.local_link_integrity_errors = 0xFUL;
  1086. if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
  1087. cntrs.excessive_buffer_overrun_errors = 0xFUL;
  1088. p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
  1089. cntrs.excessive_buffer_overrun_errors;
  1090. if (cntrs.vl15_dropped > 0xFFFFUL)
  1091. p->vl15_dropped = cpu_to_be16(0xFFFF);
  1092. else
  1093. p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
  1094. if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
  1095. p->port_xmit_data = cpu_to_be32(0xFFFFFFFF);
  1096. else
  1097. p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
  1098. if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
  1099. p->port_rcv_data = cpu_to_be32(0xFFFFFFFF);
  1100. else
  1101. p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
  1102. if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
  1103. p->port_xmit_packets = cpu_to_be32(0xFFFFFFFF);
  1104. else
  1105. p->port_xmit_packets =
  1106. cpu_to_be32((u32)cntrs.port_xmit_packets);
  1107. if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
  1108. p->port_rcv_packets = cpu_to_be32(0xFFFFFFFF);
  1109. else
  1110. p->port_rcv_packets =
  1111. cpu_to_be32((u32) cntrs.port_rcv_packets);
  1112. return reply((struct ib_smp *) pmp);
  1113. }
  1114. static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
  1115. struct ib_device *ibdev, u8 port)
  1116. {
  1117. struct ib_pma_portcounters_ext *p =
  1118. (struct ib_pma_portcounters_ext *)pmp->data;
  1119. struct ipath_ibdev *dev = to_idev(ibdev);
  1120. u64 swords, rwords, spkts, rpkts, xwait;
  1121. u8 port_select = p->port_select;
  1122. ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
  1123. &rpkts, &xwait);
  1124. /* Adjust counters for any resets done. */
  1125. swords -= dev->z_port_xmit_data;
  1126. rwords -= dev->z_port_rcv_data;
  1127. spkts -= dev->z_port_xmit_packets;
  1128. rpkts -= dev->z_port_rcv_packets;
  1129. memset(pmp->data, 0, sizeof(pmp->data));
  1130. p->port_select = port_select;
  1131. if (pmp->attr_mod != 0 ||
  1132. (port_select != port && port_select != 0xFF))
  1133. pmp->status |= IB_SMP_INVALID_FIELD;
  1134. p->port_xmit_data = cpu_to_be64(swords);
  1135. p->port_rcv_data = cpu_to_be64(rwords);
  1136. p->port_xmit_packets = cpu_to_be64(spkts);
  1137. p->port_rcv_packets = cpu_to_be64(rpkts);
  1138. p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
  1139. p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
  1140. p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
  1141. p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
  1142. return reply((struct ib_smp *) pmp);
  1143. }
  1144. static int recv_pma_set_portcounters(struct ib_perf *pmp,
  1145. struct ib_device *ibdev, u8 port)
  1146. {
  1147. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1148. pmp->data;
  1149. struct ipath_ibdev *dev = to_idev(ibdev);
  1150. struct ipath_verbs_counters cntrs;
  1151. /*
  1152. * Since the HW doesn't support clearing counters, we save the
  1153. * current count and subtract it from future responses.
  1154. */
  1155. ipath_get_counters(dev->dd, &cntrs);
  1156. if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
  1157. dev->z_symbol_error_counter = cntrs.symbol_error_counter;
  1158. if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
  1159. dev->z_link_error_recovery_counter =
  1160. cntrs.link_error_recovery_counter;
  1161. if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
  1162. dev->z_link_downed_counter = cntrs.link_downed_counter;
  1163. if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
  1164. dev->z_port_rcv_errors =
  1165. cntrs.port_rcv_errors + dev->rcv_errors;
  1166. if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
  1167. dev->z_port_rcv_remphys_errors =
  1168. cntrs.port_rcv_remphys_errors;
  1169. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
  1170. dev->z_port_xmit_discards = cntrs.port_xmit_discards;
  1171. if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
  1172. dev->z_local_link_integrity_errors =
  1173. cntrs.local_link_integrity_errors;
  1174. if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
  1175. dev->z_excessive_buffer_overrun_errors =
  1176. cntrs.excessive_buffer_overrun_errors;
  1177. if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
  1178. dev->n_vl15_dropped = 0;
  1179. dev->z_vl15_dropped = cntrs.vl15_dropped;
  1180. }
  1181. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
  1182. dev->z_port_xmit_data = cntrs.port_xmit_data;
  1183. if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
  1184. dev->z_port_rcv_data = cntrs.port_rcv_data;
  1185. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
  1186. dev->z_port_xmit_packets = cntrs.port_xmit_packets;
  1187. if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
  1188. dev->z_port_rcv_packets = cntrs.port_rcv_packets;
  1189. return recv_pma_get_portcounters(pmp, ibdev, port);
  1190. }
  1191. static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
  1192. struct ib_device *ibdev, u8 port)
  1193. {
  1194. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1195. pmp->data;
  1196. struct ipath_ibdev *dev = to_idev(ibdev);
  1197. u64 swords, rwords, spkts, rpkts, xwait;
  1198. ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
  1199. &rpkts, &xwait);
  1200. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
  1201. dev->z_port_xmit_data = swords;
  1202. if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
  1203. dev->z_port_rcv_data = rwords;
  1204. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
  1205. dev->z_port_xmit_packets = spkts;
  1206. if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
  1207. dev->z_port_rcv_packets = rpkts;
  1208. if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
  1209. dev->n_unicast_xmit = 0;
  1210. if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
  1211. dev->n_unicast_rcv = 0;
  1212. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
  1213. dev->n_multicast_xmit = 0;
  1214. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
  1215. dev->n_multicast_rcv = 0;
  1216. return recv_pma_get_portcounters_ext(pmp, ibdev, port);
  1217. }
  1218. static int process_subn(struct ib_device *ibdev, int mad_flags,
  1219. u8 port_num, struct ib_mad *in_mad,
  1220. struct ib_mad *out_mad)
  1221. {
  1222. struct ib_smp *smp = (struct ib_smp *)out_mad;
  1223. struct ipath_ibdev *dev = to_idev(ibdev);
  1224. int ret;
  1225. *out_mad = *in_mad;
  1226. if (smp->class_version != 1) {
  1227. smp->status |= IB_SMP_UNSUP_VERSION;
  1228. ret = reply(smp);
  1229. goto bail;
  1230. }
  1231. /* Is the mkey in the process of expiring? */
  1232. if (dev->mkey_lease_timeout &&
  1233. time_after_eq(jiffies, dev->mkey_lease_timeout)) {
  1234. /* Clear timeout and mkey protection field. */
  1235. dev->mkey_lease_timeout = 0;
  1236. dev->mkeyprot = 0;
  1237. }
  1238. /*
  1239. * M_Key checking depends on
  1240. * Portinfo:M_Key_protect_bits
  1241. */
  1242. if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
  1243. dev->mkey != smp->mkey &&
  1244. (smp->method == IB_MGMT_METHOD_SET ||
  1245. (smp->method == IB_MGMT_METHOD_GET &&
  1246. dev->mkeyprot >= 2))) {
  1247. if (dev->mkey_violations != 0xFFFF)
  1248. ++dev->mkey_violations;
  1249. if (dev->mkey_lease_timeout ||
  1250. dev->mkey_lease_period == 0) {
  1251. ret = IB_MAD_RESULT_SUCCESS |
  1252. IB_MAD_RESULT_CONSUMED;
  1253. goto bail;
  1254. }
  1255. dev->mkey_lease_timeout = jiffies +
  1256. dev->mkey_lease_period * HZ;
  1257. /* Future: Generate a trap notice. */
  1258. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  1259. goto bail;
  1260. } else if (dev->mkey_lease_timeout)
  1261. dev->mkey_lease_timeout = 0;
  1262. switch (smp->method) {
  1263. case IB_MGMT_METHOD_GET:
  1264. switch (smp->attr_id) {
  1265. case IB_SMP_ATTR_NODE_DESC:
  1266. ret = recv_subn_get_nodedescription(smp, ibdev);
  1267. goto bail;
  1268. case IB_SMP_ATTR_NODE_INFO:
  1269. ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
  1270. goto bail;
  1271. case IB_SMP_ATTR_GUID_INFO:
  1272. ret = recv_subn_get_guidinfo(smp, ibdev);
  1273. goto bail;
  1274. case IB_SMP_ATTR_PORT_INFO:
  1275. ret = recv_subn_get_portinfo(smp, ibdev, port_num);
  1276. goto bail;
  1277. case IB_SMP_ATTR_PKEY_TABLE:
  1278. ret = recv_subn_get_pkeytable(smp, ibdev);
  1279. goto bail;
  1280. case IB_SMP_ATTR_SM_INFO:
  1281. if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
  1282. ret = IB_MAD_RESULT_SUCCESS |
  1283. IB_MAD_RESULT_CONSUMED;
  1284. goto bail;
  1285. }
  1286. if (dev->port_cap_flags & IB_PORT_SM) {
  1287. ret = IB_MAD_RESULT_SUCCESS;
  1288. goto bail;
  1289. }
  1290. /* FALLTHROUGH */
  1291. default:
  1292. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1293. ret = reply(smp);
  1294. goto bail;
  1295. }
  1296. case IB_MGMT_METHOD_SET:
  1297. switch (smp->attr_id) {
  1298. case IB_SMP_ATTR_GUID_INFO:
  1299. ret = recv_subn_set_guidinfo(smp, ibdev);
  1300. goto bail;
  1301. case IB_SMP_ATTR_PORT_INFO:
  1302. ret = recv_subn_set_portinfo(smp, ibdev, port_num);
  1303. goto bail;
  1304. case IB_SMP_ATTR_PKEY_TABLE:
  1305. ret = recv_subn_set_pkeytable(smp, ibdev);
  1306. goto bail;
  1307. case IB_SMP_ATTR_SM_INFO:
  1308. if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
  1309. ret = IB_MAD_RESULT_SUCCESS |
  1310. IB_MAD_RESULT_CONSUMED;
  1311. goto bail;
  1312. }
  1313. if (dev->port_cap_flags & IB_PORT_SM) {
  1314. ret = IB_MAD_RESULT_SUCCESS;
  1315. goto bail;
  1316. }
  1317. /* FALLTHROUGH */
  1318. default:
  1319. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1320. ret = reply(smp);
  1321. goto bail;
  1322. }
  1323. case IB_MGMT_METHOD_TRAP:
  1324. case IB_MGMT_METHOD_REPORT:
  1325. case IB_MGMT_METHOD_REPORT_RESP:
  1326. case IB_MGMT_METHOD_TRAP_REPRESS:
  1327. case IB_MGMT_METHOD_GET_RESP:
  1328. /*
  1329. * The ib_mad module will call us to process responses
  1330. * before checking for other consumers.
  1331. * Just tell the caller to process it normally.
  1332. */
  1333. ret = IB_MAD_RESULT_SUCCESS;
  1334. goto bail;
  1335. default:
  1336. smp->status |= IB_SMP_UNSUP_METHOD;
  1337. ret = reply(smp);
  1338. }
  1339. bail:
  1340. return ret;
  1341. }
  1342. static int process_perf(struct ib_device *ibdev, u8 port_num,
  1343. struct ib_mad *in_mad,
  1344. struct ib_mad *out_mad)
  1345. {
  1346. struct ib_perf *pmp = (struct ib_perf *)out_mad;
  1347. int ret;
  1348. *out_mad = *in_mad;
  1349. if (pmp->class_version != 1) {
  1350. pmp->status |= IB_SMP_UNSUP_VERSION;
  1351. ret = reply((struct ib_smp *) pmp);
  1352. goto bail;
  1353. }
  1354. switch (pmp->method) {
  1355. case IB_MGMT_METHOD_GET:
  1356. switch (pmp->attr_id) {
  1357. case IB_PMA_CLASS_PORT_INFO:
  1358. ret = recv_pma_get_classportinfo(pmp);
  1359. goto bail;
  1360. case IB_PMA_PORT_SAMPLES_CONTROL:
  1361. ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
  1362. port_num);
  1363. goto bail;
  1364. case IB_PMA_PORT_SAMPLES_RESULT:
  1365. ret = recv_pma_get_portsamplesresult(pmp, ibdev);
  1366. goto bail;
  1367. case IB_PMA_PORT_SAMPLES_RESULT_EXT:
  1368. ret = recv_pma_get_portsamplesresult_ext(pmp,
  1369. ibdev);
  1370. goto bail;
  1371. case IB_PMA_PORT_COUNTERS:
  1372. ret = recv_pma_get_portcounters(pmp, ibdev,
  1373. port_num);
  1374. goto bail;
  1375. case IB_PMA_PORT_COUNTERS_EXT:
  1376. ret = recv_pma_get_portcounters_ext(pmp, ibdev,
  1377. port_num);
  1378. goto bail;
  1379. default:
  1380. pmp->status |= IB_SMP_UNSUP_METH_ATTR;
  1381. ret = reply((struct ib_smp *) pmp);
  1382. goto bail;
  1383. }
  1384. case IB_MGMT_METHOD_SET:
  1385. switch (pmp->attr_id) {
  1386. case IB_PMA_PORT_SAMPLES_CONTROL:
  1387. ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
  1388. port_num);
  1389. goto bail;
  1390. case IB_PMA_PORT_COUNTERS:
  1391. ret = recv_pma_set_portcounters(pmp, ibdev,
  1392. port_num);
  1393. goto bail;
  1394. case IB_PMA_PORT_COUNTERS_EXT:
  1395. ret = recv_pma_set_portcounters_ext(pmp, ibdev,
  1396. port_num);
  1397. goto bail;
  1398. default:
  1399. pmp->status |= IB_SMP_UNSUP_METH_ATTR;
  1400. ret = reply((struct ib_smp *) pmp);
  1401. goto bail;
  1402. }
  1403. case IB_MGMT_METHOD_GET_RESP:
  1404. /*
  1405. * The ib_mad module will call us to process responses
  1406. * before checking for other consumers.
  1407. * Just tell the caller to process it normally.
  1408. */
  1409. ret = IB_MAD_RESULT_SUCCESS;
  1410. goto bail;
  1411. default:
  1412. pmp->status |= IB_SMP_UNSUP_METHOD;
  1413. ret = reply((struct ib_smp *) pmp);
  1414. }
  1415. bail:
  1416. return ret;
  1417. }
  1418. /**
  1419. * ipath_process_mad - process an incoming MAD packet
  1420. * @ibdev: the infiniband device this packet came in on
  1421. * @mad_flags: MAD flags
  1422. * @port_num: the port number this packet came in on
  1423. * @in_wc: the work completion entry for this packet
  1424. * @in_grh: the global route header for this packet
  1425. * @in_mad: the incoming MAD
  1426. * @out_mad: any outgoing MAD reply
  1427. *
  1428. * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
  1429. * interested in processing.
  1430. *
  1431. * Note that the verbs framework has already done the MAD sanity checks,
  1432. * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  1433. * MADs.
  1434. *
  1435. * This is called by the ib_mad module.
  1436. */
  1437. int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  1438. struct ib_wc *in_wc, struct ib_grh *in_grh,
  1439. struct ib_mad *in_mad, struct ib_mad *out_mad)
  1440. {
  1441. int ret;
  1442. switch (in_mad->mad_hdr.mgmt_class) {
  1443. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  1444. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  1445. ret = process_subn(ibdev, mad_flags, port_num,
  1446. in_mad, out_mad);
  1447. goto bail;
  1448. case IB_MGMT_CLASS_PERF_MGMT:
  1449. ret = process_perf(ibdev, port_num, in_mad, out_mad);
  1450. goto bail;
  1451. default:
  1452. ret = IB_MAD_RESULT_SUCCESS;
  1453. }
  1454. bail:
  1455. return ret;
  1456. }