qib_mad.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499
  1. /*
  2. * Copyright (c) 2012 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
  4. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <rdma/ib_smi.h>
  35. #include "qib.h"
  36. #include "qib_mad.h"
  37. static int reply(struct ib_smp *smp)
  38. {
  39. /*
  40. * The verbs framework will handle the directed/LID route
  41. * packet changes.
  42. */
  43. smp->method = IB_MGMT_METHOD_GET_RESP;
  44. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  45. smp->status |= IB_SMP_DIRECTION;
  46. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  47. }
  48. static int reply_failure(struct ib_smp *smp)
  49. {
  50. /*
  51. * The verbs framework will handle the directed/LID route
  52. * packet changes.
  53. */
  54. smp->method = IB_MGMT_METHOD_GET_RESP;
  55. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  56. smp->status |= IB_SMP_DIRECTION;
  57. return IB_MAD_RESULT_FAILURE | IB_MAD_RESULT_REPLY;
  58. }
  59. static void qib_send_trap(struct qib_ibport *ibp, void *data, unsigned len)
  60. {
  61. struct ib_mad_send_buf *send_buf;
  62. struct ib_mad_agent *agent;
  63. struct ib_smp *smp;
  64. int ret;
  65. unsigned long flags;
  66. unsigned long timeout;
  67. agent = ibp->rvp.send_agent;
  68. if (!agent)
  69. return;
  70. /* o14-3.2.1 */
  71. if (!(ppd_from_ibp(ibp)->lflags & QIBL_LINKACTIVE))
  72. return;
  73. /* o14-2 */
  74. if (ibp->rvp.trap_timeout &&
  75. time_before(jiffies, ibp->rvp.trap_timeout))
  76. return;
  77. send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
  78. IB_MGMT_MAD_DATA, GFP_ATOMIC,
  79. IB_MGMT_BASE_VERSION);
  80. if (IS_ERR(send_buf))
  81. return;
  82. smp = send_buf->mad;
  83. smp->base_version = IB_MGMT_BASE_VERSION;
  84. smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  85. smp->class_version = 1;
  86. smp->method = IB_MGMT_METHOD_TRAP;
  87. ibp->rvp.tid++;
  88. smp->tid = cpu_to_be64(ibp->rvp.tid);
  89. smp->attr_id = IB_SMP_ATTR_NOTICE;
  90. /* o14-1: smp->mkey = 0; */
  91. memcpy(smp->data, data, len);
  92. spin_lock_irqsave(&ibp->rvp.lock, flags);
  93. if (!ibp->rvp.sm_ah) {
  94. if (ibp->rvp.sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
  95. struct ib_ah *ah;
  96. ah = qib_create_qp0_ah(ibp, (u16)ibp->rvp.sm_lid);
  97. if (IS_ERR(ah))
  98. ret = PTR_ERR(ah);
  99. else {
  100. send_buf->ah = ah;
  101. ibp->rvp.sm_ah = ibah_to_rvtah(ah);
  102. ret = 0;
  103. }
  104. } else
  105. ret = -EINVAL;
  106. } else {
  107. send_buf->ah = &ibp->rvp.sm_ah->ibah;
  108. ret = 0;
  109. }
  110. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  111. if (!ret)
  112. ret = ib_post_send_mad(send_buf, NULL);
  113. if (!ret) {
  114. /* 4.096 usec. */
  115. timeout = (4096 * (1UL << ibp->rvp.subnet_timeout)) / 1000;
  116. ibp->rvp.trap_timeout = jiffies + usecs_to_jiffies(timeout);
  117. } else {
  118. ib_free_send_mad(send_buf);
  119. ibp->rvp.trap_timeout = 0;
  120. }
  121. }
  122. /*
  123. * Send a bad P_Key trap (ch. 14.3.8).
  124. */
  125. void qib_bad_pkey(struct qib_ibport *ibp, u32 key, u32 sl,
  126. u32 qp1, u32 qp2, __be16 lid1, __be16 lid2)
  127. {
  128. struct ib_mad_notice_attr data;
  129. ibp->rvp.n_pkt_drops++;
  130. ibp->rvp.pkey_violations++;
  131. /* Send violation trap */
  132. data.generic_type = IB_NOTICE_TYPE_SECURITY;
  133. data.prod_type_msb = 0;
  134. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  135. data.trap_num = IB_NOTICE_TRAP_BAD_PKEY;
  136. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  137. data.toggle_count = 0;
  138. memset(&data.details, 0, sizeof(data.details));
  139. data.details.ntc_257_258.lid1 = lid1;
  140. data.details.ntc_257_258.lid2 = lid2;
  141. data.details.ntc_257_258.key = cpu_to_be32(key);
  142. data.details.ntc_257_258.sl_qp1 = cpu_to_be32((sl << 28) | qp1);
  143. data.details.ntc_257_258.qp2 = cpu_to_be32(qp2);
  144. qib_send_trap(ibp, &data, sizeof(data));
  145. }
  146. /*
  147. * Send a bad M_Key trap (ch. 14.3.9).
  148. */
  149. static void qib_bad_mkey(struct qib_ibport *ibp, struct ib_smp *smp)
  150. {
  151. struct ib_mad_notice_attr data;
  152. /* Send violation trap */
  153. data.generic_type = IB_NOTICE_TYPE_SECURITY;
  154. data.prod_type_msb = 0;
  155. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  156. data.trap_num = IB_NOTICE_TRAP_BAD_MKEY;
  157. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  158. data.toggle_count = 0;
  159. memset(&data.details, 0, sizeof(data.details));
  160. data.details.ntc_256.lid = data.issuer_lid;
  161. data.details.ntc_256.method = smp->method;
  162. data.details.ntc_256.attr_id = smp->attr_id;
  163. data.details.ntc_256.attr_mod = smp->attr_mod;
  164. data.details.ntc_256.mkey = smp->mkey;
  165. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
  166. u8 hop_cnt;
  167. data.details.ntc_256.dr_slid = smp->dr_slid;
  168. data.details.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE;
  169. hop_cnt = smp->hop_cnt;
  170. if (hop_cnt > ARRAY_SIZE(data.details.ntc_256.dr_rtn_path)) {
  171. data.details.ntc_256.dr_trunc_hop |=
  172. IB_NOTICE_TRAP_DR_TRUNC;
  173. hop_cnt = ARRAY_SIZE(data.details.ntc_256.dr_rtn_path);
  174. }
  175. data.details.ntc_256.dr_trunc_hop |= hop_cnt;
  176. memcpy(data.details.ntc_256.dr_rtn_path, smp->return_path,
  177. hop_cnt);
  178. }
  179. qib_send_trap(ibp, &data, sizeof(data));
  180. }
  181. /*
  182. * Send a Port Capability Mask Changed trap (ch. 14.3.11).
  183. */
  184. void qib_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num)
  185. {
  186. struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
  187. struct qib_devdata *dd = dd_from_dev(ibdev);
  188. struct qib_ibport *ibp = &dd->pport[port_num - 1].ibport_data;
  189. struct ib_mad_notice_attr data;
  190. data.generic_type = IB_NOTICE_TYPE_INFO;
  191. data.prod_type_msb = 0;
  192. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  193. data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG;
  194. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  195. data.toggle_count = 0;
  196. memset(&data.details, 0, sizeof(data.details));
  197. data.details.ntc_144.lid = data.issuer_lid;
  198. data.details.ntc_144.new_cap_mask =
  199. cpu_to_be32(ibp->rvp.port_cap_flags);
  200. qib_send_trap(ibp, &data, sizeof(data));
  201. }
  202. /*
  203. * Send a System Image GUID Changed trap (ch. 14.3.12).
  204. */
  205. void qib_sys_guid_chg(struct qib_ibport *ibp)
  206. {
  207. struct ib_mad_notice_attr data;
  208. data.generic_type = IB_NOTICE_TYPE_INFO;
  209. data.prod_type_msb = 0;
  210. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  211. data.trap_num = IB_NOTICE_TRAP_SYS_GUID_CHG;
  212. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  213. data.toggle_count = 0;
  214. memset(&data.details, 0, sizeof(data.details));
  215. data.details.ntc_145.lid = data.issuer_lid;
  216. data.details.ntc_145.new_sys_guid = ib_qib_sys_image_guid;
  217. qib_send_trap(ibp, &data, sizeof(data));
  218. }
  219. /*
  220. * Send a Node Description Changed trap (ch. 14.3.13).
  221. */
  222. void qib_node_desc_chg(struct qib_ibport *ibp)
  223. {
  224. struct ib_mad_notice_attr data;
  225. data.generic_type = IB_NOTICE_TYPE_INFO;
  226. data.prod_type_msb = 0;
  227. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  228. data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG;
  229. data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
  230. data.toggle_count = 0;
  231. memset(&data.details, 0, sizeof(data.details));
  232. data.details.ntc_144.lid = data.issuer_lid;
  233. data.details.ntc_144.local_changes = 1;
  234. data.details.ntc_144.change_flags = IB_NOTICE_TRAP_NODE_DESC_CHG;
  235. qib_send_trap(ibp, &data, sizeof(data));
  236. }
  237. static int subn_get_nodedescription(struct ib_smp *smp,
  238. struct ib_device *ibdev)
  239. {
  240. if (smp->attr_mod)
  241. smp->status |= IB_SMP_INVALID_FIELD;
  242. memcpy(smp->data, ibdev->node_desc, sizeof(smp->data));
  243. return reply(smp);
  244. }
  245. static int subn_get_nodeinfo(struct ib_smp *smp, struct ib_device *ibdev,
  246. u8 port)
  247. {
  248. struct ib_node_info *nip = (struct ib_node_info *)&smp->data;
  249. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  250. u32 majrev, minrev;
  251. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  252. /* GUID 0 is illegal */
  253. if (smp->attr_mod || pidx >= dd->num_pports ||
  254. dd->pport[pidx].guid == 0)
  255. smp->status |= IB_SMP_INVALID_FIELD;
  256. else
  257. nip->port_guid = dd->pport[pidx].guid;
  258. nip->base_version = 1;
  259. nip->class_version = 1;
  260. nip->node_type = 1; /* channel adapter */
  261. nip->num_ports = ibdev->phys_port_cnt;
  262. /* This is already in network order */
  263. nip->sys_guid = ib_qib_sys_image_guid;
  264. nip->node_guid = dd->pport->guid; /* Use first-port GUID as node */
  265. nip->partition_cap = cpu_to_be16(qib_get_npkeys(dd));
  266. nip->device_id = cpu_to_be16(dd->deviceid);
  267. majrev = dd->majrev;
  268. minrev = dd->minrev;
  269. nip->revision = cpu_to_be32((majrev << 16) | minrev);
  270. nip->local_port_num = port;
  271. nip->vendor_id[0] = QIB_SRC_OUI_1;
  272. nip->vendor_id[1] = QIB_SRC_OUI_2;
  273. nip->vendor_id[2] = QIB_SRC_OUI_3;
  274. return reply(smp);
  275. }
  276. static int subn_get_guidinfo(struct ib_smp *smp, struct ib_device *ibdev,
  277. u8 port)
  278. {
  279. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  280. u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
  281. __be64 *p = (__be64 *) smp->data;
  282. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  283. /* 32 blocks of 8 64-bit GUIDs per block */
  284. memset(smp->data, 0, sizeof(smp->data));
  285. if (startgx == 0 && pidx < dd->num_pports) {
  286. struct qib_pportdata *ppd = dd->pport + pidx;
  287. struct qib_ibport *ibp = &ppd->ibport_data;
  288. __be64 g = ppd->guid;
  289. unsigned i;
  290. /* GUID 0 is illegal */
  291. if (g == 0)
  292. smp->status |= IB_SMP_INVALID_FIELD;
  293. else {
  294. /* The first is a copy of the read-only HW GUID. */
  295. p[0] = g;
  296. for (i = 1; i < QIB_GUIDS_PER_PORT; i++)
  297. p[i] = ibp->guids[i - 1];
  298. }
  299. } else
  300. smp->status |= IB_SMP_INVALID_FIELD;
  301. return reply(smp);
  302. }
  303. static void set_link_width_enabled(struct qib_pportdata *ppd, u32 w)
  304. {
  305. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LWID_ENB, w);
  306. }
  307. static void set_link_speed_enabled(struct qib_pportdata *ppd, u32 s)
  308. {
  309. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_SPD_ENB, s);
  310. }
  311. static int get_overrunthreshold(struct qib_pportdata *ppd)
  312. {
  313. return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH);
  314. }
  315. /**
  316. * set_overrunthreshold - set the overrun threshold
  317. * @ppd: the physical port data
  318. * @n: the new threshold
  319. *
  320. * Note that this will only take effect when the link state changes.
  321. */
  322. static int set_overrunthreshold(struct qib_pportdata *ppd, unsigned n)
  323. {
  324. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH,
  325. (u32)n);
  326. return 0;
  327. }
  328. static int get_phyerrthreshold(struct qib_pportdata *ppd)
  329. {
  330. return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH);
  331. }
  332. /**
  333. * set_phyerrthreshold - set the physical error threshold
  334. * @ppd: the physical port data
  335. * @n: the new threshold
  336. *
  337. * Note that this will only take effect when the link state changes.
  338. */
  339. static int set_phyerrthreshold(struct qib_pportdata *ppd, unsigned n)
  340. {
  341. (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH,
  342. (u32)n);
  343. return 0;
  344. }
  345. /**
  346. * get_linkdowndefaultstate - get the default linkdown state
  347. * @ppd: the physical port data
  348. *
  349. * Returns zero if the default is POLL, 1 if the default is SLEEP.
  350. */
  351. static int get_linkdowndefaultstate(struct qib_pportdata *ppd)
  352. {
  353. return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT) ==
  354. IB_LINKINITCMD_SLEEP;
  355. }
  356. static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags)
  357. {
  358. int valid_mkey = 0;
  359. int ret = 0;
  360. /* Is the mkey in the process of expiring? */
  361. if (ibp->rvp.mkey_lease_timeout &&
  362. time_after_eq(jiffies, ibp->rvp.mkey_lease_timeout)) {
  363. /* Clear timeout and mkey protection field. */
  364. ibp->rvp.mkey_lease_timeout = 0;
  365. ibp->rvp.mkeyprot = 0;
  366. }
  367. if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->rvp.mkey == 0 ||
  368. ibp->rvp.mkey == smp->mkey)
  369. valid_mkey = 1;
  370. /* Unset lease timeout on any valid Get/Set/TrapRepress */
  371. if (valid_mkey && ibp->rvp.mkey_lease_timeout &&
  372. (smp->method == IB_MGMT_METHOD_GET ||
  373. smp->method == IB_MGMT_METHOD_SET ||
  374. smp->method == IB_MGMT_METHOD_TRAP_REPRESS))
  375. ibp->rvp.mkey_lease_timeout = 0;
  376. if (!valid_mkey) {
  377. switch (smp->method) {
  378. case IB_MGMT_METHOD_GET:
  379. /* Bad mkey not a violation below level 2 */
  380. if (ibp->rvp.mkeyprot < 2)
  381. break;
  382. /* fall through */
  383. case IB_MGMT_METHOD_SET:
  384. case IB_MGMT_METHOD_TRAP_REPRESS:
  385. if (ibp->rvp.mkey_violations != 0xFFFF)
  386. ++ibp->rvp.mkey_violations;
  387. if (!ibp->rvp.mkey_lease_timeout &&
  388. ibp->rvp.mkey_lease_period)
  389. ibp->rvp.mkey_lease_timeout = jiffies +
  390. ibp->rvp.mkey_lease_period * HZ;
  391. /* Generate a trap notice. */
  392. qib_bad_mkey(ibp, smp);
  393. ret = 1;
  394. }
  395. }
  396. return ret;
  397. }
  398. static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
  399. u8 port)
  400. {
  401. struct qib_devdata *dd;
  402. struct qib_pportdata *ppd;
  403. struct qib_ibport *ibp;
  404. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  405. u8 mtu;
  406. int ret;
  407. u32 state;
  408. u32 port_num = be32_to_cpu(smp->attr_mod);
  409. if (port_num == 0)
  410. port_num = port;
  411. else {
  412. if (port_num > ibdev->phys_port_cnt) {
  413. smp->status |= IB_SMP_INVALID_FIELD;
  414. ret = reply(smp);
  415. goto bail;
  416. }
  417. if (port_num != port) {
  418. ibp = to_iport(ibdev, port_num);
  419. ret = check_mkey(ibp, smp, 0);
  420. if (ret) {
  421. ret = IB_MAD_RESULT_FAILURE;
  422. goto bail;
  423. }
  424. }
  425. }
  426. dd = dd_from_ibdev(ibdev);
  427. /* IB numbers ports from 1, hdw from 0 */
  428. ppd = dd->pport + (port_num - 1);
  429. ibp = &ppd->ibport_data;
  430. /* Clear all fields. Only set the non-zero fields. */
  431. memset(smp->data, 0, sizeof(smp->data));
  432. /* Only return the mkey if the protection field allows it. */
  433. if (!(smp->method == IB_MGMT_METHOD_GET &&
  434. ibp->rvp.mkey != smp->mkey &&
  435. ibp->rvp.mkeyprot == 1))
  436. pip->mkey = ibp->rvp.mkey;
  437. pip->gid_prefix = ibp->rvp.gid_prefix;
  438. pip->lid = cpu_to_be16(ppd->lid);
  439. pip->sm_lid = cpu_to_be16((u16)ibp->rvp.sm_lid);
  440. pip->cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
  441. /* pip->diag_code; */
  442. pip->mkey_lease_period = cpu_to_be16(ibp->rvp.mkey_lease_period);
  443. pip->local_port_num = port;
  444. pip->link_width_enabled = ppd->link_width_enabled;
  445. pip->link_width_supported = ppd->link_width_supported;
  446. pip->link_width_active = ppd->link_width_active;
  447. state = dd->f_iblink_state(ppd->lastibcstat);
  448. pip->linkspeed_portstate = ppd->link_speed_supported << 4 | state;
  449. pip->portphysstate_linkdown =
  450. (dd->f_ibphys_portstate(ppd->lastibcstat) << 4) |
  451. (get_linkdowndefaultstate(ppd) ? 1 : 2);
  452. pip->mkeyprot_resv_lmc = (ibp->rvp.mkeyprot << 6) | ppd->lmc;
  453. pip->linkspeedactive_enabled = (ppd->link_speed_active << 4) |
  454. ppd->link_speed_enabled;
  455. switch (ppd->ibmtu) {
  456. default: /* something is wrong; fall through */
  457. case 4096:
  458. mtu = IB_MTU_4096;
  459. break;
  460. case 2048:
  461. mtu = IB_MTU_2048;
  462. break;
  463. case 1024:
  464. mtu = IB_MTU_1024;
  465. break;
  466. case 512:
  467. mtu = IB_MTU_512;
  468. break;
  469. case 256:
  470. mtu = IB_MTU_256;
  471. break;
  472. }
  473. pip->neighbormtu_mastersmsl = (mtu << 4) | ibp->rvp.sm_sl;
  474. pip->vlcap_inittype = ppd->vls_supported << 4; /* InitType = 0 */
  475. pip->vl_high_limit = ibp->rvp.vl_high_limit;
  476. pip->vl_arb_high_cap =
  477. dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_CAP);
  478. pip->vl_arb_low_cap =
  479. dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_LOW_CAP);
  480. /* InitTypeReply = 0 */
  481. pip->inittypereply_mtucap = qib_ibmtu ? qib_ibmtu : IB_MTU_4096;
  482. /* HCAs ignore VLStallCount and HOQLife */
  483. /* pip->vlstallcnt_hoqlife; */
  484. pip->operationalvl_pei_peo_fpi_fpo =
  485. dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OP_VLS) << 4;
  486. pip->mkey_violations = cpu_to_be16(ibp->rvp.mkey_violations);
  487. /* P_KeyViolations are counted by hardware. */
  488. pip->pkey_violations = cpu_to_be16(ibp->rvp.pkey_violations);
  489. pip->qkey_violations = cpu_to_be16(ibp->rvp.qkey_violations);
  490. /* Only the hardware GUID is supported for now */
  491. pip->guid_cap = QIB_GUIDS_PER_PORT;
  492. pip->clientrereg_resv_subnetto = ibp->rvp.subnet_timeout;
  493. /* 32.768 usec. response time (guessing) */
  494. pip->resv_resptimevalue = 3;
  495. pip->localphyerrors_overrunerrors =
  496. (get_phyerrthreshold(ppd) << 4) |
  497. get_overrunthreshold(ppd);
  498. /* pip->max_credit_hint; */
  499. if (ibp->rvp.port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
  500. u32 v;
  501. v = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKLATENCY);
  502. pip->link_roundtrip_latency[0] = v >> 16;
  503. pip->link_roundtrip_latency[1] = v >> 8;
  504. pip->link_roundtrip_latency[2] = v;
  505. }
  506. ret = reply(smp);
  507. bail:
  508. return ret;
  509. }
  510. /**
  511. * get_pkeys - return the PKEY table
  512. * @dd: the qlogic_ib device
  513. * @port: the IB port number
  514. * @pkeys: the pkey table is placed here
  515. */
  516. static int get_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys)
  517. {
  518. struct qib_pportdata *ppd = dd->pport + port - 1;
  519. /*
  520. * always a kernel context, no locking needed.
  521. * If we get here with ppd setup, no need to check
  522. * that pd is valid.
  523. */
  524. struct qib_ctxtdata *rcd = dd->rcd[ppd->hw_pidx];
  525. memcpy(pkeys, rcd->pkeys, sizeof(rcd->pkeys));
  526. return 0;
  527. }
  528. static int subn_get_pkeytable(struct ib_smp *smp, struct ib_device *ibdev,
  529. u8 port)
  530. {
  531. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  532. u16 *p = (u16 *) smp->data;
  533. __be16 *q = (__be16 *) smp->data;
  534. /* 64 blocks of 32 16-bit P_Key entries */
  535. memset(smp->data, 0, sizeof(smp->data));
  536. if (startpx == 0) {
  537. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  538. unsigned i, n = qib_get_npkeys(dd);
  539. get_pkeys(dd, port, p);
  540. for (i = 0; i < n; i++)
  541. q[i] = cpu_to_be16(p[i]);
  542. } else
  543. smp->status |= IB_SMP_INVALID_FIELD;
  544. return reply(smp);
  545. }
  546. static int subn_set_guidinfo(struct ib_smp *smp, struct ib_device *ibdev,
  547. u8 port)
  548. {
  549. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  550. u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
  551. __be64 *p = (__be64 *) smp->data;
  552. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  553. /* 32 blocks of 8 64-bit GUIDs per block */
  554. if (startgx == 0 && pidx < dd->num_pports) {
  555. struct qib_pportdata *ppd = dd->pport + pidx;
  556. struct qib_ibport *ibp = &ppd->ibport_data;
  557. unsigned i;
  558. /* The first entry is read-only. */
  559. for (i = 1; i < QIB_GUIDS_PER_PORT; i++)
  560. ibp->guids[i - 1] = p[i];
  561. } else
  562. smp->status |= IB_SMP_INVALID_FIELD;
  563. /* The only GUID we support is the first read-only entry. */
  564. return subn_get_guidinfo(smp, ibdev, port);
  565. }
  566. /**
  567. * subn_set_portinfo - set port information
  568. * @smp: the incoming SM packet
  569. * @ibdev: the infiniband device
  570. * @port: the port on the device
  571. *
  572. * Set Portinfo (see ch. 14.2.5.6).
  573. */
  574. static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
  575. u8 port)
  576. {
  577. struct ib_port_info *pip = (struct ib_port_info *)smp->data;
  578. struct ib_event event;
  579. struct qib_devdata *dd;
  580. struct qib_pportdata *ppd;
  581. struct qib_ibport *ibp;
  582. u8 clientrereg = (pip->clientrereg_resv_subnetto & 0x80);
  583. unsigned long flags;
  584. u16 lid, smlid;
  585. u8 lwe;
  586. u8 lse;
  587. u8 state;
  588. u8 vls;
  589. u8 msl;
  590. u16 lstate;
  591. int ret, ore, mtu;
  592. u32 port_num = be32_to_cpu(smp->attr_mod);
  593. if (port_num == 0)
  594. port_num = port;
  595. else {
  596. if (port_num > ibdev->phys_port_cnt)
  597. goto err;
  598. /* Port attributes can only be set on the receiving port */
  599. if (port_num != port)
  600. goto get_only;
  601. }
  602. dd = dd_from_ibdev(ibdev);
  603. /* IB numbers ports from 1, hdw from 0 */
  604. ppd = dd->pport + (port_num - 1);
  605. ibp = &ppd->ibport_data;
  606. event.device = ibdev;
  607. event.element.port_num = port;
  608. ibp->rvp.mkey = pip->mkey;
  609. ibp->rvp.gid_prefix = pip->gid_prefix;
  610. ibp->rvp.mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
  611. lid = be16_to_cpu(pip->lid);
  612. /* Must be a valid unicast LID address. */
  613. if (lid == 0 || lid >= be16_to_cpu(IB_MULTICAST_LID_BASE))
  614. smp->status |= IB_SMP_INVALID_FIELD;
  615. else if (ppd->lid != lid || ppd->lmc != (pip->mkeyprot_resv_lmc & 7)) {
  616. if (ppd->lid != lid)
  617. qib_set_uevent_bits(ppd, _QIB_EVENT_LID_CHANGE_BIT);
  618. if (ppd->lmc != (pip->mkeyprot_resv_lmc & 7))
  619. qib_set_uevent_bits(ppd, _QIB_EVENT_LMC_CHANGE_BIT);
  620. qib_set_lid(ppd, lid, pip->mkeyprot_resv_lmc & 7);
  621. event.event = IB_EVENT_LID_CHANGE;
  622. ib_dispatch_event(&event);
  623. }
  624. smlid = be16_to_cpu(pip->sm_lid);
  625. msl = pip->neighbormtu_mastersmsl & 0xF;
  626. /* Must be a valid unicast LID address. */
  627. if (smlid == 0 || smlid >= be16_to_cpu(IB_MULTICAST_LID_BASE))
  628. smp->status |= IB_SMP_INVALID_FIELD;
  629. else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) {
  630. spin_lock_irqsave(&ibp->rvp.lock, flags);
  631. if (ibp->rvp.sm_ah) {
  632. if (smlid != ibp->rvp.sm_lid)
  633. rdma_ah_set_dlid(&ibp->rvp.sm_ah->attr,
  634. smlid);
  635. if (msl != ibp->rvp.sm_sl)
  636. rdma_ah_set_sl(&ibp->rvp.sm_ah->attr, msl);
  637. }
  638. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  639. if (smlid != ibp->rvp.sm_lid)
  640. ibp->rvp.sm_lid = smlid;
  641. if (msl != ibp->rvp.sm_sl)
  642. ibp->rvp.sm_sl = msl;
  643. event.event = IB_EVENT_SM_CHANGE;
  644. ib_dispatch_event(&event);
  645. }
  646. /* Allow 1x or 4x to be set (see 14.2.6.6). */
  647. lwe = pip->link_width_enabled;
  648. if (lwe) {
  649. if (lwe == 0xFF)
  650. set_link_width_enabled(ppd, ppd->link_width_supported);
  651. else if (lwe >= 16 || (lwe & ~ppd->link_width_supported))
  652. smp->status |= IB_SMP_INVALID_FIELD;
  653. else if (lwe != ppd->link_width_enabled)
  654. set_link_width_enabled(ppd, lwe);
  655. }
  656. lse = pip->linkspeedactive_enabled & 0xF;
  657. if (lse) {
  658. /*
  659. * The IB 1.2 spec. only allows link speed values
  660. * 1, 3, 5, 7, 15. 1.2.1 extended to allow specific
  661. * speeds.
  662. */
  663. if (lse == 15)
  664. set_link_speed_enabled(ppd,
  665. ppd->link_speed_supported);
  666. else if (lse >= 8 || (lse & ~ppd->link_speed_supported))
  667. smp->status |= IB_SMP_INVALID_FIELD;
  668. else if (lse != ppd->link_speed_enabled)
  669. set_link_speed_enabled(ppd, lse);
  670. }
  671. /* Set link down default state. */
  672. switch (pip->portphysstate_linkdown & 0xF) {
  673. case 0: /* NOP */
  674. break;
  675. case 1: /* SLEEP */
  676. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT,
  677. IB_LINKINITCMD_SLEEP);
  678. break;
  679. case 2: /* POLL */
  680. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT,
  681. IB_LINKINITCMD_POLL);
  682. break;
  683. default:
  684. smp->status |= IB_SMP_INVALID_FIELD;
  685. }
  686. ibp->rvp.mkeyprot = pip->mkeyprot_resv_lmc >> 6;
  687. ibp->rvp.vl_high_limit = pip->vl_high_limit;
  688. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_LIMIT,
  689. ibp->rvp.vl_high_limit);
  690. mtu = ib_mtu_enum_to_int((pip->neighbormtu_mastersmsl >> 4) & 0xF);
  691. if (mtu == -1)
  692. smp->status |= IB_SMP_INVALID_FIELD;
  693. else
  694. qib_set_mtu(ppd, mtu);
  695. /* Set operational VLs */
  696. vls = (pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF;
  697. if (vls) {
  698. if (vls > ppd->vls_supported)
  699. smp->status |= IB_SMP_INVALID_FIELD;
  700. else
  701. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OP_VLS, vls);
  702. }
  703. if (pip->mkey_violations == 0)
  704. ibp->rvp.mkey_violations = 0;
  705. if (pip->pkey_violations == 0)
  706. ibp->rvp.pkey_violations = 0;
  707. if (pip->qkey_violations == 0)
  708. ibp->rvp.qkey_violations = 0;
  709. ore = pip->localphyerrors_overrunerrors;
  710. if (set_phyerrthreshold(ppd, (ore >> 4) & 0xF))
  711. smp->status |= IB_SMP_INVALID_FIELD;
  712. if (set_overrunthreshold(ppd, (ore & 0xF)))
  713. smp->status |= IB_SMP_INVALID_FIELD;
  714. ibp->rvp.subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
  715. /*
  716. * Do the port state change now that the other link parameters
  717. * have been set.
  718. * Changing the port physical state only makes sense if the link
  719. * is down or is being set to down.
  720. */
  721. state = pip->linkspeed_portstate & 0xF;
  722. lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
  723. if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
  724. smp->status |= IB_SMP_INVALID_FIELD;
  725. /*
  726. * Only state changes of DOWN, ARM, and ACTIVE are valid
  727. * and must be in the correct state to take effect (see 7.2.6).
  728. */
  729. switch (state) {
  730. case IB_PORT_NOP:
  731. if (lstate == 0)
  732. break;
  733. /* FALLTHROUGH */
  734. case IB_PORT_DOWN:
  735. if (lstate == 0)
  736. lstate = QIB_IB_LINKDOWN_ONLY;
  737. else if (lstate == 1)
  738. lstate = QIB_IB_LINKDOWN_SLEEP;
  739. else if (lstate == 2)
  740. lstate = QIB_IB_LINKDOWN;
  741. else if (lstate == 3)
  742. lstate = QIB_IB_LINKDOWN_DISABLE;
  743. else {
  744. smp->status |= IB_SMP_INVALID_FIELD;
  745. break;
  746. }
  747. spin_lock_irqsave(&ppd->lflags_lock, flags);
  748. ppd->lflags &= ~QIBL_LINKV;
  749. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  750. qib_set_linkstate(ppd, lstate);
  751. /*
  752. * Don't send a reply if the response would be sent
  753. * through the disabled port.
  754. */
  755. if (lstate == QIB_IB_LINKDOWN_DISABLE && smp->hop_cnt) {
  756. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  757. goto done;
  758. }
  759. qib_wait_linkstate(ppd, QIBL_LINKV, 10);
  760. break;
  761. case IB_PORT_ARMED:
  762. qib_set_linkstate(ppd, QIB_IB_LINKARM);
  763. break;
  764. case IB_PORT_ACTIVE:
  765. qib_set_linkstate(ppd, QIB_IB_LINKACTIVE);
  766. break;
  767. default:
  768. smp->status |= IB_SMP_INVALID_FIELD;
  769. }
  770. if (clientrereg) {
  771. event.event = IB_EVENT_CLIENT_REREGISTER;
  772. ib_dispatch_event(&event);
  773. }
  774. /* restore re-reg bit per o14-12.2.1 */
  775. pip->clientrereg_resv_subnetto |= clientrereg;
  776. goto get_only;
  777. err:
  778. smp->status |= IB_SMP_INVALID_FIELD;
  779. get_only:
  780. ret = subn_get_portinfo(smp, ibdev, port);
  781. done:
  782. return ret;
  783. }
  784. /**
  785. * rm_pkey - decrecment the reference count for the given PKEY
  786. * @dd: the qlogic_ib device
  787. * @key: the PKEY index
  788. *
  789. * Return true if this was the last reference and the hardware table entry
  790. * needs to be changed.
  791. */
  792. static int rm_pkey(struct qib_pportdata *ppd, u16 key)
  793. {
  794. int i;
  795. int ret;
  796. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  797. if (ppd->pkeys[i] != key)
  798. continue;
  799. if (atomic_dec_and_test(&ppd->pkeyrefs[i])) {
  800. ppd->pkeys[i] = 0;
  801. ret = 1;
  802. goto bail;
  803. }
  804. break;
  805. }
  806. ret = 0;
  807. bail:
  808. return ret;
  809. }
  810. /**
  811. * add_pkey - add the given PKEY to the hardware table
  812. * @dd: the qlogic_ib device
  813. * @key: the PKEY
  814. *
  815. * Return an error code if unable to add the entry, zero if no change,
  816. * or 1 if the hardware PKEY register needs to be updated.
  817. */
  818. static int add_pkey(struct qib_pportdata *ppd, u16 key)
  819. {
  820. int i;
  821. u16 lkey = key & 0x7FFF;
  822. int any = 0;
  823. int ret;
  824. if (lkey == 0x7FFF) {
  825. ret = 0;
  826. goto bail;
  827. }
  828. /* Look for an empty slot or a matching PKEY. */
  829. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  830. if (!ppd->pkeys[i]) {
  831. any++;
  832. continue;
  833. }
  834. /* If it matches exactly, try to increment the ref count */
  835. if (ppd->pkeys[i] == key) {
  836. if (atomic_inc_return(&ppd->pkeyrefs[i]) > 1) {
  837. ret = 0;
  838. goto bail;
  839. }
  840. /* Lost the race. Look for an empty slot below. */
  841. atomic_dec(&ppd->pkeyrefs[i]);
  842. any++;
  843. }
  844. /*
  845. * It makes no sense to have both the limited and unlimited
  846. * PKEY set at the same time since the unlimited one will
  847. * disable the limited one.
  848. */
  849. if ((ppd->pkeys[i] & 0x7FFF) == lkey) {
  850. ret = -EEXIST;
  851. goto bail;
  852. }
  853. }
  854. if (!any) {
  855. ret = -EBUSY;
  856. goto bail;
  857. }
  858. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  859. if (!ppd->pkeys[i] &&
  860. atomic_inc_return(&ppd->pkeyrefs[i]) == 1) {
  861. /* for qibstats, etc. */
  862. ppd->pkeys[i] = key;
  863. ret = 1;
  864. goto bail;
  865. }
  866. }
  867. ret = -EBUSY;
  868. bail:
  869. return ret;
  870. }
  871. /**
  872. * set_pkeys - set the PKEY table for ctxt 0
  873. * @dd: the qlogic_ib device
  874. * @port: the IB port number
  875. * @pkeys: the PKEY table
  876. */
  877. static int set_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys)
  878. {
  879. struct qib_pportdata *ppd;
  880. struct qib_ctxtdata *rcd;
  881. int i;
  882. int changed = 0;
  883. /*
  884. * IB port one/two always maps to context zero/one,
  885. * always a kernel context, no locking needed
  886. * If we get here with ppd setup, no need to check
  887. * that rcd is valid.
  888. */
  889. ppd = dd->pport + (port - 1);
  890. rcd = dd->rcd[ppd->hw_pidx];
  891. for (i = 0; i < ARRAY_SIZE(rcd->pkeys); i++) {
  892. u16 key = pkeys[i];
  893. u16 okey = rcd->pkeys[i];
  894. if (key == okey)
  895. continue;
  896. /*
  897. * The value of this PKEY table entry is changing.
  898. * Remove the old entry in the hardware's array of PKEYs.
  899. */
  900. if (okey & 0x7FFF)
  901. changed |= rm_pkey(ppd, okey);
  902. if (key & 0x7FFF) {
  903. int ret = add_pkey(ppd, key);
  904. if (ret < 0)
  905. key = 0;
  906. else
  907. changed |= ret;
  908. }
  909. rcd->pkeys[i] = key;
  910. }
  911. if (changed) {
  912. struct ib_event event;
  913. (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0);
  914. event.event = IB_EVENT_PKEY_CHANGE;
  915. event.device = &dd->verbs_dev.rdi.ibdev;
  916. event.element.port_num = port;
  917. ib_dispatch_event(&event);
  918. }
  919. return 0;
  920. }
  921. static int subn_set_pkeytable(struct ib_smp *smp, struct ib_device *ibdev,
  922. u8 port)
  923. {
  924. u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
  925. __be16 *p = (__be16 *) smp->data;
  926. u16 *q = (u16 *) smp->data;
  927. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  928. unsigned i, n = qib_get_npkeys(dd);
  929. for (i = 0; i < n; i++)
  930. q[i] = be16_to_cpu(p[i]);
  931. if (startpx != 0 || set_pkeys(dd, port, q) != 0)
  932. smp->status |= IB_SMP_INVALID_FIELD;
  933. return subn_get_pkeytable(smp, ibdev, port);
  934. }
  935. static int subn_get_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
  936. u8 port)
  937. {
  938. struct qib_ibport *ibp = to_iport(ibdev, port);
  939. u8 *p = (u8 *) smp->data;
  940. unsigned i;
  941. memset(smp->data, 0, sizeof(smp->data));
  942. if (!(ibp->rvp.port_cap_flags & IB_PORT_SL_MAP_SUP))
  943. smp->status |= IB_SMP_UNSUP_METHOD;
  944. else
  945. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2)
  946. *p++ = (ibp->sl_to_vl[i] << 4) | ibp->sl_to_vl[i + 1];
  947. return reply(smp);
  948. }
  949. static int subn_set_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
  950. u8 port)
  951. {
  952. struct qib_ibport *ibp = to_iport(ibdev, port);
  953. u8 *p = (u8 *) smp->data;
  954. unsigned i;
  955. if (!(ibp->rvp.port_cap_flags & IB_PORT_SL_MAP_SUP)) {
  956. smp->status |= IB_SMP_UNSUP_METHOD;
  957. return reply(smp);
  958. }
  959. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2, p++) {
  960. ibp->sl_to_vl[i] = *p >> 4;
  961. ibp->sl_to_vl[i + 1] = *p & 0xF;
  962. }
  963. qib_set_uevent_bits(ppd_from_ibp(to_iport(ibdev, port)),
  964. _QIB_EVENT_SL2VL_CHANGE_BIT);
  965. return subn_get_sl_to_vl(smp, ibdev, port);
  966. }
  967. static int subn_get_vl_arb(struct ib_smp *smp, struct ib_device *ibdev,
  968. u8 port)
  969. {
  970. unsigned which = be32_to_cpu(smp->attr_mod) >> 16;
  971. struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  972. memset(smp->data, 0, sizeof(smp->data));
  973. if (ppd->vls_supported == IB_VL_VL0)
  974. smp->status |= IB_SMP_UNSUP_METHOD;
  975. else if (which == IB_VLARB_LOWPRI_0_31)
  976. (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB,
  977. smp->data);
  978. else if (which == IB_VLARB_HIGHPRI_0_31)
  979. (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB,
  980. smp->data);
  981. else
  982. smp->status |= IB_SMP_INVALID_FIELD;
  983. return reply(smp);
  984. }
  985. static int subn_set_vl_arb(struct ib_smp *smp, struct ib_device *ibdev,
  986. u8 port)
  987. {
  988. unsigned which = be32_to_cpu(smp->attr_mod) >> 16;
  989. struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  990. if (ppd->vls_supported == IB_VL_VL0)
  991. smp->status |= IB_SMP_UNSUP_METHOD;
  992. else if (which == IB_VLARB_LOWPRI_0_31)
  993. (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB,
  994. smp->data);
  995. else if (which == IB_VLARB_HIGHPRI_0_31)
  996. (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB,
  997. smp->data);
  998. else
  999. smp->status |= IB_SMP_INVALID_FIELD;
  1000. return subn_get_vl_arb(smp, ibdev, port);
  1001. }
  1002. static int subn_trap_repress(struct ib_smp *smp, struct ib_device *ibdev,
  1003. u8 port)
  1004. {
  1005. /*
  1006. * For now, we only send the trap once so no need to process this.
  1007. * o13-6, o13-7,
  1008. * o14-3.a4 The SMA shall not send any message in response to a valid
  1009. * SubnTrapRepress() message.
  1010. */
  1011. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  1012. }
  1013. static int pma_get_classportinfo(struct ib_pma_mad *pmp,
  1014. struct ib_device *ibdev)
  1015. {
  1016. struct ib_class_port_info *p =
  1017. (struct ib_class_port_info *)pmp->data;
  1018. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  1019. memset(pmp->data, 0, sizeof(pmp->data));
  1020. if (pmp->mad_hdr.attr_mod != 0)
  1021. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1022. /* Note that AllPortSelect is not valid */
  1023. p->base_version = 1;
  1024. p->class_version = 1;
  1025. p->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
  1026. /*
  1027. * Set the most significant bit of CM2 to indicate support for
  1028. * congestion statistics
  1029. */
  1030. ib_set_cpi_capmask2(p,
  1031. dd->psxmitwait_supported <<
  1032. (31 - IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE));
  1033. /*
  1034. * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
  1035. */
  1036. ib_set_cpi_resp_time(p, 18);
  1037. return reply((struct ib_smp *) pmp);
  1038. }
  1039. static int pma_get_portsamplescontrol(struct ib_pma_mad *pmp,
  1040. struct ib_device *ibdev, u8 port)
  1041. {
  1042. struct ib_pma_portsamplescontrol *p =
  1043. (struct ib_pma_portsamplescontrol *)pmp->data;
  1044. struct qib_ibdev *dev = to_idev(ibdev);
  1045. struct qib_devdata *dd = dd_from_dev(dev);
  1046. struct qib_ibport *ibp = to_iport(ibdev, port);
  1047. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1048. unsigned long flags;
  1049. u8 port_select = p->port_select;
  1050. memset(pmp->data, 0, sizeof(pmp->data));
  1051. p->port_select = port_select;
  1052. if (pmp->mad_hdr.attr_mod != 0 || port_select != port) {
  1053. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1054. goto bail;
  1055. }
  1056. spin_lock_irqsave(&ibp->rvp.lock, flags);
  1057. p->tick = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PMA_TICKS);
  1058. p->sample_status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1059. p->counter_width = 4; /* 32 bit counters */
  1060. p->counter_mask0_9 = COUNTER_MASK0_9;
  1061. p->sample_start = cpu_to_be32(ibp->rvp.pma_sample_start);
  1062. p->sample_interval = cpu_to_be32(ibp->rvp.pma_sample_interval);
  1063. p->tag = cpu_to_be16(ibp->rvp.pma_tag);
  1064. p->counter_select[0] = ibp->rvp.pma_counter_select[0];
  1065. p->counter_select[1] = ibp->rvp.pma_counter_select[1];
  1066. p->counter_select[2] = ibp->rvp.pma_counter_select[2];
  1067. p->counter_select[3] = ibp->rvp.pma_counter_select[3];
  1068. p->counter_select[4] = ibp->rvp.pma_counter_select[4];
  1069. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  1070. bail:
  1071. return reply((struct ib_smp *) pmp);
  1072. }
  1073. static int pma_set_portsamplescontrol(struct ib_pma_mad *pmp,
  1074. struct ib_device *ibdev, u8 port)
  1075. {
  1076. struct ib_pma_portsamplescontrol *p =
  1077. (struct ib_pma_portsamplescontrol *)pmp->data;
  1078. struct qib_ibdev *dev = to_idev(ibdev);
  1079. struct qib_devdata *dd = dd_from_dev(dev);
  1080. struct qib_ibport *ibp = to_iport(ibdev, port);
  1081. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1082. unsigned long flags;
  1083. u8 status, xmit_flags;
  1084. int ret;
  1085. if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
  1086. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1087. ret = reply((struct ib_smp *) pmp);
  1088. goto bail;
  1089. }
  1090. spin_lock_irqsave(&ibp->rvp.lock, flags);
  1091. /* Port Sampling code owns the PS* HW counters */
  1092. xmit_flags = ppd->cong_stats.flags;
  1093. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_SAMPLE;
  1094. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1095. if (status == IB_PMA_SAMPLE_STATUS_DONE ||
  1096. (status == IB_PMA_SAMPLE_STATUS_RUNNING &&
  1097. xmit_flags == IB_PMA_CONG_HW_CONTROL_TIMER)) {
  1098. ibp->rvp.pma_sample_start = be32_to_cpu(p->sample_start);
  1099. ibp->rvp.pma_sample_interval = be32_to_cpu(p->sample_interval);
  1100. ibp->rvp.pma_tag = be16_to_cpu(p->tag);
  1101. ibp->rvp.pma_counter_select[0] = p->counter_select[0];
  1102. ibp->rvp.pma_counter_select[1] = p->counter_select[1];
  1103. ibp->rvp.pma_counter_select[2] = p->counter_select[2];
  1104. ibp->rvp.pma_counter_select[3] = p->counter_select[3];
  1105. ibp->rvp.pma_counter_select[4] = p->counter_select[4];
  1106. dd->f_set_cntr_sample(ppd, ibp->rvp.pma_sample_interval,
  1107. ibp->rvp.pma_sample_start);
  1108. }
  1109. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  1110. ret = pma_get_portsamplescontrol(pmp, ibdev, port);
  1111. bail:
  1112. return ret;
  1113. }
  1114. static u64 get_counter(struct qib_ibport *ibp, struct qib_pportdata *ppd,
  1115. __be16 sel)
  1116. {
  1117. u64 ret;
  1118. switch (sel) {
  1119. case IB_PMA_PORT_XMIT_DATA:
  1120. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITDATA);
  1121. break;
  1122. case IB_PMA_PORT_RCV_DATA:
  1123. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVDATA);
  1124. break;
  1125. case IB_PMA_PORT_XMIT_PKTS:
  1126. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITPKTS);
  1127. break;
  1128. case IB_PMA_PORT_RCV_PKTS:
  1129. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVPKTS);
  1130. break;
  1131. case IB_PMA_PORT_XMIT_WAIT:
  1132. ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITWAIT);
  1133. break;
  1134. default:
  1135. ret = 0;
  1136. }
  1137. return ret;
  1138. }
  1139. /* This function assumes that the xmit_wait lock is already held */
  1140. static u64 xmit_wait_get_value_delta(struct qib_pportdata *ppd)
  1141. {
  1142. u32 delta;
  1143. delta = get_counter(&ppd->ibport_data, ppd,
  1144. IB_PMA_PORT_XMIT_WAIT);
  1145. return ppd->cong_stats.counter + delta;
  1146. }
  1147. static void cache_hw_sample_counters(struct qib_pportdata *ppd)
  1148. {
  1149. struct qib_ibport *ibp = &ppd->ibport_data;
  1150. ppd->cong_stats.counter_cache.psxmitdata =
  1151. get_counter(ibp, ppd, IB_PMA_PORT_XMIT_DATA);
  1152. ppd->cong_stats.counter_cache.psrcvdata =
  1153. get_counter(ibp, ppd, IB_PMA_PORT_RCV_DATA);
  1154. ppd->cong_stats.counter_cache.psxmitpkts =
  1155. get_counter(ibp, ppd, IB_PMA_PORT_XMIT_PKTS);
  1156. ppd->cong_stats.counter_cache.psrcvpkts =
  1157. get_counter(ibp, ppd, IB_PMA_PORT_RCV_PKTS);
  1158. ppd->cong_stats.counter_cache.psxmitwait =
  1159. get_counter(ibp, ppd, IB_PMA_PORT_XMIT_WAIT);
  1160. }
  1161. static u64 get_cache_hw_sample_counters(struct qib_pportdata *ppd,
  1162. __be16 sel)
  1163. {
  1164. u64 ret;
  1165. switch (sel) {
  1166. case IB_PMA_PORT_XMIT_DATA:
  1167. ret = ppd->cong_stats.counter_cache.psxmitdata;
  1168. break;
  1169. case IB_PMA_PORT_RCV_DATA:
  1170. ret = ppd->cong_stats.counter_cache.psrcvdata;
  1171. break;
  1172. case IB_PMA_PORT_XMIT_PKTS:
  1173. ret = ppd->cong_stats.counter_cache.psxmitpkts;
  1174. break;
  1175. case IB_PMA_PORT_RCV_PKTS:
  1176. ret = ppd->cong_stats.counter_cache.psrcvpkts;
  1177. break;
  1178. case IB_PMA_PORT_XMIT_WAIT:
  1179. ret = ppd->cong_stats.counter_cache.psxmitwait;
  1180. break;
  1181. default:
  1182. ret = 0;
  1183. }
  1184. return ret;
  1185. }
  1186. static int pma_get_portsamplesresult(struct ib_pma_mad *pmp,
  1187. struct ib_device *ibdev, u8 port)
  1188. {
  1189. struct ib_pma_portsamplesresult *p =
  1190. (struct ib_pma_portsamplesresult *)pmp->data;
  1191. struct qib_ibdev *dev = to_idev(ibdev);
  1192. struct qib_devdata *dd = dd_from_dev(dev);
  1193. struct qib_ibport *ibp = to_iport(ibdev, port);
  1194. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1195. unsigned long flags;
  1196. u8 status;
  1197. int i;
  1198. memset(pmp->data, 0, sizeof(pmp->data));
  1199. spin_lock_irqsave(&ibp->rvp.lock, flags);
  1200. p->tag = cpu_to_be16(ibp->rvp.pma_tag);
  1201. if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
  1202. p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  1203. else {
  1204. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1205. p->sample_status = cpu_to_be16(status);
  1206. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  1207. cache_hw_sample_counters(ppd);
  1208. ppd->cong_stats.counter =
  1209. xmit_wait_get_value_delta(ppd);
  1210. dd->f_set_cntr_sample(ppd,
  1211. QIB_CONG_TIMER_PSINTERVAL, 0);
  1212. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
  1213. }
  1214. }
  1215. for (i = 0; i < ARRAY_SIZE(ibp->rvp.pma_counter_select); i++)
  1216. p->counter[i] = cpu_to_be32(
  1217. get_cache_hw_sample_counters(
  1218. ppd, ibp->rvp.pma_counter_select[i]));
  1219. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  1220. return reply((struct ib_smp *) pmp);
  1221. }
  1222. static int pma_get_portsamplesresult_ext(struct ib_pma_mad *pmp,
  1223. struct ib_device *ibdev, u8 port)
  1224. {
  1225. struct ib_pma_portsamplesresult_ext *p =
  1226. (struct ib_pma_portsamplesresult_ext *)pmp->data;
  1227. struct qib_ibdev *dev = to_idev(ibdev);
  1228. struct qib_devdata *dd = dd_from_dev(dev);
  1229. struct qib_ibport *ibp = to_iport(ibdev, port);
  1230. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1231. unsigned long flags;
  1232. u8 status;
  1233. int i;
  1234. /* Port Sampling code owns the PS* HW counters */
  1235. memset(pmp->data, 0, sizeof(pmp->data));
  1236. spin_lock_irqsave(&ibp->rvp.lock, flags);
  1237. p->tag = cpu_to_be16(ibp->rvp.pma_tag);
  1238. if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
  1239. p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  1240. else {
  1241. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  1242. p->sample_status = cpu_to_be16(status);
  1243. /* 64 bits */
  1244. p->extended_width = cpu_to_be32(0x80000000);
  1245. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  1246. cache_hw_sample_counters(ppd);
  1247. ppd->cong_stats.counter =
  1248. xmit_wait_get_value_delta(ppd);
  1249. dd->f_set_cntr_sample(ppd,
  1250. QIB_CONG_TIMER_PSINTERVAL, 0);
  1251. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
  1252. }
  1253. }
  1254. for (i = 0; i < ARRAY_SIZE(ibp->rvp.pma_counter_select); i++)
  1255. p->counter[i] = cpu_to_be64(
  1256. get_cache_hw_sample_counters(
  1257. ppd, ibp->rvp.pma_counter_select[i]));
  1258. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  1259. return reply((struct ib_smp *) pmp);
  1260. }
  1261. static int pma_get_portcounters(struct ib_pma_mad *pmp,
  1262. struct ib_device *ibdev, u8 port)
  1263. {
  1264. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1265. pmp->data;
  1266. struct qib_ibport *ibp = to_iport(ibdev, port);
  1267. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1268. struct qib_verbs_counters cntrs;
  1269. u8 port_select = p->port_select;
  1270. qib_get_counters(ppd, &cntrs);
  1271. /* Adjust counters for any resets done. */
  1272. cntrs.symbol_error_counter -= ibp->z_symbol_error_counter;
  1273. cntrs.link_error_recovery_counter -=
  1274. ibp->z_link_error_recovery_counter;
  1275. cntrs.link_downed_counter -= ibp->z_link_downed_counter;
  1276. cntrs.port_rcv_errors -= ibp->z_port_rcv_errors;
  1277. cntrs.port_rcv_remphys_errors -= ibp->z_port_rcv_remphys_errors;
  1278. cntrs.port_xmit_discards -= ibp->z_port_xmit_discards;
  1279. cntrs.port_xmit_data -= ibp->z_port_xmit_data;
  1280. cntrs.port_rcv_data -= ibp->z_port_rcv_data;
  1281. cntrs.port_xmit_packets -= ibp->z_port_xmit_packets;
  1282. cntrs.port_rcv_packets -= ibp->z_port_rcv_packets;
  1283. cntrs.local_link_integrity_errors -=
  1284. ibp->z_local_link_integrity_errors;
  1285. cntrs.excessive_buffer_overrun_errors -=
  1286. ibp->z_excessive_buffer_overrun_errors;
  1287. cntrs.vl15_dropped -= ibp->z_vl15_dropped;
  1288. cntrs.vl15_dropped += ibp->rvp.n_vl15_dropped;
  1289. memset(pmp->data, 0, sizeof(pmp->data));
  1290. p->port_select = port_select;
  1291. if (pmp->mad_hdr.attr_mod != 0 || port_select != port)
  1292. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1293. if (cntrs.symbol_error_counter > 0xFFFFUL)
  1294. p->symbol_error_counter = cpu_to_be16(0xFFFF);
  1295. else
  1296. p->symbol_error_counter =
  1297. cpu_to_be16((u16)cntrs.symbol_error_counter);
  1298. if (cntrs.link_error_recovery_counter > 0xFFUL)
  1299. p->link_error_recovery_counter = 0xFF;
  1300. else
  1301. p->link_error_recovery_counter =
  1302. (u8)cntrs.link_error_recovery_counter;
  1303. if (cntrs.link_downed_counter > 0xFFUL)
  1304. p->link_downed_counter = 0xFF;
  1305. else
  1306. p->link_downed_counter = (u8)cntrs.link_downed_counter;
  1307. if (cntrs.port_rcv_errors > 0xFFFFUL)
  1308. p->port_rcv_errors = cpu_to_be16(0xFFFF);
  1309. else
  1310. p->port_rcv_errors =
  1311. cpu_to_be16((u16) cntrs.port_rcv_errors);
  1312. if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
  1313. p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
  1314. else
  1315. p->port_rcv_remphys_errors =
  1316. cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
  1317. if (cntrs.port_xmit_discards > 0xFFFFUL)
  1318. p->port_xmit_discards = cpu_to_be16(0xFFFF);
  1319. else
  1320. p->port_xmit_discards =
  1321. cpu_to_be16((u16)cntrs.port_xmit_discards);
  1322. if (cntrs.local_link_integrity_errors > 0xFUL)
  1323. cntrs.local_link_integrity_errors = 0xFUL;
  1324. if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
  1325. cntrs.excessive_buffer_overrun_errors = 0xFUL;
  1326. p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) |
  1327. cntrs.excessive_buffer_overrun_errors;
  1328. if (cntrs.vl15_dropped > 0xFFFFUL)
  1329. p->vl15_dropped = cpu_to_be16(0xFFFF);
  1330. else
  1331. p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
  1332. if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
  1333. p->port_xmit_data = cpu_to_be32(0xFFFFFFFF);
  1334. else
  1335. p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
  1336. if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
  1337. p->port_rcv_data = cpu_to_be32(0xFFFFFFFF);
  1338. else
  1339. p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
  1340. if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
  1341. p->port_xmit_packets = cpu_to_be32(0xFFFFFFFF);
  1342. else
  1343. p->port_xmit_packets =
  1344. cpu_to_be32((u32)cntrs.port_xmit_packets);
  1345. if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
  1346. p->port_rcv_packets = cpu_to_be32(0xFFFFFFFF);
  1347. else
  1348. p->port_rcv_packets =
  1349. cpu_to_be32((u32) cntrs.port_rcv_packets);
  1350. return reply((struct ib_smp *) pmp);
  1351. }
  1352. static int pma_get_portcounters_cong(struct ib_pma_mad *pmp,
  1353. struct ib_device *ibdev, u8 port)
  1354. {
  1355. /* Congestion PMA packets start at offset 24 not 64 */
  1356. struct ib_pma_portcounters_cong *p =
  1357. (struct ib_pma_portcounters_cong *)pmp->reserved;
  1358. struct qib_verbs_counters cntrs;
  1359. struct qib_ibport *ibp = to_iport(ibdev, port);
  1360. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1361. struct qib_devdata *dd = dd_from_ppd(ppd);
  1362. u32 port_select = be32_to_cpu(pmp->mad_hdr.attr_mod) & 0xFF;
  1363. u64 xmit_wait_counter;
  1364. unsigned long flags;
  1365. /*
  1366. * This check is performed only in the GET method because the
  1367. * SET method ends up calling this anyway.
  1368. */
  1369. if (!dd->psxmitwait_supported)
  1370. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  1371. if (port_select != port)
  1372. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1373. qib_get_counters(ppd, &cntrs);
  1374. spin_lock_irqsave(&ppd->ibport_data.rvp.lock, flags);
  1375. xmit_wait_counter = xmit_wait_get_value_delta(ppd);
  1376. spin_unlock_irqrestore(&ppd->ibport_data.rvp.lock, flags);
  1377. /* Adjust counters for any resets done. */
  1378. cntrs.symbol_error_counter -= ibp->z_symbol_error_counter;
  1379. cntrs.link_error_recovery_counter -=
  1380. ibp->z_link_error_recovery_counter;
  1381. cntrs.link_downed_counter -= ibp->z_link_downed_counter;
  1382. cntrs.port_rcv_errors -= ibp->z_port_rcv_errors;
  1383. cntrs.port_rcv_remphys_errors -=
  1384. ibp->z_port_rcv_remphys_errors;
  1385. cntrs.port_xmit_discards -= ibp->z_port_xmit_discards;
  1386. cntrs.local_link_integrity_errors -=
  1387. ibp->z_local_link_integrity_errors;
  1388. cntrs.excessive_buffer_overrun_errors -=
  1389. ibp->z_excessive_buffer_overrun_errors;
  1390. cntrs.vl15_dropped -= ibp->z_vl15_dropped;
  1391. cntrs.vl15_dropped += ibp->rvp.n_vl15_dropped;
  1392. cntrs.port_xmit_data -= ibp->z_port_xmit_data;
  1393. cntrs.port_rcv_data -= ibp->z_port_rcv_data;
  1394. cntrs.port_xmit_packets -= ibp->z_port_xmit_packets;
  1395. cntrs.port_rcv_packets -= ibp->z_port_rcv_packets;
  1396. memset(pmp->reserved, 0, sizeof(pmp->reserved));
  1397. memset(pmp->data, 0, sizeof(pmp->data));
  1398. /*
  1399. * Set top 3 bits to indicate interval in picoseconds in
  1400. * remaining bits.
  1401. */
  1402. p->port_check_rate =
  1403. cpu_to_be16((QIB_XMIT_RATE_PICO << 13) |
  1404. (dd->psxmitwait_check_rate &
  1405. ~(QIB_XMIT_RATE_PICO << 13)));
  1406. p->port_adr_events = cpu_to_be64(0);
  1407. p->port_xmit_wait = cpu_to_be64(xmit_wait_counter);
  1408. p->port_xmit_data = cpu_to_be64(cntrs.port_xmit_data);
  1409. p->port_rcv_data = cpu_to_be64(cntrs.port_rcv_data);
  1410. p->port_xmit_packets =
  1411. cpu_to_be64(cntrs.port_xmit_packets);
  1412. p->port_rcv_packets =
  1413. cpu_to_be64(cntrs.port_rcv_packets);
  1414. if (cntrs.symbol_error_counter > 0xFFFFUL)
  1415. p->symbol_error_counter = cpu_to_be16(0xFFFF);
  1416. else
  1417. p->symbol_error_counter =
  1418. cpu_to_be16(
  1419. (u16)cntrs.symbol_error_counter);
  1420. if (cntrs.link_error_recovery_counter > 0xFFUL)
  1421. p->link_error_recovery_counter = 0xFF;
  1422. else
  1423. p->link_error_recovery_counter =
  1424. (u8)cntrs.link_error_recovery_counter;
  1425. if (cntrs.link_downed_counter > 0xFFUL)
  1426. p->link_downed_counter = 0xFF;
  1427. else
  1428. p->link_downed_counter =
  1429. (u8)cntrs.link_downed_counter;
  1430. if (cntrs.port_rcv_errors > 0xFFFFUL)
  1431. p->port_rcv_errors = cpu_to_be16(0xFFFF);
  1432. else
  1433. p->port_rcv_errors =
  1434. cpu_to_be16((u16) cntrs.port_rcv_errors);
  1435. if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
  1436. p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
  1437. else
  1438. p->port_rcv_remphys_errors =
  1439. cpu_to_be16(
  1440. (u16)cntrs.port_rcv_remphys_errors);
  1441. if (cntrs.port_xmit_discards > 0xFFFFUL)
  1442. p->port_xmit_discards = cpu_to_be16(0xFFFF);
  1443. else
  1444. p->port_xmit_discards =
  1445. cpu_to_be16((u16)cntrs.port_xmit_discards);
  1446. if (cntrs.local_link_integrity_errors > 0xFUL)
  1447. cntrs.local_link_integrity_errors = 0xFUL;
  1448. if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
  1449. cntrs.excessive_buffer_overrun_errors = 0xFUL;
  1450. p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) |
  1451. cntrs.excessive_buffer_overrun_errors;
  1452. if (cntrs.vl15_dropped > 0xFFFFUL)
  1453. p->vl15_dropped = cpu_to_be16(0xFFFF);
  1454. else
  1455. p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
  1456. return reply((struct ib_smp *)pmp);
  1457. }
  1458. static void qib_snapshot_pmacounters(
  1459. struct qib_ibport *ibp,
  1460. struct qib_pma_counters *pmacounters)
  1461. {
  1462. struct qib_pma_counters *p;
  1463. int cpu;
  1464. memset(pmacounters, 0, sizeof(*pmacounters));
  1465. for_each_possible_cpu(cpu) {
  1466. p = per_cpu_ptr(ibp->pmastats, cpu);
  1467. pmacounters->n_unicast_xmit += p->n_unicast_xmit;
  1468. pmacounters->n_unicast_rcv += p->n_unicast_rcv;
  1469. pmacounters->n_multicast_xmit += p->n_multicast_xmit;
  1470. pmacounters->n_multicast_rcv += p->n_multicast_rcv;
  1471. }
  1472. }
  1473. static int pma_get_portcounters_ext(struct ib_pma_mad *pmp,
  1474. struct ib_device *ibdev, u8 port)
  1475. {
  1476. struct ib_pma_portcounters_ext *p =
  1477. (struct ib_pma_portcounters_ext *)pmp->data;
  1478. struct qib_ibport *ibp = to_iport(ibdev, port);
  1479. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1480. u64 swords, rwords, spkts, rpkts, xwait;
  1481. struct qib_pma_counters pma;
  1482. u8 port_select = p->port_select;
  1483. memset(pmp->data, 0, sizeof(pmp->data));
  1484. p->port_select = port_select;
  1485. if (pmp->mad_hdr.attr_mod != 0 || port_select != port) {
  1486. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1487. goto bail;
  1488. }
  1489. qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait);
  1490. /* Adjust counters for any resets done. */
  1491. swords -= ibp->z_port_xmit_data;
  1492. rwords -= ibp->z_port_rcv_data;
  1493. spkts -= ibp->z_port_xmit_packets;
  1494. rpkts -= ibp->z_port_rcv_packets;
  1495. p->port_xmit_data = cpu_to_be64(swords);
  1496. p->port_rcv_data = cpu_to_be64(rwords);
  1497. p->port_xmit_packets = cpu_to_be64(spkts);
  1498. p->port_rcv_packets = cpu_to_be64(rpkts);
  1499. qib_snapshot_pmacounters(ibp, &pma);
  1500. p->port_unicast_xmit_packets = cpu_to_be64(pma.n_unicast_xmit
  1501. - ibp->z_unicast_xmit);
  1502. p->port_unicast_rcv_packets = cpu_to_be64(pma.n_unicast_rcv
  1503. - ibp->z_unicast_rcv);
  1504. p->port_multicast_xmit_packets = cpu_to_be64(pma.n_multicast_xmit
  1505. - ibp->z_multicast_xmit);
  1506. p->port_multicast_rcv_packets = cpu_to_be64(pma.n_multicast_rcv
  1507. - ibp->z_multicast_rcv);
  1508. bail:
  1509. return reply((struct ib_smp *) pmp);
  1510. }
  1511. static int pma_set_portcounters(struct ib_pma_mad *pmp,
  1512. struct ib_device *ibdev, u8 port)
  1513. {
  1514. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1515. pmp->data;
  1516. struct qib_ibport *ibp = to_iport(ibdev, port);
  1517. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1518. struct qib_verbs_counters cntrs;
  1519. /*
  1520. * Since the HW doesn't support clearing counters, we save the
  1521. * current count and subtract it from future responses.
  1522. */
  1523. qib_get_counters(ppd, &cntrs);
  1524. if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
  1525. ibp->z_symbol_error_counter = cntrs.symbol_error_counter;
  1526. if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
  1527. ibp->z_link_error_recovery_counter =
  1528. cntrs.link_error_recovery_counter;
  1529. if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
  1530. ibp->z_link_downed_counter = cntrs.link_downed_counter;
  1531. if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
  1532. ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
  1533. if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
  1534. ibp->z_port_rcv_remphys_errors =
  1535. cntrs.port_rcv_remphys_errors;
  1536. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
  1537. ibp->z_port_xmit_discards = cntrs.port_xmit_discards;
  1538. if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
  1539. ibp->z_local_link_integrity_errors =
  1540. cntrs.local_link_integrity_errors;
  1541. if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
  1542. ibp->z_excessive_buffer_overrun_errors =
  1543. cntrs.excessive_buffer_overrun_errors;
  1544. if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
  1545. ibp->rvp.n_vl15_dropped = 0;
  1546. ibp->z_vl15_dropped = cntrs.vl15_dropped;
  1547. }
  1548. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
  1549. ibp->z_port_xmit_data = cntrs.port_xmit_data;
  1550. if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
  1551. ibp->z_port_rcv_data = cntrs.port_rcv_data;
  1552. if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
  1553. ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
  1554. if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
  1555. ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
  1556. return pma_get_portcounters(pmp, ibdev, port);
  1557. }
  1558. static int pma_set_portcounters_cong(struct ib_pma_mad *pmp,
  1559. struct ib_device *ibdev, u8 port)
  1560. {
  1561. struct qib_ibport *ibp = to_iport(ibdev, port);
  1562. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1563. struct qib_devdata *dd = dd_from_ppd(ppd);
  1564. struct qib_verbs_counters cntrs;
  1565. u32 counter_select = (be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24) & 0xFF;
  1566. int ret = 0;
  1567. unsigned long flags;
  1568. qib_get_counters(ppd, &cntrs);
  1569. /* Get counter values before we save them */
  1570. ret = pma_get_portcounters_cong(pmp, ibdev, port);
  1571. if (counter_select & IB_PMA_SEL_CONG_XMIT) {
  1572. spin_lock_irqsave(&ppd->ibport_data.rvp.lock, flags);
  1573. ppd->cong_stats.counter = 0;
  1574. dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL,
  1575. 0x0);
  1576. spin_unlock_irqrestore(&ppd->ibport_data.rvp.lock, flags);
  1577. }
  1578. if (counter_select & IB_PMA_SEL_CONG_PORT_DATA) {
  1579. ibp->z_port_xmit_data = cntrs.port_xmit_data;
  1580. ibp->z_port_rcv_data = cntrs.port_rcv_data;
  1581. ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
  1582. ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
  1583. }
  1584. if (counter_select & IB_PMA_SEL_CONG_ALL) {
  1585. ibp->z_symbol_error_counter =
  1586. cntrs.symbol_error_counter;
  1587. ibp->z_link_error_recovery_counter =
  1588. cntrs.link_error_recovery_counter;
  1589. ibp->z_link_downed_counter =
  1590. cntrs.link_downed_counter;
  1591. ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
  1592. ibp->z_port_rcv_remphys_errors =
  1593. cntrs.port_rcv_remphys_errors;
  1594. ibp->z_port_xmit_discards =
  1595. cntrs.port_xmit_discards;
  1596. ibp->z_local_link_integrity_errors =
  1597. cntrs.local_link_integrity_errors;
  1598. ibp->z_excessive_buffer_overrun_errors =
  1599. cntrs.excessive_buffer_overrun_errors;
  1600. ibp->rvp.n_vl15_dropped = 0;
  1601. ibp->z_vl15_dropped = cntrs.vl15_dropped;
  1602. }
  1603. return ret;
  1604. }
  1605. static int pma_set_portcounters_ext(struct ib_pma_mad *pmp,
  1606. struct ib_device *ibdev, u8 port)
  1607. {
  1608. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  1609. pmp->data;
  1610. struct qib_ibport *ibp = to_iport(ibdev, port);
  1611. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1612. u64 swords, rwords, spkts, rpkts, xwait;
  1613. struct qib_pma_counters pma;
  1614. qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait);
  1615. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
  1616. ibp->z_port_xmit_data = swords;
  1617. if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
  1618. ibp->z_port_rcv_data = rwords;
  1619. if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
  1620. ibp->z_port_xmit_packets = spkts;
  1621. if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
  1622. ibp->z_port_rcv_packets = rpkts;
  1623. qib_snapshot_pmacounters(ibp, &pma);
  1624. if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
  1625. ibp->z_unicast_xmit = pma.n_unicast_xmit;
  1626. if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
  1627. ibp->z_unicast_rcv = pma.n_unicast_rcv;
  1628. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
  1629. ibp->z_multicast_xmit = pma.n_multicast_xmit;
  1630. if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
  1631. ibp->z_multicast_rcv = pma.n_multicast_rcv;
  1632. return pma_get_portcounters_ext(pmp, ibdev, port);
  1633. }
  1634. static int process_subn(struct ib_device *ibdev, int mad_flags,
  1635. u8 port, const struct ib_mad *in_mad,
  1636. struct ib_mad *out_mad)
  1637. {
  1638. struct ib_smp *smp = (struct ib_smp *)out_mad;
  1639. struct qib_ibport *ibp = to_iport(ibdev, port);
  1640. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1641. int ret;
  1642. *out_mad = *in_mad;
  1643. if (smp->class_version != 1) {
  1644. smp->status |= IB_SMP_UNSUP_VERSION;
  1645. ret = reply(smp);
  1646. goto bail;
  1647. }
  1648. ret = check_mkey(ibp, smp, mad_flags);
  1649. if (ret) {
  1650. u32 port_num = be32_to_cpu(smp->attr_mod);
  1651. /*
  1652. * If this is a get/set portinfo, we already check the
  1653. * M_Key if the MAD is for another port and the M_Key
  1654. * is OK on the receiving port. This check is needed
  1655. * to increment the error counters when the M_Key
  1656. * fails to match on *both* ports.
  1657. */
  1658. if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
  1659. (smp->method == IB_MGMT_METHOD_GET ||
  1660. smp->method == IB_MGMT_METHOD_SET) &&
  1661. port_num && port_num <= ibdev->phys_port_cnt &&
  1662. port != port_num)
  1663. (void) check_mkey(to_iport(ibdev, port_num), smp, 0);
  1664. ret = IB_MAD_RESULT_FAILURE;
  1665. goto bail;
  1666. }
  1667. switch (smp->method) {
  1668. case IB_MGMT_METHOD_GET:
  1669. switch (smp->attr_id) {
  1670. case IB_SMP_ATTR_NODE_DESC:
  1671. ret = subn_get_nodedescription(smp, ibdev);
  1672. goto bail;
  1673. case IB_SMP_ATTR_NODE_INFO:
  1674. ret = subn_get_nodeinfo(smp, ibdev, port);
  1675. goto bail;
  1676. case IB_SMP_ATTR_GUID_INFO:
  1677. ret = subn_get_guidinfo(smp, ibdev, port);
  1678. goto bail;
  1679. case IB_SMP_ATTR_PORT_INFO:
  1680. ret = subn_get_portinfo(smp, ibdev, port);
  1681. goto bail;
  1682. case IB_SMP_ATTR_PKEY_TABLE:
  1683. ret = subn_get_pkeytable(smp, ibdev, port);
  1684. goto bail;
  1685. case IB_SMP_ATTR_SL_TO_VL_TABLE:
  1686. ret = subn_get_sl_to_vl(smp, ibdev, port);
  1687. goto bail;
  1688. case IB_SMP_ATTR_VL_ARB_TABLE:
  1689. ret = subn_get_vl_arb(smp, ibdev, port);
  1690. goto bail;
  1691. case IB_SMP_ATTR_SM_INFO:
  1692. if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) {
  1693. ret = IB_MAD_RESULT_SUCCESS |
  1694. IB_MAD_RESULT_CONSUMED;
  1695. goto bail;
  1696. }
  1697. if (ibp->rvp.port_cap_flags & IB_PORT_SM) {
  1698. ret = IB_MAD_RESULT_SUCCESS;
  1699. goto bail;
  1700. }
  1701. /* FALLTHROUGH */
  1702. default:
  1703. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1704. ret = reply(smp);
  1705. goto bail;
  1706. }
  1707. case IB_MGMT_METHOD_SET:
  1708. switch (smp->attr_id) {
  1709. case IB_SMP_ATTR_GUID_INFO:
  1710. ret = subn_set_guidinfo(smp, ibdev, port);
  1711. goto bail;
  1712. case IB_SMP_ATTR_PORT_INFO:
  1713. ret = subn_set_portinfo(smp, ibdev, port);
  1714. goto bail;
  1715. case IB_SMP_ATTR_PKEY_TABLE:
  1716. ret = subn_set_pkeytable(smp, ibdev, port);
  1717. goto bail;
  1718. case IB_SMP_ATTR_SL_TO_VL_TABLE:
  1719. ret = subn_set_sl_to_vl(smp, ibdev, port);
  1720. goto bail;
  1721. case IB_SMP_ATTR_VL_ARB_TABLE:
  1722. ret = subn_set_vl_arb(smp, ibdev, port);
  1723. goto bail;
  1724. case IB_SMP_ATTR_SM_INFO:
  1725. if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) {
  1726. ret = IB_MAD_RESULT_SUCCESS |
  1727. IB_MAD_RESULT_CONSUMED;
  1728. goto bail;
  1729. }
  1730. if (ibp->rvp.port_cap_flags & IB_PORT_SM) {
  1731. ret = IB_MAD_RESULT_SUCCESS;
  1732. goto bail;
  1733. }
  1734. /* FALLTHROUGH */
  1735. default:
  1736. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1737. ret = reply(smp);
  1738. goto bail;
  1739. }
  1740. case IB_MGMT_METHOD_TRAP_REPRESS:
  1741. if (smp->attr_id == IB_SMP_ATTR_NOTICE)
  1742. ret = subn_trap_repress(smp, ibdev, port);
  1743. else {
  1744. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1745. ret = reply(smp);
  1746. }
  1747. goto bail;
  1748. case IB_MGMT_METHOD_TRAP:
  1749. case IB_MGMT_METHOD_REPORT:
  1750. case IB_MGMT_METHOD_REPORT_RESP:
  1751. case IB_MGMT_METHOD_GET_RESP:
  1752. /*
  1753. * The ib_mad module will call us to process responses
  1754. * before checking for other consumers.
  1755. * Just tell the caller to process it normally.
  1756. */
  1757. ret = IB_MAD_RESULT_SUCCESS;
  1758. goto bail;
  1759. case IB_MGMT_METHOD_SEND:
  1760. if (ib_get_smp_direction(smp) &&
  1761. smp->attr_id == QIB_VENDOR_IPG) {
  1762. ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PORT,
  1763. smp->data[0]);
  1764. ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  1765. } else
  1766. ret = IB_MAD_RESULT_SUCCESS;
  1767. goto bail;
  1768. default:
  1769. smp->status |= IB_SMP_UNSUP_METHOD;
  1770. ret = reply(smp);
  1771. }
  1772. bail:
  1773. return ret;
  1774. }
  1775. static int process_perf(struct ib_device *ibdev, u8 port,
  1776. const struct ib_mad *in_mad,
  1777. struct ib_mad *out_mad)
  1778. {
  1779. struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad;
  1780. int ret;
  1781. *out_mad = *in_mad;
  1782. if (pmp->mad_hdr.class_version != 1) {
  1783. pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
  1784. ret = reply((struct ib_smp *) pmp);
  1785. goto bail;
  1786. }
  1787. switch (pmp->mad_hdr.method) {
  1788. case IB_MGMT_METHOD_GET:
  1789. switch (pmp->mad_hdr.attr_id) {
  1790. case IB_PMA_CLASS_PORT_INFO:
  1791. ret = pma_get_classportinfo(pmp, ibdev);
  1792. goto bail;
  1793. case IB_PMA_PORT_SAMPLES_CONTROL:
  1794. ret = pma_get_portsamplescontrol(pmp, ibdev, port);
  1795. goto bail;
  1796. case IB_PMA_PORT_SAMPLES_RESULT:
  1797. ret = pma_get_portsamplesresult(pmp, ibdev, port);
  1798. goto bail;
  1799. case IB_PMA_PORT_SAMPLES_RESULT_EXT:
  1800. ret = pma_get_portsamplesresult_ext(pmp, ibdev, port);
  1801. goto bail;
  1802. case IB_PMA_PORT_COUNTERS:
  1803. ret = pma_get_portcounters(pmp, ibdev, port);
  1804. goto bail;
  1805. case IB_PMA_PORT_COUNTERS_EXT:
  1806. ret = pma_get_portcounters_ext(pmp, ibdev, port);
  1807. goto bail;
  1808. case IB_PMA_PORT_COUNTERS_CONG:
  1809. ret = pma_get_portcounters_cong(pmp, ibdev, port);
  1810. goto bail;
  1811. default:
  1812. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  1813. ret = reply((struct ib_smp *) pmp);
  1814. goto bail;
  1815. }
  1816. case IB_MGMT_METHOD_SET:
  1817. switch (pmp->mad_hdr.attr_id) {
  1818. case IB_PMA_PORT_SAMPLES_CONTROL:
  1819. ret = pma_set_portsamplescontrol(pmp, ibdev, port);
  1820. goto bail;
  1821. case IB_PMA_PORT_COUNTERS:
  1822. ret = pma_set_portcounters(pmp, ibdev, port);
  1823. goto bail;
  1824. case IB_PMA_PORT_COUNTERS_EXT:
  1825. ret = pma_set_portcounters_ext(pmp, ibdev, port);
  1826. goto bail;
  1827. case IB_PMA_PORT_COUNTERS_CONG:
  1828. ret = pma_set_portcounters_cong(pmp, ibdev, port);
  1829. goto bail;
  1830. default:
  1831. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  1832. ret = reply((struct ib_smp *) pmp);
  1833. goto bail;
  1834. }
  1835. case IB_MGMT_METHOD_TRAP:
  1836. case IB_MGMT_METHOD_GET_RESP:
  1837. /*
  1838. * The ib_mad module will call us to process responses
  1839. * before checking for other consumers.
  1840. * Just tell the caller to process it normally.
  1841. */
  1842. ret = IB_MAD_RESULT_SUCCESS;
  1843. goto bail;
  1844. default:
  1845. pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
  1846. ret = reply((struct ib_smp *) pmp);
  1847. }
  1848. bail:
  1849. return ret;
  1850. }
  1851. static int cc_get_classportinfo(struct ib_cc_mad *ccp,
  1852. struct ib_device *ibdev)
  1853. {
  1854. struct ib_cc_classportinfo_attr *p =
  1855. (struct ib_cc_classportinfo_attr *)ccp->mgmt_data;
  1856. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1857. p->base_version = 1;
  1858. p->class_version = 1;
  1859. p->cap_mask = 0;
  1860. /*
  1861. * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
  1862. */
  1863. p->resp_time_value = 18;
  1864. return reply((struct ib_smp *) ccp);
  1865. }
  1866. static int cc_get_congestion_info(struct ib_cc_mad *ccp,
  1867. struct ib_device *ibdev, u8 port)
  1868. {
  1869. struct ib_cc_info_attr *p =
  1870. (struct ib_cc_info_attr *)ccp->mgmt_data;
  1871. struct qib_ibport *ibp = to_iport(ibdev, port);
  1872. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1873. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1874. p->congestion_info = 0;
  1875. p->control_table_cap = ppd->cc_max_table_entries;
  1876. return reply((struct ib_smp *) ccp);
  1877. }
  1878. static int cc_get_congestion_setting(struct ib_cc_mad *ccp,
  1879. struct ib_device *ibdev, u8 port)
  1880. {
  1881. int i;
  1882. struct ib_cc_congestion_setting_attr *p =
  1883. (struct ib_cc_congestion_setting_attr *)ccp->mgmt_data;
  1884. struct qib_ibport *ibp = to_iport(ibdev, port);
  1885. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1886. struct ib_cc_congestion_entry_shadow *entries;
  1887. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1888. spin_lock(&ppd->cc_shadow_lock);
  1889. entries = ppd->congestion_entries_shadow->entries;
  1890. p->port_control = cpu_to_be16(
  1891. ppd->congestion_entries_shadow->port_control);
  1892. p->control_map = cpu_to_be16(
  1893. ppd->congestion_entries_shadow->control_map);
  1894. for (i = 0; i < IB_CC_CCS_ENTRIES; i++) {
  1895. p->entries[i].ccti_increase = entries[i].ccti_increase;
  1896. p->entries[i].ccti_timer = cpu_to_be16(entries[i].ccti_timer);
  1897. p->entries[i].trigger_threshold = entries[i].trigger_threshold;
  1898. p->entries[i].ccti_min = entries[i].ccti_min;
  1899. }
  1900. spin_unlock(&ppd->cc_shadow_lock);
  1901. return reply((struct ib_smp *) ccp);
  1902. }
  1903. static int cc_get_congestion_control_table(struct ib_cc_mad *ccp,
  1904. struct ib_device *ibdev, u8 port)
  1905. {
  1906. struct ib_cc_table_attr *p =
  1907. (struct ib_cc_table_attr *)ccp->mgmt_data;
  1908. struct qib_ibport *ibp = to_iport(ibdev, port);
  1909. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1910. u32 cct_block_index = be32_to_cpu(ccp->attr_mod);
  1911. u32 max_cct_block;
  1912. u32 cct_entry;
  1913. struct ib_cc_table_entry_shadow *entries;
  1914. int i;
  1915. /* Is the table index more than what is supported? */
  1916. if (cct_block_index > IB_CC_TABLE_CAP_DEFAULT - 1)
  1917. goto bail;
  1918. memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
  1919. spin_lock(&ppd->cc_shadow_lock);
  1920. max_cct_block =
  1921. (ppd->ccti_entries_shadow->ccti_last_entry + 1)/IB_CCT_ENTRIES;
  1922. max_cct_block = max_cct_block ? max_cct_block - 1 : 0;
  1923. if (cct_block_index > max_cct_block) {
  1924. spin_unlock(&ppd->cc_shadow_lock);
  1925. goto bail;
  1926. }
  1927. ccp->attr_mod = cpu_to_be32(cct_block_index);
  1928. cct_entry = IB_CCT_ENTRIES * (cct_block_index + 1);
  1929. cct_entry--;
  1930. p->ccti_limit = cpu_to_be16(cct_entry);
  1931. entries = &ppd->ccti_entries_shadow->
  1932. entries[IB_CCT_ENTRIES * cct_block_index];
  1933. cct_entry %= IB_CCT_ENTRIES;
  1934. for (i = 0; i <= cct_entry; i++)
  1935. p->ccti_entries[i].entry = cpu_to_be16(entries[i].entry);
  1936. spin_unlock(&ppd->cc_shadow_lock);
  1937. return reply((struct ib_smp *) ccp);
  1938. bail:
  1939. return reply_failure((struct ib_smp *) ccp);
  1940. }
  1941. static int cc_set_congestion_setting(struct ib_cc_mad *ccp,
  1942. struct ib_device *ibdev, u8 port)
  1943. {
  1944. struct ib_cc_congestion_setting_attr *p =
  1945. (struct ib_cc_congestion_setting_attr *)ccp->mgmt_data;
  1946. struct qib_ibport *ibp = to_iport(ibdev, port);
  1947. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1948. int i;
  1949. ppd->cc_sl_control_map = be16_to_cpu(p->control_map);
  1950. for (i = 0; i < IB_CC_CCS_ENTRIES; i++) {
  1951. ppd->congestion_entries[i].ccti_increase =
  1952. p->entries[i].ccti_increase;
  1953. ppd->congestion_entries[i].ccti_timer =
  1954. be16_to_cpu(p->entries[i].ccti_timer);
  1955. ppd->congestion_entries[i].trigger_threshold =
  1956. p->entries[i].trigger_threshold;
  1957. ppd->congestion_entries[i].ccti_min =
  1958. p->entries[i].ccti_min;
  1959. }
  1960. return reply((struct ib_smp *) ccp);
  1961. }
  1962. static int cc_set_congestion_control_table(struct ib_cc_mad *ccp,
  1963. struct ib_device *ibdev, u8 port)
  1964. {
  1965. struct ib_cc_table_attr *p =
  1966. (struct ib_cc_table_attr *)ccp->mgmt_data;
  1967. struct qib_ibport *ibp = to_iport(ibdev, port);
  1968. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1969. u32 cct_block_index = be32_to_cpu(ccp->attr_mod);
  1970. u32 cct_entry;
  1971. struct ib_cc_table_entry_shadow *entries;
  1972. int i;
  1973. /* Is the table index more than what is supported? */
  1974. if (cct_block_index > IB_CC_TABLE_CAP_DEFAULT - 1)
  1975. goto bail;
  1976. /* If this packet is the first in the sequence then
  1977. * zero the total table entry count.
  1978. */
  1979. if (be16_to_cpu(p->ccti_limit) < IB_CCT_ENTRIES)
  1980. ppd->total_cct_entry = 0;
  1981. cct_entry = (be16_to_cpu(p->ccti_limit))%IB_CCT_ENTRIES;
  1982. /* ccti_limit is 0 to 63 */
  1983. ppd->total_cct_entry += (cct_entry + 1);
  1984. if (ppd->total_cct_entry > ppd->cc_supported_table_entries)
  1985. goto bail;
  1986. ppd->ccti_limit = be16_to_cpu(p->ccti_limit);
  1987. entries = ppd->ccti_entries + (IB_CCT_ENTRIES * cct_block_index);
  1988. for (i = 0; i <= cct_entry; i++)
  1989. entries[i].entry = be16_to_cpu(p->ccti_entries[i].entry);
  1990. spin_lock(&ppd->cc_shadow_lock);
  1991. ppd->ccti_entries_shadow->ccti_last_entry = ppd->total_cct_entry - 1;
  1992. memcpy(ppd->ccti_entries_shadow->entries, ppd->ccti_entries,
  1993. (ppd->total_cct_entry * sizeof(struct ib_cc_table_entry)));
  1994. ppd->congestion_entries_shadow->port_control = IB_CC_CCS_PC_SL_BASED;
  1995. ppd->congestion_entries_shadow->control_map = ppd->cc_sl_control_map;
  1996. memcpy(ppd->congestion_entries_shadow->entries, ppd->congestion_entries,
  1997. IB_CC_CCS_ENTRIES * sizeof(struct ib_cc_congestion_entry));
  1998. spin_unlock(&ppd->cc_shadow_lock);
  1999. return reply((struct ib_smp *) ccp);
  2000. bail:
  2001. return reply_failure((struct ib_smp *) ccp);
  2002. }
  2003. static int check_cc_key(struct qib_ibport *ibp,
  2004. struct ib_cc_mad *ccp, int mad_flags)
  2005. {
  2006. return 0;
  2007. }
  2008. static int process_cc(struct ib_device *ibdev, int mad_flags,
  2009. u8 port, const struct ib_mad *in_mad,
  2010. struct ib_mad *out_mad)
  2011. {
  2012. struct ib_cc_mad *ccp = (struct ib_cc_mad *)out_mad;
  2013. struct qib_ibport *ibp = to_iport(ibdev, port);
  2014. int ret;
  2015. *out_mad = *in_mad;
  2016. if (ccp->class_version != 2) {
  2017. ccp->status |= IB_SMP_UNSUP_VERSION;
  2018. ret = reply((struct ib_smp *)ccp);
  2019. goto bail;
  2020. }
  2021. ret = check_cc_key(ibp, ccp, mad_flags);
  2022. if (ret)
  2023. goto bail;
  2024. switch (ccp->method) {
  2025. case IB_MGMT_METHOD_GET:
  2026. switch (ccp->attr_id) {
  2027. case IB_CC_ATTR_CLASSPORTINFO:
  2028. ret = cc_get_classportinfo(ccp, ibdev);
  2029. goto bail;
  2030. case IB_CC_ATTR_CONGESTION_INFO:
  2031. ret = cc_get_congestion_info(ccp, ibdev, port);
  2032. goto bail;
  2033. case IB_CC_ATTR_CA_CONGESTION_SETTING:
  2034. ret = cc_get_congestion_setting(ccp, ibdev, port);
  2035. goto bail;
  2036. case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
  2037. ret = cc_get_congestion_control_table(ccp, ibdev, port);
  2038. goto bail;
  2039. /* FALLTHROUGH */
  2040. default:
  2041. ccp->status |= IB_SMP_UNSUP_METH_ATTR;
  2042. ret = reply((struct ib_smp *) ccp);
  2043. goto bail;
  2044. }
  2045. case IB_MGMT_METHOD_SET:
  2046. switch (ccp->attr_id) {
  2047. case IB_CC_ATTR_CA_CONGESTION_SETTING:
  2048. ret = cc_set_congestion_setting(ccp, ibdev, port);
  2049. goto bail;
  2050. case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
  2051. ret = cc_set_congestion_control_table(ccp, ibdev, port);
  2052. goto bail;
  2053. /* FALLTHROUGH */
  2054. default:
  2055. ccp->status |= IB_SMP_UNSUP_METH_ATTR;
  2056. ret = reply((struct ib_smp *) ccp);
  2057. goto bail;
  2058. }
  2059. case IB_MGMT_METHOD_GET_RESP:
  2060. /*
  2061. * The ib_mad module will call us to process responses
  2062. * before checking for other consumers.
  2063. * Just tell the caller to process it normally.
  2064. */
  2065. ret = IB_MAD_RESULT_SUCCESS;
  2066. goto bail;
  2067. case IB_MGMT_METHOD_TRAP:
  2068. default:
  2069. ccp->status |= IB_SMP_UNSUP_METHOD;
  2070. ret = reply((struct ib_smp *) ccp);
  2071. }
  2072. bail:
  2073. return ret;
  2074. }
  2075. /**
  2076. * qib_process_mad - process an incoming MAD packet
  2077. * @ibdev: the infiniband device this packet came in on
  2078. * @mad_flags: MAD flags
  2079. * @port: the port number this packet came in on
  2080. * @in_wc: the work completion entry for this packet
  2081. * @in_grh: the global route header for this packet
  2082. * @in_mad: the incoming MAD
  2083. * @out_mad: any outgoing MAD reply
  2084. *
  2085. * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
  2086. * interested in processing.
  2087. *
  2088. * Note that the verbs framework has already done the MAD sanity checks,
  2089. * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  2090. * MADs.
  2091. *
  2092. * This is called by the ib_mad module.
  2093. */
  2094. int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
  2095. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  2096. const struct ib_mad_hdr *in, size_t in_mad_size,
  2097. struct ib_mad_hdr *out, size_t *out_mad_size,
  2098. u16 *out_mad_pkey_index)
  2099. {
  2100. int ret;
  2101. struct qib_ibport *ibp = to_iport(ibdev, port);
  2102. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  2103. const struct ib_mad *in_mad = (const struct ib_mad *)in;
  2104. struct ib_mad *out_mad = (struct ib_mad *)out;
  2105. if (WARN_ON_ONCE(in_mad_size != sizeof(*in_mad) ||
  2106. *out_mad_size != sizeof(*out_mad)))
  2107. return IB_MAD_RESULT_FAILURE;
  2108. switch (in_mad->mad_hdr.mgmt_class) {
  2109. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  2110. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  2111. ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad);
  2112. goto bail;
  2113. case IB_MGMT_CLASS_PERF_MGMT:
  2114. ret = process_perf(ibdev, port, in_mad, out_mad);
  2115. goto bail;
  2116. case IB_MGMT_CLASS_CONG_MGMT:
  2117. if (!ppd->congestion_entries_shadow ||
  2118. !qib_cc_table_size) {
  2119. ret = IB_MAD_RESULT_SUCCESS;
  2120. goto bail;
  2121. }
  2122. ret = process_cc(ibdev, mad_flags, port, in_mad, out_mad);
  2123. goto bail;
  2124. default:
  2125. ret = IB_MAD_RESULT_SUCCESS;
  2126. }
  2127. bail:
  2128. return ret;
  2129. }
  2130. static void xmit_wait_timer_func(struct timer_list *t)
  2131. {
  2132. struct qib_pportdata *ppd = from_timer(ppd, t, cong_stats.timer);
  2133. struct qib_devdata *dd = dd_from_ppd(ppd);
  2134. unsigned long flags;
  2135. u8 status;
  2136. spin_lock_irqsave(&ppd->ibport_data.rvp.lock, flags);
  2137. if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_SAMPLE) {
  2138. status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
  2139. if (status == IB_PMA_SAMPLE_STATUS_DONE) {
  2140. /* save counter cache */
  2141. cache_hw_sample_counters(ppd);
  2142. ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
  2143. } else
  2144. goto done;
  2145. }
  2146. ppd->cong_stats.counter = xmit_wait_get_value_delta(ppd);
  2147. dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, 0x0);
  2148. done:
  2149. spin_unlock_irqrestore(&ppd->ibport_data.rvp.lock, flags);
  2150. mod_timer(&ppd->cong_stats.timer, jiffies + HZ);
  2151. }
  2152. void qib_notify_create_mad_agent(struct rvt_dev_info *rdi, int port_idx)
  2153. {
  2154. struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
  2155. struct qib_devdata *dd = container_of(ibdev,
  2156. struct qib_devdata, verbs_dev);
  2157. /* Initialize xmit_wait structure */
  2158. dd->pport[port_idx].cong_stats.counter = 0;
  2159. timer_setup(&dd->pport[port_idx].cong_stats.timer,
  2160. xmit_wait_timer_func, 0);
  2161. dd->pport[port_idx].cong_stats.timer.expires = 0;
  2162. add_timer(&dd->pport[port_idx].cong_stats.timer);
  2163. }
  2164. void qib_notify_free_mad_agent(struct rvt_dev_info *rdi, int port_idx)
  2165. {
  2166. struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
  2167. struct qib_devdata *dd = container_of(ibdev,
  2168. struct qib_devdata, verbs_dev);
  2169. if (dd->pport[port_idx].cong_stats.timer.function)
  2170. del_timer_sync(&dd->pport[port_idx].cong_stats.timer);
  2171. if (dd->pport[port_idx].ibport_data.smi_ah)
  2172. rdma_destroy_ah(&dd->pport[port_idx].ibport_data.smi_ah->ibah);
  2173. }