DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com,
	Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH v2 01/24] net/nfp: add the stats process logic in ctrl VNIC service
Date: Mon, 10 Oct 2022 14:08:39 +0800	[thread overview]
Message-ID: <1665382142-21684-2-git-send-email-chaoyong.he@corigine.com> (raw)
In-Reply-To: <1665382142-21684-1-git-send-email-chaoyong.he@corigine.com>

Add the flow stats process logic in the ctrl VNIC service.
The flower firmware pass the flow stats to nfp driver through
control message, we store them in the flow_priv structure.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower.h      |  2 +
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 25 +++++++++++
 drivers/net/nfp/flower/nfp_flower_ctrl.c | 73 ++++++++++++++++++++++++++++++--
 drivers/net/nfp/nfp_flow.h               | 20 +++++++++
 4 files changed, 116 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/nfp/nfp_flow.h

diff --git a/drivers/net/nfp/flower/nfp_flower.h b/drivers/net/nfp/flower/nfp_flower.h
index 48f597a..b90391c 100644
--- a/drivers/net/nfp/flower/nfp_flower.h
+++ b/drivers/net/nfp/flower/nfp_flower.h
@@ -51,6 +51,8 @@ struct nfp_app_fw_flower {
 
 	/* PF representor */
 	struct nfp_flower_representor *pf_repr;
+
+	struct nfp_flow_priv *flow_priv;
 };
 
 int nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev);
diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h b/drivers/net/nfp/flower/nfp_flower_cmsg.h
index 0bf8fc8..5c28363 100644
--- a/drivers/net/nfp/flower/nfp_flower_cmsg.h
+++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h
@@ -129,6 +129,31 @@ struct nfp_flower_cmsg_port_mod {
 	rte_be16_t mtu;
 };
 
+/*
+ * NFP_FLOWER_CMSG_TYPE_FLOW_STATS
+ *    Bit    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
+ *    -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ *    Word  +---------------+-----------------------------------------------+
+ *       0  |    Reserved   |               Host Context                    |
+ *          +---------------+-----------------------------------------------+
+ *       1  |                          Packet Count                         |
+ *          +---------------------------------------------------------------+
+ *       2  |                          Byte Count                           |
+ *          +---------------------------------------------------------------+
+ *       2  |                          Byte Count                           |
+ *          +---------------------------------------------------------------+
+ *       3  |                          Host Cookie                          |
+ *          +---------------------------------------------------------------+
+ *       4  |                          Host Cookie                          |
+ *          +---------------------------------------------------------------+
+ */
+struct nfp_flower_stats_frame {
+	rte_be32_t stats_con_id;
+	rte_be32_t pkt_count;
+	rte_be64_t byte_count;
+	rte_be64_t stats_cookie;
+};
+
 enum nfp_flower_cmsg_port_type {
 	NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC,
 	NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT,
diff --git a/drivers/net/nfp/flower/nfp_flower_ctrl.c b/drivers/net/nfp/flower/nfp_flower_ctrl.c
index df908ef..bb9efe1 100644
--- a/drivers/net/nfp/flower/nfp_flower_ctrl.c
+++ b/drivers/net/nfp/flower/nfp_flower_ctrl.c
@@ -10,8 +10,10 @@
 #include "../nfp_logs.h"
 #include "../nfp_ctrl.h"
 #include "../nfp_rxtx.h"
+#include "nfp_flow.h"
 #include "nfp_flower.h"
 #include "nfp_flower_ctrl.h"
+#include "nfp_flower_cmsg.h"
 
 #define MAX_PKT_BURST 32
 
@@ -222,10 +224,74 @@
 	return cnt;
 }
 
+static void
+nfp_flower_cmsg_rx_stats(struct nfp_flow_priv *flow_priv,
+		struct rte_mbuf *mbuf)
+{
+	char *msg;
+	uint16_t i;
+	uint16_t count;
+	uint16_t msg_len;
+	uint32_t ctx_id;
+	struct nfp_flower_stats_frame *stats;
+
+	msg = rte_pktmbuf_mtod(mbuf, char *) + NFP_FLOWER_CMSG_HLEN;
+	msg_len = mbuf->data_len - NFP_FLOWER_CMSG_HLEN;
+	count = msg_len / sizeof(struct nfp_flower_stats_frame);
+
+	rte_spinlock_lock(&flow_priv->stats_lock);
+	for (i = 0; i < count; i++) {
+		stats = (struct nfp_flower_stats_frame *)msg + i;
+		ctx_id = rte_be_to_cpu_32(stats->stats_con_id);
+		flow_priv->stats[ctx_id].pkts  += rte_be_to_cpu_32(stats->pkt_count);
+		flow_priv->stats[ctx_id].bytes += rte_be_to_cpu_64(stats->byte_count);
+	}
+	rte_spinlock_unlock(&flow_priv->stats_lock);
+}
+
+static void
+nfp_flower_cmsg_rx(struct nfp_flow_priv *flow_priv,
+		struct rte_mbuf **pkts_burst,
+		uint16_t count)
+{
+	uint16_t i;
+	char *meta;
+	uint32_t meta_type;
+	uint32_t meta_info;
+	struct nfp_flower_cmsg_hdr *cmsg_hdr;
+
+	for (i = 0; i < count; i++) {
+		meta = rte_pktmbuf_mtod(pkts_burst[i], char *);
+
+		/* Free the unsupported ctrl packet */
+		meta_type = rte_be_to_cpu_32(*(uint32_t *)(meta - 8));
+		meta_info = rte_be_to_cpu_32(*(uint32_t *)(meta - 4));
+		if (meta_type != NFP_NET_META_PORTID ||
+				meta_info != NFP_META_PORT_ID_CTRL) {
+			PMD_DRV_LOG(ERR, "Incorrect metadata for ctrl packet!");
+			rte_pktmbuf_free(pkts_burst[i]);
+			continue;
+		}
+
+		cmsg_hdr = (struct nfp_flower_cmsg_hdr *)meta;
+		if (unlikely(cmsg_hdr->version != NFP_FLOWER_CMSG_VER1)) {
+			PMD_DRV_LOG(ERR, "Incorrect repr control version!");
+			rte_pktmbuf_free(pkts_burst[i]);
+			continue;
+		}
+
+		if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_FLOW_STATS) {
+			/* We need to deal with stats updates from HW asap */
+			nfp_flower_cmsg_rx_stats(flow_priv, pkts_burst[i]);
+		}
+
+		rte_pktmbuf_free(pkts_burst[i]);
+	}
+}
+
 void
 nfp_flower_ctrl_vnic_poll(struct nfp_app_fw_flower *app_fw_flower)
 {
-	uint16_t i;
 	uint16_t count;
 	struct nfp_net_rxq *rxq;
 	struct nfp_net_hw *ctrl_hw;
@@ -242,9 +308,8 @@
 		count = nfp_flower_ctrl_vnic_recv(rxq, pkts_burst, MAX_PKT_BURST);
 		if (count != 0) {
 			app_fw_flower->ctrl_vnic_rx_count += count;
-			/* Process cmsgs here, only free for now */
-			for (i = 0; i < count; i++)
-				rte_pktmbuf_free(pkts_burst[i]);
+			/* Process cmsgs here */
+			nfp_flower_cmsg_rx(app_fw_flower->flow_priv, pkts_burst, count);
 		}
 	}
 }
diff --git a/drivers/net/nfp/nfp_flow.h b/drivers/net/nfp/nfp_flow.h
new file mode 100644
index 0000000..971ba69
--- /dev/null
+++ b/drivers/net/nfp/nfp_flow.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2022 Corigine, Inc.
+ * All rights reserved.
+ */
+
+#ifndef _NFP_FLOW_H_
+#define _NFP_FLOW_H_
+
+struct nfp_fl_stats {
+	uint64_t pkts;
+	uint64_t bytes;
+};
+
+struct nfp_flow_priv {
+	/* flow stats */
+	struct nfp_fl_stats *stats; /**< Store stats of flow. */
+	rte_spinlock_t stats_lock; /** < Lock the update of 'stats' field. */
+};
+
+#endif /* _NFP_FLOW_H_ */
-- 
1.8.3.1


  reply	other threads:[~2022-10-10  6:09 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10  6:08 [PATCH v2 00/24] add the basic rte_flow offload support of nfp PMD Chaoyong He
2022-10-10  6:08 ` Chaoyong He [this message]
2022-10-10 14:48   ` [PATCH v2 01/24] net/nfp: add the stats process logic in ctrl VNIC service Ferruh Yigit
2022-10-10  6:08 ` [PATCH v2 02/24] net/nfp: add the structures and functions for flow offload Chaoyong He
2022-10-10 14:49   ` Ferruh Yigit
2022-10-19  2:50     ` Chaoyong He
2022-10-19 10:48       ` Ferruh Yigit
2022-10-10  6:08 ` [PATCH v2 03/24] net/nfp: add the flow APIs of nfp PMD Chaoyong He
2022-10-10 14:51   ` Ferruh Yigit
2022-10-19  3:00     ` Chaoyong He
2022-10-19 11:11       ` Ferruh Yigit
2022-10-19 11:30         ` Chaoyong He
2022-10-19 11:38           ` Ferruh Yigit
2022-10-10  6:08 ` [PATCH v2 04/24] net/nfp: add the offload support of basic items Chaoyong He
2022-10-10  6:08 ` [PATCH v2 05/24] net/nfp: add the offload support of basic actions Chaoyong He
2022-10-10 14:52   ` Ferruh Yigit
2022-10-19 11:32     ` Chaoyong He
2022-10-10  6:08 ` [PATCH v2 06/24] net/nfp: add the offload support of VLAN item Chaoyong He
2022-10-10  6:08 ` [PATCH v2 07/24] net/nfp: add the offload support of IPv4 item Chaoyong He
2022-10-10  6:08 ` [PATCH v2 08/24] net/nfp: add the offload support of IPv6 item Chaoyong He
2022-10-10 14:53   ` Ferruh Yigit
2022-10-19 11:33     ` Chaoyong He
2022-10-10  6:08 ` [PATCH v2 09/24] net/nfp: add the offload support of TCP item Chaoyong He
2022-10-10  6:08 ` [PATCH v2 10/24] net/nfp: add the offload support of UDP item Chaoyong He
2022-10-10  6:08 ` [PATCH v2 11/24] net/nfp: add the offload support of SCTP item Chaoyong He
2022-10-10  6:08 ` [PATCH v2 12/24] net/nfp: add the offload support of set SRC MAC action Chaoyong He
2022-10-10  6:08 ` [PATCH v2 13/24] net/nfp: add the offload support of set DST " Chaoyong He
2022-10-10  6:08 ` [PATCH v2 14/24] net/nfp: add the offload support of pop VLAN action Chaoyong He
2022-10-10  6:08 ` [PATCH v2 15/24] net/nfp: add the offload support of push " Chaoyong He
2022-10-10  6:08 ` [PATCH v2 16/24] net/nfp: add the offload support of set SRC IPv4 action Chaoyong He
2022-10-10  6:08 ` [PATCH v2 17/24] net/nfp: add the offload support of set DST " Chaoyong He
2022-10-10  6:08 ` [PATCH v2 18/24] net/nfp: add the offload support of set SRC IPv6 action Chaoyong He
2022-10-10  6:08 ` [PATCH v2 19/24] net/nfp: add the offload support of set DST " Chaoyong He
2022-10-10  6:08 ` [PATCH v2 20/24] net/nfp: add the offload support of set TP SRC port action Chaoyong He
2022-10-10  6:08 ` [PATCH v2 21/24] net/nfp: add the offload support of set TP DST " Chaoyong He
2022-10-10  6:09 ` [PATCH v2 22/24] net/nfp: add the offload support of set TTL action Chaoyong He
2022-10-10  6:09 ` [PATCH v2 23/24] net/nfp: add the offload support of set IPv4 DSCP action Chaoyong He
2022-10-10  6:09 ` [PATCH v2 24/24] net/nfp: add the offload support of set IPv6 " Chaoyong He

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=1665382142-21684-2-git-send-email-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=niklas.soderlund@corigine.com \
    --cc=oss-drivers@corigine.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).