diff --git a/include/osi_core.h b/include/osi_core.h index f8cc854..317b15e 100644 --- a/include/osi_core.h +++ b/include/osi_core.h @@ -333,7 +333,7 @@ struct osi_ptp_config { /** * @brief Max num of MAC core registers to backup. It should be max of or >= - * (EQOS_MAX_BAK_IDX=380, MGBE_MAX_BAK_IDX, coreX,...etc) backup registers. + * (EQOS_MAX_BAK_IDX=380, coreX,...etc) backup registers. */ #define CORE_MAX_BAK_IDX 700U diff --git a/include/osi_dma.h b/include/osi_dma.h index 9379303..0f459c5 100644 --- a/include/osi_dma.h +++ b/include/osi_dma.h @@ -940,4 +940,17 @@ int osi_dma_get_systime_from_mac( unsigned int *sec, unsigned int *nsec); +/** + * @brief osi_is_mac_enabled - Checks if MAC is enabled. + * + * Algorithm: Reads MAC MCR register for Tx and Rx enabled bits. + * + * @param[in] osi_dma: OSI DMA private data structure. + * + * @note MAC should be init and started. see osi_start_mac() + * + * @retval OSI_ENABLE if MAC enabled. + * @retval OSI_DISABLE otherwise. + */ +unsigned int osi_is_mac_enabled(struct osi_dma_priv_data *const osi_dma); #endif /* OSI_DMA_H */ diff --git a/osi/common/eqos_common.c b/osi/common/eqos_common.c index 6c07cb9..9403c06 100644 --- a/osi/common/eqos_common.c +++ b/osi/common/eqos_common.c @@ -56,3 +56,17 @@ unsigned long long eqos_get_systime_from_mac(void *addr) return ns; } + +unsigned int eqos_is_mac_enabled(void *addr) +{ + unsigned int enable = OSI_DISABLE; + unsigned int reg; + + reg = osi_readl((unsigned char *)addr + EQOS_MAC_MCR); + if ((reg & (EQOS_MCR_TE | EQOS_MCR_RE)) == + (EQOS_MCR_TE | EQOS_MCR_RE)) { + enable = OSI_ENABLE; + } + + return enable; +} diff --git a/osi/common/eqos_common.h b/osi/common/eqos_common.h index 98a96ec..c3124e6 100644 --- a/osi/common/eqos_common.h +++ b/osi/common/eqos_common.h @@ -34,6 +34,15 @@ #define EQOS_MAC_STNSR_TSSS_MASK 0x7FFFFFFFU /** @} */ +/** + * @brief Common MAC MCR register and its bits + * @{ + */ +#define EQOS_MAC_MCR 0x0000 +#define EQOS_MCR_TE OSI_BIT(0) +#define EQOS_MCR_RE OSI_BIT(1) +/** @} */ + /** * @brief eqos_get_systime - Get system time from MAC * @@ -49,4 +58,18 @@ */ unsigned long long eqos_get_systime_from_mac(void *addr); +/** + * @brief eqos_is_mac_enabled - Checks if MAC is enabled or not. + * + * Algorithm: Reads MAC MCR register for Tx and Rx enabled bits. + * + * @param[in] addr: Base address indicating the start of + * memory mapped IO region of the MAC. + * + * @note MAC should be init and started. see osi_start_mac() + * + * @retval OSI_ENABLE if MAC enabled. + * @retval OSI_DISABLE otherwise. + */ +unsigned int eqos_is_mac_enabled(void *addr); #endif /* EQOS_COMMON_H */ diff --git a/osi/common/include/local_common.h b/osi/common/include/local_common.h index a2dbdbe..9339b31 100644 --- a/osi/common/include/local_common.h +++ b/osi/common/include/local_common.h @@ -43,4 +43,18 @@ void common_get_systime_from_mac(void *addr, unsigned int mac, unsigned int *sec, unsigned int *nsec); +/** + * @brief common_is_mac_enabled - Checks if MAC is enabled or not. + * + * Algorithm: Reads MAC register for Tx and Rx enabled bits. + * + * @param[in] addr: Address of base register. + * @param[in] mac: MAC HW type. + * + * @note MAC should be init and started. see osi_start_mac() + * + * @retval OSI_ENABLE if MAC enabled. + * @retval OSI_DISABLE otherwise. + */ +unsigned int common_is_mac_enabled(void *addr, unsigned int mac); #endif /* LOCAL_COMMON_H */ diff --git a/osi/common/osi_common.c b/osi/common/osi_common.c index 80cf1d5..c17c36f 100644 --- a/osi/common/osi_common.c +++ b/osi/common/osi_common.c @@ -191,3 +191,13 @@ void common_get_systime_from_mac(void *addr, unsigned int mac, /* do nothing here */ } } + +unsigned int common_is_mac_enabled(void *addr, unsigned int mac) +{ + if (mac == OSI_MAC_HW_EQOS) { + return eqos_is_mac_enabled(addr); + } else { + /* Non EQOS HW is supported yet */ + return OSI_DISABLE; + } +} diff --git a/osi/dma/libnvethernetcl.export b/osi/dma/libnvethernetcl.export index e54e368..e66a979 100644 --- a/osi/dma/libnvethernetcl.export +++ b/osi/dma/libnvethernetcl.export @@ -42,3 +42,4 @@ osi_validate_dma_regs osi_config_slot_function osi_clear_tx_pkt_err_stats osi_dma_get_systime_from_mac +osi_is_mac_enabled diff --git a/osi/dma/osi_dma.c b/osi/dma/osi_dma.c index 200efc1..9c9485b 100644 --- a/osi/dma/osi_dma.c +++ b/osi/dma/osi_dma.c @@ -426,3 +426,12 @@ int osi_dma_get_systime_from_mac(struct osi_dma_priv_data *const osi_dma, return 0; } + +unsigned int osi_is_mac_enabled(struct osi_dma_priv_data *const osi_dma) +{ + if ((osi_dma != OSI_NULL) && (osi_dma->base != OSI_NULL)) { + return common_is_mac_enabled(osi_dma->base, osi_dma->mac); + } else { + return OSI_DISABLE; + } +}