ipath_verbs.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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/io.h>
  36. #include <linux/utsname.h>
  37. #include "ipath_kernel.h"
  38. #include "ipath_verbs.h"
  39. #include "ipath_common.h"
  40. static unsigned int ib_ipath_qp_table_size = 251;
  41. module_param_named(qp_table_size, ib_ipath_qp_table_size, uint, S_IRUGO);
  42. MODULE_PARM_DESC(qp_table_size, "QP table size");
  43. unsigned int ib_ipath_lkey_table_size = 12;
  44. module_param_named(lkey_table_size, ib_ipath_lkey_table_size, uint,
  45. S_IRUGO);
  46. MODULE_PARM_DESC(lkey_table_size,
  47. "LKEY table size in bits (2^n, 1 <= n <= 23)");
  48. static unsigned int ib_ipath_max_pds = 0xFFFF;
  49. module_param_named(max_pds, ib_ipath_max_pds, uint, S_IWUSR | S_IRUGO);
  50. MODULE_PARM_DESC(max_pds,
  51. "Maximum number of protection domains to support");
  52. static unsigned int ib_ipath_max_ahs = 0xFFFF;
  53. module_param_named(max_ahs, ib_ipath_max_ahs, uint, S_IWUSR | S_IRUGO);
  54. MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
  55. unsigned int ib_ipath_max_cqes = 0x2FFFF;
  56. module_param_named(max_cqes, ib_ipath_max_cqes, uint, S_IWUSR | S_IRUGO);
  57. MODULE_PARM_DESC(max_cqes,
  58. "Maximum number of completion queue entries to support");
  59. unsigned int ib_ipath_max_cqs = 0x1FFFF;
  60. module_param_named(max_cqs, ib_ipath_max_cqs, uint, S_IWUSR | S_IRUGO);
  61. MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
  62. unsigned int ib_ipath_max_qp_wrs = 0x3FFF;
  63. module_param_named(max_qp_wrs, ib_ipath_max_qp_wrs, uint,
  64. S_IWUSR | S_IRUGO);
  65. MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
  66. unsigned int ib_ipath_max_qps = 16384;
  67. module_param_named(max_qps, ib_ipath_max_qps, uint, S_IWUSR | S_IRUGO);
  68. MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
  69. unsigned int ib_ipath_max_sges = 0x60;
  70. module_param_named(max_sges, ib_ipath_max_sges, uint, S_IWUSR | S_IRUGO);
  71. MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
  72. unsigned int ib_ipath_max_mcast_grps = 16384;
  73. module_param_named(max_mcast_grps, ib_ipath_max_mcast_grps, uint,
  74. S_IWUSR | S_IRUGO);
  75. MODULE_PARM_DESC(max_mcast_grps,
  76. "Maximum number of multicast groups to support");
  77. unsigned int ib_ipath_max_mcast_qp_attached = 16;
  78. module_param_named(max_mcast_qp_attached, ib_ipath_max_mcast_qp_attached,
  79. uint, S_IWUSR | S_IRUGO);
  80. MODULE_PARM_DESC(max_mcast_qp_attached,
  81. "Maximum number of attached QPs to support");
  82. unsigned int ib_ipath_max_srqs = 1024;
  83. module_param_named(max_srqs, ib_ipath_max_srqs, uint, S_IWUSR | S_IRUGO);
  84. MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
  85. unsigned int ib_ipath_max_srq_sges = 128;
  86. module_param_named(max_srq_sges, ib_ipath_max_srq_sges,
  87. uint, S_IWUSR | S_IRUGO);
  88. MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
  89. unsigned int ib_ipath_max_srq_wrs = 0x1FFFF;
  90. module_param_named(max_srq_wrs, ib_ipath_max_srq_wrs,
  91. uint, S_IWUSR | S_IRUGO);
  92. MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
  93. static unsigned int ib_ipath_disable_sma;
  94. module_param_named(disable_sma, ib_ipath_disable_sma, uint, S_IWUSR | S_IRUGO);
  95. MODULE_PARM_DESC(ib_ipath_disable_sma, "Disable the SMA");
  96. const int ib_ipath_state_ops[IB_QPS_ERR + 1] = {
  97. [IB_QPS_RESET] = 0,
  98. [IB_QPS_INIT] = IPATH_POST_RECV_OK,
  99. [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
  100. [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
  101. IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK,
  102. [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
  103. IPATH_POST_SEND_OK,
  104. [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
  105. [IB_QPS_ERR] = 0,
  106. };
  107. struct ipath_ucontext {
  108. struct ib_ucontext ibucontext;
  109. };
  110. static inline struct ipath_ucontext *to_iucontext(struct ib_ucontext
  111. *ibucontext)
  112. {
  113. return container_of(ibucontext, struct ipath_ucontext, ibucontext);
  114. }
  115. /*
  116. * Translate ib_wr_opcode into ib_wc_opcode.
  117. */
  118. const enum ib_wc_opcode ib_ipath_wc_opcode[] = {
  119. [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
  120. [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
  121. [IB_WR_SEND] = IB_WC_SEND,
  122. [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
  123. [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
  124. [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
  125. [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
  126. };
  127. /*
  128. * System image GUID.
  129. */
  130. static __be64 sys_image_guid;
  131. /**
  132. * ipath_copy_sge - copy data to SGE memory
  133. * @ss: the SGE state
  134. * @data: the data to copy
  135. * @length: the length of the data
  136. */
  137. void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length)
  138. {
  139. struct ipath_sge *sge = &ss->sge;
  140. while (length) {
  141. u32 len = sge->length;
  142. BUG_ON(len == 0);
  143. if (len > length)
  144. len = length;
  145. memcpy(sge->vaddr, data, len);
  146. sge->vaddr += len;
  147. sge->length -= len;
  148. sge->sge_length -= len;
  149. if (sge->sge_length == 0) {
  150. if (--ss->num_sge)
  151. *sge = *ss->sg_list++;
  152. } else if (sge->length == 0 && sge->mr != NULL) {
  153. if (++sge->n >= IPATH_SEGSZ) {
  154. if (++sge->m >= sge->mr->mapsz)
  155. break;
  156. sge->n = 0;
  157. }
  158. sge->vaddr =
  159. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  160. sge->length =
  161. sge->mr->map[sge->m]->segs[sge->n].length;
  162. }
  163. data += len;
  164. length -= len;
  165. }
  166. }
  167. /**
  168. * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func
  169. * @ss: the SGE state
  170. * @length: the number of bytes to skip
  171. */
  172. void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
  173. {
  174. struct ipath_sge *sge = &ss->sge;
  175. while (length) {
  176. u32 len = sge->length;
  177. BUG_ON(len == 0);
  178. if (len > length)
  179. len = length;
  180. sge->vaddr += len;
  181. sge->length -= len;
  182. sge->sge_length -= len;
  183. if (sge->sge_length == 0) {
  184. if (--ss->num_sge)
  185. *sge = *ss->sg_list++;
  186. } else if (sge->length == 0 && sge->mr != NULL) {
  187. if (++sge->n >= IPATH_SEGSZ) {
  188. if (++sge->m >= sge->mr->mapsz)
  189. break;
  190. sge->n = 0;
  191. }
  192. sge->vaddr =
  193. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  194. sge->length =
  195. sge->mr->map[sge->m]->segs[sge->n].length;
  196. }
  197. length -= len;
  198. }
  199. }
  200. /**
  201. * ipath_post_send - post a send on a QP
  202. * @ibqp: the QP to post the send on
  203. * @wr: the list of work requests to post
  204. * @bad_wr: the first bad WR is put here
  205. *
  206. * This may be called from interrupt context.
  207. */
  208. static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  209. struct ib_send_wr **bad_wr)
  210. {
  211. struct ipath_qp *qp = to_iqp(ibqp);
  212. int err = 0;
  213. /* Check that state is OK to post send. */
  214. if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)) {
  215. *bad_wr = wr;
  216. err = -EINVAL;
  217. goto bail;
  218. }
  219. for (; wr; wr = wr->next) {
  220. switch (qp->ibqp.qp_type) {
  221. case IB_QPT_UC:
  222. case IB_QPT_RC:
  223. err = ipath_post_ruc_send(qp, wr);
  224. break;
  225. case IB_QPT_SMI:
  226. case IB_QPT_GSI:
  227. case IB_QPT_UD:
  228. err = ipath_post_ud_send(qp, wr);
  229. break;
  230. default:
  231. err = -EINVAL;
  232. }
  233. if (err) {
  234. *bad_wr = wr;
  235. break;
  236. }
  237. }
  238. bail:
  239. return err;
  240. }
  241. /**
  242. * ipath_post_receive - post a receive on a QP
  243. * @ibqp: the QP to post the receive on
  244. * @wr: the WR to post
  245. * @bad_wr: the first bad WR is put here
  246. *
  247. * This may be called from interrupt context.
  248. */
  249. static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  250. struct ib_recv_wr **bad_wr)
  251. {
  252. struct ipath_qp *qp = to_iqp(ibqp);
  253. struct ipath_rwq *wq = qp->r_rq.wq;
  254. unsigned long flags;
  255. int ret;
  256. /* Check that state is OK to post receive. */
  257. if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK) || !wq) {
  258. *bad_wr = wr;
  259. ret = -EINVAL;
  260. goto bail;
  261. }
  262. for (; wr; wr = wr->next) {
  263. struct ipath_rwqe *wqe;
  264. u32 next;
  265. int i;
  266. if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
  267. *bad_wr = wr;
  268. ret = -ENOMEM;
  269. goto bail;
  270. }
  271. spin_lock_irqsave(&qp->r_rq.lock, flags);
  272. next = wq->head + 1;
  273. if (next >= qp->r_rq.size)
  274. next = 0;
  275. if (next == wq->tail) {
  276. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  277. *bad_wr = wr;
  278. ret = -ENOMEM;
  279. goto bail;
  280. }
  281. wqe = get_rwqe_ptr(&qp->r_rq, wq->head);
  282. wqe->wr_id = wr->wr_id;
  283. wqe->num_sge = wr->num_sge;
  284. for (i = 0; i < wr->num_sge; i++)
  285. wqe->sg_list[i] = wr->sg_list[i];
  286. wq->head = next;
  287. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  288. }
  289. ret = 0;
  290. bail:
  291. return ret;
  292. }
  293. /**
  294. * ipath_qp_rcv - processing an incoming packet on a QP
  295. * @dev: the device the packet came on
  296. * @hdr: the packet header
  297. * @has_grh: true if the packet has a GRH
  298. * @data: the packet data
  299. * @tlen: the packet length
  300. * @qp: the QP the packet came on
  301. *
  302. * This is called from ipath_ib_rcv() to process an incoming packet
  303. * for the given QP.
  304. * Called at interrupt level.
  305. */
  306. static void ipath_qp_rcv(struct ipath_ibdev *dev,
  307. struct ipath_ib_header *hdr, int has_grh,
  308. void *data, u32 tlen, struct ipath_qp *qp)
  309. {
  310. /* Check for valid receive state. */
  311. if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {
  312. dev->n_pkt_drops++;
  313. return;
  314. }
  315. switch (qp->ibqp.qp_type) {
  316. case IB_QPT_SMI:
  317. case IB_QPT_GSI:
  318. if (ib_ipath_disable_sma)
  319. break;
  320. /* FALLTHROUGH */
  321. case IB_QPT_UD:
  322. ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp);
  323. break;
  324. case IB_QPT_RC:
  325. ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp);
  326. break;
  327. case IB_QPT_UC:
  328. ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp);
  329. break;
  330. default:
  331. break;
  332. }
  333. }
  334. /**
  335. * ipath_ib_rcv - process an incoming packet
  336. * @arg: the device pointer
  337. * @rhdr: the header of the packet
  338. * @data: the packet data
  339. * @tlen: the packet length
  340. *
  341. * This is called from ipath_kreceive() to process an incoming packet at
  342. * interrupt level. Tlen is the length of the header + data + CRC in bytes.
  343. */
  344. void ipath_ib_rcv(struct ipath_ibdev *dev, void *rhdr, void *data,
  345. u32 tlen)
  346. {
  347. struct ipath_ib_header *hdr = rhdr;
  348. struct ipath_other_headers *ohdr;
  349. struct ipath_qp *qp;
  350. u32 qp_num;
  351. int lnh;
  352. u8 opcode;
  353. u16 lid;
  354. if (unlikely(dev == NULL))
  355. goto bail;
  356. if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */
  357. dev->rcv_errors++;
  358. goto bail;
  359. }
  360. /* Check for a valid destination LID (see ch. 7.11.1). */
  361. lid = be16_to_cpu(hdr->lrh[1]);
  362. if (lid < IPATH_MULTICAST_LID_BASE) {
  363. lid &= ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
  364. if (unlikely(lid != dev->dd->ipath_lid)) {
  365. dev->rcv_errors++;
  366. goto bail;
  367. }
  368. }
  369. /* Check for GRH */
  370. lnh = be16_to_cpu(hdr->lrh[0]) & 3;
  371. if (lnh == IPATH_LRH_BTH)
  372. ohdr = &hdr->u.oth;
  373. else if (lnh == IPATH_LRH_GRH)
  374. ohdr = &hdr->u.l.oth;
  375. else {
  376. dev->rcv_errors++;
  377. goto bail;
  378. }
  379. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  380. dev->opstats[opcode].n_bytes += tlen;
  381. dev->opstats[opcode].n_packets++;
  382. /* Get the destination QP number. */
  383. qp_num = be32_to_cpu(ohdr->bth[1]) & IPATH_QPN_MASK;
  384. if (qp_num == IPATH_MULTICAST_QPN) {
  385. struct ipath_mcast *mcast;
  386. struct ipath_mcast_qp *p;
  387. if (lnh != IPATH_LRH_GRH) {
  388. dev->n_pkt_drops++;
  389. goto bail;
  390. }
  391. mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
  392. if (mcast == NULL) {
  393. dev->n_pkt_drops++;
  394. goto bail;
  395. }
  396. dev->n_multicast_rcv++;
  397. list_for_each_entry_rcu(p, &mcast->qp_list, list)
  398. ipath_qp_rcv(dev, hdr, 1, data, tlen, p->qp);
  399. /*
  400. * Notify ipath_multicast_detach() if it is waiting for us
  401. * to finish.
  402. */
  403. if (atomic_dec_return(&mcast->refcount) <= 1)
  404. wake_up(&mcast->wait);
  405. } else {
  406. qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
  407. if (qp) {
  408. dev->n_unicast_rcv++;
  409. ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data,
  410. tlen, qp);
  411. /*
  412. * Notify ipath_destroy_qp() if it is waiting
  413. * for us to finish.
  414. */
  415. if (atomic_dec_and_test(&qp->refcount))
  416. wake_up(&qp->wait);
  417. } else
  418. dev->n_pkt_drops++;
  419. }
  420. bail:;
  421. }
  422. /**
  423. * ipath_ib_timer - verbs timer
  424. * @arg: the device pointer
  425. *
  426. * This is called from ipath_do_rcv_timer() at interrupt level to check for
  427. * QPs which need retransmits and to collect performance numbers.
  428. */
  429. void ipath_ib_timer(struct ipath_ibdev *dev)
  430. {
  431. struct ipath_qp *resend = NULL;
  432. struct list_head *last;
  433. struct ipath_qp *qp;
  434. unsigned long flags;
  435. if (dev == NULL)
  436. return;
  437. spin_lock_irqsave(&dev->pending_lock, flags);
  438. /* Start filling the next pending queue. */
  439. if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
  440. dev->pending_index = 0;
  441. /* Save any requests still in the new queue, they have timed out. */
  442. last = &dev->pending[dev->pending_index];
  443. while (!list_empty(last)) {
  444. qp = list_entry(last->next, struct ipath_qp, timerwait);
  445. list_del_init(&qp->timerwait);
  446. qp->timer_next = resend;
  447. resend = qp;
  448. atomic_inc(&qp->refcount);
  449. }
  450. last = &dev->rnrwait;
  451. if (!list_empty(last)) {
  452. qp = list_entry(last->next, struct ipath_qp, timerwait);
  453. if (--qp->s_rnr_timeout == 0) {
  454. do {
  455. list_del_init(&qp->timerwait);
  456. tasklet_hi_schedule(&qp->s_task);
  457. if (list_empty(last))
  458. break;
  459. qp = list_entry(last->next, struct ipath_qp,
  460. timerwait);
  461. } while (qp->s_rnr_timeout == 0);
  462. }
  463. }
  464. /*
  465. * We should only be in the started state if pma_sample_start != 0
  466. */
  467. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
  468. --dev->pma_sample_start == 0) {
  469. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  470. ipath_snapshot_counters(dev->dd, &dev->ipath_sword,
  471. &dev->ipath_rword,
  472. &dev->ipath_spkts,
  473. &dev->ipath_rpkts,
  474. &dev->ipath_xmit_wait);
  475. }
  476. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
  477. if (dev->pma_sample_interval == 0) {
  478. u64 ta, tb, tc, td, te;
  479. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  480. ipath_snapshot_counters(dev->dd, &ta, &tb,
  481. &tc, &td, &te);
  482. dev->ipath_sword = ta - dev->ipath_sword;
  483. dev->ipath_rword = tb - dev->ipath_rword;
  484. dev->ipath_spkts = tc - dev->ipath_spkts;
  485. dev->ipath_rpkts = td - dev->ipath_rpkts;
  486. dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
  487. }
  488. else
  489. dev->pma_sample_interval--;
  490. }
  491. spin_unlock_irqrestore(&dev->pending_lock, flags);
  492. /* XXX What if timer fires again while this is running? */
  493. for (qp = resend; qp != NULL; qp = qp->timer_next) {
  494. struct ib_wc wc;
  495. spin_lock_irqsave(&qp->s_lock, flags);
  496. if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) {
  497. dev->n_timeouts++;
  498. ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
  499. }
  500. spin_unlock_irqrestore(&qp->s_lock, flags);
  501. /* Notify ipath_destroy_qp() if it is waiting. */
  502. if (atomic_dec_and_test(&qp->refcount))
  503. wake_up(&qp->wait);
  504. }
  505. }
  506. static void update_sge(struct ipath_sge_state *ss, u32 length)
  507. {
  508. struct ipath_sge *sge = &ss->sge;
  509. sge->vaddr += length;
  510. sge->length -= length;
  511. sge->sge_length -= length;
  512. if (sge->sge_length == 0) {
  513. if (--ss->num_sge)
  514. *sge = *ss->sg_list++;
  515. } else if (sge->length == 0 && sge->mr != NULL) {
  516. if (++sge->n >= IPATH_SEGSZ) {
  517. if (++sge->m >= sge->mr->mapsz)
  518. return;
  519. sge->n = 0;
  520. }
  521. sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
  522. sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
  523. }
  524. }
  525. #ifdef __LITTLE_ENDIAN
  526. static inline u32 get_upper_bits(u32 data, u32 shift)
  527. {
  528. return data >> shift;
  529. }
  530. static inline u32 set_upper_bits(u32 data, u32 shift)
  531. {
  532. return data << shift;
  533. }
  534. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  535. {
  536. data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
  537. data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  538. return data;
  539. }
  540. #else
  541. static inline u32 get_upper_bits(u32 data, u32 shift)
  542. {
  543. return data << shift;
  544. }
  545. static inline u32 set_upper_bits(u32 data, u32 shift)
  546. {
  547. return data >> shift;
  548. }
  549. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  550. {
  551. data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
  552. data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  553. return data;
  554. }
  555. #endif
  556. static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
  557. u32 length)
  558. {
  559. u32 extra = 0;
  560. u32 data = 0;
  561. u32 last;
  562. while (1) {
  563. u32 len = ss->sge.length;
  564. u32 off;
  565. BUG_ON(len == 0);
  566. if (len > length)
  567. len = length;
  568. if (len > ss->sge.sge_length)
  569. len = ss->sge.sge_length;
  570. /* If the source address is not aligned, try to align it. */
  571. off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
  572. if (off) {
  573. u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
  574. ~(sizeof(u32) - 1));
  575. u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
  576. u32 y;
  577. y = sizeof(u32) - off;
  578. if (len > y)
  579. len = y;
  580. if (len + extra >= sizeof(u32)) {
  581. data |= set_upper_bits(v, extra *
  582. BITS_PER_BYTE);
  583. len = sizeof(u32) - extra;
  584. if (len == length) {
  585. last = data;
  586. break;
  587. }
  588. __raw_writel(data, piobuf);
  589. piobuf++;
  590. extra = 0;
  591. data = 0;
  592. } else {
  593. /* Clear unused upper bytes */
  594. data |= clear_upper_bytes(v, len, extra);
  595. if (len == length) {
  596. last = data;
  597. break;
  598. }
  599. extra += len;
  600. }
  601. } else if (extra) {
  602. /* Source address is aligned. */
  603. u32 *addr = (u32 *) ss->sge.vaddr;
  604. int shift = extra * BITS_PER_BYTE;
  605. int ushift = 32 - shift;
  606. u32 l = len;
  607. while (l >= sizeof(u32)) {
  608. u32 v = *addr;
  609. data |= set_upper_bits(v, shift);
  610. __raw_writel(data, piobuf);
  611. data = get_upper_bits(v, ushift);
  612. piobuf++;
  613. addr++;
  614. l -= sizeof(u32);
  615. }
  616. /*
  617. * We still have 'extra' number of bytes leftover.
  618. */
  619. if (l) {
  620. u32 v = *addr;
  621. if (l + extra >= sizeof(u32)) {
  622. data |= set_upper_bits(v, shift);
  623. len -= l + extra - sizeof(u32);
  624. if (len == length) {
  625. last = data;
  626. break;
  627. }
  628. __raw_writel(data, piobuf);
  629. piobuf++;
  630. extra = 0;
  631. data = 0;
  632. } else {
  633. /* Clear unused upper bytes */
  634. data |= clear_upper_bytes(v, l,
  635. extra);
  636. if (len == length) {
  637. last = data;
  638. break;
  639. }
  640. extra += l;
  641. }
  642. } else if (len == length) {
  643. last = data;
  644. break;
  645. }
  646. } else if (len == length) {
  647. u32 w;
  648. /*
  649. * Need to round up for the last dword in the
  650. * packet.
  651. */
  652. w = (len + 3) >> 2;
  653. __iowrite32_copy(piobuf, ss->sge.vaddr, w - 1);
  654. piobuf += w - 1;
  655. last = ((u32 *) ss->sge.vaddr)[w - 1];
  656. break;
  657. } else {
  658. u32 w = len >> 2;
  659. __iowrite32_copy(piobuf, ss->sge.vaddr, w);
  660. piobuf += w;
  661. extra = len & (sizeof(u32) - 1);
  662. if (extra) {
  663. u32 v = ((u32 *) ss->sge.vaddr)[w];
  664. /* Clear unused upper bytes */
  665. data = clear_upper_bytes(v, extra, 0);
  666. }
  667. }
  668. update_sge(ss, len);
  669. length -= len;
  670. }
  671. /* Update address before sending packet. */
  672. update_sge(ss, length);
  673. /* must flush early everything before trigger word */
  674. ipath_flush_wc();
  675. __raw_writel(last, piobuf);
  676. /* be sure trigger word is written */
  677. ipath_flush_wc();
  678. }
  679. /**
  680. * ipath_verbs_send - send a packet
  681. * @dd: the infinipath device
  682. * @hdrwords: the number of words in the header
  683. * @hdr: the packet header
  684. * @len: the length of the packet in bytes
  685. * @ss: the SGE to send
  686. */
  687. int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
  688. u32 *hdr, u32 len, struct ipath_sge_state *ss)
  689. {
  690. u32 __iomem *piobuf;
  691. u32 plen;
  692. int ret;
  693. /* +1 is for the qword padding of pbc */
  694. plen = hdrwords + ((len + 3) >> 2) + 1;
  695. if (unlikely((plen << 2) > dd->ipath_ibmaxlen)) {
  696. ret = -EINVAL;
  697. goto bail;
  698. }
  699. /* Get a PIO buffer to use. */
  700. piobuf = ipath_getpiobuf(dd, NULL);
  701. if (unlikely(piobuf == NULL)) {
  702. ret = -EBUSY;
  703. goto bail;
  704. }
  705. /*
  706. * Write len to control qword, no flags.
  707. * We have to flush after the PBC for correctness on some cpus
  708. * or WC buffer can be written out of order.
  709. */
  710. writeq(plen, piobuf);
  711. ipath_flush_wc();
  712. piobuf += 2;
  713. if (len == 0) {
  714. /*
  715. * If there is just the header portion, must flush before
  716. * writing last word of header for correctness, and after
  717. * the last header word (trigger word).
  718. */
  719. __iowrite32_copy(piobuf, hdr, hdrwords - 1);
  720. ipath_flush_wc();
  721. __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
  722. ipath_flush_wc();
  723. ret = 0;
  724. goto bail;
  725. }
  726. __iowrite32_copy(piobuf, hdr, hdrwords);
  727. piobuf += hdrwords;
  728. /* The common case is aligned and contained in one segment. */
  729. if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
  730. !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
  731. u32 w;
  732. u32 *addr = (u32 *) ss->sge.vaddr;
  733. /* Update address before sending packet. */
  734. update_sge(ss, len);
  735. /* Need to round up for the last dword in the packet. */
  736. w = (len + 3) >> 2;
  737. __iowrite32_copy(piobuf, addr, w - 1);
  738. /* must flush early everything before trigger word */
  739. ipath_flush_wc();
  740. __raw_writel(addr[w - 1], piobuf + w - 1);
  741. /* be sure trigger word is written */
  742. ipath_flush_wc();
  743. ret = 0;
  744. goto bail;
  745. }
  746. copy_io(piobuf, ss, len);
  747. ret = 0;
  748. bail:
  749. return ret;
  750. }
  751. int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
  752. u64 *rwords, u64 *spkts, u64 *rpkts,
  753. u64 *xmit_wait)
  754. {
  755. int ret;
  756. if (!(dd->ipath_flags & IPATH_INITTED)) {
  757. /* no hardware, freeze, etc. */
  758. ipath_dbg("unit %u not usable\n", dd->ipath_unit);
  759. ret = -EINVAL;
  760. goto bail;
  761. }
  762. *swords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  763. *rwords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  764. *spkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  765. *rpkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  766. *xmit_wait = ipath_snap_cntr(dd, dd->ipath_cregs->cr_sendstallcnt);
  767. ret = 0;
  768. bail:
  769. return ret;
  770. }
  771. /**
  772. * ipath_get_counters - get various chip counters
  773. * @dd: the infinipath device
  774. * @cntrs: counters are placed here
  775. *
  776. * Return the counters needed by recv_pma_get_portcounters().
  777. */
  778. int ipath_get_counters(struct ipath_devdata *dd,
  779. struct ipath_verbs_counters *cntrs)
  780. {
  781. int ret;
  782. if (!(dd->ipath_flags & IPATH_INITTED)) {
  783. /* no hardware, freeze, etc. */
  784. ipath_dbg("unit %u not usable\n", dd->ipath_unit);
  785. ret = -EINVAL;
  786. goto bail;
  787. }
  788. cntrs->symbol_error_counter =
  789. ipath_snap_cntr(dd, dd->ipath_cregs->cr_ibsymbolerrcnt);
  790. cntrs->link_error_recovery_counter =
  791. ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt);
  792. /*
  793. * The link downed counter counts when the other side downs the
  794. * connection. We add in the number of times we downed the link
  795. * due to local link integrity errors to compensate.
  796. */
  797. cntrs->link_downed_counter =
  798. ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkdowncnt);
  799. cntrs->port_rcv_errors =
  800. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rxdroppktcnt) +
  801. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvovflcnt) +
  802. ipath_snap_cntr(dd, dd->ipath_cregs->cr_portovflcnt) +
  803. ipath_snap_cntr(dd, dd->ipath_cregs->cr_err_rlencnt) +
  804. ipath_snap_cntr(dd, dd->ipath_cregs->cr_invalidrlencnt) +
  805. ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) +
  806. ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) +
  807. ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) +
  808. ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt) +
  809. dd->ipath_rxfc_unsupvl_errs;
  810. cntrs->port_rcv_remphys_errors =
  811. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt);
  812. cntrs->port_xmit_discards =
  813. ipath_snap_cntr(dd, dd->ipath_cregs->cr_unsupvlcnt);
  814. cntrs->port_xmit_data =
  815. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  816. cntrs->port_rcv_data =
  817. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  818. cntrs->port_xmit_packets =
  819. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  820. cntrs->port_rcv_packets =
  821. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  822. cntrs->local_link_integrity_errors =
  823. (dd->ipath_flags & IPATH_GPIO_ERRINTRS) ?
  824. dd->ipath_lli_errs : dd->ipath_lli_errors;
  825. cntrs->excessive_buffer_overrun_errors = dd->ipath_overrun_thresh_errs;
  826. ret = 0;
  827. bail:
  828. return ret;
  829. }
  830. /**
  831. * ipath_ib_piobufavail - callback when a PIO buffer is available
  832. * @arg: the device pointer
  833. *
  834. * This is called from ipath_intr() at interrupt level when a PIO buffer is
  835. * available after ipath_verbs_send() returned an error that no buffers were
  836. * available. Return 1 if we consumed all the PIO buffers and we still have
  837. * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and
  838. * return zero).
  839. */
  840. int ipath_ib_piobufavail(struct ipath_ibdev *dev)
  841. {
  842. struct ipath_qp *qp;
  843. unsigned long flags;
  844. if (dev == NULL)
  845. goto bail;
  846. spin_lock_irqsave(&dev->pending_lock, flags);
  847. while (!list_empty(&dev->piowait)) {
  848. qp = list_entry(dev->piowait.next, struct ipath_qp,
  849. piowait);
  850. list_del_init(&qp->piowait);
  851. tasklet_hi_schedule(&qp->s_task);
  852. }
  853. spin_unlock_irqrestore(&dev->pending_lock, flags);
  854. bail:
  855. return 0;
  856. }
  857. static int ipath_query_device(struct ib_device *ibdev,
  858. struct ib_device_attr *props)
  859. {
  860. struct ipath_ibdev *dev = to_idev(ibdev);
  861. memset(props, 0, sizeof(*props));
  862. props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
  863. IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
  864. IB_DEVICE_SYS_IMAGE_GUID;
  865. props->page_size_cap = PAGE_SIZE;
  866. props->vendor_id = dev->dd->ipath_vendorid;
  867. props->vendor_part_id = dev->dd->ipath_deviceid;
  868. props->hw_ver = dev->dd->ipath_pcirev;
  869. props->sys_image_guid = dev->sys_image_guid;
  870. props->max_mr_size = ~0ull;
  871. props->max_qp = ib_ipath_max_qps;
  872. props->max_qp_wr = ib_ipath_max_qp_wrs;
  873. props->max_sge = ib_ipath_max_sges;
  874. props->max_cq = ib_ipath_max_cqs;
  875. props->max_ah = ib_ipath_max_ahs;
  876. props->max_cqe = ib_ipath_max_cqes;
  877. props->max_mr = dev->lk_table.max;
  878. props->max_fmr = dev->lk_table.max;
  879. props->max_map_per_fmr = 32767;
  880. props->max_pd = ib_ipath_max_pds;
  881. props->max_qp_rd_atom = IPATH_MAX_RDMA_ATOMIC;
  882. props->max_qp_init_rd_atom = 255;
  883. /* props->max_res_rd_atom */
  884. props->max_srq = ib_ipath_max_srqs;
  885. props->max_srq_wr = ib_ipath_max_srq_wrs;
  886. props->max_srq_sge = ib_ipath_max_srq_sges;
  887. /* props->local_ca_ack_delay */
  888. props->atomic_cap = IB_ATOMIC_GLOB;
  889. props->max_pkeys = ipath_get_npkeys(dev->dd);
  890. props->max_mcast_grp = ib_ipath_max_mcast_grps;
  891. props->max_mcast_qp_attach = ib_ipath_max_mcast_qp_attached;
  892. props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
  893. props->max_mcast_grp;
  894. return 0;
  895. }
  896. const u8 ipath_cvt_physportstate[16] = {
  897. [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3,
  898. [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5,
  899. [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2,
  900. [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2,
  901. [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1,
  902. [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1,
  903. [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4,
  904. [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4,
  905. [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4,
  906. [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4,
  907. [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6,
  908. [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6,
  909. [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6,
  910. };
  911. u32 ipath_get_cr_errpkey(struct ipath_devdata *dd)
  912. {
  913. return ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
  914. }
  915. static int ipath_query_port(struct ib_device *ibdev,
  916. u8 port, struct ib_port_attr *props)
  917. {
  918. struct ipath_ibdev *dev = to_idev(ibdev);
  919. enum ib_mtu mtu;
  920. u16 lid = dev->dd->ipath_lid;
  921. u64 ibcstat;
  922. memset(props, 0, sizeof(*props));
  923. props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  924. props->lmc = dev->mkeyprot_resv_lmc & 7;
  925. props->sm_lid = dev->sm_lid;
  926. props->sm_sl = dev->sm_sl;
  927. ibcstat = dev->dd->ipath_lastibcstat;
  928. props->state = ((ibcstat >> 4) & 0x3) + 1;
  929. /* See phys_state_show() */
  930. props->phys_state = ipath_cvt_physportstate[
  931. dev->dd->ipath_lastibcstat & 0xf];
  932. props->port_cap_flags = dev->port_cap_flags;
  933. props->gid_tbl_len = 1;
  934. props->max_msg_sz = 0x80000000;
  935. props->pkey_tbl_len = ipath_get_npkeys(dev->dd);
  936. props->bad_pkey_cntr = ipath_get_cr_errpkey(dev->dd) -
  937. dev->z_pkey_violations;
  938. props->qkey_viol_cntr = dev->qkey_violations;
  939. props->active_width = IB_WIDTH_4X;
  940. /* See rate_show() */
  941. props->active_speed = 1; /* Regular 10Mbs speed. */
  942. props->max_vl_num = 1; /* VLCap = VL0 */
  943. props->init_type_reply = 0;
  944. /*
  945. * Note: the chips support a maximum MTU of 4096, but the driver
  946. * hasn't implemented this feature yet, so set the maximum value
  947. * to 2048.
  948. */
  949. props->max_mtu = IB_MTU_2048;
  950. switch (dev->dd->ipath_ibmtu) {
  951. case 4096:
  952. mtu = IB_MTU_4096;
  953. break;
  954. case 2048:
  955. mtu = IB_MTU_2048;
  956. break;
  957. case 1024:
  958. mtu = IB_MTU_1024;
  959. break;
  960. case 512:
  961. mtu = IB_MTU_512;
  962. break;
  963. case 256:
  964. mtu = IB_MTU_256;
  965. break;
  966. default:
  967. mtu = IB_MTU_2048;
  968. }
  969. props->active_mtu = mtu;
  970. props->subnet_timeout = dev->subnet_timeout;
  971. return 0;
  972. }
  973. static int ipath_modify_device(struct ib_device *device,
  974. int device_modify_mask,
  975. struct ib_device_modify *device_modify)
  976. {
  977. int ret;
  978. if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
  979. IB_DEVICE_MODIFY_NODE_DESC)) {
  980. ret = -EOPNOTSUPP;
  981. goto bail;
  982. }
  983. if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
  984. memcpy(device->node_desc, device_modify->node_desc, 64);
  985. if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
  986. to_idev(device)->sys_image_guid =
  987. cpu_to_be64(device_modify->sys_image_guid);
  988. ret = 0;
  989. bail:
  990. return ret;
  991. }
  992. static int ipath_modify_port(struct ib_device *ibdev,
  993. u8 port, int port_modify_mask,
  994. struct ib_port_modify *props)
  995. {
  996. struct ipath_ibdev *dev = to_idev(ibdev);
  997. dev->port_cap_flags |= props->set_port_cap_mask;
  998. dev->port_cap_flags &= ~props->clr_port_cap_mask;
  999. if (port_modify_mask & IB_PORT_SHUTDOWN)
  1000. ipath_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
  1001. if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
  1002. dev->qkey_violations = 0;
  1003. return 0;
  1004. }
  1005. static int ipath_query_gid(struct ib_device *ibdev, u8 port,
  1006. int index, union ib_gid *gid)
  1007. {
  1008. struct ipath_ibdev *dev = to_idev(ibdev);
  1009. int ret;
  1010. if (index >= 1) {
  1011. ret = -EINVAL;
  1012. goto bail;
  1013. }
  1014. gid->global.subnet_prefix = dev->gid_prefix;
  1015. gid->global.interface_id = dev->dd->ipath_guid;
  1016. ret = 0;
  1017. bail:
  1018. return ret;
  1019. }
  1020. static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
  1021. struct ib_ucontext *context,
  1022. struct ib_udata *udata)
  1023. {
  1024. struct ipath_ibdev *dev = to_idev(ibdev);
  1025. struct ipath_pd *pd;
  1026. struct ib_pd *ret;
  1027. /*
  1028. * This is actually totally arbitrary. Some correctness tests
  1029. * assume there's a maximum number of PDs that can be allocated.
  1030. * We don't actually have this limit, but we fail the test if
  1031. * we allow allocations of more than we report for this value.
  1032. */
  1033. pd = kmalloc(sizeof *pd, GFP_KERNEL);
  1034. if (!pd) {
  1035. ret = ERR_PTR(-ENOMEM);
  1036. goto bail;
  1037. }
  1038. spin_lock(&dev->n_pds_lock);
  1039. if (dev->n_pds_allocated == ib_ipath_max_pds) {
  1040. spin_unlock(&dev->n_pds_lock);
  1041. kfree(pd);
  1042. ret = ERR_PTR(-ENOMEM);
  1043. goto bail;
  1044. }
  1045. dev->n_pds_allocated++;
  1046. spin_unlock(&dev->n_pds_lock);
  1047. /* ib_alloc_pd() will initialize pd->ibpd. */
  1048. pd->user = udata != NULL;
  1049. ret = &pd->ibpd;
  1050. bail:
  1051. return ret;
  1052. }
  1053. static int ipath_dealloc_pd(struct ib_pd *ibpd)
  1054. {
  1055. struct ipath_pd *pd = to_ipd(ibpd);
  1056. struct ipath_ibdev *dev = to_idev(ibpd->device);
  1057. spin_lock(&dev->n_pds_lock);
  1058. dev->n_pds_allocated--;
  1059. spin_unlock(&dev->n_pds_lock);
  1060. kfree(pd);
  1061. return 0;
  1062. }
  1063. /**
  1064. * ipath_create_ah - create an address handle
  1065. * @pd: the protection domain
  1066. * @ah_attr: the attributes of the AH
  1067. *
  1068. * This may be called from interrupt context.
  1069. */
  1070. static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
  1071. struct ib_ah_attr *ah_attr)
  1072. {
  1073. struct ipath_ah *ah;
  1074. struct ib_ah *ret;
  1075. struct ipath_ibdev *dev = to_idev(pd->device);
  1076. unsigned long flags;
  1077. /* A multicast address requires a GRH (see ch. 8.4.1). */
  1078. if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE &&
  1079. ah_attr->dlid != IPATH_PERMISSIVE_LID &&
  1080. !(ah_attr->ah_flags & IB_AH_GRH)) {
  1081. ret = ERR_PTR(-EINVAL);
  1082. goto bail;
  1083. }
  1084. if (ah_attr->dlid == 0) {
  1085. ret = ERR_PTR(-EINVAL);
  1086. goto bail;
  1087. }
  1088. if (ah_attr->port_num < 1 ||
  1089. ah_attr->port_num > pd->device->phys_port_cnt) {
  1090. ret = ERR_PTR(-EINVAL);
  1091. goto bail;
  1092. }
  1093. ah = kmalloc(sizeof *ah, GFP_ATOMIC);
  1094. if (!ah) {
  1095. ret = ERR_PTR(-ENOMEM);
  1096. goto bail;
  1097. }
  1098. spin_lock_irqsave(&dev->n_ahs_lock, flags);
  1099. if (dev->n_ahs_allocated == ib_ipath_max_ahs) {
  1100. spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
  1101. kfree(ah);
  1102. ret = ERR_PTR(-ENOMEM);
  1103. goto bail;
  1104. }
  1105. dev->n_ahs_allocated++;
  1106. spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
  1107. /* ib_create_ah() will initialize ah->ibah. */
  1108. ah->attr = *ah_attr;
  1109. ret = &ah->ibah;
  1110. bail:
  1111. return ret;
  1112. }
  1113. /**
  1114. * ipath_destroy_ah - destroy an address handle
  1115. * @ibah: the AH to destroy
  1116. *
  1117. * This may be called from interrupt context.
  1118. */
  1119. static int ipath_destroy_ah(struct ib_ah *ibah)
  1120. {
  1121. struct ipath_ibdev *dev = to_idev(ibah->device);
  1122. struct ipath_ah *ah = to_iah(ibah);
  1123. unsigned long flags;
  1124. spin_lock_irqsave(&dev->n_ahs_lock, flags);
  1125. dev->n_ahs_allocated--;
  1126. spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
  1127. kfree(ah);
  1128. return 0;
  1129. }
  1130. static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
  1131. {
  1132. struct ipath_ah *ah = to_iah(ibah);
  1133. *ah_attr = ah->attr;
  1134. return 0;
  1135. }
  1136. /**
  1137. * ipath_get_npkeys - return the size of the PKEY table for port 0
  1138. * @dd: the infinipath device
  1139. */
  1140. unsigned ipath_get_npkeys(struct ipath_devdata *dd)
  1141. {
  1142. return ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys);
  1143. }
  1144. /**
  1145. * ipath_get_pkey - return the indexed PKEY from the port 0 PKEY table
  1146. * @dd: the infinipath device
  1147. * @index: the PKEY index
  1148. */
  1149. unsigned ipath_get_pkey(struct ipath_devdata *dd, unsigned index)
  1150. {
  1151. unsigned ret;
  1152. if (index >= ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys))
  1153. ret = 0;
  1154. else
  1155. ret = dd->ipath_pd[0]->port_pkeys[index];
  1156. return ret;
  1157. }
  1158. static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
  1159. u16 *pkey)
  1160. {
  1161. struct ipath_ibdev *dev = to_idev(ibdev);
  1162. int ret;
  1163. if (index >= ipath_get_npkeys(dev->dd)) {
  1164. ret = -EINVAL;
  1165. goto bail;
  1166. }
  1167. *pkey = ipath_get_pkey(dev->dd, index);
  1168. ret = 0;
  1169. bail:
  1170. return ret;
  1171. }
  1172. /**
  1173. * ipath_alloc_ucontext - allocate a ucontest
  1174. * @ibdev: the infiniband device
  1175. * @udata: not used by the InfiniPath driver
  1176. */
  1177. static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
  1178. struct ib_udata *udata)
  1179. {
  1180. struct ipath_ucontext *context;
  1181. struct ib_ucontext *ret;
  1182. context = kmalloc(sizeof *context, GFP_KERNEL);
  1183. if (!context) {
  1184. ret = ERR_PTR(-ENOMEM);
  1185. goto bail;
  1186. }
  1187. ret = &context->ibucontext;
  1188. bail:
  1189. return ret;
  1190. }
  1191. static int ipath_dealloc_ucontext(struct ib_ucontext *context)
  1192. {
  1193. kfree(to_iucontext(context));
  1194. return 0;
  1195. }
  1196. static int ipath_verbs_register_sysfs(struct ib_device *dev);
  1197. static void __verbs_timer(unsigned long arg)
  1198. {
  1199. struct ipath_devdata *dd = (struct ipath_devdata *) arg;
  1200. /*
  1201. * If port 0 receive packet interrupts are not available, or
  1202. * can be missed, poll the receive queue
  1203. */
  1204. if (dd->ipath_flags & IPATH_POLL_RX_INTR)
  1205. ipath_kreceive(dd);
  1206. /* Handle verbs layer timeouts. */
  1207. ipath_ib_timer(dd->verbs_dev);
  1208. mod_timer(&dd->verbs_timer, jiffies + 1);
  1209. }
  1210. static int enable_timer(struct ipath_devdata *dd)
  1211. {
  1212. /*
  1213. * Early chips had a design flaw where the chip and kernel idea
  1214. * of the tail register don't always agree, and therefore we won't
  1215. * get an interrupt on the next packet received.
  1216. * If the board supports per packet receive interrupts, use it.
  1217. * Otherwise, the timer function periodically checks for packets
  1218. * to cover this case.
  1219. * Either way, the timer is needed for verbs layer related
  1220. * processing.
  1221. */
  1222. if (dd->ipath_flags & IPATH_GPIO_INTR) {
  1223. ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
  1224. 0x2074076542310ULL);
  1225. /* Enable GPIO bit 2 interrupt */
  1226. dd->ipath_gpio_mask |= (u64) (1 << IPATH_GPIO_PORT0_BIT);
  1227. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  1228. dd->ipath_gpio_mask);
  1229. }
  1230. init_timer(&dd->verbs_timer);
  1231. dd->verbs_timer.function = __verbs_timer;
  1232. dd->verbs_timer.data = (unsigned long)dd;
  1233. dd->verbs_timer.expires = jiffies + 1;
  1234. add_timer(&dd->verbs_timer);
  1235. return 0;
  1236. }
  1237. static int disable_timer(struct ipath_devdata *dd)
  1238. {
  1239. /* Disable GPIO bit 2 interrupt */
  1240. if (dd->ipath_flags & IPATH_GPIO_INTR) {
  1241. u64 val;
  1242. /* Disable GPIO bit 2 interrupt */
  1243. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask);
  1244. dd->ipath_gpio_mask &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT));
  1245. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  1246. dd->ipath_gpio_mask);
  1247. /*
  1248. * We might want to undo changes to debugportselect,
  1249. * but how?
  1250. */
  1251. }
  1252. del_timer_sync(&dd->verbs_timer);
  1253. return 0;
  1254. }
  1255. /**
  1256. * ipath_register_ib_device - register our device with the infiniband core
  1257. * @dd: the device data structure
  1258. * Return the allocated ipath_ibdev pointer or NULL on error.
  1259. */
  1260. int ipath_register_ib_device(struct ipath_devdata *dd)
  1261. {
  1262. struct ipath_verbs_counters cntrs;
  1263. struct ipath_ibdev *idev;
  1264. struct ib_device *dev;
  1265. int ret;
  1266. idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
  1267. if (idev == NULL) {
  1268. ret = -ENOMEM;
  1269. goto bail;
  1270. }
  1271. dev = &idev->ibdev;
  1272. /* Only need to initialize non-zero fields. */
  1273. spin_lock_init(&idev->n_pds_lock);
  1274. spin_lock_init(&idev->n_ahs_lock);
  1275. spin_lock_init(&idev->n_cqs_lock);
  1276. spin_lock_init(&idev->n_qps_lock);
  1277. spin_lock_init(&idev->n_srqs_lock);
  1278. spin_lock_init(&idev->n_mcast_grps_lock);
  1279. spin_lock_init(&idev->qp_table.lock);
  1280. spin_lock_init(&idev->lk_table.lock);
  1281. idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  1282. /* Set the prefix to the default value (see ch. 4.1.1) */
  1283. idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
  1284. ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
  1285. if (ret)
  1286. goto err_qp;
  1287. /*
  1288. * The top ib_ipath_lkey_table_size bits are used to index the
  1289. * table. The lower 8 bits can be owned by the user (copied from
  1290. * the LKEY). The remaining bits act as a generation number or tag.
  1291. */
  1292. idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
  1293. idev->lk_table.table = kzalloc(idev->lk_table.max *
  1294. sizeof(*idev->lk_table.table),
  1295. GFP_KERNEL);
  1296. if (idev->lk_table.table == NULL) {
  1297. ret = -ENOMEM;
  1298. goto err_lk;
  1299. }
  1300. INIT_LIST_HEAD(&idev->pending_mmaps);
  1301. spin_lock_init(&idev->pending_lock);
  1302. idev->mmap_offset = PAGE_SIZE;
  1303. spin_lock_init(&idev->mmap_offset_lock);
  1304. INIT_LIST_HEAD(&idev->pending[0]);
  1305. INIT_LIST_HEAD(&idev->pending[1]);
  1306. INIT_LIST_HEAD(&idev->pending[2]);
  1307. INIT_LIST_HEAD(&idev->piowait);
  1308. INIT_LIST_HEAD(&idev->rnrwait);
  1309. idev->pending_index = 0;
  1310. idev->port_cap_flags =
  1311. IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
  1312. idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  1313. idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  1314. idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  1315. idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  1316. idev->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
  1317. idev->link_width_enabled = 3; /* 1x or 4x */
  1318. /* Snapshot current HW counters to "clear" them. */
  1319. ipath_get_counters(dd, &cntrs);
  1320. idev->z_symbol_error_counter = cntrs.symbol_error_counter;
  1321. idev->z_link_error_recovery_counter =
  1322. cntrs.link_error_recovery_counter;
  1323. idev->z_link_downed_counter = cntrs.link_downed_counter;
  1324. idev->z_port_rcv_errors = cntrs.port_rcv_errors;
  1325. idev->z_port_rcv_remphys_errors =
  1326. cntrs.port_rcv_remphys_errors;
  1327. idev->z_port_xmit_discards = cntrs.port_xmit_discards;
  1328. idev->z_port_xmit_data = cntrs.port_xmit_data;
  1329. idev->z_port_rcv_data = cntrs.port_rcv_data;
  1330. idev->z_port_xmit_packets = cntrs.port_xmit_packets;
  1331. idev->z_port_rcv_packets = cntrs.port_rcv_packets;
  1332. idev->z_local_link_integrity_errors =
  1333. cntrs.local_link_integrity_errors;
  1334. idev->z_excessive_buffer_overrun_errors =
  1335. cntrs.excessive_buffer_overrun_errors;
  1336. /*
  1337. * The system image GUID is supposed to be the same for all
  1338. * IB HCAs in a single system but since there can be other
  1339. * device types in the system, we can't be sure this is unique.
  1340. */
  1341. if (!sys_image_guid)
  1342. sys_image_guid = dd->ipath_guid;
  1343. idev->sys_image_guid = sys_image_guid;
  1344. idev->ib_unit = dd->ipath_unit;
  1345. idev->dd = dd;
  1346. strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
  1347. dev->owner = THIS_MODULE;
  1348. dev->node_guid = dd->ipath_guid;
  1349. dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
  1350. dev->uverbs_cmd_mask =
  1351. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  1352. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  1353. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  1354. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  1355. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  1356. (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
  1357. (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
  1358. (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
  1359. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  1360. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  1361. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  1362. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  1363. (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
  1364. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  1365. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  1366. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  1367. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  1368. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  1369. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  1370. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  1371. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  1372. (1ull << IB_USER_VERBS_CMD_POST_RECV) |
  1373. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  1374. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
  1375. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  1376. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  1377. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  1378. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
  1379. (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
  1380. dev->node_type = RDMA_NODE_IB_CA;
  1381. dev->phys_port_cnt = 1;
  1382. dev->num_comp_vectors = 1;
  1383. dev->dma_device = &dd->pcidev->dev;
  1384. dev->query_device = ipath_query_device;
  1385. dev->modify_device = ipath_modify_device;
  1386. dev->query_port = ipath_query_port;
  1387. dev->modify_port = ipath_modify_port;
  1388. dev->query_pkey = ipath_query_pkey;
  1389. dev->query_gid = ipath_query_gid;
  1390. dev->alloc_ucontext = ipath_alloc_ucontext;
  1391. dev->dealloc_ucontext = ipath_dealloc_ucontext;
  1392. dev->alloc_pd = ipath_alloc_pd;
  1393. dev->dealloc_pd = ipath_dealloc_pd;
  1394. dev->create_ah = ipath_create_ah;
  1395. dev->destroy_ah = ipath_destroy_ah;
  1396. dev->query_ah = ipath_query_ah;
  1397. dev->create_srq = ipath_create_srq;
  1398. dev->modify_srq = ipath_modify_srq;
  1399. dev->query_srq = ipath_query_srq;
  1400. dev->destroy_srq = ipath_destroy_srq;
  1401. dev->create_qp = ipath_create_qp;
  1402. dev->modify_qp = ipath_modify_qp;
  1403. dev->query_qp = ipath_query_qp;
  1404. dev->destroy_qp = ipath_destroy_qp;
  1405. dev->post_send = ipath_post_send;
  1406. dev->post_recv = ipath_post_receive;
  1407. dev->post_srq_recv = ipath_post_srq_receive;
  1408. dev->create_cq = ipath_create_cq;
  1409. dev->destroy_cq = ipath_destroy_cq;
  1410. dev->resize_cq = ipath_resize_cq;
  1411. dev->poll_cq = ipath_poll_cq;
  1412. dev->req_notify_cq = ipath_req_notify_cq;
  1413. dev->get_dma_mr = ipath_get_dma_mr;
  1414. dev->reg_phys_mr = ipath_reg_phys_mr;
  1415. dev->reg_user_mr = ipath_reg_user_mr;
  1416. dev->dereg_mr = ipath_dereg_mr;
  1417. dev->alloc_fmr = ipath_alloc_fmr;
  1418. dev->map_phys_fmr = ipath_map_phys_fmr;
  1419. dev->unmap_fmr = ipath_unmap_fmr;
  1420. dev->dealloc_fmr = ipath_dealloc_fmr;
  1421. dev->attach_mcast = ipath_multicast_attach;
  1422. dev->detach_mcast = ipath_multicast_detach;
  1423. dev->process_mad = ipath_process_mad;
  1424. dev->mmap = ipath_mmap;
  1425. dev->dma_ops = &ipath_dma_mapping_ops;
  1426. snprintf(dev->node_desc, sizeof(dev->node_desc),
  1427. IPATH_IDSTR " %s", init_utsname()->nodename);
  1428. ret = ib_register_device(dev);
  1429. if (ret)
  1430. goto err_reg;
  1431. if (ipath_verbs_register_sysfs(dev))
  1432. goto err_class;
  1433. enable_timer(dd);
  1434. goto bail;
  1435. err_class:
  1436. ib_unregister_device(dev);
  1437. err_reg:
  1438. kfree(idev->lk_table.table);
  1439. err_lk:
  1440. kfree(idev->qp_table.table);
  1441. err_qp:
  1442. ib_dealloc_device(dev);
  1443. ipath_dev_err(dd, "cannot register verbs: %d!\n", -ret);
  1444. idev = NULL;
  1445. bail:
  1446. dd->verbs_dev = idev;
  1447. return ret;
  1448. }
  1449. void ipath_unregister_ib_device(struct ipath_ibdev *dev)
  1450. {
  1451. struct ib_device *ibdev = &dev->ibdev;
  1452. disable_timer(dev->dd);
  1453. ib_unregister_device(ibdev);
  1454. if (!list_empty(&dev->pending[0]) ||
  1455. !list_empty(&dev->pending[1]) ||
  1456. !list_empty(&dev->pending[2]))
  1457. ipath_dev_err(dev->dd, "pending list not empty!\n");
  1458. if (!list_empty(&dev->piowait))
  1459. ipath_dev_err(dev->dd, "piowait list not empty!\n");
  1460. if (!list_empty(&dev->rnrwait))
  1461. ipath_dev_err(dev->dd, "rnrwait list not empty!\n");
  1462. if (!ipath_mcast_tree_empty())
  1463. ipath_dev_err(dev->dd, "multicast table memory leak!\n");
  1464. /*
  1465. * Note that ipath_unregister_ib_device() can be called before all
  1466. * the QPs are destroyed!
  1467. */
  1468. ipath_free_all_qps(&dev->qp_table);
  1469. kfree(dev->qp_table.table);
  1470. kfree(dev->lk_table.table);
  1471. ib_dealloc_device(ibdev);
  1472. }
  1473. static ssize_t show_rev(struct class_device *cdev, char *buf)
  1474. {
  1475. struct ipath_ibdev *dev =
  1476. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1477. return sprintf(buf, "%x\n", dev->dd->ipath_pcirev);
  1478. }
  1479. static ssize_t show_hca(struct class_device *cdev, char *buf)
  1480. {
  1481. struct ipath_ibdev *dev =
  1482. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1483. int ret;
  1484. ret = dev->dd->ipath_f_get_boardname(dev->dd, buf, 128);
  1485. if (ret < 0)
  1486. goto bail;
  1487. strcat(buf, "\n");
  1488. ret = strlen(buf);
  1489. bail:
  1490. return ret;
  1491. }
  1492. static ssize_t show_stats(struct class_device *cdev, char *buf)
  1493. {
  1494. struct ipath_ibdev *dev =
  1495. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1496. int i;
  1497. int len;
  1498. len = sprintf(buf,
  1499. "RC resends %d\n"
  1500. "RC no QACK %d\n"
  1501. "RC ACKs %d\n"
  1502. "RC SEQ NAKs %d\n"
  1503. "RC RDMA seq %d\n"
  1504. "RC RNR NAKs %d\n"
  1505. "RC OTH NAKs %d\n"
  1506. "RC timeouts %d\n"
  1507. "RC RDMA dup %d\n"
  1508. "RC stalls %d\n"
  1509. "piobuf wait %d\n"
  1510. "no piobuf %d\n"
  1511. "PKT drops %d\n"
  1512. "WQE errs %d\n",
  1513. dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
  1514. dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
  1515. dev->n_other_naks, dev->n_timeouts,
  1516. dev->n_rdma_dup_busy, dev->n_rc_stalls, dev->n_piowait,
  1517. dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
  1518. for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
  1519. const struct ipath_opcode_stats *si = &dev->opstats[i];
  1520. if (!si->n_packets && !si->n_bytes)
  1521. continue;
  1522. len += sprintf(buf + len, "%02x %llu/%llu\n", i,
  1523. (unsigned long long) si->n_packets,
  1524. (unsigned long long) si->n_bytes);
  1525. }
  1526. return len;
  1527. }
  1528. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  1529. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  1530. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  1531. static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  1532. static struct class_device_attribute *ipath_class_attributes[] = {
  1533. &class_device_attr_hw_rev,
  1534. &class_device_attr_hca_type,
  1535. &class_device_attr_board_id,
  1536. &class_device_attr_stats
  1537. };
  1538. static int ipath_verbs_register_sysfs(struct ib_device *dev)
  1539. {
  1540. int i;
  1541. int ret;
  1542. for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
  1543. if (class_device_create_file(&dev->class_dev,
  1544. ipath_class_attributes[i])) {
  1545. ret = 1;
  1546. goto bail;
  1547. }
  1548. ret = 0;
  1549. bail:
  1550. return ret;
  1551. }