blob: f30110817c78811a4333f9623cf9ba1e66fef365 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kumar Galac916d7c2011-04-13 08:37:44 -05002/*
Roy Zang111fd192012-10-08 07:44:21 +00003 * Copyright 2009-2012 Freescale Semiconductor, Inc.
Vabhav Sharmad90c7ac2019-06-06 12:35:28 +00004 * Copyright 2019 NXP
Kumar Galac916d7c2011-04-13 08:37:44 -05005 */
6
7#ifndef __FM_ETH_H__
8#define __FM_ETH_H__
9
Claudiu Manoil93f26f12014-09-05 13:52:36 +080010#include <phy.h>
Kumar Galac916d7c2011-04-13 08:37:44 -050011#include <asm/types.h>
Kumar Galac916d7c2011-04-13 08:37:44 -050012
13enum fm_port {
14 FM1_DTSEC1,
15 FM1_DTSEC2,
16 FM1_DTSEC3,
17 FM1_DTSEC4,
18 FM1_DTSEC5,
York Sun9e758752012-10-08 07:44:19 +000019 FM1_DTSEC6,
20 FM1_DTSEC9,
21 FM1_DTSEC10,
Kumar Galac916d7c2011-04-13 08:37:44 -050022 FM1_10GEC1,
York Sun9e758752012-10-08 07:44:19 +000023 FM1_10GEC2,
Shengzhou Liu82a55c12013-11-22 17:39:09 +080024 FM1_10GEC3,
25 FM1_10GEC4,
Kumar Galac916d7c2011-04-13 08:37:44 -050026 FM2_DTSEC1,
27 FM2_DTSEC2,
28 FM2_DTSEC3,
29 FM2_DTSEC4,
Timur Tabi99abf7d2012-08-14 06:47:21 +000030 FM2_DTSEC5,
York Sun9e758752012-10-08 07:44:19 +000031 FM2_DTSEC6,
32 FM2_DTSEC9,
33 FM2_DTSEC10,
Kumar Galac916d7c2011-04-13 08:37:44 -050034 FM2_10GEC1,
York Sun9e758752012-10-08 07:44:19 +000035 FM2_10GEC2,
Kumar Galac916d7c2011-04-13 08:37:44 -050036 NUM_FM_PORTS,
37};
38
39enum fm_eth_type {
40 FM_ETH_1G_E,
41 FM_ETH_10G_E,
42};
43
Vabhav Sharmad90c7ac2019-06-06 12:35:28 +000044/* Historically, on FMan v3 platforms, the first MDIO bus has been used for
45 * Clause 22 PHYs and the second MDIO bus for 10G Clause 45 PHYs (thus the
46 * TGEC name).
47 *
48 * On LS1046A-FRWY, the QSGMII PHY is connected to the second MDIO bus,
49 * and no TGEC ports are present on-board.
50 */
Roy Zang111fd192012-10-08 07:44:21 +000051#ifdef CONFIG_SYS_FMAN_V3
Vabhav Sharmad90c7ac2019-06-06 12:35:28 +000052#ifdef CONFIG_TARGET_LS1046AFRWY
Tom Rini6e7df1d2023-01-10 11:19:45 -050053#define CFG_SYS_FM1_DTSEC_MDIO_ADDR (CFG_SYS_FSL_FM1_ADDR + 0xfd000)
Vabhav Sharmad90c7ac2019-06-06 12:35:28 +000054#else
Tom Rini6e7df1d2023-01-10 11:19:45 -050055#define CFG_SYS_FM1_DTSEC_MDIO_ADDR (CFG_SYS_FSL_FM1_ADDR + 0xfc000)
Vabhav Sharmad90c7ac2019-06-06 12:35:28 +000056#endif
Tom Rini6e7df1d2023-01-10 11:19:45 -050057#define CFG_SYS_FM1_TGEC_MDIO_ADDR (CFG_SYS_FSL_FM1_ADDR + 0xfd000)
Tom Rinicdc5ed82022-11-16 13:10:29 -050058#if (CFG_SYS_NUM_FMAN == 2)
Tom Rini6e7df1d2023-01-10 11:19:45 -050059#define CFG_SYS_FM2_DTSEC_MDIO_ADDR (CFG_SYS_FSL_FM2_ADDR + 0xfc000)
60#define CFG_SYS_FM2_TGEC_MDIO_ADDR (CFG_SYS_FSL_FM2_ADDR + 0xfd000)
Shaohui Xie23e1aca2015-10-26 19:47:49 +080061#endif
Roy Zang111fd192012-10-08 07:44:21 +000062#else
Tom Rini6e7df1d2023-01-10 11:19:45 -050063#define CFG_SYS_FM1_DTSEC1_MDIO_ADDR (CFG_SYS_FSL_FM1_ADDR + 0xe1120)
64#define CFG_SYS_FM1_TGEC_MDIO_ADDR (CFG_SYS_FSL_FM1_ADDR + 0xf1000)
Roy Zang111fd192012-10-08 07:44:21 +000065#endif
Kumar Galac916d7c2011-04-13 08:37:44 -050066
67#define DEFAULT_FM_MDIO_NAME "FSL_MDIO0"
68#define DEFAULT_FM_TGEC_MDIO_NAME "FM_TGEC_MDIO"
69
70/* Fman ethernet info struct */
71#define FM_ETH_INFO_INITIALIZER(idx, pregs) \
72 .fm = idx, \
73 .phy_regs = (void *)pregs, \
Marek BehĂșnffb0f6f2022-04-07 00:33:03 +020074 .enet_if = PHY_INTERFACE_MODE_NA, \
Kumar Galac916d7c2011-04-13 08:37:44 -050075
Roy Zang111fd192012-10-08 07:44:21 +000076#ifdef CONFIG_SYS_FMAN_V3
77#define FM_DTSEC_INFO_INITIALIZER(idx, n) \
78{ \
Tom Rini6e7df1d2023-01-10 11:19:45 -050079 FM_ETH_INFO_INITIALIZER(idx, CFG_SYS_FM1_DTSEC_MDIO_ADDR) \
Roy Zang111fd192012-10-08 07:44:21 +000080 .index = idx, \
81 .num = n - 1, \
82 .type = FM_ETH_1G_E, \
83 .port = FM##idx##_DTSEC##n, \
84 .rx_port_id = RX_PORT_1G_BASE + n - 1, \
85 .tx_port_id = TX_PORT_1G_BASE + n - 1, \
Tom Rini6cc04542022-10-28 20:27:13 -040086 .compat_offset = CFG_SYS_FSL_FM##idx##_OFFSET + \
Roy Zang111fd192012-10-08 07:44:21 +000087 offsetof(struct ccsr_fman, memac[n-1]),\
88}
89
Shengzhou Liucc19c252014-11-24 17:11:57 +080090#ifdef CONFIG_FSL_FM_10GEC_REGULAR_NOTATION
91#define FM_TGEC_INFO_INITIALIZER(idx, n) \
92{ \
Tom Rini6e7df1d2023-01-10 11:19:45 -050093 FM_ETH_INFO_INITIALIZER(idx, CFG_SYS_FM1_TGEC_MDIO_ADDR) \
Shengzhou Liucc19c252014-11-24 17:11:57 +080094 .index = idx, \
95 .num = n - 1, \
96 .type = FM_ETH_10G_E, \
97 .port = FM##idx##_10GEC##n, \
98 .rx_port_id = RX_PORT_10G_BASE2 + n - 1, \
99 .tx_port_id = TX_PORT_10G_BASE2 + n - 1, \
Tom Rini6cc04542022-10-28 20:27:13 -0400100 .compat_offset = CFG_SYS_FSL_FM##idx##_OFFSET + \
Shengzhou Liucc19c252014-11-24 17:11:57 +0800101 offsetof(struct ccsr_fman, memac[n-1]),\
102}
103#else
Tom Rinicdc5ed82022-11-16 13:10:29 -0500104#if (CFG_SYS_NUM_FMAN == 2)
Roy Zang111fd192012-10-08 07:44:21 +0000105#define FM_TGEC_INFO_INITIALIZER(idx, n) \
106{ \
Tom Rini6e7df1d2023-01-10 11:19:45 -0500107 FM_ETH_INFO_INITIALIZER(idx, CFG_SYS_FM2_TGEC_MDIO_ADDR) \
Roy Zang111fd192012-10-08 07:44:21 +0000108 .index = idx, \
109 .num = n - 1, \
110 .type = FM_ETH_10G_E, \
111 .port = FM##idx##_10GEC##n, \
112 .rx_port_id = RX_PORT_10G_BASE + n - 1, \
113 .tx_port_id = TX_PORT_10G_BASE + n - 1, \
Tom Rini6cc04542022-10-28 20:27:13 -0400114 .compat_offset = CFG_SYS_FSL_FM##idx##_OFFSET + \
Shaohui Xie944b6cc2013-03-25 07:33:17 +0000115 offsetof(struct ccsr_fman, memac[n-1+8]),\
Roy Zang111fd192012-10-08 07:44:21 +0000116}
Shaohui Xie23e1aca2015-10-26 19:47:49 +0800117#else
118#define FM_TGEC_INFO_INITIALIZER(idx, n) \
119{ \
Tom Rini6e7df1d2023-01-10 11:19:45 -0500120 FM_ETH_INFO_INITIALIZER(idx, CFG_SYS_FM1_TGEC_MDIO_ADDR) \
Shaohui Xie23e1aca2015-10-26 19:47:49 +0800121 .index = idx, \
122 .num = n - 1, \
123 .type = FM_ETH_10G_E, \
124 .port = FM##idx##_10GEC##n, \
125 .rx_port_id = RX_PORT_10G_BASE + n - 1, \
126 .tx_port_id = TX_PORT_10G_BASE + n - 1, \
Tom Rini6cc04542022-10-28 20:27:13 -0400127 .compat_offset = CFG_SYS_FSL_FM##idx##_OFFSET + \
Shaohui Xie23e1aca2015-10-26 19:47:49 +0800128 offsetof(struct ccsr_fman, memac[n-1+8]),\
129}
130#endif
Shengzhou Liucc19c252014-11-24 17:11:57 +0800131#endif
Shengzhou Liu82a55c12013-11-22 17:39:09 +0800132
Tom Rinicdc5ed82022-11-16 13:10:29 -0500133#if (CFG_SYS_NUM_FM1_10GEC >= 3)
Shengzhou Liu82a55c12013-11-22 17:39:09 +0800134#define FM_TGEC_INFO_INITIALIZER2(idx, n) \
135{ \
Tom Rini6e7df1d2023-01-10 11:19:45 -0500136 FM_ETH_INFO_INITIALIZER(idx, CFG_SYS_FM1_TGEC_MDIO_ADDR) \
Shengzhou Liu82a55c12013-11-22 17:39:09 +0800137 .index = idx, \
138 .num = n - 1, \
139 .type = FM_ETH_10G_E, \
140 .port = FM##idx##_10GEC##n, \
141 .rx_port_id = RX_PORT_10G_BASE2 + n - 3, \
142 .tx_port_id = TX_PORT_10G_BASE2 + n - 3, \
Tom Rini6cc04542022-10-28 20:27:13 -0400143 .compat_offset = CFG_SYS_FSL_FM##idx##_OFFSET + \
Shengzhou Liu82a55c12013-11-22 17:39:09 +0800144 offsetof(struct ccsr_fman, memac[n-1-2]),\
145}
146#endif
147
Roy Zang111fd192012-10-08 07:44:21 +0000148#else
Kumar Galac916d7c2011-04-13 08:37:44 -0500149#define FM_DTSEC_INFO_INITIALIZER(idx, n) \
150{ \
Tom Rini6e7df1d2023-01-10 11:19:45 -0500151 FM_ETH_INFO_INITIALIZER(idx, CFG_SYS_FM1_DTSEC1_MDIO_ADDR) \
Kumar Galac916d7c2011-04-13 08:37:44 -0500152 .index = idx, \
153 .num = n - 1, \
154 .type = FM_ETH_1G_E, \
155 .port = FM##idx##_DTSEC##n, \
156 .rx_port_id = RX_PORT_1G_BASE + n - 1, \
157 .tx_port_id = TX_PORT_1G_BASE + n - 1, \
Tom Rini6cc04542022-10-28 20:27:13 -0400158 .compat_offset = CFG_SYS_FSL_FM##idx##_OFFSET + \
Kumar Galac916d7c2011-04-13 08:37:44 -0500159 offsetof(struct ccsr_fman, mac_1g[n-1]),\
160}
161
162#define FM_TGEC_INFO_INITIALIZER(idx, n) \
163{ \
Tom Rini6e7df1d2023-01-10 11:19:45 -0500164 FM_ETH_INFO_INITIALIZER(idx, CFG_SYS_FM1_TGEC_MDIO_ADDR) \
Kumar Galac916d7c2011-04-13 08:37:44 -0500165 .index = idx, \
166 .num = n - 1, \
167 .type = FM_ETH_10G_E, \
168 .port = FM##idx##_10GEC##n, \
169 .rx_port_id = RX_PORT_10G_BASE + n - 1, \
170 .tx_port_id = TX_PORT_10G_BASE + n - 1, \
Tom Rini6cc04542022-10-28 20:27:13 -0400171 .compat_offset = CFG_SYS_FSL_FM##idx##_OFFSET + \
Kumar Galac916d7c2011-04-13 08:37:44 -0500172 offsetof(struct ccsr_fman, mac_10g[n-1]),\
173}
Roy Zang111fd192012-10-08 07:44:21 +0000174#endif
Kumar Galac916d7c2011-04-13 08:37:44 -0500175struct fm_eth_info {
176 u8 enabled;
177 u8 fm;
178 u8 num;
179 u8 phy_addr;
180 int index;
181 u16 rx_port_id;
182 u16 tx_port_id;
183 enum fm_port port;
184 enum fm_eth_type type;
185 void *phy_regs;
186 phy_interface_t enet_if;
187 u32 compat_offset;
188 struct mii_dev *bus;
189};
190
191struct tgec_mdio_info {
192 struct tgec_mdio_controller *regs;
193 char *name;
194};
195
Roy Zang111fd192012-10-08 07:44:21 +0000196struct memac_mdio_info {
197 struct memac_mdio_controller *regs;
198 char *name;
199};
200
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900201int fm_tgec_mdio_init(struct bd_info *bis, struct tgec_mdio_info *info);
202int fm_memac_mdio_init(struct bd_info *bis, struct memac_mdio_info *info);
Roy Zang111fd192012-10-08 07:44:21 +0000203
Kumar Galac916d7c2011-04-13 08:37:44 -0500204void fman_enet_init(void);
205void fdt_fixup_fman_ethernet(void *fdt);
206phy_interface_t fm_info_get_enet_if(enum fm_port port);
207void fm_info_set_phy_address(enum fm_port port, int address);
Timur Tabiae2291f2012-08-14 06:47:22 +0000208int fm_info_get_phy_address(enum fm_port port);
Kumar Galac916d7c2011-04-13 08:37:44 -0500209void fm_info_set_mdio(enum fm_port port, struct mii_dev *bus);
Kumar Gala69a85242011-09-14 12:01:35 -0500210void fm_disable_port(enum fm_port port);
Valentin Longchampf51d3b72013-10-18 11:47:21 +0200211void fm_enable_port(enum fm_port port);
Zhao Qiangffee1dd2013-09-04 10:11:27 +0800212void set_sgmii_phy(struct mii_dev *bus, enum fm_port base_port,
213 unsigned int port_num, int phy_base_addr);
214int is_qsgmii_riser_card(struct mii_dev *bus, int phy_base_addr,
215 unsigned int port_num, unsigned regnum);
Kumar Galac916d7c2011-04-13 08:37:44 -0500216
217#endif