| .. | .. |
|---|
| 37 | 37 | |
|---|
| 38 | 38 | #include "mlx4_ib.h" |
|---|
| 39 | 39 | #include <rdma/mlx4-abi.h> |
|---|
| 40 | +#include <rdma/uverbs_ioctl.h> |
|---|
| 40 | 41 | |
|---|
| 41 | 42 | static void *get_wqe(struct mlx4_ib_srq *srq, int n) |
|---|
| 42 | 43 | { |
|---|
| .. | .. |
|---|
| 68 | 69 | } |
|---|
| 69 | 70 | } |
|---|
| 70 | 71 | |
|---|
| 71 | | -struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd, |
|---|
| 72 | | - struct ib_srq_init_attr *init_attr, |
|---|
| 73 | | - struct ib_udata *udata) |
|---|
| 72 | +int mlx4_ib_create_srq(struct ib_srq *ib_srq, |
|---|
| 73 | + struct ib_srq_init_attr *init_attr, |
|---|
| 74 | + struct ib_udata *udata) |
|---|
| 74 | 75 | { |
|---|
| 75 | | - struct mlx4_ib_dev *dev = to_mdev(pd->device); |
|---|
| 76 | | - struct mlx4_ib_srq *srq; |
|---|
| 76 | + struct mlx4_ib_dev *dev = to_mdev(ib_srq->device); |
|---|
| 77 | + struct mlx4_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
|---|
| 78 | + udata, struct mlx4_ib_ucontext, ibucontext); |
|---|
| 79 | + struct mlx4_ib_srq *srq = to_msrq(ib_srq); |
|---|
| 77 | 80 | struct mlx4_wqe_srq_next_seg *next; |
|---|
| 78 | 81 | struct mlx4_wqe_data_seg *scatter; |
|---|
| 79 | 82 | u32 cqn; |
|---|
| .. | .. |
|---|
| 86 | 89 | /* Sanity check SRQ size before proceeding */ |
|---|
| 87 | 90 | if (init_attr->attr.max_wr >= dev->dev->caps.max_srq_wqes || |
|---|
| 88 | 91 | init_attr->attr.max_sge > dev->dev->caps.max_srq_sge) |
|---|
| 89 | | - return ERR_PTR(-EINVAL); |
|---|
| 90 | | - |
|---|
| 91 | | - srq = kmalloc(sizeof *srq, GFP_KERNEL); |
|---|
| 92 | | - if (!srq) |
|---|
| 93 | | - return ERR_PTR(-ENOMEM); |
|---|
| 92 | + return -EINVAL; |
|---|
| 94 | 93 | |
|---|
| 95 | 94 | mutex_init(&srq->mutex); |
|---|
| 96 | 95 | spin_lock_init(&srq->lock); |
|---|
| .. | .. |
|---|
| 105 | 104 | |
|---|
| 106 | 105 | buf_size = srq->msrq.max * desc_size; |
|---|
| 107 | 106 | |
|---|
| 108 | | - if (pd->uobject) { |
|---|
| 107 | + if (udata) { |
|---|
| 109 | 108 | struct mlx4_ib_create_srq ucmd; |
|---|
| 110 | 109 | |
|---|
| 111 | | - if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) { |
|---|
| 112 | | - err = -EFAULT; |
|---|
| 113 | | - goto err_srq; |
|---|
| 114 | | - } |
|---|
| 110 | + if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd))) |
|---|
| 111 | + return -EFAULT; |
|---|
| 115 | 112 | |
|---|
| 116 | | - srq->umem = ib_umem_get(pd->uobject->context, ucmd.buf_addr, |
|---|
| 117 | | - buf_size, 0, 0); |
|---|
| 118 | | - if (IS_ERR(srq->umem)) { |
|---|
| 119 | | - err = PTR_ERR(srq->umem); |
|---|
| 120 | | - goto err_srq; |
|---|
| 121 | | - } |
|---|
| 113 | + srq->umem = |
|---|
| 114 | + ib_umem_get(ib_srq->device, ucmd.buf_addr, buf_size, 0); |
|---|
| 115 | + if (IS_ERR(srq->umem)) |
|---|
| 116 | + return PTR_ERR(srq->umem); |
|---|
| 122 | 117 | |
|---|
| 123 | | - err = mlx4_mtt_init(dev->dev, ib_umem_page_count(srq->umem), |
|---|
| 124 | | - srq->umem->page_shift, &srq->mtt); |
|---|
| 118 | + err = mlx4_mtt_init( |
|---|
| 119 | + dev->dev, ib_umem_num_dma_blocks(srq->umem, PAGE_SIZE), |
|---|
| 120 | + PAGE_SHIFT, &srq->mtt); |
|---|
| 125 | 121 | if (err) |
|---|
| 126 | 122 | goto err_buf; |
|---|
| 127 | 123 | |
|---|
| .. | .. |
|---|
| 129 | 125 | if (err) |
|---|
| 130 | 126 | goto err_mtt; |
|---|
| 131 | 127 | |
|---|
| 132 | | - err = mlx4_ib_db_map_user(to_mucontext(pd->uobject->context), |
|---|
| 133 | | - ucmd.db_addr, &srq->db); |
|---|
| 128 | + err = mlx4_ib_db_map_user(udata, ucmd.db_addr, &srq->db); |
|---|
| 134 | 129 | if (err) |
|---|
| 135 | 130 | goto err_mtt; |
|---|
| 136 | 131 | } else { |
|---|
| 137 | 132 | err = mlx4_db_alloc(dev->dev, &srq->db, 0); |
|---|
| 138 | 133 | if (err) |
|---|
| 139 | | - goto err_srq; |
|---|
| 134 | + return err; |
|---|
| 140 | 135 | |
|---|
| 141 | 136 | *srq->db.db = 0; |
|---|
| 142 | 137 | |
|---|
| .. | .. |
|---|
| 183 | 178 | xrcdn = (init_attr->srq_type == IB_SRQT_XRC) ? |
|---|
| 184 | 179 | to_mxrcd(init_attr->ext.xrc.xrcd)->xrcdn : |
|---|
| 185 | 180 | (u16) dev->dev->caps.reserved_xrcds; |
|---|
| 186 | | - err = mlx4_srq_alloc(dev->dev, to_mpd(pd)->pdn, cqn, xrcdn, &srq->mtt, |
|---|
| 187 | | - srq->db.dma, &srq->msrq); |
|---|
| 181 | + err = mlx4_srq_alloc(dev->dev, to_mpd(ib_srq->pd)->pdn, cqn, xrcdn, |
|---|
| 182 | + &srq->mtt, srq->db.dma, &srq->msrq); |
|---|
| 188 | 183 | if (err) |
|---|
| 189 | 184 | goto err_wrid; |
|---|
| 190 | 185 | |
|---|
| 191 | 186 | srq->msrq.event = mlx4_ib_srq_event; |
|---|
| 192 | 187 | srq->ibsrq.ext.xrc.srq_num = srq->msrq.srqn; |
|---|
| 193 | 188 | |
|---|
| 194 | | - if (pd->uobject) |
|---|
| 189 | + if (udata) |
|---|
| 195 | 190 | if (ib_copy_to_udata(udata, &srq->msrq.srqn, sizeof (__u32))) { |
|---|
| 196 | 191 | err = -EFAULT; |
|---|
| 197 | 192 | goto err_wrid; |
|---|
| .. | .. |
|---|
| 199 | 194 | |
|---|
| 200 | 195 | init_attr->attr.max_wr = srq->msrq.max - 1; |
|---|
| 201 | 196 | |
|---|
| 202 | | - return &srq->ibsrq; |
|---|
| 197 | + return 0; |
|---|
| 203 | 198 | |
|---|
| 204 | 199 | err_wrid: |
|---|
| 205 | | - if (pd->uobject) |
|---|
| 206 | | - mlx4_ib_db_unmap_user(to_mucontext(pd->uobject->context), &srq->db); |
|---|
| 200 | + if (udata) |
|---|
| 201 | + mlx4_ib_db_unmap_user(ucontext, &srq->db); |
|---|
| 207 | 202 | else |
|---|
| 208 | 203 | kvfree(srq->wrid); |
|---|
| 209 | 204 | |
|---|
| .. | .. |
|---|
| 211 | 206 | mlx4_mtt_cleanup(dev->dev, &srq->mtt); |
|---|
| 212 | 207 | |
|---|
| 213 | 208 | err_buf: |
|---|
| 214 | | - if (pd->uobject) |
|---|
| 215 | | - ib_umem_release(srq->umem); |
|---|
| 216 | | - else |
|---|
| 209 | + if (!srq->umem) |
|---|
| 217 | 210 | mlx4_buf_free(dev->dev, buf_size, &srq->buf); |
|---|
| 211 | + ib_umem_release(srq->umem); |
|---|
| 218 | 212 | |
|---|
| 219 | 213 | err_db: |
|---|
| 220 | | - if (!pd->uobject) |
|---|
| 214 | + if (!udata) |
|---|
| 221 | 215 | mlx4_db_free(dev->dev, &srq->db); |
|---|
| 222 | 216 | |
|---|
| 223 | | -err_srq: |
|---|
| 224 | | - kfree(srq); |
|---|
| 225 | | - |
|---|
| 226 | | - return ERR_PTR(err); |
|---|
| 217 | + return err; |
|---|
| 227 | 218 | } |
|---|
| 228 | 219 | |
|---|
| 229 | 220 | int mlx4_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, |
|---|
| .. | .. |
|---|
| 270 | 261 | return 0; |
|---|
| 271 | 262 | } |
|---|
| 272 | 263 | |
|---|
| 273 | | -int mlx4_ib_destroy_srq(struct ib_srq *srq) |
|---|
| 264 | +int mlx4_ib_destroy_srq(struct ib_srq *srq, struct ib_udata *udata) |
|---|
| 274 | 265 | { |
|---|
| 275 | 266 | struct mlx4_ib_dev *dev = to_mdev(srq->device); |
|---|
| 276 | 267 | struct mlx4_ib_srq *msrq = to_msrq(srq); |
|---|
| .. | .. |
|---|
| 278 | 269 | mlx4_srq_free(dev->dev, &msrq->msrq); |
|---|
| 279 | 270 | mlx4_mtt_cleanup(dev->dev, &msrq->mtt); |
|---|
| 280 | 271 | |
|---|
| 281 | | - if (srq->uobject) { |
|---|
| 282 | | - mlx4_ib_db_unmap_user(to_mucontext(srq->uobject->context), &msrq->db); |
|---|
| 283 | | - ib_umem_release(msrq->umem); |
|---|
| 272 | + if (udata) { |
|---|
| 273 | + mlx4_ib_db_unmap_user( |
|---|
| 274 | + rdma_udata_to_drv_context( |
|---|
| 275 | + udata, |
|---|
| 276 | + struct mlx4_ib_ucontext, |
|---|
| 277 | + ibucontext), |
|---|
| 278 | + &msrq->db); |
|---|
| 284 | 279 | } else { |
|---|
| 285 | 280 | kvfree(msrq->wrid); |
|---|
| 286 | 281 | mlx4_buf_free(dev->dev, msrq->msrq.max << msrq->msrq.wqe_shift, |
|---|
| 287 | 282 | &msrq->buf); |
|---|
| 288 | 283 | mlx4_db_free(dev->dev, &msrq->db); |
|---|
| 289 | 284 | } |
|---|
| 290 | | - |
|---|
| 291 | | - kfree(msrq); |
|---|
| 292 | | - |
|---|
| 285 | + ib_umem_release(msrq->umem); |
|---|
| 293 | 286 | return 0; |
|---|
| 294 | 287 | } |
|---|
| 295 | 288 | |
|---|