ipath_mad.c 44 KB

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