aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/hw/mlx4/mr.c
diff options
context:
space:
mode:
authorJack Morgenstein <jackm@dev.mellanox.co.il>2007-08-01 05:29:05 -0400
committerRoland Dreier <rolandd@cisco.com>2007-10-09 22:59:16 -0400
commit8ad11fb6b0739e704953e2b0aed453bf7d75d4f6 (patch)
tree671838bc9293987efba214f2d645d7e40befc5a8 /drivers/infiniband/hw/mlx4/mr.c
parentd7bb58fb1c0e7264a7261c7d0304121ef9402e94 (diff)
IB/mlx4: Implement FMRs
Implement FMRs for mlx4. This is an adaptation of code from mthca. Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il> Signed-off-by: Michael S. Tsirkin <mst@dev.mellanox.co.il> Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband/hw/mlx4/mr.c')
-rw-r--r--drivers/infiniband/hw/mlx4/mr.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c
index 734ec2bd15c..7dc91a3e712 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
185struct 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
210err_mr:
211 mlx4_mr_free(to_mdev(pd->device)->dev, &fmr->mfmr.mr);
212
213err_free:
214 kfree(fmr);
215
216 return ERR_PTR(err);
217}
218
219int 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
229int 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
264int 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}