ipath_mad.c 42 KB

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