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 |
| 459 | struct eth_pdata *pdata = dev_get_platdata(priv->dev); |
| 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; |
| 859 | dev_dbg(priv->dev, "Port %u speed forced to %uMbit\n", |
| 860 | slave->slave_num + 1, slave->data->max_speed); |
| 861 | } |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 862 | phydev->advertising = phydev->supported; |
| 863 | |
Dan Murphy | 4b7b24e | 2016-05-02 15:45:56 -0500 | [diff] [blame] | 864 | #ifdef CONFIG_DM_ETH |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 865 | if (ofnode_valid(slave->data->phy_of_handle)) |
| 866 | phydev->node = slave->data->phy_of_handle; |
Dan Murphy | 4b7b24e | 2016-05-02 15:45:56 -0500 | [diff] [blame] | 867 | #endif |
| 868 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 869 | priv->phydev = phydev; |
| 870 | phy_config(phydev); |
| 871 | |
| 872 | return 1; |
| 873 | } |
| 874 | |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 875 | static void cpsw_phy_addr_update(struct cpsw_priv *priv) |
| 876 | { |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 877 | struct cpsw_platform_data *data = priv->data; |
Grygorii Strashko | eae545a | 2018-10-31 16:21:44 -0500 | [diff] [blame] | 878 | u16 alive = cpsw_mdio_get_alive(priv->bus); |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 879 | int active = data->active_slave; |
| 880 | int new_addr = ffs(alive) - 1; |
| 881 | |
| 882 | /* |
| 883 | * If there is only one phy alive and its address does not match |
| 884 | * that of active slave, then phy address can safely be updated. |
| 885 | */ |
| 886 | if (hweight16(alive) == 1 && |
| 887 | data->slave_data[active].phy_addr != new_addr) { |
| 888 | printf("Updated phy address for CPSW#%d, old: %d, new: %d\n", |
| 889 | active, data->slave_data[active].phy_addr, new_addr); |
| 890 | data->slave_data[active].phy_addr = new_addr; |
| 891 | } |
| 892 | } |
| 893 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 894 | int _cpsw_register(struct cpsw_priv *priv) |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 895 | { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 896 | struct cpsw_slave *slave; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 897 | struct cpsw_platform_data *data = priv->data; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 898 | void *regs = (void *)data->cpsw_base; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 899 | |
| 900 | priv->slaves = malloc(sizeof(struct cpsw_slave) * data->slaves); |
| 901 | if (!priv->slaves) { |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 902 | return -ENOMEM; |
| 903 | } |
| 904 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 905 | priv->host_port = data->host_port_num; |
| 906 | priv->regs = regs; |
| 907 | priv->host_port_regs = regs + data->host_port_reg_ofs; |
| 908 | priv->dma_regs = regs + data->cpdma_reg_ofs; |
| 909 | priv->ale_regs = regs + data->ale_reg_ofs; |
Mugunthan V N | ff55987 | 2013-07-08 16:04:37 +0530 | [diff] [blame] | 910 | priv->descs = (void *)regs + data->bd_ram_ofs; |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 911 | |
| 912 | int idx = 0; |
| 913 | |
| 914 | for_each_slave(slave, priv) { |
| 915 | cpsw_slave_setup(slave, idx, priv); |
| 916 | idx = idx + 1; |
| 917 | } |
| 918 | |
Grygorii Strashko | eae545a | 2018-10-31 16:21:44 -0500 | [diff] [blame] | 919 | priv->bus = cpsw_mdio_init(priv->dev->name, data->mdio_base, 0, 0); |
| 920 | if (!priv->bus) |
| 921 | return -EFAULT; |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 922 | |
| 923 | cpsw_phy_addr_update(priv); |
| 924 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 925 | for_active_slave(slave, priv) |
| 926 | cpsw_phy_init(priv, slave); |
| 927 | |
| 928 | return 0; |
| 929 | } |
| 930 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 931 | #ifndef CONFIG_DM_ETH |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 932 | 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] | 933 | { |
| 934 | struct cpsw_priv *priv = dev->priv; |
| 935 | |
| 936 | return _cpsw_init(priv, dev->enetaddr); |
| 937 | } |
| 938 | |
| 939 | static void cpsw_halt(struct eth_device *dev) |
| 940 | { |
| 941 | struct cpsw_priv *priv = dev->priv; |
| 942 | |
| 943 | return _cpsw_halt(priv); |
| 944 | } |
| 945 | |
| 946 | static int cpsw_send(struct eth_device *dev, void *packet, int length) |
| 947 | { |
| 948 | struct cpsw_priv *priv = dev->priv; |
| 949 | |
| 950 | return _cpsw_send(priv, packet, length); |
| 951 | } |
| 952 | |
| 953 | static int cpsw_recv(struct eth_device *dev) |
| 954 | { |
| 955 | struct cpsw_priv *priv = dev->priv; |
| 956 | uchar *pkt = NULL; |
| 957 | int len; |
| 958 | |
| 959 | len = _cpsw_recv(priv, &pkt); |
| 960 | |
| 961 | if (len > 0) { |
| 962 | net_process_received_packet(pkt, len); |
| 963 | cpdma_submit(priv, &priv->rx_chan, pkt, PKTSIZE); |
| 964 | } |
| 965 | |
| 966 | return len; |
| 967 | } |
| 968 | |
| 969 | int cpsw_register(struct cpsw_platform_data *data) |
| 970 | { |
| 971 | struct cpsw_priv *priv; |
| 972 | struct eth_device *dev; |
| 973 | int ret; |
| 974 | |
| 975 | dev = calloc(sizeof(*dev), 1); |
| 976 | if (!dev) |
| 977 | return -ENOMEM; |
| 978 | |
| 979 | priv = calloc(sizeof(*priv), 1); |
| 980 | if (!priv) { |
| 981 | free(dev); |
| 982 | return -ENOMEM; |
| 983 | } |
| 984 | |
| 985 | priv->dev = dev; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 986 | priv->data = data; |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 987 | |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 988 | strcpy(dev->name, "cpsw"); |
| 989 | dev->iobase = 0; |
| 990 | dev->init = cpsw_init; |
| 991 | dev->halt = cpsw_halt; |
| 992 | dev->send = cpsw_send; |
| 993 | dev->recv = cpsw_recv; |
| 994 | dev->priv = priv; |
| 995 | |
| 996 | eth_register(dev); |
| 997 | |
Mugunthan V N | 6af98c5 | 2015-09-07 14:22:20 +0530 | [diff] [blame] | 998 | ret = _cpsw_register(priv); |
| 999 | if (ret < 0) { |
| 1000 | eth_unregister(dev); |
| 1001 | free(dev); |
| 1002 | free(priv); |
| 1003 | return ret; |
| 1004 | } |
Cyril Chemparathy | 464adc8 | 2012-07-24 12:22:16 +0000 | [diff] [blame] | 1005 | |
| 1006 | return 1; |
| 1007 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1008 | #else |
| 1009 | static int cpsw_eth_start(struct udevice *dev) |
| 1010 | { |
| 1011 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 1012 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1013 | |
| 1014 | return _cpsw_init(priv, pdata->enetaddr); |
| 1015 | } |
| 1016 | |
| 1017 | static int cpsw_eth_send(struct udevice *dev, void *packet, int length) |
| 1018 | { |
| 1019 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1020 | |
| 1021 | return _cpsw_send(priv, packet, length); |
| 1022 | } |
| 1023 | |
| 1024 | static int cpsw_eth_recv(struct udevice *dev, int flags, uchar **packetp) |
| 1025 | { |
| 1026 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1027 | |
| 1028 | return _cpsw_recv(priv, packetp); |
| 1029 | } |
| 1030 | |
| 1031 | static int cpsw_eth_free_pkt(struct udevice *dev, uchar *packet, |
| 1032 | int length) |
| 1033 | { |
| 1034 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1035 | |
| 1036 | return cpdma_submit(priv, &priv->rx_chan, packet, PKTSIZE); |
| 1037 | } |
| 1038 | |
| 1039 | static void cpsw_eth_stop(struct udevice *dev) |
| 1040 | { |
| 1041 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1042 | |
| 1043 | return _cpsw_halt(priv); |
| 1044 | } |
| 1045 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1046 | static const struct eth_ops cpsw_eth_ops = { |
| 1047 | .start = cpsw_eth_start, |
| 1048 | .send = cpsw_eth_send, |
| 1049 | .recv = cpsw_eth_recv, |
| 1050 | .free_pkt = cpsw_eth_free_pkt, |
| 1051 | .stop = cpsw_eth_stop, |
| 1052 | }; |
| 1053 | |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1054 | static void cpsw_gmii_sel_am3352(struct cpsw_priv *priv, |
| 1055 | phy_interface_t phy_mode) |
| 1056 | { |
| 1057 | u32 reg; |
| 1058 | u32 mask; |
| 1059 | u32 mode = 0; |
| 1060 | bool rgmii_id = false; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1061 | int slave = priv->data->active_slave; |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1062 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1063 | reg = readl(priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1064 | |
| 1065 | switch (phy_mode) { |
| 1066 | case PHY_INTERFACE_MODE_RMII: |
| 1067 | mode = AM33XX_GMII_SEL_MODE_RMII; |
| 1068 | break; |
| 1069 | |
| 1070 | case PHY_INTERFACE_MODE_RGMII: |
Grygorii Strashko | 40b346d | 2019-09-19 11:16:40 +0300 | [diff] [blame] | 1071 | case PHY_INTERFACE_MODE_RGMII_RXID: |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1072 | mode = AM33XX_GMII_SEL_MODE_RGMII; |
| 1073 | break; |
| 1074 | case PHY_INTERFACE_MODE_RGMII_ID: |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1075 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 1076 | mode = AM33XX_GMII_SEL_MODE_RGMII; |
| 1077 | rgmii_id = true; |
| 1078 | break; |
| 1079 | |
| 1080 | case PHY_INTERFACE_MODE_MII: |
| 1081 | default: |
| 1082 | mode = AM33XX_GMII_SEL_MODE_MII; |
| 1083 | break; |
| 1084 | }; |
| 1085 | |
| 1086 | mask = GMII_SEL_MODE_MASK << (slave * 2) | BIT(slave + 6); |
| 1087 | mode <<= slave * 2; |
| 1088 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1089 | if (priv->data->rmii_clock_external) { |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1090 | if (slave == 0) |
| 1091 | mode |= AM33XX_GMII_SEL_RMII1_IO_CLK_EN; |
| 1092 | else |
| 1093 | mode |= AM33XX_GMII_SEL_RMII2_IO_CLK_EN; |
| 1094 | } |
| 1095 | |
| 1096 | if (rgmii_id) { |
| 1097 | if (slave == 0) |
| 1098 | mode |= AM33XX_GMII_SEL_RGMII1_IDMODE; |
| 1099 | else |
| 1100 | mode |= AM33XX_GMII_SEL_RGMII2_IDMODE; |
| 1101 | } |
| 1102 | |
| 1103 | reg &= ~mask; |
| 1104 | reg |= mode; |
| 1105 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1106 | writel(reg, priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | static void cpsw_gmii_sel_dra7xx(struct cpsw_priv *priv, |
| 1110 | phy_interface_t phy_mode) |
| 1111 | { |
| 1112 | u32 reg; |
| 1113 | u32 mask; |
| 1114 | u32 mode = 0; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1115 | int slave = priv->data->active_slave; |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1116 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1117 | reg = readl(priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1118 | |
| 1119 | switch (phy_mode) { |
| 1120 | case PHY_INTERFACE_MODE_RMII: |
| 1121 | mode = AM33XX_GMII_SEL_MODE_RMII; |
| 1122 | break; |
| 1123 | |
| 1124 | case PHY_INTERFACE_MODE_RGMII: |
| 1125 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 1126 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 1127 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 1128 | mode = AM33XX_GMII_SEL_MODE_RGMII; |
| 1129 | break; |
| 1130 | |
| 1131 | case PHY_INTERFACE_MODE_MII: |
| 1132 | default: |
| 1133 | mode = AM33XX_GMII_SEL_MODE_MII; |
| 1134 | break; |
| 1135 | }; |
| 1136 | |
| 1137 | switch (slave) { |
| 1138 | case 0: |
| 1139 | mask = GMII_SEL_MODE_MASK; |
| 1140 | break; |
| 1141 | case 1: |
| 1142 | mask = GMII_SEL_MODE_MASK << 4; |
| 1143 | mode <<= 4; |
| 1144 | break; |
| 1145 | default: |
| 1146 | dev_err(priv->dev, "invalid slave number...\n"); |
| 1147 | return; |
| 1148 | } |
| 1149 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1150 | if (priv->data->rmii_clock_external) |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1151 | dev_err(priv->dev, "RMII External clock is not supported\n"); |
| 1152 | |
| 1153 | reg &= ~mask; |
| 1154 | reg |= mode; |
| 1155 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1156 | writel(reg, priv->data->gmii_sel); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | static void cpsw_phy_sel(struct cpsw_priv *priv, const char *compat, |
| 1160 | phy_interface_t phy_mode) |
| 1161 | { |
| 1162 | if (!strcmp(compat, "ti,am3352-cpsw-phy-sel")) |
| 1163 | cpsw_gmii_sel_am3352(priv, phy_mode); |
| 1164 | if (!strcmp(compat, "ti,am43xx-cpsw-phy-sel")) |
| 1165 | cpsw_gmii_sel_am3352(priv, phy_mode); |
| 1166 | else if (!strcmp(compat, "ti,dra7xx-cpsw-phy-sel")) |
| 1167 | cpsw_gmii_sel_dra7xx(priv, phy_mode); |
| 1168 | } |
| 1169 | |
Faiz Abbas | 5b5dc0f | 2019-03-18 13:54:32 +0530 | [diff] [blame] | 1170 | static int cpsw_eth_probe(struct udevice *dev) |
| 1171 | { |
| 1172 | struct cpsw_priv *priv = dev_get_priv(dev); |
| 1173 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 1174 | |
| 1175 | priv->dev = dev; |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1176 | priv->data = pdata->priv_pdata; |
Faiz Abbas | 8ecdffe | 2019-03-18 13:54:34 +0530 | [diff] [blame] | 1177 | ti_cm_get_macid(dev, priv->data, pdata->enetaddr); |
Faiz Abbas | 5b5dc0f | 2019-03-18 13:54:32 +0530 | [diff] [blame] | 1178 | /* Select phy interface in control module */ |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1179 | cpsw_phy_sel(priv, priv->data->phy_sel_compat, |
Faiz Abbas | 5b5dc0f | 2019-03-18 13:54:32 +0530 | [diff] [blame] | 1180 | pdata->phy_interface); |
| 1181 | |
| 1182 | return _cpsw_register(priv); |
| 1183 | } |
| 1184 | |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1185 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1186 | static void cpsw_eth_of_parse_slave(struct cpsw_platform_data *data, |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1187 | int slave_index, ofnode subnode) |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1188 | { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1189 | struct ofnode_phandle_args out_args; |
| 1190 | struct cpsw_slave_data *slave_data; |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1191 | const char *phy_mode; |
| 1192 | u32 phy_id[2]; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1193 | int ret; |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1194 | |
| 1195 | slave_data = &data->slave_data[slave_index]; |
| 1196 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1197 | phy_mode = ofnode_read_string(subnode, "phy-mode"); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1198 | if (phy_mode) |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1199 | slave_data->phy_if = phy_get_interface_by_name(phy_mode); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1200 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1201 | ret = ofnode_parse_phandle_with_args(subnode, "phy-handle", |
| 1202 | NULL, 0, 0, &out_args); |
| 1203 | if (!ret) { |
| 1204 | slave_data->phy_of_handle = out_args.node; |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1205 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1206 | ret = ofnode_read_s32(slave_data->phy_of_handle, "reg", |
| 1207 | &slave_data->phy_addr); |
| 1208 | if (ret) |
| 1209 | printf("error: phy addr not found in dt\n"); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1210 | } else { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1211 | ret = ofnode_read_u32_array(subnode, "phy_id", phy_id, 2); |
| 1212 | if (ret) |
| 1213 | printf("error: phy_id read failed\n"); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1214 | } |
Grygorii Strashko | e32ed8c | 2019-09-19 11:16:39 +0300 | [diff] [blame] | 1215 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1216 | slave_data->max_speed = ofnode_read_s32_default(subnode, |
| 1217 | "max-speed", 0); |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1218 | } |
| 1219 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1220 | static int cpsw_eth_ofdata_to_platdata(struct udevice *dev) |
| 1221 | { |
| 1222 | struct eth_pdata *pdata = dev_get_platdata(dev); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1223 | struct cpsw_platform_data *data; |
Vignesh R | 8e9473d | 2016-08-02 10:14:27 +0530 | [diff] [blame] | 1224 | struct gpio_desc *mode_gpios; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1225 | int slave_index = 0; |
Vignesh R | 8e9473d | 2016-08-02 10:14:27 +0530 | [diff] [blame] | 1226 | int num_mode_gpios; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1227 | ofnode subnode; |
Mugunthan V N | 9e55635 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 1228 | int ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1229 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1230 | data = calloc(1, sizeof(struct cpsw_platform_data)); |
Faiz Abbas | 9e0e1f3 | 2019-11-11 15:22:56 +0530 | [diff] [blame] | 1231 | if (!data) |
| 1232 | return -ENOMEM; |
| 1233 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1234 | pdata->priv_pdata = data; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1235 | pdata->iobase = dev_read_addr(dev); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1236 | data->version = CPSW_CTRL_VERSION_2; |
| 1237 | data->bd_ram_ofs = CPSW_BD_OFFSET; |
| 1238 | data->ale_reg_ofs = CPSW_ALE_OFFSET; |
| 1239 | data->cpdma_reg_ofs = CPSW_CPDMA_OFFSET; |
| 1240 | data->mdio_div = CPSW_MDIO_DIV; |
| 1241 | data->host_port_reg_ofs = CPSW_HOST_PORT_OFFSET, |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1242 | |
| 1243 | pdata->phy_interface = -1; |
| 1244 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1245 | data->cpsw_base = pdata->iobase; |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1246 | |
| 1247 | ret = dev_read_s32(dev, "cpdma_channels", &data->channels); |
| 1248 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1249 | printf("error: cpdma_channels not found in dt\n"); |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1250 | return ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1251 | } |
| 1252 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1253 | ret = dev_read_s32(dev, "slaves", &data->slaves); |
| 1254 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1255 | printf("error: slaves 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 | } |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1258 | data->slave_data = malloc(sizeof(struct cpsw_slave_data) * |
| 1259 | data->slaves); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1260 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1261 | ret = dev_read_s32(dev, "ale_entries", &data->ale_entries); |
| 1262 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1263 | printf("error: ale_entries not found in dt\n"); |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1264 | return ret; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1265 | } |
| 1266 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1267 | ret = dev_read_u32(dev, "bd_ram_size", &data->bd_ram_ofs); |
| 1268 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1269 | printf("error: bd_ram_size 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, "mac_control", &data->mac_control); |
| 1274 | if (ret) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1275 | printf("error: ale_entries 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 | |
Vignesh R | 8e9473d | 2016-08-02 10:14:27 +0530 | [diff] [blame] | 1279 | num_mode_gpios = gpio_get_list_count(dev, "mode-gpios"); |
| 1280 | if (num_mode_gpios > 0) { |
| 1281 | mode_gpios = malloc(sizeof(struct gpio_desc) * |
| 1282 | num_mode_gpios); |
| 1283 | gpio_request_list_by_name(dev, "mode-gpios", mode_gpios, |
| 1284 | num_mode_gpios, GPIOD_IS_OUT); |
| 1285 | free(mode_gpios); |
| 1286 | } |
| 1287 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1288 | data->active_slave = dev_read_u32_default(dev, "active_slave", 0); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1289 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1290 | ofnode_for_each_subnode(subnode, dev_ofnode(dev)) { |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1291 | const char *name; |
| 1292 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1293 | name = ofnode_get_name(subnode); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1294 | if (!strncmp(name, "mdio", 4)) { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1295 | data->mdio_base = ofnode_get_addr(subnode); |
| 1296 | if (data->mdio_base == FDT_ADDR_T_NONE) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1297 | pr_err("Not able to get MDIO address space\n"); |
Mugunthan V N | 77f7bc7 | 2016-04-28 15:36:06 +0530 | [diff] [blame] | 1298 | return -ENOENT; |
| 1299 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | if (!strncmp(name, "slave", 5)) { |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1303 | if (slave_index >= data->slaves) |
Mugunthan V N | 13a27fd | 2016-04-28 15:36:04 +0530 | [diff] [blame] | 1304 | continue; |
Dan Murphy | 4b7b24e | 2016-05-02 15:45:56 -0500 | [diff] [blame] | 1305 | |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1306 | cpsw_eth_of_parse_slave(data, slave_index, subnode); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1307 | slave_index++; |
| 1308 | } |
| 1309 | |
| 1310 | if (!strncmp(name, "cpsw-phy-sel", 12)) { |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1311 | data->gmii_sel = ofnode_get_addr(subnode); |
Mugunthan V N | 77f7bc7 | 2016-04-28 15:36:06 +0530 | [diff] [blame] | 1312 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1313 | if (data->gmii_sel == FDT_ADDR_T_NONE) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1314 | pr_err("Not able to get gmii_sel reg address\n"); |
Mugunthan V N | 77f7bc7 | 2016-04-28 15:36:06 +0530 | [diff] [blame] | 1315 | return -ENOENT; |
| 1316 | } |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1317 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1318 | if (ofnode_read_bool(subnode, "rmii-clock-ext")) |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1319 | data->rmii_clock_external = true; |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1320 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1321 | data->phy_sel_compat = ofnode_read_string(subnode, |
| 1322 | "compatible"); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1323 | if (!data->phy_sel_compat) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1324 | pr_err("Not able to get gmii_sel compatible\n"); |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1325 | return -ENOENT; |
| 1326 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1330 | data->slave_data[0].slave_reg_ofs = CPSW_SLAVE0_OFFSET; |
| 1331 | data->slave_data[0].sliver_reg_ofs = CPSW_SLIVER0_OFFSET; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1332 | |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1333 | if (data->slaves == 2) { |
| 1334 | data->slave_data[1].slave_reg_ofs = CPSW_SLAVE1_OFFSET; |
| 1335 | data->slave_data[1].sliver_reg_ofs = CPSW_SLIVER1_OFFSET; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1336 | } |
| 1337 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1338 | ret = ti_cm_get_macid_addr(dev, data->active_slave, data); |
Mugunthan V N | 9e55635 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 1339 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1340 | pr_err("cpsw read efuse mac failed\n"); |
Mugunthan V N | 9e55635 | 2016-04-28 15:36:07 +0530 | [diff] [blame] | 1341 | return ret; |
| 1342 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1343 | |
Grygorii Strashko | 133dd1c | 2019-09-19 11:16:42 +0300 | [diff] [blame] | 1344 | pdata->phy_interface = data->slave_data[data->active_slave].phy_if; |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1345 | if (pdata->phy_interface == -1) { |
Grygorii Strashko | 68e313e | 2019-09-19 11:16:38 +0300 | [diff] [blame] | 1346 | debug("%s: Invalid PHY interface '%s'\n", __func__, |
| 1347 | phy_string_for_interface(pdata->phy_interface)); |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1348 | return -EINVAL; |
| 1349 | } |
Mugunthan V N | 4d5fdb6 | 2016-10-13 19:33:38 +0530 | [diff] [blame] | 1350 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1351 | return 0; |
| 1352 | } |
| 1353 | |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1354 | static const struct udevice_id cpsw_eth_ids[] = { |
| 1355 | { .compatible = "ti,cpsw" }, |
| 1356 | { .compatible = "ti,am335x-cpsw" }, |
| 1357 | { } |
| 1358 | }; |
| 1359 | #endif |
| 1360 | |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 1361 | int cpsw_get_slave_phy_addr(struct udevice *dev, int slave) |
| 1362 | { |
| 1363 | struct cpsw_priv *priv = dev_get_priv(dev); |
Faiz Abbas | 5e3d77f | 2019-03-18 13:54:33 +0530 | [diff] [blame] | 1364 | struct cpsw_platform_data *data = priv->data; |
Sekhar Nori | cfc5cc8 | 2018-08-23 17:11:29 +0530 | [diff] [blame] | 1365 | |
| 1366 | return data->slave_data[slave].phy_addr; |
| 1367 | } |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1368 | |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1369 | U_BOOT_DRIVER(eth_cpsw) = { |
| 1370 | .name = "eth_cpsw", |
| 1371 | .id = UCLASS_ETH, |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1372 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1373 | .of_match = cpsw_eth_ids, |
| 1374 | .ofdata_to_platdata = cpsw_eth_ofdata_to_platdata, |
Faiz Abbas | 687e80e | 2019-03-18 13:54:35 +0530 | [diff] [blame] | 1375 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 1376 | #endif |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1377 | .probe = cpsw_eth_probe, |
| 1378 | .ops = &cpsw_eth_ops, |
| 1379 | .priv_auto_alloc_size = sizeof(struct cpsw_priv), |
Faiz Abbas | d852b94 | 2019-03-18 13:54:36 +0530 | [diff] [blame] | 1380 | .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_PRE_RELOC, |
Mugunthan V N | 7ae228c | 2015-09-07 14:22:21 +0530 | [diff] [blame] | 1381 | }; |
| 1382 | #endif /* CONFIG_DM_ETH */ |