From patchwork Wed Jan 11 17:24:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iremonger, Bernard" X-Patchwork-Id: 19151 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 350ACF919; Wed, 11 Jan 2017 18:25:10 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id CA618F8C0; Wed, 11 Jan 2017 18:25:07 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 11 Jan 2017 09:25:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,346,1477983600"; d="scan'208";a="212215485" Received: from sivswdev01.ir.intel.com (HELO localhost.localdomain) ([10.237.217.45]) by fmsmga004.fm.intel.com with ESMTP; 11 Jan 2017 09:25:04 -0800 From: Bernard Iremonger To: dev@dpdk.org, wenzhuo.lu@intel.com, ferruh.yigit@intel.com Cc: Bernard Iremonger , stable@dpdk.org Date: Wed, 11 Jan 2017 17:24:59 +0000 Message-Id: <1484155499-13349-1-git-send-email-bernard.iremonger@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1484144751-10412-1-git-send-email-bernard.iremonger@intel.com> References: <1484144751-10412-1-git-send-email-bernard.iremonger@intel.com> Subject: [dpdk-dev] [PATCH v2] net/ixgbe: fix API parameter checking X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-by: Ferruh Yigit --- 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(-) 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)