From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 7AE465934 for ; Sat, 24 May 2014 03:37:29 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 23 May 2014 18:37:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,898,1392192000"; d="scan'208";a="544203197" Received: from shilc102.sh.intel.com ([10.239.39.44]) by fmsmga002.fm.intel.com with ESMTP; 23 May 2014 18:37:36 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shilc102.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4O1bWa7027808; Sat, 24 May 2014 09:37:34 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4O1bSQe032550; Sat, 24 May 2014 09:37:30 +0800 Received: (from wujingji@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s4O1bSOC032546; Sat, 24 May 2014 09:37:28 +0800 From: Jingjing Wu To: dev@dpdk.org Date: Sat, 24 May 2014 09:37:19 +0800 Message-Id: <1400895442-32433-2-git-send-email-jingjing.wu@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1400895442-32433-1-git-send-email-jingjing.wu@intel.com> References: <1400895442-32433-1-git-send-email-jingjing.wu@intel.com> Subject: [dpdk-dev] [PATCH v2 1/4]ethdev: add ethdev APIs for NIC filters of generic filter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 May 2014 01:37:31 -0000 This patch adds APIs for NIC filters list below: ethertype filter, syn filter, 2tuple filter, flex filter, 5tuple filter Signed-off-by: jingjing.wu --- lib/librte_ether/rte_ethdev.c | 281 ++++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 421 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 701 insertions(+), 1 deletion(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index a5727dd..afd4fe8 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -2335,3 +2336,283 @@ rte_eth_dev_bypass_wd_reset(uint8_t port_id) return 0; } #endif + +int +rte_eth_dev_add_syn_filter(uint8_t port_id, uint8_t high_pri, + uint8_t rx_queue) +{ + struct rte_eth_dev *dev; + struct rte_syn_filter filter; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + filter.enable = 1; + filter.hig_pri = high_pri; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_syn_filter, -ENOTSUP); + return (*dev->dev_ops->set_syn_filter)(dev, &filter, rx_queue); +} + +int +rte_eth_dev_remove_syn_filter(uint8_t port_id) +{ + struct rte_eth_dev *dev; + struct rte_syn_filter filter; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + filter.enable = 0; + filter.hig_pri = 0; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_syn_filter, -ENOTSUP); + return (*dev->dev_ops->set_syn_filter)(dev, &filter, 0); +} + +int +rte_eth_dev_get_syn_filter(uint8_t port_id, + struct rte_syn_filter *filter, uint8_t *rx_queue) +{ + struct rte_eth_dev *dev; + + if (filter == NULL || rx_queue == NULL) + return (-EINVAL); + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_syn_filter, -ENOTSUP); + return (*dev->dev_ops->get_syn_filter)(dev, filter, rx_queue); +} + +int +rte_eth_dev_add_ethertype_filter(uint8_t port_id, uint16_t index, + struct rte_ethertype_filter *filter, uint8_t rx_queue) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + if (filter->ethertype == ETHER_TYPE_IPv4 || + filter->ethertype == ETHER_TYPE_IPv6){ + PMD_DEBUG_TRACE("IP and IPv6 are not supported" + " in ethertype filter\n"); + return (-EINVAL); + } + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_ethertype_filter, -ENOTSUP); + return (*dev->dev_ops->add_ethertype_filter)(dev, index, + filter, rx_queue); +} + +int +rte_eth_dev_remove_ethertype_filter(uint8_t port_id, uint16_t index) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_ethertype_filter, -ENOTSUP); + return (*dev->dev_ops->remove_ethertype_filter)(dev, index); +} + +int +rte_eth_dev_get_ethertype_filter(uint8_t port_id, uint16_t index, + struct rte_ethertype_filter *filter, uint8_t *rx_queue) +{ + struct rte_eth_dev *dev; + + if (filter == NULL || rx_queue == NULL) + return (-EINVAL); + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_ethertype_filter, -ENOTSUP); + return (*dev->dev_ops->get_ethertype_filter)(dev, index, + filter, rx_queue); +} + +int +rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index, + struct rte_2tuple_filter *filter, uint8_t rx_queue) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + if (filter->protocol != IPPROTO_TCP && + filter->tcp_flags != 0){ + PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value" + " is not TCP\n", + filter->tcp_flags); + return (-EINVAL); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_2tuple_filter, -ENOTSUP); + return (*dev->dev_ops->add_2tuple_filter)(dev, index, filter, rx_queue); +} + +int +rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_2tuple_filter, -ENOTSUP); + return (*dev->dev_ops->remove_2tuple_filter)(dev, index); +} + +int +rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index, + struct rte_2tuple_filter *filter, uint8_t *rx_queue) +{ + struct rte_eth_dev *dev; + + if (filter == NULL || rx_queue == NULL) + return (-EINVAL); + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_2tuple_filter, -ENOTSUP); + return (*dev->dev_ops->get_2tuple_filter)(dev, index, filter, rx_queue); +} + +int +rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index, + struct rte_5tuple_filter *filter, uint8_t rx_queue) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + if (filter->protocol != IPPROTO_TCP && + filter->tcp_flags != 0){ + PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value" + " is not TCP\n", + filter->tcp_flags); + return (-EINVAL); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_5tuple_filter, -ENOTSUP); + return (*dev->dev_ops->add_5tuple_filter)(dev, index, filter, rx_queue); +} + +int +rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_5tuple_filter, -ENOTSUP); + return (*dev->dev_ops->remove_5tuple_filter)(dev, index); +} + +int +rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index, + struct rte_5tuple_filter *filter, uint8_t *rx_queue) +{ + struct rte_eth_dev *dev; + + if (filter == NULL || rx_queue == NULL) + return (-EINVAL); + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_5tuple_filter, -ENOTSUP); + return (*dev->dev_ops->get_5tuple_filter)(dev, index, filter, + rx_queue); +} + +int +rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index, + struct rte_flex_filter *filter, uint8_t rx_queue) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_flex_filter, -ENOTSUP); + return (*dev->dev_ops->add_flex_filter)(dev, index, filter, rx_queue); +} + +int +rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_flex_filter, -ENOTSUP); + return (*dev->dev_ops->remove_flex_filter)(dev, index); +} + +int +rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index, + struct rte_flex_filter *filter, uint8_t *rx_queue) +{ + struct rte_eth_dev *dev; + + if (filter == NULL || rx_queue == NULL) + return (-EINVAL); + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return (-ENODEV); + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_flex_filter, -ENOTSUP); + return (*dev->dev_ops->get_flex_filter)(dev, index, filter, + rx_queue); +} diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index d5ea46b..21257b2 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -808,6 +808,71 @@ struct rte_eth_dev_callback; /** @internal Structure to keep track of registered callbacks */ TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback); +#define TCP_UGR_FLAG 0x20 +#define TCP_ACK_FLAG 0x10 +#define TCP_PSH_FLAG 0x08 +#define TCP_RST_FLAG 0x04 +#define TCP_SYN_FLAG 0x02 +#define TCP_FIN_FLAG 0x01 +#define TCP_FLAG_ALL 0x3F + +/** + * A structure used to define an ethertype filter. + */ +struct rte_ethertype_filter { + uint16_t ethertype; /**