From patchwork Wed Dec 28 10:37:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?N=C3=A9lio_Laranjeiro?= X-Patchwork-Id: 18607 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id E954CD4CE; Wed, 28 Dec 2016 11:38:24 +0100 (CET) Received: from mail-wj0-f182.google.com (mail-wj0-f182.google.com [209.85.210.182]) by dpdk.org (Postfix) with ESMTP id 7CC9C5320 for ; Wed, 28 Dec 2016 11:37:39 +0100 (CET) Received: by mail-wj0-f182.google.com with SMTP id c11so129405865wjx.3 for ; Wed, 28 Dec 2016 02:37:39 -0800 (PST) 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 :in-reply-to:references; bh=w15oyb4bGosDJ3gRjULRCIy6GdVMb2oqJ0DrRaxBsNg=; b=N3+1bi369KoTLUvrmXA0XTBnhVgL9N0kVJr5eLOQwglTYjX5+bQx8xVDi7rJSD07e3 DNsH9TJ0MqhKtfOUS+ZVHtOWIRAADBiNycRBOsWRvxQ9g2VpxFsGHwCQdo9ZqhPnkG2E 1TQEd4jp4Y8q4tw35mFvTEmvtFhqY+Kk964SxTcfLs6rolsQ6ge9b/qvaTTOvVrRHMCn OrwPm89zP8KwbDVMg3Fq2q1NuBeqZALVUWCTVLIfXjEoF4qqyjoZhMYw1kGzOf8sJ/y6 dMbGnAVbsG32w2N4QxVBDx8aa11HzkchGhbfGOco+baht0VpmflIo2hEl+guaQ+h0E5k 2rKw== 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:in-reply-to:references; bh=w15oyb4bGosDJ3gRjULRCIy6GdVMb2oqJ0DrRaxBsNg=; b=fdNbhriwpd55CQyv6kCP1fPakXXh04DvLk8FK7WIJd/n28yIP1miYQG3U2cDg29Q1o Q1sbMBLyB5rh9pjB+XvxMO6HxOqC36deZFmriMs+ezj3gKRYZKSwzaTPLCrla2HUCtaC 8rvg4OQTbYcqhhjVwC4BmPTxRq/Cm6n5jA8r60ECKV/Cef8knTvafCCfCeiCDs/0SDjt ewBJAJ49aERouVSIKMce4TkrKfCDZBL9St28zgbCpwd2Gnh8HwiOUVMND5L/ZUwrJeRg T/GCpLNDNsyHo3rdX2JPCDKCdwDVhz5GL5XcgJp1lDzftHeOc74zhn6YJ5b/LcKjOIBH qydQ== X-Gm-Message-State: AIkVDXKzK/y6DoZMRnZp26zipCQzl9dosDKhiCXo7Q7/Cndq2iDimCD6sDJpqDk4vLEf3c9l X-Received: by 10.194.174.39 with SMTP id bp7mr31069207wjc.5.1482921459175; Wed, 28 Dec 2016 02:37:39 -0800 (PST) Received: from ping.vm.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id kq6sm30022703wjc.7.2016.12.28.02.37.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Dec 2016 02:37:38 -0800 (PST) From: Nelio Laranjeiro To: dev@dpdk.org Cc: Adrien Mazarguil Date: Wed, 28 Dec 2016 11:37:17 +0100 Message-Id: <6bb9c5d38e4d0de82451c3f081f3c77495fe3985.1482920437.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 4/6] net/mlx5: support VXLAN flow 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Nelio Laranjeiro Acked-by: Adrien Mazarguil --- drivers/net/mlx5/mlx5_flow.c | 72 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 549da6c..1ec0ef5 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -69,6 +69,9 @@ mlx5_flow_create_udp(const struct rte_flow_item *item, void *data); static int mlx5_flow_create_tcp(const struct rte_flow_item *item, void *data); +static int +mlx5_flow_create_vxlan(const struct rte_flow_item *item, void *data); + struct rte_flow { LIST_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */ struct ibv_exp_flow_attr *ibv_attr; /**< Pointer to Verbs attributes. */ @@ -123,7 +126,8 @@ static const enum rte_flow_action_type valid_actions[] = { static const struct mlx5_flow_items mlx5_flow_items[] = { [RTE_FLOW_ITEM_TYPE_VOID] = { .items = ITEMS(RTE_FLOW_ITEM_TYPE_VOID, - RTE_FLOW_ITEM_TYPE_ETH), + RTE_FLOW_ITEM_TYPE_ETH, + RTE_FLOW_ITEM_TYPE_VXLAN), .actions = valid_actions, .mask = &(const struct rte_flow_item_eth){ .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff", @@ -196,6 +200,7 @@ static const struct mlx5_flow_items mlx5_flow_items[] = { .dst_sz = sizeof(struct ibv_exp_flow_spec_ipv6), }, [RTE_FLOW_ITEM_TYPE_UDP] = { + .items = ITEMS(RTE_FLOW_ITEM_TYPE_VXLAN), .actions = valid_actions, .mask = &(const struct rte_flow_item_udp){ .hdr = { @@ -219,12 +224,23 @@ static const struct mlx5_flow_items mlx5_flow_items[] = { .convert = mlx5_flow_create_tcp, .dst_sz = sizeof(struct ibv_exp_flow_spec_tcp_udp), }, + [RTE_FLOW_ITEM_TYPE_VXLAN] = { + .items = ITEMS(RTE_FLOW_ITEM_TYPE_ETH), + .actions = valid_actions, + .mask = &(const struct rte_flow_item_vxlan){ + .vni = "\xff\xff\xff", + }, + .mask_sz = sizeof(struct rte_flow_item_vxlan), + .convert = mlx5_flow_create_vxlan, + .dst_sz = sizeof(struct ibv_exp_flow_spec_tunnel), + }, }; /** Structure to pass to the conversion function. */ struct mlx5_flow { struct ibv_exp_flow_attr *ibv_attr; /**< Verbs attribute. */ unsigned int offset; /**< Offset in bytes in the ibv_attr buffer. */ + uint32_t inner; /**< Set once VXLAN is encountered. */ }; struct mlx5_flow_action { @@ -474,7 +490,7 @@ mlx5_flow_create_eth(const struct rte_flow_item *item, void *data) eth = (void *)((uintptr_t)flow->ibv_attr + flow->offset); *eth = (struct ibv_exp_flow_spec_eth) { - .type = IBV_EXP_FLOW_SPEC_ETH, + .type = flow->inner | IBV_EXP_FLOW_SPEC_ETH, .size = eth_size, }; if (spec) { @@ -541,7 +557,7 @@ mlx5_flow_create_ipv4(const struct rte_flow_item *item, void *data) ipv4 = (void *)((uintptr_t)flow->ibv_attr + flow->offset); *ipv4 = (struct ibv_exp_flow_spec_ipv4) { - .type = IBV_EXP_FLOW_SPEC_IPV4, + .type = flow->inner | IBV_EXP_FLOW_SPEC_IPV4, .size = ipv4_size, }; if (spec) { @@ -584,7 +600,7 @@ mlx5_flow_create_ipv6(const struct rte_flow_item *item, void *data) ipv6 = (void *)((uintptr_t)flow->ibv_attr + flow->offset); *ipv6 = (struct ibv_exp_flow_spec_ipv6) { - .type = IBV_EXP_FLOW_SPEC_IPV6, + .type = flow->inner | IBV_EXP_FLOW_SPEC_IPV6, .size = ipv6_size, }; if (spec) { @@ -628,7 +644,7 @@ mlx5_flow_create_udp(const struct rte_flow_item *item, void *data) udp = (void *)((uintptr_t)flow->ibv_attr + flow->offset); *udp = (struct ibv_exp_flow_spec_tcp_udp) { - .type = IBV_EXP_FLOW_SPEC_UDP, + .type = flow->inner | IBV_EXP_FLOW_SPEC_UDP, .size = udp_size, }; if (spec) { @@ -666,7 +682,7 @@ mlx5_flow_create_tcp(const struct rte_flow_item *item, void *data) tcp = (void *)((uintptr_t)flow->ibv_attr + flow->offset); *tcp = (struct ibv_exp_flow_spec_tcp_udp) { - .type = IBV_EXP_FLOW_SPEC_TCP, + .type = flow->inner | IBV_EXP_FLOW_SPEC_TCP, .size = tcp_size, }; if (spec) { @@ -686,6 +702,49 @@ mlx5_flow_create_tcp(const struct rte_flow_item *item, void *data) } /** + * Convert VXLAN item to Verbs specification. + * + * @param item[in] + * Item specification. + * @param data[in, out] + * User structure. + */ +static int +mlx5_flow_create_vxlan(const struct rte_flow_item *item, void *data) +{ + const struct rte_flow_item_vxlan *spec = item->spec; + const struct rte_flow_item_vxlan *mask = item->mask; + struct mlx5_flow *flow = (struct mlx5_flow *)data; + struct ibv_exp_flow_spec_tunnel *vxlan; + unsigned int size = sizeof(struct ibv_exp_flow_spec_tunnel); + union vni { + uint32_t vlan_id; + uint8_t vni[4]; + } id; + + id.vni[0] = 0; + vxlan = (void *)((uintptr_t)flow->ibv_attr + flow->offset); + *vxlan = (struct ibv_exp_flow_spec_tunnel) { + .type = flow->inner | IBV_EXP_FLOW_SPEC_VXLAN_TUNNEL, + .size = size, + }; + if (spec) { + memcpy(&id.vni[1], spec->vni, 3); + vxlan->val.tunnel_id = id.vlan_id; + } + if (mask) { + memcpy(&id.vni[1], mask->vni, 3); + vxlan->mask.tunnel_id = id.vlan_id; + } + /* Remove unwanted bits from values. */ + vxlan->val.tunnel_id &= vxlan->mask.tunnel_id; + ++flow->ibv_attr->num_of_specs; + flow->ibv_attr->priority = 0; + flow->inner = IBV_EXP_FLOW_SPEC_INNER; + return 0; +} + +/** * Complete flow rule creation. * * @param priv @@ -852,6 +911,7 @@ priv_flow_create(struct priv *priv, .flags = 0, .reserved = 0, }; + flow.inner = 0; claim_zero(priv_flow_validate(priv, attr, items, actions, error, &flow)); action = (struct mlx5_flow_action){