ipath_verbs.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /*
  2. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <rdma/ib_mad.h>
  33. #include <rdma/ib_user_verbs.h>
  34. #include <linux/utsname.h>
  35. #include "ipath_kernel.h"
  36. #include "ipath_verbs.h"
  37. #include "ips_common.h"
  38. /* Not static, because we don't want the compiler removing it */
  39. const char ipath_verbs_version[] = "ipath_verbs " IPATH_IDSTR;
  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. MODULE_LICENSE("GPL");
  52. MODULE_AUTHOR("PathScale <support@pathscale.com>");
  53. MODULE_DESCRIPTION("Pathscale InfiniPath driver");
  54. const int ib_ipath_state_ops[IB_QPS_ERR + 1] = {
  55. [IB_QPS_RESET] = 0,
  56. [IB_QPS_INIT] = IPATH_POST_RECV_OK,
  57. [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
  58. [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
  59. IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK,
  60. [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
  61. IPATH_POST_SEND_OK,
  62. [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
  63. [IB_QPS_ERR] = 0,
  64. };
  65. /*
  66. * Translate ib_wr_opcode into ib_wc_opcode.
  67. */
  68. const enum ib_wc_opcode ib_ipath_wc_opcode[] = {
  69. [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
  70. [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
  71. [IB_WR_SEND] = IB_WC_SEND,
  72. [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
  73. [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
  74. [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
  75. [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
  76. };
  77. /*
  78. * System image GUID.
  79. */
  80. static __be64 sys_image_guid;
  81. /**
  82. * ipath_copy_sge - copy data to SGE memory
  83. * @ss: the SGE state
  84. * @data: the data to copy
  85. * @length: the length of the data
  86. */
  87. void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length)
  88. {
  89. struct ipath_sge *sge = &ss->sge;
  90. while (length) {
  91. u32 len = sge->length;
  92. BUG_ON(len == 0);
  93. if (len > length)
  94. len = length;
  95. memcpy(sge->vaddr, data, len);
  96. sge->vaddr += len;
  97. sge->length -= len;
  98. sge->sge_length -= len;
  99. if (sge->sge_length == 0) {
  100. if (--ss->num_sge)
  101. *sge = *ss->sg_list++;
  102. } else if (sge->length == 0 && sge->mr != NULL) {
  103. if (++sge->n >= IPATH_SEGSZ) {
  104. if (++sge->m >= sge->mr->mapsz)
  105. break;
  106. sge->n = 0;
  107. }
  108. sge->vaddr =
  109. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  110. sge->length =
  111. sge->mr->map[sge->m]->segs[sge->n].length;
  112. }
  113. data += len;
  114. length -= len;
  115. }
  116. }
  117. /**
  118. * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func
  119. * @ss: the SGE state
  120. * @length: the number of bytes to skip
  121. */
  122. void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
  123. {
  124. struct ipath_sge *sge = &ss->sge;
  125. while (length > sge->sge_length) {
  126. length -= sge->sge_length;
  127. ss->sge = *ss->sg_list++;
  128. }
  129. while (length) {
  130. u32 len = sge->length;
  131. BUG_ON(len == 0);
  132. if (len > length)
  133. len = length;
  134. sge->vaddr += len;
  135. sge->length -= len;
  136. sge->sge_length -= len;
  137. if (sge->sge_length == 0) {
  138. if (--ss->num_sge)
  139. *sge = *ss->sg_list++;
  140. } else if (sge->length == 0 && sge->mr != NULL) {
  141. if (++sge->n >= IPATH_SEGSZ) {
  142. if (++sge->m >= sge->mr->mapsz)
  143. break;
  144. sge->n = 0;
  145. }
  146. sge->vaddr =
  147. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  148. sge->length =
  149. sge->mr->map[sge->m]->segs[sge->n].length;
  150. }
  151. length -= len;
  152. }
  153. }
  154. /**
  155. * ipath_post_send - post a send on a QP
  156. * @ibqp: the QP to post the send on
  157. * @wr: the list of work requests to post
  158. * @bad_wr: the first bad WR is put here
  159. *
  160. * This may be called from interrupt context.
  161. */
  162. static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  163. struct ib_send_wr **bad_wr)
  164. {
  165. struct ipath_qp *qp = to_iqp(ibqp);
  166. int err = 0;
  167. /* Check that state is OK to post send. */
  168. if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)) {
  169. *bad_wr = wr;
  170. err = -EINVAL;
  171. goto bail;
  172. }
  173. for (; wr; wr = wr->next) {
  174. switch (qp->ibqp.qp_type) {
  175. case IB_QPT_UC:
  176. case IB_QPT_RC:
  177. err = ipath_post_rc_send(qp, wr);
  178. break;
  179. case IB_QPT_SMI:
  180. case IB_QPT_GSI:
  181. case IB_QPT_UD:
  182. err = ipath_post_ud_send(qp, wr);
  183. break;
  184. default:
  185. err = -EINVAL;
  186. }
  187. if (err) {
  188. *bad_wr = wr;
  189. break;
  190. }
  191. }
  192. bail:
  193. return err;
  194. }
  195. /**
  196. * ipath_post_receive - post a receive on a QP
  197. * @ibqp: the QP to post the receive on
  198. * @wr: the WR to post
  199. * @bad_wr: the first bad WR is put here
  200. *
  201. * This may be called from interrupt context.
  202. */
  203. static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  204. struct ib_recv_wr **bad_wr)
  205. {
  206. struct ipath_qp *qp = to_iqp(ibqp);
  207. unsigned long flags;
  208. int ret;
  209. /* Check that state is OK to post receive. */
  210. if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK)) {
  211. *bad_wr = wr;
  212. ret = -EINVAL;
  213. goto bail;
  214. }
  215. for (; wr; wr = wr->next) {
  216. struct ipath_rwqe *wqe;
  217. u32 next;
  218. int i, j;
  219. if (wr->num_sge > qp->r_rq.max_sge) {
  220. *bad_wr = wr;
  221. ret = -ENOMEM;
  222. goto bail;
  223. }
  224. spin_lock_irqsave(&qp->r_rq.lock, flags);
  225. next = qp->r_rq.head + 1;
  226. if (next >= qp->r_rq.size)
  227. next = 0;
  228. if (next == qp->r_rq.tail) {
  229. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  230. *bad_wr = wr;
  231. ret = -ENOMEM;
  232. goto bail;
  233. }
  234. wqe = get_rwqe_ptr(&qp->r_rq, qp->r_rq.head);
  235. wqe->wr_id = wr->wr_id;
  236. wqe->sg_list[0].mr = NULL;
  237. wqe->sg_list[0].vaddr = NULL;
  238. wqe->sg_list[0].length = 0;
  239. wqe->sg_list[0].sge_length = 0;
  240. wqe->length = 0;
  241. for (i = 0, j = 0; i < wr->num_sge; i++) {
  242. /* Check LKEY */
  243. if (to_ipd(qp->ibqp.pd)->user &&
  244. wr->sg_list[i].lkey == 0) {
  245. spin_unlock_irqrestore(&qp->r_rq.lock,
  246. flags);
  247. *bad_wr = wr;
  248. ret = -EINVAL;
  249. goto bail;
  250. }
  251. if (wr->sg_list[i].length == 0)
  252. continue;
  253. if (!ipath_lkey_ok(
  254. &to_idev(qp->ibqp.device)->lk_table,
  255. &wqe->sg_list[j], &wr->sg_list[i],
  256. IB_ACCESS_LOCAL_WRITE)) {
  257. spin_unlock_irqrestore(&qp->r_rq.lock,
  258. flags);
  259. *bad_wr = wr;
  260. ret = -EINVAL;
  261. goto bail;
  262. }
  263. wqe->length += wr->sg_list[i].length;
  264. j++;
  265. }
  266. wqe->num_sge = j;
  267. qp->r_rq.head = next;
  268. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  269. }
  270. ret = 0;
  271. bail:
  272. return ret;
  273. }
  274. /**
  275. * ipath_qp_rcv - processing an incoming packet on a QP
  276. * @dev: the device the packet came on
  277. * @hdr: the packet header
  278. * @has_grh: true if the packet has a GRH
  279. * @data: the packet data
  280. * @tlen: the packet length
  281. * @qp: the QP the packet came on
  282. *
  283. * This is called from ipath_ib_rcv() to process an incoming packet
  284. * for the given QP.
  285. * Called at interrupt level.
  286. */
  287. static void ipath_qp_rcv(struct ipath_ibdev *dev,
  288. struct ipath_ib_header *hdr, int has_grh,
  289. void *data, u32 tlen, struct ipath_qp *qp)
  290. {
  291. /* Check for valid receive state. */
  292. if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {
  293. dev->n_pkt_drops++;
  294. return;
  295. }
  296. switch (qp->ibqp.qp_type) {
  297. case IB_QPT_SMI:
  298. case IB_QPT_GSI:
  299. case IB_QPT_UD:
  300. ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp);
  301. break;
  302. case IB_QPT_RC:
  303. ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp);
  304. break;
  305. case IB_QPT_UC:
  306. ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp);
  307. break;
  308. default:
  309. break;
  310. }
  311. }
  312. /**
  313. * ipath_ib_rcv - process and incoming packet
  314. * @arg: the device pointer
  315. * @rhdr: the header of the packet
  316. * @data: the packet data
  317. * @tlen: the packet length
  318. *
  319. * This is called from ipath_kreceive() to process an incoming packet at
  320. * interrupt level. Tlen is the length of the header + data + CRC in bytes.
  321. */
  322. static void ipath_ib_rcv(void *arg, void *rhdr, void *data, u32 tlen)
  323. {
  324. struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
  325. struct ipath_ib_header *hdr = rhdr;
  326. struct ipath_other_headers *ohdr;
  327. struct ipath_qp *qp;
  328. u32 qp_num;
  329. int lnh;
  330. u8 opcode;
  331. u16 lid;
  332. if (unlikely(dev == NULL))
  333. goto bail;
  334. if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */
  335. dev->rcv_errors++;
  336. goto bail;
  337. }
  338. /* Check for a valid destination LID (see ch. 7.11.1). */
  339. lid = be16_to_cpu(hdr->lrh[1]);
  340. if (lid < IPS_MULTICAST_LID_BASE) {
  341. lid &= ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
  342. if (unlikely(lid != ipath_layer_get_lid(dev->dd))) {
  343. dev->rcv_errors++;
  344. goto bail;
  345. }
  346. }
  347. /* Check for GRH */
  348. lnh = be16_to_cpu(hdr->lrh[0]) & 3;
  349. if (lnh == IPS_LRH_BTH)
  350. ohdr = &hdr->u.oth;
  351. else if (lnh == IPS_LRH_GRH)
  352. ohdr = &hdr->u.l.oth;
  353. else {
  354. dev->rcv_errors++;
  355. goto bail;
  356. }
  357. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  358. dev->opstats[opcode].n_bytes += tlen;
  359. dev->opstats[opcode].n_packets++;
  360. /* Get the destination QP number. */
  361. qp_num = be32_to_cpu(ohdr->bth[1]) & IPS_QPN_MASK;
  362. if (qp_num == IPS_MULTICAST_QPN) {
  363. struct ipath_mcast *mcast;
  364. struct ipath_mcast_qp *p;
  365. mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
  366. if (mcast == NULL) {
  367. dev->n_pkt_drops++;
  368. goto bail;
  369. }
  370. dev->n_multicast_rcv++;
  371. list_for_each_entry_rcu(p, &mcast->qp_list, list)
  372. ipath_qp_rcv(dev, hdr, lnh == IPS_LRH_GRH, data,
  373. tlen, p->qp);
  374. /*
  375. * Notify ipath_multicast_detach() if it is waiting for us
  376. * to finish.
  377. */
  378. if (atomic_dec_return(&mcast->refcount) <= 1)
  379. wake_up(&mcast->wait);
  380. } else {
  381. qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
  382. if (qp) {
  383. dev->n_unicast_rcv++;
  384. ipath_qp_rcv(dev, hdr, lnh == IPS_LRH_GRH, data,
  385. tlen, qp);
  386. /*
  387. * Notify ipath_destroy_qp() if it is waiting
  388. * for us to finish.
  389. */
  390. if (atomic_dec_and_test(&qp->refcount))
  391. wake_up(&qp->wait);
  392. } else
  393. dev->n_pkt_drops++;
  394. }
  395. bail:;
  396. }
  397. /**
  398. * ipath_ib_timer - verbs timer
  399. * @arg: the device pointer
  400. *
  401. * This is called from ipath_do_rcv_timer() at interrupt level to check for
  402. * QPs which need retransmits and to collect performance numbers.
  403. */
  404. static void ipath_ib_timer(void *arg)
  405. {
  406. struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
  407. struct ipath_qp *resend = NULL;
  408. struct list_head *last;
  409. struct ipath_qp *qp;
  410. unsigned long flags;
  411. if (dev == NULL)
  412. return;
  413. spin_lock_irqsave(&dev->pending_lock, flags);
  414. /* Start filling the next pending queue. */
  415. if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
  416. dev->pending_index = 0;
  417. /* Save any requests still in the new queue, they have timed out. */
  418. last = &dev->pending[dev->pending_index];
  419. while (!list_empty(last)) {
  420. qp = list_entry(last->next, struct ipath_qp, timerwait);
  421. list_del_init(&qp->timerwait);
  422. qp->timer_next = resend;
  423. resend = qp;
  424. atomic_inc(&qp->refcount);
  425. }
  426. last = &dev->rnrwait;
  427. if (!list_empty(last)) {
  428. qp = list_entry(last->next, struct ipath_qp, timerwait);
  429. if (--qp->s_rnr_timeout == 0) {
  430. do {
  431. list_del_init(&qp->timerwait);
  432. tasklet_hi_schedule(&qp->s_task);
  433. if (list_empty(last))
  434. break;
  435. qp = list_entry(last->next, struct ipath_qp,
  436. timerwait);
  437. } while (qp->s_rnr_timeout == 0);
  438. }
  439. }
  440. /*
  441. * We should only be in the started state if pma_sample_start != 0
  442. */
  443. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
  444. --dev->pma_sample_start == 0) {
  445. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  446. ipath_layer_snapshot_counters(dev->dd, &dev->ipath_sword,
  447. &dev->ipath_rword,
  448. &dev->ipath_spkts,
  449. &dev->ipath_rpkts,
  450. &dev->ipath_xmit_wait);
  451. }
  452. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
  453. if (dev->pma_sample_interval == 0) {
  454. u64 ta, tb, tc, td, te;
  455. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  456. ipath_layer_snapshot_counters(dev->dd, &ta, &tb,
  457. &tc, &td, &te);
  458. dev->ipath_sword = ta - dev->ipath_sword;
  459. dev->ipath_rword = tb - dev->ipath_rword;
  460. dev->ipath_spkts = tc - dev->ipath_spkts;
  461. dev->ipath_rpkts = td - dev->ipath_rpkts;
  462. dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
  463. }
  464. else
  465. dev->pma_sample_interval--;
  466. }
  467. spin_unlock_irqrestore(&dev->pending_lock, flags);
  468. /* XXX What if timer fires again while this is running? */
  469. for (qp = resend; qp != NULL; qp = qp->timer_next) {
  470. struct ib_wc wc;
  471. spin_lock_irqsave(&qp->s_lock, flags);
  472. if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) {
  473. dev->n_timeouts++;
  474. ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
  475. }
  476. spin_unlock_irqrestore(&qp->s_lock, flags);
  477. /* Notify ipath_destroy_qp() if it is waiting. */
  478. if (atomic_dec_and_test(&qp->refcount))
  479. wake_up(&qp->wait);
  480. }
  481. }
  482. /**
  483. * ipath_ib_piobufavail - callback when a PIO buffer is available
  484. * @arg: the device pointer
  485. *
  486. * This is called from ipath_intr() at interrupt level when a PIO buffer is
  487. * available after ipath_verbs_send() returned an error that no buffers were
  488. * available. Return 1 if we consumed all the PIO buffers and we still have
  489. * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and
  490. * return zero).
  491. */
  492. static int ipath_ib_piobufavail(void *arg)
  493. {
  494. struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
  495. struct ipath_qp *qp;
  496. unsigned long flags;
  497. if (dev == NULL)
  498. goto bail;
  499. spin_lock_irqsave(&dev->pending_lock, flags);
  500. while (!list_empty(&dev->piowait)) {
  501. qp = list_entry(dev->piowait.next, struct ipath_qp,
  502. piowait);
  503. list_del_init(&qp->piowait);
  504. tasklet_hi_schedule(&qp->s_task);
  505. }
  506. spin_unlock_irqrestore(&dev->pending_lock, flags);
  507. bail:
  508. return 0;
  509. }
  510. static int ipath_query_device(struct ib_device *ibdev,
  511. struct ib_device_attr *props)
  512. {
  513. struct ipath_ibdev *dev = to_idev(ibdev);
  514. u32 vendor, boardrev, majrev, minrev;
  515. memset(props, 0, sizeof(*props));
  516. props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
  517. IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
  518. IB_DEVICE_SYS_IMAGE_GUID;
  519. ipath_layer_query_device(dev->dd, &vendor, &boardrev,
  520. &majrev, &minrev);
  521. props->vendor_id = vendor;
  522. props->vendor_part_id = boardrev;
  523. props->hw_ver = boardrev << 16 | majrev << 8 | minrev;
  524. props->sys_image_guid = dev->sys_image_guid;
  525. props->max_mr_size = ~0ull;
  526. props->max_qp = 0xffff;
  527. props->max_qp_wr = 0xffff;
  528. props->max_sge = 255;
  529. props->max_cq = 0xffff;
  530. props->max_cqe = 0xffff;
  531. props->max_mr = 0xffff;
  532. props->max_pd = 0xffff;
  533. props->max_qp_rd_atom = 1;
  534. props->max_qp_init_rd_atom = 1;
  535. /* props->max_res_rd_atom */
  536. props->max_srq = 0xffff;
  537. props->max_srq_wr = 0xffff;
  538. props->max_srq_sge = 255;
  539. /* props->local_ca_ack_delay */
  540. props->atomic_cap = IB_ATOMIC_HCA;
  541. props->max_pkeys = ipath_layer_get_npkeys(dev->dd);
  542. props->max_mcast_grp = 0xffff;
  543. props->max_mcast_qp_attach = 0xffff;
  544. props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
  545. props->max_mcast_grp;
  546. return 0;
  547. }
  548. const u8 ipath_cvt_physportstate[16] = {
  549. [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3,
  550. [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5,
  551. [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2,
  552. [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2,
  553. [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1,
  554. [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1,
  555. [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4,
  556. [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4,
  557. [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4,
  558. [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4,
  559. [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6,
  560. [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6,
  561. [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6,
  562. };
  563. static int ipath_query_port(struct ib_device *ibdev,
  564. u8 port, struct ib_port_attr *props)
  565. {
  566. struct ipath_ibdev *dev = to_idev(ibdev);
  567. enum ib_mtu mtu;
  568. u16 lid = ipath_layer_get_lid(dev->dd);
  569. u64 ibcstat;
  570. memset(props, 0, sizeof(*props));
  571. props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  572. props->lmc = dev->mkeyprot_resv_lmc & 7;
  573. props->sm_lid = dev->sm_lid;
  574. props->sm_sl = dev->sm_sl;
  575. ibcstat = ipath_layer_get_lastibcstat(dev->dd);
  576. props->state = ((ibcstat >> 4) & 0x3) + 1;
  577. /* See phys_state_show() */
  578. props->phys_state = ipath_cvt_physportstate[
  579. ipath_layer_get_lastibcstat(dev->dd) & 0xf];
  580. props->port_cap_flags = dev->port_cap_flags;
  581. props->gid_tbl_len = 1;
  582. props->max_msg_sz = 4096;
  583. props->pkey_tbl_len = ipath_layer_get_npkeys(dev->dd);
  584. props->bad_pkey_cntr = ipath_layer_get_cr_errpkey(dev->dd) -
  585. dev->n_pkey_violations;
  586. props->qkey_viol_cntr = dev->qkey_violations;
  587. props->active_width = IB_WIDTH_4X;
  588. /* See rate_show() */
  589. props->active_speed = 1; /* Regular 10Mbs speed. */
  590. props->max_vl_num = 1; /* VLCap = VL0 */
  591. props->init_type_reply = 0;
  592. props->max_mtu = IB_MTU_4096;
  593. switch (ipath_layer_get_ibmtu(dev->dd)) {
  594. case 4096:
  595. mtu = IB_MTU_4096;
  596. break;
  597. case 2048:
  598. mtu = IB_MTU_2048;
  599. break;
  600. case 1024:
  601. mtu = IB_MTU_1024;
  602. break;
  603. case 512:
  604. mtu = IB_MTU_512;
  605. break;
  606. case 256:
  607. mtu = IB_MTU_256;
  608. break;
  609. default:
  610. mtu = IB_MTU_2048;
  611. }
  612. props->active_mtu = mtu;
  613. props->subnet_timeout = dev->subnet_timeout;
  614. return 0;
  615. }
  616. static int ipath_modify_device(struct ib_device *device,
  617. int device_modify_mask,
  618. struct ib_device_modify *device_modify)
  619. {
  620. int ret;
  621. if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
  622. IB_DEVICE_MODIFY_NODE_DESC)) {
  623. ret = -EOPNOTSUPP;
  624. goto bail;
  625. }
  626. if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
  627. memcpy(device->node_desc, device_modify->node_desc, 64);
  628. if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
  629. to_idev(device)->sys_image_guid =
  630. cpu_to_be64(device_modify->sys_image_guid);
  631. ret = 0;
  632. bail:
  633. return ret;
  634. }
  635. static int ipath_modify_port(struct ib_device *ibdev,
  636. u8 port, int port_modify_mask,
  637. struct ib_port_modify *props)
  638. {
  639. struct ipath_ibdev *dev = to_idev(ibdev);
  640. dev->port_cap_flags |= props->set_port_cap_mask;
  641. dev->port_cap_flags &= ~props->clr_port_cap_mask;
  642. if (port_modify_mask & IB_PORT_SHUTDOWN)
  643. ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
  644. if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
  645. dev->qkey_violations = 0;
  646. return 0;
  647. }
  648. static int ipath_query_gid(struct ib_device *ibdev, u8 port,
  649. int index, union ib_gid *gid)
  650. {
  651. struct ipath_ibdev *dev = to_idev(ibdev);
  652. int ret;
  653. if (index >= 1) {
  654. ret = -EINVAL;
  655. goto bail;
  656. }
  657. gid->global.subnet_prefix = dev->gid_prefix;
  658. gid->global.interface_id = ipath_layer_get_guid(dev->dd);
  659. ret = 0;
  660. bail:
  661. return ret;
  662. }
  663. static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
  664. struct ib_ucontext *context,
  665. struct ib_udata *udata)
  666. {
  667. struct ipath_pd *pd;
  668. struct ib_pd *ret;
  669. pd = kmalloc(sizeof *pd, GFP_KERNEL);
  670. if (!pd) {
  671. ret = ERR_PTR(-ENOMEM);
  672. goto bail;
  673. }
  674. /* ib_alloc_pd() will initialize pd->ibpd. */
  675. pd->user = udata != NULL;
  676. ret = &pd->ibpd;
  677. bail:
  678. return ret;
  679. }
  680. static int ipath_dealloc_pd(struct ib_pd *ibpd)
  681. {
  682. struct ipath_pd *pd = to_ipd(ibpd);
  683. kfree(pd);
  684. return 0;
  685. }
  686. /**
  687. * ipath_create_ah - create an address handle
  688. * @pd: the protection domain
  689. * @ah_attr: the attributes of the AH
  690. *
  691. * This may be called from interrupt context.
  692. */
  693. static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
  694. struct ib_ah_attr *ah_attr)
  695. {
  696. struct ipath_ah *ah;
  697. struct ib_ah *ret;
  698. /* A multicast address requires a GRH (see ch. 8.4.1). */
  699. if (ah_attr->dlid >= IPS_MULTICAST_LID_BASE &&
  700. ah_attr->dlid != IPS_PERMISSIVE_LID &&
  701. !(ah_attr->ah_flags & IB_AH_GRH)) {
  702. ret = ERR_PTR(-EINVAL);
  703. goto bail;
  704. }
  705. ah = kmalloc(sizeof *ah, GFP_ATOMIC);
  706. if (!ah) {
  707. ret = ERR_PTR(-ENOMEM);
  708. goto bail;
  709. }
  710. /* ib_create_ah() will initialize ah->ibah. */
  711. ah->attr = *ah_attr;
  712. ret = &ah->ibah;
  713. bail:
  714. return ret;
  715. }
  716. /**
  717. * ipath_destroy_ah - destroy an address handle
  718. * @ibah: the AH to destroy
  719. *
  720. * This may be called from interrupt context.
  721. */
  722. static int ipath_destroy_ah(struct ib_ah *ibah)
  723. {
  724. struct ipath_ah *ah = to_iah(ibah);
  725. kfree(ah);
  726. return 0;
  727. }
  728. static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
  729. {
  730. struct ipath_ah *ah = to_iah(ibah);
  731. *ah_attr = ah->attr;
  732. return 0;
  733. }
  734. static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
  735. u16 *pkey)
  736. {
  737. struct ipath_ibdev *dev = to_idev(ibdev);
  738. int ret;
  739. if (index >= ipath_layer_get_npkeys(dev->dd)) {
  740. ret = -EINVAL;
  741. goto bail;
  742. }
  743. *pkey = ipath_layer_get_pkey(dev->dd, index);
  744. ret = 0;
  745. bail:
  746. return ret;
  747. }
  748. /**
  749. * ipath_alloc_ucontext - allocate a ucontest
  750. * @ibdev: the infiniband device
  751. * @udata: not used by the InfiniPath driver
  752. */
  753. static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
  754. struct ib_udata *udata)
  755. {
  756. struct ipath_ucontext *context;
  757. struct ib_ucontext *ret;
  758. context = kmalloc(sizeof *context, GFP_KERNEL);
  759. if (!context) {
  760. ret = ERR_PTR(-ENOMEM);
  761. goto bail;
  762. }
  763. ret = &context->ibucontext;
  764. bail:
  765. return ret;
  766. }
  767. static int ipath_dealloc_ucontext(struct ib_ucontext *context)
  768. {
  769. kfree(to_iucontext(context));
  770. return 0;
  771. }
  772. static int ipath_verbs_register_sysfs(struct ib_device *dev);
  773. /**
  774. * ipath_register_ib_device - register our device with the infiniband core
  775. * @unit: the device number to register
  776. * @dd: the device data structure
  777. * Return the allocated ipath_ibdev pointer or NULL on error.
  778. */
  779. static void *ipath_register_ib_device(int unit, struct ipath_devdata *dd)
  780. {
  781. struct ipath_ibdev *idev;
  782. struct ib_device *dev;
  783. int ret;
  784. idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
  785. if (idev == NULL)
  786. goto bail;
  787. dev = &idev->ibdev;
  788. /* Only need to initialize non-zero fields. */
  789. spin_lock_init(&idev->qp_table.lock);
  790. spin_lock_init(&idev->lk_table.lock);
  791. idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  792. /* Set the prefix to the default value (see ch. 4.1.1) */
  793. idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
  794. ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
  795. if (ret)
  796. goto err_qp;
  797. /*
  798. * The top ib_ipath_lkey_table_size bits are used to index the
  799. * table. The lower 8 bits can be owned by the user (copied from
  800. * the LKEY). The remaining bits act as a generation number or tag.
  801. */
  802. idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
  803. idev->lk_table.table = kzalloc(idev->lk_table.max *
  804. sizeof(*idev->lk_table.table),
  805. GFP_KERNEL);
  806. if (idev->lk_table.table == NULL) {
  807. ret = -ENOMEM;
  808. goto err_lk;
  809. }
  810. spin_lock_init(&idev->pending_lock);
  811. INIT_LIST_HEAD(&idev->pending[0]);
  812. INIT_LIST_HEAD(&idev->pending[1]);
  813. INIT_LIST_HEAD(&idev->pending[2]);
  814. INIT_LIST_HEAD(&idev->piowait);
  815. INIT_LIST_HEAD(&idev->rnrwait);
  816. idev->pending_index = 0;
  817. idev->port_cap_flags =
  818. IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
  819. idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  820. idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  821. idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  822. idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  823. idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT;
  824. idev->link_width_enabled = 3; /* 1x or 4x */
  825. /*
  826. * The system image GUID is supposed to be the same for all
  827. * IB HCAs in a single system but since there can be other
  828. * device types in the system, we can't be sure this is unique.
  829. */
  830. if (!sys_image_guid)
  831. sys_image_guid = ipath_layer_get_guid(dd);
  832. idev->sys_image_guid = sys_image_guid;
  833. idev->ib_unit = unit;
  834. idev->dd = dd;
  835. strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
  836. dev->owner = THIS_MODULE;
  837. dev->node_guid = ipath_layer_get_guid(dd);
  838. dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
  839. dev->uverbs_cmd_mask =
  840. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  841. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  842. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  843. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  844. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  845. (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
  846. (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
  847. (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
  848. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  849. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  850. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  851. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  852. (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
  853. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  854. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  855. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  856. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  857. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  858. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  859. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  860. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  861. (1ull << IB_USER_VERBS_CMD_POST_RECV) |
  862. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  863. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
  864. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  865. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  866. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  867. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
  868. (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
  869. dev->node_type = IB_NODE_CA;
  870. dev->phys_port_cnt = 1;
  871. dev->dma_device = ipath_layer_get_device(dd);
  872. dev->class_dev.dev = dev->dma_device;
  873. dev->query_device = ipath_query_device;
  874. dev->modify_device = ipath_modify_device;
  875. dev->query_port = ipath_query_port;
  876. dev->modify_port = ipath_modify_port;
  877. dev->query_pkey = ipath_query_pkey;
  878. dev->query_gid = ipath_query_gid;
  879. dev->alloc_ucontext = ipath_alloc_ucontext;
  880. dev->dealloc_ucontext = ipath_dealloc_ucontext;
  881. dev->alloc_pd = ipath_alloc_pd;
  882. dev->dealloc_pd = ipath_dealloc_pd;
  883. dev->create_ah = ipath_create_ah;
  884. dev->destroy_ah = ipath_destroy_ah;
  885. dev->query_ah = ipath_query_ah;
  886. dev->create_srq = ipath_create_srq;
  887. dev->modify_srq = ipath_modify_srq;
  888. dev->query_srq = ipath_query_srq;
  889. dev->destroy_srq = ipath_destroy_srq;
  890. dev->create_qp = ipath_create_qp;
  891. dev->modify_qp = ipath_modify_qp;
  892. dev->query_qp = ipath_query_qp;
  893. dev->destroy_qp = ipath_destroy_qp;
  894. dev->post_send = ipath_post_send;
  895. dev->post_recv = ipath_post_receive;
  896. dev->post_srq_recv = ipath_post_srq_receive;
  897. dev->create_cq = ipath_create_cq;
  898. dev->destroy_cq = ipath_destroy_cq;
  899. dev->resize_cq = ipath_resize_cq;
  900. dev->poll_cq = ipath_poll_cq;
  901. dev->req_notify_cq = ipath_req_notify_cq;
  902. dev->get_dma_mr = ipath_get_dma_mr;
  903. dev->reg_phys_mr = ipath_reg_phys_mr;
  904. dev->reg_user_mr = ipath_reg_user_mr;
  905. dev->dereg_mr = ipath_dereg_mr;
  906. dev->alloc_fmr = ipath_alloc_fmr;
  907. dev->map_phys_fmr = ipath_map_phys_fmr;
  908. dev->unmap_fmr = ipath_unmap_fmr;
  909. dev->dealloc_fmr = ipath_dealloc_fmr;
  910. dev->attach_mcast = ipath_multicast_attach;
  911. dev->detach_mcast = ipath_multicast_detach;
  912. dev->process_mad = ipath_process_mad;
  913. snprintf(dev->node_desc, sizeof(dev->node_desc),
  914. IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename);
  915. ret = ib_register_device(dev);
  916. if (ret)
  917. goto err_reg;
  918. if (ipath_verbs_register_sysfs(dev))
  919. goto err_class;
  920. ipath_layer_enable_timer(dd);
  921. goto bail;
  922. err_class:
  923. ib_unregister_device(dev);
  924. err_reg:
  925. kfree(idev->lk_table.table);
  926. err_lk:
  927. kfree(idev->qp_table.table);
  928. err_qp:
  929. ib_dealloc_device(dev);
  930. _VERBS_ERROR("ib_ipath%d cannot register verbs (%d)!\n",
  931. unit, -ret);
  932. idev = NULL;
  933. bail:
  934. return idev;
  935. }
  936. static void ipath_unregister_ib_device(void *arg)
  937. {
  938. struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
  939. struct ib_device *ibdev = &dev->ibdev;
  940. ipath_layer_disable_timer(dev->dd);
  941. ib_unregister_device(ibdev);
  942. if (!list_empty(&dev->pending[0]) ||
  943. !list_empty(&dev->pending[1]) ||
  944. !list_empty(&dev->pending[2]))
  945. _VERBS_ERROR("ipath%d pending list not empty!\n",
  946. dev->ib_unit);
  947. if (!list_empty(&dev->piowait))
  948. _VERBS_ERROR("ipath%d piowait list not empty!\n",
  949. dev->ib_unit);
  950. if (!list_empty(&dev->rnrwait))
  951. _VERBS_ERROR("ipath%d rnrwait list not empty!\n",
  952. dev->ib_unit);
  953. if (!ipath_mcast_tree_empty())
  954. _VERBS_ERROR("ipath%d multicast table memory leak!\n",
  955. dev->ib_unit);
  956. /*
  957. * Note that ipath_unregister_ib_device() can be called before all
  958. * the QPs are destroyed!
  959. */
  960. ipath_free_all_qps(&dev->qp_table);
  961. kfree(dev->qp_table.table);
  962. kfree(dev->lk_table.table);
  963. ib_dealloc_device(ibdev);
  964. }
  965. static int __init ipath_verbs_init(void)
  966. {
  967. return ipath_verbs_register(ipath_register_ib_device,
  968. ipath_unregister_ib_device,
  969. ipath_ib_piobufavail, ipath_ib_rcv,
  970. ipath_ib_timer);
  971. }
  972. static void __exit ipath_verbs_cleanup(void)
  973. {
  974. ipath_verbs_unregister();
  975. }
  976. static ssize_t show_rev(struct class_device *cdev, char *buf)
  977. {
  978. struct ipath_ibdev *dev =
  979. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  980. int vendor, boardrev, majrev, minrev;
  981. ipath_layer_query_device(dev->dd, &vendor, &boardrev,
  982. &majrev, &minrev);
  983. return sprintf(buf, "%d.%d\n", majrev, minrev);
  984. }
  985. static ssize_t show_hca(struct class_device *cdev, char *buf)
  986. {
  987. struct ipath_ibdev *dev =
  988. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  989. int ret;
  990. ret = ipath_layer_get_boardname(dev->dd, buf, 128);
  991. if (ret < 0)
  992. goto bail;
  993. strcat(buf, "\n");
  994. ret = strlen(buf);
  995. bail:
  996. return ret;
  997. }
  998. static ssize_t show_stats(struct class_device *cdev, char *buf)
  999. {
  1000. struct ipath_ibdev *dev =
  1001. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1002. int i;
  1003. int len;
  1004. len = sprintf(buf,
  1005. "RC resends %d\n"
  1006. "RC no QACK %d\n"
  1007. "RC ACKs %d\n"
  1008. "RC SEQ NAKs %d\n"
  1009. "RC RDMA seq %d\n"
  1010. "RC RNR NAKs %d\n"
  1011. "RC OTH NAKs %d\n"
  1012. "RC timeouts %d\n"
  1013. "RC RDMA dup %d\n"
  1014. "piobuf wait %d\n"
  1015. "no piobuf %d\n"
  1016. "PKT drops %d\n"
  1017. "WQE errs %d\n",
  1018. dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
  1019. dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
  1020. dev->n_other_naks, dev->n_timeouts,
  1021. dev->n_rdma_dup_busy, dev->n_piowait,
  1022. dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
  1023. for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
  1024. const struct ipath_opcode_stats *si = &dev->opstats[i];
  1025. if (!si->n_packets && !si->n_bytes)
  1026. continue;
  1027. len += sprintf(buf + len, "%02x %llu/%llu\n", i,
  1028. (unsigned long long) si->n_packets,
  1029. (unsigned long long) si->n_bytes);
  1030. }
  1031. return len;
  1032. }
  1033. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  1034. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  1035. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  1036. static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  1037. static struct class_device_attribute *ipath_class_attributes[] = {
  1038. &class_device_attr_hw_rev,
  1039. &class_device_attr_hca_type,
  1040. &class_device_attr_board_id,
  1041. &class_device_attr_stats
  1042. };
  1043. static int ipath_verbs_register_sysfs(struct ib_device *dev)
  1044. {
  1045. int i;
  1046. int ret;
  1047. for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
  1048. if (class_device_create_file(&dev->class_dev,
  1049. ipath_class_attributes[i])) {
  1050. ret = 1;
  1051. goto bail;
  1052. }
  1053. ret = 0;
  1054. bail:
  1055. return ret;
  1056. }
  1057. module_init(ipath_verbs_init);
  1058. module_exit(ipath_verbs_cleanup);