Skip to content

Commit ff50eda

Browse files
committed
Merge branch 'More-complete-PHYLINK-support-for-mv88e6xxx'
Andrew Lunn says: ==================== More complete PHYLINK support for mv88e6xxx Previous patches added sufficient PHYLINK support to the mv88e6xxx that it did not break existing use cases, basically fixed-link phys. This patchset builds out the support so that SFP modules, up to 2.5Gbps can be supported, on mv88e6390X, on ports 9 and 10. It also provides a framework which can be extended to support SFPs on ports 2-8 of mv88e6390X, 10Gbps PHYs, and SFP support on the 6352 family. Russell King did much of the initial work, implementing the validate and mac_link_state calls. However, there is an important TODO in the commit message: needs to call phylink_mac_change() when the port link comes up/goes down. The remaining patches implement this, by adding more support for the SERDES interfaces, in particular, interrupt support so we get notified when the SERDES gains/looses sync. This has been tested on the ZII devel C, using a Clearfog as peer device. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 78b3906 + 734447d commit ff50eda

8 files changed

Lines changed: 767 additions & 109 deletions

File tree

‎drivers/net/dsa/mv88e6xxx/chip.c‎

Lines changed: 219 additions & 7 deletions
Large diffs are not rendered by default.

‎drivers/net/dsa/mv88e6xxx/chip.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,16 @@ struct mv88e6xxx_port_hwtstamp {
191191
};
192192

193193
struct mv88e6xxx_port {
194+
struct mv88e6xxx_chip *chip;
195+
int port;
194196
u64 serdes_stats[2];
195197
u64 atu_member_violation;
196198
u64 atu_miss_violation;
197199
u64 atu_full_violation;
198200
u64 vtu_member_violation;
199201
u64 vtu_miss_violation;
202+
u8 cmode;
203+
int serdes_irq;
200204
};
201205

202206
struct mv88e6xxx_chip {
@@ -351,6 +355,13 @@ struct mv88e6xxx_ops {
351355
*/
352356
int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
353357

358+
#define PAUSE_ON 1
359+
#define PAUSE_OFF 0
360+
361+
/* Enable/disable sending Pause */
362+
int (*port_set_pause)(struct mv88e6xxx_chip *chip, int port,
363+
int pause);
364+
354365
#define SPEED_MAX INT_MAX
355366
#define SPEED_UNFORCED -2
356367

@@ -383,12 +394,16 @@ struct mv88e6xxx_ops {
383394
*/
384395
int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
385396
phy_interface_t mode);
397+
int (*port_get_cmode)(struct mv88e6xxx_chip *chip, int port, u8 *cmode);
386398

387399
/* Some devices have a per port register indicating what is
388400
* the upstream port this port should forward to.
389401
*/
390402
int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
391403
int upstream_port);
404+
/* Return the port link state, as required by phylink */
405+
int (*port_link_state)(struct mv88e6xxx_chip *chip, int port,
406+
struct phylink_link_state *state);
392407

393408
/* Snapshot the statistics for a port. The statistics can then
394409
* be read back a leisure but still with a consistent view.
@@ -420,6 +435,10 @@ struct mv88e6xxx_ops {
420435
/* Power on/off a SERDES interface */
421436
int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);
422437

438+
/* SERDES interrupt handling */
439+
int (*serdes_irq_setup)(struct mv88e6xxx_chip *chip, int port);
440+
void (*serdes_irq_free)(struct mv88e6xxx_chip *chip, int port);
441+
423442
/* Statistics from the SERDES interface */
424443
int (*serdes_get_sset_count)(struct mv88e6xxx_chip *chip, int port);
425444
int (*serdes_get_strings)(struct mv88e6xxx_chip *chip, int port,
@@ -444,6 +463,11 @@ struct mv88e6xxx_ops {
444463

445464
/* Precision Time Protocol operations */
446465
const struct mv88e6xxx_ptp_ops *ptp_ops;
466+
467+
/* Phylink */
468+
void (*phylink_validate)(struct mv88e6xxx_chip *chip, int port,
469+
unsigned long *mask,
470+
struct phylink_link_state *state);
447471
};
448472

449473
struct mv88e6xxx_irq_ops {

‎drivers/net/dsa/mv88e6xxx/port.c‎

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "chip.h"
2121
#include "port.h"
22+
#include "serdes.h"
2223

2324
int mv88e6xxx_port_read(struct mv88e6xxx_chip *chip, int port, int reg,
2425
u16 *val)
@@ -36,6 +37,29 @@ int mv88e6xxx_port_write(struct mv88e6xxx_chip *chip, int port, int reg,
3637
return mv88e6xxx_write(chip, addr, reg, val);
3738
}
3839

40+
/* Offset 0x00: MAC (or PCS or Physical) Status Register
41+
*
42+
* For most devices, this is read only. However the 6185 has the MyPause
43+
* bit read/write.
44+
*/
45+
int mv88e6185_port_set_pause(struct mv88e6xxx_chip *chip, int port,
46+
int pause)
47+
{
48+
u16 reg;
49+
int err;
50+
51+
err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
52+
if (err)
53+
return err;
54+
55+
if (pause)
56+
reg |= MV88E6XXX_PORT_STS_MY_PAUSE;
57+
else
58+
reg &= ~MV88E6XXX_PORT_STS_MY_PAUSE;
59+
60+
return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_STS, reg);
61+
}
62+
3963
/* Offset 0x01: MAC (or PCS or Physical) Control Register
4064
*
4165
* Link, Duplex and Flow Control have one force bit, one value bit.
@@ -318,8 +342,9 @@ int mv88e6390x_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed)
318342
int mv88e6390x_port_set_cmode(struct mv88e6xxx_chip *chip, int port,
319343
phy_interface_t mode)
320344
{
321-
u16 reg;
345+
int lane;
322346
u16 cmode;
347+
u16 reg;
323348
int err;
324349

325350
if (mode == PHY_INTERFACE_MODE_NA)
@@ -349,6 +374,20 @@ int mv88e6390x_port_set_cmode(struct mv88e6xxx_chip *chip, int port,
349374
cmode = 0;
350375
}
351376

377+
lane = mv88e6390x_serdes_get_lane(chip, port);
378+
if (lane < 0)
379+
return lane;
380+
381+
if (chip->ports[port].serdes_irq) {
382+
err = mv88e6390_serdes_irq_disable(chip, port, lane);
383+
if (err)
384+
return err;
385+
}
386+
387+
err = mv88e6390_serdes_power(chip, port, false);
388+
if (err)
389+
return err;
390+
352391
if (cmode) {
353392
err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
354393
if (err)
@@ -360,12 +399,38 @@ int mv88e6390x_port_set_cmode(struct mv88e6xxx_chip *chip, int port,
360399
err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_STS, reg);
361400
if (err)
362401
return err;
402+
403+
err = mv88e6390_serdes_power(chip, port, true);
404+
if (err)
405+
return err;
406+
407+
if (chip->ports[port].serdes_irq) {
408+
err = mv88e6390_serdes_irq_enable(chip, port, lane);
409+
if (err)
410+
return err;
411+
}
363412
}
364413

414+
chip->ports[port].cmode = cmode;
415+
365416
return 0;
366417
}
367418

368-
int mv88e6xxx_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode)
419+
int mv88e6185_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode)
420+
{
421+
int err;
422+
u16 reg;
423+
424+
err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
425+
if (err)
426+
return err;
427+
428+
*cmode = reg & MV88E6185_PORT_STS_CMODE_MASK;
429+
430+
return 0;
431+
}
432+
433+
int mv88e6352_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode)
369434
{
370435
int err;
371436
u16 reg;
@@ -379,7 +444,7 @@ int mv88e6xxx_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode)
379444
return 0;
380445
}
381446

382-
int mv88e6xxx_port_link_state(struct mv88e6xxx_chip *chip, int port,
447+
int mv88e6352_port_link_state(struct mv88e6xxx_chip *chip, int port,
383448
struct phylink_link_state *state)
384449
{
385450
int err;
@@ -400,7 +465,7 @@ int mv88e6xxx_port_link_state(struct mv88e6xxx_chip *chip, int port,
400465
state->speed = SPEED_1000;
401466
break;
402467
case MV88E6XXX_PORT_STS_SPEED_10000:
403-
if ((reg &MV88E6XXX_PORT_STS_CMODE_MASK) ==
468+
if ((reg & MV88E6XXX_PORT_STS_CMODE_MASK) ==
404469
MV88E6XXX_PORT_STS_CMODE_2500BASEX)
405470
state->speed = SPEED_2500;
406471
else
@@ -417,6 +482,42 @@ int mv88e6xxx_port_link_state(struct mv88e6xxx_chip *chip, int port,
417482
return 0;
418483
}
419484

485+
int mv88e6185_port_link_state(struct mv88e6xxx_chip *chip, int port,
486+
struct phylink_link_state *state)
487+
{
488+
if (state->interface == PHY_INTERFACE_MODE_1000BASEX) {
489+
u8 cmode = chip->ports[port].cmode;
490+
491+
/* When a port is in "Cross-chip serdes" mode, it uses
492+
* 1000Base-X full duplex mode, but there is no automatic
493+
* link detection. Use the sync OK status for link (as it
494+
* would do for 1000Base-X mode.)
495+
*/
496+
if (cmode == MV88E6185_PORT_STS_CMODE_SERDES) {
497+
u16 mac;
498+
int err;
499+
500+
err = mv88e6xxx_port_read(chip, port,
501+
MV88E6XXX_PORT_MAC_CTL, &mac);
502+
if (err)
503+
return err;
504+
505+
state->link = !!(mac & MV88E6185_PORT_MAC_CTL_SYNC_OK);
506+
state->an_enabled = 1;
507+
state->an_complete =
508+
!!(mac & MV88E6185_PORT_MAC_CTL_AN_DONE);
509+
state->duplex =
510+
state->link ? DUPLEX_FULL : DUPLEX_UNKNOWN;
511+
state->speed =
512+
state->link ? SPEED_1000 : SPEED_UNKNOWN;
513+
514+
return 0;
515+
}
516+
}
517+
518+
return mv88e6352_port_link_state(chip, port, state);
519+
}
520+
420521
/* Offset 0x02: Jamming Control
421522
*
422523
* Do not limit the period of time that this port can be paused for by

‎drivers/net/dsa/mv88e6xxx/port.h‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,28 @@
4242
#define MV88E6XXX_PORT_STS_CMODE_2500BASEX 0x000b
4343
#define MV88E6XXX_PORT_STS_CMODE_XAUI 0x000c
4444
#define MV88E6XXX_PORT_STS_CMODE_RXAUI 0x000d
45+
#define MV88E6185_PORT_STS_CDUPLEX 0x0008
46+
#define MV88E6185_PORT_STS_CMODE_MASK 0x0007
47+
#define MV88E6185_PORT_STS_CMODE_GMII_FD 0x0000
48+
#define MV88E6185_PORT_STS_CMODE_MII_100_FD_PS 0x0001
49+
#define MV88E6185_PORT_STS_CMODE_MII_100 0x0002
50+
#define MV88E6185_PORT_STS_CMODE_MII_10 0x0003
51+
#define MV88E6185_PORT_STS_CMODE_SERDES 0x0004
52+
#define MV88E6185_PORT_STS_CMODE_1000BASE_X 0x0005
53+
#define MV88E6185_PORT_STS_CMODE_PHY 0x0006
54+
#define MV88E6185_PORT_STS_CMODE_DISABLED 0x0007
4555

4656
/* Offset 0x01: MAC (or PCS or Physical) Control Register */
4757
#define MV88E6XXX_PORT_MAC_CTL 0x01
4858
#define MV88E6XXX_PORT_MAC_CTL_RGMII_DELAY_RXCLK 0x8000
4959
#define MV88E6XXX_PORT_MAC_CTL_RGMII_DELAY_TXCLK 0x4000
60+
#define MV88E6185_PORT_MAC_CTL_SYNC_OK 0x4000
5061
#define MV88E6390_PORT_MAC_CTL_FORCE_SPEED 0x2000
5162
#define MV88E6390_PORT_MAC_CTL_ALTSPEED 0x1000
5263
#define MV88E6352_PORT_MAC_CTL_200BASE 0x1000
64+
#define MV88E6185_PORT_MAC_CTL_AN_EN 0x0400
65+
#define MV88E6185_PORT_MAC_CTL_AN_RESTART 0x0200
66+
#define MV88E6185_PORT_MAC_CTL_AN_DONE 0x0100
5367
#define MV88E6XXX_PORT_MAC_CTL_FC 0x0080
5468
#define MV88E6XXX_PORT_MAC_CTL_FORCE_FC 0x0040
5569
#define MV88E6XXX_PORT_MAC_CTL_LINK_UP 0x0020
@@ -242,6 +256,8 @@ int mv88e6xxx_port_read(struct mv88e6xxx_chip *chip, int port, int reg,
242256
int mv88e6xxx_port_write(struct mv88e6xxx_chip *chip, int port, int reg,
243257
u16 val);
244258

259+
int mv88e6185_port_set_pause(struct mv88e6xxx_chip *chip, int port,
260+
int pause);
245261
int mv88e6352_port_set_rgmii_delay(struct mv88e6xxx_chip *chip, int port,
246262
phy_interface_t mode);
247263
int mv88e6390_port_set_rgmii_delay(struct mv88e6xxx_chip *chip, int port,
@@ -295,8 +311,11 @@ int mv88e6390_port_pause_limit(struct mv88e6xxx_chip *chip, int port, u8 in,
295311
u8 out);
296312
int mv88e6390x_port_set_cmode(struct mv88e6xxx_chip *chip, int port,
297313
phy_interface_t mode);
298-
int mv88e6xxx_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode);
299-
int mv88e6xxx_port_link_state(struct mv88e6xxx_chip *chip, int port,
314+
int mv88e6185_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode);
315+
int mv88e6352_port_get_cmode(struct mv88e6xxx_chip *chip, int port, u8 *cmode);
316+
int mv88e6185_port_link_state(struct mv88e6xxx_chip *chip, int port,
317+
struct phylink_link_state *state);
318+
int mv88e6352_port_link_state(struct mv88e6xxx_chip *chip, int port,
300319
struct phylink_link_state *state);
301320
int mv88e6xxx_port_set_map_da(struct mv88e6xxx_chip *chip, int port);
302321
int mv88e6095_port_set_upstream_port(struct mv88e6xxx_chip *chip, int port,

0 commit comments

Comments
 (0)