ipath_verbs.c 34 KB

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