diff --git a/include/osi_common.h b/include/osi_common.h index 5363c43..d497431 100644 --- a/include/osi_common.h +++ b/include/osi_common.h @@ -263,6 +263,12 @@ #define OSI_INVALID_CHAN_NUM 0xFFU /** @} */ +/** + * @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. + */ +#define CORE_MAX_BAK_IDX 400U + /** * @addtogroup EQOS-MAC EQOS MAC HW supported features * @@ -504,6 +510,16 @@ struct osi_hw_features { unsigned int aux_snap_num; }; +/** + * @brief core_backup - Struct used to store backup of core HW registers. + */ +struct core_backup { + /** Array of reg MMIO addresses (base of MAC core + offset of reg) */ + void *reg_addr[CORE_MAX_BAK_IDX]; + /** Array of value stored in each corresponding register */ + unsigned int reg_val[CORE_MAX_BAK_IDX]; +}; + /** * @brief osi_lock_init - Initialize lock to unlocked state. * @@ -664,4 +680,30 @@ void osi_get_hw_features(void *base, struct osi_hw_features *hw_feat); * */ void osi_memset(void *s, unsigned int c, unsigned long count); + +/* + * @brief Function to store a backup of MAC register space during SOC suspend. + * + * Algorithm: Read registers to be backed up as per struct core_backup and + * store the register values in memory. + * + * @param[in] config: Pointer to core_backup structure. + * @param[in] max_regs: Max num of registers to backup. + * + * @retval none + */ +void mac_save_registers(struct core_backup *const config); + +/** + * @brief Function to restore the backup of MAC registers during SOC resume. + * + * Algorithm: Restore the register values from the in memory backup taken using + * osi_save_registers(). + * + * @param[in] config: Pointer to core_backup structure. + * @param[in] max_regs: Max num of registers to restore. + * + * @retval none + */ +void mac_restore_registers(struct core_backup *const config); #endif /* OSI_COMMON_H */ diff --git a/include/osi_core.h b/include/osi_core.h index 82bd47d..23bb206 100644 --- a/include/osi_core.h +++ b/include/osi_core.h @@ -259,10 +259,6 @@ struct osi_core_ops { void (*configure_eee)(struct osi_core_priv_data *const osi_core, const unsigned int tx_lpi_enabled, const unsigned int tx_lpi_timer); - /** Called to save MAC register space during SOC suspend */ - void (*save_registers)(struct osi_core_priv_data *const osi_core); - /** Called to restore MAC control registers during SOC resume */ - void (*restore_registers)(struct osi_core_priv_data *const osi_core); /** Called to write into a PHY reg over MDIO bus */ int (*write_phy_reg)(struct osi_core_priv_data *const osi_core, const unsigned int phyaddr, diff --git a/osi/common/osi_common.c b/osi/common/osi_common.c index 8d50f93..c85377a 100644 --- a/osi/common/osi_common.c +++ b/osi/common/osi_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -134,3 +134,54 @@ void osi_memset(void *s, unsigned int c, unsigned long count) count--; } } + +/* + * @brief Function to store a backup of MAC register space during SOC suspend. + * + * Algorithm: Read registers to be backed up as per struct core_backup and + * store the register values in memory. + * + * @param[in] config: Pointer to core_backup structure. + * @param[in] max_regs: Max num of registers to backup. + * + * @retval none + */ +void mac_save_registers(struct core_backup *const config) +{ + unsigned int i; + + if (config == OSI_NULL) { + return; + } + for (i = 0; i < CORE_MAX_BAK_IDX; i++) { + if (config->reg_addr[i] != OSI_NULL) { + config->reg_val[i] = osi_readl(config->reg_addr[i]); + } + } + +} + +/** + * @brief Function to restore the backup of MAC registers during SOC resume. + * + * Algorithm: Restore the register values from the in memory backup taken using + * osi_save_registers(). + * + * @param[in] config: Pointer to core_backup structure. + * @param[in] max_regs: Max num of registers to restore. + * + * @retval none + */ +void mac_restore_registers(struct core_backup *const config) +{ + unsigned int i; + + if (config == OSI_NULL) { + return; + } + for (i = 0; i < CORE_MAX_BAK_IDX; i++) { + if (config->reg_addr[i] != OSI_NULL) { + osi_writel(config->reg_val[i], config->reg_addr[i]); + } + } +} diff --git a/osi/core/eqos_core.c b/osi/core/eqos_core.c index ffe8292..ebe9872 100644 --- a/osi/core/eqos_core.c +++ b/osi/core/eqos_core.c @@ -3445,52 +3445,6 @@ static void eqos_configure_eee( } } -/* - * @brief Function to store a backup of MAC register space during SOC suspend. - * - * Algorithm: Read registers to be backed up as per struct core_backup and - * store the register values in memory. - * - * @param[in] osi_core: OSI core private data structure. - * - * @retval none - */ -static inline void eqos_save_registers( - struct osi_core_priv_data *const osi_core) -{ - unsigned int i; - struct core_backup *config = osi_core->backup_config; - - for (i = 0; i < EQOS_MAX_BAK_IDX; i++) { - if (config->reg_addr[i] != OSI_NULL) { - config->reg_val[i] = osi_readl(config->reg_addr[i]); - } - } -} - -/** - * @brief Function to restore the backup of MAC registers during SOC resume. - * - * Algorithm: Restore the register values from the in memory backup taken using - * eqos_save_registers(). - * - * @param[in] osi_core: OSI core private data structure. - * - * @retval none - */ -static inline void eqos_restore_registers( - struct osi_core_priv_data *const osi_core) -{ - unsigned int i; - struct core_backup *config = osi_core->backup_config; - - for (i = 0; i < EQOS_MAX_BAK_IDX; i++) { - if (config->reg_addr[i] != OSI_NULL) { - osi_writel(config->reg_val[i], config->reg_addr[i]); - } - } -} - /** * @brief poll_for_mii_idle Query the status of an ongoing DMA transfer * @@ -3689,8 +3643,6 @@ static struct osi_core_ops eqos_core_ops = { .read_mmc = eqos_read_mmc, .reset_mmc = eqos_reset_mmc, .configure_eee = eqos_configure_eee, - .save_registers = eqos_save_registers, - .restore_registers = eqos_restore_registers, .write_phy_reg = eqos_write_phy_reg, .read_phy_reg = eqos_read_phy_reg, }; diff --git a/osi/core/eqos_core.h b/osi/core/eqos_core.h index 9f8f8cb..e7066dd 100644 --- a/osi/core/eqos_core.h +++ b/osi/core/eqos_core.h @@ -599,15 +599,5 @@ struct core_func_safety { */ #define EQOS_MAX_BAK_IDX ((EQOS_PAD_AUTO_CAL_CFG_BAK_IDX + 1U)) -/** - * @brief core_backup - Struct used to store backup of core HW registers. - */ -struct core_backup { - /** Array of reg MMIO addresses (base of EQoS + offset of reg) */ - void *reg_addr[EQOS_MAX_BAK_IDX]; - /** Array of value stored in each corresponding register */ - unsigned int reg_val[EQOS_MAX_BAK_IDX]; -}; - /** @} */ #endif diff --git a/osi/core/osi_core.c b/osi/core/osi_core.c index 9c7cdab..a3885ab 100644 --- a/osi/core/osi_core.c +++ b/osi/core/osi_core.c @@ -845,8 +845,8 @@ int osi_configure_eee(struct osi_core_priv_data *const osi_core, int osi_save_registers(struct osi_core_priv_data *const osi_core) { if ((osi_core != OSI_NULL) && (osi_core->ops != OSI_NULL) && - (osi_core->ops->save_registers != OSI_NULL)) { - osi_core->ops->save_registers(osi_core); + (osi_core->backup_config != OSI_NULL)) { + mac_save_registers(osi_core->backup_config); return 0; } @@ -856,8 +856,8 @@ int osi_save_registers(struct osi_core_priv_data *const osi_core) int osi_restore_registers(struct osi_core_priv_data *const osi_core) { if ((osi_core != OSI_NULL) && (osi_core->ops != OSI_NULL) && - (osi_core->ops->restore_registers != OSI_NULL)) { - osi_core->ops->restore_registers(osi_core); + (osi_core->backup_config != OSI_NULL)) { + mac_restore_registers(osi_core->backup_config); return 0; }