1 /*******************************************************************************
3 * Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenFabrics.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 *******************************************************************************/
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/random.h>
38 #include <linux/highmem.h>
39 #include <linux/time.h>
40 #include <asm/byteorder.h>
42 #include <rdma/ib_verbs.h>
43 #include <rdma/iw_cm.h>
44 #include <rdma/ib_user_verbs.h>
45 #include <rdma/ib_umem.h>
49 * i40iw_query_device - get device attributes
50 * @ibdev: device pointer from stack
51 * @props: returning device attributes
54 static int i40iw_query_device(struct ib_device *ibdev,
55 struct ib_device_attr *props,
56 struct ib_udata *udata)
58 struct i40iw_device *iwdev = to_iwdev(ibdev);
60 if (udata->inlen || udata->outlen)
62 memset(props, 0, sizeof(*props));
63 ether_addr_copy((u8 *)&props->sys_image_guid, iwdev->netdev->dev_addr);
64 props->fw_ver = I40IW_FW_VERSION;
65 props->device_cap_flags = iwdev->device_cap_flags;
66 props->vendor_id = iwdev->ldev->pcidev->vendor;
67 props->vendor_part_id = iwdev->ldev->pcidev->device;
68 props->hw_ver = (u32)iwdev->sc_dev.hw_rev;
69 props->max_mr_size = I40IW_MAX_OUTBOUND_MESSAGE_SIZE;
70 props->max_qp = iwdev->max_qp;
71 props->max_qp_wr = (I40IW_MAX_WQ_ENTRIES >> 2) - 1;
72 props->max_sge = I40IW_MAX_WQ_FRAGMENT_COUNT;
73 props->max_cq = iwdev->max_cq;
74 props->max_cqe = iwdev->max_cqe;
75 props->max_mr = iwdev->max_mr;
76 props->max_pd = iwdev->max_pd;
77 props->max_sge_rd = I40IW_MAX_SGE_RD;
78 props->max_qp_rd_atom = I40IW_MAX_IRD_SIZE;
79 props->max_qp_init_rd_atom = props->max_qp_rd_atom;
80 props->atomic_cap = IB_ATOMIC_NONE;
81 props->max_map_per_fmr = 1;
82 props->max_fast_reg_page_list_len = I40IW_MAX_PAGES_PER_FMR;
87 * i40iw_query_port - get port attrubutes
88 * @ibdev: device pointer from stack
89 * @port: port number for query
90 * @props: returning device attributes
92 static int i40iw_query_port(struct ib_device *ibdev,
94 struct ib_port_attr *props)
96 struct i40iw_device *iwdev = to_iwdev(ibdev);
97 struct net_device *netdev = iwdev->netdev;
99 memset(props, 0, sizeof(*props));
101 props->max_mtu = IB_MTU_4096;
102 if (netdev->mtu >= 4096)
103 props->active_mtu = IB_MTU_4096;
104 else if (netdev->mtu >= 2048)
105 props->active_mtu = IB_MTU_2048;
106 else if (netdev->mtu >= 1024)
107 props->active_mtu = IB_MTU_1024;
108 else if (netdev->mtu >= 512)
109 props->active_mtu = IB_MTU_512;
111 props->active_mtu = IB_MTU_256;
114 if (netif_carrier_ok(iwdev->netdev))
115 props->state = IB_PORT_ACTIVE;
117 props->state = IB_PORT_DOWN;
118 props->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_REINIT_SUP |
119 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
120 props->gid_tbl_len = 1;
121 props->pkey_tbl_len = 1;
122 props->active_width = IB_WIDTH_4X;
123 props->active_speed = 1;
124 props->max_msg_sz = I40IW_MAX_OUTBOUND_MESSAGE_SIZE;
129 * i40iw_alloc_ucontext - Allocate the user context data structure
130 * @ibdev: device pointer from stack
133 * This keeps track of all objects associated with a particular
136 static struct ib_ucontext *i40iw_alloc_ucontext(struct ib_device *ibdev,
137 struct ib_udata *udata)
139 struct i40iw_device *iwdev = to_iwdev(ibdev);
140 struct i40iw_alloc_ucontext_req req;
141 struct i40iw_alloc_ucontext_resp uresp;
142 struct i40iw_ucontext *ucontext;
144 if (ib_copy_from_udata(&req, udata, sizeof(req)))
145 return ERR_PTR(-EINVAL);
147 if (req.userspace_ver != I40IW_ABI_USERSPACE_VER) {
148 i40iw_pr_err("Invalid userspace driver version detected. Detected version %d, should be %d\n",
149 req.userspace_ver, I40IW_ABI_USERSPACE_VER);
150 return ERR_PTR(-EINVAL);
153 memset(&uresp, 0, sizeof(uresp));
154 uresp.max_qps = iwdev->max_qp;
155 uresp.max_pds = iwdev->max_pd;
156 uresp.wq_size = iwdev->max_qp_wr * 2;
157 uresp.kernel_ver = I40IW_ABI_KERNEL_VER;
159 ucontext = kzalloc(sizeof(*ucontext), GFP_KERNEL);
161 return ERR_PTR(-ENOMEM);
163 ucontext->iwdev = iwdev;
165 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
167 return ERR_PTR(-EFAULT);
170 INIT_LIST_HEAD(&ucontext->cq_reg_mem_list);
171 spin_lock_init(&ucontext->cq_reg_mem_list_lock);
172 INIT_LIST_HEAD(&ucontext->qp_reg_mem_list);
173 spin_lock_init(&ucontext->qp_reg_mem_list_lock);
175 return &ucontext->ibucontext;
179 * i40iw_dealloc_ucontext - deallocate the user context data structure
180 * @context: user context created during alloc
182 static int i40iw_dealloc_ucontext(struct ib_ucontext *context)
184 struct i40iw_ucontext *ucontext = to_ucontext(context);
187 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
188 if (!list_empty(&ucontext->cq_reg_mem_list)) {
189 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
192 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
193 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
194 if (!list_empty(&ucontext->qp_reg_mem_list)) {
195 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
198 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
205 * i40iw_mmap - user memory map
206 * @context: context created during alloc
207 * @vma: kernel info for user memory map
209 static int i40iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
211 struct i40iw_ucontext *ucontext = to_ucontext(context);
214 if (vma->vm_pgoff || vma->vm_end - vma->vm_start != PAGE_SIZE)
217 dbaddr = I40IW_DB_ADDR_OFFSET + pci_resource_start(ucontext->iwdev->ldev->pcidev, 0);
219 if (io_remap_pfn_range(vma, vma->vm_start, dbaddr >> PAGE_SHIFT, PAGE_SIZE,
220 pgprot_noncached(vma->vm_page_prot)))
227 * i40iw_alloc_push_page - allocate a push page for qp
228 * @iwdev: iwarp device
229 * @qp: hardware control qp
231 static void i40iw_alloc_push_page(struct i40iw_device *iwdev, struct i40iw_sc_qp *qp)
233 struct i40iw_cqp_request *cqp_request;
234 struct cqp_commands_info *cqp_info;
235 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
236 enum i40iw_status_code status;
238 if (qp->push_idx != I40IW_INVALID_PUSH_PAGE_INDEX)
241 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
245 atomic_inc(&cqp_request->refcount);
247 cqp_info = &cqp_request->info;
248 cqp_info->cqp_cmd = OP_MANAGE_PUSH_PAGE;
249 cqp_info->post_sq = 1;
251 cqp_info->in.u.manage_push_page.info.qs_handle = dev->qs_handle;
252 cqp_info->in.u.manage_push_page.info.free_page = 0;
253 cqp_info->in.u.manage_push_page.cqp = &iwdev->cqp.sc_cqp;
254 cqp_info->in.u.manage_push_page.scratch = (uintptr_t)cqp_request;
256 status = i40iw_handle_cqp_op(iwdev, cqp_request);
258 qp->push_idx = cqp_request->compl_info.op_ret_val;
260 i40iw_pr_err("CQP-OP Push page fail");
261 i40iw_put_cqp_request(&iwdev->cqp, cqp_request);
265 * i40iw_dealloc_push_page - free a push page for qp
266 * @iwdev: iwarp device
267 * @qp: hardware control qp
269 static void i40iw_dealloc_push_page(struct i40iw_device *iwdev, struct i40iw_sc_qp *qp)
271 struct i40iw_cqp_request *cqp_request;
272 struct cqp_commands_info *cqp_info;
273 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
274 enum i40iw_status_code status;
276 if (qp->push_idx == I40IW_INVALID_PUSH_PAGE_INDEX)
279 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
283 cqp_info = &cqp_request->info;
284 cqp_info->cqp_cmd = OP_MANAGE_PUSH_PAGE;
285 cqp_info->post_sq = 1;
287 cqp_info->in.u.manage_push_page.info.push_idx = qp->push_idx;
288 cqp_info->in.u.manage_push_page.info.qs_handle = dev->qs_handle;
289 cqp_info->in.u.manage_push_page.info.free_page = 1;
290 cqp_info->in.u.manage_push_page.cqp = &iwdev->cqp.sc_cqp;
291 cqp_info->in.u.manage_push_page.scratch = (uintptr_t)cqp_request;
293 status = i40iw_handle_cqp_op(iwdev, cqp_request);
295 qp->push_idx = I40IW_INVALID_PUSH_PAGE_INDEX;
297 i40iw_pr_err("CQP-OP Push page fail");
301 * i40iw_alloc_pd - allocate protection domain
302 * @ibdev: device pointer from stack
303 * @context: user context created during alloc
306 static struct ib_pd *i40iw_alloc_pd(struct ib_device *ibdev,
307 struct ib_ucontext *context,
308 struct ib_udata *udata)
310 struct i40iw_pd *iwpd;
311 struct i40iw_device *iwdev = to_iwdev(ibdev);
312 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
313 struct i40iw_alloc_pd_resp uresp;
314 struct i40iw_sc_pd *sc_pd;
318 err = i40iw_alloc_resource(iwdev, iwdev->allocated_pds,
319 iwdev->max_pd, &pd_id, &iwdev->next_pd);
321 i40iw_pr_err("alloc resource failed\n");
325 iwpd = kzalloc(sizeof(*iwpd), GFP_KERNEL);
331 sc_pd = &iwpd->sc_pd;
332 dev->iw_pd_ops->pd_init(dev, sc_pd, pd_id);
335 memset(&uresp, 0, sizeof(uresp));
337 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
343 i40iw_add_pdusecount(iwpd);
348 i40iw_free_resource(iwdev, iwdev->allocated_pds, pd_id);
353 * i40iw_dealloc_pd - deallocate pd
354 * @ibpd: ptr of pd to be deallocated
356 static int i40iw_dealloc_pd(struct ib_pd *ibpd)
358 struct i40iw_pd *iwpd = to_iwpd(ibpd);
359 struct i40iw_device *iwdev = to_iwdev(ibpd->device);
361 i40iw_rem_pdusecount(iwpd, iwdev);
366 * i40iw_qp_roundup - return round up qp ring size
367 * @wr_ring_size: ring size to round up
369 static int i40iw_qp_roundup(u32 wr_ring_size)
373 if (wr_ring_size < I40IWQP_SW_MIN_WQSIZE)
374 wr_ring_size = I40IWQP_SW_MIN_WQSIZE;
376 for (wr_ring_size--; scount <= 16; scount *= 2)
377 wr_ring_size |= wr_ring_size >> scount;
378 return ++wr_ring_size;
382 * i40iw_get_pbl - Retrieve pbl from a list given a virtual
384 * @va: user virtual address
385 * @pbl_list: pbl list to search in (QP's or CQ's)
387 static struct i40iw_pbl *i40iw_get_pbl(unsigned long va,
388 struct list_head *pbl_list)
390 struct i40iw_pbl *iwpbl;
392 list_for_each_entry(iwpbl, pbl_list, list) {
393 if (iwpbl->user_base == va) {
394 list_del(&iwpbl->list);
402 * i40iw_free_qp_resources - free up memory resources for qp
403 * @iwdev: iwarp device
404 * @iwqp: qp ptr (user or kernel)
405 * @qp_num: qp number assigned
407 void i40iw_free_qp_resources(struct i40iw_device *iwdev,
408 struct i40iw_qp *iwqp,
411 i40iw_dealloc_push_page(iwdev, &iwqp->sc_qp);
413 i40iw_free_resource(iwdev, iwdev->allocated_qps, qp_num);
414 i40iw_free_dma_mem(iwdev->sc_dev.hw, &iwqp->q2_ctx_mem);
415 i40iw_free_dma_mem(iwdev->sc_dev.hw, &iwqp->kqp.dma_mem);
416 kfree(iwqp->kqp.wrid_mem);
417 iwqp->kqp.wrid_mem = NULL;
418 kfree(iwqp->allocated_buffer);
422 * i40iw_clean_cqes - clean cq entries for qp
423 * @iwqp: qp ptr (user or kernel)
426 static void i40iw_clean_cqes(struct i40iw_qp *iwqp, struct i40iw_cq *iwcq)
428 struct i40iw_cq_uk *ukcq = &iwcq->sc_cq.cq_uk;
430 ukcq->ops.iw_cq_clean(&iwqp->sc_qp.qp_uk, ukcq);
434 * i40iw_destroy_qp - destroy qp
435 * @ibqp: qp's ib pointer also to get to device's qp address
437 static int i40iw_destroy_qp(struct ib_qp *ibqp)
439 struct i40iw_qp *iwqp = to_iwqp(ibqp);
443 if (iwqp->ibqp_state >= IB_QPS_INIT && iwqp->ibqp_state < IB_QPS_RTS)
444 i40iw_next_iw_state(iwqp, I40IW_QP_STATE_ERROR, 0, 0, 0);
446 if (!iwqp->user_mode) {
448 i40iw_clean_cqes(iwqp, iwqp->iwscq);
449 if (iwqp->iwrcq != iwqp->iwscq)
450 i40iw_clean_cqes(iwqp, iwqp->iwrcq);
454 i40iw_rem_ref(&iwqp->ibqp);
459 * i40iw_setup_virt_qp - setup for allocation of virtual qp
462 * @init_info: initialize info to return
464 static int i40iw_setup_virt_qp(struct i40iw_device *iwdev,
465 struct i40iw_qp *iwqp,
466 struct i40iw_qp_init_info *init_info)
468 struct i40iw_pbl *iwpbl = iwqp->iwpbl;
469 struct i40iw_qp_mr *qpmr = &iwpbl->qp_mr;
471 iwqp->page = qpmr->sq_page;
472 init_info->shadow_area_pa = cpu_to_le64(qpmr->shadow);
473 if (iwpbl->pbl_allocated) {
474 init_info->virtual_map = true;
475 init_info->sq_pa = qpmr->sq_pbl.idx;
476 init_info->rq_pa = qpmr->rq_pbl.idx;
478 init_info->sq_pa = qpmr->sq_pbl.addr;
479 init_info->rq_pa = qpmr->rq_pbl.addr;
485 * i40iw_setup_kmode_qp - setup initialization for kernel mode qp
486 * @iwdev: iwarp device
487 * @iwqp: qp ptr (user or kernel)
488 * @info: initialize info to return
490 static int i40iw_setup_kmode_qp(struct i40iw_device *iwdev,
491 struct i40iw_qp *iwqp,
492 struct i40iw_qp_init_info *info)
494 struct i40iw_dma_mem *mem = &iwqp->kqp.dma_mem;
495 u32 sqdepth, rqdepth;
496 u32 sq_size, rq_size;
499 enum i40iw_status_code status;
500 struct i40iw_qp_uk_init_info *ukinfo = &info->qp_uk_init_info;
502 sq_size = i40iw_qp_roundup(ukinfo->sq_size + 1);
503 rq_size = i40iw_qp_roundup(ukinfo->rq_size + 1);
505 status = i40iw_get_wqe_shift(sq_size, ukinfo->max_sq_frag_cnt, ukinfo->max_inline_data, &sqshift);
507 status = i40iw_get_wqe_shift(rq_size, ukinfo->max_rq_frag_cnt, 0, &rqshift);
512 sqdepth = sq_size << sqshift;
513 rqdepth = rq_size << rqshift;
515 size = sqdepth * sizeof(struct i40iw_sq_uk_wr_trk_info) + (rqdepth << 3);
516 iwqp->kqp.wrid_mem = kzalloc(size, GFP_KERNEL);
518 ukinfo->sq_wrtrk_array = (struct i40iw_sq_uk_wr_trk_info *)iwqp->kqp.wrid_mem;
519 if (!ukinfo->sq_wrtrk_array)
522 ukinfo->rq_wrid_array = (u64 *)&ukinfo->sq_wrtrk_array[sqdepth];
524 size = (sqdepth + rqdepth) * I40IW_QP_WQE_MIN_SIZE;
525 size += (I40IW_SHADOW_AREA_SIZE << 3);
527 status = i40iw_allocate_dma_mem(iwdev->sc_dev.hw, mem, size, 256);
529 kfree(ukinfo->sq_wrtrk_array);
530 ukinfo->sq_wrtrk_array = NULL;
534 ukinfo->sq = mem->va;
535 info->sq_pa = mem->pa;
537 ukinfo->rq = &ukinfo->sq[sqdepth];
538 info->rq_pa = info->sq_pa + (sqdepth * I40IW_QP_WQE_MIN_SIZE);
540 ukinfo->shadow_area = ukinfo->rq[rqdepth].elem;
541 info->shadow_area_pa = info->rq_pa + (rqdepth * I40IW_QP_WQE_MIN_SIZE);
543 ukinfo->sq_size = sq_size;
544 ukinfo->rq_size = rq_size;
545 ukinfo->qp_id = iwqp->ibqp.qp_num;
550 * i40iw_create_qp - create qp
552 * @init_attr: attributes for qp
553 * @udata: user data for create qp
555 static struct ib_qp *i40iw_create_qp(struct ib_pd *ibpd,
556 struct ib_qp_init_attr *init_attr,
557 struct ib_udata *udata)
559 struct i40iw_pd *iwpd = to_iwpd(ibpd);
560 struct i40iw_device *iwdev = to_iwdev(ibpd->device);
561 struct i40iw_cqp *iwcqp = &iwdev->cqp;
562 struct i40iw_qp *iwqp;
563 struct i40iw_ucontext *ucontext;
564 struct i40iw_create_qp_req req;
565 struct i40iw_create_qp_resp uresp;
568 enum i40iw_status_code ret;
572 struct i40iw_sc_qp *qp;
573 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
574 struct i40iw_qp_init_info init_info;
575 struct i40iw_create_qp_info *qp_info;
576 struct i40iw_cqp_request *cqp_request;
577 struct cqp_commands_info *cqp_info;
579 struct i40iw_qp_host_ctx_info *ctx_info;
580 struct i40iwarp_offload_info *iwarp_info;
583 if (init_attr->create_flags)
584 return ERR_PTR(-EINVAL);
585 if (init_attr->cap.max_inline_data > I40IW_MAX_INLINE_DATA_SIZE)
586 init_attr->cap.max_inline_data = I40IW_MAX_INLINE_DATA_SIZE;
588 if (init_attr->cap.max_send_sge > I40IW_MAX_WQ_FRAGMENT_COUNT)
589 init_attr->cap.max_send_sge = I40IW_MAX_WQ_FRAGMENT_COUNT;
591 memset(&init_info, 0, sizeof(init_info));
593 sq_size = init_attr->cap.max_send_wr;
594 rq_size = init_attr->cap.max_recv_wr;
596 init_info.qp_uk_init_info.sq_size = sq_size;
597 init_info.qp_uk_init_info.rq_size = rq_size;
598 init_info.qp_uk_init_info.max_sq_frag_cnt = init_attr->cap.max_send_sge;
599 init_info.qp_uk_init_info.max_rq_frag_cnt = init_attr->cap.max_recv_sge;
600 init_info.qp_uk_init_info.max_inline_data = init_attr->cap.max_inline_data;
602 mem = kzalloc(sizeof(*iwqp), GFP_KERNEL);
604 return ERR_PTR(-ENOMEM);
606 iwqp = (struct i40iw_qp *)mem;
608 qp->back_qp = (void *)iwqp;
609 qp->push_idx = I40IW_INVALID_PUSH_PAGE_INDEX;
611 iwqp->ctx_info.iwarp_info = &iwqp->iwarp_info;
613 if (i40iw_allocate_dma_mem(dev->hw,
615 I40IW_Q2_BUFFER_SIZE + I40IW_QP_CTX_SIZE,
617 i40iw_pr_err("dma_mem failed\n");
622 init_info.q2 = iwqp->q2_ctx_mem.va;
623 init_info.q2_pa = iwqp->q2_ctx_mem.pa;
625 init_info.host_ctx = (void *)init_info.q2 + I40IW_Q2_BUFFER_SIZE;
626 init_info.host_ctx_pa = init_info.q2_pa + I40IW_Q2_BUFFER_SIZE;
628 err_code = i40iw_alloc_resource(iwdev, iwdev->allocated_qps, iwdev->max_qp,
629 &qp_num, &iwdev->next_qp);
631 i40iw_pr_err("qp resource\n");
635 iwqp->allocated_buffer = mem;
638 iwqp->ibqp.qp_num = qp_num;
640 iwqp->iwscq = to_iwcq(init_attr->send_cq);
641 iwqp->iwrcq = to_iwcq(init_attr->recv_cq);
643 iwqp->host_ctx.va = init_info.host_ctx;
644 iwqp->host_ctx.pa = init_info.host_ctx_pa;
645 iwqp->host_ctx.size = I40IW_QP_CTX_SIZE;
647 init_info.pd = &iwpd->sc_pd;
648 init_info.qp_uk_init_info.qp_id = iwqp->ibqp.qp_num;
649 iwqp->ctx_info.qp_compl_ctx = (uintptr_t)qp;
651 if (init_attr->qp_type != IB_QPT_RC) {
655 if (iwdev->push_mode)
656 i40iw_alloc_push_page(iwdev, qp);
658 err_code = ib_copy_from_udata(&req, udata, sizeof(req));
660 i40iw_pr_err("ib_copy_from_data\n");
663 iwqp->ctx_info.qp_compl_ctx = req.user_compl_ctx;
664 if (ibpd->uobject && ibpd->uobject->context) {
666 ucontext = to_ucontext(ibpd->uobject->context);
668 if (req.user_wqe_buffers) {
670 &ucontext->qp_reg_mem_list_lock, flags);
671 iwqp->iwpbl = i40iw_get_pbl(
672 (unsigned long)req.user_wqe_buffers,
673 &ucontext->qp_reg_mem_list);
674 spin_unlock_irqrestore(
675 &ucontext->qp_reg_mem_list_lock, flags);
679 i40iw_pr_err("no pbl info\n");
684 err_code = i40iw_setup_virt_qp(iwdev, iwqp, &init_info);
686 err_code = i40iw_setup_kmode_qp(iwdev, iwqp, &init_info);
690 i40iw_pr_err("setup qp failed\n");
694 init_info.type = I40IW_QP_TYPE_IWARP;
695 ret = dev->iw_priv_qp_ops->qp_init(qp, &init_info);
698 i40iw_pr_err("qp_init fail\n");
701 ctx_info = &iwqp->ctx_info;
702 iwarp_info = &iwqp->iwarp_info;
703 iwarp_info->rd_enable = true;
704 iwarp_info->wr_rdresp_en = true;
705 if (!iwqp->user_mode) {
706 iwarp_info->fast_reg_en = true;
707 iwarp_info->priv_mode_en = true;
709 iwarp_info->ddp_ver = 1;
710 iwarp_info->rdmap_ver = 1;
712 ctx_info->iwarp_info_valid = true;
713 ctx_info->send_cq_num = iwqp->iwscq->sc_cq.cq_uk.cq_id;
714 ctx_info->rcv_cq_num = iwqp->iwrcq->sc_cq.cq_uk.cq_id;
715 if (qp->push_idx == I40IW_INVALID_PUSH_PAGE_INDEX) {
716 ctx_info->push_mode_en = false;
718 ctx_info->push_mode_en = true;
719 ctx_info->push_idx = qp->push_idx;
722 ret = dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp,
723 (u64 *)iwqp->host_ctx.va,
725 ctx_info->iwarp_info_valid = false;
726 cqp_request = i40iw_get_cqp_request(iwcqp, true);
731 cqp_info = &cqp_request->info;
732 qp_info = &cqp_request->info.in.u.qp_create.info;
734 memset(qp_info, 0, sizeof(*qp_info));
736 qp_info->cq_num_valid = true;
737 qp_info->next_iwarp_state = I40IW_QP_STATE_IDLE;
739 cqp_info->cqp_cmd = OP_QP_CREATE;
740 cqp_info->post_sq = 1;
741 cqp_info->in.u.qp_create.qp = qp;
742 cqp_info->in.u.qp_create.scratch = (uintptr_t)cqp_request;
743 ret = i40iw_handle_cqp_op(iwdev, cqp_request);
745 i40iw_pr_err("CQP-OP QP create fail");
750 i40iw_add_ref(&iwqp->ibqp);
751 spin_lock_init(&iwqp->lock);
752 iwqp->sig_all = (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) ? 1 : 0;
753 iwdev->qp_table[qp_num] = iwqp;
754 i40iw_add_pdusecount(iwqp->iwpd);
755 if (ibpd->uobject && udata) {
756 memset(&uresp, 0, sizeof(uresp));
757 uresp.actual_sq_size = sq_size;
758 uresp.actual_rq_size = rq_size;
759 uresp.qp_id = qp_num;
760 uresp.push_idx = qp->push_idx;
761 err_code = ib_copy_to_udata(udata, &uresp, sizeof(uresp));
763 i40iw_pr_err("copy_to_udata failed\n");
764 i40iw_destroy_qp(&iwqp->ibqp);
765 /* let the completion of the qp destroy free the qp */
766 return ERR_PTR(err_code);
769 init_completion(&iwqp->sq_drained);
770 init_completion(&iwqp->rq_drained);
774 i40iw_free_qp_resources(iwdev, iwqp, qp_num);
775 return ERR_PTR(err_code);
779 * i40iw_query - query qp attributes
781 * @attr: attributes pointer
782 * @attr_mask: Not used
783 * @init_attr: qp attributes to return
785 static int i40iw_query_qp(struct ib_qp *ibqp,
786 struct ib_qp_attr *attr,
788 struct ib_qp_init_attr *init_attr)
790 struct i40iw_qp *iwqp = to_iwqp(ibqp);
791 struct i40iw_sc_qp *qp = &iwqp->sc_qp;
793 attr->qp_state = iwqp->ibqp_state;
794 attr->cur_qp_state = attr->qp_state;
795 attr->qp_access_flags = 0;
796 attr->cap.max_send_wr = qp->qp_uk.sq_size;
797 attr->cap.max_recv_wr = qp->qp_uk.rq_size;
798 attr->cap.max_recv_sge = 1;
799 attr->cap.max_inline_data = I40IW_MAX_INLINE_DATA_SIZE;
800 init_attr->event_handler = iwqp->ibqp.event_handler;
801 init_attr->qp_context = iwqp->ibqp.qp_context;
802 init_attr->send_cq = iwqp->ibqp.send_cq;
803 init_attr->recv_cq = iwqp->ibqp.recv_cq;
804 init_attr->srq = iwqp->ibqp.srq;
805 init_attr->cap = attr->cap;
810 * i40iw_hw_modify_qp - setup cqp for modify qp
811 * @iwdev: iwarp device
812 * @iwqp: qp ptr (user or kernel)
813 * @info: info for modify qp
814 * @wait: flag to wait or not for modify qp completion
816 void i40iw_hw_modify_qp(struct i40iw_device *iwdev, struct i40iw_qp *iwqp,
817 struct i40iw_modify_qp_info *info, bool wait)
819 enum i40iw_status_code status;
820 struct i40iw_cqp_request *cqp_request;
821 struct cqp_commands_info *cqp_info;
822 struct i40iw_modify_qp_info *m_info;
824 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
828 cqp_info = &cqp_request->info;
829 m_info = &cqp_info->in.u.qp_modify.info;
830 memcpy(m_info, info, sizeof(*m_info));
831 cqp_info->cqp_cmd = OP_QP_MODIFY;
832 cqp_info->post_sq = 1;
833 cqp_info->in.u.qp_modify.qp = &iwqp->sc_qp;
834 cqp_info->in.u.qp_modify.scratch = (uintptr_t)cqp_request;
835 status = i40iw_handle_cqp_op(iwdev, cqp_request);
837 i40iw_pr_err("CQP-OP Modify QP fail");
841 * i40iw_modify_qp - modify qp request
842 * @ibqp: qp's pointer for modify
843 * @attr: access attributes
844 * @attr_mask: state mask
847 int i40iw_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
848 int attr_mask, struct ib_udata *udata)
850 struct i40iw_qp *iwqp = to_iwqp(ibqp);
851 struct i40iw_device *iwdev = iwqp->iwdev;
852 struct i40iw_qp_host_ctx_info *ctx_info;
853 struct i40iwarp_offload_info *iwarp_info;
854 struct i40iw_modify_qp_info info;
855 u8 issue_modify_qp = 0;
860 memset(&info, 0, sizeof(info));
861 ctx_info = &iwqp->ctx_info;
862 iwarp_info = &iwqp->iwarp_info;
864 spin_lock_irqsave(&iwqp->lock, flags);
866 if (attr_mask & IB_QP_STATE) {
867 switch (attr->qp_state) {
870 if (iwqp->iwarp_state > (u32)I40IW_QP_STATE_IDLE) {
874 if (iwqp->iwarp_state == I40IW_QP_STATE_INVALID) {
875 info.next_iwarp_state = I40IW_QP_STATE_IDLE;
880 if ((iwqp->iwarp_state > (u32)I40IW_QP_STATE_RTS) ||
887 iwqp->hw_tcp_state = I40IW_TCP_STATE_ESTABLISHED;
889 info.next_iwarp_state = I40IW_QP_STATE_RTS;
890 info.tcp_ctx_valid = true;
891 info.ord_valid = true;
892 info.arp_cache_idx_valid = true;
893 info.cq_num_valid = true;
896 if (iwqp->hw_iwarp_state > (u32)I40IW_QP_STATE_RTS) {
900 if ((iwqp->iwarp_state == (u32)I40IW_QP_STATE_CLOSING) ||
901 (iwqp->iwarp_state < (u32)I40IW_QP_STATE_RTS)) {
905 if (iwqp->iwarp_state > (u32)I40IW_QP_STATE_CLOSING) {
909 info.next_iwarp_state = I40IW_QP_STATE_CLOSING;
913 if (iwqp->iwarp_state >= (u32)I40IW_QP_STATE_TERMINATE) {
917 info.next_iwarp_state = I40IW_QP_STATE_TERMINATE;
922 if (iwqp->iwarp_state == (u32)I40IW_QP_STATE_ERROR) {
926 if (iwqp->sc_qp.term_flags)
927 del_timer(&iwqp->terminate_timer);
928 info.next_iwarp_state = I40IW_QP_STATE_ERROR;
929 if ((iwqp->hw_tcp_state > I40IW_TCP_STATE_CLOSED) &&
931 (iwqp->hw_tcp_state != I40IW_TCP_STATE_TIME_WAIT))
932 info.reset_tcp_conn = true;
936 info.next_iwarp_state = I40IW_QP_STATE_ERROR;
943 iwqp->ibqp_state = attr->qp_state;
946 iwqp->iwarp_state = info.next_iwarp_state;
948 info.next_iwarp_state = iwqp->iwarp_state;
950 if (attr_mask & IB_QP_ACCESS_FLAGS) {
951 ctx_info->iwarp_info_valid = true;
952 if (attr->qp_access_flags & IB_ACCESS_LOCAL_WRITE)
953 iwarp_info->wr_rdresp_en = true;
954 if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE)
955 iwarp_info->wr_rdresp_en = true;
956 if (attr->qp_access_flags & IB_ACCESS_REMOTE_READ)
957 iwarp_info->rd_enable = true;
958 if (attr->qp_access_flags & IB_ACCESS_MW_BIND)
959 iwarp_info->bind_en = true;
961 if (iwqp->user_mode) {
962 iwarp_info->rd_enable = true;
963 iwarp_info->wr_rdresp_en = true;
964 iwarp_info->priv_mode_en = false;
968 if (ctx_info->iwarp_info_valid) {
969 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
972 ctx_info->send_cq_num = iwqp->iwscq->sc_cq.cq_uk.cq_id;
973 ctx_info->rcv_cq_num = iwqp->iwrcq->sc_cq.cq_uk.cq_id;
974 ret = dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp,
975 (u64 *)iwqp->host_ctx.va,
978 i40iw_pr_err("setting QP context\n");
984 spin_unlock_irqrestore(&iwqp->lock, flags);
987 i40iw_hw_modify_qp(iwdev, iwqp, &info, true);
989 if (issue_modify_qp && (iwqp->ibqp_state > IB_QPS_RTS)) {
991 if (iwqp->cm_id && iwqp->hw_tcp_state) {
992 spin_lock_irqsave(&iwqp->lock, flags);
993 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSED;
994 iwqp->last_aeq = I40IW_AE_RESET_SENT;
995 spin_unlock_irqrestore(&iwqp->lock, flags);
1001 spin_unlock_irqrestore(&iwqp->lock, flags);
1006 * cq_free_resources - free up recources for cq
1007 * @iwdev: iwarp device
1010 static void cq_free_resources(struct i40iw_device *iwdev, struct i40iw_cq *iwcq)
1012 struct i40iw_sc_cq *cq = &iwcq->sc_cq;
1014 if (!iwcq->user_mode)
1015 i40iw_free_dma_mem(iwdev->sc_dev.hw, &iwcq->kmem);
1016 i40iw_free_resource(iwdev, iwdev->allocated_cqs, cq->cq_uk.cq_id);
1020 * cq_wq_destroy - send cq destroy cqp
1021 * @iwdev: iwarp device
1022 * @cq: hardware control cq
1024 static void cq_wq_destroy(struct i40iw_device *iwdev, struct i40iw_sc_cq *cq)
1026 enum i40iw_status_code status;
1027 struct i40iw_cqp_request *cqp_request;
1028 struct cqp_commands_info *cqp_info;
1030 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1034 cqp_info = &cqp_request->info;
1036 cqp_info->cqp_cmd = OP_CQ_DESTROY;
1037 cqp_info->post_sq = 1;
1038 cqp_info->in.u.cq_destroy.cq = cq;
1039 cqp_info->in.u.cq_destroy.scratch = (uintptr_t)cqp_request;
1040 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1042 i40iw_pr_err("CQP-OP Destroy QP fail");
1046 * i40iw_destroy_cq - destroy cq
1047 * @ib_cq: cq pointer
1049 static int i40iw_destroy_cq(struct ib_cq *ib_cq)
1051 struct i40iw_cq *iwcq;
1052 struct i40iw_device *iwdev;
1053 struct i40iw_sc_cq *cq;
1056 i40iw_pr_err("ib_cq == NULL\n");
1060 iwcq = to_iwcq(ib_cq);
1061 iwdev = to_iwdev(ib_cq->device);
1063 cq_wq_destroy(iwdev, cq);
1064 cq_free_resources(iwdev, iwcq);
1070 * i40iw_create_cq - create cq
1071 * @ibdev: device pointer from stack
1072 * @attr: attributes for cq
1073 * @context: user context created during alloc
1076 static struct ib_cq *i40iw_create_cq(struct ib_device *ibdev,
1077 const struct ib_cq_init_attr *attr,
1078 struct ib_ucontext *context,
1079 struct ib_udata *udata)
1081 struct i40iw_device *iwdev = to_iwdev(ibdev);
1082 struct i40iw_cq *iwcq;
1083 struct i40iw_pbl *iwpbl;
1085 struct i40iw_sc_cq *cq;
1086 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1087 struct i40iw_cq_init_info info;
1088 enum i40iw_status_code status;
1089 struct i40iw_cqp_request *cqp_request;
1090 struct cqp_commands_info *cqp_info;
1091 struct i40iw_cq_uk_init_info *ukinfo = &info.cq_uk_init_info;
1092 unsigned long flags;
1094 int entries = attr->cqe;
1096 if (entries > iwdev->max_cqe)
1097 return ERR_PTR(-EINVAL);
1099 iwcq = kzalloc(sizeof(*iwcq), GFP_KERNEL);
1101 return ERR_PTR(-ENOMEM);
1103 memset(&info, 0, sizeof(info));
1105 err_code = i40iw_alloc_resource(iwdev, iwdev->allocated_cqs,
1106 iwdev->max_cq, &cq_num,
1112 cq->back_cq = (void *)iwcq;
1113 spin_lock_init(&iwcq->lock);
1116 ukinfo->cq_size = max(entries, 4);
1117 ukinfo->cq_id = cq_num;
1118 iwcq->ibcq.cqe = info.cq_uk_init_info.cq_size;
1121 info.ceq_id_valid = true;
1123 info.type = I40IW_CQ_TYPE_IWARP;
1125 struct i40iw_ucontext *ucontext;
1126 struct i40iw_create_cq_req req;
1127 struct i40iw_cq_mr *cqmr;
1129 memset(&req, 0, sizeof(req));
1130 iwcq->user_mode = true;
1131 ucontext = to_ucontext(context);
1132 if (ib_copy_from_udata(&req, udata, sizeof(struct i40iw_create_cq_req)))
1133 goto cq_free_resources;
1135 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
1136 iwpbl = i40iw_get_pbl((unsigned long)req.user_cq_buffer,
1137 &ucontext->cq_reg_mem_list);
1138 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
1141 goto cq_free_resources;
1144 iwcq->iwpbl = iwpbl;
1145 iwcq->cq_mem_size = 0;
1146 cqmr = &iwpbl->cq_mr;
1147 info.shadow_area_pa = cpu_to_le64(cqmr->shadow);
1148 if (iwpbl->pbl_allocated) {
1149 info.virtual_map = true;
1150 info.pbl_chunk_size = 1;
1151 info.first_pm_pbl_idx = cqmr->cq_pbl.idx;
1153 info.cq_base_pa = cqmr->cq_pbl.addr;
1156 /* Kmode allocations */
1160 rsize = info.cq_uk_init_info.cq_size * sizeof(struct i40iw_cqe);
1161 rsize = round_up(rsize, 256);
1162 shadow = I40IW_SHADOW_AREA_SIZE << 3;
1163 status = i40iw_allocate_dma_mem(dev->hw, &iwcq->kmem,
1164 rsize + shadow, 256);
1167 goto cq_free_resources;
1169 ukinfo->cq_base = iwcq->kmem.va;
1170 info.cq_base_pa = iwcq->kmem.pa;
1171 info.shadow_area_pa = info.cq_base_pa + rsize;
1172 ukinfo->shadow_area = iwcq->kmem.va + rsize;
1175 if (dev->iw_priv_cq_ops->cq_init(cq, &info)) {
1176 i40iw_pr_err("init cq fail\n");
1178 goto cq_free_resources;
1181 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1184 goto cq_free_resources;
1187 cqp_info = &cqp_request->info;
1188 cqp_info->cqp_cmd = OP_CQ_CREATE;
1189 cqp_info->post_sq = 1;
1190 cqp_info->in.u.cq_create.cq = cq;
1191 cqp_info->in.u.cq_create.scratch = (uintptr_t)cqp_request;
1192 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1194 i40iw_pr_err("CQP-OP Create QP fail");
1196 goto cq_free_resources;
1200 struct i40iw_create_cq_resp resp;
1202 memset(&resp, 0, sizeof(resp));
1203 resp.cq_id = info.cq_uk_init_info.cq_id;
1204 resp.cq_size = info.cq_uk_init_info.cq_size;
1205 if (ib_copy_to_udata(udata, &resp, sizeof(resp))) {
1206 i40iw_pr_err("copy to user data\n");
1212 return (struct ib_cq *)iwcq;
1215 cq_wq_destroy(iwdev, cq);
1217 cq_free_resources(iwdev, iwcq);
1220 return ERR_PTR(err_code);
1224 * i40iw_get_user_access - get hw access from IB access
1225 * @acc: IB access to return hw access
1227 static inline u16 i40iw_get_user_access(int acc)
1231 access |= (acc & IB_ACCESS_LOCAL_WRITE) ? I40IW_ACCESS_FLAGS_LOCALWRITE : 0;
1232 access |= (acc & IB_ACCESS_REMOTE_WRITE) ? I40IW_ACCESS_FLAGS_REMOTEWRITE : 0;
1233 access |= (acc & IB_ACCESS_REMOTE_READ) ? I40IW_ACCESS_FLAGS_REMOTEREAD : 0;
1234 access |= (acc & IB_ACCESS_MW_BIND) ? I40IW_ACCESS_FLAGS_BIND_WINDOW : 0;
1239 * i40iw_free_stag - free stag resource
1240 * @iwdev: iwarp device
1241 * @stag: stag to free
1243 static void i40iw_free_stag(struct i40iw_device *iwdev, u32 stag)
1247 stag_idx = (stag & iwdev->mr_stagmask) >> I40IW_CQPSQ_STAG_IDX_SHIFT;
1248 i40iw_free_resource(iwdev, iwdev->allocated_mrs, stag_idx);
1252 * i40iw_create_stag - create random stag
1253 * @iwdev: iwarp device
1255 static u32 i40iw_create_stag(struct i40iw_device *iwdev)
1259 u32 next_stag_index;
1265 get_random_bytes(&random, sizeof(random));
1266 consumer_key = (u8)random;
1268 driver_key = random & ~iwdev->mr_stagmask;
1269 next_stag_index = (random & iwdev->mr_stagmask) >> 8;
1270 next_stag_index %= iwdev->max_mr;
1272 ret = i40iw_alloc_resource(iwdev,
1273 iwdev->allocated_mrs, iwdev->max_mr,
1274 &stag_index, &next_stag_index);
1276 stag = stag_index << I40IW_CQPSQ_STAG_IDX_SHIFT;
1278 stag += (u32)consumer_key;
1284 * i40iw_next_pbl_addr - Get next pbl address
1285 * @palloc: Poiner to allocated pbles
1286 * @pbl: pointer to a pble
1287 * @pinfo: info pointer
1290 static inline u64 *i40iw_next_pbl_addr(struct i40iw_pble_alloc *palloc,
1292 struct i40iw_pble_info **pinfo,
1296 if ((!(*pinfo)) || (*idx != (*pinfo)->cnt))
1300 return (u64 *)(*pinfo)->addr;
1304 * i40iw_copy_user_pgaddrs - copy user page address to pble's os locally
1305 * @iwmr: iwmr for IB's user page addresses
1306 * @pbl: ple pointer to save 1 level or 0 level pble
1307 * @level: indicated level 0, 1 or 2
1309 static void i40iw_copy_user_pgaddrs(struct i40iw_mr *iwmr,
1311 enum i40iw_pble_level level)
1313 struct ib_umem *region = iwmr->region;
1314 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1315 int chunk_pages, entry, pg_shift, i;
1316 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1317 struct i40iw_pble_info *pinfo;
1318 struct scatterlist *sg;
1321 pinfo = (level == I40IW_LEVEL_1) ? NULL : palloc->level2.leaf;
1322 pg_shift = ffs(region->page_size) - 1;
1323 for_each_sg(region->sg_head.sgl, sg, region->nmap, entry) {
1324 chunk_pages = sg_dma_len(sg) >> pg_shift;
1325 if ((iwmr->type == IW_MEMREG_TYPE_QP) &&
1326 !iwpbl->qp_mr.sq_page)
1327 iwpbl->qp_mr.sq_page = sg_page(sg);
1328 for (i = 0; i < chunk_pages; i++) {
1329 *pbl = cpu_to_le64(sg_dma_address(sg) + region->page_size * i);
1330 pbl = i40iw_next_pbl_addr(palloc, pbl, &pinfo, &idx);
1336 * i40iw_setup_pbles - copy user pg address to pble's
1337 * @iwdev: iwarp device
1338 * @iwmr: mr pointer for this memory registration
1339 * @use_pbles: flag if to use pble's or memory (level 0)
1341 static int i40iw_setup_pbles(struct i40iw_device *iwdev,
1342 struct i40iw_mr *iwmr,
1345 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1346 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1347 struct i40iw_pble_info *pinfo;
1349 enum i40iw_status_code status;
1350 enum i40iw_pble_level level = I40IW_LEVEL_1;
1352 if (!use_pbles && (iwmr->page_cnt > MAX_SAVE_PAGE_ADDRS))
1356 mutex_lock(&iwdev->pbl_mutex);
1357 status = i40iw_get_pble(&iwdev->sc_dev, iwdev->pble_rsrc, palloc, iwmr->page_cnt);
1358 mutex_unlock(&iwdev->pbl_mutex);
1362 iwpbl->pbl_allocated = true;
1363 level = palloc->level;
1364 pinfo = (level == I40IW_LEVEL_1) ? &palloc->level1 : palloc->level2.leaf;
1365 pbl = (u64 *)pinfo->addr;
1367 pbl = iwmr->pgaddrmem;
1370 i40iw_copy_user_pgaddrs(iwmr, pbl, level);
1375 * i40iw_handle_q_mem - handle memory for qp and cq
1376 * @iwdev: iwarp device
1377 * @req: information for q memory management
1378 * @iwpbl: pble struct
1379 * @use_pbles: flag to use pble
1381 static int i40iw_handle_q_mem(struct i40iw_device *iwdev,
1382 struct i40iw_mem_reg_req *req,
1383 struct i40iw_pbl *iwpbl,
1386 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1387 struct i40iw_mr *iwmr = iwpbl->iwmr;
1388 struct i40iw_qp_mr *qpmr = &iwpbl->qp_mr;
1389 struct i40iw_cq_mr *cqmr = &iwpbl->cq_mr;
1390 struct i40iw_hmc_pble *hmc_p;
1391 u64 *arr = iwmr->pgaddrmem;
1395 total = req->sq_pages + req->rq_pages + req->cq_pages;
1397 err = i40iw_setup_pbles(iwdev, iwmr, use_pbles);
1400 if (use_pbles && (palloc->level != I40IW_LEVEL_1)) {
1401 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1402 iwpbl->pbl_allocated = false;
1407 arr = (u64 *)palloc->level1.addr;
1408 if (req->reg_type == IW_MEMREG_TYPE_QP) {
1409 hmc_p = &qpmr->sq_pbl;
1410 qpmr->shadow = (dma_addr_t)arr[total];
1412 hmc_p->idx = palloc->level1.idx;
1413 hmc_p = &qpmr->rq_pbl;
1414 hmc_p->idx = palloc->level1.idx + req->sq_pages;
1416 hmc_p->addr = arr[0];
1417 hmc_p = &qpmr->rq_pbl;
1418 hmc_p->addr = arr[1];
1421 hmc_p = &cqmr->cq_pbl;
1422 cqmr->shadow = (dma_addr_t)arr[total];
1424 hmc_p->idx = palloc->level1.idx;
1426 hmc_p->addr = arr[0];
1432 * i40iw_hw_alloc_stag - cqp command to allocate stag
1433 * @iwdev: iwarp device
1434 * @iwmr: iwarp mr pointer
1436 static int i40iw_hw_alloc_stag(struct i40iw_device *iwdev, struct i40iw_mr *iwmr)
1438 struct i40iw_allocate_stag_info *info;
1439 struct i40iw_pd *iwpd = to_iwpd(iwmr->ibmr.pd);
1440 enum i40iw_status_code status;
1442 struct i40iw_cqp_request *cqp_request;
1443 struct cqp_commands_info *cqp_info;
1445 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1449 cqp_info = &cqp_request->info;
1450 info = &cqp_info->in.u.alloc_stag.info;
1451 memset(info, 0, sizeof(*info));
1452 info->page_size = PAGE_SIZE;
1453 info->stag_idx = iwmr->stag >> I40IW_CQPSQ_STAG_IDX_SHIFT;
1454 info->pd_id = iwpd->sc_pd.pd_id;
1455 info->total_len = iwmr->length;
1456 info->remote_access = true;
1457 cqp_info->cqp_cmd = OP_ALLOC_STAG;
1458 cqp_info->post_sq = 1;
1459 cqp_info->in.u.alloc_stag.dev = &iwdev->sc_dev;
1460 cqp_info->in.u.alloc_stag.scratch = (uintptr_t)cqp_request;
1462 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1465 i40iw_pr_err("CQP-OP MR Reg fail");
1471 * i40iw_alloc_mr - register stag for fast memory registration
1473 * @mr_type: memory for stag registrion
1474 * @max_num_sg: man number of pages
1476 static struct ib_mr *i40iw_alloc_mr(struct ib_pd *pd,
1477 enum ib_mr_type mr_type,
1480 struct i40iw_pd *iwpd = to_iwpd(pd);
1481 struct i40iw_device *iwdev = to_iwdev(pd->device);
1482 struct i40iw_pble_alloc *palloc;
1483 struct i40iw_pbl *iwpbl;
1484 struct i40iw_mr *iwmr;
1485 enum i40iw_status_code status;
1487 int err_code = -ENOMEM;
1489 iwmr = kzalloc(sizeof(*iwmr), GFP_KERNEL);
1491 return ERR_PTR(-ENOMEM);
1493 stag = i40iw_create_stag(iwdev);
1495 err_code = -EOVERFLOW;
1498 stag &= ~I40IW_CQPSQ_STAG_KEY_MASK;
1500 iwmr->ibmr.rkey = stag;
1501 iwmr->ibmr.lkey = stag;
1503 iwmr->ibmr.device = pd->device;
1504 iwpbl = &iwmr->iwpbl;
1506 iwmr->type = IW_MEMREG_TYPE_MEM;
1507 palloc = &iwpbl->pble_alloc;
1508 iwmr->page_cnt = max_num_sg;
1509 mutex_lock(&iwdev->pbl_mutex);
1510 status = i40iw_get_pble(&iwdev->sc_dev, iwdev->pble_rsrc, palloc, iwmr->page_cnt);
1511 mutex_unlock(&iwdev->pbl_mutex);
1515 if (palloc->level != I40IW_LEVEL_1)
1517 err_code = i40iw_hw_alloc_stag(iwdev, iwmr);
1520 iwpbl->pbl_allocated = true;
1521 i40iw_add_pdusecount(iwpd);
1524 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1526 i40iw_free_stag(iwdev, stag);
1529 return ERR_PTR(err_code);
1533 * i40iw_set_page - populate pbl list for fmr
1534 * @ibmr: ib mem to access iwarp mr pointer
1535 * @addr: page dma address fro pbl list
1537 static int i40iw_set_page(struct ib_mr *ibmr, u64 addr)
1539 struct i40iw_mr *iwmr = to_iwmr(ibmr);
1540 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1541 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1544 if (unlikely(iwmr->npages == iwmr->page_cnt))
1547 pbl = (u64 *)palloc->level1.addr;
1548 pbl[iwmr->npages++] = cpu_to_le64(addr);
1553 * i40iw_map_mr_sg - map of sg list for fmr
1554 * @ibmr: ib mem to access iwarp mr pointer
1555 * @sg: scatter gather list for fmr
1556 * @sg_nents: number of sg pages
1558 static int i40iw_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg,
1559 int sg_nents, unsigned int *sg_offset)
1561 struct i40iw_mr *iwmr = to_iwmr(ibmr);
1564 return ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, i40iw_set_page);
1568 * i40iw_drain_sq - drain the send queue
1569 * @ibqp: ib qp pointer
1571 static void i40iw_drain_sq(struct ib_qp *ibqp)
1573 struct i40iw_qp *iwqp = to_iwqp(ibqp);
1574 struct i40iw_sc_qp *qp = &iwqp->sc_qp;
1576 if (I40IW_RING_MORE_WORK(qp->qp_uk.sq_ring))
1577 wait_for_completion(&iwqp->sq_drained);
1581 * i40iw_drain_rq - drain the receive queue
1582 * @ibqp: ib qp pointer
1584 static void i40iw_drain_rq(struct ib_qp *ibqp)
1586 struct i40iw_qp *iwqp = to_iwqp(ibqp);
1587 struct i40iw_sc_qp *qp = &iwqp->sc_qp;
1589 if (I40IW_RING_MORE_WORK(qp->qp_uk.rq_ring))
1590 wait_for_completion(&iwqp->rq_drained);
1594 * i40iw_hwreg_mr - send cqp command for memory registration
1595 * @iwdev: iwarp device
1596 * @iwmr: iwarp mr pointer
1597 * @access: access for MR
1599 static int i40iw_hwreg_mr(struct i40iw_device *iwdev,
1600 struct i40iw_mr *iwmr,
1603 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1604 struct i40iw_reg_ns_stag_info *stag_info;
1605 struct i40iw_pd *iwpd = to_iwpd(iwmr->ibmr.pd);
1606 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1607 enum i40iw_status_code status;
1609 struct i40iw_cqp_request *cqp_request;
1610 struct cqp_commands_info *cqp_info;
1612 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1616 cqp_info = &cqp_request->info;
1617 stag_info = &cqp_info->in.u.mr_reg_non_shared.info;
1618 memset(stag_info, 0, sizeof(*stag_info));
1619 stag_info->va = (void *)(unsigned long)iwpbl->user_base;
1620 stag_info->stag_idx = iwmr->stag >> I40IW_CQPSQ_STAG_IDX_SHIFT;
1621 stag_info->stag_key = (u8)iwmr->stag;
1622 stag_info->total_len = iwmr->length;
1623 stag_info->access_rights = access;
1624 stag_info->pd_id = iwpd->sc_pd.pd_id;
1625 stag_info->addr_type = I40IW_ADDR_TYPE_VA_BASED;
1627 if (iwmr->page_cnt > 1) {
1628 if (palloc->level == I40IW_LEVEL_1) {
1629 stag_info->first_pm_pbl_index = palloc->level1.idx;
1630 stag_info->chunk_size = 1;
1632 stag_info->first_pm_pbl_index = palloc->level2.root.idx;
1633 stag_info->chunk_size = 3;
1636 stag_info->reg_addr_pa = iwmr->pgaddrmem[0];
1639 cqp_info->cqp_cmd = OP_MR_REG_NON_SHARED;
1640 cqp_info->post_sq = 1;
1641 cqp_info->in.u.mr_reg_non_shared.dev = &iwdev->sc_dev;
1642 cqp_info->in.u.mr_reg_non_shared.scratch = (uintptr_t)cqp_request;
1644 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1647 i40iw_pr_err("CQP-OP MR Reg fail");
1653 * i40iw_reg_user_mr - Register a user memory region
1655 * @start: virtual start address
1656 * @length: length of mr
1657 * @virt: virtual address
1658 * @acc: access of mr
1661 static struct ib_mr *i40iw_reg_user_mr(struct ib_pd *pd,
1666 struct ib_udata *udata)
1668 struct i40iw_pd *iwpd = to_iwpd(pd);
1669 struct i40iw_device *iwdev = to_iwdev(pd->device);
1670 struct i40iw_ucontext *ucontext;
1671 struct i40iw_pble_alloc *palloc;
1672 struct i40iw_pbl *iwpbl;
1673 struct i40iw_mr *iwmr;
1674 struct ib_umem *region;
1675 struct i40iw_mem_reg_req req;
1680 bool use_pbles = false;
1681 unsigned long flags;
1684 if (length > I40IW_MAX_MR_SIZE)
1685 return ERR_PTR(-EINVAL);
1686 region = ib_umem_get(pd->uobject->context, start, length, acc, 0);
1688 return (struct ib_mr *)region;
1690 if (ib_copy_from_udata(&req, udata, sizeof(req))) {
1691 ib_umem_release(region);
1692 return ERR_PTR(-EFAULT);
1695 iwmr = kzalloc(sizeof(*iwmr), GFP_KERNEL);
1697 ib_umem_release(region);
1698 return ERR_PTR(-ENOMEM);
1701 iwpbl = &iwmr->iwpbl;
1703 iwmr->region = region;
1705 iwmr->ibmr.device = pd->device;
1706 ucontext = to_ucontext(pd->uobject->context);
1707 region_length = region->length + (start & 0xfff);
1708 pbl_depth = region_length >> 12;
1709 pbl_depth += (region_length & (4096 - 1)) ? 1 : 0;
1710 iwmr->length = region->length;
1712 iwpbl->user_base = virt;
1713 palloc = &iwpbl->pble_alloc;
1715 iwmr->type = req.reg_type;
1716 iwmr->page_cnt = (u32)pbl_depth;
1718 switch (req.reg_type) {
1719 case IW_MEMREG_TYPE_QP:
1720 use_pbles = ((req.sq_pages + req.rq_pages) > 2);
1721 err = i40iw_handle_q_mem(iwdev, &req, iwpbl, use_pbles);
1724 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
1725 list_add_tail(&iwpbl->list, &ucontext->qp_reg_mem_list);
1726 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
1728 case IW_MEMREG_TYPE_CQ:
1729 use_pbles = (req.cq_pages > 1);
1730 err = i40iw_handle_q_mem(iwdev, &req, iwpbl, use_pbles);
1734 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
1735 list_add_tail(&iwpbl->list, &ucontext->cq_reg_mem_list);
1736 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
1738 case IW_MEMREG_TYPE_MEM:
1739 access = I40IW_ACCESS_FLAGS_LOCALREAD;
1741 use_pbles = (iwmr->page_cnt != 1);
1742 err = i40iw_setup_pbles(iwdev, iwmr, use_pbles);
1746 access |= i40iw_get_user_access(acc);
1747 stag = i40iw_create_stag(iwdev);
1754 iwmr->ibmr.rkey = stag;
1755 iwmr->ibmr.lkey = stag;
1757 err = i40iw_hwreg_mr(iwdev, iwmr, access);
1759 i40iw_free_stag(iwdev, stag);
1767 iwmr->type = req.reg_type;
1768 if (req.reg_type == IW_MEMREG_TYPE_MEM)
1769 i40iw_add_pdusecount(iwpd);
1773 if (palloc->level != I40IW_LEVEL_0)
1774 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1775 ib_umem_release(region);
1777 return ERR_PTR(err);
1781 * i40iw_reg_phys_mr - register kernel physical memory
1783 * @addr: physical address of memory to register
1784 * @size: size of memory to register
1785 * @acc: Access rights
1786 * @iova_start: start of virtual address for physical buffers
1788 struct ib_mr *i40iw_reg_phys_mr(struct ib_pd *pd,
1794 struct i40iw_pd *iwpd = to_iwpd(pd);
1795 struct i40iw_device *iwdev = to_iwdev(pd->device);
1796 struct i40iw_pbl *iwpbl;
1797 struct i40iw_mr *iwmr;
1798 enum i40iw_status_code status;
1800 u16 access = I40IW_ACCESS_FLAGS_LOCALREAD;
1803 iwmr = kzalloc(sizeof(*iwmr), GFP_KERNEL);
1805 return ERR_PTR(-ENOMEM);
1807 iwmr->ibmr.device = pd->device;
1808 iwpbl = &iwmr->iwpbl;
1810 iwmr->type = IW_MEMREG_TYPE_MEM;
1811 iwpbl->user_base = *iova_start;
1812 stag = i40iw_create_stag(iwdev);
1817 access |= i40iw_get_user_access(acc);
1819 iwmr->ibmr.rkey = stag;
1820 iwmr->ibmr.lkey = stag;
1822 iwmr->pgaddrmem[0] = addr;
1823 iwmr->length = size;
1824 status = i40iw_hwreg_mr(iwdev, iwmr, access);
1826 i40iw_free_stag(iwdev, stag);
1831 i40iw_add_pdusecount(iwpd);
1835 return ERR_PTR(ret);
1839 * i40iw_get_dma_mr - register physical mem
1841 * @acc: access for memory
1843 static struct ib_mr *i40iw_get_dma_mr(struct ib_pd *pd, int acc)
1847 return i40iw_reg_phys_mr(pd, 0, 0, acc, &kva);
1851 * i40iw_del_mem_list - Deleting pbl list entries for CQ/QP
1852 * @iwmr: iwmr for IB's user page addresses
1853 * @ucontext: ptr to user context
1855 static void i40iw_del_memlist(struct i40iw_mr *iwmr,
1856 struct i40iw_ucontext *ucontext)
1858 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1859 unsigned long flags;
1861 switch (iwmr->type) {
1862 case IW_MEMREG_TYPE_CQ:
1863 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
1864 if (!list_empty(&ucontext->cq_reg_mem_list))
1865 list_del(&iwpbl->list);
1866 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
1868 case IW_MEMREG_TYPE_QP:
1869 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
1870 if (!list_empty(&ucontext->qp_reg_mem_list))
1871 list_del(&iwpbl->list);
1872 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
1880 * i40iw_dereg_mr - deregister mr
1881 * @ib_mr: mr ptr for dereg
1883 static int i40iw_dereg_mr(struct ib_mr *ib_mr)
1885 struct ib_pd *ibpd = ib_mr->pd;
1886 struct i40iw_pd *iwpd = to_iwpd(ibpd);
1887 struct i40iw_mr *iwmr = to_iwmr(ib_mr);
1888 struct i40iw_device *iwdev = to_iwdev(ib_mr->device);
1889 enum i40iw_status_code status;
1890 struct i40iw_dealloc_stag_info *info;
1891 struct i40iw_pbl *iwpbl = &iwmr->iwpbl;
1892 struct i40iw_pble_alloc *palloc = &iwpbl->pble_alloc;
1893 struct i40iw_cqp_request *cqp_request;
1894 struct cqp_commands_info *cqp_info;
1898 ib_umem_release(iwmr->region);
1900 if (iwmr->type != IW_MEMREG_TYPE_MEM) {
1901 if (ibpd->uobject) {
1902 struct i40iw_ucontext *ucontext;
1904 ucontext = to_ucontext(ibpd->uobject->context);
1905 i40iw_del_memlist(iwmr, ucontext);
1907 if (iwpbl->pbl_allocated)
1908 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1913 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, true);
1917 cqp_info = &cqp_request->info;
1918 info = &cqp_info->in.u.dealloc_stag.info;
1919 memset(info, 0, sizeof(*info));
1921 info->pd_id = cpu_to_le32(iwpd->sc_pd.pd_id & 0x00007fff);
1922 info->stag_idx = RS_64_1(ib_mr->rkey, I40IW_CQPSQ_STAG_IDX_SHIFT);
1923 stag_idx = info->stag_idx;
1925 if (iwpbl->pbl_allocated)
1926 info->dealloc_pbl = true;
1928 cqp_info->cqp_cmd = OP_DEALLOC_STAG;
1929 cqp_info->post_sq = 1;
1930 cqp_info->in.u.dealloc_stag.dev = &iwdev->sc_dev;
1931 cqp_info->in.u.dealloc_stag.scratch = (uintptr_t)cqp_request;
1932 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1934 i40iw_pr_err("CQP-OP dealloc failed for stag_idx = 0x%x\n", stag_idx);
1935 i40iw_rem_pdusecount(iwpd, iwdev);
1936 i40iw_free_stag(iwdev, iwmr->stag);
1937 if (iwpbl->pbl_allocated)
1938 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1946 static ssize_t i40iw_show_rev(struct device *dev,
1947 struct device_attribute *attr, char *buf)
1949 struct i40iw_ib_device *iwibdev = container_of(dev,
1950 struct i40iw_ib_device,
1952 u32 hw_rev = iwibdev->iwdev->sc_dev.hw_rev;
1954 return sprintf(buf, "%x\n", hw_rev);
1960 static ssize_t i40iw_show_hca(struct device *dev,
1961 struct device_attribute *attr, char *buf)
1963 return sprintf(buf, "I40IW\n");
1969 static ssize_t i40iw_show_board(struct device *dev,
1970 struct device_attribute *attr,
1973 return sprintf(buf, "%.*s\n", 32, "I40IW Board ID");
1976 static DEVICE_ATTR(hw_rev, S_IRUGO, i40iw_show_rev, NULL);
1977 static DEVICE_ATTR(hca_type, S_IRUGO, i40iw_show_hca, NULL);
1978 static DEVICE_ATTR(board_id, S_IRUGO, i40iw_show_board, NULL);
1980 static struct device_attribute *i40iw_dev_attributes[] = {
1987 * i40iw_copy_sg_list - copy sg list for qp
1988 * @sg_list: copied into sg_list
1989 * @sgl: copy from sgl
1990 * @num_sges: count of sg entries
1992 static void i40iw_copy_sg_list(struct i40iw_sge *sg_list, struct ib_sge *sgl, int num_sges)
1996 for (i = 0; (i < num_sges) && (i < I40IW_MAX_WQ_FRAGMENT_COUNT); i++) {
1997 sg_list[i].tag_off = sgl[i].addr;
1998 sg_list[i].len = sgl[i].length;
1999 sg_list[i].stag = sgl[i].lkey;
2004 * i40iw_post_send - kernel application wr
2005 * @ibqp: qp ptr for wr
2006 * @ib_wr: work request ptr
2007 * @bad_wr: return of bad wr if err
2009 static int i40iw_post_send(struct ib_qp *ibqp,
2010 struct ib_send_wr *ib_wr,
2011 struct ib_send_wr **bad_wr)
2013 struct i40iw_qp *iwqp;
2014 struct i40iw_qp_uk *ukqp;
2015 struct i40iw_post_sq_info info;
2016 enum i40iw_status_code ret;
2018 unsigned long flags;
2021 iwqp = (struct i40iw_qp *)ibqp;
2022 ukqp = &iwqp->sc_qp.qp_uk;
2024 spin_lock_irqsave(&iwqp->lock, flags);
2027 memset(&info, 0, sizeof(info));
2028 info.wr_id = (u64)(ib_wr->wr_id);
2029 if ((ib_wr->send_flags & IB_SEND_SIGNALED) || iwqp->sig_all)
2030 info.signaled = true;
2031 if (ib_wr->send_flags & IB_SEND_FENCE)
2032 info.read_fence = true;
2034 switch (ib_wr->opcode) {
2037 case IB_WR_SEND_WITH_INV:
2038 if (ib_wr->opcode == IB_WR_SEND) {
2039 if (ib_wr->send_flags & IB_SEND_SOLICITED)
2040 info.op_type = I40IW_OP_TYPE_SEND_SOL;
2042 info.op_type = I40IW_OP_TYPE_SEND;
2044 if (ib_wr->send_flags & IB_SEND_SOLICITED)
2045 info.op_type = I40IW_OP_TYPE_SEND_SOL_INV;
2047 info.op_type = I40IW_OP_TYPE_SEND_INV;
2050 if (ib_wr->send_flags & IB_SEND_INLINE) {
2051 info.op.inline_send.data = (void *)(unsigned long)ib_wr->sg_list[0].addr;
2052 info.op.inline_send.len = ib_wr->sg_list[0].length;
2053 ret = ukqp->ops.iw_inline_send(ukqp, &info, ib_wr->ex.invalidate_rkey, false);
2055 info.op.send.num_sges = ib_wr->num_sge;
2056 info.op.send.sg_list = (struct i40iw_sge *)ib_wr->sg_list;
2057 ret = ukqp->ops.iw_send(ukqp, &info, ib_wr->ex.invalidate_rkey, false);
2061 if (ret == I40IW_ERR_QP_TOOMANY_WRS_POSTED)
2067 case IB_WR_RDMA_WRITE:
2068 info.op_type = I40IW_OP_TYPE_RDMA_WRITE;
2070 if (ib_wr->send_flags & IB_SEND_INLINE) {
2071 info.op.inline_rdma_write.data = (void *)(unsigned long)ib_wr->sg_list[0].addr;
2072 info.op.inline_rdma_write.len = ib_wr->sg_list[0].length;
2073 info.op.inline_rdma_write.rem_addr.tag_off = rdma_wr(ib_wr)->remote_addr;
2074 info.op.inline_rdma_write.rem_addr.stag = rdma_wr(ib_wr)->rkey;
2075 info.op.inline_rdma_write.rem_addr.len = ib_wr->sg_list->length;
2076 ret = ukqp->ops.iw_inline_rdma_write(ukqp, &info, false);
2078 info.op.rdma_write.lo_sg_list = (void *)ib_wr->sg_list;
2079 info.op.rdma_write.num_lo_sges = ib_wr->num_sge;
2080 info.op.rdma_write.rem_addr.tag_off = rdma_wr(ib_wr)->remote_addr;
2081 info.op.rdma_write.rem_addr.stag = rdma_wr(ib_wr)->rkey;
2082 info.op.rdma_write.rem_addr.len = ib_wr->sg_list->length;
2083 ret = ukqp->ops.iw_rdma_write(ukqp, &info, false);
2087 if (ret == I40IW_ERR_QP_TOOMANY_WRS_POSTED)
2093 case IB_WR_RDMA_READ_WITH_INV:
2096 case IB_WR_RDMA_READ:
2097 if (ib_wr->num_sge > I40IW_MAX_SGE_RD) {
2101 info.op_type = I40IW_OP_TYPE_RDMA_READ;
2102 info.op.rdma_read.rem_addr.tag_off = rdma_wr(ib_wr)->remote_addr;
2103 info.op.rdma_read.rem_addr.stag = rdma_wr(ib_wr)->rkey;
2104 info.op.rdma_read.rem_addr.len = ib_wr->sg_list->length;
2105 info.op.rdma_read.lo_addr.tag_off = ib_wr->sg_list->addr;
2106 info.op.rdma_read.lo_addr.stag = ib_wr->sg_list->lkey;
2107 info.op.rdma_read.lo_addr.len = ib_wr->sg_list->length;
2108 ret = ukqp->ops.iw_rdma_read(ukqp, &info, inv_stag, false);
2110 if (ret == I40IW_ERR_QP_TOOMANY_WRS_POSTED)
2116 case IB_WR_LOCAL_INV:
2117 info.op_type = I40IW_OP_TYPE_INV_STAG;
2118 info.op.inv_local_stag.target_stag = ib_wr->ex.invalidate_rkey;
2119 ret = ukqp->ops.iw_stag_local_invalidate(ukqp, &info, true);
2125 struct i40iw_mr *iwmr = to_iwmr(reg_wr(ib_wr)->mr);
2126 int page_shift = ilog2(reg_wr(ib_wr)->mr->page_size);
2127 int flags = reg_wr(ib_wr)->access;
2128 struct i40iw_pble_alloc *palloc = &iwmr->iwpbl.pble_alloc;
2129 struct i40iw_sc_dev *dev = &iwqp->iwdev->sc_dev;
2130 struct i40iw_fast_reg_stag_info info;
2132 memset(&info, 0, sizeof(info));
2133 info.access_rights = I40IW_ACCESS_FLAGS_LOCALREAD;
2134 info.access_rights |= i40iw_get_user_access(flags);
2135 info.stag_key = reg_wr(ib_wr)->key & 0xff;
2136 info.stag_idx = reg_wr(ib_wr)->key >> 8;
2137 info.wr_id = ib_wr->wr_id;
2139 info.addr_type = I40IW_ADDR_TYPE_VA_BASED;
2140 info.va = (void *)(uintptr_t)iwmr->ibmr.iova;
2141 info.total_len = iwmr->ibmr.length;
2142 info.reg_addr_pa = *(u64 *)palloc->level1.addr;
2143 info.first_pm_pbl_index = palloc->level1.idx;
2144 info.local_fence = ib_wr->send_flags & IB_SEND_FENCE;
2145 info.signaled = ib_wr->send_flags & IB_SEND_SIGNALED;
2147 if (iwmr->npages > I40IW_MIN_PAGES_PER_FMR)
2148 info.chunk_size = 1;
2150 if (page_shift == 21)
2151 info.page_size = 1; /* 2M page */
2153 ret = dev->iw_priv_qp_ops->iw_mr_fast_register(&iwqp->sc_qp, &info, true);
2160 i40iw_pr_err(" upost_send bad opcode = 0x%x\n",
2167 ib_wr = ib_wr->next;
2173 ukqp->ops.iw_qp_post_wr(ukqp);
2174 spin_unlock_irqrestore(&iwqp->lock, flags);
2180 * i40iw_post_recv - post receive wr for kernel application
2181 * @ibqp: ib qp pointer
2182 * @ib_wr: work request for receive
2183 * @bad_wr: bad wr caused an error
2185 static int i40iw_post_recv(struct ib_qp *ibqp,
2186 struct ib_recv_wr *ib_wr,
2187 struct ib_recv_wr **bad_wr)
2189 struct i40iw_qp *iwqp;
2190 struct i40iw_qp_uk *ukqp;
2191 struct i40iw_post_rq_info post_recv;
2192 struct i40iw_sge sg_list[I40IW_MAX_WQ_FRAGMENT_COUNT];
2193 enum i40iw_status_code ret = 0;
2194 unsigned long flags;
2197 iwqp = (struct i40iw_qp *)ibqp;
2198 ukqp = &iwqp->sc_qp.qp_uk;
2200 memset(&post_recv, 0, sizeof(post_recv));
2201 spin_lock_irqsave(&iwqp->lock, flags);
2203 post_recv.num_sges = ib_wr->num_sge;
2204 post_recv.wr_id = ib_wr->wr_id;
2205 i40iw_copy_sg_list(sg_list, ib_wr->sg_list, ib_wr->num_sge);
2206 post_recv.sg_list = sg_list;
2207 ret = ukqp->ops.iw_post_receive(ukqp, &post_recv);
2209 i40iw_pr_err(" post_recv err %d\n", ret);
2210 if (ret == I40IW_ERR_QP_TOOMANY_WRS_POSTED)
2217 ib_wr = ib_wr->next;
2220 spin_unlock_irqrestore(&iwqp->lock, flags);
2225 * i40iw_poll_cq - poll cq for completion (kernel apps)
2227 * @num_entries: number of entries to poll
2228 * @entry: wr of entry completed
2230 static int i40iw_poll_cq(struct ib_cq *ibcq,
2232 struct ib_wc *entry)
2234 struct i40iw_cq *iwcq;
2236 struct i40iw_cq_poll_info cq_poll_info;
2237 enum i40iw_status_code ret;
2238 struct i40iw_cq_uk *ukcq;
2239 struct i40iw_sc_qp *qp;
2240 struct i40iw_qp *iwqp;
2241 unsigned long flags;
2243 iwcq = (struct i40iw_cq *)ibcq;
2244 ukcq = &iwcq->sc_cq.cq_uk;
2246 spin_lock_irqsave(&iwcq->lock, flags);
2247 while (cqe_count < num_entries) {
2248 ret = ukcq->ops.iw_cq_poll_completion(ukcq, &cq_poll_info);
2249 if (ret == I40IW_ERR_QUEUE_EMPTY) {
2251 } else if (ret == I40IW_ERR_QUEUE_DESTROYED) {
2258 entry->wc_flags = 0;
2259 entry->wr_id = cq_poll_info.wr_id;
2260 if (cq_poll_info.error) {
2261 entry->status = IB_WC_WR_FLUSH_ERR;
2262 entry->vendor_err = cq_poll_info.major_err << 16 | cq_poll_info.minor_err;
2264 entry->status = IB_WC_SUCCESS;
2267 switch (cq_poll_info.op_type) {
2268 case I40IW_OP_TYPE_RDMA_WRITE:
2269 entry->opcode = IB_WC_RDMA_WRITE;
2271 case I40IW_OP_TYPE_RDMA_READ_INV_STAG:
2272 case I40IW_OP_TYPE_RDMA_READ:
2273 entry->opcode = IB_WC_RDMA_READ;
2275 case I40IW_OP_TYPE_SEND_SOL:
2276 case I40IW_OP_TYPE_SEND_SOL_INV:
2277 case I40IW_OP_TYPE_SEND_INV:
2278 case I40IW_OP_TYPE_SEND:
2279 entry->opcode = IB_WC_SEND;
2281 case I40IW_OP_TYPE_REC:
2282 entry->opcode = IB_WC_RECV;
2285 entry->opcode = IB_WC_RECV;
2289 entry->ex.imm_data = 0;
2290 qp = (struct i40iw_sc_qp *)cq_poll_info.qp_handle;
2291 entry->qp = (struct ib_qp *)qp->back_qp;
2292 entry->src_qp = cq_poll_info.qp_id;
2293 iwqp = (struct i40iw_qp *)qp->back_qp;
2294 if (iwqp->iwarp_state > I40IW_QP_STATE_RTS) {
2295 if (!I40IW_RING_MORE_WORK(qp->qp_uk.sq_ring))
2296 complete(&iwqp->sq_drained);
2297 if (!I40IW_RING_MORE_WORK(qp->qp_uk.rq_ring))
2298 complete(&iwqp->rq_drained);
2300 entry->byte_len = cq_poll_info.bytes_xfered;
2304 spin_unlock_irqrestore(&iwcq->lock, flags);
2309 * i40iw_req_notify_cq - arm cq kernel application
2311 * @notify_flags: notofication flags
2313 static int i40iw_req_notify_cq(struct ib_cq *ibcq,
2314 enum ib_cq_notify_flags notify_flags)
2316 struct i40iw_cq *iwcq;
2317 struct i40iw_cq_uk *ukcq;
2318 unsigned long flags;
2319 enum i40iw_completion_notify cq_notify = IW_CQ_COMPL_EVENT;
2321 iwcq = (struct i40iw_cq *)ibcq;
2322 ukcq = &iwcq->sc_cq.cq_uk;
2323 if (notify_flags == IB_CQ_SOLICITED)
2324 cq_notify = IW_CQ_COMPL_SOLICITED;
2325 spin_lock_irqsave(&iwcq->lock, flags);
2326 ukcq->ops.iw_cq_request_notification(ukcq, cq_notify);
2327 spin_unlock_irqrestore(&iwcq->lock, flags);
2332 * i40iw_port_immutable - return port's immutable data
2333 * @ibdev: ib dev struct
2334 * @port_num: port number
2335 * @immutable: immutable data for the port return
2337 static int i40iw_port_immutable(struct ib_device *ibdev, u8 port_num,
2338 struct ib_port_immutable *immutable)
2340 struct ib_port_attr attr;
2343 err = i40iw_query_port(ibdev, port_num, &attr);
2348 immutable->pkey_tbl_len = attr.pkey_tbl_len;
2349 immutable->gid_tbl_len = attr.gid_tbl_len;
2350 immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
2355 static const char * const i40iw_hw_stat_names[] = {
2357 [I40IW_HW_STAT_INDEX_IP4RXDISCARD] = "ip4InDiscards",
2358 [I40IW_HW_STAT_INDEX_IP4RXTRUNC] = "ip4InTruncatedPkts",
2359 [I40IW_HW_STAT_INDEX_IP4TXNOROUTE] = "ip4OutNoRoutes",
2360 [I40IW_HW_STAT_INDEX_IP6RXDISCARD] = "ip6InDiscards",
2361 [I40IW_HW_STAT_INDEX_IP6RXTRUNC] = "ip6InTruncatedPkts",
2362 [I40IW_HW_STAT_INDEX_IP6TXNOROUTE] = "ip6OutNoRoutes",
2363 [I40IW_HW_STAT_INDEX_TCPRTXSEG] = "tcpRetransSegs",
2364 [I40IW_HW_STAT_INDEX_TCPRXOPTERR] = "tcpInOptErrors",
2365 [I40IW_HW_STAT_INDEX_TCPRXPROTOERR] = "tcpInProtoErrors",
2367 [I40IW_HW_STAT_INDEX_IP4RXOCTS + I40IW_HW_STAT_INDEX_MAX_32] =
2369 [I40IW_HW_STAT_INDEX_IP4RXPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2371 [I40IW_HW_STAT_INDEX_IP4RXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] =
2373 [I40IW_HW_STAT_INDEX_IP4RXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2375 [I40IW_HW_STAT_INDEX_IP4TXOCTS + I40IW_HW_STAT_INDEX_MAX_32] =
2377 [I40IW_HW_STAT_INDEX_IP4TXPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2379 [I40IW_HW_STAT_INDEX_IP4TXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] =
2381 [I40IW_HW_STAT_INDEX_IP4TXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2383 [I40IW_HW_STAT_INDEX_IP6RXOCTS + I40IW_HW_STAT_INDEX_MAX_32] =
2385 [I40IW_HW_STAT_INDEX_IP6RXPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2387 [I40IW_HW_STAT_INDEX_IP6RXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] =
2389 [I40IW_HW_STAT_INDEX_IP6RXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2391 [I40IW_HW_STAT_INDEX_IP6TXOCTS + I40IW_HW_STAT_INDEX_MAX_32] =
2393 [I40IW_HW_STAT_INDEX_IP6TXPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2395 [I40IW_HW_STAT_INDEX_IP6TXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] =
2397 [I40IW_HW_STAT_INDEX_IP6TXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] =
2399 [I40IW_HW_STAT_INDEX_TCPRXSEGS + I40IW_HW_STAT_INDEX_MAX_32] =
2401 [I40IW_HW_STAT_INDEX_TCPTXSEG + I40IW_HW_STAT_INDEX_MAX_32] =
2403 [I40IW_HW_STAT_INDEX_RDMARXRDS + I40IW_HW_STAT_INDEX_MAX_32] =
2405 [I40IW_HW_STAT_INDEX_RDMARXSNDS + I40IW_HW_STAT_INDEX_MAX_32] =
2407 [I40IW_HW_STAT_INDEX_RDMARXWRS + I40IW_HW_STAT_INDEX_MAX_32] =
2409 [I40IW_HW_STAT_INDEX_RDMATXRDS + I40IW_HW_STAT_INDEX_MAX_32] =
2411 [I40IW_HW_STAT_INDEX_RDMATXSNDS + I40IW_HW_STAT_INDEX_MAX_32] =
2413 [I40IW_HW_STAT_INDEX_RDMATXWRS + I40IW_HW_STAT_INDEX_MAX_32] =
2415 [I40IW_HW_STAT_INDEX_RDMAVBND + I40IW_HW_STAT_INDEX_MAX_32] =
2417 [I40IW_HW_STAT_INDEX_RDMAVINV + I40IW_HW_STAT_INDEX_MAX_32] =
2421 static void i40iw_get_dev_fw_str(struct ib_device *dev, char *str,
2424 u32 firmware_version = I40IW_FW_VERSION;
2426 snprintf(str, str_len, "%u.%u", firmware_version,
2427 (firmware_version & 0x000000ff));
2431 * i40iw_alloc_hw_stats - Allocate a hw stats structure
2432 * @ibdev: device pointer from stack
2433 * @port_num: port number
2435 static struct rdma_hw_stats *i40iw_alloc_hw_stats(struct ib_device *ibdev,
2438 struct i40iw_device *iwdev = to_iwdev(ibdev);
2439 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
2440 int num_counters = I40IW_HW_STAT_INDEX_MAX_32 +
2441 I40IW_HW_STAT_INDEX_MAX_64;
2442 unsigned long lifespan = RDMA_HW_STATS_DEFAULT_LIFESPAN;
2444 BUILD_BUG_ON(ARRAY_SIZE(i40iw_hw_stat_names) !=
2445 (I40IW_HW_STAT_INDEX_MAX_32 +
2446 I40IW_HW_STAT_INDEX_MAX_64));
2449 * PFs get the default update lifespan, but VFs only update once
2454 return rdma_alloc_hw_stats_struct(i40iw_hw_stat_names, num_counters,
2459 * i40iw_get_hw_stats - Populates the rdma_hw_stats structure
2460 * @ibdev: device pointer from stack
2461 * @stats: stats pointer from stack
2462 * @port_num: port number
2463 * @index: which hw counter the stack is requesting we update
2465 static int i40iw_get_hw_stats(struct ib_device *ibdev,
2466 struct rdma_hw_stats *stats,
2467 u8 port_num, int index)
2469 struct i40iw_device *iwdev = to_iwdev(ibdev);
2470 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
2471 struct i40iw_dev_pestat *devstat = &dev->dev_pestat;
2472 struct i40iw_dev_hw_stats *hw_stats = &devstat->hw_stats;
2473 unsigned long flags;
2476 spin_lock_irqsave(&devstat->stats_lock, flags);
2477 devstat->ops.iw_hw_stat_read_all(devstat,
2478 &devstat->hw_stats);
2479 spin_unlock_irqrestore(&devstat->stats_lock, flags);
2481 if (i40iw_vchnl_vf_get_pe_stats(dev, &devstat->hw_stats))
2485 memcpy(&stats->value[0], hw_stats, sizeof(*hw_stats));
2487 return stats->num_counters;
2491 * i40iw_query_gid - Query port GID
2492 * @ibdev: device pointer from stack
2493 * @port: port number
2494 * @index: Entry index
2497 static int i40iw_query_gid(struct ib_device *ibdev,
2502 struct i40iw_device *iwdev = to_iwdev(ibdev);
2504 memset(gid->raw, 0, sizeof(gid->raw));
2505 ether_addr_copy(gid->raw, iwdev->netdev->dev_addr);
2510 * i40iw_modify_port Modify port properties
2511 * @ibdev: device pointer from stack
2512 * @port: port number
2513 * @port_modify_mask: mask for port modifications
2514 * @props: port properties
2516 static int i40iw_modify_port(struct ib_device *ibdev,
2518 int port_modify_mask,
2519 struct ib_port_modify *props)
2525 * i40iw_query_pkey - Query partition key
2526 * @ibdev: device pointer from stack
2527 * @port: port number
2528 * @index: index of pkey
2529 * @pkey: pointer to store the pkey
2531 static int i40iw_query_pkey(struct ib_device *ibdev,
2541 * i40iw_create_ah - create address handle
2543 * @ah_attr: address handle attributes
2545 static struct ib_ah *i40iw_create_ah(struct ib_pd *ibpd,
2546 struct ib_ah_attr *attr)
2548 return ERR_PTR(-ENOSYS);
2552 * i40iw_destroy_ah - Destroy address handle
2553 * @ah: pointer to address handle
2555 static int i40iw_destroy_ah(struct ib_ah *ah)
2561 * i40iw_init_rdma_device - initialization of iwarp device
2562 * @iwdev: iwarp device
2564 static struct i40iw_ib_device *i40iw_init_rdma_device(struct i40iw_device *iwdev)
2566 struct i40iw_ib_device *iwibdev;
2567 struct net_device *netdev = iwdev->netdev;
2568 struct pci_dev *pcidev = (struct pci_dev *)iwdev->hw.dev_context;
2570 iwibdev = (struct i40iw_ib_device *)ib_alloc_device(sizeof(*iwibdev));
2572 i40iw_pr_err("iwdev == NULL\n");
2575 strlcpy(iwibdev->ibdev.name, "i40iw%d", IB_DEVICE_NAME_MAX);
2576 iwibdev->ibdev.owner = THIS_MODULE;
2577 iwdev->iwibdev = iwibdev;
2578 iwibdev->iwdev = iwdev;
2580 iwibdev->ibdev.node_type = RDMA_NODE_RNIC;
2581 ether_addr_copy((u8 *)&iwibdev->ibdev.node_guid, netdev->dev_addr);
2583 iwibdev->ibdev.uverbs_cmd_mask =
2584 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
2585 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
2586 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
2587 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
2588 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
2589 (1ull << IB_USER_VERBS_CMD_REG_MR) |
2590 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
2591 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
2592 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
2593 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
2594 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
2595 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
2596 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
2597 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
2598 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
2599 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
2600 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
2601 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
2602 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
2603 (1ull << IB_USER_VERBS_CMD_POST_SEND);
2604 iwibdev->ibdev.phys_port_cnt = 1;
2605 iwibdev->ibdev.num_comp_vectors = 1;
2606 iwibdev->ibdev.dma_device = &pcidev->dev;
2607 iwibdev->ibdev.dev.parent = &pcidev->dev;
2608 iwibdev->ibdev.query_port = i40iw_query_port;
2609 iwibdev->ibdev.modify_port = i40iw_modify_port;
2610 iwibdev->ibdev.query_pkey = i40iw_query_pkey;
2611 iwibdev->ibdev.query_gid = i40iw_query_gid;
2612 iwibdev->ibdev.alloc_ucontext = i40iw_alloc_ucontext;
2613 iwibdev->ibdev.dealloc_ucontext = i40iw_dealloc_ucontext;
2614 iwibdev->ibdev.mmap = i40iw_mmap;
2615 iwibdev->ibdev.alloc_pd = i40iw_alloc_pd;
2616 iwibdev->ibdev.dealloc_pd = i40iw_dealloc_pd;
2617 iwibdev->ibdev.create_qp = i40iw_create_qp;
2618 iwibdev->ibdev.modify_qp = i40iw_modify_qp;
2619 iwibdev->ibdev.query_qp = i40iw_query_qp;
2620 iwibdev->ibdev.destroy_qp = i40iw_destroy_qp;
2621 iwibdev->ibdev.create_cq = i40iw_create_cq;
2622 iwibdev->ibdev.destroy_cq = i40iw_destroy_cq;
2623 iwibdev->ibdev.get_dma_mr = i40iw_get_dma_mr;
2624 iwibdev->ibdev.reg_user_mr = i40iw_reg_user_mr;
2625 iwibdev->ibdev.dereg_mr = i40iw_dereg_mr;
2626 iwibdev->ibdev.alloc_hw_stats = i40iw_alloc_hw_stats;
2627 iwibdev->ibdev.get_hw_stats = i40iw_get_hw_stats;
2628 iwibdev->ibdev.query_device = i40iw_query_device;
2629 iwibdev->ibdev.create_ah = i40iw_create_ah;
2630 iwibdev->ibdev.destroy_ah = i40iw_destroy_ah;
2631 iwibdev->ibdev.drain_sq = i40iw_drain_sq;
2632 iwibdev->ibdev.drain_rq = i40iw_drain_rq;
2633 iwibdev->ibdev.alloc_mr = i40iw_alloc_mr;
2634 iwibdev->ibdev.map_mr_sg = i40iw_map_mr_sg;
2635 iwibdev->ibdev.iwcm = kzalloc(sizeof(*iwibdev->ibdev.iwcm), GFP_KERNEL);
2636 if (!iwibdev->ibdev.iwcm) {
2637 ib_dealloc_device(&iwibdev->ibdev);
2638 i40iw_pr_err("iwcm == NULL\n");
2642 iwibdev->ibdev.iwcm->add_ref = i40iw_add_ref;
2643 iwibdev->ibdev.iwcm->rem_ref = i40iw_rem_ref;
2644 iwibdev->ibdev.iwcm->get_qp = i40iw_get_qp;
2645 iwibdev->ibdev.iwcm->connect = i40iw_connect;
2646 iwibdev->ibdev.iwcm->accept = i40iw_accept;
2647 iwibdev->ibdev.iwcm->reject = i40iw_reject;
2648 iwibdev->ibdev.iwcm->create_listen = i40iw_create_listen;
2649 iwibdev->ibdev.iwcm->destroy_listen = i40iw_destroy_listen;
2650 memcpy(iwibdev->ibdev.iwcm->ifname, netdev->name,
2651 sizeof(iwibdev->ibdev.iwcm->ifname));
2652 iwibdev->ibdev.get_port_immutable = i40iw_port_immutable;
2653 iwibdev->ibdev.get_dev_fw_str = i40iw_get_dev_fw_str;
2654 iwibdev->ibdev.poll_cq = i40iw_poll_cq;
2655 iwibdev->ibdev.req_notify_cq = i40iw_req_notify_cq;
2656 iwibdev->ibdev.post_send = i40iw_post_send;
2657 iwibdev->ibdev.post_recv = i40iw_post_recv;
2663 * i40iw_port_ibevent - indicate port event
2664 * @iwdev: iwarp device
2666 void i40iw_port_ibevent(struct i40iw_device *iwdev)
2668 struct i40iw_ib_device *iwibdev = iwdev->iwibdev;
2669 struct ib_event event;
2671 event.device = &iwibdev->ibdev;
2672 event.element.port_num = 1;
2673 event.event = iwdev->iw_status ? IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
2674 ib_dispatch_event(&event);
2678 * i40iw_unregister_rdma_device - unregister of iwarp from IB
2679 * @iwibdev: rdma device ptr
2681 static void i40iw_unregister_rdma_device(struct i40iw_ib_device *iwibdev)
2685 for (i = 0; i < ARRAY_SIZE(i40iw_dev_attributes); ++i)
2686 device_remove_file(&iwibdev->ibdev.dev,
2687 i40iw_dev_attributes[i]);
2688 ib_unregister_device(&iwibdev->ibdev);
2692 * i40iw_destroy_rdma_device - destroy rdma device and free resources
2693 * @iwibdev: IB device ptr
2695 void i40iw_destroy_rdma_device(struct i40iw_ib_device *iwibdev)
2700 i40iw_unregister_rdma_device(iwibdev);
2701 kfree(iwibdev->ibdev.iwcm);
2702 iwibdev->ibdev.iwcm = NULL;
2703 ib_dealloc_device(&iwibdev->ibdev);
2707 * i40iw_register_rdma_device - register iwarp device to IB
2708 * @iwdev: iwarp device
2710 int i40iw_register_rdma_device(struct i40iw_device *iwdev)
2713 struct i40iw_ib_device *iwibdev;
2715 iwdev->iwibdev = i40iw_init_rdma_device(iwdev);
2716 if (!iwdev->iwibdev)
2718 iwibdev = iwdev->iwibdev;
2720 ret = ib_register_device(&iwibdev->ibdev, NULL);
2724 for (i = 0; i < ARRAY_SIZE(i40iw_dev_attributes); ++i) {
2726 device_create_file(&iwibdev->ibdev.dev,
2727 i40iw_dev_attributes[i]);
2731 device_remove_file(&iwibdev->ibdev.dev, i40iw_dev_attributes[i]);
2733 ib_unregister_device(&iwibdev->ibdev);
2739 kfree(iwdev->iwibdev->ibdev.iwcm);
2740 iwdev->iwibdev->ibdev.iwcm = NULL;
2741 ib_dealloc_device(&iwdev->iwibdev->ibdev);