ipath_mad.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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 = ipath_layer_get_guid(dd);
  94. nip->port_guid = nip->sys_guid;
  95. nip->partition_cap = cpu_to_be16(ipath_layer_get_npkeys(dd));
  96. nip->device_id = cpu_to_be16(ipath_layer_get_deviceid(dd));
  97. majrev = ipath_layer_get_majrev(dd);
  98. minrev = ipath_layer_get_minrev(dd);
  99. nip->revision = cpu_to_be32((majrev << 16) | minrev);
  100. nip->local_port_num = port;
  101. vendor = ipath_layer_get_vendorid(dd);
  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 = ipath_layer_get_guid(to_idev(ibdev)->dd);
  121. else
  122. smp->status |= IB_SMP_INVALID_FIELD;
  123. return reply(smp);
  124. }
  125. static int recv_subn_get_portinfo(struct ib_smp *smp,
  126. struct ib_device *ibdev, u8 port)
  127. {
  128. struct ipath_ibdev *dev;
  129. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  130. u16 lid;
  131. u8 ibcstat;
  132. u8 mtu;
  133. int ret;
  134. if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
  135. smp->status |= IB_SMP_INVALID_FIELD;
  136. ret = reply(smp);
  137. goto bail;
  138. }
  139. dev = to_idev(ibdev);
  140. /* Clear all fields. Only set the non-zero fields. */
  141. memset(smp->data, 0, sizeof(smp->data));
  142. /* Only return the mkey if the protection field allows it. */
  143. if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
  144. (dev->mkeyprot_resv_lmc >> 6) == 0)
  145. pip->mkey = dev->mkey;
  146. pip->gid_prefix = dev->gid_prefix;
  147. lid = ipath_layer_get_lid(dev->dd);
  148. pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
  149. pip->sm_lid = cpu_to_be16(dev->sm_lid);
  150. pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
  151. /* pip->diag_code; */
  152. pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
  153. pip->local_port_num = port;
  154. pip->link_width_enabled = dev->link_width_enabled;
  155. pip->link_width_supported = 3; /* 1x or 4x */
  156. pip->link_width_active = 2; /* 4x */
  157. pip->linkspeed_portstate = 0x10; /* 2.5Gbps */
  158. ibcstat = ipath_layer_get_lastibcstat(dev->dd);
  159. pip->linkspeed_portstate |= ((ibcstat >> 4) & 0x3) + 1;
  160. pip->portphysstate_linkdown =
  161. (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
  162. (ipath_layer_get_linkdowndefaultstate(dev->dd) ? 1 : 2);
  163. pip->mkeyprot_resv_lmc = dev->mkeyprot_resv_lmc;
  164. pip->linkspeedactive_enabled = 0x11; /* 2.5Gbps, 2.5Gbps */
  165. switch (ipath_layer_get_ibmtu(dev->dd)) {
  166. case 4096:
  167. mtu = IB_MTU_4096;
  168. break;
  169. case 2048:
  170. mtu = IB_MTU_2048;
  171. break;
  172. case 1024:
  173. mtu = IB_MTU_1024;
  174. break;
  175. case 512:
  176. mtu = IB_MTU_512;
  177. break;
  178. case 256:
  179. mtu = IB_MTU_256;
  180. break;
  181. default: /* oops, something is wrong */
  182. mtu = IB_MTU_2048;
  183. break;
  184. }
  185. pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
  186. pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
  187. pip->vl_high_limit = dev->vl_high_limit;
  188. /* pip->vl_arb_high_cap; // only one VL */
  189. /* pip->vl_arb_low_cap; // only one VL */
  190. /* InitTypeReply = 0 */
  191. pip->inittypereply_mtucap = IB_MTU_4096;
  192. // HCAs ignore VLStallCount and HOQLife
  193. /* pip->vlstallcnt_hoqlife; */
  194. pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
  195. pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
  196. /* P_KeyViolations are counted by hardware. */
  197. pip->pkey_violations =
  198. cpu_to_be16((ipath_layer_get_cr_errpkey(dev->dd) -
  199. dev->z_pkey_violations) & 0xFFFF);
  200. pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
  201. /* Only the hardware GUID is supported for now */
  202. pip->guid_cap = 1;
  203. pip->clientrereg_resv_subnetto = dev->subnet_timeout;
  204. /* 32.768 usec. response time (guessing) */
  205. pip->resv_resptimevalue = 3;
  206. pip->localphyerrors_overrunerrors =
  207. (ipath_layer_get_phyerrthreshold(dev->dd) << 4) |
  208. ipath_layer_get_overrunthreshold(dev->dd);
  209. /* pip->max_credit_hint; */
  210. /* pip->link_roundtrip_latency[3]; */
  211. ret = reply(smp);
  212. bail:
  213. return ret;
  214. }
  215. static int recv_subn_get_pkeytable(struct ib_smp *smp,
  216. struct ib_device *ibdev)
  217. {
  218. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  219. u16 *p = (u16 *) smp->data;
  220. __be16 *q = (__be16 *) smp->data;
  221. /* 64 blocks of 32 16-bit P_Key entries */
  222. memset(smp->data, 0, sizeof(smp->data));
  223. if (startpx == 0) {
  224. struct ipath_ibdev *dev = to_idev(ibdev);
  225. unsigned i, n = ipath_layer_get_npkeys(dev->dd);
  226. ipath_layer_get_pkeys(dev->dd, p);
  227. for (i = 0; i < n; i++)
  228. q[i] = cpu_to_be16(p[i]);
  229. } else
  230. smp->status |= IB_SMP_INVALID_FIELD;
  231. return reply(smp);
  232. }
  233. static int recv_subn_set_guidinfo(struct ib_smp *smp,
  234. struct ib_device *ibdev)
  235. {
  236. /* The only GUID we support is the first read-only entry. */
  237. return recv_subn_get_guidinfo(smp, ibdev);
  238. }
  239. /**
  240. * recv_subn_set_portinfo - set port information
  241. * @smp: the incoming SM packet
  242. * @ibdev: the infiniband device
  243. * @port: the port on the device
  244. *
  245. * Set Portinfo (see ch. 14.2.5.6).
  246. */
  247. static int recv_subn_set_portinfo(struct ib_smp *smp,
  248. struct ib_device *ibdev, u8 port)
  249. {
  250. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  251. struct ib_event event;
  252. struct ipath_ibdev *dev;
  253. u32 flags;
  254. char clientrereg = 0;
  255. u16 lid, smlid;
  256. u8 lwe;
  257. u8 lse;
  258. u8 state;
  259. u16 lstate;
  260. u32 mtu;
  261. int ret;
  262. if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
  263. goto err;
  264. dev = to_idev(ibdev);
  265. event.device = ibdev;
  266. event.element.port_num = port;
  267. dev->mkey = pip->mkey;
  268. dev->gid_prefix = pip->gid_prefix;
  269. dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
  270. lid = be16_to_cpu(pip->lid);
  271. if (lid != ipath_layer_get_lid(dev->dd)) {
  272. /* Must be a valid unicast LID address. */
  273. if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
  274. goto err;
  275. ipath_set_lid(dev->dd, lid, pip->mkeyprot_resv_lmc & 7);
  276. event.event = IB_EVENT_LID_CHANGE;
  277. ib_dispatch_event(&event);
  278. }
  279. smlid = be16_to_cpu(pip->sm_lid);
  280. if (smlid != dev->sm_lid) {
  281. /* Must be a valid unicast LID address. */
  282. if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
  283. goto err;
  284. dev->sm_lid = smlid;
  285. event.event = IB_EVENT_SM_CHANGE;
  286. ib_dispatch_event(&event);
  287. }
  288. /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
  289. lwe = pip->link_width_enabled;
  290. if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
  291. goto err;
  292. if (lwe == 0xFF)
  293. dev->link_width_enabled = 3; /* 1x or 4x */
  294. else if (lwe)
  295. dev->link_width_enabled = lwe;
  296. /* Only 2.5 Gbs supported. */
  297. lse = pip->linkspeedactive_enabled & 0xF;
  298. if (lse >= 2 && lse <= 0xE)
  299. goto err;
  300. /* Set link down default state. */
  301. switch (pip->portphysstate_linkdown & 0xF) {
  302. case 0: /* NOP */
  303. break;
  304. case 1: /* SLEEP */
  305. if (ipath_layer_set_linkdowndefaultstate(dev->dd, 1))
  306. goto err;
  307. break;
  308. case 2: /* POLL */
  309. if (ipath_layer_set_linkdowndefaultstate(dev->dd, 0))
  310. goto err;
  311. break;
  312. default:
  313. goto err;
  314. }
  315. dev->mkeyprot_resv_lmc = pip->mkeyprot_resv_lmc;
  316. dev->vl_high_limit = pip->vl_high_limit;
  317. switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
  318. case IB_MTU_256:
  319. mtu = 256;
  320. break;
  321. case IB_MTU_512:
  322. mtu = 512;
  323. break;
  324. case IB_MTU_1024:
  325. mtu = 1024;
  326. break;
  327. case IB_MTU_2048:
  328. mtu = 2048;
  329. break;
  330. case IB_MTU_4096:
  331. mtu = 4096;
  332. break;
  333. default:
  334. /* XXX We have already partially updated our state! */
  335. goto err;
  336. }
  337. ipath_layer_set_mtu(dev->dd, mtu);
  338. dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
  339. /* We only support VL0 */
  340. if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
  341. goto err;
  342. if (pip->mkey_violations == 0)
  343. dev->mkey_violations = 0;
  344. /*
  345. * Hardware counter can't be reset so snapshot and subtract
  346. * later.
  347. */
  348. if (pip->pkey_violations == 0)
  349. dev->z_pkey_violations =
  350. ipath_layer_get_cr_errpkey(dev->dd);
  351. if (pip->qkey_violations == 0)
  352. dev->qkey_violations = 0;
  353. if (ipath_layer_set_phyerrthreshold(
  354. dev->dd,
  355. (pip->localphyerrors_overrunerrors >> 4) & 0xF))
  356. goto err;
  357. if (ipath_layer_set_overrunthreshold(
  358. dev->dd,
  359. (pip->localphyerrors_overrunerrors & 0xF)))
  360. goto err;
  361. dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
  362. if (pip->clientrereg_resv_subnetto & 0x80) {
  363. clientrereg = 1;
  364. event.event = IB_EVENT_CLIENT_REREGISTER;
  365. ib_dispatch_event(&event);
  366. }
  367. /*
  368. * Do the port state change now that the other link parameters
  369. * have been set.
  370. * Changing the port physical state only makes sense if the link
  371. * is down or is being set to down.
  372. */
  373. state = pip->linkspeed_portstate & 0xF;
  374. flags = ipath_layer_get_flags(dev->dd);
  375. lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
  376. if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
  377. goto err;
  378. /*
  379. * Only state changes of DOWN, ARM, and ACTIVE are valid
  380. * and must be in the correct state to take effect (see 7.2.6).
  381. */
  382. switch (state) {
  383. case IB_PORT_NOP:
  384. if (lstate == 0)
  385. break;
  386. /* FALLTHROUGH */
  387. case IB_PORT_DOWN:
  388. if (lstate == 0)
  389. if (ipath_layer_get_linkdowndefaultstate(dev->dd))
  390. lstate = IPATH_IB_LINKDOWN_SLEEP;
  391. else
  392. lstate = IPATH_IB_LINKDOWN;
  393. else if (lstate == 1)
  394. lstate = IPATH_IB_LINKDOWN_SLEEP;
  395. else if (lstate == 2)
  396. lstate = IPATH_IB_LINKDOWN;
  397. else if (lstate == 3)
  398. lstate = IPATH_IB_LINKDOWN_DISABLE;
  399. else
  400. goto err;
  401. ipath_layer_set_linkstate(dev->dd, lstate);
  402. if (flags & IPATH_LINKACTIVE) {
  403. event.event = IB_EVENT_PORT_ERR;
  404. ib_dispatch_event(&event);
  405. }
  406. break;
  407. case IB_PORT_ARMED:
  408. if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
  409. break;
  410. ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKARM);
  411. if (flags & IPATH_LINKACTIVE) {
  412. event.event = IB_EVENT_PORT_ERR;
  413. ib_dispatch_event(&event);
  414. }
  415. break;
  416. case IB_PORT_ACTIVE:
  417. if (!(flags & IPATH_LINKARMED))
  418. break;
  419. ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKACTIVE);
  420. event.event = IB_EVENT_PORT_ACTIVE;
  421. ib_dispatch_event(&event);
  422. break;
  423. default:
  424. /* XXX We have already partially updated our state! */
  425. goto err;
  426. }
  427. ret = recv_subn_get_portinfo(smp, ibdev, port);
  428. if (clientrereg)
  429. pip->clientrereg_resv_subnetto |= 0x80;
  430. goto done;
  431. err:
  432. smp->status |= IB_SMP_INVALID_FIELD;
  433. ret = recv_subn_get_portinfo(smp, ibdev, port);
  434. done:
  435. return ret;
  436. }
  437. static int recv_subn_set_pkeytable(struct ib_smp *smp,
  438. struct ib_device *ibdev)
  439. {
  440. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  441. __be16 *p = (__be16 *) smp->data;
  442. u16 *q = (u16 *) smp->data;
  443. struct ipath_ibdev *dev = to_idev(ibdev);
  444. unsigned i, n = ipath_layer_get_npkeys(dev->dd);
  445. for (i = 0; i < n; i++)
  446. q[i] = be16_to_cpu(p[i]);
  447. if (startpx != 0 ||
  448. ipath_layer_set_pkeys(dev->dd, q) != 0)
  449. smp->status |= IB_SMP_INVALID_FIELD;
  450. return recv_subn_get_pkeytable(smp, ibdev);
  451. }
  452. #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
  453. #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
  454. #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
  455. #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
  456. #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
  457. #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
  458. struct ib_perf {
  459. u8 base_version;
  460. u8 mgmt_class;
  461. u8 class_version;
  462. u8 method;
  463. __be16 status;
  464. __be16 unused;
  465. __be64 tid;
  466. __be16 attr_id;
  467. __be16 resv;
  468. __be32 attr_mod;
  469. u8 reserved[40];
  470. u8 data[192];
  471. } __attribute__ ((packed));
  472. struct ib_pma_classportinfo {
  473. u8 base_version;
  474. u8 class_version;
  475. __be16 cap_mask;
  476. u8 reserved[3];
  477. u8 resp_time_value; /* only lower 5 bits */
  478. union ib_gid redirect_gid;
  479. __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
  480. __be16 redirect_lid;
  481. __be16 redirect_pkey;
  482. __be32 redirect_qp; /* only lower 24 bits */
  483. __be32 redirect_qkey;
  484. union ib_gid trap_gid;
  485. __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
  486. __be16 trap_lid;
  487. __be16 trap_pkey;
  488. __be32 trap_hl_qp; /* 8, 24 bits respectively */
  489. __be32 trap_qkey;
  490. } __attribute__ ((packed));
  491. struct ib_pma_portsamplescontrol {
  492. u8 opcode;
  493. u8 port_select;
  494. u8 tick;
  495. u8 counter_width; /* only lower 3 bits */
  496. __be32 counter_mask0_9; /* 2, 10 * 3, bits */
  497. __be16 counter_mask10_14; /* 1, 5 * 3, bits */
  498. u8 sample_mechanisms;
  499. u8 sample_status; /* only lower 2 bits */
  500. __be64 option_mask;
  501. __be64 vendor_mask;
  502. __be32 sample_start;
  503. __be32 sample_interval;
  504. __be16 tag;
  505. __be16 counter_select[15];
  506. } __attribute__ ((packed));
  507. struct ib_pma_portsamplesresult {
  508. __be16 tag;
  509. __be16 sample_status; /* only lower 2 bits */
  510. __be32 counter[15];
  511. } __attribute__ ((packed));
  512. struct ib_pma_portsamplesresult_ext {
  513. __be16 tag;
  514. __be16 sample_status; /* only lower 2 bits */
  515. __be32 extended_width; /* only upper 2 bits */
  516. __be64 counter[15];
  517. } __attribute__ ((packed));
  518. struct ib_pma_portcounters {
  519. u8 reserved;
  520. u8 port_select;
  521. __be16 counter_select;
  522. __be16 symbol_error_counter;
  523. u8 link_error_recovery_counter;
  524. u8 link_downed_counter;
  525. __be16 port_rcv_errors;
  526. __be16 port_rcv_remphys_errors;
  527. __be16 port_rcv_switch_relay_errors;
  528. __be16 port_xmit_discards;
  529. u8 port_xmit_constraint_errors;
  530. u8 port_rcv_constraint_errors;
  531. u8 reserved1;
  532. u8 lli_ebor_errors; /* 4, 4, bits */
  533. __be16 reserved2;
  534. __be16 vl15_dropped;
  535. __be32 port_xmit_data;
  536. __be32 port_rcv_data;
  537. __be32 port_xmit_packets;
  538. __be32 port_rcv_packets;
  539. } __attribute__ ((packed));
  540. #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
  541. #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
  542. #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
  543. #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
  544. #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
  545. #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
  546. #define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
  547. #define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
  548. #define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
  549. #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
  550. #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
  551. #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
  552. #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
  553. struct ib_pma_portcounters_ext {
  554. u8 reserved;
  555. u8 port_select;
  556. __be16 counter_select;
  557. __be32 reserved1;
  558. __be64 port_xmit_data;
  559. __be64 port_rcv_data;
  560. __be64 port_xmit_packets;
  561. __be64 port_rcv_packets;
  562. __be64 port_unicast_xmit_packets;
  563. __be64 port_unicast_rcv_packets;
  564. __be64 port_multicast_xmit_packets;
  565. __be64 port_multicast_rcv_packets;
  566. } __attribute__ ((packed));
  567. #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
  568. #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
  569. #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
  570. #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
  571. #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
  572. #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
  573. #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
  574. #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
  575. static int recv_pma_get_classportinfo(struct ib_perf *pmp)
  576. {
  577. struct ib_pma_classportinfo *p =
  578. (struct ib_pma_classportinfo *)pmp->data;
  579. memset(pmp->data, 0, sizeof(pmp->data));
  580. if (pmp->attr_mod != 0)
  581. pmp->status |= IB_SMP_INVALID_FIELD;
  582. /* Indicate AllPortSelect is valid (only one port anyway) */
  583. p->cap_mask = __constant_cpu_to_be16(1 << 8);
  584. p->base_version = 1;
  585. p->class_version = 1;
  586. /*
  587. * Expected response time is 4.096 usec. * 2^18 == 1.073741824
  588. * sec.
  589. */
  590. p->resp_time_value = 18;
  591. return reply((struct ib_smp *) pmp);
  592. }
  593. /*
  594. * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
  595. * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
  596. * We support 5 counters which only count the mandatory quantities.
  597. */
  598. #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
  599. #define COUNTER_MASK0_9 \
  600. __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
  601. COUNTER_MASK(1, 1) | \
  602. COUNTER_MASK(1, 2) | \
  603. COUNTER_MASK(1, 3) | \
  604. COUNTER_MASK(1, 4))
  605. static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
  606. struct ib_device *ibdev, u8 port)
  607. {
  608. struct ib_pma_portsamplescontrol *p =
  609. (struct ib_pma_portsamplescontrol *)pmp->data;
  610. struct ipath_ibdev *dev = to_idev(ibdev);
  611. unsigned long flags;
  612. u8 port_select = p->port_select;
  613. memset(pmp->data, 0, sizeof(pmp->data));
  614. p->port_select = port_select;
  615. if (pmp->attr_mod != 0 ||
  616. (port_select != port && port_select != 0xFF))
  617. pmp->status |= IB_SMP_INVALID_FIELD;
  618. /*
  619. * Ticks are 10x the link transfer period which for 2.5Gbs is 4
  620. * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
  621. * intervals are counted in ticks. Since we use Linux timers, that
  622. * count in jiffies, we can't sample for less than 1000 ticks if HZ
  623. * == 1000 (4000 ticks if HZ is 250).
  624. */
  625. /* XXX This is WRONG. */
  626. p->tick = 250; /* 1 usec. */
  627. p->counter_width = 4; /* 32 bit counters */
  628. p->counter_mask0_9 = COUNTER_MASK0_9;
  629. spin_lock_irqsave(&dev->pending_lock, flags);
  630. p->sample_status = dev->pma_sample_status;
  631. p->sample_start = cpu_to_be32(dev->pma_sample_start);
  632. p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
  633. p->tag = cpu_to_be16(dev->pma_tag);
  634. p->counter_select[0] = dev->pma_counter_select[0];
  635. p->counter_select[1] = dev->pma_counter_select[1];
  636. p->counter_select[2] = dev->pma_counter_select[2];
  637. p->counter_select[3] = dev->pma_counter_select[3];
  638. p->counter_select[4] = dev->pma_counter_select[4];
  639. spin_unlock_irqrestore(&dev->pending_lock, flags);
  640. return reply((struct ib_smp *) pmp);
  641. }
  642. static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
  643. struct ib_device *ibdev, u8 port)
  644. {
  645. struct ib_pma_portsamplescontrol *p =
  646. (struct ib_pma_portsamplescontrol *)pmp->data;
  647. struct ipath_ibdev *dev = to_idev(ibdev);
  648. unsigned long flags;
  649. u32 start;
  650. int ret;
  651. if (pmp->attr_mod != 0 ||
  652. (p->port_select != port && p->port_select != 0xFF)) {
  653. pmp->status |= IB_SMP_INVALID_FIELD;
  654. ret = reply((struct ib_smp *) pmp);
  655. goto bail;
  656. }
  657. start = be32_to_cpu(p->sample_start);
  658. if (start != 0) {
  659. spin_lock_irqsave(&dev->pending_lock, flags);
  660. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
  661. dev->pma_sample_status =
  662. IB_PMA_SAMPLE_STATUS_STARTED;
  663. dev->pma_sample_start = start;
  664. dev->pma_sample_interval =
  665. be32_to_cpu(p->sample_interval);
  666. dev->pma_tag = be16_to_cpu(p->tag);
  667. if (p->counter_select[0])
  668. dev->pma_counter_select[0] =
  669. p->counter_select[0];
  670. if (p->counter_select[1])
  671. dev->pma_counter_select[1] =
  672. p->counter_select[1];
  673. if (p->counter_select[2])
  674. dev->pma_counter_select[2] =
  675. p->counter_select[2];
  676. if (p->counter_select[3])
  677. dev->pma_counter_select[3] =
  678. p->counter_select[3];
  679. if (p->counter_select[4])
  680. dev->pma_counter_select[4] =
  681. p->counter_select[4];
  682. }
  683. spin_unlock_irqrestore(&dev->pending_lock, flags);
  684. }
  685. ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
  686. bail:
  687. return ret;
  688. }
  689. static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
  690. {
  691. u64 ret;
  692. switch (sel) {
  693. case IB_PMA_PORT_XMIT_DATA:
  694. ret = dev->ipath_sword;
  695. break;
  696. case IB_PMA_PORT_RCV_DATA:
  697. ret = dev->ipath_rword;
  698. break;
  699. case IB_PMA_PORT_XMIT_PKTS:
  700. ret = dev->ipath_spkts;
  701. break;
  702. case IB_PMA_PORT_RCV_PKTS:
  703. ret = dev->ipath_rpkts;
  704. break;
  705. case IB_PMA_PORT_XMIT_WAIT:
  706. ret = dev->ipath_xmit_wait;
  707. break;
  708. default:
  709. ret = 0;
  710. }
  711. return ret;
  712. }
  713. static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
  714. struct ib_device *ibdev)
  715. {
  716. struct ib_pma_portsamplesresult *p =
  717. (struct ib_pma_portsamplesresult *)pmp->data;
  718. struct ipath_ibdev *dev = to_idev(ibdev);
  719. int i;
  720. memset(pmp->data, 0, sizeof(pmp->data));
  721. p->tag = cpu_to_be16(dev->pma_tag);
  722. p->sample_status = cpu_to_be16(dev->pma_sample_status);
  723. for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
  724. p->counter[i] = cpu_to_be32(
  725. get_counter(dev, dev->pma_counter_select[i]));
  726. return reply((struct ib_smp *) pmp);
  727. }
  728. static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
  729. struct ib_device *ibdev)
  730. {
  731. struct ib_pma_portsamplesresult_ext *p =
  732. (struct ib_pma_portsamplesresult_ext *)pmp->data;
  733. struct ipath_ibdev *dev = to_idev(ibdev);
  734. int i;
  735. memset(pmp->data, 0, sizeof(pmp->data));
  736. p->tag = cpu_to_be16(dev->pma_tag);
  737. p->sample_status = cpu_to_be16(dev->pma_sample_status);
  738. /* 64 bits */
  739. p->extended_width = __constant_cpu_to_be32(0x80000000);
  740. for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
  741. p->counter[i] = cpu_to_be64(
  742. get_counter(dev, dev->pma_counter_select[i]));
  743. return reply((struct ib_smp *) pmp);
  744. }
  745. static int recv_pma_get_portcounters(struct ib_perf *pmp,
  746. struct ib_device *ibdev, u8 port)
  747. {
  748. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  749. pmp->data;
  750. struct ipath_ibdev *dev = to_idev(ibdev);
  751. struct ipath_layer_counters cntrs;
  752. u8 port_select = p->port_select;
  753. ipath_layer_get_counters(dev->dd, &cntrs);
  754. /* Adjust counters for any resets done. */
  755. cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
  756. cntrs.link_error_recovery_counter -=
  757. dev->z_link_error_recovery_counter;
  758. cntrs.link_downed_counter -= dev->z_link_downed_counter;
  759. cntrs.port_rcv_errors += dev->rcv_errors;
  760. cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
  761. cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
  762. cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
  763. cntrs.port_xmit_data -= dev->z_port_xmit_data;
  764. cntrs.port_rcv_data -= dev->z_port_rcv_data;
  765. cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
  766. cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
  767. cntrs.local_link_integrity_errors -=
  768. dev->z_local_link_integrity_errors;
  769. cntrs.excessive_buffer_overrun_errors -=
  770. dev->z_excessive_buffer_overrun_errors;
  771. memset(pmp->data, 0, sizeof(pmp->data));
  772. p->port_select = port_select;
  773. if (pmp->attr_mod != 0 ||
  774. (port_select != port && port_select != 0xFF))
  775. pmp->status |= IB_SMP_INVALID_FIELD;
  776. if (cntrs.symbol_error_counter > 0xFFFFUL)
  777. p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
  778. else
  779. p->symbol_error_counter =
  780. cpu_to_be16((u16)cntrs.symbol_error_counter);
  781. if (cntrs.link_error_recovery_counter > 0xFFUL)
  782. p->link_error_recovery_counter = 0xFF;
  783. else
  784. p->link_error_recovery_counter =
  785. (u8)cntrs.link_error_recovery_counter;
  786. if (cntrs.link_downed_counter > 0xFFUL)
  787. p->link_downed_counter = 0xFF;
  788. else
  789. p->link_downed_counter = (u8)cntrs.link_downed_counter;
  790. if (cntrs.port_rcv_errors > 0xFFFFUL)
  791. p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
  792. else
  793. p->port_rcv_errors =
  794. cpu_to_be16((u16) cntrs.port_rcv_errors);
  795. if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
  796. p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
  797. else
  798. p->port_rcv_remphys_errors =
  799. cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
  800. if (cntrs.port_xmit_discards > 0xFFFFUL)
  801. p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
  802. else
  803. p->port_xmit_discards =
  804. cpu_to_be16((u16)cntrs.port_xmit_discards);
  805. if (cntrs.local_link_integrity_errors > 0xFUL)
  806. cntrs.local_link_integrity_errors = 0xFUL;
  807. if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
  808. cntrs.excessive_buffer_overrun_errors = 0xFUL;
  809. p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
  810. cntrs.excessive_buffer_overrun_errors;
  811. if (dev->n_vl15_dropped > 0xFFFFUL)
  812. p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
  813. else
  814. p->vl15_dropped = cpu_to_be16((u16)dev->n_vl15_dropped);
  815. if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
  816. p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
  817. else
  818. p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
  819. if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
  820. p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
  821. else
  822. p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
  823. if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
  824. p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
  825. else
  826. p->port_xmit_packets =
  827. cpu_to_be32((u32)cntrs.port_xmit_packets);
  828. if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
  829. p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
  830. else
  831. p->port_rcv_packets =
  832. cpu_to_be32((u32) cntrs.port_rcv_packets);
  833. return reply((struct ib_smp *) pmp);
  834. }
  835. static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
  836. struct ib_device *ibdev, u8 port)
  837. {
  838. struct ib_pma_portcounters_ext *p =
  839. (struct ib_pma_portcounters_ext *)pmp->data;
  840. struct ipath_ibdev *dev = to_idev(ibdev);
  841. u64 swords, rwords, spkts, rpkts, xwait;
  842. u8 port_select = p->port_select;
  843. ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
  844. &rpkts, &xwait);
  845. /* Adjust counters for any resets done. */
  846. swords -= dev->z_port_xmit_data;
  847. rwords -= dev->z_port_rcv_data;
  848. spkts -= dev->z_port_xmit_packets;
  849. rpkts -= dev->z_port_rcv_packets;
  850. memset(pmp->data, 0, sizeof(pmp->data));
  851. p->port_select = port_select;
  852. if (pmp->attr_mod != 0 ||
  853. (port_select != port && port_select != 0xFF))
  854. pmp->status |= IB_SMP_INVALID_FIELD;
  855. p->port_xmit_data = cpu_to_be64(swords);
  856. p->port_rcv_data = cpu_to_be64(rwords);
  857. p->port_xmit_packets = cpu_to_be64(spkts);
  858. p->port_rcv_packets = cpu_to_be64(rpkts);
  859. p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
  860. p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
  861. p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
  862. p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
  863. return reply((struct ib_smp *) pmp);
  864. }
  865. static int recv_pma_set_portcounters(struct ib_perf *pmp,
  866. struct ib_device *ibdev, u8 port)
  867. {
  868. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  869. pmp->data;
  870. struct ipath_ibdev *dev = to_idev(ibdev);
  871. struct ipath_layer_counters cntrs;
  872. /*
  873. * Since the HW doesn't support clearing counters, we save the
  874. * current count and subtract it from future responses.
  875. */
  876. ipath_layer_get_counters(dev->dd, &cntrs);
  877. if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
  878. dev->z_symbol_error_counter = cntrs.symbol_error_counter;
  879. if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
  880. dev->z_link_error_recovery_counter =
  881. cntrs.link_error_recovery_counter;
  882. if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
  883. dev->z_link_downed_counter = cntrs.link_downed_counter;
  884. if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
  885. dev->z_port_rcv_errors =
  886. cntrs.port_rcv_errors + dev->rcv_errors;
  887. if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
  888. dev->z_port_rcv_remphys_errors =
  889. cntrs.port_rcv_remphys_errors;
  890. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
  891. dev->z_port_xmit_discards = cntrs.port_xmit_discards;
  892. if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
  893. dev->z_local_link_integrity_errors =
  894. cntrs.local_link_integrity_errors;
  895. if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
  896. dev->z_excessive_buffer_overrun_errors =
  897. cntrs.excessive_buffer_overrun_errors;
  898. if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED)
  899. dev->n_vl15_dropped = 0;
  900. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
  901. dev->z_port_xmit_data = cntrs.port_xmit_data;
  902. if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
  903. dev->z_port_rcv_data = cntrs.port_rcv_data;
  904. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
  905. dev->z_port_xmit_packets = cntrs.port_xmit_packets;
  906. if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
  907. dev->z_port_rcv_packets = cntrs.port_rcv_packets;
  908. return recv_pma_get_portcounters(pmp, ibdev, port);
  909. }
  910. static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
  911. struct ib_device *ibdev, u8 port)
  912. {
  913. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  914. pmp->data;
  915. struct ipath_ibdev *dev = to_idev(ibdev);
  916. u64 swords, rwords, spkts, rpkts, xwait;
  917. ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
  918. &rpkts, &xwait);
  919. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
  920. dev->z_port_xmit_data = swords;
  921. if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
  922. dev->z_port_rcv_data = rwords;
  923. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
  924. dev->z_port_xmit_packets = spkts;
  925. if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
  926. dev->z_port_rcv_packets = rpkts;
  927. if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
  928. dev->n_unicast_xmit = 0;
  929. if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
  930. dev->n_unicast_rcv = 0;
  931. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
  932. dev->n_multicast_xmit = 0;
  933. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
  934. dev->n_multicast_rcv = 0;
  935. return recv_pma_get_portcounters_ext(pmp, ibdev, port);
  936. }
  937. static int process_subn(struct ib_device *ibdev, int mad_flags,
  938. u8 port_num, struct ib_mad *in_mad,
  939. struct ib_mad *out_mad)
  940. {
  941. struct ib_smp *smp = (struct ib_smp *)out_mad;
  942. struct ipath_ibdev *dev = to_idev(ibdev);
  943. int ret;
  944. *out_mad = *in_mad;
  945. if (smp->class_version != 1) {
  946. smp->status |= IB_SMP_UNSUP_VERSION;
  947. ret = reply(smp);
  948. goto bail;
  949. }
  950. /* Is the mkey in the process of expiring? */
  951. if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
  952. /* Clear timeout and mkey protection field. */
  953. dev->mkey_lease_timeout = 0;
  954. dev->mkeyprot_resv_lmc &= 0x3F;
  955. }
  956. /*
  957. * M_Key checking depends on
  958. * Portinfo:M_Key_protect_bits
  959. */
  960. if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
  961. dev->mkey != smp->mkey &&
  962. (smp->method == IB_MGMT_METHOD_SET ||
  963. (smp->method == IB_MGMT_METHOD_GET &&
  964. (dev->mkeyprot_resv_lmc >> 7) != 0))) {
  965. if (dev->mkey_violations != 0xFFFF)
  966. ++dev->mkey_violations;
  967. if (dev->mkey_lease_timeout ||
  968. dev->mkey_lease_period == 0) {
  969. ret = IB_MAD_RESULT_SUCCESS |
  970. IB_MAD_RESULT_CONSUMED;
  971. goto bail;
  972. }
  973. dev->mkey_lease_timeout = jiffies +
  974. dev->mkey_lease_period * HZ;
  975. /* Future: Generate a trap notice. */
  976. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  977. goto bail;
  978. } else if (dev->mkey_lease_timeout)
  979. dev->mkey_lease_timeout = 0;
  980. switch (smp->method) {
  981. case IB_MGMT_METHOD_GET:
  982. switch (smp->attr_id) {
  983. case IB_SMP_ATTR_NODE_DESC:
  984. ret = recv_subn_get_nodedescription(smp, ibdev);
  985. goto bail;
  986. case IB_SMP_ATTR_NODE_INFO:
  987. ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
  988. goto bail;
  989. case IB_SMP_ATTR_GUID_INFO:
  990. ret = recv_subn_get_guidinfo(smp, ibdev);
  991. goto bail;
  992. case IB_SMP_ATTR_PORT_INFO:
  993. ret = recv_subn_get_portinfo(smp, ibdev, port_num);
  994. goto bail;
  995. case IB_SMP_ATTR_PKEY_TABLE:
  996. ret = recv_subn_get_pkeytable(smp, ibdev);
  997. goto bail;
  998. case IB_SMP_ATTR_SM_INFO:
  999. if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
  1000. ret = IB_MAD_RESULT_SUCCESS |
  1001. IB_MAD_RESULT_CONSUMED;
  1002. goto bail;
  1003. }
  1004. if (dev->port_cap_flags & IB_PORT_SM) {
  1005. ret = IB_MAD_RESULT_SUCCESS;
  1006. goto bail;
  1007. }
  1008. /* FALLTHROUGH */
  1009. default:
  1010. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1011. ret = reply(smp);
  1012. goto bail;
  1013. }
  1014. case IB_MGMT_METHOD_SET:
  1015. switch (smp->attr_id) {
  1016. case IB_SMP_ATTR_GUID_INFO:
  1017. ret = recv_subn_set_guidinfo(smp, ibdev);
  1018. goto bail;
  1019. case IB_SMP_ATTR_PORT_INFO:
  1020. ret = recv_subn_set_portinfo(smp, ibdev, port_num);
  1021. goto bail;
  1022. case IB_SMP_ATTR_PKEY_TABLE:
  1023. ret = recv_subn_set_pkeytable(smp, ibdev);
  1024. goto bail;
  1025. case IB_SMP_ATTR_SM_INFO:
  1026. if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
  1027. ret = IB_MAD_RESULT_SUCCESS |
  1028. IB_MAD_RESULT_CONSUMED;
  1029. goto bail;
  1030. }
  1031. if (dev->port_cap_flags & IB_PORT_SM) {
  1032. ret = IB_MAD_RESULT_SUCCESS;
  1033. goto bail;
  1034. }
  1035. /* FALLTHROUGH */
  1036. default:
  1037. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1038. ret = reply(smp);
  1039. goto bail;
  1040. }
  1041. case IB_MGMT_METHOD_GET_RESP:
  1042. /*
  1043. * The ib_mad module will call us to process responses
  1044. * before checking for other consumers.
  1045. * Just tell the caller to process it normally.
  1046. */
  1047. ret = IB_MAD_RESULT_FAILURE;
  1048. goto bail;
  1049. default:
  1050. smp->status |= IB_SMP_UNSUP_METHOD;
  1051. ret = reply(smp);
  1052. }
  1053. bail:
  1054. return ret;
  1055. }
  1056. static int process_perf(struct ib_device *ibdev, u8 port_num,
  1057. struct ib_mad *in_mad,
  1058. struct ib_mad *out_mad)
  1059. {
  1060. struct ib_perf *pmp = (struct ib_perf *)out_mad;
  1061. int ret;
  1062. *out_mad = *in_mad;
  1063. if (pmp->class_version != 1) {
  1064. pmp->status |= IB_SMP_UNSUP_VERSION;
  1065. ret = reply((struct ib_smp *) pmp);
  1066. goto bail;
  1067. }
  1068. switch (pmp->method) {
  1069. case IB_MGMT_METHOD_GET:
  1070. switch (pmp->attr_id) {
  1071. case IB_PMA_CLASS_PORT_INFO:
  1072. ret = recv_pma_get_classportinfo(pmp);
  1073. goto bail;
  1074. case IB_PMA_PORT_SAMPLES_CONTROL:
  1075. ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
  1076. port_num);
  1077. goto bail;
  1078. case IB_PMA_PORT_SAMPLES_RESULT:
  1079. ret = recv_pma_get_portsamplesresult(pmp, ibdev);
  1080. goto bail;
  1081. case IB_PMA_PORT_SAMPLES_RESULT_EXT:
  1082. ret = recv_pma_get_portsamplesresult_ext(pmp,
  1083. ibdev);
  1084. goto bail;
  1085. case IB_PMA_PORT_COUNTERS:
  1086. ret = recv_pma_get_portcounters(pmp, ibdev,
  1087. port_num);
  1088. goto bail;
  1089. case IB_PMA_PORT_COUNTERS_EXT:
  1090. ret = recv_pma_get_portcounters_ext(pmp, ibdev,
  1091. port_num);
  1092. goto bail;
  1093. default:
  1094. pmp->status |= IB_SMP_UNSUP_METH_ATTR;
  1095. ret = reply((struct ib_smp *) pmp);
  1096. goto bail;
  1097. }
  1098. case IB_MGMT_METHOD_SET:
  1099. switch (pmp->attr_id) {
  1100. case IB_PMA_PORT_SAMPLES_CONTROL:
  1101. ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
  1102. port_num);
  1103. goto bail;
  1104. case IB_PMA_PORT_COUNTERS:
  1105. ret = recv_pma_set_portcounters(pmp, ibdev,
  1106. port_num);
  1107. goto bail;
  1108. case IB_PMA_PORT_COUNTERS_EXT:
  1109. ret = recv_pma_set_portcounters_ext(pmp, ibdev,
  1110. port_num);
  1111. goto bail;
  1112. default:
  1113. pmp->status |= IB_SMP_UNSUP_METH_ATTR;
  1114. ret = reply((struct ib_smp *) pmp);
  1115. goto bail;
  1116. }
  1117. case IB_MGMT_METHOD_GET_RESP:
  1118. /*
  1119. * The ib_mad module will call us to process responses
  1120. * before checking for other consumers.
  1121. * Just tell the caller to process it normally.
  1122. */
  1123. ret = IB_MAD_RESULT_FAILURE;
  1124. goto bail;
  1125. default:
  1126. pmp->status |= IB_SMP_UNSUP_METHOD;
  1127. ret = reply((struct ib_smp *) pmp);
  1128. }
  1129. bail:
  1130. return ret;
  1131. }
  1132. /**
  1133. * ipath_process_mad - process an incoming MAD packet
  1134. * @ibdev: the infiniband device this packet came in on
  1135. * @mad_flags: MAD flags
  1136. * @port_num: the port number this packet came in on
  1137. * @in_wc: the work completion entry for this packet
  1138. * @in_grh: the global route header for this packet
  1139. * @in_mad: the incoming MAD
  1140. * @out_mad: any outgoing MAD reply
  1141. *
  1142. * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
  1143. * interested in processing.
  1144. *
  1145. * Note that the verbs framework has already done the MAD sanity checks,
  1146. * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  1147. * MADs.
  1148. *
  1149. * This is called by the ib_mad module.
  1150. */
  1151. int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  1152. struct ib_wc *in_wc, struct ib_grh *in_grh,
  1153. struct ib_mad *in_mad, struct ib_mad *out_mad)
  1154. {
  1155. int ret;
  1156. switch (in_mad->mad_hdr.mgmt_class) {
  1157. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  1158. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  1159. ret = process_subn(ibdev, mad_flags, port_num,
  1160. in_mad, out_mad);
  1161. goto bail;
  1162. case IB_MGMT_CLASS_PERF_MGMT:
  1163. ret = process_perf(ibdev, port_num, in_mad, out_mad);
  1164. goto bail;
  1165. default:
  1166. ret = IB_MAD_RESULT_SUCCESS;
  1167. }
  1168. bail:
  1169. return ret;
  1170. }