From e5d309bc52640cb3a962806b56e2459d7fc35e66 Mon Sep 17 00:00:00 2001 From: narayanr Date: Mon, 16 Dec 2019 16:38:45 +0530 Subject: [PATCH] nvethernetrm: mgbe: add rx stats Bug 200565898 Change-Id: If3bb00422d77d24e2425764015db25cdf4e1d930 Signed-off-by: narayanr Reviewed-on: https://git-master.nvidia.com/r/c/kernel/nvethernetrm/+/2309521 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Mahesh Patil Reviewed-by: Bhadram Varka --- osi/dma/dma_local.h | 3 +++ osi/dma/eqos_desc.c | 34 +++++++++++++++++++++++++++++++++- osi/dma/hw_desc.h | 1 + osi/dma/mgbe_desc.c | 23 +++++++++++++++++++++++ osi/dma/osi_dma_local.h | 3 +++ osi/dma/osi_dma_txrx.c | 4 ++-- 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/osi/dma/dma_local.h b/osi/dma/dma_local.h index ec6cc1b..ceb5b5c 100644 --- a/osi/dma/dma_local.h +++ b/osi/dma/dma_local.h @@ -92,6 +92,9 @@ struct desc_ops { /** Called to get receive checksum */ void (*get_rx_csum)(struct osi_rx_desc *rx_desc, struct osi_rx_pkt_cx *rx_pkt_cx); + /** Called to get rx error stats */ + void (*update_rx_err_stats)(struct osi_rx_desc *rx_desc, + struct osi_pkt_err_stats pkt_err_stats); }; /** diff --git a/osi/dma/eqos_desc.c b/osi/dma/eqos_desc.c index 9aa1536..0a9493a 100644 --- a/osi/dma/eqos_desc.c +++ b/osi/dma/eqos_desc.c @@ -24,7 +24,38 @@ #include "hw_desc.h" /** - * @brief get_rx_csum - Get the Rx checksum from descriptor if valid + * @brief eqos_update_rx_err_stats - Detect Errors from Rx Descriptor + * + * Algorithm: This routine will be invoked by OSI layer itself which + * checks for the Last Descriptor and updates the receive status errors + * accordingly. + * + * @param[in] rx_desc: Rx Descriptor. + * @param[in] pkt_err_stats: Packet error stats which stores the errors reported + */ +static inline void eqos_update_rx_err_stats(struct osi_rx_desc *rx_desc, + struct osi_pkt_err_stats + pkt_err_stats) +{ + /* increment rx crc if we see CE bit set */ + if ((rx_desc->rdes3 & RDES3_ERR_CRC) == RDES3_ERR_CRC) { + pkt_err_stats.rx_crc_error = + osi_update_stats_counter( + pkt_err_stats.rx_crc_error, + 1UL); + } + + /* increment rx frame error if we see RE bit set */ + if ((rx_desc->rdes3 & RDES3_ERR_RE) == RDES3_ERR_RE) { + pkt_err_stats.rx_frame_error = + osi_update_stats_counter( + pkt_err_stats.rx_frame_error, + 1UL); + } +} + +/** + * @brief eqos_get_rx_csum - Get the Rx checksum from descriptor if valid * * @note * Algorithm: @@ -104,4 +135,5 @@ static void eqos_get_rx_csum(struct osi_rx_desc *rx_desc, void eqos_init_desc_ops(struct desc_ops *d_ops) { d_ops->get_rx_csum = eqos_get_rx_csum; + d_ops->update_rx_err_stats = eqos_update_rx_err_stats; } diff --git a/osi/dma/hw_desc.h b/osi/dma/hw_desc.h index e58d872..b588037 100644 --- a/osi/dma/hw_desc.h +++ b/osi/dma/hw_desc.h @@ -73,6 +73,7 @@ /** MGBE error summary bits for Received packet */ #define RDES3_ES_MGBE 0x8000U +#define RDES3_ERR_MGBE_CRC (OSI_BIT(16) | OSI_BIT(17)) /** * @addtogroup EQOS_TxDesc Transmit Descriptors bit fields * diff --git a/osi/dma/mgbe_desc.c b/osi/dma/mgbe_desc.c index 25a00e3..a737a82 100644 --- a/osi/dma/mgbe_desc.c +++ b/osi/dma/mgbe_desc.c @@ -23,6 +23,28 @@ #include "dma_local.h" #include "hw_desc.h" +/** + * @brief mgbe_get_rx_err_stats - Detect Errors from Rx Descriptor + * + * Algorithm: This routine will be invoked by OSI layer itself which + * checks for the Last Descriptor and updates the receive status errors + * accordingly. + * + * @param[in] rx_desc: Rx Descriptor. + * @param[in] pkt_err_stats: Packet error stats which stores the errors reported + */ +static inline void mgbe_update_rx_err_stats(struct osi_rx_desc *rx_desc, + struct osi_pkt_err_stats + pkt_err_stats) +{ + /* increment rx crc if we see CE bit set */ + if ((rx_desc->rdes3 & RDES3_ERR_MGBE_CRC) == RDES3_ERR_MGBE_CRC) { + pkt_err_stats.rx_crc_error = + osi_update_stats_counter(pkt_err_stats.rx_crc_error, + 1UL); + } +} + /** * @brief mgbe_get_rx_csum - Get the Rx checksum from descriptor if valid * @@ -54,4 +76,5 @@ static void mgbe_get_rx_csum(struct osi_rx_desc *rx_desc, void mgbe_init_desc_ops(struct desc_ops *d_ops) { d_ops->get_rx_csum = mgbe_get_rx_csum; + d_ops->update_rx_err_stats = mgbe_update_rx_err_stats; } diff --git a/osi/dma/osi_dma_local.h b/osi/dma/osi_dma_local.h index 7cb4d60..1eeaa62 100644 --- a/osi/dma/osi_dma_local.h +++ b/osi/dma/osi_dma_local.h @@ -35,6 +35,9 @@ struct desc_ops { /** Called to get receive checksum */ void (*get_rx_csum)(struct osi_rx_desc *rx_desc, struct osi_rx_pkt_cx *rx_pkt_cx); + /** Called to get rx error stats */ + void (*update_rx_err_stats)(struct osi_rx_desc *rx_desc, + struct osi_pkt_err_stats pkt_err_stats); }; /** diff --git a/osi/dma/osi_dma_txrx.c b/osi/dma/osi_dma_txrx.c index 391327d..6cac12a 100644 --- a/osi/dma/osi_dma_txrx.c +++ b/osi/dma/osi_dma_txrx.c @@ -359,8 +359,8 @@ nve32_t osi_process_rx_completions(struct osi_dma_priv_data *osi_dma, * are set */ rx_pkt_cx->flags &= ~OSI_PKT_CX_VALID; - get_rx_err_stats(rx_desc, - &osi_dma->pkt_err_stats); + d_ops.update_rx_err_stats(rx_desc, + osi_dma->pkt_err_stats); } /* Check if COE Rx checksum is valid */