[v2,17/19] net/xsc: add dev link and MTU ops

Message ID 20240911020740.3950704-18-wanry@yunsilicon.com (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers
Series XSC PMD for Yunsilicon NICs |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

WanRenyong Sept. 11, 2024, 2:07 a.m. UTC
XSC PMD does not support update link right now, in order to
start device successfully link_update function always return 0.

Signed-off-by: WanRenyong <wanry@yunsilicon.com>
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c     | 50 ++++++++++++++++++++++++++++++++
 drivers/net/xsc/xsc_utils.c      | 23 +++++++++++++++
 drivers/net/xsc/xsc_utils.h      |  1 +
 4 files changed, 75 insertions(+)
  

Patch

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 772c6418c4..84c5ff4b6b 100644
--- a/doc/guides/nics/features/xsc.ini
+++ b/doc/guides/nics/features/xsc.ini
@@ -4,6 +4,7 @@ 
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+MTU update           = Y
 RSS hash             = Y
 RSS key update       = Y
 RSS reta update      = Y
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 0dc1a63cc5..bc5e827d70 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -187,6 +187,20 @@  xsc_ethdev_configure(struct rte_eth_dev *dev)
 	return -rte_errno;
 }
 
+static int
+xsc_ethdev_set_link_down(struct rte_eth_dev *dev)
+{
+	struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+	return xsc_link_process(dev, priv->ifindex, IFF_UP);
+}
+
+static int
+xsc_ethdev_set_link_up(struct rte_eth_dev *dev)
+{
+	struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+	return xsc_link_process(dev, priv->ifindex, ~IFF_UP);
+}
+
 static int
 xsc_init_obj(struct xscdv_obj *obj, uint64_t obj_type)
 {
@@ -983,6 +997,39 @@  xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
 	return 0;
 }
 
+static int
+xsc_ethdev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
+{
+	struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+	uint16_t get_mtu = 0;
+	int ret = 0;
+
+	if (priv->eth_type != RTE_ETH_REPRESENTOR_PF) {
+		priv->mtu = mtu;
+		return 0;
+	}
+
+	ret = xsc_get_mtu(&priv->mtu, priv->ifindex);
+	if (ret)
+		return ret;
+
+	ret = xsc_set_mtu(mtu, priv->ifindex);
+	if (ret)
+		return ret;
+
+	ret = xsc_get_mtu(&get_mtu, priv->ifindex);
+	if (ret)
+		return ret;
+
+	if (get_mtu != mtu) {
+		PMD_DRV_LOG(ERR, "mtu set to %u failure", mtu);
+		return -EAGAIN;
+	}
+
+	priv->mtu = mtu;
+	return 0;
+}
+
 static int
 xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev,
 		       __rte_unused int wait_to_complete)
@@ -994,12 +1041,15 @@  const struct eth_dev_ops xsc_dev_ops = {
 	.dev_configure = xsc_ethdev_configure,
 	.dev_start = xsc_ethdev_start,
 	.dev_stop = xsc_ethdev_stop,
+	.dev_set_link_down = xsc_ethdev_set_link_down,
+	.dev_set_link_up = xsc_ethdev_set_link_up,
 	.dev_close = xsc_ethdev_close,
 	.link_update = xsc_ethdev_link_update,
 	.rx_queue_setup = xsc_ethdev_rx_queue_setup,
 	.tx_queue_setup = xsc_ethdev_tx_queue_setup,
 	.rx_queue_release = xsc_ethdev_rxq_release,
 	.tx_queue_release = xsc_ethdev_txq_release,
+	.mtu_set = xsc_ethdev_set_mtu,
 	.rss_hash_update = xsc_ethdev_rss_hash_update,
 	.rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
 };
diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c
index e40b0904b7..788cdfa54a 100644
--- a/drivers/net/xsc/xsc_utils.c
+++ b/drivers/net/xsc/xsc_utils.c
@@ -321,3 +321,26 @@  xsc_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t i
 	dev->data->mac_addrs[index] = *mac;
 	return 0;
 }
+
+int
+xsc_link_process(struct rte_eth_dev *dev __rte_unused,
+		 uint32_t ifindex, unsigned int flags)
+{
+	struct ifreq request;
+	struct ifreq *ifr = &request;
+	char ifname[sizeof(ifr->ifr_name)];
+	int ret;
+	unsigned int keep = ~IFF_UP;
+
+	if (if_indextoname(ifindex, ifname) == NULL)
+		return -rte_errno;
+
+	ret = xsc_ifreq_by_ifname(ifname, SIOCGIFFLAGS, &request);
+	if (ret)
+		return ret;
+
+	request.ifr_flags &= keep;
+	request.ifr_flags |= flags & ~keep;
+
+	return xsc_ifreq_by_ifname(ifname, SIOCSIFFLAGS, &request);
+}
diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h
index 672ba3871e..d9327020cd 100644
--- a/drivers/net/xsc/xsc_utils.h
+++ b/drivers/net/xsc/xsc_utils.h
@@ -22,5 +22,6 @@  int xsc_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32
 int xsc_get_mtu(uint16_t *mtu, uint32_t ifindex);
 int xsc_set_mtu(uint16_t mtu, uint32_t ifindex);
 int xsc_get_mac(uint8_t *mac, uint32_t ifindex);
+int xsc_link_process(struct rte_eth_dev *dev, uint32_t ifindex, unsigned int flags);
 
 #endif