From patchwork Mon Sep 24 23:17:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongseok Koh X-Patchwork-Id: 45250 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 006DF1B111; Tue, 25 Sep 2018 01:17:42 +0200 (CEST) Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10053.outbound.protection.outlook.com [40.107.1.53]) by dpdk.org (Postfix) with ESMTP id 164761B0FE for ; Tue, 25 Sep 2018 01:17:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ijOZWHuhX7AwNbe0V1k1D3Jl8qFmRQ1RqIO7zyrzYVg=; b=fbuxBm+WB7xI1EswHgwOM5EAayDf4QO/KkRFUcZFsjL1y/rnfzVLEcApnXeOJdh21DpTbWtVBTwhFHJA9MXPunxwMCfdNAsNTYIlQ3ghMewRALT8Hh20n8Bfhz3dFtDCSE6jTBauI7Eelx8M3GbDAZ8Hhj4ndMti1JcMu5aI3nw= Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com (52.134.72.27) by DB3PR0502MB3996.eurprd05.prod.outlook.com (52.134.65.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.25; Mon, 24 Sep 2018 23:17:37 +0000 Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::1cb0:661b:ecab:6045]) by DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::1cb0:661b:ecab:6045%2]) with mapi id 15.20.1164.017; Mon, 24 Sep 2018 23:17:37 +0000 From: Yongseok Koh To: Thomas Monjalon , Shahaf Shuler CC: "dev@dpdk.org" , Ori Kam Thread-Topic: [PATCH v3 02/11] net/mlx5: add flow prepare function Thread-Index: AQHUVFzI+b8IuG10tkagPGrub+nj6A== Date: Mon, 24 Sep 2018 23:17:37 +0000 Message-ID: <20180924231721.15799-3-yskoh@mellanox.com> References: <20180919072143.23211-1-yskoh@mellanox.com> <20180924231721.15799-1-yskoh@mellanox.com> In-Reply-To: <20180924231721.15799-1-yskoh@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR03CA0021.namprd03.prod.outlook.com (2603:10b6:404:23::31) To DB3PR0502MB3980.eurprd05.prod.outlook.com (2603:10a6:8:10::27) authentication-results: spf=none (sender IP is ) smtp.mailfrom=yskoh@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [209.116.155.178] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB3PR0502MB3996; 6:D3Dhxz9WGrJLuM9Rl/Ls1NCJGVK663colE5dP90VKa/ecTwd4c768WoR9jr/oKKtC3Cqlq8wiTUK21kCQQZqqbB8jSl/Rtik3nmLM80bkp6fvLjC2U9PmJRUFsMPA6eCfrf4/2u0OHw2d7Z8cHgzEDZutTYgCkJTCJsUnd4oM8lnH51nfQLK1RS6XRGW0aVHDG0IXHKaII9FxWU4zbHK2Cb7VQzaRq9iztOryNn1kAiVKyskiHR637db3QiUUf6qW5zL5/aIDRTV0gQ8PghE/znCjgxAsZOddR2U6n+Yb9Z9Fknbi/sKLhOknm82UdNXZLvswRLZh2bzVP7Y19XkM55jrT1UffTgga/LPGm5WQ2ybZOXEUkfVS4G/02q8icL6LvQuoaRGtmh5GUpVep9ShM9Irdaq6WSoe4hoR65wEFbyiqam+fLGuDZwCZZvU5v5fh1vB3RuW1cHVRPGp9ydw==; 5:A4k/95vrvHecfL5qfoniOn+pcLUr2BTBqf/AYA6OEC/DrOh4y4l+du/xDs+CK/z17a3hamGPGepgKuggndVxVY4dgfeLsumIiERUon6ghoJxZ5Tin5VJ/MGhK2Ki6MSSiR3HNj4ua8eC1ZJv7KfigzoJl1wUMNJ/6phj/f8djaA=; 7:T3i+ETHm0NiLqkpGyZrI7/RiD6w2VT2jgcuSdh4i9VTQfS8O16CnMNwKsjYbJ7D3N9SUSGVKKtra69FJJJqSCQutxQypFqTap8XGLGdGXwvyMTDXh8ZxPmhDVbk+aQFVIea3ZjvxXLLXRHm3NlnjJptaCzalz/s1fCCTLDnDK/+PL+la5+dDo5chagb2RMkuWvAah6JrRT/f5FVT1oAaJBEI/SWlhs2gY38sr3ydBjVBUu032m47BqO77G6fKOAQ x-ms-office365-filtering-correlation-id: e124f667-b841-40b1-a54c-08d62273ea81 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DB3PR0502MB3996; x-ms-traffictypediagnostic: DB3PR0502MB3996: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231355)(944501410)(52105095)(6055026)(149066)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(201708071742011)(7699051); SRVR:DB3PR0502MB3996; BCL:0; PCL:0; RULEID:; SRVR:DB3PR0502MB3996; x-forefront-prvs: 0805EC9467 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(376002)(346002)(366004)(39860400002)(136003)(199004)(189003)(51234002)(66066001)(2616005)(476003)(446003)(486006)(11346002)(6436002)(305945005)(7736002)(575784001)(386003)(6506007)(6486002)(6512007)(186003)(102836004)(5250100002)(76176011)(25786009)(26005)(68736007)(6116002)(54906003)(110136005)(99286004)(1076002)(3846002)(71200400001)(52116002)(86362001)(53936002)(71190400001)(97736004)(8936002)(107886003)(14444005)(256004)(4326008)(316002)(2900100001)(81156014)(8676002)(36756003)(81166006)(105586002)(2906002)(106356001)(6636002)(478600001)(5660300001)(14454004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB3996; H:DB3PR0502MB3980.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: wu6W2pJT+zjEcfHbj2q+FNoaj0MLx/34k0VNOv+GO2ghj6jyrsSo3Pts/s7ihJ1H+YfXj3rAmK4K9l/PhSUiPD9LeRsA67CRkSLm/LZHXk0uHBPA/pxuuQoyLHPNiIL2MsO7ksy+4RfRwQTAvHktVzWql7Q5REZm9w2fxod8SsuBBOr0a3deHRsmWeMBOowYkZd+YakCDuzXpeQfOABv2YPysKx7XqLBiGfYE05L2AMeAFLVV5hq93Ak5iw/eskadxxMU0JFz3LWovl0pK1Zc8vozQ05esHblRNIXuWmQ0wjtCC53v0bd1hcT0+qJugcc4+BKg2yOVN0vLu6Dugunf9BSF4toYmzcj2lG8RstKY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: e124f667-b841-40b1-a54c-08d62273ea81 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Sep 2018 23:17:37.5764 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB3996 Subject: [dpdk-dev] [PATCH v3 02/11] net/mlx5: add flow prepare function 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" From: Ori Kam In current implementation the calculation of the flow size is done during the validation stage, and the same function is also used to translate the input parameters into verbs spec. This is hard to maintain and error prone. Another issue is that dev-flows (flows that are created implicitly in order to support the requested flow for example when the user request RSS on UDP 2 rules need to be created one for IPv4 and one for IPv6). In current implementation the dev-flows are created on the same memory allocation. This will be harder to implement in future drivers. The commits extract the calculation and creation of the dev-flow from the translation part (the part that converts the parameters into the format required by the driver). This results in that the prepare function only function is to allocate the dev-flow. Signed-off-by: Ori Kam Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_flow.c | 269 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 263 insertions(+), 6 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 799064c0c..166fee555 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -292,6 +292,15 @@ struct mlx5_flow_verbs { uint64_t hash_fields; /**< Verbs hash Rx queue hash fields. */ }; +/** Device flow structure. */ +struct mlx5_flow { + LIST_ENTRY(mlx5_flow) next; + struct rte_flow *flow; /**< Pointer to the main flow. */ + union { + struct mlx5_flow_verbs verbs; /**< Holds the verbs dev-flow. */ + }; +}; + /* Counters information. */ struct mlx5_flow_counter { LIST_ENTRY(mlx5_flow_counter) next; /**< Pointer to the next counter. */ @@ -321,6 +330,8 @@ struct rte_flow { uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */ uint16_t (*queue)[]; /**< Destination queues to redirect traffic to. */ void *nl_flow; /**< Netlink flow buffer if relevant. */ + LIST_HEAD(dev_flows, mlx5_flow) dev_flows; + /**< Device flows that are part of the flow. */ }; static const struct rte_flow_ops mlx5_flow_ops = { @@ -2322,7 +2333,7 @@ mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev) * Pointer to error structure. * * @return - * 0 on success, a negative errno value otherwise and rte_ernno is set. + * 0 on success, a negative errno value otherwise and rte_errno is set. */ static int mlx5_flow_validate_action_flag(uint64_t action_flags, @@ -2425,7 +2436,6 @@ mlx5_flow_validate_action_drop(uint64_t action_flags, } /* - * * Validate the queue action. * * @param[in] action @@ -2469,7 +2479,6 @@ mlx5_flow_validate_action_queue(const struct rte_flow_action *action, } /* - * * Validate the rss action. * * @param[in] action @@ -3211,7 +3220,7 @@ mlx5_flow_validate_item_mpls(const struct rte_flow_item *item __rte_unused, if (ret < 0) return ret; return 0; -#endif /* !HAVE_IBV_DEVICE_MPLS_SUPPORT */ +#endif return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item, "MPLS is not supported by Verbs, please" @@ -3219,7 +3228,6 @@ mlx5_flow_validate_item_mpls(const struct rte_flow_item *item __rte_unused, } /** - * * Internal validation function. * * @param[in] dev @@ -3444,6 +3452,222 @@ mlx5_flow_validate(struct rte_eth_dev *dev, } /** + * Calculate the required bytes that are needed for the action part of the verbs + * flow, in addtion returns bit-fields with all the detected action, in order to + * avoid another interation over the actions. + * + * @param[in] actions + * Pointer to the list of actions. + * @param[out] action_flags + * Pointer to the detected actions. + * + * @return + * The size of the memory needed for all actions. + */ +static int +mlx5_flow_verbs_get_actions_and_size(const struct rte_flow_action actions[], + uint64_t *action_flags) +{ + int size = 0; + uint64_t detected_actions = 0; + + for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { + switch (actions->type) { + case RTE_FLOW_ACTION_TYPE_VOID: + break; + case RTE_FLOW_ACTION_TYPE_FLAG: + size += sizeof(struct ibv_flow_spec_action_tag); + detected_actions |= MLX5_ACTION_FLAG; + break; + case RTE_FLOW_ACTION_TYPE_MARK: + size += sizeof(struct ibv_flow_spec_action_tag); + detected_actions |= MLX5_ACTION_MARK; + break; + case RTE_FLOW_ACTION_TYPE_DROP: + size += sizeof(struct ibv_flow_spec_action_drop); + detected_actions |= MLX5_ACTION_DROP; + break; + case RTE_FLOW_ACTION_TYPE_QUEUE: + detected_actions |= MLX5_ACTION_QUEUE; + break; + case RTE_FLOW_ACTION_TYPE_RSS: + detected_actions |= MLX5_ACTION_RSS; + break; + case RTE_FLOW_ACTION_TYPE_COUNT: +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT + size += sizeof(struct ibv_flow_spec_counter_action); +#endif + detected_actions |= MLX5_ACTION_COUNT; + break; + default: + break; + } + } + *action_flags = detected_actions; + return size; +} + +/** + * Calculate the required bytes that are needed for the item part of the verbs + * flow, in addtion returns bit-fields with all the detected action, in order to + * avoid another interation over the actions. + * + * @param[in] actions + * Pointer to the list of items. + * @param[in, out] item_flags + * Pointer to the detected items. + * + * @return + * The size of the memory needed for all items. + */ +static int +mlx5_flow_verbs_get_items_and_size(const struct rte_flow_item items[], + uint64_t *item_flags) +{ + int size = 0; + uint64_t detected_items = 0; + const int tunnel = !!(*item_flags & MLX5_FLOW_LAYER_TUNNEL); + + for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) { + switch (items->type) { + case RTE_FLOW_ITEM_TYPE_VOID: + break; + case RTE_FLOW_ITEM_TYPE_ETH: + size += sizeof(struct ibv_flow_spec_eth); + detected_items |= tunnel ? MLX5_FLOW_LAYER_INNER_L2 : + MLX5_FLOW_LAYER_OUTER_L2; + break; + case RTE_FLOW_ITEM_TYPE_VLAN: + size += sizeof(struct ibv_flow_spec_eth); + detected_items |= tunnel ? MLX5_FLOW_LAYER_INNER_VLAN : + MLX5_FLOW_LAYER_OUTER_VLAN; + break; + case RTE_FLOW_ITEM_TYPE_IPV4: + size += sizeof(struct ibv_flow_spec_ipv4_ext); + detected_items |= tunnel ? + MLX5_FLOW_LAYER_INNER_L3_IPV4 : + MLX5_FLOW_LAYER_OUTER_L3_IPV4; + break; + case RTE_FLOW_ITEM_TYPE_IPV6: + size += sizeof(struct ibv_flow_spec_ipv6); + detected_items |= tunnel ? + MLX5_FLOW_LAYER_INNER_L3_IPV6 : + MLX5_FLOW_LAYER_OUTER_L3_IPV6; + break; + case RTE_FLOW_ITEM_TYPE_UDP: + size += sizeof(struct ibv_flow_spec_tcp_udp); + detected_items |= tunnel ? + MLX5_FLOW_LAYER_INNER_L4_UDP : + MLX5_FLOW_LAYER_OUTER_L4_UDP; + break; + case RTE_FLOW_ITEM_TYPE_TCP: + size += sizeof(struct ibv_flow_spec_tcp_udp); + detected_items |= tunnel ? + MLX5_FLOW_LAYER_INNER_L4_TCP : + MLX5_FLOW_LAYER_OUTER_L4_TCP; + break; + case RTE_FLOW_ITEM_TYPE_VXLAN: + size += sizeof(struct ibv_flow_spec_tunnel); + detected_items |= MLX5_FLOW_LAYER_VXLAN; + break; + case RTE_FLOW_ITEM_TYPE_VXLAN_GPE: + size += sizeof(struct ibv_flow_spec_tunnel); + detected_items |= MLX5_FLOW_LAYER_VXLAN_GPE; + break; + case RTE_FLOW_ITEM_TYPE_GRE: +#ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT + size += sizeof(struct ibv_flow_spec_gre); + detected_items |= MLX5_FLOW_LAYER_GRE; +#else + size += sizeof(struct ibv_flow_spec_tunnel); + detected_items |= MLX5_FLOW_LAYER_TUNNEL; +#endif + break; + case RTE_FLOW_ITEM_TYPE_MPLS: +#ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT + size += sizeof(struct ibv_flow_spec_mpls); + detected_items |= MLX5_FLOW_LAYER_MPLS; +#endif + break; + default: + break; + } + } + *item_flags = detected_items; + return size; +} + +/** + * Get RSS action from the action list. + * + * @param[in] actions + * Pointer to the list of actions. + * + * @return + * Pointer to the RSS action if exist, else return NULL. + */ +static const struct rte_flow_action_rss* +mlx5_flow_get_rss_action(const struct rte_flow_action actions[]) +{ + for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { + switch (actions->type) { + case RTE_FLOW_ACTION_TYPE_RSS: + return (const struct rte_flow_action_rss *) + actions->conf; + default: + break; + } + } + return NULL; +} + +/** + * Internal preparation function. Allocate mlx5_flow with the required size. + * The required size is calculate based on the actions and items. This function + * also returns the detected actions and items for later use. + * + * @param[in] attr + * Pointer to the flow attributes. + * @param[in] items + * Pointer to the list of items. + * @param[in] actions + * Pointer to the list of actions. + * @param[out] item_flags + * Pointer to bit mask of all items detected. + * @param[out] action_flags + * Pointer to bit mask of all actions detected. + * @param[out] error + * Pointer to the error structure. + * + * @return + * Pointer to mlx5_flow object on success, otherwise NULL and rte_errno + * is set. + */ +static struct mlx5_flow * +mlx5_flow_verbs_prepare(const struct rte_flow_attr *attr __rte_unused, + const struct rte_flow_item items[], + const struct rte_flow_action actions[], + uint64_t *item_flags, + uint64_t *action_flags, + struct rte_flow_error *error) +{ + uint32_t size = sizeof(struct ibv_flow_attr); + struct mlx5_flow *flow; + + size += mlx5_flow_verbs_get_actions_and_size(actions, action_flags); + size += mlx5_flow_verbs_get_items_and_size(items, item_flags); + flow = rte_calloc(__func__, 1, size, 0); + if (!flow) { + rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "not enough memory to create flow"); + return NULL; + } + return flow; +} + +/** * Remove the flow. * * @param[in] dev @@ -3594,12 +3818,46 @@ mlx5_flow_list_create(struct rte_eth_dev *dev, struct rte_flow_error *error) { struct rte_flow *flow = NULL; + struct mlx5_flow *dev_flow; size_t size = 0; + uint64_t action_flags = 0; + uint64_t item_flags = 0; + const struct rte_flow_action_rss *rss; + union { + struct rte_flow_expand_rss buf; + uint8_t buffer[2048]; + } expand_buffer; + struct rte_flow_expand_rss *buf = &expand_buffer.buf; int ret; + uint32_t i; ret = mlx5_flow_validate(dev, attr, items, actions, error); if (ret < 0) return NULL; + flow = rte_calloc(__func__, 1, sizeof(*flow), 0); + LIST_INIT(&flow->dev_flows); + rss = mlx5_flow_get_rss_action(actions); + if (rss && rss->types) { + unsigned int graph_root; + + graph_root = mlx5_find_graph_root(items, rss->level); + ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer), + items, rss->types, + mlx5_support_expansion, + graph_root); + assert(ret > 0 && + (unsigned int)ret < sizeof(expand_buffer.buffer)); + } else { + buf->entries = 1; + buf->entry[0].pattern = (void *)(uintptr_t)items; + } + for (i = 0; i < buf->entries; ++i) { + dev_flow = mlx5_flow_verbs_prepare(attr, buf->entry[i].pattern, + actions, &item_flags, + &action_flags, error); + dev_flow->flow = flow; + LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next); + } ret = mlx5_flow_merge(dev, flow, size, attr, items, actions, error); if (ret < 0) return NULL; @@ -4091,7 +4349,6 @@ mlx5_fdir_filter_convert(struct rte_eth_dev *dev, .dst_addr = input->flow.ip4_flow.dst_ip, .time_to_live = input->flow.ip4_flow.ttl, .type_of_service = input->flow.ip4_flow.tos, - .next_proto_id = input->flow.ip4_flow.proto, }; attributes->l3_mask.ipv4.hdr = (struct ipv4_hdr){ .src_addr = mask->ipv4_mask.src_ip,