2 * Copyright (C) Marvell International Ltd. and its affiliates
4 * SPDX-License-Identifier: GPL-2.0
11 #include <asm/arch/cpu.h>
12 #include <asm/arch/soc.h>
14 #include "high_speed_topology_spec.h"
15 #include "sys_env_lib.h"
17 #ifdef CONFIG_CUSTOMER_BOARD_SUPPORT
19 * This is an example implementation for this custom board
22 static struct serdes_map custom_board_topology_config
[] = {
23 /* Customer Board Topology - reference from Marvell DB-GP board */
24 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
25 {SATA0
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
26 {SATA1
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
27 {SATA3
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
28 {SATA2
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
29 {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
32 int hws_board_topology_load(struct serdes_map
*serdes_map_array
)
34 serdes_map_array
= custom_board_topology_config
;
38 load_topology_func_ptr load_topology_func_arr
[] = {
39 load_topology_rd
, /* RD NAS */
40 load_topology_db
, /* 6820 DB-BP (A38x) */
41 load_topology_rd
, /* RD AP */
42 load_topology_db_ap
, /* DB AP */
43 load_topology_db_gp
, /* DB GP */
44 load_topology_db_381
, /* 6821 DB-BP (A381) */
45 load_topology_db_amc
, /* DB-AMC */
48 /*****************************************/
49 /** Load topology - Marvell 380 DB - BP **/
50 /*****************************************/
51 /* Configuration options */
52 struct serdes_map db_config_default
[MAX_SERDES_LANES
] = {
53 {SATA0
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
54 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
55 {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
56 {SATA3
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
57 {USB3_HOST0
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
58 {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
61 struct serdes_map db_config_slm1363_c
[MAX_SERDES_LANES
] = {
62 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
63 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
64 {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
65 {PEX3
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
66 {SATA2
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
67 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
70 struct serdes_map db_config_slm1363_d
[MAX_SERDES_LANES
] = {
71 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
72 {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
73 {PEX2
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
74 {PEX3
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
75 {USB3_HOST0
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
76 {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
79 struct serdes_map db_config_slm1363_e
[MAX_SERDES_LANES
] = {
80 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
81 {USB3_HOST0
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
82 {SATA1
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
83 {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
84 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
85 {SATA2
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
88 struct serdes_map db_config_slm1363_f
[MAX_SERDES_LANES
] = {
89 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
90 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
91 {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
92 {PEX3
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
93 {SATA2
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
94 {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
97 struct serdes_map db_config_slm1364_d
[MAX_SERDES_LANES
] = {
98 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
99 {SGMII0
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
100 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
101 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
102 {SGMII1
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
103 {SGMII2
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
106 struct serdes_map db_config_slm1364_e
[MAX_SERDES_LANES
] = {
107 {SGMII0
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
108 {SGMII1
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
109 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
110 {SGMII2
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
111 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
112 {PEX2
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0}
115 struct serdes_map db_config_slm1364_f
[MAX_SERDES_LANES
] = {
116 {SGMII0
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
117 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
118 {SGMII1
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
119 {SGMII2
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
120 {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0, 0},
121 {PEX2
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0}
124 /*************************************************************************/
125 /** The following structs are mapping for DB board 'SatR' configuration **/
126 /*************************************************************************/
127 struct serdes_map db_satr_config_lane1
[SATR_DB_LANE1_MAX_OPTIONS
] = {
128 /* 0 */ {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0,
130 /* 1 */ {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
131 /* 2 */ {SATA0
, SERDES_SPEED_3_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
132 /* 3 */ {SGMII0
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0,
134 /* 4 */ {SGMII1
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0,
136 /* 5 */ {USB3_HOST0
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0,
138 /* 6 */ {QSGMII
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
141 struct serdes_map db_satr_config_lane2
[SATR_DB_LANE2_MAX_OPTIONS
] = {
142 /* 0 */ {DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
, 0,
144 /* 1 */ {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
145 /* 2 */ {SATA1
, SERDES_SPEED_3_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
146 /* 3 */ {SGMII1
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0,
150 /*******************************************************/
151 /* Configuration options DB ****************************/
152 /* mapping from TWSI address data to configuration map */
153 /*******************************************************/
154 struct serdes_map
*topology_config_db
[] = {
165 /*************************************/
166 /** Load topology - Marvell DB - AP **/
167 /*************************************/
168 struct serdes_map db_ap_config_default
[MAX_SERDES_LANES
] = {
169 /* 0 */ {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
170 /* 1 */ {SGMII1
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0,
172 /* 2 */ {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
173 /* 3 */ {SGMII2
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0,
175 /* 4 */ {USB3_HOST0
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0,
177 /* 5 */ {PEX2
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0}
180 /*************************************/
181 /** Load topology - Marvell DB - GP **/
182 /*************************************/
183 struct serdes_map db_gp_config_default
[MAX_SERDES_LANES
] = {
184 /* 0 */ {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
185 /* 1 */ {SATA0
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
186 /* 2 */ {SATA1
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
187 /* 3 */ {SATA3
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
188 /* 4 */ {SATA2
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 0, 0},
189 /* 5 */ {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0,
193 struct serdes_map db_amc_config_default
[MAX_SERDES_LANES
] = {
194 /* 0 */ {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
195 /* 1 */ {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
196 /* 2 */ {PEX2
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
197 /* 3 */ {PEX3
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X4
, 0, 0},
198 /* 4 */ {SGMII1
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0,
200 /* 5 */ {SGMII2
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 0,
204 /*****************************************/
205 /** Load topology - Marvell 381 DB - BP **/
206 /*****************************************/
207 /* Configuration options */
208 struct serdes_map db381_config_default
[MAX_SERDES_LANES
] = {
209 {SATA0
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 1, 1},
210 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
211 {PEX1
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 0, 0},
212 {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 0, 0}
215 struct serdes_map db_config_slm1427
[MAX_SERDES_LANES
] = {
216 {SATA0
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 1, 1},
217 {PEX0
, SERDES_SPEED_5_GBPS
, PEX_ROOT_COMPLEX_X1
, 1, 1},
218 {SATA1
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 1, 1},
219 {USB3_HOST1
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 1, 1}
222 struct serdes_map db_config_slm1426
[MAX_SERDES_LANES
] = {
223 {SATA0
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 1, 1},
224 {USB3_HOST0
, SERDES_SPEED_5_GBPS
, SERDES_DEFAULT_MODE
, 1, 1},
225 {SATA1
, SERDES_SPEED_3_GBPS
, SERDES_DEFAULT_MODE
, 1, 1},
226 {SGMII2
, SERDES_SPEED_3_125_GBPS
, SERDES_DEFAULT_MODE
, 1, 1}
230 * this array must be aligned with enum topology_config_db381 enum,
231 * every update to this array requires update to enum topology_config_db381
234 struct serdes_map
*topology_config_db_381
[] = {
237 db381_config_default
,
240 u8
topology_config_db_mode_get(void)
244 DEBUG_INIT_FULL_S("\n### topology_config_db_mode_get ###\n");
246 /* Default - return DB_CONFIG_DEFAULT */
248 if (!i2c_read(DB_GET_MODE_SLM1363_ADDR
, 0, 1, &mode
, 1)) {
249 switch (mode
& 0xf) {
251 DEBUG_INIT_S("\nInit DB board SLM 1363 C topology\n");
252 return DB_CONFIG_SLM1363_C
;
254 DEBUG_INIT_S("\nInit DB board SLM 1363 D topology\n");
255 return DB_CONFIG_SLM1363_D
;
257 DEBUG_INIT_S("\nInit DB board SLM 1363 E topology\n");
258 return DB_CONFIG_SLM1363_E
;
260 DEBUG_INIT_S("\nInit DB board SLM 1363 F topology\n");
261 return DB_CONFIG_SLM1363_F
;
262 default: /* not the right module */
268 if (i2c_read(DB_GET_MODE_SLM1364_ADDR
, 0, 1, &mode
, 1)) {
269 DEBUG_INIT_S("\nInit DB board default topology\n");
270 return DB_CONFIG_DEFAULT
;
273 switch (mode
& 0xf) {
275 DEBUG_INIT_S("\nInit DB board SLM 1364 D topology\n");
276 return DB_CONFIG_SLM1364_D
;
278 DEBUG_INIT_S("\nInit DB board SLM 1364 E topology\n");
279 return DB_CONFIG_SLM1364_E
;
281 DEBUG_INIT_S("\nInit DB board SLM 1364 F topology\n");
282 return DB_CONFIG_SLM1364_F
;
283 default: /* Default configuration */
284 DEBUG_INIT_S("\nInit DB board default topology\n");
285 return DB_CONFIG_DEFAULT
;
289 u8
topology_config_db_381_mode_get(void)
293 DEBUG_INIT_FULL_S("\n### topology_config_db_381_mode_get ###\n");
295 if (!i2c_read(DB381_GET_MODE_SLM1426_1427_ADDR
, 0, 2, &mode
, 1)) {
296 switch (mode
& 0xf) {
298 DEBUG_INIT_S("\nInit DB-381 board SLM 1427 topology\n");
299 return DB_CONFIG_SLM1427
;
301 DEBUG_INIT_S("\nInit DB-381 board SLM 1426 topology\n");
302 return DB_CONFIG_SLM1426
;
303 default: /* not the right module */
308 /* in case not detected any supported module, use default topology */
309 DEBUG_INIT_S("\nInit DB-381 board default topology\n");
310 return DB_381_CONFIG_DEFAULT
;
314 * Read SatR field 'sgmiispeed' and update lane topology SGMII entries
317 int update_topology_sgmii_speed(struct serdes_map
*serdes_map_array
)
319 u32 serdes_type
, lane_num
;
322 /* Update SGMII speed settings by 'sgmiispeed' SatR value */
323 for (lane_num
= 0; lane_num
< hws_serdes_get_max_lane(); lane_num
++) {
324 serdes_type
= serdes_map_array
[lane_num
].serdes_type
;
325 /*Read SatR configuration for SGMII speed */
326 if ((serdes_type
== SGMII0
) || (serdes_type
== SGMII1
) ||
327 (serdes_type
== SGMII2
)) {
328 /* Read SatR 'sgmiispeed' value */
329 if (i2c_read(EEPROM_I2C_ADDR
, 0, 2, &config_val
, 1)) {
330 printf("%s: TWSI Read of 'sgmiispeed' failed\n",
335 if (0 == (config_val
& 0x40)) {
336 serdes_map_array
[lane_num
].serdes_speed
=
337 SERDES_SPEED_1_25_GBPS
;
339 serdes_map_array
[lane_num
].serdes_speed
=
340 SERDES_SPEED_3_125_GBPS
;
347 struct serdes_map default_lane
= {
348 DEFAULT_SERDES
, LAST_SERDES_SPEED
, SERDES_DEFAULT_MODE
350 int is_custom_topology
= 0; /* indicate user of non-default topology */
353 * Read SatR fields (dbserdes1/2 , gpserdes1/2/5) and update lane
354 * topology accordingly
356 int update_topology_satr(struct serdes_map
*serdes_map_array
)
358 u8 config_val
, lane_select
, i
;
359 u32 board_id
= mv_board_id_get();
362 case DB_68XX_ID
: /* read 'dbserdes1' & 'dbserdes2' */
364 if (i2c_read(EEPROM_I2C_ADDR
, 1, 2, &config_val
, 1)) {
365 printf("%s: TWSI Read of 'dbserdes1/2' failed\n",
371 lane_select
= (config_val
& SATR_DB_LANE1_CFG_MASK
) >>
372 SATR_DB_LANE1_CFG_OFFSET
;
373 if (lane_select
>= SATR_DB_LANE1_MAX_OPTIONS
) {
374 printf("\n\%s: Error: invalid value for SatR field 'dbserdes1' (%x)\n",
375 __func__
, lane_select
);
376 printf("\t_skipping Topology update (run 'SatR write default')\n");
381 * If modified default serdes_type for lane#1, update
382 * topology and mark it as custom
384 if (serdes_map_array
[1].serdes_type
!=
385 db_satr_config_lane1
[lane_select
].serdes_type
) {
386 serdes_map_array
[1] = db_satr_config_lane1
[lane_select
];
387 is_custom_topology
= 1;
388 /* DB 381/2 board has inverted SerDes polarity */
389 if (board_id
== DB_BP_6821_ID
)
390 serdes_map_array
[1].swap_rx
=
391 serdes_map_array
[1].swap_tx
= 1;
395 lane_select
= (config_val
& SATR_DB_LANE2_CFG_MASK
) >>
396 SATR_DB_LANE2_CFG_OFFSET
;
397 if (lane_select
>= SATR_DB_LANE2_MAX_OPTIONS
) {
398 printf("\n\%s: Error: invalid value for SatR field 'dbserdes2' (%x)\n",
399 __func__
, lane_select
);
400 printf("\t_skipping Topology update (run 'SatR write default')\n");
405 * If modified default serdes_type for lane@2, update
406 * topology and mark it as custom
408 if (serdes_map_array
[2].serdes_type
!=
409 db_satr_config_lane2
[lane_select
].serdes_type
) {
410 serdes_map_array
[2] = db_satr_config_lane2
[lane_select
];
411 is_custom_topology
= 1;
412 /* DB 381/2 board has inverted SerDes polarity */
413 if (board_id
== DB_BP_6821_ID
)
414 serdes_map_array
[2].swap_rx
=
415 serdes_map_array
[2].swap_tx
= 1;
418 if (is_custom_topology
== 1) {
420 * Check for conflicts with detected lane #1 and
421 * lane #2 (Disable conflicted lanes)
423 for (i
= 0; i
< hws_serdes_get_max_lane(); i
++) {
424 if (i
!= 1 && serdes_map_array
[1].serdes_type
==
425 serdes_map_array
[i
].serdes_type
) {
426 printf("\t_lane #%d Type conflicts with Lane #1 (Lane #%d disabled)\n",
428 serdes_map_array
[i
] =
429 db_satr_config_lane1
[0];
433 serdes_map_array
[2].serdes_type
==
434 serdes_map_array
[i
].serdes_type
) {
435 printf("\t_lane #%d Type conflicts with Lane #2 (Lane #%d disabled)\n",
437 serdes_map_array
[i
] =
438 db_satr_config_lane1
[0];
443 break; /* case DB_68XX_ID */
444 case DB_GP_68XX_ID
: /* read 'gpserdes1' & 'gpserdes2' */
445 if (i2c_read(EEPROM_I2C_ADDR
, 2, 2, &config_val
, 1)) {
446 printf("%s: TWSI Read of 'gpserdes1/2' failed\n",
453 * lane_select = 0 --> SATA0,
454 * lane_select = 1 --> PCIe0 (mini PCIe)
456 lane_select
= (config_val
& SATR_GP_LANE1_CFG_MASK
) >>
457 SATR_GP_LANE1_CFG_OFFSET
;
458 if (lane_select
== 1) {
459 serdes_map_array
[1].serdes_mode
= PEX0
;
460 serdes_map_array
[1].serdes_speed
= SERDES_SPEED_5_GBPS
;
461 serdes_map_array
[1].serdes_type
= PEX_ROOT_COMPLEX_X1
;
463 * If lane 1 is set to PCIe0 --> disable PCIe0
466 serdes_map_array
[0] = default_lane
;
467 /* indicate user of non-default topology */
468 is_custom_topology
= 1;
470 printf("Lane 1 detection: %s\n",
471 lane_select
? "PCIe0 (mini PCIe)" : "SATA0");
475 * lane_select = 0 --> SATA1,
476 * lane_select = 1 --> PCIe1 (mini PCIe)
478 lane_select
= (config_val
& SATR_GP_LANE2_CFG_MASK
) >>
479 SATR_GP_LANE2_CFG_OFFSET
;
480 if (lane_select
== 1) {
481 serdes_map_array
[2].serdes_type
= PEX1
;
482 serdes_map_array
[2].serdes_speed
= SERDES_SPEED_5_GBPS
;
483 serdes_map_array
[2].serdes_mode
= PEX_ROOT_COMPLEX_X1
;
484 /* indicate user of non-default topology */
485 is_custom_topology
= 1;
487 printf("Lane 2 detection: %s\n",
488 lane_select
? "PCIe1 (mini PCIe)" : "SATA1");
489 break; /* case DB_GP_68XX_ID */
492 if (is_custom_topology
)
493 printf("\nDetected custom SerDes topology (to restore default run 'SatR write default')\n\n");
499 * hws_update_device_toplogy
500 * DESCRIPTION: Update the default board topology for specific device Id
502 * topology_config_ptr - pointer to the Serdes mapping
503 * topology_mode - topology mode (index)
506 * MV_OK - if updating the board topology success
507 * MV_BAD_PARAM - if the input parameter is wrong
509 int hws_update_device_toplogy(struct serdes_map
*topology_config_ptr
,
510 enum topology_config_db topology_mode
)
512 u32 dev_id
= sys_env_device_id_get();
513 u32 board_id
= mv_board_id_get();
515 switch (topology_mode
) {
516 case DB_CONFIG_DEFAULT
:
520 * DB-AP : default for Lane3=SGMII2 -->
521 * 6810 supports only 2 SGMII interfaces:
524 if (board_id
== DB_AP_68XX_ID
) {
525 printf("Device 6810 supports only 2 SGMII interfaces: SGMII-2 @ lane3 disabled\n");
526 topology_config_ptr
[3] = default_lane
;
530 * 6810 has only 4 SerDes and the forth one is
531 * Serdes number 5 (i.e. Serdes 4 is not connected),
532 * therefore we need to copy SerDes 5 configuration
535 printf("Device 6810 does not supports SerDes Lane #4: replaced topology entry with lane #5\n");
536 topology_config_ptr
[4] = topology_config_ptr
[5];
539 * No break between cases since the 1st
540 * 6820 limitation apply on 6810
544 * DB-GP & DB-BP: default for Lane3=SATA3 -->
545 * 6810/20 supports only 2 SATA interfaces:
548 if ((board_id
== DB_68XX_ID
) ||
549 (board_id
== DB_GP_68XX_ID
)) {
550 printf("Device 6810/20 supports only 2 SATA interfaces: SATA Port 3 @ lane3 disabled\n");
551 topology_config_ptr
[3] = default_lane
;
554 * DB-GP on 6820 only: default for Lane4=SATA2
555 * --> 6820 supports only 2 SATA interfaces:
558 if (board_id
== DB_GP_68XX_ID
&& dev_id
== MV_6820
) {
559 printf("Device 6820 supports only 2 SATA interfaces: SATA Port 2 @ lane4 disabled\n");
560 topology_config_ptr
[4] = default_lane
;
569 printf("sys_env_update_device_toplogy: selected topology is not supported by this routine\n");
576 int load_topology_db_381(struct serdes_map
*serdes_map_array
)
580 struct serdes_map
*topology_config_ptr
;
582 u8 usb3_host0_or_device
= 0, usb3_host1_or_device
= 0;
584 printf("\nInitialize DB-88F6821-BP board topology\n");
586 /* Getting the relevant topology mode (index) */
587 topology_mode
= topology_config_db_381_mode_get();
588 topology_config_ptr
= topology_config_db_381
[topology_mode
];
590 /* Read USB3.0 mode: HOST/DEVICE */
591 if (load_topology_usb_mode_get(&twsi_data
) == MV_OK
) {
592 usb3_host0_or_device
= (twsi_data
& 0x1);
593 /* Only one USB3 device is enabled */
594 if (usb3_host0_or_device
== 0)
595 usb3_host1_or_device
= ((twsi_data
>> 1) & 0x1);
598 /* Updating the topology map */
599 for (lane_num
= 0; lane_num
< hws_serdes_get_max_lane(); lane_num
++) {
600 serdes_map_array
[lane_num
].serdes_mode
=
601 topology_config_ptr
[lane_num
].serdes_mode
;
602 serdes_map_array
[lane_num
].serdes_speed
=
603 topology_config_ptr
[lane_num
].serdes_speed
;
604 serdes_map_array
[lane_num
].serdes_type
=
605 topology_config_ptr
[lane_num
].serdes_type
;
606 serdes_map_array
[lane_num
].swap_rx
=
607 topology_config_ptr
[lane_num
].swap_rx
;
608 serdes_map_array
[lane_num
].swap_tx
=
609 topology_config_ptr
[lane_num
].swap_tx
;
611 /* Update USB3 device if needed */
612 if (usb3_host0_or_device
== 1 &&
613 serdes_map_array
[lane_num
].serdes_type
== USB3_HOST0
)
614 serdes_map_array
[lane_num
].serdes_type
= USB3_DEVICE
;
616 if (usb3_host1_or_device
== 1 &&
617 serdes_map_array
[lane_num
].serdes_type
== USB3_HOST1
)
618 serdes_map_array
[lane_num
].serdes_type
= USB3_DEVICE
;
621 /* If not detected any SerDes Site module, read 'SatR' lane setup */
622 if (topology_mode
== DB_381_CONFIG_DEFAULT
)
623 update_topology_satr(serdes_map_array
);
625 /* update 'sgmiispeed' settings */
626 update_topology_sgmii_speed(serdes_map_array
);
631 int load_topology_db(struct serdes_map
*serdes_map_array
)
635 struct serdes_map
*topology_config_ptr
;
637 u8 usb3_host0_or_device
= 0, usb3_host1_or_device
= 0;
639 printf("\nInitialize DB-88F6820-BP board topology\n");
641 /* Getting the relevant topology mode (index) */
642 topology_mode
= topology_config_db_mode_get();
644 if (topology_mode
== DB_NO_TOPOLOGY
)
645 topology_mode
= DB_CONFIG_DEFAULT
;
647 topology_config_ptr
= topology_config_db
[topology_mode
];
649 /* Update the default board topology device flavours */
650 CHECK_STATUS(hws_update_device_toplogy
651 (topology_config_ptr
, topology_mode
));
653 /* Read USB3.0 mode: HOST/DEVICE */
654 if (load_topology_usb_mode_get(&twsi_data
) == MV_OK
) {
655 usb3_host0_or_device
= (twsi_data
& 0x1);
656 /* Only one USB3 device is enabled */
657 if (usb3_host0_or_device
== 0)
658 usb3_host1_or_device
= ((twsi_data
>> 1) & 0x1);
661 /* Updating the topology map */
662 for (lane_num
= 0; lane_num
< hws_serdes_get_max_lane(); lane_num
++) {
663 serdes_map_array
[lane_num
].serdes_mode
=
664 topology_config_ptr
[lane_num
].serdes_mode
;
665 serdes_map_array
[lane_num
].serdes_speed
=
666 topology_config_ptr
[lane_num
].serdes_speed
;
667 serdes_map_array
[lane_num
].serdes_type
=
668 topology_config_ptr
[lane_num
].serdes_type
;
669 serdes_map_array
[lane_num
].swap_rx
=
670 topology_config_ptr
[lane_num
].swap_rx
;
671 serdes_map_array
[lane_num
].swap_tx
=
672 topology_config_ptr
[lane_num
].swap_tx
;
675 * Update USB3 device if needed - relevant for
679 if ((serdes_map_array
[lane_num
].serdes_type
==
680 USB3_HOST0
) && (usb3_host0_or_device
== 1))
681 serdes_map_array
[lane_num
].serdes_type
=
684 if ((serdes_map_array
[lane_num
].serdes_type
==
685 USB3_HOST1
) && (usb3_host1_or_device
== 1))
686 serdes_map_array
[lane_num
].serdes_type
=
691 /* If not detected any SerDes Site module, read 'SatR' lane setup */
692 if (topology_mode
== DB_CONFIG_DEFAULT
)
693 update_topology_satr(serdes_map_array
);
695 /* update 'sgmiispeed' settings */
696 update_topology_sgmii_speed(serdes_map_array
);
701 int load_topology_db_ap(struct serdes_map
*serdes_map_array
)
704 struct serdes_map
*topology_config_ptr
;
706 DEBUG_INIT_FULL_S("\n### load_topology_db_ap ###\n");
708 printf("\nInitialize DB-AP board topology\n");
709 topology_config_ptr
= db_ap_config_default
;
711 /* Update the default board topology device flavours */
712 CHECK_STATUS(hws_update_device_toplogy
713 (topology_config_ptr
, DB_CONFIG_DEFAULT
));
715 /* Updating the topology map */
716 for (lane_num
= 0; lane_num
< hws_serdes_get_max_lane(); lane_num
++) {
717 serdes_map_array
[lane_num
].serdes_mode
=
718 topology_config_ptr
[lane_num
].serdes_mode
;
719 serdes_map_array
[lane_num
].serdes_speed
=
720 topology_config_ptr
[lane_num
].serdes_speed
;
721 serdes_map_array
[lane_num
].serdes_type
=
722 topology_config_ptr
[lane_num
].serdes_type
;
723 serdes_map_array
[lane_num
].swap_rx
=
724 topology_config_ptr
[lane_num
].swap_rx
;
725 serdes_map_array
[lane_num
].swap_tx
=
726 topology_config_ptr
[lane_num
].swap_tx
;
729 update_topology_sgmii_speed(serdes_map_array
);
734 int load_topology_db_gp(struct serdes_map
*serdes_map_array
)
737 struct serdes_map
*topology_config_ptr
;
740 DEBUG_INIT_FULL_S("\n### load_topology_db_gp ###\n");
742 topology_config_ptr
= db_gp_config_default
;
744 printf("\nInitialize DB-GP board topology\n");
746 /* check S@R: if lane 5 is USB3 or SGMII */
747 if (load_topology_rd_sgmii_usb(&is_sgmii
) != MV_OK
)
748 printf("%s: TWSI Read failed - Loading Default Topology\n",
751 topology_config_ptr
[5].serdes_type
=
752 is_sgmii
? SGMII2
: USB3_HOST1
;
753 topology_config_ptr
[5].serdes_speed
= is_sgmii
?
754 SERDES_SPEED_3_125_GBPS
: SERDES_SPEED_5_GBPS
;
755 topology_config_ptr
[5].serdes_mode
= SERDES_DEFAULT_MODE
;
758 /* Update the default board topology device flavours */
759 CHECK_STATUS(hws_update_device_toplogy
760 (topology_config_ptr
, DB_CONFIG_DEFAULT
));
762 /* Updating the topology map */
763 for (lane_num
= 0; lane_num
< hws_serdes_get_max_lane(); lane_num
++) {
764 serdes_map_array
[lane_num
].serdes_mode
=
765 topology_config_ptr
[lane_num
].serdes_mode
;
766 serdes_map_array
[lane_num
].serdes_speed
=
767 topology_config_ptr
[lane_num
].serdes_speed
;
768 serdes_map_array
[lane_num
].serdes_type
=
769 topology_config_ptr
[lane_num
].serdes_type
;
770 serdes_map_array
[lane_num
].swap_rx
=
771 topology_config_ptr
[lane_num
].swap_rx
;
772 serdes_map_array
[lane_num
].swap_tx
=
773 topology_config_ptr
[lane_num
].swap_tx
;
777 * Update 'gpserdes1/2/3' lane configuration , and 'sgmiispeed'
780 update_topology_satr(serdes_map_array
);
781 update_topology_sgmii_speed(serdes_map_array
);
786 int load_topology_db_amc(struct serdes_map
*serdes_map_array
)
789 struct serdes_map
*topology_config_ptr
;
791 DEBUG_INIT_FULL_S("\n### load_topology_db_amc ###\n");
793 printf("\nInitialize DB-AMC board topology\n");
794 topology_config_ptr
= db_amc_config_default
;
796 /* Update the default board topology device flavours */
797 CHECK_STATUS(hws_update_device_toplogy
798 (topology_config_ptr
, DB_CONFIG_DEFAULT
));
800 /* Updating the topology map */
801 for (lane_num
= 0; lane_num
< hws_serdes_get_max_lane(); lane_num
++) {
802 serdes_map_array
[lane_num
].serdes_mode
=
803 topology_config_ptr
[lane_num
].serdes_mode
;
804 serdes_map_array
[lane_num
].serdes_speed
=
805 topology_config_ptr
[lane_num
].serdes_speed
;
806 serdes_map_array
[lane_num
].serdes_type
=
807 topology_config_ptr
[lane_num
].serdes_type
;
808 serdes_map_array
[lane_num
].swap_rx
=
809 topology_config_ptr
[lane_num
].swap_rx
;
810 serdes_map_array
[lane_num
].swap_tx
=
811 topology_config_ptr
[lane_num
].swap_tx
;
814 update_topology_sgmii_speed(serdes_map_array
);
819 int load_topology_rd(struct serdes_map
*serdes_map_array
)
823 DEBUG_INIT_FULL_S("\n### load_topology_rd ###\n");
825 DEBUG_INIT_S("\nInit RD board ");
828 DEBUG_INIT_FULL_S("load_topology_rd: getting mode\n");
829 if (i2c_read(EEPROM_I2C_ADDR
, 0, 2, &mode
, 1)) {
830 DEBUG_INIT_S("load_topology_rd: TWSI Read failed\n");
834 /* Updating the topology map */
835 DEBUG_INIT_FULL_S("load_topology_rd: Loading board topology details\n");
837 /* RD mode: 0 = NAS, 1 = AP */
838 if (((mode
>> 1) & 0x1) == 0) {
839 CHECK_STATUS(load_topology_rd_nas(serdes_map_array
));
841 CHECK_STATUS(load_topology_rd_ap(serdes_map_array
));
844 update_topology_sgmii_speed(serdes_map_array
);
849 int load_topology_rd_nas(struct serdes_map
*serdes_map_array
)
854 DEBUG_INIT_S("\nInit RD NAS topology ");
856 /* check if lane 4 is USB3 or SGMII */
857 if (load_topology_rd_sgmii_usb(&is_sgmii
) != MV_OK
) {
858 DEBUG_INIT_S("load_topology_rd NAS: TWSI Read failed\n");
863 serdes_map_array
[0].serdes_type
= PEX0
;
864 serdes_map_array
[0].serdes_speed
= SERDES_SPEED_5_GBPS
;
865 serdes_map_array
[0].serdes_mode
= PEX_ROOT_COMPLEX_X1
;
868 serdes_map_array
[1].serdes_type
= SATA0
;
869 serdes_map_array
[1].serdes_speed
= SERDES_SPEED_3_GBPS
;
870 serdes_map_array
[1].serdes_mode
= SERDES_DEFAULT_MODE
;
873 serdes_map_array
[2].serdes_type
= SATA1
;
874 serdes_map_array
[2].serdes_speed
= SERDES_SPEED_3_GBPS
;
875 serdes_map_array
[2].serdes_mode
= SERDES_DEFAULT_MODE
;
878 serdes_map_array
[3].serdes_type
= SATA3
;
879 serdes_map_array
[3].serdes_speed
= SERDES_SPEED_3_GBPS
;
880 serdes_map_array
[3].serdes_mode
= SERDES_DEFAULT_MODE
;
884 DEBUG_INIT_S("Serdes Lane 4 is SGMII\n");
885 serdes_map_array
[4].serdes_type
= SGMII1
;
886 serdes_map_array
[4].serdes_speed
= SERDES_SPEED_3_125_GBPS
;
887 serdes_map_array
[4].serdes_mode
= SERDES_DEFAULT_MODE
;
889 DEBUG_INIT_S("Serdes Lane 4 is USB3\n");
890 serdes_map_array
[4].serdes_type
= USB3_HOST0
;
891 serdes_map_array
[4].serdes_speed
= SERDES_SPEED_5_GBPS
;
892 serdes_map_array
[4].serdes_mode
= SERDES_DEFAULT_MODE
;
896 serdes_map_array
[5].serdes_type
= SATA2
;
897 serdes_map_array
[5].serdes_speed
= SERDES_SPEED_3_GBPS
;
898 serdes_map_array
[5].serdes_mode
= SERDES_DEFAULT_MODE
;
900 /* init swap configuration */
901 for (i
= 0; i
<= 5; i
++) {
902 serdes_map_array
[i
].swap_rx
= 0;
903 serdes_map_array
[i
].swap_tx
= 0;
909 int load_topology_rd_ap(struct serdes_map
*serdes_map_array
)
914 DEBUG_INIT_S("\nInit RD AP topology ");
916 /* check if lane 4 is USB3 or SGMII */
917 if (load_topology_rd_sgmii_usb(&is_sgmii
) != MV_OK
) {
918 DEBUG_INIT_S("load_topology_rd AP: TWSI Read failed\n");
923 serdes_map_array
[0].serdes_type
= DEFAULT_SERDES
;
924 serdes_map_array
[0].serdes_speed
= LAST_SERDES_SPEED
;
925 serdes_map_array
[0].serdes_mode
= SERDES_DEFAULT_MODE
;
928 serdes_map_array
[1].serdes_type
= PEX0
;
929 serdes_map_array
[1].serdes_speed
= SERDES_SPEED_5_GBPS
;
930 serdes_map_array
[1].serdes_mode
= PEX_ROOT_COMPLEX_X1
;
933 serdes_map_array
[2].serdes_type
= PEX1
;
934 serdes_map_array
[2].serdes_speed
= SERDES_SPEED_5_GBPS
;
935 serdes_map_array
[2].serdes_mode
= PEX_ROOT_COMPLEX_X1
;
938 serdes_map_array
[3].serdes_type
= SATA3
;
939 serdes_map_array
[3].serdes_speed
= SERDES_SPEED_3_GBPS
;
940 serdes_map_array
[3].serdes_mode
= SERDES_DEFAULT_MODE
;
944 DEBUG_INIT_S("Serdes Lane 4 is SGMII\n");
945 serdes_map_array
[4].serdes_type
= SGMII1
;
946 serdes_map_array
[4].serdes_speed
= SERDES_SPEED_3_125_GBPS
;
947 serdes_map_array
[4].serdes_mode
= SERDES_DEFAULT_MODE
;
949 DEBUG_INIT_S("Serdes Lane 4 is USB3\n");
950 serdes_map_array
[4].serdes_type
= USB3_HOST0
;
951 serdes_map_array
[4].serdes_speed
= SERDES_SPEED_5_GBPS
;
952 serdes_map_array
[4].serdes_mode
= SERDES_DEFAULT_MODE
;
956 serdes_map_array
[5].serdes_type
= SATA2
;
957 serdes_map_array
[5].serdes_speed
= SERDES_SPEED_3_GBPS
;
958 serdes_map_array
[5].serdes_mode
= SERDES_DEFAULT_MODE
;
960 /* init swap configuration */
961 for (i
= 0; i
<= 5; i
++) {
962 serdes_map_array
[i
].swap_rx
= 0;
963 serdes_map_array
[i
].swap_tx
= 0;
969 int load_topology_rd_sgmii_usb(int *is_sgmii
)
974 * DB-GP board: Device 6810 supports only 2 GbE ports:
975 * SGMII2 not supported (USE USB3 Host instead)
977 if (sys_env_device_id_get() == MV_6810
) {
978 printf("Device 6810 supports only 2 GbE ports: SGMII-2 @ lane5 disabled (setting USB3.0 H1 instead)\n");
983 if (!i2c_read(RD_GET_MODE_ADDR
, 1, 2, &mode
, 1)) {
984 *is_sgmii
= ((mode
>> 2) & 0x1);
986 /* else use the default - USB3 */
991 is_custom_topology
= 1;
993 printf("Lane 5 detection: %s\n",
994 *is_sgmii
? "SGMII2" : "USB3.0 Host Port 1");
1000 * 'usb3port0'/'usb3port1' fields are located in EEPROM,
1001 * at 3rd byte(offset=2), bit 0:1 (respectively)
1003 int load_topology_usb_mode_get(u8
*twsi_data
)
1005 if (!i2c_read(EEPROM_I2C_ADDR
, 2, 2, twsi_data
, 1))