qib_verbs.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. /*
  2. * Copyright (c) 2012 - 2018 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
  4. * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <rdma/ib_mad.h>
  35. #include <rdma/ib_user_verbs.h>
  36. #include <linux/io.h>
  37. #include <linux/module.h>
  38. #include <linux/utsname.h>
  39. #include <linux/rculist.h>
  40. #include <linux/mm.h>
  41. #include <linux/vmalloc.h>
  42. #include <rdma/rdma_vt.h>
  43. #include "qib.h"
  44. #include "qib_common.h"
  45. static unsigned int ib_qib_qp_table_size = 256;
  46. module_param_named(qp_table_size, ib_qib_qp_table_size, uint, S_IRUGO);
  47. MODULE_PARM_DESC(qp_table_size, "QP table size");
  48. static unsigned int qib_lkey_table_size = 16;
  49. module_param_named(lkey_table_size, qib_lkey_table_size, uint,
  50. S_IRUGO);
  51. MODULE_PARM_DESC(lkey_table_size,
  52. "LKEY table size in bits (2^n, 1 <= n <= 23)");
  53. static unsigned int ib_qib_max_pds = 0xFFFF;
  54. module_param_named(max_pds, ib_qib_max_pds, uint, S_IRUGO);
  55. MODULE_PARM_DESC(max_pds,
  56. "Maximum number of protection domains to support");
  57. static unsigned int ib_qib_max_ahs = 0xFFFF;
  58. module_param_named(max_ahs, ib_qib_max_ahs, uint, S_IRUGO);
  59. MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
  60. unsigned int ib_qib_max_cqes = 0x2FFFF;
  61. module_param_named(max_cqes, ib_qib_max_cqes, uint, S_IRUGO);
  62. MODULE_PARM_DESC(max_cqes,
  63. "Maximum number of completion queue entries to support");
  64. unsigned int ib_qib_max_cqs = 0x1FFFF;
  65. module_param_named(max_cqs, ib_qib_max_cqs, uint, S_IRUGO);
  66. MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
  67. unsigned int ib_qib_max_qp_wrs = 0x3FFF;
  68. module_param_named(max_qp_wrs, ib_qib_max_qp_wrs, uint, S_IRUGO);
  69. MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
  70. unsigned int ib_qib_max_qps = 16384;
  71. module_param_named(max_qps, ib_qib_max_qps, uint, S_IRUGO);
  72. MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
  73. unsigned int ib_qib_max_sges = 0x60;
  74. module_param_named(max_sges, ib_qib_max_sges, uint, S_IRUGO);
  75. MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
  76. unsigned int ib_qib_max_mcast_grps = 16384;
  77. module_param_named(max_mcast_grps, ib_qib_max_mcast_grps, uint, S_IRUGO);
  78. MODULE_PARM_DESC(max_mcast_grps,
  79. "Maximum number of multicast groups to support");
  80. unsigned int ib_qib_max_mcast_qp_attached = 16;
  81. module_param_named(max_mcast_qp_attached, ib_qib_max_mcast_qp_attached,
  82. uint, S_IRUGO);
  83. MODULE_PARM_DESC(max_mcast_qp_attached,
  84. "Maximum number of attached QPs to support");
  85. unsigned int ib_qib_max_srqs = 1024;
  86. module_param_named(max_srqs, ib_qib_max_srqs, uint, S_IRUGO);
  87. MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
  88. unsigned int ib_qib_max_srq_sges = 128;
  89. module_param_named(max_srq_sges, ib_qib_max_srq_sges, uint, S_IRUGO);
  90. MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
  91. unsigned int ib_qib_max_srq_wrs = 0x1FFFF;
  92. module_param_named(max_srq_wrs, ib_qib_max_srq_wrs, uint, S_IRUGO);
  93. MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
  94. static unsigned int ib_qib_disable_sma;
  95. module_param_named(disable_sma, ib_qib_disable_sma, uint, S_IWUSR | S_IRUGO);
  96. MODULE_PARM_DESC(disable_sma, "Disable the SMA");
  97. /*
  98. * Translate ib_wr_opcode into ib_wc_opcode.
  99. */
  100. const enum ib_wc_opcode ib_qib_wc_opcode[] = {
  101. [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
  102. [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
  103. [IB_WR_SEND] = IB_WC_SEND,
  104. [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
  105. [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
  106. [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
  107. [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
  108. };
  109. /*
  110. * System image GUID.
  111. */
  112. __be64 ib_qib_sys_image_guid;
  113. /*
  114. * Count the number of DMA descriptors needed to send length bytes of data.
  115. * Don't modify the qib_sge_state to get the count.
  116. * Return zero if any of the segments is not aligned.
  117. */
  118. static u32 qib_count_sge(struct rvt_sge_state *ss, u32 length)
  119. {
  120. struct rvt_sge *sg_list = ss->sg_list;
  121. struct rvt_sge sge = ss->sge;
  122. u8 num_sge = ss->num_sge;
  123. u32 ndesc = 1; /* count the header */
  124. while (length) {
  125. u32 len = rvt_get_sge_length(&sge, length);
  126. if (((long) sge.vaddr & (sizeof(u32) - 1)) ||
  127. (len != length && (len & (sizeof(u32) - 1)))) {
  128. ndesc = 0;
  129. break;
  130. }
  131. ndesc++;
  132. sge.vaddr += len;
  133. sge.length -= len;
  134. sge.sge_length -= len;
  135. if (sge.sge_length == 0) {
  136. if (--num_sge)
  137. sge = *sg_list++;
  138. } else if (sge.length == 0 && sge.mr->lkey) {
  139. if (++sge.n >= RVT_SEGSZ) {
  140. if (++sge.m >= sge.mr->mapsz)
  141. break;
  142. sge.n = 0;
  143. }
  144. sge.vaddr =
  145. sge.mr->map[sge.m]->segs[sge.n].vaddr;
  146. sge.length =
  147. sge.mr->map[sge.m]->segs[sge.n].length;
  148. }
  149. length -= len;
  150. }
  151. return ndesc;
  152. }
  153. /*
  154. * Copy from the SGEs to the data buffer.
  155. */
  156. static void qib_copy_from_sge(void *data, struct rvt_sge_state *ss, u32 length)
  157. {
  158. struct rvt_sge *sge = &ss->sge;
  159. while (length) {
  160. u32 len = rvt_get_sge_length(sge, length);
  161. memcpy(data, sge->vaddr, len);
  162. sge->vaddr += len;
  163. sge->length -= len;
  164. sge->sge_length -= len;
  165. if (sge->sge_length == 0) {
  166. if (--ss->num_sge)
  167. *sge = *ss->sg_list++;
  168. } else if (sge->length == 0 && sge->mr->lkey) {
  169. if (++sge->n >= RVT_SEGSZ) {
  170. if (++sge->m >= sge->mr->mapsz)
  171. break;
  172. sge->n = 0;
  173. }
  174. sge->vaddr =
  175. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  176. sge->length =
  177. sge->mr->map[sge->m]->segs[sge->n].length;
  178. }
  179. data += len;
  180. length -= len;
  181. }
  182. }
  183. /**
  184. * qib_qp_rcv - processing an incoming packet on a QP
  185. * @rcd: the context pointer
  186. * @hdr: the packet header
  187. * @has_grh: true if the packet has a GRH
  188. * @data: the packet data
  189. * @tlen: the packet length
  190. * @qp: the QP the packet came on
  191. *
  192. * This is called from qib_ib_rcv() to process an incoming packet
  193. * for the given QP.
  194. * Called at interrupt level.
  195. */
  196. static void qib_qp_rcv(struct qib_ctxtdata *rcd, struct ib_header *hdr,
  197. int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
  198. {
  199. struct qib_ibport *ibp = &rcd->ppd->ibport_data;
  200. spin_lock(&qp->r_lock);
  201. /* Check for valid receive state. */
  202. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
  203. ibp->rvp.n_pkt_drops++;
  204. goto unlock;
  205. }
  206. switch (qp->ibqp.qp_type) {
  207. case IB_QPT_SMI:
  208. case IB_QPT_GSI:
  209. if (ib_qib_disable_sma)
  210. break;
  211. fallthrough;
  212. case IB_QPT_UD:
  213. qib_ud_rcv(ibp, hdr, has_grh, data, tlen, qp);
  214. break;
  215. case IB_QPT_RC:
  216. qib_rc_rcv(rcd, hdr, has_grh, data, tlen, qp);
  217. break;
  218. case IB_QPT_UC:
  219. qib_uc_rcv(ibp, hdr, has_grh, data, tlen, qp);
  220. break;
  221. default:
  222. break;
  223. }
  224. unlock:
  225. spin_unlock(&qp->r_lock);
  226. }
  227. /**
  228. * qib_ib_rcv - process an incoming packet
  229. * @rcd: the context pointer
  230. * @rhdr: the header of the packet
  231. * @data: the packet payload
  232. * @tlen: the packet length
  233. *
  234. * This is called from qib_kreceive() to process an incoming packet at
  235. * interrupt level. Tlen is the length of the header + data + CRC in bytes.
  236. */
  237. void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen)
  238. {
  239. struct qib_pportdata *ppd = rcd->ppd;
  240. struct qib_ibport *ibp = &ppd->ibport_data;
  241. struct ib_header *hdr = rhdr;
  242. struct qib_devdata *dd = ppd->dd;
  243. struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
  244. struct ib_other_headers *ohdr;
  245. struct rvt_qp *qp;
  246. u32 qp_num;
  247. int lnh;
  248. u8 opcode;
  249. u16 lid;
  250. /* 24 == LRH+BTH+CRC */
  251. if (unlikely(tlen < 24))
  252. goto drop;
  253. /* Check for a valid destination LID (see ch. 7.11.1). */
  254. lid = be16_to_cpu(hdr->lrh[1]);
  255. if (lid < be16_to_cpu(IB_MULTICAST_LID_BASE)) {
  256. lid &= ~((1 << ppd->lmc) - 1);
  257. if (unlikely(lid != ppd->lid))
  258. goto drop;
  259. }
  260. /* Check for GRH */
  261. lnh = be16_to_cpu(hdr->lrh[0]) & 3;
  262. if (lnh == QIB_LRH_BTH)
  263. ohdr = &hdr->u.oth;
  264. else if (lnh == QIB_LRH_GRH) {
  265. u32 vtf;
  266. ohdr = &hdr->u.l.oth;
  267. if (hdr->u.l.grh.next_hdr != IB_GRH_NEXT_HDR)
  268. goto drop;
  269. vtf = be32_to_cpu(hdr->u.l.grh.version_tclass_flow);
  270. if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
  271. goto drop;
  272. } else
  273. goto drop;
  274. opcode = (be32_to_cpu(ohdr->bth[0]) >> 24) & 0x7f;
  275. #ifdef CONFIG_DEBUG_FS
  276. rcd->opstats->stats[opcode].n_bytes += tlen;
  277. rcd->opstats->stats[opcode].n_packets++;
  278. #endif
  279. /* Get the destination QP number. */
  280. qp_num = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
  281. if (qp_num == QIB_MULTICAST_QPN) {
  282. struct rvt_mcast *mcast;
  283. struct rvt_mcast_qp *p;
  284. if (lnh != QIB_LRH_GRH)
  285. goto drop;
  286. mcast = rvt_mcast_find(&ibp->rvp, &hdr->u.l.grh.dgid, lid);
  287. if (mcast == NULL)
  288. goto drop;
  289. this_cpu_inc(ibp->pmastats->n_multicast_rcv);
  290. rcu_read_lock();
  291. list_for_each_entry_rcu(p, &mcast->qp_list, list)
  292. qib_qp_rcv(rcd, hdr, 1, data, tlen, p->qp);
  293. rcu_read_unlock();
  294. /*
  295. * Notify rvt_multicast_detach() if it is waiting for us
  296. * to finish.
  297. */
  298. if (atomic_dec_return(&mcast->refcount) <= 1)
  299. wake_up(&mcast->wait);
  300. } else {
  301. rcu_read_lock();
  302. qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
  303. if (!qp) {
  304. rcu_read_unlock();
  305. goto drop;
  306. }
  307. this_cpu_inc(ibp->pmastats->n_unicast_rcv);
  308. qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp);
  309. rcu_read_unlock();
  310. }
  311. return;
  312. drop:
  313. ibp->rvp.n_pkt_drops++;
  314. }
  315. /*
  316. * This is called from a timer to check for QPs
  317. * which need kernel memory in order to send a packet.
  318. */
  319. static void mem_timer(struct timer_list *t)
  320. {
  321. struct qib_ibdev *dev = from_timer(dev, t, mem_timer);
  322. struct list_head *list = &dev->memwait;
  323. struct rvt_qp *qp = NULL;
  324. struct qib_qp_priv *priv = NULL;
  325. unsigned long flags;
  326. spin_lock_irqsave(&dev->rdi.pending_lock, flags);
  327. if (!list_empty(list)) {
  328. priv = list_entry(list->next, struct qib_qp_priv, iowait);
  329. qp = priv->owner;
  330. list_del_init(&priv->iowait);
  331. rvt_get_qp(qp);
  332. if (!list_empty(list))
  333. mod_timer(&dev->mem_timer, jiffies + 1);
  334. }
  335. spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
  336. if (qp) {
  337. spin_lock_irqsave(&qp->s_lock, flags);
  338. if (qp->s_flags & RVT_S_WAIT_KMEM) {
  339. qp->s_flags &= ~RVT_S_WAIT_KMEM;
  340. qib_schedule_send(qp);
  341. }
  342. spin_unlock_irqrestore(&qp->s_lock, flags);
  343. rvt_put_qp(qp);
  344. }
  345. }
  346. #ifdef __LITTLE_ENDIAN
  347. static inline u32 get_upper_bits(u32 data, u32 shift)
  348. {
  349. return data >> shift;
  350. }
  351. static inline u32 set_upper_bits(u32 data, u32 shift)
  352. {
  353. return data << shift;
  354. }
  355. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  356. {
  357. data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
  358. data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  359. return data;
  360. }
  361. #else
  362. static inline u32 get_upper_bits(u32 data, u32 shift)
  363. {
  364. return data << shift;
  365. }
  366. static inline u32 set_upper_bits(u32 data, u32 shift)
  367. {
  368. return data >> shift;
  369. }
  370. static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
  371. {
  372. data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
  373. data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
  374. return data;
  375. }
  376. #endif
  377. static void qib_copy_io(u32 __iomem *piobuf, struct rvt_sge_state *ss,
  378. u32 length, unsigned flush_wc)
  379. {
  380. u32 extra = 0;
  381. u32 data = 0;
  382. u32 last;
  383. while (1) {
  384. u32 len = rvt_get_sge_length(&ss->sge, length);
  385. u32 off;
  386. /* If the source address is not aligned, try to align it. */
  387. off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
  388. if (off) {
  389. u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
  390. ~(sizeof(u32) - 1));
  391. u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
  392. u32 y;
  393. y = sizeof(u32) - off;
  394. if (len > y)
  395. len = y;
  396. if (len + extra >= sizeof(u32)) {
  397. data |= set_upper_bits(v, extra *
  398. BITS_PER_BYTE);
  399. len = sizeof(u32) - extra;
  400. if (len == length) {
  401. last = data;
  402. break;
  403. }
  404. __raw_writel(data, piobuf);
  405. piobuf++;
  406. extra = 0;
  407. data = 0;
  408. } else {
  409. /* Clear unused upper bytes */
  410. data |= clear_upper_bytes(v, len, extra);
  411. if (len == length) {
  412. last = data;
  413. break;
  414. }
  415. extra += len;
  416. }
  417. } else if (extra) {
  418. /* Source address is aligned. */
  419. u32 *addr = (u32 *) ss->sge.vaddr;
  420. int shift = extra * BITS_PER_BYTE;
  421. int ushift = 32 - shift;
  422. u32 l = len;
  423. while (l >= sizeof(u32)) {
  424. u32 v = *addr;
  425. data |= set_upper_bits(v, shift);
  426. __raw_writel(data, piobuf);
  427. data = get_upper_bits(v, ushift);
  428. piobuf++;
  429. addr++;
  430. l -= sizeof(u32);
  431. }
  432. /*
  433. * We still have 'extra' number of bytes leftover.
  434. */
  435. if (l) {
  436. u32 v = *addr;
  437. if (l + extra >= sizeof(u32)) {
  438. data |= set_upper_bits(v, shift);
  439. len -= l + extra - sizeof(u32);
  440. if (len == length) {
  441. last = data;
  442. break;
  443. }
  444. __raw_writel(data, piobuf);
  445. piobuf++;
  446. extra = 0;
  447. data = 0;
  448. } else {
  449. /* Clear unused upper bytes */
  450. data |= clear_upper_bytes(v, l, extra);
  451. if (len == length) {
  452. last = data;
  453. break;
  454. }
  455. extra += l;
  456. }
  457. } else if (len == length) {
  458. last = data;
  459. break;
  460. }
  461. } else if (len == length) {
  462. u32 w;
  463. /*
  464. * Need to round up for the last dword in the
  465. * packet.
  466. */
  467. w = (len + 3) >> 2;
  468. qib_pio_copy(piobuf, ss->sge.vaddr, w - 1);
  469. piobuf += w - 1;
  470. last = ((u32 *) ss->sge.vaddr)[w - 1];
  471. break;
  472. } else {
  473. u32 w = len >> 2;
  474. qib_pio_copy(piobuf, ss->sge.vaddr, w);
  475. piobuf += w;
  476. extra = len & (sizeof(u32) - 1);
  477. if (extra) {
  478. u32 v = ((u32 *) ss->sge.vaddr)[w];
  479. /* Clear unused upper bytes */
  480. data = clear_upper_bytes(v, extra, 0);
  481. }
  482. }
  483. rvt_update_sge(ss, len, false);
  484. length -= len;
  485. }
  486. /* Update address before sending packet. */
  487. rvt_update_sge(ss, length, false);
  488. if (flush_wc) {
  489. /* must flush early everything before trigger word */
  490. qib_flush_wc();
  491. __raw_writel(last, piobuf);
  492. /* be sure trigger word is written */
  493. qib_flush_wc();
  494. } else
  495. __raw_writel(last, piobuf);
  496. }
  497. static noinline struct qib_verbs_txreq *__get_txreq(struct qib_ibdev *dev,
  498. struct rvt_qp *qp)
  499. {
  500. struct qib_qp_priv *priv = qp->priv;
  501. struct qib_verbs_txreq *tx;
  502. unsigned long flags;
  503. spin_lock_irqsave(&qp->s_lock, flags);
  504. spin_lock(&dev->rdi.pending_lock);
  505. if (!list_empty(&dev->txreq_free)) {
  506. struct list_head *l = dev->txreq_free.next;
  507. list_del(l);
  508. spin_unlock(&dev->rdi.pending_lock);
  509. spin_unlock_irqrestore(&qp->s_lock, flags);
  510. tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
  511. } else {
  512. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK &&
  513. list_empty(&priv->iowait)) {
  514. dev->n_txwait++;
  515. qp->s_flags |= RVT_S_WAIT_TX;
  516. list_add_tail(&priv->iowait, &dev->txwait);
  517. }
  518. qp->s_flags &= ~RVT_S_BUSY;
  519. spin_unlock(&dev->rdi.pending_lock);
  520. spin_unlock_irqrestore(&qp->s_lock, flags);
  521. tx = ERR_PTR(-EBUSY);
  522. }
  523. return tx;
  524. }
  525. static inline struct qib_verbs_txreq *get_txreq(struct qib_ibdev *dev,
  526. struct rvt_qp *qp)
  527. {
  528. struct qib_verbs_txreq *tx;
  529. unsigned long flags;
  530. spin_lock_irqsave(&dev->rdi.pending_lock, flags);
  531. /* assume the list non empty */
  532. if (likely(!list_empty(&dev->txreq_free))) {
  533. struct list_head *l = dev->txreq_free.next;
  534. list_del(l);
  535. spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
  536. tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
  537. } else {
  538. /* call slow path to get the extra lock */
  539. spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
  540. tx = __get_txreq(dev, qp);
  541. }
  542. return tx;
  543. }
  544. void qib_put_txreq(struct qib_verbs_txreq *tx)
  545. {
  546. struct qib_ibdev *dev;
  547. struct rvt_qp *qp;
  548. struct qib_qp_priv *priv;
  549. unsigned long flags;
  550. qp = tx->qp;
  551. dev = to_idev(qp->ibqp.device);
  552. if (tx->mr) {
  553. rvt_put_mr(tx->mr);
  554. tx->mr = NULL;
  555. }
  556. if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF) {
  557. tx->txreq.flags &= ~QIB_SDMA_TXREQ_F_FREEBUF;
  558. dma_unmap_single(&dd_from_dev(dev)->pcidev->dev,
  559. tx->txreq.addr, tx->hdr_dwords << 2,
  560. DMA_TO_DEVICE);
  561. kfree(tx->align_buf);
  562. }
  563. spin_lock_irqsave(&dev->rdi.pending_lock, flags);
  564. /* Put struct back on free list */
  565. list_add(&tx->txreq.list, &dev->txreq_free);
  566. if (!list_empty(&dev->txwait)) {
  567. /* Wake up first QP wanting a free struct */
  568. priv = list_entry(dev->txwait.next, struct qib_qp_priv,
  569. iowait);
  570. qp = priv->owner;
  571. list_del_init(&priv->iowait);
  572. rvt_get_qp(qp);
  573. spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
  574. spin_lock_irqsave(&qp->s_lock, flags);
  575. if (qp->s_flags & RVT_S_WAIT_TX) {
  576. qp->s_flags &= ~RVT_S_WAIT_TX;
  577. qib_schedule_send(qp);
  578. }
  579. spin_unlock_irqrestore(&qp->s_lock, flags);
  580. rvt_put_qp(qp);
  581. } else
  582. spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
  583. }
  584. /*
  585. * This is called when there are send DMA descriptors that might be
  586. * available.
  587. *
  588. * This is called with ppd->sdma_lock held.
  589. */
  590. void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail)
  591. {
  592. struct rvt_qp *qp;
  593. struct qib_qp_priv *qpp, *nqpp;
  594. struct rvt_qp *qps[20];
  595. struct qib_ibdev *dev;
  596. unsigned i, n;
  597. n = 0;
  598. dev = &ppd->dd->verbs_dev;
  599. spin_lock(&dev->rdi.pending_lock);
  600. /* Search wait list for first QP wanting DMA descriptors. */
  601. list_for_each_entry_safe(qpp, nqpp, &dev->dmawait, iowait) {
  602. qp = qpp->owner;
  603. if (qp->port_num != ppd->port)
  604. continue;
  605. if (n == ARRAY_SIZE(qps))
  606. break;
  607. if (qpp->s_tx->txreq.sg_count > avail)
  608. break;
  609. avail -= qpp->s_tx->txreq.sg_count;
  610. list_del_init(&qpp->iowait);
  611. rvt_get_qp(qp);
  612. qps[n++] = qp;
  613. }
  614. spin_unlock(&dev->rdi.pending_lock);
  615. for (i = 0; i < n; i++) {
  616. qp = qps[i];
  617. spin_lock(&qp->s_lock);
  618. if (qp->s_flags & RVT_S_WAIT_DMA_DESC) {
  619. qp->s_flags &= ~RVT_S_WAIT_DMA_DESC;
  620. qib_schedule_send(qp);
  621. }
  622. spin_unlock(&qp->s_lock);
  623. rvt_put_qp(qp);
  624. }
  625. }
  626. /*
  627. * This is called with ppd->sdma_lock held.
  628. */
  629. static void sdma_complete(struct qib_sdma_txreq *cookie, int status)
  630. {
  631. struct qib_verbs_txreq *tx =
  632. container_of(cookie, struct qib_verbs_txreq, txreq);
  633. struct rvt_qp *qp = tx->qp;
  634. struct qib_qp_priv *priv = qp->priv;
  635. spin_lock(&qp->s_lock);
  636. if (tx->wqe)
  637. rvt_send_complete(qp, tx->wqe, IB_WC_SUCCESS);
  638. else if (qp->ibqp.qp_type == IB_QPT_RC) {
  639. struct ib_header *hdr;
  640. if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF)
  641. hdr = &tx->align_buf->hdr;
  642. else {
  643. struct qib_ibdev *dev = to_idev(qp->ibqp.device);
  644. hdr = &dev->pio_hdrs[tx->hdr_inx].hdr;
  645. }
  646. qib_rc_send_complete(qp, hdr);
  647. }
  648. if (atomic_dec_and_test(&priv->s_dma_busy)) {
  649. if (qp->state == IB_QPS_RESET)
  650. wake_up(&priv->wait_dma);
  651. else if (qp->s_flags & RVT_S_WAIT_DMA) {
  652. qp->s_flags &= ~RVT_S_WAIT_DMA;
  653. qib_schedule_send(qp);
  654. }
  655. }
  656. spin_unlock(&qp->s_lock);
  657. qib_put_txreq(tx);
  658. }
  659. static int wait_kmem(struct qib_ibdev *dev, struct rvt_qp *qp)
  660. {
  661. struct qib_qp_priv *priv = qp->priv;
  662. unsigned long flags;
  663. int ret = 0;
  664. spin_lock_irqsave(&qp->s_lock, flags);
  665. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  666. spin_lock(&dev->rdi.pending_lock);
  667. if (list_empty(&priv->iowait)) {
  668. if (list_empty(&dev->memwait))
  669. mod_timer(&dev->mem_timer, jiffies + 1);
  670. qp->s_flags |= RVT_S_WAIT_KMEM;
  671. list_add_tail(&priv->iowait, &dev->memwait);
  672. }
  673. spin_unlock(&dev->rdi.pending_lock);
  674. qp->s_flags &= ~RVT_S_BUSY;
  675. ret = -EBUSY;
  676. }
  677. spin_unlock_irqrestore(&qp->s_lock, flags);
  678. return ret;
  679. }
  680. static int qib_verbs_send_dma(struct rvt_qp *qp, struct ib_header *hdr,
  681. u32 hdrwords, struct rvt_sge_state *ss, u32 len,
  682. u32 plen, u32 dwords)
  683. {
  684. struct qib_qp_priv *priv = qp->priv;
  685. struct qib_ibdev *dev = to_idev(qp->ibqp.device);
  686. struct qib_devdata *dd = dd_from_dev(dev);
  687. struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
  688. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  689. struct qib_verbs_txreq *tx;
  690. struct qib_pio_header *phdr;
  691. u32 control;
  692. u32 ndesc;
  693. int ret;
  694. tx = priv->s_tx;
  695. if (tx) {
  696. priv->s_tx = NULL;
  697. /* resend previously constructed packet */
  698. ret = qib_sdma_verbs_send(ppd, tx->ss, tx->dwords, tx);
  699. goto bail;
  700. }
  701. tx = get_txreq(dev, qp);
  702. if (IS_ERR(tx))
  703. goto bail_tx;
  704. control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
  705. be16_to_cpu(hdr->lrh[0]) >> 12);
  706. tx->qp = qp;
  707. tx->wqe = qp->s_wqe;
  708. tx->mr = qp->s_rdma_mr;
  709. if (qp->s_rdma_mr)
  710. qp->s_rdma_mr = NULL;
  711. tx->txreq.callback = sdma_complete;
  712. if (dd->flags & QIB_HAS_SDMA_TIMEOUT)
  713. tx->txreq.flags = QIB_SDMA_TXREQ_F_HEADTOHOST;
  714. else
  715. tx->txreq.flags = QIB_SDMA_TXREQ_F_INTREQ;
  716. if (plen + 1 > dd->piosize2kmax_dwords)
  717. tx->txreq.flags |= QIB_SDMA_TXREQ_F_USELARGEBUF;
  718. if (len) {
  719. /*
  720. * Don't try to DMA if it takes more descriptors than
  721. * the queue holds.
  722. */
  723. ndesc = qib_count_sge(ss, len);
  724. if (ndesc >= ppd->sdma_descq_cnt)
  725. ndesc = 0;
  726. } else
  727. ndesc = 1;
  728. if (ndesc) {
  729. phdr = &dev->pio_hdrs[tx->hdr_inx];
  730. phdr->pbc[0] = cpu_to_le32(plen);
  731. phdr->pbc[1] = cpu_to_le32(control);
  732. memcpy(&phdr->hdr, hdr, hdrwords << 2);
  733. tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEDESC;
  734. tx->txreq.sg_count = ndesc;
  735. tx->txreq.addr = dev->pio_hdrs_phys +
  736. tx->hdr_inx * sizeof(struct qib_pio_header);
  737. tx->hdr_dwords = hdrwords + 2; /* add PBC length */
  738. ret = qib_sdma_verbs_send(ppd, ss, dwords, tx);
  739. goto bail;
  740. }
  741. /* Allocate a buffer and copy the header and payload to it. */
  742. tx->hdr_dwords = plen + 1;
  743. phdr = kmalloc(tx->hdr_dwords << 2, GFP_ATOMIC);
  744. if (!phdr)
  745. goto err_tx;
  746. phdr->pbc[0] = cpu_to_le32(plen);
  747. phdr->pbc[1] = cpu_to_le32(control);
  748. memcpy(&phdr->hdr, hdr, hdrwords << 2);
  749. qib_copy_from_sge((u32 *) &phdr->hdr + hdrwords, ss, len);
  750. tx->txreq.addr = dma_map_single(&dd->pcidev->dev, phdr,
  751. tx->hdr_dwords << 2, DMA_TO_DEVICE);
  752. if (dma_mapping_error(&dd->pcidev->dev, tx->txreq.addr))
  753. goto map_err;
  754. tx->align_buf = phdr;
  755. tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEBUF;
  756. tx->txreq.sg_count = 1;
  757. ret = qib_sdma_verbs_send(ppd, NULL, 0, tx);
  758. goto unaligned;
  759. map_err:
  760. kfree(phdr);
  761. err_tx:
  762. qib_put_txreq(tx);
  763. ret = wait_kmem(dev, qp);
  764. unaligned:
  765. ibp->rvp.n_unaligned++;
  766. bail:
  767. return ret;
  768. bail_tx:
  769. ret = PTR_ERR(tx);
  770. goto bail;
  771. }
  772. /*
  773. * If we are now in the error state, return zero to flush the
  774. * send work request.
  775. */
  776. static int no_bufs_available(struct rvt_qp *qp)
  777. {
  778. struct qib_qp_priv *priv = qp->priv;
  779. struct qib_ibdev *dev = to_idev(qp->ibqp.device);
  780. struct qib_devdata *dd;
  781. unsigned long flags;
  782. int ret = 0;
  783. /*
  784. * Note that as soon as want_buffer() is called and
  785. * possibly before it returns, qib_ib_piobufavail()
  786. * could be called. Therefore, put QP on the I/O wait list before
  787. * enabling the PIO avail interrupt.
  788. */
  789. spin_lock_irqsave(&qp->s_lock, flags);
  790. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  791. spin_lock(&dev->rdi.pending_lock);
  792. if (list_empty(&priv->iowait)) {
  793. dev->n_piowait++;
  794. qp->s_flags |= RVT_S_WAIT_PIO;
  795. list_add_tail(&priv->iowait, &dev->piowait);
  796. dd = dd_from_dev(dev);
  797. dd->f_wantpiobuf_intr(dd, 1);
  798. }
  799. spin_unlock(&dev->rdi.pending_lock);
  800. qp->s_flags &= ~RVT_S_BUSY;
  801. ret = -EBUSY;
  802. }
  803. spin_unlock_irqrestore(&qp->s_lock, flags);
  804. return ret;
  805. }
  806. static int qib_verbs_send_pio(struct rvt_qp *qp, struct ib_header *ibhdr,
  807. u32 hdrwords, struct rvt_sge_state *ss, u32 len,
  808. u32 plen, u32 dwords)
  809. {
  810. struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  811. struct qib_pportdata *ppd = dd->pport + qp->port_num - 1;
  812. u32 *hdr = (u32 *) ibhdr;
  813. u32 __iomem *piobuf_orig;
  814. u32 __iomem *piobuf;
  815. u64 pbc;
  816. unsigned long flags;
  817. unsigned flush_wc;
  818. u32 control;
  819. u32 pbufn;
  820. control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
  821. be16_to_cpu(ibhdr->lrh[0]) >> 12);
  822. pbc = ((u64) control << 32) | plen;
  823. piobuf = dd->f_getsendbuf(ppd, pbc, &pbufn);
  824. if (unlikely(piobuf == NULL))
  825. return no_bufs_available(qp);
  826. /*
  827. * Write the pbc.
  828. * We have to flush after the PBC for correctness on some cpus
  829. * or WC buffer can be written out of order.
  830. */
  831. writeq(pbc, piobuf);
  832. piobuf_orig = piobuf;
  833. piobuf += 2;
  834. flush_wc = dd->flags & QIB_PIO_FLUSH_WC;
  835. if (len == 0) {
  836. /*
  837. * If there is just the header portion, must flush before
  838. * writing last word of header for correctness, and after
  839. * the last header word (trigger word).
  840. */
  841. if (flush_wc) {
  842. qib_flush_wc();
  843. qib_pio_copy(piobuf, hdr, hdrwords - 1);
  844. qib_flush_wc();
  845. __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
  846. qib_flush_wc();
  847. } else
  848. qib_pio_copy(piobuf, hdr, hdrwords);
  849. goto done;
  850. }
  851. if (flush_wc)
  852. qib_flush_wc();
  853. qib_pio_copy(piobuf, hdr, hdrwords);
  854. piobuf += hdrwords;
  855. /* The common case is aligned and contained in one segment. */
  856. if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
  857. !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
  858. u32 *addr = (u32 *) ss->sge.vaddr;
  859. /* Update address before sending packet. */
  860. rvt_update_sge(ss, len, false);
  861. if (flush_wc) {
  862. qib_pio_copy(piobuf, addr, dwords - 1);
  863. /* must flush early everything before trigger word */
  864. qib_flush_wc();
  865. __raw_writel(addr[dwords - 1], piobuf + dwords - 1);
  866. /* be sure trigger word is written */
  867. qib_flush_wc();
  868. } else
  869. qib_pio_copy(piobuf, addr, dwords);
  870. goto done;
  871. }
  872. qib_copy_io(piobuf, ss, len, flush_wc);
  873. done:
  874. if (dd->flags & QIB_USE_SPCL_TRIG) {
  875. u32 spcl_off = (pbufn >= dd->piobcnt2k) ? 2047 : 1023;
  876. qib_flush_wc();
  877. __raw_writel(0xaebecede, piobuf_orig + spcl_off);
  878. }
  879. qib_sendbuf_done(dd, pbufn);
  880. if (qp->s_rdma_mr) {
  881. rvt_put_mr(qp->s_rdma_mr);
  882. qp->s_rdma_mr = NULL;
  883. }
  884. if (qp->s_wqe) {
  885. spin_lock_irqsave(&qp->s_lock, flags);
  886. rvt_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS);
  887. spin_unlock_irqrestore(&qp->s_lock, flags);
  888. } else if (qp->ibqp.qp_type == IB_QPT_RC) {
  889. spin_lock_irqsave(&qp->s_lock, flags);
  890. qib_rc_send_complete(qp, ibhdr);
  891. spin_unlock_irqrestore(&qp->s_lock, flags);
  892. }
  893. return 0;
  894. }
  895. /**
  896. * qib_verbs_send - send a packet
  897. * @qp: the QP to send on
  898. * @hdr: the packet header
  899. * @hdrwords: the number of 32-bit words in the header
  900. * @ss: the SGE to send
  901. * @len: the length of the packet in bytes
  902. *
  903. * Return zero if packet is sent or queued OK.
  904. * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise.
  905. */
  906. int qib_verbs_send(struct rvt_qp *qp, struct ib_header *hdr,
  907. u32 hdrwords, struct rvt_sge_state *ss, u32 len)
  908. {
  909. struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  910. u32 plen;
  911. int ret;
  912. u32 dwords = (len + 3) >> 2;
  913. /*
  914. * Calculate the send buffer trigger address.
  915. * The +1 counts for the pbc control dword following the pbc length.
  916. */
  917. plen = hdrwords + dwords + 1;
  918. /*
  919. * VL15 packets (IB_QPT_SMI) will always use PIO, so we
  920. * can defer SDMA restart until link goes ACTIVE without
  921. * worrying about just how we got there.
  922. */
  923. if (qp->ibqp.qp_type == IB_QPT_SMI ||
  924. !(dd->flags & QIB_HAS_SEND_DMA))
  925. ret = qib_verbs_send_pio(qp, hdr, hdrwords, ss, len,
  926. plen, dwords);
  927. else
  928. ret = qib_verbs_send_dma(qp, hdr, hdrwords, ss, len,
  929. plen, dwords);
  930. return ret;
  931. }
  932. int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
  933. u64 *rwords, u64 *spkts, u64 *rpkts,
  934. u64 *xmit_wait)
  935. {
  936. int ret;
  937. struct qib_devdata *dd = ppd->dd;
  938. if (!(dd->flags & QIB_PRESENT)) {
  939. /* no hardware, freeze, etc. */
  940. ret = -EINVAL;
  941. goto bail;
  942. }
  943. *swords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDSEND);
  944. *rwords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDRCV);
  945. *spkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTSEND);
  946. *rpkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTRCV);
  947. *xmit_wait = dd->f_portcntr(ppd, QIBPORTCNTR_SENDSTALL);
  948. ret = 0;
  949. bail:
  950. return ret;
  951. }
  952. /**
  953. * qib_get_counters - get various chip counters
  954. * @ppd: the qlogic_ib device
  955. * @cntrs: counters are placed here
  956. *
  957. * Return the counters needed by recv_pma_get_portcounters().
  958. */
  959. int qib_get_counters(struct qib_pportdata *ppd,
  960. struct qib_verbs_counters *cntrs)
  961. {
  962. int ret;
  963. if (!(ppd->dd->flags & QIB_PRESENT)) {
  964. /* no hardware, freeze, etc. */
  965. ret = -EINVAL;
  966. goto bail;
  967. }
  968. cntrs->symbol_error_counter =
  969. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBSYMBOLERR);
  970. cntrs->link_error_recovery_counter =
  971. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKERRRECOV);
  972. /*
  973. * The link downed counter counts when the other side downs the
  974. * connection. We add in the number of times we downed the link
  975. * due to local link integrity errors to compensate.
  976. */
  977. cntrs->link_downed_counter =
  978. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKDOWN);
  979. cntrs->port_rcv_errors =
  980. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXDROPPKT) +
  981. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVOVFL) +
  982. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERR_RLEN) +
  983. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_INVALIDRLEN) +
  984. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLINK) +
  985. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRICRC) +
  986. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRVCRC) +
  987. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLPCRC) +
  988. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_BADFORMAT);
  989. cntrs->port_rcv_errors +=
  990. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXLOCALPHYERR);
  991. cntrs->port_rcv_errors +=
  992. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXVLERR);
  993. cntrs->port_rcv_remphys_errors =
  994. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVEBP);
  995. cntrs->port_xmit_discards =
  996. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_UNSUPVL);
  997. cntrs->port_xmit_data = ppd->dd->f_portcntr(ppd,
  998. QIBPORTCNTR_WORDSEND);
  999. cntrs->port_rcv_data = ppd->dd->f_portcntr(ppd,
  1000. QIBPORTCNTR_WORDRCV);
  1001. cntrs->port_xmit_packets = ppd->dd->f_portcntr(ppd,
  1002. QIBPORTCNTR_PKTSEND);
  1003. cntrs->port_rcv_packets = ppd->dd->f_portcntr(ppd,
  1004. QIBPORTCNTR_PKTRCV);
  1005. cntrs->local_link_integrity_errors =
  1006. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_LLI);
  1007. cntrs->excessive_buffer_overrun_errors =
  1008. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_EXCESSBUFOVFL);
  1009. cntrs->vl15_dropped =
  1010. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_VL15PKTDROP);
  1011. ret = 0;
  1012. bail:
  1013. return ret;
  1014. }
  1015. /**
  1016. * qib_ib_piobufavail - callback when a PIO buffer is available
  1017. * @dd: the device pointer
  1018. *
  1019. * This is called from qib_intr() at interrupt level when a PIO buffer is
  1020. * available after qib_verbs_send() returned an error that no buffers were
  1021. * available. Disable the interrupt if there are no more QPs waiting.
  1022. */
  1023. void qib_ib_piobufavail(struct qib_devdata *dd)
  1024. {
  1025. struct qib_ibdev *dev = &dd->verbs_dev;
  1026. struct list_head *list;
  1027. struct rvt_qp *qps[5];
  1028. struct rvt_qp *qp;
  1029. unsigned long flags;
  1030. unsigned i, n;
  1031. struct qib_qp_priv *priv;
  1032. list = &dev->piowait;
  1033. n = 0;
  1034. /*
  1035. * Note: checking that the piowait list is empty and clearing
  1036. * the buffer available interrupt needs to be atomic or we
  1037. * could end up with QPs on the wait list with the interrupt
  1038. * disabled.
  1039. */
  1040. spin_lock_irqsave(&dev->rdi.pending_lock, flags);
  1041. while (!list_empty(list)) {
  1042. if (n == ARRAY_SIZE(qps))
  1043. goto full;
  1044. priv = list_entry(list->next, struct qib_qp_priv, iowait);
  1045. qp = priv->owner;
  1046. list_del_init(&priv->iowait);
  1047. rvt_get_qp(qp);
  1048. qps[n++] = qp;
  1049. }
  1050. dd->f_wantpiobuf_intr(dd, 0);
  1051. full:
  1052. spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
  1053. for (i = 0; i < n; i++) {
  1054. qp = qps[i];
  1055. spin_lock_irqsave(&qp->s_lock, flags);
  1056. if (qp->s_flags & RVT_S_WAIT_PIO) {
  1057. qp->s_flags &= ~RVT_S_WAIT_PIO;
  1058. qib_schedule_send(qp);
  1059. }
  1060. spin_unlock_irqrestore(&qp->s_lock, flags);
  1061. /* Notify qib_destroy_qp() if it is waiting. */
  1062. rvt_put_qp(qp);
  1063. }
  1064. }
  1065. static int qib_query_port(struct rvt_dev_info *rdi, u32 port_num,
  1066. struct ib_port_attr *props)
  1067. {
  1068. struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
  1069. struct qib_devdata *dd = dd_from_dev(ibdev);
  1070. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  1071. enum ib_mtu mtu;
  1072. u16 lid = ppd->lid;
  1073. /* props being zeroed by the caller, avoid zeroing it here */
  1074. props->lid = lid ? lid : be16_to_cpu(IB_LID_PERMISSIVE);
  1075. props->lmc = ppd->lmc;
  1076. props->state = dd->f_iblink_state(ppd->lastibcstat);
  1077. props->phys_state = dd->f_ibphys_portstate(ppd->lastibcstat);
  1078. props->gid_tbl_len = QIB_GUIDS_PER_PORT;
  1079. props->active_width = ppd->link_width_active;
  1080. /* See rate_show() */
  1081. props->active_speed = ppd->link_speed_active;
  1082. props->max_vl_num = qib_num_vls(ppd->vls_supported);
  1083. props->max_mtu = qib_ibmtu ? qib_ibmtu : IB_MTU_4096;
  1084. switch (ppd->ibmtu) {
  1085. case 4096:
  1086. mtu = IB_MTU_4096;
  1087. break;
  1088. case 2048:
  1089. mtu = IB_MTU_2048;
  1090. break;
  1091. case 1024:
  1092. mtu = IB_MTU_1024;
  1093. break;
  1094. case 512:
  1095. mtu = IB_MTU_512;
  1096. break;
  1097. case 256:
  1098. mtu = IB_MTU_256;
  1099. break;
  1100. default:
  1101. mtu = IB_MTU_2048;
  1102. }
  1103. props->active_mtu = mtu;
  1104. return 0;
  1105. }
  1106. static int qib_modify_device(struct ib_device *device,
  1107. int device_modify_mask,
  1108. struct ib_device_modify *device_modify)
  1109. {
  1110. struct qib_devdata *dd = dd_from_ibdev(device);
  1111. unsigned i;
  1112. int ret;
  1113. if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
  1114. IB_DEVICE_MODIFY_NODE_DESC)) {
  1115. ret = -EOPNOTSUPP;
  1116. goto bail;
  1117. }
  1118. if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) {
  1119. memcpy(device->node_desc, device_modify->node_desc,
  1120. IB_DEVICE_NODE_DESC_MAX);
  1121. for (i = 0; i < dd->num_pports; i++) {
  1122. struct qib_ibport *ibp = &dd->pport[i].ibport_data;
  1123. qib_node_desc_chg(ibp);
  1124. }
  1125. }
  1126. if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) {
  1127. ib_qib_sys_image_guid =
  1128. cpu_to_be64(device_modify->sys_image_guid);
  1129. for (i = 0; i < dd->num_pports; i++) {
  1130. struct qib_ibport *ibp = &dd->pport[i].ibport_data;
  1131. qib_sys_guid_chg(ibp);
  1132. }
  1133. }
  1134. ret = 0;
  1135. bail:
  1136. return ret;
  1137. }
  1138. static int qib_shut_down_port(struct rvt_dev_info *rdi, u32 port_num)
  1139. {
  1140. struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
  1141. struct qib_devdata *dd = dd_from_dev(ibdev);
  1142. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  1143. qib_set_linkstate(ppd, QIB_IB_LINKDOWN);
  1144. return 0;
  1145. }
  1146. static int qib_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
  1147. int guid_index, __be64 *guid)
  1148. {
  1149. struct qib_ibport *ibp = container_of(rvp, struct qib_ibport, rvp);
  1150. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1151. if (guid_index == 0)
  1152. *guid = ppd->guid;
  1153. else if (guid_index < QIB_GUIDS_PER_PORT)
  1154. *guid = ibp->guids[guid_index - 1];
  1155. else
  1156. return -EINVAL;
  1157. return 0;
  1158. }
  1159. int qib_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
  1160. {
  1161. if (rdma_ah_get_sl(ah_attr) > 15)
  1162. return -EINVAL;
  1163. if (rdma_ah_get_dlid(ah_attr) == 0)
  1164. return -EINVAL;
  1165. if (rdma_ah_get_dlid(ah_attr) >=
  1166. be16_to_cpu(IB_MULTICAST_LID_BASE) &&
  1167. rdma_ah_get_dlid(ah_attr) !=
  1168. be16_to_cpu(IB_LID_PERMISSIVE) &&
  1169. !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
  1170. return -EINVAL;
  1171. return 0;
  1172. }
  1173. static void qib_notify_new_ah(struct ib_device *ibdev,
  1174. struct rdma_ah_attr *ah_attr,
  1175. struct rvt_ah *ah)
  1176. {
  1177. struct qib_ibport *ibp;
  1178. struct qib_pportdata *ppd;
  1179. /*
  1180. * Do not trust reading anything from rvt_ah at this point as it is not
  1181. * done being setup. We can however modify things which we need to set.
  1182. */
  1183. ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
  1184. ppd = ppd_from_ibp(ibp);
  1185. ah->vl = ibp->sl_to_vl[rdma_ah_get_sl(&ah->attr)];
  1186. ah->log_pmtu = ilog2(ppd->ibmtu);
  1187. }
  1188. struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid)
  1189. {
  1190. struct rdma_ah_attr attr;
  1191. struct ib_ah *ah = ERR_PTR(-EINVAL);
  1192. struct rvt_qp *qp0;
  1193. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1194. struct qib_devdata *dd = dd_from_ppd(ppd);
  1195. u32 port_num = ppd->port;
  1196. memset(&attr, 0, sizeof(attr));
  1197. attr.type = rdma_ah_find_type(&dd->verbs_dev.rdi.ibdev, port_num);
  1198. rdma_ah_set_dlid(&attr, dlid);
  1199. rdma_ah_set_port_num(&attr, port_num);
  1200. rcu_read_lock();
  1201. qp0 = rcu_dereference(ibp->rvp.qp[0]);
  1202. if (qp0)
  1203. ah = rdma_create_ah(qp0->ibqp.pd, &attr, 0);
  1204. rcu_read_unlock();
  1205. return ah;
  1206. }
  1207. /**
  1208. * qib_get_npkeys - return the size of the PKEY table for context 0
  1209. * @dd: the qlogic_ib device
  1210. */
  1211. unsigned qib_get_npkeys(struct qib_devdata *dd)
  1212. {
  1213. return ARRAY_SIZE(dd->rcd[0]->pkeys);
  1214. }
  1215. /*
  1216. * Return the indexed PKEY from the port PKEY table.
  1217. * No need to validate rcd[ctxt]; the port is setup if we are here.
  1218. */
  1219. unsigned qib_get_pkey(struct qib_ibport *ibp, unsigned index)
  1220. {
  1221. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1222. struct qib_devdata *dd = ppd->dd;
  1223. unsigned ctxt = ppd->hw_pidx;
  1224. unsigned ret;
  1225. /* dd->rcd null if mini_init or some init failures */
  1226. if (!dd->rcd || index >= ARRAY_SIZE(dd->rcd[ctxt]->pkeys))
  1227. ret = 0;
  1228. else
  1229. ret = dd->rcd[ctxt]->pkeys[index];
  1230. return ret;
  1231. }
  1232. static void init_ibport(struct qib_pportdata *ppd)
  1233. {
  1234. struct qib_verbs_counters cntrs;
  1235. struct qib_ibport *ibp = &ppd->ibport_data;
  1236. spin_lock_init(&ibp->rvp.lock);
  1237. /* Set the prefix to the default value (see ch. 4.1.1) */
  1238. ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX;
  1239. ibp->rvp.sm_lid = be16_to_cpu(IB_LID_PERMISSIVE);
  1240. ibp->rvp.port_cap_flags = IB_PORT_SYS_IMAGE_GUID_SUP |
  1241. IB_PORT_CLIENT_REG_SUP | IB_PORT_SL_MAP_SUP |
  1242. IB_PORT_TRAP_SUP | IB_PORT_AUTO_MIGR_SUP |
  1243. IB_PORT_DR_NOTICE_SUP | IB_PORT_CAP_MASK_NOTICE_SUP |
  1244. IB_PORT_OTHER_LOCAL_CHANGES_SUP;
  1245. if (ppd->dd->flags & QIB_HAS_LINK_LATENCY)
  1246. ibp->rvp.port_cap_flags |= IB_PORT_LINK_LATENCY_SUP;
  1247. ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  1248. ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  1249. ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  1250. ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  1251. ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
  1252. /* Snapshot current HW counters to "clear" them. */
  1253. qib_get_counters(ppd, &cntrs);
  1254. ibp->z_symbol_error_counter = cntrs.symbol_error_counter;
  1255. ibp->z_link_error_recovery_counter =
  1256. cntrs.link_error_recovery_counter;
  1257. ibp->z_link_downed_counter = cntrs.link_downed_counter;
  1258. ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
  1259. ibp->z_port_rcv_remphys_errors = cntrs.port_rcv_remphys_errors;
  1260. ibp->z_port_xmit_discards = cntrs.port_xmit_discards;
  1261. ibp->z_port_xmit_data = cntrs.port_xmit_data;
  1262. ibp->z_port_rcv_data = cntrs.port_rcv_data;
  1263. ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
  1264. ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
  1265. ibp->z_local_link_integrity_errors =
  1266. cntrs.local_link_integrity_errors;
  1267. ibp->z_excessive_buffer_overrun_errors =
  1268. cntrs.excessive_buffer_overrun_errors;
  1269. ibp->z_vl15_dropped = cntrs.vl15_dropped;
  1270. RCU_INIT_POINTER(ibp->rvp.qp[0], NULL);
  1271. RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
  1272. }
  1273. /**
  1274. * qib_fill_device_attr - Fill in rvt dev info device attributes.
  1275. * @dd: the device data structure
  1276. */
  1277. static void qib_fill_device_attr(struct qib_devdata *dd)
  1278. {
  1279. struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
  1280. memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props));
  1281. rdi->dparms.props.max_pd = ib_qib_max_pds;
  1282. rdi->dparms.props.max_ah = ib_qib_max_ahs;
  1283. rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
  1284. IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
  1285. IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
  1286. IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE;
  1287. rdi->dparms.props.page_size_cap = PAGE_SIZE;
  1288. rdi->dparms.props.vendor_id =
  1289. QIB_SRC_OUI_1 << 16 | QIB_SRC_OUI_2 << 8 | QIB_SRC_OUI_3;
  1290. rdi->dparms.props.vendor_part_id = dd->deviceid;
  1291. rdi->dparms.props.hw_ver = dd->minrev;
  1292. rdi->dparms.props.sys_image_guid = ib_qib_sys_image_guid;
  1293. rdi->dparms.props.max_mr_size = ~0ULL;
  1294. rdi->dparms.props.max_qp = ib_qib_max_qps;
  1295. rdi->dparms.props.max_qp_wr = ib_qib_max_qp_wrs;
  1296. rdi->dparms.props.max_send_sge = ib_qib_max_sges;
  1297. rdi->dparms.props.max_recv_sge = ib_qib_max_sges;
  1298. rdi->dparms.props.max_sge_rd = ib_qib_max_sges;
  1299. rdi->dparms.props.max_cq = ib_qib_max_cqs;
  1300. rdi->dparms.props.max_cqe = ib_qib_max_cqes;
  1301. rdi->dparms.props.max_ah = ib_qib_max_ahs;
  1302. rdi->dparms.props.max_qp_rd_atom = QIB_MAX_RDMA_ATOMIC;
  1303. rdi->dparms.props.max_qp_init_rd_atom = 255;
  1304. rdi->dparms.props.max_srq = ib_qib_max_srqs;
  1305. rdi->dparms.props.max_srq_wr = ib_qib_max_srq_wrs;
  1306. rdi->dparms.props.max_srq_sge = ib_qib_max_srq_sges;
  1307. rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB;
  1308. rdi->dparms.props.max_pkeys = qib_get_npkeys(dd);
  1309. rdi->dparms.props.max_mcast_grp = ib_qib_max_mcast_grps;
  1310. rdi->dparms.props.max_mcast_qp_attach = ib_qib_max_mcast_qp_attached;
  1311. rdi->dparms.props.max_total_mcast_qp_attach =
  1312. rdi->dparms.props.max_mcast_qp_attach *
  1313. rdi->dparms.props.max_mcast_grp;
  1314. /* post send table */
  1315. dd->verbs_dev.rdi.post_parms = qib_post_parms;
  1316. /* opcode translation table */
  1317. dd->verbs_dev.rdi.wc_opcode = ib_qib_wc_opcode;
  1318. }
  1319. static const struct ib_device_ops qib_dev_ops = {
  1320. .owner = THIS_MODULE,
  1321. .driver_id = RDMA_DRIVER_QIB,
  1322. .port_groups = qib_attr_port_groups,
  1323. .device_group = &qib_attr_group,
  1324. .modify_device = qib_modify_device,
  1325. .process_mad = qib_process_mad,
  1326. };
  1327. /**
  1328. * qib_register_ib_device - register our device with the infiniband core
  1329. * @dd: the device data structure
  1330. * Return the allocated qib_ibdev pointer or NULL on error.
  1331. */
  1332. int qib_register_ib_device(struct qib_devdata *dd)
  1333. {
  1334. struct qib_ibdev *dev = &dd->verbs_dev;
  1335. struct ib_device *ibdev = &dev->rdi.ibdev;
  1336. struct qib_pportdata *ppd = dd->pport;
  1337. unsigned i, ctxt;
  1338. int ret;
  1339. for (i = 0; i < dd->num_pports; i++)
  1340. init_ibport(ppd + i);
  1341. /* Only need to initialize non-zero fields. */
  1342. timer_setup(&dev->mem_timer, mem_timer, 0);
  1343. INIT_LIST_HEAD(&dev->piowait);
  1344. INIT_LIST_HEAD(&dev->dmawait);
  1345. INIT_LIST_HEAD(&dev->txwait);
  1346. INIT_LIST_HEAD(&dev->memwait);
  1347. INIT_LIST_HEAD(&dev->txreq_free);
  1348. if (ppd->sdma_descq_cnt) {
  1349. dev->pio_hdrs = dma_alloc_coherent(&dd->pcidev->dev,
  1350. ppd->sdma_descq_cnt *
  1351. sizeof(struct qib_pio_header),
  1352. &dev->pio_hdrs_phys,
  1353. GFP_KERNEL);
  1354. if (!dev->pio_hdrs) {
  1355. ret = -ENOMEM;
  1356. goto err_hdrs;
  1357. }
  1358. }
  1359. for (i = 0; i < ppd->sdma_descq_cnt; i++) {
  1360. struct qib_verbs_txreq *tx;
  1361. tx = kzalloc(sizeof(*tx), GFP_KERNEL);
  1362. if (!tx) {
  1363. ret = -ENOMEM;
  1364. goto err_tx;
  1365. }
  1366. tx->hdr_inx = i;
  1367. list_add(&tx->txreq.list, &dev->txreq_free);
  1368. }
  1369. /*
  1370. * The system image GUID is supposed to be the same for all
  1371. * IB HCAs in a single system but since there can be other
  1372. * device types in the system, we can't be sure this is unique.
  1373. */
  1374. if (!ib_qib_sys_image_guid)
  1375. ib_qib_sys_image_guid = ppd->guid;
  1376. ibdev->node_guid = ppd->guid;
  1377. ibdev->phys_port_cnt = dd->num_pports;
  1378. ibdev->dev.parent = &dd->pcidev->dev;
  1379. snprintf(ibdev->node_desc, sizeof(ibdev->node_desc),
  1380. "Intel Infiniband HCA %s", init_utsname()->nodename);
  1381. /*
  1382. * Fill in rvt info object.
  1383. */
  1384. dd->verbs_dev.rdi.driver_f.get_pci_dev = qib_get_pci_dev;
  1385. dd->verbs_dev.rdi.driver_f.check_ah = qib_check_ah;
  1386. dd->verbs_dev.rdi.driver_f.setup_wqe = qib_check_send_wqe;
  1387. dd->verbs_dev.rdi.driver_f.notify_new_ah = qib_notify_new_ah;
  1388. dd->verbs_dev.rdi.driver_f.alloc_qpn = qib_alloc_qpn;
  1389. dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qib_qp_priv_alloc;
  1390. dd->verbs_dev.rdi.driver_f.qp_priv_free = qib_qp_priv_free;
  1391. dd->verbs_dev.rdi.driver_f.free_all_qps = qib_free_all_qps;
  1392. dd->verbs_dev.rdi.driver_f.notify_qp_reset = qib_notify_qp_reset;
  1393. dd->verbs_dev.rdi.driver_f.do_send = qib_do_send;
  1394. dd->verbs_dev.rdi.driver_f.schedule_send = qib_schedule_send;
  1395. dd->verbs_dev.rdi.driver_f.quiesce_qp = qib_quiesce_qp;
  1396. dd->verbs_dev.rdi.driver_f.stop_send_queue = qib_stop_send_queue;
  1397. dd->verbs_dev.rdi.driver_f.flush_qp_waiters = qib_flush_qp_waiters;
  1398. dd->verbs_dev.rdi.driver_f.notify_error_qp = qib_notify_error_qp;
  1399. dd->verbs_dev.rdi.driver_f.notify_restart_rc = qib_restart_rc;
  1400. dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = qib_mtu_to_path_mtu;
  1401. dd->verbs_dev.rdi.driver_f.mtu_from_qp = qib_mtu_from_qp;
  1402. dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = qib_get_pmtu_from_attr;
  1403. dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _qib_schedule_send;
  1404. dd->verbs_dev.rdi.driver_f.query_port_state = qib_query_port;
  1405. dd->verbs_dev.rdi.driver_f.shut_down_port = qib_shut_down_port;
  1406. dd->verbs_dev.rdi.driver_f.cap_mask_chg = qib_cap_mask_chg;
  1407. dd->verbs_dev.rdi.driver_f.notify_create_mad_agent =
  1408. qib_notify_create_mad_agent;
  1409. dd->verbs_dev.rdi.driver_f.notify_free_mad_agent =
  1410. qib_notify_free_mad_agent;
  1411. dd->verbs_dev.rdi.dparms.max_rdma_atomic = QIB_MAX_RDMA_ATOMIC;
  1412. dd->verbs_dev.rdi.driver_f.get_guid_be = qib_get_guid_be;
  1413. dd->verbs_dev.rdi.dparms.lkey_table_size = qib_lkey_table_size;
  1414. dd->verbs_dev.rdi.dparms.qp_table_size = ib_qib_qp_table_size;
  1415. dd->verbs_dev.rdi.dparms.qpn_start = 1;
  1416. dd->verbs_dev.rdi.dparms.qpn_res_start = QIB_KD_QP;
  1417. dd->verbs_dev.rdi.dparms.qpn_res_end = QIB_KD_QP; /* Reserve one QP */
  1418. dd->verbs_dev.rdi.dparms.qpn_inc = 1;
  1419. dd->verbs_dev.rdi.dparms.qos_shift = 1;
  1420. dd->verbs_dev.rdi.dparms.psn_mask = QIB_PSN_MASK;
  1421. dd->verbs_dev.rdi.dparms.psn_shift = QIB_PSN_SHIFT;
  1422. dd->verbs_dev.rdi.dparms.psn_modify_mask = QIB_PSN_MASK;
  1423. dd->verbs_dev.rdi.dparms.nports = dd->num_pports;
  1424. dd->verbs_dev.rdi.dparms.npkeys = qib_get_npkeys(dd);
  1425. dd->verbs_dev.rdi.dparms.node = dd->assigned_node_id;
  1426. dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_IBA_IB;
  1427. dd->verbs_dev.rdi.dparms.max_mad_size = IB_MGMT_MAD_SIZE;
  1428. dd->verbs_dev.rdi.dparms.sge_copy_mode = RVT_SGE_COPY_MEMCPY;
  1429. qib_fill_device_attr(dd);
  1430. ppd = dd->pport;
  1431. for (i = 0; i < dd->num_pports; i++, ppd++) {
  1432. ctxt = ppd->hw_pidx;
  1433. rvt_init_port(&dd->verbs_dev.rdi,
  1434. &ppd->ibport_data.rvp,
  1435. i,
  1436. dd->rcd[ctxt]->pkeys);
  1437. }
  1438. ib_set_device_ops(ibdev, &qib_dev_ops);
  1439. ret = rvt_register_device(&dd->verbs_dev.rdi);
  1440. if (ret)
  1441. goto err_tx;
  1442. return ret;
  1443. err_tx:
  1444. while (!list_empty(&dev->txreq_free)) {
  1445. struct list_head *l = dev->txreq_free.next;
  1446. struct qib_verbs_txreq *tx;
  1447. list_del(l);
  1448. tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
  1449. kfree(tx);
  1450. }
  1451. if (ppd->sdma_descq_cnt)
  1452. dma_free_coherent(&dd->pcidev->dev,
  1453. ppd->sdma_descq_cnt *
  1454. sizeof(struct qib_pio_header),
  1455. dev->pio_hdrs, dev->pio_hdrs_phys);
  1456. err_hdrs:
  1457. qib_dev_err(dd, "cannot register verbs: %d!\n", -ret);
  1458. return ret;
  1459. }
  1460. void qib_unregister_ib_device(struct qib_devdata *dd)
  1461. {
  1462. struct qib_ibdev *dev = &dd->verbs_dev;
  1463. rvt_unregister_device(&dd->verbs_dev.rdi);
  1464. if (!list_empty(&dev->piowait))
  1465. qib_dev_err(dd, "piowait list not empty!\n");
  1466. if (!list_empty(&dev->dmawait))
  1467. qib_dev_err(dd, "dmawait list not empty!\n");
  1468. if (!list_empty(&dev->txwait))
  1469. qib_dev_err(dd, "txwait list not empty!\n");
  1470. if (!list_empty(&dev->memwait))
  1471. qib_dev_err(dd, "memwait list not empty!\n");
  1472. del_timer_sync(&dev->mem_timer);
  1473. while (!list_empty(&dev->txreq_free)) {
  1474. struct list_head *l = dev->txreq_free.next;
  1475. struct qib_verbs_txreq *tx;
  1476. list_del(l);
  1477. tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
  1478. kfree(tx);
  1479. }
  1480. if (dd->pport->sdma_descq_cnt)
  1481. dma_free_coherent(&dd->pcidev->dev,
  1482. dd->pport->sdma_descq_cnt *
  1483. sizeof(struct qib_pio_header),
  1484. dev->pio_hdrs, dev->pio_hdrs_phys);
  1485. }
  1486. /**
  1487. * _qib_schedule_send - schedule progress
  1488. * @qp: the qp
  1489. *
  1490. * This schedules progress w/o regard to the s_flags.
  1491. *
  1492. * It is only used in post send, which doesn't hold
  1493. * the s_lock.
  1494. */
  1495. bool _qib_schedule_send(struct rvt_qp *qp)
  1496. {
  1497. struct qib_ibport *ibp =
  1498. to_iport(qp->ibqp.device, qp->port_num);
  1499. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1500. struct qib_qp_priv *priv = qp->priv;
  1501. return queue_work(ppd->qib_wq, &priv->s_work);
  1502. }
  1503. /**
  1504. * qib_schedule_send - schedule progress
  1505. * @qp: the qp
  1506. *
  1507. * This schedules qp progress. The s_lock
  1508. * should be held.
  1509. */
  1510. bool qib_schedule_send(struct rvt_qp *qp)
  1511. {
  1512. if (qib_send_ok(qp))
  1513. return _qib_schedule_send(qp);
  1514. return false;
  1515. }