Skip to contentSkip to conversation

octeontx2-vf: Add network driver for virtual function

PATCH Superseded [email protected] 3 participants 17 messages Mar 13, 2020 – Mar 15, 2020

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover octeontx2-vf: Add network driver for virtual function

From: Sunil Goutham <[email protected]>

This patch series adds network driver for the virtual functions of OcteonTX2 SOC's resource virtualization unit (RVU).

Changes from v1:
* Removed driver version and fixed authorship
* Removed driver version and fixed authorship in the already upstreamed AF, PF drivers.
* Removed unnecessary checks in sriov_enable and xmit fn()s.
* Removed WQ_MEM_RECLAIM flag while creating workqueue.
* Added lock in tx_timeout task.
* Added 'supported_coalesce_params' in ethtool ops.
* Minor other cleanups.
- Sugested by Jakub Kicinski

Geetha sowjanya (2):
octeontx2-pf: Handle VF function level reset
octeontx2-pf: Cleanup all receive buffers in SG descriptor

Sunil Goutham (2):
octeontx2-pf: Enable SRIOV and added VF mbox handling
octeontx2-af: Remove driver version and fix authorship

Tomasz Duszynski (3):
octeontx2-vf: Virtual function driver support
octeontx2-vf: Ethtool support
octeontx2-vf: Link event notification support

 drivers/net/ethernet/marvell/octeontx2/Kconfig     |   6 +
 drivers/net/ethernet/marvell/octeontx2/af/rvu.c    |   4 +-
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  23 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  27 +
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 133 +++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 774 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_reg.h  |  13 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |  35 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   | 663 ++++++++++++++++++
 10 files changed, 1662 insertions(+), 18 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/7 octeontx2-pf: Enable SRIOV and added VF mbox handling

From: Sunil Goutham <[email protected]>

Added 'sriov_configure' to enable/disable virtual functions (VFs). Also added handling of mailbox messages from these VFs.

Admin function (AF) is the only one with all priviliges to configure HW, alloc resources etc etc, PFs and it's VFs have to request AF via mbox for all their needs. But unlike PFs, their VFs cannot send a mbox request directly. A VF shares a mailbox region with it's parent PF, so VF sends a mailbox msg to PF and then PF forwards it to AF. Then AF after processing sends response to PF which it again forwards to VF.

This patch adds support for this 'VF <=> PF <=> AF' mailbox communication.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   3 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 443 +++++++++++++++++++++
 2 files changed, 446 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +3 -0
index 885c3dc..74439e1 100644
@@ -215,8 +215,11 @@ struct otx2_nic {
 
 	/* Mbox */
 	struct mbox		mbox;
+	struct mbox		*mbox_pfvf;
 	struct workqueue_struct *mbox_wq;
+	struct workqueue_struct *mbox_pfvf_wq;
 
+	u8			total_vfs;
 	u16			pcifunc; /* RVU PF_FUNC */
 	u16			bpid[NIX_MAX_BPID_CHAN];
 	struct cgx_link_user_info linfo;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +443 -0

479 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/7 octeontx2-pf: Handle VF function level reset

In reply to [email protected]

From: Geetha sowjanya <[email protected]>

When FLR is initiated for a VF (PCI function level reset), the parent PF gets a interrupt. PF then sends a message to admin function (AF), which then cleanups all resources attached to that VF.

Also handled IRQs triggered when master enable bit is cleared or set for VFs. This handler just clears the transaction pending ie TRPEND bit.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   7 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 234 ++++++++++++++++++++-
 2 files changed, 240 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +7 -0
index 74439e1..c0a9693 100644
@@ -191,6 +191,11 @@ struct otx2_hw {
 	u64			cgx_tx_stats[CGX_TX_STATS_COUNT];
 };
 
+struct flr_work {
+	struct work_struct work;
+	struct otx2_nic *pf;
+};
+
 struct refill_work {
 	struct delayed_work pool_refill_work;
 	struct otx2_nic *pf;
@@ -226,6 +231,8 @@ struct otx2_nic {
 
 	u64			reset_count;
 	struct work_struct	reset_task;
+	struct workqueue_struct	*flr_wq;
+	struct flr_work		*flr_wrk;
 	struct refill_work	*refill_wrk;
 
 	/* Ethtool stuff */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +233 -1

256 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v2 net-next 2/7] octeontx2-pf: Handle VF function level reset

Quoted 73 lines · On Fri, Mar 13, 2020 at 03:12:41PM +0530, [email protected] wrote:

From: Geetha sowjanya <[email protected]>

When FLR is initiated for a VF (PCI function level reset), the parent PF gets a interrupt. PF then sends a message to admin function (AF), which then cleanups all resources attached to that VF.

Also handled IRQs triggered when master enable bit is cleared or set for VFs. This handler just clears the transaction pending ie TRPEND bit.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   7 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 234 ++++++++++++++++++++-
 2 files changed, 240 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +7 -0
index 74439e1..c0a9693 100644
@@ -191,6 +191,11 @@ struct otx2_hw {
 	u64			cgx_tx_stats[CGX_TX_STATS_COUNT];
 };
 
+struct flr_work {
+	struct work_struct work;
+	struct otx2_nic *pf;
+};
+
 struct refill_work {
 	struct delayed_work pool_refill_work;
 	struct otx2_nic *pf;
@@ -226,6 +231,8 @@ struct otx2_nic {
 
 	u64			reset_count;
 	struct work_struct	reset_task;
+	struct workqueue_struct	*flr_wq;
+	struct flr_work		*flr_wrk;
 	struct refill_work	*refill_wrk;
 
 	/* Ethtool stuff */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +22 -0
index 967ef7b..bf6e2529 100644
@@ -61,6 +61,224 @@ static int otx2_change_mtu(struct net_device *netdev, int new_mtu)
 	return err;
 }
 
+static void otx2_disable_flr_me_intr(struct otx2_nic *pf)
+{
+	int irq, vfs = pf->total_vfs;
+
+	/* Disable VFs ME interrupts */
+	otx2_write64(pf, RVU_PF_VFME_INT_ENA_W1CX(0), INTR_MASK(vfs));
+	irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFME0);
+	free_irq(irq, pf);
+
+	/* Disable VFs FLR interrupts */
+	otx2_write64(pf, RVU_PF_VFFLR_INT_ENA_W1CX(0), INTR_MASK(vfs));
+	irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFFLR0);
+	free_irq(irq, pf);
+
+	if (vfs <= 64)
+		return;
+
+	otx2_write64(pf, RVU_PF_VFME_INT_ENA_W1CX(1), INTR_MASK(vfs - 64));
+	irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFME1);
+	free_irq(irq, pf);
+
+	otx2_write64(pf, RVU_PF_VFFLR_INT_ENA_W1CX(1), INTR_MASK(vfs - 64));

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_change_mtu(struct net_device *netdev, int new_mtu) · line 95

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+	irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFFLR1);
+	free_irq(irq, pf);
+}
+
+static void otx2_flr_wq_destroy(struct otx2_nic *pf)
+{
+	if (!pf->flr_wq)
+		return;
+	flush_workqueue(pf->flr_wq);
+	destroy_workqueue(pf->flr_wq);

destroy_workqueue() calls to drain_workqueue() which calls to flush_workqueue() in proper order and not like it is written here.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -0
+	pf->flr_wq = NULL;
+	devm_kfree(pf->dev, pf->flr_wrk);
+}
+

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_change_mtu(struct net_device *netdev, int new_mtu) · line 109

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+static void otx2_flr_handler(struct work_struct *work)
+{
+	struct flr_work *flrwork = container_of(work, struct flr_work, work);
+	struct otx2_nic *pf = flrwork->pf;
+	struct msg_req *req;
+	int vf, reg = 0;
+
+	vf = flrwork - pf->flr_wrk;
+
+	otx2_mbox_lock(&pf->mbox);

It is so bad that such function exists, it hides simple mutex_lock() which is standard primitive.

Thanks

#4 lore raw

Re: [PATCH v2 net-next 2/7] octeontx2-pf: Handle VF function level reset

Quoted 80 lines · Leon Romanovsky
Quoted 78 lines · On Fri, Mar 13, 2020 at 03:12:41PM +0530, [email protected] wrote:

From: Geetha sowjanya <[email protected]>

When FLR is initiated for a VF (PCI function level reset), the parent PF gets a interrupt. PF then sends a message to admin function (AF), which then cleanups all resources attached to that VF.

Also handled IRQs triggered when master enable bit is cleared or set for VFs. This handler just clears the transaction pending ie TRPEND bit.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   7 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 234 ++++++++++++++++++++-
 2 files changed, 240 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +7 -0
index 74439e1..c0a9693 100644
@@ -191,6 +191,11 @@ struct otx2_hw {
      u64                     cgx_tx_stats[CGX_TX_STATS_COUNT];
 };
 
+struct flr_work {
+     struct work_struct work;
+     struct otx2_nic *pf;
+};
+
 struct refill_work {
      struct delayed_work pool_refill_work;
      struct otx2_nic *pf;
@@ -226,6 +231,8 @@ struct otx2_nic {
 
      u64                     reset_count;
      struct work_struct      reset_task;
+     struct workqueue_struct *flr_wq;
+     struct flr_work         *flr_wrk;
      struct refill_work      *refill_wrk;
 
      /* Ethtool stuff */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +27 -0
index 967ef7b..bf6e2529 100644
@@ -61,6 +61,224 @@ static int otx2_change_mtu(struct net_device *netdev, int new_mtu)
      return err;
 }
 
+static void otx2_disable_flr_me_intr(struct otx2_nic *pf)
+{
+     int irq, vfs = pf->total_vfs;
+
+     /* Disable VFs ME interrupts */
+     otx2_write64(pf, RVU_PF_VFME_INT_ENA_W1CX(0), INTR_MASK(vfs));
+     irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFME0);
+     free_irq(irq, pf);
+
+     /* Disable VFs FLR interrupts */
+     otx2_write64(pf, RVU_PF_VFFLR_INT_ENA_W1CX(0), INTR_MASK(vfs));
+     irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFFLR0);
+     free_irq(irq, pf);
+
+     if (vfs <= 64)
+             return;
+
+     otx2_write64(pf, RVU_PF_VFME_INT_ENA_W1CX(1), INTR_MASK(vfs - 64));
+     irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFME1);
+     free_irq(irq, pf);
+
+     otx2_write64(pf, RVU_PF_VFFLR_INT_ENA_W1CX(1), INTR_MASK(vfs - 64));
+     irq = pci_irq_vector(pf->pdev, RVU_PF_INT_VEC_VFFLR1);
+     free_irq(irq, pf);
+}
+
+static void otx2_flr_wq_destroy(struct otx2_nic *pf)
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_change_mtu(struct net_device *netdev, int new_mtu) · line 95

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +5 -0
+{
+     if (!pf->flr_wq)
+             return;
+     flush_workqueue(pf->flr_wq);
+     destroy_workqueue(pf->flr_wq);

destroy_workqueue() calls to drain_workqueue() which calls to flush_workqueue() in proper order and not like it is written here.

Thanks, will fix this in v3.

Sunil.

#5 lore raw

PATCH v2 3/7 octeontx2-vf: Virtual function driver support

In reply to [email protected]

From: Tomasz Duszynski <[email protected]>

On OcteonTx2 silicon there two two types VFs, VFs that share the physical link with their parent SR-IOV PF and the VFs which work in pairs using internal HW loopback channels (LBK). Except for the underlying Rx/Tx channel mapping from netdev functionality perspective they are almost identical. This patch adds netdev driver support for these VFs.

Unlike it's parent PF a VF cannot directly communicate with admin function (AF) and it has to go through PF for the same. The mailbox communication with AF works like 'VF <=> PF <=> AF'.

Also functionality wise VF and PF are identical, hence to avoid code duplication PF driver's APIs are resued here for HW initialization, packet handling etc etc ie almost everything. For VF driver to compile as module exported few of the existing PF driver APIs.

---
 drivers/net/ethernet/marvell/octeontx2/Kconfig     |   6 +
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  14 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   9 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  11 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_reg.h  |  13 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |   1 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   | 659 +++++++++++++++++++++
 8 files changed, 714 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
drivers/net/ethernet/marvell/octeontx2/Kconfig +6 -0
index ced514c..d9dfb61 100644
@@ -33,3 +33,9 @@ config OCTEONTX2_PF
 	depends on PCI
 	help
 	  This driver supports Marvell's OcteonTX2 NIC physical function.
+
+config OCTEONTX2_VF
+	tristate "Marvell OcteonTX2 NIC Virtual Function driver"
+	depends on OCTEONTX2_PF
+	help
+	  This driver supports Marvell's OcteonTX2 NIC virtual function.
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +2 -0
index 41bf00c..778df33 100644
@@ -4,7 +4,9 @@
 #
 
 obj-$(CONFIG_OCTEONTX2_PF) += octeontx2_nicpf.o
+obj-$(CONFIG_OCTEONTX2_VF) += octeontx2_nicvf.o
 
 octeontx2_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o otx2_ethtool.o
+octeontx2_nicvf-y := otx2_vf.o
 
 ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +14 -0
index 157735443..70d97c7 100644
@@ -128,6 +128,7 @@ void otx2_get_stats64(struct net_device *netdev,
 	stats->tx_packets = dev_stats->tx_frames;
 	stats->tx_dropped = dev_stats->tx_drops;
 }
+EXPORT_SYMBOL(otx2_get_stats64);
 
 /* Sync MAC address with RVU AF */
 static int otx2_hw_set_mac_addr(struct otx2_nic *pfvf, u8 *mac)
@@ -197,6 +198,7 @@ int otx2_set_mac_address(struct net_device *netdev, void *p)
 
 	return 0;
 }
+EXPORT_SYMBOL(otx2_set_mac_address);
 
 int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu)
 {
@@ -225,6 +227,9 @@ int otx2_config_pause_frm(struct otx2_nic *pfvf)
 	struct cgx_pause_frm_cfg *req;
 	int err;
 
+	if (is_otx2_lbkvf(pfvf->pdev))
+		return 0;
+
 	otx2_mbox_lock(&pfvf->mbox);
 	req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(&pfvf->mbox);
 	if (!req) {
@@ -416,6 +421,7 @@ void otx2_tx_timeout(struct net_device *netdev, unsigned int txq)
 
 	schedule_work(&pfvf->reset_task);
 }
+EXPORT_SYMBOL(otx2_tx_timeout);
 
 void otx2_get_mac_from_af(struct net_device *netdev)
 {
@@ -430,6 +436,7 @@ void otx2_get_mac_from_af(struct net_device *netdev)
 	if (!is_valid_ether_addr(netdev->dev_addr))
 		eth_hw_addr_random(netdev);
 }
+EXPORT_SYMBOL(otx2_get_mac_from_af);
 
 static int otx2_get_link(struct otx2_nic *pfvf)
 {
@@ -1263,6 +1270,7 @@ int otx2_detach_resources(struct mbox *mbox)
 	otx2_mbox_unlock(mbox);
 	return 0;
 }
+EXPORT_SYMBOL(otx2_detach_resources);
 
 int otx2_attach_npa_nix(struct otx2_nic *pfvf)
 {
@@ -1319,6 +1327,7 @@ int otx2_attach_npa_nix(struct otx2_nic *pfvf)
 
 	return 0;
 }
+EXPORT_SYMBOL(otx2_attach_npa_nix);
 
 void otx2_ctx_disable(struct mbox *mbox, int type, bool npa)
 {
@@ -1387,6 +1396,7 @@ void mbox_handler_nix_txsch_alloc(struct otx2_nic *pf,
 			pf->hw.txschq_list[lvl][schq] =
 				rsp->schq_list[lvl][schq];
 }
+EXPORT_SYMBOL(mbox_handler_nix_txsch_alloc);
 
 void mbox_handler_npa_lf_alloc(struct otx2_nic *pfvf,
 			       struct npa_lf_alloc_rsp *rsp)
@@ -1394,6 +1404,7 @@ void mbox_handler_npa_lf_alloc(struct otx2_nic *pfvf,
 	pfvf->hw.stack_pg_ptrs = rsp->stack_pg_ptrs;
 	pfvf->hw.stack_pg_bytes = rsp->stack_pg_bytes;
 }
+EXPORT_SYMBOL(mbox_handler_npa_lf_alloc);
 
 void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 			       struct nix_lf_alloc_rsp *rsp)
@@ -1404,6 +1415,7 @@ void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 	pfvf->hw.lso_tsov4_idx = rsp->lso_tsov4_idx;
 	pfvf->hw.lso_tsov6_idx = rsp->lso_tsov6_idx;
 }
+EXPORT_SYMBOL(mbox_handler_nix_lf_alloc);
 
 void mbox_handler_msix_offset(struct otx2_nic *pfvf,
 			      struct msix_offset_rsp *rsp)
@@ -1411,6 +1423,7 @@ void mbox_handler_msix_offset(struct otx2_nic *pfvf,
 	pfvf->hw.npa_msixoff = rsp->npa_msixoff;
 	pfvf->hw.nix_msixoff = rsp->nix_msixoff;
 }
+EXPORT_SYMBOL(mbox_handler_msix_offset);
 
 void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,
 				struct nix_bp_cfg_rsp *rsp)
@@ -1422,6 +1435,7 @@ void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,
 		pfvf->bpid[chan_id] = rsp->chan_bpid[chan] & 0x3FF;
 	}
 }
+EXPORT_SYMBOL(mbox_handler_nix_bp_enable);
 
 void otx2_free_cints(struct otx2_nic *pfvf, int n)
 {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +9 -0
index c0a9693..ca757b2 100644
@@ -20,6 +20,8 @@
 
 /* PCI device IDs */
 #define PCI_DEVID_OCTEONTX2_RVU_PF              0xA063
+#define PCI_DEVID_OCTEONTX2_RVU_VF		0xA064
+#define PCI_DEVID_OCTEONTX2_RVU_AFVF		0xA0F8
 
 #define PCI_SUBSYS_DEVID_96XX_RVU_PFVF		0xB200
 
@@ -242,6 +244,11 @@ struct otx2_nic {
 	int			nix_blkaddr;
 };
 
+static inline bool is_otx2_lbkvf(struct pci_dev *pdev)
+{
+	return pdev->device == PCI_DEVID_OCTEONTX2_RVU_AFVF;
+}
+
 static inline bool is_96xx_A0(struct pci_dev *pdev)
 {
 	return (pdev->revision == 0x00) &&
@@ -627,6 +634,8 @@ void otx2_set_ethtool_ops(struct net_device *netdev);
 
 int otx2_open(struct net_device *netdev);
 int otx2_stop(struct net_device *netdev);
+int otx2vf_open(struct net_device *netdev);
+int otx2vf_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_pf.c +10 -1
index bf6e2529..89644d5 100644
@@ -1088,6 +1088,7 @@ int otx2_set_real_num_queues(struct net_device *netdev,
 			   "Failed to set no of Rx queues: %d\n", rx_queues);
 	return err;
 }
+EXPORT_SYMBOL(otx2_set_real_num_queues);
 
 static irqreturn_t otx2_q_intr_handler(int irq, void *data)
 {
@@ -1523,6 +1524,9 @@ int otx2_open(struct net_device *netdev)
 	if (pf->linfo.link_up && !(pf->pcifunc & RVU_PFVF_FUNC_MASK))
 		otx2_handle_link_event(pf);
 
+	/* Restore pause frame settings */
+	otx2_config_pause_frm(pf);
+
 	err = otx2_rxtx_enable(pf, true);
 	if (err)
 		goto err_free_cints;
@@ -1546,6 +1550,7 @@ int otx2_open(struct net_device *netdev)
 	kfree(qset->napi);
 	return err;
 }
+EXPORT_SYMBOL(otx2_open);
 
 int otx2_stop(struct net_device *netdev)
 {
@@ -1606,6 +1611,7 @@ int otx2_stop(struct net_device *netdev)
 	       sizeof(*qset) - offsetof(struct otx2_qset, sqe_cnt));
 	return 0;
 }
+EXPORT_SYMBOL(otx2_stop);
 
 static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
@@ -1734,7 +1740,6 @@ static int otx2_realloc_msix_vectors(struct otx2_nic *pf)
 
 	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",
@@ -1901,6 +1906,10 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* Enable link notifications */
 	otx2_cgx_config_linkevents(pf, true);
 
+	/* Enable pause frames by default */
+	pf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED;
+	pf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED;
+
 	return 0;
 
 err_detach_rsrc:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h +13 -0
index 7963d41..867f646 100644
@@ -45,6 +45,19 @@
 #define RVU_PF_MSIX_VECX_CTL(a)             (0x008 | (a) << 4)
 #define RVU_PF_MSIX_PBAX(a)                 (0xF0000 | (a) << 3)
 
+/* RVU VF registers */
+#define	RVU_VF_VFPF_MBOX0		    (0x00000)
+#define	RVU_VF_VFPF_MBOX1		    (0x00008)
+#define	RVU_VF_VFPF_MBOXX(a)		    (0x00 | (a) << 3)
+#define	RVU_VF_INT			    (0x20)
+#define	RVU_VF_INT_W1S			    (0x28)
+#define	RVU_VF_INT_ENA_W1S		    (0x30)
+#define	RVU_VF_INT_ENA_W1C		    (0x38)
+#define	RVU_VF_BLOCK_ADDRX_DISC(a)	    (0x200 | (a) << 3)
+#define	RVU_VF_MSIX_VECX_ADDR(a)	    (0x000 | (a) << 4)
+#define	RVU_VF_MSIX_VECX_CTL(a)		    (0x008 | (a) << 4)
+#define	RVU_VF_MSIX_PBAX(a)		    (0xF0000 | (a) << 3)
+
 #define RVU_FUNC_BLKADDR_SHIFT		20
 #define RVU_FUNC_BLKADDR_MASK		0x1FULL
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
index bef4c20..1865f16 100644
@@ -778,6 +778,7 @@ bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq,
 
 	return true;
 }
+EXPORT_SYMBOL(otx2_sq_append_skb);
 
 void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
 {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +659 -0

659 lines not on this page · raw message

Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH v2 net-next 3/7] octeontx2-vf: Virtual function driver support

Quoted 297 lines · On Fri, Mar 13, 2020 at 03:12:42PM +0530, [email protected] wrote:

From: Tomasz Duszynski <[email protected]>

On OcteonTx2 silicon there two two types VFs, VFs that share the physical link with their parent SR-IOV PF and the VFs which work in pairs using internal HW loopback channels (LBK). Except for the underlying Rx/Tx channel mapping from netdev functionality perspective they are almost identical. This patch adds netdev driver support for these VFs.

Unlike it's parent PF a VF cannot directly communicate with admin function (AF) and it has to go through PF for the same. The mailbox communication with AF works like 'VF <=> PF <=> AF'.

Also functionality wise VF and PF are identical, hence to avoid code duplication PF driver's APIs are resued here for HW initialization, packet handling etc etc ie almost everything. For VF driver to compile as module exported few of the existing PF driver APIs.

---
 drivers/net/ethernet/marvell/octeontx2/Kconfig     |   6 +
 .../net/ethernet/marvell/octeontx2/nic/Makefile    |   2 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  14 +
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   9 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  11 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_reg.h  |  13 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |   1 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   | 659 +++++++++++++++++++++
 8 files changed, 714 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
drivers/net/ethernet/marvell/octeontx2/Kconfig +6 -0
index ced514c..d9dfb61 100644
@@ -33,3 +33,9 @@ config OCTEONTX2_PF
 	depends on PCI
 	help
 	  This driver supports Marvell's OcteonTX2 NIC physical function.
+
+config OCTEONTX2_VF
+	tristate "Marvell OcteonTX2 NIC Virtual Function driver"
+	depends on OCTEONTX2_PF
+	help
+	  This driver supports Marvell's OcteonTX2 NIC virtual function.
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +2 -0
index 41bf00c..778df33 100644
@@ -4,7 +4,9 @@
 #
 
 obj-$(CONFIG_OCTEONTX2_PF) += octeontx2_nicpf.o
+obj-$(CONFIG_OCTEONTX2_VF) += octeontx2_nicvf.o
 
 octeontx2_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o otx2_ethtool.o
+octeontx2_nicvf-y := otx2_vf.o
 
 ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +14 -0
index 157735443..70d97c7 100644
@@ -128,6 +128,7 @@ void otx2_get_stats64(struct net_device *netdev,
 	stats->tx_packets = dev_stats->tx_frames;
 	stats->tx_dropped = dev_stats->tx_drops;
 }
+EXPORT_SYMBOL(otx2_get_stats64);
 
 /* Sync MAC address with RVU AF */
 static int otx2_hw_set_mac_addr(struct otx2_nic *pfvf, u8 *mac)
@@ -197,6 +198,7 @@ int otx2_set_mac_address(struct net_device *netdev, void *p)
 
 	return 0;
 }
+EXPORT_SYMBOL(otx2_set_mac_address);
 
 int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu)
 {
@@ -225,6 +227,9 @@ int otx2_config_pause_frm(struct otx2_nic *pfvf)
 	struct cgx_pause_frm_cfg *req;
 	int err;
 
+	if (is_otx2_lbkvf(pfvf->pdev))
+		return 0;
+
 	otx2_mbox_lock(&pfvf->mbox);
 	req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(&pfvf->mbox);
 	if (!req) {
@@ -416,6 +421,7 @@ void otx2_tx_timeout(struct net_device *netdev, unsigned int txq)
 
 	schedule_work(&pfvf->reset_task);
 }
+EXPORT_SYMBOL(otx2_tx_timeout);
 
 void otx2_get_mac_from_af(struct net_device *netdev)
 {
@@ -430,6 +436,7 @@ void otx2_get_mac_from_af(struct net_device *netdev)
 	if (!is_valid_ether_addr(netdev->dev_addr))
 		eth_hw_addr_random(netdev);
 }
+EXPORT_SYMBOL(otx2_get_mac_from_af);
 
 static int otx2_get_link(struct otx2_nic *pfvf)
 {
@@ -1263,6 +1270,7 @@ int otx2_detach_resources(struct mbox *mbox)
 	otx2_mbox_unlock(mbox);
 	return 0;
 }
+EXPORT_SYMBOL(otx2_detach_resources);
 
 int otx2_attach_npa_nix(struct otx2_nic *pfvf)
 {
@@ -1319,6 +1327,7 @@ int otx2_attach_npa_nix(struct otx2_nic *pfvf)
 
 	return 0;
 }
+EXPORT_SYMBOL(otx2_attach_npa_nix);
 
 void otx2_ctx_disable(struct mbox *mbox, int type, bool npa)
 {
@@ -1387,6 +1396,7 @@ void mbox_handler_nix_txsch_alloc(struct otx2_nic *pf,
 			pf->hw.txschq_list[lvl][schq] =
 				rsp->schq_list[lvl][schq];
 }
+EXPORT_SYMBOL(mbox_handler_nix_txsch_alloc);
 
 void mbox_handler_npa_lf_alloc(struct otx2_nic *pfvf,
 			       struct npa_lf_alloc_rsp *rsp)
@@ -1394,6 +1404,7 @@ void mbox_handler_npa_lf_alloc(struct otx2_nic *pfvf,
 	pfvf->hw.stack_pg_ptrs = rsp->stack_pg_ptrs;
 	pfvf->hw.stack_pg_bytes = rsp->stack_pg_bytes;
 }
+EXPORT_SYMBOL(mbox_handler_npa_lf_alloc);
 
 void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 			       struct nix_lf_alloc_rsp *rsp)
@@ -1404,6 +1415,7 @@ void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 	pfvf->hw.lso_tsov4_idx = rsp->lso_tsov4_idx;
 	pfvf->hw.lso_tsov6_idx = rsp->lso_tsov6_idx;
 }
+EXPORT_SYMBOL(mbox_handler_nix_lf_alloc);
 
 void mbox_handler_msix_offset(struct otx2_nic *pfvf,
 			      struct msix_offset_rsp *rsp)
@@ -1411,6 +1423,7 @@ void mbox_handler_msix_offset(struct otx2_nic *pfvf,
 	pfvf->hw.npa_msixoff = rsp->npa_msixoff;
 	pfvf->hw.nix_msixoff = rsp->nix_msixoff;
 }
+EXPORT_SYMBOL(mbox_handler_msix_offset);
 
 void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,
 				struct nix_bp_cfg_rsp *rsp)
@@ -1422,6 +1435,7 @@ void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,
 		pfvf->bpid[chan_id] = rsp->chan_bpid[chan] & 0x3FF;
 	}
 }
+EXPORT_SYMBOL(mbox_handler_nix_bp_enable);
 
 void otx2_free_cints(struct otx2_nic *pfvf, int n)
 {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +9 -0
index c0a9693..ca757b2 100644
@@ -20,6 +20,8 @@
 
 /* PCI device IDs */
 #define PCI_DEVID_OCTEONTX2_RVU_PF              0xA063
+#define PCI_DEVID_OCTEONTX2_RVU_VF		0xA064
+#define PCI_DEVID_OCTEONTX2_RVU_AFVF		0xA0F8
 
 #define PCI_SUBSYS_DEVID_96XX_RVU_PFVF		0xB200
 
@@ -242,6 +244,11 @@ struct otx2_nic {
 	int			nix_blkaddr;
 };
 
+static inline bool is_otx2_lbkvf(struct pci_dev *pdev)
+{
+	return pdev->device == PCI_DEVID_OCTEONTX2_RVU_AFVF;
+}
+
 static inline bool is_96xx_A0(struct pci_dev *pdev)
 {
 	return (pdev->revision == 0x00) &&
@@ -627,6 +634,8 @@ void otx2_set_ethtool_ops(struct net_device *netdev);
 
 int otx2_open(struct net_device *netdev);
 int otx2_stop(struct net_device *netdev);
+int otx2vf_open(struct net_device *netdev);
+int otx2vf_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_pf.c +10 -1
index bf6e2529..89644d5 100644
@@ -1088,6 +1088,7 @@ int otx2_set_real_num_queues(struct net_device *netdev,
 			   "Failed to set no of Rx queues: %d\n", rx_queues);
 	return err;
 }
+EXPORT_SYMBOL(otx2_set_real_num_queues);
 
 static irqreturn_t otx2_q_intr_handler(int irq, void *data)
 {
@@ -1523,6 +1524,9 @@ int otx2_open(struct net_device *netdev)
 	if (pf->linfo.link_up && !(pf->pcifunc & RVU_PFVF_FUNC_MASK))
 		otx2_handle_link_event(pf);
 
+	/* Restore pause frame settings */
+	otx2_config_pause_frm(pf);
+
 	err = otx2_rxtx_enable(pf, true);
 	if (err)
 		goto err_free_cints;
@@ -1546,6 +1550,7 @@ int otx2_open(struct net_device *netdev)
 	kfree(qset->napi);
 	return err;
 }
+EXPORT_SYMBOL(otx2_open);
 
 int otx2_stop(struct net_device *netdev)
 {
@@ -1606,6 +1611,7 @@ int otx2_stop(struct net_device *netdev)
 	       sizeof(*qset) - offsetof(struct otx2_qset, sqe_cnt));
 	return 0;
 }
+EXPORT_SYMBOL(otx2_stop);
 
 static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
@@ -1734,7 +1740,6 @@ static int otx2_realloc_msix_vectors(struct otx2_nic *pf)
 
 	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",
@@ -1901,6 +1906,10 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* Enable link notifications */
 	otx2_cgx_config_linkevents(pf, true);
 
+	/* Enable pause frames by default */
+	pf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED;
+	pf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED;
+
 	return 0;
 
 err_detach_rsrc:
drivers/net/ethernet/marvell/octeontx2/nic/otx2_reg.h +13 -0
index 7963d41..867f646 100644
@@ -45,6 +45,19 @@
 #define RVU_PF_MSIX_VECX_CTL(a)             (0x008 | (a) << 4)
 #define RVU_PF_MSIX_PBAX(a)                 (0xF0000 | (a) << 3)
 
+/* RVU VF registers */
+#define	RVU_VF_VFPF_MBOX0		    (0x00000)
+#define	RVU_VF_VFPF_MBOX1		    (0x00008)
+#define	RVU_VF_VFPF_MBOXX(a)		    (0x00 | (a) << 3)
+#define	RVU_VF_INT			    (0x20)
+#define	RVU_VF_INT_W1S			    (0x28)
+#define	RVU_VF_INT_ENA_W1S		    (0x30)
+#define	RVU_VF_INT_ENA_W1C		    (0x38)
+#define	RVU_VF_BLOCK_ADDRX_DISC(a)	    (0x200 | (a) << 3)
+#define	RVU_VF_MSIX_VECX_ADDR(a)	    (0x000 | (a) << 4)
+#define	RVU_VF_MSIX_VECX_CTL(a)		    (0x008 | (a) << 4)
+#define	RVU_VF_MSIX_PBAX(a)		    (0xF0000 | (a) << 3)
+
 #define RVU_FUNC_BLKADDR_SHIFT		20
 #define RVU_FUNC_BLKADDR_MASK		0x1FULL
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
index bef4c20..1865f16 100644
@@ -778,6 +778,7 @@ bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq,
 
 	return true;
 }
+EXPORT_SYMBOL(otx2_sq_append_skb);
 
 void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
 {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +0 -0
new file mode 100644
index 0000000..cf366dc

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 9

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +9 -0
@@ -0,0 +1,659 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Marvell OcteonTx2 RVU Virtual Function 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.
+ */

Please don't add license text, the SPDX line is enough.

Quoted 145 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +145 -0
+
+#include <linux/etherdevice.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+
+#include "otx2_common.h"
+#include "otx2_reg.h"
+
+#define DRV_NAME	"octeontx2-nicvf"
+#define DRV_STRING	"Marvell OcteonTX2 NIC Virtual Function Driver"
+
+static const struct pci_device_id otx2_vf_id_table[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_AFVF) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_VF) },
+	{ }
+};
+
+MODULE_AUTHOR("Sunil Goutham <[email protected]>");
+MODULE_DESCRIPTION(DRV_STRING);
+MODULE_LICENSE("GPL v2");
+MODULE_DEVICE_TABLE(pci, otx2_vf_id_table);
+
+/* RVU VF Interrupt Vector Enumeration */
+enum {
+	RVU_VF_INT_VEC_MBOX = 0x0,
+};
+
+static int otx2vf_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	bool if_up = netif_running(netdev);
+	int err = 0;
+
+	if (if_up)
+		otx2vf_stop(netdev);
+
+	netdev_info(netdev, "Changing MTU from %d to %d\n",
+		    netdev->mtu, new_mtu);
+	netdev->mtu = new_mtu;
+
+	if (if_up)
+		err = otx2vf_open(netdev);
+
+	return err;
+}
+
+static void otx2vf_process_vfaf_mbox_msg(struct otx2_nic *vf,
+					 struct mbox_msghdr *msg)
+{
+	if (msg->id >= MBOX_MSG_MAX) {
+		dev_err(vf->dev,
+			"Mbox msg with unknown ID %d\n", msg->id);
+		return;
+	}
+
+	if (msg->sig != OTX2_MBOX_RSP_SIG) {
+		dev_err(vf->dev,
+			"Mbox msg with wrong signature %x, ID %d\n",
+			msg->sig, msg->id);
+		return;
+	}
+
+	if (msg->rc == MBOX_MSG_INVALID) {
+		dev_err(vf->dev,
+			"PF/AF says the sent msg(s) %d were invalid\n",
+			msg->id);
+		return;
+	}
+
+	switch (msg->id) {
+	case MBOX_MSG_READY:
+		vf->pcifunc = msg->pcifunc;
+		break;
+	case MBOX_MSG_MSIX_OFFSET:
+		mbox_handler_msix_offset(vf, (struct msix_offset_rsp *)msg);
+		break;
+	case MBOX_MSG_NPA_LF_ALLOC:
+		mbox_handler_npa_lf_alloc(vf, (struct npa_lf_alloc_rsp *)msg);
+		break;
+	case MBOX_MSG_NIX_LF_ALLOC:
+		mbox_handler_nix_lf_alloc(vf, (struct nix_lf_alloc_rsp *)msg);
+		break;
+	case MBOX_MSG_NIX_TXSCH_ALLOC:
+		mbox_handler_nix_txsch_alloc(vf,
+					     (struct nix_txsch_alloc_rsp *)msg);
+		break;
+	case MBOX_MSG_NIX_BP_ENABLE:
+		mbox_handler_nix_bp_enable(vf, (struct nix_bp_cfg_rsp *)msg);
+		break;
+	default:
+		if (msg->rc)
+			dev_err(vf->dev,
+				"Mbox msg response has err %d, ID %d\n",
+				msg->rc, msg->id);
+	}
+}
+
+static void otx2vf_vfaf_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;
+	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);
+	if (af_mbox->num_msgs == 0)
+		return;
+	offset = mbox->rx_start + ALIGN(sizeof(*rsp_hdr), MBOX_MSG_ALIGN);
+
+	for (id = 0; id < af_mbox->num_msgs; id++) {
+		msg = (struct mbox_msghdr *)(mdev->mbase + offset);
+		otx2vf_process_vfaf_mbox_msg(af_mbox->pfvf, msg);
+		offset = mbox->rx_start + msg->next_msgoff;
+		mdev->msgs_acked++;
+	}
+
+	otx2_mbox_reset(mbox, 0);
+}
+
+static int otx2vf_process_mbox_msg_up(struct otx2_nic *vf,
+				      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(&vf->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(		\
+			&vf->mbox.mbox_up, 0,				\
+			sizeof(struct _rsp_type));			\
+		if (!rsp)						\
+			return -ENOMEM;					\
+									\
+		rsp->hdr.id = _id;					\

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 164

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +10 -0
+		rsp->hdr.sig = OTX2_MBOX_RSP_SIG;			\
+		rsp->hdr.pcifunc = 0;					\
+		rsp->hdr.rc = 0;					\
+									\
+		err = otx2_mbox_up_handler_ ## _fn_name(		\
+			vf, (struct _req_type *)req, rsp);		\
+		return err;						\
+	}
+MBOX_UP_CGX_MESSAGES
+#undef M

"return ..." inside macro which is called by another macro is highly discouraged by the Linux kernel coding style.

Thanks

#7 lore raw

Re: [PATCH v2 net-next 3/7] octeontx2-vf: Virtual function driver support

Review

Quoted 1 line · Leon Romanovsky
(quoted diff) +0 -0

b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c

Quoted 8 lines
Quoted 8 lines

new file mode 100644
index 0000000..cf366dc

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +3 -0
@@ -0,0 +1,659 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Marvell OcteonTx2 RVU Virtual Function ethernet driver
+ *
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 9

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +6 -0
+ * 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.
+ */

Please don't add license text, the SPDX line is enough.

Can you please point me to where this is written.
It would be great if these are made rules and written somewhere so that everyone can go through and follow.
I see that there are so many patches being submitted with copyright text. So this is very confusing.

Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +28 -0
+
+static int otx2vf_process_mbox_msg_up(struct otx2_nic *vf,
+                                   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(&vf->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(          \
+                     &vf->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(                \
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 164

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +5 -0
+                     vf, (struct _req_type *)req, rsp);              \
+             return err;                                             \
+     }
+MBOX_UP_CGX_MESSAGES
+#undef M

"return ..." inside macro which is called by another macro is highly discouraged by the Linux kernel coding style.

There are many mailbox messages to handle and adding each one of them to switch case would be a
lot of duplicate code. Hence we choose to with these macros.

Thanks,
Sunil.

#8 lore raw

Re: [PATCH v2 net-next 3/7] octeontx2-vf: Virtual function driver support

Quoted 21 lines · Sunil Kovvuri

Review

Quoted 1 line · Leon Romanovsky
(quoted diff) +0 -0

b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c

Quoted 8 lines
Quoted 8 lines

new file mode 100644
index 0000000..cf366dc

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +3 -0
@@ -0,0 +1,659 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Marvell OcteonTx2 RVU Virtual Function ethernet driver
+ *
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 9

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +6 -0
+ * 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.
+ */

Please don't add license text, the SPDX line is enough.

Quoted 1 line

Can you please point me to where this is written.

The whole idea of SPDX tags is to provide clear and proper license for the code. See what it means to place SPDX tags and there can be found LICENSE text.
https://elixir.bootlin.com/linux/latest/source/Documentation/process/license-rules.rst
https://elixir.bootlin.com/linux/latest/source/Documentation/process/howto.rst#L59

Quoted 4 lines

It would be great if these are made rules and written somewhere so that everyone can go through and follow.
I see that there are so many patches being submitted with copyright text. So this is very confusing.

It is a mistake to place LICENSE text in addition to SPDX in new files.

Quoted 39 lines
Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +28 -0
+
+static int otx2vf_process_mbox_msg_up(struct otx2_nic *vf,
+                                   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(&vf->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(          \
+                     &vf->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(                \
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 164

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +5 -0
+                     vf, (struct _req_type *)req, rsp);              \
+             return err;                                             \
+     }
+MBOX_UP_CGX_MESSAGES
+#undef M

"return ..." inside macro which is called by another macro is highly discouraged by the Linux kernel coding style.

Quoted 3 lines

There are many mailbox messages to handle and adding each one of them to switch case would be a
lot of duplicate code. Hence we choose to with these macros.

The coding style section 12.1 talks exactly about that pattern.
https://elixir.bootlin.com/linux/latest/source/Documentation/process/coding-style.rst#L752
Somehow all other drivers succeeded to write their code without such macros, I'm confident that you will success too. Please try your best.

Thanks

Quoted 3 lines

Thanks,
Sunil.

#9 lore raw

Re: [PATCH v2 net-next 3/7] octeontx2-vf: Virtual function driver support

Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
Quoted 22 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +22 -0
+static int otx2vf_process_mbox_msg_up(struct otx2_nic *vf,
+                                   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(&vf->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(          \
+                     &vf->mbox.mbox_up, 0,                           \
+                     sizeof(struct _rsp_type));                      \
+             if (!rsp)                                               \
+                     return -ENOMEM;                                 \
+                                                                     \
+             rsp->hdr.id = _id;                                      \

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 164

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +10 -0
+             rsp->hdr.sig = OTX2_MBOX_RSP_SIG;                       \
+             rsp->hdr.pcifunc = 0;                                   \
+             rsp->hdr.rc = 0;                                        \
+                                                                     \
+             err = otx2_mbox_up_handler_ ## _fn_name(                \
+                     vf, (struct _req_type *)req, rsp);              \
+             return err;                                             \
+     }
+MBOX_UP_CGX_MESSAGES
+#undef M

"return ..." inside macro which is called by another macro is highly discouraged by the Linux kernel coding style.

Quoted 8 lines
Quoted 3 lines

There are many mailbox messages to handle and adding each one of them to switch case would be a
lot of duplicate code. Hence we choose to with these macros.

The coding style section 12.1 talks exactly about that pattern.
https://elixir.bootlin.com/linux/latest/source/Documentation/process/coding-style.rst#L752
Somehow all other drivers succeeded to write their code without such macros, I'm confident that you will success too. Please try your best.

Hi Sunil

It is easy to create locking bugs with returns in macros. I've inherited code which did this, not realized where was a return hidden in a macro, and as a result got locks wrong, resulting in a deadlock.

Andrew

#10 lore raw

Re: [PATCH v2 net-next 3/7] octeontx2-vf: Virtual function driver support

In reply to Sunil Kovvuri
Quoted 21 lines · Sunil Kovvuri

Review

Quoted 1 line · Leon Romanovsky
(quoted diff) +0 -0

b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c

Quoted 8 lines
Quoted 8 lines

new file mode 100644
index 0000000..cf366dc

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +3 -0
@@ -0,0 +1,659 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Marvell OcteonTx2 RVU Virtual Function ethernet driver
+ *
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 9

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +6 -0
+ * 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.
+ */

Please don't add license text, the SPDX line is enough.

Quoted 1 line

Can you please point me to where this is written.

It is in nutshell of SPDX tags. They already include proper LICENSE text.
https://elixir.bootlin.com/linux/latest/source/Documentation/process/howto.rst#L59
https://elixir.bootlin.com/linux/latest/source/Documentation/process/license-rules.rst

Quoted 4 lines

It would be great if these are made rules and written somewhere so that everyone can go through and follow.
I see that there are so many patches being submitted with copyright text. So this is very confusing.

This is a mistake, new files should carry SPDX tags only.

Quoted 39 lines
Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +28 -0
+
+static int otx2vf_process_mbox_msg_up(struct otx2_nic *vf,
+                                   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(&vf->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(          \
+                     &vf->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(                \
Quoted 9 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c line 164

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c new file +5 -0
+                     vf, (struct _req_type *)req, rsp);              \
+             return err;                                             \
+     }
+MBOX_UP_CGX_MESSAGES
+#undef M

"return ..." inside macro which is called by another macro is highly discouraged by the Linux kernel coding style.

Quoted 3 lines

There are many mailbox messages to handle and adding each one of them to switch case would be a
lot of duplicate code. Hence we choose to with these macros.

Somehow other drivers succeeded to do it without such macros, I'm confident that you will success too. Please try your best to rewrite it.

Section 12.1 talks exactly about this case and why it is **bad** idea.
https://elixir.bootlin.com/linux/latest/source/Documentation/process/coding-style.rst#L752

Thanks

Quoted 3 lines

Thanks,
Sunil.

#11 lore raw

PATCH v2 4/7 octeontx2-vf: Ethtool support

In reply to [email protected]

From: Tomasz Duszynski <[email protected]>

Added ethtool support for VF devices for
- Driver stats, Tx/Rx perqueue stats
- Set/show Rx/Tx queue count
- Set/show Rx/Tx ring sizes
- Set/show IRQ coalescing parameters
- RSS configuration etc

It's the PF which owns the interface, hence VF cannot display underlying CGX interface stats. Except for this rest ethtool support reuses PF's APIs.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   1 +
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 133 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   |   4 +
 3 files changed, 136 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
index ca757b2..95b8f1e 100644
@@ -631,6 +631,7 @@ 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);
+void otx2vf_set_ethtool_ops(struct net_device *netdev);
 
 int otx2_open(struct net_device *netdev);
 int otx2_stop(struct net_device *netdev);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +131 -2

172 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +4 -0
index cf366dc..11885dc 100644
@@ -381,11 +381,13 @@ int otx2vf_open(struct net_device *netdev)
 
 	return 0;
 }
+EXPORT_SYMBOL(otx2vf_open);
 
 int otx2vf_stop(struct net_device *netdev)
 {
 	return otx2_stop(netdev);
 }
+EXPORT_SYMBOL(otx2vf_stop);
 
 static netdev_tx_t otx2vf_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
@@ -592,6 +594,8 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto err_detach_rsrc;
 	}
 
+	otx2vf_set_ethtool_ops(netdev);
+
 	/* Enable pause frames by default */
 	vf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED;
 	vf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED;
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v2 net-next 4/7] octeontx2-vf: Ethtool support

Quoted 49 lines · On Fri, Mar 13, 2020 at 03:12:43PM +0530, [email protected] wrote:

From: Tomasz Duszynski <[email protected]>

Added ethtool support for VF devices for
- Driver stats, Tx/Rx perqueue stats
- Set/show Rx/Tx queue count
- Set/show Rx/Tx ring sizes
- Set/show IRQ coalescing parameters
- RSS configuration etc

It's the PF which owns the interface, hence VF cannot display underlying CGX interface stats. Except for this rest ethtool support reuses PF's APIs.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   1 +
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 133 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   |   4 +
 3 files changed, 136 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
index ca757b2..95b8f1e 100644
@@ -631,6 +631,7 @@ 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);
+void otx2vf_set_ethtool_ops(struct net_device *netdev);
 
 int otx2_open(struct net_device *netdev);
 int otx2_stop(struct net_device *netdev);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +1 -0
index f450111..1751e2d 100644
@@ -17,6 +17,7 @@
 #include "otx2_common.h"
 
 #define DRV_NAME	"octeontx2-nicpf"
+#define DRV_VF_NAME	"octeontx2-nicvf"
 
 struct otx2_stat {
 	char name[ETH_GSTRING_LEN];
@@ -63,14 +64,34 @@ static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats);
 static const unsigned int otx2_n_drv_stats = ARRAY_SIZE(otx2_drv_stats);
 static const unsigned int otx2_n_queue_stats = ARRAY_SIZE(otx2_queue_stats);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats); · line 75

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +9 -0
 
+int __weak otx2vf_open(struct net_device *netdev)
+{
+	return 0;
+}
+
+int __weak otx2vf_stop(struct net_device *netdev)
+{
+	return 0;
+}

We tried very politely to explain that drivers shouldn't have "__weak" in their code, sorry if it wasn't clear enough.

Thanks

#13 lore raw

Re: [PATCH v2 net-next 4/7] octeontx2-vf: Ethtool support

Quoted 65 lines · Leon Romanovsky
Quoted 49 lines · On Fri, Mar 13, 2020 at 03:12:43PM +0530, [email protected] wrote:

From: Tomasz Duszynski <[email protected]>

Added ethtool support for VF devices for
- Driver stats, Tx/Rx perqueue stats
- Set/show Rx/Tx queue count
- Set/show Rx/Tx ring sizes
- Set/show IRQ coalescing parameters
- RSS configuration etc

It's the PF which owns the interface, hence VF cannot display underlying CGX interface stats. Except for this rest ethtool support reuses PF's APIs.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |   1 +
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  | 133 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   |   4 +
 3 files changed, 136 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
index ca757b2..95b8f1e 100644
@@ -631,6 +631,7 @@ 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);
+void otx2vf_set_ethtool_ops(struct net_device *netdev);
 
 int otx2_open(struct net_device *netdev);
 int otx2_stop(struct net_device *netdev);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +1 -0
index f450111..1751e2d 100644
@@ -17,6 +17,7 @@
 #include "otx2_common.h"
 
 #define DRV_NAME     "octeontx2-nicpf"
+#define DRV_VF_NAME  "octeontx2-nicvf"
 
 struct otx2_stat {
      char name[ETH_GSTRING_LEN];
@@ -63,14 +64,34 @@ static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats);
 static const unsigned int otx2_n_drv_stats = ARRAY_SIZE(otx2_drv_stats);
 static const unsigned int otx2_n_queue_stats = ARRAY_SIZE(otx2_queue_stats);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats); · line 75

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +9 -0
 
+int __weak otx2vf_open(struct net_device *netdev)
+{
+     return 0;
+}
+
+int __weak otx2vf_stop(struct net_device *netdev)
+{
+     return 0;
+}

We tried very politely to explain that drivers shouldn't have "__weak" in their code, sorry if it wasn't clear enough.

Quoted 1 line

Thanks

Hmm.. I will try to remove.

Thanks,
Sunil.

#14 lore raw

PATCH v2 5/7 octeontx2-vf: Link event notification support

In reply to [email protected]

From: Tomasz Duszynski <[email protected]>

VF shares physical link with PF. Admin function (AF) sends notification to PF whenever a link change event happens. PF has to forward the same notification to each of the enabled VF.

PF traps START/STOP_RX messages sent by VF to AF to keep track of VF's enabled/disabled state.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   |  7 ++
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 88 +++++++++++++++++++++-
 2 files changed, 93 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +7 -0
index 95b8f1e..5c96fee 100644
@@ -193,6 +193,12 @@ struct otx2_hw {
 	u64			cgx_tx_stats[CGX_TX_STATS_COUNT];
 };
 
+struct otx2_vf_config {
+	struct otx2_nic *pf;
+	struct delayed_work link_event_work;
+	bool intf_down; /* interface was either configured or not */
+};
+
 struct flr_work {
 	struct work_struct work;
 	struct otx2_nic *pf;
@@ -229,6 +235,7 @@ struct otx2_nic {
 	u8			total_vfs;
 	u16			pcifunc; /* RVU PF_FUNC */
 	u16			bpid[NIX_MAX_BPID_CHAN];
+	struct otx2_vf_config	*vf_configs;
 	struct cgx_link_user_info linfo;
 
 	u64			reset_count;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +86 -2

145 lines not on this page · raw message

Signature · 1 line
2.7.4
#15 lore raw

PATCH v2 6/7 octeontx2-pf: Cleanup all receive buffers in SG descriptor

In reply to [email protected]

From: Geetha sowjanya <[email protected]>

With MTU sized receive buffers it is not expected to have CQE_RX with multiple receive buffer pointers. But since same physcial link is shared by PF and it's VFs, the max receive packet configured at link could be morethan MTU. Hence there is a chance of receiving plts morethan MTU which then gets DMA'ed into multiple buffers and notified in a single CQE_RX. This patch treats such pkts as errors and frees up receive buffers pointers back to hardware.

Also on the transmit side this patch sets SMQ MAXLEN to max value to avoid HW length errors for the packets whose size > MTU, eg due to path MTU.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   |  9 +++---
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 34 ++++++++++++++++++----
 2 files changed, 34 insertions(+), 9 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +5 -4
index 70d97c7..bac1922 100644
@@ -212,8 +212,6 @@ int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu)
 		return -ENOMEM;
 	}
 
-	/* SMQ config limits maximum pkt size that can be transmitted */
-	req->update_smq = true;
 	pfvf->max_frs = mtu +  OTX2_ETH_HLEN;
 	req->maxlen = pfvf->max_frs;
 
@@ -472,7 +470,7 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl)
 	/* Set topology e.t.c configuration */
 	if (lvl == NIX_TXSCH_LVL_SMQ) {
 		req->reg[0] = NIX_AF_SMQX_CFG(schq);
-		req->regval[0] = ((pfvf->netdev->mtu  + OTX2_ETH_HLEN) << 8) |
+		req->regval[0] = ((OTX2_MAX_MTU + OTX2_ETH_HLEN) << 8) |
 				   OTX2_MIN_MTU;
 
 		req->regval[0] |= (0x20ULL << 51) | (0x80ULL << 39) |
@@ -582,17 +580,19 @@ void otx2_sqb_flush(struct otx2_nic *pfvf)
 {
 	int qidx, sqe_tail, sqe_head;
 	u64 incr, *ptr, val;
+	int timeout = 1000;
 
 	ptr = (u64 *)otx2_get_regaddr(pfvf, NIX_LF_SQ_OP_STATUS);
 	for (qidx = 0; qidx < pfvf->hw.tx_queues; qidx++) {
 		incr = (u64)qidx << 32;
-		while (1) {
+		while (timeout) {
 			val = otx2_atomic64_add(incr, ptr);
 			sqe_head = (val >> 20) & 0x3F;
 			sqe_tail = (val >> 28) & 0x3F;
 			if (sqe_head == sqe_tail)
 				break;
 			usleep_range(1, 3);
+			timeout--;
 		}
 	}
 }
@@ -988,6 +988,7 @@ void otx2_aura_pool_free(struct otx2_nic *pfvf)
 		qmem_free(pfvf->dev, pool->fc_addr);
 	}
 	devm_kfree(pfvf->dev, pfvf->qset.pool);
+	pfvf->qset.pool = NULL;
 }
 
 static int otx2_aura_init(struct otx2_nic *pfvf, int aura_id,
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +29 -5
index 1865f16..b4d523a 100644
@@ -138,6 +138,25 @@ static void otx2_set_rxhash(struct otx2_nic *pfvf,
 	skb_set_hash(skb, hash, hash_type);
 }
 
+static void otx2_free_rcv_seg(struct otx2_nic *pfvf, struct nix_cqe_rx_s *cqe,
+			      int qidx)
+{
+	struct nix_rx_sg_s *sg = &cqe->sg;
+	void *end, *start;
+	u64 *seg_addr;
+	int seg;
+
+	start = (void *)sg;
+	end = start + ((cqe->parse.desc_sizem1 + 1) * 16);
+	while (start < end) {
+		sg = (struct nix_rx_sg_s *)start;
+		seg_addr = &sg->seg_addr;
+		for (seg = 0; seg < sg->segs; seg++, seg_addr++)
+			otx2_aura_freeptr(pfvf, qidx, *seg_addr & ~0x07ULL);
+		start += sizeof(*sg);
+	}
+}
+
 static bool otx2_check_rcv_errors(struct otx2_nic *pfvf,
 				  struct nix_cqe_rx_s *cqe, int qidx)
 {
@@ -189,16 +208,17 @@ static bool otx2_check_rcv_errors(struct otx2_nic *pfvf,
 		/* For now ignore all the NPC parser errors and
 		 * pass the packets to stack.
 		 */
-		return false;
+		if (cqe->sg.segs == 1)
+			return false;
 	}
 
 	/* If RXALL is enabled pass on packets to stack. */
-	if (cqe->sg.segs && (pfvf->netdev->features & NETIF_F_RXALL))
+	if (cqe->sg.segs == 1 && (pfvf->netdev->features & NETIF_F_RXALL))
 		return false;
 
 	/* Free buffer back to pool */
 	if (cqe->sg.segs)
-		otx2_aura_freeptr(pfvf, qidx, cqe->sg.seg_addr & ~0x07ULL);
+		otx2_free_rcv_seg(pfvf, cqe, qidx);
 	return true;
 }
 
@@ -210,7 +230,7 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
 	struct nix_rx_parse_s *parse = &cqe->parse;
 	struct sk_buff *skb = NULL;
 
-	if (unlikely(parse->errlev || parse->errcode)) {
+	if (unlikely(parse->errlev || parse->errcode || cqe->sg.segs > 1)) {
 		if (otx2_check_rcv_errors(pfvf, cqe, cq->cq_idx))
 			return;
 	}
@@ -789,11 +809,15 @@ void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
 	while ((cqe = (struct nix_cqe_rx_s *)otx2_get_next_cqe(cq))) {
 		if (!cqe->sg.subdc)
 			continue;
+		processed_cqe++;
+		if (cqe->sg.segs > 1) {
+			otx2_free_rcv_seg(pfvf, cqe, cq->cq_idx);
+			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 */
Signature · 1 line
2.7.4
#16 lore raw

PATCH v2 7/7 octeontx2-af: Remove driver version and fix authorship

In reply to [email protected]

From: Sunil Goutham <[email protected]>

Removed MODULE_VERSION and fixed MODULE_AUTHOR.

---
 drivers/net/ethernet/marvell/octeontx2/af/rvu.c      | 4 +---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +1 -3
index 5ff25bf..557e429 100644
@@ -21,7 +21,6 @@
 
 #define DRV_NAME	"octeontx2-af"
 #define DRV_STRING      "Marvell OcteonTX2 RVU Admin Function Driver"
-#define DRV_VERSION	"1.0"
 
 static int rvu_get_hwvf(struct rvu *rvu, int pcifunc);
 
@@ -46,10 +45,9 @@ static const struct pci_device_id rvu_id_table[] = {
 	{ 0, }  /* end of table */
 };
 
-MODULE_AUTHOR("Marvell International Ltd.");
+MODULE_AUTHOR("Sunil Goutham <[email protected]>");
 MODULE_DESCRIPTION(DRV_STRING);
 MODULE_LICENSE("GPL v2");
-MODULE_VERSION(DRV_VERSION);
 MODULE_DEVICE_TABLE(pci, rvu_id_table);
 
 static char *mkex_profile; /* MKEX profile name */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -3
index 6564f45..71415d7 100644
@@ -24,7 +24,6 @@
 
 #define DRV_NAME	"octeontx2-nicpf"
 #define DRV_STRING	"Marvell OcteonTX2 NIC Physical Function Driver"
-#define DRV_VERSION	"1.0"
 
 /* Supported devices */
 static const struct pci_device_id otx2_pf_id_table[] = {
@@ -32,10 +31,9 @@ static const struct pci_device_id otx2_pf_id_table[] = {
 	{ 0, }  /* end of table */
 };
 
-MODULE_AUTHOR("Marvell International Ltd.");
+MODULE_AUTHOR("Sunil Goutham <[email protected]>");
 MODULE_DESCRIPTION(DRV_STRING);
 MODULE_LICENSE("GPL v2");
-MODULE_VERSION(DRV_VERSION);
 MODULE_DEVICE_TABLE(pci, otx2_pf_id_table);
 
 enum {
Signature · 1 line
2.7.4