diff mbox series

[v2,05/11] net/thunderx: implement polling of link state change

Message ID 20220523161100.86280-5-hkalra@marvell.com (mailing list archive)
State Superseded
Delegated to: Jerin Jacob
Headers show
Series [v2,01/11] event/octeontx: fix SSO fastpath | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Harman Kalra May 23, 2022, 4:10 p.m. UTC
From: Hanumanth Pothula <hpothula@marvell.com>

Moving the logic of link polling to VF from PF. Now VF
is supposed to poll for the link status, rather PF alerting
VF about any link change.

Signed-off-by: Hanumanth Pothula <hpothula@marvell.com>
---
 drivers/net/thunderx/base/nicvf_mbox.c |  9 ++++++++
 drivers/net/thunderx/base/nicvf_mbox.h |  1 +
 drivers/net/thunderx/nicvf_ethdev.c    | 32 ++++++++++++++------------
 drivers/net/thunderx/nicvf_ethdev.h    | 10 ++++----
 4 files changed, 33 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/thunderx/base/nicvf_mbox.c b/drivers/net/thunderx/base/nicvf_mbox.c
index d7209c0083..281027ccce 100644
--- a/drivers/net/thunderx/base/nicvf_mbox.c
+++ b/drivers/net/thunderx/base/nicvf_mbox.c
@@ -440,3 +440,12 @@  nicvf_mbox_cfg_done(struct nicvf *nic)
 	mbx.msg.msg = NIC_MBOX_MSG_CFG_DONE;
 	nicvf_mbox_send_async_msg_to_pf(nic, &mbx);
 }
+
+void
+nicvf_mbox_link_change(struct nicvf *nic)
+{
+	struct nic_mbx mbx = { .msg = { 0 } };
+
+	mbx.msg.msg = NIC_MBOX_MSG_BGX_LINK_CHANGE;
+	nicvf_mbox_send_async_msg_to_pf(nic, &mbx);
+}
diff --git a/drivers/net/thunderx/base/nicvf_mbox.h b/drivers/net/thunderx/base/nicvf_mbox.h
index d0b294362c..490bed206b 100644
--- a/drivers/net/thunderx/base/nicvf_mbox.h
+++ b/drivers/net/thunderx/base/nicvf_mbox.h
@@ -222,5 +222,6 @@  int nicvf_mbox_reset_stat_counters(struct nicvf *nic, uint16_t rx_stat_mask,
 int nicvf_mbox_set_link_up_down(struct nicvf *nic, bool enable);
 void nicvf_mbox_shutdown(struct nicvf *nic);
 void nicvf_mbox_cfg_done(struct nicvf *nic);
+void nicvf_mbox_link_change(struct nicvf *nic);
 
 #endif /* __THUNDERX_NICVF_MBOX__ */
diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c
index fc334cf734..addbd53735 100644
--- a/drivers/net/thunderx/nicvf_ethdev.c
+++ b/drivers/net/thunderx/nicvf_ethdev.c
@@ -71,6 +71,9 @@  nicvf_link_status_update(struct nicvf *nic,
 	link->link_autoneg = RTE_ETH_LINK_AUTONEG;
 }
 
+/*Poll for link status change by sending NIC_MBOX_MSG_BGX_LINK_CHANGE msg
+ * periodically to PF.
+ */
 static void
 nicvf_interrupt(void *arg)
 {
@@ -78,7 +81,10 @@  nicvf_interrupt(void *arg)
 	struct nicvf *nic = nicvf_pmd_priv(dev);
 	struct rte_eth_link link;
 
-	if (nicvf_reg_poll_interrupts(nic) == NIC_MBOX_MSG_BGX_LINK_CHANGE) {
+	rte_eth_linkstatus_get(dev, &link);
+
+	nicvf_mbox_link_change(nic);
+	if (nic->link_up != link.link_status) {
 		if (dev->data->dev_conf.intr_conf.lsc) {
 			nicvf_link_status_update(nic, &link);
 			rte_eth_linkstatus_set(dev, &link);
@@ -89,7 +95,7 @@  nicvf_interrupt(void *arg)
 		}
 	}
 
-	rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
+	rte_eal_alarm_set(NICVF_INTR_LINK_POLL_INTERVAL_MS * 1000,
 				nicvf_interrupt, dev);
 }
 
@@ -1841,7 +1847,6 @@  nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic, bool cleanup)
 static int
 nicvf_dev_close(struct rte_eth_dev *dev)
 {
-	size_t i;
 	struct nicvf *nic = nicvf_pmd_priv(dev);
 
 	PMD_INIT_FUNC_TRACE();
@@ -1850,13 +1855,7 @@  nicvf_dev_close(struct rte_eth_dev *dev)
 
 	nicvf_dev_stop_cleanup(dev, true);
 	nicvf_periodic_alarm_stop(nicvf_interrupt, dev);
-
-	for (i = 0; i < nic->sqs_count; i++) {
-		if (!nic->snicvf[i])
-			continue;
-
-		nicvf_periodic_alarm_stop(nicvf_vf_interrupt, nic->snicvf[i]);
-	}
+	nicvf_periodic_alarm_stop(nicvf_vf_interrupt, nic);
 
 	rte_intr_instance_free(nic->intr_handle);
 
@@ -2169,6 +2168,14 @@  nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
 
 	nicvf_disable_all_interrupts(nic);
 
+	/* To read mbox messages */
+	ret = nicvf_periodic_alarm_start(nicvf_vf_interrupt, nic);
+	if (ret) {
+		PMD_INIT_LOG(ERR, "Failed to start period alarm");
+		goto fail;
+	}
+
+	/* To poll link status change*/
 	ret = nicvf_periodic_alarm_start(nicvf_interrupt, eth_dev);
 	if (ret) {
 		PMD_INIT_LOG(ERR, "Failed to start period alarm");
@@ -2203,11 +2210,6 @@  nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
 		eth_dev->data->dev_private = NULL;
 
 		nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
-		ret = nicvf_periodic_alarm_start(nicvf_vf_interrupt, nic);
-		if (ret) {
-			PMD_INIT_LOG(ERR, "Failed to start period alarm");
-			goto fail;
-		}
 
 		/* Detach port by returning positive error number */
 		return ENOTSUP;
diff --git a/drivers/net/thunderx/nicvf_ethdev.h b/drivers/net/thunderx/nicvf_ethdev.h
index cb474e26b8..a947b55fd4 100644
--- a/drivers/net/thunderx/nicvf_ethdev.h
+++ b/drivers/net/thunderx/nicvf_ethdev.h
@@ -10,10 +10,12 @@ 
 #define THUNDERX_NICVF_PMD_VERSION      "2.0"
 #define THUNDERX_REG_BYTES		8
 
-#define NICVF_INTR_POLL_INTERVAL_MS	50
-#define NICVF_HALF_DUPLEX		0x00
-#define NICVF_FULL_DUPLEX		0x01
-#define NICVF_UNKNOWN_DUPLEX		0xff
+#define NICVF_INTR_POLL_INTERVAL_MS		50
+/* Poll for link state for every 2 sec */
+#define NICVF_INTR_LINK_POLL_INTERVAL_MS	2000
+#define NICVF_HALF_DUPLEX			0x00
+#define NICVF_FULL_DUPLEX			0x01
+#define NICVF_UNKNOWN_DUPLEX			0xff
 
 #define NICVF_RSS_OFFLOAD_PASS1 ( \
 	RTE_ETH_RSS_PORT | \