ipath_verbs.c 31 KB

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