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> 100b1fbfb9SBob Pearson 118700e3e7SMoni Shoua #include "rxe.h" 128700e3e7SMoni Shoua #include "rxe_queue.h" 130b1e5b99SYonatan Cohen #include "rxe_hw_counters.h" 148700e3e7SMoni Shoua 155bf944f2SBob Pearson static int post_one_recv(struct rxe_rq *rq, const struct ib_recv_wr *ibwr); 165bf944f2SBob Pearson 175bf944f2SBob Pearson /* dev */ 185bf944f2SBob Pearson static int rxe_query_device(struct ib_device *ibdev, 198700e3e7SMoni Shoua struct ib_device_attr *attr, 205bf944f2SBob Pearson struct ib_udata *udata) 218700e3e7SMoni Shoua { 225bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibdev); 235bf944f2SBob Pearson int err; 248700e3e7SMoni Shoua 255bf944f2SBob Pearson if (udata->inlen || udata->outlen) { 265bf944f2SBob Pearson rxe_dbg_dev(rxe, "malformed udata"); 275bf944f2SBob Pearson err = -EINVAL; 285bf944f2SBob Pearson goto err_out; 298700e3e7SMoni Shoua } 308700e3e7SMoni Shoua 315bf944f2SBob Pearson memcpy(attr, &rxe->attr, sizeof(*attr)); 325bf944f2SBob Pearson 335bf944f2SBob Pearson return 0; 345bf944f2SBob Pearson 355bf944f2SBob Pearson err_out: 365bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 375bf944f2SBob Pearson return err; 385bf944f2SBob Pearson } 395bf944f2SBob Pearson 405bf944f2SBob Pearson static int rxe_query_port(struct ib_device *ibdev, 411fb7f897SMark Bloch u32 port_num, struct ib_port_attr *attr) 428700e3e7SMoni Shoua { 435bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibdev); 445bf944f2SBob Pearson int err, ret; 458700e3e7SMoni Shoua 465bf944f2SBob Pearson if (port_num != 1) { 475bf944f2SBob Pearson err = -EINVAL; 485bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad port_num = %d", port_num); 495bf944f2SBob Pearson goto err_out; 505bf944f2SBob Pearson } 515bf944f2SBob Pearson 525bf944f2SBob Pearson memcpy(attr, &rxe->port.attr, sizeof(*attr)); 538700e3e7SMoni Shoua 548700e3e7SMoni Shoua mutex_lock(&rxe->usdev_lock); 555bf944f2SBob Pearson ret = ib_get_eth_speed(ibdev, port_num, &attr->active_speed, 56e404f945SParav Pandit &attr->active_width); 575736c7c4SAndrew Boyer 585736c7c4SAndrew Boyer if (attr->state == IB_PORT_ACTIVE) 5972a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP; 605736c7c4SAndrew Boyer else if (dev_get_flags(rxe->ndev) & IFF_UP) 6172a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_POLLING; 625736c7c4SAndrew Boyer else 6372a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_DISABLED; 645736c7c4SAndrew Boyer 658700e3e7SMoni Shoua mutex_unlock(&rxe->usdev_lock); 668700e3e7SMoni Shoua 675bf944f2SBob Pearson return ret; 685bf944f2SBob Pearson 695bf944f2SBob Pearson err_out: 705bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 715bf944f2SBob Pearson return err; 728700e3e7SMoni Shoua } 738700e3e7SMoni Shoua 745bf944f2SBob Pearson static int rxe_query_pkey(struct ib_device *ibdev, 751fb7f897SMark Bloch u32 port_num, u16 index, u16 *pkey) 768700e3e7SMoni Shoua { 775bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibdev); 785bf944f2SBob Pearson int err; 795bf944f2SBob Pearson 805bf944f2SBob Pearson if (index != 0) { 815bf944f2SBob Pearson err = -EINVAL; 825bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad pkey index = %d", index); 835bf944f2SBob Pearson goto err_out; 845bf944f2SBob Pearson } 8576251e15SKamal Heib 8676251e15SKamal Heib *pkey = IB_DEFAULT_PKEY_FULL; 8776251e15SKamal Heib return 0; 885bf944f2SBob Pearson 895bf944f2SBob Pearson err_out: 905bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 915bf944f2SBob Pearson return err; 928700e3e7SMoni Shoua } 938700e3e7SMoni Shoua 945bf944f2SBob Pearson static int rxe_modify_device(struct ib_device *ibdev, 958700e3e7SMoni Shoua int mask, struct ib_device_modify *attr) 968700e3e7SMoni Shoua { 975bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibdev); 985bf944f2SBob Pearson int err; 998700e3e7SMoni Shoua 100f3fceba5SKamal Heib if (mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | 1015bf944f2SBob Pearson IB_DEVICE_MODIFY_NODE_DESC)) { 1025bf944f2SBob Pearson err = -EOPNOTSUPP; 1035bf944f2SBob Pearson rxe_dbg_dev(rxe, "unsupported mask = 0x%x", mask); 1045bf944f2SBob Pearson goto err_out; 1055bf944f2SBob Pearson } 106f3fceba5SKamal Heib 1078700e3e7SMoni Shoua if (mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) 1088700e3e7SMoni Shoua rxe->attr.sys_image_guid = cpu_to_be64(attr->sys_image_guid); 1098700e3e7SMoni Shoua 1108700e3e7SMoni Shoua if (mask & IB_DEVICE_MODIFY_NODE_DESC) { 1118700e3e7SMoni Shoua memcpy(rxe->ib_dev.node_desc, 1128700e3e7SMoni Shoua attr->node_desc, sizeof(rxe->ib_dev.node_desc)); 1138700e3e7SMoni Shoua } 1148700e3e7SMoni Shoua 1158700e3e7SMoni Shoua return 0; 1165bf944f2SBob Pearson 1175bf944f2SBob Pearson err_out: 1185bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 1195bf944f2SBob Pearson return err; 1208700e3e7SMoni Shoua } 1218700e3e7SMoni Shoua 1225bf944f2SBob Pearson static int rxe_modify_port(struct ib_device *ibdev, u32 port_num, 1235bf944f2SBob Pearson int mask, struct ib_port_modify *attr) 1248700e3e7SMoni Shoua { 1255bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibdev); 1268700e3e7SMoni Shoua struct rxe_port *port; 1275bf944f2SBob Pearson int err; 1285bf944f2SBob Pearson 1295bf944f2SBob Pearson if (port_num != 1) { 1305bf944f2SBob Pearson err = -EINVAL; 1315bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad port_num = %d", port_num); 1325bf944f2SBob Pearson goto err_out; 1335bf944f2SBob Pearson } 1345bf944f2SBob Pearson 1355bf944f2SBob Pearson //TODO is shutdown useful 1365bf944f2SBob Pearson if (mask & ~(IB_PORT_RESET_QKEY_CNTR)) { 1375bf944f2SBob Pearson err = -EOPNOTSUPP; 1385bf944f2SBob Pearson rxe_dbg_dev(rxe, "unsupported mask = 0x%x", mask); 1395bf944f2SBob Pearson goto err_out; 1405bf944f2SBob Pearson } 1418700e3e7SMoni Shoua 1428700e3e7SMoni Shoua port = &rxe->port; 1438700e3e7SMoni Shoua port->attr.port_cap_flags |= attr->set_port_cap_mask; 1448700e3e7SMoni Shoua port->attr.port_cap_flags &= ~attr->clr_port_cap_mask; 1458700e3e7SMoni Shoua 1468700e3e7SMoni Shoua if (mask & IB_PORT_RESET_QKEY_CNTR) 1478700e3e7SMoni Shoua port->attr.qkey_viol_cntr = 0; 1488700e3e7SMoni Shoua 1498700e3e7SMoni Shoua return 0; 1505bf944f2SBob Pearson 1515bf944f2SBob Pearson err_out: 1525bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 1535bf944f2SBob Pearson return err; 1548700e3e7SMoni Shoua } 1558700e3e7SMoni Shoua 1565bf944f2SBob Pearson static enum rdma_link_layer rxe_get_link_layer(struct ib_device *ibdev, 1571fb7f897SMark Bloch u32 port_num) 1588700e3e7SMoni Shoua { 1595bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibdev); 1605bf944f2SBob Pearson int err; 1615bf944f2SBob Pearson 1625bf944f2SBob Pearson if (port_num != 1) { 1635bf944f2SBob Pearson err = -EINVAL; 1645bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad port_num = %d", port_num); 1655bf944f2SBob Pearson goto err_out; 1665bf944f2SBob Pearson } 1675bf944f2SBob Pearson 168420bd9e2SKamal Heib return IB_LINK_LAYER_ETHERNET; 1695bf944f2SBob Pearson 1705bf944f2SBob Pearson err_out: 1715bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 1725bf944f2SBob Pearson return err; 1738700e3e7SMoni Shoua } 1748700e3e7SMoni Shoua 1755bf944f2SBob Pearson static int rxe_port_immutable(struct ib_device *ibdev, u32 port_num, 1768700e3e7SMoni Shoua struct ib_port_immutable *immutable) 1778700e3e7SMoni Shoua { 1785bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibdev); 1795bf944f2SBob Pearson struct ib_port_attr attr = {}; 1808700e3e7SMoni Shoua int err; 1815bf944f2SBob Pearson 1825bf944f2SBob Pearson if (port_num != 1) { 1835bf944f2SBob Pearson err = -EINVAL; 1845bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad port_num = %d", port_num); 1855bf944f2SBob Pearson goto err_out; 1865bf944f2SBob Pearson } 1875bf944f2SBob Pearson 1885bf944f2SBob Pearson err = ib_query_port(ibdev, port_num, &attr); 1895bf944f2SBob Pearson if (err) 1905bf944f2SBob Pearson goto err_out; 1918700e3e7SMoni Shoua 192c4550c63SOr Gerlitz immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; 1938700e3e7SMoni Shoua immutable->pkey_tbl_len = attr.pkey_tbl_len; 1948700e3e7SMoni Shoua immutable->gid_tbl_len = attr.gid_tbl_len; 1958700e3e7SMoni Shoua immutable->max_mad_size = IB_MGMT_MAD_SIZE; 1968700e3e7SMoni Shoua 1978700e3e7SMoni Shoua return 0; 1985bf944f2SBob Pearson 1995bf944f2SBob Pearson err_out: 2005bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 2015bf944f2SBob Pearson return err; 2028700e3e7SMoni Shoua } 2038700e3e7SMoni Shoua 2045bf944f2SBob Pearson /* uc */ 2055bf944f2SBob Pearson static int rxe_alloc_ucontext(struct ib_ucontext *ibuc, struct ib_udata *udata) 2065bf944f2SBob Pearson { 2075bf944f2SBob Pearson struct rxe_dev *rxe = to_rdev(ibuc->device); 2085bf944f2SBob Pearson struct rxe_ucontext *uc = to_ruc(ibuc); 2095bf944f2SBob Pearson int err; 2105bf944f2SBob Pearson 2115bf944f2SBob Pearson err = rxe_add_to_pool(&rxe->uc_pool, uc); 2125bf944f2SBob Pearson if (err) 2135bf944f2SBob Pearson rxe_err_dev(rxe, "unable to create uc"); 2145bf944f2SBob Pearson 2155bf944f2SBob Pearson return err; 2165bf944f2SBob Pearson } 2175bf944f2SBob Pearson 2185bf944f2SBob Pearson static void rxe_dealloc_ucontext(struct ib_ucontext *ibuc) 2195bf944f2SBob Pearson { 2205bf944f2SBob Pearson struct rxe_ucontext *uc = to_ruc(ibuc); 2215bf944f2SBob Pearson int err; 2225bf944f2SBob Pearson 2235bf944f2SBob Pearson err = rxe_cleanup(uc); 2245bf944f2SBob Pearson if (err) 2255bf944f2SBob Pearson rxe_err_uc(uc, "cleanup failed, err = %d", err); 2265bf944f2SBob Pearson } 2275bf944f2SBob Pearson 2285bf944f2SBob Pearson /* pd */ 229ff23dfa1SShamir Rabinovitch static int rxe_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) 2308700e3e7SMoni Shoua { 23121a428a0SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibpd->device); 23221a428a0SLeon Romanovsky struct rxe_pd *pd = to_rpd(ibpd); 2335bf944f2SBob Pearson int err; 2348700e3e7SMoni Shoua 2355bf944f2SBob Pearson err = rxe_add_to_pool(&rxe->pd_pool, pd); 2365bf944f2SBob Pearson if (err) { 2375bf944f2SBob Pearson rxe_dbg_dev(rxe, "unable to alloc pd"); 2385bf944f2SBob Pearson goto err_out; 2395bf944f2SBob Pearson } 2405bf944f2SBob Pearson 2415bf944f2SBob Pearson return 0; 2425bf944f2SBob Pearson 2435bf944f2SBob Pearson err_out: 2445bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 2455bf944f2SBob Pearson return err; 2468700e3e7SMoni Shoua } 2478700e3e7SMoni Shoua 24891a7c58fSLeon Romanovsky static int rxe_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) 2498700e3e7SMoni Shoua { 2508700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 2515bf944f2SBob Pearson int err; 2528700e3e7SMoni Shoua 2535bf944f2SBob Pearson err = rxe_cleanup(pd); 2545bf944f2SBob Pearson if (err) 2555bf944f2SBob Pearson rxe_err_pd(pd, "cleanup failed, err = %d", err); 2565bf944f2SBob Pearson 25791a7c58fSLeon Romanovsky return 0; 2588700e3e7SMoni Shoua } 2598700e3e7SMoni Shoua 2605bf944f2SBob Pearson /* ah */ 261fa5d010cSMaor Gottlieb static int rxe_create_ah(struct ib_ah *ibah, 262fa5d010cSMaor Gottlieb struct rdma_ah_init_attr *init_attr, 263fa5d010cSMaor Gottlieb struct ib_udata *udata) 2648700e3e7SMoni Shoua { 265d3456914SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibah->device); 266d3456914SLeon Romanovsky struct rxe_ah *ah = to_rah(ibah); 26773a54932SBob Pearson struct rxe_create_ah_resp __user *uresp = NULL; 2685bf944f2SBob Pearson int err, cleanup_err; 26973a54932SBob Pearson 27073a54932SBob Pearson if (udata) { 27173a54932SBob Pearson /* test if new user provider */ 27273a54932SBob Pearson if (udata->outlen >= sizeof(*uresp)) 27373a54932SBob Pearson uresp = udata->outbuf; 27473a54932SBob Pearson ah->is_user = true; 27573a54932SBob Pearson } else { 27673a54932SBob Pearson ah->is_user = false; 27773a54932SBob Pearson } 2788700e3e7SMoni Shoua 279215d0a75SBob Pearson err = rxe_add_to_pool_ah(&rxe->ah_pool, ah, 280215d0a75SBob Pearson init_attr->flags & RDMA_CREATE_AH_SLEEPABLE); 2815bf944f2SBob Pearson if (err) { 2825bf944f2SBob Pearson rxe_dbg_dev(rxe, "unable to create ah"); 2835bf944f2SBob Pearson goto err_out; 2845bf944f2SBob Pearson } 2858700e3e7SMoni Shoua 28673a54932SBob Pearson /* create index > 0 */ 28702827b67SBob Pearson ah->ah_num = ah->elem.index; 28873a54932SBob Pearson 28925fd735aSBob Pearson err = rxe_ah_chk_attr(ah, init_attr->ah_attr); 29025fd735aSBob Pearson if (err) { 2915bf944f2SBob Pearson rxe_dbg_ah(ah, "bad attr"); 2925bf944f2SBob Pearson goto err_cleanup; 29325fd735aSBob Pearson } 29425fd735aSBob Pearson 29573a54932SBob Pearson if (uresp) { 29673a54932SBob Pearson /* only if new user provider */ 29773a54932SBob Pearson err = copy_to_user(&uresp->ah_num, &ah->ah_num, 29873a54932SBob Pearson sizeof(uresp->ah_num)); 29973a54932SBob Pearson if (err) { 3005bf944f2SBob Pearson err = -EFAULT; 3015bf944f2SBob Pearson rxe_dbg_ah(ah, "unable to copy to user"); 3025bf944f2SBob Pearson goto err_cleanup; 30373a54932SBob Pearson } 30473a54932SBob Pearson } else if (ah->is_user) { 30573a54932SBob Pearson /* only if old user provider */ 30673a54932SBob Pearson ah->ah_num = 0; 30773a54932SBob Pearson } 30873a54932SBob Pearson 309fa5d010cSMaor Gottlieb rxe_init_av(init_attr->ah_attr, &ah->av); 310215d0a75SBob Pearson rxe_finalize(ah); 311215d0a75SBob Pearson 312d3456914SLeon Romanovsky return 0; 3135bf944f2SBob Pearson 3145bf944f2SBob Pearson err_cleanup: 3155bf944f2SBob Pearson cleanup_err = rxe_cleanup(ah); 3165bf944f2SBob Pearson if (cleanup_err) 3175bf944f2SBob Pearson rxe_err_ah(ah, "cleanup failed, err = %d", cleanup_err); 3185bf944f2SBob Pearson err_out: 3195bf944f2SBob Pearson rxe_err_ah(ah, "returned err = %d", err); 3205bf944f2SBob Pearson return err; 3218700e3e7SMoni Shoua } 3228700e3e7SMoni Shoua 32390898850SDasaratharaman Chandramouli static int rxe_modify_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) 3248700e3e7SMoni Shoua { 3258700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 3265bf944f2SBob Pearson int err; 3278700e3e7SMoni Shoua 32825fd735aSBob Pearson err = rxe_ah_chk_attr(ah, attr); 3295bf944f2SBob Pearson if (err) { 3305bf944f2SBob Pearson rxe_dbg_ah(ah, "bad attr"); 3315bf944f2SBob Pearson goto err_out; 3325bf944f2SBob Pearson } 3338700e3e7SMoni Shoua 334fa407188SKamal Heib rxe_init_av(attr, &ah->av); 3355bf944f2SBob Pearson 3368700e3e7SMoni Shoua return 0; 3375bf944f2SBob Pearson 3385bf944f2SBob Pearson err_out: 3395bf944f2SBob Pearson rxe_err_ah(ah, "returned err = %d", err); 3405bf944f2SBob Pearson return err; 3418700e3e7SMoni Shoua } 3428700e3e7SMoni Shoua 34390898850SDasaratharaman Chandramouli static int rxe_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) 3448700e3e7SMoni Shoua { 3458700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 3468700e3e7SMoni Shoua 347eca7ddf9SDasaratharaman Chandramouli memset(attr, 0, sizeof(*attr)); 34844c58487SDasaratharaman Chandramouli attr->type = ibah->type; 3499c96f3d4SZhu Yanjun rxe_av_to_attr(&ah->av, attr); 3505bf944f2SBob Pearson 3518700e3e7SMoni Shoua return 0; 3528700e3e7SMoni Shoua } 3538700e3e7SMoni Shoua 3549a9ebf8cSLeon Romanovsky static int rxe_destroy_ah(struct ib_ah *ibah, u32 flags) 3558700e3e7SMoni Shoua { 3568700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 3575bf944f2SBob Pearson int err; 3588700e3e7SMoni Shoua 3595bf944f2SBob Pearson err = rxe_cleanup_ah(ah, flags & RDMA_DESTROY_AH_SLEEPABLE); 3605bf944f2SBob Pearson if (err) 3615bf944f2SBob Pearson rxe_err_ah(ah, "cleanup failed, err = %d", err); 362215d0a75SBob Pearson 3639a9ebf8cSLeon Romanovsky return 0; 3648700e3e7SMoni Shoua } 3658700e3e7SMoni Shoua 3665bf944f2SBob Pearson /* srq */ 36768e326deSLeon Romanovsky static int rxe_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init, 3688700e3e7SMoni Shoua struct ib_udata *udata) 3698700e3e7SMoni Shoua { 37068e326deSLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibsrq->device); 37168e326deSLeon Romanovsky struct rxe_pd *pd = to_rpd(ibsrq->pd); 37268e326deSLeon Romanovsky struct rxe_srq *srq = to_rsrq(ibsrq); 3730c43ab37SJason Gunthorpe struct rxe_create_srq_resp __user *uresp = NULL; 3745bf944f2SBob Pearson int err, cleanup_err; 3750c43ab37SJason Gunthorpe 3760c43ab37SJason Gunthorpe if (udata) { 3775bf944f2SBob Pearson if (udata->outlen < sizeof(*uresp)) { 3785bf944f2SBob Pearson err = -EINVAL; 3795bf944f2SBob Pearson rxe_err_dev(rxe, "malformed udata"); 3805bf944f2SBob Pearson goto err_out; 3815bf944f2SBob Pearson } 3820c43ab37SJason Gunthorpe uresp = udata->outbuf; 3830c43ab37SJason Gunthorpe } 3848700e3e7SMoni Shoua 3855bf944f2SBob Pearson if (init->srq_type != IB_SRQT_BASIC) { 3865bf944f2SBob Pearson err = -EOPNOTSUPP; 3875bf944f2SBob Pearson rxe_dbg_dev(rxe, "srq type = %d, not supported", 3885bf944f2SBob Pearson init->srq_type); 3895bf944f2SBob Pearson goto err_out; 3905bf944f2SBob Pearson } 391b2a41678SBob Pearson 3920b1fbfb9SBob Pearson err = rxe_srq_chk_init(rxe, init); 3935bf944f2SBob Pearson if (err) { 3945bf944f2SBob Pearson rxe_dbg_dev(rxe, "invalid init attributes"); 3955bf944f2SBob Pearson goto err_out; 3965bf944f2SBob Pearson } 3978700e3e7SMoni Shoua 39891a42c5bSBob Pearson err = rxe_add_to_pool(&rxe->srq_pool, srq); 3995bf944f2SBob Pearson if (err) { 4005bf944f2SBob Pearson rxe_dbg_dev(rxe, "unable to create srq, err = %d", err); 4015bf944f2SBob Pearson goto err_out; 4025bf944f2SBob Pearson } 4038700e3e7SMoni Shoua 4043197706aSBob Pearson rxe_get(pd); 4058700e3e7SMoni Shoua srq->pd = pd; 4068700e3e7SMoni Shoua 407ff23dfa1SShamir Rabinovitch err = rxe_srq_from_init(rxe, srq, init, udata, uresp); 4085bf944f2SBob Pearson if (err) { 4095bf944f2SBob Pearson rxe_dbg_srq(srq, "create srq failed, err = %d", err); 410215d0a75SBob Pearson goto err_cleanup; 4115bf944f2SBob Pearson } 4128700e3e7SMoni Shoua 41368e326deSLeon Romanovsky return 0; 4148700e3e7SMoni Shoua 415215d0a75SBob Pearson err_cleanup: 4165bf944f2SBob Pearson cleanup_err = rxe_cleanup(srq); 4175bf944f2SBob Pearson if (cleanup_err) 4185bf944f2SBob Pearson rxe_err_srq(srq, "cleanup failed, err = %d", cleanup_err); 4195bf944f2SBob Pearson err_out: 4205bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 42168e326deSLeon Romanovsky return err; 4228700e3e7SMoni Shoua } 4238700e3e7SMoni Shoua 4248700e3e7SMoni Shoua static int rxe_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 4258700e3e7SMoni Shoua enum ib_srq_attr_mask mask, 4268700e3e7SMoni Shoua struct ib_udata *udata) 4278700e3e7SMoni Shoua { 4288700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 4298700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibsrq->device); 4305bf944f2SBob Pearson struct rxe_modify_srq_cmd cmd = {}; 4315bf944f2SBob Pearson int err; 4320c43ab37SJason Gunthorpe 4330c43ab37SJason Gunthorpe if (udata) { 4345bf944f2SBob Pearson if (udata->inlen < sizeof(cmd)) { 4355bf944f2SBob Pearson err = -EINVAL; 4365bf944f2SBob Pearson rxe_dbg_srq(srq, "malformed udata"); 4375bf944f2SBob Pearson goto err_out; 4385bf944f2SBob Pearson } 4390c43ab37SJason Gunthorpe 4405bf944f2SBob Pearson err = ib_copy_from_udata(&cmd, udata, sizeof(cmd)); 4415bf944f2SBob Pearson if (err) { 4425bf944f2SBob Pearson err = -EFAULT; 4435bf944f2SBob Pearson rxe_dbg_srq(srq, "unable to read udata"); 4445bf944f2SBob Pearson goto err_out; 4455bf944f2SBob Pearson } 4460c43ab37SJason Gunthorpe } 4478700e3e7SMoni Shoua 4488700e3e7SMoni Shoua err = rxe_srq_chk_attr(rxe, srq, attr, mask); 4495bf944f2SBob Pearson if (err) { 4505bf944f2SBob Pearson rxe_dbg_srq(srq, "bad init attributes"); 4515bf944f2SBob Pearson goto err_out; 4525bf944f2SBob Pearson } 4538700e3e7SMoni Shoua 4545bf944f2SBob Pearson err = rxe_srq_from_attr(rxe, srq, attr, mask, &cmd, udata); 4555bf944f2SBob Pearson if (err) { 4565bf944f2SBob Pearson rxe_dbg_srq(srq, "bad attr"); 4575bf944f2SBob Pearson goto err_out; 4585bf944f2SBob Pearson } 4595bf944f2SBob Pearson 4605bf944f2SBob Pearson return 0; 4615bf944f2SBob Pearson 4625bf944f2SBob Pearson err_out: 4635bf944f2SBob Pearson rxe_err_srq(srq, "returned err = %d", err); 4645bf944f2SBob Pearson return err; 4658700e3e7SMoni Shoua } 4668700e3e7SMoni Shoua 4678700e3e7SMoni Shoua static int rxe_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr) 4688700e3e7SMoni Shoua { 4698700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 4705bf944f2SBob Pearson int err; 4718700e3e7SMoni Shoua 4725bf944f2SBob Pearson if (srq->error) { 4735bf944f2SBob Pearson err = -EINVAL; 4745bf944f2SBob Pearson rxe_dbg_srq(srq, "srq in error state"); 4755bf944f2SBob Pearson goto err_out; 4765bf944f2SBob Pearson } 4778700e3e7SMoni Shoua 4788700e3e7SMoni Shoua attr->max_wr = srq->rq.queue->buf->index_mask; 4798700e3e7SMoni Shoua attr->max_sge = srq->rq.max_sge; 4808700e3e7SMoni Shoua attr->srq_limit = srq->limit; 4818700e3e7SMoni Shoua return 0; 4828700e3e7SMoni Shoua 4835bf944f2SBob Pearson err_out: 4845bf944f2SBob Pearson rxe_err_srq(srq, "returned err = %d", err); 4855bf944f2SBob Pearson return err; 4868700e3e7SMoni Shoua } 4878700e3e7SMoni Shoua 488d34ac5cdSBart Van Assche static int rxe_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr, 489d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr) 4908700e3e7SMoni Shoua { 4918700e3e7SMoni Shoua int err = 0; 4928700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 493a099b085SBob Pearson unsigned long flags; 4948700e3e7SMoni Shoua 495a099b085SBob Pearson spin_lock_irqsave(&srq->rq.producer_lock, flags); 4968700e3e7SMoni Shoua 4978700e3e7SMoni Shoua while (wr) { 4988700e3e7SMoni Shoua err = post_one_recv(&srq->rq, wr); 4998700e3e7SMoni Shoua if (unlikely(err)) 5008700e3e7SMoni Shoua break; 5018700e3e7SMoni Shoua wr = wr->next; 5028700e3e7SMoni Shoua } 5038700e3e7SMoni Shoua 504a099b085SBob Pearson spin_unlock_irqrestore(&srq->rq.producer_lock, flags); 5058700e3e7SMoni Shoua 5065bf944f2SBob Pearson if (err) { 5078700e3e7SMoni Shoua *bad_wr = wr; 5085bf944f2SBob Pearson rxe_err_srq(srq, "returned err = %d", err); 5095bf944f2SBob Pearson } 5108700e3e7SMoni Shoua 5118700e3e7SMoni Shoua return err; 5128700e3e7SMoni Shoua } 5138700e3e7SMoni Shoua 5145bf944f2SBob Pearson static int rxe_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata) 5155bf944f2SBob Pearson { 5165bf944f2SBob Pearson struct rxe_srq *srq = to_rsrq(ibsrq); 5175bf944f2SBob Pearson int err; 5185bf944f2SBob Pearson 5195bf944f2SBob Pearson err = rxe_cleanup(srq); 5205bf944f2SBob Pearson if (err) 5215bf944f2SBob Pearson rxe_err_srq(srq, "cleanup failed, err = %d", err); 5225bf944f2SBob Pearson 5235bf944f2SBob Pearson return 0; 5245bf944f2SBob Pearson } 5255bf944f2SBob Pearson 5265bf944f2SBob Pearson /* qp */ 527514aee66SLeon Romanovsky static int rxe_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init, 5288700e3e7SMoni Shoua struct ib_udata *udata) 5298700e3e7SMoni Shoua { 530514aee66SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibqp->device); 531514aee66SLeon Romanovsky struct rxe_pd *pd = to_rpd(ibqp->pd); 532514aee66SLeon Romanovsky struct rxe_qp *qp = to_rqp(ibqp); 5330c43ab37SJason Gunthorpe struct rxe_create_qp_resp __user *uresp = NULL; 5345bf944f2SBob Pearson int err, cleanup_err; 5350c43ab37SJason Gunthorpe 5360c43ab37SJason Gunthorpe if (udata) { 5375bf944f2SBob Pearson if (udata->inlen) { 5385bf944f2SBob Pearson err = -EINVAL; 5395bf944f2SBob Pearson rxe_dbg_dev(rxe, "malformed udata, err = %d", err); 5405bf944f2SBob Pearson goto err_out; 5410c43ab37SJason Gunthorpe } 5428700e3e7SMoni Shoua 5435bf944f2SBob Pearson if (udata->outlen < sizeof(*uresp)) { 5445bf944f2SBob Pearson err = -EINVAL; 5455bf944f2SBob Pearson rxe_dbg_dev(rxe, "malformed udata, err = %d", err); 5465bf944f2SBob Pearson goto err_out; 5475bf944f2SBob Pearson } 548514aee66SLeon Romanovsky 5495bcf5a59SBob Pearson qp->is_user = true; 5505bf944f2SBob Pearson uresp = udata->outbuf; 5515bcf5a59SBob Pearson } else { 5525bcf5a59SBob Pearson qp->is_user = false; 5538700e3e7SMoni Shoua } 5548700e3e7SMoni Shoua 5555bf944f2SBob Pearson if (init->create_flags) { 5565bf944f2SBob Pearson err = -EOPNOTSUPP; 5575bf944f2SBob Pearson rxe_dbg_dev(rxe, "unsupported create_flags, err = %d", err); 5585bf944f2SBob Pearson goto err_out; 5595bf944f2SBob Pearson } 5605bf944f2SBob Pearson 5615bf944f2SBob Pearson err = rxe_qp_chk_init(rxe, init); 5625bf944f2SBob Pearson if (err) { 5635bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad init attr, err = %d", err); 5645bf944f2SBob Pearson goto err_out; 5655bf944f2SBob Pearson } 5665bf944f2SBob Pearson 567514aee66SLeon Romanovsky err = rxe_add_to_pool(&rxe->qp_pool, qp); 5685bf944f2SBob Pearson if (err) { 5695bf944f2SBob Pearson rxe_dbg_dev(rxe, "unable to create qp, err = %d", err); 5705bf944f2SBob Pearson goto err_out; 5715bf944f2SBob Pearson } 5728700e3e7SMoni Shoua 573514aee66SLeon Romanovsky err = rxe_qp_from_init(rxe, qp, pd, init, uresp, ibqp->pd, udata); 5745bf944f2SBob Pearson if (err) { 5755bf944f2SBob Pearson rxe_dbg_qp(qp, "create qp failed, err = %d", err); 5765bf944f2SBob Pearson goto err_cleanup; 5775bf944f2SBob Pearson } 5788700e3e7SMoni Shoua 579215d0a75SBob Pearson rxe_finalize(qp); 580514aee66SLeon Romanovsky return 0; 581514aee66SLeon Romanovsky 5825bf944f2SBob Pearson err_cleanup: 5835bf944f2SBob Pearson cleanup_err = rxe_cleanup(qp); 5845bf944f2SBob Pearson if (cleanup_err) 5855bf944f2SBob Pearson rxe_err_qp(qp, "cleanup failed, err = %d", cleanup_err); 5865bf944f2SBob Pearson err_out: 5875bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 588514aee66SLeon Romanovsky return err; 5898700e3e7SMoni Shoua } 5908700e3e7SMoni Shoua 5918700e3e7SMoni Shoua static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 5928700e3e7SMoni Shoua int mask, struct ib_udata *udata) 5938700e3e7SMoni Shoua { 5948700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 5958700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 5965bf944f2SBob Pearson int err; 5978700e3e7SMoni Shoua 5985bf944f2SBob Pearson if (mask & ~IB_QP_ATTR_STANDARD_BITS) { 5995bf944f2SBob Pearson err = -EOPNOTSUPP; 6005bf944f2SBob Pearson rxe_dbg_qp(qp, "unsupported mask = 0x%x, err = %d", 6015bf944f2SBob Pearson mask, err); 6025bf944f2SBob Pearson goto err_out; 6035bf944f2SBob Pearson } 60426e990baSJason Gunthorpe 6058700e3e7SMoni Shoua err = rxe_qp_chk_attr(rxe, qp, attr, mask); 6065bf944f2SBob Pearson if (err) { 6075bf944f2SBob Pearson rxe_dbg_qp(qp, "bad mask/attr, err = %d", err); 6085bf944f2SBob Pearson goto err_out; 6095bf944f2SBob Pearson } 6108700e3e7SMoni Shoua 6118700e3e7SMoni Shoua err = rxe_qp_from_attr(qp, attr, mask, udata); 6125bf944f2SBob Pearson if (err) { 6135bf944f2SBob Pearson rxe_dbg_qp(qp, "modify qp failed, err = %d", err); 6145bf944f2SBob Pearson goto err_out; 6155bf944f2SBob Pearson } 6168700e3e7SMoni Shoua 617104f062fSZhu Yanjun if ((mask & IB_QP_AV) && (attr->ah_attr.ah_flags & IB_AH_GRH)) 618104f062fSZhu Yanjun qp->src_port = rdma_get_udp_sport(attr->ah_attr.grh.flow_label, 619104f062fSZhu Yanjun qp->ibqp.qp_num, 620104f062fSZhu Yanjun qp->attr.dest_qp_num); 621104f062fSZhu Yanjun 6228700e3e7SMoni Shoua return 0; 6235bf944f2SBob Pearson 6245bf944f2SBob Pearson err_out: 6255bf944f2SBob Pearson rxe_err_qp(qp, "returned err = %d", err); 6265bf944f2SBob Pearson return err; 6278700e3e7SMoni Shoua } 6288700e3e7SMoni Shoua 6298700e3e7SMoni Shoua static int rxe_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 6308700e3e7SMoni Shoua int mask, struct ib_qp_init_attr *init) 6318700e3e7SMoni Shoua { 6328700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 6338700e3e7SMoni Shoua 6348700e3e7SMoni Shoua rxe_qp_to_init(qp, init); 6358700e3e7SMoni Shoua rxe_qp_to_attr(qp, attr, mask); 6368700e3e7SMoni Shoua 6378700e3e7SMoni Shoua return 0; 6388700e3e7SMoni Shoua } 6398700e3e7SMoni Shoua 640c4367a26SShamir Rabinovitch static int rxe_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) 6418700e3e7SMoni Shoua { 6428700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 6435bf944f2SBob Pearson int err; 644f9f48460SBob Pearson 6455bf944f2SBob Pearson err = rxe_qp_chk_destroy(qp); 6465bf944f2SBob Pearson if (err) { 6475bf944f2SBob Pearson rxe_dbg_qp(qp, "unable to destroy qp, err = %d", err); 6485bf944f2SBob Pearson goto err_out; 6498700e3e7SMoni Shoua } 6508700e3e7SMoni Shoua 6515bf944f2SBob Pearson err = rxe_cleanup(qp); 6525bf944f2SBob Pearson if (err) 6535bf944f2SBob Pearson rxe_err_qp(qp, "cleanup failed, err = %d", err); 6545bf944f2SBob Pearson 6555bf944f2SBob Pearson return 0; 6565bf944f2SBob Pearson 6575bf944f2SBob Pearson err_out: 6585bf944f2SBob Pearson rxe_err_qp(qp, "returned err = %d", err); 6595bf944f2SBob Pearson return err; 6605bf944f2SBob Pearson } 6615bf944f2SBob Pearson 6625bf944f2SBob Pearson /* send wr */ 663f605f26eSBob Pearson 664f605f26eSBob Pearson /* sanity check incoming send work request */ 665f696bf6dSBart Van Assche static int validate_send_wr(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 666f605f26eSBob Pearson unsigned int *maskp, unsigned int *lengthp) 6678700e3e7SMoni Shoua { 6688700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 6698700e3e7SMoni Shoua struct rxe_sq *sq = &qp->sq; 670f605f26eSBob Pearson unsigned int mask = 0; 671f605f26eSBob Pearson unsigned long length = 0; 672f605f26eSBob Pearson int err = -EINVAL; 673f605f26eSBob Pearson int i; 6748700e3e7SMoni Shoua 675f605f26eSBob Pearson do { 676f605f26eSBob Pearson mask = wr_opcode_mask(ibwr->opcode, qp); 677f605f26eSBob Pearson if (!mask) { 678f605f26eSBob Pearson rxe_err_qp(qp, "bad wr opcode for qp type"); 679f605f26eSBob Pearson break; 6805bf944f2SBob Pearson } 6818700e3e7SMoni Shoua 682f605f26eSBob Pearson if (num_sge > sq->max_sge) { 683f605f26eSBob Pearson rxe_err_qp(qp, "num_sge > max_sge"); 684f605f26eSBob Pearson break; 685f605f26eSBob Pearson } 686f605f26eSBob Pearson 687f605f26eSBob Pearson length = 0; 688f605f26eSBob Pearson for (i = 0; i < ibwr->num_sge; i++) 689f605f26eSBob Pearson length += ibwr->sg_list[i].length; 690f605f26eSBob Pearson 691f605f26eSBob Pearson if (length > (1UL << 31)) { 692f605f26eSBob Pearson rxe_err_qp(qp, "message length too long"); 693f605f26eSBob Pearson break; 694f605f26eSBob Pearson } 695f605f26eSBob Pearson 696f605f26eSBob Pearson if (mask & WR_ATOMIC_MASK) { 6975bf944f2SBob Pearson if (length != 8) { 698f605f26eSBob Pearson rxe_err_qp(qp, "atomic length != 8"); 699f605f26eSBob Pearson break; 7005bf944f2SBob Pearson } 7015bf944f2SBob Pearson if (atomic_wr(ibwr)->remote_addr & 0x7) { 702f605f26eSBob Pearson rxe_err_qp(qp, "misaligned atomic address"); 703f605f26eSBob Pearson break; 704f605f26eSBob Pearson } 705f605f26eSBob Pearson } 706f605f26eSBob Pearson if (ibwr->send_flags & IB_SEND_INLINE) { 707f605f26eSBob Pearson if (!(mask & WR_INLINE_MASK)) { 708f605f26eSBob Pearson rxe_err_qp(qp, "opcode doesn't support inline data"); 709f605f26eSBob Pearson break; 710f605f26eSBob Pearson } 711f605f26eSBob Pearson if (length > sq->max_inline) { 712f605f26eSBob Pearson rxe_err_qp(qp, "inline length too big"); 713f605f26eSBob Pearson break; 7145bf944f2SBob Pearson } 7158700e3e7SMoni Shoua } 7168700e3e7SMoni Shoua 717f605f26eSBob Pearson err = 0; 718f605f26eSBob Pearson } while (0); 719f605f26eSBob Pearson 720f605f26eSBob Pearson *maskp = mask; 721f605f26eSBob Pearson *lengthp = (int)length; 722f605f26eSBob Pearson 723f605f26eSBob Pearson return err; 7245bf944f2SBob Pearson } 7258700e3e7SMoni Shoua 726f605f26eSBob Pearson static int init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr, 727f696bf6dSBart Van Assche const struct ib_send_wr *ibwr) 7288700e3e7SMoni Shoua { 7298700e3e7SMoni Shoua wr->wr_id = ibwr->wr_id; 7308700e3e7SMoni Shoua wr->opcode = ibwr->opcode; 7318700e3e7SMoni Shoua wr->send_flags = ibwr->send_flags; 7328700e3e7SMoni Shoua 7338700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_UD || 7348700e3e7SMoni Shoua qp_type(qp) == IB_QPT_GSI) { 7353b87e082SBob Pearson struct ib_ah *ibah = ud_wr(ibwr)->ah; 7363b87e082SBob Pearson 7378700e3e7SMoni Shoua wr->wr.ud.remote_qpn = ud_wr(ibwr)->remote_qpn; 7388700e3e7SMoni Shoua wr->wr.ud.remote_qkey = ud_wr(ibwr)->remote_qkey; 7393b87e082SBob Pearson wr->wr.ud.ah_num = to_rah(ibah)->ah_num; 7408700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_GSI) 7418700e3e7SMoni Shoua wr->wr.ud.pkey_index = ud_wr(ibwr)->pkey_index; 742f605f26eSBob Pearson 743f605f26eSBob Pearson switch (wr->opcode) { 744f605f26eSBob Pearson case IB_WR_SEND_WITH_IMM: 7458700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 746f605f26eSBob Pearson break; 747f605f26eSBob Pearson case IB_WR_SEND: 748f605f26eSBob Pearson break; 749f605f26eSBob Pearson default: 750f605f26eSBob Pearson rxe_err_qp(qp, "bad wr opcode %d for UD/GSI QP", 751f605f26eSBob Pearson wr->opcode); 752f605f26eSBob Pearson return -EINVAL; 753f605f26eSBob Pearson } 7548700e3e7SMoni Shoua } else { 7558700e3e7SMoni Shoua switch (wr->opcode) { 7568700e3e7SMoni Shoua case IB_WR_RDMA_WRITE_WITH_IMM: 7578700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 758df561f66SGustavo A. R. Silva fallthrough; 7598700e3e7SMoni Shoua case IB_WR_RDMA_READ: 7608700e3e7SMoni Shoua case IB_WR_RDMA_WRITE: 7618700e3e7SMoni Shoua wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr; 7628700e3e7SMoni Shoua wr->wr.rdma.rkey = rdma_wr(ibwr)->rkey; 7638700e3e7SMoni Shoua break; 7648700e3e7SMoni Shoua case IB_WR_SEND_WITH_IMM: 7658700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 7668700e3e7SMoni Shoua break; 7678700e3e7SMoni Shoua case IB_WR_SEND_WITH_INV: 7688700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 7698700e3e7SMoni Shoua break; 770f605f26eSBob Pearson case IB_WR_RDMA_READ_WITH_INV: 771f605f26eSBob Pearson wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 772f605f26eSBob Pearson wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr; 773f605f26eSBob Pearson wr->wr.rdma.rkey = rdma_wr(ibwr)->rkey; 774f605f26eSBob Pearson break; 7758700e3e7SMoni Shoua case IB_WR_ATOMIC_CMP_AND_SWP: 7768700e3e7SMoni Shoua case IB_WR_ATOMIC_FETCH_AND_ADD: 7778700e3e7SMoni Shoua wr->wr.atomic.remote_addr = 7788700e3e7SMoni Shoua atomic_wr(ibwr)->remote_addr; 7798700e3e7SMoni Shoua wr->wr.atomic.compare_add = 7808700e3e7SMoni Shoua atomic_wr(ibwr)->compare_add; 7818700e3e7SMoni Shoua wr->wr.atomic.swap = atomic_wr(ibwr)->swap; 7828700e3e7SMoni Shoua wr->wr.atomic.rkey = atomic_wr(ibwr)->rkey; 7838700e3e7SMoni Shoua break; 7848700e3e7SMoni Shoua case IB_WR_LOCAL_INV: 7858700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 7868700e3e7SMoni Shoua break; 7878700e3e7SMoni Shoua case IB_WR_REG_MR: 7888700e3e7SMoni Shoua wr->wr.reg.mr = reg_wr(ibwr)->mr; 7898700e3e7SMoni Shoua wr->wr.reg.key = reg_wr(ibwr)->key; 7908700e3e7SMoni Shoua wr->wr.reg.access = reg_wr(ibwr)->access; 7918700e3e7SMoni Shoua break; 792f605f26eSBob Pearson case IB_WR_SEND: 793f605f26eSBob Pearson case IB_WR_BIND_MW: 794f605f26eSBob Pearson case IB_WR_FLUSH: 795f605f26eSBob Pearson case IB_WR_ATOMIC_WRITE: 796f605f26eSBob Pearson break; 7978700e3e7SMoni Shoua default: 798f605f26eSBob Pearson rxe_err_qp(qp, "unsupported wr opcode %d", 799f605f26eSBob Pearson wr->opcode); 800f605f26eSBob Pearson return -EINVAL; 8018700e3e7SMoni Shoua } 8028700e3e7SMoni Shoua } 803f605f26eSBob Pearson 804f605f26eSBob Pearson return 0; 8058700e3e7SMoni Shoua } 8068700e3e7SMoni Shoua 807086f580cSBob Pearson static void copy_inline_data_to_wqe(struct rxe_send_wqe *wqe, 808086f580cSBob Pearson const struct ib_send_wr *ibwr) 809086f580cSBob Pearson { 810086f580cSBob Pearson struct ib_sge *sge = ibwr->sg_list; 811086f580cSBob Pearson u8 *p = wqe->dma.inline_data; 812086f580cSBob Pearson int i; 813086f580cSBob Pearson 814086f580cSBob Pearson for (i = 0; i < ibwr->num_sge; i++, sge++) { 8158d7c7c0eSJason Gunthorpe memcpy(p, ib_virt_dma_to_page(sge->addr), sge->length); 816086f580cSBob Pearson p += sge->length; 817086f580cSBob Pearson } 818086f580cSBob Pearson } 819086f580cSBob Pearson 820f605f26eSBob Pearson static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 8218700e3e7SMoni Shoua unsigned int mask, unsigned int length, 8228700e3e7SMoni Shoua struct rxe_send_wqe *wqe) 8238700e3e7SMoni Shoua { 8248700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 825f605f26eSBob Pearson int err; 8268700e3e7SMoni Shoua 827f605f26eSBob Pearson err = init_send_wr(qp, &wqe->wr, ibwr); 828f605f26eSBob Pearson if (err) 829f605f26eSBob Pearson return err; 8308700e3e7SMoni Shoua 831dc78074aSBob Pearson /* local operation */ 832886441fbSBob Pearson if (unlikely(mask & WR_LOCAL_OP_MASK)) { 833dc78074aSBob Pearson wqe->mask = mask; 834dc78074aSBob Pearson wqe->state = wqe_state_posted; 835f605f26eSBob Pearson return 0; 836dc78074aSBob Pearson } 837dc78074aSBob Pearson 838086f580cSBob Pearson if (unlikely(ibwr->send_flags & IB_SEND_INLINE)) 839086f580cSBob Pearson copy_inline_data_to_wqe(wqe, ibwr); 840086f580cSBob Pearson else 8418700e3e7SMoni Shoua memcpy(wqe->dma.sge, ibwr->sg_list, 8428700e3e7SMoni Shoua num_sge * sizeof(struct ib_sge)); 8438700e3e7SMoni Shoua 844a6544a62SBart Van Assche wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr : 845a6544a62SBart Van Assche mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0; 8468700e3e7SMoni Shoua wqe->mask = mask; 8478700e3e7SMoni Shoua wqe->dma.length = length; 8488700e3e7SMoni Shoua wqe->dma.resid = length; 8498700e3e7SMoni Shoua wqe->dma.num_sge = num_sge; 8508700e3e7SMoni Shoua wqe->dma.cur_sge = 0; 8518700e3e7SMoni Shoua wqe->dma.sge_offset = 0; 8528700e3e7SMoni Shoua wqe->state = wqe_state_posted; 8538700e3e7SMoni Shoua wqe->ssn = atomic_add_return(1, &qp->ssn); 8548700e3e7SMoni Shoua 8558700e3e7SMoni Shoua return 0; 8568700e3e7SMoni Shoua } 8578700e3e7SMoni Shoua 858f605f26eSBob Pearson static int post_one_send(struct rxe_qp *qp, const struct ib_send_wr *ibwr) 859f605f26eSBob Pearson { 860f605f26eSBob Pearson int err; 861f605f26eSBob Pearson struct rxe_sq *sq = &qp->sq; 862f605f26eSBob Pearson struct rxe_send_wqe *send_wqe; 863f605f26eSBob Pearson unsigned int mask; 864f605f26eSBob Pearson unsigned int length; 865f605f26eSBob Pearson int full; 866f605f26eSBob Pearson 867f605f26eSBob Pearson err = validate_send_wr(qp, ibwr, &mask, &length); 868f605f26eSBob Pearson if (err) 869f605f26eSBob Pearson return err; 870f605f26eSBob Pearson 871f605f26eSBob Pearson full = queue_full(sq->queue, QUEUE_TYPE_FROM_ULP); 872f605f26eSBob Pearson if (unlikely(full)) { 873f605f26eSBob Pearson rxe_err_qp(qp, "send queue full"); 874f605f26eSBob Pearson return -ENOMEM; 875f605f26eSBob Pearson } 876f605f26eSBob Pearson 877f605f26eSBob Pearson send_wqe = queue_producer_addr(sq->queue, QUEUE_TYPE_FROM_ULP); 878f605f26eSBob Pearson err = init_send_wqe(qp, ibwr, mask, length, send_wqe); 879f605f26eSBob Pearson if (!err) 880f605f26eSBob Pearson queue_advance_producer(sq->queue, QUEUE_TYPE_FROM_ULP); 881f605f26eSBob Pearson 882f605f26eSBob Pearson return err; 883f605f26eSBob Pearson } 884f605f26eSBob Pearson 885f605f26eSBob Pearson static int rxe_post_send_kernel(struct rxe_qp *qp, 886f605f26eSBob Pearson const struct ib_send_wr *ibwr, 887d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 8888700e3e7SMoni Shoua { 8898700e3e7SMoni Shoua int err = 0; 890f605f26eSBob Pearson unsigned long flags; 89113c7bb72SBob Pearson int good = 0; 8928700e3e7SMoni Shoua 893f605f26eSBob Pearson spin_lock_irqsave(&qp->sq.sq_lock, flags); 894f605f26eSBob Pearson while (ibwr) { 895f605f26eSBob Pearson err = post_one_send(qp, ibwr); 8968700e3e7SMoni Shoua if (err) { 897f605f26eSBob Pearson *bad_wr = ibwr; 8988700e3e7SMoni Shoua break; 89913c7bb72SBob Pearson } else { 90013c7bb72SBob Pearson good++; 9018700e3e7SMoni Shoua } 902f605f26eSBob Pearson ibwr = ibwr->next; 9038700e3e7SMoni Shoua } 904f605f26eSBob Pearson spin_unlock_irqrestore(&qp->sq.sq_lock, flags); 9058700e3e7SMoni Shoua 90613c7bb72SBob Pearson /* kickoff processing of any posted wqes */ 90713c7bb72SBob Pearson if (good) 908dccb23f6SBob Pearson rxe_sched_task(&qp->req.task); 9095bf944f2SBob Pearson 910b5f3fe27SGuoqing Jiang spin_lock_irqsave(&qp->state_lock, flags); 911f605f26eSBob Pearson if (qp_state(qp) == IB_QPS_ERR) 912dccb23f6SBob Pearson rxe_sched_task(&qp->comp.task); 913b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 9148700e3e7SMoni Shoua 9158700e3e7SMoni Shoua return err; 9168700e3e7SMoni Shoua } 9178700e3e7SMoni Shoua 918d34ac5cdSBart Van Assche static int rxe_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, 919d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 920063af595SParav Pandit { 921063af595SParav Pandit struct rxe_qp *qp = to_rqp(ibqp); 9225bf944f2SBob Pearson int err; 923b5f3fe27SGuoqing Jiang unsigned long flags; 924063af595SParav Pandit 925b5f3fe27SGuoqing Jiang spin_lock_irqsave(&qp->state_lock, flags); 926f605f26eSBob Pearson /* caller has already called destroy_qp */ 927f605f26eSBob Pearson if (WARN_ON_ONCE(!qp->valid)) { 928b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 929f605f26eSBob Pearson rxe_err_qp(qp, "qp has been destroyed"); 930f605f26eSBob Pearson return -EINVAL; 931063af595SParav Pandit } 932063af595SParav Pandit 93398e891b5SBob Pearson if (unlikely(qp_state(qp) < IB_QPS_RTS)) { 934b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 935063af595SParav Pandit *bad_wr = wr; 936f605f26eSBob Pearson rxe_err_qp(qp, "qp not ready to send"); 937f605f26eSBob Pearson return -EINVAL; 938063af595SParav Pandit } 939b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 940063af595SParav Pandit 941063af595SParav Pandit if (qp->is_user) { 942063af595SParav Pandit /* Utilize process context to do protocol processing */ 943dccb23f6SBob Pearson rxe_run_task(&qp->req.task); 9445bf944f2SBob Pearson } else { 9455bf944f2SBob Pearson err = rxe_post_send_kernel(qp, wr, bad_wr); 9465bf944f2SBob Pearson if (err) 947f605f26eSBob Pearson return err; 9485bf944f2SBob Pearson } 9495bf944f2SBob Pearson 950063af595SParav Pandit return 0; 9515bf944f2SBob Pearson } 9525bf944f2SBob Pearson 9535bf944f2SBob Pearson /* recv wr */ 9545bf944f2SBob Pearson static int post_one_recv(struct rxe_rq *rq, const struct ib_recv_wr *ibwr) 9555bf944f2SBob Pearson { 9565bf944f2SBob Pearson int i; 9575bf944f2SBob Pearson unsigned long length; 9585bf944f2SBob Pearson struct rxe_recv_wqe *recv_wqe; 9595bf944f2SBob Pearson int num_sge = ibwr->num_sge; 9605bf944f2SBob Pearson int full; 9615bf944f2SBob Pearson int err; 9625bf944f2SBob Pearson 9635bf944f2SBob Pearson full = queue_full(rq->queue, QUEUE_TYPE_FROM_ULP); 9645bf944f2SBob Pearson if (unlikely(full)) { 9655bf944f2SBob Pearson err = -ENOMEM; 9665bf944f2SBob Pearson rxe_dbg("queue full"); 9675bf944f2SBob Pearson goto err_out; 9685bf944f2SBob Pearson } 9695bf944f2SBob Pearson 9705bf944f2SBob Pearson if (unlikely(num_sge > rq->max_sge)) { 9715bf944f2SBob Pearson err = -EINVAL; 9725bf944f2SBob Pearson rxe_dbg("bad num_sge > max_sge"); 9735bf944f2SBob Pearson goto err_out; 9745bf944f2SBob Pearson } 9755bf944f2SBob Pearson 9765bf944f2SBob Pearson length = 0; 9775bf944f2SBob Pearson for (i = 0; i < num_sge; i++) 9785bf944f2SBob Pearson length += ibwr->sg_list[i].length; 9795bf944f2SBob Pearson 9805bf944f2SBob Pearson /* IBA max message size is 2^31 */ 9815bf944f2SBob Pearson if (length >= (1UL<<31)) { 9825bf944f2SBob Pearson err = -EINVAL; 9835bf944f2SBob Pearson rxe_dbg("message length too long"); 9845bf944f2SBob Pearson goto err_out; 9855bf944f2SBob Pearson } 9865bf944f2SBob Pearson 9875bf944f2SBob Pearson recv_wqe = queue_producer_addr(rq->queue, QUEUE_TYPE_FROM_ULP); 9885bf944f2SBob Pearson 9895bf944f2SBob Pearson recv_wqe->wr_id = ibwr->wr_id; 9905bf944f2SBob Pearson recv_wqe->dma.length = length; 9915bf944f2SBob Pearson recv_wqe->dma.resid = length; 9925bf944f2SBob Pearson recv_wqe->dma.num_sge = num_sge; 9935bf944f2SBob Pearson recv_wqe->dma.cur_sge = 0; 9945bf944f2SBob Pearson recv_wqe->dma.sge_offset = 0; 9955bf944f2SBob Pearson memcpy(recv_wqe->dma.sge, ibwr->sg_list, 9965bf944f2SBob Pearson num_sge * sizeof(struct ib_sge)); 9975bf944f2SBob Pearson 9985bf944f2SBob Pearson queue_advance_producer(rq->queue, QUEUE_TYPE_FROM_ULP); 9995bf944f2SBob Pearson 10005bf944f2SBob Pearson return 0; 10015bf944f2SBob Pearson 10025bf944f2SBob Pearson err_out: 10035bf944f2SBob Pearson rxe_dbg("returned err = %d", err); 10045bf944f2SBob Pearson return err; 1005063af595SParav Pandit } 1006063af595SParav Pandit 1007d34ac5cdSBart Van Assche static int rxe_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, 1008d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr) 10098700e3e7SMoni Shoua { 10108700e3e7SMoni Shoua int err = 0; 10118700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 10128700e3e7SMoni Shoua struct rxe_rq *rq = &qp->rq; 1013a099b085SBob Pearson unsigned long flags; 10148700e3e7SMoni Shoua 1015b5f3fe27SGuoqing Jiang spin_lock_irqsave(&qp->state_lock, flags); 1016f605f26eSBob Pearson /* caller has already called destroy_qp */ 1017f605f26eSBob Pearson if (WARN_ON_ONCE(!qp->valid)) { 1018b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 1019f605f26eSBob Pearson rxe_err_qp(qp, "qp has been destroyed"); 1020f605f26eSBob Pearson return -EINVAL; 10218700e3e7SMoni Shoua } 10228700e3e7SMoni Shoua 1023f605f26eSBob Pearson /* see C10-97.2.1 */ 1024f605f26eSBob Pearson if (unlikely((qp_state(qp) < IB_QPS_INIT))) { 1025b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 1026f605f26eSBob Pearson *bad_wr = wr; 1027f605f26eSBob Pearson rxe_dbg_qp(qp, "qp not ready to post recv"); 1028f605f26eSBob Pearson return -EINVAL; 1029f605f26eSBob Pearson } 1030b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 1031f605f26eSBob Pearson 10328700e3e7SMoni Shoua if (unlikely(qp->srq)) { 10338700e3e7SMoni Shoua *bad_wr = wr; 1034f605f26eSBob Pearson rxe_dbg_qp(qp, "qp has srq, use post_srq_recv instead"); 1035f605f26eSBob Pearson return -EINVAL; 10368700e3e7SMoni Shoua } 10378700e3e7SMoni Shoua 1038a099b085SBob Pearson spin_lock_irqsave(&rq->producer_lock, flags); 10398700e3e7SMoni Shoua 10408700e3e7SMoni Shoua while (wr) { 10418700e3e7SMoni Shoua err = post_one_recv(rq, wr); 10428700e3e7SMoni Shoua if (unlikely(err)) { 10438700e3e7SMoni Shoua *bad_wr = wr; 10448700e3e7SMoni Shoua break; 10458700e3e7SMoni Shoua } 10468700e3e7SMoni Shoua wr = wr->next; 10478700e3e7SMoni Shoua } 10488700e3e7SMoni Shoua 1049a099b085SBob Pearson spin_unlock_irqrestore(&rq->producer_lock, flags); 10508700e3e7SMoni Shoua 1051b5f3fe27SGuoqing Jiang spin_lock_irqsave(&qp->state_lock, flags); 1052a588429aSBob Pearson if (qp_state(qp) == IB_QPS_ERR) 1053dccb23f6SBob Pearson rxe_sched_task(&qp->resp.task); 1054b5f3fe27SGuoqing Jiang spin_unlock_irqrestore(&qp->state_lock, flags); 10555bf944f2SBob Pearson 10568700e3e7SMoni Shoua return err; 10578700e3e7SMoni Shoua } 10588700e3e7SMoni Shoua 10595bf944f2SBob Pearson /* cq */ 1060e39afe3dSLeon Romanovsky static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, 10618700e3e7SMoni Shoua struct ib_udata *udata) 10628700e3e7SMoni Shoua { 1063e39afe3dSLeon Romanovsky struct ib_device *dev = ibcq->device; 10648700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 1065e39afe3dSLeon Romanovsky struct rxe_cq *cq = to_rcq(ibcq); 10660c43ab37SJason Gunthorpe struct rxe_create_cq_resp __user *uresp = NULL; 10675bf944f2SBob Pearson int err, cleanup_err; 10680c43ab37SJason Gunthorpe 10690c43ab37SJason Gunthorpe if (udata) { 10705bf944f2SBob Pearson if (udata->outlen < sizeof(*uresp)) { 10715bf944f2SBob Pearson err = -EINVAL; 10725bf944f2SBob Pearson rxe_dbg_dev(rxe, "malformed udata, err = %d", err); 10735bf944f2SBob Pearson goto err_out; 10745bf944f2SBob Pearson } 10750c43ab37SJason Gunthorpe uresp = udata->outbuf; 10760c43ab37SJason Gunthorpe } 10778700e3e7SMoni Shoua 10785bf944f2SBob Pearson if (attr->flags) { 10795bf944f2SBob Pearson err = -EOPNOTSUPP; 10805bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad attr->flags, err = %d", err); 10815bf944f2SBob Pearson goto err_out; 10825bf944f2SBob Pearson } 10838700e3e7SMoni Shoua 1084b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector); 10855bf944f2SBob Pearson if (err) { 10865bf944f2SBob Pearson rxe_dbg_dev(rxe, "bad init attributes, err = %d", err); 10875bf944f2SBob Pearson goto err_out; 10885bf944f2SBob Pearson } 10895bf944f2SBob Pearson 10905bf944f2SBob Pearson err = rxe_add_to_pool(&rxe->cq_pool, cq); 10915bf944f2SBob Pearson if (err) { 10925bf944f2SBob Pearson rxe_dbg_dev(rxe, "unable to create cq, err = %d", err); 10935bf944f2SBob Pearson goto err_out; 10945bf944f2SBob Pearson } 10958700e3e7SMoni Shoua 1096ff23dfa1SShamir Rabinovitch err = rxe_cq_from_init(rxe, cq, attr->cqe, attr->comp_vector, udata, 1097ff23dfa1SShamir Rabinovitch uresp); 10985bf944f2SBob Pearson if (err) { 10995bf944f2SBob Pearson rxe_dbg_cq(cq, "create cq failed, err = %d", err); 11005bf944f2SBob Pearson goto err_cleanup; 11018700e3e7SMoni Shoua } 11028700e3e7SMoni Shoua 110343d781b9SLeon Romanovsky return 0; 11045bf944f2SBob Pearson 11055bf944f2SBob Pearson err_cleanup: 11065bf944f2SBob Pearson cleanup_err = rxe_cleanup(cq); 11075bf944f2SBob Pearson if (cleanup_err) 11085bf944f2SBob Pearson rxe_err_cq(cq, "cleanup failed, err = %d", cleanup_err); 11095bf944f2SBob Pearson err_out: 11105bf944f2SBob Pearson rxe_err_dev(rxe, "returned err = %d", err); 11115bf944f2SBob Pearson return err; 11128700e3e7SMoni Shoua } 11138700e3e7SMoni Shoua 11148700e3e7SMoni Shoua static int rxe_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) 11158700e3e7SMoni Shoua { 11168700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 11178700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibcq->device); 11180c43ab37SJason Gunthorpe struct rxe_resize_cq_resp __user *uresp = NULL; 11195bf944f2SBob Pearson int err; 11200c43ab37SJason Gunthorpe 11210c43ab37SJason Gunthorpe if (udata) { 11225bf944f2SBob Pearson if (udata->outlen < sizeof(*uresp)) { 11235bf944f2SBob Pearson err = -EINVAL; 11245bf944f2SBob Pearson rxe_dbg_cq(cq, "malformed udata"); 11255bf944f2SBob Pearson goto err_out; 11265bf944f2SBob Pearson } 11270c43ab37SJason Gunthorpe uresp = udata->outbuf; 11280c43ab37SJason Gunthorpe } 11298700e3e7SMoni Shoua 1130b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, cq, cqe, 0); 11315bf944f2SBob Pearson if (err) { 11325bf944f2SBob Pearson rxe_dbg_cq(cq, "bad attr, err = %d", err); 11335bf944f2SBob Pearson goto err_out; 11345bf944f2SBob Pearson } 1135692373d1SYunsheng Lin 11365bf944f2SBob Pearson err = rxe_cq_resize_queue(cq, cqe, uresp, udata); 11375bf944f2SBob Pearson if (err) { 11385bf944f2SBob Pearson rxe_dbg_cq(cq, "resize cq failed, err = %d", err); 11395bf944f2SBob Pearson goto err_out; 11405bf944f2SBob Pearson } 11415bf944f2SBob Pearson 11425bf944f2SBob Pearson return 0; 11435bf944f2SBob Pearson 11445bf944f2SBob Pearson err_out: 11455bf944f2SBob Pearson rxe_err_cq(cq, "returned err = %d", err); 11465bf944f2SBob Pearson return err; 11478700e3e7SMoni Shoua } 11488700e3e7SMoni Shoua 11498700e3e7SMoni Shoua static int rxe_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc) 11508700e3e7SMoni Shoua { 11518700e3e7SMoni Shoua int i; 11528700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 11538700e3e7SMoni Shoua struct rxe_cqe *cqe; 1154a099b085SBob Pearson unsigned long flags; 11558700e3e7SMoni Shoua 1156a099b085SBob Pearson spin_lock_irqsave(&cq->cq_lock, flags); 11578700e3e7SMoni Shoua for (i = 0; i < num_entries; i++) { 1158a77a5238SBob Pearson cqe = queue_head(cq->queue, QUEUE_TYPE_TO_ULP); 11598700e3e7SMoni Shoua if (!cqe) 11605bf944f2SBob Pearson break; /* queue empty */ 11618700e3e7SMoni Shoua 11628700e3e7SMoni Shoua memcpy(wc++, &cqe->ibwc, sizeof(*wc)); 1163a77a5238SBob Pearson queue_advance_consumer(cq->queue, QUEUE_TYPE_TO_ULP); 11648700e3e7SMoni Shoua } 1165a099b085SBob Pearson spin_unlock_irqrestore(&cq->cq_lock, flags); 11668700e3e7SMoni Shoua 11678700e3e7SMoni Shoua return i; 11688700e3e7SMoni Shoua } 11698700e3e7SMoni Shoua 11708700e3e7SMoni Shoua static int rxe_peek_cq(struct ib_cq *ibcq, int wc_cnt) 11718700e3e7SMoni Shoua { 11728700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 11735bcf5a59SBob Pearson int count; 11745bcf5a59SBob Pearson 1175a77a5238SBob Pearson count = queue_count(cq->queue, QUEUE_TYPE_TO_ULP); 11768700e3e7SMoni Shoua 11778700e3e7SMoni Shoua return (count > wc_cnt) ? wc_cnt : count; 11788700e3e7SMoni Shoua } 11798700e3e7SMoni Shoua 11808700e3e7SMoni Shoua static int rxe_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) 11818700e3e7SMoni Shoua { 11828700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 1183accacb8fSAndrew Boyer int ret = 0; 11845bcf5a59SBob Pearson int empty; 1185a099b085SBob Pearson unsigned long irq_flags; 11868700e3e7SMoni Shoua 1187a099b085SBob Pearson spin_lock_irqsave(&cq->cq_lock, irq_flags); 1188350b6dd4SBob Pearson cq->notify |= flags & IB_CQ_SOLICITED_MASK; 1189a77a5238SBob Pearson empty = queue_empty(cq->queue, QUEUE_TYPE_TO_ULP); 11905bcf5a59SBob Pearson 11915bcf5a59SBob Pearson if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !empty) 1192accacb8fSAndrew Boyer ret = 1; 1193accacb8fSAndrew Boyer 1194a099b085SBob Pearson spin_unlock_irqrestore(&cq->cq_lock, irq_flags); 1195accacb8fSAndrew Boyer 1196accacb8fSAndrew Boyer return ret; 11978700e3e7SMoni Shoua } 11988700e3e7SMoni Shoua 11995bf944f2SBob Pearson static int rxe_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) 12005bf944f2SBob Pearson { 12015bf944f2SBob Pearson struct rxe_cq *cq = to_rcq(ibcq); 12025bf944f2SBob Pearson int err; 12035bf944f2SBob Pearson 12045bf944f2SBob Pearson /* See IBA C11-17: The CI shall return an error if this Verb is 12055bf944f2SBob Pearson * invoked while a Work Queue is still associated with the CQ. 12065bf944f2SBob Pearson */ 12075bf944f2SBob Pearson if (atomic_read(&cq->num_wq)) { 12085bf944f2SBob Pearson err = -EINVAL; 12095bf944f2SBob Pearson rxe_dbg_cq(cq, "still in use"); 12105bf944f2SBob Pearson goto err_out; 12115bf944f2SBob Pearson } 12125bf944f2SBob Pearson 12135bf944f2SBob Pearson err = rxe_cleanup(cq); 12145bf944f2SBob Pearson if (err) 12155bf944f2SBob Pearson rxe_err_cq(cq, "cleanup failed, err = %d", err); 12165bf944f2SBob Pearson 12175bf944f2SBob Pearson return 0; 12185bf944f2SBob Pearson 12195bf944f2SBob Pearson err_out: 12205bf944f2SBob Pearson rxe_err_cq(cq, "returned err = %d", err); 12215bf944f2SBob Pearson return err; 12225bf944f2SBob Pearson } 12235bf944f2SBob Pearson 12245bf944f2SBob Pearson /* mr */ 12258700e3e7SMoni Shoua static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access) 12268700e3e7SMoni Shoua { 12278700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 12288700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 1229364e282cSBob Pearson struct rxe_mr *mr; 123072a03627SBob Pearson int err; 12318700e3e7SMoni Shoua 123272a03627SBob Pearson mr = kzalloc(sizeof(*mr), GFP_KERNEL); 1233b6ba6855SLeon Romanovsky if (!mr) 1234b6ba6855SLeon Romanovsky return ERR_PTR(-ENOMEM); 123572a03627SBob Pearson 123672a03627SBob Pearson err = rxe_add_to_pool(&rxe->mr_pool, mr); 12375bf944f2SBob Pearson if (err) { 12385bf944f2SBob Pearson rxe_dbg_dev(rxe, "unable to create mr"); 123972a03627SBob Pearson goto err_free; 12405bf944f2SBob Pearson } 12418700e3e7SMoni Shoua 12423197706aSBob Pearson rxe_get(pd); 124358651bbbSBob Pearson mr->ibmr.pd = ibpd; 12442778b72bSBob Pearson mr->ibmr.device = ibpd->device; 124558651bbbSBob Pearson 124658651bbbSBob Pearson rxe_mr_init_dma(access, mr); 1247215d0a75SBob Pearson rxe_finalize(mr); 12488700e3e7SMoni Shoua return &mr->ibmr; 124972a03627SBob Pearson 125072a03627SBob Pearson err_free: 125172a03627SBob Pearson kfree(mr); 12525bf944f2SBob Pearson rxe_err_pd(pd, "returned err = %d", err); 125372a03627SBob Pearson return ERR_PTR(err); 12548700e3e7SMoni Shoua } 12558700e3e7SMoni Shoua 12565bf944f2SBob Pearson static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, u64 start, 12575bf944f2SBob Pearson u64 length, u64 iova, int access, 12585bf944f2SBob Pearson struct ib_udata *udata) 12598700e3e7SMoni Shoua { 12608700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 12618700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 1262364e282cSBob Pearson struct rxe_mr *mr; 12635bf944f2SBob Pearson int err, cleanup_err; 12648700e3e7SMoni Shoua 126502ed2537SBob Pearson if (access & ~RXE_ACCESS_SUPPORTED_MR) { 126602ed2537SBob Pearson rxe_err_pd(pd, "access = %#x not supported (%#x)", access, 126702ed2537SBob Pearson RXE_ACCESS_SUPPORTED_MR); 126802ed2537SBob Pearson return ERR_PTR(-EOPNOTSUPP); 126902ed2537SBob Pearson } 127002ed2537SBob Pearson 127172a03627SBob Pearson mr = kzalloc(sizeof(*mr), GFP_KERNEL); 1272b6ba6855SLeon Romanovsky if (!mr) 1273b6ba6855SLeon Romanovsky return ERR_PTR(-ENOMEM); 127472a03627SBob Pearson 127572a03627SBob Pearson err = rxe_add_to_pool(&rxe->mr_pool, mr); 12765bf944f2SBob Pearson if (err) { 12775bf944f2SBob Pearson rxe_dbg_pd(pd, "unable to create mr"); 127872a03627SBob Pearson goto err_free; 12795bf944f2SBob Pearson } 12808700e3e7SMoni Shoua 12813197706aSBob Pearson rxe_get(pd); 128258651bbbSBob Pearson mr->ibmr.pd = ibpd; 12832778b72bSBob Pearson mr->ibmr.device = ibpd->device; 12848700e3e7SMoni Shoua 128558651bbbSBob Pearson err = rxe_mr_init_user(rxe, start, length, iova, access, mr); 12865bf944f2SBob Pearson if (err) { 12875bf944f2SBob Pearson rxe_dbg_mr(mr, "reg_user_mr failed, err = %d", err); 128872a03627SBob Pearson goto err_cleanup; 12895bf944f2SBob Pearson } 12908700e3e7SMoni Shoua 1291215d0a75SBob Pearson rxe_finalize(mr); 12928700e3e7SMoni Shoua return &mr->ibmr; 12938700e3e7SMoni Shoua 129472a03627SBob Pearson err_cleanup: 12955bf944f2SBob Pearson cleanup_err = rxe_cleanup(mr); 12965bf944f2SBob Pearson if (cleanup_err) 12975bf944f2SBob Pearson rxe_err_mr(mr, "cleanup failed, err = %d", cleanup_err); 129872a03627SBob Pearson err_free: 129972a03627SBob Pearson kfree(mr); 13005bf944f2SBob Pearson rxe_err_pd(pd, "returned err = %d", err); 13018700e3e7SMoni Shoua return ERR_PTR(err); 13028700e3e7SMoni Shoua } 13038700e3e7SMoni Shoua 1304544c7f62SBob Pearson static struct ib_mr *rxe_rereg_user_mr(struct ib_mr *ibmr, int flags, 1305544c7f62SBob Pearson u64 start, u64 length, u64 iova, 1306544c7f62SBob Pearson int access, struct ib_pd *ibpd, 1307544c7f62SBob Pearson struct ib_udata *udata) 1308544c7f62SBob Pearson { 1309544c7f62SBob Pearson struct rxe_mr *mr = to_rmr(ibmr); 1310544c7f62SBob Pearson struct rxe_pd *old_pd = to_rpd(ibmr->pd); 1311544c7f62SBob Pearson struct rxe_pd *pd = to_rpd(ibpd); 1312544c7f62SBob Pearson 1313544c7f62SBob Pearson /* for now only support the two easy cases: 1314544c7f62SBob Pearson * rereg_pd and rereg_access 1315544c7f62SBob Pearson */ 1316544c7f62SBob Pearson if (flags & ~RXE_MR_REREG_SUPPORTED) { 1317544c7f62SBob Pearson rxe_err_mr(mr, "flags = %#x not supported", flags); 1318544c7f62SBob Pearson return ERR_PTR(-EOPNOTSUPP); 1319544c7f62SBob Pearson } 1320544c7f62SBob Pearson 1321544c7f62SBob Pearson if (flags & IB_MR_REREG_PD) { 1322544c7f62SBob Pearson rxe_put(old_pd); 1323544c7f62SBob Pearson rxe_get(pd); 1324544c7f62SBob Pearson mr->ibmr.pd = ibpd; 1325544c7f62SBob Pearson } 1326544c7f62SBob Pearson 1327544c7f62SBob Pearson if (flags & IB_MR_REREG_ACCESS) { 1328544c7f62SBob Pearson if (access & ~RXE_ACCESS_SUPPORTED_MR) { 1329544c7f62SBob Pearson rxe_err_mr(mr, "access = %#x not supported", access); 1330544c7f62SBob Pearson return ERR_PTR(-EOPNOTSUPP); 1331544c7f62SBob Pearson } 1332544c7f62SBob Pearson mr->access = access; 1333544c7f62SBob Pearson } 1334544c7f62SBob Pearson 1335544c7f62SBob Pearson return NULL; 1336544c7f62SBob Pearson } 1337544c7f62SBob Pearson 1338c4367a26SShamir Rabinovitch static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, 133942a3b153SGal Pressman u32 max_num_sg) 13408700e3e7SMoni Shoua { 13418700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 13428700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 1343364e282cSBob Pearson struct rxe_mr *mr; 13445bf944f2SBob Pearson int err, cleanup_err; 13458700e3e7SMoni Shoua 13465bf944f2SBob Pearson if (mr_type != IB_MR_TYPE_MEM_REG) { 13475bf944f2SBob Pearson err = -EINVAL; 13485bf944f2SBob Pearson rxe_dbg_pd(pd, "mr type %d not supported, err = %d", 13495bf944f2SBob Pearson mr_type, err); 13505bf944f2SBob Pearson goto err_out; 13515bf944f2SBob Pearson } 13528700e3e7SMoni Shoua 135372a03627SBob Pearson mr = kzalloc(sizeof(*mr), GFP_KERNEL); 1354b6ba6855SLeon Romanovsky if (!mr) 1355b6ba6855SLeon Romanovsky return ERR_PTR(-ENOMEM); 135672a03627SBob Pearson 135772a03627SBob Pearson err = rxe_add_to_pool(&rxe->mr_pool, mr); 1358b6ba6855SLeon Romanovsky if (err) 135972a03627SBob Pearson goto err_free; 13608700e3e7SMoni Shoua 13613197706aSBob Pearson rxe_get(pd); 136258651bbbSBob Pearson mr->ibmr.pd = ibpd; 13632778b72bSBob Pearson mr->ibmr.device = ibpd->device; 13648700e3e7SMoni Shoua 136558651bbbSBob Pearson err = rxe_mr_init_fast(max_num_sg, mr); 13665bf944f2SBob Pearson if (err) { 13675bf944f2SBob Pearson rxe_dbg_mr(mr, "alloc_mr failed, err = %d", err); 136872a03627SBob Pearson goto err_cleanup; 13695bf944f2SBob Pearson } 13708700e3e7SMoni Shoua 1371215d0a75SBob Pearson rxe_finalize(mr); 13728700e3e7SMoni Shoua return &mr->ibmr; 13738700e3e7SMoni Shoua 137472a03627SBob Pearson err_cleanup: 13755bf944f2SBob Pearson cleanup_err = rxe_cleanup(mr); 13765bf944f2SBob Pearson if (cleanup_err) 13775bf944f2SBob Pearson rxe_err_mr(mr, "cleanup failed, err = %d", err); 137872a03627SBob Pearson err_free: 137972a03627SBob Pearson kfree(mr); 138072a03627SBob Pearson err_out: 13815bf944f2SBob Pearson rxe_err_pd(pd, "returned err = %d", err); 13828700e3e7SMoni Shoua return ERR_PTR(err); 13838700e3e7SMoni Shoua } 13848700e3e7SMoni Shoua 13855bf944f2SBob Pearson static int rxe_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata) 13865bf944f2SBob Pearson { 13875bf944f2SBob Pearson struct rxe_mr *mr = to_rmr(ibmr); 13885bf944f2SBob Pearson int err, cleanup_err; 13895bf944f2SBob Pearson 13905bf944f2SBob Pearson /* See IBA 10.6.7.2.6 */ 13915bf944f2SBob Pearson if (atomic_read(&mr->num_mw) > 0) { 13925bf944f2SBob Pearson err = -EINVAL; 13935bf944f2SBob Pearson rxe_dbg_mr(mr, "mr has mw's bound"); 13945bf944f2SBob Pearson goto err_out; 13955bf944f2SBob Pearson } 13965bf944f2SBob Pearson 13975bf944f2SBob Pearson cleanup_err = rxe_cleanup(mr); 13985bf944f2SBob Pearson if (cleanup_err) 13995bf944f2SBob Pearson rxe_err_mr(mr, "cleanup failed, err = %d", cleanup_err); 14005bf944f2SBob Pearson 1401af96134dSLinus Torvalds kfree_rcu_mightsleep(mr); 14025bf944f2SBob Pearson return 0; 14035bf944f2SBob Pearson 14045bf944f2SBob Pearson err_out: 14055bf944f2SBob Pearson rxe_err_mr(mr, "returned err = %d", err); 14065bf944f2SBob Pearson return err; 14075bf944f2SBob Pearson } 14085bf944f2SBob Pearson 1409c05d2664SKamal Heib static ssize_t parent_show(struct device *device, 14108700e3e7SMoni Shoua struct device_attribute *attr, char *buf) 14118700e3e7SMoni Shoua { 141254747231SParav Pandit struct rxe_dev *rxe = 141354747231SParav Pandit rdma_device_to_drv_device(device, struct rxe_dev, ib_dev); 14148700e3e7SMoni Shoua 14151c7fd726SJoe Perches return sysfs_emit(buf, "%s\n", rxe_parent_name(rxe, 1)); 14168700e3e7SMoni Shoua } 14178700e3e7SMoni Shoua 1418c05d2664SKamal Heib static DEVICE_ATTR_RO(parent); 14198700e3e7SMoni Shoua 1420508a523fSParav Pandit static struct attribute *rxe_dev_attributes[] = { 1421508a523fSParav Pandit &dev_attr_parent.attr, 1422508a523fSParav Pandit NULL 1423508a523fSParav Pandit }; 1424508a523fSParav Pandit 1425508a523fSParav Pandit static const struct attribute_group rxe_attr_group = { 1426508a523fSParav Pandit .attrs = rxe_dev_attributes, 14278700e3e7SMoni Shoua }; 14288700e3e7SMoni Shoua 1429ca22354bSJason Gunthorpe static int rxe_enable_driver(struct ib_device *ib_dev) 1430ca22354bSJason Gunthorpe { 1431ca22354bSJason Gunthorpe struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev); 1432ca22354bSJason Gunthorpe 1433ca22354bSJason Gunthorpe rxe_set_port_state(rxe); 1434ca22354bSJason Gunthorpe dev_info(&rxe->ib_dev.dev, "added %s\n", netdev_name(rxe->ndev)); 1435ca22354bSJason Gunthorpe return 0; 1436ca22354bSJason Gunthorpe } 1437ca22354bSJason Gunthorpe 1438573efc4bSKamal Heib static const struct ib_device_ops rxe_dev_ops = { 14397a154142SJason Gunthorpe .owner = THIS_MODULE, 1440b9560a41SJason Gunthorpe .driver_id = RDMA_DRIVER_RXE, 144172c6ec18SJason Gunthorpe .uverbs_abi_ver = RXE_UVERBS_ABI_VERSION, 1442b9560a41SJason Gunthorpe 14434b5f4d3fSJason Gunthorpe .alloc_hw_port_stats = rxe_ib_alloc_hw_port_stats, 1444573efc4bSKamal Heib .alloc_mr = rxe_alloc_mr, 1445beec0239SBob Pearson .alloc_mw = rxe_alloc_mw, 1446573efc4bSKamal Heib .alloc_pd = rxe_alloc_pd, 1447573efc4bSKamal Heib .alloc_ucontext = rxe_alloc_ucontext, 1448573efc4bSKamal Heib .attach_mcast = rxe_attach_mcast, 1449573efc4bSKamal Heib .create_ah = rxe_create_ah, 1450573efc4bSKamal Heib .create_cq = rxe_create_cq, 1451573efc4bSKamal Heib .create_qp = rxe_create_qp, 1452573efc4bSKamal Heib .create_srq = rxe_create_srq, 1453676a80adSJason Gunthorpe .create_user_ah = rxe_create_ah, 1454c367074bSJason Gunthorpe .dealloc_driver = rxe_dealloc, 1455beec0239SBob Pearson .dealloc_mw = rxe_dealloc_mw, 1456573efc4bSKamal Heib .dealloc_pd = rxe_dealloc_pd, 1457573efc4bSKamal Heib .dealloc_ucontext = rxe_dealloc_ucontext, 1458573efc4bSKamal Heib .dereg_mr = rxe_dereg_mr, 1459573efc4bSKamal Heib .destroy_ah = rxe_destroy_ah, 1460573efc4bSKamal Heib .destroy_cq = rxe_destroy_cq, 1461573efc4bSKamal Heib .destroy_qp = rxe_destroy_qp, 1462573efc4bSKamal Heib .destroy_srq = rxe_destroy_srq, 1463573efc4bSKamal Heib .detach_mcast = rxe_detach_mcast, 1464915e4af5SJason Gunthorpe .device_group = &rxe_attr_group, 1465ca22354bSJason Gunthorpe .enable_driver = rxe_enable_driver, 1466573efc4bSKamal Heib .get_dma_mr = rxe_get_dma_mr, 1467573efc4bSKamal Heib .get_hw_stats = rxe_ib_get_hw_stats, 1468573efc4bSKamal Heib .get_link_layer = rxe_get_link_layer, 1469573efc4bSKamal Heib .get_port_immutable = rxe_port_immutable, 1470573efc4bSKamal Heib .map_mr_sg = rxe_map_mr_sg, 1471573efc4bSKamal Heib .mmap = rxe_mmap, 1472573efc4bSKamal Heib .modify_ah = rxe_modify_ah, 1473573efc4bSKamal Heib .modify_device = rxe_modify_device, 1474573efc4bSKamal Heib .modify_port = rxe_modify_port, 1475573efc4bSKamal Heib .modify_qp = rxe_modify_qp, 1476573efc4bSKamal Heib .modify_srq = rxe_modify_srq, 1477573efc4bSKamal Heib .peek_cq = rxe_peek_cq, 1478573efc4bSKamal Heib .poll_cq = rxe_poll_cq, 1479573efc4bSKamal Heib .post_recv = rxe_post_recv, 1480573efc4bSKamal Heib .post_send = rxe_post_send, 1481573efc4bSKamal Heib .post_srq_recv = rxe_post_srq_recv, 1482573efc4bSKamal Heib .query_ah = rxe_query_ah, 1483573efc4bSKamal Heib .query_device = rxe_query_device, 1484573efc4bSKamal Heib .query_pkey = rxe_query_pkey, 1485573efc4bSKamal Heib .query_port = rxe_query_port, 1486573efc4bSKamal Heib .query_qp = rxe_query_qp, 1487573efc4bSKamal Heib .query_srq = rxe_query_srq, 1488573efc4bSKamal Heib .reg_user_mr = rxe_reg_user_mr, 1489573efc4bSKamal Heib .req_notify_cq = rxe_req_notify_cq, 1490544c7f62SBob Pearson .rereg_user_mr = rxe_rereg_user_mr, 1491573efc4bSKamal Heib .resize_cq = rxe_resize_cq, 1492d3456914SLeon Romanovsky 1493d3456914SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ah, rxe_ah, ibah), 1494e39afe3dSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_cq, rxe_cq, ibcq), 149521a428a0SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_pd, rxe_pd, ibpd), 1496514aee66SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_qp, rxe_qp, ibqp), 149768e326deSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_srq, rxe_srq, ibsrq), 1498a2a074efSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ucontext, rxe_ucontext, ibuc), 1499364e282cSBob Pearson INIT_RDMA_OBJ_SIZE(ib_mw, rxe_mw, ibmw), 1500573efc4bSKamal Heib }; 1501573efc4bSKamal Heib 150266920e1bSSteve Wise int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name) 15038700e3e7SMoni Shoua { 15048700e3e7SMoni Shoua int err; 15058700e3e7SMoni Shoua struct ib_device *dev = &rxe->ib_dev; 15068700e3e7SMoni Shoua 1507dc78074aSBob Pearson strscpy(dev->node_desc, "rxe", sizeof(dev->node_desc)); 15088700e3e7SMoni Shoua 15098700e3e7SMoni Shoua dev->node_type = RDMA_NODE_IB_CA; 15108700e3e7SMoni Shoua dev->phys_port_cnt = 1; 151167cf3623SSagi Grimberg dev->num_comp_vectors = num_possible_cpus(); 15128700e3e7SMoni Shoua dev->local_dma_lkey = 0; 15134d6f2859SYuval Shaia addrconf_addr_eui48((unsigned char *)&dev->node_guid, 15144d6f2859SYuval Shaia rxe->ndev->dev_addr); 15158700e3e7SMoni Shoua 15165c419366SJason Gunthorpe dev->uverbs_cmd_mask |= BIT_ULL(IB_USER_VERBS_CMD_POST_SEND) | 15175c419366SJason Gunthorpe BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ); 15188700e3e7SMoni Shoua 1519573efc4bSKamal Heib ib_set_device_ops(dev, &rxe_dev_ops); 15204c173f59SJason Gunthorpe err = ib_device_set_netdev(&rxe->ib_dev, rxe->ndev, 1); 15214c173f59SJason Gunthorpe if (err) 15224c173f59SJason Gunthorpe return err; 15238700e3e7SMoni Shoua 1524add2b3b8SBob Pearson err = rxe_icrc_init(rxe); 1525add2b3b8SBob Pearson if (err) 1526add2b3b8SBob Pearson return err; 1527cee2688eSyonatanc 1528e0477b34SJason Gunthorpe err = ib_register_device(dev, ibdev_name, NULL); 1529c367074bSJason Gunthorpe if (err) 1530a9fb3287SBob Pearson rxe_dbg_dev(rxe, "failed with error %d\n", err); 1531cee2688eSyonatanc 1532ca22354bSJason Gunthorpe /* 1533ca22354bSJason Gunthorpe * Note that rxe may be invalid at this point if another thread 1534ca22354bSJason Gunthorpe * unregistered it. 1535ca22354bSJason Gunthorpe */ 15368700e3e7SMoni Shoua return err; 15378700e3e7SMoni Shoua } 1538