Skip to content

Commit 6912378

Browse files
committed
Merge branch 'phylink-sfp-updates'
Russell King says: ==================== phylink/sfp updates This is a series of updates to phylink and sfp: - Remove an unused net device argument from the phylink MII ioctl emulation code. - add support for using interrupts when using a GPIO for link status tracking, rather than polling it at one second intervals. This reduces the need to wakeup the CPU every second. - add support to the MII ioctl API to read and write Clause 45 PHY registers. I don't know how desirable this is for mainline, but I have used this facility extensively to investigate the Marvell 88x3310 PHY. A recent illustration of use for this was debugging the PHY-without-firmware problem recently reported. - add mandatory attach/detach methods for the upstream side of sfp bus code, which will allow us to remove the "netdev" structure from the SFP layers. - remove the "netdev" structure from the SFP upstream registration calls, which simplifies PHY to SFP links. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents b4b12b0 + 54f70b3 commit 6912378

File tree

4 files changed

+90
-36
lines changed

4 files changed

+90
-36
lines changed

drivers/net/phy/phy.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,21 +409,37 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
409409
struct mii_ioctl_data *mii_data = if_mii(ifr);
410410
u16 val = mii_data->val_in;
411411
bool change_autoneg = false;
412+
int prtad, devad;
412413

413414
switch (cmd) {
414415
case SIOCGMIIPHY:
415416
mii_data->phy_id = phydev->mdio.addr;
416417
/* fall through */
417418

418419
case SIOCGMIIREG:
419-
mii_data->val_out = mdiobus_read(phydev->mdio.bus,
420-
mii_data->phy_id,
421-
mii_data->reg_num);
420+
if (mdio_phy_id_is_c45(mii_data->phy_id)) {
421+
prtad = mdio_phy_id_prtad(mii_data->phy_id);
422+
devad = mdio_phy_id_devad(mii_data->phy_id);
423+
devad = MII_ADDR_C45 | devad << 16 | mii_data->reg_num;
424+
} else {
425+
prtad = mii_data->phy_id;
426+
devad = mii_data->reg_num;
427+
}
428+
mii_data->val_out = mdiobus_read(phydev->mdio.bus, prtad,
429+
devad);
422430
return 0;
423431

424432
case SIOCSMIIREG:
425-
if (mii_data->phy_id == phydev->mdio.addr) {
426-
switch (mii_data->reg_num) {
433+
if (mdio_phy_id_is_c45(mii_data->phy_id)) {
434+
prtad = mdio_phy_id_prtad(mii_data->phy_id);
435+
devad = mdio_phy_id_devad(mii_data->phy_id);
436+
devad = MII_ADDR_C45 | devad << 16 | mii_data->reg_num;
437+
} else {
438+
prtad = mii_data->phy_id;
439+
devad = mii_data->reg_num;
440+
}
441+
if (prtad == phydev->mdio.addr) {
442+
switch (devad) {
427443
case MII_BMCR:
428444
if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) {
429445
if (phydev->autoneg == AUTONEG_ENABLE)
@@ -456,11 +472,10 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
456472
}
457473
}
458474

459-
mdiobus_write(phydev->mdio.bus, mii_data->phy_id,
460-
mii_data->reg_num, val);
475+
mdiobus_write(phydev->mdio.bus, prtad, devad, val);
461476

462-
if (mii_data->phy_id == phydev->mdio.addr &&
463-
mii_data->reg_num == MII_BMCR &&
477+
if (prtad == phydev->mdio.addr &&
478+
devad == MII_BMCR &&
464479
val & BMCR_RESET)
465480
return phy_init_hw(phydev);
466481

drivers/net/phy/phylink.c

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct phylink {
5959
phy_interface_t cur_interface;
6060

6161
struct gpio_desc *link_gpio;
62+
unsigned int link_irq;
6263
struct timer_list link_poll;
6364
void (*get_fixed_state)(struct net_device *dev,
6465
struct phylink_link_state *s);
@@ -564,8 +565,7 @@ static int phylink_register_sfp(struct phylink *pl,
564565
return ret;
565566
}
566567

567-
pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl->netdev, pl,
568-
&sfp_phylink_ops);
568+
pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl, &sfp_phylink_ops);
569569
if (!pl->sfp_bus)
570570
return -ENOMEM;
571571

@@ -665,7 +665,7 @@ void phylink_destroy(struct phylink *pl)
665665
{
666666
if (pl->sfp_bus)
667667
sfp_unregister_upstream(pl->sfp_bus);
668-
if (!IS_ERR_OR_NULL(pl->link_gpio))
668+
if (pl->link_gpio)
669669
gpiod_put(pl->link_gpio);
670670

671671
cancel_work_sync(&pl->resolve);
@@ -928,6 +928,15 @@ void phylink_mac_change(struct phylink *pl, bool up)
928928
}
929929
EXPORT_SYMBOL_GPL(phylink_mac_change);
930930

931+
static irqreturn_t phylink_link_handler(int irq, void *data)
932+
{
933+
struct phylink *pl = data;
934+
935+
phylink_run_resolve(pl);
936+
937+
return IRQ_HANDLED;
938+
}
939+
931940
/**
932941
* phylink_start() - start a phylink instance
933942
* @pl: a pointer to a &struct phylink returned from phylink_create()
@@ -964,7 +973,22 @@ void phylink_start(struct phylink *pl)
964973
clear_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
965974
phylink_run_resolve(pl);
966975

967-
if (pl->link_an_mode == MLO_AN_FIXED && !IS_ERR(pl->link_gpio))
976+
if (pl->link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
977+
int irq = gpiod_to_irq(pl->link_gpio);
978+
979+
if (irq > 0) {
980+
if (!request_irq(irq, phylink_link_handler,
981+
IRQF_TRIGGER_RISING |
982+
IRQF_TRIGGER_FALLING,
983+
"netdev link", pl))
984+
pl->link_irq = irq;
985+
else
986+
irq = 0;
987+
}
988+
if (irq <= 0)
989+
mod_timer(&pl->link_poll, jiffies + HZ);
990+
}
991+
if (pl->link_an_mode == MLO_AN_FIXED && pl->get_fixed_state)
968992
mod_timer(&pl->link_poll, jiffies + HZ);
969993
if (pl->sfp_bus)
970994
sfp_upstream_start(pl->sfp_bus);
@@ -990,8 +1014,11 @@ void phylink_stop(struct phylink *pl)
9901014
phy_stop(pl->phydev);
9911015
if (pl->sfp_bus)
9921016
sfp_upstream_stop(pl->sfp_bus);
993-
if (pl->link_an_mode == MLO_AN_FIXED && !IS_ERR(pl->link_gpio))
994-
del_timer_sync(&pl->link_poll);
1017+
del_timer_sync(&pl->link_poll);
1018+
if (pl->link_irq) {
1019+
free_irq(pl->link_irq, pl);
1020+
pl->link_irq = 0;
1021+
}
9951022

9961023
phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED);
9971024
}
@@ -1395,8 +1422,8 @@ EXPORT_SYMBOL_GPL(phylink_ethtool_set_eee);
13951422
*
13961423
* FIXME: should deal with negotiation state too.
13971424
*/
1398-
static int phylink_mii_emul_read(struct net_device *ndev, unsigned int reg,
1399-
struct phylink_link_state *state, bool aneg)
1425+
static int phylink_mii_emul_read(unsigned int reg,
1426+
struct phylink_link_state *state)
14001427
{
14011428
struct fixed_phy_status fs;
14021429
int val;
@@ -1411,8 +1438,6 @@ static int phylink_mii_emul_read(struct net_device *ndev, unsigned int reg,
14111438
if (reg == MII_BMSR) {
14121439
if (!state->an_complete)
14131440
val &= ~BMSR_ANEGCOMPLETE;
1414-
if (!aneg)
1415-
val &= ~BMSR_ANEGCAPABLE;
14161441
}
14171442
return val;
14181443
}
@@ -1508,8 +1533,7 @@ static int phylink_mii_read(struct phylink *pl, unsigned int phy_id,
15081533
case MLO_AN_FIXED:
15091534
if (phy_id == 0) {
15101535
phylink_get_fixed_state(pl, &state);
1511-
val = phylink_mii_emul_read(pl->netdev, reg, &state,
1512-
true);
1536+
val = phylink_mii_emul_read(reg, &state);
15131537
}
15141538
break;
15151539

@@ -1522,8 +1546,7 @@ static int phylink_mii_read(struct phylink *pl, unsigned int phy_id,
15221546
if (val < 0)
15231547
return val;
15241548

1525-
val = phylink_mii_emul_read(pl->netdev, reg, &state,
1526-
true);
1549+
val = phylink_mii_emul_read(reg, &state);
15271550
}
15281551
break;
15291552
}
@@ -1626,6 +1649,20 @@ int phylink_mii_ioctl(struct phylink *pl, struct ifreq *ifr, int cmd)
16261649
}
16271650
EXPORT_SYMBOL_GPL(phylink_mii_ioctl);
16281651

1652+
static void phylink_sfp_attach(void *upstream, struct sfp_bus *bus)
1653+
{
1654+
struct phylink *pl = upstream;
1655+
1656+
pl->netdev->sfp_bus = bus;
1657+
}
1658+
1659+
static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)
1660+
{
1661+
struct phylink *pl = upstream;
1662+
1663+
pl->netdev->sfp_bus = NULL;
1664+
}
1665+
16291666
static int phylink_sfp_module_insert(void *upstream,
16301667
const struct sfp_eeprom_id *id)
16311668
{
@@ -1744,6 +1781,8 @@ static void phylink_sfp_disconnect_phy(void *upstream)
17441781
}
17451782

17461783
static const struct sfp_upstream_ops sfp_phylink_ops = {
1784+
.attach = phylink_sfp_attach,
1785+
.detach = phylink_sfp_detach,
17471786
.module_insert = phylink_sfp_module_insert,
17481787
.link_up = phylink_sfp_link_up,
17491788
.link_down = phylink_sfp_link_down,

drivers/net/phy/sfp-bus.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ struct sfp_bus {
2424

2525
const struct sfp_upstream_ops *upstream_ops;
2626
void *upstream;
27-
struct net_device *netdev;
2827
struct phy_device *phydev;
2928

3029
bool registered;
@@ -351,7 +350,7 @@ static int sfp_register_bus(struct sfp_bus *bus)
351350
bus->socket_ops->attach(bus->sfp);
352351
if (bus->started)
353352
bus->socket_ops->start(bus->sfp);
354-
bus->netdev->sfp_bus = bus;
353+
bus->upstream_ops->attach(bus->upstream, bus);
355354
bus->registered = true;
356355
return 0;
357356
}
@@ -360,8 +359,8 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
360359
{
361360
const struct sfp_upstream_ops *ops = bus->upstream_ops;
362361

363-
bus->netdev->sfp_bus = NULL;
364362
if (bus->registered) {
363+
bus->upstream_ops->detach(bus->upstream, bus);
365364
if (bus->started)
366365
bus->socket_ops->stop(bus->sfp);
367366
bus->socket_ops->detach(bus->sfp);
@@ -443,13 +442,11 @@ static void sfp_upstream_clear(struct sfp_bus *bus)
443442
{
444443
bus->upstream_ops = NULL;
445444
bus->upstream = NULL;
446-
bus->netdev = NULL;
447445
}
448446

449447
/**
450448
* sfp_register_upstream() - Register the neighbouring device
451449
* @fwnode: firmware node for the SFP bus
452-
* @ndev: network device associated with the interface
453450
* @upstream: the upstream private data
454451
* @ops: the upstream's &struct sfp_upstream_ops
455452
*
@@ -460,7 +457,7 @@ static void sfp_upstream_clear(struct sfp_bus *bus)
460457
* On error, returns %NULL.
461458
*/
462459
struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
463-
struct net_device *ndev, void *upstream,
460+
void *upstream,
464461
const struct sfp_upstream_ops *ops)
465462
{
466463
struct sfp_bus *bus = sfp_bus_get(fwnode);
@@ -470,7 +467,6 @@ struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
470467
rtnl_lock();
471468
bus->upstream_ops = ops;
472469
bus->upstream = upstream;
473-
bus->netdev = ndev;
474470

475471
if (bus->sfp) {
476472
ret = sfp_register_bus(bus);
@@ -592,7 +588,7 @@ struct sfp_bus *sfp_register_socket(struct device *dev, struct sfp *sfp,
592588
bus->sfp = sfp;
593589
bus->socket_ops = ops;
594590

595-
if (bus->netdev) {
591+
if (bus->upstream_ops) {
596592
ret = sfp_register_bus(bus);
597593
if (ret)
598594
sfp_socket_clear(bus);
@@ -612,7 +608,7 @@ EXPORT_SYMBOL_GPL(sfp_register_socket);
612608
void sfp_unregister_socket(struct sfp_bus *bus)
613609
{
614610
rtnl_lock();
615-
if (bus->netdev)
611+
if (bus->upstream_ops)
616612
sfp_unregister_bus(bus);
617613
sfp_socket_clear(bus);
618614
rtnl_unlock();

include/linux/sfp.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,14 @@ enum {
464464
struct fwnode_handle;
465465
struct ethtool_eeprom;
466466
struct ethtool_modinfo;
467-
struct net_device;
468467
struct sfp_bus;
469468

470469
/**
471470
* struct sfp_upstream_ops - upstream operations structure
471+
* @attach: called when the sfp socket driver is bound to the upstream
472+
* (mandatory).
473+
* @detach: called when the sfp socket driver is unbound from the upstream
474+
* (mandatory).
472475
* @module_insert: called after a module has been detected to determine
473476
* whether the module is supported for the upstream device.
474477
* @module_remove: called after the module has been removed.
@@ -481,6 +484,8 @@ struct sfp_bus;
481484
* been removed.
482485
*/
483486
struct sfp_upstream_ops {
487+
void (*attach)(void *priv, struct sfp_bus *bus);
488+
void (*detach)(void *priv, struct sfp_bus *bus);
484489
int (*module_insert)(void *priv, const struct sfp_eeprom_id *id);
485490
void (*module_remove)(void *priv);
486491
void (*link_down)(void *priv);
@@ -504,7 +509,7 @@ int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
504509
void sfp_upstream_start(struct sfp_bus *bus);
505510
void sfp_upstream_stop(struct sfp_bus *bus);
506511
struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
507-
struct net_device *ndev, void *upstream,
512+
void *upstream,
508513
const struct sfp_upstream_ops *ops);
509514
void sfp_unregister_upstream(struct sfp_bus *bus);
510515
#else
@@ -549,8 +554,7 @@ static inline void sfp_upstream_stop(struct sfp_bus *bus)
549554
}
550555

551556
static inline struct sfp_bus *sfp_register_upstream(
552-
struct fwnode_handle *fwnode,
553-
struct net_device *ndev, void *upstream,
557+
struct fwnode_handle *fwnode, void *upstream,
554558
const struct sfp_upstream_ops *ops)
555559
{
556560
return (struct sfp_bus *)-1;

0 commit comments

Comments
 (0)