Grygorii Strashko | 39b014a | 2018-10-31 16:21:42 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 2 | /* |
| 3 | * CPSW Ethernet Switch Driver |
| 4 | * |
Grygorii Strashko | 39b014a | 2018-10-31 16:21:42 -0500 | [diff] [blame] | 5 | * Copyright (C) 2010-2018 Texas Instruments Incorporated - http://www.ti.com/ |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 12 | #include <net.h> |
| 13 | #include <miiphy.h> |
| 14 | #include <malloc.h> |
| 15 | #include <net.h> |
| 16 | #include <netdev.h> |
| 17 | #include <cpsw.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 18 | #include <dm/device_compat.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Tom Rini | f4a0948 | 2020-06-04 16:05:32 -0400 | [diff] [blame] | 20 | #include <linux/compiler.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 21 | #include <linux/errno.h> |
Vignesh R | 8e9473d | 2016-08-02 10:14:27 +0530 | [diff] [blame] | 22 | #include <asm/gpio.h> |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <phy.h> |
Tom Rini | 8eb48ff | 2013-03-14 11:15:25 +0000 | [diff] [blame] | 25 | #include <asm/arch/cpu.h> |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 26 | #include <dm.h> |
| 27 | |
Grygorii Strashko | eae545a | 2018-10-31 16:21:44 -0500 | [diff] [blame] | 28 | #include "cpsw_mdio.h" |
| 29 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 30 | #define BITMASK(bits) (BIT(bits) - 1) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 31 | #define NUM_DESCS (PKTBUFSRX * 2) |
| 32 | #define PKT_MIN 60 |
| 33 | #define PKT_MAX (1500 + 14 + 4 + 4) |
| 34 | #define CLEAR_BIT 1 |
| 35 | #define GIGABITEN BIT(7) |
| 36 | #define FULLDUPLEXEN BIT(0) |
| 37 | #define MIIEN BIT(15) |
Grygorii Strashko | 63bba7e | 2019-09-19 11:16:37 +0300 | [diff] [blame] | 38 | #define CTL_EXT_EN BIT(18) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 39 | /* DMA Registers */ |
| 40 | #define CPDMA_TXCONTROL 0x004 |
| 41 | #define CPDMA_RXCONTROL 0x014 |
| 42 | #define CPDMA_SOFTRESET 0x01c |
| 43 | #define CPDMA_RXFREE 0x0e0 |
| 44 | #define CPDMA_TXHDP_VER1 0x100 |
| 45 | #define CPDMA_TXHDP_VER2 0x200 |
| 46 | #define CPDMA_RXHDP_VER1 0x120 |
| 47 | #define CPDMA_RXHDP_VER2 0x220 |
| 48 | #define CPDMA_TXCP_VER1 0x140 |
| 49 | #define CPDMA_TXCP_VER2 0x240 |
| 50 | #define CPDMA_RXCP_VER1 0x160 |
| 51 | #define CPDMA_RXCP_VER2 0x260 |
| 52 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 53 | /* Descriptor mode bits */ |
| 54 | #define CPDMA_DESC_SOP BIT(31) |
| 55 | #define CPDMA_DESC_EOP BIT(30) |
| 56 | #define CPDMA_DESC_OWNER BIT(29) |
| 57 | #define CPDMA_DESC_EOQ BIT(28) |
| 58 | |
| 59 | /* |
| 60 | * This timeout definition is a worst-case ultra defensive measure against |
| 61 | * unexpected controller lock ups. Ideally, we should never ever hit this |
| 62 | * scenario in practice. |
| 63 | */ |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 64 | #define CPDMA_TIMEOUT 100 /* msecs */ |
| 65 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 66 | struct cpsw_regs { |
| 67 | u32 id_ver; |
| 68 | u32 control; |
| 69 | u32 soft_reset; |
| 70 | u32 stat_port_en; |
| 71 | u32 ptype; |
| 72 | }; |
| 73 | |
| 74 | struct cpsw_slave_regs { |
| 75 | u32 max_blks; |
| 76 | u32 blk_cnt; |
| 77 | u32 flow_thresh; |
| 78 | u32 port_vlan; |
| 79 | u32 tx_pri_map; |
Matt Porter | 1ef0e87 | 2013-03-20 05:38:12 +0000 | [diff] [blame] | 80 | #ifdef CONFIG_AM33XX |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 81 | u32 gap_thresh; |
Matt Porter | 1ef0e87 | 2013-03-20 05:38:12 +0000 | [diff] [blame] | 82 | #elif defined(CONFIG_TI814X) |
| 83 | u32 ts_ctl; |
| 84 | u32 ts_seq_ltype; |
| 85 | u32 ts_vlan; |
| 86 | #endif |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 87 | u32 sa_lo; |
| 88 | u32 sa_hi; |
| 89 | }; |
| 90 | |
| 91 | struct cpsw_host_regs { |
| 92 | u32 max_blks; |
| 93 | u32 blk_cnt; |
| 94 | u32 flow_thresh; |
| 95 | u32 port_vlan; |
| 96 | u32 tx_pri_map; |
| 97 | u32 cpdma_tx_pri_map; |
| 98 | u32 cpdma_rx_chan_map; |
| 99 | }; |
| 100 | |
| 101 | struct cpsw_sliver_regs { |
| 102 | u32 id_ver; |
| 103 | u32 mac_control; |
| 104 | u32 mac_status; |
| 105 | u32 soft_reset; |
| 106 | u32 rx_maxlen; |
| 107 | u32 __reserved_0; |
| 108 | u32 rx_pause; |
| 109 | u32 tx_pause; |
| 110 | u32 __reserved_1; |
| 111 | u32 rx_pri_map; |
| 112 | }; |
| 113 | |
| 114 | #define ALE_ENTRY_BITS 68 |
| 115 | #define ALE_ENTRY_WORDS DIV_ROUND_UP(ALE_ENTRY_BITS, 32) |
| 116 | |
| 117 | /* ALE Registers */ |
| 118 | #define ALE_CONTROL 0x08 |
| 119 | #define ALE_UNKNOWNVLAN 0x18 |
| 120 | #define ALE_TABLE_CONTROL 0x20 |
| 121 | #define ALE_TABLE 0x34 |
| 122 | #define ALE_PORTCTL 0x40 |
| 123 | |
| 124 | #define ALE_TABLE_WRITE BIT(31) |
| 125 | |
| 126 | #define ALE_TYPE_FREE 0 |
| 127 | #define ALE_TYPE_ADDR 1 |
| 128 | #define ALE_TYPE_VLAN 2 |
| 129 | #define ALE_TYPE_VLAN_ADDR 3 |
| 130 | |
| 131 | #define ALE_UCAST_PERSISTANT 0 |
| 132 | #define ALE_UCAST_UNTOUCHED 1 |
| 133 | #define ALE_UCAST_OUI 2 |
| 134 | #define ALE_UCAST_TOUCHED 3 |
| 135 | |
| 136 | #define ALE_MCAST_FWD 0 |
| 137 | #define ALE_MCAST_BLOCK_LEARN_FWD 1 |
| 138 | #define ALE_MCAST_FWD_LEARN 2 |
| 139 | #define ALE_MCAST_FWD_2 3 |
| 140 | |
| 141 | enum cpsw_ale_port_state { |
| 142 | ALE_PORT_STATE_DISABLE = 0x00, |
| 143 | ALE_PORT_STATE_BLOCK = 0x01, |
| 144 | ALE_PORT_STATE_LEARN = 0x02, |
| 145 | ALE_PORT_STATE_FORWARD = 0x03, |
| 146 | }; |
| 147 | |
| 148 | /* ALE unicast entry flags - passed into cpsw_ale_add_ucast() */ |
| 149 | #define ALE_SECURE 1 |
| 150 | #define ALE_BLOCKED 2 |
| 151 | |
| 152 | struct cpsw_slave { |
| 153 | struct cpsw_slave_regs *regs; |
| 154 | struct cpsw_sliver_regs *sliver; |
| 155 | int slave_num; |
| 156 | u32 mac_control; |
| 157 | struct cpsw_slave_data *data; |
| 158 | }; |
| 159 | |
| 160 | struct cpdma_desc { |
| 161 | /* hardware fields */ |
| 162 | u32 hw_next; |
| 163 | u32 hw_buffer; |
| 164 | u32 hw_len; |
| 165 | u32 hw_mode; |
| 166 | /* software fields */ |
| 167 | u32 sw_buffer; |
| 168 | u32 sw_len; |
| 169 | }; |
| 170 | |
| 171 | struct cpdma_chan { |
| 172 | struct cpdma_desc *head, *tail; |
| 173 | void *hdp, *cp, *rxfree; |
| 174 | }; |
| 175 | |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 176 | /* AM33xx SoC specific definitions for the CONTROL port */ |
| 177 | #define AM33XX_GMII_SEL_MODE_MII 0 |
| 178 | #define AM33XX_GMII_SEL_MODE_RMII 1 |
| 179 | #define AM33XX_GMII_SEL_MODE_RGMII 2 |
| 180 | |
| 181 | #define AM33XX_GMII_SEL_RGMII1_IDMODE BIT(4) |
| 182 | #define AM33XX_GMII_SEL_RGMII2_IDMODE BIT(5) |
| 183 | #define AM33XX_GMII_SEL_RMII1_IO_CLK_EN BIT(6) |
| 184 | #define AM33XX_GMII_SEL_RMII2_IO_CLK_EN BIT(7) |
| 185 | |
| 186 | #define GMII_SEL_MODE_MASK 0x3 |
| 187 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 188 | #define desc_write(desc, fld, val) __raw_writel((u32)(val), &(desc)->fld) |
| 189 | #define desc_read(desc, fld) __raw_readl(&(desc)->fld) |
| 190 | #define desc_read_ptr(desc, fld) ((void *)__raw_readl(&(desc)->fld)) |
| 191 | |
| 192 | #define chan_write(chan, fld, val) __raw_writel((u32)(val), (chan)->fld) |
| 193 | #define chan_read(chan, fld) __raw_readl((chan)->fld) |
| 194 | #define chan_read_ptr(chan, fld) ((void *)__raw_readl((chan)->fld)) |
| 195 | |
Mugunthan V N | 33e073e | 2014-05-22 14:37:10 +0530 | [diff] [blame] | 196 | #define for_active_slave(slave, priv) \ |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 197 | slave = (priv)->slaves + ((priv)->data)->active_slave; if (slave) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 198 | #define for_each_slave(slave, priv) \ |
| 199 | for (slave = (priv)->slaves; slave != (priv)->slaves + \ |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 200 | ((priv)->data)->slaves; slave++) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 201 | |
| 202 | struct cpsw_priv { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 203 | #ifdef CONFIG_DM_ETH |
| 204 | struct udevice *dev; |
| 205 | #else |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 206 | struct eth_device *dev; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 207 | #endif |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 208 | struct cpsw_platform_data *data; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 209 | int host_port; |
| 210 | |
| 211 | struct cpsw_regs *regs; |
| 212 | void *dma_regs; |
| 213 | struct cpsw_host_regs *host_port_regs; |
| 214 | void *ale_regs; |
| 215 | |
| 216 | struct cpdma_desc *descs; |
| 217 | struct cpdma_desc *desc_free; |
| 218 | struct cpdma_chan rx_chan, tx_chan; |
| 219 | |
| 220 | struct cpsw_slave *slaves; |
| 221 | struct phy_device *phydev; |
| 222 | struct mii_dev *bus; |
Mugunthan V N | c3fdab4 | 2013-02-19 21:34:44 +0000 | [diff] [blame] | 223 | |
Mugunthan V N | c3fdab4 | 2013-02-19 21:34:44 +0000 | [diff] [blame] | 224 | u32 phy_mask; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits) |
| 228 | { |
| 229 | int idx; |
| 230 | |
| 231 | idx = start / 32; |
| 232 | start -= idx * 32; |
| 233 | idx = 2 - idx; /* flip */ |
| 234 | return (ale_entry[idx] >> start) & BITMASK(bits); |
| 235 | } |
| 236 | |
| 237 | static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32 bits, |
| 238 | u32 value) |
| 239 | { |
| 240 | int idx; |
| 241 | |
| 242 | value &= BITMASK(bits); |
| 243 | idx = start / 32; |
| 244 | start -= idx * 32; |
| 245 | idx = 2 - idx; /* flip */ |
| 246 | ale_entry[idx] &= ~(BITMASK(bits) << start); |
| 247 | ale_entry[idx] |= (value << start); |
| 248 | } |
| 249 | |
| 250 | #define DEFINE_ALE_FIELD(name, start, bits) \ |
Tom Rini | f4a0948 | 2020-06-04 16:05:32 -0400 | [diff] [blame] | 251 | static inline int __maybe_unused cpsw_ale_get_##name(u32 *ale_entry) \ |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 252 | { \ |
| 253 | return cpsw_ale_get_field(ale_entry, start, bits); \ |
| 254 | } \ |
Tom Rini | f4a0948 | 2020-06-04 16:05:32 -0400 | [diff] [blame] | 255 | static inline void __maybe_unused cpsw_ale_set_##name(u32 *ale_entry, u32 value) \ |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 256 | { \ |
| 257 | cpsw_ale_set_field(ale_entry, start, bits, value); \ |
| 258 | } |
| 259 | |
| 260 | DEFINE_ALE_FIELD(entry_type, 60, 2) |
| 261 | DEFINE_ALE_FIELD(mcast_state, 62, 2) |
| 262 | DEFINE_ALE_FIELD(port_mask, 66, 3) |
| 263 | DEFINE_ALE_FIELD(ucast_type, 62, 2) |
| 264 | DEFINE_ALE_FIELD(port_num, 66, 2) |
| 265 | DEFINE_ALE_FIELD(blocked, 65, 1) |
| 266 | DEFINE_ALE_FIELD(secure, 64, 1) |
| 267 | DEFINE_ALE_FIELD(mcast, 40, 1) |
| 268 | |
| 269 | /* The MAC address field in the ALE entry cannot be macroized as above */ |
| 270 | static inline void cpsw_ale_get_addr(u32 *ale_entry, u8 *addr) |
| 271 | { |
| 272 | int i; |
| 273 | |
| 274 | for (i = 0; i < 6; i++) |
| 275 | addr[i] = cpsw_ale_get_field(ale_entry, 40 - 8*i, 8); |
| 276 | } |
| 277 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 278 | static inline void cpsw_ale_set_addr(u32 *ale_entry, const u8 *addr) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 279 | { |
| 280 | int i; |
| 281 | |
| 282 | for (i = 0; i < 6; i++) |
| 283 | cpsw_ale_set_field(ale_entry, 40 - 8*i, 8, addr[i]); |
| 284 | } |
| 285 | |
| 286 | static int cpsw_ale_read(struct cpsw_priv *priv, int idx, u32 *ale_entry) |
| 287 | { |
| 288 | int i; |
| 289 | |
| 290 | __raw_writel(idx, priv->ale_regs + ALE_TABLE_CONTROL); |
| 291 | |
| 292 | for (i = 0; i < ALE_ENTRY_WORDS; i++) |
| 293 | ale_entry[i] = __raw_readl(priv->ale_regs + ALE_TABLE + 4 * i); |
| 294 | |
| 295 | return idx; |
| 296 | } |
| 297 | |
| 298 | static int cpsw_ale_write(struct cpsw_priv *priv, int idx, u32 *ale_entry) |
| 299 | { |
| 300 | int i; |
| 301 | |
| 302 | for (i = 0; i < ALE_ENTRY_WORDS; i++) |
| 303 | __raw_writel(ale_entry[i], priv->ale_regs + ALE_TABLE + 4 * i); |
| 304 | |
| 305 | __raw_writel(idx | ALE_TABLE_WRITE, priv->ale_regs + ALE_TABLE_CONTROL); |
| 306 | |
| 307 | return idx; |
| 308 | } |
| 309 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 310 | static int cpsw_ale_match_addr(struct cpsw_priv *priv, const u8 *addr) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 311 | { |
| 312 | u32 ale_entry[ALE_ENTRY_WORDS]; |
| 313 | int type, idx; |
| 314 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 315 | for (idx = 0; idx < priv->data->ale_entries; idx++) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 316 | u8 entry_addr[6]; |
| 317 | |
| 318 | cpsw_ale_read(priv, idx, ale_entry); |
| 319 | type = cpsw_ale_get_entry_type(ale_entry); |
| 320 | if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR) |
| 321 | continue; |
| 322 | cpsw_ale_get_addr(ale_entry, entry_addr); |
| 323 | if (memcmp(entry_addr, addr, 6) == 0) |
| 324 | return idx; |
| 325 | } |
| 326 | return -ENOENT; |
| 327 | } |
| 328 | |
| 329 | static int cpsw_ale_match_free(struct cpsw_priv *priv) |
| 330 | { |
| 331 | u32 ale_entry[ALE_ENTRY_WORDS]; |
| 332 | int type, idx; |
| 333 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 334 | for (idx = 0; idx < priv->data->ale_entries; idx++) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 335 | cpsw_ale_read(priv, idx, ale_entry); |
| 336 | type = cpsw_ale_get_entry_type(ale_entry); |
| 337 | if (type == ALE_TYPE_FREE) |
| 338 | return idx; |
| 339 | } |
| 340 | return -ENOENT; |
| 341 | } |
| 342 | |
| 343 | static int cpsw_ale_find_ageable(struct cpsw_priv *priv) |
| 344 | { |
| 345 | u32 ale_entry[ALE_ENTRY_WORDS]; |
| 346 | int type, idx; |
| 347 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 348 | for (idx = 0; idx < priv->data->ale_entries; idx++) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 349 | cpsw_ale_read(priv, idx, ale_entry); |
| 350 | type = cpsw_ale_get_entry_type(ale_entry); |
| 351 | if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR) |
| 352 | continue; |
| 353 | if (cpsw_ale_get_mcast(ale_entry)) |
| 354 | continue; |
| 355 | type = cpsw_ale_get_ucast_type(ale_entry); |
| 356 | if (type != ALE_UCAST_PERSISTANT && |
| 357 | type != ALE_UCAST_OUI) |
| 358 | return idx; |
| 359 | } |
| 360 | return -ENOENT; |
| 361 | } |
| 362 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 363 | static int cpsw_ale_add_ucast(struct cpsw_priv *priv, const u8 *addr, |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 364 | int port, int flags) |
| 365 | { |
| 366 | u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0}; |
| 367 | int idx; |
| 368 | |
| 369 | cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_ADDR); |
| 370 | cpsw_ale_set_addr(ale_entry, addr); |
| 371 | cpsw_ale_set_ucast_type(ale_entry, ALE_UCAST_PERSISTANT); |
| 372 | cpsw_ale_set_secure(ale_entry, (flags & ALE_SECURE) ? 1 : 0); |
| 373 | cpsw_ale_set_blocked(ale_entry, (flags & ALE_BLOCKED) ? 1 : 0); |
| 374 | cpsw_ale_set_port_num(ale_entry, port); |
| 375 | |
| 376 | idx = cpsw_ale_match_addr(priv, addr); |
| 377 | if (idx < 0) |
| 378 | idx = cpsw_ale_match_free(priv); |
| 379 | if (idx < 0) |
| 380 | idx = cpsw_ale_find_ageable(priv); |
| 381 | if (idx < 0) |
| 382 | return -ENOMEM; |
| 383 | |
| 384 | cpsw_ale_write(priv, idx, ale_entry); |
| 385 | return 0; |
| 386 | } |
| 387 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 388 | static int cpsw_ale_add_mcast(struct cpsw_priv *priv, const u8 *addr, |
| 389 | int port_mask) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 390 | { |
| 391 | u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0}; |
| 392 | int idx, mask; |
| 393 | |
| 394 | idx = cpsw_ale_match_addr(priv, addr); |
| 395 | if (idx >= 0) |
| 396 | cpsw_ale_read(priv, idx, ale_entry); |
| 397 | |
| 398 | cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_ADDR); |
| 399 | cpsw_ale_set_addr(ale_entry, addr); |
| 400 | cpsw_ale_set_mcast_state(ale_entry, ALE_MCAST_FWD_2); |
| 401 | |
| 402 | mask = cpsw_ale_get_port_mask(ale_entry); |
| 403 | port_mask |= mask; |
| 404 | cpsw_ale_set_port_mask(ale_entry, port_mask); |
| 405 | |
| 406 | if (idx < 0) |
| 407 | idx = cpsw_ale_match_free(priv); |
| 408 | if (idx < 0) |
| 409 | idx = cpsw_ale_find_ageable(priv); |
| 410 | if (idx < 0) |
| 411 | return -ENOMEM; |
| 412 | |
| 413 | cpsw_ale_write(priv, idx, ale_entry); |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | static inline void cpsw_ale_control(struct cpsw_priv *priv, int bit, int val) |
| 418 | { |
| 419 | u32 tmp, mask = BIT(bit); |
| 420 | |
| 421 | tmp = __raw_readl(priv->ale_regs + ALE_CONTROL); |
| 422 | tmp &= ~mask; |
| 423 | tmp |= val ? mask : 0; |
| 424 | __raw_writel(tmp, priv->ale_regs + ALE_CONTROL); |
| 425 | } |
| 426 | |
| 427 | #define cpsw_ale_enable(priv, val) cpsw_ale_control(priv, 31, val) |
| 428 | #define cpsw_ale_clear(priv, val) cpsw_ale_control(priv, 30, val) |
| 429 | #define cpsw_ale_vlan_aware(priv, val) cpsw_ale_control(priv, 2, val) |
| 430 | |
| 431 | static inline void cpsw_ale_port_state(struct cpsw_priv *priv, int port, |
| 432 | int val) |
| 433 | { |
| 434 | int offset = ALE_PORTCTL + 4 * port; |
| 435 | u32 tmp, mask = 0x3; |
| 436 | |
| 437 | tmp = __raw_readl(priv->ale_regs + offset); |
| 438 | tmp &= ~mask; |
| 439 | tmp |= val & mask; |
| 440 | __raw_writel(tmp, priv->ale_regs + offset); |
| 441 | } |
| 442 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 443 | /* Set a self-clearing bit in a register, and wait for it to clear */ |
| 444 | static inline void setbit_and_wait_for_clear32(void *addr) |
| 445 | { |
| 446 | __raw_writel(CLEAR_BIT, addr); |
| 447 | while (__raw_readl(addr) & CLEAR_BIT) |
| 448 | ; |
| 449 | } |
| 450 | |
| 451 | #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ |
| 452 | ((mac)[2] << 16) | ((mac)[3] << 24)) |
| 453 | #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8)) |
| 454 | |
| 455 | static void cpsw_set_slave_mac(struct cpsw_slave *slave, |
| 456 | struct cpsw_priv *priv) |
| 457 | { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 458 | #ifdef CONFIG_DM_ETH |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame^] | 459 | struct eth_pdata *pdata = dev_get_plat(priv->dev); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 460 | |
| 461 | writel(mac_hi(pdata->enetaddr), &slave->regs->sa_hi); |
| 462 | writel(mac_lo(pdata->enetaddr), &slave->regs->sa_lo); |
| 463 | #else |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 464 | __raw_writel(mac_hi(priv->dev->enetaddr), &slave->regs->sa_hi); |
| 465 | __raw_writel(mac_lo(priv->dev->enetaddr), &slave->regs->sa_lo); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 466 | #endif |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 469 | static int cpsw_slave_update_link(struct cpsw_slave *slave, |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 470 | struct cpsw_priv *priv, int *link) |
| 471 | { |
Heiko Schocher | ef66003 | 2013-09-05 11:50:41 +0200 | [diff] [blame] | 472 | struct phy_device *phy; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 473 | u32 mac_control = 0; |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 474 | int ret = -ENODEV; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 475 | |
Heiko Schocher | ef66003 | 2013-09-05 11:50:41 +0200 | [diff] [blame] | 476 | phy = priv->phydev; |
Heiko Schocher | ef66003 | 2013-09-05 11:50:41 +0200 | [diff] [blame] | 477 | if (!phy) |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 478 | goto out; |
| 479 | |
| 480 | ret = phy_startup(phy); |
| 481 | if (ret) |
| 482 | goto out; |
Heiko Schocher | ef66003 | 2013-09-05 11:50:41 +0200 | [diff] [blame] | 483 | |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 484 | if (link) |
| 485 | *link = phy->link; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 486 | |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 487 | if (phy->link) { /* link up */ |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 488 | mac_control = priv->data->mac_control; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 489 | if (phy->speed == 1000) |
| 490 | mac_control |= GIGABITEN; |
| 491 | if (phy->duplex == DUPLEX_FULL) |
| 492 | mac_control |= FULLDUPLEXEN; |
| 493 | if (phy->speed == 100) |
| 494 | mac_control |= MIIEN; |
Grygorii Strashko | 63bba7e | 2019-09-19 11:16:37 +0300 | [diff] [blame] | 495 | if (phy->speed == 10 && phy_interface_is_rgmii(phy)) |
| 496 | mac_control |= CTL_EXT_EN; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | if (mac_control == slave->mac_control) |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 500 | goto out; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 501 | |
| 502 | if (mac_control) { |
| 503 | printf("link up on port %d, speed %d, %s duplex\n", |
| 504 | slave->slave_num, phy->speed, |
| 505 | (phy->duplex == DUPLEX_FULL) ? "full" : "half"); |
| 506 | } else { |
| 507 | printf("link down on port %d\n", slave->slave_num); |
| 508 | } |
| 509 | |
| 510 | __raw_writel(mac_control, &slave->sliver->mac_control); |
| 511 | slave->mac_control = mac_control; |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 512 | |
| 513 | out: |
| 514 | return ret; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static int cpsw_update_link(struct cpsw_priv *priv) |
| 518 | { |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 519 | int ret = -ENODEV; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 520 | struct cpsw_slave *slave; |
| 521 | |
Mugunthan V N | 33e073e | 2014-05-22 14:37:10 +0530 | [diff] [blame] | 522 | for_active_slave(slave, priv) |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 523 | ret = cpsw_slave_update_link(slave, priv, NULL); |
Mugunthan V N | c3fdab4 | 2013-02-19 21:34:44 +0000 | [diff] [blame] | 524 | |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 525 | return ret; |
Mugunthan V N | c3fdab4 | 2013-02-19 21:34:44 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 528 | static inline u32 cpsw_get_slave_port(struct cpsw_priv *priv, u32 slave_num) |
| 529 | { |
| 530 | if (priv->host_port == 0) |
| 531 | return slave_num + 1; |
| 532 | else |
| 533 | return slave_num; |
| 534 | } |
| 535 | |
| 536 | static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_priv *priv) |
| 537 | { |
| 538 | u32 slave_port; |
| 539 | |
| 540 | setbit_and_wait_for_clear32(&slave->sliver->soft_reset); |
| 541 | |
| 542 | /* setup priority mapping */ |
| 543 | __raw_writel(0x76543210, &slave->sliver->rx_pri_map); |
| 544 | __raw_writel(0x33221100, &slave->regs->tx_pri_map); |
| 545 | |
| 546 | /* setup max packet size, and mac address */ |
| 547 | __raw_writel(PKT_MAX, &slave->sliver->rx_maxlen); |
| 548 | cpsw_set_slave_mac(slave, priv); |
| 549 | |
| 550 | slave->mac_control = 0; /* no link yet */ |
| 551 | |
| 552 | /* enable forwarding */ |
| 553 | slave_port = cpsw_get_slave_port(priv, slave->slave_num); |
| 554 | cpsw_ale_port_state(priv, slave_port, ALE_PORT_STATE_FORWARD); |
| 555 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 556 | cpsw_ale_add_mcast(priv, net_bcast_ethaddr, 1 << slave_port); |
Mugunthan V N | c3fdab4 | 2013-02-19 21:34:44 +0000 | [diff] [blame] | 557 | |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 558 | priv->phy_mask |= 1 << slave->data->phy_addr; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static struct cpdma_desc *cpdma_desc_alloc(struct cpsw_priv *priv) |
| 562 | { |
| 563 | struct cpdma_desc *desc = priv->desc_free; |
| 564 | |
| 565 | if (desc) |
| 566 | priv->desc_free = desc_read_ptr(desc, hw_next); |
| 567 | return desc; |
| 568 | } |
| 569 | |
| 570 | static void cpdma_desc_free(struct cpsw_priv *priv, struct cpdma_desc *desc) |
| 571 | { |
| 572 | if (desc) { |
| 573 | desc_write(desc, hw_next, priv->desc_free); |
| 574 | priv->desc_free = desc; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | static int cpdma_submit(struct cpsw_priv *priv, struct cpdma_chan *chan, |
| 579 | void *buffer, int len) |
| 580 | { |
| 581 | struct cpdma_desc *desc, *prev; |
| 582 | u32 mode; |
| 583 | |
| 584 | desc = cpdma_desc_alloc(priv); |
| 585 | if (!desc) |
| 586 | return -ENOMEM; |
| 587 | |
| 588 | if (len < PKT_MIN) |
| 589 | len = PKT_MIN; |
| 590 | |
| 591 | mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; |
| 592 | |
| 593 | desc_write(desc, hw_next, 0); |
| 594 | desc_write(desc, hw_buffer, buffer); |
| 595 | desc_write(desc, hw_len, len); |
| 596 | desc_write(desc, hw_mode, mode | len); |
| 597 | desc_write(desc, sw_buffer, buffer); |
| 598 | desc_write(desc, sw_len, len); |
| 599 | |
| 600 | if (!chan->head) { |
| 601 | /* simple case - first packet enqueued */ |
| 602 | chan->head = desc; |
| 603 | chan->tail = desc; |
| 604 | chan_write(chan, hdp, desc); |
| 605 | goto done; |
| 606 | } |
| 607 | |
| 608 | /* not the first packet - enqueue at the tail */ |
| 609 | prev = chan->tail; |
| 610 | desc_write(prev, hw_next, desc); |
| 611 | chan->tail = desc; |
| 612 | |
| 613 | /* next check if EOQ has been triggered already */ |
| 614 | if (desc_read(prev, hw_mode) & CPDMA_DESC_EOQ) |
| 615 | chan_write(chan, hdp, desc); |
| 616 | |
| 617 | done: |
| 618 | if (chan->rxfree) |
| 619 | chan_write(chan, rxfree, 1); |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static int cpdma_process(struct cpsw_priv *priv, struct cpdma_chan *chan, |
| 624 | void **buffer, int *len) |
| 625 | { |
| 626 | struct cpdma_desc *desc = chan->head; |
| 627 | u32 status; |
| 628 | |
| 629 | if (!desc) |
| 630 | return -ENOENT; |
| 631 | |
| 632 | status = desc_read(desc, hw_mode); |
| 633 | |
| 634 | if (len) |
| 635 | *len = status & 0x7ff; |
| 636 | |
| 637 | if (buffer) |
| 638 | *buffer = desc_read_ptr(desc, sw_buffer); |
| 639 | |
| 640 | if (status & CPDMA_DESC_OWNER) { |
| 641 | if (chan_read(chan, hdp) == 0) { |
| 642 | if (desc_read(desc, hw_mode) & CPDMA_DESC_OWNER) |
| 643 | chan_write(chan, hdp, desc); |
| 644 | } |
| 645 | |
| 646 | return -EBUSY; |
| 647 | } |
| 648 | |
| 649 | chan->head = desc_read_ptr(desc, hw_next); |
| 650 | chan_write(chan, cp, desc); |
| 651 | |
| 652 | cpdma_desc_free(priv, desc); |
| 653 | return 0; |
| 654 | } |
| 655 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 656 | static int _cpsw_init(struct cpsw_priv *priv, u8 *enetaddr) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 657 | { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 658 | struct cpsw_slave *slave; |
| 659 | int i, ret; |
| 660 | |
| 661 | /* soft reset the controller and initialize priv */ |
| 662 | setbit_and_wait_for_clear32(&priv->regs->soft_reset); |
| 663 | |
| 664 | /* initialize and reset the address lookup engine */ |
| 665 | cpsw_ale_enable(priv, 1); |
| 666 | cpsw_ale_clear(priv, 1); |
| 667 | cpsw_ale_vlan_aware(priv, 0); /* vlan unaware mode */ |
| 668 | |
| 669 | /* setup host port priority mapping */ |
| 670 | __raw_writel(0x76543210, &priv->host_port_regs->cpdma_tx_pri_map); |
| 671 | __raw_writel(0, &priv->host_port_regs->cpdma_rx_chan_map); |
| 672 | |
| 673 | /* disable priority elevation and enable statistics on all ports */ |
| 674 | __raw_writel(0, &priv->regs->ptype); |
| 675 | |
| 676 | /* enable statistics collection only on the host port */ |
| 677 | __raw_writel(BIT(priv->host_port), &priv->regs->stat_port_en); |
Mugunthan V N | 2782f3e | 2013-07-08 16:04:38 +0530 | [diff] [blame] | 678 | __raw_writel(0x7, &priv->regs->stat_port_en); |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 679 | |
| 680 | cpsw_ale_port_state(priv, priv->host_port, ALE_PORT_STATE_FORWARD); |
| 681 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 682 | cpsw_ale_add_ucast(priv, enetaddr, priv->host_port, ALE_SECURE); |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 683 | cpsw_ale_add_mcast(priv, net_bcast_ethaddr, 1 << priv->host_port); |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 684 | |
Mugunthan V N | 33e073e | 2014-05-22 14:37:10 +0530 | [diff] [blame] | 685 | for_active_slave(slave, priv) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 686 | cpsw_slave_init(slave, priv); |
| 687 | |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 688 | ret = cpsw_update_link(priv); |
| 689 | if (ret) |
| 690 | goto out; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 691 | |
| 692 | /* init descriptor pool */ |
| 693 | for (i = 0; i < NUM_DESCS; i++) { |
| 694 | desc_write(&priv->descs[i], hw_next, |
| 695 | (i == (NUM_DESCS - 1)) ? 0 : &priv->descs[i+1]); |
| 696 | } |
| 697 | priv->desc_free = &priv->descs[0]; |
| 698 | |
| 699 | /* initialize channels */ |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 700 | if (priv->data->version == CPSW_CTRL_VERSION_2) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 701 | memset(&priv->rx_chan, 0, sizeof(struct cpdma_chan)); |
| 702 | priv->rx_chan.hdp = priv->dma_regs + CPDMA_RXHDP_VER2; |
| 703 | priv->rx_chan.cp = priv->dma_regs + CPDMA_RXCP_VER2; |
| 704 | priv->rx_chan.rxfree = priv->dma_regs + CPDMA_RXFREE; |
| 705 | |
| 706 | memset(&priv->tx_chan, 0, sizeof(struct cpdma_chan)); |
| 707 | priv->tx_chan.hdp = priv->dma_regs + CPDMA_TXHDP_VER2; |
| 708 | priv->tx_chan.cp = priv->dma_regs + CPDMA_TXCP_VER2; |
| 709 | } else { |
| 710 | memset(&priv->rx_chan, 0, sizeof(struct cpdma_chan)); |
| 711 | priv->rx_chan.hdp = priv->dma_regs + CPDMA_RXHDP_VER1; |
| 712 | priv->rx_chan.cp = priv->dma_regs + CPDMA_RXCP_VER1; |
| 713 | priv->rx_chan.rxfree = priv->dma_regs + CPDMA_RXFREE; |
| 714 | |
| 715 | memset(&priv->tx_chan, 0, sizeof(struct cpdma_chan)); |
| 716 | priv->tx_chan.hdp = priv->dma_regs + CPDMA_TXHDP_VER1; |
| 717 | priv->tx_chan.cp = priv->dma_regs + CPDMA_TXCP_VER1; |
| 718 | } |
| 719 | |
| 720 | /* clear dma state */ |
| 721 | setbit_and_wait_for_clear32(priv->dma_regs + CPDMA_SOFTRESET); |
| 722 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 723 | if (priv->data->version == CPSW_CTRL_VERSION_2) { |
| 724 | for (i = 0; i < priv->data->channels; i++) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 725 | __raw_writel(0, priv->dma_regs + CPDMA_RXHDP_VER2 + 4 |
| 726 | * i); |
| 727 | __raw_writel(0, priv->dma_regs + CPDMA_RXFREE + 4 |
| 728 | * i); |
| 729 | __raw_writel(0, priv->dma_regs + CPDMA_RXCP_VER2 + 4 |
| 730 | * i); |
| 731 | __raw_writel(0, priv->dma_regs + CPDMA_TXHDP_VER2 + 4 |
| 732 | * i); |
| 733 | __raw_writel(0, priv->dma_regs + CPDMA_TXCP_VER2 + 4 |
| 734 | * i); |
| 735 | } |
| 736 | } else { |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 737 | for (i = 0; i < priv->data->channels; i++) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 738 | __raw_writel(0, priv->dma_regs + CPDMA_RXHDP_VER1 + 4 |
| 739 | * i); |
| 740 | __raw_writel(0, priv->dma_regs + CPDMA_RXFREE + 4 |
| 741 | * i); |
| 742 | __raw_writel(0, priv->dma_regs + CPDMA_RXCP_VER1 + 4 |
| 743 | * i); |
| 744 | __raw_writel(0, priv->dma_regs + CPDMA_TXHDP_VER1 + 4 |
| 745 | * i); |
| 746 | __raw_writel(0, priv->dma_regs + CPDMA_TXCP_VER1 + 4 |
| 747 | * i); |
| 748 | |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | __raw_writel(1, priv->dma_regs + CPDMA_TXCONTROL); |
| 753 | __raw_writel(1, priv->dma_regs + CPDMA_RXCONTROL); |
| 754 | |
| 755 | /* submit rx descs */ |
| 756 | for (i = 0; i < PKTBUFSRX; i++) { |
Joe Hershberger | 9f09a36 | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 757 | ret = cpdma_submit(priv, &priv->rx_chan, net_rx_packets[i], |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 758 | PKTSIZE); |
| 759 | if (ret < 0) { |
| 760 | printf("error %d submitting rx desc\n", ret); |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | |
Sekhar Nori | b598885 | 2017-05-08 20:49:56 +0530 | [diff] [blame] | 765 | out: |
| 766 | return ret; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 767 | } |
| 768 | |
Alex Kiernan | e210e98 | 2018-05-12 07:30:02 +0000 | [diff] [blame] | 769 | static int cpsw_reap_completed_packets(struct cpsw_priv *priv) |
| 770 | { |
| 771 | int timeout = CPDMA_TIMEOUT; |
| 772 | |
| 773 | /* reap completed packets */ |
| 774 | while (timeout-- && |
| 775 | (cpdma_process(priv, &priv->tx_chan, NULL, NULL) >= 0)) |
| 776 | ; |
| 777 | |
| 778 | return timeout; |
| 779 | } |
| 780 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 781 | static void _cpsw_halt(struct cpsw_priv *priv) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 782 | { |
Alex Kiernan | e210e98 | 2018-05-12 07:30:02 +0000 | [diff] [blame] | 783 | cpsw_reap_completed_packets(priv); |
| 784 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 785 | writel(0, priv->dma_regs + CPDMA_TXCONTROL); |
| 786 | writel(0, priv->dma_regs + CPDMA_RXCONTROL); |
| 787 | |
| 788 | /* soft reset the controller and initialize priv */ |
| 789 | setbit_and_wait_for_clear32(&priv->regs->soft_reset); |
| 790 | |
| 791 | /* clear dma state */ |
| 792 | setbit_and_wait_for_clear32(priv->dma_regs + CPDMA_SOFTRESET); |
| 793 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 796 | static int _cpsw_send(struct cpsw_priv *priv, void *packet, int length) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 797 | { |
Alex Kiernan | e210e98 | 2018-05-12 07:30:02 +0000 | [diff] [blame] | 798 | int timeout; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 799 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 800 | flush_dcache_range((unsigned long)packet, |
Lokesh Vutla | f9f4ced | 2016-08-11 13:00:59 +0530 | [diff] [blame] | 801 | (unsigned long)packet + ALIGN(length, PKTALIGN)); |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 802 | |
Alex Kiernan | e210e98 | 2018-05-12 07:30:02 +0000 | [diff] [blame] | 803 | timeout = cpsw_reap_completed_packets(priv); |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 804 | if (timeout == -1) { |
| 805 | printf("cpdma_process timeout\n"); |
| 806 | return -ETIMEDOUT; |
| 807 | } |
| 808 | |
| 809 | return cpdma_submit(priv, &priv->tx_chan, packet, length); |
| 810 | } |
| 811 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 812 | static int _cpsw_recv(struct cpsw_priv *priv, uchar **pkt) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 813 | { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 814 | void *buffer; |
| 815 | int len; |
Heinrich Schuchardt | 71bb8dd | 2018-03-18 11:24:38 +0100 | [diff] [blame] | 816 | int ret; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 817 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 818 | ret = cpdma_process(priv, &priv->rx_chan, &buffer, &len); |
| 819 | if (ret < 0) |
| 820 | return ret; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 821 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 822 | invalidate_dcache_range((unsigned long)buffer, |
| 823 | (unsigned long)buffer + PKTSIZE_ALIGN); |
| 824 | *pkt = buffer; |
| 825 | |
| 826 | return len; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | static void cpsw_slave_setup(struct cpsw_slave *slave, int slave_num, |
| 830 | struct cpsw_priv *priv) |
| 831 | { |
| 832 | void *regs = priv->regs; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 833 | struct cpsw_slave_data *data = priv->data->slave_data + slave_num; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 834 | slave->slave_num = slave_num; |
| 835 | slave->data = data; |
| 836 | slave->regs = regs + data->slave_reg_ofs; |
| 837 | slave->sliver = regs + data->sliver_reg_ofs; |
| 838 | } |
| 839 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 840 | static int cpsw_phy_init(struct cpsw_priv *priv, struct cpsw_slave *slave) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 841 | { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 842 | struct phy_device *phydev; |
Ilya Ledvich | a1635f0 | 2014-03-12 11:26:30 +0200 | [diff] [blame] | 843 | u32 supported = PHY_GBIT_FEATURES; |
Grygorii Strashko | e32ed8c | 2019-09-19 11:16:39 +0300 | [diff] [blame] | 844 | int ret; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 845 | |
Yegor Yefremov | 062bbac | 2012-11-26 04:03:16 +0000 | [diff] [blame] | 846 | phydev = phy_connect(priv->bus, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 847 | slave->data->phy_addr, |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 848 | priv->dev, |
Yegor Yefremov | 062bbac | 2012-11-26 04:03:16 +0000 | [diff] [blame] | 849 | slave->data->phy_if); |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 850 | |
Heiko Schocher | ef66003 | 2013-09-05 11:50:41 +0200 | [diff] [blame] | 851 | if (!phydev) |
| 852 | return -1; |
| 853 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 854 | phydev->supported &= supported; |
Grygorii Strashko | e32ed8c | 2019-09-19 11:16:39 +0300 | [diff] [blame] | 855 | if (slave->data->max_speed) { |
| 856 | ret = phy_set_supported(phydev, slave->data->max_speed); |
| 857 | if (ret) |
| 858 | return ret; |
Sean Anderson | 8e3d3be | 2020-09-15 10:45:01 -0400 | [diff] [blame] | 859 | #if CONFIG_IS_ENABLED(DM_ETH) |
Grygorii Strashko | e32ed8c | 2019-09-19 11:16:39 +0300 | [diff] [blame] | 860 | dev_dbg(priv->dev, "Port %u speed forced to %uMbit\n", |
| 861 | slave->slave_num + 1, slave->data->max_speed); |
Sean Anderson | 8e3d3be | 2020-09-15 10:45:01 -0400 | [diff] [blame] | 862 | #else |
| 863 | log_debug("%s: Port %u speed forced to %uMbit\n", |
| 864 | priv->dev->name, slave->slave_num + 1, |
| 865 | slave->data->max_speed); |
| 866 | #endif |
Grygorii Strashko | e32ed8c | 2019-09-19 11:16:39 +0300 | [diff] [blame] | 867 | } |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 868 | phydev->advertising = phydev->supported; |
| 869 | |
Dan Murphy | 4b7b24e | 2016-05-02 15:45:56 -0500 | [diff] [blame] | 870 | #ifdef CONFIG_DM_ETH |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 871 | if (ofnode_valid(slave->data->phy_of_handle)) |
| 872 | phydev->node = slave->data->phy_of_handle; |
Dan Murphy | 4b7b24e | 2016-05-02 15:45:56 -0500 | [diff] [blame] | 873 | #endif |
| 874 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 875 | priv->phydev = phydev; |
| 876 | phy_config(phydev); |
| 877 | |
| 878 | return 1; |
| 879 | } |
| 880 | |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 881 | static void cpsw_phy_addr_update(struct cpsw_priv *priv) |
| 882 | { |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 883 | struct cpsw_platform_data *data = priv->data; |
Grygorii Strashko | eae545a | 2018-10-31 16:21:44 -0500 | [diff] [blame] | 884 | u16 alive = cpsw_mdio_get_alive(priv->bus); |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 885 | int active = data->active_slave; |
| 886 | int new_addr = ffs(alive) - 1; |
| 887 | |
| 888 | /* |
| 889 | * If there is only one phy alive and its address does not match |
| 890 | * that of active slave, then phy address can safely be updated. |
| 891 | */ |
| 892 | if (hweight16(alive) == 1 && |
| 893 | data->slave_data[active].phy_addr != new_addr) { |
| 894 | printf("Updated phy address for CPSW#%d, old: %d, new: %d\n", |
| 895 | active, data->slave_data[active].phy_addr, new_addr); |
| 896 | data->slave_data[active].phy_addr = new_addr; |
| 897 | } |
| 898 | } |
| 899 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 900 | int _cpsw_register(struct cpsw_priv *priv) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 901 | { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 902 | struct cpsw_slave *slave; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 903 | struct cpsw_platform_data *data = priv->data; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 904 | void *regs = (void *)data->cpsw_base; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 905 | |
| 906 | priv->slaves = malloc(sizeof(struct cpsw_slave) * data->slaves); |
| 907 | if (!priv->slaves) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 908 | return -ENOMEM; |
| 909 | } |
| 910 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 911 | priv->host_port = data->host_port_num; |
| 912 | priv->regs = regs; |
| 913 | priv->host_port_regs = regs + data->host_port_reg_ofs; |
| 914 | priv->dma_regs = regs + data->cpdma_reg_ofs; |
| 915 | priv->ale_regs = regs + data->ale_reg_ofs; |
Mugunthan V N | ff55987 | 2013-07-08 16:04:37 +0530 | [diff] [blame] | 916 | priv->descs = (void *)regs + data->bd_ram_ofs; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 917 | |
| 918 | int idx = 0; |
| 919 | |
| 920 | for_each_slave(slave, priv) { |
| 921 | cpsw_slave_setup(slave, idx, priv); |
| 922 | idx = idx + 1; |
| 923 | } |
| 924 | |
Grygorii Strashko | eae545a | 2018-10-31 16:21:44 -0500 | [diff] [blame] | 925 | priv->bus = cpsw_mdio_init(priv->dev->name, data->mdio_base, 0, 0); |
| 926 | if (!priv->bus) |
| 927 | return -EFAULT; |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 928 | |
| 929 | cpsw_phy_addr_update(priv); |
| 930 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 931 | for_active_slave(slave, priv) |
| 932 | cpsw_phy_init(priv, slave); |
| 933 | |
| 934 | return 0; |
| 935 | } |
| 936 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 937 | #ifndef CONFIG_DM_ETH |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 938 | static int cpsw_init(struct eth_device *dev, struct bd_info *bis) |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 939 | { |
| 940 | struct cpsw_priv *priv = dev->priv; |
| 941 | |
| 942 | return _cpsw_init(priv, dev->enetaddr); |
| 943 | } |
| 944 | |
| 945 | static void cpsw_halt(struct eth_device *dev) |
| 946 | { |
| 947 | struct cpsw_priv *priv = dev->priv; |
| 948 | |
| 949 | return _cpsw_halt(priv); |
| 950 | } |
| 951 | |
| 952 | static int cpsw_send(struct eth_device *dev, void *packet, int length) |
| 953 | { |
| 954 | struct cpsw_priv *priv = dev->priv; |
| 955 | |
| 956 | return _cpsw_send(priv, packet, length); |
| 957 | } |
| 958 | |
| 959 | static int cpsw_recv(struct eth_device *dev) |
| 960 | { |
| 961 | struct cpsw_priv *priv = dev->priv; |
| 962 | uchar *pkt = NULL; |
| 963 | int len; |
| 964 | |
| 965 | len = _cpsw_recv(priv, &pkt); |
| 966 | |
| 967 | if (len > 0) { |
| 968 | net_process_received_packet(pkt, len); |
| 969 | cpdma_submit(priv, &priv->rx_chan, pkt, PKTSIZE); |
| 970 | } |
| 971 | |
| 972 | return len; |
| 973 | } |
| 974 | |
| 975 | int cpsw_register(struct cpsw_platform_data *data) |
| 976 | { |
| 977 | struct cpsw_priv *priv; |
| 978 | struct eth_device *dev; |
| 979 | int ret; |
| 980 | |
| 981 | dev = calloc(sizeof(*dev), 1); |
| 982 | if (!dev) |
| 983 | return -ENOMEM; |
| 984 | |
| 985 | priv = calloc(sizeof(*priv), 1); |
| 986 | if (!priv) { |
| 987 | free(dev); |
| 988 | return -ENOMEM; |
| 989 | } |
| 990 | |
| 991 | priv->dev = dev; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 992 | priv->data = data; |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 993 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 994 | strcpy(dev->name, "cpsw"); |
| 995 | dev->iobase = 0; |
| 996 | dev->init = cpsw_init; |
| 997 | dev->halt = cpsw_halt; |
| 998 | dev->send = cpsw_send; |
| 999 | dev->recv = cpsw_recv; |
| 1000 | dev->priv = priv; |
| 1001 | |
| 1002 | eth_register(dev); |
| 1003 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 1004 | ret = _cpsw_register(priv); |
| 1005 | if (ret < 0) { |
| 1006 | eth_unregister(dev); |
| 1007 | free(dev); |
| 1008 | free(priv); |
| 1009 | return ret; |
| 1010 | } |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 1011 | |
| 1012 | return 1; |
| 1013 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1014 | #else |
| 1015 | static int cpsw_eth_start(struct udevice *dev) |
| 1016 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame^] | 1017 | struct eth_pdata *pdata = dev_get_plat(dev); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1018 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1019 | |
| 1020 | return _cpsw_init(priv, pdata->enetaddr); |
| 1021 | } |
| 1022 | |
| 1023 | static int cpsw_eth_send(struct udevice *dev, void *packet, int length) |
| 1024 | { |
| 1025 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1026 | |
| 1027 | return _cpsw_send(priv, packet, length); |
| 1028 | } |
| 1029 | |
| 1030 | static int cpsw_eth_recv(struct udevice *dev, int flags, uchar **packetp) |
| 1031 | { |
| 1032 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1033 | |
| 1034 | return _cpsw_recv(priv, packetp); |
| 1035 | } |
| 1036 | |
| 1037 | static int cpsw_eth_free_pkt(struct udevice *dev, uchar *packet, |
| 1038 | int length) |
| 1039 | { |
| 1040 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1041 | |
| 1042 | return cpdma_submit(priv, &priv->rx_chan, packet, PKTSIZE); |
| 1043 | } |
| 1044 | |
| 1045 | static void cpsw_eth_stop(struct udevice *dev) |
| 1046 | { |
| 1047 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1048 | |
| 1049 | return _cpsw_halt(priv); |
| 1050 | } |
| 1051 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1052 | static const struct eth_ops cpsw_eth_ops = { |
| 1053 | .start = cpsw_eth_start, |
| 1054 | .send = cpsw_eth_send, |
| 1055 | .recv = cpsw_eth_recv, |
| 1056 | .free_pkt = cpsw_eth_free_pkt, |
| 1057 | .stop = cpsw_eth_stop, |
| 1058 | }; |
| 1059 | |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1060 | static void cpsw_gmii_sel_am3352(struct cpsw_priv *priv, |
| 1061 | phy_interface_t phy_mode) |
| 1062 | { |
| 1063 | u32 reg; |
| 1064 | u32 mask; |
| 1065 | u32 mode = 0; |
| 1066 | bool rgmii_id = false; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1067 | int slave = priv->data->active_slave; |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1068 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1069 | reg = readl(priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1070 | |
| 1071 | switch (phy_mode) { |
| 1072 | case PHY_INTERFACE_MODE_RMII: |
| 1073 | mode = AM33XX_GMII_SEL_MODE_RMII; |
| 1074 | break; |
| 1075 | |
| 1076 | case PHY_INTERFACE_MODE_RGMII: |
Grygorii Strashko | 40b346d | 2019-09-19 11:16:40 +0300 | [diff] [blame] | 1077 | case PHY_INTERFACE_MODE_RGMII_RXID: |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1078 | mode = AM33XX_GMII_SEL_MODE_RGMII; |
| 1079 | break; |
| 1080 | case PHY_INTERFACE_MODE_RGMII_ID: |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1081 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 1082 | mode = AM33XX_GMII_SEL_MODE_RGMII; |
| 1083 | rgmii_id = true; |
| 1084 | break; |
| 1085 | |
| 1086 | case PHY_INTERFACE_MODE_MII: |
| 1087 | default: |
| 1088 | mode = AM33XX_GMII_SEL_MODE_MII; |
| 1089 | break; |
| 1090 | }; |
| 1091 | |
| 1092 | mask = GMII_SEL_MODE_MASK << (slave * 2) | BIT(slave + 6); |
| 1093 | mode <<= slave * 2; |
| 1094 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1095 | if (priv->data->rmii_clock_external) { |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1096 | if (slave == 0) |
| 1097 | mode |= AM33XX_GMII_SEL_RMII1_IO_CLK_EN; |
| 1098 | else |
| 1099 | mode |= AM33XX_GMII_SEL_RMII2_IO_CLK_EN; |
| 1100 | } |
| 1101 | |
| 1102 | if (rgmii_id) { |
| 1103 | if (slave == 0) |
| 1104 | mode |= AM33XX_GMII_SEL_RGMII1_IDMODE; |
| 1105 | else |
| 1106 | mode |= AM33XX_GMII_SEL_RGMII2_IDMODE; |
| 1107 | } |
| 1108 | |
| 1109 | reg &= ~mask; |
| 1110 | reg |= mode; |
| 1111 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1112 | writel(reg, priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | static void cpsw_gmii_sel_dra7xx(struct cpsw_priv *priv, |
| 1116 | phy_interface_t phy_mode) |
| 1117 | { |
| 1118 | u32 reg; |
| 1119 | u32 mask; |
| 1120 | u32 mode = 0; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1121 | int slave = priv->data->active_slave; |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1122 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1123 | reg = readl(priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1124 | |
| 1125 | switch (phy_mode) { |
| 1126 | case PHY_INTERFACE_MODE_RMII: |
| 1127 | mode = AM33XX_GMII_SEL_MODE_RMII; |
| 1128 | break; |
| 1129 | |
| 1130 | case PHY_INTERFACE_MODE_RGMII: |
| 1131 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 1132 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 1133 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 1134 | mode = AM33XX_GMII_SEL_MODE_RGMII; |
| 1135 | break; |
| 1136 | |
| 1137 | case PHY_INTERFACE_MODE_MII: |
| 1138 | default: |
| 1139 | mode = AM33XX_GMII_SEL_MODE_MII; |
| 1140 | break; |
| 1141 | }; |
| 1142 | |
| 1143 | switch (slave) { |
| 1144 | case 0: |
| 1145 | mask = GMII_SEL_MODE_MASK; |
| 1146 | break; |
| 1147 | case 1: |
| 1148 | mask = GMII_SEL_MODE_MASK << 4; |
| 1149 | mode <<= 4; |
| 1150 | break; |
| 1151 | default: |
| 1152 | dev_err(priv->dev, "invalid slave number...\n"); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1156 | if (priv->data->rmii_clock_external) |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1157 | dev_err(priv->dev, "RMII External clock is not supported\n"); |
| 1158 | |
| 1159 | reg &= ~mask; |
| 1160 | reg |= mode; |
| 1161 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1162 | writel(reg, priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | static void cpsw_phy_sel(struct cpsw_priv *priv, const char *compat, |
| 1166 | phy_interface_t phy_mode) |
| 1167 | { |
| 1168 | if (!strcmp(compat, "ti,am3352-cpsw-phy-sel")) |
| 1169 | cpsw_gmii_sel_am3352(priv, phy_mode); |
| 1170 | if (!strcmp(compat, "ti,am43xx-cpsw-phy-sel")) |
| 1171 | cpsw_gmii_sel_am3352(priv, phy_mode); |
| 1172 | else if (!strcmp(compat, "ti,dra7xx-cpsw-phy-sel")) |
| 1173 | cpsw_gmii_sel_dra7xx(priv, phy_mode); |
| 1174 | } |
| 1175 | |
Faiz Abbas | 5b5dc0f | 2019-03-18 13:54:32 +0530 | [diff] [blame] | 1176 | static int cpsw_eth_probe(struct udevice *dev) |
| 1177 | { |
| 1178 | struct cpsw_priv *priv = dev_get_priv(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame^] | 1179 | struct eth_pdata *pdata = dev_get_plat(dev); |
Faiz Abbas | 5b5dc0f | 2019-03-18 13:54:32 +0530 | [diff] [blame] | 1180 | |
| 1181 | priv->dev = dev; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1182 | priv->data = pdata->priv_pdata; |
Faiz Abbas | 8ecdffe | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 1183 | ti_cm_get_macid(dev, priv->data, pdata->enetaddr); |
Faiz Abbas | 5b5dc0f | 2019-03-18 13:54:32 +0530 | [diff] [blame] | 1184 | /* Select phy interface in control module */ |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1185 | cpsw_phy_sel(priv, priv->data->phy_sel_compat, |
Faiz Abbas | 5b5dc0f | 2019-03-18 13:54:32 +0530 | [diff] [blame] | 1186 | pdata->phy_interface); |
| 1187 | |
| 1188 | return _cpsw_register(priv); |
| 1189 | } |
| 1190 | |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1191 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1192 | static void cpsw_eth_of_parse_slave(struct cpsw_platform_data *data, |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1193 | int slave_index, ofnode subnode) |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1194 | { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1195 | struct ofnode_phandle_args out_args; |
| 1196 | struct cpsw_slave_data *slave_data; |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1197 | const char *phy_mode; |
| 1198 | u32 phy_id[2]; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1199 | int ret; |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1200 | |
| 1201 | slave_data = &data->slave_data[slave_index]; |
| 1202 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1203 | phy_mode = ofnode_read_string(subnode, "phy-mode"); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1204 | if (phy_mode) |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1205 | slave_data->phy_if = phy_get_interface_by_name(phy_mode); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1206 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1207 | ret = ofnode_parse_phandle_with_args(subnode, "phy-handle", |
| 1208 | NULL, 0, 0, &out_args); |
| 1209 | if (!ret) { |
| 1210 | slave_data->phy_of_handle = out_args.node; |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1211 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1212 | ret = ofnode_read_s32(slave_data->phy_of_handle, "reg", |
| 1213 | &slave_data->phy_addr); |
| 1214 | if (ret) |
| 1215 | printf("error: phy addr not found in dt\n"); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1216 | } else { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1217 | ret = ofnode_read_u32_array(subnode, "phy_id", phy_id, 2); |
| 1218 | if (ret) |
| 1219 | printf("error: phy_id read failed\n"); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1220 | } |
Grygorii Strashko | e32ed8c | 2019-09-19 11:16:39 +0300 | [diff] [blame] | 1221 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1222 | slave_data->max_speed = ofnode_read_s32_default(subnode, |
| 1223 | "max-speed", 0); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1224 | } |
| 1225 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1226 | static int cpsw_eth_ofdata_to_platdata(struct udevice *dev) |
| 1227 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame^] | 1228 | struct eth_pdata *pdata = dev_get_plat(dev); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1229 | struct cpsw_platform_data *data; |
Vignesh R | 8e9473d | 2016-08-02 10:14:27 +0530 | [diff] [blame] | 1230 | struct gpio_desc *mode_gpios; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1231 | int slave_index = 0; |
Vignesh R | 8e9473d | 2016-08-02 10:14:27 +0530 | [diff] [blame] | 1232 | int num_mode_gpios; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1233 | ofnode subnode; |
Mugunthan V N | 9e55635 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 1234 | int ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1235 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1236 | data = calloc(1, sizeof(struct cpsw_platform_data)); |
Faiz Abbas | 9e0e1f3 | 2019-11-11 15:22:56 +0530 | [diff] [blame] | 1237 | if (!data) |
| 1238 | return -ENOMEM; |
| 1239 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1240 | pdata->priv_pdata = data; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1241 | pdata->iobase = dev_read_addr(dev); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1242 | data->version = CPSW_CTRL_VERSION_2; |
| 1243 | data->bd_ram_ofs = CPSW_BD_OFFSET; |
| 1244 | data->ale_reg_ofs = CPSW_ALE_OFFSET; |
| 1245 | data->cpdma_reg_ofs = CPSW_CPDMA_OFFSET; |
| 1246 | data->mdio_div = CPSW_MDIO_DIV; |
| 1247 | data->host_port_reg_ofs = CPSW_HOST_PORT_OFFSET, |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1248 | |
| 1249 | pdata->phy_interface = -1; |
| 1250 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1251 | data->cpsw_base = pdata->iobase; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1252 | |
| 1253 | ret = dev_read_s32(dev, "cpdma_channels", &data->channels); |
| 1254 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1255 | printf("error: cpdma_channels not found in dt\n"); |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1256 | return ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1257 | } |
| 1258 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1259 | ret = dev_read_s32(dev, "slaves", &data->slaves); |
| 1260 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1261 | printf("error: slaves not found in dt\n"); |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1262 | return ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1263 | } |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1264 | data->slave_data = malloc(sizeof(struct cpsw_slave_data) * |
| 1265 | data->slaves); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1266 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1267 | ret = dev_read_s32(dev, "ale_entries", &data->ale_entries); |
| 1268 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1269 | printf("error: ale_entries not found in dt\n"); |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1270 | return ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1271 | } |
| 1272 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1273 | ret = dev_read_u32(dev, "bd_ram_size", &data->bd_ram_ofs); |
| 1274 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1275 | printf("error: bd_ram_size not found in dt\n"); |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1276 | return ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1277 | } |
| 1278 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1279 | ret = dev_read_u32(dev, "mac_control", &data->mac_control); |
| 1280 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1281 | printf("error: ale_entries not found in dt\n"); |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1282 | return ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1283 | } |
| 1284 | |
Vignesh R | 8e9473d | 2016-08-02 10:14:27 +0530 | [diff] [blame] | 1285 | num_mode_gpios = gpio_get_list_count(dev, "mode-gpios"); |
| 1286 | if (num_mode_gpios > 0) { |
| 1287 | mode_gpios = malloc(sizeof(struct gpio_desc) * |
| 1288 | num_mode_gpios); |
| 1289 | gpio_request_list_by_name(dev, "mode-gpios", mode_gpios, |
| 1290 | num_mode_gpios, GPIOD_IS_OUT); |
| 1291 | free(mode_gpios); |
| 1292 | } |
| 1293 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1294 | data->active_slave = dev_read_u32_default(dev, "active_slave", 0); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1295 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1296 | ofnode_for_each_subnode(subnode, dev_ofnode(dev)) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1297 | const char *name; |
| 1298 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1299 | name = ofnode_get_name(subnode); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1300 | if (!strncmp(name, "mdio", 4)) { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1301 | data->mdio_base = ofnode_get_addr(subnode); |
| 1302 | if (data->mdio_base == FDT_ADDR_T_NONE) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1303 | pr_err("Not able to get MDIO address space\n"); |
Mugunthan V N | 77f7bc7 | 2016-04-28 15:36:06 +0530 | [diff] [blame] | 1304 | return -ENOENT; |
| 1305 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | if (!strncmp(name, "slave", 5)) { |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1309 | if (slave_index >= data->slaves) |
Mugunthan V N | 13a27fd | 2016-04-28 15:36:04 +0530 | [diff] [blame] | 1310 | continue; |
Dan Murphy | 4b7b24e | 2016-05-02 15:45:56 -0500 | [diff] [blame] | 1311 | |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1312 | cpsw_eth_of_parse_slave(data, slave_index, subnode); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1313 | slave_index++; |
| 1314 | } |
| 1315 | |
| 1316 | if (!strncmp(name, "cpsw-phy-sel", 12)) { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1317 | data->gmii_sel = ofnode_get_addr(subnode); |
Mugunthan V N | 77f7bc7 | 2016-04-28 15:36:06 +0530 | [diff] [blame] | 1318 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1319 | if (data->gmii_sel == FDT_ADDR_T_NONE) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1320 | pr_err("Not able to get gmii_sel reg address\n"); |
Mugunthan V N | 77f7bc7 | 2016-04-28 15:36:06 +0530 | [diff] [blame] | 1321 | return -ENOENT; |
| 1322 | } |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1323 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1324 | if (ofnode_read_bool(subnode, "rmii-clock-ext")) |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1325 | data->rmii_clock_external = true; |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1326 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1327 | data->phy_sel_compat = ofnode_read_string(subnode, |
| 1328 | "compatible"); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1329 | if (!data->phy_sel_compat) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1330 | pr_err("Not able to get gmii_sel compatible\n"); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1331 | return -ENOENT; |
| 1332 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1336 | data->slave_data[0].slave_reg_ofs = CPSW_SLAVE0_OFFSET; |
| 1337 | data->slave_data[0].sliver_reg_ofs = CPSW_SLIVER0_OFFSET; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1338 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1339 | if (data->slaves == 2) { |
| 1340 | data->slave_data[1].slave_reg_ofs = CPSW_SLAVE1_OFFSET; |
| 1341 | data->slave_data[1].sliver_reg_ofs = CPSW_SLIVER1_OFFSET; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1342 | } |
| 1343 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1344 | ret = ti_cm_get_macid_addr(dev, data->active_slave, data); |
Mugunthan V N | 9e55635 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 1345 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1346 | pr_err("cpsw read efuse mac failed\n"); |
Mugunthan V N | 9e55635 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 1347 | return ret; |
| 1348 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1349 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1350 | pdata->phy_interface = data->slave_data[data->active_slave].phy_if; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1351 | if (pdata->phy_interface == -1) { |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1352 | debug("%s: Invalid PHY interface '%s'\n", __func__, |
| 1353 | phy_string_for_interface(pdata->phy_interface)); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1354 | return -EINVAL; |
| 1355 | } |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1356 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1357 | return 0; |
| 1358 | } |
| 1359 | |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1360 | static const struct udevice_id cpsw_eth_ids[] = { |
| 1361 | { .compatible = "ti,cpsw" }, |
| 1362 | { .compatible = "ti,am335x-cpsw" }, |
| 1363 | { } |
| 1364 | }; |
| 1365 | #endif |
| 1366 | |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 1367 | int cpsw_get_slave_phy_addr(struct udevice *dev, int slave) |
| 1368 | { |
| 1369 | struct cpsw_priv *priv = dev_get_priv(dev); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1370 | struct cpsw_platform_data *data = priv->data; |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 1371 | |
| 1372 | return data->slave_data[slave].phy_addr; |
| 1373 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1374 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1375 | U_BOOT_DRIVER(eth_cpsw) = { |
| 1376 | .name = "eth_cpsw", |
| 1377 | .id = UCLASS_ETH, |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1378 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1379 | .of_match = cpsw_eth_ids, |
| 1380 | .ofdata_to_platdata = cpsw_eth_ofdata_to_platdata, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1381 | .plat_auto = sizeof(struct eth_pdata), |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1382 | #endif |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1383 | .probe = cpsw_eth_probe, |
| 1384 | .ops = &cpsw_eth_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1385 | .priv_auto = sizeof(struct cpsw_priv), |
Faiz Abbas | d852b94 | 2019-03-18 13:54:36 +0530 | [diff] [blame] | 1386 | .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_PRE_RELOC, |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1387 | }; |
| 1388 | #endif /* CONFIG_DM_ETH */ |