ipath_mad.c 38 KB

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