Skip to contentSkip to conversation

Add iecm and idpf

PATCH New Alan Brady 6 participants 83 messages Jan 28, 2022 – Feb 4, 2022 Page 1 of 5

Subsystems (4)
lore
Share & tools
lore

Alan Brady

author
#0 lore raw

cover Add iecm and idpf

This series introduces both the Intel Ethernet Common Module and the Intel Data Plane Function. This also adds extended features and functionality to virtchnl with virtchnl_2.h.

The format of the series generally follows the flow of driver init to interface open. We go from probe into a hard reset followed by an init task. From there the rest of the netdev_ops and data path are added. Then lastly advanced features and idpf are introduced.

Currently this common layer (iecm) is initially only being used by only the idpf driver (PF driver for SmartNIC). However, the plan is to eventually switch our iavf driver along with future drivers to use this common module. The hope is to better enable code sharing going forward as well as support other developers writing drivers for our hardware

Alan Brady (17):
virtchnl: Add new virtchnl2 ops
iecm: add basic module init and documentation
iecm: add probe and remove
iecm: add api_init and controlq init
iecm: add vport alloc and virtchnl messages
iecm: add virtchnl messages for queues
iecm: finish virtchnl messages
iecm: add interrupts and configure netdev
iecm: alloc vport TX resources
iecm: alloc vport RX resources
iecm: add start_xmit and set_rx_mode
iecm: finish netdev_ops
iecm: implement splitq napi_poll
iecm: implement singleq napi_poll
iecm: implement ethtool callbacks
iecm: implement cloud filters
idpf: introduce idpf driver

Haiyue Wang (2):
iecm: implement flow director
iecm: add advanced rss

 .../device_drivers/ethernet/intel/idpf.rst    |   47 +
 .../device_drivers/ethernet/intel/iecm.rst    |   93 +
 MAINTAINERS                                   |    1 +
 drivers/net/ethernet/intel/Kconfig            |   31 +
 drivers/net/ethernet/intel/Makefile           |    2 +
 drivers/net/ethernet/intel/idpf/Makefile      |   15 +
 drivers/net/ethernet/intel/idpf/idpf_dev.h    |   17 +
 drivers/net/ethernet/intel/idpf/idpf_devids.h |   10 +
 drivers/net/ethernet/intel/idpf/idpf_main.c   |  140 +
 drivers/net/ethernet/intel/idpf/idpf_reg.c    |  130 +
 drivers/net/ethernet/intel/iecm/Makefile      |   21 +
 .../net/ethernet/intel/iecm/iecm_controlq.c   |  649 ++
 .../ethernet/intel/iecm/iecm_controlq_setup.c |  175 +
 .../net/ethernet/intel/iecm/iecm_ethtool.c    | 1332 ++++
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 5717 +++++++++++++++++
 drivers/net/ethernet/intel/iecm/iecm_main.c   |   40 +
 .../ethernet/intel/iecm/iecm_singleq_txrx.c   | 1229 ++++
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 4577 +++++++++++++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 4240 ++++++++++++
 drivers/net/ethernet/intel/include/iecm.h     |  973 +++
 .../ethernet/intel/include/iecm_controlq.h    |  117 +
 .../intel/include/iecm_controlq_api.h         |  185 +
 .../ethernet/intel/include/iecm_lan_pf_regs.h |  131 +
 .../ethernet/intel/include/iecm_lan_txrx.h    |  394 ++
 drivers/net/ethernet/intel/include/iecm_mem.h |   20 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  733 +++
 include/linux/avf/virtchnl.h                  | 1507 ++++-
 include/linux/avf/virtchnl_2.h                | 1243 ++++
 include/linux/avf/virtchnl_lan_desc.h         |  603 ++
 29 files changed, 24255 insertions(+), 117 deletions(-)
 create mode 100644 Documentation/networking/device_drivers/ethernet/intel/idpf.rst
 create mode 100644 Documentation/networking/device_drivers/ethernet/intel/iecm.rst
 create mode 100644 drivers/net/ethernet/intel/idpf/Makefile
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_dev.h
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_devids.h
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_main.c
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_reg.c
 create mode 100644 drivers/net/ethernet/intel/iecm/Makefile
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_ethtool.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_lib.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_main.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_lan_pf_regs.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_lan_txrx.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_txrx.h
 create mode 100644 include/linux/avf/virtchnl_2.h
 create mode 100644 include/linux/avf/virtchnl_lan_desc.h
Signature · 1 line
2.33.0
author
#1 lore raw

PATCH 1/19 virtchnl: Add new virtchnl2 ops

This extends the virtchnl interface to add new virtchnl ops and defines needed to implement virtchnl 2.0.

---
 MAINTAINERS                           |    1 +
 include/linux/avf/virtchnl.h          | 1507 +++++++++++++++++++++++--
 include/linux/avf/virtchnl_2.h        | 1243 ++++++++++++++++++++
 include/linux/avf/virtchnl_lan_desc.h |  603 ++++++++++
 4 files changed, 3237 insertions(+), 117 deletions(-)
 create mode 100644 include/linux/avf/virtchnl_2.h
 create mode 100644 include/linux/avf/virtchnl_lan_desc.h
MAINTAINERS +1 -0
index 0d7883977e9b..5685d64afd76 100644
@@ -9602,6 +9602,7 @@ F:	Documentation/networking/device_drivers/ethernet/intel/
 F:	drivers/net/ethernet/intel/
 F:	drivers/net/ethernet/intel/*/
 F:	include/linux/avf/virtchnl.h
+F:	include/linux/avf/virtchnl_2.h
 F:	include/linux/net/intel/iidc.h
 
 INTEL ETHERNET PROTOCOL DRIVER FOR RDMA
include/linux/avf/virtchnl.h +1390 -117

1,905 lines not on this page · raw message

include/linux/avf/virtchnl_2.h new file +1243 -0

1,088 lines not on this page · raw message

include/linux/avf/virtchnl_lan_desc.h new file +603 -0

603 lines not on this page · raw message

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

Signature · 1 line
2.33.0

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

author
#3 lore raw

PATCH 2/19 iecm: add basic module init and documentation

In reply to Alan Brady

This adds the basics needed to make a kernel module and documentation needed to use iecm module.

---
 .../device_drivers/ethernet/intel/iecm.rst    | 93 +++++++++++++++++++
 drivers/net/ethernet/intel/Kconfig            | 15 +++
 drivers/net/ethernet/intel/Makefile           |  1 +
 drivers/net/ethernet/intel/iecm/Makefile      | 13 +++
 drivers/net/ethernet/intel/iecm/iecm_main.c   | 40 ++++++++
 drivers/net/ethernet/intel/include/iecm.h     | 10 ++
 6 files changed, 172 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/intel/iecm.rst
 create mode 100644 drivers/net/ethernet/intel/iecm/Makefile
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_main.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm.h
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +93 -0
new file mode 100644
index 000000000000..5634e3e65c74
@@ -0,0 +1,93 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+========================
+Intel Ethernet Common Module
+========================
+
+The Intel Ethernet Common Module is meant to serve as an abstraction layer
+between device specific implementation details and common net device driver
+flows. This library provides several function hooks which allow a device driver
+to specify register addresses, control queue communications, and other device
+specific functionality.  Some functions are required to be implemented while
+others have a default implementation that is used when none is supplied by the
+device driver.  Doing this, a device driver can be written to take advantage
+of existing code while also giving the flexibility to implement device specific
+features.
+
+The common use case for this library is for a network device driver that wants
+specify its own device specific details but also leverage the more common
+code flows found in network device drivers.
+
+Sections in this document:
+	Entry Point
+	Exit Point
+	Register Operations API
+	Virtchnl Operations API
+
+Entry Point
+~~~~~~~~~~~
+The primary entry point to the library is the iecm_probe function.  Prior to
+calling this, device drivers must have allocated an iecm_adapter struct and
+initialized it with the required API functions.  The adapter struct, along with
+the pci_dev struct and the pci_device_id struct, is provided to iecm_probe
+which finalizes device initialization and prepares the device for open.
+
+The iecm_dev_ops struct within the iecm_adapter struct is the primary vehicle
+for passing information from device drivers to the common module.  A dependent
+module must define and assign a reg_ops_init function which will assign the
+respective function pointers to initialize register values (see iecm_reg_ops
+struct).  These are required to be provided by the dependent device driver as
+no suitable default can be assumed for register addresses.
+
+The vc_ops_init function pointer and the related iecm_virtchnl_ops struct are
+optional and should only be necessary for device drivers which use a different
+method/timing for communicating across a mailbox to the hardware.  Within iecm
+is a default interface provided in the case where one is not provided by the
+device driver.
+
+Exit Point
+~~~~~~~~~~
+When the device driver is being prepared to be removed through the pci_driver
+remove callback, it is required for the device driver to call iecm_remove with
+the pci_dev struct provided.  This is required to ensure all resources are
+properly freed and returned to the operating system.
+
+Register Operations API
+~~~~~~~~~~~~~~~~~~~~~~~
+iecm_reg_ops contains three different function pointers relating to initializing
+registers for the specific net device using the library.
+
+ctlq_reg_init relates specifically to setting up registers related to control
+queue/mailbox communications.  Registers that should be defined include: head,
+tail, len, bah, bal, len_mask, len_ena_mask, and head_mask.
+
+vportq_reg_init relates to setting up queue registers.  The tail registers to
+be assigned to the iecm_queue struct for each RX/TX queue.
+
+intr_reg_init relates to any registers needed to setup interrupts.  These
+include registers needed to enable the interrupt and change ITR settings.
+
+If the initialization function finds that one or more required function
+pointers were not provided, an error will be issued and the device will be
+inoperable.
+
+
+Virtchnl Operations API
+~~~~~~~~~~~~~~~~~~~~~~~
+The virtchnl is a conduit between driver and hardware that allows device
+drivers to send and receive control messages to/from hardware.  This is
+optional to be specified as there is a general interface that can be assumed
+when using this library.  However, if a device deviates in some way to
+communicate across the mailbox correctly, this interface is provided to allow
+that.
+
+If vc_ops_init is set in the dev_ops field of the iecm_adapter struct, then it
+is assumed the device driver is using providing it's own interface to do
+virtchnl communications.  While providing vc_ops_init is optional, if it is
+provided, it is required that the device driver provide function pointers for
+those functions in vc_ops, with exception for the enable_vport, disable_vport,
+and destroy_vport functions which may not be required for all devices.
+
+If the initialization function finds that vc_ops_init was defined but one or
+more required function pointers were not provided, an error will be issued and
+the device will be inoperable.
drivers/net/ethernet/intel/Kconfig +15 -0
index 3facb55b7161..754dc7677ad5 100644
@@ -372,4 +372,19 @@ config IGC
 	  To compile this driver as a module, choose M here. The module
 	  will be called igc.
 
+config IECM
+	tristate "Intel(R) Ethernet Common Module Support"
+	default n
+	depends on PCI_MSI
+	select DIMLIB
+	help
+      This supplies needed functions to device specific device drivers
+      implementing common module.
+
+	  More specific information on configuring the driver is in
+	  <file:Documentation/networking/device_drivers/ethernet/intel/iecm.rst>.
+
+      To compile this as a module, choose M here. The module will be called
+      iecm.
+
 endif # NET_VENDOR_INTEL
drivers/net/ethernet/intel/Makefile +1 -0
index 3075290063f6..c9eba9cc5087 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_IXGB) += ixgb/
 obj-$(CONFIG_IAVF) += iavf/
 obj-$(CONFIG_FM10K) += fm10k/
 obj-$(CONFIG_ICE) += ice/
+obj-$(CONFIG_IECM) += iecm/
drivers/net/ethernet/intel/iecm/Makefile new file +13 -0
new file mode 100644
index 000000000000..d2d087ac71e9
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2019 Intel Corporation
+
+#
+# Makefile for the Intel(R) Data Plane Function Linux Driver
+#
+
+obj-$(CONFIG_IECM) += iecm.o
+
+ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
+
+iecm-y := \
+	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_main.c new file +40 -0
new file mode 100644
index 000000000000..7c09403c6918
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2019 Intel Corporation */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include "iecm.h"
+
+#define DRV_SUMMARY	"Intel(R) Ethernet Common Module"
+static const char iecm_driver_string[] = DRV_SUMMARY;
+static const char iecm_copyright[] = "Copyright (c) 2020, Intel Corporation.";
+
+MODULE_DESCRIPTION(DRV_SUMMARY);
+MODULE_LICENSE("GPL v2");
+
+/**
+ * iecm_module_init - Driver registration routine
+ *
+ * iecm_module_init is the first routine called when the driver is
+ * loaded. All it does is register with the PCI subsystem.
+ */
+static int __init iecm_module_init(void)
+{
+	pr_info("%s - version %d\n", iecm_driver_string, LINUX_VERSION_CODE);
+	pr_info("%s\n", iecm_copyright);
+
+	return 0;
+}
+module_init(iecm_module_init);
+
+/**
+ * iecm_module_exit - Driver exit cleanup routine
+ *
+ * iecm_module_exit is called just before the driver is removed
+ * from memory.
+ */
+static void __exit iecm_module_exit(void)
+{
+	pr_info("module unloaded\n");
+}
+module_exit(iecm_module_exit);
drivers/net/ethernet/intel/include/iecm.h new file +10 -0
new file mode 100644
index 000000000000..f66f0d7db8e7
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2019 Intel Corporation */
+
+#ifndef _IECM_H_
+#define _IECM_H_
+
+#include <linux/etherdevice.h>
+#include <linux/version.h>
+
+#endif /* !_IECM_H_ */
Signature · 1 line
2.33.0
author
#8 lore raw

PATCH 3/19 iecm: add probe and remove

In reply to Alan Brady

This adds everything we need in probe and remove as well as a few stubs which will kick off the next step in the init process of device driver coming up.

---
 drivers/net/ethernet/intel/iecm/Makefile      |   1 +
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 231 ++++++++++++++++++
 drivers/net/ethernet/intel/include/iecm.h     | 178 +++++++++++++-
 .../net/ethernet/intel/include/iecm_txrx.h    |  33 +++
 4 files changed, 442 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_lib.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm_txrx.h
drivers/net/ethernet/intel/iecm/Makefile +1 -0
index d2d087ac71e9..4f497723419d 100644
@@ -10,4 +10,5 @@ obj-$(CONFIG_IECM) += iecm.o
 ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
 
 iecm-y := \
+	iecm_lib.o \
 	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +231 -0

231 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +177 -1

184 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_txrx.h new file +33 -0
new file mode 100644
index 000000000000..602d3b3b19dd
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2019 Intel Corporation */
+
+#ifndef _IECM_TXRX_H_
+#define _IECM_TXRX_H_
+
+#define IECM_LARGE_MAX_Q			256
+#define IECM_MAX_Q				16
+/* Mailbox Queue */
+#define IECM_MAX_NONQ				1
+#define IECM_MAX_TXQ_DESC			4096
+#define IECM_MAX_RXQ_DESC			4096
+#define IECM_MIN_TXQ_DESC			32
+#define IECM_MIN_TXQ_COMPLQ_DESC		64
+#define IECM_MIN_RXQ_DESC			32
+#define IECM_REQ_DESC_MULTIPLE			32
+#define IECM_REQ_SPLITQ_RXQ_DESC_MULTIPLE	64
+#define IECM_MIN_TX_DESC_NEEDED (MAX_SKB_FRAGS + 6)
+#define IECM_TX_WAKE_THRESH ((s16)IECM_MIN_TX_DESC_NEEDED * 2)
+
+#define IECM_DFLT_SINGLEQ_TX_Q_GROUPS		1
+#define IECM_DFLT_SINGLEQ_RX_Q_GROUPS		1
+#define IECM_DFLT_SINGLEQ_TXQ_PER_GROUP		4
+#define IECM_DFLT_SINGLEQ_RXQ_PER_GROUP		4
+
+#define IECM_COMPLQ_PER_GROUP			1
+#define IECM_MAX_BUFQS_PER_RXQ_GRP		2
+
+#define IECM_DFLT_SPLITQ_TX_Q_GROUPS		4
+#define IECM_DFLT_SPLITQ_RX_Q_GROUPS		4
+#define IECM_DFLT_SPLITQ_TXQ_PER_GROUP		1
+#define IECM_DFLT_SPLITQ_RXQ_PER_GROUP		1
+#endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0
author
#11 lore raw

PATCH 4/19 iecm: add api_init and controlq init

In reply to Alan Brady

Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.

At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.

---
 drivers/net/ethernet/intel/iecm/Makefile      |   3 +
 .../net/ethernet/intel/iecm/iecm_controlq.c   | 649 ++++++++++++++++++
 .../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 191 +++++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 172 +++++
 drivers/net/ethernet/intel/include/iecm.h     |  52 ++
 .../ethernet/intel/include/iecm_controlq.h    | 117 ++++
 .../intel/include/iecm_controlq_api.h         | 185 +++++
 drivers/net/ethernet/intel/include/iecm_mem.h |  20 +
 9 files changed, 1563 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h
drivers/net/ethernet/intel/iecm/Makefile +3 -0
index 4f497723419d..db8fecb075a6 100644
@@ -11,4 +11,7 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
 
 iecm-y := \
 	iecm_lib.o \
+	iecm_virtchnl.o \
+	iecm_controlq.o \
+	iecm_controlq_setup.o \
 	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +649 -0

649 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +175 -0

175 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_lib.c +190 -1

253 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +172 -0

172 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +52 -0

93 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_controlq.h new file +117 -0

117 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +185 -0

185 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_mem.h new file +20 -0
new file mode 100644
index 000000000000..064dd6e10c24
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2019 Intel Corporation */
+
+#ifndef _IECM_MEM_H_
+#define _IECM_MEM_H_
+
+#include <linux/io.h>
+
+struct iecm_dma_mem {
+	void *va;
+	dma_addr_t pa;
+	size_t size;
+};
+
+#define wr32(a, reg, value)	writel((value), ((a)->hw_addr + (reg)))
+#define rd32(a, reg)		readl((a)->hw_addr + (reg))
+#define wr64(a, reg, value)	writeq((value), ((a)->hw_addr + (reg)))
+#define rd64(a, reg)		readq((a)->hw_addr + (reg))
+
+#endif /* _IECM_MEM_H_ */
Signature · 1 line
2.33.0
author
#19 lore raw

PATCH 5/19 iecm: add vport alloc and virtchnl messages

In reply to Alan Brady

After handling hard reset, we end up in init task. This starts by allocating and setting up a vport. To do that we need implement virtchnl messages.

The virtchnl messages are also offloaded into function pointers so that a device driver may override them. Here a default implementation is provided for devices using virtchnl 2.0 but there exists the flexibility add virtchnl 1.1 support through function pointers.

---
 drivers/net/ethernet/intel/iecm/Makefile      |    4 +-
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |  167 ++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |   22 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1299 +++++++++++++++++
 drivers/net/ethernet/intel/include/iecm.h     |  316 +++-
 .../net/ethernet/intel/include/iecm_txrx.h    |   94 ++
 6 files changed, 1898 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.c
drivers/net/ethernet/intel/iecm/Makefile +3 -1
index db8fecb075a6..fcb49402334f 100644
@@ -7,11 +7,13 @@
 
 obj-$(CONFIG_IECM) += iecm.o
 
-ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
+ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include \
+	     -I$(srctree)/include/linux/avf
 
 iecm-y := \
 	iecm_lib.o \
 	iecm_virtchnl.o \
+	iecm_txrx.o \
 	iecm_controlq.o \
 	iecm_controlq_setup.o \
 	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_lib.c +165 -2

197 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_txrx.c new file +22 -0
new file mode 100644
index 000000000000..2f5c16a28266
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2019 Intel Corporation */
+
+#include "iecm.h"
+
+/**
+ * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ *
+ */
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
+{
+	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+
+	q_vector->total_events++;
+	napi_schedule(&q_vector->napi);
+
+	return IRQ_HANDLED;
+}
+
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1299 -0

1,314 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +315 -1

379 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_txrx.h +94 -0

98 lines not on this page · raw message

Signature · 1 line
2.33.0
author
#26 lore raw

PATCH 6/19 iecm: add virtchnl messages for queues

In reply to Alan Brady

This continues adding virtchnl messages. This largely relates to adding messages needed to negotiate and setup traffic queues.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   14 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  161 +++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1127 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   22 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  196 +++
 5 files changed, 1505 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +14 -0
index e2e523f0700e..4e9cc7f2d138 100644
@@ -90,6 +90,20 @@ static void iecm_vport_rel_all(struct iecm_adapter *adapter)
 	adapter->num_alloc_vport = 0;
 }
 
+/**
+ * iecm_vport_set_hsplit - enable or disable header split on a given vport
+ * @vport: virtual port
+ * @ena: flag controlling header split, On (true) or Off (false)
+ */
+void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena)
+{
+	if (iecm_is_cap_ena_all(vport->adapter, IECM_HSPLIT_CAPS,
+				IECM_CAP_HSPLIT) &&
+	    iecm_is_queue_model_split(vport->rxq_model))
+		set_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+			vport->adapter->config_data.user_flags);
+}
+
 /**
  * iecm_vport_alloc - Allocates the next available struct vport in the adapter
  * @adapter: board private structure
drivers/net/ethernet/intel/iecm/iecm_txrx.c +161 -0

164 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1112 -15

1,175 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +22 -0
index 994664dfe419..8dd6272db7d3 100644
@@ -432,6 +432,8 @@ struct iecm_adapter {
 	u16 num_alloc_vport;
 	u16 next_vport;		/* Next free slot in pf->vport[] - 0-based! */
 
+	u16 max_queue_limit;	/* Max number of queues user can request */
+
 	struct delayed_work init_task; /* delayed init task */
 	struct workqueue_struct *init_wq;
 	u32 mb_wait_count;
@@ -510,6 +512,12 @@ static inline bool __iecm_is_cap_ena(struct iecm_adapter *adapter, bool all,
 	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field, flag);
 }
 
+#define IECM_CAP_HSPLIT (\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure
@@ -530,6 +538,8 @@ int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
 int iecm_vc_core_init(struct iecm_adapter *adapter, int *vport_id);
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs);
 int iecm_wait_for_event(struct iecm_adapter *adapter,
 			enum iecm_vport_vc_state state,
 			enum iecm_vport_vc_state err_check);
@@ -537,6 +547,14 @@ int iecm_min_wait_for_event(struct iecm_adapter *adapter,
 			    enum iecm_vport_vc_state state,
 			    enum iecm_vport_vc_state err_check);
 int iecm_send_get_caps_msg(struct iecm_adapter *adapter);
+int iecm_send_delete_queues_msg(struct iecm_vport *vport);
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
+int iecm_send_enable_vport_msg(struct iecm_vport *vport);
+int iecm_send_disable_vport_msg(struct iecm_vport *vport);
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
@@ -546,7 +564,11 @@ int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     void *msg, int msg_size);
 int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
+void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
+int iecm_send_enable_channels_msg(struct iecm_vport *vport);
+int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport, bool map);
 #endif /* !_IECM_H_ */
drivers/net/ethernet/intel/include/iecm_txrx.h +196 -0

208 lines not on this page · raw message

Signature · 1 line
2.33.0
author
#31 lore raw

PATCH 7/19 iecm: finish virtchnl messages

In reply to Alan Brady

This adds the rest of the needed virtchnl messages mostly related to negotiating ptypes and initializing queue registers.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   21 +-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  226 +++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1187 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   36 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  198 ++-
 5 files changed, 1635 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +20 -1
index 4e9cc7f2d138..aab8ee40424e 100644
@@ -10,6 +10,25 @@ const char * const iecm_vport_vc_state_str[] = {
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_is_feature_ena - Determine if a particular feature is enabled
+ * @vport: vport to check
+ * @feature: netdev flag to check
+ *
+ * Returns true or false if a particular feature is enabled.
+ */
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)
+{
+	bool ena;
+
+	switch (feature) {
+	default:
+		ena = vport->netdev->features & feature;
+		break;
+	}
+	return ena;
+}
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -132,7 +151,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = iecm_vport_intr_clean_queues;
+	vport->irq_q_handler = NULL;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
drivers/net/ethernet/intel/iecm/iecm_txrx.c +212 -14

234 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1172 -15

1,241 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +36 -0
index 8dd6272db7d3..d736db65da06 100644
@@ -346,6 +346,7 @@ struct iecm_vport {
 	int num_rxq_grp;
 	struct iecm_rxq_group *rxq_grps;
 	u32 rxq_model;
+	struct iecm_rx_ptype_decoded rx_ptype_lkup[IECM_RX_MAX_PTYPE];
 
 	struct iecm_adapter *adapter;
 	struct net_device *netdev;
@@ -382,6 +383,30 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+#define IECM_GET_PTYPE_SIZE(p) \
+	(sizeof(struct virtchnl2_ptype) + \
+	(((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof(u16)))
+
+#define IECM_TUN_IP_GRE (\
+	IECM_PTYPE_TUNNEL_IP |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT)
+
+#define IECM_TUN_IP_GRE_MAC (\
+	IECM_TUN_IP_GRE |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC)
+
+enum iecm_tunnel_state {
+	IECM_PTYPE_TUNNEL_IP                    = BIT(0),
+	IECM_PTYPE_TUNNEL_IP_GRENAT             = BIT(1),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC         = BIT(2),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN    = BIT(3),
+};
+
+struct iecm_ptype_state {
+	bool outer_ip;
+	bool outer_frag;
+	u8 tunnel_state;
+};
 /* User defined configuration values */
 struct iecm_user_config_data {
 	u32 num_req_tx_qs; /* user requested TX queues through ethtool */
@@ -534,6 +559,7 @@ int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter);
 void iecm_remove(struct pci_dev *pdev);
+void iecm_vport_adjust_qs(struct iecm_vport *vport);
 int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
@@ -555,8 +581,15 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
 int iecm_send_enable_vport_msg(struct iecm_vport *vport);
 int iecm_send_disable_vport_msg(struct iecm_vport *vport);
 int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
+int iecm_send_get_rx_ptype_msg(struct iecm_vport *vport);
+int iecm_send_get_set_rss_key_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_lut_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_hash_msg(struct iecm_vport *vport, bool get);
+int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter);
+int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
+int iecm_send_get_stats_msg(struct iecm_vport *vport);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
 		     u16 *vecids, int num_vecids,
 		     struct virtchnl2_vector_chunks *chunks);
@@ -567,6 +600,9 @@ int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);
 int iecm_send_disable_channels_msg(struct iecm_vport *vport);
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature);
+int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
+		     u64 tx_desc_ids, u16 rxq_model, u16 txq_model);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
drivers/net/ethernet/intel/include/iecm_txrx.h +195 -3

216 lines not on this page · raw message

Signature · 1 line
2.33.0
author
#36 lore raw

PATCH 8/19 iecm: add interrupts and configure netdev

In reply to Alan Brady

This finishes implementing init_task by adding everything we need to configure the netdevice for the vport and setup its interrupts.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 813 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  17 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 165 ++++
 drivers/net/ethernet/intel/include/iecm.h     | 112 ++-
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 1104 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +812 -1
index aab8ee40424e..255b04c25683 100644
@@ -5,11 +5,35 @@
 
 #include "iecm.h"
 
+static const struct net_device_ops iecm_netdev_ops_splitq;
+static const struct net_device_ops iecm_netdev_ops_singleq;
+
 const char * const iecm_vport_vc_state_str[] = {
 	IECM_FOREACH_VPORT_VC_STATE(IECM_GEN_STRING)
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_get_vport_index - Get the vport index
+ * @adapter: adapter structure to get the vports array
+ * @vport: vport pointer for which the index to find
+ */
+static int iecm_get_vport_index(struct iecm_adapter *adapter,
+				struct iecm_vport *vport)
+{
+	int i, err = -EINVAL;
+
+	if (!adapter->vports)
+		return err;
+
+	for (i = 0; i < adapter->num_alloc_vport; i++) {
+		if (adapter->vports[i] != vport)
+			continue;
+		return i;
+	}
+	return err;
+}
+
 /**
  * iecm_is_feature_ena - Determine if a particular feature is enabled
  * @vport: vport to check
@@ -29,6 +53,595 @@ bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)
 	return ena;
 }
 
+/**
+ * iecm_is_vlan_cap_ena - Check if VLAN capability is enabled
+ * @adapter: pointer to adapter
+ * @vcaps: VLAN capability bit
+ *
+ * Returns true if VLAN capability is set, false otherwise
+ */
+static bool iecm_is_vlan_cap_ena(struct iecm_adapter *adapter,
+				 enum iecm_vlan_caps vcaps)
+{
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN)) {
+		struct virtchnl_vlan_supported_caps *offload;
+
+		if (!adapter->vlan_caps)
+			return false;
+
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_8100) == IECM_VLAN_8100 ||
+			    (offload->inner & IECM_VLAN_8100) == IECM_VLAN_8100)
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_INSERT:
+			offload =
+			&adapter->vlan_caps->offloads.insertion_support;
+			if ((offload->outer & IECM_VLAN_88A8) == IECM_VLAN_88A8)
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_8100) == IECM_VLAN_8100 ||
+			    (offload->inner & IECM_VLAN_8100) == IECM_VLAN_8100)
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_STRIP:
+			offload =
+			&adapter->vlan_caps->offloads.stripping_support;
+			if ((offload->outer & IECM_VLAN_88A8) == IECM_VLAN_88A8)
+				return true;
+			break;
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) ||
+			    (offload->inner & VIRTCHNL_VLAN_ETHERTYPE_8100))
+				return true;
+			break;
+		case IECM_CAP_VLAN_STAG_ADD_DEL:
+			offload =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if ((offload->outer & VIRTCHNL_VLAN_ETHERTYPE_88A8) ||
+			    (offload->inner & VIRTCHNL_VLAN_ETHERTYPE_88A8))
+				return true;
+			break;
+		default:
+			dev_err(&adapter->pdev->dev, "Invalid VLAN capability %d\n",
+				vcaps);
+			return false;
+		}
+	} else if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				   VIRTCHNL2_CAP_VLAN)) {
+		switch (vcaps) {
+		case IECM_CAP_VLAN_CTAG_INSERT:
+		case IECM_CAP_VLAN_CTAG_STRIP:
+		case IECM_CAP_VLAN_CTAG_ADD_DEL:
+			return true;
+		default:
+			return false;
+		}
+	}
+
+	return false;
+}
+
+/**
+ * iecm_netdev_to_vport - get a vport handle from a netdev
+ * @netdev: network interface device structure
+ */
+struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return np->vport;
+}
+
+/**
+ * iecm_mb_intr_rel_irq - Free the IRQ association with the OS
+ * @adapter: adapter structure
+ */
+static void iecm_mb_intr_rel_irq(struct iecm_adapter *adapter)
+{
+	int irq_num;
+
+	irq_num = adapter->msix_entries[0].vector;
+	free_irq(irq_num, adapter);
+}
+
+/**
+ * iecm_intr_rel - Release interrupt capabilities and free memory
+ * @adapter: adapter to disable interrupts on
+ */
+static void iecm_intr_rel(struct iecm_adapter *adapter)
+{
+	if (!adapter->msix_entries)
+		return;
+	clear_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	clear_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	iecm_mb_intr_rel_irq(adapter);
+
+	pci_free_irq_vectors(adapter->pdev);
+	if (adapter->dev_ops.vc_ops.dealloc_vectors) {
+		int err;
+
+		err = adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to deallocate vectors: %d\n", err);
+		}
+	}
+	kfree(adapter->msix_entries);
+	adapter->msix_entries = NULL;
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+}
+
+/**
+ * iecm_mb_intr_clean - Interrupt handler for the mailbox
+ * @irq: interrupt number
+ * @data: pointer to the adapter structure
+ */
+static irqreturn_t iecm_mb_intr_clean(int __always_unused irq, void *data)
+{
+	struct iecm_adapter *adapter = (struct iecm_adapter *)data;
+
+	set_bit(__IECM_MB_INTR_TRIGGER, adapter->flags);
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(0));
+	return IRQ_HANDLED;
+}
+
+/**
+ * iecm_mb_irq_enable - Enable MSIX interrupt for the mailbox
+ * @adapter: adapter to get the hardware address for register write
+ */
+static void iecm_mb_irq_enable(struct iecm_adapter *adapter)
+{
+	struct iecm_hw *hw = &adapter->hw;
+	struct iecm_intr_reg *intr = &adapter->mb_vector.intr_reg;
+	u32 val;
+
+	val = intr->dyn_ctl_intena_m | intr->dyn_ctl_itridx_m;
+	wr32(hw, intr->dyn_ctl, val);
+	wr32(hw, intr->icr_ena, intr->icr_ena_ctlq_m);
+}
+
+/**
+ * iecm_mb_intr_req_irq - Request irq for the mailbox interrupt
+ * @adapter: adapter structure to pass to the mailbox irq handler
+ */
+static int iecm_mb_intr_req_irq(struct iecm_adapter *adapter)
+{
+	struct iecm_q_vector *mb_vector = &adapter->mb_vector;
+	int irq_num, mb_vidx = 0, err;
+
+	irq_num = adapter->msix_entries[mb_vidx].vector;
+	snprintf(mb_vector->name, sizeof(mb_vector->name) - 1,
+		 "%s-%s-%d", dev_driver_string(&adapter->pdev->dev),
+		 "Mailbox", mb_vidx);
+	err = request_irq(irq_num, adapter->irq_mb_handler, 0,
+			  mb_vector->name, adapter);
+	if (err) {
+		dev_err(&adapter->pdev->dev,
+			"Request_irq for mailbox failed, error: %d\n", err);
+		return err;
+	}
+	set_bit(__IECM_MB_INTR_MODE, adapter->flags);
+	return 0;
+}
+
+/**
+ * iecm_get_mb_vec_id - Get vector index for mailbox
+ * @adapter: adapter structure to access the vector chunks
+ *
+ * The first vector id in the requested vector chunks from the CP is for
+ * the mailbox
+ */
+static void iecm_get_mb_vec_id(struct iecm_adapter *adapter)
+{
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_get_capabilities *caps;
+
+		caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+		adapter->mb_vector.v_idx = le16_to_cpu(caps->mailbox_vector_id);
+	} else {
+		adapter->mb_vector.v_idx = 0;
+	}
+}
+
+/**
+ * iecm_mb_intr_init - Initialize the mailbox interrupt
+ * @adapter: adapter structure to store the mailbox vector
+ */
+static int iecm_mb_intr_init(struct iecm_adapter *adapter)
+{
+	adapter->dev_ops.reg_ops.mb_intr_reg_init(adapter);
+	adapter->irq_mb_handler = iecm_mb_intr_clean;
+	return iecm_mb_intr_req_irq(adapter);
+}
+
+/**
+ * iecm_intr_distribute - Distribute MSIX vectors
+ * @adapter: adapter structure to get the vports
+ * @pre_req: before or after msi request
+ *
+ * Distribute the MSIX vectors acquired from the OS to the vports based on the
+ * num of vectors requested by each vport
+ */
+static int
+iecm_intr_distribute(struct iecm_adapter *adapter, bool pre_req)
+{
+	struct iecm_vport *vport = adapter->vports[0];
+	int err = 0;
+
+	if (pre_req) {
+		u16 vecs_avail;
+
+		vecs_avail = iecm_get_reserved_vecs(adapter);
+		if (vecs_avail < IECM_MIN_VEC) {
+			return -EAGAIN;
+		} else if (vecs_avail == IECM_MIN_VEC) {
+			vport->num_q_vectors = IECM_MIN_Q_VEC;
+		} else {
+			vport->num_q_vectors = vecs_avail - IECM_NONQ_VEC -
+						IECM_MAX_RDMA_VEC;
+		}
+	} else {
+		if (adapter->num_msix_entries != adapter->num_req_msix)
+			vport->num_q_vectors = adapter->num_msix_entries -
+					       IECM_NONQ_VEC;
+	}
+
+	return err;
+}
+
+/**
+ * iecm_intr_req - Request interrupt capabilities
+ * @adapter: adapter to enable interrupts on
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_intr_req(struct iecm_adapter *adapter)
+{
+	int min_vectors, max_vectors, err = 0;
+	int num_q_vecs, total_num_vecs;
+	u16 vecids[IECM_MAX_VECIDS];
+	unsigned int vector;
+	int v_actual;
+
+	err = iecm_intr_distribute(adapter, true);
+	if (err)
+		return err;
+
+	num_q_vecs = adapter->vports[0]->num_q_vectors;
+
+	total_num_vecs = num_q_vecs + IECM_NONQ_VEC;
+
+	if (adapter->dev_ops.vc_ops.alloc_vectors) {
+		err = adapter->dev_ops.vc_ops.alloc_vectors(adapter,
+							    num_q_vecs);
+		if (err) {
+			dev_err(&adapter->pdev->dev,
+				"Failed to allocate vectors: %d\n", err);
+			return -EAGAIN;
+		}
+	}
+
+	min_vectors = IECM_MIN_VEC;
+	max_vectors = total_num_vecs;
+	v_actual = pci_alloc_irq_vectors(adapter->pdev, min_vectors,
+					 max_vectors, PCI_IRQ_MSIX);
+	if (v_actual < 0) {
+		dev_err(&adapter->pdev->dev, "Failed to allocate MSIX vectors: %d\n",
+			v_actual);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -EAGAIN;
+	}
+
+	adapter->msix_entries = kcalloc(v_actual, sizeof(struct msix_entry),
+					GFP_KERNEL);
+
+	if (!adapter->msix_entries) {
+		pci_free_irq_vectors(adapter->pdev);
+		if (adapter->dev_ops.vc_ops.dealloc_vectors)
+			adapter->dev_ops.vc_ops.dealloc_vectors(adapter);
+		return -ENOMEM;
+	}
+
+	iecm_get_mb_vec_id(adapter);
+
+	if (adapter->req_vec_chunks) {
+		struct virtchnl2_vector_chunks *vchunks;
+		struct virtchnl2_alloc_vectors *ac;
+
+		ac = adapter->req_vec_chunks;
+		vchunks = &ac->vchunks;
+
+		iecm_get_vec_ids(adapter, vecids, IECM_MAX_VECIDS, vchunks);
+	} else {
+		int i = 0;
+
+		for (i = 0; i < v_actual; i++)
+			vecids[i] = i;
+	}
+
+	for (vector = 0; vector < v_actual; vector++) {
+		adapter->msix_entries[vector].entry = vecids[vector];
+		adapter->msix_entries[vector].vector =
+			pci_irq_vector(adapter->pdev, vector);
+	}
+	adapter->num_msix_entries = v_actual;
+	adapter->num_req_msix = total_num_vecs;
+
+	iecm_intr_distribute(adapter, false);
+
+	err = iecm_mb_intr_init(adapter);
+	if (err)
+		goto intr_rel;
+	iecm_mb_irq_enable(adapter);
+	return err;
+
+intr_rel:
+	iecm_intr_rel(adapter);
+	return err;
+}
+
+/**
+ * iecm_find_mac_filter - Search filter list for specific mac filter
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter object or NULL. Must be called while holding the
+ * mac_filter_list_lock.
+ **/
+static struct
+iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
+				      const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return NULL;
+
+	list_for_each_entry(f, &adapter->config_data.mac_filter_list, list) {
+		if (ether_addr_equal(macaddr, f->macaddr))
+			return f;
+	}
+	return NULL;
+}
+
+/**
+ * __iecm_add_mac_filter - Add mac filter helper function
+ * @vport: main vport struct
+ * @macaddr: address to add
+ *
+ * Takes mac_filter_list_lock spinlock to add new filter to list.
+ */
+static struct
+iecm_mac_filter *__iecm_add_mac_filter(struct iecm_vport *vport,
+				       const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f = NULL;
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	if (!f) {
+		f = kzalloc(sizeof(*f), GFP_ATOMIC);
+		if (!f) {
+			dev_err(&adapter->pdev->dev, "Failed to allocate filter: %pM",
+				macaddr);
+			goto error;
+		}
+
+		ether_addr_copy(f->macaddr, macaddr);
+
+		list_add_tail(&f->list, &adapter->config_data.mac_filter_list);
+		f->add = true;
+	} else {
+		f->remove = false;
+	}
+error:
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+
+	return f;
+}
+
+/**
+ * iecm_add_mac_filter - Add a mac filter to the filter list
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Returns ptr to the filter or NULL on error. If interface is up, we'll also
+ * send the virtchnl message to tell hardware about the filter.
+ **/
+static struct iecm_mac_filter *iecm_add_mac_filter(struct iecm_vport *vport,
+						   const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return NULL;
+
+	f = __iecm_add_mac_filter(vport, macaddr);
+	if (!f)
+		return NULL;
+
+	if (vport->adapter->state == __IECM_UP)
+		iecm_add_del_ether_addrs(vport, true, false);
+
+	return f;
+}
+
+/**
+ * iecm_init_mac_addr - initialize mac address for vport
+ * @vport: main vport structure
+ * @netdev: pointer to netdev struct associated with this vport
+ */
+static int iecm_init_mac_addr(struct iecm_vport *vport,
+			      struct net_device *netdev)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!is_valid_ether_addr(vport->default_mac_addr)) {
+		if (!iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+				     VIRTCHNL2_CAP_MACFILTER)) {
+			dev_err(&adapter->pdev->dev,
+				"MAC address not provided and capability is not set\n");
+			return -EINVAL;
+		}
+
+		dev_info(&adapter->pdev->dev, "Invalid MAC address %pM, using random\n",
+			 vport->default_mac_addr);
+		eth_hw_addr_random(netdev);
+
+		if (!iecm_add_mac_filter(vport, netdev->dev_addr))
+			return -ENOMEM;
+
+		ether_addr_copy(vport->default_mac_addr, netdev->dev_addr);
+	} else {
+		dev_addr_mod(netdev, 0, vport->default_mac_addr, ETH_ALEN);
+		ether_addr_copy(netdev->perm_addr, vport->default_mac_addr);
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_cfg_netdev - Allocate, configure and register a netdev
+ * @vport: main vport structure
+ *
+ * Returns 0 on success, negative value on failure.
+ */
+static int iecm_cfg_netdev(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	netdev_features_t dflt_features;
+	netdev_features_t offloads = 0;
+	struct iecm_netdev_priv *np;
+	struct net_device *netdev;
+	u16 max_q;
+	int err;
+
+	lockdep_assert_held(&adapter->sw_mutex);
+
+	/* It's possible we already have a netdev allocated and registered for
+	 * this vport
+	 */
+	if (adapter->netdevs[vport->idx]) {
+		netdev = adapter->netdevs[vport->idx];
+		np = netdev_priv(netdev);
+		np->vport = vport;
+		vport->netdev = netdev;
+
+		return iecm_init_mac_addr(vport, netdev);
+	}
+
+	max_q = adapter->max_queue_limit;
+
+	netdev = alloc_etherdev_mqs(sizeof(struct iecm_netdev_priv),
+				    max_q, max_q);
+	if (!netdev)
+		return -ENOMEM;
+	vport->netdev = netdev;
+	np = netdev_priv(netdev);
+	np->vport = vport;
+
+	err = iecm_init_mac_addr(vport, netdev);
+	if (err)
+		goto err;
+
+	/* assign netdev_ops */
+	if (iecm_is_queue_model_split(vport->txq_model))
+		netdev->netdev_ops = &iecm_netdev_ops_splitq;
+	else
+		netdev->netdev_ops = &iecm_netdev_ops_singleq;
+
+	/* setup watchdog timeout value to be 5 second */
+	netdev->watchdog_timeo = 5 * HZ;
+
+	/* configure default MTU size */
+	netdev->min_mtu = ETH_MIN_MTU;
+	netdev->max_mtu = vport->max_mtu;
+
+	dflt_features = NETIF_F_SG	|
+			NETIF_F_HIGHDMA;
+
+	if (iecm_is_cap_ena_all(adapter, IECM_RSS_CAPS, IECM_CAP_RSS))
+		dflt_features |= NETIF_F_RXHASH;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM_L4V4))
+		dflt_features |= NETIF_F_IP_CSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM_L4V6))
+		dflt_features |= NETIF_F_IPV6_CSUM;
+	if (iecm_is_cap_ena(adapter, IECM_CSUM_CAPS, IECM_CAP_RX_CSUM))
+		dflt_features |= NETIF_F_RXCSUM;
+	if (iecm_is_cap_ena_all(adapter, IECM_CSUM_CAPS, IECM_CAP_SCTP_CSUM))
+		dflt_features |= NETIF_F_SCTP_CRC;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_INSERT))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_STRIP))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_CTAG_ADD_DEL))
+		dflt_features |= IECM_F_HW_VLAN_CTAG_FILTER;
+
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_INSERT))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_TX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_STRIP))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_RX;
+	if (iecm_is_vlan_cap_ena(adapter, IECM_CAP_VLAN_STAG_ADD_DEL))
+		dflt_features |= NETIF_F_HW_VLAN_STAG_FILTER;
+	/* Enable cloud filter if ADQ is supported */
+	if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_ADQ) ||
+	    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+		dflt_features |= NETIF_F_HW_TC;
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS, VIRTCHNL2_CAP_SEG_IPV4_TCP))
+		dflt_features |= NETIF_F_TSO;
+	if (iecm_is_cap_ena(adapter, IECM_SEG_CAPS, VIRTCHNL2_CAP_SEG_IPV6_TCP))
+		dflt_features |= NETIF_F_TSO6;
+	if (iecm_is_cap_ena_all(adapter, IECM_SEG_CAPS,
+				VIRTCHNL2_CAP_SEG_IPV4_UDP |
+				VIRTCHNL2_CAP_SEG_IPV6_UDP))
+		dflt_features |= NETIF_F_GSO_UDP_L4;
+	if (iecm_is_cap_ena_all(adapter, IECM_RSC_CAPS, IECM_CAP_RSC))
+		offloads |= NETIF_F_GRO_HW;
+	netdev->features |= dflt_features;
+	netdev->hw_features |= dflt_features | offloads;
+	netdev->hw_enc_features |= dflt_features | offloads;
+
+	SET_NETDEV_DEV(netdev, &adapter->pdev->dev);
+
+	/* carrier off on init to avoid Tx hangs */
+	netif_carrier_off(netdev);
+
+	/* make sure transmit queues start off as stopped */
+	netif_tx_stop_all_queues(netdev);
+
+	/* register last */
+	err = register_netdev(netdev);
+	if (err)
+		goto err;
+
+	/* The vport can be arbitrarily released so we need to also track
+	 * netdevs in the adapter struct
+	 */
+	adapter->netdevs[vport->idx] = netdev;
+
+	return 0;
+err:
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	return err;
+}
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -77,6 +690,24 @@ static int iecm_get_free_slot(void *array, int size, int curr)
 	return next;
 }
 
+/**
+ * iecm_decfg_netdev - Unregister the netdev
+ * @vport: vport for which netdev to be unregistred
+ */
+static void iecm_decfg_netdev(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!vport->netdev)
+		return;
+
+	unregister_netdev(vport->netdev);
+	free_netdev(vport->netdev);
+	vport->netdev = NULL;
+
+	adapter->netdevs[vport->idx] = NULL;
+}
+
 /**
  * iecm_vport_rel - Delete a vport and free its resources
  * @vport: the vport being removed
@@ -102,6 +733,8 @@ static void iecm_vport_rel_all(struct iecm_adapter *adapter)
 		if (!adapter->vports[i])
 			continue;
 
+		if (!test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags))
+			iecm_decfg_netdev(adapter->vports[i]);
 		iecm_vport_rel(adapter->vports[i]);
 		adapter->vports[i] = NULL;
 		adapter->next_vport = 0;
@@ -151,7 +784,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = NULL;
+	vport->irq_q_handler = iecm_vport_intr_clean_queues;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
@@ -184,8 +817,94 @@ static void iecm_statistics_task(struct work_struct *work)
  *
  */
 static void iecm_service_task(struct work_struct *work)
+{
+	struct iecm_adapter *adapter = container_of(work,
+						    struct iecm_adapter,
+						    serv_task.work);
+
+	if (test_bit(__IECM_MB_INTR_MODE, adapter->flags)) {
+		if (test_and_clear_bit(__IECM_MB_INTR_TRIGGER,
+				       adapter->flags)) {
+			iecm_recv_mb_msg(adapter, VIRTCHNL_OP_UNKNOWN, NULL, 0);
+			iecm_mb_irq_enable(adapter);
+		}
+	} else {
+		iecm_recv_mb_msg(adapter, VIRTCHNL_OP_UNKNOWN, NULL, 0);
+	}
+
+	if (iecm_is_reset_detected(adapter) &&
+	    !iecm_is_reset_in_prog(adapter)) {
+		dev_info(&adapter->pdev->dev, "HW reset detected\n");
+		set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+	}
+
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(300));
+}
+
+/* iecm_set_vlan_offload_features - set vlan offload features
+ * @netdev: netdev structure
+ * @prev_features: previously set features
+ * @features: current features received from user
+ *
+ * Returns 0 on success, error value on failure
+ */
+static int
+iecm_set_vlan_offload_features(struct net_device *netdev,
+			       netdev_features_t prev_features,
+			       netdev_features_t features)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	bool stripping_ena = true, insertion_ena = true;
+	struct iecm_virtchnl_ops *vc_ops;
+	u16 vlan_ethertype = 0;
+
+	vc_ops = &vport->adapter->dev_ops.vc_ops;
+	/* keep cases separate because one ethertype for offloads can be
+	 * disabled at the same time as another is disabled, so check for an
+	 * enabled ethertype first, then check for disabled. Default to
+	 * ETH_P_8021Q so an ethertype is specified if disabling insertion
+	 * and stripping.
+	 */
+	if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))
+		vlan_ethertype = ETH_P_8021AD;
+	else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX))
+		vlan_ethertype = ETH_P_8021Q;
+	else if (prev_features & (NETIF_F_HW_VLAN_STAG_RX |
+				  NETIF_F_HW_VLAN_STAG_TX))
+		vlan_ethertype = ETH_P_8021AD;
+	else if (prev_features & (NETIF_F_HW_VLAN_CTAG_RX |
+				  NETIF_F_HW_VLAN_CTAG_TX))
+		vlan_ethertype = ETH_P_8021Q;
+	else
+		vlan_ethertype = ETH_P_8021Q;
+
+	if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX)))
+		stripping_ena = false;
+	if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX)))
+		insertion_ena = false;
+
+	vport->adapter->config_data.vlan_ethertype = vlan_ethertype;
+
+	vc_ops->strip_vlan_msg(vport, stripping_ena);
+	if (vc_ops->insert_vlan_msg)
+		vc_ops->insert_vlan_msg(vport, insertion_ena);
+
+	return 0;
+}
+
+/**
+ * iecm_vport_open - Bring up a vport
+ * @vport: vport to bring up
+ * @alloc_res: allocate queue resources
+ */
+static int iecm_vport_open(struct iecm_vport *vport, bool alloc_res)
 {
 	/* stub */
+	return 0;
 }
 
 /**
@@ -206,6 +925,7 @@ static void iecm_init_task(struct work_struct *work)
 	struct iecm_vport *vport;
 	struct pci_dev *pdev;
 	int vport_id, err;
+	int index;
 
 	err = adapter->dev_ops.vc_ops.core_init(adapter, &vport_id);
 	if (err)
@@ -219,6 +939,65 @@ static void iecm_init_task(struct work_struct *work)
 			err);
 		return;
 	}
+	/* Start the service task before requesting vectors. This will ensure
+	 * vector information response from mailbox is handled
+	 */
+	queue_delayed_work(adapter->serv_wq, &adapter->serv_task,
+			   msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
+	err = iecm_intr_req(adapter);
+	if (err) {
+		dev_err(&pdev->dev, "failed to enable interrupt vectors: %d\n",
+			err);
+		goto intr_req_err;
+	}
+	err = iecm_send_vlan_v2_caps_msg(adapter);
+	if (err)
+		goto vlan_v2_caps_failed;
+
+	err = adapter->dev_ops.vc_ops.get_supported_desc_ids(vport);
+	if (err) {
+		dev_err(&pdev->dev, "failed to get required descriptor ids\n");
+		goto rxdids_failed;
+	}
+
+	if (iecm_cfg_netdev(vport))
+		goto cfg_netdev_err;
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN) ||
+	    iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_VLAN)) {
+		err = iecm_set_vlan_offload_features(vport->netdev, 0,
+						     vport->netdev->features);
+		if (err)
+			goto cfg_netdev_err;
+	}
+
+	err = adapter->dev_ops.vc_ops.get_ptype(vport);
+	if (err)
+		goto cfg_netdev_err;
+	queue_delayed_work(adapter->stats_wq, &adapter->stats_task,
+			   msecs_to_jiffies(10 * (pdev->devfn & 0x07)));
+	set_bit(__IECM_VPORT_INIT_PROMISC, vport->flags);
+	/* Once state is put into DOWN, driver is ready for dev_open */
+	adapter->state = __IECM_DOWN;
+	if (test_and_clear_bit(__IECM_UP_REQUESTED, adapter->flags))
+		iecm_vport_open(vport, true);
+
+	/* Clear the reset flag unconditionally here in case we were in reset
+	 * and the link was down
+	 */
+	clear_bit(__IECM_HR_RESET_IN_PROG, vport->adapter->flags);
+
+	return;
+
+vlan_v2_caps_failed:
+rxdids_failed:
+cfg_netdev_err:
+	iecm_intr_rel(adapter);
+intr_req_err:
+	index = iecm_get_vport_index(adapter, vport);
+	if (index >= 0)
+		adapter->vports[index] = NULL;
+	iecm_vport_rel(vport);
 }
 
 /**
@@ -614,3 +1393,35 @@ void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem)
 	mem->va = NULL;
 	mem->pa = 0;
 }
+
+static const struct net_device_ops iecm_netdev_ops_splitq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc = NULL,
+};
+
+static const struct net_device_ops iecm_netdev_ops_singleq = {
+	.ndo_open = NULL,
+	.ndo_stop = NULL,
+	.ndo_start_xmit = NULL,
+	.ndo_set_rx_mode = NULL,
+	.ndo_validate_addr = eth_validate_addr,
+	.ndo_set_mac_address = NULL,
+	.ndo_change_mtu = NULL,
+	.ndo_get_stats64 = NULL,
+	.ndo_fix_features = NULL,
+	.ndo_set_features = NULL,
+	.ndo_vlan_rx_add_vid = NULL,
+	.ndo_vlan_rx_kill_vid = NULL,
+	.ndo_setup_tc           = NULL,
+};
drivers/net/ethernet/intel/iecm/iecm_txrx.c +17 -0
index bd0cfd89bf03..bb7f5830cffb 100644
@@ -218,6 +218,23 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ *
+ */
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
+{
+	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+
+	q_vector->total_events++;
+	napi_schedule(&q_vector->napi);
+
+	return IRQ_HANDLED;
+}
+
 /**
  * iecm_vport_init_num_qs - Initialize number of queues
  * @vport: vport to initialize queues
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +165 -0

177 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +108 -4

162 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
index 9f3086bfe575..0aa1eac70e7c 100644
@@ -512,4 +512,6 @@ void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
 			      struct virtchnl2_create_vport *vport_msg);
 void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0
author
#40 lore raw

PATCH 9/19 iecm: alloc vport TX resources

In reply to Alan Brady

With init_task out of the way, we can start implementing open and data path. During open we'll allocate queue resources for vport. This only includes what's needed to get the TX resources. The next patch will get RX resources.

The splitq model is unique in that it introduces the concept of "queue groups" where, for TX, we have some number of descriptor queues being serviced by one completion queue in a given group association. By 'splitting' a normal queue into two queues, one context is just handling descriptors and one context handling buffers, we can more effeciently deal with both and configure asymmetric setups (multiple descriptor queues to one completion queue).

---
 drivers/net/ethernet/intel/iecm/Makefile      |    1 +
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |  369 ++++-
 .../ethernet/intel/iecm/iecm_singleq_txrx.c   |   29 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 1282 ++++++++++++++++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |   29 +
 drivers/net/ethernet/intel/include/iecm.h     |   28 +
 .../ethernet/intel/include/iecm_lan_txrx.h    |  394 +++++
 .../net/ethernet/intel/include/iecm_txrx.h    |   96 ++
 8 files changed, 2214 insertions(+), 14 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm_lan_txrx.h
drivers/net/ethernet/intel/iecm/Makefile +1 -0
index fcb49402334f..205d6f2b436a 100644
@@ -14,6 +14,7 @@ iecm-y := \
 	iecm_lib.o \
 	iecm_virtchnl.o \
 	iecm_txrx.o \
+	iecm_singleq_txrx.o \
 	iecm_controlq.o \
 	iecm_controlq_setup.o \
 	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_lib.c +364 -5

444 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c new file +29 -0
new file mode 100644
index 000000000000..d6c47cb84249
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2019 Intel Corporation */
+
+#include "iecm.h"
+
+/**
+ * iecm_rx_singleq_buf_hw_alloc_all - Replace used receive buffers
+ * @rx_q: queue for which the hw buffers are allocated
+ * @cleaned_count: number of buffers to replace
+ *
+ * Returns false if all allocations were successful, true if any fail
+ */
+bool iecm_rx_singleq_buf_hw_alloc_all(struct iecm_queue *rx_q,
+				      u16 cleaned_count)
+{
+	/* stub */
+	return true;
+}
+
+/**
+ * iecm_vport_singleq_napi_poll - NAPI handler
+ * @napi: struct from which you get q_vector
+ * @budget: budget provided by stack
+ */
+int iecm_vport_singleq_napi_poll(struct napi_struct *napi, int budget)
+{
+	/* stub */
+	return 0;
+}
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1273 -9

1,302 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +29 -0
index b91716aeef6f..919fb3958cf8 100644
@@ -3745,6 +3745,35 @@ void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async)
 		dev_err(&pdev->dev, "Failed to add or del mac filters %d", err);
 }
 
+/**
+ * iecm_set_promiscuous - set promiscuous and send message to mailbox
+ * @adapter: Driver specific private structure
+ *
+ * Request that the PF enable promiscuous mode for our VSI.  Message is sent
+ * asynchronously and won't wait for response.  Returns 0 on success, negative
+ * on failure;
+ */
+int iecm_set_promiscuous(struct iecm_adapter *adapter)
+{
+	struct iecm_vport *vport = adapter->vports[0];
+	struct virtchnl_promisc_info vpi;
+	u16 flags = 0;
+	int err = 0;
+
+	if (test_bit(__IECM_PROMISC_UC, adapter->config_data.user_flags))
+		flags |= FLAG_VF_UNICAST_PROMISC;
+	if (test_bit(__IECM_PROMISC_MC,
+		     adapter->config_data.user_flags))
+		flags |= FLAG_VF_MULTICAST_PROMISC;
+
+	vpi.vsi_id = vport->vport_id;
+	vpi.flags = flags;
+	err = iecm_send_mb_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
+			       sizeof(struct virtchnl_promisc_info),
+			       (u8 *)&vpi);
+	return err;
+}
+
 /**
  * iecm_add_del_vlans - Add or delete vlan filter
  * @vport: vport structure
drivers/net/ethernet/intel/include/iecm.h +28 -0
index b5bd73be2855..4304256f7010 100644
@@ -13,6 +13,7 @@
 #include <linux/version.h>
 #include <linux/dim.h>
 
+#include "iecm_lan_txrx.h"
 #include "virtchnl_2.h"
 #include "iecm_txrx.h"
 #include "iecm_controlq.h"
@@ -621,6 +622,17 @@ enum iecm_vlan_caps {
 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP	|\
 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP)
 
+/**
+ * iecm_restore_features - Restore feature configs
+ * @adapter: driver specific private structure
+ * @flag: User settings flag to check
+ */
+static inline bool iecm_is_user_flag_ena(struct iecm_adapter *adapter,
+					 enum iecm_user_flags flag)
+{
+	return test_bit(flag, adapter->config_data.user_flags);
+}
+
 /**
  * iecm_get_reserved_vecs - Get reserved vectors
  * @adapter: private data struct
@@ -656,6 +668,19 @@ static inline bool iecm_is_reset_in_prog(struct iecm_adapter *adapter)
 		test_bit(__IECM_HR_DRV_LOAD, adapter->flags));
 }
 
+/**
+ * iecm_rx_offset - Return expected offset into page to access data
+ * @rx_q: queue we are requesting offset of
+ *
+ * Returns the offset value for queue into the data buffer.
+ */
+static inline unsigned int
+iecm_rx_offset(struct iecm_queue __maybe_unused *rx_q)
+{
+	/* could be non-zero if xdp is enabled */
+	return 0;
+}
+
 int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter);
@@ -702,6 +727,7 @@ int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async);
+int iecm_set_promiscuous(struct iecm_adapter *adapter);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);
 int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature);
@@ -710,5 +736,7 @@ int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
+void iecm_vport_intr_write_itr(struct iecm_q_vector *q_vector,
+			       u16 itr, bool tx);
 int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport, bool map);
 #endif /* !_IECM_H_ */
drivers/net/ethernet/intel/include/iecm_lan_txrx.h new file +394 -0

394 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_txrx.h +96 -0

129 lines not on this page · raw message

Signature · 1 line
2.33.0
author
#43 lore raw

PATCH 10/19 iecm: alloc vport RX resources

In reply to Alan Brady

This finishes what we need to do for open by adding RX resource allocations.

As noted in the TX alloc patch, the splitq model is unique in introducing the concept of queue groups, which also applies to RX, albeit in a slightly different way. For RX we also split the queue between descriptor handling and buffer handling. We have some number of RX completion queues associated with up to two buffer queues in a given queue group. Once buffers are cleaned and recycled, they're given the buffer queues which then posts the buffers back to hardware. To enable this in a lockless way, there's also the concept of 'refill queues' introduced. Recycled buffers are put onto refill queues which is what the buffer queues clean to get buffers back.

---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 769 ++++++++++++++++++
 .../net/ethernet/intel/include/iecm_txrx.h    |   7 +
 2 files changed, 776 insertions(+)
drivers/net/ethernet/intel/iecm/iecm_txrx.c +769 -0
index 85e88a30370d..fb6a61277b00 100644
@@ -452,6 +452,545 @@ static int iecm_tx_desc_alloc_all(struct iecm_vport *vport)
 	return err;
 }
 
+/**
+ * iecm_rx_page_rel - Release an rx buffer page
+ * @rxq: the queue that owns the buffer
+ * @page_info: pointer to page metadata of page to be freed
+ */
+static void iecm_rx_page_rel(struct iecm_queue *rxq,
+			     struct iecm_page_info *page_info)
+{
+	if (!page_info->page)
+		return;
+
+	/* free resources associated with mapping */
+	dma_unmap_page_attrs(rxq->dev, page_info->dma, PAGE_SIZE,
+			     DMA_FROM_DEVICE, IECM_RX_DMA_ATTR);
+
+	__page_frag_cache_drain(page_info->page, page_info->pagecnt_bias);
+
+	page_info->page = NULL;
+	page_info->page_offset = 0;
+}
+
+/**
+ * iecm_rx_buf_rel - Release a rx buffer
+ * @rxq: the queue that owns the buffer
+ * @rx_buf: the buffer to free
+ */
+static void iecm_rx_buf_rel(struct iecm_queue *rxq,
+			    struct iecm_rx_buf *rx_buf)
+{
+	iecm_rx_page_rel(rxq, &rx_buf->page_info[0]);
+#if (PAGE_SIZE < 8192)
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		iecm_rx_page_rel(rxq, &rx_buf->page_info[1]);
+
+#endif
+	if (rx_buf->skb) {
+		dev_kfree_skb_any(rx_buf->skb);
+		rx_buf->skb = NULL;
+	}
+}
+
+/**
+ * iecm_rx_hdr_buf_rel_all - Release header buffer memory
+ * @rxq: queue to use
+ */
+static void iecm_rx_hdr_buf_rel_all(struct iecm_queue *rxq)
+{
+	struct iecm_hw *hw = &rxq->vport->adapter->hw;
+	int i;
+
+	if (!rxq)
+		return;
+
+	if (rxq->rx_buf.hdr_buf) {
+		for (i = 0; i < rxq->desc_count; i++) {
+			struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];
+
+			if (hbuf) {
+				iecm_free_dma_mem(hw, hbuf);
+				kfree(hbuf);
+			}
+			rxq->rx_buf.hdr_buf[i] = NULL;
+		}
+		kfree(rxq->rx_buf.hdr_buf);
+		rxq->rx_buf.hdr_buf = NULL;
+	}
+
+	for (i = 0; i < rxq->hbuf_pages.nr_pages; i++)
+		iecm_rx_page_rel(rxq, &rxq->hbuf_pages.pages[i]);
+
+	kfree(rxq->hbuf_pages.pages);
+}
+
+/**
+ * iecm_rx_buf_rel_all - Free all Rx buffer resources for a queue
+ * @rxq: queue to be cleaned
+ */
+static void iecm_rx_buf_rel_all(struct iecm_queue *rxq)
+{
+	u16 i;
+
+	/* queue already cleared, nothing to do */
+	if (!rxq->rx_buf.buf)
+		return;
+
+	/* Free all the bufs allocated and given to hw on Rx queue */
+	for (i = 0; i < rxq->desc_count; i++)
+		iecm_rx_buf_rel(rxq, &rxq->rx_buf.buf[i]);
+	if (rxq->rx_hsplit_en)
+		iecm_rx_hdr_buf_rel_all(rxq);
+
+	kfree(rxq->rx_buf.buf);
+	rxq->rx_buf.buf = NULL;
+	kfree(rxq->rx_buf.hdr_buf);
+	rxq->rx_buf.hdr_buf = NULL;
+}
+
+/**
+ * iecm_rx_desc_rel - Free a specific Rx q resources
+ * @rxq: queue to clean the resources from
+ * @bufq: buffer q or completion q
+ * @q_model: single or split q model
+ *
+ * Free a specific rx queue resources
+ */
+static void iecm_rx_desc_rel(struct iecm_queue *rxq, bool bufq, s32 q_model)
+{
+	if (!rxq)
+		return;
+
+	if (!bufq && iecm_is_queue_model_split(q_model) && rxq->skb) {
+		dev_kfree_skb_any(rxq->skb);
+		rxq->skb = NULL;
+	}
+
+	if (bufq || !iecm_is_queue_model_split(q_model))
+		iecm_rx_buf_rel_all(rxq);
+
+	if (rxq->desc_ring) {
+		dmam_free_coherent(rxq->dev, rxq->size,
+				   rxq->desc_ring, rxq->dma);
+		rxq->desc_ring = NULL;
+		rxq->next_to_alloc = 0;
+		rxq->next_to_clean = 0;
+		rxq->next_to_use = 0;
+	}
+}
+
+/**
+ * iecm_rx_desc_rel_all - Free Rx Resources for All Queues
+ * @vport: virtual port structure
+ *
+ * Free all rx queues resources
+ */
+static void iecm_rx_desc_rel_all(struct iecm_vport *vport)
+{
+	struct iecm_rxq_group *rx_qgrp;
+	struct iecm_queue *q;
+	int i, j, num_rxq;
+
+	if (!vport->rxq_grps)
+		return;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			for (j = 0; j < num_rxq; j++) {
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+
+			if (!rx_qgrp->splitq.bufq_sets)
+				continue;
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];
+
+				q = &bufq_set->bufq;
+				iecm_rx_desc_rel(q, true, vport->rxq_model);
+			}
+		} else {
+			for (j = 0; j < rx_qgrp->singleq.num_rxq; j++) {
+				q = rx_qgrp->singleq.rxqs[j];
+				iecm_rx_desc_rel(q, false,
+						 vport->rxq_model);
+			}
+		}
+	}
+}
+
+/**
+ * iecm_rx_buf_hw_update - Store the new tail and head values
+ * @rxq: queue to bump
+ * @val: new head index
+ */
+void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val)
+{
+	rxq->next_to_use = val;
+
+	if (unlikely(!rxq->tail))
+		return;
+	/* writel has an implicit memory barrier */
+	writel(val, rxq->tail);
+}
+
+/**
+ * iecm_alloc_page - allocate page to back RX buffer
+ * @rxbufq: pointer to queue struct
+ * @page_info: pointer to page metadata struct
+ */
+static int
+iecm_alloc_page(struct iecm_queue *rxbufq, struct iecm_page_info *page_info)
+{
+	/* alloc new page for storage */
+	page_info->page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!page_info->page))
+		return -ENOMEM;
+
+	/* map page for use */
+	page_info->dma = dma_map_page_attrs(rxbufq->dev, page_info->page,
+					    0, PAGE_SIZE, DMA_FROM_DEVICE,
+					    IECM_RX_DMA_ATTR);
+
+	/* if mapping failed free memory back to system since
+	 * there isn't much point in holding memory we can't use
+	 */
+	if (dma_mapping_error(rxbufq->dev, page_info->dma)) {
+		__free_pages(page_info->page, 0);
+		return -ENOMEM;
+	}
+
+	page_info->page_offset = 0;
+
+	/* initialize pagecnt_bias to claim we fully own page */
+	page_ref_add(page_info->page, USHRT_MAX - 1);
+	page_info->pagecnt_bias = USHRT_MAX;
+
+	return 0;
+}
+
+/**
+ * iecm_init_rx_buf_hw_alloc - allocate initial RX buffer pages
+ * @rxbufq: ring to use; equivalent to rxq when operating in singleq mode
+ * @buf: rx_buffer struct to modify
+ *
+ * Returns true if the page was successfully allocated or
+ * reused.
+ */
+bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxbufq, struct iecm_rx_buf *buf)
+{
+	if (iecm_alloc_page(rxbufq, &buf->page_info[0]))
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	if (rxbufq->rx_buf_size > IECM_RX_BUF_2048)
+		if (iecm_alloc_page(rxbufq, &buf->page_info[1]))
+			return false;
+#endif
+
+	buf->page_indx = 0;
+	buf->buf_size = rxbufq->rx_buf_size;
+
+	return true;
+}
+
+/**
+ * iecm_rx_hdr_buf_alloc_all - Allocate memory for header buffers
+ * @rxq: ring to use
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_rx_hdr_buf_alloc_all(struct iecm_queue *rxq)
+{
+	struct iecm_page_info *page_info;
+	int nr_pages, offset;
+	int i, j = 0;
+
+	rxq->rx_buf.hdr_buf = kcalloc(rxq->desc_count,
+				      sizeof(struct iecm_dma_mem *),
+				      GFP_KERNEL);
+	if (!rxq->rx_buf.hdr_buf)
+		return -ENOMEM;
+
+	for (i = 0; i < rxq->desc_count; i++) {
+		rxq->rx_buf.hdr_buf[i] = kcalloc(1,
+						 sizeof(struct iecm_dma_mem),
+						 GFP_KERNEL);
+		if (!rxq->rx_buf.hdr_buf[i])
+			goto unroll_buf_alloc;
+	}
+
+	/* Determine the number of pages necessary to back the total number of header buffers */
+	nr_pages = (rxq->desc_count * rxq->rx_hbuf_size) / PAGE_SIZE;
+	rxq->hbuf_pages.pages = kcalloc(nr_pages,
+					sizeof(struct iecm_page_info),
+					GFP_KERNEL);
+	if (!rxq->hbuf_pages.pages)
+		goto unroll_buf_alloc;
+
+	rxq->hbuf_pages.nr_pages = nr_pages;
+	for (i = 0; i < nr_pages; i++) {
+		if (iecm_alloc_page(rxq, &rxq->hbuf_pages.pages[i]))
+			goto unroll_buf_alloc;
+	}
+
+	page_info = &rxq->hbuf_pages.pages[0];
+	for (i = 0, offset = 0; i < rxq->desc_count; i++, offset += rxq->rx_hbuf_size) {
+		struct iecm_dma_mem *hbuf = rxq->rx_buf.hdr_buf[i];
+
+		/* Move to next page */
+		if (offset >= PAGE_SIZE) {
+			offset = 0;
+			page_info = &rxq->hbuf_pages.pages[++j];
+		}
+
+		hbuf->va = page_address(page_info->page) + offset;
+		hbuf->pa = page_info->dma + offset;
+		hbuf->size = rxq->rx_hbuf_size;
+	}
+
+	return 0;
+unroll_buf_alloc:
+	iecm_rx_hdr_buf_rel_all(rxq);
+	return -ENOMEM;
+}
+
+/**
+ * iecm_rx_buf_hw_alloc_all - Allocate receive buffers
+ * @rxbufq: queue for which the hw buffers are allocated; equivalent to rxq
+ * when operating in singleq mode
+ * @alloc_count: number of buffers to allocate
+ *
+ * Returns false if all allocations were successful, true if any fail
+ */
+static bool
+iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count)
+{
+	u16 nta = rxbufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
+	if (!alloc_count)
+		return false;
+
+	buf = &rxbufq->rx_buf.buf[nta];
+
+	do {
+		if (!iecm_init_rx_buf_hw_alloc(rxbufq, buf))
+			break;
+
+		buf++;
+		nta++;
+		if (unlikely(nta == rxbufq->desc_count)) {
+			buf = rxbufq->rx_buf.buf;
+			nta = 0;
+		}
+
+		alloc_count--;
+	} while (alloc_count);
+
+	return !!alloc_count;
+}
+
+/**
+ * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
+ * @bufq: buffer queue to post to
+ * @buf_id: buffer id to post
+ */
+static void iecm_rx_post_buf_desc(struct iecm_queue *bufq, u16 buf_id)
+{
+	struct virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL;
+	struct iecm_page_info *page_info;
+	u16 nta = bufq->next_to_alloc;
+	struct iecm_rx_buf *buf;
+
+	splitq_rx_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, nta);
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+	if (bufq->rx_hsplit_en)
+		splitq_rx_desc->hdr_addr = cpu_to_le64(bufq->rx_buf.hdr_buf[buf_id]->pa);
+
+	splitq_rx_desc->pkt_addr = cpu_to_le64(page_info->dma +
+					       page_info->page_offset);
+	splitq_rx_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	nta++;
+	if (unlikely(nta == bufq->desc_count))
+		nta = 0;
+	bufq->next_to_alloc = nta;
+}
+
+/**
+ * iecm_rx_post_init_bufs - Post initial buffers to bufq
+ * @bufq: buffer queue to post working set to
+ * @working_set: number of buffers to put in working set
+ */
+static void iecm_rx_post_init_bufs(struct iecm_queue *bufq,
+				   u16 working_set)
+{
+	int i;
+
+	for (i = 0; i < working_set; i++)
+		iecm_rx_post_buf_desc(bufq, i);
+
+	iecm_rx_buf_hw_update(bufq, bufq->next_to_alloc & ~(bufq->rx_buf_stride - 1));
+}
+
+/**
+ * iecm_rx_buf_alloc_all - Allocate memory for all buffer resources
+ * @rxbufq: queue for which the buffers are allocated; equivalent to
+ * rxq when operating in singleq mode
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_buf_alloc_all(struct iecm_queue *rxbufq)
+{
+	int err = 0;
+
+	/* Allocate book keeping buffers */
+	rxbufq->rx_buf.buf = kcalloc(rxbufq->desc_count,
+				     sizeof(struct iecm_rx_buf), GFP_KERNEL);
+	if (!rxbufq->rx_buf.buf) {
+		err = -ENOMEM;
+		goto rx_buf_alloc_all_out;
+	}
+
+	if (rxbufq->rx_hsplit_en) {
+		err = iecm_rx_hdr_buf_alloc_all(rxbufq);
+		if (err)
+			goto rx_buf_alloc_all_out;
+	}
+
+	/* Allocate buffers to be given to HW.	 */
+	if (iecm_is_queue_model_split(rxbufq->vport->rxq_model)) {
+		if (iecm_rx_buf_hw_alloc_all(rxbufq, rxbufq->desc_count - 1))
+			err = -ENOMEM;
+	} else {
+		if (iecm_rx_singleq_buf_hw_alloc_all(rxbufq, rxbufq->desc_count - 1))
+			err = -ENOMEM;
+	}
+
+rx_buf_alloc_all_out:
+	if (err)
+		iecm_rx_buf_rel_all(rxbufq);
+	return err;
+}
+
+/**
+ * iecm_rx_desc_alloc - Allocate queue Rx resources
+ * @rxq: Rx queue for which the resources are setup
+ * @bufq: buffer or completion queue
+ * @q_model: single or split queue model
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_desc_alloc(struct iecm_queue *rxq, bool bufq, s32 q_model)
+{
+	struct device *dev = rxq->dev;
+
+	/* As both single and split descriptors are 32 byte, memory size
+	 * will be same for all three singleq_base rx, buf., splitq_base
+	 * rx. So pick anyone of them for size
+	 */
+	if (bufq) {
+		rxq->size = rxq->desc_count *
+			sizeof(struct virtchnl2_splitq_rx_buf_desc);
+	} else {
+		rxq->size = rxq->desc_count *
+			sizeof(union virtchnl2_rx_desc);
+	}
+
+	/* Allocate descriptors and also round up to nearest 4K */
+	rxq->size = ALIGN(rxq->size, 4096);
+	rxq->desc_ring = dmam_alloc_coherent(dev, rxq->size,
+					     &rxq->dma, GFP_KERNEL);
+	if (!rxq->desc_ring) {
+		dev_info(dev, "Unable to allocate memory for the Rx descriptor ring, size=%d\n",
+			 rxq->size);
+		return -ENOMEM;
+	}
+
+	rxq->next_to_alloc = 0;
+	rxq->next_to_clean = 0;
+	rxq->next_to_use = 0;
+	set_bit(__IECM_Q_GEN_CHK, rxq->flags);
+
+	/* Allocate buffers for a rx queue if the q_model is single OR if it
+	 * is a buffer queue in split queue model
+	 */
+	if (bufq || !iecm_is_queue_model_split(q_model)) {
+		int err = 0;
+
+		err = iecm_rx_buf_alloc_all(rxq);
+		if (err) {
+			iecm_rx_desc_rel(rxq, bufq, q_model);
+			return err;
+		}
+	}
+	return 0;
+}
+
+/**
+ * iecm_rx_desc_alloc_all - allocate all RX queues resources
+ * @vport: virtual port structure
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rx_desc_alloc_all(struct iecm_vport *vport)
+{
+	struct device *dev = &vport->adapter->pdev->dev;
+	struct iecm_rxq_group *rx_qgrp;
+	int i, j, num_rxq, working_set;
+	struct iecm_queue *q;
+	int err = 0;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		rx_qgrp = &vport->rxq_grps[i];
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++) {
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				q = rx_qgrp->singleq.rxqs[j];
+			err = iecm_rx_desc_alloc(q, false, vport->rxq_model);
+			if (err) {
+				dev_err(dev, "Memory allocation for Rx Queue %u failed\n",
+					i);
+				goto err_out;
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				err = iecm_rx_desc_alloc(q, true,
+							 vport->rxq_model);
+				if (err) {
+					dev_err(dev, "Memory allocation for Rx Buffer Queue %u failed\n",
+						i);
+					goto err_out;
+				}
+
+				working_set = IECM_RX_BUFQ_WORKING_SET(q);
+				iecm_rx_post_init_bufs(q, working_set);
+			}
+		}
+	}
+err_out:
+	if (err)
+		iecm_rx_desc_rel_all(vport);
+	return err;
+}
+
 /**
  * iecm_txq_group_rel - Release all resources for txq groups
  * @vport: vport to release txq groups on
@@ -478,6 +1017,61 @@ static void iecm_txq_group_rel(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_rxq_sw_queue_rel - Release software queue resources
+ * @rx_qgrp: rx queue group with software queues
+ */
+static void iecm_rxq_sw_queue_rel(struct iecm_rxq_group *rx_qgrp)
+{
+	int i, j;
+
+	for (i = 0; i < rx_qgrp->vport->num_bufqs_per_qgrp; i++) {
+		struct iecm_bufq_set *bufq_set = &rx_qgrp->splitq.bufq_sets[i];
+
+		for (j = 0; j < bufq_set->num_refillqs; j++) {
+			kfree(bufq_set->refillqs[j].ring);
+			bufq_set->refillqs[j].ring = NULL;
+		}
+		kfree(bufq_set->refillqs);
+		bufq_set->refillqs = NULL;
+	}
+}
+
+/**
+ * iecm_rxq_group_rel - Release all resources for rxq groups
+ * @vport: vport to release rxq groups on
+ */
+static void iecm_rxq_group_rel(struct iecm_vport *vport)
+{
+	if (vport->rxq_grps) {
+		int i;
+
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int j, num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->splitq.rxq_sets[j]);
+					rx_qgrp->splitq.rxq_sets[j] = NULL;
+				}
+				iecm_rxq_sw_queue_rel(rx_qgrp);
+				kfree(rx_qgrp->splitq.bufq_sets);
+				rx_qgrp->splitq.bufq_sets = NULL;
+			} else {
+				num_rxq = rx_qgrp->singleq.num_rxq;
+				for (j = 0; j < num_rxq; j++) {
+					kfree(rx_qgrp->singleq.rxqs[j]);
+					rx_qgrp->singleq.rxqs[j] = NULL;
+				}
+			}
+		}
+		kfree(vport->rxq_grps);
+		vport->rxq_grps = NULL;
+	}
+}
+
 /**
  * iecm_vport_queue_grp_rel_all - Release all queue groups
  * @vport: vport to release queue groups for
@@ -485,6 +1079,7 @@ static void iecm_txq_group_rel(struct iecm_vport *vport)
 static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport)
 {
 	iecm_txq_group_rel(vport);
+	iecm_rxq_group_rel(vport);
 }
 
 /**
@@ -496,6 +1091,7 @@ static void iecm_vport_queue_grp_rel_all(struct iecm_vport *vport)
 void iecm_vport_queues_rel(struct iecm_vport *vport)
 {
 	iecm_tx_desc_rel_all(vport);
+	iecm_rx_desc_rel_all(vport);
 	iecm_vport_queue_grp_rel_all(vport);
 
 	kfree(vport->txqs);
@@ -715,6 +1311,24 @@ void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)
 }
 EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
 
+/**
+ * iecm_rxq_set_descids - set the descids supported by this queue
+ * @vport: virtual port data structure
+ * @q: rx queue for which descids are set
+ *
+ */
+static void iecm_rxq_set_descids(struct iecm_vport *vport, struct iecm_queue *q)
+{
+	if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+		q->rxdids = VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M;
+	} else {
+		if (vport->base_rxd)
+			q->rxdids = VIRTCHNL2_RXDID_1_32B_BASE_M;
+		else
+			q->rxdids = VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M;
+	}
+}
+
 /**
  * iecm_set_vlan_tag_loc - set the tag location for a tx/rx queue
  * @adapter: adapter structure
@@ -827,6 +1441,152 @@ static int iecm_txq_group_alloc(struct iecm_vport *vport, int num_txq)
 	return err;
 }
 
+/**
+ * iecm_rxq_group_alloc - Allocate all rxq group resources
+ * @vport: vport to allocate rxq groups for
+ * @num_rxq: number of rxqs to allocate for each group
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_rxq_group_alloc(struct iecm_vport *vport, int num_rxq)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_queue *q;
+	int i, k, err = 0;
+
+	vport->rxq_grps = kcalloc(vport->num_rxq_grp,
+				  sizeof(struct iecm_rxq_group), GFP_KERNEL);
+	if (!vport->rxq_grps)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int j;
+
+		rx_qgrp->vport = vport;
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			rx_qgrp->splitq.num_rxq_sets = num_rxq;
+
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->splitq.rxq_sets[j] =
+					kzalloc(sizeof(struct iecm_rxq_set),
+						GFP_KERNEL);
+				if (!rx_qgrp->splitq.rxq_sets[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+
+			rx_qgrp->splitq.bufq_sets = kcalloc(vport->num_bufqs_per_qgrp,
+							    sizeof(struct iecm_bufq_set),
+							    GFP_KERNEL);
+			if (!rx_qgrp->splitq.bufq_sets) {
+				err = -ENOMEM;
+				goto err_alloc;
+			}
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				struct iecm_bufq_set *bufq_set =
+					&rx_qgrp->splitq.bufq_sets[j];
+				int swq_size = sizeof(struct iecm_sw_queue);
+
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				q->dev = &adapter->pdev->dev;
+				q->desc_count = vport->bufq_desc_count[j];
+				q->vport = vport;
+				q->rxq_grp = rx_qgrp;
+				q->idx = j;
+				q->rx_buf_size = vport->bufq_size[j];
+				q->rx_buffer_low_watermark = IECM_LOW_WATERMARK;
+				q->rx_buf_stride = IECM_RX_BUF_STRIDE;
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size = IECM_HDR_BUF_SIZE;
+				}
+
+				bufq_set->num_refillqs = num_rxq;
+				bufq_set->refillqs = kcalloc(num_rxq,
+							     swq_size,
+							     GFP_KERNEL);
+				if (!bufq_set->refillqs) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+				for (k = 0; k < bufq_set->num_refillqs; k++) {
+					struct iecm_sw_queue *refillq =
+						&bufq_set->refillqs[k];
+
+					refillq->dev =
+						&vport->adapter->pdev->dev;
+					refillq->buf_size = q->rx_buf_size;
+					refillq->desc_count =
+						vport->bufq_desc_count[j];
+					set_bit(__IECM_Q_GEN_CHK,
+						refillq->flags);
+					set_bit(__IECM_RFLQ_GEN_CHK,
+						refillq->flags);
+					refillq->ring = kcalloc(refillq->desc_count,
+								sizeof(u16),
+								GFP_KERNEL);
+					if (!refillq->ring) {
+						err = -ENOMEM;
+						goto err_alloc;
+					}
+				}
+			}
+		} else {
+			rx_qgrp->singleq.num_rxq = num_rxq;
+			for (j = 0; j < num_rxq; j++) {
+				rx_qgrp->singleq.rxqs[j] =
+					kzalloc(sizeof(*rx_qgrp->singleq.rxqs[j]), GFP_KERNEL);
+				if (!rx_qgrp->singleq.rxqs[j]) {
+					err = -ENOMEM;
+					goto err_alloc;
+				}
+			}
+		}
+
+		for (j = 0; j < num_rxq; j++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				rx_qgrp->splitq.rxq_sets[j]->refillq0 =
+				      &rx_qgrp->splitq.bufq_sets[0].refillqs[j];
+				rx_qgrp->splitq.rxq_sets[j]->refillq1 =
+				      &rx_qgrp->splitq.bufq_sets[1].refillqs[j];
+
+				if (test_bit(__IECM_PRIV_FLAGS_HDR_SPLIT,
+					     adapter->config_data.user_flags)) {
+					q->rx_hsplit_en = true;
+					q->rx_hbuf_size = IECM_HDR_BUF_SIZE;
+				}
+			} else {
+				q = rx_qgrp->singleq.rxqs[j];
+			}
+			q->dev = &adapter->pdev->dev;
+			q->desc_count = vport->rxq_desc_count;
+			q->vport = vport;
+			q->rxq_grp = rx_qgrp;
+			q->idx = (i * num_rxq) + j;
+			/* In splitq mode, RXQ buffer size should be
+			 * set to that of the first buffer queue
+			 * associated with this RXQ
+			 */
+			q->rx_buf_size = vport->bufq_size[0];
+			q->rx_buffer_low_watermark = IECM_LOW_WATERMARK;
+			q->rx_max_pkt_size = vport->netdev->mtu +
+							IECM_PACKET_HDR_PAD;
+			iecm_rxq_set_descids(vport, q);
+			iecm_set_vlan_tag_loc(adapter, q);
+		}
+	}
+err_alloc:
+	if (err)
+		iecm_rxq_group_rel(vport);
+	return err;
+}
+
 /**
  * iecm_vport_queue_grp_alloc_all - Allocate all queue groups/resources
  * @vport: vport with qgrps to allocate
@@ -841,6 +1601,11 @@ static int iecm_vport_queue_grp_alloc_all(struct iecm_vport *vport)
 	iecm_vport_calc_numq_per_grp(vport, &num_txq, &num_rxq);
 
 	err = iecm_txq_group_alloc(vport, num_txq);
+	if (err)
+		goto err_out;
+
+	err = iecm_rxq_group_alloc(vport, num_rxq);
+err_out:
 	if (err)
 		iecm_vport_queue_grp_rel_all(vport);
 	return err;
@@ -866,6 +1631,10 @@ int iecm_vport_queues_alloc(struct iecm_vport *vport)
 	if (err)
 		goto err_out;
 
+	err = iecm_rx_desc_alloc_all(vport);
+	if (err)
+		goto err_out;
+
 	err = iecm_vport_init_fast_path_txqs(vport);
 	if (err)
 		goto err_out;
drivers/net/ethernet/intel/include/iecm_txrx.h +7 -0
index 44c20f8a2039..5e29148938fb 100644
@@ -198,6 +198,11 @@ struct iecm_page_info {
 	u16 pagecnt_bias;
 };
 
+struct iecm_rx_hdr_buf_pages {
+	u32 nr_pages;
+	struct iecm_page_info *pages;
+};
+
 struct iecm_rx_buf {
 #define IECM_RX_BUF_MAX_PAGES 2
 	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES];
@@ -498,6 +503,8 @@ struct iecm_queue {
 					 * with scatter-gather
 					 */
 	DECLARE_HASHTABLE(sched_buf_hash, 12);
+
+	struct iecm_rx_hdr_buf_pages hbuf_pages;
 } ____cacheline_internodealigned_in_smp;
 
 /* Software queues are used in splitq mode to manage buffers between rxq
Signature · 1 line
2.33.0
author
#47 lore raw

PATCH 11/19 iecm: add start_xmit and set_rx_mode

In reply to Alan Brady

With open and stop done, this continues down the netdev_ops struct to add start_xmit and set_rx_mode callbacks. The rest of the data path will be added after netdev_ops are done.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 247 ++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 667 ++++++++++++++++++
 drivers/net/ethernet/intel/include/iecm.h     |   1 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  60 ++
 4 files changed, 970 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +242 -5
index 037a0e06bb7b..003057f48f0c 100644
@@ -141,6 +141,17 @@ struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev)
 	return np->vport;
 }
 
+/**
+ * iecm_netdev_to_adapter - get an adapter handle from a netdev
+ * @netdev: network interface device structure
+ */
+struct iecm_adapter *iecm_netdev_to_adapter(struct net_device *netdev)
+{
+	struct iecm_netdev_priv *np = netdev_priv(netdev);
+
+	return np->vport->adapter;
+}
+
 /**
  * iecm_mb_intr_rel_irq - Free the IRQ association with the OS
  * @adapter: adapter structure
@@ -417,6 +428,61 @@ iecm_mac_filter *iecm_find_mac_filter(struct iecm_vport *vport,
 	return NULL;
 }
 
+/**
+ * __iecm_del_mac_filter - Delete MAC filter helper
+ * @vport: main vport struct
+ * @macaddr: address to delete
+ *
+ * Takes mac_filter_list_lock spinlock to set remove field for filter in list.
+ */
+static struct
+iecm_mac_filter *__iecm_del_mac_filter(struct iecm_vport *vport,
+				       const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	spin_lock_bh(&vport->adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	if (f) {
+		/* If filter was never synced to HW we can just delete it here,
+		 * otherwise mark for removal.
+		 */
+		if (f->add) {
+			list_del(&f->list);
+			kfree(f);
+			f = NULL;
+		} else {
+			f->remove = true;
+		}
+	}
+	spin_unlock_bh(&vport->adapter->mac_filter_list_lock);
+
+	return f;
+}
+
+/**
+ * iecm_del_mac_filter - Delete a MAC filter from the filter list
+ * @vport: main vport structure
+ * @macaddr: the MAC address
+ *
+ * Removes filter from list and if interface is up, tells hardware about the
+ * removed filter.
+ **/
+static void iecm_del_mac_filter(struct iecm_vport *vport, const u8 *macaddr)
+{
+	struct iecm_mac_filter *f;
+
+	if (!macaddr)
+		return;
+
+	f = __iecm_del_mac_filter(vport, macaddr);
+	if (!f)
+		return;
+
+	if (vport->adapter->state == __IECM_UP)
+		iecm_add_del_ether_addrs(vport, false, false);
+}
+
 /**
  * __iecm_add_mac_filter - Add mac filter helper function
  * @vport: main vport struct
@@ -1711,6 +1777,134 @@ void iecm_remove(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL(iecm_remove);
 
+/**
+ * iecm_addr_sync - Callback for dev_(mc|uc)_sync to add address
+ * @netdev: the netdevice
+ * @addr: address to add
+ *
+ * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
+ * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock
+ * meaning we cannot sleep in this context. Due to this, we have to add the
+ * filter and send the virtchnl message asynchronously without waiting for the
+ * response from the other side. We won't know whether or not the operation
+ * actually succeeded until we get the message back.  Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_addr_sync(struct net_device *netdev, const u8 *addr)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	if (__iecm_add_mac_filter(vport, addr)) {
+		if (vport->adapter->state == __IECM_UP) {
+			set_bit(__IECM_ADD_ETH_REQ, vport->adapter->flags);
+			iecm_add_del_ether_addrs(vport, true, true);
+		}
+		return 0;
+	}
+
+	return -ENOMEM;
+}
+
+/**
+ * iecm_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
+ * @netdev: the netdevice
+ * @addr: address to add
+ *
+ * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
+ * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock
+ * meaning we cannot sleep in this context. Due to this we have to delete the
+ * filter and send the virtchnl message asychronously without waiting for the
+ * return from the other side.  We won't know whether or not the operation
+ * actually succeeded until we get the message back. Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_addr_unsync(struct net_device *netdev, const u8 *addr)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	/* Under some circumstances, we might receive a request to delete
+	 * our own device address from our uc list. Because we store the
+	 * device address in the VSI's MAC/VLAN filter list, we need to ignore
+	 * such requests and not delete our device address from this list.
+	 */
+	if (ether_addr_equal(addr, netdev->dev_addr))
+		return 0;
+
+	if (__iecm_del_mac_filter(vport, addr)) {
+		if (vport->adapter->state == __IECM_UP) {
+			set_bit(__IECM_DEL_ETH_REQ, vport->adapter->flags);
+			iecm_add_del_ether_addrs(vport, false, true);
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_set_rx_mode - NDO callback to set the netdev filters
+ * @netdev: network interface device structure
+ *
+ * Stack takes addr_list_lock spinlock before calling our .set_rx_mode.  We
+ * cannot sleep in this context.
+ */
+static void iecm_set_rx_mode(struct net_device *netdev)
+{
+	struct iecm_adapter *adapter = iecm_netdev_to_adapter(netdev);
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_MACFILTER)) {
+		__dev_uc_sync(netdev, iecm_addr_sync, iecm_addr_unsync);
+		__dev_mc_sync(netdev, iecm_addr_sync, iecm_addr_unsync);
+	}
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_PROMISC)) {
+		bool changed = false;
+
+		/* IFF_PROMISC enables both unicast and multicast promiscuous,
+		 * while IFF_ALLMULTI only enables multicast such that:
+		 *
+		 * promisc  + allmulti		= unicast | multicast
+		 * promisc  + !allmulti		= unicast | multicast
+		 * !promisc + allmulti		= multicast
+		 */
+		if ((netdev->flags & IFF_PROMISC) &&
+		    !test_and_set_bit(__IECM_PROMISC_UC,
+				      adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
+			if (!test_and_set_bit(__IECM_PROMISC_MC,
+					      adapter->flags))
+				dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
+		}
+		if (!(netdev->flags & IFF_PROMISC) &&
+		    test_and_clear_bit(__IECM_PROMISC_UC,
+				       adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
+		}
+		if (netdev->flags & IFF_ALLMULTI &&
+		    !test_and_set_bit(__IECM_PROMISC_MC,
+				      adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
+		}
+		if (!(netdev->flags & (IFF_ALLMULTI | IFF_PROMISC)) &&
+		    test_and_clear_bit(__IECM_PROMISC_MC,
+				       adapter->config_data.user_flags)) {
+			changed = true;
+			dev_info(&adapter->pdev->dev, "Leaving multicast promiscuous mode\n");
+		}
+
+		if (changed) {
+			int err = iecm_set_promiscuous(adapter);
+
+			if (err) {
+				dev_info(&adapter->pdev->dev, "Failed to set promiscuous mode: %d\n",
+					 err);
+			}
+		}
+	}
+}
+
 /**
  * iecm_open - Called when a network interface becomes active
  * @netdev: network interface device structure
@@ -1730,6 +1924,49 @@ static int iecm_open(struct net_device *netdev)
 	return iecm_vport_open(np->vport, true);
 }
 
+/**
+ * iecm_set_mac - NDO callback to set port mac address
+ * @netdev: network interface device structure
+ * @p: pointer to an address structure
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int iecm_set_mac(struct net_device *netdev, void *p)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_mac_filter *f;
+	struct sockaddr *addr = p;
+
+	if (!iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+			     VIRTCHNL2_CAP_MACFILTER)) {
+		dev_info(&vport->adapter->pdev->dev, "Setting MAC address is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (!is_valid_ether_addr(addr->sa_data)) {
+		dev_info(&vport->adapter->pdev->dev, "Invalid MAC address: %pM\n",
+			 addr->sa_data);
+		return -EADDRNOTAVAIL;
+	}
+
+	if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
+		return 0;
+
+	/* Delete the current filter */
+	if (is_valid_ether_addr(vport->default_mac_addr))
+		iecm_del_mac_filter(vport, vport->default_mac_addr);
+
+	/* Add new filter */
+	f = iecm_add_mac_filter(vport, addr->sa_data);
+
+	if (f) {
+		ether_addr_copy(vport->default_mac_addr, addr->sa_data);
+		dev_addr_mod(netdev, 0, addr->sa_data, ETH_ALEN);
+	}
+
+	return f ? 0 : -ENOMEM;
+}
+
 void *iecm_alloc_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem, u64 size)
 {
 	struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back;
@@ -1756,10 +1993,10 @@ void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem *mem)
 static const struct net_device_ops iecm_netdev_ops_splitq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
-	.ndo_start_xmit = NULL,
-	.ndo_set_rx_mode = NULL,
+	.ndo_start_xmit = iecm_tx_splitq_start,
+	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
-	.ndo_set_mac_address = NULL,
+	.ndo_set_mac_address = iecm_set_mac,
 	.ndo_change_mtu = NULL,
 	.ndo_get_stats64 = NULL,
 	.ndo_fix_features = NULL,
@@ -1773,9 +2010,9 @@ static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
 	.ndo_start_xmit = NULL,
-	.ndo_set_rx_mode = NULL,
+	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
-	.ndo_set_mac_address = NULL,
+	.ndo_set_mac_address = iecm_set_mac,
 	.ndo_change_mtu = NULL,
 	.ndo_get_stats64 = NULL,
 	.ndo_fix_features = NULL,
drivers/net/ethernet/intel/iecm/iecm_txrx.c +667 -0

673 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +1 -0
index 4304256f7010..f6f9884c10c2 100644
@@ -717,6 +717,7 @@ int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
 struct iecm_vport *iecm_netdev_to_vport(struct net_device *netdev);
+struct iecm_adapter *iecm_netdev_to_adapter(struct net_device *netdev);
 int iecm_send_get_stats_msg(struct iecm_vport *vport);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
 		     u16 *vecids, int num_vecids,
drivers/net/ethernet/intel/include/iecm_txrx.h +60 -0

85 lines not on this page · raw message

Signature · 1 line
2.33.0
author
#49 lore raw

PATCH 12/19 iecm: finish netdev_ops

In reply to Alan Brady

This fills out the remaining NDO callbacks. Once netdev_ops are there, the rest of the patches will fill out the data path and advanced features.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 742 +++++++++++++++++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  15 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |  63 ++
 drivers/net/ethernet/intel/include/iecm.h     |  14 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   2 +
 5 files changed, 822 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +728 -14
index 003057f48f0c..cc82e665dfaf 100644
@@ -568,6 +568,147 @@ static void iecm_set_all_filters(struct iecm_vport *vport)
 	iecm_add_del_ether_addrs(vport, true, false);
 }
 
+/**
+ * iecm_find_vlan - Search filter list for specific vlan filter
+ * @vport: vport structure
+ * @vlan: vlan tag
+ *
+ * Returns ptr to the filter object or NULL. Must be called while holding the
+ * vlan_list_lock.
+ */
+static struct
+iecm_vlan_filter *iecm_find_vlan(struct iecm_vport *vport,
+				 struct iecm_vlan *vlan)
+{
+	struct iecm_vlan_filter *f;
+
+	list_for_each_entry(f, &vport->adapter->config_data.vlan_filter_list,
+			    list) {
+		if (vlan->vid == f->vlan.vid && vlan->tpid == f->vlan.tpid)
+			return f;
+	}
+	return NULL;
+}
+
+/**
+ * iecm_add_vlan - Add a vlan filter to the list
+ * @vport: vport structure
+ * @vlan: VLAN tag
+ *
+ * Returns ptr to the filter object or NULL when no memory available.
+ */
+static struct
+iecm_vlan_filter *iecm_add_vlan(struct iecm_vport *vport,
+				struct iecm_vlan *vlan)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f = NULL;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	f = iecm_find_vlan(vport, vlan);
+	if (!f) {
+		f = kzalloc(sizeof(*f), GFP_ATOMIC);
+		if (!f)
+			goto error;
+
+		f->vlan.vid = vlan->vid;
+		f->vlan.tpid = vlan->tpid;
+
+		list_add_tail(&f->list, &adapter->config_data.vlan_filter_list);
+		f->add = true;
+	}
+
+error:
+	spin_unlock_bh(&adapter->vlan_list_lock);
+	return f;
+}
+
+/**
+ * iecm_del_vlan - Remove a vlan filter from the list
+ * @vport: vport structure
+ * @vlan: VLAN tag
+ */
+static void iecm_del_vlan(struct iecm_vport *vport, struct iecm_vlan *vlan)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	f = iecm_find_vlan(vport, vlan);
+	if (f)
+		f->remove = true;
+
+	spin_unlock_bh(&adapter->vlan_list_lock);
+}
+
+/**
+ * iecm_vlan_rx_add_vid - Add a VLAN filter to the device
+ * @netdev: network device struct
+ * @proto: unused protocol data
+ * @vid: VLAN tag
+ *
+ * Returns 0 on success
+ */
+static int iecm_vlan_rx_add_vid(struct net_device *netdev,
+				__always_unused __be16 proto, u16 vid)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan vlan;
+
+	vlan = IECM_VLAN(vid, be16_to_cpu(proto));
+	if (!iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_FILTER))
+		return -EINVAL;
+
+	iecm_add_vlan(vport, &vlan);
+
+	if (adapter->state == __IECM_UP)
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, true);
+
+	return 0;
+}
+
+/**
+ * iecm_vlan_rx_kill_vid - Remove a VLAN filter from the device
+ * @netdev: network device struct
+ * @proto: unused protocol data
+ * @vid: VLAN tag
+ *
+ * Returns 0 on success
+ */
+static int iecm_vlan_rx_kill_vid(struct net_device *netdev,
+				 __always_unused __be16 proto, u16 vid)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vlan_filter *f, *ftmp;
+	struct iecm_vlan vlan;
+
+	vlan = IECM_VLAN(vid, be16_to_cpu(proto));
+	if (!iecm_is_feature_ena(vport, NETIF_F_HW_VLAN_CTAG_FILTER))
+		return -EINVAL;
+
+	if (vport->adapter->state == __IECM_UP) {
+		iecm_del_vlan(vport, &vlan);
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, false);
+	}
+	/* It is safe to delete entry from the list now */
+	spin_lock_bh(&adapter->vlan_list_lock);
+	list_for_each_entry_safe(f, ftmp,
+				 &adapter->config_data.vlan_filter_list,
+				 list) {
+		if (f->vlan.vid == vlan.vid && f->vlan.tpid == vlan.tpid) {
+			list_del(&f->list);
+			kfree(f);
+		}
+	}
+	spin_unlock_bh(&adapter->vlan_list_lock);
+
+	return 0;
+}
+
 /**
  * iecm_set_all_vlans - Re-add all VLANs in list
  * @vport: main vport struct
@@ -804,6 +945,27 @@ static int iecm_get_free_slot(void *array, int size, int curr)
 	return next;
 }
 
+/**
+ * iecm_remove_vlan_filters - Remove all vlan filters
+ * @vport: vport structure
+ */
+static void iecm_remove_vlan_filters(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_user_config_data *config_data;
+
+	config_data = &adapter->config_data;
+	if (!list_empty(&config_data->vlan_filter_list)) {
+		struct iecm_vlan_filter *f;
+
+		spin_lock_bh(&adapter->vlan_list_lock);
+		list_for_each_entry(f, &config_data->vlan_filter_list, list)
+			f->remove = true;
+		spin_unlock_bh(&adapter->vlan_list_lock);
+		adapter->dev_ops.vc_ops.add_del_vlans(vport, false);
+	}
+}
+
 /**
  * iecm_vport_stop - Disable a vport
  * @vport: vport to disable
@@ -831,6 +993,8 @@ static void iecm_vport_stop(struct iecm_vport *vport)
 	if (test_and_clear_bit(__IECM_DEL_QUEUES,
 			       vport->adapter->flags))
 		iecm_send_delete_queues_msg(vport);
+	if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags))
+		iecm_remove_vlan_filters(vport);
 
 	adapter->link_up = false;
 	iecm_vport_intr_deinit(vport);
@@ -1581,6 +1745,147 @@ static void iecm_vc_event_task(struct work_struct *work)
 	}
 }
 
+/**
+ * iecm_initiate_soft_reset - Initiate a software reset
+ * @vport: virtual port data struct
+ * @reset_cause: reason for the soft reset
+ *
+ * Soft reset only reallocs vport queue resources. Returns 0 on success,
+ * negative on failure.
+ */
+int iecm_initiate_soft_reset(struct iecm_vport *vport,
+			     enum iecm_flags reset_cause)
+{
+	enum iecm_state current_state = vport->adapter->state;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_vport *new_vport;
+	int err = 0, i;
+
+	/* make sure we do not end up in initiating multiple resets */
+	mutex_lock(&adapter->reset_lock);
+
+	/* If the system is low on memory, we can end up in bad state if we
+	 * free all the memory for queue resources and try to allocate them
+	 * again. Instead, we can pre-allocate the new resources before doing
+	 * anything and bailing if the alloc fails.
+	 *
+	 * Make a clone of the existing vport to mimic its current configuration,
+	 * then modify the new structure with any requested changes. Once the
+	 * allocation of the new resources is done, stop the existing vport and
+	 * copy the configuration to the main vport. If an error occurred, the
+	 * existing vport will be untouched.
+	 *
+	 */
+	new_vport = kzalloc(sizeof(*vport), GFP_KERNEL);
+	if (!new_vport) {
+		mutex_unlock(&adapter->reset_lock);
+		return -ENOMEM;
+	}
+	memcpy(new_vport, vport, sizeof(*vport));
+
+	/* Adjust resource parameters prior to reallocating resources */
+	switch (reset_cause) {
+	case __IECM_SR_Q_CHANGE:
+		adapter->dev_ops.vc_ops.adjust_qs(new_vport);
+		break;
+	case __IECM_SR_Q_DESC_CHANGE:
+		/* Update queue parameters before allocating resources */
+		iecm_vport_calc_num_q_desc(new_vport);
+		break;
+	case __IECM_SR_Q_SCH_CHANGE:
+	case __IECM_SR_MTU_CHANGE:
+	case __IECM_SR_RSC_CHANGE:
+	case __IECM_SR_HSPLIT_CHANGE:
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Unhandled soft reset cause\n");
+		err = -EINVAL;
+		goto err_default;
+	}
+
+	err = iecm_vport_queues_alloc(new_vport);
+	if (err)
+		goto err_default;
+
+	if (adapter->virt_ver_maj == VIRTCHNL_VERSION_MAJOR_2) {
+		if (current_state <= __IECM_DOWN) {
+			adapter->dev_ops.vc_ops.delete_queues(vport);
+		} else {
+			set_bit(__IECM_DEL_QUEUES, adapter->flags);
+			iecm_vport_stop(vport);
+		}
+
+		iecm_deinit_rss(vport);
+		err = adapter->dev_ops.vc_ops.add_queues(new_vport, new_vport->num_txq,
+							 new_vport->num_complq,
+							 new_vport->num_rxq,
+							 new_vport->num_bufq);
+		if (err)
+			goto err_reset;
+	} else {
+		iecm_vport_stop(vport);
+	}
+
+	memcpy(vport, new_vport, sizeof(*vport));
+	/* Since iecm_vport_queues_alloc was called with new_port, the queue
+	 * back pointers are currently pointing to the local new_vport. Reset
+	 * the backpointers to the original vport here
+	 */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		tx_qgrp->vport = vport;
+		for (j = 0; j < tx_qgrp->num_txq; j++)
+			tx_qgrp->txqs[j]->vport = vport;
+
+		if (iecm_is_queue_model_split(vport->txq_model))
+			tx_qgrp->complq->vport = vport;
+	}
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		struct iecm_queue *q;
+		int j, num_rxq;
+
+		rx_qgrp->vport = vport;
+		for (j = 0; j < vport->num_bufqs_per_qgrp; j++)
+			rx_qgrp->splitq.bufq_sets[j].bufq.vport = vport;
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++) {
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				q = rx_qgrp->singleq.rxqs[j];
+			q->vport = vport;
+		}
+	}
+
+	/* Post resource allocation reset */
+	if (reset_cause == __IECM_SR_Q_CHANGE) {
+		iecm_intr_rel(adapter);
+		iecm_intr_req(adapter);
+	}
+
+	kfree(new_vport);
+
+	if (current_state == __IECM_UP)
+		err = iecm_vport_open(vport, false);
+	mutex_unlock(&adapter->reset_lock);
+	return err;
+err_reset:
+	iecm_vport_queues_rel(vport);
+err_default:
+	kfree(new_vport);
+	mutex_unlock(&adapter->reset_lock);
+	return err;
+}
+
 /**
  * iecm_probe - Device initialization routine
  * @pdev: PCI device information struct
@@ -1905,6 +2210,47 @@ static void iecm_set_rx_mode(struct net_device *netdev)
 	}
 }
 
+/**
+ * iecm_set_features - set the netdev feature flags
+ * @netdev: ptr to the netdev being adjusted
+ * @features: the feature set that the stack is suggesting
+ */
+static int iecm_set_features(struct net_device *netdev,
+			     netdev_features_t features)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0;
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_VLAN) ||
+	    iecm_is_cap_ena(adapter, IECM_BASE_CAPS, VIRTCHNL2_CAP_VLAN)) {
+		err = iecm_set_vlan_offload_features(netdev, netdev->features,
+						     features);
+		if (err)
+			return err;
+	}
+
+	if ((netdev->features ^ features) & NETIF_F_GRO_HW) {
+		netdev->features ^= NETIF_F_GRO_HW;
+		err = iecm_initiate_soft_reset(vport, __IECM_SR_RSC_CHANGE);
+	}
+
+	return err;
+}
+
+/**
+ * iecm_fix_features - fix up the netdev feature bits
+ * @netdev: our net device
+ * @features: desired feature bits
+ *
+ * Returns fixed-up features bits
+ */
+static netdev_features_t iecm_fix_features(struct net_device *netdev,
+					   netdev_features_t features)
+{
+	return features;
+}
+
 /**
  * iecm_open - Called when a network interface becomes active
  * @netdev: network interface device structure
@@ -1924,6 +2270,374 @@ static int iecm_open(struct net_device *netdev)
 	return iecm_vport_open(np->vport, true);
 }
 
+/**
+ * iecm_change_mtu - NDO callback to change the MTU
+ * @netdev: network interface device structure
+ * @new_mtu: new value for maximum frame size
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	struct iecm_vport *vport =  iecm_netdev_to_vport(netdev);
+
+	netdev->mtu = new_mtu;
+
+	return iecm_initiate_soft_reset(vport, __IECM_SR_MTU_CHANGE);
+}
+
+static int iecm_offload_txtime(struct iecm_vport *vport,
+			       struct tc_etf_qopt_offload *qopt)
+{
+	return -EOPNOTSUPP;
+}
+
+/**
+ * iecm_validate_tx_bandwidth - validate the max Tx bandwidth
+ * @vport: vport structure
+ * @max_tx_rate: max Tx bandwidth for a tc
+ **/
+static int iecm_validate_tx_bandwidth(struct iecm_vport *vport,
+				      u64 max_tx_rate)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int speed = 0, ret = 0;
+
+	if (adapter->link_speed_mbps) {
+		if (adapter->link_speed_mbps < U32_MAX) {
+			speed = adapter->link_speed_mbps;
+			goto validate_bw;
+		} else {
+			dev_err(&adapter->pdev->dev, "Unknown link speed\n");
+			return -EINVAL;
+		}
+	}
+
+	switch (adapter->link_speed) {
+	case VIRTCHNL_LINK_SPEED_40GB:
+		speed = SPEED_40000;
+		break;
+	case VIRTCHNL_LINK_SPEED_25GB:
+		speed = SPEED_25000;
+		break;
+	case VIRTCHNL_LINK_SPEED_20GB:
+		speed = SPEED_20000;
+		break;
+	case VIRTCHNL_LINK_SPEED_10GB:
+		speed = SPEED_10000;
+		break;
+	case VIRTCHNL_LINK_SPEED_5GB:
+		speed = SPEED_5000;
+		break;
+	case VIRTCHNL_LINK_SPEED_2_5GB:
+		speed = SPEED_2500;
+		break;
+	case VIRTCHNL_LINK_SPEED_1GB:
+		speed = SPEED_1000;
+		break;
+	case VIRTCHNL_LINK_SPEED_100MB:
+		speed = SPEED_100;
+		break;
+	default:
+		break;
+	}
+
+validate_bw:
+	if (max_tx_rate > speed) {
+		dev_err(&adapter->pdev->dev, "Invalid tx rate specified\n");
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+/**
+ * iecm_validate_ch_config - validate queue mapping info
+ * @vport: vport structure
+ * @mqprio_qopt: queue parameters
+ * @max_tc_allowed: MAX TC allowed, it could be 4 or 16 depends.
+ *
+ * This function validates if the configuration provided by the user to
+ * configure queue channels is valid or not.
+ *
+ * Returns 0 on a valid config and negative on invalid config.
+ **/
+static int iecm_validate_ch_config(struct iecm_vport *vport,
+				   struct tc_mqprio_qopt_offload *mqprio_qopt,
+				   u8 max_tc_allowed)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	u32 tc, qcount, non_power_2_qcount = 0;
+	u64 total_max_rate = 0;
+	int i, num_qs = 0;
+
+	if (mqprio_qopt->qopt.num_tc > max_tc_allowed ||
+	    mqprio_qopt->qopt.num_tc < 1)
+		return -EINVAL;
+
+	/* For ADQ there are few rules on queue allocation for each TC
+	 *     1. Number of queues for TC0 should always be a power of 2
+	 *     2. Number of queues for rest of TCs can be non-power of 2
+	 *     3. If the previous TC has non-power of 2 queues, then all the
+	 *        following TCs should be either
+	 *        a. same number of queues as that of the previous non-power
+	 *           of 2 or
+	 *        b. less than previous non-power of 2 and power of 2
+	 *        ex: 1 at 0 2 at 1 3 at 3 4 at 6 - Invalid
+	 *            1 at 0 2 at 1 3 at 3 3 at 6 - Valid
+	 *            1 at 0 2 at 1 3 at 3 2 at 6 - Valid
+	 *            1 at 0 2 at 1 3 at 3 1@6 - Valid
+	 */
+	for (tc = 0; tc < mqprio_qopt->qopt.num_tc; tc++) {
+		qcount = mqprio_qopt->qopt.count[tc];
+
+		/* case 1. check for first TC to be always power of 2 in ADQ */
+		if (!tc && !is_power_of_2(qcount)) {
+			dev_err(&adapter->pdev->dev,
+				"TC0:qcount[%d] must be a power of 2\n",
+				qcount);
+			return -EINVAL;
+		}
+		/* case 2 & 3, check for non-power of 2 number of queues */
+		if (tc && non_power_2_qcount) {
+			if (qcount > non_power_2_qcount) {
+				dev_err(&adapter->pdev->dev,
+					"TC%d has %d qcount cannot be > non_power_of_2 qcount [%d]\n",
+					tc, qcount, non_power_2_qcount);
+				return -EINVAL;
+			} else if (qcount < non_power_2_qcount) {
+				/* it must be power of 2, otherwise fail */
+				if (!is_power_of_2(qcount)) {
+					dev_err(&adapter->pdev->dev,
+						"TC%d has %d qcount must be a power of 2 < non_power_of_2 qcount [%d]\n",
+						tc, qcount, non_power_2_qcount);
+					return -EINVAL;
+				}
+			}
+		} else if (tc && !is_power_of_2(qcount)) {
+			/* this is the first TC to have a non-power of 2 queue
+			 * count and the code is going to enter this section
+			 * only once. The qcount for this TC will serve as
+			 * our reference/guide to allocate number of queues
+			 * for all the further TCs as per section a. and b. in
+			 * case 3 mentioned above.
+			 */
+			non_power_2_qcount = qcount;
+			dev_dbg(&adapter->pdev->dev,
+				"TC%d:count[%d] non power of 2\n", tc,
+				qcount);
+			}
+	}
+
+	for (i = 0; i <= mqprio_qopt->qopt.num_tc - 1; i++) {
+		u64 tx_rate = 0;
+
+		if (!mqprio_qopt->qopt.count[i] ||
+		    mqprio_qopt->qopt.offset[i] != num_qs)
+			return -EINVAL;
+		if (mqprio_qopt->min_rate[i]) {
+			dev_err(&adapter->pdev->dev,
+				"Invalid min tx rate (greater than 0) specified\n");
+			return -EINVAL;
+		}
+		/*convert to Mbps */
+		tx_rate = div_u64(mqprio_qopt->max_rate[i], IECM_MBPS_DIVISOR);
+		total_max_rate += tx_rate;
+		num_qs += mqprio_qopt->qopt.count[i];
+	}
+	/* Comparing with num_txq as num_txq and num_rxq are equal for single
+	 * queue model
+	 */
+	if (num_qs > vport->num_txq) {
+		dev_err(&adapter->pdev->dev,
+			"Cannot support requested number of queues\n");
+		return -EINVAL;
+	}
+	/* no point in validating TX bandwidth rate limit if the user hasn't
+	 * specified any rate limit for any TCs, so validate only if it's set.
+	 */
+	if (total_max_rate)
+		return iecm_validate_tx_bandwidth(vport, total_max_rate);
+	else
+		return 0;
+}
+
+/**
+ * __iecm_setup_tc - configure multiple traffic classes
+ * @vport: vport structure
+ * @type_data: tc offload data
+ *
+ * This function processes the config information provided by the
+ * user to configure traffic classes/queue channels and packages the
+ * information to request the PF to setup traffic classes.
+ *
+ * Returns 0 on success.
+ **/
+static int __iecm_setup_tc(struct iecm_vport *vport, void *type_data)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct tc_mqprio_qopt_offload *mqprio_qopt;
+	struct net_device *netdev = vport->netdev;
+	struct iecm_channel_config *ch_config;
+	u8 num_tc = 0, total_qs = 0;
+	int ret = 0;
+	u8 max_tc_allowed;
+	u64 max_tx_rate;
+	u16 mode;
+
+	mqprio_qopt = (struct tc_mqprio_qopt_offload *)type_data;
+	ch_config = &adapter->config_data.ch_config;
+	num_tc = mqprio_qopt->qopt.num_tc;
+	mode = mqprio_qopt->mode;
+
+	/* delete queue_channel */
+	if (!mqprio_qopt->qopt.hw) {
+		if (ch_config->tc_running) {
+			/* reset the tc configuration */
+			netdev_reset_tc(netdev);
+			ch_config->num_tc = 0;
+			netif_tx_stop_all_queues(netdev);
+			netif_tx_disable(netdev);
+			ret = iecm_send_disable_channels_msg(vport);
+			netif_tx_start_all_queues(netdev);
+			if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags) &&
+			    !ret) {
+				ch_config->tc_running = false;
+				set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+				queue_delayed_work(adapter->vc_event_wq,
+						   &adapter->vc_event_task,
+						   msecs_to_jiffies(10));
+			}
+			return ret;
+		} else {
+			return -EINVAL;
+		}
+	}
+
+	if (mode == TC_MQPRIO_MODE_CHANNEL) {
+		int i, netdev_tc = 0;
+
+		if (!iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				     VIRTCHNL2_CAP_ADQ) &&
+		    !iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+					     VIRTCHNL2_CAP_ADQ)) {
+			dev_info(&adapter->pdev->dev, "ADQ not supported\n");
+			return -EOPNOTSUPP;
+		}
+
+		if (ch_config->tc_running) {
+			dev_info(&adapter->pdev->dev, "TC configuration already exists\n");
+			return -EINVAL;
+		}
+
+		/* If negotiated capability between VF and PF indicated that
+		 * ADQ_V2 is enabled, means it's OK to allow max_tc
+		 * to be 16. This is needed to handle the case where iAVF
+		 * is newer but PF is older or different generation
+		 */
+		if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+			max_tc_allowed = VIRTCHNL_MAX_ADQ_V2_CHANNELS;
+		else
+			max_tc_allowed = VIRTCHNL_MAX_ADQ_CHANNELS;
+
+		ret = iecm_validate_ch_config(vport, mqprio_qopt,
+					      max_tc_allowed);
+		if (ret)
+			return ret;
+		/* Return if same TC config is requested */
+		if (ch_config->num_tc == num_tc)
+			return 0;
+		ch_config->num_tc = num_tc;
+
+		for (i = 0; i < max_tc_allowed; i++) {
+			if (i < num_tc) {
+				ch_config->ch_info[i].count =
+					mqprio_qopt->qopt.count[i];
+				ch_config->ch_info[i].offset =
+					mqprio_qopt->qopt.offset[i];
+				total_qs += mqprio_qopt->qopt.count[i];
+				max_tx_rate = mqprio_qopt->max_rate[i];
+				/* convert to Mbps */
+				max_tx_rate = div_u64(max_tx_rate,
+						      IECM_MBPS_DIVISOR);
+				ch_config->ch_info[i].max_tx_rate =
+								max_tx_rate;
+			} else {
+				ch_config->ch_info[i].count = 1;
+				ch_config->ch_info[i].offset = 0;
+			}
+		}
+
+		/* Store queue info based on TC so that, VF gets configured
+		 * with correct number of queues when VF completes ADQ config
+		 * flow
+		 */
+		ch_config->total_qs = total_qs;
+
+		netif_tx_stop_all_queues(netdev);
+		netif_tx_disable(netdev);
+		ret = iecm_send_enable_channels_msg(vport);
+		if (ret)
+			return ret;
+		netdev_reset_tc(netdev);
+		/* Report the tc mapping up the stack */
+		netdev_set_num_tc(netdev, num_tc);
+		for (i = 0; i < max_tc_allowed; i++) {
+			u16 qcount = mqprio_qopt->qopt.count[i];
+			u16 qoffset = mqprio_qopt->qopt.offset[i];
+
+			if (i < num_tc)
+				netdev_set_tc_queue(netdev, netdev_tc++, qcount,
+						    qoffset);
+		}
+		/* Start all queues */
+		netif_tx_start_all_queues(netdev);
+		ch_config->tc_running = true;
+		set_bit(__IECM_HR_FUNC_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+	}
+	return ret;
+}
+
+/**
+ * iecm_setup_tc - ndo callback to setup up TC schedulers
+ * @netdev: pointer to net_device struct
+ * @type: TC type
+ * @type_data: TC type specific data
+ */
+static int iecm_setup_tc(struct net_device *netdev, enum tc_setup_type type,
+			 void *type_data)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0;
+
+	switch (type) {
+	case TC_SETUP_QDISC_ETF:
+		if (iecm_is_queue_model_split(vport->txq_model))
+			err =
+			iecm_offload_txtime(vport,
+					    (struct tc_etf_qopt_offload *)
+					     type_data);
+		break;
+	case TC_SETUP_BLOCK:
+		break;
+	case TC_SETUP_QDISC_MQPRIO:
+		if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				    VIRTCHNL2_CAP_ADQ) ||
+		    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ))
+			__iecm_setup_tc(vport, type_data);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+		break;
+	}
+
+	return err;
+}
+
 /**
  * iecm_set_mac - NDO callback to set port mac address
  * @netdev: network interface device structure
@@ -1997,13 +2711,13 @@ static const struct net_device_ops iecm_netdev_ops_splitq = {
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
-	.ndo_change_mtu = NULL,
-	.ndo_get_stats64 = NULL,
-	.ndo_fix_features = NULL,
-	.ndo_set_features = NULL,
-	.ndo_vlan_rx_add_vid = NULL,
-	.ndo_vlan_rx_kill_vid = NULL,
-	.ndo_setup_tc = NULL,
+	.ndo_change_mtu = iecm_change_mtu,
+	.ndo_get_stats64 = iecm_get_stats64,
+	.ndo_fix_features = iecm_fix_features,
+	.ndo_set_features = iecm_set_features,
+	.ndo_vlan_rx_add_vid = iecm_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid = iecm_vlan_rx_kill_vid,
+	.ndo_setup_tc = iecm_setup_tc,
 };
 
 static const struct net_device_ops iecm_netdev_ops_singleq = {
@@ -2013,11 +2727,11 @@ static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
-	.ndo_change_mtu = NULL,
-	.ndo_get_stats64 = NULL,
-	.ndo_fix_features = NULL,
-	.ndo_set_features = NULL,
-	.ndo_vlan_rx_add_vid = NULL,
-	.ndo_vlan_rx_kill_vid = NULL,
-	.ndo_setup_tc           = NULL,
+	.ndo_change_mtu = iecm_change_mtu,
+	.ndo_get_stats64 = iecm_get_stats64,
+	.ndo_fix_features = iecm_fix_features,
+	.ndo_set_features = iecm_set_features,
+	.ndo_vlan_rx_add_vid = iecm_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid = iecm_vlan_rx_kill_vid,
+	.ndo_setup_tc = iecm_setup_tc,
 };
drivers/net/ethernet/intel/iecm/iecm_txrx.c +15 -0
index ef5fe659389b..4b9288e1c254 100644
@@ -218,6 +218,21 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_get_stats64 - get statistics for network device structure
+ * @netdev: network interface device structure
+ * @stats: main device statistics structure
+ */
+void iecm_get_stats64(struct net_device *netdev,
+		      struct rtnl_link_stats64 *stats)
+{
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+
+	set_bit(__IECM_MB_STATS_PENDING, vport->adapter->flags);
+
+	*stats = vport->netstats;
+}
+
 /**
  * iecm_tx_buf_rel - Release a Tx buffer
  * @tx_q: the queue that owns the buffer
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +63 -0

69 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +14 -0
index f6f9884c10c2..a655e797f457 100644
@@ -4,6 +4,8 @@
 #ifndef _IECM_H_
 #define _IECM_H_
 
+#include <net/pkt_sched.h>
+#include <net/pkt_cls.h>
 #include <linux/aer.h>
 #include <linux/pci.h>
 #include <linux/netdevice.h>
@@ -44,6 +46,8 @@
 /* available message levels */
 #define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+#define IECM_MBPS_DIVISOR		125000 /* divisor to convert to Mbps */
+
 #define IECM_VIRTCHNL_VERSION_MAJOR VIRTCHNL_VERSION_MAJOR_2
 #define IECM_VIRTCHNL_VERSION_MINOR VIRTCHNL_VERSION_MINOR_0
 
@@ -393,6 +397,13 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+struct iecm_channel_config {
+	struct virtchnl_channel_info ch_info[VIRTCHNL_MAX_ADQ_V2_CHANNELS];
+	bool tc_running;
+	u8 total_qs;
+	u8 num_tc;
+};
+
 #define IECM_GET_PTYPE_SIZE(p) \
 	(sizeof(struct virtchnl2_ptype) + \
 	(((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof(u16)))
@@ -430,6 +441,7 @@ struct iecm_user_config_data {
 	struct list_head mac_filter_list;
 	struct list_head vlan_filter_list;
 	struct list_head adv_rss_list;
+	struct iecm_channel_config ch_config;
 };
 
 struct iecm_rss_data {
@@ -703,6 +715,8 @@ int iecm_send_delete_queues_msg(struct iecm_vport *vport);
 int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
 			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
 int iecm_send_vlan_v2_caps_msg(struct iecm_adapter *adapter);
+int iecm_initiate_soft_reset(struct iecm_vport *vport,
+			     enum iecm_flags reset_cause);
 int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);
 int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
 int iecm_send_enable_vport_msg(struct iecm_vport *vport);
drivers/net/ethernet/intel/include/iecm_txrx.h +2 -0
index 26e480343876..7ec742fd4c6b 100644
@@ -672,6 +672,8 @@ netdev_tx_t iecm_tx_singleq_start(struct sk_buff *skb,
 				  struct net_device *netdev);
 bool iecm_rx_singleq_buf_hw_alloc_all(struct iecm_queue *rxq,
 				      u16 cleaned_count);
+void iecm_get_stats64(struct net_device *netdev,
+		      struct rtnl_link_stats64 *stats);
 int iecm_tso(struct iecm_tx_buf *first, struct iecm_tx_offload_params *off);
 void iecm_tx_prepare_vlan_flags(struct iecm_queue *tx_q,
 				struct iecm_tx_buf *first,
Signature · 1 line
2.33.0
author
#51 lore raw

PATCH 13/19 iecm: implement splitq napi_poll

In reply to Alan Brady

This adds everything we need to actually receive packets and process spent buffers using the splitq model. This contrasts to more traditional queueing models by essentially splitting a normal queue of descriptors and mapped buffers into separate queues. This allows us to deal with both more efficiently and also allows us to implement asymmetric queuing setups where you have multiple completion queues associated with a single buffer queue.

---
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   | 1468 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |    4 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   20 +
 3 files changed, 1490 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_txrx.c +1466 -2
index 4b9288e1c254..85a82b58525a 100644
@@ -218,6 +218,36 @@ const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
 };
 EXPORT_SYMBOL(iecm_ptype_lookup);
 
+/**
+ * iecm_buf_lifo_push - push a buffer pointer onto stack
+ * @stack: pointer to stack struct
+ * @buf: pointer to buf to push
+ *
+ * Returns 0 on success, negative on failure
+ **/
+static int iecm_buf_lifo_push(struct iecm_buf_lifo *stack,
+			      struct iecm_tx_buf *buf)
+{
+	if (stack->top == stack->size)
+		return -ENOSPC;
+
+	stack->bufs[stack->top++] = buf;
+
+	return 0;
+}
+
+/**
+ * iecm_buf_lifo_pop - pop a buffer pointer from stack
+ * @stack: pointer to stack struct
+ **/
+static struct iecm_tx_buf *iecm_buf_lifo_pop(struct iecm_buf_lifo *stack)
+{
+	if (!stack->top)
+		return NULL;
+
+	return stack->bufs[--stack->top];
+}
+
 /**
  * iecm_get_stats64 - get statistics for network device structure
  * @netdev: network interface device structure
@@ -812,6 +842,30 @@ iecm_rx_buf_hw_alloc_all(struct iecm_queue *rxbufq, u16 alloc_count)
 	return !!alloc_count;
 }
 
+/**
+ * iecm_rx_post_buf_refill - Post buffer id to refill queue
+ * @refillq: refill queue to post to
+ * @buf_id: buffer id to post
+ */
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id)
+{
+	u16 nta = refillq->next_to_alloc;
+	u16 *bi;
+
+	bi = IECM_SPLITQ_RX_BI_DESC(refillq, nta);
+	/* store the buffer ID and the SW maintained GEN bit to the refillq */
+	*bi = ((buf_id << IECM_RX_BI_BUFID_S) & IECM_RX_BI_BUFID_M) |
+	      (!!(test_bit(__IECM_Q_GEN_CHK, refillq->flags)) <<
+	       IECM_RX_BI_GEN_S);
+
+	nta++;
+	if (unlikely(nta == refillq->desc_count)) {
+		nta = 0;
+		change_bit(__IECM_Q_GEN_CHK, refillq->flags);
+	}
+	refillq->next_to_alloc = nta;
+}
+
 /**
  * iecm_rx_post_buf_desc - Post buffer to bufq descriptor ring
  * @bufq: buffer queue to post to
@@ -1670,6 +1724,398 @@ int iecm_vport_queues_alloc(struct iecm_vport *vport)
 	return err;
 }
 
+/**
+ * iecm_tx_find_q - Find the tx q based on q id
+ * @vport: the vport we care about
+ * @q_id: Id of the queue
+ *
+ * Returns queue ptr if found else returns NULL
+ */
+static struct iecm_queue *
+iecm_tx_find_q(struct iecm_vport *vport, int q_id)
+{
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++) {
+		struct iecm_queue *tx_q = vport->txqs[i];
+
+		if (tx_q->q_id == q_id)
+			return tx_q;
+	}
+
+	return NULL;
+}
+
+/**
+ * iecm_tx_handle_sw_marker - Handle queue marker packet
+ * @tx_q: tx queue to handle software marker
+ */
+static void iecm_tx_handle_sw_marker(struct iecm_queue *tx_q)
+{
+	struct iecm_vport *vport = tx_q->vport;
+	bool drain_complete = true;
+	int i;
+
+	clear_bit(__IECM_Q_SW_MARKER, tx_q->flags);
+	/* Hardware must write marker packets to all queues associated with
+	 * completion queues. So check if all queues received marker packets
+	 */
+	for (i = 0; i < vport->num_txq; i++) {
+		if (test_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags))
+			drain_complete = false;
+	}
+	if (drain_complete) {
+		set_bit(__IECM_SW_MARKER, vport->adapter->flags);
+		wake_up(&vport->adapter->sw_marker_wq);
+	}
+}
+
+/**
+ * iecm_tx_splitq_clean_buf - Clean TX buffer resources
+ * @tx_q: tx queue to clean buffer from
+ * @tx_buf: buffer to be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ */
+static void
+iecm_tx_splitq_clean_buf(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf,
+			 int napi_budget)
+{
+	/* unmap skb header data */
+	dma_unmap_single(tx_q->dev,
+			 dma_unmap_addr(tx_buf, dma),
+			 dma_unmap_len(tx_buf, len),
+			 DMA_TO_DEVICE);
+
+	napi_consume_skb(tx_buf->skb, napi_budget);
+
+	/* clear tx_buf data */
+	tx_buf->skb = NULL;
+	dma_unmap_len_set(tx_buf, len, 0);
+}
+
+/**
+ * iecm_stash_flow_sch_buffers - store buffere parameter info to be freed at a
+ * later time (only relevant for flow scheduling mode)
+ * @txq: Tx queue to clean
+ * @tx_buf: buffer to store
+ */
+static int
+iecm_stash_flow_sch_buffers(struct iecm_queue *txq, struct iecm_tx_buf *tx_buf)
+{
+	struct iecm_adapter *adapter = txq->vport->adapter;
+	struct iecm_tx_buf *shadow_buf;
+
+	shadow_buf = iecm_buf_lifo_pop(&txq->buf_stack);
+	if (!shadow_buf) {
+		dev_err(&adapter->pdev->dev,
+			"No out-of-order TX buffers left!\n");
+		return -ENOMEM;
+	}
+
+	/* Store buffer params in shadow buffer */
+	shadow_buf->skb = tx_buf->skb;
+	shadow_buf->bytecount = tx_buf->bytecount;
+	shadow_buf->gso_segs = tx_buf->gso_segs;
+	dma_unmap_addr_set(shadow_buf, dma, dma_unmap_addr(tx_buf, dma));
+	dma_unmap_len_set(shadow_buf, len, dma_unmap_len(tx_buf, len));
+	shadow_buf->compl_tag = tx_buf->compl_tag;
+
+	/* Add buffer to buf_hash table to be freed
+	 * later
+	 */
+	hash_add(txq->sched_buf_hash, &shadow_buf->hlist,
+		 shadow_buf->compl_tag);
+
+	memset(tx_buf, 0, sizeof(struct iecm_tx_buf));
+
+	return 0;
+}
+
+/**
+ * iecm_tx_splitq_clean - Reclaim resources from buffer queue
+ * @tx_q: Tx queue to clean
+ * @end: queue index until which it should be cleaned
+ * @napi_budget: Used to determine if we are in netpoll
+ * @descs_only: true if queue is using flow-based scheduling and should
+ * not clean buffers at this time
+ *
+ * Cleans the queue descriptor ring. If the queue is using queue-based
+ * scheduling, the buffers will be cleaned as well and this function will
+ * return the number of bytes/packets cleaned. If the queue is using flow-based
+ * scheduling, only the descriptors are cleaned at this time. Separate packet
+ * completion events will be reported on the completion queue, and the buffers
+ * will be cleaned separately. The stats returned from this function when using
+ * flow-based scheduling are irrelevant.
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_splitq_clean(struct iecm_queue *tx_q, u16 end, int napi_budget,
+		     bool descs_only)
+{
+	union iecm_tx_flex_desc *next_pending_desc = NULL;
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	union iecm_tx_flex_desc *tx_desc;
+	s16 ntc = tx_q->next_to_clean;
+	struct iecm_tx_buf *tx_buf;
+	unsigned short gso_segs = 0;
+	unsigned int bytecount = 0;
+	struct netdev_queue *nq;
+
+	tx_desc = IECM_FLEX_TX_DESC(tx_q, ntc);
+	next_pending_desc = IECM_FLEX_TX_DESC(tx_q, end);
+	tx_buf = &tx_q->tx_buf[ntc];
+	ntc -= tx_q->desc_count;
+
+	while (tx_desc != next_pending_desc) {
+		union iecm_tx_flex_desc *eop_desc =
+			(union iecm_tx_flex_desc *)tx_buf->next_to_watch;
+
+		/* clear next_to_watch to prevent false hangs */
+		tx_buf->next_to_watch = NULL;
+
+		bytecount += tx_buf->bytecount;
+		gso_segs += tx_buf->gso_segs;
+
+		if (descs_only) {
+			if (iecm_stash_flow_sch_buffers(tx_q, tx_buf))
+				goto tx_splitq_clean_out;
+
+			while (tx_desc != eop_desc) {
+				tx_buf++;
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+				}
+
+				if (dma_unmap_len(tx_buf, len)) {
+					if (iecm_stash_flow_sch_buffers(tx_q,
+									tx_buf))
+						goto tx_splitq_clean_out;
+				}
+			}
+		} else {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(tx_q, tx_buf, napi_budget);
+
+			/* unmap remaining buffers */
+			while (tx_desc != eop_desc) {
+				tx_buf++;
+				tx_desc++;
+				ntc++;
+				if (unlikely(!ntc)) {
+					ntc -= tx_q->desc_count;
+					tx_buf = tx_q->tx_buf;
+					tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+				}
+
+				/* unmap any remaining paged data */
+				if (dma_unmap_len(tx_buf, len)) {
+					dma_unmap_page(tx_q->dev,
+						       dma_unmap_addr(tx_buf, dma),
+						       dma_unmap_len(tx_buf, len),
+						       DMA_TO_DEVICE);
+					dma_unmap_len_set(tx_buf, len, 0);
+				}
+			}
+		}
+
+		tx_buf++;
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= tx_q->desc_count;
+			tx_buf = tx_q->tx_buf;
+			tx_desc = IECM_FLEX_TX_DESC(tx_q, 0);
+		}
+	}
+
+tx_splitq_clean_out:
+	ntc += tx_q->desc_count;
+	tx_q->next_to_clean = ntc;
+
+	nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx);
+	netdev_tx_completed_queue(nq, gso_segs, bytecount);
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_flow_sch_bufs - clean bufs that were stored for
+ * out of order completions
+ * @txq: queue to clean
+ * @compl_tag: completion tag of packet to clean (from completion descriptor)
+ * @budget: Used to determine if we are in netpoll
+ */
+static struct iecm_tx_queue_stats
+iecm_tx_clean_flow_sch_bufs(struct iecm_queue *txq, u16 compl_tag,
+			    int budget)
+{
+	struct iecm_tx_queue_stats cleaned_stats = {0};
+	struct hlist_node *tmp_buf = NULL;
+	struct iecm_tx_buf *tx_buf = NULL;
+
+	/* Buffer completion */
+	hash_for_each_possible_safe(txq->sched_buf_hash, tx_buf, tmp_buf,
+				    hlist, compl_tag) {
+		if (tx_buf->compl_tag != compl_tag)
+			continue;
+
+		if (likely(tx_buf->skb)) {
+			/* update the statistics for this packet */
+			cleaned_stats.bytes += tx_buf->bytecount;
+			cleaned_stats.packets += tx_buf->gso_segs;
+
+			iecm_tx_splitq_clean_buf(txq, tx_buf, budget);
+		} else if (dma_unmap_len(tx_buf, len)) {
+			dma_unmap_page(txq->dev,
+				       dma_unmap_addr(tx_buf, dma),
+				       dma_unmap_len(tx_buf, len),
+				       DMA_TO_DEVICE);
+			dma_unmap_len_set(tx_buf, len, 0);
+		}
+		/* Push shadow buf back onto stack */
+		iecm_buf_lifo_push(&txq->buf_stack, tx_buf);
+
+		hash_del(&tx_buf->hlist);
+	}
+
+	return cleaned_stats;
+}
+
+/**
+ * iecm_tx_clean_complq - Reclaim resources on completion queue
+ * @complq: Tx ring to clean
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns true if there's any budget left (e.g. the clean is finished)
+ */
+static bool
+iecm_tx_clean_complq(struct iecm_queue *complq, int budget)
+{
+	struct iecm_splitq_tx_compl_desc *tx_desc;
+	struct iecm_vport *vport = complq->vport;
+	s16 ntc = complq->next_to_clean;
+	bool clean_completed = false;
+	unsigned int complq_budget;
+
+	complq_budget = vport->compln_clean_budget;
+	tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, ntc);
+	ntc -= complq->desc_count;
+
+	do {
+		struct iecm_tx_queue_stats cleaned_stats = {0};
+		struct iecm_queue *tx_q;
+		u16 compl_tag, hw_head;
+		int tx_qid;
+		u8 ctype;	/* completion type */
+		u16 gen;
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+		      IECM_TXD_COMPLQ_GEN_M) >> IECM_TXD_COMPLQ_GEN_S;
+		if (test_bit(__IECM_Q_GEN_CHK, complq->flags) != gen)
+			break;
+
+		/* Find necessary info of TX queue to clean buffers */
+		tx_qid = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			 IECM_TXD_COMPLQ_QID_M) >> IECM_TXD_COMPLQ_QID_S;
+		tx_q = iecm_tx_find_q(vport, tx_qid);
+		if (!tx_q) {
+			dev_err(&complq->vport->adapter->pdev->dev,
+				"TxQ #%d not found\n", tx_qid);
+			goto fetch_next_desc;
+		}
+
+		/* Determine completion type */
+		ctype = (le16_to_cpu(tx_desc->qid_comptype_gen) &
+			IECM_TXD_COMPLQ_COMPL_TYPE_M) >>
+			IECM_TXD_COMPLQ_COMPL_TYPE_S;
+		switch (ctype) {
+		case IECM_TXD_COMPLT_RE:
+			hw_head = le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
+
+			cleaned_stats = iecm_tx_splitq_clean(tx_q, hw_head,
+							     budget, true);
+			break;
+		case IECM_TXD_COMPLT_RS:
+			if (test_bit(__IECM_Q_FLOW_SCH_EN, tx_q->flags)) {
+				compl_tag =
+				le16_to_cpu(tx_desc->q_head_compl_tag.compl_tag);
+
+				cleaned_stats =
+					iecm_tx_clean_flow_sch_bufs(tx_q,
+								    compl_tag,
+								    budget);
+			} else {
+				hw_head =
+				le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
+
+				cleaned_stats = iecm_tx_splitq_clean(tx_q,
+								     hw_head,
+								     budget,
+								     false);
+			}
+
+			break;
+		case IECM_TXD_COMPLT_SW_MARKER:
+			iecm_tx_handle_sw_marker(tx_q);
+			break;
+		default:
+			dev_err(&tx_q->vport->adapter->pdev->dev,
+				"Unknown TX completion type: %d\n",
+				ctype);
+			goto fetch_next_desc;
+		}
+
+		u64_stats_update_begin(&tx_q->stats_sync);
+		tx_q->q_stats.tx.packets += cleaned_stats.packets;
+		tx_q->q_stats.tx.bytes += cleaned_stats.bytes;
+		u64_stats_update_end(&tx_q->stats_sync);
+
+		if (unlikely(cleaned_stats.packets &&
+			     netif_carrier_ok(tx_q->vport->netdev) &&
+			     (IECM_DESC_UNUSED(tx_q) >= IECM_TX_WAKE_THRESH) &&
+			     (IECM_TX_BUF_UNUSED(tx_q) >= tx_q->desc_count >> 2))) {
+			/* Make sure any other threads stopping queue after
+			 * this see new next_to_clean.
+			 */
+			smp_mb();
+			if (tx_q->vport->adapter->state == __IECM_UP &&
+			    __netif_subqueue_stopped(tx_q->vport->netdev,
+						     tx_q->idx)) {
+				netif_wake_subqueue(tx_q->vport->netdev,
+						    tx_q->idx);
+			}
+		}
+
+fetch_next_desc:
+		tx_desc++;
+		ntc++;
+		if (unlikely(!ntc)) {
+			ntc -= complq->desc_count;
+			tx_desc = IECM_SPLITQ_TX_COMPLQ_DESC(complq, 0);
+			change_bit(__IECM_Q_GEN_CHK, complq->flags);
+		}
+
+		prefetch(tx_desc);
+
+		/* update budget accounting */
+		complq_budget--;
+	} while (likely(complq_budget));
+
+	ntc += complq->desc_count;
+	complq->next_to_clean = ntc;
+
+	clean_completed = !!complq_budget;
+
+	return clean_completed;
+}
+
 /**
  * iecm_tx_splitq_build_ctb - populate command tag and size for queue
  * based scheduling descriptors
@@ -2337,6 +2783,940 @@ netdev_tx_t iecm_tx_splitq_start(struct sk_buff *skb,
 	return iecm_tx_splitq_frame(skb, tx_q);
 }
 
+/**
+ * iecm_ptype_to_htype - get a hash type
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Returns appropriate hash type (such as PKT_HASH_TYPE_L2/L3/L4) to be used by
+ * skb_set_hash based on PTYPE as parsed by HW Rx pipeline and is part of
+ * Rx desc.
+ */
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded *decoded)
+{
+	if (!decoded->known)
+		return PKT_HASH_TYPE_NONE;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2 &&
+	    decoded->inner_prot)
+		return PKT_HASH_TYPE_L4;
+	if (decoded->payload_layer == IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2 &&
+	    decoded->outer_ip)
+		return PKT_HASH_TYPE_L3;
+	if (decoded->outer_ip == IECM_RX_PTYPE_OUTER_L2)
+		return PKT_HASH_TYPE_L2;
+
+	return PKT_HASH_TYPE_NONE;
+}
+
+/**
+ * iecm_rx_hash - set the hash value in the skb
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ */
+static void
+iecm_rx_hash(struct iecm_queue *rxq, struct sk_buff *skb,
+	     struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+	     struct iecm_rx_ptype_decoded *decoded)
+{
+	u32 hash;
+
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXHASH))
+		return;
+
+	hash = le16_to_cpu(rx_desc->hash1) |
+	       (rx_desc->ff2_mirrid_hash2.hash2 << 16) |
+	       (rx_desc->hash3 << 24);
+
+	skb_set_hash(skb, hash, iecm_ptype_to_htype(decoded));
+}
+
+/**
+ * iecm_rx_csum - Indicate in skb if checksum is good
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @csum_bits: checksum fields extracted from the descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * skb->protocol must be set before this function is called
+ */
+static void iecm_rx_csum(struct iecm_queue *rxq, struct sk_buff *skb,
+			 struct iecm_rx_csum_decoded *csum_bits,
+			 struct iecm_rx_ptype_decoded *decoded)
+{
+	bool ipv4, ipv6;
+
+	/* Start with CHECKSUM_NONE and by default csum_level = 0 */
+	skb->ip_summed = CHECKSUM_NONE;
+
+	/* check if Rx checksum is enabled */
+	if (!iecm_is_feature_ena(rxq->vport, NETIF_F_RXCSUM))
+		return;
+
+	/* check if HW has decoded the packet and checksum */
+	if (!(csum_bits->l3l4p))
+		return;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+	       (decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (ipv4 && (csum_bits->ipe || csum_bits->eipe))
+		goto checksum_fail;
+
+	if (ipv6 && csum_bits->ipv6exadd)
+		return;
+
+	/* HW checksum will be invalid if vlan stripping is not enabled and
+	 * packet has an outer vlan tag. raw_csum_inv will also not be set
+	 * even though it's invalid.
+	 */
+	if (skb_vlan_tag_present(skb))
+		return;
+
+	/* check for L4 errors and handle packets that were not able to be
+	 * checksummed
+	 */
+	if (csum_bits->l4e)
+		goto checksum_fail;
+
+	/* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */
+	switch (decoded->inner_prot) {
+	case IECM_RX_PTYPE_INNER_PROT_ICMP:
+	case IECM_RX_PTYPE_INNER_PROT_TCP:
+	case IECM_RX_PTYPE_INNER_PROT_UDP:
+	case IECM_RX_PTYPE_INNER_PROT_SCTP:
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+	default:
+		break;
+	}
+	return;
+
+checksum_fail:
+	rxq->vport->port_stats.rx_hw_csum_err++;
+}
+
+/**
+ * iecm_rx_splitq_extract_csum_bits - Extract checksum bits from descriptor
+ * @rx_desc: receive descriptor
+ * @csum: structure to extract checksum fields
+ *
+ **/
+static void
+iecm_rx_splitq_extract_csum_bits(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+				 struct iecm_rx_csum_decoded *csum)
+{
+	u8 qword0, qword1;
+
+	qword0 = rx_desc->status_err0_qw0;
+	qword1 = rx_desc->status_err0_qw1;
+
+	csum->ipe = !!(qword1 &
+		       BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_IPE_S));
+	csum->eipe = !!(qword1 &
+			BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_EIPE_S));
+	csum->l4e = !!(qword1 &
+		       BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_L4E_S));
+	csum->l3l4p = !!(qword1 &
+			 BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L3L4P_S));
+	csum->ipv6exadd =
+			!!(qword0 &
+			   BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_IPV6EXADD_S));
+	csum->rsc = !!(le16_to_cpu(rx_desc->hdrlen_flags) &
+		       VIRTCHNL2_RX_FLEX_DESC_ADV_RSC_M);
+	csum->raw_csum_inv = !!(le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_FF0_S));
+	csum->raw_csum = le16_to_cpu(rx_desc->misc.raw_cs);
+	csum->pprs = 0;
+}
+
+/**
+ * iecm_rx_rsc - Set the RSC fields in the skb
+ * @rxq : Rx descriptor ring packet is being transacted on
+ * @skb : pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ * @decoded: Decoded Rx packet type related fields
+ *
+ * Return 0 on success and error code on failure
+ *
+ * Populate the skb fields with the total number of RSC segments, RSC payload
+ * length and packet type.
+ */
+static int iecm_rx_rsc(struct iecm_queue *rxq, struct sk_buff *skb,
+		       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+		       struct iecm_rx_ptype_decoded *decoded)
+{
+	u16 rsc_segments, rsc_payload_len;
+	struct tcphdr *tcph;
+	bool ipv4, ipv6;
+
+	if (!decoded->outer_ip)
+		return -EINVAL;
+
+	rsc_payload_len = le16_to_cpu(rx_desc->misc.rscseglen);
+	if (!rsc_payload_len)
+		return -EINVAL;
+
+	ipv4 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV4);
+	ipv6 = (decoded->outer_ip == IECM_RX_PTYPE_OUTER_IP) &&
+		(decoded->outer_ip_ver == IECM_RX_PTYPE_OUTER_IPV6);
+
+	if (!(ipv4 ^ ipv6))
+		return -EINVAL;
+
+	rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_payload_len);
+
+	NAPI_GRO_CB(skb)->count = rsc_segments;
+	skb_shinfo(skb)->gso_size = rsc_payload_len;
+
+	skb_reset_network_header(skb);
+
+	if (ipv4) {
+		struct iphdr *ipv4h = ip_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+
+		/* Reset and set transport header offset in skb */
+		skb_set_transport_header(skb, sizeof(struct iphdr));
+		tcph = tcp_hdr(skb);
+
+		/* Compute the TCP pseudo header checksum*/
+		tcph->check =
+			~tcp_v4_check(skb->len - skb_transport_offset(skb),
+				      ipv4h->saddr, ipv4h->daddr, 0);
+	} else {
+		struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+
+		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+		skb_set_transport_header(skb, sizeof(struct ipv6hdr));
+		tcph = tcp_hdr(skb);
+		tcph->check =
+			~tcp_v6_check(skb->len - skb_transport_offset(skb),
+				      &ipv6h->saddr, &ipv6h->daddr, 0);
+	}
+
+	tcp_gro_complete(skb);
+
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.rsc_pkts++;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	return 0;
+}
+
+/**
+ * iecm_rx_process_skb_fields - Populate skb header fields from Rx descriptor
+ * @rxq: Rx descriptor ring packet is being transacted on
+ * @skb: pointer to current skb being populated
+ * @rx_desc: Receive descriptor
+ *
+ * This function checks the ring, descriptor, and packet information in
+ * order to populate the hash, checksum, VLAN, protocol, and
+ * other fields within the skb.
+ */
+int
+iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			   struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+{
+	struct iecm_rx_ptype_decoded decoded;
+	struct iecm_rx_csum_decoded csum_bits;
+	u16 rx_ptype;
+	int err = 0;
+
+	rx_ptype = le16_to_cpu(rx_desc->ptype_err_fflags0) &
+				VIRTCHNL2_RX_FLEX_DESC_ADV_PTYPE_M;
+
+	decoded = rxq->vport->rx_ptype_lkup[rx_ptype];
+	if (!decoded.known)
+		return -EINVAL;
+
+	/* modifies the skb - consumes the enet header */
+	skb->protocol = eth_type_trans(skb, rxq->vport->netdev);
+	iecm_rx_splitq_extract_csum_bits(rx_desc, &csum_bits);
+	iecm_rx_csum(rxq, skb, &csum_bits, &decoded);
+	/* process RSS/hash */
+	iecm_rx_hash(rxq, skb, rx_desc, &decoded);
+
+	if (csum_bits.rsc)
+		err = iecm_rx_rsc(rxq, skb, rx_desc, &decoded);
+
+	return err;
+}
+
+/**
+ * iecm_rx_skb - Send a completed packet up the stack
+ * @rxq: Rx ring in play
+ * @skb: packet to send up
+ * @vlan_tag: packet vlan tag
+ *
+ * This function sends the completed packet (via. skb) up the stack using
+ * gro receive functions
+ */
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag)
+{
+	/* Adding HW VLAN tag to skb must occur after processing csum */
+	if (vlan_tag & VLAN_VID_MASK)
+		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
+
+	napi_gro_receive(&rxq->q_vector->napi, skb);
+}
+
+/**
+ * iecm_rx_page_is_reserved - check if reuse is possible
+ * @page: page struct to check
+ */
+static bool iecm_rx_page_is_reserved(struct page *page)
+{
+	return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
+}
+
+/**
+ * iecm_rx_buf_adjust_pg - Prepare rx buffer for reuse
+ * @rx_buf: Rx buffer to adjust
+ * @size: Size of adjustment
+ *
+ * Update the offset within page so that rx buf will be ready to be reused.
+ * For systems with PAGE_SIZE < 8192 this function will flip the page offset
+ * so the second half of page assigned to rx buffer will be used, otherwise
+ * the offset is moved by the @size bytes
+ */
+void
+iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE < 8192)
+	if (rx_buf->buf_size > IECM_RX_BUF_2048)
+		/* flip to second page */
+		rx_buf->page_indx = !rx_buf->page_indx;
+	else
+		/* flip page offset to other buffer */
+		page_info->page_offset ^= size;
+#else
+	/* move offset up to the next cache line */
+	page_info->page_offset += size;
+#endif
+}
+
+/**
+ * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
+ * @rx_buf: buffer containing the page
+ *
+ * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
+ * which will assign the current buffer to the buffer that next_to_alloc is
+ * pointing to; otherwise, the dma mapping needs to be destroyed and
+ * page freed
+ */
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
+#endif /* PAGE_SIZE < 8192) */
+	unsigned int pagecnt_bias = page_info->pagecnt_bias;
+	struct page *page = page_info->page;
+
+	/* avoid re-using remote pages */
+	if (unlikely(iecm_rx_page_is_reserved(page)))
+		return false;
+
+#if (PAGE_SIZE < 8192)
+	/* if we are only owner of page we can reuse it */
+	if (unlikely((page_count(page) - pagecnt_bias) > 1))
+		return false;
+#else
+	if (rx_buf->page_offset > last_offset)
+		return false;
+#endif /* PAGE_SIZE < 8192) */
+
+	/* If we have drained the page fragment pool we need to update
+	 * the pagecnt_bias and page count so that we fully restock the
+	 * number of references the driver holds.
+	 */
+	if (unlikely(pagecnt_bias == 1)) {
+		page_ref_add(page, USHRT_MAX - 1);
+		page_info->pagecnt_bias = USHRT_MAX;
+	}
+
+	return true;
+}
+
+/**
+ * iecm_rx_add_frag - Add contents of Rx buffer to sk_buff as a frag
+ * @rx_buf: buffer containing page to add
+ * @skb: sk_buff to place the data into
+ * @size: packet length from rx_desc
+ *
+ * This function will add the data contained in rx_buf->page to the skb.
+ * It will just attach the page as a frag to the skb.
+ * The function will then update the page offset.
+ */
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+#if (PAGE_SIZE >= 8192)
+	unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+	unsigned int truesize = rx_buf->buf_size;
+#endif
+
+	skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page_info->page,
+			page_info->page_offset, size, truesize);
+
+	iecm_rx_buf_adjust_pg(rx_buf, truesize);
+}
+
+/**
+ * iecm_rx_get_buf_page - Fetch Rx buffer page and synchronize data for use
+ * @dev: device struct
+ * @rx_buf: Rx buf to fetch page for
+ * @size: size of buffer to add to skb
+ *
+ * This function will pull an Rx buffer page from the ring and synchronize it
+ * for use by the CPU.
+ */
+static void
+iecm_rx_get_buf_page(struct device *dev, struct iecm_rx_buf *rx_buf,
+		     const unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	prefetch(page_info->page);
+
+	/* we are reusing so sync this buffer for CPU use */
+	dma_sync_single_range_for_cpu(dev, page_info->dma,
+				      page_info->page_offset, size,
+				      DMA_FROM_DEVICE);
+
+	/* We have pulled a buffer for use, so decrement pagecnt_bias */
+	page_info->pagecnt_bias--;
+}
+
+/**
+ * iecm_rx_construct_skb - Allocate skb and populate it
+ * @rxq: Rx descriptor queue
+ * @rx_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page
+ * data from the current receive descriptor, taking care to set up the
+ * skb correctly.
+ */
+struct sk_buff *
+iecm_rx_construct_skb(struct iecm_queue *rxq, struct iecm_rx_buf *rx_buf,
+		      unsigned int size)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	void *va = page_address(page_info->page) + page_info->page_offset;
+	unsigned int headlen;
+	struct sk_buff *skb;
+
+	/* prefetch first cache line of first page */
+	prefetch(va);
+#if L1_CACHE_BYTES < 128
+	prefetch((u8 *)va + L1_CACHE_BYTES);
+#endif /* L1_CACHE_BYTES */
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	/* Determine available headroom for copy */
+	headlen = size;
+	if (headlen > IECM_RX_HDR_SIZE)
+		headlen = eth_get_headlen(skb->dev, va, IECM_RX_HDR_SIZE);
+
+	/* align pull length to size of long to optimize memcpy performance */
+	memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
+
+	/* if we exhaust the linear part then add what is left as a frag */
+	size -= headlen;
+	if (size) {
+#if (PAGE_SIZE >= 8192)
+		unsigned int truesize = SKB_DATA_ALIGN(size);
+#else
+		unsigned int truesize = rx_buf->buf_size;
+#endif
+		skb_add_rx_frag(skb, 0, page_info->page,
+				page_info->page_offset + headlen, size,
+				truesize);
+		/* buffer is used by skb, update page_offset */
+		iecm_rx_buf_adjust_pg(rx_buf, truesize);
+
+	} else {
+		/* buffer is unused, reset bias back to rx_buf; data was copied
+		 * onto skb's linear part so there's no need for adjusting
+		 * page offset and we can reuse this buffer as-is
+		 */
+		page_info->pagecnt_bias++;
+	}
+
+	return skb;
+}
+
+/**
+ * iecm_rx_hdr_construct_skb - Allocate skb and populate it from header buffer
+ * @rxq: Rx descriptor queue
+ * @hdr_buf: Rx buffer to pull data from
+ * @size: the length of the packet
+ *
+ * This function allocates an skb. It then populates it with the page data from
+ * the current receive descriptor, taking care to set up the skb correctly.
+ * This specifcally uses a header buffer to start building the skb.
+ */
+static struct sk_buff *
+iecm_rx_hdr_construct_skb(struct iecm_queue *rxq, struct iecm_dma_mem *hdr_buf,
+			  unsigned int size)
+{
+	struct sk_buff *skb;
+
+	/* allocate a skb to store the frags */
+	skb = __napi_alloc_skb(&rxq->q_vector->napi, IECM_RX_HDR_SIZE,
+			       GFP_ATOMIC | __GFP_NOWARN);
+	if (unlikely(!skb))
+		return NULL;
+
+	skb_record_rx_queue(skb, rxq->idx);
+
+	memcpy(__skb_put(skb, size), hdr_buf->va, size);
+
+	return skb;
+}
+
+/**
+ * iecm_rx_splitq_test_staterr - tests bits in Rx descriptor
+ * status and error fields
+ * @stat_err_field: field from descriptor to test bits in
+ * @stat_err_bits: value to mask
+ *
+ */
+bool
+iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits)
+{
+	return !!(stat_err_field & stat_err_bits);
+}
+
+/**
+ * iecm_rx_splitq_extract_vlan_tag - Extract vlan tag from the descriptor
+ * @desc: Rx flex descriptor
+ * @rxq: rxq to check the vlan flags
+ * @vlan_tag: vlan tag to fill in
+ *
+ * Return true if error bit is set in the descriptor, else return false and
+ * store the vlan_tag in the variable passed in the function parameters
+ */
+bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
+				     struct iecm_queue *rxq, u16 *vlan_tag)
+{
+	u8 stat_err0_qw0, stat_err_bits, stat_err1;
+
+	stat_err_bits = BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_RXE_S);
+	stat_err0_qw0 = desc->status_err0_qw0;
+	if (unlikely(iecm_rx_splitq_test_staterr(stat_err0_qw0, stat_err_bits)))
+		return true;
+
+	stat_err1 = desc->status_err1;
+
+	if (stat_err0_qw0 & BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L2TAG1P_S) &&
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG1, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag1);
+	if (stat_err1 & BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS1_L2TAG2P_S) &&
+	    test_bit(__IECM_Q_VLAN_TAG_LOC_L2TAG2, rxq->flags))
+		*vlan_tag = le16_to_cpu(desc->l2tag2);
+
+	return false;
+}
+
+/**
+ * iecm_rx_splitq_is_non_eop - process handling of non-EOP buffers
+ * @rx_desc: Rx descriptor for current buffer
+ *
+ * If the buffer is an EOP buffer, this function exits returning false,
+ * otherwise return true indicating that this is in fact a non-EOP buffer.
+ */
+static bool
+iecm_rx_splitq_is_non_eop(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+{
+	/* if we are the last buffer then there is nothing else to do */
+#define IECM_RXD_EOF BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_S)
+	if (likely(iecm_rx_splitq_test_staterr(rx_desc->status_err0_qw1,
+					       IECM_RXD_EOF)))
+		return false;
+
+	return true;
+}
+
+/**
+ * iecm_rx_splitq_recycle_buf - Attempt to recycle or realloc buffer
+ * @rxbufq: receive queue
+ * @rx_buf: Rx buffer to pull data from
+ *
+ * This function will clean up the contents of the rx_buf. It will either
+ * recycle the buffer or unmap it and free the associated resources. The buffer
+ * will then be placed on a refillq where it will later be reclaimed by the
+ * corresponding bufq.
+ *
+ * This works based on page flipping. If we assume e.g., a 4k page, it will be
+ * divided into two 2k buffers. We post the first half to hardware and, after
+ * using it, flip to second half of the page with iecm_adjust_pg_offset and
+ * post that to hardware. The third time through we'll flip back to first half
+ * of page and check if stack is still using it, if not we can reuse the buffer
+ * as is, otherwise we'll drain it and get a new page.
+ */
+static void iecm_rx_splitq_recycle_buf(struct iecm_queue *rxbufq,
+				       struct iecm_rx_buf *rx_buf)
+{
+	struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
+
+	if (!iecm_rx_can_reuse_page(rx_buf)) {
+		/* we are not reusing the buffer so unmap it */
+		dma_unmap_page_attrs(rxbufq->dev, page_info->dma, PAGE_SIZE,
+				     DMA_FROM_DEVICE, IECM_RX_DMA_ATTR);
+		__page_frag_cache_drain(page_info->page,
+					page_info->pagecnt_bias);
+
+		/* clear contents of buffer_info */
+		page_info->page = NULL;
+		rx_buf->skb = NULL;
+
+		/* It's possible the alloc can fail here but there's not much
+		 * we can do, bufq will have to try and realloc to fill the
+		 * hole.
+		 */
+		iecm_alloc_page(rxbufq, page_info);
+	}
+
+	/* We sync the memory back to hardware now to do as much work in this
+	 * context as feasible.  Hardware won't actually know about the buffer
+	 * until it's reclaimed off the refillq and put back into the bufq.
+	 */
+	if (likely(page_info->page)) {
+		dma_sync_single_range_for_device(rxbufq->dev, page_info->dma,
+						 page_info->page_offset,
+						 rxbufq->rx_buf_size,
+						 DMA_FROM_DEVICE);
+	}
+}
+
+/**
+ * iecm_rx_bump_ntc - Bump and wrap q->next_to_clean value
+ * @q: queue to bump
+ */
+void iecm_rx_bump_ntc(struct iecm_queue *q)
+{
+	u16 ntc = q->next_to_clean + 1;
+	/* fetch, update, and store next to clean */
+	if (ntc < q->desc_count) {
+		q->next_to_clean = ntc;
+	} else {
+		q->next_to_clean = 0;
+		change_bit(__IECM_Q_GEN_CHK, q->flags);
+	}
+}
+
+/**
+ * iecm_rx_splitq_clean - Clean completed descriptors from Rx queue
+ * @rxq: Rx descriptor queue to retrieve receive buffer queue
+ * @budget: Total limit on number of packets to process
+ *
+ * This function provides a "bounce buffer" approach to Rx interrupt
+ * processing. The advantage to this is that on systems that have
+ * expensive overhead for IOMMU access this provides a means of avoiding
+ * it by maintaining the mapping of the page to the system.
+ *
+ * Returns amount of work completed
+ */
+static int iecm_rx_splitq_clean(struct iecm_queue *rxq, int budget)
+{
+	int total_rx_bytes = 0, total_rx_pkts = 0;
+	struct iecm_queue *rx_bufq = NULL;
+	struct sk_buff *skb = rxq->skb;
+	bool failure = false;
+
+	/* Process Rx packets bounded by budget */
+	while (likely(total_rx_pkts < budget)) {
+		struct virtchnl2_rx_flex_desc_adv_nic_3 *splitq_flex_rx_desc;
+		struct iecm_sw_queue *refillq = NULL;
+		struct iecm_dma_mem *hdr_buf = NULL;
+		struct iecm_rxq_set *rxq_set = NULL;
+		struct iecm_rx_buf *rx_buf = NULL;
+		u16 gen_id, buf_id, vlan_tag = 0;
+		union virtchnl2_rx_desc *rx_desc;
+		unsigned int pkt_len = 0;
+		unsigned int hdr_len = 0;
+		 /* Header buffer overflow only valid for header split */
+		bool hbo = false;
+		int bufq_id;
+
+		/* get the Rx desc from Rx queue based on 'next_to_clean' */
+		rx_desc = IECM_RX_DESC(rxq, rxq->next_to_clean);
+		splitq_flex_rx_desc = (struct virtchnl2_rx_flex_desc_adv_nic_3 *)rx_desc;
+
+		/* This memory barrier is needed to keep us from reading
+		 * any other fields out of the rx_desc
+		 */
+		dma_rmb();
+
+		/* if the descriptor isn't done, no work yet to do */
+		gen_id = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id);
+		gen_id = (gen_id & VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M) >>
+						VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_S;
+		if (test_bit(__IECM_Q_GEN_CHK, rxq->flags) != gen_id)
+			break;
+
+		if ((splitq_flex_rx_desc->rxdid_ucast &
+		    VIRTCHNL2_RX_FLEX_DESC_ADV_RXDID_M) != VIRTCHNL2_RXDID_1_FLEX_SPLITQ) {
+			iecm_rx_bump_ntc(rxq);
+			rxq->vport->port_stats.rx_bad_descs++;
+			continue;
+		}
+
+		pkt_len = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id) &
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_PBUF_M;
+
+		hbo = splitq_flex_rx_desc->status_err0_qw1 &
+		      BIT(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_S);
+
+		if (unlikely(hbo)) {
+			rxq->vport->port_stats.rx_hsplit_hbo++;
+			goto bypass_hsplit;
+		}
+
+		hdr_len =
+			le16_to_cpu(splitq_flex_rx_desc->hdrlen_flags) &
+			VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M;
+
+bypass_hsplit:
+		bufq_id = le16_to_cpu(splitq_flex_rx_desc->pktlen_gen_bufq_id);
+		bufq_id = (bufq_id & VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M) >>
+			  VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_S;
+
+		rxq_set = container_of(rxq, struct iecm_rxq_set, rxq);
+		if (!bufq_id)
+			refillq = rxq_set->refillq0;
+		else
+			refillq = rxq_set->refillq1;
+
+		/* retrieve buffer from the rxq */
+		rx_bufq = &rxq->rxq_grp->splitq.bufq_sets[bufq_id].bufq;
+
+		buf_id = le16_to_cpu(splitq_flex_rx_desc->buf_id);
+
+		if (pkt_len) {
+			rx_buf = &rx_bufq->rx_buf.buf[buf_id];
+			iecm_rx_get_buf_page(rx_bufq->dev, rx_buf, pkt_len);
+		}
+
+		if (hdr_len) {
+			hdr_buf = rx_bufq->rx_buf.hdr_buf[buf_id];
+
+			dma_sync_single_for_cpu(rxq->dev, hdr_buf->pa, hdr_buf->size,
+						DMA_FROM_DEVICE);
+
+			skb = iecm_rx_hdr_construct_skb(rxq, hdr_buf, hdr_len);
+			rxq->vport->port_stats.rx_hsplit++;
+		}
+
+		if (pkt_len) {
+			if (skb)
+				iecm_rx_add_frag(rx_buf, skb, pkt_len);
+			else
+				skb = iecm_rx_construct_skb(rxq, rx_buf,
+							    pkt_len);
+		}
+
+		/* exit if we failed to retrieve a buffer */
+		if (!skb) {
+			/* If we fetched a buffer, but didn't use it
+			 * undo pagecnt_bias decrement
+			 */
+			if (rx_buf)
+				rx_buf->page_info[rx_buf->page_indx].pagecnt_bias++;
+			break;
+		}
+
+		if (rx_buf)
+			iecm_rx_splitq_recycle_buf(rx_bufq, rx_buf);
+		iecm_rx_post_buf_refill(refillq, buf_id);
+
+		iecm_rx_bump_ntc(rxq);
+		/* skip if it is non EOP desc */
+		if (iecm_rx_splitq_is_non_eop(splitq_flex_rx_desc))
+			continue;
+
+		/* extract vlan tag from the descriptor */
+		if (unlikely(iecm_rx_splitq_extract_vlan_tag(splitq_flex_rx_desc,
+							     rxq, &vlan_tag))) {
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* pad skb if needed (to make valid ethernet frame) */
+		if (eth_skb_pad(skb)) {
+			skb = NULL;
+			continue;
+		}
+
+		/* probably a little skewed due to removing CRC */
+		total_rx_bytes += skb->len;
+
+		/* protocol */
+		if (unlikely(iecm_rx_process_skb_fields(rxq, skb,
+							splitq_flex_rx_desc))) {
+			dev_kfree_skb_any(skb);
+			skb = NULL;
+			continue;
+		}
+
+		/* send completed skb up the stack */
+		iecm_rx_skb(rxq, skb, vlan_tag);
+		skb = NULL;
+
+		/* update budget accounting */
+		total_rx_pkts++;
+	}
+	rxq->skb = skb;
+	u64_stats_update_begin(&rxq->stats_sync);
+	rxq->q_stats.rx.packets += total_rx_pkts;
+	rxq->q_stats.rx.bytes += total_rx_bytes;
+	u64_stats_update_end(&rxq->stats_sync);
+
+	/* guarantee a trip back through this routine if there was a failure */
+	return unlikely(failure) ? budget : total_rx_pkts;
+}
+
+/**
+ * iecm_rx_update_bufq_desc - Update buffer queue descriptor
+ * @bufq: Pointer to the buffer queue
+ * @desc: Refill queue descriptor
+ * @buf_desc: Buffer queue descriptor
+ *
+ * Return 0 on success and negative on failure.
+ */
+static int iecm_rx_update_bufq_desc(struct iecm_queue *bufq, u16 *desc,
+				    struct virtchnl2_splitq_rx_buf_desc *buf_desc)
+{
+	struct iecm_page_info *page_info;
+	struct iecm_rx_buf *buf;
+	u16 buf_id;
+
+	buf_id = ((*desc) & IECM_RX_BI_BUFID_M) >> IECM_RX_BI_BUFID_S;
+
+	buf = &bufq->rx_buf.buf[buf_id];
+	page_info = &buf->page_info[buf->page_indx];
+
+	/* It's possible page alloc failed during rxq clean, try to
+	 * recover here.
+	 */
+	if (unlikely(!page_info->page)) {
+		if (iecm_alloc_page(bufq, page_info))
+			return -ENOMEM;
+	}
+	buf_desc->pkt_addr = cpu_to_le64(page_info->dma + page_info->page_offset);
+	buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
+
+	if (bufq->rx_hsplit_en) {
+		struct iecm_dma_mem *hdr_buf = bufq->rx_buf.hdr_buf[buf_id];
+
+		buf_desc->hdr_addr = cpu_to_le64(hdr_buf->pa);
+		dma_sync_single_for_device(bufq->dev, hdr_buf->pa,
+					   hdr_buf->size, DMA_FROM_DEVICE);
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_rx_clean_refillq - Clean refill queue buffers
+ * @bufq: buffer queue to post buffers back to
+ * @refillq: refill queue to clean
+ *
+ * This function takes care of the buffer refill management
+ */
+static void iecm_rx_clean_refillq(struct iecm_queue *bufq,
+				  struct iecm_sw_queue *refillq)
+{
+	struct virtchnl2_splitq_rx_buf_desc *buf_desc;
+	u16 refillq_ntc = refillq->next_to_clean;
+	u16 bufq_nta = bufq->next_to_alloc;
+	u16 *refill_desc;
+	int cleaned = 0;
+	u16 gen;
+
+	refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, refillq_ntc);
+	buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, bufq_nta);
+
+	/* make sure we stop at ring wrap in the unlikely case ring is full */
+	while (likely(cleaned < refillq->desc_count)) {
+		bool failure;
+
+		gen = ((*refill_desc) & IECM_RX_BI_GEN_M) >> IECM_RX_BI_GEN_S;
+		if (test_bit(__IECM_RFLQ_GEN_CHK, refillq->flags) != gen)
+			break;
+
+		failure = iecm_rx_update_bufq_desc(bufq, refill_desc,
+						   buf_desc);
+		if (failure)
+			break;
+
+		refillq_ntc++;
+		refill_desc++;
+		bufq_nta++;
+		buf_desc++;
+		cleaned++;
+
+		if (unlikely(refillq_ntc == refillq->desc_count)) {
+			change_bit(__IECM_RFLQ_GEN_CHK, refillq->flags);
+			refill_desc = IECM_SPLITQ_RX_BI_DESC(refillq, 0);
+			refillq_ntc = 0;
+		}
+		if (unlikely(bufq_nta == bufq->desc_count)) {
+			buf_desc = IECM_SPLITQ_RX_BUF_DESC(bufq, 0);
+			bufq_nta = 0;
+		}
+	}
+
+	if (cleaned) {
+		/* only update hardware tail in strides */
+		if (((bufq->next_to_use <= bufq_nta ? 0 : bufq->desc_count) +
+		    bufq_nta - bufq->next_to_use) >= bufq->rx_buf_stride)
+			iecm_rx_buf_hw_update(bufq, bufq_nta & ~(bufq->rx_buf_stride - 1));
+
+		/* update next to alloc since we have filled the ring */
+		refillq->next_to_clean = refillq_ntc;
+		bufq->next_to_alloc = bufq_nta;
+	}
+}
+
+/**
+ * iecm_rx_clean_refillq_all - Clean all refill queues
+ * @bufq: bufq with refillqs to clean
+ *
+ * Iterates through all refill queues assigned to the buffer queue assigned to
+ * this vector.  Returns true if clean is complete within budget, false
+ * otherwise.
+ */
+static void iecm_rx_clean_refillq_all(struct iecm_queue *bufq)
+{
+	struct iecm_bufq_set *bufq_set;
+	int i = 0;
+
+	bufq_set = container_of(bufq, struct iecm_bufq_set, bufq);
+	for (i = 0; i < bufq_set->num_refillqs; i++)
+		iecm_rx_clean_refillq(bufq, &bufq_set->refillqs[i]);
+}
+
 /**
  * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
  * @irq: interrupt number
@@ -2742,6 +4122,64 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_tx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_tx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget)
+{
+	bool clean_complete = true;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_txq, 1);
+	for (i = 0; i < q_vec->num_txq; i++) {
+		if (!iecm_tx_clean_complq(q_vec->tx[i], budget_per_q))
+			clean_complete = false;
+	}
+	return clean_complete;
+}
+
+/**
+ * iecm_rx_splitq_clean_all- Clean completetion queues
+ * @q_vec: queue vector
+ * @budget: Used to determine if we are in netpoll
+ * @cleaned: returns number of packets cleaned
+ *
+ * Returns false if clean is not complete else returns true
+ */
+static bool
+iecm_rx_splitq_clean_all(struct iecm_q_vector *q_vec, int budget,
+			 int *cleaned)
+{
+	bool clean_complete = true;
+	int pkts_cleaned = 0;
+	int i, budget_per_q;
+
+	budget_per_q = max(budget / q_vec->num_rxq, 1);
+	for (i = 0; i < q_vec->num_rxq; i++) {
+		struct iecm_queue *rxq = q_vec->rx[i];
+		int pkts_cleaned_per_q;
+
+		pkts_cleaned_per_q = iecm_rx_splitq_clean(rxq, budget_per_q);
+		/* if we clean as many as budgeted, we must not
+		 * be done
+		 */
+		if (pkts_cleaned_per_q >= budget_per_q)
+			clean_complete = false;
+		pkts_cleaned += pkts_cleaned_per_q;
+	}
+	*cleaned = pkts_cleaned;
+
+	for (i = 0; i < q_vec->num_bufq; i++)
+		iecm_rx_clean_refillq_all(q_vec->bufq[i]);
+
+	return clean_complete;
+}
+
 /**
  * iecm_vport_splitq_napi_poll - NAPI handler
  * @napi: struct from which you get q_vector
@@ -2749,8 +4187,34 @@ iecm_vport_intr_napi_ena_all(struct iecm_vport *vport)
  */
 static int iecm_vport_splitq_napi_poll(struct napi_struct *napi, int budget)
 {
-	/* stub */
-	return 0;
+	struct iecm_q_vector *q_vector =
+				container_of(napi, struct iecm_q_vector, napi);
+	bool clean_complete;
+	int work_done = 0;
+
+	clean_complete = iecm_tx_splitq_clean_all(q_vector, budget);
+
+	/* Handle case where we are called by netpoll with a budget of 0 */
+	if (budget <= 0)
+		return budget;
+
+	/* We attempt to distribute budget to each Rx queue fairly, but don't
+	 * allow the budget to go below 1 because that would exit polling early.
+	 */
+	clean_complete |= iecm_rx_splitq_clean_all(q_vector, budget,
+						   &work_done);
+
+	/* If work not completed, return budget and polling will return */
+	if (!clean_complete)
+		return budget;
+
+	/* Exit the polling mode, but don't re-enable interrupts if stack might
+	 * poll us due to busy-polling
+	 */
+	if (likely(napi_complete_done(napi, work_done)))
+		iecm_vport_intr_update_itr_ena_irq(q_vector);
+
+	return min_t(int, work_done, budget - 1);
 }
 
 /**
drivers/net/ethernet/intel/include/iecm.h +4 -0
index a655e797f457..3cf2a2f0cb0f 100644
@@ -12,6 +12,10 @@
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
 #include <net/tcp.h>
+#include <net/ip6_checksum.h>
+#include <net/ipv6.h>
+#include <net/sch_generic.h>
+#include <net/gro.h>
 #include <linux/version.h>
 #include <linux/dim.h>
 
drivers/net/ethernet/intel/include/iecm_txrx.h +20 -0
index 7ec742fd4c6b..086b0efc989a 100644
@@ -638,6 +638,7 @@ void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
 			      struct virtchnl2_create_vport *vport_msg);
 void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
 int iecm_vport_queues_alloc(struct iecm_vport *vport);
+void iecm_rx_post_buf_refill(struct iecm_sw_queue *refillq, u16 buf_id);
 void iecm_vport_queues_rel(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
 void iecm_vport_intr_rel(struct iecm_vport *vport);
@@ -650,14 +651,33 @@ int iecm_vport_intr_init(struct iecm_vport *vport);
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 void iecm_vport_intr_ena_irq_all(struct iecm_vport *vport);
+enum
+pkt_hash_types iecm_ptype_to_htype(struct iecm_rx_ptype_decoded *decoded);
 int iecm_config_rss(struct iecm_vport *vport);
 void iecm_fill_dflt_rss_lut(struct iecm_vport *vport);
 int iecm_init_rss(struct iecm_vport *vport);
 void iecm_deinit_rss(struct iecm_vport *vport);
+bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf);
+void iecm_rx_buf_adjust_pg(struct iecm_rx_buf *rx_buf, unsigned int size);
+void iecm_rx_add_frag(struct iecm_rx_buf *rx_buf, struct sk_buff *skb,
+		      unsigned int size);
+struct sk_buff *iecm_rx_construct_skb(struct iecm_queue *rxq,
+				      struct iecm_rx_buf *rx_buf,
+				      unsigned int size);
+void iecm_rx_skb(struct iecm_queue *rxq, struct sk_buff *skb, u16 vlan_tag);
 bool iecm_init_rx_buf_hw_alloc(struct iecm_queue *rxq, struct iecm_rx_buf *buf);
 void iecm_rx_buf_hw_update(struct iecm_queue *rxq, u32 val);
 void iecm_tx_buf_hw_update(struct iecm_queue *tx_q, u32 val,
 			   bool xmit_more);
+void iecm_rx_splitq_put_bufs(struct iecm_queue *rx_bufq,
+			     struct iecm_rx_buf *hdr_buf,
+			     struct iecm_rx_buf *rx_buf);
+bool iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits);
+int iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
+			       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc);
+bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
+				     struct iecm_queue *rxq, u16 *vlan_tag);
+void iecm_rx_bump_ntc(struct iecm_queue *q);
 void iecm_tx_buf_rel(struct iecm_queue *tx_q, struct iecm_tx_buf *tx_buf);
 unsigned int iecm_size_to_txd_count(unsigned int size);
 unsigned int iecm_tx_desc_count_required(struct sk_buff *skb);
Signature · 1 line
2.33.0
author
#58 lore raw

PATCH 14/19 iecm: implement singleq napi_poll

In reply to Alan Brady

This adds everything we do the more traditional singleq model data path.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |    2 +-
 .../ethernet/intel/iecm/iecm_singleq_txrx.c   | 1208 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |    1 +
 .../net/ethernet/intel/include/iecm_txrx.h    |   31 +
 4 files changed, 1237 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +1 -1
index cc82e665dfaf..cbde65f1c523 100644
@@ -2723,7 +2723,7 @@ static const struct net_device_ops iecm_netdev_ops_splitq = {
 static const struct net_device_ops iecm_netdev_ops_singleq = {
 	.ndo_open = iecm_open,
 	.ndo_stop = iecm_stop,
-	.ndo_start_xmit = NULL,
+	.ndo_start_xmit = iecm_tx_singleq_start,
 	.ndo_set_rx_mode = iecm_set_rx_mode,
 	.ndo_validate_addr = eth_validate_addr,
 	.ndo_set_mac_address = iecm_set_mac,
drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c +1204 -4

1,224 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +1 -0
index 3cf2a2f0cb0f..97c9935b832d 100644
@@ -8,6 +8,7 @@
 #include <net/pkt_cls.h>
 #include <linux/aer.h>
 #include <linux/pci.h>
+#include <linux/sctp.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
drivers/net/ethernet/intel/include/iecm_txrx.h +31 -0
index 086b0efc989a..4dba4f52be98 100644
@@ -624,6 +624,26 @@ struct iecm_txq_group {
 
 struct iecm_adapter;
 
+/**
+ * iecm_tx_singleq_build_ctob - populate command tag offset and size
+ * @td_cmd: Command to be filled in desc
+ * @td_offset: Offset to be filled in desc
+ * @size: Size of the buffer
+ * @td_tag: vlan tag to be filled
+ *
+ * Returns the 64 bit value populated with the input parameters
+ */
+static inline __le64
+iecm_tx_singleq_build_ctob(u64 td_cmd, u64 td_offset, unsigned int size,
+			   u64 td_tag)
+{
+	return cpu_to_le64(IECM_TX_DESC_DTYPE_DATA |
+			   (td_cmd    << IECM_TXD_QW1_CMD_S) |
+			   (td_offset << IECM_TXD_QW1_OFFSET_S) |
+			   ((u64)size << IECM_TXD_QW1_TX_BUF_SZ_S) |
+			   (td_tag    << IECM_TXD_QW1_L2TAG1_S));
+}
+
 void iecm_tx_splitq_build_ctb(union iecm_tx_flex_desc *desc,
 			      struct iecm_tx_splitq_params *parms,
 			      u16 td_cmd, u16 size);
@@ -673,8 +693,19 @@ void iecm_rx_splitq_put_bufs(struct iecm_queue *rx_bufq,
 			     struct iecm_rx_buf *hdr_buf,
 			     struct iecm_rx_buf *rx_buf);
 bool iecm_rx_splitq_test_staterr(u8 stat_err_field, const u8 stat_err_bits);
+bool iecm_rx_singleq_test_staterr(union virtchnl2_rx_desc *rx_desc,
+				  const u64 stat_err_bits);
 int iecm_rx_process_skb_fields(struct iecm_queue *rxq, struct sk_buff *skb,
 			       struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc);
+void iecm_rx_singleq_process_skb_fields(struct iecm_queue *rx_q, struct sk_buff *skb,
+					union virtchnl2_rx_desc *rx_desc, u16 ptype);
+void iecm_rx_singleq_extract_fields(struct iecm_queue *rx_q,
+				    union virtchnl2_rx_desc *rx_desc,
+				    struct iecm_rx_extracted *fields);
+void iecm_rx_singleq_bump_ntc(struct iecm_queue *q);
+bool iecm_rx_singleq_is_non_eop(struct iecm_queue *rxq,
+				union virtchnl2_rx_desc *rx_desc,
+				struct sk_buff *skb);
 bool iecm_rx_splitq_extract_vlan_tag(struct virtchnl2_rx_flex_desc_adv_nic_3 *desc,
 				     struct iecm_queue *rxq, u16 *vlan_tag);
 void iecm_rx_bump_ntc(struct iecm_queue *q);
Signature · 1 line
2.33.0
author
#62 lore raw

PATCH 15/19 iecm: implement ethtool callbacks

In reply to Alan Brady

This does everything needed to handle ethtool ops minus a few stubs for cloud filters and other advanced features which will be added in later in this series.

---
 drivers/net/ethernet/intel/iecm/Makefile      |    1 +
 .../net/ethernet/intel/iecm/iecm_ethtool.c    | 1325 +++++++++++++++++
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   11 +-
 drivers/net/ethernet/intel/include/iecm.h     |    1 +
 4 files changed, 1337 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_ethtool.c
drivers/net/ethernet/intel/iecm/Makefile +1 -0
index 205d6f2b436a..fe2ed403d35c 100644
@@ -15,6 +15,7 @@ iecm-y := \
 	iecm_virtchnl.o \
 	iecm_txrx.o \
 	iecm_singleq_txrx.o \
+	iecm_ethtool.o \
 	iecm_controlq.o \
 	iecm_controlq_setup.o \
 	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_ethtool.c new file +1325 -0

1,325 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -1
index cbde65f1c523..c5900723b018 100644
@@ -871,6 +871,7 @@ static int iecm_cfg_netdev(struct iecm_vport *vport)
 	netdev->hw_features |= dflt_features | offloads;
 	netdev->hw_enc_features |= dflt_features | offloads;
 
+	iecm_set_ethtool_ops(netdev);
 	SET_NETDEV_DEV(netdev, &adapter->pdev->dev);
 
 	/* carrier off on init to avoid Tx hangs */
@@ -1150,7 +1151,15 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
  */
 static void iecm_statistics_task(struct work_struct *work)
 {
-	/* stub */
+	struct iecm_adapter *adapter = container_of(work,
+						    struct iecm_adapter,
+						    stats_task.work);
+	if (test_bit(__IECM_MB_STATS_PENDING, adapter->flags) &&
+	    !test_bit(__IECM_HR_RESET_IN_PROG, adapter->flags))
+		adapter->dev_ops.vc_ops.get_stats_msg(adapter->vports[0]);
+
+	queue_delayed_work(adapter->stats_wq, &adapter->stats_task,
+			   msecs_to_jiffies(1000));
 }
 
 /**
drivers/net/ethernet/intel/include/iecm.h +1 -0
index 97c9935b832d..d118da1ea8cd 100644
@@ -745,6 +745,7 @@ int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     void *msg, int msg_size);
 int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
+void iecm_set_ethtool_ops(struct net_device *netdev);
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async);
 int iecm_set_promiscuous(struct iecm_adapter *adapter);
Signature · 1 line
2.33.0
author
#66 lore raw

PATCH 16/19 iecm: implement flow director

In reply to Alan Brady

From: Haiyue Wang <[email protected]>

This adds everthing needed to do flow director commands.

---
 .../net/ethernet/intel/iecm/iecm_ethtool.c    |   17 +-
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 1528 ++++++++++++++++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |  119 ++
 drivers/net/ethernet/intel/include/iecm.h     |  112 ++
 4 files changed, 1770 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_ethtool.c +12 -5
index 32d905fb1bb6..7e252b25e02d 100644
@@ -15,6 +15,7 @@ static int iecm_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
 			  u32 __always_unused *rule_locs)
 {
 	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
+	struct iecm_adapter *adapter = vport->adapter;
 	int ret = -EOPNOTSUPP;
 
 	switch (cmd->cmd) {
@@ -23,14 +24,19 @@ static int iecm_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
 		ret = 0;
 		break;
 	case ETHTOOL_GRXCLSRLCNT:
-		/* stub */
+		if (!iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+				     VIRTCHNL2_CAP_FDIR))
+			break;
+		cmd->rule_cnt =
+			adapter->config_data.fdir_config.num_active_filters;
+		cmd->data = IECM_MAX_FDIR_FILTERS;
 		ret = 0;
 		break;
 	case ETHTOOL_GRXCLSRULE:
-		/* stub */
+		ret = iecm_get_fdir_fltr_entry(vport, cmd);
 		break;
 	case ETHTOOL_GRXCLSRLALL:
-		/* stub */
+		ret = iecm_get_fdir_fltr_ids(vport, cmd, (u32 *)rule_locs);
 		break;
 	case ETHTOOL_GRXFH:
 		/* stub */
@@ -51,14 +57,15 @@ static int iecm_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  */
 static int iecm_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
 {
+	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
 	int ret = -EOPNOTSUPP;
 
 	switch (cmd->cmd) {
 	case ETHTOOL_SRXCLSRLINS:
-		/* stub */
+		ret = iecm_add_fdir_fltr(vport, cmd);
 		break;
 	case ETHTOOL_SRXCLSRLDEL:
-		/* stub */
+		ret = iecm_del_fdir_fltr(vport, cmd);
 		break;
 	case ETHTOOL_SRXFH:
 		/* stub */
drivers/net/ethernet/intel/iecm/iecm_lib.c +1527 -1

1,570 lines not on this page · raw message

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +119 -0

125 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +112 -0

136 lines not on this page · raw message

Signature · 1 line
2.33.0
author
#70 lore raw

PATCH 17/19 iecm: implement cloud filters

In reply to Alan Brady

This gives iecm the ability to deal with cloud filters and other traffic classes.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 900 +++++++++++++++++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |  68 ++
 drivers/net/ethernet/intel/include/iecm.h     |  25 +
 3 files changed, 992 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +899 -1
index 35c0cbc42ebe..d11413cb438c 100644
@@ -43,9 +43,16 @@ static int iecm_get_vport_index(struct iecm_adapter *adapter,
  */
 bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)
 {
+	struct iecm_channel_config *ch_config;
 	bool ena;
 
 	switch (feature) {
+	case NETIF_F_HW_TC:
+		ch_config = &vport->adapter->config_data.ch_config;
+		ena = (vport->netdev->features & feature) &&
+			(ch_config->num_tc > IECM_START_CHNL_TC) &&
+			(ch_config->tc_running);
+		break;
 	default:
 		ena = vport->netdev->features & feature;
 		break;
@@ -53,6 +60,23 @@ bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)
 	return ena;
 }
 
+/**
+ * iecm_is_adq_v2_ena - Determine whether ADQ V2 is enabled
+ * @vport: virtual port struct
+ *
+ * This function returns true based on negotiated capability ADQ_V2
+ * if set and ADQ enabled
+ */
+static bool iecm_is_adq_v2_ena(struct iecm_vport *vport)
+{
+	/* iecm_is_feature_ena tells if the netdev flag is set and adq is
+	 * enabled
+	 */
+	return (iecm_is_feature_ena(vport, NETIF_F_HW_TC) &&
+		iecm_is_cap_ena(vport->adapter, IECM_OTHER_CAPS,
+				VIRTCHNL2_CAP_ADQ));
+}
+
 /**
  * iecm_is_vlan_cap_ena - Check if VLAN capability is enabled
  * @adapter: pointer to adapter
@@ -946,6 +970,28 @@ static int iecm_get_free_slot(void *array, int size, int curr)
 	return next;
 }
 
+/**
+ * iecm_remove_cloud_filters - Remove all cloud filters
+ * @vport: vport structure
+ */
+static void iecm_remove_cloud_filters(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_cloud_filter_config *cf_config;
+
+	cf_config = &adapter->config_data.cf_config;
+	if (!list_empty(&cf_config->cloud_filter_list)) {
+		struct iecm_cloud_filter *cf;
+
+		spin_lock_bh(&adapter->cloud_filter_list_lock);
+		list_for_each_entry(cf, &cf_config->cloud_filter_list, list) {
+			cf->remove = true;
+		}
+		spin_unlock_bh(&adapter->cloud_filter_list_lock);
+		iecm_send_add_del_cloud_filter_msg(vport, false);
+	}
+}
+
 /**
  * iecm_remove_vlan_filters - Remove all vlan filters
  * @vport: vport structure
@@ -1044,8 +1090,14 @@ static void iecm_vport_stop(struct iecm_vport *vport)
 	if (test_and_clear_bit(__IECM_DEL_QUEUES,
 			       vport->adapter->flags))
 		iecm_send_delete_queues_msg(vport);
-	if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags))
+	/* In function reset/rmmod path we call unregister_netdev which
+	 * internally calls delete cloud filters. We remove cloud filters only
+	 * when the interface goes down
+	 */
+	if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags)) {
+		iecm_remove_cloud_filters(vport);
 		iecm_remove_vlan_filters(vport);
+	}
 
 	iecm_remove_fdir_filters(vport);
 
@@ -1258,6 +1310,28 @@ static void iecm_restore_vlans(struct iecm_vport *vport)
 		iecm_set_all_vlans(vport);
 }
 
+/**
+ * iecm_restore_cloud_filters - Restore cloud filters
+ * @vport: vport structure
+ */
+static void iecm_restore_cloud_filters(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_cloud_filter_config *cf_config;
+
+	cf_config = &adapter->config_data.cf_config;
+	if (!list_empty(&cf_config->cloud_filter_list)) {
+		struct iecm_cloud_filter *cf;
+
+		spin_lock_bh(&adapter->cloud_filter_list_lock);
+		list_for_each_entry(cf, &cf_config->cloud_filter_list, list) {
+			cf->add = true;
+		}
+		spin_unlock_bh(&adapter->cloud_filter_list_lock);
+		iecm_send_add_del_cloud_filter_msg(vport, true);
+	}
+}
+
 /**
  * iecm_restore_fdir_filters - Restore all Flow Director filters
  * @vport: vport structure
@@ -1302,6 +1376,10 @@ static void iecm_restore_features(struct iecm_vport *vport)
 			dev_info(&adapter->pdev->dev, "Failed to restore promiscuous settings\n");
 	}
 
+	/* Restore cloud filters if ADQ is enabled */
+	if (iecm_is_feature_ena(vport, NETIF_F_HW_TC))
+		iecm_restore_cloud_filters(vport);
+
 	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_FDIR))
 		iecm_restore_fdir_filters(vport);
 }
@@ -2088,6 +2166,8 @@ int iecm_probe(struct pci_dev *pdev,
 	spin_lock_init(&adapter->vlan_list_lock);
 	spin_lock_init(&adapter->adv_rss_list_lock);
 	spin_lock_init(&adapter->fdir_fltr_list_lock);
+	INIT_LIST_HEAD(&adapter->config_data.cf_config.cloud_filter_list);
+	INIT_LIST_HEAD(&adapter->config_data.cf_config.block_cb_list);
 	INIT_LIST_HEAD(&adapter->config_data.mac_filter_list);
 	INIT_LIST_HEAD(&adapter->config_data.vlan_filter_list);
 	INIT_LIST_HEAD(&adapter->config_data.adv_rss_list);
@@ -2389,6 +2469,810 @@ static int iecm_offload_txtime(struct iecm_vport *vport,
 	return -EOPNOTSUPP;
 }
 
+/**
+ * iecm_is_vlan_tc_filter_allowed - allowed to add tc-filter using VLAN
+ * @vport: vport structure
+ * @vlan: VLAN to verify
+ *
+ * Using specified "vlan" ID, there must be active VLAN filter in VF's
+ * MAC-VLAN filter list.
+ */
+static bool
+iecm_is_vlan_tc_filter_allowed(struct iecm_vport *vport,
+			       struct iecm_vlan *vlan)
+{
+	struct iecm_vlan_filter *f;
+	bool allowed;
+
+	spin_lock_bh(&vport->adapter->vlan_list_lock);
+	f = iecm_find_vlan(vport, vlan);
+	allowed = (f && !f->add && !f->remove);
+	spin_unlock_bh(&vport->adapter->vlan_list_lock);
+	return allowed;
+}
+
+/**
+ * iecm_is_mac_tc_filter_allowed - allowed to add tc-filter using MAC addr
+ * @vport: vport structure
+ * @macaddr: MAC address
+ *
+ * Using specified MAC address, there must be active MAC filter in
+ * MAC filter list.
+ */
+static bool
+iecm_is_mac_tc_filter_allowed(struct iecm_vport *vport, const u8 *macaddr)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_mac_filter *f;
+	bool allowed;
+
+	spin_lock_bh(&adapter->mac_filter_list_lock);
+	f = iecm_find_mac_filter(vport, macaddr);
+	allowed = (f && !f->add && !f->remove);
+	spin_unlock_bh(&adapter->mac_filter_list_lock);
+	return allowed;
+}
+
+/**
+ * iecm_parse_keyid - Parse keyid
+ * @rule: Flow rule structure
+ * @field_flags: Cloud filter flags
+ */
+static void  iecm_parse_keyid(struct flow_rule *rule, u8 *field_flags)
+{
+	struct flow_match_enc_keyid match;
+
+	flow_rule_match_enc_keyid(rule, &match);
+
+	if (match.mask->keyid != 0)
+		*field_flags |= IECM_CLOUD_FIELD_TEN_ID;
+}
+
+/**
+ * iecm_parse_flow_type - Parse flow type based on L2 and L3 protocols
+ * @vport: vport structure
+ * @rule: rule from user
+ * @cf: Structure for the virtchnl filter
+ * @filter: Structure for the cloud filter
+ *
+ * Return 0 on success, negative on failure
+ */
+static int
+iecm_parse_flow_type(struct iecm_vport *vport,
+		     struct flow_rule *rule, struct virtchnl_filter *cf,
+		     struct iecm_cloud_filter *filter)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	enum virtchnl_flow_type flow_type;
+	struct flow_match_basic match;
+	u16 n_proto_mask = 0;
+	u16 n_proto_key = 0;
+	u16 n_proto = 0;
+	u8 ip_proto = 0;
+
+	flow_rule_match_basic(rule, &match);
+
+	n_proto_key = ntohs(match.key->n_proto);
+	n_proto_mask = ntohs(match.mask->n_proto);
+
+	if (n_proto_key == ETH_P_ALL) {
+		n_proto_key = 0;
+		n_proto_mask = 0;
+	}
+	n_proto = n_proto_key & n_proto_mask;
+	if (n_proto != ETH_P_IP && n_proto != ETH_P_IPV6)
+		return -EINVAL;
+
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ)) {
+		if (match.key->ip_proto != IPPROTO_TCP &&
+		    match.key->ip_proto != IPPROTO_UDP) {
+			dev_err(&adapter->pdev->dev,
+				"Only TCP or UDP transport is supported\n");
+			return -EINVAL;
+		}
+	} else if (match.key->ip_proto != IPPROTO_TCP) {
+		dev_err(&adapter->pdev->dev,
+			"Only TCP transport is supported\n");
+		return -EINVAL;
+	}
+	ip_proto = match.key->ip_proto;
+
+	/* determine VIRTCHNL flow_type based on L3 and L4 protocol */
+	if (n_proto == ETH_P_IP)
+		flow_type = (ip_proto == IPPROTO_TCP) ?
+			     VIRTCHNL_TCP_V4_FLOW :
+			     VIRTCHNL_UDP_V4_FLOW;
+	else
+		flow_type = (ip_proto == IPPROTO_TCP) ?
+			     VIRTCHNL_TCP_V6_FLOW :
+			     VIRTCHNL_UDP_V6_FLOW;
+	cf->flow_type = flow_type;
+	filter->f.flow_type = flow_type;
+
+	return 0;
+}
+
+/**
+ * iecm_parse_ether_header - Parse ethernet header fields
+ * @vport: vport structure
+ * @field_flags: Cloud filter flags
+ * @d_spec: Virtchnl structure for L4 specs
+ * @m_spec: Virtchnl structure for L4 specs
+ * @rule: Flow rule structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int
+iecm_parse_ether_header(struct iecm_vport *vport, u8 *field_flags,
+			struct virtchnl_l4_spec *d_spec,
+			struct virtchnl_l4_spec *m_spec,
+			struct flow_rule *rule)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct flow_match_eth_addrs match;
+	bool adv_adq_ena;
+
+	adv_adq_ena = iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+				      VIRTCHNL2_CAP_ADQ);
+
+	flow_rule_match_eth_addrs(rule, &match);
+
+	/* use is_broadcast and is_zero to check for all 0xf or 0 */
+	if (!is_zero_ether_addr(match.mask->dst)) {
+		if (adv_adq_ena || is_broadcast_ether_addr(match.mask->dst)) {
+			*field_flags |= IECM_CLOUD_FIELD_OMAC;
+		} else {
+			dev_err(&adapter->pdev->dev, "Bad ether dest mask %pM\n",
+				match.mask->dst);
+			return -EINVAL;
+		}
+	}
+
+	if (!is_zero_ether_addr(match.mask->src)) {
+		if (adv_adq_ena || is_broadcast_ether_addr(match.mask->src)) {
+			*field_flags |= IECM_CLOUD_FIELD_IMAC;
+		} else {
+			dev_err(&adapter->pdev->dev, "Bad ether src mask %pM\n",
+				match.mask->src);
+			return -EINVAL;
+		}
+	}
+
+	if (!is_zero_ether_addr(match.key->dst)) {
+		if (!iecm_is_mac_tc_filter_allowed(adapter->vports[0],
+						   match.key->dst)) {
+			dev_err(&adapter->pdev->dev,
+				"Dest MAC %pM doesn't belong to this device\n",
+				match.key->dst);
+			return -EINVAL;
+		}
+
+		if (is_valid_ether_addr(match.key->dst) ||
+		    is_multicast_ether_addr(match.key->dst)) {
+			/* set the mask if a valid dst_mac address */
+			if (adv_adq_ena)
+				ether_addr_copy(m_spec->dst_mac,
+						match.mask->dst);
+			else
+				eth_broadcast_addr(m_spec->dst_mac);
+			ether_addr_copy(d_spec->dst_mac,
+					match.key->dst);
+		}
+	}
+
+	if (!is_zero_ether_addr(match.key->src))
+		if (is_valid_ether_addr(match.key->src) ||
+		    is_multicast_ether_addr(match.key->src)) {
+			/* set the mask if a valid src_mac address */
+			if (adv_adq_ena) {
+				ether_addr_copy(m_spec->src_mac,
+						match.mask->src);
+			} else {
+				eth_broadcast_addr(m_spec->src_mac);
+			}
+			ether_addr_copy(d_spec->src_mac,
+					match.key->src);
+		}
+	return 0;
+}
+
+/**
+ * iecm_parse_vlan_header - Parse vlan header fields
+ * @vport: vport structure
+ * @field_flags: Cloud filter flags
+ * @d_spec: Virtchnl structure for L4 specs
+ * @m_spec: Virtchnl structure for L4 specs
+ * @rule: Flow rule structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int
+iecm_parse_vlan_header(struct iecm_vport *vport, u8 *field_flags,
+		       struct virtchnl_l4_spec *d_spec,
+		       struct virtchnl_l4_spec *m_spec,
+		       struct flow_rule *rule)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct flow_match_vlan match;
+
+	flow_rule_match_vlan(rule, &match);
+	if (match.mask->vlan_id) {
+		u16 vid = match.key->vlan_id & VLAN_VID_MASK;
+		struct iecm_vlan vlan;
+
+		vlan = IECM_VLAN(vid, ETH_P_8021Q);
+
+		if (match.mask->vlan_id != VLAN_VID_MASK) {
+			dev_err(&adapter->pdev->dev, "Bad vlan mask %u\n",
+				match.mask->vlan_id);
+			return -EINVAL;
+		}
+		if (!iecm_is_vlan_tc_filter_allowed(vport, &vlan)) {
+			dev_err(&adapter->pdev->dev,
+				"VLAN %u doesn't belong to this VF\n",
+				vid);
+			return -EINVAL;
+		}
+		*field_flags |= IECM_CLOUD_FIELD_IVLAN;
+		m_spec->vlan_id = cpu_to_be16(match.mask->vlan_id);
+		d_spec->vlan_id = cpu_to_be16(match.key->vlan_id);
+	}
+	return 0;
+}
+
+/**
+ * iecm_parse_ipv4_header - Parse ipv4 header fields
+ * @vport: vport structure
+ * @field_flags: Cloud filter flags
+ * @d_spec: Virtchnl structure for L4 specs
+ * @m_spec: Virtchnl structure for L4 specs
+ * @rule: Flow rule structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int
+iecm_parse_ipv4_header(struct iecm_vport *vport, u8 *field_flags,
+		       struct virtchnl_l4_spec *d_spec,
+		       struct virtchnl_l4_spec *m_spec,
+		       struct flow_rule *rule)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct flow_match_ipv4_addrs match;
+	bool adv_adq_ena;
+
+	adv_adq_ena = iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+				      VIRTCHNL2_CAP_ADQ);
+
+	flow_rule_match_ipv4_addrs(rule, &match);
+
+	if (*field_flags & IECM_CLOUD_FIELD_TEN_ID) {
+		dev_info(&adapter->pdev->dev,
+			 "Tenant id not allowed for ip filter\n");
+		return -EINVAL;
+	}
+
+	if (match.mask->dst) {
+		if (adv_adq_ena || match.mask->dst == cpu_to_be32(0xffffffff)) {
+			*field_flags |= IECM_CLOUD_FIELD_IIP;
+		} else {
+			dev_err(&adapter->pdev->dev, "Bad ip dst mask 0x%08x\n",
+				be32_to_cpu(match.mask->dst));
+			return -EINVAL;
+		}
+	}
+
+	if (match.mask->src) {
+		if (adv_adq_ena || match.mask->src == cpu_to_be32(0xffffffff)) {
+			*field_flags |= IECM_CLOUD_FIELD_IIP;
+		} else {
+			dev_err(&adapter->pdev->dev, "Bad ip src mask 0x%08x\n",
+				be32_to_cpu(match.mask->dst));
+			return -EINVAL;
+		}
+	}
+
+	if (match.key->dst) {
+		if (adv_adq_ena)
+			m_spec->dst_ip[0] = match.mask->dst;
+		else
+			m_spec->dst_ip[0] = cpu_to_be32(0xffffffff);
+		d_spec->dst_ip[0] = match.key->dst;
+	}
+
+	if (match.key->src) {
+		if (adv_adq_ena)
+			m_spec->src_ip[0] = match.mask->src;
+		else
+			m_spec->src_ip[0] = cpu_to_be32(0xffffffff);
+		d_spec->src_ip[0] = match.key->src;
+	}
+	return 0;
+}
+
+/**
+ * iecm_parse_ipv6_header - Parse ipv6 header fields
+ * @vport: vport structure
+ * @field_flags: Cloud filter flags
+ * @d_spec: Virtchnl structure for L4 specs
+ * @m_spec: Virtchnl structure for L4 specs
+ * @rule: Flow rule structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int
+iecm_parse_ipv6_header(struct iecm_vport *vport, u8 *field_flags,
+		       struct virtchnl_l4_spec *d_spec,
+		       struct virtchnl_l4_spec *m_spec,
+		       struct flow_rule *rule)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct flow_match_ipv6_addrs match;
+	int i;
+
+	flow_rule_match_ipv6_addrs(rule, &match);
+
+	/* validate mask, make sure it is not IPV6_ADDR_ANY */
+	if (ipv6_addr_any(&match.mask->dst)) {
+		dev_err(&adapter->pdev->dev, "Bad ipv6 dst mask 0x%02x\n",
+			IPV6_ADDR_ANY);
+		return -EINVAL;
+	}
+
+	/* src and dest IPv6 address should not be LOOPBACK
+	 * (0:0:0:0:0:0:0:1) which can be represented as ::1
+	 */
+	if (ipv6_addr_loopback(&match.key->dst) ||
+	    ipv6_addr_loopback(&match.key->src)) {
+		dev_err(&adapter->pdev->dev,
+			"ipv6 addr should not be loopback\n");
+		return -EINVAL;
+	}
+
+	if (!ipv6_addr_any(&match.mask->dst) ||
+	    !ipv6_addr_any(&match.mask->src))
+		*field_flags |= IECM_CLOUD_FIELD_IIP;
+
+	/* copy dest IPv6 mask and address */
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ)) {
+		memcpy(&m_spec->dst_ip, &match.mask->dst.s6_addr32,
+		       sizeof(m_spec->dst_ip));
+	} else {
+		for (i = 0; i < 4; i++)
+			m_spec->dst_ip[i] = cpu_to_be32(0xffffffff);
+	}
+	memcpy(&d_spec->dst_ip, &match.key->dst.s6_addr32,
+	       sizeof(d_spec->dst_ip));
+
+	/* copy source IPv6 mask and address */
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADQ)) {
+		memcpy(&m_spec->src_ip, &match.mask->src.s6_addr32,
+		       sizeof(m_spec->src_ip));
+	} else {
+		for (i = 0; i < 4; i++)
+			m_spec->src_ip[i] = cpu_to_be32(0xffffffff);
+	}
+	memcpy(&d_spec->src_ip, &match.key->src.s6_addr32,
+	       sizeof(d_spec->src_ip));
+
+	return 0;
+}
+
+/**
+ * iecm_parse_l4_header - Parse l4 header fields
+ * @vport: vport structure
+ * @d_spec: Virtchnl structure for L4 specs
+ * @m_spec: Virtchnl structure for L4 specs
+ * @rule: Flow rule structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int
+iecm_parse_l4_header(struct iecm_vport *vport,
+		     struct virtchnl_l4_spec *d_spec,
+		     struct virtchnl_l4_spec *m_spec,
+		     struct flow_rule *rule)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct flow_match_ports match;
+
+	flow_rule_match_ports(rule, &match);
+
+	if (match.key->dst) {
+		if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+				    VIRTCHNL2_CAP_ADQ) ||
+		    match.mask->dst == cpu_to_be16(0xffff)) {
+			m_spec->dst_port = match.mask->dst;
+			d_spec->dst_port = match.key->dst;
+		} else {
+			dev_err(&adapter->pdev->dev, "Bad dst port mask %u\n",
+				be16_to_cpu(match.mask->dst));
+			return -EINVAL;
+		}
+	}
+
+	if (match.key->src) {
+		if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+				    VIRTCHNL2_CAP_ADQ) ||
+		    match.mask->src == cpu_to_be16(0xffff)) {
+			m_spec->src_port = match.mask->src;
+			d_spec->src_port = match.key->src;
+		} else {
+			dev_err(&adapter->pdev->dev, "Bad src port mask %u\n",
+				be16_to_cpu(match.mask->src));
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+
+/**
+ * iecm_parse_cls_flower - Parse tc flower filters provided by kernel
+ * @vport: vport structure
+ * @f: pointer to struct flow_cls_offload
+ * @filter: pointer to cloud filter structure
+ */
+static int iecm_parse_cls_flower(struct iecm_vport *vport,
+				 struct flow_cls_offload *f,
+				 struct iecm_cloud_filter *filter)
+{
+	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl_l4_spec *d_spec, *m_spec;
+	struct virtchnl_filter *cf = &filter->f;
+	struct flow_dissector *dissector;
+	u8 field_flags = 0;
+	u16 addr_type = 0;
+	int err;
+
+	dissector = rule->match.dissector;
+	if (dissector->used_keys &
+	    ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
+	      BIT(FLOW_DISSECTOR_KEY_BASIC) |
+	      BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
+	      BIT(FLOW_DISSECTOR_KEY_VLAN) |
+	      BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
+	      BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
+	      BIT(FLOW_DISSECTOR_KEY_ENC_KEYID) |
+	      BIT(FLOW_DISSECTOR_KEY_PORTS))) {
+		dev_err(&adapter->pdev->dev, "Unsupported key used: 0x%x\n",
+			dissector->used_keys);
+		return -EOPNOTSUPP;
+	}
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_KEYID))
+		iecm_parse_keyid(rule, &field_flags);
+
+	/* even though following code refers as "tcp_sec", it is not
+	 * just for TCP but a generic struct representing
+	 * L2, L3 + L4 fields if specified
+	 */
+	m_spec = &cf->mask.tcp_spec;
+	d_spec = &cf->data.tcp_spec;
+
+	/* determine flow type, TCP/UDP_V4[6]_FLOW based on
+	 * L2 proto (aka ETH proto) and L3 proto (aka IP_PROTO)
+	 */
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
+		err = iecm_parse_flow_type(vport, rule, cf, filter);
+		if (err)
+			return err;
+	}
+
+	/* process Ethernet header fields */
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
+		err = iecm_parse_ether_header(vport, &field_flags,
+					      d_spec, m_spec, rule);
+		if (err)
+			return err;
+	}
+
+	/* process VLAN header for single VLAN (type could be S/C-tag) */
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
+		err = iecm_parse_vlan_header(vport, &field_flags,
+					     d_spec, m_spec, rule);
+		if (err)
+			return err;
+	}
+
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
+		struct flow_match_control match;
+
+		flow_rule_match_control(rule, &match);
+		addr_type = match.key->addr_type;
+	}
+
+	/* process IPv4 header */
+	if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
+		err = iecm_parse_ipv4_header(vport, &field_flags,
+					     d_spec, m_spec, rule);
+		if (err)
+			return err;
+	}
+
+	/* process IPv6 header */
+	if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
+		err = iecm_parse_ipv6_header(vport, &field_flags,
+					     d_spec, m_spec, rule);
+		if (err)
+			return err;
+	}
+
+	/* process L4 header, supported L4 protocols are TCP and UDP */
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) {
+		err = iecm_parse_l4_header(vport, d_spec, m_spec, rule);
+		if (err)
+			return err;
+	}
+	cf->field_flags = field_flags;
+
+	return 0;
+}
+
+/**
+ * iecm_handle_tclass - Forward to a traffic class on the device
+ * @vport: vport structure
+ * @tc: traffic class index on the device
+ * @filter: pointer to cloud filter structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int iecm_handle_tclass(struct iecm_vport *vport, int tc,
+			      struct iecm_cloud_filter *filter)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (tc == 0)
+		return 0;
+	if ((!iecm_is_adq_v2_ena(vport)) &&
+	    !filter->f.data.tcp_spec.dst_port) {
+		dev_err(&adapter->pdev->dev,
+			"Specify destination port to redirect to traffic class other than TC0\n");
+		return -EINVAL;
+	}
+	/* redirect to a traffic class on the same device */
+	filter->f.action = VIRTCHNL_ACTION_TC_REDIRECT;
+	filter->f.action_meta = tc;
+	return 0;
+}
+
+/* iecm_find_cf - Find the cloud filter in the list
+ * @vport: vport structure
+ * @cookie: filter specific cookie
+ *
+ * Returns pointer to the filter object or NULL. Must be called while holding
+ * cloud_filter_list_lock.
+ */
+static struct iecm_cloud_filter *iecm_find_cf(struct iecm_vport *vport,
+					      unsigned long *cookie)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_cloud_filter *filter = NULL;
+
+	if (!cookie)
+		return NULL;
+
+	list_for_each_entry(filter,
+			    &adapter->config_data.cf_config.cloud_filter_list,
+			    list) {
+		if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
+			return filter;
+	}
+	return NULL;
+}
+
+/**
+ * iecm_configure_clsflower - Add tc flower filters
+ * @vport: vport structure
+ * @cls_flower: Pointer to struct flow_cls_offload
+ *
+ * Return 0 on success, negative on failure
+ */
+static int iecm_configure_clsflower(struct iecm_vport *vport,
+				    struct flow_cls_offload *cls_flower)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_user_config_data *config_data;
+	struct iecm_cloud_filter *filter = NULL;
+	int err;
+	int tc;
+
+	config_data = &adapter->config_data;
+	tc = tc_classid_to_hwtc(vport->netdev, cls_flower->classid);
+	if (tc < 0) {
+		dev_err(&adapter->pdev->dev, "Invalid traffic class\n");
+		return -EINVAL;
+	}
+
+#define IECM_MAX_CLOUD_ADQ_FILTERS	128
+
+	if (config_data->cf_config.num_cloud_filters >=
+						IECM_MAX_CLOUD_ADQ_FILTERS) {
+		dev_err(&adapter->pdev->dev,
+			"Unable to add filter (action is forward to TC), reached max allowed filters (%u)\n",
+			IECM_MAX_CLOUD_ADQ_FILTERS);
+		return -ENOSPC;
+	}
+
+	/* bail out here if filter already exists */
+	spin_lock_bh(&adapter->cloud_filter_list_lock);
+	filter = iecm_find_cf(vport, &cls_flower->cookie);
+	if (filter) {
+		filter->remove = false;
+		dev_err(&adapter->pdev->dev, "Failed to add TC Flower filter, it already exists\n");
+		spin_unlock_bh(&adapter->cloud_filter_list_lock);
+		return -EEXIST;
+	}
+	spin_unlock_bh(&adapter->cloud_filter_list_lock);
+
+	filter = kzalloc(sizeof(*filter), GFP_KERNEL);
+	if (!filter)
+		return -ENOMEM;
+
+	filter->cookie = cls_flower->cookie;
+
+	/* set the mask to all zeroes to begin with */
+	memset(&filter->f.mask.tcp_spec, 0, sizeof(struct virtchnl_l4_spec));
+
+	/* start out with flow type and eth type IPv4 to begin with */
+	filter->f.flow_type = VIRTCHNL_TCP_V4_FLOW;
+	err = iecm_parse_cls_flower(vport, cls_flower, filter);
+	if (err)
+		goto error;
+
+	err = iecm_handle_tclass(vport, tc, filter);
+	if (err)
+		goto error;
+
+	/* add filter to the list */
+	spin_lock_bh(&adapter->cloud_filter_list_lock);
+	list_add_tail(&filter->list, &config_data->cf_config.cloud_filter_list);
+	filter->add = true;
+	spin_unlock_bh(&adapter->cloud_filter_list_lock);
+	err = iecm_send_add_del_cloud_filter_msg(vport, true);
+	spin_lock_bh(&adapter->cloud_filter_list_lock);
+	/* We have to find it again in case another thread has already
+	 * deleted and kfreed it.
+	 */
+	filter = iecm_find_cf(vport, &cls_flower->cookie);
+	if (filter && err) {
+		list_del(&filter->list);
+		spin_unlock_bh(&adapter->cloud_filter_list_lock);
+		goto error;
+	}
+	spin_unlock_bh(&adapter->cloud_filter_list_lock);
+
+	config_data->cf_config.num_cloud_filters++;
+error:
+	if (err)
+		kfree(filter);
+	return err;
+}
+
+/**
+ * iecm_delete_clsflower - Remove tc flower filters
+ * @vport: vport structure
+ * @cls_flower: Pointer to struct flow_cls_offload
+ *
+ * Return 0 on success, negative on failure
+ */
+static int iecm_delete_clsflower(struct iecm_vport *vport,
+				 struct flow_cls_offload *cls_flower)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_cloud_filter *filter = NULL;
+	int err = 0;
+
+	spin_lock_bh(&adapter->cloud_filter_list_lock);
+	filter = iecm_find_cf(vport, &cls_flower->cookie);
+	if (filter) {
+		filter->remove = true;
+		adapter->config_data.cf_config.num_cloud_filters--;
+	} else if (adapter->config_data.cf_config.num_cloud_filters) {
+		/* "num_cloud_filters" can become zero if egress qdisc is
+		 * detached as per design, driver deletes related filters
+		 * when qdisc is detached to avoid stale filters, hence
+		 * num_cloud_filters can become zero. But since netdev
+		 * layer doesn't know that filters are deleted by driver
+		 * implictly when egress qdisc is deleted, it sees filters
+		 * being present and "in_hw". User can request delete
+		 * of specific filter of detach ingress qdisc - in either of
+		 * those operation, filter(s) won't be found in driver cache,
+		 * hence instead of returning, let this function return SUCCESS
+		 * Returning of err as -EINVAL is only applicable when
+		 * unable to find filter and num_cloud_filters is non-zero
+		 */
+		err = -EINVAL;
+	}
+	spin_unlock_bh(&adapter->cloud_filter_list_lock);
+
+	if (filter) {
+		err = iecm_send_add_del_cloud_filter_msg(vport, false);
+		spin_lock_bh(&adapter->cloud_filter_list_lock);
+		/* It can happen that asynchronously the filter was already
+		 * deleted from the list. Make sure it's still there and marked
+		 * for remove under spinlock before actually trying to delete
+		 * from list.
+		 */
+		filter = iecm_find_cf(vport, &cls_flower->cookie);
+		if (filter) {
+			list_del(&filter->list);
+			kfree(filter);
+		}
+		spin_unlock_bh(&adapter->cloud_filter_list_lock);
+	}
+	return err;
+}
+
+/**
+ * iecm_setup_tc_cls_flower - flower classifier offloads
+ * @vport: vport structure
+ * @cls_flower: pointer to struct flow_cls_offload
+ *
+ * Return 0 on success, negative on failure
+ */
+static int iecm_setup_tc_cls_flower(struct iecm_vport *vport,
+				    struct flow_cls_offload *cls_flower)
+{
+	if (cls_flower->common.chain_index)
+		return -EOPNOTSUPP;
+
+	switch (cls_flower->command) {
+	case FLOW_CLS_REPLACE:
+		return iecm_configure_clsflower(vport, cls_flower);
+	case FLOW_CLS_DESTROY:
+		return iecm_delete_clsflower(vport, cls_flower);
+	case FLOW_CLS_STATS:
+		return -EOPNOTSUPP;
+	default:
+		return -EINVAL;
+	}
+}
+
+/**
+ * iecm_setup_tc_block_cb - block callback for tc
+ * @type: type of offload
+ * @type_data: offload data
+ * @cb_priv: Private adapter structure
+ *
+ * This function is the block callback for traffic classes
+ * Return 0 on success, negative on failure
+ **/
+static int iecm_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
+				  void *cb_priv)
+{
+	switch (type) {
+	case TC_SETUP_CLSFLOWER:
+		return iecm_setup_tc_cls_flower((struct iecm_vport *)cb_priv,
+						(struct flow_cls_offload *)
+						 type_data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+/**
+ * iecm_del_all_cloud_filters - delete all cloud filters on the traffic classes
+ * @vport: vport structure
+ *
+ * This function will loop through the list of cloud filters and deletes them.
+ **/
+static void iecm_del_all_cloud_filters(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_cloud_filter_config *cf_config;
+	struct iecm_cloud_filter *cf, *cftmp;
+
+	cf_config = &adapter->config_data.cf_config;
+	spin_lock_bh(&adapter->cloud_filter_list_lock);
+	list_for_each_entry_safe(cf, cftmp,
+				 &cf_config->cloud_filter_list,
+				 list) {
+		list_del(&cf->list);
+		kfree(cf);
+		cf_config->num_cloud_filters--;
+	}
+	spin_unlock_bh(&adapter->cloud_filter_list_lock);
+}
+
 /**
  * iecm_validate_tx_bandwidth - validate the max Tx bandwidth
  * @vport: vport structure
@@ -2596,6 +3480,7 @@ static int __iecm_setup_tc(struct iecm_vport *vport, void *type_data)
 			netif_tx_stop_all_queues(netdev);
 			netif_tx_disable(netdev);
 			ret = iecm_send_disable_channels_msg(vport);
+			iecm_del_all_cloud_filters(vport);
 			netif_tx_start_all_queues(netdev);
 			if (!test_bit(__IECM_REL_RES_IN_PROG, adapter->flags) &&
 			    !ret) {
@@ -2709,8 +3594,10 @@ static int iecm_setup_tc(struct net_device *netdev, enum tc_setup_type type,
 {
 	struct iecm_vport *vport = iecm_netdev_to_vport(netdev);
 	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_cloud_filter_config *cf_config;
 	int err = 0;
 
+	cf_config = &adapter->config_data.cf_config;
 	switch (type) {
 	case TC_SETUP_QDISC_ETF:
 		if (iecm_is_queue_model_split(vport->txq_model))
@@ -2720,6 +3607,17 @@ static int iecm_setup_tc(struct net_device *netdev, enum tc_setup_type type,
 					     type_data);
 		break;
 	case TC_SETUP_BLOCK:
+		if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
+				    VIRTCHNL2_CAP_ADQ) ||
+		    iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+				    VIRTCHNL2_CAP_ADQ)) {
+			err =
+			flow_block_cb_setup_simple((struct flow_block_offload *)
+						    type_data,
+						   &cf_config->block_cb_list,
+						   iecm_setup_tc_block_cb,
+						   vport, vport, true);
+		}
 		break;
 	case TC_SETUP_QDISC_MQPRIO:
 		if (iecm_is_cap_ena(adapter, IECM_BASE_CAPS,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +68 -0

74 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +25 -0
index b0785684cc63..0aab41cf982c 100644
@@ -403,6 +403,28 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+#define IECM_CLOUD_FIELD_OMAC		BIT(0)
+#define IECM_CLOUD_FIELD_IMAC		BIT(1)
+#define IECM_CLOUD_FIELD_IVLAN		BIT(2)
+#define IECM_CLOUD_FIELD_TEN_ID		BIT(3)
+#define IECM_CLOUD_FIELD_IIP		BIT(4)
+
+#define IECM_START_CHNL_TC		1
+
+struct iecm_cloud_filter {
+	struct list_head list;
+	struct virtchnl_filter f;
+	unsigned long cookie;
+	bool remove;		/* filter needs to be deleted */
+	bool add;		/* filter needs to be added */
+};
+
+struct iecm_cloud_filter_config {
+	struct list_head block_cb_list;		/* need to pass this to stack */
+	struct list_head cloud_filter_list;
+	u16 num_cloud_filters;
+};
+
 struct iecm_channel_config {
 	struct virtchnl_channel_info ch_info[VIRTCHNL_MAX_ADQ_V2_CHANNELS];
 	bool tc_running;
@@ -536,6 +558,7 @@ struct iecm_ptype_state {
 	bool outer_frag;
 	u8 tunnel_state;
 };
+
 /* User defined configuration values */
 struct iecm_user_config_data {
 	u32 num_req_tx_qs; /* user requested TX queues through ethtool */
@@ -550,6 +573,7 @@ struct iecm_user_config_data {
 	struct list_head vlan_filter_list;
 	struct list_head adv_rss_list;
 	struct iecm_fdir_fltr_config fdir_config;
+	struct iecm_cloud_filter_config cf_config;
 	struct iecm_channel_config ch_config;
 };
 
@@ -853,6 +877,7 @@ void iecm_set_ethtool_ops(struct net_device *netdev);
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 void iecm_add_del_ether_addrs(struct iecm_vport *vport, bool add, bool async);
 int iecm_set_promiscuous(struct iecm_adapter *adapter);
+int iecm_send_add_del_cloud_filter_msg(struct iecm_vport *vport, bool add);
 int iecm_send_add_fdir_filter_msg(struct iecm_vport *vport);
 int iecm_send_del_fdir_filter_msg(struct iecm_vport *vport);
 int iecm_get_fdir_fltr_entry(struct iecm_vport *vport,
Signature · 1 line
2.33.0
author
#73 lore raw

PATCH 18/19 iecm: add advanced rss

In reply to Alan Brady

From: Haiyue Wang <[email protected]>

Continuing with advanced features this implements what's needed to do advanced rss.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 547 ++++++++++++++++++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   |  71 +++
 drivers/net/ethernet/intel/include/iecm.h     |  73 +++
 3 files changed, 691 insertions(+)
drivers/net/ethernet/intel/iecm/iecm_lib.c +547 -0
index d11413cb438c..baa1e312652a 100644
@@ -1013,6 +1013,52 @@ static void iecm_remove_vlan_filters(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_remove_adv_rss_cfgs - Remove all RSS configuration
+ * @vport: vport structure
+ */
+static void iecm_remove_adv_rss_cfgs(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADV_RSS))
+		return;
+
+	if (!list_empty(&adapter->config_data.adv_rss_list)) {
+		struct iecm_adv_rss *rss;
+
+		spin_lock_bh(&adapter->adv_rss_list_lock);
+		list_for_each_entry(rss, &adapter->config_data.adv_rss_list,
+				    list) {
+			rss->remove = true;
+		}
+		spin_unlock_bh(&adapter->adv_rss_list_lock);
+		iecm_send_add_del_adv_rss_cfg_msg(vport, false);
+	}
+}
+
+/**
+ * iecm_del_all_adv_rss_cfgs - delete all RSS configuration
+ * @vport: vport structure
+ *
+ * This function will loop through the list of RSS configuration and deletes
+ * them.
+ **/
+static void iecm_del_all_adv_rss_cfgs(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_adv_rss *rss, *rss_tmp;
+
+	spin_lock_bh(&adapter->adv_rss_list_lock);
+	list_for_each_entry_safe(rss, rss_tmp,
+				 &adapter->config_data.adv_rss_list,
+				 list) {
+		list_del(&rss->list);
+		kfree(rss);
+	}
+	spin_unlock_bh(&adapter->adv_rss_list_lock);
+}
+
 /**
  * iecm_remove_fdir_filters - Remove all Flow Director filters
  * @vport: vport structure
@@ -1099,6 +1145,7 @@ static void iecm_vport_stop(struct iecm_vport *vport)
 		iecm_remove_vlan_filters(vport);
 	}
 
+	iecm_remove_adv_rss_cfgs(vport);
 	iecm_remove_fdir_filters(vport);
 
 	adapter->link_up = false;
@@ -1332,6 +1379,27 @@ static void iecm_restore_cloud_filters(struct iecm_vport *vport)
 	}
 }
 
+/**
+ * iecm_restore_adv_rss_cfgs - Restore all RSS configuration
+ * @vport: vport structure
+ */
+static void iecm_restore_adv_rss_cfgs(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (!list_empty(&adapter->config_data.adv_rss_list)) {
+		struct iecm_adv_rss *rss;
+
+		spin_lock_bh(&adapter->adv_rss_list_lock);
+		list_for_each_entry(rss, &adapter->config_data.adv_rss_list,
+				    list) {
+			rss->add = true;
+		}
+		spin_unlock_bh(&adapter->adv_rss_list_lock);
+		iecm_send_add_del_adv_rss_cfg_msg(vport, true);
+	}
+}
+
 /**
  * iecm_restore_fdir_filters - Restore all Flow Director filters
  * @vport: vport structure
@@ -1380,6 +1448,9 @@ static void iecm_restore_features(struct iecm_vport *vport)
 	if (iecm_is_feature_ena(vport, NETIF_F_HW_TC))
 		iecm_restore_cloud_filters(vport);
 
+	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADV_RSS))
+		iecm_restore_adv_rss_cfgs(vport);
+
 	if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_FDIR))
 		iecm_restore_fdir_filters(vport);
 }
@@ -2219,6 +2290,7 @@ static void iecm_del_user_cfg_data(struct iecm_adapter *adapter)
 		if (!adapter->vports[i])
 			continue;
 
+		iecm_del_all_adv_rss_cfgs(adapter->vports[i]);
 		iecm_del_all_fdir_filters(adapter->vports[i]);
 	}
 }
@@ -3633,6 +3705,481 @@ static int iecm_setup_tc(struct net_device *netdev, enum tc_setup_type type,
 	return err;
 }
 
+/**
+ * iecm_fill_adv_rss_ip4_hdr - fill the IPv4 RSS protocol header
+ * @hdr: the virtchnl message protocol header data structure
+ * @hash_flds: the RSS configuration protocol hash fields
+ */
+static void
+iecm_fill_adv_rss_ip4_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
+{
+	VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, IPV4);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_IPV4_SA)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV4, SRC);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_IPV4_DA)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV4, DST);
+}
+
+/**
+ * iecm_fill_adv_rss_ip6_hdr - fill the IPv6 RSS protocol header
+ * @hdr: the virtchnl message protocol header data structure
+ * @hash_flds: the RSS configuration protocol hash fields
+ */
+static void
+iecm_fill_adv_rss_ip6_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
+{
+	VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, IPV6);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_IPV6_SA)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV6, SRC);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_IPV6_DA)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV6, DST);
+}
+
+/**
+ * iecm_fill_adv_rss_tcp_hdr - fill the TCP RSS protocol header
+ * @hdr: the virtchnl message protocol header data structure
+ * @hash_flds: the RSS configuration protocol hash fields
+ */
+static void
+iecm_fill_adv_rss_tcp_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
+{
+	VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, TCP);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_TCP_SRC_PORT)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, TCP, SRC_PORT);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_TCP_DST_PORT)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, TCP, DST_PORT);
+}
+
+/**
+ * iecm_fill_adv_rss_udp_hdr - fill the UDP RSS protocol header
+ * @hdr: the virtchnl message protocol header data structure
+ * @hash_flds: the RSS configuration protocol hash fields
+ */
+static void
+iecm_fill_adv_rss_udp_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
+{
+	VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, UDP);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_UDP_SRC_PORT)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, UDP, SRC_PORT);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_UDP_DST_PORT)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, UDP, DST_PORT);
+}
+
+/**
+ * iecm_fill_adv_rss_sctp_hdr - fill the SCTP RSS protocol header
+ * @hdr: the virtchnl message protocol header data structure
+ * @hash_flds: the RSS configuration protocol hash fields
+ */
+static void
+iecm_fill_adv_rss_sctp_hdr(struct virtchnl_proto_hdr *hdr, s64 hash_flds)
+{
+	VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, SCTP);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_SCTP_SRC_PORT)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, SCTP, SRC_PORT);
+
+	if (hash_flds & IECM_ADV_RSS_HASH_FLD_SCTP_DST_PORT)
+		VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, SCTP, DST_PORT);
+}
+
+/**
+ * iecm_fill_adv_rss_cfg_msg - fill the RSS configuration into virtchnl message
+ * @rss_cfg: the virtchnl message to be filled with RSS configuration setting
+ * @packet_hdrs: the RSS configuration protocol header types
+ * @hash_flds: the RSS configuration protocol hash fields
+ *
+ * Returns 0 if the RSS configuration virtchnl message is filled successfully
+ */
+static int
+iecm_fill_adv_rss_cfg_msg(struct virtchnl_rss_cfg *rss_cfg,
+			  u32 packet_hdrs, u64 hash_flds)
+{
+	struct virtchnl_proto_hdrs *proto_hdrs = &rss_cfg->proto_hdrs;
+	struct virtchnl_proto_hdr *hdr;
+
+	rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
+
+	proto_hdrs->tunnel_level = 0;	/* always outer layer */
+
+	hdr = &proto_hdrs->proto_hdr[proto_hdrs->count++];
+	switch (packet_hdrs & IECM_ADV_RSS_FLOW_SEG_HDR_L3) {
+	case IECM_ADV_RSS_FLOW_SEG_HDR_IPV4:
+		iecm_fill_adv_rss_ip4_hdr(hdr, hash_flds);
+		break;
+	case IECM_ADV_RSS_FLOW_SEG_HDR_IPV6:
+		iecm_fill_adv_rss_ip6_hdr(hdr, hash_flds);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	hdr = &proto_hdrs->proto_hdr[proto_hdrs->count++];
+	switch (packet_hdrs & IECM_ADV_RSS_FLOW_SEG_HDR_L4) {
+	case IECM_ADV_RSS_FLOW_SEG_HDR_TCP:
+		iecm_fill_adv_rss_tcp_hdr(hdr, hash_flds);
+		break;
+	case IECM_ADV_RSS_FLOW_SEG_HDR_UDP:
+		iecm_fill_adv_rss_udp_hdr(hdr, hash_flds);
+		break;
+	case IECM_ADV_RSS_FLOW_SEG_HDR_SCTP:
+		iecm_fill_adv_rss_sctp_hdr(hdr, hash_flds);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_find_adv_rss_cfg_by_hdrs - find RSS configuration with header type
+ * @vport: vport structure
+ * @packet_hdrs: protocol header type to find.
+ *
+ * Returns pointer to advance RSS configuration if found or null
+ */
+static struct iecm_adv_rss *
+iecm_find_adv_rss_cfg_by_hdrs(struct iecm_vport *vport, u32 packet_hdrs)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_adv_rss *rss;
+
+	list_for_each_entry(rss, &adapter->config_data.adv_rss_list, list)
+		if (rss->packet_hdrs == packet_hdrs)
+			return rss;
+
+	return NULL;
+}
+
+/**
+ * iecm_dump_adv_rss_cfg_info
+ * @vport: vport structure
+ * @packet_hdrs: The protocol headers for RSS configuration
+ * @hash_flds: The protocol hash fields for RSS configuration
+ * @prefix: the prefix string description to dump the RSS
+ * @postfix: the postfix string description to dump the RSS
+ *
+ * Dump the advance RSS configuration
+ **/
+static void
+iecm_dump_adv_rss_cfg_info(struct iecm_vport *vport,
+			   u32 packet_hdrs, u64 hash_flds,
+			   const char *prefix, const char *postfix)
+{
+	static char hash_opt[300];
+	const char *proto;
+
+	if (packet_hdrs & IECM_ADV_RSS_FLOW_SEG_HDR_TCP)
+		proto = "TCP";
+	else if (packet_hdrs & IECM_ADV_RSS_FLOW_SEG_HDR_UDP)
+		proto = "UDP";
+	else if (packet_hdrs & IECM_ADV_RSS_FLOW_SEG_HDR_SCTP)
+		proto = "SCTP";
+	else
+		return;
+
+	memset(hash_opt, 0, sizeof(hash_opt));
+
+	strcat(hash_opt, proto);
+	if (packet_hdrs & IECM_ADV_RSS_FLOW_SEG_HDR_IPV4)
+		strcat(hash_opt, "v4 ");
+	else
+		strcat(hash_opt, "v6 ");
+
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_IPV4_SA |
+			 IECM_ADV_RSS_HASH_FLD_IPV6_SA))
+		strcat(hash_opt, "[IP SA] ");
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_IPV4_DA |
+			 IECM_ADV_RSS_HASH_FLD_IPV6_DA))
+		strcat(hash_opt, "[IP DA] ");
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_TCP_SRC_PORT |
+			 IECM_ADV_RSS_HASH_FLD_UDP_SRC_PORT |
+			 IECM_ADV_RSS_HASH_FLD_SCTP_SRC_PORT))
+		strcat(hash_opt, "[src port] ");
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_TCP_DST_PORT |
+			 IECM_ADV_RSS_HASH_FLD_UDP_DST_PORT |
+			 IECM_ADV_RSS_HASH_FLD_SCTP_DST_PORT))
+		strcat(hash_opt, "[dst port] ");
+
+	if (!prefix)
+		prefix = "";
+
+	if (!postfix)
+		postfix = "";
+
+	dev_info(&vport->adapter->pdev->dev, "%s %s %s\n",
+		 prefix, hash_opt, postfix);
+}
+
+/**
+ * iecm_adv_rss_parse_hdrs - parses headers from RSS hash input
+ * @cmd: ethtool rxnfc command
+ *
+ * This function parses the rxnfc command and returns intended
+ * header types for RSS configuration
+ */
+static u32 iecm_adv_rss_parse_hdrs(struct ethtool_rxnfc *cmd)
+{
+	u32 hdrs = IECM_ADV_RSS_FLOW_SEG_HDR_NONE;
+
+	switch (cmd->flow_type) {
+	case TCP_V4_FLOW:
+		hdrs |= IECM_ADV_RSS_FLOW_SEG_HDR_TCP |
+			IECM_ADV_RSS_FLOW_SEG_HDR_IPV4;
+		break;
+	case UDP_V4_FLOW:
+		hdrs |= IECM_ADV_RSS_FLOW_SEG_HDR_UDP |
+			IECM_ADV_RSS_FLOW_SEG_HDR_IPV4;
+		break;
+	case SCTP_V4_FLOW:
+		hdrs |= IECM_ADV_RSS_FLOW_SEG_HDR_SCTP |
+			IECM_ADV_RSS_FLOW_SEG_HDR_IPV4;
+		break;
+	case TCP_V6_FLOW:
+		hdrs |= IECM_ADV_RSS_FLOW_SEG_HDR_TCP |
+			IECM_ADV_RSS_FLOW_SEG_HDR_IPV6;
+		break;
+	case UDP_V6_FLOW:
+		hdrs |= IECM_ADV_RSS_FLOW_SEG_HDR_UDP |
+			IECM_ADV_RSS_FLOW_SEG_HDR_IPV6;
+		break;
+	case SCTP_V6_FLOW:
+		hdrs |= IECM_ADV_RSS_FLOW_SEG_HDR_SCTP |
+			IECM_ADV_RSS_FLOW_SEG_HDR_IPV6;
+		break;
+	default:
+		break;
+	}
+
+	return hdrs;
+}
+
+/**
+ * iecm_adv_rss_parse_hash_flds - parses hash fields from RSS hash input
+ * @cmd: ethtool rxnfc command
+ *
+ * This function parses the rxnfc command and returns intended hash fields for
+ * RSS configuration
+ */
+static u64 iecm_adv_rss_parse_hash_flds(struct ethtool_rxnfc *cmd)
+{
+	u64 hfld = IECM_ADV_RSS_HASH_INVALID;
+
+	if (cmd->data & RXH_IP_SRC || cmd->data & RXH_IP_DST) {
+		switch (cmd->flow_type) {
+		case TCP_V4_FLOW:
+		case UDP_V4_FLOW:
+		case SCTP_V4_FLOW:
+			if (cmd->data & RXH_IP_SRC)
+				hfld |= IECM_ADV_RSS_HASH_FLD_IPV4_SA;
+			if (cmd->data & RXH_IP_DST)
+				hfld |= IECM_ADV_RSS_HASH_FLD_IPV4_DA;
+			break;
+		case TCP_V6_FLOW:
+		case UDP_V6_FLOW:
+		case SCTP_V6_FLOW:
+			if (cmd->data & RXH_IP_SRC)
+				hfld |= IECM_ADV_RSS_HASH_FLD_IPV6_SA;
+			if (cmd->data & RXH_IP_DST)
+				hfld |= IECM_ADV_RSS_HASH_FLD_IPV6_DA;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (cmd->data & RXH_L4_B_0_1 || cmd->data & RXH_L4_B_2_3) {
+		switch (cmd->flow_type) {
+		case TCP_V4_FLOW:
+		case TCP_V6_FLOW:
+			if (cmd->data & RXH_L4_B_0_1)
+				hfld |= IECM_ADV_RSS_HASH_FLD_TCP_SRC_PORT;
+			if (cmd->data & RXH_L4_B_2_3)
+				hfld |= IECM_ADV_RSS_HASH_FLD_TCP_DST_PORT;
+			break;
+		case UDP_V4_FLOW:
+		case UDP_V6_FLOW:
+			if (cmd->data & RXH_L4_B_0_1)
+				hfld |= IECM_ADV_RSS_HASH_FLD_UDP_SRC_PORT;
+			if (cmd->data & RXH_L4_B_2_3)
+				hfld |= IECM_ADV_RSS_HASH_FLD_UDP_DST_PORT;
+			break;
+		case SCTP_V4_FLOW:
+		case SCTP_V6_FLOW:
+			if (cmd->data & RXH_L4_B_0_1)
+				hfld |= IECM_ADV_RSS_HASH_FLD_SCTP_SRC_PORT;
+			if (cmd->data & RXH_L4_B_2_3)
+				hfld |= IECM_ADV_RSS_HASH_FLD_SCTP_DST_PORT;
+			break;
+		default:
+			break;
+		}
+	}
+
+	return hfld;
+}
+
+/**
+ * iecm_set_adv_rss_hash_opt - Enable/Disable flow types for RSS hash
+ * @vport: vport structure
+ * @cmd: ethtool rxnfc command
+ *
+ * Returns Success if the flow input set is supported.
+ */
+int
+iecm_set_adv_rss_hash_opt(struct iecm_vport *vport, struct ethtool_rxnfc *cmd)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_adv_rss *rss, *rss_new;
+	u64 hash_flds;
+	u32 hdrs;
+	int err;
+
+	if (adapter->state != __IECM_UP)
+		return -EIO;
+
+	if (!iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADV_RSS))
+		return -EOPNOTSUPP;
+
+	hdrs = iecm_adv_rss_parse_hdrs(cmd);
+	if (hdrs == IECM_ADV_RSS_FLOW_SEG_HDR_NONE)
+		return -EINVAL;
+
+	hash_flds = iecm_adv_rss_parse_hash_flds(cmd);
+	if (hash_flds == IECM_ADV_RSS_HASH_INVALID)
+		return -EINVAL;
+
+	rss_new = kzalloc(sizeof(*rss_new), GFP_KERNEL);
+	if (!rss_new)
+		return -ENOMEM;
+
+	/* Since this can fail, do it now to avoid dirtying the list, we'll
+	 * copy it from rss_new if it turns out we're updating an existing
+	 * filter instead of adding a new one.
+	 */
+	if (iecm_fill_adv_rss_cfg_msg(&rss_new->cfg_msg, hdrs, hash_flds)) {
+		kfree(rss_new);
+		return -EINVAL;
+	}
+
+	iecm_dump_adv_rss_cfg_info(vport, hdrs, hash_flds,
+				   "Input set change for", "is pending");
+
+	spin_lock_bh(&adapter->adv_rss_list_lock);
+	rss = iecm_find_adv_rss_cfg_by_hdrs(vport, hdrs);
+	if (rss) {
+		if (rss->hash_flds != hash_flds) {
+			rss->remove = false;
+			memcpy(&rss->cfg_msg, &rss_new->cfg_msg,
+			       sizeof(rss_new->cfg_msg));
+			kfree(rss_new);
+		} else {
+			kfree(rss_new);
+			spin_unlock_bh(&adapter->adv_rss_list_lock);
+			return -EEXIST;
+		}
+	} else {
+		rss = rss_new;
+		rss->packet_hdrs = hdrs;
+		list_add_tail(&rss->list, &adapter->config_data.adv_rss_list);
+	}
+	rss->add = true;
+	rss->hash_flds = hash_flds;
+	spin_unlock_bh(&adapter->adv_rss_list_lock);
+
+	err = iecm_send_add_del_adv_rss_cfg_msg(vport, true);
+	if (err) {
+		spin_lock_bh(&adapter->adv_rss_list_lock);
+		/* We have to find it again to make sure another thread hasn't
+		 * already deleted and kfreed it.
+		 */
+		rss = iecm_find_adv_rss_cfg_by_hdrs(vport, hdrs);
+		if (rss) {
+			list_del(&rss->list);
+			kfree(rss);
+		}
+		spin_unlock_bh(&adapter->adv_rss_list_lock);
+	}
+
+	if (!err)
+		iecm_dump_adv_rss_cfg_info(vport, hdrs, hash_flds,
+					   "Input set change for",
+					   "successful");
+	else
+		iecm_dump_adv_rss_cfg_info(vport, hdrs, hash_flds,
+					   "Failed to change the input set for",
+					   NULL);
+
+	return err;
+}
+
+/**
+ * iecm_get_adv_rss_hash_opt - Retrieve hash fields for a given flow-type
+ * @vport: vport structure
+ * @cmd: ethtool rxnfc command
+ *
+ * Returns Success if the flow input set is supported.
+ */
+int
+iecm_get_adv_rss_hash_opt(struct iecm_vport *vport, struct ethtool_rxnfc *cmd)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct iecm_adv_rss *rss;
+	u64 hash_flds;
+	u32 hdrs;
+
+	if (adapter->state != __IECM_UP)
+		return -EIO;
+
+	if (!iecm_is_cap_ena(adapter, IECM_OTHER_CAPS, VIRTCHNL2_CAP_ADV_RSS))
+		return -EOPNOTSUPP;
+
+	cmd->data = 0;
+
+	hdrs = iecm_adv_rss_parse_hdrs(cmd);
+	if (hdrs == IECM_ADV_RSS_FLOW_SEG_HDR_NONE)
+		return -EINVAL;
+
+	spin_lock_bh(&adapter->adv_rss_list_lock);
+	rss = iecm_find_adv_rss_cfg_by_hdrs(vport, hdrs);
+	if (rss)
+		hash_flds = rss->hash_flds;
+	else
+		hash_flds = IECM_ADV_RSS_HASH_INVALID;
+	spin_unlock_bh(&adapter->adv_rss_list_lock);
+
+	if (hash_flds == IECM_ADV_RSS_HASH_INVALID)
+		return -EINVAL;
+
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_IPV4_SA |
+			 IECM_ADV_RSS_HASH_FLD_IPV6_SA))
+		cmd->data |= (u64)RXH_IP_SRC;
+
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_IPV4_DA |
+			 IECM_ADV_RSS_HASH_FLD_IPV6_DA))
+		cmd->data |= (u64)RXH_IP_DST;
+
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_TCP_SRC_PORT |
+			 IECM_ADV_RSS_HASH_FLD_UDP_SRC_PORT |
+			 IECM_ADV_RSS_HASH_FLD_SCTP_SRC_PORT))
+		cmd->data |= (u64)RXH_L4_B_0_1;
+
+	if (hash_flds & (IECM_ADV_RSS_HASH_FLD_TCP_DST_PORT |
+			 IECM_ADV_RSS_HASH_FLD_UDP_DST_PORT |
+			 IECM_ADV_RSS_HASH_FLD_SCTP_DST_PORT))
+		cmd->data |= (u64)RXH_L4_B_2_3;
+
+	return 0;
+}
+
 /**
  * iecm_pkt_udp_no_pay_len - the length of UDP packet without payload
  * @fltr: Flow Director filter data structure
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +71 -0

77 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm.h +73 -0

85 lines not on this page · raw message

Signature · 1 line
2.33.0
author
#78 lore raw

PATCH 19/19 idpf: introduce idpf driver

In reply to Alan Brady

This adds the idpf driver which uses the iecm module to provide common functionality. Device specific behavior and registers are defined here and handed off to iecm which takes over the rest of the flow.

---
 .../device_drivers/ethernet/intel/idpf.rst    |  47 ++++++
 drivers/net/ethernet/intel/Kconfig            |  16 ++
 drivers/net/ethernet/intel/Makefile           |   1 +
 drivers/net/ethernet/intel/idpf/Makefile      |  15 ++
 drivers/net/ethernet/intel/idpf/idpf_dev.h    |  17 +++
 drivers/net/ethernet/intel/idpf/idpf_devids.h |  10 ++
 drivers/net/ethernet/intel/idpf/idpf_main.c   | 140 ++++++++++++++++++
 drivers/net/ethernet/intel/idpf/idpf_reg.c    | 130 ++++++++++++++++
 .../ethernet/intel/include/iecm_lan_pf_regs.h | 131 ++++++++++++++++
 9 files changed, 507 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/intel/idpf.rst
 create mode 100644 drivers/net/ethernet/intel/idpf/Makefile
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_dev.h
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_devids.h
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_main.c
 create mode 100644 drivers/net/ethernet/intel/idpf/idpf_reg.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm_lan_pf_regs.h
Documentation/networking/device_drivers/ethernet/intel/idpf.rst new file +47 -0
new file mode 100644
index 000000000000..973fa9613428
@@ -0,0 +1,47 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==================================================================
+Linux Base Driver for the Intel(R) Smart Network Adapter Family Series
+==================================================================
+
+Intel idpf Linux driver.
+Copyright(c) 2020 Intel Corporation.
+
+Contents
+========
+
+- Enabling the driver
+- Support
+
+The driver in this release supports Intel's Smart Network Adapter Family Series
+of products. For more information, visit Intel's support page at
+https://support.intel.com.
+
+Enabling the driver
+===================
+The driver is enabled via the standard kernel configuration system,
+using the make command::
+
+  make oldconfig/menuconfig/etc.
+
+The driver is located in the menu structure at:
+
+  -> Device Drivers
+    -> Network device support (NETDEVICES [=y])
+      -> Ethernet driver support
+        -> Intel devices
+          -> Intel(R) Smart Network Adapter Family Series Support
+
+Support
+=======
+For general information, go to the Intel support website at:
+
+https://www.intel.com/support/
+
+or the Intel Wired Networking project hosted by Sourceforge at:
+
+https://sourceforge.net/projects/e1000
+
+If an issue is identified with the released source code on a supported kernel
+with a supported adapter, email the specific information related to the issue
+to e1000-devel at lists.sf.net.
drivers/net/ethernet/intel/Kconfig +16 -0
index 754dc7677ad5..93c8883c22ad 100644
@@ -387,4 +387,20 @@ config IECM
       To compile this as a module, choose M here. The module will be called
       iecm.
 
+config IDPF
+	tristate "Intel(R) Data Plane Function Support"
+	default n
+	depends on IECM
+	help
+	  For more information on how to identify your adapter, go
+	  to the Adapter & Driver ID Guide that can be located at:
+
+	  <http://support.intel.com>
+
+	  More specific information on configuring the driver is in
+	  <file:Documentation/networking/device_drivers/ethernet/intel/idpf.rst>.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called idpf.
+
 endif # NET_VENDOR_INTEL
drivers/net/ethernet/intel/Makefile +1 -0
index c9eba9cc5087..3786c2269f3d 100644
@@ -17,3 +17,4 @@ obj-$(CONFIG_IAVF) += iavf/
 obj-$(CONFIG_FM10K) += fm10k/
 obj-$(CONFIG_ICE) += ice/
 obj-$(CONFIG_IECM) += iecm/
+obj-$(CONFIG_IDPF) += idpf/
drivers/net/ethernet/intel/idpf/Makefile new file +15 -0
new file mode 100644
index 000000000000..85846620bc9f
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2019 Intel Corporation
+
+#
+# Makefile for the Intel(R) Data Plane Function Linux Driver
+#
+
+obj-$(CONFIG_IDPF) += idpf.o
+
+ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include \
+			 -I$(srctree)/include/linux/avf
+
+idpf-y := \
+	idpf_main.o \
+	idpf_reg.o
drivers/net/ethernet/intel/idpf/idpf_dev.h new file +17 -0
new file mode 100644
index 000000000000..dc146161f884
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2019 Intel Corporation */
+
+#ifndef _IDPF_DEV_H_
+#define _IDPF_DEV_H_
+
+#include "iecm.h"
+
+int idpf_intr_reg_init(struct iecm_vport *vport);
+void idpf_mb_intr_reg_init(struct iecm_adapter *adapter);
+void idpf_reset_reg_init(struct iecm_reset_reg *reset_reg);
+void idpf_trigger_reset(struct iecm_adapter *adapter,
+			enum iecm_flags trig_cause);
+void idpf_vportq_reg_init(struct iecm_vport *vport);
+void idpf_ctlq_reg_init(struct iecm_ctlq_create_info *cq);
+
+#endif /* _IDPF_DEV_H_ */
drivers/net/ethernet/intel/idpf/idpf_devids.h new file +10 -0
new file mode 100644
index 000000000000..7bf8eb64b76a
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2019 Intel Corporation */
+
+#ifndef _IDPF_DEVIDS_H_
+#define _IDPF_DEVIDS_H_
+
+/* Device IDs */
+#define IDPF_DEV_ID_PF			0x1452
+
+#endif /* _IDPF_DEVIDS_H_ */
drivers/net/ethernet/intel/idpf/idpf_main.c new file +140 -0

140 lines not on this page · raw message

drivers/net/ethernet/intel/idpf/idpf_reg.c new file +130 -0

130 lines not on this page · raw message

drivers/net/ethernet/intel/include/iecm_lan_pf_regs.h new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.33.0
#20 lore raw

[Intel-wired-lan] [PATCH net-next 05/19] iecm: add vport alloc and virtchnl messages

In reply to Alan Brady
Thank you for the patch! Perhaps something to improve:

Hi Alan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-idpf/20220128-085513
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220128/202201281200.CI9u45bS-lkp at intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/1233d9631b312eea5aebbce63590e27f9993bacc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513 git checkout 1233d9631b312eea5aebbce63590e27f9993bacc
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/net/ethernet/intel/iecm/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c: In function 'iecm_vport_queue_ids_init':

>> drivers/net/ethernet/intel/iecm/iecm_virtchnl.c:1396:1: warning: the frame size of 1052 bytes is larger than 1024 bytes [-Wframe-larger-than=]
    1396 | }
         | ^

vim +1396 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c

1322
1323 /**
1324 * iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters
1325 * @vport: virtual port for which the queues ids are initialized
1326 *
1327 * Will initialize all queue ids with ids received as mailbox parameters.
1328 * Returns 0 on success, negative if all the queues are not initialized.
1329 */
1330 static int iecm_vport_queue_ids_init(struct iecm_vport *vport)
1331 {
1332 struct virtchnl2_create_vport *vport_params;
1333 struct virtchnl2_queue_reg_chunks *chunks;
1334 /* We may never deal with more than 256 same type of queues */
1335 #define IECM_MAX_QIDS 256
1336 u32 qids[IECM_MAX_QIDS];
1337 int num_ids;
1338 u16 q_type;
1339
1340 if (vport->adapter->config_data.req_qs_chunks) {
1341 struct virtchnl2_add_queues *vc_aq =
1342 (struct virtchnl2_add_queues *)
1343 vport->adapter->config_data.req_qs_chunks;
1344 chunks = &vc_aq->chunks;
1345 } else {
1346 vport_params = (struct virtchnl2_create_vport *)
1347 vport->adapter->vport_params_recvd[0];
1348 chunks = &vport_params->chunks;
1349 }
1350
1351 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
1352 VIRTCHNL2_QUEUE_TYPE_TX,
1353 chunks);
1354 if (num_ids != vport->num_txq)
1355 return -EINVAL;
1356 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1357 VIRTCHNL2_QUEUE_TYPE_TX);
1358 if (num_ids != vport->num_txq)
1359 return -EINVAL;
1360 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
1361 VIRTCHNL2_QUEUE_TYPE_RX,
1362 chunks);
1363 if (num_ids != vport->num_rxq)
1364 return -EINVAL;
1365 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1366 VIRTCHNL2_QUEUE_TYPE_RX);
1367 if (num_ids != vport->num_rxq)
1368 return -EINVAL;
1369
1370 if (iecm_is_queue_model_split(vport->txq_model)) {
1371 q_type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
1372 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
1373 chunks);
1374 if (num_ids != vport->num_complq)
1375 return -EINVAL;
1376 num_ids = __iecm_vport_queue_ids_init(vport, qids,
1377 num_ids,
1378 q_type);
1379 if (num_ids != vport->num_complq)
1380 return -EINVAL;
1381 }
1382
1383 if (iecm_is_queue_model_split(vport->rxq_model)) {
1384 q_type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
1385 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
1386 chunks);
1387 if (num_ids != vport->num_bufq)
1388 return -EINVAL;
1389 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1390 q_type);
1391 if (num_ids != vport->num_bufq)
1392 return -EINVAL;
1393 }
1394
1395 return 0;

> 1396	}

1397

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org

#52 lore raw

[Intel-wired-lan] [PATCH net-next 13/19] iecm: implement splitq napi_poll

In reply to Alan Brady
Thank you for the patch! Yet something to improve:

Hi Alan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-idpf/20220128-085513
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220128/202201281316.ZdiaZw6q-lkp at intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/8e9b2451747f81363327cf5a4e07aaf88af52397
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513
git checkout 8e9b2451747f81363327cf5a4e07aaf88af52397
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/net/ethernet/intel/iecm/iecm_txrx.c: In function 'iecm_rx_can_reuse_page':

>> drivers/net/ethernet/intel/iecm/iecm_txrx.c:3132:19: error: 'struct iecm_rx_buf' has no member named 'page_offset'
    3132 |         if (rx_buf->page_offset > last_offset)
         |                   ^~

vim +3132 drivers/net/ethernet/intel/iecm/iecm_txrx.c

3103
3104 /**
3105 * iecm_rx_can_reuse_page - Determine if page can be reused for another rx
3106 * @rx_buf: buffer containing the page
3107 *
3108 * If page is reusable, we have a green light for calling iecm_reuse_rx_page,
3109 * which will assign the current buffer to the buffer that next_to_alloc is
3110 * pointing to; otherwise, the dma mapping needs to be destroyed and
3111 * page freed
3112 */
3113 bool iecm_rx_can_reuse_page(struct iecm_rx_buf *rx_buf)
3114 {
3115 struct iecm_page_info *page_info = &rx_buf->page_info[rx_buf->page_indx];
3116
3117 #if (PAGE_SIZE >= 8192)
3118 unsigned int last_offset = PAGE_SIZE - rx_buf->buf_size;
3119 #endif /* PAGE_SIZE < 8192) */
3120 unsigned int pagecnt_bias = page_info->pagecnt_bias;
3121 struct page *page = page_info->page;
3122
3123 /* avoid re-using remote pages */
3124 if (unlikely(iecm_rx_page_is_reserved(page)))
3125 return false;
3126
3127 #if (PAGE_SIZE < 8192)
3128 /* if we are only owner of page we can reuse it */
3129 if (unlikely((page_count(page) - pagecnt_bias) > 1))
3130 return false;
3131 #else

> 3132		if (rx_buf->page_offset > last_offset)

3133 return false;
3134 #endif /* PAGE_SIZE < 8192) */
3135
3136 /* If we have drained the page fragment pool we need to update
3137 * the pagecnt_bias and page count so that we fully restock the
3138 * number of references the driver holds.
3139 */
3140 if (unlikely(pagecnt_bias == 1)) {
3141 page_ref_add(page, USHRT_MAX - 1);
3142 page_info->pagecnt_bias = USHRT_MAX;
3143 }
3144
3145 return true;
3146 }
3147

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org

#4 lore raw

PATCH 2/19 iecm: add basic module init and documentation

In reply to Alan Brady

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:52 -0800

Quoted 125 lines

This adds the basics needed to make a kernel module and documentation needed to use iecm module.

---
 .../device_drivers/ethernet/intel/iecm.rst    | 93 +++++++++++++++++++
 drivers/net/ethernet/intel/Kconfig            | 15 +++
 drivers/net/ethernet/intel/Makefile           |  1 +
 drivers/net/ethernet/intel/iecm/Makefile      | 13 +++
 drivers/net/ethernet/intel/iecm/iecm_main.c   | 40 ++++++++
 drivers/net/ethernet/intel/include/iecm.h     | 10 ++
 6 files changed, 172 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/intel/iecm.rst
 create mode 100644 drivers/net/ethernet/intel/iecm/Makefile
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_main.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm.h
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +93 -0
new file mode 100644
index 000000000000..5634e3e65c74
@@ -0,0 +1,93 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+========================
+Intel Ethernet Common Module
+========================
+
+The Intel Ethernet Common Module is meant to serve as an abstraction layer
+between device specific implementation details and common net device driver
+flows. This library provides several function hooks which allow a device driver
+to specify register addresses, control queue communications, and other device
+specific functionality.  Some functions are required to be implemented while
+others have a default implementation that is used when none is supplied by the
+device driver.  Doing this, a device driver can be written to take advantage
+of existing code while also giving the flexibility to implement device specific
+features.
+
+The common use case for this library is for a network device driver that wants
+specify its own device specific details but also leverage the more common
+code flows found in network device drivers.
+
+Sections in this document:
+	Entry Point
+	Exit Point
+	Register Operations API
+	Virtchnl Operations API
+
+Entry Point
+~~~~~~~~~~~
+The primary entry point to the library is the iecm_probe function.  Prior to
+calling this, device drivers must have allocated an iecm_adapter struct and
+initialized it with the required API functions.  The adapter struct, along with
+the pci_dev struct and the pci_device_id struct, is provided to iecm_probe
+which finalizes device initialization and prepares the device for open.
+
+The iecm_dev_ops struct within the iecm_adapter struct is the primary vehicle
+for passing information from device drivers to the common module.  A dependent
+module must define and assign a reg_ops_init function which will assign the
+respective function pointers to initialize register values (see iecm_reg_ops
+struct).  These are required to be provided by the dependent device driver as
+no suitable default can be assumed for register addresses.
+
+The vc_ops_init function pointer and the related iecm_virtchnl_ops struct are
+optional and should only be necessary for device drivers which use a different
+method/timing for communicating across a mailbox to the hardware.  Within iecm
+is a default interface provided in the case where one is not provided by the
+device driver.
+
+Exit Point
+~~~~~~~~~~
+When the device driver is being prepared to be removed through the pci_driver
+remove callback, it is required for the device driver to call iecm_remove with
+the pci_dev struct provided.  This is required to ensure all resources are
+properly freed and returned to the operating system.
+
+Register Operations API
+~~~~~~~~~~~~~~~~~~~~~~~
+iecm_reg_ops contains three different function pointers relating to initializing
+registers for the specific net device using the library.
+
+ctlq_reg_init relates specifically to setting up registers related to control
+queue/mailbox communications.  Registers that should be defined include: head,
+tail, len, bah, bal, len_mask, len_ena_mask, and head_mask.
+
+vportq_reg_init relates to setting up queue registers.  The tail registers to
+be assigned to the iecm_queue struct for each RX/TX queue.
+
+intr_reg_init relates to any registers needed to setup interrupts.  These
+include registers needed to enable the interrupt and change ITR settings.
+
+If the initialization function finds that one or more required function
+pointers were not provided, an error will be issued and the device will be
+inoperable.
+
+
+Virtchnl Operations API
+~~~~~~~~~~~~~~~~~~~~~~~
+The virtchnl is a conduit between driver and hardware that allows device
+drivers to send and receive control messages to/from hardware.  This is
+optional to be specified as there is a general interface that can be assumed
+when using this library.  However, if a device deviates in some way to
+communicate across the mailbox correctly, this interface is provided to allow
+that.
+
+If vc_ops_init is set in the dev_ops field of the iecm_adapter struct, then it
+is assumed the device driver is using providing it's own interface to do
+virtchnl communications.  While providing vc_ops_init is optional, if it is
+provided, it is required that the device driver provide function pointers for
+those functions in vc_ops, with exception for the enable_vport, disable_vport,
+and destroy_vport functions which may not be required for all devices.
+
+If the initialization function finds that vc_ops_init was defined but one or
+more required function pointers were not provided, an error will be issued and
+the device will be inoperable.
drivers/net/ethernet/intel/Kconfig +0 -0
index 3facb55b7161..754dc7677ad5 100644

drivers/net/ethernet/intel/Kconfig config IGC · line 381

Quoted 10 lines
drivers/net/ethernet/intel/Kconfig +7 -0
@@ -372,4 +372,19 @@ config IGC
 	  To compile this driver as a module, choose M here. The module
 	  will be called igc.
 
+config IECM
+	tristate "Intel(R) Ethernet Common Module Support"
+	default n
+	depends on PCI_MSI
+	select DIMLIB
+	help
+      This supplies needed functions to device specific device drivers

One Tab + two spaces instead of 6 spaces. And one Tab is 8 cols in the kernel.

Quoted 24 lines
drivers/net/ethernet/intel/Kconfig +8 -0
+      implementing common module.
+
+	  More specific information on configuring the driver is in
+	  <file:Documentation/networking/device_drivers/ethernet/intel/iecm.rst>.
+
+      To compile this as a module, choose M here. The module will be called
+      iecm.
+
 endif # NET_VENDOR_INTEL
drivers/net/ethernet/intel/Makefile +1 -0
index 3075290063f6..c9eba9cc5087 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_IXGB) += ixgb/
 obj-$(CONFIG_IAVF) += iavf/
 obj-$(CONFIG_FM10K) += fm10k/
 obj-$(CONFIG_ICE) += ice/
+obj-$(CONFIG_IECM) += iecm/
drivers/net/ethernet/intel/iecm/Makefile new file +0 -0
new file mode 100644
index 000000000000..d2d087ac71e9

drivers/net/ethernet/intel/iecm/Makefile line 10

Quoted 10 lines
drivers/net/ethernet/intel/iecm/Makefile new file +10 -0
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2019 Intel Corporation
+
+#
+# Makefile for the Intel(R) Data Plane Function Linux Driver
+#
+
+obj-$(CONFIG_IECM) += iecm.o
+
+ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include

Common includes are usually being added to include/linux/. Files outside include directories are usually considered "private", i.e. used only inside a particular folder.

Quoted 9 lines
drivers/net/ethernet/intel/iecm/Makefile new file +3 -0
+
+iecm-y := \
+	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_main.c new file +0 -0
new file mode 100644
index 000000000000..7c09403c6918

drivers/net/ethernet/intel/iecm/iecm_main.c line 6

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +6 -0
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2019 Intel Corporation */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include "iecm.h"

Quotes are used for local includes. For includes from the search directories please use <>.

drivers/net/ethernet/intel/iecm/iecm_main.c line 13

Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +7 -0
+
+#define DRV_SUMMARY	"Intel(R) Ethernet Common Module"
+static const char iecm_driver_string[] = DRV_SUMMARY;
+static const char iecm_copyright[] = "Copyright (c) 2020, Intel Corporation.";
+
+MODULE_DESCRIPTION(DRV_SUMMARY);
+MODULE_LICENSE("GPL v2");

"GPL v2" is a deprecated identifier and is not recommended for new modules. Just "GPL" is enough and means exactly the same.

Quoted 45 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +27 -0
+
+/**
+ * iecm_module_init - Driver registration routine
+ *
+ * iecm_module_init is the first routine called when the driver is
+ * loaded. All it does is register with the PCI subsystem.
+ */
+static int __init iecm_module_init(void)
+{
+	pr_info("%s - version %d\n", iecm_driver_string, LINUX_VERSION_CODE);
+	pr_info("%s\n", iecm_copyright);
+
+	return 0;
+}
+module_init(iecm_module_init);
+
+/**
+ * iecm_module_exit - Driver exit cleanup routine
+ *
+ * iecm_module_exit is called just before the driver is removed
+ * from memory.
+ */
+static void __exit iecm_module_exit(void)
+{
+	pr_info("module unloaded\n");
+}
+module_exit(iecm_module_exit);
drivers/net/ethernet/intel/include/iecm.h new file +10 -0
new file mode 100644
index 000000000000..f66f0d7db8e7
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2019 Intel Corporation */
+
+#ifndef _IECM_H_
+#define _IECM_H_
+
+#include <linux/etherdevice.h>
+#include <linux/version.h>
+
+#endif /* !_IECM_H_ */
Signature · 1 line
2.33.0

Thanks,
Al

#12 lore raw

PATCH 4/19 iecm: add api_init and controlq init

In reply to Alan Brady

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:54 -0800

Quoted 22 lines

Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.

At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.

---
 drivers/net/ethernet/intel/iecm/Makefile      |   3 +
 .../net/ethernet/intel/iecm/iecm_controlq.c   | 649 ++++++++++++++++++
 .../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++
 drivers/net/ethernet/intel/iecm/iecm_lib.c    | 191 +++++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 172 +++++
 drivers/net/ethernet/intel/include/iecm.h     |  52 ++
 .../ethernet/intel/include/iecm_controlq.h    | 117 ++++
 .../intel/include/iecm_controlq_api.h         | 185 +++++
Quoted 9 lines
 drivers/net/ethernet/intel/include/iecm_mem.h |  20 +
 9 files changed, 1563 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
 create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h
 create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h

--- 8< ---

Quoted 50 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +44 -0
new file mode 100644
index 000000000000..5f624f005d33
@@ -0,0 +1,185 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (c) 2020, Intel Corporation. */
+
+#ifndef _IECM_CONTROLQ_API_H_
+#define _IECM_CONTROLQ_API_H_
+
+#include "iecm_mem.h"
+
+struct iecm_hw;
+
+/* Used for queue init, response and events */
+enum iecm_ctlq_type {
+	IECM_CTLQ_TYPE_MAILBOX_TX	= 0,
+	IECM_CTLQ_TYPE_MAILBOX_RX	= 1,
+	IECM_CTLQ_TYPE_CONFIG_TX	= 2,
+	IECM_CTLQ_TYPE_CONFIG_RX	= 3,
+	IECM_CTLQ_TYPE_EVENT_RX		= 4,
+	IECM_CTLQ_TYPE_RDMA_TX		= 5,
+	IECM_CTLQ_TYPE_RDMA_RX		= 6,
+	IECM_CTLQ_TYPE_RDMA_COMPL	= 7
+};
+
+/* Generic Control Queue Structures */
+struct iecm_ctlq_reg {
+	/* used for queue tracking */
+	u32 head;
+	u32 tail;
+	/* Below applies only to default mb (if present) */
+	u32 len;
+	u32 bah;
+	u32 bal;
+	u32 len_mask;
+	u32 len_ena_mask;
+	u32 head_mask;
+};
+
+/* Generic queue msg structure */
+struct iecm_ctlq_msg {
+	u16 vmvf_type; /* represents the source of the message on recv */
+#define IECM_VMVF_TYPE_VF 0
+#define IECM_VMVF_TYPE_VM 1
+#define IECM_VMVF_TYPE_PF 2
+	u16 opcode;
+	u16 data_len;	/* data_len = 0 when no payload is attached */

drivers/net/ethernet/intel/include/iecm_controlq_api.h line 54

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +10 -0
+	union {
+		u16 func_id;	/* when sending a message */
+		u16 status;	/* when receiving a message */
+	};
+	union {
+		struct {
+			u32 chnl_retval;
+			u32 chnl_opcode;
+		} mbx;
+	} cookie;

One field union? If it will be expanded later, please unionize it only then.

Quoted 121 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +121 -0
+	union {
+#define IECM_DIRECT_CTX_SIZE	16
+#define IECM_INDIRECT_CTX_SIZE	8
+		/* 16 bytes of context can be provided or 8 bytes of context
+		 * plus the address of a DMA buffer
+		 */
+		u8 direct[IECM_DIRECT_CTX_SIZE];
+		struct {
+			u8 context[IECM_INDIRECT_CTX_SIZE];
+			struct iecm_dma_mem *payload;
+		} indirect;
+	} ctx;
+};
+
+/* Generic queue info structures */
+/* MB, CONFIG and EVENT q do not have extended info */
+struct iecm_ctlq_create_info {
+	enum iecm_ctlq_type type;
+	int id; /* absolute queue offset passed as input
+		 * -1 for default mailbox if present
+		 */
+	u16 len; /* Queue length passed as input */
+	u16 buf_size; /* buffer size passed as input */
+	u64 base_address; /* output, HPA of the Queue start  */
+	struct iecm_ctlq_reg reg; /* registers accessed by ctlqs */
+
+	int ext_info_size;
+	void *ext_info; /* Specific to q type */
+};
+
+/* Control Queue information */
+struct iecm_ctlq_info {
+	struct list_head cq_list;
+
+	enum iecm_ctlq_type cq_type;
+	int q_id;
+	/* control queue lock */
+	struct mutex cq_lock;
+
+	/* used for interrupt processing */
+	u16 next_to_use;
+	u16 next_to_clean;
+	u16 next_to_post;		/* starting descriptor to post buffers
+					 * to after recev
+					 */
+
+	struct iecm_dma_mem desc_ring;	/* descriptor ring memory
+					 * iecm_dma_mem is defined in OSdep.h
+					 */
+	union {
+		struct iecm_dma_mem **rx_buff;
+		struct iecm_ctlq_msg **tx_msg;
+	} bi;
+
+	u16 buf_size;			/* queue buffer size */
+	u16 ring_size;			/* Number of descriptors */
+	struct iecm_ctlq_reg reg;	/* registers accessed by ctlqs */
+};
+
+/* PF/VF mailbox commands */
+enum iecm_mbx_opc {
+	/* iecm_mbq_opc_send_msg_to_pf:
+	 *	usage: used by PF or VF to send a message to its CPF
+	 *	target: RX queue and function ID of parent PF taken from HW
+	 */
+	iecm_mbq_opc_send_msg_to_pf		= 0x0801,
+
+	/* iecm_mbq_opc_send_msg_to_vf:
+	 *	usage: used by PF to send message to a VF
+	 *	target: VF control queue ID must be specified in descriptor
+	 */
+	iecm_mbq_opc_send_msg_to_vf		= 0x0802,
+
+	/* iecm_mbq_opc_send_msg_to_peer_pf:
+	 *	usage: used by any function to send message to any peer PF
+	 *	target: RX queue and host of parent PF taken from HW
+	 */
+	iecm_mbq_opc_send_msg_to_peer_pf	= 0x0803,
+
+	/* iecm_mbq_opc_send_msg_to_peer_drv:
+	 *	usage: used by any function to send message to any peer driver
+	 *	target: RX queue and target host must be specific in descriptor
+	 */
+	iecm_mbq_opc_send_msg_to_peer_drv	= 0x0804,
+};
+
+/* API support for control queue management */
+
+/* Will init all required q including default mb.  "q_info" is an array of
+ * create_info structs equal to the number of control queues to be created.
+ */
+int iecm_ctlq_init(struct iecm_hw *hw, u8 num_q,
+		   struct iecm_ctlq_create_info *q_info);
+
+/* Allocate and initialize a single control queue, which will be added to the
+ * control queue list; returns a handle to the created control queue
+ */
+int iecm_ctlq_add(struct iecm_hw *hw,
+		  struct iecm_ctlq_create_info *qinfo,
+		  struct iecm_ctlq_info **cq);
+
+/* Deinitialize and deallocate a single control queue */
+void iecm_ctlq_remove(struct iecm_hw *hw,
+		      struct iecm_ctlq_info *cq);
+
+/* Sends messages to HW and will also free the buffer*/
+int iecm_ctlq_send(struct iecm_hw *hw,
+		   struct iecm_ctlq_info *cq,
+		   u16 num_q_msg,
+		   struct iecm_ctlq_msg q_msg[]);
+
+/* Receives messages and called by interrupt handler/polling
+ * initiated by app/process. Also caller is supposed to free the buffers
+ */
+int iecm_ctlq_recv(struct iecm_ctlq_info *cq, u16 *num_q_msg,
+		   struct iecm_ctlq_msg *q_msg);
+
+/* Reclaims send descriptors on HW write back */
+int iecm_ctlq_clean_sq(struct iecm_ctlq_info *cq, u16 *clean_count,
+		       struct iecm_ctlq_msg *msg_status[]);
+

drivers/net/ethernet/intel/include/iecm_controlq_api.h line 185

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +10 -0
+/* Indicate RX buffers are done being processed */
+int iecm_ctlq_post_rx_buffs(struct iecm_hw *hw,
+			    struct iecm_ctlq_info *cq,
+			    u16 *buff_count,
+			    struct iecm_dma_mem **buffs);
+
+/* Will destroy all q including the default mb */
+int iecm_ctlq_deinit(struct iecm_hw *hw);
+
+#endif /* _IECM_CONTROLQ_API_H_ */

--- 8< ---

Quoted 2 lines
Signature · 1 line
2.33.0

Thanks,
Al

#23 lore raw

PATCH 5/19 iecm: add vport alloc and virtchnl messages

In reply to Alan Brady

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:55 -0800

Quoted 68 lines

After handling hard reset, we end up in init task. This starts by allocating and setting up a vport. To do that we need implement virtchnl messages.

The virtchnl messages are also offloaded into function pointers so that a device driver may override them. Here a default implementation is provided for devices using virtchnl 2.0 but there exists the flexibility add virtchnl 1.1 support through function pointers.

---
 drivers/net/ethernet/intel/iecm/Makefile      |    4 +-
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |  167 ++-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |   22 +
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1299 +++++++++++++++++
 drivers/net/ethernet/intel/include/iecm.h     |  316 +++-
 .../net/ethernet/intel/include/iecm_txrx.h    |   94 ++
 6 files changed, 1898 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.c
drivers/net/ethernet/intel/iecm/Makefile +3 -1
index db8fecb075a6..fcb49402334f 100644
@@ -7,11 +7,13 @@
 
 obj-$(CONFIG_IECM) += iecm.o
 
-ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
+ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include \
+	     -I$(srctree)/include/linux/avf
 
 iecm-y := \
 	iecm_lib.o \
 	iecm_virtchnl.o \
+	iecm_txrx.o \
 	iecm_controlq.o \
 	iecm_controlq_setup.o \
 	iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
index 64cdbce2c842..e2e523f0700e 100644
@@ -5,6 +5,11 @@
 
 #include "iecm.h"
 
+const char * const iecm_vport_vc_state_str[] = {
+	IECM_FOREACH_VPORT_VC_STATE(IECM_GEN_STRING)
+};
+EXPORT_SYMBOL(iecm_vport_vc_state_str);
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -24,6 +29,113 @@ static int iecm_cfg_hw(struct iecm_adapter *adapter)
 	return 0;
 }
 
+/**
+ * iecm_get_free_slot - get the next non-NULL location index in array
+ * @array: array to search
+ * @size: size of the array
+ * @curr: last known occupied index to be used as a search hint

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 46

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+ *
+ * void * is being used to keep the functionality generic. This lets us use this
+ * function on any array of pointers.
+ */
+static int iecm_get_free_slot(void *array, int size, int curr)
+{
+	int **tmp_array = (int **)array;
+	int next;
+
+	if (curr < (size - 1) && !tmp_array[curr + 1]) {

Redundant braces around size - 1.

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 57

Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11 -0
+		next = curr + 1;
+	} else {
+		int i = 0;
+
+		while ((i < size) && (tmp_array[i]))
+			i++;
+		if (i == size)
+			next = IECM_NO_FREE_SLOT;
+		else
+			next = i;
+	}

One indent level is redundant here. First condition is an oneliner:

	if (curr < (size - 1) && !tmp_array[curr + 1]) {
		return curr + 1;

	while ((i < size) && (tmp_array[i])) {
		...
Quoted 123 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +108 -1
+	return next;
+}
+
+/**
+ * iecm_vport_rel - Delete a vport and free its resources
+ * @vport: the vport being removed
+ */
+static void iecm_vport_rel(struct iecm_vport *vport)
+{
+	mutex_destroy(&vport->stop_mutex);
+	kfree(vport);
+}
+
+/**
+ * iecm_vport_rel_all - Delete all vports
+ * @adapter: adapter from which all vports are being removed
+ */
+static void iecm_vport_rel_all(struct iecm_adapter *adapter)
+{
+	int i;
+
+	if (!adapter->vports)
+		return;
+
+	for (i = 0; i < adapter->num_alloc_vport; i++) {
+		if (!adapter->vports[i])
+			continue;
+
+		iecm_vport_rel(adapter->vports[i]);
+		adapter->vports[i] = NULL;
+		adapter->next_vport = 0;
+	}
+	adapter->num_alloc_vport = 0;
+}
+
+/**
+ * iecm_vport_alloc - Allocates the next available struct vport in the adapter
+ * @adapter: board private structure
+ * @vport_id: vport identifier
+ *
+ * returns a pointer to a vport on success, NULL on failure.
+ */
+static struct iecm_vport *
+iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
+{
+	struct iecm_vport *vport = NULL;
+
+	if (adapter->next_vport == IECM_NO_FREE_SLOT)
+		return vport;
+
+	/* Need to protect the allocation of the vports at the adapter level */
+	mutex_lock(&adapter->sw_mutex);
+
+	vport = kzalloc(sizeof(*vport), GFP_KERNEL);
+	if (!vport)
+		goto unlock_adapter;
+
+	vport->adapter = adapter;
+	vport->idx = adapter->next_vport;
+	vport->compln_clean_budget = IECM_TX_COMPLQ_CLEAN_BUDGET;
+	adapter->num_alloc_vport++;
+
+	/* Setup default MSIX irq handler for the vport */
+	vport->irq_q_handler = iecm_vport_intr_clean_queues;
+	vport->q_vector_base = IECM_NONQ_VEC;
+
+	mutex_init(&vport->stop_mutex);
+
+	/* fill vport slot in the adapter struct */
+	adapter->vports[adapter->next_vport] = vport;
+
+	/* prepare adapter->next_vport for next use */
+	adapter->next_vport = iecm_get_free_slot(adapter->vports,
+						 adapter->num_alloc_vport,
+						 adapter->next_vport);
+
+unlock_adapter:
+	mutex_unlock(&adapter->sw_mutex);
+	return vport;
+}
+
 /**
  * iecm_statistics_task - Delayed task to get statistics over mailbox
  * @work: work_struct handle to our data
@@ -55,7 +167,25 @@ static void iecm_service_task(struct work_struct *work)
  */
 static void iecm_init_task(struct work_struct *work)
 {
-	/* stub */
+	struct iecm_adapter *adapter = container_of(work,
+						    struct iecm_adapter,
+						    init_task.work);
+	struct iecm_vport *vport;
+	struct pci_dev *pdev;
+	int vport_id, err;
+
+	err = adapter->dev_ops.vc_ops.core_init(adapter, &vport_id);
+	if (err)
+		return;
+
+	pdev = adapter->pdev;
+	vport = iecm_vport_alloc(adapter, vport_id);
+	if (!vport) {
+		err = -EFAULT;
+		dev_err(&pdev->dev, "failed to allocate vport: %d\n",
+			err);
+		return;
+	}
 }
 
 /**
@@ -81,6 +211,31 @@ static int iecm_api_init(struct iecm_adapter *adapter)
 		return -EINVAL;
 	}
 
+	if (adapter->dev_ops.vc_ops_init) {
+		struct iecm_virtchnl_ops *vc_ops;
+
+		adapter->dev_ops.vc_ops_init(adapter);
+		vc_ops = &adapter->dev_ops.vc_ops;
+		if (!(vc_ops->core_init &&
+		      vc_ops->vport_init &&
+		      vc_ops->vport_queue_ids_init &&

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 231

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+		      vc_ops->get_caps &&
+		      vc_ops->config_queues &&
+		      vc_ops->enable_queues &&
+		      vc_ops->disable_queues &&
+		      vc_ops->irq_map_unmap &&
+		      vc_ops->get_set_rss_lut &&
+		      vc_ops->get_set_rss_hash &&
+		      vc_ops->adjust_qs &&
+		      vc_ops->get_ptype &&
+		      vc_ops->init_max_queues)) {
if (!op1 ||
    !op2 ||

!opn) would look more natural and more readable here.

drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 237

Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6 -0
+			dev_err(&pdev->dev, "Invalid device, missing one or more virtchnl functions\n");
+			return -EINVAL;
+		}
+	} else {
+		iecm_vc_ops_init(adapter);
+	}

'else' path is a two-liner allowing to save one indent level:

	if (!adapter->dev_ops.vc_ops_init) {
		iecm_vc_ops_init(adapter);
		return 0;
	}

	adapter->dev_ops.vc_ops_init(adapter);
	vc_ops = &adapter->dev_ops.vc_ops;
	if (!(vc_ops->core_init &&
	...
Quoted 291 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -1
+
 	return 0;
 }
 
@@ -93,7 +248,15 @@ static int iecm_api_init(struct iecm_adapter *adapter)
  */
 static void iecm_deinit_task(struct iecm_adapter *adapter)
 {
-	/* stub */
+	set_bit(__IECM_REL_RES_IN_PROG, adapter->flags);
+	/* Wait until the init_task is done else this thread might release
+	 * the resources first and the other thread might end up in a bad state
+	 */
+	cancel_delayed_work_sync(&adapter->init_task);
+	iecm_vport_rel_all(adapter);
+
+	cancel_delayed_work_sync(&adapter->serv_task);
+	cancel_delayed_work_sync(&adapter->stats_task);
 }
 
 /**
drivers/net/ethernet/intel/iecm/iecm_txrx.c new file +22 -0
new file mode 100644
index 000000000000..2f5c16a28266
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2019 Intel Corporation */
+
+#include "iecm.h"
+
+/**
+ * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ *
+ */
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
+{
+	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+
+	q_vector->total_events++;
+	napi_schedule(&q_vector->napi);
+
+	return IRQ_HANDLED;
+}
+
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +227 -0
index b8f54b8c700a..aae06064d706 100644
@@ -3,6 +3,74 @@
 
 #include "iecm.h"
 
+/**
+ * iecm_recv_event_msg - Receive virtchnl event message
+ * @vport: virtual port structure
+ *
+ * Receive virtchnl event message
+ */
+static void iecm_recv_event_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl_pf_event *vpe;
+	struct virtchnl2_event *v2e;
+	bool link_status;
+	u32 event;
+
+	if (adapter->virt_ver_maj < VIRTCHNL_VERSION_MAJOR_2) {
+		vpe = (struct virtchnl_pf_event *)adapter->vc_msg;
+		event = vpe->event;
+	} else {
+		v2e = (struct virtchnl2_event *)adapter->vc_msg;
+		event = le32_to_cpu(v2e->event);
+	}
+
+	switch (event) {
+	case VIRTCHNL2_EVENT_LINK_CHANGE:
+		if (adapter->virt_ver_maj < VIRTCHNL_VERSION_MAJOR_2) {
+			if (iecm_is_cap_ena(adapter, IECM_OTHER_CAPS,
+					    VIRTCHNL2_CAP_LINK_SPEED)) {
+				adapter->link_speed_mbps =
+				vpe->event_data.link_event_adv.link_speed;
+				link_status =
+				vpe->event_data.link_event_adv.link_status;
+			} else {
+				adapter->link_speed =
+				vpe->event_data.link_event.link_speed;
+				link_status =
+				vpe->event_data.link_event.link_status;
+			}
+		} else {
+			adapter->link_speed_mbps = le32_to_cpu(v2e->link_speed);
+			link_status = v2e->link_status;
+		}
+		if (adapter->link_up != link_status) {
+			adapter->link_up = link_status;
+			if (adapter->state == __IECM_UP) {
+				if (adapter->link_up) {
+					netif_tx_start_all_queues(vport->netdev);
+					netif_carrier_on(vport->netdev);
+				} else {
+					netif_tx_stop_all_queues(vport->netdev);
+					netif_carrier_off(vport->netdev);
+				}
+			}
+		}
+		break;
+	case VIRTCHNL_EVENT_RESET_IMPENDING:
+		set_bit(__IECM_HR_CORE_RESET, adapter->flags);
+		queue_delayed_work(adapter->vc_event_wq,
+				   &adapter->vc_event_task,
+				   msecs_to_jiffies(10));
+		break;
+	default:
+		dev_err(&vport->adapter->pdev->dev,
+			"Unknown event %d from PF\n", event);
+		break;
+	}
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+}
+
 /**
  * iecm_mb_clean - Reclaim the send mailbox queue entries
  * @adapter: Driver specific private structure
@@ -39,6 +107,865 @@ static int iecm_mb_clean(struct iecm_adapter *adapter)
 	return err;
 }
 
+/**
+ * iecm_send_mb_msg - Send message over mailbox
+ * @adapter: Driver specific private structure
+ * @op: virtchnl opcode
+ * @msg_size: size of the payload
+ * @msg: pointer to buffer holding the payload
+ *
+ * Will prepare the control queue message and initiates the send api
+ *
+ * Returns 0 on success, negative on failure
+ */
+int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
+		     u16 msg_size, u8 *msg)
+{
+	struct iecm_ctlq_msg *ctlq_msg;
+	struct iecm_dma_mem *dma_mem;
+	int err = 0;
+
+	if (iecm_is_reset_detected(adapter))
+		return -EBUSY;
+
+	err = iecm_mb_clean(adapter);
+	if (err)
+		return err;
+
+	ctlq_msg = kzalloc(sizeof(*ctlq_msg), GFP_KERNEL);
+	if (!ctlq_msg)
+		return -ENOMEM;
+
+	dma_mem = kzalloc(sizeof(*dma_mem), GFP_KERNEL);
+	if (!dma_mem) {
+		err = -ENOMEM;
+		goto dma_mem_error;
+	}
+
+	memset(ctlq_msg, 0, sizeof(struct iecm_ctlq_msg));
+	ctlq_msg->opcode = iecm_mbq_opc_send_msg_to_pf;
+	ctlq_msg->func_id = 0;
+	ctlq_msg->data_len = msg_size;
+	ctlq_msg->cookie.mbx.chnl_opcode = op;
+	ctlq_msg->cookie.mbx.chnl_retval = VIRTCHNL_STATUS_SUCCESS;
+	dma_mem->size = IECM_DFLT_MBX_BUF_SIZE;
+	dma_mem->va = dmam_alloc_coherent(&adapter->pdev->dev, dma_mem->size,
+					  &dma_mem->pa, GFP_KERNEL);
+	if (!dma_mem->va) {
+		err = -ENOMEM;
+		goto dma_alloc_error;
+	}
+	memcpy(dma_mem->va, msg, msg_size);
+	ctlq_msg->ctx.indirect.payload = dma_mem;
+
+	err = iecm_ctlq_send(&adapter->hw, adapter->hw.asq, 1, ctlq_msg);
+	if (err)
+		goto send_error;
+
+	return 0;
+send_error:
+	dmam_free_coherent(&adapter->pdev->dev, dma_mem->size, dma_mem->va,
+			   dma_mem->pa);
+dma_alloc_error:
+	kfree(dma_mem);
+dma_mem_error:
+	kfree(ctlq_msg);
+	return err;
+}
+EXPORT_SYMBOL(iecm_send_mb_msg);
+
+/**
+ * iecm_set_msg_pending_bit - Wait for clear and set msg pending
+ * @adapter: driver specific private structure
+ *
+ * If clear sets msg pending bit, otherwise waits for it to clear before
+ * setting it again. Returns 0 on success, negative on failure.
+ */
+static int iecm_set_msg_pending_bit(struct iecm_adapter *adapter)
+{
+	unsigned int retries = 100;
+
+	/* If msg pending bit already set, there's a message waiting to be
+	 * parsed and we must wait for it to be cleared before copying a new
+	 * message into the vc_msg buffer or else we'll stomp all over the
+	 * previous message.
+	 */
+	while (retries) {
+		if (!test_and_set_bit(__IECM_VC_MSG_PENDING,
+				      adapter->flags))
+			break;
+		msleep(20);
+		retries--;
+	}
+	return retries ? 0 : -ETIMEDOUT;
+}
+
+/**
+ * iecm_set_msg_pending - Wait for msg pending bit and copy msg to buf
+ * @adapter: driver specific private structure
+ * @ctlq_msg: msg to copy from
+ * @err_enum: err bit to set on error
+ *
+ * Copies payload from ctlq_msg into vc_msg buf in adapter and sets msg pending
+ * bit. Returns 0 on success, negative on failure.
+ */
+int iecm_set_msg_pending(struct iecm_adapter *adapter,
+			 struct iecm_ctlq_msg *ctlq_msg,
+			 enum iecm_vport_vc_state err_enum)
+{
+	if (ctlq_msg->cookie.mbx.chnl_retval) {
+		set_bit(err_enum, adapter->vc_state);
+		return -EINVAL;
+	}
+
+	if (iecm_set_msg_pending_bit(adapter)) {
+		set_bit(err_enum, adapter->vc_state);
+		dev_info(&adapter->pdev->dev, "Timed out setting msg pending\n");
+		return -ETIMEDOUT;
+	}
+
+	memcpy(adapter->vc_msg, ctlq_msg->ctx.indirect.payload->va,
+	       min_t(int, ctlq_msg->ctx.indirect.payload->size,
+		     IECM_DFLT_MBX_BUF_SIZE));
+	return 0;
+}
+EXPORT_SYMBOL(iecm_set_msg_pending);
+
+/**
+ * iecm_recv_mb_msg - Receive message over mailbox
+ * @adapter: Driver specific private structure
+ * @op: virtchannel operation code
+ * @msg: Received message holding buffer
+ * @msg_size: message size
+ *
+ * Will receive control queue message and posts the receive buffer. Returns 0
+ * on success and negative on failure.
+ */
+int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
+		     void *msg, int msg_size)
+{
+	struct iecm_ctlq_msg ctlq_msg;
+	struct iecm_dma_mem *dma_mem;
+	struct iecm_vport *vport;
+	bool work_done = false;
+	int num_retry = 2000;
+	int payload_size = 0;
+	u16 num_q_msg;
+	int err = 0;
+
+	vport = adapter->vports[0];
+	while (1) {
+		/* Try to get one message */
+		num_q_msg = 1;
+		dma_mem = NULL;
+		err = iecm_ctlq_recv(adapter->hw.arq, &num_q_msg, &ctlq_msg);
+		/* If no message then decide if we have to retry based on
+		 * opcode
+		 */
+		if (err || !num_q_msg) {
+			/* Increasing num_retry to consider the delayed
+			 * responses because of large number of VF's mailbox
+			 * messages. If the mailbox message is received from

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 278

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			 * the other side, we come out of the sleep cycle
+			 * immediately else we wait for more time.
+			 */
+			if (op && num_retry-- &&
+			    !test_bit(__IECM_REL_RES_IN_PROG, adapter->flags)) {
+				msleep(20);
+				continue;
+			} else {
+				break;
+			}

Since if-condition always ends with a 'continue', 'else' is reduntant here.

Quoted 675 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +675 -0
+		}
+
+		/* If we are here a message is received. Check if we are looking
+		 * for a specific message based on opcode. If it is different
+		 * ignore and post buffers
+		 */
+		if (op && ctlq_msg.cookie.mbx.chnl_opcode != op)
+			goto post_buffs;
+
+		if (ctlq_msg.data_len)
+			payload_size = ctlq_msg.ctx.indirect.payload->size;
+
+		/* All conditions are met. Either a message requested is
+		 * received or we received a message to be processed
+		 */
+		switch (ctlq_msg.cookie.mbx.chnl_opcode) {
+		case VIRTCHNL_OP_VERSION:
+		case VIRTCHNL2_OP_GET_CAPS:
+		case VIRTCHNL2_OP_CREATE_VPORT:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_info(&adapter->pdev->dev, "Failure initializing, vc op: %u retval: %u\n",
+					 ctlq_msg.cookie.mbx.chnl_opcode,
+					 ctlq_msg.cookie.mbx.chnl_retval);
+				err = -EBADMSG;
+			} else if (msg) {
+				memcpy(msg, ctlq_msg.ctx.indirect.payload->va,
+				       min_t(int,
+					     payload_size, msg_size));
+			}
+			work_done = true;
+			break;
+		case VIRTCHNL2_OP_ENABLE_VPORT:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_ENA_VPORT_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_ENA_VPORT, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_DISABLE_VPORT:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_DIS_VPORT_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_DIS_VPORT, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_DESTROY_VPORT:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_DESTROY_VPORT_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_DESTROY_VPORT, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_CONFIG_TX_QUEUES:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_CONFIG_TXQ_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_CONFIG_TXQ, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_CONFIG_RX_QUEUES:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_CONFIG_RXQ_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_CONFIG_RXQ, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_ENABLE_QUEUES:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_ENA_QUEUES_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_ENA_QUEUES, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_DISABLE_QUEUES:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_DIS_QUEUES_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_DIS_QUEUES, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_ADD_QUEUES:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_ADD_QUEUES_ERR);
+			set_bit(IECM_VC_ADD_QUEUES, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_DEL_QUEUES:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_DEL_QUEUES_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_DEL_QUEUES, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_MAP_QUEUE_VECTOR:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_MAP_IRQ_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_MAP_IRQ, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_UNMAP_IRQ_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_UNMAP_IRQ, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_GET_STATS:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_GET_STATS_ERR);
+			set_bit(IECM_VC_GET_STATS, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_GET_RSS_HASH:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_GET_RSS_HASH_ERR);
+			set_bit(IECM_VC_GET_RSS_HASH, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_SET_RSS_HASH:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_SET_RSS_HASH_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_SET_RSS_HASH, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_GET_RSS_LUT:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_GET_RSS_LUT_ERR);
+			set_bit(IECM_VC_GET_RSS_LUT, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_SET_RSS_LUT:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_SET_RSS_LUT_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_SET_RSS_LUT, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_GET_RSS_KEY:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_GET_RSS_KEY_ERR);
+			set_bit(IECM_VC_GET_RSS_KEY, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_SET_RSS_KEY:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_SET_RSS_KEY_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_SET_RSS_KEY, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_ALLOC_VECTORS:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_ALLOC_VECTORS_ERR);
+			set_bit(IECM_VC_ALLOC_VECTORS, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_DEALLOC_VECTORS:
+			if (ctlq_msg.cookie.mbx.chnl_retval)
+				set_bit(IECM_VC_DEALLOC_VECTORS_ERR,
+					adapter->vc_state);
+			set_bit(IECM_VC_DEALLOC_VECTORS, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_GET_PTYPE_INFO:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_GET_PTYPE_INFO_ERR);
+			set_bit(IECM_VC_GET_PTYPE_INFO, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL2_OP_EVENT:
+		case VIRTCHNL_OP_EVENT:
+			if (iecm_set_msg_pending_bit(adapter)) {
+				dev_info(&adapter->pdev->dev, "Timed out setting msg pending\n");
+			} else {
+				memcpy(adapter->vc_msg,
+				       ctlq_msg.ctx.indirect.payload->va,
+				       min_t(int, payload_size,
+					     IECM_DFLT_MBX_BUF_SIZE));
+				iecm_recv_event_msg(vport);
+			}
+			break;
+		case VIRTCHNL_OP_ADD_ETH_ADDR:
+			if (test_and_clear_bit(__IECM_ADD_ETH_REQ, adapter->flags)) {
+				/* Message was sent asynchronously. We don't
+				 * normally print errors here, instead
+				 * preferring to handle errors in the function
+				 * calling wait_for_event. However, we will
+				 * have lost the context in which we sent the
+				 * message if asynchronous. We can't really do
+				 * anything about at it this point, but we
+				 * should at a minimum indicate that it looks
+				 * like something went wrong. Also don't bother
+				 * setting ERR bit or waking vchnl_wq since no
+				 * one will be waiting to read the async
+				 * message.
+				 */
+				if (ctlq_msg.cookie.mbx.chnl_retval) {
+					dev_err(&adapter->pdev->dev, "Failed to add MAC address: %d\n",
+						ctlq_msg.cookie.mbx.chnl_retval);
+				}
+				break;
+			}
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				set_bit(IECM_VC_ADD_ETH_ADDR_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_ADD_ETH_ADDR, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_DEL_ETH_ADDR:
+			if (test_and_clear_bit(__IECM_DEL_ETH_REQ, adapter->flags)) {
+				/* Message was sent asynchronously. We don't
+				 * normally print errors here, instead
+				 * preferring to handle errors in the function
+				 * calling wait_for_event. However, we will
+				 * have lost the context in which we sent the
+				 * message if asynchronous. We can't really do
+				 * anything about at it this point, but we
+				 * should at a minimum indicate that it looks
+				 * like something went wrong. Also don't bother
+				 * setting ERR bit or waking vchnl_wq since no
+				 * one will be waiting to read the async
+				 * message.
+				 */
+				if (ctlq_msg.cookie.mbx.chnl_retval) {
+					dev_err(&adapter->pdev->dev, "Failed to delete MAC address: %d\n",
+						ctlq_msg.cookie.mbx.chnl_retval);
+				}
+				break;
+			}
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				set_bit(IECM_VC_DEL_ETH_ADDR_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_DEL_ETH_ADDR, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				set_bit(IECM_VC_OFFLOAD_VLAN_V2_CAPS_ERR, adapter->vc_state);
+			} else {
+				memcpy(adapter->vc_msg,
+				       ctlq_msg.ctx.indirect.payload->va,
+				       min_t(int, payload_size,
+					     IECM_DFLT_MBX_BUF_SIZE));
+			}
+			set_bit(IECM_VC_OFFLOAD_VLAN_V2_CAPS, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_ADD_VLAN_V2:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to add vlan filter: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+			}
+			break;
+		case VIRTCHNL_OP_DEL_VLAN_V2:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to delete vlan filter: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+			}
+			break;
+		case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				set_bit(IECM_VC_INSERTION_ENA_VLAN_V2_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_INSERTION_ENA_VLAN_V2,
+				adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				set_bit(IECM_VC_INSERTION_DIS_VLAN_V2_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_INSERTION_DIS_VLAN_V2,
+				adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				set_bit(IECM_VC_STRIPPING_ENA_VLAN_V2_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_STRIPPING_ENA_VLAN_V2,
+				adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				set_bit(IECM_VC_STRIPPING_DIS_VLAN_V2_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_STRIPPING_DIS_VLAN_V2,
+				adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
+			/* This message can only be sent asynchronously. As
+			 * such we'll have lost the context in which it was
+			 * called and thus can only really report if it looks
+			 * like an error occurred. Don't bother setting ERR bit
+			 * or waking chnl_wq since no will be waiting to
+			 * reading message.
+			 */
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to set promiscuous mode: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+			}
+			break;
+		case VIRTCHNL_OP_ADD_CLOUD_FILTER:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to add cloud filter: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+				set_bit(IECM_VC_ADD_CLOUD_FILTER_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_ADD_CLOUD_FILTER, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_DEL_CLOUD_FILTER:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to delete cloud filter: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+				set_bit(IECM_VC_DEL_CLOUD_FILTER_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_DEL_CLOUD_FILTER, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_ADD_RSS_CFG:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to add RSS configuration: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+				set_bit(IECM_VC_ADD_RSS_CFG_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_ADD_RSS_CFG, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_DEL_RSS_CFG:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+				set_bit(IECM_VC_DEL_RSS_CFG_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_DEL_RSS_CFG, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_ADD_FDIR_FILTER:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_ADD_FDIR_FILTER_ERR);
+			set_bit(IECM_VC_ADD_FDIR_FILTER, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_DEL_FDIR_FILTER:
+			iecm_set_msg_pending(adapter, &ctlq_msg,
+					     IECM_VC_DEL_FDIR_FILTER_ERR);
+			set_bit(IECM_VC_DEL_FDIR_FILTER, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_ENABLE_CHANNELS:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to enable channels: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+				set_bit(IECM_VC_ENA_CHANNELS_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_ENA_CHANNELS, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		case VIRTCHNL_OP_DISABLE_CHANNELS:
+			if (ctlq_msg.cookie.mbx.chnl_retval) {
+				dev_err(&adapter->pdev->dev, "Failed to disable channels: %d\n",
+					ctlq_msg.cookie.mbx.chnl_retval);
+				set_bit(IECM_VC_DIS_CHANNELS_ERR,
+					adapter->vc_state);
+			}
+			set_bit(IECM_VC_DIS_CHANNELS, adapter->vc_state);
+			wake_up(&adapter->vchnl_wq);
+			break;
+		default:
+			if (adapter->dev_ops.vc_ops.recv_mbx_msg)
+				err =
+				adapter->dev_ops.vc_ops.recv_mbx_msg(adapter,
+								   msg,
+								   msg_size,
+								   &ctlq_msg,
+								   &work_done);
+			else
+				dev_warn(&adapter->pdev->dev,
+					 "Unhandled virtchnl response %d\n",
+					 ctlq_msg.cookie.mbx.chnl_opcode);
+			break;
+		} /* switch v_opcode */
+post_buffs:
+		if (ctlq_msg.data_len)
+			dma_mem = ctlq_msg.ctx.indirect.payload;
+		else
+			num_q_msg = 0;
+
+		err = iecm_ctlq_post_rx_buffs(&adapter->hw, adapter->hw.arq,
+					      &num_q_msg, &dma_mem);
+		/* If post failed clear the only buffer we supplied */
+		if (err && dma_mem)
+			dmam_free_coherent(&adapter->pdev->dev, dma_mem->size,
+					   dma_mem->va, dma_mem->pa);
+		/* Applies only if we are looking for a specific opcode */
+		if (work_done)
+			break;
+	}
+
+	return err;
+}
+EXPORT_SYMBOL(iecm_recv_mb_msg);
+
+/**
+ * iecm_send_ver_msg - send virtchnl version message
+ * @adapter: Driver specific private structure
+ *
+ * Send virtchnl version message.  Returns 0 on success, negative on failure.
+ */
+static int iecm_send_ver_msg(struct iecm_adapter *adapter)
+{
+	struct virtchnl_version_info vvi;
+
+	if (adapter->virt_ver_maj) {
+		vvi.major = adapter->virt_ver_maj;
+		vvi.minor = adapter->virt_ver_min;
+	} else {
+		vvi.major = IECM_VIRTCHNL_VERSION_MAJOR;
+		vvi.minor = IECM_VIRTCHNL_VERSION_MINOR;
+	}
+
+	return iecm_send_mb_msg(adapter, VIRTCHNL_OP_VERSION, sizeof(vvi),
+				(u8 *)&vvi);
+}
+
+/**
+ * iecm_recv_ver_msg - Receive virtchnl version message
+ * @adapter: Driver specific private structure
+ *
+ * Receive virtchnl version message. Returns 0 on success, -EAGAIN if we need
+ * to send version message again, otherwise negative on failure.
+ */
+static int iecm_recv_ver_msg(struct iecm_adapter *adapter)
+{
+	struct virtchnl_version_info vvi;
+	int err = 0;
+
+	err = iecm_recv_mb_msg(adapter, VIRTCHNL_OP_VERSION, &vvi, sizeof(vvi));
+	if (err)
+		return err;
+
+	if (vvi.major > IECM_VIRTCHNL_VERSION_MAJOR) {
+		dev_warn(&adapter->pdev->dev, "Virtchnl major version greater than supported\n");
+		return -EINVAL;
+	}
+	if (vvi.major == IECM_VIRTCHNL_VERSION_MAJOR &&
+	    vvi.minor > IECM_VIRTCHNL_VERSION_MINOR)
+		dev_warn(&adapter->pdev->dev, "Virtchnl minor version not matched\n");
+
+	/* If we have a mismatch, resend version to update receiver on what
+	 * version we will use.
+	 */
+	if (!adapter->virt_ver_maj &&
+	    vvi.major != IECM_VIRTCHNL_VERSION_MAJOR &&
+	    vvi.minor != IECM_VIRTCHNL_VERSION_MINOR)
+		err = -EAGAIN;
+
+	adapter->virt_ver_maj = vvi.major;
+	adapter->virt_ver_min = vvi.minor;
+
+	return err;
+}
+
+/**
+ * iecm_send_get_caps_msg - Send virtchnl get capabilities message
+ * @adapter: Driver specific private structure
+ *
+ * Send virtchl get capabilities message. Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_get_caps_msg(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_get_capabilities caps = {0};
+	int buf_size;
+
+	buf_size = sizeof(struct virtchnl2_get_capabilities);
+	adapter->caps = kzalloc(buf_size, GFP_KERNEL);
+	if (!adapter->caps)
+		return -ENOMEM;
+
+	caps.csum_caps =
+		cpu_to_le32(VIRTCHNL2_CAP_TX_CSUM_L3_IPV4	|
+			    VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP	|
+			    VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP	|
+			    VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP	|
+			    VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP	|
+			    VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP	|
+			    VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP	|
+			    VIRTCHNL2_CAP_TX_CSUM_GENERIC	|
+			    VIRTCHNL2_CAP_RX_CSUM_L3_IPV4	|
+			    VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP	|
+			    VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP	|
+			    VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP	|
+			    VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP	|
+			    VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP	|
+			    VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP	|
+			    VIRTCHNL2_CAP_RX_CSUM_GENERIC);
+
+	caps.seg_caps =
+		cpu_to_le32(VIRTCHNL2_CAP_SEG_IPV4_TCP		|
+			    VIRTCHNL2_CAP_SEG_IPV4_UDP		|
+			    VIRTCHNL2_CAP_SEG_IPV4_SCTP		|
+			    VIRTCHNL2_CAP_SEG_IPV6_TCP		|
+			    VIRTCHNL2_CAP_SEG_IPV6_UDP		|
+			    VIRTCHNL2_CAP_SEG_IPV6_SCTP		|
+			    VIRTCHNL2_CAP_SEG_GENERIC);
+
+	caps.rss_caps =
+		cpu_to_le64(VIRTCHNL2_CAP_RSS_IPV4_TCP		|
+			    VIRTCHNL2_CAP_RSS_IPV4_UDP		|
+			    VIRTCHNL2_CAP_RSS_IPV4_SCTP		|
+			    VIRTCHNL2_CAP_RSS_IPV4_OTHER	|
+			    VIRTCHNL2_CAP_RSS_IPV6_TCP		|
+			    VIRTCHNL2_CAP_RSS_IPV6_UDP		|
+			    VIRTCHNL2_CAP_RSS_IPV6_SCTP		|
+			    VIRTCHNL2_CAP_RSS_IPV6_OTHER	|
+			    VIRTCHNL2_CAP_RSS_IPV4_AH		|
+			    VIRTCHNL2_CAP_RSS_IPV4_ESP		|
+			    VIRTCHNL2_CAP_RSS_IPV4_AH_ESP	|
+			    VIRTCHNL2_CAP_RSS_IPV6_AH		|
+			    VIRTCHNL2_CAP_RSS_IPV6_ESP		|
+			    VIRTCHNL2_CAP_RSS_IPV6_AH_ESP);
+
+	caps.hsplit_caps =
+		cpu_to_le32(VIRTCHNL2_CAP_RX_HSPLIT_AT_L2	|
+			    VIRTCHNL2_CAP_RX_HSPLIT_AT_L3	|
+			    VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4	|
+			    VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6);
+
+	caps.rsc_caps =
+		cpu_to_le32(VIRTCHNL2_CAP_RSC_IPV4_TCP		|
+			    VIRTCHNL2_CAP_RSC_IPV4_SCTP		|
+			    VIRTCHNL2_CAP_RSC_IPV6_TCP		|
+			    VIRTCHNL2_CAP_RSC_IPV6_SCTP);
+
+	caps.other_caps =
+		cpu_to_le64(VIRTCHNL2_CAP_RDMA			|
+			    VIRTCHNL2_CAP_SRIOV			|
+			    VIRTCHNL2_CAP_MACFILTER		|
+			    VIRTCHNL2_CAP_FLOW_DIRECTOR		|
+			    VIRTCHNL2_CAP_SPLITQ_QSCHED		|
+			    VIRTCHNL2_CAP_CRC			|
+			    VIRTCHNL2_CAP_ADQ			|
+			    VIRTCHNL2_CAP_WB_ON_ITR		|
+			    VIRTCHNL2_CAP_PROMISC		|
+			    VIRTCHNL2_CAP_INLINE_IPSEC		|
+			    VIRTCHNL2_CAP_VLAN			|
+			    VIRTCHNL2_CAP_RX_FLEX_DESC);
+
+	return iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_CAPS, sizeof(caps),
+				(u8 *)&caps);
+}
+EXPORT_SYMBOL(iecm_send_get_caps_msg);
+
+/**
+ * iecm_recv_get_caps_msg - Receive virtchnl get capabilities message
+ * @adapter: Driver specific private structure
+ *
+ * Receive virtchnl get capabilities message.  Returns 0 on succes, negative on
+ * failure.
+ */
+static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)
+{
+	return iecm_recv_mb_msg(adapter, VIRTCHNL2_OP_GET_CAPS, adapter->caps,
+				sizeof(struct virtchnl2_get_capabilities));
+}
+
+/**
+ * iecm_send_create_vport_msg - Send virtchnl create vport message
+ * @adapter: Driver specific private structure
+ *
+ * send virtchnl creae vport message
+ *
+ * Returns 0 on success, negative on failure
+ */
+static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
+{
+	/* stub */
+	return 0;
+}
+
+/**
+ * iecm_recv_create_vport_msg - Receive virtchnl create vport message
+ * @adapter: Driver specific private structure
+ * @vport_id: Virtual port identifier
+ *
+ * Receive virtchnl create vport message.  Returns 0 on success, negative on
+ * failure.
+ */
+static int iecm_recv_create_vport_msg(struct iecm_adapter *adapter,
+				      int *vport_id)
+{
+	/* stub */
+	return 0;
+}
+
+/**
+ * __iecm_wait_for_event - wrapper function for wait on virtchannel response
+ * @adapter: Driver private data structure
+ * @state: check on state upon timeout
+ * @err_check: check if this specific error bit is set
+ * @timeout: Max time to wait
+ *
+ * Checks if state is set upon expiry of timeout.  Returns 0 on success,
+ * negative on failure.
+ */
+static int __iecm_wait_for_event(struct iecm_adapter *adapter,
+				 enum iecm_vport_vc_state state,
+				 enum iecm_vport_vc_state err_check,
+				 int timeout)
+{
+	int event;
+
+	event = wait_event_timeout(adapter->vchnl_wq,
+				   test_and_clear_bit(state, adapter->vc_state),
+				   msecs_to_jiffies(timeout));
+	if (event) {
+		if (test_and_clear_bit(err_check, adapter->vc_state)) {
+			dev_err(&adapter->pdev->dev, "VC response error %s\n",
+				iecm_vport_vc_state_str[err_check]);
+			return -EINVAL;
+		}
+		return 0;
+	}
+
+	/* Timeout occurred */
+	dev_err(&adapter->pdev->dev, "VC timeout, state = %s\n",
+		iecm_vport_vc_state_str[state]);
+	return -ETIMEDOUT;
+}
+
+/**
+ * iecm_min_wait_for_event - wait for virtchannel response
+ * @adapter: Driver private data structure
+ * @state: check on state upon timeout
+ * @err_check: check if this specific error bit is set
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_min_wait_for_event(struct iecm_adapter *adapter,
+			    enum iecm_vport_vc_state state,
+			    enum iecm_vport_vc_state err_check)
+{
+	int timeout = 2000;
+
+	return __iecm_wait_for_event(adapter, state, err_check, timeout);
+}
+EXPORT_SYMBOL(iecm_min_wait_for_event);
+
+/**
+ * iecm_wait_for_event - wait for virtchannel response
+ * @adapter: Driver private data structure
+ * @state: check on state upon timeout after 500ms
+ * @err_check: check if this specific error bit is set
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_wait_for_event(struct iecm_adapter *adapter,
+			enum iecm_vport_vc_state state,

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 963

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			enum iecm_vport_vc_state err_check)
+{
+	/* Increasing the timeout in __IECM_INIT_SW flow to consider large
+	 * number of VF's mailbox message responses. When a message is received
+	 * on mailbox, this thread is wake up by the iecm_recv_mb_msg before the
+	 * timeout expires. Only in the error case i.e. if no message is
+	 * received on mailbox, we wait for the complete timeout which is
+	 * less likely to happen.
+	 */
+	int timeout = 60000;

If you make a definition from it, it would be easier to find it later in case of adjustments needed.

Quoted 660 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +377 -0
+
+	return __iecm_wait_for_event(adapter, state, err_check, timeout);
+}
+EXPORT_SYMBOL(iecm_wait_for_event);
+
 /**
  * iecm_find_ctlq - Given a type and id, find ctlq info
  * @hw: hardware struct
@@ -170,3 +1097,375 @@ void iecm_vport_params_buf_rel(struct iecm_adapter *adapter)
 	kfree(adapter->caps);
 	kfree(adapter->config_data.req_qs_chunks);
 }
+
+/**
+ * iecm_vc_core_init - Initialize mailbox and get resources
+ * @adapter: Driver specific private structure
+ * @vport_id: Virtual port identifier
+ *
+ * Will check if HW is ready with reset complete. Initializes the mailbox and
+ * communicate with master to get all the default vport parameters. Returns 0
+ * on success, -EAGAIN function will get called again, otherwise negative on
+ * failure.
+ */
+int iecm_vc_core_init(struct iecm_adapter *adapter, int *vport_id)
+{
+	int err;
+
+	switch (adapter->state) {
+	case __IECM_STARTUP:
+		if (iecm_send_ver_msg(adapter))
+			goto init_failed;
+		adapter->state = __IECM_VER_CHECK;
+		goto restart;
+	case __IECM_VER_CHECK:
+		err = iecm_recv_ver_msg(adapter);
+		if (err == -EAGAIN) {
+			adapter->state = __IECM_STARTUP;
+			goto restart;
+		} else if (err) {
+			goto init_failed;
+		}
+		adapter->state = __IECM_GET_CAPS;
+		if (adapter->dev_ops.vc_ops.get_caps(adapter))
+			goto init_failed;
+		goto restart;
+	case __IECM_GET_CAPS:
+		if (iecm_recv_get_caps_msg(adapter))
+			goto init_failed;
+		if (iecm_send_create_vport_msg(adapter))
+			goto init_failed;
+		adapter->state = __IECM_GET_DFLT_VPORT_PARAMS;
+		goto restart;
+	case __IECM_GET_DFLT_VPORT_PARAMS:
+		if (iecm_recv_create_vport_msg(adapter, vport_id))
+			goto init_failed;
+		adapter->state = __IECM_INIT_SW;
+		break;
+	case __IECM_INIT_SW:
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Device is in bad state: %d\n",
+			adapter->state);
+		goto init_failed;
+	}
+
+	return 0;
+restart:
+	queue_delayed_work(adapter->init_wq, &adapter->init_task,
+			   msecs_to_jiffies(30));
+	/* Not an error. Using try again to continue with state machine */
+	return -EAGAIN;
+init_failed:
+	if (++adapter->mb_wait_count > IECM_MB_MAX_ERR) {
+		dev_err(&adapter->pdev->dev, "Failed to establish mailbox communications with hardware\n");
+		return -EFAULT;
+	}
+	adapter->state = __IECM_STARTUP;
+	/* If it reaches here, it is possible that mailbox queue initialization
+	 * register writes might not have taken effect. Retry to initialize
+	 * the mailbox again
+	 */
+	iecm_deinit_dflt_mbx(adapter);
+	set_bit(__IECM_HR_DRV_LOAD, adapter->flags);
+	queue_delayed_work(adapter->vc_event_wq, &adapter->vc_event_task,
+			   msecs_to_jiffies(20));
+	return -EAGAIN;
+}
+EXPORT_SYMBOL(iecm_vc_core_init);
+
+/**
+ * iecm_vport_init - Initialize virtual port
+ * @vport: virtual port to be initialized
+ * @vport_id: Unique identification number of vport
+ *
+ * Will initialize vport with the info received through MB earlier
+ */
+static void iecm_vport_init(struct iecm_vport *vport,
+			    __always_unused int vport_id)
+{
+	struct virtchnl2_create_vport *vport_msg;
+	u16 rx_itr[] = {2, 8, 32, 96, 128};
+	u16 tx_itr[] = {2, 8, 64, 128, 256};
+
+	vport_msg = (struct virtchnl2_create_vport *)
+				vport->adapter->vport_params_recvd[0];
+	vport->txq_model = le16_to_cpu(vport_msg->txq_model);
+	vport->rxq_model = le16_to_cpu(vport_msg->rxq_model);
+	vport->vport_type = le16_to_cpu(vport_msg->vport_type);
+	vport->vport_id = le32_to_cpu(vport_msg->vport_id);
+	vport->adapter->rss_data.rss_key_size =
+				min_t(u16, NETDEV_RSS_KEY_LEN,
+				      le16_to_cpu(vport_msg->rss_key_size));
+	vport->adapter->rss_data.rss_lut_size =
+				le16_to_cpu(vport_msg->rss_lut_size);
+	ether_addr_copy(vport->default_mac_addr, vport_msg->default_mac_addr);
+	vport->max_mtu = IECM_MAX_MTU;
+
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		vport->num_bufqs_per_qgrp = IECM_MAX_BUFQS_PER_RXQ_GRP;
+		/* Bufq[0] default buffer size is 4K
+		 * Bufq[1] default buffer size is 2K
+		 */
+		vport->bufq_size[0] = IECM_RX_BUF_4096;
+		vport->bufq_size[1] = IECM_RX_BUF_2048;
+	} else {
+		vport->num_bufqs_per_qgrp = 0;
+		vport->bufq_size[0] = IECM_RX_BUF_2048;
+	}
+
+	/*Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */
+	memcpy(vport->rx_itr_profile, rx_itr, IECM_DIM_PROFILE_SLOTS);
+	memcpy(vport->tx_itr_profile, tx_itr, IECM_DIM_PROFILE_SLOTS);
+}
+
+/**
+ * iecm_get_vec_ids - Initialize vector id from Mailbox parameters
+ * @adapter: adapter structure to get the mailbox vector id
+ * @vecids: Array of vector ids
+ * @num_vecids: number of vector ids
+ * @chunks: vector ids received over mailbox
+ *
+ * Will initialize the mailbox vector id which is received from the
+ * get capabilities and data queue vector ids with ids received as
+ * mailbox parameters.
+ * Returns number of ids filled
+ */
+int iecm_get_vec_ids(struct iecm_adapter *adapter,
+		     u16 *vecids, int num_vecids,
+		     struct virtchnl2_vector_chunks *chunks)
+{
+	u16 num_chunks = le16_to_cpu(chunks->num_vchunks);
+	u16 start_vecid, num_vec;
+	int num_vecid_filled = 0;
+	int i, j;
+
+	vecids[num_vecid_filled] = adapter->mb_vector.v_idx;
+	num_vecid_filled++;
+
+	for (j = 0; j < num_chunks; j++) {
+		struct virtchnl2_vector_chunk *chunk = &chunks->vchunks[j];
+
+		num_vec = le16_to_cpu(chunk->num_vectors);
+		start_vecid = le16_to_cpu(chunk->start_vector_id);
+		for (i = 0; i < num_vec; i++) {
+			if ((num_vecid_filled + i) < num_vecids) {
+				vecids[num_vecid_filled + i] = start_vecid;
+				start_vecid++;
+			} else {
+				break;
+			}
+		}
+		num_vecid_filled = num_vecid_filled + i;
+	}
+
+	return num_vecid_filled;
+}
+
+/**
+ * iecm_vport_get_queue_ids - Initialize queue id from Mailbox parameters
+ * @qids: Array of queue ids
+ * @num_qids: number of queue ids
+ * @q_type: queue model
+ * @chunks: queue ids received over mailbox
+ *
+ * Will initialize all queue ids with ids received as mailbox parameters
+ * Returns number of ids filled
+ */
+static int
+iecm_vport_get_queue_ids(u32 *qids, int num_qids, u16 q_type,
+			 struct virtchnl2_queue_reg_chunks *chunks)
+{
+	u16 num_chunks = le16_to_cpu(chunks->num_chunks);
+	u32 num_q_id_filled = 0, i;
+	u32 start_q_id, num_q;
+
+	while (num_chunks) {
+		struct virtchnl2_queue_reg_chunk *chunk = &chunks->chunks[num_chunks - 1];
+
+		if (le32_to_cpu(chunk->type) == q_type) {
+			num_q = le32_to_cpu(chunk->num_queues);
+			start_q_id = le32_to_cpu(chunk->start_queue_id);
+			for (i = 0; i < num_q; i++) {
+				if ((num_q_id_filled + i) < num_qids) {
+					qids[num_q_id_filled + i] = start_q_id;
+					start_q_id++;
+				} else {
+					break;
+				}
+			}
+			num_q_id_filled = num_q_id_filled + i;
+		}
+		num_chunks--;
+	}
+
+	return num_q_id_filled;
+}
+
+/**
+ * __iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters
+ * @vport: virtual port for which the queues ids are initialized
+ * @qids: queue ids
+ * @num_qids: number of queue ids
+ * @q_type: type of queue
+ *
+ * Will initialize all queue ids with ids received as mailbox
+ * parameters. Returns number of queue ids initialized.
+ */
+static int
+__iecm_vport_queue_ids_init(struct iecm_vport *vport, u32 *qids,
+			    int num_qids, u32 q_type)
+{
+	/* stub */
+	return 0;
+}
+
+/**
+ * iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters
+ * @vport: virtual port for which the queues ids are initialized
+ *
+ * Will initialize all queue ids with ids received as mailbox parameters.
+ * Returns 0 on success, negative if all the queues are not initialized.
+ */
+static int iecm_vport_queue_ids_init(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	/* We may never deal with more than 256 same type of queues */
+#define IECM_MAX_QIDS	256
+	u32 qids[IECM_MAX_QIDS];
+	int num_ids;
+	u16 q_type;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+			(struct virtchnl2_add_queues *)
+			vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+				vport->adapter->vport_params_recvd[0];
+		chunks = &vport_params->chunks;
+	}
+
+	num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
+					   VIRTCHNL2_QUEUE_TYPE_TX,
+					   chunks);
+	if (num_ids != vport->num_txq)
+		return -EINVAL;
+	num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
+					      VIRTCHNL2_QUEUE_TYPE_TX);
+	if (num_ids != vport->num_txq)
+		return -EINVAL;
+	num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
+					   VIRTCHNL2_QUEUE_TYPE_RX,
+					   chunks);
+	if (num_ids != vport->num_rxq)
+		return -EINVAL;
+	num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
+					      VIRTCHNL2_QUEUE_TYPE_RX);
+	if (num_ids != vport->num_rxq)
+		return -EINVAL;
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		q_type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
+		num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
+						   chunks);
+		if (num_ids != vport->num_complq)
+			return -EINVAL;
+		num_ids = __iecm_vport_queue_ids_init(vport, qids,
+						      num_ids,
+						      q_type);
+		if (num_ids != vport->num_complq)
+			return -EINVAL;
+	}
+
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		q_type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
+		num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
+						   chunks);
+		if (num_ids != vport->num_bufq)
+			return -EINVAL;
+		num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
+						      q_type);
+		if (num_ids != vport->num_bufq)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_is_capability_ena - Default implementation of capability checking
+ * @adapter: Private data struct
+ * @all: all or one flag
+ * @field: caps field to check for flags
+ * @flag: flag to check
+ *
+ * Return true if all capabilities are supported, false otherwise
+ */
+static bool iecm_is_capability_ena(struct iecm_adapter *adapter, bool all,
+				   enum iecm_cap_field field, u64 flag)
+{
+	u8 *caps = (u8 *)adapter->caps;
+	u32 *cap_field;
+
+	if (field == IECM_BASE_CAPS)
+		return false;
+	if (field >= IECM_CAP_FIELD_LAST) {
+		dev_err(&adapter->pdev->dev, "Bad capability field: %d\n",
+			field);
+		return false;
+	}
+	cap_field = (u32 *)(caps + field);
+
+	if (all)
+		return (*cap_field & flag) == flag;
+	else
+		return !!(*cap_field & flag);
+}
+
+/**
+ * iecm_vc_ops_init - Initialize virtchnl common api
+ * @adapter: Driver specific private structure
+ *
+ * Initialize the function pointers with the extended feature set functions
+ * as APF will deal only with new set of opcodes.
+ */
+void iecm_vc_ops_init(struct iecm_adapter *adapter)
+{
+	struct iecm_virtchnl_ops *vc_ops = &adapter->dev_ops.vc_ops;
+
+	vc_ops->core_init = iecm_vc_core_init;
+	vc_ops->vport_init = iecm_vport_init;
+	vc_ops->vport_queue_ids_init = iecm_vport_queue_ids_init;
+	vc_ops->get_caps = iecm_send_get_caps_msg;
+	vc_ops->is_cap_ena = iecm_is_capability_ena;
+	vc_ops->get_reserved_vecs = NULL;
+	vc_ops->config_queues = NULL;
+	vc_ops->enable_queues = NULL;
+	vc_ops->disable_queues = NULL;
+	vc_ops->add_queues = NULL;
+	vc_ops->delete_queues = NULL;
+	vc_ops->irq_map_unmap = NULL;
+	vc_ops->enable_vport = NULL;
+	vc_ops->disable_vport = NULL;
+	vc_ops->destroy_vport = NULL;
+	vc_ops->get_ptype = NULL;
+	vc_ops->get_set_rss_key = NULL;
+	vc_ops->get_set_rss_lut = NULL;
+	vc_ops->get_set_rss_hash = NULL;
+	vc_ops->adjust_qs = NULL;
+	vc_ops->add_del_vlans = NULL;
+	vc_ops->strip_vlan_msg = NULL;
+	vc_ops->insert_vlan_msg = NULL;
+	vc_ops->init_max_queues = NULL;
+	vc_ops->get_max_tx_bufs = NULL;
+	vc_ops->vportq_reg_init = NULL;
+	vc_ops->alloc_vectors = NULL;
+	vc_ops->dealloc_vectors = NULL;
+	vc_ops->get_supported_desc_ids = NULL;
+	vc_ops->get_stats_msg = NULL;
+	vc_ops->recv_mbx_msg = NULL;
+}
+EXPORT_SYMBOL(iecm_vc_ops_init);
drivers/net/ethernet/intel/include/iecm.h +231 -1
index ca9029224e06..994664dfe419 100644
@@ -7,10 +7,13 @@
 #include <linux/aer.h>
 #include <linux/pci.h>
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 #include <linux/ethtool.h>
+#include <net/tcp.h>
 #include <linux/version.h>
 #include <linux/dim.h>
 
+#include "virtchnl_2.h"
 #include "iecm_txrx.h"
 #include "iecm_controlq.h"
 
@@ -35,10 +38,34 @@
 /* available message levels */
 #define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+#define IECM_VIRTCHNL_VERSION_MAJOR VIRTCHNL_VERSION_MAJOR_2
+#define IECM_VIRTCHNL_VERSION_MINOR VIRTCHNL_VERSION_MINOR_0
+
 /* Forward declaration */
 struct iecm_adapter;
 struct iecm_vport;
 
+struct iecm_mac_filter {
+	struct list_head list;
+	u8 macaddr[ETH_ALEN];
+	bool remove;		/* filter needs to be removed */
+	bool add;		/* filter needs to be added */
+};
+
+#define IECM_VLAN(vid, tpid) ((struct iecm_vlan){ vid, tpid })
+
+struct iecm_vlan {
+	u16 vid;
+	u16 tpid;
+};
+
+struct iecm_vlan_filter {
+	struct list_head list;
+	struct iecm_vlan vlan;
+	bool remove;		/* filter needs to be removed */
+	bool add;		/* filter needs to be added */
+};
+
 enum iecm_state {
 	__IECM_STARTUP,
 	__IECM_VER_CHECK,
@@ -90,6 +117,24 @@ enum iecm_flags {
 	__IECM_FLAGS_NBITS,
 };
 
+/* enum used to distinquish which capability field to check */
+enum iecm_cap_field {
+	IECM_BASE_CAPS		= -1,
+	IECM_CSUM_CAPS		= offsetof(struct virtchnl2_get_capabilities,
+					   csum_caps),
+	IECM_SEG_CAPS		= offsetof(struct virtchnl2_get_capabilities,
+					   seg_caps),
+	IECM_RSS_CAPS		= offsetof(struct virtchnl2_get_capabilities,
+					   rss_caps),
+	IECM_HSPLIT_CAPS	= offsetof(struct virtchnl2_get_capabilities,
+					   hsplit_caps),
+	IECM_RSC_CAPS		= offsetof(struct virtchnl2_get_capabilities,
+					   rsc_caps),
+	IECM_OTHER_CAPS		= offsetof(struct virtchnl2_get_capabilities,
+					   other_caps),
+	IECM_CAP_FIELD_LAST,
+};
+
 struct iecm_reset_reg {
 	u32 rstat;
 	u32 rstat_m;
@@ -105,14 +150,229 @@ struct iecm_reg_ops {
 			      enum iecm_flags trig_cause);
 };
 
+struct iecm_virtchnl_ops {
+	int (*core_init)(struct iecm_adapter *adapter, int *vport_id);
+	void (*vport_init)(struct iecm_vport *vport, int vport_id);
+	int (*vport_queue_ids_init)(struct iecm_vport *vport);
+	int (*get_caps)(struct iecm_adapter *adapter);
+	int (*config_queues)(struct iecm_vport *vport);
+	int (*enable_queues)(struct iecm_vport *vport);
+	int (*disable_queues)(struct iecm_vport *vport);
+	int (*add_queues)(struct iecm_vport *vport, u16 num_tx_q,
+			  u16 num_complq, u16 num_rx_q,
+			  u16 num_rx_bufq);
+	int (*delete_queues)(struct iecm_vport *vport);
+	int (*irq_map_unmap)(struct iecm_vport *vport, bool map);
+	int (*enable_vport)(struct iecm_vport *vport);
+	int (*disable_vport)(struct iecm_vport *vport);
+	int (*destroy_vport)(struct iecm_vport *vport);
+	int (*get_ptype)(struct iecm_vport *vport);
+	int (*get_set_rss_key)(struct iecm_vport *vport, bool get);
+	int (*get_set_rss_lut)(struct iecm_vport *vport, bool get);
+	int (*get_set_rss_hash)(struct iecm_vport *vport, bool get);
+	void (*adjust_qs)(struct iecm_vport *vport);
+	int (*recv_mbx_msg)(struct iecm_adapter *adapter,
+			    void *msg, int msg_size,
+			    struct iecm_ctlq_msg *ctlq_msg, bool *work_done);
+	bool (*is_cap_ena)(struct iecm_adapter *adapter, bool all,
+			   enum iecm_cap_field field, u64 flag);
+	u16 (*get_reserved_vecs)(struct iecm_adapter *adapter);
+	void (*add_del_vlans)(struct iecm_vport *vport, bool add);
+	int (*strip_vlan_msg)(struct iecm_vport *vport, bool ena);
+	int (*insert_vlan_msg)(struct iecm_vport *vport, bool ena);
+	void (*init_max_queues)(struct iecm_adapter *adapter);
+	unsigned int (*get_max_tx_bufs)(struct iecm_adapter *adapter);
+	int (*vportq_reg_init)(struct iecm_vport *vport);
+	int (*alloc_vectors)(struct iecm_adapter *adapter, u16 num_vectors);
+	int (*dealloc_vectors)(struct iecm_adapter *adapter);
+	int (*get_supported_desc_ids)(struct iecm_vport *vport);
+	int (*get_stats_msg)(struct iecm_vport *vport);
+};
+
 struct iecm_dev_ops {
 	void (*reg_ops_init)(struct iecm_adapter *adapter);
+	void (*vc_ops_init)(struct iecm_adapter *adapter);
 	void (*crc_enable)(u64 *td_cmd);
 	struct iecm_reg_ops reg_ops;
+	struct iecm_virtchnl_ops vc_ops;
+};
+
+/* These macros allow us to generate an enum and a matching char * array of
+ * stringified enums that are always in sync. Checkpatch issues a bogus warning
+ * about this being a complex macro; but it's wrong, these are never used as a
+ * statement and instead only used to define the enum and array.
+ */
+#define IECM_FOREACH_VPORT_VC_STATE(STATE)	\
+	STATE(IECM_VC_ENA_VPORT)		\
+	STATE(IECM_VC_ENA_VPORT_ERR)		\
+	STATE(IECM_VC_DIS_VPORT)		\
+	STATE(IECM_VC_DIS_VPORT_ERR)		\
+	STATE(IECM_VC_DESTROY_VPORT)		\
+	STATE(IECM_VC_DESTROY_VPORT_ERR)	\
+	STATE(IECM_VC_CONFIG_TXQ)		\
+	STATE(IECM_VC_CONFIG_TXQ_ERR)		\
+	STATE(IECM_VC_CONFIG_RXQ)		\
+	STATE(IECM_VC_CONFIG_RXQ_ERR)		\
+	STATE(IECM_VC_CONFIG_Q)			\
+	STATE(IECM_VC_CONFIG_Q_ERR)		\
+	STATE(IECM_VC_ENA_QUEUES)		\
+	STATE(IECM_VC_ENA_QUEUES_ERR)		\
+	STATE(IECM_VC_DIS_QUEUES)		\
+	STATE(IECM_VC_DIS_QUEUES_ERR)		\
+	STATE(IECM_VC_ENA_CHANNELS)		\
+	STATE(IECM_VC_ENA_CHANNELS_ERR)		\
+	STATE(IECM_VC_DIS_CHANNELS)		\
+	STATE(IECM_VC_DIS_CHANNELS_ERR)		\
+	STATE(IECM_VC_MAP_IRQ)			\
+	STATE(IECM_VC_MAP_IRQ_ERR)		\
+	STATE(IECM_VC_UNMAP_IRQ)		\
+	STATE(IECM_VC_UNMAP_IRQ_ERR)		\
+	STATE(IECM_VC_ADD_QUEUES)		\
+	STATE(IECM_VC_ADD_QUEUES_ERR)		\
+	STATE(IECM_VC_DEL_QUEUES)		\
+	STATE(IECM_VC_REQUEST_QUEUES)		\
+	STATE(IECM_VC_REQUEST_QUEUES_ERR)	\
+	STATE(IECM_VC_DEL_QUEUES_ERR)		\
+	STATE(IECM_VC_ALLOC_VECTORS)		\
+	STATE(IECM_VC_ALLOC_VECTORS_ERR)	\
+	STATE(IECM_VC_DEALLOC_VECTORS)		\
+	STATE(IECM_VC_DEALLOC_VECTORS_ERR)	\
+	STATE(IECM_VC_SET_SRIOV_VFS)		\
+	STATE(IECM_VC_SET_SRIOV_VFS_ERR)	\
+	STATE(IECM_VC_GET_RSS_HASH)		\
+	STATE(IECM_VC_GET_RSS_HASH_ERR)		\
+	STATE(IECM_VC_SET_RSS_HASH)		\
+	STATE(IECM_VC_SET_RSS_HASH_ERR)		\
+	STATE(IECM_VC_GET_RSS_LUT)		\
+	STATE(IECM_VC_GET_RSS_LUT_ERR)		\
+	STATE(IECM_VC_SET_RSS_LUT)		\
+	STATE(IECM_VC_SET_RSS_LUT_ERR)		\
+	STATE(IECM_VC_GET_RSS_KEY)		\
+	STATE(IECM_VC_GET_RSS_KEY_ERR)		\
+	STATE(IECM_VC_SET_RSS_KEY)		\
+	STATE(IECM_VC_SET_RSS_KEY_ERR)		\
+	STATE(IECM_VC_GET_STATS)		\
+	STATE(IECM_VC_GET_STATS_ERR)		\
+	STATE(IECM_VC_ENA_STRIP_VLAN_TAG)	\
+	STATE(IECM_VC_ENA_STRIP_VLAN_TAG_ERR)	\
+	STATE(IECM_VC_DIS_STRIP_VLAN_TAG)	\
+	STATE(IECM_VC_DIS_STRIP_VLAN_TAG_ERR)	\
+	STATE(IECM_VC_IWARP_IRQ_MAP)		\
+	STATE(IECM_VC_IWARP_IRQ_MAP_ERR)	\
+	STATE(IECM_VC_ADD_ETH_ADDR)		\
+	STATE(IECM_VC_ADD_ETH_ADDR_ERR)		\
+	STATE(IECM_VC_DEL_ETH_ADDR)		\
+	STATE(IECM_VC_DEL_ETH_ADDR_ERR)		\
+	STATE(IECM_VC_PROMISC)			\
+	STATE(IECM_VC_ADD_CLOUD_FILTER)		\
+	STATE(IECM_VC_ADD_CLOUD_FILTER_ERR)	\
+	STATE(IECM_VC_DEL_CLOUD_FILTER)		\
+	STATE(IECM_VC_DEL_CLOUD_FILTER_ERR)	\
+	STATE(IECM_VC_ADD_RSS_CFG)		\
+	STATE(IECM_VC_ADD_RSS_CFG_ERR)		\
+	STATE(IECM_VC_DEL_RSS_CFG)		\
+	STATE(IECM_VC_DEL_RSS_CFG_ERR)		\
+	STATE(IECM_VC_ADD_FDIR_FILTER)		\
+	STATE(IECM_VC_ADD_FDIR_FILTER_ERR)	\
+	STATE(IECM_VC_DEL_FDIR_FILTER)		\
+	STATE(IECM_VC_DEL_FDIR_FILTER_ERR)	\
+	STATE(IECM_VC_OFFLOAD_VLAN_V2_CAPS)	\
+	STATE(IECM_VC_OFFLOAD_VLAN_V2_CAPS_ERR)	\
+	STATE(IECM_VC_INSERTION_ENA_VLAN_V2)	\
+	STATE(IECM_VC_INSERTION_ENA_VLAN_V2_ERR)\
+	STATE(IECM_VC_INSERTION_DIS_VLAN_V2)	\
+	STATE(IECM_VC_INSERTION_DIS_VLAN_V2_ERR)\
+	STATE(IECM_VC_STRIPPING_ENA_VLAN_V2)	\
+	STATE(IECM_VC_STRIPPING_ENA_VLAN_V2_ERR)\
+	STATE(IECM_VC_STRIPPING_DIS_VLAN_V2)	\
+	STATE(IECM_VC_STRIPPING_DIS_VLAN_V2_ERR)\
+	STATE(IECM_VC_GET_SUPPORTED_RXDIDS)	\
+	STATE(IECM_VC_GET_SUPPORTED_RXDIDS_ERR)	\
+	STATE(IECM_VC_GET_PTYPE_INFO)		\
+	STATE(IECM_VC_GET_PTYPE_INFO_ERR)	\
+	STATE(IECM_VC_NBITS)
+
+#define IECM_GEN_ENUM(ENUM) ENUM,
+#define IECM_GEN_STRING(STRING) #STRING,
+
+enum iecm_vport_vc_state {
+	IECM_FOREACH_VPORT_VC_STATE(IECM_GEN_ENUM)
+};
+
+extern const char * const iecm_vport_vc_state_str[];
+
+enum iecm_vport_flags {
+	__IECM_VPORT_INIT_PROMISC,
+	__IECM_VPORT_FLAGS_NBITS,
+};
+
+struct iecm_port_stats {
+	struct u64_stats_sync stats_sync;
+	u64 rx_hw_csum_err;
+	u64 rx_hsplit;
+	u64 rx_hsplit_hbo;
+	u64 tx_linearize;
+	u64 rx_bad_descs;
+	struct virtchnl2_vport_stats vport_stats;
+	struct virtchnl_eth_stats eth_stats;
 };
 
-/* stub */
 struct iecm_vport {
+	/* TX */
+	int num_txq;
+	int num_complq;
+	/* It makes more sense for descriptor count to be part of only idpf
+	 * queue structure. But when user changes the count via ethtool, driver
+	 * has to store that value somewhere other than queue structure as the
+	 * queues will be freed and allocated again.
+	 */
+	int txq_desc_count;
+	int complq_desc_count;
+	int compln_clean_budget;
+	int num_txq_grp;
+	struct iecm_txq_group *txq_grps;
+	u32 txq_model;
+	/* Used only in hotpath to get to the right queue very fast */
+	struct iecm_queue **txqs;
+	DECLARE_BITMAP(flags, __IECM_VPORT_FLAGS_NBITS);
+
+	/* RX */
+	int num_rxq;
+	int num_bufq;
+	int rxq_desc_count;
+	u8 num_bufqs_per_qgrp;
+	int bufq_desc_count[IECM_MAX_BUFQS_PER_RXQ_GRP];
+	u32 bufq_size[IECM_MAX_BUFQS_PER_RXQ_GRP];

drivers/net/ethernet/intel/include/iecm.h struct iecm_reg_ops { · line 355

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +10 -0
+	int num_rxq_grp;
+	struct iecm_rxq_group *rxq_grps;
+	u32 rxq_model;
+
+	struct iecm_adapter *adapter;
+	struct net_device *netdev;
+	u16 vport_type;
+	u16 vport_id;
+	u16 idx;		 /* software index in adapter vports struct */
+	bool base_rxd;

Bools are not really advised to use inside structures since they may have different sizes and alignments. There's a 2-byte hole here, so u8 or u16 for base_rxd would do the job.

Quoted 179 lines
drivers/net/ethernet/intel/include/iecm.h +74 -0
+
+	/* handler for hard interrupt */
+	irqreturn_t (*irq_q_handler)(int irq, void *data);
+	struct iecm_q_vector *q_vectors;	/* q vector array */
+	u16 num_q_vectors;
+	u16 q_vector_base;
+	u16 max_mtu;
+	u8 default_mac_addr[ETH_ALEN];
+	u16 qset_handle;
+	/* ITR profiles for the DIM algorithm */
+#define IECM_DIM_PROFILE_SLOTS	5
+	u16 rx_itr_profile[IECM_DIM_PROFILE_SLOTS];
+	u16 tx_itr_profile[IECM_DIM_PROFILE_SLOTS];
+	struct rtnl_link_stats64 netstats;
+	struct iecm_port_stats port_stats;
+
+	/* lock to protect against multiple stop threads, which can happen when
+	 * the driver is in a namespace in a system that is being shutdown
+	 */
+	struct mutex stop_mutex;
 };
 
 enum iecm_user_flags {
@@ -164,6 +424,7 @@ struct iecm_adapter {
 	u16 num_msix_entries;
 	struct msix_entry *msix_entries;
 	struct virtchnl2_alloc_vectors *req_vec_chunks;
+	struct iecm_q_vector mb_vector;
 
 	/* vport structs */
 	struct iecm_vport **vports;	/* vports created by the driver */
@@ -190,6 +451,8 @@ struct iecm_adapter {
 
 	wait_queue_head_t vchnl_wq;
 	wait_queue_head_t sw_marker_wq;
+	DECLARE_BITMAP(vc_state, IECM_VC_NBITS);
+	char vc_msg[IECM_DFLT_MBX_BUF_SIZE];
 	struct iecm_rss_data rss_data;
 	struct iecm_dev_ops dev_ops;
 	s32 link_speed;
@@ -215,6 +478,38 @@ struct iecm_adapter {
 	spinlock_t fdir_fltr_list_lock;
 };
 
+/**
+ * iecm_is_queue_model_split - check if queue model is split
+ * @q_model: queue model single or split
+ *
+ * Returns true if queue model is split else false
+ */
+static inline int iecm_is_queue_model_split(u16 q_model)
+{
+	return (q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT);
+}
+
+#define iecm_is_cap_ena(adapter, field, flag) \
+	__iecm_is_cap_ena(adapter, false, field, flag)
+#define iecm_is_cap_ena_all(adapter, field, flag) \
+	__iecm_is_cap_ena(adapter, true, field, flag)
+/**
+ * __iecm_is_cap_ena - Determine if HW capability is supported
+ * @adapter: private data struct
+ * @all: all or one flag
+ * @field: cap field to check
+ * @flag: Feature flag to check
+ *
+ * iecm_is_cap_ena_all is used to check if all the capability bits are set
+ * ('AND' operation) where as iecm_is_cap_ena is used to check if
+ * any one of the capability bits is set ('OR' operation)
+ */
+static inline bool __iecm_is_cap_ena(struct iecm_adapter *adapter, bool all,
+				     enum iecm_cap_field field, u64 flag)
+{
+	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field, flag);
+}
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure
@@ -233,6 +528,25 @@ int iecm_probe(struct pci_dev *pdev,
 void iecm_remove(struct pci_dev *pdev);
 int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
+void iecm_vc_ops_init(struct iecm_adapter *adapter);
+int iecm_vc_core_init(struct iecm_adapter *adapter, int *vport_id);
+int iecm_wait_for_event(struct iecm_adapter *adapter,
+			enum iecm_vport_vc_state state,
+			enum iecm_vport_vc_state err_check);
+int iecm_min_wait_for_event(struct iecm_adapter *adapter,
+			    enum iecm_vport_vc_state state,
+			    enum iecm_vport_vc_state err_check);
+int iecm_send_get_caps_msg(struct iecm_adapter *adapter);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
+int iecm_get_vec_ids(struct iecm_adapter *adapter,
+		     u16 *vecids, int num_vecids,
+		     struct virtchnl2_vector_chunks *chunks);
+int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
+		     void *msg, int msg_size);
+int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
+		     u16 msg_size, u8 *msg);
+int iecm_set_msg_pending(struct iecm_adapter *adapter,
+			 struct iecm_ctlq_msg *ctlq_msg,
+			 enum iecm_vport_vc_state err_enum);
 #endif /* !_IECM_H_ */
drivers/net/ethernet/intel/include/iecm_txrx.h +66 -0
index 602d3b3b19dd..e1348011c991 100644
@@ -30,4 +30,98 @@
 #define IECM_DFLT_SPLITQ_RX_Q_GROUPS		4
 #define IECM_DFLT_SPLITQ_TXQ_PER_GROUP		1
 #define IECM_DFLT_SPLITQ_RXQ_PER_GROUP		1
+
+/* Default vector sharing */
+#define IECM_NONQ_VEC		1
+#define IECM_MAX_Q_VEC		4 /* For Tx Completion queue and Rx queue */
+#define IECM_MIN_Q_VEC		1
+#define IECM_MAX_RDMA_VEC	2 /* To share with RDMA */
+#define IECM_MIN_RDMA_VEC	1 /* Minimum vectors to be shared with RDMA */
+#define IECM_MIN_VEC		3 /* One for mailbox, one for data queues, one
+				   * for RDMA
+				   */
+
+#define IECM_DFLT_TX_Q_DESC_COUNT		512
+#define IECM_DFLT_TX_COMPLQ_DESC_COUNT		512
+#define IECM_DFLT_RX_Q_DESC_COUNT		512
+/* IMPORTANT: We absolutely _cannot_ have more buffers in the system than a
+ * given RX completion queue has descriptors. This includes _ALL_ buffer
+ * queues. E.g.: If you have two buffer queues of 512 descriptors and buffers,
+ * you have a total of 1024 buffers so your RX queue _must_ have at least that
+ * many descriptors. This macro divides a given number of RX descriptors by
+ * number of buffer queues to calculate how many descriptors each buffer queue
+ * can have without overrunning the RX queue.
+ *
+ * If you give hardware more buffers than completion descriptors what will
+ * happen is that if hardware gets a chance to post more than ring wrap of
+ * descriptors before SW gets an interrupt and overwrites SW head, the gen bit
+ * in the descriptor will be wrong. Any overwritten descriptors' buffers will
+ * be gone forever and SW has no reasonable way to tell that this has happened.
+ * From SW perspective, when we finally get an interrupt, it looks like we're
+ * still waiting for descriptor to be done, stalling forever.
+ */
+#define IECM_RX_BUFQ_DESC_COUNT(RXD, NUM_BUFQ)	((RXD) / (NUM_BUFQ))
+
+#define IECM_RX_BUFQ_WORKING_SET(R)		((R)->desc_count - 1)
+#define IECM_RX_BUFQ_NON_WORKING_SET(R)		((R)->desc_count - \
+						 IECM_RX_BUFQ_WORKING_SET(R))
+
+#define IECM_RX_HDR_SIZE			256
+#define IECM_RX_BUF_2048			2048
+#define IECM_RX_BUF_4096			4096
+#define IECM_RX_BUF_STRIDE			64
+#define IECM_LOW_WATERMARK			64
+#define IECM_HDR_BUF_SIZE			256
+#define IECM_PACKET_HDR_PAD	\
+	(ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))
+#define IECM_MAX_RXBUFFER			9728
+#define IECM_MAX_MTU		\
+	(IECM_MAX_RXBUFFER - IECM_PACKET_HDR_PAD)
+#define IECM_INT_NAME_STR_LEN	(IFNAMSIZ + 16)
+
+#define IECM_TX_COMPLQ_CLEAN_BUDGET	256
+
+struct iecm_intr_reg {
+	u32 dyn_ctl;
+	u32 dyn_ctl_intena_m;
+	u32 dyn_ctl_clrpba_m;
+	u32 dyn_ctl_itridx_s;
+	u32 dyn_ctl_itridx_m;
+	u32 dyn_ctl_intrvl_s;
+	u32 rx_itr;
+	u32 tx_itr;
+	u32 icr_ena;
+	u32 icr_ena_ctlq_m;
+};
+
+struct iecm_q_vector {
+	struct iecm_vport *vport;

drivers/net/ethernet/intel/include/iecm_txrx.h line 108

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+	cpumask_t affinity_mask;
+	struct napi_struct napi;
+	u16 v_idx;		/* index in the vport->q_vector array */
+	struct iecm_intr_reg intr_reg;
+
+	int num_txq;
+	struct iecm_queue **tx;
+	struct dim tx_dim;	/* data for net_dim algorithm */
+	u16 tx_itr_value;
+	bool tx_intr_mode;

Same here.

drivers/net/ethernet/intel/include/iecm_txrx.h line 115

Quoted 7 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +7 -0
+	u32 tx_itr_idx;
+
+	int num_rxq;
+	struct iecm_queue **rx;
+	struct dim rx_dim;	/* data for net_dim algorithm */
+	u16 rx_itr_value;
+	bool rx_intr_mode;

...here as well, and most likely in more places I overlooked.

Quoted 14 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +11 -0
+	u32 rx_itr_idx;
+
+	int num_bufq;
+	struct iecm_queue **bufq;
+
+	u16 total_events;       /* net_dim(): number of interrupts processed */
+	char name[IECM_INT_NAME_STR_LEN];
+};
+
+irqreturn_t
+iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0

Thanks,
Al

#21 lore raw

PATCH 5/19 iecm: add vport alloc and virtchnl messages

In reply to kernel test robot

From: kernel test robot <[email protected]>
Date: Fri, 28 Jan 2022 12:19:10 +0800

Quoted 32 lines

Hi Alan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-idpf/20220128-085513
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220128/202201281200.CI9u45bS-lkp at intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/1233d9631b312eea5aebbce63590e27f9993bacc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513 git checkout 1233d9631b312eea5aebbce63590e27f9993bacc
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/net/ethernet/intel/iecm/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c: In function 'iecm_vport_queue_ids_init':

Quoted 1 line
Quoted 1 line

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c:1396:1: warning: the frame size of 1052 bytes is larger than 1024 bytes [-Wframe-larger-than=]

    1396 | }
         | ^

vim +1396 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c

Quoted 15 lines

1322
1323 /**
1324 * iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters
1325 * @vport: virtual port for which the queues ids are initialized
1326 *
1327 * Will initialize all queue ids with ids received as mailbox parameters.
1328 * Returns 0 on success, negative if all the queues are not initialized.
1329 */
1330 static int iecm_vport_queue_ids_init(struct iecm_vport *vport)
1331 {
1332 struct virtchnl2_create_vport *vport_params;
1333 struct virtchnl2_queue_reg_chunks *chunks;
1334 /* We may never deal with more than 256 same type of queues */
1335 #define IECM_MAX_QIDS 256
1336 u32 qids[IECM_MAX_QIDS];

I'll elaborate on this warning a bit: you declare 4 * 256 = 1 Kb array directly on the stack here.

1 Kb is a limit inside the kernel, it won't cause any issues since stacks on x86 are huge, but raises such warnings and we should listen to them, especially given that compile tests are now being done with -Werror.

Just use kzalloc(array_size(IECM_MAX_QIDS, sizeof(u32))) + kfree() here to avoid that.

Quoted 59 lines

1337 int num_ids;
1338 u16 q_type;
1339
1340 if (vport->adapter->config_data.req_qs_chunks) {
1341 struct virtchnl2_add_queues *vc_aq =
1342 (struct virtchnl2_add_queues *)
1343 vport->adapter->config_data.req_qs_chunks;
1344 chunks = &vc_aq->chunks;
1345 } else {
1346 vport_params = (struct virtchnl2_create_vport *)
1347 vport->adapter->vport_params_recvd[0];
1348 chunks = &vport_params->chunks;
1349 }
1350
1351 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
1352 VIRTCHNL2_QUEUE_TYPE_TX,
1353 chunks);
1354 if (num_ids != vport->num_txq)
1355 return -EINVAL;
1356 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1357 VIRTCHNL2_QUEUE_TYPE_TX);
1358 if (num_ids != vport->num_txq)
1359 return -EINVAL;
1360 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
1361 VIRTCHNL2_QUEUE_TYPE_RX,
1362 chunks);
1363 if (num_ids != vport->num_rxq)
1364 return -EINVAL;
1365 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1366 VIRTCHNL2_QUEUE_TYPE_RX);
1367 if (num_ids != vport->num_rxq)
1368 return -EINVAL;
1369
1370 if (iecm_is_queue_model_split(vport->txq_model)) {
1371 q_type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
1372 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
1373 chunks);
1374 if (num_ids != vport->num_complq)
1375 return -EINVAL;
1376 num_ids = __iecm_vport_queue_ids_init(vport, qids,
1377 num_ids,
1378 q_type);
1379 if (num_ids != vport->num_complq)
1380 return -EINVAL;
1381 }
1382
1383 if (iecm_is_queue_model_split(vport->rxq_model)) {
1384 q_type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
1385 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
1386 chunks);
1387 if (num_ids != vport->num_bufq)
1388 return -EINVAL;
1389 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1390 q_type);
1391 if (num_ids != vport->num_bufq)
1392 return -EINVAL;
1393 }
1394
1395 return 0;

Quoted 6 lines
Quoted 1 line

1396 }

1397

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org

Thanks,
Al

#27 lore raw

PATCH 6/19 iecm: add virtchnl messages for queues

In reply to Alan Brady

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:56 -0800

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 21 lines

This continues adding virtchnl messages. This largely relates to adding messages needed to negotiate and setup traffic queues.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   14 +
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  161 +++
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1127 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   22 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  196 +++
 5 files changed, 1505 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +0 -0
index e2e523f0700e..4e9cc7f2d138 100644

--- 8< ---

Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +13 -0
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport)
+{
+	int num_req_txq_desc = vport->adapter->config_data.num_req_txq_desc;
+	int num_req_rxq_desc = vport->adapter->config_data.num_req_rxq_desc;
+	int num_bufqs = vport->num_bufqs_per_qgrp;
+	int i = 0;
+
+	vport->complq_desc_count = 0;
+	if (num_req_txq_desc) {
+		vport->txq_desc_count = num_req_txq_desc;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count = num_req_txq_desc;
+			if (vport->complq_desc_count < IECM_MIN_TXQ_COMPLQ_DESC)

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+				vport->complq_desc_count =
+					IECM_MIN_TXQ_COMPLQ_DESC;
+		}
+	} else {
+		vport->txq_desc_count =
+			IECM_DFLT_TX_Q_DESC_COUNT;
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			vport->complq_desc_count =
+				IECM_DFLT_TX_COMPLQ_DESC_COUNT;
+		}

Braces are redundant here since the path is a one-liner.

drivers/net/ethernet/intel/iecm/iecm_lib.c

Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +12 -0
+	}
+
+	if (num_req_rxq_desc)
+		vport->rxq_desc_count = num_req_rxq_desc;
+	else
+		vport->rxq_desc_count = IECM_DFLT_RX_Q_DESC_COUNT;
+
+	for (i = 0; i < num_bufqs; i++) {
+		if (!vport->bufq_desc_count[i])
+			vport->bufq_desc_count[i] =
+				IECM_RX_BUFQ_DESC_COUNT(vport->rxq_desc_count,
+							num_bufqs);
		if (vport->bufq_desc_count[i])
			continue;

		vport-> ...

-1 indent level with that.

Quoted 490 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +96 -0
+	}
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_desc);
+
+/**
+ * iecm_vport_calc_total_qs - Calculate total number of queues
+ * @adapter: private data struct
+ * @vport_msg: message to fill with data
+ */
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg)
+{
+	unsigned int num_req_tx_qs = adapter->config_data.num_req_tx_qs;
+	unsigned int num_req_rx_qs = adapter->config_data.num_req_rx_qs;
+	int dflt_splitq_txq_grps, dflt_singleq_txqs;
+	int dflt_splitq_rxq_grps, dflt_singleq_rxqs;
+	int num_txq_grps, num_rxq_grps;
+	int num_cpus;
+	u16 max_q;
+
+	/* Restrict num of queues to cpus online as a default configuration to
+	 * give best performance. User can always override to a max number
+	 * of queues via ethtool.
+	 */
+	num_cpus = num_online_cpus();
+	max_q = adapter->max_queue_limit;
+
+	dflt_splitq_txq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_txqs = min_t(int, max_q, num_cpus);
+	dflt_splitq_rxq_grps = min_t(int, max_q, num_cpus);
+	dflt_singleq_rxqs = min_t(int, max_q, num_cpus);
+
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->txq_model))) {
+		num_txq_grps = num_req_tx_qs ? num_req_tx_qs : dflt_splitq_txq_grps;
+		vport_msg->num_tx_complq = cpu_to_le16(num_txq_grps *
+						       IECM_COMPLQ_PER_GROUP);
+		vport_msg->num_tx_q = cpu_to_le16(num_txq_grps *
+						  IECM_DFLT_SPLITQ_TXQ_PER_GROUP);
+	} else {
+		num_txq_grps = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;
+		vport_msg->num_tx_q =
+				cpu_to_le16(num_txq_grps *
+					    (num_req_tx_qs ? num_req_tx_qs :
+					    dflt_singleq_txqs));
+		vport_msg->num_tx_complq = 0;
+	}
+	if (iecm_is_queue_model_split(le16_to_cpu(vport_msg->rxq_model))) {
+		num_rxq_grps = num_req_rx_qs ? num_req_rx_qs : dflt_splitq_rxq_grps;
+		vport_msg->num_rx_bufq =
+					cpu_to_le16(num_rxq_grps *
+						    IECM_MAX_BUFQS_PER_RXQ_GRP);
+
+		vport_msg->num_rx_q = cpu_to_le16(num_rxq_grps *
+						  IECM_DFLT_SPLITQ_RXQ_PER_GROUP);
+	} else {
+		num_rxq_grps = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+		vport_msg->num_rx_bufq = 0;
+		vport_msg->num_rx_q =
+				cpu_to_le16(num_rxq_grps *
+					    (num_req_rx_qs ? num_req_rx_qs :
+					    dflt_singleq_rxqs));
+	}
+}
+
+/**
+ * iecm_vport_calc_num_q_groups - Calculate number of queue groups
+ * @vport: vport to calculate q groups for
+ */
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_txq_grp = vport->num_txq;
+	else
+		vport->num_txq_grp = IECM_DFLT_SINGLEQ_TX_Q_GROUPS;
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		vport->num_rxq_grp = vport->num_rxq;
+	else
+		vport->num_rxq_grp = IECM_DFLT_SINGLEQ_RX_Q_GROUPS;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_groups);
+
+/**
+ * iecm_vport_calc_num_q_vec - Calculate total number of vectors required for
+ * this vport
+ * @vport: virtual port
+ *
+ */
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport)
+{
+	if (iecm_is_queue_model_split(vport->txq_model))
+		vport->num_q_vectors = vport->num_txq_grp;
+	else
+		vport->num_q_vectors = vport->num_txq;
+}
+EXPORT_SYMBOL(iecm_vport_calc_num_q_vec);
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +362 -3
index aae06064d706..d8152e657e24 100644
@@ -859,6 +859,48 @@ static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)
 				sizeof(struct virtchnl2_get_capabilities));
 }
 
+/**
+ * iecm_get_reg_intr_vecs - Get vector queue register offset
+ * @vport: virtual port structure
+ * @reg_vals: Register offsets to store in
+ * @num_vecs: Number of vector registers
+ *
+ * Returns number of regsiters that got populated
+ */
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs)
+{
+	struct virtchnl2_vector_chunks *chunks;
+	struct iecm_vec_regs reg_val;
+	u16 num_vchunks, num_vec;
+	int num_regs = 0, i, j;
+
+	chunks = &vport->adapter->req_vec_chunks->vchunks;
+	num_vchunks = le16_to_cpu(chunks->num_vchunks);
+
+	for (j = 0; j < num_vchunks; j++) {
+		struct virtchnl2_vector_chunk *chunk = &chunks->vchunks[j];
+
+		num_vec = le16_to_cpu(chunk->num_vectors);
+		reg_val.dyn_ctl_reg = le32_to_cpu(chunk->dynctl_reg_start);
+		reg_val.itrn_reg = le32_to_cpu(chunk->itrn_reg_start);
+		for (i = 0; i < num_vec; i++) {
+			if (num_regs == num_vecs)
+				break;
+			reg_vals[i].dyn_ctl_reg = reg_val.dyn_ctl_reg;
+			reg_vals[i].itrn_reg = reg_val.itrn_reg;
+			reg_val.dyn_ctl_reg +=
+				le32_to_cpu(chunk->dynctl_reg_spacing);
+			reg_val.itrn_reg +=
+				le32_to_cpu(chunk->itrn_reg_spacing);
+			num_regs++;
+		}
+	}
+
+	return num_regs;
+}
+EXPORT_SYMBOL(iecm_get_reg_intr_vecs);
+
 /**
  * iecm_send_create_vport_msg - Send virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -869,8 +911,36 @@ static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)
  */
 static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 {
-	/* stub */
-	return 0;
+	struct virtchnl2_create_vport *vport_msg;
+	int buf_size;
+
+	buf_size = sizeof(struct virtchnl2_create_vport);
+	if (!adapter->vport_params_reqd[0]) {
+		adapter->vport_params_reqd[0] = kzalloc(buf_size, GFP_KERNEL);
+		if (!adapter->vport_params_reqd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_reqd[0];
+	vport_msg->vport_type = cpu_to_le16(VIRTCHNL2_VPORT_TYPE_DEFAULT);
+
+	if (test_bit(__IECM_REQ_TX_SPLITQ, adapter->flags))
+		vport_msg->txq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);
+	else
+		vport_msg->txq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);
+
+	if (test_bit(__IECM_REQ_RX_SPLITQ, adapter->flags))
+		vport_msg->rxq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT);
+	else
+		vport_msg->rxq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE);
+
+	adapter->dev_ops.vc_ops.init_max_queues(adapter);
+
+	iecm_vport_calc_total_qs(adapter, vport_msg);
+
+	return iecm_send_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT, buf_size,
+				(u8 *)vport_msg);
 }
 
 /**
@@ -884,7 +954,25 @@ static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 static int iecm_recv_create_vport_msg(struct iecm_adapter *adapter,
 				      int *vport_id)
 {
-	/* stub */
+	struct virtchnl2_create_vport *vport_msg;
+	int err;
+
+	if (!adapter->vport_params_recvd[0]) {
+		adapter->vport_params_recvd[0] = kzalloc(IECM_DFLT_MBX_BUF_SIZE,
+							 GFP_KERNEL);
+		if (!adapter->vport_params_recvd[0])
+			return -ENOMEM;
+	}
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			adapter->vport_params_recvd[0];
+
+	err = iecm_recv_mb_msg(adapter, VIRTCHNL2_OP_CREATE_VPORT, vport_msg,
+			       IECM_DFLT_MBX_BUF_SIZE);
+	if (err)
+		return err;
+
+	*vport_id = le32_to_cpu(vport_msg->vport_id);
 	return 0;
 }
 
@@ -966,6 +1054,920 @@ int iecm_wait_for_event(struct iecm_adapter *adapter,
 }
 EXPORT_SYMBOL(iecm_wait_for_event);
 
+/**
+ * iecm_wait_for_marker_event - wait for software marker response
+ * @vport: virtual port data structure
+ *
+ * Returns 0 success, negative on failure.
+ **/
+static int iecm_wait_for_marker_event(struct iecm_vport *vport)
+{
+	int event = 0;
+	int i;
+
+	for (i = 0; i < vport->num_txq; i++)
+		set_bit(__IECM_Q_SW_MARKER, vport->txqs[i]->flags);
+
+	event = wait_event_timeout(vport->adapter->sw_marker_wq,
+				   test_and_clear_bit(__IECM_SW_MARKER,
+						      vport->adapter->flags),
+				   msecs_to_jiffies(500));
+	if (event)
+		return 0;
+	return -ETIMEDOUT;
+}
+
+/**
+ * iecm_send_destroy_vport_msg - Send virtchnl destroy vport message
+ * @vport: virtual port data structure
+ *
+ * Send virtchnl destroy vport message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DESTROY_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DESTROY_VPORT,
+				       IECM_VC_DESTROY_VPORT_ERR);
+}
+
+/**
+ * iecm_send_enable_vport_msg - Send virtchnl enable vport message
+ * @vport: virtual port data structure
+ *
+ * Send enable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_enable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_ENABLE_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_VPORT,
+				   IECM_VC_ENA_VPORT_ERR);
+}
+
+/**
+ * iecm_send_disable_vport_msg - Send virtchnl disable vport message
+ * @vport: virtual port data structure
+ *
+ * Send disable vport virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_disable_vport_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport v_id;
+	int err;
+
+	v_id.vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DISABLE_VPORT,
+			       sizeof(v_id), (u8 *)&v_id);
+	if (err)
+		return err;
+
+	return iecm_min_wait_for_event(adapter, IECM_VC_DIS_VPORT,
+				       IECM_VC_DIS_VPORT_ERR);
+}
+
+/**
+ * iecm_send_config_tx_queues_msg - Send virtchnl config tx queues message
+ * @vport: virtual port data structure
+ *
+ * Send config tx queues virtchnl message. Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_tx_queues *ctq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_txq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_txq + vport->num_complq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_txq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+		int j;
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->txqs[j]->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->txqs[j]->dma);
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				struct iecm_queue *q = tx_qgrp->txqs[j];
+
+				qi[k].tx_compl_queue_id =
+					cpu_to_le16(tx_qgrp->complq->q_id);
+
+				if (test_bit(__IECM_Q_FLOW_SCH_EN, q->flags))
+					qi[k].sched_mode =
+					cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_FLOW);
+				else
+					qi[k].sched_mode =
+					cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);
+			} else {
+				qi[k].sched_mode =
+					cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_QUEUE);
+			}
+		}
+
+		if (iecm_is_queue_model_split(vport->txq_model)) {
+			qi[k].queue_id =
+				cpu_to_le32(tx_qgrp->complq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->txq_model);
+			qi[k].type =
+				cpu_to_le32(tx_qgrp->complq->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(tx_qgrp->complq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(tx_qgrp->complq->dma);
+			k++;
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_tx_queues);
+	chunk_size = sizeof(struct virtchnl2_txq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!ctq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(ctq);
+			ctq = kzalloc(buf_size, GFP_KERNEL);
+			if (!ctq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(ctq, 0, buf_size);
+		}
+
+		ctq->vport_id = cpu_to_le32(vport->vport_id);
+		ctq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(ctq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_TX_QUEUES,
+				       buf_size, (u8 *)ctq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter, IECM_VC_CONFIG_TXQ,
+					  IECM_VC_CONFIG_TXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}
+
+mbx_error:
+	kfree(ctq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_config_rx_queues_msg - Send virtchnl config rx queues message
+ * @vport: virtual port data structure
+ *
+ * Send config rx queues virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
+{
+	struct virtchnl2_config_rx_queues *crq = NULL;
+	int config_data_size, chunk_size, buf_size = 0;
+	int totqs, num_msgs, num_chunks;
+	struct virtchnl2_rxq_info *qi;
+	int err = 0, i, k = 0;
+	bool alloc = false;
+
+	totqs = vport->num_rxq + vport->num_bufq;
+	qi = kcalloc(totqs, sizeof(struct virtchnl2_rxq_info), GFP_KERNEL);
+	if (!qi)
+		return -ENOMEM;
+
+	/* Populate the queue info buffer with all queue context info */
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+		int j;
+
+		if (iecm_is_queue_model_split(vport->rxq_model)) {
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *bufq =
+					&rx_qgrp->splitq.bufq_sets[j].bufq;
+
+				qi[k].queue_id =
+					cpu_to_le32(bufq->q_id);
+				qi[k].model =
+					cpu_to_le16(vport->rxq_model);
+				qi[k].type =
+					cpu_to_le32(bufq->q_type);
+				qi[k].desc_ids =
+					cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);
+				qi[k].ring_len =
+					cpu_to_le16(bufq->desc_count);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1337

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+				qi[k].dma_ring_addr =
+					cpu_to_le64(bufq->dma);
+				qi[k].data_buffer_size =
+					cpu_to_le32(bufq->rx_buf_size);
+				qi[k].buffer_notif_stride =
+					bufq->rx_buf_stride;
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(bufq->rx_buffer_low_watermark);
+			}
+		}
		if (iecm_is_queue_model_split(vport->rxq_model))
			goto here;

-1 indent level for the for-loop.
Braces for 'if' are not needed since the for-loop has their own.

Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +19 -0
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				qi[k].rx_bufq1_id =
+				  cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[0].bufq.q_id);
+				qi[k].rx_bufq2_id =
+				  cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[1].bufq.q_id);
+				qi[k].hdr_buffer_size =
+					cpu_to_le16(rxq->rx_hbuf_size);
+				qi[k].rx_buffer_low_watermark =
+					cpu_to_le16(rxq->rx_buffer_low_watermark);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1366

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+				if (rxq->rx_hsplit_en) {
+					qi[k].qflags =
+						cpu_to_le16(VIRTCHNL2_RXQ_HDR_SPLIT);
+					qi[k].hdr_buffer_size =
+						cpu_to_le16(rxq->rx_hbuf_size);
+				}
+			} else {
+				rxq = rx_qgrp->singleq.rxqs[j];
+			}

Same here, but with rxq = ... + goto.

Quoted 141 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +141 -0
+
+			qi[k].queue_id =
+				cpu_to_le32(rxq->q_id);
+			qi[k].model =
+				cpu_to_le16(vport->rxq_model);
+			qi[k].type =
+				cpu_to_le32(rxq->q_type);
+			qi[k].ring_len =
+				cpu_to_le16(rxq->desc_count);
+			qi[k].dma_ring_addr =
+				cpu_to_le64(rxq->dma);
+			qi[k].max_pkt_size =
+				cpu_to_le32(rxq->rx_max_pkt_size);
+			qi[k].data_buffer_size =
+				cpu_to_le32(rxq->rx_buf_size);
+			qi[k].qflags |=
+				cpu_to_le16(VIRTCHNL2_RX_DESC_SIZE_32BYTE);
+			qi[k].desc_ids =
+				cpu_to_le64(rxq->rxdids);
+		}
+	}
+
+	/* Make sure accounting agrees */
+	if (k != totqs) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	/* Chunk up the queue contexts into multiple messages to avoid
+	 * sending a control queue message buffer that is too large
+	 */
+	config_data_size = sizeof(struct virtchnl2_config_rx_queues);
+	chunk_size = sizeof(struct virtchnl2_rxq_info);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (totqs < num_chunks)
+		num_chunks = totqs;
+
+	num_msgs = totqs / num_chunks;
+	if (totqs % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!crq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(crq);
+			crq = kzalloc(buf_size, GFP_KERNEL);
+			if (!crq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(crq, 0, buf_size);
+		}
+
+		crq->vport_id = cpu_to_le32(vport->vport_id);
+		crq->num_qinfo = cpu_to_le16(num_chunks);
+		memcpy(crq->qinfo, &qi[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter,
+				       VIRTCHNL2_OP_CONFIG_RX_QUEUES,
+				       buf_size, (u8 *)crq);
+		if (err)
+			goto mbx_error;
+
+		err = iecm_wait_for_event(vport->adapter, IECM_VC_CONFIG_RXQ,
+					  IECM_VC_CONFIG_RXQ_ERR);
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		totqs -= num_chunks;
+		if (totqs < num_chunks) {
+			num_chunks = totqs;
+			alloc = true;
+		}
+	}
+
+mbx_error:
+	kfree(crq);
+error:
+	kfree(qi);
+	return err;
+}
+
+/**
+ * iecm_send_ena_dis_queues_msg - Send virtchnl enable or disable
+ * queues message
+ * @vport: virtual port data structure
+ * @vc_op: virtchnl op code to send
+ *
+ * Send enable or disable queues virtchnl message. Returns 0 on success,
+ * negative on failure.
+ */
+static int iecm_send_ena_dis_queues_msg(struct iecm_vport *vport,
+					enum virtchnl_ops vc_op)
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	int num_txq, num_rxq, num_q, buf_size, err = 0;
+	struct virtchnl2_del_ena_dis_queues *eq = NULL;
+	struct virtchnl2_queue_chunk *qc;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	/* validate virtchnl op */
+	switch (vc_op) {
+	case VIRTCHNL2_OP_ENABLE_QUEUES:
+	case VIRTCHNL2_OP_DISABLE_QUEUES:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	num_txq = vport->num_txq + vport->num_complq;
+	num_rxq = vport->num_rxq + vport->num_bufq;
+	num_q = num_txq + num_rxq;
+	buf_size = sizeof(struct virtchnl2_queue_chunk) * (num_q);
+	qc = kzalloc(buf_size, GFP_KERNEL);
+	if (!qc)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			qc[k].type = cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		for (i = 0; i < vport->num_txq_grp; i++, k++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1517

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			qc[k].type = cpu_to_le32(tx_qgrp->complq->q_type);
+			qc[k].start_queue_id =
+					cpu_to_le32(tx_qgrp->complq->q_id);
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+		if (vport->num_complq != (k - vport->num_txq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

Quoted 38 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +38 -0
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			if (iecm_is_queue_model_split(vport->rxq_model)) {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]->rxq.q_id);
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]->rxq.q_type);
+			} else {
+				qc[k].start_queue_id =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_id);
+				qc[k].type =
+				cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_type);
+			}
+			qc[k].num_queues = cpu_to_le32(1);
+		}
+	}
+	if (vport->num_rxq != k - (vport->num_txq + vport->num_complq)) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) {
+				struct iecm_queue *q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+
+				qc[k].type = cpu_to_le32(q->q_type);
+				qc[k].start_queue_id = cpu_to_le32(q->q_id);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1565

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+				qc[k].num_queues = cpu_to_le32(1);
+			}
+		}
+		if (vport->num_bufq != k - (vport->num_txq +
+					       vport->num_complq +
+					       vport->num_rxq)) {
+			err = -EINVAL;
+			goto error;
+		}
+	}

...and here.

Quoted 116 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +116 -0
+
+	/* Chunk up the queue info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_del_ena_dis_queues);
+	chunk_size = sizeof(struct virtchnl2_queue_chunk);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!eq || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(eq);
+			eq = kzalloc(buf_size, GFP_KERNEL);
+			if (!eq) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(eq, 0, buf_size);
+		}
+		eq->vport_id = cpu_to_le32(vport->vport_id);
+		eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+		memcpy(eq->chunks.chunks, &qc[k], chunk_size * num_chunks);
+
+		err = iecm_send_mb_msg(vport->adapter, vc_op, buf_size,
+				       (u8 *)eq);
+		if (err)
+			goto mbx_error;
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}
+	}
+mbx_error:
+	kfree(eq);
+error:
+	kfree(qc);
+	return err;
+}
+
+/**
+ * iecm_send_map_unmap_queue_vector_msg - Send virtchnl map or unmap queue
+ * vector message
+ * @vport: virtual port data structure
+ * @map: true for map and false for unmap
+ *
+ * Send map or unmap queue vector virtchnl message.  Returns 0 on success,
+ * negative on failure.
+ */
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport, bool map)
+{
+	int num_msgs, num_chunks, config_data_size, chunk_size;
+	struct virtchnl2_queue_vector_maps *vqvm = NULL;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_queue_vector *vqv;
+	int buf_size, num_q, err = 0;
+	bool alloc = false;
+	int i, j, k = 0;
+
+	num_q = vport->num_txq + vport->num_rxq;
+
+	buf_size = sizeof(struct virtchnl2_queue_vector) * num_q;
+	vqv = kzalloc(buf_size, GFP_KERNEL);
+	if (!vqv)
+		return -ENOMEM;
+
+	for (i = 0; i < vport->num_txq_grp; i++) {
+		struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+		for (j = 0; j < tx_qgrp->num_txq; j++, k++) {
+			vqv[k].queue_type = cpu_to_le32(tx_qgrp->txqs[j]->q_type);
+			vqv[k].queue_id = cpu_to_le32(tx_qgrp->txqs[j]->q_id);
+
+			if (iecm_is_queue_model_split(vport->txq_model)) {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->complq->q_vector->v_idx);
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->complq->q_vector->tx_itr_idx);
+			} else {
+				vqv[k].vector_id =
+				cpu_to_le16(tx_qgrp->txqs[j]->q_vector->v_idx);
+				vqv[k].itr_idx =
+				cpu_to_le32(tx_qgrp->txqs[j]->q_vector->tx_itr_idx);
+			}
+		}
+	}
+
+	if (vport->num_txq != k) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	for (i = 0; i < vport->num_rxq_grp; i++) {
+		struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+		int num_rxq;
+
+		if (iecm_is_queue_model_split(vport->rxq_model))
+			num_rxq = rx_qgrp->splitq.num_rxq_sets;
+		else
+			num_rxq = rx_qgrp->singleq.num_rxq;
+
+		for (j = 0; j < num_rxq; j++, k++) {
+			struct iecm_queue *rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+			else
+				rxq = rx_qgrp->singleq.rxqs[j];

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1691

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+
+			vqv[k].queue_type = cpu_to_le32(rxq->q_type);
+			vqv[k].queue_id = cpu_to_le32(rxq->q_id);
+			vqv[k].vector_id = cpu_to_le16(rxq->q_vector->v_idx);
+			vqv[k].itr_idx = cpu_to_le32(rxq->q_vector->rx_itr_idx);
+		}
+	}
+
+	if (iecm_is_queue_model_split(vport->txq_model)) {
+		if (vport->num_rxq != k - vport->num_complq) {
	if (iecm_is_queue_model_split() && vport->num_rxq != ...) {

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_wait_for_event(struct iecm_adapter *adapter, · line 1252

Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4 -0
+			err = -EINVAL;
+			goto error;
+		}
+	} else {

Don't forget to convert this then into !split + ..., either with 'else' or not.

Quoted 415 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +375 -12
+		if (vport->num_rxq != k - vport->num_txq) {
+			err = -EINVAL;
+			goto error;
+		}
+	}
+
+	/* Chunk up the vector info into multiple messages */
+	config_data_size = sizeof(struct virtchnl2_queue_vector_maps);
+	chunk_size = sizeof(struct virtchnl2_queue_vector);
+
+	num_chunks = IECM_NUM_CHUNKS_PER_MSG(config_data_size, chunk_size) + 1;
+	if (num_q < num_chunks)
+		num_chunks = num_q;
+
+	num_msgs = num_q / num_chunks;
+	if (num_q % num_chunks)
+		num_msgs++;
+
+	for (i = 0, k = 0; i < num_msgs; i++) {
+		if (!vqvm || alloc) {
+			buf_size = (chunk_size * (num_chunks - 1)) +
+					config_data_size;
+			kfree(vqvm);
+			vqvm = kzalloc(buf_size, GFP_KERNEL);
+			if (!vqvm) {
+				err = -ENOMEM;
+				goto error;
+			}
+		} else {
+			memset(vqvm, 0, buf_size);
+		}
+		vqvm->vport_id = cpu_to_le32(vport->vport_id);
+		vqvm->num_qv_maps = cpu_to_le16(num_chunks);
+		memcpy(vqvm->qv_maps, &vqv[k], chunk_size * num_chunks);
+
+		if (map) {
+			err = iecm_send_mb_msg(adapter,
+					       VIRTCHNL2_OP_MAP_QUEUE_VECTOR,
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err = iecm_wait_for_event(adapter,
+							  IECM_VC_MAP_IRQ,
+							  IECM_VC_MAP_IRQ_ERR);
+		} else {
+			err = iecm_send_mb_msg(adapter,
+					       VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR,
+					       buf_size, (u8 *)vqvm);
+			if (!err)
+				err =
+				iecm_min_wait_for_event(adapter,
+							IECM_VC_UNMAP_IRQ,
+							IECM_VC_UNMAP_IRQ_ERR);
+		}
+		if (err)
+			goto mbx_error;
+
+		k += num_chunks;
+		num_q -= num_chunks;
+		if (num_q < num_chunks) {
+			num_chunks = num_q;
+			alloc = true;
+		}
+	}
+mbx_error:
+	kfree(vqvm);
+error:
+	kfree(vqv);
+	return err;
+}
+EXPORT_SYMBOL(iecm_send_map_unmap_queue_vector_msg);
+
+/**
+ * iecm_send_enable_queues_msg - send enable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send enable queues virtchnl message.  Returns 0 on success, negative on
+ * failure.
+ */
+static int iecm_send_enable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_ENABLE_QUEUES);
+	if (err)
+		return err;
+
+	return iecm_wait_for_event(adapter, IECM_VC_ENA_QUEUES,
+				   IECM_VC_ENA_QUEUES_ERR);
+}
+
+/**
+ * iecm_send_disable_queues_msg - send disable queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send disable queues virtchnl message.  Returns 0 on success, negative
+ * on failure.
+ */
+static int iecm_send_disable_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	int err;
+
+	err = iecm_send_ena_dis_queues_msg(vport,
+					   VIRTCHNL2_OP_DISABLE_QUEUES);
+	if (err)
+		return err;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DIS_QUEUES,
+				      IECM_VC_DIS_QUEUES_ERR);
+	if (err)
+		return err;
+
+	return iecm_wait_for_marker_event(vport);
+}
+
+/**
+ * iecm_convert_reg_to_queue_chunks - Copy queue chunk information to the right
+ * structure
+ * @dchunks: Destination chunks to store data to
+ * @schunks: Source chunks to copy data from
+ * @num_chunks: number of chunks to copy
+ */
+static void
+iecm_convert_reg_to_queue_chunks(struct virtchnl2_queue_chunk *dchunks,
+				 struct virtchnl2_queue_reg_chunk *schunks,
+				 u16 num_chunks)
+{
+	u16 i;
+
+	for (i = 0; i < num_chunks; i++) {
+		dchunks[i].type = schunks[i].type;
+		dchunks[i].start_queue_id = schunks[i].start_queue_id;
+		dchunks[i].num_queues = schunks[i].num_queues;
+	}
+}
+
+/**
+ * iecm_send_delete_queues_msg - send delete queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send delete queues virtchnl message. Return 0 on success, negative on
+ * failure.
+ */
+int iecm_send_delete_queues_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	struct virtchnl2_del_ena_dis_queues *eq;
+	int buf_size, err;
+	u16 num_chunks;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+			(struct virtchnl2_add_queues *)
+			vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+				vport->adapter->vport_params_recvd[0];
+		 chunks = &vport_params->chunks;
+	}
+
+	num_chunks = le16_to_cpu(chunks->num_chunks);
+	buf_size = sizeof(struct virtchnl2_del_ena_dis_queues) +
+			  (sizeof(struct virtchnl2_queue_chunk) *
+			  (num_chunks - 1));
+
+	eq = kzalloc(buf_size, GFP_KERNEL);
+	if (!eq)
+		return -ENOMEM;
+
+	eq->vport_id = cpu_to_le32(vport->vport_id);
+	eq->chunks.num_chunks = cpu_to_le16(num_chunks);
+
+	iecm_convert_reg_to_queue_chunks(eq->chunks.chunks, chunks->chunks,
+					 num_chunks);
+
+	err = iecm_send_mb_msg(vport->adapter, VIRTCHNL2_OP_DEL_QUEUES,
+			       buf_size, (u8 *)eq);
+	if (err)
+		goto error;
+
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DEL_QUEUES,
+				      IECM_VC_DEL_QUEUES_ERR);
+error:
+	kfree(eq);
+	return err;
+}
+
+/**
+ * iecm_send_config_queues_msg - Send config queues virtchnl message
+ * @vport: Virtual port private data structure
+ *
+ * Will send config queues virtchnl message. Returns 0 on success, negative on
+ * failure.
+ */
+static int iecm_send_config_queues_msg(struct iecm_vport *vport)
+{
+	int err;
+
+	err = iecm_send_config_tx_queues_msg(vport);
+	if (err)
+		return err;
+
+	return iecm_send_config_rx_queues_msg(vport);
+}
+
+/**
+ * iecm_send_add_queues_msg - Send virtchnl add queues message
+ * @vport: Virtual port private data structure
+ * @num_tx_q: number of transmit queues
+ * @num_complq: number of transmit completion queues
+ * @num_rx_q: number of receive queues
+ * @num_rx_bufq: number of receive buffer queues
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_add_queues aq = {0};
+	struct virtchnl2_add_queues *vc_msg;
+	int size, err;
+
+	vc_msg = (struct virtchnl2_add_queues *)adapter->vc_msg;
+
+	aq.vport_id = cpu_to_le32(vport->vport_id);
+	aq.num_tx_q = cpu_to_le16(num_tx_q);
+	aq.num_tx_complq = cpu_to_le16(num_complq);
+	aq.num_rx_q = cpu_to_le16(num_rx_q);
+	aq.num_rx_bufq = cpu_to_le16(num_rx_bufq);
+
+	err = iecm_send_mb_msg(adapter,
+			       VIRTCHNL2_OP_ADD_QUEUES,
+			       sizeof(struct virtchnl2_add_queues), (u8 *)&aq);
+	if (err)
+		return err;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ADD_QUEUES,
+				  IECM_VC_ADD_QUEUES_ERR);
+	if (err)
+		return err;
+
+	kfree(adapter->config_data.req_qs_chunks);
+	adapter->config_data.req_qs_chunks = NULL;
+
+	/* compare vc_msg num queues with vport num queues */
+	if (le16_to_cpu(vc_msg->num_tx_q) != num_tx_q ||
+	    le16_to_cpu(vc_msg->num_rx_q) != num_rx_q ||
+	    le16_to_cpu(vc_msg->num_tx_complq) != num_complq ||
+	    le16_to_cpu(vc_msg->num_rx_bufq) != num_rx_bufq) {
+		err = -EINVAL;
+		goto error;
+	}
+
+	size = sizeof(struct virtchnl2_add_queues) +
+			((le16_to_cpu(vc_msg->chunks.num_chunks) - 1) *
+			sizeof(struct virtchnl2_queue_reg_chunk));
+	adapter->config_data.req_qs_chunks =
+		kzalloc(size, GFP_KERNEL);
+	if (!adapter->config_data.req_qs_chunks) {
+		err = -ENOMEM;
+		goto error;
+	}
+	memcpy(adapter->config_data.req_qs_chunks,
+	       adapter->vc_msg, size);
+error:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	return err;
+}
+
 /**
  * iecm_find_ctlq - Given a type and id, find ctlq info
  * @hw: hardware struct
@@ -1217,6 +2219,13 @@ static void iecm_vport_init(struct iecm_vport *vport,
 	/*Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */
 	memcpy(vport->rx_itr_profile, rx_itr, IECM_DIM_PROFILE_SLOTS);
 	memcpy(vport->tx_itr_profile, tx_itr, IECM_DIM_PROFILE_SLOTS);
+
+	iecm_vport_set_hsplit(vport, true);
+
+	iecm_vport_init_num_qs(vport, vport_msg);
+	iecm_vport_calc_num_q_desc(vport);
+	iecm_vport_calc_num_q_groups(vport);
+	iecm_vport_calc_num_q_vec(vport);
 }
 
 /**
@@ -1316,8 +2325,82 @@ static int
 __iecm_vport_queue_ids_init(struct iecm_vport *vport, u32 *qids,
 			    int num_qids, u32 q_type)
 {
-	/* stub */
-	return 0;
+	struct iecm_queue *q;
+	int i, j, k = 0;
+
+	switch (q_type) {
+	case VIRTCHNL2_QUEUE_TYPE_TX:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			for (j = 0; j < tx_qgrp->num_txq; j++) {
+				if (k < num_qids) {
+					tx_qgrp->txqs[j]->q_id = qids[k];
+					tx_qgrp->txqs[j]->q_type =
+						VIRTCHNL2_QUEUE_TYPE_TX;
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int num_rxq;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				num_rxq = rx_qgrp->splitq.num_rxq_sets;
+			else
+				num_rxq = rx_qgrp->singleq.num_rxq;
+
+			for (j = 0; j < num_rxq && k < num_qids; j++, k++) {
+				if (iecm_is_queue_model_split(vport->rxq_model))
+					q = &rx_qgrp->splitq.rxq_sets[j]->rxq;
+				else
+					q = rx_qgrp->singleq.rxqs[j];
+				q->q_id = qids[k];
+				q->q_type = VIRTCHNL2_QUEUE_TYPE_RX;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			if (k < num_qids) {
+				tx_qgrp->complq->q_id = qids[k];
+				tx_qgrp->complq->q_type =
+					VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
+				k++;
+			} else {
+				break;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				if (k < num_qids) {
+					q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+					q->q_id = qids[k];
+					q->q_type =
+						VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
+					k++;
+				} else {
+					break;
+				}
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return k;
 }
 
 /**
@@ -1425,6 +2508,20 @@ static bool iecm_is_capability_ena(struct iecm_adapter *adapter, bool all,
 		return !!(*cap_field & flag);
 }
 
+/**
+ * iecm_get_reserved_vectors - Default implementation to get reserved vectors
+ * @adapter: Private data struct
+ *
+ * Return number of vectors reserved
+ */
+static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_get_capabilities *caps;
+
+	caps = (struct virtchnl2_get_capabilities *)adapter->caps;
+	return le16_to_cpu(caps->num_allocated_vectors);
+}
+
 /**
  * iecm_vc_ops_init - Initialize virtchnl common api
  * @adapter: Driver specific private structure
@@ -1441,16 +2538,16 @@ void iecm_vc_ops_init(struct iecm_adapter *adapter)
 	vc_ops->vport_queue_ids_init = iecm_vport_queue_ids_init;
 	vc_ops->get_caps = iecm_send_get_caps_msg;
 	vc_ops->is_cap_ena = iecm_is_capability_ena;
-	vc_ops->get_reserved_vecs = NULL;
-	vc_ops->config_queues = NULL;
-	vc_ops->enable_queues = NULL;
-	vc_ops->disable_queues = NULL;
-	vc_ops->add_queues = NULL;
-	vc_ops->delete_queues = NULL;
-	vc_ops->irq_map_unmap = NULL;
-	vc_ops->enable_vport = NULL;
-	vc_ops->disable_vport = NULL;
-	vc_ops->destroy_vport = NULL;
+	vc_ops->get_reserved_vecs = iecm_get_reserved_vectors;
+	vc_ops->config_queues = iecm_send_config_queues_msg;
+	vc_ops->enable_queues = iecm_send_enable_queues_msg;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vc_ops_init(struct iecm_adapter *adapter) · line 2553

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7 -0
+	vc_ops->disable_queues = iecm_send_disable_queues_msg;
+	vc_ops->add_queues = iecm_send_add_queues_msg;
+	vc_ops->delete_queues = iecm_send_delete_queues_msg;
+	vc_ops->irq_map_unmap = iecm_send_map_unmap_queue_vector_msg;
+	vc_ops->enable_vport = iecm_send_enable_vport_msg;
+	vc_ops->disable_vport = iecm_send_disable_vport_msg;
+	vc_ops->destroy_vport = iecm_send_destroy_vport_msg;
 	vc_ops->get_ptype = NULL;
 	vc_ops->get_set_rss_key = NULL;
 	vc_ops->get_set_rss_lut = NULL;

Forgot to mention earlier, any reason to not declare this ops as static const and just assign a pointer then? I don't see any alternations here to e.g. fill callbacks with different functions or so.

Quoted 186 lines
drivers/net/ethernet/intel/include/iecm.h +22 -0
index 994664dfe419..8dd6272db7d3 100644
@@ -432,6 +432,8 @@ struct iecm_adapter {
 	u16 num_alloc_vport;
 	u16 next_vport;		/* Next free slot in pf->vport[] - 0-based! */
 
+	u16 max_queue_limit;	/* Max number of queues user can request */
+
 	struct delayed_work init_task; /* delayed init task */
 	struct workqueue_struct *init_wq;
 	u32 mb_wait_count;
@@ -510,6 +512,12 @@ static inline bool __iecm_is_cap_ena(struct iecm_adapter *adapter, bool all,
 	return adapter->dev_ops.vc_ops.is_cap_ena(adapter, all, field, flag);
 }
 
+#define IECM_CAP_HSPLIT (\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L2   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L3   |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
+	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
+
 /**
  * iecm_is_reset_detected - check if we were reset at some point
  * @adapter: driver specific private structure
@@ -530,6 +538,8 @@ int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
 int iecm_vc_core_init(struct iecm_adapter *adapter, int *vport_id);
+int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
+			   struct iecm_vec_regs *reg_vals, int num_vecs);
 int iecm_wait_for_event(struct iecm_adapter *adapter,
 			enum iecm_vport_vc_state state,
 			enum iecm_vport_vc_state err_check);
@@ -537,6 +547,14 @@ int iecm_min_wait_for_event(struct iecm_adapter *adapter,
 			    enum iecm_vport_vc_state state,
 			    enum iecm_vport_vc_state err_check);
 int iecm_send_get_caps_msg(struct iecm_adapter *adapter);
+int iecm_send_delete_queues_msg(struct iecm_vport *vport);
+int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
+			     u16 num_complq, u16 num_rx_q, u16 num_rx_bufq);
+int iecm_send_config_tx_queues_msg(struct iecm_vport *vport);
+int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
+int iecm_send_enable_vport_msg(struct iecm_vport *vport);
+int iecm_send_disable_vport_msg(struct iecm_vport *vport);
+int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
@@ -546,7 +564,11 @@ int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     void *msg, int msg_size);
 int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 		     u16 msg_size, u8 *msg);
+void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
+int iecm_send_enable_channels_msg(struct iecm_vport *vport);
+int iecm_send_disable_channels_msg(struct iecm_vport *vport);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
+int iecm_send_map_unmap_queue_vector_msg(struct iecm_vport *vport, bool map);
 #endif /* !_IECM_H_ */
drivers/net/ethernet/intel/include/iecm_txrx.h +109 -0
index e1348011c991..448cae0bf6e7 100644
@@ -81,6 +81,22 @@
 
 #define IECM_TX_COMPLQ_CLEAN_BUDGET	256
 
+enum iecm_queue_flags_t {
+	__IECM_Q_GEN_CHK,
+	__IECM_RFLQ_GEN_CHK,
+	__IECM_Q_FLOW_SCH_EN,
+	__IECM_Q_ETF_EN,
+	__IECM_Q_SW_MARKER,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG1,
+	__IECM_Q_VLAN_TAG_LOC_L2TAG2,
+	__IECM_Q_FLAGS_NBITS,
+};
+
+struct iecm_vec_regs {
+	u32 dyn_ctl_reg;
+	u32 itrn_reg;
+};
+
 struct iecm_intr_reg {
 	u32 dyn_ctl;
 	u32 dyn_ctl_intena_m;
@@ -122,6 +138,186 @@ struct iecm_q_vector {
 	char name[IECM_INT_NAME_STR_LEN];
 };
 
+struct iecm_rx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 rsc_pkts;
+};
+
+struct iecm_tx_queue_stats {
+	u64 packets;
+	u64 bytes;
+	u64 lso_pkts;
+};
+
+union iecm_queue_stats {
+	struct iecm_rx_queue_stats rx;
+	struct iecm_tx_queue_stats tx;
+};
+
+/* queue associated with a vport */
+struct iecm_queue {
+	struct device *dev;		/* Used for DMA mapping */
+	struct iecm_vport *vport;	/* Backreference to associated vport */
+	union {
+		struct iecm_txq_group *txq_grp;
+		struct iecm_rxq_group *rxq_grp;
+	};
+	/* bufq: Used as group id, either 0 or 1, on clean Buf Q uses this
+	 *       index to determine which group of refill queues to clean.
+	 *       Bufqs are use in splitq only.
+	 * txq: Index to map between Tx Q group and hot path Tx ptrs stored in
+	 *      vport.  Used in both single Q/split Q
+	 * rxq: Index to total rxq across groups, used for skb reporting
+	 */
+	u16 idx;
+	/* Used for both Q models single and split. In split Q model relevant
+	 * only to Tx Q and Rx Q
+	 */
+	u8 __iomem *tail;
+	/* Used in both single and split Q.  In single Q, Tx Q uses tx_buf and
+	 * Rx Q uses rx_buf.  In split Q, Tx Q uses tx_buf, Rx Q uses skb, and
+	 * Buf Q uses rx_buf.
+	 */
+	union {
+		struct iecm_tx_buf *tx_buf;
+		struct {
+			struct iecm_rx_buf *buf;
+			struct iecm_dma_mem **hdr_buf;
+		} rx_buf;
+		struct sk_buff *skb;
+	};
+	u16 q_type;
+	/* Queue id(Tx/Tx compl/Rx/Bufq) */
+	u32 q_id;
+	u16 desc_count;		/* Number of descriptors */
+
+	/* Relevant in both split & single Tx Q & Buf Q*/
+	u16 next_to_use;
+	/* In split q model only relevant for Tx Compl Q and Rx Q */
+	u16 next_to_clean;	/* used in interrupt processing */
+	/* Used only for Rx. In split Q model only relevant to Rx Q */
+	u16 next_to_alloc;
+	/* Generation bit check stored, as HW flips the bit at Queue end */
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS);
+
+	union iecm_queue_stats q_stats;
+	struct u64_stats_sync stats_sync;
+
+	bool rx_hsplit_en;
+
+	u16 rx_hbuf_size;	/* Header buffer size */
+	u16 rx_buf_size;
+	u16 rx_max_pkt_size;
+	u16 rx_buf_stride;
+	u8 rx_buffer_low_watermark;
+	u64 rxdids;
+	/* Used for both Q models single and split. In split Q model relavant
+	 * only to Tx compl Q and Rx compl Q
+	 */
+	struct iecm_q_vector *q_vector;	/* Backreference to associated vector */
+	unsigned int size;		/* length of descriptor ring in bytes */
+	dma_addr_t dma;			/* physical address of ring */
+	void *desc_ring;		/* Descriptor ring memory */
+
+	u16 tx_buf_key;			/* 16 bit unique "identifier" (index)
+					 * to be used as the completion tag when
+					 * queue is using flow based scheduling
+					 */
+	u16 tx_max_bufs;		/* Max buffers that can be transmitted
+					 * with scatter-gather
+					 */
+	DECLARE_HASHTABLE(sched_buf_hash, 12);
+} ____cacheline_internodealigned_in_smp;
+
+/* Software queues are used in splitq mode to manage buffers between rxq

drivers/net/ethernet/intel/include/iecm_txrx.h struct iecm_q_vector { · line 243

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+ * producer and the bufq consumer.  These are required in order to maintain a
+ * lockless buffer management system and are strictly software only constructs.
+ */
+struct iecm_sw_queue {
+	u16 next_to_clean ____cacheline_aligned_in_smp;
+	u16 next_to_alloc ____cacheline_aligned_in_smp;
+	u16 next_to_use ____cacheline_aligned_in_smp;
+	DECLARE_BITMAP(flags, __IECM_Q_FLAGS_NBITS)
+		____cacheline_aligned_in_smp;
+	u16 *ring ____cacheline_aligned_in_smp;

This will result in this part being FIVE cachelines long for 3 * 2 + 8 + 8 = 22 bytes, i.e. 320 bytes for 22! Just making the entire structure cacheline-aligned after its declaration is enough, these ones are not even an overkill, it's an overslaughter.

Quoted 82 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +77 -0
+	u16 desc_count;
+	u16 buf_size;
+	struct device *dev;
+} ____cacheline_internodealigned_in_smp;
+
+/* Splitq only.  iecm_rxq_set associates an rxq with at an array of refillqs.
+ * Each rxq needs a refillq to return used buffers back to the respective bufq.
+ * Bufqs then clean these refillqs for buffers to give to hardware.
+ */
+struct iecm_rxq_set {
+	struct iecm_queue rxq;
+	/* refillqs assoc with bufqX mapped to this rxq */
+	struct iecm_sw_queue *refillq0;
+	struct iecm_sw_queue *refillq1;
+};
+
+/* Splitq only.  iecm_bufq_set associates a bufq to an array of refillqs.
+ * In this bufq_set, there will be one refillq for each rxq in this rxq_group.
+ * Used buffers received by rxqs will be put on refillqs which bufqs will
+ * clean to return new buffers back to hardware.
+ *
+ * Buffers needed by some number of rxqs associated in this rxq_group are
+ * managed by at most two bufqs (depending on performance configuration).
+ */
+struct iecm_bufq_set {
+	struct iecm_queue bufq;
+	/* This is always equal to num_rxq_sets in iecm_rxq_group */
+	int num_refillqs;
+	struct iecm_sw_queue *refillqs;
+};
+
+/* In singleq mode, an rxq_group is simply an array of rxqs.  In splitq, a
+ * rxq_group contains all the rxqs, bufqs and refillqs needed to
+ * manage buffers in splitq mode.
+ */
+struct iecm_rxq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	union {
+		struct {
+			int num_rxq;
+			/* store queue pointers */
+			struct iecm_queue *rxqs[IECM_LARGE_MAX_Q];
+		} singleq;
+		struct {
+			int num_rxq_sets;
+			/* store queue pointers */
+			struct iecm_rxq_set *rxq_sets[IECM_LARGE_MAX_Q];
+			struct iecm_bufq_set *bufq_sets;
+		} splitq;
+	};
+};
+
+/* Between singleq and splitq, a txq_group is largely the same except for the
+ * complq.  In splitq a single complq is responsible for handling completions
+ * for some number of txqs associated in this txq_group.
+ */
+struct iecm_txq_group {
+	struct iecm_vport *vport; /* back pointer */
+
+	int num_txq;
+	/* store queue pointers */
+	struct iecm_queue *txqs[IECM_LARGE_MAX_Q];
+
+	/* splitq only */
+	struct iecm_queue *complq;
+};
+
+struct iecm_adapter;
+
+void iecm_vport_init_num_qs(struct iecm_vport *vport,
+			    struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_desc(struct iecm_vport *vport);
+void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
+			      struct virtchnl2_create_vport *vport_msg);
+void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
+void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
 irqreturn_t
 iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0

Thanks,
Al

#32 lore raw

PATCH 7/19 iecm: finish virtchnl messages

In reply to Alan Brady

From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:57 -0800

Quoted 33 lines

This adds the rest of the needed virtchnl messages mostly related to negotiating ptypes and initializing queue registers.

---
 drivers/net/ethernet/intel/iecm/iecm_lib.c    |   21 +-
 drivers/net/ethernet/intel/iecm/iecm_txrx.c   |  226 +++-
 .../net/ethernet/intel/iecm/iecm_virtchnl.c   | 1187 ++++++++++++++++-
 drivers/net/ethernet/intel/include/iecm.h     |   36 +
 .../net/ethernet/intel/include/iecm_txrx.h    |  198 ++-
 5 files changed, 1635 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +8 -0
index 4e9cc7f2d138..aab8ee40424e 100644
@@ -10,6 +10,25 @@ const char * const iecm_vport_vc_state_str[] = {
 };
 EXPORT_SYMBOL(iecm_vport_vc_state_str);
 
+/**
+ * iecm_is_feature_ena - Determine if a particular feature is enabled
+ * @vport: vport to check
+ * @feature: netdev flag to check
+ *
+ * Returns true or false if a particular feature is enabled.
+ */
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature)

drivers/net/ethernet/intel/iecm/iecm_lib.c const char * const iecm_vport_vc_state_str[] = { · line 30

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10 -0
+{
+	bool ena;
+
+	switch (feature) {
+	default:
+		ena = vport->netdev->features & feature;
+		break;
+	}
+	return ena;
+}

This makes absolutely no sense, please rewrite to

	return vport->netdev->features & feature;

If it will be expanded later, convert it to a switch-case only then.

Quoted 298 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2 -1
+
 /**
  * iecm_cfg_hw - Initialize HW struct
  * @adapter: adapter to setup hw struct for
@@ -132,7 +151,7 @@ iecm_vport_alloc(struct iecm_adapter *adapter, int vport_id)
 	adapter->num_alloc_vport++;
 
 	/* Setup default MSIX irq handler for the vport */
-	vport->irq_q_handler = iecm_vport_intr_clean_queues;
+	vport->irq_q_handler = NULL;
 	vport->q_vector_base = IECM_NONQ_VEC;
 
 	mutex_init(&vport->stop_mutex);
drivers/net/ethernet/intel/iecm/iecm_txrx.c +212 -14
index 2dfb0be002e3..bd0cfd89bf03 100644
@@ -3,22 +3,220 @@
 
 #include "iecm.h"
 
-/**
- * iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler
- * @irq: interrupt number
- * @data: pointer to a q_vector
- *
- */
-irqreturn_t
-iecm_vport_intr_clean_queues(int __always_unused irq, void *data)
-{
-	struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data;
+const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE] = {
+	/* ptype indices are dynamic and package dependent. Indices represented
+	 * in this lookup table are for reference and will be replaced by the
+	 * values which CP sends. Also these values are static for older
+	 * versions of virtchnl and if VIRTCHNL2_CAP_PTYPE is not set in
+	 * virtchnl2_get_capabilities.
+	 */
+	/* L2 Packet types */
+	IECM_PTT_UNUSED_ENTRY(0),
+	IECM_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
+	IECM_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT_UNUSED_ENTRY(4),
+	IECM_PTT_UNUSED_ENTRY(5),
+	IECM_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT_UNUSED_ENTRY(8),
+	IECM_PTT_UNUSED_ENTRY(9),
+	IECM_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
+	IECM_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
+	IECM_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
 
-	q_vector->total_events++;
-	napi_schedule(&q_vector->napi);
+	/* Non Tunneled IPv4 */
+	IECM_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(25),
+	IECM_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
+	IECM_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
+	IECM_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
 
-	return IRQ_HANDLED;
-}
+	/* IPv4 --> IPv4 */
+	IECM_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(32),
+	IECM_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> IPv6 */
+	IECM_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(39),
+	IECM_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT */
+	IECM_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
+
+	/* IPv4 --> GRE/NAT --> IPv4 */
+	IECM_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(47),
+	IECM_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> IPv6 */
+	IECM_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(54),
+	IECM_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> MAC */
+	IECM_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
+
+	/* IPv4 --> GRE/NAT --> MAC --> IPv4 */
+	IECM_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(62),
+	IECM_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT -> MAC --> IPv6 */
+	IECM_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(69),
+	IECM_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv4 --> GRE/NAT --> MAC/VLAN */
+	IECM_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
+
+	/* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
+	IECM_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(77),
+	IECM_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
+	IECM_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(84),
+	IECM_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
+
+	/* Non Tunneled IPv6 */
+	IECM_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
+	IECM_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(91),
+	IECM_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
+	IECM_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
+	IECM_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
+
+	/* IPv6 --> IPv4 */
+	IECM_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(98),
+	IECM_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> IPv6 */
+	IECM_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(105),
+	IECM_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT */
+	IECM_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
+
+	/* IPv6 --> GRE/NAT -> IPv4 */
+	IECM_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(113),
+	IECM_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> IPv6 */
+	IECM_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(120),
+	IECM_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC */
+	IECM_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
+
+	/* IPv6 --> GRE/NAT -> MAC -> IPv4 */
+	IECM_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(128),
+	IECM_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC -> IPv6 */
+	IECM_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(135),
+	IECM_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN */
+	IECM_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
+	IECM_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
+	IECM_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
+	IECM_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(143),
+	IECM_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
+	IECM_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
+	IECM_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
+
+	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
+	IECM_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
+	IECM_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
+	IECM_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
+	IECM_PTT_UNUSED_ENTRY(150),
+	IECM_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
+	IECM_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
+	IECM_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
+
+	/* rest of the entries are unused */
+};
+EXPORT_SYMBOL(iecm_ptype_lookup);
 
 /**
  * iecm_vport_init_num_qs - Initialize number of queues
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +31 -0
index d8152e657e24..c4ae56897d1b 100644
@@ -859,6 +859,15 @@ static int iecm_recv_get_caps_msg(struct iecm_adapter *adapter)
 				sizeof(struct virtchnl2_get_capabilities));
 }
 
+/**
+ * iecm_vport_init_max_qs - Initialize max queues supported on this device
+ * @adapter: Driver specific private structure
+ */
+static void iecm_vport_init_max_qs(struct iecm_adapter *adapter)
+{
+	adapter->max_queue_limit = IECM_MAX_Q;
+}
+
 /**
  * iecm_get_reg_intr_vecs - Get vector queue register offset
  * @vport: virtual port structure
@@ -901,6 +910,199 @@ int iecm_get_reg_intr_vecs(struct iecm_vport *vport,
 }
 EXPORT_SYMBOL(iecm_get_reg_intr_vecs);
 
+/**
+ * iecm_vport_get_q_reg - Get the queue registers for the vport
+ * @reg_vals: register values needing to be set
+ * @num_regs: amount we expect to fill
+ * @q_type: queue model
+ * @chunks: queue regs received over mailbox
+ */
+static int
+iecm_vport_get_q_reg(u32 *reg_vals, int num_regs, u32 q_type,
+		     struct virtchnl2_queue_reg_chunks *chunks)
+{
+	u16 num_chunks = le16_to_cpu(chunks->num_chunks);
+	int reg_filled = 0, i;
+	u32 reg_val;
+	u16 num_q;
+
+	while (num_chunks) {
+		struct virtchnl2_queue_reg_chunk *chunk = &chunks->chunks[num_chunks - 1];
+
+		if (le32_to_cpu(chunk->type) == q_type) {
+			num_q = le32_to_cpu(chunk->num_queues);
+			reg_val = le64_to_cpu(chunk->qtail_reg_start);

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c int iecm_get_reg_intr_vecs(struct iecm_vport *vport, · line 944

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+			for (i = 0; i < num_q; i++) {
+				if (reg_filled == num_regs)
+					break;
+				reg_vals[reg_filled++] = reg_val;
+				reg_val +=
+					le32_to_cpu(chunk->qtail_reg_spacing);
+			}
+		}
+		num_chunks--;
+	}
	while (num_chunks--) {
		struct ... = ... [num_chunks];

		if (le32_to_cpu(chunk->type) != q_type)
			continue;

		...
	}

-1 indent level, -complexity.

Quoted 1,047 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1005 -0
+
+	return reg_filled;
+}
+
+/**
+ * __iecm_queue_reg_init - initialize queue registers
+ * @vport: virtual port structure
+ * @reg_vals: registers we are initializing
+ * @num_regs: how many registers there are in total
+ * @q_type: queue model
+ *
+ * Return number of queues that are initialized
+ */
+static int
+__iecm_queue_reg_init(struct iecm_vport *vport, u32 *reg_vals,
+		      int num_regs, u32 q_type)
+{
+	struct iecm_hw *hw = &vport->adapter->hw;
+	struct iecm_queue *q;
+	int i, j, k = 0;
+
+	switch (q_type) {
+	case VIRTCHNL2_QUEUE_TYPE_TX:
+		for (i = 0; i < vport->num_txq_grp; i++) {
+			struct iecm_txq_group *tx_qgrp = &vport->txq_grps[i];
+
+			for (j = 0; j < tx_qgrp->num_txq; j++) {
+				if (k == num_regs)
+					break;
+
+				tx_qgrp->txqs[j]->tail =
+				  (__force u8 __iomem *)(hw->hw_addr +
+							 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+			int num_rxq = rx_qgrp->singleq.num_rxq;
+
+			for (j = 0; j < num_rxq; j++) {
+				if (k == num_regs)
+					break;
+
+				q = rx_qgrp->singleq.rxqs[j];
+				q->tail = (__force u8 __iomem *)(hw->hw_addr +
+								 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
+		for (i = 0; i < vport->num_rxq_grp; i++) {
+			struct iecm_rxq_group *rx_qgrp = &vport->rxq_grps[i];
+
+			for (j = 0; j < vport->num_bufqs_per_qgrp; j++) {
+				if (k == num_regs)
+					break;
+
+				q = &rx_qgrp->splitq.bufq_sets[j].bufq;
+				q->tail = (__force u8 __iomem *)(hw->hw_addr +
+								 reg_vals[k]);
+				k++;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return k;
+}
+
+/**
+ * iecm_queue_reg_init - initialize queue registers
+ * @vport: virtual port structure
+ *
+ * Return 0 on success, negative on failure
+ */
+static int iecm_queue_reg_init(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport *vport_params;
+	struct virtchnl2_queue_reg_chunks *chunks;
+	int num_regs, ret = 0;
+	u32 *reg_vals;
+
+	/* We may never deal with more than 256 same type of queues */
+	reg_vals = kmalloc(sizeof(void *) * IECM_LARGE_MAX_Q,
+			   GFP_KERNEL);
+	if (!reg_vals)
+		return -ENOMEM;
+
+	if (vport->adapter->config_data.req_qs_chunks) {
+		struct virtchnl2_add_queues *vc_aq =
+		  (struct virtchnl2_add_queues *)
+		  vport->adapter->config_data.req_qs_chunks;
+		chunks = &vc_aq->chunks;
+	} else {
+		vport_params = (struct virtchnl2_create_vport *)
+			vport->adapter->vport_params_recvd[0];
+		chunks = &vport_params->chunks;
+	}
+
+	/* Initialize Tx queue tail register address */
+	num_regs = iecm_vport_get_q_reg(reg_vals, IECM_LARGE_MAX_Q,
+					VIRTCHNL2_QUEUE_TYPE_TX,
+					chunks);
+	if (num_regs < vport->num_txq) {
+		ret = -EINVAL;
+		goto free_reg_vals;
+	}
+
+	num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+					 VIRTCHNL2_QUEUE_TYPE_TX);
+	if (num_regs < vport->num_txq) {
+		ret = -EINVAL;
+		goto free_reg_vals;
+	}
+
+	/* Initialize Rx/buffer queue tail register address based on Rx queue
+	 * model
+	 */
+	if (iecm_is_queue_model_split(vport->rxq_model)) {
+		num_regs = iecm_vport_get_q_reg(reg_vals, IECM_LARGE_MAX_Q,
+						VIRTCHNL2_QUEUE_TYPE_RX_BUFFER,
+						chunks);
+		if (num_regs < vport->num_bufq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+
+		num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+						 VIRTCHNL2_QUEUE_TYPE_RX_BUFFER);
+		if (num_regs < vport->num_bufq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+	} else {
+		num_regs = iecm_vport_get_q_reg(reg_vals, IECM_LARGE_MAX_Q,
+						VIRTCHNL2_QUEUE_TYPE_RX,
+						chunks);
+		if (num_regs < vport->num_rxq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+
+		num_regs = __iecm_queue_reg_init(vport, reg_vals, num_regs,
+						 VIRTCHNL2_QUEUE_TYPE_RX);
+		if (num_regs < vport->num_rxq) {
+			ret = -EINVAL;
+			goto free_reg_vals;
+		}
+	}
+
+free_reg_vals:
+	kfree(reg_vals);
+	return ret;
+}
+
 /**
  * iecm_send_create_vport_msg - Send virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -943,6 +1145,66 @@ static int iecm_send_create_vport_msg(struct iecm_adapter *adapter)
 				(u8 *)vport_msg);
 }
 
+/**
+ * iecm_check_descs - Verify we have the descriptor support required
+ * @vport: virtual port structure
+ * @rx_desc_ids: Rx descriptor ids to check
+ * @tx_desc_ids: Tx descriptor ids to check
+ * @rxq_model: Rx queue model
+ * @txq_model: Tx queue model
+ *
+ * Returns 0 on success, negative if we didn't get sufficient descriptor
+ * support.
+ */
+int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
+		     u64 tx_desc_ids, u16 rxq_model, u16 txq_model)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+
+	if (rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+		if (!(rx_desc_ids & VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M)) {
+			dev_err(&adapter->pdev->dev, "No supported RX descriptors provided");
+			return -EINVAL;
+		}
+	} else {
+		if (!(rx_desc_ids & VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M))
+			vport->base_rxd = true;
+	}
+
+	if (txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
+#define MIN_SUPPORT_TXDID (\
+		VIRTCHNL2_TXDID_FLEX_FLOW_SCHED |\
+		VIRTCHNL2_TXDID_FLEX_TSO_CTX |\
+		VIRTCHNL2_TXDID_FLEX_DATA)
+		if ((tx_desc_ids & MIN_SUPPORT_TXDID) != MIN_SUPPORT_TXDID) {
+			dev_err(&adapter->pdev->dev, "Minimum TX descriptor support not provided");
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL(iecm_check_descs);
+
+/**
+ * iecm_get_supported_desc_ids - Get supported Rx and Tx descriptor ids
+ * @vport: virtual port structure
+ *
+ * Return 0 on success, error on failure
+ */
+static int iecm_get_supported_desc_ids(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport *vport_msg;
+
+	vport_msg = (struct virtchnl2_create_vport *)
+			vport->adapter->vport_params_recvd[0];
+	vport_msg->rx_desc_ids = cpu_to_le64(VIRTCHNL2_RXDID_1_FLEX_SPLITQ_M);
+	vport_msg->tx_desc_ids = cpu_to_le64(MIN_SUPPORT_TXDID);
+
+	return iecm_check_descs(vport, le64_to_cpu(vport_msg->rx_desc_ids),
+				le64_to_cpu(vport_msg->tx_desc_ids),
+				vport->rxq_model, vport->txq_model);
+}
+
 /**
  * iecm_recv_create_vport_msg - Receive virtchnl create vport message
  * @adapter: Driver specific private structure
@@ -1333,6 +1595,9 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
 					bufq->rx_buf_stride;
 				qi[k].rx_buffer_low_watermark =
 					cpu_to_le16(bufq->rx_buffer_low_watermark);
+				if (iecm_is_feature_ena(vport, NETIF_F_GRO_HW))
+					qi[k].qflags |=
+						cpu_to_le16(VIRTCHNL2_RXQ_RSC);
 			}
 		}
 
@@ -1361,6 +1626,9 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport)
 					qi[k].hdr_buffer_size =
 						cpu_to_le16(rxq->rx_hbuf_size);
 				}
+				if (iecm_is_feature_ena(vport, NETIF_F_GRO_HW))
+					qi[k].qflags |=
+						cpu_to_le16(VIRTCHNL2_RXQ_RSC);
 			} else {
 				rxq = rx_qgrp->singleq.rxqs[j];
 			}
@@ -1968,6 +2236,765 @@ int iecm_send_add_queues_msg(struct iecm_vport *vport, u16 num_tx_q,
 	return err;
 }
 
+/**
+ * iecm_send_alloc_vectors_msg - Send virtchnl alloc vectors message
+ * @adapter: Driver specific private structure
+ * @num_vectors: number of vectors to be allocated
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors)
+{
+	struct virtchnl2_alloc_vectors *alloc_vec;
+	struct virtchnl2_alloc_vectors ac = {0};
+	int size, err;
+
+	ac.num_vectors = cpu_to_le16(num_vectors);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_ALLOC_VECTORS,
+			       sizeof(ac), (u8 *)&ac);
+	if (err)
+		return err;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_ALLOC_VECTORS,
+				  IECM_VC_ALLOC_VECTORS_ERR);
+	if (err)
+		return err;
+
+	size = sizeof(struct virtchnl2_alloc_vectors) +
+		((num_vectors - 1) *
+		sizeof(struct virtchnl2_vector_chunk));
+
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+	adapter->req_vec_chunks = kzalloc(size, GFP_KERNEL);
+	if (!adapter->req_vec_chunks) {
+		err = -ENOMEM;
+		goto error;
+	}
+	memcpy(adapter->req_vec_chunks, adapter->vc_msg, size);
+
+	alloc_vec = adapter->req_vec_chunks;
+	if (le16_to_cpu(alloc_vec->num_vectors) < num_vectors) {
+		kfree(adapter->req_vec_chunks);
+		adapter->req_vec_chunks = NULL;
+		err = -EINVAL;
+	}
+error:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	return err;
+}
+
+/**
+ * iecm_send_dealloc_vectors_msg - Send virtchnl de allocate vectors message
+ * @adapter: Driver specific private structure
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter)
+{
+	struct virtchnl2_vector_chunks *vcs;
+	struct virtchnl2_alloc_vectors *ac;
+	int buf_size, err;
+
+	ac = adapter->req_vec_chunks;
+	vcs = &ac->vchunks;
+
+	buf_size = sizeof(struct virtchnl2_vector_chunks) +
+			((le16_to_cpu(vcs->num_vchunks) - 1) *
+			sizeof(struct virtchnl2_vector_chunk));
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_DEALLOC_VECTORS, buf_size,
+			       (u8 *)vcs);
+	if (err)
+		return err;
+	err = iecm_min_wait_for_event(adapter, IECM_VC_DEALLOC_VECTORS,
+				      IECM_VC_DEALLOC_VECTORS_ERR);
+	if (err)
+		return err;
+
+	kfree(adapter->req_vec_chunks);
+	adapter->req_vec_chunks = NULL;
+	return 0;
+}
+
+/**
+ * iecm_send_get_stats_msg - Send virtchnl get statistics message
+ * @vport: vport to get stats for
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_stats_msg(struct iecm_vport *vport)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_vport_stats *stats;
+	int err = 0;
+
+	stats = (struct virtchnl2_vport_stats *)adapter->vc_msg;
+
+	/* Don't send get_stats message if one is pending or the
+	 * link is down
+	 */
+	if (test_bit(IECM_VC_GET_STATS, adapter->vc_state) ||
+	    adapter->state <= __IECM_DOWN)
+		goto error;
+
+	stats->vport_id = cpu_to_le32(vport->vport_id);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_STATS,
+			       sizeof(stats), (u8 *)&stats);
+	if (err)
+		goto error;
+
+	err = iecm_wait_for_event(adapter, IECM_VC_GET_STATS,
+				  IECM_VC_GET_STATS_ERR);
+	if (err)
+		goto error;
+
+	vport->netstats.rx_packets = le64_to_cpu(stats->rx_unicast) +
+				     le64_to_cpu(stats->rx_multicast) +
+				     le64_to_cpu(stats->rx_broadcast);
+	vport->netstats.tx_packets = le64_to_cpu(stats->tx_unicast) +
+				     le64_to_cpu(stats->tx_multicast) +
+				     le64_to_cpu(stats->tx_broadcast);
+	vport->netstats.rx_bytes = le64_to_cpu(stats->rx_bytes);
+	vport->netstats.tx_bytes = le64_to_cpu(stats->tx_bytes);
+	vport->netstats.tx_errors = le64_to_cpu(stats->tx_errors);
+	vport->netstats.rx_dropped = le64_to_cpu(stats->rx_discards);
+	vport->netstats.tx_dropped = le64_to_cpu(stats->tx_discards);
+	vport->port_stats.vport_stats = *stats;
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+error:
+	clear_bit(__IECM_MB_STATS_PENDING, vport->adapter->flags);
+
+	return err;
+}
+
+/**
+ * iecm_send_get_set_rss_hash_msg - Send set or get rss hash message
+ * @vport: virtual port data structure
+ * @get: flag to get or set rss hash
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_set_rss_hash_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_hash rh = {0};
+	int err;
+
+	rh.vport_id = cpu_to_le32(vport->vport_id);
+	rh.ptype_groups = cpu_to_le64(adapter->rss_data.rss_hash);
+
+	if (get) {
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_RSS_HASH,
+				       sizeof(rh), (u8 *)&rh);
+		if (err)
+			return err;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_HASH,
+					  IECM_VC_GET_RSS_HASH_ERR);
+		if (err)
+			return err;
+
+		memcpy(&rh, adapter->vc_msg, sizeof(rh));
+		adapter->rss_data.rss_hash = le64_to_cpu(rh.ptype_groups);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+
+		return 0;
+	}
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_SET_RSS_HASH,
+			       sizeof(rh), (u8 *)&rh);
+	if (err)
+		return err;
+
+	return  iecm_wait_for_event(adapter, IECM_VC_SET_RSS_HASH,
+				    IECM_VC_SET_RSS_HASH_ERR);
+}
+
+/**
+ * iecm_send_get_set_rss_lut_msg - Send virtchnl get or set rss lut message
+ * @vport: virtual port data structure
+ * @get: flag to set or get rss look up table
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_set_rss_lut_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_lut *recv_rl;
+	struct virtchnl2_rss_lut *rl;
+	int buf_size, lut_buf_size;
+	int i, err = 0;
+
+	buf_size = sizeof(struct virtchnl2_rss_lut) +
+		       (sizeof(u32) * (adapter->rss_data.rss_lut_size - 1));
+	rl = kzalloc(buf_size, GFP_KERNEL);
+	if (!rl)
+		return -ENOMEM;
+
+	if (!get) {
+		rl->lut_entries = cpu_to_le16(adapter->rss_data.rss_lut_size);
+		for (i = 0; i < adapter->rss_data.rss_lut_size; i++)
+			rl->lut[i] = cpu_to_le32(adapter->rss_data.rss_lut[i]);
+	}
+	rl->vport_id = cpu_to_le32(vport->vport_id);
+
+	if (get) {
+		err = iecm_send_mb_msg(vport->adapter, VIRTCHNL2_OP_GET_RSS_LUT,
+				       buf_size, (u8 *)rl);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_LUT,
+					  IECM_VC_GET_RSS_LUT_ERR);
+		if (err)
+			goto error;
+
+		recv_rl = (struct virtchnl2_rss_lut *)adapter->vc_msg;
+		if (adapter->rss_data.rss_lut_size !=
+		    le16_to_cpu(recv_rl->lut_entries)) {
+			adapter->rss_data.rss_lut_size =
+				le16_to_cpu(recv_rl->lut_entries);
+			kfree(adapter->rss_data.rss_lut);
+
+			lut_buf_size = adapter->rss_data.rss_lut_size *
+					sizeof(u32);
+			adapter->rss_data.rss_lut = kzalloc(lut_buf_size,
+							    GFP_KERNEL);
+			if (!adapter->rss_data.rss_lut) {
+				adapter->rss_data.rss_lut_size = 0;
+				/* Leave the buffer clean */
+				memset(adapter->vc_msg, 0,
+				       IECM_DFLT_MBX_BUF_SIZE);
+				clear_bit(__IECM_VC_MSG_PENDING,
+					  adapter->flags);
+				err = -ENOMEM;
+				goto error;
+			}
+		}
+		memcpy(adapter->rss_data.rss_lut, adapter->vc_msg,
+		       adapter->rss_data.rss_lut_size);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	} else {
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_SET_RSS_LUT,
+				       buf_size, (u8 *)rl);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_SET_RSS_LUT,
+					  IECM_VC_SET_RSS_LUT_ERR);
+	}
+error:
+	kfree(rl);
+	return err;
+}
+
+/**
+ * iecm_send_get_set_rss_key_msg - Send virtchnl get or set rss key message
+ * @vport: virtual port data structure
+ * @get: flag to set or get rss look up table
+ *
+ * Returns 0 on success, negative on failure
+ */
+int iecm_send_get_set_rss_key_msg(struct iecm_vport *vport, bool get)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl2_rss_key *recv_rk;
+	struct virtchnl2_rss_key *rk;
+	int i, buf_size, err = 0;
+
+	buf_size = sizeof(struct virtchnl2_rss_key) +
+		       (sizeof(u8) * (adapter->rss_data.rss_key_size - 1));
+	rk = kzalloc(buf_size, GFP_KERNEL);
+	if (!rk)
+		return -ENOMEM;
+	rk->vport_id = cpu_to_le32(vport->vport_id);
+
+	if (get) {
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_RSS_KEY,
+				       buf_size, (u8 *)rk);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_RSS_KEY,
+					  IECM_VC_GET_RSS_KEY_ERR);
+		if (err)
+			goto error;
+
+		recv_rk = (struct virtchnl2_rss_key *)adapter->vc_msg;
+		if (adapter->rss_data.rss_key_size !=
+		    le16_to_cpu(recv_rk->key_len)) {
+			adapter->rss_data.rss_key_size =
+				min_t(u16, NETDEV_RSS_KEY_LEN,
+				      le16_to_cpu(recv_rk->key_len));
+			kfree(adapter->rss_data.rss_key);
+			adapter->rss_data.rss_key = kzalloc(adapter->rss_data.rss_key_size,
+							    GFP_KERNEL);
+			if (!adapter->rss_data.rss_key) {
+				adapter->rss_data.rss_key_size = 0;
+				/* Leave the buffer clean */
+				memset(adapter->vc_msg, 0,
+				       IECM_DFLT_MBX_BUF_SIZE);
+				clear_bit(__IECM_VC_MSG_PENDING,
+					  adapter->flags);
+				err = -ENOMEM;
+				goto error;
+			}
+		}
+		memcpy(adapter->rss_data.rss_key, adapter->vc_msg,
+		       adapter->rss_data.rss_key_size);
+		/* Leave the buffer clean for next message */
+		memset(adapter->vc_msg, 0, IECM_DFLT_MBX_BUF_SIZE);
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+	} else {
+		rk->key_len = cpu_to_le16(adapter->rss_data.rss_key_size);
+		for (i = 0; i < adapter->rss_data.rss_key_size; i++)
+			rk->key[i] = adapter->rss_data.rss_key[i];
+
+		err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_SET_RSS_KEY,
+				       buf_size, (u8 *)rk);
+		if (err)
+			goto error;
+
+		err = iecm_wait_for_event(adapter, IECM_VC_SET_RSS_KEY,
+					  IECM_VC_SET_RSS_KEY_ERR);
+	}
+error:
+	kfree(rk);
+	return err;
+}
+
+/**
+ * iecm_tpid_to_ethertype - transform from VLAN TPID to virtchnl ethertype
+ * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
+ *
+ * Return virtchnl ethertype
+ */
+static u32 iecm_tpid_to_ethertype(u16 tpid)
+{
+	switch (tpid) {
+	case ETH_P_8021Q:
+		return VIRTCHNL_VLAN_ETHERTYPE_8100;
+	case ETH_P_8021AD:
+		return VIRTCHNL_VLAN_ETHERTYPE_88A8;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_set_vlan_offload_ethertype - set ethertype for offload message
+ * @adapter: adapter structure
+ * @msg: message structure used for updating offloads
+ * @offload_op: opcode used to determine which support structure to check
+ *
+ * Return 0 on success, negative on failure.
+ */
+static int
+iecm_set_vlan_offload_ethertype(struct iecm_adapter *adapter,
+				struct virtchnl_vlan_setting *msg,
+				enum virtchnl_ops offload_op)
+{
+	struct virtchnl_vlan_supported_caps *offload_support;
+	u16 tpid = adapter->config_data.vlan_ethertype;
+	u32 vc_ethertype;
+
+	vc_ethertype = iecm_tpid_to_ethertype(tpid);
+	/* reference the correct offload support structure */
+	switch (offload_op) {
+	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
+	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
+		offload_support =
+			&adapter->vlan_caps->offloads.stripping_support;
+		break;
+	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
+	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
+		offload_support =
+			&adapter->vlan_caps->offloads.insertion_support;
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
+			offload_op);
+		return -EINVAL;
+	}
+
+	/* make sure ethertype is supported and turning feature on/off
+	 * is allowed
+	 */
+	if ((offload_support->outer & vc_ethertype) &&
+	    (offload_support->outer & VIRTCHNL_VLAN_TOGGLE)) {
+		msg->outer_ethertype_setting = vc_ethertype;
+	} else if ((offload_support->inner & vc_ethertype) &&
+		   (offload_support->inner & VIRTCHNL_VLAN_TOGGLE)) {
+		msg->inner_ethertype_setting = vc_ethertype;
+	} else {
+		dev_err(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
+			offload_op, tpid);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * iecm_send_strip_vlan_msg - Send enable/disable vlan stripping message
+ * @vport: vport structure
+ * @ena: enable or disable vlan stripping
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_send_strip_vlan_msg(struct iecm_vport *vport, bool ena)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_vlan_setting *msg;
+	enum virtchnl_ops vop;
+	int err, len;
+
+	len = sizeof(struct virtchnl_vlan_setting);
+	msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+
+	if (!msg)
+		return -ENOMEM;
+
+	msg->vport_id = vport->vport_id;
+	if (ena) {
+		vop = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2;
+		vc = IECM_VC_STRIPPING_ENA_VLAN_V2;
+		vc_err = IECM_VC_STRIPPING_ENA_VLAN_V2_ERR;
+	} else {
+		vop = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
+		vc = IECM_VC_STRIPPING_DIS_VLAN_V2;
+		vc_err = IECM_VC_STRIPPING_DIS_VLAN_V2_ERR;
+	}
+
+	err = iecm_set_vlan_offload_ethertype(adapter, msg, vop);
+	if (!err) {
+		err = iecm_send_mb_msg(adapter, vop, len, (u8 *)msg);
+		if (!err)
+			err = iecm_wait_for_event(adapter, vc, vc_err);
+	}
+
+	kfree(msg);
+
+	return err;
+}
+
+/**
+ * iecm_send_insert_vlan_msg - Send enable/disable vlan insertion message
+ * @vport: vport structure
+ * @ena: enable/disable vlan insertion
+ *
+ * Returns 0 on success, negative on failure.
+ */
+static int iecm_send_insert_vlan_msg(struct iecm_vport *vport, bool ena)
+{
+	struct iecm_adapter *adapter = vport->adapter;
+	enum iecm_vport_vc_state vc, vc_err;
+	struct virtchnl_vlan_setting *msg;
+	enum virtchnl_ops vop;
+	int err, len;
+
+	len = sizeof(struct virtchnl_vlan_setting);
+	msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+
+	if (!msg)
+		return -ENOMEM;
+
+	msg->vport_id = vport->vport_id;
+
+	if (ena) {
+		vop = VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2;
+		vc = IECM_VC_INSERTION_ENA_VLAN_V2;
+		vc_err = IECM_VC_INSERTION_ENA_VLAN_V2_ERR;
+	} else {
+		vop = VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
+		vc = IECM_VC_INSERTION_DIS_VLAN_V2;
+		vc_err = IECM_VC_INSERTION_DIS_VLAN_V2_ERR;
+	}
+
+	err = iecm_set_vlan_offload_ethertype(adapter, msg, vop);
+	if (!err) {
+		err = iecm_send_mb_msg(adapter, vop, len, (u8 *)msg);
+		if (!err)
+			err = iecm_wait_for_event(adapter, vc, vc_err);
+	}
+
+	kfree(msg);
+
+	return err;
+}
+
+/**
+ * iecm_fill_ptype_lookup - Fill L3 specific fields in ptype lookup table
+ * @ptype: ptype lookup table
+ * @pstate: state machine for ptype lookup table
+ * @ipv4: ipv4 or ipv6
+ * @frag: fragmentation allowed
+ *
+ */
+static void iecm_fill_ptype_lookup(struct iecm_rx_ptype_decoded *ptype,
+				   struct iecm_ptype_state *pstate,
+				   bool ipv4, bool frag)
+{
+	if (!pstate->outer_ip || !pstate->outer_frag) {
+		ptype->outer_ip = IECM_RX_PTYPE_OUTER_IP;
+		pstate->outer_ip = true;
+
+		if (ipv4)
+			ptype->outer_ip_ver = IECM_RX_PTYPE_OUTER_IPV4;
+		else
+			ptype->outer_ip_ver = IECM_RX_PTYPE_OUTER_IPV6;
+
+		if (frag) {
+			ptype->outer_frag = IECM_RX_PTYPE_FRAG;
+			pstate->outer_frag = true;
+		}
+	} else {
+		ptype->tunnel_type = IECM_RX_PTYPE_TUNNEL_IP_IP;
+		pstate->tunnel_state = IECM_PTYPE_TUNNEL_IP;
+
+		if (ipv4)
+			ptype->tunnel_end_prot =
+					IECM_RX_PTYPE_TUNNEL_END_IPV4;
+		else
+			ptype->tunnel_end_prot =
+					IECM_RX_PTYPE_TUNNEL_END_IPV6;
+
+		if (frag)
+			ptype->tunnel_end_frag = IECM_RX_PTYPE_FRAG;
+	}
+}
+
+/**
+ * iecm_send_get_rx_ptype_msg - Send virtchnl for ptype info
+ * @vport: virtual port data structure
+ *
+ * Returns 0 on success, negative on failure.
+ */
+int iecm_send_get_rx_ptype_msg(struct iecm_vport *vport)
+{
+	struct iecm_rx_ptype_decoded *ptype_lkup = vport->rx_ptype_lkup;
+	struct virtchnl2_get_ptype_info *get_ptype_info, *ptype_info;
+	int max_ptype, ptypes_recvd = 0, len, ptype_offset;
+	struct iecm_adapter *adapter = vport->adapter;
+	int err = 0, i, j, k = 0;
+
+	if (iecm_is_queue_model_split(vport->rxq_model))
+		max_ptype = IECM_RX_MAX_PTYPE;
+	else
+		max_ptype = IECM_RX_MAX_BASE_PTYPE;
+
+	for (i = 0; i < max_ptype; i++)
+		ptype_lkup[i] = iecm_ptype_lookup[0];
+
+	len = sizeof(struct virtchnl2_get_ptype_info);
+	get_ptype_info = kzalloc(len, GFP_KERNEL);
+	if (!get_ptype_info)
+		return -ENOMEM;
+
+	get_ptype_info->start_ptype_id = 0;
+	get_ptype_info->num_ptypes = cpu_to_le16(max_ptype);
+
+	err = iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_PTYPE_INFO,
+			       len, (u8 *)get_ptype_info);
+	if (err)
+		goto get_ptype_rel;
+
+	while (ptypes_recvd < max_ptype) {
+		err = iecm_wait_for_event(adapter, IECM_VC_GET_PTYPE_INFO,
+					  IECM_VC_GET_PTYPE_INFO_ERR);
+		if (err)
+			goto get_ptype_rel;
+
+		len = IECM_DFLT_MBX_BUF_SIZE;
+		ptype_info = kzalloc(len, GFP_KERNEL);
+		if (!ptype_info) {
+			err = -ENOMEM;
+			goto clear_vc_flag;
+		}
+
+		memcpy(ptype_info, adapter->vc_msg, len);
+
+		ptypes_recvd += le16_to_cpu(ptype_info->num_ptypes);
+		if (ptypes_recvd > max_ptype) {
+			err = -EINVAL;
+			goto ptype_rel;
+		}
+
+		ptype_offset = sizeof(struct virtchnl2_get_ptype_info) -
+						sizeof(struct virtchnl2_ptype);
+
+		for (i = 0; i < le16_to_cpu(ptype_info->num_ptypes); i++) {
+			struct iecm_ptype_state pstate = { 0 };
+			struct virtchnl2_ptype *ptype;
+			u16 id;
+
+			ptype = (struct virtchnl2_ptype *)
+					((u8 *)ptype_info + ptype_offset);
+
+			ptype_offset += IECM_GET_PTYPE_SIZE(ptype);
+			if (ptype_offset > len) {
+				err = -EINVAL;
+				goto ptype_rel;
+			}
+
+			if (le16_to_cpu(ptype->ptype_id_10) == 0xFFFF)
+				goto ptype_rel;
+
+			if (iecm_is_queue_model_split(vport->rxq_model))
+				k = le16_to_cpu(ptype->ptype_id_10);
+			else
+				k = ptype->ptype_id_8;
+
+			if (ptype->proto_id_count)
+				ptype_lkup[k].known = 1;
+
+			for (j = 0; j < ptype->proto_id_count; j++) {
+				id = le16_to_cpu(ptype->proto_id[j]);
+				switch (id) {
+				case VIRTCHNL2_PROTO_HDR_GRE:
+					if (pstate.tunnel_state ==
+							IECM_PTYPE_TUNNEL_IP) {
+						ptype_lkup[k].tunnel_type =
+						IECM_RX_PTYPE_TUNNEL_IP_GRENAT;
+						pstate.tunnel_state |=
+						IECM_PTYPE_TUNNEL_IP_GRENAT;
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_MAC:
+					ptype_lkup[k].outer_ip =
+						IECM_RX_PTYPE_OUTER_L2;
+					if (pstate.tunnel_state ==
+							IECM_TUN_IP_GRE) {
+						ptype_lkup[k].tunnel_type =
+						IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC;
+						pstate.tunnel_state |=
+						IECM_PTYPE_TUNNEL_IP_GRENAT_MAC;
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_VLAN:
+					if (pstate.tunnel_state ==
+							IECM_TUN_IP_GRE_MAC) {
+						ptype_lkup[k].tunnel_type =
+						IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN;
+						pstate.tunnel_state |=
+						IECM_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN;
+					}
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV4:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, true,
+							       false);
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV6:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, false,
+							       false);
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV4_FRAG:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, true,
+							       true);
+					break;
+				case VIRTCHNL2_PROTO_HDR_IPV6_FRAG:
+					iecm_fill_ptype_lookup(&ptype_lkup[k],
+							       &pstate, false,
+							       true);
+					break;
+				case VIRTCHNL2_PROTO_HDR_UDP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_UDP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_TCP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_TCP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_SCTP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_SCTP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_ICMP:
+					ptype_lkup[k].inner_prot =
+					IECM_RX_PTYPE_INNER_PROT_ICMP;
+					break;
+				case VIRTCHNL2_PROTO_HDR_PAY:
+					ptype_lkup[k].payload_layer =
+						IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2;
+					break;
+				case VIRTCHNL2_PROTO_HDR_ICMPV6:
+				case VIRTCHNL2_PROTO_HDR_IPV6_EH:
+				case VIRTCHNL2_PROTO_HDR_PRE_MAC:
+				case VIRTCHNL2_PROTO_HDR_POST_MAC:
+				case VIRTCHNL2_PROTO_HDR_ETHERTYPE:
+				case VIRTCHNL2_PROTO_HDR_SVLAN:
+				case VIRTCHNL2_PROTO_HDR_CVLAN:
+				case VIRTCHNL2_PROTO_HDR_MPLS:
+				case VIRTCHNL2_PROTO_HDR_MMPLS:
+				case VIRTCHNL2_PROTO_HDR_PTP:
+				case VIRTCHNL2_PROTO_HDR_CTRL:
+				case VIRTCHNL2_PROTO_HDR_LLDP:
+				case VIRTCHNL2_PROTO_HDR_ARP:
+				case VIRTCHNL2_PROTO_HDR_ECP:
+				case VIRTCHNL2_PROTO_HDR_EAPOL:
+				case VIRTCHNL2_PROTO_HDR_PPPOD:
+				case VIRTCHNL2_PROTO_HDR_PPPOE:
+				case VIRTCHNL2_PROTO_HDR_IGMP:
+				case VIRTCHNL2_PROTO_HDR_AH:
+				case VIRTCHNL2_PROTO_HDR_ESP:
+				case VIRTCHNL2_PROTO_HDR_IKE:
+				case VIRTCHNL2_PROTO_HDR_NATT_KEEP:
+				case VIRTCHNL2_PROTO_HDR_L2TPV2:
+				case VIRTCHNL2_PROTO_HDR_L2TPV2_CONTROL:
+				case VIRTCHNL2_PROTO_HDR_L2TPV3:
+				case VIRTCHNL2_PROTO_HDR_GTP:
+				case VIRTCHNL2_PROTO_HDR_GTP_EH:
+				case VIRTCHNL2_PROTO_HDR_GTPCV2:
+				case VIRTCHNL2_PROTO_HDR_GTPC_TEID:
+				case VIRTCHNL2_PROTO_HDR_GTPU:
+				case VIRTCHNL2_PROTO_HDR_GTPU_UL:
+				case VIRTCHNL2_PROTO_HDR_GTPU_DL:
+				case VIRTCHNL2_PROTO_HDR_ECPRI:
+				case VIRTCHNL2_PROTO_HDR_VRRP:
+				case VIRTCHNL2_PROTO_HDR_OSPF:
+				case VIRTCHNL2_PROTO_HDR_TUN:
+				case VIRTCHNL2_PROTO_HDR_NVGRE:
+				case VIRTCHNL2_PROTO_HDR_VXLAN:
+				case VIRTCHNL2_PROTO_HDR_VXLAN_GPE:
+				case VIRTCHNL2_PROTO_HDR_GENEVE:
+				case VIRTCHNL2_PROTO_HDR_NSH:
+				case VIRTCHNL2_PROTO_HDR_QUIC:
+				case VIRTCHNL2_PROTO_HDR_PFCP:
+				case VIRTCHNL2_PROTO_HDR_PFCP_NODE:
+				case VIRTCHNL2_PROTO_HDR_PFCP_SESSION:
+				case VIRTCHNL2_PROTO_HDR_RTP:
+				case VIRTCHNL2_PROTO_HDR_NO_PROTO:
+				default:
+					continue;
+				}
+			}
+		}
+		clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+		kfree(ptype_info);
+	}
+	kfree(get_ptype_info);
+	return 0;
+
+ptype_rel:
+	kfree(ptype_info);
+clear_vc_flag:
+	clear_bit(__IECM_VC_MSG_PENDING, adapter->flags);
+get_ptype_rel:
+	kfree(get_ptype_info);
+	return err;
+}
+
 /**
  * iecm_find_ctlq - Given a type and id, find ctlq info
  * @hw: hardware struct
@@ -2478,6 +3505,25 @@ static int iecm_vport_queue_ids_init(struct iecm_vport *vport)
 	return 0;
 }
 
+/**
+ * iecm_vport_adjust_qs - Adjust to new requested queues
+ * @vport: virtual port data struct
+ *
+ * Renegotiate queues.  Returns 0 on success, negative on failure.
+ */
+void iecm_vport_adjust_qs(struct iecm_vport *vport)
+{
+	struct virtchnl2_create_vport vport_msg;
+
+	vport_msg.txq_model = cpu_to_le16(vport->txq_model);
+	vport_msg.rxq_model = cpu_to_le16(vport->rxq_model);
+	iecm_vport_calc_total_qs(vport->adapter, &vport_msg);
+
+	iecm_vport_init_num_qs(vport, &vport_msg);
+	iecm_vport_calc_num_q_groups(vport);
+	iecm_vport_calc_num_q_vec(vport);
+}
+
 /**
  * iecm_is_capability_ena - Default implementation of capability checking
  * @adapter: Private data struct
@@ -2522,6 +3568,117 @@ static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter)
 	return le16_to_cpu(caps->num_allocated_vectors);
 }
 

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter) · line 3580

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+/**
+ * iecm_get_max_tx_bufs - Max scatter-gather TX buffers
+ * @adapter: Private data struct
+ *
+ * Return maximum number of buffers that can be used in scatter-gather before
+ * they need to be linearized for hardware.
+ */
+static unsigned int iecm_get_max_tx_bufs(struct iecm_adapter *adapter)
+{
+	return ((struct virtchnl2_get_capabilities *)adapter->caps)->max_sg_bufs_per_tx_pkt;

93-cols line here, you can introduce some interm variables to reduce the burden.

Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +16 -0
+}
+
+/**
+ * iecm_add_del_vlans - Add or delete vlan filter
+ * @vport: vport structure
+ * @add: add or delete
+ *
+ * Request that the PF add one or more VLAN filters to our VSI.
+ */
+static void iecm_add_del_vlans(struct iecm_vport *vport, bool add)
+{
+	struct virtchnl_vlan_supported_caps *filtering_support;
+	struct iecm_adapter *adapter = vport->adapter;
+	struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
+	int total_vlans = 0, num_vlans, i, len;
+	struct iecm_vlan_filter *f, *ftmp;

drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static u16 iecm_get_reserved_vectors(struct iecm_adapter *adapter) · line 3606

Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10 -0
+	struct virtchnl_vlan *vlan;
+	enum virtchnl_ops vop;
+	int err = 0;
+
+	spin_lock_bh(&adapter->vlan_list_lock);
+
+	list_for_each_entry(f, &adapter->config_data.vlan_filter_list, list) {
+		if ((add && f->add) || (!add && f->remove))
+			total_vlans++;
+	}

Braces are redundant, if-something is one command from the outer view.

Quoted 260 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +90 -15
+
+	if (!total_vlans) {
+		spin_unlock_bh(&adapter->vlan_list_lock);
+		return;
+	}
+
+	len = sizeof(struct virtchnl_vlan_filter_list_v2) +
+		(IECM_VLANS_PER_MSG * sizeof(struct virtchnl_vlan_filter));
+	vvfl_v2 = kzalloc(len, GFP_ATOMIC);
+
+	if (!vvfl_v2) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	if (add)
+		vop = VIRTCHNL_OP_ADD_VLAN_V2;
+	else
+		vop = VIRTCHNL_OP_DEL_VLAN_V2;
+
+	while (total_vlans) {
+		if (total_vlans > IECM_VLANS_PER_MSG)
+			num_vlans = IECM_VLANS_PER_MSG;
+		else
+			num_vlans = total_vlans;
+		total_vlans -= num_vlans;
+
+		len = sizeof(struct virtchnl_vlan_filter_list_v2) +
+			((num_vlans - 1) * sizeof(struct virtchnl_vlan_filter));
+		vvfl_v2->vport_id = vport->vport_id;
+		vvfl_v2->num_elements = num_vlans;
+		i = 0;
+		list_for_each_entry_safe(f, ftmp,
+					 &adapter->config_data.vlan_filter_list,
+					 list) {
+			filtering_support =
+			&adapter->vlan_caps->filtering.filtering_support;
+			if (add && f->add) {
+				/* give priority over outer if it's enabled */
+				if (filtering_support->outer)
+					vlan = &vvfl_v2->filters[i].outer;
+				else
+					vlan = &vvfl_v2->filters[i].inner;
+				vlan->tci = f->vlan.vid;
+				vlan->tpid = f->vlan.tpid;
+				i++;
+				f->add = false;
+			} else if (!add && f->remove) {
+				/* give priority over outer if it's enabled */
+				if (filtering_support->outer)
+					vlan = &vvfl_v2->filters[i].outer;
+				else
+					vlan = &vvfl_v2->filters[i].inner;
+				vlan->tci = f->vlan.vid;
+				vlan->tpid = f->vlan.tpid;
+				i++;
+				f->remove = false;
+			}
+			if (i == num_vlans)
+				break;
+		}
+		spin_unlock_bh(&adapter->vlan_list_lock);
+		iecm_send_mb_msg(adapter, vop, len, (u8 *)vvfl_v2);
+		spin_lock_bh(&adapter->vlan_list_lock);
+	}
+	spin_unlock_bh(&adapter->vlan_list_lock);
+	kfree(vvfl_v2);
+	return;
+error:
+	spin_unlock_bh(&adapter->vlan_list_lock);
+	if (err)
+		dev_err(&adapter->pdev->dev,
+			"Failed to add or del vlan filters %d", err);
+}
+
 /**
  * iecm_vc_ops_init - Initialize virtchnl common api
  * @adapter: Driver specific private structure
@@ -2548,21 +3705,21 @@ void iecm_vc_ops_init(struct iecm_adapter *adapter)
 	vc_ops->enable_vport = iecm_send_enable_vport_msg;
 	vc_ops->disable_vport = iecm_send_disable_vport_msg;
 	vc_ops->destroy_vport = iecm_send_destroy_vport_msg;
-	vc_ops->get_ptype = NULL;
-	vc_ops->get_set_rss_key = NULL;
-	vc_ops->get_set_rss_lut = NULL;
-	vc_ops->get_set_rss_hash = NULL;
-	vc_ops->adjust_qs = NULL;
-	vc_ops->add_del_vlans = NULL;
-	vc_ops->strip_vlan_msg = NULL;
-	vc_ops->insert_vlan_msg = NULL;
-	vc_ops->init_max_queues = NULL;
-	vc_ops->get_max_tx_bufs = NULL;
-	vc_ops->vportq_reg_init = NULL;
-	vc_ops->alloc_vectors = NULL;
-	vc_ops->dealloc_vectors = NULL;
-	vc_ops->get_supported_desc_ids = NULL;
-	vc_ops->get_stats_msg = NULL;
+	vc_ops->get_ptype = iecm_send_get_rx_ptype_msg;
+	vc_ops->get_set_rss_key = iecm_send_get_set_rss_key_msg;
+	vc_ops->get_set_rss_lut = iecm_send_get_set_rss_lut_msg;
+	vc_ops->get_set_rss_hash = iecm_send_get_set_rss_hash_msg;
+	vc_ops->adjust_qs = iecm_vport_adjust_qs;
+	vc_ops->add_del_vlans = iecm_add_del_vlans;
+	vc_ops->strip_vlan_msg = iecm_send_strip_vlan_msg;
+	vc_ops->insert_vlan_msg = iecm_send_insert_vlan_msg;
+	vc_ops->init_max_queues = iecm_vport_init_max_qs;
+	vc_ops->get_max_tx_bufs = iecm_get_max_tx_bufs;
+	vc_ops->vportq_reg_init = iecm_queue_reg_init;
+	vc_ops->alloc_vectors = iecm_send_alloc_vectors_msg;
+	vc_ops->dealloc_vectors = iecm_send_dealloc_vectors_msg;
+	vc_ops->get_supported_desc_ids = iecm_get_supported_desc_ids;
+	vc_ops->get_stats_msg = iecm_send_get_stats_msg;
 	vc_ops->recv_mbx_msg = NULL;
 }
 EXPORT_SYMBOL(iecm_vc_ops_init);
drivers/net/ethernet/intel/include/iecm.h +36 -0
index 8dd6272db7d3..d736db65da06 100644
@@ -346,6 +346,7 @@ struct iecm_vport {
 	int num_rxq_grp;
 	struct iecm_rxq_group *rxq_grps;
 	u32 rxq_model;
+	struct iecm_rx_ptype_decoded rx_ptype_lkup[IECM_RX_MAX_PTYPE];
 
 	struct iecm_adapter *adapter;
 	struct net_device *netdev;
@@ -382,6 +383,30 @@ enum iecm_user_flags {
 	__IECM_USER_FLAGS_NBITS,
 };
 
+#define IECM_GET_PTYPE_SIZE(p) \
+	(sizeof(struct virtchnl2_ptype) + \
+	(((p)->proto_id_count ? ((p)->proto_id_count - 1) : 0) * sizeof(u16)))
+
+#define IECM_TUN_IP_GRE (\
+	IECM_PTYPE_TUNNEL_IP |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT)
+
+#define IECM_TUN_IP_GRE_MAC (\
+	IECM_TUN_IP_GRE |\
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC)
+
+enum iecm_tunnel_state {
+	IECM_PTYPE_TUNNEL_IP                    = BIT(0),
+	IECM_PTYPE_TUNNEL_IP_GRENAT             = BIT(1),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC         = BIT(2),
+	IECM_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN    = BIT(3),
+};
+
+struct iecm_ptype_state {
+	bool outer_ip;
+	bool outer_frag;
+	u8 tunnel_state;
+};
 /* User defined configuration values */
 struct iecm_user_config_data {
 	u32 num_req_tx_qs; /* user requested TX queues through ethtool */
@@ -534,6 +559,7 @@ int iecm_probe(struct pci_dev *pdev,
 	       const struct pci_device_id __always_unused *ent,
 	       struct iecm_adapter *adapter);
 void iecm_remove(struct pci_dev *pdev);
+void iecm_vport_adjust_qs(struct iecm_vport *vport);
 int iecm_init_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_deinit_dflt_mbx(struct iecm_adapter *adapter);
 void iecm_vc_ops_init(struct iecm_adapter *adapter);
@@ -555,8 +581,15 @@ int iecm_send_config_rx_queues_msg(struct iecm_vport *vport);
 int iecm_send_enable_vport_msg(struct iecm_vport *vport);
 int iecm_send_disable_vport_msg(struct iecm_vport *vport);
 int iecm_send_destroy_vport_msg(struct iecm_vport *vport);
+int iecm_send_get_rx_ptype_msg(struct iecm_vport *vport);
+int iecm_send_get_set_rss_key_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_lut_msg(struct iecm_vport *vport, bool get);
+int iecm_send_get_set_rss_hash_msg(struct iecm_vport *vport, bool get);
+int iecm_send_dealloc_vectors_msg(struct iecm_adapter *adapter);
+int iecm_send_alloc_vectors_msg(struct iecm_adapter *adapter, u16 num_vectors);
 int iecm_vport_params_buf_alloc(struct iecm_adapter *adapter);
 void iecm_vport_params_buf_rel(struct iecm_adapter *adapter);
+int iecm_send_get_stats_msg(struct iecm_vport *vport);
 int iecm_get_vec_ids(struct iecm_adapter *adapter,
 		     u16 *vecids, int num_vecids,
 		     struct virtchnl2_vector_chunks *chunks);
@@ -567,6 +600,9 @@ int iecm_send_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op,
 void iecm_vport_set_hsplit(struct iecm_vport *vport, bool ena);
 int iecm_send_enable_channels_msg(struct iecm_vport *vport);
 int iecm_send_disable_channels_msg(struct iecm_vport *vport);
+bool iecm_is_feature_ena(struct iecm_vport *vport, netdev_features_t feature);
+int iecm_check_descs(struct iecm_vport *vport, u64 rx_desc_ids,
+		     u64 tx_desc_ids, u16 rxq_model, u16 txq_model);
 int iecm_set_msg_pending(struct iecm_adapter *adapter,
 			 struct iecm_ctlq_msg *ctlq_msg,
 			 enum iecm_vport_vc_state err_enum);
drivers/net/ethernet/intel/include/iecm_txrx.h +50 -1
index 448cae0bf6e7..9f3086bfe575 100644
@@ -4,6 +4,9 @@
 #ifndef _IECM_TXRX_H_
 #define _IECM_TXRX_H_
 
+#include "virtchnl_lan_desc.h"
+#include <linux/indirect_call_wrapper.h>
+
 #define IECM_LARGE_MAX_Q			256
 #define IECM_MAX_Q				16
 /* Mailbox Queue */
@@ -77,9 +80,200 @@
 #define IECM_MAX_RXBUFFER			9728
 #define IECM_MAX_MTU		\
 	(IECM_MAX_RXBUFFER - IECM_PACKET_HDR_PAD)
-#define IECM_INT_NAME_STR_LEN	(IFNAMSIZ + 16)
+
+#define MAKEMASK(m, s)	((m) << (s))
+
+/* Checksum offload bits decoded from the receive descriptor. */
+struct iecm_rx_csum_decoded {
+	u8 l3l4p : 1;
+	u8 ipe : 1;
+	u8 eipe : 1;
+	u8 eudpe : 1;
+	u8 ipv6exadd : 1;
+	u8 l4e : 1;
+	u8 pprs : 1;
+	u8 nat : 1;
+	u8 rsc : 1;
+	u8 raw_csum_inv : 1;
+	u16 raw_csum;
+};
+
+struct iecm_rx_extracted {
+	unsigned int size;
+	u16 vlan_tag;
+	u16 rx_ptype;
+};
 
 #define IECM_TX_COMPLQ_CLEAN_BUDGET	256
+#define IECM_TX_MIN_LEN			17
+#define IECM_TX_DESCS_FOR_SKB_DATA_PTR	1
+#define IECM_TX_MAX_BUF			8
+#define IECM_TX_DESCS_PER_CACHE_LINE	4
+#define IECM_TX_DESCS_FOR_CTX		1
+/* TX descriptors needed, worst case */
+#define IECM_TX_DESC_NEEDED (MAX_SKB_FRAGS + IECM_TX_DESCS_FOR_CTX + \
+			     IECM_TX_DESCS_PER_CACHE_LINE + \
+			     IECM_TX_DESCS_FOR_SKB_DATA_PTR)
+
+/* The size limit for a transmit buffer in a descriptor is (16K - 1).
+ * In order to align with the read requests we will align the value to
+ * the nearest 4K which represents our maximum read request size.
+ */
+#define IECM_TX_MAX_READ_REQ_SIZE	4096
+#define IECM_TX_MAX_DESC_DATA		(16 * 1024 - 1)
+#define IECM_TX_MAX_DESC_DATA_ALIGNED \
+	(~(IECM_TX_MAX_READ_REQ_SIZE - 1) & IECM_TX_MAX_DESC_DATA)
+
+#define IECM_RX_DMA_ATTR \
+	(DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
+#define IECM_RX_DESC(R, i)	\
+	(&(((union virtchnl2_rx_desc *)((R)->desc_ring))[i]))
+

drivers/net/ethernet/intel/include/iecm_txrx.h line 141

Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10 -0
+struct iecm_page_info {
+	dma_addr_t dma;
+	struct page *page;
+	unsigned int page_offset;
+	u16 pagecnt_bias;
+};
+
+struct iecm_rx_buf {
+#define IECM_RX_BUF_MAX_PAGES 2
+	struct iecm_page_info page_info[IECM_RX_BUF_MAX_PAGES];

As I said previously, it will most likely be rejected upstream. They will either suggest using compounds or page_pool (it uses compounds for non-zero-order pages) or maybe introduce folio support to the networking stack or so, but not such stuff.

Quoted 147 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +135 -2
+	u8 page_indx;
+	u16 buf_id;
+	u16 buf_size;
+	struct sk_buff *skb;
+};
+
+/* Packet type non-ip values */
+enum iecm_rx_ptype_l2 {
+	IECM_RX_PTYPE_L2_RESERVED	= 0,
+	IECM_RX_PTYPE_L2_MAC_PAY2	= 1,
+	IECM_RX_PTYPE_L2_TIMESYNC_PAY2	= 2,
+	IECM_RX_PTYPE_L2_FIP_PAY2	= 3,
+	IECM_RX_PTYPE_L2_OUI_PAY2	= 4,
+	IECM_RX_PTYPE_L2_MACCNTRL_PAY2	= 5,
+	IECM_RX_PTYPE_L2_LLDP_PAY2	= 6,
+	IECM_RX_PTYPE_L2_ECP_PAY2	= 7,
+	IECM_RX_PTYPE_L2_EVB_PAY2	= 8,
+	IECM_RX_PTYPE_L2_QCN_PAY2	= 9,
+	IECM_RX_PTYPE_L2_EAPOL_PAY2	= 10,
+	IECM_RX_PTYPE_L2_ARP		= 11,
+};
+
+enum iecm_rx_ptype_outer_ip {
+	IECM_RX_PTYPE_OUTER_L2	= 0,
+	IECM_RX_PTYPE_OUTER_IP	= 1,
+};
+
+enum iecm_rx_ptype_outer_ip_ver {
+	IECM_RX_PTYPE_OUTER_NONE	= 0,
+	IECM_RX_PTYPE_OUTER_IPV4	= 1,
+	IECM_RX_PTYPE_OUTER_IPV6	= 2,
+};
+
+enum iecm_rx_ptype_outer_fragmented {
+	IECM_RX_PTYPE_NOT_FRAG	= 0,
+	IECM_RX_PTYPE_FRAG	= 1,
+};
+
+enum iecm_rx_ptype_tunnel_type {
+	IECM_RX_PTYPE_TUNNEL_NONE		= 0,
+	IECM_RX_PTYPE_TUNNEL_IP_IP		= 1,
+	IECM_RX_PTYPE_TUNNEL_IP_GRENAT		= 2,
+	IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC	= 3,
+	IECM_RX_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN	= 4,
+};
+
+enum iecm_rx_ptype_tunnel_end_prot {
+	IECM_RX_PTYPE_TUNNEL_END_NONE	= 0,
+	IECM_RX_PTYPE_TUNNEL_END_IPV4	= 1,
+	IECM_RX_PTYPE_TUNNEL_END_IPV6	= 2,
+};
+
+enum iecm_rx_ptype_inner_prot {
+	IECM_RX_PTYPE_INNER_PROT_NONE		= 0,
+	IECM_RX_PTYPE_INNER_PROT_UDP		= 1,
+	IECM_RX_PTYPE_INNER_PROT_TCP		= 2,
+	IECM_RX_PTYPE_INNER_PROT_SCTP		= 3,
+	IECM_RX_PTYPE_INNER_PROT_ICMP		= 4,
+	IECM_RX_PTYPE_INNER_PROT_TIMESYNC	= 5,
+};
+
+enum iecm_rx_ptype_payload_layer {
+	IECM_RX_PTYPE_PAYLOAD_LAYER_NONE	= 0,
+	IECM_RX_PTYPE_PAYLOAD_LAYER_PAY2	= 1,
+	IECM_RX_PTYPE_PAYLOAD_LAYER_PAY3	= 2,
+	IECM_RX_PTYPE_PAYLOAD_LAYER_PAY4	= 3,
+};
+
+struct iecm_rx_ptype_decoded {
+	u32 ptype:10;
+	u32 known:1;
+	u32 outer_ip:1;
+	u32 outer_ip_ver:2;
+	u32 outer_frag:1;
+	u32 tunnel_type:3;
+	u32 tunnel_end_prot:2;
+	u32 tunnel_end_frag:1;
+	u32 inner_prot:4;
+	u32 payload_layer:3;
+};
+
+enum iecm_rx_hsplit {
+	IECM_RX_NO_HDR_SPLIT = 0,
+	IECM_RX_HDR_SPLIT = 1,
+};
+
+/* The iecm_ptype_lkup table is used to convert from the 10-bit ptype in the
+ * hardware to a bit-field that can be used by SW to more easily determine the
+ * packet type.
+ *
+ * Macros are used to shorten the table lines and make this table human
+ * readable.
+ *
+ * We store the PTYPE in the top byte of the bit field - this is just so that
+ * we can check that the table doesn't have a row missing, as the index into
+ * the table should be the PTYPE.
+ *
+ * Typical work flow:
+ *
+ * IF NOT iecm_ptype_lkup[ptype].known
+ * THEN
+ *      Packet is unknown
+ * ELSE IF iecm_ptype_lkup[ptype].outer_ip == IECM_RX_PTYPE_OUTER_IP
+ *      Use the rest of the fields to look at the tunnels, inner protocols, etc
+ * ELSE
+ *      Use the enum iecm_rx_ptype_l2 to decode the packet type
+ * ENDIF
+ */
+/* macro to make the table lines short */
+#define IECM_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
+	{	PTYPE, \
+		1, \
+		IECM_RX_PTYPE_OUTER_##OUTER_IP, \
+		IECM_RX_PTYPE_OUTER_##OUTER_IP_VER, \
+		IECM_RX_PTYPE_##OUTER_FRAG, \
+		IECM_RX_PTYPE_TUNNEL_##T, \
+		IECM_RX_PTYPE_TUNNEL_END_##TE, \
+		IECM_RX_PTYPE_##TEF, \
+		IECM_RX_PTYPE_INNER_PROT_##I, \
+		IECM_RX_PTYPE_PAYLOAD_LAYER_##PL }
+
+#define IECM_PTT_UNUSED_ENTRY(PTYPE) { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+
+/* shorter macros makes the table fit but are terse */
+#define IECM_RX_PTYPE_NOF		IECM_RX_PTYPE_NOT_FRAG
+#define IECM_RX_PTYPE_FRG		IECM_RX_PTYPE_FRAG
+#define IECM_RX_PTYPE_INNER_PROT_TS	IECM_RX_PTYPE_INNER_PROT_TIMESYNC
+#define IECM_RX_SUPP_PTYPE		18
+#define IECM_RX_MAX_PTYPE		1024
+#define IECM_RX_MAX_BASE_PTYPE		256
+
+#define IECM_INT_NAME_STR_LEN	(IFNAMSIZ + 16)
+
+/* Lookup table mapping the HW PTYPE to the bit field for decoding */
+extern const struct iecm_rx_ptype_decoded iecm_ptype_lookup[IECM_RX_MAX_PTYPE];
 
 enum iecm_queue_flags_t {
 	__IECM_Q_GEN_CHK,
@@ -318,6 +512,4 @@ void iecm_vport_calc_total_qs(struct iecm_adapter *adapter,
 			      struct virtchnl2_create_vport *vport_msg);
 void iecm_vport_calc_num_q_groups(struct iecm_vport *vport);
 void iecm_vport_calc_num_q_vec(struct iecm_vport *vport);
-irqreturn_t
-iecm_vport_intr_clean_queues(int __always_unused irq, void *data);
 #endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0

Thanks,
Al