ipath_verbs.c 45 KB

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