timesync.c (5643B)
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 port control API 8 */ 9 #include <shared/bsl.h> 10 11 #include <sal/core/libc.h> 12 #include <shared/alloc.h> 13 #include <sal/core/spl.h> 14 15 #include <soc/drv.h> 16 #include <soc/phy/drv.h> 17 #include <soc/debug.h> 18 #include <soc/timesync.h> 19 20 /* 21 * Function: 22 * soc_port_phy_timesync_config_set 23 * Purpose: 24 * Update PHY's phy_timesync config 25 * Parameters: 26 * unit - SOC Unit #. 27 * port - Port number. 28 * conf - Config 29 * Returns: 30 * SOC_E_XXX 31 */ 32 int 33 soc_port_phy_timesync_config_set(int unit, soc_port_t port, soc_port_phy_timesync_config_t *conf) 34 { 35 int rv; 36 phy_ctrl_t *int_pc; 37 phy_ctrl_t *ext_pc; 38 phy_driver_t *pd = NULL; 39 40 rv = SOC_E_UNAVAIL; 41 int_pc = INT_PHY_SW_STATE(unit, port); 42 ext_pc = EXT_PHY_SW_STATE(unit, port); 43 44 if ((NULL == (ext_pc)) && (NULL == (int_pc))) { 45 return SOC_E_INIT; 46 } 47 48 if (NULL != ext_pc) { 49 pd = ext_pc->pd; 50 } else { 51 pd = int_pc->pd; 52 } 53 54 INT_MCU_LOCK(unit); 55 rv = PHY_TIMESYNC_CONFIG_SET(pd, unit, port, conf); 56 INT_MCU_UNLOCK(unit); 57 58 if (SOC_FAILURE(rv)) { 59 LOG_WARN(BSL_LS_SOC_COMMON, 60 (BSL_META_U(unit, 61 "soc_port_phy_timesync_config_set failed %d\n"), rv)); 62 } 63 return rv; 64 } 65 66 /* 67 * Function: 68 * soc_port_phy_timesync_config_get 69 * Purpose: 70 * Retrive PHY's phy_timesync config 71 * Parameters: 72 * unit - SOC Unit #. 73 * port - Port number. 74 * conf - Config 75 * Returns: 76 * SOC_E_XXX 77 */ 78 int 79 soc_port_phy_timesync_config_get(int unit, soc_port_t port, soc_port_phy_timesync_config_t *conf) 80 { 81 int rv; 82 phy_ctrl_t *int_pc; 83 phy_ctrl_t *ext_pc; 84 phy_driver_t *pd = NULL; 85 86 rv = SOC_E_UNAVAIL; 87 88 int_pc = INT_PHY_SW_STATE(unit, port); 89 ext_pc = EXT_PHY_SW_STATE(unit, port); 90 if ((NULL == (ext_pc)) && (NULL == (int_pc))) { 91 return SOC_E_INIT; 92 } 93 94 if (NULL != ext_pc) { 95 pd = ext_pc->pd; 96 } else { 97 pd = int_pc->pd; 98 } 99 100 INT_MCU_LOCK(unit); 101 rv = PHY_TIMESYNC_CONFIG_GET(pd, unit, port, conf); 102 INT_MCU_UNLOCK(unit); 103 104 if (SOC_FAILURE(rv)) { 105 LOG_WARN(BSL_LS_SOC_COMMON, 106 (BSL_META_U(unit, 107 "soc_port_phy_timesync_config_get failed %d\n"), rv)); 108 } 109 return rv; 110 } 111 112 /* 113 * Function: 114 * soc_port_control_phy_timesync_set 115 * Purpose: 116 * Update PHY's phy_timesync parameter 117 * Parameters: 118 * unit - SOC Unit #. 119 * port - Port number. 120 * type - operation 121 * value - parameter 122 * Returns: 123 * SOC_E_XXX 124 */ 125 int 126 soc_port_control_phy_timesync_set(int unit, soc_port_t port, soc_port_control_phy_timesync_t type, uint64 value) 127 { 128 int rv; 129 phy_ctrl_t *int_pc; 130 phy_ctrl_t *ext_pc; 131 phy_driver_t *pd = NULL; 132 133 rv = SOC_E_UNAVAIL; 134 135 int_pc = INT_PHY_SW_STATE(unit, port); 136 ext_pc = EXT_PHY_SW_STATE(unit, port); 137 if ((NULL == (ext_pc)) && (NULL == (int_pc))) { 138 return SOC_E_INIT; 139 } 140 141 if (NULL != ext_pc) { 142 pd = ext_pc->pd; 143 } else { 144 pd = int_pc->pd; 145 } 146 147 INT_MCU_LOCK(unit); 148 rv = PHY_TIMESYNC_CONTROL_SET(pd, unit, port, type, value); 149 INT_MCU_UNLOCK(unit); 150 151 if (SOC_FAILURE(rv)) { 152 LOG_WARN(BSL_LS_SOC_COMMON, 153 (BSL_META_U(unit, 154 "soc_port_control_phy_timesync_set failed %d\n"), rv)); 155 } 156 return rv; 157 } 158 159 /* 160 * Function: 161 * soc_port_control_phy_timesync_get 162 * Purpose: 163 * Retrive PHY's phy_timesync parameter 164 * Parameters: 165 * unit - SOC Unit #. 166 * port - Port number. 167 * type - operation 168 * value - *parameter 169 * Returns: 170 * SOC_E_XXX 171 */ 172 int 173 soc_port_control_phy_timesync_get(int unit, soc_port_t port, soc_port_control_phy_timesync_t type, uint64 *value) 174 { 175 int rv; 176 phy_ctrl_t *int_pc; 177 phy_ctrl_t *ext_pc; 178 phy_driver_t *pd = NULL; 179 180 rv = SOC_E_UNAVAIL; 181 182 int_pc = INT_PHY_SW_STATE(unit, port); 183 ext_pc = EXT_PHY_SW_STATE(unit, port); 184 if ((NULL == (ext_pc)) && (NULL == (int_pc))) { 185 return SOC_E_INIT; 186 } 187 188 if (NULL != ext_pc) { 189 pd = ext_pc->pd; 190 } else { 191 pd = int_pc->pd; 192 } 193 194 INT_MCU_LOCK(unit); 195 rv = PHY_TIMESYNC_CONTROL_GET(pd, unit, port, type, value); 196 INT_MCU_UNLOCK(unit); 197 198 if (SOC_FAILURE(rv)) { 199 LOG_WARN(BSL_LS_SOC_COMMON, 200 (BSL_META_U(unit, 201 "soc_port_control_phy_timesync_get failed %d\n"), rv)); 202 } 203 return rv; 204 } 205 206 /* 207 * Function: 208 * soc_port_phy_timesync_enhanced_capture_get 209 * Purpose: 210 * Retrive PHY's phy_timesync parameter 211 * Parameters: 212 * unit - SOC Unit #. 213 * port - Port number. 214 * type - operation 215 * value - *parameter 216 * Returns: 217 * SOC_E_XXX 218 */ 219 int 220 soc_port_phy_timesync_enhanced_capture_get(int unit, soc_port_t port, soc_port_phy_timesync_enhanced_capture_t *value) 221 { 222 int rv; 223 phy_ctrl_t *pc; 224 225 rv = SOC_E_UNAVAIL; 226 227 pc = EXT_PHY_SW_STATE(unit, port); 228 229 if (NULL != pc) { 230 INT_MCU_LOCK(unit); 231 rv = PHY_TIMESYNC_ENHANCED_CAPTURE_GET(pc->pd, unit, port, value); 232 INT_MCU_UNLOCK(unit); 233 } 234 235 if (SOC_FAILURE(rv)) { 236 LOG_WARN(BSL_LS_SOC_COMMON, 237 (BSL_META_U(unit, 238 "soc_port_phy_timesync_enhanced_capture_get failed %d\n"), rv)); 239 } 240 return rv; 241 }