ipath_mad.c 37 KB

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