ipath_verbs.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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 ipath_qp *rnr = 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. if (last->next == LIST_POISON1 ||
  423. last->next != &qp->timerwait ||
  424. qp->timerwait.prev != last) {
  425. INIT_LIST_HEAD(last);
  426. } else {
  427. list_del(&qp->timerwait);
  428. qp->timerwait.prev = (struct list_head *) resend;
  429. resend = qp;
  430. atomic_inc(&qp->refcount);
  431. }
  432. }
  433. last = &dev->rnrwait;
  434. if (!list_empty(last)) {
  435. qp = list_entry(last->next, struct ipath_qp, timerwait);
  436. if (--qp->s_rnr_timeout == 0) {
  437. do {
  438. if (last->next == LIST_POISON1 ||
  439. last->next != &qp->timerwait ||
  440. qp->timerwait.prev != last) {
  441. INIT_LIST_HEAD(last);
  442. break;
  443. }
  444. list_del(&qp->timerwait);
  445. qp->timerwait.prev =
  446. (struct list_head *) rnr;
  447. rnr = qp;
  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_layer_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_layer_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;
  485. qp = (struct ipath_qp *) qp->timerwait.prev) {
  486. struct ib_wc wc;
  487. spin_lock_irqsave(&qp->s_lock, flags);
  488. if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) {
  489. dev->n_timeouts++;
  490. ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
  491. }
  492. spin_unlock_irqrestore(&qp->s_lock, flags);
  493. /* Notify ipath_destroy_qp() if it is waiting. */
  494. if (atomic_dec_and_test(&qp->refcount))
  495. wake_up(&qp->wait);
  496. }
  497. for (qp = rnr; qp != NULL;
  498. qp = (struct ipath_qp *) qp->timerwait.prev)
  499. tasklet_hi_schedule(&qp->s_task);
  500. }
  501. /**
  502. * ipath_ib_piobufavail - callback when a PIO buffer is available
  503. * @arg: the device pointer
  504. *
  505. * This is called from ipath_intr() at interrupt level when a PIO buffer is
  506. * available after ipath_verbs_send() returned an error that no buffers were
  507. * available. Return 0 if we consumed all the PIO buffers and we still have
  508. * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and
  509. * return one).
  510. */
  511. static int ipath_ib_piobufavail(void *arg)
  512. {
  513. struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
  514. struct ipath_qp *qp;
  515. unsigned long flags;
  516. if (dev == NULL)
  517. goto bail;
  518. spin_lock_irqsave(&dev->pending_lock, flags);
  519. while (!list_empty(&dev->piowait)) {
  520. qp = list_entry(dev->piowait.next, struct ipath_qp,
  521. piowait);
  522. list_del(&qp->piowait);
  523. tasklet_hi_schedule(&qp->s_task);
  524. }
  525. spin_unlock_irqrestore(&dev->pending_lock, flags);
  526. bail:
  527. return 1;
  528. }
  529. static int ipath_query_device(struct ib_device *ibdev,
  530. struct ib_device_attr *props)
  531. {
  532. struct ipath_ibdev *dev = to_idev(ibdev);
  533. u32 vendor, boardrev, majrev, minrev;
  534. memset(props, 0, sizeof(*props));
  535. props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
  536. IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
  537. IB_DEVICE_SYS_IMAGE_GUID;
  538. ipath_layer_query_device(dev->dd, &vendor, &boardrev,
  539. &majrev, &minrev);
  540. props->vendor_id = vendor;
  541. props->vendor_part_id = boardrev;
  542. props->hw_ver = boardrev << 16 | majrev << 8 | minrev;
  543. props->sys_image_guid = dev->sys_image_guid;
  544. props->max_mr_size = ~0ull;
  545. props->max_qp = 0xffff;
  546. props->max_qp_wr = 0xffff;
  547. props->max_sge = 255;
  548. props->max_cq = 0xffff;
  549. props->max_cqe = 0xffff;
  550. props->max_mr = 0xffff;
  551. props->max_pd = 0xffff;
  552. props->max_qp_rd_atom = 1;
  553. props->max_qp_init_rd_atom = 1;
  554. /* props->max_res_rd_atom */
  555. props->max_srq = 0xffff;
  556. props->max_srq_wr = 0xffff;
  557. props->max_srq_sge = 255;
  558. /* props->local_ca_ack_delay */
  559. props->atomic_cap = IB_ATOMIC_HCA;
  560. props->max_pkeys = ipath_layer_get_npkeys(dev->dd);
  561. props->max_mcast_grp = 0xffff;
  562. props->max_mcast_qp_attach = 0xffff;
  563. props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
  564. props->max_mcast_grp;
  565. return 0;
  566. }
  567. const u8 ipath_cvt_physportstate[16] = {
  568. [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3,
  569. [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5,
  570. [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2,
  571. [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2,
  572. [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1,
  573. [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1,
  574. [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4,
  575. [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4,
  576. [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4,
  577. [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4,
  578. [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6,
  579. [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6,
  580. [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6,
  581. };
  582. static int ipath_query_port(struct ib_device *ibdev,
  583. u8 port, struct ib_port_attr *props)
  584. {
  585. struct ipath_ibdev *dev = to_idev(ibdev);
  586. enum ib_mtu mtu;
  587. u16 lid = ipath_layer_get_lid(dev->dd);
  588. u64 ibcstat;
  589. memset(props, 0, sizeof(*props));
  590. props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  591. props->lmc = dev->mkeyprot_resv_lmc & 7;
  592. props->sm_lid = dev->sm_lid;
  593. props->sm_sl = dev->sm_sl;
  594. ibcstat = ipath_layer_get_lastibcstat(dev->dd);
  595. props->state = ((ibcstat >> 4) & 0x3) + 1;
  596. /* See phys_state_show() */
  597. props->phys_state = ipath_cvt_physportstate[
  598. ipath_layer_get_lastibcstat(dev->dd) & 0xf];
  599. props->port_cap_flags = dev->port_cap_flags;
  600. props->gid_tbl_len = 1;
  601. props->max_msg_sz = 4096;
  602. props->pkey_tbl_len = ipath_layer_get_npkeys(dev->dd);
  603. props->bad_pkey_cntr = ipath_layer_get_cr_errpkey(dev->dd) -
  604. dev->n_pkey_violations;
  605. props->qkey_viol_cntr = dev->qkey_violations;
  606. props->active_width = IB_WIDTH_4X;
  607. /* See rate_show() */
  608. props->active_speed = 1; /* Regular 10Mbs speed. */
  609. props->max_vl_num = 1; /* VLCap = VL0 */
  610. props->init_type_reply = 0;
  611. props->max_mtu = IB_MTU_4096;
  612. switch (ipath_layer_get_ibmtu(dev->dd)) {
  613. case 4096:
  614. mtu = IB_MTU_4096;
  615. break;
  616. case 2048:
  617. mtu = IB_MTU_2048;
  618. break;
  619. case 1024:
  620. mtu = IB_MTU_1024;
  621. break;
  622. case 512:
  623. mtu = IB_MTU_512;
  624. break;
  625. case 256:
  626. mtu = IB_MTU_256;
  627. break;
  628. default:
  629. mtu = IB_MTU_2048;
  630. }
  631. props->active_mtu = mtu;
  632. props->subnet_timeout = dev->subnet_timeout;
  633. return 0;
  634. }
  635. static int ipath_modify_device(struct ib_device *device,
  636. int device_modify_mask,
  637. struct ib_device_modify *device_modify)
  638. {
  639. int ret;
  640. if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
  641. IB_DEVICE_MODIFY_NODE_DESC)) {
  642. ret = -EOPNOTSUPP;
  643. goto bail;
  644. }
  645. if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
  646. memcpy(device->node_desc, device_modify->node_desc, 64);
  647. if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
  648. to_idev(device)->sys_image_guid =
  649. cpu_to_be64(device_modify->sys_image_guid);
  650. ret = 0;
  651. bail:
  652. return ret;
  653. }
  654. static int ipath_modify_port(struct ib_device *ibdev,
  655. u8 port, int port_modify_mask,
  656. struct ib_port_modify *props)
  657. {
  658. struct ipath_ibdev *dev = to_idev(ibdev);
  659. dev->port_cap_flags |= props->set_port_cap_mask;
  660. dev->port_cap_flags &= ~props->clr_port_cap_mask;
  661. if (port_modify_mask & IB_PORT_SHUTDOWN)
  662. ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
  663. if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
  664. dev->qkey_violations = 0;
  665. return 0;
  666. }
  667. static int ipath_query_gid(struct ib_device *ibdev, u8 port,
  668. int index, union ib_gid *gid)
  669. {
  670. struct ipath_ibdev *dev = to_idev(ibdev);
  671. int ret;
  672. if (index >= 1) {
  673. ret = -EINVAL;
  674. goto bail;
  675. }
  676. gid->global.subnet_prefix = dev->gid_prefix;
  677. gid->global.interface_id = ipath_layer_get_guid(dev->dd);
  678. ret = 0;
  679. bail:
  680. return ret;
  681. }
  682. static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
  683. struct ib_ucontext *context,
  684. struct ib_udata *udata)
  685. {
  686. struct ipath_pd *pd;
  687. struct ib_pd *ret;
  688. pd = kmalloc(sizeof *pd, GFP_KERNEL);
  689. if (!pd) {
  690. ret = ERR_PTR(-ENOMEM);
  691. goto bail;
  692. }
  693. /* ib_alloc_pd() will initialize pd->ibpd. */
  694. pd->user = udata != NULL;
  695. ret = &pd->ibpd;
  696. bail:
  697. return ret;
  698. }
  699. static int ipath_dealloc_pd(struct ib_pd *ibpd)
  700. {
  701. struct ipath_pd *pd = to_ipd(ibpd);
  702. kfree(pd);
  703. return 0;
  704. }
  705. /**
  706. * ipath_create_ah - create an address handle
  707. * @pd: the protection domain
  708. * @ah_attr: the attributes of the AH
  709. *
  710. * This may be called from interrupt context.
  711. */
  712. static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
  713. struct ib_ah_attr *ah_attr)
  714. {
  715. struct ipath_ah *ah;
  716. struct ib_ah *ret;
  717. /* A multicast address requires a GRH (see ch. 8.4.1). */
  718. if (ah_attr->dlid >= IPS_MULTICAST_LID_BASE &&
  719. ah_attr->dlid != IPS_PERMISSIVE_LID &&
  720. !(ah_attr->ah_flags & IB_AH_GRH)) {
  721. ret = ERR_PTR(-EINVAL);
  722. goto bail;
  723. }
  724. ah = kmalloc(sizeof *ah, GFP_ATOMIC);
  725. if (!ah) {
  726. ret = ERR_PTR(-ENOMEM);
  727. goto bail;
  728. }
  729. /* ib_create_ah() will initialize ah->ibah. */
  730. ah->attr = *ah_attr;
  731. ret = &ah->ibah;
  732. bail:
  733. return ret;
  734. }
  735. /**
  736. * ipath_destroy_ah - destroy an address handle
  737. * @ibah: the AH to destroy
  738. *
  739. * This may be called from interrupt context.
  740. */
  741. static int ipath_destroy_ah(struct ib_ah *ibah)
  742. {
  743. struct ipath_ah *ah = to_iah(ibah);
  744. kfree(ah);
  745. return 0;
  746. }
  747. static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
  748. {
  749. struct ipath_ah *ah = to_iah(ibah);
  750. *ah_attr = ah->attr;
  751. return 0;
  752. }
  753. static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
  754. u16 *pkey)
  755. {
  756. struct ipath_ibdev *dev = to_idev(ibdev);
  757. int ret;
  758. if (index >= ipath_layer_get_npkeys(dev->dd)) {
  759. ret = -EINVAL;
  760. goto bail;
  761. }
  762. *pkey = ipath_layer_get_pkey(dev->dd, index);
  763. ret = 0;
  764. bail:
  765. return ret;
  766. }
  767. /**
  768. * ipath_alloc_ucontext - allocate a ucontest
  769. * @ibdev: the infiniband device
  770. * @udata: not used by the InfiniPath driver
  771. */
  772. static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
  773. struct ib_udata *udata)
  774. {
  775. struct ipath_ucontext *context;
  776. struct ib_ucontext *ret;
  777. context = kmalloc(sizeof *context, GFP_KERNEL);
  778. if (!context) {
  779. ret = ERR_PTR(-ENOMEM);
  780. goto bail;
  781. }
  782. ret = &context->ibucontext;
  783. bail:
  784. return ret;
  785. }
  786. static int ipath_dealloc_ucontext(struct ib_ucontext *context)
  787. {
  788. kfree(to_iucontext(context));
  789. return 0;
  790. }
  791. static int ipath_verbs_register_sysfs(struct ib_device *dev);
  792. /**
  793. * ipath_register_ib_device - register our device with the infiniband core
  794. * @unit: the device number to register
  795. * @dd: the device data structure
  796. * Return the allocated ipath_ibdev pointer or NULL on error.
  797. */
  798. static void *ipath_register_ib_device(int unit, struct ipath_devdata *dd)
  799. {
  800. struct ipath_ibdev *idev;
  801. struct ib_device *dev;
  802. int ret;
  803. idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
  804. if (idev == NULL)
  805. goto bail;
  806. dev = &idev->ibdev;
  807. /* Only need to initialize non-zero fields. */
  808. spin_lock_init(&idev->qp_table.lock);
  809. spin_lock_init(&idev->lk_table.lock);
  810. idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  811. /* Set the prefix to the default value (see ch. 4.1.1) */
  812. idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
  813. ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
  814. if (ret)
  815. goto err_qp;
  816. /*
  817. * The top ib_ipath_lkey_table_size bits are used to index the
  818. * table. The lower 8 bits can be owned by the user (copied from
  819. * the LKEY). The remaining bits act as a generation number or tag.
  820. */
  821. idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
  822. idev->lk_table.table = kzalloc(idev->lk_table.max *
  823. sizeof(*idev->lk_table.table),
  824. GFP_KERNEL);
  825. if (idev->lk_table.table == NULL) {
  826. ret = -ENOMEM;
  827. goto err_lk;
  828. }
  829. spin_lock_init(&idev->pending_lock);
  830. INIT_LIST_HEAD(&idev->pending[0]);
  831. INIT_LIST_HEAD(&idev->pending[1]);
  832. INIT_LIST_HEAD(&idev->pending[2]);
  833. INIT_LIST_HEAD(&idev->piowait);
  834. INIT_LIST_HEAD(&idev->rnrwait);
  835. idev->pending_index = 0;
  836. idev->port_cap_flags =
  837. IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
  838. idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  839. idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  840. idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  841. idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  842. idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT;
  843. idev->link_width_enabled = 3; /* 1x or 4x */
  844. /*
  845. * The system image GUID is supposed to be the same for all
  846. * IB HCAs in a single system but since there can be other
  847. * device types in the system, we can't be sure this is unique.
  848. */
  849. if (!sys_image_guid)
  850. sys_image_guid = ipath_layer_get_guid(dd);
  851. idev->sys_image_guid = sys_image_guid;
  852. idev->ib_unit = unit;
  853. idev->dd = dd;
  854. strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
  855. dev->node_guid = ipath_layer_get_guid(dd);
  856. dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
  857. dev->uverbs_cmd_mask =
  858. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  859. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  860. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  861. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  862. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  863. (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
  864. (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
  865. (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
  866. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  867. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  868. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  869. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  870. (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
  871. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  872. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  873. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  874. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  875. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  876. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  877. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  878. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  879. (1ull << IB_USER_VERBS_CMD_POST_RECV) |
  880. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  881. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
  882. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  883. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  884. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  885. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
  886. (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
  887. dev->node_type = IB_NODE_CA;
  888. dev->phys_port_cnt = 1;
  889. dev->dma_device = ipath_layer_get_device(dd);
  890. dev->class_dev.dev = dev->dma_device;
  891. dev->query_device = ipath_query_device;
  892. dev->modify_device = ipath_modify_device;
  893. dev->query_port = ipath_query_port;
  894. dev->modify_port = ipath_modify_port;
  895. dev->query_pkey = ipath_query_pkey;
  896. dev->query_gid = ipath_query_gid;
  897. dev->alloc_ucontext = ipath_alloc_ucontext;
  898. dev->dealloc_ucontext = ipath_dealloc_ucontext;
  899. dev->alloc_pd = ipath_alloc_pd;
  900. dev->dealloc_pd = ipath_dealloc_pd;
  901. dev->create_ah = ipath_create_ah;
  902. dev->destroy_ah = ipath_destroy_ah;
  903. dev->query_ah = ipath_query_ah;
  904. dev->create_srq = ipath_create_srq;
  905. dev->modify_srq = ipath_modify_srq;
  906. dev->query_srq = ipath_query_srq;
  907. dev->destroy_srq = ipath_destroy_srq;
  908. dev->create_qp = ipath_create_qp;
  909. dev->modify_qp = ipath_modify_qp;
  910. dev->query_qp = ipath_query_qp;
  911. dev->destroy_qp = ipath_destroy_qp;
  912. dev->post_send = ipath_post_send;
  913. dev->post_recv = ipath_post_receive;
  914. dev->post_srq_recv = ipath_post_srq_receive;
  915. dev->create_cq = ipath_create_cq;
  916. dev->destroy_cq = ipath_destroy_cq;
  917. dev->resize_cq = ipath_resize_cq;
  918. dev->poll_cq = ipath_poll_cq;
  919. dev->req_notify_cq = ipath_req_notify_cq;
  920. dev->get_dma_mr = ipath_get_dma_mr;
  921. dev->reg_phys_mr = ipath_reg_phys_mr;
  922. dev->reg_user_mr = ipath_reg_user_mr;
  923. dev->dereg_mr = ipath_dereg_mr;
  924. dev->alloc_fmr = ipath_alloc_fmr;
  925. dev->map_phys_fmr = ipath_map_phys_fmr;
  926. dev->unmap_fmr = ipath_unmap_fmr;
  927. dev->dealloc_fmr = ipath_dealloc_fmr;
  928. dev->attach_mcast = ipath_multicast_attach;
  929. dev->detach_mcast = ipath_multicast_detach;
  930. dev->process_mad = ipath_process_mad;
  931. snprintf(dev->node_desc, sizeof(dev->node_desc),
  932. IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename);
  933. ret = ib_register_device(dev);
  934. if (ret)
  935. goto err_reg;
  936. if (ipath_verbs_register_sysfs(dev))
  937. goto err_class;
  938. ipath_layer_enable_timer(dd);
  939. goto bail;
  940. err_class:
  941. ib_unregister_device(dev);
  942. err_reg:
  943. kfree(idev->lk_table.table);
  944. err_lk:
  945. kfree(idev->qp_table.table);
  946. err_qp:
  947. ib_dealloc_device(dev);
  948. _VERBS_ERROR("ib_ipath%d cannot register verbs (%d)!\n",
  949. unit, -ret);
  950. idev = NULL;
  951. bail:
  952. return idev;
  953. }
  954. static void ipath_unregister_ib_device(void *arg)
  955. {
  956. struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
  957. struct ib_device *ibdev = &dev->ibdev;
  958. ipath_layer_disable_timer(dev->dd);
  959. ib_unregister_device(ibdev);
  960. if (!list_empty(&dev->pending[0]) ||
  961. !list_empty(&dev->pending[1]) ||
  962. !list_empty(&dev->pending[2]))
  963. _VERBS_ERROR("ipath%d pending list not empty!\n",
  964. dev->ib_unit);
  965. if (!list_empty(&dev->piowait))
  966. _VERBS_ERROR("ipath%d piowait list not empty!\n",
  967. dev->ib_unit);
  968. if (!list_empty(&dev->rnrwait))
  969. _VERBS_ERROR("ipath%d rnrwait list not empty!\n",
  970. dev->ib_unit);
  971. if (!ipath_mcast_tree_empty())
  972. _VERBS_ERROR("ipath%d multicast table memory leak!\n",
  973. dev->ib_unit);
  974. /*
  975. * Note that ipath_unregister_ib_device() can be called before all
  976. * the QPs are destroyed!
  977. */
  978. ipath_free_all_qps(&dev->qp_table);
  979. kfree(dev->qp_table.table);
  980. kfree(dev->lk_table.table);
  981. ib_dealloc_device(ibdev);
  982. }
  983. static int __init ipath_verbs_init(void)
  984. {
  985. return ipath_verbs_register(ipath_register_ib_device,
  986. ipath_unregister_ib_device,
  987. ipath_ib_piobufavail, ipath_ib_rcv,
  988. ipath_ib_timer);
  989. }
  990. static void __exit ipath_verbs_cleanup(void)
  991. {
  992. ipath_verbs_unregister();
  993. }
  994. static ssize_t show_rev(struct class_device *cdev, char *buf)
  995. {
  996. struct ipath_ibdev *dev =
  997. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  998. int vendor, boardrev, majrev, minrev;
  999. ipath_layer_query_device(dev->dd, &vendor, &boardrev,
  1000. &majrev, &minrev);
  1001. return sprintf(buf, "%d.%d\n", majrev, minrev);
  1002. }
  1003. static ssize_t show_hca(struct class_device *cdev, char *buf)
  1004. {
  1005. struct ipath_ibdev *dev =
  1006. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1007. int ret;
  1008. ret = ipath_layer_get_boardname(dev->dd, buf, 128);
  1009. if (ret < 0)
  1010. goto bail;
  1011. strcat(buf, "\n");
  1012. ret = strlen(buf);
  1013. bail:
  1014. return ret;
  1015. }
  1016. static ssize_t show_stats(struct class_device *cdev, char *buf)
  1017. {
  1018. struct ipath_ibdev *dev =
  1019. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1020. int i;
  1021. int len;
  1022. len = sprintf(buf,
  1023. "RC resends %d\n"
  1024. "RC QACKs %d\n"
  1025. "RC ACKs %d\n"
  1026. "RC SEQ NAKs %d\n"
  1027. "RC RDMA seq %d\n"
  1028. "RC RNR NAKs %d\n"
  1029. "RC OTH NAKs %d\n"
  1030. "RC timeouts %d\n"
  1031. "RC RDMA dup %d\n"
  1032. "piobuf wait %d\n"
  1033. "no piobuf %d\n"
  1034. "PKT drops %d\n"
  1035. "WQE errs %d\n",
  1036. dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
  1037. dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
  1038. dev->n_other_naks, dev->n_timeouts,
  1039. dev->n_rdma_dup_busy, dev->n_piowait,
  1040. dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
  1041. for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
  1042. const struct ipath_opcode_stats *si = &dev->opstats[i];
  1043. if (!si->n_packets && !si->n_bytes)
  1044. continue;
  1045. len += sprintf(buf + len, "%02x %llu/%llu\n", i,
  1046. (unsigned long long) si->n_packets,
  1047. (unsigned long long) si->n_bytes);
  1048. }
  1049. return len;
  1050. }
  1051. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  1052. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  1053. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  1054. static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  1055. static struct class_device_attribute *ipath_class_attributes[] = {
  1056. &class_device_attr_hw_rev,
  1057. &class_device_attr_hca_type,
  1058. &class_device_attr_board_id,
  1059. &class_device_attr_stats
  1060. };
  1061. static int ipath_verbs_register_sysfs(struct ib_device *dev)
  1062. {
  1063. int i;
  1064. int ret;
  1065. for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
  1066. if (class_device_create_file(&dev->class_dev,
  1067. ipath_class_attributes[i])) {
  1068. ret = 1;
  1069. goto bail;
  1070. }
  1071. ret = 0;
  1072. bail:
  1073. return ret;
  1074. }
  1075. module_init(ipath_verbs_init);
  1076. module_exit(ipath_verbs_cleanup);