Added CPSW support
Subsystems (2)
v2 cover Added CPSW support
This patch series is submitted to add support for CPSW which is an on-chip ethernet switch on TI AM335X EVM.
The patches have been compile tested and run on AM335X EVM.
The patches depends on previous patch series which was submitted for supporting AM33xx platform.
Changes since v1:
- Used eth_setenv_enetaddr function and code cleanup
- Added weak alias miiphy_is_1000base_x function
Chandan Nath (1):
ARM:AM33XX:Added cpsw support for AM335x EVM
Cyril Chemparathy (1):
TI: netdev: add driver for cpsw ethernet device
arch/arm/cpu/armv7/am33xx/clock.c | 9 +- arch/arm/include/asm/arch-am33xx/cpu.h | 22 +- arch/arm/include/asm/arch-am33xx/hardware.h | 5 + board/ti/am335x/common_def.h | 2 + board/ti/am335x/evm.c | 149 +++++ board/ti/am335x/mux.c | 24 + common/miiphyutil.c | 5 +- drivers/net/Makefile | 1 + drivers/net/cpsw.c | 919 +++++++++++++++++++++++++++ include/configs/am335x_evm.h | 16 +- include/netdev.h | 36 + 11 files changed, 1182 insertions(+), 6 deletions(-) create mode 100644 drivers/net/cpsw.c
PATCH v2 1/2 TI: netdev: add driver for cpsw ethernet device
From: Cyril Chemparathy <[email protected]>
CPSW is an on-chip ethernet switch that is found on various SoCs from Texas Instruments. This patch adds a simple driver (based on the Linux driver) for this hardware module.
---
Changes since v1:
- Code cleanup and removal of cpsw_eth_set_mac_addr function
drivers/net/Makefile | 1 + drivers/net/cpsw.c | 862 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/netdev.h | 29 ++ 3 files changed, 892 insertions(+), 0 deletions(-) create mode 100644 drivers/net/cpsw.c
drivers/net/Makefile +1 -0
@@ -80,6 +80,7 @@ COBJS-$(CONFIG_TIGON3) += bcm570x_autoneg.o COBJS-$(CONFIG_TIGON3) += 5701rls.o COBJS-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o COBJS-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o +COBJS-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o COBJS-$(CONFIG_TSI108_ETH) += tsi108_eth.o COBJS-$(CONFIG_ULI526X) += uli526x.o COBJS-$(CONFIG_VSC7385_ENET) += vsc7385.o
drivers/net/cpsw.c new file +862 -0
862 lines not on this page · raw message
include/netdev.h +29 -0
@@ -185,4 +185,33 @@ struct mv88e61xx_config {int mv88e61xx_switch_initialize (struct mv88e61xx_config *swconfig);#endif /* CONFIG_MV88E61XX_SWITCH */ +#ifdef CONFIG_DRIVER_TI_CPSW + +struct cpsw_slave_data { +u32 slave_reg_ofs; +u32 sliver_reg_ofs; +int phy_id; +}; + +struct cpsw_platform_data { +u32 mdio_base; +u32 cpsw_base; +int mdio_div; +int channels;/* number of cpdma channels (symmetric) */ +u32 cpdma_reg_ofs;/* cpdma register offset */ +int slaves;/* number of slave cpgmac ports */ +u32 ale_reg_ofs;/* address lookup engine reg offset */ +int ale_entries;/* ale table size */ +u32 host_port_reg_ofs;/* cpdma host port registers */ +u32 hw_stats_reg_ofs;/* cpsw hw stats counters */ +u32 mac_control; +struct cpsw_slave_data *slave_data; +void (*control)(int enabled); +void (*phy_init)(char *name,int addr); +}; + +int cpsw_register (struct cpsw_platform_data *data); + +#endif /* CONFIG_DRIVER_TI_CPSW */ +#endif /* _NETDEV_H_ */
Signature · 1 line
1.7.1
PATCH v2 1/2 TI: netdev: add driver for cpsw ethernet device
drivers/net/cpsw.c line 518
Quoted 2 lines · On Thursday 10 November 2011 07:40:28 Chandan Nath wrote:
drivers/net/cpsw.c new file +2
-0+#define mac_hi (mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ + ((mac)[2] << 16) | ((mac)[3] << 24))
looks like __get_unaligned_u32()
Quoted 1 line
+#define
mac_lo(mac)(((mac)[4] << 0) | ((mac)[5] << 8))
looks like __get_unaligned_u16()
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111110/e76893bf/attachment.pgp
PATCH v2 1/2 TI: netdev: add driver for cpsw ethernet device
Quoted 9 lines · Mike Frysinger
Quoted 2 lines · On Thursday 10 November 2011 07:40:28 Chandan Nath wrote:
+#define
mac_hi(mac)? ?(((mac)[0] << 0) | ((mac)[1] << 8) | ? ?\
+ ? ? ? ? ? ? ? ? ? ? ? ?((mac)[2] << 16) | ((mac)[3] << 24))looks like
__get_unaligned_u32()Quoted 1 line
+#define
mac_lo(mac)? ?(((mac)[4] << 0) | ((mac)[5] << 8))looks like
__get_unaligned_u16()
It's the regular MAC shifting around everyone does. Are you saying there's a general cleanup to be done here?
Signature · 1 line
Tom
PATCH v2 1/2 TI: netdev: add driver for cpsw ethernet device
Quoted 5 lines · On Thursday 10 November 2011 11:39:49 Tom Rini wrote:
Quoted 4 lines · Mike Frysinger
Quoted 2 lines · On Thursday 10 November 2011 07:40:28 Chandan Nath wrote:
drivers/net/cpsw.c new file +2
-0+#define mac_hi (mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ + ((mac)[2] << 16) | ((mac)[3] << 24))
Quoted 8 lines
Quoted 5 lines
looks like
__get_unaligned_u32()Quoted 1 line
+#define
mac_lo(mac)(((mac)[4] << 0) | ((mac)[5] << 8))looks like
__get_unaligned_u16()It's the regular MAC shifting around everyone does. Are you saying there's a general cleanup to be done here?
other drivers probably could benefit from using the unaligned helpers. but it isn't something we could generally unify as it requires assumption on core/system endian, and the layout of the registers in the peripheral. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111110/afa2dcd4/attachment.pgp
PATCH v2 1/2 TI: netdev: add driver for cpsw ethernet device
In reply to Chandan NathQuoted 5 lines · Chandan Nath
From: Cyril Chemparathy <[email protected]>
CPSW is an on-chip ethernet switch that is found on various SoCs from Texas Instruments. ?This patch adds a simple driver (based on the Linux driver) for this hardware module.
Which Linux driver is this based on?
Quoted 12 lines
Signed-off-by Cyril Chemparathy <[email protected]>---
Changes since v1:
?- Code cleanup and removal ofcpsw_eth_set_mac_addrfunction?drivers/net/Makefile | ? ?1 + ?drivers/net/cpsw.c ? | ?862 ++++++++++++++++++++++++++++++++++++++++++++++++++ ?include/netdev.h ? ? | ? 29 ++?3 files changed, 892 insertions(+), 0 deletions(-) ?create mode 100644
drivers/net/cpsw.c
Review
Quoted 5 lines
(quoted diff) +5
-0+ +#define BIT(x) ? ? ? ? ? ? ? ? (1 << (x)) +#define BITMASK(bits) ? ? ? ? ?(BIT(bits) - 1) +#define PHY_REG_MASK ? ? ? ? ? 0x1f +#define PHY_ID_MASK ? ? ? ? ? ?0x1f
These 4 defines seem very generic
Quoted 12 lines
(quoted diff) +12
-0+struct cpsw_priv { + ? ? ? struct eth_device ? ? ? ? ? ? ? *dev; + ? ? ? struct cpsw_platform_data ? ? ? data; + ? ? ? int ? ? ? ? ? ? ? ? ? ? ? ? ? ? host_port; + + ? ? ? struct cpsw_regs ? ? ? ? ? ? ? ?*regs; + ? ? ? void ? ? ? ? ? ? ? ? ? ? ? ? ? ?*dma_regs; + ? ? ? struct cpsw_host_regs ? ? ? ? ? *host_port_regs; + ? ? ? void ? ? ? ? ? ? ? ? ? ? ? ? ? ?*ale_regs; + + ? ? ? struct cpdma_desc ? ? ? ? ? ? ? descs[NUM_DESCS]; + ? ? ? struct cpdma_desc ? ? ? ? ? ? ? *desc_free;
Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? struct cpdma_chan ? ? ? ? ? ? ? rx_chan, tx_chan; + + ? ? ? struct cpsw_slave ? ? ? ? ? ? ? *slaves; +#define for_each_slave(priv, func, arg...) ? ? ? ? ? ? ? ? ? ? \ + ? ? ? do { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ? ? ? ? ? ? int idx; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ? ? ? ? ? ? for (idx = 0; idx < (priv)->data.slaves; idx++) \ + ? ? ? ? ? ? ? ? ? ? ? (func)((priv)->slaves + idx, ##arg); ? ?\ + ? ? ? } while (0) +};
It seems a bit awkward to me to put a complex macro like this inside the structure definition. After further review, I think it should also be defined differently, more like the list macros:
#define for_each_slave(slave, priv) \
for (slave = (priv)->slaves; slave != (priv)->slaves +(priv)->data.slaves; slave++)
It makes the code more maintainable, as the macro no longer contains the implicit assumption that "func" has a slave pointer as its first argument.
Quoted 13 lines
(quoted diff) +13
-0+ +static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits) +{ + ? ? ? int idx; + + ? ? ? idx ? ?= start / 32; + ? ? ? start -= idx * 32; + ? ? ? idx ? ?= 2 - idx; /* flip */ + ? ? ? return (ale_entry[idx] >> start) & BITMASK(bits); +} + +static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32 bits, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? u32 value)
Review
Quoted 10 lines
(quoted diff) +10
-0+{ + ? ? ? int idx; + + ? ? ? value &= BITMASK(bits); + ? ? ? idx ? ?= start / 32; + ? ? ? start -= idx * 32; + ? ? ? idx ? ?= 2 - idx; /* flip */ + ? ? ? ale_entry[idx] &= ~(BITMASK(bits) << start); + ? ? ? ale_entry[idx] |= ?(value << start); +}
These two functions seem both very generic, and also over-worked.
Quoted 50 lines
(quoted diff) +50
-0+ +#define DEFINE_ALE_FIELD(name, start, bits) ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ +static inline int cpsw_ale_get_##name(u32 *ale_entry) ? ? ? ? ? ? ? ? ?\ +{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ? ? return cpsw_ale_get_field(ale_entry, start, bits); ? ? ? ? ? ? ?\ +} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ +static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value) ? ? ?\ +{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ? ? cpsw_ale_set_field(ale_entry, start, bits, value); ? ? ? ? ? ? ?\ +} + +DEFINE_ALE_FIELD(entry_type, ? ? ? ? ? 60, ? ? 2) +DEFINE_ALE_FIELD(mcast_state, ? ? ? ? ?62, ? ? 2) +DEFINE_ALE_FIELD(port_mask, ? ? ? ? ? ?64, ? ? 3) +DEFINE_ALE_FIELD(ucast_type, ? ? ? ? ? 66, ? ? 2) +DEFINE_ALE_FIELD(port_num, ? ? ? ? ? ? 64, ? ? 2) +DEFINE_ALE_FIELD(blocked, ? ? ? ? ? ? ?63, ? ? 1) +DEFINE_ALE_FIELD(secure, ? ? ? ? ? ? ? 62, ? ? 1) +DEFINE_ALE_FIELD(mcast, ? ? ? ? ? ? ? ? ? ? ? ?47, ? ? 1) + +/* The MAC address field in the ALE entry cannot be macroized as above */ +static inline void cpsw_ale_get_addr(u32 *ale_entry, u8 *addr) +{ + ? ? ? int i; + + ? ? ? for (i = 0; i < 6; i++) + ? ? ? ? ? ? ? addr[i] = cpsw_ale_get_field(ale_entry, 40 - 8*i, 8); +} + +static inline void cpsw_ale_set_addr(u32 *ale_entry, u8 *addr) +{ + ? ? ? int i; + + ? ? ? for (i = 0; i < 6; i++) + ? ? ? ? ? ? ? cpsw_ale_set_field(ale_entry, 40 - 8*i, 8, addr[i]); +} + +static int cpsw_ale_read(struct cpsw_priv *priv, int idx, u32 *ale_entry) +{ + ? ? ? int i; + + ? ? ? __raw_writel(idx, priv->ale_regs + ALE_TABLE_CONTROL); + + ? ? ? for (i = 0; i < ALE_ENTRY_WORDS; i++) + ? ? ? ? ? ? ? ale_entry[i] = __raw_readl(priv->ale_regs + ALE_TABLE + 4 * i); + + ? ? ? return idx; +} + +static int cpsw_ale_write(struct cpsw_priv *priv, int idx, u32 *ale_entry)
Review
Quoted 10 lines
(quoted diff) +10
-0+{ + ? ? ? int i; + + ? ? ? for (i = 0; i < ALE_ENTRY_WORDS; i++) + ? ? ? ? ? ? ? __raw_writel(ale_entry[i], priv->ale_regs + ALE_TABLE + 4 * i); + + ? ? ? __raw_writel(idx | ALE_TABLE_WRITE, priv->ale_regs + ALE_TABLE_CONTROL); + + ? ? ? return idx; +}
I don't know how your device works, but it seems odd to me to have to read out a large table, and modify it, and then write it back out.
I'm also highly suspicious of the overworked bitfield math. Are standard C bitfields not usable for some reason? It borders on code obfuscation, IMO. I've spent far too much time, already, just trying to figure out what that code was doing, and why.
Review
Quoted 9 lines
(quoted diff) +9
-0+static inline void cpsw_ale_port_state(struct cpsw_priv *priv, int port, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int val) +{ + ? ? ? int offset = ALE_PORTCTL + 4 * port; + ? ? ? u32 tmp, mask = 0x3; + + ? ? ? tmp ?= __raw_readl(priv->ale_regs + offset); + ? ? ? tmp &= ~mask; + ? ? ? tmp |= val & 0x3;
All of this can probably be done with more generic setbits functions, but at least use "mask" consistently for both the clearing and the masking of "val".
drivers/net/cpsw.c line 435
Quoted 4 lines
+ ? ? ?
__raw_writel(tmp, priv->ale_regs + offset);drivers/net/cpsw.c new file +3
-0+} + +static struct cpsw_mdio_regs *mdio_regs;
Global variables like this shouldn't be necessary. Especially with the new PHY API
drivers/net/cpsw.c line 457
Quoted 4 lines
drivers/net/cpsw.c new file +4
-0+ +static int cpsw_mdio_read (char *devname,unsigned char phy_id, + ? ? ? ? ? ? ? ? ? ? ? ? unsigned char phy_reg, unsigned short *data) +{
This is the legacy interface for PHY interactions. You should look into using the new "PHYLIB" code.
Quoted 7 lines
+ ? ? ? u32 reg;
(quoted diff) +6
-0+ + ? ? ? if (phy_reg & ~PHY_REG_MASK || phy_id & ~PHY_ID_MASK) + ? ? ? ? ? ? ? return -EINVAL; + + ? ? ? wait_for_user_access(); + ? ? ? reg = (USERACCESS_GO | USERACCESS_READ | (phy_reg << 21) |
Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? ?(phy_id << 16)); + ? ? ? __raw_writel(reg, &mdio_regs->user[0].access); + ? ? ? reg = wait_for_user_access(); + + ? ? ? *data = (reg & USERACCESS_ACK) ? (reg & USERACCESS_DATA) : -1; + ? ? ? return (reg & USERACCESS_ACK) ? 0 : -EIO; +} + +static int cpsw_mdio_write(char *devname, unsigned char phy_id, + ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned char phy_reg, unsigned short data)
Same comment as above.
Quoted 6 lines
(quoted diff) +6
-0+static void cpsw_mdio_init(char *name, u32 mdio_base, u32 div) +{ + ? ? ? mdio_regs = (struct cpsw_mdio_regs *)mdio_base; + + ? ? ? /* set enable and clock divider */ + ? ? ? __raw_writel(div | CONTROL_ENABLE, &mdio_regs->control);
Review
Quoted 10 lines
(quoted diff) +10
-0+ + ? ? ? /* + ? ? ? ?* wait for scan logic to settle: + ? ? ? ?* the scan time consists of (a) a large fixed component, and (b) a + ? ? ? ?* small component that varies with the mii bus frequency. ?These + ? ? ? ?* were estimated using measurements at 1.1 and 2.2 MHz on tnetv107x + ? ? ? ?* silicon. ?Since the effect of (b) was found to be largely + ? ? ? ?* negligible, we keep things simple here. + ? ? ? ?*/ + ? ? ? udelay(1000);
This seems sketchy. Is there no way to *know* the bus is ready, other than to wait?
Quoted 2 lines
+
+ ? ? ?miiphy_register(name, cpsw_mdio_read, cpsw_mdio_write);
This is the legacy API.
drivers/net/cpsw.c line 515
Quoted 8 lines
drivers/net/cpsw.c new file +8
-0+} + +static inline void soft_reset (void *reg) +{ + ? ? ? __raw_writel(1, reg); + ? ? ? while (__raw_readl(reg) & 1) + ? ? ? ? ? ? ? ; +}
???
Can reg be *any* reg? Use a better name. Also, name "1" something sensible.
Perhaps a cleaner implementation (which might be usable in other people's code) would be something like:
/* Set a self-clearing bit in a register, and wait for it to clear */ static inline void setbit_and_wait_for_clear32(void *addr, u32 mask) {
__raw_writel(val, addr);
while (__raw_readl(addr) & val)
; }
Review
Quoted 11 lines
(quoted diff) +11
-0+static void cpsw_slave_update_link(struct cpsw_slave *slave, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct cpsw_priv *priv, int *link) +{ + ? ? ? char *name = priv->dev->name; + ? ? ? int phy_id = slave->data->phy_id; + ? ? ? int speed, duplex; + ? ? ? unsigned short reg; + ? ? ? u32 mac_control = 0; + + ? ? ? if (miiphy_read(name, phy_id, MII_BMSR, ®)) + ? ? ? ? ? ? ? return; /* could not read, assume no link */
Please use phy_read(), with the new API.
Review
Quoted 11 lines
(quoted diff) +11
-0+ + ? ? ? if (reg & BMSR_LSTATUS) { /* link up */ + ? ? ? ? ? ? ? speed = miiphy_speed(name, phy_id); + ? ? ? ? ? ? ? duplex = miiphy_duplex(name, phy_id); + + ? ? ? ? ? ? ? *link = 1; + ? ? ? ? ? ? ? mac_control = priv->data.mac_control; + ? ? ? ? ? ? ? if (speed == 1000) + ? ? ? ? ? ? ? ? ? ? ? mac_control |= BIT(7); ?/* GIGABITEN ? ?*/ + ? ? ? ? ? ? ? if (duplex == FULL) + ? ? ? ? ? ? ? ? ? ? ? mac_control |= BIT(0); ?/* FULLDUPLEXEN */
Why not:
mac_control |= GIGABITEN;
etc
drivers/net/cpsw.c
Quoted 4 lines
drivers/net/cpsw.c new file +4
-0+static int cpsw_update_link (struct cpsw_priv *priv) +{ + ? ? ? int link = 0; + ? ? ? for_each_slave(priv, cpsw_slave_update_link, priv, &link);
As I mentioned, there are a lot of similarly-named macros in Linux and U-boot. Usually they act exactly like for-loops, where you provide an iterator, and then use it in each iteration:
struct cpsw_slave *slave;
for_each_slave(slave, priv)
cpsw_slave_update_link(slave, priv, &link);
I think this is much easier to understand and maintain.
Quoted 1 line
+ ? ? ? return link;
Also, link looks useless. It will always be the value in the last slave. Is that what you meant to do?
Quoted 4 lines
drivers/net/cpsw.c new file +4
-0+} + +static void cpsw_slave_init (struct cpsw_slave *slave,struct cpsw_priv *priv) +{
[...]
Quoted 2 lines
+
+ ? ? ?priv->data.phy_init(priv->dev->name, slave->data->phy_id);
What does this do? Probably needs to be converted to the newer API.
Quoted 87 lines
(quoted diff) +87
-0+} + +static struct cpdma_desc *cpdma_desc_alloc(struct cpsw_priv *priv) +{ + ? ? ? struct cpdma_desc *desc = priv->desc_free; + + ? ? ? if (desc) + ? ? ? ? ? ? ? priv->desc_free = desc_read_ptr(desc, hw_next); + ? ? ? return desc; +} + +static void cpdma_desc_free(struct cpsw_priv *priv, struct cpdma_desc *desc) +{ + ? ? ? if (desc) { + ? ? ? ? ? ? ? desc_write(desc, hw_next, priv->desc_free); + ? ? ? ? ? ? ? priv->desc_free = desc; + ? ? ? } +} + +static int cpdma_submit(struct cpsw_priv *priv, struct cpdma_chan *chan, + ? ? ? ? ? ? ? ? ? ? ? volatile void *buffer, int len) +{ + ? ? ? struct cpdma_desc *desc, *prev; + ? ? ? u32 mode; + + ? ? ? desc = cpdma_desc_alloc(priv); + ? ? ? if (!desc) + ? ? ? ? ? ? ? return -ENOMEM; + + ? ? ? if (len < PKT_MIN) + ? ? ? ? ? ? ? len = PKT_MIN; + + ? ? ? mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; + + ? ? ? desc_write(desc, hw_next, ? 0); + ? ? ? desc_write(desc, hw_buffer, buffer); + ? ? ? desc_write(desc, hw_len, ? ?len); + ? ? ? desc_write(desc, hw_mode, ? mode | len); + ? ? ? desc_write(desc, sw_buffer, buffer); + ? ? ? desc_write(desc, sw_len, ? ?len); + + ? ? ? if (!chan->head) { + ? ? ? ? ? ? ? /* simple case - first packet enqueued */ + ? ? ? ? ? ? ? chan->head = desc; + ? ? ? ? ? ? ? chan->tail = desc; + ? ? ? ? ? ? ? chan_write(chan, hdp, desc); + ? ? ? ? ? ? ? goto done; + ? ? ? } + + ? ? ? /* not the first packet - enqueue at the tail */ + ? ? ? prev = chan->tail; + ? ? ? desc_write(prev, hw_next, desc); + ? ? ? chan->tail = desc; + + ? ? ? /* next check if EOQ has been triggered already */ + ? ? ? if (desc_read(prev, hw_mode) & CPDMA_DESC_EOQ) + ? ? ? ? ? ? ? chan_write(chan, hdp, desc); + +done: + ? ? ? if (chan->rxfree) + ? ? ? ? ? ? ? chan_write(chan, rxfree, 1); + ? ? ? return 0; +} + +static int cpdma_process(struct cpsw_priv *priv, struct cpdma_chan *chan, + ? ? ? ? ? ? ? ? ? ? ? ?void **buffer, int *len) +{ + ? ? ? struct cpdma_desc *desc = chan->head; + ? ? ? u32 status; + + ? ? ? if (!desc) + ? ? ? ? ? ? ? return -ENOENT; + + ? ? ? status ?= desc_read(desc, hw_mode); + + ? ? ? if (len) + ? ? ? ? ? ? ? *len = status & 0x7ff; + + ? ? ? if (buffer) + ? ? ? ? ? ? ? *buffer = desc_read_ptr(desc, sw_buffer); + + ? ? ? if (status & CPDMA_DESC_OWNER) + ? ? ? ? ? ? ? return -EBUSY; + + ? ? ? chan->head = desc_read_ptr(desc, hw_next); + ? ? ? chan_write(chan, cp, desc); +
Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? cpdma_desc_free(priv, desc); + ? ? ? return 0; +} + +static int cpsw_init(struct eth_device *dev, bd_t *bis) +{ + ? ? ? struct cpsw_priv ? ? ? ?*priv = dev->priv; + ? ? ? int i, ret; + + ? ? ? priv->data.control(1);
1 what? The "control" function probably needs a better name. And maybe so does "1".
drivers/net/cpsw.c line 32
Quoted 4 lines
drivers/net/cpsw.c new file +4
-0+ + ? ? ? /* soft reset the controller and initialize priv */ + ? ? ? soft_reset(&priv->regs->soft_reset); +
See comment about soft_reset, above.
Review
Quoted 8 lines
(quoted diff) +8
-0+ + ? ? ? cpsw_ale_port_state(priv, priv->host_port, ALE_PORT_STATE_FORWARD); + + ? ? ? cpsw_ale_add_ucast(priv, priv->dev->enetaddr, priv->host_port, + ? ? ? ? ? ? ? ? ? ? ? ? ?ALE_SECURE); + ? ? ? cpsw_ale_add_mcast(priv, NetBcastAddr, 1 << priv->host_port); + + ? ? ? for_each_slave(priv, cpsw_slave_init, priv);
Same comment as before about the for-loop construct.
[...]
Quoted 3 lines
+ ? ? ?
eth_register(dev);
+
+ ? ? ?cpsw_mdio_init(dev->name, data->mdio_base, data->mdio_div);
I bet you only need one MDIO bus, and the new PHY API makes that straightforward.
Quoted 29 lines
drivers/net/cpsw.c new file +3
-0+ + ? ? ? return 1; +}include/netdev.h +0
-0@@ -185,4 +185,33 @@ struct mv88e61xx_config { ?int mv88e61xx_switch_initialize(struct mv88e61xx_config *swconfig);?#endif /*
CONFIG_MV88E61XX_SWITCH*/include/netdev.h +18
-0+#ifdef CONFIG_DRIVER_TI_CPSW + +struct cpsw_slave_data { + ? ? ? u32 ? ? ? ? ? ? slave_reg_ofs; + ? ? ? u32 ? ? ? ? ? ? sliver_reg_ofs; + ? ? ? int ? ? ? ? ? ? phy_id; +}; + +struct cpsw_platform_data { + ? ? ? u32 ? ? mdio_base; + ? ? ? u32 ? ? cpsw_base; + ? ? ? int ? ? mdio_div; + ? ? ? int ? ? channels; ? ? ? /* number of cpdma channels (symmetric) */ + ? ? ? u32 ? ? cpdma_reg_ofs; ?/* cpdma register offset ? ? ? ? ? ? ? ?*/ + ? ? ? int ? ? slaves; ? ? ? ? /* number of slave cpgmac ports ? ? ? ? */ + ? ? ? u32 ? ? ale_reg_ofs; ? ?/* address lookup engine reg offset ? ? */ + ? ? ? int ? ? ale_entries; ? ?/* ale table size ? ? ? ? ? ? ? ? ? ? ? */ + ? ? ? u32 ? ? host_port_reg_ofs; ? ? ?/* cpdma host port registers ? ?*/
include/netdev.h
Quoted 10 lines
include/netdev.h +10
-0+ ? ? ? u32 ? ? hw_stats_reg_ofs; ? ? ? /* cpsw hw stats counters ? ? ? */ + ? ? ? u32 ? ? mac_control; + ? ? ? struct cpsw_slave_data ?*slave_data; + ? ? ? void ? ?(*control)(int enabled); + ? ? ? void ? ?(*phy_init)(char *name, int addr); +}; + +int cpsw_register(struct cpsw_platform_data *data); + +#endif /* CONFIG_DRIVER_TI_CPSW */
Hmmm... nothing here seems like it should be in a generic header like "netdev.h". Only cpsw_register(), and probably not that, either. I see there's some Marvell stuff in there, too, which is suspect, but let's not propagate that issue. There's a cpu_eth_init() and a board_eth_init(). Surely one of those can call cpsw_register(), and then you can put the cpsw-specific structures in something like include/cpsw.h.
Andy
PATCH v2 1/2 TI: netdev: add driver for cpsw ethernet device
Quoted 8 lines · Andy Fleming
Quoted 5 lines · Chandan Nath
From: Cyril Chemparathy <[email protected]>
CPSW is an on-chip ethernet switch that is found on various SoCs from Texas Instruments. ?This patch adds a simple driver (based on the Linux driver) for this hardware module.
Which Linux driver is this based on?
drivers/net/cpsw.c, which isn't in mainline (and I didn't go running about other maintainer trees). There's a copy over in
http://arago-project.org/git/projects/?p=linux-am33x.git
Signature · 1 line
Tom
Kumar Nath
PATCH v2 1/2 TI: netdev: add driver for cpsw ethernet device
In reply to Andy FlemingAndy,
Quoted 12 lines
-----Original Message-----
From: Andy Fleming [mailto:afleming at gmail.com]
Sent: Friday, November 11, 2011 4:14 AM
To: Kumar Nath, Chandan
Cc: u-boot at lists.denx.de; Chemparathy, Cyril
Subject: Re: [U-Boot] [PATCH v2 1/2] TI: netdev: add driver for cpsw ethernet deviceQuoted 2 lines · Chandan Nath
From: Cyril Chemparathy <[email protected]>
Quoted 8 lines
Quoted 1 line
CPSW is an on-chip ethernet switch that is found on various SoCs from
Texas
Quoted 1 line
Instruments. ?This patch adds a simple driver (based on the Linux
driver) for
Quoted 1 line
this hardware module.
Which Linux driver is this based on?
This is based on linux CPSW driver, which is yet to be up streamed.
Quoted 15 lines
Quoted 10 lines
Signed-off-by Cyril Chemparathy <[email protected]>---
Changes since v1:
?- Code cleanup and removal ofcpsw_eth_set_mac_addrfunction?drivers/net/Makefile | ? ?1 +
?drivers/net/cpsw.c ? | ?862++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 4 lines
?include/netdev.h ? ? | ? 29 ++
?3 files changed, 892 insertions(+), 0 deletions(-) ?create mode 100644drivers/net/cpsw.c
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ +#define BIT(x) ? ? ? ? ? ? ? ? (1 << (x)) +#define BITMASK(bits) ? ? ? ? ?(BIT(bits) - 1) +#define PHY_REG_MASK ? ? ? ? ? 0x1f +#define PHY_ID_MASK ? ? ? ? ? ?0x1fThese 4 defines seem very generic
I did not find any generic code for these definitions in arch/arm and so keeping these definitions here.
Quoted 30 lines
Quoted 14 lines
(quoted diff) +12
-0+struct cpsw_priv { + ? ? ? struct eth_device ? ? ? ? ? ? ? *dev; + ? ? ? struct cpsw_platform_data ? ? ? data; + ? ? ? int ? ? ? ? ? ? ? ? ? ? ? ? ? ? host_port; + + ? ? ? struct cpsw_regs ? ? ? ? ? ? ? ?*regs; + ? ? ? void ? ? ? ? ? ? ? ? ? ? ? ? ? ?*dma_regs; + ? ? ? struct cpsw_host_regs ? ? ? ? ? *host_port_regs; + ? ? ? void ? ? ? ? ? ? ? ? ? ? ? ? ? ?*ale_regs; + + ? ? ? struct cpdma_desc ? ? ? ? ? ? ? descs[NUM_DESCS]; + ? ? ? struct cpdma_desc ? ? ? ? ? ? ? *desc_free;Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? struct cpdma_chan ? ? ? ? ? ? ? rx_chan, tx_chan; + + ? ? ? struct cpsw_slave ? ? ? ? ? ? ? *slaves; +#define for_each_slave(priv, func, arg...) ? ? ? ? ? ? ? ? ? ? \ + ? ? ? do { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ? ? ? ? ? ? int idx; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ + ? ? ? ? ? ? ? for (idx = 0; idx < (priv)->data.slaves; idx++) \ + ? ? ? ? ? ? ? ? ? ? ? (func)((priv)->slaves + idx, ##arg); ? ?\ + ? ? ? } while (0) +};It seems a bit awkward to me to put a complex macro like this inside the structure definition. After further review, I think it should also be defined differently, more like the list macros:
Quoted 8 lines
#define for_each_slave(slave, priv) \ for (slave = (priv)->slaves; slave != (priv)->slaves +(priv)->data.slaves; slave++)
It makes the code more maintainable, as the macro no longer contains the implicit assumption that "func" has a slave pointer as its first argument.
This complex macro will be separated out and will be defined like list macros as you have mentioned above.
Quoted 15 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32bits)
Review
Quoted 10 lines
(quoted diff) +10
-0+{ + ? ? ? int idx; + + ? ? ? idx ? ?= start / 32; + ? ? ? start -= idx * 32; + ? ? ? idx ? ?= 2 - idx; /* flip */ + ? ? ? return (ale_entry[idx] >> start) & BITMASK(bits); +} + +static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32bits,
Quoted 15 lines
Review
Quoted 11 lines
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? u32 value)
(quoted diff) +10
-0+{ + ? ? ? int idx; + + ? ? ? value &= BITMASK(bits); + ? ? ? idx ? ?= start / 32; + ? ? ? start -= idx * 32; + ? ? ? idx ? ?= 2 - idx; /* flip */ + ? ? ? ale_entry[idx] &= ~(BITMASK(bits) << start); + ? ? ? ale_entry[idx] |= ?(value << start); +}These two functions seem both very generic, and also over-worked.
Should this be changed to a different implementation?
Quoted 80 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +#define DEFINE_ALE_FIELD(name, start, bits)? ?\
Quoted 1 line
+static inline int cpsw_ale_get_##name(u32
*ale_entry)? ?\
Quoted 1 line
+{
? ?\
Quoted 1 line
+ ? ? ? return
cpsw_ale_get_field(ale_entry, start, bits);? ?\
Quoted 1 line
+}
? ?\
Quoted 1 line
+static inline void cpsw_ale_set_##name(u32
*ale_entry, u32 value)? ?\
Quoted 1 line
+{
? ?\
Quoted 1 line
+ ? ? ?
cpsw_ale_set_field(ale_entry, start, bits, value);? ?\
Review
Quoted 12 lines
(quoted diff) +12
-0+} + +DEFINE_ALE_FIELD(entry_type, ? ? ? ? ? 60, ? ? 2) +DEFINE_ALE_FIELD(mcast_state, ? ? ? ? ?62, ? ? 2) +DEFINE_ALE_FIELD(port_mask, ? ? ? ? ? ?64, ? ? 3) +DEFINE_ALE_FIELD(ucast_type, ? ? ? ? ? 66, ? ? 2) +DEFINE_ALE_FIELD(port_num, ? ? ? ? ? ? 64, ? ? 2) +DEFINE_ALE_FIELD(blocked, ? ? ? ? ? ? ?63, ? ? 1) +DEFINE_ALE_FIELD(secure, ? ? ? ? ? ? ? 62, ? ? 1) +DEFINE_ALE_FIELD(mcast, ? ? ? ? ? ? ? ? ? ? ? ?47, ? ? 1) + +/* The MAC address field in the ALE entry cannot be macroized asabove */
Quoted 7 lines
drivers/net/cpsw.c new file +7
-0+static inline void cpsw_ale_get_addr (u32 *ale_entry,u8 *addr) +{ + ? ? ? int i; + + ? ? ? for (i = 0; i < 6; i++) + ? ? ? ? ? ? ? addr[i] = cpsw_ale_get_field(ale_entry, 40 - 8*i, 8); +}drivers/net/cpsw.c
Quoted 10 lines
drivers/net/cpsw.c new file +10
-0+ +static inline void cpsw_ale_set_addr (u32 *ale_entry,u8 *addr) +{ + ? ? ? int i; + + ? ? ? for (i = 0; i < 6; i++) + ? ? ? ? ? ? ? cpsw_ale_set_field(ale_entry, 40 - 8*i, 8, addr[i]); +} + +static int cpsw_ale_read(struct cpsw_priv *priv, int idx, u32
*ale_entry)Review
Quoted 7 lines
(quoted diff) +7
-0+{ + ? ? ? int i; + + ? ? ? __raw_writel(idx, priv->ale_regs + ALE_TABLE_CONTROL); + + ? ? ? for (i = 0; i < ALE_ENTRY_WORDS; i++) + ? ? ? ? ? ? ? ale_entry[i] = __raw_readl(priv->ale_regs + ALE_TABLE+ 4 * i);
drivers/net/cpsw.c
Quoted 5 lines
drivers/net/cpsw.c new file +5
-0+ + ? ? ? return idx; +} + +static int cpsw_ale_write(struct cpsw_priv *priv, int idx, u32
*ale_entry)Review
Quoted 5 lines
(quoted diff) +5
-0+{ + ? ? ? int i; + + ? ? ? for (i = 0; i < ALE_ENTRY_WORDS; i++) + ? ? ? ? ? ? ? __raw_writel(ale_entry[i], priv->ale_regs + ALE_TABLE+ 4 * i);
Quoted 2 lines
+
+ ? ? ? __raw_writel(idx |ALE_TABLE_WRITE,priv->ale_regs+
ALE_TABLE_CONTROL);drivers/net/cpsw.c line 228
Quoted 3 lines
drivers/net/cpsw.c new file +3
-0+ + ? ? ? return idx; +}I don't know how your device works, but it seems odd to me to have to read out a large table, and modify it, and then write it back out.
Quoted 5 lines
I'm also highly suspicious of the overworked bitfield math. Are standard C bitfields not usable for some reason? It borders on code obfuscation, IMO. I've spent far too much time, already, just trying to figure out what that code was doing, and why.
I will think of some standard C bitfields to make it simpler.
Quoted 15 lines
Quoted 1 line
+static inline void cpsw_ale_port_state(struct
cpsw_priv*priv, intport,
Review
Quoted 8 lines
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int val)
(quoted diff) +7
-0+{ + ? ? ? int offset = ALE_PORTCTL + 4 * port; + ? ? ? u32 tmp, mask = 0x3; + + ? ? ? tmp ?= __raw_readl(priv->ale_regs + offset); + ? ? ? tmp &= ~mask; + ? ? ? tmp |= val & 0x3;All of this can probably be done with more generic setbits functions, but at least use "mask" consistently for both the clearing and the masking of "val".
Ok, mask will be used consistently.
Quoted 9 lines
drivers/net/cpsw.c line 435
Quoted 4 lines
+ ? ? ?
__raw_writel(tmp, priv->ale_regs + offset);drivers/net/cpsw.c new file +3
-0+} + +static struct cpsw_mdio_regs *mdio_regs;Global variables like this shouldn't be necessary. Especially with the new PHY API
This global variable is required to access mdio registers across different functions.
Quoted 11 lines
drivers/net/cpsw.c
Quoted 5 lines
drivers/net/cpsw.c new file +3
-0+ +static int cpsw_mdio_read (char *devname,unsigned char phy_id, + ? ? ? ? ? ? ? ? ? ? ? ? unsigned char phy_reg, unsigned short*data)
Quoted 1 line
+{
This is the legacy interface for PHY interactions. You should look into using the new "PHYLIB" code.
Sure, I will be using new "PHYLIB" code instead of this legacy code.
Quoted 14 lines
Review
Quoted 13 lines
+ ? ? ? u32 reg;
(quoted diff) +11
-0+ + ? ? ? if (phy_reg & ~PHY_REG_MASK || phy_id & ~PHY_ID_MASK) + ? ? ? ? ? ? ? return -EINVAL; + + ? ? ? wait_for_user_access(); + ? ? ? reg = (USERACCESS_GO | USERACCESS_READ | (phy_reg << 21) | + ? ? ? ? ? ? ?(phy_id << 16)); + ? ? ? __raw_writel(reg, &mdio_regs->user[0].access); + ? ? ? reg = wait_for_user_access(); + + ? ? ? *data = (reg & USERACCESS_ACK) ? (reg & USERACCESS_DATA) : -1;
Quoted 9 lines
drivers/net/cpsw.c
Quoted 5 lines
+ ? ? ? return (reg &
USERACCESS_ACK) ? 0 :-EIO;drivers/net/cpsw.c new file +4
-0+} + +static int cpsw_mdio_write (char *devname,unsigned char phy_id, + ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned char phy_reg, unsigned shortdata)
Same comment as above.
Yes, I will use "PHYLIB" code instead of legacy code.
Quoted 21 lines
Review
Quoted 11 lines
(quoted diff) +10
-0+static void cpsw_mdio_init(char *name, u32 mdio_base, u32 div) +{ + ? ? ? mdio_regs = (struct cpsw_mdio_regs *)mdio_base; + + ? ? ? /* set enable and clock divider */ + ? ? ? __raw_writel(div | CONTROL_ENABLE, &mdio_regs->control); + + ? ? ? /* + ? ? ? ?* wait for scan logic to settle: + ? ? ? ?* the scan time consists of (a) a large fixed component, and(b) a
Quoted 1 line
+ ? ? ? ?* small component that varies with the mii bus frequency.
?These
Quoted 1 line
+ ? ? ? ?* were estimated using measurements at 1.1 and 2.2 MHz on
tnetv107x
Quoted 4 lines
+ ? ? ? ?* silicon. ?Since the effect of (b) was found to be largely
+ ? ? ? ?* negligible, we keep things simple here.
+ ? ? ? ?*/
+ ? ? ? udelay(1000);
Quoted 9 lines
This seems sketchy. Is there no way to *know* the bus is ready, other than to wait?
Quoted 2 lines
+
+ ? ? ?miiphy_register(name, cpsw_mdio_read, cpsw_mdio_write);This is the legacy API.
PHYLIB code will be used instead of this.
Quoted 19 lines
drivers/net/cpsw.c line 515
Quoted 9 lines
drivers/net/cpsw.c new file +8
-0+} + +static inline void soft_reset (void *reg) +{ + ? ? ? __raw_writel(1, reg); + ? ? ? while (__raw_readl(reg) & 1) + ? ? ? ? ? ? ? ; +}???
Can reg be *any* reg? Use a better name. Also, name "1" something sensible.
Perhaps a cleaner implementation (which might be usable in other people's code) would be something like:
Quoted 9 lines
/* Set a self-clearing bit in a register, and wait for it to clear */ static inline void
setbit_and_wait_for_clear32(void *addr, u32 mask){ __raw_writel(val, addr); while (__raw_readl(addr) & val) ; }
Ok, I will implement this in a cleaner manner.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+static void cpsw_slave_update_link(struct cpsw_slave *slave, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct cpsw_priv *priv, int *link) +{ + ? ? ? char *name = priv->dev->name; + ? ? ? int phy_id = slave->data->phy_id; + ? ? ? int speed, duplex;
Quoted 9 lines
Quoted 5 lines
+ ? ? ? unsigned short reg;
+ ? ? ? u32mac_control= 0;
+
+ ? ? ? if (miiphy_read(name, phy_id, MII_BMSR, ®))
+ ? ? ? ? ? ? ? return; /* could not read, assume no link */Please use
phy_read(), with the new API.
Ok, I will use phy_read(), instead of miiphy_read.
Quoted 14 lines
Review
Quoted 12 lines
(quoted diff) +11
-0+ + ? ? ? if (reg & BMSR_LSTATUS) { /* link up */ + ? ? ? ? ? ? ? speed = miiphy_speed(name, phy_id); + ? ? ? ? ? ? ? duplex = miiphy_duplex(name, phy_id); + + ? ? ? ? ? ? ? *link = 1; + ? ? ? ? ? ? ? mac_control = priv->data.mac_control; + ? ? ? ? ? ? ? if (speed == 1000) + ? ? ? ? ? ? ? ? ? ? ? mac_control |= BIT(7); ?/* GIGABITEN ? ?*/ + ? ? ? ? ? ? ? if (duplex == FULL) + ? ? ? ? ? ? ? ? ? ? ? mac_control |= BIT(0); ?/* FULLDUPLEXEN */Why not:
Quoted 4 lines
mac_control |= GIGABITEN;etc
Sure, I will make this change.
Quoted 16 lines
drivers/net/cpsw.c
Quoted 6 lines
drivers/net/cpsw.c new file +4
-0+static int cpsw_update_link (struct cpsw_priv *priv) +{ + ? ? ? int link = 0; + ? ? ? for_each_slave(priv, cpsw_slave_update_link, priv, &link);As I mentioned, there are a lot of similarly-named macros in Linux and U-boot. Usually they act exactly like for-loops, where you provide an iterator, and then use it in each iteration:
struct
cpsw_slave*slave;
for_each_slave(slave, priv)
cpsw_slave_update_link(slave, priv, &link);
Quoted 8 lines
I think this is much easier to understand and maintain.
Quoted 1 line
+ ? ? ? return link;
Also, link looks useless. It will always be the value in the last slave. Is that what you meant to do?
Ok, I will use this as per your comment.for_each_slave(slave, priv)
cpsw_slave_update_link(slave, priv, &link);
Also, I am returning link which returns the value of last slave.
Quoted 4 lines
drivers/net/cpsw.c
Quoted 3 lines
drivers/net/cpsw.c new file +3
-0+} + +static void cpsw_slave_init(struct cpsw_slave *slave, struct
cpsw_priv*priv)
Quoted 9 lines
Quoted 1 line
+{
[...]
Quoted 2 lines
+
+ ? ? ?priv->data.phy_init(priv->dev->name, slave->data->phy_id);What does this do? Probably needs to be converted to the newer API.
I will remove this and new PHYLIB APIs will be used instead.
Quoted 96 lines
drivers/net/cpsw.c
Quoted 13 lines
drivers/net/cpsw.c new file +12
-0+} + +static struct cpdma_desc *cpdma_desc_alloc (struct cpsw_priv *priv) +{ + ? ? ? struct cpdma_desc *desc = priv->desc_free; + + ? ? ? if (desc) + ? ? ? ? ? ? ? priv->desc_free = desc_read_ptr(desc, hw_next); + ? ? ? return desc; +} + +static void cpdma_desc_free(struct cpsw_priv *priv, struct
cpdma_desc*desc)Review
Quoted 8 lines
(quoted diff) +8
-0+{ + ? ? ? if (desc) { + ? ? ? ? ? ? ? desc_write(desc, hw_next, priv->desc_free); + ? ? ? ? ? ? ? priv->desc_free = desc; + ? ? ? } +} + +static int cpdma_submit(struct cpsw_priv *priv, struct cpdma_chan*chan,
Quoted 35 lines
+ ? ? ? ? ? ? ? ? ? ? ? volatile void *buffer, int len)
(quoted diff) +34
-0+{ + ? ? ? struct cpdma_desc *desc, *prev; + ? ? ? u32 mode; + + ? ? ? desc = cpdma_desc_alloc(priv); + ? ? ? if (!desc) + ? ? ? ? ? ? ? return -ENOMEM; + + ? ? ? if (len < PKT_MIN) + ? ? ? ? ? ? ? len = PKT_MIN; + + ? ? ? mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; + + ? ? ? desc_write(desc, hw_next, ? 0); + ? ? ? desc_write(desc, hw_buffer, buffer); + ? ? ? desc_write(desc, hw_len, ? ?len); + ? ? ? desc_write(desc, hw_mode, ? mode | len); + ? ? ? desc_write(desc, sw_buffer, buffer); + ? ? ? desc_write(desc, sw_len, ? ?len); + + ? ? ? if (!chan->head) { + ? ? ? ? ? ? ? /* simple case - first packet enqueued */ + ? ? ? ? ? ? ? chan->head = desc; + ? ? ? ? ? ? ? chan->tail = desc; + ? ? ? ? ? ? ? chan_write(chan, hdp, desc); + ? ? ? ? ? ? ? goto done; + ? ? ? } + + ? ? ? /* not the first packet - enqueue at the tail */ + ? ? ? prev = chan->tail; + ? ? ? desc_write(prev, hw_next, desc); + ? ? ? chan->tail = desc; + + ? ? ? /* next check if EOQ has been triggered already */Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? if (desc_read(prev, hw_mode) & CPDMA_DESC_EOQ) + ? ? ? ? ? ? ? chan_write(chan, hdp, desc); + +done: + ? ? ? if (chan->rxfree) + ? ? ? ? ? ? ? chan_write(chan, rxfree, 1); + ? ? ? return 0; +} + +static int cpdma_process(struct cpsw_priv *priv, struct cpdma_chan*chan,
Quoted 27 lines
+ ? ? ? ? ? ? ? ? ? ? ? ?void **buffer, int *len)
(quoted diff) +26
-0+{ + ? ? ? struct cpdma_desc *desc = chan->head; + ? ? ? u32 status; + + ? ? ? if (!desc) + ? ? ? ? ? ? ? return -ENOENT; + + ? ? ? status ?= desc_read(desc, hw_mode); + + ? ? ? if (len) + ? ? ? ? ? ? ? *len = status & 0x7ff; + + ? ? ? if (buffer) + ? ? ? ? ? ? ? *buffer = desc_read_ptr(desc, sw_buffer); + + ? ? ? if (status & CPDMA_DESC_OWNER) + ? ? ? ? ? ? ? return -EBUSY; + + ? ? ? chan->head = desc_read_ptr(desc, hw_next); + ? ? ? chan_write(chan, cp, desc); + + ? ? ? cpdma_desc_free(priv, desc); + ? ? ? return 0; +} + +static int cpsw_init(struct eth_device *dev, bd_t *bis)
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+{ + ? ? ? struct cpsw_priv ? ? ? ?*priv = dev->priv; + ? ? ? int i, ret; + + ? ? ? priv->data.control(1);1 what? The "control" function probably needs a better name. And maybe so does "1".
This is not required and will be removed from the code.
Quoted 7 lines
drivers/net/cpsw.c line 32
Quoted 4 lines
drivers/net/cpsw.c new file +4
-0+ + ? ? ? /* soft reset the controller and initialize priv */ + ? ? ? soft_reset(&priv->regs->soft_reset); +See comment about
soft_reset, above.
Ok, I will address this as above.
Quoted 13 lines
Quoted 2 lines
+
+ ? ? ? cpsw_ale_port_state(priv,priv->host_port,
ALE_PORT_STATE_FORWARD);Quoted 7 lines
+
+ ? ? ? cpsw_ale_add_ucast(priv,priv->dev->enetaddr, priv-host_port,
+ ? ? ? ? ? ? ? ? ? ? ? ? ?ALE_SECURE);
+ ? ? ?cpsw_ale_add_mcast(priv, NetBcastAddr, 1 << priv->host_port); +
+ ? ? ?for_each_slave(priv, cpsw_slave_init, priv);Same comment as before about the for-loop construct.
Ok, will address in similar way as above.
Quoted 9 lines
[...]
Quoted 3 lines
+ ? ? ?
eth_register(dev);
+
+ ? ? ?cpsw_mdio_init(dev->name, data->mdio_base, data->mdio_div);I bet you only need one MDIO bus, and the new PHY API makes that straightforward.
Yes, I will use new PHYLIB APIs.
Quoted 47 lines
Quoted 14 lines
drivers/net/cpsw.c new file +3
-0+ + ? ? ? return 1; +}include/netdev.h +0
-0@@ -185,4 +185,33 @@ struct mv88e61xx_config { ?int mv88e61xx_switch_initialize(struct mv88e61xx_config *swconfig);?#endif /*
CONFIG_MV88E61XX_SWITCH*/include/netdev.h +3
-0+#ifdef CONFIG_DRIVER_TI_CPSW + +struct cpsw_slave_data {include/netdev.h
Quoted 10 lines
include/netdev.h +10
-0+ ? ? ? u32 ? ? ? ? ? ? slave_reg_ofs; + ? ? ? u32 ? ? ? ? ? ? sliver_reg_ofs; + ? ? ? int ? ? ? ? ? ? phy_id; +}; + +struct cpsw_platform_data { + ? ? ? u32 ? ? mdio_base; + ? ? ? u32 ? ? cpsw_base; + ? ? ? int ? ? mdio_div; + ? ? ? int ? ? channels; ? ? ? /* number of cpdma channels(symmetric) */
Quoted 1 line
+ ? ? ? u32 ? ?
cpdma_reg_ofs; ?/* cpdma register offset? ?*/
Quoted 1 line
+ ? ? ? int ? ? slaves; ? ? ? ? /* number of slave cpgmac ports
? */
Quoted 1 line
+ ? ? ? u32 ? ?
ale_reg_ofs; ? ?/* address lookup engine reg offset? */
Quoted 1 line
+ ? ? ? int ? ?
ale_entries; ? ?/* ale table size? */
Quoted 1 line
+ ? ? ? u32 ? ?
host_port_reg_ofs; ? ? ?/* cpdma host port registers? ?*/
Quoted 1 line
+ ? ? ? u32 ? ?
hw_stats_reg_ofs; ? ? ? /* cpsw hw stats counters? */
include/netdev.h struct mv88e61xx_config { · line 215
Quoted 9 lines
+ ? ? ? u32 ? ?
mac_control;
+ ? ? ? structcpsw_slave_data?*slave_data;
+ ? ? ? void ? ?(*control)(int enabled);
+ ? ? ? void ? ?(*phy_init)(char *name, int addr);include/netdev.h +5
-0+}; + +int cpsw_register (struct cpsw_platform_data *data); + +#endif /* CONFIG_DRIVER_TI_CPSW */
Quoted 8 lines
Hmmm... nothing here seems like it should be in a generic header like "
netdev.h". Onlycpsw_register(), and probably not that, either. I see there's some Marvell stuff in there, too, which is suspect, but let's not propagate that issue. There's acpu_eth_init()and aboard_eth_init(). Surely one of those can callcpsw_register(), and then you can put the cpsw-specific structures in something likeinclude/cpsw.h.
Sure, I will remove this code from netdev.h and will keep in separate cpsw header, i.e. cpsw.h
Quoted 1 line
Andy
PATCH v2 2/2 ARM:AM33XX:Added cpsw support for AM335x EVM
In reply to Chandan NathThis patch adds cpsw support on AM335X EVM.
---
Changes since v1:
- Added weak alias miiphy_is_1000base_x function to fix atheros phy issue
arch/arm/cpu/armv7/am33xx/clock.c | 9 ++- arch/arm/include/asm/arch-am33xx/cpu.h | 22 ++++- arch/arm/include/asm/arch-am33xx/hardware.h | 5 + board/ti/am335x/common_def.h | 2 + board/ti/am335x/evm.c | 149 +++++++++++++++++++++++++++ board/ti/am335x/mux.c | 24 +++++ common/miiphyutil.c | 5 +- drivers/net/cpsw.c | 147 ++++++++++++++++++-------- include/configs/am335x_evm.h | 16 +++- include/netdev.h | 19 +++- 10 files changed, 341 insertions(+), 57 deletions(-)
arch/arm/cpu/armv7/am33xx/clock.c +8 -1
@@ -24,6 +24,7 @@#define PRCM_MOD_EN 0x2#define PRCM_FORCE_WAKEUP 0x2 +#define PRCM_FUNCTL 0x0#define PRCM_EMIF_CLK_ACTIVITY BIT(2)#define PRCM_L3_GCLK_ACTIVITY BIT(4)
@@ -38,7 +39,7 @@#define CLK_MODE_SEL 0x7#define CLK_MODE_MASK 0xfffffff8#define CLK_DIV_SEL 0xFFFFFFE0 - +#define CPGMAC0_IDLE 0x30000const struct cm_perpll *cmper = (struct cm_perpll *)CM_PER ;const struct cm_wkuppll *cmwkup = (struct cm_wkuppll *)CM_WKUP ;
@@ -105,6 +106,12 @@ static void enable_per_clocks(void)writel (PRCM_MOD_EN , &cmwkup->wkup_uart0ctrl);while (readl (&cmwkup->wkup_uart0ctrl) !=PRCM_MOD_EN ) ; + +/* Ethernet */ +writel (PRCM_MOD_EN , &cmper->cpgmac0clkctrl); +writel (PRCM_MOD_EN , &cmper->cpswclkstctrl); +while ((readl (&cmper->cpgmac0clkctrl) &CPGMAC0_IDLE ) !=PRCM_FUNCTL ) + ; }static void mpu_pll_config (void )
arch/arm/include/asm/arch-am33xx/cpu.h +19 -3
@@ -108,7 +108,9 @@ struct cm_perpll {unsigned int l3sclkstctrl;/* offset 0x04 */ unsigned int l4fwclkstctrl;/* offset 0x08 */ unsigned int l3clkstctrl;/* offset 0x0c */ -unsigned int resv1[6 ]; +unsigned int resv0[1 ]; +unsigned int cpgmac0clkctrl;/* offset 0x14 */ +unsigned int resv1[4 ];unsigned int emifclkctrl;/* offset 0x28 */ unsigned int ocmcramclkctrl;/* offset 0x2c */ unsigned int resv2[12 ];
@@ -124,6 +126,8 @@ struct cm_perpll {unsigned int resv6[14 ];unsigned int l4hsclkstctrl;/* offset 0x11C */ unsigned int l4hsclkctrl;/* offset 0x120 */ +unsigned int resv7[8 ]; +unsigned int cpswclkstctrl;/* offset 0x144 */ };/* Encapsulating Display pll registers */
@@ -173,9 +177,9 @@ struct timer_reg {/* Timer 32 bit registers */ struct gptimer {unsigned int tidr;/* offset 0x00 */ -unsigned int res1[0xc ]; +unsigned int res1[3 ];unsigned int tiocp_cfg;/* offset 0x10 */ -unsigned int res2[0xc ]; +unsigned int res2[3 ];unsigned int tier;/* offset 0x20 */ unsigned int tistatr;/* offset 0x24 */ unsigned int tistat;/* offset 0x28 */
@@ -211,6 +215,18 @@ struct ctrl_stat {unsigned int statusreg;/* ofset 0x40 */ }; +/* Control Device Register */ +struct ctrl_dev { +unsigned int deviceid;/* offset 0x00 */ +unsigned int resv1[11 ]; +unsigned int macid0l;/* offset 0x30 */ +unsigned int macid0h;/* offset 0x34 */ +unsigned int macid1l;/* offset 0x38 */ +unsigned int macid1h;/* offset 0x3c */ +unsigned int resv2[4 ]; +unsigned int miisel;/* offset 0x50 */ +}; +void init_timer (void );#endif /* __ASSEMBLY__ */ #endif /* __KERNEL_STRICT_NAMES */
arch/arm/include/asm/arch-am33xx/hardware.h +5 -0
@@ -46,6 +46,7 @@/* Control Module Base Address */ #define CTRL_BASE 0x44E10000 +#define CTRL_DEVICE_BASE 0x44E10600/* PRCM Base Address */ #define PRCM_BASE 0x44E00000
@@ -78,4 +79,8 @@#define DDRPHY_0_CONFIG_BASE (CTRL_BASE + 0x1400)#define DDRPHY_CONFIG_BASE DDRPHY_0_CONFIG_BASE +/* CPSW Config space */ +#define AM335X_CPSW_BASE 0x4A100000 +#define AM335X_CPSW_MDIO_BASE 0x4A101000 +#endif /* __AM33XX_HARDWARE_H */
board/ti/am335x/common_def.h +2 -0
@@ -17,8 +17,10 @@#define __COMMON_DEF_H__extern void enable_uart0_pin_mux (void ); +extern void enable_rgmii1_pin_mux (void );extern void configure_evm_pin_mux (unsigned char daughter_board_id,unsigned short daughter_board_profile,unsigned char daughter_board_flag); +extern void cpsw_eth_set_mac_addr (const unsigned char *addr);#endif /*__COMMON_DEF_H__ */
board/ti/am335x/evm.c +149 -0
168 lines not on this page · raw message
board/ti/am335x/mux.c +24 -0
@@ -258,6 +258,24 @@ static struct module_pin_mux uart0_pin_mux[] = { {-1}, }; +static struct module_pin_mux rgmii1_pin_mux[] = { + {OFFSET (mii1_txen),MODE (2 )},/* RGMII1_TCTL */ + {OFFSET (mii1_rxdv),MODE (2 ) |RXACTIVE },/* RGMII1_RCTL */ + {OFFSET (mii1_txd3),MODE (2 )},/* RGMII1_TD3 */ + {OFFSET (mii1_txd2),MODE (2 )},/* RGMII1_TD2 */ + {OFFSET (mii1_txd1),MODE (2 )},/* RGMII1_TD1 */ + {OFFSET (mii1_txd0),MODE (2 )},/* RGMII1_TD0 */ + {OFFSET (mii1_txclk),MODE (2 )},/* RGMII1_TCLK */ + {OFFSET (mii1_rxclk),MODE (2 ) |RXACTIVE },/* RGMII1_RCLK */ + {OFFSET (mii1_rxd3),MODE (2 ) |RXACTIVE },/* RGMII1_RD3 */ + {OFFSET (mii1_rxd2),MODE (2 ) |RXACTIVE },/* RGMII1_RD2 */ + {OFFSET (mii1_rxd1),MODE (2 ) |RXACTIVE },/* RGMII1_RD1 */ + {OFFSET (mii1_rxd0),MODE (2 ) |RXACTIVE },/* RGMII1_RD0 */ + {OFFSET (mdio_data),MODE (0 ) |RXACTIVE |PULLUP_EN },/* MDIO_DATA */ + {OFFSET (mdio_clk),MODE (0 ) |PULLUP_EN },/* MDIO_CLK */ + {-1 }, +}; +/* * Configure the pin mux for the module */
@@ -276,3 +294,9 @@ void enable_uart0_pin_mux(void) {configure_module_pin_mux (uart0_pin_mux); } + + +void enable_rgmii1_pin_mux (void ) +{ +configure_module_pin_mux (rgmii1_pin_mux); +}
common/miiphyutil.c +4 -1
@@ -548,7 +548,7 @@ miiphy_read_failed:* Return 1 if PHY supports 1000BASE-X, 0 if PHY supports 10BASE-T/100BASE-TX/ * 1000BASE-T, or on error. */ -int miiphy_is_1000base_x (const char *devname,unsigned char addr) +static int __miiphy_is_1000base_x (const char *devname,unsigned char addr) {#if defined(CONFIG_PHY_GIGE )u16 exsr;
@@ -564,6 +564,9 @@ int miiphy_is_1000base_x(const char *devname, unsigned char addr)#endif } +int miiphy_is_1000base_x (const char *devname,unsigned char addr) + __attribute__((weak,alias ("__miiphy_is_1000base_x" ))); +#ifdef CONFIG_SYS_FAULT_ECHO_LINK_DOWN /***************************************************************************** *
drivers/net/cpsw.c +102 -45
243 lines not on this page · raw message
include/configs/am335x_evm.h +15 -1
@@ -21,7 +21,6 @@#undef CONFIG_GZIP#undef CONFIG_ZLIB#undef CONFIG_SYS_HUSH_PARSER -#undef CONFIG_CMD_NET#include <asm/arch/cpu.h> #include <asm/arch/hardware.h>
@@ -116,6 +115,21 @@#define CONFIG_SYS_TEXT_BASE 0x402f0400 +# define CONFIG_CMD_NET +# define CONFIG_CMD_DHCP +# define CONFIG_CMD_PING +# define CONFIG_DRIVER_TI_CPSW +# define CONFIG_MII +# define CONFIG_BOOTP_DEFAULT +# define CONFIG_BOOTP_DNS +# define CONFIG_BOOTP_DNS2 +# define CONFIG_BOOTP_SEND_HOSTNAME +# define CONFIG_BOOTP_GATEWAY +# define CONFIG_BOOTP_SUBNETMASK +# define CONFIG_NET_RETRY_COUNT 10 +# define CONFIG_NET_MULTI +# define CONFIG_PHY_GIGE +/* Unsupported features */ #undef CONFIG_USE_IRQ
include/netdev.h +13 -6
@@ -193,21 +193,28 @@ struct cpsw_slave_data {int phy_id; }; +enum { +CPSW_CTRL_VERSION_1 =0 ,/* version1 devices */ +CPSW_CTRL_VERSION_2 /* version2 devices */ +}; +struct cpsw_platform_data {u32 mdio_base;u32 cpsw_base;int mdio_div; -int channels;/* number of cpdma channels (symmetric) */ -u32 cpdma_reg_ofs;/* cpdma register offset */ -int slaves;/* number of slave cpgmac ports */ -u32 ale_reg_ofs;/* address lookup engine reg offset */ -int ale_entries;/* ale table size */ +int channels;/* number of cpdma channels (symmetric) */ +u32 cpdma_reg_ofs;/* cpdma register offset */ +int slaves;/* number of slave cpgmac ports */ +u32 ale_reg_ofs;/* address lookup engine reg offset */ +int ale_entries;/* ale table size */ u32 host_port_reg_ofs;/* cpdma host port registers */ u32 hw_stats_reg_ofs;/* cpsw hw stats counters */ u32 mac_control; -struct cpsw_slave_data *slave_data; +struct cpsw_slave_data *slave_data;void (*control)(int enabled);void (*phy_init)(char *name,int addr); +u32 host_port_num; +u8 version; };int cpsw_register (struct cpsw_platform_data *data);
Signature · 1 line
1.7.1
PATCH v2 2/2 ARM:AM33XX:Added cpsw support for AM335x EVM
Quoted 3 lines · Chandan Nath
This patch adds cpsw support on AM335X EVM.
Signed-off-by Chandan Nath <[email protected]>
You aren't allowed to have hard-coded MACs anymore, iirc. And everyone will be able to get valid MACs from the e-fuse (or on the other platforms, EEPROM), we need to drop that particular debug print and just fail when ethaddr isn't set. So you can drop the ..set_mac_addr function, and fold the rest of the changes to cpsw.c into the original patch. Finally, please split the miiphyutil.c change into its own commit. Thanks.
Signature · 1 line
Tom
Kumar Nath
PATCH v2 2/2 ARM:AM33XX:Added cpsw support for AM335x EVM
Quoted 16 lines
-----Original Message-----
From: Tom Rini [mailto:tom.rini at gmail.com]
Sent: Thursday, November 10, 2011 8:17 PM
To: Kumar Nath, Chandan
Cc: u-boot at lists.denx.de
Subject: Re: [U-Boot] [PATCH v2 2/2] ARM:AM33XX:Added cpsw support for AM335x EVMQuoted 3 lines · Chandan Nath
This patch adds cpsw support on AM335X EVM.
Signed-off-by Chandan Nath <[email protected]>
Quoted 8 lines
You aren't allowed to have hard-coded MACs anymore, iirc. And everyone will be able to get valid MACs from the e-fuse (or on the other platforms, EEPROM), we need to drop that particular debug print and just fail when ethaddr isn't set. So you can drop the ..set_mac_addr function, and fold the rest of the changes to
cpsw.cinto the original patch. Finally, please split themiiphyutil.cchange into its own commit. Thanks.
I will remove the debug print and return failure when ethaddr is not set. I have already remove cpsw_eth_set_mac_addr function from cpsw.c and pushed to the original patch.
I will split miiphyutil.c changes in to a separate patch.
Quoted 2 lines
--
Tom
PATCH v2 2/2 ARM:AM33XX:Added cpsw support for AM335x EVM
In reply to Chandan Nath #ifdef CONFIG_ARCH_EBSA110
# ifdef machine_arch_type @@ -42913,6 +42915,19 @@ extern unsigned int __machine_arch_type; # define machine_is_goflexhome() (0) #endif
+#ifdef CONFIG_MACH_TIAM335EVM
+# ifdef machine_arch_type
+# undef machine_arch_type
+# define machine_arch_type __machine_arch_type
+# else
+# define machine_arch_type MACH_TYPE_TIAM335EVM
+# endif
+# define machine_is_tiam335evm() (machine_arch_type == MACH_TYPE_TIAM335EVM) +#else
+# define machine_is_tiam335evm() (0)
+#endif
+
+
/*
* These have not yet been registered
*/
board/ti/am335x/evm.c +10 -9
@@ -57,6 +57,15 @@ int board_init(void) }#ifdef CONFIG_DRIVER_TI_CPSW +/* Atheros PHY report 1000baseX speed incorrectly and so this function +* is define to overcome this issue. The original code is kept as +* _miiphy_is_1000base_x as an weak alias to this function. +*/ +int miiphy_is_1000base_x (const char *devname,unsigned char addr) +{ +return 0 ; +} +/* TODO : Check for the board specific PHY */ static void evm_phy_init (char *name,int addr) {
@@ -159,7 +168,6 @@ int board_eth_init(bd_t *bis) {uint8_t mac_addr[6 ];uint32_t mac_hi, mac_lo; -char mac_buf[32 ];if (!eth_getenv_enetaddr ("ethaddr" , mac_addr)) {debug ("<ethaddr> not set. Reading from E-fuse\n" );
@@ -174,18 +182,11 @@ int board_eth_init(bd_t *bis) mac_addr[5 ] = (mac_lo &0xFF00 ) >>8 ;if (is_valid_ether_addr (mac_addr)) { -sprintf (mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x" , - mac_addr[0 ], mac_addr[1 ], mac_addr[2 ], - mac_addr[3 ], mac_addr[4 ], mac_addr[5 ]); - -printf ("ENET MAC address: %s\n" , mac_buf); -setenv ("ethaddr" , (char *)mac_buf); +eth_setenv_enetaddr ("ethaddr" , mac_addr); }else {printf ("Caution: Using hardcoded mac address. " "Set <ethaddr> variable to overcome this.\n" ); } - -cpsw_eth_set_mac_addr (mac_addr); }/* set mii mode to rgmii in in device configure register */
common/miiphyutil.c +5 -2
@@ -548,7 +548,7 @@ miiphy_read_failed:* Return 1 if PHY supports 1000BASE-X, 0 if PHY supports 10BASE-T/100BASE-TX/ * 1000BASE-T, or on error. */ -int miiphy_is_1000base_x (const char *devname,unsigned char addr) +static int __miiphy_is_1000base_x (const char *devname,unsigned char addr) {#if defined(CONFIG_PHY_GIGE )u16 exsr;
@@ -558,12 +558,15 @@ int miiphy_is_1000base_x(const char *devname, unsigned char addr) "1000BASE-X\n"); return 0; } -return 0 ; +return 0 != (exsr & (ESTATUS_1000XF |ESTATUS_1000XH ));#else return 0 ;#endif } +int miiphy_is_1000base_x (const char *devname,unsigned char addr) + __attribute__((weak,alias ("__miiphy_is_1000base_x" ))); +#ifdef CONFIG_SYS_FAULT_ECHO_LINK_DOWN /***************************************************************************** *
drivers/net/cpsw.c +1 -15
@@ -512,20 +512,6 @@ static inline void soft_reset(void *reg) ; } -static u_int8_t cpsw_eth_mac_addr[] = {0x00 ,0x11 ,0x22 ,0x33 ,0x44 ,0x66 }; - -/* -* This function must be called before cpsw_init() if you want to override -* the default mac address. -*/ -void cpsw_eth_set_mac_addr (const u_int8_t *addr) -{ -int i; - -for (i =0 ; i <sizeof (cpsw_eth_mac_addr); i++) - cpsw_eth_mac_addr[i] = addr[i]; -} -#define mac_hi (mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ ((mac)[2] << 16) | ((mac)[3] << 24))#define mac_lo (mac) (((mac)[4] << 0) | ((mac)[5] << 8))
@@ -732,7 +718,7 @@ static int cpsw_init(struct eth_device *dev, bd_t *bis)__raw_writel (BIT (priv->host_port), &priv->regs->stat_port_en);cpsw_ale_port_state (priv, priv->host_port,ALE_PORT_STATE_FORWARD ); -memcpy (priv->dev->enetaddr, cpsw_eth_mac_addr,6 ); +cpsw_ale_add_ucast (priv, priv->dev->enetaddr, priv->host_port,ALE_SECURE );cpsw_ale_add_mcast (priv, NetBcastAddr,1 << priv->host_port);
Kumar Nath
PATCH v2 2/2 ARM:AM33XX:Added cpsw support for AM335x EVM
Please ignore this patch which went by mistake.
Quoted 151 lines
-----Original Message-----
From: Kumar Nath, Chandan
Sent: Thursday, November 10, 2011 6:11 PM
To: u-boot at lists.denx.de
Cc: Kumar Nath, Chandan
Subject: [PATCH v2 2/2] ARM:AM33XX:Added cpsw support for AM335x EVM#ifdef
CONFIG_ARCH_EBSA110# ifdef machine_arch_type(quoted diff) +13
-0@@ -42913,6 +42915,19 @@ extern unsigned int __machine_arch_type; # define machine_is_goflexhome() (0) #endif +#ifdef CONFIG_MACH_TIAM335EVM +# ifdef machine_arch_type +# undef machine_arch_type +# define machine_arch_type __machine_arch_type +# else +# define machine_arch_type MACH_TYPE_TIAM335EVM +# endif +# define machine_is_tiam335evm() (machine_arch_type == MACH_TYPE_TIAM335EVM) +#else +# define machine_is_tiam335evm() (0) +#endif + + /* * These have not yet been registered*/
board/ti/am335x/evm.c +10
-9@@ -57,6 +57,15 @@ int board_init(void) }#ifdef CONFIG_DRIVER_TI_CPSW +/* Atheros PHY report 1000baseX speed incorrectly and so this function +* is define to overcome this issue. The original code is kept as +* _miiphy_is_1000base_x as an weak alias to this function. +*/ +int miiphy_is_1000base_x (const char *devname,unsigned char addr) +{ +return 0 ; +} +/* TODO : Check for the board specific PHY */ static void evm_phy_init (char *name,int addr) {@@ -159,7 +168,6 @@ int board_eth_init(bd_t *bis) {uint8_t mac_addr[6 ];uint32_t mac_hi, mac_lo; -char mac_buf[32 ];if (!eth_getenv_enetaddr ("ethaddr" , mac_addr)) {debug ("<ethaddr> not set. Reading from E-fuse\n" );@@ -174,18 +182,11 @@ int board_eth_init(bd_t *bis) mac_addr[5 ] = (mac_lo &0xFF00 ) >>8 ;if (is_valid_ether_addr (mac_addr)) { -sprintf (mac_buf,"%02x:%02x:%02x:%02x:%02x:%02x" , - mac_addr[0 ], mac_addr[1 ], mac_addr[2 ], - mac_addr[3 ], mac_addr[4 ], mac_addr[5 ]); - -printf ("ENET MAC address: %s\n" , mac_buf); -setenv ("ethaddr" , (char *)mac_buf); +eth_setenv_enetaddr ("ethaddr" , mac_addr); }else {printf ("Caution: Using hardcoded mac address. " "Set <ethaddr> variable to overcome this.\n" ); } - -cpsw_eth_set_mac_addr (mac_addr); }/* set mii mode to rgmii in in device configure register */ common/miiphyutil.c +0
-0@@ -548,7 +548,7 @@ miiphy_read_failed:* Return 1 if PHY supports 1000BASE-X, 0 if PHY supports 10BASE- T/100BASE-TX/
* 1000BASE-T, or on error.
*/common/miiphyutil.c +1
-1-int miiphy_is_1000base_x (const char *devname,unsigned char addr) +static int __miiphy_is_1000base_x(const char *devname, unsigned charaddr)
{
#ifdefined(CONFIG_PHY_GIGE)common/miiphyutil.c +4
-1u16 exsr;@@ -558,12 +558,15 @@ int miiphy_is_1000base_x(const char *devname, unsigned char addr) "1000BASE-X\n"); return 0; } -return 0 ; +return 0 != (exsr & (ESTATUS_1000XF |ESTATUS_1000XH ));#else return 0 ;#endif } +int miiphy_is_1000base_x (const char *devname,unsigned char addr) + __attribute__((weak,alias ("__miiphy_is_1000base_x" ))); +#ifdef CONFIG_SYS_FAULT_ECHO_LINK_DOWN /**********************************************************************
*******
*drivers/net/cpsw.c +0
-4@@ -512,20 +512,6 @@ static inline void soft_reset(void *reg) ; } -static u_int8_t cpsw_eth_mac_addr[] = {0x00 ,0x11 ,0x22 ,0x33 ,0x44 , 0x66 }; - -/* -* This function must be called before cpsw_init() if you want to override
- * the default mac address.
- */drivers/net/cpsw.c +1
-9-void cpsw_eth_set_mac_addr (const u_int8_t *addr) -{ -int i; - -for (i =0 ; i <sizeof (cpsw_eth_mac_addr); i++) - cpsw_eth_mac_addr[i] = addr[i]; -} -#define mac_hi (mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ ((mac)[2] << 16) | ((mac)[3] << 24))#define mac_lo (mac) (((mac)[4] << 0) | ((mac)[5] << 8))@@ -732,7 +718,7 @@ static int cpsw_init(struct eth_device *dev, bd_t *bis)__raw_writel (BIT (priv->host_port), &priv->regs->stat_port_en);cpsw_ale_port_state (priv, priv->host_port,ALE_PORT_STATE_FORWARD ); -memcpy (priv->dev->enetaddr, cpsw_eth_mac_addr,6 ); + cpsw_ale_add_ucast(priv, priv->dev->enetaddr, priv->host_port,drivers/net/cpsw.c +0
-0ALE_SECURE);cpsw_ale_add_mcast (priv, NetBcastAddr,1 << priv->host_port);