netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, jiri@nvidia.com,
	yotam.gi@gmail.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com,
	roopa@nvidia.com, peter.phaal@inmon.com, neil.mckee@inmon.com,
	mlxsw@nvidia.com, Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH net-next 10/11] mlxsw: spectrum: Report extra metadata to psample module
Date: Sun, 14 Mar 2021 14:19:39 +0200	[thread overview]
Message-ID: <20210314121940.2807621-11-idosch@idosch.org> (raw)
In-Reply-To: <20210314121940.2807621-1-idosch@idosch.org>

From: Ido Schimmel <idosch@nvidia.com>

Make use of the previously added metadata and report it to the psample
module. The metadata is read from the skb's control block, which was
initialized by the bus driver (i.e., 'mlxsw_pci') after decoding the
packet's Completion Queue Element (CQE).

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 .../ethernet/mellanox/mlxsw/spectrum_trap.c   | 54 ++++++++++++++++++-
 1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
index ea01047f8f8f..056201029ce5 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
@@ -204,6 +204,55 @@ static void mlxsw_sp_rx_ptp_listener(struct sk_buff *skb, u8 local_port,
 	mlxsw_sp_ptp_receive(mlxsw_sp, skb, local_port);
 }
 
+static struct mlxsw_sp_port *
+mlxsw_sp_sample_tx_port_get(struct mlxsw_sp *mlxsw_sp,
+			    const struct mlxsw_rx_md_info *rx_md_info)
+{
+	u8 local_port;
+
+	if (!rx_md_info->tx_port_valid)
+		return NULL;
+
+	if (rx_md_info->tx_port_is_lag)
+		local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
+							rx_md_info->tx_lag_id,
+							rx_md_info->tx_lag_port_index);
+	else
+		local_port = rx_md_info->tx_sys_port;
+
+	if (local_port >= mlxsw_core_max_ports(mlxsw_sp->core))
+		return NULL;
+
+	return mlxsw_sp->ports[local_port];
+}
+
+/* The latency units are determined according to MOGCR.mirror_latency_units. It
+ * defaults to 64 nanoseconds.
+ */
+#define MLXSW_SP_MIRROR_LATENCY_SHIFT	6
+
+static void mlxsw_sp_psample_md_init(struct mlxsw_sp *mlxsw_sp,
+				     struct psample_metadata *md,
+				     struct sk_buff *skb, int in_ifindex,
+				     bool truncate, u32 trunc_size)
+{
+	struct mlxsw_rx_md_info *rx_md_info = &mlxsw_skb_cb(skb)->rx_md_info;
+	struct mlxsw_sp_port *mlxsw_sp_port;
+
+	md->trunc_size = truncate ? trunc_size : skb->len;
+	md->in_ifindex = in_ifindex;
+	mlxsw_sp_port = mlxsw_sp_sample_tx_port_get(mlxsw_sp, rx_md_info);
+	md->out_ifindex = mlxsw_sp_port && mlxsw_sp_port->dev ?
+			  mlxsw_sp_port->dev->ifindex : 0;
+	md->out_tc_valid = rx_md_info->tx_tc_valid;
+	md->out_tc = rx_md_info->tx_tc;
+	md->out_tc_occ_valid = rx_md_info->tx_congestion_valid;
+	md->out_tc_occ = rx_md_info->tx_congestion;
+	md->latency_valid = rx_md_info->latency_valid;
+	md->latency = rx_md_info->latency;
+	md->latency <<= MLXSW_SP_MIRROR_LATENCY_SHIFT;
+}
+
 static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port,
 					void *trap_ctx)
 {
@@ -229,8 +278,9 @@ static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port,
 	 * Ethernet header.
 	 */
 	skb_push(skb, ETH_HLEN);
-	md.trunc_size = sample->truncate ? sample->trunc_size : skb->len;
-	md.in_ifindex = mlxsw_sp_port->dev->ifindex;
+	mlxsw_sp_psample_md_init(mlxsw_sp, &md, skb,
+				 mlxsw_sp_port->dev->ifindex, sample->truncate,
+				 sample->trunc_size);
 	psample_sample_packet(sample->psample_group, skb, sample->rate, &md);
 out:
 	consume_skb(skb);
-- 
2.29.2


  parent reply	other threads:[~2021-03-14 12:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-14 12:19 [PATCH net-next 00/11] psample: Add additional metadata attributes Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 01/11] psample: Encapsulate packet metadata in a struct Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 02/11] psample: Add additional metadata attributes Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 03/11] netdevsim: Add dummy psample implementation Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 04/11] selftests: netdevsim: Test psample functionality Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 05/11] mlxsw: pci: Add more metadata fields to CQEv2 Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 06/11] mlxsw: Create dedicated field for Rx metadata in skb control block Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 07/11] mlxsw: pci: Set extra " Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 08/11] mlxsw: spectrum: Remove unnecessary RCU read-side critical section Ido Schimmel
2021-03-14 12:19 ` [PATCH net-next 09/11] mlxsw: spectrum: Remove mlxsw_sp_sample_receive() Ido Schimmel
2021-03-14 12:19 ` Ido Schimmel [this message]
2021-03-14 12:19 ` [PATCH net-next 11/11] selftests: mlxsw: Add tc sample tests Ido Schimmel
2021-03-14 22:40 ` [PATCH net-next 00/11] psample: Add additional metadata attributes patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210314121940.2807621-11-idosch@idosch.org \
    --to=idosch@idosch.org \
    --cc=davem@davemloft.net \
    --cc=idosch@nvidia.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mlxsw@nvidia.com \
    --cc=neil.mckee@inmon.com \
    --cc=netdev@vger.kernel.org \
    --cc=peter.phaal@inmon.com \
    --cc=roopa@nvidia.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yotam.gi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).