net: hinic3: Add a driver for Huawei 3rd gen NIC - part 2
Subsystems (4)
Fan Gong
maintainerv3 cover net: hinic3: Add a driver for Huawei 3rd gen NIC - part 2
This is the 2/3 patch of the patch-set described below.
The patch-set contains driver for Huawei's 3rd generation HiNIC Ethernet device that will be available in the future.
This is an SRIOV device, designed for data centers. Initially, the driver only supports VFs.
Following the discussion over RFC01, the code will be submitted in separate smaller patches where until the last patch the driver is non-functional. The RFC02 submission contains overall view of the entire driver but every patch will be posted as a standalone submission.
Changes:
PATCH 02 V01: https://lore.kernel.org/netdev/[email protected]
PATCH 02 V02: https://lore.kernel.org/netdev/[email protected]
* Fix build allmodconfig warning (patchwork)
* Update cover-letter changes information.
PATCH 02 V03:
* Use refcount_*() instead of atomic_*() (Jakub Kicinski)
* Consistency fixes : HIG->HIGH, BAR45->BAR4/5 , etc (ALOK TIWARI)
* Code format fixes : use \n before return, remove extra spaces (ALOK TIWARI)
* Remove hinic3_request_irq redundant error print (ALOK TIWARI)
* Modify hinic3_wq_create error print (ALOK TIWARI)
Fan Gong (1):
hinic3: management interfaces
drivers/net/ethernet/huawei/hinic3/Makefile | 4 +- .../net/ethernet/huawei/hinic3/hinic3_cmdq.c | 912 ++++++++++++++++++ .../net/ethernet/huawei/hinic3/hinic3_cmdq.h | 156 +++ .../ethernet/huawei/hinic3/hinic3_common.c | 31 + .../ethernet/huawei/hinic3/hinic3_common.h | 27 + .../net/ethernet/huawei/hinic3/hinic3_csr.h | 79 ++ .../net/ethernet/huawei/hinic3/hinic3_eqs.c | 803 +++++++++++++++ .../net/ethernet/huawei/hinic3/hinic3_eqs.h | 130 +++ .../ethernet/huawei/hinic3/hinic3_hw_cfg.c | 43 + .../ethernet/huawei/hinic3/hinic3_hw_comm.c | 31 + .../ethernet/huawei/hinic3/hinic3_hw_comm.h | 13 + .../ethernet/huawei/hinic3/hinic3_hw_intf.h | 36 + .../net/ethernet/huawei/hinic3/hinic3_hwif.c | 153 ++- .../net/ethernet/huawei/hinic3/hinic3_hwif.h | 16 + .../net/ethernet/huawei/hinic3/hinic3_irq.c | 137 ++- .../net/ethernet/huawei/hinic3/hinic3_lld.c | 5 + .../net/ethernet/huawei/hinic3/hinic3_main.c | 65 +- .../net/ethernet/huawei/hinic3/hinic3_mbox.c | 843 +++++++++++++++- .../net/ethernet/huawei/hinic3/hinic3_mbox.h | 127 +++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 2 + .../ethernet/huawei/hinic3/hinic3_nic_dev.h | 14 +- .../huawei/hinic3/hinic3_queue_common.h | 1 + .../net/ethernet/huawei/hinic3/hinic3_tx.c | 2 + .../net/ethernet/huawei/hinic3/hinic3_wq.c | 109 +++ .../net/ethernet/huawei/hinic3/hinic3_wq.h | 11 + 25 files changed, 3735 insertions(+), 15 deletions(-) create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_cmdq.c create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_cmdq.h create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_csr.h create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_eqs.c create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_eqs.h
base-commit: 8909f5f4ecd551c2299b28e05254b77424c8c7dc
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v3 1/1 hinic3: management interfaces
This is [2/3] part of hinic3 Ethernet driver initial submission. With this patch hinic3 is a valid kernel module but non-functional driver.
The driver parts contained in this patch:
Mailbox management interface.
Command queue management interface.
Event queues, AEQ and CEQ upon which management relies. Some of thew IRQ implementation but without full initialization yet.
--- drivers/net/ethernet/huawei/hinic3/Makefile | 4 +- .../net/ethernet/huawei/hinic3/hinic3_cmdq.c | 912 ++++++++++++++++++ .../net/ethernet/huawei/hinic3/hinic3_cmdq.h | 156 +++ .../ethernet/huawei/hinic3/hinic3_common.c | 31 + .../ethernet/huawei/hinic3/hinic3_common.h | 27 + .../net/ethernet/huawei/hinic3/hinic3_csr.h | 79 ++ .../net/ethernet/huawei/hinic3/hinic3_eqs.c | 803 +++++++++++++++ .../net/ethernet/huawei/hinic3/hinic3_eqs.h | 130 +++ .../ethernet/huawei/hinic3/hinic3_hw_cfg.c | 43 + .../ethernet/huawei/hinic3/hinic3_hw_comm.c | 31 + .../ethernet/huawei/hinic3/hinic3_hw_comm.h | 13 + .../ethernet/huawei/hinic3/hinic3_hw_intf.h | 36 + .../net/ethernet/huawei/hinic3/hinic3_hwif.c | 153 ++- .../net/ethernet/huawei/hinic3/hinic3_hwif.h | 16 + .../net/ethernet/huawei/hinic3/hinic3_irq.c | 137 ++- .../net/ethernet/huawei/hinic3/hinic3_lld.c | 5 + .../net/ethernet/huawei/hinic3/hinic3_main.c | 65 +- .../net/ethernet/huawei/hinic3/hinic3_mbox.c | 843 +++++++++++++++- .../net/ethernet/huawei/hinic3/hinic3_mbox.h | 127 +++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 2 + .../ethernet/huawei/hinic3/hinic3_nic_dev.h | 14 +- .../huawei/hinic3/hinic3_queue_common.h | 1 + .../net/ethernet/huawei/hinic3/hinic3_tx.c | 2 + .../net/ethernet/huawei/hinic3/hinic3_wq.c | 109 +++ .../net/ethernet/huawei/hinic3/hinic3_wq.h | 11 + 25 files changed, 3735 insertions(+), 15 deletions(-)
drivers/net/ethernet/huawei/hinic3/Makefile +3 -1
@@ -3,7 +3,9 @@ obj-$(CONFIG_HINIC3) += hinic3.o -hinic3-objs := hinic3_common.o \ +hinic3-objs := hinic3_cmdq.o \ + hinic3_common.o \ + hinic3_eqs.o \ hinic3_hw_cfg.o \ hinic3_hw_comm.o \ hinic3_hwdev.o \
drivers/net/ethernet/huawei/hinic3/hinic3_cmdq.c new file +912 -0
912 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_cmdq.h new file +156 -0
156 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_common.c +31 -0
@@ -3,6 +3,7 @@#include <linux/delay.h> #include <linux/dma-mapping.h> +#include <linux/iopoll.h> #include "hinic3_common.h"
@@ -51,3 +52,33 @@ void hinic3_dma_free_coherent_align(struct device *dev,dma_free_coherent (dev, mem_align->real_size, mem_align->ori_vaddr, mem_align->ori_paddr); } + +int hinic3_wait_for_timeout (void *priv_data,wait_cpl_handler handler, +u32 wait_total_ms,u32 wait_once_us) +{ +enum hinic3_wait_return ret; +int err; + + err =read_poll_timeout (handler, ret, ret ==HINIC3_WAIT_PROCESS_CPL , + wait_once_us, wait_total_ms *USEC_PER_MSEC , + false, priv_data); + +return err; +} + +/* Data provided to/by cmdq is arranged in structs with little endian fields but +* every dword (32bits) should be swapped since HW swaps it again when it +* copies it from/to host memory. This is a mandatory swap regardless of the +* CPU endianness. +*/ +void hinic3_cmdq_buf_swab32 (void *data,int len) +{ +int i, chunk_sz =sizeof (u32); +int data_len = len; +u32 *mem = data; + + data_len = data_len / chunk_sz; + +for (i =0 ; i < data_len; i++) + mem[i] =swab32 (mem[i]); +}
drivers/net/ethernet/huawei/hinic3/hinic3_common.h +27 -0
@@ -18,10 +18,37 @@ struct hinic3_dma_addr_align {dma_addr_t align_paddr; }; +enum hinic3_wait_return { +HINIC3_WAIT_PROCESS_CPL =0 , +HINIC3_WAIT_PROCESS_WAITING =1 , +}; + +struct hinic3_sge { +u32 hi_addr; +u32 lo_addr; +u32 len; +u32 rsvd; +}; + +static inline void hinic3_set_sge (struct hinic3_sge *sge,dma_addr_t addr, +int len) +{ + sge->hi_addr =upper_32_bits (addr); + sge->lo_addr =lower_32_bits (addr); + sge->len = len; + sge->rsvd =0 ; +} +int hinic3_dma_zalloc_coherent_align (struct device *dev,u32 size,u32 align,gfp_t flag,struct hinic3_dma_addr_align *mem_align);void hinic3_dma_free_coherent_align (struct device *dev,struct hinic3_dma_addr_align *mem_align); +typedef enum hinic3_wait_return (*wait_cpl_handler )(void *priv_data); +int hinic3_wait_for_timeout (void *priv_data,wait_cpl_handler handler, +u32 wait_total_ms,u32 wait_once_us); + +void hinic3_cmdq_buf_swab32 (void *data,int len); +#endif
drivers/net/ethernet/huawei/hinic3/hinic3_csr.h new file +79 -0
79 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_eqs.c new file +803 -0
803 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_eqs.h new file +130 -0
130 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.c +43 -0
49 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.c +31 -0
@@ -8,6 +8,37 @@#include "hinic3_hwif.h" #include "hinic3_mbox.h" +int hinic3_set_interrupt_cfg_direct (struct hinic3_hwdev *hwdev, +const struct hinic3_interrupt_info *info) +{ +struct comm_cmd_cfg_msix_ctrl_reg msix_cfg = {}; +struct mgmt_msg_params msg_params = {}; +int err; + + msix_cfg.func_id =hinic3_global_func_id (hwdev); + msix_cfg.msix_index = info->msix_index; + msix_cfg.opcode =MGMT_MSG_CMD_OP_SET ; + + msix_cfg.lli_credit_cnt = info->lli_credit_limit; + msix_cfg.lli_timer_cnt = info->lli_timer_cfg; + msix_cfg.pending_cnt = info->pending_limit; + msix_cfg.coalesce_timer_cnt = info->coalesc_timer_cfg; + msix_cfg.resend_timer_cnt = info->resend_timer_cfg; + +mgmt_msg_params_init_default (&msg_params, &msix_cfg,sizeof (msix_cfg)); + + err =hinic3_send_mbox_to_mgmt (hwdev,MGMT_MOD_COMM , +COMM_CMD_CFG_MSIX_CTRL_REG , &msg_params); +if (err || msix_cfg.head.status) { +dev_err (hwdev->dev, +"Failed to set interrupt config, err: %d, status: 0x%x\n" , + err, msix_cfg.head.status); +return -EINVAL ; + } + +return 0 ; +} +int hinic3_func_reset (struct hinic3_hwdev *hwdev,u16 func_id,u64 reset_flag) {struct comm_cmd_func_reset func_reset = {};
drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.h +13 -0
@@ -8,6 +8,19 @@struct hinic3_hwdev ; +struct hinic3_interrupt_info { +u32 lli_set; +u32 interrupt_coalesc_set; +u16 msix_index; +u8 lli_credit_limit; +u8 lli_timer_cfg; +u8 pending_limit; +u8 coalesc_timer_cfg; +u8 resend_timer_cfg; +}; + +int hinic3_set_interrupt_cfg_direct (struct hinic3_hwdev *hwdev, +const struct hinic3_interrupt_info *info);int hinic3_func_reset (struct hinic3_hwdev *hwdev,u16 func_id,u64 reset_flag);#endif
drivers/net/ethernet/huawei/hinic3/hinic3_hw_intf.h +36 -0
@@ -70,6 +70,20 @@ enum comm_cmd { COMM_CMD_SET_DMA_ATTR = 25, }; +struct comm_cmd_cfg_msix_ctrl_reg { +struct mgmt_msg_head head; +u16 func_id; +u8 opcode; +u8 rsvd1; +u16 msix_index; +u8 pending_cnt; +u8 coalesce_timer_cnt; +u8 resend_timer_cnt; +u8 lli_timer_cnt; +u8 lli_credit_cnt; +u8 rsvd2[5 ]; +}; +enum comm_func_reset_bits {COMM_FUNC_RESET_BIT_FLUSH =BIT (0 ),COMM_FUNC_RESET_BIT_MQM =BIT (1 ),
@@ -100,6 +114,28 @@ struct comm_cmd_feature_nego {u64 s_feature[COMM_MAX_FEATURE_QWORD ]; }; +struct comm_cmd_set_ceq_ctrl_reg { +struct mgmt_msg_head head; +u16 func_id; +u16 q_id; +u32 ctrl0; +u32 ctrl1; +u32 rsvd1; +}; + +struct comm_cmdq_ctxt_info { +u64 curr_wqe_page_pfn; +u64 wq_block_pfn; +}; + +struct comm_cmd_set_cmdq_ctxt { +struct mgmt_msg_head head; +u16 func_id; +u8 cmdq_id; +u8 rsvd1[5 ]; +struct comm_cmdq_ctxt_info ctxt; +}; +/* Services supported by HW. HW uses these values when delivering events. * HW supports multiple services that are not yet supported by driver * (e.g. RoCE).
drivers/net/ethernet/huawei/hinic3/hinic3_hwif.c +152 -1
165 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_hwif.h +16 -0
@@ -50,8 +50,24 @@ enum hinic3_msix_state { HINIC3_MSIX_DISABLE, }; +enum hinic3_msix_auto_mask { +HINIC3_CLR_MSIX_AUTO_MASK , +HINIC3_SET_MSIX_AUTO_MASK , +}; + +u32 hinic3_hwif_read_reg (struct hinic3_hwif *hwif,u32 reg); +void hinic3_hwif_write_reg (struct hinic3_hwif *hwif,u32 reg,u32 val); + +int hinic3_alloc_db_addr (struct hinic3_hwdev *hwdev,void __iomem **db_base, +void __iomem **dwqe_base); +void hinic3_free_db_addr (struct hinic3_hwdev *hwdev,const u8 __iomem *db_base); +void hinic3_set_msix_state (struct hinic3_hwdev *hwdev,u16 msix_idx,enum hinic3_msix_state flag); +void hinic3_msix_intr_clear_resend_bit (struct hinic3_hwdev *hwdev,u16 msix_idx, +u8 clear_resend_en); +void hinic3_set_msix_auto_mask_state (struct hinic3_hwdev *hwdev,u16 msix_idx, +enum hinic3_msix_auto_mask flag);u16 hinic3_global_func_id (struct hinic3_hwdev *hwdev);
drivers/net/ethernet/huawei/hinic3/hinic3_irq.c +135 -2
152 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_lld.c +5 -0
@@ -121,6 +121,7 @@ static int hinic3_attach_aux_devices(struct hinic3_hwdev *hwdev) goto err_del_adevs; }mutex_unlock (&pci_adapter->pdev_mutex); +return 0 ; err_del_adevs:
@@ -132,6 +133,7 @@ static int hinic3_attach_aux_devices(struct hinic3_hwdev *hwdev) } }mutex_unlock (&pci_adapter->pdev_mutex); +return -ENOMEM ; }
@@ -153,6 +155,7 @@ struct hinic3_hwdev *hinic3_adev_get_hwdev(struct auxiliary_device *adev)struct hinic3_adev *hadev; hadev = container_of(adev, struct hinic3_adev, adev); +return hadev->hwdev; }
@@ -333,6 +336,7 @@ static int hinic3_probe_func(struct hinic3_pcidev *pci_adapter) err_out:dev_err (&pdev->dev,"PCIe device probe function failed\n" ); +return err; }
@@ -365,6 +369,7 @@ static int hinic3_probe(struct pci_dev *pdev, const struct pci_device_id *id) err_out:dev_err (&pdev->dev,"PCIe device probe failed\n" ); +return err; }
drivers/net/ethernet/huawei/hinic3/hinic3_main.c +60 -5
86 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c +841 -2
218 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_mbox.h +127 -0
127 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c +2 -0
Lines of this file are not shown. View the raw message.
drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h +10 -4
Lines of this file are not shown. View the raw message.
drivers/net/ethernet/huawei/hinic3/hinic3_queue_common.h +1 -0
Lines of this file are not shown. View the raw message.
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +2 -0
Lines of this file are not shown. View the raw message.
drivers/net/ethernet/huawei/hinic3/hinic3_wq.c +109 -0
109 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_wq.h +11 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.43.0
Part of the diff is not shown here. View the raw message.
Jakub Kicinski
maintainerRe: [PATCH net-next v03 1/1] hinic3: management interfaces
Quoted 1 line · On Mon, 16 Jun 2025 15:27:50 +0800 Fan Gong wrote:
25 files changed, 3735 insertions(+), 15 deletions(-)
Break it up into smaller patches, please.
Signature · 1 line
pw-bot: cr