fcmapphy.c (4750B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * StrataSwitch FCMAP PHY control 8 * FCMAP PHY initialization 9 */ 10 11 12 #include <shared/bsl.h> 13 14 #include <soc/drv.h> 15 #include <soc/phy/phyctrl.h> 16 #include <soc/debug.h> 17 18 #ifdef INCLUDE_FCMAP 19 #include <bfcmap.h> 20 #if defined(INCLUDE_PHY_8806X) 21 #include <src/soc/phy/phy8806x.h> 22 #endif /* INCLUDE_PHY_8806X */ 23 24 #include <soc/fcmapphy.h> 25 26 27 /* 28 * Function: 29 * soc_fcmapphy_init 30 * Purpose: 31 * Initializes the FCMAP phy port. 32 * Parameters: 33 * unit - SOC Unit #. 34 * port - Port number. 35 * pc - Phy control structure 36 * Returns: 37 * SOC_E_XXX 38 */ 39 int 40 soc_fcmapphy_init(int unit, soc_port_t port, phy_ctrl_t *pc, 41 bfcmap_core_t core_type, bfcmap_dev_io_f iofn) 42 { 43 int /* ii, */ p, rv; 44 int fcmap_enable = 0; 45 46 p = SOC_FCMAP_PORTID(unit, port); 47 /* Destroy the port if it were created before. */ 48 (void)bfcmap_port_destroy(p); 49 50 fcmap_enable = soc_property_port_get(unit, port, spn_FCMAP_ENABLE, 0); 51 pc->fcmap_enable = fcmap_enable; 52 53 if (fcmap_enable) { 54 /* Create FCMAP Port */ 55 rv = bfcmap_port_create(p, core_type, pc->fcmap_dev_addr, 56 pc->fcmap_uc_dev_addr, 57 pc->fcmap_dev_port, iofn, pc->fcmap_port_cfg); 58 if (rv != BFCMAP_E_NONE) { 59 LOG_WARN(BSL_LS_SOC_COMMON, 60 (BSL_META_U(unit, 61 "soc_fcmapphy_init: " 62 "FCMAP port create failed for u=%d p=%d rv = %d\n"), 63 unit, port, rv)); 64 return SOC_E_FAIL; 65 } 66 } 67 return SOC_E_NONE; 68 } 69 /* 70 * Function: 71 * soc_fcmapphy_uninit 72 * Purpose: 73 * Uninitializes the FCMAP phy port. 74 * Parameters: 75 * unit - SOC Unit #. 76 * port - Port number. 77 * Returns: 78 * SOC_E_XXX 79 */ 80 int 81 soc_fcmapphy_uninit(int unit, soc_port_t port) 82 { 83 int p; 84 85 p = SOC_FCMAP_PORTID(unit, port); 86 /* Destroy the port if it were created before. */ 87 (void)bfcmap_port_destroy(p); 88 89 return SOC_E_NONE; 90 91 } 92 93 int 94 soc_fcmapphy_miim_read(soc_fcmap_dev_addr_t dev_addr, 95 uint32 phy_reg_addr, uint16 *data) 96 { 97 int unit, phy_id, clause45; 98 int rv = SOC_E_NONE; 99 100 /* 101 * Decode dev_addr into phyid and unit. 102 */ 103 unit = SOC_FCMAPPHY_ADDR2UNIT(dev_addr); 104 phy_id = SOC_FCMAPPHY_ADDR2MDIO(dev_addr); 105 clause45 = SOC_FCMAPPHY_ADDR_IS_CLAUSE45(dev_addr); 106 107 #ifdef BCM_ESW_SUPPORT 108 if (SOC_IS_ESW(unit)) { 109 if (clause45) { 110 rv = soc_esw_miimc45_read(unit, phy_id, 111 phy_reg_addr, data); 112 } else { 113 rv = soc_miim_read(unit, phy_id, phy_reg_addr, data); 114 } 115 } 116 #endif /* BCM_ESW_SUPPORT */ 117 118 return (rv == SOC_E_NONE) ? 0 : -1; 119 } 120 121 int 122 soc_fcmapphy_miim_write(soc_fcmap_dev_addr_t dev_addr, 123 uint32 phy_reg_addr, uint16 data) 124 { 125 int unit, phy_id, clause45; 126 int rv = SOC_E_NONE; 127 128 /* 129 * Decode dev_addr into phyid and unit. 130 */ 131 unit = SOC_FCMAPPHY_ADDR2UNIT(dev_addr); 132 phy_id = SOC_FCMAPPHY_ADDR2MDIO(dev_addr); 133 134 clause45 = SOC_FCMAPPHY_ADDR_IS_CLAUSE45(dev_addr); 135 136 #if defined (BCM_WARM_BOOT_SUPPORT) /* */ 137 if ( SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit) ) { 138 return SOC_E_NONE; 139 } 140 #endif /* BCM_WARM_BOOT_SUPPORT */ 141 142 143 #ifdef BCM_ESW_SUPPORT 144 if (SOC_IS_ESW(unit)) { 145 if (clause45) { 146 rv = soc_esw_miimc45_write(unit, phy_id, 147 phy_reg_addr, data); 148 } else { 149 rv = soc_miim_write(unit, phy_id, phy_reg_addr, data); 150 } 151 } 152 #endif /* BCM_ESW_SUPPORT */ 153 154 return (rv == SOC_E_NONE) ? 0 : -1; 155 } 156 157 158 #if defined (BCM_WARM_BOOT_SUPPORT) /* */ 159 extern int bfcmap_cli_sync_recovery_needed ; 160 161 int 162 soc_fcmapphy_blmi_enable(int enable) 163 { 164 int rv; 165 166 bfcmap_cli_sync_recovery_needed = enable ? FALSE : TRUE; 167 168 rv = blmi_io_mmi1_operational_flag_set( 169 enable ? 0 : BLMI_OP_FLAG_ACCESS_INHIBIT, 170 BLMI_OP_FLAG_ACCESS_INHIBIT); 171 172 if (rv != BFCMAP_E_NONE) { 173 LOG_WARN(BSL_LS_SOC_COMMON, 174 (BSL_META( 175 "soc_fcmapphy_blmi_enable(%d): " 176 "FAILED ! rv = %d\n"), enable, rv)); 177 return SOC_E_FAIL; 178 } 179 return SOC_E_NONE; 180 } 181 #endif /* BCM_WARM_BOOT_SUPPORT */ 182 183 184 #else 185 186 int 187 soc_fcmapphy_init(int unit, soc_port_t port, void *pc) 188 { 189 return SOC_E_NONE; 190 } 191 #endif /* INCLUDE_FCMAP */ 192