Debian Codegraph @

drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c

raw
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
3
4 #include <linux/if_vlan.h>
5
6 #include "hinic3_hwdev.h"
7 #include "hinic3_hwif.h"
8 #include "hinic3_mbox.h"
9 #include "hinic3_nic_cfg.h"
10 #include "hinic3_nic_dev.h"
11 #include "hinic3_nic_io.h"
12
13 #define MGMT_MSG_CMD_OP_ADD 1
14 #define MGMT_MSG_CMD_OP_DEL 0
15
16 static int hinic3_feature_nego(struct hinic3_hwdev *hwdev, u8 opcode,
17 u64 *s_feature, u16 size)
18 {
19 struct l2nic_cmd_feature_nego feature_nego = {};
20 struct mgmt_msg_params msg_params = {};
21 int err;
22
23 feature_nego.func_id = hinic3_global_func_id(hwdev);
24 feature_nego.opcode = opcode;
25 if (opcode == MGMT_MSG_CMD_OP_SET)
26 memcpy(feature_nego.s_feature, s_feature,
27 array_size(size, sizeof(u64)));
28
29 mgmt_msg_params_init_default(&msg_params, &feature_nego,
30 sizeof(feature_nego));
31
32 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
33 L2NIC_CMD_FEATURE_NEGO, &msg_params);
34 if (err || feature_nego.msg_head.status) {
35 dev_err(hwdev->dev, "Failed to negotiate nic feature, err:%d, status: 0x%x\n",
36 err, feature_nego.msg_head.status);
37 return -EIO;
38 }
39
40 if (opcode == MGMT_MSG_CMD_OP_GET)
41 memcpy(s_feature, feature_nego.s_feature,
42 array_size(size, sizeof(u64)));
43
44 return 0;
45 }
46
47 int hinic3_get_nic_feature_from_hw(struct hinic3_nic_dev *nic_dev)
48 {
49 return hinic3_feature_nego(nic_dev->hwdev, MGMT_MSG_CMD_OP_GET,
50 &nic_dev->nic_io->feature_cap, 1);
51 }
52
53 int hinic3_set_nic_feature_to_hw(struct hinic3_nic_dev *nic_dev)
54 {
55 return hinic3_feature_nego(nic_dev->hwdev, MGMT_MSG_CMD_OP_SET,
56 &nic_dev->nic_io->feature_cap, 1);
57 }
58
59 bool hinic3_test_support(struct hinic3_nic_dev *nic_dev,
60 enum hinic3_nic_feature_cap feature_bits)
61 {
62 return (nic_dev->nic_io->feature_cap & feature_bits) == feature_bits;
63 }
64
65 static int hinic3_set_rx_lro(struct hinic3_hwdev *hwdev, u8 ipv4_en, u8 ipv6_en,
66 u8 lro_max_pkt_len)
67 {
68 struct l2nic_cmd_lro_config lro_cfg = {};
69 struct mgmt_msg_params msg_params = {};
70 int err;
71
72 lro_cfg.func_id = hinic3_global_func_id(hwdev);
73 lro_cfg.opcode = MGMT_MSG_CMD_OP_SET;
74 lro_cfg.lro_ipv4_en = ipv4_en;
75 lro_cfg.lro_ipv6_en = ipv6_en;
76 lro_cfg.lro_max_pkt_len = lro_max_pkt_len;
77
78 mgmt_msg_params_init_default(&msg_params, &lro_cfg,
79 sizeof(lro_cfg));
80
81 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
82 L2NIC_CMD_CFG_RX_LRO,
83 &msg_params);
84
85 if (err || lro_cfg.msg_head.status) {
86 dev_err(hwdev->dev, "Failed to set lro offload, err: %d, status: 0x%x\n",
87 err, lro_cfg.msg_head.status);
88 return -EFAULT;
89 }
90
91 return 0;
92 }
93
94 static int hinic3_set_rx_lro_timer(struct hinic3_hwdev *hwdev, u32 timer_value)
95 {
96 struct l2nic_cmd_lro_timer lro_timer = {};
97 struct mgmt_msg_params msg_params = {};
98 int err;
99
100 lro_timer.opcode = MGMT_MSG_CMD_OP_SET;
101 lro_timer.timer = timer_value;
102
103 mgmt_msg_params_init_default(&msg_params, &lro_timer,
104 sizeof(lro_timer));
105
106 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
107 L2NIC_CMD_CFG_LRO_TIMER,
108 &msg_params);
109
110 if (err || lro_timer.msg_head.status) {
111 dev_err(hwdev->dev, "Failed to set lro timer, err: %d, status: 0x%x\n",
112 err, lro_timer.msg_head.status);
113
114 return -EFAULT;
115 }
116
117 return 0;
118 }
119
120 int hinic3_set_rx_lro_state(struct hinic3_hwdev *hwdev, u8 lro_en,
121 u32 lro_timer, u8 lro_max_pkt_len)
122 {
123 u8 ipv4_en, ipv6_en;
124 int err;
125
126 ipv4_en = lro_en ? 1 : 0;
127 ipv6_en = lro_en ? 1 : 0;
128
129 dev_dbg(hwdev->dev, "Set LRO max coalesce packet size to %uK\n",
130 lro_max_pkt_len);
131
132 err = hinic3_set_rx_lro(hwdev, ipv4_en, ipv6_en, lro_max_pkt_len);
133 if (err)
134 return err;
135
136 /* we don't set LRO timer for VF */
137 if (HINIC3_IS_VF(hwdev))
138 return 0;
139
140 dev_dbg(hwdev->dev, "Set LRO timer to %u\n", lro_timer);
141
142 return hinic3_set_rx_lro_timer(hwdev, lro_timer);
143 }
144
145 int hinic3_set_rx_vlan_offload(struct hinic3_hwdev *hwdev, u8 en)
146 {
147 struct l2nic_cmd_vlan_offload vlan_cfg = {};
148 struct mgmt_msg_params msg_params = {};
149 int err;
150
151 vlan_cfg.func_id = hinic3_global_func_id(hwdev);
152 vlan_cfg.vlan_offload = en;
153
154 mgmt_msg_params_init_default(&msg_params, &vlan_cfg,
155 sizeof(vlan_cfg));
156
157 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
158 L2NIC_CMD_SET_RX_VLAN_OFFLOAD,
159 &msg_params);
160
161 if (err || vlan_cfg.msg_head.status) {
162 dev_err(hwdev->dev, "Failed to set rx vlan offload, err: %d, status: 0x%x\n",
163 err, vlan_cfg.msg_head.status);
164 return -EFAULT;
165 }
166
167 return 0;
168 }
169
170 int hinic3_set_vlan_filter(struct hinic3_hwdev *hwdev, u32 vlan_filter_ctrl)
171 {
172 struct l2nic_cmd_set_vlan_filter vlan_filter = {};
173 struct mgmt_msg_params msg_params = {};
174 int err;
175
176 vlan_filter.func_id = hinic3_global_func_id(hwdev);
177 vlan_filter.vlan_filter_ctrl = vlan_filter_ctrl;
178
179 mgmt_msg_params_init_default(&msg_params, &vlan_filter,
180 sizeof(vlan_filter));
181
182 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
183 L2NIC_CMD_SET_VLAN_FILTER_EN,
184 &msg_params);
185
186 if (err || vlan_filter.msg_head.status) {
187 dev_err(hwdev->dev, "Failed to set vlan filter, err: %d, status: 0x%x\n",
188 err, vlan_filter.msg_head.status);
189 return -EFAULT;
190 }
191
192 return 0;
193 }
194
195 void hinic3_update_nic_feature(struct hinic3_nic_dev *nic_dev, u64 feature_cap)
196 {
197 nic_dev->nic_io->feature_cap = feature_cap;
198 }
199
200 static int hinic3_set_function_table(struct hinic3_hwdev *hwdev, u32 cfg_bitmap,
201 const struct l2nic_func_tbl_cfg *cfg)
202 {
203 struct l2nic_cmd_set_func_tbl cmd_func_tbl = {};
204 struct mgmt_msg_params msg_params = {};
205 int err;
206
207 cmd_func_tbl.func_id = hinic3_global_func_id(hwdev);
208 cmd_func_tbl.cfg_bitmap = cfg_bitmap;
209 cmd_func_tbl.tbl_cfg = *cfg;
210
211 mgmt_msg_params_init_default(&msg_params, &cmd_func_tbl,
212 sizeof(cmd_func_tbl));
213
214 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
215 L2NIC_CMD_SET_FUNC_TBL, &msg_params);
216 if (err || cmd_func_tbl.msg_head.status) {
217 dev_err(hwdev->dev,
218 "Failed to set func table, bitmap: 0x%x, err: %d, status: 0x%x\n",
219 cfg_bitmap, err, cmd_func_tbl.msg_head.status);
220 return -EFAULT;
221 }
222
223 return 0;
224 }
225
226 int hinic3_init_function_table(struct hinic3_nic_dev *nic_dev)
227 {
228 struct hinic3_nic_io *nic_io = nic_dev->nic_io;
229 struct l2nic_func_tbl_cfg func_tbl_cfg = {};
230 u32 cfg_bitmap;
231
232 func_tbl_cfg.mtu = 0x3FFF; /* default, max mtu */
233 func_tbl_cfg.rx_wqe_buf_size = nic_io->rx_buf_len;
234
235 cfg_bitmap = BIT(L2NIC_FUNC_TBL_CFG_INIT) |
236 BIT(L2NIC_FUNC_TBL_CFG_MTU) |
237 BIT(L2NIC_FUNC_TBL_CFG_RX_BUF_SIZE);
238
239 return hinic3_set_function_table(nic_dev->hwdev, cfg_bitmap,
240 &func_tbl_cfg);
241 }
242
243 int hinic3_set_port_mtu(struct net_device *netdev, u16 new_mtu)
244 {
245 struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
246 struct l2nic_func_tbl_cfg func_tbl_cfg = {};
247 struct hinic3_hwdev *hwdev = nic_dev->hwdev;
248
249 func_tbl_cfg.mtu = new_mtu;
250
251 return hinic3_set_function_table(hwdev, BIT(L2NIC_FUNC_TBL_CFG_MTU),
252 &func_tbl_cfg);
253 }
254
255 static bool hinic3_check_vf_set_by_pf(struct hinic3_hwdev *hwdev,
256 u8 status)
257 {
258 return HINIC3_IS_VF(hwdev) && status == HINIC3_PF_SET_VF_ALREADY;
259 }
260
261 static int hinic3_check_mac_info(struct hinic3_hwdev *hwdev, u8 status,
262 u16 vlan_id)
263 {
264 if ((status && status != MGMT_STATUS_EXIST) ||
265 ((vlan_id & BIT(15)) && status == MGMT_STATUS_EXIST)) {
266 if (hinic3_check_vf_set_by_pf(hwdev, status))
267 return 0;
268
269 return -EINVAL;
270 }
271
272 return 0;
273 }
274
275 int hinic3_get_default_mac(struct hinic3_hwdev *hwdev, u8 *mac_addr)
276 {
277 struct l2nic_cmd_set_mac mac_info = {};
278 struct mgmt_msg_params msg_params = {};
279 int err;
280
281 mac_info.func_id = hinic3_global_func_id(hwdev);
282
283 mgmt_msg_params_init_default(&msg_params, &mac_info, sizeof(mac_info));
284
285 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
286 L2NIC_CMD_GET_MAC,
287 &msg_params);
288
289 if (err || mac_info.msg_head.status) {
290 dev_err(hwdev->dev,
291 "Failed to get mac, err: %d, status: 0x%x\n",
292 err, mac_info.msg_head.status);
293 return -EFAULT;
294 }
295
296 ether_addr_copy(mac_addr, mac_info.mac);
297
298 return 0;
299 }
300
301 int hinic3_set_mac(struct hinic3_hwdev *hwdev, const u8 *mac_addr, u16 vlan_id,
302 u16 func_id)
303 {
304 struct l2nic_cmd_set_mac mac_info = {};
305 struct mgmt_msg_params msg_params = {};
306 int err;
307
308 if ((vlan_id & HINIC3_VLAN_ID_MASK) >= VLAN_N_VID) {
309 dev_err(hwdev->dev, "Invalid VLAN number: %d\n",
310 (vlan_id & HINIC3_VLAN_ID_MASK));
311 return -EINVAL;
312 }
313
314 mac_info.func_id = func_id;
315 mac_info.vlan_id = vlan_id;
316 ether_addr_copy(mac_info.mac, mac_addr);
317
318 mgmt_msg_params_init_default(&msg_params, &mac_info, sizeof(mac_info));
319
320 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
321 L2NIC_CMD_SET_MAC, &msg_params);
322 if (err || hinic3_check_mac_info(hwdev, mac_info.msg_head.status,
323 mac_info.vlan_id)) {
324 dev_err(hwdev->dev,
325 "Failed to update MAC, err: %d, status: 0x%x\n",
326 err, mac_info.msg_head.status);
327 return -EIO;
328 }
329
330 if (hinic3_check_vf_set_by_pf(hwdev, mac_info.msg_head.status)) {
331 dev_warn(hwdev->dev, "PF has already set VF mac, Ignore set operation\n");
332 return -EADDRINUSE;
333 }
334
335 if (mac_info.msg_head.status == MGMT_STATUS_EXIST) {
336 dev_warn(hwdev->dev, "MAC is repeated. Ignore update operation\n");
337 return 0;
338 }
339
340 return 0;
341 }
342
343 int hinic3_del_mac(struct hinic3_hwdev *hwdev, const u8 *mac_addr, u16 vlan_id,
344 u16 func_id)
345 {
346 struct l2nic_cmd_set_mac mac_info = {};
347 struct mgmt_msg_params msg_params = {};
348 int err;
349
350 if ((vlan_id & HINIC3_VLAN_ID_MASK) >= VLAN_N_VID) {
351 dev_err(hwdev->dev, "Invalid VLAN number: %d\n",
352 (vlan_id & HINIC3_VLAN_ID_MASK));
353 return -EINVAL;
354 }
355
356 mac_info.func_id = func_id;
357 mac_info.vlan_id = vlan_id;
358 ether_addr_copy(mac_info.mac, mac_addr);
359
360 mgmt_msg_params_init_default(&msg_params, &mac_info, sizeof(mac_info));
361
362 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
363 L2NIC_CMD_DEL_MAC, &msg_params);
364 if (err ||
365 (mac_info.msg_head.status &&
366 !hinic3_check_vf_set_by_pf(hwdev, mac_info.msg_head.status))) {
367 dev_err(hwdev->dev,
368 "Failed to delete MAC, err: %d, status: 0x%x\n",
369 err, mac_info.msg_head.status);
370 return -EFAULT;
371 }
372
373 if (hinic3_check_vf_set_by_pf(hwdev, mac_info.msg_head.status)) {
374 dev_warn(hwdev->dev, "PF has already set VF mac, Ignore delete operation.\n");
375 return -EADDRINUSE;
376 }
377
378 return 0;
379 }
380
381 int hinic3_update_mac(struct hinic3_hwdev *hwdev, const u8 *old_mac,
382 u8 *new_mac, u16 vlan_id, u16 func_id)
383 {
384 struct l2nic_cmd_update_mac mac_info = {};
385 struct mgmt_msg_params msg_params = {};
386 int err;
387
388 if ((vlan_id & HINIC3_VLAN_ID_MASK) >= VLAN_N_VID) {
389 dev_err(hwdev->dev, "Invalid VLAN number: %d\n",
390 (vlan_id & HINIC3_VLAN_ID_MASK));
391 return -EINVAL;
392 }
393
394 mac_info.func_id = func_id;
395 mac_info.vlan_id = vlan_id;
396 ether_addr_copy(mac_info.old_mac, old_mac);
397 ether_addr_copy(mac_info.new_mac, new_mac);
398
399 mgmt_msg_params_init_default(&msg_params, &mac_info, sizeof(mac_info));
400
401 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
402 L2NIC_CMD_UPDATE_MAC, &msg_params);
403 if (err || hinic3_check_mac_info(hwdev, mac_info.msg_head.status,
404 mac_info.vlan_id)) {
405 dev_err(hwdev->dev,
406 "Failed to update MAC, err: %d, status: 0x%x\n",
407 err, mac_info.msg_head.status);
408 return -EIO;
409 }
410
411 if (hinic3_check_vf_set_by_pf(hwdev, mac_info.msg_head.status)) {
412 dev_warn(hwdev->dev, "PF has already set VF MAC. Ignore update operation\n");
413 return -EADDRINUSE;
414 }
415
416 if (mac_info.msg_head.status == HINIC3_MGMT_STATUS_EXIST) {
417 dev_warn(hwdev->dev,
418 "MAC is repeated. Ignore update operation\n");
419 return 0;
420 }
421
422 return 0;
423 }
424
425 int hinic3_set_ci_table(struct hinic3_hwdev *hwdev, struct hinic3_sq_attr *attr)
426 {
427 struct l2nic_cmd_set_ci_attr cons_idx_attr = {};
428 struct mgmt_msg_params msg_params = {};
429 int err;
430
431 cons_idx_attr.func_idx = hinic3_global_func_id(hwdev);
432 cons_idx_attr.dma_attr_off = attr->dma_attr_off;
433 cons_idx_attr.pending_limit = attr->pending_limit;
434 cons_idx_attr.coalescing_time = attr->coalescing_time;
435
436 if (attr->intr_en) {
437 cons_idx_attr.intr_en = attr->intr_en;
438 cons_idx_attr.intr_idx = attr->intr_idx;
439 }
440
441 cons_idx_attr.l2nic_sqn = attr->l2nic_sqn;
442 cons_idx_attr.ci_addr = attr->ci_dma_base;
443
444 mgmt_msg_params_init_default(&msg_params, &cons_idx_attr,
445 sizeof(cons_idx_attr));
446
447 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
448 L2NIC_CMD_SET_SQ_CI_ATTR, &msg_params);
449 if (err || cons_idx_attr.msg_head.status) {
450 dev_err(hwdev->dev,
451 "Failed to set ci attribute table, err: %d, status: 0x%x\n",
452 err, cons_idx_attr.msg_head.status);
453 return -EFAULT;
454 }
455
456 return 0;
457 }
458
459 int hinic3_flush_qps_res(struct hinic3_hwdev *hwdev)
460 {
461 struct l2nic_cmd_clear_qp_resource sq_res = {};
462 struct mgmt_msg_params msg_params = {};
463 int err;
464
465 sq_res.func_id = hinic3_global_func_id(hwdev);
466
467 mgmt_msg_params_init_default(&msg_params, &sq_res, sizeof(sq_res));
468
469 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
470 L2NIC_CMD_CLEAR_QP_RESOURCE,
471 &msg_params);
472 if (err || sq_res.msg_head.status) {
473 dev_err(hwdev->dev, "Failed to clear sq resources, err: %d, status: 0x%x\n",
474 err, sq_res.msg_head.status);
475 return -EINVAL;
476 }
477
478 return 0;
479 }
480
481 int hinic3_force_drop_tx_pkt(struct hinic3_hwdev *hwdev)
482 {
483 struct l2nic_cmd_force_pkt_drop pkt_drop = {};
484 struct mgmt_msg_params msg_params = {};
485 int err;
486
487 pkt_drop.port = hinic3_physical_port_id(hwdev);
488
489 mgmt_msg_params_init_default(&msg_params, &pkt_drop, sizeof(pkt_drop));
490
491 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
492 L2NIC_CMD_FORCE_PKT_DROP, &msg_params);
493 if ((pkt_drop.msg_head.status != MGMT_STATUS_CMD_UNSUPPORTED &&
494 pkt_drop.msg_head.status) || err) {
495 dev_err(hwdev->dev,
496 "Failed to set force tx packets drop, err: %d, status: 0x%x\n",
497 err, pkt_drop.msg_head.status);
498 return -EFAULT;
499 }
500
501 return pkt_drop.msg_head.status;
502 }
503
504 int hinic3_set_rx_mode(struct hinic3_hwdev *hwdev, u32 rx_mode)
505 {
506 struct l2nic_rx_mode_config rx_mode_cfg = {};
507 struct mgmt_msg_params msg_params = {};
508 int err;
509
510 rx_mode_cfg.func_id = hinic3_global_func_id(hwdev);
511 rx_mode_cfg.rx_mode = rx_mode;
512
513 mgmt_msg_params_init_default(&msg_params, &rx_mode_cfg,
514 sizeof(rx_mode_cfg));
515
516 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
517 L2NIC_CMD_SET_RX_MODE, &msg_params);
518
519 if (err || rx_mode_cfg.msg_head.status) {
520 dev_err(hwdev->dev, "Failed to set rx mode, err: %d, status: 0x%x\n",
521 err, rx_mode_cfg.msg_head.status);
522 return -EFAULT;
523 }
524
525 return 0;
526 }
527
528 static int hinic3_config_vlan(struct hinic3_hwdev *hwdev,
529 u8 opcode, u16 vlan_id, u16 func_id)
530 {
531 struct l2nic_cmd_vlan_config vlan_info = {};
532 struct mgmt_msg_params msg_params = {};
533 int err;
534
535 vlan_info.opcode = opcode;
536 vlan_info.func_id = func_id;
537 vlan_info.vlan_id = vlan_id;
538
539 mgmt_msg_params_init_default(&msg_params, &vlan_info,
540 sizeof(vlan_info));
541
542 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
543 L2NIC_CMD_CFG_FUNC_VLAN, &msg_params);
544
545 if (err || vlan_info.msg_head.status) {
546 dev_err(hwdev->dev,
547 "Failed to %s vlan, err: %d, status: 0x%x\n",
548 opcode == MGMT_MSG_CMD_OP_ADD ? "add" : "delete",
549 err, vlan_info.msg_head.status);
550 return -EFAULT;
551 }
552
553 return 0;
554 }
555
556 int hinic3_add_vlan(struct hinic3_hwdev *hwdev, u16 vlan_id, u16 func_id)
557 {
558 return hinic3_config_vlan(hwdev, MGMT_MSG_CMD_OP_ADD, vlan_id, func_id);
559 }
560
561 int hinic3_del_vlan(struct hinic3_hwdev *hwdev, u16 vlan_id, u16 func_id)
562 {
563 return hinic3_config_vlan(hwdev, MGMT_MSG_CMD_OP_DEL, vlan_id, func_id);
564 }
565
566 int hinic3_set_port_enable(struct hinic3_hwdev *hwdev, bool enable)
567 {
568 struct mag_cmd_set_port_enable en_state = {};
569 struct mgmt_msg_params msg_params = {};
570 int err;
571
572 if (HINIC3_IS_VF(hwdev))
573 return 0;
574
575 en_state.function_id = hinic3_global_func_id(hwdev);
576 en_state.state = enable ? MAG_CMD_TX_ENABLE | MAG_CMD_RX_ENABLE :
577 MAG_CMD_PORT_DISABLE;
578
579 mgmt_msg_params_init_default(&msg_params, &en_state,
580 sizeof(en_state));
581
582 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_HILINK,
583 MAG_CMD_SET_PORT_ENABLE, &msg_params);
584
585 if (err || en_state.head.status) {
586 dev_err(hwdev->dev, "Failed to set port state, err: %d, status: 0x%x\n",
587 err, en_state.head.status);
588 return -EFAULT;
589 }
590
591 return 0;
592 }
593
594 int hinic3_sync_dcb_state(struct hinic3_hwdev *hwdev, u8 op_code, u8 state)
595 {
596 struct l2nic_cmd_set_dcb_state dcb_state = {};
597 struct mgmt_msg_params msg_params = {};
598 int err;
599
600 dcb_state.op_code = op_code;
601 dcb_state.state = state;
602 dcb_state.func_id = hinic3_global_func_id(hwdev);
603
604 mgmt_msg_params_init_default(&msg_params, &dcb_state,
605 sizeof(dcb_state));
606
607 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
608 L2NIC_CMD_QOS_DCB_STATE, &msg_params);
609 if (err || dcb_state.head.status) {
610 dev_err(hwdev->dev,
611 "Failed to set dcb state, err: %d, status: 0x%x\n",
612 err, dcb_state.head.status);
613 return -EFAULT;
614 }
615
616 return 0;
617 }
618
619 int hinic3_get_link_status(struct hinic3_hwdev *hwdev, bool *link_status_up)
620 {
621 struct mag_cmd_get_link_status get_link = {};
622 struct mgmt_msg_params msg_params = {};
623 int err;
624
625 get_link.port_id = hinic3_physical_port_id(hwdev);
626
627 mgmt_msg_params_init_default(&msg_params, &get_link, sizeof(get_link));
628
629 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_HILINK,
630 MAG_CMD_GET_LINK_STATUS, &msg_params);
631 if (err || get_link.head.status) {
632 dev_err(hwdev->dev, "Failed to get link state, err: %d, status: 0x%x\n",
633 err, get_link.head.status);
634 return -EIO;
635 }
636
637 *link_status_up = !!get_link.status;
638
639 return 0;
640 }
641
642 int hinic3_set_vport_enable(struct hinic3_hwdev *hwdev, u16 func_id,
643 bool enable)
644 {
645 struct l2nic_cmd_set_vport_state en_state = {};
646 struct mgmt_msg_params msg_params = {};
647 int err;
648
649 en_state.func_id = func_id;
650 en_state.state = enable ? 1 : 0;
651
652 mgmt_msg_params_init_default(&msg_params, &en_state, sizeof(en_state));
653
654 err = hinic3_send_mbox_to_mgmt(hwdev, MGMT_MOD_L2NIC,
655 L2NIC_CMD_SET_VPORT_ENABLE, &msg_params);
656 if (err || en_state.msg_head.status) {
657 dev_err(hwdev->dev, "Failed to set vport state, err: %d, status: 0x%x\n",
658 err, en_state.msg_head.status);
659 return -EINVAL;
660 }
661
662 return 0;
663 }