From 50c383793b7b377ed9f733a779976447dbfd8bda Mon Sep 17 00:00:00 2001 From: Haifei Luo Date: Wed, 14 Apr 2021 13:19:59 +0300 Subject: [PATCH] ethdev: dump single flow rule Previous implementations support dump all the flows. Add new arg rte_flow in rte_flow_dev_dump to dump one flow. Signed-off-by: Haifei Luo Acked-by: Ajit Khaparde Acked-by: Ori Kam --- app/test-pmd/config.c | 2 +- doc/guides/nics/mlx5.rst | 9 ++++++--- doc/guides/rel_notes/release_21_05.rst | 3 +++ drivers/net/mlx5/linux/mlx5_socket.c | 2 +- drivers/net/mlx5/mlx5.h | 4 ++-- drivers/net/mlx5/mlx5_flow.c | 9 ++++++--- drivers/net/octeontx2/otx2_flow.c | 9 ++++++++- lib/librte_ethdev/rte_flow.c | 5 +++-- lib/librte_ethdev/rte_flow.h | 5 ++++- lib/librte_ethdev/rte_flow_driver.h | 1 + 10 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index a8bd664097..995171f110 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1931,7 +1931,7 @@ port_flow_dump(portid_t port_id, const char *file_name) return -errno; } } - ret = rte_flow_dev_dump(port_id, file, &error); + ret = rte_flow_dev_dump(port_id, NULL, file, &error); if (ret) { port_flow_complain(&error); printf("Failed to dump flow: %s\n", strerror(-ret)); diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst index 490329a95c..7ff92b0491 100644 --- a/doc/guides/nics/mlx5.rst +++ b/doc/guides/nics/mlx5.rst @@ -1837,13 +1837,16 @@ all flows with assistance of external tools. .. code-block:: console - testpmd> flow dump + To dump all flows: + testpmd> flow dump all + and dump one flow: + testpmd> flow dump rule - call rte_flow_dev_dump api: .. code-block:: console - rte_flow_dev_dump(port, file, NULL); + rte_flow_dev_dump(port, flow, file, NULL); #. Dump human-readable flows from raw file: @@ -1851,4 +1854,4 @@ all flows with assistance of external tools. .. code-block:: console - mlx_steering_dump.py -f + mlx_steering_dump.py -f -flowptr diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst index d7fdc8dc12..cbfa6b9279 100644 --- a/doc/guides/rel_notes/release_21_05.rst +++ b/doc/guides/rel_notes/release_21_05.rst @@ -248,6 +248,9 @@ API Changes * pci: The value ``PCI_ANY_ID`` is marked as deprecated and can be replaced with ``RTE_PCI_ANY_ID``. +* ethdev: Added a ``rte_flow`` pointer parameter to the function + ``rte_flow_dev_dump()`` allowing dump for single flow. + * cryptodev: The experimental raw data path API for dequeue ``rte_cryptodev_raw_dequeue_burst`` got a new parameter ``max_nb_to_dequeue`` to provide flexible control on dequeue. diff --git a/drivers/net/mlx5/linux/mlx5_socket.c b/drivers/net/mlx5/linux/mlx5_socket.c index b1f41bc102..6e354f4a51 100644 --- a/drivers/net/mlx5/linux/mlx5_socket.c +++ b/drivers/net/mlx5/linux/mlx5_socket.c @@ -84,7 +84,7 @@ mlx5_pmd_socket_handle(void *cb __rte_unused) } /* Dump flow. */ dev = &rte_eth_devices[port_id]; - ret = mlx5_flow_dev_dump(dev, file, NULL); + ret = mlx5_flow_dev_dump(dev, NULL, file, NULL); /* Set-up the ancillary data and reply. */ msg.msg_controllen = 0; msg.msg_control = NULL; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index bac8bc0377..2a39aca397 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1244,8 +1244,8 @@ uint32_t mlx5_counter_alloc(struct rte_eth_dev *dev); void mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt); int mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt, bool clear, uint64_t *pkts, uint64_t *bytes); -int mlx5_flow_dev_dump(struct rte_eth_dev *dev, FILE *file, - struct rte_flow_error *error); +int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow, + FILE *file, struct rte_flow_error *error); void mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev); int mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts, uint32_t nb_contexts, struct rte_flow_error *error); diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index b34d2952b1..d153fc2b5c 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -7153,7 +7153,7 @@ mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev) * 0 on success, a nagative value otherwise. */ int -mlx5_flow_dev_dump(struct rte_eth_dev *dev, +mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx, FILE *file, struct rte_flow_error *error __rte_unused) { @@ -7165,8 +7165,11 @@ mlx5_flow_dev_dump(struct rte_eth_dev *dev, return -errno; return -ENOTSUP; } - return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain, - sh->tx_domain, file); + + if (!flow_idx) + return mlx5_devx_cmd_flow_dump(sh->fdb_domain, + sh->rx_domain, sh->tx_domain, file); + return -ENOTSUP; } /** diff --git a/drivers/net/octeontx2/otx2_flow.c b/drivers/net/octeontx2/otx2_flow.c index 14ac9bc766..1c90d753ff 100644 --- a/drivers/net/octeontx2/otx2_flow.c +++ b/drivers/net/octeontx2/otx2_flow.c @@ -807,7 +807,7 @@ err_exit: static int otx2_flow_dev_dump(struct rte_eth_dev *dev, - FILE *file, + struct rte_flow *flow, FILE *file, struct rte_flow_error *error) { struct otx2_eth_dev *hw = dev->data->dev_private; @@ -822,6 +822,13 @@ otx2_flow_dev_dump(struct rte_eth_dev *dev, "Invalid file"); return -EINVAL; } + if (flow != NULL) { + rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_HANDLE, + NULL, + "Invalid argument"); + return -EINVAL; + } max_prio = hw->npc_flow.flow_max_priority; diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c index e07e617d74..7241f00353 100644 --- a/lib/librte_ethdev/rte_flow.c +++ b/lib/librte_ethdev/rte_flow.c @@ -1027,7 +1027,8 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len, } int -rte_flow_dev_dump(uint16_t port_id, FILE *file, struct rte_flow_error *error) +rte_flow_dev_dump(uint16_t port_id, struct rte_flow *flow, + FILE *file, struct rte_flow_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); @@ -1037,7 +1038,7 @@ rte_flow_dev_dump(uint16_t port_id, FILE *file, struct rte_flow_error *error) return -rte_errno; if (likely(!!ops->dev_dump)) { fts_enter(dev); - ret = ops->dev_dump(dev, file, error); + ret = ops->dev_dump(dev, flow, file, error); fts_exit(dev); return flow_err(port_id, ret, error); } diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h index c476a0f59d..5eba79d26f 100644 --- a/lib/librte_ethdev/rte_flow.h +++ b/lib/librte_ethdev/rte_flow.h @@ -3232,6 +3232,8 @@ enum rte_flow_conv_op { * * @param[in] port_id * The port identifier of the Ethernet device. + * @param[in] flow + * The pointer of flow rule to dump. Dump all rules if NULL. * @param[in] file * A pointer to a file for output. * @param[out] error @@ -3242,7 +3244,8 @@ enum rte_flow_conv_op { */ __rte_experimental int -rte_flow_dev_dump(uint16_t port_id, FILE *file, struct rte_flow_error *error); +rte_flow_dev_dump(uint16_t port_id, struct rte_flow *flow, + FILE *file, struct rte_flow_error *error); /** * Check if mbuf dynamic field for metadata is registered. diff --git a/lib/librte_ethdev/rte_flow_driver.h b/lib/librte_ethdev/rte_flow_driver.h index da594d9256..6ae1f8c264 100644 --- a/lib/librte_ethdev/rte_flow_driver.h +++ b/lib/librte_ethdev/rte_flow_driver.h @@ -75,6 +75,7 @@ struct rte_flow_ops { /** See rte_flow_dev_dump(). */ int (*dev_dump) (struct rte_eth_dev *dev, + struct rte_flow *flow, FILE *file, struct rte_flow_error *error); /** See rte_flow_get_aged_flows() */ -- 2.20.1