diff mbox

[dpdk-dev,v2] net/ixgbe: fix API parameter checking

Message ID 1484155499-13349-1-git-send-email-bernard.iremonger@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation fail Compilation issues

Commit Message

Iremonger, Bernard Jan. 11, 2017, 5:24 p.m. UTC
Add checks to rte_pmd_ixgbe_* API's to ensure that the port
is an ixgbe port.

Fixes: 49e248223e9f ("net/ixgbe: add API for VF management")

CC: stable@dpdk.org
Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
Changes in v2:
Moved pmd checks into new function is_ixgbe_pmd.

 drivers/net/ixgbe/ixgbe_ethdev.c | 55 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 7 deletions(-)

Comments

Ferruh Yigit Jan. 11, 2017, 6:21 p.m. UTC | #1
On 1/11/2017 5:24 PM, Bernard Iremonger wrote:
> Add checks to rte_pmd_ixgbe_* API's to ensure that the port
> is an ixgbe port.
> 
> Fixes: 49e248223e9f ("net/ixgbe: add API for VF management")
> 
> CC: stable@dpdk.org
> Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/master, thanks.
diff mbox

Patch

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index b7ddd4f..cc8f7d6 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -1,7 +1,7 @@ 
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -244,6 +244,7 @@  static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
 static void ixgbe_set_default_mac_addr(struct rte_eth_dev *dev,
 					   struct ether_addr *mac_addr);
 static void ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config);
+static int is_ixgbe_pmd(const char *driver_name);
 
 /* For Virtual Function support */
 static int eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev);
@@ -4050,6 +4051,18 @@  ixgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
 	ixgbe_add_rar(dev, addr, 0, 0);
 }
 
+static int
+is_ixgbe_pmd(const char *driver_name)
+{
+	if (!strstr(driver_name, "ixgbe"))
+		return -ENOTSUP;
+
+	if (strstr(driver_name, "ixgbe_vf"))
+		return -ENOTSUP;
+
+	return 0;
+}
+
 int
 rte_pmd_ixgbe_set_vf_mac_addr(uint8_t port, uint16_t vf,
 		struct ether_addr *mac_addr)
@@ -4066,6 +4079,9 @@  rte_pmd_ixgbe_set_vf_mac_addr(uint8_t port, uint16_t vf,
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
+
 	if (vf >= dev_info.max_vfs)
 		return -EINVAL;
 
@@ -4564,6 +4580,9 @@  rte_pmd_ixgbe_set_vf_vlan_anti_spoof(uint8_t port, uint16_t vf, uint8_t on)
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
+
 	if (vf >= dev_info.max_vfs)
 		return -EINVAL;
 
@@ -4591,6 +4610,9 @@  rte_pmd_ixgbe_set_vf_mac_anti_spoof(uint8_t port, uint16_t vf, uint8_t on)
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
+
 	if (vf >= dev_info.max_vfs)
 		return -EINVAL;
 
@@ -4617,10 +4639,13 @@  rte_pmd_ixgbe_set_vf_vlan_insert(uint8_t port, uint16_t vf, uint16_t vlan_id)
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
+
 	if (vf >= dev_info.max_vfs)
 		return -EINVAL;
 
-	if (vlan_id > 4095)
+	if (vlan_id > ETHER_MAX_VLAN_ID)
 		return -EINVAL;
 
 	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -4643,10 +4668,15 @@  rte_pmd_ixgbe_set_tx_loopback(uint8_t port, uint8_t on)
 	struct ixgbe_hw *hw;
 	uint32_t ctrl;
 	struct rte_eth_dev *dev;
+	struct rte_eth_dev_info dev_info;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
 
 	dev = &rte_eth_devices[port];
+	rte_eth_dev_info_get(port, &dev_info);
+
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
 
 	if (on > 1)
 		return -EINVAL;
@@ -4672,10 +4702,15 @@  rte_pmd_ixgbe_set_all_queues_drop_en(uint8_t port, uint8_t on)
 	int i;
 	int num_queues = (int)(IXGBE_QDE_IDX_MASK >> IXGBE_QDE_IDX_SHIFT);
 	struct rte_eth_dev *dev;
+	struct rte_eth_dev_info dev_info;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
 
 	dev = &rte_eth_devices[port];
+	rte_eth_dev_info_get(port, &dev_info);
+
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
 
 	if (on > 1)
 		return -EINVAL;
@@ -4704,6 +4739,9 @@  rte_pmd_ixgbe_set_vf_split_drop_en(uint8_t port, uint16_t vf, uint8_t on)
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
+
 	/* only support VF's 0 to 63 */
 	if ((vf >= dev_info.max_vfs) || (vf > 63))
 		return -EINVAL;
@@ -4736,6 +4774,9 @@  rte_pmd_ixgbe_set_vf_vlan_stripq(uint8_t port, uint16_t vf, uint8_t on)
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
+		return -ENOTSUP;
+
 	if (vf >= dev_info.max_vfs)
 		return -EINVAL;
 
@@ -4775,7 +4816,7 @@  rte_pmd_ixgbe_set_vf_rxmode(uint8_t port, uint16_t vf, uint16_t rx_mask, uint8_t
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
-	if (strstr(dev_info.driver_name, "ixgbe_vf"))
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
 		return -ENOTSUP;
 
 	if (vf >= dev_info.max_vfs)
@@ -4822,7 +4863,7 @@  rte_pmd_ixgbe_set_vf_rx(uint8_t port, uint16_t vf, uint8_t on)
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
-	if (strstr(dev_info.driver_name, "ixgbe_vf"))
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
 		return -ENOTSUP;
 
 	if (vf >= dev_info.max_vfs)
@@ -4873,7 +4914,7 @@  rte_pmd_ixgbe_set_vf_tx(uint8_t port, uint16_t vf, uint8_t on)
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
-	if (strstr(dev_info.driver_name, "ixgbe_vf"))
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
 		return -ENOTSUP;
 
 	if (vf >= dev_info.max_vfs)
@@ -4922,7 +4963,7 @@  rte_pmd_ixgbe_set_vf_vlan_filter(uint8_t port, uint16_t vlan,
 	dev = &rte_eth_devices[port];
 	rte_eth_dev_info_get(port, &dev_info);
 
-	if (strstr(dev_info.driver_name, "ixgbe_vf"))
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
 		return -ENOTSUP;
 
 	if ((vlan > ETHER_MAX_VLAN_ID) || (vf_mask == 0))
@@ -4965,7 +5006,7 @@  int rte_pmd_ixgbe_set_vf_rate_limit(uint8_t port, uint16_t vf,
 	rte_eth_dev_info_get(port, &dev_info);
 	rte_eth_link_get_nowait(port, &link);
 
-	if (strstr(dev_info.driver_name, "ixgbe_vf"))
+	if (is_ixgbe_pmd(dev_info.driver_name) != 0)
 		return -ENOTSUP;
 
 	if (vf >= dev_info.max_vfs)