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, \
23 * hinic_init_function_table - Initialize function table.
26 * The hardware interface of a nic device.
28 * Receive buffer size.
32 * negative error value otherwise.
34 int hinic_init_function_table(void *hwdev, u16 rx_buf_sz)
36 struct hinic_function_table function_table;
37 u16 out_size = sizeof(function_table);
41 PMD_DRV_LOG(ERR, "Hwdev is NULL");
45 memset(&function_table, 0, sizeof(function_table));
46 function_table.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
47 function_table.func_id = hinic_global_func_id(hwdev);
48 function_table.mtu = 0x3FFF; /* default, max mtu */
49 function_table.rx_wqe_buf_size = rx_buf_sz;
51 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
52 HINIC_PORT_CMD_INIT_FUNC,
53 &function_table, sizeof(function_table),
54 &function_table, &out_size, 0);
55 if (err || function_table.mgmt_msg_head.status || !out_size) {
57 "Failed to init func table, err: %d, status: 0x%x, out size: 0x%x",
58 err, function_table.mgmt_msg_head.status, out_size);
66 * hinic_get_base_qpn - Get global queue number.
69 * The hardware interface of a nic device.
71 * Global queue number.
75 * negative error value otherwise.
77 int hinic_get_base_qpn(void *hwdev, u16 *global_qpn)
79 struct hinic_cmd_qpn cmd_qpn;
80 u16 out_size = sizeof(cmd_qpn);
83 if (!hwdev || !global_qpn) {
84 PMD_DRV_LOG(ERR, "Hwdev or global_qpn is NULL");
88 memset(&cmd_qpn, 0, sizeof(cmd_qpn));
89 cmd_qpn.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
90 cmd_qpn.func_id = hinic_global_func_id(hwdev);
92 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
93 HINIC_PORT_CMD_GET_GLOBAL_QPN,
94 &cmd_qpn, sizeof(cmd_qpn), &cmd_qpn,
96 if (err || !out_size || cmd_qpn.mgmt_msg_head.status) {
98 "Failed to get base qpn, err: %d, status: 0x%x, out size: 0x%x",
99 err, cmd_qpn.mgmt_msg_head.status, out_size);
103 *global_qpn = cmd_qpn.base_qpn;
109 * hinic_set_mac - Init mac_vlan table in NIC.
112 * The hardware interface of a nic device.
116 * Set 0 for mac_vlan table initialization.
118 * Global function id of NIC.
122 * negative error value otherwise.
124 int hinic_set_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
126 struct hinic_port_mac_set mac_info;
127 u16 out_size = sizeof(mac_info);
130 if (!hwdev || !mac_addr) {
131 PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
135 memset(&mac_info, 0, sizeof(mac_info));
136 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
137 mac_info.func_id = func_id;
138 mac_info.vlan_id = vlan_id;
139 memmove(mac_info.mac, mac_addr, ETH_ALEN);
141 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_MAC, &mac_info,
142 sizeof(mac_info), &mac_info, &out_size);
143 if (err || !out_size || (mac_info.mgmt_msg_head.status &&
144 mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
145 PMD_DRV_LOG(ERR, "Failed to set MAC, err: %d, status: 0x%x, out size: 0x%x",
146 err, mac_info.mgmt_msg_head.status, out_size);
150 if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
151 PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore set operation.");
152 return HINIC_PF_SET_VF_ALREADY;
159 * hinic_del_mac - Uninit mac_vlan table in NIC.
162 * The hardware interface of a nic device.
166 * Set 0 for mac_vlan table initialization.
168 * Global function id of NIC.
172 * negative error value otherwise.
174 int hinic_del_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
176 struct hinic_port_mac_set mac_info;
177 u16 out_size = sizeof(mac_info);
180 if (!hwdev || !mac_addr) {
181 PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
185 if (vlan_id >= VLAN_N_VID) {
186 PMD_DRV_LOG(ERR, "Invalid VLAN number");
190 memset(&mac_info, 0, sizeof(mac_info));
191 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
192 mac_info.func_id = func_id;
193 mac_info.vlan_id = vlan_id;
194 memmove(mac_info.mac, mac_addr, ETH_ALEN);
196 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_DEL_MAC, &mac_info,
197 sizeof(mac_info), &mac_info, &out_size);
198 if (err || !out_size || (mac_info.mgmt_msg_head.status &&
199 mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
200 PMD_DRV_LOG(ERR, "Failed to delete MAC, err: %d, status: 0x%x, out size: 0x%x",
201 err, mac_info.mgmt_msg_head.status, out_size);
204 if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
205 PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore delete operation.");
206 return HINIC_PF_SET_VF_ALREADY;
213 * hinic_get_default_mac - Get default mac address from hardware.
216 * The hardware interface of a nic device.
222 * negative error value otherwise.
224 int hinic_get_default_mac(void *hwdev, u8 *mac_addr)
226 struct hinic_port_mac_set mac_info;
227 u16 out_size = sizeof(mac_info);
230 if (!hwdev || !mac_addr) {
231 PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
235 memset(&mac_info, 0, sizeof(mac_info));
236 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
237 mac_info.func_id = hinic_global_func_id(hwdev);
239 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_MAC,
240 &mac_info, sizeof(mac_info),
241 &mac_info, &out_size);
242 if (err || !out_size || mac_info.mgmt_msg_head.status) {
243 PMD_DRV_LOG(ERR, "Failed to get mac, err: %d, status: 0x%x, out size: 0x%x",
244 err, mac_info.mgmt_msg_head.status, out_size);
248 memmove(mac_addr, mac_info.mac, ETH_ALEN);
254 * hinic_update_mac - Update mac address to hardware.
257 * The hardware interface of a nic device.
263 * Set 0 for mac_vlan table initialization.
265 * Global function id of NIC.
269 * negative error value otherwise.
271 int hinic_update_mac(void *hwdev, u8 *old_mac, u8 *new_mac, u16 vlan_id,
274 struct hinic_port_mac_update mac_info;
275 u16 out_size = sizeof(mac_info);
278 if (!hwdev || !old_mac || !new_mac) {
279 PMD_DRV_LOG(ERR, "Hwdev, old_mac or new_mac is NULL");
283 memset(&mac_info, 0, sizeof(mac_info));
284 mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
285 mac_info.func_id = func_id;
286 mac_info.vlan_id = vlan_id;
287 memcpy(mac_info.old_mac, old_mac, ETH_ALEN);
288 memcpy(mac_info.new_mac, new_mac, ETH_ALEN);
290 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UPDATE_MAC,
291 &mac_info, sizeof(mac_info),
292 &mac_info, &out_size);
293 if (err || !out_size ||
294 (mac_info.mgmt_msg_head.status &&
295 mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
296 PMD_DRV_LOG(ERR, "Failed to update MAC, err: %d, status: 0x%x, out size: 0x%x",
297 err, mac_info.mgmt_msg_head.status, out_size);
300 if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
301 PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore update operation");
302 return HINIC_PF_SET_VF_ALREADY;
309 * hinic_set_port_mtu - Set MTU to port.
312 * The hardware interface of a nic device.
318 * negative error value otherwise.
320 int hinic_set_port_mtu(void *hwdev, u32 new_mtu)
322 struct hinic_mtu mtu_info;
323 u16 out_size = sizeof(mtu_info);
327 PMD_DRV_LOG(ERR, "Hwdev is NULL");
331 memset(&mtu_info, 0, sizeof(mtu_info));
332 mtu_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
333 mtu_info.func_id = hinic_global_func_id(hwdev);
334 mtu_info.mtu = new_mtu;
336 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CHANGE_MTU,
337 &mtu_info, sizeof(mtu_info),
338 &mtu_info, &out_size);
339 if (err || !out_size || mtu_info.mgmt_msg_head.status) {
340 PMD_DRV_LOG(ERR, "Failed to set mtu, err: %d, status: 0x%x, out size: 0x%x",
341 err, mtu_info.mgmt_msg_head.status, out_size);
349 * hinic_add_remove_vlan - Add or remove vlan id to vlan elb table.
352 * The hardware interface of a nic device.
356 * Global function id of NIC.
358 * Add or remove operation.
362 * negative error value otherwise.
364 int hinic_add_remove_vlan(void *hwdev, u16 vlan_id, u16 func_id, bool add)
366 struct hinic_vlan_config vlan_info;
367 u16 out_size = sizeof(vlan_info);
372 PMD_DRV_LOG(ERR, "Hwdev is NULL");
376 cmd = add ? HINIC_PORT_CMD_ADD_VLAN : HINIC_PORT_CMD_DEL_VLAN;
378 memset(&vlan_info, 0, sizeof(vlan_info));
379 vlan_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
380 vlan_info.func_id = func_id;
381 vlan_info.vlan_id = vlan_id;
383 err = l2nic_msg_to_mgmt_sync(hwdev, cmd, &vlan_info,
384 sizeof(vlan_info), &vlan_info,
386 if (err || !out_size || vlan_info.mgmt_msg_head.status) {
388 "Failed to %s vlan, err: %d, status: 0x%x, out size: 0x%x",
389 add ? "add" : "remove", err,
390 vlan_info.mgmt_msg_head.status, out_size);
398 * hinic_config_vlan_filter - Enable or Disable vlan filter.
401 * The hardware interface of a nic device.
402 * @param vlan_filter_ctrl
407 * negative error value otherwise.
409 int hinic_config_vlan_filter(void *hwdev, u32 vlan_filter_ctrl)
411 struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
412 struct hinic_vlan_filter vlan_filter;
413 u16 out_size = sizeof(vlan_filter);
419 memset(&vlan_filter, 0, sizeof(vlan_filter));
420 vlan_filter.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
421 vlan_filter.func_id = hinic_global_func_id(nic_hwdev);
422 vlan_filter.vlan_filter_ctrl = vlan_filter_ctrl;
424 err = l2nic_msg_to_mgmt_sync(nic_hwdev, HINIC_PORT_CMD_SET_VLAN_FILTER,
425 &vlan_filter, sizeof(vlan_filter),
426 &vlan_filter, &out_size);
427 if (vlan_filter.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
428 err = HINIC_MGMT_CMD_UNSUPPORTED;
429 } else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
430 (HINIC_IS_VF(nic_hwdev))) {
431 err = HINIC_MGMT_CMD_UNSUPPORTED;
432 } else if (err || !out_size || vlan_filter.mgmt_msg_head.status) {
434 "Failed to config vlan filter, vlan_filter_ctrl: 0x%x, err: %d, status: 0x%x, out size: 0x%x",
435 vlan_filter_ctrl, err,
436 vlan_filter.mgmt_msg_head.status, out_size);
444 * hinic_set_rx_vlan_offload - Enable or Disable vlan offload.
447 * The hardware interface of a nic device.
453 * negative error value otherwise.
455 int hinic_set_rx_vlan_offload(void *hwdev, u8 en)
457 struct hinic_vlan_offload vlan_cfg;
458 u16 out_size = sizeof(vlan_cfg);
462 PMD_DRV_LOG(ERR, "Hwdev is NULL");
466 memset(&vlan_cfg, 0, sizeof(vlan_cfg));
467 vlan_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
468 vlan_cfg.func_id = hinic_global_func_id(hwdev);
469 vlan_cfg.vlan_rx_offload = en;
471 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_VLAN_OFFLOAD,
472 &vlan_cfg, sizeof(vlan_cfg),
473 &vlan_cfg, &out_size);
474 if (err || !out_size || vlan_cfg.mgmt_msg_head.status) {
476 "Failed to set rx vlan offload, err: %d, status: 0x%x, out size: 0x%x",
477 err, vlan_cfg.mgmt_msg_head.status, out_size);
485 * hinic_get_link_status - Get link status from hardware.
488 * The hardware interface of a nic device.
494 * negative error value otherwise.
496 int hinic_get_link_status(void *hwdev, u8 *link_state)
498 struct hinic_get_link get_link;
499 u16 out_size = sizeof(get_link);
502 if (!hwdev || !link_state) {
503 PMD_DRV_LOG(ERR, "Hwdev or link_state is NULL");
507 memset(&get_link, 0, sizeof(get_link));
508 get_link.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
509 get_link.func_id = hinic_global_func_id(hwdev);
511 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_LINK_STATE,
512 &get_link, sizeof(get_link),
513 &get_link, &out_size);
514 if (err || !out_size || get_link.mgmt_msg_head.status) {
515 PMD_DRV_LOG(ERR, "Failed to get link state, err: %d, status: 0x%x, out size: 0x%x",
516 err, get_link.mgmt_msg_head.status, out_size);
520 *link_state = get_link.link_status;
526 * hinic_set_vport_enable - Notify firmware that driver is ready or not.
529 * The hardware interface of a nic device.
531 * 1: driver is ready; 0: driver is not ok.
535 * negative error value otherwise.
537 int hinic_set_vport_enable(void *hwdev, bool enable)
539 struct hinic_vport_state en_state;
540 u16 out_size = sizeof(en_state);
544 PMD_DRV_LOG(ERR, "Hwdev is NULL");
548 memset(&en_state, 0, sizeof(en_state));
549 en_state.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
550 en_state.func_id = hinic_global_func_id(hwdev);
551 en_state.state = (enable ? 1 : 0);
553 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_VPORT_ENABLE,
554 &en_state, sizeof(en_state),
555 &en_state, &out_size);
556 if (err || !out_size || en_state.mgmt_msg_head.status) {
557 PMD_DRV_LOG(ERR, "Failed to set vport state, err: %d, status: 0x%x, out size: 0x%x",
558 err, en_state.mgmt_msg_head.status, out_size);
566 * hinic_set_port_enable - Open MAG to receive packets.
569 * The hardware interface of a nic device.
571 * 1: open MAG; 0: close MAG.
575 * negative error value otherwise.
577 int hinic_set_port_enable(void *hwdev, bool enable)
579 struct hinic_port_state en_state;
580 u16 out_size = sizeof(en_state);
584 PMD_DRV_LOG(ERR, "Hwdev is NULL");
588 if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
591 memset(&en_state, 0, sizeof(en_state));
592 en_state.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
593 en_state.state = (enable ? HINIC_PORT_ENABLE : HINIC_PORT_DISABLE);
595 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_PORT_ENABLE,
596 &en_state, sizeof(en_state),
597 &en_state, &out_size);
598 if (err || !out_size || en_state.mgmt_msg_head.status) {
599 PMD_DRV_LOG(ERR, "Failed to set phy port state, err: %d, status: 0x%x, out size: 0x%x",
600 err, en_state.mgmt_msg_head.status, out_size);
607 int hinic_get_port_info(void *hwdev, struct nic_port_info *port_info)
609 struct hinic_port_info port_msg;
610 u16 out_size = sizeof(port_msg);
613 if (!hwdev || !port_info) {
614 PMD_DRV_LOG(ERR, "Hwdev or port_info is NULL");
618 memset(&port_msg, 0, sizeof(port_msg));
619 port_msg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
620 port_msg.func_id = hinic_global_func_id(hwdev);
622 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_PORT_INFO,
623 &port_msg, sizeof(port_msg),
624 &port_msg, &out_size);
625 if (err || !out_size || port_msg.mgmt_msg_head.status) {
627 "Failed to get port info, err: %d, status: 0x%x, out size: 0x%x",
628 err, port_msg.mgmt_msg_head.status, out_size);
632 port_info->autoneg_cap = port_msg.autoneg_cap;
633 port_info->autoneg_state = port_msg.autoneg_state;
634 port_info->duplex = port_msg.duplex;
635 port_info->port_type = port_msg.port_type;
636 port_info->speed = port_msg.speed;
641 int hinic_set_pause_config(void *hwdev, struct nic_pause_config nic_pause)
643 struct hinic_pause_config pause_info;
644 u16 out_size = sizeof(pause_info);
648 PMD_DRV_LOG(ERR, "Hwdev is NULL");
652 memset(&pause_info, 0, sizeof(pause_info));
653 pause_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
654 pause_info.func_id = hinic_global_func_id(hwdev);
655 pause_info.auto_neg = nic_pause.auto_neg;
656 pause_info.rx_pause = nic_pause.rx_pause;
657 pause_info.tx_pause = nic_pause.tx_pause;
659 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_PAUSE_INFO,
660 &pause_info, sizeof(pause_info),
661 &pause_info, &out_size);
662 if (err || !out_size || pause_info.mgmt_msg_head.status) {
663 PMD_DRV_LOG(ERR, "Failed to set pause info, err: %d, status: 0x%x, out size: 0x%x",
664 err, pause_info.mgmt_msg_head.status, out_size);
671 int hinic_dcb_set_ets(void *hwdev, u8 *up_tc, u8 *pg_bw,
672 u8 *pgid, u8 *up_bw, u8 *prio)
674 struct hinic_up_ets_cfg ets;
675 u16 out_size = sizeof(ets);
680 if (!hwdev || !up_tc || !pg_bw || !pgid || !up_bw || !prio) {
681 PMD_DRV_LOG(ERR, "Hwdev, up_tc, pg_bw, pgid, up_bw or prio is NULL");
685 for (i = 0; i < HINIC_DCB_TC_MAX; i++) {
686 up_bw_t += *(up_bw + i);
687 pg_bw_t += *(pg_bw + i);
689 if (*(up_tc + i) > HINIC_DCB_TC_MAX) {
690 PMD_DRV_LOG(ERR, "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);
1280 * hinic_get_mgmt_version - Get mgmt module version from chip.
1283 * The hardware interface of a nic device.
1289 * negative error value otherwise.
1291 int hinic_get_mgmt_version(void *hwdev, char *fw)
1293 struct hinic_version_info fw_ver;
1294 u16 out_size = sizeof(fw_ver);
1297 if (!hwdev || !fw) {
1298 PMD_DRV_LOG(ERR, "Hwdev or fw is NULL");
1302 memset(&fw_ver, 0, sizeof(fw_ver));
1303 fw_ver.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1305 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_MGMT_VERSION,
1306 &fw_ver, sizeof(fw_ver), &fw_ver,
1308 if (err || !out_size || fw_ver.mgmt_msg_head.status) {
1309 PMD_DRV_LOG(ERR, "Failed to get mgmt version, err: %d, status: 0x%x, out size: 0x%x\n",
1310 err, fw_ver.mgmt_msg_head.status, out_size);
1314 snprintf(fw, HINIC_MGMT_VERSION_MAX_LEN, "%s", fw_ver.ver);
1319 int hinic_set_rx_csum_offload(void *hwdev, u32 en)
1321 struct hinic_checksum_offload rx_csum_cfg;
1322 u16 out_size = sizeof(rx_csum_cfg);
1326 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1330 memset(&rx_csum_cfg, 0, sizeof(rx_csum_cfg));
1331 rx_csum_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1332 rx_csum_cfg.func_id = hinic_global_func_id(hwdev);
1333 rx_csum_cfg.rx_csum_offload = en;
1335 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_CSUM,
1336 &rx_csum_cfg, sizeof(rx_csum_cfg),
1337 &rx_csum_cfg, &out_size);
1338 if (err || !out_size || rx_csum_cfg.mgmt_msg_head.status) {
1340 "Failed to set rx csum offload, err: %d, status: 0x%x, out size: 0x%x",
1341 err, rx_csum_cfg.mgmt_msg_head.status, out_size);
1348 int hinic_set_rx_lro(void *hwdev, u8 ipv4_en, u8 ipv6_en, u8 max_wqe_num)
1350 struct hinic_lro_config lro_cfg;
1351 u16 out_size = sizeof(lro_cfg);
1355 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1359 memset(&lro_cfg, 0, sizeof(lro_cfg));
1360 lro_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1361 lro_cfg.func_id = hinic_global_func_id(hwdev);
1362 lro_cfg.lro_ipv4_en = ipv4_en;
1363 lro_cfg.lro_ipv6_en = ipv6_en;
1364 lro_cfg.lro_max_wqe_num = max_wqe_num;
1366 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_LRO,
1367 &lro_cfg, sizeof(lro_cfg), &lro_cfg,
1369 if (err || !out_size || lro_cfg.mgmt_msg_head.status) {
1370 PMD_DRV_LOG(ERR, "Failed to set lro offload, err: %d, status: 0x%x, out size: 0x%x",
1371 err, lro_cfg.mgmt_msg_head.status, out_size);
1378 int hinic_set_anti_attack(void *hwdev, bool enable)
1380 struct hinic_port_anti_attack_rate rate;
1381 u16 out_size = sizeof(rate);
1385 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1389 memset(&rate, 0, sizeof(rate));
1390 rate.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1391 rate.func_id = hinic_global_func_id(hwdev);
1392 rate.enable = enable;
1393 rate.cir = ANTI_ATTACK_DEFAULT_CIR;
1394 rate.xir = ANTI_ATTACK_DEFAULT_XIR;
1395 rate.cbs = ANTI_ATTACK_DEFAULT_CBS;
1396 rate.xbs = ANTI_ATTACK_DEFAULT_XBS;
1398 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_ANTI_ATTACK_RATE,
1399 &rate, sizeof(rate), &rate,
1401 if (err || !out_size || rate.mgmt_msg_head.status) {
1402 PMD_DRV_LOG(ERR, "Can't %s port Anti-Attack rate limit, err: %d, status: 0x%x, out size: 0x%x",
1403 (enable ? "enable" : "disable"), err,
1404 rate.mgmt_msg_head.status, out_size);
1411 /* Set autoneg status and restart port link status */
1412 int hinic_reset_port_link_cfg(void *hwdev)
1414 struct hinic_reset_link_cfg reset_cfg;
1415 u16 out_size = sizeof(reset_cfg);
1418 memset(&reset_cfg, 0, sizeof(reset_cfg));
1419 reset_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1420 reset_cfg.func_id = hinic_global_func_id(hwdev);
1422 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RESET_LINK_CFG,
1423 &reset_cfg, sizeof(reset_cfg),
1424 &reset_cfg, &out_size);
1425 if (err || !out_size || reset_cfg.mgmt_msg_head.status) {
1426 PMD_DRV_LOG(ERR, "Reset port link configure failed, err: %d, status: 0x%x, out size: 0x%x",
1427 err, reset_cfg.mgmt_msg_head.status, out_size);
1435 * hinic_vf_func_init - Register VF to PF.
1438 * The hardware interface of a nic device.
1442 * negative error value otherwise.
1444 int hinic_vf_func_init(struct hinic_hwdev *hwdev)
1448 if (!HINIC_IS_VF(hwdev))
1451 err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
1452 HINIC_PORT_CMD_VF_REGISTER, &state, sizeof(state),
1455 PMD_DRV_LOG(ERR, "Fail to register vf");
1463 * hinic_vf_func_free - Unregister VF from PF.
1466 * The hardware interface of a nic device.
1468 void hinic_vf_func_free(struct hinic_hwdev *hwdev)
1472 if (hinic_func_type(hwdev) != TYPE_VF)
1475 err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
1476 HINIC_PORT_CMD_VF_UNREGISTER, &err, sizeof(err),
1479 PMD_DRV_LOG(ERR, "Fail to unregister VF, err: %d", err);
1482 int hinic_set_fast_recycle_mode(void *hwdev, u8 mode)
1484 struct hinic_fast_recycled_mode fast_recycled_mode;
1485 u16 out_size = sizeof(fast_recycled_mode);
1489 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1493 memset(&fast_recycled_mode, 0, sizeof(fast_recycled_mode));
1494 fast_recycled_mode.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1495 fast_recycled_mode.func_id = hinic_global_func_id(hwdev);
1496 fast_recycled_mode.fast_recycled_mode = mode;
1498 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_COMM,
1499 HINIC_MGMT_CMD_FAST_RECYCLE_MODE_SET,
1500 &fast_recycled_mode,
1501 sizeof(fast_recycled_mode),
1502 &fast_recycled_mode, &out_size, 0);
1503 if (err || fast_recycled_mode.mgmt_msg_head.status || !out_size) {
1504 PMD_DRV_LOG(ERR, "Failed to set recycle mode, ret: %d",
1505 fast_recycled_mode.mgmt_msg_head.status);
1512 int hinic_clear_vport_stats(struct hinic_hwdev *hwdev)
1514 struct hinic_clear_vport_stats clear_vport_stats;
1515 u16 out_size = sizeof(clear_vport_stats);
1519 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1523 memset(&clear_vport_stats, 0, sizeof(clear_vport_stats));
1524 clear_vport_stats.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1525 clear_vport_stats.func_id = hinic_global_func_id(hwdev);
1527 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CLEAN_VPORT_STAT,
1529 sizeof(clear_vport_stats),
1530 &clear_vport_stats, &out_size);
1531 if (err || !out_size || clear_vport_stats.mgmt_msg_head.status) {
1532 PMD_DRV_LOG(ERR, "Failed to clear vport statistics, err: %d, status: 0x%x, out size: 0x%x",
1533 err, clear_vport_stats.mgmt_msg_head.status, out_size);
1540 int hinic_clear_phy_port_stats(struct hinic_hwdev *hwdev)
1542 struct hinic_clear_port_stats clear_phy_port_stats;
1543 u16 out_size = sizeof(clear_phy_port_stats);
1547 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1551 memset(&clear_phy_port_stats, 0, sizeof(clear_phy_port_stats));
1552 clear_phy_port_stats.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1553 clear_phy_port_stats.func_id = hinic_global_func_id(hwdev);
1555 err = l2nic_msg_to_mgmt_sync(hwdev,
1556 HINIC_PORT_CMD_CLEAR_PORT_STATISTICS,
1557 &clear_phy_port_stats,
1558 sizeof(clear_phy_port_stats),
1559 &clear_phy_port_stats, &out_size);
1560 if (err || !out_size || clear_phy_port_stats.mgmt_msg_head.status) {
1561 PMD_DRV_LOG(ERR, "Failed to clear phy port statistics, err: %d, status: 0x%x, out size: 0x%x",
1562 err, clear_phy_port_stats.mgmt_msg_head.status,
1570 int hinic_set_link_status_follow(void *hwdev,
1571 enum hinic_link_follow_status status)
1573 struct hinic_set_link_follow follow;
1574 u16 out_size = sizeof(follow);
1580 if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
1583 if (status >= HINIC_LINK_FOLLOW_STATUS_MAX) {
1585 "Invalid link follow status: %d", status);
1589 memset(&follow, 0, sizeof(follow));
1590 follow.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1591 follow.func_id = hinic_global_func_id(hwdev);
1592 follow.follow_status = status;
1594 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_LINK_FOLLOW,
1595 &follow, sizeof(follow),
1596 &follow, &out_size);
1597 if ((follow.mgmt_msg_head.status != HINIC_MGMT_CMD_UNSUPPORTED &&
1598 follow.mgmt_msg_head.status) || err || !out_size) {
1600 "Failed to set link status follow phy port status, err: %d, status: 0x%x, out size: 0x%x",
1601 err, follow.mgmt_msg_head.status, out_size);
1605 return follow.mgmt_msg_head.status;
1608 int hinic_get_link_mode(void *hwdev, u32 *supported, u32 *advertised)
1610 struct hinic_link_mode_cmd link_mode;
1611 u16 out_size = sizeof(link_mode);
1614 if (!hwdev || !supported || !advertised)
1617 memset(&link_mode, 0, sizeof(link_mode));
1618 link_mode.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1619 link_mode.func_id = hinic_global_func_id(hwdev);
1621 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_LINK_MODE,
1622 &link_mode, sizeof(link_mode),
1623 &link_mode, &out_size);
1624 if (err || !out_size || link_mode.mgmt_msg_head.status) {
1626 "Failed to get link mode, err: %d, status: 0x%x, out size: 0x%x",
1627 err, link_mode.mgmt_msg_head.status, out_size);
1631 *supported = link_mode.supported;
1632 *advertised = link_mode.advertised;
1638 * hinic_set_xsfp_tx_status - Enable or disable the fiber in
1639 * tx direction when set link up or down.
1642 * The hardware interface of a nic device.
1644 * Enable or Disable.
1648 * negative error value otherwise.
1650 int hinic_set_xsfp_tx_status(void *hwdev, bool enable)
1652 struct hinic_set_xsfp_status xsfp_status;
1653 u16 out_size = sizeof(struct hinic_set_xsfp_status);
1656 memset(&xsfp_status, 0, sizeof(xsfp_status));
1657 xsfp_status.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1658 xsfp_status.port_id = hinic_global_func_id(hwdev);
1659 xsfp_status.xsfp_tx_dis = ((enable == 0) ? 1 : 0);
1661 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_XSFP_STATUS,
1662 &xsfp_status, sizeof(struct hinic_set_xsfp_status),
1663 &xsfp_status, &out_size);
1664 if (err || !out_size || xsfp_status.mgmt_msg_head.status) {
1666 "Failed to %s port xsfp status, err: %d, status: 0x%x, out size: 0x%x\n",
1667 enable ? "Disable" : "Enable", err,
1668 xsfp_status.mgmt_msg_head.status, out_size);
1676 * hinic_flush_qp_res - Flush tx && rx chip resources in case of set vport
1677 * fake failed when device start.
1680 * The hardware interface of a nic device.
1684 * negative error value otherwise.
1686 int hinic_flush_qp_res(void *hwdev)
1688 struct hinic_clear_qp_resource qp_res;
1689 u16 out_size = sizeof(qp_res);
1692 memset(&qp_res, 0, sizeof(qp_res));
1693 qp_res.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1694 qp_res.func_id = hinic_global_func_id(hwdev);
1696 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CLEAR_QP_RES,
1697 &qp_res, sizeof(qp_res), &qp_res,
1699 if (err || !out_size || qp_res.mgmt_msg_head.status) {
1700 PMD_DRV_LOG(ERR, "Failed to clear sq resources, err: %d, status: 0x%x, out size: 0x%x",
1701 err, qp_res.mgmt_msg_head.status, out_size);
1709 * hinic_vf_get_default_cos - Get default cos of VF.
1712 * The hardware interface of a nic device.
1718 * negative error value otherwise.
1720 int hinic_vf_get_default_cos(struct hinic_hwdev *hwdev, u8 *cos_id)
1722 struct hinic_vf_default_cos vf_cos;
1723 u16 out_size = sizeof(vf_cos);
1726 memset(&vf_cos, 0, sizeof(vf_cos));
1727 vf_cos.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1729 err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
1730 HINIC_PORT_CMD_GET_VF_COS, &vf_cos,
1731 sizeof(vf_cos), &vf_cos,
1733 if (err || !out_size || vf_cos.mgmt_msg_head.status) {
1734 PMD_DRV_LOG(ERR, "Get VF default cos failed, err: %d, status: 0x%x, out size: 0x%x",
1735 err, vf_cos.mgmt_msg_head.status, out_size);
1738 *cos_id = vf_cos.state.default_cos;
1744 * hinic_set_fdir_filter - Set fdir filter for control path
1745 * packet to notify firmware.
1748 * The hardware interface of a nic device.
1749 * @param filter_type
1750 * Packet type to filter.
1753 * @param type_enable
1754 * The status of pkt type filter.
1756 * Fdir function Enable or Disable.
1759 * negative error value otherwise.
1761 int hinic_set_fdir_filter(void *hwdev, u8 filter_type, u8 qid, u8 type_enable,
1764 struct hinic_port_qfilter_info port_filer_cmd;
1765 u16 out_size = sizeof(port_filer_cmd);
1771 memset(&port_filer_cmd, 0, sizeof(port_filer_cmd));
1772 port_filer_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1773 port_filer_cmd.func_id = hinic_global_func_id(hwdev);
1774 port_filer_cmd.filter_enable = (u8)enable;
1775 port_filer_cmd.filter_type = filter_type;
1776 port_filer_cmd.qid = qid;
1777 port_filer_cmd.filter_type_enable = type_enable;
1778 port_filer_cmd.fdir_flag = 0;
1780 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_Q_FILTER,
1781 &port_filer_cmd, sizeof(port_filer_cmd),
1782 &port_filer_cmd, &out_size);
1783 if (err || !out_size || port_filer_cmd.mgmt_msg_head.status) {
1784 PMD_DRV_LOG(ERR, "Set port Q filter failed, err: %d, status: 0x%x, out size: 0x%x, type: 0x%x,"
1785 " enable: 0x%x, qid: 0x%x, filter_type_enable: 0x%x\n",
1786 err, port_filer_cmd.mgmt_msg_head.status, out_size,
1787 filter_type, enable, qid, type_enable);
1795 * hinic_set_normal_filter - Set fdir filter for IO path packet.
1798 * The hardware interface of a nic device.
1801 * @param normal_type_enable
1802 * IO path packet function Enable or Disable
1804 * IO path packet filter key value, such as DIP from pkt.
1806 * Fdir function Enable or Disable.
1808 * Filter flag, such as dip or others.
1811 * negative error value otherwise.
1813 int hinic_set_normal_filter(void *hwdev, u8 qid, u8 normal_type_enable,
1814 u32 key, bool enable, u8 flag)
1816 struct hinic_port_qfilter_info port_filer_cmd;
1817 u16 out_size = sizeof(port_filer_cmd);
1823 memset(&port_filer_cmd, 0, sizeof(port_filer_cmd));
1824 port_filer_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1825 port_filer_cmd.func_id = hinic_global_func_id(hwdev);
1826 port_filer_cmd.filter_enable = (u8)enable;
1827 port_filer_cmd.qid = qid;
1828 port_filer_cmd.normal_type_enable = normal_type_enable;
1829 port_filer_cmd.fdir_flag = flag; /* fdir flag: support dip */
1830 port_filer_cmd.key = key;
1832 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_Q_FILTER,
1833 &port_filer_cmd, sizeof(port_filer_cmd),
1834 &port_filer_cmd, &out_size);
1835 if (err || !out_size || port_filer_cmd.mgmt_msg_head.status) {
1836 PMD_DRV_LOG(ERR, "Set normal filter failed, err: %d, status: 0x%x, out size: 0x%x, fdir_flag: 0x%x,"
1837 " enable: 0x%x, qid: 0x%x, normal_type_enable: 0x%x, key:0x%x\n",
1838 err, port_filer_cmd.mgmt_msg_head.status, out_size,
1839 flag, enable, qid, normal_type_enable, key);
1847 * hinic_set_fdir_tcam - Set fdir filter for control packet
1848 * by tcam table to notify hardware.
1851 * The hardware interface of a nic device.
1854 * @param filter_rule
1855 * TCAM rule for control packet, such as lacp or bgp.
1856 * @param filter_action
1857 * TCAM action for control packet, such as accept or drop.
1860 * negative error value otherwise.
1862 int hinic_set_fdir_tcam(void *hwdev, u16 type_mask,
1863 struct tag_pa_rule *filter_rule,
1864 struct tag_pa_action *filter_action)
1866 struct hinic_fdir_tcam_info port_tcam_cmd;
1867 u16 out_size = sizeof(port_tcam_cmd);
1873 memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
1874 port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1875 port_tcam_cmd.tcam_index = type_mask;
1876 port_tcam_cmd.flag = TCAM_SET;
1877 memcpy((void *)&port_tcam_cmd.filter_rule,
1878 (void *)filter_rule, sizeof(struct tag_pa_rule));
1879 memcpy((void *)&port_tcam_cmd.filter_action,
1880 (void *)filter_action, sizeof(struct tag_pa_action));
1882 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_TCAM_FILTER,
1883 &port_tcam_cmd, sizeof(port_tcam_cmd),
1884 &port_tcam_cmd, &out_size);
1885 if (err || !out_size || port_tcam_cmd.mgmt_msg_head.status) {
1886 PMD_DRV_LOG(ERR, "Set tcam table failed, err: %d, status: 0x%x, out size: 0x%x",
1887 err, port_tcam_cmd.mgmt_msg_head.status, out_size);
1895 * hinic_clear_fdir_tcam - Clear fdir filter TCAM table for control packet.
1898 * The hardware interface of a nic device.
1903 * negative error value otherwise.
1905 int hinic_clear_fdir_tcam(void *hwdev, u16 type_mask)
1907 struct hinic_fdir_tcam_info port_tcam_cmd;
1908 u16 out_size = sizeof(port_tcam_cmd);
1914 memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
1915 port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1916 port_tcam_cmd.tcam_index = type_mask;
1917 port_tcam_cmd.flag = TCAM_CLEAR;
1919 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_TCAM_FILTER,
1920 &port_tcam_cmd, sizeof(port_tcam_cmd),
1921 &port_tcam_cmd, &out_size);
1922 if (err || !out_size || port_tcam_cmd.mgmt_msg_head.status) {
1923 PMD_DRV_LOG(ERR, "Clear tcam table failed, err: %d, status: 0x%x, out size: 0x%x",
1924 err, port_tcam_cmd.mgmt_msg_head.status, out_size);
1931 int hinic_add_tcam_rule(void *hwdev, struct tag_tcam_cfg_rule *tcam_rule)
1933 u16 out_size = sizeof(struct tag_fdir_add_rule_cmd);
1934 struct tag_fdir_add_rule_cmd tcam_cmd;
1938 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1942 if (tcam_rule->index >= HINIC_MAX_TCAM_RULES_NUM) {
1943 PMD_DRV_LOG(ERR, "Tcam rules num to add is invalid");
1947 memset(&tcam_cmd, 0, sizeof(struct tag_fdir_add_rule_cmd));
1948 tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1949 memcpy((void *)&tcam_cmd.rule, (void *)tcam_rule,
1950 sizeof(struct tag_tcam_cfg_rule));
1952 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_ADD_FLOW,
1953 &tcam_cmd, sizeof(tcam_cmd),
1954 &tcam_cmd, &out_size);
1955 if (err || tcam_cmd.mgmt_msg_head.status || !out_size) {
1957 "Add tcam rule failed, err: %d, status: 0x%x, out size: 0x%x",
1958 err, tcam_cmd.mgmt_msg_head.status, out_size);
1965 int hinic_del_tcam_rule(void *hwdev, u32 index)
1967 u16 out_size = sizeof(struct tag_fdir_del_rule_cmd);
1968 struct tag_fdir_del_rule_cmd tcam_cmd;
1972 PMD_DRV_LOG(ERR, "Hwdev is NULL");
1976 if (index >= HINIC_MAX_TCAM_RULES_NUM) {
1977 PMD_DRV_LOG(ERR, "Tcam rules num to del is invalid");
1981 memset(&tcam_cmd, 0, sizeof(struct tag_fdir_del_rule_cmd));
1982 tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
1983 tcam_cmd.index_start = index;
1984 tcam_cmd.index_num = 1;
1986 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_DEL_FLOW,
1987 &tcam_cmd, sizeof(tcam_cmd),
1988 &tcam_cmd, &out_size);
1989 if (err || tcam_cmd.mgmt_msg_head.status || !out_size) {
1991 "Del tcam rule failed, err: %d, status: 0x%x, out size: 0x%x",
1992 err, tcam_cmd.mgmt_msg_head.status, out_size);
1999 static int hinic_mgmt_tcam_block(void *hwdev, u8 alloc_en,
2000 u8 block_type, u16 *index)
2002 struct hinic_cmd_ctrl_tcam_block tcam_block_info;
2003 u16 out_size = sizeof(struct hinic_cmd_ctrl_tcam_block);
2004 struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
2008 PMD_DRV_LOG(ERR, "Hwdev is NULL");
2012 memset(&tcam_block_info, 0, sizeof(struct hinic_cmd_ctrl_tcam_block));
2013 tcam_block_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
2014 tcam_block_info.func_id = hinic_global_func_id(hwdev);
2015 tcam_block_info.alloc_en = alloc_en;
2016 tcam_block_info.tcam_type = block_type;
2017 tcam_block_info.tcam_block_index = *index;
2019 err = l2nic_msg_to_mgmt_sync(hwdev,
2020 HINIC_PORT_CMD_UP_TC_CTRL_TCAM_BLOCK,
2021 &tcam_block_info, sizeof(tcam_block_info),
2022 &tcam_block_info, &out_size);
2023 if (tcam_block_info.mgmt_msg_head.status ==
2024 HINIC_MGMT_CMD_UNSUPPORTED) {
2025 err = HINIC_MGMT_CMD_UNSUPPORTED;
2026 PMD_DRV_LOG(INFO, "Firmware/uP doesn't support alloc or del tcam block");
2028 } else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
2029 (HINIC_IS_VF(nic_hwdev))) {
2030 err = HINIC_MGMT_CMD_UNSUPPORTED;
2031 PMD_DRV_LOG(INFO, "VF doesn't support alloc and del tcam block.");
2033 } else if (err || (!out_size) || tcam_block_info.mgmt_msg_head.status) {
2035 "Set tcam block failed, err: %d, status: 0x%x, out size: 0x%x",
2036 err, tcam_block_info.mgmt_msg_head.status, out_size);
2041 *index = tcam_block_info.tcam_block_index;
2046 int hinic_alloc_tcam_block(void *hwdev, u8 block_type, u16 *index)
2048 return hinic_mgmt_tcam_block(hwdev, HINIC_TCAM_BLOCK_ENABLE,
2052 int hinic_free_tcam_block(void *hwdev, u8 block_type, u16 *index)
2054 return hinic_mgmt_tcam_block(hwdev, HINIC_TCAM_BLOCK_DISABLE,
2058 int hinic_flush_tcam_rule(void *hwdev)
2060 struct hinic_cmd_flush_tcam_rules tcam_flush;
2061 u16 out_size = sizeof(struct hinic_cmd_flush_tcam_rules);
2062 struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
2066 PMD_DRV_LOG(ERR, "Hwdev is NULL");
2070 memset(&tcam_flush, 0, sizeof(struct hinic_cmd_flush_tcam_rules));
2071 tcam_flush.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
2072 tcam_flush.func_id = hinic_global_func_id(hwdev);
2074 err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_FLUSH_TCAM,
2075 &tcam_flush, sizeof(struct hinic_cmd_flush_tcam_rules),
2076 &tcam_flush, &out_size);
2077 if (tcam_flush.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
2078 err = HINIC_MGMT_CMD_UNSUPPORTED;
2079 PMD_DRV_LOG(INFO, "Firmware/uP doesn't support flush tcam fdir");
2080 } else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
2081 (HINIC_IS_VF(nic_hwdev))) {
2082 err = HINIC_MGMT_CMD_UNSUPPORTED;
2083 PMD_DRV_LOG(INFO, "VF doesn't support flush tcam fdir");
2084 } else if (err || (!out_size) || tcam_flush.mgmt_msg_head.status) {
2086 "Flush tcam fdir rules failed, err: %d, status: 0x%x, out size: 0x%x",
2087 err, tcam_flush.mgmt_msg_head.status, out_size);