ipath_verbs.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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 > 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 < IPATH_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 == IPATH_LRH_BTH)
  393. ohdr = &hdr->u.oth;
  394. else if (lnh == IPATH_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]) & IPATH_QPN_MASK;
  405. if (qp_num == IPATH_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 == IPATH_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 == IPATH_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 = 0x80000000;
  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 >= IPATH_MULTICAST_LID_BASE &&
  760. ah_attr->dlid != IPATH_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_layer_counters cntrs;
  854. struct ipath_ibdev *idev;
  855. struct ib_device *dev;
  856. int ret;
  857. idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
  858. if (idev == NULL)
  859. goto bail;
  860. dev = &idev->ibdev;
  861. /* Only need to initialize non-zero fields. */
  862. spin_lock_init(&idev->qp_table.lock);
  863. spin_lock_init(&idev->lk_table.lock);
  864. idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  865. /* Set the prefix to the default value (see ch. 4.1.1) */
  866. idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
  867. ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
  868. if (ret)
  869. goto err_qp;
  870. /*
  871. * The top ib_ipath_lkey_table_size bits are used to index the
  872. * table. The lower 8 bits can be owned by the user (copied from
  873. * the LKEY). The remaining bits act as a generation number or tag.
  874. */
  875. idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
  876. idev->lk_table.table = kzalloc(idev->lk_table.max *
  877. sizeof(*idev->lk_table.table),
  878. GFP_KERNEL);
  879. if (idev->lk_table.table == NULL) {
  880. ret = -ENOMEM;
  881. goto err_lk;
  882. }
  883. spin_lock_init(&idev->pending_lock);
  884. INIT_LIST_HEAD(&idev->pending[0]);
  885. INIT_LIST_HEAD(&idev->pending[1]);
  886. INIT_LIST_HEAD(&idev->pending[2]);
  887. INIT_LIST_HEAD(&idev->piowait);
  888. INIT_LIST_HEAD(&idev->rnrwait);
  889. idev->pending_index = 0;
  890. idev->port_cap_flags =
  891. IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
  892. idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  893. idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  894. idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  895. idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  896. idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT;
  897. idev->link_width_enabled = 3; /* 1x or 4x */
  898. /* Snapshot current HW counters to "clear" them. */
  899. ipath_layer_get_counters(dd, &cntrs);
  900. idev->z_symbol_error_counter = cntrs.symbol_error_counter;
  901. idev->z_link_error_recovery_counter =
  902. cntrs.link_error_recovery_counter;
  903. idev->z_link_downed_counter = cntrs.link_downed_counter;
  904. idev->z_port_rcv_errors = cntrs.port_rcv_errors;
  905. idev->z_port_rcv_remphys_errors =
  906. cntrs.port_rcv_remphys_errors;
  907. idev->z_port_xmit_discards = cntrs.port_xmit_discards;
  908. idev->z_port_xmit_data = cntrs.port_xmit_data;
  909. idev->z_port_rcv_data = cntrs.port_rcv_data;
  910. idev->z_port_xmit_packets = cntrs.port_xmit_packets;
  911. idev->z_port_rcv_packets = cntrs.port_rcv_packets;
  912. idev->z_local_link_integrity_errors =
  913. cntrs.local_link_integrity_errors;
  914. idev->z_excessive_buffer_overrun_errors =
  915. cntrs.excessive_buffer_overrun_errors;
  916. /*
  917. * The system image GUID is supposed to be the same for all
  918. * IB HCAs in a single system but since there can be other
  919. * device types in the system, we can't be sure this is unique.
  920. */
  921. if (!sys_image_guid)
  922. sys_image_guid = ipath_layer_get_guid(dd);
  923. idev->sys_image_guid = sys_image_guid;
  924. idev->ib_unit = unit;
  925. idev->dd = dd;
  926. strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
  927. dev->owner = THIS_MODULE;
  928. dev->node_guid = ipath_layer_get_guid(dd);
  929. dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
  930. dev->uverbs_cmd_mask =
  931. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  932. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  933. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  934. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  935. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  936. (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
  937. (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
  938. (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
  939. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  940. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  941. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  942. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  943. (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
  944. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  945. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  946. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  947. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  948. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  949. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  950. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  951. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  952. (1ull << IB_USER_VERBS_CMD_POST_RECV) |
  953. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  954. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
  955. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  956. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  957. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  958. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
  959. (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
  960. dev->node_type = IB_NODE_CA;
  961. dev->phys_port_cnt = 1;
  962. dev->dma_device = ipath_layer_get_device(dd);
  963. dev->class_dev.dev = dev->dma_device;
  964. dev->query_device = ipath_query_device;
  965. dev->modify_device = ipath_modify_device;
  966. dev->query_port = ipath_query_port;
  967. dev->modify_port = ipath_modify_port;
  968. dev->query_pkey = ipath_query_pkey;
  969. dev->query_gid = ipath_query_gid;
  970. dev->alloc_ucontext = ipath_alloc_ucontext;
  971. dev->dealloc_ucontext = ipath_dealloc_ucontext;
  972. dev->alloc_pd = ipath_alloc_pd;
  973. dev->dealloc_pd = ipath_dealloc_pd;
  974. dev->create_ah = ipath_create_ah;
  975. dev->destroy_ah = ipath_destroy_ah;
  976. dev->query_ah = ipath_query_ah;
  977. dev->create_srq = ipath_create_srq;
  978. dev->modify_srq = ipath_modify_srq;
  979. dev->query_srq = ipath_query_srq;
  980. dev->destroy_srq = ipath_destroy_srq;
  981. dev->create_qp = ipath_create_qp;
  982. dev->modify_qp = ipath_modify_qp;
  983. dev->query_qp = ipath_query_qp;
  984. dev->destroy_qp = ipath_destroy_qp;
  985. dev->post_send = ipath_post_send;
  986. dev->post_recv = ipath_post_receive;
  987. dev->post_srq_recv = ipath_post_srq_receive;
  988. dev->create_cq = ipath_create_cq;
  989. dev->destroy_cq = ipath_destroy_cq;
  990. dev->resize_cq = ipath_resize_cq;
  991. dev->poll_cq = ipath_poll_cq;
  992. dev->req_notify_cq = ipath_req_notify_cq;
  993. dev->get_dma_mr = ipath_get_dma_mr;
  994. dev->reg_phys_mr = ipath_reg_phys_mr;
  995. dev->reg_user_mr = ipath_reg_user_mr;
  996. dev->dereg_mr = ipath_dereg_mr;
  997. dev->alloc_fmr = ipath_alloc_fmr;
  998. dev->map_phys_fmr = ipath_map_phys_fmr;
  999. dev->unmap_fmr = ipath_unmap_fmr;
  1000. dev->dealloc_fmr = ipath_dealloc_fmr;
  1001. dev->attach_mcast = ipath_multicast_attach;
  1002. dev->detach_mcast = ipath_multicast_detach;
  1003. dev->process_mad = ipath_process_mad;
  1004. snprintf(dev->node_desc, sizeof(dev->node_desc),
  1005. IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename);
  1006. ret = ib_register_device(dev);
  1007. if (ret)
  1008. goto err_reg;
  1009. if (ipath_verbs_register_sysfs(dev))
  1010. goto err_class;
  1011. ipath_layer_enable_timer(dd);
  1012. goto bail;
  1013. err_class:
  1014. ib_unregister_device(dev);
  1015. err_reg:
  1016. kfree(idev->lk_table.table);
  1017. err_lk:
  1018. kfree(idev->qp_table.table);
  1019. err_qp:
  1020. ib_dealloc_device(dev);
  1021. _VERBS_ERROR("ib_ipath%d cannot register verbs (%d)!\n",
  1022. unit, -ret);
  1023. idev = NULL;
  1024. bail:
  1025. return idev;
  1026. }
  1027. static void ipath_unregister_ib_device(void *arg)
  1028. {
  1029. struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
  1030. struct ib_device *ibdev = &dev->ibdev;
  1031. ipath_layer_disable_timer(dev->dd);
  1032. ib_unregister_device(ibdev);
  1033. if (!list_empty(&dev->pending[0]) ||
  1034. !list_empty(&dev->pending[1]) ||
  1035. !list_empty(&dev->pending[2]))
  1036. _VERBS_ERROR("ipath%d pending list not empty!\n",
  1037. dev->ib_unit);
  1038. if (!list_empty(&dev->piowait))
  1039. _VERBS_ERROR("ipath%d piowait list not empty!\n",
  1040. dev->ib_unit);
  1041. if (!list_empty(&dev->rnrwait))
  1042. _VERBS_ERROR("ipath%d rnrwait list not empty!\n",
  1043. dev->ib_unit);
  1044. if (!ipath_mcast_tree_empty())
  1045. _VERBS_ERROR("ipath%d multicast table memory leak!\n",
  1046. dev->ib_unit);
  1047. /*
  1048. * Note that ipath_unregister_ib_device() can be called before all
  1049. * the QPs are destroyed!
  1050. */
  1051. ipath_free_all_qps(&dev->qp_table);
  1052. kfree(dev->qp_table.table);
  1053. kfree(dev->lk_table.table);
  1054. ib_dealloc_device(ibdev);
  1055. }
  1056. static int __init ipath_verbs_init(void)
  1057. {
  1058. return ipath_verbs_register(ipath_register_ib_device,
  1059. ipath_unregister_ib_device,
  1060. ipath_ib_piobufavail, ipath_ib_rcv,
  1061. ipath_ib_timer);
  1062. }
  1063. static void __exit ipath_verbs_cleanup(void)
  1064. {
  1065. ipath_verbs_unregister();
  1066. }
  1067. static ssize_t show_rev(struct class_device *cdev, char *buf)
  1068. {
  1069. struct ipath_ibdev *dev =
  1070. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1071. return sprintf(buf, "%x\n", ipath_layer_get_pcirev(dev->dd));
  1072. }
  1073. static ssize_t show_hca(struct class_device *cdev, char *buf)
  1074. {
  1075. struct ipath_ibdev *dev =
  1076. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1077. int ret;
  1078. ret = ipath_layer_get_boardname(dev->dd, buf, 128);
  1079. if (ret < 0)
  1080. goto bail;
  1081. strcat(buf, "\n");
  1082. ret = strlen(buf);
  1083. bail:
  1084. return ret;
  1085. }
  1086. static ssize_t show_stats(struct class_device *cdev, char *buf)
  1087. {
  1088. struct ipath_ibdev *dev =
  1089. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1090. int i;
  1091. int len;
  1092. len = sprintf(buf,
  1093. "RC resends %d\n"
  1094. "RC no QACK %d\n"
  1095. "RC ACKs %d\n"
  1096. "RC SEQ NAKs %d\n"
  1097. "RC RDMA seq %d\n"
  1098. "RC RNR NAKs %d\n"
  1099. "RC OTH NAKs %d\n"
  1100. "RC timeouts %d\n"
  1101. "RC RDMA dup %d\n"
  1102. "piobuf wait %d\n"
  1103. "no piobuf %d\n"
  1104. "PKT drops %d\n"
  1105. "WQE errs %d\n",
  1106. dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
  1107. dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
  1108. dev->n_other_naks, dev->n_timeouts,
  1109. dev->n_rdma_dup_busy, dev->n_piowait,
  1110. dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
  1111. for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
  1112. const struct ipath_opcode_stats *si = &dev->opstats[i];
  1113. if (!si->n_packets && !si->n_bytes)
  1114. continue;
  1115. len += sprintf(buf + len, "%02x %llu/%llu\n", i,
  1116. (unsigned long long) si->n_packets,
  1117. (unsigned long long) si->n_bytes);
  1118. }
  1119. return len;
  1120. }
  1121. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  1122. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  1123. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  1124. static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  1125. static struct class_device_attribute *ipath_class_attributes[] = {
  1126. &class_device_attr_hw_rev,
  1127. &class_device_attr_hca_type,
  1128. &class_device_attr_board_id,
  1129. &class_device_attr_stats
  1130. };
  1131. static int ipath_verbs_register_sysfs(struct ib_device *dev)
  1132. {
  1133. int i;
  1134. int ret;
  1135. for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
  1136. if (class_device_create_file(&dev->class_dev,
  1137. ipath_class_attributes[i])) {
  1138. ret = 1;
  1139. goto bail;
  1140. }
  1141. ret = 0;
  1142. bail:
  1143. return ret;
  1144. }
  1145. module_init(ipath_verbs_init);
  1146. module_exit(ipath_verbs_cleanup);