iwch_provider.c 32 KB

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