Skip to contentSkip to conversation

net: hinic3: Add a driver for Huawei 3rd gen NIC

RFC Superseded Gur Stavi 3 participants 10 messages Dec 12, 2024 – Dec 19, 2024

Subsystems (4)

v2 of 17 Superseded Latest is v17 →

lore
Share & tools
lore

Gur Stavi

author
#0 lore raw

v2 cover net: hinic3: Add a driver for Huawei 3rd gen NIC

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.
This RFC02 is an overall view of the entire driver but every patch will be posted as a standalone submission.

Changes:

V01: https://lore.kernel.org/netdev/[email protected]
* Reduce overall line of code by removing optional functionality.
* Break down into smaller patches.

gongfan (3):
net: hinic3: module initialization and tx/rx logic
net: hinic3: management interfaces
net: hinic3: sw and hw initialization code

 .../device_drivers/ethernet/huawei/hinic3.rst | 136 +++
 MAINTAINERS                                   |   7 +
 drivers/net/ethernet/huawei/Kconfig           |   1 +
 drivers/net/ethernet/huawei/Makefile          |   1 +
 drivers/net/ethernet/huawei/hinic3/Kconfig    |  16 +
 drivers/net/ethernet/huawei/hinic3/Makefile   |  25 +
 .../net/ethernet/huawei/hinic3/hinic3_cmdq.c  | 898 ++++++++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_cmdq.h  | 150 +++
 .../ethernet/huawei/hinic3/hinic3_common.c    |  98 ++
 .../ethernet/huawei/hinic3/hinic3_common.h    |  54 ++
 .../net/ethernet/huawei/hinic3/hinic3_csr.h   |  74 ++
 .../net/ethernet/huawei/hinic3/hinic3_eqs.c   | 786 +++++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_eqs.h   | 128 +++
 .../ethernet/huawei/hinic3/hinic3_hw_cfg.c    | 266 ++++++
 .../ethernet/huawei/hinic3/hinic3_hw_cfg.h    |  62 ++
 .../ethernet/huawei/hinic3/hinic3_hw_comm.c   | 412 ++++++++
 .../ethernet/huawei/hinic3/hinic3_hw_comm.h   |  42 +
 .../ethernet/huawei/hinic3/hinic3_hw_intf.h   | 248 +++++
 .../net/ethernet/huawei/hinic3/hinic3_hwdev.c | 569 +++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_hwdev.h |  82 ++
 .../net/ethernet/huawei/hinic3/hinic3_hwif.c  | 430 +++++++++
 .../net/ethernet/huawei/hinic3/hinic3_hwif.h  |  91 ++
 .../net/ethernet/huawei/hinic3/hinic3_irq.c   | 172 ++++
 .../net/ethernet/huawei/hinic3/hinic3_lld.c   | 417 ++++++++
 .../net/ethernet/huawei/hinic3/hinic3_lld.h   |  20 +
 .../net/ethernet/huawei/hinic3/hinic3_main.c  | 417 ++++++++
 .../net/ethernet/huawei/hinic3/hinic3_mbox.c  | 844 ++++++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_mbox.h  | 147 +++
 .../net/ethernet/huawei/hinic3/hinic3_mgmt.c  |  21 +
 .../net/ethernet/huawei/hinic3/hinic3_mgmt.h  |  14 +
 .../huawei/hinic3/hinic3_mgmt_interface.h     | 212 +++++
 .../huawei/hinic3/hinic3_netdev_ops.c         | 518 ++++++++++
 .../ethernet/huawei/hinic3/hinic3_nic_cfg.c   | 395 ++++++++
 .../ethernet/huawei/hinic3/hinic3_nic_cfg.h   |  76 ++
 .../ethernet/huawei/hinic3/hinic3_nic_dev.h   | 107 +++
 .../ethernet/huawei/hinic3/hinic3_nic_io.c    | 885 +++++++++++++++++
 .../ethernet/huawei/hinic3/hinic3_nic_io.h    | 142 +++
 .../huawei/hinic3/hinic3_pci_id_tbl.h         |  10 +
 .../huawei/hinic3/hinic3_queue_common.c       |  65 ++
 .../huawei/hinic3/hinic3_queue_common.h       |  51 +
 .../net/ethernet/huawei/hinic3/hinic3_rss.c   | 378 ++++++++
 .../net/ethernet/huawei/hinic3/hinic3_rss.h   |  14 +
 .../net/ethernet/huawei/hinic3/hinic3_rx.c    | 620 ++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_rx.h    | 104 ++
 .../net/ethernet/huawei/hinic3/hinic3_tx.c    | 817 ++++++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_tx.h    | 141 +++
 .../net/ethernet/huawei/hinic3/hinic3_wq.c    | 132 +++
 .../net/ethernet/huawei/hinic3/hinic3_wq.h    |  87 ++
 48 files changed, 11382 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst
 create mode 100644 drivers/net/ethernet/huawei/hinic3/Kconfig
 create mode 100644 drivers/net/ethernet/huawei/hinic3/Makefile
 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_common.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_common.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
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hw_intf.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hwif.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_hwif.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_irq.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_lld.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_lld.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_main.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_mbox.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_mgmt.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_mgmt.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_mgmt_interface.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_pci_id_tbl.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_queue_common.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_queue_common.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_rss.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_rss.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_rx.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_rx.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_tx.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_tx.h
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_wq.c
 create mode 100644 drivers/net/ethernet/huawei/hinic3/hinic3_wq.h

base-commit: 65fb414c93f486cef5408951350f20552113abd0 --
2.45.2

author
#1 lore raw

RFC v2 1/3 net: hinic3: module initialization and tx/rx logic

From: gongfan <[email protected]>

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.

---
 .../device_drivers/ethernet/huawei/hinic3.rst | 136 ++++
 MAINTAINERS                                   |   7 +
 drivers/net/ethernet/huawei/Kconfig           |   1 +
 drivers/net/ethernet/huawei/Makefile          |   1 +
 drivers/net/ethernet/huawei/hinic3/Kconfig    |  16 +
 drivers/net/ethernet/huawei/hinic3/Makefile   |  21 +
 .../ethernet/huawei/hinic3/hinic3_common.c    |  53 ++
 .../ethernet/huawei/hinic3/hinic3_common.h    |  27 +
 .../ethernet/huawei/hinic3/hinic3_hw_cfg.c    |  30 +
 .../ethernet/huawei/hinic3/hinic3_hw_cfg.h    |  58 ++
 .../ethernet/huawei/hinic3/hinic3_hw_comm.c   |  37 +
 .../ethernet/huawei/hinic3/hinic3_hw_comm.h   |  13 +
 .../ethernet/huawei/hinic3/hinic3_hw_intf.h   |  85 ++
 .../net/ethernet/huawei/hinic3/hinic3_hwdev.c |  24 +
 .../net/ethernet/huawei/hinic3/hinic3_hwdev.h |  82 ++
 .../net/ethernet/huawei/hinic3/hinic3_hwif.c  |  15 +
 .../net/ethernet/huawei/hinic3/hinic3_hwif.h  |  50 ++
 .../net/ethernet/huawei/hinic3/hinic3_lld.c   | 415 ++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_lld.h   |  20 +
 .../net/ethernet/huawei/hinic3/hinic3_main.c  | 417 ++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_mbox.c  |  17 +
 .../net/ethernet/huawei/hinic3/hinic3_mbox.h  |  16 +
 .../net/ethernet/huawei/hinic3/hinic3_mgmt.h  |  13 +
 .../huawei/hinic3/hinic3_mgmt_interface.h     | 111 +++
 .../huawei/hinic3/hinic3_netdev_ops.c         |  77 ++
 .../ethernet/huawei/hinic3/hinic3_nic_cfg.c   | 254 ++++++
 .../ethernet/huawei/hinic3/hinic3_nic_cfg.h   |  45 ++
 .../ethernet/huawei/hinic3/hinic3_nic_dev.h   | 100 +++
 .../ethernet/huawei/hinic3/hinic3_nic_io.c    |  21 +
 .../ethernet/huawei/hinic3/hinic3_nic_io.h    | 118 +++
 .../huawei/hinic3/hinic3_queue_common.c       |  65 ++
 .../huawei/hinic3/hinic3_queue_common.h       |  51 ++
 .../net/ethernet/huawei/hinic3/hinic3_rss.c   |  24 +
 .../net/ethernet/huawei/hinic3/hinic3_rss.h   |  12 +
 .../net/ethernet/huawei/hinic3/hinic3_rx.c    | 411 ++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_rx.h    |  91 +++
 .../net/ethernet/huawei/hinic3/hinic3_tx.c    | 724 ++++++++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_tx.h    | 129 ++++
 .../net/ethernet/huawei/hinic3/hinic3_wq.c    |  29 +
 .../net/ethernet/huawei/hinic3/hinic3_wq.h    |  75 ++
 40 files changed, 3891 insertions(+)
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +136 -0
new file mode 100644
index 000000000000..c93b1fa75d8b
@@ -0,0 +1,136 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=====================================================================
+Linux kernel driver for Huawei Ethernet Device Driver (hinic3) family
+=====================================================================
+
+Overview
+========
+
+The hinic3 is a network interface card(NIC) for Data Center. It supports
+a range of link-speed devices (10GE, 25GE, 100GE, etc.). The hinic3
+devices can have multiple physical forms (LOM NIC, PCIe standard NIC,
+OCP NIC etc.).
+
+The hinic3 driver supports the following features:
+- IPv4/IPv6 TCP/UDP checksum offload
+- TSO (TCP Segmentation Offload), LRO (Large Receive Offload)
+- RSS (Receive Side Scaling)
+- MSI-X interrupt aggregation configuration and interrupt adaptation.
+- SR-IOV (Single Root I/O Virtualization).
+
+Content
+=======
+
+- Supported PCI vendor ID/device IDs
+- Source Code Structure of Hinic3 Driver
+- Management Interface
+
+Supported PCI vendor ID/device IDs
+==================================
+
+19e5:0222 - hinic3 PF/PPF
+19e5:375F - hinic3 VF
+
+Prime Physical Function (PPF) is responsible for the management of the
+whole NIC card. For example, clock synchronization between the NIC and
+the host.
+Any PF may serve as a PPF. The PPF is selected dynamically.
+
+Source Code Structure of Hinic3 Driver
+======================================
+
+========================  ================================================
+hinic3_pci_id_tbl.h       Supported device IDs.
+hinic3_hw_intf.h          Interface between HW and driver.
+hinic3_queue_common.[ch]  Common structures and methods for NIC queues.
+hinic3_common.[ch]        Encapsulation of memory operations in Linux.
+hinic3_csr.h              Register definitions in the BAR.
+hinic3_hwif.[ch]          Interface for BAR.
+hinic3_eqs.[ch]           Interface for AEQs and CEQs.
+hinic3_mbox.[ch]          Interface for mailbox.
+hinic3_mgmt.[ch]          Management interface based on mailbox and AEQ.
+hinic3_wq.[ch]            Work queue data structures and interface.
+hinic3_cmdq.[ch]          Command queue is used to post command to HW.
+hinic3_hwdev.[ch]         HW structures and methods abstractions.
+hinic3_lld.[ch]           Auxiliary driver adaptation layer.
+hinic3_hw_comm.[ch]       Interface for common HW operations.
+hinic3_mgmt_interface.h   Interface between firmware and driver.
+hinic3_hw_cfg.[ch]        Interface for HW configuration.
+hinic3_irq.c              Interrupt request
+hinic3_netdev_ops.c       Operations registered to Linux kernel stack.
+hinic3_nic_dev.h          NIC structures and methods abstractions.
+hinic3_main.c             Main Linux kernel driver.
+hinic3_nic_cfg.[ch]       NIC service configuration.
+hinic3_nic_io.[ch]        Management plane interface for TX and RX.
+hinic3_rss.[ch]           Interface for Receive Side Scaling (RSS).
+hinic3_rx.[ch]            Interface for transmit.
+hinic3_tx.[ch]            Interface for receive.
+hinic3_ethtool.c          Interface for ethtool operations (ops).
+hinic3_filter.c           Interface for mac address.
+========================  ================================================
+
+Management Interface
+====================
+
+Asynchronous Event Queue (AEQ)
+------------------------------
+
+AEQ receives high priority events from the HW over a descriptor queue.
+Every descriptor is a fixed size of 64 bytes. AEQ can receive solicited or
+unsolicited events. Every device, VF or PF, can have up to 4 AEQs.
+Every AEQ is associated to a dedicated IRQ. AEQ can receive multiple types
+of events, but in practice the hinic3 driver ignores all events except for
+2 mailbox related events.
+
+MailBox
+-------
+
+Mailbox is a communication mechanism between the hinic3 driver and the HW.
+Each device has an independent mailbox. Driver can use the mailbox to send
+requests to management. Driver receives mailbox messages, such as responses
+to requests, over the AEQ (using event HINIC3_AEQ_FOR_MBOX). Due to the
+limited size of mailbox data register, mailbox messages are sent
+segment-by-segment.
+
+Every device can use its mailbox to post request to firmware. The mailbox
+can also be used to post requests and responses between the PF and its VFs.
+
+Completion Event Queue (CEQ)
+--------------------------
+
+The implementation of CEQ is the same as AEQ. It receives completion events
+form HW over a fixed size descriptor of 32 bits. Every device can have up
+to 32 CEQs. Every CEQ has a dedicated IRQ. CEQ only receives solicited
+events that are responses to requests from the driver. CEQ can receive
+multiple types of events, but in practice the hinic3 driver ignores all
+events except for HINIC3_CMDQ that represents completion of previously
+posted commands on a cmdq.
+
+Command Queue (cmdq)
+--------------------
+
+Every cmdq has a dedicated work queue on which commands are posted.
+Commands on the work queue are fixed size descriptor of size 64 bytes.
+Completion of a command will be indicated using ctrl bits in the
+descriptor that carried the command. Notification of command completions
+will also be provided via event on CEQ. Every device has 4 command queues
+that are initialized as a set (called cmdqs), each with its own type.
+Hinic3 driver only uses type HINIC3_CMDQ_SYNC.
+
+Work Queues(WQ)
+---------------
+
+Work queues are logical arrays of fixed size WQEs. The array may be spread
+over multiple non-contiguous pages using indirection table.
+Work queues are used by I/O queues and command queues.
+
+Global function ID
+------------------
+
+Every function, PF or VF, has a unique ordinal identification within the device.
+Many commands to management (mbox or cmdq) contain this ID so HW can apply the
+command effect to the right function.
+PF is allowed to post management commands to a subordinate VF by specifying the
+VFs ID. A VF must provide its own ID. Anti-spoofing in the HW will cause
+command from a VF to fail if it contains the wrong ID.
MAINTAINERS +7 -0
index af35519be320..64555a934d6b 100644
@@ -10600,6 +10600,13 @@ S:	Maintained
 F:	Documentation/networking/device_drivers/ethernet/huawei/hinic.rst
 F:	drivers/net/ethernet/huawei/hinic/
 
+HUAWEI 3RD GEN ETHERNET DRIVER
+M:	gongfan <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst
+F:	drivers/net/ethernet/huawei/hinic3/
+
 HUGETLB SUBSYSTEM
 M:	Muchun Song <[email protected]>
 L:	[email protected]
drivers/net/ethernet/huawei/Kconfig +1 -0
index c05fce15eb51..7d0feb1da158 100644
@@ -16,5 +16,6 @@ config NET_VENDOR_HUAWEI
 if NET_VENDOR_HUAWEI
 
 source "drivers/net/ethernet/huawei/hinic/Kconfig"
+source "drivers/net/ethernet/huawei/hinic3/Kconfig"
 
 endif # NET_VENDOR_HUAWEI
drivers/net/ethernet/huawei/Makefile +1 -0
index 2549ad5afe6d..59865b882879 100644
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_HINIC) += hinic/
+obj-$(CONFIG_HINIC3) += hinic3/
drivers/net/ethernet/huawei/hinic3/Kconfig new file +16 -0
new file mode 100644
index 000000000000..5ab5c460bbc6
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Huawei driver configuration
+#
+
+config HINIC3
+	tristate "Huawei Intelligent Network Interface Card 3rd"
+	# Fields of HW and management structures are little endian and will not
+	# be explicitly converted
+	depends on 64BIT && !CPU_BIG_ENDIAN
+	depends on PCI_MSI && (X86 || ARM64)
+	help
+	  This driver supports HiNIC PCIE Ethernet cards.
+	  To compile this driver as part of the kernel, choose Y here.
+	  If unsure, choose N.
+	  The default is N.
drivers/net/ethernet/huawei/hinic3/Makefile new file +21 -0
new file mode 100644
index 000000000000..b80543cff545
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+obj-$(CONFIG_HINIC3) += hinic3.o
+
+hinic3-objs := hinic3_hwdev.o \
+	       hinic3_lld.o \
+	       hinic3_common.o \
+	       hinic3_hwif.o \
+	       hinic3_hw_cfg.o \
+	       hinic3_queue_common.o \
+	       hinic3_mbox.o \
+	       hinic3_hw_comm.o \
+	       hinic3_wq.o \
+	       hinic3_nic_io.o \
+	       hinic3_nic_cfg.o \
+	       hinic3_tx.o \
+	       hinic3_rx.o \
+	       hinic3_netdev_ops.o \
+	       hinic3_rss.o \
+	       hinic3_main.o
\ No newline at end of file
drivers/net/ethernet/huawei/hinic3/hinic3_common.c new file +53 -0

53 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_common.h new file +27 -0
new file mode 100644
index 000000000000..f8ff768c20ca
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. */
+
+#ifndef HINIC3_COMMON_H
+#define HINIC3_COMMON_H
+
+#include <linux/device.h>
+
+#define HINIC3_MIN_PAGE_SIZE  0x1000
+
+struct hinic3_dma_addr_align {
+	u32        real_size;
+
+	void       *ori_vaddr;
+	dma_addr_t ori_paddr;
+
+	void       *align_vaddr;
+	dma_addr_t align_paddr;
+};
+
+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);
+
+#endif
drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.c new file +30 -0
new file mode 100644
index 000000000000..be1bc3f47c08
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include <linux/device.h>
+
+#include "hinic3_hw_cfg.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_mbox.h"
+#include "hinic3_hwif.h"
+
+#define IS_NIC_TYPE(hwdev) \
+	(((u32)(hwdev)->cfg_mgmt->svc_cap.chip_svc_type) & BIT(SERVICE_T_NIC))
+
+bool hinic3_support_nic(struct hinic3_hwdev *hwdev)
+{
+	if (!IS_NIC_TYPE(hwdev))
+		return false;
+
+	return true;
+}
+
+u16 hinic3_func_max_qnum(struct hinic3_hwdev *hwdev)
+{
+	return hwdev->cfg_mgmt->svc_cap.nic_cap.max_sqs;
+}
+
+u8 hinic3_physical_port_id(struct hinic3_hwdev *hwdev)
+{
+	return hwdev->cfg_mgmt->svc_cap.port_id;
+}
drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.h new file +58 -0

58 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.c new file +37 -0
new file mode 100644
index 000000000000..fc2efcfd22a1
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include <linux/delay.h>
+
+#include "hinic3_hw_comm.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_mbox.h"
+#include "hinic3_hwif.h"
+
+static int comm_msg_to_mgmt_sync(struct hinic3_hwdev *hwdev, u16 cmd, const void *buf_in,
+				 u32 in_size, void *buf_out, u32 *out_size)
+{
+	return hinic3_send_mbox_to_mgmt(hwdev, HINIC3_MOD_COMM, cmd, buf_in,
+					in_size, buf_out, out_size, 0);
+}
+
+int hinic3_func_reset(struct hinic3_hwdev *hwdev, u16 func_id, u64 reset_flag)
+{
+	struct comm_cmd_func_reset func_reset;
+	u32 out_size = sizeof(func_reset);
+	int err;
+
+	memset(&func_reset, 0, sizeof(func_reset));
+	func_reset.func_id = func_id;
+	func_reset.reset_flag = reset_flag;
+	err = comm_msg_to_mgmt_sync(hwdev, COMM_MGMT_CMD_FUNC_RESET,
+				    &func_reset, sizeof(func_reset),
+				    &func_reset, &out_size);
+	if (err || !out_size || func_reset.head.status) {
+		dev_err(hwdev->dev, "Failed to reset func resources, reset_flag 0x%llx, err: %d, status: 0x%x, out_size: 0x%x\n",
+			reset_flag, err, func_reset.head.status, out_size);
+		return -EIO;
+	}
+
+	return 0;
+}
drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.h new file +13 -0
new file mode 100644
index 000000000000..cb60d7d7826d
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. */
+
+#ifndef HINIC3_HW_COMM_H
+#define HINIC3_HW_COMM_H
+
+#include "hinic3_hw_intf.h"
+
+struct hinic3_hwdev;
+
+int hinic3_func_reset(struct hinic3_hwdev *hwdev, u16 func_id, u64 reset_flag);
+
+#endif
drivers/net/ethernet/huawei/hinic3/hinic3_hw_intf.h new file +85 -0

85 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c new file +24 -0
new file mode 100644
index 000000000000..014fe4eeed5c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include "hinic3_hwdev.h"
+#include "hinic3_mbox.h"
+#include "hinic3_mgmt.h"
+#include "hinic3_hw_comm.h"
+#include "hinic3_hwif.h"
+
+int hinic3_init_hwdev(struct pci_dev *pdev)
+{
+	/* Completed by later submission due to LoC limit. */
+	return -EFAULT;
+}
+
+void hinic3_free_hwdev(struct hinic3_hwdev *hwdev)
+{
+	/* Completed by later submission due to LoC limit. */
+}
+
+void hinic3_set_api_stop(struct hinic3_hwdev *hwdev)
+{
+	/* Completed by later submission due to LoC limit. */
+}
drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.h new file +82 -0

82 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hwif.c new file +15 -0
new file mode 100644
index 000000000000..4e12670a9440
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/bitfield.h>
+
+#include "hinic3_hwdev.h"
+#include "hinic3_common.h"
+#include "hinic3_hwif.h"
+
+u16 hinic3_global_func_id(struct hinic3_hwdev *hwdev)
+{
+	return hwdev->hwif->attr.func_global_idx;
+}
drivers/net/ethernet/huawei/hinic3/hinic3_hwif.h new file +50 -0

50 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_lld.c new file +415 -0

415 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_lld.h new file +20 -0
new file mode 100644
index 000000000000..b84b6641af42
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. */
+
+#ifndef HINIC3_LLD_H
+#define HINIC3_LLD_H
+
+#include <linux/auxiliary_bus.h>
+
+struct hinic3_event_info;
+
+#define HINIC3_NIC_DRV_NAME "hinic3"
+
+int hinic3_lld_init(void);
+void hinic3_lld_exit(void);
+int hinic3_adev_event_register(struct auxiliary_device *adev,
+			       void (*event_handler)(struct auxiliary_device *adev,
+						     struct hinic3_event_info *event));
+struct hinic3_hwdev *adev_get_hwdev(struct auxiliary_device *adev);
+
+#endif
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +417 -0

417 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c new file +17 -0
new file mode 100644
index 000000000000..73b0357c0a07
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include <linux/dma-mapping.h>
+
+#include "hinic3_mbox.h"
+#include "hinic3_common.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_hwif.h"
+
+int hinic3_send_mbox_to_mgmt(struct hinic3_hwdev *hwdev, u8 mod, u16 cmd,
+			     const void *buf_in, u32 in_size, void *buf_out,
+			     u32 *out_size, u32 timeout)
+{
+	/* Completed by later submission due to LoC limit. */
+	return -EFAULT;
+}
drivers/net/ethernet/huawei/hinic3/hinic3_mbox.h new file +16 -0
new file mode 100644
index 000000000000..5a90420230b4
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. */
+
+#ifndef HINIC3_MBOX_H
+#define HINIC3_MBOX_H
+
+#include <linux/mutex.h>
+#include <linux/bitfield.h>
+
+struct hinic3_hwdev;
+
+int hinic3_send_mbox_to_mgmt(struct hinic3_hwdev *hwdev, u8 mod, u16 cmd,
+			     const void *buf_in, u32 in_size, void *buf_out,
+			     u32 *out_size, u32 timeout);
+
+#endif
drivers/net/ethernet/huawei/hinic3/hinic3_mgmt.h new file +13 -0
new file mode 100644
index 000000000000..9e044a8a81b5
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. */
+
+#ifndef HINIC3_MGMT_H
+#define HINIC3_MGMT_H
+
+#include <linux/types.h>
+
+struct hinic3_hwdev;
+
+void hinic3_flush_mgmt_workq(struct hinic3_hwdev *hwdev);
+
+#endif
drivers/net/ethernet/huawei/hinic3/hinic3_mgmt_interface.h new file +111 -0

111 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c new file +77 -0

77 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c new file +254 -0

254 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h new file +45 -0

45 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h new file +100 -0

100 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.c new file +21 -0
new file mode 100644
index 000000000000..fe79bf8013b9
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include "hinic3_nic_io.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_nic_cfg.h"
+#include "hinic3_nic_dev.h"
+#include "hinic3_hw_comm.h"
+#include "hinic3_hw_intf.h"
+#include "hinic3_hwif.h"
+
+int hinic3_init_nic_io(struct hinic3_nic_dev *nic_dev)
+{
+	/* Completed by later submission due to LoC limit. */
+	return -EFAULT;
+}
+
+void hinic3_free_nic_io(struct hinic3_nic_dev *nic_dev)
+{
+	/* Completed by later submission due to LoC limit. */
+}
drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.h new file +118 -0

118 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_queue_common.c new file +65 -0

65 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_queue_common.h new file +51 -0

51 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_rss.c new file +24 -0
new file mode 100644
index 000000000000..7873a18fac65
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include "hinic3_rss.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_nic_dev.h"
+#include "hinic3_nic_cfg.h"
+#include "hinic3_hwif.h"
+
+void hinic3_clear_rss_config(struct net_device *netdev)
+{
+	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+
+	kfree(nic_dev->rss_hkey);
+	nic_dev->rss_hkey = NULL;
+
+	kfree(nic_dev->rss_indir);
+	nic_dev->rss_indir = NULL;
+}
+
+void hinic3_try_to_enable_rss(struct net_device *netdev)
+{
+	/* Completed by later submission due to LoC limit. */
+}
drivers/net/ethernet/huawei/hinic3/hinic3_rss.h new file +12 -0
new file mode 100644
index 000000000000..4da23014d680
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. */
+
+#ifndef HINIC3_RSS_H
+#define HINIC3_RSS_H
+
+#include <linux/netdevice.h>
+
+void hinic3_try_to_enable_rss(struct net_device *netdev);
+void hinic3_clear_rss_config(struct net_device *netdev);
+
+#endif
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c new file +411 -0

411 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_rx.h new file +91 -0

91 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_tx.c new file +724 -0

51 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_tx.h new file +129 -0

129 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_wq.c new file +29 -0
new file mode 100644
index 000000000000..e4ed790f3de1

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/huawei/hinic3/hinic3_wq.h new file +75 -0

75 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.45.2

Part of the diff is not shown here. View the raw message.

author
#8 lore raw

RFC v2 2/3 net: hinic3: management interfaces

In reply to Gur Stavi

From: gongfan <[email protected]>

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   |   3 +
 .../net/ethernet/huawei/hinic3/hinic3_cmdq.c  | 898 ++++++++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_cmdq.h  | 150 +++
 .../ethernet/huawei/hinic3/hinic3_common.c    |  45 +
 .../ethernet/huawei/hinic3/hinic3_common.h    |  27 +
 .../net/ethernet/huawei/hinic3/hinic3_csr.h   |  74 ++
 .../net/ethernet/huawei/hinic3/hinic3_eqs.c   | 786 +++++++++++++++
 .../net/ethernet/huawei/hinic3/hinic3_eqs.h   | 128 +++
 .../ethernet/huawei/hinic3/hinic3_hw_cfg.c    |  42 +
 .../ethernet/huawei/hinic3/hinic3_hw_comm.c   |  31 +
 .../ethernet/huawei/hinic3/hinic3_hw_comm.h   |  13 +
 .../ethernet/huawei/hinic3/hinic3_hw_intf.h   |  43 +
 .../net/ethernet/huawei/hinic3/hinic3_hwif.c  | 156 +++
 .../net/ethernet/huawei/hinic3/hinic3_hwif.h  |  25 +
 .../net/ethernet/huawei/hinic3/hinic3_irq.c   | 172 ++++
 .../net/ethernet/huawei/hinic3/hinic3_mbox.c  | 831 +++++++++++++++-
 .../net/ethernet/huawei/hinic3/hinic3_mbox.h  | 131 +++
 .../ethernet/huawei/hinic3/hinic3_nic_dev.h   |   2 +
 .../net/ethernet/huawei/hinic3/hinic3_wq.c    | 103 ++
 .../net/ethernet/huawei/hinic3/hinic3_wq.h    |  12 +
 20 files changed, 3670 insertions(+), 2 deletions(-)
drivers/net/ethernet/huawei/hinic3/Makefile +3 -0
index b80543cff545..423501b87cbd 100644
@@ -8,14 +8,17 @@ hinic3-objs := hinic3_hwdev.o \
 	       hinic3_common.o \
 	       hinic3_hwif.o \
 	       hinic3_hw_cfg.o \
+	       hinic3_eqs.o \
 	       hinic3_queue_common.o \
 	       hinic3_mbox.o \
 	       hinic3_hw_comm.o \
 	       hinic3_wq.o \
+	       hinic3_cmdq.o \
 	       hinic3_nic_io.o \
 	       hinic3_nic_cfg.o \
 	       hinic3_tx.o \
 	       hinic3_rx.o \
 	       hinic3_netdev_ops.o \
+	       hinic3_irq.o \
 	       hinic3_rss.o \
 	       hinic3_main.o
\ No newline at end of file
drivers/net/ethernet/huawei/hinic3/hinic3_cmdq.c new file +898 -0

898 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_cmdq.h new file +150 -0

150 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_common.c +45 -0

48 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_common.h +27 -0
index f8ff768c20ca..83595e0f3b31 100644
@@ -18,10 +18,37 @@ struct hinic3_dma_addr_align {
 	dma_addr_t align_paddr;
 };
 
+enum hinic3_wait_return {
+	WAIT_PROCESS_CPL     = 0,
+	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 cmdq_buf_swab32(void *data, int len);
+
 #endif
drivers/net/ethernet/huawei/hinic3/hinic3_csr.h new file +74 -0

74 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_eqs.c new file +786 -0

786 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_eqs.h new file +128 -0

128 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.c +42 -0

48 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.c +31 -0
index fc2efcfd22a1..3147afc8391d 100644
@@ -15,6 +15,37 @@ static int comm_msg_to_mgmt_sync(struct hinic3_hwdev *hwdev, u16 cmd, const void
 					in_size, buf_out, out_size, 0);
 }
 
+int hinic3_set_interrupt_cfg_direct(struct hinic3_hwdev *hwdev,
+				    const struct interrupt_info *info)
+{
+	struct comm_cmd_msix_config msix_cfg;
+	u32 out_size = sizeof(msix_cfg);
+	int err;
+
+	memset(&msix_cfg, 0, sizeof(msix_cfg));
+	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_limt;
+	msix_cfg.coalesce_timer_cnt = info->coalesc_timer_cfg;
+	msix_cfg.resend_timer_cnt = info->resend_timer_cfg;
+
+	err = comm_msg_to_mgmt_sync(hwdev, COMM_MGMT_CMD_CFG_MSIX_CTRL_REG,
+				    &msix_cfg, sizeof(msix_cfg), &msix_cfg,
+				    &out_size);
+	if (err || !out_size || msix_cfg.head.status) {
+		dev_err(hwdev->dev,
+			"Failed to set interrupt config, err: %d, status: 0x%x, out size: 0x%x\n",
+			err, msix_cfg.head.status, out_size);
+		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
index cb60d7d7826d..2d747270515e 100644
@@ -8,6 +8,19 @@
 
 struct hinic3_hwdev;
 
+struct interrupt_info {
+	u32 lli_set;
+	u32 interrupt_coalesc_set;
+	u16 msix_index;
+	u8  lli_credit_limit;
+	u8  lli_timer_cfg;
+	u8  pending_limt;
+	u8  coalesc_timer_cfg;
+	u8  resend_timer_cfg;
+};
+
+int hinic3_set_interrupt_cfg_direct(struct hinic3_hwdev *hwdev,
+				    const struct 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 +43 -0

59 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hwif.c +156 -0

162 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hwif.h +25 -0
index da502c4b6efb..ebfaf2c49c3a 100644
@@ -45,6 +45,31 @@ struct hinic3_hwif {
 	struct hinic3_func_attr attr;
 };
 
+enum hinic3_msix_state {
+	HINIC3_MSIX_ENABLE,
+	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 void __iomem *db_base,
+			 void __iomem *dwqe_base);
+
+void hinic3_set_msix_state(struct hinic3_hwdev *hwdev, u16 msix_idx,
+			   enum hinic3_msix_state flag);
+void hinic3_misx_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);
 
 #endif
drivers/net/ethernet/huawei/hinic3/hinic3_irq.c new file +172 -0

172 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c +829 -2

333 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_mbox.h +131 -0

131 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h +2 -0
index 4daacc7b03b0..86857cc920b6 100644

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/huawei/hinic3/hinic3_wq.c +103 -0

103 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_wq.h +12 -0
index ca33f4176eea..dba7d2a0c5d8 100644

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.45.2

Part of the diff is not shown here. View the raw message.

author
#9 lore raw

RFC v2 3/3 net: hinic3: sw and hw initialization code

In reply to Gur Stavi

From: gongfan <[email protected]>

This is [3/3] part of hinic3 Ethernet driver initial submission. With this patch hinic3 becomes a functional Ethernet driver.

The driver parts contained in this patch:
Memory allocation and initialization of the driver structures. Management interfaces initialization.
HW capabilities probing, initialization and setup using management interfaces.
Net device open/stop implementation and data queues initialization. Register VID:DID in PCI id_table.

---
 drivers/net/ethernet/huawei/hinic3/Makefile   |   1 +
 .../ethernet/huawei/hinic3/hinic3_hw_cfg.c    | 194 ++++
 .../ethernet/huawei/hinic3/hinic3_hw_cfg.h    |   4 +
 .../ethernet/huawei/hinic3/hinic3_hw_comm.c   | 344 +++++++
 .../ethernet/huawei/hinic3/hinic3_hw_comm.h   |  16 +
 .../ethernet/huawei/hinic3/hinic3_hw_intf.h   | 120 +++
 .../net/ethernet/huawei/hinic3/hinic3_hwdev.c | 551 ++++++++++-
 .../net/ethernet/huawei/hinic3/hinic3_hwif.c  | 259 ++++++
 .../net/ethernet/huawei/hinic3/hinic3_hwif.h  |  16 +
 .../net/ethernet/huawei/hinic3/hinic3_lld.c   |   4 +-
 .../net/ethernet/huawei/hinic3/hinic3_mgmt.c  |  21 +
 .../net/ethernet/huawei/hinic3/hinic3_mgmt.h  |   1 +
 .../huawei/hinic3/hinic3_mgmt_interface.h     | 101 ++
 .../huawei/hinic3/hinic3_netdev_ops.c         | 449 ++++++++-
 .../ethernet/huawei/hinic3/hinic3_nic_cfg.c   | 141 +++
 .../ethernet/huawei/hinic3/hinic3_nic_cfg.h   |  31 +
 .../ethernet/huawei/hinic3/hinic3_nic_dev.h   |   5 +
 .../ethernet/huawei/hinic3/hinic3_nic_io.c    | 870 +++++++++++++++++-
 .../ethernet/huawei/hinic3/hinic3_nic_io.h    |  24 +
 .../huawei/hinic3/hinic3_pci_id_tbl.h         |  10 +
 .../net/ethernet/huawei/hinic3/hinic3_rss.c   | 356 ++++++-
 .../net/ethernet/huawei/hinic3/hinic3_rss.h   |   2 +
 .../net/ethernet/huawei/hinic3/hinic3_rx.c    | 215 ++++-
 .../net/ethernet/huawei/hinic3/hinic3_rx.h    |  13 +
 .../net/ethernet/huawei/hinic3/hinic3_tx.c    |  93 ++
 .../net/ethernet/huawei/hinic3/hinic3_tx.h    |  12 +
 26 files changed, 3838 insertions(+), 15 deletions(-)
drivers/net/ethernet/huawei/hinic3/Makefile +1 -0
index 423501b87cbd..db82948804c8 100644
@@ -11,6 +11,7 @@ hinic3-objs := hinic3_hwdev.o \
 	       hinic3_eqs.o \
 	       hinic3_queue_common.o \
 	       hinic3_mbox.o \
+	       hinic3_mgmt.o \
 	       hinic3_hw_comm.o \
 	       hinic3_wq.o \
 	       hinic3_cmdq.o \
drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.c +194 -0

209 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hw_cfg.h +4 -0
index cef311b8f642..c9616a56b8f4 100644
@@ -47,10 +47,14 @@ struct cfg_mgmt_info {
 	struct service_cap  svc_cap;
 };
 
+int hinic3_init_cfg_mgmt(struct hinic3_hwdev *hwdev);
+void hinic3_free_cfg_mgmt(struct hinic3_hwdev *hwdev);
+
 int hinic3_alloc_irqs(struct hinic3_hwdev *hwdev, u16 num,
 		      struct irq_info *alloc_arr, u16 *act_num);
 void hinic3_free_irq(struct hinic3_hwdev *hwdev, u32 irq_id);
 
+int init_capability(struct hinic3_hwdev *hwdev);
 bool hinic3_support_nic(struct hinic3_hwdev *hwdev);
 u16 hinic3_func_max_qnum(struct hinic3_hwdev *hwdev);
 u8 hinic3_physical_port_id(struct hinic3_hwdev *hwdev);
drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.c +344 -0

353 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hw_comm.h +16 -0
index 2d747270515e..2a7ef8181939 100644
@@ -8,6 +8,8 @@
 
 struct hinic3_hwdev;
 
+#define HINIC3_WQ_PAGE_SIZE_ORDER       8
+
 struct interrupt_info {
 	u32 lli_set;
 	u32 interrupt_coalesc_set;
@@ -23,4 +25,18 @@ int hinic3_set_interrupt_cfg_direct(struct hinic3_hwdev *hwdev,
 				    const struct interrupt_info *info);
 int hinic3_func_reset(struct hinic3_hwdev *hwdev, u16 func_id, u64 reset_flag);
 
+int hinic3_get_comm_features(struct hinic3_hwdev *hwdev, u64 *s_feature, u16 size);
+int hinic3_set_comm_features(struct hinic3_hwdev *hwdev, u64 *s_feature, u16 size);
+int hinic3_get_global_attr(struct hinic3_hwdev *hwdev, struct comm_global_attr *attr);
+int hinic3_set_func_svc_used_state(struct hinic3_hwdev *hwdev, u16 svc_type, u8 state);
+int hinic3_set_dma_attr_tbl(struct hinic3_hwdev *hwdev, u8 entry_idx, u8 st, u8 at, u8 ph,
+			    u8 no_snooping, u8 tph_en);
+
+int hinic3_set_wq_page_size(struct hinic3_hwdev *hwdev, u16 func_idx, u32 page_size);
+int hinic3_set_cmdq_depth(struct hinic3_hwdev *hwdev, u16 cmdq_depth);
+int hinic3_func_rx_tx_flush(struct hinic3_hwdev *hwdev);
+int hinic3_set_root_ctxt(struct hinic3_hwdev *hwdev, u32 rq_depth, u32 sq_depth,
+			 int rx_buf_sz);
+int hinic3_clean_root_ctxt(struct hinic3_hwdev *hwdev);
+
 #endif
drivers/net/ethernet/huawei/hinic3/hinic3_hw_intf.h +120 -0

148 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c +548 -3

570 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hwif.c +259 -0

289 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_hwif.h +16 -0
index ebfaf2c49c3a..5e3d2f135884 100644
@@ -45,6 +45,16 @@ struct hinic3_hwif {
 	struct hinic3_func_attr attr;
 };
 
+enum hinic3_outbound_ctrl {
+	ENABLE_OUTBOUND  = 0x0,
+	DISABLE_OUTBOUND = 0x1,
+};
+
+enum hinic3_doorbell_ctrl {
+	ENABLE_DOORBELL  = 0,
+	DISABLE_DOORBELL = 1,
+};
+
 enum hinic3_msix_state {
 	HINIC3_MSIX_ENABLE,
 	HINIC3_MSIX_DISABLE,
@@ -58,11 +68,17 @@ enum hinic3_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);
 
+void hinic3_disable_doorbell(struct hinic3_hwif *hwif);
+void hinic3_enable_doorbell(struct hinic3_hwif *hwif);
+
 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 void __iomem *db_base,
 			 void __iomem *dwqe_base);
 
+int hinic3_init_hwif(struct hinic3_hwdev *hwdev);
+void hinic3_free_hwif(struct hinic3_hwdev *hwdev);
+
 void hinic3_set_msix_state(struct hinic3_hwdev *hwdev, u16 msix_idx,
 			   enum hinic3_msix_state flag);
 void hinic3_misx_intr_clear_resend_bit(struct hinic3_hwdev *hwdev, u16 msix_idx,
drivers/net/ethernet/huawei/hinic3/hinic3_lld.c +3 -1
index 526b4a9aecf4..a8371c94ec6a 100644
@@ -6,6 +6,7 @@
 #include "hinic3_lld.h"
 #include "hinic3_hwdev.h"
 #include "hinic3_hw_cfg.h"
+#include "hinic3_pci_id_tbl.h"
 #include "hinic3_mgmt.h"
 
 #define HINIC3_VF_PCI_CFG_REG_BAR  0
@@ -307,6 +308,7 @@ static void hinic3_func_deinit(struct pci_dev *pdev)
 {
 	struct hinic3_pcidev *pci_adapter = pci_get_drvdata(pdev);
 
+	hinic3_flush_mgmt_workq(pci_adapter->hwdev);
 	hinic3_detach_aux_devices(pci_adapter->hwdev);
 	hinic3_free_hwdev(pci_adapter->hwdev);
 }
@@ -378,7 +380,7 @@ static void hinic3_remove(struct pci_dev *pdev)
 }
 
 static const struct pci_device_id hinic3_pci_table[] = {
-	/* Completed by later submission due to LoC limit. */
+	{PCI_VDEVICE(HUAWEI, PCI_DEV_ID_HINIC3_VF), 0},
 	{0, 0}
 
 };
drivers/net/ethernet/huawei/hinic3/hinic3_mgmt.c new file +21 -0
new file mode 100644
index 000000000000..9271dac53761
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+#include "hinic3_mgmt.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_eqs.h"
+#include "hinic3_mbox.h"
+
+void hinic3_flush_mgmt_workq(struct hinic3_hwdev *hwdev)
+{
+	if (hwdev->aeqs)
+		flush_workqueue(hwdev->aeqs->workq);
+}
+
+void hinic3_mgmt_msg_aeqe_handler(struct hinic3_hwdev *hwdev, u8 *header, u8 size)
+{
+	if ((HINIC3_MSG_HEADER_GET(*(u64 *)header, SOURCE) ==
+	     HINIC3_MSG_FROM_MBOX)) {
+		hinic3_mbox_func_aeqe_handler(hwdev, header, size);
+	}
+}
drivers/net/ethernet/huawei/hinic3/hinic3_mgmt.h +1 -0
index 9e044a8a81b5..327f3ca55b89 100644
@@ -9,5 +9,6 @@
 struct hinic3_hwdev;
 
 void hinic3_flush_mgmt_workq(struct hinic3_hwdev *hwdev);
+void hinic3_mgmt_msg_aeqe_handler(struct hinic3_hwdev *hwdev, u8 *header, u8 size);
 
 #endif
drivers/net/ethernet/huawei/hinic3/hinic3_mgmt_interface.h +101 -0

119 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c +445 -4

461 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c +141 -0

162 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h +31 -0
index 00456994e55c..3df4bf3c6584 100644
@@ -24,15 +24,40 @@ enum hinic3_nic_event_type {
 	EVENT_NIC_LINK_UP = 1,
 };
 
+struct hinic3_sq_attr {
+	u8  dma_attr_off;
+	u8  pending_limit;
+	u8  coalescing_time;
+	u8  intr_en;
+	u16 intr_idx;
+	u32 l2nic_sqn;
+	u64 ci_dma_base;
+};
+
+enum mag_cmd {
+	MAG_CMD_GET_LINK_STATUS        = 7,
+};
+
+/* firmware also use this cmd report link event to driver */
+struct mag_cmd_get_link_status {
+	struct mgmt_msg_head head;
+	u8                   port_id;
+	/* 0:link down  1:link up */
+	u8                   status;
+	u8                   rsvd0[2];
+};
+
 int l2nic_msg_to_mgmt_sync(struct hinic3_hwdev *hwdev, u16 cmd,
 			   const void *buf_in, u32 in_size,
 			   void *buf_out, u32 *out_size);
 
+int hinic3_get_nic_feature_from_hw(struct hinic3_nic_dev *nic_dev);
 int hinic3_set_nic_feature_to_hw(struct hinic3_nic_dev *nic_dev);
 bool hinic3_test_support(struct hinic3_nic_dev *nic_dev,
 			 enum nic_feature_cap feature_bits);
 void hinic3_update_nic_feature(struct hinic3_nic_dev *nic_dev, u64 feature_cap);
 
+int hinic3_init_function_table(struct hinic3_nic_dev *nic_dev);
 int hinic3_set_port_mtu(struct net_device *netdev, u16 new_mtu);
 
 int hinic3_set_mac(struct hinic3_hwdev *hwdev, const u8 *mac_addr, u16 vlan_id, u16 func_id);
@@ -40,6 +65,12 @@ int hinic3_del_mac(struct hinic3_hwdev *hwdev, const u8 *mac_addr, u16 vlan_id,
 int hinic3_update_mac(struct hinic3_hwdev *hwdev, const u8 *old_mac, u8 *new_mac, u16 vlan_id,
 		      u16 func_id);
 
+int hinic3_set_ci_table(struct hinic3_hwdev *hwdev, struct hinic3_sq_attr *attr);
+int hinic3_flush_qps_res(struct hinic3_hwdev *hwdev);
 int hinic3_force_drop_tx_pkt(struct hinic3_hwdev *hwdev);
 
+int hinic3_sync_dcb_state(struct hinic3_hwdev *hwdev, u8 op_code, u8 state);
+int hinic3_get_link_status(struct hinic3_hwdev *hwdev, bool *link_status_up);
+int hinic3_set_vport_enable(struct hinic3_hwdev *hwdev, u16 func_id, bool enable);
+
 #endif
drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h +5 -0
index 86857cc920b6..c4e6c3537215 100644
@@ -36,6 +36,11 @@ struct nic_rss_type {
 	u8 udp_ipv4;
 };
 
+struct nic_rss_indirect_tbl_set {
+	u32 rsvd[4];
+	u16 entry[NIC_RSS_INDIR_SIZE];
+};
+
 struct hinic3_irq {
 	struct net_device  *netdev;
 	u16                msix_entry_idx;
drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.c +867 -3

497 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.h +24 -0
index c10e48726386..1c9e145de3ad 100644

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/huawei/hinic3/hinic3_pci_id_tbl.h new file +10 -0
new file mode 100644
index 000000000000..4336e002988a

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/huawei/hinic3/hinic3_rss.c +355 -1

356 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_rss.h +2 -0
index 4da23014d680..ddc6a91aae39 100644

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +212 -3

215 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_rx.h +13 -0
index 6a567647795e..b1c2d4dc791c 100644

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +93 -0

93 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_tx.h +12 -0
index 7b4cb4608353..3185d0c21872 100644

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.45.2

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [RFC net-next v02 1/3] net: hinic3: module initialization and tx/rx logic

In reply to Gur Stavi
Quoted 7 lines · Gur Stavi

From: gongfan <[email protected]>

This is [1/3] part of hinic3 Ethernet driver initial submission. With this patch hinic3 is a valid kernel module but non-functional driver.

+++ b/Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst

Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst line 10

Quoted 10 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +10 -0
@@ -0,0 +1,136 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=====================================================================
+Linux kernel driver for Huawei Ethernet Device Driver (hinic3) family
+=====================================================================
+
+Overview
+========
+
+The hinic3 is a network interface card(NIC) for Data Center. It supports

Add space before "(".

Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst line 38

Quoted 4 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +4 -0
+Prime Physical Function (PPF) is responsible for the management of the
+whole NIC card. For example, clock synchronization between the NIC and
+the host.
+Any PF may serve as a PPF. The PPF is selected dynamically.

Add blank line between paragraphs or reflow into a single paragraph.

Is the PPF selected dynamically by the driver? By firmware on the NIC?

Quoted 17 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +17 -0
+hinic3_pci_id_tbl.h       Supported device IDs.
+hinic3_hw_intf.h          Interface between HW and driver.
+hinic3_queue_common.[ch]  Common structures and methods for NIC queues.
+hinic3_common.[ch]        Encapsulation of memory operations in Linux.
+hinic3_csr.h              Register definitions in the BAR.
+hinic3_hwif.[ch]          Interface for BAR.
+hinic3_eqs.[ch]           Interface for AEQs and CEQs.
+hinic3_mbox.[ch]          Interface for mailbox.
+hinic3_mgmt.[ch]          Management interface based on mailbox and AEQ.
+hinic3_wq.[ch]            Work queue data structures and interface.
+hinic3_cmdq.[ch]          Command queue is used to post command to HW.
+hinic3_hwdev.[ch]         HW structures and methods abstractions.
+hinic3_lld.[ch]           Auxiliary driver adaptation layer.
+hinic3_hw_comm.[ch]       Interface for common HW operations.
+hinic3_mgmt_interface.h   Interface between firmware and driver.
+hinic3_hw_cfg.[ch]        Interface for HW configuration.
+hinic3_irq.c              Interrupt request

Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst line 70

Quoted 10 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +10 -0
+hinic3_netdev_ops.c       Operations registered to Linux kernel stack.
+hinic3_nic_dev.h          NIC structures and methods abstractions.
+hinic3_main.c             Main Linux kernel driver.
+hinic3_nic_cfg.[ch]       NIC service configuration.
+hinic3_nic_io.[ch]        Management plane interface for TX and RX.
+hinic3_rss.[ch]           Interface for Receive Side Scaling (RSS).
+hinic3_rx.[ch]            Interface for transmit.
+hinic3_tx.[ch]            Interface for receive.
+hinic3_ethtool.c          Interface for ethtool operations (ops).
+hinic3_filter.c           Interface for mac address.

Could drop "." at end (or use it consistently).

s/mac/MAC/

Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst line 86

Quoted 3 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +3 -0
+2 mailbox related events.
+
+MailBox

s/MailBox/Mailbox/ since that's how you use it elsewhere.

Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst line 108

Quoted 11 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +10 -0
+-------
+
+Mailbox is a communication mechanism between the hinic3 driver and the HW.
 
+The implementation of CEQ is the same as AEQ. It receives completion events
+form HW over a fixed size descriptor of 32 bits. Every device can have up
+to 32 CEQs. Every CEQ has a dedicated IRQ. CEQ only receives solicited
+events that are responses to requests from the driver. CEQ can receive
+multiple types of events, but in practice the hinic3 driver ignores all
+events except for HINIC3_CMDQ that represents completion of previously
+posted commands on a cmdq.

s/form HW/from HW/

Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst line 125

Quoted 2 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +2 -0
+Work queues are logical arrays of fixed size WQEs. The array may be spread
+over multiple non-contiguous pages using indirection table.

Add blank line or wrap into single paragraph.

Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst line 133

Quoted 5 lines
Documentation/networking/device_drivers/ethernet/huawei/hinic3.rst new file +4 -0
+Work queues are used by I/O queues and command queues.
 
+Every function, PF or VF, has a unique ordinal identification within the device.
+Many commands to management (mbox or cmdq) contain this ID so HW can apply the
+command effect to the right function.

Add blank line or wrap into single paragraph.

drivers/net/ethernet/huawei/hinic3/Kconfig line 9

Quoted 8 lines
drivers/net/ethernet/huawei/hinic3/Kconfig new file +7 -0
+PF is allowed to post management commands to a subordinate VF by specifying the
+VFs ID. A VF must provide its own ID. Anti-spoofing in the HW will cause
+command from a VF to fail if it contains the wrong ID.
 
+config HINIC3
+	tristate "Huawei Intelligent Network Interface Card 3rd"
+	# Fields of HW and management structures are little endian and will not
+	# be explicitly converted

I guess this comment is here to explain the !CPU_BIG_ENDIAN below? That's quite an unusual dependency.

Quoted 16 lines
drivers/net/ethernet/huawei/hinic3/Makefile new file +14 -0
+	depends on 64BIT && !CPU_BIG_ENDIAN
 
+++ b/drivers/net/ethernet/huawei/hinic3/Makefile
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
+
+obj-$(CONFIG_HINIC3) += hinic3.o
+
+hinic3-objs := hinic3_hwdev.o \
+	       hinic3_lld.o \
+	       hinic3_common.o \
+	       hinic3_hwif.o \
+	       hinic3_hw_cfg.o \
+	       hinic3_queue_common.o \
+	       hinic3_mbox.o \

drivers/net/ethernet/huawei/hinic3/Makefile line 21

Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/Makefile new file +9 -0
+	       hinic3_hw_comm.o \
+	       hinic3_wq.o \
+	       hinic3_nic_io.o \
+	       hinic3_nic_cfg.o \
+	       hinic3_tx.o \
+	       hinic3_rx.o \
+	       hinic3_netdev_ops.o \
+	       hinic3_rss.o \
+	       hinic3_main.o
\ No newline at end of file

Add newline.

#4 lore raw

Re: [RFC net-next v02 1/3] net: hinic3: module initialization and tx/rx logic

In reply to Gur Stavi
Quoted 9 lines
drivers/net/ethernet/huawei/hinic3/hinic3_lld.c new file +9 -0
+static void hinic3_del_one_adev(struct hinic3_hwdev *hwdev,
+				enum hinic3_service_type svc_type)
+{
+	struct hinic3_pcidev *pci_adapter = hwdev->adapter;
+	struct hinic3_adev *hadev;
+	bool timeout = true;
+	unsigned long end;
+
+	end = jiffies + msecs_to_jiffies(HINIC3_EVENT_PROCESS_TIMEOUT);

drivers/net/ethernet/huawei/hinic3/hinic3_lld.c line 101

Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_lld.c new file +10 -0
+	do {
+		if (!test_and_set_bit(svc_type, &pci_adapter->state)) {
+			timeout = false;
+			break;
+		}
+		usleep_range(900, 1000);
+	} while (time_before(jiffies, end));
+
+	if (timeout && !test_and_set_bit(svc_type, &pci_adapter->state))
+		timeout = false;

Please look at using iopoll.h

drivers/net/ethernet/huawei/hinic3/hinic3_main.c line 148

Quoted 12 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +12 -0
+static int hinic3_sw_init(struct net_device *netdev)
+{
+	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+	struct hinic3_hwdev *hwdev = nic_dev->hwdev;
+	int err;
+
+	nic_dev->q_params.sq_depth = HINIC3_SQ_DEPTH;
+	nic_dev->q_params.rq_depth = HINIC3_RQ_DEPTH;
+
+	hinic3_try_to_enable_rss(netdev);
+
+	eth_hw_addr_random(netdev);

Is using a random MAC just a temporary thing until more code is added to access an OTP?

drivers/net/ethernet/huawei/hinic3/hinic3_main.c line 327

Quoted 9 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +9 -0
+	err = register_netdev(netdev);
+	if (err) {
+		err = -ENOMEM;
+		goto err_netdev;
+	}
+
+	netif_carrier_off(netdev);
+
+	dev_set_drvdata(&adev->dev, nic_dev);

Is this used anywhere in the driver? Calling register_netdev() makes the interface live, even before it returns. If you have NFS root for example, it could be sending packets, etc, before drvdata is set.

Quoted 8 lines
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c new file +8 -0
+int hinic3_set_port_mtu(struct net_device *netdev, u16 new_mtu)
+{
+	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+	struct hinic3_func_tbl_cfg func_tbl_cfg = {};
+	struct hinic3_hwdev *hwdev = nic_dev->hwdev;
+
+	if (new_mtu < HINIC3_MIN_MTU_SIZE) {
+		dev_err(hwdev->dev,

drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c line 109

Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c new file +10 -0
+			"Invalid mtu size: %ubytes, mtu size < %ubytes\n",
+			new_mtu, HINIC3_MIN_MTU_SIZE);
+		return -EINVAL;
+	}
+
+	if (new_mtu > HINIC3_MAX_JUMBO_FRAME_SIZE) {
+		dev_err(hwdev->dev, "Invalid mtu size: %ubytes, mtu size > %ubytes\n",
+			new_mtu, HINIC3_MAX_JUMBO_FRAME_SIZE);
+		return -EINVAL;
+	}

The core can do this validation for you, if you set ndev->max_mtu, ndev->min_mtu.

Andrew

---
pw-bot: cr

author
#3 lore raw

RE: [RFC net-next v02 1/3] net: hinic3: module initialization and tx/rx logic

In reply to Bjorn Helgaas
Quoted 2 lines

Is the PPF selected dynamically by the driver? By firmware on the NIC?

Selected dynamically by PF driver but initial submission only contains VF logic.

Quoted 7 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	# Fields of HW and management structures are little endian and will

not

drivers/net/ethernet/huawei/hinic3/Kconfig line 9

Quoted 1 line
drivers/net/ethernet/huawei/hinic3/Kconfig new file +1 -0
+	# be explicitly converted

I guess this comment is here to explain the !CPU_BIG_ENDIAN below? That's quite an unusual dependency.

Yes. Otherwise the code will be swamped with cpu_to_le and le_to_cpu. Microsoft and Amazon drivers have it as well. I wonder if all other drivers were tested on big endian host.
Dependency on CPU_LITTLE_ENDIAN would be nicer but unfortunately x86 arch does not define it.

Quoted 2 lines

drivers/net/ethernet/huawei/hinic3/Kconfig line 10

Quoted 1 line
drivers/net/ethernet/huawei/hinic3/Kconfig new file +1 -0
+	depends on 64BIT && !CPU_BIG_ENDIAN

Other comments were addressed in files for next submission.

author
#5 lore raw

Re: [RFC net-next v02 1/3] net: hinic3: module initialization and tx/rx logic

In reply to Andrew Lunn
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/huawei/hinic3/hinic3_lld.c new file +13 -0
+static void hinic3_del_one_adev(struct hinic3_hwdev *hwdev,
+				enum hinic3_service_type svc_type)
+{
+	struct hinic3_pcidev *pci_adapter = hwdev->adapter;
+	struct hinic3_adev *hadev;
+	bool timeout = true;
+	unsigned long end;
+
+	end = jiffies + msecs_to_jiffies(HINIC3_EVENT_PROCESS_TIMEOUT);
+	do {
+		if (!test_and_set_bit(svc_type, &pci_adapter->state)) {
+			timeout = false;
+			break;
Quoted 9 lines

drivers/net/ethernet/huawei/hinic3/hinic3_lld.c line 101

Quoted 6 lines
drivers/net/ethernet/huawei/hinic3/hinic3_lld.c new file +6 -0
+		}
+		usleep_range(900, 1000);
+	} while (time_before(jiffies, end));
+
+	if (timeout && !test_and_set_bit(svc_type, &pci_adapter->state))
+		timeout = false;

Please look at using iopoll.h

Ack

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +7 -0
+static int hinic3_sw_init(struct net_device *netdev)
+{
+	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+	struct hinic3_hwdev *hwdev = nic_dev->hwdev;
+	int err;
+
+	nic_dev->q_params.sq_depth = HINIC3_SQ_DEPTH;
Quoted 9 lines

drivers/net/ethernet/huawei/hinic3/hinic3_main.c line 148

Quoted 5 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +5 -0
+	nic_dev->q_params.rq_depth = HINIC3_RQ_DEPTH;
+
+	hinic3_try_to_enable_rss(netdev);
+
+	eth_hw_addr_random(netdev);

Is using a random MAC just a temporary thing until more code is added to access an OTP?

No, using a random MAC is not a temporary solution.
This device is designed for cloud environments. VFs are expected to be used by VMs that may migrate from device to device. Therefore the HW does not provide a MAC address to VFs, but rather the VF driver selects a random MAC address and configures it into the (current) device.

Once the driver is extended to support PFs, the PF MAC will be obtained from the device.

Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +5 -0
+	err = register_netdev(netdev);
+	if (err) {
+		err = -ENOMEM;
+		goto err_netdev;
+	}
Quoted 9 lines

drivers/net/ethernet/huawei/hinic3/hinic3_main.c line 327

Quoted 4 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +4 -0
+
+	netif_carrier_off(netdev);
+
+	dev_set_drvdata(&adev->dev, nic_dev);

Is this used anywhere in the driver? Calling register_netdev() makes the interface live, even before it returns. If you have NFS root for example, it could be sending packets, etc, before drvdata is set.

Ack

Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c new file +13 -0
+int hinic3_set_port_mtu(struct net_device *netdev, u16 new_mtu)
+{
+	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+	struct hinic3_func_tbl_cfg func_tbl_cfg = {};
+	struct hinic3_hwdev *hwdev = nic_dev->hwdev;
+
+	if (new_mtu < HINIC3_MIN_MTU_SIZE) {
+		dev_err(hwdev->dev,
+			"Invalid mtu size: %ubytes, mtu size < %ubytes\n",
+			new_mtu, HINIC3_MIN_MTU_SIZE);
+		return -EINVAL;
+	}
+
Quoted 8 lines

drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c line 109

Quoted 5 lines
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c new file +5 -0
+	if (new_mtu > HINIC3_MAX_JUMBO_FRAME_SIZE) {
+		dev_err(hwdev->dev, "Invalid mtu size: %ubytes, mtu size > %ubytes\n",
+			new_mtu, HINIC3_MAX_JUMBO_FRAME_SIZE);
+		return -EINVAL;
+	}

The core can do this validation for you, if you set ndev->max_mtu, ndev->min_mtu.

Ack

#6 lore raw

Re: [RFC net-next v02 1/3] net: hinic3: module initialization and tx/rx logic

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +7 -0
+static int hinic3_sw_init(struct net_device *netdev)
+{
+	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+	struct hinic3_hwdev *hwdev = nic_dev->hwdev;
+	int err;
+
+	nic_dev->q_params.sq_depth = HINIC3_SQ_DEPTH;
Quoted 9 lines

drivers/net/ethernet/huawei/hinic3/hinic3_main.c line 148

Quoted 5 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +5 -0
+	nic_dev->q_params.rq_depth = HINIC3_RQ_DEPTH;
+
+	hinic3_try_to_enable_rss(netdev);
+
+	eth_hw_addr_random(netdev);

Is using a random MAC just a temporary thing until more code is added to access an OTP?

Quoted 5 lines

No, using a random MAC is not a temporary solution.
This device is designed for cloud environments. VFs are expected to be used by VMs that may migrate from device to device. Therefore the HW does not provide a MAC address to VFs, but rather the VF driver selects a random MAC address and configures it into the (current) device.

If you look at MAC drivers in general, this is unusual. So it would be good to add a comment why this unusual behaviour is used.

Andrew

author
#7 lore raw

Re: [RFC net-next v02 1/3] net: hinic3: module initialization and tx/rx logic

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

drivers/net/ethernet/huawei/hinic3/hinic3_main.c line 148

Quoted 12 lines
drivers/net/ethernet/huawei/hinic3/hinic3_main.c new file +12 -0
+static int hinic3_sw_init(struct net_device *netdev)
+{
+	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+	struct hinic3_hwdev *hwdev = nic_dev->hwdev;
+	int err;
+
+	nic_dev->q_params.sq_depth = HINIC3_SQ_DEPTH;
+	nic_dev->q_params.rq_depth = HINIC3_RQ_DEPTH;
+
+	hinic3_try_to_enable_rss(netdev);
+
+	eth_hw_addr_random(netdev);

Is using a random MAC just a temporary thing until more code is added to access an OTP?

Quoted 8 lines
Quoted 5 lines

No, using a random MAC is not a temporary solution.
This device is designed for cloud environments. VFs are expected to be used by VMs that may migrate from device to device. Therefore the HW does not provide a MAC address to VFs, but rather the VF driver selects a random MAC address and configures it into the (current) device.

If you look at MAC drivers in general, this is unusual. So it would be good to add a comment why this unusual behaviour is used.

Ack. Just posted PATCH v1. Will add comment for v2.