From a9b03b83a901ef38d17394e873b6c1bad49adb11 Mon Sep 17 00:00:00 2001 From: Rakesh Goyal Date: Mon, 6 Sep 2021 19:40:15 +0530 Subject: [PATCH] core: mgbe: use lock for time stamping Using lock for protect critical section between common interrupt and ioctl call to read timestamp Add mmc counters for lock failure during node addition and deletion. Bug 200743666 Change-Id: I12a2e57993e91d6ed50ed0efc84d1b60ef736677 Signed-off-by: Rakesh Goyal Reviewed-on: https://git-master.nvidia.com/r/c/kernel/nvethernetrm/+/2590099 Tested-by: Gaurav Asati Tested-by: mobile promotions Reviewed-by: Gaurav Asati Reviewed-by: svcacv Reviewed-by: Nagarjuna Kristam Reviewed-by: Bhadram Varka Reviewed-by: Krishna Thota Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit --- include/mmc.h | 4 ++++ osi/core/core_local.h | 2 ++ osi/core/mgbe_core.c | 13 +++++++++++++ osi/core/osi_core.c | 1 + osi/core/osi_hal.c | 12 ++++++++++++ osi/dma/dma_local.h | 2 +- 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/mmc.h b/include/mmc.h index ffe9385..6f5e2a0 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -578,6 +578,10 @@ struct osi_xtra_stat_counters { nveu64_t link_connect_count; /** link disconnect count */ nveu64_t link_disconnect_count; + /** lock fail count node addition */ + nveu64_t ts_lock_add_fail; + /** lock fail count node removal */ + nveu64_t ts_lock_del_fail; }; #ifdef MACSEC_SUPPORT diff --git a/osi/core/core_local.h b/osi/core/core_local.h index 8cd9da6..a6ca061 100644 --- a/osi/core/core_local.h +++ b/osi/core/core_local.h @@ -299,6 +299,8 @@ struct core_local { nveu32_t gcl_dep; /** Max GCL width (time + gate) value supported by HW */ nveu32_t gcl_width_val; + /** TS lock */ + nveu32_t ts_lock; }; /** diff --git a/osi/core/mgbe_core.c b/osi/core/mgbe_core.c index 21fe7f0..3ba4875 100644 --- a/osi/core/mgbe_core.c +++ b/osi/core/mgbe_core.c @@ -3270,6 +3270,15 @@ static void mgbe_handle_mac_intrs(struct osi_core_priv_data *osi_core, if ((mac_isr & MGBE_ISR_TSIS) == MGBE_ISR_TSIS) { struct osi_core_tx_ts *head = &l_core->tx_ts_head; + if (__sync_fetch_and_add(&l_core->ts_lock, 1) == 1U) { + /* mask return as initial value is returned always */ + (void)__sync_fetch_and_sub(&l_core->ts_lock, 1); + osi_core->xstats.ts_lock_add_fail = + osi_update_stats_counter( + osi_core->xstats.ts_lock_add_fail, 1U); + goto done; + } + /* TXTSC bit should get reset when all timestamp read */ while (((osi_readla(osi_core, (nveu8_t *)osi_core->base + MGBE_MAC_TSS) & @@ -3299,7 +3308,11 @@ static void mgbe_handle_mac_intrs(struct osi_core_priv_data *osi_core, l_core->ts[i].prev = head->prev; head->prev = &l_core->ts[i]; } + + /* mask return as initial value is returned always */ + (void)__sync_fetch_and_sub(&l_core->ts_lock, 1); } +done: mac_isr &= ~MGBE_ISR_TSIS; osi_writela(osi_core, mac_isr, diff --git a/osi/core/osi_core.c b/osi/core/osi_core.c index f8821d0..508dbb4 100644 --- a/osi/core/osi_core.c +++ b/osi/core/osi_core.c @@ -167,6 +167,7 @@ nve32_t osi_init_core_ops(struct osi_core_priv_data *const osi_core) return ret; } l_core->if_init_done = OSI_ENABLE; + l_core->ts_lock = OSI_DISABLE; return ret; } diff --git a/osi/core/osi_hal.c b/osi/core/osi_hal.c index ce52259..548b444 100644 --- a/osi/core/osi_hal.c +++ b/osi/core/osi_hal.c @@ -1425,6 +1425,15 @@ static inline nve32_t get_tx_ts(struct osi_core_priv_data *osi_core, nve32_t ret = -1; nveu32_t count = 0U; + if (__sync_fetch_and_add(&l_core->ts_lock, 1) == 1U) { + /* mask return as initial value is returned always */ + (void)__sync_fetch_and_sub(&l_core->ts_lock, 1); + osi_core->xstats.ts_lock_del_fail = + osi_update_stats_counter( + osi_core->xstats.ts_lock_del_fail, 1U); + goto done; + } + while ((temp != head) && (count < MAX_TX_TS_CNT)) { if ((temp->pkt_id == ts->pkt_id) && (temp->in_use != OSI_NONE)) { @@ -1442,6 +1451,9 @@ static inline nve32_t get_tx_ts(struct osi_core_priv_data *osi_core, temp = temp->next; } + /* mask return as initial value is returned always */ + (void)__sync_fetch_and_sub(&l_core->ts_lock, 1); +done: return ret; } diff --git a/osi/dma/dma_local.h b/osi/dma/dma_local.h index 5528870..bff9a5f 100644 --- a/osi/dma/dma_local.h +++ b/osi/dma/dma_local.h @@ -249,7 +249,7 @@ nve32_t dma_desc_init(struct osi_dma_priv_data *osi_dma, } \ } \ -#define BOOLEAN_FALSE (0U != 0U) +#define BOOLEAN_FALSE (0U != 0U) #define L32(data) ((data) & 0xFFFFFFFFU) #define H32(data) (((data) & 0xFFFFFFFF00000000UL) >> 32UL) /** @} */