From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 4F5654C6E for ; Tue, 27 May 2014 09:57:43 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 27 May 2014 00:57:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,917,1392192000"; d="scan'208";a="546982679" Received: from fmsmsx103.amr.corp.intel.com ([10.19.9.34]) by orsmga002.jf.intel.com with ESMTP; 27 May 2014 00:57:52 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.19.17.7) by FMSMSX103.amr.corp.intel.com (10.19.9.34) with Microsoft SMTP Server (TLS) id 14.3.123.3; Tue, 27 May 2014 00:57:52 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX153.amr.corp.intel.com (10.19.17.7) with Microsoft SMTP Server (TLS) id 14.3.123.3; Tue, 27 May 2014 00:57:51 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.192]) by shsmsx102.ccr.corp.intel.com ([169.254.2.190]) with mapi id 14.03.0123.003; Tue, 27 May 2014 15:57:49 +0800 From: "Ming, LiX" To: "Wu, Jingjing" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2 1/4]ethdev: add ethdev APIs for NIC filters of generic filter Thread-Index: AQHPdvDS6U38exQXzkyQ+3bw1aVWs5tUEnxA Date: Tue, 27 May 2014 07:57:49 +0000 Message-ID: <0976FC66838DDE4585886952506C9436FBA620@SHSMSX104.ccr.corp.intel.com> References: <1400895442-32433-1-git-send-email-jingjing.wu@intel.com> <1400895442-32433-2-git-send-email-jingjing.wu@intel.com> In-Reply-To: <1400895442-32433-2-git-send-email-jingjing.wu@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-cr-hashedpuzzle: AcWR A5j4 Bx1u B2gI CdAL CoNR C/Uo D3Bc FENY FmWZ FzIk Gs+S HuCB Ijod JXV+ KPU2; 1; ZABlAHYAQABkAHAAZABrAC4AbwByAGcA; Sosha1_v1; 7; {9F797200-654D-4D84-87AB-76FF06FCED05}; bABpAHgALgBtAGkAbgBnAEAAaQBuAHQAZQBsAC4AYwBvAG0A; Tue, 27 May 2014 07:57:47 GMT; UgBFADoAIABbAGQAcABkAGsALQBkAGUAdgBdACAAWwBQAEEAVABDAEgAIAB2ADIAIAAxAC8ANABdAGUAdABoAGQAZQB2ADoAIABhAGQAZAAgAGUAdABoAGQAZQB2ACAAQQBQAEkAcwAgAGYAbwByACAATgBJAEMAIABmAGkAbAB0AGUAcgBzACAAbwBmAAkAZwBlAG4AZQByAGkAYwAgAGYAaQBsAHQAZQByAA== x-cr-puzzleid: {9F797200-654D-4D84-87AB-76FF06FCED05} x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [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: Tue, 27 May 2014 07:57:44 -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(-) Test-by: lmingX lix,ming@intel.com Compile pass >>Compile OS: FC20 x86_64 >>Kernel version: 3.11.10-301 >>GCC version: 4.8.2 >>Server: Crownpass 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 =20 #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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &rte_eth_devices[port_id]; + filter.enable =3D 1; + filter.hig_pri =3D 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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &rte_eth_devices[port_id]; + filter.enable =3D 0; + filter.hig_pri =3D 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 =3D=3D NULL || rx_queue =3D=3D NULL) + return (-EINVAL); + + if (port_id >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + if (filter->ethertype =3D=3D ETHER_TYPE_IPv4 || + filter->ethertype =3D=3D ETHER_TYPE_IPv6){ + PMD_DEBUG_TRACE("IP and IPv6 are not supported" + " in ethertype filter\n"); + return (-EINVAL); + } + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 =3D=3D NULL || rx_queue =3D=3D NULL) + return (-EINVAL); + + if (port_id >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + if (filter->protocol !=3D IPPROTO_TCP && + filter->tcp_flags !=3D 0){ + PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value" + " is not TCP\n", + filter->tcp_flags); + return (-EINVAL); + } + + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 =3D=3D NULL || rx_queue =3D=3D NULL) + return (-EINVAL); + + if (port_id >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + if (filter->protocol !=3D IPPROTO_TCP && + filter->tcp_flags !=3D 0){ + PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value" + " is not TCP\n", + filter->tcp_flags); + return (-EINVAL); + } + + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 =3D=3D NULL || rx_queue =3D=3D NULL) + return (-EINVAL); + + if (port_id >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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 =3D=3D NULL || rx_queue =3D=3D NULL) + return (-EINVAL); + + if (port_id >=3D nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); + return (-ENODEV); + } + + dev =3D &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); =20 +#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; /**