add hinic3 PMD driver
Subsystems (2)
cover add hinic3 PMD driver
*** BLURB HERE ***
The hinic3 PMD (**librte_net_hinic3**) provides poll mode driver support for 25Gbps/100Gbps/200Gbps Huawei SPx series Network Adapters.
Feifei Wang (3):
net/hinic3: add intro doc for hinic3
net/hinic3: add dev ops
net/hinic3: add Rx/Tx functions
Xin Wang (7):
net/hinic3: add basic header files
net/hinic3: add support for cmdq mechanism
net/hinic3: add NIC event module
net/hinic3: add context and work queue support
net/hinic3: add device initailization
net/hinic3: add MML and EEPROM access feature
net/hinic3: add RSS promiscuous ops
Yi Chen (8):
net/hinic3: add hardware interfaces of BAR operation net/hinic3: add eq mechanism function code net/hinic3: add mgmt module function code net/hinic3: add module about hardware operation net/hinic3: add a NIC business configuration module net/hinic3: add a mailbox communication module net/hinic3: add FDIR flow control module drivers/net: add hinic3 PMD build and doc files
.mailmap | 4 +- MAINTAINERS | 6 + doc/guides/nics/features/hinic3.ini | 9 + doc/guides/nics/hinic3.rst | 52 + doc/guides/nics/index.rst | 1 + doc/guides/rel_notes/release_25_07.rst | 32 +- drivers/net/hinic3/base/hinic3_cmd.h | 231 ++ drivers/net/hinic3/base/hinic3_cmdq.c | 975 +++++ drivers/net/hinic3/base/hinic3_cmdq.h | 230 ++ drivers/net/hinic3/base/hinic3_compat.h | 266 ++ drivers/net/hinic3/base/hinic3_csr.h | 108 + drivers/net/hinic3/base/hinic3_eqs.c | 719 ++++ drivers/net/hinic3/base/hinic3_eqs.h | 98 + drivers/net/hinic3/base/hinic3_hw_cfg.c | 240 ++ drivers/net/hinic3/base/hinic3_hw_cfg.h | 121 + drivers/net/hinic3/base/hinic3_hw_comm.c | 452 +++ drivers/net/hinic3/base/hinic3_hw_comm.h | 366 ++ drivers/net/hinic3/base/hinic3_hwdev.c | 573 +++ drivers/net/hinic3/base/hinic3_hwdev.h | 177 + drivers/net/hinic3/base/hinic3_hwif.c | 779 ++++ drivers/net/hinic3/base/hinic3_hwif.h | 142 + drivers/net/hinic3/base/hinic3_mbox.c | 1392 +++++++ drivers/net/hinic3/base/hinic3_mbox.h | 199 + drivers/net/hinic3/base/hinic3_mgmt.c | 392 ++ drivers/net/hinic3/base/hinic3_mgmt.h | 121 + drivers/net/hinic3/base/hinic3_nic_cfg.c | 1828 +++++++++ drivers/net/hinic3/base/hinic3_nic_cfg.h | 1527 ++++++++ drivers/net/hinic3/base/hinic3_nic_event.c | 433 +++ drivers/net/hinic3/base/hinic3_nic_event.h | 39 + drivers/net/hinic3/base/hinic3_wq.c | 148 + drivers/net/hinic3/base/hinic3_wq.h | 109 + drivers/net/hinic3/base/meson.build | 50 + drivers/net/hinic3/hinic3_ethdev.c | 3866 ++++++++++++++++++++ drivers/net/hinic3/hinic3_ethdev.h | 167 + drivers/net/hinic3/hinic3_fdir.c | 1394 +++++++ drivers/net/hinic3/hinic3_fdir.h | 398 ++ drivers/net/hinic3/hinic3_flow.c | 1700 +++++++++ drivers/net/hinic3/hinic3_flow.h | 80 + drivers/net/hinic3/hinic3_nic_io.c | 827 +++++ drivers/net/hinic3/hinic3_nic_io.h | 169 + drivers/net/hinic3/hinic3_rx.c | 1096 ++++++ drivers/net/hinic3/hinic3_rx.h | 356 ++ drivers/net/hinic3/hinic3_tx.c | 1028 ++++++ drivers/net/hinic3/hinic3_tx.h | 315 ++ drivers/net/hinic3/meson.build | 44 + drivers/net/hinic3/mml/hinic3_dbg.c | 171 + drivers/net/hinic3/mml/hinic3_dbg.h | 160 + drivers/net/hinic3/mml/hinic3_mml_cmd.c | 375 ++ drivers/net/hinic3/mml/hinic3_mml_cmd.h | 131 + drivers/net/hinic3/mml/hinic3_mml_ioctl.c | 215 ++ drivers/net/hinic3/mml/hinic3_mml_lib.c | 136 + drivers/net/hinic3/mml/hinic3_mml_lib.h | 275 ++ drivers/net/hinic3/mml/hinic3_mml_main.c | 167 + drivers/net/hinic3/mml/hinic3_mml_queue.c | 749 ++++ drivers/net/hinic3/mml/hinic3_mml_queue.h | 256 ++ drivers/net/hinic3/mml/meson.build | 62 + drivers/net/meson.build | 1 + 57 files changed, 25926 insertions(+), 31 deletions(-) create mode 100644 doc/guides/nics/features/hinic3.ini create mode 100644 doc/guides/nics/hinic3.rst create mode 100644 drivers/net/hinic3/base/hinic3_cmd.h create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.c create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.h create mode 100644 drivers/net/hinic3/base/hinic3_compat.h create mode 100644 drivers/net/hinic3/base/hinic3_csr.h create mode 100644 drivers/net/hinic3/base/hinic3_eqs.c create mode 100644 drivers/net/hinic3/base/hinic3_eqs.h create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.c create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.h create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.c create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.h create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.c create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.h create mode 100644 drivers/net/hinic3/base/hinic3_hwif.c create mode 100644 drivers/net/hinic3/base/hinic3_hwif.h create mode 100644 drivers/net/hinic3/base/hinic3_mbox.c create mode 100644 drivers/net/hinic3/base/hinic3_mbox.h create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.c create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.h create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.c create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.h create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.c create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.h create mode 100644 drivers/net/hinic3/base/hinic3_wq.c create mode 100644 drivers/net/hinic3/base/hinic3_wq.h create mode 100644 drivers/net/hinic3/base/meson.build create mode 100644 drivers/net/hinic3/hinic3_ethdev.c create mode 100644 drivers/net/hinic3/hinic3_ethdev.h create mode 100644 drivers/net/hinic3/hinic3_fdir.c create mode 100644 drivers/net/hinic3/hinic3_fdir.h create mode 100644 drivers/net/hinic3/hinic3_flow.c create mode 100644 drivers/net/hinic3/hinic3_flow.h create mode 100644 drivers/net/hinic3/hinic3_nic_io.c create mode 100644 drivers/net/hinic3/hinic3_nic_io.h create mode 100644 drivers/net/hinic3/hinic3_rx.c create mode 100644 drivers/net/hinic3/hinic3_rx.h create mode 100644 drivers/net/hinic3/hinic3_tx.c create mode 100644 drivers/net/hinic3/hinic3_tx.h create mode 100644 drivers/net/hinic3/meson.build create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.c create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.h create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.h create mode 100644 drivers/net/hinic3/mml/hinic3_mml_ioctl.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.h create mode 100644 drivers/net/hinic3/mml/hinic3_mml_main.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.h create mode 100644 drivers/net/hinic3/mml/meson.build
Signature · 1 line
2.47.0.windows.2
RFC 1/18 net/hinic3: add intro doc for hinic3
From: Feifei Wang <[email protected]>
This patch adds some basic files to describe the hinic3 driver.
--- .mailmap | 4 +- MAINTAINERS | 6 +++ doc/guides/nics/hinic3.rst | 52 ++++++++++++++++++++++++++ doc/guides/nics/index.rst | 1 + doc/guides/rel_notes/release_25_07.rst | 32 +--------------- 5 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 doc/guides/nics/hinic3.rst
.mailmap +3 -1
@@ -429,7 +429,7 @@ Fang TongHao <[email protected]> Fan Zhang <[email protected]> <[email protected]> Farah Smith <[email protected]> Fei Chen <[email protected]> -Feifei Wang <[email protected]> <[email protected]> +Feifei Wang <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> Fei Qin <[email protected]> Fengjiang Liu <[email protected]> Fengnan Chang <[email protected]>
@@ -1718,6 +1718,7 @@ Xingguang He <[email protected]> Xingyou Chen <[email protected]> Xing Wang <[email protected]> Xinying Yu <[email protected]> +Xin Wang <[email protected]> Xin Long <[email protected]> Xi Zhang <[email protected]> Xuan Ding <[email protected]>
@@ -1750,6 +1751,7 @@ Yelena Krivosheev <[email protected]> Yerden Zhumabekov <[email protected]> <[email protected]> Yevgeny Kliteynik <[email protected]> Yicai Lu <[email protected]> +Yi Chen <[email protected]> Yiding Zhou <[email protected]> Yi Li <[email protected]> Yi Liu <[email protected]>
MAINTAINERS +6 -0
@@ -773,6 +773,12 @@ F: drivers/net/hinic/ F: doc/guides/nics/hinic.rst F: doc/guides/nics/features/hinic.ini +Huawei hinic3 +M: Feifei Wang <[email protected]> +F: drivers/net/hinic3/ +F: doc/guides/nics/hinic3.rst +F: doc/guides/nics/features/hinic3.ini + Intel Network Common Code M: Bruce Richardson <[email protected]> T: git://dpdk.org/next/dpdk-next-net-intel
doc/guides/nics/hinic3.rst new file +52 -0
52 lines not on this page · raw message
doc/guides/nics/index.rst +1 -0
@@ -33,6 +33,7 @@ Network Interface Controller Drivers fm10k gve hinic + hinic3 hns3 i40e ice
doc/guides/rel_notes/release_25_07.rst +2 -30
@@ -24,37 +24,9 @@ DPDK Release 25.07 New Features ------------ -.. This section should contain new features added in this release. - Sample format: - - * **Add a title in the past tense with a full stop.** - - Add a short 1-2 sentence description in the past tense. - The description should be enough to allow someone scanning - the release notes to understand the new feature. - - If the feature adds a lot of sub-features you can use a bullet list - like this: - - * Added feature foo to do something. - * Enhanced feature bar to do something else. - - Refer to the previous release notes for examples. - - Suggested order in release notes items: - * Core libs (EAL, mempool, ring, mbuf, buses) - * Device abstraction libs and PMDs (ordered alphabetically by vendor name) - - ethdev (lib, PMDs) - - cryptodev (lib, PMDs) - - eventdev (lib, PMDs) - - etc - * Other libs - * Apps, Examples, Tools (if significant) - - This section is a comment. Do not overwrite or remove it. - Also, make sure to start the actual text at the margin. - ======================================================= +* **Added Huawei hinic3 net driver [EXPERIMENTAL].** + * Added network driver for the Huawei SPx series Network Adapters. Removed Items -------------
Signature · 1 line
2.47.0.windows.2
RFC 2/18 net/hinic3: add basic header files
In reply to Feifei WangFrom: Xin Wang <[email protected]>
Add HW registers definition header file for SP series NIC. Add some headers that define commands and basic defines for use in the code.
--- drivers/net/hinic3/base/hinic3_cmd.h | 231 ++++++++++++++++++++ drivers/net/hinic3/base/hinic3_compat.h | 266 ++++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_csr.h | 108 ++++++++++ 3 files changed, 605 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_cmd.h create mode 100644 drivers/net/hinic3/base/hinic3_compat.h create mode 100644 drivers/net/hinic3/base/hinic3_csr.h
drivers/net/hinic3/base/hinic3_cmd.h new file +231 -0
@@ -0,0 +1,231 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#ifndef _HINIC3_CMD_H_ +#define _HINIC3_CMD_H_ + +#define NIC_RSS_TEMP_ID_TO_CTX_LT_IDX (tmp_id) tmp_id +/* Begin of one temp tbl. */ +#define NIC_RSS_TEMP_ID_TO_INDIR_LT_IDX (tmp_id) ((tmp_id) << 4) +/* 4 ctx in one entry. */ +#define NIC_RSS_CTX_TBL_ENTRY_SIZE 0x10 +/* Entry size = 16B, 16 entry/template. */ +#define NIC_RSS_INDIR_TBL_ENTRY_SIZE 0x10 +/* Entry size = 16B, so entry_num = 256B/16B. */ +#define NIC_RSS_INDIR_TBL_ENTRY_NUM 0x10 + +#define NIC_UP_RSS_INVALID_TEMP_ID 0xFF +#define NIC_UP_RSS_INVALID_FUNC_ID 0xFFFF +#define NIC_UP_RSS_INVALID 0x00 +#define NIC_UP_RSS_EN 0x01 +#define NIC_UP_RSS_INVALID_GROUP_ID 0x7F + +#define NIC_RSS_CMD_TEMP_ALLOC 0x01 +#define NIC_RSS_CMD_TEMP_FREE 0x02 + +#define HINIC3_RSS_TYPE_VALID_SHIFT 23 +#define HINIC3_RSS_TYPE_TCP_IPV6_EXT_SHIFT 24 +#define HINIC3_RSS_TYPE_IPV6_EXT_SHIFT 25 +#define HINIC3_RSS_TYPE_TCP_IPV6_SHIFT 26 +#define HINIC3_RSS_TYPE_IPV6_SHIFT 27 +#define HINIC3_RSS_TYPE_TCP_IPV4_SHIFT 28 +#define HINIC3_RSS_TYPE_IPV4_SHIFT 29 +#define HINIC3_RSS_TYPE_UDP_IPV6_SHIFT 30 +#define HINIC3_RSS_TYPE_UDP_IPV4_SHIFT 31 +#define HINIC3_RSS_TYPE_SET (val, member) \ + (((u32)(val) & 0x1) << HINIC3_RSS_TYPE_##member##_SHIFT) + +#define HINIC3_RSS_TYPE_GET (val, member) \ + (((u32)(val) >> HINIC3_RSS_TYPE_##member##_SHIFT) & 0x1) + +/* NIC CMDQ MODE. */ +typedef enum hinic3_ucode_cmd { +HINIC3_UCODE_CMD_MODIFY_QUEUE_CTX =0 , +HINIC3_UCODE_CMD_CLEAN_QUEUE_CONTEXT , +HINIC3_UCODE_CMD_ARM_SQ , +HINIC3_UCODE_CMD_ARM_RQ , +HINIC3_UCODE_CMD_SET_RSS_INDIR_TABLE , +HINIC3_UCODE_CMD_SET_RSS_CONTEXT_TABLE , +HINIC3_UCODE_CMD_GET_RSS_INDIR_TABLE , +HINIC3_UCODE_CMD_GET_RSS_CONTEXT_TABLE , +HINIC3_UCODE_CMD_SET_IQ_ENABLE , +HINIC3_UCODE_CMD_SET_RQ_FLUSH =10 , +HINIC3_UCODE_CMD_MODIFY_VLAN_CTX , +}cmdq_nic_subtype_e ; + +/* Commands between NIC to MPU. */ +enum hinic3_nic_cmd { +/* Only for PFD and VFD. */ +HINIC3_NIC_CMD_VF_REGISTER =0 , + +/* FUNC CFG */ +HINIC3_NIC_CMD_SET_FUNC_TBL =5 , +HINIC3_NIC_CMD_SET_VPORT_ENABLE , +HINIC3_NIC_CMD_SET_RX_MODE , +HINIC3_NIC_CMD_SQ_CI_ATTR_SET , +HINIC3_NIC_CMD_GET_VPORT_STAT , +HINIC3_NIC_CMD_CLEAN_VPORT_STAT , +HINIC3_NIC_CMD_CLEAR_QP_RESOURCE , +HINIC3_NIC_CMD_CFG_FLEX_QUEUE , +/* LRO CFG */ +HINIC3_NIC_CMD_CFG_RX_LRO , +HINIC3_NIC_CMD_CFG_LRO_TIMER , +HINIC3_NIC_CMD_FEATURE_NEGO , + +/* MAC & VLAN CFG */ +HINIC3_NIC_CMD_GET_MAC =20 , +HINIC3_NIC_CMD_SET_MAC , +HINIC3_NIC_CMD_DEL_MAC , +HINIC3_NIC_CMD_UPDATE_MAC , +HINIC3_NIC_CMD_GET_ALL_DEFAULT_MAC , + +HINIC3_NIC_CMD_CFG_FUNC_VLAN , +HINIC3_NIC_CMD_SET_VLAN_FILTER_EN , +HINIC3_NIC_CMD_SET_RX_VLAN_OFFLOAD , + +/* SR-IOV */ +HINIC3_NIC_CMD_CFG_VF_VLAN =40 , +HINIC3_NIC_CMD_SET_SPOOPCHK_STATE , +/* RATE LIMIT */ +HINIC3_NIC_CMD_SET_MAX_MIN_RATE , + +/* RSS CFG */ +HINIC3_NIC_CMD_RSS_CFG =60 , +HINIC3_NIC_CMD_RSS_TEMP_MGR , +HINIC3_NIC_CMD_GET_RSS_CTX_TBL , +HINIC3_NIC_CMD_CFG_RSS_HASH_KEY , +HINIC3_NIC_CMD_CFG_RSS_HASH_ENGINE , +HINIC3_NIC_CMD_SET_RSS_CTX_TBL_INTO_FUNC , + +/* FDIR */ +HINIC3_NIC_CMD_ADD_TC_FLOW =80 , +HINIC3_NIC_CMD_DEL_TC_FLOW , +HINIC3_NIC_CMD_GET_TC_FLOW , +HINIC3_NIC_CMD_FLUSH_TCAM , +HINIC3_NIC_CMD_CFG_TCAM_BLOCK , +HINIC3_NIC_CMD_ENABLE_TCAM , +HINIC3_NIC_CMD_GET_TCAM_BLOCK , + +HINIC3_NIC_CMD_SET_FDIR_STATUS =91 , + +/* PORT CFG */ +HINIC3_NIC_CMD_SET_PORT_ENABLE =100 , +HINIC3_NIC_CMD_CFG_PAUSE_INFO , + +HINIC3_NIC_CMD_SET_PORT_CAR , +HINIC3_NIC_CMD_SET_ER_DROP_PKT , + +HINIC3_NIC_CMD_VF_COS , +HINIC3_NIC_CMD_SETUP_COS_MAPPING , +HINIC3_NIC_CMD_SET_ETS , +HINIC3_NIC_CMD_SET_PFC , + +/* MISC */ +HINIC3_NIC_CMD_BIOS_CFG =120 , +HINIC3_NIC_CMD_SET_FIRMWARE_CUSTOM_PACKETS_MSG , + +/* DFX */ +HINIC3_NIC_CMD_GET_SM_TABLE =140 , +HINIC3_NIC_CMD_RD_LINE_TBL , + +HINIC3_NIC_CMD_SET_VHD_CFG =161 , + +HINIC3_NIC_CMD_GET_PORT_STAT =200 , +HINIC3_NIC_CMD_CLEAN_PORT_STAT , + +HINIC3_NIC_CMD_MAX =256 +}; + +/* COMM commands between driver to MPU. */ +enum hinic3_mgmt_cmd { +HINIC3_MGMT_CMD_FUNC_RESET =0 , +HINIC3_MGMT_CMD_FEATURE_NEGO , +HINIC3_MGMT_CMD_FLUSH_DOORBELL , +HINIC3_MGMT_CMD_START_FLUSH , +HINIC3_MGMT_CMD_SET_FUNC_FLR , +HINIC3_MGMT_CMD_SET_FUNC_SVC_USED_STATE =7 , + +HINIC3_MGMT_CMD_CFG_MSIX_NUM =10 , + +HINIC3_MGMT_CMD_SET_CMDQ_CTXT =20 , +HINIC3_MGMT_CMD_SET_VAT , +HINIC3_MGMT_CMD_CFG_PAGESIZE , +HINIC3_MGMT_CMD_CFG_MSIX_CTRL_REG , +HINIC3_MGMT_CMD_SET_CEQ_CTRL_REG , +HINIC3_MGMT_CMD_SET_DMA_ATTR , + +HINIC3_MGMT_CMD_GET_MQM_FIX_INFO =40 , +HINIC3_MGMT_CMD_SET_MQM_CFG_INFO , +HINIC3_MGMT_CMD_SET_MQM_SRCH_GPA , +HINIC3_MGMT_CMD_SET_PPF_TMR , +HINIC3_MGMT_CMD_SET_PPF_HT_GPA , +HINIC3_MGMT_CMD_SET_FUNC_TMR_BITMAT , + +HINIC3_MGMT_CMD_GET_FW_VERSION =60 , +HINIC3_MGMT_CMD_GET_BOARD_INFO , +HINIC3_MGMT_CMD_SYNC_TIME , +HINIC3_MGMT_CMD_GET_HW_PF_INFOS , +HINIC3_MGMT_CMD_SEND_BDF_INFO , + +HINIC3_MGMT_CMD_UPDATE_FW =80 , +HINIC3_MGMT_CMD_ACTIVE_FW , +HINIC3_MGMT_CMD_HOT_ACTIVE_FW , +HINIC3_MGMT_CMD_HOT_ACTIVE_DONE_NOTICE , +HINIC3_MGMT_CMD_SWITCH_CFG , +HINIC3_MGMT_CMD_CHECK_FLASH , +HINIC3_MGMT_CMD_CHECK_FLASH_RW , +HINIC3_MGMT_CMD_RESOURCE_CFG , +HINIC3_MGMT_CMD_UPDATE_BIOS , + +HINIC3_MGMT_CMD_FAULT_REPORT =100 , +HINIC3_MGMT_CMD_WATCHDOG_INFO , +HINIC3_MGMT_CMD_MGMT_RESET , +HINIC3_MGMT_CMD_FFM_SET , + +HINIC3_MGMT_CMD_GET_LOG =120 , +HINIC3_MGMT_CMD_TEMP_OP , +HINIC3_MGMT_CMD_EN_AUTO_RST_CHIP , +HINIC3_MGMT_CMD_CFG_REG , +HINIC3_MGMT_CMD_GET_CHIP_ID , +HINIC3_MGMT_CMD_SYSINFO_DFX , +HINIC3_MGMT_CMD_PCIE_DFX_NTC , +}; + +enum mag_cmd { +SERDES_CMD_PROCESS =0 , + +MAG_CMD_SET_PORT_CFG =1 , +MAG_CMD_SET_PORT_ADAPT =2 , +MAG_CMD_CFG_LOOPBACK_MODE =3 , + +MAG_CMD_GET_PORT_ENABLE =5 , +MAG_CMD_SET_PORT_ENABLE =6 , +MAG_CMD_GET_LINK_STATUS =7 , +MAG_CMD_SET_LINK_FOLLOW =8 , +MAG_CMD_SET_PMA_ENABLE =9 , +MAG_CMD_CFG_FEC_MODE =10 , + +/* PHY */ +MAG_CMD_GET_XSFP_INFO =60 , +MAG_CMD_SET_XSFP_ENABLE =61 , +MAG_CMD_GET_XSFP_PRESENT =62 , +/* sfp/qsfp single byte read/write, for equipment test. */ +MAG_CMD_SET_XSFP_RW =63 , +MAG_CMD_CFG_XSFP_TEMPERATURE =64 , + +MAG_CMD_WIRE_EVENT =100 , +MAG_CMD_LINK_ERR_EVENT =101 , + +MAG_CMD_EVENT_PORT_INFO =150 , +MAG_CMD_GET_PORT_STAT =151 , +MAG_CMD_CLR_PORT_STAT =152 , +MAG_CMD_GET_PORT_INFO =153 , +MAG_CMD_GET_PCS_ERR_CNT =154 , +MAG_CMD_GET_MAG_CNT =155 , +MAG_CMD_DUMP_ANTRAIN_INFO =156 , + +MAG_CMD_MAX =0xFF +}; + +#endif /* _HINIC3_CMD_H_ */
drivers/net/hinic3/base/hinic3_compat.h new file +266 -0
266 lines not on this page · raw message
drivers/net/hinic3/base/hinic3_csr.h new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 3/18 net/hinic3: add hardware interfaces of BAR operation
In reply to Feifei WangFrom: Yi Chen <[email protected]>
This patch adds some HW interfaces for bar operatioin interfaces,
including: mapped bar address geeting, HW attributes getting, msi-x reg operation, function type getting and so on.
--- drivers/net/hinic3/base/hinic3_hwif.c | 779 ++++++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_hwif.h | 142 +++++ 2 files changed, 921 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_hwif.c create mode 100644 drivers/net/hinic3/base/hinic3_hwif.h
drivers/net/hinic3/base/hinic3_hwif.c new file +779 -0
@@ -0,0 +1,779 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include <rte_bus_pci.h> +#include "hinic3_compat.h" +#include "hinic3_csr.h" +#include "hinic3_hwdev.h" +#include "hinic3_hwif.h" + +#define WAIT_HWIF_READY_TIMEOUT 10000 + +#define DB_IDX (db, db_base) \ + ((u32)(((ulong)(db) - (ulong)(db_base)) / HINIC3_DB_PAGE_SIZE)) + +#define HINIC3_AF0_FUNC_GLOBAL_IDX_SHIFT 0 +#define HINIC3_AF0_P2P_IDX_SHIFT 12 +#define HINIC3_AF0_PCI_INTF_IDX_SHIFT 17 +#define HINIC3_AF0_VF_IN_PF_SHIFT 20 +#define HINIC3_AF0_FUNC_TYPE_SHIFT 28 + +#define HINIC3_AF0_FUNC_GLOBAL_IDX_MASK 0xFFF +#define HINIC3_AF0_P2P_IDX_MASK 0x1F +#define HINIC3_AF0_PCI_INTF_IDX_MASK 0x7 +#define HINIC3_AF0_VF_IN_PF_MASK 0xFF +#define HINIC3_AF0_FUNC_TYPE_MASK 0x1 + +#define HINIC3_AF0_GET (val, member) \ + (((val) >> HINIC3_AF0_##member##_SHIFT) & HINIC3_AF0_##member##_MASK) + +#define HINIC3_AF1_PPF_IDX_SHIFT 0 +#define HINIC3_AF1_AEQS_PER_FUNC_SHIFT 8 +#define HINIC3_AF1_MGMT_INIT_STATUS_SHIFT 30 +#define HINIC3_AF1_PF_INIT_STATUS_SHIFT 31 + +#define HINIC3_AF1_PPF_IDX_MASK 0x3F +#define HINIC3_AF1_AEQS_PER_FUNC_MASK 0x3 +#define HINIC3_AF1_MGMT_INIT_STATUS_MASK 0x1 +#define HINIC3_AF1_PF_INIT_STATUS_MASK 0x1 + +#define HINIC3_AF1_GET (val, member) \ + (((val) >> HINIC3_AF1_##member##_SHIFT) & HINIC3_AF1_##member##_MASK) + +#define HINIC3_AF2_CEQS_PER_FUNC_SHIFT 0 +#define HINIC3_AF2_DMA_ATTR_PER_FUNC_SHIFT 9 +#define HINIC3_AF2_IRQS_PER_FUNC_SHIFT 16 + +#define HINIC3_AF2_CEQS_PER_FUNC_MASK 0x1FF +#define HINIC3_AF2_DMA_ATTR_PER_FUNC_MASK 0x7 +#define HINIC3_AF2_IRQS_PER_FUNC_MASK 0x7FF + +#define HINIC3_AF2_GET (val, member) \ + (((val) >> HINIC3_AF2_##member##_SHIFT) & HINIC3_AF2_##member##_MASK) + +#define HINIC3_AF3_GLOBAL_VF_ID_OF_NXT_PF_SHIFT 0 +#define HINIC3_AF3_GLOBAL_VF_ID_OF_PF_SHIFT 16 + +#define HINIC3_AF3_GLOBAL_VF_ID_OF_NXT_PF_MASK 0xFFF +#define HINIC3_AF3_GLOBAL_VF_ID_OF_PF_MASK 0xFFF + +#define HINIC3_AF3_GET (val, member) \ + (((val) >> HINIC3_AF3_##member##_SHIFT) & HINIC3_AF3_##member##_MASK) + +#define HINIC3_AF4_DOORBELL_CTRL_SHIFT 0 +#define HINIC3_AF4_DOORBELL_CTRL_MASK 0x1 + +#define HINIC3_AF4_GET (val, member) \ + (((val) >> HINIC3_AF4_##member##_SHIFT) & HINIC3_AF4_##member##_MASK) + +#define HINIC3_AF4_SET (val, member) \ + (((val) & HINIC3_AF4_##member##_MASK) << HINIC3_AF4_##member##_SHIFT) + +#define HINIC3_AF4_CLEAR (val, member) \ + ((val) & (~(HINIC3_AF4_##member##_MASK << HINIC3_AF4_##member##_SHIFT))) + +#define HINIC3_AF5_OUTBOUND_CTRL_SHIFT 0 +#define HINIC3_AF5_OUTBOUND_CTRL_MASK 0x1 + +#define HINIC3_AF5_GET (val, member) \ + (((val) >> HINIC3_AF5_##member##_SHIFT) & HINIC3_AF5_##member##_MASK) + +#define HINIC3_AF5_SET (val, member) \ + (((val) & HINIC3_AF5_##member##_MASK) << HINIC3_AF5_##member##_SHIFT) + +#define HINIC3_AF5_CLEAR (val, member) \ + ((val) & (~(HINIC3_AF5_##member##_MASK << HINIC3_AF5_##member##_SHIFT))) + +#define HINIC3_AF6_PF_STATUS_SHIFT 0 +#define HINIC3_AF6_PF_STATUS_MASK 0xFFFF + +#define HINIC3_AF6_FUNC_MAX_QUEUE_SHIFT 23 +#define HINIC3_AF6_FUNC_MAX_QUEUE_MASK 0x1FF + +#define HINIC3_AF6_MSIX_FLEX_EN_SHIFT 22 +#define HINIC3_AF6_MSIX_FLEX_EN_MASK 0x1 + +#define HINIC3_AF6_SET (val, member) \ + ((((u32)(val)) & HINIC3_AF6_##member##_MASK) \ + << HINIC3_AF6_##member##_SHIFT) + +#define HINIC3_AF6_GET (val, member) \ + (((val) >> HINIC3_AF6_##member##_SHIFT) & HINIC3_AF6_##member##_MASK) + +#define HINIC3_AF6_CLEAR (val, member) \ + ((val) & (~(HINIC3_AF6_##member##_MASK << HINIC3_AF6_##member##_SHIFT))) + +#define HINIC3_PPF_ELECTION_IDX_SHIFT 0 + +#define HINIC3_PPF_ELECTION_IDX_MASK 0x3F + +#define HINIC3_PPF_ELECTION_SET (val, member) \ + (((val) & HINIC3_PPF_ELECTION_##member##_MASK) \ + << HINIC3_PPF_ELECTION_##member##_SHIFT) + +#define HINIC3_PPF_ELECTION_GET (val, member) \ + (((val) >> HINIC3_PPF_ELECTION_##member##_SHIFT) & \ + HINIC3_PPF_ELECTION_##member##_MASK) + +#define HINIC3_PPF_ELECTION_CLEAR (val, member) \ + ((val) & (~(HINIC3_PPF_ELECTION_##member##_MASK \ + << HINIC3_PPF_ELECTION_##member##_SHIFT))) + +#define HINIC3_MPF_ELECTION_IDX_SHIFT 0 + +#define HINIC3_MPF_ELECTION_IDX_MASK 0x1F + +#define HINIC3_MPF_ELECTION_SET (val, member) \ + (((val) & HINIC3_MPF_ELECTION_##member##_MASK) \ + << HINIC3_MPF_ELECTION_##member##_SHIFT) + +#define HINIC3_MPF_ELECTION_GET (val, member) \ + (((val) >> HINIC3_MPF_ELECTION_##member##_SHIFT) & \ + HINIC3_MPF_ELECTION_##member##_MASK) + +#define HINIC3_MPF_ELECTION_CLEAR (val, member) \ + ((val) & (~(HINIC3_MPF_ELECTION_##member##_MASK \ + << HINIC3_MPF_ELECTION_##member##_SHIFT))) + +#define HINIC3_GET_REG_FLAG (reg) ((reg) & (~(HINIC3_REGS_FLAG_MAKS))) + +#define HINIC3_GET_REG_ADDR (reg) ((reg) & (HINIC3_REGS_FLAG_MAKS)) + +#define HINIC3_IS_VF_DEV (pdev) ((pdev)->id.device_id == HINIC3_DEV_ID_VF) + +u32 +hinic3_hwif_read_reg (struct hinic3_hwif *hwif,u32 reg) +{ +if (HINIC3_GET_REG_FLAG (reg) ==HINIC3_MGMT_REGS_FLAG ) +return be32_to_cpu (rte_read32 (hwif->mgmt_regs_base + +HINIC3_GET_REG_ADDR (reg))); +else +return be32_to_cpu (rte_read32 (hwif->cfg_regs_base + +HINIC3_GET_REG_ADDR (reg))); +} + +void +hinic3_hwif_write_reg (struct hinic3_hwif *hwif,u32 reg,u32 val) +{ +if (HINIC3_GET_REG_FLAG (reg) ==HINIC3_MGMT_REGS_FLAG ) +rte_write32 (cpu_to_be32 (val), + hwif->mgmt_regs_base +HINIC3_GET_REG_ADDR (reg)); +else +rte_write32 (cpu_to_be32 (val), + hwif->cfg_regs_base +HINIC3_GET_REG_ADDR (reg)); +} + +/** +* Judge whether HW initialization ok. +* +* @param[in] hwdev +* The pointer to the private hardware device. +* @return +* 0 on success, non-zero on failure. +*/ +static int +hwif_ready (struct hinic3_hwdev *hwdev) +{ +u32 addr, attr1; + + addr =HINIC3_CSR_FUNC_ATTR1_ADDR ; + attr1 =hinic3_hwif_read_reg (hwdev->hwif, addr); +if (attr1 ==HINIC3_PCIE_LINK_DOWN ) +return -EBUSY ; + +if (!HINIC3_AF1_GET (attr1,MGMT_INIT_STATUS )) +return -EBUSY ; + +return 0 ; +} + +static int +wait_hwif_ready (struct hinic3_hwdev *hwdev) +{ +ulong timeout =0 ; + +do { +if (!hwif_ready (hwdev)) +return 0 ; + +rte_delay_ms (1 ); + timeout++; + }while (timeout <=WAIT_HWIF_READY_TIMEOUT ); + +PMD_DRV_LOG (ERR ,"Hwif is not ready" ); +return -EBUSY ; +} + +/** +* Set the attributes as members in hwif. +* +* @param[in] hwif +* The hardware interface of a pci function device. +* @param[in] attr0 +* The first attribute that was read from the hw. +* @param[in] attr1 +* The second attribute that was read from the hw. +* @param[in] attr2 +* The third attribute that was read from the hw. +* @param[in] attr3 +* The fourth attribute that was read from the hw. +*/ +static void +set_hwif_attr (struct hinic3_hwif *hwif,u32 attr0,u32 attr1,u32 attr2, +u32 attr3) +{ + hwif->attr.func_global_idx =HINIC3_AF0_GET (attr0,FUNC_GLOBAL_IDX ); + hwif->attr.port_to_port_idx =HINIC3_AF0_GET (attr0,P2P_IDX ); + hwif->attr.pci_intf_idx =HINIC3_AF0_GET (attr0,PCI_INTF_IDX ); + hwif->attr.vf_in_pf =HINIC3_AF0_GET (attr0,VF_IN_PF ); + hwif->attr.func_type =HINIC3_AF0_GET (attr0,FUNC_TYPE ); + + hwif->attr.ppf_idx =HINIC3_AF1_GET (attr1,PPF_IDX ); + hwif->attr.num_aeqs =BIT (HINIC3_AF1_GET (attr1,AEQS_PER_FUNC )); + + hwif->attr.num_ceqs = (u8 )HINIC3_AF2_GET (attr2,CEQS_PER_FUNC ); + hwif->attr.num_irqs =HINIC3_AF2_GET (attr2,IRQS_PER_FUNC ); + hwif->attr.num_dma_attr =BIT (HINIC3_AF2_GET (attr2,DMA_ATTR_PER_FUNC )); + + hwif->attr.global_vf_id_of_pf = +HINIC3_AF3_GET (attr3,GLOBAL_VF_ID_OF_PF ); +} + +/** +* Read and set the attributes as members in hwif. +* +* @param[in] hwif +* The hardware interface of a pci function device. +*/ +static void +get_hwif_attr (struct hinic3_hwif *hwif) +{ +u32 addr, attr0, attr1, attr2, attr3; + + addr =HINIC3_CSR_FUNC_ATTR0_ADDR ; + attr0 =hinic3_hwif_read_reg (hwif, addr); + + addr =HINIC3_CSR_FUNC_ATTR1_ADDR ; + attr1 =hinic3_hwif_read_reg (hwif, addr); + + addr =HINIC3_CSR_FUNC_ATTR2_ADDR ; + attr2 =hinic3_hwif_read_reg (hwif, addr); + + addr =HINIC3_CSR_FUNC_ATTR3_ADDR ; + attr3 =hinic3_hwif_read_reg (hwif, addr); + +set_hwif_attr (hwif, attr0, attr1, attr2, attr3); +} + +/** +* Update message signaled interrupt information. +* +* @param[in] hwif +* The hardware interface of a pci function device. +*/ +void +hinic3_update_msix_info (struct hinic3_hwif *hwif) +{ +u32 attr6 =hinic3_hwif_read_reg (hwif,HINIC3_CSR_FUNC_ATTR6_ADDR ); + hwif->attr.num_queue =HINIC3_AF6_GET (attr6,FUNC_MAX_QUEUE ); + hwif->attr.msix_flex_en =HINIC3_AF6_GET (attr6,MSIX_FLEX_EN ); +PMD_DRV_LOG (INFO ,"msix_flex_en: %u, queue msix: %u" , + hwif->attr.msix_flex_en, hwif->attr.num_queue); +} + +void +hinic3_set_pf_status (struct hinic3_hwif *hwif,enum hinic3_pf_status status) +{ +u32 attr6 =hinic3_hwif_read_reg (hwif,HINIC3_CSR_FUNC_ATTR6_ADDR ); + + attr6 =HINIC3_AF6_CLEAR (attr6,PF_STATUS ); + attr6 |=HINIC3_AF6_SET (status,PF_STATUS ); + +if (hwif->attr.func_type ==TYPE_VF ) +return ; + +hinic3_hwif_write_reg (hwif,HINIC3_CSR_FUNC_ATTR6_ADDR , attr6); +} + +enum hinic3_pf_status +hinic3_get_pf_status (struct hinic3_hwif *hwif) +{ +u32 attr6 =hinic3_hwif_read_reg (hwif,HINIC3_CSR_FUNC_ATTR6_ADDR ); + +return HINIC3_AF6_GET (attr6,PF_STATUS ); +} + +static enum hinic3_doorbell_ctrl +hinic3_get_doorbell_ctrl_status (struct hinic3_hwif *hwif) +{ +u32 attr4 =hinic3_hwif_read_reg (hwif,HINIC3_CSR_FUNC_ATTR4_ADDR ); + +return HINIC3_AF4_GET (attr4,DOORBELL_CTRL ); +} + +static enum hinic3_outbound_ctrl +hinic3_get_outbound_ctrl_status (struct hinic3_hwif *hwif) +{ +u32 attr5 =hinic3_hwif_read_reg (hwif,HINIC3_CSR_FUNC_ATTR5_ADDR ); + +return HINIC3_AF5_GET (attr5,OUTBOUND_CTRL ); +} + +void +hinic3_enable_doorbell (struct hinic3_hwif *hwif) +{ +u32 addr, attr4; + + addr =HINIC3_CSR_FUNC_ATTR4_ADDR ; + attr4 =hinic3_hwif_read_reg (hwif, addr); + + attr4 =HINIC3_AF4_CLEAR (attr4,DOORBELL_CTRL ); + attr4 |=HINIC3_AF4_SET (ENABLE_DOORBELL ,DOORBELL_CTRL ); + +hinic3_hwif_write_reg (hwif, addr, attr4); +} + +void +hinic3_disable_doorbell (struct hinic3_hwif *hwif) +{ +u32 addr, attr4; + + addr =HINIC3_CSR_FUNC_ATTR4_ADDR ; + attr4 =hinic3_hwif_read_reg (hwif, addr); + + attr4 =HINIC3_AF4_CLEAR (attr4,DOORBELL_CTRL ); + attr4 |=HINIC3_AF4_SET (DISABLE_DOORBELL ,DOORBELL_CTRL ); + +hinic3_hwif_write_reg (hwif, addr, attr4); +} + +/** +* Try to set hwif as ppf and set the type of hwif in this case. +* +* @param[in] hwif +* The hardware interface of a pci function device +*/ +static void +set_ppf (struct hinic3_hwif *hwif) +{ +struct hinic3_func_attr *attr = &hwif->attr; +u32 addr, val, ppf_election; + + addr =HINIC3_CSR_PPF_ELECTION_ADDR ; + + val =hinic3_hwif_read_reg (hwif, addr); + val =HINIC3_PPF_ELECTION_CLEAR (val,IDX ); + + ppf_election =HINIC3_PPF_ELECTION_SET (attr->func_global_idx,IDX ); + val |= ppf_election; + +hinic3_hwif_write_reg (hwif, addr, val); + +/* Check PPF. */ + val =hinic3_hwif_read_reg (hwif, addr); + + attr->ppf_idx =HINIC3_PPF_ELECTION_GET (val,IDX ); +if (attr->ppf_idx == attr->func_global_idx) + attr->func_type =TYPE_PPF ; +} + +/** +* Get the mpf index from the hwif. +* +* @param[in] hwif +* The hardware interface of a pci function device. +*/ +static void +get_mpf (struct hinic3_hwif *hwif) +{ +struct hinic3_func_attr *attr = &hwif->attr; +u32 mpf_election, addr; + + addr =HINIC3_CSR_GLOBAL_MPF_ELECTION_ADDR ; + + mpf_election =hinic3_hwif_read_reg (hwif, addr); + attr->mpf_idx =HINIC3_MPF_ELECTION_GET (mpf_election,IDX ); +} + +/** +* Try to set hwif as mpf and set the mpf idx in hwif. +* +* @param[in] hwif +* The hardware interface of a pci function device. +*/ +static void +set_mpf (struct hinic3_hwif *hwif) +{ +struct hinic3_func_attr *attr = &hwif->attr; +u32 addr, val, mpf_election; + + addr =HINIC3_CSR_GLOBAL_MPF_ELECTION_ADDR ; + + val =hinic3_hwif_read_reg (hwif, addr); + + val =HINIC3_MPF_ELECTION_CLEAR (val,IDX ); + mpf_election =HINIC3_MPF_ELECTION_SET (attr->func_global_idx,IDX ); + + val |= mpf_election; +hinic3_hwif_write_reg (hwif, addr, val); +} + +int +hinic3_alloc_db_addr (void *hwdev,void **db_base, +enum hinic3_db_type queue_type) +{ +struct hinic3_hwif *hwif =NULL ; + +if (!hwdev || !db_base) +return -EINVAL ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + *db_base = hwif->db_base + queue_type *HINIC3_DB_PAGE_SIZE ; + +return 0 ; +} + +void +hinic3_set_msix_auto_mask_state (void *hwdev,u16 msix_idx, +enum hinic3_msix_auto_mask flag) +{ +struct hinic3_hwif *hwif =NULL ; +u32 mask_bits; +u32 addr; + +if (!hwdev) +return ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + +if (flag) + mask_bits =HINIC3_MSI_CLR_INDIR_SET (1 ,AUTO_MSK_SET ); +else + mask_bits =HINIC3_MSI_CLR_INDIR_SET (1 ,AUTO_MSK_CLR ); + + mask_bits = mask_bits | +HINIC3_MSI_CLR_INDIR_SET (msix_idx,SIMPLE_INDIR_IDX ); + + addr =HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR ; +hinic3_hwif_write_reg (hwif, addr, mask_bits); +} + +/** +* Set msix state. +* +* @param[in] hwdev +* The pointer to the private hardware device object. +* @param[in] msix_idx +* MSIX(Message Signaled Interrupts) index. +* @param[in] flag +* MSIX state flag, 0-enable, 1-disable. +*/ +void +hinic3_set_msix_state (void *hwdev,u16 msix_idx,enum hinic3_msix_state flag) +{ +struct hinic3_hwif *hwif =NULL ; +u32 mask_bits; +u32 addr; +u8 int_msk =1 ; + +if (!hwdev) +return ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + +if (flag) + mask_bits =HINIC3_MSI_CLR_INDIR_SET (int_msk,INT_MSK_SET ); +else + mask_bits =HINIC3_MSI_CLR_INDIR_SET (int_msk,INT_MSK_CLR ); + mask_bits = mask_bits | +HINIC3_MSI_CLR_INDIR_SET (msix_idx,SIMPLE_INDIR_IDX ); + + addr =HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR ; +hinic3_hwif_write_reg (hwif, addr, mask_bits); +} + +static void +disable_all_msix (struct hinic3_hwdev *hwdev) +{ +u16 num_irqs = hwdev->hwif->attr.num_irqs; +u16 i; + +for (i =0 ; i < num_irqs; i++) +hinic3_set_msix_state (hwdev, i,HINIC3_MSIX_DISABLE ); +} + +/** +* Clear msix resend bit. +* +* @param[in] hwdev +* The pointer to the private hardware device object. +* @param[in] msix_idx +* MSIX(Message Signaled Interrupts) index +* @param[in] clear_resend_en +* Clear resend en flag, 1-clear. +*/ +void +hinic3_misx_intr_clear_resend_bit (void *hwdev,u16 msix_idx,u8 clear_resend_en) +{ +struct hinic3_hwif *hwif =NULL ; +u32 msix_ctrl =0 , addr; + +if (!hwdev) +return ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + + msix_ctrl =HINIC3_MSI_CLR_INDIR_SET (msix_idx,SIMPLE_INDIR_IDX ) | +HINIC3_MSI_CLR_INDIR_SET (clear_resend_en,RESEND_TIMER_CLR ); + + addr =HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR ; +hinic3_hwif_write_reg (hwif, addr, msix_ctrl); +} + +#ifdef HINIC3_RELEASE +static int +wait_until_doorbell_flush_states (struct hinic3_hwif *hwif, +enum hinic3_doorbell_ctrl states) +{ +enum hinic3_doorbell_ctrl db_ctrl; +u32 cnt =0 ; + +if (!hwif) +return -EINVAL ; + +while (cnt <HINIC3_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT ) { + db_ctrl =hinic3_get_doorbell_ctrl_status (hwif); +if (db_ctrl == states) +return 0 ; + +rte_delay_ms (1 ); + cnt++; + } + +return -EFAULT ; +} +#endif + +static int +wait_until_doorbell_and_outbound_enabled (struct hinic3_hwif *hwif) +{ +enum hinic3_doorbell_ctrl db_ctrl; +enum hinic3_outbound_ctrl outbound_ctrl; +u32 cnt =0 ; + +while (cnt <HINIC3_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT ) { + db_ctrl =hinic3_get_doorbell_ctrl_status (hwif); + outbound_ctrl =hinic3_get_outbound_ctrl_status (hwif); +if (outbound_ctrl ==ENABLE_OUTBOUND && + db_ctrl ==ENABLE_DOORBELL ) +return 0 ; + +rte_delay_ms (1 ); + cnt++; + } + +return -EFAULT ; +} + +static int +hinic3_get_bar_addr (struct hinic3_hwdev *hwdev) +{ +struct rte_pci_device *pci_dev = hwdev->pci_dev; +struct hinic3_hwif *hwif = hwdev->hwif; +void *cfg_regs_base =NULL ; +void *mgmt_reg_base =NULL ; +void *db_base =NULL ; +int cfg_bar; + + cfg_bar =HINIC3_IS_VF_DEV (pci_dev) ?HINIC3_VF_PCI_CFG_REG_BAR + :HINIC3_PF_PCI_CFG_REG_BAR ; + + cfg_regs_base = pci_dev->mem_resource[cfg_bar].addr; +if (!HINIC3_IS_VF_DEV (pci_dev)) { + mgmt_reg_base = + pci_dev->mem_resource[HINIC3_PCI_MGMT_REG_BAR ].addr; +if (mgmt_reg_base ==NULL ) { +PMD_DRV_LOG (ERR ,"mgmt_reg_base addr is null" ); +return -EFAULT ; + } + } + db_base = pci_dev->mem_resource[HINIC3_PCI_DB_BAR ].addr; +if (cfg_regs_base ==NULL ) { +PMD_DRV_LOG (ERR , +"mem_resource addr is null, cfg_regs_base is NULL" ); +return -EFAULT ; + }else if (db_base ==NULL ) { +PMD_DRV_LOG (ERR ,"mem_resource addr is null, db_base is NULL" ); +return -EFAULT ; + } + +/* If function is VF, mgmt_regs_base will be NULL. */ +if (!mgmt_reg_base) + hwif->cfg_regs_base = + (u8 *)cfg_regs_base +HINIC3_VF_CFG_REG_OFFSET ; +else + hwif->cfg_regs_base = cfg_regs_base; + hwif->mgmt_regs_base = mgmt_reg_base; + hwif->db_base = db_base; + hwif->db_dwqe_len = pci_dev->mem_resource[HINIC3_PCI_DB_BAR ].len; + +return 0 ; +} + +/** +* Initialize the hw interface. +* +* @param[in] hwdev +* The pointer to the private hardware device object. +* @return +* 0 on success, non-zero on failure. +*/ +int +hinic3_init_hwif (void *dev) +{ +struct hinic3_hwdev *hwdev =NULL ; +struct hinic3_hwif *hwif; +int err; +u32 attr4, attr5; + + hwif =rte_zmalloc ("hinic_hwif" ,sizeof (struct hinic3_hwif ), +RTE_CACHE_LINE_SIZE ); +if (!hwif) +return -ENOMEM ; + + hwdev = (struct hinic3_hwdev *)dev; + hwdev->hwif = hwif; + + err =hinic3_get_bar_addr (hwdev); +if (err !=0 ) { +PMD_DRV_LOG (ERR ,"get bar addr fail" ); + goto hwif_ready_err; + } + + err =wait_hwif_ready (hwdev); +if (err !=0 ) { +PMD_DRV_LOG (ERR ,"Chip status is not ready" ); + goto hwif_ready_err; + } + +get_hwif_attr (hwif); + + err =wait_until_doorbell_and_outbound_enabled (hwif); +if (err !=0 ) { + attr4 =hinic3_hwif_read_reg (hwif,HINIC3_CSR_FUNC_ATTR4_ADDR ); + attr5 =hinic3_hwif_read_reg (hwif,HINIC3_CSR_FUNC_ATTR5_ADDR ); +PMD_DRV_LOG (ERR , +"Hw doorbell/outbound is disabled, attr4 0x%x " +"attr5 0x%x" , + attr4, attr5); + goto hwif_ready_err; + } + +if (!HINIC3_IS_VF (hwdev)) { +set_ppf (hwif); + +if (HINIC3_IS_PPF (hwdev)) +set_mpf (hwif); + +get_mpf (hwif); + } + +disable_all_msix (hwdev); +/* Disable mgmt cpu reporting any event. */ +hinic3_set_pf_status (hwdev->hwif,HINIC3_PF_STATUS_INIT ); + +PMD_DRV_LOG (INFO , +"global_func_idx: %d, func_type: %d, host_id: %d, ppf: %d, " +"mpf: %d" , + hwif->attr.func_global_idx, hwif->attr.func_type, + hwif->attr.pci_intf_idx, hwif->attr.ppf_idx, + hwif->attr.mpf_idx); + +return 0 ; + +hwif_ready_err: +rte_free (hwdev->hwif); + hwdev->hwif =NULL ; + +return err; +} + +/** +* Free the hw interface. +* +* @param[in] dev +* The pointer to the private hardware device. +*/ +void +hinic3_free_hwif (void *dev) +{ +struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev; + +rte_free (hwdev->hwif); +} + +u16 +hinic3_global_func_id (void *hwdev) +{ +struct hinic3_hwif *hwif =NULL ; + +if (!hwdev) +return 0 ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + +return hwif->attr.func_global_idx; +} + +u8 +hinic3_pf_id_of_vf (void *hwdev) +{ +struct hinic3_hwif *hwif =NULL ; + +if (!hwdev) +return 0 ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + +return hwif->attr.port_to_port_idx; +} + +u8 +hinic3_pcie_itf_id (void *hwdev) +{ +struct hinic3_hwif *hwif =NULL ; + +if (!hwdev) +return 0 ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + +return hwif->attr.pci_intf_idx; +} + +enum func_type +hinic3_func_type (void *hwdev) +{ +struct hinic3_hwif *hwif =NULL ; + +if (!hwdev) +return 0 ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + +return hwif->attr.func_type; +} + +u16 +hinic3_glb_pf_vf_offset (void *hwdev) +{ +struct hinic3_hwif *hwif =NULL ; + +if (!hwdev) +return 0 ; + + hwif = ((struct hinic3_hwdev *)hwdev)->hwif; + +return hwif->attr.global_vf_id_of_pf; +}
drivers/net/hinic3/base/hinic3_hwif.h new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 4/18 net/hinic3: add support for cmdq mechanism
In reply to Feifei WangFrom: Xin Wang <[email protected]>
Micocode is named ucode in SP series NIC. Its main responsibility is data transmission and reception. But it can also handle some administration works. It uses cmdq mechanism. This patch introduces data structures, initialization, interfaces, and commands sending functions of cmdq.
--- drivers/net/hinic3/base/hinic3_cmdq.c | 975 ++++++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_cmdq.h | 230 ++++++ 2 files changed, 1205 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.c create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.h
drivers/net/hinic3/base/hinic3_cmdq.c new file +975 -0
@@ -0,0 +1,975 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include <rte_mbuf.h> + +#include "hinic3_compat.h" +#include "hinic3_cmd.h" +#include "hinic3_cmdq.h" +#include "hinic3_hwdev.h" +#include "hinic3_hwif.h" +#include "hinic3_mgmt.h" +#include "hinic3_wq.h" + +#define CMDQ_CMD_TIMEOUT 5000/**< Millisecond. */ + +#define UPPER_8_BITS (data) (((data) >> 8) & 0xFF) +#define LOWER_8_BITS (data) ((data) & 0xFF) + +#define CMDQ_DB_INFO_HI_PROD_IDX_SHIFT 0 +#define CMDQ_DB_INFO_HI_PROD_IDX_MASK 0xFFU + +#define CMDQ_DB_INFO_SET (val, member) \ + ((((u32)(val)) & CMDQ_DB_INFO_##member##_MASK) \ + << CMDQ_DB_INFO_##member##_SHIFT) +#define CMDQ_DB_INFO_UPPER_32 (val) ((u64)(val) << 32) + +#define CMDQ_DB_HEAD_QUEUE_TYPE_SHIFT 23 +#define CMDQ_DB_HEAD_CMDQ_TYPE_SHIFT 24 +#define CMDQ_DB_HEAD_SRC_TYPE_SHIFT 27 +#define CMDQ_DB_HEAD_QUEUE_TYPE_MASK 0x1U +#define CMDQ_DB_HEAD_CMDQ_TYPE_MASK 0x7U +#define CMDQ_DB_HEAD_SRC_TYPE_MASK 0x1FU +#define CMDQ_DB_HEAD_SET (val, member) \ + ((((u32)(val)) & CMDQ_DB_HEAD_##member##_MASK) \ + << CMDQ_DB_HEAD_##member##_SHIFT) + +#define CMDQ_CTRL_PI_SHIFT 0 +#define CMDQ_CTRL_CMD_SHIFT 16 +#define CMDQ_CTRL_MOD_SHIFT 24 +#define CMDQ_CTRL_ACK_TYPE_SHIFT 29 +#define CMDQ_CTRL_HW_BUSY_BIT_SHIFT 31 + +#define CMDQ_CTRL_PI_MASK 0xFFFFU +#define CMDQ_CTRL_CMD_MASK 0xFFU +#define CMDQ_CTRL_MOD_MASK 0x1FU +#define CMDQ_CTRL_ACK_TYPE_MASK 0x3U +#define CMDQ_CTRL_HW_BUSY_BIT_MASK 0x1U + +#define CMDQ_CTRL_SET (val, member) \ + (((u32)(val) & CMDQ_CTRL_##member##_MASK) << CMDQ_CTRL_##member##_SHIFT) + +#define CMDQ_CTRL_GET (val, member) \ + (((val) >> CMDQ_CTRL_##member##_SHIFT) & CMDQ_CTRL_##member##_MASK) + +#define CMDQ_WQE_HEADER_BUFDESC_LEN_SHIFT 0 +#define CMDQ_WQE_HEADER_COMPLETE_FMT_SHIFT 15 +#define CMDQ_WQE_HEADER_DATA_FMT_SHIFT 22 +#define CMDQ_WQE_HEADER_COMPLETE_REQ_SHIFT 23 +#define CMDQ_WQE_HEADER_COMPLETE_SECT_LEN_SHIFT 27 +#define CMDQ_WQE_HEADER_CTRL_LEN_SHIFT 29 +#define CMDQ_WQE_HEADER_HW_BUSY_BIT_SHIFT 31 + +#define CMDQ_WQE_HEADER_BUFDESC_LEN_MASK 0xFFU +#define CMDQ_WQE_HEADER_COMPLETE_FMT_MASK 0x1U +#define CMDQ_WQE_HEADER_DATA_FMT_MASK 0x1U +#define CMDQ_WQE_HEADER_COMPLETE_REQ_MASK 0x1U +#define CMDQ_WQE_HEADER_COMPLETE_SECT_LEN_MASK 0x3U +#define CMDQ_WQE_HEADER_CTRL_LEN_MASK 0x3U +#define CMDQ_WQE_HEADER_HW_BUSY_BIT_MASK 0x1U + +#define CMDQ_WQE_HEADER_SET (val, member) \ + (((u32)(val) & CMDQ_WQE_HEADER_##member##_MASK) \ + << CMDQ_WQE_HEADER_##member##_SHIFT) + +#define CMDQ_WQE_HEADER_GET (val, member) \ + (((val) >> CMDQ_WQE_HEADER_##member##_SHIFT) & \ + CMDQ_WQE_HEADER_##member##_MASK) + +#define CMDQ_CTXT_CURR_WQE_PAGE_PFN_SHIFT 0 +#define CMDQ_CTXT_EQ_ID_SHIFT 53 +#define CMDQ_CTXT_CEQ_ARM_SHIFT 61 +#define CMDQ_CTXT_CEQ_EN_SHIFT 62 +#define CMDQ_CTXT_HW_BUSY_BIT_SHIFT 63 + +#define CMDQ_CTXT_CURR_WQE_PAGE_PFN_MASK 0xFFFFFFFFFFFFF +#define CMDQ_CTXT_EQ_ID_MASK 0xFF +#define CMDQ_CTXT_CEQ_ARM_MASK 0x1 +#define CMDQ_CTXT_CEQ_EN_MASK 0x1 +#define CMDQ_CTXT_HW_BUSY_BIT_MASK 0x1 + +#define CMDQ_CTXT_PAGE_INFO_SET (val, member) \ + (((u64)(val) & CMDQ_CTXT_##member##_MASK) << CMDQ_CTXT_##member##_SHIFT) + +#define CMDQ_CTXT_WQ_BLOCK_PFN_SHIFT 0 +#define CMDQ_CTXT_CI_SHIFT 52 + +#define CMDQ_CTXT_WQ_BLOCK_PFN_MASK 0xFFFFFFFFFFFFF +#define CMDQ_CTXT_CI_MASK 0xFFF + +#define CMDQ_CTXT_BLOCK_INFO_SET (val, member) \ + (((u64)(val) & CMDQ_CTXT_##member##_MASK) << CMDQ_CTXT_##member##_SHIFT) + +#define SAVED_DATA_ARM_SHIFT 31 + +#define SAVED_DATA_ARM_MASK 0x1U + +#define SAVED_DATA_SET (val, member) \ + (((val) & SAVED_DATA_##member##_MASK) << SAVED_DATA_##member##_SHIFT) + +#define SAVED_DATA_CLEAR (val, member) \ + ((val) & (~(SAVED_DATA_##member##_MASK << SAVED_DATA_##member##_SHIFT))) + +#define WQE_ERRCODE_VAL_SHIFT 0 + +#define WQE_ERRCODE_VAL_MASK 0x7FFFFFFF + +#define WQE_ERRCODE_GET (val, member) \ + (((val) >> WQE_ERRCODE_##member##_SHIFT) & WQE_ERRCODE_##member##_MASK) + +#define WQE_COMPLETED (ctrl_info) CMDQ_CTRL_GET(ctrl_info, HW_BUSY_BIT) + +#define WQE_HEADER (wqe) ((struct hinic3_cmdq_header *)(wqe)) + +#define CMDQ_DB_PI_OFF (pi) (((u16)LOWER_8_BITS(pi)) << 3) + +#define CMDQ_DB_ADDR (db_base, pi) (((u8 *)(db_base)) + CMDQ_DB_PI_OFF(pi)) + +#define CMDQ_PFN (addr, page_size) ((addr) >> (ilog2(page_size))) + +#define FIRST_DATA_TO_WRITE_LAST sizeof(u64) + +#define WQE_LCMD_SIZE 64 +#define WQE_SCMD_SIZE 64 + +#define COMPLETE_LEN 3 + +#define CMDQ_WQEBB_SIZE 64 +#define CMDQ_WQEBB_SHIFT 6 + +#define CMDQ_WQE_SIZE 64 + +#define HINIC3_CMDQ_WQ_BUF_SIZE 4096 + +#define WQE_NUM_WQEBBS (wqe_size, wq) \ + ({ \ + typeof(wq) __wq = (wq); \ + (u16)(RTE_ALIGN((u32)(wqe_size), __wq->wqebb_size) / \ + __wq->wqebb_size); \ + }) + +#define cmdq_to_cmdqs (cmdq) \ + ({ \ + typeof(cmdq) __cmdq = (cmdq); \ + container_of(__cmdq - __cmdq->cmdq_type, struct hinic3_cmdqs, \ + __cmdq[0]); \ + }) + +#define WAIT_CMDQ_ENABLE_TIMEOUT 300 + +static int hinic3_cmdq_poll_msg (struct hinic3_cmdq *cmdq,u32 timeout); + +bool +hinic3_cmdq_idle (struct hinic3_cmdq *cmdq) +{ +struct hinic3_wq *wq = cmdq->wq; + +return rte_atomic_load_explicit (&wq->delta, rte_memory_order_seq_cst) == + wq->q_depth; +} + +struct hinic3_cmd_buf * +hinic3_alloc_cmd_buf (void *hwdev) +{ +struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs; +struct hinic3_cmd_buf *cmd_buf; + + cmd_buf =rte_zmalloc (NULL ,sizeof (*cmd_buf),0 ); +if (!cmd_buf) { +PMD_DRV_LOG (ERR ,"Allocate cmd buffer failed" ); +return NULL ; + } + + cmd_buf->mbuf =rte_pktmbuf_alloc (cmdqs->cmd_buf_pool); +if (!cmd_buf->mbuf) { +PMD_DRV_LOG (ERR ,"Allocate cmd from the pool failed" ); + goto alloc_pci_buf_err; + } + + cmd_buf->dma_addr =rte_mbuf_data_iova (cmd_buf->mbuf); + cmd_buf->buf = rte_pktmbuf_mtod(cmd_buf->mbuf, void *); + +return cmd_buf; + +alloc_pci_buf_err: +rte_free (cmd_buf); +return NULL ; +} + +void +hinic3_free_cmd_buf (struct hinic3_cmd_buf *cmd_buf) +{ +rte_pktmbuf_free (cmd_buf->mbuf); + +rte_free (cmd_buf); +} + +static u32 +cmdq_wqe_size (enum cmdq_wqe_type wqe_type) +{ +u32 wqe_size =0 ; + +switch (wqe_type) { +case WQE_LCMD_TYPE : + wqe_size =WQE_LCMD_SIZE ; +break ; +case WQE_SCMD_TYPE : + wqe_size =WQE_SCMD_SIZE ; +break ; +default : +break ; + } + +return wqe_size; +} + +static int +cmdq_get_wqe_size (enum bufdesc_len len) +{ +int wqe_size =0 ; + +switch (len) { +case BUFDESC_LCMD_LEN : + wqe_size =WQE_LCMD_SIZE ; +break ; +case BUFDESC_SCMD_LEN : + wqe_size =WQE_SCMD_SIZE ; +break ; +default : +break ; + } + +return wqe_size; +} + +static void +cmdq_set_completion (struct hinic3_cmdq_completion *complete, +struct hinic3_cmd_buf *buf_out) +{ +struct hinic3_sge_resp *sge_resp = &complete->sge_resp; + +hinic3_set_sge (&sge_resp->sge, buf_out->dma_addr,HINIC3_CMDQ_BUF_SIZE ); +} + +static void +cmdq_set_lcmd_bufdesc (struct hinic3_cmdq_wqe_lcmd *wqe, +struct hinic3_cmd_buf *buf_in) +{ +hinic3_set_sge (&wqe->buf_desc.sge, buf_in->dma_addr, buf_in->size); +} + +static void +cmdq_set_db (struct hinic3_cmdq *cmdq,enum hinic3_cmdq_type cmdq_type, +u16 prod_idx) +{ +u64 db =0 ; + +/* Hardware will do endianness coverting. */ + db =CMDQ_DB_INFO_SET (UPPER_8_BITS (prod_idx),HI_PROD_IDX ); + db =CMDQ_DB_INFO_UPPER_32 (db) | +CMDQ_DB_HEAD_SET (HINIC3_DB_CMDQ_TYPE ,QUEUE_TYPE ) | +CMDQ_DB_HEAD_SET (cmdq_type,CMDQ_TYPE ) | +CMDQ_DB_HEAD_SET (HINIC3_DB_SRC_CMDQ_TYPE ,SRC_TYPE ); + +rte_wmb ();/**< Write all before the doorbell. */ + +rte_write64 (db,CMDQ_DB_ADDR (cmdq->db_base, prod_idx)); +} + +static void +cmdq_wqe_fill (void *dst,void *src) +{ +memcpy ((void *)((u8 *)dst +FIRST_DATA_TO_WRITE_LAST ), + (void *)((u8 *)src +FIRST_DATA_TO_WRITE_LAST ), +CMDQ_WQE_SIZE -FIRST_DATA_TO_WRITE_LAST ); + +rte_wmb ();/**< The first 8 bytes should be written last. */ + + *(u64 *)dst = *(u64 *)src; +} + +static void +cmdq_prepare_wqe_ctrl (struct hinic3_cmdq_wqe *wqe,int wrapped, +enum hinic3_mod_type mod,u8 cmd,u16 prod_idx, +enum completion_format complete_format, +enum data_format local_data_format, +enum bufdesc_len buf_len) +{ +struct hinic3_ctrl *ctrl =NULL ; +enum ctrl_sect_len ctrl_len; +struct hinic3_cmdq_wqe_lcmd *wqe_lcmd =NULL ; +struct hinic3_cmdq_wqe_scmd *wqe_scmd =NULL ; +u32 saved_data =WQE_HEADER (wqe)->saved_data; + +if (local_data_format ==DATA_SGE ) { + wqe_lcmd = &wqe->wqe_lcmd; + + wqe_lcmd->status.status_info =0 ; + ctrl = &wqe_lcmd->ctrl; + ctrl_len =CTRL_SECT_LEN ; + }else { + wqe_scmd = &wqe->inline_wqe.wqe_scmd; + + wqe_scmd->status.status_info =0 ; + ctrl = &wqe_scmd->ctrl; + ctrl_len =CTRL_DIRECT_SECT_LEN ; + } + + ctrl->ctrl_info =CMDQ_CTRL_SET (prod_idx,PI ) | +CMDQ_CTRL_SET (cmd,CMD ) |CMDQ_CTRL_SET (mod,MOD ) | +CMDQ_CTRL_SET (HINIC3_ACK_TYPE_CMDQ ,ACK_TYPE ); + +WQE_HEADER (wqe)->header_info = +CMDQ_WQE_HEADER_SET (buf_len,BUFDESC_LEN ) | +CMDQ_WQE_HEADER_SET (complete_format,COMPLETE_FMT ) | +CMDQ_WQE_HEADER_SET (local_data_format,DATA_FMT ) | +CMDQ_WQE_HEADER_SET (CEQ_SET ,COMPLETE_REQ ) | +CMDQ_WQE_HEADER_SET (COMPLETE_LEN ,COMPLETE_SECT_LEN ) | +CMDQ_WQE_HEADER_SET (ctrl_len,CTRL_LEN ) | +CMDQ_WQE_HEADER_SET ((u32 )wrapped,HW_BUSY_BIT ); + + saved_data &=SAVED_DATA_CLEAR (saved_data,ARM ); +if (cmd ==CMDQ_SET_ARM_CMD && mod ==HINIC3_MOD_COMM ) +WQE_HEADER (wqe)->saved_data = saved_data | +SAVED_DATA_SET (1 ,ARM ); +else +WQE_HEADER (wqe)->saved_data = saved_data; +} + +static void +cmdq_set_lcmd_wqe (struct hinic3_cmdq_wqe *wqe,enum cmdq_cmd_type cmd_type, +struct hinic3_cmd_buf *buf_in,struct hinic3_cmd_buf *buf_out, +int wrapped,enum hinic3_mod_type mod,u8 cmd,u16 prod_idx) +{ +struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = &wqe->wqe_lcmd; +enum completion_format complete_format =COMPLETE_DIRECT ; + +switch (cmd_type) { +case SYNC_CMD_DIRECT_RESP : + complete_format =COMPLETE_DIRECT ; + wqe_lcmd->completion.direct_resp =0 ; +break ; +case SYNC_CMD_SGE_RESP : +if (buf_out) { + complete_format =COMPLETE_SGE ; +cmdq_set_completion (&wqe_lcmd->completion, buf_out); + } +break ; +case ASYNC_CMD : + complete_format =COMPLETE_DIRECT ; + wqe_lcmd->completion.direct_resp =0 ; + wqe_lcmd->buf_desc.saved_async_buf = (u64)(buf_in); +break ; +default : +break ; + } + +cmdq_prepare_wqe_ctrl (wqe, wrapped, mod, cmd, prod_idx, complete_format, +DATA_SGE ,BUFDESC_LCMD_LEN ); + +cmdq_set_lcmd_bufdesc (wqe_lcmd, buf_in); +} + +/** +* Prepare necessary context for command queue, send a synchronous command with +* a direct response to hardware. It waits for completion of command by polling +* command queue for a response. +* +* @param[in] cmdq +* The command queue object that represents the queue to send the command to. +* @param[in] mod +* The module type that the command belongs to. +* @param[in] cmd +* The command to be executed. +* @param[in] buf_in +* The input buffer containing the command parameters. +* @param[out] out_param +* A pointer to the location where the response data will be stored, if +* available. +* @param[in] timeout +* The timeout value (ms) to wait for the command completion. If zero, a default +* timeout will be used. +* +* @return +* 0 on success, non-zero on failure. +* - -EBUSY: The command queue is busy. +* - -ETIMEDOUT: The command did not complete within the specified timeout. +*/ +static int +cmdq_sync_cmd_direct_resp (struct hinic3_cmdq *cmdq,enum hinic3_mod_type mod, +u8 cmd,struct hinic3_cmd_buf *buf_in,u64 *out_param, +u32 timeout) +{ +struct hinic3_wq *wq = cmdq->wq; +struct hinic3_cmdq_wqe wqe; +struct hinic3_cmdq_wqe *curr_wqe =NULL ; +struct hinic3_cmdq_wqe_lcmd *wqe_lcmd =NULL ; +u16 curr_prod_idx, next_prod_idx, num_wqebbs; +int wrapped; +u32 timeo, wqe_size; +int err; + + wqe_size =cmdq_wqe_size (WQE_LCMD_TYPE ); + num_wqebbs =WQE_NUM_WQEBBS (wqe_size, wq); + +/* Keep wrapped and doorbell index correct. */ +rte_spinlock_lock (&cmdq->cmdq_lock); + + curr_wqe =hinic3_get_wqe (cmdq->wq, num_wqebbs, &curr_prod_idx); +if (!curr_wqe) { + err = -EBUSY ; + goto cmdq_unlock; + } + +memset (&wqe,0 ,sizeof (wqe)); + wrapped = cmdq->wrapped; + + next_prod_idx = curr_prod_idx + num_wqebbs; +if (next_prod_idx >= wq->q_depth) { + cmdq->wrapped = !cmdq->wrapped; + next_prod_idx -= wq->q_depth; + } + +cmdq_set_lcmd_wqe (&wqe,SYNC_CMD_DIRECT_RESP , buf_in,NULL , wrapped, + mod, cmd, curr_prod_idx); + +/* The data that is written to HW should be in Big Endian Format. */ +hinic3_hw_be32_len (&wqe, (int )wqe_size); + +/* Cmdq wqe is not shadow, therefore wqe will be written to wq. */ +cmdq_wqe_fill (curr_wqe, &wqe); + + cmdq->cmd_infos[curr_prod_idx].cmd_type =HINIC3_CMD_TYPE_DIRECT_RESP ; + +cmdq_set_db (cmdq,HINIC3_CMDQ_SYNC , next_prod_idx); + + timeo =msecs_to_jiffies (timeout ? timeout :CMDQ_CMD_TIMEOUT ); + err =hinic3_cmdq_poll_msg (cmdq, timeo); +if (err) { +PMD_DRV_LOG (ERR ,"Cmdq poll msg ack failed, prod idx: 0x%x" , + curr_prod_idx); + err = -ETIMEDOUT ; + goto cmdq_unlock; + } + +rte_smp_rmb ();/**< Read error code after completion. */ + +if (out_param) { + wqe_lcmd = &curr_wqe->wqe_lcmd; + *out_param =cpu_to_be64 (wqe_lcmd->completion.direct_resp); + } + +if (cmdq->errcode[curr_prod_idx]) + err = cmdq->errcode[curr_prod_idx]; + +cmdq_unlock: +rte_spinlock_unlock (&cmdq->cmdq_lock); + +return err; +} + +/** +* Send a synchronous command with detailed response and wait for the +* completion. +* +* @param[in] cmdq +* The command queue object representing the queue to send the command to. +* @param[in] mod +* The module type that the command belongs to. +* @param[in] cmd +* The command to be executed. +* @param[in] buf_in +* The input buffer containing the parameters for the command. +* @param[out] buf_out +* The output buffer where the detailed response from the hardware will be +* stored. +* @param[in] timeout +* The timeout value (ms) to wait for the command completion. If zero, a default +* timeout will be used. +* +* @return +* 0 on success, non-zero on failure. +* - -EBUSY: The command queue is busy. +* - -ETIMEDOUT: The command did not complete within the specified timeout. +*/ +static int +cmdq_sync_cmd_detail_resp (struct hinic3_cmdq *cmdq,enum hinic3_mod_type mod, +u8 cmd,struct hinic3_cmd_buf *buf_in, +struct hinic3_cmd_buf *buf_out,u32 timeout) +{ +struct hinic3_wq *wq = cmdq->wq; +struct hinic3_cmdq_wqe wqe; +struct hinic3_cmdq_wqe *curr_wqe =NULL ; +u16 curr_prod_idx, next_prod_idx, num_wqebbs; +int wrapped; +u32 timeo, wqe_size; +int err; + + wqe_size =cmdq_wqe_size (WQE_LCMD_TYPE ); + num_wqebbs =WQE_NUM_WQEBBS (wqe_size, wq); + +/* Keep wrapped and doorbell index correct. */ +rte_spinlock_lock (&cmdq->cmdq_lock); + + curr_wqe =hinic3_get_wqe (cmdq->wq, num_wqebbs, &curr_prod_idx); +if (!curr_wqe) { + err = -EBUSY ; + goto cmdq_unlock; + } + +memset (&wqe,0 ,sizeof (wqe)); + wrapped = cmdq->wrapped; + + next_prod_idx = curr_prod_idx + num_wqebbs; +if (next_prod_idx >= wq->q_depth) { + cmdq->wrapped = !cmdq->wrapped; + next_prod_idx -= wq->q_depth; + } + +cmdq_set_lcmd_wqe (&wqe,SYNC_CMD_SGE_RESP , buf_in, buf_out, wrapped, + mod, cmd, curr_prod_idx); + +/* The data that is written to HW should be in Big Endian Format. */ +hinic3_hw_be32_len (&wqe, (int )wqe_size); + +/* Cmdq wqe is not shadow, therefore wqe will be written to wq. */ +cmdq_wqe_fill (curr_wqe, &wqe); + + cmdq->cmd_infos[curr_prod_idx].cmd_type =HINIC3_CMD_TYPE_SGE_RESP ; + +cmdq_set_db (cmdq, cmdq->cmdq_type, next_prod_idx); + + timeo =msecs_to_jiffies (timeout ? timeout :CMDQ_CMD_TIMEOUT ); + err =hinic3_cmdq_poll_msg (cmdq, timeo); +if (err) { +PMD_DRV_LOG (ERR ,"Cmdq poll msg ack failed, prod idx: 0x%x" , + curr_prod_idx); + err = -ETIMEDOUT ; + goto cmdq_unlock; + } + +rte_smp_rmb ();/**< Read error code after completion. */ + +if (cmdq->errcode[curr_prod_idx]) + err = cmdq->errcode[curr_prod_idx]; + +cmdq_unlock: +rte_spinlock_unlock (&cmdq->cmdq_lock); + +return err; +} + +static int +cmdq_params_valid (void *hwdev,struct hinic3_cmd_buf *buf_in) +{ +if (!buf_in || !hwdev) { +PMD_DRV_LOG (ERR ,"Invalid CMDQ buffer or hwdev is NULL" ); +return -EINVAL ; + } + +if (buf_in->size ==0 || buf_in->size >HINIC3_CMDQ_BUF_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid CMDQ buffer size: 0x%x" , + buf_in->size); +return -EINVAL ; + } + +return 0 ; +} + +static int +wait_cmdqs_enable (struct hinic3_cmdqs *cmdqs) +{ +unsigned long end; + + end = jiffies +msecs_to_jiffies (WAIT_CMDQ_ENABLE_TIMEOUT ); +do { +if (cmdqs->status &HINIC3_CMDQ_ENABLE ) +return 0 ; + }while (time_before (jiffies, end)); + +return -EBUSY ; +} + +int +hinic3_cmdq_direct_resp (void *hwdev,enum hinic3_mod_type mod,u8 cmd, +struct hinic3_cmd_buf *buf_in,u64 *out_param, +u32 timeout) +{ +struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs; +int err; + + err =cmdq_params_valid (hwdev, buf_in); +if (err) { +PMD_DRV_LOG (ERR ,"Invalid cmdq parameters" ); +return err; + } + + err =wait_cmdqs_enable (cmdqs); +if (err) { +PMD_DRV_LOG (ERR ,"Cmdq is disabled" ); +return err; + } + +return cmdq_sync_cmd_direct_resp (&cmdqs->cmdq[HINIC3_CMDQ_SYNC ], mod, + cmd, buf_in, out_param, timeout); +} + +int +hinic3_cmdq_detail_resp (void *hwdev,enum hinic3_mod_type mod,u8 cmd, +struct hinic3_cmd_buf *buf_in, +struct hinic3_cmd_buf *buf_out,u32 timeout) +{ +struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs; +int err; + + err =cmdq_params_valid (hwdev, buf_in); +if (err) { +PMD_DRV_LOG (ERR ,"Invalid cmdq parameters" ); +return err; + } + + err =wait_cmdqs_enable (cmdqs); +if (err) { +PMD_DRV_LOG (ERR ,"Cmdq is disabled" ); +return err; + } + +return cmdq_sync_cmd_detail_resp (&cmdqs->cmdq[HINIC3_CMDQ_SYNC ], mod, + cmd, buf_in, buf_out, timeout); +} + +static void +cmdq_update_errcode (struct hinic3_cmdq *cmdq,u16 prod_idx,int errcode) +{ + cmdq->errcode[prod_idx] = errcode; +} + +static void +clear_wqe_complete_bit (struct hinic3_cmdq *cmdq,struct hinic3_cmdq_wqe *wqe) +{ +struct hinic3_ctrl *ctrl =NULL ; +u32 header_info =hinic3_hw_cpu32 (WQE_HEADER (wqe)->header_info); +int buf_len =CMDQ_WQE_HEADER_GET (header_info,BUFDESC_LEN ); +int wqe_size =cmdq_get_wqe_size (buf_len); +u16 num_wqebbs; + +if (wqe_size ==WQE_LCMD_SIZE ) + ctrl = &wqe->wqe_lcmd.ctrl; +else + ctrl = &wqe->inline_wqe.wqe_scmd.ctrl; + +/* Clear HW busy bit. */ + ctrl->ctrl_info =0 ; + +rte_wmb ();/**< Verify wqe is cleared. */ + + num_wqebbs =WQE_NUM_WQEBBS (wqe_size, cmdq->wq); +hinic3_put_wqe (cmdq->wq, num_wqebbs); +} + +static void +cmdq_init_queue_ctxt (struct hinic3_cmdq *cmdq, +struct hinic3_cmdq_ctxt_info *ctxt_info) +{ +struct hinic3_wq *wq = cmdq->wq; +u64 wq_first_page_paddr, pfn; + +u16 start_ci = (u16)(wq->cons_idx); + +/* The data in the HW is in Big Endian Format. */ + wq_first_page_paddr = wq->queue_buf_paddr; + + pfn =CMDQ_PFN (wq_first_page_paddr,RTE_PGSIZE_4K ); + ctxt_info->curr_wqe_page_pfn = +CMDQ_CTXT_PAGE_INFO_SET (1 ,HW_BUSY_BIT ) | +CMDQ_CTXT_PAGE_INFO_SET (0 ,CEQ_EN ) | +CMDQ_CTXT_PAGE_INFO_SET (0 ,CEQ_ARM ) | +CMDQ_CTXT_PAGE_INFO_SET (HINIC3_CEQ_ID_CMDQ ,EQ_ID ) | +CMDQ_CTXT_PAGE_INFO_SET (pfn,CURR_WQE_PAGE_PFN ); + + ctxt_info->wq_block_pfn =CMDQ_CTXT_BLOCK_INFO_SET (start_ci,CI ) | +CMDQ_CTXT_BLOCK_INFO_SET (pfn,WQ_BLOCK_PFN ); +} + +static int +init_cmdq (struct hinic3_cmdq *cmdq,struct hinic3_hwdev *hwdev, +struct hinic3_wq *wq,enum hinic3_cmdq_type q_type) +{ +int err =0 ; +size_t errcode_size; +size_t cmd_infos_size; + + cmdq->wq = wq; + cmdq->cmdq_type = q_type; + cmdq->wrapped =1 ; + +rte_spinlock_init (&cmdq->cmdq_lock); + + errcode_size = wq->q_depth *sizeof (*cmdq->errcode); + cmdq->errcode =rte_zmalloc (NULL , errcode_size,0 ); +if (!cmdq->errcode) { +PMD_DRV_LOG (ERR ,"Allocate errcode for cmdq failed" ); +return -ENOMEM ; + } + + cmd_infos_size = wq->q_depth *sizeof (*cmdq->cmd_infos); + cmdq->cmd_infos =rte_zmalloc (NULL , cmd_infos_size,0 ); +if (!cmdq->cmd_infos) { +PMD_DRV_LOG (ERR ,"Allocate cmd info for cmdq failed" ); + err = -ENOMEM ; + goto cmd_infos_err; + } + + cmdq->db_base = hwdev->cmdqs->cmdqs_db_base; + +return 0 ; + +cmd_infos_err: +rte_free (cmdq->errcode); + +return err; +} + +static void +free_cmdq (struct hinic3_cmdq *cmdq) +{ +rte_free (cmdq->cmd_infos); +rte_free (cmdq->errcode); +} + +static int +hinic3_set_cmdq_ctxts (struct hinic3_hwdev *hwdev) +{ +struct hinic3_cmdqs *cmdqs = hwdev->cmdqs; +struct hinic3_cmd_cmdq_ctxt cmdq_ctxt; +enum hinic3_cmdq_type cmdq_type; +u16 out_size =sizeof (cmdq_ctxt); +int err; + + cmdq_type =HINIC3_CMDQ_SYNC ; +for (; cmdq_type <HINIC3_MAX_CMDQ_TYPES ; cmdq_type++) { +memset (&cmdq_ctxt,0 ,sizeof (cmdq_ctxt)); +memcpy ((void *)&cmdq_ctxt.ctxt_info, + (void *)&cmdqs->cmdq[cmdq_type].cmdq_ctxt, +sizeof (cmdq_ctxt.ctxt_info)); + cmdq_ctxt.func_idx =hinic3_global_func_id (hwdev); + cmdq_ctxt.cmdq_id = cmdq_type; + + err =hinic3_msg_to_mgmt_sync (hwdev,HINIC3_MOD_COMM , +HINIC3_MGMT_CMD_SET_CMDQ_CTXT , + &cmdq_ctxt,sizeof (cmdq_ctxt), + &cmdq_ctxt, &out_size,0 ); +if (err || !out_size || cmdq_ctxt.status) { +PMD_DRV_LOG (ERR , +"Set cmdq ctxt failed, err: %d, status: " +"0x%x, out_size: 0x%x" , + err, cmdq_ctxt.status, out_size); +return -EFAULT ; + } + } + + cmdqs->status |=HINIC3_CMDQ_ENABLE ; + +return 0 ; +} + +int +hinic3_reinit_cmdq_ctxts (struct hinic3_hwdev *hwdev) +{ +struct hinic3_cmdqs *cmdqs = hwdev->cmdqs; +enum hinic3_cmdq_type cmdq_type =HINIC3_CMDQ_SYNC ; + +for (; cmdq_type <HINIC3_MAX_CMDQ_TYPES ; cmdq_type++) { + cmdqs->cmdq[cmdq_type].wrapped =1 ; +hinic3_wq_wqe_pg_clear (cmdqs->cmdq[cmdq_type].wq); + } + +return hinic3_set_cmdq_ctxts (hwdev); +} + +static int +hinic3_set_cmdqs (struct hinic3_hwdev *hwdev,struct hinic3_cmdqs *cmdqs) +{ +void *db_base =NULL ; +enum hinic3_cmdq_type type, cmdq_type; +int err; + + err =hinic3_alloc_db_addr (hwdev, &db_base,HINIC3_DB_TYPE_CMDQ ); +if (err) { +PMD_DRV_LOG (ERR ,"Failed to allocate doorbell address" ); + goto alloc_db_err; + } + cmdqs->cmdqs_db_base = (u8 *)db_base; + + cmdq_type =HINIC3_CMDQ_SYNC ; +for (; cmdq_type <HINIC3_MAX_CMDQ_TYPES ; cmdq_type++) { + err =init_cmdq (&cmdqs->cmdq[cmdq_type], hwdev, + &cmdqs->saved_wqs[cmdq_type], cmdq_type); +if (err) { +PMD_DRV_LOG (ERR ,"Initialize cmdq failed" ); + goto init_cmdq_err; + } + +cmdq_init_queue_ctxt (&cmdqs->cmdq[cmdq_type], + &cmdqs->cmdq[cmdq_type].cmdq_ctxt); + } + + err =hinic3_set_cmdq_ctxts (hwdev); +if (err) + goto init_cmdq_err; + +return 0 ; + +init_cmdq_err: + type =HINIC3_CMDQ_SYNC ; +for (; type < cmdq_type; type++) +free_cmdq (&cmdqs->cmdq[type]); + +alloc_db_err: +hinic3_cmdq_free (cmdqs->saved_wqs,HINIC3_MAX_CMDQ_TYPES ); +return -ENOMEM ; +} + +int +hinic3_cmdqs_init (struct hinic3_hwdev *hwdev) +{ +struct hinic3_cmdqs *cmdqs =NULL ; +size_t saved_wqs_size; +char cmdq_pool_name[RTE_MEMPOOL_NAMESIZE ]; +int err; + + cmdqs =rte_zmalloc (NULL ,sizeof (*cmdqs),0 ); +if (!cmdqs) +return -ENOMEM ; + + hwdev->cmdqs = cmdqs; + cmdqs->hwdev = hwdev; + + saved_wqs_size =HINIC3_MAX_CMDQ_TYPES *sizeof (struct hinic3_wq ); + cmdqs->saved_wqs =rte_zmalloc (NULL , saved_wqs_size,0 ); +if (!cmdqs->saved_wqs) { +PMD_DRV_LOG (ERR ,"Allocate saved wqs failed" ); + err = -ENOMEM ; + goto alloc_wqs_err; + } + +memset (cmdq_pool_name,0 ,RTE_MEMPOOL_NAMESIZE ); + (void )snprintf (cmdq_pool_name,sizeof (cmdq_pool_name),"hinic3_cmdq_%u" , + hwdev->port_id); + + cmdqs->cmd_buf_pool =rte_pktmbuf_pool_create (cmdq_pool_name, +HINIC3_CMDQ_DEPTH *HINIC3_MAX_CMDQ_TYPES ,0 ,0 , +HINIC3_CMDQ_BUF_SIZE , (int )rte_socket_id ()); +if (!cmdqs->cmd_buf_pool) { +PMD_DRV_LOG (ERR ,"Create cmdq buffer pool failed" ); + err = -ENOMEM ; + goto pool_create_err; + } + + err =hinic3_cmdq_alloc (cmdqs->saved_wqs, hwdev,HINIC3_MAX_CMDQ_TYPES , +HINIC3_CMDQ_WQ_BUF_SIZE ,CMDQ_WQEBB_SHIFT , +HINIC3_CMDQ_DEPTH ); +if (err) { +PMD_DRV_LOG (ERR ,"Allocate cmdq failed" ); + goto cmdq_alloc_err; + } + + err =hinic3_set_cmdqs (hwdev, cmdqs); +if (err) { +PMD_DRV_LOG (ERR ,"set_cmdqs failed" ); + goto cmdq_alloc_err; + } +return 0 ; + +cmdq_alloc_err: +rte_mempool_free (cmdqs->cmd_buf_pool); + +pool_create_err: +rte_free (cmdqs->saved_wqs); + +alloc_wqs_err: +rte_free (cmdqs); + +return err; +} + +void +hinic3_cmdqs_free (struct hinic3_hwdev *hwdev) +{ +struct hinic3_cmdqs *cmdqs = hwdev->cmdqs; +enum hinic3_cmdq_type cmdq_type =HINIC3_CMDQ_SYNC ; + + cmdqs->status &= ~HINIC3_CMDQ_ENABLE ; + +for (; cmdq_type <HINIC3_MAX_CMDQ_TYPES ; cmdq_type++) +free_cmdq (&cmdqs->cmdq[cmdq_type]); + +hinic3_cmdq_free (cmdqs->saved_wqs,HINIC3_MAX_CMDQ_TYPES ); + +rte_mempool_free (cmdqs->cmd_buf_pool); + +rte_free (cmdqs->saved_wqs); + +rte_free (cmdqs); +} + +static int +hinic3_cmdq_poll_msg (struct hinic3_cmdq *cmdq,u32 timeout) +{ +struct hinic3_cmdq_wqe *wqe =NULL ; +struct hinic3_cmdq_wqe_lcmd *wqe_lcmd =NULL ; +struct hinic3_ctrl *ctrl =NULL ; +struct hinic3_cmdq_cmd_info *cmd_info =NULL ; +u32 status_info, ctrl_info; +u16 ci; +int errcode; +unsigned long end; +int done =0 ; +int err =0 ; + + wqe =hinic3_read_wqe (cmdq->wq,1 , &ci); +if (!wqe) { +PMD_DRV_LOG (ERR ,"No outstanding cmdq msg" ); +return -EINVAL ; + } + + cmd_info = &cmdq->cmd_infos[ci]; +if (cmd_info->cmd_type ==HINIC3_CMD_TYPE_NONE ) { +PMD_DRV_LOG (ERR , +"Cmdq msg has not been filled and send to hw, " +"or get TMO msg ack. cmdq ci: %u" , + ci); +return -EINVAL ; + } + +/* Only arm bit is using scmd wqe, the wqe is lcmd. */ + wqe_lcmd = &wqe->wqe_lcmd; + ctrl = &wqe_lcmd->ctrl; + end = jiffies +msecs_to_jiffies (timeout); +do { + ctrl_info =hinic3_hw_cpu32 ((ctrl)->ctrl_info); +if (WQE_COMPLETED (ctrl_info)) { + done =1 ; +break ; + } + +rte_delay_us (1 ); + }while (time_before (jiffies, end)); + +if (done) { + status_info =hinic3_hw_cpu32 (wqe_lcmd->status.status_info); + errcode =WQE_ERRCODE_GET (status_info,VAL ); +cmdq_update_errcode (cmdq, ci, errcode); +clear_wqe_complete_bit (cmdq, wqe); + err =0 ; + }else { +PMD_DRV_LOG (ERR ,"Poll cmdq msg time out, ci: %u" , ci); + err = -ETIMEDOUT ; + } + +/* Set this cmd invalid. */ + cmd_info->cmd_type =HINIC3_CMD_TYPE_NONE ; + +return err; +}
drivers/net/hinic3/base/hinic3_cmdq.h new file +230 -0
230 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 5/18 net/hinic3: add NIC event module
In reply to Feifei WangFrom: Xin Wang <[email protected]>
Currently, there are two types of events: pf/vf connection status and port information printing. This patch contains related data structures and function codes.
--- drivers/net/hinic3/base/hinic3_nic_event.c | 433 +++++++++++++++++++++ drivers/net/hinic3/base/hinic3_nic_event.h | 39 ++ 2 files changed, 472 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.c create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.h
drivers/net/hinic3/base/hinic3_nic_event.c new file +433 -0
@@ -0,0 +1,433 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include "hinic3_compat.h" +#include "hinic3_cmd.h" +#include "hinic3_hwif.h" +#include "hinic3_nic_cfg.h" +#include "hinic3_hwdev.h" +#include "hinic3_nic_event.h" +#include "hinic3_ethdev.h" + +static const char *g_hw_to_char_fec[HILINK_FEC_MAX_TYPE ] = { +"not set" ,"rsfec" ,"basefec" ,"nofec" ,"llrsfec" , +}; +static const char *g_hw_to_speed_info[PORT_SPEED_UNKNOWN ] = { +"not set" ,"10MB" ,"100MB" ,"1GB" ,"10GB" , +"25GB" ,"40GB" ,"50GB" ,"100GB" ,"200GB" , +}; +static const char *g_hw_to_an_state_info[PORT_CFG_AN_OFF +1 ] = { +"not set" , +"on" , +"off" , +}; + +struct port_type_table { +u32 port_type; +const char *port_type_name; +}; + +void +get_port_info (struct hinic3_hwdev *hwdev,u8 link_state, +struct rte_eth_link *link) +{ +uint32_t port_speed[LINK_SPEED_LEVELS ] = { +RTE_ETH_SPEED_NUM_NONE ,RTE_ETH_SPEED_NUM_10M , +RTE_ETH_SPEED_NUM_100M ,RTE_ETH_SPEED_NUM_1G , +RTE_ETH_SPEED_NUM_10G ,RTE_ETH_SPEED_NUM_25G , +RTE_ETH_SPEED_NUM_40G ,RTE_ETH_SPEED_NUM_50G , +RTE_ETH_SPEED_NUM_100G ,RTE_ETH_SPEED_NUM_200G , + }; +struct nic_port_info port_info = {0 }; +int err; + +if (!link_state) { + link->link_status =RTE_ETH_LINK_DOWN ; + link->link_speed =RTE_ETH_SPEED_NUM_NONE ; + link->link_duplex =RTE_ETH_LINK_HALF_DUPLEX ; + link->link_autoneg =RTE_ETH_LINK_FIXED ; + }else { + link->link_status =RTE_ETH_LINK_UP ; + + err =hinic3_get_port_info (hwdev, &port_info); +if (err) { + link->link_speed =RTE_ETH_SPEED_NUM_NONE ; + link->link_duplex =RTE_ETH_LINK_FULL_DUPLEX ; + link->link_autoneg =RTE_ETH_LINK_FIXED ; + }else { + link->link_speed = + port_speed[port_info.speed %LINK_SPEED_LEVELS ]; + link->link_duplex = port_info.duplex; + link->link_autoneg = port_info.autoneg_state; + } + } +} + +static void +hinic3_link_event_stats (void *dev,u8 link) +{ +struct hinic3_hwdev *hwdev = dev; + +if (link) +rte_atomic_fetch_add_explicit (&hwdev->hw_stats.link_event_stats.link_up_stats, +1 , rte_memory_order_seq_cst); +else +rte_atomic_fetch_add_explicit (&hwdev->hw_stats.link_event_stats.link_down_stats, +1 , rte_memory_order_seq_cst); +} + +static void +hinic3_set_vport_state (struct hinic3_hwdev *hwdev, +struct hinic3_cmd_link_state *link_state) +{ +struct hinic3_nic_dev *nic_dev =NULL ; +int err =0 ; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV ((struct rte_eth_dev *)(hwdev->eth_dev)); + +if (link_state->state) { +if (hinic3_get_bit (HINIC3_DEV_START , &nic_dev->dev_status)) + err =hinic3_set_vport_enable (hwdev, true); + }else { + err =hinic3_set_vport_enable (hwdev, false); + } + +if (err) +PMD_DRV_LOG (ERR ,"Set vport status failed" ); +} + +static void +link_status_event_handler(void *hwdev, void *buf_in, __rte_unused u16 in_size, + __rte_unused void *buf_out, + __rte_unused u16 *out_size) +{ +struct hinic3_cmd_link_state *link_status =NULL ; +struct rte_eth_link link; +struct hinic3_hwdev *dev = hwdev; +int err; + + link_status = buf_in; +PMD_DRV_LOG (INFO , +"Link status report received, func_id: %d, status: %d(%s)" , +hinic3_global_func_id (hwdev), link_status->state, + link_status->state ?"UP" :"DOWN" ); + +hinic3_link_event_stats (hwdev, link_status->state); + +hinic3_set_vport_state (dev, link_status); + +/* Link event reported only after set vport enable. */ +get_port_info (dev, link_status->state, &link); + err =rte_eth_linkstatus_set ((struct rte_eth_dev *)(dev->eth_dev), + &link); +if (!err) +rte_eth_dev_callback_process (dev->eth_dev, +RTE_ETH_EVENT_INTR_LSC ,NULL ); +} + +static const char * +get_port_type_name (u32 type) +{ +int i; +const struct port_type_table port_optical_type_table_s[] = { + {LINK_PORT_UNKNOWN ,"UNKNOWN" }, + {LINK_PORT_OPTICAL_MM ,"optical_sr" }, + {LINK_PORT_OPTICAL_SM ,"optical_lr" }, + {LINK_PORT_PAS_COPPER ,"copper" }, + {LINK_PORT_ACC ,"ACC" }, + {LINK_PORT_BASET ,"baset" }, + {LINK_PORT_AOC ,"AOC" }, + {LINK_PORT_ELECTRIC ,"electric" }, + {LINK_PORT_BACKBOARD_INTERFACE ,"interface" }, + }; + +for (i =0 ; i <ARRAY_LEN (port_optical_type_table_s); i++) { +if (type == port_optical_type_table_s[i].port_type) +return port_optical_type_table_s[i].port_type_name; + } +return "UNKNOWN TYPE" ; +} + +static void +get_port_type (struct mag_cmd_event_port_info *port_info,const char **port_type) +{ +if (port_info->port_type <=LINK_PORT_BACKBOARD_INTERFACE ) + *port_type =get_port_type_name (port_info->port_type); +else +PMD_DRV_LOG (INFO ,"Unknown port type: %u" , + port_info->port_type); +} + +static int +get_port_temperature_power (struct mag_cmd_event_port_info *info,char *str) +{ +char arr[CAP_INFO_MAX_LEN ]; + +snprintf (arr,CAP_INFO_MAX_LEN -1 ,"%s, %s, Temperature: %u" , str, + info->sfp_type ?"QSFP" :"SFP" , info->cable_temp); +if (info->sfp_type) +snprintf (str,CAP_INFO_MAX_LEN -1 , +"%s, rx power: %uuw %uuW %uuW %uuW" , arr, + info->power[0x0 ], info->power[0x1 ], info->power[0x2 ], + info->power[0x3 ]); +else +snprintf (str,CAP_INFO_MAX_LEN -1 , +"%s, rx power: %uuW, tx power: %uuW" , arr, + info->power[0x0 ], info->power[0x1 ]); + +return 0 ; +} + +static void +print_cable_info (struct mag_cmd_event_port_info *port_info) +{ +char tmp_str[CAP_INFO_MAX_LEN ] = {0 }; +char tmp_vendor[VENDOR_MAX_LEN ] = {0 }; +const char *port_type ="Unknown port type" ; +int i; +int err =0 ; +if (port_info->gpio_insert) { +PMD_DRV_LOG (INFO ,"Cable unpresent" ); +return ; + } + +get_port_type (port_info, &port_type); + +for (i = (int )sizeof (port_info->vendor_name) -1 ; i >=0 ; i--) { +if (port_info->vendor_name[i] ==' ' ) + port_info->vendor_name[i] ='\0' ; +else +break ; + } + +memcpy (tmp_vendor, port_info->vendor_name, +sizeof (port_info->vendor_name)); + (void )snprintf (tmp_str,CAP_INFO_MAX_LEN -1 , +"Vendor: %s, %s, length: %um, max_speed: %uGbps" , + tmp_vendor, port_type, port_info->cable_length, + port_info->max_speed); + +if (port_info->port_type ==LINK_PORT_OPTICAL_MM || + port_info->port_type ==LINK_PORT_AOC ) { + err =get_port_temperature_power (port_info, tmp_str); +if (err) +return ; + } + +PMD_DRV_LOG (INFO ,"Cable information: %s" , tmp_str); +} + +static void +print_link_info (struct mag_cmd_event_port_info *port_info) +{ +const char *fec ="None" ; +const char *speed ="None" ; +const char *an_state ="None" ; + +if (port_info->fec <HILINK_FEC_MAX_TYPE ) + fec = g_hw_to_char_fec[port_info->fec]; +else +PMD_DRV_LOG (INFO ,"Unknown fec type: %u" , port_info->fec); + +if (port_info->an_state >PORT_CFG_AN_OFF ) { +PMD_DRV_LOG (INFO ,"an_state %u is invalid" , + port_info->an_state); +return ; + } + + an_state = g_hw_to_an_state_info[port_info->an_state]; + +if (port_info->speed >=PORT_SPEED_UNKNOWN ) { +PMD_DRV_LOG (INFO ,"speed %u is invalid" , port_info->speed); +return ; + } + + speed = g_hw_to_speed_info[port_info->speed]; +PMD_DRV_LOG (INFO ,"Link information: speed %s, %s, autoneg %s" , speed, + fec, an_state); +} + +static void +print_port_info (void *hwdev,struct mag_cmd_event_port_info *port_info,u8 type) +{ +print_cable_info (port_info); + +print_link_info (port_info); + +if (type ==RTE_ETH_LINK_UP ) +return ; + +PMD_DRV_LOG (INFO ,"Function %d link down msg:" , +hinic3_global_func_id (hwdev)); + +PMD_DRV_LOG (INFO , +"PMA ctrl: %s, tx %s, rx %s, PMA fifo reg: 0x%x, " +"PMA signal ok reg: 0x%x, RF/LF status reg: 0x%x" , + port_info->pma_ctrl ==1 ?"off" :"on" , + port_info->tx_enable ?"enable" :"disable" , + port_info->rx_enable ?"enable" :"disable" , + port_info->pma_fifo_reg, port_info->pma_signal_ok_reg, + port_info->rf_lf); +PMD_DRV_LOG (INFO , +"alos: %u, rx_los: %u, PCS 64 66b reg: 0x%x, " +"PCS link: 0x%x, MAC link: 0x%x, PCS_err_cnt: 0x%x" , + port_info->alos, port_info->rx_los, + port_info->pcs_64_66b_reg, port_info->pcs_link, + port_info->pcs_mac_link, port_info->pcs_err_cnt); +PMD_DRV_LOG (INFO , +"his_link_machine_state = 0x%08x, " +"cur_link_machine_state = 0x%08x" , + port_info->his_link_machine_state, + port_info->cur_link_machine_state); +} + +static void +port_info_event_printf(void *hwdev, void *buf_in, __rte_unused u16 in_size, + __rte_unused void *buf_out, __rte_unused u16 *out_size) +{ +struct mag_cmd_event_port_info *port_info = buf_in; + ((struct mag_cmd_event_port_info *)buf_out)->head.status =0 ; +enum hinic3_nic_event_type type = port_info->event_type; +if (type <RTE_ETH_LINK_DOWN || type >RTE_ETH_LINK_UP ) { +PMD_DRV_LOG (ERR ,"Invalid hilink info report, type: %d" , + type); +return ; + } + +print_port_info (hwdev, port_info, type); +} + +struct nic_event_handler { +u16 cmd; +void (*handler)(void *hwdev,void *buf_in,u16 in_size,void *buf_out, +u16 *out_size); +}; + +static const struct nic_event_handler nic_cmd_handler[] = {}; + +/** +* Handle NIC event based on the provided command. +* +* @param[in] hwdev +* Pointer to hardware device structure. +* @param[in] cmd +* The command associated with the NIC event to be handled. +* @param[in] buf_in +* The input buffer containing the event data. +* @param[in] in_size +* The size of the input buffer. +* @param[out] buf_out +* The output buffer to store the event response. +* @param[out] out_size +* The size of the output data stored in the output buffer. +*/ +static void +nic_event_handler (void *hwdev,u16 cmd,void *buf_in,u16 in_size, +void *buf_out,u16 *out_size) +{ +u32 i, size =ARRAY_LEN (nic_cmd_handler); + +if (!hwdev) +return ; + + *out_size =0 ; + +for (i =0 ; i < size; i++) { +if (cmd == nic_cmd_handler[i].cmd) { + nic_cmd_handler[i].handler (hwdev, buf_in, in_size, + buf_out, out_size); +break ; + } + } + +if (i == size) +PMD_DRV_LOG (WARNING ,"Unsupported nic event cmd(%d) to process" , + cmd); +} + +/* +* VF handler mbox msg from ppf/pf. +* VF link change event. +*/ +int +hinic3_vf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd, +void *buf_in,u16 in_size,void *buf_out,u16 *out_size) +{ +nic_event_handler (hwdev, cmd, buf_in, in_size, buf_out, out_size); +return 0 ; +} + +/* NIC event of PF/PPF handler reported by mgmt cpu. */ +void +hinic3_pf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd, +void *buf_in,u16 in_size,void *buf_out,u16 *out_size) +{ +nic_event_handler (hwdev, cmd, buf_in, in_size, buf_out, out_size); +} + +static const struct nic_event_handler mag_cmd_handler[] = { + { + .cmd =MAG_CMD_GET_LINK_STATUS , + .handler = link_status_event_handler, + }, + { + .cmd =MAG_CMD_EVENT_PORT_INFO , + .handler = port_info_event_printf, + }, +}; + +static int +hinic3_mag_event_handler (void *hwdev,u16 cmd,void *buf_in,u16 in_size, +void *buf_out,u16 *out_size) +{ +u32 size =ARRAY_LEN (mag_cmd_handler); +u32 i; + +if (!hwdev) +return -EINVAL ; + + *out_size =0 ; +for (i =0 ; i < size; i++) { +if (cmd == mag_cmd_handler[i].cmd) { + mag_cmd_handler[i].handler (hwdev, buf_in, in_size, + buf_out, out_size); +break ; + } + } + +/* Can't find this event cmd. */ +if (i == size) +PMD_DRV_LOG (ERR ,"Unsupported mag event, cmd: %u" , cmd); + +return 0 ; +} + +int +hinic3_vf_mag_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd, +void *buf_in,u16 in_size,void *buf_out, +u16 *out_size) +{ +return hinic3_mag_event_handler (hwdev, cmd, buf_in, in_size, buf_out, + out_size); +} + +/* pf/ppf handler mgmt cpu report hilink event. */ +void +hinic3_pf_mag_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd, +void *buf_in,u16 in_size,void *buf_out, +u16 *out_size) +{ +hinic3_mag_event_handler (hwdev, cmd, buf_in, in_size, buf_out, + out_size); +} + +u8 +hinic3_nic_sw_aeqe_handler(__rte_unused void *hwdev, u8 event, u8 *data) +{ +PMD_DRV_LOG (ERR , +"Received nic ucode aeq event type: 0x%x, data: %" PRIu64, + event, *((u64 *)data)); + +return 0 ; +}
drivers/net/hinic3/base/hinic3_nic_event.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#ifndef _HINIC3_NIC_EVENT_H_ +#define _HINIC3_NIC_EVENT_H_ + +/** +* Get the Ethernet port link information based on the link state. +* +* @param[in] hwdev +* The hardware device context. +* @param[in] link_state +* The current link state (0 = down, non-zero = up). +* @param[out] link +* Pointer to the `rte_eth_link` structure. +*/ +void get_port_info (struct hinic3_hwdev *hwdev,u8 link_state, +struct rte_eth_link *link); + +int hinic3_vf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd, +void *buf_in,u16 in_size,void *buf_out, +u16 *out_size); + +void hinic3_pf_event_handler(void *hwdev, __rte_unused void *pri_handle, +u16 cmd,void *buf_in,u16 in_size,void *buf_out, +u16 *out_size); + +int hinic3_vf_mag_event_handler (void *hwdev,void *pri_handle,u16 cmd, +void *buf_in,u16 in_size,void *buf_out, +u16 *out_size); + +void hinic3_pf_mag_event_handler (void *hwdev,void *pri_handle,u16 cmd, +void *buf_in,u16 in_size,void *buf_out, +u16 *out_size); + +u8 hinic3_nic_sw_aeqe_handler(__rte_unused void *hwdev, u8 event, u8 *data); + +#endif /* _HINIC3_NIC_EVENT_H_ */
Signature · 1 line
2.47.0.windows.2
RFC 6/18 net/hinic3: add eq mechanism function code
In reply to Feifei WangFrom: Yi Chen <[email protected]>
Eqs include aeq and ceq. Aeq is a kind of queue for mgmt asynchronous message and mgmt command response message. This patch introduces data structures, initialization, and related interfaces about aeq.
--- drivers/net/hinic3/base/hinic3_eqs.c | 719 +++++++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_eqs.h | 98 ++++ 2 files changed, 817 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_eqs.c create mode 100644 drivers/net/hinic3/base/hinic3_eqs.h
drivers/net/hinic3/base/hinic3_eqs.c new file +719 -0
@@ -0,0 +1,719 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include <rte_memory.h> +#include <rte_memzone.h> +#include "hinic3_compat.h" +#include "hinic3_csr.h" +#include "hinic3_eqs.h" +#include "hinic3_hwdev.h" +#include "hinic3_hwif.h" +#include "hinic3_mbox.h" +#include "hinic3_mgmt.h" +#include "hinic3_nic_event.h" + +/* Indicate AEQ_CTRL_0 shift. */ +#define AEQ_CTRL_0_INTR_IDX_SHIFT 0 +#define AEQ_CTRL_0_DMA_ATTR_SHIFT 12 +#define AEQ_CTRL_0_PCI_INTF_IDX_SHIFT 20 +#define AEQ_CTRL_0_INTR_MODE_SHIFT 31 + +/* Indicate AEQ_CTRL_0 mask. */ +#define AEQ_CTRL_0_INTR_IDX_MASK 0x3FFU +#define AEQ_CTRL_0_DMA_ATTR_MASK 0x3FU +#define AEQ_CTRL_0_PCI_INTF_IDX_MASK 0x7U +#define AEQ_CTRL_0_INTR_MODE_MASK 0x1U + +/* Set and clear the AEQ_CTRL_0 bit fields. */ +#define AEQ_CTRL_0_SET (val, member) \ + (((val) & AEQ_CTRL_0_##member##_MASK) << AEQ_CTRL_0_##member##_SHIFT) +#define AEQ_CTRL_0_CLEAR (val, member) \ + ((val) & (~(AEQ_CTRL_0_##member##_MASK << AEQ_CTRL_0_##member##_SHIFT))) + +/* Indicate AEQ_CTRL_1 shift. */ +#define AEQ_CTRL_1_LEN_SHIFT 0 +#define AEQ_CTRL_1_ELEM_SIZE_SHIFT 24 +#define AEQ_CTRL_1_PAGE_SIZE_SHIFT 28 + +/* Indicate AEQ_CTRL_1 mask. */ +#define AEQ_CTRL_1_LEN_MASK 0x1FFFFFU +#define AEQ_CTRL_1_ELEM_SIZE_MASK 0x3U +#define AEQ_CTRL_1_PAGE_SIZE_MASK 0xFU + +/* Set and clear the AEQ_CTRL_1 bit fields. */ +#define AEQ_CTRL_1_SET (val, member) \ + (((val) & AEQ_CTRL_1_##member##_MASK) << AEQ_CTRL_1_##member##_SHIFT) +#define AEQ_CTRL_1_CLEAR (val, member) \ + ((val) & (~(AEQ_CTRL_1_##member##_MASK << AEQ_CTRL_1_##member##_SHIFT))) + +#define HINIC3_EQ_PROD_IDX_MASK 0xFFFFF +#define HINIC3_TASK_PROCESS_EQE_LIMIT 1024 +#define HINIC3_EQ_UPDATE_CI_STEP 64 + +/* Indicate EQ_ELEM_DESC shift. */ +#define EQ_ELEM_DESC_TYPE_SHIFT 0 +#define EQ_ELEM_DESC_SRC_SHIFT 7 +#define EQ_ELEM_DESC_SIZE_SHIFT 8 +#define EQ_ELEM_DESC_WRAPPED_SHIFT 31 + +/* Indicate EQ_ELEM_DESC mask. */ +#define EQ_ELEM_DESC_TYPE_MASK 0x7FU +#define EQ_ELEM_DESC_SRC_MASK 0x1U +#define EQ_ELEM_DESC_SIZE_MASK 0xFFU +#define EQ_ELEM_DESC_WRAPPED_MASK 0x1U + +/* Get the AEQ_CTRL_1 bit fields. */ +#define EQ_ELEM_DESC_GET (val, member) \ + (((val) >> EQ_ELEM_DESC_##member##_SHIFT) & \ + EQ_ELEM_DESC_##member##_MASK) + +/* Indicate EQ_CI_SIMPLE_INDIR shift. */ +#define EQ_CI_SIMPLE_INDIR_CI_SHIFT 0 +#define EQ_CI_SIMPLE_INDIR_ARMED_SHIFT 21 +#define EQ_CI_SIMPLE_INDIR_AEQ_IDX_SHIFT 30 + +/* Indicate EQ_CI_SIMPLE_INDIR mask. */ +#define EQ_CI_SIMPLE_INDIR_CI_MASK 0x1FFFFFU +#define EQ_CI_SIMPLE_INDIR_ARMED_MASK 0x1U +#define EQ_CI_SIMPLE_INDIR_AEQ_IDX_MASK 0x3U + +/* Set and clear the EQ_CI_SIMPLE_INDIR bit fields. */ +#define EQ_CI_SIMPLE_INDIR_SET (val, member) \ + (((val) & EQ_CI_SIMPLE_INDIR_##member##_MASK) \ + << EQ_CI_SIMPLE_INDIR_##member##_SHIFT) +#define EQ_CI_SIMPLE_INDIR_CLEAR (val, member) \ + ((val) & (~(EQ_CI_SIMPLE_INDIR_##member##_MASK \ + << EQ_CI_SIMPLE_INDIR_##member##_SHIFT))) + +#define EQ_WRAPPED (eq) ((u32)(eq)->wrapped << EQ_VALID_SHIFT) + +#define EQ_CONS_IDX (eq) \ + ({ \ + typeof(eq) __eq = (eq); \ + __eq->cons_idx | ((u32)__eq->wrapped << EQ_WRAPPED_SHIFT); \ + }) +#define GET_EQ_NUM_PAGES (eq, size) \ + ({ \ + typeof(eq) __eq = (eq); \ + typeof(size) __size = (size); \ + (u16)(RTE_ALIGN((u32)(__eq->eq_len * __eq->elem_size), \ + __size) / \ + __size); \ + }) + +#define GET_EQ_NUM_ELEMS (eq, pg_size) ((pg_size) / (u32)(eq)->elem_size) + +#define GET_EQ_ELEMENT (eq, idx) \ + ({ \ + typeof(eq) __eq = (eq); \ + typeof(idx) __idx = (idx); \ + ((u8 *)__eq->virt_addr[__idx / __eq->num_elem_in_pg]) + \ + (u32)((__idx & (__eq->num_elem_in_pg - 1)) * \ + __eq->elem_size); \ + }) + +#define GET_AEQ_ELEM (eq, idx) \ + ((struct hinic3_aeq_elem *)GET_EQ_ELEMENT((eq), (idx))) + +#define PAGE_IN_4K (page_size) ((page_size) >> 12) +#define EQ_SET_HW_PAGE_SIZE_VAL (eq) ((u32)ilog2(PAGE_IN_4K((eq)->page_size))) + +#define ELEMENT_SIZE_IN_32B (eq) (((eq)->elem_size) >> 5) +#define EQ_SET_HW_ELEM_SIZE_VAL (eq) ((u32)ilog2(ELEMENT_SIZE_IN_32B(eq))) + +#define AEQ_DMA_ATTR_DEFAULT 0 + +#define EQ_WRAPPED_SHIFT 20 + +#define EQ_VALID_SHIFT 31 + +#define aeq_to_aeqs (eq) \ + ({ \ + typeof(eq) __eq = (eq); \ + container_of(__eq - __eq->q_id, struct hinic3_aeqs, aeq[0]); \ + }) + +#define AEQ_MSIX_ENTRY_IDX_0 0 + +/** +* Write the consumer idx to hw. +* +* @param[in] eq +* The event queue to update the cons idx. +* @param[in] arm_state +* Indicate whether report interrupts when generate eq element. +*/ +static void +set_eq_cons_idx (struct hinic3_eq *eq,u32 arm_state) +{ +u32 eq_wrap_ci =0 ; +u32 val =0 ; +u32 addr =HINIC3_CSR_AEQ_CI_SIMPLE_INDIR_ADDR ; + + eq_wrap_ci =EQ_CONS_IDX (eq); + +/* Dpdk pmd driver only aeq0 use int_arm mode. */ +if (eq->q_id !=0 ) + val =EQ_CI_SIMPLE_INDIR_SET (HINIC3_EQ_NOT_ARMED ,ARMED ); +else + val =EQ_CI_SIMPLE_INDIR_SET (arm_state,ARMED ); + + val = val |EQ_CI_SIMPLE_INDIR_SET (eq_wrap_ci,CI ) | +EQ_CI_SIMPLE_INDIR_SET (eq->q_id,AEQ_IDX ); + +hinic3_hwif_write_reg (eq->hwdev->hwif, addr, val); +} + +/** +* Set aeq's ctrls registers. +* +* @param[in] eq +* The event queue for setting. +*/ +static void +set_aeq_ctrls (struct hinic3_eq *eq) +{ +struct hinic3_hwif *hwif = eq->hwdev->hwif; +struct irq_info *eq_irq = &eq->eq_irq; +u32 addr, val, ctrl0, ctrl1, page_size_val, elem_size; +u32 pci_intf_idx =HINIC3_PCI_INTF_IDX (hwif); + +/* Set AEQ ctrl0. */ + addr =HINIC3_CSR_AEQ_CTRL_0_ADDR ; + + val =hinic3_hwif_read_reg (hwif, addr); + + val =AEQ_CTRL_0_CLEAR (val,INTR_IDX ) & +AEQ_CTRL_0_CLEAR (val,DMA_ATTR ) & +AEQ_CTRL_0_CLEAR (val,PCI_INTF_IDX ) & +AEQ_CTRL_0_CLEAR (val,INTR_MODE ); + + ctrl0 =AEQ_CTRL_0_SET (eq_irq->msix_entry_idx,INTR_IDX ) | +AEQ_CTRL_0_SET (AEQ_DMA_ATTR_DEFAULT ,DMA_ATTR ) | +AEQ_CTRL_0_SET (pci_intf_idx,PCI_INTF_IDX ) | +AEQ_CTRL_0_SET (HINIC3_INTR_MODE_ARMED ,INTR_MODE ); + + val |= ctrl0; + +hinic3_hwif_write_reg (hwif, addr, val); + +/* Set AEQ ctrl1. */ + addr =HINIC3_CSR_AEQ_CTRL_1_ADDR ; + + page_size_val =EQ_SET_HW_PAGE_SIZE_VAL (eq); + elem_size =EQ_SET_HW_ELEM_SIZE_VAL (eq); + + ctrl1 =AEQ_CTRL_1_SET (eq->eq_len,LEN ) | +AEQ_CTRL_1_SET (elem_size,ELEM_SIZE ) | +AEQ_CTRL_1_SET (page_size_val,PAGE_SIZE ); + +hinic3_hwif_write_reg (hwif, addr, ctrl1); +} + +/** +* Initialize all the elements in the aeq. +* +* @param[in] eq +* The event queue. +* @param[in] init_val +* Value to init. +*/ +static void +aeq_elements_init (struct hinic3_eq *eq,u32 init_val) +{ +struct hinic3_aeq_elem *aeqe =NULL ; +u32 i; + +for (i =0 ; i < eq->eq_len; i++) { + aeqe =GET_AEQ_ELEM (eq, i); + aeqe->desc =cpu_to_be32 (init_val); + } + +rte_wmb ();/**< Write the init values. */ +} + +/** +* Set the pages for the event queue. +* +* @param[in] eq +* The event queue. +* @return +* 0 on success, non-zero on failure. +*/ +static int +set_eq_pages (struct hinic3_eq *eq) +{ +struct hinic3_hwif *hwif = eq->hwdev->hwif; +u32 reg, init_val; +u16 pg_num, i; +int err; + +for (pg_num =0 ; pg_num < eq->num_pages; pg_num++) { +/* Allocate memory for each page. */ + eq->eq_mz[pg_num] =hinic3_dma_zone_reserve (eq->hwdev->eth_dev, +"eq_mz" , eq->q_id, eq->page_size, + eq->page_size,SOCKET_ID_ANY ); +if (!eq->eq_mz[pg_num]) { + err = -ENOMEM ; + goto dma_alloc_err; + } + +/* Write physical memory address and virtual memory address. */ + eq->dma_addr[pg_num] = eq->eq_mz[pg_num]->iova; + eq->virt_addr[pg_num] = eq->eq_mz[pg_num]->addr; + + reg =HINIC3_AEQ_HI_PHYS_ADDR_REG (pg_num); +hinic3_hwif_write_reg (hwif, reg, +upper_32_bits (eq->dma_addr[pg_num])); + + reg =HINIC3_AEQ_LO_PHYS_ADDR_REG (pg_num); +hinic3_hwif_write_reg (hwif, reg, +lower_32_bits (eq->dma_addr[pg_num])); + } +/* Calculate the number of elements that can be accommodated. */ + eq->num_elem_in_pg =GET_EQ_NUM_ELEMS (eq, eq->page_size); +if (eq->num_elem_in_pg & (eq->num_elem_in_pg -1 )) { +PMD_DRV_LOG (ERR ,"Number element in eq page != power of 2" ); + err = -EINVAL ; + goto dma_alloc_err; + } + init_val =EQ_WRAPPED (eq); + +/* Initialize elements in the queue. */ +aeq_elements_init (eq, init_val); + +return 0 ; + +dma_alloc_err: +for (i =0 ; i < pg_num; i++) +hinic3_memzone_free (eq->eq_mz[i]); + +return err; +} + +/** +* Allocate the pages for the event queue. +* +* @param[in] eq +* The event queue. +* @return +* 0 on success, non-zero on failure. +*/ +static int +alloc_eq_pages (struct hinic3_eq *eq) +{ +u64 dma_addr_size, virt_addr_size, eq_mz_size; +int err; + +/* Calculate the size of the memory to be allocated. */ + dma_addr_size = eq->num_pages *sizeof (*eq->dma_addr); + virt_addr_size = eq->num_pages *sizeof (*eq->virt_addr); + eq_mz_size = eq->num_pages *sizeof (*eq->eq_mz); + + eq->dma_addr =rte_zmalloc ("eq_dma" , dma_addr_size, +HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!eq->dma_addr) +return -ENOMEM ; + + eq->virt_addr =rte_zmalloc ("eq_va" , virt_addr_size, +HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!eq->virt_addr) { + err = -ENOMEM ; + goto virt_addr_alloc_err; + } + + eq->eq_mz = +rte_zmalloc ("eq_mz" , eq_mz_size,HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!eq->eq_mz) { + err = -ENOMEM ; + goto eq_mz_alloc_err; + } + err =set_eq_pages (eq); +if (err !=0 ) + goto eq_pages_err; + +return 0 ; + +eq_pages_err: +rte_free (eq->eq_mz); + +eq_mz_alloc_err: +rte_free (eq->virt_addr); + +virt_addr_alloc_err: +rte_free (eq->dma_addr); + +return err; +} + +/** +* Free the pages of the event queue. +* +* @param[in] eq +* The event queue. +*/ +static void +free_eq_pages (struct hinic3_eq *eq) +{ +u16 pg_num; + +for (pg_num =0 ; pg_num < eq->num_pages; pg_num++) +hinic3_memzone_free (eq->eq_mz[pg_num]); + +rte_free (eq->eq_mz); +rte_free (eq->virt_addr); +rte_free (eq->dma_addr); +} + +static u32 +get_page_size (struct hinic3_eq *eq) +{ +u32 total_size; +u16 count, n =0 ; + +/* Total memory size. */ + total_size =RTE_ALIGN ((eq->eq_len * eq->elem_size), +HINIC3_MIN_EQ_PAGE_SIZE ); +if (total_size <= (HINIC3_EQ_MAX_PAGES *HINIC3_MIN_EQ_PAGE_SIZE )) +return HINIC3_MIN_EQ_PAGE_SIZE ; +/* Total number of pages. */ + count = (u16)(RTE_ALIGN ((total_size /HINIC3_EQ_MAX_PAGES ), +HINIC3_MIN_EQ_PAGE_SIZE ) / +HINIC3_MIN_EQ_PAGE_SIZE ); + +/* Whether count is a power of 2. */ +if (!(count & (count -1 ))) +return HINIC3_MIN_EQ_PAGE_SIZE * count; + +while (count) { + count >>=1 ; + n++; + } + +return ((u32 )HINIC3_MIN_EQ_PAGE_SIZE ) << n; +} + +/** +* Initialize AEQ. +* +* @param[in] eq +* The event queue. +* @param[in] hwdev +* The pointer to the private hardware device. +* @param[in] q_id +* Queue id number. +* @param[in] q_len +* The number of EQ elements. +* @return +* 0 on success, non-zero on failure. +*/ +static int +init_aeq (struct hinic3_eq *eq,struct hinic3_hwdev *hwdev,u16 q_id,u32 q_len) +{ +int err =0 ; + + eq->hwdev = hwdev; + eq->q_id = q_id; + eq->eq_len = q_len; + +/* Indirect access should set q_id first. */ +hinic3_hwif_write_reg (hwdev->hwif,HINIC3_AEQ_INDIR_IDX_ADDR , eq->q_id); +rte_wmb ();/**< write index before config. */ + +/* Clear eq_len to force eqe drop in hardware. */ +hinic3_hwif_write_reg (eq->hwdev->hwif,HINIC3_CSR_AEQ_CTRL_1_ADDR ,0 ); +rte_wmb (); +/* Init aeq pi to 0 before allocating aeq pages. */ +hinic3_hwif_write_reg (eq->hwdev->hwif,HINIC3_CSR_AEQ_PROD_IDX_ADDR ,0 ); + + eq->cons_idx =0 ; + eq->wrapped =0 ; + + eq->elem_size =HINIC3_AEQE_SIZE ; + eq->page_size =get_page_size (eq); + eq->orig_page_size = eq->page_size; + eq->num_pages =GET_EQ_NUM_PAGES (eq, eq->page_size); +if (eq->num_pages >HINIC3_EQ_MAX_PAGES ) { +PMD_DRV_LOG (ERR ,"Too many pages: %d for aeq" , eq->num_pages); +return -EINVAL ; + } + + err =alloc_eq_pages (eq); +if (err) { +PMD_DRV_LOG (ERR ,"Allocate pages for eq failed" ); +return err; + } + +/* Pmd driver uses AEQ_MSIX_ENTRY_IDX_0. */ + eq->eq_irq.msix_entry_idx =AEQ_MSIX_ENTRY_IDX_0 ; +set_aeq_ctrls (eq); + +set_eq_cons_idx (eq,HINIC3_EQ_ARMED ); + +if (eq->q_id ==0 ) +hinic3_set_msix_state (hwdev,0 ,HINIC3_MSIX_ENABLE ); + + eq->poll_retry_nr =HINIC3_RETRY_NUM ; + +return 0 ; +} + +/** +* Remove AEQ. +* +* @param[in] eq +* The event queue. +*/ +static void +remove_aeq (struct hinic3_eq *eq) +{ +struct irq_info *entry = &eq->eq_irq; + +if (eq->q_id ==0 ) +hinic3_set_msix_state (eq->hwdev, entry->msix_entry_idx, +HINIC3_MSIX_DISABLE ); + +/* Indirect access should set q_id first. */ +hinic3_hwif_write_reg (eq->hwdev->hwif,HINIC3_AEQ_INDIR_IDX_ADDR , + eq->q_id); + +rte_wmb ();/**< Write index before config. */ + +/* Clear eq_len to avoid hw access host memory. */ +hinic3_hwif_write_reg (eq->hwdev->hwif,HINIC3_CSR_AEQ_CTRL_1_ADDR ,0 ); + +/* Update cons_idx to avoid invalid interrupt. */ + eq->cons_idx =hinic3_hwif_read_reg (eq->hwdev->hwif, +HINIC3_CSR_AEQ_PROD_IDX_ADDR ); +set_eq_cons_idx (eq,HINIC3_EQ_NOT_ARMED ); + +free_eq_pages (eq); +} + +/** +* Init all AEQs. +* +* @param[in] hwdev +* The pointer to the private hardware device object +* @return +* 0 on success, non-zero on failure. +*/ +int +hinic3_aeqs_init (struct hinic3_hwdev *hwdev) +{ +struct hinic3_aeqs *aeqs =NULL ; +u16 num_aeqs; +int err; +u16 i, q_id; + +if (!hwdev) +return -EINVAL ; + + num_aeqs =HINIC3_HWIF_NUM_AEQS (hwdev->hwif); +if (num_aeqs >HINIC3_MAX_AEQS ) { +PMD_DRV_LOG (INFO ,"Adjust aeq num to %d" ,HINIC3_MAX_AEQS ); + num_aeqs =HINIC3_MAX_AEQS ; + }else if (num_aeqs <HINIC3_MIN_AEQS ) { +PMD_DRV_LOG (ERR ,"PMD needs %d AEQs, Chip has %d" , +HINIC3_MIN_AEQS , num_aeqs); +return -EINVAL ; + } + + aeqs =rte_zmalloc ("hinic3_aeqs" ,sizeof (*aeqs), +HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!aeqs) +return -ENOMEM ; + + hwdev->aeqs = aeqs; + aeqs->hwdev = hwdev; + aeqs->num_aeqs = num_aeqs; + +for (q_id =0 ; q_id < num_aeqs; q_id++) { + err =init_aeq (&aeqs->aeq[q_id], hwdev, q_id, +HINIC3_DEFAULT_AEQ_LEN ); +if (err) { +PMD_DRV_LOG (ERR ,"Init aeq %d failed" , q_id); + goto init_aeq_err; + } + } + +return 0 ; + +init_aeq_err: +for (i =0 ; i < q_id; i++) +remove_aeq (&aeqs->aeq[i]); + +rte_free (aeqs); +return err; +} + +/** +* Free all AEQs. +* +* @param[in] hwdev +* The pointer to the private hardware device. +*/ +void +hinic3_aeqs_free (struct hinic3_hwdev *hwdev) +{ +struct hinic3_aeqs *aeqs = hwdev->aeqs; +u16 q_id; + +for (q_id =0 ; q_id < aeqs->num_aeqs; q_id++) +remove_aeq (&aeqs->aeq[q_id]); + +rte_free (aeqs); +} + +void +hinic3_dump_aeq_info (struct hinic3_hwdev *hwdev) +{ +struct hinic3_aeq_elem *aeqe_pos =NULL ; +struct hinic3_eq *eq =NULL ; +u32 addr, ci, pi, ctrl0, idx; +int q_id; + +for (q_id =0 ; q_id < hwdev->aeqs->num_aeqs; q_id++) { + eq = &hwdev->aeqs->aeq[q_id]; +/* Indirect access should set q_id first. */ +hinic3_hwif_write_reg (eq->hwdev->hwif, +HINIC3_AEQ_INDIR_IDX_ADDR , eq->q_id); +rte_wmb ();/**< Write index before config. */ + + addr =HINIC3_CSR_AEQ_CTRL_0_ADDR ; + + ctrl0 =hinic3_hwif_read_reg (hwdev->hwif, addr); + + idx =hinic3_hwif_read_reg (hwdev->hwif, +HINIC3_AEQ_INDIR_IDX_ADDR ); + + addr =HINIC3_CSR_AEQ_CONS_IDX_ADDR ; + ci =hinic3_hwif_read_reg (hwdev->hwif, addr); + addr =HINIC3_CSR_AEQ_PROD_IDX_ADDR ; + pi =hinic3_hwif_read_reg (hwdev->hwif, addr); + aeqe_pos =GET_AEQ_ELEM (eq, eq->cons_idx); +PMD_DRV_LOG (ERR , +"Aeq id: %d, idx: %u, ctrl0: 0x%08x, wrap: %d," +" pi: 0x%x, ci: 0x%08x, desc: 0x%x" , + q_id, idx, ctrl0, eq->wrapped, pi, ci, +be32_to_cpu (aeqe_pos->desc)); + } +} + +static int +aeq_elem_handler (struct hinic3_eq *eq,u32 aeqe_desc, +struct hinic3_aeq_elem *aeqe_pos,void *param) +{ +enum hinic3_aeq_type event; +u8 data[HINIC3_AEQE_DATA_SIZE ]; +u8 size; + + event =EQ_ELEM_DESC_GET (aeqe_desc,TYPE ); +if (EQ_ELEM_DESC_GET (aeqe_desc,SRC )) { +/* SW event uses only the first 8B. */ +memcpy (data, aeqe_pos->aeqe_data,HINIC3_AEQE_DATA_SIZE ); +hinic3_be32_to_cpu (data,HINIC3_AEQE_DATA_SIZE ); +/* Just support HINIC3_STATELESS_EVENT. */ +return hinic3_nic_sw_aeqe_handler (eq->hwdev, event, data); + } + +memcpy (data, aeqe_pos->aeqe_data,HINIC3_AEQE_DATA_SIZE ); +hinic3_be32_to_cpu (data,HINIC3_AEQE_DATA_SIZE ); + size =EQ_ELEM_DESC_GET (aeqe_desc,SIZE ); + +if (event ==HINIC3_MSG_FROM_MGMT_CPU ) { +return hinic3_mgmt_msg_aeqe_handler (eq->hwdev, data, size, + param); + }else if (event ==HINIC3_MBX_FROM_FUNC ) { +return hinic3_mbox_func_aeqe_handler (eq->hwdev, data, size, + param); + }else { +PMD_DRV_LOG (ERR ,"AEQ hw event not support %d" , event); +return -EINVAL ; + } +} + +/** +* Poll one or continue aeqe, and call dedicated process. +* +* @param[in] eq +* Pointer to the event queue. +* @param[in] timeout +* equal to 0 - Poll all aeqe in eq, used in interrupt mode. +* Greater than 0 - Poll aeq until get aeqe with 'last' field set to 1, used in +* polling mode. +* @param[in] param +* Customized parameter. +* @return +* 0 on success, non-zero on failure. +*/ +int +hinic3_aeq_poll_msg (struct hinic3_eq *eq,u32 timeout,void *param) +{ +struct hinic3_aeq_elem *aeqe_pos =NULL ; +u32 aeqe_desc =0 ; +u32 eqe_cnt =0 ; +int err = -EFAULT ; +int done =HINIC3_MSG_HANDLER_RES ; +unsigned long end; +u16 i; + +for (i =0 ; ((timeout ==0 ) && (i < eq->eq_len)) || + ((timeout >0 ) && (done !=0 ) && (i < eq->eq_len)); + i++) { + err = -EIO ; + end = jiffies +msecs_to_jiffies (timeout); +do { + aeqe_pos =GET_AEQ_ELEM (eq, eq->cons_idx); +rte_rmb (); + +/* Data in HW is in Big endian format. */ + aeqe_desc =be32_to_cpu (aeqe_pos->desc); + +/* +* HW updates wrapped bit, when it adds eq element +* event. +*/ +if (EQ_ELEM_DESC_GET (aeqe_desc,WRAPPED ) != + eq->wrapped) { + err =0 ; +break ; + } + +if (timeout !=0 ) +usleep (HINIC3_AEQE_DESC_SIZE ); + }while (time_before (jiffies, end)); + +if (err !=0 )/**< Poll time out. */ +break ; +/* Handle the middle element of the event queue. */ + done =aeq_elem_handler (eq, aeqe_desc, aeqe_pos, param); + + eq->cons_idx++; +if (eq->cons_idx == eq->eq_len) { + eq->cons_idx =0 ; + eq->wrapped = !eq->wrapped; + } + +if (++eqe_cnt >=HINIC3_EQ_UPDATE_CI_STEP ) { + eqe_cnt =0 ; +set_eq_cons_idx (eq,HINIC3_EQ_NOT_ARMED ); + } + } +/* Set the consumer index of the event queue. */ +set_eq_cons_idx (eq,HINIC3_EQ_ARMED ); + +return err; +} + +void +hinic3_dev_handle_aeq_event (struct hinic3_hwdev *hwdev,void *param) +{ +struct hinic3_eq *aeq = &hwdev->aeqs->aeq[0 ]; + +/* Clear resend timer cnt register. */ +hinic3_misx_intr_clear_resend_bit (hwdev, aeq->eq_irq.msix_entry_idx, +MSIX_RESEND_TIMER_CLEAR ); + (void )hinic3_aeq_poll_msg (aeq,0 , param); +}
drivers/net/hinic3/base/hinic3_eqs.h new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 7/18 net/hinic3: add mgmt module function code
In reply to Feifei WangFrom: Yi Chen <[email protected]>
Mgmt module is a kind of administration module for the chip. It is responsible for handling administration command from host. It mainly uses aeq to implement. This patch adds related data structures, packaged interfaces and function codes.
--- drivers/net/hinic3/base/hinic3_mgmt.c | 392 ++++++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_mgmt.h | 121 ++++++++ 2 files changed, 513 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.c create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.h
drivers/net/hinic3/base/hinic3_mgmt.c new file +392 -0
@@ -0,0 +1,392 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ +#include <rte_ethdev.h> + +#include "hinic3_compat.h" +#include "hinic3_hwdev.h" +#include "hinic3_mbox.h" +#include "hinic3_mgmt.h" +#include "hinic3_nic_event.h" + +#define HINIC3_MSG_TO_MGMT_MAX_LEN 2016 + +#define MAX_PF_MGMT_BUF_SIZE 2048UL +#define SEGMENT_LEN 48 +#define ASYNC_MSG_FLAG 0x20 +#define MGMT_MSG_MAX_SEQ_ID \ + (RTE_ALIGN(HINIC3_MSG_TO_MGMT_MAX_LEN, SEGMENT_LEN) / SEGMENT_LEN) + +#define BUF_OUT_DEFAULT_SIZE 1 + +#define MGMT_MSG_SIZE_MIN 20 +#define MGMT_MSG_SIZE_STEP 16 +#define MGMT_MSG_RSVD_FOR_DEV 8 + +#define SYNC_MSG_ID_MASK 0x1F +#define ASYNC_MSG_ID_MASK 0x1F + +#define SYNC_FLAG 0 +#define ASYNC_FLAG 1 + +#define MSG_NO_RESP 0xFFFF + +#define MGMT_MSG_TIMEOUT 5000/**< Millisecond. */ + +int +hinic3_msg_to_mgmt_sync (void *hwdev,enum hinic3_mod_type mod,u16 cmd, +void *buf_in,u16 in_size,void *buf_out,u16 *out_size, +u32 timeout) +{ +int err; + +if (!hwdev) +return -EINVAL ; + +/* Send a mailbox message to the management. */ + err =hinic3_send_mbox_to_mgmt (hwdev, mod, cmd, buf_in, in_size, + buf_out, out_size, timeout); +return err; +} + +int +hinic3_msg_to_mgmt_no_ack (void *hwdev,enum hinic3_mod_type mod,u16 cmd, +void *buf_in,u16 in_size) +{ +if (!hwdev) +return -EINVAL ; + +return hinic3_send_mbox_to_mgmt_no_ack (hwdev, mod, cmd, buf_in, + in_size); +} + +static void +send_mgmt_ack (struct hinic3_msg_pf_to_mgmt *pf_to_mgmt, +enum hinic3_mod_type mod,u16 cmd,void *buf_in,u16 in_size, +u16 msg_id) +{ +u16 buf_size; + +if (!in_size) + buf_size =BUF_OUT_DEFAULT_SIZE ; +else + buf_size = in_size; + +hinic3_response_mbox_to_mgmt (pf_to_mgmt->hwdev, mod, cmd, buf_in, + buf_size, msg_id); +} + +static bool +check_mgmt_seq_id_and_seg_len (struct hinic3_recv_msg *recv_msg,u8 seq_id, +u8 seg_len,u16 msg_id) +{ +if (seq_id >MGMT_MSG_MAX_SEQ_ID || seg_len >SEGMENT_LEN ) +return false; + +if (seq_id ==0 ) { + recv_msg->seq_id = seq_id; + recv_msg->msg_id = msg_id; + }else { +if ((seq_id != recv_msg->seq_id +1 ) || + msg_id != recv_msg->msg_id) { + recv_msg->seq_id =0 ; +return false; + } + + recv_msg->seq_id = seq_id; + } + +return true; +} + +static void +hinic3_mgmt_recv_msg_handler (struct hinic3_msg_pf_to_mgmt *pf_to_mgmt, +struct hinic3_recv_msg *recv_msg, + __rte_unused void *param) +{ +void *buf_out = pf_to_mgmt->mgmt_ack_buf; +bool ack_first = false; +u16 out_size =0 ; + +memset (buf_out,0 ,MAX_PF_MGMT_BUF_SIZE ); + +/* Select the corresponding processing function according to the mod. */ +switch (recv_msg->mod) { +case HINIC3_MOD_COMM : +pf_handle_mgmt_comm_event (pf_to_mgmt->hwdev, + pf_to_mgmt, recv_msg->cmd, + recv_msg->msg, recv_msg->msg_len, buf_out, &out_size); +break ; +case HINIC3_MOD_L2NIC : +hinic3_pf_event_handler (pf_to_mgmt->hwdev, pf_to_mgmt, + recv_msg->cmd, recv_msg->msg, + recv_msg->msg_len, buf_out, &out_size); +break ; +case HINIC3_MOD_HILINK : +hinic3_pf_mag_event_handler (pf_to_mgmt->hwdev, + pf_to_mgmt, recv_msg->cmd, + recv_msg->msg, recv_msg->msg_len, buf_out, &out_size); +break ; + +default : +PMD_DRV_LOG (ERR , +"Not support mod, maybe need to response, mod: %d" , + recv_msg->mod); +break ; + } + +if (!ack_first && !recv_msg->async_mgmt_to_pf) +/* Mgmt sends async msg, sends the response. */ +send_mgmt_ack (pf_to_mgmt, recv_msg->mod, recv_msg->cmd, buf_out, + out_size, recv_msg->msg_id); +} + +/** +* Handler a recv message from mgmt channel. +* +* @param[in] pf_to_mgmt +* PF to mgmt channel. +* @param[in] recv_msg +* Received message details. +* @param[in] param +* Customized parameter. +* @return +* 0 : When aeqe is response message. +* -1 : Default result, when wrong message or not last message. +*/ +static int +recv_mgmt_msg_handler (struct hinic3_msg_pf_to_mgmt *pf_to_mgmt,u8 *header, +struct hinic3_recv_msg *recv_msg,void *param) +{ +u64 mbox_header = *((u64 *)header); +void *msg_body = header +sizeof (mbox_header); +u8 seq_id, seq_len; +u32 offset; +u8 front_id; +u16 msg_id; + +/* Don't need to get anything from hw when cmd is async. */ +if (HINIC3_MSG_HEADER_GET (mbox_header,DIRECTION ) == +HINIC3_MSG_RESPONSE ) +return 0 ; + + seq_len =HINIC3_MSG_HEADER_GET (mbox_header,SEG_LEN ); + seq_id =HINIC3_MSG_HEADER_GET (mbox_header,SEQID ); + msg_id =HINIC3_MSG_HEADER_GET (mbox_header,MSG_ID ); + front_id = recv_msg->seq_id; + +/* Check the consistency between seq_id and seg_len. */ +if (!check_mgmt_seq_id_and_seg_len (recv_msg, seq_id, seq_len, msg_id)) { +PMD_DRV_LOG (ERR , +"Mgmt msg sequence id and segment length check " +"failed, front seq_id: 0x%x, current seq_id: 0x%x," +" seg len: 0x%x front msg_id: %d, cur msg_id: %d" , + front_id, seq_id, seq_len, recv_msg->msg_id, + msg_id); +/* Set seq_id to invalid seq_id. */ + recv_msg->seq_id =MGMT_MSG_MAX_SEQ_ID ; +return HINIC3_MSG_HANDLER_RES ; + } + + offset = seq_id *SEGMENT_LEN ; +memcpy ((u8 *)recv_msg->msg + offset, msg_body, seq_len); + +if (!HINIC3_MSG_HEADER_GET (mbox_header,LAST )) +return HINIC3_MSG_HANDLER_RES ; +/* Setting the message receiving information. */ + recv_msg->cmd =HINIC3_MSG_HEADER_GET (mbox_header,CMD ); + recv_msg->mod =HINIC3_MSG_HEADER_GET (mbox_header,MODULE ); + recv_msg->async_mgmt_to_pf =HINIC3_MSG_HEADER_GET (mbox_header,NO_ACK ); + recv_msg->msg_len =HINIC3_MSG_HEADER_GET (mbox_header,MSG_LEN ); + recv_msg->msg_id =HINIC3_MSG_HEADER_GET (mbox_header,MSG_ID ); + recv_msg->seq_id =MGMT_MSG_MAX_SEQ_ID ; + +hinic3_mgmt_recv_msg_handler (pf_to_mgmt, recv_msg, param); + +return HINIC3_MSG_HANDLER_RES ; +} + +/** +* Handler for a aeqe from mgmt channel. +* +* @param[in] hwdev +* The pointer to the private hardware device. +* @param[in] header +* The header of the message. +* @param[in] size +* Indicate size. +* @param[in] param +* Customized parameter. +* @return +* zero: When aeqe is response message +* negative: When wrong message or not last message. +*/ +int +hinic3_mgmt_msg_aeqe_handler (void *hwdev,u8 *header,u8 size,void *param) +{ +struct hinic3_hwdev *dev = (struct hinic3_hwdev *)hwdev; +struct hinic3_msg_pf_to_mgmt *pf_to_mgmt =NULL ; +struct hinic3_recv_msg *recv_msg =NULL ; +bool is_send_dir = false; + +/* For mbox messgae, invoke the mailbox processing function. */ +if ((HINIC3_MSG_HEADER_GET (*(u64 *)header,SOURCE ) == +HINIC3_MSG_FROM_MBOX )) { +return hinic3_mbox_func_aeqe_handler (hwdev, header, size, + param); + } + + pf_to_mgmt = dev->pf_to_mgmt; + + is_send_dir = (HINIC3_MSG_HEADER_GET (*(u64 *)header,DIRECTION ) == +HINIC3_MSG_DIRECT_SEND ) ? true : false; + +/* Determine whether a message is received or responsed. */ + recv_msg = is_send_dir ? &pf_to_mgmt->recv_msg_from_mgmt + : &pf_to_mgmt->recv_resp_msg_from_mgmt; + +return recv_mgmt_msg_handler (pf_to_mgmt, header, recv_msg, param); +} + +/** +* Allocate received message memory. +* +* @param[in] recv_msg +* Pointer that will hold the allocated data. +* @return +* 0 on success, non-zero on failure. +*/ +static int +alloc_recv_msg (struct hinic3_recv_msg *recv_msg) +{ + recv_msg->seq_id =MGMT_MSG_MAX_SEQ_ID ; + + recv_msg->msg =rte_zmalloc ("recv_msg" ,MAX_PF_MGMT_BUF_SIZE , +HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!recv_msg->msg) +return -ENOMEM ; + +return 0 ; +} + +static void +free_recv_msg (struct hinic3_recv_msg *recv_msg) +{ +rte_free (recv_msg->msg); +} + +/** +* Allocate all the message buffers of PF to mgmt channel. +* +* @param[in] pf_to_mgmt +* PF to mgmt channel. +* @return +* 0 on success, non-zero on failure. +*/ +static int +alloc_msg_buf (struct hinic3_msg_pf_to_mgmt *pf_to_mgmt) +{ +int err; + + err =alloc_recv_msg (&pf_to_mgmt->recv_msg_from_mgmt); +if (err) { +PMD_DRV_LOG (ERR ,"Allocate recv msg failed" ); +return err; + } + + err =alloc_recv_msg (&pf_to_mgmt->recv_resp_msg_from_mgmt); +if (err) { +PMD_DRV_LOG (ERR ,"Allocate resp recv msg failed" ); + goto alloc_msg_for_resp_err; + } + + pf_to_mgmt->mgmt_ack_buf =rte_zmalloc ("mgmt_ack_buf" , +MAX_PF_MGMT_BUF_SIZE , +HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!pf_to_mgmt->mgmt_ack_buf) { + err = -ENOMEM ; + goto ack_msg_buf_err; + } + +return 0 ; + +ack_msg_buf_err: +free_recv_msg (&pf_to_mgmt->recv_resp_msg_from_mgmt); + +alloc_msg_for_resp_err: +free_recv_msg (&pf_to_mgmt->recv_msg_from_mgmt); +return err; +} + +/** +* Free all the message buffers of PF to mgmt channel. +* +* @param[in] pf_to_mgmt +* PF to mgmt channel. +*/ +static void +free_msg_buf (struct hinic3_msg_pf_to_mgmt *pf_to_mgmt) +{ +rte_free (pf_to_mgmt->mgmt_ack_buf); +free_recv_msg (&pf_to_mgmt->recv_resp_msg_from_mgmt); +free_recv_msg (&pf_to_mgmt->recv_msg_from_mgmt); +} + +/** +* Initialize PF to mgmt channel. +* +* @param[in] hwdev +* The pointer to the private hardware device. +* @return +* 0 on success, non-zero on failure. +*/ +int +hinic3_pf_to_mgmt_init (struct hinic3_hwdev *hwdev) +{ +struct hinic3_msg_pf_to_mgmt *pf_to_mgmt; +int err; + + pf_to_mgmt =rte_zmalloc ("pf_to_mgmt" ,sizeof (*pf_to_mgmt), +HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!pf_to_mgmt) +return -ENOMEM ; + + hwdev->pf_to_mgmt = pf_to_mgmt; + pf_to_mgmt->hwdev = hwdev; + + err =hinic3_mutex_init (&pf_to_mgmt->sync_msg_mutex,NULL ); +if (err) + goto mutex_init_err; + + err =alloc_msg_buf (pf_to_mgmt); +if (err) { +PMD_DRV_LOG (ERR ,"Allocate msg buffers failed" ); + goto alloc_msg_buf_err; + } + +return 0 ; + +alloc_msg_buf_err: +hinic3_mutex_destroy (&pf_to_mgmt->sync_msg_mutex); + +mutex_init_err: +rte_free (pf_to_mgmt); + +return err; +} + +/** +* Free PF to mgmt channel. +* +* @param[in] hwdev +* The pointer to the private hardware device. +*/ +void +hinic3_pf_to_mgmt_free (struct hinic3_hwdev *hwdev) +{ +struct hinic3_msg_pf_to_mgmt *pf_to_mgmt = hwdev->pf_to_mgmt; + +free_msg_buf (pf_to_mgmt); +hinic3_mutex_destroy (&pf_to_mgmt->sync_msg_mutex); +rte_free (pf_to_mgmt); +}
drivers/net/hinic3/base/hinic3_mgmt.h new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 8/18 net/hinic3: add module about hardware operation
In reply to Feifei WangFrom: Yi Chen <[email protected]>
Add code and data structure for hardware operation, including configuration, query, initialization and release.
--- drivers/net/hinic3/base/hinic3_hw_cfg.c | 240 ++++++++++ drivers/net/hinic3/base/hinic3_hw_cfg.h | 121 +++++ drivers/net/hinic3/base/hinic3_hw_comm.c | 452 ++++++++++++++++++ drivers/net/hinic3/base/hinic3_hw_comm.h | 366 +++++++++++++++ drivers/net/hinic3/base/hinic3_hwdev.c | 573 +++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_hwdev.h | 177 +++++++ 6 files changed, 1929 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.c create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.h create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.c create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.h create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.c create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.h
drivers/net/hinic3/base/hinic3_hw_cfg.c new file +240 -0
@@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include "hinic3_compat.h" +#include "hinic3_mbox.h" +#include "hinic3_mgmt.h" +#include "hinic3_hw_cfg.h" +#include "hinic3_hwdev.h" +#include "hinic3_hwif.h" + +static void +parse_pub_res_cap (struct service_cap *cap, +struct hinic3_cfg_cmd_dev_cap *dev_cap,enum func_type type) +{ + cap->host_id = dev_cap->host_id; + cap->ep_id = dev_cap->ep_id; + cap->er_id = dev_cap->er_id; + cap->port_id = dev_cap->port_id; + + cap->svc_type = dev_cap->svc_cap_en; + cap->chip_svc_type = cap->svc_type; + + cap->cos_valid_bitmap = dev_cap->valid_cos_bitmap; + cap->flexq_en = dev_cap->flexq_en; + + cap->host_total_function = dev_cap->host_total_func; + cap->max_vf =0 ; +if (type ==TYPE_PF || type ==TYPE_PPF ) { + cap->max_vf = dev_cap->max_vf; + cap->pf_num = dev_cap->host_pf_num; + cap->pf_id_start = dev_cap->pf_id_start; + cap->vf_num = dev_cap->host_vf_num; + cap->vf_id_start = dev_cap->vf_id_start; + } + +PMD_DRV_LOG (INFO ,"Get public resource capability: " ); +PMD_DRV_LOG (INFO , +"host_id: 0x%x, ep_id: 0x%x, er_id: 0x%x, port_id: 0x%x" , + cap->host_id, cap->ep_id, cap->er_id, cap->port_id); +PMD_DRV_LOG (INFO ,"host_total_function: 0x%x, max_vf: 0x%x" , + cap->host_total_function, cap->max_vf); +PMD_DRV_LOG (INFO , +"host_pf_num: 0x%x, pf_id_start: 0x%x, host_vf_num: 0x%x, " +"vf_id_start: 0x%x" , + cap->pf_num, cap->pf_id_start, cap->vf_num, + cap->vf_id_start); +} + +static void +parse_l2nic_res_cap (struct service_cap *cap, +struct hinic3_cfg_cmd_dev_cap *dev_cap) +{ +struct nic_service_cap *nic_cap = &cap->nic_cap; + + nic_cap->max_sqs = dev_cap->nic_max_sq_id +1 ; + nic_cap->max_rqs = dev_cap->nic_max_rq_id +1 ; + +PMD_DRV_LOG (INFO , +"L2nic resource capbility, " +"max_sqs: 0x%x, max_rqs: 0x%x" , + nic_cap->max_sqs, nic_cap->max_rqs); +} + +static void +parse_dev_cap (struct hinic3_hwdev *dev,struct hinic3_cfg_cmd_dev_cap *dev_cap, +enum func_type type) +{ +struct service_cap *cap = &dev->cfg_mgmt->svc_cap; + +parse_pub_res_cap (cap, dev_cap, type); + +if (IS_NIC_TYPE (dev)) +parse_l2nic_res_cap (cap, dev_cap); +} + +static int +get_cap_from_fw (struct hinic3_hwdev *hwdev,enum func_type type) +{ +struct hinic3_cfg_cmd_dev_cap dev_cap; +u16 out_len =sizeof (dev_cap); +int err; + +memset (&dev_cap,0 ,sizeof (dev_cap)); + dev_cap.func_id =hinic3_global_func_id (hwdev); + err =hinic3_msg_to_mgmt_sync (hwdev,HINIC3_MOD_CFGM , +HINIC3_CFG_CMD_GET_DEV_CAP , &dev_cap, +sizeof (dev_cap), &dev_cap, &out_len,0 ); +if (err || dev_cap.status || !out_len) { +PMD_DRV_LOG (ERR , +"Get capability from FW failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, dev_cap.status, out_len); +return -EFAULT ; + } + +parse_dev_cap (hwdev, &dev_cap, type); +return 0 ; +} + +static int +get_dev_cap (struct hinic3_hwdev *hwdev) +{ +enum func_type type =HINIC3_FUNC_TYPE (hwdev); + +switch (type) { +case TYPE_PF : +case TYPE_PPF : +case TYPE_VF : +if (get_cap_from_fw (hwdev, type) !=0 ) +return -EFAULT ; +break ; +default : +PMD_DRV_LOG (ERR ,"Unsupported PCIe function type: %d" , type); +return -EINVAL ; + } + +return 0 ; +} + +int +cfg_mbx_vf_proc_msg(void *hwdev, __rte_unused void *pri_handle, u16 cmd, + __rte_unused void *buf_in, __rte_unused u16 in_size, + __rte_unused void *buf_out, __rte_unused u16 *out_size) +{ +struct hinic3_hwdev *dev = hwdev; + +if (!dev) +return -EINVAL ; + +PMD_DRV_LOG (WARNING ,"Unsupported cfg mbox vf event %d to process" , + cmd); + +return 0 ; +} + +int +hinic3_init_cfg_mgmt (void *dev) +{ +struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev; +struct cfg_mgmt_info *cfg_mgmt =NULL ; + + cfg_mgmt =rte_zmalloc ("cfg_mgmt" ,sizeof (*cfg_mgmt), +HINIC3_MEM_ALLOC_ALIGN_MIN ); +if (!cfg_mgmt) +return -ENOMEM ; + +memset (cfg_mgmt,0 ,sizeof (struct cfg_mgmt_info )); + hwdev->cfg_mgmt = cfg_mgmt; + cfg_mgmt->hwdev = hwdev; + +return 0 ; +} + +int +hinic3_init_capability (void *dev) +{ +struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev; + +return get_dev_cap (hwdev); +} + +void +hinic3_deinit_cfg_mgmt (void *dev) +{ +rte_free (((struct hinic3_hwdev *)dev)->cfg_mgmt); + ((struct hinic3_hwdev *)dev)->cfg_mgmt =NULL ; +} + +#ifdef HINIC3_RELEASE +static bool +hinic3_support_nic (void *hwdev,struct nic_service_cap *cap) +{ +struct hinic3_hwdev *dev = (struct hinic3_hwdev *)hwdev; + +if (!hwdev) +return false; + +if (!IS_NIC_TYPE (dev)) +return false; + +if (cap) +memcpy (cap, &dev->cfg_mgmt->svc_cap.nic_cap,sizeof (*cap)); + +return true; +} + +static bool +hinic3_func_for_mgmt (void *hwdev) +{ +struct hinic3_hwdev *dev = hwdev; + +if (!hwdev) +return false; + +if (dev->cfg_mgmt->svc_cap.chip_svc_type >=CFG_SVC_NIC_BIT0 ) +return false; +else +return true; +} +#endif + +u16 +hinic3_func_max_sqs (void *hwdev) +{ +struct hinic3_hwdev *dev = hwdev; + +if (!dev) { +PMD_DRV_LOG (INFO ,"Hwdev is NULL for getting max_sqs" ); +return 0 ; + } + +return dev->cfg_mgmt->svc_cap.nic_cap.max_sqs; +} + +u16 +hinic3_func_max_rqs (void *hwdev) +{ +struct hinic3_hwdev *dev = hwdev; + +if (!dev) { +PMD_DRV_LOG (INFO ,"Hwdev is NULL for getting max_rqs" ); +return 0 ; + } + +return dev->cfg_mgmt->svc_cap.nic_cap.max_rqs; +} + +u8 +hinic3_physical_port_id (void *hwdev) +{ +struct hinic3_hwdev *dev = hwdev; + +if (!dev) { +PMD_DRV_LOG (INFO ,"Hwdev is NULL for getting physical port id" ); +return 0 ; + } + +return dev->cfg_mgmt->svc_cap.port_id; +}
drivers/net/hinic3/base/hinic3_hw_cfg.h new file +121 -0
121 lines not on this page · raw message
drivers/net/hinic3/base/hinic3_hw_comm.c new file +452 -0
452 lines not on this page · raw message
drivers/net/hinic3/base/hinic3_hw_comm.h new file +366 -0
366 lines not on this page · raw message
drivers/net/hinic3/base/hinic3_hwdev.c new file +573 -0
573 lines not on this page · raw message
drivers/net/hinic3/base/hinic3_hwdev.h new file +177 -0
177 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 9/18 net/hinic3: add a NIC business configuration module
In reply to Feifei WangFrom: Yi Chen <[email protected]>
The items of configurations and queries for NIC business include MAC, VLAN, MTU, RSS and so on. These configurations and queries are handled by mgmt module. This patch introduces related data structures and function codes.
--- drivers/net/hinic3/base/hinic3_nic_cfg.c | 1828 ++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_nic_cfg.h | 1527 ++++++++++++++++++ 2 files changed, 3355 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.c create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.h
drivers/net/hinic3/base/hinic3_nic_cfg.c new file +1828 -0
@@ -0,0 +1,1828 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include <rte_ether.h> + +#include "hinic3_compat.h" +#include "hinic3_cmd.h" +#include "hinic3_cmdq.h" +#include "hinic3_hw_cfg.h" +#include "hinic3_hwdev.h" +#include "hinic3_hwif.h" +#include "hinic3_mbox.h" +#include "hinic3_nic_cfg.h" +#include "hinic3_wq.h" + +struct vf_msg_handler { +u16 cmd; +}; + +static const struct vf_msg_handler vf_cmd_handler[] = { + { + .cmd =HINIC3_NIC_CMD_VF_REGISTER , + }, + + { + .cmd =HINIC3_NIC_CMD_GET_MAC , + }, + + { + .cmd =HINIC3_NIC_CMD_SET_MAC , + }, + + { + .cmd =HINIC3_NIC_CMD_DEL_MAC , + }, + + { + .cmd =HINIC3_NIC_CMD_UPDATE_MAC , + }, + + { + .cmd =HINIC3_NIC_CMD_VF_COS , + }, +}; + +static const struct vf_msg_handler vf_mag_cmd_handler[] = { + { + .cmd =MAG_CMD_GET_LINK_STATUS , + }, +}; + +static int mag_msg_to_mgmt_sync (void *hwdev,u16 cmd,void *buf_in,u16 in_size, +void *buf_out,u16 *out_size); + +/** +* If device is VF and command is found in a predefined list, send to PF, else +* send to management module. +* +* @param[in] hwdev +* The pointer to the hardware device structure. +* @param[in] cmd +* The command to send. +* @param[in] buf_in +* The input buffer containing the request data. +* @param[in] in_size +* The size of the input buffer. +* @param[out] buf_out +* The output buffer to receive the response data. +* @param[out] out_size +* The size of the output buffer on return. +* +* @return +* 0 on success, non-zero on failure. +*/ +int +l2nic_msg_to_mgmt_sync (void *hwdev,u16 cmd,void *buf_in,u16 in_size, +void *buf_out,u16 *out_size) +{ +u32 i, cmd_cnt =ARRAY_LEN (vf_cmd_handler); +bool cmd_to_pf = false; + +if (hinic3_func_type (hwdev) ==TYPE_VF ) { +for (i =0 ; i < cmd_cnt; i++) { +if (cmd == vf_cmd_handler[i].cmd) + cmd_to_pf = true; + } + } + +if (cmd_to_pf) { +return hinic3_mbox_to_pf (hwdev,HINIC3_MOD_L2NIC , cmd, buf_in, + in_size, buf_out, out_size,0 ); + } + +return hinic3_msg_to_mgmt_sync (hwdev,HINIC3_MOD_L2NIC , cmd, buf_in, + in_size, buf_out, out_size,0 ); +} + +/** +* Set CI table for a SQ. +* +* Configure the CI table with attributes like CI address, pending limit, +* coalescing time, and optional interrupt settings for specified SQ. +* +* @param[in] hwdev +* Pointer to hardware device structure. +* @param[in] attr +* Attributes to configure for CI table. +* +* @return +* 0 on success, non-zero on failure. +*/ +int +hinic3_set_ci_table (void *hwdev,struct hinic3_sq_attr *attr) +{ +struct hinic3_cmd_cons_idx_attr cons_idx_attr; +u16 out_size =sizeof (cons_idx_attr); +int err; + +if (!hwdev || !attr) +return -EINVAL ; + +memset (&cons_idx_attr,0 ,sizeof (cons_idx_attr)); + cons_idx_attr.func_idx =hinic3_global_func_id (hwdev); + cons_idx_attr.dma_attr_off = attr->dma_attr_off; + cons_idx_attr.pending_limit = attr->pending_limit; + cons_idx_attr.coalescing_time = attr->coalescing_time; + +if (attr->intr_en) { + cons_idx_attr.intr_en = attr->intr_en; + cons_idx_attr.intr_idx = attr->intr_idx; + } + + cons_idx_attr.l2nic_sqn = attr->l2nic_sqn; + cons_idx_attr.ci_addr = attr->ci_dma_base; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SQ_CI_ATTR_SET , + &cons_idx_attr,sizeof (cons_idx_attr), + &cons_idx_attr, &out_size); +if (err || !out_size || cons_idx_attr.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set ci attribute table failed, " +"err: %d, status: 0x%x, out_size: 0x%x" , + err, cons_idx_attr.msg_head.status, out_size); +return -EFAULT ; + } + +return 0 ; +} + +#define PF_SET_VF_MAC (hwdev, status) \ + (hinic3_func_type(hwdev) == TYPE_VF && \ + (status) == HINIC3_PF_SET_VF_ALREADY) + +static int +hinic3_check_mac_info (void *hwdev,u8 status,u16 vlan_id) +{ +if ((status && status !=HINIC3_MGMT_STATUS_EXIST ) || + ((vlan_id &CHECK_IPSU_15BIT ) && + status ==HINIC3_MGMT_STATUS_EXIST )) { +if (PF_SET_VF_MAC (hwdev, status)) +return 0 ; + +return -EINVAL ; + } + +return 0 ; +} + +#define VLAN_N_VID 4096 + +int +hinic3_set_mac (void *hwdev,const u8 *mac_addr,u16 vlan_id,u16 func_id) +{ +struct hinic3_port_mac_set mac_info; +u16 out_size =sizeof (mac_info); +int err; + +if (!hwdev || !mac_addr) +return -EINVAL ; + +memset (&mac_info,0 ,sizeof (mac_info)); + +if (vlan_id >=VLAN_N_VID ) { +PMD_DRV_LOG (ERR ,"Invalid VLAN number: %d" , vlan_id); +return -EINVAL ; + } + + mac_info.func_id = func_id; + mac_info.vlan_id = vlan_id; +memmove (mac_info.mac, mac_addr,ETH_ALEN ); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SET_MAC , &mac_info, +sizeof (mac_info), &mac_info, &out_size); +if (err || !out_size || +hinic3_check_mac_info (hwdev, mac_info.msg_head.status, + mac_info.vlan_id)) { +PMD_DRV_LOG (ERR , +"Update MAC failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, mac_info.msg_head.status, out_size); +return -EIO ; + } + +if (PF_SET_VF_MAC (hwdev, mac_info.msg_head.status)) { +PMD_DRV_LOG (WARNING , +"PF has already set VF mac, Ignore set operation" ); +return HINIC3_PF_SET_VF_ALREADY ; + } + +if (mac_info.msg_head.status ==HINIC3_MGMT_STATUS_EXIST ) { +PMD_DRV_LOG (WARNING , +"MAC is repeated. Ignore update operation" ); +return 0 ; + } + +return 0 ; +} + +int +hinic3_del_mac (void *hwdev,const u8 *mac_addr,u16 vlan_id,u16 func_id) +{ +struct hinic3_port_mac_set mac_info; +u16 out_size =sizeof (mac_info); +int err; + +if (!hwdev || !mac_addr) +return -EINVAL ; + +if (vlan_id >=VLAN_N_VID ) { +PMD_DRV_LOG (ERR ,"Invalid VLAN number: %d" , vlan_id); +return -EINVAL ; + } + +memset (&mac_info,0 ,sizeof (mac_info)); + mac_info.func_id = func_id; + mac_info.vlan_id = vlan_id; +memmove (mac_info.mac, mac_addr,ETH_ALEN ); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_DEL_MAC , &mac_info, +sizeof (mac_info), &mac_info, &out_size); +if (err || !out_size || + (mac_info.msg_head.status && + !PF_SET_VF_MAC (hwdev, mac_info.msg_head.status))) { +PMD_DRV_LOG (ERR , +"Delete MAC failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, mac_info.msg_head.status, out_size); +return -EIO ; + } + +if (PF_SET_VF_MAC (hwdev, mac_info.msg_head.status)) { +PMD_DRV_LOG (WARNING , +"PF has already set VF mac, Ignore delete operation" ); +return HINIC3_PF_SET_VF_ALREADY ; + } + +return 0 ; +} + +int +hinic3_update_mac (void *hwdev,u8 *old_mac,u8 *new_mac,u16 vlan_id, +u16 func_id) +{ +struct hinic3_port_mac_update mac_info; +u16 out_size =sizeof (mac_info); +int err; + +if (!hwdev || !old_mac || !new_mac) +return -EINVAL ; + +if (vlan_id >=VLAN_N_VID ) { +PMD_DRV_LOG (ERR ,"Invalid VLAN number: %d" , vlan_id); +return -EINVAL ; + } + +memset (&mac_info,0 ,sizeof (mac_info)); + mac_info.func_id = func_id; + mac_info.vlan_id = vlan_id; +memcpy (mac_info.old_mac, old_mac,ETH_ALEN ); +memcpy (mac_info.new_mac, new_mac,ETH_ALEN ); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_UPDATE_MAC , + &mac_info,sizeof (mac_info), &mac_info, + &out_size); +if (err || !out_size || +hinic3_check_mac_info (hwdev, mac_info.msg_head.status, + mac_info.vlan_id)) { +PMD_DRV_LOG (ERR , +"Update MAC failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, mac_info.msg_head.status, out_size); +return -EIO ; + } + +if (PF_SET_VF_MAC (hwdev, mac_info.msg_head.status)) { +PMD_DRV_LOG (WARNING , +"PF has already set VF MAC. Ignore update operation" ); +return HINIC3_PF_SET_VF_ALREADY ; + } + +if (mac_info.msg_head.status ==HINIC3_MGMT_STATUS_EXIST ) { +PMD_DRV_LOG (INFO ,"MAC is repeated. Ignore update operation" ); +return 0 ; + } + +return 0 ; +} + +int +hinic3_get_default_mac (void *hwdev,u8 *mac_addr,int ether_len) +{ +struct hinic3_port_mac_set mac_info; +u16 out_size =sizeof (mac_info); +int err; + +if (!hwdev || !mac_addr) +return -EINVAL ; + +memset (&mac_info,0 ,sizeof (mac_info)); + mac_info.func_id =hinic3_global_func_id (hwdev); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_GET_MAC , &mac_info, +sizeof (mac_info), &mac_info, &out_size); +if (err || !out_size || mac_info.msg_head.status) { +PMD_DRV_LOG (ERR , +"Get MAC failed, err: %d, status: 0x%x, out size: 0x%x" , + err, mac_info.msg_head.status, out_size); +return -EINVAL ; + } + +memmove (mac_addr, mac_info.mac, ether_len); + +return 0 ; +} + +static int +hinic3_config_vlan (void *hwdev,u8 opcode,u16 vlan_id,u16 func_id) +{ +struct hinic3_cmd_vlan_config vlan_info; +u16 out_size =sizeof (vlan_info); +int err; + +memset (&vlan_info,0 ,sizeof (vlan_info)); + vlan_info.opcode = opcode; + vlan_info.func_id = func_id; + vlan_info.vlan_id = vlan_id; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CFG_FUNC_VLAN , + &vlan_info,sizeof (vlan_info), &vlan_info, + &out_size); +if (err || !out_size || vlan_info.msg_head.status) { +PMD_DRV_LOG (ERR , +"%s vlan failed, err: %d, status: 0x%x, out size: 0x%x" , + opcode ==HINIC3_CMD_OP_ADD ?"Add" :"Delete" , err, + vlan_info.msg_head.status, out_size); +return -EINVAL ; + } + +return 0 ; +} + +int +hinic3_add_vlan (void *hwdev,u16 vlan_id,u16 func_id) +{ +if (!hwdev) +return -EINVAL ; + +return hinic3_config_vlan (hwdev,HINIC3_CMD_OP_ADD , vlan_id, func_id); +} + +int +hinic3_del_vlan (void *hwdev,u16 vlan_id,u16 func_id) +{ +if (!hwdev) +return -EINVAL ; + +return hinic3_config_vlan (hwdev,HINIC3_CMD_OP_DEL , vlan_id, func_id); +} + +int +hinic3_get_port_info (void *hwdev,struct nic_port_info *port_info) +{ +struct hinic3_cmd_port_info port_msg; +u16 out_size =sizeof (port_msg); +int err; + +if (!hwdev || !port_info) +return -EINVAL ; + +memset (&port_msg,0 ,sizeof (port_msg)); + port_msg.port_id =hinic3_physical_port_id (hwdev); + + err =mag_msg_to_mgmt_sync (hwdev,MAG_CMD_GET_PORT_INFO , &port_msg, +sizeof (port_msg), &port_msg, &out_size); +if (err || !out_size || port_msg.msg_head.status) { +PMD_DRV_LOG (ERR , +"Get port info failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, port_msg.msg_head.status, out_size); +return -EINVAL ; + } + + port_info->autoneg_cap = port_msg.autoneg_cap; + port_info->autoneg_state = port_msg.autoneg_state; + port_info->duplex = port_msg.duplex; + port_info->port_type = port_msg.port_type; + port_info->speed = port_msg.speed; + port_info->fec = port_msg.fec; + +return 0 ; +} + +int +hinic3_get_link_state (void *hwdev,u8 *link_state) +{ +struct hinic3_cmd_link_state get_link; +u16 out_size =sizeof (get_link); +int err; + +if (!hwdev || !link_state) +return -EINVAL ; + +memset (&get_link,0 ,sizeof (get_link)); + get_link.port_id =hinic3_physical_port_id (hwdev); + err =mag_msg_to_mgmt_sync (hwdev,MAG_CMD_GET_LINK_STATUS , &get_link, +sizeof (get_link), &get_link, &out_size); +if (err || !out_size || get_link.msg_head.status) { +PMD_DRV_LOG (ERR , +"Get link state failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, get_link.msg_head.status, out_size); +return -EIO ; + } + + *link_state = get_link.state; + +return 0 ; +} + +int +hinic3_set_vport_enable (void *hwdev,bool enable) +{ +struct hinic3_vport_state en_state; +u16 out_size =sizeof (en_state); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&en_state,0 ,sizeof (en_state)); + en_state.func_id =hinic3_global_func_id (hwdev); + en_state.state = enable ?1 :0 ; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SET_VPORT_ENABLE , + &en_state,sizeof (en_state), &en_state, + &out_size); +if (err || !out_size || en_state.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set vport state failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, en_state.msg_head.status, out_size); +return -EIO ; + } + +return 0 ; +} + +int +hinic3_set_port_enable (void *hwdev,bool enable) +{ +struct mag_cmd_set_port_enable en_state; +u16 out_size =sizeof (en_state); +int err; + +if (!hwdev) +return -EINVAL ; + +if (hinic3_func_type (hwdev) ==TYPE_VF ) +return 0 ; + +memset (&en_state,0 ,sizeof (en_state)); + en_state.function_id =hinic3_global_func_id (hwdev); + en_state.state = enable ?MAG_CMD_TX_ENABLE |MAG_CMD_RX_ENABLE + :MAG_CMD_PORT_DISABLE ; + + err =mag_msg_to_mgmt_sync (hwdev,MAG_CMD_SET_PORT_ENABLE , &en_state, +sizeof (en_state), &en_state, &out_size); +if (err || !out_size || en_state.head.status) { +PMD_DRV_LOG (ERR , +"Set port state failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, en_state.head.status, out_size); +return -EIO ; + } + +return 0 ; +} + +int +hinic3_flush_qps_res (void *hwdev) +{ +struct hinic3_cmd_clear_qp_resource sq_res; +u16 out_size =sizeof (sq_res); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&sq_res,0 ,sizeof (sq_res)); + sq_res.func_id =hinic3_global_func_id (hwdev); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CLEAR_QP_RESOURCE , + &sq_res,sizeof (sq_res), &sq_res, + &out_size); +if (err || !out_size || sq_res.msg_head.status) { +PMD_DRV_LOG (ERR , +"Clear sq resources failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, sq_res.msg_head.status, out_size); +return -EIO ; + } + +return 0 ; +} + +/** +* Get or set the flow control (pause frame) settings for NIC. +* +* @param[in] hwdev +* Pointer to the hardware device. +* @param[in] opcode +* The operation to perform. Use `HINIC3_CMD_OP_SET` to set the pause settings +* and `HINIC3_CMD_OP_GET` to get them. +* @param[out] nic_pause +* Pointer to the `nic_pause_config` structure. This structure contains the flow +* control settings (auto-negotiation, Rx pause, and Tx pause). It is updated +* when getting settings. When setting, the values in this structure are used. +* +* @return +* 0 on success, non-zero on failure. +* - -EIO if the operation failed. +*/ +static int +hinic3_cfg_hw_pause (void *hwdev,u8 opcode,struct nic_pause_config *nic_pause) +{ +struct hinic3_cmd_pause_config pause_info = {0 }; +u16 out_size =sizeof (pause_info); +int err =0 ; + + pause_info.port_id =hinic3_physical_port_id (hwdev); + pause_info.opcode = opcode; +if (opcode ==HINIC3_CMD_OP_SET ) { + pause_info.auto_neg = nic_pause->auto_neg; + pause_info.rx_pause = nic_pause->rx_pause; + pause_info.tx_pause = nic_pause->tx_pause; + } + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CFG_PAUSE_INFO , + &pause_info,sizeof (pause_info), + &pause_info, &out_size); +if (err || !out_size || pause_info.msg_head.status) { +PMD_DRV_LOG (ERR , +"%s pause info failed, err: %d, status: 0x%x, out " +"size: 0x%x" , + opcode ==HINIC3_CMD_OP_SET ?"Set" :"Get" , err, + pause_info.msg_head.status, out_size); +return -EIO ; + } + +if (opcode ==HINIC3_CMD_OP_GET ) { + nic_pause->auto_neg = pause_info.auto_neg; + nic_pause->rx_pause = pause_info.rx_pause; + nic_pause->tx_pause = pause_info.tx_pause; + } + +return 0 ; +} + +int +hinic3_set_pause_info (void *hwdev,struct nic_pause_config nic_pause) +{ +if (!hwdev) +return -EINVAL ; + +return hinic3_cfg_hw_pause (hwdev,HINIC3_CMD_OP_SET , &nic_pause); +} + +int +hinic3_get_pause_info (void *hwdev,struct nic_pause_config *nic_pause) +{ +if (!hwdev || !nic_pause) +return -EINVAL ; + +return hinic3_cfg_hw_pause (hwdev,HINIC3_CMD_OP_GET , nic_pause); +} + +int +hinic3_get_vport_stats (void *hwdev,struct hinic3_vport_stats *stats) +{ +struct hinic3_port_stats_info stats_info; +struct hinic3_cmd_vport_stats vport_stats; +u16 out_size =sizeof (vport_stats); +int err; + +if (!hwdev || !stats) +return -EINVAL ; + +memset (&stats_info,0 ,sizeof (stats_info)); +memset (&vport_stats,0 ,sizeof (vport_stats)); + + stats_info.func_id =hinic3_global_func_id (hwdev); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_GET_VPORT_STAT , + &stats_info,sizeof (stats_info), + &vport_stats, &out_size); +if (err || !out_size || vport_stats.msg_head.status) { +PMD_DRV_LOG (ERR , +"Get function stats failed, err: %d, status: 0x%x, " +"out size: 0x%x" , + err, vport_stats.msg_head.status, out_size); +return -EIO ; + } + +memcpy (stats, &vport_stats.stats,sizeof (*stats)); + +return 0 ; +} + +int +hinic3_get_phy_port_stats (void *hwdev,struct mag_phy_port_stats *stats) +{ +struct mag_cmd_get_port_stat *port_stats =NULL ; +struct mag_cmd_port_stats_info stats_info; +u16 out_size =sizeof (*port_stats); +int err; + + port_stats =rte_zmalloc ("port_stats" ,sizeof (*port_stats),0 ); +if (!port_stats) +return -ENOMEM ; + +memset (&stats_info,0 ,sizeof (stats_info)); + stats_info.port_id =hinic3_physical_port_id (hwdev); + + err =mag_msg_to_mgmt_sync (hwdev,MAG_CMD_GET_PORT_STAT , &stats_info, +sizeof (stats_info), port_stats, &out_size); +if (err || !out_size || port_stats->head.status) { +PMD_DRV_LOG (ERR , +"Failed to get port statistics, err: %d, status: " +"0x%x, out size: 0x%x" , + err, port_stats->head.status, out_size); + err = -EIO ; + goto out; + } + +memcpy (stats, &port_stats->counter,sizeof (*stats)); + +out: +rte_free (port_stats); + +return err; +} + +int +hinic3_clear_vport_stats (void *hwdev) +{ +struct hinic3_cmd_clear_vport_stats clear_vport_stats; +u16 out_size =sizeof (clear_vport_stats); +int err; + +if (!hwdev) { +PMD_DRV_LOG (ERR ,"Hwdev is NULL" ); +return -EINVAL ; + } + +memset (&clear_vport_stats,0 ,sizeof (clear_vport_stats)); + clear_vport_stats.func_id =hinic3_global_func_id (hwdev); + + err =l2nic_msg_to_mgmt_sync (hwdev, +HINIC3_NIC_CMD_CLEAN_VPORT_STAT , &clear_vport_stats, +sizeof (clear_vport_stats), &clear_vport_stats, &out_size); +if (err || !out_size || clear_vport_stats.msg_head.status) { +PMD_DRV_LOG (ERR , +"Clear vport stats failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, clear_vport_stats.msg_head.status, out_size); +return -EIO ; + } + +return 0 ; +} + +int +hinic3_clear_phy_port_stats (void *hwdev) +{ +struct mag_cmd_port_stats_info port_stats; +u16 out_size =sizeof (port_stats); +int err; + + port_stats.port_id =hinic3_physical_port_id (hwdev); + + err =mag_msg_to_mgmt_sync (hwdev,MAG_CMD_CLR_PORT_STAT , &port_stats, +sizeof (port_stats), &port_stats, &out_size); +if (err || !out_size || port_stats.head.status) { +PMD_DRV_LOG (ERR , +"Failed to get port statistics, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, port_stats.head.status, out_size); + err = -EIO ; + } + +return err; +} + +static int +hinic3_set_function_table (void *hwdev,u32 cfg_bitmap, +struct hinic3_func_tbl_cfg *cfg) +{ +struct hinic3_cmd_set_func_tbl cmd_func_tbl; +u16 out_size =sizeof (cmd_func_tbl); +int err; + +memset (&cmd_func_tbl,0 ,sizeof (cmd_func_tbl)); + cmd_func_tbl.func_id =hinic3_global_func_id (hwdev); + cmd_func_tbl.cfg_bitmap = cfg_bitmap; + cmd_func_tbl.tbl_cfg = *cfg; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SET_FUNC_TBL , + &cmd_func_tbl,sizeof (cmd_func_tbl), + &cmd_func_tbl, &out_size); +if (err || cmd_func_tbl.msg_head.status || !out_size) { +PMD_DRV_LOG (ERR , +"Set func table failed, bitmap: 0x%x, err: %d, " +"status: 0x%x, out size: 0x%x" , + cfg_bitmap, err, cmd_func_tbl.msg_head.status, + out_size); +return -EFAULT ; + } + +return 0 ; +} + +int +hinic3_init_function_table (void *hwdev,u16 rx_buff_len) +{ +struct hinic3_func_tbl_cfg func_tbl_cfg; +u32 cfg_bitmap =BIT (FUNC_CFG_INIT ) |BIT (FUNC_CFG_MTU ) | +BIT (FUNC_CFG_RX_BUF_SIZE ); + +memset (&func_tbl_cfg,0 ,sizeof (func_tbl_cfg)); + func_tbl_cfg.mtu =0x3FFF ;/**< Default, max mtu */ + func_tbl_cfg.rx_wqe_buf_size = rx_buff_len; + +return hinic3_set_function_table (hwdev, cfg_bitmap, &func_tbl_cfg); +} + +int +hinic3_set_port_mtu (void *hwdev,u16 new_mtu) +{ +struct hinic3_func_tbl_cfg func_tbl_cfg; + +if (!hwdev) +return -EINVAL ; + +if (new_mtu <HINIC3_MIN_MTU_SIZE ) { +PMD_DRV_LOG (ERR , +"Invalid mtu size: %ubytes, mtu size < %ubytes" , + new_mtu,HINIC3_MIN_MTU_SIZE ); +return -EINVAL ; + } + +if (new_mtu >HINIC3_MAX_JUMBO_FRAME_SIZE ) { +PMD_DRV_LOG (ERR , +"Invalid mtu size: %ubytes, mtu size > %ubytes" , + new_mtu,HINIC3_MAX_JUMBO_FRAME_SIZE ); +return -EINVAL ; + } + +memset (&func_tbl_cfg,0 ,sizeof (func_tbl_cfg)); + func_tbl_cfg.mtu = new_mtu; +return hinic3_set_function_table (hwdev,BIT (FUNC_CFG_MTU ), + &func_tbl_cfg); +} + +static int +nic_feature_nego (void *hwdev,u8 opcode,u64 *s_feature,u16 size) +{ +struct hinic3_cmd_feature_nego feature_nego; +u16 out_size =sizeof (feature_nego); +int err; + +if (!hwdev || !s_feature || size >MAX_FEATURE_QWORD ) +return -EINVAL ; + +memset (&feature_nego,0 ,sizeof (feature_nego)); + feature_nego.func_id =hinic3_global_func_id (hwdev); + feature_nego.opcode = opcode; +if (opcode ==HINIC3_CMD_OP_SET ) +memcpy (feature_nego.s_feature, s_feature, size *sizeof (u64)); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_FEATURE_NEGO , + &feature_nego,sizeof (feature_nego), + &feature_nego, &out_size); +if (err || !out_size || feature_nego.msg_head.status) { +PMD_DRV_LOG (ERR , +"Failed to negotiate nic feature, err:%d, status: " +"0x%x, out_size: 0x%x" , + err, feature_nego.msg_head.status, out_size); +return -EFAULT ; + } + +if (opcode ==HINIC3_CMD_OP_GET ) +memcpy (s_feature, feature_nego.s_feature, size *sizeof (u64)); + +return 0 ; +} + +int +hinic3_get_feature_from_hw (void *hwdev,u64 *s_feature,u16 size) +{ +return nic_feature_nego (hwdev,HINIC3_CMD_OP_GET , s_feature, size); +} + +int +hinic3_set_feature_to_hw (void *hwdev,u64 *s_feature,u16 size) +{ +return nic_feature_nego (hwdev,HINIC3_CMD_OP_SET , s_feature, size); +} + +static int +hinic3_vf_func_init (void *hwdev) +{ +struct hinic3_cmd_register_vf register_info; +u16 out_size =sizeof (register_info); +int err; + +if (hinic3_func_type (hwdev) !=TYPE_VF ) +return 0 ; + +memset (®ister_info,0 ,sizeof (register_info)); + register_info.op_register =1 ; + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_VF_REGISTER , + ®ister_info,sizeof (register_info), + ®ister_info, &out_size); +if (err || register_info.msg_head.status || !out_size) { +PMD_DRV_LOG (ERR , +"Register VF failed, err: %d, status: 0x%x, out " +"size: 0x%x" , + err, register_info.msg_head.status, out_size); +return -EFAULT ; + } + +return 0 ; +} + +static int +hinic3_vf_func_free (void *hwdev) +{ +struct hinic3_cmd_register_vf unregister; +u16 out_size =sizeof (unregister); +int err; + +if (hinic3_func_type (hwdev) !=TYPE_VF ) +return 0 ; + +memset (&unregister,0 ,sizeof (unregister)); + unregister.op_register =0 ; + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_VF_REGISTER , + &unregister,sizeof (unregister), + &unregister, &out_size); +if (err || unregister.msg_head.status || !out_size) { +PMD_DRV_LOG (ERR , +"Unregister VF failed, err: %d, status: 0x%x, out " +"size: 0x%x" , + err, unregister.msg_head.status, out_size); +return -EFAULT ; + } + +return 0 ; +} + +int +hinic3_init_nic_hwdev (void *hwdev) +{ +return hinic3_vf_func_init (hwdev); +} + +void +hinic3_free_nic_hwdev (void *hwdev) +{ +if (!hwdev) +return ; + +if (hinic3_func_type (hwdev) !=TYPE_VF ) + (void )hinic3_set_link_status_follow (hwdev, +HINIC3_LINK_FOLLOW_DEFAULT ); + +hinic3_vf_func_free (hwdev); +} + +int +hinic3_set_rx_mode (void *hwdev,u32 enable) +{ +struct hinic3_rx_mode_config rx_mode_cfg; +u16 out_size =sizeof (rx_mode_cfg); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&rx_mode_cfg,0 ,sizeof (rx_mode_cfg)); + rx_mode_cfg.func_id =hinic3_global_func_id (hwdev); + rx_mode_cfg.rx_mode = enable; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SET_RX_MODE , + &rx_mode_cfg,sizeof (rx_mode_cfg), + &rx_mode_cfg, &out_size); +if (err || !out_size || rx_mode_cfg.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set rx mode failed, err: %d, status: 0x%x, out " +"size: 0x%x" , + err, rx_mode_cfg.msg_head.status, out_size); +return -EIO ; + } +return 0 ; +} + +int +hinic3_set_rx_vlan_offload (void *hwdev,u8 en) +{ +struct hinic3_cmd_vlan_offload vlan_cfg; +u16 out_size =sizeof (vlan_cfg); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&vlan_cfg,0 ,sizeof (vlan_cfg)); + vlan_cfg.func_id =hinic3_global_func_id (hwdev); + vlan_cfg.vlan_offload = en; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SET_RX_VLAN_OFFLOAD , + &vlan_cfg,sizeof (vlan_cfg), &vlan_cfg, + &out_size); +if (err || !out_size || vlan_cfg.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set rx vlan offload failed, err: %d, status: " +"0x%x, out size: 0x%x" , + err, vlan_cfg.msg_head.status, out_size); +return -EIO ; + } +return 0 ; +} + +int +hinic3_set_vlan_fliter (void *hwdev,u32 vlan_filter_ctrl) +{ +struct hinic3_cmd_set_vlan_filter vlan_filter; +u16 out_size =sizeof (vlan_filter); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&vlan_filter,0 ,sizeof (vlan_filter)); + vlan_filter.func_id =hinic3_global_func_id (hwdev); + vlan_filter.vlan_filter_ctrl = vlan_filter_ctrl; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SET_VLAN_FILTER_EN , + &vlan_filter,sizeof (vlan_filter), + &vlan_filter, &out_size); +if (err || !out_size || vlan_filter.msg_head.status) { +PMD_DRV_LOG (ERR , +"Failed to set vlan filter, err: %d, status: 0x%x, " +"out size: 0x%x" , + err, vlan_filter.msg_head.status, out_size); +return -EIO ; + } +return 0 ; +} + +static int +hinic3_set_rx_lro (void *hwdev,u8 ipv4_en,u8 ipv6_en,u8 lro_max_pkt_len) +{ +struct hinic3_cmd_lro_config lro_cfg = {0 }; +u16 out_size =sizeof (lro_cfg); +int err; + +if (!hwdev) +return -EINVAL ; + + lro_cfg.func_id =hinic3_global_func_id (hwdev); + lro_cfg.opcode =HINIC3_CMD_OP_SET ; + lro_cfg.lro_ipv4_en = ipv4_en; + lro_cfg.lro_ipv6_en = ipv6_en; + lro_cfg.lro_max_pkt_len = lro_max_pkt_len; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CFG_RX_LRO , &lro_cfg, +sizeof (lro_cfg), &lro_cfg, &out_size); +if (err || !out_size || lro_cfg.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set lro offload failed, err: %d, status: 0x%x, " +"out size: 0x%x" , + err, lro_cfg.msg_head.status, out_size); +return -EIO ; + } + +return 0 ; +} + +static int +hinic3_set_rx_lro_timer (void *hwdev,u32 timer_value) +{ +struct hinic3_cmd_lro_timer lro_timer; +u16 out_size =sizeof (lro_timer); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&lro_timer,0 ,sizeof (lro_timer)); + lro_timer.opcode =HINIC3_CMD_OP_SET ; + lro_timer.timer = timer_value; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CFG_LRO_TIMER , + &lro_timer,sizeof (lro_timer), &lro_timer, + &out_size); +if (err || !out_size || lro_timer.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set lro timer failed, err: %d, status: 0x%x, out " +"size: 0x%x" , + err, lro_timer.msg_head.status, out_size); + +return -EIO ; + } + +return 0 ; +} + +int +hinic3_set_rx_lro_state (void *hwdev,u8 lro_en,u32 lro_timer, +u32 lro_max_pkt_len) +{ +u8 ipv4_en =0 , ipv6_en =0 ; +int err; + +if (!hwdev) +return -EINVAL ; + + ipv4_en = lro_en ?1 :0 ; + ipv6_en = lro_en ?1 :0 ; + +PMD_DRV_LOG (INFO ,"Set LRO max coalesce packet size to %uK" , + lro_max_pkt_len); + + err =hinic3_set_rx_lro (hwdev, ipv4_en, ipv6_en, (u8 )lro_max_pkt_len); +if (err) +return err; + +/* We don't set LRO timer for VF */ +if (hinic3_func_type (hwdev) ==TYPE_VF ) +return 0 ; + +PMD_DRV_LOG (INFO ,"Set LRO timer to %u" , lro_timer); + +return hinic3_set_rx_lro_timer (hwdev, lro_timer); +} + +/* RSS config */ +int +hinic3_rss_template_alloc (void *hwdev) +{ +struct hinic3_rss_template_mgmt template_mgmt; +u16 out_size =sizeof (template_mgmt); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&template_mgmt,0 ,sizeof (struct hinic3_rss_template_mgmt )); + template_mgmt.func_id =hinic3_global_func_id (hwdev); + template_mgmt.cmd =NIC_RSS_CMD_TEMP_ALLOC ; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_RSS_TEMP_MGR , + &template_mgmt,sizeof (template_mgmt), + &template_mgmt, &out_size); +if (err || !out_size || template_mgmt.msg_head.status) { +if (template_mgmt.msg_head.status == +HINIC3_MGMT_STATUS_TABLE_FULL ) { +PMD_DRV_LOG (ERR ,"There is no more template available" ); +return -ENOSPC ; + } +PMD_DRV_LOG (ERR , +"Alloc rss template failed, err: %d, " +"status: 0x%x, out size: 0x%x" , + err, template_mgmt.msg_head.status, out_size); +return -EFAULT ; + } + +return 0 ; +} + +int +hinic3_rss_template_free (void *hwdev) +{ +struct hinic3_rss_template_mgmt template_mgmt; +u16 out_size =sizeof (template_mgmt); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&template_mgmt,0 ,sizeof (struct hinic3_rss_template_mgmt )); + template_mgmt.func_id =hinic3_global_func_id (hwdev); + template_mgmt.cmd =NIC_RSS_CMD_TEMP_FREE ; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_RSS_TEMP_MGR , + &template_mgmt,sizeof (template_mgmt), + &template_mgmt, &out_size); +if (err || !out_size || template_mgmt.msg_head.status) { +PMD_DRV_LOG (ERR , +"Free rss template failed, err: %d, " +"status: 0x%x, out size: 0x%x" , + err, template_mgmt.msg_head.status, out_size); +return -EFAULT ; + } + +return 0 ; +} + +static int +hinic3_rss_cfg_hash_key (void *hwdev,u8 opcode,u8 *key,u16 key_size) +{ +struct hinic3_cmd_rss_hash_key hash_key; +u16 out_size =sizeof (hash_key); +int err; + +if (!hwdev || !key) +return -EINVAL ; + +memset (&hash_key,0 ,sizeof (struct hinic3_cmd_rss_hash_key )); + hash_key.func_id =hinic3_global_func_id (hwdev); + hash_key.opcode = opcode; +if (opcode ==HINIC3_CMD_OP_SET ) +memcpy (hash_key.key, key, key_size); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CFG_RSS_HASH_KEY , + &hash_key,sizeof (hash_key), &hash_key, + &out_size); +if (err || !out_size || hash_key.msg_head.status) { +PMD_DRV_LOG (ERR , +"%s hash key failed, err: %d, " +"status: 0x%x, out size: 0x%x" , + opcode ==HINIC3_CMD_OP_SET ?"Set" :"Get" , err, + hash_key.msg_head.status, out_size); +return -EFAULT ; + } + +if (opcode ==HINIC3_CMD_OP_GET ) +memcpy (key, hash_key.key, key_size); + +return 0 ; +} + +int +hinic3_rss_set_hash_key (void *hwdev,u8 *key,u16 key_size) +{ +if (!hwdev || !key) +return -EINVAL ; + +return hinic3_rss_cfg_hash_key (hwdev,HINIC3_CMD_OP_SET , key, key_size); +} + +int +hinic3_rss_get_indir_tbl (void *hwdev,u32 *indir_table,u32 indir_table_size) +{ +struct hinic3_cmd_buf *cmd_buf =NULL ; +u16 *indir_tbl =NULL ; +int err; +u32 i; + +if (!hwdev || !indir_table) +return -EINVAL ; + + cmd_buf =hinic3_alloc_cmd_buf (hwdev); +if (!cmd_buf) { +PMD_DRV_LOG (ERR ,"Allocate cmd buf failed" ); +return -ENOMEM ; + } + + cmd_buf->size =sizeof (struct nic_rss_indirect_tbl ); + err =hinic3_cmdq_detail_resp (hwdev,HINIC3_MOD_L2NIC , +HINIC3_UCODE_CMD_GET_RSS_INDIR_TABLE , + cmd_buf, cmd_buf,0 ); +if (err) { +PMD_DRV_LOG (ERR ,"Get rss indir table failed" ); +hinic3_free_cmd_buf (cmd_buf); +return err; + } + + indir_tbl = (u16 *)cmd_buf->buf; +for (i =0 ; i < indir_table_size; i++) + indir_table[i] = *(indir_tbl + i); + +hinic3_free_cmd_buf (cmd_buf); +return 0 ; +} + +int +hinic3_rss_set_indir_tbl (void *hwdev,const u32 *indir_table, +u32 indir_table_size) +{ +struct nic_rss_indirect_tbl *indir_tbl =NULL ; +struct hinic3_cmd_buf *cmd_buf =NULL ; +u32 i, size; +u32 *temp =NULL ; +u64 out_param =0 ; +int err; + +if (!hwdev || !indir_table) +return -EINVAL ; + + cmd_buf =hinic3_alloc_cmd_buf (hwdev); +if (!cmd_buf) { +PMD_DRV_LOG (ERR ,"Allocate cmd buf failed" ); +return -ENOMEM ; + } + + cmd_buf->size =sizeof (struct nic_rss_indirect_tbl ); + indir_tbl = (struct nic_rss_indirect_tbl *)cmd_buf->buf; +memset (indir_tbl,0 ,sizeof (*indir_tbl)); + +for (i =0 ; i < indir_table_size; i++) + indir_tbl->entry[i] = (u16)(*(indir_table + i)); + +rte_mb (); + size =sizeof (indir_tbl->entry) /sizeof (u32); + temp = (u32 *)indir_tbl->entry; +for (i =0 ; i < size; i++) + temp[i] =cpu_to_be32 (temp[i]); + + err =hinic3_cmdq_direct_resp (hwdev,HINIC3_MOD_L2NIC , +HINIC3_UCODE_CMD_SET_RSS_INDIR_TABLE , + cmd_buf, &out_param,0 ); +if (err || out_param !=0 ) { +PMD_DRV_LOG (ERR ,"Set rss indir table failed" ); + err = -EFAULT ; + } + +hinic3_free_cmd_buf (cmd_buf); +return err; +} + +static int +hinic3_cmdq_set_rss_type (void *hwdev,struct hinic3_rss_type rss_type) +{ +struct nic_rss_context_tbl *ctx_tbl =NULL ; +struct hinic3_cmd_buf *cmd_buf =NULL ; +u32 ctx =0 ; +u64 out_param =0 ; +int err; + +if (!hwdev) +return -EINVAL ; + + cmd_buf =hinic3_alloc_cmd_buf (hwdev); +if (!cmd_buf) { +PMD_DRV_LOG (ERR ,"Allocate cmd buf failed" ); +return -ENOMEM ; + } + + ctx |=HINIC3_RSS_TYPE_SET (1 ,VALID ) | +HINIC3_RSS_TYPE_SET (rss_type.ipv4,IPV4 ) | +HINIC3_RSS_TYPE_SET (rss_type.ipv6,IPV6 ) | +HINIC3_RSS_TYPE_SET (rss_type.ipv6_ext,IPV6_EXT ) | +HINIC3_RSS_TYPE_SET (rss_type.tcp_ipv4,TCP_IPV4 ) | +HINIC3_RSS_TYPE_SET (rss_type.tcp_ipv6,TCP_IPV6 ) | +HINIC3_RSS_TYPE_SET (rss_type.tcp_ipv6_ext,TCP_IPV6_EXT ) | +HINIC3_RSS_TYPE_SET (rss_type.udp_ipv4,UDP_IPV4 ) | +HINIC3_RSS_TYPE_SET (rss_type.udp_ipv6,UDP_IPV6 ); + + cmd_buf->size =sizeof (struct nic_rss_context_tbl ); + ctx_tbl = (struct nic_rss_context_tbl *)cmd_buf->buf; +memset (ctx_tbl,0 ,sizeof (*ctx_tbl)); +rte_mb (); + ctx_tbl->ctx =cpu_to_be32 (ctx); + +/* Cfg the RSS context table by command queue. */ + err =hinic3_cmdq_direct_resp (hwdev,HINIC3_MOD_L2NIC , +HINIC3_UCODE_CMD_SET_RSS_CONTEXT_TABLE , + cmd_buf, &out_param,0 ); + +hinic3_free_cmd_buf (cmd_buf); + +if (err || out_param !=0 ) { +PMD_DRV_LOG (ERR ,"Cmdq set rss context table failed, err: %d" , + err); +return -EFAULT ; + } + +return 0 ; +} + +static int +hinic3_mgmt_set_rss_type (void *hwdev,struct hinic3_rss_type rss_type) +{ +struct hinic3_rss_context_table ctx_tbl; +u32 ctx =0 ; +u16 out_size =sizeof (ctx_tbl); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&ctx_tbl,0 ,sizeof (ctx_tbl)); + ctx_tbl.func_id =hinic3_global_func_id (hwdev); + ctx |=HINIC3_RSS_TYPE_SET (1 ,VALID ) | +HINIC3_RSS_TYPE_SET (rss_type.ipv4,IPV4 ) | +HINIC3_RSS_TYPE_SET (rss_type.ipv6,IPV6 ) | +HINIC3_RSS_TYPE_SET (rss_type.ipv6_ext,IPV6_EXT ) | +HINIC3_RSS_TYPE_SET (rss_type.tcp_ipv4,TCP_IPV4 ) | +HINIC3_RSS_TYPE_SET (rss_type.tcp_ipv6,TCP_IPV6 ) | +HINIC3_RSS_TYPE_SET (rss_type.tcp_ipv6_ext,TCP_IPV6_EXT ) | +HINIC3_RSS_TYPE_SET (rss_type.udp_ipv4,UDP_IPV4 ) | +HINIC3_RSS_TYPE_SET (rss_type.udp_ipv6,UDP_IPV6 ); + ctx_tbl.context = ctx; + + err =l2nic_msg_to_mgmt_sync (hwdev, +HINIC3_NIC_CMD_SET_RSS_CTX_TBL_INTO_FUNC , &ctx_tbl, +sizeof (ctx_tbl), &ctx_tbl, &out_size); +if (ctx_tbl.msg_head.status ==HINIC3_MGMT_CMD_UNSUPPORTED ) { +return HINIC3_MGMT_CMD_UNSUPPORTED ; + }else if (err || !out_size || ctx_tbl.msg_head.status) { +PMD_DRV_LOG (ERR , +"Mgmt set rss context table failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, ctx_tbl.msg_head.status, out_size); +return -EINVAL ; + } +return 0 ; +} + +int +hinic3_set_rss_type (void *hwdev,struct hinic3_rss_type rss_type) +{ +int err; + err =hinic3_mgmt_set_rss_type (hwdev, rss_type); +if (err ==HINIC3_MGMT_CMD_UNSUPPORTED ) + err =hinic3_cmdq_set_rss_type (hwdev, rss_type); +return err; +} + +int +hinic3_get_rss_type (void *hwdev,struct hinic3_rss_type *rss_type) +{ +struct hinic3_rss_context_table ctx_tbl; +u16 out_size =sizeof (ctx_tbl); +int err; + +if (!hwdev || !rss_type) +return -EINVAL ; + +memset (&ctx_tbl,0 ,sizeof (struct hinic3_rss_context_table )); + ctx_tbl.func_id =hinic3_global_func_id (hwdev); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_GET_RSS_CTX_TBL , + &ctx_tbl,sizeof (ctx_tbl), &ctx_tbl, + &out_size); +if (err || !out_size || ctx_tbl.msg_head.status) { +PMD_DRV_LOG (ERR , +"Get hash type failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, ctx_tbl.msg_head.status, out_size); +return -EFAULT ; + } + + rss_type->ipv4 =HINIC3_RSS_TYPE_GET (ctx_tbl.context,IPV4 ); + rss_type->ipv6 =HINIC3_RSS_TYPE_GET (ctx_tbl.context,IPV6 ); + rss_type->ipv6_ext =HINIC3_RSS_TYPE_GET (ctx_tbl.context,IPV6_EXT ); + rss_type->tcp_ipv4 =HINIC3_RSS_TYPE_GET (ctx_tbl.context,TCP_IPV4 ); + rss_type->tcp_ipv6 =HINIC3_RSS_TYPE_GET (ctx_tbl.context,TCP_IPV6 ); + rss_type->tcp_ipv6_ext = +HINIC3_RSS_TYPE_GET (ctx_tbl.context,TCP_IPV6_EXT ); + rss_type->udp_ipv4 =HINIC3_RSS_TYPE_GET (ctx_tbl.context,UDP_IPV4 ); + rss_type->udp_ipv6 =HINIC3_RSS_TYPE_GET (ctx_tbl.context,UDP_IPV6 ); + +return 0 ; +} + +static int +hinic3_rss_cfg_hash_engine (void *hwdev,u8 opcode,u8 *type) +{ +struct hinic3_cmd_rss_engine_type hash_type; +u16 out_size =sizeof (hash_type); +int err; + +if (!hwdev || !type) +return -EINVAL ; + +memset (&hash_type,0 ,sizeof (struct hinic3_cmd_rss_engine_type )); + hash_type.func_id =hinic3_global_func_id (hwdev); + hash_type.opcode = opcode; +if (opcode ==HINIC3_CMD_OP_SET ) + hash_type.hash_engine = *type; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CFG_RSS_HASH_ENGINE , + &hash_type,sizeof (hash_type), &hash_type, + &out_size); +if (err || !out_size || hash_type.msg_head.status) { +PMD_DRV_LOG (ERR , +"%s hash engine failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + opcode ==HINIC3_CMD_OP_SET ?"Set" :"Get" , err, + hash_type.msg_head.status, out_size); +return -EFAULT ; + } + +if (opcode ==HINIC3_CMD_OP_GET ) + *type = hash_type.hash_engine; + +return 0 ; +} + +int +hinic3_rss_get_hash_engine (void *hwdev,u8 *type) +{ +if (!hwdev || !type) +return -EINVAL ; + +return hinic3_rss_cfg_hash_engine (hwdev,HINIC3_CMD_OP_GET , type); +} + +int +hinic3_rss_set_hash_engine (void *hwdev,u8 type) +{ +if (!hwdev) +return -EINVAL ; + +return hinic3_rss_cfg_hash_engine (hwdev,HINIC3_CMD_OP_SET , &type); +} + +int +hinic3_rss_cfg (void *hwdev,u8 rss_en,u8 tc_num,u8 *prio_tc) +{ +struct hinic3_cmd_rss_config rss_cfg; +u16 out_size =sizeof (rss_cfg); +int err; + +/* Ucode requires number of TC should be power of 2. */ +if (!hwdev || !prio_tc || (tc_num & (tc_num -1 ))) +return -EINVAL ; + +memset (&rss_cfg,0 ,sizeof (struct hinic3_cmd_rss_config )); + rss_cfg.func_id =hinic3_global_func_id (hwdev); + rss_cfg.rss_en = rss_en; + rss_cfg.rq_priority_number = tc_num ? (u8 )ilog2 (tc_num) :0 ; + +memcpy (rss_cfg.prio_tc, prio_tc,HINIC3_DCB_UP_MAX ); + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_RSS_CFG , &rss_cfg, +sizeof (rss_cfg), &rss_cfg, &out_size); +if (err || !out_size || rss_cfg.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set rss cfg failed, err: %d, " +"status: 0x%x, out size: 0x%x" , + err, rss_cfg.msg_head.status, out_size); +return -EFAULT ; + } + +return 0 ; +} + +int +hinic3_vf_get_default_cos (void *hwdev,u8 *cos_id) +{ +struct hinic3_cmd_vf_dcb_state vf_dcb; +u16 out_size =sizeof (vf_dcb); +int err; + +memset (&vf_dcb,0 ,sizeof (vf_dcb)); + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_VF_COS , &vf_dcb, +sizeof (vf_dcb), &vf_dcb, &out_size); +if (err || !out_size || vf_dcb.msg_head.status) { +PMD_DRV_LOG (ERR , +"Get VF default cos failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, vf_dcb.msg_head.status, out_size); +return -EIO ; + } + + *cos_id = vf_dcb.state.default_cos; + +return 0 ; +} + +/** +* Set the Ethernet type filtering rule for the FDIR of a NIC. +* +* @param[in] hwdev +* Pointer to hardware device structure. +* @param[in] pkt_type +* Indicate the packet type. +* @param[in] queue_id +* Indicate the queue id. +* @param[in] en +* Indicate whether to add or delete an operation. 1 - add; 0 - delete. +* +* @return +* 0 on success, non-zero on failure. +*/ +int +hinic3_set_fdir_ethertype_filter (void *hwdev,u8 pkt_type,u16 queue_id,u8 en) +{ +struct hinic3_set_fdir_ethertype_rule ethertype_cmd; +u16 out_size =sizeof (ethertype_cmd); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (ðertype_cmd,0 , +sizeof (struct hinic3_set_fdir_ethertype_rule )); + ethertype_cmd.func_id =hinic3_global_func_id (hwdev); + ethertype_cmd.pkt_type = pkt_type; + ethertype_cmd.pkt_type_en = en; + ethertype_cmd.qid = (u8 )queue_id; + + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_SET_FDIR_STATUS , + ðertype_cmd,sizeof (ethertype_cmd), + ðertype_cmd, &out_size); +if (err || ethertype_cmd.head.status || !out_size) { +PMD_DRV_LOG (ERR , +"set fdir ethertype rule failed, " +"err: %d, status: 0x%x, out size: 0x%x, func_id %d" , + err, ethertype_cmd.head.status, out_size, + ethertype_cmd.func_id); +return -EIO ; + } + +return 0 ; +} + +int +hinic3_add_tcam_rule (void *hwdev,struct hinic3_tcam_cfg_rule *tcam_rule, +u8 tcam_rule_type) +{ +struct hinic3_fdir_add_rule tcam_cmd; +u16 out_size =sizeof (tcam_cmd); +int err; + +if (!hwdev || !tcam_rule) +return -EINVAL ; +/* Check whether the index is out of range. */ +if (tcam_rule->index >=HINIC3_MAX_TCAM_RULES_NUM ) { +PMD_DRV_LOG (ERR ,"Tcam rules num to add is invalid" ); +return -EINVAL ; + } + +memset (&tcam_cmd,0 ,sizeof (struct hinic3_fdir_add_rule )); + tcam_cmd.func_id =hinic3_global_func_id (hwdev); +memcpy ((void *)&tcam_cmd.rule, (void *)tcam_rule, +sizeof (struct hinic3_tcam_cfg_rule )); + tcam_cmd.type = tcam_rule_type; + +/* Synchronize the information to the management module. */ + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_ADD_TC_FLOW , + &tcam_cmd,sizeof (tcam_cmd), &tcam_cmd, + &out_size); +if (err || tcam_cmd.msg_head.status || !out_size) { +PMD_DRV_LOG (ERR , +"Add tcam rule failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, tcam_cmd.msg_head.status, out_size); +return -EIO ; + } + +return 0 ; +} + +int +hinic3_del_tcam_rule (void *hwdev,u32 index,u8 tcam_rule_type) +{ +struct hinic3_fdir_del_rule tcam_cmd; +u16 out_size =sizeof (tcam_cmd); +int err; + +if (!hwdev) +return -EINVAL ; +/* Check whether the index is out of range. */ +if (index >=HINIC3_MAX_TCAM_RULES_NUM ) { +PMD_DRV_LOG (ERR ,"Tcam rules num to del is invalid" ); +return -EINVAL ; + } + +memset (&tcam_cmd,0 ,sizeof (struct hinic3_fdir_del_rule )); + tcam_cmd.func_id =hinic3_global_func_id (hwdev); + tcam_cmd.index_start = index; + tcam_cmd.index_num =1 ; + tcam_cmd.type = tcam_rule_type; + +/* Synchronize the information to the management module. */ + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_DEL_TC_FLOW , + &tcam_cmd,sizeof (tcam_cmd), &tcam_cmd, + &out_size); +if (err || tcam_cmd.msg_head.status || !out_size) { +PMD_DRV_LOG (ERR , +"Del tcam rule failed, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, tcam_cmd.msg_head.status, out_size); +return -EIO ; + } + +return 0 ; +} + +static int +hinic3_cfg_tcam_block (void *hwdev,u8 alloc_en,u16 *index) +{ +struct hinic3_tcam_block tcam_block_info; +u16 out_size =sizeof (tcam_block_info); +int err; + +if (!hwdev) +return -EINVAL ; +/* Initialization TCAM block structure. */ +memset (&tcam_block_info,0 ,sizeof (struct hinic3_tcam_block )); + tcam_block_info.func_id =hinic3_global_func_id (hwdev); + tcam_block_info.alloc_en = alloc_en; + tcam_block_info.tcam_type =HINIC3_TCAM_BLOCK_NORMAL_TYPE ; + tcam_block_info.tcam_block_index = *index; + +/* Synchronize the information to the management module. */ + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_CFG_TCAM_BLOCK , + &tcam_block_info,sizeof (tcam_block_info), + &tcam_block_info, &out_size); +if (err || !out_size || tcam_block_info.msg_head.status) { +PMD_DRV_LOG (ERR , +"Set tcam block failed, err: %d, status: 0x%x, out " +"size: 0x%x" , + err, tcam_block_info.msg_head.status, out_size); +return -EIO ; + } + +/* Update TCAM block of index. */ +if (alloc_en) + *index = tcam_block_info.tcam_block_index; + +return 0 ; +} + +int +hinic3_alloc_tcam_block (void *hwdev,u16 *index) +{ +return hinic3_cfg_tcam_block (hwdev,HINIC3_TCAM_BLOCK_ENABLE , index); +} + +int +hinic3_free_tcam_block (void *hwdev,u16 *index) +{ +return hinic3_cfg_tcam_block (hwdev,HINIC3_TCAM_BLOCK_DISABLE , index); +} + +int +hinic3_flush_tcam_rule (void *hwdev) +{ +struct hinic3_flush_tcam_rules tcam_flush; +u16 out_size =sizeof (tcam_flush); +int err; + +if (!hwdev) +return -EINVAL ; + +memset (&tcam_flush,0 ,sizeof (struct hinic3_flush_tcam_rules )); + tcam_flush.func_id =hinic3_global_func_id (hwdev); + + err =l2nic_msg_to_mgmt_sync (hwdev, +HINIC3_NIC_CMD_FLUSH_TCAM , &tcam_flush, +sizeof (struct hinic3_flush_tcam_rules ), &tcam_flush, &out_size); +if (tcam_flush.msg_head.status ==HINIC3_MGMT_CMD_UNSUPPORTED ) { + err =HINIC3_MGMT_CMD_UNSUPPORTED ; +PMD_DRV_LOG (INFO , +"Firmware/uP doesn't support flush tcam fdir" ); + }else if (err || (!out_size) || tcam_flush.msg_head.status) { +PMD_DRV_LOG (ERR , +"Flush tcam fdir rules failed, err: %d, status: " +"0x%x, out size: 0x%x" , + err, tcam_flush.msg_head.status, out_size); + err = -EIO ; + } + +return err; +} + +int +hinic3_set_fdir_tcam_rule_filter (void *hwdev,bool enable) +{ +struct hinic3_port_tcam_info port_tcam_cmd; +u16 out_size =sizeof (port_tcam_cmd); +int err; + +if (!hwdev) +return -EINVAL ; +/* Initialization information. */ +memset (&port_tcam_cmd,0 ,sizeof (port_tcam_cmd)); + port_tcam_cmd.func_id =hinic3_global_func_id (hwdev); + port_tcam_cmd.tcam_enable = (u8 )enable; + +/* Synchronize the information to the management module. */ + err =l2nic_msg_to_mgmt_sync (hwdev,HINIC3_NIC_CMD_ENABLE_TCAM , + &port_tcam_cmd,sizeof (port_tcam_cmd), + &port_tcam_cmd, &out_size); +if ((port_tcam_cmd.msg_head.status !=HINIC3_MGMT_CMD_UNSUPPORTED && + port_tcam_cmd.msg_head.status) || + err || !out_size) { +PMD_DRV_LOG (ERR , +"Set fdir tcam filter failed, err: %d, " +"status: 0x%x, out size: 0x%x, enable: 0x%x" , + err, port_tcam_cmd.msg_head.status, out_size, + enable); +return -EIO ; + } + +if (port_tcam_cmd.msg_head.status ==HINIC3_MGMT_CMD_UNSUPPORTED ) { + err =HINIC3_MGMT_CMD_UNSUPPORTED ; +PMD_DRV_LOG (WARNING , +"Fw doesn't support setting fdir tcam filter" ); + } + +return err; +} + +int +hinic3_set_rq_flush (void *hwdev,u16 q_id) +{ +struct hinic3_cmd_set_rq_flush *rq_flush_msg =NULL ; +struct hinic3_cmd_buf *cmd_buf =NULL ; +u64 out_param =EIO ; +int err; + + cmd_buf =hinic3_alloc_cmd_buf (hwdev); +if (!cmd_buf) { +PMD_DRV_LOG (ERR ,"Failed to allocate cmd buf" ); +return -ENOMEM ; + } + + cmd_buf->size =sizeof (*rq_flush_msg); + + rq_flush_msg = cmd_buf->buf; + rq_flush_msg->local_rq_id = q_id; +rte_mb (); + rq_flush_msg->value =cpu_to_be32 (rq_flush_msg->value); + + err =hinic3_cmdq_direct_resp (hwdev,HINIC3_MOD_L2NIC , +HINIC3_UCODE_CMD_SET_RQ_FLUSH , cmd_buf, + &out_param,0 ); +if (err || out_param !=0 ) { +PMD_DRV_LOG (ERR , +"Failed to set rq flush, err:%d, out_param:0x%" PRIx64, + err, out_param); + err = -EFAULT ; + } + +hinic3_free_cmd_buf (cmd_buf); + +return err; +} + +static int +_mag_msg_to_mgmt_sync (void *hwdev,u16 cmd,void *buf_in,u16 in_size, +void *buf_out,u16 *out_size) +{ +u32 i, cmd_cnt =ARRAY_LEN (vf_mag_cmd_handler); + +if (hinic3_func_type (hwdev) ==TYPE_VF ) { +for (i =0 ; i < cmd_cnt; i++) { +if (cmd == vf_mag_cmd_handler[i].cmd) +return hinic3_mbox_to_pf (hwdev, +HINIC3_MOD_HILINK , cmd, buf_in, + in_size, buf_out, out_size,0 ); + } + } + +return hinic3_msg_to_mgmt_sync (hwdev,HINIC3_MOD_HILINK , cmd, buf_in, + in_size, buf_out, out_size,0 ); +} + +static int +mag_msg_to_mgmt_sync (void *hwdev,u16 cmd,void *buf_in,u16 in_size, +void *buf_out,u16 *out_size) +{ +return _mag_msg_to_mgmt_sync (hwdev, cmd, buf_in, in_size, buf_out, + out_size); +} + +int +hinic3_set_link_status_follow (void *hwdev, +enum hinic3_link_follow_status status) +{ +struct mag_cmd_set_link_follow follow; +u16 out_size =sizeof (follow); +int err; + +if (!hwdev) +return -EINVAL ; + +if (status >=HINIC3_LINK_FOLLOW_STATUS_MAX ) { +PMD_DRV_LOG (ERR ,"Invalid link follow status: %d" , status); +return -EINVAL ; + } + +memset (&follow,0 ,sizeof (follow)); + follow.function_id =hinic3_global_func_id (hwdev); + follow.follow = status; + + err =mag_msg_to_mgmt_sync (hwdev,MAG_CMD_SET_LINK_FOLLOW , &follow, +sizeof (follow), &follow, &out_size); +if ((follow.head.status !=HINIC3_MGMT_CMD_UNSUPPORTED && + follow.head.status) || + err || !out_size) { +PMD_DRV_LOG (ERR , +"Failed to set link status follow port status, " +"err: %d, status: 0x%x, out size: 0x%x" , + err, follow.head.status, out_size); +return -EFAULT ; + } + +return follow.head.status; +}
drivers/net/hinic3/base/hinic3_nic_cfg.h new file +1527 -0
1,172 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.47.0.windows.2
Part of the diff is not shown here. View the raw message.
RFC 10/18 net/hinic3: add context and work queue support
In reply to Feifei WangFrom: Xin Wang <[email protected]>
Work queue is used for cmdq and tx/rx buff description. Nic business needs to configure cmdq context and txq/rxq context. This patch adds data structures and function codes for work queue and context.
--- drivers/net/hinic3/base/hinic3_wq.c | 148 ++++++++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_wq.h | 109 ++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_wq.c create mode 100644 drivers/net/hinic3/base/hinic3_wq.h
drivers/net/hinic3/base/hinic3_wq.c new file +148 -0
@@ -0,0 +1,148 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ +#include <rte_bus_pci.h> +#include <rte_errno.h> +#include <rte_ether.h> +#include <rte_malloc.h> +#include <rte_mbuf.h> +#include <rte_mempool.h> +#include <rte_pci.h> + +#include "hinic3_compat.h" +#include "hinic3_hwdev.h" +#include "hinic3_wq.h" + +static void +free_wq_pages (struct hinic3_wq *wq) +{ +hinic3_memzone_free (wq->wq_mz); + + wq->queue_buf_paddr =0 ; + wq->queue_buf_vaddr =0 ; +} + +static int +alloc_wq_pages (struct hinic3_hwdev *hwdev,struct hinic3_wq *wq,int qid) +{ +const struct rte_memzone *wq_mz; + + wq_mz =hinic3_dma_zone_reserve (hwdev->eth_dev,"hinic3_wq_mz" , + (uint16_t )qid, wq->wq_buf_size, +RTE_PGSIZE_256K ,SOCKET_ID_ANY ); +if (!wq_mz) { +PMD_DRV_LOG (ERR ,"Allocate wq[%d] rq_mz failed" , qid); +return -ENOMEM ; + } + +memset (wq_mz->addr,0 , wq->wq_buf_size); + wq->wq_mz = wq_mz; + wq->queue_buf_paddr = wq_mz->iova; + wq->queue_buf_vaddr = (u64 )(u64 *)wq_mz->addr; + +return 0 ; +} + +void +hinic3_put_wqe (struct hinic3_wq *wq,int num_wqebbs) +{ + wq->cons_idx += num_wqebbs; +rte_atomic_fetch_add_explicit (&wq->delta, num_wqebbs, + rte_memory_order_seq_cst); +} + +void * +hinic3_read_wqe (struct hinic3_wq *wq,int num_wqebbs,u16 *cons_idx) +{ +u16 curr_cons_idx; + +if ((rte_atomic_load_explicit (&wq->delta, rte_memory_order_seq_cst) + + num_wqebbs) > wq->q_depth) +return NULL ; + + curr_cons_idx = (u16)(wq->cons_idx); + + curr_cons_idx =MASKED_WQE_IDX (wq, curr_cons_idx); + + *cons_idx = curr_cons_idx; + +return WQ_WQE_ADDR (wq, (u32)(*cons_idx)); +} + +int +hinic3_cmdq_alloc (struct hinic3_wq *wq,void *dev,int cmdq_blocks, +u32 wq_buf_size,u32 wqebb_shift,u16 q_depth) +{ +struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev; +int i, j; +int err; + +/* Validate q_depth is power of 2 & wqebb_size is not 0. */ +for (i =0 ; i < cmdq_blocks; i++) { + wq[i].wqebb_size =1U << wqebb_shift; + wq[i].wqebb_shift = wqebb_shift; + wq[i].wq_buf_size = wq_buf_size; + wq[i].q_depth = q_depth; + + err =alloc_wq_pages (hwdev, &wq[i], i); +if (err) { +PMD_DRV_LOG (ERR ,"Failed to alloc CMDQ blocks" ); + goto cmdq_block_err; + } + + wq[i].cons_idx =0 ; + wq[i].prod_idx =0 ; +rte_atomic_store_explicit (&wq[i].delta, q_depth, + rte_memory_order_seq_cst); + + wq[i].mask = q_depth -1 ; + } + +return 0 ; + +cmdq_block_err: +for (j =0 ; j < i; j++) +free_wq_pages (&wq[j]); + +return err; +} + +void +hinic3_cmdq_free (struct hinic3_wq *wq,int cmdq_blocks) +{ +int i; + +for (i =0 ; i < cmdq_blocks; i++) +free_wq_pages (&wq[i]); +} + +void +hinic3_wq_wqe_pg_clear (struct hinic3_wq *wq) +{ + wq->cons_idx =0 ; + wq->prod_idx =0 ; + +memset ((void *)wq->queue_buf_vaddr,0 , wq->wq_buf_size); +} + +void * +hinic3_get_wqe (struct hinic3_wq *wq,int num_wqebbs,u16 *prod_idx) +{ +u16 curr_prod_idx; + +rte_atomic_fetch_sub_explicit (&wq->delta, num_wqebbs, + rte_memory_order_seq_cst); + curr_prod_idx = (u16)(wq->prod_idx); + wq->prod_idx += num_wqebbs; + *prod_idx =MASKED_WQE_IDX (wq, curr_prod_idx); + +return WQ_WQE_ADDR (wq, (u32)(*prod_idx)); +} + +void +hinic3_set_sge (struct hinic3_sge *sge,uint64_t addr,u32 len) +{ + sge->hi_addr =upper_32_bits (addr); + sge->lo_addr =lower_32_bits (addr); + sge->len = len; +}
drivers/net/hinic3/base/hinic3_wq.h new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 11/18 net/hinic3: add a mailbox communication module
In reply to Feifei WangFrom: Yi Chen <[email protected]>
This patch adds support for mailbox of hinic3 PMD driver, mailbox is used for communication between PF/VF driver and MPU. This patch provides mailbox-related data structures and functional code.
--- drivers/net/hinic3/base/hinic3_mbox.c | 1392 +++++++++++++++++++++++++ drivers/net/hinic3/base/hinic3_mbox.h | 199 ++++ 2 files changed, 1591 insertions(+) create mode 100644 drivers/net/hinic3/base/hinic3_mbox.c create mode 100644 drivers/net/hinic3/base/hinic3_mbox.h
drivers/net/hinic3/base/hinic3_mbox.c new file +1392 -0
@@ -0,0 +1,1392 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include "hinic3_compat.h" +#include "hinic3_csr.h" +#include "hinic3_eqs.h" +#include "hinic3_hw_cfg.h" +#include "hinic3_hwdev.h" +#include "hinic3_hwif.h" +#include "hinic3_mbox.h" +#include "hinic3_mgmt.h" +#include "hinic3_nic_event.h" + +#define HINIC3_MBOX_INT_DST_FUNC_SHIFT 0 +#define HINIC3_MBOX_INT_DST_AEQN_SHIFT 10 +#define HINIC3_MBOX_INT_SRC_RESP_AEQN_SHIFT 12 +#define HINIC3_MBOX_INT_STAT_DMA_SHIFT 14 +/* The size of data to be send (unit of 4 bytes). */ +#define HINIC3_MBOX_INT_TX_SIZE_SHIFT 20 +/* SO_RO(strong order, relax order). */ +#define HINIC3_MBOX_INT_STAT_DMA_SO_RO_SHIFT 25 +#define HINIC3_MBOX_INT_WB_EN_SHIFT 28 + +#define HINIC3_MBOX_INT_DST_AEQN_MASK 0x3 +#define HINIC3_MBOX_INT_SRC_RESP_AEQN_MASK 0x3 +#define HINIC3_MBOX_INT_STAT_DMA_MASK 0x3F +#define HINIC3_MBOX_INT_TX_SIZE_MASK 0x1F +#define HINIC3_MBOX_INT_STAT_DMA_SO_RO_MASK 0x3 +#define HINIC3_MBOX_INT_WB_EN_MASK 0x1 + +#define HINIC3_MBOX_INT_SET (val, field) \ + (((val) & HINIC3_MBOX_INT_##field##_MASK) \ + << HINIC3_MBOX_INT_##field##_SHIFT) + +enum hinic3_mbox_tx_status { +TX_NOT_DONE =1 , +}; + +#define HINIC3_MBOX_CTRL_TRIGGER_AEQE_SHIFT 0 + +/* +* Specifies the issue request for the message data. +* 0 - Tx request is done; +* 1 - Tx request is in process. +*/ +#define HINIC3_MBOX_CTRL_TX_STATUS_SHIFT 1 +#define HINIC3_MBOX_CTRL_DST_FUNC_SHIFT 16 + +#define HINIC3_MBOX_CTRL_TRIGGER_AEQE_MASK 0x1 +#define HINIC3_MBOX_CTRL_TX_STATUS_MASK 0x1 +#define HINIC3_MBOX_CTRL_DST_FUNC_MASK 0x1FFF + +#define HINIC3_MBOX_CTRL_SET (val, field) \ + (((val) & HINIC3_MBOX_CTRL_##field##_MASK) \ + << HINIC3_MBOX_CTRL_##field##_SHIFT) + +#define MBOX_SEGLEN_MASK \ + HINIC3_MSG_HEADER_SET(HINIC3_MSG_HEADER_SEG_LEN_MASK, SEG_LEN) + +#define MBOX_MSG_POLLING_TIMEOUT 500000/* Unit is 10us. */ +#define HINIC3_MBOX_COMP_TIME 40000U + +#define MBOX_MAX_BUF_SZ 2048UL +#define MBOX_HEADER_SZ 8 +#define HINIC3_MBOX_DATA_SIZE (MBOX_MAX_BUF_SZ - MBOX_HEADER_SZ) + +#define MBOX_TLP_HEADER_SZ 16 + +/* Mbox size is 64B, 8B for mbox_header, 8B reserved. */ +#define MBOX_SEG_LEN 48 +#define MBOX_SEG_LEN_ALIGN 4 +#define MBOX_WB_STATUS_LEN 16UL + +/* Mbox write back status is 16B, only first 4B is used. */ +#define MBOX_WB_STATUS_ERRCODE_MASK 0xFFFF +#define MBOX_WB_STATUS_MASK 0xFF +#define MBOX_WB_ERROR_CODE_MASK 0xFF00 +#define MBOX_WB_STATUS_FINISHED_SUCCESS 0xFF +#define MBOX_WB_STATUS_FINISHED_WITH_ERR 0xFE +#define MBOX_WB_STATUS_NOT_FINISHED 0x00 + +/* Determine the write back status. */ +#define MBOX_STATUS_FINISHED (wb) \ + (((wb) & MBOX_WB_STATUS_MASK) != MBOX_WB_STATUS_NOT_FINISHED) +#define MBOX_STATUS_SUCCESS (wb) \ + (((wb) & MBOX_WB_STATUS_MASK) == MBOX_WB_STATUS_FINISHED_SUCCESS) +#define MBOX_STATUS_ERRCODE (wb) ((wb) & MBOX_WB_ERROR_CODE_MASK) + +/* Indicate the value related to the sequence ID. */ +#define SEQ_ID_START_VAL 0 +#define SEQ_ID_MAX_VAL 42 + +#define DST_AEQ_IDX_DEFAULT_VAL 0 +#define SRC_AEQ_IDX_DEFAULT_VAL 0 +#define NO_DMA_ATTRIBUTE_VAL 0 + +#define MBOX_MSG_NO_DATA_LEN 1 + +/* Obtain the specified content of the mailbox. */ +#define MBOX_BODY_FROM_HDR (header) ((u8 *)(header) + MBOX_HEADER_SZ) +#define MBOX_AREA (hwif) \ + ((hwif)->cfg_regs_base + HINIC3_FUNC_CSR_MAILBOX_DATA_OFF) + +#define IS_PF_OR_PPF_SRC (src_func_idx) ((src_func_idx) < HINIC3_MAX_PF_FUNCS) + +#define MBOX_RESPONSE_ERROR 0x1 +#define MBOX_MSG_ID_MASK 0xF +#define MBOX_MSG_ID (func_to_func) ((func_to_func)->send_msg_id) +#define MBOX_MSG_ID_INC (func_to_func) \ + ({ \ + typeof(func_to_func) __func = (func_to_func); \ + MBOX_MSG_ID(__func) = (MBOX_MSG_ID(__func) + 1) & \ + MBOX_MSG_ID_MASK; \ + }) + +/* Max message counter waits to process for one function. */ +#define HINIC3_MAX_MSG_CNT_TO_PROCESS 10 + +enum mbox_ordering_type { +STRONG_ORDER , +}; + +enum mbox_write_back_type { +WRITE_BACK =1 , +}; + +enum mbox_aeq_trig_type { +NOT_TRIGGER , +TRIGGER , +}; + +static int send_mbox_to_func (struct hinic3_mbox *func_to_func, +enum hinic3_mod_type mod,u16 cmd,void *msg, +u16 msg_len,u16 dst_func, +enum hinic3_msg_direction_type direction, +enum hinic3_msg_ack_type ack_type, +struct mbox_msg_info *msg_info); +static int send_tlp_mbox_to_func (struct hinic3_mbox *func_to_func, +enum hinic3_mod_type mod,u16 cmd,void *msg, +u16 msg_len,u16 dst_func, +enum hinic3_msg_direction_type direction, +enum hinic3_msg_ack_type ack_type, +struct mbox_msg_info *msg_info); + +static int +recv_vf_mbox_handler (struct hinic3_mbox *func_to_func, +struct hinic3_recv_mbox *recv_mbox,void *buf_out, + u16 *out_size, __rte_unused void *param) +{ +int err =0 ; + +/* +* Invoke the corresponding processing function according to the type of +* the received mailbox. +*/ +switch (recv_mbox->mod) { +case HINIC3_MOD_COMM : + err =vf_handle_pf_comm_mbox (func_to_func->hwdev, func_to_func, + recv_mbox->cmd, recv_mbox->mbox, + recv_mbox->mbox_len, buf_out, + out_size); +break ; +case HINIC3_MOD_CFGM : + err =cfg_mbx_vf_proc_msg (func_to_func->hwdev, + func_to_func->hwdev->cfg_mgmt, + recv_mbox->cmd, recv_mbox->mbox, recv_mbox->mbox_len, + buf_out, out_size); +break ; +case HINIC3_MOD_L2NIC : + err =hinic3_vf_event_handler (func_to_func->hwdev, + func_to_func->hwdev->cfg_mgmt, + recv_mbox->cmd, recv_mbox->mbox, recv_mbox->mbox_len, + buf_out, out_size); +break ; +case HINIC3_MOD_HILINK : + err =hinic3_vf_mag_event_handler (func_to_func->hwdev, + func_to_func->hwdev->cfg_mgmt, + recv_mbox->cmd, recv_mbox->mbox, recv_mbox->mbox_len, + buf_out, out_size); +break ; +default : +PMD_DRV_LOG (ERR ,"No handler, mod: %d" , recv_mbox->mod); + err =HINIC3_MBOX_VF_CMD_ERROR ; +break ; + } + +return err; +} + +/** +* Respond to the accept packet, construct a response message, and send it. +* +* @param[in] func_to_func +* Context for inter-function communication. +* @param[in] recv_mbox +* Pointer to the received inter-function mailbox structure. +* @param[in] err +* Error Code. +* @param[in] out_size +* Output Size. +* @param[in] src_func_idx +* Index of the source function. +*/ +static void +response_for_recv_func_mbox (struct hinic3_mbox *func_to_func, +struct hinic3_recv_mbox *recv_mbox,int err, +u16 out_size,u16 src_func_idx) +{ +struct mbox_msg_info msg_info = {0 }; + +if (recv_mbox->ack_type ==HINIC3_MSG_ACK ) { + msg_info.msg_id = recv_mbox->msg_info.msg_id; +if (err) + msg_info.status =HINIC3_MBOX_PF_SEND_ERR ; + +/* Select the sending function based on the packet type. */ +if (IS_TLP_MBX (src_func_idx)) +send_tlp_mbox_to_func (func_to_func, recv_mbox->mod, + recv_mbox->cmd, + recv_mbox->buf_out, out_size, + src_func_idx,HINIC3_MSG_RESPONSE , +HINIC3_MSG_NO_ACK , &msg_info); +else +send_mbox_to_func (func_to_func, recv_mbox->mod, + recv_mbox->cmd, recv_mbox->buf_out, + out_size, src_func_idx, +HINIC3_MSG_RESPONSE , +HINIC3_MSG_NO_ACK , &msg_info); + } +} + +static bool +check_func_mbox_ack_first (u8 mod) +{ +return mod ==HINIC3_MOD_HILINK ; +} + +static void +recv_func_mbox_handler (struct hinic3_mbox *func_to_func, +struct hinic3_recv_mbox *recv_mbox,u16 src_func_idx, +void *param) +{ +struct hinic3_hwdev *hwdev = func_to_func->hwdev; +void *buf_out = recv_mbox->buf_out; +bool ack_first = false; +u16 out_size =MBOX_MAX_BUF_SZ ; +int err =0 ; +/* Check whether the response is the first ACK message. */ + ack_first =check_func_mbox_ack_first (recv_mbox->mod); +if (ack_first && recv_mbox->ack_type ==HINIC3_MSG_ACK ) { +response_for_recv_func_mbox (func_to_func, recv_mbox, err, + out_size, src_func_idx); + } + +/* Processe mailbox information in the VF. */ +if (HINIC3_IS_VF (hwdev)) { + err =recv_vf_mbox_handler (func_to_func, recv_mbox, buf_out, + &out_size, param); + }else { + err = -EINVAL ; +PMD_DRV_LOG (ERR , +"PMD doesn't support non-VF handle mailbox message" ); + } + +if (!out_size || err) + out_size =MBOX_MSG_NO_DATA_LEN ; + +if (!ack_first && recv_mbox->ack_type ==HINIC3_MSG_ACK ) { +response_for_recv_func_mbox (func_to_func, recv_mbox, err, + out_size, src_func_idx); + } +} + +/** +* Processe mailbox responses from functions. +* +* @param[in] func_to_func +* Mailbox for inter-function communication. +* @param[in] recv_mbox +* Received mailbox message. +* @return +* 0 on success, non-zero on failure. +*/ +static int +resp_mbox_handler (struct hinic3_mbox *func_to_func, +struct hinic3_recv_mbox *recv_mbox) +{ +int ret; +rte_spinlock_lock (&func_to_func->mbox_lock); +if (recv_mbox->msg_info.msg_id == func_to_func->send_msg_id && + func_to_func->event_flag ==EVENT_START ) { + func_to_func->event_flag =EVENT_SUCCESS ; + ret =0 ; + }else { +PMD_DRV_LOG (ERR , +"Mbox response timeout, current send msg id(0x%x), " +"recv msg id(0x%x), status(0x%x)" , + func_to_func->send_msg_id, + recv_mbox->msg_info.msg_id, + recv_mbox->msg_info.status); + ret =HINIC3_MSG_HANDLER_RES ; + } +rte_spinlock_unlock (&func_to_func->mbox_lock); +return ret; +} + +/** +* Check whether the received mailbox message segment is valid. +* +* @param[out] recv_mbox +* Received mailbox message. +* @param[in] mbox_header +* Mailbox header. +* @return +* The value true indicates valid, and the value false indicates invalid. +*/ +static bool +check_mbox_segment (struct hinic3_recv_mbox *recv_mbox,u64 mbox_header) +{ +u8 seq_id, seg_len, msg_id, mod; +u16 src_func_idx, cmd; + +/* Get info from the mailbox header. */ + seq_id =HINIC3_MSG_HEADER_GET (mbox_header,SEQID ); + seg_len =HINIC3_MSG_HEADER_GET (mbox_header,SEG_LEN ); + src_func_idx =HINIC3_MSG_HEADER_GET (mbox_header,SRC_GLB_FUNC_IDX ); + msg_id =HINIC3_MSG_HEADER_GET (mbox_header,MSG_ID ); + mod =HINIC3_MSG_HEADER_GET (mbox_header,MODULE ); + cmd =HINIC3_MSG_HEADER_GET (mbox_header,CMD ); + +if (seq_id >SEQ_ID_MAX_VAL || seg_len >MBOX_SEG_LEN ) + goto seg_err; + +/* New message segment, which saves its information to recv_mbox. */ +if (seq_id ==0 ) { + recv_mbox->seq_id = seq_id; + recv_mbox->msg_info.msg_id = msg_id; + recv_mbox->mod = mod; + recv_mbox->cmd = cmd; + }else { +if ((seq_id != recv_mbox->seq_id +1 ) || + msg_id != recv_mbox->msg_info.msg_id || + mod != recv_mbox->mod || cmd != recv_mbox->cmd) + goto seg_err; + + recv_mbox->seq_id = seq_id; + } + +return true; + +seg_err: +PMD_DRV_LOG (ERR , +"Mailbox segment check failed, src func id: 0x%x, " +"front seg info: seq id: 0x%x, msg id: 0x%x, mod: 0x%x, " +"cmd: 0x%x" , + src_func_idx, recv_mbox->seq_id, recv_mbox->msg_info.msg_id, + recv_mbox->mod, recv_mbox->cmd); +PMD_DRV_LOG (ERR , +"Current seg info: seg len: 0x%x, seq id: 0x%x, " +"msg id: 0x%x, mod: 0x%x, cmd: 0x%x" , + seg_len, seq_id, msg_id, mod, cmd); + +return false; +} + +static int +recv_mbox_handler (struct hinic3_mbox *func_to_func,void *header, +struct hinic3_recv_mbox *recv_mbox,void *param) +{ +u64 mbox_header = *((u64 *)header); +void *mbox_body =MBOX_BODY_FROM_HDR (header); +u16 src_func_idx; +int pos; +u8 seq_id; +/* Obtain information from the mailbox header. */ + seq_id =HINIC3_MSG_HEADER_GET (mbox_header,SEQID ); + src_func_idx =HINIC3_MSG_HEADER_GET (mbox_header,SRC_GLB_FUNC_IDX ); + +if (!check_mbox_segment (recv_mbox, mbox_header)) { + recv_mbox->seq_id =SEQ_ID_MAX_VAL ; +return HINIC3_MSG_HANDLER_RES ; + } + + pos = seq_id *MBOX_SEG_LEN ; +memcpy ((void *)((u8 *)recv_mbox->mbox + pos), (void *)mbox_body, + (size_t )HINIC3_MSG_HEADER_GET (mbox_header,SEG_LEN )); + +if (!HINIC3_MSG_HEADER_GET (mbox_header,LAST )) +return HINIC3_MSG_HANDLER_RES ; +/* Setting the information about the recv mailbox. */ + recv_mbox->cmd =HINIC3_MSG_HEADER_GET (mbox_header,CMD ); + recv_mbox->mod =HINIC3_MSG_HEADER_GET (mbox_header,MODULE ); + recv_mbox->mbox_len =HINIC3_MSG_HEADER_GET (mbox_header,MSG_LEN ); + recv_mbox->ack_type =HINIC3_MSG_HEADER_GET (mbox_header,NO_ACK ); + recv_mbox->msg_info.msg_id =HINIC3_MSG_HEADER_GET (mbox_header,MSG_ID ); + recv_mbox->msg_info.status =HINIC3_MSG_HEADER_GET (mbox_header,STATUS ); + recv_mbox->seq_id =SEQ_ID_MAX_VAL ; + +/* +* If the received message is a response message, call the mbox response +* processing function. +*/ +if (HINIC3_MSG_HEADER_GET (mbox_header,DIRECTION ) == +HINIC3_MSG_RESPONSE ) { +return resp_mbox_handler (func_to_func, recv_mbox); + } + +recv_func_mbox_handler (func_to_func, recv_mbox, src_func_idx, param); +return HINIC3_MSG_HANDLER_RES ; +} + +static inline int +hinic3_mbox_get_index (int func) +{ +return (func ==HINIC3_MGMT_SRC_ID ) ?HINIC3_MBOX_MPU_INDEX + :HINIC3_MBOX_PF_INDEX ; +} + +int +hinic3_mbox_func_aeqe_handler(void *handle, u8 *header, __rte_unused u8 size, +void *param) +{ +struct hinic3_mbox *func_to_func =NULL ; +struct hinic3_recv_mbox *recv_mbox =NULL ; +u64 mbox_header = *((u64 *)header); +u64 src, dir; +/* Obtain the mailbox for communication between functions. */ + func_to_func = ((struct hinic3_hwdev *)handle)->func_to_func; + + dir =HINIC3_MSG_HEADER_GET (mbox_header,DIRECTION ); + src =HINIC3_MSG_HEADER_GET (mbox_header,SRC_GLB_FUNC_IDX ); + + src =hinic3_mbox_get_index ((int )src); + recv_mbox = (dir ==HINIC3_MSG_DIRECT_SEND ) + ? &func_to_func->mbox_send[src] + : &func_to_func->mbox_resp[src]; +/* Processing Received Mailbox info. */ +return recv_mbox_handler (func_to_func, (u64 *)header, recv_mbox, param); +} + +static void +clear_mbox_status (struct hinic3_send_mbox *mbox) +{ + *mbox->wb_status =0 ; + +/* Clear mailbox write back status. */ +rte_wmb (); +} + +static void +mbox_copy_header (struct hinic3_send_mbox *mbox,u64 *header) +{ +u32 *data = (u32 *)header; +u32 i, idx_max =MBOX_HEADER_SZ /sizeof (u32); + +for (i =0 ; i < idx_max; i++) { +rte_write32 (cpu_to_be32 (*(data + i)), + mbox->data + i *sizeof (u32)); + } +} + +#define MBOX_DMA_MSG_INIT_XOR_VAL 0x5a5a5a5a +static u32 +mbox_dma_msg_xor (u32 *data,u16 msg_len) +{ +u32 xor =MBOX_DMA_MSG_INIT_XOR_VAL ; +u16 dw_len = msg_len /sizeof (u32); +u16 i; + +for (i =0 ; i < dw_len; i++) + xor ^= data[i]; + +return xor; +} + +static void +mbox_copy_send_data_addr (struct hinic3_send_mbox *mbox,u16 seg_len) +{ +u32 addr_h, addr_l, xor; + + xor =mbox_dma_msg_xor (mbox->sbuff_vaddr, seg_len); + addr_h =upper_32_bits (mbox->sbuff_paddr); + addr_l =lower_32_bits (mbox->sbuff_paddr); + +rte_write32 (cpu_to_be32 (xor), mbox->data +MBOX_HEADER_SZ ); +rte_write32 (cpu_to_be32 (addr_h), + mbox->data +MBOX_HEADER_SZ +sizeof (u32)); +rte_write32 (cpu_to_be32 (addr_l), + mbox->data +MBOX_HEADER_SZ +0x2 *sizeof (u32)); +rte_write32 (cpu_to_be32 ((u32 )seg_len), + mbox->data +MBOX_HEADER_SZ +0x3 *sizeof (u32)); +/* Reserved field. */ +rte_write32 (0 , mbox->data +MBOX_HEADER_SZ +0x4 *sizeof (u32)); +rte_write32 (0 , mbox->data +MBOX_HEADER_SZ +0x5 *sizeof (u32)); +} + +static void +mbox_copy_send_data (struct hinic3_send_mbox *mbox,void *seg,u16 seg_len) +{ +u32 *data = seg; +u32 data_len, chk_sz =sizeof (u32); +u32 i, idx_max; +u8 mbox_max_buf[MBOX_SEG_LEN ] = {0 }; + +/* The mbox message should be aligned in 4 bytes. */ +if (seg_len % chk_sz) { +rte_memcpy (mbox_max_buf, seg, seg_len); + data = (u32 *)mbox_max_buf; + } + + data_len = seg_len; + idx_max =RTE_ALIGN (data_len, chk_sz) / chk_sz; + +for (i =0 ; i < idx_max; i++) { +rte_write32 (cpu_to_be32 (*(data + i)), + mbox->data +MBOX_HEADER_SZ + i *sizeof (u32)); + } +} + +static void +write_mbox_msg_attr (struct hinic3_mbox *func_to_func,u16 dst_func, +u16 dst_aeqn,u16 seg_len) +{ +u32 mbox_int, mbox_ctrl; + +/* If VF, function ids must self-learning by HW(PPF=1 PF=0). */ +if (HINIC3_IS_VF (func_to_func->hwdev) && + dst_func !=HINIC3_MGMT_SRC_ID ) { +if (dst_func ==HINIC3_HWIF_PPF_IDX (func_to_func->hwdev->hwif)) + dst_func =1 ; +else + dst_func =0 ; + } +/* Set the interrupt attribute of the mailbox. */ + mbox_int =HINIC3_MBOX_INT_SET (dst_aeqn,DST_AEQN ) | +HINIC3_MBOX_INT_SET (0 ,SRC_RESP_AEQN ) | +HINIC3_MBOX_INT_SET (NO_DMA_ATTRIBUTE_VAL ,STAT_DMA ) | +HINIC3_MBOX_INT_SET (RTE_ALIGN (seg_len +MBOX_HEADER_SZ , +MBOX_SEG_LEN_ALIGN ) >> +2 , +TX_SIZE ) | +HINIC3_MBOX_INT_SET (STRONG_ORDER ,STAT_DMA_SO_RO ) | +HINIC3_MBOX_INT_SET (WRITE_BACK ,WB_EN ); + +/* The interrupt attribute is written to the interrupt register. */ +hinic3_hwif_write_reg (func_to_func->hwdev->hwif, +HINIC3_FUNC_CSR_MAILBOX_INT_OFFSET_OFF , mbox_int); + +rte_wmb ();/**< Writing the mbox intr attributes */ + +/* Set the control attributes of the mailbox and write to register. */ + mbox_ctrl =HINIC3_MBOX_CTRL_SET (TX_NOT_DONE ,TX_STATUS ); + mbox_ctrl |=HINIC3_MBOX_CTRL_SET (NOT_TRIGGER ,TRIGGER_AEQE ); + mbox_ctrl |=HINIC3_MBOX_CTRL_SET (dst_func,DST_FUNC ); +hinic3_hwif_write_reg (func_to_func->hwdev->hwif, +HINIC3_FUNC_CSR_MAILBOX_CONTROL_OFF , mbox_ctrl); +} + +/** +* Read the value of the mailbox register of the hardware device. +* +* @param[in] hwdev +* Pointer to hardware device structure. +*/ +static void +dump_mbox_reg (struct hinic3_hwdev *hwdev) +{ +u32 val; +/* Read the value of the MBOX control register. */ + val =hinic3_hwif_read_reg (hwdev->hwif, +HINIC3_FUNC_CSR_MAILBOX_CONTROL_OFF ); +PMD_DRV_LOG (ERR ,"Mailbox control reg: 0x%x" , val); +/* Read the value of the MBOX interrupt offset register. */ + val =hinic3_hwif_read_reg (hwdev->hwif, +HINIC3_FUNC_CSR_MAILBOX_INT_OFFSET_OFF ); +PMD_DRV_LOG (ERR ,"Mailbox interrupt offset: 0x%x" , val); +} + +static u16 +get_mbox_status (struct hinic3_send_mbox *mbox) +{ +/* Write back is 16B, but only use first 4B. */ +u64 wb_val =be64_to_cpu (*mbox->wb_status); + +rte_rmb ();/**< Verify reading before check. */ + +return (u16)(wb_val &MBOX_WB_STATUS_ERRCODE_MASK ); +} + +/** +* Sending Mailbox Message Segment. +* +* @param[in] func_to_func +* Mailbox for inter-function communication. +* @param[in] header +* Mailbox header. +* @param[in] dst_func +* Indicate destination func. +* @param[in] seg +* Segment data to be sent. +* @param[in] seg_len +* Length of the segment to be sent. +* @param[in] msg_info +* Indicate the message information. +* @return +* 0 on success, non-zero on failure. +*/ +static int +send_mbox_seg (struct hinic3_mbox *func_to_func,u64 header,u16 dst_func, + void *seg, u16 seg_len, __rte_unused void *msg_info) +{ +struct hinic3_send_mbox *send_mbox = &func_to_func->send_mbox; +struct hinic3_hwdev *hwdev = func_to_func->hwdev; +u8 num_aeqs = hwdev->hwif->attr.num_aeqs; +u16 dst_aeqn, wb_status =0 , errcode; +u16 seq_dir =HINIC3_MSG_HEADER_GET (header,DIRECTION ); +u32 cnt =0 ; + +/* Mbox to mgmt cpu, hardware doesn't care dst aeq id. */ +if (num_aeqs >=2 ) + dst_aeqn = (seq_dir ==HINIC3_MSG_DIRECT_SEND ) + ?HINIC3_ASYNC_MSG_AEQ + :HINIC3_MBOX_RSP_MSG_AEQ ; +else + dst_aeqn =0 ; + +clear_mbox_status (send_mbox); +mbox_copy_header (send_mbox, &header); +mbox_copy_send_data (send_mbox, seg, seg_len); + +/* Set mailbox msg seg len. */ +write_mbox_msg_attr (func_to_func, dst_func, dst_aeqn, seg_len); +rte_wmb ();/**< Writing the mbox msg attributes. */ + +/* Wait until the status of the mailbox changes to Complete. */ +while (cnt <MBOX_MSG_POLLING_TIMEOUT ) { + wb_status =get_mbox_status (send_mbox); +if (MBOX_STATUS_FINISHED (wb_status)) +break ; + +rte_delay_us (10 ); + cnt++; + } + +if (cnt ==MBOX_MSG_POLLING_TIMEOUT ) { +PMD_DRV_LOG (ERR , +"Send mailbox segment timeout, wb status: 0x%x" , + wb_status); +dump_mbox_reg (hwdev); +return -ETIMEDOUT ; + } + +if (!MBOX_STATUS_SUCCESS (wb_status)) { +PMD_DRV_LOG (ERR , +"Send mailbox segment to function %d error, wb " +"status: 0x%x" , + dst_func, wb_status); + errcode =MBOX_STATUS_ERRCODE (wb_status); +return errcode ? errcode : -EFAULT ; + } + +return 0 ; +} + +static int +send_tlp_mbox_seg (struct hinic3_mbox *func_to_func,u64 header,u16 dst_func, + void *seg, u16 seg_len, __rte_unused void *msg_info) +{ +struct hinic3_send_mbox *send_mbox = &func_to_func->send_mbox; +struct hinic3_hwdev *hwdev = func_to_func->hwdev; +u8 num_aeqs = hwdev->hwif->attr.num_aeqs; +u16 dst_aeqn, errcode, wb_status =0 ; +u16 seq_dir =HINIC3_MSG_HEADER_GET (header,DIRECTION ); +u32 cnt =0 ; + +/* Mbox to mgmt cpu, hardware doesn't care dst aeq id. */ +if (num_aeqs >=2 ) + dst_aeqn = (seq_dir ==HINIC3_MSG_DIRECT_SEND ) + ?HINIC3_ASYNC_MSG_AEQ + :HINIC3_MBOX_RSP_MSG_AEQ ; +else + dst_aeqn =0 ; + +clear_mbox_status (send_mbox); +mbox_copy_header (send_mbox, &header); + +/* Copy data to DMA buffer. */ +memcpy ((void *)send_mbox->sbuff_vaddr, (void *)seg, (size_t )seg_len); + +/* +* Copy data address to mailbox ctrl CSR(Control and Status Register). +*/ +mbox_copy_send_data_addr (send_mbox, seg_len); + +/* Set mailbox msg header size. */ +write_mbox_msg_attr (func_to_func, dst_func, dst_aeqn, +MBOX_TLP_HEADER_SZ ); + +rte_wmb ();/**< Writing the mbox msg attributes. */ + +/* Wait until the status of the mailbox changes to Complete. */ +while (cnt <MBOX_MSG_POLLING_TIMEOUT ) { + wb_status =get_mbox_status (send_mbox); +if (MBOX_STATUS_FINISHED (wb_status)) +break ; + +rte_delay_us (10 ); + cnt++; + } + +if (cnt ==MBOX_MSG_POLLING_TIMEOUT ) { +PMD_DRV_LOG (ERR , +"Send mailbox segment timeout, wb status: 0x%x" , + wb_status); +dump_mbox_reg (hwdev); +return -ETIMEDOUT ; + } + +if (!MBOX_STATUS_SUCCESS (wb_status)) { +PMD_DRV_LOG (ERR , +"Send mailbox segment to function %d error, wb " +"status: 0x%x" , + dst_func, wb_status); + errcode =MBOX_STATUS_ERRCODE (wb_status); +return errcode ? errcode : -EFAULT ; + } + +return 0 ; +} + +static int +send_mbox_to_func (struct hinic3_mbox *func_to_func,enum hinic3_mod_type mod, +u16 cmd,void *msg,u16 msg_len,u16 dst_func, +enum hinic3_msg_direction_type direction, +enum hinic3_msg_ack_type ack_type, +struct mbox_msg_info *msg_info) +{ +int err =0 ; +u32 seq_id =0 ; +u16 seg_len =MBOX_SEG_LEN ; +u16 rsp_aeq_id, left = msg_len; +u8 *msg_seg = (u8 *)msg; +u64 header =0 ; + + rsp_aeq_id =HINIC3_MBOX_RSP_MSG_AEQ ; + + err =hinic3_mutex_lock (&func_to_func->msg_send_mutex); +if (err) +return err; + +/* Set the header message. */ + header =HINIC3_MSG_HEADER_SET (msg_len,MSG_LEN ) | +HINIC3_MSG_HEADER_SET (mod,MODULE ) | +HINIC3_MSG_HEADER_SET (seg_len,SEG_LEN ) | +HINIC3_MSG_HEADER_SET (ack_type,NO_ACK ) | +HINIC3_MSG_HEADER_SET (HINIC3_DATA_INLINE ,DATA_TYPE ) | +HINIC3_MSG_HEADER_SET (SEQ_ID_START_VAL ,SEQID ) | +HINIC3_MSG_HEADER_SET (NOT_LAST_SEGMENT ,LAST ) | +HINIC3_MSG_HEADER_SET (direction,DIRECTION ) | +HINIC3_MSG_HEADER_SET (cmd,CMD ) | +/* The VF's offset to it's associated PF. */ +HINIC3_MSG_HEADER_SET (msg_info->msg_id,MSG_ID ) | +HINIC3_MSG_HEADER_SET (rsp_aeq_id,AEQ_ID ) | +HINIC3_MSG_HEADER_SET (HINIC3_MSG_FROM_MBOX ,SOURCE ) | +HINIC3_MSG_HEADER_SET (!!msg_info->status,STATUS ); +/* Loop until all messages are sent. */ +while (!(HINIC3_MSG_HEADER_GET (header,LAST ))) { +if (left <=MBOX_SEG_LEN ) { + header &= ~MBOX_SEGLEN_MASK ; + header |=HINIC3_MSG_HEADER_SET (left,SEG_LEN ); + header |=HINIC3_MSG_HEADER_SET (LAST_SEGMENT ,LAST ); + + seg_len = left; + } + + err =send_mbox_seg (func_to_func, header, dst_func, msg_seg, + seg_len, msg_info); +if (err) { +PMD_DRV_LOG (ERR , +"Send mbox seg failed, seq_id: 0x%" PRIx64, +HINIC3_MSG_HEADER_GET (header,SEQID )); + + goto send_err; + } + + left -=MBOX_SEG_LEN ; + msg_seg +=MBOX_SEG_LEN ; + + seq_id++; + header &= ~(HINIC3_MSG_HEADER_SET (HINIC3_MSG_HEADER_SEQID_MASK , +SEQID )); + header |=HINIC3_MSG_HEADER_SET (seq_id,SEQID ); + } + +send_err: + (void )hinic3_mutex_unlock (&func_to_func->msg_send_mutex); + +return err; +} + +static int +send_tlp_mbox_to_func (struct hinic3_mbox *func_to_func, +enum hinic3_mod_type mod,u16 cmd,void *msg,u16 msg_len, +u16 dst_func,enum hinic3_msg_direction_type direction, +enum hinic3_msg_ack_type ack_type, +struct mbox_msg_info *msg_info) +{ +struct hinic3_hwdev *hwdev = func_to_func->hwdev; +u8 *msg_seg = (u8 *)msg; +int err =0 ; +u16 rsp_aeq_id; +u64 header =0 ; + + rsp_aeq_id =HINIC3_MBOX_RSP_MSG_AEQ ; + + err =hinic3_mutex_lock (&func_to_func->msg_send_mutex); +if (err) +return err; + +/* Set the header message. */ + header =HINIC3_MSG_HEADER_SET (MBOX_TLP_HEADER_SZ ,MSG_LEN ) | +HINIC3_MSG_HEADER_SET (MBOX_TLP_HEADER_SZ ,SEG_LEN ) | +HINIC3_MSG_HEADER_SET (mod,MODULE ) | +HINIC3_MSG_HEADER_SET (LAST_SEGMENT ,LAST ) | +HINIC3_MSG_HEADER_SET (ack_type,NO_ACK ) | +HINIC3_MSG_HEADER_SET (HINIC3_DATA_DMA ,DATA_TYPE ) | +HINIC3_MSG_HEADER_SET (SEQ_ID_START_VAL ,SEQID ) | +HINIC3_MSG_HEADER_SET (direction,DIRECTION ) | +HINIC3_MSG_HEADER_SET (cmd,CMD ) | +/* The VF's offset to it's associated PF. */ +HINIC3_MSG_HEADER_SET (msg_info->msg_id,MSG_ID ) | +HINIC3_MSG_HEADER_SET (rsp_aeq_id,AEQ_ID ) | +HINIC3_MSG_HEADER_SET (HINIC3_MSG_FROM_MBOX ,SOURCE ) | +HINIC3_MSG_HEADER_SET (!!msg_info->status,STATUS ) | +HINIC3_MSG_HEADER_SET (hinic3_global_func_id (hwdev), +SRC_GLB_FUNC_IDX ); + +/* Send a message. */ + err =send_tlp_mbox_seg (func_to_func, header, dst_func, msg_seg, + msg_len, msg_info); +if (err) { +PMD_DRV_LOG (ERR ,"Send mbox seg failed, seq_id: 0x%" PRIx64, +HINIC3_MSG_HEADER_GET (header,SEQID )); + } + + (void )hinic3_mutex_unlock (&func_to_func->msg_send_mutex); + +return err; +} + +/** +* Set mailbox F2F(Function to Function) event status. +* +* @param[out] func_to_func +* Context for inter-function communication. +* @param[in] event_flag +* Event status enumerated value. +*/ +static void +set_mbox_to_func_event (struct hinic3_mbox *func_to_func, +enum mbox_event_state event_flag) +{ +rte_spinlock_lock (&func_to_func->mbox_lock); + func_to_func->event_flag = event_flag; +rte_spinlock_unlock (&func_to_func->mbox_lock); +} + +/** +* Send data from one function to another and receive responses. +* +* @param[in] func_to_func +* Context for inter-function communication. +* @param[in] mod +* Command queue module type. +* @param[in] cmd +* Indicate the command to be executed. +the command to be executed. +* @param[in] dst_func +* Indicate destination func. +* @param[in] buf_in +* Pointer to the input buffer. +* @param[in] in_size +* Input buffer size. +* @param[out] buf_out +* Pointer to the output buffer. +* @param[out] out_size +* Output buffer size. +* @param[in] timeout +* Timeout interval for waiting for a response. +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_mbox_to_func (struct hinic3_mbox *func_to_func,enum hinic3_mod_type mod, +u16 cmd,u16 dst_func,void *buf_in,u16 in_size, +void *buf_out,u16 *out_size,u32 timeout) +{ +/* Use mbox_resp to hole data which responsed from other function. */ +struct hinic3_recv_mbox *mbox_for_resp =NULL ; +struct mbox_msg_info msg_info = {0 }; +struct hinic3_eq *aeq =NULL ; +u16 mbox_rsp_idx; +u32 time; +int err; + + mbox_rsp_idx = (u16 )hinic3_mbox_get_index (dst_func); + mbox_for_resp = &func_to_func->mbox_resp[mbox_rsp_idx]; + + err =hinic3_mutex_lock (&func_to_func->mbox_send_mutex); +if (err) +return err; + +/* Set message ID and start event. */ + msg_info.msg_id =MBOX_MSG_ID_INC (func_to_func); +set_mbox_to_func_event (func_to_func,EVENT_START ); + +/* Select a function to send messages based on the dst_func type. */ +if (IS_TLP_MBX (dst_func)) + err =send_tlp_mbox_to_func (func_to_func, + mod, cmd, buf_in, in_size, dst_func, +HINIC3_MSG_DIRECT_SEND ,HINIC3_MSG_ACK , &msg_info); +else + err =send_mbox_to_func (func_to_func, mod, cmd, buf_in, in_size, + dst_func,HINIC3_MSG_DIRECT_SEND , +HINIC3_MSG_ACK , &msg_info); + +if (err) { +PMD_DRV_LOG (ERR ,"Send mailbox failed, msg_id: %d" , + msg_info.msg_id); +set_mbox_to_func_event (func_to_func,EVENT_FAIL ); + goto send_err; + } + +/* Wait for the response message. */ + time =msecs_to_jiffies (timeout ? timeout :HINIC3_MBOX_COMP_TIME ); + aeq = &func_to_func->hwdev->aeqs->aeq[HINIC3_MBOX_RSP_MSG_AEQ ]; + err =hinic3_aeq_poll_msg (aeq, time,NULL ); +if (err) { +set_mbox_to_func_event (func_to_func,EVENT_TIMEOUT ); +PMD_DRV_LOG (ERR ,"Send mailbox message time out" ); + err = -ETIMEDOUT ; + goto send_err; + } + +/* Check whether mod and command of the rsp message match the sent message. */ +if (mod != mbox_for_resp->mod || cmd != mbox_for_resp->cmd) { +PMD_DRV_LOG (ERR , +"Invalid response mbox message, mod: 0x%x, cmd: " +"0x%x, expect mod: 0x%x, cmd: 0x%x" , + mbox_for_resp->mod, mbox_for_resp->cmd, mod, cmd); + err = -EFAULT ; + goto send_err; + } + +/* Check the response status. */ +if (mbox_for_resp->msg_info.status) { + err = mbox_for_resp->msg_info.status; + goto send_err; + } + +/* Check whether the length of the response message is valid. */ +if (buf_out && out_size) { +if (*out_size < mbox_for_resp->mbox_len) { +PMD_DRV_LOG (ERR , +"Invalid response mbox message length: %d for " +"mod: %d cmd: %d, should less than: %d" , + mbox_for_resp->mbox_len, mod, cmd, *out_size); + err = -EFAULT ; + goto send_err; + } + +if (mbox_for_resp->mbox_len) +memcpy (buf_out, mbox_for_resp->mbox, + (size_t )(mbox_for_resp->mbox_len)); + + *out_size = mbox_for_resp->mbox_len; + } + +send_err: + (void )hinic3_mutex_unlock (&func_to_func->mbox_send_mutex); + +return err; +} + +static int +mbox_func_params_valid(__rte_unused struct hinic3_mbox *func_to_func, +void *buf_in,u16 in_size) +{ +if (!buf_in || !in_size) +return -EINVAL ; + +if (in_size >HINIC3_MBOX_DATA_SIZE ) { +PMD_DRV_LOG (ERR ,"Mbox msg len(%d) exceed limit(%" PRIu64")" , + in_size,HINIC3_MBOX_DATA_SIZE ); +return -EINVAL ; + } + +return 0 ; +} + +static int +hinic3_mbox_to_func_no_ack (struct hinic3_hwdev *hwdev,u16 func_idx, +enum hinic3_mod_type mod,u16 cmd,void *buf_in, +u16 in_size) +{ +struct hinic3_mbox *func_to_func = hwdev->func_to_func; +struct mbox_msg_info msg_info = {0 }; +int err; + + err =mbox_func_params_valid (hwdev->func_to_func, buf_in, in_size); +if (err) +return err; + + err =hinic3_mutex_lock (&func_to_func->mbox_send_mutex); +if (err) +return err; + +if (IS_TLP_MBX (func_idx)) + err =send_tlp_mbox_to_func (func_to_func, + mod, cmd, buf_in, in_size, func_idx, +HINIC3_MSG_DIRECT_SEND ,HINIC3_MSG_NO_ACK , &msg_info); +else + err =send_mbox_to_func (func_to_func, mod, cmd, buf_in, in_size, + func_idx,HINIC3_MSG_DIRECT_SEND , +HINIC3_MSG_NO_ACK , &msg_info); +if (err) +PMD_DRV_LOG (ERR ,"Send mailbox no ack failed" ); + + (void )hinic3_mutex_unlock (&func_to_func->mbox_send_mutex); + +return err; +} + +int +hinic3_send_mbox_to_mgmt (struct hinic3_hwdev *hwdev,enum hinic3_mod_type mod, +u16 cmd,void *buf_in,u16 in_size,void *buf_out, +u16 *out_size,u32 timeout) +{ +struct hinic3_mbox *func_to_func = hwdev->func_to_func; +int err; +/* Verify the validity of the input parameters. */ + err =mbox_func_params_valid (func_to_func, buf_in, in_size); +if (err) +return err; + +return hinic3_mbox_to_func (func_to_func, mod, cmd,HINIC3_MGMT_SRC_ID , + buf_in, in_size, buf_out, out_size, timeout); +} + +void +hinic3_response_mbox_to_mgmt (struct hinic3_hwdev *hwdev, +enum hinic3_mod_type mod,u16 cmd,void *buf_in, +u16 in_size,u16 msg_id) +{ +struct mbox_msg_info msg_info; +u16 dst_func; + + msg_info.msg_id = (u8 )msg_id; + msg_info.status =0 ; + dst_func =HINIC3_MGMT_SRC_ID ; + +if (IS_TLP_MBX (dst_func)) +send_tlp_mbox_to_func (hwdev->func_to_func, mod, cmd, buf_in, + in_size,HINIC3_MGMT_SRC_ID , +HINIC3_MSG_RESPONSE ,HINIC3_MSG_NO_ACK , + &msg_info); +else +send_mbox_to_func (hwdev->func_to_func, mod, cmd, buf_in, + in_size,HINIC3_MGMT_SRC_ID , +HINIC3_MSG_RESPONSE ,HINIC3_MSG_NO_ACK , + &msg_info); +} + +int +hinic3_send_mbox_to_mgmt_no_ack (struct hinic3_hwdev *hwdev, +enum hinic3_mod_type mod,u16 cmd,void *buf_in, +u16 in_size) +{ +struct hinic3_mbox *func_to_func = hwdev->func_to_func; +int err; + + err =mbox_func_params_valid (func_to_func, buf_in, in_size); +if (err) +return err; + +return hinic3_mbox_to_func_no_ack (hwdev,HINIC3_MGMT_SRC_ID , mod, cmd, + buf_in, in_size); +} + +int +hinic3_mbox_to_pf (struct hinic3_hwdev *hwdev,enum hinic3_mod_type mod,u16 cmd, +void *buf_in,u16 in_size,void *buf_out,u16 *out_size, +u32 timeout) +{ +int err; + +if (!hwdev) +return -EINVAL ; + +/* Check the validity of parameters. */ + err =mbox_func_params_valid (hwdev->func_to_func, buf_in, in_size); +if (err) +return err; + +if (!HINIC3_IS_VF (hwdev)) { +PMD_DRV_LOG (ERR ,"Params error, func_type: %d" , +hinic3_func_type (hwdev)); +return -EINVAL ; + } + +/* Sending Email to PF. */ +return hinic3_mbox_to_func (hwdev->func_to_func, mod, cmd, +hinic3_pf_id_of_vf (hwdev), buf_in, in_size, + buf_out, out_size, timeout); +} + +int +hinic3_mbox_to_vf (struct hinic3_hwdev *hwdev,enum hinic3_mod_type mod, +u16 vf_id,u16 cmd,void *buf_in,u16 in_size,void *buf_out, +u16 *out_size,u32 timeout) +{ +struct hinic3_mbox *func_to_func =NULL ; +u16 dst_func_idx; +int err =0 ; + +if (!hwdev) +return -EINVAL ; + + func_to_func = hwdev->func_to_func; + err =mbox_func_params_valid (func_to_func, buf_in, in_size); +if (err) +return err; + +if (HINIC3_IS_VF (hwdev)) { +PMD_DRV_LOG (ERR ,"Params error, func_type: %d" , +hinic3_func_type (hwdev)); +return -EINVAL ; + } + +if (!vf_id) { +PMD_DRV_LOG (ERR ,"VF id: %d error!" , vf_id); +return -EINVAL ; + } + +/* +* The sum of vf_offset_to_pf + vf_id is the VF's global function id of +* VF in this pf. +*/ + dst_func_idx =hinic3_glb_pf_vf_offset (hwdev) + vf_id; + +return hinic3_mbox_to_func (func_to_func, mod, cmd, dst_func_idx, buf_in, + in_size, buf_out, out_size, timeout); +} + +static int +init_mbox_info (struct hinic3_recv_mbox *mbox_info,int mbox_max_buf_sz) +{ +int err; + + mbox_info->seq_id =SEQ_ID_MAX_VAL ; + + mbox_info->mbox = +rte_zmalloc ("mbox" , (size_t )mbox_max_buf_sz,1 );/*lint !e571*/ +if (!mbox_info->mbox) +return -ENOMEM ; + + mbox_info->buf_out =rte_zmalloc ("mbox_buf_out" , + (size_t )mbox_max_buf_sz,1 );/*lint !e571*/ +if (!mbox_info->buf_out) { + err = -ENOMEM ; + goto alloc_buf_out_err; + } + +return 0 ; + +alloc_buf_out_err: +rte_free (mbox_info->mbox); + +return err; +} + +static void +clean_mbox_info (struct hinic3_recv_mbox *mbox_info) +{ +rte_free (mbox_info->buf_out); +rte_free (mbox_info->mbox); +} + +static int +alloc_mbox_info (struct hinic3_recv_mbox *mbox_info,int mbox_max_buf_sz) +{ +u16 func_idx, i; +int err; + +for (func_idx =0 ; func_idx <HINIC3_MAX_FUNCTIONS +1 ; func_idx++) { + err =init_mbox_info (&mbox_info[func_idx], mbox_max_buf_sz); +if (err) { +PMD_DRV_LOG (ERR ,"Init mbox info failed" ); + goto init_mbox_info_err; + } + } + +return 0 ; + +init_mbox_info_err: +for (i =0 ; i < func_idx; i++) +clean_mbox_info (&mbox_info[i]); + +return err; +} + +static void +free_mbox_info (struct hinic3_recv_mbox *mbox_info) +{ +u16 func_idx; + +for (func_idx =0 ; func_idx <HINIC3_MAX_FUNCTIONS +1 ; func_idx++) +clean_mbox_info (&mbox_info[func_idx]); +} + +static void +prepare_send_mbox (struct hinic3_mbox *func_to_func) +{ +struct hinic3_send_mbox *send_mbox = &func_to_func->send_mbox; + + send_mbox->data =MBOX_AREA (func_to_func->hwdev->hwif); +} + +/** +* Allocate memory for the write-back state of the mailbox and write to +* register. +* +* @param[in] func_to_func +* Context for inter-function communication. +* @return +* 0 on success, non-zero on failure. +*/ +static int +alloc_mbox_wb_status (struct hinic3_mbox *func_to_func) +{ +struct hinic3_send_mbox *send_mbox = &func_to_func->send_mbox; +struct hinic3_hwdev *hwdev = func_to_func->hwdev; +u32 addr_h, addr_l; + +/* Reserved DMA area. */ + send_mbox->wb_mz =hinic3_dma_zone_reserve (hwdev->eth_dev, +"wb_mz" ,0 ,MBOX_WB_STATUS_LEN , +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +if (!send_mbox->wb_mz) +return -ENOMEM ; + + send_mbox->wb_vaddr = send_mbox->wb_mz->addr; + send_mbox->wb_paddr = send_mbox->wb_mz->iova; + send_mbox->wb_status = send_mbox->wb_vaddr; + + addr_h =upper_32_bits (send_mbox->wb_paddr); + addr_l =lower_32_bits (send_mbox->wb_paddr); + +/* Write info to the register. */ +hinic3_hwif_write_reg (hwdev->hwif,HINIC3_FUNC_CSR_MAILBOX_RESULT_H_OFF , + addr_h); +hinic3_hwif_write_reg (hwdev->hwif,HINIC3_FUNC_CSR_MAILBOX_RESULT_L_OFF , + addr_l); + +return 0 ; +} + +static void +free_mbox_wb_status (struct hinic3_mbox *func_to_func) +{ +struct hinic3_send_mbox *send_mbox = &func_to_func->send_mbox; +struct hinic3_hwdev *hwdev = func_to_func->hwdev; + +hinic3_hwif_write_reg (hwdev->hwif,HINIC3_FUNC_CSR_MAILBOX_RESULT_H_OFF , +0 ); +hinic3_hwif_write_reg (hwdev->hwif,HINIC3_FUNC_CSR_MAILBOX_RESULT_L_OFF , +0 ); + +hinic3_memzone_free (send_mbox->wb_mz); +} + +static int +alloc_mbox_tlp_buffer (struct hinic3_mbox *func_to_func) +{ +struct hinic3_send_mbox *send_mbox = &func_to_func->send_mbox; +struct hinic3_hwdev *hwdev = func_to_func->hwdev; + + send_mbox->sbuff_mz =hinic3_dma_zone_reserve (hwdev->eth_dev, +"sbuff_mz" ,0 ,MBOX_MAX_BUF_SZ ,MBOX_MAX_BUF_SZ , +SOCKET_ID_ANY ); +if (!send_mbox->sbuff_mz) +return -ENOMEM ; + + send_mbox->sbuff_vaddr = send_mbox->sbuff_mz->addr; + send_mbox->sbuff_paddr = send_mbox->sbuff_mz->iova; + +return 0 ; +} + +static void +free_mbox_tlp_buffer (struct hinic3_mbox *func_to_func) +{ +struct hinic3_send_mbox *send_mbox = &func_to_func->send_mbox; + +hinic3_memzone_free (send_mbox->sbuff_mz); +} + +/** +* Initialize function to function communication. +* +* @param[in] hwdev +* Pointer to hardware device structure. +* @return +* 0 on success, non-zero on failure. +*/ +int +hinic3_func_to_func_init (struct hinic3_hwdev *hwdev) +{ +struct hinic3_mbox *func_to_func; +int err; + + func_to_func =rte_zmalloc ("func_to_func" ,sizeof (*func_to_func),1 ); +if (!func_to_func) +return -ENOMEM ; + + hwdev->func_to_func = func_to_func; + func_to_func->hwdev = hwdev; + (void )hinic3_mutex_init (&func_to_func->mbox_send_mutex,NULL ); + (void )hinic3_mutex_init (&func_to_func->msg_send_mutex,NULL ); +rte_spinlock_init (&func_to_func->mbox_lock); + +/* Alloc the memory required by the mailbox. */ + err =alloc_mbox_info (func_to_func->mbox_send,MBOX_MAX_BUF_SZ ); +if (err) { +PMD_DRV_LOG (ERR ,"Alloc mem for mbox_active failed" ); + goto alloc_mbox_for_send_err; + } + + err =alloc_mbox_info (func_to_func->mbox_resp,MBOX_MAX_BUF_SZ ); +if (err) { +PMD_DRV_LOG (ERR ,"Alloc mem for mbox_passive failed" ); + goto alloc_mbox_for_resp_err; + } + + err =alloc_mbox_tlp_buffer (func_to_func); +if (err) { +PMD_DRV_LOG (ERR ,"Alloc mbox send buffer failed" ); + goto alloc_tlp_buffer_err; + } + + err =alloc_mbox_wb_status (func_to_func); +if (err) { +PMD_DRV_LOG (ERR ,"Alloc mbox write back status failed" ); + goto alloc_wb_status_err; + } + +prepare_send_mbox (func_to_func); + +return 0 ; + +alloc_wb_status_err: +free_mbox_tlp_buffer (func_to_func); + +alloc_tlp_buffer_err: +free_mbox_info (func_to_func->mbox_resp); + +alloc_mbox_for_resp_err: +free_mbox_info (func_to_func->mbox_send); + +alloc_mbox_for_send_err: + (void )hinic3_mutex_destroy (&func_to_func->msg_send_mutex); + (void )hinic3_mutex_destroy (&func_to_func->mbox_send_mutex); +rte_free (func_to_func); + +return err; +} + +void +hinic3_func_to_func_free (struct hinic3_hwdev *hwdev) +{ +struct hinic3_mbox *func_to_func = hwdev->func_to_func; + +free_mbox_wb_status (func_to_func); +free_mbox_tlp_buffer (func_to_func); +free_mbox_info (func_to_func->mbox_resp); +free_mbox_info (func_to_func->mbox_send); + (void )hinic3_mutex_destroy (&func_to_func->mbox_send_mutex); + (void )hinic3_mutex_destroy (&func_to_func->msg_send_mutex); + +rte_free (func_to_func); +}
drivers/net/hinic3/base/hinic3_mbox.h new file +199 -0
199 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 12/18 net/hinic3: add device initailization
In reply to Feifei WangFrom: Xin Wang <[email protected]>
This patch contains data structures and function codes related to device initialization.
--- drivers/net/hinic3/hinic3_ethdev.c | 514 +++++++++++++++++++++++++++++ drivers/net/hinic3/hinic3_ethdev.h | 119 +++++++ 2 files changed, 633 insertions(+) create mode 100644 drivers/net/hinic3/hinic3_ethdev.c create mode 100644 drivers/net/hinic3/hinic3_ethdev.h
drivers/net/hinic3/hinic3_ethdev.c new file +514 -0
@@ -0,0 +1,514 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Huawei Technologies Co., Ltd +*/ + +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_mbuf.h> +#include <rte_malloc.h> +#include <rte_mempool.h> +#include <rte_errno.h> +#include <rte_ether.h> + +#include "base/hinic3_compat.h" +#include "base/hinic3_csr.h" +#include "base/hinic3_wq.h" +#include "base/hinic3_eqs.h" +#include "base/hinic3_cmdq.h" +#include "base/hinic3_hwdev.h" +#include "base/hinic3_hwif.h" +#include "base/hinic3_hw_cfg.h" +#include "base/hinic3_hw_comm.h" +#include "base/hinic3_nic_cfg.h" +#include "base/hinic3_nic_event.h" +#include "hinic3_ethdev.h" + +/** +* Interrupt handler triggered by NIC for handling specific event. +* +* @param[in] param +* The address of parameter (struct rte_eth_dev *) regsitered before. +*/ +static void +hinic3_dev_interrupt_handler (void *param) +{ +struct rte_eth_dev *dev = param; +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +if (!hinic3_get_bit (HINIC3_DEV_INTR_EN , &nic_dev->dev_status)) { +PMD_DRV_LOG (WARNING , +"Intr is disabled, ignore intr event, " +"dev_name: %s, port_id: %d" , + nic_dev->dev_name, dev->data->port_id); +return ; + } + +/* Aeq0 msg handler. */ +hinic3_dev_handle_aeq_event (nic_dev->hwdev, param); +} + +static void +hinic3_deinit_sw_rxtxqs (struct hinic3_nic_dev *nic_dev) +{ +rte_free (nic_dev->txqs); + nic_dev->txqs =NULL ; + +rte_free (nic_dev->rxqs); + nic_dev->rxqs =NULL ; +} + +/** +* Init mac_vlan table in hardwares. +* +* @param[in] eth_dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_init_mac_table (struct rte_eth_dev *eth_dev) +{ +struct hinic3_nic_dev *nic_dev = +HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +u8 addr_bytes[RTE_ETHER_ADDR_LEN ]; +u16 func_id =0 ; +int err =0 ; + + err =hinic3_get_default_mac (nic_dev->hwdev, addr_bytes, +RTE_ETHER_ADDR_LEN ); +if (err) +return err; + +rte_ether_addr_copy ((struct rte_ether_addr *)addr_bytes, + ð_dev->data->mac_addrs[0 ]); +if (rte_is_zero_ether_addr (ð_dev->data->mac_addrs[0 ])) +rte_eth_random_addr (eth_dev->data->mac_addrs[0 ].addr_bytes); + + func_id =hinic3_global_func_id (nic_dev->hwdev); + err =hinic3_set_mac (nic_dev->hwdev, + eth_dev->data->mac_addrs[0 ].addr_bytes,0 , + func_id); +if (err && err !=HINIC3_PF_SET_VF_ALREADY ) +return err; + +rte_ether_addr_copy (ð_dev->data->mac_addrs[0 ], + &nic_dev->default_addr); + +return 0 ; +} + +/** +* Deinit mac_vlan table in hardware. +* +* @param[in] eth_dev +* Pointer to ethernet device structure. +*/ +static void +hinic3_deinit_mac_addr (struct rte_eth_dev *eth_dev) +{ +struct hinic3_nic_dev *nic_dev = +HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +u16 func_id =0 ; +int err; +int i; + + func_id =hinic3_global_func_id (nic_dev->hwdev); + +for (i =0 ; i <HINIC3_MAX_UC_MAC_ADDRS ; i++) { +if (rte_is_zero_ether_addr (ð_dev->data->mac_addrs[i])) +continue ; + + err =hinic3_del_mac (nic_dev->hwdev, + eth_dev->data->mac_addrs[i].addr_bytes,0 , + func_id); +if (err && err !=HINIC3_PF_SET_VF_ALREADY ) +PMD_DRV_LOG (ERR , +"Delete mac table failed, dev_name: %s" , + eth_dev->data->name); + +memset (ð_dev->data->mac_addrs[i],0 , +sizeof (struct rte_ether_addr )); + } + +/* Delete multicast mac addrs. */ +hinic3_delete_mc_addr_list (nic_dev); +} + +/** +* Check the valid CoS bitmap to determine the available CoS IDs and set +* the default CoS ID to the highest valid one. +* +* @param[in] hwdev +* Pointer to hardware device structure. +* @param[out] cos_id +* Pointer to store the default CoS ID. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_pf_get_default_cos (struct hinic3_hwdev *hwdev,u8 *cos_id) +{ +u8 default_cos =0 ; +u8 valid_cos_bitmap; +u8 i; + + valid_cos_bitmap = hwdev->cfg_mgmt->svc_cap.cos_valid_bitmap; +if (!valid_cos_bitmap) { +PMD_DRV_LOG (ERR ,"PF has none cos to support" ); +return -EFAULT ; + } + +for (i =0 ; i <HINIC3_COS_NUM_MAX ; i++) { +if (valid_cos_bitmap &BIT (i)) +/* Find max cos id as default cos. */ + default_cos = i; + } + + *cos_id = default_cos; + +return 0 ; +} + +static int +hinic3_init_default_cos (struct hinic3_nic_dev *nic_dev) +{ +u8 cos_id =0 ; +int err; + +if (!HINIC3_IS_VF (nic_dev->hwdev)) { + err =hinic3_pf_get_default_cos (nic_dev->hwdev, &cos_id); +if (err) { +PMD_DRV_LOG (ERR ,"Get PF default cos failed, err: %d" , + err); +return err; + } + }else { + err =hinic3_vf_get_default_cos (nic_dev->hwdev, &cos_id); +if (err) { +PMD_DRV_LOG (ERR ,"Get VF default cos failed, err: %d" , + err); +return err; + } + } + + nic_dev->default_cos = cos_id; +PMD_DRV_LOG (INFO ,"Default cos %d" , nic_dev->default_cos); +return 0 ; +} + +/** +* Initialize Class of Service (CoS). For PF devices, it also sync the link +* status with the physical port. +* +* @param[in] nic_dev +* Pointer to NIC device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_set_default_hw_feature (struct hinic3_nic_dev *nic_dev) +{ +int err; + + err =hinic3_init_default_cos (nic_dev); +if (err) +return err; + +if (hinic3_func_type (nic_dev->hwdev) ==TYPE_VF ) +return 0 ; + + err =hinic3_set_link_status_follow (nic_dev->hwdev, +HINIC3_LINK_FOLLOW_PORT ); +if (err ==HINIC3_MGMT_CMD_UNSUPPORTED ) +PMD_DRV_LOG (WARNING ,"Don't support to set link status follow " +"phy port status" ); +else if (err) +return err; + +return 0 ; +} + +/** +* Initialize the network function, including hardware configuration, memory +* allocation for data structures, MAC address setup, and interrupt enabling. +* It also registers interrupt callbacks and sets default hardware features. +* If any step fails, appropriate cleanup is performed. +* +* @param[out] eth_dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_func_init (struct rte_eth_dev *eth_dev) +{ +struct hinic3_tcam_info *tcam_info =NULL ; +struct hinic3_nic_dev *nic_dev =NULL ; +struct rte_pci_device *pci_dev =NULL ; +int err; + + pci_dev =RTE_ETH_DEV_TO_PCI (eth_dev); + +/* EAL is secondary and eth_dev is already created. */ +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { +PMD_DRV_LOG (INFO ,"Initialize %s in secondary process" , + eth_dev->data->name); + +return 0 ; + } + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +memset (nic_dev,0 ,sizeof (*nic_dev)); + (void )snprintf (nic_dev->dev_name,sizeof (nic_dev->dev_name), +"dbdf-%.4x:%.2x:%.2x.%x" , pci_dev->addr.domain, + pci_dev->addr.bus, pci_dev->addr.devid, + pci_dev->addr.function); + +/* Alloc mac_addrs. */ + eth_dev->data->mac_addrs =rte_zmalloc ("hinic3_mac" , +HINIC3_MAX_UC_MAC_ADDRS *sizeof (struct rte_ether_addr ),0 ); +if (!eth_dev->data->mac_addrs) { +PMD_DRV_LOG (ERR , +"Allocate %zx bytes to store MAC addresses " +"failed, dev_name: %s" , +HINIC3_MAX_UC_MAC_ADDRS * +sizeof (struct rte_ether_addr ), + eth_dev->data->name); + err = -ENOMEM ; + goto alloc_eth_addr_fail; + } + + nic_dev->mc_list =rte_zmalloc ("hinic3_mc" , +HINIC3_MAX_MC_MAC_ADDRS *sizeof (struct rte_ether_addr ),0 ); +if (!nic_dev->mc_list) { +PMD_DRV_LOG (ERR , +"Allocate %zx bytes to store multicast " +"addresses failed, dev_name: %s" , +HINIC3_MAX_MC_MAC_ADDRS * +sizeof (struct rte_ether_addr ), + eth_dev->data->name); + err = -ENOMEM ; + goto alloc_mc_list_fail; + } + +/* Create hardware device. */ + nic_dev->hwdev =rte_zmalloc ("hinic3_hwdev" ,sizeof (*nic_dev->hwdev), +RTE_CACHE_LINE_SIZE ); +if (!nic_dev->hwdev) { +PMD_DRV_LOG (ERR ,"Allocate hwdev memory failed, dev_name: %s" , + eth_dev->data->name); + err = -ENOMEM ; + goto alloc_hwdev_mem_fail; + } + nic_dev->hwdev->pci_dev =RTE_ETH_DEV_TO_PCI (eth_dev); + nic_dev->hwdev->dev_handle = nic_dev; + nic_dev->hwdev->eth_dev = eth_dev; + nic_dev->hwdev->port_id = eth_dev->data->port_id; + + err =hinic3_init_hwdev (nic_dev->hwdev); +if (err) { +PMD_DRV_LOG (ERR ,"Init chip hwdev failed, dev_name: %s" , + eth_dev->data->name); + goto init_hwdev_fail; + } + + nic_dev->max_sqs =hinic3_func_max_sqs (nic_dev->hwdev); + nic_dev->max_rqs =hinic3_func_max_rqs (nic_dev->hwdev); + + err =hinic3_init_nic_hwdev (nic_dev->hwdev); +if (err) { +PMD_DRV_LOG (ERR ,"Init nic hwdev failed, dev_name: %s" , + eth_dev->data->name); + goto init_nic_hwdev_fail; + } + + err =hinic3_get_feature_from_hw (nic_dev->hwdev, &nic_dev->feature_cap, +1 ); +if (err) { +PMD_DRV_LOG (ERR , +"Get nic feature from hardware failed, dev_name: %s" , + eth_dev->data->name); + goto get_cap_fail; + } + + err =hinic3_init_sw_rxtxqs (nic_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Init sw rxqs or txqs failed, dev_name: %s" , + eth_dev->data->name); + goto init_sw_rxtxqs_fail; + } + + err =hinic3_init_mac_table (eth_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Init mac table failed, dev_name: %s" , + eth_dev->data->name); + goto init_mac_table_fail; + } + +/* Set hardware feature to default status. */ + err =hinic3_set_default_hw_feature (nic_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Set hw default features failed, dev_name: %s" , + eth_dev->data->name); + goto set_default_feature_fail; + } + +/* Register callback func to eal lib. */ + err =rte_intr_callback_register (PCI_DEV_TO_INTR_HANDLE (pci_dev), + hinic3_dev_interrupt_handler, + (void *)eth_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Register intr callback failed, dev_name: %s" , + eth_dev->data->name); + goto reg_intr_cb_fail; + } + +/* Enable uio/vfio intr/eventfd mapping. */ + err =rte_intr_enable (PCI_DEV_TO_INTR_HANDLE (pci_dev)); +if (err) { +PMD_DRV_LOG (ERR ,"Enable rte interrupt failed, dev_name: %s" , + eth_dev->data->name); + goto enable_intr_fail; + } + tcam_info = &nic_dev->tcam; +memset (tcam_info,0 ,sizeof (struct hinic3_tcam_info )); +TAILQ_INIT (&tcam_info->tcam_list); +TAILQ_INIT (&tcam_info->tcam_dynamic_info.tcam_dynamic_list); +TAILQ_INIT (&nic_dev->filter_ethertype_list); +TAILQ_INIT (&nic_dev->filter_fdir_rule_list); + +hinic3_mutex_init (&nic_dev->rx_mode_mutex,NULL ); + +hinic3_set_bit (HINIC3_DEV_INTR_EN , &nic_dev->dev_status); + +hinic3_set_bit (HINIC3_DEV_INIT , &nic_dev->dev_status); +PMD_DRV_LOG (INFO ,"Initialize %s in primary succeed" , + eth_dev->data->name); + +/** +* Queue xstats filled automatically by ethdev layer. +*/ + eth_dev->data->dev_flags |=RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS ; + +return 0 ; + +enable_intr_fail: + (void )rte_intr_callback_unregister (PCI_DEV_TO_INTR_HANDLE (pci_dev), + hinic3_dev_interrupt_handler, + (void *)eth_dev); + +reg_intr_cb_fail: +set_default_feature_fail: +hinic3_deinit_mac_addr (eth_dev); + +init_mac_table_fail: +hinic3_deinit_sw_rxtxqs (nic_dev); + +init_sw_rxtxqs_fail: +hinic3_free_nic_hwdev (nic_dev->hwdev); + +get_cap_fail: +init_nic_hwdev_fail: +hinic3_free_hwdev (nic_dev->hwdev); + eth_dev->dev_ops =NULL ; + eth_dev->rx_queue_count =NULL ; + eth_dev->rx_descriptor_status =NULL ; + eth_dev->tx_descriptor_status =NULL ; + +init_hwdev_fail: +rte_free (nic_dev->hwdev); + nic_dev->hwdev =NULL ; + +alloc_hwdev_mem_fail: +rte_free (nic_dev->mc_list); + nic_dev->mc_list =NULL ; + +alloc_mc_list_fail: +rte_free (eth_dev->data->mac_addrs); + eth_dev->data->mac_addrs =NULL ; + +alloc_eth_addr_fail: +PMD_DRV_LOG (ERR ,"Initialize %s in primary failed" , + eth_dev->data->name); +return err; +} + +static int +hinic3_dev_init (struct rte_eth_dev *eth_dev) +{ +struct rte_pci_device *pci_dev; + + pci_dev =RTE_ETH_DEV_TO_PCI (eth_dev); + +PMD_DRV_LOG (INFO ,"Initializing %.4x:%.2x:%.2x.%x in %s process" , + pci_dev->addr.domain, pci_dev->addr.bus, + pci_dev->addr.devid, pci_dev->addr.function, + (rte_eal_process_type () ==RTE_PROC_PRIMARY ) ?"primary" + :"secondary" ); + +PMD_DRV_LOG (INFO ,"Network Interface pmd driver version: %s" , +HINIC3_PMD_DRV_VERSION ); + +return hinic3_func_init (eth_dev); +} + +static int +hinic3_dev_uninit (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +hinic3_clear_bit (HINIC3_DEV_INIT , &nic_dev->dev_status); + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) +return 0 ; + +return hinic3_dev_close (dev); +} + +static const struct rte_pci_id pci_id_hinic3_map[] = { +#ifdef CONFIG_SP_VID_DID + {RTE_PCI_DEVICE (PCI_VENDOR_ID_SPNIC ,HINIC3_DEV_ID_STANDARD )}, + {RTE_PCI_DEVICE (PCI_VENDOR_ID_SPNIC ,HINIC3_DEV_ID_VF )}, +#else + {RTE_PCI_DEVICE (PCI_VENDOR_ID_HUAWEI ,HINIC3_DEV_ID_STANDARD )}, + {RTE_PCI_DEVICE (PCI_VENDOR_ID_HUAWEI ,HINIC3_DEV_ID_VF )}, +#endif + + {.vendor_id =0 }, +}; + +static int +hinic3_pci_probe(__rte_unused struct rte_pci_driver *pci_drv, +struct rte_pci_device *pci_dev) +{ +return rte_eth_dev_pci_generic_probe (pci_dev, +sizeof (struct hinic3_nic_dev ), hinic3_dev_init); +} + +static int +hinic3_pci_remove (struct rte_pci_device *pci_dev) +{ +return rte_eth_dev_pci_generic_remove (pci_dev, hinic3_dev_uninit); +} + +static struct rte_pci_driver rte_hinic3_pmd = { + .id_table = pci_id_hinic3_map, + .drv_flags =RTE_PCI_DRV_NEED_MAPPING |RTE_PCI_DRV_INTR_LSC , + .probe = hinic3_pci_probe, + .remove = hinic3_pci_remove, +}; + +RTE_PMD_REGISTER_PCI (net_hinic3, rte_hinic3_pmd); +RTE_PMD_REGISTER_PCI_TABLE (net_hinic3, pci_id_hinic3_map); + +RTE_INIT (hinic3_init_log) +{ + hinic3_logtype =rte_log_register ("pmd.net.hinic3" ); +if (hinic3_logtype >=0 ) +rte_log_set_level (hinic3_logtype,RTE_LOG_INFO ); +}
drivers/net/hinic3/hinic3_ethdev.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 13/18 net/hinic3: add dev ops
In reply to Feifei WangFrom: Feifei Wang <[email protected]>
Add ops related function codes.
--- drivers/net/hinic3/hinic3_ethdev.c | 2918 +++++++++++++++++++++++++++- drivers/net/hinic3/hinic3_nic_io.c | 827 ++++++++ drivers/net/hinic3/hinic3_nic_io.h | 169 ++ drivers/net/hinic3/hinic3_rx.c | 811 ++++++++ drivers/net/hinic3/hinic3_rx.h | 356 ++++ drivers/net/hinic3/hinic3_tx.c | 274 +++ drivers/net/hinic3/hinic3_tx.h | 314 +++ 7 files changed, 5652 insertions(+), 17 deletions(-) create mode 100644 drivers/net/hinic3/hinic3_nic_io.c create mode 100644 drivers/net/hinic3/hinic3_nic_io.h create mode 100644 drivers/net/hinic3/hinic3_rx.c create mode 100644 drivers/net/hinic3/hinic3_rx.h create mode 100644 drivers/net/hinic3/hinic3_tx.c create mode 100644 drivers/net/hinic3/hinic3_tx.h
drivers/net/hinic3/hinic3_ethdev.c +2901 -17
@@ -21,42 +21,2917 @@#include "base/hinic3_hw_comm.h" #include "base/hinic3_nic_cfg.h" #include "base/hinic3_nic_event.h" +#include "hinic3_pmd_nic_io.h" +#include "hinic3_pmd_tx.h" +#include "hinic3_pmd_rx.h" #include "hinic3_ethdev.h" +#define HINIC3_MIN_RX_BUF_SIZE 1024 + +#define HINIC3_DEFAULT_BURST_SIZE 32 +#define HINIC3_DEFAULT_NB_QUEUES 1 +#define HINIC3_DEFAULT_RING_SIZE 1024 +#define HINIC3_MAX_LRO_SIZE 65536 + +#define HINIC3_DEFAULT_RX_FREE_THRESH 32 +#define HINIC3_DEFAULT_TX_FREE_THRESH 32 + +#define HINIC3_RX_WAIT_CYCLE_THRESH 500 + +/** +* Get the 32-bit VFTA bit mask for the lower 5 bits of the VLAN ID. +* +* Vlan_id is a 12 bit number. The VFTA array is actually a 4096 bit array, +* 128 of 32bit elements. 2^5 = 32. The val of lower 5 bits specifies the bit +* in the 32bit element. The higher 7 bit val specifies VFTA array index. +*/ +#define HINIC3_VFTA_BIT (vlan_id) (1 << ((vlan_id) & 0x1F)) +/** +* Get the VFTA index from the upper 7 bits of the VLAN ID. +*/ +#define HINIC3_VFTA_IDX (vlan_id) ((vlan_id) >> 5) + +#define HINIC3_LRO_DEFAULT_TIME_LIMIT 16 +#define HINIC3_LRO_UNIT_WQE_SIZE 1024/**< Bytes. */ + +#define HINIC3_MAX_RX_PKT_LEN (rxmod) ((rxmod).mtu) +int hinic3_logtype;/**< Driver-specific log messages type. */ + +/** +* The different receive modes for the NIC. +* +* The receive modes are represented as bit flags that control how the +* NIC handles various types of network traffic. +*/ +enum hinic3_rx_mod { +/* Enable unicast receive mode. */ +HINIC3_RX_MODE_UC =1 <<0 , +/* Enable multicast receive mode. */ +HINIC3_RX_MODE_MC =1 <<1 , +/* Enable broadcast receive mode. */ +HINIC3_RX_MODE_BC =1 <<2 , +/* Enable receive mode for all multicast addresses. */ +HINIC3_RX_MODE_MC_ALL =1 <<3 , +/* Enable promiscuous mode, receiving all packets. */ +HINIC3_RX_MODE_PROMISC =1 <<4 , +}; + +#define HINIC3_DEFAULT_RX_MODE \ + (HINIC3_RX_MODE_UC | HINIC3_RX_MODE_MC | HINIC3_RX_MODE_BC) + +struct hinic3_xstats_name_off { +char name[RTE_ETH_XSTATS_NAME_SIZE ]; +u32 offset; +}; + +#define HINIC3_FUNC_STAT (_stat_item) \ + { \ + .name = #_stat_item, \ + .offset = offsetof(struct hinic3_vport_stats, _stat_item), \ + } + +static const struct hinic3_xstats_name_off hinic3_vport_stats_strings[] = { +HINIC3_FUNC_STAT (tx_unicast_pkts_vport), +HINIC3_FUNC_STAT (tx_unicast_bytes_vport), +HINIC3_FUNC_STAT (tx_multicast_pkts_vport), +HINIC3_FUNC_STAT (tx_multicast_bytes_vport), +HINIC3_FUNC_STAT (tx_broadcast_pkts_vport), +HINIC3_FUNC_STAT (tx_broadcast_bytes_vport), + +HINIC3_FUNC_STAT (rx_unicast_pkts_vport), +HINIC3_FUNC_STAT (rx_unicast_bytes_vport), +HINIC3_FUNC_STAT (rx_multicast_pkts_vport), +HINIC3_FUNC_STAT (rx_multicast_bytes_vport), +HINIC3_FUNC_STAT (rx_broadcast_pkts_vport), +HINIC3_FUNC_STAT (rx_broadcast_bytes_vport), + +HINIC3_FUNC_STAT (tx_discard_vport), +HINIC3_FUNC_STAT (rx_discard_vport), +HINIC3_FUNC_STAT (tx_err_vport), +HINIC3_FUNC_STAT (rx_err_vport), +}; + +#define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) + +#define HINIC3_VPORT_XSTATS_NUM ARRAY_SIZE(hinic3_vport_stats_strings) + +#define HINIC3_PORT_STAT (_stat_item) \ + { \ + .name = #_stat_item, \ + .offset = offsetof(struct mag_phy_port_stats, _stat_item), \ + } + +static const struct hinic3_xstats_name_off hinic3_phyport_stats_strings[] = { +HINIC3_PORT_STAT (mac_tx_fragment_pkt_num), +HINIC3_PORT_STAT (mac_tx_undersize_pkt_num), +HINIC3_PORT_STAT (mac_tx_undermin_pkt_num), +HINIC3_PORT_STAT (mac_tx_64_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_65_127_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_128_255_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_256_511_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_512_1023_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_1024_1518_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_1519_2047_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_2048_4095_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_4096_8191_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_8192_9216_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_9217_12287_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_12288_16383_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_1519_max_bad_pkt_num), +HINIC3_PORT_STAT (mac_tx_1519_max_good_pkt_num), +HINIC3_PORT_STAT (mac_tx_oversize_pkt_num), +HINIC3_PORT_STAT (mac_tx_jabber_pkt_num), +HINIC3_PORT_STAT (mac_tx_bad_pkt_num), +HINIC3_PORT_STAT (mac_tx_bad_oct_num), +HINIC3_PORT_STAT (mac_tx_good_pkt_num), +HINIC3_PORT_STAT (mac_tx_good_oct_num), +HINIC3_PORT_STAT (mac_tx_total_pkt_num), +HINIC3_PORT_STAT (mac_tx_total_oct_num), +HINIC3_PORT_STAT (mac_tx_uni_pkt_num), +HINIC3_PORT_STAT (mac_tx_multi_pkt_num), +HINIC3_PORT_STAT (mac_tx_broad_pkt_num), +HINIC3_PORT_STAT (mac_tx_pause_num), +HINIC3_PORT_STAT (mac_tx_pfc_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri0_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri1_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri2_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri3_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri4_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri5_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri6_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri7_pkt_num), +HINIC3_PORT_STAT (mac_tx_control_pkt_num), +HINIC3_PORT_STAT (mac_tx_err_all_pkt_num), +HINIC3_PORT_STAT (mac_tx_from_app_good_pkt_num), +HINIC3_PORT_STAT (mac_tx_from_app_bad_pkt_num), + +HINIC3_PORT_STAT (mac_rx_fragment_pkt_num), +HINIC3_PORT_STAT (mac_rx_undersize_pkt_num), +HINIC3_PORT_STAT (mac_rx_undermin_pkt_num), +HINIC3_PORT_STAT (mac_rx_64_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_65_127_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_128_255_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_256_511_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_512_1023_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_1024_1518_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_1519_2047_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_2048_4095_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_4096_8191_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_8192_9216_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_9217_12287_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_12288_16383_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_1519_max_bad_pkt_num), +HINIC3_PORT_STAT (mac_rx_1519_max_good_pkt_num), +HINIC3_PORT_STAT (mac_rx_oversize_pkt_num), +HINIC3_PORT_STAT (mac_rx_jabber_pkt_num), +HINIC3_PORT_STAT (mac_rx_bad_pkt_num), +HINIC3_PORT_STAT (mac_rx_bad_oct_num), +HINIC3_PORT_STAT (mac_rx_good_pkt_num), +HINIC3_PORT_STAT (mac_rx_good_oct_num), +HINIC3_PORT_STAT (mac_rx_total_pkt_num), +HINIC3_PORT_STAT (mac_rx_total_oct_num), +HINIC3_PORT_STAT (mac_rx_uni_pkt_num), +HINIC3_PORT_STAT (mac_rx_multi_pkt_num), +HINIC3_PORT_STAT (mac_rx_broad_pkt_num), +HINIC3_PORT_STAT (mac_rx_pause_num), +HINIC3_PORT_STAT (mac_rx_pfc_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri0_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri1_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri2_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri3_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri4_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri5_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri6_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri7_pkt_num), +HINIC3_PORT_STAT (mac_rx_control_pkt_num), +HINIC3_PORT_STAT (mac_rx_sym_err_pkt_num), +HINIC3_PORT_STAT (mac_rx_fcs_err_pkt_num), +HINIC3_PORT_STAT (mac_rx_send_app_good_pkt_num), +HINIC3_PORT_STAT (mac_rx_send_app_bad_pkt_num), +HINIC3_PORT_STAT (mac_rx_unfilter_pkt_num), +}; + +#define HINIC3_PHYPORT_XSTATS_NUM ARRAY_SIZE(hinic3_phyport_stats_strings) + +#define HINIC3_RXQ_STAT (_stat_item) \ + { \ + .name = #_stat_item, \ + .offset = offsetof(struct hinic3_rxq_stats, _stat_item), \ + } + +/** +* The name and offset field of RXQ statistic items. +* +* The inclusion of additional statistics depends on the compilation flags: +* - `HINIC3_XSTAT_RXBUF_INFO` enables buffer-related stats. +* - `HINIC3_XSTAT_PROF_RX` enables performance timing stats. +* - `HINIC3_XSTAT_MBUF_USE` enables memory buffer usage stats. +*/ +static const struct hinic3_xstats_name_off hinic3_rxq_stats_strings[] = { +HINIC3_RXQ_STAT (rx_nombuf), +HINIC3_RXQ_STAT (burst_pkts), +HINIC3_RXQ_STAT (errors), +HINIC3_RXQ_STAT (csum_errors), +HINIC3_RXQ_STAT (other_errors), +HINIC3_RXQ_STAT (empty), + +#ifdef HINIC3_XSTAT_RXBUF_INFO +HINIC3_RXQ_STAT (rx_mbuf), +HINIC3_RXQ_STAT (rx_avail), +HINIC3_RXQ_STAT (rx_hole), +#endif + +#ifdef HINIC3_XSTAT_PROF_RX +HINIC3_RXQ_STAT (app_tsc), +HINIC3_RXQ_STAT (pmd_tsc), +#endif + +#ifdef HINIC3_XSTAT_MBUF_USE +HINIC3_RXQ_STAT (rx_alloc_mbuf_bytes), +HINIC3_RXQ_STAT (rx_free_mbuf_bytes), +HINIC3_RXQ_STAT (rx_left_mbuf_bytes), +#endif +}; + +#define HINIC3_RXQ_XSTATS_NUM ARRAY_SIZE(hinic3_rxq_stats_strings) + +#define HINIC3_TXQ_STAT (_stat_item) \ + { \ + .name = #_stat_item, \ + .offset = offsetof(struct hinic3_txq_stats, _stat_item), \ + } + +/** +* The name and offset field of TXQ statistic items. +* +* The inclusion of additional statistics depends on the compilation flags: +* - `HINIC3_XSTAT_PROF_TX` enables performance timing stats. +* - `HINIC3_XSTAT_MBUF_USE` enables memory buffer usage stats. +*/ +static const struct hinic3_xstats_name_off hinic3_txq_stats_strings[] = { +HINIC3_TXQ_STAT (tx_busy), +HINIC3_TXQ_STAT (offload_errors), +HINIC3_TXQ_STAT (burst_pkts), +HINIC3_TXQ_STAT (sge_len0), +HINIC3_TXQ_STAT (mbuf_null), + +#ifdef HINIC3_XSTAT_PROF_TX +HINIC3_TXQ_STAT (app_tsc), +HINIC3_TXQ_STAT (pmd_tsc), +#endif + +#ifdef HINIC3_XSTAT_MBUF_USE +HINIC3_TXQ_STAT (tx_left_mbuf_bytes), +#endif +}; + +#define HINIC3_TXQ_XSTATS_NUM ARRAY_SIZE(hinic3_txq_stats_strings) + +static int +hinic3_xstats_calc_num (struct hinic3_nic_dev *nic_dev) +{ +if (HINIC3_IS_VF (nic_dev->hwdev)) { +return (HINIC3_VPORT_XSTATS_NUM + +HINIC3_RXQ_XSTATS_NUM * nic_dev->num_rqs + +HINIC3_TXQ_XSTATS_NUM * nic_dev->num_sqs); + }else { +return (HINIC3_VPORT_XSTATS_NUM +HINIC3_PHYPORT_XSTATS_NUM + +HINIC3_RXQ_XSTATS_NUM * nic_dev->num_rqs + +HINIC3_TXQ_XSTATS_NUM * nic_dev->num_sqs); + } +} + +#define HINIC3_MAX_QUEUE_DEPTH 16384 +#define HINIC3_MIN_QUEUE_DEPTH 128 +#define HINIC3_TXD_ALIGN 1 +#define HINIC3_RXD_ALIGN 1 + +static const struct rte_eth_desc_lim hinic3_rx_desc_lim = { + .nb_max =HINIC3_MAX_QUEUE_DEPTH , + .nb_min =HINIC3_MIN_QUEUE_DEPTH , + .nb_align =HINIC3_RXD_ALIGN , +}; + +static const struct rte_eth_desc_lim hinic3_tx_desc_lim = { + .nb_max =HINIC3_MAX_QUEUE_DEPTH , + .nb_min =HINIC3_MIN_QUEUE_DEPTH , + .nb_align =HINIC3_TXD_ALIGN , +}; + +static void hinic3_deinit_mac_addr (struct rte_eth_dev *eth_dev); + +static int hinic3_copy_mempool_init (struct hinic3_nic_dev *nic_dev); + +static void hinic3_copy_mempool_uninit (struct hinic3_nic_dev *nic_dev); + +/** +* Interrupt handler triggered by NIC for handling specific event. +* +* @param[in] param +* The address of parameter (struct rte_eth_dev *) regsitered before. +*/ +static void +hinic3_dev_interrupt_handler (void *param) +{ +struct rte_eth_dev *dev = param; +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +if (!hinic3_get_bit (HINIC3_DEV_INTR_EN , &nic_dev->dev_status)) { +PMD_DRV_LOG (WARNING , +"Intr is disabled, ignore intr event, " +"dev_name: %s, port_id: %d" , + nic_dev->dev_name, dev->data->port_id); +return ; + } + +/* Aeq0 msg handler. */ +hinic3_dev_handle_aeq_event (nic_dev->hwdev, param); +} + +/** +* Do the config for TX/Rx queues, include queue number, mtu size and RSS. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_configure (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + + nic_dev->num_sqs = dev->data->nb_tx_queues; + nic_dev->num_rqs = dev->data->nb_rx_queues; + +if (nic_dev->num_sqs > nic_dev->max_sqs || + nic_dev->num_rqs > nic_dev->max_rqs) { +PMD_DRV_LOG (ERR , +"num_sqs: %d or num_rqs: %d larger than " +"max_sqs: %d or max_rqs: %d" , + nic_dev->num_sqs, nic_dev->num_rqs, + nic_dev->max_sqs, nic_dev->max_rqs); +return -EINVAL ; + } + +/* The range of mtu is 384~9600. */ + +if (HINIC3_MAX_RX_PKT_LEN (dev->data->dev_conf.rxmode) < +HINIC3_MIN_FRAME_SIZE || +HINIC3_MAX_RX_PKT_LEN (dev->data->dev_conf.rxmode) > +HINIC3_MAX_JUMBO_FRAME_SIZE ) { +PMD_DRV_LOG (ERR , +"Max rx pkt len out of range, max_rx_pkt_len: %d, " +"expect between %d and %d" , +HINIC3_MAX_RX_PKT_LEN (dev->data->dev_conf.rxmode), +HINIC3_MIN_FRAME_SIZE ,HINIC3_MAX_JUMBO_FRAME_SIZE ); +return -EINVAL ; + } + nic_dev->mtu_size = + (u16 )HINIC3_PKTLEN_TO_MTU (HINIC3_MAX_RX_PKT_LEN (dev->data->dev_conf.rxmode)); +if (dev->data->dev_conf.rxmode.mq_mode &RTE_ETH_MQ_RX_RSS_FLAG ) + dev->data->dev_conf.rxmode.offloads |= +RTE_ETH_RX_OFFLOAD_RSS_HASH ; + +/* Clear fdir filter. */ +hinic3_free_fdir_filter (dev); + +return 0 ; +} + +/** +* Get information about the device. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[out] info +* Info structure for ethernet device. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_infos_get (struct rte_eth_dev *dev,struct rte_eth_dev_info *info) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + + info->max_rx_queues = nic_dev->max_rqs; + info->max_tx_queues = nic_dev->max_sqs; + info->min_rx_bufsize =HINIC3_MIN_RX_BUF_SIZE ; + info->max_rx_pktlen =HINIC3_MAX_JUMBO_FRAME_SIZE ; + info->max_mac_addrs =HINIC3_MAX_UC_MAC_ADDRS ; + info->min_mtu =HINIC3_MIN_MTU_SIZE ; + info->max_mtu =HINIC3_MAX_MTU_SIZE ; + info->max_lro_pkt_size =HINIC3_MAX_LRO_SIZE ; + + info->rx_queue_offload_capa =0 ; + info->rx_offload_capa = +RTE_ETH_RX_OFFLOAD_VLAN_STRIP |RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | +RTE_ETH_RX_OFFLOAD_UDP_CKSUM |RTE_ETH_RX_OFFLOAD_TCP_CKSUM | +RTE_ETH_RX_OFFLOAD_SCTP_CKSUM |RTE_ETH_RX_OFFLOAD_VLAN_FILTER | +RTE_ETH_RX_OFFLOAD_SCATTER |RTE_ETH_RX_OFFLOAD_TCP_LRO | +RTE_ETH_RX_OFFLOAD_RSS_HASH ; + + info->tx_queue_offload_capa =0 ; + info->tx_offload_capa = +RTE_ETH_TX_OFFLOAD_VLAN_INSERT |RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | +RTE_ETH_TX_OFFLOAD_UDP_CKSUM |RTE_ETH_TX_OFFLOAD_TCP_CKSUM | +RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | +RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM | +RTE_ETH_TX_OFFLOAD_TCP_TSO |RTE_ETH_TX_OFFLOAD_MULTI_SEGS ; + + info->hash_key_size =HINIC3_RSS_KEY_SIZE ; + info->reta_size =HINIC3_RSS_INDIR_SIZE ; + info->flow_type_rss_offloads =HINIC3_RSS_OFFLOAD_ALL ; + + info->rx_desc_lim = hinic3_rx_desc_lim; + info->tx_desc_lim = hinic3_tx_desc_lim; + +/* Driver-preferred rx/tx parameters. */ + info->default_rxportconf.burst_size =HINIC3_DEFAULT_BURST_SIZE ; + info->default_txportconf.burst_size =HINIC3_DEFAULT_BURST_SIZE ; + info->default_rxportconf.nb_queues =HINIC3_DEFAULT_NB_QUEUES ; + info->default_txportconf.nb_queues =HINIC3_DEFAULT_NB_QUEUES ; + info->default_rxportconf.ring_size =HINIC3_DEFAULT_RING_SIZE ; + info->default_txportconf.ring_size =HINIC3_DEFAULT_RING_SIZE ; + +return 0 ; +} + +static int +hinic3_fw_version_get (struct rte_eth_dev *dev,char *fw_version,size_t fw_size) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +char mgmt_ver[MGMT_VERSION_MAX_LEN ] = {0 }; +int err; + + err =hinic3_get_mgmt_version (nic_dev->hwdev, mgmt_ver, +HINIC3_MGMT_VERSION_MAX_LEN ); +if (err) { +PMD_DRV_LOG (ERR ,"Get fw version failed" ); +return -EIO ; + } + +if (fw_size <strlen ((char *)mgmt_ver) +1 ) +return (strlen ((char *)mgmt_ver) +1 ); + + (void )snprintf (fw_version, fw_size,"%s" , mgmt_ver); + +return 0 ; +} + +/** +* Set ethernet device link state up. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_set_link_up (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int err; + +/* +* Vport enable will set function valid in mpu. +* So dev start status need to be checked before vport enable. +*/ +if (hinic3_get_bit (HINIC3_DEV_START , &nic_dev->dev_status)) { + err =hinic3_set_vport_enable (nic_dev->hwdev, true); +if (err) { +PMD_DRV_LOG (ERR ,"Enable vport failed, dev_name: %s" , + nic_dev->dev_name); +return err; + } + } + +/* Link status follow phy port status, mpu will open pma. */ + err =hinic3_set_port_enable (nic_dev->hwdev, true); +if (err) { +PMD_DRV_LOG (ERR , +"Set MAC link up failed, dev_name: %s, port_id: %d" , + nic_dev->dev_name, dev->data->port_id); +return err; + } + +return 0 ; +} + +/** +* Set ethernet device link state down. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_set_link_down (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int err; + + err =hinic3_set_vport_enable (nic_dev->hwdev, false); +if (err) { +PMD_DRV_LOG (ERR ,"Disable vport failed, dev_name: %s" , + nic_dev->dev_name); +return err; + } + +/* Link status follow phy port status, mpu will close pma. */ + err =hinic3_set_port_enable (nic_dev->hwdev, false); +if (err) { +PMD_DRV_LOG (ERR , +"Set MAC link down failed, dev_name: %s, port_id: %d" , + nic_dev->dev_name, dev->data->port_id); +return err; + } + +return 0 ; +} + +/** +* Get device physical link information. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] wait_to_complete +* Wait for request completion. +* +* @return +* 0 : Link status changed +* -1 : Link status not changed. +*/ +static int +hinic3_link_update (struct rte_eth_dev *dev,int wait_to_complete) +{ +#define CHECK_INTERVAL 10/**< 10ms. */ +#define MAX_REPEAT_TIME 100/**< 1s (100 * 10ms) in total. */ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct rte_eth_link link; +u8 link_state; +unsigned int rep_cnt =MAX_REPEAT_TIME ; +int ret; + +memset (&link,0 ,sizeof (link)); +do { +/* Get link status information from hardware. */ + ret =hinic3_get_link_state (nic_dev->hwdev, &link_state); +if (ret) { + link.link_status =RTE_ETH_LINK_DOWN ; + link.link_speed =RTE_ETH_SPEED_NUM_NONE ; + link.link_duplex =RTE_ETH_LINK_HALF_DUPLEX ; + link.link_autoneg =RTE_ETH_LINK_FIXED ; + goto out; + } + +get_port_info (nic_dev->hwdev, link_state, &link); + +if (!wait_to_complete || link.link_status) +break ; + +rte_delay_ms (CHECK_INTERVAL ); + }while (rep_cnt--); + +out: +return rte_eth_linkstatus_set (dev, &link); +} + +/** +* Reset all RX queues (RXQs). +* +* @param[in] dev +* Pointer to ethernet device structure. +*/ +static void +hinic3_reset_rx_queue (struct rte_eth_dev *dev) +{ +struct hinic3_rxq *rxq =NULL ; +struct hinic3_nic_dev *nic_dev; +int q_id =0 ; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +for (q_id =0 ; q_id < nic_dev->num_rqs; q_id++) { + rxq = nic_dev->rxqs[q_id]; + + rxq->cons_idx =0 ; + rxq->prod_idx =0 ; + rxq->delta = rxq->q_depth; + rxq->next_to_update =0 ; + } +} + +/** +* Reset all TX queues (TXQs). +* +* @param[in] dev +* Pointer to ethernet device structure. +*/ +static void +hinic3_reset_tx_queue (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev; +struct hinic3_txq *txq =NULL ; +int q_id =0 ; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +for (q_id =0 ; q_id < nic_dev->num_sqs; q_id++) { + txq = nic_dev->txqs[q_id]; + + txq->cons_idx =0 ; + txq->prod_idx =0 ; + txq->owner =1 ; + +/* Clear hardware ci. */ + *txq->ci_vaddr_base =0 ; + } +} + +/** +* Create the receive queue. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] qid +* Receive queue index. +* @param[in] nb_desc +* Number of descriptors for receive queue. +* @param[in] socket_id +* Socket index on which memory must be allocated. +* @param[in] rx_conf +* Thresholds parameters (unused_). +* @param[in] mp +* Memory pool for buffer allocations. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_rx_queue_setup (struct rte_eth_dev *dev,uint16_t qid,uint16_t nb_desc, +unsigned int socket_id, + __rte_unused const struct rte_eth_rxconf *rx_conf, +struct rte_mempool *mp) +{ +struct hinic3_nic_dev *nic_dev; +struct hinic3_rxq *rxq =NULL ; +const struct rte_memzone *rq_mz =NULL ; +const struct rte_memzone *cqe_mz =NULL ; +const struct rte_memzone *pi_mz =NULL ; +u16 rq_depth, rx_free_thresh; +u32 queue_buf_size; +void *db_addr =NULL ; +int wqe_count; +u32 buf_size; +int err; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +/* Queue depth must be power of 2, otherwise will be aligned up. */ + rq_depth = (nb_desc & (nb_desc -1 )) + ? ((u16)(1U << (ilog2 (nb_desc) +1 ))) + : nb_desc; + +/* +* Validate number of receive descriptors. +* It must not exceed hardware maximum and minimum. +*/ +if (rq_depth >HINIC3_MAX_QUEUE_DEPTH || + rq_depth <HINIC3_MIN_QUEUE_DEPTH ) { +PMD_DRV_LOG (ERR , +"RX queue depth is out of range from %d to %d," +"(nb_desc: %d, q_depth: %d, port: %d queue: %d)" , +HINIC3_MIN_QUEUE_DEPTH ,HINIC3_MAX_QUEUE_DEPTH , + (int )nb_desc, (int )rq_depth, + (int )dev->data->port_id, (int )qid); +return -EINVAL ; + } + +/* +* The RX descriptor ring will be cleaned after rxq->rx_free_thresh +* descriptors are used or if the number of descriptors required +* to transmit a packet is greater than the number of free RX +* descriptors. +* The following constraints must be satisfied: +* - rx_free_thresh must be greater than 0. +* - rx_free_thresh must be less than the size of the ring minus 1. +* When set to zero use default values. +*/ + rx_free_thresh = (u16)((rx_conf->rx_free_thresh) + ? rx_conf->rx_free_thresh + :HINIC3_DEFAULT_RX_FREE_THRESH ); +if (rx_free_thresh >= (rq_depth -1 )) { +PMD_DRV_LOG (ERR , +"rx_free_thresh must be less than the number " +"of RX descriptors minus 1, rx_free_thresh: %u " +"port: %d queue: %d)" , + (unsigned int )rx_free_thresh, + (int )dev->data->port_id, (int )qid); + +return -EINVAL ; + } + + rxq =rte_zmalloc_socket ("hinic3_rq" ,sizeof (struct hinic3_rxq ), +RTE_CACHE_LINE_SIZE , (int )socket_id); +if (!rxq) { +PMD_DRV_LOG (ERR ,"Allocate rxq[%d] failed, dev_name: %s" , qid, + dev->data->name); + +return -ENOMEM ; + } + +/* Init rq parameters. */ + rxq->nic_dev = nic_dev; + nic_dev->rxqs[qid] = rxq; + rxq->mb_pool = mp; + rxq->q_id = qid; + rxq->next_to_update =0 ; + rxq->q_depth = rq_depth; + rxq->q_mask = rq_depth -1 ; + rxq->delta = rq_depth; + rxq->cons_idx =0 ; + rxq->prod_idx =0 ; + rxq->rx_free_thresh = rx_free_thresh; + rxq->rxinfo_align_end = rxq->q_depth - rxq->rx_free_thresh; + rxq->port_id = dev->data->port_id; + rxq->wait_time_cycle =HINIC3_RX_WAIT_CYCLE_THRESH ; + +/* If buf_len used for function table, need to translated. */ +u16 rx_buf_size = +rte_pktmbuf_data_room_size (rxq->mb_pool) -RTE_PKTMBUF_HEADROOM ; + err =hinic3_convert_rx_buf_size (rx_buf_size, &buf_size); +if (err) { +PMD_DRV_LOG (ERR ,"Adjust buf size failed, dev_name: %s" , + dev->data->name); + goto adjust_bufsize_fail; + } + +if (buf_size >=HINIC3_RX_BUF_SIZE_4K && + buf_size <HINIC3_RX_BUF_SIZE_16K ) + rxq->wqe_type =HINIC3_EXTEND_RQ_WQE ; +else + rxq->wqe_type =HINIC3_NORMAL_RQ_WQE ; + + rxq->wqebb_shift =HINIC3_RQ_WQEBB_SHIFT + rxq->wqe_type; + rxq->wqebb_size = (u16 )BIT (rxq->wqebb_shift); + + rxq->buf_len = (u16 )buf_size; + rxq->rx_buff_shift =ilog2 (rxq->buf_len); + + pi_mz =hinic3_dma_zone_reserve (dev,"hinic3_rq_pi" , qid,RTE_PGSIZE_4K , +RTE_CACHE_LINE_SIZE , (int )socket_id); +if (!pi_mz) { +PMD_DRV_LOG (ERR ,"Allocate rxq[%d] pi_mz failed, dev_name: %s" , + qid, dev->data->name); + err = -ENOMEM ; + goto alloc_pi_mz_fail; + } + rxq->pi_mz = pi_mz; + rxq->pi_dma_addr = pi_mz->iova; + rxq->pi_virt_addr = pi_mz->addr; + + err =hinic3_alloc_db_addr (nic_dev->hwdev, &db_addr,HINIC3_DB_TYPE_RQ ); +if (err) { +PMD_DRV_LOG (ERR ,"Alloc rq doorbell addr failed" ); + goto alloc_db_err_fail; + } + rxq->db_addr = db_addr; + + queue_buf_size =BIT (rxq->wqebb_shift) * rq_depth; + rq_mz =hinic3_dma_zone_reserve (dev,"hinic3_rq_mz" , qid, + queue_buf_size,RTE_PGSIZE_256K , + (int )socket_id); +if (!rq_mz) { +PMD_DRV_LOG (ERR ,"Allocate rxq[%d] rq_mz failed, dev_name: %s" , + qid, dev->data->name); + err = -ENOMEM ; + goto alloc_rq_mz_fail; + } + +memset (rq_mz->addr,0 , queue_buf_size); + rxq->rq_mz = rq_mz; + rxq->queue_buf_paddr = rq_mz->iova; + rxq->queue_buf_vaddr = rq_mz->addr; + + rxq->rx_info =rte_zmalloc_socket ("rx_info" , + rq_depth *sizeof (*rxq->rx_info), +RTE_CACHE_LINE_SIZE , (int )socket_id); +if (!rxq->rx_info) { +PMD_DRV_LOG (ERR ,"Allocate rx_info failed, dev_name: %s" , + dev->data->name); + err = -ENOMEM ; + goto alloc_rx_info_fail; + } + + cqe_mz =hinic3_dma_zone_reserve (dev,"hinic3_cqe_mz" , qid, + rq_depth *sizeof (*rxq->rx_cqe), +RTE_CACHE_LINE_SIZE , (int )socket_id); +if (!cqe_mz) { +PMD_DRV_LOG (ERR ,"Allocate cqe mem zone failed, dev_name: %s" , + dev->data->name); + err = -ENOMEM ; + goto alloc_cqe_mz_fail; + } +memset (cqe_mz->addr,0 , rq_depth *sizeof (*rxq->rx_cqe)); + rxq->cqe_mz = cqe_mz; + rxq->cqe_start_paddr = cqe_mz->iova; + rxq->cqe_start_vaddr = cqe_mz->addr; + rxq->rx_cqe = (struct hinic3_rq_cqe *)rxq->cqe_start_vaddr; + + wqe_count =hinic3_rx_fill_wqe (rxq); +if (wqe_count != rq_depth) { +PMD_DRV_LOG (ERR , +"Fill rx wqe failed, wqe_count: %d, dev_name: %s" , + wqe_count, dev->data->name); + err = -ENOMEM ; + goto fill_rx_wqe_fail; + } +/* Record rxq pointer in rte_eth rx_queues. */ + dev->data->rx_queues[qid] = rxq; + +return 0 ; + +fill_rx_wqe_fail: +hinic3_memzone_free (rxq->cqe_mz); +alloc_cqe_mz_fail: +rte_free (rxq->rx_info); + +alloc_rx_info_fail: +hinic3_memzone_free (rxq->rq_mz); + +alloc_rq_mz_fail: +alloc_db_err_fail: +hinic3_memzone_free (rxq->pi_mz); + +alloc_pi_mz_fail: +adjust_bufsize_fail: +rte_free (rxq); + nic_dev->rxqs[qid] =NULL ; + +return err; +} + +/** +* Create the transmit queue. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] queue_idx +* Transmit queue index. +* @param[in] nb_desc +* Number of descriptors for transmit queue. +* @param[in] socket_id +* Socket index on which memory must be allocated. +* @param[in] tx_conf +* Tx queue configuration parameters (unused_). +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_tx_queue_setup (struct rte_eth_dev *dev,uint16_t qid,uint16_t nb_desc, +unsigned int socket_id, + __rte_unused const struct rte_eth_txconf *tx_conf) +{ +struct hinic3_nic_dev *nic_dev; +struct hinic3_hwdev *hwdev; +struct hinic3_txq *txq =NULL ; +const struct rte_memzone *sq_mz =NULL ; +const struct rte_memzone *ci_mz =NULL ; +void *db_addr =NULL ; +u16 sq_depth, tx_free_thresh; +u32 queue_buf_size; +int err; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + hwdev = nic_dev->hwdev; + +/* Queue depth must be power of 2, otherwise will be aligned up. */ + sq_depth = (nb_desc & (nb_desc -1 )) + ? ((u16)(1U << (ilog2 (nb_desc) +1 ))) + : nb_desc; + +/* +* Validate number of transmit descriptors. +* It must not exceed hardware maximum and minimum. +*/ +if (sq_depth >HINIC3_MAX_QUEUE_DEPTH || + sq_depth <HINIC3_MIN_QUEUE_DEPTH ) { +PMD_DRV_LOG (ERR , +"TX queue depth is out of range from %d to %d," +"(nb_desc: %d, q_depth: %d, port: %d queue: %d)" , +HINIC3_MIN_QUEUE_DEPTH ,HINIC3_MAX_QUEUE_DEPTH , + (int )nb_desc, (int )sq_depth, + (int )dev->data->port_id, (int )qid); +return -EINVAL ; + } + +/* +* The TX descriptor ring will be cleaned after txq->tx_free_thresh +* descriptors are used or if the number of descriptors required +* to transmit a packet is greater than the number of free TX +* descriptors. +* The following constraints must be satisfied: +* - tx_free_thresh must be greater than 0. +* - tx_free_thresh must be less than the size of the ring minus 1. +* When set to zero use default values. +*/ + tx_free_thresh = (u16)((tx_conf->tx_free_thresh) + ? tx_conf->tx_free_thresh + :HINIC3_DEFAULT_TX_FREE_THRESH ); +if (tx_free_thresh >= (sq_depth -1 )) { +PMD_DRV_LOG (ERR , +"tx_free_thresh must be less than the number of tx " +"descriptors minus 1, tx_free_thresh: %u port: %d " +"queue: %d" , + (unsigned int )tx_free_thresh, + (int )dev->data->port_id, (int )qid); +return -EINVAL ; + } + + txq =rte_zmalloc_socket ("hinic3_tx_queue" ,sizeof (struct hinic3_txq ), +RTE_CACHE_LINE_SIZE , (int )socket_id); +if (!txq) { +PMD_DRV_LOG (ERR ,"Allocate txq[%d] failed, dev_name: %s" , qid, + dev->data->name); +return -ENOMEM ; + } + nic_dev->txqs[qid] = txq; + txq->nic_dev = nic_dev; + txq->q_id = qid; + txq->q_depth = sq_depth; + txq->q_mask = sq_depth -1 ; + txq->cons_idx =0 ; + txq->prod_idx =0 ; + txq->wqebb_shift =HINIC3_SQ_WQEBB_SHIFT ; + txq->wqebb_size = (u16 )BIT (txq->wqebb_shift); + txq->tx_free_thresh = tx_free_thresh; + txq->owner =1 ; + txq->cos = nic_dev->default_cos; + + ci_mz =hinic3_dma_zone_reserve (dev,"hinic3_sq_ci" , qid, +HINIC3_CI_Q_ADDR_SIZE , +HINIC3_CI_Q_ADDR_SIZE , (int )socket_id); +if (!ci_mz) { +PMD_DRV_LOG (ERR ,"Allocate txq[%d] ci_mz failed, dev_name: %s" , + qid, dev->data->name); + err = -ENOMEM ; + goto alloc_ci_mz_fail; + } + txq->ci_mz = ci_mz; + txq->ci_dma_base = ci_mz->iova; + txq->ci_vaddr_base = (volatile u16 *)ci_mz->addr; + + queue_buf_size =BIT (txq->wqebb_shift) * sq_depth; + sq_mz =hinic3_dma_zone_reserve (dev,"hinic3_sq_mz" , qid, + queue_buf_size,RTE_PGSIZE_256K , + (int )socket_id); +if (!sq_mz) { +PMD_DRV_LOG (ERR ,"Allocate txq[%d] sq_mz failed, dev_name: %s" , + qid, dev->data->name); + err = -ENOMEM ; + goto alloc_sq_mz_fail; + } +memset (sq_mz->addr,0 , queue_buf_size); + txq->sq_mz = sq_mz; + txq->queue_buf_paddr = sq_mz->iova; + txq->queue_buf_vaddr = sq_mz->addr; + txq->sq_head_addr = (u64 )txq->queue_buf_vaddr; + txq->sq_bot_sge_addr = txq->sq_head_addr + queue_buf_size; + + err =hinic3_alloc_db_addr (hwdev, &db_addr,HINIC3_DB_TYPE_SQ ); +if (err) { +PMD_DRV_LOG (ERR ,"Alloc sq doorbell addr failed" ); + goto alloc_db_err_fail; + } + txq->db_addr = db_addr; + + txq->tx_info =rte_zmalloc_socket ("tx_info" , + sq_depth *sizeof (*txq->tx_info), +RTE_CACHE_LINE_SIZE , (int )socket_id); +if (!txq->tx_info) { +PMD_DRV_LOG (ERR ,"Allocate tx_info failed, dev_name: %s" , + dev->data->name); + err = -ENOMEM ; + goto alloc_tx_info_fail; + } + +/* Record txq pointer in rte_eth tx_queues. */ + dev->data->tx_queues[qid] = txq; + +return 0 ; + +alloc_tx_info_fail: +alloc_db_err_fail: +hinic3_memzone_free (txq->sq_mz); + +alloc_sq_mz_fail: +hinic3_memzone_free (txq->ci_mz); + +alloc_ci_mz_fail: +rte_free (txq); +return err; +} + +static void +hinic3_rx_queue_release (struct rte_eth_dev *dev,uint16_t queue_id) +{ +if (dev ==NULL || dev->data ==NULL || dev->data->rx_queues ==NULL ) { +PMD_DRV_LOG (WARNING ,"rx queue is null when release" ); +return ; + } +if (queue_id >= dev->data->nb_rx_queues) { +PMD_DRV_LOG (WARNING ,"eth_dev: %s, rx queue id: %u is illegal" , + dev->data->name, queue_id); +return ; + } +struct hinic3_rxq *rxq = dev->data->rx_queues[queue_id]; +struct hinic3_nic_dev *nic_dev =NULL ; + +if (!rxq) { +PMD_DRV_LOG (WARNING ,"Rxq is null when release" ); +return ; + } + + nic_dev = rxq->nic_dev; + +hinic3_free_rxq_mbufs (rxq); + +hinic3_memzone_free (rxq->cqe_mz); + +rte_free (rxq->rx_info); + rxq->rx_info =NULL ; + +hinic3_memzone_free (rxq->rq_mz); + +hinic3_memzone_free (rxq->pi_mz); + + nic_dev->rxqs[rxq->q_id] =NULL ; +rte_free (rxq); + dev->data->rx_queues[queue_id] =NULL ; +} + +static void +hinic3_tx_queue_release (struct rte_eth_dev *dev,uint16_t queue_id) +{ +if (dev ==NULL || dev->data ==NULL || dev->data->tx_queues ==NULL ) { +PMD_DRV_LOG (WARNING ,"tx queue is null when release" ); +return ; + } +if (queue_id >= dev->data->nb_tx_queues) { +PMD_DRV_LOG (WARNING ,"eth_dev: %s, tx queue id: %u is illegal" , + dev->data->name, queue_id); +return ; + } +struct hinic3_txq *txq = dev->data->tx_queues[queue_id]; +struct hinic3_nic_dev *nic_dev =NULL ; + +if (!txq) { +PMD_DRV_LOG (WARNING ,"Txq is null when release" ); +return ; + } +PMD_DRV_LOG (INFO ,"%s txq_idx:%d queue release." , + txq->nic_dev->dev_name, txq->q_id); + nic_dev = txq->nic_dev; + +hinic3_free_txq_mbufs (txq); + +rte_free (txq->tx_info); + txq->tx_info =NULL ; + +hinic3_memzone_free (txq->sq_mz); + +hinic3_memzone_free (txq->ci_mz); + + nic_dev->txqs[txq->q_id] =NULL ; +rte_free (txq); + dev->data->tx_queues[queue_id] =NULL ; +} + +/** +* Start RXQ and enables flow director (fdir) filter for RXQ. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] rq_id +* RX queue ID to be started. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_rx_queue_start(__rte_unused struct rte_eth_dev *dev, + __rte_unused uint16_t rq_id) +{ +struct hinic3_rxq *rxq =NULL ; +int rc; + +if (rq_id < dev->data->nb_rx_queues) { + rxq = dev->data->rx_queues[rq_id]; + + rc =hinic3_start_rq (dev, rxq); +if (rc) { +PMD_DRV_LOG (ERR , +"Start rx queue failed, eth_dev:%s, " +"queue_idx:%d" , + dev->data->name, rq_id); +return rc; + } + + dev->data->rx_queue_state[rq_id] =RTE_ETH_QUEUE_STATE_STARTED ; + } + rc =hinic3_enable_rxq_fdir_filter (dev, (u32 )rq_id, (u32 )true); +if (rc) { +PMD_DRV_LOG (ERR ,"Failed to enable rq : %d fdir filter." , + rq_id); +return rc; + } +return 0 ; +} + +/** +* Stop RXQ and disable flow director (fdir) filter for RXQ. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] rq_id +* RX queue ID to be stopped. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_rx_queue_stop(__rte_unused struct rte_eth_dev *dev, + __rte_unused uint16_t rq_id) +{ +struct hinic3_rxq *rxq =NULL ; +int rc; + +if (rq_id < dev->data->nb_rx_queues) { + rxq = dev->data->rx_queues[rq_id]; + + rc =hinic3_stop_rq (dev, rxq); +if (rc) { +PMD_DRV_LOG (ERR , +"Stop rx queue failed, eth_dev:%s, " +"queue_idx:%d" , + dev->data->name, rq_id); +return rc; + } + + dev->data->rx_queue_state[rq_id] =RTE_ETH_QUEUE_STATE_STOPPED ; + } + rc =hinic3_enable_rxq_fdir_filter (dev, (u32 )rq_id, (u32 )false); +if (rc) { +PMD_DRV_LOG (ERR ,"Failed to disable rq : %d fdir filter." , + rq_id); +return rc; + } + +return 0 ; +} + +static int +hinic3_dev_tx_queue_start(__rte_unused struct rte_eth_dev *dev, + __rte_unused uint16_t sq_id) +{ +struct hinic3_txq *txq =NULL ; + +PMD_DRV_LOG (INFO ,"Start tx queue, eth_dev:%s, queue_idx:%d" , + dev->data->name, sq_id); + + txq = dev->data->tx_queues[sq_id]; +HINIC3_SET_TXQ_STARTED (txq); + dev->data->tx_queue_state[sq_id] =RTE_ETH_QUEUE_STATE_STARTED ; +return 0 ; +} + +static int +hinic3_dev_tx_queue_stop(__rte_unused struct rte_eth_dev *dev, + __rte_unused uint16_t sq_id) +{ +struct hinic3_txq *txq =NULL ; +int rc; + +if (sq_id < dev->data->nb_tx_queues) { + txq = dev->data->tx_queues[sq_id]; + rc =hinic3_stop_sq (txq); +if (rc) { +PMD_DRV_LOG (ERR , +"Stop tx queue failed, eth_dev:%s, " +"queue_idx:%d" , + dev->data->name, sq_id); +return rc; + } + +HINIC3_SET_TXQ_STOPPED (txq); + dev->data->tx_queue_state[sq_id] =RTE_ETH_QUEUE_STATE_STOPPED ; + } + +return 0 ; +} + +int +hinic3_dev_rx_queue_intr_enable (struct rte_eth_dev *dev,uint16_t queue_id) +{ +struct rte_pci_device *pci_dev =RTE_ETH_DEV_TO_PCI (dev); +struct rte_intr_handle *intr_handle =PCI_DEV_TO_INTR_HANDLE (pci_dev); +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u16 msix_intr; + +if (!rte_intr_dp_is_en (intr_handle) || !intr_handle->intr_vec) +return 0 ; + +if (queue_id >= dev->data->nb_rx_queues) +return -EINVAL ; + + msix_intr = (u16 )intr_handle->intr_vec[queue_id]; +hinic3_set_msix_auto_mask_state (nic_dev->hwdev, msix_intr, +HINIC3_SET_MSIX_AUTO_MASK ); +hinic3_set_msix_state (nic_dev->hwdev, msix_intr,HINIC3_MSIX_ENABLE ); + +return 0 ; +} + +int +hinic3_dev_rx_queue_intr_disable (struct rte_eth_dev *dev,uint16_t queue_id) +{ +struct rte_pci_device *pci_dev =RTE_ETH_DEV_TO_PCI (dev); +struct rte_intr_handle *intr_handle =PCI_DEV_TO_INTR_HANDLE (pci_dev); +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u16 msix_intr; + +if (!rte_intr_dp_is_en (intr_handle) || !intr_handle->intr_vec) +return 0 ; + +if (queue_id >= dev->data->nb_rx_queues) +return -EINVAL ; + + msix_intr = (u16 )intr_handle->intr_vec[queue_id]; +hinic3_set_msix_auto_mask_state (nic_dev->hwdev, msix_intr, +HINIC3_CLR_MSIX_AUTO_MASK ); +hinic3_set_msix_state (nic_dev->hwdev, msix_intr,HINIC3_MSIX_DISABLE ); +hinic3_misx_intr_clear_resend_bit (nic_dev->hwdev, msix_intr, +MSIX_RESEND_TIMER_CLEAR ); + +return 0 ; +} + +static uint32_t +hinic3_dev_rx_queue_count(__rte_unused void *rx_queue) +{ +return 0 ; +} + +static int +hinic3_dev_rx_descriptor_status(__rte_unused void *rx_queue, + __rte_unused uint16_t offset) +{ +return 0 ; +} + +static int +hinic3_dev_tx_descriptor_status(__rte_unused void *tx_queue, + __rte_unused uint16_t offset) +{ +return 0 ; +} + +static int +hinic3_set_lro (struct hinic3_nic_dev *nic_dev,struct rte_eth_conf *dev_conf) +{ +bool lro_en; +int max_lro_size, lro_max_pkt_len; +int err; + +/* Config lro. */ + lro_en = dev_conf->rxmode.offloads &RTE_ETH_RX_OFFLOAD_TCP_LRO ? true + : false; + max_lro_size = (int )(dev_conf->rxmode.max_lro_pkt_size); +/* `max_lro_size` is divisible by `HINIC3_LRO_UNIT_WQE_SIZE`. */ + lro_max_pkt_len = max_lro_size /HINIC3_LRO_UNIT_WQE_SIZE + ? max_lro_size /HINIC3_LRO_UNIT_WQE_SIZE + :1 ; + +PMD_DRV_LOG (INFO , +"max_lro_size: %d, rx_buff_len: %d, lro_max_pkt_len: %d" , + max_lro_size, nic_dev->rx_buff_len, lro_max_pkt_len); +PMD_DRV_LOG (INFO ,"max_rx_pkt_len: %d" , +HINIC3_MAX_RX_PKT_LEN (dev_conf->rxmode)); + err =hinic3_set_rx_lro_state (nic_dev->hwdev, lro_en, +HINIC3_LRO_DEFAULT_TIME_LIMIT , + lro_max_pkt_len); +if (err) +PMD_DRV_LOG (ERR ,"Set lro state failed, err: %d" , err); +return err; +} + +static int +hinic3_set_vlan (struct rte_eth_dev *dev,struct rte_eth_conf *dev_conf) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +bool vlan_filter, vlan_strip; +int err; + +/* Config vlan filter. */ + vlan_filter = dev_conf->rxmode.offloads & +RTE_ETH_RX_OFFLOAD_VLAN_FILTER ; + + err =hinic3_set_vlan_fliter (nic_dev->hwdev, vlan_filter); +if (err) { +PMD_DRV_LOG (ERR , +"Config vlan filter failed, device: %s, port_id: " +"%d, err: %d" , + nic_dev->dev_name, dev->data->port_id, err); +return err; + } + +/* Config vlan stripping. */ + vlan_strip = dev_conf->rxmode.offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ; + + err =hinic3_set_rx_vlan_offload (nic_dev->hwdev, vlan_strip); +if (err) { +PMD_DRV_LOG (ERR , +"Config vlan strip failed, device: %s, port_id: " +"%d, err: %d" , + nic_dev->dev_name, dev->data->port_id, err); + } + +return err; +} + +/** +* Configure RX mode, checksum offload, LRO, RSS, VLAN and initialize the RXQ +* list. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_set_rxtx_configure (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct rte_eth_conf *dev_conf = &dev->data->dev_conf; +struct rte_eth_rss_conf *rss_conf =NULL ; +int err; + +/* Config rx mode. */ + err =hinic3_set_rx_mode (nic_dev->hwdev,HINIC3_DEFAULT_RX_MODE ); +if (err) { +PMD_DRV_LOG (ERR ,"Set rx_mode: 0x%x failed" , +HINIC3_DEFAULT_RX_MODE ); +return err; + } + nic_dev->rx_mode =HINIC3_DEFAULT_RX_MODE ; + +/* Config rx checksum offload. */ +if (dev_conf->rxmode.offloads &RTE_ETH_RX_OFFLOAD_CHECKSUM ) + nic_dev->rx_csum_en =HINIC3_DEFAULT_RX_CSUM_OFFLOAD ; + + err =hinic3_set_lro (nic_dev, dev_conf); +if (err) { +PMD_DRV_LOG (ERR ,"Set lro failed" ); +return err; + } +/* Config RSS. */ +if ((dev_conf->rxmode.mq_mode &RTE_ETH_MQ_RX_RSS_FLAG ) && + nic_dev->num_rqs >1 ) { + rss_conf = &dev_conf->rx_adv_conf.rss_conf; + err =hinic3_update_rss_config (dev, rss_conf); +if (err) { +PMD_DRV_LOG (ERR ,"Set rss config failed, err: %d" , err); +return err; + } + } + + err =hinic3_set_vlan (dev, dev_conf); +if (err) { +PMD_DRV_LOG (ERR ,"Set vlan failed, err: %d" , err); +return err; + } + +hinic3_init_rx_queue_list (nic_dev); + +return 0 ; +} + +/** +* Disable RX mode and RSS, and free associated resources. +* +* @param[in] dev +* Pointer to ethernet device structure. +*/ +static void +hinic3_remove_rxtx_configure (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u8 prio_tc[HINIC3_DCB_UP_MAX ] = {0 }; + +hinic3_set_rx_mode (nic_dev->hwdev,0 ); + +if (nic_dev->rss_state ==HINIC3_RSS_ENABLE ) { +hinic3_rss_cfg (nic_dev->hwdev,HINIC3_RSS_DISABLE ,0 , prio_tc); +hinic3_rss_template_free (nic_dev->hwdev); + nic_dev->rss_state =HINIC3_RSS_DISABLE ; + } +} + +static bool +hinic3_find_vlan_filter (struct hinic3_nic_dev *nic_dev,uint16_t vlan_id) +{ +u32 vid_idx, vid_bit; + + vid_idx =HINIC3_VFTA_IDX (vlan_id); + vid_bit =HINIC3_VFTA_BIT (vlan_id); + +return (nic_dev->vfta[vid_idx] & vid_bit) ? true : false; +} + +static void +hinic3_store_vlan_filter (struct hinic3_nic_dev *nic_dev,u16 vlan_id,bool on) +{ +u32 vid_idx, vid_bit; + + vid_idx =HINIC3_VFTA_IDX (vlan_id); + vid_bit =HINIC3_VFTA_BIT (vlan_id); + +if (on) + nic_dev->vfta[vid_idx] |= vid_bit; +else + nic_dev->vfta[vid_idx] &= ~vid_bit; +} + +static void +hinic3_remove_all_vlanid (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int vlan_id; +u16 func_id; + + func_id =hinic3_global_func_id (nic_dev->hwdev); + +for (vlan_id =1 ; vlan_id <RTE_ETHER_MAX_VLAN_ID ; vlan_id++) { +if (hinic3_find_vlan_filter (nic_dev, vlan_id)) { +hinic3_del_vlan (nic_dev->hwdev, vlan_id, func_id); +hinic3_store_vlan_filter (nic_dev, vlan_id, false); + } + } +} + +static void +hinic3_disable_interrupt (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct rte_pci_device *pci_dev =RTE_ETH_DEV_TO_PCI (dev); + +if (!hinic3_get_bit (HINIC3_DEV_INIT , &nic_dev->dev_status)) +return ; + +/* Disable rte interrupt. */ +rte_intr_disable (PCI_DEV_TO_INTR_HANDLE (pci_dev)); +rte_intr_callback_unregister (PCI_DEV_TO_INTR_HANDLE (pci_dev), + hinic3_dev_interrupt_handler, (void *)dev); +} + +static void +hinic3_enable_interrupt (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct rte_pci_device *pci_dev =RTE_ETH_DEV_TO_PCI (dev); + +if (!hinic3_get_bit (HINIC3_DEV_INIT , &nic_dev->dev_status)) +return ; + +/* Enable rte interrupt. */ +rte_intr_enable (PCI_DEV_TO_INTR_HANDLE (pci_dev)); +rte_intr_callback_register (PCI_DEV_TO_INTR_HANDLE (pci_dev), + hinic3_dev_interrupt_handler, (void *)dev); +} + +#define HINIC3_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET + +/** Dp interrupt msix attribute. */ +#define HINIC3_TXRX_MSIX_PENDING_LIMIT 2 +#define HINIC3_TXRX_MSIX_COALESC_TIMER 2 +#define HINIC3_TXRX_MSIX_RESEND_TIMER_CFG 7 + +static int +hinic3_init_rxq_msix_attr (void *hwdev,u16 msix_index) +{ +struct interrupt_info info = {0 }; +int err; + + info.lli_set =0 ; + info.interrupt_coalesc_set =1 ; + info.pending_limt =HINIC3_TXRX_MSIX_PENDING_LIMIT ; + info.coalesc_timer_cfg =HINIC3_TXRX_MSIX_COALESC_TIMER ; + info.resend_timer_cfg =HINIC3_TXRX_MSIX_RESEND_TIMER_CFG ; + + info.msix_index = msix_index; + err =hinic3_set_interrupt_cfg (hwdev, info); +if (err) { +PMD_DRV_LOG (ERR ,"Set msix attr failed, msix_index %d" , + msix_index); +return -EFAULT ; + } + +return 0 ; +} + +static void +hinic3_deinit_rxq_intr (struct rte_eth_dev *dev) +{ +struct rte_intr_handle *intr_handle = dev->intr_handle; + +rte_intr_efd_disable (intr_handle); +if (intr_handle->intr_vec) { +rte_free (intr_handle->intr_vec); + intr_handle->intr_vec =NULL ; + } +} + +/** +* Initialize RX queue interrupts by enabling MSI-X, allocate interrupt vectors, +* and configure interrupt attributes for each RX queue. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, negative error code on failure. +* - -ENOTSUP if MSI-X interrupts are not supported. +* - Error code if enabling event file descriptors fails. +* - -ENOMEM if allocating interrupt vectors fails. +*/ +static int +hinic3_init_rxq_intr (struct rte_eth_dev *dev) +{ +struct rte_intr_handle *intr_handle =NULL ; +struct hinic3_nic_dev *nic_dev =NULL ; +struct hinic3_rxq *rxq =NULL ; +u32 nb_rx_queues, i; +int err; + + intr_handle = dev->intr_handle; + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +if (!dev->data->dev_conf.intr_conf.rxq) +return 0 ; + +if (!rte_intr_cap_multiple (intr_handle)) { +PMD_DRV_LOG (ERR ,"Rx queue interrupts require MSI-X interrupts" +" (vfio-pci driver)" ); +return -ENOTSUP ; + } + + nb_rx_queues = dev->data->nb_rx_queues; + err =rte_intr_efd_enable (intr_handle, nb_rx_queues); +if (err) { +PMD_DRV_LOG (ERR , +"Failed to enable event fds for Rx queue interrupts" ); +return err; + } + + intr_handle->intr_vec = +rte_zmalloc ("hinic_intr_vec" , nb_rx_queues *sizeof (int ),0 ); +if (intr_handle->intr_vec ==NULL ) { +PMD_DRV_LOG (ERR ,"Failed to allocate intr_vec" ); +rte_intr_efd_disable (intr_handle); +return -ENOMEM ; + } + intr_handle->vec_list_size = nb_rx_queues; +for (i =0 ; i < nb_rx_queues; i++) + intr_handle->intr_vec[i] = (int )(i +HINIC3_RX_VEC_START ); + +for (i =0 ; i < dev->data->nb_rx_queues; i++) { + rxq = dev->data->rx_queues[i]; + rxq->dp_intr_en =1 ; + rxq->msix_entry_idx = (u16 )intr_handle->intr_vec[i]; + + err =hinic3_init_rxq_msix_attr (nic_dev->hwdev, + rxq->msix_entry_idx); +if (err) { +hinic3_deinit_rxq_intr (dev); +return err; + } + } + +return 0 ; +} + +static int +hinic3_init_sw_rxtxqs (struct hinic3_nic_dev *nic_dev) +{ +u32 txq_size; +u32 rxq_size; + +/* Allocate software txq array. */ + txq_size = nic_dev->max_sqs *sizeof (*nic_dev->txqs); + nic_dev->txqs = +rte_zmalloc ("hinic3_txqs" , txq_size,RTE_CACHE_LINE_SIZE ); +if (!nic_dev->txqs) { +PMD_DRV_LOG (ERR ,"Allocate txqs failed" ); +return -ENOMEM ; + } + +/* Allocate software rxq array. */ + rxq_size = nic_dev->max_rqs *sizeof (*nic_dev->rxqs); + nic_dev->rxqs = +rte_zmalloc ("hinic3_rxqs" , rxq_size,RTE_CACHE_LINE_SIZE ); +if (!nic_dev->rxqs) { +/* Free txqs. */ +rte_free (nic_dev->txqs); + nic_dev->txqs =NULL ; + +PMD_DRV_LOG (ERR ,"Allocate rxqs failed" ); +return -ENOMEM ; + } + +return 0 ; +} + +static void +hinic3_deinit_sw_rxtxqs (struct hinic3_nic_dev *nic_dev) +{ +rte_free (nic_dev->txqs); + nic_dev->txqs =NULL ; + +rte_free (nic_dev->rxqs); + nic_dev->rxqs =NULL ; +} + +static void +hinic3_disable_queue_intr (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct rte_intr_handle *intr_handle = dev->intr_handle; +int msix_intr; +int i; + +if (intr_handle->intr_vec ==NULL ) +return ; + +for (i =0 ; i < nic_dev->num_rqs; i++) { + msix_intr = intr_handle->intr_vec[i]; +hinic3_set_msix_state (nic_dev->hwdev, (u16 )msix_intr, +HINIC3_MSIX_DISABLE ); +hinic3_misx_intr_clear_resend_bit (nic_dev->hwdev, + (u16 )msix_intr, +MSIX_RESEND_TIMER_CLEAR ); + } +} + +/** +* Start the device. +* +* Initialize function table, TXQ and TXQ context, configure RX offload, and +* enable vport and port to prepare receiving packets. +* +* @param[in] eth_dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_start (struct rte_eth_dev *eth_dev) +{ +struct hinic3_nic_dev *nic_dev =NULL ; +u64 nic_features; +struct hinic3_rxq *rxq =NULL ; +int i; +int err; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); + err =hinic3_copy_mempool_init (nic_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Create copy mempool failed, dev_name: %s" , + eth_dev->data->name); + goto init_mpool_fail; + } +hinic3_update_msix_info (nic_dev->hwdev->hwif); +hinic3_disable_interrupt (eth_dev); + err =hinic3_init_rxq_intr (eth_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Init rxq intr fail, eth_dev:%s" , + eth_dev->data->name); + goto init_rxq_intr_fail; + } + +hinic3_get_func_rx_buf_size (nic_dev); + err =hinic3_init_function_table (nic_dev->hwdev, nic_dev->rx_buff_len); +if (err) { +PMD_DRV_LOG (ERR ,"Init function table failed, dev_name: %s" , + eth_dev->data->name); + goto init_func_tbl_fail; + } + + nic_features =hinic3_get_driver_feature (nic_dev); +/* +* You can update the features supported by the driver according to the +* scenario here. +*/ + nic_features &=DEFAULT_DRV_FEATURE ; +hinic3_update_driver_feature (nic_dev, nic_features); + + err =hinic3_set_feature_to_hw (nic_dev->hwdev, &nic_dev->feature_cap, +1 ); +if (err) { +PMD_DRV_LOG (ERR , +"Failed to set nic features to hardware, err %d" , + err); + goto get_feature_err; + } + +/* Reset rx and tx queue. */ +hinic3_reset_rx_queue (eth_dev); +hinic3_reset_tx_queue (eth_dev); + +/* Init txq and rxq context. */ + err =hinic3_init_qp_ctxts (nic_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Init qp context failed, dev_name: %s" , + eth_dev->data->name); + goto init_qp_fail; + } + +/* Set default mtu. */ + err =hinic3_set_port_mtu (nic_dev->hwdev, nic_dev->mtu_size); +if (err) { +PMD_DRV_LOG (ERR ,"Set mtu_size[%d] failed, dev_name: %s" , + nic_dev->mtu_size, eth_dev->data->name); + goto set_mtu_fail; + } + eth_dev->data->mtu = nic_dev->mtu_size; + +/* Set rx configuration: rss/checksum/rxmode/lro. */ + err =hinic3_set_rxtx_configure (eth_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Set rx config failed, dev_name: %s" , + eth_dev->data->name); + goto set_rxtx_config_fail; + } + +/* Enable dev interrupt. */ +hinic3_enable_interrupt (eth_dev); + err =hinic3_start_all_rqs (eth_dev); +if (err) { +PMD_DRV_LOG (ERR ,"Set rx config failed, dev_name: %s" , + eth_dev->data->name); + goto start_rqs_fail; + } + +hinic3_start_all_sqs (eth_dev); + +/* Open virtual port and ready to start packet receiving. */ + err =hinic3_set_vport_enable (nic_dev->hwdev, true); +if (err) { +PMD_DRV_LOG (ERR ,"Enable vport failed, dev_name: %s" , + eth_dev->data->name); + goto en_vport_fail; + } + +/* Open physical port and start packet receiving. */ + err =hinic3_set_port_enable (nic_dev->hwdev, true); +if (err) { +PMD_DRV_LOG (ERR ,"Enable physical port failed, dev_name: %s" , + eth_dev->data->name); + goto en_port_fail; + } + +/* Update eth_dev link status. */ +if (eth_dev->data->dev_conf.intr_conf.lsc !=0 ) + (void )hinic3_link_update (eth_dev,0 ); + +hinic3_set_bit (HINIC3_DEV_START , &nic_dev->dev_status); + +return 0 ; + +en_port_fail: + (void )hinic3_set_vport_enable (nic_dev->hwdev, false); + +en_vport_fail: +/* Flush tx && rx chip resources in case of setting vport fake fail. */ + (void )hinic3_flush_qps_res (nic_dev->hwdev); +rte_delay_ms (DEV_START_DELAY_MS ); +for (i =0 ; i < nic_dev->num_rqs; i++) { + rxq = nic_dev->rxqs[i]; +hinic3_remove_rq_from_rx_queue_list (nic_dev, rxq->q_id); +hinic3_free_rxq_mbufs (rxq); +hinic3_dev_rx_queue_intr_disable (eth_dev, rxq->q_id); + eth_dev->data->rx_queue_state[i] =RTE_ETH_QUEUE_STATE_STOPPED ; + eth_dev->data->tx_queue_state[i] =RTE_ETH_QUEUE_STATE_STOPPED ; + } +start_rqs_fail: +hinic3_remove_rxtx_configure (eth_dev); + +set_rxtx_config_fail: +set_mtu_fail: +hinic3_free_qp_ctxts (nic_dev->hwdev); + +init_qp_fail: +get_feature_err: +init_func_tbl_fail: +hinic3_deinit_rxq_intr (eth_dev); +init_rxq_intr_fail: +hinic3_copy_mempool_uninit (nic_dev); +init_mpool_fail: +return err; +} + +/** +* Look up or creates a memory pool for storing packet buffers used in copy +* operations. +* +* @param[in] nic_dev +* Pointer to NIC device structure. +* +* @return +* 0 on success, non-zero on failure. +* `-ENOMEM`: Memory pool creation fails. +*/ +static int +hinic3_copy_mempool_init (struct hinic3_nic_dev *nic_dev) +{ + nic_dev->cpy_mpool =rte_mempool_lookup (HINCI3_CPY_MEMPOOL_NAME ); +if (nic_dev->cpy_mpool ==NULL ) { + nic_dev->cpy_mpool =rte_pktmbuf_pool_create (HINCI3_CPY_MEMPOOL_NAME , +HINIC3_COPY_MEMPOOL_DEPTH ,HINIC3_COPY_MEMPOOL_CACHE , +0 ,HINIC3_COPY_MBUF_SIZE , (int )rte_socket_id ()); +if (nic_dev->cpy_mpool ==NULL ) { +PMD_DRV_LOG (ERR , +"Create copy mempool failed, errno: %d, " +"dev_name: %s" , + rte_errno,HINCI3_CPY_MEMPOOL_NAME ); +return -ENOMEM ; + } + } + +return 0 ; +} + +/** +* Clear the reference to the copy memory pool without freeing it. +* +* @param[in] nic_dev +* Pointer to NIC device structure. +*/ +static void +hinic3_copy_mempool_uninit (struct hinic3_nic_dev *nic_dev) +{ + nic_dev->cpy_mpool =NULL ; +} + +/** +* Stop the device. +* +* Stop phy port and vport, flush pending io request, clean context configure +* and free io resourece. +* +* @param[in] dev +* Pointer to ethernet device structure. +*/ +static int +hinic3_dev_stop (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev; +struct rte_eth_link link; +int err; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +if (!hinic3_test_and_clear_bit (HINIC3_DEV_START , + &nic_dev->dev_status)) { +PMD_DRV_LOG (INFO ,"Device %s already stopped" , + nic_dev->dev_name); +return 0 ; + } + +/* Stop phy port and vport. */ + err =hinic3_set_port_enable (nic_dev->hwdev, false); +if (err) +PMD_DRV_LOG (WARNING , +"Disable phy port failed, error: %d, " +"dev_name: %s, port_id: %d" , + err, dev->data->name, dev->data->port_id); + + err =hinic3_set_vport_enable (nic_dev->hwdev, false); +if (err) +PMD_DRV_LOG (WARNING , +"Disable vport failed, error: %d, " +"dev_name: %s, port_id: %d" , + err, dev->data->name, dev->data->port_id); + +/* Clear recorded link status. */ +memset (&link,0 ,sizeof (link)); + (void )rte_eth_linkstatus_set (dev, &link); + +/* Disable dp interrupt. */ +hinic3_disable_queue_intr (dev); +hinic3_deinit_rxq_intr (dev); + +/* Flush pending io request. */ +hinic3_flush_txqs (nic_dev); + +/* After set vport disable 100ms, no packets will be send to host. */ +rte_delay_ms (DEV_STOP_DELAY_MS ); + +hinic3_flush_qps_res (nic_dev->hwdev); + +/* Clean RSS table and rx_mode. */ +hinic3_remove_rxtx_configure (dev); + +/* Clean root context. */ +hinic3_free_qp_ctxts (nic_dev->hwdev); + +/* Free all tx and rx mbufs. */ +hinic3_free_all_txq_mbufs (nic_dev); +hinic3_free_all_rxq_mbufs (nic_dev); + +/* Free mempool. */ +hinic3_copy_mempool_uninit (nic_dev); +return 0 ; +} + +static void +hinic3_dev_release (struct rte_eth_dev *eth_dev) +{ +struct hinic3_nic_dev *nic_dev = +HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +struct rte_pci_device *pci_dev =RTE_ETH_DEV_TO_PCI (eth_dev); +int qid; + +/* Release io resource. */ +for (qid =0 ; qid < nic_dev->num_sqs; qid++) +hinic3_tx_queue_release (eth_dev, qid); + +for (qid =0 ; qid < nic_dev->num_rqs; qid++) +hinic3_rx_queue_release (eth_dev, qid); + +hinic3_deinit_sw_rxtxqs (nic_dev); + +hinic3_deinit_mac_addr (eth_dev); +rte_free (nic_dev->mc_list); + +hinic3_remove_all_vlanid (eth_dev); + +hinic3_clear_bit (HINIC3_DEV_INTR_EN , &nic_dev->dev_status); +hinic3_set_msix_state (nic_dev->hwdev,0 ,HINIC3_MSIX_DISABLE ); +rte_intr_disable (PCI_DEV_TO_INTR_HANDLE (pci_dev)); + (void )rte_intr_callback_unregister (PCI_DEV_TO_INTR_HANDLE (pci_dev), + hinic3_dev_interrupt_handler, + (void *)eth_dev); + +/* Destroy rx mode mutex. */ +hinic3_mutex_destroy (&nic_dev->rx_mode_mutex); + +hinic3_free_nic_hwdev (nic_dev->hwdev); +hinic3_free_hwdev (nic_dev->hwdev); + + eth_dev->rx_pkt_burst =NULL ; + eth_dev->tx_pkt_burst =NULL ; + eth_dev->dev_ops =NULL ; + eth_dev->rx_queue_count =NULL ; + eth_dev->rx_descriptor_status =NULL ; + eth_dev->tx_descriptor_status =NULL ; + +rte_free (nic_dev->hwdev); + nic_dev->hwdev =NULL ; +} + +/** +* Close the device. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_close (struct rte_eth_dev *eth_dev) +{ +struct hinic3_nic_dev *nic_dev = +HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +int ret; + +if (hinic3_test_and_set_bit (HINIC3_DEV_CLOSE , &nic_dev->dev_status)) { +PMD_DRV_LOG (WARNING ,"Device %s already closed" , + nic_dev->dev_name); +return 0 ; + } + + ret =hinic3_dev_stop (eth_dev); + +hinic3_dev_release (eth_dev); +return ret; +} + +static int +hinic3_dev_reset(__rte_unused struct rte_eth_dev *dev) +{ +return 0 ; +} + +#define MIN_RX_BUFFER_SIZE 256 +#define MIN_RX_BUFFER_SIZE_SMALL_MODE 1518 + +static int +hinic3_dev_set_mtu (struct rte_eth_dev *dev,uint16_t mtu) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int err =0 ; + +PMD_DRV_LOG (INFO ,"Set port mtu, port_id: %d, mtu: %d, max_pkt_len: %d" , + dev->data->port_id, mtu,HINIC3_MTU_TO_PKTLEN (mtu)); + +if (mtu <HINIC3_MIN_MTU_SIZE || mtu >HINIC3_MAX_MTU_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid mtu: %d, must between %d and %d" , mtu, +HINIC3_MIN_MTU_SIZE ,HINIC3_MAX_MTU_SIZE ); +return -EINVAL ; + } + + err =hinic3_set_port_mtu (nic_dev->hwdev, mtu); +if (err) { +PMD_DRV_LOG (ERR ,"Set port mtu failed, err: %d" , err); +return err; + } + +/* Update max frame size. */ +HINIC3_MAX_RX_PKT_LEN (dev->data->dev_conf.rxmode) = +HINIC3_MTU_TO_PKTLEN (mtu); + nic_dev->mtu_size = mtu; +return err; +} + +/** +* Add or delete vlan id. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] vlan_id +* Vlan id is used to filter vlan packets. +* @param[in] enable +* Disable or enable vlan filter function. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_vlan_filter_set (struct rte_eth_dev *dev,uint16_t vlan_id,int enable) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int err =0 ; +u16 func_id; + +if (vlan_id >=RTE_ETHER_MAX_VLAN_ID ) +return -EINVAL ; + +if (vlan_id ==0 ) +return 0 ; + + func_id =hinic3_global_func_id (nic_dev->hwdev); + +if (enable) { +/* If vlanid is already set, just return. */ +if (hinic3_find_vlan_filter (nic_dev, vlan_id)) { +PMD_DRV_LOG (INFO ,"Vlan %u has been added, device: %s" , + vlan_id, nic_dev->dev_name); +return 0 ; + } + + err =hinic3_add_vlan (nic_dev->hwdev, vlan_id, func_id); + }else { +/* If vlanid can't be found, just return. */ +if (!hinic3_find_vlan_filter (nic_dev, vlan_id)) { +PMD_DRV_LOG (INFO , +"Vlan %u is not in the vlan filter list, " +"device: %s" , + vlan_id, nic_dev->dev_name); +return 0 ; + } + + err =hinic3_del_vlan (nic_dev->hwdev, vlan_id, func_id); + } + +if (err) { +PMD_DRV_LOG (ERR , +"%s vlan failed, func_id: %d, vlan_id: %d, err: %d" , + enable ?"Add" :"Remove" , func_id, vlan_id, err); +return err; + } + +hinic3_store_vlan_filter (nic_dev, vlan_id, enable); + +PMD_DRV_LOG (INFO ,"%s vlan %u succeed, device: %s" , + enable ?"Add" :"Remove" , vlan_id, nic_dev->dev_name); + +return 0 ; +} + +/** +* Enable or disable vlan offload. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] mask +* Definitions used for VLAN setting, vlan filter of vlan strip. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_vlan_offload_set (struct rte_eth_dev *dev,int mask) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode; +bool on; +int err; + +/* Enable or disable VLAN filter. */ +if (mask &RTE_ETH_VLAN_FILTER_MASK ) { + on = (rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_FILTER ) + ? true + : false; + err =hinic3_set_vlan_fliter (nic_dev->hwdev, on); +if (err) { +PMD_DRV_LOG (ERR , +"%s vlan filter failed, device: %s, " +"port_id: %d, err: %d" , + on ?"Enable" :"Disable" , + nic_dev->dev_name, dev->data->port_id, err); +return err; + } + +PMD_DRV_LOG (INFO , +"%s vlan filter succeed, device: %s, port_id: %d" , + on ?"Enable" :"Disable" , nic_dev->dev_name, + dev->data->port_id); + } + +/* Enable or disable VLAN stripping. */ +if (mask &RTE_ETH_VLAN_STRIP_MASK ) { + on = (rxmode->offloads &RTE_ETH_RX_OFFLOAD_VLAN_STRIP ) ? true + : false; + err =hinic3_set_rx_vlan_offload (nic_dev->hwdev, on); +if (err) { +PMD_DRV_LOG (ERR , +"%s vlan strip failed, device: %s, " +"port_id: %d, err: %d" , + on ?"Enable" :"Disable" , + nic_dev->dev_name, dev->data->port_id, err); +return err; + } + +PMD_DRV_LOG (INFO , +"%s vlan strip succeed, device: %s, port_id: %d" , + on ?"Enable" :"Disable" , nic_dev->dev_name, + dev->data->port_id); + } +return 0 ; +} + +/** +* Enable allmulticast mode. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_allmulticast_enable (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u32 rx_mode; +int err; + + err =hinic3_mutex_lock (&nic_dev->rx_mode_mutex); +if (err) +return err; + + rx_mode = nic_dev->rx_mode |HINIC3_RX_MODE_MC_ALL ; + + err =hinic3_set_rx_mode (nic_dev->hwdev, rx_mode); +if (err) { + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); +PMD_DRV_LOG (ERR ,"Enable allmulticast failed, error: %d" , err); +return err; + } + + nic_dev->rx_mode = rx_mode; + + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); + +PMD_DRV_LOG (INFO , +"Enable allmulticast succeed, nic_dev: %s, port_id: %d" , + nic_dev->dev_name, dev->data->port_id); +return 0 ; +} + +/** +* Disable allmulticast mode. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_allmulticast_disable (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u32 rx_mode; +int err; + + err =hinic3_mutex_lock (&nic_dev->rx_mode_mutex); +if (err) +return err; + + rx_mode = nic_dev->rx_mode & (~HINIC3_RX_MODE_MC_ALL ); + + err =hinic3_set_rx_mode (nic_dev->hwdev, rx_mode); +if (err) { + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); +PMD_DRV_LOG (ERR ,"Disable allmulticast failed, error: %d" , err); +return err; + } + + nic_dev->rx_mode = rx_mode; + + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); + +PMD_DRV_LOG (INFO , +"Disable allmulticast succeed, nic_dev: %s, port_id: %d" , + nic_dev->dev_name, dev->data->port_id); +return 0 ; +} + +/** +* Get device generic statistics. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[out] stats +* Stats structure output buffer. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_stats_get (struct rte_eth_dev *dev,struct rte_eth_stats *stats) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct hinic3_vport_stats vport_stats; +struct hinic3_rxq *rxq =NULL ; +struct hinic3_txq *txq =NULL ; +int i, err, q_num; +u64 rx_discards_pmd =0 ; + + err =hinic3_get_vport_stats (nic_dev->hwdev, &vport_stats); +if (err) { +PMD_DRV_LOG (ERR ,"Get vport stats from fw failed, nic_dev: %s" , + nic_dev->dev_name); +return err; + } + + dev->data->rx_mbuf_alloc_failed =0 ; + +/* Rx queue stats. */ + q_num = (nic_dev->num_rqs <RTE_ETHDEV_QUEUE_STAT_CNTRS ) + ? nic_dev->num_rqs + :RTE_ETHDEV_QUEUE_STAT_CNTRS ; +for (i =0 ; i < q_num; i++) { + rxq = nic_dev->rxqs[i]; +#ifdef HINIC3_XSTAT_MBUF_USE + rxq->rxq_stats.rx_left_mbuf_bytes = + rxq->rxq_stats.rx_alloc_mbuf_bytes - + rxq->rxq_stats.rx_free_mbuf_bytes; +#endif + rxq->rxq_stats.errors = rxq->rxq_stats.csum_errors + + rxq->rxq_stats.other_errors; + + stats->q_ipackets[i] = rxq->rxq_stats.packets; + stats->q_ibytes[i] = rxq->rxq_stats.bytes; + stats->q_errors[i] = rxq->rxq_stats.errors; + + stats->ierrors += rxq->rxq_stats.errors; + rx_discards_pmd += rxq->rxq_stats.dropped; + dev->data->rx_mbuf_alloc_failed += rxq->rxq_stats.rx_nombuf; + } + +/* Tx queue stats. */ + q_num = (nic_dev->num_sqs <RTE_ETHDEV_QUEUE_STAT_CNTRS ) + ? nic_dev->num_sqs + :RTE_ETHDEV_QUEUE_STAT_CNTRS ; +for (i =0 ; i < q_num; i++) { + txq = nic_dev->txqs[i]; + stats->q_opackets[i] = txq->txq_stats.packets; + stats->q_obytes[i] = txq->txq_stats.bytes; + stats->oerrors += (txq->txq_stats.tx_busy + + txq->txq_stats.offload_errors); + } + +/* Vport stats. */ + stats->oerrors += vport_stats.tx_discard_vport; + + stats->imissed = vport_stats.rx_discard_vport + rx_discards_pmd; + + stats->ipackets = + (vport_stats.rx_unicast_pkts_vport + + vport_stats.rx_multicast_pkts_vport + + vport_stats.rx_broadcast_pkts_vport - rx_discards_pmd); + + stats->opackets = (vport_stats.tx_unicast_pkts_vport + + vport_stats.tx_multicast_pkts_vport + + vport_stats.tx_broadcast_pkts_vport); + + stats->ibytes = (vport_stats.rx_unicast_bytes_vport + + vport_stats.rx_multicast_bytes_vport + + vport_stats.rx_broadcast_bytes_vport); + + stats->obytes = (vport_stats.tx_unicast_bytes_vport + + vport_stats.tx_multicast_bytes_vport + + vport_stats.tx_broadcast_bytes_vport); +return 0 ; +} +/** -* Interrupt handler triggered by NIC for handling specific event. +* Clear device generic statistics. * -* @param[in] param -* The address of parameter (struct rte_eth_dev *) regsitered before. +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_stats_reset (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct hinic3_rxq *rxq =NULL ; +struct hinic3_txq *txq =NULL ; +int qid; +int err; + + err =hinic3_clear_vport_stats (nic_dev->hwdev); +if (err) +return err; + +for (qid =0 ; qid < nic_dev->num_rqs; qid++) { + rxq = nic_dev->rxqs[qid]; +memset (&rxq->rxq_stats,0 ,sizeof (struct hinic3_rxq_stats )); + } + +for (qid =0 ; qid < nic_dev->num_sqs; qid++) { + txq = nic_dev->txqs[qid]; +memset (&txq->txq_stats,0 ,sizeof (struct hinic3_txq_stats )); + } + +return 0 ; +} + +/** +* Get device extended statistics. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[out] xstats +* Pointer to rte extended stats table. +* @param[in] n +* The size of the stats table. +* +* @return +* positive: Number of extended stats on success and stats is filled. +* negative: Failure. +*/ +static int +hinic3_dev_xstats_get (struct rte_eth_dev *dev,struct rte_eth_xstat *xstats, +unsigned int n) +{ +struct hinic3_nic_dev *nic_dev; +struct mag_phy_port_stats port_stats; +struct hinic3_vport_stats vport_stats; +struct hinic3_rxq *rxq =NULL ; +struct hinic3_rxq_stats rxq_stats; +struct hinic3_txq *txq =NULL ; +struct hinic3_txq_stats txq_stats; +u16 qid; +u32 i; +int err, count; + + nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + count =hinic3_xstats_calc_num (nic_dev); +if ((int )n < count) +return count; + + count =0 ; + +/* Get stats from rxq stats structure. */ +for (qid =0 ; qid < nic_dev->num_rqs; qid++) { + rxq = nic_dev->rxqs[qid]; + +#ifdef HINIC3_XSTAT_RXBUF_INFO +hinic3_get_stats (rxq); +#endif + +#ifdef HINIC3_XSTAT_MBUF_USE + rxq->rxq_stats.rx_left_mbuf_bytes = + rxq->rxq_stats.rx_alloc_mbuf_bytes - + rxq->rxq_stats.rx_free_mbuf_bytes; +#endif + rxq->rxq_stats.errors = rxq->rxq_stats.csum_errors + + rxq->rxq_stats.other_errors; + +memcpy ((void *)&rxq_stats, (void *)&rxq->rxq_stats, +sizeof (rxq->rxq_stats)); + +for (i =0 ; i <HINIC3_RXQ_XSTATS_NUM ; i++) { + xstats[count].value = *(uint64_t *)(((char *)&rxq_stats) + + hinic3_rxq_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + } + +/* Get stats from txq stats structure. */ +for (qid =0 ; qid < nic_dev->num_sqs; qid++) { + txq = nic_dev->txqs[qid]; +memcpy ((void *)&txq_stats, (void *)&txq->txq_stats, +sizeof (txq->txq_stats)); + +for (i =0 ; i <HINIC3_TXQ_XSTATS_NUM ; i++) { + xstats[count].value = *(uint64_t *)(((char *)&txq_stats) + + hinic3_txq_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + } + +/* Get stats from vport stats structure. */ + err =hinic3_get_vport_stats (nic_dev->hwdev, &vport_stats); +if (err) +return err; + +for (i =0 ; i <HINIC3_VPORT_XSTATS_NUM ; i++) { + xstats[count].value = + *(uint64_t *)(((char *)&vport_stats) + + hinic3_vport_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + +if (HINIC3_IS_VF (nic_dev->hwdev)) +return count; + +/* Get stats from phy port stats structure. */ + err =hinic3_get_phy_port_stats (nic_dev->hwdev, &port_stats); +if (err) +return err; + +for (i =0 ; i <HINIC3_PHYPORT_XSTATS_NUM ; i++) { + xstats[count].value = + *(uint64_t *)(((char *)&port_stats) + + hinic3_phyport_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + +return count; +} + +/** +* Clear device extended statistics. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_xstats_reset (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int err; + + err =hinic3_dev_stats_reset (dev); +if (err) +return err; + +if (hinic3_func_type (nic_dev->hwdev) !=TYPE_VF ) { + err =hinic3_clear_phy_port_stats (nic_dev->hwdev); +if (err) +return err; + } + +return 0 ; +} + +/** +* Retrieve names of extended device statistics. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[out] xstats_names +* Buffer to insert names into. +* +* @return +* Number of xstats names. +*/ +static int +hinic3_dev_xstats_get_names (struct rte_eth_dev *dev, +struct rte_eth_xstat_name *xstats_names, + __rte_unused unsigned int limit) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int count =0 ; +u16 i, q_num; + +if (xstats_names ==NULL ) +return hinic3_xstats_calc_num (nic_dev); + +/* Get pmd rxq stats name. */ +for (q_num =0 ; q_num < nic_dev->num_rqs; q_num++) { +for (i =0 ; i <HINIC3_RXQ_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name), +"rxq%d_%s_pmd" , q_num, + hinic3_rxq_stats_strings[i].name); + count++; + } + } + +/* Get pmd txq stats name. */ +for (q_num =0 ; q_num < nic_dev->num_sqs; q_num++) { +for (i =0 ; i <HINIC3_TXQ_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name), +"txq%d_%s_pmd" , q_num, + hinic3_txq_stats_strings[i].name); + count++; + } + } + +/* Get vport stats name. */ +for (i =0 ; i <HINIC3_VPORT_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name),"%s" , + hinic3_vport_stats_strings[i].name); + count++; + } + +if (HINIC3_IS_VF (nic_dev->hwdev)) +return count; + +/* Get phy port stats name. */ +for (i =0 ; i <HINIC3_PHYPORT_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name),"%s" , + hinic3_phyport_stats_strings[i].name); + count++; + } + +return count; +} + +/** +* Function used to get supported ptypes of an Ethernet device. +* +* @param[in] dev +* ethdev handle of port. +* @param[out] no_of_elements +* number of ptypes elements. Must be initialized to 0. +* +* @return +* Success, array of ptypes elements and valid no_of_elements > 0. +* Failures, NULL. */ +static const uint32_t * +hinic3_dev_supported_ptypes_get(__rte_unused struct rte_eth_dev *dev, + __rte_unused size_t *no_of_elements) +{ +return 0 ; +} +static void -hinic3_dev_interrupt_handler (void *param) +hinic3_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_rxq_info *rxq_info) +{ +struct hinic3_rxq *rxq = dev->data->rx_queues[queue_id]; + + rxq_info->mp = rxq->mb_pool; + rxq_info->nb_desc = rxq->q_depth; +} + +static void +hinic3_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_txq_info *txq_qinfo) +{ +struct hinic3_txq *txq = dev->data->tx_queues[queue_id]; + + txq_qinfo->nb_desc = txq->q_depth; +} + +/** +* Update MAC address. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] addr +* Pointer to MAC address. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_set_mac_addr (struct rte_eth_dev *dev,struct rte_ether_addr *addr) { -struct rte_eth_dev *dev = param;struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +char mac_addr[RTE_ETHER_ADDR_FMT_SIZE ]; +u16 func_id; +int err; -if (!hinic3_get_bit (HINIC3_DEV_INTR_EN , &nic_dev->dev_status)) { -PMD_DRV_LOG (WARNING , -"Intr is disabled, ignore intr event, " -"dev_name: %s, port_id: %d" , - nic_dev->dev_name, dev->data->port_id); +if (!rte_is_valid_assigned_ether_addr (addr)) { +rte_ether_format_addr (mac_addr,RTE_ETHER_ADDR_FMT_SIZE , addr); +PMD_DRV_LOG (ERR ,"Set invalid MAC address %s" , mac_addr); +return -EINVAL ; + } + + func_id =hinic3_global_func_id (nic_dev->hwdev); + err =hinic3_update_mac (nic_dev->hwdev, + nic_dev->default_addr.addr_bytes, + addr->addr_bytes,0 , func_id); +if (err) +return err; + +rte_ether_addr_copy (addr, &nic_dev->default_addr); +rte_ether_format_addr (mac_addr,RTE_ETHER_ADDR_FMT_SIZE , + &nic_dev->default_addr); + +PMD_DRV_LOG (INFO ,"Set new MAC address %s" , mac_addr); +return 0 ; +} + +/** +* Remove a MAC address. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] index +* MAC address index. +*/ +static void +hinic3_mac_addr_remove (struct rte_eth_dev *dev,uint32_t index) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u16 func_id; +int err; + +if (index >=HINIC3_MAX_UC_MAC_ADDRS ) { +PMD_DRV_LOG (INFO ,"Remove MAC index(%u) is out of range" , + index);return ; } -/* Aeq0 msg handler. */ -hinic3_dev_handle_aeq_event (nic_dev->hwdev, param); + func_id =hinic3_global_func_id (nic_dev->hwdev); + err =hinic3_del_mac (nic_dev->hwdev, + dev->data->mac_addrs[index].addr_bytes,0 , + func_id); +if (err) +PMD_DRV_LOG (ERR ,"Remove MAC index(%u) failed" , index); +} + +/** +* Add a MAC address. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] mac_addr +* MAC address to register. +* @param[in] index +* MAC address index. +* @param[in] vmdq +* VMDq pool index to associate address with (unused_). +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_mac_addr_add (struct rte_eth_dev *dev,struct rte_ether_addr *mac_addr, + uint32_t index, __rte_unused uint32_t vmdq) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +unsigned int i; +u16 func_id; +int err; + +if (!rte_is_valid_assigned_ether_addr (mac_addr)) { +PMD_DRV_LOG (ERR ,"Add invalid MAC address" ); +return -EINVAL ; + } + +if (index >=HINIC3_MAX_UC_MAC_ADDRS ) { +PMD_DRV_LOG (ERR ,"Add MAC index(%u) is out of range" , index); +return -EINVAL ; + } + +/* Make sure this address doesn't already be configured. */ +for (i =0 ; i <HINIC3_MAX_UC_MAC_ADDRS ; i++) { +if (rte_is_same_ether_addr (mac_addr, + &dev->data->mac_addrs[i])) { +PMD_DRV_LOG (ERR ,"MAC address is already configured" ); +return -EADDRINUSE ; + } + } + + func_id =hinic3_global_func_id (nic_dev->hwdev); + err =hinic3_set_mac (nic_dev->hwdev, mac_addr->addr_bytes,0 , func_id); +if (err) +return err; + +return 0 ; } +/** +* Delete all multicast MAC addresses from the NIC device. +* +* This function iterates over the list of multicast MAC addresses and removes +* each address from the NIC device by calling `hinic3_del_mac`. After each +* deletion, the address is reset to zero. +* +* @param[in] nic_dev +* Pointer to NIC device structure. +*/ static void -hinic3_deinit_sw_rxtxqs (struct hinic3_nic_dev *nic_dev) +hinic3_delete_mc_addr_list (struct hinic3_nic_dev *nic_dev) { -rte_free (nic_dev->txqs); - nic_dev->txqs =NULL ; +u16 func_id; +u32 i; -rte_free (nic_dev->rxqs); - nic_dev->rxqs =NULL ; + func_id =hinic3_global_func_id (nic_dev->hwdev); + +for (i =0 ; i <HINIC3_MAX_MC_MAC_ADDRS ; i++) { +if (rte_is_zero_ether_addr (&nic_dev->mc_list[i])) +break ; + +hinic3_del_mac (nic_dev->hwdev, nic_dev->mc_list[i].addr_bytes, +0 , func_id); +memset (&nic_dev->mc_list[i],0 ,sizeof (struct rte_ether_addr )); + } +} + +/** +* Set multicast MAC address. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] mc_addr_set +* Pointer to multicast MAC address. +* @param[in] nb_mc_addr +* The number of multicast MAC address to set. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_set_mc_addr_list (struct rte_eth_dev *dev, +struct rte_ether_addr *mc_addr_set,uint32_t nb_mc_addr) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +char mac_addr[RTE_ETHER_ADDR_FMT_SIZE ]; +u16 func_id; +int err; +u32 i; + + func_id =hinic3_global_func_id (nic_dev->hwdev); + +/* Delete old multi_cast addrs firstly. */ +hinic3_delete_mc_addr_list (nic_dev); + +if (nb_mc_addr >HINIC3_MAX_MC_MAC_ADDRS ) +return -EINVAL ; + +for (i =0 ; i < nb_mc_addr; i++) { +if (!rte_is_multicast_ether_addr (&mc_addr_set[i])) { +rte_ether_format_addr (mac_addr,RTE_ETHER_ADDR_FMT_SIZE , + &mc_addr_set[i]); +PMD_DRV_LOG (ERR , +"Set mc MAC addr failed, addr(%s) invalid" , + mac_addr); +return -EINVAL ; + } + } + +for (i =0 ; i < nb_mc_addr; i++) { + err =hinic3_set_mac (nic_dev->hwdev, mc_addr_set[i].addr_bytes, +0 , func_id); +if (err) { +hinic3_delete_mc_addr_list (nic_dev); +return err; + } + +rte_ether_addr_copy (&mc_addr_set[i], &nic_dev->mc_list[i]); + } + +return 0 ; +} + +static int +hinic3_get_reg(__rte_unused struct rte_eth_dev *dev, + __rte_unused struct rte_dev_reg_info *regs) +{ +return 0 ; } +static const struct eth_dev_ops hinic3_pmd_ops = { + .dev_configure = hinic3_dev_configure, + .dev_infos_get = hinic3_dev_infos_get, + .fw_version_get = hinic3_fw_version_get, + .dev_set_link_up = hinic3_dev_set_link_up, + .dev_set_link_down = hinic3_dev_set_link_down, + .link_update = hinic3_link_update, + .rx_queue_setup = hinic3_rx_queue_setup, + .tx_queue_setup = hinic3_tx_queue_setup, + .rx_queue_release = hinic3_rx_queue_release, + .tx_queue_release = hinic3_tx_queue_release, + .rx_queue_start = hinic3_dev_rx_queue_start, + .rx_queue_stop = hinic3_dev_rx_queue_stop, + .tx_queue_start = hinic3_dev_tx_queue_start, + .tx_queue_stop = hinic3_dev_tx_queue_stop, + .rx_queue_intr_enable = hinic3_dev_rx_queue_intr_enable, + .rx_queue_intr_disable = hinic3_dev_rx_queue_intr_disable, + .dev_start = hinic3_dev_start, + .dev_stop = hinic3_dev_stop, + .dev_close = hinic3_dev_close, + .dev_reset = hinic3_dev_reset, + .mtu_set = hinic3_dev_set_mtu, + .vlan_filter_set = hinic3_vlan_filter_set, + .vlan_offload_set = hinic3_vlan_offload_set, + .allmulticast_enable = hinic3_dev_allmulticast_enable, + .allmulticast_disable = hinic3_dev_allmulticast_disable, + .stats_get = hinic3_dev_stats_get, + .stats_reset = hinic3_dev_stats_reset, + .xstats_get = hinic3_dev_xstats_get, + .xstats_reset = hinic3_dev_xstats_reset, + .xstats_get_names = hinic3_dev_xstats_get_names, + .dev_supported_ptypes_get = hinic3_dev_supported_ptypes_get, + .rxq_info_get = hinic3_rxq_info_get, + .txq_info_get = hinic3_txq_info_get, + .mac_addr_set = hinic3_set_mac_addr, + .mac_addr_remove = hinic3_mac_addr_remove, + .mac_addr_add = hinic3_mac_addr_add, + .set_mc_addr_list = hinic3_set_mc_addr_list, + .get_reg = hinic3_get_reg, +}; + +static const struct eth_dev_ops hinic3_pmd_vf_ops = { + .dev_configure = hinic3_dev_configure, + .dev_infos_get = hinic3_dev_infos_get, + .fw_version_get = hinic3_fw_version_get, + .rx_queue_setup = hinic3_rx_queue_setup, + .tx_queue_setup = hinic3_tx_queue_setup, + .rx_queue_intr_enable = hinic3_dev_rx_queue_intr_enable, + .rx_queue_intr_disable = hinic3_dev_rx_queue_intr_disable, + + .rx_queue_start = hinic3_dev_rx_queue_start, + .rx_queue_stop = hinic3_dev_rx_queue_stop, + .tx_queue_start = hinic3_dev_tx_queue_start, + .tx_queue_stop = hinic3_dev_tx_queue_stop, + + .dev_start = hinic3_dev_start, + .link_update = hinic3_link_update, + .rx_queue_release = hinic3_rx_queue_release, + .tx_queue_release = hinic3_tx_queue_release, + .dev_stop = hinic3_dev_stop, + .dev_close = hinic3_dev_close, + .mtu_set = hinic3_dev_set_mtu, + .vlan_filter_set = hinic3_vlan_filter_set, + .vlan_offload_set = hinic3_vlan_offload_set, + .allmulticast_enable = hinic3_dev_allmulticast_enable, + .allmulticast_disable = hinic3_dev_allmulticast_disable, + .stats_get = hinic3_dev_stats_get, + .stats_reset = hinic3_dev_stats_reset, + .xstats_get = hinic3_dev_xstats_get, + .xstats_reset = hinic3_dev_xstats_reset, + .xstats_get_names = hinic3_dev_xstats_get_names, + .rxq_info_get = hinic3_rxq_info_get, + .txq_info_get = hinic3_txq_info_get, + .mac_addr_set = hinic3_set_mac_addr, + .mac_addr_remove = hinic3_mac_addr_remove, + .mac_addr_add = hinic3_mac_addr_add, + .set_mc_addr_list = hinic3_set_mc_addr_list, +}; +/** * Init mac_vlan table in hardwares. *
@@ -319,6 +3194,15 @@ hinic3_func_init(struct rte_eth_dev *eth_dev) nic_dev->max_sqs =hinic3_func_max_sqs (nic_dev->hwdev); nic_dev->max_rqs =hinic3_func_max_rqs (nic_dev->hwdev); +if (HINIC3_FUNC_TYPE (nic_dev->hwdev) ==TYPE_VF ) + eth_dev->dev_ops = &hinic3_pmd_vf_ops; +else + eth_dev->dev_ops = &hinic3_pmd_ops; + + eth_dev->rx_queue_count = hinic3_dev_rx_queue_count; + eth_dev->rx_descriptor_status = hinic3_dev_rx_descriptor_status; + eth_dev->tx_descriptor_status = hinic3_dev_tx_descriptor_status; + err =hinic3_init_nic_hwdev (nic_dev->hwdev);if (err) { PMD_DRV_LOG(ERR, "Init nic hwdev failed, dev_name: %s",
drivers/net/hinic3/hinic3_nic_io.c new file +827 -0
51 lines not on this page · raw message
drivers/net/hinic3/hinic3_nic_io.h new file +169 -0
169 lines not on this page · raw message
drivers/net/hinic3/hinic3_rx.c new file +811 -0
811 lines not on this page · raw message
drivers/net/hinic3/hinic3_rx.h new file +356 -0
356 lines not on this page · raw message
drivers/net/hinic3/hinic3_tx.c new file +274 -0
274 lines not on this page · raw message
drivers/net/hinic3/hinic3_tx.h new file +314 -0
314 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.47.0.windows.2
Part of the diff is not shown here. View the raw message.
RFC 14/18 net/hinic3: add Rx/Tx functions
In reply to Feifei WangFrom: Feifei Wang <[email protected]>
This patch add package sending and receiving function codes.
--- drivers/net/hinic3/hinic3_ethdev.c | 9 +- drivers/net/hinic3/hinic3_rx.c | 301 +++++++++++- drivers/net/hinic3/hinic3_tx.c | 754 +++++++++++++++++++++++++++++ drivers/net/hinic3/hinic3_tx.h | 1 + 4 files changed, 1054 insertions(+), 11 deletions(-)
drivers/net/hinic3/hinic3_ethdev.c +6 -3
@@ -21,9 +21,9 @@#include "base/hinic3_hw_comm.h" #include "base/hinic3_nic_cfg.h" #include "base/hinic3_nic_event.h" -#include "hinic3_pmd_nic_io.h" -#include "hinic3_pmd_tx.h" -#include "hinic3_pmd_rx.h" +#include "hinic3_nic_io.h" +#include "hinic3_tx.h" +#include "hinic3_rx.h" #include "hinic3_ethdev.h" #define HINIC3_MIN_RX_BUF_SIZE 1024
@@ -3337,6 +3337,9 @@ hinic3_dev_init(struct rte_eth_dev *eth_dev)PMD_DRV_LOG (INFO ,"Network Interface pmd driver version: %s" ,HINIC3_PMD_DRV_VERSION ); + eth_dev->rx_pkt_burst = hinic3_recv_pkts; + eth_dev->tx_pkt_burst = hinic3_xmit_pkts; +return hinic3_func_init (eth_dev); }
drivers/net/hinic3/hinic3_rx.c +293 -8
310 lines not on this page · raw message
drivers/net/hinic3/hinic3_tx.c +754 -0
766 lines not on this page · raw message
drivers/net/hinic3/hinic3_tx.h +1 -0
@@ -308,6 +308,7 @@ struct __rte_cache_aligned hinic3_txq {void hinic3_flush_txqs (struct hinic3_nic_dev *nic_dev);void hinic3_free_txq_mbufs (struct hinic3_txq *txq);void hinic3_free_all_txq_mbufs (struct hinic3_nic_dev *nic_dev); +u16 hinic3_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,u16 nb_pkts);int hinic3_stop_sq (struct hinic3_txq *txq);int hinic3_start_all_sqs (struct rte_eth_dev *eth_dev);int hinic3_tx_done_cleanup (void *txq,uint32_t free_cnt);
Signature · 1 line
2.47.0.windows.2
RFC 15/18 net/hinic3: add MML and EEPROM access feature
In reply to Feifei WangFrom: Xin Wang <[email protected]>
Add man-machine language support and implements the get eeprom method.
--- drivers/net/hinic3/hinic3_ethdev.c | 13 + drivers/net/hinic3/mml/hinic3_dbg.c | 171 +++++ drivers/net/hinic3/mml/hinic3_dbg.h | 160 +++++ drivers/net/hinic3/mml/hinic3_mml_cmd.c | 375 +++++++++++ drivers/net/hinic3/mml/hinic3_mml_cmd.h | 131 ++++ drivers/net/hinic3/mml/hinic3_mml_ioctl.c | 215 +++++++ drivers/net/hinic3/mml/hinic3_mml_lib.c | 136 ++++ drivers/net/hinic3/mml/hinic3_mml_lib.h | 275 ++++++++ drivers/net/hinic3/mml/hinic3_mml_main.c | 167 +++++ drivers/net/hinic3/mml/hinic3_mml_queue.c | 749 ++++++++++++++++++++++ drivers/net/hinic3/mml/hinic3_mml_queue.h | 256 ++++++++ drivers/net/hinic3/mml/meson.build | 62 ++ 12 files changed, 2710 insertions(+) create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.c create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.h create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.h create mode 100644 drivers/net/hinic3/mml/hinic3_mml_ioctl.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.h create mode 100644 drivers/net/hinic3/mml/hinic3_mml_main.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.c create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.h create mode 100644 drivers/net/hinic3/mml/meson.build
drivers/net/hinic3/hinic3_ethdev.c +13 -0
@@ -21,6 +21,7 @@#include "base/hinic3_hw_comm.h" #include "base/hinic3_nic_cfg.h" #include "base/hinic3_nic_event.h" +#include "mml/hinic3_mml_lib.h" #include "hinic3_nic_io.h" #include "hinic3_tx.h" #include "hinic3_rx.h"
@@ -2276,6 +2277,16 @@ hinic3_dev_allmulticast_disable(struct rte_eth_dev *dev)return 0 ; } +static int +hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev, +struct rte_dev_eeprom_info *info) +{ +#define MAX_BUF_OUT_LEN 2048 + +return hinic3_pmd_mml_lib (info->data, info->offset, info->data, + &info->length,MAX_BUF_OUT_LEN ); +} +/** * Get device generic statistics. *
@@ -2879,6 +2890,7 @@ static const struct eth_dev_ops hinic3_pmd_ops = { .vlan_offload_set = hinic3_vlan_offload_set, .allmulticast_enable = hinic3_dev_allmulticast_enable, .allmulticast_disable = hinic3_dev_allmulticast_disable, + .get_eeprom = hinic3_get_eeprom, .stats_get = hinic3_dev_stats_get, .stats_reset = hinic3_dev_stats_reset, .xstats_get = hinic3_dev_xstats_get,
@@ -2919,6 +2931,7 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = { .vlan_offload_set = hinic3_vlan_offload_set, .allmulticast_enable = hinic3_dev_allmulticast_enable, .allmulticast_disable = hinic3_dev_allmulticast_disable, + .get_eeprom = hinic3_get_eeprom, .stats_get = hinic3_dev_stats_get, .stats_reset = hinic3_dev_stats_reset, .xstats_get = hinic3_dev_xstats_get,
drivers/net/hinic3/mml/hinic3_dbg.c new file +171 -0
171 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_dbg.h new file +160 -0
160 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_cmd.c new file +375 -0
375 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_cmd.h new file +131 -0
131 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_ioctl.c new file +215 -0
215 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_lib.c new file +136 -0
136 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_lib.h new file +275 -0
275 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_main.c new file +167 -0
167 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_queue.c new file +749 -0
749 lines not on this page · raw message
drivers/net/hinic3/mml/hinic3_mml_queue.h new file +256 -0
256 lines not on this page · raw message
drivers/net/hinic3/mml/meson.build new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.47.0.windows.2
RFC 16/18 net/hinic3: add RSS promiscuous ops
In reply to Feifei WangFrom: Xin Wang <[email protected]>
Add RSS and promiscuous ops related function codes.
--- drivers/net/hinic3/hinic3_ethdev.c | 370 +++++++++++++++++++++++++++++ drivers/net/hinic3/hinic3_ethdev.h | 31 +++ 2 files changed, 401 insertions(+)
drivers/net/hinic3/hinic3_ethdev.c +370 -0
@@ -2277,6 +2277,281 @@ hinic3_dev_allmulticast_disable(struct rte_eth_dev *dev)return 0 ; } +/** +* Enable promiscuous mode. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_promiscuous_enable (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u32 rx_mode; +int err; + + err =hinic3_mutex_lock (&nic_dev->rx_mode_mutex); +if (err) +return err; + + rx_mode = nic_dev->rx_mode |HINIC3_RX_MODE_PROMISC ; + + err =hinic3_set_rx_mode (nic_dev->hwdev, rx_mode); +if (err) { + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); +PMD_DRV_LOG (ERR ,"Enable promiscuous failed" ); +return err; + } + + nic_dev->rx_mode = rx_mode; + + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); + +PMD_DRV_LOG (INFO , +"Enable promiscuous, nic_dev: %s, port_id: %d, promisc: %d" , + nic_dev->dev_name, dev->data->port_id, + dev->data->promiscuous); +return 0 ; +} + +/** +* Disable promiscuous mode. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_promiscuous_disable (struct rte_eth_dev *dev) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u32 rx_mode; +int err; + + err =hinic3_mutex_lock (&nic_dev->rx_mode_mutex); +if (err) +return err; + + rx_mode = nic_dev->rx_mode & (~HINIC3_RX_MODE_PROMISC ); + + err =hinic3_set_rx_mode (nic_dev->hwdev, rx_mode); +if (err) { + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); +PMD_DRV_LOG (ERR ,"Disable promiscuous failed" ); +return err; + } + + nic_dev->rx_mode = rx_mode; + + (void )hinic3_mutex_unlock (&nic_dev->rx_mode_mutex); + +PMD_DRV_LOG (INFO , +"Disable promiscuous, nic_dev: %s, port_id: %d, promisc: %d" , + nic_dev->dev_name, dev->data->port_id, dev->data->promiscuous); +return 0 ; +} + +/** +* Get flow control configuration, including auto-negotiation and RX/TX pause +* settings. +* +* @param[in] dev +* Pointer to ethernet device structure. +* +* @param[out] fc_conf +* The flow control configuration to be filled. +* +* @return +* 0 on success, non-zero on failure. +*/ + +/** +* Update the RSS hash key and RSS hash type. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] rss_conf +* RSS configuration data. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_rss_hash_update (struct rte_eth_dev *dev, +struct rte_eth_rss_conf *rss_conf) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct hinic3_rss_type rss_type = {0 }; +u64 rss_hf = rss_conf->rss_hf; +int err =0 ; + +if (nic_dev->rss_state ==HINIC3_RSS_DISABLE ) { +if (rss_hf !=0 ) +return -EINVAL ; + +PMD_DRV_LOG (INFO ,"RSS is not enabled" ); +return 0 ; + } + +if (rss_conf->rss_key_len >HINIC3_RSS_KEY_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid RSS key, rss_key_len: %d" , + rss_conf->rss_key_len); +return -EINVAL ; + } + +if (rss_conf->rss_key) { + err =hinic3_rss_set_hash_key (nic_dev->hwdev, nic_dev->rss_key, +HINIC3_RSS_KEY_SIZE ); +if (err) { +PMD_DRV_LOG (ERR ,"Set RSS hash key failed" ); +return err; + } +memcpy ((void *)nic_dev->rss_key, (void *)rss_conf->rss_key, + (size_t )rss_conf->rss_key_len); + } + + rss_type.ipv4 = (rss_hf & (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 | +RTE_ETH_RSS_NONFRAG_IPV4_OTHER )) + ?1 + :0 ; + rss_type.tcp_ipv4 = (rss_hf &RTE_ETH_RSS_NONFRAG_IPV4_TCP ) ?1 :0 ; + rss_type.ipv6 = (rss_hf & (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 | +RTE_ETH_RSS_NONFRAG_IPV6_OTHER )) + ?1 + :0 ; + rss_type.ipv6_ext = (rss_hf &RTE_ETH_RSS_IPV6_EX ) ?1 :0 ; + rss_type.tcp_ipv6 = (rss_hf &RTE_ETH_RSS_NONFRAG_IPV6_TCP ) ?1 :0 ; + rss_type.tcp_ipv6_ext = (rss_hf &RTE_ETH_RSS_IPV6_TCP_EX ) ?1 :0 ; + rss_type.udp_ipv4 = (rss_hf &RTE_ETH_RSS_NONFRAG_IPV4_UDP ) ?1 :0 ; + rss_type.udp_ipv6 = (rss_hf &RTE_ETH_RSS_NONFRAG_IPV6_UDP ) ?1 :0 ; + + err =hinic3_set_rss_type (nic_dev->hwdev, rss_type); +if (err) +PMD_DRV_LOG (ERR ,"Set RSS type failed" ); + +return err; +} + +/** +* Get the RSS hash configuration. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[out] rss_conf +* RSS configuration data. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_rss_conf_get (struct rte_eth_dev *dev,struct rte_eth_rss_conf *rss_conf) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct hinic3_rss_type rss_type = {0 }; +int err; + +if (!rss_conf) +return -EINVAL ; + +if (nic_dev->rss_state ==HINIC3_RSS_DISABLE ) { + rss_conf->rss_hf =0 ; +PMD_DRV_LOG (INFO ,"RSS is not enabled" ); +return 0 ; + } + +if (rss_conf->rss_key && rss_conf->rss_key_len >=HINIC3_RSS_KEY_SIZE ) { +/* +* Get RSS key from driver to reduce the frequency of the MPU +* accessing the RSS memory. +*/ + rss_conf->rss_key_len =sizeof (nic_dev->rss_key); +memcpy ((void *)rss_conf->rss_key, (void *)nic_dev->rss_key, + (size_t )rss_conf->rss_key_len); + } + + err =hinic3_get_rss_type (nic_dev->hwdev, &rss_type); +if (err) +return err; + + rss_conf->rss_hf =0 ; + rss_conf->rss_hf |= + rss_type.ipv4 ? (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 | +RTE_ETH_RSS_NONFRAG_IPV4_OTHER ) + :0 ; + rss_conf->rss_hf |= rss_type.tcp_ipv4 ?RTE_ETH_RSS_NONFRAG_IPV4_TCP + :0 ; + rss_conf->rss_hf |= + rss_type.ipv6 ? (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 | +RTE_ETH_RSS_NONFRAG_IPV6_OTHER ) + :0 ; + rss_conf->rss_hf |= rss_type.ipv6_ext ?RTE_ETH_RSS_IPV6_EX :0 ; + rss_conf->rss_hf |= rss_type.tcp_ipv6 ?RTE_ETH_RSS_NONFRAG_IPV6_TCP + :0 ; + rss_conf->rss_hf |= rss_type.tcp_ipv6_ext ?RTE_ETH_RSS_IPV6_TCP_EX :0 ; + rss_conf->rss_hf |= rss_type.udp_ipv4 ?RTE_ETH_RSS_NONFRAG_IPV4_UDP + :0 ; + rss_conf->rss_hf |= rss_type.udp_ipv6 ?RTE_ETH_RSS_NONFRAG_IPV6_UDP + :0 ; + +return 0 ; +} + +/** +* Get the RETA indirection table. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[out] reta_conf +* Pointer to RETA configuration structure array. +* @param[in] reta_size +* Size of the RETA table. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_rss_reta_query (struct rte_eth_dev *dev, +struct rte_eth_rss_reta_entry64 *reta_conf, +uint16_t reta_size) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u32 indirtbl[HINIC3_RSS_INDIR_SIZE ] = {0 }; +u16 idx, shift; +u16 i; +int err; + +if (nic_dev->rss_state ==HINIC3_RSS_DISABLE ) { +PMD_DRV_LOG (INFO ,"RSS is not enabled" ); +return 0 ; + } + +if (reta_size !=HINIC3_RSS_INDIR_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid reta size, reta_size: %d" , reta_size); +return -EINVAL ; + } + + err =hinic3_rss_get_indir_tbl (nic_dev->hwdev, indirtbl, +HINIC3_RSS_INDIR_SIZE ); +if (err) { +PMD_DRV_LOG (ERR ,"Get RSS retas table failed, error: %d" , err); +return err; + } + +for (i =0 ; i < reta_size; i++) { + idx = i /RTE_ETH_RETA_GROUP_SIZE ; + shift = i %RTE_ETH_RETA_GROUP_SIZE ; +if (reta_conf[idx].mask & (1ULL << shift)) + reta_conf[idx].reta[shift] = (uint16_t )indirtbl[i]; + } + +return 0 ; +} +static int hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev,struct rte_dev_eeprom_info *info)
@@ -2287,6 +2562,68 @@ hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev, &info->length, MAX_BUF_OUT_LEN); } +/** +* Update the RETA indirection table. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] reta_conf +* Pointer to RETA configuration structure array. +* @param[in] reta_size +* Size of the RETA table. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_rss_reta_update (struct rte_eth_dev *dev, +struct rte_eth_rss_reta_entry64 *reta_conf, +uint16_t reta_size) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u32 indirtbl[HINIC3_RSS_INDIR_SIZE ] = {0 }; +u16 idx, shift; +u16 i; +int err; + +if (nic_dev->rss_state ==HINIC3_RSS_DISABLE ) +return 0 ; + +if (reta_size !=HINIC3_RSS_INDIR_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid reta size, reta_size: %d" , reta_size); +return -EINVAL ; + } + + err =hinic3_rss_get_indir_tbl (nic_dev->hwdev, indirtbl, +HINIC3_RSS_INDIR_SIZE ); +if (err) +return err; + +/* Update RSS reta table. */ +for (i =0 ; i < reta_size; i++) { + idx = i /RTE_ETH_RETA_GROUP_SIZE ; + shift = i %RTE_ETH_RETA_GROUP_SIZE ; +if (reta_conf[idx].mask & (1ULL << shift)) + indirtbl[i] = reta_conf[idx].reta[shift]; + } + +for (i =0 ; i < reta_size; i++) { +if (indirtbl[i] >= nic_dev->num_rqs) { +PMD_DRV_LOG (ERR , +"Invalid reta entry, index: %d, num_rqs: %d" , + indirtbl[i], nic_dev->num_rqs); +return -EFAULT ; + } + } + + err =hinic3_rss_set_indir_tbl (nic_dev->hwdev, indirtbl, +HINIC3_RSS_INDIR_SIZE ); +if (err) +PMD_DRV_LOG (ERR ,"Set RSS reta table failed" ); + +return err; +} +/** * Get device generic statistics. *
@@ -2857,6 +3194,29 @@ hinic3_set_mc_addr_list(struct rte_eth_dev *dev,return 0 ; } +/** +* Manage flow director filter operations. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] filter_type +* Filter type. +* @param[in] filter_op +* Operation to perform. +* @param[in] arg +* Pointer to operation-specific structure. +* +* @return +* 0 on success, non-zero on failure. +*/ +static int +hinic3_dev_filter_ctrl (struct rte_eth_dev *dev,const struct rte_flow_ops **arg) +{ +RTE_SET_USED (dev); + *arg = &hinic3_flow_ops; +return 0 ; +} +static int hinic3_get_reg(__rte_unused struct rte_eth_dev *dev, __rte_unused struct rte_dev_reg_info *regs)
@@ -2890,6 +3250,12 @@ static const struct eth_dev_ops hinic3_pmd_ops = { .vlan_offload_set = hinic3_vlan_offload_set, .allmulticast_enable = hinic3_dev_allmulticast_enable, .allmulticast_disable = hinic3_dev_allmulticast_disable, + .promiscuous_enable = hinic3_dev_promiscuous_enable, + .promiscuous_disable = hinic3_dev_promiscuous_disable, + .rss_hash_update = hinic3_rss_hash_update, + .rss_hash_conf_get = hinic3_rss_conf_get, + .reta_update = hinic3_rss_reta_update, + .reta_query = hinic3_rss_reta_query, .get_eeprom = hinic3_get_eeprom, .stats_get = hinic3_dev_stats_get, .stats_reset = hinic3_dev_stats_reset,
@@ -2931,6 +3297,10 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = { .vlan_offload_set = hinic3_vlan_offload_set, .allmulticast_enable = hinic3_dev_allmulticast_enable, .allmulticast_disable = hinic3_dev_allmulticast_disable, + .rss_hash_update = hinic3_rss_hash_update, + .rss_hash_conf_get = hinic3_rss_conf_get, + .reta_update = hinic3_rss_reta_update, + .reta_query = hinic3_rss_reta_query, .get_eeprom = hinic3_get_eeprom, .stats_get = hinic3_dev_stats_get, .stats_reset = hinic3_dev_stats_reset,
drivers/net/hinic3/hinic3_ethdev.h +31 -0
@@ -97,6 +97,10 @@ struct hinic3_nic_dev {u16 rx_buff_len;u16 mtu_size; +u16 rss_state; +u8 num_rss;/**< Number of RSS queues. */ +u8 rsvd0;/**< Reserved field 0. */ +u32 rx_mode;u8 rx_queue_list[HINIC3_MAX_QUEUE_NUM ];rte_spinlock_t queue_list_lock;
@@ -106,6 +110,8 @@ struct hinic3_nic_dev {u32 default_cos;u32 rx_csum_en; +u8 rss_key[HINIC3_RSS_KEY_SIZE ]; +unsigned long dev_status;struct rte_ether_addr default_addr;
@@ -116,4 +122,29 @@ struct hinic3_nic_dev { u32 vfta[HINIC3_VFTA_SIZE]; /**< VLAN bitmap. */ }; +/** +* Enable interrupt for the specified RX queue. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] queue_id +* The ID of the receive queue for which the interrupt is being enabled. +* @return +* 0 on success, a negative error code on failure. +*/ +int hinic3_dev_rx_queue_intr_enable (struct rte_eth_dev *dev,uint16_t queue_id); + +/** +* Disable interrupt for the specified RX queue. +* +* @param[in] dev +* Pointer to ethernet device structure. +* @param[in] queue_id +* The ID of the receive queue for which the interrupt is being disabled. +* @return +* 0 on success, a negative error code on failure. +*/ +int hinic3_dev_rx_queue_intr_disable (struct rte_eth_dev *dev, +uint16_t queue_id); +#endif /* _HINIC3_ETHDEV_H_ */
Signature · 1 line
2.47.0.windows.2
RFC 17/18 net/hinic3: add FDIR flow control module
In reply to Feifei WangFrom: Yi Chen <[email protected]>
Added support for flow director filters, including ethertype, IPv4, IPv6, and tunnel VXLAN. In addition, user can add or delete filters.
--- drivers/net/hinic3/hinic3_ethdev.c | 82 ++ drivers/net/hinic3/hinic3_ethdev.h | 17 + drivers/net/hinic3/hinic3_fdir.c | 1394 +++++++++++++++++++++++ drivers/net/hinic3/hinic3_fdir.h | 398 +++++++ drivers/net/hinic3/hinic3_flow.c | 1700 ++++++++++++++++++++++++++++ drivers/net/hinic3/hinic3_flow.h | 80 ++ 6 files changed, 3671 insertions(+) create mode 100644 drivers/net/hinic3/hinic3_fdir.c create mode 100644 drivers/net/hinic3/hinic3_fdir.h create mode 100644 drivers/net/hinic3/hinic3_flow.c create mode 100644 drivers/net/hinic3/hinic3_flow.h
drivers/net/hinic3/hinic3_ethdev.c +82 -0
@@ -2369,6 +2369,84 @@ hinic3_dev_promiscuous_disable(struct rte_eth_dev *dev)* @return * 0 on success, non-zero on failure. */ +static int +hinic3_dev_flow_ctrl_get (struct rte_eth_dev *dev, +struct rte_eth_fc_conf *fc_conf) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct nic_pause_config nic_pause; +int err; + + err =hinic3_mutex_lock (&nic_dev->pause_mutuex); +if (err) +return err; + +memset (&nic_pause,0 ,sizeof (nic_pause)); + err =hinic3_get_pause_info (nic_dev->hwdev, &nic_pause); +if (err) { + (void )hinic3_mutex_unlock (&nic_dev->pause_mutuex); +return err; + } + +if (nic_dev->pause_set || !nic_pause.auto_neg) { + nic_pause.rx_pause = nic_dev->nic_pause.rx_pause; + nic_pause.tx_pause = nic_dev->nic_pause.tx_pause; + } + + fc_conf->autoneg = nic_pause.auto_neg; + +if (nic_pause.tx_pause && nic_pause.rx_pause) + fc_conf->mode =RTE_ETH_FC_FULL ; +else if (nic_pause.tx_pause) + fc_conf->mode =RTE_ETH_FC_TX_PAUSE ; +else if (nic_pause.rx_pause) + fc_conf->mode =RTE_ETH_FC_RX_PAUSE ; +else + fc_conf->mode =RTE_ETH_FC_NONE ; + + (void )hinic3_mutex_unlock (&nic_dev->pause_mutuex); +return 0 ; +} + +static int +hinic3_dev_flow_ctrl_set (struct rte_eth_dev *dev, +struct rte_eth_fc_conf *fc_conf) +{ +struct hinic3_nic_dev *nic_dev =HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct nic_pause_config nic_pause; +int err; + + err =hinic3_mutex_lock (&nic_dev->pause_mutuex); +if (err) +return err; + +memset (&nic_pause,0 ,sizeof (nic_pause)); +if ((fc_conf->mode &RTE_ETH_FC_FULL ) ==RTE_ETH_FC_FULL || + (fc_conf->mode &RTE_ETH_FC_TX_PAUSE )) + nic_pause.tx_pause = true; + +if ((fc_conf->mode &RTE_ETH_FC_FULL ) ==RTE_ETH_FC_FULL || + (fc_conf->mode &RTE_ETH_FC_RX_PAUSE )) + nic_pause.rx_pause = true; + + err =hinic3_set_pause_info (nic_dev->hwdev, nic_pause); +if (err) { + (void )hinic3_mutex_unlock (&nic_dev->pause_mutuex); +return err; + } + + nic_dev->pause_set = true; + nic_dev->nic_pause.rx_pause = nic_pause.rx_pause; + nic_dev->nic_pause.tx_pause = nic_pause.tx_pause; + +PMD_DRV_LOG (INFO , +"Just support set tx or rx pause info, tx: %s, rx: %s" , + nic_pause.tx_pause ?"on" :"off" , + nic_pause.rx_pause ?"on" :"off" ); + + (void )hinic3_mutex_unlock (&nic_dev->pause_mutuex); +return 0 ; +}/** * Update the RSS hash key and RSS hash type.
@@ -3252,6 +3330,8 @@ static const struct eth_dev_ops hinic3_pmd_ops = { .allmulticast_disable = hinic3_dev_allmulticast_disable, .promiscuous_enable = hinic3_dev_promiscuous_enable, .promiscuous_disable = hinic3_dev_promiscuous_disable, + .flow_ctrl_get = hinic3_dev_flow_ctrl_get, + .flow_ctrl_set = hinic3_dev_flow_ctrl_set, .rss_hash_update = hinic3_rss_hash_update, .rss_hash_conf_get = hinic3_rss_conf_get, .reta_update = hinic3_rss_reta_update,
@@ -3269,6 +3349,7 @@ static const struct eth_dev_ops hinic3_pmd_ops = { .mac_addr_remove = hinic3_mac_addr_remove, .mac_addr_add = hinic3_mac_addr_add, .set_mc_addr_list = hinic3_set_mc_addr_list, + .flow_ops_get = hinic3_dev_filter_ctrl, .get_reg = hinic3_get_reg, };
@@ -3313,6 +3394,7 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = { .mac_addr_remove = hinic3_mac_addr_remove, .mac_addr_add = hinic3_mac_addr_add, .set_mc_addr_list = hinic3_set_mc_addr_list, + .flow_ops_get = hinic3_dev_filter_ctrl, };/**
drivers/net/hinic3/hinic3_ethdev.h +17 -0
@@ -8,6 +8,8 @@#include <rte_ethdev.h> #include <rte_ethdev_core.h> +#include "hinic3_fdir.h" +#define HINIC3_PMD_DRV_VERSION "B106"#define PCI_DEV_TO_INTR_HANDLE (pci_dev) ((pci_dev)->intr_handle)
@@ -83,6 +85,9 @@ enum nic_feature_cap {#define DEFAULT_DRV_FEATURE 0x3FFF +TAILQ_HEAD (hinic3_ethertype_filter_list, rte_flow); +TAILQ_HEAD (hinic3_fdir_rule_filter_list, rte_flow); +struct hinic3_nic_dev {struct hinic3_hwdev *hwdev;/**< Hardware device. */ struct hinic3_txq **txqs;
@@ -114,14 +119,26 @@ struct hinic3_nic_dev {unsigned long dev_status; +u8 pause_set;/**< Flag of PAUSE frame setting. */ +pthread_mutex_t pause_mutuex; +struct nic_pause_config nic_pause; +struct rte_ether_addr default_addr;struct rte_ether_addr *mc_list;char dev_name[HINIC3_DEV_NAME_LEN ];u64 feature_cap;u32 vfta[HINIC3_VFTA_SIZE ];/**< VLAN bitmap. */ + +u16 tcam_rule_nums; +u16 ethertype_rule_nums; +struct hinic3_tcam_info tcam; +struct hinic3_ethertype_filter_list filter_ethertype_list; +struct hinic3_fdir_rule_filter_list filter_fdir_rule_list; }; +extern const struct rte_flow_ops hinic3_flow_ops; +/** * Enable interrupt for the specified RX queue. *
drivers/net/hinic3/hinic3_fdir.c new file +1394 -0
1,394 lines not on this page · raw message
drivers/net/hinic3/hinic3_fdir.h new file +398 -0
398 lines not on this page · raw message
drivers/net/hinic3/hinic3_flow.c new file +1700 -0
1,059 lines not on this page · raw message
drivers/net/hinic3/hinic3_flow.h new file +80 -0
80 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.47.0.windows.2
Part of the diff is not shown here. View the raw message.
RFC 18/18 drivers/net: add hinic3 PMD build and doc files
In reply to Feifei WangFrom: Yi Chen <[email protected]>
The meson.build file is added to this patch to enable the hinic3 compilation function.
--- doc/guides/nics/features/hinic3.ini | 9 ++++++ drivers/net/hinic3/base/meson.build | 50 +++++++++++++++++++++++++++++ drivers/net/hinic3/meson.build | 44 +++++++++++++++++++++++++ drivers/net/meson.build | 1 + 4 files changed, 104 insertions(+) create mode 100644 doc/guides/nics/features/hinic3.ini create mode 100644 drivers/net/hinic3/base/meson.build create mode 100644 drivers/net/hinic3/meson.build
doc/guides/nics/features/hinic3.ini new file +9 -0
@@ -0,0 +1,9 @@ +; +; Supported features of the 'hinic3' network poll mode driver. +; +; Refer to default.ini for the full list of available PMD features. +; +[Features] +Linux = Y +x86-64 = Y +ARMv8 = Y
drivers/net/hinic3/base/meson.build new file +50 -0
50 lines not on this page · raw message
drivers/net/hinic3/meson.build new file +44 -0
44 lines not on this page · raw message
drivers/net/meson.build +1 -0
@@ -23,6 +23,7 @@ drivers = [ 'failsafe', 'gve', 'hinic', + 'hinic3', 'hns3', 'intel/e1000', 'intel/fm10k',
Signature · 1 line
2.47.0.windows.2