ipath_mad.c 46 KB

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