ipath_mad.c 44 KB

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