net dsa: add per port phy address mapping
Subsystems (3)
PATCH 1/1 net dsa: add per port phy address mapping
In some circumstances ports' phy addresses must be remapped in a custom manner (i.e. when phys have multiple MDIO addresses).
Compatibility with old behaviour is kept by using a special flag named "port_phy_remap" which must be set to 1 in order to enable remapping defined into "port_phy_addr" array.
--- include/net/dsa.h | 11 +++++++++++ net/dsa/dsa.c | 3 ++- net/dsa/dsa_priv.h | 3 ++- net/dsa/slave.c | 25 +++++++++++++++---------- 4 files changed, 30 insertions(+), 12 deletions(-)
include/net/dsa.h +11 -0
@@ -36,6 +36,17 @@ struct dsa_chip_data {char *port_names[DSA_MAX_PORTS ];/* +* The MDIO address of the phy connected to each port. +* Set port_phy_remap = 1 in order to activate the remap otherwise +* is assumed that phy on port0 has address 0x0, phy on port1 has +* address 0x1 and so on... +* Note that for ports marked as "cpu" or "dsa" these fields are +* ignored. +*/ + unsigned long port_phy_remap:1; +int port_phy_addr[DSA_MAX_PORTS ]; + +/* * An array (with nr_chips elements) of which element [a] * indicates which port on this switch should be used to * send packets to that are destined for switch a. Can be
net/dsa/dsa.c +2 -1
@@ -175,7 +175,8 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,if (!(ds->phys_port_mask & (1 << i)))continue ; - slave_dev =dsa_slave_create (ds, parent, i, pd->port_names[i]); + slave_dev =dsa_slave_create (ds, parent, i, pd->port_names[i], + pd->port_phy_remap ? pd->port_phy_addr[i] : i);if (slave_dev ==NULL ) { printk(KERN_ERR "%s[%d]: can't create dsa " "slave device for port %d(%s)\n",
net/dsa/dsa_priv.h +2 -1
@@ -42,7 +42,8 @@ extern char dsa_driver_version[];void dsa_slave_mii_bus_init (struct dsa_switch *ds);struct net_device *dsa_slave_create (struct dsa_switch *ds,struct device *parent, -int port,char *name); +int port,char *name, +int phy_addr);/* tag_dsa.c */ netdev_tx_t dsa_xmit (struct sk_buff *skb,struct net_device *dev);
net/dsa/slave.c +15 -10
@@ -19,20 +19,25 @@ static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg) {struct dsa_switch *ds = bus->priv; -if (ds->phys_port_mask & (1 << addr)) -return ds->drv->phy_read (ds, addr, reg); - -return 0xffff ; +/* +* if port_phy_remap is not enabled when can use old sanity check: +* +* if (ds->phys_port_mask & (1 << port)) +* +* but if port_phy_remap is enabled we should find port<-->addr +* mapping by looking into port_phy_addr array... that why I dropped +* any sanity checks here (real kernel programmers should know what +* they do! ;) - Rodolfo Giometti +*/ +return ds->drv->phy_read (ds, addr, reg); }static int dsa_slave_phy_write (struct mii_bus *bus,int addr,int reg,u16 val) {struct dsa_switch *ds = bus->priv; -if (ds->phys_port_mask & (1 << addr)) -return ds->drv->phy_write (ds, addr, reg, val); - -return 0 ; +/* See comment in function dsa_slave_phy_read() above */ +return ds->drv->phy_write (ds, addr, reg, val); }void dsa_slave_mii_bus_init (struct dsa_switch *ds)
@@ -333,7 +338,7 @@ static const struct net_device_ops trailer_netdev_ops = {/* slave device setup *******************************************************/ struct net_device *dsa_slave_create (struct dsa_switch *ds,struct device *parent, -int port,char *name) +int port,char *name,int phy_addr) {struct net_device *master = ds->dst->master_netdev;struct net_device *slave_dev;
@@ -377,7 +382,7 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent, p->dev = slave_dev; p->parent = ds; p->port = port; - p->phy = ds->slave_mii_bus->phy_map[port]; + p->phy = ds->slave_mii_bus->phy_map[phy_addr]; ret =register_netdev (slave_dev);if (ret) {
Signature · 1 line
1.7.9.5
PATCH 1/1 net dsa: add new option "master_netdev_autoup"
By using this option the user can decide if the master device should be turned on when one of the slave devices is opened.
This functionality is needed if RootFS over NFS is used throught the DSA.
--- include/net/dsa.h | 8 ++++++++ net/dsa/slave.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
include/net/dsa.h +8 -0
@@ -63,6 +63,14 @@ struct dsa_platform_data {struct device *netdev;/* +* Enable the auto-up of the master device when a slave is +* open. +* This functionality is needed if RootFS over NFS is used +* throught the DSA. +*/ + unsigned long master_netdev_autoup:1; + +/* * Info structs describing each of the switch chips * connected via this network interface. */
net/dsa/slave.c +6 -1
@@ -66,9 +66,14 @@ static int dsa_slave_open(struct net_device *dev) {struct dsa_slave_priv *p =netdev_priv (dev);struct net_device *master = p->parent->dst->master_netdev; +struct dsa_platform_data *pd = p->parent->dst->pd;int err; -if (!(master->flags &IFF_UP )) +if (pd->master_netdev_autoup) + err =dev_open (master); +else + err = !(master->flags &IFF_UP ); +if (err)return -ENETDOWN ;if (!ether_addr_equal (dev->dev_addr, master->dev_addr)) {
Signature · 1 line
1.7.9.5
Re: [PATCH] net dsa: add new option "master_netdev_autoup"
Quoted 5 lines · Rodolfo Giometti
By using this option the user can decide if the master device should be turned on when one of the slave devices is opened.
This functionality is needed if RootFS over NFS is used throught the DSA.
NAK
Use an initramfs if you want this.
PATCH 1/1 net dsa: add phy's interrupts management
In reply to Rodolfo Giometti--- net/dsa/slave.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/dsa/slave.c +7 -2
@@ -340,6 +340,11 @@ static const struct net_device_ops trailer_netdev_ops = { };#endif +static void dsa_slave_handle_link_change (struct net_device *dev) +{ +/* nop */ +} +/* slave device setup *******************************************************/ struct net_device * dsa_slave_create(struct dsa_switch *ds, struct device *parent,
@@ -400,8 +405,8 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,netif_carrier_off (slave_dev);if (p->phy !=NULL ) { -phy_attach (slave_dev,dev_name (&p->phy->dev), -0 ,PHY_INTERFACE_MODE_GMII ); +phy_connect_direct (p->dev, p->phy, dsa_slave_handle_link_change, +0 ,PHY_INTERFACE_MODE_GMII ); p->phy->autoneg =AUTONEG_ENABLE ; p->phy->speed =0 ;
Signature · 1 line
1.7.9.5
Re: [PATCH] net dsa: add phy's interrupts management
Quoted 17 lines · Rodolfo Giometti
net/dsa/slave.c +5
-0@@ -340,6 +340,11 @@ static const struct net_device_ops trailer_netdev_ops = { };#endif +static void dsa_slave_handle_link_change (struct net_device *dev) +{ +/* nop */ +} +/* slave device setup *******************************************************/ struct net_device * dsa_slave_create(struct dsa_switch *ds, struct device *parent,
net/dsa/slave.c dsa_slave_create(struct dsa_switch *ds, struct device *parent, · line 411
Quoted 9 lines
net/dsa/slave.c +2
-2@@ -400,8 +405,8 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,netif_carrier_off (slave_dev);if (p->phy !=NULL ) { -phy_attach (slave_dev,dev_name (&p->phy->dev), -0 ,PHY_INTERFACE_MODE_GMII ); +phy_connect_direct (p->dev, p->phy, dsa_slave_handle_link_change, +0 ,PHY_INTERFACE_MODE_GMII ); p->phy->autoneg =AUTONEG_ENABLE ;
What does this do?
PATCH 1/1 net dsa: add TX timestamping support
In reply to Rodolfo Giometti--- net/dsa/tag_dsa.c | 8 ++++++++ net/dsa/tag_edsa.c | 8 ++++++++ net/dsa/tag_trailer.c | 8 ++++++++ 3 files changed, 24 insertions(+)
net/dsa/tag_dsa.c +8 -0
@@ -24,6 +24,14 @@ netdev_tx_t dsa_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; +/* We should call skb_tx_timestamp() at bottom of this function, +* just before dev_queue_xmit(), but the skb is going to be +* modified by DSA stack so it is going to be NOT recognized +* by the ptp_filter called into function skb_clone_tx_timestamp() +* [see file linux/net/core/timestamping.c]. +*/ +skb_tx_timestamp (skb); +/* * Convert the outermost 802.1q tag to a DSA tag for tagged * packets, or insert a DSA tag between the addresses and
net/dsa/tag_edsa.c +8 -0
@@ -25,6 +25,14 @@ netdev_tx_t edsa_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; +/* We should call skb_tx_timestamp() at bottom of this function, +* just before dev_queue_xmit(), but the skb is going to be +* modified by DSA stack so it is going to be NOT recognized +* by the ptp_filter called into function skb_clone_tx_timestamp() +* [see file linux/net/core/timestamping.c]. +*/ +skb_tx_timestamp (skb); +/* * Convert the outermost 802.1q tag to a DSA tag and prepend * a DSA ethertype field is the packet is tagged, or insert
net/dsa/tag_trailer.c +8 -0
@@ -24,6 +24,14 @@ netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; +/* We should call skb_tx_timestamp() at bottom of this function, +* just before dev_queue_xmit(), but the skb is going to be +* modified by DSA stack so it is going to be NOT recognized +* by the ptp_filter called into function skb_clone_tx_timestamp() +* [see file linux/net/core/timestamping.c]. +*/ +skb_tx_timestamp (skb); +/* * We have to make sure that the trailer ends up as the very * last 4 bytes of the packet. This means that we have to pad
Signature · 1 line
1.7.9.5
Quoted 2 lines · Rodolfo Giometti
In some circumstances ports' phy addresses must be remapped in a custom manner (i.e. when phys have multiple MDIO addresses).
Can you give an example of when this is needed (i.e. on which switch chips)?