osi: core: remove condition to compiled code for QNX

If there is no request from PTP application to read
Tx timestamp to OSD driver, OSD driver don't
read time to local OSI structure and it may lead to wrong
TX time on request from OSD.
Any PTP time stamp after 2 sync time is not useful.
As POR 2 sync time can be max equal to 1sec.
Remove old timestamp from driver structure if it older
than 1 sec.

Bug 3810821
Bug 3759976

Change-Id: I3173104b60bb50de05285ba1993291c489c34079
Signed-off-by: Rakesh Goyal <rgoyal@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/kernel/nvethernetrm/+/2814646
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Rakesh Goyal
2022-11-25 05:48:59 +05:30
committed by Bhadram Varka
parent d26a803401
commit c220b78d89
2 changed files with 26 additions and 55 deletions

View File

@@ -250,14 +250,7 @@ struct core_ops {
#define DRIFT_CAL 0 #define DRIFT_CAL 0
#endif #endif
#if (!defined(ETHERNET_SERVER) && !defined(__QNX__)) || DRIFT_CAL
#define EQOS_SEC_OFFSET 0xB08
#define EQOS_NSEC_OFFSET 0xB0C
#define MGBE_SEC_OFFSET 0xD08
#define MGBE_NSEC_OFFSET 0xD0C
#define ETHER_NSEC_MASK 0x7FFFFFFFU #define ETHER_NSEC_MASK 0x7FFFFFFFU
#define OSI_1SEC_TO_NSEC 1000000000LL
#endif
#if DRIFT_CAL #if DRIFT_CAL
/** /**

View File

@@ -1660,45 +1660,28 @@ static inline void free_tx_ts(struct osi_core_priv_data *osi_core,
} }
} }
#if (!defined(ETHERNET_SERVER) && !defined(__QNX__)) || DRIFT_CAL
/** /**
* @brief read time counters from HW register * @brief Return absolute difference
*
* Algorithm: * Algorithm:
* - read HW time counters and take care of roll-over * - calculate absolute positive difference
* *
* @param[in] addr: base address * @param[in] a - First input argument
* @param[in] mac: IP type * @param[in] b - Second input argument
* @param[out] sec: sec counter *
* @param[out] nsec: nsec counter * @retval absolute difference
*/ */
static void read_sec_ns(void *addr, nveu32_t mac, static inline nveul64_t eth_abs(nveul64_t a, nveul64_t b)
nveu32_t *sec,
nveu32_t *nsec)
{ {
nveu32_t ns1, ns2; nveul64_t temp = 0ULL;
nveu32_t time_reg_offset[][2] = {{EQOS_SEC_OFFSET, EQOS_NSEC_OFFSET},
{MGBE_SEC_OFFSET, MGBE_NSEC_OFFSET}};
ns1 = osi_readl((nveu8_t *)addr + time_reg_offset[mac][1]); if (a > b) {
ns1 = (ns1 & ETHER_NSEC_MASK); temp = (a - b);
*sec = osi_readl((nveu8_t *)addr + time_reg_offset[mac][0]);
ns2 = osi_readl((nveu8_t *)addr + time_reg_offset[mac][1]);
ns2 = (ns2 & ETHER_NSEC_MASK);
/* if ns1 is greater than ns2, it means nsec counter rollover
* happened. In that case read the updated sec counter again
*/
if (ns1 >= ns2) {
*sec = osi_readl((nveu8_t *)addr + time_reg_offset[mac][0]);
*nsec = ns2;
} else { } else {
*nsec = ns1; temp = (b - a);
} }
return temp;
} }
#endif
/** /**
* @brief Parses internal ts structure array and update time stamp if packet * @brief Parses internal ts structure array and update time stamp if packet
@@ -1722,14 +1705,12 @@ static inline nve32_t get_tx_ts(struct osi_core_priv_data *osi_core,
struct osi_core_tx_ts const *head = &l_core->tx_ts_head; struct osi_core_tx_ts const *head = &l_core->tx_ts_head;
nve32_t ret = -1; nve32_t ret = -1;
nveu32_t count = 0U; nveu32_t count = 0U;
#if !defined(ETHERNET_SERVER) && !defined(__QNX__)
nveu32_t nsec, sec, temp_nsec; nveu32_t nsec, sec, temp_nsec;
nvel64_t temp_val = 0LL; nveul64_t temp_val = 0ULL;
nvel64_t ts_val = 0LL; nveul64_t ts_val = 0ULL;
read_sec_ns(osi_core->base, osi_core->mac, &sec, &nsec); common_get_systime_from_mac(osi_core->base, osi_core->mac, &sec, &nsec);
ts_val = (nvel64_t)(sec * OSI_1SEC_TO_NSEC) + (nvel64_t)nsec; ts_val = (sec * OSI_NSEC_PER_SEC) + nsec;
#endif
if (__sync_fetch_and_add(&l_core->ts_lock, 1) == 1U) { if (__sync_fetch_and_add(&l_core->ts_lock, 1) == 1U) {
/* mask return as initial value is returned always */ /* mask return as initial value is returned always */
@@ -1743,11 +1724,10 @@ static inline nve32_t get_tx_ts(struct osi_core_priv_data *osi_core,
} }
while ((temp != head) && (count < MAX_TX_TS_CNT)) { while ((temp != head) && (count < MAX_TX_TS_CNT)) {
#if !defined(ETHERNET_SERVER) && !defined(__QNX__)
temp_nsec = temp->nsec & ETHER_NSEC_MASK; temp_nsec = temp->nsec & ETHER_NSEC_MASK;
temp_val = (nvel64_t)(temp->sec * OSI_1SEC_TO_NSEC) + (nvel64_t)temp_nsec; temp_val = (temp->sec * OSI_NSEC_PER_SEC) + temp_nsec;
if (((ts_val - temp_val) > (2LL * OSI_1SEC_TO_NSEC)) && if ((eth_abs(ts_val, temp_val) > OSI_NSEC_PER_SEC) &&
(temp->in_use != OSI_NONE)) { (temp->in_use != OSI_NONE)) {
/* remove old node from the link */ /* remove old node from the link */
temp->next->prev = temp->prev; temp->next->prev = temp->prev;
@@ -1756,13 +1736,11 @@ static inline nve32_t get_tx_ts(struct osi_core_priv_data *osi_core,
temp->in_use = OSI_DISABLE; temp->in_use = OSI_DISABLE;
OSI_CORE_INFO(osi_core->osd, OSI_LOG_ARG_INVALID, OSI_CORE_INFO(osi_core->osd, OSI_LOG_ARG_INVALID,
"Removing stale TS from queue pkt_id\n", "Removing stale TS from queue pkt_id\n",
temp->pkt_id); (nveul64_t)temp->pkt_id);
count++; count++;
temp = temp->next; temp = temp->next;
continue; continue;
} else } else if ((temp->pkt_id == ts->pkt_id) &&
#endif
if ((temp->pkt_id == ts->pkt_id) &&
(temp->in_use != OSI_NONE)) { (temp->in_use != OSI_NONE)) {
ts->sec = temp->sec; ts->sec = temp->sec;
ts->nsec = temp->nsec; ts->nsec = temp->nsec;
@@ -2442,9 +2420,9 @@ static nve32_t osi_hal_handle_ioctl(struct osi_core_priv_data *osi_core,
if (l_core->ether_m2m_role == OSI_PTP_M2M_PRIMARY) { if (l_core->ether_m2m_role == OSI_PTP_M2M_PRIMARY) {
drift_value = 0x0; drift_value = 0x0;
osi_lock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock); osi_lock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock);
read_sec_ns(sec_osi_core->base, common_get_systime_from_mac(sec_osi_core->base,
sec_osi_core->mac, &secondary_sec, &secondary_nsec); sec_osi_core->mac, &secondary_sec, &secondary_nsec);
read_sec_ns(osi_core->base, common_get_systime_from_mac(osi_core->base,
osi_core->mac, &sec, &nsec); osi_core->mac, &sec, &nsec);
osi_unlock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock); osi_unlock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock);
@@ -2499,9 +2477,9 @@ static nve32_t osi_hal_handle_ioctl(struct osi_core_priv_data *osi_core,
if (l_core->ether_m2m_role == OSI_PTP_M2M_PRIMARY) { if (l_core->ether_m2m_role == OSI_PTP_M2M_PRIMARY) {
drift_value = 0x0; drift_value = 0x0;
osi_lock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock); osi_lock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock);
read_sec_ns(sec_osi_core->base, common_get_systime_from_mac(sec_osi_core->base,
sec_osi_core->mac, &secondary_sec, &secondary_nsec); sec_osi_core->mac, &secondary_sec, &secondary_nsec);
read_sec_ns(osi_core->base, common_get_systime_from_mac(osi_core->base,
osi_core->mac, &sec, &nsec); osi_core->mac, &sec, &nsec);
osi_unlock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock); osi_unlock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock);
drift_value = dirft_calculation(sec, nsec, drift_value = dirft_calculation(sec, nsec,
@@ -2587,7 +2565,7 @@ static nve32_t osi_hal_handle_ioctl(struct osi_core_priv_data *osi_core,
if (l_core->ether_m2m_role == OSI_PTP_M2M_PRIMARY) { if (l_core->ether_m2m_role == OSI_PTP_M2M_PRIMARY) {
osi_lock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock); osi_lock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock);
read_sec_ns(osi_core->base, common_get_systime_from_mac(osi_core->base,
osi_core->mac, &sec, &nsec); osi_core->mac, &sec, &nsec);
osi_unlock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock); osi_unlock_irq_enabled(&secondary_osi_lcore->serv.m2m_lock);
ret = hw_set_systime_to_mac(sec_osi_core, sec, nsec); ret = hw_set_systime_to_mac(sec_osi_core, sec, nsec);