From 1fe7b7f7c971c669661c06744e6b76cf3a4ebd54 Mon Sep 17 00:00:00 2001
From: Michal Krawczyk <mk@semihalf.com>
Date: Fri, 23 Jul 2021 12:24:50 +0200
Subject: [PATCH 173/177] net/ena: use common debug options

ENA defined its own logger flags for Tx and Rx, but they weren't
technically used anywhere. Those data path loggers weren't used anywhere
after the definition.

This commit uses the generic RTE_ETHDEV_DEBUG_RX and RTE_ETHDEV_DEBUG_TX
flags to define PMD_TX_LOG and PMD_RX_LOG which are now being used on
the data path. The PMD_TX_FREE_LOG was removed, as it has no usage in
the current version of the driver.

RTE_ETH_DEBUG_[TR]X now wraps extra checks for the driver state in the
IO path - this saves extra conditionals on the hot path.

ena_com logger is no longer optional (previously it had to be explicitly
enabled by defining this flag: RTE_LIBRTE_ENA_COM_DEBUG). Having this
logger optional makes tracing of ena_com errors much harder.
Due to ena_com design, it's impossible to separate IO path logs
from the management path logs, so for now they will be always enabled.

Default levels for the affected loggers were modified. Hot path loggers
are initialized with the default level of DEBUG instead of NOTICE, as
they have to be explicitly enabled. ena_com logging level was reduced
from NOTICE to WARNING - as it's no longer optional, the driver should
report just a warnings in the ena_com layer.

Signed-off-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Igor Chauskin <igorch@amazon.com>
Reviewed-by: Shai Brandes <shaibran@amazon.com>
---
 config/common_base           |  1 -
 drivers/net/ena/ena_ethdev.c | 37 ++++++++++++++++++++++--------------
 drivers/net/ena/ena_logs.h   |  7 -------
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/config/common_base b/config/common_base
index 4f44806820..1c7578f532 100644
--- a/config/common_base
+++ b/config/common_base
@@ -141,7 +141,6 @@ CONFIG_RTE_NIC_BYPASS=n
 CONFIG_RTE_LIBRTE_ENA_PMD=y
 CONFIG_RTE_LIBRTE_ENA_DEBUG_RX=n
 CONFIG_RTE_LIBRTE_ENA_DEBUG_TX=n
-CONFIG_RTE_LIBRTE_ENA_DEBUG_TX_FREE=n
 CONFIG_RTE_LIBRTE_ENA_DEBUG_DRIVER=n
 CONFIG_RTE_LIBRTE_ENA_COM_DEBUG=n
 
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 6a41ef978e..a849b7d1ec 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -370,9 +370,9 @@ static int validate_tx_req_id(struct ena_ring *tx_ring, u16 req_id)
 	}
 
 	if (tx_info)
-		PMD_DRV_LOG(ERR, "tx_info doesn't have valid mbuf\n");
+		PMD_TX_LOG(ERR, "tx_info doesn't have valid mbuf\n");
 	else
-		PMD_DRV_LOG(ERR, "Invalid req_id: %hu\n", req_id);
+		PMD_TX_LOG(ERR, "Invalid req_id: %hu\n", req_id);
 
 	/* Trigger device reset */
 	++tx_ring->tx_stats.bad_req_id;
@@ -1401,7 +1401,7 @@ static int ena_add_single_rx_desc(struct ena_com_io_sq *io_sq,
 	/* pass resource to device */
 	rc = ena_com_add_single_rx_desc(io_sq, &ebuf, id);
 	if (unlikely(rc != 0))
-		PMD_DRV_LOG(WARNING, "Failed adding Rx desc\n");
+		PMD_RX_LOG(WARNING, "Failed adding Rx desc\n");
 
 	return rc;
 }
@@ -1411,16 +1411,21 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
 	unsigned int i;
 	int rc;
 	uint16_t next_to_use = rxq->next_to_use;
-	uint16_t in_use, req_id;
+	uint16_t req_id;
+#ifdef RTE_LIBRTE_ENA_DEBUG_RX
+	uint16_t in_use;
+#endif
 	struct rte_mbuf **mbufs = rxq->rx_refill_buffer;
 
 	if (unlikely(!count))
 		return 0;
 
+#ifdef RTE_LIBRTE_ENA_DEBUG_RX
 	in_use = rxq->ring_size - 1 -
 		ena_com_free_q_entries(rxq->ena_com_io_sq);
-	ena_assert_msg(((in_use + count) < rxq->ring_size),
-		"bad ring state\n");
+	if (unlikely((in_use + count) >= rxq->ring_size))
+		PMD_RX_LOG(ERR, "Bad Rx ring state\n");
+#endif
 
 	/* get resources for incoming packets */
 	rc = rte_mempool_get_bulk(rxq->mb_pool, (void **)mbufs, count);
@@ -1450,7 +1455,7 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
 	}
 
 	if (unlikely(i < count)) {
-		PMD_DRV_LOG(WARNING,
+		PMD_RX_LOG(WARNING,
 			"Refilled Rx queue[%d] with only %d/%d buffers\n",
 			rxq->id, i, count);
 		rte_mempool_put_bulk(rxq->mb_pool, (void **)(&mbufs[i]),
@@ -2136,12 +2141,14 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 	struct ena_com_rx_ctx ena_rx_ctx;
 	int i, rc = 0;
 
+#ifdef RTE_LIBRTE_ENA_DEBUG_TX
 	/* Check adapter state */
 	if (unlikely(rx_ring->adapter->state != ENA_ADAPTER_STATE_RUNNING)) {
-		PMD_DRV_LOG(ALERT,
+		PMD_RX_LOG(ALERT,
 			"Trying to receive pkts while device is NOT running\n");
 		return 0;
 	}
+#endif
 
 	descs_in_use = rx_ring->ring_size -
 		ena_com_free_q_entries(rx_ring->ena_com_io_sq) - 1;
@@ -2157,7 +2164,7 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 				    rx_ring->ena_com_io_sq,
 				    &ena_rx_ctx);
 		if (unlikely(rc)) {
-			PMD_DRV_LOG(ERR,
+			PMD_RX_LOG(ERR,
 				"Failed to get the packet from the device, rc: %d\n",
 				rc);
 			if (rc == ENA_COM_NO_SPACE) {
@@ -2264,13 +2271,13 @@ static int ena_check_space_and_linearize_mbuf(struct ena_ring *tx_ring,
 	 * be needed so we reduce the segments number from num_segments to 1
 	 */
 	if (!ena_com_sq_have_enough_space(tx_ring->ena_com_io_sq, 3)) {
-		PMD_DRV_LOG(DEBUG, "Not enough space in the Tx queue\n");
+		PMD_TX_LOG(DEBUG, "Not enough space in the Tx queue\n");
 		return ENA_COM_NO_MEM;
 	}
 	++tx_ring->tx_stats.linearize;
 	rc = rte_pktmbuf_linearize(mbuf);
 	if (unlikely(rc)) {
-		PMD_DRV_LOG(WARNING, "Mbuf linearize failed\n");
+		PMD_TX_LOG(WARNING, "Mbuf linearize failed\n");
 		rte_atomic64_inc(&tx_ring->adapter->drv_stats->ierrors);
 		++tx_ring->tx_stats.linearize_failed;
 		return rc;
@@ -2284,7 +2291,7 @@ static int ena_check_space_and_linearize_mbuf(struct ena_ring *tx_ring,
 	 */
 	if (!ena_com_sq_have_enough_space(tx_ring->ena_com_io_sq,
 					  num_segments + 2)) {
-		PMD_DRV_LOG(DEBUG, "Not enough space in the Tx queue\n");
+		PMD_TX_LOG(DEBUG, "Not enough space in the Tx queue\n");
 		return ENA_COM_NO_MEM;
 	}
 
@@ -2398,7 +2405,7 @@ static int ena_xmit_mbuf(struct ena_ring *tx_ring, struct rte_mbuf *mbuf)
 
 	if (unlikely(ena_com_is_doorbell_needed(tx_ring->ena_com_io_sq,
 			&ena_tx_ctx))) {
-		PMD_DRV_LOG(DEBUG,
+		PMD_TX_LOG(DEBUG,
 			"LLQ Tx max burst size of queue %d achieved, writing doorbell to send burst\n",
 			tx_ring->id);
 		ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
@@ -2475,12 +2482,14 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 	struct ena_ring *tx_ring = (struct ena_ring *)(tx_queue);
 	uint16_t sent_idx = 0;
 
+#ifdef RTE_LIBRTE_ENA_DEBUG_TX
 	/* Check adapter state */
 	if (unlikely(tx_ring->adapter->state != ENA_ADAPTER_STATE_RUNNING)) {
-		PMD_DRV_LOG(ALERT,
+		PMD_TX_LOG(ALERT,
 			"Trying to xmit pkts while device is NOT running\n");
 		return 0;
 	}
+#endif
 
 	for (sent_idx = 0; sent_idx < nb_pkts; sent_idx++) {
 		if (ena_xmit_mbuf(tx_ring, tx_pkts[sent_idx]))
diff --git a/drivers/net/ena/ena_logs.h b/drivers/net/ena/ena_logs.h
index 13bde97334..f483275f53 100644
--- a/drivers/net/ena/ena_logs.h
+++ b/drivers/net/ena/ena_logs.h
@@ -25,13 +25,6 @@
 #define PMD_TX_LOG(level, fmt, args...) do { } while (0)
 #endif
 
-#ifdef RTE_LIBRTE_ENA_DEBUG_TX_FREE
-#define PMD_TX_FREE_LOG(level, fmt, args...) \
-	RTE_LOG(level, PMD, "%s(): " fmt, __func__, ## args)
-#else
-#define PMD_TX_FREE_LOG(level, fmt, args...) do { } while (0)
-#endif
-
 #ifdef RTE_LIBRTE_ENA_DEBUG_DRIVER
 #define PMD_DRV_LOG(level, fmt, args...) \
 	RTE_LOG(level, PMD, "%s(): " fmt, __func__, ## args)
-- 
2.25.1

