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 834201B3AE for ; Fri, 13 Jul 2018 11:41:04 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id v128-v6so8148798wme.5 for ; Fri, 13 Jul 2018 02:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pBVDRproGw6M+uVk39+6Ft0dsE1RvntXrkz4O2vobnI=; b=1FpAk2NERf/XerGqxYQsHaVBKoNA2iDscJ2vVRNZSU5GQydIMrGV2nZPV4UcT0Neqo 8ehk3lxm22RN5qY1P9XgjDTh+TUmbkA0rvyBQB3lPYf1Ix6hzhZT76HbNbdemgCBg0pn GJS0+ffnyJSebX/CeTM2GtxZOf9R3TO4salTGhtZ4EGaTjq8Zy+6YkoKurjlkbf6pWAd hvnANPYPnTgRIdOK6uq+ueZp4Uoxb6274sMNm6RVkiezLEpRw1q/p1fwXEkd53DA61l4 80XHXOeD96C/cgeBghf8OCnCKNX9Z+jYJdJkKG6wrNb1494haizibvRdRfVtQrgHcq1L nR0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pBVDRproGw6M+uVk39+6Ft0dsE1RvntXrkz4O2vobnI=; b=QOK64oRsL3jhLg+n0p5pYCwVbVgIBsfnPtJlrDlfl0ZcPyC1Qe9Yl1YhknXHpo8u6t y6cpV+F+Pj6XTkF99up/MsJp5RuqVJOt6S5zFpT4MTbKzlgiRDOu4EUUgfUDycNz4znr DmEXpXxGME8FKD13FQ/eBakw79SPKAlvBcUGwjoc2O/h6XC0jn64SkNUuOulV2wlFYK3 7UolRk2Gjywng0cXvJhg114PzDcWdNuPHstEGmsEYzB3ByHqGZCOzBuHmTaEz9S1PLov 4nHWjvZs5H7XV1hj1OdhZik8D4r6qJRICHzNX+uoIK2YJSMO0PUGtWrs+scnaSrNosvS XvtQ== X-Gm-Message-State: AOUpUlH4LdYqT/eR6lIscNQYfmwWEYzdRO5+k1NEVh8EWfLg5m70Kb7A aKUX1vueBWFLbGLGcglEXSVbew== X-Google-Smtp-Source: AAOMgpezOQe8nrADVi1PBoDyXgv6/mxEgjCzBclNMnxZfgm1EenEupKfkND1eVMPcLvkC/ZYdbGOXw== X-Received: by 2002:a1c:14c3:: with SMTP id 186-v6mr3234110wmu.21.1531474864228; Fri, 13 Jul 2018 02:41:04 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id c18-v6sm29920747wrq.17.2018.07.13.02.41.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 02:41:03 -0700 (PDT) Date: Fri, 13 Jul 2018 11:40:47 +0200 From: Adrien Mazarguil To: Shahaf Shuler Cc: Nelio Laranjeiro , Yongseok Koh , dev@dpdk.org Message-ID: <20180713092910.26276-7-adrien.mazarguil@6wind.com> References: <20180627173355.4718-1-adrien.mazarguil@6wind.com> <20180713092910.26276-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180713092910.26276-1-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH v2 6/6] net/mlx5: add port ID pattern item to switch flow rules 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: Fri, 13 Jul 2018 09:41:04 -0000 This enables flow rules to match traffic coming from a different DPDK port ID associated with the device (PORT_ID pattern item), mainly for the convenience of applications that want to deal with a single port ID for all flow rules associated with some physical device. Testpmd example: - Creating a flow rule on port ID 1 to consume all traffic from port ID 0 and direct it to port ID 2: flow create 1 ingress transfer pattern port_id id is 0 / end actions port_id id 2 / end Signed-off-by: Adrien Mazarguil Acked-by: Nelio Laranjeiro Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_nl_flow.c | 57 +++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/mlx5_nl_flow.c b/drivers/net/mlx5/mlx5_nl_flow.c index 6c7bf7119..9bad1a418 100644 --- a/drivers/net/mlx5/mlx5_nl_flow.c +++ b/drivers/net/mlx5/mlx5_nl_flow.c @@ -154,6 +154,7 @@ enum mlx5_nl_flow_trans { ATTR, PATTERN, ITEM_VOID, + ITEM_PORT_ID, ITEM_ETH, ITEM_VLAN, ITEM_IPV4, @@ -174,7 +175,7 @@ enum mlx5_nl_flow_trans { #define TRANS(...) (const enum mlx5_nl_flow_trans []){ __VA_ARGS__, INVALID, } #define PATTERN_COMMON \ - ITEM_VOID, ACTIONS + ITEM_VOID, ITEM_PORT_ID, ACTIONS #define ACTIONS_COMMON \ ACTION_VOID, ACTION_OF_POP_VLAN, ACTION_OF_PUSH_VLAN, \ ACTION_OF_SET_VLAN_VID, ACTION_OF_SET_VLAN_PCP @@ -188,6 +189,7 @@ static const enum mlx5_nl_flow_trans *const mlx5_nl_flow_trans[] = { [ATTR] = TRANS(PATTERN), [PATTERN] = TRANS(ITEM_ETH, PATTERN_COMMON), [ITEM_VOID] = TRANS(BACK), + [ITEM_PORT_ID] = TRANS(BACK), [ITEM_ETH] = TRANS(ITEM_IPV4, ITEM_IPV6, ITEM_VLAN, PATTERN_COMMON), [ITEM_VLAN] = TRANS(ITEM_IPV4, ITEM_IPV6, PATTERN_COMMON), [ITEM_IPV4] = TRANS(ITEM_TCP, ITEM_UDP, PATTERN_COMMON), @@ -207,6 +209,7 @@ static const enum mlx5_nl_flow_trans *const mlx5_nl_flow_trans[] = { /** Empty masks for known item types. */ static const union { + struct rte_flow_item_port_id port_id; struct rte_flow_item_eth eth; struct rte_flow_item_vlan vlan; struct rte_flow_item_ipv4 ipv4; @@ -217,6 +220,7 @@ static const union { /** Supported masks for known item types. */ static const struct { + struct rte_flow_item_port_id port_id; struct rte_flow_item_eth eth; struct rte_flow_item_vlan vlan; struct rte_flow_item_ipv4 ipv4; @@ -224,6 +228,9 @@ static const struct { struct rte_flow_item_tcp tcp; struct rte_flow_item_udp udp; } mlx5_nl_flow_mask_supported = { + .port_id = { + .id = 0xffffffff, + }, .eth = { .type = RTE_BE16(0xffff), .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff", @@ -378,6 +385,7 @@ mlx5_nl_flow_transpose(void *buf, const struct rte_flow_action *action; unsigned int n; uint32_t act_index_cur; + bool in_port_id_set; bool eth_type_set; bool vlan_present; bool vlan_eth_type_set; @@ -396,6 +404,7 @@ mlx5_nl_flow_transpose(void *buf, action = actions; n = 0; act_index_cur = 0; + in_port_id_set = false; eth_type_set = false; vlan_present = false; vlan_eth_type_set = false; @@ -409,6 +418,7 @@ mlx5_nl_flow_transpose(void *buf, trans: switch (trans[n++]) { union { + const struct rte_flow_item_port_id *port_id; const struct rte_flow_item_eth *eth; const struct rte_flow_item_vlan *vlan; const struct rte_flow_item_ipv4 *ipv4; @@ -510,6 +520,51 @@ mlx5_nl_flow_transpose(void *buf, goto trans; ++item; break; + case ITEM_PORT_ID: + if (item->type != RTE_FLOW_ITEM_TYPE_PORT_ID) + goto trans; + mask.port_id = mlx5_nl_flow_item_mask + (item, &rte_flow_item_port_id_mask, + &mlx5_nl_flow_mask_supported.port_id, + &mlx5_nl_flow_mask_empty.port_id, + sizeof(mlx5_nl_flow_mask_supported.port_id), error); + if (!mask.port_id) + return -rte_errno; + if (mask.port_id == &mlx5_nl_flow_mask_empty.port_id) { + in_port_id_set = 1; + ++item; + break; + } + spec.port_id = item->spec; + if (mask.port_id->id && mask.port_id->id != 0xffffffff) + return rte_flow_error_set + (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM_MASK, + mask.port_id, + "no support for partial mask on" + " \"id\" field"); + if (!mask.port_id->id) + i = 0; + else + for (i = 0; ptoi[i].ifindex; ++i) + if (ptoi[i].port_id == spec.port_id->id) + break; + if (!ptoi[i].ifindex) + return rte_flow_error_set + (error, ENODEV, RTE_FLOW_ERROR_TYPE_ITEM_SPEC, + spec.port_id, + "missing data to convert port ID to ifindex"); + tcm = mnl_nlmsg_get_payload(buf); + if (in_port_id_set && + ptoi[i].ifindex != (unsigned int)tcm->tcm_ifindex) + return rte_flow_error_set + (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM_SPEC, + spec.port_id, + "cannot match traffic for several port IDs" + " through a single flow rule"); + tcm->tcm_ifindex = ptoi[i].ifindex; + in_port_id_set = 1; + ++item; + break; case ITEM_ETH: if (item->type != RTE_FLOW_ITEM_TYPE_ETH) goto trans; -- 2.11.0