aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/dsa
diff options
context:
space:
mode:
authorAndrew Lunn <andrew@lunn.ch>2015-04-01 22:06:33 -0400
committerDavid S. Miller <davem@davemloft.net>2015-04-01 22:55:40 -0400
commit44e50ddbc74a4bd6a862be9e6de22bce8c0b4150 (patch)
tree924eef387293c87024a27716e711c5649c211ed9 /drivers/net/dsa
parent14ef6ad22a2db28021e8ea8cd068fe5fcd88de7b (diff)
net: dsa: Consistently set and use ps->num_ports
As a step towards consolidating code, consistently set the number of ports in the private state structure, and make use of it in loops. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Tested-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/dsa')
-rw-r--r--drivers/net/dsa/mv88e6171.c23
-rw-r--r--drivers/net/dsa/mv88e6352.c10
2 files changed, 22 insertions, 11 deletions
diff --git a/drivers/net/dsa/mv88e6171.c b/drivers/net/dsa/mv88e6171.c
index 639bd83b76c7..5a295533ff20 100644
--- a/drivers/net/dsa/mv88e6171.c
+++ b/drivers/net/dsa/mv88e6171.c
@@ -38,12 +38,13 @@ static char *mv88e6171_probe(struct device *host_dev, int sw_addr)
38 38
39static int mv88e6171_switch_reset(struct dsa_switch *ds) 39static int mv88e6171_switch_reset(struct dsa_switch *ds)
40{ 40{
41 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
41 int i; 42 int i;
42 int ret; 43 int ret;
43 unsigned long timeout; 44 unsigned long timeout;
44 45
45 /* Set all ports to the disabled state. */ 46 /* Set all ports to the disabled state. */
46 for (i = 0; i < 8; i++) { 47 for (i = 0; i < ps->num_ports; i++) {
47 ret = REG_READ(REG_PORT(i), 0x04); 48 ret = REG_READ(REG_PORT(i), 0x04);
48 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc); 49 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
49 } 50 }
@@ -70,7 +71,7 @@ static int mv88e6171_switch_reset(struct dsa_switch *ds)
70 return -ETIMEDOUT; 71 return -ETIMEDOUT;
71 72
72 /* Enable ports not under DSA, e.g. WAN port */ 73 /* Enable ports not under DSA, e.g. WAN port */
73 for (i = 0; i < 8; i++) { 74 for (i = 0; i < ps->num_ports; i++) {
74 if (dsa_is_cpu_port(ds, i) || ds->phys_port_mask & (1 << i)) 75 if (dsa_is_cpu_port(ds, i) || ds->phys_port_mask & (1 << i))
75 continue; 76 continue;
76 77
@@ -83,6 +84,7 @@ static int mv88e6171_switch_reset(struct dsa_switch *ds)
83 84
84static int mv88e6171_setup_global(struct dsa_switch *ds) 85static int mv88e6171_setup_global(struct dsa_switch *ds)
85{ 86{
87 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
86 int ret; 88 int ret;
87 int i; 89 int i;
88 90
@@ -147,7 +149,7 @@ static int mv88e6171_setup_global(struct dsa_switch *ds)
147 } 149 }
148 150
149 /* Clear all trunk masks. */ 151 /* Clear all trunk masks. */
150 for (i = 0; i < 8; i++) 152 for (i = 0; i < ps->num_ports; i++)
151 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0xff); 153 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0xff);
152 154
153 /* Clear all trunk mappings. */ 155 /* Clear all trunk mappings. */
@@ -270,6 +272,7 @@ static int mv88e6171_setup_port(struct dsa_switch *ds, int p)
270 272
271static int mv88e6171_setup(struct dsa_switch *ds) 273static int mv88e6171_setup(struct dsa_switch *ds)
272{ 274{
275 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
273 int i; 276 int i;
274 int ret; 277 int ret;
275 278
@@ -277,6 +280,8 @@ static int mv88e6171_setup(struct dsa_switch *ds)
277 if (ret < 0) 280 if (ret < 0)
278 return ret; 281 return ret;
279 282
283 ps->num_ports = 7;
284
280 ret = mv88e6171_switch_reset(ds); 285 ret = mv88e6171_switch_reset(ds);
281 if (ret < 0) 286 if (ret < 0)
282 return ret; 287 return ret;
@@ -287,7 +292,7 @@ static int mv88e6171_setup(struct dsa_switch *ds)
287 if (ret < 0) 292 if (ret < 0)
288 return ret; 293 return ret;
289 294
290 for (i = 0; i < 8; i++) { 295 for (i = 0; i < ps->num_ports; i++) {
291 if (!(dsa_is_cpu_port(ds, i) || ds->phys_port_mask & (1 << i))) 296 if (!(dsa_is_cpu_port(ds, i) || ds->phys_port_mask & (1 << i)))
292 continue; 297 continue;
293 298
@@ -299,9 +304,11 @@ static int mv88e6171_setup(struct dsa_switch *ds)
299 return 0; 304 return 0;
300} 305}
301 306
302static int mv88e6171_port_to_phy_addr(int port) 307static int mv88e6171_port_to_phy_addr(struct dsa_switch *ds, int port)
303{ 308{
304 if (port >= 0 && port <= 4) 309 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
310
311 if (port >= 0 && port < ps->num_ports)
305 return port; 312 return port;
306 return -1; 313 return -1;
307} 314}
@@ -310,7 +317,7 @@ static int
310mv88e6171_phy_read(struct dsa_switch *ds, int port, int regnum) 317mv88e6171_phy_read(struct dsa_switch *ds, int port, int regnum)
311{ 318{
312 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 319 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
313 int addr = mv88e6171_port_to_phy_addr(port); 320 int addr = mv88e6171_port_to_phy_addr(ds, port);
314 int ret; 321 int ret;
315 322
316 mutex_lock(&ps->phy_mutex); 323 mutex_lock(&ps->phy_mutex);
@@ -324,7 +331,7 @@ mv88e6171_phy_write(struct dsa_switch *ds,
324 int port, int regnum, u16 val) 331 int port, int regnum, u16 val)
325{ 332{
326 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); 333 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
327 int addr = mv88e6171_port_to_phy_addr(port); 334 int addr = mv88e6171_port_to_phy_addr(ds, port);
328 int ret; 335 int ret;
329 336
330 mutex_lock(&ps->phy_mutex); 337 mutex_lock(&ps->phy_mutex);
diff --git a/drivers/net/dsa/mv88e6352.c b/drivers/net/dsa/mv88e6352.c
index 41fe3a6a72d1..040027fcd013 100644
--- a/drivers/net/dsa/mv88e6352.c
+++ b/drivers/net/dsa/mv88e6352.c
@@ -47,12 +47,13 @@ static char *mv88e6352_probe(struct device *host_dev, int sw_addr)
47 47
48static int mv88e6352_switch_reset(struct dsa_switch *ds) 48static int mv88e6352_switch_reset(struct dsa_switch *ds)
49{ 49{
50 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
50 unsigned long timeout; 51 unsigned long timeout;
51 int ret; 52 int ret;
52 int i; 53 int i;
53 54
54 /* Set all ports to the disabled state. */ 55 /* Set all ports to the disabled state. */
55 for (i = 0; i < 7; i++) { 56 for (i = 0; i < ps->num_ports; i++) {
56 ret = REG_READ(REG_PORT(i), 0x04); 57 ret = REG_READ(REG_PORT(i), 0x04);
57 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc); 58 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
58 } 59 }
@@ -82,6 +83,7 @@ static int mv88e6352_switch_reset(struct dsa_switch *ds)
82 83
83static int mv88e6352_setup_global(struct dsa_switch *ds) 84static int mv88e6352_setup_global(struct dsa_switch *ds)
84{ 85{
86 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
85 int ret; 87 int ret;
86 int i; 88 int i;
87 89
@@ -152,7 +154,7 @@ static int mv88e6352_setup_global(struct dsa_switch *ds)
152 /* Disable ingress rate limiting by resetting all ingress 154 /* Disable ingress rate limiting by resetting all ingress
153 * rate limit registers to their initial state. 155 * rate limit registers to their initial state.
154 */ 156 */
155 for (i = 0; i < 7; i++) 157 for (i = 0; i < ps->num_ports; i++)
156 REG_WRITE(REG_GLOBAL2, 0x09, 0x9000 | (i << 8)); 158 REG_WRITE(REG_GLOBAL2, 0x09, 0x9000 | (i << 8));
157 159
158 /* Initialise cross-chip port VLAN table to reset defaults. */ 160 /* Initialise cross-chip port VLAN table to reset defaults. */
@@ -367,6 +369,8 @@ static int mv88e6352_setup(struct dsa_switch *ds)
367 if (ret < 0) 369 if (ret < 0)
368 return ret; 370 return ret;
369 371
372 ps->num_ports = 7;
373
370 mutex_init(&ps->eeprom_mutex); 374 mutex_init(&ps->eeprom_mutex);
371 375
372 ret = mv88e6352_switch_reset(ds); 376 ret = mv88e6352_switch_reset(ds);
@@ -379,7 +383,7 @@ static int mv88e6352_setup(struct dsa_switch *ds)
379 if (ret < 0) 383 if (ret < 0)
380 return ret; 384 return ret;
381 385
382 for (i = 0; i < 7; i++) { 386 for (i = 0; i < ps->num_ports; i++) {
383 ret = mv88e6352_setup_port(ds, i); 387 ret = mv88e6352_setup_port(ds, i);
384 if (ret < 0) 388 if (ret < 0)
385 return ret; 389 return ret;