From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 500E5A0096 for ; Mon, 3 Jun 2019 23:32:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 165E51B9A2; Mon, 3 Jun 2019 23:32:46 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 0EBF01B99F for ; Mon, 3 Jun 2019 23:32:44 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from yskoh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Jun 2019 00:32:44 +0300 Received: from scfae-sc-2.mti.labs.mlnx (scfae-sc-2.mti.labs.mlnx [10.101.0.96]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x53LWeDD020818; Tue, 4 Jun 2019 00:32:41 +0300 From: Yongseok Koh To: shahafs@mellanox.com, thomas@monjalon.net, ferruh.yigit@intel.com, arybchenko@solarflare.com, adrien.mazarguil@6wind.com, olivier.matz@6wind.com Cc: dev@dpdk.org Date: Mon, 3 Jun 2019 14:32:29 -0700 Message-Id: <20190603213231.27020-1-yskoh@mellanox.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [RFC 1/3] ethdev: extend flow metadata 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" Currently, metadata can be set on egress path via mbuf tx_meatadata field with PKT_TX_METADATA flag and RTE_FLOW_ITEM_TYPE_RX_META matches metadata. This patch extends the usability. 1) RTE_FLOW_ACTION_TYPE_SET_META When supporting multiple tables, Tx metadata can also be set by a rule and matched by another rule. This new action allows metadata to be set as a result of flow match. 2) Metadata on ingress There's also need to support metadata on packet Rx. Metadata can be set by SET_META action and matched by META item like Tx. The final value set by the action will be delivered to application via mbuf metadata field with PKT_RX_METADATA ol_flag. For this purpose, mbuf->tx_metadata is moved as a separate new field and renamed to 'metadata' to support both Rx and Tx metadata. For loopback/hairpin packet, metadata set on Rx/Tx may or may not be propagated to the other path depending on HW capability. Signed-off-by: Yongseok Koh --- app/test-pmd/util.c | 2 +- doc/guides/prog_guide/rte_flow.rst | 73 +++++++++++++++++++-------- drivers/net/mlx5/mlx5_rxtx.c | 12 ++--- drivers/net/mlx5/mlx5_rxtx_vec.c | 4 +- drivers/net/mlx5/mlx5_rxtx_vec_neon.h | 2 +- drivers/net/mlx5/mlx5_rxtx_vec_sse.h | 2 +- lib/librte_ethdev/rte_flow.h | 43 ++++++++++++++-- lib/librte_mbuf/rte_mbuf.h | 21 ++++---- 8 files changed, 111 insertions(+), 48 deletions(-) diff --git a/app/test-pmd/util.c b/app/test-pmd/util.c index a1164b7053..6ecc97351f 100644 --- a/app/test-pmd/util.c +++ b/app/test-pmd/util.c @@ -182,7 +182,7 @@ tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue, * and set ol_flags accordingly. */ for (i = 0; i < nb_pkts; i++) { - pkts[i]->tx_metadata = ports[port_id].tx_metadata; + pkts[i]->metadata = ports[port_id].tx_metadata; pkts[i]->ol_flags |= PKT_TX_METADATA; } return nb_pkts; diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index a34d012e55..016cd90e52 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -658,6 +658,32 @@ the physical device, with virtual groups in the PMD or not at all. | ``mask`` | ``id`` | zeroed to match any value | +----------+----------+---------------------------+ +Item: ``META`` +^^^^^^^^^^^^^^^^^ + +Matches 32 bit metadata item set. + +On egress, metadata can be set either by mbuf metadata field with +PKT_TX_METADATA flag or ``SET_META`` action. On ingress, ``SET_META`` action +sets metadata for a packet and the metadata will be reported via mbuf metadata +field with PKT_RX_METADATA flag. + +- Default ``mask`` matches the specified Rx metadata value. + +.. _table_rte_flow_item_meta: + +.. table:: META + + +----------+----------+---------------------------------------+ + | Field | Subfield | Value | + +==========+==========+=======================================+ + | ``spec`` | ``data`` | 32 bit metadata value | + +----------+----------+---------------------------------------+ + | ``last`` | ``data`` | upper range value | + +----------+----------+---------------------------------------+ + | ``mask`` | ``data`` | bit-mask applies to "spec" and "last" | + +----------+----------+---------------------------------------+ + Data matching item types ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1189,27 +1215,6 @@ Normally preceded by any of: - `Item: ICMP6_ND_NS`_ - `Item: ICMP6_ND_OPT`_ -Item: ``META`` -^^^^^^^^^^^^^^ - -Matches an application specific 32 bit metadata item. - -- Default ``mask`` matches the specified metadata value. - -.. _table_rte_flow_item_meta: - -.. table:: META - - +----------+----------+---------------------------------------+ - | Field | Subfield | Value | - +==========+==========+=======================================+ - | ``spec`` | ``data`` | 32 bit metadata value | - +----------+--------------------------------------------------+ - | ``last`` | ``data`` | upper range value | - +----------+----------+---------------------------------------+ - | ``mask`` | ``data`` | bit-mask applies to "spec" and "last" | - +----------+----------+---------------------------------------+ - Actions ~~~~~~~ @@ -2345,6 +2350,32 @@ Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned. | ``mac_addr`` | MAC address | +--------------+---------------+ +Action: ``SET_META`` +^^^^^^^^^^^^^^^^^^^^^^^ + +Set metadata. Item ``META`` matches metadata. + +Metadata set by mbuf metadata field with PKT_TX_METADATA flag on egress will be +overridden by this action. On ingress, the metadata will be carried by mbuf +metadata field with PKT_RX_METADATA flag if set. + +Altering partial bits is supported with ``mask``. For bits which have never been +set, unpredictable value will be seen depending on driver implementation. For +loopback/hairpin packet, metadata set on Rx/Tx may or may not be propagated to +the other path depending on HW capability. + +.. _table_rte_flow_action_set_meta: + +.. table:: SET_META + + +----------+----------------------------+ + | Field | Value | + +==========+============================+ + | ``data`` | 32 bit metadata value | + +----------+----------------------------+ + | ``mask`` | bit-mask applies to "data" | + +----------+----------------------------+ + Negative types ~~~~~~~~~~~~~~ diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c index 7174ffc91c..19b4a2567b 100644 --- a/drivers/net/mlx5/mlx5_rxtx.c +++ b/drivers/net/mlx5/mlx5_rxtx.c @@ -626,8 +626,7 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) txq_mbuf_to_swp(txq, buf, (uint8_t *)&swp_offsets, &swp_types); raw = ((uint8_t *)(uintptr_t)wqe) + 2 * MLX5_WQE_DWORD_SIZE; /* Copy metadata from mbuf if valid */ - metadata = buf->ol_flags & PKT_TX_METADATA ? buf->tx_metadata : - 0; + metadata = buf->ol_flags & PKT_TX_METADATA ? buf->metadata : 0; /* Replace the Ethernet type by the VLAN if necessary. */ if (buf->ol_flags & PKT_TX_VLAN_PKT) { uint32_t vlan = rte_cpu_to_be_32(0x81000000 | @@ -1029,8 +1028,7 @@ mlx5_tx_burst_mpw(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) --pkts_n; cs_flags = txq_ol_cksum_to_cs(buf); /* Copy metadata from mbuf if valid */ - metadata = buf->ol_flags & PKT_TX_METADATA ? buf->tx_metadata : - 0; + metadata = buf->ol_flags & PKT_TX_METADATA ? buf->metadata : 0; /* Retrieve packet information. */ length = PKT_LEN(buf); assert(length); @@ -1264,8 +1262,7 @@ mlx5_tx_burst_mpw_inline(void *dpdk_txq, struct rte_mbuf **pkts, max_wqe = (1u << txq->wqe_n) - (txq->wqe_ci - txq->wqe_pi); cs_flags = txq_ol_cksum_to_cs(buf); /* Copy metadata from mbuf if valid */ - metadata = buf->ol_flags & PKT_TX_METADATA ? buf->tx_metadata : - 0; + metadata = buf->ol_flags & PKT_TX_METADATA ? buf->metadata : 0; /* Retrieve packet information. */ length = PKT_LEN(buf); /* Start new session if packet differs. */ @@ -1547,8 +1544,7 @@ txq_burst_empw(struct mlx5_txq_data *txq, struct rte_mbuf **pkts, break; cs_flags = txq_ol_cksum_to_cs(buf); /* Copy metadata from mbuf if valid */ - metadata = buf->ol_flags & PKT_TX_METADATA ? buf->tx_metadata : - 0; + metadata = buf->ol_flags & PKT_TX_METADATA ? buf->metadata : 0; /* Retrieve packet information. */ length = PKT_LEN(buf); /* Start new session if: diff --git a/drivers/net/mlx5/mlx5_rxtx_vec.c b/drivers/net/mlx5/mlx5_rxtx_vec.c index 9a3a5ae437..9f99c8cb03 100644 --- a/drivers/net/mlx5/mlx5_rxtx_vec.c +++ b/drivers/net/mlx5/mlx5_rxtx_vec.c @@ -71,7 +71,7 @@ txq_calc_offload(struct rte_mbuf **pkts, uint16_t pkts_n, uint8_t *cs_flags, if (!pkts_n) return 0; p0_metadata = pkts[0]->ol_flags & PKT_TX_METADATA ? - pkts[0]->tx_metadata : 0; + pkts[0]->metadata : 0; /* Count the number of packets having same offload parameters. */ for (pos = 1; pos < pkts_n; ++pos) { /* Check if packet has same checksum flags. */ @@ -81,7 +81,7 @@ txq_calc_offload(struct rte_mbuf **pkts, uint16_t pkts_n, uint8_t *cs_flags, /* Check if packet has same metadata. */ if (txq_offloads & DEV_TX_OFFLOAD_MATCH_METADATA) { pn_metadata = pkts[pos]->ol_flags & PKT_TX_METADATA ? - pkts[pos]->tx_metadata : 0; + pkts[pos]->metadata : 0; if (pn_metadata != p0_metadata) break; } diff --git a/drivers/net/mlx5/mlx5_rxtx_vec_neon.h b/drivers/net/mlx5/mlx5_rxtx_vec_neon.h index b2cc710887..c54914e97a 100644 --- a/drivers/net/mlx5/mlx5_rxtx_vec_neon.h +++ b/drivers/net/mlx5/mlx5_rxtx_vec_neon.h @@ -131,7 +131,7 @@ txq_scatter_v(struct mlx5_txq_data *txq, struct rte_mbuf **pkts, uint8x16_t ctrl; rte_be32_t metadata = metadata_ol && (buf->ol_flags & PKT_TX_METADATA) ? - buf->tx_metadata : 0; + buf->metadata : 0; assert(segs_n); max_elts = elts_n - (elts_head - txq->elts_tail); diff --git a/drivers/net/mlx5/mlx5_rxtx_vec_sse.h b/drivers/net/mlx5/mlx5_rxtx_vec_sse.h index dce3ee4b40..3de640a2fd 100644 --- a/drivers/net/mlx5/mlx5_rxtx_vec_sse.h +++ b/drivers/net/mlx5/mlx5_rxtx_vec_sse.h @@ -129,7 +129,7 @@ txq_scatter_v(struct mlx5_txq_data *txq, struct rte_mbuf **pkts, __m128i ctrl; rte_be32_t metadata = metadata_ol && (buf->ol_flags & PKT_TX_METADATA) ? - buf->tx_metadata : 0; + buf->metadata : 0; assert(segs_n); max_elts = elts_n - (elts_head - txq->elts_tail); diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h index f3a8fb103f..cda8628183 100644 --- a/lib/librte_ethdev/rte_flow.h +++ b/lib/librte_ethdev/rte_flow.h @@ -417,7 +417,8 @@ enum rte_flow_item_type { /** * [META] * - * Matches a metadata value specified in mbuf metadata field. + * Matches a metadata value. + * * See struct rte_flow_item_meta. */ RTE_FLOW_ITEM_TYPE_META, @@ -1164,9 +1165,16 @@ rte_flow_item_icmp6_nd_opt_tla_eth_mask = { #endif /** - * RTE_FLOW_ITEM_TYPE_META. + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice * - * Matches a specified metadata value. + * RTE_FLOW_ITEM_TYPE_META + * + * Matches a specified metadata value. On egress, metadata can be set either by + * mbuf metadata field with PKT_TX_METADATA flag or + * RTE_FLOW_ACTION_TYPE_SET_META. On ingress, RTE_FLOW_ACTION_TYPE_SET_META sets + * metadata for a packet and the metadata will be reported via mbuf metadata + * field with PKT_RX_METADATA flag. */ struct rte_flow_item_meta { rte_be32_t data; @@ -1650,6 +1658,13 @@ enum rte_flow_action_type { * See struct rte_flow_action_set_mac. */ RTE_FLOW_ACTION_TYPE_SET_MAC_DST, + + /** + * Set metadata on ingress or egress path. + * + * See struct rte_flow_action_set_meta. + */ + RTE_FLOW_ACTION_TYPE_SET_META, }; /** @@ -2131,6 +2146,28 @@ struct rte_flow_action_set_mac { uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; }; +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice + * + * RTE_FLOW_ACTION_TYPE_SET_META + * + * Set metadata. Metadata set by mbuf metadata field with PKT_TX_METADATA flag + * on egress will be overridden by this action. On ingress, the metadata will be + * carried by mbuf metadata field with PKT_RX_METADATA flag if set. + * + * Altering partial bits is supported with mask. For bits which have never been + * set, unpredictable value will be seen depending on driver implementation. For + * loopback/hairpin packet, metadata set on Rx/Tx may or may not be propagated + * to the other path depending on HW capability. + * + * RTE_FLOW_ITEM_TYPE_META matches metadata. + */ +struct rte_flow_action_set_meta { + rte_be32_t data; + rte_be32_t mask; +}; + /* * Definition of a single action. * diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index e4c2da6ee6..60f2b553e6 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -200,6 +200,11 @@ extern "C" { /* add new RX flags here */ +/** + * Indicate that mbuf has metadata from device. + */ +#define PKT_RX_METADATA (1ULL << 23) + /* add new TX flags here */ /** @@ -648,17 +653,6 @@ struct rte_mbuf { /**< User defined tags. See rte_distributor_process() */ uint32_t usr; } hash; /**< hash information */ - struct { - /** - * Application specific metadata value - * for egress flow rule match. - * Valid if PKT_TX_METADATA is set. - * Located here to allow conjunct use - * with hash.sched.hi. - */ - uint32_t tx_metadata; - uint32_t reserved; - }; }; /** Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ is set. */ @@ -725,6 +719,11 @@ struct rte_mbuf { */ struct rte_mbuf_ext_shared_info *shinfo; + /** Application specific metadata value for flow rule match. + * Valid if PKT_RX_METADATA or PKT_TX_METADATA is set. + */ + uint32_t metadata; + } __rte_cache_aligned; /** -- 2.21.0