From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 7501E1B4D0 for ; Wed, 11 Jul 2018 09:23:27 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id 69-v6so1383368wmf.3 for ; Wed, 11 Jul 2018 00:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+jIgZdPvzrOLEyYIES6ZvqCP8B4B6iee7ZK4xNloXdU=; b=SL+HfimsRvNPpPl1iZBUNjvdbXB2Qifr9eReS+v+etRVz+p9QXn4LOcvJQCkeFkyGg PxTNtXeV9iUHezwuqAhcKnqEdB6mBxrvr482nTdIBHVwhlgbJs1tktJgGJ7HnL3rkBZY Q3pniGYLUPwQWAgba3DEnZXReMOP90haP4VX4zIO+1DgxSBQlKP8qnmibbxA+Kv8DpFz YD+lOPy5LhH6VB98MzEfM16Ibi/d/RwfPpwemLmzMFuOHj+98SaCNrWMg83wjGAQiJZE IEj1Y6t8lLexapiQHah5uFV/3G4TfcTBVNo/cOZUpg+cdLkUVCCO0Uz8DUw3gUeu59ps T2Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+jIgZdPvzrOLEyYIES6ZvqCP8B4B6iee7ZK4xNloXdU=; b=HWHBIABpNV2TBxEHPu91S3A4w2Nqv10F7U8SCsbvcxuNDksdzy9VE4x50+AJAUHxuP vlFXh5P14DhOodY/XP+294MnS3+YkM/qlNBFhpohyEuWtDk51p9tN7D2sc5hS27zXC/9 IW7WVko8U+lY00pfdhHU77HAEnVY4oCxA67y7EjNT9IfanL5Je3GGKxIWoMEzNxR5MCs OTffeNJV+GvhrnPefYFxG+mDWrzoLQ9MtcW/feCag/3wBXL3wXekS2BmKjq5cCosc68i tUf9HyeANc4BfCJ0HrdSISQEqaUvqhheHVpJtncdqwmSOOXBhnjqpvGtC5eskJWu0llh 0lAg== X-Gm-Message-State: APt69E3G97SGCZs5/xkLBY3hxwUZC5uVqdIzZPmxcNyGjTHNf4sSeXvS ANatW0MOeunMY6t/T1OG9tLLx3mtrA== X-Google-Smtp-Source: AAOMgpcLkxvy49Bzn3f0SiO8fydBJbheVux4n/B557dzLuDcFiU8uAG+vR9keCc7k8SWzyCUSFTEEQ== X-Received: by 2002:a1c:3351:: with SMTP id z78-v6mr16003435wmz.23.1531293807009; Wed, 11 Jul 2018 00:23:27 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id t10-v6sm31314212wre.95.2018.07.11.00.23.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:23:26 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Yongseok Koh Cc: Adrien Mazarguil Date: Wed, 11 Jul 2018 09:22:44 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 11/21] net/mlx5: add flow TCP item 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: , X-List-Received-Date: Wed, 11 Jul 2018 07:23:28 -0000 Signed-off-by: Nelio Laranjeiro Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_flow.c | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 0096ed8a2..f646eee01 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -53,6 +53,7 @@ extern const struct eth_dev_ops mlx5_dev_ops_isolate; #define MLX5_FLOW_FATE_QUEUE (1u << 1) /* possible L3 layers protocols filtering. */ +#define MLX5_IP_PROTOCOL_TCP 6 #define MLX5_IP_PROTOCOL_UDP 17 /** Handles information leading to a drop fate. */ @@ -787,6 +788,81 @@ mlx5_flow_item_udp(const struct rte_flow_item *item, struct rte_flow *flow, return size; } +/** + * Convert the @p item into a Verbs specification after ensuring the NIC + * will understand and process it correctly. + * If the necessary size for the conversion is greater than the @p flow_size, + * nothing is written in @p flow, the validation is still performed. + * + * @param[in] item + * Item specification. + * @param[in, out] flow + * Pointer to flow structure. + * @param[in] flow_size + * Size in bytes of the available space in @p flow, if too small, nothing is + * written. + * @param[out] error + * Pointer to error structure. + * + * @return + * On success the number of bytes consumed/necessary, if the returned value + * is lesser or equal to @p flow_size, the @p item has fully been converted, + * otherwise another call with this returned memory size should be done. + * On error, a negative errno value is returned and rte_errno is set. + */ +static int +mlx5_flow_item_tcp(const struct rte_flow_item *item, struct rte_flow *flow, + const size_t flow_size, struct rte_flow_error *error) +{ + const struct rte_flow_item_tcp *spec = item->spec; + const struct rte_flow_item_tcp *mask = item->mask; + unsigned int size = sizeof(struct ibv_flow_spec_tcp_udp); + struct ibv_flow_spec_tcp_udp tcp = { + .type = IBV_FLOW_SPEC_TCP, + .size = size, + }; + int ret; + + if (flow->l3_protocol_en && flow->l3_protocol != MLX5_IP_PROTOCOL_TCP) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "protocol filtering not compatible" + " with TCP layer"); + if (!(flow->layers & MLX5_FLOW_LAYER_OUTER_L3)) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "L3 is mandatory to filter on L4"); + if (flow->layers & MLX5_FLOW_LAYER_OUTER_L4) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "L4 layer is already present"); + if (!mask) + mask = &rte_flow_item_tcp_mask; + ret = mlx5_flow_item_acceptable + (item, (const uint8_t *)mask, + (const uint8_t *)&rte_flow_item_tcp_mask, + sizeof(struct rte_flow_item_tcp), error); + if (ret < 0) + return ret; + flow->layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP; + if (size > flow_size) + return size; + if (spec) { + tcp.val.dst_port = spec->hdr.dst_port; + tcp.val.src_port = spec->hdr.src_port; + tcp.mask.dst_port = mask->hdr.dst_port; + tcp.mask.src_port = mask->hdr.src_port; + /* Remove unwanted bits from values. */ + tcp.val.src_port &= tcp.mask.src_port; + tcp.val.dst_port &= tcp.mask.dst_port; + } + mlx5_flow_spec_verbs_add(flow, &tcp, size); + return size; +} + /** * Convert the @p pattern into a Verbs specifications after ensuring the NIC * will understand and process it correctly. @@ -841,6 +917,9 @@ mlx5_flow_items(const struct rte_flow_item pattern[], case RTE_FLOW_ITEM_TYPE_UDP: ret = mlx5_flow_item_udp(pattern, flow, remain, error); break; + case RTE_FLOW_ITEM_TYPE_TCP: + ret = mlx5_flow_item_tcp(pattern, flow, remain, error); + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, -- 2.18.0