aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2015-04-01 22:06:31 -0400
committerDavid S. Miller <davem@davemloft.net>2015-04-01 22:55:40 -0400
commitd198893e73c66ceb36cc1b1c3f261e82b7cc5700 (patch)
tree41827697e0595cdf0b42f8d30d89f36e7099038e
parentb2eb06627718836f7d133141693ec9685b4c4ef5 (diff)
net: dsa: mv88e6131: Determine and use number of switch ports
Determine and use number of switch ports from chip ID instead of always using the maximum, and return error when an attempt is made to access a non-existing port. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/dsa/mv88e6131.c42
-rw-r--r--drivers/net/dsa/mv88e6xxx.h1
2 files changed, 36 insertions, 7 deletions
diff --git a/drivers/net/dsa/mv88e6131.c b/drivers/net/dsa/mv88e6131.c
index f0dea2d1581e..6b818fde2216 100644
--- a/drivers/net/dsa/mv88e6131.c
+++ b/drivers/net/dsa/mv88e6131.c
@@ -44,12 +44,13 @@ static char *mv88e6131_probe(struct device *host_dev, int sw_addr)
44 44
45static int mv88e6131_switch_reset(struct dsa_switch *ds) 45static int mv88e6131_switch_reset(struct dsa_switch *ds)
46{ 46{
47 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
47 int i; 48 int i;
48 int ret; 49 int ret;
49 unsigned long timeout; 50 unsigned long timeout;
50 51
51 /* Set all ports to the disabled state. */ 52 /* Set all ports to the disabled state. */
52 for (i = 0; i < 11; i++) { 53 for (i = 0; i < ps->num_ports; i++) {
53 ret = REG_READ(REG_PORT(i), 0x04); 54 ret = REG_READ(REG_PORT(i), 0x04);
54 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc); 55 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
55 } 56 }
@@ -255,6 +256,7 @@ static int mv88e6131_setup_port(struct dsa_switch *ds, int p)
255 256
256static int mv88e6131_setup(struct dsa_switch *ds) 257static int mv88e6131_setup(struct dsa_switch *ds)
257{ 258{
259 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
258 int i; 260 int i;
259 int ret; 261 int ret;
260 262
@@ -264,6 +266,21 @@ static int mv88e6131_setup(struct dsa_switch *ds)
264 266
265 mv88e6xxx_ppu_state_init(ds); 267 mv88e6xxx_ppu_state_init(ds);
266 268
269 switch (ps->id) {
270 case ID_6085:
271 ps->num_ports = 10;
272 break;
273 case ID_6095:
274 ps->num_ports = 11;
275 break;
276 case ID_6131:
277 case ID_6131_B2:
278 ps->num_ports = 8;
279 break;
280 default:
281 return -ENODEV;
282 }
283
267 ret = mv88e6131_switch_reset(ds); 284 ret = mv88e6131_switch_reset(ds);
268 if (ret < 0) 285 if (ret < 0)
269 return ret; 286 return ret;
@@ -274,7 +291,7 @@ static int mv88e6131_setup(struct dsa_switch *ds)
274 if (ret < 0) 291 if (ret < 0)
275 return ret; 292 return ret;
276 293
277 for (i = 0; i < 11; i++) { 294 for (i = 0; i < ps->num_ports; i++) {
278 ret = mv88e6131_setup_port(ds, i); 295 ret = mv88e6131_setup_port(ds, i);
279 if (ret < 0) 296 if (ret < 0)
280 return ret; 297 return ret;
@@ -283,17 +300,24 @@ static int mv88e6131_setup(struct dsa_switch *ds)
283 return 0; 300 return 0;
284} 301}
285 302
286static int mv88e6131_port_to_phy_addr(int port) 303static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
287{ 304{
288 if (port >= 0 && port <= 11) 305 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
306
307 if (port >= 0 && port < ps->num_ports)
289 return port; 308 return port;
290 return -1; 309
310 return -EINVAL;
291} 311}
292 312
293static int 313static int
294mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum) 314mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
295{ 315{
296 int addr = mv88e6131_port_to_phy_addr(port); 316 int addr = mv88e6131_port_to_phy_addr(ds, port);
317
318 if (addr < 0)
319 return addr;
320
297 return mv88e6xxx_phy_read_ppu(ds, addr, regnum); 321 return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
298} 322}
299 323
@@ -301,7 +325,11 @@ static int
301mv88e6131_phy_write(struct dsa_switch *ds, 325mv88e6131_phy_write(struct dsa_switch *ds,
302 int port, int regnum, u16 val) 326 int port, int regnum, u16 val)
303{ 327{
304 int addr = mv88e6131_port_to_phy_addr(port); 328 int addr = mv88e6131_port_to_phy_addr(ds, port);
329
330 if (addr < 0)
331 return addr;
332
305 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val); 333 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
306} 334}
307 335
diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h
index aca48792db4b..ef058444bdb7 100644
--- a/drivers/net/dsa/mv88e6xxx.h
+++ b/drivers/net/dsa/mv88e6xxx.h
@@ -109,6 +109,7 @@ struct mv88e6xxx_priv_state {
109 struct mutex eeprom_mutex; 109 struct mutex eeprom_mutex;
110 110
111 int id; /* switch product id */ 111 int id; /* switch product id */
112 int num_ports; /* number of switch ports */
112 113
113 /* hw bridging */ 114 /* hw bridging */
114 115