2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <linux/init.h>
36 #include <linux/errno.h>
37 #include <linux/export.h>
38 #include <linux/slab.h>
39 #include <linux/kernel.h>
40 #include <linux/vmalloc.h>
42 #include <linux/mlx4/cmd.h>
47 #define MLX4_MPT_FLAG_SW_OWNS (0xfUL << 28)
48 #define MLX4_MPT_FLAG_FREE (0x3UL << 28)
49 #define MLX4_MPT_FLAG_MIO (1 << 17)
50 #define MLX4_MPT_FLAG_BIND_ENABLE (1 << 15)
51 #define MLX4_MPT_FLAG_PHYSICAL (1 << 9)
52 #define MLX4_MPT_FLAG_REGION (1 << 8)
54 #define MLX4_MPT_PD_FLAG_FAST_REG (1 << 27)
55 #define MLX4_MPT_PD_FLAG_RAE (1 << 28)
56 #define MLX4_MPT_PD_FLAG_EN_INV (3 << 24)
58 #define MLX4_MPT_STATUS_SW 0xF0
59 #define MLX4_MPT_STATUS_HW 0x00
61 static u32 mlx4_buddy_alloc(struct mlx4_buddy *buddy, int order)
67 spin_lock(&buddy->lock);
69 for (o = order; o <= buddy->max_order; ++o)
70 if (buddy->num_free[o]) {
71 m = 1 << (buddy->max_order - o);
72 seg = find_first_bit(buddy->bits[o], m);
77 spin_unlock(&buddy->lock);
81 clear_bit(seg, buddy->bits[o]);
87 set_bit(seg ^ 1, buddy->bits[o]);
91 spin_unlock(&buddy->lock);
98 static void mlx4_buddy_free(struct mlx4_buddy *buddy, u32 seg, int order)
102 spin_lock(&buddy->lock);
104 while (test_bit(seg ^ 1, buddy->bits[order])) {
105 clear_bit(seg ^ 1, buddy->bits[order]);
106 --buddy->num_free[order];
111 set_bit(seg, buddy->bits[order]);
112 ++buddy->num_free[order];
114 spin_unlock(&buddy->lock);
117 static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
121 buddy->max_order = max_order;
122 spin_lock_init(&buddy->lock);
124 buddy->bits = kcalloc(buddy->max_order + 1, sizeof (long *),
126 buddy->num_free = kcalloc((buddy->max_order + 1), sizeof *buddy->num_free,
128 if (!buddy->bits || !buddy->num_free)
131 for (i = 0; i <= buddy->max_order; ++i) {
132 s = BITS_TO_LONGS(1 << (buddy->max_order - i));
133 buddy->bits[i] = kcalloc(s, sizeof (long), GFP_KERNEL | __GFP_NOWARN);
134 if (!buddy->bits[i]) {
135 buddy->bits[i] = vzalloc(s * sizeof(long));
141 set_bit(0, buddy->bits[buddy->max_order]);
142 buddy->num_free[buddy->max_order] = 1;
147 for (i = 0; i <= buddy->max_order; ++i)
148 if (buddy->bits[i] && is_vmalloc_addr(buddy->bits[i]))
149 vfree(buddy->bits[i]);
151 kfree(buddy->bits[i]);
155 kfree(buddy->num_free);
160 static void mlx4_buddy_cleanup(struct mlx4_buddy *buddy)
164 for (i = 0; i <= buddy->max_order; ++i)
165 if (is_vmalloc_addr(buddy->bits[i]))
166 vfree(buddy->bits[i]);
168 kfree(buddy->bits[i]);
171 kfree(buddy->num_free);
174 u32 __mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order)
176 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
181 seg_order = max_t(int, order - log_mtts_per_seg, 0);
183 seg = mlx4_buddy_alloc(&mr_table->mtt_buddy, seg_order);
187 offset = seg * (1 << log_mtts_per_seg);
189 if (mlx4_table_get_range(dev, &mr_table->mtt_table, offset,
190 offset + (1 << order) - 1)) {
191 mlx4_buddy_free(&mr_table->mtt_buddy, seg, seg_order);
198 static u32 mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order)
204 if (mlx4_is_mfunc(dev)) {
205 set_param_l(&in_param, order);
206 err = mlx4_cmd_imm(dev, in_param, &out_param, RES_MTT,
207 RES_OP_RESERVE_AND_MAP,
209 MLX4_CMD_TIME_CLASS_A,
213 return get_param_l(&out_param);
215 return __mlx4_alloc_mtt_range(dev, order);
218 int mlx4_mtt_init(struct mlx4_dev *dev, int npages, int page_shift,
219 struct mlx4_mtt *mtt)
225 mtt->page_shift = MLX4_ICM_PAGE_SHIFT;
228 mtt->page_shift = page_shift;
230 for (mtt->order = 0, i = 1; i < npages; i <<= 1)
233 mtt->offset = mlx4_alloc_mtt_range(dev, mtt->order);
234 if (mtt->offset == -1)
239 EXPORT_SYMBOL_GPL(mlx4_mtt_init);
241 void __mlx4_free_mtt_range(struct mlx4_dev *dev, u32 offset, int order)
245 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
247 seg_order = max_t(int, order - log_mtts_per_seg, 0);
248 first_seg = offset / (1 << log_mtts_per_seg);
250 mlx4_buddy_free(&mr_table->mtt_buddy, first_seg, seg_order);
251 mlx4_table_put_range(dev, &mr_table->mtt_table, offset,
252 offset + (1 << order) - 1);
255 static void mlx4_free_mtt_range(struct mlx4_dev *dev, u32 offset, int order)
260 if (mlx4_is_mfunc(dev)) {
261 set_param_l(&in_param, offset);
262 set_param_h(&in_param, order);
263 err = mlx4_cmd(dev, in_param, RES_MTT, RES_OP_RESERVE_AND_MAP,
265 MLX4_CMD_TIME_CLASS_A,
268 mlx4_warn(dev, "Failed to free mtt range at:"
269 "%d order:%d\n", offset, order);
272 __mlx4_free_mtt_range(dev, offset, order);
275 void mlx4_mtt_cleanup(struct mlx4_dev *dev, struct mlx4_mtt *mtt)
280 mlx4_free_mtt_range(dev, mtt->offset, mtt->order);
282 EXPORT_SYMBOL_GPL(mlx4_mtt_cleanup);
284 u64 mlx4_mtt_addr(struct mlx4_dev *dev, struct mlx4_mtt *mtt)
286 return (u64) mtt->offset * dev->caps.mtt_entry_sz;
288 EXPORT_SYMBOL_GPL(mlx4_mtt_addr);
290 static u32 hw_index_to_key(u32 ind)
292 return (ind >> 24) | (ind << 8);
295 static u32 key_to_hw_index(u32 key)
297 return (key << 24) | (key >> 8);
300 static int mlx4_SW2HW_MPT(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
303 return mlx4_cmd(dev, mailbox->dma, mpt_index,
304 0, MLX4_CMD_SW2HW_MPT, MLX4_CMD_TIME_CLASS_B,
308 static int mlx4_HW2SW_MPT(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
311 return mlx4_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index,
312 !mailbox, MLX4_CMD_HW2SW_MPT,
313 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
316 static int mlx4_mr_alloc_reserved(struct mlx4_dev *dev, u32 mridx, u32 pd,
317 u64 iova, u64 size, u32 access, int npages,
318 int page_shift, struct mlx4_mr *mr)
324 mr->enabled = MLX4_MR_DISABLED;
325 mr->key = hw_index_to_key(mridx);
327 return mlx4_mtt_init(dev, npages, page_shift, &mr->mtt);
330 static int mlx4_WRITE_MTT(struct mlx4_dev *dev,
331 struct mlx4_cmd_mailbox *mailbox,
334 return mlx4_cmd(dev, mailbox->dma, num_entries, 0, MLX4_CMD_WRITE_MTT,
335 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
338 int __mlx4_mr_reserve(struct mlx4_dev *dev)
340 struct mlx4_priv *priv = mlx4_priv(dev);
342 return mlx4_bitmap_alloc(&priv->mr_table.mpt_bitmap);
345 static int mlx4_mr_reserve(struct mlx4_dev *dev)
349 if (mlx4_is_mfunc(dev)) {
350 if (mlx4_cmd_imm(dev, 0, &out_param, RES_MPT, RES_OP_RESERVE,
352 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED))
354 return get_param_l(&out_param);
356 return __mlx4_mr_reserve(dev);
359 void __mlx4_mr_release(struct mlx4_dev *dev, u32 index)
361 struct mlx4_priv *priv = mlx4_priv(dev);
363 mlx4_bitmap_free(&priv->mr_table.mpt_bitmap, index);
366 static void mlx4_mr_release(struct mlx4_dev *dev, u32 index)
370 if (mlx4_is_mfunc(dev)) {
371 set_param_l(&in_param, index);
372 if (mlx4_cmd(dev, in_param, RES_MPT, RES_OP_RESERVE,
374 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED))
375 mlx4_warn(dev, "Failed to release mr index:%d\n",
379 __mlx4_mr_release(dev, index);
382 int __mlx4_mr_alloc_icm(struct mlx4_dev *dev, u32 index)
384 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
386 return mlx4_table_get(dev, &mr_table->dmpt_table, index);
389 static int mlx4_mr_alloc_icm(struct mlx4_dev *dev, u32 index)
393 if (mlx4_is_mfunc(dev)) {
394 set_param_l(¶m, index);
395 return mlx4_cmd_imm(dev, param, ¶m, RES_MPT, RES_OP_MAP_ICM,
397 MLX4_CMD_TIME_CLASS_A,
400 return __mlx4_mr_alloc_icm(dev, index);
403 void __mlx4_mr_free_icm(struct mlx4_dev *dev, u32 index)
405 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
407 mlx4_table_put(dev, &mr_table->dmpt_table, index);
410 static void mlx4_mr_free_icm(struct mlx4_dev *dev, u32 index)
414 if (mlx4_is_mfunc(dev)) {
415 set_param_l(&in_param, index);
416 if (mlx4_cmd(dev, in_param, RES_MPT, RES_OP_MAP_ICM,
417 MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A,
419 mlx4_warn(dev, "Failed to free icm of mr index:%d\n",
423 return __mlx4_mr_free_icm(dev, index);
426 int mlx4_mr_alloc(struct mlx4_dev *dev, u32 pd, u64 iova, u64 size, u32 access,
427 int npages, int page_shift, struct mlx4_mr *mr)
432 index = mlx4_mr_reserve(dev);
436 err = mlx4_mr_alloc_reserved(dev, index, pd, iova, size,
437 access, npages, page_shift, mr);
439 mlx4_mr_release(dev, index);
443 EXPORT_SYMBOL_GPL(mlx4_mr_alloc);
445 static void mlx4_mr_free_reserved(struct mlx4_dev *dev, struct mlx4_mr *mr)
449 if (mr->enabled == MLX4_MR_EN_HW) {
450 err = mlx4_HW2SW_MPT(dev, NULL,
451 key_to_hw_index(mr->key) &
452 (dev->caps.num_mpts - 1));
454 mlx4_warn(dev, "xxx HW2SW_MPT failed (%d)\n", err);
456 mr->enabled = MLX4_MR_EN_SW;
458 mlx4_mtt_cleanup(dev, &mr->mtt);
461 void mlx4_mr_free(struct mlx4_dev *dev, struct mlx4_mr *mr)
463 mlx4_mr_free_reserved(dev, mr);
465 mlx4_mr_free_icm(dev, key_to_hw_index(mr->key));
466 mlx4_mr_release(dev, key_to_hw_index(mr->key));
468 EXPORT_SYMBOL_GPL(mlx4_mr_free);
470 int mlx4_mr_enable(struct mlx4_dev *dev, struct mlx4_mr *mr)
472 struct mlx4_cmd_mailbox *mailbox;
473 struct mlx4_mpt_entry *mpt_entry;
476 err = mlx4_mr_alloc_icm(dev, key_to_hw_index(mr->key));
480 mailbox = mlx4_alloc_cmd_mailbox(dev);
481 if (IS_ERR(mailbox)) {
482 err = PTR_ERR(mailbox);
485 mpt_entry = mailbox->buf;
487 memset(mpt_entry, 0, sizeof *mpt_entry);
489 mpt_entry->flags = cpu_to_be32(MLX4_MPT_FLAG_MIO |
490 MLX4_MPT_FLAG_REGION |
493 mpt_entry->key = cpu_to_be32(key_to_hw_index(mr->key));
494 mpt_entry->pd_flags = cpu_to_be32(mr->pd | MLX4_MPT_PD_FLAG_EN_INV);
495 mpt_entry->start = cpu_to_be64(mr->iova);
496 mpt_entry->length = cpu_to_be64(mr->size);
497 mpt_entry->entity_size = cpu_to_be32(mr->mtt.page_shift);
499 if (mr->mtt.order < 0) {
500 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_PHYSICAL);
501 mpt_entry->mtt_addr = 0;
503 mpt_entry->mtt_addr = cpu_to_be64(mlx4_mtt_addr(dev,
507 if (mr->mtt.order >= 0 && mr->mtt.page_shift == 0) {
508 /* fast register MR in free state */
509 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_FREE);
510 mpt_entry->pd_flags |= cpu_to_be32(MLX4_MPT_PD_FLAG_FAST_REG |
511 MLX4_MPT_PD_FLAG_RAE);
512 mpt_entry->mtt_sz = cpu_to_be32(1 << mr->mtt.order);
514 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_SW_OWNS);
517 err = mlx4_SW2HW_MPT(dev, mailbox,
518 key_to_hw_index(mr->key) & (dev->caps.num_mpts - 1));
520 mlx4_warn(dev, "SW2HW_MPT failed (%d)\n", err);
523 mr->enabled = MLX4_MR_EN_HW;
525 mlx4_free_cmd_mailbox(dev, mailbox);
530 mlx4_free_cmd_mailbox(dev, mailbox);
533 mlx4_mr_free_icm(dev, key_to_hw_index(mr->key));
536 EXPORT_SYMBOL_GPL(mlx4_mr_enable);
538 static int mlx4_write_mtt_chunk(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
539 int start_index, int npages, u64 *page_list)
541 struct mlx4_priv *priv = mlx4_priv(dev);
543 dma_addr_t dma_handle;
546 mtts = mlx4_table_find(&priv->mr_table.mtt_table, mtt->offset +
547 start_index, &dma_handle);
552 dma_sync_single_for_cpu(&dev->pdev->dev, dma_handle,
553 npages * sizeof (u64), DMA_TO_DEVICE);
555 for (i = 0; i < npages; ++i)
556 mtts[i] = cpu_to_be64(page_list[i] | MLX4_MTT_FLAG_PRESENT);
558 dma_sync_single_for_device(&dev->pdev->dev, dma_handle,
559 npages * sizeof (u64), DMA_TO_DEVICE);
564 int __mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
565 int start_index, int npages, u64 *page_list)
570 int max_mtts_first_page;
572 /* compute how may mtts fit in the first page */
573 mtts_per_page = PAGE_SIZE / sizeof(u64);
574 max_mtts_first_page = mtts_per_page - (mtt->offset + start_index)
577 chunk = min_t(int, max_mtts_first_page, npages);
580 err = mlx4_write_mtt_chunk(dev, mtt, start_index, chunk, page_list);
584 start_index += chunk;
587 chunk = min_t(int, mtts_per_page, npages);
592 int mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
593 int start_index, int npages, u64 *page_list)
595 struct mlx4_cmd_mailbox *mailbox = NULL;
596 __be64 *inbox = NULL;
604 if (mlx4_is_mfunc(dev)) {
605 mailbox = mlx4_alloc_cmd_mailbox(dev);
607 return PTR_ERR(mailbox);
608 inbox = mailbox->buf;
611 chunk = min_t(int, MLX4_MAILBOX_SIZE / sizeof(u64) - 2,
613 inbox[0] = cpu_to_be64(mtt->offset + start_index);
615 for (i = 0; i < chunk; ++i)
616 inbox[i + 2] = cpu_to_be64(page_list[i] |
617 MLX4_MTT_FLAG_PRESENT);
618 err = mlx4_WRITE_MTT(dev, mailbox, chunk);
620 mlx4_free_cmd_mailbox(dev, mailbox);
625 start_index += chunk;
628 mlx4_free_cmd_mailbox(dev, mailbox);
632 return __mlx4_write_mtt(dev, mtt, start_index, npages, page_list);
634 EXPORT_SYMBOL_GPL(mlx4_write_mtt);
636 int mlx4_buf_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
637 struct mlx4_buf *buf)
643 page_list = kmalloc(buf->npages * sizeof *page_list, GFP_KERNEL);
647 for (i = 0; i < buf->npages; ++i)
649 page_list[i] = buf->direct.map + (i << buf->page_shift);
651 page_list[i] = buf->page_list[i].map;
653 err = mlx4_write_mtt(dev, mtt, 0, buf->npages, page_list);
658 EXPORT_SYMBOL_GPL(mlx4_buf_write_mtt);
660 int mlx4_init_mr_table(struct mlx4_dev *dev)
662 struct mlx4_priv *priv = mlx4_priv(dev);
663 struct mlx4_mr_table *mr_table = &priv->mr_table;
666 if (!is_power_of_2(dev->caps.num_mpts))
669 /* Nothing to do for slaves - all MR handling is forwarded
671 if (mlx4_is_slave(dev))
674 err = mlx4_bitmap_init(&mr_table->mpt_bitmap, dev->caps.num_mpts,
675 ~0, dev->caps.reserved_mrws, 0);
679 err = mlx4_buddy_init(&mr_table->mtt_buddy,
680 ilog2((u32)dev->caps.num_mtts /
681 (1 << log_mtts_per_seg)));
685 if (dev->caps.reserved_mtts) {
686 priv->reserved_mtts =
687 mlx4_alloc_mtt_range(dev,
688 fls(dev->caps.reserved_mtts - 1));
689 if (priv->reserved_mtts < 0) {
690 mlx4_warn(dev, "MTT table of order %u is too small.\n",
691 mr_table->mtt_buddy.max_order);
693 goto err_reserve_mtts;
700 mlx4_buddy_cleanup(&mr_table->mtt_buddy);
703 mlx4_bitmap_cleanup(&mr_table->mpt_bitmap);
708 void mlx4_cleanup_mr_table(struct mlx4_dev *dev)
710 struct mlx4_priv *priv = mlx4_priv(dev);
711 struct mlx4_mr_table *mr_table = &priv->mr_table;
713 if (mlx4_is_slave(dev))
715 if (priv->reserved_mtts >= 0)
716 mlx4_free_mtt_range(dev, priv->reserved_mtts,
717 fls(dev->caps.reserved_mtts - 1));
718 mlx4_buddy_cleanup(&mr_table->mtt_buddy);
719 mlx4_bitmap_cleanup(&mr_table->mpt_bitmap);
722 static inline int mlx4_check_fmr(struct mlx4_fmr *fmr, u64 *page_list,
723 int npages, u64 iova)
727 if (npages > fmr->max_pages)
730 page_mask = (1 << fmr->page_shift) - 1;
732 /* We are getting page lists, so va must be page aligned. */
733 if (iova & page_mask)
736 /* Trust the user not to pass misaligned data in page_list */
738 for (i = 0; i < npages; ++i) {
739 if (page_list[i] & ~page_mask)
743 if (fmr->maps >= fmr->max_maps)
749 int mlx4_map_phys_fmr(struct mlx4_dev *dev, struct mlx4_fmr *fmr, u64 *page_list,
750 int npages, u64 iova, u32 *lkey, u32 *rkey)
755 err = mlx4_check_fmr(fmr, page_list, npages, iova);
761 key = key_to_hw_index(fmr->mr.key);
762 key += dev->caps.num_mpts;
763 *lkey = *rkey = fmr->mr.key = hw_index_to_key(key);
765 *(u8 *) fmr->mpt = MLX4_MPT_STATUS_SW;
767 /* Make sure MPT status is visible before writing MTT entries */
770 dma_sync_single_for_cpu(&dev->pdev->dev, fmr->dma_handle,
771 npages * sizeof(u64), DMA_TO_DEVICE);
773 for (i = 0; i < npages; ++i)
774 fmr->mtts[i] = cpu_to_be64(page_list[i] | MLX4_MTT_FLAG_PRESENT);
776 dma_sync_single_for_device(&dev->pdev->dev, fmr->dma_handle,
777 npages * sizeof(u64), DMA_TO_DEVICE);
779 fmr->mpt->key = cpu_to_be32(key);
780 fmr->mpt->lkey = cpu_to_be32(key);
781 fmr->mpt->length = cpu_to_be64(npages * (1ull << fmr->page_shift));
782 fmr->mpt->start = cpu_to_be64(iova);
784 /* Make MTT entries are visible before setting MPT status */
787 *(u8 *) fmr->mpt = MLX4_MPT_STATUS_HW;
789 /* Make sure MPT status is visible before consumer can use FMR */
794 EXPORT_SYMBOL_GPL(mlx4_map_phys_fmr);
796 int mlx4_fmr_alloc(struct mlx4_dev *dev, u32 pd, u32 access, int max_pages,
797 int max_maps, u8 page_shift, struct mlx4_fmr *fmr)
799 struct mlx4_priv *priv = mlx4_priv(dev);
802 if (max_maps > dev->caps.max_fmr_maps)
805 if (page_shift < (ffs(dev->caps.page_size_cap) - 1) || page_shift >= 32)
808 /* All MTTs must fit in the same page */
809 if (max_pages * sizeof *fmr->mtts > PAGE_SIZE)
812 fmr->page_shift = page_shift;
813 fmr->max_pages = max_pages;
814 fmr->max_maps = max_maps;
817 err = mlx4_mr_alloc(dev, pd, 0, 0, access, max_pages,
818 page_shift, &fmr->mr);
822 fmr->mtts = mlx4_table_find(&priv->mr_table.mtt_table,
834 mlx4_mr_free(dev, &fmr->mr);
837 EXPORT_SYMBOL_GPL(mlx4_fmr_alloc);
839 int mlx4_fmr_enable(struct mlx4_dev *dev, struct mlx4_fmr *fmr)
841 struct mlx4_priv *priv = mlx4_priv(dev);
844 err = mlx4_mr_enable(dev, &fmr->mr);
848 fmr->mpt = mlx4_table_find(&priv->mr_table.dmpt_table,
849 key_to_hw_index(fmr->mr.key), NULL);
855 EXPORT_SYMBOL_GPL(mlx4_fmr_enable);
857 void mlx4_fmr_unmap(struct mlx4_dev *dev, struct mlx4_fmr *fmr,
858 u32 *lkey, u32 *rkey)
860 struct mlx4_cmd_mailbox *mailbox;
868 mailbox = mlx4_alloc_cmd_mailbox(dev);
869 if (IS_ERR(mailbox)) {
870 err = PTR_ERR(mailbox);
871 printk(KERN_WARNING "mlx4_ib: mlx4_alloc_cmd_mailbox"
872 " failed (%d)\n", err);
876 err = mlx4_HW2SW_MPT(dev, NULL,
877 key_to_hw_index(fmr->mr.key) &
878 (dev->caps.num_mpts - 1));
879 mlx4_free_cmd_mailbox(dev, mailbox);
881 printk(KERN_WARNING "mlx4_ib: mlx4_HW2SW_MPT failed (%d)\n",
885 fmr->mr.enabled = MLX4_MR_EN_SW;
887 EXPORT_SYMBOL_GPL(mlx4_fmr_unmap);
889 int mlx4_fmr_free(struct mlx4_dev *dev, struct mlx4_fmr *fmr)
894 mlx4_mr_free(dev, &fmr->mr);
895 fmr->mr.enabled = MLX4_MR_DISABLED;
899 EXPORT_SYMBOL_GPL(mlx4_fmr_free);
901 int mlx4_SYNC_TPT(struct mlx4_dev *dev)
903 return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_SYNC_TPT, 1000,
906 EXPORT_SYMBOL_GPL(mlx4_SYNC_TPT);