hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/infiniband/hw/mthca/mthca_srq.c
....@@ -36,6 +36,8 @@
3636
3737 #include <asm/io.h>
3838
39
+#include <rdma/uverbs_ioctl.h>
40
+
3941 #include "mthca_dev.h"
4042 #include "mthca_cmd.h"
4143 #include "mthca_memfree.h"
....@@ -95,17 +97,20 @@
9597 static void mthca_tavor_init_srq_context(struct mthca_dev *dev,
9698 struct mthca_pd *pd,
9799 struct mthca_srq *srq,
98
- struct mthca_tavor_srq_context *context)
100
+ struct mthca_tavor_srq_context *context,
101
+ struct ib_udata *udata)
99102 {
103
+ struct mthca_ucontext *ucontext = rdma_udata_to_drv_context(
104
+ udata, struct mthca_ucontext, ibucontext);
105
+
100106 memset(context, 0, sizeof *context);
101107
102108 context->wqe_base_ds = cpu_to_be64(1 << (srq->wqe_shift - 4));
103109 context->state_pd = cpu_to_be32(pd->pd_num);
104110 context->lkey = cpu_to_be32(srq->mr.ibmr.lkey);
105111
106
- if (pd->ibpd.uobject)
107
- context->uar =
108
- cpu_to_be32(to_mucontext(pd->ibpd.uobject->context)->uar.index);
112
+ if (udata)
113
+ context->uar = cpu_to_be32(ucontext->uar.index);
109114 else
110115 context->uar = cpu_to_be32(dev->driver_uar.index);
111116 }
....@@ -113,8 +118,11 @@
113118 static void mthca_arbel_init_srq_context(struct mthca_dev *dev,
114119 struct mthca_pd *pd,
115120 struct mthca_srq *srq,
116
- struct mthca_arbel_srq_context *context)
121
+ struct mthca_arbel_srq_context *context,
122
+ struct ib_udata *udata)
117123 {
124
+ struct mthca_ucontext *ucontext = rdma_udata_to_drv_context(
125
+ udata, struct mthca_ucontext, ibucontext);
118126 int logsize, max;
119127
120128 memset(context, 0, sizeof *context);
....@@ -129,9 +137,8 @@
129137 context->lkey = cpu_to_be32(srq->mr.ibmr.lkey);
130138 context->db_index = cpu_to_be32(srq->db_index);
131139 context->logstride_usrpage = cpu_to_be32((srq->wqe_shift - 4) << 29);
132
- if (pd->ibpd.uobject)
133
- context->logstride_usrpage |=
134
- cpu_to_be32(to_mucontext(pd->ibpd.uobject->context)->uar.index);
140
+ if (udata)
141
+ context->logstride_usrpage |= cpu_to_be32(ucontext->uar.index);
135142 else
136143 context->logstride_usrpage |= cpu_to_be32(dev->driver_uar.index);
137144 context->eq_pd = cpu_to_be32(MTHCA_EQ_ASYNC << 24 | pd->pd_num);
....@@ -145,14 +152,14 @@
145152 }
146153
147154 static int mthca_alloc_srq_buf(struct mthca_dev *dev, struct mthca_pd *pd,
148
- struct mthca_srq *srq)
155
+ struct mthca_srq *srq, struct ib_udata *udata)
149156 {
150157 struct mthca_data_seg *scatter;
151158 void *wqe;
152159 int err;
153160 int i;
154161
155
- if (pd->ibpd.uobject)
162
+ if (udata)
156163 return 0;
157164
158165 srq->wrid = kmalloc_array(srq->max, sizeof(u64), GFP_KERNEL);
....@@ -197,7 +204,8 @@
197204 }
198205
199206 int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
200
- struct ib_srq_attr *attr, struct mthca_srq *srq)
207
+ struct ib_srq_attr *attr, struct mthca_srq *srq,
208
+ struct ib_udata *udata)
201209 {
202210 struct mthca_mailbox *mailbox;
203211 int ds;
....@@ -235,7 +243,7 @@
235243 if (err)
236244 goto err_out;
237245
238
- if (!pd->ibpd.uobject) {
246
+ if (!udata) {
239247 srq->db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SRQ,
240248 srq->srqn, &srq->db);
241249 if (srq->db_index < 0) {
....@@ -251,7 +259,7 @@
251259 goto err_out_db;
252260 }
253261
254
- err = mthca_alloc_srq_buf(dev, pd, srq);
262
+ err = mthca_alloc_srq_buf(dev, pd, srq, udata);
255263 if (err)
256264 goto err_out_mailbox;
257265
....@@ -261,9 +269,9 @@
261269 mutex_init(&srq->mutex);
262270
263271 if (mthca_is_memfree(dev))
264
- mthca_arbel_init_srq_context(dev, pd, srq, mailbox->buf);
272
+ mthca_arbel_init_srq_context(dev, pd, srq, mailbox->buf, udata);
265273 else
266
- mthca_tavor_init_srq_context(dev, pd, srq, mailbox->buf);
274
+ mthca_tavor_init_srq_context(dev, pd, srq, mailbox->buf, udata);
267275
268276 err = mthca_SW2HW_SRQ(dev, mailbox, srq->srqn);
269277
....@@ -297,14 +305,14 @@
297305 mthca_warn(dev, "HW2SW_SRQ failed (%d)\n", err);
298306
299307 err_out_free_buf:
300
- if (!pd->ibpd.uobject)
308
+ if (!udata)
301309 mthca_free_srq_buf(dev, srq);
302310
303311 err_out_mailbox:
304312 mthca_free_mailbox(dev, mailbox);
305313
306314 err_out_db:
307
- if (!pd->ibpd.uobject && mthca_is_memfree(dev))
315
+ if (!udata && mthca_is_memfree(dev))
308316 mthca_free_db(dev, MTHCA_DB_TYPE_SRQ, srq->db_index);
309317
310318 err_out_icm:
....@@ -561,12 +569,6 @@
561569 dev->kar + MTHCA_RECEIVE_DOORBELL,
562570 MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
563571 }
564
-
565
- /*
566
- * Make sure doorbells don't leak out of SRQ spinlock and
567
- * reach the HCA out of order:
568
- */
569
- mmiowb();
570572
571573 spin_unlock_irqrestore(&srq->lock, flags);
572574 return err;