Skip to content

Commit 3c783b8

Browse files
Russell Kingkuba-moo
authored andcommitted
net: dsa: mv88e6xxx: get rid of SPEED_MAX setting
Currently, all the device specific speed setting functions convert SPEED_MAX to the actual speed of the port. Rather than having each of the mv88e6xxx chip specifics handling SPEED_MAX, derive it from the mac_capabilities instead. This is only needed for CPU and DSA ports, so move the logic up into mv88e6xxx_setup_port() - which allows us to kill off all users of SPEED_MAX throughout the driver. Signed-off-by: Russell King <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent aa64bc1 commit 3c783b8

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,6 @@ static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
449449
goto restore_link;
450450
}
451451

452-
if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
453-
mode = chip->info->ops->port_max_speed_mode(port);
454-
455452
if (chip->info->ops->port_set_pause) {
456453
err = chip->info->ops->port_set_pause(chip, port, pause);
457454
if (err)
@@ -3280,28 +3277,51 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
32803277
{
32813278
struct device_node *phy_handle = NULL;
32823279
struct dsa_switch *ds = chip->ds;
3280+
phy_interface_t mode;
32833281
struct dsa_port *dp;
3284-
int tx_amp;
3282+
int tx_amp, speed;
32853283
int err;
32863284
u16 reg;
32873285

32883286
chip->ports[port].chip = chip;
32893287
chip->ports[port].port = port;
32903288

3289+
dp = dsa_to_port(ds, port);
3290+
32913291
/* MAC Forcing register: don't force link, speed, duplex or flow control
32923292
* state to any particular values on physical ports, but force the CPU
32933293
* port and all DSA ports to their maximum bandwidth and full duplex.
32943294
*/
3295-
if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
3295+
if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
3296+
unsigned long caps = dp->pl_config.mac_capabilities;
3297+
3298+
if (chip->info->ops->port_max_speed_mode)
3299+
mode = chip->info->ops->port_max_speed_mode(port);
3300+
else
3301+
mode = PHY_INTERFACE_MODE_NA;
3302+
3303+
if (caps & MAC_10000FD)
3304+
speed = SPEED_10000;
3305+
else if (caps & MAC_5000FD)
3306+
speed = SPEED_5000;
3307+
else if (caps & MAC_2500FD)
3308+
speed = SPEED_2500;
3309+
else if (caps & MAC_1000)
3310+
speed = SPEED_1000;
3311+
else if (caps & MAC_100)
3312+
speed = SPEED_100;
3313+
else
3314+
speed = SPEED_10;
3315+
32963316
err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
3297-
SPEED_MAX, DUPLEX_FULL,
3298-
PAUSE_OFF,
3299-
PHY_INTERFACE_MODE_NA);
3300-
else
3317+
speed, DUPLEX_FULL,
3318+
PAUSE_OFF, mode);
3319+
} else {
33013320
err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
33023321
SPEED_UNFORCED, DUPLEX_UNFORCED,
33033322
PAUSE_ON,
33043323
PHY_INTERFACE_MODE_NA);
3324+
}
33053325
if (err)
33063326
return err;
33073327

@@ -3473,7 +3493,6 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
34733493
}
34743494

34753495
if (chip->info->ops->serdes_set_tx_amplitude) {
3476-
dp = dsa_to_port(ds, port);
34773496
if (dp)
34783497
phy_handle = of_parse_phandle(dp->dn, "phy-handle", 0);
34793498

drivers/net/dsa/mv88e6xxx/chip.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,13 @@ struct mv88e6xxx_ops {
488488
int (*port_set_pause)(struct mv88e6xxx_chip *chip, int port,
489489
int pause);
490490

491-
#define SPEED_MAX INT_MAX
492491
#define SPEED_UNFORCED -2
493492
#define DUPLEX_UNFORCED -2
494493

495494
/* Port's MAC speed (in Mbps) and MAC duplex mode
496495
*
497496
* Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
498-
* Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
497+
* Use SPEED_UNFORCED for normal detection.
499498
*
500499
* Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
501500
* or DUPLEX_UNFORCED for normal duplex detection.

drivers/net/dsa/mv88e6xxx/port.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ static int mv88e6xxx_port_set_speed_duplex(struct mv88e6xxx_chip *chip,
298298
int mv88e6185_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
299299
int speed, int duplex)
300300
{
301-
if (speed == SPEED_MAX)
302-
speed = 1000;
303-
304301
if (speed == 200 || speed > 1000)
305302
return -EOPNOTSUPP;
306303

@@ -312,9 +309,6 @@ int mv88e6185_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
312309
int mv88e6250_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
313310
int speed, int duplex)
314311
{
315-
if (speed == SPEED_MAX)
316-
speed = 100;
317-
318312
if (speed > 100)
319313
return -EOPNOTSUPP;
320314

@@ -326,9 +320,6 @@ int mv88e6250_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
326320
int mv88e6341_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
327321
int speed, int duplex)
328322
{
329-
if (speed == SPEED_MAX)
330-
speed = port < 5 ? 1000 : 2500;
331-
332323
if (speed > 2500)
333324
return -EOPNOTSUPP;
334325

@@ -354,9 +345,6 @@ phy_interface_t mv88e6341_port_max_speed_mode(int port)
354345
int mv88e6352_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
355346
int speed, int duplex)
356347
{
357-
if (speed == SPEED_MAX)
358-
speed = 1000;
359-
360348
if (speed > 1000)
361349
return -EOPNOTSUPP;
362350

@@ -371,9 +359,6 @@ int mv88e6352_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
371359
int mv88e6390_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
372360
int speed, int duplex)
373361
{
374-
if (speed == SPEED_MAX)
375-
speed = port < 9 ? 1000 : 2500;
376-
377362
if (speed > 2500)
378363
return -EOPNOTSUPP;
379364

@@ -399,9 +384,6 @@ phy_interface_t mv88e6390_port_max_speed_mode(int port)
399384
int mv88e6390x_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
400385
int speed, int duplex)
401386
{
402-
if (speed == SPEED_MAX)
403-
speed = port < 9 ? 1000 : 10000;
404-
405387
if (speed == 200 && port != 0)
406388
return -EOPNOTSUPP;
407389

@@ -430,9 +412,6 @@ int mv88e6393x_port_set_speed_duplex(struct mv88e6xxx_chip *chip, int port,
430412
u16 reg, ctrl;
431413
int err;
432414

433-
if (speed == SPEED_MAX)
434-
speed = (port > 0 && port < 9) ? 1000 : 10000;
435-
436415
if (speed == 200 && port != 0)
437416
return -EOPNOTSUPP;
438417

0 commit comments

Comments
 (0)