diff options
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx5/core/main.c | 1 | ||||
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx5/core/mr.c | 24 | ||||
-rw-r--r-- | include/linux/mlx5/driver.h | 18 |
3 files changed, 43 insertions, 0 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index a064f06e0cb8..96a0617f7609 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c | |||
@@ -446,6 +446,7 @@ int mlx5_dev_init(struct mlx5_core_dev *dev, struct pci_dev *pdev) | |||
446 | mlx5_init_cq_table(dev); | 446 | mlx5_init_cq_table(dev); |
447 | mlx5_init_qp_table(dev); | 447 | mlx5_init_qp_table(dev); |
448 | mlx5_init_srq_table(dev); | 448 | mlx5_init_srq_table(dev); |
449 | mlx5_init_mr_table(dev); | ||
449 | 450 | ||
450 | return 0; | 451 | return 0; |
451 | 452 | ||
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mr.c b/drivers/net/ethernet/mellanox/mlx5/core/mr.c index bb746bbe73c6..4cc927649404 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/mr.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/mr.c | |||
@@ -36,11 +36,24 @@ | |||
36 | #include <linux/mlx5/cmd.h> | 36 | #include <linux/mlx5/cmd.h> |
37 | #include "mlx5_core.h" | 37 | #include "mlx5_core.h" |
38 | 38 | ||
39 | void mlx5_init_mr_table(struct mlx5_core_dev *dev) | ||
40 | { | ||
41 | struct mlx5_mr_table *table = &dev->priv.mr_table; | ||
42 | |||
43 | rwlock_init(&table->lock); | ||
44 | INIT_RADIX_TREE(&table->tree, GFP_ATOMIC); | ||
45 | } | ||
46 | |||
47 | void mlx5_cleanup_mr_table(struct mlx5_core_dev *dev) | ||
48 | { | ||
49 | } | ||
50 | |||
39 | int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, | 51 | int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, |
40 | struct mlx5_create_mkey_mbox_in *in, int inlen, | 52 | struct mlx5_create_mkey_mbox_in *in, int inlen, |
41 | mlx5_cmd_cbk_t callback, void *context, | 53 | mlx5_cmd_cbk_t callback, void *context, |
42 | struct mlx5_create_mkey_mbox_out *out) | 54 | struct mlx5_create_mkey_mbox_out *out) |
43 | { | 55 | { |
56 | struct mlx5_mr_table *table = &dev->priv.mr_table; | ||
44 | struct mlx5_create_mkey_mbox_out lout; | 57 | struct mlx5_create_mkey_mbox_out lout; |
45 | int err; | 58 | int err; |
46 | u8 key; | 59 | u8 key; |
@@ -73,14 +86,21 @@ int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, | |||
73 | mlx5_core_dbg(dev, "out 0x%x, key 0x%x, mkey 0x%x\n", | 86 | mlx5_core_dbg(dev, "out 0x%x, key 0x%x, mkey 0x%x\n", |
74 | be32_to_cpu(lout.mkey), key, mr->key); | 87 | be32_to_cpu(lout.mkey), key, mr->key); |
75 | 88 | ||
89 | /* connect to MR tree */ | ||
90 | write_lock_irq(&table->lock); | ||
91 | err = radix_tree_insert(&table->tree, mlx5_base_mkey(mr->key), mr); | ||
92 | write_unlock_irq(&table->lock); | ||
93 | |||
76 | return err; | 94 | return err; |
77 | } | 95 | } |
78 | EXPORT_SYMBOL(mlx5_core_create_mkey); | 96 | EXPORT_SYMBOL(mlx5_core_create_mkey); |
79 | 97 | ||
80 | int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr) | 98 | int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr) |
81 | { | 99 | { |
100 | struct mlx5_mr_table *table = &dev->priv.mr_table; | ||
82 | struct mlx5_destroy_mkey_mbox_in in; | 101 | struct mlx5_destroy_mkey_mbox_in in; |
83 | struct mlx5_destroy_mkey_mbox_out out; | 102 | struct mlx5_destroy_mkey_mbox_out out; |
103 | unsigned long flags; | ||
84 | int err; | 104 | int err; |
85 | 105 | ||
86 | memset(&in, 0, sizeof(in)); | 106 | memset(&in, 0, sizeof(in)); |
@@ -95,6 +115,10 @@ int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr) | |||
95 | if (out.hdr.status) | 115 | if (out.hdr.status) |
96 | return mlx5_cmd_status_to_err(&out.hdr); | 116 | return mlx5_cmd_status_to_err(&out.hdr); |
97 | 117 | ||
118 | write_lock_irqsave(&table->lock, flags); | ||
119 | radix_tree_delete(&table->tree, mlx5_base_mkey(mr->key)); | ||
120 | write_unlock_irqrestore(&table->lock, flags); | ||
121 | |||
98 | return err; | 122 | return err; |
99 | } | 123 | } |
100 | EXPORT_SYMBOL(mlx5_core_destroy_mkey); | 124 | EXPORT_SYMBOL(mlx5_core_destroy_mkey); |
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index e1cb657ccade..e562e01e59c7 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h | |||
@@ -491,6 +491,13 @@ struct mlx5_srq_table { | |||
491 | struct radix_tree_root tree; | 491 | struct radix_tree_root tree; |
492 | }; | 492 | }; |
493 | 493 | ||
494 | struct mlx5_mr_table { | ||
495 | /* protect radix tree | ||
496 | */ | ||
497 | rwlock_t lock; | ||
498 | struct radix_tree_root tree; | ||
499 | }; | ||
500 | |||
494 | struct mlx5_priv { | 501 | struct mlx5_priv { |
495 | char name[MLX5_MAX_NAME_LEN]; | 502 | char name[MLX5_MAX_NAME_LEN]; |
496 | struct mlx5_eq_table eq_table; | 503 | struct mlx5_eq_table eq_table; |
@@ -520,6 +527,10 @@ struct mlx5_priv { | |||
520 | struct mlx5_cq_table cq_table; | 527 | struct mlx5_cq_table cq_table; |
521 | /* end: cq staff */ | 528 | /* end: cq staff */ |
522 | 529 | ||
530 | /* start: mr staff */ | ||
531 | struct mlx5_mr_table mr_table; | ||
532 | /* end: mr staff */ | ||
533 | |||
523 | /* start: alloc staff */ | 534 | /* start: alloc staff */ |
524 | struct mutex pgdir_mutex; | 535 | struct mutex pgdir_mutex; |
525 | struct list_head pgdir_list; | 536 | struct list_head pgdir_list; |
@@ -667,6 +678,11 @@ static inline void mlx5_vfree(const void *addr) | |||
667 | kfree(addr); | 678 | kfree(addr); |
668 | } | 679 | } |
669 | 680 | ||
681 | static inline u32 mlx5_base_mkey(const u32 key) | ||
682 | { | ||
683 | return key & 0xffffff00u; | ||
684 | } | ||
685 | |||
670 | int mlx5_dev_init(struct mlx5_core_dev *dev, struct pci_dev *pdev); | 686 | int mlx5_dev_init(struct mlx5_core_dev *dev, struct pci_dev *pdev); |
671 | void mlx5_dev_cleanup(struct mlx5_core_dev *dev); | 687 | void mlx5_dev_cleanup(struct mlx5_core_dev *dev); |
672 | int mlx5_cmd_init(struct mlx5_core_dev *dev); | 688 | int mlx5_cmd_init(struct mlx5_core_dev *dev); |
@@ -701,6 +717,8 @@ int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq, | |||
701 | struct mlx5_query_srq_mbox_out *out); | 717 | struct mlx5_query_srq_mbox_out *out); |
702 | int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq, | 718 | int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq, |
703 | u16 lwm, int is_srq); | 719 | u16 lwm, int is_srq); |
720 | void mlx5_init_mr_table(struct mlx5_core_dev *dev); | ||
721 | void mlx5_cleanup_mr_table(struct mlx5_core_dev *dev); | ||
704 | int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, | 722 | int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, |
705 | struct mlx5_create_mkey_mbox_in *in, int inlen, | 723 | struct mlx5_create_mkey_mbox_in *in, int inlen, |
706 | mlx5_cmd_cbk_t callback, void *context, | 724 | mlx5_cmd_cbk_t callback, void *context, |