ipath_verbs.c 35 KB

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