This source file includes following definitions.
- mlx5e_create_tir
- mlx5e_destroy_tir
- mlx5e_create_mkey
- mlx5e_create_mdev_resources
- mlx5e_destroy_mdev_resources
- mlx5e_refresh_tirs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include "en.h"
34
35
36
37
38
39 int mlx5e_create_tir(struct mlx5_core_dev *mdev,
40 struct mlx5e_tir *tir, u32 *in, int inlen)
41 {
42 int err;
43
44 err = mlx5_core_create_tir(mdev, in, inlen, &tir->tirn);
45 if (err)
46 return err;
47
48 mutex_lock(&mdev->mlx5e_res.td.list_lock);
49 list_add(&tir->list, &mdev->mlx5e_res.td.tirs_list);
50 mutex_unlock(&mdev->mlx5e_res.td.list_lock);
51
52 return 0;
53 }
54
55 void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
56 struct mlx5e_tir *tir)
57 {
58 mutex_lock(&mdev->mlx5e_res.td.list_lock);
59 mlx5_core_destroy_tir(mdev, tir->tirn);
60 list_del(&tir->list);
61 mutex_unlock(&mdev->mlx5e_res.td.list_lock);
62 }
63
64 static int mlx5e_create_mkey(struct mlx5_core_dev *mdev, u32 pdn,
65 struct mlx5_core_mkey *mkey)
66 {
67 int inlen = MLX5_ST_SZ_BYTES(create_mkey_in);
68 void *mkc;
69 u32 *in;
70 int err;
71
72 in = kvzalloc(inlen, GFP_KERNEL);
73 if (!in)
74 return -ENOMEM;
75
76 mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry);
77 MLX5_SET(mkc, mkc, access_mode_1_0, MLX5_MKC_ACCESS_MODE_PA);
78 MLX5_SET(mkc, mkc, lw, 1);
79 MLX5_SET(mkc, mkc, lr, 1);
80
81 MLX5_SET(mkc, mkc, pd, pdn);
82 MLX5_SET(mkc, mkc, length64, 1);
83 MLX5_SET(mkc, mkc, qpn, 0xffffff);
84
85 err = mlx5_core_create_mkey(mdev, mkey, in, inlen);
86
87 kvfree(in);
88 return err;
89 }
90
91 int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev)
92 {
93 struct mlx5e_resources *res = &mdev->mlx5e_res;
94 int err;
95
96 err = mlx5_core_alloc_pd(mdev, &res->pdn);
97 if (err) {
98 mlx5_core_err(mdev, "alloc pd failed, %d\n", err);
99 return err;
100 }
101
102 err = mlx5_core_alloc_transport_domain(mdev, &res->td.tdn);
103 if (err) {
104 mlx5_core_err(mdev, "alloc td failed, %d\n", err);
105 goto err_dealloc_pd;
106 }
107
108 err = mlx5e_create_mkey(mdev, res->pdn, &res->mkey);
109 if (err) {
110 mlx5_core_err(mdev, "create mkey failed, %d\n", err);
111 goto err_dealloc_transport_domain;
112 }
113
114 err = mlx5_alloc_bfreg(mdev, &res->bfreg, false, false);
115 if (err) {
116 mlx5_core_err(mdev, "alloc bfreg failed, %d\n", err);
117 goto err_destroy_mkey;
118 }
119
120 INIT_LIST_HEAD(&mdev->mlx5e_res.td.tirs_list);
121 mutex_init(&mdev->mlx5e_res.td.list_lock);
122
123 return 0;
124
125 err_destroy_mkey:
126 mlx5_core_destroy_mkey(mdev, &res->mkey);
127 err_dealloc_transport_domain:
128 mlx5_core_dealloc_transport_domain(mdev, res->td.tdn);
129 err_dealloc_pd:
130 mlx5_core_dealloc_pd(mdev, res->pdn);
131 return err;
132 }
133
134 void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev)
135 {
136 struct mlx5e_resources *res = &mdev->mlx5e_res;
137
138 mlx5_free_bfreg(mdev, &res->bfreg);
139 mlx5_core_destroy_mkey(mdev, &res->mkey);
140 mlx5_core_dealloc_transport_domain(mdev, res->td.tdn);
141 mlx5_core_dealloc_pd(mdev, res->pdn);
142 memset(res, 0, sizeof(*res));
143 }
144
145 int mlx5e_refresh_tirs(struct mlx5e_priv *priv, bool enable_uc_lb)
146 {
147 struct mlx5_core_dev *mdev = priv->mdev;
148 struct mlx5e_tir *tir;
149 int err = 0;
150 u32 tirn = 0;
151 int inlen;
152 void *in;
153
154 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
155 in = kvzalloc(inlen, GFP_KERNEL);
156 if (!in) {
157 err = -ENOMEM;
158 goto out;
159 }
160
161 if (enable_uc_lb)
162 MLX5_SET(modify_tir_in, in, ctx.self_lb_block,
163 MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST);
164
165 MLX5_SET(modify_tir_in, in, bitmask.self_lb_en, 1);
166
167 mutex_lock(&mdev->mlx5e_res.td.list_lock);
168 list_for_each_entry(tir, &mdev->mlx5e_res.td.tirs_list, list) {
169 tirn = tir->tirn;
170 err = mlx5_core_modify_tir(mdev, tirn, in, inlen);
171 if (err)
172 goto out;
173 }
174
175 out:
176 kvfree(in);
177 if (err)
178 netdev_err(priv->netdev, "refresh tir(0x%x) failed, %d\n", tirn, err);
179 mutex_unlock(&mdev->mlx5e_res.td.list_lock);
180
181 return err;
182 }