Skip to contentSkip to conversation

octeontx2-pf: Add network driver for physical function

PATCH Superseded [email protected] 3 participants 36 messages Jan 21, 2020 – Jan 24, 2020

Subsystems (5)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover octeontx2-pf: Add network driver for physical function

From: Sunil Goutham <[email protected]>

OcteonTX2 SOC's resource virtualization unit (RVU) supports multiple physical and virtual functions. Each of the PF's functionality is determined by what kind of resources are attached to it. If NPA and NIX blocks are attached to a PF it can function as a highly capable network device.

This patch series add a network driver for the PF. Initial set of patches adds mailbox communication with admin function (RVU AF) and configuration of queues. Followed by Rx and tx pkts NAPI handler and then support for HW offloads like RSS, TSO, Rxhash etc. Ethtool support to extract stats, config RSS, queue sizes, queue count is also added.

Added documentation to give a high level overview of HW and different drivers which will be upstreamed and how they interact.

Changes from v3:
* Fixed receive side scaling reinitialization during interface DOWN and UP to retain user configured settings, if any.
* Removed driver version from ethtool.
* Fixed otx2_set_rss_hash_opts() to return error incase RSS is not enabled.
- Sugested by Jakub Kicinski

Changes from v2:
* Removed frames, bytes, dropped packet stats from ethtool to avoid duplication of same stats in netlink and ethtool.
- Sugested by Jakub Kicinski
* Removed number of channels and ringparam upper bound checking in ethtool support.
* Fixed RSS hash option setting to reject unsupported config.
- Suggested by Michal Kubecek

Changes from v1:
* Made driver dependent on 64bit, to fix build errors related to non availability of writeq/readq APIs for 32bit platforms.
- Reported by kbuild test robot

Christina Jacob (1):
octeontx2-pf: Add basic ethtool support

Geetha sowjanya (2):
octeontx2-pf: Error handling support
octeontx2-pf: Add ndo_get_stats64

Linu Cherian (1):
octeontx2-pf: Register and handle link notifications

Sunil Goutham (13):
octeontx2-pf: Add Marvell OcteonTX2 NIC driver
octeontx2-pf: Mailbox communication with AF
octeontx2-pf: Attach NIX and NPA block LFs
octeontx2-pf: Initialize and config queues
octeontx2-pf: Setup interrupts and NAPI handler
octeontx2-pf: Receive packet handling support
octeontx2-pf: Add packet transmission support
octeontx2-pf: MTU, MAC and RX mode config support
octeontx2-pf: Receive side scaling support
octeontx2-pf: TCP segmentation offload support
octeontx2-pf: ethtool RSS config support
Documentation: net: octeontx2: Add RVU HW and drivers overview
MAINTAINERS: Add entry for Marvell OcteonTX2 Physical Function driver

 Documentation/networking/device_drivers/index.rst  |    1 +
 .../device_drivers/marvell/octeontx2.rst           |  159 +++
 MAINTAINERS                                        |   10 +
 drivers/net/ethernet/marvell/octeontx2/Kconfig     |    8 +
 drivers/net/ethernet/marvell/octeontx2/Makefile    |    2 +
 drivers/net/ethernet/marvell/octeontx2/af/common.h |    9 +-
 drivers/net/ethernet/marvell/octeontx2/af/mbox.h   |    8 +-
 .../net/ethernet/marvell/octeontx2/af/rvu_nix.c    |   17 +
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   10 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 1416 ++++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  615 +++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  |  662 +++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 1361 +++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_reg.h  |  147 ++
 .../ethernet/marvell/octeontx2/nic/otx2_struct.h   |  439 ++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |  863 ++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |  162 +++
 17 files changed, 5886 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/networking/device_drivers/marvell/octeontx2.rst
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/Makefile
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v4 1/17 octeontx2-pf: Add Marvell OcteonTX2 NIC driver

From: Sunil Goutham <[email protected]>

This patch adds template for the Marvell's OcteonTX2 network controller's physical function driver. Just the probe, PCI specific initialization and netdev registration.

---
 drivers/net/ethernet/marvell/octeontx2/Kconfig     |   8 +
 drivers/net/ethernet/marvell/octeontx2/Makefile    |   2 +
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |  10 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  77 ++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 220 +++++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_reg.h  |  51 +++++
 6 files changed, 368 insertions(+)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/Makefile
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h
drivers/net/ethernet/marvell/octeontx2/Kconfig +8 -0
index fb34fbd..ced514c 100644
@@ -25,3 +25,11 @@ config NDC_DIS_DYNAMIC_CACHING
 	  This config option disables caching of dynamic entries such as NIX SQEs
 	  , NPA stack pages etc in NDC. Also locks down NIX SQ/CQ/RQ/RSS and
 	  NPA Aura/Pool contexts.
+
+config OCTEONTX2_PF
+	tristate "Marvell OcteonTX2 NIC Physical Function driver"
+	select OCTEONTX2_MBOX
+	depends on (64BIT && COMPILE_TEST) || ARM64
+	depends on PCI
+	help
+	  This driver supports Marvell's OcteonTX2 NIC physical function.
drivers/net/ethernet/marvell/octeontx2/Makefile +2 -0
index e579dcd..0064a69 100644
@@ -3,4 +3,6 @@
 # Makefile for Marvell OcteonTX2 device drivers.
 #
 
+obj-$(CONFIG_OCTEONTX2_MBOX) += af/
 obj-$(CONFIG_OCTEONTX2_AF) += af/
+obj-$(CONFIG_OCTEONTX2_PF) += nic/
drivers/net/ethernet/marvell/octeontx2/nic/Makefile new file +10 -0
new file mode 100644
index 0000000..622b803
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for Marvell's OcteonTX2 ethernet device drivers
+#
+
+obj-$(CONFIG_OCTEONTX2_PF) += octeontx2_nicpf.o
+
+octeontx2_nicpf-y := otx2_pf.o
+
+ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h new file +77 -0

77 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c new file +220 -0

220 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH v4 01/17] octeontx2-pf: Add Marvell OcteonTX2 NIC driver

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c line 122

Quoted 11 lines · On Tue, 21 Jan 2020 18:51:35 +0530, [email protected] wrote:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c new file +11 -0
+	err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48));
+	if (err) {
+		dev_err(dev, "Unable to set DMA mask\n");
+		goto err_release_regions;
+	}
+
+	err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48));
+	if (err) {
+		dev_err(dev, "Unable to set consistent DMA mask\n");
+		goto err_release_regions;
+	}

please convert to using dma_set_mask_and_coherent()

#3 lore raw

PATCH v4 2/17 octeontx2-pf: Mailbox communication with AF

In reply to [email protected]

From: Sunil Goutham <[email protected]>

In the resource virtualization unit (RVU) each of the PF and AF (admin function) share a 64KB of reserved memory region for communication. This patch initializes PF <=> AF mailbox IRQs, registers handlers for processing these communication messages. Also adds support to process these messages in both directions ie responses to PF initiated DOWN (PF => AF) messages and AF initiated UP messages (AF => PF).

Mbox communication APIs and message formats are defined in AF driver (drivers/net/ethernet/marvell/octeontx2/af), mbox.h from AF driver is included here to avoid duplication.

---
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  28 ++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   | 166 ++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 359 ++++++++++++++++++++-
 4 files changed, 552 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +1 -1
index 622b803..339fde8 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_OCTEONTX2_PF) += octeontx2_nicpf.o
 
-octeontx2_nicpf-y := otx2_pf.o
+octeontx2_nicpf-y := otx2_pf.o otx2_common.o
 
 ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c new file +28 -0
new file mode 100644
index 0000000..cbab325
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Marvell OcteonTx2 RVU Ethernet driver
+ *
+ * Copyright (C) 2020 Marvell International Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/pci.h>
+
+#include "otx2_reg.h"
+#include "otx2_common.h"
+
+#define M(_name, _id, _fn_name, _req_type, _rsp_type)			\
+int __weak								\
+otx2_mbox_up_handler_ ## _fn_name(struct otx2_nic *pfvf,		\
+				struct _req_type *req,			\
+				struct _rsp_type *rsp)			\
+{									\
+	/* Nothing to do here */					\
+	return 0;							\
+}									\
+EXPORT_SYMBOL(otx2_mbox_up_handler_ ## _fn_name);
+MBOX_UP_CGX_MESSAGES
+#undef M
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +166 -0

194 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +357 -2

404 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#4 lore raw

Re: [PATCH v4 02/17] octeontx2-pf: Mailbox communication with AF

Quoted 14 lines · On Tue, 21 Jan 2020 18:51:36 +0530, [email protected] wrote:

From: Sunil Goutham <[email protected]>

In the resource virtualization unit (RVU) each of the PF and AF (admin function) share a 64KB of reserved memory region for communication. This patch initializes PF <=> AF mailbox IRQs, registers handlers for processing these communication messages. Also adds support to process these messages in both directions ie responses to PF initiated DOWN (PF => AF) messages and AF initiated UP messages (AF => PF).

Mbox communication APIs and message formats are defined in AF driver (drivers/net/ethernet/marvell/octeontx2/af), mbox.h from AF driver is included here to avoid duplication.

Quoted 7 lines

+struct mbox {

         ^^

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h line 36

Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +8 -0
+	struct otx2_mbox	mbox;
+	struct work_struct	mbox_wrk;
+	struct otx2_mbox	mbox_up;
+	struct work_struct	mbox_up_wrk;
+	struct otx2_nic		*pfvf;
+	void			*bbuf_base; /* Bounce buffer for mbox memory */
+	struct mutex		lock;	/* serialize mailbox access */
+	int			num_msgs; /*mbox number of messages*/

^ ^

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h line 37

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
+	int			up_num_msgs;/* mbox_up number of messages*/

^ ^

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h line 46

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +3 -0
+};
 
 struct otx2_hw {
 	struct pci_dev		*pdev;
 	u16                     rx_queues;
 	u16                     tx_queues;
 	u16			max_queues;
+
+	/* MSI-X*/
                ^

The white space here is fairly loose

Quoted 15 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +12 -0
+	char			*irq_name;
+	cpumask_var_t           *affinity_mask;
 };
 
 
+static inline void otx2_sync_mbox_bbuf(struct otx2_mbox *mbox, int devid)
+{
+	u16 msgs_offset = ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
+	void *hw_mbase = mbox->hwbase + (devid * MBOX_SIZE);
+	struct otx2_mbox_dev *mdev = &mbox->dev[devid];
+	struct mbox_hdr *hdr;
+	u64 msg_size;
+
+	if (mdev->mbase == hw_mbase)
+		return;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h static inline u64 otx2_read64(struct otx2_nic *nic, u64 offset) · line 146

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +10 -0
+
+	hdr = hw_mbase + mbox->rx_start;
+	msg_size = hdr->msg_size;
+
+	if (msg_size > mbox->rx_size - msgs_offset)
+		msg_size = mbox->rx_size - msgs_offset;
+
+	/* Copy mbox messages from mbox memory to bounce buffer */
+	memcpy(mdev->mbase + mbox->rx_start,
+	       hw_mbase + mbox->rx_start, msg_size + msgs_offset);

I'm slightly concerned about the use of non-iomem helpers like memset and memcpy on what I understand to be IOMEM, and the lack of memory barriers. But then again, I don't know much about iomem_wc(), is this code definitely correct from memory ordering perspective? (The memory barrier in otx2_mbox_msg_send() should probably be just wmb(), syncing with HW is unrelated with SMP.)

#5 lore raw

Re: [PATCH v4 02/17] octeontx2-pf: Mailbox communication with AF

Quoted 23 lines · Jakub Kicinski
Quoted 21 lines · On Tue, 21 Jan 2020 18:51:36 +0530, [email protected] wrote:

From: Sunil Goutham <[email protected]>

In the resource virtualization unit (RVU) each of the PF and AF (admin function) share a 64KB of reserved memory region for communication. This patch initializes PF <=> AF mailbox IRQs, registers handlers for processing these communication messages. Also adds support to process these messages in both directions ie responses to PF initiated DOWN (PF => AF) messages and AF initiated UP messages (AF => PF).

Mbox communication APIs and message formats are defined in AF driver (drivers/net/ethernet/marvell/octeontx2/af), mbox.h from AF driver is included here to avoid duplication.

Quoted 7 lines

Review

Quoted 3 lines

struct otx2_hw {

(quoted diff) +2 -0
+
+     /* MSI-X*/
                ^

The white space here is fairly loose

Will fix the white space issues.

Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +19 -0
+static inline void otx2_sync_mbox_bbuf(struct otx2_mbox *mbox, int devid)
+{
+     u16 msgs_offset = ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
+     void *hw_mbase = mbox->hwbase + (devid * MBOX_SIZE);
+     struct otx2_mbox_dev *mdev = &mbox->dev[devid];
+     struct mbox_hdr *hdr;
+     u64 msg_size;
+
+     if (mdev->mbase == hw_mbase)
+             return;
+
+     hdr = hw_mbase + mbox->rx_start;
+     msg_size = hdr->msg_size;
+
+     if (msg_size > mbox->rx_size - msgs_offset)
+             msg_size = mbox->rx_size - msgs_offset;
+
+     /* Copy mbox messages from mbox memory to bounce buffer */
+     memcpy(mdev->mbase + mbox->rx_start,
Quoted 8 lines
Quoted 1 line

+ hw_mbase + mbox->rx_start, msg_size + msgs_offset);

I'm slightly concerned about the use of non-iomem helpers like memset and memcpy on what I understand to be IOMEM, and the lack of memory barriers. But then again, I don't know much about iomem_wc(), is this code definitely correct from memory ordering perspective? (The memory barrier in otx2_mbox_msg_send() should probably be just wmb(), syncing with HW is unrelated with SMP.)

The mailbox region is a normal memory which is exposed to two devices via PCI BARs.
And the writeq() call (to trigger IRQ) inside otx2_mbox_msg_send() has a wmb().

Thanks,
Sunil.

maintainer
#6 lore raw

Re: [PATCH v4 02/17] octeontx2-pf: Mailbox communication with AF

Quoted 10 lines · Sunil Kovvuri
Quoted 6 lines

I'm slightly concerned about the use of non-iomem helpers like memset and memcpy on what I understand to be IOMEM, and the lack of memory barriers. But then again, I don't know much about iomem_wc(), is this code definitely correct from memory ordering perspective? (The memory barrier in otx2_mbox_msg_send() should probably be just wmb(), syncing with HW is unrelated with SMP.)

The mailbox region is a normal memory which is exposed to two devices via PCI BARs.
And the writeq() call (to trigger IRQ) inside otx2_mbox_msg_send() has a wmb().

Oka, fine, if it works it works, I guess.

#7 lore raw

Re: [PATCH v4 02/17] octeontx2-pf: Mailbox communication with AF

In reply to [email protected]
Quoted 164 lines · On Tue, Jan 21, 2020 at 06:51:36PM +0530, [email protected] wrote:

From: Sunil Goutham <[email protected]>

In the resource virtualization unit (RVU) each of the PF and AF (admin function) share a 64KB of reserved memory region for communication. This patch initializes PF <=> AF mailbox IRQs, registers handlers for processing these communication messages. Also adds support to process these messages in both directions ie responses to PF initiated DOWN (PF => AF) messages and AF initiated UP messages (AF => PF).

Mbox communication APIs and message formats are defined in AF driver (drivers/net/ethernet/marvell/octeontx2/af), mbox.h from AF driver is included here to avoid duplication.

---
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  28 ++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   | 166 ++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 359 ++++++++++++++++++++-
 4 files changed, 552 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +1 -1
index 622b803..339fde8 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_OCTEONTX2_PF) += octeontx2_nicpf.o
 
-octeontx2_nicpf-y := otx2_pf.o
+octeontx2_nicpf-y := otx2_pf.o otx2_common.o
 
 ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c new file +28 -0
new file mode 100644
index 0000000..cbab325
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Marvell OcteonTx2 RVU Ethernet driver
+ *
+ * Copyright (C) 2020 Marvell International Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/pci.h>
+
+#include "otx2_reg.h"
+#include "otx2_common.h"
+
+#define M(_name, _id, _fn_name, _req_type, _rsp_type)			\
+int __weak								\
+otx2_mbox_up_handler_ ## _fn_name(struct otx2_nic *pfvf,		\
+				struct _req_type *req,			\
+				struct _rsp_type *rsp)			\
+{									\
+	/* Nothing to do here */					\
+	return 0;							\
+}									\
+EXPORT_SYMBOL(otx2_mbox_up_handler_ ## _fn_name);
+MBOX_UP_CGX_MESSAGES
+#undef M
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +56 -0
index 9d52ab3..f194082 100644
@@ -13,6 +13,7 @@
 
 #include <linux/pci.h>
 
+#include <mbox.h>
 #include "otx2_reg.h"
 
 /* PCI device IDs */
@@ -20,12 +21,31 @@
 
 /* PCI BAR nos */
 #define PCI_CFG_REG_BAR_NUM                     2
+#define PCI_MBOX_BAR_NUM                        4
+
+#define NAME_SIZE                               32
+
+struct  mbox {
+	struct otx2_mbox	mbox;
+	struct work_struct	mbox_wrk;
+	struct otx2_mbox	mbox_up;
+	struct work_struct	mbox_up_wrk;
+	struct otx2_nic		*pfvf;
+	void			*bbuf_base; /* Bounce buffer for mbox memory */
+	struct mutex		lock;	/* serialize mailbox access */
+	int			num_msgs; /*mbox number of messages*/
+	int			up_num_msgs;/* mbox_up number of messages*/
+};
 
 struct otx2_hw {
 	struct pci_dev		*pdev;
 	u16                     rx_queues;
 	u16                     tx_queues;
 	u16			max_queues;
+
+	/* MSI-X*/
+	char			*irq_name;
+	cpumask_var_t           *affinity_mask;
 };
 
 struct otx2_nic {
@@ -35,6 +55,12 @@ struct otx2_nic {
 	struct otx2_hw		hw;
 	struct pci_dev		*pdev;
 	struct device		*dev;
+
+	/* Mbox */
+	struct mbox		mbox;
+	struct workqueue_struct *mbox_wq;
+
+	u16			pcifunc; /* RVU PF_FUNC */
 };
 
 /* Register read/write APIs */
@@ -74,4 +100,144 @@ static inline u64 otx2_read64(struct otx2_nic *nic, u64 offset)
 	return readq(addr);
 }
 
+/* Mbox bounce buffer APIs */
+static inline int otx2_mbox_bbuf_init(struct mbox *mbox, struct pci_dev *pdev)
+{
+	struct otx2_mbox *otx2_mbox;
+	struct otx2_mbox_dev *mdev;
+
+	mbox->bbuf_base = devm_kmalloc(&pdev->dev, MBOX_SIZE, GFP_KERNEL);
+	if (!mbox->bbuf_base)
+		return -ENOMEM;
+
+	/* Overwrite mbox mbase to point to bounce buffer, so that PF/VF
+	 * prepare all mbox messages in bounce buffer instead of directly
+	 * in hw mbox memory.
+	 */
+	otx2_mbox = &mbox->mbox;
+	mdev = &otx2_mbox->dev[0];
+	mdev->mbase = mbox->bbuf_base;
+
+	otx2_mbox = &mbox->mbox_up;
+	mdev = &otx2_mbox->dev[0];
+	mdev->mbase = mbox->bbuf_base;
+	return 0;
+}
+
+static inline void otx2_sync_mbox_bbuf(struct otx2_mbox *mbox, int devid)
+{
+	u16 msgs_offset = ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
+	void *hw_mbase = mbox->hwbase + (devid * MBOX_SIZE);
+	struct otx2_mbox_dev *mdev = &mbox->dev[devid];
+	struct mbox_hdr *hdr;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h static inline u64 otx2_read64(struct otx2_nic *nic, u64 offset) · line 142

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +10 -0
+	u64 msg_size;
+
+	if (mdev->mbase == hw_mbase)
+		return;
+
+	hdr = hw_mbase + mbox->rx_start;
+	msg_size = hdr->msg_size;
+
+	if (msg_size > mbox->rx_size - msgs_offset)
+		msg_size = mbox->rx_size - msgs_offset;

msg_size = min(msg_size, (mbox->rx_size - msgs_offset)); ? But can stay as is I guess.

Quoted 141 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +100 -0
+
+	/* Copy mbox messages from mbox memory to bounce buffer */
+	memcpy(mdev->mbase + mbox->rx_start,
+	       hw_mbase + mbox->rx_start, msg_size + msgs_offset);
+}
+
+static inline void otx2_mbox_lock_init(struct mbox *mbox)
+{
+	mutex_init(&mbox->lock);
+}
+
+static inline void otx2_mbox_lock(struct mbox *mbox)
+{
+	mutex_lock(&mbox->lock);
+}
+
+static inline void otx2_mbox_unlock(struct mbox *mbox)
+{
+	mutex_unlock(&mbox->lock);
+}
+
+/* Mbox APIs */
+static inline int otx2_sync_mbox_msg(struct mbox *mbox)
+{
+	int err;
+
+	if (!otx2_mbox_nonempty(&mbox->mbox, 0))
+		return 0;
+	otx2_mbox_msg_send(&mbox->mbox, 0);
+	err = otx2_mbox_wait_for_rsp(&mbox->mbox, 0);
+	if (err)
+		return err;
+
+	return otx2_mbox_check_rsp_msgs(&mbox->mbox, 0);
+}
+
+static inline int otx2_sync_mbox_up_msg(struct mbox *mbox, int devid)
+{
+	int err;
+
+	if (!otx2_mbox_nonempty(&mbox->mbox_up, devid))
+		return 0;
+	otx2_mbox_msg_send(&mbox->mbox_up, devid);
+	err = otx2_mbox_wait_for_rsp(&mbox->mbox_up, devid);
+	if (err)
+		return err;
+
+	return otx2_mbox_check_rsp_msgs(&mbox->mbox_up, devid);
+}
+
+/* Use this API to send mbox msgs in atomic context
+ * where sleeping is not allowed
+ */
+static inline int otx2_sync_mbox_msg_busy_poll(struct mbox *mbox)
+{
+	int err;
+
+	if (!otx2_mbox_nonempty(&mbox->mbox, 0))
+		return 0;
+	otx2_mbox_msg_send(&mbox->mbox, 0);
+	err = otx2_mbox_busy_poll_for_rsp(&mbox->mbox, 0);
+	if (err)
+		return err;
+
+	return otx2_mbox_check_rsp_msgs(&mbox->mbox, 0);
+}
+
+#define M(_name, _id, _fn_name, _req_type, _rsp_type)                   \
+static struct _req_type __maybe_unused					\
+*otx2_mbox_alloc_msg_ ## _fn_name(struct mbox *mbox)                    \
+{									\
+	struct _req_type *req;						\
+									\
+	req = (struct _req_type *)otx2_mbox_alloc_msg_rsp(		\
+		&mbox->mbox, 0, sizeof(struct _req_type),		\
+		sizeof(struct _rsp_type));				\
+	if (!req)							\
+		return NULL;						\
+	req->hdr.sig = OTX2_MBOX_REQ_SIG;				\
+	req->hdr.id = _id;						\
+	return req;							\
+}
+
+MBOX_MESSAGES
+#undef M
+
+#define M(_name, _id, _fn_name, _req_type, _rsp_type)			\
+int									\
+otx2_mbox_up_handler_ ## _fn_name(struct otx2_nic *pfvf,		\
+				struct _req_type *req,			\
+				struct _rsp_type *rsp);			\
+
+MBOX_UP_CGX_MESSAGES
+#undef M
+
+#define	RVU_PFVF_PF_SHIFT	10
+#define	RVU_PFVF_PF_MASK	0x3F
+#define	RVU_PFVF_FUNC_SHIFT	0
+#define	RVU_PFVF_FUNC_MASK	0x3FF
+
 #endif /* OTX2_COMMON_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +32 -0
index cf60efa..eb8cf20 100644
@@ -35,6 +35,322 @@ MODULE_LICENSE("GPL v2");
 MODULE_VERSION(DRV_VERSION);
 MODULE_DEVICE_TABLE(pci, otx2_pf_id_table);
 
+enum {
+	TYPE_PFAF,
+	TYPE_PFVF,
+};
+
+static void otx2_queue_work(struct mbox *mw, struct workqueue_struct *mbox_wq,
+			    int first, int mdevs, u64 intr, int type)
+{
+	struct otx2_mbox_dev *mdev;
+	struct otx2_mbox *mbox;
+	struct mbox_hdr *hdr;
+	int i;
+
+	for (i = first; i < mdevs; i++) {
+		/* start from 0 */
+		if (!(intr & BIT_ULL(i - first)))
+			continue;
+
+		mbox = &mw->mbox;
+		mdev = &mbox->dev[i];
+		if (type == TYPE_PFAF)
+			otx2_sync_mbox_bbuf(mbox, i);
+		hdr = mdev->mbase + mbox->rx_start;
+		/* The hdr->num_msgs is set to zero immediately in the interrupt
+		 * handler to  ensure that it holds a correct value next time
+		 * when the interrupt handler is called.
+		 * pf->mbox.num_msgs holds the data for use in pfaf_mbox_handler
+		 * pf>mbox.up_num_msgs holds the data for use in
+		 * pfaf_mbox_up_handler.
+		 */
+		if (hdr->num_msgs) {
+			mw[i].num_msgs = hdr->num_msgs;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c MODULE_LICENSE("GPL v2"); · line 79

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+			hdr->num_msgs = 0;
+			if (type == TYPE_PFAF)
+				memset(mbox->hwbase + mbox->rx_start, 0,
+				       ALIGN(sizeof(struct mbox_hdr),
+					     sizeof(u64)));
+
+			queue_work(mbox_wq, &mw[i].mbox_wrk);
+		}
+
+		mbox = &mw->mbox_up;

You could have a two separate stack variables for these two mboxes instead of flipping the single variable on each loop iteration.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -0
+		mdev = &mbox->dev[i];
+		if (type == TYPE_PFAF)
+			otx2_sync_mbox_bbuf(mbox, i);
+		hdr = mdev->mbase + mbox->rx_start;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c MODULE_LICENSE("GPL v2"); · line 93

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+		if (hdr->num_msgs) {
+			mw[i].up_num_msgs = hdr->num_msgs;
+			hdr->num_msgs = 0;
+			if (type == TYPE_PFAF)
+				memset(mbox->hwbase + mbox->rx_start, 0,
+				       ALIGN(sizeof(struct mbox_hdr),
+					     sizeof(u64)));
+
+			queue_work(mbox_wq, &mw[i].mbox_up_wrk);
+		}

Does it make sense to pull out the logic above onto separate function?

Quoted 233 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +233 -0
+	}
+}
+
+static void otx2_process_pfaf_mbox_msg(struct otx2_nic *pf,
+				       struct mbox_msghdr *msg)
+{
+	if (msg->id >= MBOX_MSG_MAX) {
+		dev_err(pf->dev,
+			"Mbox msg with unknown ID 0x%x\n", msg->id);
+		return;
+	}
+
+	if (msg->sig != OTX2_MBOX_RSP_SIG) {
+		dev_err(pf->dev,
+			"Mbox msg with wrong signature %x, ID 0x%x\n",
+			 msg->sig, msg->id);
+		return;
+	}
+
+	switch (msg->id) {
+	case MBOX_MSG_READY:
+		pf->pcifunc = msg->pcifunc;
+		break;
+	default:
+		if (msg->rc)
+			dev_err(pf->dev,
+				"Mbox msg response has err %d, ID 0x%x\n",
+				msg->rc, msg->id);
+		break;
+	}
+}
+
+static void otx2_pfaf_mbox_handler(struct work_struct *work)
+{
+	struct otx2_mbox_dev *mdev;
+	struct mbox_hdr *rsp_hdr;
+	struct mbox_msghdr *msg;
+	struct otx2_mbox *mbox;
+	struct mbox *af_mbox;
+	struct otx2_nic *pf;
+	int offset, id;
+
+	af_mbox = container_of(work, struct mbox, mbox_wrk);
+	mbox = &af_mbox->mbox;
+	mdev = &mbox->dev[0];
+	rsp_hdr = (struct mbox_hdr *)(mdev->mbase + mbox->rx_start);
+
+	offset = mbox->rx_start + ALIGN(sizeof(*rsp_hdr), MBOX_MSG_ALIGN);
+	pf = af_mbox->pfvf;
+
+	for (id = 0; id < af_mbox->num_msgs; id++) {
+		msg = (struct mbox_msghdr *)(mdev->mbase + offset);
+		otx2_process_pfaf_mbox_msg(pf, msg);
+		offset = mbox->rx_start + msg->next_msgoff;
+		mdev->msgs_acked++;
+	}
+
+	otx2_mbox_reset(mbox, 0);
+}
+
+static int otx2_process_mbox_msg_up(struct otx2_nic *pf,
+				    struct mbox_msghdr *req)
+{
+	/* Check if valid, if not reply with a invalid msg */
+	if (req->sig != OTX2_MBOX_REQ_SIG) {
+		otx2_reply_invalid_msg(&pf->mbox.mbox_up, 0, 0, req->id);
+		return -ENODEV;
+	}
+
+	switch (req->id) {
+#define M(_name, _id, _fn_name, _req_type, _rsp_type)			\
+	case _id: {							\
+		struct _rsp_type *rsp;					\
+		int err;						\
+									\
+		rsp = (struct _rsp_type *)otx2_mbox_alloc_msg(		\
+			&pf->mbox.mbox_up, 0,				\
+			sizeof(struct _rsp_type));			\
+		if (!rsp)						\
+			return -ENOMEM;					\
+									\
+		rsp->hdr.id = _id;					\
+		rsp->hdr.sig = OTX2_MBOX_RSP_SIG;			\
+		rsp->hdr.pcifunc = 0;					\
+		rsp->hdr.rc = 0;					\
+									\
+		err = otx2_mbox_up_handler_ ## _fn_name(		\
+			pf, (struct _req_type *)req, rsp);		\
+		return err;						\
+	}
+MBOX_UP_CGX_MESSAGES
+#undef M
+		break;
+	default:
+		otx2_reply_invalid_msg(&pf->mbox.mbox_up, 0, 0, req->id);
+		return -ENODEV;
+	}
+	return 0;
+}
+
+static void otx2_pfaf_mbox_up_handler(struct work_struct *work)
+{
+	struct mbox *af_mbox = container_of(work, struct mbox, mbox_up_wrk);
+	struct otx2_mbox *mbox = &af_mbox->mbox_up;
+	struct otx2_mbox_dev *mdev = &mbox->dev[0];
+	struct otx2_nic *pf = af_mbox->pfvf;
+	int offset, id, devid = 0;
+	struct mbox_hdr *rsp_hdr;
+	struct mbox_msghdr *msg;
+
+	rsp_hdr = (struct mbox_hdr *)(mdev->mbase + mbox->rx_start);
+
+	offset = mbox->rx_start + ALIGN(sizeof(*rsp_hdr), MBOX_MSG_ALIGN);
+
+	for (id = 0; id < af_mbox->up_num_msgs; id++) {
+		msg = (struct mbox_msghdr *)(mdev->mbase + offset);
+
+		devid = msg->pcifunc & RVU_PFVF_FUNC_MASK;
+		/* Skip processing VF's messages */
+		if (!devid)
+			otx2_process_mbox_msg_up(pf, msg);
+		offset = mbox->rx_start + msg->next_msgoff;
+	}
+
+	otx2_mbox_msg_send(mbox, 0);
+}
+
+static irqreturn_t otx2_pfaf_mbox_intr_handler(int irq, void *pf_irq)
+{
+	struct otx2_nic *pf = (struct otx2_nic *)pf_irq;
+	struct mbox *mbox;
+
+	/* Clear the IRQ */
+	otx2_write64(pf, RVU_PF_INT, BIT_ULL(0));
+
+	mbox = &pf->mbox;
+	otx2_queue_work(mbox, pf->mbox_wq, 0, 1, 1, TYPE_PFAF);
+
+	return IRQ_HANDLED;
+}
+
+static void otx2_disable_mbox_intr(struct otx2_nic *pf)
+{
+	int vector = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_AFPF_MBOX);
+
+	/* Disable AF => PF mailbox IRQ */
+	otx2_write64(pf, RVU_PF_INT_ENA_W1C, BIT_ULL(0));
+	free_irq(vector, pf);
+}
+
+static int otx2_register_mbox_intr(struct otx2_nic *pf, bool probe_af)
+{
+	struct otx2_hw *hw = &pf->hw;
+	struct msg_req *req;
+	char *irq_name;
+	int err;
+
+	/* Register mailbox interrupt handler */
+	irq_name = &hw->irq_name[RVU_PF_INT_VEC_AFPF_MBOX * NAME_SIZE];
+	snprintf(irq_name, NAME_SIZE, "RVUPFAF Mbox");
+	err = request_irq(pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_AFPF_MBOX),
+			  otx2_pfaf_mbox_intr_handler, 0, irq_name, pf);
+	if (err) {
+		dev_err(pf->dev,
+			"RVUPF: IRQ registration failed for PFAF mbox irq\n");
+		return err;
+	}
+
+	/* Enable mailbox interrupt for msgs coming from AF.
+	 * First clear to avoid spurious interrupts, if any.
+	 */
+	otx2_write64(pf, RVU_PF_INT, BIT_ULL(0));
+	otx2_write64(pf, RVU_PF_INT_ENA_W1S, BIT_ULL(0));
+
+	if (!probe_af)
+		return 0;
+
+	/* Check mailbox communication with AF */
+	req = otx2_mbox_alloc_msg_ready(&pf->mbox);
+	if (!req) {
+		otx2_disable_mbox_intr(pf);
+		return -ENOMEM;
+	}
+	err = otx2_sync_mbox_msg(&pf->mbox);
+	if (err) {
+		dev_warn(pf->dev,
+			 "AF not responding to mailbox, deferring probe\n");
+		otx2_disable_mbox_intr(pf);
+		return -EPROBE_DEFER;
+	}
+
+	return 0;
+}
+
+static void otx2_pfaf_mbox_destroy(struct otx2_nic *pf)
+{
+	struct mbox *mbox = &pf->mbox;
+
+	if (pf->mbox_wq) {
+		flush_workqueue(pf->mbox_wq);
+		destroy_workqueue(pf->mbox_wq);
+		pf->mbox_wq = NULL;
+	}
+
+	if (mbox->mbox.hwbase)
+		iounmap((void __iomem *)mbox->mbox.hwbase);
+
+	otx2_mbox_destroy(&mbox->mbox);
+	otx2_mbox_destroy(&mbox->mbox_up);
+}
+
+static int otx2_pfaf_mbox_init(struct otx2_nic *pf)
+{
+	struct mbox *mbox = &pf->mbox;
+	void __iomem *hwbase;
+	int err;
+
+	mbox->pfvf = pf;
+	pf->mbox_wq = alloc_workqueue("otx2_pfaf_mailbox",
+				      WQ_UNBOUND | WQ_HIGHPRI |
+				      WQ_MEM_RECLAIM, 1);
+	if (!pf->mbox_wq)
+		return -ENOMEM;
+
+	/* Mailbox is a reserved memory (in RAM) region shared between
+	 * admin function (i.e AF) and this PF, shouldn't be mapped as
+	 * device memory to allow unaligned accesses.
+	 */
+	hwbase = ioremap_wc(pci_resource_start(pf->pdev, PCI_MBOX_BAR_NUM),
+			    pci_resource_len(pf->pdev, PCI_MBOX_BAR_NUM));
+	if (!hwbase) {
+		dev_err(pf->dev, "Unable to map PFAF mailbox region\n");
+		err = -ENOMEM;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c MODULE_LICENSE("GPL v2"); · line 336

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+		goto exit;
+	}
+
+	err = otx2_mbox_init(&mbox->mbox, hwbase, pf->pdev, pf->reg_base,
+			     MBOX_DIR_PFAF, 1);
+	if (err)
+		goto exit;
+
+	err = otx2_mbox_init(&mbox->mbox_up, hwbase, pf->pdev, pf->reg_base,
+			     MBOX_DIR_PFAF_UP, 1);

There is a chance that the first otx2_mbox_init succeeded and second one failed. In that case you will be leaking the mbox->dev that otx2_mbox_init is internally allocating as the caller of otx2_pfaf_mbox_init in case of error has a 'goto err_free_irq_vectors', so otx2_mbox_destroy won't be called for the mbox->mbox. Furthermore the iounmap() would be skipped as well.

I'm not sure whether PCI subsystem will call the remove() callback in case when probe() failed?

Quoted 109 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +58 -2
+	if (err)
+		goto exit;
+
+	err = otx2_mbox_bbuf_init(mbox, pf->pdev);
+	if (err)
+		goto exit;
+
+	INIT_WORK(&mbox->mbox_wrk, otx2_pfaf_mbox_handler);
+	INIT_WORK(&mbox->mbox_up_wrk, otx2_pfaf_mbox_up_handler);
+	otx2_mbox_lock_init(&pf->mbox);
+
+	return 0;
+exit:
+	destroy_workqueue(pf->mbox_wq);
+	return err;
+}
+
 static int otx2_set_real_num_queues(struct net_device *netdev,
 				    int tx_queues, int rx_queues)
 {
@@ -96,6 +412,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct otx2_nic *pf;
 	struct otx2_hw *hw;
 	int err, qcount;
+	int num_vec;
 
 	err = pcim_enable_device(pdev);
 	if (err) {
@@ -145,6 +462,17 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	hw->tx_queues = qcount;
 	hw->max_queues = qcount;
 
+	num_vec = pci_msix_vec_count(pdev);
+	hw->irq_name = devm_kmalloc_array(&hw->pdev->dev, num_vec, NAME_SIZE,
+					  GFP_KERNEL);
+	if (!hw->irq_name)
+		goto err_free_netdev;
+
+	hw->affinity_mask = devm_kcalloc(&hw->pdev->dev, num_vec,
+					 sizeof(cpumask_var_t), GFP_KERNEL);
+	if (!hw->affinity_mask)
+		goto err_free_netdev;
+
 	/* Map CSRs */
 	pf->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0);
 	if (!pf->reg_base) {
@@ -157,20 +485,44 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (err)
 		goto err_free_netdev;
 
+	err = pci_alloc_irq_vectors(hw->pdev, RVU_PF_INT_VEC_CNT,
+				    RVU_PF_INT_VEC_CNT, PCI_IRQ_MSIX);
+	if (err < 0) {
+		dev_err(dev, "%s: Failed to alloc %d IRQ vectors\n",
+			__func__, num_vec);
+		goto err_free_netdev;
+	}
+
+	/* Init PF <=> AF mailbox stuff */
+	err = otx2_pfaf_mbox_init(pf);
+	if (err)
+		goto err_free_irq_vectors;
+
+	/* Register mailbox interrupt */
+	err = otx2_register_mbox_intr(pf, true);
+	if (err)
+		goto err_mbox_destroy;
+
 	err = otx2_set_real_num_queues(netdev, hw->tx_queues, hw->rx_queues);
 	if (err)
-		goto err_free_netdev;
+		goto err_disable_mbox_intr;
 
 	netdev->netdev_ops = &otx2_netdev_ops;
 
 	err = register_netdev(netdev);
 	if (err) {
 		dev_err(dev, "Failed to register netdevice\n");
-		goto err_free_netdev;
+		goto err_disable_mbox_intr;
 	}
 
 	return 0;
 
+err_disable_mbox_intr:
+	otx2_disable_mbox_intr(pf);
+err_mbox_destroy:
+	otx2_pfaf_mbox_destroy(pf);
+err_free_irq_vectors:
+	pci_free_irq_vectors(hw->pdev);
 err_free_netdev:
 	pci_set_drvdata(pdev, NULL);
 	free_netdev(netdev);
@@ -190,9 +542,12 @@ static void otx2_remove(struct pci_dev *pdev)
 	pf = netdev_priv(netdev);
 
 	unregister_netdev(netdev);
+	otx2_disable_mbox_intr(pf);
+	otx2_pfaf_mbox_destroy(pf);
 	pci_free_irq_vectors(pf->pdev);
 	pci_set_drvdata(pdev, NULL);
 	free_netdev(netdev);
+
 	pci_release_regions(pdev);
 }
 
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH v4 02/17] octeontx2-pf: Mailbox communication with AF

Quoted 61 lines · Maciej Fijalkowski
Quoted 30 lines · On Tue, Jan 21, 2020 at 06:51:36PM +0530, [email protected] wrote:

From: Sunil Goutham <[email protected]>

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +28 -0
+
+static void otx2_queue_work(struct mbox *mw, struct workqueue_struct *mbox_wq,
+                         int first, int mdevs, u64 intr, int type)
+{
+     struct otx2_mbox_dev *mdev;
+     struct otx2_mbox *mbox;
+     struct mbox_hdr *hdr;
+     int i;
+
+     for (i = first; i < mdevs; i++) {
+             /* start from 0 */
+             if (!(intr & BIT_ULL(i - first)))
+                     continue;
+
+             mbox = &mw->mbox;
+             mdev = &mbox->dev[i];
+             if (type == TYPE_PFAF)
+                     otx2_sync_mbox_bbuf(mbox, i);
+             hdr = mdev->mbase + mbox->rx_start;
+             /* The hdr->num_msgs is set to zero immediately in the interrupt
+              * handler to  ensure that it holds a correct value next time
+              * when the interrupt handler is called.
+              * pf->mbox.num_msgs holds the data for use in pfaf_mbox_handler
+              * pf>mbox.up_num_msgs holds the data for use in
+              * pfaf_mbox_up_handler.
+              */
+             if (hdr->num_msgs) {
+                     mw[i].num_msgs = hdr->num_msgs;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c MODULE_LICENSE("GPL v2"); · line 79

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+                     hdr->num_msgs = 0;
+                     if (type == TYPE_PFAF)
+                             memset(mbox->hwbase + mbox->rx_start, 0,
+                                    ALIGN(sizeof(struct mbox_hdr),
+                                          sizeof(u64)));
+
+                     queue_work(mbox_wq, &mw[i].mbox_wrk);
+             }
+
+             mbox = &mw->mbox_up;

You could have a two separate stack variables for these two mboxes instead of flipping the single variable on each loop iteration.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -0
+             mdev = &mbox->dev[i];
+             if (type == TYPE_PFAF)
+                     otx2_sync_mbox_bbuf(mbox, i);
+             hdr = mdev->mbase + mbox->rx_start;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c MODULE_LICENSE("GPL v2"); · line 93

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+             if (hdr->num_msgs) {
+                     mw[i].up_num_msgs = hdr->num_msgs;
+                     hdr->num_msgs = 0;
+                     if (type == TYPE_PFAF)
+                             memset(mbox->hwbase + mbox->rx_start, 0,
+                                    ALIGN(sizeof(struct mbox_hdr),
+                                          sizeof(u64)));
+
+                     queue_work(mbox_wq, &mw[i].mbox_up_wrk);
+             }
Quoted 2 lines

Does it make sense to pull out the logic above onto separate function?

Thanks for the feedback.
I will relook into the logic and see if this can be cleanedup and submit along with next patchset.

Quoted 60 lines
Quoted 42 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +42 -0
+     }
+}
+
+static void otx2_pfaf_mbox_destroy(struct otx2_nic *pf)
+{
+     struct mbox *mbox = &pf->mbox;
+
+     if (pf->mbox_wq) {
+             flush_workqueue(pf->mbox_wq);
+             destroy_workqueue(pf->mbox_wq);
+             pf->mbox_wq = NULL;
+     }
+
+     if (mbox->mbox.hwbase)
+             iounmap((void __iomem *)mbox->mbox.hwbase);
+
+     otx2_mbox_destroy(&mbox->mbox);
+     otx2_mbox_destroy(&mbox->mbox_up);
+}
+
+static int otx2_pfaf_mbox_init(struct otx2_nic *pf)
+{
+     struct mbox *mbox = &pf->mbox;
+     void __iomem *hwbase;
+     int err;
+
+     mbox->pfvf = pf;
+     pf->mbox_wq = alloc_workqueue("otx2_pfaf_mailbox",
+                                   WQ_UNBOUND | WQ_HIGHPRI |
+                                   WQ_MEM_RECLAIM, 1);
+     if (!pf->mbox_wq)
+             return -ENOMEM;
+
+     /* Mailbox is a reserved memory (in RAM) region shared between
+      * admin function (i.e AF) and this PF, shouldn't be mapped as
+      * device memory to allow unaligned accesses.
+      */
+     hwbase = ioremap_wc(pci_resource_start(pf->pdev, PCI_MBOX_BAR_NUM),
+                         pci_resource_len(pf->pdev, PCI_MBOX_BAR_NUM));
+     if (!hwbase) {
+             dev_err(pf->dev, "Unable to map PFAF mailbox region\n");
+             err = -ENOMEM;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c MODULE_LICENSE("GPL v2"); · line 336

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+             goto exit;
+     }
+
+     err = otx2_mbox_init(&mbox->mbox, hwbase, pf->pdev, pf->reg_base,
+                          MBOX_DIR_PFAF, 1);
+     if (err)
+             goto exit;
+
+     err = otx2_mbox_init(&mbox->mbox_up, hwbase, pf->pdev, pf->reg_base,
+                          MBOX_DIR_PFAF_UP, 1);

There is a chance that the first otx2_mbox_init succeeded and second one failed. In that case you will be leaking the mbox->dev that otx2_mbox_init is internally allocating as the caller of otx2_pfaf_mbox_init in case of error has a 'goto err_free_irq_vectors', so otx2_mbox_destroy won't be called for the mbox->mbox. Furthermore the iounmap() would be skipped as well.

Quoted 3 lines

I'm not sure whether PCI subsystem will call the remove() callback in case when probe() failed?

Thanks for catching this, will fix and resubmit.

Sunil.

#9 lore raw

PATCH v4 3/17 octeontx2-pf: Attach NIX and NPA block LFs

In reply to [email protected]

From: Sunil Goutham <[email protected]>

For a PF to function as a NIC, NPA (for Rx buffers, Tx descriptors etc) and NIX (for rcv, send and completion queues) are the minimum resources needed. So request admin function (AF) to attach one each of NIX and NPA block LFs (local functions).

Only AF can configure a LF's contexts, so request AF to allocate memory for NPA aura/pool and NIX RQ/SQ/CQ HW contexts. Upon receiving response, save some of the HW constants like number of pointers per stack page, size of send queue buffer (SQBs, where SQEs are queued by HW) e.t.c which are later used to initialize queues.

A HW context here is like a state machine maintained for a descriptor queue. eg size, head/tail pointers, irq etc etc. HW maintains this in memory.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 170 +++++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  36 +++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  72 ++++++++-
 .../ethernet/marvell/octeontx2/nic/otx2_struct.h   |  20 +++
 4 files changed, 295 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +170 -0
index cbab325..96e044c 100644
@@ -13,6 +13,176 @@
 
 #include "otx2_reg.h"
 #include "otx2_common.h"
+#include "otx2_struct.h"
+
+int otx2_config_nix(struct otx2_nic *pfvf)
+{
+	struct nix_lf_alloc_req  *nixlf;
+	struct nix_lf_alloc_rsp *rsp;
+	int err;
+
+	pfvf->qset.xqe_size = NIX_XQESZ_W16 ? 128 : 512;
+
+	/* Get memory to put this msg */
+	nixlf = otx2_mbox_alloc_msg_nix_lf_alloc(&pfvf->mbox);
+	if (!nixlf)
+		return -ENOMEM;
+
+	/* Set RQ/SQ/CQ counts */
+	nixlf->rq_cnt = pfvf->hw.rx_queues;
+	nixlf->sq_cnt = pfvf->hw.tx_queues;
+	nixlf->cq_cnt = pfvf->qset.cq_cnt;
+	nixlf->xqe_sz = NIX_XQESZ_W16;
+	/* We don't know absolute NPA LF idx attached.
+	 * AF will replace 'RVU_DEFAULT_PF_FUNC' with
+	 * NPA LF attached to this RVU PF/VF.
+	 */
+	nixlf->npa_func = RVU_DEFAULT_PF_FUNC;
+	/* Disable alignment pad, enable L2 length check,
+	 * enable L4 TCP/UDP checksum verification.
+	 */
+	nixlf->rx_cfg = BIT_ULL(33) | BIT_ULL(35) | BIT_ULL(37);
+
+	err = otx2_sync_mbox_msg(&pfvf->mbox);
+	if (err)
+		return err;
+
+	rsp = (struct nix_lf_alloc_rsp *)otx2_mbox_get_rsp(&pfvf->mbox.mbox, 0,
+							   &nixlf->hdr);
+	if (IS_ERR(rsp))
+		return PTR_ERR(rsp);
+
+	if (rsp->qints < 1)
+		return -ENXIO;
+
+	return rsp->hdr.rc;
+}
+
+int otx2_config_npa(struct otx2_nic *pfvf)
+{
+	struct otx2_qset *qset = &pfvf->qset;
+	struct npa_lf_alloc_req  *npalf;
+	struct otx2_hw *hw = &pfvf->hw;
+	int aura_cnt, err;
+
+	/* Pool - Stack of free buffer pointers
+	 * Aura - Alloc/frees pointers from/to pool for NIX DMA.
+	 */
+
+	if (!hw->pool_cnt)
+		return -EINVAL;
+
+	qset->pool = devm_kzalloc(pfvf->dev, sizeof(struct otx2_pool) *
+				  hw->pool_cnt, GFP_KERNEL);
+	if (!qset->pool)
+		return -ENOMEM;
+
+	/* Get memory to put this msg */
+	npalf = otx2_mbox_alloc_msg_npa_lf_alloc(&pfvf->mbox);
+	if (!npalf)
+		return -ENOMEM;
+
+	/* Set aura and pool counts */
+	npalf->nr_pools = hw->pool_cnt;
+	aura_cnt = ilog2(roundup_pow_of_two(hw->pool_cnt));
+	npalf->aura_sz = (aura_cnt >= ilog2(128)) ? (aura_cnt - 6) : 1;
+
+	err = otx2_sync_mbox_msg(&pfvf->mbox);
+	if (err)
+		return err;
+	return 0;
+}
+
+int otx2_detach_resources(struct mbox *mbox)
+{
+	struct rsrc_detach *detach;
+
+	otx2_mbox_lock(mbox);
+	detach = otx2_mbox_alloc_msg_detach_resources(mbox);
+	if (!detach) {
+		otx2_mbox_unlock(mbox);
+		return -ENOMEM;
+	}
+
+	/* detach all */
+	detach->partial = false;
+
+	/* Send detach request to AF */
+	otx2_mbox_msg_send(&mbox->mbox, 0);
+	otx2_mbox_unlock(mbox);
+	return 0;
+}
+
+int otx2_attach_npa_nix(struct otx2_nic *pfvf)
+{
+	struct rsrc_attach *attach;
+	struct msg_req *msix;
+	int err;
+
+	otx2_mbox_lock(&pfvf->mbox);
+	/* Get memory to put this msg */
+	attach = otx2_mbox_alloc_msg_attach_resources(&pfvf->mbox);
+	if (!attach) {
+		otx2_mbox_unlock(&pfvf->mbox);
+		return -ENOMEM;
+	}
+
+	attach->npalf = true;
+	attach->nixlf = true;
+
+	/* Send attach request to AF */
+	err = otx2_sync_mbox_msg(&pfvf->mbox);
+	if (err) {
+		otx2_mbox_unlock(&pfvf->mbox);
+		return err;
+	}
+
+	/* Get NPA and NIX MSIX vector offsets */
+	msix = otx2_mbox_alloc_msg_msix_offset(&pfvf->mbox);
+	if (!msix) {
+		otx2_mbox_unlock(&pfvf->mbox);
+		return -ENOMEM;
+	}
+
+	err = otx2_sync_mbox_msg(&pfvf->mbox);
+	if (err) {
+		otx2_mbox_unlock(&pfvf->mbox);
+		return err;
+	}
+	otx2_mbox_unlock(&pfvf->mbox);
+
+	if (pfvf->hw.npa_msixoff == MSIX_VECTOR_INVALID ||
+	    pfvf->hw.nix_msixoff == MSIX_VECTOR_INVALID) {
+		dev_err(pfvf->dev,
+			"RVUPF: Invalid MSIX vector offset for NPA/NIX\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/* Mbox message handlers */
+void mbox_handler_npa_lf_alloc(struct otx2_nic *pfvf,
+			       struct npa_lf_alloc_rsp *rsp)
+{
+	pfvf->hw.stack_pg_ptrs = rsp->stack_pg_ptrs;
+	pfvf->hw.stack_pg_bytes = rsp->stack_pg_bytes;
+}
+
+void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
+			       struct nix_lf_alloc_rsp *rsp)
+{
+	pfvf->hw.sqb_size = rsp->sqb_size;
+	pfvf->hw.rx_chan_base = rsp->rx_chan_base;
+	pfvf->hw.tx_chan_base = rsp->tx_chan_base;
+}
+
+void mbox_handler_msix_offset(struct otx2_nic *pfvf,
+			      struct msix_offset_rsp *rsp)
+{
+	pfvf->hw.npa_msixoff = rsp->npa_msixoff;
+	pfvf->hw.nix_msixoff = rsp->nix_msixoff;
+}
 
 #define M(_name, _id, _fn_name, _req_type, _rsp_type)			\
 int __weak								\
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +36 -0
index f194082..dcd768b 100644
@@ -25,6 +25,17 @@
 
 #define NAME_SIZE                               32
 
+struct otx2_pool {
+	struct qmem		*stack;
+};
+
+struct otx2_qset {
+#define OTX2_MAX_CQ_CNT		64
+	u16			cq_cnt;
+	u16			xqe_size; /* Size of CQE i.e 128 or 512 bytes*/
+	struct otx2_pool	*pool;
+};
+
 struct  mbox {
 	struct otx2_mbox	mbox;
 	struct work_struct	mbox_wrk;
@@ -42,8 +53,19 @@ struct otx2_hw {
 	u16                     rx_queues;
 	u16                     tx_queues;
 	u16			max_queues;
+	u16			pool_cnt;
+
+	/* NPA */
+	u32			stack_pg_ptrs;  /* No of ptrs per stack page */
+	u32			stack_pg_bytes; /* Size of stack page */
+	u16			sqb_size;
+
+	u16			rx_chan_base;
+	u16			tx_chan_base;
 
 	/* MSI-X*/
+	u16			npa_msixoff; /* Offset of NPA vectors */
+	u16			nix_msixoff; /* Offset of NIX vectors */
 	char			*irq_name;
 	cpumask_var_t           *affinity_mask;
 };
@@ -52,6 +74,7 @@ struct otx2_nic {
 	void __iomem		*reg_base;
 	struct net_device	*netdev;
 
+	struct otx2_qset	qset;
 	struct otx2_hw		hw;
 	struct pci_dev		*pdev;
 	struct device		*dev;
@@ -240,4 +263,17 @@ MBOX_UP_CGX_MESSAGES
 #define	RVU_PFVF_FUNC_SHIFT	0
 #define	RVU_PFVF_FUNC_MASK	0x3FF
 
+/* RVU block related APIs */
+int otx2_attach_npa_nix(struct otx2_nic *pfvf);
+int otx2_detach_resources(struct mbox *mbox);
+int otx2_config_npa(struct otx2_nic *pfvf);
+int otx2_config_nix(struct otx2_nic *pfvf);
+
+/* Mbox handlers */
+void mbox_handler_msix_offset(struct otx2_nic *pfvf,
+			      struct msix_offset_rsp *rsp);
+void mbox_handler_npa_lf_alloc(struct otx2_nic *pfvf,
+			       struct npa_lf_alloc_rsp *rsp);
+void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
+			       struct nix_lf_alloc_rsp *rsp);
 #endif /* OTX2_COMMON_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +69 -3

122 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h new file +20 -0
new file mode 100644
index 0000000..e37f89f
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Marvell OcteonTx2 RVU Ethernet driver
+ *
+ * Copyright (C) 2020 Marvell International Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef OTX2_STRUCT_H
+#define OTX2_STRUCT_H
+
+/* NIX WQE/CQE size 128 byte or 512 byte */
+enum nix_cqesz_e {
+	NIX_XQESZ_W64 = 0x0,
+	NIX_XQESZ_W16 = 0x1,
+};
+
+#endif /* OTX2_STRUCT_H */
Signature · 1 line
2.7.4
maintainer
#10 lore raw

Re: [PATCH v4 03/17] octeontx2-pf: Attach NIX and NPA block LFs

Quoted 23 lines · On Tue, 21 Jan 2020 18:51:37 +0530, [email protected] wrote:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +23 -0
+int otx2_config_npa(struct otx2_nic *pfvf)
+{
+	struct otx2_qset *qset = &pfvf->qset;
+	struct npa_lf_alloc_req  *npalf;
+	struct otx2_hw *hw = &pfvf->hw;
+	int aura_cnt, err;
+
+	/* Pool - Stack of free buffer pointers
+	 * Aura - Alloc/frees pointers from/to pool for NIX DMA.
+	 */
+
+	if (!hw->pool_cnt)
+		return -EINVAL;
+
+	qset->pool = devm_kzalloc(pfvf->dev, sizeof(struct otx2_pool) *
+				  hw->pool_cnt, GFP_KERNEL);
+	if (!qset->pool)
+		return -ENOMEM;
+
+	/* Get memory to put this msg */
+	npalf = otx2_mbox_alloc_msg_npa_lf_alloc(&pfvf->mbox);
+	if (!npalf)
+		return -ENOMEM;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 93

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +10 -0
+
+	/* Set aura and pool counts */
+	npalf->nr_pools = hw->pool_cnt;
+	aura_cnt = ilog2(roundup_pow_of_two(hw->pool_cnt));
+	npalf->aura_sz = (aura_cnt >= ilog2(128)) ? (aura_cnt - 6) : 1;
+
+	err = otx2_sync_mbox_msg(&pfvf->mbox);
+	if (err)
+		return err;
+	return 0;

return otx2_sync..

directly

Quoted 19 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +18 -0
+}
 
+static int otx2_realloc_msix_vectors(struct otx2_nic *pf)
+{
+	struct otx2_hw *hw = &pf->hw;
+	int num_vec, err;
+
+	/* NPA interrupts are inot registered, so alloc only
+	 * upto NIX vector offset.
+	 */
+	num_vec = hw->nix_msixoff;
+#define NIX_LF_CINT_VEC_START			0x40
+	num_vec += NIX_LF_CINT_VEC_START + hw->max_queues;
+
+	otx2_disable_mbox_intr(pf);
+	pci_free_irq_vectors(hw->pdev);
+	pci_free_irq_vectors(hw->pdev);
+	err = pci_alloc_irq_vectors(hw->pdev, num_vec, num_vec, PCI_IRQ_MSIX);
+	if (err < 0) {

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_check_pf_usable(struct otx2_nic *nic) · line 458

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+		dev_err(pf->dev, "%s: Failed to realloc %d IRQ vectors\n",
+			__func__, num_vec);
+		return err;
+	}
+
+	err = otx2_register_mbox_intr(pf, false);
+	if (err)
+		return err;
+	return 0;
+}

ditto, please fix this everywhere in the submission

#11 lore raw

Re: [PATCH v4 03/17] octeontx2-pf: Attach NIX and NPA block LFs

Quoted 63 lines · Jakub Kicinski
Quoted 23 lines · On Tue, 21 Jan 2020 18:51:37 +0530, [email protected] wrote:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +23 -0
+int otx2_config_npa(struct otx2_nic *pfvf)
+{
+     struct otx2_qset *qset = &pfvf->qset;
+     struct npa_lf_alloc_req  *npalf;
+     struct otx2_hw *hw = &pfvf->hw;
+     int aura_cnt, err;
+
+     /* Pool - Stack of free buffer pointers
+      * Aura - Alloc/frees pointers from/to pool for NIX DMA.
+      */
+
+     if (!hw->pool_cnt)
+             return -EINVAL;
+
+     qset->pool = devm_kzalloc(pfvf->dev, sizeof(struct otx2_pool) *
+                               hw->pool_cnt, GFP_KERNEL);
+     if (!qset->pool)
+             return -ENOMEM;
+
+     /* Get memory to put this msg */
+     npalf = otx2_mbox_alloc_msg_npa_lf_alloc(&pfvf->mbox);
+     if (!npalf)
+             return -ENOMEM;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 93

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +10 -0
+
+     /* Set aura and pool counts */
+     npalf->nr_pools = hw->pool_cnt;
+     aura_cnt = ilog2(roundup_pow_of_two(hw->pool_cnt));
+     npalf->aura_sz = (aura_cnt >= ilog2(128)) ? (aura_cnt - 6) : 1;
+
+     err = otx2_sync_mbox_msg(&pfvf->mbox);
+     if (err)
+             return err;
+     return 0;

return otx2_sync..

directly

Quoted 23 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +22 -0
+}
 
+static int otx2_realloc_msix_vectors(struct otx2_nic *pf)
+{
+     struct otx2_hw *hw = &pf->hw;
+     int num_vec, err;
+
+     /* NPA interrupts are inot registered, so alloc only
+      * upto NIX vector offset.
+      */
+     num_vec = hw->nix_msixoff;
+#define NIX_LF_CINT_VEC_START                        0x40
+     num_vec += NIX_LF_CINT_VEC_START + hw->max_queues;
+
+     otx2_disable_mbox_intr(pf);
+     pci_free_irq_vectors(hw->pdev);
+     pci_free_irq_vectors(hw->pdev);
+     err = pci_alloc_irq_vectors(hw->pdev, num_vec, num_vec, PCI_IRQ_MSIX);
+     if (err < 0) {
+             dev_err(pf->dev, "%s: Failed to realloc %d IRQ vectors\n",
+                     __func__, num_vec);
+             return err;
+     }
Quoted 8 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_check_pf_usable(struct otx2_nic *nic) · line 458

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +6 -0
+
+     err = otx2_register_mbox_intr(pf, false);
+     if (err)
+             return err;
+     return 0;
+}

ditto, please fix this everywhere in the submission

Thanks, will fix and resubmit.

Sunil.

#12 lore raw

PATCH v4 4/17 octeontx2-pf: Initialize and config queues

In reply to [email protected]

From: Sunil Goutham <[email protected]>

This patch does the initialization of all queues ie the receive buffer pools, receive and transmit queues, completion or notification queues etc. Allocates all required resources (eg transmit schedulers, receive buffers etc) and configures them for proper functioning of queues. Also sets up receive queue's RED dropping levels.

---
 drivers/net/ethernet/marvell/octeontx2/af/common.h |   9 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 726 +++++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   | 131 +++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 235 ++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_reg.h  |  96 +++
 .../ethernet/marvell/octeontx2/nic/otx2_struct.h   |  11 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h | 102 +++
 7 files changed, 1291 insertions(+), 19 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h
drivers/net/ethernet/marvell/octeontx2/af/common.h +7 -2
index 784207b..cd33c2e 100644
@@ -143,8 +143,13 @@ enum nix_scheduler {
 	NIX_TXSCH_LVL_CNT = 0x5,
 };
 
-#define TXSCH_TL1_DFLT_RR_QTM      ((1 << 24) - 1)
-#define TXSCH_TL1_DFLT_RR_PRIO     (0x1ull)
+#define TXSCH_RR_QTM_MAX		((1 << 24) - 1)
+#define TXSCH_TL1_DFLT_RR_QTM		TXSCH_RR_QTM_MAX
+#define TXSCH_TL1_DFLT_RR_PRIO		(0x1ull)
+#define MAX_SCHED_WEIGHT		0xFF
+#define DFLT_RR_WEIGHT			71
+#define DFLT_RR_QTM	((DFLT_RR_WEIGHT * TXSCH_RR_QTM_MAX) \
+			 / MAX_SCHED_WEIGHT)
 
 /* Min/Max packet sizes, excluding FCS */
 #define	NIC_HW_MIN_FRS			40
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +726 -0

750 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +121 -10

199 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +228 -7

277 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h +96 -0

100 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +11 -0
index e37f89f..13086b0 100644
@@ -17,4 +17,15 @@ enum nix_cqesz_e {
 	NIX_XQESZ_W16 = 0x1,
 };
 
+enum nix_sqes_e {
+	NIX_SQESZ_W16 = 0x0,
+	NIX_SQESZ_W8 = 0x1,
+};
+
+enum nix_send_ldtype {
+	NIX_SEND_LDTYPE_LDD  = 0x0,
+	NIX_SEND_LDTYPE_LDT  = 0x1,
+	NIX_SEND_LDTYPE_LDWB = 0x2,
+};
+
 #endif /* OTX2_STRUCT_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#13 lore raw

Re: [PATCH v4 04/17] octeontx2-pf: Initialize and config queues

Quoted 23 lines · On Tue, 21 Jan 2020 18:51:38 +0530, [email protected] wrote:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +23 -0
+dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
+			   gfp_t gfp)
+{
+	dma_addr_t iova;
+
+	/* Check if request can be accommodated in previous allocated page */
+	if (pool->page &&
+	    ((pool->page_offset + pool->rbsize) <= PAGE_SIZE)) {
+		pool->pageref++;
+		goto ret;
+	}
+
+	otx2_get_page(pool);
+
+	/* Allocate a new page */
+	pool->page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
+				 pool->rbpage_order);
+	if (unlikely(!pool->page))
+		return -ENOMEM;
+
+	pool->page_offset = 0;
+ret:
+	iova = (u64)otx2_dma_map_page(pfvf, pool->page, pool->page_offset,

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 50

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +10 -0
+				      pool->rbsize, DMA_FROM_DEVICE);
+	if (!iova) {
+		if (!pool->page_offset)
+			__free_pages(pool->page, pool->rbpage_order);
+		pool->page = NULL;
+		return -ENOMEM;
+	}
+	pool->page_offset += pool->rbsize;
+	return iova;
+}

You don't seem to be doing any page recycling if I'm reading this right. Can't you use the standard in-kernel page frag allocator (netdev_alloc_frag/napi_alloc_frag)?

#14 lore raw

Re: [PATCH v4 04/17] octeontx2-pf: Initialize and config queues

Quoted 31 lines · Jakub Kicinski
Quoted 29 lines · On Tue, 21 Jan 2020 18:51:38 +0530, [email protected] wrote:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +29 -0
+dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
+                        gfp_t gfp)
+{
+     dma_addr_t iova;
+
+     /* Check if request can be accommodated in previous allocated page */
+     if (pool->page &&
+         ((pool->page_offset + pool->rbsize) <= PAGE_SIZE)) {
+             pool->pageref++;
+             goto ret;
+     }
+
+     otx2_get_page(pool);
+
+     /* Allocate a new page */
+     pool->page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
+                              pool->rbpage_order);
+     if (unlikely(!pool->page))
+             return -ENOMEM;
+
+     pool->page_offset = 0;
+ret:
+     iova = (u64)otx2_dma_map_page(pfvf, pool->page, pool->page_offset,
+                                   pool->rbsize, DMA_FROM_DEVICE);
+     if (!iova) {
+             if (!pool->page_offset)
+                     __free_pages(pool->page, pool->rbpage_order);
+             pool->page = NULL;
+             return -ENOMEM;
Quoted 8 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 50

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +4 -0
+     }
+     pool->page_offset += pool->rbsize;
+     return iova;
+}

You don't seem to be doing any page recycling if I'm reading this right. Can't you use the standard in-kernel page frag allocator (netdev_alloc_frag/napi_alloc_frag)?

netdev_alloc_frag() is costly.
eg: it does updates to page's refcount per frag allocation.

Thanks,
Sunil.

maintainer
#15 lore raw

Re: [PATCH v4 04/17] octeontx2-pf: Initialize and config queues

Quoted 10 lines · Sunil Kovvuri
Quoted 9 lines · Jakub Kicinski

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 25

Quoted 8 lines · On Tue, 21 Jan 2020 18:51:38 +0530, [email protected] wrote:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +8 -0
+dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
+                        gfp_t gfp)
+{
+     dma_addr_t iova;
+
+     /* Check if request can be accommodated in previous allocated page */
+     if (pool->page &&
+         ((pool->page_offset + pool->rbsize) <= PAGE_SIZE)) {

You use straight PAGE_SIZE here

Quoted 9 lines
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 34

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +9 -0
+             pool->pageref++;
+             goto ret;
+     }
+
+     otx2_get_page(pool);
+
+     /* Allocate a new page */
+     pool->page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
+                              pool->rbpage_order);

but allocate with order

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +12 -0
+     if (unlikely(!pool->page))
+             return -ENOMEM;
+
+     pool->page_offset = 0;
+ret:
+     iova = (u64)otx2_dma_map_page(pfvf, pool->page, pool->page_offset,
+                                   pool->rbsize, DMA_FROM_DEVICE);
+     if (!iova) {
+             if (!pool->page_offset)
+                     __free_pages(pool->page, pool->rbpage_order);
+             pool->page = NULL;
+             return -ENOMEM;
Quoted 8 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 50

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +4 -0
+     }
+     pool->page_offset += pool->rbsize;
+     return iova;
+}  

You don't seem to be doing any page recycling if I'm reading this right. Can't you use the standard in-kernel page frag allocator (netdev_alloc_frag/napi_alloc_frag)?

Quoted 2 lines

netdev_alloc_frag() is costly.
eg: it does updates to page's refcount per frag allocation.

It would be nice to see it improve rather than have drivers implement a slight variation of the scheme :/

#16 lore raw

Re: [PATCH v4 04/17] octeontx2-pf: Initialize and config queues

Quoted 15 lines · Jakub Kicinski
Quoted 10 lines · Sunil Kovvuri
Quoted 9 lines · Jakub Kicinski

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 25

Quoted 8 lines · On Tue, 21 Jan 2020 18:51:38 +0530, [email protected] wrote:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +8 -0
+dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
+                        gfp_t gfp)
+{
+     dma_addr_t iova;
+
+     /* Check if request can be accommodated in previous allocated page */
+     if (pool->page &&
+         ((pool->page_offset + pool->rbsize) <= PAGE_SIZE)) {

You use straight PAGE_SIZE here

Quoted 12 lines
Quoted 9 lines
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c line 34

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +9 -0
+             pool->pageref++;
+             goto ret;
+     }
+
+     otx2_get_page(pool);
+
+     /* Allocate a new page */
+     pool->page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
+                              pool->rbpage_order);

but allocate with order

For 4K pages and with MTU > 4K, we cannot allocate morethan 1buffer from a compound page.
For 64K pages the order will never go beyond '0'.
So comparing with PAGE_SIZE or with (PAGE_SIZE * (pool->rbpage_order + 1)) will not make a difference.

But anyway i will change this to make things clear. Thanks for pointing.

Sunil.

#17 lore raw

PATCH v4 5/17 octeontx2-pf: Setup interrupts and NAPI handler

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Completion queue (CQ) is the one with which HW notifies SW on a packet reception or transmission. Each of the RQ and SQ are mapped to a unique CQ and again both CQs are mapped to same interrupt ie the CINT. So that each core has one interrupt source in whose handler both Rx and Tx notifications are processed.

Also
- Registered a NAPI handler for the CINT.
- Setup coalescing parameters.
- IRQ affinity hints etc

---
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  55 +++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  54 +++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 125 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |  68 +++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |  38 ++++++-
 6 files changed, 332 insertions(+), 10 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +1 -1
index 339fde8..0484d70 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_OCTEONTX2_PF) += octeontx2_nicpf.o
 
-octeontx2_nicpf-y := otx2_pf.o otx2_common.o
+octeontx2_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o
 
 ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +55 -0

67 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +54 -0

93 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +122 -3

176 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c new file +68 -0

68 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +32 -6
index ce6efcf..a81bdc6 100644
@@ -37,6 +37,22 @@
 		((x) - OTX2_HEAD_ROOM - \
 		OTX2_DATA_ALIGN(sizeof(struct skb_shared_info)))
 
+/* IRQ triggered when NIX_LF_CINTX_CNT[ECOUNT]
+ * is equal to this value.
+ */
+#define CQ_CQE_THRESH_DEFAULT	10
+
+/* IRQ triggered when NIX_LF_CINTX_CNT[ECOUNT]
+ * is nonzero and this much time elapses after that.
+ */
+#define CQ_TIMER_THRESH_DEFAULT	1  /* 1 usec */
+#define CQ_TIMER_THRESH_MAX     25 /* 25 usec */
+
+/* Min number of CQs (of the ones mapped to this CINT)
+ * with valid CQEs.
+ */
+#define CQ_QCOUNT_DEFAULT	1
+
 struct otx2_snd_queue {
 	u8			aura_id;
 	u16			sqe_size;
@@ -52,6 +68,20 @@ struct otx2_snd_queue {
 	u64			*sqb_ptrs;
 } ____cacheline_aligned_in_smp;
 
+enum cq_type {
+	CQ_RX,
+	CQ_TX,
+	CQS_PER_CINT = 2, /* RQ + SQ */
+};
+
+struct otx2_cq_poll {
+	void			*dev;
+#define CINT_INVALID_CQ		255
+	u8			cint_idx;
+	u8			cq_ids[CQS_PER_CINT];
+	struct napi_struct	napi;
+};
+
 struct otx2_pool {
 	struct qmem		*stack;
 	struct qmem		*fc_addr;
@@ -62,12 +92,6 @@ struct otx2_pool {
 	struct page		*page;
 };
 
-enum cq_type {
-	CQ_RX,
-	CQ_TX,
-	CQS_PER_CINT = 2, /* RQ + SQ */
-};
-
 struct otx2_cq_queue {
 	u8			cq_idx;
 	u8			cq_type;
@@ -86,6 +110,7 @@ struct otx2_qset {
 	u16			cq_cnt;
 	u16			xqe_size;
 	struct otx2_pool	*pool;
+	struct otx2_cq_poll	*napi;
 	struct otx2_cq_queue	*cq;
 	struct otx2_snd_queue	*sq;
 };
@@ -99,4 +124,5 @@ static inline u64 otx2_iova_to_phys(void *iommu_domain, dma_addr_t dma_addr)
 	return dma_addr;
 }
 
+int otx2_napi_handler(struct napi_struct *napi, int budget);
 #endif /* OTX2_TXRX_H */
Signature · 1 line
2.7.4
#18 lore raw

PATCH v4 6/17 octeontx2-pf: Receive packet handling support

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Added receive packet handling (NAPI) support, error stats, RX_ALL capability config option to passon error pkts to stack upon user request.

In subsequent patches these error stats will be added to ethttool.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  44 +++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  16 +-
 .../ethernet/marvell/octeontx2/nic/otx2_struct.h   | 195 +++++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 185 ++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |   2 +
 6 files changed, 441 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +2 -0
index 0d55131..5f31cf8 100644
@@ -337,6 +337,7 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 	cq->cq_idx = qidx;
 	if (qidx < pfvf->hw.rx_queues) {
 		cq->cq_type = CQ_RX;
+		cq->cint_idx = qidx;
 		cq->cqe_cnt = qset->rqe_cnt;
 	} else {
 		cq->cq_type = CQ_TX;
@@ -367,6 +368,7 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 	aq->cq.qsize = Q_SIZE(cq->cqe_cnt, 4);
 	aq->cq.caching = 1;
 	aq->cq.base = cq->cqe->iova;
+	aq->cq.cint_idx = cq->cint_idx;
 	aq->cq.avg_level = 255;
 
 	if (qidx < pfvf->hw.rx_queues) {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +44 -0

62 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +15 -1
index d15e089..1f03fd6 100644
@@ -547,9 +547,11 @@ static int otx2_init_hw_resources(struct otx2_nic *pf)
 
 static void otx2_free_hw_resources(struct otx2_nic *pf)
 {
+	struct otx2_qset *qset = &pf->qset;
 	struct mbox *mbox = &pf->mbox;
+	struct otx2_cq_queue *cq;
 	struct msg_req *req;
-	int err;
+	int qidx, err;
 
 	/* Ensure all SQE are processed */
 	otx2_sqb_flush(pf);
@@ -562,6 +564,13 @@ static void otx2_free_hw_resources(struct otx2_nic *pf)
 	/* Disable RQs */
 	otx2_ctx_disable(mbox, NIX_AQ_CTYPE_RQ, false);
 
+	/*Dequeue all CQEs */
+	for (qidx = 0; qidx < qset->cq_cnt; qidx++) {
+		cq = &qset->cq[qidx];
+		if (cq->cq_type == CQ_RX)
+			otx2_cleanup_rx_cqes(pf, cq);
+	}
+
 	otx2_free_sq_res(pf);
 
 	/* Free RQ buffer pointers*/
@@ -910,6 +919,11 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	 */
 	pf->iommu_domain = iommu_get_domain_for_dev(dev);
 
+	netdev->hw_features = NETIF_F_RXCSUM;
+	netdev->features |= netdev->hw_features;
+
+	netdev->hw_features |= NETIF_F_RXALL;
+
 	netdev->netdev_ops = &otx2_netdev_ops;
 
 	err = register_netdev(netdev);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +195 -0

199 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +183 -2

198 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +2 -0
index a81bdc6..0944c17 100644
@@ -95,9 +95,11 @@ struct otx2_pool {
 struct otx2_cq_queue {
 	u8			cq_idx;
 	u8			cq_type;
+	u8			cint_idx; /* CQ interrupt id */
 	u16			cqe_size;
 	u16			pool_ptrs;
 	u32			cqe_cnt;
+	u32			cq_head;
 	void			*cqe_base;
 	struct qmem		*cqe;
 	struct otx2_pool	*rbpool;
Signature · 1 line
2.7.4
maintainer
#19 lore raw

Re: [PATCH v4 06/17] octeontx2-pf: Receive packet handling support

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c line 146

Quoted 9 lines · On Tue, 21 Jan 2020 18:51:40 +0530, [email protected] wrote:

static int otx2_rx_napi_handler(struct otx2_nic *pfvf,

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +5 -0
 				struct napi_struct *napi,
 				struct otx2_cq_queue *cq, int budget)
 
+	int processed_cqe = 0;
+	s64 bufptr;
+
+	/* Make sure HW writes to CQ are done */
+	dma_rmb();

What is this memory barrier between?

Usually dma_rmb() barrier is placed between accesses to the part of the descriptor which tells us device is done and the rest of descriptor accesses.

Quoted 16 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +16 -0
+	while (likely(processed_cqe < budget)) {
+		cqe = (struct nix_cqe_rx_s *)CQE_ADDR(cq, cq->cq_head);
+		if (cqe->hdr.cqe_type == NIX_XQE_TYPE_INVALID ||
+		    !cqe->sg.subdc) {
+			if (!processed_cqe)
+				return 0;
+			break;
+		}
+		cq->cq_head++;
+		cq->cq_head &= (cq->cqe_cnt - 1);
+
+		otx2_rcv_pkt_handler(pfvf, napi, cq, cqe);
+
+		cqe->hdr.cqe_type = NIX_XQE_TYPE_INVALID;
+		cqe->sg.subdc = NIX_SUBDC_NOP;
+		processed_cqe++;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +9 -0
+	}
 
+void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
+{
+	struct nix_cqe_rx_s *cqe;
+	int processed_cqe = 0;
+	u64 iova, pa;
+
+	/* Make sure HW writes to CQ are done */
+	dma_rmb();

ditto

Quoted 14 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +14 -0
+	while ((cqe = (struct nix_cqe_rx_s *)otx2_get_next_cqe(cq))) {
+		if (!cqe->sg.subdc)
+			continue;
+		iova = cqe->sg.seg_addr - OTX2_HEAD_ROOM;
+		pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
+		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize, DMA_FROM_DEVICE);
+		put_page(virt_to_page(phys_to_virt(pa)));
+		processed_cqe++;
+	}
+
+	/* Free CQEs to HW */
+	otx2_write64(pfvf, NIX_LF_CQ_OP_DOOR,
+		     ((u64)cq->cq_idx << 32) | processed_cqe);
+}
#20 lore raw

Re: [PATCH v4 06/17] octeontx2-pf: Receive packet handling support

Quoted 12 lines · Jakub Kicinski

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c line 146

Quoted 9 lines · On Tue, 21 Jan 2020 18:51:40 +0530, [email protected] wrote:

static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
struct napi_struct *napi, struct otx2_cq_queue *cq, int budget)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +5 -0
+     int processed_cqe = 0;
+     s64 bufptr;
+
+     /* Make sure HW writes to CQ are done */
+     dma_rmb();
Quoted 6 lines

What is this memory barrier between?

Usually dma_rmb() barrier is placed between accesses to the part of the descriptor which tells us device is done and the rest of descriptor accesses.

Will recheck, i think this can be removed.
Previously the logic was different and used to read number of valid descriptor count from HW
and a barrier between that and descriptor processing was needed.

Thanks,
Sunil.

#21 lore raw

Re: [PATCH v4 06/17] octeontx2-pf: Receive packet handling support

In reply to [email protected]
Quoted 17 lines · On Tue, Jan 21, 2020 at 06:51:40PM +0530, [email protected] wrote:

From: Sunil Goutham <[email protected]>

Added receive packet handling (NAPI) support, error stats, RX_ALL capability config option to passon error pkts to stack upon user request.

In subsequent patches these error stats will be added to ethttool.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  44 +++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  16 +-
 .../ethernet/marvell/octeontx2/nic/otx2_struct.h   | 195 +++++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 185 ++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |   2 +
 6 files changed, 441 insertions(+), 3 deletions(-)

<snip>

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c line 36

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +2 -0
+static void otx2_skb_add_frag(struct otx2_nic *pfvf, struct sk_buff *skb,
+			      u64 iova, int len, struct nix_rx_parse_s *parse)

Nit: 'parse' is unused in this function.

Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +12 -0
+{
+	struct page *page;
+	void *va;
+
+	va = phys_to_virt(otx2_iova_to_phys(pfvf->iommu_domain, iova));
+	page = virt_to_page(va);
+	skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
+			va - page_address(page), len, pfvf->rbsize);
+
+	otx2_dma_unmap_page(pfvf, iova - OTX2_HEAD_ROOM,
+			    pfvf->rbsize, DMA_FROM_DEVICE);
+}

<snip>

#22 lore raw

PATCH v4 7/17 octeontx2-pf: Add packet transmission support

In reply to [email protected]

From: Sunil Goutham <[email protected]>

This patch adds the packet transmission support.
For a given skb prepares send queue descriptors (SQEs) and pushes them to HW. Here driver doesn't maintain it's own SQ rings, SQEs are pushed to HW using a silicon specific operations called LMTST. From the instuction HW derives the transmit queue number and queues the SQE to that queue. These LMTST instructions are designed to avoid queue maintenance in SW and lockless behavior ie when multiple cores are trying to add SQEs to same queue then HW will takecare of serialization, no need for SW to hold locks.

Also supports scatter/gather.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |   7 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  13 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  41 ++-
 .../ethernet/marvell/octeontx2/nic/otx2_struct.h   | 185 +++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 299 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |  14 +
 6 files changed, 557 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +7 -0
index 5f31cf8..f7726a1 100644
@@ -290,9 +290,15 @@ static int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura)
 		return err;
 
 	sq->sqe_base = sq->sqe->base;
+	sq->sg = kcalloc(qset->sqe_cnt, sizeof(struct sg_list), GFP_KERNEL);
+	if (!sq->sg)
+		return -ENOMEM;
 
+	sq->head = 0;
 	sq->sqe_per_sqb = (pfvf->hw.sqb_size / sq->sqe_size) - 1;
 	sq->num_sqbs = (qset->sqe_cnt + sq->sqe_per_sqb) / sq->sqe_per_sqb;
+	/* Set SQE threshold to 10% of total SQEs */
+	sq->sqe_thresh = ((sq->num_sqbs * sq->sqe_per_sqb) * 10) / 100;
 	sq->aura_id = sqb_aura;
 	sq->aura_fc_addr = pool->fc_addr->base;
 	sq->lmt_addr = (__force u64 *)(pfvf->reg_base + LMT_LF_LMTLINEX(qidx));
@@ -341,6 +347,7 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 		cq->cqe_cnt = qset->rqe_cnt;
 	} else {
 		cq->cq_type = CQ_TX;
+		cq->cint_idx = qidx - pfvf->hw.rx_queues;
 		cq->cqe_cnt = qset->sqe_cnt;
 	}
 	cq->cqe_size = pfvf->qset.xqe_size;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +13 -0
index fb833c8..88a1a2d 100644
@@ -300,9 +300,21 @@ static inline u64 otx2_atomic64_add(u64 incr, u64 *ptr)
 	return result;
 }
 
+static inline u64 otx2_lmt_flush(uint64_t addr)
+{
+	u64 result = 0;
+
+	__asm__ volatile(".cpu  generic+lse\n"
+			 "ldeor xzr,%x[rf],[%[rs]]"
+			 : [rf]"=r"(result)
+			 : [rs]"r"(addr));
+	return result;
+}
+
 #else
 #define otx2_write128(lo, hi, addr)
 #define otx2_atomic64_add(incr, ptr)		({ *ptr = incr; })
+#define otx2_lmt_flush(addr)			({ 0; })
 #endif
 
 /* Alloc pointer from pool/aura */
@@ -475,6 +487,7 @@ dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
 			   gfp_t gfp);
 void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
 void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
+void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
 
 /* Mbox handlers */
 void mbox_handler_msix_offset(struct otx2_nic *pfvf,
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +40 -1

68 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +185 -0

207 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +298 -1

320 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +14 -0
index 0944c17..d9683c3 100644
@@ -22,6 +22,8 @@
 #define OTX2_DATA_ALIGN(X)	ALIGN(X, OTX2_ALIGN)
 #define OTX2_HEAD_ROOM		OTX2_ALIGN
 
+#define OTX2_MAX_FRAGS_IN_SQE	9
+
 /* Rx buffer size should be in multiples of 128bytes */
 #define RCV_FRAG_LEN1(x)				\
 		((OTX2_HEAD_ROOM + OTX2_DATA_ALIGN(x)) + \
@@ -53,17 +55,27 @@
  */
 #define CQ_QCOUNT_DEFAULT	1
 
+struct sg_list {
+	u16	num_segs;
+	u64	skb;
+	u64	size[OTX2_MAX_FRAGS_IN_SQE];
+	u64	dma_addr[OTX2_MAX_FRAGS_IN_SQE];
+};
+
 struct otx2_snd_queue {
 	u8			aura_id;
+	u16			head;
 	u16			sqe_size;
 	u32			sqe_cnt;
 	u16			num_sqbs;
+	u16			sqe_thresh;
 	u8			sqe_per_sqb;
 	u64			 io_addr;
 	u64			*aura_fc_addr;
 	u64			*lmt_addr;
 	void			*sqe_base;
 	struct qmem		*sqe;
+	struct sg_list		*sg;
 	u16			sqb_count;
 	u64			*sqb_ptrs;
 } ____cacheline_aligned_in_smp;
@@ -127,4 +139,6 @@ static inline u64 otx2_iova_to_phys(void *iommu_domain, dma_addr_t dma_addr)
 }
 
 int otx2_napi_handler(struct napi_struct *napi, int budget);
+bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq,
+			struct sk_buff *skb, u16 qidx);
 #endif /* OTX2_TXRX_H */
Signature · 1 line
2.7.4
maintainer
#23 lore raw

Re: [PATCH v4 07/17] octeontx2-pf: Add packet transmission support

Quoted 18 lines · On Tue, 21 Jan 2020 18:51:41 +0530, [email protected] wrote:

From: Sunil Goutham <[email protected]>

This patch adds the packet transmission support.
For a given skb prepares send queue descriptors (SQEs) and pushes them to HW. Here driver doesn't maintain it's own SQ rings, SQEs are pushed to HW using a silicon specific operations called LMTST. From the instuction HW derives the transmit queue number and queues the SQE to that queue. These LMTST instructions are designed to avoid queue maintenance in SW and lockless behavior ie when multiple cores are trying to add SQEs to same queue then HW will takecare of serialization, no need for SW to hold locks.

Also supports scatter/gather.

Review

Quoted 2 lines
(quoted diff) +2 -0
+static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
+

Spurious new line

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_stop(struct net_device *netdev) · line 755

Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +7 -0
+{
+	struct otx2_nic *pf = netdev_priv(netdev);
+	int qidx = skb_get_queue_mapping(skb);
+	struct otx2_snd_queue *sq;
+	struct netdev_queue *txq;
+
+	/* Check for minimum and maximum packet length */

You only check for min

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_stop(struct net_device *netdev) · line 765

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+	if (skb->len <= ETH_HLEN) {
+		dev_kfree_skb(skb);
+		return NETDEV_TX_OK;
+	}
+
+	sq = &pf->qset.sq[qidx];
+	txq = netdev_get_tx_queue(netdev, qidx);
+
+	if (netif_tx_queue_stopped(txq)) {
+		dev_kfree_skb(skb);

This should never happen.

Quoted 22 lines
(quoted diff) +21 -0
+	} else if (!otx2_sq_append_skb(netdev, sq, skb, qidx)) {
+		netif_tx_stop_queue(txq);
+
+		/* Check again, incase SQBs got freed up */
+		smp_mb();
+		if (((sq->num_sqbs - *sq->aura_fc_addr) * sq->sqe_per_sqb)
+							> sq->sqe_thresh)
+			netif_tx_wake_queue(txq);
+
+		return NETDEV_TX_BUSY;
+	}
+
+	return NETDEV_TX_OK;
+}
 
+/* NIX send memory subdescriptor structure */
+struct nix_sqe_mem_s {
+#if defined(__BIG_ENDIAN_BITFIELD)  /* W0 */
+	u64 subdc         : 4;
+	u64 alg           : 4;
+	u64 dsz           : 2;
+	u64 wmem          : 1;

Review

Quoted 10 lines
(quoted diff) +10 -0
+	u64 rsvd_52_16    : 37;
+	u64 offset        : 16;
+#else
+	u64 offset        : 16;
+	u64 rsvd_52_16    : 37;
+	u64 wmem          : 1;
+	u64 dsz           : 2;
+	u64 alg           : 4;
+	u64 subdc         : 4;
+#endif

Traditionally we prefer to extract the bitfields with masks and shifts manually in the kernel, rather than having those (subjectively) ugly and finicky bitfield structs. But I guess if nobody else complains this can stay :/

drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h struct nix_rx_sg_s { · line 408

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +1 -0
+	u64 addr;

Why do you care about big endian bitfields tho, if you don't care about endianness of the data itself?

Quoted 39 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +2 -0
+};
+
 #endif /* OTX2_STRUCT_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +28 -0
index e6be18d..f416603 100644
@@ -32,6 +32,78 @@ static struct nix_cqe_hdr_s *otx2_get_next_cqe(struct otx2_cq_queue *cq)
 	return cqe_hdr;
 }
 
+static unsigned int frag_num(unsigned int i)
+{
+#ifdef __BIG_ENDIAN
+	return (i & ~3) + 3 - (i & 3);
+#else
+	return i;
+#endif
+}
+
+static dma_addr_t otx2_dma_map_skb_frag(struct otx2_nic *pfvf,
+					struct sk_buff *skb, int seg, int *len)
+{
+	const skb_frag_t *frag;
+	struct page *page;
+	int offset;
+
+	/* First segment is always skb->data */
+	if (!seg) {
+		page = virt_to_page(skb->data);
+		offset = offset_in_page(skb->data);
+		*len = skb_headlen(skb);
+	} else {
+		frag = &skb_shinfo(skb)->frags[seg - 1];
+		page = skb_frag_page(frag);
+		offset = skb_frag_off(frag);
+		*len = skb_frag_size(frag);
+	}
+	return otx2_dma_map_page(pfvf, page, offset, *len, DMA_TO_DEVICE);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static struct nix_cqe_hdr_s *otx2_get_next_cqe(struct otx2_cq_queue *cq) · line 72

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +10 -0
+}
+
+static void otx2_dma_unmap_skb_frags(struct otx2_nic *pfvf, struct sg_list *sg)
+{
+	int seg;
+
+	for (seg = 0; seg < sg->num_segs; seg++) {
+		otx2_dma_unmap_page(pfvf, sg->dma_addr[seg],
+				    sg->size[seg], DMA_TO_DEVICE);
+	}

no need for parenthesis

Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +7 -0
+	sg->num_segs = 0;
+}
+
+static void otx2_snd_pkt_handler(struct otx2_nic *pfvf,
+				 struct otx2_cq_queue *cq,
+				 struct otx2_snd_queue *sq,
+				 struct nix_cqe_tx_s *cqe,

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static struct nix_cqe_hdr_s *otx2_get_next_cqe(struct otx2_cq_queue *cq) · line 89

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +10 -0
+				 int budget, int *tx_pkts, int *tx_bytes)
+{
+	struct nix_send_comp_s *snd_comp = &cqe->comp;
+	struct sk_buff *skb = NULL;
+	struct sg_list *sg;
+
+	if (unlikely(snd_comp->status)) {
+		netdev_info(pfvf->netdev,
+			    "TX%d: Error in send CQ status:%x\n",
+			    cq->cint_idx, snd_comp->status);

This should probably be ratelimitted

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static struct nix_cqe_hdr_s *otx2_get_next_cqe(struct otx2_cq_queue *cq) · line 90

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
+	}

unnecessary parenthesis

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static struct nix_cqe_hdr_s *otx2_get_next_cqe(struct otx2_cq_queue *cq) · line 93

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +3 -0
+
+	/* Barrier, so that update to sq by other cpus is visible */
+	smp_mb();

Could you please rephrase this comment to explain between what and what this barrier is? :S

Quoted 15 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +13 -0
+	sg = &sq->sg[snd_comp->sqe_id];
+
+	skb = (struct sk_buff *)sg->skb;
+	if (unlikely(!skb))
+		return;
+
+	*tx_bytes += skb->len;
+	(*tx_pkts)++;
+	otx2_dma_unmap_skb_frags(pfvf, sg);
+	napi_consume_skb(skb, budget);
+	sg->skb = (u64)NULL;
+}
+
 

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c int otx2_napi_handler(struct napi_struct *napi, int budget) · line 338

Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +5 -0
@@ -225,6 +331,169 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 	return workdone;
 }
 
+static void otx2_sqe_flush(struct otx2_snd_queue *sq, int size)
+{
+	u64 status;
+
+	/* Packet data stores should finish before SQE is flushed to HW */

Packet data is synced by the dma operations the barrier shouldn't be needed AFAIK (and if it would be, dma_wmb() would not be the one, as it only works for iomem AFAIU).

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +10 -0
+	dma_wmb();
+
+	do {
+		memcpy(sq->lmt_addr, sq->sqe_base, size);
+		status = otx2_lmt_flush(sq->io_addr);
+	} while (status == 0);
+
+	sq->head++;
+	sq->head &= (sq->sqe_cnt - 1);
+}
#24 lore raw

Re: [PATCH v4 07/17] octeontx2-pf: Add packet transmission support

Quoted 25 lines · Jakub Kicinski
Quoted 18 lines · On Tue, 21 Jan 2020 18:51:41 +0530, [email protected] wrote:

From: Sunil Goutham <[email protected]>

This patch adds the packet transmission support.
For a given skb prepares send queue descriptors (SQEs) and pushes them to HW. Here driver doesn't maintain it's own SQ rings, SQEs are pushed to HW using a silicon specific operations called LMTST. From the instuction HW derives the transmit queue number and queues the SQE to that queue. These LMTST instructions are designed to avoid queue maintenance in SW and lockless behavior ie when multiple cores are trying to add SQEs to same queue then HW will takecare of serialization, no need for SW to hold locks.

Also supports scatter/gather.

Review

Quoted 2 lines
(quoted diff) +2 -0
+static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
+

Spurious new line

Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_stop(struct net_device *netdev) · line 755

Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +7 -0
+{
+     struct otx2_nic *pf = netdev_priv(netdev);
+     int qidx = skb_get_queue_mapping(skb);
+     struct otx2_snd_queue *sq;
+     struct netdev_queue *txq;
+
+     /* Check for minimum and maximum packet length */

You only check for min

Hmm.. will fix the comment.

Quoted 52 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_stop(struct net_device *netdev) · line 765

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+     if (skb->len <= ETH_HLEN) {
+             dev_kfree_skb(skb);
+             return NETDEV_TX_OK;
+     }
+
+     sq = &pf->qset.sq[qidx];
+     txq = netdev_get_tx_queue(netdev, qidx);
+
+     if (netif_tx_queue_stopped(txq)) {
+             dev_kfree_skb(skb);

This should never happen.

Quoted 22 lines
(quoted diff) +21 -0
+     } else if (!otx2_sq_append_skb(netdev, sq, skb, qidx)) {
+             netif_tx_stop_queue(txq);
+
+             /* Check again, incase SQBs got freed up */
+             smp_mb();
+             if (((sq->num_sqbs - *sq->aura_fc_addr) * sq->sqe_per_sqb)
+                                                     > sq->sqe_thresh)
+                     netif_tx_wake_queue(txq);
+
+             return NETDEV_TX_BUSY;
+     }
+
+     return NETDEV_TX_OK;
+}
 
+/* NIX send memory subdescriptor structure */
+struct nix_sqe_mem_s {
+#if defined(__BIG_ENDIAN_BITFIELD)  /* W0 */
+     u64 subdc         : 4;
+     u64 alg           : 4;
+     u64 dsz           : 2;
+     u64 wmem          : 1;

Review

Quoted 10 lines
(quoted diff) +10 -0
+     u64 rsvd_52_16    : 37;
+     u64 offset        : 16;
+#else
+     u64 offset        : 16;
+     u64 rsvd_52_16    : 37;
+     u64 wmem          : 1;
+     u64 dsz           : 2;
+     u64 alg           : 4;
+     u64 subdc         : 4;
+#endif

Traditionally we prefer to extract the bitfields with masks and shifts manually in the kernel, rather than having those (subjectively) ugly and finicky bitfield structs. But I guess if nobody else complains this can stay :/

Quoted 4 lines
Quoted 1 line

+ u64 addr;

Why do you care about big endian bitfields tho, if you don't care about endianness of the data itself?

At this point of time we are not addressing big endian functionality, so few things
might be broken in that aspect. If it's preferred to remove, i will remove it.

Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +2 -0
+};
+
 #endif /* OTX2_STRUCT_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
index e6be18d..f416603 100644
@@ -32,6 +32,78 @@ static struct nix_cqe_hdr_s *otx2_get_next_cqe(struct otx2_cq_queue *cq)
      return cqe_hdr;
 }
 
 > +static void otx2_sqe_flush(struct otx2_snd_queue *sq, int size)
Quoted 10 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c int otx2_napi_handler(struct napi_struct *napi, int budget) · line 338

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +4 -0
+{
+     u64 status;
+
+     /* Packet data stores should finish before SQE is flushed to HW */

Packet data is synced by the dma operations the barrier shouldn't be needed AFAIK (and if it would be, dma_wmb() would not be the one, as it only works for iomem AFAIU).

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
+     dma_wmb();

Due to out of order execution by CPU, HW folks have suggested add a barrier to avoid scenarios where packet is transmitted before all stores from CPU are committed.
On arm64 a dmb() is less costlier than a dsb() barrier and as per HW folks a dmb(st)
is sufficient to ensure all stores from CPU are committed. And dma_wmb() uses dmb(st)
hence it is used. It's more of choice of architecture specific instruction rather than the API.

Thanks,
Sunil.

maintainer
#25 lore raw

Re: [PATCH v4 07/17] octeontx2-pf: Add packet transmission support

Quoted 6 lines · Sunil Kovvuri
Quoted 2 lines

Why do you care about big endian bitfields tho, if you don't care about endianness of the data itself?

At this point of time we are not addressing big endian functionality, so few things
might be broken in that aspect. If it's preferred to remove, i will remove it.

Yes, I think removing it would be cleaner than having it partially working. The driver depends on ARM64, anyway.

Quoted 23 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +2 -0
+};
+
 #endif /* OTX2_STRUCT_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
index e6be18d..f416603 100644
@@ -32,6 +32,78 @@ static struct nix_cqe_hdr_s *otx2_get_next_cqe(struct otx2_cq_queue *cq)
      return cqe_hdr;
 }
 
 > +static void otx2_sqe_flush(struct otx2_snd_queue *sq, int size)  
Quoted 10 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c int otx2_napi_handler(struct napi_struct *napi, int budget) · line 338

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +4 -0
+{
+     u64 status;
+
+     /* Packet data stores should finish before SQE is flushed to HW */  

Packet data is synced by the dma operations the barrier shouldn't be needed AFAIK (and if it would be, dma_wmb() would not be the one, as it only works for iomem AFAIU).

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
+     dma_wmb();  
Quoted 9 lines

Due to out of order execution by CPU, HW folks have suggested add a barrier to avoid scenarios where packet is transmitted before all stores from CPU are committed.
On arm64 a dmb() is less costlier than a dsb() barrier and as per HW folks a dmb(st)
is sufficient to ensure all stores from CPU are committed. And dma_wmb() uses dmb(st)
hence it is used. It's more of choice of architecture specific instruction rather than the API.

Hmm.. I'm not a DMA API expert but AFAIU it'd be a serious bug if dma_map..() APIs didn't guarantee that packet data is written out. Not only out of the CPU store buffer but also the caches to DRAM.

#26 lore raw

PATCH v4 8/17 octeontx2-pf: Register and handle link notifications

In reply to [email protected]

From: Linu Cherian <[email protected]>

PF and AF (admin function) shares 64KB of reserved memory region for communication. This region is shared for
- Messages sent by PF and responses sent by AF.
- Notifications sent by AF and ACKs sent by PF.

This patch adds infrastructure to handle notifications sent by AF and adds handlers to process them.

One of the main usecase of notifications from AF is physical link changes. So this patch adds registration of PF with AF to receive link status change notifications and also adds the handler for that notification.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  5 ++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 79 ++++++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 25 +++++++
 3 files changed, 109 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +5 -0
index 88a1a2d..888003e 100644
@@ -135,6 +135,9 @@ struct otx2_nic {
 	void			*iommu_domain;
 	u16			rbsize; /* Receive buffer size */
 
+#define OTX2_FLAG_INTF_DOWN			BIT_ULL(2)
+	u64			flags;
+
 	struct otx2_qset	qset;
 	struct otx2_hw		hw;
 	struct pci_dev		*pdev;
@@ -145,6 +148,7 @@ struct otx2_nic {
 	struct workqueue_struct *mbox_wq;
 
 	u16			pcifunc; /* RVU PF_FUNC */
+	struct cgx_link_user_info linfo;
 
 	/* Block address of NIX either BLKADDR_NIX0 or BLKADDR_NIX1 */
 	int			nix_blkaddr;
@@ -485,6 +489,7 @@ int otx2_txschq_stop(struct otx2_nic *pfvf);
 void otx2_sqb_flush(struct otx2_nic *pfvf);
 dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
 			   gfp_t gfp);
+int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable);
 void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
 void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
 void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +79 -0

121 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +25 -0
index f416603..364fdbd 100644
@@ -324,6 +324,10 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 	otx2_write64(pfvf, NIX_LF_CINTX_INT(cq_poll->cint_idx), BIT_ULL(0));
 
 	if (workdone < budget && napi_complete_done(napi, workdone)) {
+		/* If interface is going down, don't re-enable IRQ */
+		if (pfvf->flags & OTX2_FLAG_INTF_DOWN)
+			return workdone;
+
 		/* Re-enable interrupts */
 		otx2_write64(pfvf, NIX_LF_CINTX_ENA_W1S(cq_poll->cint_idx),
 			     BIT_ULL(0));
@@ -544,3 +548,24 @@ void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
 	otx2_write64(pfvf, NIX_LF_CQ_OP_DOOR,
 		     ((u64)cq->cq_idx << 32) | processed_cqe);
 }
+
+int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable)
+{
+	struct msg_req *msg;
+	int err;
+
+	otx2_mbox_lock(&pfvf->mbox);
+	if (enable)
+		msg = otx2_mbox_alloc_msg_nix_lf_start_rx(&pfvf->mbox);
+	else
+		msg = otx2_mbox_alloc_msg_nix_lf_stop_rx(&pfvf->mbox);
+
+	if (!msg) {
+		otx2_mbox_unlock(&pfvf->mbox);
+		return -ENOMEM;
+	}
+
+	err = otx2_sync_mbox_msg(&pfvf->mbox);
+	otx2_mbox_unlock(&pfvf->mbox);
+	return err;
+}
Signature · 1 line
2.7.4
#27 lore raw

PATCH v4 9/17 octeontx2-pf: MTU, MAC and RX mode config support

In reply to [email protected]

From: Sunil Goutham <[email protected]>

This patch addes support to change interface MTU, MAC address retrieval and config, RX mode ie unicast, multicast and promiscuous. Also added link loopback support

---
 drivers/net/ethernet/marvell/octeontx2/af/mbox.h   |   8 +-
 .../net/ethernet/marvell/octeontx2/af/rvu_nix.c    |  17 ++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 108 +++++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   8 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 103 +++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |   4 +
 6 files changed, 242 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +7 -1
index a589748..8bbc1f1 100644
@@ -210,7 +210,8 @@ M(NIX_SET_RX_CFG,	0x8010, nix_set_rx_cfg, nix_rx_cfg, msg_rsp)	\
 M(NIX_LSO_FORMAT_CFG,	0x8011, nix_lso_format_cfg,			\
 				 nix_lso_format_cfg,			\
 				 nix_lso_format_cfg_rsp)		\
-M(NIX_RXVLAN_ALLOC,	0x8012, nix_rxvlan_alloc, msg_req, msg_rsp)
+M(NIX_RXVLAN_ALLOC,	0x8012, nix_rxvlan_alloc, msg_req, msg_rsp)	\
+M(NIX_GET_MAC_ADDR, 0x8018, nix_get_mac_addr, msg_req, nix_get_mac_addr_rsp) \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES						\
@@ -618,6 +619,11 @@ struct nix_set_mac_addr {
 	u8 mac_addr[ETH_ALEN]; /* MAC address to be set for this pcifunc */
 };
 
+struct nix_get_mac_addr_rsp {
+	struct mbox_msghdr hdr;
+	u8 mac_addr[ETH_ALEN];
+};
+
 struct nix_mark_format_cfg {
 	struct mbox_msghdr hdr;
 	u8 offset;
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +17 -0
index 8a59f7d..eb5e542 100644
@@ -2546,6 +2546,23 @@ int rvu_mbox_handler_nix_set_mac_addr(struct rvu *rvu,
 	return 0;
 }
 
+int rvu_mbox_handler_nix_get_mac_addr(struct rvu *rvu,
+				      struct msg_req *req,
+				      struct nix_get_mac_addr_rsp *rsp)
+{
+	u16 pcifunc = req->hdr.pcifunc;
+	struct rvu_pfvf *pfvf;
+
+	if (!is_nixlf_attached(rvu, pcifunc))
+		return NIX_AF_ERR_AF_LF_INVALID;
+
+	pfvf = rvu_get_pfvf(rvu, pcifunc);
+
+	ether_addr_copy(rsp->mac_addr, pfvf->mac_addr);
+
+	return 0;
+}
+
 int rvu_mbox_handler_nix_set_rx_mode(struct rvu *rvu, struct nix_rx_mode *req,
 				     struct msg_rsp *rsp)
 {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +108 -0

126 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +7 -1
index 888003e..bc7344e 100644
@@ -133,6 +133,7 @@ struct otx2_nic {
 	void __iomem		*reg_base;
 	struct net_device	*netdev;
 	void			*iommu_domain;
+	u16			max_frs;
 	u16			rbsize; /* Receive buffer size */
 
 #define OTX2_FLAG_INTF_DOWN			BIT_ULL(2)
@@ -469,7 +470,9 @@ static inline void otx2_dma_unmap_page(struct otx2_nic *pfvf,
 /* MSI-X APIs */
 void otx2_free_cints(struct otx2_nic *pfvf, int n);
 void otx2_set_cints_affinity(struct otx2_nic *pfvf);
-
+int otx2_set_mac_address(struct net_device *netdev, void *p);
+int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu);
+void otx2_get_mac_from_af(struct net_device *netdev);
 void otx2_config_irq_coalescing(struct otx2_nic *pfvf, int qidx);
 
 /* RVU block related APIs */
@@ -503,4 +506,7 @@ void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 			       struct nix_lf_alloc_rsp *rsp);
 void mbox_handler_nix_txsch_alloc(struct otx2_nic *pf,
 				  struct nix_txsch_alloc_rsp *rsp);
+
+int otx2_open(struct net_device *netdev);
+int otx2_stop(struct net_device *netdev);
 #endif /* OTX2_COMMON_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +99 -4

170 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +4 -0
index d9683c3..bad2259 100644
@@ -22,6 +22,10 @@
 #define OTX2_DATA_ALIGN(X)	ALIGN(X, OTX2_ALIGN)
 #define OTX2_HEAD_ROOM		OTX2_ALIGN
 
+#define	OTX2_ETH_HLEN		(VLAN_ETH_HLEN + VLAN_HLEN)
+#define	OTX2_MIN_MTU		64
+#define	OTX2_MAX_MTU		(9212 - OTX2_ETH_HLEN)
+
 #define OTX2_MAX_FRAGS_IN_SQE	9
 
 /* Rx buffer size should be in multiples of 128bytes */
Signature · 1 line
2.7.4
#28 lore raw

PATCH v4 10/17 octeontx2-pf: Error handling support

In reply to [email protected]

From: Geetha sowjanya <[email protected]>

HW reports many errors on the receive and transmit paths. Such as incorrect queue configuration, pkt transmission errors, LMTST instruction errors, transmit queue full etc. These are reported via QINT interrupt. Most of the errors are fatal and needs reinitialization.

Also added support to allocate receive buffers in non-atomic context when allocation fails in NAPI context.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  63 ++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  13 ++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 133 ++++++++++++++++++++-
 .../ethernet/marvell/octeontx2/nic/otx2_struct.h   |  28 +++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |  20 +++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |   1 +
 6 files changed, 255 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +63 -0
index a7bd23e..738d366 100644
@@ -154,6 +154,13 @@ dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
 	return iova;
 }
 
+void otx2_tx_timeout(struct net_device *netdev, unsigned int txq)
+{
+	struct otx2_nic *pfvf = netdev_priv(netdev);
+
+	schedule_work(&pfvf->reset_task);
+}
+
 void otx2_get_mac_from_af(struct net_device *netdev)
 {
 	struct otx2_nic *pfvf = netdev_priv(netdev);
@@ -365,6 +372,7 @@ static int otx2_rq_init(struct otx2_nic *pfvf, u16 qidx, u16 lpb_aura)
 	aq->rq.lpb_sizem1 = (DMA_BUFFER_LEN(pfvf->rbsize) / 8) - 1;
 	aq->rq.xqe_imm_size = 0; /* Copying of packet to CQE not needed */
 	aq->rq.flow_tagw = 32; /* Copy full 32bit flow_tag to CQE header */
+	aq->rq.qint_idx = 0;
 	aq->rq.lpb_drop_ena = 1; /* Enable RED dropping for AURA */
 	aq->rq.xqe_drop_ena = 1; /* Enable RED dropping for CQ/SSO */
 	aq->rq.xqe_pass = RQ_PASS_LVL_CQ(pfvf->hw.rq_skid, qset->rqe_cnt);
@@ -427,6 +435,8 @@ static int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura)
 	aq->sq.default_chan = pfvf->hw.tx_chan_base;
 	aq->sq.sqe_stype = NIX_STYPE_STF; /* Cache SQB */
 	aq->sq.sqb_aura = sqb_aura;
+	aq->sq.sq_int_ena = NIX_SQINT_BITS;
+	aq->sq.qint_idx = 0;
 	/* Due pipelining impact minimum 2000 unused SQ CQE's
 	 * need to maintain to avoid CQ overflow.
 	 */
@@ -473,6 +483,7 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 	pool_id = ((cq->cq_type == CQ_RX) &&
 		   (pfvf->hw.rqpool_cnt != pfvf->hw.rx_queues)) ? 0 : qidx;
 	cq->rbpool = &qset->pool[pool_id];
+	cq->refill_task_sched = false;
 
 	/* Get memory to put this msg */
 	aq = otx2_mbox_alloc_msg_nix_aq_enq(&pfvf->mbox);
@@ -484,6 +495,8 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 	aq->cq.caching = 1;
 	aq->cq.base = cq->cqe->iova;
 	aq->cq.cint_idx = cq->cint_idx;
+	aq->cq.cq_err_int_ena = NIX_CQERRINT_BITS;
+	aq->cq.qint_idx = 0;
 	aq->cq.avg_level = 255;
 
 	if (qidx < pfvf->hw.rx_queues) {
@@ -499,6 +512,45 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 	return otx2_sync_mbox_msg(&pfvf->mbox);
 }
 
+static void otx2_pool_refill_task(struct work_struct *work)
+{
+	struct otx2_cq_queue *cq;
+	struct otx2_pool *rbpool;
+	struct refill_work *wrk;
+	int qidx, free_ptrs = 0;
+	struct otx2_nic *pfvf;
+	s64 bufptr;
+
+	wrk = container_of(work, struct refill_work, pool_refill_work.work);
+	pfvf = wrk->pf;
+	qidx = wrk - pfvf->refill_wrk;
+	cq = &pfvf->qset.cq[qidx];
+	rbpool = cq->rbpool;
+	free_ptrs = cq->pool_ptrs;
+
+	while (cq->pool_ptrs) {
+		bufptr = otx2_alloc_rbuf(pfvf, rbpool, GFP_KERNEL);
+		if (bufptr <= 0) {
+			/* Schedule a WQ if we fails to free atleast half of the
+			 * pointers else enable napi for this RQ.
+			 */
+			if (!((free_ptrs - cq->pool_ptrs) > free_ptrs / 2)) {
+				struct delayed_work *dwork;
+
+				dwork = &wrk->pool_refill_work;
+				schedule_delayed_work(dwork,
+						      msecs_to_jiffies(100));
+			} else {
+				cq->refill_task_sched = false;
+			}
+			return;
+		}
+		otx2_aura_freeptr(pfvf, qidx, bufptr + OTX2_HEAD_ROOM);
+		cq->pool_ptrs--;
+	}
+	cq->refill_task_sched = false;
+}
+
 int otx2_config_nix_queues(struct otx2_nic *pfvf)
 {
 	int qidx, err;
@@ -528,6 +580,17 @@ int otx2_config_nix_queues(struct otx2_nic *pfvf)
 			return err;
 	}
 
+	/* Initialize work queue for receive buffer refill */
+	pfvf->refill_wrk = devm_kcalloc(pfvf->dev, pfvf->qset.cq_cnt,
+					sizeof(struct refill_work), GFP_KERNEL);
+	if (!pfvf->refill_wrk)
+		return -ENOMEM;
+
+	for (qidx = 0; qidx < pfvf->qset.cq_cnt; qidx++) {
+		pfvf->refill_wrk[qidx].pf = pfvf;
+		INIT_DELAYED_WORK(&pfvf->refill_wrk[qidx].pool_refill_work,
+				  otx2_pool_refill_task);
+	}
 	return 0;
 }
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +13 -0
index bc7344e..4415920 100644
@@ -129,6 +129,11 @@ struct otx2_hw {
 	struct otx2_drv_stats	drv_stats;
 };
 
+struct refill_work {
+	struct delayed_work pool_refill_work;
+	struct otx2_nic *pf;
+};
+
 struct otx2_nic {
 	void __iomem		*reg_base;
 	struct net_device	*netdev;
@@ -151,6 +156,10 @@ struct otx2_nic {
 	u16			pcifunc; /* RVU PF_FUNC */
 	struct cgx_link_user_info linfo;
 
+	u64			reset_count;
+	struct work_struct	reset_task;
+	struct refill_work	*refill_wrk;
+
 	/* Block address of NIX either BLKADDR_NIX0 or BLKADDR_NIX1 */
 	int			nix_blkaddr;
 };
@@ -435,6 +444,9 @@ otx2_mbox_up_handler_ ## _fn_name(struct otx2_nic *pfvf,		\
 MBOX_UP_CGX_MESSAGES
 #undef M
 
+/* Time to wait before watchdog kicks off */
+#define OTX2_TX_TIMEOUT		(100 * HZ)
+
 #define	RVU_PFVF_PF_SHIFT	10
 #define	RVU_PFVF_PF_MASK	0x3F
 #define	RVU_PFVF_FUNC_SHIFT	0
@@ -472,6 +484,7 @@ void otx2_free_cints(struct otx2_nic *pfvf, int n);
 void otx2_set_cints_affinity(struct otx2_nic *pfvf);
 int otx2_set_mac_address(struct net_device *netdev, void *p);
 int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu);
+void otx2_tx_timeout(struct net_device *netdev, unsigned int txq);
 void otx2_get_mac_from_af(struct net_device *netdev);
 void otx2_config_irq_coalescing(struct otx2_nic *pfvf, int qidx);
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +132 -1

193 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +28 -0
index f0ff2cb..7230b3c 100644
@@ -408,4 +408,32 @@ struct nix_sqe_mem_s {
 	u64 addr;
 };
 
+enum nix_cqerrint_e {
+	NIX_CQERRINT_DOOR_ERR = 0,
+	NIX_CQERRINT_WR_FULL = 1,
+	NIX_CQERRINT_CQE_FAULT = 2,
+};
+
+#define NIX_CQERRINT_BITS (BIT_ULL(NIX_CQERRINT_DOOR_ERR) | \
+			   BIT_ULL(NIX_CQERRINT_CQE_FAULT))
+
+enum nix_rqint_e {
+	NIX_RQINT_DROP = 0,
+	NIX_RQINT_RED = 1,
+};
+
+#define NIX_RQINT_BITS (BIT_ULL(NIX_RQINT_DROP) | BIT_ULL(NIX_RQINT_RED))
+
+enum nix_sqint_e {
+	NIX_SQINT_LMT_ERR = 0,
+	NIX_SQINT_MNQ_ERR = 1,
+	NIX_SQINT_SEND_ERR = 2,
+	NIX_SQINT_SQB_ALLOC_FAIL = 3,
+};
+
+#define NIX_SQINT_BITS (BIT_ULL(NIX_SQINT_LMT_ERR) | \
+			BIT_ULL(NIX_SQINT_MNQ_ERR) | \
+			BIT_ULL(NIX_SQINT_SEND_ERR) | \
+			BIT_ULL(NIX_SQINT_SQB_ALLOC_FAIL))
+
 #endif /* OTX2_STRUCT_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +18 -2
index 364fdbd..cf2bbb7 100644
@@ -244,12 +244,23 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
 	/* Refill pool with new buffers */
 	while (cq->pool_ptrs) {
 		bufptr = otx2_alloc_rbuf(pfvf, cq->rbpool, GFP_ATOMIC);
-		if (unlikely(bufptr <= 0))
+		if (unlikely(bufptr <= 0)) {
+			struct refill_work *work;
+			struct delayed_work *dwork;
+
+			work = &pfvf->refill_wrk[cq->cq_idx];
+			dwork = &work->pool_refill_work;
+			/* Schedule a task if no other task is running */
+			if (!cq->refill_task_sched) {
+				cq->refill_task_sched = true;
+				schedule_delayed_work(dwork,
+						      msecs_to_jiffies(100));
+			}
 			break;
+		}
 		otx2_aura_freeptr(pfvf, cq->cq_idx, bufptr + OTX2_HEAD_ROOM);
 		cq->pool_ptrs--;
 	}
-	otx2_get_page(cq->rbpool);
 
 	return processed_cqe;
 }
@@ -313,6 +324,11 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 			continue;
 		cq = &qset->cq[cq_idx];
 		if (cq->cq_type == CQ_RX) {
+			/* If the RQ refill WQ task is running, skip napi
+			 * scheduler for this queue.
+			 */
+			if (cq->refill_task_sched)
+				continue;
 			workdone += otx2_rx_napi_handler(pfvf, napi,
 							 cq, budget);
 		} else {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +1 -0
index bad2259..a889b49 100644
@@ -112,6 +112,7 @@ struct otx2_cq_queue {
 	u8			cq_idx;
 	u8			cq_type;
 	u8			cint_idx; /* CQ interrupt id */
+	u8			refill_task_sched;
 	u16			cqe_size;
 	u16			pool_ptrs;
 	u32			cqe_cnt;
Signature · 1 line
2.7.4
#29 lore raw

PATCH v4 11/17 octeontx2-pf: Receive side scaling support

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Adds receive side scaling (RSS) support to distribute pkts/flows across multiple queues. Sets up key, indirection table etc. Also added extraction of HW calculated rxhash and adding to same to SKB ie NETIF_F_RXHASH offload support.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 122 +++++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  14 +++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |   8 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |  24 ++++
 4 files changed, 167 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +122 -0
index 738d366..7da9acd 100644
@@ -106,6 +106,126 @@ int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu)
 	return err;
 }
 
+static int otx2_set_flowkey_cfg(struct otx2_nic *pfvf)
+{
+	struct otx2_rss_info *rss = &pfvf->hw.rss_info;
+	struct nix_rss_flowkey_cfg *req;
+	int err;
+
+	otx2_mbox_lock(&pfvf->mbox);
+	req = otx2_mbox_alloc_msg_nix_rss_flowkey_cfg(&pfvf->mbox);
+	if (!req) {
+		otx2_mbox_unlock(&pfvf->mbox);
+		return -ENOMEM;
+	}
+	req->mcam_index = -1; /* Default or reserved index */
+	req->flowkey_cfg = rss->flowkey_cfg;
+	req->group = DEFAULT_RSS_CONTEXT_GROUP;
+
+	err = otx2_sync_mbox_msg(&pfvf->mbox);
+	otx2_mbox_unlock(&pfvf->mbox);
+	return err;
+}
+
+static int otx2_set_rss_table(struct otx2_nic *pfvf)
+{
+	struct otx2_rss_info *rss = &pfvf->hw.rss_info;
+	struct mbox *mbox = &pfvf->mbox;
+	struct nix_aq_enq_req *aq;
+	int idx, err;
+
+	otx2_mbox_lock(mbox);
+	/* Get memory to put this msg */
+	for (idx = 0; idx < rss->rss_size; idx++) {
+		aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
+		if (!aq) {
+			/* The shared memory buffer can be full.
+			 * Flush it and retry
+			 */
+			err = otx2_sync_mbox_msg(mbox);
+			if (err) {
+				otx2_mbox_unlock(mbox);
+				return err;
+			}
+			aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
+			if (!aq) {
+				otx2_mbox_unlock(mbox);
+				return -ENOMEM;
+			}
+		}
+
+		aq->rss.rq = rss->ind_tbl[idx];
+
+		/* Fill AQ info */
+		aq->qidx = idx;
+		aq->ctype = NIX_AQ_CTYPE_RSS;
+		aq->op = NIX_AQ_INSTOP_INIT;
+	}
+	err = otx2_sync_mbox_msg(mbox);
+	otx2_mbox_unlock(mbox);
+	return err;
+}
+
+static void otx2_set_rss_key(struct otx2_nic *pfvf)
+{
+	struct otx2_rss_info *rss = &pfvf->hw.rss_info;
+	u64 *key = (u64 *)&rss->key[4];
+	int idx;
+
+	/* 352bit or 44byte key needs to be configured as below
+	 * NIX_LF_RX_SECRETX0 = key<351:288>
+	 * NIX_LF_RX_SECRETX1 = key<287:224>
+	 * NIX_LF_RX_SECRETX2 = key<223:160>
+	 * NIX_LF_RX_SECRETX3 = key<159:96>
+	 * NIX_LF_RX_SECRETX4 = key<95:32>
+	 * NIX_LF_RX_SECRETX5<63:32> = key<31:0>
+	 */
+	otx2_write64(pfvf, NIX_LF_RX_SECRETX(5),
+		     (u64)(*((u32 *)&rss->key)) << 32);
+	idx = sizeof(rss->key) / sizeof(u64);
+	while (idx > 0) {
+		idx--;
+		otx2_write64(pfvf, NIX_LF_RX_SECRETX(idx), *key++);
+	}
+}
+
+int otx2_rss_init(struct otx2_nic *pfvf)
+{
+	struct otx2_rss_info *rss = &pfvf->hw.rss_info;
+	int idx, ret = 0;
+
+	rss->rss_size = sizeof(rss->ind_tbl);
+
+	/* Init RSS key if it is not setup already */
+	if (!rss->enable)
+		netdev_rss_key_fill(rss->key, sizeof(rss->key));
+	otx2_set_rss_key(pfvf);
+
+	if (!netif_is_rxfh_configured(pfvf->netdev)) {
+		/* Default indirection table */
+		for (idx = 0; idx < rss->rss_size; idx++)
+			rss->ind_tbl[idx] =
+				ethtool_rxfh_indir_default(idx,
+							   pfvf->hw.rx_queues);
+	}
+	ret = otx2_set_rss_table(pfvf);
+	if (ret)
+		return ret;
+
+	/* Flowkey or hash config to be used for generating flow tag */
+	rss->flowkey_cfg = rss->enable ? rss->flowkey_cfg :
+			   NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6 |
+			   NIX_FLOW_KEY_TYPE_TCP | NIX_FLOW_KEY_TYPE_UDP |
+			   NIX_FLOW_KEY_TYPE_SCTP;
+
+	ret = otx2_set_flowkey_cfg(pfvf);
+	if (ret)
+		return ret;
+
+	rss->enable = true;
+	return 0;
+}
+
 void otx2_config_irq_coalescing(struct otx2_nic *pfvf, int qidx)
 {
 	/* Configure CQE interrupt coalescing parameters
@@ -611,6 +731,8 @@ int otx2_config_nix(struct otx2_nic *pfvf)
 	nixlf->rq_cnt = pfvf->hw.rx_queues;
 	nixlf->sq_cnt = pfvf->hw.tx_queues;
 	nixlf->cq_cnt = pfvf->qset.cq_cnt;
+	nixlf->rss_sz = MAX_RSS_INDIR_TBL_SIZE;
+	nixlf->rss_grps = 1; /* Single RSS indir table supported, for now */
 	nixlf->xqe_sz = NIX_XQESZ_W16;
 	/* We don't know absolute NPA LF idx attached.
 	 * AF will replace 'RVU_DEFAULT_PF_FUNC' with
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +14 -0
index 4415920..2fd7fcc 100644
@@ -41,6 +41,16 @@ enum arua_mapped_qtypes {
 #define NIX_LF_ERR_VEC				0x81
 #define NIX_LF_POISON_VEC			0x82
 
+/* RSS configuration */
+struct otx2_rss_info {
+	u8 enable;
+	u32 flowkey_cfg;
+	u16 rss_size;
+	u8  ind_tbl[MAX_RSS_INDIR_TBL_SIZE];
+#define RSS_HASH_KEY_SIZE	44   /* 352 bit key */
+	u8  key[RSS_HASH_KEY_SIZE];
+};
+
 /* NIX (or NPC) RX errors */
 enum otx2_errlvl {
 	NPC_ERRLVL_RE,
@@ -95,6 +105,7 @@ struct  mbox {
 
 struct otx2_hw {
 	struct pci_dev		*pdev;
+	struct otx2_rss_info	rss_info;
 	u16                     rx_queues;
 	u16                     tx_queues;
 	u16			max_queues;
@@ -510,6 +521,9 @@ void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
 void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
 void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
 
+/* RSS configuration APIs*/
+int otx2_rss_init(struct otx2_nic *pfvf);
+
 /* Mbox handlers */
 void mbox_handler_msix_offset(struct otx2_nic *pfvf,
 			      struct msix_offset_rsp *rsp);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +7 -1
index 557f86b..fe5b3de 100644
@@ -838,6 +838,11 @@ int otx2_open(struct net_device *netdev)
 	if (err)
 		goto err_disable_napi;
 
+	/* Initialize RSS */
+	err = otx2_rss_init(pf);
+	if (err)
+		goto err_disable_napi;
+
 	/* Register Queue IRQ handlers */
 	vec = pf->hw.nix_msixoff + NIX_LF_QINT_VEC_START;
 	irq_name = &pf->hw.irq_name[vec * NAME_SIZE];
@@ -1249,7 +1254,8 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	pf->iommu_domain = iommu_get_domain_for_dev(dev);
 
 	netdev->hw_features = (NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
-			       NETIF_F_IPV6_CSUM | NETIF_F_SG);
+			       NETIF_F_IPV6_CSUM | NETIF_F_RXHASH |
+			       NETIF_F_SG);
 	netdev->features |= netdev->hw_features;
 
 	netdev->hw_features |= NETIF_F_LOOPBACK | NETIF_F_RXALL;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +24 -0
index cf2bbb7..f2de352 100644
@@ -119,6 +119,28 @@ static void otx2_skb_add_frag(struct otx2_nic *pfvf, struct sk_buff *skb,
 			    pfvf->rbsize, DMA_FROM_DEVICE);
 }
 
+static void otx2_set_rxhash(struct otx2_nic *pfvf,
+			    struct nix_cqe_rx_s *cqe, struct sk_buff *skb)
+{
+	enum pkt_hash_types hash_type = PKT_HASH_TYPE_NONE;
+	struct otx2_rss_info *rss;
+	u32 hash = 0;
+
+	if (!(pfvf->netdev->features & NETIF_F_RXHASH))
+		return;
+
+	rss = &pfvf->hw.rss_info;
+	if (rss->flowkey_cfg) {
+		if (rss->flowkey_cfg &
+		    ~(NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6))
+			hash_type = PKT_HASH_TYPE_L4;
+		else
+			hash_type = PKT_HASH_TYPE_L3;
+		hash = cqe->hdr.flow_tag;
+	}
+	skb_set_hash(skb, hash, hash_type);
+}
+
 static bool otx2_check_rcv_errors(struct otx2_nic *pfvf,
 				  struct nix_cqe_rx_s *cqe, int qidx)
 {
@@ -199,6 +221,8 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
 			  cqe->sg.seg_size, parse);
 	cq->pool_ptrs++;
 
+	otx2_set_rxhash(pfvf, cqe, skb);
+
 	skb_record_rx_queue(skb, cq->cq_idx);
 	if (pfvf->netdev->features & NETIF_F_RXCSUM)
 		skb->ip_summed = CHECKSUM_UNNECESSARY;
Signature · 1 line
2.7.4
#30 lore raw

PATCH v4 12/17 octeontx2-pf: TCP segmentation offload support

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Adds TCP segmentation offload (TSO) support. First version of the silicon didn't support TSO offload, for this driver level TSO support is added.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |   8 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  11 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |   7 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 247 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |   2 +
 5 files changed, 272 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +8 -0
index 7da9acd..9612b50 100644
@@ -10,6 +10,7 @@
 
 #include <linux/interrupt.h>
 #include <linux/pci.h>
+#include <net/tso.h>
 
 #include "otx2_reg.h"
 #include "otx2_common.h"
@@ -525,6 +526,11 @@ static int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura)
 	if (err)
 		return err;
 
+	err = qmem_alloc(pfvf->dev, &sq->tso_hdrs, qset->sqe_cnt,
+			 TSO_HEADER_SIZE);
+	if (err)
+		return err;
+
 	sq->sqe_base = sq->sqe->base;
 	sq->sg = kcalloc(qset->sqe_cnt, sizeof(struct sg_list), GFP_KERNEL);
 	if (!sq->sg)
@@ -1217,6 +1223,8 @@ void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 	pfvf->hw.sqb_size = rsp->sqb_size;
 	pfvf->hw.rx_chan_base = rsp->rx_chan_base;
 	pfvf->hw.tx_chan_base = rsp->tx_chan_base;
+	pfvf->hw.lso_tsov4_idx = rsp->lso_tsov4_idx;
+	pfvf->hw.lso_tsov6_idx = rsp->lso_tsov6_idx;
 }
 
 void mbox_handler_msix_offset(struct otx2_nic *pfvf,
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +11 -0
index 2fd7fcc..1d51976 100644
@@ -129,6 +129,11 @@ struct otx2_hw {
 	u16			rq_skid;
 	u8			cq_time_wait;
 
+	/* For TSO segmentation */
+	u8			lso_tsov4_idx;
+	u8			lso_tsov6_idx;
+	u8			hw_tso;
+
 	/* MSI-X*/
 	u8			cint_cnt; /* CQ interrupt count */
 	u16			npa_msixoff; /* Offset of NPA vectors */
@@ -189,11 +194,17 @@ static inline bool is_96xx_B0(struct pci_dev *pdev)
 
 static inline void otx2_setup_dev_hw_settings(struct otx2_nic *pfvf)
 {
+	struct otx2_hw *hw = &pfvf->hw;
+
 	pfvf->hw.cq_time_wait = CQ_TIMER_THRESH_DEFAULT;
 	pfvf->hw.cq_ecount_wait = CQ_CQE_THRESH_DEFAULT;
 	pfvf->hw.cq_qcount_wait = CQ_QCOUNT_DEFAULT;
 
+	hw->hw_tso = true;
+
 	if (is_96xx_A0(pfvf->pdev)) {
+		hw->hw_tso = false;
+
 		/* Time based irq coalescing is not supported */
 		pfvf->hw.cq_qcount_wait = 0x0;
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +5 -2
index fe5b3de..f163573 100644
@@ -616,6 +616,7 @@ static void otx2_free_sq_res(struct otx2_nic *pf)
 	for (qidx = 0; qidx < pf->hw.tx_queues; qidx++) {
 		sq = &qset->sq[qidx];
 		qmem_free(pf->dev, sq->sqe);
+		qmem_free(pf->dev, sq->tso_hdrs);
 		kfree(sq->sg);
 		kfree(sq->sqb_ptrs);
 	}
@@ -988,7 +989,8 @@ static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
 	struct netdev_queue *txq;
 
 	/* Check for minimum and maximum packet length */
-	if (skb->len <= ETH_HLEN) {
+	if (skb->len <= ETH_HLEN ||
+	    (!skb_shinfo(skb)->gso_size && skb->len > pf->max_frs)) {
 		dev_kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
@@ -1255,11 +1257,12 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	netdev->hw_features = (NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
 			       NETIF_F_IPV6_CSUM | NETIF_F_RXHASH |
-			       NETIF_F_SG);
+			       NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6);
 	netdev->features |= netdev->hw_features;
 
 	netdev->hw_features |= NETIF_F_LOOPBACK | NETIF_F_RXALL;
 
+	netdev->gso_max_segs = OTX2_MAX_GSO_SEGS;
 	netdev->watchdog_timeo = OTX2_TX_TIMEOUT;
 
 	netdev->netdev_ops = &otx2_netdev_ops;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +246 -1

283 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +2 -0
index a889b49..107a261 100644
@@ -26,6 +26,7 @@
 #define	OTX2_MIN_MTU		64
 #define	OTX2_MAX_MTU		(9212 - OTX2_ETH_HLEN)
 
+#define OTX2_MAX_GSO_SEGS	255
 #define OTX2_MAX_FRAGS_IN_SQE	9
 
 /* Rx buffer size should be in multiples of 128bytes */
@@ -79,6 +80,7 @@ struct otx2_snd_queue {
 	u64			*lmt_addr;
 	void			*sqe_base;
 	struct qmem		*sqe;
+	struct qmem		*tso_hdrs;
 	struct sg_list		*sg;
 	u16			sqb_count;
 	u64			*sqb_ptrs;
Signature · 1 line
2.7.4
#31 lore raw

PATCH v4 13/17 octeontx2-pf: Add ndo_get_stats64

In reply to [email protected]

From: Geetha sowjanya <[email protected]>

Added ndo_get_stats64 which returns stats maintained by HW.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 47 +++++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   | 49 ++++++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  1 +
 3 files changed, 97 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +47 -0
index 9612b50..02ac930 100644
@@ -16,6 +16,53 @@
 #include "otx2_common.h"
 #include "otx2_struct.h"
 
+void otx2_get_dev_stats(struct otx2_nic *pfvf)
+{
+	struct otx2_dev_stats *dev_stats = &pfvf->hw.dev_stats;
+
+#define OTX2_GET_RX_STATS(reg) \
+	 otx2_read64(pfvf, NIX_LF_RX_STATX(reg))
+#define OTX2_GET_TX_STATS(reg) \
+	 otx2_read64(pfvf, NIX_LF_TX_STATX(reg))
+
+	dev_stats->rx_bytes = OTX2_GET_RX_STATS(RX_OCTS);
+	dev_stats->rx_drops = OTX2_GET_RX_STATS(RX_DROP);
+	dev_stats->rx_bcast_frames = OTX2_GET_RX_STATS(RX_BCAST);
+	dev_stats->rx_mcast_frames = OTX2_GET_RX_STATS(RX_MCAST);
+	dev_stats->rx_ucast_frames = OTX2_GET_RX_STATS(RX_UCAST);
+	dev_stats->rx_frames = dev_stats->rx_bcast_frames +
+			       dev_stats->rx_mcast_frames +
+			       dev_stats->rx_ucast_frames;
+
+	dev_stats->tx_bytes = OTX2_GET_TX_STATS(TX_OCTS);
+	dev_stats->tx_drops = OTX2_GET_TX_STATS(TX_DROP);
+	dev_stats->tx_bcast_frames = OTX2_GET_TX_STATS(TX_BCAST);
+	dev_stats->tx_mcast_frames = OTX2_GET_TX_STATS(TX_MCAST);
+	dev_stats->tx_ucast_frames = OTX2_GET_TX_STATS(TX_UCAST);
+	dev_stats->tx_frames = dev_stats->tx_bcast_frames +
+			       dev_stats->tx_mcast_frames +
+			       dev_stats->tx_ucast_frames;
+}
+
+void otx2_get_stats64(struct net_device *netdev,
+		      struct rtnl_link_stats64 *stats)
+{
+	struct otx2_nic *pfvf = netdev_priv(netdev);
+	struct otx2_dev_stats *dev_stats;
+
+	otx2_get_dev_stats(pfvf);
+
+	dev_stats = &pfvf->hw.dev_stats;
+	stats->rx_bytes = dev_stats->rx_bytes;
+	stats->rx_packets = dev_stats->rx_frames;
+	stats->rx_dropped = dev_stats->rx_drops;
+	stats->multicast = dev_stats->rx_mcast_frames;
+
+	stats->tx_bytes = dev_stats->tx_bytes;
+	stats->tx_packets = dev_stats->tx_frames;
+	stats->tx_dropped = dev_stats->tx_drops;
+}
+
 /* Sync MAC address with RVU AF */
 static int otx2_hw_set_mac_addr(struct otx2_nic *pfvf, u8 *mac)
 {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +49 -0

67 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -0
index f163573..06eeaa6 100644
@@ -1076,6 +1076,7 @@ static const struct net_device_ops otx2_netdev_ops = {
 	.ndo_set_rx_mode	= otx2_set_rx_mode,
 	.ndo_set_features	= otx2_set_features,
 	.ndo_tx_timeout		= otx2_tx_timeout,
+	.ndo_get_stats64	= otx2_get_stats64,
 };
 
 static int otx2_check_pf_usable(struct otx2_nic *nic)
Signature · 1 line
2.7.4
#32 lore raw

PATCH v4 14/17 octeontx2-pf: Add basic ethtool support

In reply to [email protected]

From: Christina Jacob <[email protected]>

This patch adds ethtool support for
- Driver stats, Tx/Rx perqueue and CGX LMAC stats
- Set/show Rx/Tx queue count
- Set/show Rx/Tx ring sizes
- Set/show IRQ coalescing parameters

---
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  82 ++++-
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  10 +
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 408 +++++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  16 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.h |  11 +
 6 files changed, 525 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +1 -1
index 0484d70..41bf00c 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_OCTEONTX2_PF) += octeontx2_nicpf.o
 
-octeontx2_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o
+octeontx2_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o otx2_ethtool.o
 
 ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +81 -1

106 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +10 -0
index 76c6997..28dcfab 100644
@@ -187,6 +187,8 @@ struct otx2_hw {
 	/* Stats */
 	struct otx2_dev_stats	dev_stats;
 	struct otx2_drv_stats	drv_stats;
+	u64			cgx_rx_stats[CGX_RX_STATS_COUNT];
+	u64			cgx_tx_stats[CGX_TX_STATS_COUNT];
 };
 
 struct refill_work {
@@ -588,12 +590,20 @@ void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 			       struct nix_lf_alloc_rsp *rsp);
 void mbox_handler_nix_txsch_alloc(struct otx2_nic *pf,
 				  struct nix_txsch_alloc_rsp *rsp);
+void mbox_handler_cgx_stats(struct otx2_nic *pfvf,
+			    struct cgx_stats_rsp *rsp);
 
 /* Device stats APIs */
 void otx2_get_dev_stats(struct otx2_nic *pfvf);
 void otx2_get_stats64(struct net_device *netdev,
 		      struct rtnl_link_stats64 *stats);
+void otx2_update_lmac_stats(struct otx2_nic *pfvf);
+int otx2_update_rq_stats(struct otx2_nic *pfvf, int qidx);
+int otx2_update_sq_stats(struct otx2_nic *pfvf, int qidx);
+void otx2_set_ethtool_ops(struct net_device *netdev);
 
 int otx2_open(struct net_device *netdev);
 int otx2_stop(struct net_device *netdev);
+int otx2_set_real_num_queues(struct net_device *netdev,
+			     int tx_queues, int rx_queues);
 #endif /* OTX2_COMMON_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c new file +408 -0

408 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +14 -2
index 06eeaa6..50f6fbf 100644
@@ -148,6 +148,9 @@ static void otx2_process_pfaf_mbox_msg(struct otx2_nic *pf,
 		mbox_handler_nix_txsch_alloc(pf,
 					     (struct nix_txsch_alloc_rsp *)msg);
 		break;
+	case MBOX_MSG_CGX_STATS:
+		mbox_handler_cgx_stats(pf, (struct cgx_stats_rsp *)msg);
+		break;
 	default:
 		if (msg->rc)
 			dev_err(pf->dev,
@@ -459,8 +462,8 @@ static int otx2_cgx_config_loopback(struct otx2_nic *pf, bool enable)
 	return err;
 }
 
-static int otx2_set_real_num_queues(struct net_device *netdev,
-				    int tx_queues, int rx_queues)
+int otx2_set_real_num_queues(struct net_device *netdev,
+			     int tx_queues, int rx_queues)
 {
 	int err;
 
@@ -812,6 +815,11 @@ int otx2_open(struct net_device *netdev)
 	if (!qset->sq)
 		goto err_free_mem;
 
+	qset->rq = kcalloc(pf->hw.rx_queues,
+			   sizeof(struct otx2_rcv_queue), GFP_KERNEL);
+	if (!qset->rq)
+		goto err_free_mem;
+
 	err = otx2_init_hw_resources(pf);
 	if (err)
 		goto err_free_mem;
@@ -917,6 +925,7 @@ int otx2_open(struct net_device *netdev)
 err_free_mem:
 	kfree(qset->sq);
 	kfree(qset->cq);
+	kfree(qset->rq);
 	kfree(qset->napi);
 	return err;
 }
@@ -973,6 +982,7 @@ int otx2_stop(struct net_device *netdev)
 
 	kfree(qset->sq);
 	kfree(qset->cq);
+	kfree(qset->rq);
 	kfree(qset->napi);
 	/* Do not clear RQ/SQ ringsize settings */
 	memset((void *)qset + offsetof(struct otx2_qset, sqe_cnt), 0,
@@ -1280,6 +1290,8 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto err_detach_rsrc;
 	}
 
+	otx2_set_ethtool_ops(netdev);
+
 	/* Enable link notifications */
 	otx2_cgx_config_linkevents(pf, true);
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +11 -0
index 107a261..4ab32d3 100644
@@ -60,6 +60,15 @@
  */
 #define CQ_QCOUNT_DEFAULT	1
 
+struct queue_stats {
+	u64	bytes;
+	u64	pkts;
+};
+
+struct otx2_rcv_queue {
+	struct queue_stats	stats;
+};
+
 struct sg_list {
 	u16	num_segs;
 	u64	skb;
@@ -82,6 +91,7 @@ struct otx2_snd_queue {
 	struct qmem		*sqe;
 	struct qmem		*tso_hdrs;
 	struct sg_list		*sg;
+	struct queue_stats	stats;
 	u16			sqb_count;
 	u64			*sqb_ptrs;
 } ____cacheline_aligned_in_smp;
@@ -134,6 +144,7 @@ struct otx2_qset {
 	struct otx2_cq_poll	*napi;
 	struct otx2_cq_queue	*cq;
 	struct otx2_snd_queue	*sq;
+	struct otx2_rcv_queue	*rq;
 };
 
 /* Translate IOVA to physical address */
Signature · 1 line
2.7.4
#33 lore raw

PATCH v4 15/17 octeontx2-pf: ethtool RSS config support

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Added support to show or configure RSS hash key, indirection table, 2,4 tuple via ethtool. Also added debug msg_level support to dump messages when HW reports errors in packet received or transmitted.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |   6 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   6 +
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 254 +++++++++++++++++++++
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |  13 +-
 4 files changed, 273 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +3 -3
index a8d7966..45c1614 100644
@@ -220,7 +220,7 @@ int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu)
 	return err;
 }
 
-static int otx2_set_flowkey_cfg(struct otx2_nic *pfvf)
+int otx2_set_flowkey_cfg(struct otx2_nic *pfvf)
 {
 	struct otx2_rss_info *rss = &pfvf->hw.rss_info;
 	struct nix_rss_flowkey_cfg *req;
@@ -241,7 +241,7 @@ static int otx2_set_flowkey_cfg(struct otx2_nic *pfvf)
 	return err;
 }
 
-static int otx2_set_rss_table(struct otx2_nic *pfvf)
+int otx2_set_rss_table(struct otx2_nic *pfvf)
 {
 	struct otx2_rss_info *rss = &pfvf->hw.rss_info;
 	struct mbox *mbox = &pfvf->mbox;
@@ -280,7 +280,7 @@ static int otx2_set_rss_table(struct otx2_nic *pfvf)
 	return err;
 }
 
-static void otx2_set_rss_key(struct otx2_nic *pfvf)
+void otx2_set_rss_key(struct otx2_nic *pfvf)
 {
 	struct otx2_rss_info *rss = &pfvf->hw.rss_info;
 	u64 *key = (u64 *)&rss->key[4];
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +6 -0
index 28dcfab..31aeb48 100644
@@ -222,6 +222,9 @@ struct otx2_nic {
 	struct work_struct	reset_task;
 	struct refill_work	*refill_wrk;
 
+	/* Ethtool stuff */
+	u32			msg_enable;
+
 	/* Block address of NIX either BLKADDR_NIX0 or BLKADDR_NIX1 */
 	int			nix_blkaddr;
 };
@@ -580,6 +583,9 @@ void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
 
 /* RSS configuration APIs*/
 int otx2_rss_init(struct otx2_nic *pfvf);
+int otx2_set_flowkey_cfg(struct otx2_nic *pfvf);
+void otx2_set_rss_key(struct otx2_nic *pfvf);
+int otx2_set_rss_table(struct otx2_nic *pfvf);
 
 /* Mbox handlers */
 void mbox_handler_msix_offset(struct otx2_nic *pfvf,
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +254 -0

267 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +10 -3
index 993e045..135506f 100644
@@ -85,9 +85,11 @@ static void otx2_snd_pkt_handler(struct otx2_nic *pfvf,
 	struct sg_list *sg;
 
 	if (unlikely(snd_comp->status)) {
-		netdev_info(pfvf->netdev,
-			    "TX%d: Error in send CQ status:%x\n",
-			    cq->cint_idx, snd_comp->status);
+		if (netif_msg_tx_err(pfvf)) {
+			netdev_info(pfvf->netdev,
+				    "TX%d: Error in send CQ status:%x\n",
+				    cq->cint_idx, snd_comp->status);
+		}
 	}
 
 	/* Barrier, so that update to sq by other cpus is visible */
@@ -148,6 +150,11 @@ static bool otx2_check_rcv_errors(struct otx2_nic *pfvf,
 	struct otx2_drv_stats *stats = &pfvf->hw.drv_stats;
 	struct nix_rx_parse_s *parse = &cqe->parse;
 
+	if (netif_msg_rx_err(pfvf))
+		netdev_err(pfvf->netdev,
+			   "RQ%d: Error pkt with errlev:0x%x errcode:0x%x\n",
+			   qidx, parse->errlev, parse->errcode);
+
 	if (parse->errlev == NPC_ERRLVL_RE) {
 		switch (parse->errcode) {
 		case ERRCODE_FCS:
Signature · 1 line
2.7.4
#34 lore raw

PATCH v4 16/17 Documentation: net: octeontx2: Add RVU HW and drivers overview

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Added high level overview of OcteonTx2 RVU HW and functionality of various drivers which will be upstreamed.

---
 Documentation/networking/device_drivers/index.rst  |   1 +
 .../device_drivers/marvell/octeontx2.rst           | 159 +++++++++++++++++++++
 MAINTAINERS                                        |   1 +
 3 files changed, 161 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/marvell/octeontx2.rst
Documentation/networking/device_drivers/index.rst +1 -0
index 4bc6ff2..a191faa 100644
@@ -22,6 +22,7 @@ Contents:
    intel/iavf
    intel/ice
    google/gve
+   marvell/octeontx2
    mellanox/mlx5
    netronome/nfp
    pensando/ionic
Documentation/networking/device_drivers/marvell/octeontx2.rst new file +159 -0

159 lines not on this page · raw message

MAINTAINERS +1 -0
index 702382b..fdbb875 100644
@@ -10000,6 +10000,7 @@ M:	Jerin Jacob <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	drivers/net/ethernet/marvell/octeontx2/af/
+F:	Documentation/networking/device_drivers/marvell/octeontx2.rst
 
 MATROX FRAMEBUFFER DRIVER
 L:	[email protected]
Signature · 1 line
2.7.4
#35 lore raw

PATCH v4 17/17 MAINTAINERS: Add entry for Marvell OcteonTX2 Physical Function driver

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Added maintainers entry for Marvell OcteonTX2 SOC's physical function NIC driver.

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index fdbb875..51d7876 100644
@@ -10002,6 +10002,15 @@ S:	Supported
 F:	drivers/net/ethernet/marvell/octeontx2/af/
 F:	Documentation/networking/device_drivers/marvell/octeontx2.rst
 
+MARVELL OCTEONTX2 PHYSICAL FUNCTION DRIVER
+M:	Sunil Goutham <[email protected]>
+M:	Geetha sowjanya <[email protected]>
+M:	Subbaraya Sundeep <[email protected]>
+M:	hariprasad <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/net/ethernet/marvell/octeontx2/nic/
+
 MATROX FRAMEBUFFER DRIVER
 L:	[email protected]
 S:	Orphan
Signature · 1 line
2.7.4