163fa15dbSBob Pearson // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB 28700e3e7SMoni Shoua /* 38700e3e7SMoni Shoua * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. 48700e3e7SMoni Shoua * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. 58700e3e7SMoni Shoua */ 68700e3e7SMoni Shoua 70bbb3b74SBart Van Assche #include <linux/dma-mapping.h> 84d6f2859SYuval Shaia #include <net/addrconf.h> 989944450SShamir Rabinovitch #include <rdma/uverbs_ioctl.h> 108700e3e7SMoni Shoua #include "rxe.h" 118700e3e7SMoni Shoua #include "rxe_loc.h" 128700e3e7SMoni Shoua #include "rxe_queue.h" 130b1e5b99SYonatan Cohen #include "rxe_hw_counters.h" 148700e3e7SMoni Shoua 158700e3e7SMoni Shoua static int rxe_query_device(struct ib_device *dev, 168700e3e7SMoni Shoua struct ib_device_attr *attr, 178700e3e7SMoni Shoua struct ib_udata *uhw) 188700e3e7SMoni Shoua { 198700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 208700e3e7SMoni Shoua 218700e3e7SMoni Shoua if (uhw->inlen || uhw->outlen) 228700e3e7SMoni Shoua return -EINVAL; 238700e3e7SMoni Shoua 248700e3e7SMoni Shoua *attr = rxe->attr; 258700e3e7SMoni Shoua return 0; 268700e3e7SMoni Shoua } 278700e3e7SMoni Shoua 288700e3e7SMoni Shoua static int rxe_query_port(struct ib_device *dev, 291fb7f897SMark Bloch u32 port_num, struct ib_port_attr *attr) 308700e3e7SMoni Shoua { 318700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 3259590b8aSYuval Shaia int rc; 338700e3e7SMoni Shoua 34c4550c63SOr Gerlitz /* *attr being zeroed by the caller, avoid zeroing it here */ 35d12faf2dSZhu Yanjun *attr = rxe->port.attr; 368700e3e7SMoni Shoua 378700e3e7SMoni Shoua mutex_lock(&rxe->usdev_lock); 38d4186194SYuval Shaia rc = ib_get_eth_speed(dev, port_num, &attr->active_speed, 39e404f945SParav Pandit &attr->active_width); 405736c7c4SAndrew Boyer 415736c7c4SAndrew Boyer if (attr->state == IB_PORT_ACTIVE) 4272a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP; 435736c7c4SAndrew Boyer else if (dev_get_flags(rxe->ndev) & IFF_UP) 4472a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_POLLING; 455736c7c4SAndrew Boyer else 4672a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_DISABLED; 475736c7c4SAndrew Boyer 488700e3e7SMoni Shoua mutex_unlock(&rxe->usdev_lock); 498700e3e7SMoni Shoua 50d4186194SYuval Shaia return rc; 518700e3e7SMoni Shoua } 528700e3e7SMoni Shoua 538700e3e7SMoni Shoua static int rxe_query_pkey(struct ib_device *device, 541fb7f897SMark Bloch u32 port_num, u16 index, u16 *pkey) 558700e3e7SMoni Shoua { 5676251e15SKamal Heib if (index > 0) 578700e3e7SMoni Shoua return -EINVAL; 5876251e15SKamal Heib 5976251e15SKamal Heib *pkey = IB_DEFAULT_PKEY_FULL; 6076251e15SKamal Heib return 0; 618700e3e7SMoni Shoua } 628700e3e7SMoni Shoua 638700e3e7SMoni Shoua static int rxe_modify_device(struct ib_device *dev, 648700e3e7SMoni Shoua int mask, struct ib_device_modify *attr) 658700e3e7SMoni Shoua { 668700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 678700e3e7SMoni Shoua 68f3fceba5SKamal Heib if (mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | 69f3fceba5SKamal Heib IB_DEVICE_MODIFY_NODE_DESC)) 70f3fceba5SKamal Heib return -EOPNOTSUPP; 71f3fceba5SKamal Heib 728700e3e7SMoni Shoua if (mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) 738700e3e7SMoni Shoua rxe->attr.sys_image_guid = cpu_to_be64(attr->sys_image_guid); 748700e3e7SMoni Shoua 758700e3e7SMoni Shoua if (mask & IB_DEVICE_MODIFY_NODE_DESC) { 768700e3e7SMoni Shoua memcpy(rxe->ib_dev.node_desc, 778700e3e7SMoni Shoua attr->node_desc, sizeof(rxe->ib_dev.node_desc)); 788700e3e7SMoni Shoua } 798700e3e7SMoni Shoua 808700e3e7SMoni Shoua return 0; 818700e3e7SMoni Shoua } 828700e3e7SMoni Shoua 838700e3e7SMoni Shoua static int rxe_modify_port(struct ib_device *dev, 841fb7f897SMark Bloch u32 port_num, int mask, struct ib_port_modify *attr) 858700e3e7SMoni Shoua { 868700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 878700e3e7SMoni Shoua struct rxe_port *port; 888700e3e7SMoni Shoua 898700e3e7SMoni Shoua port = &rxe->port; 908700e3e7SMoni Shoua 918700e3e7SMoni Shoua port->attr.port_cap_flags |= attr->set_port_cap_mask; 928700e3e7SMoni Shoua port->attr.port_cap_flags &= ~attr->clr_port_cap_mask; 938700e3e7SMoni Shoua 948700e3e7SMoni Shoua if (mask & IB_PORT_RESET_QKEY_CNTR) 958700e3e7SMoni Shoua port->attr.qkey_viol_cntr = 0; 968700e3e7SMoni Shoua 978700e3e7SMoni Shoua return 0; 988700e3e7SMoni Shoua } 998700e3e7SMoni Shoua 1008700e3e7SMoni Shoua static enum rdma_link_layer rxe_get_link_layer(struct ib_device *dev, 1011fb7f897SMark Bloch u32 port_num) 1028700e3e7SMoni Shoua { 103420bd9e2SKamal Heib return IB_LINK_LAYER_ETHERNET; 1048700e3e7SMoni Shoua } 1058700e3e7SMoni Shoua 10691a42c5bSBob Pearson static int rxe_alloc_ucontext(struct ib_ucontext *ibuc, struct ib_udata *udata) 1078700e3e7SMoni Shoua { 10891a42c5bSBob Pearson struct rxe_dev *rxe = to_rdev(ibuc->device); 10991a42c5bSBob Pearson struct rxe_ucontext *uc = to_ruc(ibuc); 1108700e3e7SMoni Shoua 11191a42c5bSBob Pearson return rxe_add_to_pool(&rxe->uc_pool, uc); 1128700e3e7SMoni Shoua } 1138700e3e7SMoni Shoua 114a2a074efSLeon Romanovsky static void rxe_dealloc_ucontext(struct ib_ucontext *ibuc) 1158700e3e7SMoni Shoua { 1168700e3e7SMoni Shoua struct rxe_ucontext *uc = to_ruc(ibuc); 1178700e3e7SMoni Shoua 1188700e3e7SMoni Shoua rxe_drop_ref(uc); 1198700e3e7SMoni Shoua } 1208700e3e7SMoni Shoua 1211fb7f897SMark Bloch static int rxe_port_immutable(struct ib_device *dev, u32 port_num, 1228700e3e7SMoni Shoua struct ib_port_immutable *immutable) 1238700e3e7SMoni Shoua { 1248700e3e7SMoni Shoua int err; 1258700e3e7SMoni Shoua struct ib_port_attr attr; 1268700e3e7SMoni Shoua 127c4550c63SOr Gerlitz immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; 128c4550c63SOr Gerlitz 129c4550c63SOr Gerlitz err = ib_query_port(dev, port_num, &attr); 1308700e3e7SMoni Shoua if (err) 1318700e3e7SMoni Shoua return err; 1328700e3e7SMoni Shoua 1338700e3e7SMoni Shoua immutable->pkey_tbl_len = attr.pkey_tbl_len; 1348700e3e7SMoni Shoua immutable->gid_tbl_len = attr.gid_tbl_len; 1358700e3e7SMoni Shoua immutable->max_mad_size = IB_MGMT_MAD_SIZE; 1368700e3e7SMoni Shoua 1378700e3e7SMoni Shoua return 0; 1388700e3e7SMoni Shoua } 1398700e3e7SMoni Shoua 140ff23dfa1SShamir Rabinovitch static int rxe_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) 1418700e3e7SMoni Shoua { 14221a428a0SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibpd->device); 14321a428a0SLeon Romanovsky struct rxe_pd *pd = to_rpd(ibpd); 1448700e3e7SMoni Shoua 14591a42c5bSBob Pearson return rxe_add_to_pool(&rxe->pd_pool, pd); 1468700e3e7SMoni Shoua } 1478700e3e7SMoni Shoua 14891a7c58fSLeon Romanovsky static int rxe_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) 1498700e3e7SMoni Shoua { 1508700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 1518700e3e7SMoni Shoua 1528700e3e7SMoni Shoua rxe_drop_ref(pd); 15391a7c58fSLeon Romanovsky return 0; 1548700e3e7SMoni Shoua } 1558700e3e7SMoni Shoua 156fa5d010cSMaor Gottlieb static int rxe_create_ah(struct ib_ah *ibah, 157fa5d010cSMaor Gottlieb struct rdma_ah_init_attr *init_attr, 158fa5d010cSMaor Gottlieb struct ib_udata *udata) 159477864c8SMoni Shoua 1608700e3e7SMoni Shoua { 161d3456914SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibah->device); 162d3456914SLeon Romanovsky struct rxe_ah *ah = to_rah(ibah); 16373a54932SBob Pearson struct rxe_create_ah_resp __user *uresp = NULL; 16473a54932SBob Pearson int err; 16573a54932SBob Pearson 16673a54932SBob Pearson if (udata) { 16773a54932SBob Pearson /* test if new user provider */ 16873a54932SBob Pearson if (udata->outlen >= sizeof(*uresp)) 16973a54932SBob Pearson uresp = udata->outbuf; 17073a54932SBob Pearson ah->is_user = true; 17173a54932SBob Pearson } else { 17273a54932SBob Pearson ah->is_user = false; 17373a54932SBob Pearson } 1748700e3e7SMoni Shoua 175fa5d010cSMaor Gottlieb err = rxe_av_chk_attr(rxe, init_attr->ah_attr); 1768700e3e7SMoni Shoua if (err) 177d3456914SLeon Romanovsky return err; 1788700e3e7SMoni Shoua 17991a42c5bSBob Pearson err = rxe_add_to_pool(&rxe->ah_pool, ah); 180d3456914SLeon Romanovsky if (err) 181d3456914SLeon Romanovsky return err; 1828700e3e7SMoni Shoua 18373a54932SBob Pearson /* create index > 0 */ 18473a54932SBob Pearson rxe_add_index(ah); 185*02827b67SBob Pearson ah->ah_num = ah->elem.index; 18673a54932SBob Pearson 18773a54932SBob Pearson if (uresp) { 18873a54932SBob Pearson /* only if new user provider */ 18973a54932SBob Pearson err = copy_to_user(&uresp->ah_num, &ah->ah_num, 19073a54932SBob Pearson sizeof(uresp->ah_num)); 19173a54932SBob Pearson if (err) { 19273a54932SBob Pearson rxe_drop_index(ah); 19373a54932SBob Pearson rxe_drop_ref(ah); 19473a54932SBob Pearson return -EFAULT; 19573a54932SBob Pearson } 19673a54932SBob Pearson } else if (ah->is_user) { 19773a54932SBob Pearson /* only if old user provider */ 19873a54932SBob Pearson ah->ah_num = 0; 19973a54932SBob Pearson } 20073a54932SBob Pearson 201fa5d010cSMaor Gottlieb rxe_init_av(init_attr->ah_attr, &ah->av); 202d3456914SLeon Romanovsky return 0; 2038700e3e7SMoni Shoua } 2048700e3e7SMoni Shoua 20590898850SDasaratharaman Chandramouli static int rxe_modify_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) 2068700e3e7SMoni Shoua { 2078700e3e7SMoni Shoua int err; 2088700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibah->device); 2098700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 2108700e3e7SMoni Shoua 2118700e3e7SMoni Shoua err = rxe_av_chk_attr(rxe, attr); 2128700e3e7SMoni Shoua if (err) 2138700e3e7SMoni Shoua return err; 2148700e3e7SMoni Shoua 215fa407188SKamal Heib rxe_init_av(attr, &ah->av); 2168700e3e7SMoni Shoua return 0; 2178700e3e7SMoni Shoua } 2188700e3e7SMoni Shoua 21990898850SDasaratharaman Chandramouli static int rxe_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) 2208700e3e7SMoni Shoua { 2218700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 2228700e3e7SMoni Shoua 223eca7ddf9SDasaratharaman Chandramouli memset(attr, 0, sizeof(*attr)); 22444c58487SDasaratharaman Chandramouli attr->type = ibah->type; 2259c96f3d4SZhu Yanjun rxe_av_to_attr(&ah->av, attr); 2268700e3e7SMoni Shoua return 0; 2278700e3e7SMoni Shoua } 2288700e3e7SMoni Shoua 2299a9ebf8cSLeon Romanovsky static int rxe_destroy_ah(struct ib_ah *ibah, u32 flags) 2308700e3e7SMoni Shoua { 2318700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 2328700e3e7SMoni Shoua 23373a54932SBob Pearson rxe_drop_index(ah); 2348700e3e7SMoni Shoua rxe_drop_ref(ah); 2359a9ebf8cSLeon Romanovsky return 0; 2368700e3e7SMoni Shoua } 2378700e3e7SMoni Shoua 238d34ac5cdSBart Van Assche static int post_one_recv(struct rxe_rq *rq, const struct ib_recv_wr *ibwr) 2398700e3e7SMoni Shoua { 2408700e3e7SMoni Shoua int err; 2418700e3e7SMoni Shoua int i; 2428700e3e7SMoni Shoua u32 length; 2438700e3e7SMoni Shoua struct rxe_recv_wqe *recv_wqe; 2448700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 2455bcf5a59SBob Pearson int full; 2468700e3e7SMoni Shoua 247ae6e843fSBob Pearson full = queue_full(rq->queue, QUEUE_TYPE_TO_DRIVER); 2485bcf5a59SBob Pearson if (unlikely(full)) { 2498700e3e7SMoni Shoua err = -ENOMEM; 2508700e3e7SMoni Shoua goto err1; 2518700e3e7SMoni Shoua } 2528700e3e7SMoni Shoua 2538700e3e7SMoni Shoua if (unlikely(num_sge > rq->max_sge)) { 2548700e3e7SMoni Shoua err = -EINVAL; 2558700e3e7SMoni Shoua goto err1; 2568700e3e7SMoni Shoua } 2578700e3e7SMoni Shoua 2588700e3e7SMoni Shoua length = 0; 2598700e3e7SMoni Shoua for (i = 0; i < num_sge; i++) 2608700e3e7SMoni Shoua length += ibwr->sg_list[i].length; 2618700e3e7SMoni Shoua 262ae6e843fSBob Pearson recv_wqe = queue_producer_addr(rq->queue, QUEUE_TYPE_TO_DRIVER); 2638700e3e7SMoni Shoua recv_wqe->wr_id = ibwr->wr_id; 2648700e3e7SMoni Shoua recv_wqe->num_sge = num_sge; 2658700e3e7SMoni Shoua 2668700e3e7SMoni Shoua memcpy(recv_wqe->dma.sge, ibwr->sg_list, 2678700e3e7SMoni Shoua num_sge * sizeof(struct ib_sge)); 2688700e3e7SMoni Shoua 2698700e3e7SMoni Shoua recv_wqe->dma.length = length; 2708700e3e7SMoni Shoua recv_wqe->dma.resid = length; 2718700e3e7SMoni Shoua recv_wqe->dma.num_sge = num_sge; 2728700e3e7SMoni Shoua recv_wqe->dma.cur_sge = 0; 2738700e3e7SMoni Shoua recv_wqe->dma.sge_offset = 0; 2748700e3e7SMoni Shoua 275ae6e843fSBob Pearson queue_advance_producer(rq->queue, QUEUE_TYPE_TO_DRIVER); 2765bcf5a59SBob Pearson 2778700e3e7SMoni Shoua return 0; 2788700e3e7SMoni Shoua 2798700e3e7SMoni Shoua err1: 2808700e3e7SMoni Shoua return err; 2818700e3e7SMoni Shoua } 2828700e3e7SMoni Shoua 28368e326deSLeon Romanovsky static int rxe_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init, 2848700e3e7SMoni Shoua struct ib_udata *udata) 2858700e3e7SMoni Shoua { 2868700e3e7SMoni Shoua int err; 28768e326deSLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibsrq->device); 28868e326deSLeon Romanovsky struct rxe_pd *pd = to_rpd(ibsrq->pd); 28968e326deSLeon Romanovsky struct rxe_srq *srq = to_rsrq(ibsrq); 2900c43ab37SJason Gunthorpe struct rxe_create_srq_resp __user *uresp = NULL; 2910c43ab37SJason Gunthorpe 292652caba5SJason Gunthorpe if (init->srq_type != IB_SRQT_BASIC) 293652caba5SJason Gunthorpe return -EOPNOTSUPP; 294652caba5SJason Gunthorpe 2950c43ab37SJason Gunthorpe if (udata) { 2960c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 29768e326deSLeon Romanovsky return -EINVAL; 2980c43ab37SJason Gunthorpe uresp = udata->outbuf; 2990c43ab37SJason Gunthorpe } 3008700e3e7SMoni Shoua 3018700e3e7SMoni Shoua err = rxe_srq_chk_attr(rxe, NULL, &init->attr, IB_SRQ_INIT_MASK); 3028700e3e7SMoni Shoua if (err) 3038700e3e7SMoni Shoua goto err1; 3048700e3e7SMoni Shoua 30591a42c5bSBob Pearson err = rxe_add_to_pool(&rxe->srq_pool, srq); 30668e326deSLeon Romanovsky if (err) 3078700e3e7SMoni Shoua goto err1; 3088700e3e7SMoni Shoua 3098700e3e7SMoni Shoua rxe_add_ref(pd); 3108700e3e7SMoni Shoua srq->pd = pd; 3118700e3e7SMoni Shoua 312ff23dfa1SShamir Rabinovitch err = rxe_srq_from_init(rxe, srq, init, udata, uresp); 3138700e3e7SMoni Shoua if (err) 3148700e3e7SMoni Shoua goto err2; 3158700e3e7SMoni Shoua 31668e326deSLeon Romanovsky return 0; 3178700e3e7SMoni Shoua 3188700e3e7SMoni Shoua err2: 3198700e3e7SMoni Shoua rxe_drop_ref(pd); 3208700e3e7SMoni Shoua rxe_drop_ref(srq); 3218700e3e7SMoni Shoua err1: 32268e326deSLeon Romanovsky return err; 3238700e3e7SMoni Shoua } 3248700e3e7SMoni Shoua 3258700e3e7SMoni Shoua static int rxe_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 3268700e3e7SMoni Shoua enum ib_srq_attr_mask mask, 3278700e3e7SMoni Shoua struct ib_udata *udata) 3288700e3e7SMoni Shoua { 3298700e3e7SMoni Shoua int err; 3308700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3318700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibsrq->device); 3320c43ab37SJason Gunthorpe struct rxe_modify_srq_cmd ucmd = {}; 3330c43ab37SJason Gunthorpe 3340c43ab37SJason Gunthorpe if (udata) { 3350c43ab37SJason Gunthorpe if (udata->inlen < sizeof(ucmd)) 3360c43ab37SJason Gunthorpe return -EINVAL; 3370c43ab37SJason Gunthorpe 3380c43ab37SJason Gunthorpe err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)); 3390c43ab37SJason Gunthorpe if (err) 3400c43ab37SJason Gunthorpe return err; 3410c43ab37SJason Gunthorpe } 3428700e3e7SMoni Shoua 3438700e3e7SMoni Shoua err = rxe_srq_chk_attr(rxe, srq, attr, mask); 3448700e3e7SMoni Shoua if (err) 3458700e3e7SMoni Shoua goto err1; 3468700e3e7SMoni Shoua 347ff23dfa1SShamir Rabinovitch err = rxe_srq_from_attr(rxe, srq, attr, mask, &ucmd, udata); 3488700e3e7SMoni Shoua if (err) 3498700e3e7SMoni Shoua goto err1; 3508700e3e7SMoni Shoua 3518700e3e7SMoni Shoua return 0; 3528700e3e7SMoni Shoua 3538700e3e7SMoni Shoua err1: 3548700e3e7SMoni Shoua return err; 3558700e3e7SMoni Shoua } 3568700e3e7SMoni Shoua 3578700e3e7SMoni Shoua static int rxe_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr) 3588700e3e7SMoni Shoua { 3598700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3608700e3e7SMoni Shoua 3618700e3e7SMoni Shoua if (srq->error) 3628700e3e7SMoni Shoua return -EINVAL; 3638700e3e7SMoni Shoua 3648700e3e7SMoni Shoua attr->max_wr = srq->rq.queue->buf->index_mask; 3658700e3e7SMoni Shoua attr->max_sge = srq->rq.max_sge; 3668700e3e7SMoni Shoua attr->srq_limit = srq->limit; 3678700e3e7SMoni Shoua return 0; 3688700e3e7SMoni Shoua } 3698700e3e7SMoni Shoua 370119181d1SLeon Romanovsky static int rxe_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata) 3718700e3e7SMoni Shoua { 3728700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3738700e3e7SMoni Shoua 3748700e3e7SMoni Shoua if (srq->rq.queue) 3758700e3e7SMoni Shoua rxe_queue_cleanup(srq->rq.queue); 3768700e3e7SMoni Shoua 3778700e3e7SMoni Shoua rxe_drop_ref(srq->pd); 3788700e3e7SMoni Shoua rxe_drop_ref(srq); 379119181d1SLeon Romanovsky return 0; 3808700e3e7SMoni Shoua } 3818700e3e7SMoni Shoua 382d34ac5cdSBart Van Assche static int rxe_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr, 383d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr) 3848700e3e7SMoni Shoua { 3858700e3e7SMoni Shoua int err = 0; 3868700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3878700e3e7SMoni Shoua 38821adfa7aSBob Pearson spin_lock_bh(&srq->rq.producer_lock); 3898700e3e7SMoni Shoua 3908700e3e7SMoni Shoua while (wr) { 3918700e3e7SMoni Shoua err = post_one_recv(&srq->rq, wr); 3928700e3e7SMoni Shoua if (unlikely(err)) 3938700e3e7SMoni Shoua break; 3948700e3e7SMoni Shoua wr = wr->next; 3958700e3e7SMoni Shoua } 3968700e3e7SMoni Shoua 39721adfa7aSBob Pearson spin_unlock_bh(&srq->rq.producer_lock); 3988700e3e7SMoni Shoua 3998700e3e7SMoni Shoua if (err) 4008700e3e7SMoni Shoua *bad_wr = wr; 4018700e3e7SMoni Shoua 4028700e3e7SMoni Shoua return err; 4038700e3e7SMoni Shoua } 4048700e3e7SMoni Shoua 405514aee66SLeon Romanovsky static int rxe_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init, 4068700e3e7SMoni Shoua struct ib_udata *udata) 4078700e3e7SMoni Shoua { 4088700e3e7SMoni Shoua int err; 409514aee66SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibqp->device); 410514aee66SLeon Romanovsky struct rxe_pd *pd = to_rpd(ibqp->pd); 411514aee66SLeon Romanovsky struct rxe_qp *qp = to_rqp(ibqp); 4120c43ab37SJason Gunthorpe struct rxe_create_qp_resp __user *uresp = NULL; 4130c43ab37SJason Gunthorpe 4140c43ab37SJason Gunthorpe if (udata) { 4150c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 416514aee66SLeon Romanovsky return -EINVAL; 4170c43ab37SJason Gunthorpe uresp = udata->outbuf; 4180c43ab37SJason Gunthorpe } 4198700e3e7SMoni Shoua 4201f11a761SJason Gunthorpe if (init->create_flags) 421514aee66SLeon Romanovsky return -EOPNOTSUPP; 4221f11a761SJason Gunthorpe 4238700e3e7SMoni Shoua err = rxe_qp_chk_init(rxe, init); 4248700e3e7SMoni Shoua if (err) 425514aee66SLeon Romanovsky return err; 4268700e3e7SMoni Shoua 4278700e3e7SMoni Shoua if (udata) { 428514aee66SLeon Romanovsky if (udata->inlen) 429514aee66SLeon Romanovsky return -EINVAL; 430514aee66SLeon Romanovsky 4315bcf5a59SBob Pearson qp->is_user = true; 4325bcf5a59SBob Pearson } else { 4335bcf5a59SBob Pearson qp->is_user = false; 4348700e3e7SMoni Shoua } 4358700e3e7SMoni Shoua 436514aee66SLeon Romanovsky err = rxe_add_to_pool(&rxe->qp_pool, qp); 4378700e3e7SMoni Shoua if (err) 438514aee66SLeon Romanovsky return err; 4398700e3e7SMoni Shoua 440514aee66SLeon Romanovsky rxe_add_index(qp); 441514aee66SLeon Romanovsky err = rxe_qp_from_init(rxe, qp, pd, init, uresp, ibqp->pd, udata); 442514aee66SLeon Romanovsky if (err) 443514aee66SLeon Romanovsky goto qp_init; 4448700e3e7SMoni Shoua 445514aee66SLeon Romanovsky return 0; 446514aee66SLeon Romanovsky 447514aee66SLeon Romanovsky qp_init: 4488700e3e7SMoni Shoua rxe_drop_index(qp); 4498700e3e7SMoni Shoua rxe_drop_ref(qp); 450514aee66SLeon Romanovsky return err; 4518700e3e7SMoni Shoua } 4528700e3e7SMoni Shoua 4538700e3e7SMoni Shoua static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 4548700e3e7SMoni Shoua int mask, struct ib_udata *udata) 4558700e3e7SMoni Shoua { 4568700e3e7SMoni Shoua int err; 4578700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 4588700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4598700e3e7SMoni Shoua 46026e990baSJason Gunthorpe if (mask & ~IB_QP_ATTR_STANDARD_BITS) 46126e990baSJason Gunthorpe return -EOPNOTSUPP; 46226e990baSJason Gunthorpe 4638700e3e7SMoni Shoua err = rxe_qp_chk_attr(rxe, qp, attr, mask); 4648700e3e7SMoni Shoua if (err) 4658700e3e7SMoni Shoua goto err1; 4668700e3e7SMoni Shoua 4678700e3e7SMoni Shoua err = rxe_qp_from_attr(qp, attr, mask, udata); 4688700e3e7SMoni Shoua if (err) 4698700e3e7SMoni Shoua goto err1; 4708700e3e7SMoni Shoua 4718700e3e7SMoni Shoua return 0; 4728700e3e7SMoni Shoua 4738700e3e7SMoni Shoua err1: 4748700e3e7SMoni Shoua return err; 4758700e3e7SMoni Shoua } 4768700e3e7SMoni Shoua 4778700e3e7SMoni Shoua static int rxe_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 4788700e3e7SMoni Shoua int mask, struct ib_qp_init_attr *init) 4798700e3e7SMoni Shoua { 4808700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4818700e3e7SMoni Shoua 4828700e3e7SMoni Shoua rxe_qp_to_init(qp, init); 4838700e3e7SMoni Shoua rxe_qp_to_attr(qp, attr, mask); 4848700e3e7SMoni Shoua 4858700e3e7SMoni Shoua return 0; 4868700e3e7SMoni Shoua } 4878700e3e7SMoni Shoua 488c4367a26SShamir Rabinovitch static int rxe_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) 4898700e3e7SMoni Shoua { 4908700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4918700e3e7SMoni Shoua 4928700e3e7SMoni Shoua rxe_qp_destroy(qp); 4938700e3e7SMoni Shoua rxe_drop_index(qp); 4948700e3e7SMoni Shoua rxe_drop_ref(qp); 4958700e3e7SMoni Shoua return 0; 4968700e3e7SMoni Shoua } 4978700e3e7SMoni Shoua 498f696bf6dSBart Van Assche static int validate_send_wr(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 4998700e3e7SMoni Shoua unsigned int mask, unsigned int length) 5008700e3e7SMoni Shoua { 5018700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 5028700e3e7SMoni Shoua struct rxe_sq *sq = &qp->sq; 5038700e3e7SMoni Shoua 5048700e3e7SMoni Shoua if (unlikely(num_sge > sq->max_sge)) 5058700e3e7SMoni Shoua goto err1; 5068700e3e7SMoni Shoua 5078700e3e7SMoni Shoua if (unlikely(mask & WR_ATOMIC_MASK)) { 5088700e3e7SMoni Shoua if (length < 8) 5098700e3e7SMoni Shoua goto err1; 5108700e3e7SMoni Shoua 5118700e3e7SMoni Shoua if (atomic_wr(ibwr)->remote_addr & 0x7) 5128700e3e7SMoni Shoua goto err1; 5138700e3e7SMoni Shoua } 5148700e3e7SMoni Shoua 5158700e3e7SMoni Shoua if (unlikely((ibwr->send_flags & IB_SEND_INLINE) && 5168700e3e7SMoni Shoua (length > sq->max_inline))) 5178700e3e7SMoni Shoua goto err1; 5188700e3e7SMoni Shoua 5198700e3e7SMoni Shoua return 0; 5208700e3e7SMoni Shoua 5218700e3e7SMoni Shoua err1: 5228700e3e7SMoni Shoua return -EINVAL; 5238700e3e7SMoni Shoua } 5248700e3e7SMoni Shoua 5258700e3e7SMoni Shoua static void init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr, 526f696bf6dSBart Van Assche const struct ib_send_wr *ibwr) 5278700e3e7SMoni Shoua { 5288700e3e7SMoni Shoua wr->wr_id = ibwr->wr_id; 5298700e3e7SMoni Shoua wr->num_sge = ibwr->num_sge; 5308700e3e7SMoni Shoua wr->opcode = ibwr->opcode; 5318700e3e7SMoni Shoua wr->send_flags = ibwr->send_flags; 5328700e3e7SMoni Shoua 5338700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_UD || 5348700e3e7SMoni Shoua qp_type(qp) == IB_QPT_SMI || 5358700e3e7SMoni Shoua qp_type(qp) == IB_QPT_GSI) { 5363b87e082SBob Pearson struct ib_ah *ibah = ud_wr(ibwr)->ah; 5373b87e082SBob Pearson 5388700e3e7SMoni Shoua wr->wr.ud.remote_qpn = ud_wr(ibwr)->remote_qpn; 5398700e3e7SMoni Shoua wr->wr.ud.remote_qkey = ud_wr(ibwr)->remote_qkey; 5403b87e082SBob Pearson wr->wr.ud.ah_num = to_rah(ibah)->ah_num; 5418700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_GSI) 5428700e3e7SMoni Shoua wr->wr.ud.pkey_index = ud_wr(ibwr)->pkey_index; 5438700e3e7SMoni Shoua if (wr->opcode == IB_WR_SEND_WITH_IMM) 5448700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 5458700e3e7SMoni Shoua } else { 5468700e3e7SMoni Shoua switch (wr->opcode) { 5478700e3e7SMoni Shoua case IB_WR_RDMA_WRITE_WITH_IMM: 5488700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 549df561f66SGustavo A. R. Silva fallthrough; 5508700e3e7SMoni Shoua case IB_WR_RDMA_READ: 5518700e3e7SMoni Shoua case IB_WR_RDMA_WRITE: 5528700e3e7SMoni Shoua wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr; 5538700e3e7SMoni Shoua wr->wr.rdma.rkey = rdma_wr(ibwr)->rkey; 5548700e3e7SMoni Shoua break; 5558700e3e7SMoni Shoua case IB_WR_SEND_WITH_IMM: 5568700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 5578700e3e7SMoni Shoua break; 5588700e3e7SMoni Shoua case IB_WR_SEND_WITH_INV: 5598700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 5608700e3e7SMoni Shoua break; 5618700e3e7SMoni Shoua case IB_WR_ATOMIC_CMP_AND_SWP: 5628700e3e7SMoni Shoua case IB_WR_ATOMIC_FETCH_AND_ADD: 5638700e3e7SMoni Shoua wr->wr.atomic.remote_addr = 5648700e3e7SMoni Shoua atomic_wr(ibwr)->remote_addr; 5658700e3e7SMoni Shoua wr->wr.atomic.compare_add = 5668700e3e7SMoni Shoua atomic_wr(ibwr)->compare_add; 5678700e3e7SMoni Shoua wr->wr.atomic.swap = atomic_wr(ibwr)->swap; 5688700e3e7SMoni Shoua wr->wr.atomic.rkey = atomic_wr(ibwr)->rkey; 5698700e3e7SMoni Shoua break; 5708700e3e7SMoni Shoua case IB_WR_LOCAL_INV: 5718700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 5728700e3e7SMoni Shoua break; 5738700e3e7SMoni Shoua case IB_WR_REG_MR: 5748700e3e7SMoni Shoua wr->wr.reg.mr = reg_wr(ibwr)->mr; 5758700e3e7SMoni Shoua wr->wr.reg.key = reg_wr(ibwr)->key; 5768700e3e7SMoni Shoua wr->wr.reg.access = reg_wr(ibwr)->access; 5778700e3e7SMoni Shoua break; 5788700e3e7SMoni Shoua default: 5798700e3e7SMoni Shoua break; 5808700e3e7SMoni Shoua } 5818700e3e7SMoni Shoua } 5828700e3e7SMoni Shoua } 5838700e3e7SMoni Shoua 584086f580cSBob Pearson static void copy_inline_data_to_wqe(struct rxe_send_wqe *wqe, 585086f580cSBob Pearson const struct ib_send_wr *ibwr) 586086f580cSBob Pearson { 587086f580cSBob Pearson struct ib_sge *sge = ibwr->sg_list; 588086f580cSBob Pearson u8 *p = wqe->dma.inline_data; 589086f580cSBob Pearson int i; 590086f580cSBob Pearson 591086f580cSBob Pearson for (i = 0; i < ibwr->num_sge; i++, sge++) { 592086f580cSBob Pearson memcpy(p, (void *)(uintptr_t)sge->addr, sge->length); 593086f580cSBob Pearson p += sge->length; 594086f580cSBob Pearson } 595086f580cSBob Pearson } 596086f580cSBob Pearson 597086f580cSBob Pearson static void init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 5988700e3e7SMoni Shoua unsigned int mask, unsigned int length, 5998700e3e7SMoni Shoua struct rxe_send_wqe *wqe) 6008700e3e7SMoni Shoua { 6018700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 6028700e3e7SMoni Shoua 6038700e3e7SMoni Shoua init_send_wr(qp, &wqe->wr, ibwr); 6048700e3e7SMoni Shoua 605dc78074aSBob Pearson /* local operation */ 606886441fbSBob Pearson if (unlikely(mask & WR_LOCAL_OP_MASK)) { 607dc78074aSBob Pearson wqe->mask = mask; 608dc78074aSBob Pearson wqe->state = wqe_state_posted; 609086f580cSBob Pearson return; 610dc78074aSBob Pearson } 611dc78074aSBob Pearson 612086f580cSBob Pearson if (unlikely(ibwr->send_flags & IB_SEND_INLINE)) 613086f580cSBob Pearson copy_inline_data_to_wqe(wqe, ibwr); 614086f580cSBob Pearson else 6158700e3e7SMoni Shoua memcpy(wqe->dma.sge, ibwr->sg_list, 6168700e3e7SMoni Shoua num_sge * sizeof(struct ib_sge)); 6178700e3e7SMoni Shoua 618a6544a62SBart Van Assche wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr : 619a6544a62SBart Van Assche mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0; 6208700e3e7SMoni Shoua wqe->mask = mask; 6218700e3e7SMoni Shoua wqe->dma.length = length; 6228700e3e7SMoni Shoua wqe->dma.resid = length; 6238700e3e7SMoni Shoua wqe->dma.num_sge = num_sge; 6248700e3e7SMoni Shoua wqe->dma.cur_sge = 0; 6258700e3e7SMoni Shoua wqe->dma.sge_offset = 0; 6268700e3e7SMoni Shoua wqe->state = wqe_state_posted; 6278700e3e7SMoni Shoua wqe->ssn = atomic_add_return(1, &qp->ssn); 6288700e3e7SMoni Shoua } 6298700e3e7SMoni Shoua 630f696bf6dSBart Van Assche static int post_one_send(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 631e404f945SParav Pandit unsigned int mask, u32 length) 6328700e3e7SMoni Shoua { 6338700e3e7SMoni Shoua int err; 6348700e3e7SMoni Shoua struct rxe_sq *sq = &qp->sq; 6358700e3e7SMoni Shoua struct rxe_send_wqe *send_wqe; 6365bcf5a59SBob Pearson int full; 6378700e3e7SMoni Shoua 6388700e3e7SMoni Shoua err = validate_send_wr(qp, ibwr, mask, length); 6398700e3e7SMoni Shoua if (err) 6408700e3e7SMoni Shoua return err; 6418700e3e7SMoni Shoua 64221adfa7aSBob Pearson spin_lock_bh(&qp->sq.sq_lock); 6438700e3e7SMoni Shoua 644ae6e843fSBob Pearson full = queue_full(sq->queue, QUEUE_TYPE_TO_DRIVER); 6455bcf5a59SBob Pearson 6465bcf5a59SBob Pearson if (unlikely(full)) { 64721adfa7aSBob Pearson spin_unlock_bh(&qp->sq.sq_lock); 6485bcf5a59SBob Pearson return -ENOMEM; 6498700e3e7SMoni Shoua } 6508700e3e7SMoni Shoua 651ae6e843fSBob Pearson send_wqe = queue_producer_addr(sq->queue, QUEUE_TYPE_TO_DRIVER); 652086f580cSBob Pearson init_send_wqe(qp, ibwr, mask, length, send_wqe); 6538700e3e7SMoni Shoua 654ae6e843fSBob Pearson queue_advance_producer(sq->queue, QUEUE_TYPE_TO_DRIVER); 6555bcf5a59SBob Pearson 65621adfa7aSBob Pearson spin_unlock_bh(&qp->sq.sq_lock); 6578700e3e7SMoni Shoua 6588700e3e7SMoni Shoua return 0; 6598700e3e7SMoni Shoua } 6608700e3e7SMoni Shoua 661d34ac5cdSBart Van Assche static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr, 662d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 6638700e3e7SMoni Shoua { 6648700e3e7SMoni Shoua int err = 0; 6658700e3e7SMoni Shoua unsigned int mask; 6668700e3e7SMoni Shoua unsigned int length = 0; 6678700e3e7SMoni Shoua int i; 6685f0b2a60SMikhail Malygin struct ib_send_wr *next; 6698700e3e7SMoni Shoua 6708700e3e7SMoni Shoua while (wr) { 6718700e3e7SMoni Shoua mask = wr_opcode_mask(wr->opcode, qp); 6728700e3e7SMoni Shoua if (unlikely(!mask)) { 6738700e3e7SMoni Shoua err = -EINVAL; 6748700e3e7SMoni Shoua *bad_wr = wr; 6758700e3e7SMoni Shoua break; 6768700e3e7SMoni Shoua } 6778700e3e7SMoni Shoua 6788700e3e7SMoni Shoua if (unlikely((wr->send_flags & IB_SEND_INLINE) && 6798700e3e7SMoni Shoua !(mask & WR_INLINE_MASK))) { 6808700e3e7SMoni Shoua err = -EINVAL; 6818700e3e7SMoni Shoua *bad_wr = wr; 6828700e3e7SMoni Shoua break; 6838700e3e7SMoni Shoua } 6848700e3e7SMoni Shoua 6855f0b2a60SMikhail Malygin next = wr->next; 6865f0b2a60SMikhail Malygin 6878700e3e7SMoni Shoua length = 0; 6888700e3e7SMoni Shoua for (i = 0; i < wr->num_sge; i++) 6898700e3e7SMoni Shoua length += wr->sg_list[i].length; 6908700e3e7SMoni Shoua 6918700e3e7SMoni Shoua err = post_one_send(qp, wr, mask, length); 6928700e3e7SMoni Shoua 6938700e3e7SMoni Shoua if (err) { 6948700e3e7SMoni Shoua *bad_wr = wr; 6958700e3e7SMoni Shoua break; 6968700e3e7SMoni Shoua } 6975f0b2a60SMikhail Malygin wr = next; 6988700e3e7SMoni Shoua } 6998700e3e7SMoni Shoua 7001661d3b0SAlexandru Moise rxe_run_task(&qp->req.task, 1); 7016f301e06SBart Van Assche if (unlikely(qp->req.state == QP_STATE_ERROR)) 7026f301e06SBart Van Assche rxe_run_task(&qp->comp.task, 1); 7038700e3e7SMoni Shoua 7048700e3e7SMoni Shoua return err; 7058700e3e7SMoni Shoua } 7068700e3e7SMoni Shoua 707d34ac5cdSBart Van Assche static int rxe_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, 708d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 709063af595SParav Pandit { 710063af595SParav Pandit struct rxe_qp *qp = to_rqp(ibqp); 711063af595SParav Pandit 712063af595SParav Pandit if (unlikely(!qp->valid)) { 713063af595SParav Pandit *bad_wr = wr; 714063af595SParav Pandit return -EINVAL; 715063af595SParav Pandit } 716063af595SParav Pandit 717063af595SParav Pandit if (unlikely(qp->req.state < QP_STATE_READY)) { 718063af595SParav Pandit *bad_wr = wr; 719063af595SParav Pandit return -EINVAL; 720063af595SParav Pandit } 721063af595SParav Pandit 722063af595SParav Pandit if (qp->is_user) { 723063af595SParav Pandit /* Utilize process context to do protocol processing */ 724063af595SParav Pandit rxe_run_task(&qp->req.task, 0); 725063af595SParav Pandit return 0; 726063af595SParav Pandit } else 727063af595SParav Pandit return rxe_post_send_kernel(qp, wr, bad_wr); 728063af595SParav Pandit } 729063af595SParav Pandit 730d34ac5cdSBart Van Assche static int rxe_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, 731d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr) 7328700e3e7SMoni Shoua { 7338700e3e7SMoni Shoua int err = 0; 7348700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 7358700e3e7SMoni Shoua struct rxe_rq *rq = &qp->rq; 7368700e3e7SMoni Shoua 7378700e3e7SMoni Shoua if (unlikely((qp_state(qp) < IB_QPS_INIT) || !qp->valid)) { 7388700e3e7SMoni Shoua *bad_wr = wr; 7398700e3e7SMoni Shoua err = -EINVAL; 7408700e3e7SMoni Shoua goto err1; 7418700e3e7SMoni Shoua } 7428700e3e7SMoni Shoua 7438700e3e7SMoni Shoua if (unlikely(qp->srq)) { 7448700e3e7SMoni Shoua *bad_wr = wr; 7458700e3e7SMoni Shoua err = -EINVAL; 7468700e3e7SMoni Shoua goto err1; 7478700e3e7SMoni Shoua } 7488700e3e7SMoni Shoua 74921adfa7aSBob Pearson spin_lock_bh(&rq->producer_lock); 7508700e3e7SMoni Shoua 7518700e3e7SMoni Shoua while (wr) { 7528700e3e7SMoni Shoua err = post_one_recv(rq, wr); 7538700e3e7SMoni Shoua if (unlikely(err)) { 7548700e3e7SMoni Shoua *bad_wr = wr; 7558700e3e7SMoni Shoua break; 7568700e3e7SMoni Shoua } 7578700e3e7SMoni Shoua wr = wr->next; 7588700e3e7SMoni Shoua } 7598700e3e7SMoni Shoua 76021adfa7aSBob Pearson spin_unlock_bh(&rq->producer_lock); 7618700e3e7SMoni Shoua 76212171971SVijay Immanuel if (qp->resp.state == QP_STATE_ERROR) 76312171971SVijay Immanuel rxe_run_task(&qp->resp.task, 1); 76412171971SVijay Immanuel 7658700e3e7SMoni Shoua err1: 7668700e3e7SMoni Shoua return err; 7678700e3e7SMoni Shoua } 7688700e3e7SMoni Shoua 769e39afe3dSLeon Romanovsky static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, 7708700e3e7SMoni Shoua struct ib_udata *udata) 7718700e3e7SMoni Shoua { 7728700e3e7SMoni Shoua int err; 773e39afe3dSLeon Romanovsky struct ib_device *dev = ibcq->device; 7748700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 775e39afe3dSLeon Romanovsky struct rxe_cq *cq = to_rcq(ibcq); 7760c43ab37SJason Gunthorpe struct rxe_create_cq_resp __user *uresp = NULL; 7770c43ab37SJason Gunthorpe 7780c43ab37SJason Gunthorpe if (udata) { 7790c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 780e39afe3dSLeon Romanovsky return -EINVAL; 7810c43ab37SJason Gunthorpe uresp = udata->outbuf; 7820c43ab37SJason Gunthorpe } 7838700e3e7SMoni Shoua 7848700e3e7SMoni Shoua if (attr->flags) 7851c407cb5SJason Gunthorpe return -EOPNOTSUPP; 7868700e3e7SMoni Shoua 787b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector); 7888700e3e7SMoni Shoua if (err) 789e39afe3dSLeon Romanovsky return err; 7908700e3e7SMoni Shoua 791ff23dfa1SShamir Rabinovitch err = rxe_cq_from_init(rxe, cq, attr->cqe, attr->comp_vector, udata, 792ff23dfa1SShamir Rabinovitch uresp); 7938700e3e7SMoni Shoua if (err) 794e39afe3dSLeon Romanovsky return err; 7958700e3e7SMoni Shoua 79691a42c5bSBob Pearson return rxe_add_to_pool(&rxe->cq_pool, cq); 7978700e3e7SMoni Shoua } 7988700e3e7SMoni Shoua 79943d781b9SLeon Romanovsky static int rxe_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) 8008700e3e7SMoni Shoua { 8018700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8028700e3e7SMoni Shoua 803bfc3ae05SAndrew Boyer rxe_cq_disable(cq); 804bfc3ae05SAndrew Boyer 8058700e3e7SMoni Shoua rxe_drop_ref(cq); 80643d781b9SLeon Romanovsky return 0; 8078700e3e7SMoni Shoua } 8088700e3e7SMoni Shoua 8098700e3e7SMoni Shoua static int rxe_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) 8108700e3e7SMoni Shoua { 8118700e3e7SMoni Shoua int err; 8128700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8138700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibcq->device); 8140c43ab37SJason Gunthorpe struct rxe_resize_cq_resp __user *uresp = NULL; 8150c43ab37SJason Gunthorpe 8160c43ab37SJason Gunthorpe if (udata) { 8170c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 8180c43ab37SJason Gunthorpe return -EINVAL; 8190c43ab37SJason Gunthorpe uresp = udata->outbuf; 8200c43ab37SJason Gunthorpe } 8218700e3e7SMoni Shoua 822b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, cq, cqe, 0); 8238700e3e7SMoni Shoua if (err) 8248700e3e7SMoni Shoua goto err1; 8258700e3e7SMoni Shoua 826ff23dfa1SShamir Rabinovitch err = rxe_cq_resize_queue(cq, cqe, uresp, udata); 8278700e3e7SMoni Shoua if (err) 8288700e3e7SMoni Shoua goto err1; 8298700e3e7SMoni Shoua 8308700e3e7SMoni Shoua return 0; 8318700e3e7SMoni Shoua 8328700e3e7SMoni Shoua err1: 8338700e3e7SMoni Shoua return err; 8348700e3e7SMoni Shoua } 8358700e3e7SMoni Shoua 8368700e3e7SMoni Shoua static int rxe_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc) 8378700e3e7SMoni Shoua { 8388700e3e7SMoni Shoua int i; 8398700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8408700e3e7SMoni Shoua struct rxe_cqe *cqe; 8418700e3e7SMoni Shoua 84221adfa7aSBob Pearson spin_lock_bh(&cq->cq_lock); 8438700e3e7SMoni Shoua for (i = 0; i < num_entries; i++) { 844ae6e843fSBob Pearson cqe = queue_head(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8458700e3e7SMoni Shoua if (!cqe) 8468700e3e7SMoni Shoua break; 8478700e3e7SMoni Shoua 8488700e3e7SMoni Shoua memcpy(wc++, &cqe->ibwc, sizeof(*wc)); 849ae6e843fSBob Pearson queue_advance_consumer(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8508700e3e7SMoni Shoua } 85121adfa7aSBob Pearson spin_unlock_bh(&cq->cq_lock); 8528700e3e7SMoni Shoua 8538700e3e7SMoni Shoua return i; 8548700e3e7SMoni Shoua } 8558700e3e7SMoni Shoua 8568700e3e7SMoni Shoua static int rxe_peek_cq(struct ib_cq *ibcq, int wc_cnt) 8578700e3e7SMoni Shoua { 8588700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8595bcf5a59SBob Pearson int count; 8605bcf5a59SBob Pearson 861ae6e843fSBob Pearson count = queue_count(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8628700e3e7SMoni Shoua 8638700e3e7SMoni Shoua return (count > wc_cnt) ? wc_cnt : count; 8648700e3e7SMoni Shoua } 8658700e3e7SMoni Shoua 8668700e3e7SMoni Shoua static int rxe_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) 8678700e3e7SMoni Shoua { 8688700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 869accacb8fSAndrew Boyer int ret = 0; 8705bcf5a59SBob Pearson int empty; 8718700e3e7SMoni Shoua 87221adfa7aSBob Pearson spin_lock_bh(&cq->cq_lock); 8738700e3e7SMoni Shoua if (cq->notify != IB_CQ_NEXT_COMP) 8748700e3e7SMoni Shoua cq->notify = flags & IB_CQ_SOLICITED_MASK; 8758700e3e7SMoni Shoua 876ae6e843fSBob Pearson empty = queue_empty(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8775bcf5a59SBob Pearson 8785bcf5a59SBob Pearson if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !empty) 879accacb8fSAndrew Boyer ret = 1; 880accacb8fSAndrew Boyer 88121adfa7aSBob Pearson spin_unlock_bh(&cq->cq_lock); 882accacb8fSAndrew Boyer 883accacb8fSAndrew Boyer return ret; 8848700e3e7SMoni Shoua } 8858700e3e7SMoni Shoua 8868700e3e7SMoni Shoua static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access) 8878700e3e7SMoni Shoua { 8888700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 8898700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 890364e282cSBob Pearson struct rxe_mr *mr; 8918700e3e7SMoni Shoua 8928700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 893293d8440SKamal Heib if (!mr) 894293d8440SKamal Heib return ERR_PTR(-ENOMEM); 8958700e3e7SMoni Shoua 8968700e3e7SMoni Shoua rxe_add_index(mr); 8978700e3e7SMoni Shoua rxe_add_ref(pd); 898364e282cSBob Pearson rxe_mr_init_dma(pd, access, mr); 8998700e3e7SMoni Shoua 9008700e3e7SMoni Shoua return &mr->ibmr; 9018700e3e7SMoni Shoua } 9028700e3e7SMoni Shoua 9038700e3e7SMoni Shoua static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, 9048700e3e7SMoni Shoua u64 start, 9058700e3e7SMoni Shoua u64 length, 9068700e3e7SMoni Shoua u64 iova, 9078700e3e7SMoni Shoua int access, struct ib_udata *udata) 9088700e3e7SMoni Shoua { 9098700e3e7SMoni Shoua int err; 9108700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 9118700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 912364e282cSBob Pearson struct rxe_mr *mr; 9138700e3e7SMoni Shoua 9148700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 9158700e3e7SMoni Shoua if (!mr) { 9168700e3e7SMoni Shoua err = -ENOMEM; 9178700e3e7SMoni Shoua goto err2; 9188700e3e7SMoni Shoua } 9198700e3e7SMoni Shoua 9208700e3e7SMoni Shoua rxe_add_index(mr); 9218700e3e7SMoni Shoua 9228700e3e7SMoni Shoua rxe_add_ref(pd); 9238700e3e7SMoni Shoua 924cd5b010fSLang Cheng err = rxe_mr_init_user(pd, start, length, iova, access, mr); 9258700e3e7SMoni Shoua if (err) 9268700e3e7SMoni Shoua goto err3; 9278700e3e7SMoni Shoua 9288700e3e7SMoni Shoua return &mr->ibmr; 9298700e3e7SMoni Shoua 9308700e3e7SMoni Shoua err3: 9318700e3e7SMoni Shoua rxe_drop_ref(pd); 9328700e3e7SMoni Shoua rxe_drop_index(mr); 9338700e3e7SMoni Shoua rxe_drop_ref(mr); 9348700e3e7SMoni Shoua err2: 9358700e3e7SMoni Shoua return ERR_PTR(err); 9368700e3e7SMoni Shoua } 9378700e3e7SMoni Shoua 938c4367a26SShamir Rabinovitch static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, 93942a3b153SGal Pressman u32 max_num_sg) 9408700e3e7SMoni Shoua { 9418700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 9428700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 943364e282cSBob Pearson struct rxe_mr *mr; 9448700e3e7SMoni Shoua int err; 9458700e3e7SMoni Shoua 9468700e3e7SMoni Shoua if (mr_type != IB_MR_TYPE_MEM_REG) 9478700e3e7SMoni Shoua return ERR_PTR(-EINVAL); 9488700e3e7SMoni Shoua 9498700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 9508700e3e7SMoni Shoua if (!mr) { 9518700e3e7SMoni Shoua err = -ENOMEM; 9528700e3e7SMoni Shoua goto err1; 9538700e3e7SMoni Shoua } 9548700e3e7SMoni Shoua 9558700e3e7SMoni Shoua rxe_add_index(mr); 9568700e3e7SMoni Shoua 9578700e3e7SMoni Shoua rxe_add_ref(pd); 9588700e3e7SMoni Shoua 959364e282cSBob Pearson err = rxe_mr_init_fast(pd, max_num_sg, mr); 9608700e3e7SMoni Shoua if (err) 9618700e3e7SMoni Shoua goto err2; 9628700e3e7SMoni Shoua 9638700e3e7SMoni Shoua return &mr->ibmr; 9648700e3e7SMoni Shoua 9658700e3e7SMoni Shoua err2: 9668700e3e7SMoni Shoua rxe_drop_ref(pd); 9678700e3e7SMoni Shoua rxe_drop_index(mr); 9688700e3e7SMoni Shoua rxe_drop_ref(mr); 9698700e3e7SMoni Shoua err1: 9708700e3e7SMoni Shoua return ERR_PTR(err); 9718700e3e7SMoni Shoua } 9728700e3e7SMoni Shoua 973647bf13cSBob Pearson /* build next_map_set from scatterlist 974647bf13cSBob Pearson * The IB_WR_REG_MR WR will swap map_sets 975647bf13cSBob Pearson */ 976e404f945SParav Pandit static int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, 977e404f945SParav Pandit int sg_nents, unsigned int *sg_offset) 9788700e3e7SMoni Shoua { 979364e282cSBob Pearson struct rxe_mr *mr = to_rmr(ibmr); 980647bf13cSBob Pearson struct rxe_map_set *set = mr->next_map_set; 9818700e3e7SMoni Shoua int n; 9828700e3e7SMoni Shoua 983647bf13cSBob Pearson set->nbuf = 0; 9848700e3e7SMoni Shoua 985647bf13cSBob Pearson n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_mr_set_page); 9868700e3e7SMoni Shoua 987647bf13cSBob Pearson set->va = ibmr->iova; 988647bf13cSBob Pearson set->iova = ibmr->iova; 989647bf13cSBob Pearson set->length = ibmr->length; 990647bf13cSBob Pearson set->page_shift = ilog2(ibmr->page_size); 991647bf13cSBob Pearson set->page_mask = ibmr->page_size - 1; 992647bf13cSBob Pearson set->offset = set->iova & set->page_mask; 9938700e3e7SMoni Shoua 9948700e3e7SMoni Shoua return n; 9958700e3e7SMoni Shoua } 9968700e3e7SMoni Shoua 9978700e3e7SMoni Shoua static int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) 9988700e3e7SMoni Shoua { 9998700e3e7SMoni Shoua int err; 10008700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 10018700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 10028700e3e7SMoni Shoua struct rxe_mc_grp *grp; 10038700e3e7SMoni Shoua 10048700e3e7SMoni Shoua /* takes a ref on grp if successful */ 10058700e3e7SMoni Shoua err = rxe_mcast_get_grp(rxe, mgid, &grp); 10068700e3e7SMoni Shoua if (err) 10078700e3e7SMoni Shoua return err; 10088700e3e7SMoni Shoua 10098700e3e7SMoni Shoua err = rxe_mcast_add_grp_elem(rxe, qp, grp); 10108700e3e7SMoni Shoua 10118700e3e7SMoni Shoua rxe_drop_ref(grp); 10128700e3e7SMoni Shoua return err; 10138700e3e7SMoni Shoua } 10148700e3e7SMoni Shoua 10158700e3e7SMoni Shoua static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) 10168700e3e7SMoni Shoua { 10178700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 10188700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 10198700e3e7SMoni Shoua 10208700e3e7SMoni Shoua return rxe_mcast_drop_grp_elem(rxe, qp, mgid); 10218700e3e7SMoni Shoua } 10228700e3e7SMoni Shoua 1023c05d2664SKamal Heib static ssize_t parent_show(struct device *device, 10248700e3e7SMoni Shoua struct device_attribute *attr, char *buf) 10258700e3e7SMoni Shoua { 102654747231SParav Pandit struct rxe_dev *rxe = 102754747231SParav Pandit rdma_device_to_drv_device(device, struct rxe_dev, ib_dev); 10288700e3e7SMoni Shoua 10291c7fd726SJoe Perches return sysfs_emit(buf, "%s\n", rxe_parent_name(rxe, 1)); 10308700e3e7SMoni Shoua } 10318700e3e7SMoni Shoua 1032c05d2664SKamal Heib static DEVICE_ATTR_RO(parent); 10338700e3e7SMoni Shoua 1034508a523fSParav Pandit static struct attribute *rxe_dev_attributes[] = { 1035508a523fSParav Pandit &dev_attr_parent.attr, 1036508a523fSParav Pandit NULL 1037508a523fSParav Pandit }; 1038508a523fSParav Pandit 1039508a523fSParav Pandit static const struct attribute_group rxe_attr_group = { 1040508a523fSParav Pandit .attrs = rxe_dev_attributes, 10418700e3e7SMoni Shoua }; 10428700e3e7SMoni Shoua 1043ca22354bSJason Gunthorpe static int rxe_enable_driver(struct ib_device *ib_dev) 1044ca22354bSJason Gunthorpe { 1045ca22354bSJason Gunthorpe struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev); 1046ca22354bSJason Gunthorpe 1047ca22354bSJason Gunthorpe rxe_set_port_state(rxe); 1048ca22354bSJason Gunthorpe dev_info(&rxe->ib_dev.dev, "added %s\n", netdev_name(rxe->ndev)); 1049ca22354bSJason Gunthorpe return 0; 1050ca22354bSJason Gunthorpe } 1051ca22354bSJason Gunthorpe 1052573efc4bSKamal Heib static const struct ib_device_ops rxe_dev_ops = { 10537a154142SJason Gunthorpe .owner = THIS_MODULE, 1054b9560a41SJason Gunthorpe .driver_id = RDMA_DRIVER_RXE, 105572c6ec18SJason Gunthorpe .uverbs_abi_ver = RXE_UVERBS_ABI_VERSION, 1056b9560a41SJason Gunthorpe 10574b5f4d3fSJason Gunthorpe .alloc_hw_port_stats = rxe_ib_alloc_hw_port_stats, 1058573efc4bSKamal Heib .alloc_mr = rxe_alloc_mr, 1059beec0239SBob Pearson .alloc_mw = rxe_alloc_mw, 1060573efc4bSKamal Heib .alloc_pd = rxe_alloc_pd, 1061573efc4bSKamal Heib .alloc_ucontext = rxe_alloc_ucontext, 1062573efc4bSKamal Heib .attach_mcast = rxe_attach_mcast, 1063573efc4bSKamal Heib .create_ah = rxe_create_ah, 1064573efc4bSKamal Heib .create_cq = rxe_create_cq, 1065573efc4bSKamal Heib .create_qp = rxe_create_qp, 1066573efc4bSKamal Heib .create_srq = rxe_create_srq, 1067676a80adSJason Gunthorpe .create_user_ah = rxe_create_ah, 1068c367074bSJason Gunthorpe .dealloc_driver = rxe_dealloc, 1069beec0239SBob Pearson .dealloc_mw = rxe_dealloc_mw, 1070573efc4bSKamal Heib .dealloc_pd = rxe_dealloc_pd, 1071573efc4bSKamal Heib .dealloc_ucontext = rxe_dealloc_ucontext, 1072573efc4bSKamal Heib .dereg_mr = rxe_dereg_mr, 1073573efc4bSKamal Heib .destroy_ah = rxe_destroy_ah, 1074573efc4bSKamal Heib .destroy_cq = rxe_destroy_cq, 1075573efc4bSKamal Heib .destroy_qp = rxe_destroy_qp, 1076573efc4bSKamal Heib .destroy_srq = rxe_destroy_srq, 1077573efc4bSKamal Heib .detach_mcast = rxe_detach_mcast, 1078915e4af5SJason Gunthorpe .device_group = &rxe_attr_group, 1079ca22354bSJason Gunthorpe .enable_driver = rxe_enable_driver, 1080573efc4bSKamal Heib .get_dma_mr = rxe_get_dma_mr, 1081573efc4bSKamal Heib .get_hw_stats = rxe_ib_get_hw_stats, 1082573efc4bSKamal Heib .get_link_layer = rxe_get_link_layer, 1083573efc4bSKamal Heib .get_port_immutable = rxe_port_immutable, 1084573efc4bSKamal Heib .map_mr_sg = rxe_map_mr_sg, 1085573efc4bSKamal Heib .mmap = rxe_mmap, 1086573efc4bSKamal Heib .modify_ah = rxe_modify_ah, 1087573efc4bSKamal Heib .modify_device = rxe_modify_device, 1088573efc4bSKamal Heib .modify_port = rxe_modify_port, 1089573efc4bSKamal Heib .modify_qp = rxe_modify_qp, 1090573efc4bSKamal Heib .modify_srq = rxe_modify_srq, 1091573efc4bSKamal Heib .peek_cq = rxe_peek_cq, 1092573efc4bSKamal Heib .poll_cq = rxe_poll_cq, 1093573efc4bSKamal Heib .post_recv = rxe_post_recv, 1094573efc4bSKamal Heib .post_send = rxe_post_send, 1095573efc4bSKamal Heib .post_srq_recv = rxe_post_srq_recv, 1096573efc4bSKamal Heib .query_ah = rxe_query_ah, 1097573efc4bSKamal Heib .query_device = rxe_query_device, 1098573efc4bSKamal Heib .query_pkey = rxe_query_pkey, 1099573efc4bSKamal Heib .query_port = rxe_query_port, 1100573efc4bSKamal Heib .query_qp = rxe_query_qp, 1101573efc4bSKamal Heib .query_srq = rxe_query_srq, 1102573efc4bSKamal Heib .reg_user_mr = rxe_reg_user_mr, 1103573efc4bSKamal Heib .req_notify_cq = rxe_req_notify_cq, 1104573efc4bSKamal Heib .resize_cq = rxe_resize_cq, 1105d3456914SLeon Romanovsky 1106d3456914SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ah, rxe_ah, ibah), 1107e39afe3dSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_cq, rxe_cq, ibcq), 110821a428a0SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_pd, rxe_pd, ibpd), 1109514aee66SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_qp, rxe_qp, ibqp), 111068e326deSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_srq, rxe_srq, ibsrq), 1111a2a074efSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ucontext, rxe_ucontext, ibuc), 1112364e282cSBob Pearson INIT_RDMA_OBJ_SIZE(ib_mw, rxe_mw, ibmw), 1113573efc4bSKamal Heib }; 1114573efc4bSKamal Heib 111566920e1bSSteve Wise int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name) 11168700e3e7SMoni Shoua { 11178700e3e7SMoni Shoua int err; 11188700e3e7SMoni Shoua struct ib_device *dev = &rxe->ib_dev; 11198700e3e7SMoni Shoua 1120dc78074aSBob Pearson strscpy(dev->node_desc, "rxe", sizeof(dev->node_desc)); 11218700e3e7SMoni Shoua 11228700e3e7SMoni Shoua dev->node_type = RDMA_NODE_IB_CA; 11238700e3e7SMoni Shoua dev->phys_port_cnt = 1; 112467cf3623SSagi Grimberg dev->num_comp_vectors = num_possible_cpus(); 11258700e3e7SMoni Shoua dev->local_dma_lkey = 0; 11264d6f2859SYuval Shaia addrconf_addr_eui48((unsigned char *)&dev->node_guid, 11274d6f2859SYuval Shaia rxe->ndev->dev_addr); 11288700e3e7SMoni Shoua 11295c419366SJason Gunthorpe dev->uverbs_cmd_mask |= BIT_ULL(IB_USER_VERBS_CMD_POST_SEND) | 11305c419366SJason Gunthorpe BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ); 11318700e3e7SMoni Shoua 1132573efc4bSKamal Heib ib_set_device_ops(dev, &rxe_dev_ops); 11334c173f59SJason Gunthorpe err = ib_device_set_netdev(&rxe->ib_dev, rxe->ndev, 1); 11344c173f59SJason Gunthorpe if (err) 11354c173f59SJason Gunthorpe return err; 11368700e3e7SMoni Shoua 1137add2b3b8SBob Pearson err = rxe_icrc_init(rxe); 1138add2b3b8SBob Pearson if (err) 1139add2b3b8SBob Pearson return err; 1140cee2688eSyonatanc 1141e0477b34SJason Gunthorpe err = ib_register_device(dev, ibdev_name, NULL); 1142c367074bSJason Gunthorpe if (err) 114361013828SKamal Heib pr_warn("%s failed with error %d\n", __func__, err); 1144cee2688eSyonatanc 1145ca22354bSJason Gunthorpe /* 1146ca22354bSJason Gunthorpe * Note that rxe may be invalid at this point if another thread 1147ca22354bSJason Gunthorpe * unregistered it. 1148ca22354bSJason Gunthorpe */ 11498700e3e7SMoni Shoua return err; 11508700e3e7SMoni Shoua } 1151