ipath_verbs.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /*
  2. * Copyright (c) 2006 QLogic, Inc. All rights reserved.
  3. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <rdma/ib_mad.h>
  34. #include <rdma/ib_user_verbs.h>
  35. #include <linux/io.h>
  36. #include <linux/utsname.h>
  37. #include "ipath_kernel.h"
  38. #include "ipath_verbs.h"
  39. #include "ipath_common.h"
  40. static unsigned int ib_ipath_qp_table_size = 251;
  41. module_param_named(qp_table_size, ib_ipath_qp_table_size, uint, S_IRUGO);
  42. MODULE_PARM_DESC(qp_table_size, "QP table size");
  43. unsigned int ib_ipath_lkey_table_size = 12;
  44. module_param_named(lkey_table_size, ib_ipath_lkey_table_size, uint,
  45. S_IRUGO);
  46. MODULE_PARM_DESC(lkey_table_size,
  47. "LKEY table size in bits (2^n, 1 <= n <= 23)");
  48. static unsigned int ib_ipath_max_pds = 0xFFFF;
  49. module_param_named(max_pds, ib_ipath_max_pds, uint, S_IWUSR | S_IRUGO);
  50. MODULE_PARM_DESC(max_pds,
  51. "Maximum number of protection domains to support");
  52. static unsigned int ib_ipath_max_ahs = 0xFFFF;
  53. module_param_named(max_ahs, ib_ipath_max_ahs, uint, S_IWUSR | S_IRUGO);
  54. MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
  55. unsigned int ib_ipath_max_cqes = 0x2FFFF;
  56. module_param_named(max_cqes, ib_ipath_max_cqes, uint, S_IWUSR | S_IRUGO);
  57. MODULE_PARM_DESC(max_cqes,
  58. "Maximum number of completion queue entries to support");
  59. unsigned int ib_ipath_max_cqs = 0x1FFFF;
  60. module_param_named(max_cqs, ib_ipath_max_cqs, uint, S_IWUSR | S_IRUGO);
  61. MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
  62. unsigned int ib_ipath_max_qp_wrs = 0x3FFF;
  63. module_param_named(max_qp_wrs, ib_ipath_max_qp_wrs, uint,
  64. S_IWUSR | S_IRUGO);
  65. MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
  66. unsigned int ib_ipath_max_sges = 0x60;
  67. module_param_named(max_sges, ib_ipath_max_sges, uint, S_IWUSR | S_IRUGO);
  68. MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
  69. unsigned int ib_ipath_max_mcast_grps = 16384;
  70. module_param_named(max_mcast_grps, ib_ipath_max_mcast_grps, uint,
  71. S_IWUSR | S_IRUGO);
  72. MODULE_PARM_DESC(max_mcast_grps,
  73. "Maximum number of multicast groups to support");
  74. unsigned int ib_ipath_max_mcast_qp_attached = 16;
  75. module_param_named(max_mcast_qp_attached, ib_ipath_max_mcast_qp_attached,
  76. uint, S_IWUSR | S_IRUGO);
  77. MODULE_PARM_DESC(max_mcast_qp_attached,
  78. "Maximum number of attached QPs to support");
  79. unsigned int ib_ipath_max_srqs = 1024;
  80. module_param_named(max_srqs, ib_ipath_max_srqs, uint, S_IWUSR | S_IRUGO);
  81. MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
  82. unsigned int ib_ipath_max_srq_sges = 128;
  83. module_param_named(max_srq_sges, ib_ipath_max_srq_sges,
  84. uint, S_IWUSR | S_IRUGO);
  85. MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
  86. unsigned int ib_ipath_max_srq_wrs = 0x1FFFF;
  87. module_param_named(max_srq_wrs, ib_ipath_max_srq_wrs,
  88. uint, S_IWUSR | S_IRUGO);
  89. MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
  90. const int ib_ipath_state_ops[IB_QPS_ERR + 1] = {
  91. [IB_QPS_RESET] = 0,
  92. [IB_QPS_INIT] = IPATH_POST_RECV_OK,
  93. [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
  94. [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
  95. IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK,
  96. [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
  97. IPATH_POST_SEND_OK,
  98. [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
  99. [IB_QPS_ERR] = 0,
  100. };
  101. struct ipath_ucontext {
  102. struct ib_ucontext ibucontext;
  103. };
  104. static inline struct ipath_ucontext *to_iucontext(struct ib_ucontext
  105. *ibucontext)
  106. {
  107. return container_of(ibucontext, struct ipath_ucontext, ibucontext);
  108. }
  109. /*
  110. * Translate ib_wr_opcode into ib_wc_opcode.
  111. */
  112. const enum ib_wc_opcode ib_ipath_wc_opcode[] = {
  113. [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
  114. [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
  115. [IB_WR_SEND] = IB_WC_SEND,
  116. [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
  117. [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
  118. [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
  119. [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
  120. };
  121. /*
  122. * System image GUID.
  123. */
  124. static __be64 sys_image_guid;
  125. /**
  126. * ipath_copy_sge - copy data to SGE memory
  127. * @ss: the SGE state
  128. * @data: the data to copy
  129. * @length: the length of the data
  130. */
  131. void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length)
  132. {
  133. struct ipath_sge *sge = &ss->sge;
  134. while (length) {
  135. u32 len = sge->length;
  136. BUG_ON(len == 0);
  137. if (len > length)
  138. len = length;
  139. memcpy(sge->vaddr, data, len);
  140. sge->vaddr += len;
  141. sge->length -= len;
  142. sge->sge_length -= len;
  143. if (sge->sge_length == 0) {
  144. if (--ss->num_sge)
  145. *sge = *ss->sg_list++;
  146. } else if (sge->length == 0 && sge->mr != NULL) {
  147. if (++sge->n >= IPATH_SEGSZ) {
  148. if (++sge->m >= sge->mr->mapsz)
  149. break;
  150. sge->n = 0;
  151. }
  152. sge->vaddr =
  153. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  154. sge->length =
  155. sge->mr->map[sge->m]->segs[sge->n].length;
  156. }
  157. data += len;
  158. length -= len;
  159. }
  160. }
  161. /**
  162. * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func
  163. * @ss: the SGE state
  164. * @length: the number of bytes to skip
  165. */
  166. void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
  167. {
  168. struct ipath_sge *sge = &ss->sge;
  169. while (length) {
  170. u32 len = sge->length;
  171. BUG_ON(len == 0);
  172. if (len > length)
  173. len = length;
  174. sge->vaddr += len;
  175. sge->length -= len;
  176. sge->sge_length -= len;
  177. if (sge->sge_length == 0) {
  178. if (--ss->num_sge)
  179. *sge = *ss->sg_list++;
  180. } else if (sge->length == 0 && sge->mr != NULL) {
  181. if (++sge->n >= IPATH_SEGSZ) {
  182. if (++sge->m >= sge->mr->mapsz)
  183. break;
  184. sge->n = 0;
  185. }
  186. sge->vaddr =
  187. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  188. sge->length =
  189. sge->mr->map[sge->m]->segs[sge->n].length;
  190. }
  191. length -= len;
  192. }
  193. }
  194. /**
  195. * ipath_post_send - post a send on a QP
  196. * @ibqp: the QP to post the send on
  197. * @wr: the list of work requests to post
  198. * @bad_wr: the first bad WR is put here
  199. *
  200. * This may be called from interrupt context.
  201. */
  202. static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  203. struct ib_send_wr **bad_wr)
  204. {
  205. struct ipath_qp *qp = to_iqp(ibqp);
  206. int err = 0;
  207. /* Check that state is OK to post send. */
  208. if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)) {
  209. *bad_wr = wr;
  210. err = -EINVAL;
  211. goto bail;
  212. }
  213. for (; wr; wr = wr->next) {
  214. switch (qp->ibqp.qp_type) {
  215. case IB_QPT_UC:
  216. case IB_QPT_RC:
  217. err = ipath_post_ruc_send(qp, wr);
  218. break;
  219. case IB_QPT_SMI:
  220. case IB_QPT_GSI:
  221. case IB_QPT_UD:
  222. err = ipath_post_ud_send(qp, wr);
  223. break;
  224. default:
  225. err = -EINVAL;
  226. }
  227. if (err) {
  228. *bad_wr = wr;
  229. break;
  230. }
  231. }
  232. bail:
  233. return err;
  234. }
  235. /**
  236. * ipath_post_receive - post a receive on a QP
  237. * @ibqp: the QP to post the receive on
  238. * @wr: the WR to post
  239. * @bad_wr: the first bad WR is put here
  240. *
  241. * This may be called from interrupt context.
  242. */
  243. static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  244. struct ib_recv_wr **bad_wr)
  245. {
  246. struct ipath_qp *qp = to_iqp(ibqp);
  247. struct ipath_rwq *wq = qp->r_rq.wq;
  248. unsigned long flags;
  249. int ret;
  250. /* Check that state is OK to post receive. */
  251. if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK) || !wq) {
  252. *bad_wr = wr;
  253. ret = -EINVAL;
  254. goto bail;
  255. }
  256. for (; wr; wr = wr->next) {
  257. struct ipath_rwqe *wqe;
  258. u32 next;
  259. int i;
  260. if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
  261. *bad_wr = wr;
  262. ret = -ENOMEM;
  263. goto bail;
  264. }
  265. spin_lock_irqsave(&qp->r_rq.lock, flags);
  266. next = wq->head + 1;
  267. if (next >= qp->r_rq.size)
  268. next = 0;
  269. if (next == wq->tail) {
  270. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  271. *bad_wr = wr;
  272. ret = -ENOMEM;
  273. goto bail;
  274. }
  275. wqe = get_rwqe_ptr(&qp->r_rq, wq->head);
  276. wqe->wr_id = wr->wr_id;
  277. wqe->num_sge = wr->num_sge;
  278. for (i = 0; i < wr->num_sge; i++)
  279. wqe->sg_list[i] = wr->sg_list[i];
  280. wq->head = next;
  281. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  282. }
  283. ret = 0;
  284. bail:
  285. return ret;
  286. }
  287. /**
  288. * ipath_qp_rcv - processing an incoming packet on a QP
  289. * @dev: the device the packet came on
  290. * @hdr: the packet header
  291. * @has_grh: true if the packet has a GRH
  292. * @data: the packet data
  293. * @tlen: the packet length
  294. * @qp: the QP the packet came on
  295. *
  296. * This is called from ipath_ib_rcv() to process an incoming packet
  297. * for the given QP.
  298. * Called at interrupt level.
  299. */
  300. static void ipath_qp_rcv(struct ipath_ibdev *dev,
  301. struct ipath_ib_header *hdr, int has_grh,
  302. void *data, u32 tlen, struct ipath_qp *qp)
  303. {
  304. /* Check for valid receive state. */
  305. if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {
  306. dev->n_pkt_drops++;
  307. return;
  308. }
  309. switch (qp->ibqp.qp_type) {
  310. case IB_QPT_SMI:
  311. case IB_QPT_GSI:
  312. case IB_QPT_UD:
  313. ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp);
  314. break;
  315. case IB_QPT_RC:
  316. ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp);
  317. break;
  318. case IB_QPT_UC:
  319. ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp);
  320. break;
  321. default:
  322. break;
  323. }
  324. }
  325. /**
  326. * ipath_ib_rcv - process an incoming packet
  327. * @arg: the device pointer
  328. * @rhdr: the header of the packet
  329. * @data: the packet data
  330. * @tlen: the packet length
  331. *
  332. * This is called from ipath_kreceive() to process an incoming packet at
  333. * interrupt level. Tlen is the length of the header + data + CRC in bytes.
  334. */
  335. void ipath_ib_rcv(struct ipath_ibdev *dev, void *rhdr, void *data,
  336. u32 tlen)
  337. {
  338. struct ipath_ib_header *hdr = rhdr;
  339. struct ipath_other_headers *ohdr;
  340. struct ipath_qp *qp;
  341. u32 qp_num;
  342. int lnh;
  343. u8 opcode;
  344. u16 lid;
  345. if (unlikely(dev == NULL))
  346. goto bail;
  347. if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */
  348. dev->rcv_errors++;
  349. goto bail;
  350. }
  351. /* Check for a valid destination LID (see ch. 7.11.1). */
  352. lid = be16_to_cpu(hdr->lrh[1]);
  353. if (lid < IPATH_MULTICAST_LID_BASE) {
  354. lid &= ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
  355. if (unlikely(lid != dev->dd->ipath_lid)) {
  356. dev->rcv_errors++;
  357. goto bail;
  358. }
  359. }
  360. /* Check for GRH */
  361. lnh = be16_to_cpu(hdr->lrh[0]) & 3;
  362. if (lnh == IPATH_LRH_BTH)
  363. ohdr = &hdr->u.oth;
  364. else if (lnh == IPATH_LRH_GRH)
  365. ohdr = &hdr->u.l.oth;
  366. else {
  367. dev->rcv_errors++;
  368. goto bail;
  369. }
  370. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  371. dev->opstats[opcode].n_bytes += tlen;
  372. dev->opstats[opcode].n_packets++;
  373. /* Get the destination QP number. */
  374. qp_num = be32_to_cpu(ohdr->bth[1]) & IPATH_QPN_MASK;
  375. if (qp_num == IPATH_MULTICAST_QPN) {
  376. struct ipath_mcast *mcast;
  377. struct ipath_mcast_qp *p;
  378. mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
  379. if (mcast == NULL) {
  380. dev->n_pkt_drops++;
  381. goto bail;
  382. }
  383. dev->n_multicast_rcv++;
  384. list_for_each_entry_rcu(p, &mcast->qp_list, list)
  385. ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data,
  386. tlen, p->qp);
  387. /*
  388. * Notify ipath_multicast_detach() if it is waiting for us
  389. * to finish.
  390. */
  391. if (atomic_dec_return(&mcast->refcount) <= 1)
  392. wake_up(&mcast->wait);
  393. } else {
  394. qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
  395. if (qp) {
  396. dev->n_unicast_rcv++;
  397. ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data,
  398. tlen, qp);
  399. /*
  400. * Notify ipath_destroy_qp() if it is waiting
  401. * for us to finish.
  402. */
  403. if (atomic_dec_and_test(&qp->refcount))
  404. wake_up(&qp->wait);
  405. } else
  406. dev->n_pkt_drops++;
  407. }
  408. bail:;
  409. }
  410. /**
  411. * ipath_ib_timer - verbs timer
  412. * @arg: the device pointer
  413. *
  414. * This is called from ipath_do_rcv_timer() at interrupt level to check for
  415. * QPs which need retransmits and to collect performance numbers.
  416. */
  417. void ipath_ib_timer(struct ipath_ibdev *dev)
  418. {
  419. struct ipath_qp *resend = NULL;
  420. struct list_head *last;
  421. struct ipath_qp *qp;
  422. unsigned long flags;
  423. if (dev == NULL)
  424. return;
  425. spin_lock_irqsave(&dev->pending_lock, flags);
  426. /* Start filling the next pending queue. */
  427. if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
  428. dev->pending_index = 0;
  429. /* Save any requests still in the new queue, they have timed out. */
  430. last = &dev->pending[dev->pending_index];
  431. while (!list_empty(last)) {
  432. qp = list_entry(last->next, struct ipath_qp, timerwait);
  433. list_del_init(&qp->timerwait);
  434. qp->timer_next = resend;
  435. resend = qp;
  436. atomic_inc(&qp->refcount);
  437. }
  438. last = &dev->rnrwait;
  439. if (!list_empty(last)) {
  440. qp = list_entry(last->next, struct ipath_qp, timerwait);
  441. if (--qp->s_rnr_timeout == 0) {
  442. do {
  443. list_del_init(&qp->timerwait);
  444. tasklet_hi_schedule(&qp->s_task);
  445. if (list_empty(last))
  446. break;
  447. qp = list_entry(last->next, struct ipath_qp,
  448. timerwait);
  449. } while (qp->s_rnr_timeout == 0);
  450. }
  451. }
  452. /*
  453. * We should only be in the started state if pma_sample_start != 0
  454. */
  455. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
  456. --dev->pma_sample_start == 0) {
  457. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  458. ipath_snapshot_counters(dev->dd, &dev->ipath_sword,
  459. &dev->ipath_rword,
  460. &dev->ipath_spkts,
  461. &dev->ipath_rpkts,
  462. &dev->ipath_xmit_wait);
  463. }
  464. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
  465. if (dev->pma_sample_interval == 0) {
  466. u64 ta, tb, tc, td, te;
  467. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  468. ipath_snapshot_counters(dev->dd, &ta, &tb,
  469. &tc, &td, &te);
  470. dev->ipath_sword = ta - dev->ipath_sword;
  471. dev->ipath_rword = tb - dev->ipath_rword;
  472. dev->ipath_spkts = tc - dev->ipath_spkts;
  473. dev->ipath_rpkts = td - dev->ipath_rpkts;
  474. dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
  475. }
  476. else
  477. dev->pma_sample_interval--;
  478. }
  479. spin_unlock_irqrestore(&dev->pending_lock, flags);
  480. /* XXX What if timer fires again while this is running? */
  481. for (qp = resend; qp != NULL; qp = qp->timer_next) {
  482. struct ib_wc wc;
  483. spin_lock_irqsave(&qp->s_lock, flags);
  484. if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) {
  485. dev->n_timeouts++;
  486. ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
  487. }
  488. spin_unlock_irqrestore(&qp->s_lock, flags);
  489. /* Notify ipath_destroy_qp() if it is waiting. */
  490. if (atomic_dec_and_test(&qp->refcount))
  491. wake_up(&qp->wait);
  492. }
  493. }
  494. static void update_sge(struct ipath_sge_state *ss, u32 length)
  495. {
  496. struct ipath_sge *sge = &ss->sge;
  497. sge->vaddr += length;
  498. sge->length -= length;
  499. sge->sge_length -= length;
  500. if (sge->sge_length == 0) {
  501. if (--ss->num_sge)
  502. *sge = *ss->sg_list++;
  503. } else if (sge->length == 0 && sge->mr != NULL) {
  504. if (++sge->n >= IPATH_SEGSZ) {
  505. if (++sge->m >= sge->mr->mapsz)
  506. return;
  507. sge->n = 0;
  508. }
  509. sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
  510. sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
  511. }
  512. }
  513. #ifdef __LITTLE_ENDIAN
  514. static inline u32 get_upper_bits(u32 data, u32 shift)
  515. {
  516. return data >> shift;
  517. }
  518. static inline u32 set_upper_bits(u32 data, u32 shift)
  519. {
  520. return data << shift;
  521. }
  522. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  523. {
  524. data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
  525. data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  526. return data;
  527. }
  528. #else
  529. static inline u32 get_upper_bits(u32 data, u32 shift)
  530. {
  531. return data << shift;
  532. }
  533. static inline u32 set_upper_bits(u32 data, u32 shift)
  534. {
  535. return data >> shift;
  536. }
  537. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  538. {
  539. data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
  540. data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  541. return data;
  542. }
  543. #endif
  544. static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
  545. u32 length)
  546. {
  547. u32 extra = 0;
  548. u32 data = 0;
  549. u32 last;
  550. while (1) {
  551. u32 len = ss->sge.length;
  552. u32 off;
  553. BUG_ON(len == 0);
  554. if (len > length)
  555. len = length;
  556. if (len > ss->sge.sge_length)
  557. len = ss->sge.sge_length;
  558. /* If the source address is not aligned, try to align it. */
  559. off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
  560. if (off) {
  561. u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
  562. ~(sizeof(u32) - 1));
  563. u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
  564. u32 y;
  565. y = sizeof(u32) - off;
  566. if (len > y)
  567. len = y;
  568. if (len + extra >= sizeof(u32)) {
  569. data |= set_upper_bits(v, extra *
  570. BITS_PER_BYTE);
  571. len = sizeof(u32) - extra;
  572. if (len == length) {
  573. last = data;
  574. break;
  575. }
  576. __raw_writel(data, piobuf);
  577. piobuf++;
  578. extra = 0;
  579. data = 0;
  580. } else {
  581. /* Clear unused upper bytes */
  582. data |= clear_upper_bytes(v, len, extra);
  583. if (len == length) {
  584. last = data;
  585. break;
  586. }
  587. extra += len;
  588. }
  589. } else if (extra) {
  590. /* Source address is aligned. */
  591. u32 *addr = (u32 *) ss->sge.vaddr;
  592. int shift = extra * BITS_PER_BYTE;
  593. int ushift = 32 - shift;
  594. u32 l = len;
  595. while (l >= sizeof(u32)) {
  596. u32 v = *addr;
  597. data |= set_upper_bits(v, shift);
  598. __raw_writel(data, piobuf);
  599. data = get_upper_bits(v, ushift);
  600. piobuf++;
  601. addr++;
  602. l -= sizeof(u32);
  603. }
  604. /*
  605. * We still have 'extra' number of bytes leftover.
  606. */
  607. if (l) {
  608. u32 v = *addr;
  609. if (l + extra >= sizeof(u32)) {
  610. data |= set_upper_bits(v, shift);
  611. len -= l + extra - sizeof(u32);
  612. if (len == length) {
  613. last = data;
  614. break;
  615. }
  616. __raw_writel(data, piobuf);
  617. piobuf++;
  618. extra = 0;
  619. data = 0;
  620. } else {
  621. /* Clear unused upper bytes */
  622. data |= clear_upper_bytes(v, l,
  623. extra);
  624. if (len == length) {
  625. last = data;
  626. break;
  627. }
  628. extra += l;
  629. }
  630. } else if (len == length) {
  631. last = data;
  632. break;
  633. }
  634. } else if (len == length) {
  635. u32 w;
  636. /*
  637. * Need to round up for the last dword in the
  638. * packet.
  639. */
  640. w = (len + 3) >> 2;
  641. __iowrite32_copy(piobuf, ss->sge.vaddr, w - 1);
  642. piobuf += w - 1;
  643. last = ((u32 *) ss->sge.vaddr)[w - 1];
  644. break;
  645. } else {
  646. u32 w = len >> 2;
  647. __iowrite32_copy(piobuf, ss->sge.vaddr, w);
  648. piobuf += w;
  649. extra = len & (sizeof(u32) - 1);
  650. if (extra) {
  651. u32 v = ((u32 *) ss->sge.vaddr)[w];
  652. /* Clear unused upper bytes */
  653. data = clear_upper_bytes(v, extra, 0);
  654. }
  655. }
  656. update_sge(ss, len);
  657. length -= len;
  658. }
  659. /* Update address before sending packet. */
  660. update_sge(ss, length);
  661. /* must flush early everything before trigger word */
  662. ipath_flush_wc();
  663. __raw_writel(last, piobuf);
  664. /* be sure trigger word is written */
  665. ipath_flush_wc();
  666. }
  667. /**
  668. * ipath_verbs_send - send a packet
  669. * @dd: the infinipath device
  670. * @hdrwords: the number of words in the header
  671. * @hdr: the packet header
  672. * @len: the length of the packet in bytes
  673. * @ss: the SGE to send
  674. */
  675. int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
  676. u32 *hdr, u32 len, struct ipath_sge_state *ss)
  677. {
  678. u32 __iomem *piobuf;
  679. u32 plen;
  680. int ret;
  681. /* +1 is for the qword padding of pbc */
  682. plen = hdrwords + ((len + 3) >> 2) + 1;
  683. if (unlikely((plen << 2) > dd->ipath_ibmaxlen)) {
  684. ipath_dbg("packet len 0x%x too long, failing\n", plen);
  685. ret = -EINVAL;
  686. goto bail;
  687. }
  688. /* Get a PIO buffer to use. */
  689. piobuf = ipath_getpiobuf(dd, NULL);
  690. if (unlikely(piobuf == NULL)) {
  691. ret = -EBUSY;
  692. goto bail;
  693. }
  694. /*
  695. * Write len to control qword, no flags.
  696. * We have to flush after the PBC for correctness on some cpus
  697. * or WC buffer can be written out of order.
  698. */
  699. writeq(plen, piobuf);
  700. ipath_flush_wc();
  701. piobuf += 2;
  702. if (len == 0) {
  703. /*
  704. * If there is just the header portion, must flush before
  705. * writing last word of header for correctness, and after
  706. * the last header word (trigger word).
  707. */
  708. __iowrite32_copy(piobuf, hdr, hdrwords - 1);
  709. ipath_flush_wc();
  710. __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
  711. ipath_flush_wc();
  712. ret = 0;
  713. goto bail;
  714. }
  715. __iowrite32_copy(piobuf, hdr, hdrwords);
  716. piobuf += hdrwords;
  717. /* The common case is aligned and contained in one segment. */
  718. if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
  719. !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
  720. u32 w;
  721. u32 *addr = (u32 *) ss->sge.vaddr;
  722. /* Update address before sending packet. */
  723. update_sge(ss, len);
  724. /* Need to round up for the last dword in the packet. */
  725. w = (len + 3) >> 2;
  726. __iowrite32_copy(piobuf, addr, w - 1);
  727. /* must flush early everything before trigger word */
  728. ipath_flush_wc();
  729. __raw_writel(addr[w - 1], piobuf + w - 1);
  730. /* be sure trigger word is written */
  731. ipath_flush_wc();
  732. ret = 0;
  733. goto bail;
  734. }
  735. copy_io(piobuf, ss, len);
  736. ret = 0;
  737. bail:
  738. return ret;
  739. }
  740. int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
  741. u64 *rwords, u64 *spkts, u64 *rpkts,
  742. u64 *xmit_wait)
  743. {
  744. int ret;
  745. if (!(dd->ipath_flags & IPATH_INITTED)) {
  746. /* no hardware, freeze, etc. */
  747. ipath_dbg("unit %u not usable\n", dd->ipath_unit);
  748. ret = -EINVAL;
  749. goto bail;
  750. }
  751. *swords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  752. *rwords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  753. *spkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  754. *rpkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  755. *xmit_wait = ipath_snap_cntr(dd, dd->ipath_cregs->cr_sendstallcnt);
  756. ret = 0;
  757. bail:
  758. return ret;
  759. }
  760. /**
  761. * ipath_get_counters - get various chip counters
  762. * @dd: the infinipath device
  763. * @cntrs: counters are placed here
  764. *
  765. * Return the counters needed by recv_pma_get_portcounters().
  766. */
  767. int ipath_get_counters(struct ipath_devdata *dd,
  768. struct ipath_verbs_counters *cntrs)
  769. {
  770. int ret;
  771. if (!(dd->ipath_flags & IPATH_INITTED)) {
  772. /* no hardware, freeze, etc. */
  773. ipath_dbg("unit %u not usable\n", dd->ipath_unit);
  774. ret = -EINVAL;
  775. goto bail;
  776. }
  777. cntrs->symbol_error_counter =
  778. ipath_snap_cntr(dd, dd->ipath_cregs->cr_ibsymbolerrcnt);
  779. cntrs->link_error_recovery_counter =
  780. ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt);
  781. /*
  782. * The link downed counter counts when the other side downs the
  783. * connection. We add in the number of times we downed the link
  784. * due to local link integrity errors to compensate.
  785. */
  786. cntrs->link_downed_counter =
  787. ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkdowncnt);
  788. cntrs->port_rcv_errors =
  789. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rxdroppktcnt) +
  790. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvovflcnt) +
  791. ipath_snap_cntr(dd, dd->ipath_cregs->cr_portovflcnt) +
  792. ipath_snap_cntr(dd, dd->ipath_cregs->cr_err_rlencnt) +
  793. ipath_snap_cntr(dd, dd->ipath_cregs->cr_invalidrlencnt) +
  794. ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) +
  795. ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) +
  796. ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) +
  797. ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt);
  798. cntrs->port_rcv_remphys_errors =
  799. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt);
  800. cntrs->port_xmit_discards =
  801. ipath_snap_cntr(dd, dd->ipath_cregs->cr_unsupvlcnt);
  802. cntrs->port_xmit_data =
  803. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  804. cntrs->port_rcv_data =
  805. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  806. cntrs->port_xmit_packets =
  807. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  808. cntrs->port_rcv_packets =
  809. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  810. cntrs->local_link_integrity_errors = dd->ipath_lli_errors;
  811. cntrs->excessive_buffer_overrun_errors = 0; /* XXX */
  812. ret = 0;
  813. bail:
  814. return ret;
  815. }
  816. /**
  817. * ipath_ib_piobufavail - callback when a PIO buffer is available
  818. * @arg: the device pointer
  819. *
  820. * This is called from ipath_intr() at interrupt level when a PIO buffer is
  821. * available after ipath_verbs_send() returned an error that no buffers were
  822. * available. Return 1 if we consumed all the PIO buffers and we still have
  823. * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and
  824. * return zero).
  825. */
  826. int ipath_ib_piobufavail(struct ipath_ibdev *dev)
  827. {
  828. struct ipath_qp *qp;
  829. unsigned long flags;
  830. if (dev == NULL)
  831. goto bail;
  832. spin_lock_irqsave(&dev->pending_lock, flags);
  833. while (!list_empty(&dev->piowait)) {
  834. qp = list_entry(dev->piowait.next, struct ipath_qp,
  835. piowait);
  836. list_del_init(&qp->piowait);
  837. tasklet_hi_schedule(&qp->s_task);
  838. }
  839. spin_unlock_irqrestore(&dev->pending_lock, flags);
  840. bail:
  841. return 0;
  842. }
  843. static int ipath_query_device(struct ib_device *ibdev,
  844. struct ib_device_attr *props)
  845. {
  846. struct ipath_ibdev *dev = to_idev(ibdev);
  847. memset(props, 0, sizeof(*props));
  848. props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
  849. IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
  850. IB_DEVICE_SYS_IMAGE_GUID;
  851. props->page_size_cap = PAGE_SIZE;
  852. props->vendor_id = dev->dd->ipath_vendorid;
  853. props->vendor_part_id = dev->dd->ipath_deviceid;
  854. props->hw_ver = dev->dd->ipath_pcirev;
  855. props->sys_image_guid = dev->sys_image_guid;
  856. props->max_mr_size = ~0ull;
  857. props->max_qp = dev->qp_table.max;
  858. props->max_qp_wr = ib_ipath_max_qp_wrs;
  859. props->max_sge = ib_ipath_max_sges;
  860. props->max_cq = ib_ipath_max_cqs;
  861. props->max_ah = ib_ipath_max_ahs;
  862. props->max_cqe = ib_ipath_max_cqes;
  863. props->max_mr = dev->lk_table.max;
  864. props->max_pd = ib_ipath_max_pds;
  865. props->max_qp_rd_atom = 1;
  866. props->max_qp_init_rd_atom = 1;
  867. /* props->max_res_rd_atom */
  868. props->max_srq = ib_ipath_max_srqs;
  869. props->max_srq_wr = ib_ipath_max_srq_wrs;
  870. props->max_srq_sge = ib_ipath_max_srq_sges;
  871. /* props->local_ca_ack_delay */
  872. props->atomic_cap = IB_ATOMIC_HCA;
  873. props->max_pkeys = ipath_get_npkeys(dev->dd);
  874. props->max_mcast_grp = ib_ipath_max_mcast_grps;
  875. props->max_mcast_qp_attach = ib_ipath_max_mcast_qp_attached;
  876. props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
  877. props->max_mcast_grp;
  878. return 0;
  879. }
  880. const u8 ipath_cvt_physportstate[16] = {
  881. [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3,
  882. [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5,
  883. [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2,
  884. [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2,
  885. [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1,
  886. [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1,
  887. [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4,
  888. [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4,
  889. [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4,
  890. [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4,
  891. [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6,
  892. [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6,
  893. [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6,
  894. };
  895. u32 ipath_get_cr_errpkey(struct ipath_devdata *dd)
  896. {
  897. return ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
  898. }
  899. static int ipath_query_port(struct ib_device *ibdev,
  900. u8 port, struct ib_port_attr *props)
  901. {
  902. struct ipath_ibdev *dev = to_idev(ibdev);
  903. enum ib_mtu mtu;
  904. u16 lid = dev->dd->ipath_lid;
  905. u64 ibcstat;
  906. memset(props, 0, sizeof(*props));
  907. props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  908. props->lmc = dev->mkeyprot_resv_lmc & 7;
  909. props->sm_lid = dev->sm_lid;
  910. props->sm_sl = dev->sm_sl;
  911. ibcstat = dev->dd->ipath_lastibcstat;
  912. props->state = ((ibcstat >> 4) & 0x3) + 1;
  913. /* See phys_state_show() */
  914. props->phys_state = ipath_cvt_physportstate[
  915. dev->dd->ipath_lastibcstat & 0xf];
  916. props->port_cap_flags = dev->port_cap_flags;
  917. props->gid_tbl_len = 1;
  918. props->max_msg_sz = 0x80000000;
  919. props->pkey_tbl_len = ipath_get_npkeys(dev->dd);
  920. props->bad_pkey_cntr = ipath_get_cr_errpkey(dev->dd) -
  921. dev->z_pkey_violations;
  922. props->qkey_viol_cntr = dev->qkey_violations;
  923. props->active_width = IB_WIDTH_4X;
  924. /* See rate_show() */
  925. props->active_speed = 1; /* Regular 10Mbs speed. */
  926. props->max_vl_num = 1; /* VLCap = VL0 */
  927. props->init_type_reply = 0;
  928. props->max_mtu = IB_MTU_4096;
  929. switch (dev->dd->ipath_ibmtu) {
  930. case 4096:
  931. mtu = IB_MTU_4096;
  932. break;
  933. case 2048:
  934. mtu = IB_MTU_2048;
  935. break;
  936. case 1024:
  937. mtu = IB_MTU_1024;
  938. break;
  939. case 512:
  940. mtu = IB_MTU_512;
  941. break;
  942. case 256:
  943. mtu = IB_MTU_256;
  944. break;
  945. default:
  946. mtu = IB_MTU_2048;
  947. }
  948. props->active_mtu = mtu;
  949. props->subnet_timeout = dev->subnet_timeout;
  950. return 0;
  951. }
  952. static int ipath_modify_device(struct ib_device *device,
  953. int device_modify_mask,
  954. struct ib_device_modify *device_modify)
  955. {
  956. int ret;
  957. if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
  958. IB_DEVICE_MODIFY_NODE_DESC)) {
  959. ret = -EOPNOTSUPP;
  960. goto bail;
  961. }
  962. if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
  963. memcpy(device->node_desc, device_modify->node_desc, 64);
  964. if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
  965. to_idev(device)->sys_image_guid =
  966. cpu_to_be64(device_modify->sys_image_guid);
  967. ret = 0;
  968. bail:
  969. return ret;
  970. }
  971. static int ipath_modify_port(struct ib_device *ibdev,
  972. u8 port, int port_modify_mask,
  973. struct ib_port_modify *props)
  974. {
  975. struct ipath_ibdev *dev = to_idev(ibdev);
  976. dev->port_cap_flags |= props->set_port_cap_mask;
  977. dev->port_cap_flags &= ~props->clr_port_cap_mask;
  978. if (port_modify_mask & IB_PORT_SHUTDOWN)
  979. ipath_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
  980. if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
  981. dev->qkey_violations = 0;
  982. return 0;
  983. }
  984. static int ipath_query_gid(struct ib_device *ibdev, u8 port,
  985. int index, union ib_gid *gid)
  986. {
  987. struct ipath_ibdev *dev = to_idev(ibdev);
  988. int ret;
  989. if (index >= 1) {
  990. ret = -EINVAL;
  991. goto bail;
  992. }
  993. gid->global.subnet_prefix = dev->gid_prefix;
  994. gid->global.interface_id = dev->dd->ipath_guid;
  995. ret = 0;
  996. bail:
  997. return ret;
  998. }
  999. static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
  1000. struct ib_ucontext *context,
  1001. struct ib_udata *udata)
  1002. {
  1003. struct ipath_ibdev *dev = to_idev(ibdev);
  1004. struct ipath_pd *pd;
  1005. struct ib_pd *ret;
  1006. /*
  1007. * This is actually totally arbitrary. Some correctness tests
  1008. * assume there's a maximum number of PDs that can be allocated.
  1009. * We don't actually have this limit, but we fail the test if
  1010. * we allow allocations of more than we report for this value.
  1011. */
  1012. pd = kmalloc(sizeof *pd, GFP_KERNEL);
  1013. if (!pd) {
  1014. ret = ERR_PTR(-ENOMEM);
  1015. goto bail;
  1016. }
  1017. spin_lock(&dev->n_pds_lock);
  1018. if (dev->n_pds_allocated == ib_ipath_max_pds) {
  1019. spin_unlock(&dev->n_pds_lock);
  1020. kfree(pd);
  1021. ret = ERR_PTR(-ENOMEM);
  1022. goto bail;
  1023. }
  1024. dev->n_pds_allocated++;
  1025. spin_unlock(&dev->n_pds_lock);
  1026. /* ib_alloc_pd() will initialize pd->ibpd. */
  1027. pd->user = udata != NULL;
  1028. ret = &pd->ibpd;
  1029. bail:
  1030. return ret;
  1031. }
  1032. static int ipath_dealloc_pd(struct ib_pd *ibpd)
  1033. {
  1034. struct ipath_pd *pd = to_ipd(ibpd);
  1035. struct ipath_ibdev *dev = to_idev(ibpd->device);
  1036. spin_lock(&dev->n_pds_lock);
  1037. dev->n_pds_allocated--;
  1038. spin_unlock(&dev->n_pds_lock);
  1039. kfree(pd);
  1040. return 0;
  1041. }
  1042. /**
  1043. * ipath_create_ah - create an address handle
  1044. * @pd: the protection domain
  1045. * @ah_attr: the attributes of the AH
  1046. *
  1047. * This may be called from interrupt context.
  1048. */
  1049. static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
  1050. struct ib_ah_attr *ah_attr)
  1051. {
  1052. struct ipath_ah *ah;
  1053. struct ib_ah *ret;
  1054. struct ipath_ibdev *dev = to_idev(pd->device);
  1055. /* A multicast address requires a GRH (see ch. 8.4.1). */
  1056. if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE &&
  1057. ah_attr->dlid != IPATH_PERMISSIVE_LID &&
  1058. !(ah_attr->ah_flags & IB_AH_GRH)) {
  1059. ret = ERR_PTR(-EINVAL);
  1060. goto bail;
  1061. }
  1062. if (ah_attr->dlid == 0) {
  1063. ret = ERR_PTR(-EINVAL);
  1064. goto bail;
  1065. }
  1066. if (ah_attr->port_num < 1 ||
  1067. ah_attr->port_num > pd->device->phys_port_cnt) {
  1068. ret = ERR_PTR(-EINVAL);
  1069. goto bail;
  1070. }
  1071. ah = kmalloc(sizeof *ah, GFP_ATOMIC);
  1072. if (!ah) {
  1073. ret = ERR_PTR(-ENOMEM);
  1074. goto bail;
  1075. }
  1076. spin_lock(&dev->n_ahs_lock);
  1077. if (dev->n_ahs_allocated == ib_ipath_max_ahs) {
  1078. spin_unlock(&dev->n_ahs_lock);
  1079. kfree(ah);
  1080. ret = ERR_PTR(-ENOMEM);
  1081. goto bail;
  1082. }
  1083. dev->n_ahs_allocated++;
  1084. spin_unlock(&dev->n_ahs_lock);
  1085. /* ib_create_ah() will initialize ah->ibah. */
  1086. ah->attr = *ah_attr;
  1087. ret = &ah->ibah;
  1088. bail:
  1089. return ret;
  1090. }
  1091. /**
  1092. * ipath_destroy_ah - destroy an address handle
  1093. * @ibah: the AH to destroy
  1094. *
  1095. * This may be called from interrupt context.
  1096. */
  1097. static int ipath_destroy_ah(struct ib_ah *ibah)
  1098. {
  1099. struct ipath_ibdev *dev = to_idev(ibah->device);
  1100. struct ipath_ah *ah = to_iah(ibah);
  1101. spin_lock(&dev->n_ahs_lock);
  1102. dev->n_ahs_allocated--;
  1103. spin_unlock(&dev->n_ahs_lock);
  1104. kfree(ah);
  1105. return 0;
  1106. }
  1107. static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
  1108. {
  1109. struct ipath_ah *ah = to_iah(ibah);
  1110. *ah_attr = ah->attr;
  1111. return 0;
  1112. }
  1113. /**
  1114. * ipath_get_npkeys - return the size of the PKEY table for port 0
  1115. * @dd: the infinipath device
  1116. */
  1117. unsigned ipath_get_npkeys(struct ipath_devdata *dd)
  1118. {
  1119. return ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys);
  1120. }
  1121. /**
  1122. * ipath_get_pkey - return the indexed PKEY from the port 0 PKEY table
  1123. * @dd: the infinipath device
  1124. * @index: the PKEY index
  1125. */
  1126. unsigned ipath_get_pkey(struct ipath_devdata *dd, unsigned index)
  1127. {
  1128. unsigned ret;
  1129. if (index >= ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys))
  1130. ret = 0;
  1131. else
  1132. ret = dd->ipath_pd[0]->port_pkeys[index];
  1133. return ret;
  1134. }
  1135. static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
  1136. u16 *pkey)
  1137. {
  1138. struct ipath_ibdev *dev = to_idev(ibdev);
  1139. int ret;
  1140. if (index >= ipath_get_npkeys(dev->dd)) {
  1141. ret = -EINVAL;
  1142. goto bail;
  1143. }
  1144. *pkey = ipath_get_pkey(dev->dd, index);
  1145. ret = 0;
  1146. bail:
  1147. return ret;
  1148. }
  1149. /**
  1150. * ipath_alloc_ucontext - allocate a ucontest
  1151. * @ibdev: the infiniband device
  1152. * @udata: not used by the InfiniPath driver
  1153. */
  1154. static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
  1155. struct ib_udata *udata)
  1156. {
  1157. struct ipath_ucontext *context;
  1158. struct ib_ucontext *ret;
  1159. context = kmalloc(sizeof *context, GFP_KERNEL);
  1160. if (!context) {
  1161. ret = ERR_PTR(-ENOMEM);
  1162. goto bail;
  1163. }
  1164. ret = &context->ibucontext;
  1165. bail:
  1166. return ret;
  1167. }
  1168. static int ipath_dealloc_ucontext(struct ib_ucontext *context)
  1169. {
  1170. kfree(to_iucontext(context));
  1171. return 0;
  1172. }
  1173. static int ipath_verbs_register_sysfs(struct ib_device *dev);
  1174. static void __verbs_timer(unsigned long arg)
  1175. {
  1176. struct ipath_devdata *dd = (struct ipath_devdata *) arg;
  1177. /*
  1178. * If port 0 receive packet interrupts are not available, or
  1179. * can be missed, poll the receive queue
  1180. */
  1181. if (dd->ipath_flags & IPATH_POLL_RX_INTR)
  1182. ipath_kreceive(dd);
  1183. /* Handle verbs layer timeouts. */
  1184. ipath_ib_timer(dd->verbs_dev);
  1185. mod_timer(&dd->verbs_timer, jiffies + 1);
  1186. }
  1187. static int enable_timer(struct ipath_devdata *dd)
  1188. {
  1189. /*
  1190. * Early chips had a design flaw where the chip and kernel idea
  1191. * of the tail register don't always agree, and therefore we won't
  1192. * get an interrupt on the next packet received.
  1193. * If the board supports per packet receive interrupts, use it.
  1194. * Otherwise, the timer function periodically checks for packets
  1195. * to cover this case.
  1196. * Either way, the timer is needed for verbs layer related
  1197. * processing.
  1198. */
  1199. if (dd->ipath_flags & IPATH_GPIO_INTR) {
  1200. ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
  1201. 0x2074076542310ULL);
  1202. /* Enable GPIO bit 2 interrupt */
  1203. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  1204. (u64) (1 << 2));
  1205. }
  1206. init_timer(&dd->verbs_timer);
  1207. dd->verbs_timer.function = __verbs_timer;
  1208. dd->verbs_timer.data = (unsigned long)dd;
  1209. dd->verbs_timer.expires = jiffies + 1;
  1210. add_timer(&dd->verbs_timer);
  1211. return 0;
  1212. }
  1213. static int disable_timer(struct ipath_devdata *dd)
  1214. {
  1215. /* Disable GPIO bit 2 interrupt */
  1216. if (dd->ipath_flags & IPATH_GPIO_INTR)
  1217. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask, 0);
  1218. del_timer_sync(&dd->verbs_timer);
  1219. return 0;
  1220. }
  1221. /**
  1222. * ipath_register_ib_device - register our device with the infiniband core
  1223. * @dd: the device data structure
  1224. * Return the allocated ipath_ibdev pointer or NULL on error.
  1225. */
  1226. int ipath_register_ib_device(struct ipath_devdata *dd)
  1227. {
  1228. struct ipath_verbs_counters cntrs;
  1229. struct ipath_ibdev *idev;
  1230. struct ib_device *dev;
  1231. int ret;
  1232. idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
  1233. if (idev == NULL) {
  1234. ret = -ENOMEM;
  1235. goto bail;
  1236. }
  1237. dev = &idev->ibdev;
  1238. /* Only need to initialize non-zero fields. */
  1239. spin_lock_init(&idev->n_pds_lock);
  1240. spin_lock_init(&idev->n_ahs_lock);
  1241. spin_lock_init(&idev->n_cqs_lock);
  1242. spin_lock_init(&idev->n_srqs_lock);
  1243. spin_lock_init(&idev->n_mcast_grps_lock);
  1244. spin_lock_init(&idev->qp_table.lock);
  1245. spin_lock_init(&idev->lk_table.lock);
  1246. idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  1247. /* Set the prefix to the default value (see ch. 4.1.1) */
  1248. idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
  1249. ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
  1250. if (ret)
  1251. goto err_qp;
  1252. /*
  1253. * The top ib_ipath_lkey_table_size bits are used to index the
  1254. * table. The lower 8 bits can be owned by the user (copied from
  1255. * the LKEY). The remaining bits act as a generation number or tag.
  1256. */
  1257. idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
  1258. idev->lk_table.table = kzalloc(idev->lk_table.max *
  1259. sizeof(*idev->lk_table.table),
  1260. GFP_KERNEL);
  1261. if (idev->lk_table.table == NULL) {
  1262. ret = -ENOMEM;
  1263. goto err_lk;
  1264. }
  1265. spin_lock_init(&idev->pending_lock);
  1266. INIT_LIST_HEAD(&idev->pending[0]);
  1267. INIT_LIST_HEAD(&idev->pending[1]);
  1268. INIT_LIST_HEAD(&idev->pending[2]);
  1269. INIT_LIST_HEAD(&idev->piowait);
  1270. INIT_LIST_HEAD(&idev->rnrwait);
  1271. idev->pending_index = 0;
  1272. idev->port_cap_flags =
  1273. IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
  1274. idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  1275. idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  1276. idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  1277. idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  1278. idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT;
  1279. idev->link_width_enabled = 3; /* 1x or 4x */
  1280. /* Snapshot current HW counters to "clear" them. */
  1281. ipath_get_counters(dd, &cntrs);
  1282. idev->z_symbol_error_counter = cntrs.symbol_error_counter;
  1283. idev->z_link_error_recovery_counter =
  1284. cntrs.link_error_recovery_counter;
  1285. idev->z_link_downed_counter = cntrs.link_downed_counter;
  1286. idev->z_port_rcv_errors = cntrs.port_rcv_errors;
  1287. idev->z_port_rcv_remphys_errors =
  1288. cntrs.port_rcv_remphys_errors;
  1289. idev->z_port_xmit_discards = cntrs.port_xmit_discards;
  1290. idev->z_port_xmit_data = cntrs.port_xmit_data;
  1291. idev->z_port_rcv_data = cntrs.port_rcv_data;
  1292. idev->z_port_xmit_packets = cntrs.port_xmit_packets;
  1293. idev->z_port_rcv_packets = cntrs.port_rcv_packets;
  1294. idev->z_local_link_integrity_errors =
  1295. cntrs.local_link_integrity_errors;
  1296. idev->z_excessive_buffer_overrun_errors =
  1297. cntrs.excessive_buffer_overrun_errors;
  1298. /*
  1299. * The system image GUID is supposed to be the same for all
  1300. * IB HCAs in a single system but since there can be other
  1301. * device types in the system, we can't be sure this is unique.
  1302. */
  1303. if (!sys_image_guid)
  1304. sys_image_guid = dd->ipath_guid;
  1305. idev->sys_image_guid = sys_image_guid;
  1306. idev->ib_unit = dd->ipath_unit;
  1307. idev->dd = dd;
  1308. strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
  1309. dev->owner = THIS_MODULE;
  1310. dev->node_guid = dd->ipath_guid;
  1311. dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
  1312. dev->uverbs_cmd_mask =
  1313. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  1314. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  1315. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  1316. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  1317. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  1318. (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
  1319. (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
  1320. (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
  1321. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  1322. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  1323. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  1324. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  1325. (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
  1326. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  1327. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  1328. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  1329. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  1330. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  1331. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  1332. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  1333. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  1334. (1ull << IB_USER_VERBS_CMD_POST_RECV) |
  1335. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  1336. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
  1337. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  1338. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  1339. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  1340. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
  1341. (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
  1342. dev->node_type = IB_NODE_CA;
  1343. dev->phys_port_cnt = 1;
  1344. dev->dma_device = &dd->pcidev->dev;
  1345. dev->class_dev.dev = dev->dma_device;
  1346. dev->query_device = ipath_query_device;
  1347. dev->modify_device = ipath_modify_device;
  1348. dev->query_port = ipath_query_port;
  1349. dev->modify_port = ipath_modify_port;
  1350. dev->query_pkey = ipath_query_pkey;
  1351. dev->query_gid = ipath_query_gid;
  1352. dev->alloc_ucontext = ipath_alloc_ucontext;
  1353. dev->dealloc_ucontext = ipath_dealloc_ucontext;
  1354. dev->alloc_pd = ipath_alloc_pd;
  1355. dev->dealloc_pd = ipath_dealloc_pd;
  1356. dev->create_ah = ipath_create_ah;
  1357. dev->destroy_ah = ipath_destroy_ah;
  1358. dev->query_ah = ipath_query_ah;
  1359. dev->create_srq = ipath_create_srq;
  1360. dev->modify_srq = ipath_modify_srq;
  1361. dev->query_srq = ipath_query_srq;
  1362. dev->destroy_srq = ipath_destroy_srq;
  1363. dev->create_qp = ipath_create_qp;
  1364. dev->modify_qp = ipath_modify_qp;
  1365. dev->query_qp = ipath_query_qp;
  1366. dev->destroy_qp = ipath_destroy_qp;
  1367. dev->post_send = ipath_post_send;
  1368. dev->post_recv = ipath_post_receive;
  1369. dev->post_srq_recv = ipath_post_srq_receive;
  1370. dev->create_cq = ipath_create_cq;
  1371. dev->destroy_cq = ipath_destroy_cq;
  1372. dev->resize_cq = ipath_resize_cq;
  1373. dev->poll_cq = ipath_poll_cq;
  1374. dev->req_notify_cq = ipath_req_notify_cq;
  1375. dev->get_dma_mr = ipath_get_dma_mr;
  1376. dev->reg_phys_mr = ipath_reg_phys_mr;
  1377. dev->reg_user_mr = ipath_reg_user_mr;
  1378. dev->dereg_mr = ipath_dereg_mr;
  1379. dev->alloc_fmr = ipath_alloc_fmr;
  1380. dev->map_phys_fmr = ipath_map_phys_fmr;
  1381. dev->unmap_fmr = ipath_unmap_fmr;
  1382. dev->dealloc_fmr = ipath_dealloc_fmr;
  1383. dev->attach_mcast = ipath_multicast_attach;
  1384. dev->detach_mcast = ipath_multicast_detach;
  1385. dev->process_mad = ipath_process_mad;
  1386. dev->mmap = ipath_mmap;
  1387. snprintf(dev->node_desc, sizeof(dev->node_desc),
  1388. IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename);
  1389. ret = ib_register_device(dev);
  1390. if (ret)
  1391. goto err_reg;
  1392. if (ipath_verbs_register_sysfs(dev))
  1393. goto err_class;
  1394. enable_timer(dd);
  1395. goto bail;
  1396. err_class:
  1397. ib_unregister_device(dev);
  1398. err_reg:
  1399. kfree(idev->lk_table.table);
  1400. err_lk:
  1401. kfree(idev->qp_table.table);
  1402. err_qp:
  1403. ib_dealloc_device(dev);
  1404. ipath_dev_err(dd, "cannot register verbs: %d!\n", -ret);
  1405. idev = NULL;
  1406. bail:
  1407. dd->verbs_dev = idev;
  1408. return ret;
  1409. }
  1410. void ipath_unregister_ib_device(struct ipath_ibdev *dev)
  1411. {
  1412. struct ib_device *ibdev = &dev->ibdev;
  1413. disable_timer(dev->dd);
  1414. ib_unregister_device(ibdev);
  1415. if (!list_empty(&dev->pending[0]) ||
  1416. !list_empty(&dev->pending[1]) ||
  1417. !list_empty(&dev->pending[2]))
  1418. ipath_dev_err(dev->dd, "pending list not empty!\n");
  1419. if (!list_empty(&dev->piowait))
  1420. ipath_dev_err(dev->dd, "piowait list not empty!\n");
  1421. if (!list_empty(&dev->rnrwait))
  1422. ipath_dev_err(dev->dd, "rnrwait list not empty!\n");
  1423. if (!ipath_mcast_tree_empty())
  1424. ipath_dev_err(dev->dd, "multicast table memory leak!\n");
  1425. /*
  1426. * Note that ipath_unregister_ib_device() can be called before all
  1427. * the QPs are destroyed!
  1428. */
  1429. ipath_free_all_qps(&dev->qp_table);
  1430. kfree(dev->qp_table.table);
  1431. kfree(dev->lk_table.table);
  1432. ib_dealloc_device(ibdev);
  1433. }
  1434. static ssize_t show_rev(struct class_device *cdev, char *buf)
  1435. {
  1436. struct ipath_ibdev *dev =
  1437. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1438. return sprintf(buf, "%x\n", dev->dd->ipath_pcirev);
  1439. }
  1440. static ssize_t show_hca(struct class_device *cdev, char *buf)
  1441. {
  1442. struct ipath_ibdev *dev =
  1443. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1444. int ret;
  1445. ret = dev->dd->ipath_f_get_boardname(dev->dd, buf, 128);
  1446. if (ret < 0)
  1447. goto bail;
  1448. strcat(buf, "\n");
  1449. ret = strlen(buf);
  1450. bail:
  1451. return ret;
  1452. }
  1453. static ssize_t show_stats(struct class_device *cdev, char *buf)
  1454. {
  1455. struct ipath_ibdev *dev =
  1456. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1457. int i;
  1458. int len;
  1459. len = sprintf(buf,
  1460. "RC resends %d\n"
  1461. "RC no QACK %d\n"
  1462. "RC ACKs %d\n"
  1463. "RC SEQ NAKs %d\n"
  1464. "RC RDMA seq %d\n"
  1465. "RC RNR NAKs %d\n"
  1466. "RC OTH NAKs %d\n"
  1467. "RC timeouts %d\n"
  1468. "RC RDMA dup %d\n"
  1469. "piobuf wait %d\n"
  1470. "no piobuf %d\n"
  1471. "PKT drops %d\n"
  1472. "WQE errs %d\n",
  1473. dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
  1474. dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
  1475. dev->n_other_naks, dev->n_timeouts,
  1476. dev->n_rdma_dup_busy, dev->n_piowait,
  1477. dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
  1478. for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
  1479. const struct ipath_opcode_stats *si = &dev->opstats[i];
  1480. if (!si->n_packets && !si->n_bytes)
  1481. continue;
  1482. len += sprintf(buf + len, "%02x %llu/%llu\n", i,
  1483. (unsigned long long) si->n_packets,
  1484. (unsigned long long) si->n_bytes);
  1485. }
  1486. return len;
  1487. }
  1488. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  1489. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  1490. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  1491. static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  1492. static struct class_device_attribute *ipath_class_attributes[] = {
  1493. &class_device_attr_hw_rev,
  1494. &class_device_attr_hca_type,
  1495. &class_device_attr_board_id,
  1496. &class_device_attr_stats
  1497. };
  1498. static int ipath_verbs_register_sysfs(struct ib_device *dev)
  1499. {
  1500. int i;
  1501. int ret;
  1502. for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
  1503. if (class_device_create_file(&dev->class_dev,
  1504. ipath_class_attributes[i])) {
  1505. ret = 1;
  1506. goto bail;
  1507. }
  1508. ret = 0;
  1509. bail:
  1510. return ret;
  1511. }