This source file includes following definitions.
- mlx5_devlink_flash_update
- mlx5_fw_ver_major
- mlx5_fw_ver_minor
- mlx5_fw_ver_subminor
- mlx5_devlink_info_get
- mlx5_devlink_alloc
- mlx5_devlink_free
- mlx5_devlink_fs_mode_validate
- mlx5_devlink_fs_mode_set
- mlx5_devlink_fs_mode_get
- mlx5_devlink_set_params_init_values
- mlx5_devlink_register
- mlx5_devlink_unregister
1
2
3
4 #include <devlink.h>
5
6 #include "mlx5_core.h"
7 #include "fs_core.h"
8 #include "eswitch.h"
9
10 static int mlx5_devlink_flash_update(struct devlink *devlink,
11 const char *file_name,
12 const char *component,
13 struct netlink_ext_ack *extack)
14 {
15 struct mlx5_core_dev *dev = devlink_priv(devlink);
16 const struct firmware *fw;
17 int err;
18
19 if (component)
20 return -EOPNOTSUPP;
21
22 err = request_firmware_direct(&fw, file_name, &dev->pdev->dev);
23 if (err)
24 return err;
25
26 err = mlx5_firmware_flash(dev, fw, extack);
27 release_firmware(fw);
28
29 return err;
30 }
31
32 static u8 mlx5_fw_ver_major(u32 version)
33 {
34 return (version >> 24) & 0xff;
35 }
36
37 static u8 mlx5_fw_ver_minor(u32 version)
38 {
39 return (version >> 16) & 0xff;
40 }
41
42 static u16 mlx5_fw_ver_subminor(u32 version)
43 {
44 return version & 0xffff;
45 }
46
47 #define DEVLINK_FW_STRING_LEN 32
48
49 static int
50 mlx5_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
51 struct netlink_ext_ack *extack)
52 {
53 struct mlx5_core_dev *dev = devlink_priv(devlink);
54 char version_str[DEVLINK_FW_STRING_LEN];
55 u32 running_fw, stored_fw;
56 int err;
57
58 err = devlink_info_driver_name_put(req, DRIVER_NAME);
59 if (err)
60 return err;
61
62 err = devlink_info_version_fixed_put(req, "fw.psid", dev->board_id);
63 if (err)
64 return err;
65
66 err = mlx5_fw_version_query(dev, &running_fw, &stored_fw);
67 if (err)
68 return err;
69
70 snprintf(version_str, sizeof(version_str), "%d.%d.%04d",
71 mlx5_fw_ver_major(running_fw), mlx5_fw_ver_minor(running_fw),
72 mlx5_fw_ver_subminor(running_fw));
73 err = devlink_info_version_running_put(req, "fw.version", version_str);
74 if (err)
75 return err;
76
77
78 if (stored_fw == 0)
79 stored_fw = running_fw;
80
81 snprintf(version_str, sizeof(version_str), "%d.%d.%04d",
82 mlx5_fw_ver_major(stored_fw), mlx5_fw_ver_minor(stored_fw),
83 mlx5_fw_ver_subminor(stored_fw));
84 err = devlink_info_version_stored_put(req, "fw.version", version_str);
85 if (err)
86 return err;
87
88 return 0;
89 }
90
91 static const struct devlink_ops mlx5_devlink_ops = {
92 #ifdef CONFIG_MLX5_ESWITCH
93 .eswitch_mode_set = mlx5_devlink_eswitch_mode_set,
94 .eswitch_mode_get = mlx5_devlink_eswitch_mode_get,
95 .eswitch_inline_mode_set = mlx5_devlink_eswitch_inline_mode_set,
96 .eswitch_inline_mode_get = mlx5_devlink_eswitch_inline_mode_get,
97 .eswitch_encap_mode_set = mlx5_devlink_eswitch_encap_mode_set,
98 .eswitch_encap_mode_get = mlx5_devlink_eswitch_encap_mode_get,
99 #endif
100 .flash_update = mlx5_devlink_flash_update,
101 .info_get = mlx5_devlink_info_get,
102 };
103
104 struct devlink *mlx5_devlink_alloc(void)
105 {
106 return devlink_alloc(&mlx5_devlink_ops, sizeof(struct mlx5_core_dev));
107 }
108
109 void mlx5_devlink_free(struct devlink *devlink)
110 {
111 devlink_free(devlink);
112 }
113
114 static int mlx5_devlink_fs_mode_validate(struct devlink *devlink, u32 id,
115 union devlink_param_value val,
116 struct netlink_ext_ack *extack)
117 {
118 struct mlx5_core_dev *dev = devlink_priv(devlink);
119 char *value = val.vstr;
120 int err = 0;
121
122 if (!strcmp(value, "dmfs")) {
123 return 0;
124 } else if (!strcmp(value, "smfs")) {
125 u8 eswitch_mode;
126 bool smfs_cap;
127
128 eswitch_mode = mlx5_eswitch_mode(dev->priv.eswitch);
129 smfs_cap = mlx5_fs_dr_is_supported(dev);
130
131 if (!smfs_cap) {
132 err = -EOPNOTSUPP;
133 NL_SET_ERR_MSG_MOD(extack,
134 "Software managed steering is not supported by current device");
135 }
136
137 else if (eswitch_mode == MLX5_ESWITCH_OFFLOADS) {
138 NL_SET_ERR_MSG_MOD(extack,
139 "Software managed steering is not supported when eswitch offloads enabled.");
140 err = -EOPNOTSUPP;
141 }
142 } else {
143 NL_SET_ERR_MSG_MOD(extack,
144 "Bad parameter: supported values are [\"dmfs\", \"smfs\"]");
145 err = -EINVAL;
146 }
147
148 return err;
149 }
150
151 static int mlx5_devlink_fs_mode_set(struct devlink *devlink, u32 id,
152 struct devlink_param_gset_ctx *ctx)
153 {
154 struct mlx5_core_dev *dev = devlink_priv(devlink);
155 enum mlx5_flow_steering_mode mode;
156
157 if (!strcmp(ctx->val.vstr, "smfs"))
158 mode = MLX5_FLOW_STEERING_MODE_SMFS;
159 else
160 mode = MLX5_FLOW_STEERING_MODE_DMFS;
161 dev->priv.steering->mode = mode;
162
163 return 0;
164 }
165
166 static int mlx5_devlink_fs_mode_get(struct devlink *devlink, u32 id,
167 struct devlink_param_gset_ctx *ctx)
168 {
169 struct mlx5_core_dev *dev = devlink_priv(devlink);
170
171 if (dev->priv.steering->mode == MLX5_FLOW_STEERING_MODE_SMFS)
172 strcpy(ctx->val.vstr, "smfs");
173 else
174 strcpy(ctx->val.vstr, "dmfs");
175 return 0;
176 }
177
178 enum mlx5_devlink_param_id {
179 MLX5_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
180 MLX5_DEVLINK_PARAM_FLOW_STEERING_MODE,
181 };
182
183 static const struct devlink_param mlx5_devlink_params[] = {
184 DEVLINK_PARAM_DRIVER(MLX5_DEVLINK_PARAM_FLOW_STEERING_MODE,
185 "flow_steering_mode", DEVLINK_PARAM_TYPE_STRING,
186 BIT(DEVLINK_PARAM_CMODE_RUNTIME),
187 mlx5_devlink_fs_mode_get, mlx5_devlink_fs_mode_set,
188 mlx5_devlink_fs_mode_validate),
189 };
190
191 static void mlx5_devlink_set_params_init_values(struct devlink *devlink)
192 {
193 struct mlx5_core_dev *dev = devlink_priv(devlink);
194 union devlink_param_value value;
195
196 if (dev->priv.steering->mode == MLX5_FLOW_STEERING_MODE_DMFS)
197 strcpy(value.vstr, "dmfs");
198 else
199 strcpy(value.vstr, "smfs");
200 devlink_param_driverinit_value_set(devlink,
201 MLX5_DEVLINK_PARAM_FLOW_STEERING_MODE,
202 value);
203 }
204
205 int mlx5_devlink_register(struct devlink *devlink, struct device *dev)
206 {
207 int err;
208
209 err = devlink_register(devlink, dev);
210 if (err)
211 return err;
212
213 err = devlink_params_register(devlink, mlx5_devlink_params,
214 ARRAY_SIZE(mlx5_devlink_params));
215 if (err)
216 goto params_reg_err;
217 mlx5_devlink_set_params_init_values(devlink);
218 devlink_params_publish(devlink);
219 return 0;
220
221 params_reg_err:
222 devlink_unregister(devlink);
223 return err;
224 }
225
226 void mlx5_devlink_unregister(struct devlink *devlink)
227 {
228 devlink_params_unregister(devlink, mlx5_devlink_params,
229 ARRAY_SIZE(mlx5_devlink_params));
230 devlink_unregister(devlink);
231 }