diff mbox series

[v1,18/20] net/txgbe: hardware support for VF representor

Message ID 20210122094800.197748-19-jiawenwu@trustnetic.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers show
Series net/txgbe: add VF driver support | expand

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Jiawen Wu Jan. 22, 2021, 9:47 a.m. UTC
Support to get link status and set mac address for VF representor.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 drivers/net/txgbe/meson.build            |  1 +
 drivers/net/txgbe/rte_pmd_txgbe.c        | 45 ++++++++++++++++++++++++
 drivers/net/txgbe/rte_pmd_txgbe.h        | 17 +++++++++
 drivers/net/txgbe/txgbe_ethdev.c         |  9 +++++
 drivers/net/txgbe/txgbe_ethdev.h         |  2 ++
 drivers/net/txgbe/txgbe_vf_representor.c | 26 ++++++++++++++
 6 files changed, 100 insertions(+)
 create mode 100644 drivers/net/txgbe/rte_pmd_txgbe.c

Comments

Ferruh Yigit Feb. 2, 2021, 5:50 p.m. UTC | #1
On 1/22/2021 9:47 AM, Jiawen Wu wrote:
> Support to get link status and set mac address for VF representor.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>

<...>

> @@ -21,6 +21,7 @@ sources = files(
>   	'txgbe_rxtx.c',
>   	'txgbe_tm.c',
>   	'txgbe_vf_representor.c',
> +	'rte_pmd_txgbe.c'

This is adding PMD specific API, but with the port representor support, you 
should not need this API.

I can see some representor related funcitons are calling these APIs, but it is 
possible to move those functions and remove the 'rte_pmd_txgbe.[ch]' files.

>   )
>   
>   deps += ['hash', 'security']
> diff --git a/drivers/net/txgbe/rte_pmd_txgbe.c b/drivers/net/txgbe/rte_pmd_txgbe.c
> new file mode 100644
> index 000000000..c84233bd6
> --- /dev/null
> +++ b/drivers/net/txgbe/rte_pmd_txgbe.c
> @@ -0,0 +1,45 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2015-2020
> + */
> +
> +#include <rte_ethdev_driver.h>
> +

This header file renamed, it should be 'ethdev_driver'.
diff mbox series

Patch

diff --git a/drivers/net/txgbe/meson.build b/drivers/net/txgbe/meson.build
index f5391076e..142d47df2 100644
--- a/drivers/net/txgbe/meson.build
+++ b/drivers/net/txgbe/meson.build
@@ -21,6 +21,7 @@  sources = files(
 	'txgbe_rxtx.c',
 	'txgbe_tm.c',
 	'txgbe_vf_representor.c',
+	'rte_pmd_txgbe.c'
 )
 
 deps += ['hash', 'security']
diff --git a/drivers/net/txgbe/rte_pmd_txgbe.c b/drivers/net/txgbe/rte_pmd_txgbe.c
new file mode 100644
index 000000000..c84233bd6
--- /dev/null
+++ b/drivers/net/txgbe/rte_pmd_txgbe.c
@@ -0,0 +1,45 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2015-2020
+ */
+
+#include <rte_ethdev_driver.h>
+
+#include "base/txgbe.h"
+#include "txgbe_ethdev.h"
+#include "rte_pmd_txgbe.h"
+
+int
+rte_pmd_txgbe_set_vf_mac_addr(uint16_t port, uint16_t vf,
+			      struct rte_ether_addr *mac_addr)
+{
+	struct txgbe_hw *hw;
+	struct txgbe_vf_info *vfinfo;
+	int rar_entry;
+	struct rte_ether_addr *new_mac = mac_addr;
+	struct rte_eth_dev *dev;
+	struct rte_pci_device *pci_dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+	pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+
+	if (!is_txgbe_supported(dev))
+		return -ENOTSUP;
+
+	if (vf >= pci_dev->max_vfs)
+		return -EINVAL;
+
+	hw = TXGBE_DEV_HW(dev);
+	vfinfo = *(TXGBE_DEV_VFDATA(dev));
+	rar_entry = hw->mac.num_rar_entries - (vf + 1);
+
+	if (rte_is_valid_assigned_ether_addr(new_mac)) {
+		rte_memcpy(vfinfo[vf].vf_mac_addresses, (uint8_t *)new_mac,
+			   RTE_ETHER_ADDR_LEN);
+		return hw->mac.set_rar(hw, rar_entry, (uint8_t *)new_mac, vf,
+					   true);
+	}
+	return -EINVAL;
+}
+
diff --git a/drivers/net/txgbe/rte_pmd_txgbe.h b/drivers/net/txgbe/rte_pmd_txgbe.h
index 51a316f6f..b994b476e 100644
--- a/drivers/net/txgbe/rte_pmd_txgbe.h
+++ b/drivers/net/txgbe/rte_pmd_txgbe.h
@@ -15,6 +15,23 @@ 
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 
+/**
+ * Set the VF MAC address.
+ *
+ * @param port
+ *   The port identifier of the Ethernet device.
+ * @param vf
+ *   VF id.
+ * @param mac_addr
+ *   VF MAC address.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENODEV) if *port* invalid.
+ *   - (-EINVAL) if *vf* or *mac_addr* is invalid.
+ */
+int rte_pmd_txgbe_set_vf_mac_addr(uint16_t port, uint16_t vf,
+		struct rte_ether_addr *mac_addr);
+
 /**
  * Response sent back to txgbe driver from user app after callback
  */
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index fb2ffb0e1..0fe8e3415 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -5186,6 +5186,15 @@  txgbe_clear_all_l2_tn_filter(struct rte_eth_dev *dev)
 	return 0;
 }
 
+bool
+is_txgbe_supported(struct rte_eth_dev *dev)
+{
+	if (strcmp(dev->device->driver->name, rte_txgbe_pmd.driver.name))
+		return false;
+	else
+		return true;
+}
+
 static const struct eth_dev_ops txgbe_eth_dev_ops = {
 	.dev_configure              = txgbe_dev_configure,
 	.dev_infos_get              = txgbe_dev_info_get,
diff --git a/drivers/net/txgbe/txgbe_ethdev.h b/drivers/net/txgbe/txgbe_ethdev.h
index a6fd39b7b..73ca975e7 100644
--- a/drivers/net/txgbe/txgbe_ethdev.h
+++ b/drivers/net/txgbe/txgbe_ethdev.h
@@ -723,6 +723,8 @@  void txgbe_dev_setup_link_alarm_handler(void *param);
 void txgbe_read_stats_registers(struct txgbe_hw *hw,
 			   struct txgbe_hw_stats *hw_stats);
 
+bool is_txgbe_supported(struct rte_eth_dev *dev);
+
 void txgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev);
 void txgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);
 void txgbe_vlan_hw_strip_config(struct rte_eth_dev *dev);
diff --git a/drivers/net/txgbe/txgbe_vf_representor.c b/drivers/net/txgbe/txgbe_vf_representor.c
index bee4957c4..87af9b34b 100644
--- a/drivers/net/txgbe/txgbe_vf_representor.c
+++ b/drivers/net/txgbe/txgbe_vf_representor.c
@@ -10,6 +10,30 @@ 
 #include "base/txgbe_vf.h"
 #include "txgbe_ethdev.h"
 #include "txgbe_rxtx.h"
+#include "rte_pmd_txgbe.h"
+
+static int
+txgbe_vf_representor_link_update(struct rte_eth_dev *ethdev,
+	int wait_to_complete)
+{
+	struct txgbe_vf_representor *representor =
+			TXGBE_DEV_REPRESENTOR(ethdev);
+
+	return txgbe_dev_link_update_share(representor->pf_ethdev,
+		wait_to_complete);
+}
+
+static int
+txgbe_vf_representor_mac_addr_set(struct rte_eth_dev *ethdev,
+	struct rte_ether_addr *mac_addr)
+{
+	struct txgbe_vf_representor *representor =
+			TXGBE_DEV_REPRESENTOR(ethdev);
+
+	return rte_pmd_txgbe_set_vf_mac_addr(
+		representor->pf_ethdev->data->port_id,
+		representor->vf_id, mac_addr);
+}
 
 static int
 txgbe_vf_representor_dev_infos_get(struct rte_eth_dev *ethdev,
@@ -59,6 +83,8 @@  txgbe_vf_representor_dev_infos_get(struct rte_eth_dev *ethdev,
 
 static const struct eth_dev_ops txgbe_vf_representor_dev_ops = {
 	.dev_infos_get		= txgbe_vf_representor_dev_infos_get,
+	.link_update		= txgbe_vf_representor_link_update,
+	.mac_addr_set		= txgbe_vf_representor_mac_addr_set,
 };
 
 static uint16_t