From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id D69A21B57B for ; Thu, 12 Jul 2018 11:31:34 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id c13-v6so20921669wrt.1 for ; Thu, 12 Jul 2018 02:31:34 -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=y8MFaQXc7e3EnsWbK4yeU7aIKmKQhlgqYByFD8RhIG8QPoFAXqItqgYvTrEace7rSA DiwLLD5E7E+74BWqL9w5DbGuY7ZAxJEoq0E1wlvvQI4s2TV1RznGjlz71CxLUagJ0S+F h5wou/W1/PLstUBsy13cG5LzZSuAvy/ehdvOO5+rsPZR5nbrXjYrr1S/rSTfH4gNNvR8 aHag2IXrKpwtuWSoTTB5JMbTB1fa034K9ySBDNgbLXLz30y7yFg2fSog5QdikjSwXMUD ApNvJttkGuCVT3nPR8nkVwxR7+7qVY4mjKft4cvq1Oa2F+XvpFJ0bzA7+4N42MLqPm31 yM7Q== 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=Jxzi8zO+HaQXHUm1miMUiX6OdAYOUwq4hpw1mguGMRfSDZYXcTmC6nlqYhMPGBYA+3 UrFBNS4Cn0lYJ1tQwc51aGSqruWISC57qEwZS+IJ3G4sf2SF0mtPE7ToElYMM8auVr8c /mBqV8JPv7J2yUhnP7UwN94A2F3GVF3PA8kYaroNW26WW9bqX2dAxAjWBTK9a3HKDMF8 XTn/tJgaPF2Fglc716epHfApdiIRUBe+CMyEHjJc85BTUPG5aMGDLdwAPelcahJrv2Im /t0cpzyCtIDCoalnBk9VMT3cxTeTtjUwYHF4WifNzYZ/5CRq4gFcg5L/YWvFQf/3X5NN Ms9w== X-Gm-Message-State: AOUpUlEkCCBkr5i1ZqwuBDX6ASm+gJZfuPqbM0n8Yg3issbLfJhQhgmi LKE09dupoLxcuz6hzCTl19z2FqVvNA== X-Google-Smtp-Source: AAOMgpdwKNDcFzRKnDCIMSZR1YKzQDOPFdKYl0CCZKNttIg8ErDSXLr+jJ3KxF8//DCgbt6AxLfK1Q== X-Received: by 2002:adf:8541:: with SMTP id 59-v6mr1062475wrh.223.1531387894442; Thu, 12 Jul 2018 02:31:34 -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 s2-v6sm18717603wrn.75.2018.07.12.02.31.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 02:31:33 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Yongseok Koh Cc: Adrien Mazarguil Date: Thu, 12 Jul 2018 11:30:57 +0200 Message-Id: <9cb634f4990a421a9328aa1e71714a2933c8ebea.1531387413.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 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: Thu, 12 Jul 2018 09:31:35 -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