forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/infiniband/hw/ocrdma/ocrdma_ah.c
....@@ -155,36 +155,34 @@
155155 return status;
156156 }
157157
158
-struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct rdma_ah_attr *attr,
159
- struct ib_udata *udata)
158
+int ocrdma_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr,
159
+ struct ib_udata *udata)
160160 {
161161 u32 *ahid_addr;
162162 int status;
163
- struct ocrdma_ah *ah;
163
+ struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
164164 bool isvlan = false;
165165 u16 vlan_tag = 0xffff;
166166 const struct ib_gid_attr *sgid_attr;
167
- struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
168
- struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device);
167
+ struct ocrdma_pd *pd = get_ocrdma_pd(ibah->pd);
168
+ struct rdma_ah_attr *attr = init_attr->ah_attr;
169
+ struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device);
169170
170171 if ((attr->type != RDMA_AH_ATTR_TYPE_ROCE) ||
171172 !(rdma_ah_get_ah_flags(attr) & IB_AH_GRH))
172
- return ERR_PTR(-EINVAL);
173
+ return -EINVAL;
173174
174175 if (atomic_cmpxchg(&dev->update_sl, 1, 0))
175176 ocrdma_init_service_level(dev);
176177
177
- ah = kzalloc(sizeof(*ah), GFP_ATOMIC);
178
- if (!ah)
179
- return ERR_PTR(-ENOMEM);
178
+ sgid_attr = attr->grh.sgid_attr;
179
+ status = rdma_read_gid_l2_fields(sgid_attr, &vlan_tag, NULL);
180
+ if (status)
181
+ return status;
180182
181183 status = ocrdma_alloc_av(dev, ah);
182184 if (status)
183185 goto av_err;
184
-
185
- sgid_attr = attr->grh.sgid_attr;
186
- if (is_vlan_dev(sgid_attr->ndev))
187
- vlan_tag = vlan_dev_vlan_id(sgid_attr->ndev);
188186
189187 /* Get network header type for this GID */
190188 ah->hdr_type = rdma_gid_attr_network_type(sgid_attr);
....@@ -209,22 +207,20 @@
209207 OCRDMA_AH_VLAN_VALID_SHIFT);
210208 }
211209
212
- return &ah->ibah;
210
+ return 0;
213211
214212 av_conf_err:
215213 ocrdma_free_av(dev, ah);
216214 av_err:
217
- kfree(ah);
218
- return ERR_PTR(status);
215
+ return status;
219216 }
220217
221
-int ocrdma_destroy_ah(struct ib_ah *ibah)
218
+int ocrdma_destroy_ah(struct ib_ah *ibah, u32 flags)
222219 {
223220 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
224221 struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device);
225222
226223 ocrdma_free_av(dev, ah);
227
- kfree(ah);
228224 return 0;
229225 }
230226
....@@ -253,35 +249,20 @@
253249 return 0;
254250 }
255251
256
-int ocrdma_process_mad(struct ib_device *ibdev,
257
- int process_mad_flags,
258
- u8 port_num,
259
- const struct ib_wc *in_wc,
260
- const struct ib_grh *in_grh,
261
- const struct ib_mad_hdr *in, size_t in_mad_size,
262
- struct ib_mad_hdr *out, size_t *out_mad_size,
252
+int ocrdma_process_mad(struct ib_device *ibdev, int process_mad_flags,
253
+ u8 port_num, const struct ib_wc *in_wc,
254
+ const struct ib_grh *in_grh, const struct ib_mad *in,
255
+ struct ib_mad *out, size_t *out_mad_size,
263256 u16 *out_mad_pkey_index)
264257 {
265
- int status;
258
+ int status = IB_MAD_RESULT_SUCCESS;
266259 struct ocrdma_dev *dev;
267
- const struct ib_mad *in_mad = (const struct ib_mad *)in;
268
- struct ib_mad *out_mad = (struct ib_mad *)out;
269260
270
- if (WARN_ON_ONCE(in_mad_size != sizeof(*in_mad) ||
271
- *out_mad_size != sizeof(*out_mad)))
272
- return IB_MAD_RESULT_FAILURE;
273
-
274
- switch (in_mad->mad_hdr.mgmt_class) {
275
- case IB_MGMT_CLASS_PERF_MGMT:
261
+ if (in->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) {
276262 dev = get_ocrdma_dev(ibdev);
277
- if (!ocrdma_pma_counters(dev, out_mad))
278
- status = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
279
- else
280
- status = IB_MAD_RESULT_SUCCESS;
281
- break;
282
- default:
283
- status = IB_MAD_RESULT_SUCCESS;
284
- break;
263
+ ocrdma_pma_counters(dev, out);
264
+ status |= IB_MAD_RESULT_REPLY;
285265 }
266
+
286267 return status;
287268 }