From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id 40AC137B0 for ; Mon, 28 May 2018 13:21:46 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id j1-v6so19712814wrm.1 for ; Mon, 28 May 2018 04:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=IP3C+uIi4bbS/4RZmJwgZ7PBeNgeo8gMsOPh3jdM56k=; b=RMiDG5woBjiUZPdi2OV9NCBR9UiM/vNAOBjC/5Xpd9gqTJxepqar7C8nekPeFlIXI+ nkWL6bZmna5sxZ2DSxOKJyNqxNgvQ0p14ZR3Bech9jFD+2H+DqyTm8N+lPXpEVMw7SsS FMCy+39eVXcfRhrZC4j4mIcr4Q3aOJMTbnsR4KxAFOzALKf6ZH0GZdB/c0P73T0Fs5H9 q996ClsyS0U4RqPadOzIWxf3XK4I+RyLLuAwMiLK+LeNCBkPD30deQP71tThdaA+zzb9 uI9ThQgSOm8XtFH6S/Hn0oPw9cow/R5kSqMQDPKTQ++Me/A1ZNpYmElRNEBqsmTKlOfh hqXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=IP3C+uIi4bbS/4RZmJwgZ7PBeNgeo8gMsOPh3jdM56k=; b=eN7KDNCFoj1A90MxZCBXn/nHLrQZBfLpPbkn8pgeJo2bG9VOga9OL4a5iE1rcH3JBU 0DYGHa8bbGo+8ch9GHvt2RDtJjWF9JqVu1YSiZest3GvsP0oE/5/BK+UxB1BdTH9fE6h tC3gaJWdIuhZ0y2vAzz4s7ZzoeZqJ5Os53lB/TgO9SovPoLOnxyPrZG8Z7X1HuR4Dp1Y oFqPUHpWRdr1RxTagVZgfdTFK2MPvwKZDBf3NXSfrV7pSgkV25QDBoIObNHycPTGx9Ne zNAGkrenrOfWoOp28bgKqU4DELc7MU0d253O992uAsNAW4wPig2ZN6HdGe9ZHNaFs7Cq sonQ== X-Gm-Message-State: ALKqPwdtzkp5S2LumcO8Bh/XgF/HUTN+hDTb6xQ0IBgAUUZaFKTvyWCq rYybMKN1Q0TjNLGFV5QPwQkCs39ThQ== X-Google-Smtp-Source: AB8JxZodrfOETvJvM71i9uV7EcvgmB0cejZHzl0rfZmUdSsG9kc8AqRXdyRU7//48ht9k1szU1xHyQ== X-Received: by 2002:adf:e9c3:: with SMTP id l3-v6mr11099822wrn.195.1527506504984; Mon, 28 May 2018 04:21:44 -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 q81-v6sm20755444wmd.14.2018.05.28.04.21.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 04:21:44 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Adrien Mazarguil , Yongseok Koh Date: Mon, 28 May 2018 13:21:40 +0200 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [DPDK 18.08 v1 07/12] net/mlx5: add flow IPv4 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: Mon, 28 May 2018 11:21:46 -0000 Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index ed27914aa..003c4aadd 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -479,6 +479,81 @@ mlx5_flow_item_vlan(const struct rte_flow_item *item, struct rte_flow *flow, return 0; } +/** + * Validate IPv4 layer and possibly create the Verbs specification. + * + * @param item[in] + * Item specification. + * @param flow[in, out] + * Pointer to flow structure. + * @param error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_item_ipv4(const struct rte_flow_item *item, struct rte_flow *flow, + struct rte_flow_error *error) +{ + const struct rte_flow_item_ipv4 *spec = item->spec; + const struct rte_flow_item_ipv4 *mask = item->mask; + const struct rte_flow_item_ipv4 nic_mask = { + .hdr = { + .src_addr = RTE_BE32(0xffffffff), + .dst_addr = RTE_BE32(0xffffffff), + .type_of_service = 0xff, + .next_proto_id = 0xff, + }, + }; + unsigned int size = sizeof(struct ibv_flow_spec_ipv4_ext); + struct ibv_flow_spec_ipv4_ext ipv4 = { + .type = IBV_FLOW_SPEC_IPV4_EXT, + .size = size, + }; + int ret; + + if (flow->verbs.layers & MLX5_FLOW_LAYER_L3) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "multiple L3 layers not supported"); + else if (flow->verbs.layers & MLX5_FLOW_LAYER_L4) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "L3 cannot follow an L4 layer."); + if (!mask) + mask = &rte_flow_item_ipv4_mask; + ret = mlx5_flow_item_validate(item, (const uint8_t *)mask, + (const uint8_t *)&nic_mask, + sizeof(struct rte_flow_item_ipv4), error); + if (ret < 0) + return ret; + if (spec) { + ipv4.val = (struct ibv_flow_ipv4_ext_filter){ + .src_ip = spec->hdr.src_addr, + .dst_ip = spec->hdr.dst_addr, + .proto = spec->hdr.next_proto_id, + .tos = spec->hdr.type_of_service, + }; + ipv4.mask = (struct ibv_flow_ipv4_ext_filter){ + .src_ip = mask->hdr.src_addr, + .dst_ip = mask->hdr.dst_addr, + .proto = mask->hdr.next_proto_id, + .tos = mask->hdr.type_of_service, + }; + /* Remove unwanted bits from values. */ + ipv4.val.src_ip &= ipv4.mask.src_ip; + ipv4.val.dst_ip &= ipv4.mask.dst_ip; + ipv4.val.proto &= ipv4.mask.proto; + ipv4.val.tos &= ipv4.mask.tos; + } + mlx5_flow_spec_verbs_add(flow, &ipv4, size); + flow->verbs.layers |= MLX5_FLOW_LAYER_L3_IPV4; + return 0; +} + /** * Validate items provided by the user. * @@ -509,6 +584,9 @@ mlx5_flow_items(const struct rte_flow_item items[], case RTE_FLOW_ITEM_TYPE_VLAN: ret = mlx5_flow_item_vlan(items, flow, error); break; + case RTE_FLOW_ITEM_TYPE_IPV4: + ret = mlx5_flow_item_ipv4(items, flow, error); + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, -- 2.17.0