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); 18573a54932SBob Pearson ah->ah_num = ah->pelem.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 unsigned long flags; 3878700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3888700e3e7SMoni Shoua 3898700e3e7SMoni Shoua spin_lock_irqsave(&srq->rq.producer_lock, flags); 3908700e3e7SMoni Shoua 3918700e3e7SMoni Shoua while (wr) { 3928700e3e7SMoni Shoua err = post_one_recv(&srq->rq, wr); 3938700e3e7SMoni Shoua if (unlikely(err)) 3948700e3e7SMoni Shoua break; 3958700e3e7SMoni Shoua wr = wr->next; 3968700e3e7SMoni Shoua } 3978700e3e7SMoni Shoua 3988700e3e7SMoni Shoua spin_unlock_irqrestore(&srq->rq.producer_lock, flags); 3998700e3e7SMoni Shoua 4008700e3e7SMoni Shoua if (err) 4018700e3e7SMoni Shoua *bad_wr = wr; 4028700e3e7SMoni Shoua 4038700e3e7SMoni Shoua return err; 4048700e3e7SMoni Shoua } 4058700e3e7SMoni Shoua 406514aee66SLeon Romanovsky static int rxe_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init, 4078700e3e7SMoni Shoua struct ib_udata *udata) 4088700e3e7SMoni Shoua { 4098700e3e7SMoni Shoua int err; 410514aee66SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibqp->device); 411514aee66SLeon Romanovsky struct rxe_pd *pd = to_rpd(ibqp->pd); 412514aee66SLeon Romanovsky struct rxe_qp *qp = to_rqp(ibqp); 4130c43ab37SJason Gunthorpe struct rxe_create_qp_resp __user *uresp = NULL; 4140c43ab37SJason Gunthorpe 4150c43ab37SJason Gunthorpe if (udata) { 4160c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 417514aee66SLeon Romanovsky return -EINVAL; 4180c43ab37SJason Gunthorpe uresp = udata->outbuf; 4190c43ab37SJason Gunthorpe } 4208700e3e7SMoni Shoua 4211f11a761SJason Gunthorpe if (init->create_flags) 422514aee66SLeon Romanovsky return -EOPNOTSUPP; 4231f11a761SJason Gunthorpe 4248700e3e7SMoni Shoua err = rxe_qp_chk_init(rxe, init); 4258700e3e7SMoni Shoua if (err) 426514aee66SLeon Romanovsky return err; 4278700e3e7SMoni Shoua 4288700e3e7SMoni Shoua if (udata) { 429514aee66SLeon Romanovsky if (udata->inlen) 430514aee66SLeon Romanovsky return -EINVAL; 431514aee66SLeon Romanovsky 4325bcf5a59SBob Pearson qp->is_user = true; 4335bcf5a59SBob Pearson } else { 4345bcf5a59SBob Pearson qp->is_user = false; 4358700e3e7SMoni Shoua } 4368700e3e7SMoni Shoua 437514aee66SLeon Romanovsky err = rxe_add_to_pool(&rxe->qp_pool, qp); 4388700e3e7SMoni Shoua if (err) 439514aee66SLeon Romanovsky return err; 4408700e3e7SMoni Shoua 441514aee66SLeon Romanovsky rxe_add_index(qp); 442514aee66SLeon Romanovsky err = rxe_qp_from_init(rxe, qp, pd, init, uresp, ibqp->pd, udata); 443514aee66SLeon Romanovsky if (err) 444514aee66SLeon Romanovsky goto qp_init; 4458700e3e7SMoni Shoua 446514aee66SLeon Romanovsky return 0; 447514aee66SLeon Romanovsky 448514aee66SLeon Romanovsky qp_init: 4498700e3e7SMoni Shoua rxe_drop_index(qp); 4508700e3e7SMoni Shoua rxe_drop_ref(qp); 451514aee66SLeon Romanovsky return err; 4528700e3e7SMoni Shoua } 4538700e3e7SMoni Shoua 4548700e3e7SMoni Shoua static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 4558700e3e7SMoni Shoua int mask, struct ib_udata *udata) 4568700e3e7SMoni Shoua { 4578700e3e7SMoni Shoua int err; 4588700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 4598700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4608700e3e7SMoni Shoua 46126e990baSJason Gunthorpe if (mask & ~IB_QP_ATTR_STANDARD_BITS) 46226e990baSJason Gunthorpe return -EOPNOTSUPP; 46326e990baSJason Gunthorpe 4648700e3e7SMoni Shoua err = rxe_qp_chk_attr(rxe, qp, attr, mask); 4658700e3e7SMoni Shoua if (err) 4668700e3e7SMoni Shoua goto err1; 4678700e3e7SMoni Shoua 4688700e3e7SMoni Shoua err = rxe_qp_from_attr(qp, attr, mask, udata); 4698700e3e7SMoni Shoua if (err) 4708700e3e7SMoni Shoua goto err1; 4718700e3e7SMoni Shoua 4728700e3e7SMoni Shoua return 0; 4738700e3e7SMoni Shoua 4748700e3e7SMoni Shoua err1: 4758700e3e7SMoni Shoua return err; 4768700e3e7SMoni Shoua } 4778700e3e7SMoni Shoua 4788700e3e7SMoni Shoua static int rxe_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 4798700e3e7SMoni Shoua int mask, struct ib_qp_init_attr *init) 4808700e3e7SMoni Shoua { 4818700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4828700e3e7SMoni Shoua 4838700e3e7SMoni Shoua rxe_qp_to_init(qp, init); 4848700e3e7SMoni Shoua rxe_qp_to_attr(qp, attr, mask); 4858700e3e7SMoni Shoua 4868700e3e7SMoni Shoua return 0; 4878700e3e7SMoni Shoua } 4888700e3e7SMoni Shoua 489c4367a26SShamir Rabinovitch static int rxe_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) 4908700e3e7SMoni Shoua { 4918700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4928700e3e7SMoni Shoua 4938700e3e7SMoni Shoua rxe_qp_destroy(qp); 4948700e3e7SMoni Shoua rxe_drop_index(qp); 4958700e3e7SMoni Shoua rxe_drop_ref(qp); 4968700e3e7SMoni Shoua return 0; 4978700e3e7SMoni Shoua } 4988700e3e7SMoni Shoua 499f696bf6dSBart Van Assche static int validate_send_wr(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 5008700e3e7SMoni Shoua unsigned int mask, unsigned int length) 5018700e3e7SMoni Shoua { 5028700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 5038700e3e7SMoni Shoua struct rxe_sq *sq = &qp->sq; 5048700e3e7SMoni Shoua 5058700e3e7SMoni Shoua if (unlikely(num_sge > sq->max_sge)) 5068700e3e7SMoni Shoua goto err1; 5078700e3e7SMoni Shoua 5088700e3e7SMoni Shoua if (unlikely(mask & WR_ATOMIC_MASK)) { 5098700e3e7SMoni Shoua if (length < 8) 5108700e3e7SMoni Shoua goto err1; 5118700e3e7SMoni Shoua 5128700e3e7SMoni Shoua if (atomic_wr(ibwr)->remote_addr & 0x7) 5138700e3e7SMoni Shoua goto err1; 5148700e3e7SMoni Shoua } 5158700e3e7SMoni Shoua 5168700e3e7SMoni Shoua if (unlikely((ibwr->send_flags & IB_SEND_INLINE) && 5178700e3e7SMoni Shoua (length > sq->max_inline))) 5188700e3e7SMoni Shoua goto err1; 5198700e3e7SMoni Shoua 5208700e3e7SMoni Shoua return 0; 5218700e3e7SMoni Shoua 5228700e3e7SMoni Shoua err1: 5238700e3e7SMoni Shoua return -EINVAL; 5248700e3e7SMoni Shoua } 5258700e3e7SMoni Shoua 5268700e3e7SMoni Shoua static void init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr, 527f696bf6dSBart Van Assche const struct ib_send_wr *ibwr) 5288700e3e7SMoni Shoua { 5298700e3e7SMoni Shoua wr->wr_id = ibwr->wr_id; 5308700e3e7SMoni Shoua wr->num_sge = ibwr->num_sge; 5318700e3e7SMoni Shoua wr->opcode = ibwr->opcode; 5328700e3e7SMoni Shoua wr->send_flags = ibwr->send_flags; 5338700e3e7SMoni Shoua 5348700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_UD || 5358700e3e7SMoni Shoua qp_type(qp) == IB_QPT_SMI || 5368700e3e7SMoni Shoua qp_type(qp) == IB_QPT_GSI) { 537*3b87e082SBob Pearson struct ib_ah *ibah = ud_wr(ibwr)->ah; 538*3b87e082SBob Pearson 5398700e3e7SMoni Shoua wr->wr.ud.remote_qpn = ud_wr(ibwr)->remote_qpn; 5408700e3e7SMoni Shoua wr->wr.ud.remote_qkey = ud_wr(ibwr)->remote_qkey; 541*3b87e082SBob Pearson wr->wr.ud.ah_num = to_rah(ibah)->ah_num; 5428700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_GSI) 5438700e3e7SMoni Shoua wr->wr.ud.pkey_index = ud_wr(ibwr)->pkey_index; 5448700e3e7SMoni Shoua if (wr->opcode == IB_WR_SEND_WITH_IMM) 5458700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 5468700e3e7SMoni Shoua } else { 5478700e3e7SMoni Shoua switch (wr->opcode) { 5488700e3e7SMoni Shoua case IB_WR_RDMA_WRITE_WITH_IMM: 5498700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 550df561f66SGustavo A. R. Silva fallthrough; 5518700e3e7SMoni Shoua case IB_WR_RDMA_READ: 5528700e3e7SMoni Shoua case IB_WR_RDMA_WRITE: 5538700e3e7SMoni Shoua wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr; 5548700e3e7SMoni Shoua wr->wr.rdma.rkey = rdma_wr(ibwr)->rkey; 5558700e3e7SMoni Shoua break; 5568700e3e7SMoni Shoua case IB_WR_SEND_WITH_IMM: 5578700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 5588700e3e7SMoni Shoua break; 5598700e3e7SMoni Shoua case IB_WR_SEND_WITH_INV: 5608700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 5618700e3e7SMoni Shoua break; 5628700e3e7SMoni Shoua case IB_WR_ATOMIC_CMP_AND_SWP: 5638700e3e7SMoni Shoua case IB_WR_ATOMIC_FETCH_AND_ADD: 5648700e3e7SMoni Shoua wr->wr.atomic.remote_addr = 5658700e3e7SMoni Shoua atomic_wr(ibwr)->remote_addr; 5668700e3e7SMoni Shoua wr->wr.atomic.compare_add = 5678700e3e7SMoni Shoua atomic_wr(ibwr)->compare_add; 5688700e3e7SMoni Shoua wr->wr.atomic.swap = atomic_wr(ibwr)->swap; 5698700e3e7SMoni Shoua wr->wr.atomic.rkey = atomic_wr(ibwr)->rkey; 5708700e3e7SMoni Shoua break; 5718700e3e7SMoni Shoua case IB_WR_LOCAL_INV: 5728700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 5738700e3e7SMoni Shoua break; 5748700e3e7SMoni Shoua case IB_WR_REG_MR: 5758700e3e7SMoni Shoua wr->wr.reg.mr = reg_wr(ibwr)->mr; 5768700e3e7SMoni Shoua wr->wr.reg.key = reg_wr(ibwr)->key; 5778700e3e7SMoni Shoua wr->wr.reg.access = reg_wr(ibwr)->access; 5788700e3e7SMoni Shoua break; 5798700e3e7SMoni Shoua default: 5808700e3e7SMoni Shoua break; 5818700e3e7SMoni Shoua } 5828700e3e7SMoni Shoua } 5838700e3e7SMoni Shoua } 5848700e3e7SMoni Shoua 585086f580cSBob Pearson static void copy_inline_data_to_wqe(struct rxe_send_wqe *wqe, 586086f580cSBob Pearson const struct ib_send_wr *ibwr) 587086f580cSBob Pearson { 588086f580cSBob Pearson struct ib_sge *sge = ibwr->sg_list; 589086f580cSBob Pearson u8 *p = wqe->dma.inline_data; 590086f580cSBob Pearson int i; 591086f580cSBob Pearson 592086f580cSBob Pearson for (i = 0; i < ibwr->num_sge; i++, sge++) { 593086f580cSBob Pearson memcpy(p, (void *)(uintptr_t)sge->addr, sge->length); 594086f580cSBob Pearson p += sge->length; 595086f580cSBob Pearson } 596086f580cSBob Pearson } 597086f580cSBob Pearson 598086f580cSBob Pearson static void init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 5998700e3e7SMoni Shoua unsigned int mask, unsigned int length, 6008700e3e7SMoni Shoua struct rxe_send_wqe *wqe) 6018700e3e7SMoni Shoua { 6028700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 6038700e3e7SMoni Shoua 6048700e3e7SMoni Shoua init_send_wr(qp, &wqe->wr, ibwr); 6058700e3e7SMoni Shoua 606dc78074aSBob Pearson /* local operation */ 607886441fbSBob Pearson if (unlikely(mask & WR_LOCAL_OP_MASK)) { 608dc78074aSBob Pearson wqe->mask = mask; 609dc78074aSBob Pearson wqe->state = wqe_state_posted; 610086f580cSBob Pearson return; 611dc78074aSBob Pearson } 612dc78074aSBob Pearson 613086f580cSBob Pearson if (unlikely(ibwr->send_flags & IB_SEND_INLINE)) 614086f580cSBob Pearson copy_inline_data_to_wqe(wqe, ibwr); 615086f580cSBob Pearson else 6168700e3e7SMoni Shoua memcpy(wqe->dma.sge, ibwr->sg_list, 6178700e3e7SMoni Shoua num_sge * sizeof(struct ib_sge)); 6188700e3e7SMoni Shoua 619a6544a62SBart Van Assche wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr : 620a6544a62SBart Van Assche mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0; 6218700e3e7SMoni Shoua wqe->mask = mask; 6228700e3e7SMoni Shoua wqe->dma.length = length; 6238700e3e7SMoni Shoua wqe->dma.resid = length; 6248700e3e7SMoni Shoua wqe->dma.num_sge = num_sge; 6258700e3e7SMoni Shoua wqe->dma.cur_sge = 0; 6268700e3e7SMoni Shoua wqe->dma.sge_offset = 0; 6278700e3e7SMoni Shoua wqe->state = wqe_state_posted; 6288700e3e7SMoni Shoua wqe->ssn = atomic_add_return(1, &qp->ssn); 6298700e3e7SMoni Shoua } 6308700e3e7SMoni Shoua 631f696bf6dSBart Van Assche static int post_one_send(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 632e404f945SParav Pandit unsigned int mask, u32 length) 6338700e3e7SMoni Shoua { 6348700e3e7SMoni Shoua int err; 6358700e3e7SMoni Shoua struct rxe_sq *sq = &qp->sq; 6368700e3e7SMoni Shoua struct rxe_send_wqe *send_wqe; 6378700e3e7SMoni Shoua unsigned long flags; 6385bcf5a59SBob Pearson int full; 6398700e3e7SMoni Shoua 6408700e3e7SMoni Shoua err = validate_send_wr(qp, ibwr, mask, length); 6418700e3e7SMoni Shoua if (err) 6428700e3e7SMoni Shoua return err; 6438700e3e7SMoni Shoua 6448700e3e7SMoni Shoua spin_lock_irqsave(&qp->sq.sq_lock, flags); 6458700e3e7SMoni Shoua 646ae6e843fSBob Pearson full = queue_full(sq->queue, QUEUE_TYPE_TO_DRIVER); 6475bcf5a59SBob Pearson 6485bcf5a59SBob Pearson if (unlikely(full)) { 6495bcf5a59SBob Pearson spin_unlock_irqrestore(&qp->sq.sq_lock, flags); 6505bcf5a59SBob Pearson return -ENOMEM; 6518700e3e7SMoni Shoua } 6528700e3e7SMoni Shoua 653ae6e843fSBob Pearson send_wqe = queue_producer_addr(sq->queue, QUEUE_TYPE_TO_DRIVER); 654086f580cSBob Pearson init_send_wqe(qp, ibwr, mask, length, send_wqe); 6558700e3e7SMoni Shoua 656ae6e843fSBob Pearson queue_advance_producer(sq->queue, QUEUE_TYPE_TO_DRIVER); 6575bcf5a59SBob Pearson 6588700e3e7SMoni Shoua spin_unlock_irqrestore(&qp->sq.sq_lock, flags); 6598700e3e7SMoni Shoua 6608700e3e7SMoni Shoua return 0; 6618700e3e7SMoni Shoua } 6628700e3e7SMoni Shoua 663d34ac5cdSBart Van Assche static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr, 664d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 6658700e3e7SMoni Shoua { 6668700e3e7SMoni Shoua int err = 0; 6678700e3e7SMoni Shoua unsigned int mask; 6688700e3e7SMoni Shoua unsigned int length = 0; 6698700e3e7SMoni Shoua int i; 6705f0b2a60SMikhail Malygin struct ib_send_wr *next; 6718700e3e7SMoni Shoua 6728700e3e7SMoni Shoua while (wr) { 6738700e3e7SMoni Shoua mask = wr_opcode_mask(wr->opcode, qp); 6748700e3e7SMoni Shoua if (unlikely(!mask)) { 6758700e3e7SMoni Shoua err = -EINVAL; 6768700e3e7SMoni Shoua *bad_wr = wr; 6778700e3e7SMoni Shoua break; 6788700e3e7SMoni Shoua } 6798700e3e7SMoni Shoua 6808700e3e7SMoni Shoua if (unlikely((wr->send_flags & IB_SEND_INLINE) && 6818700e3e7SMoni Shoua !(mask & WR_INLINE_MASK))) { 6828700e3e7SMoni Shoua err = -EINVAL; 6838700e3e7SMoni Shoua *bad_wr = wr; 6848700e3e7SMoni Shoua break; 6858700e3e7SMoni Shoua } 6868700e3e7SMoni Shoua 6875f0b2a60SMikhail Malygin next = wr->next; 6885f0b2a60SMikhail Malygin 6898700e3e7SMoni Shoua length = 0; 6908700e3e7SMoni Shoua for (i = 0; i < wr->num_sge; i++) 6918700e3e7SMoni Shoua length += wr->sg_list[i].length; 6928700e3e7SMoni Shoua 6938700e3e7SMoni Shoua err = post_one_send(qp, wr, mask, length); 6948700e3e7SMoni Shoua 6958700e3e7SMoni Shoua if (err) { 6968700e3e7SMoni Shoua *bad_wr = wr; 6978700e3e7SMoni Shoua break; 6988700e3e7SMoni Shoua } 6995f0b2a60SMikhail Malygin wr = next; 7008700e3e7SMoni Shoua } 7018700e3e7SMoni Shoua 7021661d3b0SAlexandru Moise rxe_run_task(&qp->req.task, 1); 7036f301e06SBart Van Assche if (unlikely(qp->req.state == QP_STATE_ERROR)) 7046f301e06SBart Van Assche rxe_run_task(&qp->comp.task, 1); 7058700e3e7SMoni Shoua 7068700e3e7SMoni Shoua return err; 7078700e3e7SMoni Shoua } 7088700e3e7SMoni Shoua 709d34ac5cdSBart Van Assche static int rxe_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, 710d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 711063af595SParav Pandit { 712063af595SParav Pandit struct rxe_qp *qp = to_rqp(ibqp); 713063af595SParav Pandit 714063af595SParav Pandit if (unlikely(!qp->valid)) { 715063af595SParav Pandit *bad_wr = wr; 716063af595SParav Pandit return -EINVAL; 717063af595SParav Pandit } 718063af595SParav Pandit 719063af595SParav Pandit if (unlikely(qp->req.state < QP_STATE_READY)) { 720063af595SParav Pandit *bad_wr = wr; 721063af595SParav Pandit return -EINVAL; 722063af595SParav Pandit } 723063af595SParav Pandit 724063af595SParav Pandit if (qp->is_user) { 725063af595SParav Pandit /* Utilize process context to do protocol processing */ 726063af595SParav Pandit rxe_run_task(&qp->req.task, 0); 727063af595SParav Pandit return 0; 728063af595SParav Pandit } else 729063af595SParav Pandit return rxe_post_send_kernel(qp, wr, bad_wr); 730063af595SParav Pandit } 731063af595SParav Pandit 732d34ac5cdSBart Van Assche static int rxe_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, 733d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr) 7348700e3e7SMoni Shoua { 7358700e3e7SMoni Shoua int err = 0; 7368700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 7378700e3e7SMoni Shoua struct rxe_rq *rq = &qp->rq; 7388700e3e7SMoni Shoua unsigned long flags; 7398700e3e7SMoni Shoua 7408700e3e7SMoni Shoua if (unlikely((qp_state(qp) < IB_QPS_INIT) || !qp->valid)) { 7418700e3e7SMoni Shoua *bad_wr = wr; 7428700e3e7SMoni Shoua err = -EINVAL; 7438700e3e7SMoni Shoua goto err1; 7448700e3e7SMoni Shoua } 7458700e3e7SMoni Shoua 7468700e3e7SMoni Shoua if (unlikely(qp->srq)) { 7478700e3e7SMoni Shoua *bad_wr = wr; 7488700e3e7SMoni Shoua err = -EINVAL; 7498700e3e7SMoni Shoua goto err1; 7508700e3e7SMoni Shoua } 7518700e3e7SMoni Shoua 7528700e3e7SMoni Shoua spin_lock_irqsave(&rq->producer_lock, flags); 7538700e3e7SMoni Shoua 7548700e3e7SMoni Shoua while (wr) { 7558700e3e7SMoni Shoua err = post_one_recv(rq, wr); 7568700e3e7SMoni Shoua if (unlikely(err)) { 7578700e3e7SMoni Shoua *bad_wr = wr; 7588700e3e7SMoni Shoua break; 7598700e3e7SMoni Shoua } 7608700e3e7SMoni Shoua wr = wr->next; 7618700e3e7SMoni Shoua } 7628700e3e7SMoni Shoua 7638700e3e7SMoni Shoua spin_unlock_irqrestore(&rq->producer_lock, flags); 7648700e3e7SMoni Shoua 76512171971SVijay Immanuel if (qp->resp.state == QP_STATE_ERROR) 76612171971SVijay Immanuel rxe_run_task(&qp->resp.task, 1); 76712171971SVijay Immanuel 7688700e3e7SMoni Shoua err1: 7698700e3e7SMoni Shoua return err; 7708700e3e7SMoni Shoua } 7718700e3e7SMoni Shoua 772e39afe3dSLeon Romanovsky static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, 7738700e3e7SMoni Shoua struct ib_udata *udata) 7748700e3e7SMoni Shoua { 7758700e3e7SMoni Shoua int err; 776e39afe3dSLeon Romanovsky struct ib_device *dev = ibcq->device; 7778700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 778e39afe3dSLeon Romanovsky struct rxe_cq *cq = to_rcq(ibcq); 7790c43ab37SJason Gunthorpe struct rxe_create_cq_resp __user *uresp = NULL; 7800c43ab37SJason Gunthorpe 7810c43ab37SJason Gunthorpe if (udata) { 7820c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 783e39afe3dSLeon Romanovsky return -EINVAL; 7840c43ab37SJason Gunthorpe uresp = udata->outbuf; 7850c43ab37SJason Gunthorpe } 7868700e3e7SMoni Shoua 7878700e3e7SMoni Shoua if (attr->flags) 7881c407cb5SJason Gunthorpe return -EOPNOTSUPP; 7898700e3e7SMoni Shoua 790b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector); 7918700e3e7SMoni Shoua if (err) 792e39afe3dSLeon Romanovsky return err; 7938700e3e7SMoni Shoua 794ff23dfa1SShamir Rabinovitch err = rxe_cq_from_init(rxe, cq, attr->cqe, attr->comp_vector, udata, 795ff23dfa1SShamir Rabinovitch uresp); 7968700e3e7SMoni Shoua if (err) 797e39afe3dSLeon Romanovsky return err; 7988700e3e7SMoni Shoua 79991a42c5bSBob Pearson return rxe_add_to_pool(&rxe->cq_pool, cq); 8008700e3e7SMoni Shoua } 8018700e3e7SMoni Shoua 80243d781b9SLeon Romanovsky static int rxe_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) 8038700e3e7SMoni Shoua { 8048700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8058700e3e7SMoni Shoua 806bfc3ae05SAndrew Boyer rxe_cq_disable(cq); 807bfc3ae05SAndrew Boyer 8088700e3e7SMoni Shoua rxe_drop_ref(cq); 80943d781b9SLeon Romanovsky return 0; 8108700e3e7SMoni Shoua } 8118700e3e7SMoni Shoua 8128700e3e7SMoni Shoua static int rxe_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) 8138700e3e7SMoni Shoua { 8148700e3e7SMoni Shoua int err; 8158700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8168700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibcq->device); 8170c43ab37SJason Gunthorpe struct rxe_resize_cq_resp __user *uresp = NULL; 8180c43ab37SJason Gunthorpe 8190c43ab37SJason Gunthorpe if (udata) { 8200c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 8210c43ab37SJason Gunthorpe return -EINVAL; 8220c43ab37SJason Gunthorpe uresp = udata->outbuf; 8230c43ab37SJason Gunthorpe } 8248700e3e7SMoni Shoua 825b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, cq, cqe, 0); 8268700e3e7SMoni Shoua if (err) 8278700e3e7SMoni Shoua goto err1; 8288700e3e7SMoni Shoua 829ff23dfa1SShamir Rabinovitch err = rxe_cq_resize_queue(cq, cqe, uresp, udata); 8308700e3e7SMoni Shoua if (err) 8318700e3e7SMoni Shoua goto err1; 8328700e3e7SMoni Shoua 8338700e3e7SMoni Shoua return 0; 8348700e3e7SMoni Shoua 8358700e3e7SMoni Shoua err1: 8368700e3e7SMoni Shoua return err; 8378700e3e7SMoni Shoua } 8388700e3e7SMoni Shoua 8398700e3e7SMoni Shoua static int rxe_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc) 8408700e3e7SMoni Shoua { 8418700e3e7SMoni Shoua int i; 8428700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8438700e3e7SMoni Shoua struct rxe_cqe *cqe; 8448700e3e7SMoni Shoua unsigned long flags; 8458700e3e7SMoni Shoua 8468700e3e7SMoni Shoua spin_lock_irqsave(&cq->cq_lock, flags); 8478700e3e7SMoni Shoua for (i = 0; i < num_entries; i++) { 848ae6e843fSBob Pearson cqe = queue_head(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8498700e3e7SMoni Shoua if (!cqe) 8508700e3e7SMoni Shoua break; 8518700e3e7SMoni Shoua 8528700e3e7SMoni Shoua memcpy(wc++, &cqe->ibwc, sizeof(*wc)); 853ae6e843fSBob Pearson queue_advance_consumer(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8548700e3e7SMoni Shoua } 8558700e3e7SMoni Shoua spin_unlock_irqrestore(&cq->cq_lock, flags); 8568700e3e7SMoni Shoua 8578700e3e7SMoni Shoua return i; 8588700e3e7SMoni Shoua } 8598700e3e7SMoni Shoua 8608700e3e7SMoni Shoua static int rxe_peek_cq(struct ib_cq *ibcq, int wc_cnt) 8618700e3e7SMoni Shoua { 8628700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8635bcf5a59SBob Pearson int count; 8645bcf5a59SBob Pearson 865ae6e843fSBob Pearson count = queue_count(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8668700e3e7SMoni Shoua 8678700e3e7SMoni Shoua return (count > wc_cnt) ? wc_cnt : count; 8688700e3e7SMoni Shoua } 8698700e3e7SMoni Shoua 8708700e3e7SMoni Shoua static int rxe_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) 8718700e3e7SMoni Shoua { 8728700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 873accacb8fSAndrew Boyer unsigned long irq_flags; 874accacb8fSAndrew Boyer int ret = 0; 8755bcf5a59SBob Pearson int empty; 8768700e3e7SMoni Shoua 877accacb8fSAndrew Boyer spin_lock_irqsave(&cq->cq_lock, irq_flags); 8788700e3e7SMoni Shoua if (cq->notify != IB_CQ_NEXT_COMP) 8798700e3e7SMoni Shoua cq->notify = flags & IB_CQ_SOLICITED_MASK; 8808700e3e7SMoni Shoua 881ae6e843fSBob Pearson empty = queue_empty(cq->queue, QUEUE_TYPE_FROM_DRIVER); 8825bcf5a59SBob Pearson 8835bcf5a59SBob Pearson if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !empty) 884accacb8fSAndrew Boyer ret = 1; 885accacb8fSAndrew Boyer 886accacb8fSAndrew Boyer spin_unlock_irqrestore(&cq->cq_lock, irq_flags); 887accacb8fSAndrew Boyer 888accacb8fSAndrew Boyer return ret; 8898700e3e7SMoni Shoua } 8908700e3e7SMoni Shoua 8918700e3e7SMoni Shoua static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access) 8928700e3e7SMoni Shoua { 8938700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 8948700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 895364e282cSBob Pearson struct rxe_mr *mr; 8968700e3e7SMoni Shoua 8978700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 898293d8440SKamal Heib if (!mr) 899293d8440SKamal Heib return ERR_PTR(-ENOMEM); 9008700e3e7SMoni Shoua 9018700e3e7SMoni Shoua rxe_add_index(mr); 9028700e3e7SMoni Shoua rxe_add_ref(pd); 903364e282cSBob Pearson rxe_mr_init_dma(pd, access, mr); 9048700e3e7SMoni Shoua 9058700e3e7SMoni Shoua return &mr->ibmr; 9068700e3e7SMoni Shoua } 9078700e3e7SMoni Shoua 9088700e3e7SMoni Shoua static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, 9098700e3e7SMoni Shoua u64 start, 9108700e3e7SMoni Shoua u64 length, 9118700e3e7SMoni Shoua u64 iova, 9128700e3e7SMoni Shoua int access, struct ib_udata *udata) 9138700e3e7SMoni Shoua { 9148700e3e7SMoni Shoua int err; 9158700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 9168700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 917364e282cSBob Pearson struct rxe_mr *mr; 9188700e3e7SMoni Shoua 9198700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 9208700e3e7SMoni Shoua if (!mr) { 9218700e3e7SMoni Shoua err = -ENOMEM; 9228700e3e7SMoni Shoua goto err2; 9238700e3e7SMoni Shoua } 9248700e3e7SMoni Shoua 9258700e3e7SMoni Shoua rxe_add_index(mr); 9268700e3e7SMoni Shoua 9278700e3e7SMoni Shoua rxe_add_ref(pd); 9288700e3e7SMoni Shoua 929cd5b010fSLang Cheng err = rxe_mr_init_user(pd, start, length, iova, access, mr); 9308700e3e7SMoni Shoua if (err) 9318700e3e7SMoni Shoua goto err3; 9328700e3e7SMoni Shoua 9338700e3e7SMoni Shoua return &mr->ibmr; 9348700e3e7SMoni Shoua 9358700e3e7SMoni Shoua err3: 9368700e3e7SMoni Shoua rxe_drop_ref(pd); 9378700e3e7SMoni Shoua rxe_drop_index(mr); 9388700e3e7SMoni Shoua rxe_drop_ref(mr); 9398700e3e7SMoni Shoua err2: 9408700e3e7SMoni Shoua return ERR_PTR(err); 9418700e3e7SMoni Shoua } 9428700e3e7SMoni Shoua 943c4367a26SShamir Rabinovitch static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, 94442a3b153SGal Pressman u32 max_num_sg) 9458700e3e7SMoni Shoua { 9468700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 9478700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 948364e282cSBob Pearson struct rxe_mr *mr; 9498700e3e7SMoni Shoua int err; 9508700e3e7SMoni Shoua 9518700e3e7SMoni Shoua if (mr_type != IB_MR_TYPE_MEM_REG) 9528700e3e7SMoni Shoua return ERR_PTR(-EINVAL); 9538700e3e7SMoni Shoua 9548700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 9558700e3e7SMoni Shoua if (!mr) { 9568700e3e7SMoni Shoua err = -ENOMEM; 9578700e3e7SMoni Shoua goto err1; 9588700e3e7SMoni Shoua } 9598700e3e7SMoni Shoua 9608700e3e7SMoni Shoua rxe_add_index(mr); 9618700e3e7SMoni Shoua 9628700e3e7SMoni Shoua rxe_add_ref(pd); 9638700e3e7SMoni Shoua 964364e282cSBob Pearson err = rxe_mr_init_fast(pd, max_num_sg, mr); 9658700e3e7SMoni Shoua if (err) 9668700e3e7SMoni Shoua goto err2; 9678700e3e7SMoni Shoua 9688700e3e7SMoni Shoua return &mr->ibmr; 9698700e3e7SMoni Shoua 9708700e3e7SMoni Shoua err2: 9718700e3e7SMoni Shoua rxe_drop_ref(pd); 9728700e3e7SMoni Shoua rxe_drop_index(mr); 9738700e3e7SMoni Shoua rxe_drop_ref(mr); 9748700e3e7SMoni Shoua err1: 9758700e3e7SMoni Shoua return ERR_PTR(err); 9768700e3e7SMoni Shoua } 9778700e3e7SMoni Shoua 978647bf13cSBob Pearson /* build next_map_set from scatterlist 979647bf13cSBob Pearson * The IB_WR_REG_MR WR will swap map_sets 980647bf13cSBob Pearson */ 981e404f945SParav Pandit static int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, 982e404f945SParav Pandit int sg_nents, unsigned int *sg_offset) 9838700e3e7SMoni Shoua { 984364e282cSBob Pearson struct rxe_mr *mr = to_rmr(ibmr); 985647bf13cSBob Pearson struct rxe_map_set *set = mr->next_map_set; 9868700e3e7SMoni Shoua int n; 9878700e3e7SMoni Shoua 988647bf13cSBob Pearson set->nbuf = 0; 9898700e3e7SMoni Shoua 990647bf13cSBob Pearson n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_mr_set_page); 9918700e3e7SMoni Shoua 992647bf13cSBob Pearson set->va = ibmr->iova; 993647bf13cSBob Pearson set->iova = ibmr->iova; 994647bf13cSBob Pearson set->length = ibmr->length; 995647bf13cSBob Pearson set->page_shift = ilog2(ibmr->page_size); 996647bf13cSBob Pearson set->page_mask = ibmr->page_size - 1; 997647bf13cSBob Pearson set->offset = set->iova & set->page_mask; 9988700e3e7SMoni Shoua 9998700e3e7SMoni Shoua return n; 10008700e3e7SMoni Shoua } 10018700e3e7SMoni Shoua 10028700e3e7SMoni Shoua static int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) 10038700e3e7SMoni Shoua { 10048700e3e7SMoni Shoua int err; 10058700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 10068700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 10078700e3e7SMoni Shoua struct rxe_mc_grp *grp; 10088700e3e7SMoni Shoua 10098700e3e7SMoni Shoua /* takes a ref on grp if successful */ 10108700e3e7SMoni Shoua err = rxe_mcast_get_grp(rxe, mgid, &grp); 10118700e3e7SMoni Shoua if (err) 10128700e3e7SMoni Shoua return err; 10138700e3e7SMoni Shoua 10148700e3e7SMoni Shoua err = rxe_mcast_add_grp_elem(rxe, qp, grp); 10158700e3e7SMoni Shoua 10168700e3e7SMoni Shoua rxe_drop_ref(grp); 10178700e3e7SMoni Shoua return err; 10188700e3e7SMoni Shoua } 10198700e3e7SMoni Shoua 10208700e3e7SMoni Shoua static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) 10218700e3e7SMoni Shoua { 10228700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 10238700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 10248700e3e7SMoni Shoua 10258700e3e7SMoni Shoua return rxe_mcast_drop_grp_elem(rxe, qp, mgid); 10268700e3e7SMoni Shoua } 10278700e3e7SMoni Shoua 1028c05d2664SKamal Heib static ssize_t parent_show(struct device *device, 10298700e3e7SMoni Shoua struct device_attribute *attr, char *buf) 10308700e3e7SMoni Shoua { 103154747231SParav Pandit struct rxe_dev *rxe = 103254747231SParav Pandit rdma_device_to_drv_device(device, struct rxe_dev, ib_dev); 10338700e3e7SMoni Shoua 10341c7fd726SJoe Perches return sysfs_emit(buf, "%s\n", rxe_parent_name(rxe, 1)); 10358700e3e7SMoni Shoua } 10368700e3e7SMoni Shoua 1037c05d2664SKamal Heib static DEVICE_ATTR_RO(parent); 10388700e3e7SMoni Shoua 1039508a523fSParav Pandit static struct attribute *rxe_dev_attributes[] = { 1040508a523fSParav Pandit &dev_attr_parent.attr, 1041508a523fSParav Pandit NULL 1042508a523fSParav Pandit }; 1043508a523fSParav Pandit 1044508a523fSParav Pandit static const struct attribute_group rxe_attr_group = { 1045508a523fSParav Pandit .attrs = rxe_dev_attributes, 10468700e3e7SMoni Shoua }; 10478700e3e7SMoni Shoua 1048ca22354bSJason Gunthorpe static int rxe_enable_driver(struct ib_device *ib_dev) 1049ca22354bSJason Gunthorpe { 1050ca22354bSJason Gunthorpe struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev); 1051ca22354bSJason Gunthorpe 1052ca22354bSJason Gunthorpe rxe_set_port_state(rxe); 1053ca22354bSJason Gunthorpe dev_info(&rxe->ib_dev.dev, "added %s\n", netdev_name(rxe->ndev)); 1054ca22354bSJason Gunthorpe return 0; 1055ca22354bSJason Gunthorpe } 1056ca22354bSJason Gunthorpe 1057573efc4bSKamal Heib static const struct ib_device_ops rxe_dev_ops = { 10587a154142SJason Gunthorpe .owner = THIS_MODULE, 1059b9560a41SJason Gunthorpe .driver_id = RDMA_DRIVER_RXE, 106072c6ec18SJason Gunthorpe .uverbs_abi_ver = RXE_UVERBS_ABI_VERSION, 1061b9560a41SJason Gunthorpe 10624b5f4d3fSJason Gunthorpe .alloc_hw_port_stats = rxe_ib_alloc_hw_port_stats, 1063573efc4bSKamal Heib .alloc_mr = rxe_alloc_mr, 1064beec0239SBob Pearson .alloc_mw = rxe_alloc_mw, 1065573efc4bSKamal Heib .alloc_pd = rxe_alloc_pd, 1066573efc4bSKamal Heib .alloc_ucontext = rxe_alloc_ucontext, 1067573efc4bSKamal Heib .attach_mcast = rxe_attach_mcast, 1068573efc4bSKamal Heib .create_ah = rxe_create_ah, 1069573efc4bSKamal Heib .create_cq = rxe_create_cq, 1070573efc4bSKamal Heib .create_qp = rxe_create_qp, 1071573efc4bSKamal Heib .create_srq = rxe_create_srq, 1072676a80adSJason Gunthorpe .create_user_ah = rxe_create_ah, 1073c367074bSJason Gunthorpe .dealloc_driver = rxe_dealloc, 1074beec0239SBob Pearson .dealloc_mw = rxe_dealloc_mw, 1075573efc4bSKamal Heib .dealloc_pd = rxe_dealloc_pd, 1076573efc4bSKamal Heib .dealloc_ucontext = rxe_dealloc_ucontext, 1077573efc4bSKamal Heib .dereg_mr = rxe_dereg_mr, 1078573efc4bSKamal Heib .destroy_ah = rxe_destroy_ah, 1079573efc4bSKamal Heib .destroy_cq = rxe_destroy_cq, 1080573efc4bSKamal Heib .destroy_qp = rxe_destroy_qp, 1081573efc4bSKamal Heib .destroy_srq = rxe_destroy_srq, 1082573efc4bSKamal Heib .detach_mcast = rxe_detach_mcast, 1083915e4af5SJason Gunthorpe .device_group = &rxe_attr_group, 1084ca22354bSJason Gunthorpe .enable_driver = rxe_enable_driver, 1085573efc4bSKamal Heib .get_dma_mr = rxe_get_dma_mr, 1086573efc4bSKamal Heib .get_hw_stats = rxe_ib_get_hw_stats, 1087573efc4bSKamal Heib .get_link_layer = rxe_get_link_layer, 1088573efc4bSKamal Heib .get_port_immutable = rxe_port_immutable, 1089573efc4bSKamal Heib .map_mr_sg = rxe_map_mr_sg, 1090573efc4bSKamal Heib .mmap = rxe_mmap, 1091573efc4bSKamal Heib .modify_ah = rxe_modify_ah, 1092573efc4bSKamal Heib .modify_device = rxe_modify_device, 1093573efc4bSKamal Heib .modify_port = rxe_modify_port, 1094573efc4bSKamal Heib .modify_qp = rxe_modify_qp, 1095573efc4bSKamal Heib .modify_srq = rxe_modify_srq, 1096573efc4bSKamal Heib .peek_cq = rxe_peek_cq, 1097573efc4bSKamal Heib .poll_cq = rxe_poll_cq, 1098573efc4bSKamal Heib .post_recv = rxe_post_recv, 1099573efc4bSKamal Heib .post_send = rxe_post_send, 1100573efc4bSKamal Heib .post_srq_recv = rxe_post_srq_recv, 1101573efc4bSKamal Heib .query_ah = rxe_query_ah, 1102573efc4bSKamal Heib .query_device = rxe_query_device, 1103573efc4bSKamal Heib .query_pkey = rxe_query_pkey, 1104573efc4bSKamal Heib .query_port = rxe_query_port, 1105573efc4bSKamal Heib .query_qp = rxe_query_qp, 1106573efc4bSKamal Heib .query_srq = rxe_query_srq, 1107573efc4bSKamal Heib .reg_user_mr = rxe_reg_user_mr, 1108573efc4bSKamal Heib .req_notify_cq = rxe_req_notify_cq, 1109573efc4bSKamal Heib .resize_cq = rxe_resize_cq, 1110d3456914SLeon Romanovsky 1111d3456914SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ah, rxe_ah, ibah), 1112e39afe3dSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_cq, rxe_cq, ibcq), 111321a428a0SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_pd, rxe_pd, ibpd), 1114514aee66SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_qp, rxe_qp, ibqp), 111568e326deSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_srq, rxe_srq, ibsrq), 1116a2a074efSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ucontext, rxe_ucontext, ibuc), 1117364e282cSBob Pearson INIT_RDMA_OBJ_SIZE(ib_mw, rxe_mw, ibmw), 1118573efc4bSKamal Heib }; 1119573efc4bSKamal Heib 112066920e1bSSteve Wise int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name) 11218700e3e7SMoni Shoua { 11228700e3e7SMoni Shoua int err; 11238700e3e7SMoni Shoua struct ib_device *dev = &rxe->ib_dev; 11248700e3e7SMoni Shoua 1125dc78074aSBob Pearson strscpy(dev->node_desc, "rxe", sizeof(dev->node_desc)); 11268700e3e7SMoni Shoua 11278700e3e7SMoni Shoua dev->node_type = RDMA_NODE_IB_CA; 11288700e3e7SMoni Shoua dev->phys_port_cnt = 1; 112967cf3623SSagi Grimberg dev->num_comp_vectors = num_possible_cpus(); 11308700e3e7SMoni Shoua dev->local_dma_lkey = 0; 11314d6f2859SYuval Shaia addrconf_addr_eui48((unsigned char *)&dev->node_guid, 11324d6f2859SYuval Shaia rxe->ndev->dev_addr); 11338700e3e7SMoni Shoua 11345c419366SJason Gunthorpe dev->uverbs_cmd_mask |= BIT_ULL(IB_USER_VERBS_CMD_POST_SEND) | 11355c419366SJason Gunthorpe BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ); 11368700e3e7SMoni Shoua 1137573efc4bSKamal Heib ib_set_device_ops(dev, &rxe_dev_ops); 11384c173f59SJason Gunthorpe err = ib_device_set_netdev(&rxe->ib_dev, rxe->ndev, 1); 11394c173f59SJason Gunthorpe if (err) 11404c173f59SJason Gunthorpe return err; 11418700e3e7SMoni Shoua 1142add2b3b8SBob Pearson err = rxe_icrc_init(rxe); 1143add2b3b8SBob Pearson if (err) 1144add2b3b8SBob Pearson return err; 1145cee2688eSyonatanc 1146e0477b34SJason Gunthorpe err = ib_register_device(dev, ibdev_name, NULL); 1147c367074bSJason Gunthorpe if (err) 114861013828SKamal Heib pr_warn("%s failed with error %d\n", __func__, err); 1149cee2688eSyonatanc 1150ca22354bSJason Gunthorpe /* 1151ca22354bSJason Gunthorpe * Note that rxe may be invalid at this point if another thread 1152ca22354bSJason Gunthorpe * unregistered it. 1153ca22354bSJason Gunthorpe */ 11548700e3e7SMoni Shoua return err; 11558700e3e7SMoni Shoua } 1156