Bob Pearson | 63fa15d | 2020-08-27 09:54:40 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
| 4 | * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
Bart Van Assche | 0bbb3b7 | 2017-01-20 13:04:37 -0800 | [diff] [blame] | 7 | #include <linux/dma-mapping.h> |
Yuval Shaia | 4d6f285 | 2017-03-14 16:01:57 +0200 | [diff] [blame] | 8 | #include <net/addrconf.h> |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 9 | #include <rdma/uverbs_ioctl.h> |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 10 | #include "rxe.h" |
| 11 | #include "rxe_loc.h" |
| 12 | #include "rxe_queue.h" |
Yonatan Cohen | 0b1e5b9 | 2017-03-10 18:23:56 +0200 | [diff] [blame] | 13 | #include "rxe_hw_counters.h" |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 14 | |
| 15 | static int rxe_query_device(struct ib_device *dev, |
| 16 | struct ib_device_attr *attr, |
| 17 | struct ib_udata *uhw) |
| 18 | { |
| 19 | struct rxe_dev *rxe = to_rdev(dev); |
| 20 | |
| 21 | if (uhw->inlen || uhw->outlen) |
| 22 | return -EINVAL; |
| 23 | |
| 24 | *attr = rxe->attr; |
| 25 | return 0; |
| 26 | } |
| 27 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 28 | static int rxe_query_port(struct ib_device *dev, |
Mark Bloch | 1fb7f89 | 2021-03-01 09:04:20 +0200 | [diff] [blame] | 29 | u32 port_num, struct ib_port_attr *attr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 30 | { |
| 31 | struct rxe_dev *rxe = to_rdev(dev); |
Yuval Shaia | 59590b8 | 2018-12-09 13:06:10 +0200 | [diff] [blame] | 32 | int rc; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 33 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 34 | /* *attr being zeroed by the caller, avoid zeroing it here */ |
Zhu Yanjun | d12faf2 | 2021-09-14 21:24:56 -0400 | [diff] [blame] | 35 | *attr = rxe->port.attr; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 36 | |
| 37 | mutex_lock(&rxe->usdev_lock); |
Yuval Shaia | d418619 | 2017-06-14 23:13:34 +0300 | [diff] [blame] | 38 | rc = ib_get_eth_speed(dev, port_num, &attr->active_speed, |
| 39 | &attr->active_width); |
Andrew Boyer | 5736c7c | 2018-11-01 09:18:45 -0400 | [diff] [blame] | 40 | |
| 41 | if (attr->state == IB_PORT_ACTIVE) |
Kamal Heib | 72a7720 | 2019-08-07 13:31:35 +0300 | [diff] [blame] | 42 | attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP; |
Andrew Boyer | 5736c7c | 2018-11-01 09:18:45 -0400 | [diff] [blame] | 43 | else if (dev_get_flags(rxe->ndev) & IFF_UP) |
Kamal Heib | 72a7720 | 2019-08-07 13:31:35 +0300 | [diff] [blame] | 44 | attr->phys_state = IB_PORT_PHYS_STATE_POLLING; |
Andrew Boyer | 5736c7c | 2018-11-01 09:18:45 -0400 | [diff] [blame] | 45 | else |
Kamal Heib | 72a7720 | 2019-08-07 13:31:35 +0300 | [diff] [blame] | 46 | attr->phys_state = IB_PORT_PHYS_STATE_DISABLED; |
Andrew Boyer | 5736c7c | 2018-11-01 09:18:45 -0400 | [diff] [blame] | 47 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 48 | mutex_unlock(&rxe->usdev_lock); |
| 49 | |
Yuval Shaia | d418619 | 2017-06-14 23:13:34 +0300 | [diff] [blame] | 50 | return rc; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 51 | } |
| 52 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 53 | static int rxe_query_pkey(struct ib_device *device, |
Mark Bloch | 1fb7f89 | 2021-03-01 09:04:20 +0200 | [diff] [blame] | 54 | u32 port_num, u16 index, u16 *pkey) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 55 | { |
Kamal Heib | 76251e1 | 2020-07-21 13:16:18 +0300 | [diff] [blame] | 56 | if (index > 0) |
| 57 | return -EINVAL; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 58 | |
Kamal Heib | 76251e1 | 2020-07-21 13:16:18 +0300 | [diff] [blame] | 59 | *pkey = IB_DEFAULT_PKEY_FULL; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 60 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int rxe_modify_device(struct ib_device *dev, |
| 64 | int mask, struct ib_device_modify *attr) |
| 65 | { |
| 66 | struct rxe_dev *rxe = to_rdev(dev); |
| 67 | |
Kamal Heib | f3fceba | 2019-09-23 13:41:58 +0300 | [diff] [blame] | 68 | if (mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | |
| 69 | IB_DEVICE_MODIFY_NODE_DESC)) |
| 70 | return -EOPNOTSUPP; |
| 71 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 72 | if (mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) |
| 73 | rxe->attr.sys_image_guid = cpu_to_be64(attr->sys_image_guid); |
| 74 | |
| 75 | if (mask & IB_DEVICE_MODIFY_NODE_DESC) { |
| 76 | memcpy(rxe->ib_dev.node_desc, |
| 77 | attr->node_desc, sizeof(rxe->ib_dev.node_desc)); |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int rxe_modify_port(struct ib_device *dev, |
Mark Bloch | 1fb7f89 | 2021-03-01 09:04:20 +0200 | [diff] [blame] | 84 | u32 port_num, int mask, struct ib_port_modify *attr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 85 | { |
| 86 | struct rxe_dev *rxe = to_rdev(dev); |
| 87 | struct rxe_port *port; |
| 88 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 89 | port = &rxe->port; |
| 90 | |
| 91 | port->attr.port_cap_flags |= attr->set_port_cap_mask; |
| 92 | port->attr.port_cap_flags &= ~attr->clr_port_cap_mask; |
| 93 | |
| 94 | if (mask & IB_PORT_RESET_QKEY_CNTR) |
| 95 | port->attr.qkey_viol_cntr = 0; |
| 96 | |
| 97 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static enum rdma_link_layer rxe_get_link_layer(struct ib_device *dev, |
Mark Bloch | 1fb7f89 | 2021-03-01 09:04:20 +0200 | [diff] [blame] | 101 | u32 port_num) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 102 | { |
Kamal Heib | 420bd9e | 2020-07-05 13:43:13 +0300 | [diff] [blame] | 103 | return IB_LINK_LAYER_ETHERNET; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 104 | } |
| 105 | |
Bob Pearson | 91a42c5 | 2020-12-16 17:15:48 -0600 | [diff] [blame] | 106 | static int rxe_alloc_ucontext(struct ib_ucontext *ibuc, struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 107 | { |
Bob Pearson | 91a42c5 | 2020-12-16 17:15:48 -0600 | [diff] [blame] | 108 | struct rxe_dev *rxe = to_rdev(ibuc->device); |
| 109 | struct rxe_ucontext *uc = to_ruc(ibuc); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 110 | |
Bob Pearson | 91a42c5 | 2020-12-16 17:15:48 -0600 | [diff] [blame] | 111 | return rxe_add_to_pool(&rxe->uc_pool, uc); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 112 | } |
| 113 | |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 114 | static void rxe_dealloc_ucontext(struct ib_ucontext *ibuc) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 115 | { |
| 116 | struct rxe_ucontext *uc = to_ruc(ibuc); |
| 117 | |
| 118 | rxe_drop_ref(uc); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 119 | } |
| 120 | |
Mark Bloch | 1fb7f89 | 2021-03-01 09:04:20 +0200 | [diff] [blame] | 121 | static int rxe_port_immutable(struct ib_device *dev, u32 port_num, |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 122 | struct ib_port_immutable *immutable) |
| 123 | { |
| 124 | int err; |
| 125 | struct ib_port_attr attr; |
| 126 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 127 | immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP; |
| 128 | |
| 129 | err = ib_query_port(dev, port_num, &attr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 130 | if (err) |
| 131 | return err; |
| 132 | |
| 133 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 134 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 135 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 140 | static int rxe_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 141 | { |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 142 | struct rxe_dev *rxe = to_rdev(ibpd->device); |
| 143 | struct rxe_pd *pd = to_rpd(ibpd); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 144 | |
Bob Pearson | 91a42c5 | 2020-12-16 17:15:48 -0600 | [diff] [blame] | 145 | return rxe_add_to_pool(&rxe->pd_pool, pd); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 146 | } |
| 147 | |
Leon Romanovsky | 91a7c58 | 2020-09-07 15:09:13 +0300 | [diff] [blame] | 148 | static int rxe_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 149 | { |
| 150 | struct rxe_pd *pd = to_rpd(ibpd); |
| 151 | |
| 152 | rxe_drop_ref(pd); |
Leon Romanovsky | 91a7c58 | 2020-09-07 15:09:13 +0300 | [diff] [blame] | 153 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 154 | } |
| 155 | |
Maor Gottlieb | fa5d010 | 2020-04-30 22:21:42 +0300 | [diff] [blame] | 156 | static int rxe_create_ah(struct ib_ah *ibah, |
| 157 | struct rdma_ah_init_attr *init_attr, |
| 158 | struct ib_udata *udata) |
Moni Shoua | 477864c | 2016-11-23 08:23:24 +0200 | [diff] [blame] | 159 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 160 | { |
| 161 | int err; |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 162 | struct rxe_dev *rxe = to_rdev(ibah->device); |
| 163 | struct rxe_ah *ah = to_rah(ibah); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 164 | |
Maor Gottlieb | fa5d010 | 2020-04-30 22:21:42 +0300 | [diff] [blame] | 165 | err = rxe_av_chk_attr(rxe, init_attr->ah_attr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 166 | if (err) |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 167 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 168 | |
Bob Pearson | 91a42c5 | 2020-12-16 17:15:48 -0600 | [diff] [blame] | 169 | err = rxe_add_to_pool(&rxe->ah_pool, ah); |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 170 | if (err) |
| 171 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 172 | |
Maor Gottlieb | fa5d010 | 2020-04-30 22:21:42 +0300 | [diff] [blame] | 173 | rxe_init_av(init_attr->ah_attr, &ah->av); |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 174 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 175 | } |
| 176 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 177 | static int rxe_modify_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 178 | { |
| 179 | int err; |
| 180 | struct rxe_dev *rxe = to_rdev(ibah->device); |
| 181 | struct rxe_ah *ah = to_rah(ibah); |
| 182 | |
| 183 | err = rxe_av_chk_attr(rxe, attr); |
| 184 | if (err) |
| 185 | return err; |
| 186 | |
Kamal Heib | fa40718 | 2019-01-29 12:08:49 +0200 | [diff] [blame] | 187 | rxe_init_av(attr, &ah->av); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 191 | static int rxe_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 192 | { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 193 | struct rxe_ah *ah = to_rah(ibah); |
| 194 | |
Dasaratharaman Chandramouli | eca7ddf | 2017-04-29 14:41:17 -0400 | [diff] [blame] | 195 | memset(attr, 0, sizeof(*attr)); |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 196 | attr->type = ibah->type; |
Zhu Yanjun | 9c96f3d | 2018-01-31 06:06:56 -0500 | [diff] [blame] | 197 | rxe_av_to_attr(&ah->av, attr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
Leon Romanovsky | 9a9ebf8 | 2020-09-07 15:09:14 +0300 | [diff] [blame] | 201 | static int rxe_destroy_ah(struct ib_ah *ibah, u32 flags) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 202 | { |
| 203 | struct rxe_ah *ah = to_rah(ibah); |
| 204 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 205 | rxe_drop_ref(ah); |
Leon Romanovsky | 9a9ebf8 | 2020-09-07 15:09:14 +0300 | [diff] [blame] | 206 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 207 | } |
| 208 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 209 | static int post_one_recv(struct rxe_rq *rq, const struct ib_recv_wr *ibwr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 210 | { |
| 211 | int err; |
| 212 | int i; |
| 213 | u32 length; |
| 214 | struct rxe_recv_wqe *recv_wqe; |
| 215 | int num_sge = ibwr->num_sge; |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 216 | int full; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 217 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 218 | full = queue_full(rq->queue, QUEUE_TYPE_TO_DRIVER); |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 219 | if (unlikely(full)) { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 220 | err = -ENOMEM; |
| 221 | goto err1; |
| 222 | } |
| 223 | |
| 224 | if (unlikely(num_sge > rq->max_sge)) { |
| 225 | err = -EINVAL; |
| 226 | goto err1; |
| 227 | } |
| 228 | |
| 229 | length = 0; |
| 230 | for (i = 0; i < num_sge; i++) |
| 231 | length += ibwr->sg_list[i].length; |
| 232 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 233 | recv_wqe = queue_producer_addr(rq->queue, QUEUE_TYPE_TO_DRIVER); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 234 | recv_wqe->wr_id = ibwr->wr_id; |
| 235 | recv_wqe->num_sge = num_sge; |
| 236 | |
| 237 | memcpy(recv_wqe->dma.sge, ibwr->sg_list, |
| 238 | num_sge * sizeof(struct ib_sge)); |
| 239 | |
| 240 | recv_wqe->dma.length = length; |
| 241 | recv_wqe->dma.resid = length; |
| 242 | recv_wqe->dma.num_sge = num_sge; |
| 243 | recv_wqe->dma.cur_sge = 0; |
| 244 | recv_wqe->dma.sge_offset = 0; |
| 245 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 246 | queue_advance_producer(rq->queue, QUEUE_TYPE_TO_DRIVER); |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 247 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 248 | return 0; |
| 249 | |
| 250 | err1: |
| 251 | return err; |
| 252 | } |
| 253 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 254 | static int rxe_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init, |
| 255 | struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 256 | { |
| 257 | int err; |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 258 | struct rxe_dev *rxe = to_rdev(ibsrq->device); |
| 259 | struct rxe_pd *pd = to_rpd(ibsrq->pd); |
| 260 | struct rxe_srq *srq = to_rsrq(ibsrq); |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 261 | struct rxe_create_srq_resp __user *uresp = NULL; |
| 262 | |
Jason Gunthorpe | 652caba | 2020-10-03 20:20:05 -0300 | [diff] [blame] | 263 | if (init->srq_type != IB_SRQT_BASIC) |
| 264 | return -EOPNOTSUPP; |
| 265 | |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 266 | if (udata) { |
| 267 | if (udata->outlen < sizeof(*uresp)) |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 268 | return -EINVAL; |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 269 | uresp = udata->outbuf; |
| 270 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 271 | |
| 272 | err = rxe_srq_chk_attr(rxe, NULL, &init->attr, IB_SRQ_INIT_MASK); |
| 273 | if (err) |
| 274 | goto err1; |
| 275 | |
Bob Pearson | 91a42c5 | 2020-12-16 17:15:48 -0600 | [diff] [blame] | 276 | err = rxe_add_to_pool(&rxe->srq_pool, srq); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 277 | if (err) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 278 | goto err1; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 279 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 280 | rxe_add_ref(pd); |
| 281 | srq->pd = pd; |
| 282 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 283 | err = rxe_srq_from_init(rxe, srq, init, udata, uresp); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 284 | if (err) |
| 285 | goto err2; |
| 286 | |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 287 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 288 | |
| 289 | err2: |
| 290 | rxe_drop_ref(pd); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 291 | rxe_drop_ref(srq); |
| 292 | err1: |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 293 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static int rxe_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, |
| 297 | enum ib_srq_attr_mask mask, |
| 298 | struct ib_udata *udata) |
| 299 | { |
| 300 | int err; |
| 301 | struct rxe_srq *srq = to_rsrq(ibsrq); |
| 302 | struct rxe_dev *rxe = to_rdev(ibsrq->device); |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 303 | struct rxe_modify_srq_cmd ucmd = {}; |
| 304 | |
| 305 | if (udata) { |
| 306 | if (udata->inlen < sizeof(ucmd)) |
| 307 | return -EINVAL; |
| 308 | |
| 309 | err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)); |
| 310 | if (err) |
| 311 | return err; |
| 312 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 313 | |
| 314 | err = rxe_srq_chk_attr(rxe, srq, attr, mask); |
| 315 | if (err) |
| 316 | goto err1; |
| 317 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 318 | err = rxe_srq_from_attr(rxe, srq, attr, mask, &ucmd, udata); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 319 | if (err) |
| 320 | goto err1; |
| 321 | |
| 322 | return 0; |
| 323 | |
| 324 | err1: |
| 325 | return err; |
| 326 | } |
| 327 | |
| 328 | static int rxe_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr) |
| 329 | { |
| 330 | struct rxe_srq *srq = to_rsrq(ibsrq); |
| 331 | |
| 332 | if (srq->error) |
| 333 | return -EINVAL; |
| 334 | |
| 335 | attr->max_wr = srq->rq.queue->buf->index_mask; |
| 336 | attr->max_sge = srq->rq.max_sge; |
| 337 | attr->srq_limit = srq->limit; |
| 338 | return 0; |
| 339 | } |
| 340 | |
Leon Romanovsky | 119181d | 2020-09-07 15:09:16 +0300 | [diff] [blame] | 341 | static int rxe_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 342 | { |
| 343 | struct rxe_srq *srq = to_rsrq(ibsrq); |
| 344 | |
| 345 | if (srq->rq.queue) |
| 346 | rxe_queue_cleanup(srq->rq.queue); |
| 347 | |
| 348 | rxe_drop_ref(srq->pd); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 349 | rxe_drop_ref(srq); |
Leon Romanovsky | 119181d | 2020-09-07 15:09:16 +0300 | [diff] [blame] | 350 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 351 | } |
| 352 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 353 | static int rxe_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr, |
| 354 | const struct ib_recv_wr **bad_wr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 355 | { |
| 356 | int err = 0; |
| 357 | unsigned long flags; |
| 358 | struct rxe_srq *srq = to_rsrq(ibsrq); |
| 359 | |
| 360 | spin_lock_irqsave(&srq->rq.producer_lock, flags); |
| 361 | |
| 362 | while (wr) { |
| 363 | err = post_one_recv(&srq->rq, wr); |
| 364 | if (unlikely(err)) |
| 365 | break; |
| 366 | wr = wr->next; |
| 367 | } |
| 368 | |
| 369 | spin_unlock_irqrestore(&srq->rq.producer_lock, flags); |
| 370 | |
| 371 | if (err) |
| 372 | *bad_wr = wr; |
| 373 | |
| 374 | return err; |
| 375 | } |
| 376 | |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 377 | static int rxe_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init, |
| 378 | struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 379 | { |
| 380 | int err; |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 381 | struct rxe_dev *rxe = to_rdev(ibqp->device); |
| 382 | struct rxe_pd *pd = to_rpd(ibqp->pd); |
| 383 | struct rxe_qp *qp = to_rqp(ibqp); |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 384 | struct rxe_create_qp_resp __user *uresp = NULL; |
| 385 | |
| 386 | if (udata) { |
| 387 | if (udata->outlen < sizeof(*uresp)) |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 388 | return -EINVAL; |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 389 | uresp = udata->outbuf; |
| 390 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 391 | |
Jason Gunthorpe | 1f11a76 | 2020-10-03 20:20:08 -0300 | [diff] [blame] | 392 | if (init->create_flags) |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 393 | return -EOPNOTSUPP; |
Jason Gunthorpe | 1f11a76 | 2020-10-03 20:20:08 -0300 | [diff] [blame] | 394 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 395 | err = rxe_qp_chk_init(rxe, init); |
| 396 | if (err) |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 397 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 398 | |
| 399 | if (udata) { |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 400 | if (udata->inlen) |
| 401 | return -EINVAL; |
| 402 | |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 403 | qp->is_user = true; |
| 404 | } else { |
| 405 | qp->is_user = false; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 406 | } |
| 407 | |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 408 | err = rxe_add_to_pool(&rxe->qp_pool, qp); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 409 | if (err) |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 410 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 411 | |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 412 | rxe_add_index(qp); |
| 413 | err = rxe_qp_from_init(rxe, qp, pd, init, uresp, ibqp->pd, udata); |
| 414 | if (err) |
| 415 | goto qp_init; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 416 | |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 417 | return 0; |
| 418 | |
| 419 | qp_init: |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 420 | rxe_drop_index(qp); |
| 421 | rxe_drop_ref(qp); |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 422 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 426 | int mask, struct ib_udata *udata) |
| 427 | { |
| 428 | int err; |
| 429 | struct rxe_dev *rxe = to_rdev(ibqp->device); |
| 430 | struct rxe_qp *qp = to_rqp(ibqp); |
| 431 | |
Jason Gunthorpe | 26e990b | 2020-10-03 20:20:06 -0300 | [diff] [blame] | 432 | if (mask & ~IB_QP_ATTR_STANDARD_BITS) |
| 433 | return -EOPNOTSUPP; |
| 434 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 435 | err = rxe_qp_chk_attr(rxe, qp, attr, mask); |
| 436 | if (err) |
| 437 | goto err1; |
| 438 | |
| 439 | err = rxe_qp_from_attr(qp, attr, mask, udata); |
| 440 | if (err) |
| 441 | goto err1; |
| 442 | |
| 443 | return 0; |
| 444 | |
| 445 | err1: |
| 446 | return err; |
| 447 | } |
| 448 | |
| 449 | static int rxe_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 450 | int mask, struct ib_qp_init_attr *init) |
| 451 | { |
| 452 | struct rxe_qp *qp = to_rqp(ibqp); |
| 453 | |
| 454 | rxe_qp_to_init(qp, init); |
| 455 | rxe_qp_to_attr(qp, attr, mask); |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 460 | static int rxe_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 461 | { |
| 462 | struct rxe_qp *qp = to_rqp(ibqp); |
| 463 | |
| 464 | rxe_qp_destroy(qp); |
| 465 | rxe_drop_index(qp); |
| 466 | rxe_drop_ref(qp); |
| 467 | return 0; |
| 468 | } |
| 469 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 470 | static int validate_send_wr(struct rxe_qp *qp, const struct ib_send_wr *ibwr, |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 471 | unsigned int mask, unsigned int length) |
| 472 | { |
| 473 | int num_sge = ibwr->num_sge; |
| 474 | struct rxe_sq *sq = &qp->sq; |
| 475 | |
| 476 | if (unlikely(num_sge > sq->max_sge)) |
| 477 | goto err1; |
| 478 | |
| 479 | if (unlikely(mask & WR_ATOMIC_MASK)) { |
| 480 | if (length < 8) |
| 481 | goto err1; |
| 482 | |
| 483 | if (atomic_wr(ibwr)->remote_addr & 0x7) |
| 484 | goto err1; |
| 485 | } |
| 486 | |
| 487 | if (unlikely((ibwr->send_flags & IB_SEND_INLINE) && |
| 488 | (length > sq->max_inline))) |
| 489 | goto err1; |
| 490 | |
| 491 | return 0; |
| 492 | |
| 493 | err1: |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
| 497 | static void init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 498 | const struct ib_send_wr *ibwr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 499 | { |
| 500 | wr->wr_id = ibwr->wr_id; |
| 501 | wr->num_sge = ibwr->num_sge; |
| 502 | wr->opcode = ibwr->opcode; |
| 503 | wr->send_flags = ibwr->send_flags; |
| 504 | |
| 505 | if (qp_type(qp) == IB_QPT_UD || |
| 506 | qp_type(qp) == IB_QPT_SMI || |
| 507 | qp_type(qp) == IB_QPT_GSI) { |
| 508 | wr->wr.ud.remote_qpn = ud_wr(ibwr)->remote_qpn; |
| 509 | wr->wr.ud.remote_qkey = ud_wr(ibwr)->remote_qkey; |
| 510 | if (qp_type(qp) == IB_QPT_GSI) |
| 511 | wr->wr.ud.pkey_index = ud_wr(ibwr)->pkey_index; |
| 512 | if (wr->opcode == IB_WR_SEND_WITH_IMM) |
| 513 | wr->ex.imm_data = ibwr->ex.imm_data; |
| 514 | } else { |
| 515 | switch (wr->opcode) { |
| 516 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 517 | wr->ex.imm_data = ibwr->ex.imm_data; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 518 | fallthrough; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 519 | case IB_WR_RDMA_READ: |
| 520 | case IB_WR_RDMA_WRITE: |
| 521 | wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr; |
| 522 | wr->wr.rdma.rkey = rdma_wr(ibwr)->rkey; |
| 523 | break; |
| 524 | case IB_WR_SEND_WITH_IMM: |
| 525 | wr->ex.imm_data = ibwr->ex.imm_data; |
| 526 | break; |
| 527 | case IB_WR_SEND_WITH_INV: |
| 528 | wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; |
| 529 | break; |
| 530 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 531 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
| 532 | wr->wr.atomic.remote_addr = |
| 533 | atomic_wr(ibwr)->remote_addr; |
| 534 | wr->wr.atomic.compare_add = |
| 535 | atomic_wr(ibwr)->compare_add; |
| 536 | wr->wr.atomic.swap = atomic_wr(ibwr)->swap; |
| 537 | wr->wr.atomic.rkey = atomic_wr(ibwr)->rkey; |
| 538 | break; |
| 539 | case IB_WR_LOCAL_INV: |
| 540 | wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey; |
| 541 | break; |
| 542 | case IB_WR_REG_MR: |
| 543 | wr->wr.reg.mr = reg_wr(ibwr)->mr; |
| 544 | wr->wr.reg.key = reg_wr(ibwr)->key; |
| 545 | wr->wr.reg.access = reg_wr(ibwr)->access; |
| 546 | break; |
| 547 | default: |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
Bob Pearson | 086f580 | 2021-02-05 18:24:37 -0600 | [diff] [blame] | 553 | static void copy_inline_data_to_wqe(struct rxe_send_wqe *wqe, |
| 554 | const struct ib_send_wr *ibwr) |
| 555 | { |
| 556 | struct ib_sge *sge = ibwr->sg_list; |
| 557 | u8 *p = wqe->dma.inline_data; |
| 558 | int i; |
| 559 | |
| 560 | for (i = 0; i < ibwr->num_sge; i++, sge++) { |
| 561 | memcpy(p, (void *)(uintptr_t)sge->addr, sge->length); |
| 562 | p += sge->length; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | static void init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 567 | unsigned int mask, unsigned int length, |
| 568 | struct rxe_send_wqe *wqe) |
| 569 | { |
| 570 | int num_sge = ibwr->num_sge; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 571 | |
| 572 | init_send_wr(qp, &wqe->wr, ibwr); |
| 573 | |
Bob Pearson | dc78074 | 2021-02-05 17:05:26 -0600 | [diff] [blame] | 574 | /* local operation */ |
Bob Pearson | 886441f | 2021-06-07 23:25:48 -0500 | [diff] [blame] | 575 | if (unlikely(mask & WR_LOCAL_OP_MASK)) { |
Bob Pearson | dc78074 | 2021-02-05 17:05:26 -0600 | [diff] [blame] | 576 | wqe->mask = mask; |
| 577 | wqe->state = wqe_state_posted; |
Bob Pearson | 086f580 | 2021-02-05 18:24:37 -0600 | [diff] [blame] | 578 | return; |
Bob Pearson | dc78074 | 2021-02-05 17:05:26 -0600 | [diff] [blame] | 579 | } |
| 580 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 581 | if (qp_type(qp) == IB_QPT_UD || |
| 582 | qp_type(qp) == IB_QPT_SMI || |
| 583 | qp_type(qp) == IB_QPT_GSI) |
Bob Pearson | cfc0312 | 2021-10-07 15:40:47 -0500 | [diff] [blame^] | 584 | memcpy(&wqe->wr.wr.ud.av, &to_rah(ud_wr(ibwr)->ah)->av, |
| 585 | sizeof(struct rxe_av)); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 586 | |
Bob Pearson | 086f580 | 2021-02-05 18:24:37 -0600 | [diff] [blame] | 587 | if (unlikely(ibwr->send_flags & IB_SEND_INLINE)) |
| 588 | copy_inline_data_to_wqe(wqe, ibwr); |
| 589 | else |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 590 | memcpy(wqe->dma.sge, ibwr->sg_list, |
| 591 | num_sge * sizeof(struct ib_sge)); |
| 592 | |
Bart Van Assche | a6544a6 | 2018-03-01 14:00:29 -0800 | [diff] [blame] | 593 | wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr : |
| 594 | mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 595 | wqe->mask = mask; |
| 596 | wqe->dma.length = length; |
| 597 | wqe->dma.resid = length; |
| 598 | wqe->dma.num_sge = num_sge; |
| 599 | wqe->dma.cur_sge = 0; |
| 600 | wqe->dma.sge_offset = 0; |
| 601 | wqe->state = wqe_state_posted; |
| 602 | wqe->ssn = atomic_add_return(1, &qp->ssn); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 603 | } |
| 604 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 605 | static int post_one_send(struct rxe_qp *qp, const struct ib_send_wr *ibwr, |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 606 | unsigned int mask, u32 length) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 607 | { |
| 608 | int err; |
| 609 | struct rxe_sq *sq = &qp->sq; |
| 610 | struct rxe_send_wqe *send_wqe; |
| 611 | unsigned long flags; |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 612 | int full; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 613 | |
| 614 | err = validate_send_wr(qp, ibwr, mask, length); |
| 615 | if (err) |
| 616 | return err; |
| 617 | |
| 618 | spin_lock_irqsave(&qp->sq.sq_lock, flags); |
| 619 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 620 | full = queue_full(sq->queue, QUEUE_TYPE_TO_DRIVER); |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 621 | |
| 622 | if (unlikely(full)) { |
| 623 | spin_unlock_irqrestore(&qp->sq.sq_lock, flags); |
| 624 | return -ENOMEM; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 625 | } |
| 626 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 627 | send_wqe = queue_producer_addr(sq->queue, QUEUE_TYPE_TO_DRIVER); |
Bob Pearson | 086f580 | 2021-02-05 18:24:37 -0600 | [diff] [blame] | 628 | init_send_wqe(qp, ibwr, mask, length, send_wqe); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 629 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 630 | queue_advance_producer(sq->queue, QUEUE_TYPE_TO_DRIVER); |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 631 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 632 | spin_unlock_irqrestore(&qp->sq.sq_lock, flags); |
| 633 | |
| 634 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 635 | } |
| 636 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 637 | static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr, |
| 638 | const struct ib_send_wr **bad_wr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 639 | { |
| 640 | int err = 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 641 | unsigned int mask; |
| 642 | unsigned int length = 0; |
| 643 | int i; |
Mikhail Malygin | 5f0b2a6 | 2020-07-16 22:03:41 +0300 | [diff] [blame] | 644 | struct ib_send_wr *next; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 645 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 646 | while (wr) { |
| 647 | mask = wr_opcode_mask(wr->opcode, qp); |
| 648 | if (unlikely(!mask)) { |
| 649 | err = -EINVAL; |
| 650 | *bad_wr = wr; |
| 651 | break; |
| 652 | } |
| 653 | |
| 654 | if (unlikely((wr->send_flags & IB_SEND_INLINE) && |
| 655 | !(mask & WR_INLINE_MASK))) { |
| 656 | err = -EINVAL; |
| 657 | *bad_wr = wr; |
| 658 | break; |
| 659 | } |
| 660 | |
Mikhail Malygin | 5f0b2a6 | 2020-07-16 22:03:41 +0300 | [diff] [blame] | 661 | next = wr->next; |
| 662 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 663 | length = 0; |
| 664 | for (i = 0; i < wr->num_sge; i++) |
| 665 | length += wr->sg_list[i].length; |
| 666 | |
| 667 | err = post_one_send(qp, wr, mask, length); |
| 668 | |
| 669 | if (err) { |
| 670 | *bad_wr = wr; |
| 671 | break; |
| 672 | } |
Mikhail Malygin | 5f0b2a6 | 2020-07-16 22:03:41 +0300 | [diff] [blame] | 673 | wr = next; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 674 | } |
| 675 | |
Alexandru Moise | 1661d3b0 | 2018-05-08 11:02:02 +0200 | [diff] [blame] | 676 | rxe_run_task(&qp->req.task, 1); |
Bart Van Assche | 6f301e0 | 2018-01-09 11:23:40 -0800 | [diff] [blame] | 677 | if (unlikely(qp->req.state == QP_STATE_ERROR)) |
| 678 | rxe_run_task(&qp->comp.task, 1); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 679 | |
| 680 | return err; |
| 681 | } |
| 682 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 683 | static int rxe_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 684 | const struct ib_send_wr **bad_wr) |
Parav Pandit | 063af59 | 2016-09-28 20:24:12 +0000 | [diff] [blame] | 685 | { |
| 686 | struct rxe_qp *qp = to_rqp(ibqp); |
| 687 | |
| 688 | if (unlikely(!qp->valid)) { |
| 689 | *bad_wr = wr; |
| 690 | return -EINVAL; |
| 691 | } |
| 692 | |
| 693 | if (unlikely(qp->req.state < QP_STATE_READY)) { |
| 694 | *bad_wr = wr; |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
| 698 | if (qp->is_user) { |
| 699 | /* Utilize process context to do protocol processing */ |
| 700 | rxe_run_task(&qp->req.task, 0); |
| 701 | return 0; |
| 702 | } else |
| 703 | return rxe_post_send_kernel(qp, wr, bad_wr); |
| 704 | } |
| 705 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 706 | static int rxe_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 707 | const struct ib_recv_wr **bad_wr) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 708 | { |
| 709 | int err = 0; |
| 710 | struct rxe_qp *qp = to_rqp(ibqp); |
| 711 | struct rxe_rq *rq = &qp->rq; |
| 712 | unsigned long flags; |
| 713 | |
| 714 | if (unlikely((qp_state(qp) < IB_QPS_INIT) || !qp->valid)) { |
| 715 | *bad_wr = wr; |
| 716 | err = -EINVAL; |
| 717 | goto err1; |
| 718 | } |
| 719 | |
| 720 | if (unlikely(qp->srq)) { |
| 721 | *bad_wr = wr; |
| 722 | err = -EINVAL; |
| 723 | goto err1; |
| 724 | } |
| 725 | |
| 726 | spin_lock_irqsave(&rq->producer_lock, flags); |
| 727 | |
| 728 | while (wr) { |
| 729 | err = post_one_recv(rq, wr); |
| 730 | if (unlikely(err)) { |
| 731 | *bad_wr = wr; |
| 732 | break; |
| 733 | } |
| 734 | wr = wr->next; |
| 735 | } |
| 736 | |
| 737 | spin_unlock_irqrestore(&rq->producer_lock, flags); |
| 738 | |
Vijay Immanuel | 1217197 | 2017-06-27 12:19:38 +0300 | [diff] [blame] | 739 | if (qp->resp.state == QP_STATE_ERROR) |
| 740 | rxe_run_task(&qp->resp.task, 1); |
| 741 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 742 | err1: |
| 743 | return err; |
| 744 | } |
| 745 | |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 746 | static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, |
| 747 | struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 748 | { |
| 749 | int err; |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 750 | struct ib_device *dev = ibcq->device; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 751 | struct rxe_dev *rxe = to_rdev(dev); |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 752 | struct rxe_cq *cq = to_rcq(ibcq); |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 753 | struct rxe_create_cq_resp __user *uresp = NULL; |
| 754 | |
| 755 | if (udata) { |
| 756 | if (udata->outlen < sizeof(*uresp)) |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 757 | return -EINVAL; |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 758 | uresp = udata->outbuf; |
| 759 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 760 | |
| 761 | if (attr->flags) |
Jason Gunthorpe | 1c407cb | 2020-10-03 20:20:07 -0300 | [diff] [blame] | 762 | return -EOPNOTSUPP; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 763 | |
Jason Gunthorpe | b92ec0f | 2018-03-13 16:33:17 -0600 | [diff] [blame] | 764 | err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 765 | if (err) |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 766 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 767 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 768 | err = rxe_cq_from_init(rxe, cq, attr->cqe, attr->comp_vector, udata, |
| 769 | uresp); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 770 | if (err) |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 771 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 772 | |
Bob Pearson | 91a42c5 | 2020-12-16 17:15:48 -0600 | [diff] [blame] | 773 | return rxe_add_to_pool(&rxe->cq_pool, cq); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 774 | } |
| 775 | |
Leon Romanovsky | 43d781b | 2020-09-07 15:09:18 +0300 | [diff] [blame] | 776 | static int rxe_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 777 | { |
| 778 | struct rxe_cq *cq = to_rcq(ibcq); |
| 779 | |
Andrew Boyer | bfc3ae0 | 2017-08-28 16:11:50 -0400 | [diff] [blame] | 780 | rxe_cq_disable(cq); |
| 781 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 782 | rxe_drop_ref(cq); |
Leon Romanovsky | 43d781b | 2020-09-07 15:09:18 +0300 | [diff] [blame] | 783 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | static int rxe_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) |
| 787 | { |
| 788 | int err; |
| 789 | struct rxe_cq *cq = to_rcq(ibcq); |
| 790 | struct rxe_dev *rxe = to_rdev(ibcq->device); |
Jason Gunthorpe | 0c43ab3 | 2018-03-13 16:33:18 -0600 | [diff] [blame] | 791 | struct rxe_resize_cq_resp __user *uresp = NULL; |
| 792 | |
| 793 | if (udata) { |
| 794 | if (udata->outlen < sizeof(*uresp)) |
| 795 | return -EINVAL; |
| 796 | uresp = udata->outbuf; |
| 797 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 798 | |
Jason Gunthorpe | b92ec0f | 2018-03-13 16:33:17 -0600 | [diff] [blame] | 799 | err = rxe_cq_chk_attr(rxe, cq, cqe, 0); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 800 | if (err) |
| 801 | goto err1; |
| 802 | |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 803 | err = rxe_cq_resize_queue(cq, cqe, uresp, udata); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 804 | if (err) |
| 805 | goto err1; |
| 806 | |
| 807 | return 0; |
| 808 | |
| 809 | err1: |
| 810 | return err; |
| 811 | } |
| 812 | |
| 813 | static int rxe_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc) |
| 814 | { |
| 815 | int i; |
| 816 | struct rxe_cq *cq = to_rcq(ibcq); |
| 817 | struct rxe_cqe *cqe; |
| 818 | unsigned long flags; |
| 819 | |
| 820 | spin_lock_irqsave(&cq->cq_lock, flags); |
| 821 | for (i = 0; i < num_entries; i++) { |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 822 | cqe = queue_head(cq->queue, QUEUE_TYPE_FROM_DRIVER); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 823 | if (!cqe) |
| 824 | break; |
| 825 | |
| 826 | memcpy(wc++, &cqe->ibwc, sizeof(*wc)); |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 827 | queue_advance_consumer(cq->queue, QUEUE_TYPE_FROM_DRIVER); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 828 | } |
| 829 | spin_unlock_irqrestore(&cq->cq_lock, flags); |
| 830 | |
| 831 | return i; |
| 832 | } |
| 833 | |
| 834 | static int rxe_peek_cq(struct ib_cq *ibcq, int wc_cnt) |
| 835 | { |
| 836 | struct rxe_cq *cq = to_rcq(ibcq); |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 837 | int count; |
| 838 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 839 | count = queue_count(cq->queue, QUEUE_TYPE_FROM_DRIVER); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 840 | |
| 841 | return (count > wc_cnt) ? wc_cnt : count; |
| 842 | } |
| 843 | |
| 844 | static int rxe_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) |
| 845 | { |
| 846 | struct rxe_cq *cq = to_rcq(ibcq); |
Andrew Boyer | accacb8 | 2016-11-23 12:39:22 -0500 | [diff] [blame] | 847 | unsigned long irq_flags; |
| 848 | int ret = 0; |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 849 | int empty; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 850 | |
Andrew Boyer | accacb8 | 2016-11-23 12:39:22 -0500 | [diff] [blame] | 851 | spin_lock_irqsave(&cq->cq_lock, irq_flags); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 852 | if (cq->notify != IB_CQ_NEXT_COMP) |
| 853 | cq->notify = flags & IB_CQ_SOLICITED_MASK; |
| 854 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 855 | empty = queue_empty(cq->queue, QUEUE_TYPE_FROM_DRIVER); |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 856 | |
| 857 | if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !empty) |
Andrew Boyer | accacb8 | 2016-11-23 12:39:22 -0500 | [diff] [blame] | 858 | ret = 1; |
| 859 | |
| 860 | spin_unlock_irqrestore(&cq->cq_lock, irq_flags); |
| 861 | |
| 862 | return ret; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access) |
| 866 | { |
| 867 | struct rxe_dev *rxe = to_rdev(ibpd->device); |
| 868 | struct rxe_pd *pd = to_rpd(ibpd); |
Bob Pearson | 364e282 | 2021-03-25 16:24:26 -0500 | [diff] [blame] | 869 | struct rxe_mr *mr; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 870 | |
| 871 | mr = rxe_alloc(&rxe->mr_pool); |
Kamal Heib | 293d844 | 2020-07-05 13:43:12 +0300 | [diff] [blame] | 872 | if (!mr) |
| 873 | return ERR_PTR(-ENOMEM); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 874 | |
| 875 | rxe_add_index(mr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 876 | rxe_add_ref(pd); |
Bob Pearson | 364e282 | 2021-03-25 16:24:26 -0500 | [diff] [blame] | 877 | rxe_mr_init_dma(pd, access, mr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 878 | |
| 879 | return &mr->ibmr; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, |
| 883 | u64 start, |
| 884 | u64 length, |
| 885 | u64 iova, |
| 886 | int access, struct ib_udata *udata) |
| 887 | { |
| 888 | int err; |
| 889 | struct rxe_dev *rxe = to_rdev(ibpd->device); |
| 890 | struct rxe_pd *pd = to_rpd(ibpd); |
Bob Pearson | 364e282 | 2021-03-25 16:24:26 -0500 | [diff] [blame] | 891 | struct rxe_mr *mr; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 892 | |
| 893 | mr = rxe_alloc(&rxe->mr_pool); |
| 894 | if (!mr) { |
| 895 | err = -ENOMEM; |
| 896 | goto err2; |
| 897 | } |
| 898 | |
| 899 | rxe_add_index(mr); |
| 900 | |
| 901 | rxe_add_ref(pd); |
| 902 | |
Lang Cheng | cd5b010 | 2021-05-12 16:12:22 +0800 | [diff] [blame] | 903 | err = rxe_mr_init_user(pd, start, length, iova, access, mr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 904 | if (err) |
| 905 | goto err3; |
| 906 | |
| 907 | return &mr->ibmr; |
| 908 | |
| 909 | err3: |
| 910 | rxe_drop_ref(pd); |
| 911 | rxe_drop_index(mr); |
| 912 | rxe_drop_ref(mr); |
| 913 | err2: |
| 914 | return ERR_PTR(err); |
| 915 | } |
| 916 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 917 | static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, |
Gal Pressman | 42a3b15 | 2020-07-06 15:03:43 +0300 | [diff] [blame] | 918 | u32 max_num_sg) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 919 | { |
| 920 | struct rxe_dev *rxe = to_rdev(ibpd->device); |
| 921 | struct rxe_pd *pd = to_rpd(ibpd); |
Bob Pearson | 364e282 | 2021-03-25 16:24:26 -0500 | [diff] [blame] | 922 | struct rxe_mr *mr; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 923 | int err; |
| 924 | |
| 925 | if (mr_type != IB_MR_TYPE_MEM_REG) |
| 926 | return ERR_PTR(-EINVAL); |
| 927 | |
| 928 | mr = rxe_alloc(&rxe->mr_pool); |
| 929 | if (!mr) { |
| 930 | err = -ENOMEM; |
| 931 | goto err1; |
| 932 | } |
| 933 | |
| 934 | rxe_add_index(mr); |
| 935 | |
| 936 | rxe_add_ref(pd); |
| 937 | |
Bob Pearson | 364e282 | 2021-03-25 16:24:26 -0500 | [diff] [blame] | 938 | err = rxe_mr_init_fast(pd, max_num_sg, mr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 939 | if (err) |
| 940 | goto err2; |
| 941 | |
| 942 | return &mr->ibmr; |
| 943 | |
| 944 | err2: |
| 945 | rxe_drop_ref(pd); |
| 946 | rxe_drop_index(mr); |
| 947 | rxe_drop_ref(mr); |
| 948 | err1: |
| 949 | return ERR_PTR(err); |
| 950 | } |
| 951 | |
Bob Pearson | 647bf13 | 2021-09-14 11:42:06 -0500 | [diff] [blame] | 952 | /* build next_map_set from scatterlist |
| 953 | * The IB_WR_REG_MR WR will swap map_sets |
| 954 | */ |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 955 | static int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, |
| 956 | int sg_nents, unsigned int *sg_offset) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 957 | { |
Bob Pearson | 364e282 | 2021-03-25 16:24:26 -0500 | [diff] [blame] | 958 | struct rxe_mr *mr = to_rmr(ibmr); |
Bob Pearson | 647bf13 | 2021-09-14 11:42:06 -0500 | [diff] [blame] | 959 | struct rxe_map_set *set = mr->next_map_set; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 960 | int n; |
| 961 | |
Bob Pearson | 647bf13 | 2021-09-14 11:42:06 -0500 | [diff] [blame] | 962 | set->nbuf = 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 963 | |
Bob Pearson | 647bf13 | 2021-09-14 11:42:06 -0500 | [diff] [blame] | 964 | n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_mr_set_page); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 965 | |
Bob Pearson | 647bf13 | 2021-09-14 11:42:06 -0500 | [diff] [blame] | 966 | set->va = ibmr->iova; |
| 967 | set->iova = ibmr->iova; |
| 968 | set->length = ibmr->length; |
| 969 | set->page_shift = ilog2(ibmr->page_size); |
| 970 | set->page_mask = ibmr->page_size - 1; |
| 971 | set->offset = set->iova & set->page_mask; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 972 | |
| 973 | return n; |
| 974 | } |
| 975 | |
| 976 | static int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) |
| 977 | { |
| 978 | int err; |
| 979 | struct rxe_dev *rxe = to_rdev(ibqp->device); |
| 980 | struct rxe_qp *qp = to_rqp(ibqp); |
| 981 | struct rxe_mc_grp *grp; |
| 982 | |
| 983 | /* takes a ref on grp if successful */ |
| 984 | err = rxe_mcast_get_grp(rxe, mgid, &grp); |
| 985 | if (err) |
| 986 | return err; |
| 987 | |
| 988 | err = rxe_mcast_add_grp_elem(rxe, qp, grp); |
| 989 | |
| 990 | rxe_drop_ref(grp); |
| 991 | return err; |
| 992 | } |
| 993 | |
| 994 | static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) |
| 995 | { |
| 996 | struct rxe_dev *rxe = to_rdev(ibqp->device); |
| 997 | struct rxe_qp *qp = to_rqp(ibqp); |
| 998 | |
| 999 | return rxe_mcast_drop_grp_elem(rxe, qp, mgid); |
| 1000 | } |
| 1001 | |
Kamal Heib | c05d266 | 2017-06-15 11:29:05 +0300 | [diff] [blame] | 1002 | static ssize_t parent_show(struct device *device, |
| 1003 | struct device_attribute *attr, char *buf) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1004 | { |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 1005 | struct rxe_dev *rxe = |
| 1006 | rdma_device_to_drv_device(device, struct rxe_dev, ib_dev); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1007 | |
Joe Perches | 1c7fd72 | 2020-10-07 19:36:24 -0700 | [diff] [blame] | 1008 | return sysfs_emit(buf, "%s\n", rxe_parent_name(rxe, 1)); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1009 | } |
| 1010 | |
Kamal Heib | c05d266 | 2017-06-15 11:29:05 +0300 | [diff] [blame] | 1011 | static DEVICE_ATTR_RO(parent); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1012 | |
Parav Pandit | 508a523 | 2018-10-11 22:31:54 +0300 | [diff] [blame] | 1013 | static struct attribute *rxe_dev_attributes[] = { |
| 1014 | &dev_attr_parent.attr, |
| 1015 | NULL |
| 1016 | }; |
| 1017 | |
| 1018 | static const struct attribute_group rxe_attr_group = { |
| 1019 | .attrs = rxe_dev_attributes, |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1020 | }; |
| 1021 | |
Jason Gunthorpe | ca22354 | 2019-02-12 21:12:56 -0700 | [diff] [blame] | 1022 | static int rxe_enable_driver(struct ib_device *ib_dev) |
| 1023 | { |
| 1024 | struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev); |
| 1025 | |
| 1026 | rxe_set_port_state(rxe); |
| 1027 | dev_info(&rxe->ib_dev.dev, "added %s\n", netdev_name(rxe->ndev)); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1031 | static const struct ib_device_ops rxe_dev_ops = { |
Jason Gunthorpe | 7a15414 | 2019-06-05 14:39:26 -0300 | [diff] [blame] | 1032 | .owner = THIS_MODULE, |
Jason Gunthorpe | b9560a4 | 2019-06-05 14:39:24 -0300 | [diff] [blame] | 1033 | .driver_id = RDMA_DRIVER_RXE, |
Jason Gunthorpe | 72c6ec1 | 2019-06-05 14:39:25 -0300 | [diff] [blame] | 1034 | .uverbs_abi_ver = RXE_UVERBS_ABI_VERSION, |
Jason Gunthorpe | b9560a4 | 2019-06-05 14:39:24 -0300 | [diff] [blame] | 1035 | |
Jason Gunthorpe | 4b5f4d3 | 2021-06-11 19:00:20 +0300 | [diff] [blame] | 1036 | .alloc_hw_port_stats = rxe_ib_alloc_hw_port_stats, |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1037 | .alloc_mr = rxe_alloc_mr, |
Bob Pearson | beec023 | 2021-06-07 23:25:47 -0500 | [diff] [blame] | 1038 | .alloc_mw = rxe_alloc_mw, |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1039 | .alloc_pd = rxe_alloc_pd, |
| 1040 | .alloc_ucontext = rxe_alloc_ucontext, |
| 1041 | .attach_mcast = rxe_attach_mcast, |
| 1042 | .create_ah = rxe_create_ah, |
| 1043 | .create_cq = rxe_create_cq, |
| 1044 | .create_qp = rxe_create_qp, |
| 1045 | .create_srq = rxe_create_srq, |
Jason Gunthorpe | 676a80a | 2020-10-03 20:20:11 -0300 | [diff] [blame] | 1046 | .create_user_ah = rxe_create_ah, |
Jason Gunthorpe | c367074 | 2019-01-22 16:27:24 -0700 | [diff] [blame] | 1047 | .dealloc_driver = rxe_dealloc, |
Bob Pearson | beec023 | 2021-06-07 23:25:47 -0500 | [diff] [blame] | 1048 | .dealloc_mw = rxe_dealloc_mw, |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1049 | .dealloc_pd = rxe_dealloc_pd, |
| 1050 | .dealloc_ucontext = rxe_dealloc_ucontext, |
| 1051 | .dereg_mr = rxe_dereg_mr, |
| 1052 | .destroy_ah = rxe_destroy_ah, |
| 1053 | .destroy_cq = rxe_destroy_cq, |
| 1054 | .destroy_qp = rxe_destroy_qp, |
| 1055 | .destroy_srq = rxe_destroy_srq, |
| 1056 | .detach_mcast = rxe_detach_mcast, |
Jason Gunthorpe | 915e4af | 2021-06-11 19:00:34 +0300 | [diff] [blame] | 1057 | .device_group = &rxe_attr_group, |
Jason Gunthorpe | ca22354 | 2019-02-12 21:12:56 -0700 | [diff] [blame] | 1058 | .enable_driver = rxe_enable_driver, |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1059 | .get_dma_mr = rxe_get_dma_mr, |
| 1060 | .get_hw_stats = rxe_ib_get_hw_stats, |
| 1061 | .get_link_layer = rxe_get_link_layer, |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1062 | .get_port_immutable = rxe_port_immutable, |
| 1063 | .map_mr_sg = rxe_map_mr_sg, |
| 1064 | .mmap = rxe_mmap, |
| 1065 | .modify_ah = rxe_modify_ah, |
| 1066 | .modify_device = rxe_modify_device, |
| 1067 | .modify_port = rxe_modify_port, |
| 1068 | .modify_qp = rxe_modify_qp, |
| 1069 | .modify_srq = rxe_modify_srq, |
| 1070 | .peek_cq = rxe_peek_cq, |
| 1071 | .poll_cq = rxe_poll_cq, |
| 1072 | .post_recv = rxe_post_recv, |
| 1073 | .post_send = rxe_post_send, |
| 1074 | .post_srq_recv = rxe_post_srq_recv, |
| 1075 | .query_ah = rxe_query_ah, |
| 1076 | .query_device = rxe_query_device, |
| 1077 | .query_pkey = rxe_query_pkey, |
| 1078 | .query_port = rxe_query_port, |
| 1079 | .query_qp = rxe_query_qp, |
| 1080 | .query_srq = rxe_query_srq, |
| 1081 | .reg_user_mr = rxe_reg_user_mr, |
| 1082 | .req_notify_cq = rxe_req_notify_cq, |
| 1083 | .resize_cq = rxe_resize_cq, |
Leon Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 1084 | |
| 1085 | INIT_RDMA_OBJ_SIZE(ib_ah, rxe_ah, ibah), |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 1086 | INIT_RDMA_OBJ_SIZE(ib_cq, rxe_cq, ibcq), |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 1087 | INIT_RDMA_OBJ_SIZE(ib_pd, rxe_pd, ibpd), |
Leon Romanovsky | 514aee6 | 2021-07-23 14:39:50 +0300 | [diff] [blame] | 1088 | INIT_RDMA_OBJ_SIZE(ib_qp, rxe_qp, ibqp), |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 1089 | INIT_RDMA_OBJ_SIZE(ib_srq, rxe_srq, ibsrq), |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 1090 | INIT_RDMA_OBJ_SIZE(ib_ucontext, rxe_ucontext, ibuc), |
Bob Pearson | 364e282 | 2021-03-25 16:24:26 -0500 | [diff] [blame] | 1091 | INIT_RDMA_OBJ_SIZE(ib_mw, rxe_mw, ibmw), |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1092 | }; |
| 1093 | |
Steve Wise | 66920e1 | 2019-02-15 11:03:57 -0800 | [diff] [blame] | 1094 | int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1095 | { |
| 1096 | int err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1097 | struct ib_device *dev = &rxe->ib_dev; |
| 1098 | |
Bob Pearson | dc78074 | 2021-02-05 17:05:26 -0600 | [diff] [blame] | 1099 | strscpy(dev->node_desc, "rxe", sizeof(dev->node_desc)); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1100 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1101 | dev->node_type = RDMA_NODE_IB_CA; |
| 1102 | dev->phys_port_cnt = 1; |
Sagi Grimberg | 67cf362 | 2017-05-04 16:23:07 +0300 | [diff] [blame] | 1103 | dev->num_comp_vectors = num_possible_cpus(); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1104 | dev->local_dma_lkey = 0; |
Yuval Shaia | 4d6f285 | 2017-03-14 16:01:57 +0200 | [diff] [blame] | 1105 | addrconf_addr_eui48((unsigned char *)&dev->node_guid, |
| 1106 | rxe->ndev->dev_addr); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1107 | |
Jason Gunthorpe | 5c41936 | 2020-10-30 11:03:05 -0300 | [diff] [blame] | 1108 | dev->uverbs_cmd_mask |= BIT_ULL(IB_USER_VERBS_CMD_POST_SEND) | |
| 1109 | BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1110 | |
Kamal Heib | 573efc4 | 2018-12-10 21:09:46 +0200 | [diff] [blame] | 1111 | ib_set_device_ops(dev, &rxe_dev_ops); |
Jason Gunthorpe | 4c173f5 | 2019-02-12 21:12:52 -0700 | [diff] [blame] | 1112 | err = ib_device_set_netdev(&rxe->ib_dev, rxe->ndev, 1); |
| 1113 | if (err) |
| 1114 | return err; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1115 | |
Bob Pearson | add2b3b | 2021-07-06 23:00:39 -0500 | [diff] [blame] | 1116 | err = rxe_icrc_init(rxe); |
| 1117 | if (err) |
| 1118 | return err; |
yonatanc | cee2688 | 2017-04-20 20:55:55 +0300 | [diff] [blame] | 1119 | |
Jason Gunthorpe | e0477b3 | 2020-10-08 11:27:52 +0300 | [diff] [blame] | 1120 | err = ib_register_device(dev, ibdev_name, NULL); |
Jason Gunthorpe | c367074 | 2019-01-22 16:27:24 -0700 | [diff] [blame] | 1121 | if (err) |
Kamal Heib | 6101382 | 2017-06-15 11:29:06 +0300 | [diff] [blame] | 1122 | pr_warn("%s failed with error %d\n", __func__, err); |
yonatanc | cee2688 | 2017-04-20 20:55:55 +0300 | [diff] [blame] | 1123 | |
Jason Gunthorpe | ca22354 | 2019-02-12 21:12:56 -0700 | [diff] [blame] | 1124 | /* |
| 1125 | * Note that rxe may be invalid at this point if another thread |
| 1126 | * unregistered it. |
| 1127 | */ |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 1128 | return err; |
| 1129 | } |