ipath_mad.c 43 KB

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