1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Huawei Technologies Co., Ltd
5 #include "hinic_compat.h"
6 #include "hinic_pmd_hwdev.h"
7 #include "hinic_pmd_hwif.h"
8 #include "hinic_pmd_eqs.h"
9 #include "hinic_pmd_wq.h"
10 #include "hinic_pmd_mgmt.h"
11 #include "hinic_pmd_cmdq.h"
12 #include "hinic_pmd_niccfg.h"
13 #include "hinic_pmd_mbox.h"
15 #define l2nic_msg_to_mgmt_sync(hwdev, cmd, buf_in, \
16 in_size, buf_out, out_size) \
17 hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC, cmd, \
22 * hinic_init_function_table - Initialize function table.
25 * The hardware interface of a nic device.
27 * Receive buffer size.
31 * negative error value otherwise.
33 int hinic_init_function_table(void *hwdev, u16 rx_buf_sz)
35 struct hinic_function_table function_table;
36 u16 out_size = sizeof(function_table);
40 PMD_DRV_LOG(ERR, "Hwdev is NULL");
44 memset(&function_table, 0, sizeof(function_table));
45 function_table.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
46 function_table.func_id = hinic_global_func_id(hwdev);
47 function_table.mtu = 0x3FFF; /* default, max mtu */
48 function_table.rx_wqe_buf_size = rx_buf_sz;
50 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
51 HINIC_PORT_CMD_INIT_FUNC,
52 &function_table, sizeof(function_table),
53 &function_table, &out_size, 0);
54 if (err || function_table.mgmt_msg_head.status || !out_size) {
56 "Failed to init func table, err: %d, status: 0x%x, out size: 0x%x",
57 err, function_table.mgmt_msg_head.status, out_size);
65 * hinic_get_base_qpn - Get global queue number.
68 * The hardware interface of a nic device.
70 * Global queue number.
74 * negative error value otherwise.
76 int hinic_get_base_qpn(void *hwdev, u16 *global_qpn)
78 struct hinic_cmd_qpn cmd_qpn;
79 u16 out_size = sizeof(cmd_qpn);
82 if (!hwdev || !global_qpn) {
83 PMD_DRV_LOG(ERR, "Hwdev or global_qpn is NULL");
87 memset(&cmd_qpn, 0, sizeof(cmd_qpn));
88 cmd_qpn.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
89 cmd_qpn.func_id = hinic_global_func_id(hwdev);
91 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
92 HINIC_PORT_CMD_GET_GLOBAL_QPN,
93 &cmd_qpn, sizeof(cmd_qpn), &cmd_qpn,
95 if (err || !out_size || cmd_qpn.mgmt_msg_head.status) {
97 "Failed to get base qpn, err: %d, status: 0x%x, out size: 0x%x",
98 err, cmd_qpn.mgmt_msg_head.status, out_size);
102 *global_qpn = cmd_qpn.base_qpn;
108 * hinic_set_mac - Init mac_vlan table in NIC.
111 * The hardware interface of a nic device.
115 * Set 0 for mac_vlan table initialization.
117 * Global function id of NIC.
121 * negative error value otherwise.
123 int hinic_set_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
125 struct hinic_port_mac_set mac_info;
126 u16 out_size = sizeof(mac_info);
129 if (!hwdev || !mac_addr) {
130 PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
134 memset(&mac_info, 0, sizeof(mac_info));
135 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
136 mac_info.func_id = func_id;
137 mac_info.vlan_id = vlan_id;
138 memmove(mac_info.mac, mac_addr, ETH_ALEN);
140 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_MAC, &mac_info,
141 sizeof(mac_info), &mac_info, &out_size);
142 if (err || !out_size || (mac_info.mgmt_msg_head.status &&
143 mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
144 PMD_DRV_LOG(ERR, "Failed to set MAC, err: %d, status: 0x%x, out size: 0x%x",
145 err, mac_info.mgmt_msg_head.status, out_size);
149 if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
150 PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore set operation.");
151 return HINIC_PF_SET_VF_ALREADY;
158 * hinic_del_mac - Uninit mac_vlan table in NIC.
161 * The hardware interface of a nic device.
165 * Set 0 for mac_vlan table initialization.
167 * Global function id of NIC.
171 * negative error value otherwise.
173 int hinic_del_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
175 struct hinic_port_mac_set mac_info;
176 u16 out_size = sizeof(mac_info);
179 if (!hwdev || !mac_addr) {
180 PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
184 if (vlan_id >= VLAN_N_VID) {
185 PMD_DRV_LOG(ERR, "Invalid VLAN number");
189 memset(&mac_info, 0, sizeof(mac_info));
190 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
191 mac_info.func_id = func_id;
192 mac_info.vlan_id = vlan_id;
193 memmove(mac_info.mac, mac_addr, ETH_ALEN);
195 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_DEL_MAC, &mac_info,
196 sizeof(mac_info), &mac_info, &out_size);
197 if (err || !out_size || (mac_info.mgmt_msg_head.status &&
198 mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
199 PMD_DRV_LOG(ERR, "Failed to delete MAC, err: %d, status: 0x%x, out size: 0x%x",
200 err, mac_info.mgmt_msg_head.status, out_size);
203 if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
204 PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore delete operation.");
205 return HINIC_PF_SET_VF_ALREADY;
212 * hinic_get_default_mac - Get default mac address from hardware.
215 * The hardware interface of a nic device.
221 * negative error value otherwise.
223 int hinic_get_default_mac(void *hwdev, u8 *mac_addr)
225 struct hinic_port_mac_set mac_info;
226 u16 out_size = sizeof(mac_info);
229 if (!hwdev || !mac_addr) {
230 PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
234 memset(&mac_info, 0, sizeof(mac_info));
235 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
236 mac_info.func_id = hinic_global_func_id(hwdev);
238 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_MAC,
239 &mac_info, sizeof(mac_info),
240 &mac_info, &out_size);
241 if (err || !out_size || mac_info.mgmt_msg_head.status) {
242 PMD_DRV_LOG(ERR, "Failed to get mac, err: %d, status: 0x%x, out size: 0x%x",
243 err, mac_info.mgmt_msg_head.status, out_size);
247 memmove(mac_addr, mac_info.mac, ETH_ALEN);
253 * hinic_update_mac - Update mac address to hardware.
256 * The hardware interface of a nic device.
262 * Set 0 for mac_vlan table initialization.
264 * Global function id of NIC.
268 * negative error value otherwise.
270 int hinic_update_mac(void *hwdev, u8 *old_mac, u8 *new_mac, u16 vlan_id,
273 struct hinic_port_mac_update mac_info;
274 u16 out_size = sizeof(mac_info);
277 if (!hwdev || !old_mac || !new_mac) {
278 PMD_DRV_LOG(ERR, "Hwdev, old_mac or new_mac is NULL\n");
282 memset(&mac_info, 0, sizeof(mac_info));
283 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
284 mac_info.func_id = func_id;
285 mac_info.vlan_id = vlan_id;
286 memcpy(mac_info.old_mac, old_mac, ETH_ALEN);
287 memcpy(mac_info.new_mac, new_mac, ETH_ALEN);
289 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UPDATE_MAC,
290 &mac_info, sizeof(mac_info),
291 &mac_info, &out_size);
292 if (err || !out_size ||
293 (mac_info.mgmt_msg_head.status &&
294 mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
295 PMD_DRV_LOG(ERR, "Failed to update MAC, err: %d, status: 0x%x, out size: 0x%x\n",
296 err, mac_info.mgmt_msg_head.status, out_size);
299 if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
300 PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore update operation.\n");
301 return HINIC_PF_SET_VF_ALREADY;
308 * hinic_set_port_mtu - Set MTU to port.
311 * The hardware interface of a nic device.
317 * negative error value otherwise.
319 int hinic_set_port_mtu(void *hwdev, u32 new_mtu)
321 struct hinic_mtu mtu_info;
322 u16 out_size = sizeof(mtu_info);
326 PMD_DRV_LOG(ERR, "Hwdev is NULL");
330 memset(&mtu_info, 0, sizeof(mtu_info));
331 mtu_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
332 mtu_info.func_id = hinic_global_func_id(hwdev);
333 mtu_info.mtu = new_mtu;
335 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CHANGE_MTU,
336 &mtu_info, sizeof(mtu_info),
337 &mtu_info, &out_size);
338 if (err || !out_size || mtu_info.mgmt_msg_head.status) {
339 PMD_DRV_LOG(ERR, "Failed to set mtu, err: %d, status: 0x%x, out size: 0x%x",
340 err, mtu_info.mgmt_msg_head.status, out_size);
348 * hinic_add_remove_vlan - Add or remove vlan id to vlan elb table.
351 * The hardware interface of a nic device.
355 * Global function id of NIC.
357 * Add or remove operation.
361 * negative error value otherwise.
363 int hinic_add_remove_vlan(void *hwdev, u16 vlan_id, u16 func_id, bool add)
365 struct hinic_vlan_config vlan_info;
366 u16 out_size = sizeof(vlan_info);
371 PMD_DRV_LOG(ERR, "Hwdev is NULL");
375 cmd = add ? HINIC_PORT_CMD_ADD_VLAN : HINIC_PORT_CMD_DEL_VLAN;
377 memset(&vlan_info, 0, sizeof(vlan_info));
378 vlan_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
379 vlan_info.func_id = func_id;
380 vlan_info.vlan_id = vlan_id;
382 err = l2nic_msg_to_mgmt_sync(hwdev, cmd, &vlan_info,
383 sizeof(vlan_info), &vlan_info,
385 if (err || !out_size || vlan_info.mgmt_msg_head.status) {
387 "Failed to %s vlan, err: %d, status: 0x%x, out size: 0x%x\n",
388 add ? "add" : "remove", err,
389 vlan_info.mgmt_msg_head.status, out_size);
397 * hinic_config_vlan_filter - Enable or Disable vlan filter.
400 * The hardware interface of a nic device.
401 * @param vlan_filter_ctrl
406 * negative error value otherwise.
408 int hinic_config_vlan_filter(void *hwdev, u32 vlan_filter_ctrl)
410 struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
411 struct hinic_vlan_filter vlan_filter;
412 u16 out_size = sizeof(vlan_filter);
418 memset(&vlan_filter, 0, sizeof(vlan_filter));
419 vlan_filter.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
420 vlan_filter.func_id = hinic_global_func_id(nic_hwdev);
421 vlan_filter.vlan_filter_ctrl = vlan_filter_ctrl;
423 err = l2nic_msg_to_mgmt_sync(nic_hwdev, HINIC_PORT_CMD_SET_VLAN_FILTER,
424 &vlan_filter, sizeof(vlan_filter),
425 &vlan_filter, &out_size);
426 if (vlan_filter.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
427 err = HINIC_MGMT_CMD_UNSUPPORTED;
428 } else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
429 (HINIC_IS_VF(nic_hwdev))) {
430 err = HINIC_MGMT_CMD_UNSUPPORTED;
431 } else if (err || !out_size || vlan_filter.mgmt_msg_head.status) {
433 "Failed to config vlan filter, vlan_filter_ctrl: 0x%x, err: %d, status: 0x%x, out size: 0x%x\n",
434 vlan_filter_ctrl, err,
435 vlan_filter.mgmt_msg_head.status, out_size);
443 * hinic_set_rx_vlan_offload - Enable or Disable vlan offload.
446 * The hardware interface of a nic device.
452 * negative error value otherwise.
454 int hinic_set_rx_vlan_offload(void *hwdev, u8 en)
456 struct hinic_vlan_offload vlan_cfg;
457 u16 out_size = sizeof(vlan_cfg);
461 PMD_DRV_LOG(ERR, "Hwdev is NULL");
465 memset(&vlan_cfg, 0, sizeof(vlan_cfg));
466 vlan_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
467 vlan_cfg.func_id = hinic_global_func_id(hwdev);
468 vlan_cfg.vlan_rx_offload = en;
470 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_VLAN_OFFLOAD,
471 &vlan_cfg, sizeof(vlan_cfg),
472 &vlan_cfg, &out_size);
473 if (err || !out_size || vlan_cfg.mgmt_msg_head.status) {
475 "Failed to set rx vlan offload, err: %d, status: 0x%x, out size: 0x%x\n",
476 err, vlan_cfg.mgmt_msg_head.status, out_size);
484 * hinic_get_link_status - Get link status from hardware.
487 * The hardware interface of a nic device.
493 * negative error value otherwise.
495 int hinic_get_link_status(void *hwdev, u8 *link_state)
497 struct hinic_get_link get_link;
498 u16 out_size = sizeof(get_link);
501 if (!hwdev || !link_state) {
502 PMD_DRV_LOG(ERR, "Hwdev or link_state is NULL");
506 memset(&get_link, 0, sizeof(get_link));
507 get_link.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
508 get_link.func_id = hinic_global_func_id(hwdev);
510 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_LINK_STATE,
511 &get_link, sizeof(get_link),
512 &get_link, &out_size);
513 if (err || !out_size || get_link.mgmt_msg_head.status) {
514 PMD_DRV_LOG(ERR, "Failed to get link state, err: %d, status: 0x%x, out size: 0x%x",
515 err, get_link.mgmt_msg_head.status, out_size);
519 *link_state = get_link.link_status;
525 * hinic_set_vport_enable - Notify firmware that driver is ready or not.
528 * The hardware interface of a nic device.
530 * 1: driver is ready; 0: driver is not ok.
534 * negative error value otherwise.
536 int hinic_set_vport_enable(void *hwdev, bool enable)
538 struct hinic_vport_state en_state;
539 u16 out_size = sizeof(en_state);
543 PMD_DRV_LOG(ERR, "Hwdev is NULL");
547 memset(&en_state, 0, sizeof(en_state));
548 en_state.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
549 en_state.func_id = hinic_global_func_id(hwdev);
550 en_state.state = (enable ? 1 : 0);
552 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_VPORT_ENABLE,
553 &en_state, sizeof(en_state),
554 &en_state, &out_size);
555 if (err || !out_size || en_state.mgmt_msg_head.status) {
556 PMD_DRV_LOG(ERR, "Failed to set vport state, err: %d, status: 0x%x, out size: 0x%x",
557 err, en_state.mgmt_msg_head.status, out_size);
565 * hinic_set_port_enable - Open MAG to receive packets.
568 * The hardware interface of a nic device.
570 * 1: open MAG; 0: close MAG.
574 * negative error value otherwise.
576 int hinic_set_port_enable(void *hwdev, bool enable)
578 struct hinic_port_state en_state;
579 u16 out_size = sizeof(en_state);
583 PMD_DRV_LOG(ERR, "Hwdev is NULL");
587 if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
590 memset(&en_state, 0, sizeof(en_state));
591 en_state.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
592 en_state.state = (enable ? HINIC_PORT_ENABLE : HINIC_PORT_DISABLE);
594 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_PORT_ENABLE,
595 &en_state, sizeof(en_state),
596 &en_state, &out_size);
597 if (err || !out_size || en_state.mgmt_msg_head.status) {
598 PMD_DRV_LOG(ERR, "Failed to set phy port state, err: %d, status: 0x%x, out size: 0x%x",
599 err, en_state.mgmt_msg_head.status, out_size);
606 int hinic_get_port_info(void *hwdev, struct nic_port_info *port_info)
608 struct hinic_port_info port_msg;
609 u16 out_size = sizeof(port_msg);
612 if (!hwdev || !port_info) {
613 PMD_DRV_LOG(ERR, "Hwdev or port_info is NULL");
617 memset(&port_msg, 0, sizeof(port_msg));
618 port_msg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
619 port_msg.func_id = hinic_global_func_id(hwdev);
621 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_PORT_INFO,
622 &port_msg, sizeof(port_msg),
623 &port_msg, &out_size);
624 if (err || !out_size || port_msg.mgmt_msg_head.status) {
626 "Failed to get port info, err: %d, status: 0x%x, out size: 0x%x",
627 err, port_msg.mgmt_msg_head.status, out_size);
631 port_info->autoneg_cap = port_msg.autoneg_cap;
632 port_info->autoneg_state = port_msg.autoneg_state;
633 port_info->duplex = port_msg.duplex;
634 port_info->port_type = port_msg.port_type;
635 port_info->speed = port_msg.speed;
640 int hinic_set_pause_config(void *hwdev, struct nic_pause_config nic_pause)
642 struct hinic_pause_config pause_info;
643 u16 out_size = sizeof(pause_info);
647 PMD_DRV_LOG(ERR, "Hwdev is NULL");
651 memset(&pause_info, 0, sizeof(pause_info));
652 pause_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
653 pause_info.func_id = hinic_global_func_id(hwdev);
654 pause_info.auto_neg = nic_pause.auto_neg;
655 pause_info.rx_pause = nic_pause.rx_pause;
656 pause_info.tx_pause = nic_pause.tx_pause;
658 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_PAUSE_INFO,
659 &pause_info, sizeof(pause_info),
660 &pause_info, &out_size);
661 if (err || !out_size || pause_info.mgmt_msg_head.status) {
662 PMD_DRV_LOG(ERR, "Failed to set pause info, err: %d, status: 0x%x, out size: 0x%x",
663 err, pause_info.mgmt_msg_head.status, out_size);
670 int hinic_dcb_set_ets(void *hwdev, u8 *up_tc, u8 *pg_bw,
671 u8 *pgid, u8 *up_bw, u8 *prio)
673 struct hinic_up_ets_cfg ets;
674 u16 out_size = sizeof(ets);
679 if (!hwdev || !up_tc || !pg_bw || !pgid || !up_bw || !prio) {
680 PMD_DRV_LOG(ERR, "Hwdev, up_tc, pg_bw, pgid, up_bw or prio is NULL");
684 for (i = 0; i < HINIC_DCB_TC_MAX; i++) {
685 up_bw_t += *(up_bw + i);
686 pg_bw_t += *(pg_bw + i);
688 if (*(up_tc + i) > HINIC_DCB_TC_MAX) {
690 "Invalid up %d mapping tc: %d", i,
696 if (pg_bw_t != 100 || (up_bw_t % 100) != 0) {
698 "Invalid pg_bw: %d or up_bw: %d", pg_bw_t, up_bw_t);
702 memset(&ets, 0, sizeof(ets));
703 ets.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
704 ets.port_id = 0; /* reserved */
705 memcpy(ets.up_tc, up_tc, HINIC_DCB_TC_MAX);
706 memcpy(ets.pg_bw, pg_bw, HINIC_DCB_UP_MAX);
707 memcpy(ets.pgid, pgid, HINIC_DCB_UP_MAX);
708 memcpy(ets.up_bw, up_bw, HINIC_DCB_UP_MAX);
709 memcpy(ets.prio, prio, HINIC_DCB_UP_MAX);
711 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_ETS,
712 &ets, sizeof(ets), &ets, &out_size);
713 if (err || ets.mgmt_msg_head.status || !out_size) {
715 "Failed to set ets, err: %d, status: 0x%x, out size: 0x%x",
716 err, ets.mgmt_msg_head.status, out_size);
723 int hinic_get_vport_stats(void *hwdev, struct hinic_vport_stats *stats)
725 struct hinic_port_stats_info vport_stats_cmd;
726 struct hinic_cmd_vport_stats vport_stats_rsp;
727 u16 out_size = sizeof(vport_stats_rsp);
730 if (!hwdev || !stats) {
731 PMD_DRV_LOG(ERR, "Hwdev or stats is NULL");
735 memset(&vport_stats_rsp, 0, sizeof(vport_stats_rsp));
736 memset(&vport_stats_cmd, 0, sizeof(vport_stats_cmd));
737 vport_stats_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
738 vport_stats_cmd.stats_version = HINIC_PORT_STATS_VERSION;
739 vport_stats_cmd.func_id = hinic_global_func_id(hwdev);
740 vport_stats_cmd.stats_size = sizeof(vport_stats_rsp);
742 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_VPORT_STAT,
743 &vport_stats_cmd, sizeof(vport_stats_cmd),
744 &vport_stats_rsp, &out_size);
745 if (err || !out_size || vport_stats_rsp.mgmt_msg_head.status) {
747 "Get vport stats from fw failed, err: %d, status: 0x%x, out size: 0x%x",
748 err, vport_stats_rsp.mgmt_msg_head.status, out_size);
752 memcpy(stats, &vport_stats_rsp.stats, sizeof(*stats));
757 int hinic_get_phy_port_stats(void *hwdev, struct hinic_phy_port_stats *stats)
759 struct hinic_port_stats_info port_stats_cmd;
760 struct hinic_port_stats port_stats_rsp;
761 u16 out_size = sizeof(port_stats_rsp);
764 if (!hwdev || !stats) {
765 PMD_DRV_LOG(ERR, "Hwdev or stats is NULL");
769 memset(&port_stats_rsp, 0, sizeof(port_stats_rsp));
770 memset(&port_stats_cmd, 0, sizeof(port_stats_cmd));
771 port_stats_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
772 port_stats_cmd.stats_version = HINIC_PORT_STATS_VERSION;
773 port_stats_cmd.stats_size = sizeof(port_stats_rsp);
775 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_PORT_STATISTICS,
776 &port_stats_cmd, sizeof(port_stats_cmd),
777 &port_stats_rsp, &out_size);
778 if (err || !out_size || port_stats_rsp.mgmt_msg_head.status) {
780 "Failed to get port statistics, err: %d, status: 0x%x, out size: 0x%x",
781 err, port_stats_rsp.mgmt_msg_head.status, out_size);
785 memcpy(stats, &port_stats_rsp.stats, sizeof(*stats));
790 int hinic_set_rss_type(void *hwdev, u32 tmpl_idx, struct nic_rss_type rss_type)
792 struct nic_rss_context_tbl *ctx_tbl;
793 struct hinic_cmd_buf *cmd_buf;
799 PMD_DRV_LOG(ERR, "Hwdev is NULL");
803 cmd_buf = hinic_alloc_cmd_buf(hwdev);
805 PMD_DRV_LOG(ERR, "Failed to allocate cmd buf");
809 ctx |= HINIC_RSS_TYPE_SET(1, VALID) |
810 HINIC_RSS_TYPE_SET(rss_type.ipv4, IPV4) |
811 HINIC_RSS_TYPE_SET(rss_type.ipv6, IPV6) |
812 HINIC_RSS_TYPE_SET(rss_type.ipv6_ext, IPV6_EXT) |
813 HINIC_RSS_TYPE_SET(rss_type.tcp_ipv4, TCP_IPV4) |
814 HINIC_RSS_TYPE_SET(rss_type.tcp_ipv6, TCP_IPV6) |
815 HINIC_RSS_TYPE_SET(rss_type.tcp_ipv6_ext, TCP_IPV6_EXT) |
816 HINIC_RSS_TYPE_SET(rss_type.udp_ipv4, UDP_IPV4) |
817 HINIC_RSS_TYPE_SET(rss_type.udp_ipv6, UDP_IPV6);
819 cmd_buf->size = sizeof(struct nic_rss_context_tbl);
821 ctx_tbl = (struct nic_rss_context_tbl *)cmd_buf->buf;
822 ctx_tbl->group_index = cpu_to_be32(tmpl_idx);
824 ctx_tbl->size = sizeof(u32);
825 ctx_tbl->size = cpu_to_be32(ctx_tbl->size);
827 ctx_tbl->ctx = cpu_to_be32(ctx);
829 /* cfg the rss context table by command queue */
830 err = hinic_cmdq_direct_resp(hwdev, HINIC_ACK_TYPE_CMDQ,
832 HINIC_UCODE_CMD_SET_RSS_CONTEXT_TABLE,
833 cmd_buf, &out_param, 0);
835 hinic_free_cmd_buf(hwdev, cmd_buf);
837 if (err || out_param != 0) {
838 PMD_DRV_LOG(ERR, "Failed to set rss context table");
845 int hinic_get_rss_type(void *hwdev, u32 tmpl_idx, struct nic_rss_type *rss_type)
847 struct hinic_rss_context_table ctx_tbl;
848 u16 out_size = sizeof(ctx_tbl);
851 if (!hwdev || !rss_type) {
852 PMD_DRV_LOG(ERR, "Hwdev or rss_type is NULL");
856 ctx_tbl.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
857 ctx_tbl.func_id = hinic_global_func_id(hwdev);
858 ctx_tbl.template_id = (u8)tmpl_idx;
860 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_RSS_CTX_TBL,
861 &ctx_tbl, sizeof(ctx_tbl),
862 &ctx_tbl, &out_size);
863 if (err || !out_size || ctx_tbl.mgmt_msg_head.status) {
865 "Failed to get hash type, err: %d, status: 0x%x, out size: 0x%x",
866 err, ctx_tbl.mgmt_msg_head.status, out_size);
870 rss_type->ipv4 = HINIC_RSS_TYPE_GET(ctx_tbl.context, IPV4);
871 rss_type->ipv6 = HINIC_RSS_TYPE_GET(ctx_tbl.context, IPV6);
872 rss_type->ipv6_ext = HINIC_RSS_TYPE_GET(ctx_tbl.context, IPV6_EXT);
873 rss_type->tcp_ipv4 = HINIC_RSS_TYPE_GET(ctx_tbl.context, TCP_IPV4);
874 rss_type->tcp_ipv6 = HINIC_RSS_TYPE_GET(ctx_tbl.context, TCP_IPV6);
875 rss_type->tcp_ipv6_ext =
876 HINIC_RSS_TYPE_GET(ctx_tbl.context, TCP_IPV6_EXT);
877 rss_type->udp_ipv4 = HINIC_RSS_TYPE_GET(ctx_tbl.context, UDP_IPV4);
878 rss_type->udp_ipv6 = HINIC_RSS_TYPE_GET(ctx_tbl.context, UDP_IPV6);
883 int hinic_rss_set_template_tbl(void *hwdev, u32 tmpl_idx, u8 *temp)
885 struct hinic_rss_template_key temp_key;
886 u16 out_size = sizeof(temp_key);
889 if (!hwdev || !temp) {
890 PMD_DRV_LOG(ERR, "Hwdev or temp is NULL");
894 memset(&temp_key, 0, sizeof(temp_key));
895 temp_key.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
896 temp_key.func_id = hinic_global_func_id(hwdev);
897 temp_key.template_id = (u8)tmpl_idx;
898 memcpy(temp_key.key, temp, HINIC_RSS_KEY_SIZE);
900 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RSS_TEMPLATE_TBL,
901 &temp_key, sizeof(temp_key),
902 &temp_key, &out_size);
903 if (err || !out_size || temp_key.mgmt_msg_head.status) {
905 "Failed to set hash key, err: %d, status: 0x%x, out size: 0x%x",
906 err, temp_key.mgmt_msg_head.status, out_size);
913 int hinic_rss_get_template_tbl(void *hwdev, u32 tmpl_idx, u8 *temp)
915 struct hinic_rss_template_key temp_key;
916 u16 out_size = sizeof(temp_key);
919 if (!hwdev || !temp) {
920 PMD_DRV_LOG(ERR, "Hwdev or temp is NULL");
924 memset(&temp_key, 0, sizeof(temp_key));
925 temp_key.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
926 temp_key.func_id = hinic_global_func_id(hwdev);
927 temp_key.template_id = (u8)tmpl_idx;
929 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_RSS_TEMPLATE_TBL,
930 &temp_key, sizeof(temp_key),
931 &temp_key, &out_size);
932 if (err || !out_size || temp_key.mgmt_msg_head.status) {
933 PMD_DRV_LOG(ERR, "Failed to get hash key, err: %d, status: 0x%x, out size: 0x%x",
934 err, temp_key.mgmt_msg_head.status, out_size);
938 memcpy(temp, temp_key.key, HINIC_RSS_KEY_SIZE);
944 * hinic_rss_set_hash_engine - Init rss hash function.
947 * The hardware interface of a nic device.
949 * Index of rss template from NIC.
951 * Hash function, such as Toeplitz or XOR.
955 * negative error value otherwise.
957 int hinic_rss_set_hash_engine(void *hwdev, u8 tmpl_idx, u8 type)
959 struct hinic_rss_engine_type hash_type;
960 u16 out_size = sizeof(hash_type);
964 PMD_DRV_LOG(ERR, "Hwdev is NULL");
968 memset(&hash_type, 0, sizeof(hash_type));
969 hash_type.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
970 hash_type.func_id = hinic_global_func_id(hwdev);
971 hash_type.hash_engine = type;
972 hash_type.template_id = tmpl_idx;
974 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RSS_HASH_ENGINE,
975 &hash_type, sizeof(hash_type),
976 &hash_type, &out_size);
977 if (err || !out_size || hash_type.mgmt_msg_head.status) {
978 PMD_DRV_LOG(ERR, "Failed to get hash engine, err: %d, status: 0x%x, out size: 0x%x",
979 err, hash_type.mgmt_msg_head.status, out_size);
986 int hinic_rss_set_indir_tbl(void *hwdev, u32 tmpl_idx, u32 *indir_table)
988 struct nic_rss_indirect_tbl *indir_tbl;
989 struct hinic_cmd_buf *cmd_buf;
996 if (!hwdev || !indir_table) {
997 PMD_DRV_LOG(ERR, "Hwdev or indir_table is NULL");
1001 cmd_buf = hinic_alloc_cmd_buf(hwdev);
1003 PMD_DRV_LOG(ERR, "Failed to allocate cmd buf");
1007 cmd_buf->size = sizeof(struct nic_rss_indirect_tbl);
1008 indir_tbl = cmd_buf->buf;
1009 indir_tbl->group_index = cpu_to_be32(tmpl_idx);
1011 for (i = 0; i < HINIC_RSS_INDIR_SIZE; i++) {
1012 indir_tbl->entry[i] = (u8)(*(indir_table + i));
1014 if (0x3 == (i & 0x3)) {
1015 temp = (u32 *)&indir_tbl->entry[i - 3];
1016 *temp = cpu_to_be32(*temp);
1020 /* configure the rss indirect table by command queue */
1021 indir_size = HINIC_RSS_INDIR_SIZE / 2;
1022 indir_tbl->offset = 0;
1023 indir_tbl->size = cpu_to_be32(indir_size);
1025 err = hinic_cmdq_direct_resp(hwdev, HINIC_ACK_TYPE_CMDQ,
1027 HINIC_UCODE_CMD_SET_RSS_INDIR_TABLE,
1028 cmd_buf, &out_param, 0);
1029 if (err || out_param != 0) {
1030 PMD_DRV_LOG(ERR, "Failed to set rss indir table");
1035 indir_tbl->offset = cpu_to_be32(indir_size);
1036 indir_tbl->size = cpu_to_be32(indir_size);
1037 memcpy(indir_tbl->entry, &indir_tbl->entry[indir_size], indir_size);
1039 err = hinic_cmdq_direct_resp(hwdev, HINIC_ACK_TYPE_CMDQ,
1041 HINIC_UCODE_CMD_SET_RSS_INDIR_TABLE,
1042 cmd_buf, &out_param, 0);
1043 if (err || out_param != 0) {
1044 PMD_DRV_LOG(ERR, "Failed to set rss indir table");
1049 hinic_free_cmd_buf(hwdev, cmd_buf);
1054 int hinic_rss_get_indir_tbl(void *hwdev, u32 tmpl_idx, u32 *indir_table)
1056 struct hinic_rss_indir_table rss_cfg;
1057 u16 out_size = sizeof(rss_cfg);
1060 if (!hwdev || !indir_table) {
1061 PMD_DRV_LOG(ERR, "Hwdev or indir_table is NULL");
1065 memset(&rss_cfg, 0, sizeof(rss_cfg));
1066 rss_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1067 rss_cfg.func_id = hinic_global_func_id(hwdev);
1068 rss_cfg.template_id = (u8)tmpl_idx;
1070 err = l2nic_msg_to_mgmt_sync(hwdev,
1071 HINIC_PORT_CMD_GET_RSS_TEMPLATE_INDIR_TBL,
1072 &rss_cfg, sizeof(rss_cfg), &rss_cfg,
1074 if (err || !out_size || rss_cfg.mgmt_msg_head.status) {
1075 PMD_DRV_LOG(ERR, "Failed to get indir table, err: %d, status: 0x%x, out size: 0x%x",
1076 err, rss_cfg.mgmt_msg_head.status, out_size);
1080 hinic_be32_to_cpu(rss_cfg.indir, HINIC_RSS_INDIR_SIZE);
1081 for (i = 0; i < HINIC_RSS_INDIR_SIZE; i++)
1082 indir_table[i] = rss_cfg.indir[i];
1087 int hinic_rss_cfg(void *hwdev, u8 rss_en, u8 tmpl_idx, u8 tc_num, u8 *prio_tc)
1089 struct hinic_rss_config rss_cfg;
1090 u16 out_size = sizeof(rss_cfg);
1093 /* micro code required: number of TC should be power of 2 */
1094 if (!hwdev || !prio_tc || (tc_num & (tc_num - 1))) {
1095 PMD_DRV_LOG(ERR, "Hwdev or prio_tc is NULL, or tc_num: %u Not power of 2",
1100 memset(&rss_cfg, 0, sizeof(rss_cfg));
1101 rss_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1102 rss_cfg.func_id = hinic_global_func_id(hwdev);
1103 rss_cfg.rss_en = rss_en;
1104 rss_cfg.template_id = tmpl_idx;
1105 rss_cfg.rq_priority_number = tc_num ? (u8)ilog2(tc_num) : 0;
1107 memcpy(rss_cfg.prio_tc, prio_tc, HINIC_DCB_UP_MAX);
1109 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RSS_CFG,
1110 &rss_cfg, sizeof(rss_cfg), &rss_cfg,
1112 if (err || !out_size || rss_cfg.mgmt_msg_head.status) {
1113 PMD_DRV_LOG(ERR, "Failed to set rss cfg, err: %d, status: 0x%x, out size: 0x%x",
1114 err, rss_cfg.mgmt_msg_head.status, out_size);
1122 * hinic_rss_template_alloc - Get rss template id from the chip,
1123 * all functions share 96 templates.
1126 * The hardware interface of a nic device.
1128 * Index of rss template from chip.
1132 * negative error value otherwise.
1134 int hinic_rss_template_alloc(void *hwdev, u8 *tmpl_idx)
1136 struct hinic_rss_template_mgmt template_mgmt;
1137 u16 out_size = sizeof(template_mgmt);
1140 if (!hwdev || !tmpl_idx) {
1141 PMD_DRV_LOG(ERR, "Hwdev or tmpl_idx is NULL");
1145 memset(&template_mgmt, 0, sizeof(template_mgmt));
1146 template_mgmt.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1147 template_mgmt.func_id = hinic_global_func_id(hwdev);
1148 template_mgmt.cmd = NIC_RSS_CMD_TEMP_ALLOC;
1150 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RSS_TEMP_MGR,
1151 &template_mgmt, sizeof(template_mgmt),
1152 &template_mgmt, &out_size);
1153 if (err || !out_size || template_mgmt.mgmt_msg_head.status) {
1154 PMD_DRV_LOG(ERR, "Failed to alloc rss template, err: %d, status: 0x%x, out size: 0x%x",
1155 err, template_mgmt.mgmt_msg_head.status, out_size);
1159 *tmpl_idx = template_mgmt.template_id;
1165 * hinic_rss_template_free - Free rss template id to the chip.
1168 * The hardware interface of a nic device.
1170 * Index of rss template from chip.
1174 * negative error value otherwise.
1176 int hinic_rss_template_free(void *hwdev, u8 tmpl_idx)
1178 struct hinic_rss_template_mgmt template_mgmt;
1179 u16 out_size = sizeof(template_mgmt);
1183 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1187 memset(&template_mgmt, 0, sizeof(template_mgmt));
1188 template_mgmt.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1189 template_mgmt.func_id = hinic_global_func_id(hwdev);
1190 template_mgmt.template_id = tmpl_idx;
1191 template_mgmt.cmd = NIC_RSS_CMD_TEMP_FREE;
1193 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RSS_TEMP_MGR,
1194 &template_mgmt, sizeof(template_mgmt),
1195 &template_mgmt, &out_size);
1196 if (err || !out_size || template_mgmt.mgmt_msg_head.status) {
1197 PMD_DRV_LOG(ERR, "Failed to free rss template, err: %d, status: 0x%x, out size: 0x%x",
1198 err, template_mgmt.mgmt_msg_head.status, out_size);
1206 * hinic_set_rx_vhd_mode - Change rx buffer size after initialization.
1209 * The hardware interface of a nic device.
1213 * receive buffer size.
1217 * negative error value otherwise.
1219 int hinic_set_rx_vhd_mode(void *hwdev, u16 vhd_mode, u16 rx_buf_sz)
1221 struct hinic_set_vhd_mode vhd_mode_cfg;
1222 u16 out_size = sizeof(vhd_mode_cfg);
1226 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1230 memset(&vhd_mode_cfg, 0, sizeof(vhd_mode_cfg));
1232 vhd_mode_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1233 vhd_mode_cfg.func_id = hinic_global_func_id(hwdev);
1234 vhd_mode_cfg.vhd_type = vhd_mode;
1235 vhd_mode_cfg.rx_wqe_buffer_size = rx_buf_sz;
1237 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_VHD_CFG,
1238 &vhd_mode_cfg, sizeof(vhd_mode_cfg),
1239 &vhd_mode_cfg, &out_size);
1240 if (err || !out_size || vhd_mode_cfg.mgmt_msg_head.status) {
1242 "Failed to set vhd mode, err: %d, status: 0x%x, out size: 0x%x",
1243 err, vhd_mode_cfg.mgmt_msg_head.status, out_size);
1251 int hinic_set_rx_mode(void *hwdev, u32 enable)
1253 struct hinic_rx_mode_config rx_mode_cfg;
1254 u16 out_size = sizeof(rx_mode_cfg);
1258 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1262 memset(&rx_mode_cfg, 0, sizeof(rx_mode_cfg));
1263 rx_mode_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1264 rx_mode_cfg.func_id = hinic_global_func_id(hwdev);
1265 rx_mode_cfg.rx_mode = enable;
1267 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_MODE,
1268 &rx_mode_cfg, sizeof(rx_mode_cfg),
1269 &rx_mode_cfg, &out_size);
1270 if (err || !out_size || rx_mode_cfg.mgmt_msg_head.status) {
1271 PMD_DRV_LOG(ERR, "Failed to set rx mode, err: %d, status: 0x%x, out size: 0x%x",
1272 err, rx_mode_cfg.mgmt_msg_head.status, out_size);
1279 int hinic_set_rx_csum_offload(void *hwdev, u32 en)
1281 struct hinic_checksum_offload rx_csum_cfg;
1282 u16 out_size = sizeof(rx_csum_cfg);
1286 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1290 memset(&rx_csum_cfg, 0, sizeof(rx_csum_cfg));
1291 rx_csum_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1292 rx_csum_cfg.func_id = hinic_global_func_id(hwdev);
1293 rx_csum_cfg.rx_csum_offload = en;
1295 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_CSUM,
1296 &rx_csum_cfg, sizeof(rx_csum_cfg),
1297 &rx_csum_cfg, &out_size);
1298 if (err || !out_size || rx_csum_cfg.mgmt_msg_head.status) {
1300 "Failed to set rx csum offload, err: %d, status: 0x%x, out size: 0x%x",
1301 err, rx_csum_cfg.mgmt_msg_head.status, out_size);
1308 int hinic_set_rx_lro(void *hwdev, u8 ipv4_en, u8 ipv6_en, u8 max_wqe_num)
1310 struct hinic_lro_config lro_cfg;
1311 u16 out_size = sizeof(lro_cfg);
1315 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1319 memset(&lro_cfg, 0, sizeof(lro_cfg));
1320 lro_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1321 lro_cfg.func_id = hinic_global_func_id(hwdev);
1322 lro_cfg.lro_ipv4_en = ipv4_en;
1323 lro_cfg.lro_ipv6_en = ipv6_en;
1324 lro_cfg.lro_max_wqe_num = max_wqe_num;
1326 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_LRO,
1327 &lro_cfg, sizeof(lro_cfg), &lro_cfg,
1329 if (err || !out_size || lro_cfg.mgmt_msg_head.status) {
1330 PMD_DRV_LOG(ERR, "Failed to set lro offload, err: %d, status: 0x%x, out size: 0x%x",
1331 err, lro_cfg.mgmt_msg_head.status, out_size);
1338 int hinic_set_anti_attack(void *hwdev, bool enable)
1340 struct hinic_port_anti_attack_rate rate;
1341 u16 out_size = sizeof(rate);
1345 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1349 memset(&rate, 0, sizeof(rate));
1350 rate.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1351 rate.func_id = hinic_global_func_id(hwdev);
1352 rate.enable = enable;
1353 rate.cir = ANTI_ATTACK_DEFAULT_CIR;
1354 rate.xir = ANTI_ATTACK_DEFAULT_XIR;
1355 rate.cbs = ANTI_ATTACK_DEFAULT_CBS;
1356 rate.xbs = ANTI_ATTACK_DEFAULT_XBS;
1358 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_ANTI_ATTACK_RATE,
1359 &rate, sizeof(rate), &rate,
1361 if (err || !out_size || rate.mgmt_msg_head.status) {
1362 PMD_DRV_LOG(ERR, "can't %s port Anti-Attack rate limit, err: %d, status: 0x%x, out size: 0x%x",
1363 (enable ? "enable" : "disable"), err,
1364 rate.mgmt_msg_head.status, out_size);
1371 /* Set autoneg status and restart port link status */
1372 int hinic_reset_port_link_cfg(void *hwdev)
1374 struct hinic_reset_link_cfg reset_cfg;
1375 u16 out_size = sizeof(reset_cfg);
1378 memset(&reset_cfg, 0, sizeof(reset_cfg));
1379 reset_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1380 reset_cfg.func_id = hinic_global_func_id(hwdev);
1382 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RESET_LINK_CFG,
1383 &reset_cfg, sizeof(reset_cfg),
1384 &reset_cfg, &out_size);
1385 if (err || !out_size || reset_cfg.mgmt_msg_head.status) {
1386 PMD_DRV_LOG(ERR, "Reset port link configure failed, err: %d, status: 0x%x, out size: 0x%x",
1387 err, reset_cfg.mgmt_msg_head.status, out_size);
1395 * hinic_vf_func_init - Register VF to PF.
1398 * The hardware interface of a nic device.
1402 * negative error value otherwise.
1404 int hinic_vf_func_init(struct hinic_hwdev *hwdev)
1408 if (!HINIC_IS_VF(hwdev))
1411 err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
1412 HINIC_PORT_CMD_VF_REGISTER, &state, sizeof(state),
1415 PMD_DRV_LOG(ERR, "Fail to register vf");
1423 * hinic_vf_func_free - Unregister VF from PF.
1426 * The hardware interface of a nic device.
1428 void hinic_vf_func_free(struct hinic_hwdev *hwdev)
1432 if (hinic_func_type(hwdev) != TYPE_VF)
1435 err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
1436 HINIC_PORT_CMD_VF_UNREGISTER, &err, sizeof(err),
1439 PMD_DRV_LOG(ERR, "Fail to unregister VF, err: %d", err);
1442 int hinic_set_fast_recycle_mode(void *hwdev, u8 mode)
1444 struct hinic_fast_recycled_mode fast_recycled_mode;
1445 u16 out_size = sizeof(fast_recycled_mode);
1449 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1453 memset(&fast_recycled_mode, 0, sizeof(fast_recycled_mode));
1454 fast_recycled_mode.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1455 fast_recycled_mode.func_id = hinic_global_func_id(hwdev);
1456 fast_recycled_mode.fast_recycled_mode = mode;
1458 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_COMM,
1459 HINIC_MGMT_CMD_FAST_RECYCLE_MODE_SET,
1460 &fast_recycled_mode,
1461 sizeof(fast_recycled_mode),
1462 &fast_recycled_mode, &out_size, 0);
1463 if (err || fast_recycled_mode.mgmt_msg_head.status || !out_size) {
1465 "Failed to set recycle mode, ret = %d",
1466 fast_recycled_mode.mgmt_msg_head.status);
1473 int hinic_clear_vport_stats(struct hinic_hwdev *hwdev)
1475 struct hinic_clear_vport_stats clear_vport_stats;
1476 u16 out_size = sizeof(clear_vport_stats);
1480 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1484 memset(&clear_vport_stats, 0, sizeof(clear_vport_stats));
1485 clear_vport_stats.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1486 clear_vport_stats.func_id = hinic_global_func_id(hwdev);
1488 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CLEAN_VPORT_STAT,
1490 sizeof(clear_vport_stats),
1491 &clear_vport_stats, &out_size);
1492 if (err || !out_size || clear_vport_stats.mgmt_msg_head.status) {
1493 PMD_DRV_LOG(ERR, "Failed to clear vport statistics, err: %d, status: 0x%x, out size: 0x%x",
1494 err, clear_vport_stats.mgmt_msg_head.status, out_size);
1501 int hinic_clear_phy_port_stats(struct hinic_hwdev *hwdev)
1503 struct hinic_clear_port_stats clear_phy_port_stats;
1504 u16 out_size = sizeof(clear_phy_port_stats);
1508 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1512 memset(&clear_phy_port_stats, 0, sizeof(clear_phy_port_stats));
1513 clear_phy_port_stats.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1514 clear_phy_port_stats.func_id = hinic_global_func_id(hwdev);
1516 err = l2nic_msg_to_mgmt_sync(hwdev,
1517 HINIC_PORT_CMD_CLEAR_PORT_STATISTICS,
1518 &clear_phy_port_stats,
1519 sizeof(clear_phy_port_stats),
1520 &clear_phy_port_stats, &out_size);
1521 if (err || !out_size || clear_phy_port_stats.mgmt_msg_head.status) {
1522 PMD_DRV_LOG(ERR, "Failed to clear phy port statistics, err: %d, status: 0x%x, out size: 0x%x",
1523 err, clear_phy_port_stats.mgmt_msg_head.status,
1531 int hinic_set_link_status_follow(void *hwdev,
1532 enum hinic_link_follow_status status)
1534 struct hinic_set_link_follow follow;
1535 u16 out_size = sizeof(follow);
1541 if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
1544 if (status >= HINIC_LINK_FOLLOW_STATUS_MAX) {
1546 "Invalid link follow status: %d", status);
1550 memset(&follow, 0, sizeof(follow));
1551 follow.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1552 follow.func_id = hinic_global_func_id(hwdev);
1553 follow.follow_status = status;
1555 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_LINK_FOLLOW,
1556 &follow, sizeof(follow),
1557 &follow, &out_size);
1558 if ((follow.mgmt_msg_head.status != HINIC_MGMT_CMD_UNSUPPORTED &&
1559 follow.mgmt_msg_head.status) || err || !out_size) {
1561 "Failed to set link status follow phy port status, err: %d, status: 0x%x, out size: 0x%x",
1562 err, follow.mgmt_msg_head.status, out_size);
1566 return follow.mgmt_msg_head.status;
1569 int hinic_get_link_mode(void *hwdev, u32 *supported, u32 *advertised)
1571 struct hinic_link_mode_cmd link_mode;
1572 u16 out_size = sizeof(link_mode);
1575 if (!hwdev || !supported || !advertised)
1578 memset(&link_mode, 0, sizeof(link_mode));
1579 link_mode.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1580 link_mode.func_id = hinic_global_func_id(hwdev);
1582 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_LINK_MODE,
1583 &link_mode, sizeof(link_mode),
1584 &link_mode, &out_size);
1585 if (err || !out_size || link_mode.mgmt_msg_head.status) {
1587 "Failed to get link mode, err: %d, status: 0x%x, out size: 0x%x",
1588 err, link_mode.mgmt_msg_head.status, out_size);
1592 *supported = link_mode.supported;
1593 *advertised = link_mode.advertised;
1599 * hinic_flush_qp_res - Flush tx && rx chip resources in case of set vport
1600 * fake failed when device start.
1603 * The hardware interface of a nic device.
1607 * negative error value otherwise.
1609 int hinic_flush_qp_res(void *hwdev)
1611 struct hinic_clear_qp_resource qp_res;
1612 u16 out_size = sizeof(qp_res);
1615 memset(&qp_res, 0, sizeof(qp_res));
1616 qp_res.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1617 qp_res.func_id = hinic_global_func_id(hwdev);
1619 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CLEAR_QP_RES,
1620 &qp_res, sizeof(qp_res), &qp_res,
1622 if (err || !out_size || qp_res.mgmt_msg_head.status) {
1623 PMD_DRV_LOG(ERR, "Failed to clear sq resources, err: %d, status: 0x%x, out size: 0x%x",
1624 err, qp_res.mgmt_msg_head.status, out_size);
1632 * hinic_vf_get_default_cos - Get default cos of VF.
1635 * The hardware interface of a nic device.
1641 * negative error value otherwise.
1643 int hinic_vf_get_default_cos(struct hinic_hwdev *hwdev, u8 *cos_id)
1645 struct hinic_vf_default_cos vf_cos;
1646 u16 out_size = sizeof(vf_cos);
1649 memset(&vf_cos, 0, sizeof(vf_cos));
1650 vf_cos.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1652 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
1653 HINIC_PORT_CMD_GET_VF_COS, &vf_cos,
1654 sizeof(vf_cos), &vf_cos,
1656 if (err || !out_size || vf_cos.mgmt_msg_head.status) {
1657 PMD_DRV_LOG(ERR, "Get VF default cos failed, err: %d, status: 0x%x, out size: 0x%x",
1658 err, vf_cos.mgmt_msg_head.status, out_size);
1661 *cos_id = vf_cos.state.default_cos;