A new net PMD - hinic
Subsystems (2)
v4 cover A new net PMD - hinic
This patch set adds support of a new net PMD for Huawei Intelligent nic. This patch provides supoort for basic RX/TX and the contorl path needed for it. Later on new features will be added like VLAN, VFs, etc.
Basic features:
1. Basic device operations: probe, initialization, start/stop, configure, info get.
2. RX/TX queue operations: setup/release, start/stop.
3. RX/TX.
Stats:
1. statistics and extended statistics.
---
v2:
- Fix arm64 compilation issue.
- Fix some checkpatch checks issues
- Fix patches thread issue.
- Fit to the newest rte_ prefix patch
v3:
- Remove Rami from hinic pmd maintainers
- Remove hinic_logs.* files and move log codes to other files
- Remove the C++ guards within hinic pmd codes
- Remove variable related errors shields from compilation files
- Use lib link statu related functions but selfdefined
- Fix x86_64-native-linuxapp-clang compilation errors
- Fix i686-native-linuxapp-gcc compilation errors
v4:
- Update doc hinic.ini and hini.rst
- Remove x86-32, i686, BSD, Power8, ARMv7 compilations
- Fit to newest IPV4 and IPV6 uppercase
Ziyang Xuan (11):
net/hinic/base: add registers for Huawei Hi1822 NIC net/hinic/base: add command channels code net/hinic/base: add mgmt module interactive code net/hinic/base: add code about hardware operation net/hinic/base: add eqs and context code net/hinic/base: add code for nic business net/hinic/base: add various headers net/hinic: add hinic PMD build and doc files net/hinic: add RX module
net/hinic: add TX module
net/hinic: add support for basic device operations
MAINTAINERS | 9 + config/common_base | 5 + config/common_linux | 5 + config/defconfig_arm-armv7a-linuxapp-gcc | 1 + config/defconfig_i686-native-linuxapp-gcc | 5 + config/defconfig_i686-native-linuxapp-icc | 5 + config/defconfig_ppc_64-power8-linuxapp-gcc | 1 + config/defconfig_x86_64-native-linuxapp-icc | 5 + config/defconfig_x86_x32-native-linuxapp-gcc | 5 + doc/guides/nics/features/hinic.ini | 37 + doc/guides/nics/hinic.rst | 55 + drivers/net/Makefile | 1 + drivers/net/hinic/Makefile | 73 + drivers/net/hinic/base/hinic_compat.h | 239 ++ drivers/net/hinic/base/hinic_csr.h | 164 ++ drivers/net/hinic/base/hinic_ctx_def.h | 184 ++ drivers/net/hinic/base/hinic_pmd_api_cmd.c | 1037 ++++++++ drivers/net/hinic/base/hinic_pmd_api_cmd.h | 271 +++ drivers/net/hinic/base/hinic_pmd_cfg.c | 269 +++ drivers/net/hinic/base/hinic_pmd_cfg.h | 264 ++ drivers/net/hinic/base/hinic_pmd_cmdq.c | 901 +++++++ drivers/net/hinic/base/hinic_pmd_cmdq.h | 190 ++ drivers/net/hinic/base/hinic_pmd_dpdev.h | 146 ++ drivers/net/hinic/base/hinic_pmd_eqs.c | 725 ++++++ drivers/net/hinic/base/hinic_pmd_eqs.h | 94 + drivers/net/hinic/base/hinic_pmd_hw.h | 49 + drivers/net/hinic/base/hinic_pmd_hw_mgmt.h | 85 + drivers/net/hinic/base/hinic_pmd_hwdev.c | 1544 ++++++++++++ drivers/net/hinic/base/hinic_pmd_hwdev.h | 205 ++ drivers/net/hinic/base/hinic_pmd_hwif.c | 542 +++++ drivers/net/hinic/base/hinic_pmd_hwif.h | 90 + drivers/net/hinic/base/hinic_pmd_mgmt.c | 617 +++++ drivers/net/hinic/base/hinic_pmd_mgmt.h | 125 + .../net/hinic/base/hinic_pmd_mgmt_interface.h | 503 ++++ drivers/net/hinic/base/hinic_pmd_nic.h | 85 + drivers/net/hinic/base/hinic_pmd_niccfg.c | 1376 +++++++++++ drivers/net/hinic/base/hinic_pmd_niccfg.h | 333 +++ drivers/net/hinic/base/hinic_pmd_nicio.c | 919 +++++++ drivers/net/hinic/base/hinic_pmd_nicio.h | 53 + drivers/net/hinic/base/hinic_pmd_qp.c | 26 + drivers/net/hinic/base/hinic_pmd_qp.h | 76 + drivers/net/hinic/base/hinic_pmd_wq.c | 164 ++ drivers/net/hinic/base/hinic_pmd_wq.h | 52 + drivers/net/hinic/base/hinic_port_cmd.h | 483 ++++ drivers/net/hinic/base/hinic_qe_def.h | 450 ++++ drivers/net/hinic/base/meson.build | 50 + drivers/net/hinic/hinic_pmd_dpdev.c | 702 ++++++ drivers/net/hinic/hinic_pmd_ethdev.c | 2150 +++++++++++++++++ drivers/net/hinic/hinic_pmd_ethdev.h | 102 + drivers/net/hinic/hinic_pmd_rx.c | 902 +++++++ drivers/net/hinic/hinic_pmd_rx.h | 135 ++ drivers/net/hinic/hinic_pmd_tx.c | 1070 ++++++++ drivers/net/hinic/hinic_pmd_tx.h | 97 + drivers/net/hinic/meson.build | 18 + drivers/net/hinic/rte_pmd_hinic_version.map | 4 + mk/rte.app.mk | 1 + 56 files changed, 17699 insertions(+) create mode 100644 doc/guides/nics/features/hinic.ini create mode 100644 doc/guides/nics/hinic.rst create mode 100644 drivers/net/hinic/Makefile create mode 100644 drivers/net/hinic/base/hinic_compat.h create mode 100644 drivers/net/hinic/base/hinic_csr.h create mode 100644 drivers/net/hinic/base/hinic_ctx_def.h create mode 100644 drivers/net/hinic/base/hinic_pmd_api_cmd.c create mode 100644 drivers/net/hinic/base/hinic_pmd_api_cmd.h create mode 100644 drivers/net/hinic/base/hinic_pmd_cfg.c create mode 100644 drivers/net/hinic/base/hinic_pmd_cfg.h create mode 100644 drivers/net/hinic/base/hinic_pmd_cmdq.c create mode 100644 drivers/net/hinic/base/hinic_pmd_cmdq.h create mode 100644 drivers/net/hinic/base/hinic_pmd_dpdev.h create mode 100644 drivers/net/hinic/base/hinic_pmd_eqs.c create mode 100644 drivers/net/hinic/base/hinic_pmd_eqs.h create mode 100644 drivers/net/hinic/base/hinic_pmd_hw.h create mode 100644 drivers/net/hinic/base/hinic_pmd_hw_mgmt.h create mode 100644 drivers/net/hinic/base/hinic_pmd_hwdev.c create mode 100644 drivers/net/hinic/base/hinic_pmd_hwdev.h create mode 100644 drivers/net/hinic/base/hinic_pmd_hwif.c create mode 100644 drivers/net/hinic/base/hinic_pmd_hwif.h create mode 100644 drivers/net/hinic/base/hinic_pmd_mgmt.c create mode 100644 drivers/net/hinic/base/hinic_pmd_mgmt.h create mode 100644 drivers/net/hinic/base/hinic_pmd_mgmt_interface.h create mode 100644 drivers/net/hinic/base/hinic_pmd_nic.h create mode 100644 drivers/net/hinic/base/hinic_pmd_niccfg.c create mode 100644 drivers/net/hinic/base/hinic_pmd_niccfg.h create mode 100644 drivers/net/hinic/base/hinic_pmd_nicio.c create mode 100644 drivers/net/hinic/base/hinic_pmd_nicio.h create mode 100644 drivers/net/hinic/base/hinic_pmd_qp.c create mode 100644 drivers/net/hinic/base/hinic_pmd_qp.h create mode 100644 drivers/net/hinic/base/hinic_pmd_wq.c create mode 100644 drivers/net/hinic/base/hinic_pmd_wq.h create mode 100644 drivers/net/hinic/base/hinic_port_cmd.h create mode 100644 drivers/net/hinic/base/hinic_qe_def.h create mode 100644 drivers/net/hinic/base/meson.build create mode 100644 drivers/net/hinic/hinic_pmd_dpdev.c create mode 100644 drivers/net/hinic/hinic_pmd_ethdev.c create mode 100644 drivers/net/hinic/hinic_pmd_ethdev.h create mode 100644 drivers/net/hinic/hinic_pmd_rx.c create mode 100644 drivers/net/hinic/hinic_pmd_rx.h create mode 100644 drivers/net/hinic/hinic_pmd_tx.c create mode 100644 drivers/net/hinic/hinic_pmd_tx.h create mode 100644 drivers/net/hinic/meson.build create mode 100644 drivers/net/hinic/rte_pmd_hinic_version.map
Signature · 1 line
2.18.0
PATCH v4 1/11 net/hinic/base: add registers for Huawei Hi1822 NIC
Add the registers that comprise the Huawei Hi1822 NIC. There is no functionality in this patch.
--- drivers/net/hinic/base/hinic_csr.h | 164 +++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 drivers/net/hinic/base/hinic_csr.h
drivers/net/hinic/base/hinic_csr.h new file +164 -0
@@ -0,0 +1,164 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#ifndef _HINIC_CSR_H_ +#define _HINIC_CSR_H_ + +#define HINIC_CSR_GLOBAL_BASE_ADDR 0x4000 + +/* HW interface registers */ +#define HINIC_CSR_FUNC_ATTR0_ADDR 0x0 +#define HINIC_CSR_FUNC_ATTR1_ADDR 0x4 +#define HINIC_CSR_FUNC_ATTR2_ADDR 0x8 +#define HINIC_CSR_FUNC_ATTR4_ADDR 0x10 +#define HINIC_CSR_FUNC_ATTR5_ADDR 0x14 + +#define HINIC_FUNC_CSR_MAILBOX_DATA_OFF 0x80 +#define HINIC_FUNC_CSR_MAILBOX_CONTROL_OFF 0x0100 +#define HINIC_FUNC_CSR_MAILBOX_INT_OFFSET_OFF 0x0104 +#define HINIC_FUNC_CSR_MAILBOX_RESULT_H_OFF 0x0108 +#define HINIC_FUNC_CSR_MAILBOX_RESULT_L_OFF 0x010C + +#define HINIC_CSR_DMA_ATTR_TBL_BASE 0xC80 + +#define HINIC_ELECTION_BASE 0x200 + +#define HINIC_CSR_DMA_ATTR_TBL_STRIDE 0x4 +#define HINIC_CSR_DMA_ATTR_TBL_ADDR (idx) \ + (HINIC_CSR_DMA_ATTR_TBL_BASE \ + + (idx) * HINIC_CSR_DMA_ATTR_TBL_STRIDE) + +#define HINIC_PPF_ELECTION_STRIDE 0x4 +#define HINIC_CSR_MAX_PORTS 4 +#define HINIC_CSR_PPF_ELECTION_ADDR \ + (HINIC_CSR_GLOBAL_BASE_ADDR + HINIC_ELECTION_BASE) + +#define HINIC_CSR_GLOBAL_MPF_ELECTION_ADDR \ + (HINIC_CSR_GLOBAL_BASE_ADDR + HINIC_ELECTION_BASE + \ + HINIC_CSR_MAX_PORTS * HINIC_PPF_ELECTION_STRIDE) + +/* MSI-X registers */ +#define HINIC_CSR_MSIX_CTRL_BASE 0x2000 +#define HINIC_CSR_MSIX_CNT_BASE 0x2004 + +#define HINIC_CSR_MSIX_STRIDE 0x8 + +#define HINIC_CSR_MSIX_CTRL_ADDR (idx) \ + (HINIC_CSR_MSIX_CTRL_BASE + (idx) * HINIC_CSR_MSIX_STRIDE) + +#define HINIC_CSR_MSIX_CNT_ADDR (idx) \ + (HINIC_CSR_MSIX_CNT_BASE + (idx) * HINIC_CSR_MSIX_STRIDE) + +/* EQ registers */ +#define HINIC_AEQ_MTT_OFF_BASE_ADDR 0x200 +#define HINIC_CEQ_MTT_OFF_BASE_ADDR 0x400 + +#define HINIC_EQ_MTT_OFF_STRIDE 0x40 + +#define HINIC_CSR_AEQ_MTT_OFF (id) \ + (HINIC_AEQ_MTT_OFF_BASE_ADDR + (id) * HINIC_EQ_MTT_OFF_STRIDE) + +#define HINIC_CSR_CEQ_MTT_OFF (id) \ + (HINIC_CEQ_MTT_OFF_BASE_ADDR + (id) * HINIC_EQ_MTT_OFF_STRIDE) + +#define HINIC_CSR_EQ_PAGE_OFF_STRIDE 8 + +#define HINIC_AEQ_HI_PHYS_ADDR_REG (q_id, pg_num) \ + (HINIC_CSR_AEQ_MTT_OFF(q_id) + \ + (pg_num) * HINIC_CSR_EQ_PAGE_OFF_STRIDE) + +#define HINIC_AEQ_LO_PHYS_ADDR_REG (q_id, pg_num) \ + (HINIC_CSR_AEQ_MTT_OFF(q_id) + \ + (pg_num) * HINIC_CSR_EQ_PAGE_OFF_STRIDE + 4) + +#define HINIC_CEQ_HI_PHYS_ADDR_REG (q_id, pg_num) \ + (HINIC_CSR_CEQ_MTT_OFF(q_id) + \ + (pg_num) * HINIC_CSR_EQ_PAGE_OFF_STRIDE) + +#define HINIC_CEQ_LO_PHYS_ADDR_REG (q_id, pg_num) \ + (HINIC_CSR_CEQ_MTT_OFF(q_id) + \ + (pg_num) * HINIC_CSR_EQ_PAGE_OFF_STRIDE + 4) + +#define HINIC_EQ_HI_PHYS_ADDR_REG (type, q_id, pg_num) \ + ((u32)((type == HINIC_AEQ) ? \ + HINIC_AEQ_HI_PHYS_ADDR_REG(q_id, pg_num) : \ + HINIC_CEQ_HI_PHYS_ADDR_REG(q_id, pg_num))) + +#define HINIC_EQ_LO_PHYS_ADDR_REG (type, q_id, pg_num) \ + ((u32)((type == HINIC_AEQ) ? \ + HINIC_AEQ_LO_PHYS_ADDR_REG(q_id, pg_num) : \ + HINIC_CEQ_LO_PHYS_ADDR_REG(q_id, pg_num))) + +#define HINIC_AEQ_CTRL_0_ADDR_BASE 0xE00 +#define HINIC_AEQ_CTRL_1_ADDR_BASE 0xE04 +#define HINIC_AEQ_CONS_IDX_0_ADDR_BASE 0xE08 +#define HINIC_AEQ_CONS_IDX_1_ADDR_BASE 0xE0C + +#define HINIC_EQ_OFF_STRIDE 0x80 + +#define HINIC_CSR_AEQ_CTRL_0_ADDR (idx) \ + (HINIC_AEQ_CTRL_0_ADDR_BASE + (idx) * HINIC_EQ_OFF_STRIDE) + +#define HINIC_CSR_AEQ_CTRL_1_ADDR (idx) \ + (HINIC_AEQ_CTRL_1_ADDR_BASE + (idx) * HINIC_EQ_OFF_STRIDE) + +#define HINIC_CSR_AEQ_CONS_IDX_ADDR (idx) \ + (HINIC_AEQ_CONS_IDX_0_ADDR_BASE + (idx) * HINIC_EQ_OFF_STRIDE) + +#define HINIC_CSR_AEQ_PROD_IDX_ADDR (idx) \ + (HINIC_AEQ_CONS_IDX_1_ADDR_BASE + (idx) * HINIC_EQ_OFF_STRIDE) + +#define HINIC_CEQ_CONS_IDX_0_ADDR_BASE 0x1008 +#define HINIC_CEQ_CONS_IDX_1_ADDR_BASE 0x100C + +#define HINIC_CSR_CEQ_CONS_IDX_ADDR (idx) \ + (HINIC_CEQ_CONS_IDX_0_ADDR_BASE + (idx) * HINIC_EQ_OFF_STRIDE) + +#define HINIC_CSR_CEQ_PROD_IDX_ADDR (idx) \ + (HINIC_CEQ_CONS_IDX_1_ADDR_BASE + (idx) * HINIC_EQ_OFF_STRIDE) + +/* API CMD registers */ +#define HINIC_CSR_API_CMD_BASE 0xF000 + +#define HINIC_CSR_API_CMD_STRIDE 0x100 + +#define HINIC_CSR_API_CMD_CHAIN_HEAD_HI_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x0 + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_CHAIN_HEAD_LO_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x4 + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_STATUS_HI_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x8 + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_STATUS_LO_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0xC + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_CHAIN_NUM_CELLS_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x10 + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_CHAIN_CTRL_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x14 + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_CHAIN_PI_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x1C + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_CHAIN_REQ_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x20 + (idx) * HINIC_CSR_API_CMD_STRIDE) + +#define HINIC_CSR_API_CMD_STATUS_0_ADDR (idx) \ + (HINIC_CSR_API_CMD_BASE + 0x30 + (idx) * HINIC_CSR_API_CMD_STRIDE) + +/* VF control registers in pf */ +#define HINIC_PF_CSR_VF_FLUSH_BASE 0x1F400 +#define HINIC_PF_CSR_VF_FLUSH_STRIDE 0x4 + +#define HINIC_GLB_DMA_SO_RO_REPLACE_ADDR 0x488C + +#define HINIC_ICPL_RESERVD_ADDR 0x9204 + +#define HINIC_PF_CSR_VF_FLUSH_OFF (idx) \ + (HINIC_PF_CSR_VF_FLUSH_BASE + (idx) * HINIC_PF_CSR_VF_FLUSH_STRIDE) + +#endif /* _HINIC_CSR_H_ */
Signature · 1 line
2.18.0
PATCH v4 2/11 net/hinic/base: add command channels code
In reply to Ziyang XuanAdmin channels include api channel and command queue, Api channel is for mgmt module. And command queue is for ucode module.
--- drivers/net/hinic/base/hinic_pmd_api_cmd.c | 1037 ++++++++++++++++++++ drivers/net/hinic/base/hinic_pmd_api_cmd.h | 271 +++++ drivers/net/hinic/base/hinic_pmd_cmdq.c | 901 +++++++++++++++++ drivers/net/hinic/base/hinic_pmd_cmdq.h | 190 ++++ 4 files changed, 2399 insertions(+) create mode 100644 drivers/net/hinic/base/hinic_pmd_api_cmd.c create mode 100644 drivers/net/hinic/base/hinic_pmd_api_cmd.h create mode 100644 drivers/net/hinic/base/hinic_pmd_cmdq.c create mode 100644 drivers/net/hinic/base/hinic_pmd_cmdq.h
drivers/net/hinic/base/hinic_pmd_api_cmd.c new file +1037 -0
@@ -0,0 +1,1037 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#include "hinic_pmd_dpdev.h" + +#define API_CMD_CHAIN_CELL_SIZE_SHIFT 6U + +#define API_CMD_CELL_DESC_SIZE 8 +#define API_CMD_CELL_DATA_ADDR_SIZE 8 + +#define API_CHAIN_NUM_CELLS 32 +#define API_CHAIN_CELL_SIZE 128 +#define API_CHAIN_RSP_DATA_SIZE 128 + +#define API_CHAIN_CELL_ALIGNMENT 8 + +#define API_CMD_TIMEOUT 10000 + +#define API_CMD_BUF_SIZE 2048UL + +#define API_CMD_NODE_ALIGN_SIZE 512UL +#define API_PAYLOAD_ALIGN_SIZE 64 + +#define API_CHAIN_RESP_ALIGNMENT 64ULL + +#define COMPLETION_TIMEOUT_DEFAULT 1000UL +#define POLLING_COMPLETION_TIMEOUT_DEFAULT 1000U + +#define API_CMD_RESPONSE_DATA_PADDR (val) be64_to_cpu(*((u64 *)(val))) + +#define READ_API_CMD_PRIV_DATA (id, token) (((id) << 16) + (token)) +#define WRITE_API_CMD_PRIV_DATA (id) ((id) << 16) + +#define MASKED_IDX (chain, idx) ((idx) & ((chain)->num_cells - 1)) + +#undef SIZE_4BYTES +#undef SIZE_8BYTES +#define SIZE_4BYTES (size) (ALIGN((u32)(size), 4U) >> 2) +#define SIZE_8BYTES (size) (ALIGN((u32)(size), 8U) >> 3) + +enum api_cmd_data_format { +SGL_DATA =1 , +}; + +enum api_cmd_type { +API_CMD_WRITE_TYPE =0 , +API_CMD_READ_TYPE =1 , +}; + +enum api_cmd_bypass { +NOT_BYPASS =0 , +BYPASS =1 , +}; + +enum api_cmd_resp_aeq { +NOT_TRIGGER =0 , +TRIGGER =1 , +}; + +static u8 xor_chksum_set (void *data) +{ +int idx; +u8 checksum =0 ; +u8 *val = (u8 *)data; + +for (idx =0 ; idx <7 ; idx++) + checksum ^= val[idx]; + +return checksum; +} + +static void set_prod_idx (struct hinic_api_cmd_chain *chain) +{ +enum hinic_api_cmd_chain_type chain_type = chain->chain_type; +struct hinic_hwif *hwif = chain->hwdev->hwif; +u32 hw_prod_idx_addr =HINIC_CSR_API_CMD_CHAIN_PI_ADDR (chain_type); +u32 prod_idx = chain->prod_idx; + +hinic_hwif_write_reg (hwif, hw_prod_idx_addr, prod_idx); +} + +static u32 get_hw_cons_idx (struct hinic_api_cmd_chain *chain) +{ +u32 addr, val; + + addr =HINIC_CSR_API_CMD_STATUS_0_ADDR (chain->chain_type); + val =hinic_hwif_read_reg (chain->hwdev->hwif, addr); + +return HINIC_API_CMD_STATUS_GET (val,CONS_IDX ); +} + +static void dump_api_chain_reg (struct hinic_api_cmd_chain *chain) +{ +u32 addr, val; + + addr =HINIC_CSR_API_CMD_STATUS_0_ADDR (chain->chain_type); + val =hinic_hwif_read_reg (chain->hwdev->hwif, addr); + +PMD_DRV_LOG (ERR ,"chain type: 0x%x" , chain->chain_type); +PMD_DRV_LOG (ERR ,"chain hw cpld error: 0x%x" , +HINIC_API_CMD_STATUS_GET (val,CPLD_ERR )); +PMD_DRV_LOG (ERR ,"chain hw check error: 0x%x" , +HINIC_API_CMD_STATUS_GET (val,CHKSUM_ERR )); +PMD_DRV_LOG (ERR ,"chain hw current fsm: 0x%x" , +HINIC_API_CMD_STATUS_GET (val,FSM )); +PMD_DRV_LOG (ERR ,"chain hw current ci: 0x%x" , +HINIC_API_CMD_STATUS_GET (val,CONS_IDX )); + + addr =HINIC_CSR_API_CMD_CHAIN_PI_ADDR (chain->chain_type); + val =hinic_hwif_read_reg (chain->hwdev->hwif, addr); +PMD_DRV_LOG (ERR ,"Chain hw current pi: 0x%x" , val); +} + +/** +* chain_busy - check if the chain is still processing last requests +* @chain: chain to check +**/ +static int chain_busy (struct hinic_api_cmd_chain *chain) +{ +switch (chain->chain_type) { +case HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU : +case HINIC_API_CMD_PMD_WRITE_TO_MGMT : + chain->cons_idx =get_hw_cons_idx (chain); +if (chain->cons_idx ==MASKED_IDX (chain, chain->prod_idx +1 )) { +PMD_DRV_LOG (ERR ,"API CMD chain %d is busy, cons_idx: %d, prod_idx: %d" , + chain->chain_type, chain->cons_idx, + chain->prod_idx); +dump_api_chain_reg (chain); +return -EBUSY ; + } +break ; +default : +PMD_DRV_LOG (ERR ,"Unknown Chain type" ); +return -EINVAL ; + } + +return 0 ; +} + +/** +* get_cell_data_size - get the data size of specific cell type +* @type: chain type +**/ +static u16 get_cell_data_size (enum hinic_api_cmd_chain_type type, + __rte_unused u16 cmd_size) +{ +u16 cell_data_size =0 ; + +switch (type) { +case HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU : +case HINIC_API_CMD_PMD_WRITE_TO_MGMT : + cell_data_size =ALIGN (API_CMD_CELL_DESC_SIZE + +API_CMD_CELL_DATA_ADDR_SIZE , +API_CHAIN_CELL_ALIGNMENT ); +break ; +default : +break ; + } + +return cell_data_size; +} + +/** +* prepare_cell_ctrl - prepare the ctrl of the cell for the command +* @cell_ctrl: the control of the cell to set the control into it +* @cell_len: the size of the cell +**/ +static void prepare_cell_ctrl (u64 *cell_ctrl,u16 cell_len) +{ +u64 ctrl; +u8 chksum; + +/* Read Modify Write */ + ctrl =be64_to_cpu (*cell_ctrl); + ctrl =HINIC_API_CMD_CELL_CTRL_CLEAR (ctrl,CELL_LEN ) & +HINIC_API_CMD_CELL_CTRL_CLEAR (ctrl,RD_DMA_ATTR_OFF ) & +HINIC_API_CMD_CELL_CTRL_CLEAR (ctrl,WR_DMA_ATTR_OFF ) & +HINIC_API_CMD_CELL_CTRL_CLEAR (ctrl,XOR_CHKSUM ); + + ctrl |=HINIC_API_CMD_CELL_CTRL_SET (SIZE_8BYTES (cell_len),CELL_LEN ) | +HINIC_API_CMD_CELL_CTRL_SET (0ULL ,RD_DMA_ATTR_OFF ) | +HINIC_API_CMD_CELL_CTRL_SET (0ULL ,WR_DMA_ATTR_OFF ); + + chksum =xor_chksum_set (&ctrl); + + ctrl |=HINIC_API_CMD_CELL_CTRL_SET (chksum,XOR_CHKSUM ); + +/* The data in the HW should be in Big Endian Format */ + *cell_ctrl =cpu_to_be64 (ctrl); +} + +/** +* prepare_api_cmd - prepare API CMD command +* @chain: chain for the command +* @cell: the cell of the command +* @dest: destination node on the card that will receive the command +* @cmd: command data +* @cmd_size: the command size +**/ +static void prepare_api_cmd (struct hinic_api_cmd_chain *chain, +struct hinic_api_cmd_cell *cell, +enum hinic_node_id dest, +void *cmd,u16 cmd_size) +{ +struct hinic_api_cmd_cell_ctxt *cell_ctxt; +u32 priv; + + cell_ctxt = &chain->cell_ctxt[chain->prod_idx]; + +/* Clear all the members before changes */ + cell->desc =HINIC_API_CMD_DESC_CLEAR (cell->desc,API_TYPE ) & +HINIC_API_CMD_DESC_CLEAR (cell->desc,RD_WR ) & +HINIC_API_CMD_DESC_CLEAR (cell->desc,MGMT_BYPASS ) & +HINIC_API_CMD_DESC_CLEAR (cell->desc,RESP_AEQE_EN ) & +HINIC_API_CMD_DESC_CLEAR (cell->desc,DEST ) & +HINIC_API_CMD_DESC_CLEAR (cell->desc,SIZE ) & +HINIC_API_CMD_DESC_CLEAR (cell->desc,XOR_CHKSUM ); + +switch (chain->chain_type) { +case HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU : +case HINIC_API_CMD_PMD_WRITE_TO_MGMT : + priv =WRITE_API_CMD_PRIV_DATA (chain->chain_type); + cell->desc =HINIC_API_CMD_DESC_SET (SGL_DATA ,API_TYPE ) | +HINIC_API_CMD_DESC_SET (API_CMD_WRITE_TYPE ,RD_WR ) | +HINIC_API_CMD_DESC_SET (NOT_BYPASS ,MGMT_BYPASS ) | +HINIC_API_CMD_DESC_SET (TRIGGER ,RESP_AEQE_EN ) | +HINIC_API_CMD_DESC_SET (priv,PRIV_DATA ); +break ; +default : +PMD_DRV_LOG (ERR ,"Unknown Chain type" ); +return ; + } + + cell->desc |=HINIC_API_CMD_DESC_SET (dest,DEST ) | +HINIC_API_CMD_DESC_SET (SIZE_4BYTES (cmd_size),SIZE ); + cell->desc |=HINIC_API_CMD_DESC_SET (xor_chksum_set (&cell->desc), +XOR_CHKSUM ); + +/* The data in the HW should be in Big Endian Format */ + cell->desc =cpu_to_be64 (cell->desc); + +memcpy (cell_ctxt->api_cmd_vaddr, cmd, cmd_size); +} + +/** +* prepare_cell - prepare cell ctrl and cmd in the current producer cell +* @chain: chain for the command +* @dest: destination node on the card that will receive the command +* @cmd: command data +* @cmd_size: the command size +**/ +static void prepare_cell (struct hinic_api_cmd_chain *chain, +enum hinic_node_id dest, +void *cmd,u16 cmd_size) +{ +struct hinic_api_cmd_cell *curr_node; +u16 cell_size; + + curr_node = chain->curr_node; + + cell_size =get_cell_data_size (chain->chain_type, cmd_size); + +prepare_cell_ctrl (&curr_node->ctrl, cell_size); +prepare_api_cmd (chain, curr_node, dest, cmd, cmd_size); +} + +static inline void cmd_chain_prod_idx_inc (struct hinic_api_cmd_chain *chain) +{ + chain->prod_idx =MASKED_IDX (chain, chain->prod_idx +1 ); +} + +static void issue_api_cmd (struct hinic_api_cmd_chain *chain) +{ +set_prod_idx (chain); +} + +/** +* api_cmd_status_update - update the status of the chain +* @chain: chain to update +**/ +static void api_cmd_status_update (struct hinic_api_cmd_chain *chain) +{ +struct hinic_api_cmd_status *wb_status; +enum hinic_api_cmd_chain_type chain_type; +u64 status_header; +u32 buf_desc; + + wb_status = chain->wb_status; + + buf_desc =be32_to_cpu (wb_status->buf_desc); +if (HINIC_API_CMD_STATUS_GET (buf_desc,CHKSUM_ERR )) { +PMD_DRV_LOG (ERR ,"API CMD status Xor check error" ); +return ; + } + + status_header =be64_to_cpu (wb_status->header); + chain_type =HINIC_API_CMD_STATUS_HEADER_GET (status_header,CHAIN_ID ); +if (chain_type >=HINIC_API_CMD_MAX ) +return ; + +if (chain_type != chain->chain_type) +return ; + + chain->cons_idx =HINIC_API_CMD_STATUS_GET (buf_desc,CONS_IDX ); +} + +/** +* wait_for_status_poll - wait for write to mgmt command to complete +* @chain: the chain of the command +* Return: 0 - success, negative - failure +**/ +static int wait_for_status_poll (struct hinic_api_cmd_chain *chain) +{ +unsigned long end; +int err = -ETIMEDOUT ; + + end = jiffies +msecs_to_jiffies (API_CMD_TIMEOUT ); +do { +api_cmd_status_update (chain); + +/* SYNC API CMD cmd should start after prev cmd finished */ +if (chain->cons_idx == chain->prod_idx) { + err =0 ; +break ; + } + +rte_delay_us (10 ); + }while (time_before (jiffies, end)); + +return err; +} + +/** +* wait_for_api_cmd_completion - wait for command to complete +* @chain: chain for the command +* Return: 0 - success, negative - failure +**/ +static int wait_for_api_cmd_completion (struct hinic_api_cmd_chain *chain, + __rte_unused struct hinic_api_cmd_cell_ctxt *ctxt, + __rte_unused void *ack, __rte_unused u16 ack_size) +{ +int err =0 ; + +/* poll api cmd status for debug*/ +switch (chain->chain_type) { +case HINIC_API_CMD_PMD_WRITE_TO_MGMT : + err =wait_for_status_poll (chain); +if (err) +PMD_DRV_LOG (ERR ,"API CMD poll status timeout" ); +break ; +case HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU : +break ; +default : +PMD_DRV_LOG (ERR ,"Unknown API CMD chain type" ); + err = -EINVAL ; +break ; + } + +if (err) +dump_api_chain_reg (chain); + +return err; +} + +static inline void update_api_cmd_ctxt (struct hinic_api_cmd_chain *chain, +struct hinic_api_cmd_cell_ctxt *ctxt) +{ + ctxt->status =1 ; + ctxt->saved_prod_idx = chain->prod_idx; +} + +/** +* api_cmd - API CMD command +* @chain: chain for the command +* @dest: destination node on the card that will receive the command +* @cmd: command data +* @cmd_size: the command size +* @ack: pointer to messages to response +* @ack_size: the size of ack message +* Return: 0 - success, negative - failure +**/ +static int api_cmd (struct hinic_api_cmd_chain *chain, +enum hinic_node_id dest, +void *cmd,u16 cmd_size,void *ack,u16 ack_size) +{ +struct hinic_api_cmd_cell_ctxt *ctxt; + +spin_lock (&chain->async_lock); + + ctxt = &chain->cell_ctxt[chain->prod_idx]; +if (chain_busy (chain)) { +spin_unlock (&chain->async_lock); +return -EBUSY ; + } +update_api_cmd_ctxt (chain, ctxt); + +prepare_cell (chain, dest, cmd, cmd_size); + +cmd_chain_prod_idx_inc (chain); + +rte_wmb ();/* issue the command */ + +issue_api_cmd (chain); + +/* incremented prod idx, update ctxt */ + chain->curr_node = chain->cell_ctxt[chain->prod_idx].cell_vaddr; + +spin_unlock (&chain->async_lock); + +return wait_for_api_cmd_completion (chain, ctxt, ack, ack_size); +} + +/** +* hinic_api_cmd_write - Write API CMD command +* @chain: chain for write command +* @dest: destination node on the card that will receive the command +* @cmd: command data +* @size: the command size +* Return: 0 - success, negative - failure +**/ +int hinic_api_cmd_write (struct hinic_api_cmd_chain *chain, +enum hinic_node_id dest,void *cmd,u16 size) +{ +/* Verify the chain type */ +return api_cmd (chain, dest, cmd, size,NULL ,0 ); +} + +/** +* api_cmd_hw_restart - restart the chain in the HW +* @chain: the API CMD specific chain to restart +**/ +static int api_cmd_hw_restart (struct hinic_api_cmd_chain *chain) +{ +struct hinic_hwif *hwif = chain->hwdev->hwif; +unsigned long end; +u32 reg_addr, val; +int err; + +/* Read Modify Write */ + reg_addr =HINIC_CSR_API_CMD_CHAIN_REQ_ADDR (chain->chain_type); + val =hinic_hwif_read_reg (hwif, reg_addr); + + val =HINIC_API_CMD_CHAIN_REQ_CLEAR (val,RESTART ); + val |=HINIC_API_CMD_CHAIN_REQ_SET (1 ,RESTART ); + +hinic_hwif_write_reg (hwif, reg_addr, val); + + end = jiffies +msecs_to_jiffies (API_CMD_TIMEOUT ); + err = -ETIMEDOUT ; +do { + val =hinic_hwif_read_reg (hwif, reg_addr); + +if (!HINIC_API_CMD_CHAIN_REQ_GET (val,RESTART )) { + err =0 ; +break ; + } + +rte_delay_ms (1 ); + }while (time_before (jiffies, end)); + +return err; +} + +/** +* api_cmd_ctrl_init - set the control register of a chain +* @chain: the API CMD specific chain to set control register for +**/ +static void api_cmd_ctrl_init (struct hinic_api_cmd_chain *chain) +{ +struct hinic_hwif *hwif = chain->hwdev->hwif; +u32 reg_addr, ctrl; +u32 cell_size; + +/* Read Modify Write */ + reg_addr =HINIC_CSR_API_CMD_CHAIN_CTRL_ADDR (chain->chain_type); + + cell_size = (u32 )ilog2 (chain->cell_size >> +API_CMD_CHAIN_CELL_SIZE_SHIFT ); + + ctrl =hinic_hwif_read_reg (hwif, reg_addr); + + ctrl =HINIC_API_CMD_CHAIN_CTRL_CLEAR (ctrl,AEQE_EN ) & +HINIC_API_CMD_CHAIN_CTRL_CLEAR (ctrl,CELL_SIZE ); + + ctrl |=HINIC_API_CMD_CHAIN_CTRL_SET (0 ,AEQE_EN ) | +HINIC_API_CMD_CHAIN_CTRL_SET (cell_size,CELL_SIZE ); + +hinic_hwif_write_reg (hwif, reg_addr, ctrl); +} + +/** +* api_cmd_set_status_addr - set the status address of a chain in the HW +* @chain: the API CMD specific chain to set status address for +**/ +static void api_cmd_set_status_addr (struct hinic_api_cmd_chain *chain) +{ +struct hinic_hwif *hwif = chain->hwdev->hwif; +u32 addr, val; + + addr =HINIC_CSR_API_CMD_STATUS_HI_ADDR (chain->chain_type); + val =upper_32_bits (chain->wb_status_paddr); +hinic_hwif_write_reg (hwif, addr, val); + + addr =HINIC_CSR_API_CMD_STATUS_LO_ADDR (chain->chain_type); + val =lower_32_bits (chain->wb_status_paddr); +hinic_hwif_write_reg (hwif, addr, val); +} + +/** +* api_cmd_set_num_cells - set the number cells of a chain in the HW +* @chain: the API CMD specific chain to set the number of cells for +**/ +static void api_cmd_set_num_cells (struct hinic_api_cmd_chain *chain) +{ +struct hinic_hwif *hwif = chain->hwdev->hwif; +u32 addr, val; + + addr =HINIC_CSR_API_CMD_CHAIN_NUM_CELLS_ADDR (chain->chain_type); + val = chain->num_cells; +hinic_hwif_write_reg (hwif, addr, val); +} + +/** +* api_cmd_head_init - set the head cell of a chain in the HW +* @chain: the API CMD specific chain to set the head for +**/ +static void api_cmd_head_init (struct hinic_api_cmd_chain *chain) +{ +struct hinic_hwif *hwif = chain->hwdev->hwif; +u32 addr, val; + + addr =HINIC_CSR_API_CMD_CHAIN_HEAD_HI_ADDR (chain->chain_type); + val =upper_32_bits (chain->head_cell_paddr); +hinic_hwif_write_reg (hwif, addr, val); + + addr =HINIC_CSR_API_CMD_CHAIN_HEAD_LO_ADDR (chain->chain_type); + val =lower_32_bits (chain->head_cell_paddr); +hinic_hwif_write_reg (hwif, addr, val); +} + +/** +* wait_for_ready_chain - wait for the chain to be ready +* @chain: the API CMD specific chain to wait for +* Return: 0 - success, negative - failure +**/ +static int wait_for_ready_chain (struct hinic_api_cmd_chain *chain) +{ +struct hinic_hwif *hwif = chain->hwdev->hwif; +unsigned long end; +u32 addr, val; +u32 hw_cons_idx; +int err; + + end = jiffies +msecs_to_jiffies (API_CMD_TIMEOUT ); + + addr =HINIC_CSR_API_CMD_STATUS_0_ADDR (chain->chain_type); + err = -ETIMEDOUT ; +do { + val =hinic_hwif_read_reg (hwif, addr); + hw_cons_idx =HINIC_API_CMD_STATUS_GET (val,CONS_IDX ); + +/* Wait for HW cons idx to be updated */ +if (hw_cons_idx == chain->cons_idx) { + err =0 ; +break ; + } + +rte_delay_ms (1 ); + }while (time_before (jiffies, end)); + +return err; +} + +/** +* api_cmd_chain_hw_clean - clean the HW +* @chain: the API CMD specific chain +**/ +static void api_cmd_chain_hw_clean (struct hinic_api_cmd_chain *chain) +{ +struct hinic_hwif *hwif = chain->hwdev->hwif; +u32 addr, ctrl; + + addr =HINIC_CSR_API_CMD_CHAIN_CTRL_ADDR (chain->chain_type); + + ctrl =hinic_hwif_read_reg (hwif, addr); + ctrl =HINIC_API_CMD_CHAIN_CTRL_CLEAR (ctrl,RESTART_EN ) & +HINIC_API_CMD_CHAIN_CTRL_CLEAR (ctrl,XOR_ERR ) & +HINIC_API_CMD_CHAIN_CTRL_CLEAR (ctrl,AEQE_EN ) & +HINIC_API_CMD_CHAIN_CTRL_CLEAR (ctrl,XOR_CHK_EN ) & +HINIC_API_CMD_CHAIN_CTRL_CLEAR (ctrl,CELL_SIZE ); + +hinic_hwif_write_reg (hwif, addr, ctrl); +} + +/** +* api_cmd_chain_hw_init - initialize the chain in the HW +*(initialize API command csr) +* @chain: the API CMD specific chain to initialize in HW +* Return: 0 - success, negative - failure +**/ +static int api_cmd_chain_hw_init (struct hinic_api_cmd_chain *chain) +{ +api_cmd_chain_hw_clean (chain); + +api_cmd_set_status_addr (chain); + +if (api_cmd_hw_restart (chain)) { +PMD_DRV_LOG (ERR ,"Restart api_cmd_hw failed" ); +return -EBUSY ; + } + +api_cmd_ctrl_init (chain); +api_cmd_set_num_cells (chain); +api_cmd_head_init (chain); + +return wait_for_ready_chain (chain); +} + +/** +* free_cmd_buf - free the dma buffer of API CMD command +* @chain: the API CMD specific chain of the cmd +* @cell_idx: the cell index of the cmd +**/ +static void free_cmd_buf (struct hinic_api_cmd_chain *chain,u32 cell_idx) +{ +struct hinic_api_cmd_cell_ctxt *cell_ctxt; +void *dev = chain->hwdev->dev_hdl; + + cell_ctxt = &chain->cell_ctxt[cell_idx]; + +dma_free_coherent (dev, (API_CMD_BUF_SIZE +API_PAYLOAD_ALIGN_SIZE ), + cell_ctxt->api_cmd_vaddr_free, + cell_ctxt->api_cmd_paddr_free); +} + +/** +* alloc_cmd_buf - allocate a dma buffer for API CMD command +* @chain: the API CMD specific chain for the cmd +* @cell: the cell in the HW for the cmd +* @cell_idx: the index of the cell +* Return: 0 - success, negative - failure +**/ +static int alloc_cmd_buf (struct hinic_api_cmd_chain *chain, +struct hinic_api_cmd_cell *cell,u32 cell_idx) +{ +void *dev = chain->hwdev->dev_hdl; +struct hinic_api_cmd_cell_ctxt *cell_ctxt; +dma_addr_t cmd_paddr =0 ; +void *cmd_vaddr; +void *cmd_vaddr_alloc; +int err =0 ; + + cmd_vaddr_alloc =dma_zalloc_coherent (dev, (API_CMD_BUF_SIZE + +API_PAYLOAD_ALIGN_SIZE ), + &cmd_paddr,GFP_KERNEL ); +if (!cmd_vaddr_alloc) { +PMD_DRV_LOG (ERR ,"Allocate API CMD dma memory failed" ); +return -ENOMEM ; + } + + cell_ctxt = &chain->cell_ctxt[cell_idx]; + + cell_ctxt->api_cmd_paddr_free = cmd_paddr; + cell_ctxt->api_cmd_vaddr_free = cmd_vaddr_alloc; + cmd_vaddr =PTR_ALIGN (cmd_vaddr_alloc,API_PAYLOAD_ALIGN_SIZE ); + cmd_paddr = cmd_paddr + ((u64 )cmd_vaddr - (u64 )cmd_vaddr_alloc); + + cell_ctxt->api_cmd_vaddr = cmd_vaddr; + cell_ctxt->api_cmd_paddr = cmd_paddr; + +/* set the cmd DMA address in the cell */ +switch (chain->chain_type) { +case HINIC_API_CMD_PMD_WRITE_TO_MGMT : +case HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU : + cell->write.hw_cmd_paddr =cpu_to_be64 (cmd_paddr); +break ; +default : +PMD_DRV_LOG (ERR ,"Unknown API CMD chain type" ); +free_cmd_buf (chain, cell_idx); + err = -EINVAL ; +break ; + } + +return err; +} + +/** +* api_cmd_create_cell - create API CMD cell of specific chain +* @chain: the API CMD specific chain to create its cell +* @cell_idx: the cell index to create +* @pre_node: previous cell +* @node_vaddr: the virt addr of the cell +* Return: 0 - success, negative - failure +**/ +static int api_cmd_create_cell (struct hinic_api_cmd_chain *chain, +u32 cell_idx, +struct hinic_api_cmd_cell *pre_node, +struct hinic_api_cmd_cell **node_vaddr) +{ +void *dev = chain->hwdev->dev_hdl; +struct hinic_api_cmd_cell_ctxt *cell_ctxt; +struct hinic_api_cmd_cell *node; +dma_addr_t node_paddr =0 ; +void *node_vaddr_alloc; +int err =0 ; + + node_vaddr_alloc =dma_zalloc_coherent (dev, (chain->cell_size + +API_CMD_NODE_ALIGN_SIZE ), + &node_paddr,GFP_KERNEL ); +if (!node_vaddr_alloc) { +PMD_DRV_LOG (ERR ,"Allocate dma API CMD cell failed" ); +return -ENOMEM ; + } + + cell_ctxt = &chain->cell_ctxt[cell_idx]; + + cell_ctxt->cell_vaddr_free = node_vaddr_alloc; + cell_ctxt->cell_paddr_free = node_paddr; + node = (struct hinic_api_cmd_cell *)PTR_ALIGN (node_vaddr_alloc, +API_CMD_NODE_ALIGN_SIZE ); + node_paddr = node_paddr + ((u64 )node - (u64 )node_vaddr_alloc); + + node->read.hw_wb_resp_paddr =0 ; + + cell_ctxt->cell_vaddr = node; + cell_ctxt->cell_paddr = node_paddr; + +if (!pre_node) { + chain->head_node = node; + chain->head_cell_paddr = node_paddr; + }else { +/* The data in the HW should be in Big Endian Format */ + pre_node->next_cell_paddr =cpu_to_be64 (node_paddr); + } + +/* Driver software should make sure that there is an empty +* API command cell at the end the chain +*/ + node->next_cell_paddr =0 ; + +switch (chain->chain_type) { +case HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU : +case HINIC_API_CMD_PMD_WRITE_TO_MGMT : + err =alloc_cmd_buf (chain, node, cell_idx); +if (err) { +PMD_DRV_LOG (ERR ,"Allocate cmd buffer failed" ); + goto alloc_cmd_buf_err; + } +break ; +default : +PMD_DRV_LOG (ERR ,"Unsupported API CMD chain type" ); + err = -EINVAL ; + goto alloc_cmd_buf_err; + } + + *node_vaddr = node; + +return 0 ; + +alloc_cmd_buf_err: +dma_free_coherent (dev, (chain->cell_size +API_CMD_NODE_ALIGN_SIZE ), + node_vaddr_alloc, cell_ctxt->cell_paddr_free); + +return err; +} + +/** +* api_cmd_destroy_cell - destroy API CMD cell of specific chain +* @chain: the API CMD specific chain to destroy its cell +* @cell_idx: the cell to destroy +**/ +static void api_cmd_destroy_cell (struct hinic_api_cmd_chain *chain, +u32 cell_idx) +{ +void *dev = chain->hwdev->dev_hdl; +struct hinic_api_cmd_cell_ctxt *cell_ctxt; +struct hinic_api_cmd_cell *node; +dma_addr_t node_paddr; + + cell_ctxt = &chain->cell_ctxt[cell_idx]; + + node = (struct hinic_api_cmd_cell *)(cell_ctxt->cell_vaddr_free); + node_paddr = cell_ctxt->cell_paddr_free; + +if (cell_ctxt->api_cmd_vaddr) { +switch (chain->chain_type) { +case HINIC_API_CMD_PMD_WRITE_TO_MGMT : +case HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU : +free_cmd_buf (chain, cell_idx); +break ; +default : +break ; + } + +dma_free_coherent (dev, (chain->cell_size + +API_CMD_NODE_ALIGN_SIZE ), + node, node_paddr); + } +} + +/** +* api_cmd_destroy_cells - destroy API CMD cells of specific chain +* @chain: the API CMD specific chain to destroy its cells +* @num_cells: number of cells to destroy +**/ +static void api_cmd_destroy_cells (struct hinic_api_cmd_chain *chain, +u32 num_cells) +{ +u32 cell_idx; + +for (cell_idx =0 ; cell_idx < num_cells; cell_idx++) +api_cmd_destroy_cell (chain, cell_idx); +} + +/** +* api_cmd_create_cells - create API CMD cells for specific chain +* @chain: the API CMD specific chain +* Return: 0 - success, negative - failure +**/ +static int api_cmd_create_cells (struct hinic_api_cmd_chain *chain) +{ +struct hinic_api_cmd_cell *node =NULL , *pre_node =NULL ; +u32 cell_idx; +int err; + +for (cell_idx =0 ; cell_idx < chain->num_cells; cell_idx++) { + err =api_cmd_create_cell (chain, cell_idx, pre_node, &node); +if (err) { +PMD_DRV_LOG (ERR ,"Create API CMD cell failed" ); + goto create_cell_err; + } + + pre_node = node; + } + +if (!node) { + err = -EFAULT ; + goto create_cell_err; + } + +/* set the Final node to point on the start */ + node->next_cell_paddr =cpu_to_be64 (chain->head_cell_paddr); + +/* set the current node to be the head */ + chain->curr_node = chain->head_node; +return 0 ; + +create_cell_err: +api_cmd_destroy_cells (chain, cell_idx); +return err; +} + +/** +* api_chain_init - initialize API CMD specific chain +* @chain: the API CMD specific chain to initialize +* @attr: attributes to set in the chain +* Return: 0 - success, negative - failure +**/ +static int api_chain_init (struct hinic_api_cmd_chain *chain, +struct hinic_api_cmd_chain_attr *attr) +{ +void *dev = chain->hwdev->dev_hdl; +size_t cell_ctxt_size; +int err; + + chain->chain_type = attr->chain_type; + chain->num_cells = attr->num_cells; + chain->cell_size = attr->cell_size; + chain->rsp_size = attr->rsp_size; + + chain->prod_idx =0 ; + chain->cons_idx =0 ; + +spin_lock_init (&chain->async_lock); + + cell_ctxt_size = chain->num_cells *sizeof (*chain->cell_ctxt); + chain->cell_ctxt =kzalloc (cell_ctxt_size,GFP_KERNEL ); +if (!chain->cell_ctxt) { +PMD_DRV_LOG (ERR ,"Allocate cell contexts for a chain failed" ); + err = -ENOMEM ; + goto alloc_cell_ctxt_err; + } + + chain->wb_status = (struct hinic_api_cmd_status *) +dma_zalloc_coherent (dev,sizeof (*chain->wb_status), + &chain->wb_status_paddr, +GFP_KERNEL ); +if (!chain->wb_status) { +PMD_DRV_LOG (ERR ,"Allocate DMA wb status failed" ); + err = -ENOMEM ; + goto alloc_wb_status_err; + } + +return 0 ; + +alloc_wb_status_err: +kfree (chain->cell_ctxt); + +alloc_cell_ctxt_err: + +return err; +} + +/** +* api_chain_free - free API CMD specific chain +* @chain: the API CMD specific chain to free +**/ +static void api_chain_free (struct hinic_api_cmd_chain *chain) +{ +void *dev = chain->hwdev->dev_hdl; + +dma_free_coherent (dev,sizeof (*chain->wb_status), + chain->wb_status, chain->wb_status_paddr); +kfree (chain->cell_ctxt); +} + +/** +* api_cmd_create_chain - create API CMD specific chain +* @cmd_chain: the API CMD specific chain to create +* @attr: attributes to set in the chain +* Return: 0 - success, negative - failure +**/ +static int api_cmd_create_chain (struct hinic_api_cmd_chain **cmd_chain, +struct hinic_api_cmd_chain_attr *attr) +{ +struct hinic_hwdev *hwdev = attr->hwdev; +struct hinic_api_cmd_chain *chain; +int err; + +if (attr->num_cells & (attr->num_cells -1 )) { +PMD_DRV_LOG (ERR ,"Invalid number of cells, must be power of 2" ); +return -EINVAL ; + } + + chain =kzalloc (sizeof (*chain),GFP_KERNEL ); +if (!chain) { +PMD_DRV_LOG (ERR ,"Allocate memory for the chain failed" ); +return -ENOMEM ; + } + + chain->hwdev = hwdev; + + err =api_chain_init (chain, attr); +if (err) { +PMD_DRV_LOG (ERR ,"Initialize chain failed" ); + goto chain_init_err; + } + + err =api_cmd_create_cells (chain); +if (err) { +PMD_DRV_LOG (ERR ,"Create cells for API CMD chain failed" ); + goto create_cells_err; + } + + err =api_cmd_chain_hw_init (chain); +if (err) { +PMD_DRV_LOG (ERR ,"Initialize chain hw info failed" ); + goto chain_hw_init_err; + } + + *cmd_chain = chain; +return 0 ; + +chain_hw_init_err: +api_cmd_destroy_cells (chain, chain->num_cells); + +create_cells_err: +api_chain_free (chain); + +chain_init_err: +kfree (chain); +return err; +} + +/** +* api_cmd_destroy_chain - destroy API CMD specific chain +* @chain: the API CMD specific chain to destroy +**/ +static void api_cmd_destroy_chain (struct hinic_api_cmd_chain *chain) +{ +api_cmd_destroy_cells (chain, chain->num_cells); +api_chain_free (chain); +kfree (chain); +} + +/** +* hinic_api_cmd_init - Initialize all the API CMD chains +* @hwdev: the hardware interface of a pci function device +* @chain: the API CMD chains that will be initialized +* Return: 0 - success, negative - failure +**/ +int hinic_api_cmd_init (struct hinic_hwdev *hwdev, +struct hinic_api_cmd_chain **chain) +{ +struct hinic_api_cmd_chain_attr attr; +enum hinic_api_cmd_chain_type chain_type, i; +int err; + + attr.hwdev = hwdev; + attr.num_cells =API_CHAIN_NUM_CELLS ; + attr.cell_size =API_CHAIN_CELL_SIZE ; + attr.rsp_size =API_CHAIN_RSP_DATA_SIZE ; + + chain_type =HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU ; +for ( ; chain_type <HINIC_API_CMD_MAX ; chain_type++) { + attr.chain_type = chain_type; + err =api_cmd_create_chain (&chain[chain_type], &attr); +if (err) { +PMD_DRV_LOG (ERR ,"Create chain %d failed" , + chain_type); + goto create_chain_err; + } + } + +return 0 ; + +create_chain_err: + i =HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU ; +for (; i < chain_type; i++) +api_cmd_destroy_chain (chain[i]); + +return err; +} + +/** +* hinic_api_cmd_free - free the API CMD chains +* @chain: the API CMD chains that will be freed +**/ +void hinic_api_cmd_free (struct hinic_api_cmd_chain **chain) +{ +enum hinic_api_cmd_chain_type chain_type; + + chain_type =HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU ; +for ( ; chain_type <HINIC_API_CMD_MAX ; chain_type++) +api_cmd_destroy_chain (chain[chain_type]); +}
drivers/net/hinic/base/hinic_pmd_api_cmd.h new file +271 -0
271 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_cmdq.c new file +901 -0
901 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_cmdq.h new file +190 -0
190 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v4 3/11 net/hinic/base: add mgmt module interactive code
In reply to Ziyang XuanAdd the structures, functionalities for interaction with mgmt module.
--- drivers/net/hinic/base/hinic_pmd_hw_mgmt.h | 85 +++ drivers/net/hinic/base/hinic_pmd_mgmt.c | 617 ++++++++++++++++++ drivers/net/hinic/base/hinic_pmd_mgmt.h | 125 ++++ .../net/hinic/base/hinic_pmd_mgmt_interface.h | 503 ++++++++++++++ 4 files changed, 1330 insertions(+) create mode 100644 drivers/net/hinic/base/hinic_pmd_hw_mgmt.h create mode 100644 drivers/net/hinic/base/hinic_pmd_mgmt.c create mode 100644 drivers/net/hinic/base/hinic_pmd_mgmt.h create mode 100644 drivers/net/hinic/base/hinic_pmd_mgmt_interface.h
drivers/net/hinic/base/hinic_pmd_hw_mgmt.h new file +85 -0
@@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#ifndef _HINIC_PMD_HW_MGMT_H_ +#define _HINIC_PMD_HW_MGMT_H_ + +/* show each drivers only such as nic_service_cap, +* toe_service_cap structure, but not show service_cap +*/ +enum hinic_service_type { +SERVICE_T_NIC =0 , +SERVICE_T_MAX =7 , + +/* Only used for interruption resource management, +* mark the request module +*/ +SERVICE_T_INTF = (1 <<15 ), +SERVICE_T_CQM = (1 <<16 ), +}; + +enum intr_type { +INTR_TYPE_MSIX , +INTR_TYPE_MSI , +INTR_TYPE_INT , +/* PXE,OVS need single thread processing, synchronization +* messages must use poll wait mechanism interface +*/ +INTR_TYPE_NONE , +}; + +struct nic_service_cap { +/* PF resources */ +u16 max_sqs; +u16 max_rqs; + +/* VF resources, VF obtain them through the MailBox mechanism from +* corresponding PF +*/ +u16 vf_max_sqs; +u16 vf_max_rqs; + +bool lro_en;/* LRO feature enable bit */ +u8 lro_sz;/* LRO context space: n*16B */ +u8 tso_sz;/* TSO context space: n*16B */ +}; + +/* Defines the IRQ information structure*/ +struct irq_info { +u16 msix_entry_idx;/* IRQ corresponding index number */ +u32 irq_id;/* the IRQ number from OS */ +}; + +/* Define the version information structure*/ +struct dev_version_info { +u8 up_ver;/* uP version, directly read from uP +* is not configured to file +*/ +u8 ucode_ver;/* The microcode version, +* read through the CMDq from microcode +*/ +u8 cfg_file_ver;/* uP configuration file version */ +u8 sdk_ver;/* SDK driver version */ +u8 hw_ver;/* Hardware version */ +}; + +/* Obtain service_cap.nic_cap.dev_nic_cap.max_sqs */ +u16 hinic_func_max_qnum (void *hwdev); + +u16 hinic_global_func_id (void *hwdev);/* func_attr.glb_func_idx */ + +enum func_type { +TYPE_PF , +TYPE_VF , +TYPE_PPF , +}; + +enum hinic_msix_state { +HINIC_MSIX_ENABLE , +HINIC_MSIX_DISABLE , +}; + +enum func_type hinic_func_type (void *hwdev); + +#endif /* _HINIC_PMD_HW_MGMT_H_ */
drivers/net/hinic/base/hinic_pmd_mgmt.c new file +617 -0
617 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_mgmt.h new file +125 -0
125 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_mgmt_interface.h new file +503 -0
503 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v4 4/11 net/hinic/base: add code about hardware operation
In reply to Ziyang XuanAdd code for hardware operation, including configuration, query and so on.
--- drivers/net/hinic/base/hinic_pmd_cfg.c | 269 ++++ drivers/net/hinic/base/hinic_pmd_cfg.h | 264 ++++ drivers/net/hinic/base/hinic_pmd_hw.h | 49 + drivers/net/hinic/base/hinic_pmd_hwdev.c | 1544 ++++++++++++++++++++++ drivers/net/hinic/base/hinic_pmd_hwdev.h | 205 +++ drivers/net/hinic/base/hinic_pmd_hwif.c | 542 ++++++++ drivers/net/hinic/base/hinic_pmd_hwif.h | 90 ++ 7 files changed, 2963 insertions(+) create mode 100644 drivers/net/hinic/base/hinic_pmd_cfg.c create mode 100644 drivers/net/hinic/base/hinic_pmd_cfg.h create mode 100644 drivers/net/hinic/base/hinic_pmd_hw.h create mode 100644 drivers/net/hinic/base/hinic_pmd_hwdev.c create mode 100644 drivers/net/hinic/base/hinic_pmd_hwdev.h create mode 100644 drivers/net/hinic/base/hinic_pmd_hwif.c create mode 100644 drivers/net/hinic/base/hinic_pmd_hwif.h
drivers/net/hinic/base/hinic_pmd_cfg.c new file +269 -0
@@ -0,0 +1,269 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#include "hinic_pmd_dpdev.h" + +static void parse_dev_cap (struct hinic_hwdev *dev, +struct hinic_dev_cap *dev_cap, +enum func_type type); + +bool hinic_support_nic (struct hinic_hwdev *hwdev,struct nic_service_cap *cap) +{ +if (!hwdev) +return false; + +if (!IS_NIC_TYPE (hwdev)) +return false; + +if (cap) +memcpy (cap, &hwdev->cfg_mgmt->svc_cap.nic_cap,sizeof (*cap)); + +return true; +} + +static void hinic_parse_shared_res_cap (struct service_cap *cap, +struct hinic_dev_cap *dev_cap, + __rte_unused enum func_type type) +{ +struct host_shared_resource_cap *shared_cap = &cap->shared_res_cap; + + shared_cap->host_pctxs = dev_cap->host_pctx_num; + +if (dev_cap->host_sf_en) + cap->sf_en = true; +else + cap->sf_en = false; + + shared_cap->host_cctxs = dev_cap->host_ccxt_num; + shared_cap->host_scqs = dev_cap->host_scq_num; + shared_cap->host_srqs = dev_cap->host_srq_num; + shared_cap->host_mpts = dev_cap->host_mpt_num; + +PMD_DRV_LOG (INFO ,"Get share resource capability:" ); +PMD_DRV_LOG (INFO ,"host_pctxs: 0x%x, host_cctxs: 0x%x, host_scqs: 0x%x, host_srqs: 0x%x, host_mpts: 0x%x" , + shared_cap->host_pctxs, shared_cap->host_cctxs, + shared_cap->host_scqs, shared_cap->host_srqs, + shared_cap->host_mpts); +} + +static void hinic_parse_l2nic_res_cap (struct service_cap *cap, +struct hinic_dev_cap *dev_cap, +enum func_type type) +{ +struct nic_service_cap *nic_cap = &cap->nic_cap; + +if (type ==TYPE_PF || type ==TYPE_PPF ) { + nic_cap->max_sqs = dev_cap->nic_max_sq +1 ; + nic_cap->max_rqs = dev_cap->nic_max_rq +1 ; + nic_cap->vf_max_sqs = dev_cap->nic_vf_max_sq +1 ; + nic_cap->vf_max_rqs = dev_cap->nic_vf_max_rq +1 ; + }else { + nic_cap->max_sqs = dev_cap->nic_max_sq; + nic_cap->max_rqs = dev_cap->nic_max_rq; + nic_cap->vf_max_sqs =0 ; + nic_cap->vf_max_rqs =0 ; + } + +if (dev_cap->nic_lro_en) + nic_cap->lro_en = true; +else + nic_cap->lro_en = false; + + nic_cap->lro_sz = dev_cap->nic_lro_sz; + nic_cap->tso_sz = dev_cap->nic_tso_sz; + +PMD_DRV_LOG (INFO ,"Get l2nic resource capability:" ); +PMD_DRV_LOG (INFO ,"max_sqs: 0x%x, max_rqs: 0x%x, vf_max_sqs: 0x%x, vf_max_rqs: 0x%x" , + nic_cap->max_sqs, nic_cap->max_rqs, + nic_cap->vf_max_sqs, nic_cap->vf_max_rqs); +} + +static int get_cap_from_fw (struct hinic_hwdev *dev,enum func_type type) +{ +int err; +u16 in_len, out_len; +struct hinic_dev_cap dev_cap; + +memset (&dev_cap,0 ,sizeof (dev_cap)); + in_len =sizeof (dev_cap); + out_len = in_len; + dev_cap.mgmt_msg_head.resp_aeq_num =HINIC_AEQ1 ; + err =hinic_msg_to_mgmt_sync (dev,HINIC_MOD_CFGM ,HINIC_CFG_NIC_CAP , + &dev_cap, in_len, &dev_cap, &out_len,0 ); +if (err || dev_cap.mgmt_msg_head.status || !out_len) { +PMD_DRV_LOG (ERR ,"Get capability from FW failed, err: %d, status: %d, out_len: %d" , + err, dev_cap.mgmt_msg_head.status, out_len); +return -EFAULT ; + } + +parse_dev_cap (dev, &dev_cap, type); +return 0 ; +} + +static int get_dev_cap (struct hinic_hwdev *dev) +{ +int err; +enum func_type type =HINIC_FUNC_TYPE (dev); + +switch (type) { +case TYPE_PF : +case TYPE_PPF : + err =get_cap_from_fw (dev, type); +if (err) { +PMD_DRV_LOG (ERR ,"Get PF/PPF capability failed" ); +return err; + } +break ; +default : +PMD_DRV_LOG (ERR ,"Unsupported PCI function type" ); +return -EINVAL ; + } + +return 0 ; +} + +u16 hinic_func_max_qnum (void *hwdev) +{ +struct hinic_hwdev *dev = (struct hinic_hwdev *)hwdev; + +return dev->cfg_mgmt->svc_cap.max_sqs; +} + +int init_cfg_mgmt (struct hinic_hwdev *dev) +{ +struct cfg_mgmt_info *cfg_mgmt; + + cfg_mgmt =kzalloc (sizeof (*cfg_mgmt),GFP_KERNEL ); +if (!cfg_mgmt) { +PMD_DRV_LOG (ERR ,"Alloc cfg mgmt failed" ); +return -ENOMEM ; + } + + dev->cfg_mgmt = cfg_mgmt; + cfg_mgmt->hwdev = dev; + +return 0 ; +} + +void free_cfg_mgmt (struct hinic_hwdev *dev) +{ +kfree (dev->cfg_mgmt); + dev->cfg_mgmt =NULL ; +} + +static void hinic_parse_pub_res_cap (struct service_cap *cap, +struct hinic_dev_cap *dev_cap, +enum func_type type) +{ +struct dev_sf_svc_attr *attr = &cap->sf_svc_attr; + +if (dev_cap->sf_svc_attr &SF_SVC_FT_BIT ) + attr->ft_en = true; +else + attr->ft_en = false; + +if (dev_cap->sf_svc_attr &SF_SVC_RDMA_BIT ) + attr->rdma_en = true; +else + attr->rdma_en = false; + +if (type ==TYPE_PPF ) { +/* For PPF's SF EN flag, we assign it in get_dynamic_res_cap(). +* we only save its VF's flag. +*/ + attr->sf_en_vf = dev_cap->sf_en_vf; + }else if (type ==TYPE_PF ) { +if (dev_cap->sf_en_pf) + cap->sf_en = true; +else + cap->sf_en = false; + + attr->sf_en_vf = dev_cap->sf_en_vf; + } + + cap->host_id = dev_cap->host_id; + cap->ep_id = dev_cap->ep_id; + cap->interrupt_type = dev_cap->intr_type; + cap->max_cos_id = dev_cap->max_cos_id; + cap->er_id = dev_cap->er_id; + cap->port_id = dev_cap->port_id; + +if (type ==TYPE_PF || type ==TYPE_PPF ) { + cap->max_vf = dev_cap->max_vf; + cap->pf_num = dev_cap->pf_num; + cap->pf_id_start = dev_cap->pf_id_start; + cap->vf_num = dev_cap->vf_num; + cap->vf_id_start = dev_cap->vf_id_start; + cap->max_sqs = dev_cap->nic_max_sq +1 ; + cap->max_rqs = dev_cap->nic_max_rq +1 ; + } + + cap->chip_svc_type =CFG_SVC_NIC_BIT0 ; + cap->host_total_function = dev_cap->host_total_func; + cap->host_oq_id_mask_val = dev_cap->host_oq_id_mask_val; + cap->max_connect_num = dev_cap->max_conn_num; + cap->max_stick2cache_num = dev_cap->max_stick2cache_num; + cap->bfilter_start_addr = dev_cap->max_bfilter_start_addr; + cap->bfilter_len = dev_cap->bfilter_len; + cap->hash_bucket_num = dev_cap->hash_bucket_num; + cap->dev_ver_info.cfg_file_ver = dev_cap->cfg_file_ver; + cap->net_port_mode = dev_cap->net_port_mode; + +PMD_DRV_LOG (INFO ,"Get public resource capability:" ); +PMD_DRV_LOG (INFO ,"host_id: 0x%x, ep_id: 0x%x, intr_type: 0x%x, max_cos_id: 0x%x, er_id: 0x%x, port_id: 0x%x" , + cap->host_id, cap->ep_id, cap->intr_chip_en, + cap->max_cos_id, cap->er_id, cap->port_id); +PMD_DRV_LOG (INFO ,"host_total_function: 0x%x, host_oq_id_mask_val: 0x%x, net_port_mode: 0x%x, max_vf: 0x%x" , + cap->host_total_function, cap->host_oq_id_mask_val, + cap->net_port_mode, cap->max_vf); +PMD_DRV_LOG (INFO ,"pf_num: 0x%x, pf_id_start: 0x%x, 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_dev_cap (struct hinic_hwdev *dev, +struct hinic_dev_cap *dev_cap, +enum func_type type) +{ +struct service_cap *cap = &dev->cfg_mgmt->svc_cap; + +/* Public resource */ +hinic_parse_pub_res_cap (cap, dev_cap, type); + +/* PPF managed dynamic resource */ +if (type ==TYPE_PPF ) +hinic_parse_shared_res_cap (cap, dev_cap, type); + +/* L2 NIC resource */ +if (IS_NIC_TYPE (dev)) +hinic_parse_l2nic_res_cap (cap, dev_cap, type); +} + +int hinic_init_capability (struct hinic_nic_dev *nic_dev) +{ +int err; +struct hinic_hwdev *dev = nic_dev->hwdev; +struct cfg_mgmt_info *cfg_mgmt = dev->cfg_mgmt; + + cfg_mgmt->svc_cap.sf_svc_attr.ft_pf_en = false; + cfg_mgmt->svc_cap.sf_svc_attr.rdma_pf_en = false; + + cfg_mgmt->svc_cap.max_connect_num =1024 *1024 ;/* 1M */ + cfg_mgmt->svc_cap.max_stick2cache_num =12 *1024 ; + + cfg_mgmt->svc_cap.timer_en = true; + cfg_mgmt->svc_cap.bloomfilter_en = false; + + err =get_dev_cap (dev); +if (err) +return err; + +/* get nic capability */ +if (!hinic_support_nic (dev, &nic_dev->nic_cap)) { +PMD_DRV_LOG (ERR ,"Device does not support nic feature" ); +return -ENOTSUP ; + } + +return 0 ; +}
drivers/net/hinic/base/hinic_pmd_cfg.h new file +264 -0
264 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_hw.h new file +49 -0
49 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_hwdev.c new file +1544 -0
1,544 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_hwdev.h new file +205 -0
205 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_hwif.c new file +542 -0
542 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_hwif.h new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v4 5/11 net/hinic/base: add eqs and context code
In reply to Ziyang XuanAdd code for eq. Aeq is a kind queue for mgmt asynchronous message and mgmt command response message.
--- drivers/net/hinic/base/hinic_ctx_def.h | 184 ++++++ drivers/net/hinic/base/hinic_pmd_dpdev.h | 146 +++++ drivers/net/hinic/base/hinic_pmd_eqs.c | 725 +++++++++++++++++++++++ drivers/net/hinic/base/hinic_pmd_eqs.h | 94 +++ 4 files changed, 1149 insertions(+) create mode 100644 drivers/net/hinic/base/hinic_ctx_def.h create mode 100644 drivers/net/hinic/base/hinic_pmd_dpdev.h create mode 100644 drivers/net/hinic/base/hinic_pmd_eqs.c create mode 100644 drivers/net/hinic/base/hinic_pmd_eqs.h
drivers/net/hinic/base/hinic_ctx_def.h new file +184 -0
@@ -0,0 +1,184 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#ifndef _HINIC_CTX_DEF_H_ +#define _HINIC_CTX_DEF_H_ + +#define MASKED_SQ_IDX (sq, idx) ((idx) & (sq)->wq->mask) + +#define HINIC_Q_CTXT_MAX 42 + +/* performance: ci addr RTE_CACHE_SIZE(64B) alignment */ +#define HINIC_CI_Q_ADDR_SIZE (64) + +#define CI_TABLE_SIZE (num_qps, pg_sz) \ + (ALIGN((num_qps) * HINIC_CI_Q_ADDR_SIZE, pg_sz)) + +#define HINIC_CI_VADDR (base_addr, q_id) ((u8 *)(base_addr) + \ + (q_id) * HINIC_CI_Q_ADDR_SIZE) + +#define HINIC_CI_PADDR (base_paddr, q_id) ((base_paddr) + \ + (q_id) * HINIC_CI_Q_ADDR_SIZE) + +#define Q_CTXT_SIZE 48 +#define TSO_LRO_CTXT_SIZE 240 + +#define SQ_CTXT_OFFSET (max_sqs, max_rqs, q_id) \ + (((max_rqs) + (max_sqs)) * TSO_LRO_CTXT_SIZE \ + + (q_id) * Q_CTXT_SIZE) + +#define RQ_CTXT_OFFSET (max_sqs, max_rqs, q_id) \ + (((max_rqs) + (max_sqs)) * TSO_LRO_CTXT_SIZE \ + + (max_sqs) * Q_CTXT_SIZE + (q_id) * Q_CTXT_SIZE) + +#define SQ_CTXT_SIZE (num_sqs) ((u16)(sizeof(struct hinic_qp_ctxt_header) \ + + (num_sqs) * sizeof(struct hinic_sq_ctxt))) + +#define RQ_CTXT_SIZE (num_rqs) ((u16)(sizeof(struct hinic_qp_ctxt_header) \ + + (num_rqs) * sizeof(struct hinic_rq_ctxt))) + +#define SQ_CTXT_CEQ_ATTR_CEQ_ID_SHIFT 8 +#define SQ_CTXT_CEQ_ATTR_GLOBAL_SQ_ID_SHIFT 13 +#define SQ_CTXT_CEQ_ATTR_EN_SHIFT 23 +#define SQ_CTXT_CEQ_ATTR_ARM_SHIFT 31 + +#define SQ_CTXT_CEQ_ATTR_CEQ_ID_MASK 0x1FU +#define SQ_CTXT_CEQ_ATTR_GLOBAL_SQ_ID_MASK 0x3FFU +#define SQ_CTXT_CEQ_ATTR_EN_MASK 0x1U +#define SQ_CTXT_CEQ_ATTR_ARM_MASK 0x1U + +#define SQ_CTXT_CEQ_ATTR_SET (val, member) (((val) & \ + SQ_CTXT_CEQ_ATTR_##member##_MASK) \ + << SQ_CTXT_CEQ_ATTR_##member##_SHIFT) + +#define SQ_CTXT_CI_IDX_SHIFT 11 +#define SQ_CTXT_CI_OWNER_SHIFT 23 + +#define SQ_CTXT_CI_IDX_MASK 0xFFFU +#define SQ_CTXT_CI_OWNER_MASK 0x1U + +#define SQ_CTXT_CI_SET (val, member) (((val) & \ + SQ_CTXT_CI_##member##_MASK) \ + << SQ_CTXT_CI_##member##_SHIFT) + +#define SQ_CTXT_WQ_PAGE_HI_PFN_SHIFT 0 +#define SQ_CTXT_WQ_PAGE_PI_SHIFT 20 + +#define SQ_CTXT_WQ_PAGE_HI_PFN_MASK 0xFFFFFU +#define SQ_CTXT_WQ_PAGE_PI_MASK 0xFFFU + +#define SQ_CTXT_WQ_PAGE_SET (val, member) (((val) & \ + SQ_CTXT_WQ_PAGE_##member##_MASK) \ + << SQ_CTXT_WQ_PAGE_##member##_SHIFT) + +#define SQ_CTXT_PREF_CACHE_THRESHOLD_SHIFT 0 +#define SQ_CTXT_PREF_CACHE_MAX_SHIFT 14 +#define SQ_CTXT_PREF_CACHE_MIN_SHIFT 25 + +#define SQ_CTXT_PREF_CACHE_THRESHOLD_MASK 0x3FFFU +#define SQ_CTXT_PREF_CACHE_MAX_MASK 0x7FFU +#define SQ_CTXT_PREF_CACHE_MIN_MASK 0x7FU + +#define SQ_CTXT_PREF_WQ_PFN_HI_SHIFT 0 +#define SQ_CTXT_PREF_CI_SHIFT 20 + +#define SQ_CTXT_PREF_WQ_PFN_HI_MASK 0xFFFFFU +#define SQ_CTXT_PREF_CI_MASK 0xFFFU + +#define SQ_CTXT_PREF_SET (val, member) (((val) & \ + SQ_CTXT_PREF_##member##_MASK) \ + << SQ_CTXT_PREF_##member##_SHIFT) + +#define SQ_CTXT_WQ_BLOCK_PFN_HI_SHIFT 0 + +#define SQ_CTXT_WQ_BLOCK_PFN_HI_MASK 0x7FFFFFU + +#define SQ_CTXT_WQ_BLOCK_SET (val, member) (((val) & \ + SQ_CTXT_WQ_BLOCK_##member##_MASK) \ + << SQ_CTXT_WQ_BLOCK_##member##_SHIFT) + +#define RQ_CTXT_CEQ_ATTR_EN_SHIFT 0 +#define RQ_CTXT_CEQ_ATTR_OWNER_SHIFT 1 + +#define RQ_CTXT_CEQ_ATTR_EN_MASK 0x1U +#define RQ_CTXT_CEQ_ATTR_OWNER_MASK 0x1U + +#define RQ_CTXT_CEQ_ATTR_SET (val, member) (((val) & \ + RQ_CTXT_CEQ_ATTR_##member##_MASK) \ + << RQ_CTXT_CEQ_ATTR_##member##_SHIFT) + +#define RQ_CTXT_PI_IDX_SHIFT 0 +#define RQ_CTXT_PI_INTR_SHIFT 22 +#define RQ_CTXT_PI_CEQ_ARM_SHIFT 31 + +#define RQ_CTXT_PI_IDX_MASK 0xFFFU +#define RQ_CTXT_PI_INTR_MASK 0x3FFU +#define RQ_CTXT_PI_CEQ_ARM_MASK 0x1U + +#define RQ_CTXT_PI_SET (val, member) (((val) & \ + RQ_CTXT_PI_##member##_MASK) << \ + RQ_CTXT_PI_##member##_SHIFT) + +#define RQ_CTXT_WQ_PAGE_HI_PFN_SHIFT 0 +#define RQ_CTXT_WQ_PAGE_CI_SHIFT 20 + +#define RQ_CTXT_WQ_PAGE_HI_PFN_MASK 0xFFFFFU +#define RQ_CTXT_WQ_PAGE_CI_MASK 0xFFFU + +#define RQ_CTXT_WQ_PAGE_SET (val, member) (((val) & \ + RQ_CTXT_WQ_PAGE_##member##_MASK) << \ + RQ_CTXT_WQ_PAGE_##member##_SHIFT) + +#define RQ_CTXT_PREF_CACHE_THRESHOLD_SHIFT 0 +#define RQ_CTXT_PREF_CACHE_MAX_SHIFT 14 +#define RQ_CTXT_PREF_CACHE_MIN_SHIFT 25 + +#define RQ_CTXT_PREF_CACHE_THRESHOLD_MASK 0x3FFFU +#define RQ_CTXT_PREF_CACHE_MAX_MASK 0x7FFU +#define RQ_CTXT_PREF_CACHE_MIN_MASK 0x7FU + +#define RQ_CTXT_PREF_WQ_PFN_HI_SHIFT 0 +#define RQ_CTXT_PREF_CI_SHIFT 20 + +#define RQ_CTXT_PREF_WQ_PFN_HI_MASK 0xFFFFFU +#define RQ_CTXT_PREF_CI_MASK 0xFFFU + +#define RQ_CTXT_PREF_SET (val, member) (((val) & \ + RQ_CTXT_PREF_##member##_MASK) << \ + RQ_CTXT_PREF_##member##_SHIFT) + +#define RQ_CTXT_WQ_BLOCK_PFN_HI_SHIFT 0 + +#define RQ_CTXT_WQ_BLOCK_PFN_HI_MASK 0x7FFFFFU + +#define RQ_CTXT_WQ_BLOCK_SET (val, member) (((val) & \ + RQ_CTXT_WQ_BLOCK_##member##_MASK) << \ + RQ_CTXT_WQ_BLOCK_##member##_SHIFT) + +#define SIZE_16BYTES (size) (ALIGN((size), 16) >> 4) + +#define WQ_PAGE_PFN_SHIFT 12 +#define WQ_BLOCK_PFN_SHIFT 9 + +#define WQ_PAGE_PFN (page_addr) ((page_addr) >> WQ_PAGE_PFN_SHIFT) +#define WQ_BLOCK_PFN (page_addr) ((page_addr) >> WQ_BLOCK_PFN_SHIFT) + +enum sq_cflag { +CFLAG_DATA_PATH =0 , +}; + +enum hinic_qp_ctxt_type { +HINIC_QP_CTXT_TYPE_SQ , +HINIC_QP_CTXT_TYPE_RQ , +}; + +/* service type related define */ +enum cfg_svc_type_en { +CFG_SVC_NIC_BIT0 = (1 <<0 ), +}; + +#define IS_NIC_TYPE (dev) \ + ((dev)->cfg_mgmt->svc_cap.chip_svc_type & CFG_SVC_NIC_BIT0) + +#endif /* _HINIC_CTX_DEF_H_ */
drivers/net/hinic/base/hinic_pmd_dpdev.h new file +146 -0
146 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_eqs.c new file +725 -0
725 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_eqs.h new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v4 6/11 net/hinic/base: add code for nic business
In reply to Ziyang XuanAdd code for nic business, including qps structures, qps configuration, wqs configuration for qps, nic business configuration functionalities.
--- drivers/net/hinic/base/hinic_pmd_nic.h | 85 ++ drivers/net/hinic/base/hinic_pmd_niccfg.c | 1376 +++++++++++++++++++++ drivers/net/hinic/base/hinic_pmd_niccfg.h | 333 +++++ drivers/net/hinic/base/hinic_pmd_nicio.c | 919 ++++++++++++++ drivers/net/hinic/base/hinic_pmd_nicio.h | 53 + drivers/net/hinic/base/hinic_pmd_qp.c | 26 + drivers/net/hinic/base/hinic_pmd_qp.h | 76 ++ drivers/net/hinic/base/hinic_pmd_wq.c | 164 +++ drivers/net/hinic/base/hinic_pmd_wq.h | 52 + 9 files changed, 3084 insertions(+) create mode 100644 drivers/net/hinic/base/hinic_pmd_nic.h create mode 100644 drivers/net/hinic/base/hinic_pmd_niccfg.c create mode 100644 drivers/net/hinic/base/hinic_pmd_niccfg.h create mode 100644 drivers/net/hinic/base/hinic_pmd_nicio.c create mode 100644 drivers/net/hinic/base/hinic_pmd_nicio.h create mode 100644 drivers/net/hinic/base/hinic_pmd_qp.c create mode 100644 drivers/net/hinic/base/hinic_pmd_qp.h create mode 100644 drivers/net/hinic/base/hinic_pmd_wq.c create mode 100644 drivers/net/hinic/base/hinic_pmd_wq.h
drivers/net/hinic/base/hinic_pmd_nic.h new file +85 -0
@@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#ifndef _HINIC_PMD_NIC_H_ +#define _HINIC_PMD_NIC_H_ + +#define HINIC_FLUSH_QUEUE_TIMEOUT 3000 + +struct hinic_hwdev ; +struct hinic_wq ; + +struct hinic_sq { +struct hinic_wq *wq; +volatile u16 *cons_idx_addr; +void __iomem *db_addr; + +u16 q_id; +u16 owner; +u16 sq_depth; +}; + +struct hinic_rq { +struct hinic_wq *wq; +volatile u16 *pi_virt_addr; +dma_addr_t pi_dma_addr; + +u16 irq_id; +u16 msix_entry_idx; +u16 q_id; +u16 rq_depth; +}; + +struct hinic_qp { +struct hinic_sq sq; +struct hinic_rq rq; +}; + +struct vf_data_storage { +u8 vf_mac_addr[ETH_ALEN ]; +bool registered; +bool pf_set_mac; +u16 pf_vlan; +u8 pf_qos; + +bool link_forced; +bool link_up;/* only valid if VF link is forced */ +}; + +struct hinic_nic_io { +struct hinic_hwdev *hwdev; + +u16 global_qpn; +u8 link_status; + +struct hinic_wq *sq_wq; +struct hinic_wq *rq_wq; + +u16 max_qps; +u16 num_qps; + +u16 num_sqs; +u16 num_rqs; + +u16 sq_depth; +u16 rq_depth; + +u16 rq_buf_size; +u16 vhd_mode; + +struct hinic_qp *qps; +/* sq ci mem base addr of the function*/ +void *ci_vaddr_base; +dma_addr_t ci_dma_base; + +struct hinic_event event; +void *event_handle; + +u16 max_vfs; +u16 num_vfs; +u8 vf_link_mode; +struct vf_data_storage *vf_infos; +}; + +#endif /* _HINIC_PMD_NIC_H_ */
drivers/net/hinic/base/hinic_pmd_niccfg.c new file +1376 -0
1,376 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_niccfg.h new file +333 -0
333 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_nicio.c new file +919 -0
919 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_nicio.h new file +53 -0
53 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_qp.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#include "hinic_pmd_dpdev.h" + +void hinic_prepare_rq_wqe(void *wqe, __rte_unused u16 pi, dma_addr_t buf_addr, +dma_addr_t cqe_dma) +{ +struct hinic_rq_wqe *rq_wqe = (struct hinic_rq_wqe *)wqe; +struct hinic_rq_ctrl *ctrl = &rq_wqe->ctrl; +struct hinic_rq_cqe_sect *cqe_sect = &rq_wqe->cqe_sect; +struct hinic_rq_bufdesc *buf_desc = &rq_wqe->buf_desc; +u32 rq_ceq_len =sizeof (struct hinic_rq_cqe ); + + ctrl->ctrl_fmt = +RQ_CTRL_SET (SIZE_8BYTES (sizeof (*ctrl)),LEN ) | +RQ_CTRL_SET (SIZE_8BYTES (sizeof (*cqe_sect)),COMPLETE_LEN ) | +RQ_CTRL_SET (SIZE_8BYTES (sizeof (*buf_desc)),BUFDESC_SECT_LEN ) | +RQ_CTRL_SET (RQ_COMPLETE_SGE ,COMPLETE_FORMAT ); + +hinic_set_sge (&cqe_sect->sge, cqe_dma, rq_ceq_len); + + buf_desc->addr_high =upper_32_bits (buf_addr); + buf_desc->addr_low =lower_32_bits (buf_addr); +}
drivers/net/hinic/base/hinic_pmd_qp.h new file +76 -0
76 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_wq.c new file +164 -0
132 lines not on this page · raw message
drivers/net/hinic/base/hinic_pmd_wq.h new file +52 -0
52 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.18.0
Part of the diff is not shown here. View the raw message.
PATCH v4 7/11 net/hinic/base: add various headers
In reply to Ziyang XuanAdd various headers that define mgmt commands, cmdq commands, rx data structures, tx data structures and basic defines for use in the code.
--- drivers/net/hinic/base/hinic_compat.h | 239 ++++++++++++ drivers/net/hinic/base/hinic_port_cmd.h | 483 ++++++++++++++++++++++++ drivers/net/hinic/base/hinic_qe_def.h | 450 ++++++++++++++++++++++ drivers/net/hinic/hinic_pmd_ethdev.h | 102 +++++ drivers/net/hinic/hinic_pmd_rx.h | 135 +++++++ drivers/net/hinic/hinic_pmd_tx.h | 97 +++++ 6 files changed, 1506 insertions(+) create mode 100644 drivers/net/hinic/base/hinic_compat.h create mode 100644 drivers/net/hinic/base/hinic_port_cmd.h create mode 100644 drivers/net/hinic/base/hinic_qe_def.h create mode 100644 drivers/net/hinic/hinic_pmd_ethdev.h create mode 100644 drivers/net/hinic/hinic_pmd_rx.h create mode 100644 drivers/net/hinic/hinic_pmd_tx.h
drivers/net/hinic/base/hinic_compat.h new file +239 -0
@@ -0,0 +1,239 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#ifndef _HINIC_COMPAT_H_ +#define _HINIC_COMPAT_H_ + +#include <stdint.h> +#include <sys/time.h> +#include <rte_common.h> +#include <rte_byteorder.h> +#include <rte_memzone.h> +#include <rte_memcpy.h> +#include <rte_malloc.h> +#include <rte_atomic.h> +#include <rte_spinlock.h> +#include <rte_cycles.h> +#include <rte_log.h> +#include <rte_config.h> + +typedef uint8_t u8 ; +typedef int8_t s8 ; +typedef uint16_t u16 ; +typedef uint32_t u32 ; +typedef int32_t s32 ; +typedef uint64_t u64 ; + +#ifndef dma_addr_t +typedef uint64_t dma_addr_t ; +#endif + +#ifndef gfp_t +#define gfp_t unsigned +#endif + +#ifndef bool +#define bool int +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + +#ifndef TRUE +#define TRUE (1) +#endif + +#ifndef false +#define false (0) +#endif + +#ifndef true +#define true (1) +#endif + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define HINIC_ERROR (-1) +#define HINIC_OK (0) + +#ifndef BIT +#define BIT (n) (1 << (n)) +#endif + +#define upper_32_bits (n) ((u32)(((n) >> 16) >> 16)) +#define lower_32_bits (n) ((u32)(n)) + +/* Returns X / Y, rounding up. X must be nonnegative to round correctly. */ +#define DIV_ROUND_UP (X ,Y ) (((X) + ((Y) - 1)) / (Y)) + +/* Returns X rounded up to the nearest multiple of Y. */ +#define ROUND_UP (X ,Y ) (DIV_ROUND_UP(X, Y) * (Y)) + +#undef ALIGN +#define ALIGN (x, a) RTE_ALIGN(x, a) + +#define PTR_ALIGN (p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) + +/* Reported driver name. */ +#define HINIC_DRIVER_NAME "net_hinic" + +extern int hinic_logtype; + +#define PMD_DRV_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, hinic_logtype, \ + HINIC_DRIVER_NAME": " fmt "\n", ##args) + +#define HINIC_ASSERT_EN + +#ifdef HINIC_ASSERT_EN +#define HINIC_ASSERT (exp) \ + do { \ + if (!(exp)) { \ + rte_panic("line%d\tassert \"" #exp "\" failed\n", \ + __LINE__); \ + } \ + } while (0) +#else +#define HINIC_ASSERT (exp) do {} while (0) +#endif + +#define HINIC_BUG_ON (x) HINIC_ASSERT(!(x)) + +/* common definition */ +#ifndef ETH_ALEN +#define ETH_ALEN 6 +#endif +#define ETH_HLEN 14 +#define ETH_CRC_LEN 4 +#define VLAN_PRIO_SHIFT 13 +#define VLAN_N_VID 4096 + +/* bit order interface */ +#define cpu_to_be16 (o) rte_cpu_to_be_16(o) +#define cpu_to_be32 (o) rte_cpu_to_be_32(o) +#define cpu_to_be64 (o) rte_cpu_to_be_64(o) +#define cpu_to_le32 (o) rte_cpu_to_le_32(o) +#define be16_to_cpu (o) rte_be_to_cpu_16(o) +#define be32_to_cpu (o) rte_be_to_cpu_32(o) +#define be64_to_cpu (o) rte_be_to_cpu_64(o) +#define le32_to_cpu (o) rte_le_to_cpu_32(o) + +/* virt memory and dma phy memory */ +#define __iomem +#define __force +#define GFP_KERNEL RTE_MEMZONE_IOVA_CONTIG +#define HINIC_PAGE_SHIFT 12 +#define HINIC_PAGE_SIZE RTE_PGSIZE_4K +#define HINIC_MEM_ALLOC_ALIGNE_MIN 8 + +static inline int hinic_test_bit (int nr,volatile unsigned long *addr) +{ +int res; + +rte_mb (); + res = ((*addr) & (1UL << nr)) !=0 ; +rte_mb (); +return res; +} + +static inline void hinic_set_bit (unsigned int nr,volatile unsigned long *addr) +{ +__sync_fetch_and_or (addr, (1UL << nr)); +} + +static inline void hinic_clear_bit (int nr,volatile unsigned long *addr) +{ +__sync_fetch_and_and (addr, ~(1UL << nr)); +} + +static inline int hinic_test_and_clear_bit (int nr,volatile unsigned long *addr) +{ +unsigned long mask = (1UL << nr); + +return __sync_fetch_and_and (addr, ~mask) & mask; +} + +static inline int hinic_test_and_set_bit (int nr,volatile unsigned long *addr) +{ +unsigned long mask = (1UL << nr); + +return __sync_fetch_and_or (addr, mask) & mask; +} + +void *dma_zalloc_coherent (void *dev,size_t size,dma_addr_t *dma_handle, +gfp_t flag); +void *dma_zalloc_coherent_aligned (void *dev,size_t size, +dma_addr_t *dma_handle,gfp_t flag); +void *dma_zalloc_coherent_aligned256k (void *dev,size_t size, +dma_addr_t *dma_handle,gfp_t flag); +void dma_free_coherent (void *dev,size_t size,void *virt,dma_addr_t phys); + +/* dma pool alloc and free */ +#define pci_pool dma_pool +#define pci_pool_alloc (pool, flags, handle) dma_pool_alloc(pool, flags, handle) +#define pci_pool_free (pool, vaddr, addr) dma_pool_free(pool, vaddr, addr) + +struct dma_pool *dma_pool_create (const char *name,void *dev,size_t size, +size_t align,size_t boundary); +void dma_pool_destroy (struct dma_pool *pool); +void *dma_pool_alloc (struct pci_pool *pool,int flags,dma_addr_t *dma_addr); +void dma_pool_free (struct pci_pool *pool,void *vaddr,dma_addr_t dma); + +#define kzalloc (size, flag) rte_zmalloc(NULL, size, HINIC_MEM_ALLOC_ALIGNE_MIN) +#define kzalloc_aligned (size, flag) rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE) +#define kfree (ptr) rte_free(ptr) + +/* mmio interface */ +static inline void writel (u32 value,volatile void *addr) +{ + *(volatile u32 *)addr = value; +} + +static inline u32 readl (const volatile void *addr) +{ +return *(const volatile u32 *)addr; +} + +#define __raw_writel (value, reg) writel((value), (reg)) +#define __raw_readl (reg) readl((reg)) + +/* Spinlock related interface */ +#define hinic_spinlock_t rte_spinlock_t + +#define spinlock_t rte_spinlock_t +#define spin_lock_init (spinlock_prt) rte_spinlock_init(spinlock_prt) +#define spin_lock_deinit (lock) +#define spin_lock (spinlock_prt) rte_spinlock_lock(spinlock_prt) +#define spin_unlock (spinlock_prt) rte_spinlock_unlock(spinlock_prt) + +static inline unsigned long get_timeofday_ms (void ) +{ +struct timeval tv; + + (void )gettimeofday (&tv,NULL ); + +return (unsigned long )tv.tv_sec *1000 + tv.tv_usec /1000 ; +} + +#define jiffies get_timeofday_ms() +#define msecs_to_jiffies (ms) (ms) +#define time_before (now, end) ((now) < (end)) + +/* misc kernel utils */ +static inline u16 ilog2 (u32 n) +{ +u16 res =0 ; + +while (n >1 ) { + n >>=1 ; + res++; + } + +return res; +} + +#endif /* _HINIC_COMPAT_H_ */
drivers/net/hinic/base/hinic_port_cmd.h new file +483 -0
483 lines not on this page · raw message
drivers/net/hinic/base/hinic_qe_def.h new file +450 -0
450 lines not on this page · raw message
drivers/net/hinic/hinic_pmd_ethdev.h new file +102 -0
102 lines not on this page · raw message
drivers/net/hinic/hinic_pmd_rx.h new file +135 -0
135 lines not on this page · raw message
drivers/net/hinic/hinic_pmd_tx.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.18.0
Re: [dpdk-dev] [PATCH v4 07/11] net/hinic/base: add various headers
Quoted 5 lines · Ziyang Xuan
Add various headers that define mgmt commands, cmdq commands, rx data structures, tx data structures and basic defines for use in the code.
Signed-off-by Ziyang Xuan <[email protected]>
<...>
Quoted 7 lines
drivers/net/hinic/base/hinic_compat.h new file +7
-0+#define PMD_DRV_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, hinic_logtype, \ + HINIC_DRIVER_NAME": " fmt "\n", ##args) + +#define HINIC_ASSERT_EN + +#ifdef HINIC_ASSERT_EN
drivers/net/hinic/base/hinic_compat.h line 102
Quoted 10 lines
drivers/net/hinic/base/hinic_compat.h new file +10
-0+#define HINIC_ASSERT (exp) \ + do { \ + if (!(exp)) { \ + rte_panic("line%d\tassert \"" #exp "\" failed\n", \ + __LINE__); \ + } \ + } while (0) +#else +#define HINIC_ASSERT (exp) do {} while (0) +#endif
So you are enabling asserting by default? Which can cause "rte_panic()" ?
Please make sure asserting is disabled by default, and please tie this to the "CONFIG_RTE_ENABLE_ASSERT" config option. So it that option is disabled hinic also should disable the assertions.
PATCH v4 8/11 net/hinic: add hinic PMD build and doc files
In reply to Ziyang XuanAdd build and doc files, and common code files.
--- MAINTAINERS | 9 + config/common_base | 5 + config/common_linux | 5 + config/defconfig_arm-armv7a-linuxapp-gcc | 1 + config/defconfig_i686-native-linuxapp-gcc | 5 + config/defconfig_i686-native-linuxapp-icc | 5 + config/defconfig_ppc_64-power8-linuxapp-gcc | 1 + config/defconfig_x86_64-native-linuxapp-icc | 5 + config/defconfig_x86_x32-native-linuxapp-gcc | 5 + doc/guides/nics/features/hinic.ini | 37 + doc/guides/nics/hinic.rst | 55 ++ drivers/net/Makefile | 1 + drivers/net/hinic/Makefile | 73 ++ drivers/net/hinic/base/meson.build | 50 ++ drivers/net/hinic/hinic_pmd_dpdev.c | 702 +++++++++++++++++++ drivers/net/hinic/hinic_pmd_ethdev.c | 25 + drivers/net/hinic/meson.build | 18 + mk/rte.app.mk | 1 + 18 files changed, 1003 insertions(+) create mode 100644 doc/guides/nics/features/hinic.ini create mode 100644 doc/guides/nics/hinic.rst create mode 100644 drivers/net/hinic/Makefile create mode 100644 drivers/net/hinic/base/meson.build create mode 100644 drivers/net/hinic/hinic_pmd_dpdev.c create mode 100644 drivers/net/hinic/hinic_pmd_ethdev.c create mode 100644 drivers/net/hinic/meson.build
MAINTAINERS +9 -0
@@ -577,6 +577,15 @@ F: drivers/net/enic/ F: doc/guides/nics/enic.rst F: doc/guides/nics/features/enic.ini +Huawei hinic +M: Xiaoyun Wang <[email protected]> +M: Ziyang Xuan <[email protected]> +M: Guoyang Zhou <[email protected]> +M: Shahar Belkar <[email protected]> +F: drivers/net/hinic/ +F: doc/guides/nics/hinic.rst +F: doc/guides/nics/features/hinic.ini + Intel e1000 M: Wenzhuo Lu <[email protected]> T: git://dpdk.org/next/dpdk-next-net-intel
config/common_base +5 -0
@@ -276,6 +276,11 @@ CONFIG_RTE_LIBRTE_E1000_DEBUG_TX=n CONFIG_RTE_LIBRTE_E1000_DEBUG_TX_FREE=n CONFIG_RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC=n +# +# Compile burst-oriented HINIC PMD driver +# +CONFIG_RTE_LIBRTE_HINIC_PMD=n + # # Compile burst-oriented IXGBE PMD driver #
config/common_linux +5 -0
@@ -57,3 +57,8 @@ CONFIG_RTE_LIBRTE_PMD_DPAA2_QDMA_RAWDEV=y # NXP ENETC PMD Driver # CONFIG_RTE_LIBRTE_ENETC_PMD=y + +# +# HINIC PMD driver +# +CONFIG_RTE_LIBRTE_HINIC_PMD=y
config/defconfig_arm-armv7a-linuxapp-gcc +1 -0
@@ -54,3 +54,4 @@ CONFIG_RTE_LIBRTE_QEDE_PMD=n CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n CONFIG_RTE_LIBRTE_AVP_PMD=n CONFIG_RTE_LIBRTE_NFP_PMD=n +CONFIG_RTE_LIBRTE_HINIC_PMD=n
config/defconfig_i686-native-linuxapp-gcc +5 -0
@@ -54,3 +54,8 @@ CONFIG_RTE_LIBRTE_NFP_PMD=n # 32-bit doesn't break up memory in lists, but does have VA allocation limit CONFIG_RTE_MAX_MEM_MB=2048 + +# +# HINIC PMD is not supported on 32-bit +# +CONFIG_RTE_LIBRTE_HINIC_PMD=n
config/defconfig_i686-native-linuxapp-icc +5 -0
@@ -54,3 +54,8 @@ CONFIG_RTE_LIBRTE_NFP_PMD=n # 32-bit doesn't break up memory in lists, but does have VA allocation limit CONFIG_RTE_MAX_MEM_MB=2048 + +# +# HINIC PMD is not supported on 32-bit +# +CONFIG_RTE_LIBRTE_HINIC_PMD=n
config/defconfig_ppc_64-power8-linuxapp-gcc +1 -0
@@ -56,3 +56,4 @@ CONFIG_RTE_LIBRTE_ENIC_PMD=n CONFIG_RTE_LIBRTE_FM10K_PMD=n CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n CONFIG_RTE_LIBRTE_AVP_PMD=n +CONFIG_RTE_LIBRTE_HINIC_PMD=n
config/defconfig_x86_64-native-linuxapp-icc +5 -0
@@ -17,3 +17,8 @@ CONFIG_RTE_TOOLCHAIN_ICC=y # Solarflare PMD build is not supported using icc toolchain # CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n + +# +# HINIC PMD build is not supported using icc toolchain +# +CONFIG_RTE_LIBRTE_HINIC_PMD=n
config/defconfig_x86_x32-native-linuxapp-gcc +5 -0
@@ -34,3 +34,8 @@ CONFIG_RTE_LIBRTE_NFP_PMD=n # 32-bit doesn't break up memory in lists, but does have VA allocation limit CONFIG_RTE_MAX_MEM_MB=2048 + +# +# HINIC PMD is not supported on 32-bit +# +CONFIG_RTE_LIBRTE_HINIC_PMD=n
doc/guides/nics/features/hinic.ini new file +37 -0
@@ -0,0 +1,37 @@ +; +; Supported features of the 'hinic' network poll mode driver. +; +; Refer to default.ini for the full list of available PMD features. +; +[Features] +Speed capabilities = Y +Link status = Y +Link status event = Y +Free Tx mbuf on demand = Y +Queue start/stop = Y +Jumbo frame = N +Scattered Rx = Y +TSO = Y +Promiscuous mode = Y +Unicast MAC filter = Y +Multicast MAC filter = Y +RSS hash = Y +RSS key update = Y +RSS reta update = Y +Inner RSS = Y +CRC offload = Y +L3 checksum offload = Y +L4 checksum offload = Y +Inner L3 checksum = Y +Inner L4 checksum = Y +Basic stats = Y +Extended stats = Y +Stats per queue = Y +Linux UIO = Y +Linux VFIO = Y +BSD nic_uio = N +x86-64 = Y +ARMv8 = Y +ARMv7 = N +x86-32 = N +Power8 = N
doc/guides/nics/hinic.rst new file +55 -0
55 lines not on this page · raw message
drivers/net/Makefile +1 -0
@@ -29,6 +29,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_ENETC_PMD) += enetc DIRS-$(CONFIG_RTE_LIBRTE_ENIC_PMD) += enic DIRS-$(CONFIG_RTE_LIBRTE_PMD_FAILSAFE) += failsafe DIRS-$(CONFIG_RTE_LIBRTE_FM10K_PMD) += fm10k +DIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic DIRS-$(CONFIG_RTE_LIBRTE_I40E_PMD) += i40e DIRS-$(CONFIG_RTE_LIBRTE_IAVF_PMD) += iavf DIRS-$(CONFIG_RTE_LIBRTE_ICE_PMD) += ice
drivers/net/hinic/Makefile new file +73 -0
73 lines not on this page · raw message
drivers/net/hinic/base/meson.build new file +50 -0
50 lines not on this page · raw message
drivers/net/hinic/hinic_pmd_dpdev.c new file +702 -0
702 lines not on this page · raw message
drivers/net/hinic/hinic_pmd_ethdev.c new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#include <stdio.h> +#include <rte_pci.h> +#include <rte_bus_pci.h> +#include <rte_ethdev_pci.h> +#include <rte_mbuf.h> +#include <rte_malloc.h> +#include <rte_memcpy.h> +#include <rte_mempool.h> +#include <rte_dev.h> +#include <rte_errno.h> +#include <rte_kvargs.h> + +/** Driver-specific log messages type. */ +int hinic_logtype; + +RTE_INIT (hinic_init_log) +{ + hinic_logtype =rte_log_register ("pmd.net.hinic" ); +if (hinic_logtype >=0 ) +rte_log_set_level (hinic_logtype,RTE_LOG_INFO ); +}
drivers/net/hinic/meson.build new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2017 Huawei Technologies Co., Ltd + +subdir('base') +objs = [base_objs] + +sources = files( + 'hinic_pmd_dpdev.c', + 'hinic_pmd_ethdev.c', +# 'hinic_pmd_rx.c', +# 'hinic_pmd_tx.c' + ) + +deps += 'ethdev' +deps += 'pci' +deps += 'hash' + +includes += include_directories('base')
mk/rte.app.mk +1 -0
@@ -166,6 +166,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_ENETC_PMD) += -lrte_pmd_enetc _LDLIBS-$(CONFIG_RTE_LIBRTE_ENIC_PMD) += -lrte_pmd_enic _LDLIBS-$(CONFIG_RTE_LIBRTE_FM10K_PMD) += -lrte_pmd_fm10k _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_FAILSAFE) += -lrte_pmd_failsafe +_LDLIBS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += -lrte_pmd_hinic _LDLIBS-$(CONFIG_RTE_LIBRTE_I40E_PMD) += -lrte_pmd_i40e _LDLIBS-$(CONFIG_RTE_LIBRTE_IAVF_PMD) += -lrte_pmd_iavf _LDLIBS-$(CONFIG_RTE_LIBRTE_ICE_PMD) += -lrte_pmd_ice
Signature · 1 line
2.18.0
Re: [dpdk-dev] [PATCH v4 08/11] net/hinic: add hinic PMD build and doc files
Quoted 15 lines · Ziyang Xuan
Add build and doc files, and common code files.
Signed-off-by Ziyang Xuan <[email protected]>--- MAINTAINERS | 9 + config/common_base | 5 + config/common_linux | 5 + config/defconfig_arm-armv7a-linuxapp-gcc | 1 + config/defconfig_i686-native-linuxapp-gcc | 5 + config/defconfig_i686-native-linuxapp-icc | 5 + config/defconfig_ppc_64-power8-linuxapp-gcc | 1 + config/defconfig_x86_64-native-linuxapp-icc | 5 + config/defconfig_x86_x32-native-linuxapp-gcc | 5 + doc/guides/nics/features/hinic.ini | 37 + doc/guides/nics/hinic.rst | 55 ++
Can you also update the release notes documentation (doc/guides/rel_notes/release_19_08.rst) to announce new driver?
<...>
doc/guides/nics/hinic.rst line 10
Quoted 11 lines
doc/guides/nics/hinic.rst new file +10
-0@@ -0,0 +1,55 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright(c) 2017 Huawei Technologies Co., Ltd + + +HINIC Poll Mode Driver +====================== + +The hinic PMD (librte_pmd_hinic) provides poll mode driver support for +25 Gbps Huawei Intelligent PCIE Network Adapters based on +the Huawei Ethernet Controller Hi1822.
Can you please provide a link to product documentation?
Quoted 4 lines
doc/guides/nics/hinic.rst new file +4
-0+ + +Features +--------
doc/guides/nics/hinic.rst line 24
Quoted 10 lines
doc/guides/nics/hinic.rst new file +10
-0+ +- Multi arch support: x86_64, ARMv8. +- Multiple queues for TX and RX +- Receiver Side Scaling (RSS) +- MAC/VLAN filtering +- Checksum offload +- TSO offload +- Promiscuous mode +- Port hardware statistics +- Jumbo frames
Jumbo frame marked as not supported in above .ini file?
doc/guides/nics/hinic.rst line 34
Quoted 10 lines
doc/guides/nics/hinic.rst new file +10
-0+- Link state information +- Link flow control +- Scattered and gather for TX and RX + +Prerequisites +------------- + +- Follow the DPDK :ref:`Getting Started Guide for Linux <linux_gsg>` to setup the basic DPDK environment. + +Requires firmware 1.6.2.5
Please provide some link for this prerequisite.
<...>
drivers/net/hinic/Makefile line 34
Quoted 13 lines
drivers/net/hinic/Makefile new file +13
-0+# +# Add extra flags for base driver files (also known as shared code) +# to disable warnings +# +ifeq ($(CONFIG_RTE_TOOLCHAIN_ICC),y) +CFLAGS_BASE_DRIVER = -diag-disable 593 +else +CFLAGS_BASE_DRIVER = -Wno-sign-compare +CFLAGS_BASE_DRIVER += -Wno-unused-parameter +CFLAGS_BASE_DRIVER += -Wno-strict-aliasing +CFLAGS_BASE_DRIVER += -Wno-missing-field-initializers +CFLAGS_BASE_DRIVER += -Wno-pointer-to-int-cast +endif
Since icc is not supported (yet), can drop this part.
drivers/net/hinic/Makefile line 37
Quoted 3 lines
drivers/net/hinic/Makefile new file +3
-0+ +OBJS_BASE_DRIVER=$(sort $(patsubst %.c,%.o,$(notdir $(wildcard $(SRCDIR)/base/*.c)))) +$(foreach obj, $(OBJS_BASE_DRIVER), $(eval CFLAGS_$(obj)+=$(CFLAGS_BASE_DRIVER)))
And when icc part removed, I think nothing is left to set "CFLAGS_BASE_DRIVER", so this part can be removed too.
Quoted 12 lines
drivers/net/hinic/Makefile new file +12
-0+ +VPATH += $(SRCDIR)/base + +# +# all source are stored in SRCS-y +# +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_api_cmd.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_cfg.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_cmdq.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_eqs.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_hwdev.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_hwif.c
drivers/net/hinic/Makefile line 59
Quoted 10 lines
drivers/net/hinic/Makefile new file +10
-0+SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_mgmt.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_niccfg.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_nicio.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_qp.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_wq.c + +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_dpdev.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_ethdev.c +#SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_rx.c +#SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_tx.c
Please remove commented lines.
drivers/net/hinic/Makefile line 67
Quoted 8 lines
drivers/net/hinic/Makefile new file +8
-0+ +# this lib depends upon: +DEPDIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += lib/librte_eal lib/librte_ether +DEPDIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += lib/librte_mempool lib/librte_mbuf +DEPDIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += lib/librte_net lib/librte_hash +DEPDIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += lib/librte_kvargs +DEPDIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += lib/librte_net +DEPDIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += lib/librte_ring
We stop using DEPDIRS, below LDLIBS is replacing it, can drop above lines.
<...>
Quoted 13 lines
drivers/net/hinic/base/meson.build new file +13
-0+headers = [ + 'hinic_compat.h', + 'hinic_csr.h', + 'hinic_ctx_def.h', + 'hinic_pmd_api_cmd.h', + 'hinic_pmd_cfg.h', + 'hinic_pmd_cmdq.h', + 'hinic_pmd_dpdev.h', + 'hinic_pmd_eqs.h', + 'hinic_pmd_hwdev.h', + 'hinic_pmd_hw.h', + 'hinic_pmd_hwif.h', + 'hinic_pmd_hw_mgmt.h',
drivers/net/hinic/base/meson.build line 40
Quoted 10 lines
drivers/net/hinic/base/meson.build new file +10
-0+ 'hinic_pmd_mgmt.h', + 'hinic_pmd_mgmt_interface.h', + 'hinic_pmd_niccfg.h', + 'hinic_pmd_nic.h', + 'hinic_pmd_nicio.h', + 'hinic_pmd_qp.h', + 'hinic_pmd_wq.h', + 'hinic_port_cmd.h', + 'hinic_qe_def.h', +]
Does headers need to be defined for the PMD?
<...>
drivers/net/hinic/hinic_pmd_dpdev.c line 90
Quoted 3 lines
drivers/net/hinic/hinic_pmd_dpdev.c new file +3
-0+ +void *hinic_dma_mem_zalloc (void *dev,size_t size,dma_addr_t *dma_handle, +unsigned int flag,unsigned int align)
Why not many of the functions are not 'static'? Please make them 'static' as much as possible.
<...>
drivers/net/hinic/hinic_pmd_dpdev.c line 516
Quoted 10 lines
drivers/net/hinic/hinic_pmd_dpdev.c new file +10
-0+int32_t hinic_nic_dev_create (struct rte_eth_dev *eth_dev) +{ +struct hinic_nic_dev *nic_dev = +HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +int rc; + + nic_dev->hwdev = + (struct hinic_hwdev *)rte_zmalloc ("hinic_hwdev" , +sizeof (*nic_dev->hwdev), +RTE_CACHE_LINE_SIZE );
There was a patch by Stephen [1] very recently to remove the casting from and to the "void *" which is not required by 'C'.
To not need similar cleanups later, can you please check them at first place.
[1]https://patches.dpdk.org/project/dpdk/list/?series=4816
<...>
drivers/net/hinic/meson.build line 11
Quoted 5 lines
drivers/net/hinic/meson.build new file +5
-0+sources = files( + 'hinic_pmd_dpdev.c', + 'hinic_pmd_ethdev.c', +# 'hinic_pmd_rx.c', +# 'hinic_pmd_tx.c'
Please don't have commented code.
drivers/net/hinic/meson.build line 16
Quoted 5 lines
drivers/net/hinic/meson.build new file +5
-0+ ) + +deps += 'ethdev' +deps += 'pci' +deps += 'hash'
Is hash a dependency?
PATCH v4 9/11 net/hinic: add RX module
In reply to Ziyang XuanAdd code for RX module.
--- drivers/net/hinic/Makefile | 2 +- drivers/net/hinic/hinic_pmd_rx.c | 902 +++++++++++++++++++++++++++++++ drivers/net/hinic/meson.build | 2 +- 3 files changed, 904 insertions(+), 2 deletions(-) create mode 100644 drivers/net/hinic/hinic_pmd_rx.c
drivers/net/hinic/Makefile +1 -1
@@ -55,7 +55,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_wq.c SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_dpdev.c SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_ethdev.c -#SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_rx.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_rx.c #SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_tx.c # this lib depends upon:
drivers/net/hinic/hinic_pmd_rx.c new file +902 -0
902 lines not on this page · raw message
drivers/net/hinic/meson.build +1 -1
@@ -7,7 +7,7 @@ objs = [base_objs] sources = files( 'hinic_pmd_dpdev.c', 'hinic_pmd_ethdev.c', -# 'hinic_pmd_rx.c', + 'hinic_pmd_rx.c', # 'hinic_pmd_tx.c' )
Signature · 1 line
2.18.0
Re: [dpdk-dev] [PATCH v4 09/11] net/hinic: add RX module
Quoted 3 lines · Ziyang Xuan
Add code for RX module.
Signed-off-by Ziyang Xuan <[email protected]>
<...>
Quoted 6 lines
drivers/net/hinic/hinic_pmd_rx.c new file +5
-0@@ -0,0 +1,902 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd +*/ + +#include <rte_ether.h>
drivers/net/hinic/hinic_pmd_rx.c line 15
Quoted 10 lines
drivers/net/hinic/hinic_pmd_rx.c new file +10
-0+#include <rte_ethdev.h> +#include <rte_mbuf.h> +#ifdef __ARM64_NEON__ +#include <arm_neon.h> +#endif + +#include "hinic_pmd_ethdev.h" +#include "hinic_pmd_rx.h" + +#ifdef HINIC_XSTAT_RXBUF_INFO
Where this define is defined? I think it is not coming from Makefile.
<...>
drivers/net/hinic/hinic_pmd_rx.c line 55
Quoted 7 lines
drivers/net/hinic/hinic_pmd_rx.c new file +7
-0+#ifdef HINIC_XSTAT_RXBUF_INFO + rxq->rxq_stats.rx_mbuf = (rxq->q_depth) + -HINIC_GET_RQ_FREE_WQEBBS (rxq); + +hinic_rxq_buffer_done_count (rxq); +#endif +#ifdef HINIC_XSTAT_MBUF_USE
Similar to this one, there are ifdefs in the code not defined, creating dead code. Please don't have any compile time option that can't be modified from config file.
[dpdk-dev] 答复: [PATCH v4 09/11] net/hinic: add RX module
Quoted 26 lines · Ziyang Xuan
Quoted 3 lines
Add code for RX module.
Signed-off-by Ziyang Xuan <[email protected]><...>
Quoted 5 lines
drivers/net/hinic/hinic_pmd_rx.c new file +4
-0@@ -0,0 +1,902 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017 Huawei Technologies Co., Ltd */ + +#include <rte_ether.h> drivers/net/hinic/hinic_pmd_rx.c line 14
Quoted 10 lines
drivers/net/hinic/hinic_pmd_rx.c new file +10
-0+#include <rte_ethdev.h> +#include <rte_mbuf.h> +#ifdef __ARM64_NEON__ +#include <arm_neon.h> +#endif + +#include "hinic_pmd_ethdev.h" +#include "hinic_pmd_rx.h" + +#ifdef HINIC_XSTAT_RXBUF_INFO Where this define is defined? I think it is not coming from
Makefile.<...>
Quoted 12 lines
drivers/net/hinic/hinic_pmd_rx.c line 55
Quoted 7 lines
drivers/net/hinic/hinic_pmd_rx.c new file +7
-0+#ifdef HINIC_XSTAT_RXBUF_INFO + rxq->rxq_stats.rx_mbuf = (rxq->q_depth) + -HINIC_GET_RQ_FREE_WQEBBS (rxq); + +hinic_rxq_buffer_done_count (rxq); +#endif +#ifdef HINIC_XSTAT_MBUF_USE Similar to this one, there are ifdefs in the code not defined, creating dead code.
Please don't have any compile time option that can't be modified from config file.
These compilation option was for debug when we tested, and I will delete them.
PATCH v4 10/11 net/hinic: add TX module
In reply to Ziyang XuanAdd code for TX module
--- drivers/net/hinic/Makefile | 2 +- drivers/net/hinic/hinic_pmd_tx.c | 1070 ++++++++++++++++++++++++++++++ drivers/net/hinic/meson.build | 2 +- 3 files changed, 1072 insertions(+), 2 deletions(-) create mode 100644 drivers/net/hinic/hinic_pmd_tx.c
drivers/net/hinic/Makefile +1 -1
@@ -56,7 +56,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_wq.c SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_dpdev.c SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_ethdev.c SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_rx.c -#SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_tx.c +SRCS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += hinic_pmd_tx.c # this lib depends upon: DEPDIRS-$(CONFIG_RTE_LIBRTE_HINIC_PMD) += lib/librte_eal lib/librte_ether
drivers/net/hinic/hinic_pmd_tx.c new file +1070 -0
1,070 lines not on this page · raw message
drivers/net/hinic/meson.build +1 -1
@@ -8,7 +8,7 @@ sources = files( 'hinic_pmd_dpdev.c', 'hinic_pmd_ethdev.c', 'hinic_pmd_rx.c', -# 'hinic_pmd_tx.c' + 'hinic_pmd_tx.c' ) deps += 'ethdev'
Signature · 1 line
2.18.0
PATCH v4 11/11 net/hinic: add support for basic device operations
In reply to Ziyang XuanAdd hinic PMD initialization and ethernet operatioins code.
--- drivers/net/hinic/hinic_pmd_ethdev.c | 2125 +++++++++++++++++++ drivers/net/hinic/rte_pmd_hinic_version.map | 4 + 2 files changed, 2129 insertions(+) create mode 100644 drivers/net/hinic/rte_pmd_hinic_version.map
drivers/net/hinic/hinic_pmd_ethdev.c +2125 -0
@@ -14,9 +14,2134 @@#include <rte_errno.h> #include <rte_kvargs.h> +#include "hinic_pmd_ethdev.h" +#include "hinic_pmd_tx.h" +#include "hinic_pmd_rx.h" + +#define HINIC_MIN_RX_BUF_SIZE 1024 + +#define HINIC_MAX_MAC_ADDRS 1 +#define EQ_MSIX_RESEND_TIMER_CLEAR 1 + +/* Hinic PMD parameters */ +#define ETH_HINIC_FW_VER "check_fw_version" + +static const char *const valid_params[] = { +ETH_HINIC_FW_VER , +NULL }; + +/** Driver-specific log messages type. */ int hinic_logtype; +static int check_fw_ver =1 ; + +static int hinic_dev_init (struct rte_eth_dev *eth_dev); +static int hinic_dev_uninit (struct rte_eth_dev *dev); +static int hinic_init_mac_addr (struct rte_eth_dev *eth_dev); +static void hinic_deinit_mac_addr (struct rte_eth_dev *eth_dev); +static int hinic_rx_queue_setup (struct rte_eth_dev *dev,uint16_t queue_idx, +uint16_t nb_desc,unsigned int socket_id, + __rte_unused const struct rte_eth_rxconf *rx_conf, +struct rte_mempool *mp); +static int hinic_tx_queue_setup (struct rte_eth_dev *dev,uint16_t queue_idx, +uint16_t nb_desc,unsigned int socket_id, + __rte_unused const struct rte_eth_txconf *tx_conf); + +static const struct eth_dev_ops hinic_pmd_ops = { + .dev_configure = hinic_dev_configure, + .dev_infos_get = hinic_dev_infos_get, + .rx_queue_setup = hinic_rx_queue_setup, + .tx_queue_setup = hinic_tx_queue_setup, + .dev_start = hinic_dev_start, + .link_update = hinic_link_update, + .rx_queue_release = hinic_rx_queue_release, + .tx_queue_release = hinic_tx_queue_release, + .dev_stop = hinic_dev_stop, + .dev_close = hinic_dev_close, + .promiscuous_enable = hinic_dev_promiscuous_enable, + .promiscuous_disable = hinic_dev_promiscuous_disable, + .rss_hash_update = hinic_rss_hash_update, + .rss_hash_conf_get = hinic_rss_conf_get, + .reta_update = hinic_rss_indirtbl_update, + .reta_query = hinic_rss_indirtbl_query, + .stats_get = hinic_dev_stats_get, + .stats_reset = hinic_dev_stats_reset, + .xstats_get = hinic_dev_xstats_get, + .xstats_reset = hinic_dev_xstats_reset, + .xstats_get_names = hinic_dev_xstats_get_names, + .fw_version_get = hinic_fw_version_get, +}; + +static int hinic_check_fw_ver_param(__rte_unused const char *key, +const char *value, + __rte_unused void *opaque) +{ +int num =-1 ; +char *end =NULL ; + +while (isblank (*value)) + value++; + + num =strtoul (value, &end,10 ); +if ((*end =='-' ) || errno) +return -1 ; + check_fw_ver = num; + +return 0 ; +} + +static int +hinic_pci_verify_fw_ver (struct rte_eth_dev *eth_dev, +struct rte_devargs *devargs) +{ +struct rte_kvargs *kvlist; +const char *hinic_fw_ver_arg =ETH_HINIC_FW_VER ; +int ret =HINIC_OK ; +char ver_str[64 ] = {0 }; + +if (hinic_fw_version_get (eth_dev, ver_str,64 ) !=HINIC_OK ) +PMD_DRV_LOG (ERR ,"Failed to get FW version" ); + +PMD_DRV_LOG (INFO ,"FW version = %s\n" , ver_str); + +if (!devargs) +return ret; + + kvlist =rte_kvargs_parse (devargs->args, valid_params); +if (kvlist ==NULL ) +return ret; + +if (!rte_kvargs_count (kvlist, hinic_fw_ver_arg)) { +rte_kvargs_free (kvlist); +return ret; + } + +if (!rte_kvargs_process (kvlist, hinic_fw_ver_arg, + hinic_check_fw_ver_param,NULL ) && check_fw_ver >0 ) { +/* TODO: Verify version compatibility +* and update ret accordingly +*/ + } +rte_kvargs_free (kvlist); + +return ret; +} + +RTE_PMD_REGISTER_PARAM_STRING (net_hinic, +ETH_HINIC_FW_VER "=<int>" ); + +static struct rte_pci_id pci_id_hinic_map[] = { + {RTE_PCI_DEVICE (HINIC_HUAWEI_VENDOR_ID ,HINIC_DEV_ID_PRD ) }, + {RTE_PCI_DEVICE (HINIC_HUAWEI_VENDOR_ID ,HINIC_DEV_ID_MEZZ_25GE ) }, + {RTE_PCI_DEVICE (HINIC_HUAWEI_VENDOR_ID ,HINIC_DEV_ID_MEZZ_40GE ) }, + {RTE_PCI_DEVICE (HINIC_HUAWEI_VENDOR_ID ,HINIC_DEV_ID_MEZZ_100GE ) }, + {.vendor_id =0 }, +}; + +static int hinic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, +struct rte_pci_device *pci_dev) +{ +return rte_eth_dev_pci_generic_probe (pci_dev, +sizeof (struct hinic_nic_dev ), hinic_dev_init); +} + +static int hinic_pci_remove (struct rte_pci_device *pci_dev) +{ +return rte_eth_dev_pci_generic_remove (pci_dev, hinic_dev_uninit); +} + +static struct rte_pci_driver rte_hinic_pmd = { + .id_table = pci_id_hinic_map, + .drv_flags =RTE_PCI_DRV_NEED_MAPPING |RTE_PCI_DRV_INTR_LSC , + .probe = hinic_pci_probe, + .remove = hinic_pci_remove, +}; + +RTE_PMD_REGISTER_PCI (net_hinic, rte_hinic_pmd); +RTE_PMD_REGISTER_PCI_TABLE (net_hinic, pci_id_hinic_map); + +struct hinic_xstats_name_off { +char name[RTE_ETH_XSTATS_NAME_SIZE ]; +u32 offset; +}; + +#define HINIC_FUNC_STAT (_stat_item) { \ + .name = #_stat_item, \ + .offset = offsetof(struct hinic_vport_stats, _stat_item) \ +} + +static const struct hinic_xstats_name_off hinic_vport_stats_strings[] = { +HINIC_FUNC_STAT (tx_unicast_pkts_vport), +HINIC_FUNC_STAT (tx_unicast_bytes_vport), +HINIC_FUNC_STAT (tx_multicast_pkts_vport), +HINIC_FUNC_STAT (tx_multicast_bytes_vport), +HINIC_FUNC_STAT (tx_broadcast_pkts_vport), +HINIC_FUNC_STAT (tx_broadcast_bytes_vport), + +HINIC_FUNC_STAT (rx_unicast_pkts_vport), +HINIC_FUNC_STAT (rx_unicast_bytes_vport), +HINIC_FUNC_STAT (rx_multicast_pkts_vport), +HINIC_FUNC_STAT (rx_multicast_bytes_vport), +HINIC_FUNC_STAT (rx_broadcast_pkts_vport), +HINIC_FUNC_STAT (rx_broadcast_bytes_vport), + +HINIC_FUNC_STAT (tx_discard_vport), +HINIC_FUNC_STAT (rx_discard_vport), +HINIC_FUNC_STAT (tx_err_vport), +HINIC_FUNC_STAT (rx_err_vport), +}; + +#define HINIC_VPORT_XSTATS_NUM (sizeof(hinic_vport_stats_strings) / \ + sizeof(hinic_vport_stats_strings[0])) + +#define HINIC_PORT_STAT (_stat_item) { \ + .name = #_stat_item, \ + .offset = offsetof(struct hinic_phy_port_stats, _stat_item) \ +} + +static const struct hinic_xstats_name_off hinic_phyport_stats_strings[] = { +HINIC_PORT_STAT (mac_rx_total_pkt_num), +HINIC_PORT_STAT (mac_rx_total_oct_num), +HINIC_PORT_STAT (mac_rx_bad_pkt_num), +HINIC_PORT_STAT (mac_rx_bad_oct_num), +HINIC_PORT_STAT (mac_rx_good_pkt_num), +HINIC_PORT_STAT (mac_rx_good_oct_num), +HINIC_PORT_STAT (mac_rx_uni_pkt_num), +HINIC_PORT_STAT (mac_rx_multi_pkt_num), +HINIC_PORT_STAT (mac_rx_broad_pkt_num), +HINIC_PORT_STAT (mac_tx_total_pkt_num), +HINIC_PORT_STAT (mac_tx_total_oct_num), +HINIC_PORT_STAT (mac_tx_bad_pkt_num), +HINIC_PORT_STAT (mac_tx_bad_oct_num), +HINIC_PORT_STAT (mac_tx_good_pkt_num), +HINIC_PORT_STAT (mac_tx_good_oct_num), +HINIC_PORT_STAT (mac_tx_uni_pkt_num), +HINIC_PORT_STAT (mac_tx_multi_pkt_num), +HINIC_PORT_STAT (mac_tx_broad_pkt_num), +HINIC_PORT_STAT (mac_rx_fragment_pkt_num), +HINIC_PORT_STAT (mac_rx_undersize_pkt_num), +HINIC_PORT_STAT (mac_rx_undermin_pkt_num), +HINIC_PORT_STAT (mac_rx_64_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_65_127_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_128_255_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_256_511_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_512_1023_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_1024_1518_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_1519_2047_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_2048_4095_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_4096_8191_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_8192_9216_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_9217_12287_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_12288_16383_oct_pkt_num), +HINIC_PORT_STAT (mac_rx_1519_max_bad_pkt_num), +HINIC_PORT_STAT (mac_rx_1519_max_good_pkt_num), +HINIC_PORT_STAT (mac_rx_oversize_pkt_num), +HINIC_PORT_STAT (mac_rx_jabber_pkt_num), +HINIC_PORT_STAT (mac_rx_mac_pause_num), +HINIC_PORT_STAT (mac_rx_pfc_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri0_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri1_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri2_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri3_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri4_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri5_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri6_pkt_num), +HINIC_PORT_STAT (mac_rx_pfc_pri7_pkt_num), +HINIC_PORT_STAT (mac_rx_mac_control_pkt_num), +HINIC_PORT_STAT (mac_rx_sym_err_pkt_num), +HINIC_PORT_STAT (mac_rx_fcs_err_pkt_num), +HINIC_PORT_STAT (mac_rx_send_app_good_pkt_num), +HINIC_PORT_STAT (mac_rx_send_app_bad_pkt_num), +HINIC_PORT_STAT (mac_tx_fragment_pkt_num), +HINIC_PORT_STAT (mac_tx_undersize_pkt_num), +HINIC_PORT_STAT (mac_tx_undermin_pkt_num), +HINIC_PORT_STAT (mac_tx_64_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_65_127_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_128_255_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_256_511_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_512_1023_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_1024_1518_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_1519_2047_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_2048_4095_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_4096_8191_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_8192_9216_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_9217_12287_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_12288_16383_oct_pkt_num), +HINIC_PORT_STAT (mac_tx_1519_max_bad_pkt_num), +HINIC_PORT_STAT (mac_tx_1519_max_good_pkt_num), +HINIC_PORT_STAT (mac_tx_oversize_pkt_num), +HINIC_PORT_STAT (mac_trans_jabber_pkt_num), +HINIC_PORT_STAT (mac_tx_mac_pause_num), +HINIC_PORT_STAT (mac_tx_pfc_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri0_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri1_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri2_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri3_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri4_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri5_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri6_pkt_num), +HINIC_PORT_STAT (mac_tx_pfc_pri7_pkt_num), +HINIC_PORT_STAT (mac_tx_mac_control_pkt_num), +HINIC_PORT_STAT (mac_tx_err_all_pkt_num), +HINIC_PORT_STAT (mac_tx_from_app_good_pkt_num), +HINIC_PORT_STAT (mac_tx_from_app_bad_pkt_num), +}; + +#define HINIC_PHYPORT_XSTATS_NUM (sizeof(hinic_phyport_stats_strings) / \ + sizeof(hinic_phyport_stats_strings[0])) + +static const struct hinic_xstats_name_off hinic_rxq_stats_strings[] = { + {"rx_nombuf" , offsetof(struct hinic_rxq_stats , rx_nombuf)}, + +#ifdef HINIC_XSTAT_RXBUF_INFO + {"rxmbuf" , offsetof(struct hinic_rxq_stats , rx_mbuf)}, + {"avail" , offsetof(struct hinic_rxq_stats , rx_avail)}, + {"hole" , offsetof(struct hinic_rxq_stats , rx_hole)}, + {"burst_pkt" , offsetof(struct hinic_rxq_stats , burst_pkts)}, +#endif + +#ifdef HINIC_XSTAT_PROF_RX + {"app_tsc" , offsetof(struct hinic_rxq_stats , app_tsc)}, + {"pmd_tsc" , offsetof(struct hinic_rxq_stats , pmd_tsc)}, +#endif + +#ifdef HINIC_XSTAT_MBUF_USE + {"rx_alloc_mbuf" , offsetof(struct hinic_rxq_stats , alloc_mbuf)}, + {"rx_free_mbuf" , offsetof(struct hinic_rxq_stats , free_mbuf)}, + {"rx_left_mbuf" , offsetof(struct hinic_rxq_stats , left_mbuf)}, +#endif +}; + +#define HINIC_RXQ_XSTATS_NUM (sizeof(hinic_rxq_stats_strings) / \ + sizeof(hinic_rxq_stats_strings[0])) + +static const struct hinic_xstats_name_off hinic_txq_stats_strings[] = { + {"tx_busy" , offsetof(struct hinic_txq_stats , tx_busy)}, + {"offload_errors" , offsetof(struct hinic_txq_stats , off_errs)}, + {"copy_pkts" , offsetof(struct hinic_txq_stats , cpy_pkts)}, + {"rl_drop" , offsetof(struct hinic_txq_stats , rl_drop)}, + +#ifdef HINIC_XSTAT_PROF_TX + {"app_tsc" , offsetof(struct hinic_txq_stats , app_tsc)}, + {"pmd_tsc" , offsetof(struct hinic_txq_stats , pmd_tsc)}, + {"burst_pkts" , offsetof(struct hinic_txq_stats , burst_pkts)}, +#endif +}; + +#define HINIC_TXQ_XSTATS_NUM (sizeof(hinic_txq_stats_strings) / \ + sizeof(hinic_txq_stats_strings[0])) + +static const struct rte_eth_desc_lim hinic_rx_desc_lim = { + .nb_max =HINIC_MAX_QUEUE_DEPTH , + .nb_min =HINIC_MIN_QUEUE_DEPTH , + .nb_align =HINIC_RXD_ALIGN , +}; + +static const struct rte_eth_desc_lim hinic_tx_desc_lim = { + .nb_max =HINIC_MAX_QUEUE_DEPTH , + .nb_min =HINIC_MIN_QUEUE_DEPTH , + .nb_align =HINIC_TXD_ALIGN , +}; + +static int hinic_xstats_calc_num (struct hinic_nic_dev *nic_dev) +{ +return (HINIC_VPORT_XSTATS_NUM + +HINIC_PHYPORT_XSTATS_NUM + +HINIC_RXQ_XSTATS_NUM * nic_dev->num_rq + +HINIC_TXQ_XSTATS_NUM * nic_dev->num_sq); +} + +static void +hinic_dev_handle_aeq_event (struct hinic_nic_dev *nic_dev,void *param) +{ +struct hinic_hwdev *hwdev = nic_dev->hwdev; +struct hinic_eq *aeq = &hwdev->aeqs->aeq[0 ]; + +/* clear resend timer cnt register */ +hinic_misx_intr_clear_resend_bit (hwdev, aeq->eq_irq.msix_entry_idx, +EQ_MSIX_RESEND_TIMER_CLEAR ); + (void )hinic_aeq_poll_msg (aeq,0 , param); +} + +/** +* Interrupt handler triggered by NIC for handling +* specific event. +* +* @param: The address of parameter (struct rte_eth_dev *) regsitered before. +**/ +static void hinic_dev_interrupt_handler (void *param) +{ +struct rte_eth_dev *dev = (struct rte_eth_dev *)param; +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +if (!hinic_test_bit (HINIC_DEV_INTR_EN , &nic_dev->dev_status)) { +PMD_DRV_LOG (INFO ,"Device's interrupt is disabled, ignore interrupt event, dev_name: %s, port_id: %d" , + nic_dev->proc_dev_name, dev->data->port_id); +return ; + } + +/* aeq0 msg handler */ +hinic_dev_handle_aeq_event (nic_dev, param); +} + +static int hinic_func_init (struct rte_eth_dev *eth_dev) +{ +struct rte_pci_device *pci_dev; +struct rte_ether_addr *eth_addr; +struct hinic_nic_dev *nic_dev; +int rc; + + 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 ) { + rc =rte_intr_callback_register (&pci_dev->intr_handle, + hinic_dev_interrupt_handler, + (void *)eth_dev); +if (rc) +PMD_DRV_LOG (ERR ,"Initialize %s failed in secondary process" , + eth_dev->data->name); + +return rc; + } + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +memset (nic_dev,0 ,sizeof (*nic_dev)); + +snprintf (nic_dev->proc_dev_name, +sizeof (nic_dev->proc_dev_name), +"hinic-%.4x:%.2x:%.2x.%x" , + pci_dev->addr.domain, pci_dev->addr.bus, + pci_dev->addr.devid, pci_dev->addr.function); + +rte_eth_copy_pci_info (eth_dev, pci_dev); + +/* clear RX ring mbuf allocated failed */ + eth_dev->data->rx_mbuf_alloc_failed =0 ; + +/* alloc mac_addrs */ + eth_addr = (struct rte_ether_addr *)rte_zmalloc ("hinic_mac" , +sizeof (*eth_addr),0 ); +if (!eth_addr) { +PMD_DRV_LOG (ERR ,"Allocate ethernet addresses' memory failed, dev_name: %s" , + eth_dev->data->name); + rc = -ENOMEM ; + goto eth_addr_fail; + } + eth_dev->data->mac_addrs = eth_addr; + +/* create hardware nic_device */ + rc =hinic_nic_dev_create (eth_dev); +if (rc) { +PMD_DRV_LOG (ERR ,"Create nic device failed, dev_name: %s" , + eth_dev->data->name); + goto create_nic_dev_fail; + } + + rc =hinic_init_mac_addr (eth_dev); +if (rc) { +PMD_DRV_LOG (ERR ,"Initialize mac table failed, dev_name: %s" , + eth_dev->data->name); + goto init_mac_fail; + } + +/* register callback func to eal lib */ + rc =rte_intr_callback_register (&pci_dev->intr_handle, + hinic_dev_interrupt_handler, + (void *)eth_dev); +if (rc) { +PMD_DRV_LOG (ERR ,"Register rte interrupt callback failed, dev_name: %s" , + eth_dev->data->name); + goto reg_intr_cb_fail; + } + +/* Verify fw-driver version compatibility */ + rc =hinic_pci_verify_fw_ver (eth_dev, pci_dev->device.devargs); +if (rc !=HINIC_OK ) + goto enable_intr_fail; + +/* enable uio/vfio intr/eventfd mapping */ + rc =rte_intr_enable (&pci_dev->intr_handle); +if (rc) { +PMD_DRV_LOG (ERR ,"Enable rte interrupt failed, dev_name: %s" , + eth_dev->data->name); + goto enable_intr_fail; + } +hinic_set_bit (HINIC_DEV_INTR_EN , &nic_dev->dev_status); + +hinic_set_bit (HINIC_DEV_INIT , &nic_dev->dev_status); +PMD_DRV_LOG (INFO ,"Initialize %s in primary successfully" , + eth_dev->data->name); + +return 0 ; + +enable_intr_fail: + (void )rte_intr_callback_unregister (&pci_dev->intr_handle, + hinic_dev_interrupt_handler, + (void *)eth_dev); + +reg_intr_cb_fail: +hinic_deinit_mac_addr (eth_dev); + +init_mac_fail: +hinic_nic_dev_destroy (eth_dev); + +create_nic_dev_fail: +rte_free (eth_addr); + eth_dev->data->mac_addrs =NULL ; + +eth_addr_fail: +PMD_DRV_LOG (INFO ,"Initialize %s in primary failed" , + eth_dev->data->name); +return rc; +} + +static int hinic_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 pf hinic-%.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" ); + +/* rte_eth_dev ops, rx_burst and tx_burst */ + eth_dev->dev_ops = &hinic_pmd_ops; + eth_dev->rx_pkt_burst = hinic_recv_pkts; + eth_dev->tx_pkt_burst = hinic_xmit_pkts; + +return hinic_func_init (eth_dev); +} + +/** +* PF Function device uninit. +*/ +static int hinic_dev_uninit (struct rte_eth_dev *dev) +{ +struct hinic_nic_dev *nic_dev; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +hinic_clear_bit (HINIC_DEV_INIT , &nic_dev->dev_status); + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) +return 0 ; + +hinic_dev_close (dev); + + dev->dev_ops =NULL ; + dev->rx_pkt_burst =NULL ; + dev->tx_pkt_burst =NULL ; + +rte_free (dev->data->mac_addrs); + dev->data->mac_addrs =NULL ; + +return HINIC_OK ; +} + +/** +* Ethernet device configuration. +* +* Prepare the driver for a given number of TX and RX queues, mtu size +* and configure RSS. +* +* @param dev +* Pointer to Ethernet device structure. +* +* @return +* 0 on success, negative error value otherwise. +*/ +int hinic_dev_configure (struct rte_eth_dev *dev) +{ +struct hinic_nic_dev *nic_dev; +struct hinic_nic_io *nic_io; +int err; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + nic_io = nic_dev->hwdev->nic_io; + + nic_dev->num_sq = dev->data->nb_tx_queues; + nic_dev->num_rq = dev->data->nb_rx_queues; + + nic_io->num_sqs = dev->data->nb_tx_queues; + nic_io->num_rqs = dev->data->nb_rx_queues; + +/* queue pair is max_num(sq, rq) */ + nic_dev->num_qps = (nic_dev->num_sq > nic_dev->num_rq) ? + nic_dev->num_sq : nic_dev->num_rq; + nic_io->num_qps = nic_dev->num_qps; + +if (nic_dev->num_qps > nic_io->max_qps) { +PMD_DRV_LOG (ERR , +"Queue number out of range, get queue_num:%d, max_queue_num:%d" , + nic_dev->num_qps, nic_io->max_qps); +return -EINVAL ; + } + +/* mtu size is 256~9600 */ +if (dev->data->dev_conf.rxmode.max_rx_pkt_len <HINIC_MIN_FRAME_SIZE || + dev->data->dev_conf.rxmode.max_rx_pkt_len > +HINIC_MAX_JUMBO_FRAME_SIZE ) { +PMD_DRV_LOG (ERR , +"Max rx pkt len out of range, get max_rx_pkt_len:%d, " +"expect between %d and %d" , + dev->data->dev_conf.rxmode.max_rx_pkt_len, +HINIC_MIN_FRAME_SIZE ,HINIC_MAX_JUMBO_FRAME_SIZE ); +return -EINVAL ; + } + + nic_dev->mtu_size = +HINIC_PKTLEN_TO_MTU (dev->data->dev_conf.rxmode.max_rx_pkt_len); + +/* rss template */ + err =hinic_config_mq_mode (dev, TRUE); +if (err) { +PMD_DRV_LOG (ERR ,"Config multi-queue failed" ); +return err; + } + +return HINIC_OK ; +} + +/** +* DPDK callback to create the receive queue. +* +* @param dev +* Pointer to Ethernet device structure. +* @param queue_idx +* RX queue index. +* @param nb_desc +* Number of descriptors for receive queue. +* @param socket_id +* NUMA socket on which memory must be allocated. +* @param rx_conf +* Thresholds parameters (unused_). +* @param mp +* Memory pool for buffer allocations. +* +* @return +* 0 on success, negative error value otherwise. +*/ +static int hinic_rx_queue_setup (struct rte_eth_dev *dev,uint16_t queue_idx, +uint16_t nb_desc,unsigned int socket_id, + __rte_unused const struct rte_eth_rxconf *rx_conf, +struct rte_mempool *mp) +{ +int rc; +struct hinic_nic_dev *nic_dev; +struct hinic_rxq *rxq; +u16 rq_depth, rx_free_thresh; +u32 buf_size; + + nic_dev =HINIC_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 >HINIC_MAX_QUEUE_DEPTH || + rq_depth <HINIC_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)" , +HINIC_MIN_QUEUE_DEPTH ,HINIC_MAX_QUEUE_DEPTH , + (int )nb_desc, (int )rq_depth, + (int )dev->data->port_id, (int )queue_idx); +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 :HINIC_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 )queue_idx); +return -EINVAL ; + } + + rxq = (struct hinic_rxq *)rte_zmalloc_socket ("hinic_rx_queue" , +sizeof (struct hinic_rxq ), +RTE_CACHE_LINE_SIZE , + socket_id); +if (!rxq) { +PMD_DRV_LOG (ERR ,"Allocate rxq[%d] failed, dev_name: %s" , + queue_idx, dev->data->name); +return -ENOMEM ; + } + nic_dev->rxqs[queue_idx] = rxq; + +/* alloc rx sq hw wqepage*/ + rc =hinic_create_rq (nic_dev, queue_idx, rq_depth); +if (rc) { +PMD_DRV_LOG (ERR ,"Create rxq[%d] failed, dev_name: %s, rq_depth: %d" , + queue_idx, dev->data->name, rq_depth); + goto ceate_rq_fail; + } + +/* mbuf pool must be assigned before setup rx resources */ + rxq->mb_pool = mp; + + rc = +hinic_convert_rx_buf_size (rte_pktmbuf_data_room_size (rxq->mb_pool) - +RTE_PKTMBUF_HEADROOM , &buf_size); +if (rc) { +PMD_DRV_LOG (ERR ,"Adjust buf size failed, dev_name: %s" , + dev->data->name); + goto adjust_bufsize_fail; + } + +/* rx queue info, rearm control */ + rxq->wq = &nic_dev->nic_io->rq_wq[queue_idx]; + rxq->pi_virt_addr = nic_dev->nic_io->qps[queue_idx].rq.pi_virt_addr; + rxq->nic_dev = nic_dev; + rxq->q_id = queue_idx; + rxq->q_depth = rq_depth; + rxq->buf_len = (u16 )buf_size; + rxq->rx_free_thresh = rx_free_thresh; + +/* the last point cant do mbuf rearm in bulk */ + rxq->rxinfo_align_end = rxq->q_depth - rxq->rx_free_thresh; + +/* device port identifier */ + rxq->port_id = dev->data->port_id; + +/* alloc rx_cqe and prepare rq_wqe */ + rc =hinic_setup_rx_resources (rxq); +if (rc) { +PMD_DRV_LOG (ERR ,"Setup rxq[%d] rx_resources failed, dev_name:%s" , + queue_idx, dev->data->name); + goto setup_rx_res_err; + } + +/* record nic_dev rxq in rte_eth rx_queues */ + dev->data->rx_queues[queue_idx] = rxq; + +PMD_DRV_LOG (INFO ,"Setup rxq[%d] successfully, dev_name: %s, rq_depth: %d" , + queue_idx, dev->data->name, rq_depth); +return 0 ; + +setup_rx_res_err: +adjust_bufsize_fail: +hinic_destroy_rq (nic_dev, queue_idx); + +ceate_rq_fail: +rte_free (rxq); + +return rc; +} + +static void hinic_reset_rx_queue (struct rte_eth_dev *dev) +{ +struct hinic_rxq *rxq; +struct hinic_nic_dev *nic_dev; +int q_id =0 ; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +for (q_id =0 ; q_id < nic_dev->num_rq; q_id++) { + rxq = (struct hinic_rxq *)dev->data->rx_queues[q_id]; + + rxq->wq->cons_idx =0 ; + rxq->wq->prod_idx =0 ; + rxq->wq->delta = rxq->q_depth; + rxq->wq->mask = rxq->q_depth -1 ; + +/* alloc mbuf to rq */ +hinic_rx_alloc_pkts (rxq); + } +} + +/** +* DPDK callback to configure the transmit queue. +* +* @param dev +* Pointer to Ethernet device structure. +* @param queue_idx +* Transmit queue index. +* @param nb_desc +* Number of descriptors for transmit queue. +* @param socket_id +* NUMA socket on which memory must be allocated. +* @param tx_conf +* Tx queue configuration parameters. +* +* @return +* 0 on success, negative error value otherwise. +*/ +static int hinic_tx_queue_setup (struct rte_eth_dev *dev,uint16_t queue_idx, +uint16_t nb_desc,unsigned int socket_id, + __rte_unused const struct rte_eth_txconf *tx_conf) +{ +int rc; +struct hinic_nic_dev *nic_dev; +struct hinic_txq *txq; +u16 sq_depth, tx_free_thresh; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +/* 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 >HINIC_MAX_QUEUE_DEPTH || + sq_depth <HINIC_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)" , +HINIC_MIN_QUEUE_DEPTH ,HINIC_MAX_QUEUE_DEPTH , + (int )nb_desc, (int )sq_depth, + (int )dev->data->port_id, (int )queue_idx); +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 :HINIC_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 )queue_idx); +return -EINVAL ; + } + + txq = (struct hinic_txq *)rte_zmalloc_socket ("hinic_tx_queue" , +sizeof (struct hinic_txq ),RTE_CACHE_LINE_SIZE , socket_id); +if (!txq) { +PMD_DRV_LOG (ERR ,"Allocate txq[%d] failed, dev_name: %s" , + queue_idx, dev->data->name); +return -ENOMEM ; + } + nic_dev->txqs[queue_idx] = txq; + +/* alloc tx sq hw wqepage */ + rc =hinic_create_sq (nic_dev, queue_idx, sq_depth); +if (rc) { +PMD_DRV_LOG (ERR ,"Create txq[%d] failed, dev_name: %s, sq_depth: %d" , + queue_idx, dev->data->name, sq_depth); + goto create_sq_fail; + } + + txq->q_id = queue_idx; + txq->q_depth = sq_depth; + txq->port_id = dev->data->port_id; + txq->tx_free_thresh = tx_free_thresh; + txq->nic_dev = nic_dev; + txq->wq = &nic_dev->nic_io->sq_wq[queue_idx]; + txq->sq = &nic_dev->nic_io->qps[queue_idx].sq; + txq->cons_idx_addr = nic_dev->nic_io->qps[queue_idx].sq.cons_idx_addr; + txq->sq_head_addr =HINIC_GET_WQ_HEAD (txq); + txq->sq_bot_sge_addr =HINIC_GET_WQ_TAIL (txq) - +sizeof (struct hinic_sq_bufdesc ); + txq->cos = nic_dev->default_cos; + +/* alloc software txinfo */ + rc =hinic_setup_tx_resources (txq); +if (rc) { +PMD_DRV_LOG (ERR ,"Setup txq[%d] tx_resources failed, dev_name: %s" , + queue_idx, dev->data->name); + goto setup_tx_res_fail; + } + +/* record nic_dev txq in rte_eth tx_queues */ + dev->data->tx_queues[queue_idx] = txq; + +return HINIC_OK ; + +setup_tx_res_fail: +hinic_destroy_sq (nic_dev, queue_idx); + +create_sq_fail: +rte_free (txq); + +return rc; +} + +static void hinic_reset_tx_queue (struct rte_eth_dev *dev) +{ +struct hinic_nic_dev *nic_dev; +struct hinic_txq *txq; +struct hinic_nic_io *nic_io; +struct hinic_hwdev *hwdev; +volatile u32 *ci_addr; +int q_id =0 ; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + hwdev = nic_dev->hwdev; + nic_io = hwdev->nic_io; + +for (q_id =0 ; q_id < nic_dev->num_sq; q_id++) { + txq = (struct hinic_txq *)dev->data->tx_queues[q_id]; + + txq->wq->cons_idx =0 ; + txq->wq->prod_idx =0 ; + txq->wq->delta = txq->q_depth; + txq->wq->mask = txq->q_depth -1 ; + +/*clear hardware ci*/ + ci_addr = (volatile u32 *)HINIC_CI_VADDR (nic_io->ci_vaddr_base, + q_id); + *ci_addr =0 ; + } +} + +/** +* Get link speed from NIC. +* +* @param dev +* Pointer to Ethernet device structure. +* @param speed_capa +* Pointer to link speed structure. +*/ +static void hinic_get_speed_capa (struct rte_eth_dev *dev,uint32_t *speed_capa) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u32 supported_link, advertised_link; +int err; + +#define HINIC_LINK_MODE_SUPPORT_1G (1U << HINIC_GE_BASE_KX) + +#define HINIC_LINK_MODE_SUPPORT_10G (1U << HINIC_10GE_BASE_KR) + +#define HINIC_LINK_MODE_SUPPORT_25G ((1U << HINIC_25GE_BASE_KR_S) | \ + (1U << HINIC_25GE_BASE_CR_S) | \ + (1U << HINIC_25GE_BASE_KR) | \ + (1U << HINIC_25GE_BASE_CR)) + +#define HINIC_LINK_MODE_SUPPORT_40G ((1U << HINIC_40GE_BASE_KR4) | \ + (1U << HINIC_40GE_BASE_CR4)) + +#define HINIC_LINK_MODE_SUPPORT_100G ((1U << HINIC_100GE_BASE_KR4) | \ + (1U << HINIC_100GE_BASE_CR4)) + + err =hinic_get_link_mode (nic_dev->hwdev, + &supported_link, &advertised_link); +if (err || supported_link ==HINIC_SUPPORTED_UNKNOWN || + advertised_link ==HINIC_SUPPORTED_UNKNOWN ) { +PMD_DRV_LOG (WARNING ,"Get speed capability info failed, device: %s, port_id: %u" , + nic_dev->proc_dev_name, dev->data->port_id); + }else { + *speed_capa =0 ; +if (!!(supported_link &HINIC_LINK_MODE_SUPPORT_1G )) + *speed_capa |=ETH_LINK_SPEED_1G ; +if (!!(supported_link &HINIC_LINK_MODE_SUPPORT_10G )) + *speed_capa |=ETH_LINK_SPEED_10G ; +if (!!(supported_link &HINIC_LINK_MODE_SUPPORT_25G )) + *speed_capa |=ETH_LINK_SPEED_25G ; +if (!!(supported_link &HINIC_LINK_MODE_SUPPORT_40G )) + *speed_capa |=ETH_LINK_SPEED_40G ; +if (!!(supported_link &HINIC_LINK_MODE_SUPPORT_100G )) + *speed_capa |=ETH_LINK_SPEED_100G ; + } +} + +/** +* DPDK callback to get information about the device. +* +* @param dev +* Pointer to Ethernet device structure. +* @param info +* Pointer to Info structure output buffer. +*/ +void hinic_dev_infos_get (struct rte_eth_dev *dev,struct rte_eth_dev_info *info) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + + info->max_rx_queues = nic_dev->nic_cap.max_rqs; + info->max_tx_queues = nic_dev->nic_cap.max_sqs; + info->min_rx_bufsize =HINIC_MIN_RX_BUF_SIZE ; + info->max_rx_pktlen =HINIC_MAX_JUMBO_FRAME_SIZE ; + info->max_mac_addrs =HINIC_MAX_MAC_ADDRS ; + +hinic_get_speed_capa (dev, &info->speed_capa); + info->rx_queue_offload_capa =0 ; + info->rx_offload_capa =DEV_RX_OFFLOAD_VLAN_STRIP | +DEV_RX_OFFLOAD_IPV4_CKSUM | +DEV_RX_OFFLOAD_UDP_CKSUM | +DEV_RX_OFFLOAD_TCP_CKSUM | +DEV_RX_OFFLOAD_VLAN_FILTER | +DEV_RX_OFFLOAD_JUMBO_FRAME ; + + info->tx_queue_offload_capa =0 ; + info->tx_offload_capa =DEV_TX_OFFLOAD_VLAN_INSERT | +DEV_TX_OFFLOAD_IPV4_CKSUM | +DEV_TX_OFFLOAD_UDP_CKSUM | +DEV_TX_OFFLOAD_TCP_CKSUM | +DEV_TX_OFFLOAD_SCTP_CKSUM | +DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM | +DEV_TX_OFFLOAD_TCP_TSO | +DEV_TX_OFFLOAD_MULTI_SEGS ; + + info->hash_key_size =HINIC_RSS_KEY_SIZE ; + info->reta_size =HINIC_RSS_INDIR_SIZE ; + info->flow_type_rss_offloads =HINIC_RSS_OFFLOAD_ALL ; + info->rx_desc_lim = hinic_rx_desc_lim; + info->tx_desc_lim = hinic_tx_desc_lim; +} + +int hinic_rxtx_configure (struct rte_eth_dev *dev) +{ +int err; +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +/* rx configure, if rss enable, need to init default configuration */ + err =hinic_rx_configure (dev); +if (err) { +PMD_DRV_LOG (ERR ,"Configure rss failed" ); +return err; + } + +/* rx mode init */ + err =hinic_config_rx_mode (nic_dev,HINIC_DEFAULT_RX_MODE ); +if (err) { +PMD_DRV_LOG (ERR ,"Configure rx_mode:0x%x failed" , +HINIC_DEFAULT_RX_MODE ); + goto set_rx_mode_fail; + } + +return HINIC_OK ; + +set_rx_mode_fail: +hinic_rx_remove_configure (dev); + +return err; +} + +static void hinic_remove_rxtx_configure (struct rte_eth_dev *dev) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + + (void )hinic_config_rx_mode (nic_dev,0 ); +hinic_rx_remove_configure (dev); +} + +/** +* DPDK callback to start the device. +* +* @param dev +* Pointer to Ethernet device structure. +* +* @return +* 0 on success, negative errno value on failure. +*/ +int hinic_dev_start (struct rte_eth_dev *dev) +{ +int rc; +char *name; +struct hinic_nic_dev *nic_dev; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + name = dev->data->name; + +/* reset rx and tx queue */ +hinic_reset_rx_queue (dev); +hinic_reset_tx_queue (dev); + +/* init txq and rxq context */ + rc =hinic_init_qp_ctxts (nic_dev->hwdev); +if (rc) { +PMD_DRV_LOG (ERR ,"Initialize qp context failed, dev_name:%s" , + name); + goto init_qp_fail; + } + +/* rss template */ + rc =hinic_config_mq_mode (dev, TRUE); +if (rc) { +PMD_DRV_LOG (ERR ,"Configure mq mode failed, dev_name: %s" , + name); + goto cfg_mq_mode_fail; + } + +/* set default mtu */ + rc =hinic_set_port_mtu (nic_dev->hwdev, nic_dev->mtu_size); +if (rc) { +PMD_DRV_LOG (ERR ,"Set mtu_size[%d] failed, dev_name: %s" , + nic_dev->mtu_size, name); + goto set_mtu_fail; + } + +/* configure rss rx_mode and other rx or tx default feature */ + rc =hinic_rxtx_configure (dev); +if (rc) { +PMD_DRV_LOG (ERR ,"Configure tx and rx failed, dev_name: %s" , + name); + goto cfg_rxtx_fail; + } + +/* open virtual port and ready to start packet receiving */ + rc =hinic_set_vport_enable (nic_dev->hwdev, true); +if (rc) { +PMD_DRV_LOG (ERR ,"Enable vport failed, dev_name:%s" , name); + goto en_vport_fail; + } + +/* open physical port and start packet receiving */ + rc =hinic_set_port_enable (nic_dev->hwdev, true); +if (rc) { +PMD_DRV_LOG (ERR ,"Enable physical port failed, dev_name:%s" , + name); + goto en_port_fail; + } + +/* update eth_dev link status */ +if (dev->data->dev_conf.intr_conf.lsc !=0 ) + (void )hinic_link_update (dev,0 ); + +hinic_set_bit (HINIC_DEV_START , &nic_dev->dev_status); + +PMD_DRV_LOG (INFO ,"Device %s started" , name); + +return 0 ; + +en_port_fail: + (void )hinic_set_vport_enable (nic_dev->hwdev, false); + +en_vport_fail: +/* Flush tx && rx chip resources in case of set vport fake fail */ + (void )hinic_flush_qp_res (nic_dev->hwdev); +rte_delay_ms (100 ); + +hinic_remove_rxtx_configure (dev); + +cfg_rxtx_fail: +set_mtu_fail: +cfg_mq_mode_fail: +hinic_free_qp_ctxts (nic_dev->hwdev); + +init_qp_fail: +hinic_free_all_rx_mbuf (dev); +hinic_free_all_tx_mbuf (dev); + +return rc; +} + +/** +* DPDK callback to release the receive queue. +* +* @param queue +* Generic receive queue pointer. +*/ +void hinic_rx_queue_release (void *queue) +{ +struct hinic_rxq *rxq = (struct hinic_rxq *)queue; +struct hinic_nic_dev *nic_dev; + +if (!rxq) { +PMD_DRV_LOG (WARNING ,"Rxq is null when release" ); +return ; + } + nic_dev = rxq->nic_dev; + +/* free rxq_pkt mbuf */ +hinic_free_all_rx_skbs (rxq); + +/* free rxq_cqe, rxq_info */ +hinic_free_rx_resources (rxq); + +/* free root rq wq */ +hinic_destroy_rq (nic_dev, rxq->q_id); + + nic_dev->rxqs[rxq->q_id] =NULL ; + +/* free rxq */ +rte_free (rxq); +} + +/** +* DPDK callback to release the transmit queue. +* +* @param queue +* Generic transmit queue pointer. +*/ +void hinic_tx_queue_release (void *queue) +{ +struct hinic_txq *txq = (struct hinic_txq *)queue; +struct hinic_nic_dev *nic_dev; + +if (!txq) { +PMD_DRV_LOG (WARNING ,"Txq is null when release" ); +return ; + } + nic_dev = txq->nic_dev; + +/* free txq_pkt mbuf */ +hinic_free_all_tx_skbs (txq); + +/* free txq_info */ +hinic_free_tx_resources (txq); + +/* free root sq wq */ +hinic_destroy_sq (nic_dev, txq->q_id); + nic_dev->txqs[txq->q_id] =NULL ; + +/* free txq */ +rte_free (txq); +} + +void hinic_free_all_rq (struct hinic_nic_dev *nic_dev) +{ +u16 q_id; + +for (q_id =0 ; q_id < nic_dev->num_rq; q_id++) +hinic_destroy_rq (nic_dev, q_id); +} + +void hinic_free_all_sq (struct hinic_nic_dev *nic_dev) +{ +u16 q_id; + +for (q_id =0 ; q_id < nic_dev->num_sq; q_id++) +hinic_destroy_sq (nic_dev, q_id); +} + +/** +* DPDK callback to stop the device. +* +* @param dev +* Pointer to Ethernet device structure. +*/ +void hinic_dev_stop (struct rte_eth_dev *dev) +{ +int rc; +char *name; +uint16_t port_id; +struct hinic_nic_dev *nic_dev; +struct rte_eth_link link; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + name = dev->data->name; + port_id = dev->data->port_id; + +if (!hinic_test_and_clear_bit (HINIC_DEV_START , &nic_dev->dev_status)) { +PMD_DRV_LOG (INFO ,"Device %s already stopped" , name); +return ; + } + +/* just stop phy port and vport */ + rc =hinic_set_port_enable (nic_dev->hwdev, false); +if (rc) +PMD_DRV_LOG (WARNING ,"Disable phy port failed, error: %d, dev_name:%s, port_id:%d" , + rc, name, port_id); + + rc =hinic_set_vport_enable (nic_dev->hwdev, false); +if (rc) +PMD_DRV_LOG (WARNING ,"Disable vport failed, error: %d, dev_name:%s, port_id:%d" , + rc, name, port_id); + +/* Clear recorded link status */ +memset (&link,0 ,sizeof (link)); + (void )rte_eth_linkstatus_set (dev, &link); + +/* flush pending io request */ + rc =hinic_rx_tx_flush (nic_dev->hwdev); +if (rc) +PMD_DRV_LOG (WARNING ,"Flush pending io failed, error: %d, dev_name: %s, port_id: %d" , + rc, name, port_id); + +/* clean rss table and rx_mode */ +hinic_remove_rxtx_configure (dev); + +/* clean root context */ +hinic_free_qp_ctxts (nic_dev->hwdev); + +/* free mbuf */ +hinic_free_all_rx_mbuf (dev); +hinic_free_all_tx_mbuf (dev); + +PMD_DRV_LOG (INFO ,"Device %s stopped" , name); +} + +void hinic_disable_interrupt (struct rte_eth_dev *dev) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct rte_pci_device *pci_dev =RTE_ETH_DEV_TO_PCI (dev); +int ret, retries =0 ; + +hinic_clear_bit (HINIC_DEV_INTR_EN , &nic_dev->dev_status); + +/* disable msix interrupt in hardware */ +hinic_set_msix_state (nic_dev->hwdev,0 ,HINIC_MSIX_DISABLE ); + +/* disable rte interrupt */ + ret =rte_intr_disable (&pci_dev->intr_handle); +if (ret) +PMD_DRV_LOG (ERR ,"Disable intr failed: %d" , ret); + +do { + ret = +rte_intr_callback_unregister (&pci_dev->intr_handle, + hinic_dev_interrupt_handler, dev); +if (ret >=0 ) { +break ; + }else if (ret == -EAGAIN ) { +rte_delay_ms (100 ); + retries++; + }else { +PMD_DRV_LOG (ERR ,"intr callback unregister failed: %d" , + ret); +break ; + } + }while (retries <HINIC_INTR_CB_UNREG_MAX_RETRIES ); + +if (retries ==HINIC_INTR_CB_UNREG_MAX_RETRIES ) +PMD_DRV_LOG (ERR ,"Unregister intr callback failed after %d retries" , + retries); +} + +/** +* DPDK callback to close the device. +* +* @param dev +* Pointer to Ethernet device structure. +*/ +void hinic_dev_close (struct rte_eth_dev *dev) +{ +char *name; +struct hinic_nic_dev *nic_dev; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + name = dev->data->name; + +if (hinic_test_and_set_bit (HINIC_DEV_CLOSE , &nic_dev->dev_status)) { +PMD_DRV_LOG (INFO ,"Device %s already closed" , name); +return ; + } + +/* stop device first */ +hinic_dev_stop (dev); + +/* rx_cqe, rx_info */ +hinic_free_all_rx_resources (dev); + +/* tx_info */ +hinic_free_all_tx_resources (dev); + +/* free wq, pi_dma_addr */ +hinic_free_all_rq (nic_dev); + +/* free wq, db_addr */ +hinic_free_all_sq (nic_dev); + +/* deinit mac vlan tbl */ +hinic_deinit_mac_addr (dev); + +/* disable hardware and uio interrupt */ +hinic_disable_interrupt (dev); + +/* deinit nic hardware device */ +hinic_nic_dev_destroy (dev); + +PMD_DRV_LOG (INFO ,"Device %s closed" , name); +} + +static int hinic_priv_get_dev_link_status (struct hinic_nic_dev *nic_dev, +struct rte_eth_link *link) +{ +int rc =HINIC_OK ; +u8 port_link_status =0 ; +struct nic_port_info port_link_info; +struct hinic_hwdev *nic_hwdev = nic_dev->hwdev; +uint32_t port_speed[LINK_SPEED_MAX ] = {ETH_SPEED_NUM_10M , +ETH_SPEED_NUM_100M ,ETH_SPEED_NUM_1G , +ETH_SPEED_NUM_10G ,ETH_SPEED_NUM_25G , +ETH_SPEED_NUM_40G ,ETH_SPEED_NUM_100G }; + +memset (link,0 ,sizeof (*link)); + rc =hinic_get_link_status (nic_hwdev, &port_link_status); +if (rc) +return rc; + + nic_dev->link_status = port_link_status; +if (!port_link_status) { + link->link_status =ETH_LINK_DOWN ; + link->link_speed =0 ; + link->link_duplex =ETH_LINK_HALF_DUPLEX ; + link->link_autoneg =ETH_LINK_FIXED ; +return rc; + } + +memset (&port_link_info,0 ,sizeof (port_link_info)); + rc =hinic_get_port_info (nic_hwdev, &port_link_info); +if (rc) +return rc; + + link->link_speed = port_speed[port_link_info.speed %LINK_SPEED_MAX ]; + link->link_duplex = port_link_info.duplex; + link->link_autoneg = port_link_info.autoneg_state; + link->link_status = port_link_status; + +return rc; +} + +static int hinic_set_dev_promiscuous (struct hinic_nic_dev *nic_dev,bool enable) +{ +u32 rx_mode_ctrl = nic_dev->rx_mode_status; + +if (enable) + rx_mode_ctrl |=HINIC_RX_MODE_PROMISC ; +else + rx_mode_ctrl &= (~HINIC_RX_MODE_PROMISC ); + +return hinic_config_rx_mode (nic_dev, rx_mode_ctrl); +} + +/** +* DPDK callback to get device statistics. +* +* @param dev +* Pointer to Ethernet device structure. +* @param stats +* Stats structure output buffer. +* +* @return +* 0 on success and stats is filled, +* negative error value otherwise. +*/ +int hinic_dev_stats_get (struct rte_eth_dev *dev,struct rte_eth_stats *stats) +{ +int i, err, q_num; +u64 rx_discards_pmd =0 ; +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct hinic_vport_stats vport_stats; +struct hinic_rxq *rxq =NULL ; +struct hinic_rxq_stats rxq_stats; +struct hinic_txq *txq =NULL ; +struct hinic_txq_stats txq_stats; + + err =hinic_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->proc_dev_name); +return err; + } + + dev->data->rx_mbuf_alloc_failed =0 ; + +/* rx queue stats */ + q_num = (nic_dev->num_rq <RTE_ETHDEV_QUEUE_STAT_CNTRS ) ? + nic_dev->num_rq :RTE_ETHDEV_QUEUE_STAT_CNTRS ; +for (i =0 ; i < q_num; i++) { + rxq = nic_dev->rxqs[i]; +hinic_rxq_get_stats (rxq, &rxq_stats); + stats->q_ipackets[i] = rxq_stats.packets; + stats->q_ibytes[i] = rxq_stats.bytes; + stats->q_errors[i] = rxq_stats.rx_discards; + + stats->ierrors += rxq_stats.errors; + rx_discards_pmd += rxq_stats.rx_discards; + dev->data->rx_mbuf_alloc_failed += rxq_stats.rx_nombuf; + } + +/* tx queue stats */ + q_num = (nic_dev->num_sq <RTE_ETHDEV_QUEUE_STAT_CNTRS ) ? + nic_dev->num_sq :RTE_ETHDEV_QUEUE_STAT_CNTRS ; +for (i =0 ; i < q_num; i++) { + txq = nic_dev->txqs[i]; +hinic_txq_get_stats (txq, &txq_stats); + stats->q_opackets[i] = txq_stats.packets; + stats->q_obytes[i] = txq_stats.bytes; + stats->oerrors += (txq_stats.tx_busy + txq_stats.off_errs); + } + +/* 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 ; +} + +/** +* DPDK callback to clear device statistics. +* +* @param dev +* Pointer to Ethernet device structure. +*/ +void hinic_dev_stats_reset (struct rte_eth_dev *dev) +{ +int qid; +struct hinic_rxq *rxq =NULL ; +struct hinic_txq *txq =NULL ; +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +hinic_clear_vport_stats (nic_dev->hwdev); + +for (qid =0 ; qid < nic_dev->num_rq; qid++) { + rxq = nic_dev->rxqs[qid]; +hinic_rxq_stats_reset (rxq); + } + +for (qid =0 ; qid < nic_dev->num_sq; qid++) { + txq = nic_dev->txqs[qid]; +hinic_txq_stats_reset (txq); + } +} + +/** +* DPDK callback to clear device extended statistics. +* +* @param dev +* Pointer to Ethernet device structure. +**/ +void hinic_dev_xstats_reset (struct rte_eth_dev *dev) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +hinic_dev_stats_reset (dev); + +if (hinic_func_type (nic_dev->hwdev) !=TYPE_VF ) +hinic_clear_phy_port_stats (nic_dev->hwdev); +} + +static void hinic_gen_random_mac_addr (struct rte_ether_addr *mac_addr) +{ +uint64_t random_value; + +/* Set Organizationally Unique Identifier (OUI) prefix */ + mac_addr->addr_bytes[0 ] =0x00 ; + mac_addr->addr_bytes[1 ] =0x09 ; + mac_addr->addr_bytes[2 ] =0xC0 ; +/* Force indication of locally assigned MAC address. */ + mac_addr->addr_bytes[0 ] |=RTE_ETHER_LOCAL_ADMIN_ADDR ; +/* Generate the last 3 bytes of the MAC address with a random number. */ + random_value =rte_rand (); +memcpy (&mac_addr->addr_bytes[3 ], &random_value,3 ); +} + +/** +* Init mac_vlan table in NIC. +* +* @param dev +* Pointer to Ethernet device structure. +* +* @return +* 0 on success and stats is filled, +* negative error value otherwise. +*/ +static int hinic_init_mac_addr (struct rte_eth_dev *eth_dev) +{ +struct hinic_nic_dev *nic_dev = +HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +uint8_t addr_bytes[RTE_ETHER_ADDR_LEN ]; +u16 func_id =0 ; +int rc =0 ; + + rc =hinic_get_default_mac (nic_dev->hwdev, addr_bytes); +if (rc) +return rc; + +memmove (eth_dev->data->mac_addrs->addr_bytes, + addr_bytes,RTE_ETHER_ADDR_LEN ); + +if (rte_is_zero_ether_addr (eth_dev->data->mac_addrs)) +hinic_gen_random_mac_addr (eth_dev->data->mac_addrs); + + func_id =hinic_global_func_id (nic_dev->hwdev); + rc =hinic_set_mac (nic_dev->hwdev, eth_dev->data->mac_addrs->addr_bytes, +0 , func_id); +if (rc && rc !=HINIC_PF_SET_VF_ALREADY ) +return rc; + +return 0 ; +} + +/** +* Deinit mac_vlan table in NIC. +* +* @param dev +* Pointer to Ethernet device structure. +* +* @return +* 0 on success and stats is filled, +* negative error value otherwise. +*/ +static void hinic_deinit_mac_addr (struct rte_eth_dev *eth_dev) +{ +struct hinic_nic_dev *nic_dev = +HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (eth_dev); +int rc; +u16 func_id =0 ; + +if (rte_is_zero_ether_addr (eth_dev->data->mac_addrs)) +return ; + + func_id =hinic_global_func_id (nic_dev->hwdev); + rc =hinic_del_mac (nic_dev->hwdev, + eth_dev->data->mac_addrs->addr_bytes, +0 , func_id); +if (rc && rc !=HINIC_PF_SET_VF_ALREADY ) +PMD_DRV_LOG (ERR ,"Delete mac table failed, dev_name: %s" , + eth_dev->data->name); +} + +/** +* DPDK callback to retrieve physical link information. +* +* @param dev +* Pointer to Ethernet device structure. +* @param wait_to_complete +* Wait for request completion. +* +* @return +* 0 link status changed, -1 link status not changed +*/ +int hinic_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 */ +int rc =HINIC_OK ; +struct rte_eth_link new_link, old_link; +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +unsigned int rep_cnt =MAX_REPEAT_TIME ; + +memset (&old_link,0 ,sizeof (old_link)); +memset (&new_link,0 ,sizeof (new_link)); +rte_eth_linkstatus_get (dev, &old_link); + +do { +/* Get link status information from hardware */ + rc =hinic_priv_get_dev_link_status (nic_dev, &new_link); +if (rc !=HINIC_OK ) { + new_link.link_speed =ETH_SPEED_NUM_NONE ; + new_link.link_duplex =ETH_LINK_FULL_DUPLEX ; +PMD_DRV_LOG (ERR ,"Get link status failed" ); + goto out; + } + +if (!wait_to_complete) +break ; + +rte_delay_ms (CHECK_INTERVAL ); + }while (!new_link.link_status && rep_cnt--); + +out: + (void )rte_eth_linkstatus_set (dev, &new_link); + +if (old_link.link_status == new_link.link_status) +return HINIC_ERROR ; + +PMD_DRV_LOG (INFO ,"Device %s link status change from %s to %s" , + nic_dev->proc_dev_name, + (old_link.link_status ?"UP" :"DOWN" ), + (new_link.link_status ?"UP" :"DOWN" )); + +return HINIC_OK ; +} + +/** +* DPDK callback to enable promiscuous mode. +* +* @param dev +* Pointer to Ethernet device structure. +*/ +void hinic_dev_promiscuous_enable (struct rte_eth_dev *dev) +{ +int rc =HINIC_OK ; +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +PMD_DRV_LOG (INFO ,"Enable promiscuous, nic_dev: %s, port_id: %d, promisc: %d" , + nic_dev->proc_dev_name, dev->data->port_id, + dev->data->promiscuous); + + rc =hinic_set_dev_promiscuous (nic_dev, true); +if (rc) +PMD_DRV_LOG (ERR ,"Enable promiscuous failed" ); +} + +/** +* DPDK callback to disable promiscuous mode. +* +* @param dev +* Pointer to Ethernet device structure. +*/ +void hinic_dev_promiscuous_disable (struct rte_eth_dev *dev) +{ +int rc =HINIC_OK ; +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + +PMD_DRV_LOG (INFO ,"Disable promiscuous, nic_dev: %s, port_id: %d, promisc: %d" , + nic_dev->proc_dev_name, dev->data->port_id, + dev->data->promiscuous); + + rc =hinic_set_dev_promiscuous (nic_dev, false); +if (rc) +PMD_DRV_LOG (ERR ,"Disable promiscuous failed" ); +} + +/** +* DPDK callback to update the RSS hash key and RSS hash type. +* +* @param dev +* Pointer to Ethernet device structure. +* @param rss_conf +* RSS configuration data. +* +* @return +* 0 on success, negative error value otherwise. +*/ +int hinic_rss_hash_update (struct rte_eth_dev *dev, +struct rte_eth_rss_conf *rss_conf) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u8 tmpl_idx = nic_dev->rss_tmpl_idx; +u8 hashkey[HINIC_RSS_KEY_SIZE ] = {0 }; +u8 prio_tc[HINIC_DCB_UP_MAX ] = {0 }; +u64 rss_hf = rss_conf->rss_hf; +struct nic_rss_type rss_type = {0 }; +int err =0 ; + +PMD_DRV_LOG (INFO ,"rss info, rss_flag:0x%x, rss_key_len:%d, rss_hf:%lu, tmpl_idx:%d" , + nic_dev->flags, rss_conf->rss_key_len, rss_hf, tmpl_idx); + +if (!(nic_dev->flags Ð_MQ_RX_RSS_FLAG )) { +PMD_DRV_LOG (INFO ,"RSS is not enabled" ); +return HINIC_OK ; + } + +if (rss_conf->rss_key_len >HINIC_RSS_KEY_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid rss key, rss_key_len:%d" , + rss_conf->rss_key_len); +return HINIC_ERROR ; + } + +if (rss_conf->rss_key) { +memcpy (hashkey, rss_conf->rss_key, rss_conf->rss_key_len); + err =hinic_rss_set_template_tbl (nic_dev->hwdev, tmpl_idx, + hashkey); +if (err) { +PMD_DRV_LOG (ERR ,"Set rss template table failed" ); + goto disable_rss; + } + } + + rss_type.ipv4 = (rss_hf & (ETH_RSS_IPV4 |ETH_RSS_FRAG_IPV4 )) ?1 :0 ; + rss_type.tcp_ipv4 = (rss_hf Ð_RSS_NONFRAG_IPV4_TCP ) ?1 :0 ; + rss_type.ipv6 = (rss_hf & (ETH_RSS_IPV6 |ETH_RSS_FRAG_IPV6 )) ?1 :0 ; + rss_type.ipv6_ext = (rss_hf Ð_RSS_IPV6_EX ) ?1 :0 ; + rss_type.tcp_ipv6 = (rss_hf Ð_RSS_NONFRAG_IPV6_TCP ) ?1 :0 ; + rss_type.tcp_ipv6_ext = (rss_hf Ð_RSS_IPV6_TCP_EX ) ?1 :0 ; + rss_type.udp_ipv4 = (rss_hf Ð_RSS_NONFRAG_IPV4_UDP ) ?1 :0 ; + rss_type.udp_ipv6 = (rss_hf Ð_RSS_NONFRAG_IPV6_UDP ) ?1 :0 ; + + err =hinic_set_rss_type (nic_dev->hwdev, tmpl_idx, rss_type); +if (err) { +PMD_DRV_LOG (ERR ,"Set rss type table failed" ); + goto disable_rss; + } + +return 0 ; + +disable_rss: +memset (prio_tc,0 ,sizeof (prio_tc)); + (void )hinic_rss_cfg (nic_dev->hwdev,0 , tmpl_idx,0 , prio_tc); +return err; +} + +/** +* DPDK callback to get the RSS hash configuration. +* +* @param dev +* Pointer to Ethernet device structure. +* @param rss_conf +* RSS configuration data. +* +* @return +* 0 on success, negative error value otherwise. +*/ +int hinic_rss_conf_get (struct rte_eth_dev *dev, +struct rte_eth_rss_conf *rss_conf) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u8 tmpl_idx = nic_dev->rss_tmpl_idx; +u8 hashkey[HINIC_RSS_KEY_SIZE ] = {0 }; +struct nic_rss_type rss_type = {0 }; +int err; + +if (!(nic_dev->flags Ð_MQ_RX_RSS_FLAG )) { +PMD_DRV_LOG (INFO ,"RSS is not enabled" ); +return HINIC_ERROR ; + } + + err =hinic_rss_get_template_tbl (nic_dev->hwdev, tmpl_idx, hashkey); +if (err) +return err; + +if (rss_conf->rss_key && + rss_conf->rss_key_len >=HINIC_RSS_KEY_SIZE ) { +memcpy (rss_conf->rss_key, hashkey,sizeof (hashkey)); + rss_conf->rss_key_len =sizeof (hashkey); + } + + err =hinic_get_rss_type (nic_dev->hwdev, tmpl_idx, &rss_type); +if (err) +return err; + + rss_conf->rss_hf =0 ; + rss_conf->rss_hf |= rss_type.ipv4 ? + (ETH_RSS_IPV4 |ETH_RSS_FRAG_IPV4 ) :0 ; + rss_conf->rss_hf |= rss_type.tcp_ipv4 ?ETH_RSS_NONFRAG_IPV4_TCP :0 ; + rss_conf->rss_hf |= rss_type.ipv6 ? + (ETH_RSS_IPV6 |ETH_RSS_FRAG_IPV6 ) :0 ; + rss_conf->rss_hf |= rss_type.ipv6_ext ?ETH_RSS_IPV6_EX :0 ; + rss_conf->rss_hf |= rss_type.tcp_ipv6 ?ETH_RSS_NONFRAG_IPV6_TCP :0 ; + rss_conf->rss_hf |= rss_type.tcp_ipv6_ext ?ETH_RSS_IPV6_TCP_EX :0 ; + rss_conf->rss_hf |= rss_type.udp_ipv4 ?ETH_RSS_NONFRAG_IPV4_UDP :0 ; + rss_conf->rss_hf |= rss_type.udp_ipv6 ?ETH_RSS_NONFRAG_IPV6_UDP :0 ; + +return HINIC_OK ; +} + +/** +* DPDK callback to update the RETA indirection table. +* +* @param dev +* Pointer to Ethernet device structure. +* @param reta_conf +* Pointer to RETA configuration structure array. +* @param reta_size +* Size of the RETA table. +* +* @return +* 0 on success, negative error value otherwise. +*/ +int hinic_rss_indirtbl_update (struct rte_eth_dev *dev, +struct rte_eth_rss_reta_entry64 *reta_conf, +uint16_t reta_size) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u8 tmpl_idx = nic_dev->rss_tmpl_idx; +u8 prio_tc[HINIC_DCB_UP_MAX ] = {0 }; +u32 indirtbl[NIC_RSS_INDIR_SIZE ] = {0 }; +int err =0 ; +u16 i =0 ; +u16 idx, shift; + +PMD_DRV_LOG (INFO ,"Update indirect table, rss_flag:0x%x, reta_size:%d, tmpl_idx:%d" , + nic_dev->flags, reta_size, tmpl_idx); + +if (!(nic_dev->flags Ð_MQ_RX_RSS_FLAG )) +return HINIC_OK ; + +if (reta_size !=NIC_RSS_INDIR_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid reta size, reta_size:%d" , reta_size); +return HINIC_ERROR ; + } + + err =hinic_rss_get_indir_tbl (nic_dev->hwdev, tmpl_idx, indirtbl); +if (err) +return err; + +/* update rss indir_tbl */ +for (i =0 ; i < reta_size; i++) { + idx = i /RTE_RETA_GROUP_SIZE ; + shift = i %RTE_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_rq) { +PMD_DRV_LOG (ERR ,"Invalid reta entry, index:%d, num_rq:%d" , + i, nic_dev->num_rq); + goto disable_rss; + } + } + + err =hinic_rss_set_indir_tbl (nic_dev->hwdev, tmpl_idx, indirtbl); +if (err) + goto disable_rss; + + nic_dev->rss_indir_flag = true; + +return 0 ; + +disable_rss: +memset (prio_tc,0 ,sizeof (prio_tc)); + (void )hinic_rss_cfg (nic_dev->hwdev,0 , tmpl_idx,0 , prio_tc); + +return HINIC_ERROR ; +} + + +/** +* DPDK callback to get the RETA indirection table. +* +* @param dev +* Pointer to Ethernet device structure. +* @param reta_conf +* Pointer to RETA configuration structure array. +* @param reta_size +* Size of the RETA table. +* +* @return +* 0 on success, negative error value otherwise. +*/ +int hinic_rss_indirtbl_query (struct rte_eth_dev *dev, +struct rte_eth_rss_reta_entry64 *reta_conf, +uint16_t reta_size) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +u8 tmpl_idx = nic_dev->rss_tmpl_idx; +int err =0 ; +u32 indirtbl[NIC_RSS_INDIR_SIZE ] = {0 }; +u16 idx, shift; +u16 i =0 ; + +if (reta_size !=NIC_RSS_INDIR_SIZE ) { +PMD_DRV_LOG (ERR ,"Invalid reta size, reta_size:%d" , reta_size); +return HINIC_ERROR ; + } + + err =hinic_rss_get_indir_tbl (nic_dev->hwdev, tmpl_idx, indirtbl); +if (err) { +PMD_DRV_LOG (ERR ,"Get rss indirect table failed, error:%d" , + err); +return err; + } + +for (i =0 ; i < reta_size; i++) { + idx = i /RTE_RETA_GROUP_SIZE ; + shift = i %RTE_RETA_GROUP_SIZE ; +if (reta_conf[idx].mask & (1ULL << shift)) + reta_conf[idx].reta[shift] = (uint16_t )indirtbl[i]; + } + +return HINIC_OK ; +} + +/** +* DPDK callback to get extended device statistics. +* +* @param dev +* Pointer to Ethernet device. +* @param xstats +* Pointer to rte extended stats table. +* @param n +* The size of the stats table. +* +* @return +* Number of extended stats on success and stats is filled, +* negative error value otherwise. +*/ +int hinic_dev_xstats_get (struct rte_eth_dev *dev, +struct rte_eth_xstat *xstats, +unsigned int n) +{ +u16 qid =0 ; +u32 i; +int err, count; +struct hinic_nic_dev *nic_dev; +struct hinic_phy_port_stats port_stats; +struct hinic_vport_stats vport_stats; +struct hinic_rxq *rxq =NULL ; +struct hinic_rxq_stats rxq_stats; +struct hinic_txq *txq =NULL ; +struct hinic_txq_stats txq_stats; + + nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); + count =hinic_xstats_calc_num (nic_dev); +if ((int )n < count) +return count; + + count =0 ; + +/* Get stats from hinic_rxq_stats */ +for (qid =0 ; qid < nic_dev->num_rq; qid++) { + rxq = nic_dev->rxqs[qid]; +hinic_rxq_get_stats (rxq, &rxq_stats); + +for (i =0 ; i <HINIC_RXQ_XSTATS_NUM ; i++) { + xstats[count].value = + *(uint64_t *)(((char *)&rxq_stats) + + hinic_rxq_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + } + +/* Get stats from hinic_txq_stats */ +for (qid =0 ; qid < nic_dev->num_sq; qid++) { + txq = nic_dev->txqs[qid]; +hinic_txq_get_stats (txq, &txq_stats); + +for (i =0 ; i <HINIC_TXQ_XSTATS_NUM ; i++) { + xstats[count].value = + *(uint64_t *)(((char *)&txq_stats) + + hinic_txq_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + } + +/* Get stats from hinic_vport_stats */ + err =hinic_get_vport_stats (nic_dev->hwdev, &vport_stats); +if (err) +return err; + +for (i =0 ; i <HINIC_VPORT_XSTATS_NUM ; i++) { + xstats[count].value = + *(uint64_t *)(((char *)&vport_stats) + + hinic_vport_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + +/* Get stats from hinic_phy_port_stats */ + err =hinic_get_phy_port_stats (nic_dev->hwdev, &port_stats); +if (err) +return err; + +for (i =0 ; i <HINIC_PHYPORT_XSTATS_NUM ; i++) { + xstats[count].value = *(uint64_t *)(((char *)&port_stats) + + hinic_phyport_stats_strings[i].offset); + xstats[count].id = count; + count++; + } + +return count; +} + +/** +* DPDK callback to retrieve names of extended device statistics +* +* @param dev +* Pointer to Ethernet device structure. +* @param xstats_names +* Buffer to insert names into. +* +* @return +* Number of xstats names. +*/ +int hinic_dev_xstats_get_names (struct rte_eth_dev *dev, +struct rte_eth_xstat_name *xstats_names, + __rte_unused unsigned int limit) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +int count =0 ; +u16 i =0 , q_num; + +if (xstats_names ==NULL ) +return hinic_xstats_calc_num (nic_dev); + +/* get pmd rxq stats */ +for (q_num =0 ; q_num < nic_dev->num_rq; q_num++) { +for (i =0 ; i <HINIC_RXQ_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name), +"rxq%d_%s_pmd" , + q_num, hinic_rxq_stats_strings[i].name); + count++; + } + } + +/* get pmd txq stats */ +for (q_num =0 ; q_num < nic_dev->num_sq; q_num++) { +for (i =0 ; i <HINIC_TXQ_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name), +"txq%d_%s_pmd" , + q_num, hinic_txq_stats_strings[i].name); + count++; + } + } + +/* get vport stats */ +for (i =0 ; i <HINIC_VPORT_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name), +"%s" , + hinic_vport_stats_strings[i].name); + count++; + } + +/* get phy port stats */ +for (i =0 ; i <HINIC_PHYPORT_XSTATS_NUM ; i++) { +snprintf (xstats_names[count].name, +sizeof (xstats_names[count].name), +"%s" , + hinic_phyport_stats_strings[i].name); + count++; + } + +return count; +} + +/** +* DPDK callback to get fw version +* +* @param dev +* Pointer to Ethernet device structure. +* @param fw_version +* Pointer to fw version structure. +* @param fw_size +* Size of fw version. +* +* @return +* Number of xstats names. +*/ +int +hinic_fw_version_get (struct rte_eth_dev *dev,char *fw_version,size_t fw_size) +{ +struct hinic_nic_dev *nic_dev =HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV (dev); +struct hinic_fw_version fw_ver; +int ret; + +memset (&fw_ver,0 ,sizeof (fw_ver)); + ret =hinic_get_fw_version (nic_dev->hwdev, &fw_ver); +if (ret) +return ret; + + ret =snprintf (fw_version, fw_size,"%s" , fw_ver.microcode_ver); + ret +=1 ;/* add the size of '\0' */ +if (fw_size < (u32 )ret) +return ret; +else +return 0 ; +} +RTE_INIT (hinic_init_log) { hinic_logtype =rte_log_register ("pmd.net.hinic" );
drivers/net/hinic/rte_pmd_hinic_version.map new file +4 -0
@@ -0,0 +1,4 @@ +DPDK_19.08 { + + local: *; +};
Signature · 1 line
2.18.0
Re: [dpdk-dev] [PATCH v4 11/11] net/hinic: add support for basic device operations
Quoted 1 line · Ziyang Xuan
Add hinic PMD initialization and ethernet operatioins code.
Hi Xuan,
Previous patches puts the code without enabling them, this last patch registers the PMD with lots of new code, it is hard to review this PMD.
I think "OCTEON TX2" which also submitted this release [1] is good sample of how building the PMD incrementally, feature by feature, can you please check it?
[1] https://patches.dpdk.org/user/todo/dpdk/?series=4848
Quoted 5 lines
Signed-off-by Ziyang Xuan <[email protected]>--- drivers/net/hinic/hinic_pmd_ethdev.c | 2125 +++++++++++++++++++ drivers/net/hinic/rte_pmd_hinic_version.map | 4 +
.map file needs to be added in the patch that adds "hinic/Makefile", otherwise shared build will fail for those patches in between.
<...>
drivers/net/hinic/hinic_pmd_ethdev.c line 31
Quoted 7 lines
drivers/net/hinic/hinic_pmd_ethdev.c +7
-0+ +/* Hinic PMD parameters */ +#define ETH_HINIC_FW_VER "check_fw_version" + +static const char *const valid_params[] = { +ETH_HINIC_FW_VER , +NULL };
Can you please document this devargs in hinic documentation, describe what it does, and perhaps provide a sample command line to use it.
<...>
<...>
drivers/net/hinic/hinic_pmd_ethdev.c line 418
Quoted 7 lines
drivers/net/hinic/hinic_pmd_ethdev.c +7
-0+snprintf (nic_dev->proc_dev_name, +sizeof (nic_dev->proc_dev_name), +"hinic-%.4x:%.2x:%.2x.%x" , + pci_dev->addr.domain, pci_dev->addr.bus, + pci_dev->addr.devid, pci_dev->addr.function); + +rte_eth_copy_pci_info (eth_dev, pci_dev);
You may not need this, can you please double check?
drivers/net/hinic/hinic_pmd_ethdev.c line 421
Quoted 3 lines
drivers/net/hinic/hinic_pmd_ethdev.c +3
-0+ +/* clear RX ring mbuf allocated failed */ + eth_dev->data->rx_mbuf_alloc_failed =0 ;
At this stage all ethdev->data should be 0, is this assignment required?
<...>
drivers/net/hinic/hinic_pmd_ethdev.c line 1325
Quoted 8 lines
drivers/net/hinic/hinic_pmd_ethdev.c +8
-0+/** +* DPDK callback to close the device. +* +* @param dev +* Pointer to Ethernet device structure. +*/ +void hinic_dev_close (struct rte_eth_dev *dev) +{
You may want to 'RTE_ETH_DEV_CLOSE_REMOVE' flag to cause 'rte_eth_dev_close()' clean ethdev resources clean, please check other PMDs and ethdev API for sample usage.