iwch_provider.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /*
  2. * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/device.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/delay.h>
  38. #include <linux/errno.h>
  39. #include <linux/list.h>
  40. #include <linux/spinlock.h>
  41. #include <linux/ethtool.h>
  42. #include <asm/io.h>
  43. #include <asm/irq.h>
  44. #include <asm/byteorder.h>
  45. #include <rdma/iw_cm.h>
  46. #include <rdma/ib_verbs.h>
  47. #include <rdma/ib_smi.h>
  48. #include <rdma/ib_user_verbs.h>
  49. #include "cxio_hal.h"
  50. #include "iwch.h"
  51. #include "iwch_provider.h"
  52. #include "iwch_cm.h"
  53. #include "iwch_user.h"
  54. static int iwch_modify_port(struct ib_device *ibdev,
  55. u8 port, int port_modify_mask,
  56. struct ib_port_modify *props)
  57. {
  58. return -ENOSYS;
  59. }
  60. static struct ib_ah *iwch_ah_create(struct ib_pd *pd,
  61. struct ib_ah_attr *ah_attr)
  62. {
  63. return ERR_PTR(-ENOSYS);
  64. }
  65. static int iwch_ah_destroy(struct ib_ah *ah)
  66. {
  67. return -ENOSYS;
  68. }
  69. static int iwch_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
  70. {
  71. return -ENOSYS;
  72. }
  73. static int iwch_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
  74. {
  75. return -ENOSYS;
  76. }
  77. static int iwch_process_mad(struct ib_device *ibdev,
  78. int mad_flags,
  79. u8 port_num,
  80. struct ib_wc *in_wc,
  81. struct ib_grh *in_grh,
  82. struct ib_mad *in_mad, struct ib_mad *out_mad)
  83. {
  84. return -ENOSYS;
  85. }
  86. static int iwch_dealloc_ucontext(struct ib_ucontext *context)
  87. {
  88. struct iwch_dev *rhp = to_iwch_dev(context->device);
  89. struct iwch_ucontext *ucontext = to_iwch_ucontext(context);
  90. struct iwch_mm_entry *mm, *tmp;
  91. PDBG("%s context %p\n", __FUNCTION__, context);
  92. list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
  93. kfree(mm);
  94. cxio_release_ucontext(&rhp->rdev, &ucontext->uctx);
  95. kfree(ucontext);
  96. return 0;
  97. }
  98. static struct ib_ucontext *iwch_alloc_ucontext(struct ib_device *ibdev,
  99. struct ib_udata *udata)
  100. {
  101. struct iwch_ucontext *context;
  102. struct iwch_dev *rhp = to_iwch_dev(ibdev);
  103. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  104. context = kzalloc(sizeof(*context), GFP_KERNEL);
  105. if (!context)
  106. return ERR_PTR(-ENOMEM);
  107. cxio_init_ucontext(&rhp->rdev, &context->uctx);
  108. INIT_LIST_HEAD(&context->mmaps);
  109. spin_lock_init(&context->mmap_lock);
  110. return &context->ibucontext;
  111. }
  112. static int iwch_destroy_cq(struct ib_cq *ib_cq)
  113. {
  114. struct iwch_cq *chp;
  115. PDBG("%s ib_cq %p\n", __FUNCTION__, ib_cq);
  116. chp = to_iwch_cq(ib_cq);
  117. remove_handle(chp->rhp, &chp->rhp->cqidr, chp->cq.cqid);
  118. atomic_dec(&chp->refcnt);
  119. wait_event(chp->wait, !atomic_read(&chp->refcnt));
  120. cxio_destroy_cq(&chp->rhp->rdev, &chp->cq);
  121. kfree(chp);
  122. return 0;
  123. }
  124. static struct ib_cq *iwch_create_cq(struct ib_device *ibdev, int entries,
  125. struct ib_ucontext *ib_context,
  126. struct ib_udata *udata)
  127. {
  128. struct iwch_dev *rhp;
  129. struct iwch_cq *chp;
  130. struct iwch_create_cq_resp uresp;
  131. struct iwch_create_cq_req ureq;
  132. struct iwch_ucontext *ucontext = NULL;
  133. PDBG("%s ib_dev %p entries %d\n", __FUNCTION__, ibdev, entries);
  134. rhp = to_iwch_dev(ibdev);
  135. chp = kzalloc(sizeof(*chp), GFP_KERNEL);
  136. if (!chp)
  137. return ERR_PTR(-ENOMEM);
  138. if (ib_context) {
  139. ucontext = to_iwch_ucontext(ib_context);
  140. if (!t3a_device(rhp)) {
  141. if (ib_copy_from_udata(&ureq, udata, sizeof (ureq))) {
  142. kfree(chp);
  143. return ERR_PTR(-EFAULT);
  144. }
  145. chp->user_rptr_addr = (u32 __user *)(unsigned long)ureq.user_rptr_addr;
  146. }
  147. }
  148. if (t3a_device(rhp)) {
  149. /*
  150. * T3A: Add some fluff to handle extra CQEs inserted
  151. * for various errors.
  152. * Additional CQE possibilities:
  153. * TERMINATE,
  154. * incoming RDMA WRITE Failures
  155. * incoming RDMA READ REQUEST FAILUREs
  156. * NOTE: We cannot ensure the CQ won't overflow.
  157. */
  158. entries += 16;
  159. }
  160. entries = roundup_pow_of_two(entries);
  161. chp->cq.size_log2 = ilog2(entries);
  162. if (cxio_create_cq(&rhp->rdev, &chp->cq)) {
  163. kfree(chp);
  164. return ERR_PTR(-ENOMEM);
  165. }
  166. chp->rhp = rhp;
  167. chp->ibcq.cqe = (1 << chp->cq.size_log2) - 1;
  168. spin_lock_init(&chp->lock);
  169. atomic_set(&chp->refcnt, 1);
  170. init_waitqueue_head(&chp->wait);
  171. insert_handle(rhp, &rhp->cqidr, chp, chp->cq.cqid);
  172. if (ucontext) {
  173. struct iwch_mm_entry *mm;
  174. mm = kmalloc(sizeof *mm, GFP_KERNEL);
  175. if (!mm) {
  176. iwch_destroy_cq(&chp->ibcq);
  177. return ERR_PTR(-ENOMEM);
  178. }
  179. uresp.cqid = chp->cq.cqid;
  180. uresp.size_log2 = chp->cq.size_log2;
  181. spin_lock(&ucontext->mmap_lock);
  182. uresp.key = ucontext->key;
  183. ucontext->key += PAGE_SIZE;
  184. spin_unlock(&ucontext->mmap_lock);
  185. if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
  186. kfree(mm);
  187. iwch_destroy_cq(&chp->ibcq);
  188. return ERR_PTR(-EFAULT);
  189. }
  190. mm->key = uresp.key;
  191. mm->addr = virt_to_phys(chp->cq.queue);
  192. mm->len = PAGE_ALIGN((1UL << uresp.size_log2) *
  193. sizeof (struct t3_cqe));
  194. insert_mmap(ucontext, mm);
  195. }
  196. PDBG("created cqid 0x%0x chp %p size 0x%0x, dma_addr 0x%0llx\n",
  197. chp->cq.cqid, chp, (1 << chp->cq.size_log2),
  198. (unsigned long long) chp->cq.dma_addr);
  199. return &chp->ibcq;
  200. }
  201. static int iwch_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata)
  202. {
  203. #ifdef notyet
  204. struct iwch_cq *chp = to_iwch_cq(cq);
  205. struct t3_cq oldcq, newcq;
  206. int ret;
  207. PDBG("%s ib_cq %p cqe %d\n", __FUNCTION__, cq, cqe);
  208. /* We don't downsize... */
  209. if (cqe <= cq->cqe)
  210. return 0;
  211. /* create new t3_cq with new size */
  212. cqe = roundup_pow_of_two(cqe+1);
  213. newcq.size_log2 = ilog2(cqe);
  214. /* Dont allow resize to less than the current wce count */
  215. if (cqe < Q_COUNT(chp->cq.rptr, chp->cq.wptr)) {
  216. return -ENOMEM;
  217. }
  218. /* Quiesce all QPs using this CQ */
  219. ret = iwch_quiesce_qps(chp);
  220. if (ret) {
  221. return ret;
  222. }
  223. ret = cxio_create_cq(&chp->rhp->rdev, &newcq);
  224. if (ret) {
  225. return ret;
  226. }
  227. /* copy CQEs */
  228. memcpy(newcq.queue, chp->cq.queue, (1 << chp->cq.size_log2) *
  229. sizeof(struct t3_cqe));
  230. /* old iwch_qp gets new t3_cq but keeps old cqid */
  231. oldcq = chp->cq;
  232. chp->cq = newcq;
  233. chp->cq.cqid = oldcq.cqid;
  234. /* resize new t3_cq to update the HW context */
  235. ret = cxio_resize_cq(&chp->rhp->rdev, &chp->cq);
  236. if (ret) {
  237. chp->cq = oldcq;
  238. return ret;
  239. }
  240. chp->ibcq.cqe = (1<<chp->cq.size_log2) - 1;
  241. /* destroy old t3_cq */
  242. oldcq.cqid = newcq.cqid;
  243. ret = cxio_destroy_cq(&chp->rhp->rdev, &oldcq);
  244. if (ret) {
  245. printk(KERN_ERR MOD "%s - cxio_destroy_cq failed %d\n",
  246. __FUNCTION__, ret);
  247. }
  248. /* add user hooks here */
  249. /* resume qps */
  250. ret = iwch_resume_qps(chp);
  251. return ret;
  252. #else
  253. return -ENOSYS;
  254. #endif
  255. }
  256. static int iwch_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify)
  257. {
  258. struct iwch_dev *rhp;
  259. struct iwch_cq *chp;
  260. enum t3_cq_opcode cq_op;
  261. int err;
  262. unsigned long flag;
  263. u32 rptr;
  264. chp = to_iwch_cq(ibcq);
  265. rhp = chp->rhp;
  266. if (notify == IB_CQ_SOLICITED)
  267. cq_op = CQ_ARM_SE;
  268. else
  269. cq_op = CQ_ARM_AN;
  270. if (chp->user_rptr_addr) {
  271. if (get_user(rptr, chp->user_rptr_addr))
  272. return -EFAULT;
  273. spin_lock_irqsave(&chp->lock, flag);
  274. chp->cq.rptr = rptr;
  275. } else
  276. spin_lock_irqsave(&chp->lock, flag);
  277. PDBG("%s rptr 0x%x\n", __FUNCTION__, chp->cq.rptr);
  278. err = cxio_hal_cq_op(&rhp->rdev, &chp->cq, cq_op, 0);
  279. spin_unlock_irqrestore(&chp->lock, flag);
  280. if (err)
  281. printk(KERN_ERR MOD "Error %d rearming CQID 0x%x\n", err,
  282. chp->cq.cqid);
  283. return err;
  284. }
  285. static int iwch_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
  286. {
  287. int len = vma->vm_end - vma->vm_start;
  288. u32 key = vma->vm_pgoff << PAGE_SHIFT;
  289. struct cxio_rdev *rdev_p;
  290. int ret = 0;
  291. struct iwch_mm_entry *mm;
  292. struct iwch_ucontext *ucontext;
  293. u64 addr;
  294. PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __FUNCTION__, vma->vm_pgoff,
  295. key, len);
  296. if (vma->vm_start & (PAGE_SIZE-1)) {
  297. return -EINVAL;
  298. }
  299. rdev_p = &(to_iwch_dev(context->device)->rdev);
  300. ucontext = to_iwch_ucontext(context);
  301. mm = remove_mmap(ucontext, key, len);
  302. if (!mm)
  303. return -EINVAL;
  304. addr = mm->addr;
  305. kfree(mm);
  306. if ((addr >= rdev_p->rnic_info.udbell_physbase) &&
  307. (addr < (rdev_p->rnic_info.udbell_physbase +
  308. rdev_p->rnic_info.udbell_len))) {
  309. /*
  310. * Map T3 DB register.
  311. */
  312. if (vma->vm_flags & VM_READ) {
  313. return -EPERM;
  314. }
  315. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  316. vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
  317. vma->vm_flags &= ~VM_MAYREAD;
  318. ret = io_remap_pfn_range(vma, vma->vm_start,
  319. addr >> PAGE_SHIFT,
  320. len, vma->vm_page_prot);
  321. } else {
  322. /*
  323. * Map WQ or CQ contig dma memory...
  324. */
  325. ret = remap_pfn_range(vma, vma->vm_start,
  326. addr >> PAGE_SHIFT,
  327. len, vma->vm_page_prot);
  328. }
  329. return ret;
  330. }
  331. static int iwch_deallocate_pd(struct ib_pd *pd)
  332. {
  333. struct iwch_dev *rhp;
  334. struct iwch_pd *php;
  335. php = to_iwch_pd(pd);
  336. rhp = php->rhp;
  337. PDBG("%s ibpd %p pdid 0x%x\n", __FUNCTION__, pd, php->pdid);
  338. cxio_hal_put_pdid(rhp->rdev.rscp, php->pdid);
  339. kfree(php);
  340. return 0;
  341. }
  342. static struct ib_pd *iwch_allocate_pd(struct ib_device *ibdev,
  343. struct ib_ucontext *context,
  344. struct ib_udata *udata)
  345. {
  346. struct iwch_pd *php;
  347. u32 pdid;
  348. struct iwch_dev *rhp;
  349. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  350. rhp = (struct iwch_dev *) ibdev;
  351. pdid = cxio_hal_get_pdid(rhp->rdev.rscp);
  352. if (!pdid)
  353. return ERR_PTR(-EINVAL);
  354. php = kzalloc(sizeof(*php), GFP_KERNEL);
  355. if (!php) {
  356. cxio_hal_put_pdid(rhp->rdev.rscp, pdid);
  357. return ERR_PTR(-ENOMEM);
  358. }
  359. php->pdid = pdid;
  360. php->rhp = rhp;
  361. if (context) {
  362. if (ib_copy_to_udata(udata, &php->pdid, sizeof (__u32))) {
  363. iwch_deallocate_pd(&php->ibpd);
  364. return ERR_PTR(-EFAULT);
  365. }
  366. }
  367. PDBG("%s pdid 0x%0x ptr 0x%p\n", __FUNCTION__, pdid, php);
  368. return &php->ibpd;
  369. }
  370. static int iwch_dereg_mr(struct ib_mr *ib_mr)
  371. {
  372. struct iwch_dev *rhp;
  373. struct iwch_mr *mhp;
  374. u32 mmid;
  375. PDBG("%s ib_mr %p\n", __FUNCTION__, ib_mr);
  376. /* There can be no memory windows */
  377. if (atomic_read(&ib_mr->usecnt))
  378. return -EINVAL;
  379. mhp = to_iwch_mr(ib_mr);
  380. rhp = mhp->rhp;
  381. mmid = mhp->attr.stag >> 8;
  382. cxio_dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
  383. mhp->attr.pbl_addr);
  384. remove_handle(rhp, &rhp->mmidr, mmid);
  385. if (mhp->kva)
  386. kfree((void *) (unsigned long) mhp->kva);
  387. PDBG("%s mmid 0x%x ptr %p\n", __FUNCTION__, mmid, mhp);
  388. kfree(mhp);
  389. return 0;
  390. }
  391. static struct ib_mr *iwch_register_phys_mem(struct ib_pd *pd,
  392. struct ib_phys_buf *buffer_list,
  393. int num_phys_buf,
  394. int acc,
  395. u64 *iova_start)
  396. {
  397. __be64 *page_list;
  398. int shift;
  399. u64 total_size;
  400. int npages;
  401. struct iwch_dev *rhp;
  402. struct iwch_pd *php;
  403. struct iwch_mr *mhp;
  404. int ret;
  405. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  406. php = to_iwch_pd(pd);
  407. rhp = php->rhp;
  408. acc = iwch_convert_access(acc);
  409. mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
  410. if (!mhp)
  411. return ERR_PTR(-ENOMEM);
  412. /* First check that we have enough alignment */
  413. if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK)) {
  414. ret = -EINVAL;
  415. goto err;
  416. }
  417. if (num_phys_buf > 1 &&
  418. ((buffer_list[0].addr + buffer_list[0].size) & ~PAGE_MASK)) {
  419. ret = -EINVAL;
  420. goto err;
  421. }
  422. ret = build_phys_page_list(buffer_list, num_phys_buf, iova_start,
  423. &total_size, &npages, &shift, &page_list);
  424. if (ret)
  425. goto err;
  426. mhp->rhp = rhp;
  427. mhp->attr.pdid = php->pdid;
  428. mhp->attr.zbva = 0;
  429. /* NOTE: TPT perms are backwards from BIND WR perms! */
  430. mhp->attr.perms = (acc & 0x1) << 3;
  431. mhp->attr.perms |= (acc & 0x2) << 1;
  432. mhp->attr.perms |= (acc & 0x4) >> 1;
  433. mhp->attr.perms |= (acc & 0x8) >> 3;
  434. mhp->attr.va_fbo = *iova_start;
  435. mhp->attr.page_size = shift - 12;
  436. mhp->attr.len = (u32) total_size;
  437. mhp->attr.pbl_size = npages;
  438. ret = iwch_register_mem(rhp, php, mhp, shift, page_list);
  439. kfree(page_list);
  440. if (ret) {
  441. goto err;
  442. }
  443. return &mhp->ibmr;
  444. err:
  445. kfree(mhp);
  446. return ERR_PTR(ret);
  447. }
  448. static int iwch_reregister_phys_mem(struct ib_mr *mr,
  449. int mr_rereg_mask,
  450. struct ib_pd *pd,
  451. struct ib_phys_buf *buffer_list,
  452. int num_phys_buf,
  453. int acc, u64 * iova_start)
  454. {
  455. struct iwch_mr mh, *mhp;
  456. struct iwch_pd *php;
  457. struct iwch_dev *rhp;
  458. int new_acc;
  459. __be64 *page_list = NULL;
  460. int shift = 0;
  461. u64 total_size;
  462. int npages;
  463. int ret;
  464. PDBG("%s ib_mr %p ib_pd %p\n", __FUNCTION__, mr, pd);
  465. /* There can be no memory windows */
  466. if (atomic_read(&mr->usecnt))
  467. return -EINVAL;
  468. mhp = to_iwch_mr(mr);
  469. rhp = mhp->rhp;
  470. php = to_iwch_pd(mr->pd);
  471. /* make sure we are on the same adapter */
  472. if (rhp != php->rhp)
  473. return -EINVAL;
  474. new_acc = mhp->attr.perms;
  475. memcpy(&mh, mhp, sizeof *mhp);
  476. if (mr_rereg_mask & IB_MR_REREG_PD)
  477. php = to_iwch_pd(pd);
  478. if (mr_rereg_mask & IB_MR_REREG_ACCESS)
  479. mh.attr.perms = iwch_convert_access(acc);
  480. if (mr_rereg_mask & IB_MR_REREG_TRANS)
  481. ret = build_phys_page_list(buffer_list, num_phys_buf,
  482. iova_start,
  483. &total_size, &npages,
  484. &shift, &page_list);
  485. ret = iwch_reregister_mem(rhp, php, &mh, shift, page_list, npages);
  486. kfree(page_list);
  487. if (ret) {
  488. return ret;
  489. }
  490. if (mr_rereg_mask & IB_MR_REREG_PD)
  491. mhp->attr.pdid = php->pdid;
  492. if (mr_rereg_mask & IB_MR_REREG_ACCESS)
  493. mhp->attr.perms = acc;
  494. if (mr_rereg_mask & IB_MR_REREG_TRANS) {
  495. mhp->attr.zbva = 0;
  496. mhp->attr.va_fbo = *iova_start;
  497. mhp->attr.page_size = shift - 12;
  498. mhp->attr.len = (u32) total_size;
  499. mhp->attr.pbl_size = npages;
  500. }
  501. return 0;
  502. }
  503. static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
  504. int acc, struct ib_udata *udata)
  505. {
  506. __be64 *pages;
  507. int shift, n, len;
  508. int i, j, k;
  509. int err = 0;
  510. struct ib_umem_chunk *chunk;
  511. struct iwch_dev *rhp;
  512. struct iwch_pd *php;
  513. struct iwch_mr *mhp;
  514. struct iwch_reg_user_mr_resp uresp;
  515. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  516. shift = ffs(region->page_size) - 1;
  517. php = to_iwch_pd(pd);
  518. rhp = php->rhp;
  519. mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
  520. if (!mhp)
  521. return ERR_PTR(-ENOMEM);
  522. n = 0;
  523. list_for_each_entry(chunk, &region->chunk_list, list)
  524. n += chunk->nents;
  525. pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
  526. if (!pages) {
  527. err = -ENOMEM;
  528. goto err;
  529. }
  530. acc = iwch_convert_access(acc);
  531. i = n = 0;
  532. list_for_each_entry(chunk, &region->chunk_list, list)
  533. for (j = 0; j < chunk->nmap; ++j) {
  534. len = sg_dma_len(&chunk->page_list[j]) >> shift;
  535. for (k = 0; k < len; ++k) {
  536. pages[i++] = cpu_to_be64(sg_dma_address(
  537. &chunk->page_list[j]) +
  538. region->page_size * k);
  539. }
  540. }
  541. mhp->rhp = rhp;
  542. mhp->attr.pdid = php->pdid;
  543. mhp->attr.zbva = 0;
  544. mhp->attr.perms = (acc & 0x1) << 3;
  545. mhp->attr.perms |= (acc & 0x2) << 1;
  546. mhp->attr.perms |= (acc & 0x4) >> 1;
  547. mhp->attr.perms |= (acc & 0x8) >> 3;
  548. mhp->attr.va_fbo = region->virt_base;
  549. mhp->attr.page_size = shift - 12;
  550. mhp->attr.len = (u32) region->length;
  551. mhp->attr.pbl_size = i;
  552. err = iwch_register_mem(rhp, php, mhp, shift, pages);
  553. kfree(pages);
  554. if (err)
  555. goto err;
  556. if (udata && t3b_device(rhp)) {
  557. uresp.pbl_addr = (mhp->attr.pbl_addr -
  558. rhp->rdev.rnic_info.pbl_base) >> 3;
  559. PDBG("%s user resp pbl_addr 0x%x\n", __FUNCTION__,
  560. uresp.pbl_addr);
  561. if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
  562. iwch_dereg_mr(&mhp->ibmr);
  563. err = -EFAULT;
  564. goto err;
  565. }
  566. }
  567. return &mhp->ibmr;
  568. err:
  569. kfree(mhp);
  570. return ERR_PTR(err);
  571. }
  572. static struct ib_mr *iwch_get_dma_mr(struct ib_pd *pd, int acc)
  573. {
  574. struct ib_phys_buf bl;
  575. u64 kva;
  576. struct ib_mr *ibmr;
  577. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  578. /*
  579. * T3 only supports 32 bits of size.
  580. */
  581. bl.size = 0xffffffff;
  582. bl.addr = 0;
  583. kva = 0;
  584. ibmr = iwch_register_phys_mem(pd, &bl, 1, acc, &kva);
  585. return ibmr;
  586. }
  587. static struct ib_mw *iwch_alloc_mw(struct ib_pd *pd)
  588. {
  589. struct iwch_dev *rhp;
  590. struct iwch_pd *php;
  591. struct iwch_mw *mhp;
  592. u32 mmid;
  593. u32 stag = 0;
  594. int ret;
  595. php = to_iwch_pd(pd);
  596. rhp = php->rhp;
  597. mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
  598. if (!mhp)
  599. return ERR_PTR(-ENOMEM);
  600. ret = cxio_allocate_window(&rhp->rdev, &stag, php->pdid);
  601. if (ret) {
  602. kfree(mhp);
  603. return ERR_PTR(ret);
  604. }
  605. mhp->rhp = rhp;
  606. mhp->attr.pdid = php->pdid;
  607. mhp->attr.type = TPT_MW;
  608. mhp->attr.stag = stag;
  609. mmid = (stag) >> 8;
  610. insert_handle(rhp, &rhp->mmidr, mhp, mmid);
  611. PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __FUNCTION__, mmid, mhp, stag);
  612. return &(mhp->ibmw);
  613. }
  614. static int iwch_dealloc_mw(struct ib_mw *mw)
  615. {
  616. struct iwch_dev *rhp;
  617. struct iwch_mw *mhp;
  618. u32 mmid;
  619. mhp = to_iwch_mw(mw);
  620. rhp = mhp->rhp;
  621. mmid = (mw->rkey) >> 8;
  622. cxio_deallocate_window(&rhp->rdev, mhp->attr.stag);
  623. remove_handle(rhp, &rhp->mmidr, mmid);
  624. kfree(mhp);
  625. PDBG("%s ib_mw %p mmid 0x%x ptr %p\n", __FUNCTION__, mw, mmid, mhp);
  626. return 0;
  627. }
  628. static int iwch_destroy_qp(struct ib_qp *ib_qp)
  629. {
  630. struct iwch_dev *rhp;
  631. struct iwch_qp *qhp;
  632. struct iwch_qp_attributes attrs;
  633. struct iwch_ucontext *ucontext;
  634. qhp = to_iwch_qp(ib_qp);
  635. rhp = qhp->rhp;
  636. if (qhp->attr.state == IWCH_QP_STATE_RTS) {
  637. attrs.next_state = IWCH_QP_STATE_ERROR;
  638. iwch_modify_qp(rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, &attrs, 0);
  639. }
  640. wait_event(qhp->wait, !qhp->ep);
  641. remove_handle(rhp, &rhp->qpidr, qhp->wq.qpid);
  642. atomic_dec(&qhp->refcnt);
  643. wait_event(qhp->wait, !atomic_read(&qhp->refcnt));
  644. ucontext = ib_qp->uobject ? to_iwch_ucontext(ib_qp->uobject->context)
  645. : NULL;
  646. cxio_destroy_qp(&rhp->rdev, &qhp->wq,
  647. ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
  648. PDBG("%s ib_qp %p qpid 0x%0x qhp %p\n", __FUNCTION__,
  649. ib_qp, qhp->wq.qpid, qhp);
  650. kfree(qhp);
  651. return 0;
  652. }
  653. static struct ib_qp *iwch_create_qp(struct ib_pd *pd,
  654. struct ib_qp_init_attr *attrs,
  655. struct ib_udata *udata)
  656. {
  657. struct iwch_dev *rhp;
  658. struct iwch_qp *qhp;
  659. struct iwch_pd *php;
  660. struct iwch_cq *schp;
  661. struct iwch_cq *rchp;
  662. struct iwch_create_qp_resp uresp;
  663. int wqsize, sqsize, rqsize;
  664. struct iwch_ucontext *ucontext;
  665. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  666. if (attrs->qp_type != IB_QPT_RC)
  667. return ERR_PTR(-EINVAL);
  668. php = to_iwch_pd(pd);
  669. rhp = php->rhp;
  670. schp = get_chp(rhp, ((struct iwch_cq *) attrs->send_cq)->cq.cqid);
  671. rchp = get_chp(rhp, ((struct iwch_cq *) attrs->recv_cq)->cq.cqid);
  672. if (!schp || !rchp)
  673. return ERR_PTR(-EINVAL);
  674. /* The RQT size must be # of entries + 1 rounded up to a power of two */
  675. rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr);
  676. if (rqsize == attrs->cap.max_recv_wr)
  677. rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr+1);
  678. /* T3 doesn't support RQT depth < 16 */
  679. if (rqsize < 16)
  680. rqsize = 16;
  681. if (rqsize > T3_MAX_RQ_SIZE)
  682. return ERR_PTR(-EINVAL);
  683. /*
  684. * NOTE: The SQ and total WQ sizes don't need to be
  685. * a power of two. However, all the code assumes
  686. * they are. EG: Q_FREECNT() and friends.
  687. */
  688. sqsize = roundup_pow_of_two(attrs->cap.max_send_wr);
  689. wqsize = roundup_pow_of_two(rqsize + sqsize);
  690. PDBG("%s wqsize %d sqsize %d rqsize %d\n", __FUNCTION__,
  691. wqsize, sqsize, rqsize);
  692. qhp = kzalloc(sizeof(*qhp), GFP_KERNEL);
  693. if (!qhp)
  694. return ERR_PTR(-ENOMEM);
  695. qhp->wq.size_log2 = ilog2(wqsize);
  696. qhp->wq.rq_size_log2 = ilog2(rqsize);
  697. qhp->wq.sq_size_log2 = ilog2(sqsize);
  698. ucontext = pd->uobject ? to_iwch_ucontext(pd->uobject->context) : NULL;
  699. if (cxio_create_qp(&rhp->rdev, !udata, &qhp->wq,
  700. ucontext ? &ucontext->uctx : &rhp->rdev.uctx)) {
  701. kfree(qhp);
  702. return ERR_PTR(-ENOMEM);
  703. }
  704. attrs->cap.max_recv_wr = rqsize - 1;
  705. attrs->cap.max_send_wr = sqsize;
  706. qhp->rhp = rhp;
  707. qhp->attr.pd = php->pdid;
  708. qhp->attr.scq = ((struct iwch_cq *) attrs->send_cq)->cq.cqid;
  709. qhp->attr.rcq = ((struct iwch_cq *) attrs->recv_cq)->cq.cqid;
  710. qhp->attr.sq_num_entries = attrs->cap.max_send_wr;
  711. qhp->attr.rq_num_entries = attrs->cap.max_recv_wr;
  712. qhp->attr.sq_max_sges = attrs->cap.max_send_sge;
  713. qhp->attr.sq_max_sges_rdma_write = attrs->cap.max_send_sge;
  714. qhp->attr.rq_max_sges = attrs->cap.max_recv_sge;
  715. qhp->attr.state = IWCH_QP_STATE_IDLE;
  716. qhp->attr.next_state = IWCH_QP_STATE_IDLE;
  717. /*
  718. * XXX - These don't get passed in from the openib user
  719. * at create time. The CM sets them via a QP modify.
  720. * Need to fix... I think the CM should
  721. */
  722. qhp->attr.enable_rdma_read = 1;
  723. qhp->attr.enable_rdma_write = 1;
  724. qhp->attr.enable_bind = 1;
  725. qhp->attr.max_ord = 1;
  726. qhp->attr.max_ird = 1;
  727. spin_lock_init(&qhp->lock);
  728. init_waitqueue_head(&qhp->wait);
  729. atomic_set(&qhp->refcnt, 1);
  730. insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.qpid);
  731. if (udata) {
  732. struct iwch_mm_entry *mm1, *mm2;
  733. mm1 = kmalloc(sizeof *mm1, GFP_KERNEL);
  734. if (!mm1) {
  735. iwch_destroy_qp(&qhp->ibqp);
  736. return ERR_PTR(-ENOMEM);
  737. }
  738. mm2 = kmalloc(sizeof *mm2, GFP_KERNEL);
  739. if (!mm2) {
  740. kfree(mm1);
  741. iwch_destroy_qp(&qhp->ibqp);
  742. return ERR_PTR(-ENOMEM);
  743. }
  744. uresp.qpid = qhp->wq.qpid;
  745. uresp.size_log2 = qhp->wq.size_log2;
  746. uresp.sq_size_log2 = qhp->wq.sq_size_log2;
  747. uresp.rq_size_log2 = qhp->wq.rq_size_log2;
  748. spin_lock(&ucontext->mmap_lock);
  749. uresp.key = ucontext->key;
  750. ucontext->key += PAGE_SIZE;
  751. uresp.db_key = ucontext->key;
  752. ucontext->key += PAGE_SIZE;
  753. spin_unlock(&ucontext->mmap_lock);
  754. if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
  755. kfree(mm1);
  756. kfree(mm2);
  757. iwch_destroy_qp(&qhp->ibqp);
  758. return ERR_PTR(-EFAULT);
  759. }
  760. mm1->key = uresp.key;
  761. mm1->addr = virt_to_phys(qhp->wq.queue);
  762. mm1->len = PAGE_ALIGN(wqsize * sizeof (union t3_wr));
  763. insert_mmap(ucontext, mm1);
  764. mm2->key = uresp.db_key;
  765. mm2->addr = qhp->wq.udb & PAGE_MASK;
  766. mm2->len = PAGE_SIZE;
  767. insert_mmap(ucontext, mm2);
  768. }
  769. qhp->ibqp.qp_num = qhp->wq.qpid;
  770. init_timer(&(qhp->timer));
  771. PDBG("%s sq_num_entries %d, rq_num_entries %d "
  772. "qpid 0x%0x qhp %p dma_addr 0x%llx size %d\n",
  773. __FUNCTION__, qhp->attr.sq_num_entries, qhp->attr.rq_num_entries,
  774. qhp->wq.qpid, qhp, (unsigned long long) qhp->wq.dma_addr,
  775. 1 << qhp->wq.size_log2);
  776. return &qhp->ibqp;
  777. }
  778. static int iwch_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  779. int attr_mask, struct ib_udata *udata)
  780. {
  781. struct iwch_dev *rhp;
  782. struct iwch_qp *qhp;
  783. enum iwch_qp_attr_mask mask = 0;
  784. struct iwch_qp_attributes attrs;
  785. PDBG("%s ib_qp %p\n", __FUNCTION__, ibqp);
  786. /* iwarp does not support the RTR state */
  787. if ((attr_mask & IB_QP_STATE) && (attr->qp_state == IB_QPS_RTR))
  788. attr_mask &= ~IB_QP_STATE;
  789. /* Make sure we still have something left to do */
  790. if (!attr_mask)
  791. return 0;
  792. memset(&attrs, 0, sizeof attrs);
  793. qhp = to_iwch_qp(ibqp);
  794. rhp = qhp->rhp;
  795. attrs.next_state = iwch_convert_state(attr->qp_state);
  796. attrs.enable_rdma_read = (attr->qp_access_flags &
  797. IB_ACCESS_REMOTE_READ) ? 1 : 0;
  798. attrs.enable_rdma_write = (attr->qp_access_flags &
  799. IB_ACCESS_REMOTE_WRITE) ? 1 : 0;
  800. attrs.enable_bind = (attr->qp_access_flags & IB_ACCESS_MW_BIND) ? 1 : 0;
  801. mask |= (attr_mask & IB_QP_STATE) ? IWCH_QP_ATTR_NEXT_STATE : 0;
  802. mask |= (attr_mask & IB_QP_ACCESS_FLAGS) ?
  803. (IWCH_QP_ATTR_ENABLE_RDMA_READ |
  804. IWCH_QP_ATTR_ENABLE_RDMA_WRITE |
  805. IWCH_QP_ATTR_ENABLE_RDMA_BIND) : 0;
  806. return iwch_modify_qp(rhp, qhp, mask, &attrs, 0);
  807. }
  808. void iwch_qp_add_ref(struct ib_qp *qp)
  809. {
  810. PDBG("%s ib_qp %p\n", __FUNCTION__, qp);
  811. atomic_inc(&(to_iwch_qp(qp)->refcnt));
  812. }
  813. void iwch_qp_rem_ref(struct ib_qp *qp)
  814. {
  815. PDBG("%s ib_qp %p\n", __FUNCTION__, qp);
  816. if (atomic_dec_and_test(&(to_iwch_qp(qp)->refcnt)))
  817. wake_up(&(to_iwch_qp(qp)->wait));
  818. }
  819. static struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn)
  820. {
  821. PDBG("%s ib_dev %p qpn 0x%x\n", __FUNCTION__, dev, qpn);
  822. return (struct ib_qp *)get_qhp(to_iwch_dev(dev), qpn);
  823. }
  824. static int iwch_query_pkey(struct ib_device *ibdev,
  825. u8 port, u16 index, u16 * pkey)
  826. {
  827. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  828. *pkey = 0;
  829. return 0;
  830. }
  831. static int iwch_query_gid(struct ib_device *ibdev, u8 port,
  832. int index, union ib_gid *gid)
  833. {
  834. struct iwch_dev *dev;
  835. PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
  836. __FUNCTION__, ibdev, port, index, gid);
  837. dev = to_iwch_dev(ibdev);
  838. BUG_ON(port == 0 || port > 2);
  839. memset(&(gid->raw[0]), 0, sizeof(gid->raw));
  840. memcpy(&(gid->raw[0]), dev->rdev.port_info.lldevs[port-1]->dev_addr, 6);
  841. return 0;
  842. }
  843. static int iwch_query_device(struct ib_device *ibdev,
  844. struct ib_device_attr *props)
  845. {
  846. struct iwch_dev *dev;
  847. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  848. dev = to_iwch_dev(ibdev);
  849. memset(props, 0, sizeof *props);
  850. memcpy(&props->sys_image_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
  851. props->device_cap_flags = dev->device_cap_flags;
  852. props->vendor_id = (u32)dev->rdev.rnic_info.pdev->vendor;
  853. props->vendor_part_id = (u32)dev->rdev.rnic_info.pdev->device;
  854. props->max_mr_size = ~0ull;
  855. props->max_qp = dev->attr.max_qps;
  856. props->max_qp_wr = dev->attr.max_wrs;
  857. props->max_sge = dev->attr.max_sge_per_wr;
  858. props->max_sge_rd = 1;
  859. props->max_qp_rd_atom = dev->attr.max_rdma_reads_per_qp;
  860. props->max_cq = dev->attr.max_cqs;
  861. props->max_cqe = dev->attr.max_cqes_per_cq;
  862. props->max_mr = dev->attr.max_mem_regs;
  863. props->max_pd = dev->attr.max_pds;
  864. props->local_ca_ack_delay = 0;
  865. return 0;
  866. }
  867. static int iwch_query_port(struct ib_device *ibdev,
  868. u8 port, struct ib_port_attr *props)
  869. {
  870. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  871. props->max_mtu = IB_MTU_4096;
  872. props->lid = 0;
  873. props->lmc = 0;
  874. props->sm_lid = 0;
  875. props->sm_sl = 0;
  876. props->state = IB_PORT_ACTIVE;
  877. props->phys_state = 0;
  878. props->port_cap_flags =
  879. IB_PORT_CM_SUP |
  880. IB_PORT_SNMP_TUNNEL_SUP |
  881. IB_PORT_REINIT_SUP |
  882. IB_PORT_DEVICE_MGMT_SUP |
  883. IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
  884. props->gid_tbl_len = 1;
  885. props->pkey_tbl_len = 1;
  886. props->qkey_viol_cntr = 0;
  887. props->active_width = 2;
  888. props->active_speed = 2;
  889. props->max_msg_sz = -1;
  890. return 0;
  891. }
  892. static ssize_t show_rev(struct class_device *cdev, char *buf)
  893. {
  894. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  895. ibdev.class_dev);
  896. PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
  897. return sprintf(buf, "%d\n", dev->rdev.t3cdev_p->type);
  898. }
  899. static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
  900. {
  901. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  902. ibdev.class_dev);
  903. struct ethtool_drvinfo info;
  904. struct net_device *lldev = dev->rdev.t3cdev_p->lldev;
  905. PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
  906. lldev->ethtool_ops->get_drvinfo(lldev, &info);
  907. return sprintf(buf, "%s\n", info.fw_version);
  908. }
  909. static ssize_t show_hca(struct class_device *cdev, char *buf)
  910. {
  911. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  912. ibdev.class_dev);
  913. struct ethtool_drvinfo info;
  914. struct net_device *lldev = dev->rdev.t3cdev_p->lldev;
  915. PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
  916. lldev->ethtool_ops->get_drvinfo(lldev, &info);
  917. return sprintf(buf, "%s\n", info.driver);
  918. }
  919. static ssize_t show_board(struct class_device *cdev, char *buf)
  920. {
  921. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  922. ibdev.class_dev);
  923. PDBG("%s class dev 0x%p\n", __FUNCTION__, dev);
  924. return sprintf(buf, "%x.%x\n", dev->rdev.rnic_info.pdev->vendor,
  925. dev->rdev.rnic_info.pdev->device);
  926. }
  927. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  928. static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
  929. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  930. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
  931. static struct class_device_attribute *iwch_class_attributes[] = {
  932. &class_device_attr_hw_rev,
  933. &class_device_attr_fw_ver,
  934. &class_device_attr_hca_type,
  935. &class_device_attr_board_id
  936. };
  937. int iwch_register_device(struct iwch_dev *dev)
  938. {
  939. int ret;
  940. int i;
  941. PDBG("%s iwch_dev %p\n", __FUNCTION__, dev);
  942. strlcpy(dev->ibdev.name, "cxgb3_%d", IB_DEVICE_NAME_MAX);
  943. memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
  944. memcpy(&dev->ibdev.node_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
  945. dev->ibdev.owner = THIS_MODULE;
  946. dev->device_cap_flags =
  947. (IB_DEVICE_ZERO_STAG |
  948. IB_DEVICE_SEND_W_INV | IB_DEVICE_MEM_WINDOW);
  949. dev->ibdev.uverbs_cmd_mask =
  950. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  951. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  952. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  953. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  954. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  955. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  956. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  957. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  958. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  959. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  960. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  961. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  962. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  963. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  964. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  965. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  966. (1ull << IB_USER_VERBS_CMD_POST_RECV);
  967. dev->ibdev.node_type = RDMA_NODE_RNIC;
  968. memcpy(dev->ibdev.node_desc, IWCH_NODE_DESC, sizeof(IWCH_NODE_DESC));
  969. dev->ibdev.phys_port_cnt = dev->rdev.port_info.nports;
  970. dev->ibdev.dma_device = &(dev->rdev.rnic_info.pdev->dev);
  971. dev->ibdev.class_dev.dev = &(dev->rdev.rnic_info.pdev->dev);
  972. dev->ibdev.query_device = iwch_query_device;
  973. dev->ibdev.query_port = iwch_query_port;
  974. dev->ibdev.modify_port = iwch_modify_port;
  975. dev->ibdev.query_pkey = iwch_query_pkey;
  976. dev->ibdev.query_gid = iwch_query_gid;
  977. dev->ibdev.alloc_ucontext = iwch_alloc_ucontext;
  978. dev->ibdev.dealloc_ucontext = iwch_dealloc_ucontext;
  979. dev->ibdev.mmap = iwch_mmap;
  980. dev->ibdev.alloc_pd = iwch_allocate_pd;
  981. dev->ibdev.dealloc_pd = iwch_deallocate_pd;
  982. dev->ibdev.create_ah = iwch_ah_create;
  983. dev->ibdev.destroy_ah = iwch_ah_destroy;
  984. dev->ibdev.create_qp = iwch_create_qp;
  985. dev->ibdev.modify_qp = iwch_ib_modify_qp;
  986. dev->ibdev.destroy_qp = iwch_destroy_qp;
  987. dev->ibdev.create_cq = iwch_create_cq;
  988. dev->ibdev.destroy_cq = iwch_destroy_cq;
  989. dev->ibdev.resize_cq = iwch_resize_cq;
  990. dev->ibdev.poll_cq = iwch_poll_cq;
  991. dev->ibdev.get_dma_mr = iwch_get_dma_mr;
  992. dev->ibdev.reg_phys_mr = iwch_register_phys_mem;
  993. dev->ibdev.rereg_phys_mr = iwch_reregister_phys_mem;
  994. dev->ibdev.reg_user_mr = iwch_reg_user_mr;
  995. dev->ibdev.dereg_mr = iwch_dereg_mr;
  996. dev->ibdev.alloc_mw = iwch_alloc_mw;
  997. dev->ibdev.bind_mw = iwch_bind_mw;
  998. dev->ibdev.dealloc_mw = iwch_dealloc_mw;
  999. dev->ibdev.attach_mcast = iwch_multicast_attach;
  1000. dev->ibdev.detach_mcast = iwch_multicast_detach;
  1001. dev->ibdev.process_mad = iwch_process_mad;
  1002. dev->ibdev.req_notify_cq = iwch_arm_cq;
  1003. dev->ibdev.post_send = iwch_post_send;
  1004. dev->ibdev.post_recv = iwch_post_receive;
  1005. dev->ibdev.iwcm =
  1006. (struct iw_cm_verbs *) kmalloc(sizeof(struct iw_cm_verbs),
  1007. GFP_KERNEL);
  1008. dev->ibdev.iwcm->connect = iwch_connect;
  1009. dev->ibdev.iwcm->accept = iwch_accept_cr;
  1010. dev->ibdev.iwcm->reject = iwch_reject_cr;
  1011. dev->ibdev.iwcm->create_listen = iwch_create_listen;
  1012. dev->ibdev.iwcm->destroy_listen = iwch_destroy_listen;
  1013. dev->ibdev.iwcm->add_ref = iwch_qp_add_ref;
  1014. dev->ibdev.iwcm->rem_ref = iwch_qp_rem_ref;
  1015. dev->ibdev.iwcm->get_qp = iwch_get_qp;
  1016. ret = ib_register_device(&dev->ibdev);
  1017. if (ret)
  1018. goto bail1;
  1019. for (i = 0; i < ARRAY_SIZE(iwch_class_attributes); ++i) {
  1020. ret = class_device_create_file(&dev->ibdev.class_dev,
  1021. iwch_class_attributes[i]);
  1022. if (ret) {
  1023. goto bail2;
  1024. }
  1025. }
  1026. return 0;
  1027. bail2:
  1028. ib_unregister_device(&dev->ibdev);
  1029. bail1:
  1030. return ret;
  1031. }
  1032. void iwch_unregister_device(struct iwch_dev *dev)
  1033. {
  1034. int i;
  1035. PDBG("%s iwch_dev %p\n", __FUNCTION__, dev);
  1036. for (i = 0; i < ARRAY_SIZE(iwch_class_attributes); ++i)
  1037. class_device_remove_file(&dev->ibdev.class_dev,
  1038. iwch_class_attributes[i]);
  1039. ib_unregister_device(&dev->ibdev);
  1040. return;
  1041. }