diff options
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/hw/mlx4/main.c | 5 | ||||
-rw-r--r-- | drivers/infiniband/hw/mlx4/mlx4_ib.h | 16 | ||||
-rw-r--r-- | drivers/infiniband/hw/mlx4/mr.c | 93 |
3 files changed, 114 insertions, 0 deletions
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index d9fc822a1468..d8287d9db41e 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c | |||
@@ -607,6 +607,11 @@ static void *mlx4_ib_add(struct mlx4_dev *dev) | |||
607 | ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach; | 607 | ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach; |
608 | ibdev->ib_dev.process_mad = mlx4_ib_process_mad; | 608 | ibdev->ib_dev.process_mad = mlx4_ib_process_mad; |
609 | 609 | ||
610 | ibdev->ib_dev.alloc_fmr = mlx4_ib_fmr_alloc; | ||
611 | ibdev->ib_dev.map_phys_fmr = mlx4_ib_map_phys_fmr; | ||
612 | ibdev->ib_dev.unmap_fmr = mlx4_ib_unmap_fmr; | ||
613 | ibdev->ib_dev.dealloc_fmr = mlx4_ib_fmr_dealloc; | ||
614 | |||
610 | if (init_node_data(ibdev)) | 615 | if (init_node_data(ibdev)) |
611 | goto err_map; | 616 | goto err_map; |
612 | 617 | ||
diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h index 705ff2fa237e..28697653a370 100644 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h | |||
@@ -93,6 +93,11 @@ struct mlx4_ib_mr { | |||
93 | struct ib_umem *umem; | 93 | struct ib_umem *umem; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | struct mlx4_ib_fmr { | ||
97 | struct ib_fmr ibfmr; | ||
98 | struct mlx4_fmr mfmr; | ||
99 | }; | ||
100 | |||
96 | struct mlx4_ib_wq { | 101 | struct mlx4_ib_wq { |
97 | u64 *wrid; | 102 | u64 *wrid; |
98 | spinlock_t lock; | 103 | spinlock_t lock; |
@@ -199,6 +204,10 @@ static inline struct mlx4_ib_mr *to_mmr(struct ib_mr *ibmr) | |||
199 | return container_of(ibmr, struct mlx4_ib_mr, ibmr); | 204 | return container_of(ibmr, struct mlx4_ib_mr, ibmr); |
200 | } | 205 | } |
201 | 206 | ||
207 | static inline struct mlx4_ib_fmr *to_mfmr(struct ib_fmr *ibfmr) | ||
208 | { | ||
209 | return container_of(ibfmr, struct mlx4_ib_fmr, ibfmr); | ||
210 | } | ||
202 | static inline struct mlx4_ib_qp *to_mqp(struct ib_qp *ibqp) | 211 | static inline struct mlx4_ib_qp *to_mqp(struct ib_qp *ibqp) |
203 | { | 212 | { |
204 | return container_of(ibqp, struct mlx4_ib_qp, ibqp); | 213 | return container_of(ibqp, struct mlx4_ib_qp, ibqp); |
@@ -284,6 +293,13 @@ int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num, | |||
284 | int mlx4_ib_mad_init(struct mlx4_ib_dev *dev); | 293 | int mlx4_ib_mad_init(struct mlx4_ib_dev *dev); |
285 | void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev); | 294 | void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev); |
286 | 295 | ||
296 | struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int mr_access_flags, | ||
297 | struct ib_fmr_attr *fmr_attr); | ||
298 | int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, int npages, | ||
299 | u64 iova); | ||
300 | int mlx4_ib_unmap_fmr(struct list_head *fmr_list); | ||
301 | int mlx4_ib_fmr_dealloc(struct ib_fmr *fmr); | ||
302 | |||
287 | static inline int mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah) | 303 | static inline int mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah) |
288 | { | 304 | { |
289 | return !!(ah->av.g_slid & 0x80); | 305 | return !!(ah->av.g_slid & 0x80); |
diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c index 734ec2bd15cd..7dc91a3e712d 100644 --- a/drivers/infiniband/hw/mlx4/mr.c +++ b/drivers/infiniband/hw/mlx4/mr.c | |||
@@ -181,3 +181,96 @@ int mlx4_ib_dereg_mr(struct ib_mr *ibmr) | |||
181 | 181 | ||
182 | return 0; | 182 | return 0; |
183 | } | 183 | } |
184 | |||
185 | struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int acc, | ||
186 | struct ib_fmr_attr *fmr_attr) | ||
187 | { | ||
188 | struct mlx4_ib_dev *dev = to_mdev(pd->device); | ||
189 | struct mlx4_ib_fmr *fmr; | ||
190 | int err = -ENOMEM; | ||
191 | |||
192 | fmr = kmalloc(sizeof *fmr, GFP_KERNEL); | ||
193 | if (!fmr) | ||
194 | return ERR_PTR(-ENOMEM); | ||
195 | |||
196 | err = mlx4_fmr_alloc(dev->dev, to_mpd(pd)->pdn, convert_access(acc), | ||
197 | fmr_attr->max_pages, fmr_attr->max_maps, | ||
198 | fmr_attr->page_shift, &fmr->mfmr); | ||
199 | if (err) | ||
200 | goto err_free; | ||
201 | |||
202 | err = mlx4_mr_enable(to_mdev(pd->device)->dev, &fmr->mfmr.mr); | ||
203 | if (err) | ||
204 | goto err_mr; | ||
205 | |||
206 | fmr->ibfmr.rkey = fmr->ibfmr.lkey = fmr->mfmr.mr.key; | ||
207 | |||
208 | return &fmr->ibfmr; | ||
209 | |||
210 | err_mr: | ||
211 | mlx4_mr_free(to_mdev(pd->device)->dev, &fmr->mfmr.mr); | ||
212 | |||
213 | err_free: | ||
214 | kfree(fmr); | ||
215 | |||
216 | return ERR_PTR(err); | ||
217 | } | ||
218 | |||
219 | int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, | ||
220 | int npages, u64 iova) | ||
221 | { | ||
222 | struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr); | ||
223 | struct mlx4_ib_dev *dev = to_mdev(ifmr->ibfmr.device); | ||
224 | |||
225 | return mlx4_map_phys_fmr(dev->dev, &ifmr->mfmr, page_list, npages, iova, | ||
226 | &ifmr->ibfmr.lkey, &ifmr->ibfmr.rkey); | ||
227 | } | ||
228 | |||
229 | int mlx4_ib_unmap_fmr(struct list_head *fmr_list) | ||
230 | { | ||
231 | struct ib_fmr *ibfmr; | ||
232 | int err; | ||
233 | struct mlx4_dev *mdev = NULL; | ||
234 | |||
235 | list_for_each_entry(ibfmr, fmr_list, list) { | ||
236 | if (mdev && to_mdev(ibfmr->device)->dev != mdev) | ||
237 | return -EINVAL; | ||
238 | mdev = to_mdev(ibfmr->device)->dev; | ||
239 | } | ||
240 | |||
241 | if (!mdev) | ||
242 | return 0; | ||
243 | |||
244 | list_for_each_entry(ibfmr, fmr_list, list) { | ||
245 | struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr); | ||
246 | |||
247 | mlx4_fmr_unmap(mdev, &ifmr->mfmr, &ifmr->ibfmr.lkey, &ifmr->ibfmr.rkey); | ||
248 | } | ||
249 | |||
250 | /* | ||
251 | * Make sure all MPT status updates are visible before issuing | ||
252 | * SYNC_TPT firmware command. | ||
253 | */ | ||
254 | wmb(); | ||
255 | |||
256 | err = mlx4_SYNC_TPT(mdev); | ||
257 | if (err) | ||
258 | printk(KERN_WARNING "mlx4_ib: SYNC_TPT error %d when " | ||
259 | "unmapping FMRs\n", err); | ||
260 | |||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | int mlx4_ib_fmr_dealloc(struct ib_fmr *ibfmr) | ||
265 | { | ||
266 | struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr); | ||
267 | struct mlx4_ib_dev *dev = to_mdev(ibfmr->device); | ||
268 | int err; | ||
269 | |||
270 | err = mlx4_fmr_free(dev->dev, &ifmr->mfmr); | ||
271 | |||
272 | if (!err) | ||
273 | kfree(ifmr); | ||
274 | |||
275 | return err; | ||
276 | } | ||