ipath_mad.c 37 KB

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