viper_diagnostics.c (8429B)
1 /* 2 * 3 * 4 * 5 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 6 * 7 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 8 */ 9 10 #include <phymod/phymod.h> 11 #include <phymod/phymod_system.h> 12 #include <phymod/phymod_diagnostics.h> 13 #include <phymod/phymod_diagnostics_dispatch.h> 14 #include <phymod/phymod_util.h> 15 #include "../tier1/viper_inc.h" 16 17 #ifdef PHYMOD_VIPER_SUPPORT 18 19 /*phymod, internal enum mappings*/ 20 STATIC 21 int _viper_prbs_poly_phymod_to_viper(phymod_prbs_poly_t phymod_poly, viper_prbs_poly_t *viper_poly) 22 { 23 switch(phymod_poly){ 24 case phymodPrbsPoly7: 25 *viper_poly = VIPER_PRBS_POLYNOMIAL_7; 26 break; 27 case phymodPrbsPoly15: 28 *viper_poly = VIPER_PRBS_POLYNOMIAL_15; 29 break; 30 case phymodPrbsPoly23: 31 *viper_poly = VIPER_PRBS_POLYNOMIAL_23; 32 break; 33 case phymodPrbsPoly31: 34 *viper_poly = VIPER_PRBS_POLYNOMIAL_31; 35 break; 36 case phymodPrbsPoly9: 37 *viper_poly = VIPER_PRBS_POLYNOMIAL_9; 38 break; 39 case phymodPrbsPoly10: 40 *viper_poly = VIPER_PRBS_POLYNOMIAL_10; 41 break; 42 case phymodPrbsPoly11: 43 *viper_poly = VIPER_PRBS_POLYNOMIAL_11; 44 break; 45 default: 46 PHYMOD_RETURN_WITH_ERR(PHYMOD_E_PARAM, (_PHYMOD_MSG("unsupported poly for viper %u"), phymod_poly)); 47 } 48 return PHYMOD_E_NONE; 49 } 50 51 STATIC 52 int _viper_prbs_poly_viper_to_phymod(viper_prbs_poly_t viper_poly, phymod_prbs_poly_t *phymod_poly) 53 { 54 switch(viper_poly){ 55 case VIPER_PRBS_POLYNOMIAL_7: 56 *phymod_poly = phymodPrbsPoly7; 57 break; 58 case VIPER_PRBS_POLYNOMIAL_15: 59 *phymod_poly = phymodPrbsPoly15; 60 break; 61 case VIPER_PRBS_POLYNOMIAL_23: 62 *phymod_poly = phymodPrbsPoly23; 63 break; 64 case VIPER_PRBS_POLYNOMIAL_31: 65 *phymod_poly = phymodPrbsPoly31; 66 break; 67 case VIPER_PRBS_POLYNOMIAL_9: 68 *phymod_poly = phymodPrbsPoly9; 69 break; 70 case VIPER_PRBS_POLYNOMIAL_10: 71 *phymod_poly = phymodPrbsPoly10; 72 break; 73 case VIPER_PRBS_POLYNOMIAL_11: 74 *phymod_poly = phymodPrbsPoly11; 75 break; 76 default: 77 PHYMOD_RETURN_WITH_ERR(PHYMOD_E_INTERNAL, (_PHYMOD_MSG("uknown poly %u"), viper_poly)); 78 } 79 return PHYMOD_E_NONE; 80 } 81 82 83 84 int viper_phy_rx_slicer_position_set(const phymod_phy_access_t* phy, uint32_t flags, const phymod_slicer_position_t* position) 85 { 86 87 88 /* Place your code here */ 89 90 91 return PHYMOD_E_NONE; 92 93 } 94 95 int viper_phy_rx_slicer_position_get(const phymod_phy_access_t* phy, uint32_t flags, phymod_slicer_position_t* position) 96 { 97 98 99 /* Place your code here */ 100 101 102 return PHYMOD_E_NONE; 103 104 } 105 106 107 int viper_phy_rx_slicer_position_max_get(const phymod_phy_access_t* phy, uint32_t flags, const phymod_slicer_position_t* position_min, const phymod_slicer_position_t* position_max) 108 { 109 110 111 /* Place your code here */ 112 113 114 return PHYMOD_E_NONE; 115 116 } 117 118 119 int viper_phy_prbs_config_set(const phymod_phy_access_t* phy, uint32_t flags , const phymod_prbs_t* prbs) 120 { 121 phymod_phy_access_t phy_copy; 122 viper_prbs_poly_t viper_poly; 123 int start_lane, num_lane; 124 int i = 0; 125 126 PHYMOD_MEMCPY(&phy_copy, phy, sizeof(phy_copy)); 127 128 /*next figure out the lane num and start_lane based on the input*/ 129 PHYMOD_IF_ERR_RETURN 130 (phymod_util_lane_config_get(&phy->access, &start_lane, &num_lane)); 131 132 PHYMOD_IF_ERR_RETURN(_viper_prbs_poly_phymod_to_viper(prbs->poly, &viper_poly)); 133 134 for (i = 0; i < num_lane; i++) { 135 phy_copy.access.lane_mask = 0x1 << (i + start_lane); 136 PHYMOD_IF_ERR_RETURN(viper_prbs_lane_inv_data_set(&phy_copy.access, num_lane, prbs->invert)); 137 PHYMOD_IF_ERR_RETURN(viper_prbs_lane_poly_set(&phy_copy.access, num_lane, viper_poly)); 138 } 139 140 return PHYMOD_E_NONE; 141 142 } 143 144 int viper_phy_prbs_config_get(const phymod_phy_access_t* phy, uint32_t flags , phymod_prbs_t* prbs) 145 { 146 phymod_phy_access_t phy_copy; 147 phymod_prbs_t config_tmp; 148 viper_prbs_poly_t viper_poly; 149 int start_lane, num_lane; 150 int i = 0; 151 152 PHYMOD_MEMCPY(&phy_copy, phy, sizeof(phy_copy)); 153 154 /*next figure out the lane num and start_lane based on the input*/ 155 PHYMOD_IF_ERR_RETURN 156 (phymod_util_lane_config_get(&phy->access, &start_lane, &num_lane)); 157 158 for (i = 0; i < num_lane; i++) { 159 PHYMOD_IF_ERR_RETURN(viper_prbs_lane_inv_data_get(&phy_copy.access, num_lane ,&config_tmp.invert)); 160 PHYMOD_IF_ERR_RETURN(viper_prbs_lane_poly_get(&phy_copy.access, num_lane, &viper_poly)); 161 PHYMOD_IF_ERR_RETURN(_viper_prbs_poly_viper_to_phymod(viper_poly, &config_tmp.poly)); 162 prbs->invert = config_tmp.invert; 163 prbs->poly = config_tmp.poly; 164 } 165 return PHYMOD_E_NONE; 166 167 } 168 169 170 int viper_phy_prbs_enable_set(const phymod_phy_access_t* phy, uint32_t flags , uint32_t enable) 171 { 172 phymod_phy_access_t phy_copy; 173 int start_lane, num_lane; 174 int i = 0; 175 176 PHYMOD_MEMCPY(&phy_copy, phy, sizeof(phy_copy)); 177 178 /*next figure out the lane num and start_lane based on the input*/ 179 PHYMOD_IF_ERR_RETURN 180 (phymod_util_lane_config_get(&phy->access, &start_lane, &num_lane)); 181 182 for (i = 0; i < num_lane; i++) { 183 PHYMOD_IF_ERR_RETURN(viper_prbs_enable_set(&phy_copy.access, num_lane, enable)); 184 } 185 return PHYMOD_E_NONE; 186 187 } 188 189 int viper_phy_prbs_enable_get(const phymod_phy_access_t* phy, uint32_t flags , uint32_t* enable) 190 { 191 phymod_phy_access_t phy_copy; 192 uint32_t enable_tmp; 193 int start_lane, num_lane; 194 int i = 0; 195 196 PHYMOD_MEMCPY(&phy_copy, phy, sizeof(phy_copy)); 197 198 /*next figure out the lane num and start_lane based on the input*/ 199 PHYMOD_IF_ERR_RETURN 200 (phymod_util_lane_config_get(&phy->access, &start_lane, &num_lane)); 201 202 for (i = 0; i < num_lane; i++) { 203 PHYMOD_IF_ERR_RETURN(viper_prbs_enable_get(&phy_copy.access, num_lane, &enable_tmp)); 204 *enable = enable_tmp; 205 } 206 return PHYMOD_E_NONE; 207 208 } 209 210 211 int viper_phy_prbs_status_get(const phymod_phy_access_t* phy, uint32_t flags, phymod_prbs_status_t* prbs_status) 212 { 213 viper_prbs_status_t status; 214 int i, start_lane, num_lane; 215 phymod_phy_access_t phy_copy; 216 217 PHYMOD_MEMCPY(&phy_copy, phy, sizeof(phy_copy)); 218 /* next figure out the lane num and start_lane based on the input */ 219 PHYMOD_IF_ERR_RETURN 220 (phymod_util_lane_config_get(&phy->access, &start_lane, &num_lane)); 221 222 for (i = 0; i < num_lane; i++) { 223 phy_copy.access.lane_mask = 0x1 << (i + start_lane); 224 PHYMOD_IF_ERR_RETURN(viper_prbs_status_get(&phy_copy.access, &status)); 225 prbs_status->prbs_lock = status.prbs_lock; 226 prbs_status->prbs_lock_loss = status.prbs_lock_loss; 227 prbs_status->error_count = status.error_count; 228 } 229 230 return PHYMOD_E_NONE; 231 } 232 233 234 int viper_phy_pattern_config_set(const phymod_phy_access_t* phy, const phymod_pattern_t* pattern) 235 { 236 237 238 /* Place your code here */ 239 240 241 return PHYMOD_E_NONE; 242 243 } 244 245 int viper_phy_pattern_config_get(const phymod_phy_access_t* phy, phymod_pattern_t* pattern) 246 { 247 248 249 /* Place your code here */ 250 251 252 return PHYMOD_E_NONE; 253 254 } 255 256 257 int viper_phy_pattern_enable_set(const phymod_phy_access_t* phy, uint32_t enable, const phymod_pattern_t* pattern) 258 { 259 260 261 /* Place your code here */ 262 263 264 return PHYMOD_E_NONE; 265 266 } 267 268 int viper_phy_pattern_enable_get(const phymod_phy_access_t* phy, uint32_t* enable) 269 { 270 271 272 /* Place your code here */ 273 274 275 return PHYMOD_E_NONE; 276 277 } 278 279 280 int viper_core_diagnostics_get(const phymod_core_access_t* core, phymod_core_diagnostics_t* diag) 281 { 282 283 284 /* Place your code here */ 285 286 287 return PHYMOD_E_NONE; 288 289 } 290 291 292 int viper_phy_diagnostics_get(const phymod_phy_access_t* phy, phymod_phy_diagnostics_t* diag) 293 { 294 295 296 /* Place your code here */ 297 298 299 return PHYMOD_E_NONE; 300 301 } 302 303 304 int viper_phy_pmd_info_dump(const phymod_phy_access_t* phy, const char* type) 305 { 306 return PHYMOD_E_NONE; 307 308 } 309 310 311 int viper_phy_pcs_info_dump(const phymod_phy_access_t* phy, const char* type) 312 { 313 314 phymod_phy_access_t phy_copy; 315 316 PHYMOD_MEMCPY(&phy_copy, phy, sizeof(phy_copy)); 317 PHYMOD_IF_ERR_RETURN(viper_diag_disp(&phy_copy.access, (char*)type)); 318 319 return PHYMOD_E_NONE; 320 321 } 322 323 324 #endif /* PHYMOD_VIPER_SUPPORT */