From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by dpdk.org (Postfix) with ESMTP id 2C00337A8 for ; Thu, 29 Dec 2016 16:15:42 +0100 (CET) Received: by mail-wm0-f53.google.com with SMTP id c85so119107569wmi.1 for ; Thu, 29 Dec 2016 07:15:42 -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=GciLqLfC8JXz+0dF6ujzfNqOlLJdrbUws+5G4rFUN+8=; b=FG7WaSZmFD+TTfnBhITcf2idIMYWy1IqPfmmSHyKpI7vrwaDNSNadlYBfbeVMLUoc6 hL97082NXNbL93TXkup9wCs4cZCR/ciSztXMuOyqaQA4h7vMshKwckgNakuzWOba525+ IENNciLMqdbqq/rSy84UB0kJV5htVU3M2ZgHcTuYCPeCUDDU6l64tDW2PMFD1b4bHCpO MIQE4vzha9PTnRDfa66H7Dw32bt780k7SN2EfdTQRmJRqV1DVruj8rCNjtbjA8t9q5+H GqRFcGVPosuzqvvTdh9e1POZgN9+Oq4Fbq2KEynvyrzHs+i5SaWGotwNXn1mfo5hOD0U c+kA== 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=GciLqLfC8JXz+0dF6ujzfNqOlLJdrbUws+5G4rFUN+8=; b=LES/QWmE6Jlf1bjx7/ZACzX5whmvZ5n8d54uX0EFUGDPEk749rklPFQOMRPRP7EuDP KWAn1QO5spkmjAHg8MzV7ELsKs/pHl7VW10+HWRQ0liMC91+w+4JUhaKm+vfOqsqA9iW LY4wLSWzdz/W0YRIfm6vOKsgAbovPjQQb7FALnzxL5SARoGveldgWCOULNXUJZcRCtpO 3r0aoqXFUpUcHi6DyN21h67tSdKNWSzSlIXv5RTy/oZQavWSadPyDBmt7zSGL7vd7mTH Zp/1XJzaKsedKIF+R0nFb4kModEJTgEiIBkdLYAm6IH1ecuR7CiPDQwIXrL5HvalKytq po4Q== X-Gm-Message-State: AIkVDXJFiOy/GUAV22hPjANhmjdFLTnfljdNbgPhXPfxT+7DWrHdAcxwEQVZleG7NbUMvlAS X-Received: by 10.28.213.74 with SMTP id m71mr38555218wmg.39.1483024542381; Thu, 29 Dec 2016 07:15:42 -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 o3sm69289997wjx.39.2016.12.29.07.15.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Dec 2016 07:15:41 -0800 (PST) From: Nelio Laranjeiro To: dev@dpdk.org, Ferruh Yigit Cc: Adrien Mazarguil Date: Thu, 29 Dec 2016 16:15:20 +0100 Message-Id: <83f25a66ca041a71369f85eec8367289a351bd20.1483022600.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 v5 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: , X-List-Received-Date: Thu, 29 Dec 2016 15:15:43 -0000 Signed-off-by: Nelio Laranjeiro Acked-by: Adrien Mazarguil --- drivers/net/mlx5/mlx5_flow.c | 78 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 8f2f4d5..093c140 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -81,6 +81,11 @@ mlx5_flow_create_tcp(const struct rte_flow_item *item, const void *default_mask, void *data); +static int +mlx5_flow_create_vxlan(const struct rte_flow_item *item, + const void *default_mask, + 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. */ @@ -138,7 +143,8 @@ static const enum rte_flow_action_type valid_actions[] = { /** Graph of supported items and associated actions. */ static const struct mlx5_flow_items mlx5_flow_items[] = { [RTE_FLOW_ITEM_TYPE_END] = { - .items = ITEMS(RTE_FLOW_ITEM_TYPE_ETH), + .items = ITEMS(RTE_FLOW_ITEM_TYPE_ETH, + RTE_FLOW_ITEM_TYPE_VXLAN), }, [RTE_FLOW_ITEM_TYPE_ETH] = { .items = ITEMS(RTE_FLOW_ITEM_TYPE_VLAN, @@ -203,6 +209,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 = { @@ -226,12 +233,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 { @@ -489,7 +507,7 @@ mlx5_flow_create_eth(const struct rte_flow_item *item, flow->ibv_attr->priority = 2; 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) @@ -565,7 +583,7 @@ mlx5_flow_create_ipv4(const struct rte_flow_item *item, flow->ibv_attr->priority = 1; 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) @@ -612,7 +630,7 @@ mlx5_flow_create_ipv6(const struct rte_flow_item *item, flow->ibv_attr->priority = 1; 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) @@ -660,7 +678,7 @@ mlx5_flow_create_udp(const struct rte_flow_item *item, flow->ibv_attr->priority = 0; 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) @@ -702,7 +720,7 @@ mlx5_flow_create_tcp(const struct rte_flow_item *item, flow->ibv_attr->priority = 0; 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) @@ -720,6 +738,53 @@ mlx5_flow_create_tcp(const struct rte_flow_item *item, } /** + * Convert VXLAN item to Verbs specification. + * + * @param item[in] + * Item specification. + * @param default_mask[in] + * Default bit-masks to use when item->mask is not provided. + * @param data[in, out] + * User structure. + */ +static int +mlx5_flow_create_vxlan(const struct rte_flow_item *item, + const void *default_mask, + 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; + + ++flow->ibv_attr->num_of_specs; + flow->ibv_attr->priority = 0; + 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, + }; + flow->inner = IBV_EXP_FLOW_SPEC_INNER; + if (!spec) + return 0; + if (!mask) + mask = default_mask; + memcpy(&id.vni[1], spec->vni, 3); + vxlan->val.tunnel_id = id.vlan_id; + 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; + return 0; +} + +/** * Complete flow rule creation. * * @param priv @@ -886,6 +951,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){ -- 2.1.4