2 * Copyright 2011 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/fsl_serdes.h>
14 struct fm_eth_info fm_info[] = {
15 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 1)
16 FM_DTSEC_INFO_INITIALIZER(1, 1),
18 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 2)
19 FM_DTSEC_INFO_INITIALIZER(1, 2),
21 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 3)
22 FM_DTSEC_INFO_INITIALIZER(1, 3),
24 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 4)
25 FM_DTSEC_INFO_INITIALIZER(1, 4),
27 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 5)
28 FM_DTSEC_INFO_INITIALIZER(1, 5),
30 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 6)
31 FM_DTSEC_INFO_INITIALIZER(1, 6),
33 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 7)
34 FM_DTSEC_INFO_INITIALIZER(1, 9),
36 #if (CONFIG_SYS_NUM_FM1_DTSEC >= 8)
37 FM_DTSEC_INFO_INITIALIZER(1, 10),
39 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 1)
40 FM_DTSEC_INFO_INITIALIZER(2, 1),
42 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 2)
43 FM_DTSEC_INFO_INITIALIZER(2, 2),
45 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 3)
46 FM_DTSEC_INFO_INITIALIZER(2, 3),
48 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 4)
49 FM_DTSEC_INFO_INITIALIZER(2, 4),
51 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 5)
52 FM_DTSEC_INFO_INITIALIZER(2, 5),
54 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 6)
55 FM_DTSEC_INFO_INITIALIZER(2, 6),
57 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 7)
58 FM_DTSEC_INFO_INITIALIZER(2, 9),
60 #if (CONFIG_SYS_NUM_FM2_DTSEC >= 8)
61 FM_DTSEC_INFO_INITIALIZER(2, 10),
63 #if (CONFIG_SYS_NUM_FM1_10GEC >= 1)
64 FM_TGEC_INFO_INITIALIZER(1, 1),
66 #if (CONFIG_SYS_NUM_FM1_10GEC >= 2)
67 FM_TGEC_INFO_INITIALIZER(1, 2),
69 #if (CONFIG_SYS_NUM_FM1_10GEC >= 3)
70 FM_TGEC_INFO_INITIALIZER2(1, 3),
72 #if (CONFIG_SYS_NUM_FM1_10GEC >= 4)
73 FM_TGEC_INFO_INITIALIZER2(1, 4),
75 #if (CONFIG_SYS_NUM_FM2_10GEC >= 1)
76 FM_TGEC_INFO_INITIALIZER(2, 1),
78 #if (CONFIG_SYS_NUM_FM2_10GEC >= 2)
79 FM_TGEC_INFO_INITIALIZER(2, 2),
83 int fm_standard_init(bd_t *bis)
86 struct ccsr_fman *reg;
88 reg = (void *)CONFIG_SYS_FSL_FM1_ADDR;
89 if (fm_init_common(0, reg))
92 for (i = 0; i < ARRAY_SIZE(fm_info); i++) {
93 if ((fm_info[i].enabled) && (fm_info[i].index == 1))
94 fm_eth_initialize(reg, &fm_info[i]);
97 #if (CONFIG_SYS_NUM_FMAN == 2)
98 reg = (void *)CONFIG_SYS_FSL_FM2_ADDR;
99 if (fm_init_common(1, reg))
102 for (i = 0; i < ARRAY_SIZE(fm_info); i++) {
103 if ((fm_info[i].enabled) && (fm_info[i].index == 2))
104 fm_eth_initialize(reg, &fm_info[i]);
111 /* simple linear search to map from port to array index */
112 static int fm_port_to_index(enum fm_port port)
116 for (i = 0; i < ARRAY_SIZE(fm_info); i++) {
117 if (fm_info[i].port == port)
125 * Determine if an interface is actually active based on HW config
126 * we expect fman_port_enet_if() to report PHY_INTERFACE_MODE_NONE if
127 * the interface is not active based on HW cfg of the SoC
129 void fman_enet_init(void)
133 for (i = 0; i < ARRAY_SIZE(fm_info); i++) {
134 phy_interface_t enet_if;
136 enet_if = fman_port_enet_if(fm_info[i].port);
137 if (enet_if != PHY_INTERFACE_MODE_NONE) {
138 fm_info[i].enabled = 1;
139 fm_info[i].enet_if = enet_if;
141 fm_info[i].enabled = 0;
148 void fm_disable_port(enum fm_port port)
150 int i = fm_port_to_index(port);
155 fm_info[i].enabled = 0;
156 fman_disable_port(port);
159 void fm_enable_port(enum fm_port port)
161 int i = fm_port_to_index(port);
166 fm_info[i].enabled = 1;
167 fman_enable_port(port);
170 void fm_info_set_mdio(enum fm_port port, struct mii_dev *bus)
172 int i = fm_port_to_index(port);
177 fm_info[i].bus = bus;
180 void fm_info_set_phy_address(enum fm_port port, int address)
182 int i = fm_port_to_index(port);
187 fm_info[i].phy_addr = address;
191 * Returns the PHY address for a given Fman port
193 * The port must be set via a prior call to fm_info_set_phy_address().
194 * A negative error code is returned if the port is invalid.
196 int fm_info_get_phy_address(enum fm_port port)
198 int i = fm_port_to_index(port);
203 return fm_info[i].phy_addr;
207 * Returns the type of the data interface between the given MAC and its PHY.
208 * This is typically determined by the RCW.
210 phy_interface_t fm_info_get_enet_if(enum fm_port port)
212 int i = fm_port_to_index(port);
215 return PHY_INTERFACE_MODE_NONE;
217 if (fm_info[i].enabled)
218 return fm_info[i].enet_if;
220 return PHY_INTERFACE_MODE_NONE;
224 __def_board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
225 enum fm_port port, int offset)
230 void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
231 enum fm_port port, int offset)
232 __attribute__((weak, alias("__def_board_ft_fman_fixup_port")));
234 int ft_fixup_port(void *blob, struct fm_eth_info *info, char *prop)
238 phys_addr_t paddr = CONFIG_SYS_CCSRBAR_PHYS + info->compat_offset;
239 u64 dtsec1_addr = (u64)CONFIG_SYS_CCSRBAR_PHYS +
240 CONFIG_SYS_FSL_FM1_DTSEC1_OFFSET;
242 off = fdt_node_offset_by_compat_reg(blob, prop, paddr);
243 if (off == -FDT_ERR_NOTFOUND)
247 fdt_fixup_phy_connection(blob, off, info->enet_if);
248 board_ft_fman_fixup_port(blob, prop, paddr, info->port, off);
252 #ifdef CONFIG_SYS_FMAN_V3
253 #ifndef CONFIG_FSL_FM_10GEC_REGULAR_NOTATION
255 * On T2/T4 SoCs, physically FM1_DTSEC9 and FM1_10GEC1 use the same
256 * dual-role MAC, when FM1_10GEC1 is enabled and FM1_DTSEC9
257 * is disabled, ensure that the dual-role MAC is not disabled,
258 * ditto for other dual-role MACs.
260 if (((info->port == FM1_DTSEC9) && (PORT_IS_ENABLED(FM1_10GEC1))) ||
261 ((info->port == FM1_DTSEC10) && (PORT_IS_ENABLED(FM1_10GEC2))) ||
262 ((info->port == FM1_DTSEC1) && (PORT_IS_ENABLED(FM1_10GEC3))) ||
263 ((info->port == FM1_DTSEC2) && (PORT_IS_ENABLED(FM1_10GEC4))) ||
264 ((info->port == FM1_10GEC1) && (PORT_IS_ENABLED(FM1_DTSEC9))) ||
265 ((info->port == FM1_10GEC2) && (PORT_IS_ENABLED(FM1_DTSEC10))) ||
266 ((info->port == FM1_10GEC3) && (PORT_IS_ENABLED(FM1_DTSEC1))) ||
267 ((info->port == FM1_10GEC4) && (PORT_IS_ENABLED(FM1_DTSEC2)))
268 #if (CONFIG_SYS_NUM_FMAN == 2)
270 ((info->port == FM2_DTSEC9) && (PORT_IS_ENABLED(FM2_10GEC1))) ||
271 ((info->port == FM2_DTSEC10) && (PORT_IS_ENABLED(FM2_10GEC2))) ||
272 ((info->port == FM2_10GEC1) && (PORT_IS_ENABLED(FM2_DTSEC9))) ||
273 ((info->port == FM2_10GEC2) && (PORT_IS_ENABLED(FM2_DTSEC10)))
276 /* FM1_DTSECx and FM1_10GECx use the same dual-role MAC */
277 if (((info->port == FM1_DTSEC1) && (PORT_IS_ENABLED(FM1_10GEC1))) ||
278 ((info->port == FM1_DTSEC2) && (PORT_IS_ENABLED(FM1_10GEC2))) ||
279 ((info->port == FM1_DTSEC3) && (PORT_IS_ENABLED(FM1_10GEC3))) ||
280 ((info->port == FM1_DTSEC4) && (PORT_IS_ENABLED(FM1_10GEC4))) ||
281 ((info->port == FM1_10GEC1) && (PORT_IS_ENABLED(FM1_DTSEC1))) ||
282 ((info->port == FM1_10GEC2) && (PORT_IS_ENABLED(FM1_DTSEC2))) ||
283 ((info->port == FM1_10GEC3) && (PORT_IS_ENABLED(FM1_DTSEC3))) ||
284 ((info->port == FM1_10GEC4) && (PORT_IS_ENABLED(FM1_DTSEC4)))
289 /* board code might have caused offset to change */
290 off = fdt_node_offset_by_compat_reg(blob, prop, paddr);
292 /* Don't disable FM1-DTSEC1 MAC as its used for MDIO */
293 if (paddr != dtsec1_addr)
294 fdt_status_disabled(blob, off); /* disable the MAC node */
296 /* disable the fsl,dpa-ethernet node that points to the MAC */
297 ph = fdt_get_phandle(blob, off);
298 do_fixup_by_prop(blob, "fsl,fman-mac", &ph, sizeof(ph),
299 "status", "disabled", strlen("disabled") + 1, 1);
304 void fdt_fixup_fman_ethernet(void *blob)
308 #ifdef CONFIG_SYS_FMAN_V3
309 for (i = 0; i < ARRAY_SIZE(fm_info); i++)
310 ft_fixup_port(blob, &fm_info[i], "fsl,fman-memac");
312 for (i = 0; i < ARRAY_SIZE(fm_info); i++) {
313 /* Try the new compatible first.
314 * If the node is missing, try the old.
316 if (fm_info[i].type == FM_ETH_1G_E) {
317 if (ft_fixup_port(blob, &fm_info[i], "fsl,fman-dtsec"))
318 ft_fixup_port(blob, &fm_info[i],
321 if (ft_fixup_port(blob, &fm_info[i], "fsl,fman-tgec"))
322 ft_fixup_port(blob, &fm_info[i],
329 /*QSGMII Riser Card can work in SGMII mode, but the PHY address is different.
330 *This function scans which Riser Card being used(QSGMII or SGMII Riser Card),
331 *then set the correct PHY address
333 void set_sgmii_phy(struct mii_dev *bus, enum fm_port base_port,
334 unsigned int port_num, int phy_base_addr)
336 unsigned int regnum = 0;
341 qsgmii = is_qsgmii_riser_card(bus, phy_base_addr, port_num, regnum);
346 for (i = base_port; i < base_port + port_num; i++) {
347 if (fm_info_get_enet_if(i) == PHY_INTERFACE_MODE_SGMII) {
348 phy_real_addr = phy_base_addr + i - base_port;
349 fm_info_set_phy_address(i, phy_real_addr);
354 /*to check whether qsgmii riser card is used*/
355 int is_qsgmii_riser_card(struct mii_dev *bus, int phy_base_addr,
356 unsigned int port_num, unsigned regnum)
364 for (i = phy_base_addr; i < phy_base_addr + port_num; i++) {
365 val = bus->read(bus, i, MDIO_DEVAD_NONE, regnum);
366 if (val != MIIM_TIMEOUT)