iwch_provider.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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, int vector,
  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_flags flags)
  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 ((flags & IB_CQ_SOLICITED_MASK) == 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 < 0)
  281. printk(KERN_ERR MOD "Error %d rearming CQID 0x%x\n", err,
  282. chp->cq.cqid);
  283. if (err > 0 && !(flags & IB_CQ_REPORT_MISSED_EVENTS))
  284. err = 0;
  285. return err;
  286. }
  287. static int iwch_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
  288. {
  289. int len = vma->vm_end - vma->vm_start;
  290. u32 key = vma->vm_pgoff << PAGE_SHIFT;
  291. struct cxio_rdev *rdev_p;
  292. int ret = 0;
  293. struct iwch_mm_entry *mm;
  294. struct iwch_ucontext *ucontext;
  295. u64 addr;
  296. PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __FUNCTION__, vma->vm_pgoff,
  297. key, len);
  298. if (vma->vm_start & (PAGE_SIZE-1)) {
  299. return -EINVAL;
  300. }
  301. rdev_p = &(to_iwch_dev(context->device)->rdev);
  302. ucontext = to_iwch_ucontext(context);
  303. mm = remove_mmap(ucontext, key, len);
  304. if (!mm)
  305. return -EINVAL;
  306. addr = mm->addr;
  307. kfree(mm);
  308. if ((addr >= rdev_p->rnic_info.udbell_physbase) &&
  309. (addr < (rdev_p->rnic_info.udbell_physbase +
  310. rdev_p->rnic_info.udbell_len))) {
  311. /*
  312. * Map T3 DB register.
  313. */
  314. if (vma->vm_flags & VM_READ) {
  315. return -EPERM;
  316. }
  317. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  318. vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
  319. vma->vm_flags &= ~VM_MAYREAD;
  320. ret = io_remap_pfn_range(vma, vma->vm_start,
  321. addr >> PAGE_SHIFT,
  322. len, vma->vm_page_prot);
  323. } else {
  324. /*
  325. * Map WQ or CQ contig dma memory...
  326. */
  327. ret = remap_pfn_range(vma, vma->vm_start,
  328. addr >> PAGE_SHIFT,
  329. len, vma->vm_page_prot);
  330. }
  331. return ret;
  332. }
  333. static int iwch_deallocate_pd(struct ib_pd *pd)
  334. {
  335. struct iwch_dev *rhp;
  336. struct iwch_pd *php;
  337. php = to_iwch_pd(pd);
  338. rhp = php->rhp;
  339. PDBG("%s ibpd %p pdid 0x%x\n", __FUNCTION__, pd, php->pdid);
  340. cxio_hal_put_pdid(rhp->rdev.rscp, php->pdid);
  341. kfree(php);
  342. return 0;
  343. }
  344. static struct ib_pd *iwch_allocate_pd(struct ib_device *ibdev,
  345. struct ib_ucontext *context,
  346. struct ib_udata *udata)
  347. {
  348. struct iwch_pd *php;
  349. u32 pdid;
  350. struct iwch_dev *rhp;
  351. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  352. rhp = (struct iwch_dev *) ibdev;
  353. pdid = cxio_hal_get_pdid(rhp->rdev.rscp);
  354. if (!pdid)
  355. return ERR_PTR(-EINVAL);
  356. php = kzalloc(sizeof(*php), GFP_KERNEL);
  357. if (!php) {
  358. cxio_hal_put_pdid(rhp->rdev.rscp, pdid);
  359. return ERR_PTR(-ENOMEM);
  360. }
  361. php->pdid = pdid;
  362. php->rhp = rhp;
  363. if (context) {
  364. if (ib_copy_to_udata(udata, &php->pdid, sizeof (__u32))) {
  365. iwch_deallocate_pd(&php->ibpd);
  366. return ERR_PTR(-EFAULT);
  367. }
  368. }
  369. PDBG("%s pdid 0x%0x ptr 0x%p\n", __FUNCTION__, pdid, php);
  370. return &php->ibpd;
  371. }
  372. static int iwch_dereg_mr(struct ib_mr *ib_mr)
  373. {
  374. struct iwch_dev *rhp;
  375. struct iwch_mr *mhp;
  376. u32 mmid;
  377. PDBG("%s ib_mr %p\n", __FUNCTION__, ib_mr);
  378. /* There can be no memory windows */
  379. if (atomic_read(&ib_mr->usecnt))
  380. return -EINVAL;
  381. mhp = to_iwch_mr(ib_mr);
  382. rhp = mhp->rhp;
  383. mmid = mhp->attr.stag >> 8;
  384. cxio_dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
  385. mhp->attr.pbl_addr);
  386. remove_handle(rhp, &rhp->mmidr, mmid);
  387. if (mhp->kva)
  388. kfree((void *) (unsigned long) mhp->kva);
  389. PDBG("%s mmid 0x%x ptr %p\n", __FUNCTION__, mmid, mhp);
  390. kfree(mhp);
  391. return 0;
  392. }
  393. static struct ib_mr *iwch_register_phys_mem(struct ib_pd *pd,
  394. struct ib_phys_buf *buffer_list,
  395. int num_phys_buf,
  396. int acc,
  397. u64 *iova_start)
  398. {
  399. __be64 *page_list;
  400. int shift;
  401. u64 total_size;
  402. int npages;
  403. struct iwch_dev *rhp;
  404. struct iwch_pd *php;
  405. struct iwch_mr *mhp;
  406. int ret;
  407. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  408. php = to_iwch_pd(pd);
  409. rhp = php->rhp;
  410. mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
  411. if (!mhp)
  412. return ERR_PTR(-ENOMEM);
  413. /* First check that we have enough alignment */
  414. if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK)) {
  415. ret = -EINVAL;
  416. goto err;
  417. }
  418. if (num_phys_buf > 1 &&
  419. ((buffer_list[0].addr + buffer_list[0].size) & ~PAGE_MASK)) {
  420. ret = -EINVAL;
  421. goto err;
  422. }
  423. ret = build_phys_page_list(buffer_list, num_phys_buf, iova_start,
  424. &total_size, &npages, &shift, &page_list);
  425. if (ret)
  426. goto err;
  427. mhp->rhp = rhp;
  428. mhp->attr.pdid = php->pdid;
  429. mhp->attr.zbva = 0;
  430. mhp->attr.perms = iwch_ib_to_tpt_access(acc);
  431. mhp->attr.va_fbo = *iova_start;
  432. mhp->attr.page_size = shift - 12;
  433. mhp->attr.len = (u32) total_size;
  434. mhp->attr.pbl_size = npages;
  435. ret = iwch_register_mem(rhp, php, mhp, shift, page_list);
  436. kfree(page_list);
  437. if (ret) {
  438. goto err;
  439. }
  440. return &mhp->ibmr;
  441. err:
  442. kfree(mhp);
  443. return ERR_PTR(ret);
  444. }
  445. static int iwch_reregister_phys_mem(struct ib_mr *mr,
  446. int mr_rereg_mask,
  447. struct ib_pd *pd,
  448. struct ib_phys_buf *buffer_list,
  449. int num_phys_buf,
  450. int acc, u64 * iova_start)
  451. {
  452. struct iwch_mr mh, *mhp;
  453. struct iwch_pd *php;
  454. struct iwch_dev *rhp;
  455. __be64 *page_list = NULL;
  456. int shift = 0;
  457. u64 total_size;
  458. int npages;
  459. int ret;
  460. PDBG("%s ib_mr %p ib_pd %p\n", __FUNCTION__, mr, pd);
  461. /* There can be no memory windows */
  462. if (atomic_read(&mr->usecnt))
  463. return -EINVAL;
  464. mhp = to_iwch_mr(mr);
  465. rhp = mhp->rhp;
  466. php = to_iwch_pd(mr->pd);
  467. /* make sure we are on the same adapter */
  468. if (rhp != php->rhp)
  469. return -EINVAL;
  470. memcpy(&mh, mhp, sizeof *mhp);
  471. if (mr_rereg_mask & IB_MR_REREG_PD)
  472. php = to_iwch_pd(pd);
  473. if (mr_rereg_mask & IB_MR_REREG_ACCESS)
  474. mh.attr.perms = iwch_ib_to_tpt_access(acc);
  475. if (mr_rereg_mask & IB_MR_REREG_TRANS) {
  476. ret = build_phys_page_list(buffer_list, num_phys_buf,
  477. iova_start,
  478. &total_size, &npages,
  479. &shift, &page_list);
  480. if (ret)
  481. return ret;
  482. }
  483. ret = iwch_reregister_mem(rhp, php, &mh, shift, page_list, npages);
  484. kfree(page_list);
  485. if (ret) {
  486. return ret;
  487. }
  488. if (mr_rereg_mask & IB_MR_REREG_PD)
  489. mhp->attr.pdid = php->pdid;
  490. if (mr_rereg_mask & IB_MR_REREG_ACCESS)
  491. mhp->attr.perms = iwch_ib_to_tpt_access(acc);
  492. if (mr_rereg_mask & IB_MR_REREG_TRANS) {
  493. mhp->attr.zbva = 0;
  494. mhp->attr.va_fbo = *iova_start;
  495. mhp->attr.page_size = shift - 12;
  496. mhp->attr.len = (u32) total_size;
  497. mhp->attr.pbl_size = npages;
  498. }
  499. return 0;
  500. }
  501. static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
  502. int acc, struct ib_udata *udata)
  503. {
  504. __be64 *pages;
  505. int shift, n, len;
  506. int i, j, k;
  507. int err = 0;
  508. struct ib_umem_chunk *chunk;
  509. struct iwch_dev *rhp;
  510. struct iwch_pd *php;
  511. struct iwch_mr *mhp;
  512. struct iwch_reg_user_mr_resp uresp;
  513. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  514. shift = ffs(region->page_size) - 1;
  515. php = to_iwch_pd(pd);
  516. rhp = php->rhp;
  517. mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
  518. if (!mhp)
  519. return ERR_PTR(-ENOMEM);
  520. n = 0;
  521. list_for_each_entry(chunk, &region->chunk_list, list)
  522. n += chunk->nents;
  523. pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
  524. if (!pages) {
  525. err = -ENOMEM;
  526. goto err;
  527. }
  528. i = n = 0;
  529. list_for_each_entry(chunk, &region->chunk_list, list)
  530. for (j = 0; j < chunk->nmap; ++j) {
  531. len = sg_dma_len(&chunk->page_list[j]) >> shift;
  532. for (k = 0; k < len; ++k) {
  533. pages[i++] = cpu_to_be64(sg_dma_address(
  534. &chunk->page_list[j]) +
  535. region->page_size * k);
  536. }
  537. }
  538. mhp->rhp = rhp;
  539. mhp->attr.pdid = php->pdid;
  540. mhp->attr.zbva = 0;
  541. mhp->attr.perms = iwch_ib_to_tpt_access(acc);
  542. mhp->attr.va_fbo = region->virt_base;
  543. mhp->attr.page_size = shift - 12;
  544. mhp->attr.len = (u32) region->length;
  545. mhp->attr.pbl_size = i;
  546. err = iwch_register_mem(rhp, php, mhp, shift, pages);
  547. kfree(pages);
  548. if (err)
  549. goto err;
  550. if (udata && t3b_device(rhp)) {
  551. uresp.pbl_addr = (mhp->attr.pbl_addr -
  552. rhp->rdev.rnic_info.pbl_base) >> 3;
  553. PDBG("%s user resp pbl_addr 0x%x\n", __FUNCTION__,
  554. uresp.pbl_addr);
  555. if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
  556. iwch_dereg_mr(&mhp->ibmr);
  557. err = -EFAULT;
  558. goto err;
  559. }
  560. }
  561. return &mhp->ibmr;
  562. err:
  563. kfree(mhp);
  564. return ERR_PTR(err);
  565. }
  566. static struct ib_mr *iwch_get_dma_mr(struct ib_pd *pd, int acc)
  567. {
  568. struct ib_phys_buf bl;
  569. u64 kva;
  570. struct ib_mr *ibmr;
  571. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  572. /*
  573. * T3 only supports 32 bits of size.
  574. */
  575. bl.size = 0xffffffff;
  576. bl.addr = 0;
  577. kva = 0;
  578. ibmr = iwch_register_phys_mem(pd, &bl, 1, acc, &kva);
  579. return ibmr;
  580. }
  581. static struct ib_mw *iwch_alloc_mw(struct ib_pd *pd)
  582. {
  583. struct iwch_dev *rhp;
  584. struct iwch_pd *php;
  585. struct iwch_mw *mhp;
  586. u32 mmid;
  587. u32 stag = 0;
  588. int ret;
  589. php = to_iwch_pd(pd);
  590. rhp = php->rhp;
  591. mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
  592. if (!mhp)
  593. return ERR_PTR(-ENOMEM);
  594. ret = cxio_allocate_window(&rhp->rdev, &stag, php->pdid);
  595. if (ret) {
  596. kfree(mhp);
  597. return ERR_PTR(ret);
  598. }
  599. mhp->rhp = rhp;
  600. mhp->attr.pdid = php->pdid;
  601. mhp->attr.type = TPT_MW;
  602. mhp->attr.stag = stag;
  603. mmid = (stag) >> 8;
  604. insert_handle(rhp, &rhp->mmidr, mhp, mmid);
  605. PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __FUNCTION__, mmid, mhp, stag);
  606. return &(mhp->ibmw);
  607. }
  608. static int iwch_dealloc_mw(struct ib_mw *mw)
  609. {
  610. struct iwch_dev *rhp;
  611. struct iwch_mw *mhp;
  612. u32 mmid;
  613. mhp = to_iwch_mw(mw);
  614. rhp = mhp->rhp;
  615. mmid = (mw->rkey) >> 8;
  616. cxio_deallocate_window(&rhp->rdev, mhp->attr.stag);
  617. remove_handle(rhp, &rhp->mmidr, mmid);
  618. kfree(mhp);
  619. PDBG("%s ib_mw %p mmid 0x%x ptr %p\n", __FUNCTION__, mw, mmid, mhp);
  620. return 0;
  621. }
  622. static int iwch_destroy_qp(struct ib_qp *ib_qp)
  623. {
  624. struct iwch_dev *rhp;
  625. struct iwch_qp *qhp;
  626. struct iwch_qp_attributes attrs;
  627. struct iwch_ucontext *ucontext;
  628. qhp = to_iwch_qp(ib_qp);
  629. rhp = qhp->rhp;
  630. attrs.next_state = IWCH_QP_STATE_ERROR;
  631. iwch_modify_qp(rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, &attrs, 0);
  632. wait_event(qhp->wait, !qhp->ep);
  633. remove_handle(rhp, &rhp->qpidr, qhp->wq.qpid);
  634. atomic_dec(&qhp->refcnt);
  635. wait_event(qhp->wait, !atomic_read(&qhp->refcnt));
  636. ucontext = ib_qp->uobject ? to_iwch_ucontext(ib_qp->uobject->context)
  637. : NULL;
  638. cxio_destroy_qp(&rhp->rdev, &qhp->wq,
  639. ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
  640. PDBG("%s ib_qp %p qpid 0x%0x qhp %p\n", __FUNCTION__,
  641. ib_qp, qhp->wq.qpid, qhp);
  642. kfree(qhp);
  643. return 0;
  644. }
  645. static struct ib_qp *iwch_create_qp(struct ib_pd *pd,
  646. struct ib_qp_init_attr *attrs,
  647. struct ib_udata *udata)
  648. {
  649. struct iwch_dev *rhp;
  650. struct iwch_qp *qhp;
  651. struct iwch_pd *php;
  652. struct iwch_cq *schp;
  653. struct iwch_cq *rchp;
  654. struct iwch_create_qp_resp uresp;
  655. int wqsize, sqsize, rqsize;
  656. struct iwch_ucontext *ucontext;
  657. PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
  658. if (attrs->qp_type != IB_QPT_RC)
  659. return ERR_PTR(-EINVAL);
  660. php = to_iwch_pd(pd);
  661. rhp = php->rhp;
  662. schp = get_chp(rhp, ((struct iwch_cq *) attrs->send_cq)->cq.cqid);
  663. rchp = get_chp(rhp, ((struct iwch_cq *) attrs->recv_cq)->cq.cqid);
  664. if (!schp || !rchp)
  665. return ERR_PTR(-EINVAL);
  666. /* The RQT size must be # of entries + 1 rounded up to a power of two */
  667. rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr);
  668. if (rqsize == attrs->cap.max_recv_wr)
  669. rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr+1);
  670. /* T3 doesn't support RQT depth < 16 */
  671. if (rqsize < 16)
  672. rqsize = 16;
  673. if (rqsize > T3_MAX_RQ_SIZE)
  674. return ERR_PTR(-EINVAL);
  675. if (attrs->cap.max_inline_data > T3_MAX_INLINE)
  676. return ERR_PTR(-EINVAL);
  677. /*
  678. * NOTE: The SQ and total WQ sizes don't need to be
  679. * a power of two. However, all the code assumes
  680. * they are. EG: Q_FREECNT() and friends.
  681. */
  682. sqsize = roundup_pow_of_two(attrs->cap.max_send_wr);
  683. wqsize = roundup_pow_of_two(rqsize + sqsize);
  684. PDBG("%s wqsize %d sqsize %d rqsize %d\n", __FUNCTION__,
  685. wqsize, sqsize, rqsize);
  686. qhp = kzalloc(sizeof(*qhp), GFP_KERNEL);
  687. if (!qhp)
  688. return ERR_PTR(-ENOMEM);
  689. qhp->wq.size_log2 = ilog2(wqsize);
  690. qhp->wq.rq_size_log2 = ilog2(rqsize);
  691. qhp->wq.sq_size_log2 = ilog2(sqsize);
  692. ucontext = pd->uobject ? to_iwch_ucontext(pd->uobject->context) : NULL;
  693. if (cxio_create_qp(&rhp->rdev, !udata, &qhp->wq,
  694. ucontext ? &ucontext->uctx : &rhp->rdev.uctx)) {
  695. kfree(qhp);
  696. return ERR_PTR(-ENOMEM);
  697. }
  698. attrs->cap.max_recv_wr = rqsize - 1;
  699. attrs->cap.max_send_wr = sqsize;
  700. qhp->rhp = rhp;
  701. qhp->attr.pd = php->pdid;
  702. qhp->attr.scq = ((struct iwch_cq *) attrs->send_cq)->cq.cqid;
  703. qhp->attr.rcq = ((struct iwch_cq *) attrs->recv_cq)->cq.cqid;
  704. qhp->attr.sq_num_entries = attrs->cap.max_send_wr;
  705. qhp->attr.rq_num_entries = attrs->cap.max_recv_wr;
  706. qhp->attr.sq_max_sges = attrs->cap.max_send_sge;
  707. qhp->attr.sq_max_sges_rdma_write = attrs->cap.max_send_sge;
  708. qhp->attr.rq_max_sges = attrs->cap.max_recv_sge;
  709. qhp->attr.state = IWCH_QP_STATE_IDLE;
  710. qhp->attr.next_state = IWCH_QP_STATE_IDLE;
  711. /*
  712. * XXX - These don't get passed in from the openib user
  713. * at create time. The CM sets them via a QP modify.
  714. * Need to fix... I think the CM should
  715. */
  716. qhp->attr.enable_rdma_read = 1;
  717. qhp->attr.enable_rdma_write = 1;
  718. qhp->attr.enable_bind = 1;
  719. qhp->attr.max_ord = 1;
  720. qhp->attr.max_ird = 1;
  721. spin_lock_init(&qhp->lock);
  722. init_waitqueue_head(&qhp->wait);
  723. atomic_set(&qhp->refcnt, 1);
  724. insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.qpid);
  725. if (udata) {
  726. struct iwch_mm_entry *mm1, *mm2;
  727. mm1 = kmalloc(sizeof *mm1, GFP_KERNEL);
  728. if (!mm1) {
  729. iwch_destroy_qp(&qhp->ibqp);
  730. return ERR_PTR(-ENOMEM);
  731. }
  732. mm2 = kmalloc(sizeof *mm2, GFP_KERNEL);
  733. if (!mm2) {
  734. kfree(mm1);
  735. iwch_destroy_qp(&qhp->ibqp);
  736. return ERR_PTR(-ENOMEM);
  737. }
  738. uresp.qpid = qhp->wq.qpid;
  739. uresp.size_log2 = qhp->wq.size_log2;
  740. uresp.sq_size_log2 = qhp->wq.sq_size_log2;
  741. uresp.rq_size_log2 = qhp->wq.rq_size_log2;
  742. spin_lock(&ucontext->mmap_lock);
  743. uresp.key = ucontext->key;
  744. ucontext->key += PAGE_SIZE;
  745. uresp.db_key = ucontext->key;
  746. ucontext->key += PAGE_SIZE;
  747. spin_unlock(&ucontext->mmap_lock);
  748. if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) {
  749. kfree(mm1);
  750. kfree(mm2);
  751. iwch_destroy_qp(&qhp->ibqp);
  752. return ERR_PTR(-EFAULT);
  753. }
  754. mm1->key = uresp.key;
  755. mm1->addr = virt_to_phys(qhp->wq.queue);
  756. mm1->len = PAGE_ALIGN(wqsize * sizeof (union t3_wr));
  757. insert_mmap(ucontext, mm1);
  758. mm2->key = uresp.db_key;
  759. mm2->addr = qhp->wq.udb & PAGE_MASK;
  760. mm2->len = PAGE_SIZE;
  761. insert_mmap(ucontext, mm2);
  762. }
  763. qhp->ibqp.qp_num = qhp->wq.qpid;
  764. init_timer(&(qhp->timer));
  765. PDBG("%s sq_num_entries %d, rq_num_entries %d "
  766. "qpid 0x%0x qhp %p dma_addr 0x%llx size %d\n",
  767. __FUNCTION__, qhp->attr.sq_num_entries, qhp->attr.rq_num_entries,
  768. qhp->wq.qpid, qhp, (unsigned long long) qhp->wq.dma_addr,
  769. 1 << qhp->wq.size_log2);
  770. return &qhp->ibqp;
  771. }
  772. static int iwch_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  773. int attr_mask, struct ib_udata *udata)
  774. {
  775. struct iwch_dev *rhp;
  776. struct iwch_qp *qhp;
  777. enum iwch_qp_attr_mask mask = 0;
  778. struct iwch_qp_attributes attrs;
  779. PDBG("%s ib_qp %p\n", __FUNCTION__, ibqp);
  780. /* iwarp does not support the RTR state */
  781. if ((attr_mask & IB_QP_STATE) && (attr->qp_state == IB_QPS_RTR))
  782. attr_mask &= ~IB_QP_STATE;
  783. /* Make sure we still have something left to do */
  784. if (!attr_mask)
  785. return 0;
  786. memset(&attrs, 0, sizeof attrs);
  787. qhp = to_iwch_qp(ibqp);
  788. rhp = qhp->rhp;
  789. attrs.next_state = iwch_convert_state(attr->qp_state);
  790. attrs.enable_rdma_read = (attr->qp_access_flags &
  791. IB_ACCESS_REMOTE_READ) ? 1 : 0;
  792. attrs.enable_rdma_write = (attr->qp_access_flags &
  793. IB_ACCESS_REMOTE_WRITE) ? 1 : 0;
  794. attrs.enable_bind = (attr->qp_access_flags & IB_ACCESS_MW_BIND) ? 1 : 0;
  795. mask |= (attr_mask & IB_QP_STATE) ? IWCH_QP_ATTR_NEXT_STATE : 0;
  796. mask |= (attr_mask & IB_QP_ACCESS_FLAGS) ?
  797. (IWCH_QP_ATTR_ENABLE_RDMA_READ |
  798. IWCH_QP_ATTR_ENABLE_RDMA_WRITE |
  799. IWCH_QP_ATTR_ENABLE_RDMA_BIND) : 0;
  800. return iwch_modify_qp(rhp, qhp, mask, &attrs, 0);
  801. }
  802. void iwch_qp_add_ref(struct ib_qp *qp)
  803. {
  804. PDBG("%s ib_qp %p\n", __FUNCTION__, qp);
  805. atomic_inc(&(to_iwch_qp(qp)->refcnt));
  806. }
  807. void iwch_qp_rem_ref(struct ib_qp *qp)
  808. {
  809. PDBG("%s ib_qp %p\n", __FUNCTION__, qp);
  810. if (atomic_dec_and_test(&(to_iwch_qp(qp)->refcnt)))
  811. wake_up(&(to_iwch_qp(qp)->wait));
  812. }
  813. static struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn)
  814. {
  815. PDBG("%s ib_dev %p qpn 0x%x\n", __FUNCTION__, dev, qpn);
  816. return (struct ib_qp *)get_qhp(to_iwch_dev(dev), qpn);
  817. }
  818. static int iwch_query_pkey(struct ib_device *ibdev,
  819. u8 port, u16 index, u16 * pkey)
  820. {
  821. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  822. *pkey = 0;
  823. return 0;
  824. }
  825. static int iwch_query_gid(struct ib_device *ibdev, u8 port,
  826. int index, union ib_gid *gid)
  827. {
  828. struct iwch_dev *dev;
  829. PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
  830. __FUNCTION__, ibdev, port, index, gid);
  831. dev = to_iwch_dev(ibdev);
  832. BUG_ON(port == 0 || port > 2);
  833. memset(&(gid->raw[0]), 0, sizeof(gid->raw));
  834. memcpy(&(gid->raw[0]), dev->rdev.port_info.lldevs[port-1]->dev_addr, 6);
  835. return 0;
  836. }
  837. static int iwch_query_device(struct ib_device *ibdev,
  838. struct ib_device_attr *props)
  839. {
  840. struct iwch_dev *dev;
  841. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  842. dev = to_iwch_dev(ibdev);
  843. memset(props, 0, sizeof *props);
  844. memcpy(&props->sys_image_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
  845. props->device_cap_flags = dev->device_cap_flags;
  846. props->vendor_id = (u32)dev->rdev.rnic_info.pdev->vendor;
  847. props->vendor_part_id = (u32)dev->rdev.rnic_info.pdev->device;
  848. props->max_mr_size = ~0ull;
  849. props->max_qp = dev->attr.max_qps;
  850. props->max_qp_wr = dev->attr.max_wrs;
  851. props->max_sge = dev->attr.max_sge_per_wr;
  852. props->max_sge_rd = 1;
  853. props->max_qp_rd_atom = dev->attr.max_rdma_reads_per_qp;
  854. props->max_cq = dev->attr.max_cqs;
  855. props->max_cqe = dev->attr.max_cqes_per_cq;
  856. props->max_mr = dev->attr.max_mem_regs;
  857. props->max_pd = dev->attr.max_pds;
  858. props->local_ca_ack_delay = 0;
  859. return 0;
  860. }
  861. static int iwch_query_port(struct ib_device *ibdev,
  862. u8 port, struct ib_port_attr *props)
  863. {
  864. PDBG("%s ibdev %p\n", __FUNCTION__, ibdev);
  865. props->max_mtu = IB_MTU_4096;
  866. props->lid = 0;
  867. props->lmc = 0;
  868. props->sm_lid = 0;
  869. props->sm_sl = 0;
  870. props->state = IB_PORT_ACTIVE;
  871. props->phys_state = 0;
  872. props->port_cap_flags =
  873. IB_PORT_CM_SUP |
  874. IB_PORT_SNMP_TUNNEL_SUP |
  875. IB_PORT_REINIT_SUP |
  876. IB_PORT_DEVICE_MGMT_SUP |
  877. IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
  878. props->gid_tbl_len = 1;
  879. props->pkey_tbl_len = 1;
  880. props->qkey_viol_cntr = 0;
  881. props->active_width = 2;
  882. props->active_speed = 2;
  883. props->max_msg_sz = -1;
  884. return 0;
  885. }
  886. static ssize_t show_rev(struct class_device *cdev, char *buf)
  887. {
  888. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  889. ibdev.class_dev);
  890. PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
  891. return sprintf(buf, "%d\n", dev->rdev.t3cdev_p->type);
  892. }
  893. static ssize_t show_fw_ver(struct class_device *cdev, char *buf)
  894. {
  895. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  896. ibdev.class_dev);
  897. struct ethtool_drvinfo info;
  898. struct net_device *lldev = dev->rdev.t3cdev_p->lldev;
  899. PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
  900. lldev->ethtool_ops->get_drvinfo(lldev, &info);
  901. return sprintf(buf, "%s\n", info.fw_version);
  902. }
  903. static ssize_t show_hca(struct class_device *cdev, char *buf)
  904. {
  905. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  906. ibdev.class_dev);
  907. struct ethtool_drvinfo info;
  908. struct net_device *lldev = dev->rdev.t3cdev_p->lldev;
  909. PDBG("%s class dev 0x%p\n", __FUNCTION__, cdev);
  910. lldev->ethtool_ops->get_drvinfo(lldev, &info);
  911. return sprintf(buf, "%s\n", info.driver);
  912. }
  913. static ssize_t show_board(struct class_device *cdev, char *buf)
  914. {
  915. struct iwch_dev *dev = container_of(cdev, struct iwch_dev,
  916. ibdev.class_dev);
  917. PDBG("%s class dev 0x%p\n", __FUNCTION__, dev);
  918. return sprintf(buf, "%x.%x\n", dev->rdev.rnic_info.pdev->vendor,
  919. dev->rdev.rnic_info.pdev->device);
  920. }
  921. static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  922. static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
  923. static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  924. static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
  925. static struct class_device_attribute *iwch_class_attributes[] = {
  926. &class_device_attr_hw_rev,
  927. &class_device_attr_fw_ver,
  928. &class_device_attr_hca_type,
  929. &class_device_attr_board_id
  930. };
  931. int iwch_register_device(struct iwch_dev *dev)
  932. {
  933. int ret;
  934. int i;
  935. PDBG("%s iwch_dev %p\n", __FUNCTION__, dev);
  936. strlcpy(dev->ibdev.name, "cxgb3_%d", IB_DEVICE_NAME_MAX);
  937. memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
  938. memcpy(&dev->ibdev.node_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
  939. dev->ibdev.owner = THIS_MODULE;
  940. dev->device_cap_flags =
  941. (IB_DEVICE_ZERO_STAG |
  942. IB_DEVICE_SEND_W_INV | IB_DEVICE_MEM_WINDOW);
  943. dev->ibdev.uverbs_cmd_mask =
  944. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  945. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  946. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  947. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  948. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  949. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  950. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  951. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  952. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  953. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  954. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  955. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  956. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  957. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  958. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  959. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  960. (1ull << IB_USER_VERBS_CMD_POST_RECV);
  961. dev->ibdev.node_type = RDMA_NODE_RNIC;
  962. memcpy(dev->ibdev.node_desc, IWCH_NODE_DESC, sizeof(IWCH_NODE_DESC));
  963. dev->ibdev.phys_port_cnt = dev->rdev.port_info.nports;
  964. dev->ibdev.num_comp_vectors = 1;
  965. dev->ibdev.dma_device = &(dev->rdev.rnic_info.pdev->dev);
  966. dev->ibdev.query_device = iwch_query_device;
  967. dev->ibdev.query_port = iwch_query_port;
  968. dev->ibdev.modify_port = iwch_modify_port;
  969. dev->ibdev.query_pkey = iwch_query_pkey;
  970. dev->ibdev.query_gid = iwch_query_gid;
  971. dev->ibdev.alloc_ucontext = iwch_alloc_ucontext;
  972. dev->ibdev.dealloc_ucontext = iwch_dealloc_ucontext;
  973. dev->ibdev.mmap = iwch_mmap;
  974. dev->ibdev.alloc_pd = iwch_allocate_pd;
  975. dev->ibdev.dealloc_pd = iwch_deallocate_pd;
  976. dev->ibdev.create_ah = iwch_ah_create;
  977. dev->ibdev.destroy_ah = iwch_ah_destroy;
  978. dev->ibdev.create_qp = iwch_create_qp;
  979. dev->ibdev.modify_qp = iwch_ib_modify_qp;
  980. dev->ibdev.destroy_qp = iwch_destroy_qp;
  981. dev->ibdev.create_cq = iwch_create_cq;
  982. dev->ibdev.destroy_cq = iwch_destroy_cq;
  983. dev->ibdev.resize_cq = iwch_resize_cq;
  984. dev->ibdev.poll_cq = iwch_poll_cq;
  985. dev->ibdev.get_dma_mr = iwch_get_dma_mr;
  986. dev->ibdev.reg_phys_mr = iwch_register_phys_mem;
  987. dev->ibdev.rereg_phys_mr = iwch_reregister_phys_mem;
  988. dev->ibdev.reg_user_mr = iwch_reg_user_mr;
  989. dev->ibdev.dereg_mr = iwch_dereg_mr;
  990. dev->ibdev.alloc_mw = iwch_alloc_mw;
  991. dev->ibdev.bind_mw = iwch_bind_mw;
  992. dev->ibdev.dealloc_mw = iwch_dealloc_mw;
  993. dev->ibdev.attach_mcast = iwch_multicast_attach;
  994. dev->ibdev.detach_mcast = iwch_multicast_detach;
  995. dev->ibdev.process_mad = iwch_process_mad;
  996. dev->ibdev.req_notify_cq = iwch_arm_cq;
  997. dev->ibdev.post_send = iwch_post_send;
  998. dev->ibdev.post_recv = iwch_post_receive;
  999. dev->ibdev.iwcm =
  1000. (struct iw_cm_verbs *) kmalloc(sizeof(struct iw_cm_verbs),
  1001. GFP_KERNEL);
  1002. dev->ibdev.iwcm->connect = iwch_connect;
  1003. dev->ibdev.iwcm->accept = iwch_accept_cr;
  1004. dev->ibdev.iwcm->reject = iwch_reject_cr;
  1005. dev->ibdev.iwcm->create_listen = iwch_create_listen;
  1006. dev->ibdev.iwcm->destroy_listen = iwch_destroy_listen;
  1007. dev->ibdev.iwcm->add_ref = iwch_qp_add_ref;
  1008. dev->ibdev.iwcm->rem_ref = iwch_qp_rem_ref;
  1009. dev->ibdev.iwcm->get_qp = iwch_get_qp;
  1010. ret = ib_register_device(&dev->ibdev);
  1011. if (ret)
  1012. goto bail1;
  1013. for (i = 0; i < ARRAY_SIZE(iwch_class_attributes); ++i) {
  1014. ret = class_device_create_file(&dev->ibdev.class_dev,
  1015. iwch_class_attributes[i]);
  1016. if (ret) {
  1017. goto bail2;
  1018. }
  1019. }
  1020. return 0;
  1021. bail2:
  1022. ib_unregister_device(&dev->ibdev);
  1023. bail1:
  1024. return ret;
  1025. }
  1026. void iwch_unregister_device(struct iwch_dev *dev)
  1027. {
  1028. int i;
  1029. PDBG("%s iwch_dev %p\n", __FUNCTION__, dev);
  1030. for (i = 0; i < ARRAY_SIZE(iwch_class_attributes); ++i)
  1031. class_device_remove_file(&dev->ibdev.class_dev,
  1032. iwch_class_attributes[i]);
  1033. ib_unregister_device(&dev->ibdev);
  1034. return;
  1035. }