Merge branch 'phy_ksettings'
Philippe Reynes says: ==================== net: phy: add phy_ethtool_{get|set}_link_ksettings Ethtool callbacks {get|set}_link_ksettings may be the same for many drivers. So we add two generics callbacks phy_ethtool_{get|set}_link_ksettings. To use those generics callbacks, the ethernet driver must use the pointer phydev contained in struct net_device, and not use a private structure to store this pointer. Changelog: v3: - rename function to phy_ethtool_{get|set}_link_ksettings - move code to net/phy/phy.c This feedback were provided by David Decotigny v2: - use generic function instead of macro - ethernet driver use the pointer phydev provided by struct net_device Those idea were provided by Ben Hutchings, and Florian Fainelli acknowledge them. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
dc6079d8ab
|
@ -517,7 +517,6 @@ struct fec_enet_private {
|
|||
|
||||
/* Phylib and MDIO interface */
|
||||
struct mii_bus *mii_bus;
|
||||
struct phy_device *phy_dev;
|
||||
int mii_timeout;
|
||||
uint phy_speed;
|
||||
phy_interface_t phy_interface;
|
||||
|
|
|
@ -967,10 +967,10 @@ fec_restart(struct net_device *ndev)
|
|||
rcntl &= ~(1 << 8);
|
||||
|
||||
/* 1G, 100M or 10M */
|
||||
if (fep->phy_dev) {
|
||||
if (fep->phy_dev->speed == SPEED_1000)
|
||||
if (ndev->phydev) {
|
||||
if (ndev->phydev->speed == SPEED_1000)
|
||||
ecntl |= (1 << 5);
|
||||
else if (fep->phy_dev->speed == SPEED_100)
|
||||
else if (ndev->phydev->speed == SPEED_100)
|
||||
rcntl &= ~(1 << 9);
|
||||
else
|
||||
rcntl |= (1 << 9);
|
||||
|
@ -991,7 +991,7 @@ fec_restart(struct net_device *ndev)
|
|||
*/
|
||||
cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
|
||||
? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII;
|
||||
if (fep->phy_dev && fep->phy_dev->speed == SPEED_10)
|
||||
if (ndev->phydev && ndev->phydev->speed == SPEED_10)
|
||||
cfgr |= BM_MIIGSK_CFGR_FRCONT_10M;
|
||||
writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR);
|
||||
|
||||
|
@ -1005,7 +1005,7 @@ fec_restart(struct net_device *ndev)
|
|||
/* enable pause frame*/
|
||||
if ((fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) ||
|
||||
((fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) &&
|
||||
fep->phy_dev && fep->phy_dev->pause)) {
|
||||
ndev->phydev && ndev->phydev->pause)) {
|
||||
rcntl |= FEC_ENET_FCE;
|
||||
|
||||
/* set FIFO threshold parameter to reduce overrun */
|
||||
|
@ -1685,7 +1685,7 @@ static void fec_get_mac(struct net_device *ndev)
|
|||
static void fec_enet_adjust_link(struct net_device *ndev)
|
||||
{
|
||||
struct fec_enet_private *fep = netdev_priv(ndev);
|
||||
struct phy_device *phy_dev = fep->phy_dev;
|
||||
struct phy_device *phy_dev = ndev->phydev;
|
||||
int status_change = 0;
|
||||
|
||||
/* Prevent a state halted on mii error */
|
||||
|
@ -1885,8 +1885,6 @@ static int fec_enet_mii_probe(struct net_device *ndev)
|
|||
int phy_id;
|
||||
int dev_id = fep->dev_id;
|
||||
|
||||
fep->phy_dev = NULL;
|
||||
|
||||
if (fep->phy_node) {
|
||||
phy_dev = of_phy_connect(ndev, fep->phy_node,
|
||||
&fec_enet_adjust_link, 0,
|
||||
|
@ -1934,7 +1932,6 @@ static int fec_enet_mii_probe(struct net_device *ndev)
|
|||
|
||||
phy_dev->advertising = phy_dev->supported;
|
||||
|
||||
fep->phy_dev = phy_dev;
|
||||
fep->link = 0;
|
||||
fep->full_duplex = 0;
|
||||
|
||||
|
@ -2064,30 +2061,6 @@ static void fec_enet_mii_remove(struct fec_enet_private *fep)
|
|||
}
|
||||
}
|
||||
|
||||
static int fec_enet_get_link_ksettings(struct net_device *ndev,
|
||||
struct ethtool_link_ksettings *cmd)
|
||||
{
|
||||
struct fec_enet_private *fep = netdev_priv(ndev);
|
||||
struct phy_device *phydev = fep->phy_dev;
|
||||
|
||||
if (!phydev)
|
||||
return -ENODEV;
|
||||
|
||||
return phy_ethtool_ksettings_get(phydev, cmd);
|
||||
}
|
||||
|
||||
static int fec_enet_set_link_ksettings(struct net_device *ndev,
|
||||
const struct ethtool_link_ksettings *cmd)
|
||||
{
|
||||
struct fec_enet_private *fep = netdev_priv(ndev);
|
||||
struct phy_device *phydev = fep->phy_dev;
|
||||
|
||||
if (!phydev)
|
||||
return -ENODEV;
|
||||
|
||||
return phy_ethtool_ksettings_set(phydev, cmd);
|
||||
}
|
||||
|
||||
static void fec_enet_get_drvinfo(struct net_device *ndev,
|
||||
struct ethtool_drvinfo *info)
|
||||
{
|
||||
|
@ -2220,7 +2193,7 @@ static int fec_enet_set_pauseparam(struct net_device *ndev,
|
|||
{
|
||||
struct fec_enet_private *fep = netdev_priv(ndev);
|
||||
|
||||
if (!fep->phy_dev)
|
||||
if (!ndev->phydev)
|
||||
return -ENODEV;
|
||||
|
||||
if (pause->tx_pause != pause->rx_pause) {
|
||||
|
@ -2236,17 +2209,17 @@ static int fec_enet_set_pauseparam(struct net_device *ndev,
|
|||
fep->pause_flag |= pause->autoneg ? FEC_PAUSE_FLAG_AUTONEG : 0;
|
||||
|
||||
if (pause->rx_pause || pause->autoneg) {
|
||||
fep->phy_dev->supported |= ADVERTISED_Pause;
|
||||
fep->phy_dev->advertising |= ADVERTISED_Pause;
|
||||
ndev->phydev->supported |= ADVERTISED_Pause;
|
||||
ndev->phydev->advertising |= ADVERTISED_Pause;
|
||||
} else {
|
||||
fep->phy_dev->supported &= ~ADVERTISED_Pause;
|
||||
fep->phy_dev->advertising &= ~ADVERTISED_Pause;
|
||||
ndev->phydev->supported &= ~ADVERTISED_Pause;
|
||||
ndev->phydev->advertising &= ~ADVERTISED_Pause;
|
||||
}
|
||||
|
||||
if (pause->autoneg) {
|
||||
if (netif_running(ndev))
|
||||
fec_stop(ndev);
|
||||
phy_start_aneg(fep->phy_dev);
|
||||
phy_start_aneg(ndev->phydev);
|
||||
}
|
||||
if (netif_running(ndev)) {
|
||||
napi_disable(&fep->napi);
|
||||
|
@ -2362,8 +2335,7 @@ static int fec_enet_get_sset_count(struct net_device *dev, int sset)
|
|||
|
||||
static int fec_enet_nway_reset(struct net_device *dev)
|
||||
{
|
||||
struct fec_enet_private *fep = netdev_priv(dev);
|
||||
struct phy_device *phydev = fep->phy_dev;
|
||||
struct phy_device *phydev = dev->phydev;
|
||||
|
||||
if (!phydev)
|
||||
return -ENODEV;
|
||||
|
@ -2587,14 +2559,14 @@ static const struct ethtool_ops fec_enet_ethtool_ops = {
|
|||
.set_tunable = fec_enet_set_tunable,
|
||||
.get_wol = fec_enet_get_wol,
|
||||
.set_wol = fec_enet_set_wol,
|
||||
.get_link_ksettings = fec_enet_get_link_ksettings,
|
||||
.set_link_ksettings = fec_enet_set_link_ksettings,
|
||||
.get_link_ksettings = phy_ethtool_get_link_ksettings,
|
||||
.set_link_ksettings = phy_ethtool_set_link_ksettings,
|
||||
};
|
||||
|
||||
static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
|
||||
{
|
||||
struct fec_enet_private *fep = netdev_priv(ndev);
|
||||
struct phy_device *phydev = fep->phy_dev;
|
||||
struct phy_device *phydev = ndev->phydev;
|
||||
|
||||
if (!netif_running(ndev))
|
||||
return -EINVAL;
|
||||
|
@ -2849,7 +2821,7 @@ fec_enet_open(struct net_device *ndev)
|
|||
goto err_enet_mii_probe;
|
||||
|
||||
napi_enable(&fep->napi);
|
||||
phy_start(fep->phy_dev);
|
||||
phy_start(ndev->phydev);
|
||||
netif_tx_start_all_queues(ndev);
|
||||
|
||||
device_set_wakeup_enable(&ndev->dev, fep->wol_flag &
|
||||
|
@ -2873,7 +2845,7 @@ fec_enet_close(struct net_device *ndev)
|
|||
{
|
||||
struct fec_enet_private *fep = netdev_priv(ndev);
|
||||
|
||||
phy_stop(fep->phy_dev);
|
||||
phy_stop(ndev->phydev);
|
||||
|
||||
if (netif_device_present(ndev)) {
|
||||
napi_disable(&fep->napi);
|
||||
|
@ -2881,8 +2853,7 @@ fec_enet_close(struct net_device *ndev)
|
|||
fec_stop(ndev);
|
||||
}
|
||||
|
||||
phy_disconnect(fep->phy_dev);
|
||||
fep->phy_dev = NULL;
|
||||
phy_disconnect(ndev->phydev);
|
||||
|
||||
fec_enet_clk_enable(ndev, false);
|
||||
pinctrl_pm_select_sleep_state(&fep->pdev->dev);
|
||||
|
@ -3510,7 +3481,7 @@ static int __maybe_unused fec_suspend(struct device *dev)
|
|||
if (netif_running(ndev)) {
|
||||
if (fep->wol_flag & FEC_WOL_FLAG_ENABLE)
|
||||
fep->wol_flag |= FEC_WOL_FLAG_SLEEP_ON;
|
||||
phy_stop(fep->phy_dev);
|
||||
phy_stop(ndev->phydev);
|
||||
napi_disable(&fep->napi);
|
||||
netif_tx_lock_bh(ndev);
|
||||
netif_device_detach(ndev);
|
||||
|
@ -3570,7 +3541,7 @@ static int __maybe_unused fec_resume(struct device *dev)
|
|||
netif_device_attach(ndev);
|
||||
netif_tx_unlock_bh(ndev);
|
||||
napi_enable(&fep->napi);
|
||||
phy_start(fep->phy_dev);
|
||||
phy_start(ndev->phydev);
|
||||
}
|
||||
rtnl_unlock();
|
||||
|
||||
|
|
|
@ -1347,3 +1347,27 @@ void phy_ethtool_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
|
|||
phydev->drv->get_wol(phydev, wol);
|
||||
}
|
||||
EXPORT_SYMBOL(phy_ethtool_get_wol);
|
||||
|
||||
int phy_ethtool_get_link_ksettings(struct net_device *ndev,
|
||||
struct ethtool_link_ksettings *cmd)
|
||||
{
|
||||
struct phy_device *phydev = ndev->phydev;
|
||||
|
||||
if (!phydev)
|
||||
return -ENODEV;
|
||||
|
||||
return phy_ethtool_ksettings_get(phydev, cmd);
|
||||
}
|
||||
EXPORT_SYMBOL(phy_ethtool_get_link_ksettings);
|
||||
|
||||
int phy_ethtool_set_link_ksettings(struct net_device *ndev,
|
||||
const struct ethtool_link_ksettings *cmd)
|
||||
{
|
||||
struct phy_device *phydev = ndev->phydev;
|
||||
|
||||
if (!phydev)
|
||||
return -ENODEV;
|
||||
|
||||
return phy_ethtool_ksettings_set(phydev, cmd);
|
||||
}
|
||||
EXPORT_SYMBOL(phy_ethtool_set_link_ksettings);
|
||||
|
|
|
@ -829,6 +829,10 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
|
|||
int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
|
||||
void phy_ethtool_get_wol(struct phy_device *phydev,
|
||||
struct ethtool_wolinfo *wol);
|
||||
int phy_ethtool_get_link_ksettings(struct net_device *ndev,
|
||||
struct ethtool_link_ksettings *cmd);
|
||||
int phy_ethtool_set_link_ksettings(struct net_device *ndev,
|
||||
const struct ethtool_link_ksettings *cmd);
|
||||
|
||||
int __init mdio_bus_init(void);
|
||||
void mdio_bus_exit(void);
|
||||
|
|
Loading…
Reference in New Issue