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, 298700e3e7SMoni Shoua u8 port_num, struct ib_port_attr *attr) 308700e3e7SMoni Shoua { 318700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 328700e3e7SMoni Shoua struct rxe_port *port; 3359590b8aSYuval Shaia int rc; 348700e3e7SMoni Shoua 358700e3e7SMoni Shoua port = &rxe->port; 368700e3e7SMoni Shoua 37c4550c63SOr Gerlitz /* *attr being zeroed by the caller, avoid zeroing it here */ 388700e3e7SMoni Shoua *attr = port->attr; 398700e3e7SMoni Shoua 408700e3e7SMoni Shoua mutex_lock(&rxe->usdev_lock); 41d4186194SYuval Shaia rc = ib_get_eth_speed(dev, port_num, &attr->active_speed, 42e404f945SParav Pandit &attr->active_width); 435736c7c4SAndrew Boyer 445736c7c4SAndrew Boyer if (attr->state == IB_PORT_ACTIVE) 4572a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP; 465736c7c4SAndrew Boyer else if (dev_get_flags(rxe->ndev) & IFF_UP) 4772a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_POLLING; 485736c7c4SAndrew Boyer else 4972a7720fSKamal Heib attr->phys_state = IB_PORT_PHYS_STATE_DISABLED; 505736c7c4SAndrew Boyer 518700e3e7SMoni Shoua mutex_unlock(&rxe->usdev_lock); 528700e3e7SMoni Shoua 53d4186194SYuval Shaia return rc; 548700e3e7SMoni Shoua } 558700e3e7SMoni Shoua 568700e3e7SMoni Shoua static int rxe_query_pkey(struct ib_device *device, 578700e3e7SMoni Shoua u8 port_num, u16 index, u16 *pkey) 588700e3e7SMoni Shoua { 5976251e15SKamal Heib if (index > 0) 608700e3e7SMoni Shoua return -EINVAL; 6176251e15SKamal Heib 6276251e15SKamal Heib *pkey = IB_DEFAULT_PKEY_FULL; 6376251e15SKamal Heib return 0; 648700e3e7SMoni Shoua } 658700e3e7SMoni Shoua 668700e3e7SMoni Shoua static int rxe_modify_device(struct ib_device *dev, 678700e3e7SMoni Shoua int mask, struct ib_device_modify *attr) 688700e3e7SMoni Shoua { 698700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 708700e3e7SMoni Shoua 71f3fceba5SKamal Heib if (mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | 72f3fceba5SKamal Heib IB_DEVICE_MODIFY_NODE_DESC)) 73f3fceba5SKamal Heib return -EOPNOTSUPP; 74f3fceba5SKamal Heib 758700e3e7SMoni Shoua if (mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) 768700e3e7SMoni Shoua rxe->attr.sys_image_guid = cpu_to_be64(attr->sys_image_guid); 778700e3e7SMoni Shoua 788700e3e7SMoni Shoua if (mask & IB_DEVICE_MODIFY_NODE_DESC) { 798700e3e7SMoni Shoua memcpy(rxe->ib_dev.node_desc, 808700e3e7SMoni Shoua attr->node_desc, sizeof(rxe->ib_dev.node_desc)); 818700e3e7SMoni Shoua } 828700e3e7SMoni Shoua 838700e3e7SMoni Shoua return 0; 848700e3e7SMoni Shoua } 858700e3e7SMoni Shoua 868700e3e7SMoni Shoua static int rxe_modify_port(struct ib_device *dev, 878700e3e7SMoni Shoua u8 port_num, int mask, struct ib_port_modify *attr) 888700e3e7SMoni Shoua { 898700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 908700e3e7SMoni Shoua struct rxe_port *port; 918700e3e7SMoni Shoua 928700e3e7SMoni Shoua port = &rxe->port; 938700e3e7SMoni Shoua 948700e3e7SMoni Shoua port->attr.port_cap_flags |= attr->set_port_cap_mask; 958700e3e7SMoni Shoua port->attr.port_cap_flags &= ~attr->clr_port_cap_mask; 968700e3e7SMoni Shoua 978700e3e7SMoni Shoua if (mask & IB_PORT_RESET_QKEY_CNTR) 988700e3e7SMoni Shoua port->attr.qkey_viol_cntr = 0; 998700e3e7SMoni Shoua 1008700e3e7SMoni Shoua return 0; 1018700e3e7SMoni Shoua } 1028700e3e7SMoni Shoua 1038700e3e7SMoni Shoua static enum rdma_link_layer rxe_get_link_layer(struct ib_device *dev, 1048700e3e7SMoni Shoua u8 port_num) 1058700e3e7SMoni Shoua { 106420bd9e2SKamal Heib return IB_LINK_LAYER_ETHERNET; 1078700e3e7SMoni Shoua } 1088700e3e7SMoni Shoua 109a2a074efSLeon Romanovsky static int rxe_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata) 1108700e3e7SMoni Shoua { 111a2a074efSLeon Romanovsky struct rxe_dev *rxe = to_rdev(uctx->device); 112a2a074efSLeon Romanovsky struct rxe_ucontext *uc = to_ruc(uctx); 1138700e3e7SMoni Shoua 114a2a074efSLeon Romanovsky return rxe_add_to_pool(&rxe->uc_pool, &uc->pelem); 1158700e3e7SMoni Shoua } 1168700e3e7SMoni Shoua 117a2a074efSLeon Romanovsky static void rxe_dealloc_ucontext(struct ib_ucontext *ibuc) 1188700e3e7SMoni Shoua { 1198700e3e7SMoni Shoua struct rxe_ucontext *uc = to_ruc(ibuc); 1208700e3e7SMoni Shoua 1218700e3e7SMoni Shoua rxe_drop_ref(uc); 1228700e3e7SMoni Shoua } 1238700e3e7SMoni Shoua 1248700e3e7SMoni Shoua static int rxe_port_immutable(struct ib_device *dev, u8 port_num, 1258700e3e7SMoni Shoua struct ib_port_immutable *immutable) 1268700e3e7SMoni Shoua { 1278700e3e7SMoni Shoua int err; 1288700e3e7SMoni Shoua struct ib_port_attr attr; 1298700e3e7SMoni Shoua 130c4550c63SOr Gerlitz immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; 131c4550c63SOr Gerlitz 132c4550c63SOr Gerlitz err = ib_query_port(dev, port_num, &attr); 1338700e3e7SMoni Shoua if (err) 1348700e3e7SMoni Shoua return err; 1358700e3e7SMoni Shoua 1368700e3e7SMoni Shoua immutable->pkey_tbl_len = attr.pkey_tbl_len; 1378700e3e7SMoni Shoua immutable->gid_tbl_len = attr.gid_tbl_len; 1388700e3e7SMoni Shoua immutable->max_mad_size = IB_MGMT_MAD_SIZE; 1398700e3e7SMoni Shoua 1408700e3e7SMoni Shoua return 0; 1418700e3e7SMoni Shoua } 1428700e3e7SMoni Shoua 143ff23dfa1SShamir Rabinovitch static int rxe_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) 1448700e3e7SMoni Shoua { 14521a428a0SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibpd->device); 14621a428a0SLeon Romanovsky struct rxe_pd *pd = to_rpd(ibpd); 1478700e3e7SMoni Shoua 14821a428a0SLeon Romanovsky return rxe_add_to_pool(&rxe->pd_pool, &pd->pelem); 1498700e3e7SMoni Shoua } 1508700e3e7SMoni Shoua 15191a7c58fSLeon Romanovsky static int rxe_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) 1528700e3e7SMoni Shoua { 1538700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 1548700e3e7SMoni Shoua 1558700e3e7SMoni Shoua rxe_drop_ref(pd); 15691a7c58fSLeon Romanovsky return 0; 1578700e3e7SMoni Shoua } 1588700e3e7SMoni Shoua 159fa5d010cSMaor Gottlieb static int rxe_create_ah(struct ib_ah *ibah, 160fa5d010cSMaor Gottlieb struct rdma_ah_init_attr *init_attr, 161fa5d010cSMaor Gottlieb struct ib_udata *udata) 162477864c8SMoni Shoua 1638700e3e7SMoni Shoua { 1648700e3e7SMoni Shoua int err; 165d3456914SLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibah->device); 166d3456914SLeon Romanovsky struct rxe_ah *ah = to_rah(ibah); 1678700e3e7SMoni Shoua 168fa5d010cSMaor Gottlieb err = rxe_av_chk_attr(rxe, init_attr->ah_attr); 1698700e3e7SMoni Shoua if (err) 170d3456914SLeon Romanovsky return err; 1718700e3e7SMoni Shoua 172d3456914SLeon Romanovsky err = rxe_add_to_pool(&rxe->ah_pool, &ah->pelem); 173d3456914SLeon Romanovsky if (err) 174d3456914SLeon Romanovsky return err; 1758700e3e7SMoni Shoua 176fa5d010cSMaor Gottlieb rxe_init_av(init_attr->ah_attr, &ah->av); 177d3456914SLeon Romanovsky return 0; 1788700e3e7SMoni Shoua } 1798700e3e7SMoni Shoua 18090898850SDasaratharaman Chandramouli static int rxe_modify_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) 1818700e3e7SMoni Shoua { 1828700e3e7SMoni Shoua int err; 1838700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibah->device); 1848700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 1858700e3e7SMoni Shoua 1868700e3e7SMoni Shoua err = rxe_av_chk_attr(rxe, attr); 1878700e3e7SMoni Shoua if (err) 1888700e3e7SMoni Shoua return err; 1898700e3e7SMoni Shoua 190fa407188SKamal Heib rxe_init_av(attr, &ah->av); 1918700e3e7SMoni Shoua return 0; 1928700e3e7SMoni Shoua } 1938700e3e7SMoni Shoua 19490898850SDasaratharaman Chandramouli static int rxe_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) 1958700e3e7SMoni Shoua { 1968700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 1978700e3e7SMoni Shoua 198eca7ddf9SDasaratharaman Chandramouli memset(attr, 0, sizeof(*attr)); 19944c58487SDasaratharaman Chandramouli attr->type = ibah->type; 2009c96f3d4SZhu Yanjun rxe_av_to_attr(&ah->av, attr); 2018700e3e7SMoni Shoua return 0; 2028700e3e7SMoni Shoua } 2038700e3e7SMoni Shoua 2049a9ebf8cSLeon Romanovsky static int rxe_destroy_ah(struct ib_ah *ibah, u32 flags) 2058700e3e7SMoni Shoua { 2068700e3e7SMoni Shoua struct rxe_ah *ah = to_rah(ibah); 2078700e3e7SMoni Shoua 2088700e3e7SMoni Shoua rxe_drop_ref(ah); 2099a9ebf8cSLeon Romanovsky return 0; 2108700e3e7SMoni Shoua } 2118700e3e7SMoni Shoua 212d34ac5cdSBart Van Assche static int post_one_recv(struct rxe_rq *rq, const struct ib_recv_wr *ibwr) 2138700e3e7SMoni Shoua { 2148700e3e7SMoni Shoua int err; 2158700e3e7SMoni Shoua int i; 2168700e3e7SMoni Shoua u32 length; 2178700e3e7SMoni Shoua struct rxe_recv_wqe *recv_wqe; 2188700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 2198700e3e7SMoni Shoua 2208700e3e7SMoni Shoua if (unlikely(queue_full(rq->queue))) { 2218700e3e7SMoni Shoua err = -ENOMEM; 2228700e3e7SMoni Shoua goto err1; 2238700e3e7SMoni Shoua } 2248700e3e7SMoni Shoua 2258700e3e7SMoni Shoua if (unlikely(num_sge > rq->max_sge)) { 2268700e3e7SMoni Shoua err = -EINVAL; 2278700e3e7SMoni Shoua goto err1; 2288700e3e7SMoni Shoua } 2298700e3e7SMoni Shoua 2308700e3e7SMoni Shoua length = 0; 2318700e3e7SMoni Shoua for (i = 0; i < num_sge; i++) 2328700e3e7SMoni Shoua length += ibwr->sg_list[i].length; 2338700e3e7SMoni Shoua 2348700e3e7SMoni Shoua recv_wqe = producer_addr(rq->queue); 2358700e3e7SMoni Shoua recv_wqe->wr_id = ibwr->wr_id; 2368700e3e7SMoni Shoua recv_wqe->num_sge = num_sge; 2378700e3e7SMoni Shoua 2388700e3e7SMoni Shoua memcpy(recv_wqe->dma.sge, ibwr->sg_list, 2398700e3e7SMoni Shoua num_sge * sizeof(struct ib_sge)); 2408700e3e7SMoni Shoua 2418700e3e7SMoni Shoua recv_wqe->dma.length = length; 2428700e3e7SMoni Shoua recv_wqe->dma.resid = length; 2438700e3e7SMoni Shoua recv_wqe->dma.num_sge = num_sge; 2448700e3e7SMoni Shoua recv_wqe->dma.cur_sge = 0; 2458700e3e7SMoni Shoua recv_wqe->dma.sge_offset = 0; 2468700e3e7SMoni Shoua 2478700e3e7SMoni Shoua /* make sure all changes to the work queue are written before we 2488700e3e7SMoni Shoua * update the producer pointer 2498700e3e7SMoni Shoua */ 2508700e3e7SMoni Shoua smp_wmb(); 2518700e3e7SMoni Shoua 2528700e3e7SMoni Shoua advance_producer(rq->queue); 2538700e3e7SMoni Shoua return 0; 2548700e3e7SMoni Shoua 2558700e3e7SMoni Shoua err1: 2568700e3e7SMoni Shoua return err; 2578700e3e7SMoni Shoua } 2588700e3e7SMoni Shoua 25968e326deSLeon Romanovsky static int rxe_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init, 2608700e3e7SMoni Shoua struct ib_udata *udata) 2618700e3e7SMoni Shoua { 2628700e3e7SMoni Shoua int err; 26368e326deSLeon Romanovsky struct rxe_dev *rxe = to_rdev(ibsrq->device); 26468e326deSLeon Romanovsky struct rxe_pd *pd = to_rpd(ibsrq->pd); 26568e326deSLeon Romanovsky struct rxe_srq *srq = to_rsrq(ibsrq); 2660c43ab37SJason Gunthorpe struct rxe_create_srq_resp __user *uresp = NULL; 2670c43ab37SJason Gunthorpe 268652caba5SJason Gunthorpe if (init->srq_type != IB_SRQT_BASIC) 269652caba5SJason Gunthorpe return -EOPNOTSUPP; 270652caba5SJason Gunthorpe 2710c43ab37SJason Gunthorpe if (udata) { 2720c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 27368e326deSLeon Romanovsky return -EINVAL; 2740c43ab37SJason Gunthorpe uresp = udata->outbuf; 2750c43ab37SJason Gunthorpe } 2768700e3e7SMoni Shoua 2778700e3e7SMoni Shoua err = rxe_srq_chk_attr(rxe, NULL, &init->attr, IB_SRQ_INIT_MASK); 2788700e3e7SMoni Shoua if (err) 2798700e3e7SMoni Shoua goto err1; 2808700e3e7SMoni Shoua 28168e326deSLeon Romanovsky err = rxe_add_to_pool(&rxe->srq_pool, &srq->pelem); 28268e326deSLeon Romanovsky if (err) 2838700e3e7SMoni Shoua goto err1; 2848700e3e7SMoni Shoua 2858700e3e7SMoni Shoua rxe_add_ref(pd); 2868700e3e7SMoni Shoua srq->pd = pd; 2878700e3e7SMoni Shoua 288ff23dfa1SShamir Rabinovitch err = rxe_srq_from_init(rxe, srq, init, udata, uresp); 2898700e3e7SMoni Shoua if (err) 2908700e3e7SMoni Shoua goto err2; 2918700e3e7SMoni Shoua 29268e326deSLeon Romanovsky return 0; 2938700e3e7SMoni Shoua 2948700e3e7SMoni Shoua err2: 2958700e3e7SMoni Shoua rxe_drop_ref(pd); 2968700e3e7SMoni Shoua rxe_drop_ref(srq); 2978700e3e7SMoni Shoua err1: 29868e326deSLeon Romanovsky return err; 2998700e3e7SMoni Shoua } 3008700e3e7SMoni Shoua 3018700e3e7SMoni Shoua static int rxe_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 3028700e3e7SMoni Shoua enum ib_srq_attr_mask mask, 3038700e3e7SMoni Shoua struct ib_udata *udata) 3048700e3e7SMoni Shoua { 3058700e3e7SMoni Shoua int err; 3068700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3078700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibsrq->device); 3080c43ab37SJason Gunthorpe struct rxe_modify_srq_cmd ucmd = {}; 3090c43ab37SJason Gunthorpe 3100c43ab37SJason Gunthorpe if (udata) { 3110c43ab37SJason Gunthorpe if (udata->inlen < sizeof(ucmd)) 3120c43ab37SJason Gunthorpe return -EINVAL; 3130c43ab37SJason Gunthorpe 3140c43ab37SJason Gunthorpe err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)); 3150c43ab37SJason Gunthorpe if (err) 3160c43ab37SJason Gunthorpe return err; 3170c43ab37SJason Gunthorpe } 3188700e3e7SMoni Shoua 3198700e3e7SMoni Shoua err = rxe_srq_chk_attr(rxe, srq, attr, mask); 3208700e3e7SMoni Shoua if (err) 3218700e3e7SMoni Shoua goto err1; 3228700e3e7SMoni Shoua 323ff23dfa1SShamir Rabinovitch err = rxe_srq_from_attr(rxe, srq, attr, mask, &ucmd, udata); 3248700e3e7SMoni Shoua if (err) 3258700e3e7SMoni Shoua goto err1; 3268700e3e7SMoni Shoua 3278700e3e7SMoni Shoua return 0; 3288700e3e7SMoni Shoua 3298700e3e7SMoni Shoua err1: 3308700e3e7SMoni Shoua return err; 3318700e3e7SMoni Shoua } 3328700e3e7SMoni Shoua 3338700e3e7SMoni Shoua static int rxe_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr) 3348700e3e7SMoni Shoua { 3358700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3368700e3e7SMoni Shoua 3378700e3e7SMoni Shoua if (srq->error) 3388700e3e7SMoni Shoua return -EINVAL; 3398700e3e7SMoni Shoua 3408700e3e7SMoni Shoua attr->max_wr = srq->rq.queue->buf->index_mask; 3418700e3e7SMoni Shoua attr->max_sge = srq->rq.max_sge; 3428700e3e7SMoni Shoua attr->srq_limit = srq->limit; 3438700e3e7SMoni Shoua return 0; 3448700e3e7SMoni Shoua } 3458700e3e7SMoni Shoua 346119181d1SLeon Romanovsky static int rxe_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata) 3478700e3e7SMoni Shoua { 3488700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3498700e3e7SMoni Shoua 3508700e3e7SMoni Shoua if (srq->rq.queue) 3518700e3e7SMoni Shoua rxe_queue_cleanup(srq->rq.queue); 3528700e3e7SMoni Shoua 3538700e3e7SMoni Shoua rxe_drop_ref(srq->pd); 3548700e3e7SMoni Shoua rxe_drop_ref(srq); 355119181d1SLeon Romanovsky return 0; 3568700e3e7SMoni Shoua } 3578700e3e7SMoni Shoua 358d34ac5cdSBart Van Assche static int rxe_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr, 359d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr) 3608700e3e7SMoni Shoua { 3618700e3e7SMoni Shoua int err = 0; 3628700e3e7SMoni Shoua unsigned long flags; 3638700e3e7SMoni Shoua struct rxe_srq *srq = to_rsrq(ibsrq); 3648700e3e7SMoni Shoua 3658700e3e7SMoni Shoua spin_lock_irqsave(&srq->rq.producer_lock, flags); 3668700e3e7SMoni Shoua 3678700e3e7SMoni Shoua while (wr) { 3688700e3e7SMoni Shoua err = post_one_recv(&srq->rq, wr); 3698700e3e7SMoni Shoua if (unlikely(err)) 3708700e3e7SMoni Shoua break; 3718700e3e7SMoni Shoua wr = wr->next; 3728700e3e7SMoni Shoua } 3738700e3e7SMoni Shoua 3748700e3e7SMoni Shoua spin_unlock_irqrestore(&srq->rq.producer_lock, flags); 3758700e3e7SMoni Shoua 3768700e3e7SMoni Shoua if (err) 3778700e3e7SMoni Shoua *bad_wr = wr; 3788700e3e7SMoni Shoua 3798700e3e7SMoni Shoua return err; 3808700e3e7SMoni Shoua } 3818700e3e7SMoni Shoua 3828700e3e7SMoni Shoua static struct ib_qp *rxe_create_qp(struct ib_pd *ibpd, 3838700e3e7SMoni Shoua struct ib_qp_init_attr *init, 3848700e3e7SMoni Shoua struct ib_udata *udata) 3858700e3e7SMoni Shoua { 3868700e3e7SMoni Shoua int err; 3878700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 3888700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 3898700e3e7SMoni Shoua struct rxe_qp *qp; 3900c43ab37SJason Gunthorpe struct rxe_create_qp_resp __user *uresp = NULL; 3910c43ab37SJason Gunthorpe 3920c43ab37SJason Gunthorpe if (udata) { 3930c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 3940c43ab37SJason Gunthorpe return ERR_PTR(-EINVAL); 3950c43ab37SJason Gunthorpe uresp = udata->outbuf; 3960c43ab37SJason Gunthorpe } 3978700e3e7SMoni Shoua 3988700e3e7SMoni Shoua err = rxe_qp_chk_init(rxe, init); 3998700e3e7SMoni Shoua if (err) 4008700e3e7SMoni Shoua goto err1; 4018700e3e7SMoni Shoua 4028700e3e7SMoni Shoua qp = rxe_alloc(&rxe->qp_pool); 4038700e3e7SMoni Shoua if (!qp) { 4048700e3e7SMoni Shoua err = -ENOMEM; 4058700e3e7SMoni Shoua goto err1; 4068700e3e7SMoni Shoua } 4078700e3e7SMoni Shoua 4088700e3e7SMoni Shoua if (udata) { 4098700e3e7SMoni Shoua if (udata->inlen) { 4108700e3e7SMoni Shoua err = -EINVAL; 4115b9ea16cSAndrew Boyer goto err2; 4128700e3e7SMoni Shoua } 4138700e3e7SMoni Shoua qp->is_user = 1; 4148700e3e7SMoni Shoua } 4158700e3e7SMoni Shoua 4168700e3e7SMoni Shoua rxe_add_index(qp); 4178700e3e7SMoni Shoua 418e00b64f7SShamir Rabinovitch err = rxe_qp_from_init(rxe, qp, pd, init, uresp, ibpd, udata); 4198700e3e7SMoni Shoua if (err) 4205b9ea16cSAndrew Boyer goto err3; 4218700e3e7SMoni Shoua 4228700e3e7SMoni Shoua return &qp->ibqp; 4238700e3e7SMoni Shoua 4245b9ea16cSAndrew Boyer err3: 4258700e3e7SMoni Shoua rxe_drop_index(qp); 4265b9ea16cSAndrew Boyer err2: 4278700e3e7SMoni Shoua rxe_drop_ref(qp); 4288700e3e7SMoni Shoua err1: 4298700e3e7SMoni Shoua return ERR_PTR(err); 4308700e3e7SMoni Shoua } 4318700e3e7SMoni Shoua 4328700e3e7SMoni Shoua static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 4338700e3e7SMoni Shoua int mask, struct ib_udata *udata) 4348700e3e7SMoni Shoua { 4358700e3e7SMoni Shoua int err; 4368700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 4378700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4388700e3e7SMoni Shoua 439*26e990baSJason Gunthorpe if (mask & ~IB_QP_ATTR_STANDARD_BITS) 440*26e990baSJason Gunthorpe return -EOPNOTSUPP; 441*26e990baSJason Gunthorpe 4428700e3e7SMoni Shoua err = rxe_qp_chk_attr(rxe, qp, attr, mask); 4438700e3e7SMoni Shoua if (err) 4448700e3e7SMoni Shoua goto err1; 4458700e3e7SMoni Shoua 4468700e3e7SMoni Shoua err = rxe_qp_from_attr(qp, attr, mask, udata); 4478700e3e7SMoni Shoua if (err) 4488700e3e7SMoni Shoua goto err1; 4498700e3e7SMoni Shoua 4508700e3e7SMoni Shoua return 0; 4518700e3e7SMoni Shoua 4528700e3e7SMoni Shoua err1: 4538700e3e7SMoni Shoua return err; 4548700e3e7SMoni Shoua } 4558700e3e7SMoni Shoua 4568700e3e7SMoni Shoua static int rxe_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 4578700e3e7SMoni Shoua int mask, struct ib_qp_init_attr *init) 4588700e3e7SMoni Shoua { 4598700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4608700e3e7SMoni Shoua 4618700e3e7SMoni Shoua rxe_qp_to_init(qp, init); 4628700e3e7SMoni Shoua rxe_qp_to_attr(qp, attr, mask); 4638700e3e7SMoni Shoua 4648700e3e7SMoni Shoua return 0; 4658700e3e7SMoni Shoua } 4668700e3e7SMoni Shoua 467c4367a26SShamir Rabinovitch static int rxe_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) 4688700e3e7SMoni Shoua { 4698700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 4708700e3e7SMoni Shoua 4718700e3e7SMoni Shoua rxe_qp_destroy(qp); 4728700e3e7SMoni Shoua rxe_drop_index(qp); 4738700e3e7SMoni Shoua rxe_drop_ref(qp); 4748700e3e7SMoni Shoua return 0; 4758700e3e7SMoni Shoua } 4768700e3e7SMoni Shoua 477f696bf6dSBart Van Assche static int validate_send_wr(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 4788700e3e7SMoni Shoua unsigned int mask, unsigned int length) 4798700e3e7SMoni Shoua { 4808700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 4818700e3e7SMoni Shoua struct rxe_sq *sq = &qp->sq; 4828700e3e7SMoni Shoua 4838700e3e7SMoni Shoua if (unlikely(num_sge > sq->max_sge)) 4848700e3e7SMoni Shoua goto err1; 4858700e3e7SMoni Shoua 4868700e3e7SMoni Shoua if (unlikely(mask & WR_ATOMIC_MASK)) { 4878700e3e7SMoni Shoua if (length < 8) 4888700e3e7SMoni Shoua goto err1; 4898700e3e7SMoni Shoua 4908700e3e7SMoni Shoua if (atomic_wr(ibwr)->remote_addr & 0x7) 4918700e3e7SMoni Shoua goto err1; 4928700e3e7SMoni Shoua } 4938700e3e7SMoni Shoua 4948700e3e7SMoni Shoua if (unlikely((ibwr->send_flags & IB_SEND_INLINE) && 4958700e3e7SMoni Shoua (length > sq->max_inline))) 4968700e3e7SMoni Shoua goto err1; 4978700e3e7SMoni Shoua 4988700e3e7SMoni Shoua return 0; 4998700e3e7SMoni Shoua 5008700e3e7SMoni Shoua err1: 5018700e3e7SMoni Shoua return -EINVAL; 5028700e3e7SMoni Shoua } 5038700e3e7SMoni Shoua 5048700e3e7SMoni Shoua static void init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr, 505f696bf6dSBart Van Assche const struct ib_send_wr *ibwr) 5068700e3e7SMoni Shoua { 5078700e3e7SMoni Shoua wr->wr_id = ibwr->wr_id; 5088700e3e7SMoni Shoua wr->num_sge = ibwr->num_sge; 5098700e3e7SMoni Shoua wr->opcode = ibwr->opcode; 5108700e3e7SMoni Shoua wr->send_flags = ibwr->send_flags; 5118700e3e7SMoni Shoua 5128700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_UD || 5138700e3e7SMoni Shoua qp_type(qp) == IB_QPT_SMI || 5148700e3e7SMoni Shoua qp_type(qp) == IB_QPT_GSI) { 5158700e3e7SMoni Shoua wr->wr.ud.remote_qpn = ud_wr(ibwr)->remote_qpn; 5168700e3e7SMoni Shoua wr->wr.ud.remote_qkey = ud_wr(ibwr)->remote_qkey; 5178700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_GSI) 5188700e3e7SMoni Shoua wr->wr.ud.pkey_index = ud_wr(ibwr)->pkey_index; 5198700e3e7SMoni Shoua if (wr->opcode == IB_WR_SEND_WITH_IMM) 5208700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 5218700e3e7SMoni Shoua } else { 5228700e3e7SMoni Shoua switch (wr->opcode) { 5238700e3e7SMoni Shoua case IB_WR_RDMA_WRITE_WITH_IMM: 5248700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 525df561f66SGustavo A. R. Silva fallthrough; 5268700e3e7SMoni Shoua case IB_WR_RDMA_READ: 5278700e3e7SMoni Shoua case IB_WR_RDMA_WRITE: 5288700e3e7SMoni Shoua wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr; 5298700e3e7SMoni Shoua wr->wr.rdma.rkey = rdma_wr(ibwr)->rkey; 5308700e3e7SMoni Shoua break; 5318700e3e7SMoni Shoua case IB_WR_SEND_WITH_IMM: 5328700e3e7SMoni Shoua wr->ex.imm_data = ibwr->ex.imm_data; 5338700e3e7SMoni Shoua break; 5348700e3e7SMoni Shoua case IB_WR_SEND_WITH_INV: 5358700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 5368700e3e7SMoni Shoua break; 5378700e3e7SMoni Shoua case IB_WR_ATOMIC_CMP_AND_SWP: 5388700e3e7SMoni Shoua case IB_WR_ATOMIC_FETCH_AND_ADD: 5398700e3e7SMoni Shoua wr->wr.atomic.remote_addr = 5408700e3e7SMoni Shoua atomic_wr(ibwr)->remote_addr; 5418700e3e7SMoni Shoua wr->wr.atomic.compare_add = 5428700e3e7SMoni Shoua atomic_wr(ibwr)->compare_add; 5438700e3e7SMoni Shoua wr->wr.atomic.swap = atomic_wr(ibwr)->swap; 5448700e3e7SMoni Shoua wr->wr.atomic.rkey = atomic_wr(ibwr)->rkey; 5458700e3e7SMoni Shoua break; 5468700e3e7SMoni Shoua case IB_WR_LOCAL_INV: 5478700e3e7SMoni Shoua wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; 5488700e3e7SMoni Shoua break; 5498700e3e7SMoni Shoua case IB_WR_REG_MR: 5508700e3e7SMoni Shoua wr->wr.reg.mr = reg_wr(ibwr)->mr; 5518700e3e7SMoni Shoua wr->wr.reg.key = reg_wr(ibwr)->key; 5528700e3e7SMoni Shoua wr->wr.reg.access = reg_wr(ibwr)->access; 5538700e3e7SMoni Shoua break; 5548700e3e7SMoni Shoua default: 5558700e3e7SMoni Shoua break; 5568700e3e7SMoni Shoua } 5578700e3e7SMoni Shoua } 5588700e3e7SMoni Shoua } 5598700e3e7SMoni Shoua 560f696bf6dSBart Van Assche static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 5618700e3e7SMoni Shoua unsigned int mask, unsigned int length, 5628700e3e7SMoni Shoua struct rxe_send_wqe *wqe) 5638700e3e7SMoni Shoua { 5648700e3e7SMoni Shoua int num_sge = ibwr->num_sge; 5658700e3e7SMoni Shoua struct ib_sge *sge; 5668700e3e7SMoni Shoua int i; 5678700e3e7SMoni Shoua u8 *p; 5688700e3e7SMoni Shoua 5698700e3e7SMoni Shoua init_send_wr(qp, &wqe->wr, ibwr); 5708700e3e7SMoni Shoua 5718700e3e7SMoni Shoua if (qp_type(qp) == IB_QPT_UD || 5728700e3e7SMoni Shoua qp_type(qp) == IB_QPT_SMI || 5738700e3e7SMoni Shoua qp_type(qp) == IB_QPT_GSI) 5748700e3e7SMoni Shoua memcpy(&wqe->av, &to_rah(ud_wr(ibwr)->ah)->av, sizeof(wqe->av)); 5758700e3e7SMoni Shoua 5768700e3e7SMoni Shoua if (unlikely(ibwr->send_flags & IB_SEND_INLINE)) { 5778700e3e7SMoni Shoua p = wqe->dma.inline_data; 5788700e3e7SMoni Shoua 5798700e3e7SMoni Shoua sge = ibwr->sg_list; 5808700e3e7SMoni Shoua for (i = 0; i < num_sge; i++, sge++) { 5818700e3e7SMoni Shoua memcpy(p, (void *)(uintptr_t)sge->addr, 5828700e3e7SMoni Shoua sge->length); 5838700e3e7SMoni Shoua 5848700e3e7SMoni Shoua p += sge->length; 5858700e3e7SMoni Shoua } 5868700e3e7SMoni Shoua } else if (mask & WR_REG_MASK) { 5878700e3e7SMoni Shoua wqe->mask = mask; 5888700e3e7SMoni Shoua wqe->state = wqe_state_posted; 5898700e3e7SMoni Shoua return 0; 5908700e3e7SMoni Shoua } else 5918700e3e7SMoni Shoua memcpy(wqe->dma.sge, ibwr->sg_list, 5928700e3e7SMoni Shoua num_sge * sizeof(struct ib_sge)); 5938700e3e7SMoni Shoua 594a6544a62SBart Van Assche wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr : 595a6544a62SBart Van Assche mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0; 5968700e3e7SMoni Shoua wqe->mask = mask; 5978700e3e7SMoni Shoua wqe->dma.length = length; 5988700e3e7SMoni Shoua wqe->dma.resid = length; 5998700e3e7SMoni Shoua wqe->dma.num_sge = num_sge; 6008700e3e7SMoni Shoua wqe->dma.cur_sge = 0; 6018700e3e7SMoni Shoua wqe->dma.sge_offset = 0; 6028700e3e7SMoni Shoua wqe->state = wqe_state_posted; 6038700e3e7SMoni Shoua wqe->ssn = atomic_add_return(1, &qp->ssn); 6048700e3e7SMoni Shoua 6058700e3e7SMoni Shoua return 0; 6068700e3e7SMoni Shoua } 6078700e3e7SMoni Shoua 608f696bf6dSBart Van Assche static int post_one_send(struct rxe_qp *qp, const struct ib_send_wr *ibwr, 609e404f945SParav Pandit unsigned int mask, u32 length) 6108700e3e7SMoni Shoua { 6118700e3e7SMoni Shoua int err; 6128700e3e7SMoni Shoua struct rxe_sq *sq = &qp->sq; 6138700e3e7SMoni Shoua struct rxe_send_wqe *send_wqe; 6148700e3e7SMoni Shoua unsigned long flags; 6158700e3e7SMoni Shoua 6168700e3e7SMoni Shoua err = validate_send_wr(qp, ibwr, mask, length); 6178700e3e7SMoni Shoua if (err) 6188700e3e7SMoni Shoua return err; 6198700e3e7SMoni Shoua 6208700e3e7SMoni Shoua spin_lock_irqsave(&qp->sq.sq_lock, flags); 6218700e3e7SMoni Shoua 6228700e3e7SMoni Shoua if (unlikely(queue_full(sq->queue))) { 6238700e3e7SMoni Shoua err = -ENOMEM; 6248700e3e7SMoni Shoua goto err1; 6258700e3e7SMoni Shoua } 6268700e3e7SMoni Shoua 6278700e3e7SMoni Shoua send_wqe = producer_addr(sq->queue); 6288700e3e7SMoni Shoua 6298700e3e7SMoni Shoua err = init_send_wqe(qp, ibwr, mask, length, send_wqe); 6308700e3e7SMoni Shoua if (unlikely(err)) 6318700e3e7SMoni Shoua goto err1; 6328700e3e7SMoni Shoua 6338700e3e7SMoni Shoua /* 6348700e3e7SMoni Shoua * make sure all changes to the work queue are 6358700e3e7SMoni Shoua * written before we update the producer pointer 6368700e3e7SMoni Shoua */ 6378700e3e7SMoni Shoua smp_wmb(); 6388700e3e7SMoni Shoua 6398700e3e7SMoni Shoua advance_producer(sq->queue); 6408700e3e7SMoni Shoua spin_unlock_irqrestore(&qp->sq.sq_lock, flags); 6418700e3e7SMoni Shoua 6428700e3e7SMoni Shoua return 0; 6438700e3e7SMoni Shoua 6448700e3e7SMoni Shoua err1: 6458700e3e7SMoni Shoua spin_unlock_irqrestore(&qp->sq.sq_lock, flags); 6468700e3e7SMoni Shoua return err; 6478700e3e7SMoni Shoua } 6488700e3e7SMoni Shoua 649d34ac5cdSBart Van Assche static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr, 650d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 6518700e3e7SMoni Shoua { 6528700e3e7SMoni Shoua int err = 0; 6538700e3e7SMoni Shoua unsigned int mask; 6548700e3e7SMoni Shoua unsigned int length = 0; 6558700e3e7SMoni Shoua int i; 6565f0b2a60SMikhail Malygin struct ib_send_wr *next; 6578700e3e7SMoni Shoua 6588700e3e7SMoni Shoua while (wr) { 6598700e3e7SMoni Shoua mask = wr_opcode_mask(wr->opcode, qp); 6608700e3e7SMoni Shoua if (unlikely(!mask)) { 6618700e3e7SMoni Shoua err = -EINVAL; 6628700e3e7SMoni Shoua *bad_wr = wr; 6638700e3e7SMoni Shoua break; 6648700e3e7SMoni Shoua } 6658700e3e7SMoni Shoua 6668700e3e7SMoni Shoua if (unlikely((wr->send_flags & IB_SEND_INLINE) && 6678700e3e7SMoni Shoua !(mask & WR_INLINE_MASK))) { 6688700e3e7SMoni Shoua err = -EINVAL; 6698700e3e7SMoni Shoua *bad_wr = wr; 6708700e3e7SMoni Shoua break; 6718700e3e7SMoni Shoua } 6728700e3e7SMoni Shoua 6735f0b2a60SMikhail Malygin next = wr->next; 6745f0b2a60SMikhail Malygin 6758700e3e7SMoni Shoua length = 0; 6768700e3e7SMoni Shoua for (i = 0; i < wr->num_sge; i++) 6778700e3e7SMoni Shoua length += wr->sg_list[i].length; 6788700e3e7SMoni Shoua 6798700e3e7SMoni Shoua err = post_one_send(qp, wr, mask, length); 6808700e3e7SMoni Shoua 6818700e3e7SMoni Shoua if (err) { 6828700e3e7SMoni Shoua *bad_wr = wr; 6838700e3e7SMoni Shoua break; 6848700e3e7SMoni Shoua } 6855f0b2a60SMikhail Malygin wr = next; 6868700e3e7SMoni Shoua } 6878700e3e7SMoni Shoua 6881661d3b0SAlexandru Moise rxe_run_task(&qp->req.task, 1); 6896f301e06SBart Van Assche if (unlikely(qp->req.state == QP_STATE_ERROR)) 6906f301e06SBart Van Assche rxe_run_task(&qp->comp.task, 1); 6918700e3e7SMoni Shoua 6928700e3e7SMoni Shoua return err; 6938700e3e7SMoni Shoua } 6948700e3e7SMoni Shoua 695d34ac5cdSBart Van Assche static int rxe_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, 696d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr) 697063af595SParav Pandit { 698063af595SParav Pandit struct rxe_qp *qp = to_rqp(ibqp); 699063af595SParav Pandit 700063af595SParav Pandit if (unlikely(!qp->valid)) { 701063af595SParav Pandit *bad_wr = wr; 702063af595SParav Pandit return -EINVAL; 703063af595SParav Pandit } 704063af595SParav Pandit 705063af595SParav Pandit if (unlikely(qp->req.state < QP_STATE_READY)) { 706063af595SParav Pandit *bad_wr = wr; 707063af595SParav Pandit return -EINVAL; 708063af595SParav Pandit } 709063af595SParav Pandit 710063af595SParav Pandit if (qp->is_user) { 711063af595SParav Pandit /* Utilize process context to do protocol processing */ 712063af595SParav Pandit rxe_run_task(&qp->req.task, 0); 713063af595SParav Pandit return 0; 714063af595SParav Pandit } else 715063af595SParav Pandit return rxe_post_send_kernel(qp, wr, bad_wr); 716063af595SParav Pandit } 717063af595SParav Pandit 718d34ac5cdSBart Van Assche static int rxe_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, 719d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr) 7208700e3e7SMoni Shoua { 7218700e3e7SMoni Shoua int err = 0; 7228700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 7238700e3e7SMoni Shoua struct rxe_rq *rq = &qp->rq; 7248700e3e7SMoni Shoua unsigned long flags; 7258700e3e7SMoni Shoua 7268700e3e7SMoni Shoua if (unlikely((qp_state(qp) < IB_QPS_INIT) || !qp->valid)) { 7278700e3e7SMoni Shoua *bad_wr = wr; 7288700e3e7SMoni Shoua err = -EINVAL; 7298700e3e7SMoni Shoua goto err1; 7308700e3e7SMoni Shoua } 7318700e3e7SMoni Shoua 7328700e3e7SMoni Shoua if (unlikely(qp->srq)) { 7338700e3e7SMoni Shoua *bad_wr = wr; 7348700e3e7SMoni Shoua err = -EINVAL; 7358700e3e7SMoni Shoua goto err1; 7368700e3e7SMoni Shoua } 7378700e3e7SMoni Shoua 7388700e3e7SMoni Shoua spin_lock_irqsave(&rq->producer_lock, flags); 7398700e3e7SMoni Shoua 7408700e3e7SMoni Shoua while (wr) { 7418700e3e7SMoni Shoua err = post_one_recv(rq, wr); 7428700e3e7SMoni Shoua if (unlikely(err)) { 7438700e3e7SMoni Shoua *bad_wr = wr; 7448700e3e7SMoni Shoua break; 7458700e3e7SMoni Shoua } 7468700e3e7SMoni Shoua wr = wr->next; 7478700e3e7SMoni Shoua } 7488700e3e7SMoni Shoua 7498700e3e7SMoni Shoua spin_unlock_irqrestore(&rq->producer_lock, flags); 7508700e3e7SMoni Shoua 75112171971SVijay Immanuel if (qp->resp.state == QP_STATE_ERROR) 75212171971SVijay Immanuel rxe_run_task(&qp->resp.task, 1); 75312171971SVijay Immanuel 7548700e3e7SMoni Shoua err1: 7558700e3e7SMoni Shoua return err; 7568700e3e7SMoni Shoua } 7578700e3e7SMoni Shoua 758e39afe3dSLeon Romanovsky static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, 7598700e3e7SMoni Shoua struct ib_udata *udata) 7608700e3e7SMoni Shoua { 7618700e3e7SMoni Shoua int err; 762e39afe3dSLeon Romanovsky struct ib_device *dev = ibcq->device; 7638700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(dev); 764e39afe3dSLeon Romanovsky struct rxe_cq *cq = to_rcq(ibcq); 7650c43ab37SJason Gunthorpe struct rxe_create_cq_resp __user *uresp = NULL; 7660c43ab37SJason Gunthorpe 7670c43ab37SJason Gunthorpe if (udata) { 7680c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 769e39afe3dSLeon Romanovsky return -EINVAL; 7700c43ab37SJason Gunthorpe uresp = udata->outbuf; 7710c43ab37SJason Gunthorpe } 7728700e3e7SMoni Shoua 7738700e3e7SMoni Shoua if (attr->flags) 774e39afe3dSLeon Romanovsky return -EINVAL; 7758700e3e7SMoni Shoua 776b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector); 7778700e3e7SMoni Shoua if (err) 778e39afe3dSLeon Romanovsky return err; 7798700e3e7SMoni Shoua 780ff23dfa1SShamir Rabinovitch err = rxe_cq_from_init(rxe, cq, attr->cqe, attr->comp_vector, udata, 781ff23dfa1SShamir Rabinovitch uresp); 7828700e3e7SMoni Shoua if (err) 783e39afe3dSLeon Romanovsky return err; 7848700e3e7SMoni Shoua 785e39afe3dSLeon Romanovsky return rxe_add_to_pool(&rxe->cq_pool, &cq->pelem); 7868700e3e7SMoni Shoua } 7878700e3e7SMoni Shoua 78843d781b9SLeon Romanovsky static int rxe_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) 7898700e3e7SMoni Shoua { 7908700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 7918700e3e7SMoni Shoua 792bfc3ae05SAndrew Boyer rxe_cq_disable(cq); 793bfc3ae05SAndrew Boyer 7948700e3e7SMoni Shoua rxe_drop_ref(cq); 79543d781b9SLeon Romanovsky return 0; 7968700e3e7SMoni Shoua } 7978700e3e7SMoni Shoua 7988700e3e7SMoni Shoua static int rxe_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) 7998700e3e7SMoni Shoua { 8008700e3e7SMoni Shoua int err; 8018700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8028700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibcq->device); 8030c43ab37SJason Gunthorpe struct rxe_resize_cq_resp __user *uresp = NULL; 8040c43ab37SJason Gunthorpe 8050c43ab37SJason Gunthorpe if (udata) { 8060c43ab37SJason Gunthorpe if (udata->outlen < sizeof(*uresp)) 8070c43ab37SJason Gunthorpe return -EINVAL; 8080c43ab37SJason Gunthorpe uresp = udata->outbuf; 8090c43ab37SJason Gunthorpe } 8108700e3e7SMoni Shoua 811b92ec0feSJason Gunthorpe err = rxe_cq_chk_attr(rxe, cq, cqe, 0); 8128700e3e7SMoni Shoua if (err) 8138700e3e7SMoni Shoua goto err1; 8148700e3e7SMoni Shoua 815ff23dfa1SShamir Rabinovitch err = rxe_cq_resize_queue(cq, cqe, uresp, udata); 8168700e3e7SMoni Shoua if (err) 8178700e3e7SMoni Shoua goto err1; 8188700e3e7SMoni Shoua 8198700e3e7SMoni Shoua return 0; 8208700e3e7SMoni Shoua 8218700e3e7SMoni Shoua err1: 8228700e3e7SMoni Shoua return err; 8238700e3e7SMoni Shoua } 8248700e3e7SMoni Shoua 8258700e3e7SMoni Shoua static int rxe_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc) 8268700e3e7SMoni Shoua { 8278700e3e7SMoni Shoua int i; 8288700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8298700e3e7SMoni Shoua struct rxe_cqe *cqe; 8308700e3e7SMoni Shoua unsigned long flags; 8318700e3e7SMoni Shoua 8328700e3e7SMoni Shoua spin_lock_irqsave(&cq->cq_lock, flags); 8338700e3e7SMoni Shoua for (i = 0; i < num_entries; i++) { 8348700e3e7SMoni Shoua cqe = queue_head(cq->queue); 8358700e3e7SMoni Shoua if (!cqe) 8368700e3e7SMoni Shoua break; 8378700e3e7SMoni Shoua 8388700e3e7SMoni Shoua memcpy(wc++, &cqe->ibwc, sizeof(*wc)); 8398700e3e7SMoni Shoua advance_consumer(cq->queue); 8408700e3e7SMoni Shoua } 8418700e3e7SMoni Shoua spin_unlock_irqrestore(&cq->cq_lock, flags); 8428700e3e7SMoni Shoua 8438700e3e7SMoni Shoua return i; 8448700e3e7SMoni Shoua } 8458700e3e7SMoni Shoua 8468700e3e7SMoni Shoua static int rxe_peek_cq(struct ib_cq *ibcq, int wc_cnt) 8478700e3e7SMoni Shoua { 8488700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 8498700e3e7SMoni Shoua int count = queue_count(cq->queue); 8508700e3e7SMoni Shoua 8518700e3e7SMoni Shoua return (count > wc_cnt) ? wc_cnt : count; 8528700e3e7SMoni Shoua } 8538700e3e7SMoni Shoua 8548700e3e7SMoni Shoua static int rxe_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) 8558700e3e7SMoni Shoua { 8568700e3e7SMoni Shoua struct rxe_cq *cq = to_rcq(ibcq); 857accacb8fSAndrew Boyer unsigned long irq_flags; 858accacb8fSAndrew Boyer int ret = 0; 8598700e3e7SMoni Shoua 860accacb8fSAndrew Boyer spin_lock_irqsave(&cq->cq_lock, irq_flags); 8618700e3e7SMoni Shoua if (cq->notify != IB_CQ_NEXT_COMP) 8628700e3e7SMoni Shoua cq->notify = flags & IB_CQ_SOLICITED_MASK; 8638700e3e7SMoni Shoua 864accacb8fSAndrew Boyer if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !queue_empty(cq->queue)) 865accacb8fSAndrew Boyer ret = 1; 866accacb8fSAndrew Boyer 867accacb8fSAndrew Boyer spin_unlock_irqrestore(&cq->cq_lock, irq_flags); 868accacb8fSAndrew Boyer 869accacb8fSAndrew Boyer return ret; 8708700e3e7SMoni Shoua } 8718700e3e7SMoni Shoua 8728700e3e7SMoni Shoua static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access) 8738700e3e7SMoni Shoua { 8748700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 8758700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 8768700e3e7SMoni Shoua struct rxe_mem *mr; 8778700e3e7SMoni Shoua 8788700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 879293d8440SKamal Heib if (!mr) 880293d8440SKamal Heib return ERR_PTR(-ENOMEM); 8818700e3e7SMoni Shoua 8828700e3e7SMoni Shoua rxe_add_index(mr); 8838700e3e7SMoni Shoua rxe_add_ref(pd); 884293d8440SKamal Heib rxe_mem_init_dma(pd, access, mr); 8858700e3e7SMoni Shoua 8868700e3e7SMoni Shoua return &mr->ibmr; 8878700e3e7SMoni Shoua } 8888700e3e7SMoni Shoua 8898700e3e7SMoni Shoua static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, 8908700e3e7SMoni Shoua u64 start, 8918700e3e7SMoni Shoua u64 length, 8928700e3e7SMoni Shoua u64 iova, 8938700e3e7SMoni Shoua int access, struct ib_udata *udata) 8948700e3e7SMoni Shoua { 8958700e3e7SMoni Shoua int err; 8968700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 8978700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 8988700e3e7SMoni Shoua struct rxe_mem *mr; 8998700e3e7SMoni Shoua 9008700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 9018700e3e7SMoni Shoua if (!mr) { 9028700e3e7SMoni Shoua err = -ENOMEM; 9038700e3e7SMoni Shoua goto err2; 9048700e3e7SMoni Shoua } 9058700e3e7SMoni Shoua 9068700e3e7SMoni Shoua rxe_add_index(mr); 9078700e3e7SMoni Shoua 9088700e3e7SMoni Shoua rxe_add_ref(pd); 9098700e3e7SMoni Shoua 910e12ee8ceSZhu Yanjun err = rxe_mem_init_user(pd, start, length, iova, 9118700e3e7SMoni Shoua access, udata, mr); 9128700e3e7SMoni Shoua if (err) 9138700e3e7SMoni Shoua goto err3; 9148700e3e7SMoni Shoua 9158700e3e7SMoni Shoua return &mr->ibmr; 9168700e3e7SMoni Shoua 9178700e3e7SMoni Shoua err3: 9188700e3e7SMoni Shoua rxe_drop_ref(pd); 9198700e3e7SMoni Shoua rxe_drop_index(mr); 9208700e3e7SMoni Shoua rxe_drop_ref(mr); 9218700e3e7SMoni Shoua err2: 9228700e3e7SMoni Shoua return ERR_PTR(err); 9238700e3e7SMoni Shoua } 9248700e3e7SMoni Shoua 925c4367a26SShamir Rabinovitch static int rxe_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata) 9268700e3e7SMoni Shoua { 9278700e3e7SMoni Shoua struct rxe_mem *mr = to_rmr(ibmr); 9288700e3e7SMoni Shoua 9298700e3e7SMoni Shoua mr->state = RXE_MEM_STATE_ZOMBIE; 9301858d98bSBob Pearson rxe_drop_ref(mr_pd(mr)); 9318700e3e7SMoni Shoua rxe_drop_index(mr); 9328700e3e7SMoni Shoua rxe_drop_ref(mr); 9338700e3e7SMoni Shoua return 0; 9348700e3e7SMoni Shoua } 9358700e3e7SMoni Shoua 936c4367a26SShamir Rabinovitch static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, 93742a3b153SGal Pressman u32 max_num_sg) 9388700e3e7SMoni Shoua { 9398700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibpd->device); 9408700e3e7SMoni Shoua struct rxe_pd *pd = to_rpd(ibpd); 9418700e3e7SMoni Shoua struct rxe_mem *mr; 9428700e3e7SMoni Shoua int err; 9438700e3e7SMoni Shoua 9448700e3e7SMoni Shoua if (mr_type != IB_MR_TYPE_MEM_REG) 9458700e3e7SMoni Shoua return ERR_PTR(-EINVAL); 9468700e3e7SMoni Shoua 9478700e3e7SMoni Shoua mr = rxe_alloc(&rxe->mr_pool); 9488700e3e7SMoni Shoua if (!mr) { 9498700e3e7SMoni Shoua err = -ENOMEM; 9508700e3e7SMoni Shoua goto err1; 9518700e3e7SMoni Shoua } 9528700e3e7SMoni Shoua 9538700e3e7SMoni Shoua rxe_add_index(mr); 9548700e3e7SMoni Shoua 9558700e3e7SMoni Shoua rxe_add_ref(pd); 9568700e3e7SMoni Shoua 957e12ee8ceSZhu Yanjun err = rxe_mem_init_fast(pd, max_num_sg, mr); 9588700e3e7SMoni Shoua if (err) 9598700e3e7SMoni Shoua goto err2; 9608700e3e7SMoni Shoua 9618700e3e7SMoni Shoua return &mr->ibmr; 9628700e3e7SMoni Shoua 9638700e3e7SMoni Shoua err2: 9648700e3e7SMoni Shoua rxe_drop_ref(pd); 9658700e3e7SMoni Shoua rxe_drop_index(mr); 9668700e3e7SMoni Shoua rxe_drop_ref(mr); 9678700e3e7SMoni Shoua err1: 9688700e3e7SMoni Shoua return ERR_PTR(err); 9698700e3e7SMoni Shoua } 9708700e3e7SMoni Shoua 9718700e3e7SMoni Shoua static int rxe_set_page(struct ib_mr *ibmr, u64 addr) 9728700e3e7SMoni Shoua { 9738700e3e7SMoni Shoua struct rxe_mem *mr = to_rmr(ibmr); 9748700e3e7SMoni Shoua struct rxe_map *map; 9758700e3e7SMoni Shoua struct rxe_phys_buf *buf; 9768700e3e7SMoni Shoua 9778700e3e7SMoni Shoua if (unlikely(mr->nbuf == mr->num_buf)) 9788700e3e7SMoni Shoua return -ENOMEM; 9798700e3e7SMoni Shoua 9808700e3e7SMoni Shoua map = mr->map[mr->nbuf / RXE_BUF_PER_MAP]; 9818700e3e7SMoni Shoua buf = &map->buf[mr->nbuf % RXE_BUF_PER_MAP]; 9828700e3e7SMoni Shoua 9838700e3e7SMoni Shoua buf->addr = addr; 9848700e3e7SMoni Shoua buf->size = ibmr->page_size; 9858700e3e7SMoni Shoua mr->nbuf++; 9868700e3e7SMoni Shoua 9878700e3e7SMoni Shoua return 0; 9888700e3e7SMoni Shoua } 9898700e3e7SMoni Shoua 990e404f945SParav Pandit static int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, 991e404f945SParav Pandit int sg_nents, unsigned int *sg_offset) 9928700e3e7SMoni Shoua { 9938700e3e7SMoni Shoua struct rxe_mem *mr = to_rmr(ibmr); 9948700e3e7SMoni Shoua int n; 9958700e3e7SMoni Shoua 9968700e3e7SMoni Shoua mr->nbuf = 0; 9978700e3e7SMoni Shoua 9988700e3e7SMoni Shoua n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page); 9998700e3e7SMoni Shoua 10008700e3e7SMoni Shoua mr->va = ibmr->iova; 10018700e3e7SMoni Shoua mr->iova = ibmr->iova; 10028700e3e7SMoni Shoua mr->length = ibmr->length; 10038700e3e7SMoni Shoua mr->page_shift = ilog2(ibmr->page_size); 10048700e3e7SMoni Shoua mr->page_mask = ibmr->page_size - 1; 10058700e3e7SMoni Shoua mr->offset = mr->iova & mr->page_mask; 10068700e3e7SMoni Shoua 10078700e3e7SMoni Shoua return n; 10088700e3e7SMoni Shoua } 10098700e3e7SMoni Shoua 10108700e3e7SMoni Shoua static int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) 10118700e3e7SMoni Shoua { 10128700e3e7SMoni Shoua int err; 10138700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 10148700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 10158700e3e7SMoni Shoua struct rxe_mc_grp *grp; 10168700e3e7SMoni Shoua 10178700e3e7SMoni Shoua /* takes a ref on grp if successful */ 10188700e3e7SMoni Shoua err = rxe_mcast_get_grp(rxe, mgid, &grp); 10198700e3e7SMoni Shoua if (err) 10208700e3e7SMoni Shoua return err; 10218700e3e7SMoni Shoua 10228700e3e7SMoni Shoua err = rxe_mcast_add_grp_elem(rxe, qp, grp); 10238700e3e7SMoni Shoua 10248700e3e7SMoni Shoua rxe_drop_ref(grp); 10258700e3e7SMoni Shoua return err; 10268700e3e7SMoni Shoua } 10278700e3e7SMoni Shoua 10288700e3e7SMoni Shoua static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) 10298700e3e7SMoni Shoua { 10308700e3e7SMoni Shoua struct rxe_dev *rxe = to_rdev(ibqp->device); 10318700e3e7SMoni Shoua struct rxe_qp *qp = to_rqp(ibqp); 10328700e3e7SMoni Shoua 10338700e3e7SMoni Shoua return rxe_mcast_drop_grp_elem(rxe, qp, mgid); 10348700e3e7SMoni Shoua } 10358700e3e7SMoni Shoua 1036c05d2664SKamal Heib static ssize_t parent_show(struct device *device, 10378700e3e7SMoni Shoua struct device_attribute *attr, char *buf) 10388700e3e7SMoni Shoua { 103954747231SParav Pandit struct rxe_dev *rxe = 104054747231SParav Pandit rdma_device_to_drv_device(device, struct rxe_dev, ib_dev); 10418700e3e7SMoni Shoua 104260b1af64SYi Zhang return scnprintf(buf, PAGE_SIZE, "%s\n", rxe_parent_name(rxe, 1)); 10438700e3e7SMoni Shoua } 10448700e3e7SMoni Shoua 1045c05d2664SKamal Heib static DEVICE_ATTR_RO(parent); 10468700e3e7SMoni Shoua 1047508a523fSParav Pandit static struct attribute *rxe_dev_attributes[] = { 1048508a523fSParav Pandit &dev_attr_parent.attr, 1049508a523fSParav Pandit NULL 1050508a523fSParav Pandit }; 1051508a523fSParav Pandit 1052508a523fSParav Pandit static const struct attribute_group rxe_attr_group = { 1053508a523fSParav Pandit .attrs = rxe_dev_attributes, 10548700e3e7SMoni Shoua }; 10558700e3e7SMoni Shoua 1056ca22354bSJason Gunthorpe static int rxe_enable_driver(struct ib_device *ib_dev) 1057ca22354bSJason Gunthorpe { 1058ca22354bSJason Gunthorpe struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev); 1059ca22354bSJason Gunthorpe 1060ca22354bSJason Gunthorpe rxe_set_port_state(rxe); 1061ca22354bSJason Gunthorpe dev_info(&rxe->ib_dev.dev, "added %s\n", netdev_name(rxe->ndev)); 1062ca22354bSJason Gunthorpe return 0; 1063ca22354bSJason Gunthorpe } 1064ca22354bSJason Gunthorpe 1065573efc4bSKamal Heib static const struct ib_device_ops rxe_dev_ops = { 10667a154142SJason Gunthorpe .owner = THIS_MODULE, 1067b9560a41SJason Gunthorpe .driver_id = RDMA_DRIVER_RXE, 106872c6ec18SJason Gunthorpe .uverbs_abi_ver = RXE_UVERBS_ABI_VERSION, 1069b9560a41SJason Gunthorpe 1070573efc4bSKamal Heib .alloc_hw_stats = rxe_ib_alloc_hw_stats, 1071573efc4bSKamal Heib .alloc_mr = rxe_alloc_mr, 1072573efc4bSKamal Heib .alloc_pd = rxe_alloc_pd, 1073573efc4bSKamal Heib .alloc_ucontext = rxe_alloc_ucontext, 1074573efc4bSKamal Heib .attach_mcast = rxe_attach_mcast, 1075573efc4bSKamal Heib .create_ah = rxe_create_ah, 1076573efc4bSKamal Heib .create_cq = rxe_create_cq, 1077573efc4bSKamal Heib .create_qp = rxe_create_qp, 1078573efc4bSKamal Heib .create_srq = rxe_create_srq, 1079c367074bSJason Gunthorpe .dealloc_driver = rxe_dealloc, 1080573efc4bSKamal Heib .dealloc_pd = rxe_dealloc_pd, 1081573efc4bSKamal Heib .dealloc_ucontext = rxe_dealloc_ucontext, 1082573efc4bSKamal Heib .dereg_mr = rxe_dereg_mr, 1083573efc4bSKamal Heib .destroy_ah = rxe_destroy_ah, 1084573efc4bSKamal Heib .destroy_cq = rxe_destroy_cq, 1085573efc4bSKamal Heib .destroy_qp = rxe_destroy_qp, 1086573efc4bSKamal Heib .destroy_srq = rxe_destroy_srq, 1087573efc4bSKamal Heib .detach_mcast = rxe_detach_mcast, 1088ca22354bSJason Gunthorpe .enable_driver = rxe_enable_driver, 1089573efc4bSKamal Heib .get_dma_mr = rxe_get_dma_mr, 1090573efc4bSKamal Heib .get_hw_stats = rxe_ib_get_hw_stats, 1091573efc4bSKamal Heib .get_link_layer = rxe_get_link_layer, 1092573efc4bSKamal Heib .get_port_immutable = rxe_port_immutable, 1093573efc4bSKamal Heib .map_mr_sg = rxe_map_mr_sg, 1094573efc4bSKamal Heib .mmap = rxe_mmap, 1095573efc4bSKamal Heib .modify_ah = rxe_modify_ah, 1096573efc4bSKamal Heib .modify_device = rxe_modify_device, 1097573efc4bSKamal Heib .modify_port = rxe_modify_port, 1098573efc4bSKamal Heib .modify_qp = rxe_modify_qp, 1099573efc4bSKamal Heib .modify_srq = rxe_modify_srq, 1100573efc4bSKamal Heib .peek_cq = rxe_peek_cq, 1101573efc4bSKamal Heib .poll_cq = rxe_poll_cq, 1102573efc4bSKamal Heib .post_recv = rxe_post_recv, 1103573efc4bSKamal Heib .post_send = rxe_post_send, 1104573efc4bSKamal Heib .post_srq_recv = rxe_post_srq_recv, 1105573efc4bSKamal Heib .query_ah = rxe_query_ah, 1106573efc4bSKamal Heib .query_device = rxe_query_device, 1107573efc4bSKamal Heib .query_pkey = rxe_query_pkey, 1108573efc4bSKamal Heib .query_port = rxe_query_port, 1109573efc4bSKamal Heib .query_qp = rxe_query_qp, 1110573efc4bSKamal Heib .query_srq = rxe_query_srq, 1111573efc4bSKamal Heib .reg_user_mr = rxe_reg_user_mr, 1112573efc4bSKamal Heib .req_notify_cq = rxe_req_notify_cq, 1113573efc4bSKamal Heib .resize_cq = rxe_resize_cq, 1114d3456914SLeon Romanovsky 1115d3456914SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ah, rxe_ah, ibah), 1116e39afe3dSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_cq, rxe_cq, ibcq), 111721a428a0SLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_pd, rxe_pd, ibpd), 111868e326deSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_srq, rxe_srq, ibsrq), 1119a2a074efSLeon Romanovsky INIT_RDMA_OBJ_SIZE(ib_ucontext, rxe_ucontext, ibuc), 1120573efc4bSKamal Heib }; 1121573efc4bSKamal Heib 112266920e1bSSteve Wise int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name) 11238700e3e7SMoni Shoua { 11248700e3e7SMoni Shoua int err; 11258700e3e7SMoni Shoua struct ib_device *dev = &rxe->ib_dev; 11263192c53eSThomas Bogendoerfer struct crypto_shash *tfm; 11278700e3e7SMoni Shoua 11288700e3e7SMoni Shoua strlcpy(dev->node_desc, "rxe", sizeof(dev->node_desc)); 11298700e3e7SMoni Shoua 11308700e3e7SMoni Shoua dev->node_type = RDMA_NODE_IB_CA; 11318700e3e7SMoni Shoua dev->phys_port_cnt = 1; 113267cf3623SSagi Grimberg dev->num_comp_vectors = num_possible_cpus(); 113385e9f1dbSBart Van Assche dev->dev.parent = rxe_dma_device(rxe); 11348700e3e7SMoni Shoua dev->local_dma_lkey = 0; 11354d6f2859SYuval Shaia addrconf_addr_eui48((unsigned char *)&dev->node_guid, 11364d6f2859SYuval Shaia rxe->ndev->dev_addr); 113797458fd5SBart Van Assche dev->dev.dma_parms = &rxe->dma_parms; 1138e0477b34SJason Gunthorpe dma_set_max_seg_size(&dev->dev, UINT_MAX); 1139e0477b34SJason Gunthorpe dma_set_coherent_mask(&dev->dev, dma_get_required_mask(&dev->dev)); 11408700e3e7SMoni Shoua 1141c074bb1eSJason Gunthorpe dev->uverbs_cmd_mask |= 114244ce37bcSJason Gunthorpe BIT_ULL(IB_USER_VERBS_CMD_POST_SRQ_RECV) 11438700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_POST_SEND) 11448700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_POST_RECV) 11458700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_POLL_CQ) 11468700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_PEEK_CQ) 11478700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) 11488700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_CREATE_AH) 11498700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_MODIFY_AH) 11508700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_QUERY_AH) 11518700e3e7SMoni Shoua | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_AH) 11528700e3e7SMoni Shoua ; 11538700e3e7SMoni Shoua 1154573efc4bSKamal Heib ib_set_device_ops(dev, &rxe_dev_ops); 11554c173f59SJason Gunthorpe err = ib_device_set_netdev(&rxe->ib_dev, rxe->ndev, 1); 11564c173f59SJason Gunthorpe if (err) 11574c173f59SJason Gunthorpe return err; 11588700e3e7SMoni Shoua 11593192c53eSThomas Bogendoerfer tfm = crypto_alloc_shash("crc32", 0, 0); 11603192c53eSThomas Bogendoerfer if (IS_ERR(tfm)) { 116127b0b832SColin Ian King pr_err("failed to allocate crc algorithm err:%ld\n", 11623192c53eSThomas Bogendoerfer PTR_ERR(tfm)); 11633192c53eSThomas Bogendoerfer return PTR_ERR(tfm); 1164cee2688eSyonatanc } 11653192c53eSThomas Bogendoerfer rxe->tfm = tfm; 1166cee2688eSyonatanc 1167508a523fSParav Pandit rdma_set_device_sysfs_group(dev, &rxe_attr_group); 1168e0477b34SJason Gunthorpe err = ib_register_device(dev, ibdev_name, NULL); 1169c367074bSJason Gunthorpe if (err) 117061013828SKamal Heib pr_warn("%s failed with error %d\n", __func__, err); 1171cee2688eSyonatanc 1172ca22354bSJason Gunthorpe /* 1173ca22354bSJason Gunthorpe * Note that rxe may be invalid at this point if another thread 1174ca22354bSJason Gunthorpe * unregistered it. 1175ca22354bSJason Gunthorpe */ 11768700e3e7SMoni Shoua return err; 11778700e3e7SMoni Shoua } 1178