From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D21B5A052E; Mon, 9 Mar 2020 09:31:00 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 223F71C0C9; Mon, 9 Mar 2020 09:29:23 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 660681C0C6 for ; Mon, 9 Mar 2020 09:29:21 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2020 01:29:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,518,1574150400"; d="scan'208";a="260350826" Received: from unknown (HELO dpdk-zhangalvin-dev.sh.intel.com) ([10.240.179.50]) by orsmga002.jf.intel.com with ESMTP; 09 Mar 2020 01:29:18 -0700 From: alvinx.zhang@intel.com To: dev@dpdk.org Cc: haiyue.wang@intel.com, xiaolong.ye@intel.com, qi.z.zhang@intel.com, beilei.xing@intel.com, Alvin Zhang Date: Mon, 9 Mar 2020 16:24:05 +0800 Message-Id: <1583742247-370386-13-git-send-email-alvinx.zhang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1583742247-370386-1-git-send-email-alvinx.zhang@intel.com> References: <1583742247-370386-1-git-send-email-alvinx.zhang@intel.com> Subject: [dpdk-dev] [PATCH v1 13/15] net/igc: implement TCP SYN filter 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" From: Alvin Zhang Support putting all TCP SYN packets into a specified queue. Signed-off-by: Alvin Zhang --- drivers/net/igc/igc_ethdev.h | 18 ++++++ drivers/net/igc/igc_filter.c | 129 +++++++++++++++++++++++++++++++++++++++++++ drivers/net/igc/igc_filter.h | 3 + 3 files changed, 150 insertions(+) diff --git a/drivers/net/igc/igc_ethdev.h b/drivers/net/igc/igc_ethdev.h index 639782c..68237aa 100644 --- a/drivers/net/igc/igc_ethdev.h +++ b/drivers/net/igc/igc_ethdev.h @@ -102,6 +102,11 @@ #define IGC_MAX_2TUPLE_FILTERS 8 #define IGC_2TUPLE_MAX_PRI 7 +#define IGC_SYN_FILTER_ENABLE 0x01 /* syn filter enable field */ +#define IGC_SYN_FILTER_QUEUE_SHIFT 1 /* syn filter queue field */ +#define IGC_SYN_FILTER_QUEUE 0x0000000E /* syn filter queue field */ +#define IGC_RFCTL_SYNQFP 0x00080000 /* SYNQFP in RFCTL register */ + /* structure for interrupt relative data */ struct igc_interrupt { uint32_t flags; @@ -176,6 +181,18 @@ struct igc_2tuple_filter { uint8_t queue; }; +/* Structure of TCP SYN filter */ +struct igc_syn_filter { + uint8_t queue; + /* + * Defines the priority between SYNQF and 2 tuple filter + * 0b = 2-tuple filter priority + * 1b = SYN filter priority + */ + uint8_t priority:1, + enable:1; /* 1-enable; 0-disable */ +}; + /* * Structure to store private data for each driver instance (for each port). */ @@ -192,6 +209,7 @@ struct igc_adapter { struct igc_ethertype_filter ethertype_filters[IGC_MAX_ETQF_FILTERS]; struct igc_2tuple_filter tuple2_filters[IGC_MAX_2TUPLE_FILTERS]; + struct igc_syn_filter syn_filter; }; #define IGC_DEV_PRIVATE(_dev) ((_dev)->data->dev_private) diff --git a/drivers/net/igc/igc_filter.c b/drivers/net/igc/igc_filter.c index 340dbee..5203d82 100644 --- a/drivers/net/igc/igc_filter.c +++ b/drivers/net/igc/igc_filter.c @@ -546,11 +546,136 @@ return ret; } +int +igc_set_syn_filter(struct rte_eth_dev *dev, + const struct rte_eth_syn_filter *filter) +{ + struct igc_hw *hw; + struct igc_adapter *igc; + struct igc_syn_filter *syn_filter; + uint32_t synqf, rfctl; + + if (filter->queue >= IGC_QUEUE_PAIRS_NUM) { + PMD_DRV_LOG(ERR, "out of range queue %u(max is %u)", + filter->queue, IGC_QUEUE_PAIRS_NUM); + return -EINVAL; + } + + igc = IGC_DEV_PRIVATE(dev); + syn_filter = &igc->syn_filter; + + if (syn_filter->enable) { + PMD_DRV_LOG(ERR, "SYN filter has been enabled before!"); + return -EEXIST; + } + + hw = IGC_DEV_PRIVATE_HW(dev); + synqf = (uint32_t)filter->queue << IGC_SYN_FILTER_QUEUE_SHIFT; + synqf |= IGC_SYN_FILTER_ENABLE; + + rfctl = IGC_READ_REG(hw, IGC_RFCTL); + if (filter->hig_pri) { + syn_filter->priority = 1; + rfctl |= IGC_RFCTL_SYNQFP; + } else { + syn_filter->priority = 0; + rfctl &= ~IGC_RFCTL_SYNQFP; + } + + syn_filter->enable = 1; + syn_filter->queue = filter->queue; + IGC_WRITE_REG(hw, IGC_RFCTL, rfctl); + IGC_WRITE_REG(hw, IGC_SYNQF(0), synqf); + IGC_WRITE_FLUSH(hw); + return 0; +} + +int +igc_del_syn_filter(struct rte_eth_dev *dev) +{ + struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev); + struct igc_adapter *igc = IGC_DEV_PRIVATE(dev); + struct igc_syn_filter *syn_filter = &igc->syn_filter; + + if (syn_filter->enable == 0) + return 0; + + syn_filter->enable = 0; + + IGC_WRITE_REG(hw, IGC_SYNQF(0), 0); + IGC_WRITE_FLUSH(hw); + return 0; +} + +static int +igc_syn_filter_get(struct rte_eth_dev *dev, struct rte_eth_syn_filter *filter) +{ + struct igc_adapter *igc = IGC_DEV_PRIVATE(dev); + struct igc_syn_filter *syn_filter = &igc->syn_filter; + + if (syn_filter->enable == 0) { + PMD_DRV_LOG(ERR, "syn filter not been set.\n"); + return -ENOENT; + } + + filter->hig_pri = syn_filter->priority; + filter->queue = syn_filter->queue; + return 0; +} + +/* clear the SYN filter */ +static void +igc_clear_syn_filter(struct rte_eth_dev *dev) +{ + struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev); + struct igc_adapter *igc = IGC_DEV_PRIVATE(dev); + + IGC_WRITE_REG(hw, IGC_SYNQF(0), 0); + IGC_WRITE_FLUSH(hw); + + memset(&igc->syn_filter, 0, sizeof(igc->syn_filter)); +} + +static int +igc_syn_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op, + struct rte_eth_syn_filter *filter) +{ + int ret; + + if (filter_op == RTE_ETH_FILTER_NOP) + return 0; + + if (filter == NULL) { + PMD_DRV_LOG(ERR, "filter shouldn't be NULL for operation %u", + filter_op); + return -EINVAL; + } + + switch (filter_op) { + case RTE_ETH_FILTER_ADD: + ret = igc_set_syn_filter(dev, filter); + break; + case RTE_ETH_FILTER_DELETE: + ret = igc_del_syn_filter(dev); + break; + case RTE_ETH_FILTER_GET: + ret = igc_syn_filter_get(dev, filter); + break; + default: + PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op); + ret = -EINVAL; + break; + } + + return ret; +} + void igc_clear_all_filter(struct rte_eth_dev *dev) { igc_clear_all_ethertype_filter(dev); igc_clear_all_ntuple_filter(dev); + igc_clear_syn_filter(dev); } int @@ -568,6 +693,10 @@ ret = igc_ntuple_filter_handle(dev, filter_op, (struct rte_eth_ntuple_filter *)arg); break; + case RTE_ETH_FILTER_SYN: + ret = igc_syn_filter_handle(dev, filter_op, + (struct rte_eth_syn_filter *)arg); + break; default: PMD_DRV_LOG(WARNING, "Filter type (%d) not supported", filter_type); diff --git a/drivers/net/igc/igc_filter.h b/drivers/net/igc/igc_filter.h index 7c5e843..4fad8e0 100644 --- a/drivers/net/igc/igc_filter.h +++ b/drivers/net/igc/igc_filter.h @@ -20,6 +20,9 @@ int igc_del_ethertype_filter(struct rte_eth_dev *dev, int igc_add_del_ntuple_filter(struct rte_eth_dev *dev, const struct rte_eth_ntuple_filter *ntuple, bool add); +int igc_set_syn_filter(struct rte_eth_dev *dev, + const struct rte_eth_syn_filter *filter); +int igc_del_syn_filter(struct rte_eth_dev *dev); void igc_clear_all_filter(struct rte_eth_dev *dev); -- 1.8.3.1