net-next: dsa: add support for multiple cpu ports
Subsystems (4)
RFC 1/4 Documentation: devicetree: add multiple cpu port DSA binding
In reply to John CrispinFrom: Andrew Lunn <[email protected]>
Extend the DSA binding documentation, adding the new properties required when there is more than one CPU port attached to the switch.
--- Documentation/devicetree/bindings/net/dsa/dsa.txt | 67 ++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/dsa/dsa.txt +66 -1
@@ -337,13 +337,25 @@ Optional property: This mii-bus will be used in preference to the global dsa,mii-bus defined above, for this switch. +- ethernet : Optional for "cpu" ports. A phandle to an ethernet + device which will be used by this CPU port for + passing packets to/from the host. If not present, + the port will use the "dsa,ethernet" property + defined above. + +- cpu : Option for non "cpu"/"dsa" ports. A phandle to a + "cpu" port, which will be used for passing packets + from this port to the host. If not present, the first + "cpu" port will be used. + + Optional subnodes: - fixed-link : Fixed-link subnode describing a link to a non-MDIO managed entity. See Documentation/devicetree/bindings/net/fixed-link.txt for details. -Example: +Examples: dsa@0 { compatible = "marvell,dsa";
@@ -416,3 +428,56 @@ Example: }; }; }; + + dsa@1 { + compatible = "marvell,dsa"; + #address-cells = <2>; + #size-cells = <0>; + + dsa,ethernet = <ð0port>; + dsa,mii-bus = <&mdio>; + + switch@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0 0>; /* MDIO address 0, switch 0 in tree */ + + port@0 { + reg = <0>; + label = "lan4"; + }; + + port@1 { + reg = <1>; + label = "lan3"; + cpu = <&cpu1>; + }; + + port@2 { + reg = <2>; + label = "lan2"; + }; + + port@3 { + reg = <3>; + label = "lan1"; + cpu = <&cpu1>; + }; + + port@4 { + reg = <4>; + label = "wan"; + }; + + port@5 { + reg = <5>; + label = "cpu"; + }; + + cpu1: port@6 { + reg = <6>; + label = "cpu"; + ethernet = <ð1port>; + }; + }; + };
Signature · 1 line
1.7.10.4
RFC 2/4 net-next: dsa: Refactor DT probing of a switch port
In reply to John CrispinFrom: Andrew Lunn <[email protected]>
Move the DT probing of a switch port into a function of its own, since it is about to get more complex. Add better error handling as well.
--- net/dsa/dsa.c | 138 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 102 insertions(+), 36 deletions(-)
net/dsa/dsa.c +102 -36
@@ -326,14 +326,10 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)continue ;if (!strcmp (name,"cpu" )) { -if (dst->cpu_switch !=-1 ) { -netdev_err (dst->master_netdev, -"multiple cpu ports?!\n" ); - ret = -EINVAL ; - goto out; +if (dst->cpu_switch ==-1 ) { + dst->cpu_switch = index; + dst->cpu_port = i; } - dst->cpu_switch = index; - dst->cpu_port = i; ds->cpu_port_mask |=1 << i; }else if (!strcmp (name,"dsa" )) { ds->dsa_port_mask |=1 << i;
@@ -709,11 +705,15 @@ static void dsa_of_free_platform_data(struct dsa_platform_data *pd) {int i;int port_index; +struct dsa_chip_data *cd;for (i =0 ; i < pd->nr_chips; i++) { + cd = &pd->chip[i]; port_index =0 ;while (port_index <DSA_MAX_PORTS ) { -kfree (pd->chip[i].port_names[port_index]); +kfree (cd->port_names[port_index]); +if (cd->port_ethernet[port_index]) +dev_put (cd->port_ethernet[port_index]); port_index++; }
@@ -724,6 +724,94 @@ static void dsa_of_free_platform_data(struct dsa_platform_data *pd)kfree (pd->chip); } +static int dsa_of_probe_cpu_port (struct dsa_chip_data *cd, +struct device_node *port, +int port_index) +{ +struct net_device *ethernet_dev; +struct device_node *ethernet; + + ethernet =of_parse_phandle (port,"ethernet" ,0 ); +if (ethernet) { + ethernet_dev =of_find_net_device_by_node (ethernet); +if (!ethernet_dev) +return -EPROBE_DEFER ; + +dev_hold (ethernet_dev); + cd->port_ethernet[port_index] = ethernet_dev; + } + +return 0 ; +} + +static int dsa_of_probe_user_port (struct dsa_chip_data *cd, +struct device_node *port, +int port_index) +{ +struct device_node *cpu_port; +const unsigned int *cpu_port_reg; +int cpu_port_index; + + cpu_port =of_parse_phandle (port,"cpu" ,0 ); +if (cpu_port) { + cpu_port_reg =of_get_property (cpu_port,"reg" ,NULL ); +if (!cpu_port_reg) +return -EINVAL ; + cpu_port_index =be32_to_cpup (cpu_port_reg); + cd->port_cpu[port_index] = cpu_port_index; + } + +return 0 ; +} + +static int dsa_of_probe_port (struct dsa_platform_data *pd, +struct dsa_chip_data *cd, +int chip_index, +struct device_node *port) +{ +bool is_cpu_port = false, is_dsa_port = false; +bool is_user_port = false; +const unsigned int *port_reg; +const char *port_name; +int port_index, ret =0 ; + + port_reg =of_get_property (port,"reg" ,NULL ); +if (!port_reg) +return -EINVAL ; + + port_index =be32_to_cpup (port_reg); + + port_name =of_get_property (port,"label" ,NULL ); +if (!port_name) +return -EINVAL ; + +if (!strcmp (port_name,"cpu" )) + is_cpu_port = true; +if (!strcmp (port_name,"dsa" )) + is_dsa_port = true; +if (!is_cpu_port && !is_dsa_port) + is_user_port = true; + + cd->port_dn[port_index] = port; + + cd->port_names[port_index] =kstrdup (port_name, +GFP_KERNEL ); +if (!cd->port_names[port_index]) +return -ENOMEM ; + +if (is_dsa_port) + ret =dsa_of_probe_links (pd, cd, chip_index, + port_index, port, port_name); +if (is_cpu_port) + ret =dsa_of_probe_cpu_port (cd, port, port_index); +if (is_user_port) + ret =dsa_of_probe_user_port (cd, port, port_index); +if (ret) +return ret; + +return port_index; +} +static int dsa_of_probe (struct device *dev) {struct device_node *np = dev->of_node;
@@ -732,9 +820,8 @@ static int dsa_of_probe(struct device *dev)struct net_device *ethernet_dev;struct dsa_platform_data *pd;struct dsa_chip_data *cd; -const char *port_name; -int chip_index, port_index; -const unsigned int *sw_addr, *port_reg; +int chip_index; +const unsigned int *sw_addr;u32 eeprom_len;int ret;
@@ -821,32 +908,11 @@ static int dsa_of_probe(struct device *dev) }for_each_available_child_of_node (child, port) { - port_reg =of_get_property (port,"reg" ,NULL ); -if (!port_reg) -continue ; - - port_index =be32_to_cpup (port_reg); -if (port_index >=DSA_MAX_PORTS ) -break ; - - port_name =of_get_property (port,"label" ,NULL ); -if (!port_name) -continue ; - - cd->port_dn[port_index] = port; - - cd->port_names[port_index] =kstrdup (port_name, -GFP_KERNEL ); -if (!cd->port_names[port_index]) { - ret = -ENOMEM ; + ret =dsa_of_probe_port (pd, cd, chip_index, port); +if (ret <0 ) goto out_free_chip; - } - - ret =dsa_of_probe_links (pd, cd, chip_index, - port_index, port, port_name); -if (ret) - goto out_free_chip; - +if (ret ==DSA_MAX_PORTS ) +break ; } }
Signature · 1 line
1.7.10.4
cover net-next: dsa: add support for multiple cpu ports
This series is based on work from Andrew. I have rebased his patches to work on the latest kernel. The main problem is probably the fact that the cpu port to user port mapping happens inside the devicetree.
Andrew Lunn (3):
Documentation: devicetree: add multiple cpu port DSA binding
net-next: dsa: Refactor DT probing of a switch port
net-next: dsa: Add support for multiple cpu ports.
John Crispin (1):
net-next: dsa: qca8k: add support for multiple cpu ports
Documentation/devicetree/bindings/net/dsa/dsa.txt | 67 +++++++++- drivers/net/dsa/qca8k.c | 135 +++++++++++--------- drivers/net/dsa/qca8k.h | 2 - include/net/dsa.h | 21 +++- net/dsa/dsa.c | 138 +++++++++++++++------ net/dsa/dsa2.c | 36 +++++- net/dsa/dsa_priv.h | 5 + net/dsa/slave.c | 27 ++-- 8 files changed, 317 insertions(+), 114 deletions(-)
Signature · 1 line
1.7.10.4
RFC 3/4 net-next: dsa: Add support for multiple cpu ports.
From: Andrew Lunn <[email protected]>
Some boards have two CPU interfaces connected to the switch, e.g. WiFi access points, with 1 port labeled WAN, 4 ports labeled lan1-lan4, and two port connected to the SoC.
This patch extends DSA to allows both CPU ports to be used. The "cpu" node in the DSA tree can now have a phandle to the host interface it connects to. Each user port can have a phandle to a cpu port which should be used for traffic between the port and the CPU. Thus simple load sharing over the two CPU ports can be achieved.
--- include/net/dsa.h | 21 ++++++++++++++++++++- net/dsa/dsa2.c | 36 ++++++++++++++++++++++++++++++------ net/dsa/dsa_priv.h | 5 +++++ net/dsa/slave.c | 27 ++++++++++++++++----------- 4 files changed, 71 insertions(+), 18 deletions(-)
include/net/dsa.h +20 -1
@@ -60,6 +60,8 @@ struct dsa_chip_data {*/ char *port_names[DSA_MAX_PORTS ];struct device_node *port_dn[DSA_MAX_PORTS ]; +struct net_device *port_ethernet[DSA_MAX_PORTS ]; +int port_cpu[DSA_MAX_PORTS ];/* * An array of which element [a] indicates which port on this
@@ -204,7 +206,7 @@ struct dsa_switch {static inline bool dsa_is_cpu_port (struct dsa_switch *ds,int p) { -return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port); +return !!(ds->cpu_port_mask & (1 << p)); }static inline bool dsa_is_dsa_port (struct dsa_switch *ds,int p)
@@ -217,6 +219,11 @@ static inline bool dsa_is_port_initialized(struct dsa_switch *ds, int p)return ds->enabled_port_mask & (1 << p) && ds->ports[p].netdev; } +static inline bool dsa_is_upstream_port (struct dsa_switch *ds,int p) +{ +return dsa_is_cpu_port (ds, p) ||dsa_is_dsa_port (ds, p); +} +static inline u8 dsa_upstream_port (struct dsa_switch *ds) {struct dsa_switch_tree *dst = ds->dst;
@@ -233,6 +240,18 @@ static inline u8 dsa_upstream_port(struct dsa_switch *ds)return ds->rtable[dst->cpu_switch]; } +static inline u8 dsa_port_upstream_port (struct dsa_switch *ds,int port) +{ +/* +* If this port has a specific upstream cpu port, use it, +* otherwise use the switch default. +*/ +if (ds->cd->port_cpu[port]) +return ds->cd->port_cpu[port]; +else +return dsa_upstream_port (ds); +} +struct switchdev_trans ;struct switchdev_obj ;struct switchdev_obj_port_fdb ;
net/dsa/dsa2.c +30 -6
@@ -258,7 +258,7 @@ static void dsa_cpu_port_unapply(struct device_node *port, u32 index, {dsa_cpu_dsa_destroy (port); ds->cpu_port_mask &= ~BIT (index); - +dev_put (ds->cd->port_ethernet[index]); } static int dsa_user_port_apply(struct device_node *port, u32 index,
@@ -475,6 +475,28 @@ static int dsa_cpu_parse(struct device_node *port, u32 index, dst->rcv = dst->tag_ops->rcv; +dev_hold (ethernet_dev); + ds->cd->port_ethernet[index] = ethernet_dev; + +return 0 ; +} + +static int dsa_user_parse (struct device_node *port,u32 index, +struct dsa_switch *ds) +{ +struct device_node *cpu_port; +const unsigned int *cpu_port_reg; +int cpu_port_index; + + cpu_port =of_parse_phandle (port,"cpu" ,0 ); +if (cpu_port) { + cpu_port_reg =of_get_property (cpu_port,"reg" ,NULL ); +if (!cpu_port_reg) +return -EINVAL ; + cpu_port_index =be32_to_cpup (cpu_port_reg); + ds->cd->port_cpu[index] = cpu_port_index; + } +return 0 ; }
@@ -482,18 +504,20 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) {struct device_node *port;u32 index; -int err; +int err =0 ;for (index =0 ; index <DSA_MAX_PORTS ; index++) { port = ds->ports[index].dn;if (!port)continue ; -if (dsa_port_is_cpu (port)) { +if (dsa_port_is_cpu (port)) err =dsa_cpu_parse (port, index, dst, ds); -if (err) -return err; - } +else if (!dsa_port_is_dsa (port)) + err =dsa_user_parse (port, index, ds); + +if (err) +return err; }pr_info ("DSA: switch %d %d parsed\n" , dst->tree, ds->index);
net/dsa/dsa_priv.h +5 -0
@@ -24,6 +24,11 @@ struct dsa_device_ops {struct dsa_slave_priv {struct sk_buff * (*xmit)(struct sk_buff *skb,struct net_device *dev); +/* +* Which host device do we used to send packets to the switch +* for this port. +*/ +struct net_device *master;/* * Which switch this port is a part of, and the port index
net/dsa/slave.c +16 -11
@@ -61,7 +61,7 @@ static int dsa_slave_get_iflink(const struct net_device *dev) {struct dsa_slave_priv *p =netdev_priv (dev); -return p->parent->dst->master_netdev->ifindex; +return p->master->ifindex; }static inline bool dsa_port_is_bridged (struct dsa_slave_priv *p)
@@ -96,7 +96,7 @@ static void dsa_port_set_stp_state(struct dsa_switch *ds, int port, u8 state)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 net_device *master = p->master;struct dsa_switch *ds = p->parent;u8 stp_state =dsa_port_is_bridged (p) ?BR_STATE_BLOCKING :BR_STATE_FORWARDING ;
@@ -151,7 +151,7 @@ static int dsa_slave_open(struct net_device *dev)static int dsa_slave_close (struct net_device *dev) {struct dsa_slave_priv *p =netdev_priv (dev); -struct net_device *master = p->parent->dst->master_netdev; +struct net_device *master = p->master;struct dsa_switch *ds = p->parent;if (p->phy)
@@ -178,7 +178,7 @@ static int dsa_slave_close(struct net_device *dev)static void dsa_slave_change_rx_flags (struct net_device *dev,int change) {struct dsa_slave_priv *p =netdev_priv (dev); -struct net_device *master = p->parent->dst->master_netdev; +struct net_device *master = p->master;if (change &IFF_ALLMULTI )dev_set_allmulti (master, dev->flags &IFF_ALLMULTI ?1 :-1 );
@@ -189,7 +189,7 @@ static void dsa_slave_change_rx_flags(struct net_device *dev, int change)static void dsa_slave_set_rx_mode (struct net_device *dev) {struct dsa_slave_priv *p =netdev_priv (dev); -struct net_device *master = p->parent->dst->master_netdev; +struct net_device *master = p->master;dev_mc_sync (master, dev);dev_uc_sync (master, dev);
@@ -198,7 +198,7 @@ static void dsa_slave_set_rx_mode(struct net_device *dev)static int dsa_slave_set_mac_address (struct net_device *dev,void *a) {struct dsa_slave_priv *p =netdev_priv (dev); -struct net_device *master = p->parent->dst->master_netdev; +struct net_device *master = p->master;struct sockaddr *addr = a;int err;
@@ -633,7 +633,7 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)/* Queue the SKB for transmission on the parent interface, but * do not modify its EtherType */ - nskb->dev = p->parent->dst->master_netdev; + nskb->dev = p->master;dev_queue_xmit (nskb);return NETDEV_TX_OK ;
@@ -947,7 +947,7 @@ static int dsa_slave_netpoll_setup(struct net_device *dev, {struct dsa_slave_priv *p =netdev_priv (dev);struct dsa_switch *ds = p->parent; -struct net_device *master = ds->dst->master_netdev; +struct net_device *master = p->master;struct netpoll *netpoll;int err =0 ;
@@ -1247,12 +1247,16 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,struct net_device *master;struct net_device *slave_dev;struct dsa_slave_priv *p; +int port_cpu = ds->cd->port_cpu[port];int ret; - master = ds->dst->master_netdev; -if (ds->master_netdev) +if (port_cpu && ds->cd->port_ethernet[port_cpu]) + master = ds->cd->port_ethernet[port_cpu]; +else if (ds->master_netdev) master = ds->master_netdev; - +else + master = ds->dst->master_netdev; + master->dsa_ptr = (void *)ds->dst; slave_dev =alloc_netdev (sizeof (struct dsa_slave_priv ), name,NET_NAME_UNKNOWN , ether_setup);if (slave_dev ==NULL )
@@ -1279,6 +1283,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent, p->parent = ds; p->port = port; p->xmit = dst->tag_ops->xmit; + p->master = master; p->old_pause =-1 ; p->old_link =-1 ;
Signature · 1 line
1.7.10.4
RFC 4/4 net-next: dsa: qca8k: add support for multiple cpu ports
In reply to John CrispinWith the subsystem now supporting multiple cpu ports, we need to make some changes to the driver as it currently has the cpu port hardcoded as port0. The patch moves the setup logic for the cpu port into one loop which iterates over all cpu ports and sets them up. Additionally the bridge join/leave logic needs a small fix to work with having a cpu port other than 0.
--- drivers/net/dsa/qca8k.c | 135 +++++++++++++++++++++++++++-------------------- drivers/net/dsa/qca8k.h | 2 - 2 files changed, 78 insertions(+), 59 deletions(-)
drivers/net/dsa/qca8k.c +78 -57
@@ -486,11 +486,25 @@qca8k_reg_clear (priv,QCA8K_REG_PORT_STATUS (port), mask); } +static void +qca8k_setup_flooding (struct qca8k_priv *priv,int port_mask,int enable) +{ +u32 mask = (port_mask <<QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S ) | + (port_mask <<QCA8K_GLOBAL_FW_CTRL1_BC_DP_S ) | + (port_mask <<QCA8K_GLOBAL_FW_CTRL1_MC_DP_S ) | + (port_mask <<QCA8K_GLOBAL_FW_CTRL1_UC_DP_S ); + +if (enable) +qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL1 , mask); +else +qca8k_reg_clear (priv,QCA8K_REG_GLOBAL_FW_CTRL1 , mask); +} +static int qca8k_setup (struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -int ret, i, phy_mode =-1 ; +int ret, i;/* Make sure that port 0 is the cpu port */ if (!dsa_is_cpu_port (ds,0 )) {
@@ -506,29 +520,49 @@if (IS_ERR (priv->regmap))pr_warn ("regmap initialization failed" ); -/* Initialize CPU port pad mode (xMII type, delays...) */ - phy_mode =of_get_phy_mode (ds->ports[ds->dst->cpu_port].dn); -if (phy_mode <0 ) { -pr_err ("Can't find phy-mode for master device\n" ); -return phy_mode; - } - ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode); -if (ret <0 ) -return ret; - -/* Enable CPU Port */ +/* Tell the switch that port0 is a cpu port */ qca8k_reg_set (priv,QCA8K_REG_GLOBAL_FW_CTRL0 ,QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN ); -qca8k_port_set_status (priv,QCA8K_CPU_PORT ,1 ); - priv->port_sts[QCA8K_CPU_PORT ].enabled =1 ;/* Enable MIB counters */ qca8k_mib_init (priv); -/* Enable QCA header mode on the cpu port */ -qca8k_write (priv,QCA8K_REG_PORT_HDR_CTRL (QCA8K_CPU_PORT ), -QCA8K_PORT_HDR_CTRL_ALL <<QCA8K_PORT_HDR_CTRL_TX_S | -QCA8K_PORT_HDR_CTRL_ALL <<QCA8K_PORT_HDR_CTRL_RX_S ); +/* Setup the cpu ports */ +for (i =0 ; i <DSA_MAX_PORTS ; i++) { +struct net_device *netdev; +int phy_mode =-1 ; + +if (!dsa_is_cpu_port (ds, i)) +continue ; + + netdev = ds->dst->pd->chip->port_ethernet[i]; +if (!netdev) { +pr_err ("Can't find netdev for port%d\n" , i); +return -ENODEV ; + } + +/* Initialize CPU port pad mode (xMII type, delays...) */ + phy_mode =of_get_phy_mode (netdev->dev.parent->of_node); +if (phy_mode <0 ) { +pr_err ("Can't find phy-mode for port:%d\n" , i); +return phy_mode; + } + ret =qca8k_set_pad_ctrl (priv, i, phy_mode); +if (ret <0 ) +return ret; + +/* Enable QCA header mode on the cpu port */ +qca8k_write (priv, +QCA8K_REG_PORT_HDR_CTRL (i), +QCA8K_PORT_HDR_CTRL_ALL <<QCA8K_PORT_HDR_CTRL_TX_S | +QCA8K_PORT_HDR_CTRL_ALL <<QCA8K_PORT_HDR_CTRL_RX_S ); + +qca8k_port_set_status (priv, i,1 ); + priv->port_sts[i].enabled =1 ; + +/* Forward all unknown frames to CPU port for Linux processing */ +qca8k_setup_flooding (priv,BIT (i),1 ); + }/* Disable forwarding by default on all ports */ for (i =0 ; i <QCA8K_NUM_PORTS ; i++)
@@ -540,43 +574,30 @@if (ds->enabled_port_mask &BIT (i))qca8k_port_set_status (priv, i,0 ); -/* Forward all unknown frames to CPU port for Linux processing */ -qca8k_write (priv,QCA8K_REG_GLOBAL_FW_CTRL1 , -BIT (0 ) <<QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S | -BIT (0 ) <<QCA8K_GLOBAL_FW_CTRL1_BC_DP_S | -BIT (0 ) <<QCA8K_GLOBAL_FW_CTRL1_MC_DP_S | -BIT (0 ) <<QCA8K_GLOBAL_FW_CTRL1_UC_DP_S ); - -/* Setup connection between CPU port & user ports */ +/* Setup user ports and connections to CPU ports */ for (i =0 ; i <DSA_MAX_PORTS ; i++) { -/* CPU port gets connected to all user ports of the switch */ -if (dsa_is_cpu_port (ds, i)) { -qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (QCA8K_CPU_PORT ), -QCA8K_PORT_LOOKUP_MEMBER , - ds->enabled_port_mask); - } +int shift =16 * (i %2 ); +int cpu_port; -/* Invividual user ports get connected to CPU port only */ -if (ds->enabled_port_mask &BIT (i)) { -int shift =16 * (i %2 ); - -qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i), -QCA8K_PORT_LOOKUP_MEMBER , -BIT (QCA8K_CPU_PORT )); - -/* Enable ARP Auto-learning by default */ -qca8k_reg_set (priv,QCA8K_PORT_LOOKUP_CTRL (i), -QCA8K_PORT_LOOKUP_LEARN ); - -/* For port based vlans to work we need to set the -* default egress vid -*/ -qca8k_rmw (priv,QCA8K_EGRESS_VLAN (i), -0xffff << shift,1 << shift); -qca8k_write (priv,QCA8K_REG_PORT_VLAN_CTRL0 (i), -QCA8K_PORT_VLAN_CVID (1 ) | -QCA8K_PORT_VLAN_SVID (1 )); - } +if (!(ds->enabled_port_mask &BIT (i))) +continue ; + + cpu_port =dsa_port_upstream_port (ds, i); +qca8k_reg_set (priv,QCA8K_PORT_LOOKUP_CTRL (i),BIT (cpu_port)); +qca8k_reg_set (priv,QCA8K_PORT_LOOKUP_CTRL (cpu_port),BIT (i)); + +/* Enable ARP Auto-learning by default */ +qca8k_reg_set (priv,QCA8K_PORT_LOOKUP_CTRL (i), +QCA8K_PORT_LOOKUP_LEARN ); + +/* For port based vlans to work we need to set the +* default egress vid +*/ +qca8k_rmw (priv,QCA8K_EGRESS_VLAN (i), +0xffff << shift,1 << shift); +qca8k_write (priv,QCA8K_REG_PORT_VLAN_CTRL0 (i), +QCA8K_PORT_VLAN_CVID (1 ) | +QCA8K_PORT_VLAN_SVID (1 )); }/* Flush the FDB table */
@@ -750,7 +771,7 @@ struct net_device *bridge) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -int port_mask =BIT (QCA8K_CPU_PORT ); +int port_mask =0 ;int i; priv->port_sts[port].bridge_dev = bridge;
@@ -768,8 +789,7 @@ port_mask |=BIT (i); }/* Add all other ports to this ports portvlan mask */ -qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), -QCA8K_PORT_LOOKUP_MEMBER , port_mask); +qca8k_reg_set (priv,QCA8K_PORT_LOOKUP_CTRL (port), port_mask);return 0 ; }
@@ -796,7 +816,8 @@* this port */ qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), -QCA8K_PORT_LOOKUP_MEMBER ,BIT (QCA8K_CPU_PORT )); +QCA8K_PORT_LOOKUP_MEMBER , +BIT (dsa_port_upstream_port (ds, i))); } static int
drivers/net/dsa/qca8k.h +0 -2
@@ -26,8 +26,6 @@#define QCA8K_NUM_FDB_RECORDS 2048 -#define QCA8K_CPU_PORT 0 -/* Global control registers */ #define QCA8K_REG_MASK_CTRL 0x000#define QCA8K_MASK_CTRL_ID_M 0xff
Signature · 1 line
1.7.10.4
Andrew Lunn
maintainerRe: [RFC 1/4] Documentation: devicetree: add multiple cpu port DSA binding
In reply to John CrispinQuoted 4 lines · John Crispin
From: Andrew Lunn <[email protected]>
Extend the DSA binding documentation, adding the new properties required when there is more than one CPU port attached to the switch.
Hi John
Thanks for picking up my old patches.
Quoted 12 lines
--- Documentation/devicetree/bindings/net/dsa/dsa.txt | 67 ++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/net/dsa/dsa.txt +0
-0
Documentation/devicetree/bindings/net/dsa/dsa.txt Optional property: · line 344
Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/dsa.txt +5
-0@@ -337,13 +337,25 @@ Optional property: This mii-bus will be used in preference to the global dsa,mii-bus defined above, for this switch. +- ethernet : Optional for "cpu" ports. A phandle to an ethernet + device which will be used by this CPU port for + passing packets to/from the host. If not present, + the port will use the "dsa,ethernet" property + defined above.
This appears to be for the old binding. The new binding has this already. I only want to support multiple CPU ports with the new binding, since Florian is in the process of removing the old one.
Quoted 36 lines
Documentation/devicetree/bindings/net/dsa/dsa.txt +22
-1+ +- cpu : Option for non "cpu"/"dsa" ports. A phandle to a + "cpu" port, which will be used for passing packets + from this port to the host. If not present, the first + "cpu" port will be used. + + Optional subnodes: - fixed-link : Fixed-link subnode describing a link to a non-MDIO managed entity. See Documentation/devicetree/bindings/net/fixed-link.txt for details. -Example: +Examples: dsa@0 { compatible = "marvell,dsa";@@ -416,3 +428,56 @@ Example: }; }; }; + + dsa@1 { + compatible = "marvell,dsa"; + #address-cells = <2>; + #size-cells = <0>; + + dsa,ethernet = <ð0port>; + dsa,mii-bus = <&mdio>; + + switch@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0 0>; /* MDIO address 0, switch 0 in tree */ +
Documentation/devicetree/bindings/net/dsa/dsa.txt Example: · line 454
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/dsa.txt +10
-0+ port@0 { + reg = <0>; + label = "lan4"; + }; + + port@1 { + reg = <1>; + label = "lan3"; + cpu = <&cpu1>; + };
Again, this is the old binding. The example should use the new binding.
Thanks
Andrew
Andrew Lunn
maintainerRe: [RFC 3/4] net-next: dsa: Add support for multiple cpu ports.
In reply to John CrispinQuoted 4 lines · John Crispin
static int dsa_user_port_apply(struct
device_node*port, u32 index,net/dsa/dsa2.c +0
-0@@ -475,6 +475,28 @@ static int dsa_cpu_parse(struct device_node *port, u32 index, dst->rcv = dst->tag_ops->rcv;
net/dsa/dsa2.c static int dsa_cpu_parse(struct device_node *port, u32 index, · line 486
Quoted 10 lines
net/dsa/dsa2.c +9
-0+dev_hold (ethernet_dev); + ds->cd->port_ethernet[index] = ethernet_dev; + +return 0 ; +} + +static int dsa_user_parse (struct device_node *port,u32 index, +struct dsa_switch *ds) +{
Please put this function next to dsa_cpu_parse(). All the apply/unapply functions are together, and all the _parse functions should be together.
Quoted 29 lines
net/dsa/dsa2.c +14
-2+struct device_node *cpu_port; +const unsigned int *cpu_port_reg; +int cpu_port_index; + + cpu_port =of_parse_phandle (port,"cpu" ,0 ); +if (cpu_port) { + cpu_port_reg =of_get_property (cpu_port,"reg" ,NULL ); +if (!cpu_port_reg) +return -EINVAL ; + cpu_port_index =be32_to_cpup (cpu_port_reg); + ds->cd->port_cpu[index] = cpu_port_index; + } +return 0 ; }@@ -482,18 +504,20 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) {struct device_node *port;u32 index; -int err; +int err =0 ;for (index =0 ; index <DSA_MAX_PORTS ; index++) { port = ds->ports[index].dn;if (!port)continue ; -if (dsa_port_is_cpu (port)) {
net/dsa/dsa2.c static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) · line 520
Quoted 10 lines
net/dsa/dsa2.c +6
-3+if (dsa_port_is_cpu (port)) err =dsa_cpu_parse (port, index, dst, ds); -if (err) -return err; - } +else if (!dsa_port_is_dsa (port)) + err =dsa_user_parse (port, index, ds); + +if (err) +return err;
Having this if (err) here is correct, but it goes against the general pattern we have in the code. Please indent it so it is under the err =, and remove the initialisation of err.
Also, if one branch of an if/else has {}, the coding style says the other branch should also use {}.
Just to make this code look nicer, i would be tempted to add a helper, dsa_port_is_user().
net/dsa/dsa2.c static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) · line 523
Quoted 3 lines
net/dsa/dsa2.c +0
-0}pr_info ("DSA: switch %d %d parsed\n" , dst->tree, ds->index);
Thanks
Andrew
Andrew Lunn
maintainerRe: [RFC 2/4] net-next: dsa: Refactor DT probing of a switch port
In reply to John CrispinQuoted 4 lines · John Crispin
From: Andrew Lunn <[email protected]>
Move the DT probing of a switch port into a function of its own, since it is about to get more complex. Add better error handling as well.
Hi John
I would prefer to drop the majority of this. Just keep enough that it does not break, but don't implement multiple CPU ports.
Andrew
Andrew Lunn
maintainerRe: [RFC 3/4] net-next: dsa: Add support for multiple cpu ports.
In reply to John CrispinQuoted 26 lines · John Crispin
From: Andrew Lunn <[email protected]>
Some boards have two CPU interfaces connected to the switch, e.g. WiFi access points, with 1 port labeled WAN, 4 ports labeled lan1-lan4, and two port connected to the SoC.
This patch extends DSA to allows both CPU ports to be used. The "cpu" node in the DSA tree can now have a phandle to the host interface it connects to. Each user port can have a phandle to a cpu port which should be used for traffic between the port and the CPU. Thus simple load sharing over the two CPU ports can be achieved.
Signed-off-by John Crispin <[email protected]>Signed-off-by Andrew Lunn <[email protected]>--- include/net/dsa.h | 21 ++++++++++++++++++++- net/dsa/dsa2.c | 36 ++++++++++++++++++++++++++++++------ net/dsa/dsa_priv.h | 5 +++++ net/dsa/slave.c | 27 ++++++++++++++++----------- 4 files changed, 71 insertions(+), 18 deletions(-)include/net/dsa.h +0
-0
include/net/dsa.h struct dsa_chip_data { · line 64
Quoted 5 lines
include/net/dsa.h +2
-0@@ -60,6 +60,8 @@ struct dsa_chip_data {*/ char *port_names[DSA_MAX_PORTS ];struct device_node *port_dn[DSA_MAX_PORTS ]; +struct net_device *port_ethernet[DSA_MAX_PORTS ]; +int port_cpu[DSA_MAX_PORTS ];
Hi John
My proof of concept patches have "bit rotted" a bit. When implementing dsa2, i removed the use of dsa_chip_data, aka cd, from all the drivers and the new binding does not use it at all. I don't want to add it back again. When Florain removes the old binding in 6 months time, i expect dsa_chip_data and dsa_platform_data will be removed.
I would be tempted to put these two members into the dsa_port structure.
Andrew
Andrew Lunn
maintainerRe: [RFC 4/4] net-next: dsa: qca8k: add support for multiple cpu ports
In reply to John CrispinQuoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+/* Setup the cpu ports */ +for (i =0 ; i <DSA_MAX_PORTS ; i++) { +struct net_device *netdev; +int phy_mode =-1 ; + +if (!dsa_is_cpu_port (ds, i)) +continue ; + + netdev = ds->dst->pd->chip->port_ethernet[i]; +if (!netdev) {
drivers/net/dsa/qca8k.c line 549
Quoted 10 lines
drivers/net/dsa/qca8k.c +10
-0+pr_err ("Can't find netdev for port%d\n" , i); +return -ENODEV ; + } + +/* Initialize CPU port pad mode (xMII type, delays...) */ + phy_mode =of_get_phy_mode (netdev->dev.parent->of_node); +if (phy_mode <0 ) { +pr_err ("Can't find phy-mode for port:%d\n" , i); +return phy_mode; + }
Hi John
We try to avoid having the switch drivers parse the DSA device tree. There is code in the DSA core to do what you want here.
dsa.c: dsa_cpu_dsa_setup() will parse the phy-mode property, if you have a fixed-phy node in the "cpu" or "dsa" node. It will then call the drivers adjust_list_() function, which can then set the xMII type etc.
The problem might be how to make use of this without breaking backwards compatibility with older device tree blobs.
Andrew
Re: [RFC 3/4] net-next: dsa: Add support for multiple cpu ports.
In reply to Andrew LunnQuoted 35 lines · Andrew Lunn
Quoted 26 lines · John Crispin
From: Andrew Lunn <[email protected]>
Some boards have two CPU interfaces connected to the switch, e.g. WiFi access points, with 1 port labeled WAN, 4 ports labeled lan1-lan4, and two port connected to the SoC.
This patch extends DSA to allows both CPU ports to be used. The "cpu" node in the DSA tree can now have a phandle to the host interface it connects to. Each user port can have a phandle to a cpu port which should be used for traffic between the port and the CPU. Thus simple load sharing over the two CPU ports can be achieved.
Signed-off-by John Crispin <[email protected]>Signed-off-by Andrew Lunn <[email protected]>--- include/net/dsa.h | 21 ++++++++++++++++++++- net/dsa/dsa2.c | 36 ++++++++++++++++++++++++++++++------ net/dsa/dsa_priv.h | 5 +++++ net/dsa/slave.c | 27 ++++++++++++++++----------- 4 files changed, 71 insertions(+), 18 deletions(-)include/net/dsa.h +0
-0include/net/dsa.h struct dsa_chip_data { · line 64
Quoted 5 lines
include/net/dsa.h +2
-0@@ -60,6 +60,8 @@ struct dsa_chip_data {*/ char *port_names[DSA_MAX_PORTS ];struct device_node *port_dn[DSA_MAX_PORTS ]; +struct net_device *port_ethernet[DSA_MAX_PORTS ]; +int port_cpu[DSA_MAX_PORTS ];Hi John
Quoted 5 lines
My proof of concept patches have "bit rotted" a bit. When implementing dsa2, i removed the use of
dsa_chip_data, aka cd, from all the drivers and the new binding does not use it at all. I don't want to add it back again. When Florain removes the old binding in 6 months time, i expectdsa_chip_dataanddsa_platform_datawill be removed.
I am actually in the process of cleaning up my patches that add platform_data support to net/dsa/dsa2.c this time with an user, and hopefully a couple more after that, but that maintains the existing struct dsa_chip_data as-is, no new additions are required, and this would be purely for non-DT enabled platforms anyway.
Signature · 1 line
Florian
Andrew Lunn
maintainerRe: [RFC 3/4] net-next: dsa: Add support for multiple cpu ports.
Quoted 5 lines
I am actually in the process of cleaning up my patches that add
platform_datasupport tonet/dsa/dsa2.cthis time with an user, and hopefully a couple more after that, but that maintains the existing structdsa_chip_dataas-is, no new additions are required, and this would be purely for non-DT enabled platforms anyway.
Hi Florian
I was hoping we could avoid this complexity. But if there is a real need, the platform cannot be converted to device tree, we can add it.
Andrew