Skip to content

Commit 17fcb3d

Browse files
Fan Gongkuba-moo
authored andcommitted
hinic3: module initialization and tx/rx logic
This is [1/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: Module initialization. PCI driver registration but with empty id_table. Auxiliary driver registration. Net device_ops registration but open/stop are empty stubs. tx/rx logic. All major data structures of the driver are fully introduced with the code that uses them but without their initialization code that requires management interface with the hw. Co-developed-by: Xin Guo <guoxin09@huawei.com> Signed-off-by: Xin Guo <guoxin09@huawei.com> Signed-off-by: Fan Gong <gongfan1@huawei.com> Co-developed-by: Gur Stavi <gur.stavi@huawei.com> Signed-off-by: Gur Stavi <gur.stavi@huawei.com> Link: https://patch.msgid.link/76a137ffdfe115c737c2c224f0c93b60ba53cc16.1747736586.git.gur.stavi@huawei.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent bd15b2b commit 17fcb3d

40 files changed

+3726
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=====================================================================
4+
Linux kernel driver for Huawei Ethernet Device Driver (hinic3) family
5+
=====================================================================
6+
7+
Overview
8+
========
9+
10+
The hinic3 is a network interface card (NIC) for Data Center. It supports
11+
a range of link-speed devices (10GE, 25GE, 100GE, etc.). The hinic3
12+
devices can have multiple physical forms: LOM (Lan on Motherboard) NIC,
13+
PCIe standard NIC, OCP (Open Compute Project) NIC, etc.
14+
15+
The hinic3 driver supports the following features:
16+
- IPv4/IPv6 TCP/UDP checksum offload
17+
- TSO (TCP Segmentation Offload), LRO (Large Receive Offload)
18+
- RSS (Receive Side Scaling)
19+
- MSI-X interrupt aggregation configuration and interrupt adaptation.
20+
- SR-IOV (Single Root I/O Virtualization).
21+
22+
Content
23+
=======
24+
25+
- Supported PCI vendor ID/device IDs
26+
- Source Code Structure of Hinic3 Driver
27+
- Management Interface
28+
29+
Supported PCI vendor ID/device IDs
30+
==================================
31+
32+
19e5:0222 - hinic3 PF/PPF
33+
19e5:375F - hinic3 VF
34+
35+
Prime Physical Function (PPF) is responsible for the management of the
36+
whole NIC card. For example, clock synchronization between the NIC and
37+
the host. Any PF may serve as a PPF. The PPF is selected dynamically.
38+
39+
Source Code Structure of Hinic3 Driver
40+
======================================
41+
42+
======================== ================================================
43+
hinic3_pci_id_tbl.h Supported device IDs
44+
hinic3_hw_intf.h Interface between HW and driver
45+
hinic3_queue_common.[ch] Common structures and methods for NIC queues
46+
hinic3_common.[ch] Encapsulation of memory operations in Linux
47+
hinic3_csr.h Register definitions in the BAR
48+
hinic3_hwif.[ch] Interface for BAR
49+
hinic3_eqs.[ch] Interface for AEQs and CEQs
50+
hinic3_mbox.[ch] Interface for mailbox
51+
hinic3_mgmt.[ch] Management interface based on mailbox and AEQ
52+
hinic3_wq.[ch] Work queue data structures and interface
53+
hinic3_cmdq.[ch] Command queue is used to post command to HW
54+
hinic3_hwdev.[ch] HW structures and methods abstractions
55+
hinic3_lld.[ch] Auxiliary driver adaptation layer
56+
hinic3_hw_comm.[ch] Interface for common HW operations
57+
hinic3_mgmt_interface.h Interface between firmware and driver
58+
hinic3_hw_cfg.[ch] Interface for HW configuration
59+
hinic3_irq.c Interrupt request
60+
hinic3_netdev_ops.c Operations registered to Linux kernel stack
61+
hinic3_nic_dev.h NIC structures and methods abstractions
62+
hinic3_main.c Main Linux kernel driver
63+
hinic3_nic_cfg.[ch] NIC service configuration
64+
hinic3_nic_io.[ch] Management plane interface for TX and RX
65+
hinic3_rss.[ch] Interface for Receive Side Scaling (RSS)
66+
hinic3_rx.[ch] Interface for transmit
67+
hinic3_tx.[ch] Interface for receive
68+
hinic3_ethtool.c Interface for ethtool operations (ops)
69+
hinic3_filter.c Interface for MAC address
70+
======================== ================================================
71+
72+
Management Interface
73+
====================
74+
75+
Asynchronous Event Queue (AEQ)
76+
------------------------------
77+
78+
AEQ receives high priority events from the HW over a descriptor queue.
79+
Every descriptor is a fixed size of 64 bytes. AEQ can receive solicited or
80+
unsolicited events. Every device, VF or PF, can have up to 4 AEQs.
81+
Every AEQ is associated to a dedicated IRQ. AEQ can receive multiple types
82+
of events, but in practice the hinic3 driver ignores all events except for
83+
2 mailbox related events.
84+
85+
Mailbox
86+
-------
87+
88+
Mailbox is a communication mechanism between the hinic3 driver and the HW.
89+
Each device has an independent mailbox. Driver can use the mailbox to send
90+
requests to management. Driver receives mailbox messages, such as responses
91+
to requests, over the AEQ (using event HINIC3_AEQ_FOR_MBOX). Due to the
92+
limited size of mailbox data register, mailbox messages are sent
93+
segment-by-segment.
94+
95+
Every device can use its mailbox to post request to firmware. The mailbox
96+
can also be used to post requests and responses between the PF and its VFs.
97+
98+
Completion Event Queue (CEQ)
99+
----------------------------
100+
101+
The implementation of CEQ is the same as AEQ. It receives completion events
102+
from HW over a fixed size descriptor of 32 bits. Every device can have up
103+
to 32 CEQs. Every CEQ has a dedicated IRQ. CEQ only receives solicited
104+
events that are responses to requests from the driver. CEQ can receive
105+
multiple types of events, but in practice the hinic3 driver ignores all
106+
events except for HINIC3_CMDQ that represents completion of previously
107+
posted commands on a cmdq.
108+
109+
Command Queue (cmdq)
110+
--------------------
111+
112+
Every cmdq has a dedicated work queue on which commands are posted.
113+
Commands on the work queue are fixed size descriptor of size 64 bytes.
114+
Completion of a command will be indicated using ctrl bits in the
115+
descriptor that carried the command. Notification of command completions
116+
will also be provided via event on CEQ. Every device has 4 command queues
117+
that are initialized as a set (called cmdqs), each with its own type.
118+
Hinic3 driver only uses type HINIC3_CMDQ_SYNC.
119+
120+
Work Queues(WQ)
121+
---------------
122+
123+
Work queues are logical arrays of fixed size WQEs. The array may be spread
124+
over multiple non-contiguous pages using indirection table. Work queues are
125+
used by I/O queues and command queues.
126+
127+
Global function ID
128+
------------------
129+
130+
Every function, PF or VF, has a unique ordinal identification within the device.
131+
Many management commands (mbox or cmdq) contain this ID so HW can apply the
132+
command effect to the right function.
133+
134+
PF is allowed to post management commands to a subordinate VF by specifying the
135+
VFs ID. A VF must provide its own ID. Anti-spoofing in the HW will cause
136+
command from a VF to fail if it contains the wrong ID.
137+

Documentation/networking/device_drivers/ethernet/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Contents:
2828
freescale/gianfar
2929
google/gve
3030
huawei/hinic
31+
huawei/hinic3
3132
intel/e100
3233
intel/e1000
3334
intel/e1000e

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10963,6 +10963,13 @@ S: Maintained
1096310963
F: Documentation/networking/device_drivers/ethernet/huawei/hinic.rst
1096410964
F: drivers/net/ethernet/huawei/hinic/
1096510965

10966+
HUAWEI 3RD GEN ETHERNET DRIVER
10967+
M: Fan Gong <gongfan1@huawei.com>
10968+
L: netdev@vger.kernel.org
10969+
S: Maintained
10970+
F: Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst
10971+
F: drivers/net/ethernet/huawei/hinic3/
10972+
1096610973
HUAWEI MATEBOOK E GO EMBEDDED CONTROLLER DRIVER
1096710974
M: Pengyu Luo <mitltlatltl@gmail.com>
1096810975
S: Maintained

drivers/net/ethernet/huawei/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ config NET_VENDOR_HUAWEI
1616
if NET_VENDOR_HUAWEI
1717

1818
source "drivers/net/ethernet/huawei/hinic/Kconfig"
19+
source "drivers/net/ethernet/huawei/hinic3/Kconfig"
1920

2021
endif # NET_VENDOR_HUAWEI

drivers/net/ethernet/huawei/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
#
55

66
obj-$(CONFIG_HINIC) += hinic/
7+
obj-$(CONFIG_HINIC3) += hinic3/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# Huawei driver configuration
4+
#
5+
6+
config HINIC3
7+
tristate "Huawei 3rd generation network adapters (HINIC3) support"
8+
# Fields of HW and management structures are little endian and are
9+
# currently not converted
10+
depends on !CPU_BIG_ENDIAN
11+
depends on X86 || ARM64 || COMPILE_TEST
12+
depends on PCI_MSI && 64BIT
13+
select AUXILIARY_BUS
14+
select PAGE_POOL
15+
help
16+
This driver supports HiNIC 3rd gen Network Adapter (HINIC3).
17+
The driver is supported on X86_64 and ARM64 little endian.
18+
19+
To compile this driver as a module, choose M here.
20+
The module will be called hinic3.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
3+
4+
obj-$(CONFIG_HINIC3) += hinic3.o
5+
6+
hinic3-objs := hinic3_common.o \
7+
hinic3_hw_cfg.o \
8+
hinic3_hw_comm.o \
9+
hinic3_hwdev.o \
10+
hinic3_hwif.o \
11+
hinic3_irq.o \
12+
hinic3_lld.o \
13+
hinic3_main.o \
14+
hinic3_mbox.o \
15+
hinic3_netdev_ops.o \
16+
hinic3_nic_cfg.o \
17+
hinic3_nic_io.o \
18+
hinic3_queue_common.o \
19+
hinic3_rx.o \
20+
hinic3_tx.o \
21+
hinic3_wq.o
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
3+
4+
#include <linux/delay.h>
5+
#include <linux/dma-mapping.h>
6+
7+
#include "hinic3_common.h"
8+
9+
int hinic3_dma_zalloc_coherent_align(struct device *dev, u32 size, u32 align,
10+
gfp_t flag,
11+
struct hinic3_dma_addr_align *mem_align)
12+
{
13+
dma_addr_t paddr, align_paddr;
14+
void *vaddr, *align_vaddr;
15+
u32 real_size = size;
16+
17+
vaddr = dma_alloc_coherent(dev, real_size, &paddr, flag);
18+
if (!vaddr)
19+
return -ENOMEM;
20+
21+
align_paddr = ALIGN(paddr, align);
22+
if (align_paddr == paddr) {
23+
align_vaddr = vaddr;
24+
goto out;
25+
}
26+
27+
dma_free_coherent(dev, real_size, vaddr, paddr);
28+
29+
/* realloc memory for align */
30+
real_size = size + align;
31+
vaddr = dma_alloc_coherent(dev, real_size, &paddr, flag);
32+
if (!vaddr)
33+
return -ENOMEM;
34+
35+
align_paddr = ALIGN(paddr, align);
36+
align_vaddr = vaddr + (align_paddr - paddr);
37+
38+
out:
39+
mem_align->real_size = real_size;
40+
mem_align->ori_vaddr = vaddr;
41+
mem_align->ori_paddr = paddr;
42+
mem_align->align_vaddr = align_vaddr;
43+
mem_align->align_paddr = align_paddr;
44+
45+
return 0;
46+
}
47+
48+
void hinic3_dma_free_coherent_align(struct device *dev,
49+
struct hinic3_dma_addr_align *mem_align)
50+
{
51+
dma_free_coherent(dev, mem_align->real_size,
52+
mem_align->ori_vaddr, mem_align->ori_paddr);
53+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. */
3+
4+
#ifndef _HINIC3_COMMON_H_
5+
#define _HINIC3_COMMON_H_
6+
7+
#include <linux/device.h>
8+
9+
#define HINIC3_MIN_PAGE_SIZE 0x1000
10+
11+
struct hinic3_dma_addr_align {
12+
u32 real_size;
13+
14+
void *ori_vaddr;
15+
dma_addr_t ori_paddr;
16+
17+
void *align_vaddr;
18+
dma_addr_t align_paddr;
19+
};
20+
21+
int hinic3_dma_zalloc_coherent_align(struct device *dev, u32 size, u32 align,
22+
gfp_t flag,
23+
struct hinic3_dma_addr_align *mem_align);
24+
void hinic3_dma_free_coherent_align(struct device *dev,
25+
struct hinic3_dma_addr_align *mem_align);
26+
27+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
3+
4+
#include <linux/device.h>
5+
6+
#include "hinic3_hw_cfg.h"
7+
#include "hinic3_hwdev.h"
8+
#include "hinic3_hwif.h"
9+
#include "hinic3_mbox.h"
10+
11+
bool hinic3_support_nic(struct hinic3_hwdev *hwdev)
12+
{
13+
return hwdev->cfg_mgmt->cap.supp_svcs_bitmap &
14+
BIT(HINIC3_SERVICE_T_NIC);
15+
}
16+
17+
u16 hinic3_func_max_qnum(struct hinic3_hwdev *hwdev)
18+
{
19+
return hwdev->cfg_mgmt->cap.nic_svc_cap.max_sqs;
20+
}
21+
22+
u8 hinic3_physical_port_id(struct hinic3_hwdev *hwdev)
23+
{
24+
return hwdev->cfg_mgmt->cap.port_id;
25+
}

0 commit comments

Comments
 (0)