From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 006E21B535 for ; Thu, 12 Jul 2018 11:31:34 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id z13-v6so5288293wma.5 for ; Thu, 12 Jul 2018 02:31:33 -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=j8VbX1jANxkfYceXfWDEHAqvwkXaiqVftC18KlRQkjc=; b=SpZURVBFYBguuw9Yi+ijDJGSZfUw84T2qQOMOeJDqihJuhTnFAYvu/MLdc7AOcABSz yiybWj4Ywlbyxx5fzGAQr/Zq7sL4w7ghq602fndwoMR+YTQddiKuuljh6tLLcAr9ifwe NQ+C/qKP+Ja3Z1r4CzaOdELSEHfRNgh9CT/UB0aqcN+3fdezmYZHTZpDORjBmqEfXVnz dti0xIaTWlCOGr0re5QwBCEc/Jaece9LL8Wj0kUB84Fn2T3sYku1fAbZBGfVO90fPx12 MK3D//kd0dq2QvvIv77Sq6m6reI5Ys67TD+lkqnRuUwtpmjA38STXKdsuIWawjR4semR M/Fg== 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=j8VbX1jANxkfYceXfWDEHAqvwkXaiqVftC18KlRQkjc=; b=bkgSjBQjsgXfaTG8UMj0sVW7o+jigIWMCaTcubw8p1ERhfTApwbU9qNRdJNB7BdHKp Q27SIb6alM8m7vK8S9+s330bElnWH3/gkwKwMH7V/xXx7kMw1Y1jOOzFvctWQZOfeUQ6 DR6DEah7k3sCftZUBTautSzYRWiFMeCyfF53PZTgdkgEHo7nH40N20FwRR+U8ThKvW54 1JULQuhO+ak1Q6dpXrWYJUeCeveo6idEcc0zkvIdROmeEXLuYLokknopwtpwxc2L7bq4 f4Krwt8xrb5kjc8Wnzh69JzKLbaOvkKBeMfhkxxaaJ8EWflU81UN48oahMxhZQ0hD6pO dVHg== X-Gm-Message-State: AOUpUlFD/vPPB0x1boGd7+ploHF0ChqD/UCwAQK34DtNw1jH97fH9jiE P+6Hmb+yEOnSKhjX4TTY/q9kOYTApg== X-Google-Smtp-Source: AAOMgpcFPJrnE2w2WvGOGdKWnJ+0F4eD5WBVcZgotdMBl4ndUnsAsGfY2o3lZZzrIcPVOterAKT5HQ== X-Received: by 2002:a1c:b24c:: with SMTP id b73-v6mr620537wmf.141.1531387893545; Thu, 12 Jul 2018 02:31:33 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 02:31:32 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Yongseok Koh Cc: Adrien Mazarguil Date: Thu, 12 Jul 2018 11:30:56 +0200 Message-Id: <4da6a61eba9065a78a4af8f4fa78d7ccb7fced26.1531387413.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 10/21] net/mlx5: add flow UDP 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:34 -0000 Signed-off-by: Nelio Laranjeiro Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_flow.c | 97 +++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 6 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 513f70d40..0096ed8a2 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -52,6 +52,9 @@ extern const struct eth_dev_ops mlx5_dev_ops_isolate; #define MLX5_FLOW_FATE_DROP (1u << 0) #define MLX5_FLOW_FATE_QUEUE (1u << 1) +/* possible L3 layers protocols filtering. */ +#define MLX5_IP_PROTOCOL_UDP 17 + /** Handles information leading to a drop fate. */ struct mlx5_flow_verbs { unsigned int size; /**< Size of the attribute. */ @@ -68,10 +71,12 @@ struct mlx5_flow_verbs { struct rte_flow { TAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */ struct rte_flow_attr attributes; /**< User flow attribute. */ + uint32_t l3_protocol_en:1; /**< Protocol filtering requested. */ uint32_t layers; /**< Bit-fields of present layers see MLX5_FLOW_LAYER_*. */ uint32_t fate; /**< Bit-fields of present fate see MLX5_FLOW_FATE_*. */ + uint8_t l3_protocol; /**< valid when l3_protocol_en is set. */ struct mlx5_flow_verbs verbs; /* Verbs flow. */ uint16_t queue; /**< Destination queue to redirect traffic to. */ }; @@ -568,8 +573,6 @@ mlx5_flow_item_ipv4(const struct rte_flow_item *item, struct rte_flow *flow, if (ret < 0) return ret; flow->layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4; - if (size > flow_size) - return size; if (spec) { ipv4.val = (struct ibv_flow_ipv4_ext_filter){ .src_ip = spec->hdr.src_addr, @@ -589,7 +592,10 @@ mlx5_flow_item_ipv4(const struct rte_flow_item *item, struct rte_flow *flow, ipv4.val.proto &= ipv4.mask.proto; ipv4.val.tos &= ipv4.mask.tos; } - mlx5_flow_spec_verbs_add(flow, &ipv4, size); + flow->l3_protocol_en = !!ipv4.mask.proto; + flow->l3_protocol = ipv4.val.proto; + if (size <= flow_size) + mlx5_flow_spec_verbs_add(flow, &ipv4, size); return size; } @@ -660,8 +666,6 @@ mlx5_flow_item_ipv6(const struct rte_flow_item *item, struct rte_flow *flow, if (ret < 0) return ret; flow->layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6; - if (size > flow_size) - return size; if (spec) { unsigned int i; uint32_t vtc_flow_val; @@ -701,7 +705,85 @@ mlx5_flow_item_ipv6(const struct rte_flow_item *item, struct rte_flow *flow, ipv6.val.next_hdr &= ipv6.mask.next_hdr; ipv6.val.hop_limit &= ipv6.mask.hop_limit; } - mlx5_flow_spec_verbs_add(flow, &ipv6, size); + flow->l3_protocol_en = !!ipv6.mask.next_hdr; + flow->l3_protocol = ipv6.val.next_hdr; + if (size <= flow_size) + mlx5_flow_spec_verbs_add(flow, &ipv6, size); + 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_udp(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_udp *spec = item->spec; + const struct rte_flow_item_udp *mask = item->mask; + unsigned int size = sizeof(struct ibv_flow_spec_tcp_udp); + struct ibv_flow_spec_tcp_udp udp = { + .type = IBV_FLOW_SPEC_UDP, + .size = size, + }; + int ret; + + 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 (flow->l3_protocol_en && flow->l3_protocol != MLX5_IP_PROTOCOL_UDP) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "protocol filtering not compatible" + " with UDP layer"); + if (!mask) + mask = &rte_flow_item_udp_mask; + ret = mlx5_flow_item_acceptable + (item, (const uint8_t *)mask, + (const uint8_t *)&rte_flow_item_udp_mask, + sizeof(struct rte_flow_item_udp), error); + if (ret < 0) + return ret; + flow->layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP; + if (size > flow_size) + return size; + if (spec) { + udp.val.dst_port = spec->hdr.dst_port; + udp.val.src_port = spec->hdr.src_port; + udp.mask.dst_port = mask->hdr.dst_port; + udp.mask.src_port = mask->hdr.src_port; + /* Remove unwanted bits from values. */ + udp.val.src_port &= udp.mask.src_port; + udp.val.dst_port &= udp.mask.dst_port; + } + mlx5_flow_spec_verbs_add(flow, &udp, size); return size; } @@ -756,6 +838,9 @@ mlx5_flow_items(const struct rte_flow_item pattern[], case RTE_FLOW_ITEM_TYPE_IPV6: ret = mlx5_flow_item_ipv6(pattern, flow, remain, error); break; + case RTE_FLOW_ITEM_TYPE_UDP: + ret = mlx5_flow_item_udp(pattern, flow, remain, error); + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, -- 2.18.0