ipath_verbs.c 47 KB

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