ipath_verbs.c 31 KB

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