ipath_verbs.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  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. mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
  388. if (mcast == NULL) {
  389. dev->n_pkt_drops++;
  390. goto bail;
  391. }
  392. dev->n_multicast_rcv++;
  393. list_for_each_entry_rcu(p, &mcast->qp_list, list)
  394. ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data,
  395. tlen, p->qp);
  396. /*
  397. * Notify ipath_multicast_detach() if it is waiting for us
  398. * to finish.
  399. */
  400. if (atomic_dec_return(&mcast->refcount) <= 1)
  401. wake_up(&mcast->wait);
  402. } else {
  403. qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
  404. if (qp) {
  405. dev->n_unicast_rcv++;
  406. ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data,
  407. tlen, qp);
  408. /*
  409. * Notify ipath_destroy_qp() if it is waiting
  410. * for us to finish.
  411. */
  412. if (atomic_dec_and_test(&qp->refcount))
  413. wake_up(&qp->wait);
  414. } else
  415. dev->n_pkt_drops++;
  416. }
  417. bail:;
  418. }
  419. /**
  420. * ipath_ib_timer - verbs timer
  421. * @arg: the device pointer
  422. *
  423. * This is called from ipath_do_rcv_timer() at interrupt level to check for
  424. * QPs which need retransmits and to collect performance numbers.
  425. */
  426. void ipath_ib_timer(struct ipath_ibdev *dev)
  427. {
  428. struct ipath_qp *resend = NULL;
  429. struct list_head *last;
  430. struct ipath_qp *qp;
  431. unsigned long flags;
  432. if (dev == NULL)
  433. return;
  434. spin_lock_irqsave(&dev->pending_lock, flags);
  435. /* Start filling the next pending queue. */
  436. if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
  437. dev->pending_index = 0;
  438. /* Save any requests still in the new queue, they have timed out. */
  439. last = &dev->pending[dev->pending_index];
  440. while (!list_empty(last)) {
  441. qp = list_entry(last->next, struct ipath_qp, timerwait);
  442. list_del_init(&qp->timerwait);
  443. qp->timer_next = resend;
  444. resend = qp;
  445. atomic_inc(&qp->refcount);
  446. }
  447. last = &dev->rnrwait;
  448. if (!list_empty(last)) {
  449. qp = list_entry(last->next, struct ipath_qp, timerwait);
  450. if (--qp->s_rnr_timeout == 0) {
  451. do {
  452. list_del_init(&qp->timerwait);
  453. tasklet_hi_schedule(&qp->s_task);
  454. if (list_empty(last))
  455. break;
  456. qp = list_entry(last->next, struct ipath_qp,
  457. timerwait);
  458. } while (qp->s_rnr_timeout == 0);
  459. }
  460. }
  461. /*
  462. * We should only be in the started state if pma_sample_start != 0
  463. */
  464. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
  465. --dev->pma_sample_start == 0) {
  466. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  467. ipath_snapshot_counters(dev->dd, &dev->ipath_sword,
  468. &dev->ipath_rword,
  469. &dev->ipath_spkts,
  470. &dev->ipath_rpkts,
  471. &dev->ipath_xmit_wait);
  472. }
  473. if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
  474. if (dev->pma_sample_interval == 0) {
  475. u64 ta, tb, tc, td, te;
  476. dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  477. ipath_snapshot_counters(dev->dd, &ta, &tb,
  478. &tc, &td, &te);
  479. dev->ipath_sword = ta - dev->ipath_sword;
  480. dev->ipath_rword = tb - dev->ipath_rword;
  481. dev->ipath_spkts = tc - dev->ipath_spkts;
  482. dev->ipath_rpkts = td - dev->ipath_rpkts;
  483. dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
  484. }
  485. else
  486. dev->pma_sample_interval--;
  487. }
  488. spin_unlock_irqrestore(&dev->pending_lock, flags);
  489. /* XXX What if timer fires again while this is running? */
  490. for (qp = resend; qp != NULL; qp = qp->timer_next) {
  491. struct ib_wc wc;
  492. spin_lock_irqsave(&qp->s_lock, flags);
  493. if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) {
  494. dev->n_timeouts++;
  495. ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
  496. }
  497. spin_unlock_irqrestore(&qp->s_lock, flags);
  498. /* Notify ipath_destroy_qp() if it is waiting. */
  499. if (atomic_dec_and_test(&qp->refcount))
  500. wake_up(&qp->wait);
  501. }
  502. }
  503. static void update_sge(struct ipath_sge_state *ss, u32 length)
  504. {
  505. struct ipath_sge *sge = &ss->sge;
  506. sge->vaddr += length;
  507. sge->length -= length;
  508. sge->sge_length -= length;
  509. if (sge->sge_length == 0) {
  510. if (--ss->num_sge)
  511. *sge = *ss->sg_list++;
  512. } else if (sge->length == 0 && sge->mr != NULL) {
  513. if (++sge->n >= IPATH_SEGSZ) {
  514. if (++sge->m >= sge->mr->mapsz)
  515. return;
  516. sge->n = 0;
  517. }
  518. sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
  519. sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
  520. }
  521. }
  522. #ifdef __LITTLE_ENDIAN
  523. static inline u32 get_upper_bits(u32 data, u32 shift)
  524. {
  525. return data >> shift;
  526. }
  527. static inline u32 set_upper_bits(u32 data, u32 shift)
  528. {
  529. return data << shift;
  530. }
  531. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  532. {
  533. data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
  534. data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  535. return data;
  536. }
  537. #else
  538. static inline u32 get_upper_bits(u32 data, u32 shift)
  539. {
  540. return data << shift;
  541. }
  542. static inline u32 set_upper_bits(u32 data, u32 shift)
  543. {
  544. return data >> shift;
  545. }
  546. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  547. {
  548. data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
  549. data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  550. return data;
  551. }
  552. #endif
  553. static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
  554. u32 length)
  555. {
  556. u32 extra = 0;
  557. u32 data = 0;
  558. u32 last;
  559. while (1) {
  560. u32 len = ss->sge.length;
  561. u32 off;
  562. BUG_ON(len == 0);
  563. if (len > length)
  564. len = length;
  565. if (len > ss->sge.sge_length)
  566. len = ss->sge.sge_length;
  567. /* If the source address is not aligned, try to align it. */
  568. off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
  569. if (off) {
  570. u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
  571. ~(sizeof(u32) - 1));
  572. u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
  573. u32 y;
  574. y = sizeof(u32) - off;
  575. if (len > y)
  576. len = y;
  577. if (len + extra >= sizeof(u32)) {
  578. data |= set_upper_bits(v, extra *
  579. BITS_PER_BYTE);
  580. len = sizeof(u32) - extra;
  581. if (len == length) {
  582. last = data;
  583. break;
  584. }
  585. __raw_writel(data, piobuf);
  586. piobuf++;
  587. extra = 0;
  588. data = 0;
  589. } else {
  590. /* Clear unused upper bytes */
  591. data |= clear_upper_bytes(v, len, extra);
  592. if (len == length) {
  593. last = data;
  594. break;
  595. }
  596. extra += len;
  597. }
  598. } else if (extra) {
  599. /* Source address is aligned. */
  600. u32 *addr = (u32 *) ss->sge.vaddr;
  601. int shift = extra * BITS_PER_BYTE;
  602. int ushift = 32 - shift;
  603. u32 l = len;
  604. while (l >= sizeof(u32)) {
  605. u32 v = *addr;
  606. data |= set_upper_bits(v, shift);
  607. __raw_writel(data, piobuf);
  608. data = get_upper_bits(v, ushift);
  609. piobuf++;
  610. addr++;
  611. l -= sizeof(u32);
  612. }
  613. /*
  614. * We still have 'extra' number of bytes leftover.
  615. */
  616. if (l) {
  617. u32 v = *addr;
  618. if (l + extra >= sizeof(u32)) {
  619. data |= set_upper_bits(v, shift);
  620. len -= l + extra - sizeof(u32);
  621. if (len == length) {
  622. last = data;
  623. break;
  624. }
  625. __raw_writel(data, piobuf);
  626. piobuf++;
  627. extra = 0;
  628. data = 0;
  629. } else {
  630. /* Clear unused upper bytes */
  631. data |= clear_upper_bytes(v, l,
  632. extra);
  633. if (len == length) {
  634. last = data;
  635. break;
  636. }
  637. extra += l;
  638. }
  639. } else if (len == length) {
  640. last = data;
  641. break;
  642. }
  643. } else if (len == length) {
  644. u32 w;
  645. /*
  646. * Need to round up for the last dword in the
  647. * packet.
  648. */
  649. w = (len + 3) >> 2;
  650. __iowrite32_copy(piobuf, ss->sge.vaddr, w - 1);
  651. piobuf += w - 1;
  652. last = ((u32 *) ss->sge.vaddr)[w - 1];
  653. break;
  654. } else {
  655. u32 w = len >> 2;
  656. __iowrite32_copy(piobuf, ss->sge.vaddr, w);
  657. piobuf += w;
  658. extra = len & (sizeof(u32) - 1);
  659. if (extra) {
  660. u32 v = ((u32 *) ss->sge.vaddr)[w];
  661. /* Clear unused upper bytes */
  662. data = clear_upper_bytes(v, extra, 0);
  663. }
  664. }
  665. update_sge(ss, len);
  666. length -= len;
  667. }
  668. /* Update address before sending packet. */
  669. update_sge(ss, length);
  670. /* must flush early everything before trigger word */
  671. ipath_flush_wc();
  672. __raw_writel(last, piobuf);
  673. /* be sure trigger word is written */
  674. ipath_flush_wc();
  675. }
  676. /**
  677. * ipath_verbs_send - send a packet
  678. * @dd: the infinipath device
  679. * @hdrwords: the number of words in the header
  680. * @hdr: the packet header
  681. * @len: the length of the packet in bytes
  682. * @ss: the SGE to send
  683. */
  684. int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
  685. u32 *hdr, u32 len, struct ipath_sge_state *ss)
  686. {
  687. u32 __iomem *piobuf;
  688. u32 plen;
  689. int ret;
  690. /* +1 is for the qword padding of pbc */
  691. plen = hdrwords + ((len + 3) >> 2) + 1;
  692. if (unlikely((plen << 2) > dd->ipath_ibmaxlen)) {
  693. ipath_dbg("packet len 0x%x too long, failing\n", plen);
  694. ret = -EINVAL;
  695. goto bail;
  696. }
  697. /* Get a PIO buffer to use. */
  698. piobuf = ipath_getpiobuf(dd, NULL);
  699. if (unlikely(piobuf == NULL)) {
  700. ret = -EBUSY;
  701. goto bail;
  702. }
  703. /*
  704. * Write len to control qword, no flags.
  705. * We have to flush after the PBC for correctness on some cpus
  706. * or WC buffer can be written out of order.
  707. */
  708. writeq(plen, piobuf);
  709. ipath_flush_wc();
  710. piobuf += 2;
  711. if (len == 0) {
  712. /*
  713. * If there is just the header portion, must flush before
  714. * writing last word of header for correctness, and after
  715. * the last header word (trigger word).
  716. */
  717. __iowrite32_copy(piobuf, hdr, hdrwords - 1);
  718. ipath_flush_wc();
  719. __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
  720. ipath_flush_wc();
  721. ret = 0;
  722. goto bail;
  723. }
  724. __iowrite32_copy(piobuf, hdr, hdrwords);
  725. piobuf += hdrwords;
  726. /* The common case is aligned and contained in one segment. */
  727. if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
  728. !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
  729. u32 w;
  730. u32 *addr = (u32 *) ss->sge.vaddr;
  731. /* Update address before sending packet. */
  732. update_sge(ss, len);
  733. /* Need to round up for the last dword in the packet. */
  734. w = (len + 3) >> 2;
  735. __iowrite32_copy(piobuf, addr, w - 1);
  736. /* must flush early everything before trigger word */
  737. ipath_flush_wc();
  738. __raw_writel(addr[w - 1], piobuf + w - 1);
  739. /* be sure trigger word is written */
  740. ipath_flush_wc();
  741. ret = 0;
  742. goto bail;
  743. }
  744. copy_io(piobuf, ss, len);
  745. ret = 0;
  746. bail:
  747. return ret;
  748. }
  749. int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
  750. u64 *rwords, u64 *spkts, u64 *rpkts,
  751. u64 *xmit_wait)
  752. {
  753. int ret;
  754. if (!(dd->ipath_flags & IPATH_INITTED)) {
  755. /* no hardware, freeze, etc. */
  756. ipath_dbg("unit %u not usable\n", dd->ipath_unit);
  757. ret = -EINVAL;
  758. goto bail;
  759. }
  760. *swords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  761. *rwords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  762. *spkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  763. *rpkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  764. *xmit_wait = ipath_snap_cntr(dd, dd->ipath_cregs->cr_sendstallcnt);
  765. ret = 0;
  766. bail:
  767. return ret;
  768. }
  769. /**
  770. * ipath_get_counters - get various chip counters
  771. * @dd: the infinipath device
  772. * @cntrs: counters are placed here
  773. *
  774. * Return the counters needed by recv_pma_get_portcounters().
  775. */
  776. int ipath_get_counters(struct ipath_devdata *dd,
  777. struct ipath_verbs_counters *cntrs)
  778. {
  779. int ret;
  780. if (!(dd->ipath_flags & IPATH_INITTED)) {
  781. /* no hardware, freeze, etc. */
  782. ipath_dbg("unit %u not usable\n", dd->ipath_unit);
  783. ret = -EINVAL;
  784. goto bail;
  785. }
  786. cntrs->symbol_error_counter =
  787. ipath_snap_cntr(dd, dd->ipath_cregs->cr_ibsymbolerrcnt);
  788. cntrs->link_error_recovery_counter =
  789. ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt);
  790. /*
  791. * The link downed counter counts when the other side downs the
  792. * connection. We add in the number of times we downed the link
  793. * due to local link integrity errors to compensate.
  794. */
  795. cntrs->link_downed_counter =
  796. ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkdowncnt);
  797. cntrs->port_rcv_errors =
  798. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rxdroppktcnt) +
  799. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvovflcnt) +
  800. ipath_snap_cntr(dd, dd->ipath_cregs->cr_portovflcnt) +
  801. ipath_snap_cntr(dd, dd->ipath_cregs->cr_err_rlencnt) +
  802. ipath_snap_cntr(dd, dd->ipath_cregs->cr_invalidrlencnt) +
  803. ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) +
  804. ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) +
  805. ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) +
  806. ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt);
  807. cntrs->port_rcv_remphys_errors =
  808. ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt);
  809. cntrs->port_xmit_discards =
  810. ipath_snap_cntr(dd, dd->ipath_cregs->cr_unsupvlcnt);
  811. cntrs->port_xmit_data =
  812. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  813. cntrs->port_rcv_data =
  814. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  815. cntrs->port_xmit_packets =
  816. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  817. cntrs->port_rcv_packets =
  818. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  819. cntrs->local_link_integrity_errors = dd->ipath_lli_errors;
  820. cntrs->excessive_buffer_overrun_errors = 0; /* XXX */
  821. ret = 0;
  822. bail:
  823. return ret;
  824. }
  825. /**
  826. * ipath_ib_piobufavail - callback when a PIO buffer is available
  827. * @arg: the device pointer
  828. *
  829. * This is called from ipath_intr() at interrupt level when a PIO buffer is
  830. * available after ipath_verbs_send() returned an error that no buffers were
  831. * available. Return 1 if we consumed all the PIO buffers and we still have
  832. * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and
  833. * return zero).
  834. */
  835. int ipath_ib_piobufavail(struct ipath_ibdev *dev)
  836. {
  837. struct ipath_qp *qp;
  838. unsigned long flags;
  839. if (dev == NULL)
  840. goto bail;
  841. spin_lock_irqsave(&dev->pending_lock, flags);
  842. while (!list_empty(&dev->piowait)) {
  843. qp = list_entry(dev->piowait.next, struct ipath_qp,
  844. piowait);
  845. list_del_init(&qp->piowait);
  846. tasklet_hi_schedule(&qp->s_task);
  847. }
  848. spin_unlock_irqrestore(&dev->pending_lock, flags);
  849. bail:
  850. return 0;
  851. }
  852. static int ipath_query_device(struct ib_device *ibdev,
  853. struct ib_device_attr *props)
  854. {
  855. struct ipath_ibdev *dev = to_idev(ibdev);
  856. memset(props, 0, sizeof(*props));
  857. props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
  858. IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
  859. IB_DEVICE_SYS_IMAGE_GUID;
  860. props->page_size_cap = PAGE_SIZE;
  861. props->vendor_id = dev->dd->ipath_vendorid;
  862. props->vendor_part_id = dev->dd->ipath_deviceid;
  863. props->hw_ver = dev->dd->ipath_pcirev;
  864. props->sys_image_guid = dev->sys_image_guid;
  865. props->max_mr_size = ~0ull;
  866. props->max_qp = ib_ipath_max_qps;
  867. props->max_qp_wr = ib_ipath_max_qp_wrs;
  868. props->max_sge = ib_ipath_max_sges;
  869. props->max_cq = ib_ipath_max_cqs;
  870. props->max_ah = ib_ipath_max_ahs;
  871. props->max_cqe = ib_ipath_max_cqes;
  872. props->max_mr = dev->lk_table.max;
  873. props->max_pd = ib_ipath_max_pds;
  874. props->max_qp_rd_atom = 1;
  875. props->max_qp_init_rd_atom = 1;
  876. /* props->max_res_rd_atom */
  877. props->max_srq = ib_ipath_max_srqs;
  878. props->max_srq_wr = ib_ipath_max_srq_wrs;
  879. props->max_srq_sge = ib_ipath_max_srq_sges;
  880. /* props->local_ca_ack_delay */
  881. props->atomic_cap = IB_ATOMIC_HCA;
  882. props->max_pkeys = ipath_get_npkeys(dev->dd);
  883. props->max_mcast_grp = ib_ipath_max_mcast_grps;
  884. props->max_mcast_qp_attach = ib_ipath_max_mcast_qp_attached;
  885. props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
  886. props->max_mcast_grp;
  887. return 0;
  888. }
  889. const u8 ipath_cvt_physportstate[16] = {
  890. [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3,
  891. [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5,
  892. [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2,
  893. [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2,
  894. [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1,
  895. [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1,
  896. [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4,
  897. [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4,
  898. [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4,
  899. [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4,
  900. [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6,
  901. [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6,
  902. [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6,
  903. };
  904. u32 ipath_get_cr_errpkey(struct ipath_devdata *dd)
  905. {
  906. return ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
  907. }
  908. static int ipath_query_port(struct ib_device *ibdev,
  909. u8 port, struct ib_port_attr *props)
  910. {
  911. struct ipath_ibdev *dev = to_idev(ibdev);
  912. enum ib_mtu mtu;
  913. u16 lid = dev->dd->ipath_lid;
  914. u64 ibcstat;
  915. memset(props, 0, sizeof(*props));
  916. props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  917. props->lmc = dev->mkeyprot_resv_lmc & 7;
  918. props->sm_lid = dev->sm_lid;
  919. props->sm_sl = dev->sm_sl;
  920. ibcstat = dev->dd->ipath_lastibcstat;
  921. props->state = ((ibcstat >> 4) & 0x3) + 1;
  922. /* See phys_state_show() */
  923. props->phys_state = ipath_cvt_physportstate[
  924. dev->dd->ipath_lastibcstat & 0xf];
  925. props->port_cap_flags = dev->port_cap_flags;
  926. props->gid_tbl_len = 1;
  927. props->max_msg_sz = 0x80000000;
  928. props->pkey_tbl_len = ipath_get_npkeys(dev->dd);
  929. props->bad_pkey_cntr = ipath_get_cr_errpkey(dev->dd) -
  930. dev->z_pkey_violations;
  931. props->qkey_viol_cntr = dev->qkey_violations;
  932. props->active_width = IB_WIDTH_4X;
  933. /* See rate_show() */
  934. props->active_speed = 1; /* Regular 10Mbs speed. */
  935. props->max_vl_num = 1; /* VLCap = VL0 */
  936. props->init_type_reply = 0;
  937. props->max_mtu = IB_MTU_4096;
  938. switch (dev->dd->ipath_ibmtu) {
  939. case 4096:
  940. mtu = IB_MTU_4096;
  941. break;
  942. case 2048:
  943. mtu = IB_MTU_2048;
  944. break;
  945. case 1024:
  946. mtu = IB_MTU_1024;
  947. break;
  948. case 512:
  949. mtu = IB_MTU_512;
  950. break;
  951. case 256:
  952. mtu = IB_MTU_256;
  953. break;
  954. default:
  955. mtu = IB_MTU_2048;
  956. }
  957. props->active_mtu = mtu;
  958. props->subnet_timeout = dev->subnet_timeout;
  959. return 0;
  960. }
  961. static int ipath_modify_device(struct ib_device *device,
  962. int device_modify_mask,
  963. struct ib_device_modify *device_modify)
  964. {
  965. int ret;
  966. if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
  967. IB_DEVICE_MODIFY_NODE_DESC)) {
  968. ret = -EOPNOTSUPP;
  969. goto bail;
  970. }
  971. if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
  972. memcpy(device->node_desc, device_modify->node_desc, 64);
  973. if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
  974. to_idev(device)->sys_image_guid =
  975. cpu_to_be64(device_modify->sys_image_guid);
  976. ret = 0;
  977. bail:
  978. return ret;
  979. }
  980. static int ipath_modify_port(struct ib_device *ibdev,
  981. u8 port, int port_modify_mask,
  982. struct ib_port_modify *props)
  983. {
  984. struct ipath_ibdev *dev = to_idev(ibdev);
  985. dev->port_cap_flags |= props->set_port_cap_mask;
  986. dev->port_cap_flags &= ~props->clr_port_cap_mask;
  987. if (port_modify_mask & IB_PORT_SHUTDOWN)
  988. ipath_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
  989. if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
  990. dev->qkey_violations = 0;
  991. return 0;
  992. }
  993. static int ipath_query_gid(struct ib_device *ibdev, u8 port,
  994. int index, union ib_gid *gid)
  995. {
  996. struct ipath_ibdev *dev = to_idev(ibdev);
  997. int ret;
  998. if (index >= 1) {
  999. ret = -EINVAL;
  1000. goto bail;
  1001. }
  1002. gid->global.subnet_prefix = dev->gid_prefix;
  1003. gid->global.interface_id = dev->dd->ipath_guid;
  1004. ret = 0;
  1005. bail:
  1006. return ret;
  1007. }
  1008. static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
  1009. struct ib_ucontext *context,
  1010. struct ib_udata *udata)
  1011. {
  1012. struct ipath_ibdev *dev = to_idev(ibdev);
  1013. struct ipath_pd *pd;
  1014. struct ib_pd *ret;
  1015. /*
  1016. * This is actually totally arbitrary. Some correctness tests
  1017. * assume there's a maximum number of PDs that can be allocated.
  1018. * We don't actually have this limit, but we fail the test if
  1019. * we allow allocations of more than we report for this value.
  1020. */
  1021. pd = kmalloc(sizeof *pd, GFP_KERNEL);
  1022. if (!pd) {
  1023. ret = ERR_PTR(-ENOMEM);
  1024. goto bail;
  1025. }
  1026. spin_lock(&dev->n_pds_lock);
  1027. if (dev->n_pds_allocated == ib_ipath_max_pds) {
  1028. spin_unlock(&dev->n_pds_lock);
  1029. kfree(pd);
  1030. ret = ERR_PTR(-ENOMEM);
  1031. goto bail;
  1032. }
  1033. dev->n_pds_allocated++;
  1034. spin_unlock(&dev->n_pds_lock);
  1035. /* ib_alloc_pd() will initialize pd->ibpd. */
  1036. pd->user = udata != NULL;
  1037. ret = &pd->ibpd;
  1038. bail:
  1039. return ret;
  1040. }
  1041. static int ipath_dealloc_pd(struct ib_pd *ibpd)
  1042. {
  1043. struct ipath_pd *pd = to_ipd(ibpd);
  1044. struct ipath_ibdev *dev = to_idev(ibpd->device);
  1045. spin_lock(&dev->n_pds_lock);
  1046. dev->n_pds_allocated--;
  1047. spin_unlock(&dev->n_pds_lock);
  1048. kfree(pd);
  1049. return 0;
  1050. }
  1051. /**
  1052. * ipath_create_ah - create an address handle
  1053. * @pd: the protection domain
  1054. * @ah_attr: the attributes of the AH
  1055. *
  1056. * This may be called from interrupt context.
  1057. */
  1058. static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
  1059. struct ib_ah_attr *ah_attr)
  1060. {
  1061. struct ipath_ah *ah;
  1062. struct ib_ah *ret;
  1063. struct ipath_ibdev *dev = to_idev(pd->device);
  1064. /* A multicast address requires a GRH (see ch. 8.4.1). */
  1065. if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE &&
  1066. ah_attr->dlid != IPATH_PERMISSIVE_LID &&
  1067. !(ah_attr->ah_flags & IB_AH_GRH)) {
  1068. ret = ERR_PTR(-EINVAL);
  1069. goto bail;
  1070. }
  1071. if (ah_attr->dlid == 0) {
  1072. ret = ERR_PTR(-EINVAL);
  1073. goto bail;
  1074. }
  1075. if (ah_attr->port_num < 1 ||
  1076. ah_attr->port_num > pd->device->phys_port_cnt) {
  1077. ret = ERR_PTR(-EINVAL);
  1078. goto bail;
  1079. }
  1080. ah = kmalloc(sizeof *ah, GFP_ATOMIC);
  1081. if (!ah) {
  1082. ret = ERR_PTR(-ENOMEM);
  1083. goto bail;
  1084. }
  1085. spin_lock(&dev->n_ahs_lock);
  1086. if (dev->n_ahs_allocated == ib_ipath_max_ahs) {
  1087. spin_unlock(&dev->n_ahs_lock);
  1088. kfree(ah);
  1089. ret = ERR_PTR(-ENOMEM);
  1090. goto bail;
  1091. }
  1092. dev->n_ahs_allocated++;
  1093. spin_unlock(&dev->n_ahs_lock);
  1094. /* ib_create_ah() will initialize ah->ibah. */
  1095. ah->attr = *ah_attr;
  1096. ret = &ah->ibah;
  1097. bail:
  1098. return ret;
  1099. }
  1100. /**
  1101. * ipath_destroy_ah - destroy an address handle
  1102. * @ibah: the AH to destroy
  1103. *
  1104. * This may be called from interrupt context.
  1105. */
  1106. static int ipath_destroy_ah(struct ib_ah *ibah)
  1107. {
  1108. struct ipath_ibdev *dev = to_idev(ibah->device);
  1109. struct ipath_ah *ah = to_iah(ibah);
  1110. spin_lock(&dev->n_ahs_lock);
  1111. dev->n_ahs_allocated--;
  1112. spin_unlock(&dev->n_ahs_lock);
  1113. kfree(ah);
  1114. return 0;
  1115. }
  1116. static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
  1117. {
  1118. struct ipath_ah *ah = to_iah(ibah);
  1119. *ah_attr = ah->attr;
  1120. return 0;
  1121. }
  1122. /**
  1123. * ipath_get_npkeys - return the size of the PKEY table for port 0
  1124. * @dd: the infinipath device
  1125. */
  1126. unsigned ipath_get_npkeys(struct ipath_devdata *dd)
  1127. {
  1128. return ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys);
  1129. }
  1130. /**
  1131. * ipath_get_pkey - return the indexed PKEY from the port 0 PKEY table
  1132. * @dd: the infinipath device
  1133. * @index: the PKEY index
  1134. */
  1135. unsigned ipath_get_pkey(struct ipath_devdata *dd, unsigned index)
  1136. {
  1137. unsigned ret;
  1138. if (index >= ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys))
  1139. ret = 0;
  1140. else
  1141. ret = dd->ipath_pd[0]->port_pkeys[index];
  1142. return ret;
  1143. }
  1144. static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
  1145. u16 *pkey)
  1146. {
  1147. struct ipath_ibdev *dev = to_idev(ibdev);
  1148. int ret;
  1149. if (index >= ipath_get_npkeys(dev->dd)) {
  1150. ret = -EINVAL;
  1151. goto bail;
  1152. }
  1153. *pkey = ipath_get_pkey(dev->dd, index);
  1154. ret = 0;
  1155. bail:
  1156. return ret;
  1157. }
  1158. /**
  1159. * ipath_alloc_ucontext - allocate a ucontest
  1160. * @ibdev: the infiniband device
  1161. * @udata: not used by the InfiniPath driver
  1162. */
  1163. static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
  1164. struct ib_udata *udata)
  1165. {
  1166. struct ipath_ucontext *context;
  1167. struct ib_ucontext *ret;
  1168. context = kmalloc(sizeof *context, GFP_KERNEL);
  1169. if (!context) {
  1170. ret = ERR_PTR(-ENOMEM);
  1171. goto bail;
  1172. }
  1173. ret = &context->ibucontext;
  1174. bail:
  1175. return ret;
  1176. }
  1177. static int ipath_dealloc_ucontext(struct ib_ucontext *context)
  1178. {
  1179. kfree(to_iucontext(context));
  1180. return 0;
  1181. }
  1182. static int ipath_verbs_register_sysfs(struct ib_device *dev);
  1183. static void __verbs_timer(unsigned long arg)
  1184. {
  1185. struct ipath_devdata *dd = (struct ipath_devdata *) arg;
  1186. /*
  1187. * If port 0 receive packet interrupts are not available, or
  1188. * can be missed, poll the receive queue
  1189. */
  1190. if (dd->ipath_flags & IPATH_POLL_RX_INTR)
  1191. ipath_kreceive(dd);
  1192. /* Handle verbs layer timeouts. */
  1193. ipath_ib_timer(dd->verbs_dev);
  1194. mod_timer(&dd->verbs_timer, jiffies + 1);
  1195. }
  1196. static int enable_timer(struct ipath_devdata *dd)
  1197. {
  1198. /*
  1199. * Early chips had a design flaw where the chip and kernel idea
  1200. * of the tail register don't always agree, and therefore we won't
  1201. * get an interrupt on the next packet received.
  1202. * If the board supports per packet receive interrupts, use it.
  1203. * Otherwise, the timer function periodically checks for packets
  1204. * to cover this case.
  1205. * Either way, the timer is needed for verbs layer related
  1206. * processing.
  1207. */
  1208. if (dd->ipath_flags & IPATH_GPIO_INTR) {
  1209. ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
  1210. 0x2074076542310ULL);
  1211. /* Enable GPIO bit 2 interrupt */
  1212. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  1213. (u64) (1 << 2));
  1214. }
  1215. init_timer(&dd->verbs_timer);
  1216. dd->verbs_timer.function = __verbs_timer;
  1217. dd->verbs_timer.data = (unsigned long)dd;
  1218. dd->verbs_timer.expires = jiffies + 1;
  1219. add_timer(&dd->verbs_timer);
  1220. return 0;
  1221. }
  1222. static int disable_timer(struct ipath_devdata *dd)
  1223. {
  1224. /* Disable GPIO bit 2 interrupt */
  1225. if (dd->ipath_flags & IPATH_GPIO_INTR)
  1226. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask, 0);
  1227. del_timer_sync(&dd->verbs_timer);
  1228. return 0;
  1229. }
  1230. /**
  1231. * ipath_register_ib_device - register our device with the infiniband core
  1232. * @dd: the device data structure
  1233. * Return the allocated ipath_ibdev pointer or NULL on error.
  1234. */
  1235. int ipath_register_ib_device(struct ipath_devdata *dd)
  1236. {
  1237. struct ipath_verbs_counters cntrs;
  1238. struct ipath_ibdev *idev;
  1239. struct ib_device *dev;
  1240. int ret;
  1241. idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
  1242. if (idev == NULL) {
  1243. ret = -ENOMEM;
  1244. goto bail;
  1245. }
  1246. dev = &idev->ibdev;
  1247. /* Only need to initialize non-zero fields. */
  1248. spin_lock_init(&idev->n_pds_lock);
  1249. spin_lock_init(&idev->n_ahs_lock);
  1250. spin_lock_init(&idev->n_cqs_lock);
  1251. spin_lock_init(&idev->n_qps_lock);
  1252. spin_lock_init(&idev->n_srqs_lock);
  1253. spin_lock_init(&idev->n_mcast_grps_lock);
  1254. spin_lock_init(&idev->qp_table.lock);
  1255. spin_lock_init(&idev->lk_table.lock);
  1256. idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
  1257. /* Set the prefix to the default value (see ch. 4.1.1) */
  1258. idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
  1259. ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
  1260. if (ret)
  1261. goto err_qp;
  1262. /*
  1263. * The top ib_ipath_lkey_table_size bits are used to index the
  1264. * table. The lower 8 bits can be owned by the user (copied from
  1265. * the LKEY). The remaining bits act as a generation number or tag.
  1266. */
  1267. idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
  1268. idev->lk_table.table = kzalloc(idev->lk_table.max *
  1269. sizeof(*idev->lk_table.table),
  1270. GFP_KERNEL);
  1271. if (idev->lk_table.table == NULL) {
  1272. ret = -ENOMEM;
  1273. goto err_lk;
  1274. }
  1275. spin_lock_init(&idev->pending_lock);
  1276. INIT_LIST_HEAD(&idev->pending[0]);
  1277. INIT_LIST_HEAD(&idev->pending[1]);
  1278. INIT_LIST_HEAD(&idev->pending[2]);
  1279. INIT_LIST_HEAD(&idev->piowait);
  1280. INIT_LIST_HEAD(&idev->rnrwait);
  1281. idev->pending_index = 0;
  1282. idev->port_cap_flags =
  1283. IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
  1284. idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  1285. idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  1286. idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  1287. idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  1288. idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT;
  1289. idev->link_width_enabled = 3; /* 1x or 4x */
  1290. /* Snapshot current HW counters to "clear" them. */
  1291. ipath_get_counters(dd, &cntrs);
  1292. idev->z_symbol_error_counter = cntrs.symbol_error_counter;
  1293. idev->z_link_error_recovery_counter =
  1294. cntrs.link_error_recovery_counter;
  1295. idev->z_link_downed_counter = cntrs.link_downed_counter;
  1296. idev->z_port_rcv_errors = cntrs.port_rcv_errors;
  1297. idev->z_port_rcv_remphys_errors =
  1298. cntrs.port_rcv_remphys_errors;
  1299. idev->z_port_xmit_discards = cntrs.port_xmit_discards;
  1300. idev->z_port_xmit_data = cntrs.port_xmit_data;
  1301. idev->z_port_rcv_data = cntrs.port_rcv_data;
  1302. idev->z_port_xmit_packets = cntrs.port_xmit_packets;
  1303. idev->z_port_rcv_packets = cntrs.port_rcv_packets;
  1304. idev->z_local_link_integrity_errors =
  1305. cntrs.local_link_integrity_errors;
  1306. idev->z_excessive_buffer_overrun_errors =
  1307. cntrs.excessive_buffer_overrun_errors;
  1308. /*
  1309. * The system image GUID is supposed to be the same for all
  1310. * IB HCAs in a single system but since there can be other
  1311. * device types in the system, we can't be sure this is unique.
  1312. */
  1313. if (!sys_image_guid)
  1314. sys_image_guid = dd->ipath_guid;
  1315. idev->sys_image_guid = sys_image_guid;
  1316. idev->ib_unit = dd->ipath_unit;
  1317. idev->dd = dd;
  1318. strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
  1319. dev->owner = THIS_MODULE;
  1320. dev->node_guid = dd->ipath_guid;
  1321. dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
  1322. dev->uverbs_cmd_mask =
  1323. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  1324. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  1325. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  1326. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  1327. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  1328. (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
  1329. (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
  1330. (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
  1331. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  1332. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  1333. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  1334. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  1335. (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
  1336. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  1337. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  1338. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  1339. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  1340. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  1341. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  1342. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  1343. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  1344. (1ull << IB_USER_VERBS_CMD_POST_RECV) |
  1345. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  1346. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
  1347. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  1348. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  1349. (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
  1350. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
  1351. (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
  1352. dev->node_type = RDMA_NODE_IB_CA;
  1353. dev->phys_port_cnt = 1;
  1354. dev->dma_device = &dd->pcidev->dev;
  1355. dev->class_dev.dev = dev->dma_device;
  1356. dev->query_device = ipath_query_device;
  1357. dev->modify_device = ipath_modify_device;
  1358. dev->query_port = ipath_query_port;
  1359. dev->modify_port = ipath_modify_port;
  1360. dev->query_pkey = ipath_query_pkey;
  1361. dev->query_gid = ipath_query_gid;
  1362. dev->alloc_ucontext = ipath_alloc_ucontext;
  1363. dev->dealloc_ucontext = ipath_dealloc_ucontext;
  1364. dev->alloc_pd = ipath_alloc_pd;
  1365. dev->dealloc_pd = ipath_dealloc_pd;
  1366. dev->create_ah = ipath_create_ah;
  1367. dev->destroy_ah = ipath_destroy_ah;
  1368. dev->query_ah = ipath_query_ah;
  1369. dev->create_srq = ipath_create_srq;
  1370. dev->modify_srq = ipath_modify_srq;
  1371. dev->query_srq = ipath_query_srq;
  1372. dev->destroy_srq = ipath_destroy_srq;
  1373. dev->create_qp = ipath_create_qp;
  1374. dev->modify_qp = ipath_modify_qp;
  1375. dev->query_qp = ipath_query_qp;
  1376. dev->destroy_qp = ipath_destroy_qp;
  1377. dev->post_send = ipath_post_send;
  1378. dev->post_recv = ipath_post_receive;
  1379. dev->post_srq_recv = ipath_post_srq_receive;
  1380. dev->create_cq = ipath_create_cq;
  1381. dev->destroy_cq = ipath_destroy_cq;
  1382. dev->resize_cq = ipath_resize_cq;
  1383. dev->poll_cq = ipath_poll_cq;
  1384. dev->req_notify_cq = ipath_req_notify_cq;
  1385. dev->get_dma_mr = ipath_get_dma_mr;
  1386. dev->reg_phys_mr = ipath_reg_phys_mr;
  1387. dev->reg_user_mr = ipath_reg_user_mr;
  1388. dev->dereg_mr = ipath_dereg_mr;
  1389. dev->alloc_fmr = ipath_alloc_fmr;
  1390. dev->map_phys_fmr = ipath_map_phys_fmr;
  1391. dev->unmap_fmr = ipath_unmap_fmr;
  1392. dev->dealloc_fmr = ipath_dealloc_fmr;
  1393. dev->attach_mcast = ipath_multicast_attach;
  1394. dev->detach_mcast = ipath_multicast_detach;
  1395. dev->process_mad = ipath_process_mad;
  1396. dev->mmap = ipath_mmap;
  1397. snprintf(dev->node_desc, sizeof(dev->node_desc),
  1398. IPATH_IDSTR " %s", system_utsname.nodename);
  1399. ret = ib_register_device(dev);
  1400. if (ret)
  1401. goto err_reg;
  1402. if (ipath_verbs_register_sysfs(dev))
  1403. goto err_class;
  1404. enable_timer(dd);
  1405. goto bail;
  1406. err_class:
  1407. ib_unregister_device(dev);
  1408. err_reg:
  1409. kfree(idev->lk_table.table);
  1410. err_lk:
  1411. kfree(idev->qp_table.table);
  1412. err_qp:
  1413. ib_dealloc_device(dev);
  1414. ipath_dev_err(dd, "cannot register verbs: %d!\n", -ret);
  1415. idev = NULL;
  1416. bail:
  1417. dd->verbs_dev = idev;
  1418. return ret;
  1419. }
  1420. void ipath_unregister_ib_device(struct ipath_ibdev *dev)
  1421. {
  1422. struct ib_device *ibdev = &dev->ibdev;
  1423. disable_timer(dev->dd);
  1424. ib_unregister_device(ibdev);
  1425. if (!list_empty(&dev->pending[0]) ||
  1426. !list_empty(&dev->pending[1]) ||
  1427. !list_empty(&dev->pending[2]))
  1428. ipath_dev_err(dev->dd, "pending list not empty!\n");
  1429. if (!list_empty(&dev->piowait))
  1430. ipath_dev_err(dev->dd, "piowait list not empty!\n");
  1431. if (!list_empty(&dev->rnrwait))
  1432. ipath_dev_err(dev->dd, "rnrwait list not empty!\n");
  1433. if (!ipath_mcast_tree_empty())
  1434. ipath_dev_err(dev->dd, "multicast table memory leak!\n");
  1435. /*
  1436. * Note that ipath_unregister_ib_device() can be called before all
  1437. * the QPs are destroyed!
  1438. */
  1439. ipath_free_all_qps(&dev->qp_table);
  1440. kfree(dev->qp_table.table);
  1441. kfree(dev->lk_table.table);
  1442. ib_dealloc_device(ibdev);
  1443. }
  1444. static ssize_t show_rev(struct class_device *cdev, char *buf)
  1445. {
  1446. struct ipath_ibdev *dev =
  1447. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1448. return sprintf(buf, "%x\n", dev->dd->ipath_pcirev);
  1449. }
  1450. static ssize_t show_hca(struct class_device *cdev, char *buf)
  1451. {
  1452. struct ipath_ibdev *dev =
  1453. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1454. int ret;
  1455. ret = dev->dd->ipath_f_get_boardname(dev->dd, buf, 128);
  1456. if (ret < 0)
  1457. goto bail;
  1458. strcat(buf, "\n");
  1459. ret = strlen(buf);
  1460. bail:
  1461. return ret;
  1462. }
  1463. static ssize_t show_stats(struct class_device *cdev, char *buf)
  1464. {
  1465. struct ipath_ibdev *dev =
  1466. container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
  1467. int i;
  1468. int len;
  1469. len = sprintf(buf,
  1470. "RC resends %d\n"
  1471. "RC no QACK %d\n"
  1472. "RC ACKs %d\n"
  1473. "RC SEQ NAKs %d\n"
  1474. "RC RDMA seq %d\n"
  1475. "RC RNR NAKs %d\n"
  1476. "RC OTH NAKs %d\n"
  1477. "RC timeouts %d\n"
  1478. "RC RDMA dup %d\n"
  1479. "piobuf wait %d\n"
  1480. "no piobuf %d\n"
  1481. "PKT drops %d\n"
  1482. "WQE errs %d\n",
  1483. dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
  1484. dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
  1485. dev->n_other_naks, dev->n_timeouts,
  1486. dev->n_rdma_dup_busy, dev->n_piowait,
  1487. dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
  1488. for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
  1489. const struct ipath_opcode_stats *si = &dev->opstats[i];
  1490. if (!si->n_packets && !si->n_bytes)
  1491. continue;
  1492. len += sprintf(buf + len, "%02x %llu/%llu\n", i,
  1493. (unsigned long long) si->n_packets,
  1494. (unsigned long long) si->n_bytes);
  1495. }
  1496. return len;
  1497. }
  1498. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  1499. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  1500. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  1501. static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  1502. static struct class_device_attribute *ipath_class_attributes[] = {
  1503. &class_device_attr_hw_rev,
  1504. &class_device_attr_hca_type,
  1505. &class_device_attr_board_id,
  1506. &class_device_attr_stats
  1507. };
  1508. static int ipath_verbs_register_sysfs(struct ib_device *dev)
  1509. {
  1510. int i;
  1511. int ret;
  1512. for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
  1513. if (class_device_create_file(&dev->class_dev,
  1514. ipath_class_attributes[i])) {
  1515. ret = 1;
  1516. goto bail;
  1517. }
  1518. ret = 0;
  1519. bail:
  1520. return ret;
  1521. }