ipath_mad.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  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 __constant_htons(0x0004)
  38. #define IB_SMP_UNSUP_METHOD __constant_htons(0x0008)
  39. #define IB_SMP_UNSUP_METH_ATTR __constant_htons(0x000C)
  40. #define IB_SMP_INVALID_FIELD __constant_htons(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. struct ipath_portdata *pd = dd->ipath_pd[0];
  316. memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
  317. return 0;
  318. }
  319. static int recv_subn_get_pkeytable(struct ib_smp *smp,
  320. struct ib_device *ibdev)
  321. {
  322. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  323. u16 *p = (u16 *) smp->data;
  324. __be16 *q = (__be16 *) smp->data;
  325. /* 64 blocks of 32 16-bit P_Key entries */
  326. memset(smp->data, 0, sizeof(smp->data));
  327. if (startpx == 0) {
  328. struct ipath_ibdev *dev = to_idev(ibdev);
  329. unsigned i, n = ipath_get_npkeys(dev->dd);
  330. get_pkeys(dev->dd, p);
  331. for (i = 0; i < n; i++)
  332. q[i] = cpu_to_be16(p[i]);
  333. } else
  334. smp->status |= IB_SMP_INVALID_FIELD;
  335. return reply(smp);
  336. }
  337. static int recv_subn_set_guidinfo(struct ib_smp *smp,
  338. struct ib_device *ibdev)
  339. {
  340. /* The only GUID we support is the first read-only entry. */
  341. return recv_subn_get_guidinfo(smp, ibdev);
  342. }
  343. /**
  344. * set_linkdowndefaultstate - set the default linkdown state
  345. * @dd: the infinipath device
  346. * @sleep: the new state
  347. *
  348. * Note that this will only take effect when the link state changes.
  349. */
  350. static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
  351. {
  352. if (sleep)
  353. dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
  354. else
  355. dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
  356. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  357. dd->ipath_ibcctrl);
  358. return 0;
  359. }
  360. /**
  361. * recv_subn_set_portinfo - set port information
  362. * @smp: the incoming SM packet
  363. * @ibdev: the infiniband device
  364. * @port: the port on the device
  365. *
  366. * Set Portinfo (see ch. 14.2.5.6).
  367. */
  368. static int recv_subn_set_portinfo(struct ib_smp *smp,
  369. struct ib_device *ibdev, u8 port)
  370. {
  371. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  372. struct ib_event event;
  373. struct ipath_ibdev *dev;
  374. struct ipath_devdata *dd;
  375. char clientrereg = 0;
  376. u16 lid, smlid;
  377. u8 lwe;
  378. u8 lse;
  379. u8 state;
  380. u16 lstate;
  381. u32 mtu;
  382. int ret, ore;
  383. if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
  384. goto err;
  385. dev = to_idev(ibdev);
  386. dd = dev->dd;
  387. event.device = ibdev;
  388. event.element.port_num = port;
  389. dev->mkey = pip->mkey;
  390. dev->gid_prefix = pip->gid_prefix;
  391. dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
  392. lid = be16_to_cpu(pip->lid);
  393. if (dd->ipath_lid != lid ||
  394. dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
  395. /* Must be a valid unicast LID address. */
  396. if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
  397. goto err;
  398. ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
  399. event.event = IB_EVENT_LID_CHANGE;
  400. ib_dispatch_event(&event);
  401. }
  402. smlid = be16_to_cpu(pip->sm_lid);
  403. if (smlid != dev->sm_lid) {
  404. /* Must be a valid unicast LID address. */
  405. if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
  406. goto err;
  407. dev->sm_lid = smlid;
  408. event.event = IB_EVENT_SM_CHANGE;
  409. ib_dispatch_event(&event);
  410. }
  411. /* Allow 1x or 4x to be set (see 14.2.6.6). */
  412. lwe = pip->link_width_enabled;
  413. if (lwe) {
  414. if (lwe == 0xFF)
  415. lwe = dd->ipath_link_width_supported;
  416. else if (lwe >= 16 || (lwe & ~dd->ipath_link_width_supported))
  417. goto err;
  418. set_link_width_enabled(dd, lwe);
  419. }
  420. /* Allow 2.5 or 5.0 Gbs. */
  421. lse = pip->linkspeedactive_enabled & 0xF;
  422. if (lse) {
  423. if (lse == 15)
  424. lse = dd->ipath_link_speed_supported;
  425. else if (lse >= 8 || (lse & ~dd->ipath_link_speed_supported))
  426. goto err;
  427. set_link_speed_enabled(dd, lse);
  428. }
  429. /* Set link down default state. */
  430. switch (pip->portphysstate_linkdown & 0xF) {
  431. case 0: /* NOP */
  432. break;
  433. case 1: /* SLEEP */
  434. if (set_linkdowndefaultstate(dd, 1))
  435. goto err;
  436. break;
  437. case 2: /* POLL */
  438. if (set_linkdowndefaultstate(dd, 0))
  439. goto err;
  440. break;
  441. default:
  442. goto err;
  443. }
  444. dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
  445. dev->vl_high_limit = pip->vl_high_limit;
  446. switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
  447. case IB_MTU_256:
  448. mtu = 256;
  449. break;
  450. case IB_MTU_512:
  451. mtu = 512;
  452. break;
  453. case IB_MTU_1024:
  454. mtu = 1024;
  455. break;
  456. case IB_MTU_2048:
  457. mtu = 2048;
  458. break;
  459. case IB_MTU_4096:
  460. if (!ipath_mtu4096)
  461. goto err;
  462. mtu = 4096;
  463. break;
  464. default:
  465. /* XXX We have already partially updated our state! */
  466. goto err;
  467. }
  468. ipath_set_mtu(dd, mtu);
  469. dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
  470. /* We only support VL0 */
  471. if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
  472. goto err;
  473. if (pip->mkey_violations == 0)
  474. dev->mkey_violations = 0;
  475. /*
  476. * Hardware counter can't be reset so snapshot and subtract
  477. * later.
  478. */
  479. if (pip->pkey_violations == 0)
  480. dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
  481. if (pip->qkey_violations == 0)
  482. dev->qkey_violations = 0;
  483. ore = pip->localphyerrors_overrunerrors;
  484. if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
  485. goto err;
  486. if (set_overrunthreshold(dd, (ore & 0xF)))
  487. goto err;
  488. dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
  489. if (pip->clientrereg_resv_subnetto & 0x80) {
  490. clientrereg = 1;
  491. event.event = IB_EVENT_CLIENT_REREGISTER;
  492. ib_dispatch_event(&event);
  493. }
  494. /*
  495. * Do the port state change now that the other link parameters
  496. * have been set.
  497. * Changing the port physical state only makes sense if the link
  498. * is down or is being set to down.
  499. */
  500. state = pip->linkspeed_portstate & 0xF;
  501. lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
  502. if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
  503. goto err;
  504. /*
  505. * Only state changes of DOWN, ARM, and ACTIVE are valid
  506. * and must be in the correct state to take effect (see 7.2.6).
  507. */
  508. switch (state) {
  509. case IB_PORT_NOP:
  510. if (lstate == 0)
  511. break;
  512. /* FALLTHROUGH */
  513. case IB_PORT_DOWN:
  514. if (lstate == 0)
  515. lstate = IPATH_IB_LINKDOWN_ONLY;
  516. else if (lstate == 1)
  517. lstate = IPATH_IB_LINKDOWN_SLEEP;
  518. else if (lstate == 2)
  519. lstate = IPATH_IB_LINKDOWN;
  520. else if (lstate == 3)
  521. lstate = IPATH_IB_LINKDOWN_DISABLE;
  522. else
  523. goto err;
  524. ipath_set_linkstate(dd, lstate);
  525. if (lstate == IPATH_IB_LINKDOWN_DISABLE) {
  526. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  527. goto done;
  528. }
  529. ipath_wait_linkstate(dd, IPATH_LINKINIT | IPATH_LINKARMED |
  530. IPATH_LINKACTIVE, 1000);
  531. break;
  532. case IB_PORT_ARMED:
  533. ipath_set_linkstate(dd, IPATH_IB_LINKARM);
  534. break;
  535. case IB_PORT_ACTIVE:
  536. ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
  537. break;
  538. default:
  539. /* XXX We have already partially updated our state! */
  540. goto err;
  541. }
  542. ret = recv_subn_get_portinfo(smp, ibdev, port);
  543. if (clientrereg)
  544. pip->clientrereg_resv_subnetto |= 0x80;
  545. goto done;
  546. err:
  547. smp->status |= IB_SMP_INVALID_FIELD;
  548. ret = recv_subn_get_portinfo(smp, ibdev, port);
  549. done:
  550. return ret;
  551. }
  552. /**
  553. * rm_pkey - decrecment the reference count for the given PKEY
  554. * @dd: the infinipath device
  555. * @key: the PKEY index
  556. *
  557. * Return true if this was the last reference and the hardware table entry
  558. * needs to be changed.
  559. */
  560. static int rm_pkey(struct ipath_devdata *dd, u16 key)
  561. {
  562. int i;
  563. int ret;
  564. for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
  565. if (dd->ipath_pkeys[i] != key)
  566. continue;
  567. if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
  568. dd->ipath_pkeys[i] = 0;
  569. ret = 1;
  570. goto bail;
  571. }
  572. break;
  573. }
  574. ret = 0;
  575. bail:
  576. return ret;
  577. }
  578. /**
  579. * add_pkey - add the given PKEY to the hardware table
  580. * @dd: the infinipath device
  581. * @key: the PKEY
  582. *
  583. * Return an error code if unable to add the entry, zero if no change,
  584. * or 1 if the hardware PKEY register needs to be updated.
  585. */
  586. static int add_pkey(struct ipath_devdata *dd, u16 key)
  587. {
  588. int i;
  589. u16 lkey = key & 0x7FFF;
  590. int any = 0;
  591. int ret;
  592. if (lkey == 0x7FFF) {
  593. ret = 0;
  594. goto bail;
  595. }
  596. /* Look for an empty slot or a matching PKEY. */
  597. for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
  598. if (!dd->ipath_pkeys[i]) {
  599. any++;
  600. continue;
  601. }
  602. /* If it matches exactly, try to increment the ref count */
  603. if (dd->ipath_pkeys[i] == key) {
  604. if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
  605. ret = 0;
  606. goto bail;
  607. }
  608. /* Lost the race. Look for an empty slot below. */
  609. atomic_dec(&dd->ipath_pkeyrefs[i]);
  610. any++;
  611. }
  612. /*
  613. * It makes no sense to have both the limited and unlimited
  614. * PKEY set at the same time since the unlimited one will
  615. * disable the limited one.
  616. */
  617. if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
  618. ret = -EEXIST;
  619. goto bail;
  620. }
  621. }
  622. if (!any) {
  623. ret = -EBUSY;
  624. goto bail;
  625. }
  626. for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
  627. if (!dd->ipath_pkeys[i] &&
  628. atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
  629. /* for ipathstats, etc. */
  630. ipath_stats.sps_pkeys[i] = lkey;
  631. dd->ipath_pkeys[i] = key;
  632. ret = 1;
  633. goto bail;
  634. }
  635. }
  636. ret = -EBUSY;
  637. bail:
  638. return ret;
  639. }
  640. /**
  641. * set_pkeys - set the PKEY table for port 0
  642. * @dd: the infinipath device
  643. * @pkeys: the PKEY table
  644. */
  645. static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
  646. {
  647. struct ipath_portdata *pd;
  648. int i;
  649. int changed = 0;
  650. pd = dd->ipath_pd[0];
  651. for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
  652. u16 key = pkeys[i];
  653. u16 okey = pd->port_pkeys[i];
  654. if (key == okey)
  655. continue;
  656. /*
  657. * The value of this PKEY table entry is changing.
  658. * Remove the old entry in the hardware's array of PKEYs.
  659. */
  660. if (okey & 0x7FFF)
  661. changed |= rm_pkey(dd, okey);
  662. if (key & 0x7FFF) {
  663. int ret = add_pkey(dd, key);
  664. if (ret < 0)
  665. key = 0;
  666. else
  667. changed |= ret;
  668. }
  669. pd->port_pkeys[i] = key;
  670. }
  671. if (changed) {
  672. u64 pkey;
  673. pkey = (u64) dd->ipath_pkeys[0] |
  674. ((u64) dd->ipath_pkeys[1] << 16) |
  675. ((u64) dd->ipath_pkeys[2] << 32) |
  676. ((u64) dd->ipath_pkeys[3] << 48);
  677. ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
  678. (unsigned long long) pkey);
  679. ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
  680. pkey);
  681. }
  682. return 0;
  683. }
  684. static int recv_subn_set_pkeytable(struct ib_smp *smp,
  685. struct ib_device *ibdev)
  686. {
  687. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  688. __be16 *p = (__be16 *) smp->data;
  689. u16 *q = (u16 *) smp->data;
  690. struct ipath_ibdev *dev = to_idev(ibdev);
  691. unsigned i, n = ipath_get_npkeys(dev->dd);
  692. for (i = 0; i < n; i++)
  693. q[i] = be16_to_cpu(p[i]);
  694. if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
  695. smp->status |= IB_SMP_INVALID_FIELD;
  696. return recv_subn_get_pkeytable(smp, ibdev);
  697. }
  698. #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
  699. #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
  700. #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
  701. #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
  702. #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
  703. #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
  704. struct ib_perf {
  705. u8 base_version;
  706. u8 mgmt_class;
  707. u8 class_version;
  708. u8 method;
  709. __be16 status;
  710. __be16 unused;
  711. __be64 tid;
  712. __be16 attr_id;
  713. __be16 resv;
  714. __be32 attr_mod;
  715. u8 reserved[40];
  716. u8 data[192];
  717. } __attribute__ ((packed));
  718. struct ib_pma_classportinfo {
  719. u8 base_version;
  720. u8 class_version;
  721. __be16 cap_mask;
  722. u8 reserved[3];
  723. u8 resp_time_value; /* only lower 5 bits */
  724. union ib_gid redirect_gid;
  725. __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
  726. __be16 redirect_lid;
  727. __be16 redirect_pkey;
  728. __be32 redirect_qp; /* only lower 24 bits */
  729. __be32 redirect_qkey;
  730. union ib_gid trap_gid;
  731. __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
  732. __be16 trap_lid;
  733. __be16 trap_pkey;
  734. __be32 trap_hl_qp; /* 8, 24 bits respectively */
  735. __be32 trap_qkey;
  736. } __attribute__ ((packed));
  737. struct ib_pma_portsamplescontrol {
  738. u8 opcode;
  739. u8 port_select;
  740. u8 tick;
  741. u8 counter_width; /* only lower 3 bits */
  742. __be32 counter_mask0_9; /* 2, 10 * 3, bits */
  743. __be16 counter_mask10_14; /* 1, 5 * 3, bits */
  744. u8 sample_mechanisms;
  745. u8 sample_status; /* only lower 2 bits */
  746. __be64 option_mask;
  747. __be64 vendor_mask;
  748. __be32 sample_start;
  749. __be32 sample_interval;
  750. __be16 tag;
  751. __be16 counter_select[15];
  752. } __attribute__ ((packed));
  753. struct ib_pma_portsamplesresult {
  754. __be16 tag;
  755. __be16 sample_status; /* only lower 2 bits */
  756. __be32 counter[15];
  757. } __attribute__ ((packed));
  758. struct ib_pma_portsamplesresult_ext {
  759. __be16 tag;
  760. __be16 sample_status; /* only lower 2 bits */
  761. __be32 extended_width; /* only upper 2 bits */
  762. __be64 counter[15];
  763. } __attribute__ ((packed));
  764. struct ib_pma_portcounters {
  765. u8 reserved;
  766. u8 port_select;
  767. __be16 counter_select;
  768. __be16 symbol_error_counter;
  769. u8 link_error_recovery_counter;
  770. u8 link_downed_counter;
  771. __be16 port_rcv_errors;
  772. __be16 port_rcv_remphys_errors;
  773. __be16 port_rcv_switch_relay_errors;
  774. __be16 port_xmit_discards;
  775. u8 port_xmit_constraint_errors;
  776. u8 port_rcv_constraint_errors;
  777. u8 reserved1;
  778. u8 lli_ebor_errors; /* 4, 4, bits */
  779. __be16 reserved2;
  780. __be16 vl15_dropped;
  781. __be32 port_xmit_data;
  782. __be32 port_rcv_data;
  783. __be32 port_xmit_packets;
  784. __be32 port_rcv_packets;
  785. } __attribute__ ((packed));
  786. #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
  787. #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
  788. #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
  789. #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
  790. #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
  791. #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
  792. #define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
  793. #define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
  794. #define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
  795. #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
  796. #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
  797. #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
  798. #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
  799. struct ib_pma_portcounters_ext {
  800. u8 reserved;
  801. u8 port_select;
  802. __be16 counter_select;
  803. __be32 reserved1;
  804. __be64 port_xmit_data;
  805. __be64 port_rcv_data;
  806. __be64 port_xmit_packets;
  807. __be64 port_rcv_packets;
  808. __be64 port_unicast_xmit_packets;
  809. __be64 port_unicast_rcv_packets;
  810. __be64 port_multicast_xmit_packets;
  811. __be64 port_multicast_rcv_packets;
  812. } __attribute__ ((packed));
  813. #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
  814. #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
  815. #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
  816. #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
  817. #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
  818. #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
  819. #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
  820. #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
  821. static int recv_pma_get_classportinfo(struct ib_perf *pmp)
  822. {
  823. struct ib_pma_classportinfo *p =
  824. (struct ib_pma_classportinfo *)pmp->data;
  825. memset(pmp->data, 0, sizeof(pmp->data));
  826. if (pmp->attr_mod != 0)
  827. pmp->status |= IB_SMP_INVALID_FIELD;
  828. /* Indicate AllPortSelect is valid (only one port anyway) */
  829. p->cap_mask = __constant_cpu_to_be16(1 << 8);
  830. p->base_version = 1;
  831. p->class_version = 1;
  832. /*
  833. * Expected response time is 4.096 usec. * 2^18 == 1.073741824
  834. * sec.
  835. */
  836. p->resp_time_value = 18;
  837. return reply((struct ib_smp *) pmp);
  838. }
  839. /*
  840. * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
  841. * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
  842. * We support 5 counters which only count the mandatory quantities.
  843. */
  844. #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
  845. #define COUNTER_MASK0_9 \
  846. __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
  847. COUNTER_MASK(1, 1) | \
  848. COUNTER_MASK(1, 2) | \
  849. COUNTER_MASK(1, 3) | \
  850. COUNTER_MASK(1, 4))
  851. static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
  852. struct ib_device *ibdev, u8 port)
  853. {
  854. struct ib_pma_portsamplescontrol *p =
  855. (struct ib_pma_portsamplescontrol *)pmp->data;
  856. struct ipath_ibdev *dev = to_idev(ibdev);
  857. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  858. unsigned long flags;
  859. u8 port_select = p->port_select;
  860. memset(pmp->data, 0, sizeof(pmp->data));
  861. p->port_select = port_select;
  862. if (pmp->attr_mod != 0 ||
  863. (port_select != port && port_select != 0xFF))
  864. pmp->status |= IB_SMP_INVALID_FIELD;
  865. /*
  866. * Ticks are 10x the link transfer period which for 2.5Gbs is 4
  867. * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
  868. * intervals are counted in ticks. Since we use Linux timers, that
  869. * count in jiffies, we can't sample for less than 1000 ticks if HZ
  870. * == 1000 (4000 ticks if HZ is 250). link_speed_active returns 2 for
  871. * DDR, 1 for SDR, set the tick to 1 for DDR, 0 for SDR on chips that
  872. * have hardware support for delaying packets.
  873. */
  874. if (crp->cr_psstat)
  875. p->tick = dev->dd->ipath_link_speed_active - 1;
  876. else
  877. p->tick = 250; /* 1 usec. */
  878. p->counter_width = 4; /* 32 bit counters */
  879. p->counter_mask0_9 = COUNTER_MASK0_9;
  880. spin_lock_irqsave(&dev->pending_lock, flags);
  881. if (crp->cr_psstat)
  882. p->sample_status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  883. else
  884. p->sample_status = dev->pma_sample_status;
  885. p->sample_start = cpu_to_be32(dev->pma_sample_start);
  886. p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
  887. p->tag = cpu_to_be16(dev->pma_tag);
  888. p->counter_select[0] = dev->pma_counter_select[0];
  889. p->counter_select[1] = dev->pma_counter_select[1];
  890. p->counter_select[2] = dev->pma_counter_select[2];
  891. p->counter_select[3] = dev->pma_counter_select[3];
  892. p->counter_select[4] = dev->pma_counter_select[4];
  893. spin_unlock_irqrestore(&dev->pending_lock, flags);
  894. return reply((struct ib_smp *) pmp);
  895. }
  896. static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
  897. struct ib_device *ibdev, u8 port)
  898. {
  899. struct ib_pma_portsamplescontrol *p =
  900. (struct ib_pma_portsamplescontrol *)pmp->data;
  901. struct ipath_ibdev *dev = to_idev(ibdev);
  902. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  903. unsigned long flags;
  904. u8 status;
  905. int ret;
  906. if (pmp->attr_mod != 0 ||
  907. (p->port_select != port && p->port_select != 0xFF)) {
  908. pmp->status |= IB_SMP_INVALID_FIELD;
  909. ret = reply((struct ib_smp *) pmp);
  910. goto bail;
  911. }
  912. spin_lock_irqsave(&dev->pending_lock, flags);
  913. if (crp->cr_psstat)
  914. status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  915. else
  916. status = dev->pma_sample_status;
  917. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  918. dev->pma_sample_start = be32_to_cpu(p->sample_start);
  919. dev->pma_sample_interval = be32_to_cpu(p->sample_interval);
  920. dev->pma_tag = be16_to_cpu(p->tag);
  921. dev->pma_counter_select[0] = p->counter_select[0];
  922. dev->pma_counter_select[1] = p->counter_select[1];
  923. dev->pma_counter_select[2] = p->counter_select[2];
  924. dev->pma_counter_select[3] = p->counter_select[3];
  925. dev->pma_counter_select[4] = p->counter_select[4];
  926. if (crp->cr_psstat) {
  927. ipath_write_creg(dev->dd, crp->cr_psinterval,
  928. dev->pma_sample_interval);
  929. ipath_write_creg(dev->dd, crp->cr_psstart,
  930. dev->pma_sample_start);
  931. } else
  932. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
  933. }
  934. spin_unlock_irqrestore(&dev->pending_lock, flags);
  935. ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
  936. bail:
  937. return ret;
  938. }
  939. static u64 get_counter(struct ipath_ibdev *dev,
  940. struct ipath_cregs const *crp,
  941. __be16 sel)
  942. {
  943. u64 ret;
  944. switch (sel) {
  945. case IB_PMA_PORT_XMIT_DATA:
  946. ret = (crp->cr_psxmitdatacount) ?
  947. ipath_read_creg32(dev->dd, crp->cr_psxmitdatacount) :
  948. dev->ipath_sword;
  949. break;
  950. case IB_PMA_PORT_RCV_DATA:
  951. ret = (crp->cr_psrcvdatacount) ?
  952. ipath_read_creg32(dev->dd, crp->cr_psrcvdatacount) :
  953. dev->ipath_rword;
  954. break;
  955. case IB_PMA_PORT_XMIT_PKTS:
  956. ret = (crp->cr_psxmitpktscount) ?
  957. ipath_read_creg32(dev->dd, crp->cr_psxmitpktscount) :
  958. dev->ipath_spkts;
  959. break;
  960. case IB_PMA_PORT_RCV_PKTS:
  961. ret = (crp->cr_psrcvpktscount) ?
  962. ipath_read_creg32(dev->dd, crp->cr_psrcvpktscount) :
  963. dev->ipath_rpkts;
  964. break;
  965. case IB_PMA_PORT_XMIT_WAIT:
  966. ret = (crp->cr_psxmitwaitcount) ?
  967. ipath_read_creg32(dev->dd, crp->cr_psxmitwaitcount) :
  968. dev->ipath_xmit_wait;
  969. break;
  970. default:
  971. ret = 0;
  972. }
  973. return ret;
  974. }
  975. static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
  976. struct ib_device *ibdev)
  977. {
  978. struct ib_pma_portsamplesresult *p =
  979. (struct ib_pma_portsamplesresult *)pmp->data;
  980. struct ipath_ibdev *dev = to_idev(ibdev);
  981. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  982. u8 status;
  983. int i;
  984. memset(pmp->data, 0, sizeof(pmp->data));
  985. p->tag = cpu_to_be16(dev->pma_tag);
  986. if (crp->cr_psstat)
  987. status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  988. else
  989. status = dev->pma_sample_status;
  990. p->sample_status = cpu_to_be16(status);
  991. for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
  992. p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
  993. cpu_to_be32(
  994. get_counter(dev, crp, dev->pma_counter_select[i]));
  995. return reply((struct ib_smp *) pmp);
  996. }
  997. static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
  998. struct ib_device *ibdev)
  999. {
  1000. struct ib_pma_portsamplesresult_ext *p =
  1001. (struct ib_pma_portsamplesresult_ext *)pmp->data;
  1002. struct ipath_ibdev *dev = to_idev(ibdev);
  1003. struct ipath_cregs const *crp = dev->dd->ipath_cregs;
  1004. u8 status;
  1005. int i;
  1006. memset(pmp->data, 0, sizeof(pmp->data));
  1007. p->tag = cpu_to_be16(dev->pma_tag);
  1008. if (crp->cr_psstat)
  1009. status = ipath_read_creg32(dev->dd, crp->cr_psstat);
  1010. else
  1011. status = dev->pma_sample_status;
  1012. p->sample_status = cpu_to_be16(status);
  1013. /* 64 bits */
  1014. p->extended_width = __constant_cpu_to_be32(0x80000000);
  1015. for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
  1016. p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
  1017. cpu_to_be64(
  1018. get_counter(dev, crp, dev->pma_counter_select[i]));
  1019. return reply((struct ib_smp *) pmp);
  1020. }
  1021. static int recv_pma_get_portcounters(struct ib_perf *pmp,
  1022. struct ib_device *ibdev, u8 port)
  1023. {
  1024. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1025. pmp->data;
  1026. struct ipath_ibdev *dev = to_idev(ibdev);
  1027. struct ipath_verbs_counters cntrs;
  1028. u8 port_select = p->port_select;
  1029. ipath_get_counters(dev->dd, &cntrs);
  1030. /* Adjust counters for any resets done. */
  1031. cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
  1032. cntrs.link_error_recovery_counter -=
  1033. dev->z_link_error_recovery_counter;
  1034. cntrs.link_downed_counter -= dev->z_link_downed_counter;
  1035. cntrs.port_rcv_errors += dev->rcv_errors;
  1036. cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
  1037. cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
  1038. cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
  1039. cntrs.port_xmit_data -= dev->z_port_xmit_data;
  1040. cntrs.port_rcv_data -= dev->z_port_rcv_data;
  1041. cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
  1042. cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
  1043. cntrs.local_link_integrity_errors -=
  1044. dev->z_local_link_integrity_errors;
  1045. cntrs.excessive_buffer_overrun_errors -=
  1046. dev->z_excessive_buffer_overrun_errors;
  1047. cntrs.vl15_dropped -= dev->z_vl15_dropped;
  1048. cntrs.vl15_dropped += dev->n_vl15_dropped;
  1049. memset(pmp->data, 0, sizeof(pmp->data));
  1050. p->port_select = port_select;
  1051. if (pmp->attr_mod != 0 ||
  1052. (port_select != port && port_select != 0xFF))
  1053. pmp->status |= IB_SMP_INVALID_FIELD;
  1054. if (cntrs.symbol_error_counter > 0xFFFFUL)
  1055. p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
  1056. else
  1057. p->symbol_error_counter =
  1058. cpu_to_be16((u16)cntrs.symbol_error_counter);
  1059. if (cntrs.link_error_recovery_counter > 0xFFUL)
  1060. p->link_error_recovery_counter = 0xFF;
  1061. else
  1062. p->link_error_recovery_counter =
  1063. (u8)cntrs.link_error_recovery_counter;
  1064. if (cntrs.link_downed_counter > 0xFFUL)
  1065. p->link_downed_counter = 0xFF;
  1066. else
  1067. p->link_downed_counter = (u8)cntrs.link_downed_counter;
  1068. if (cntrs.port_rcv_errors > 0xFFFFUL)
  1069. p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
  1070. else
  1071. p->port_rcv_errors =
  1072. cpu_to_be16((u16) cntrs.port_rcv_errors);
  1073. if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
  1074. p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
  1075. else
  1076. p->port_rcv_remphys_errors =
  1077. cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
  1078. if (cntrs.port_xmit_discards > 0xFFFFUL)
  1079. p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
  1080. else
  1081. p->port_xmit_discards =
  1082. cpu_to_be16((u16)cntrs.port_xmit_discards);
  1083. if (cntrs.local_link_integrity_errors > 0xFUL)
  1084. cntrs.local_link_integrity_errors = 0xFUL;
  1085. if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
  1086. cntrs.excessive_buffer_overrun_errors = 0xFUL;
  1087. p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
  1088. cntrs.excessive_buffer_overrun_errors;
  1089. if (cntrs.vl15_dropped > 0xFFFFUL)
  1090. p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
  1091. else
  1092. p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
  1093. if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
  1094. p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
  1095. else
  1096. p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
  1097. if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
  1098. p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
  1099. else
  1100. p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
  1101. if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
  1102. p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
  1103. else
  1104. p->port_xmit_packets =
  1105. cpu_to_be32((u32)cntrs.port_xmit_packets);
  1106. if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
  1107. p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
  1108. else
  1109. p->port_rcv_packets =
  1110. cpu_to_be32((u32) cntrs.port_rcv_packets);
  1111. return reply((struct ib_smp *) pmp);
  1112. }
  1113. static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
  1114. struct ib_device *ibdev, u8 port)
  1115. {
  1116. struct ib_pma_portcounters_ext *p =
  1117. (struct ib_pma_portcounters_ext *)pmp->data;
  1118. struct ipath_ibdev *dev = to_idev(ibdev);
  1119. u64 swords, rwords, spkts, rpkts, xwait;
  1120. u8 port_select = p->port_select;
  1121. ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
  1122. &rpkts, &xwait);
  1123. /* Adjust counters for any resets done. */
  1124. swords -= dev->z_port_xmit_data;
  1125. rwords -= dev->z_port_rcv_data;
  1126. spkts -= dev->z_port_xmit_packets;
  1127. rpkts -= dev->z_port_rcv_packets;
  1128. memset(pmp->data, 0, sizeof(pmp->data));
  1129. p->port_select = port_select;
  1130. if (pmp->attr_mod != 0 ||
  1131. (port_select != port && port_select != 0xFF))
  1132. pmp->status |= IB_SMP_INVALID_FIELD;
  1133. p->port_xmit_data = cpu_to_be64(swords);
  1134. p->port_rcv_data = cpu_to_be64(rwords);
  1135. p->port_xmit_packets = cpu_to_be64(spkts);
  1136. p->port_rcv_packets = cpu_to_be64(rpkts);
  1137. p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
  1138. p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
  1139. p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
  1140. p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
  1141. return reply((struct ib_smp *) pmp);
  1142. }
  1143. static int recv_pma_set_portcounters(struct ib_perf *pmp,
  1144. struct ib_device *ibdev, u8 port)
  1145. {
  1146. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1147. pmp->data;
  1148. struct ipath_ibdev *dev = to_idev(ibdev);
  1149. struct ipath_verbs_counters cntrs;
  1150. /*
  1151. * Since the HW doesn't support clearing counters, we save the
  1152. * current count and subtract it from future responses.
  1153. */
  1154. ipath_get_counters(dev->dd, &cntrs);
  1155. if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
  1156. dev->z_symbol_error_counter = cntrs.symbol_error_counter;
  1157. if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
  1158. dev->z_link_error_recovery_counter =
  1159. cntrs.link_error_recovery_counter;
  1160. if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
  1161. dev->z_link_downed_counter = cntrs.link_downed_counter;
  1162. if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
  1163. dev->z_port_rcv_errors =
  1164. cntrs.port_rcv_errors + dev->rcv_errors;
  1165. if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
  1166. dev->z_port_rcv_remphys_errors =
  1167. cntrs.port_rcv_remphys_errors;
  1168. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
  1169. dev->z_port_xmit_discards = cntrs.port_xmit_discards;
  1170. if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
  1171. dev->z_local_link_integrity_errors =
  1172. cntrs.local_link_integrity_errors;
  1173. if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
  1174. dev->z_excessive_buffer_overrun_errors =
  1175. cntrs.excessive_buffer_overrun_errors;
  1176. if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
  1177. dev->n_vl15_dropped = 0;
  1178. dev->z_vl15_dropped = cntrs.vl15_dropped;
  1179. }
  1180. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
  1181. dev->z_port_xmit_data = cntrs.port_xmit_data;
  1182. if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
  1183. dev->z_port_rcv_data = cntrs.port_rcv_data;
  1184. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
  1185. dev->z_port_xmit_packets = cntrs.port_xmit_packets;
  1186. if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
  1187. dev->z_port_rcv_packets = cntrs.port_rcv_packets;
  1188. return recv_pma_get_portcounters(pmp, ibdev, port);
  1189. }
  1190. static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
  1191. struct ib_device *ibdev, u8 port)
  1192. {
  1193. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1194. pmp->data;
  1195. struct ipath_ibdev *dev = to_idev(ibdev);
  1196. u64 swords, rwords, spkts, rpkts, xwait;
  1197. ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
  1198. &rpkts, &xwait);
  1199. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
  1200. dev->z_port_xmit_data = swords;
  1201. if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
  1202. dev->z_port_rcv_data = rwords;
  1203. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
  1204. dev->z_port_xmit_packets = spkts;
  1205. if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
  1206. dev->z_port_rcv_packets = rpkts;
  1207. if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
  1208. dev->n_unicast_xmit = 0;
  1209. if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
  1210. dev->n_unicast_rcv = 0;
  1211. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
  1212. dev->n_multicast_xmit = 0;
  1213. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
  1214. dev->n_multicast_rcv = 0;
  1215. return recv_pma_get_portcounters_ext(pmp, ibdev, port);
  1216. }
  1217. static int process_subn(struct ib_device *ibdev, int mad_flags,
  1218. u8 port_num, struct ib_mad *in_mad,
  1219. struct ib_mad *out_mad)
  1220. {
  1221. struct ib_smp *smp = (struct ib_smp *)out_mad;
  1222. struct ipath_ibdev *dev = to_idev(ibdev);
  1223. int ret;
  1224. *out_mad = *in_mad;
  1225. if (smp->class_version != 1) {
  1226. smp->status |= IB_SMP_UNSUP_VERSION;
  1227. ret = reply(smp);
  1228. goto bail;
  1229. }
  1230. /* Is the mkey in the process of expiring? */
  1231. if (dev->mkey_lease_timeout &&
  1232. time_after_eq(jiffies, dev->mkey_lease_timeout)) {
  1233. /* Clear timeout and mkey protection field. */
  1234. dev->mkey_lease_timeout = 0;
  1235. dev->mkeyprot = 0;
  1236. }
  1237. /*
  1238. * M_Key checking depends on
  1239. * Portinfo:M_Key_protect_bits
  1240. */
  1241. if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
  1242. dev->mkey != smp->mkey &&
  1243. (smp->method == IB_MGMT_METHOD_SET ||
  1244. (smp->method == IB_MGMT_METHOD_GET &&
  1245. dev->mkeyprot >= 2))) {
  1246. if (dev->mkey_violations != 0xFFFF)
  1247. ++dev->mkey_violations;
  1248. if (dev->mkey_lease_timeout ||
  1249. dev->mkey_lease_period == 0) {
  1250. ret = IB_MAD_RESULT_SUCCESS |
  1251. IB_MAD_RESULT_CONSUMED;
  1252. goto bail;
  1253. }
  1254. dev->mkey_lease_timeout = jiffies +
  1255. dev->mkey_lease_period * HZ;
  1256. /* Future: Generate a trap notice. */
  1257. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  1258. goto bail;
  1259. } else if (dev->mkey_lease_timeout)
  1260. dev->mkey_lease_timeout = 0;
  1261. switch (smp->method) {
  1262. case IB_MGMT_METHOD_GET:
  1263. switch (smp->attr_id) {
  1264. case IB_SMP_ATTR_NODE_DESC:
  1265. ret = recv_subn_get_nodedescription(smp, ibdev);
  1266. goto bail;
  1267. case IB_SMP_ATTR_NODE_INFO:
  1268. ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
  1269. goto bail;
  1270. case IB_SMP_ATTR_GUID_INFO:
  1271. ret = recv_subn_get_guidinfo(smp, ibdev);
  1272. goto bail;
  1273. case IB_SMP_ATTR_PORT_INFO:
  1274. ret = recv_subn_get_portinfo(smp, ibdev, port_num);
  1275. goto bail;
  1276. case IB_SMP_ATTR_PKEY_TABLE:
  1277. ret = recv_subn_get_pkeytable(smp, ibdev);
  1278. goto bail;
  1279. case IB_SMP_ATTR_SM_INFO:
  1280. if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
  1281. ret = IB_MAD_RESULT_SUCCESS |
  1282. IB_MAD_RESULT_CONSUMED;
  1283. goto bail;
  1284. }
  1285. if (dev->port_cap_flags & IB_PORT_SM) {
  1286. ret = IB_MAD_RESULT_SUCCESS;
  1287. goto bail;
  1288. }
  1289. /* FALLTHROUGH */
  1290. default:
  1291. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1292. ret = reply(smp);
  1293. goto bail;
  1294. }
  1295. case IB_MGMT_METHOD_SET:
  1296. switch (smp->attr_id) {
  1297. case IB_SMP_ATTR_GUID_INFO:
  1298. ret = recv_subn_set_guidinfo(smp, ibdev);
  1299. goto bail;
  1300. case IB_SMP_ATTR_PORT_INFO:
  1301. ret = recv_subn_set_portinfo(smp, ibdev, port_num);
  1302. goto bail;
  1303. case IB_SMP_ATTR_PKEY_TABLE:
  1304. ret = recv_subn_set_pkeytable(smp, ibdev);
  1305. goto bail;
  1306. case IB_SMP_ATTR_SM_INFO:
  1307. if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
  1308. ret = IB_MAD_RESULT_SUCCESS |
  1309. IB_MAD_RESULT_CONSUMED;
  1310. goto bail;
  1311. }
  1312. if (dev->port_cap_flags & IB_PORT_SM) {
  1313. ret = IB_MAD_RESULT_SUCCESS;
  1314. goto bail;
  1315. }
  1316. /* FALLTHROUGH */
  1317. default:
  1318. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1319. ret = reply(smp);
  1320. goto bail;
  1321. }
  1322. case IB_MGMT_METHOD_TRAP:
  1323. case IB_MGMT_METHOD_REPORT:
  1324. case IB_MGMT_METHOD_REPORT_RESP:
  1325. case IB_MGMT_METHOD_TRAP_REPRESS:
  1326. case IB_MGMT_METHOD_GET_RESP:
  1327. /*
  1328. * The ib_mad module will call us to process responses
  1329. * before checking for other consumers.
  1330. * Just tell the caller to process it normally.
  1331. */
  1332. ret = IB_MAD_RESULT_SUCCESS;
  1333. goto bail;
  1334. default:
  1335. smp->status |= IB_SMP_UNSUP_METHOD;
  1336. ret = reply(smp);
  1337. }
  1338. bail:
  1339. return ret;
  1340. }
  1341. static int process_perf(struct ib_device *ibdev, u8 port_num,
  1342. struct ib_mad *in_mad,
  1343. struct ib_mad *out_mad)
  1344. {
  1345. struct ib_perf *pmp = (struct ib_perf *)out_mad;
  1346. int ret;
  1347. *out_mad = *in_mad;
  1348. if (pmp->class_version != 1) {
  1349. pmp->status |= IB_SMP_UNSUP_VERSION;
  1350. ret = reply((struct ib_smp *) pmp);
  1351. goto bail;
  1352. }
  1353. switch (pmp->method) {
  1354. case IB_MGMT_METHOD_GET:
  1355. switch (pmp->attr_id) {
  1356. case IB_PMA_CLASS_PORT_INFO:
  1357. ret = recv_pma_get_classportinfo(pmp);
  1358. goto bail;
  1359. case IB_PMA_PORT_SAMPLES_CONTROL:
  1360. ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
  1361. port_num);
  1362. goto bail;
  1363. case IB_PMA_PORT_SAMPLES_RESULT:
  1364. ret = recv_pma_get_portsamplesresult(pmp, ibdev);
  1365. goto bail;
  1366. case IB_PMA_PORT_SAMPLES_RESULT_EXT:
  1367. ret = recv_pma_get_portsamplesresult_ext(pmp,
  1368. ibdev);
  1369. goto bail;
  1370. case IB_PMA_PORT_COUNTERS:
  1371. ret = recv_pma_get_portcounters(pmp, ibdev,
  1372. port_num);
  1373. goto bail;
  1374. case IB_PMA_PORT_COUNTERS_EXT:
  1375. ret = recv_pma_get_portcounters_ext(pmp, ibdev,
  1376. port_num);
  1377. goto bail;
  1378. default:
  1379. pmp->status |= IB_SMP_UNSUP_METH_ATTR;
  1380. ret = reply((struct ib_smp *) pmp);
  1381. goto bail;
  1382. }
  1383. case IB_MGMT_METHOD_SET:
  1384. switch (pmp->attr_id) {
  1385. case IB_PMA_PORT_SAMPLES_CONTROL:
  1386. ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
  1387. port_num);
  1388. goto bail;
  1389. case IB_PMA_PORT_COUNTERS:
  1390. ret = recv_pma_set_portcounters(pmp, ibdev,
  1391. port_num);
  1392. goto bail;
  1393. case IB_PMA_PORT_COUNTERS_EXT:
  1394. ret = recv_pma_set_portcounters_ext(pmp, ibdev,
  1395. port_num);
  1396. goto bail;
  1397. default:
  1398. pmp->status |= IB_SMP_UNSUP_METH_ATTR;
  1399. ret = reply((struct ib_smp *) pmp);
  1400. goto bail;
  1401. }
  1402. case IB_MGMT_METHOD_GET_RESP:
  1403. /*
  1404. * The ib_mad module will call us to process responses
  1405. * before checking for other consumers.
  1406. * Just tell the caller to process it normally.
  1407. */
  1408. ret = IB_MAD_RESULT_SUCCESS;
  1409. goto bail;
  1410. default:
  1411. pmp->status |= IB_SMP_UNSUP_METHOD;
  1412. ret = reply((struct ib_smp *) pmp);
  1413. }
  1414. bail:
  1415. return ret;
  1416. }
  1417. /**
  1418. * ipath_process_mad - process an incoming MAD packet
  1419. * @ibdev: the infiniband device this packet came in on
  1420. * @mad_flags: MAD flags
  1421. * @port_num: the port number this packet came in on
  1422. * @in_wc: the work completion entry for this packet
  1423. * @in_grh: the global route header for this packet
  1424. * @in_mad: the incoming MAD
  1425. * @out_mad: any outgoing MAD reply
  1426. *
  1427. * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
  1428. * interested in processing.
  1429. *
  1430. * Note that the verbs framework has already done the MAD sanity checks,
  1431. * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  1432. * MADs.
  1433. *
  1434. * This is called by the ib_mad module.
  1435. */
  1436. int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  1437. struct ib_wc *in_wc, struct ib_grh *in_grh,
  1438. struct ib_mad *in_mad, struct ib_mad *out_mad)
  1439. {
  1440. int ret;
  1441. switch (in_mad->mad_hdr.mgmt_class) {
  1442. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  1443. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  1444. ret = process_subn(ibdev, mad_flags, port_num,
  1445. in_mad, out_mad);
  1446. goto bail;
  1447. case IB_MGMT_CLASS_PERF_MGMT:
  1448. ret = process_perf(ibdev, port_num, in_mad, out_mad);
  1449. goto bail;
  1450. default:
  1451. ret = IB_MAD_RESULT_SUCCESS;
  1452. }
  1453. bail:
  1454. return ret;
  1455. }