Commit 9e8e6e88 authored by Philippe Reynes's avatar Philippe Reynes Committed by David S. Miller

net: ethernet: cavium: octeon: use phydev from struct net_device

The private structure contain a pointer to phydev, but the structure
net_device already contain such pointer. So we can remove the pointer
phy in the private structure, and update the driver to use the
one contained in struct net_device.
Signed-off-by: default avatarPhilippe Reynes <tremyfr@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5d4de16c
...@@ -146,7 +146,6 @@ struct octeon_mgmt { ...@@ -146,7 +146,6 @@ struct octeon_mgmt {
struct device *dev; struct device *dev;
struct napi_struct napi; struct napi_struct napi;
struct tasklet_struct tx_clean_tasklet; struct tasklet_struct tx_clean_tasklet;
struct phy_device *phydev;
struct device_node *phy_np; struct device_node *phy_np;
resource_size_t mix_phys; resource_size_t mix_phys;
resource_size_t mix_size; resource_size_t mix_size;
...@@ -787,14 +786,12 @@ static int octeon_mgmt_ioctl_hwtstamp(struct net_device *netdev, ...@@ -787,14 +786,12 @@ static int octeon_mgmt_ioctl_hwtstamp(struct net_device *netdev,
static int octeon_mgmt_ioctl(struct net_device *netdev, static int octeon_mgmt_ioctl(struct net_device *netdev,
struct ifreq *rq, int cmd) struct ifreq *rq, int cmd)
{ {
struct octeon_mgmt *p = netdev_priv(netdev);
switch (cmd) { switch (cmd) {
case SIOCSHWTSTAMP: case SIOCSHWTSTAMP:
return octeon_mgmt_ioctl_hwtstamp(netdev, rq, cmd); return octeon_mgmt_ioctl_hwtstamp(netdev, rq, cmd);
default: default:
if (p->phydev) if (netdev->phydev)
return phy_mii_ioctl(p->phydev, rq, cmd); return phy_mii_ioctl(netdev->phydev, rq, cmd);
return -EINVAL; return -EINVAL;
} }
} }
...@@ -836,16 +833,18 @@ static void octeon_mgmt_enable_link(struct octeon_mgmt *p) ...@@ -836,16 +833,18 @@ static void octeon_mgmt_enable_link(struct octeon_mgmt *p)
static void octeon_mgmt_update_link(struct octeon_mgmt *p) static void octeon_mgmt_update_link(struct octeon_mgmt *p)
{ {
struct net_device *ndev = p->netdev;
struct phy_device *phydev = ndev->phydev;
union cvmx_agl_gmx_prtx_cfg prtx_cfg; union cvmx_agl_gmx_prtx_cfg prtx_cfg;
prtx_cfg.u64 = cvmx_read_csr(p->agl + AGL_GMX_PRT_CFG); prtx_cfg.u64 = cvmx_read_csr(p->agl + AGL_GMX_PRT_CFG);
if (!p->phydev->link) if (!phydev->link)
prtx_cfg.s.duplex = 1; prtx_cfg.s.duplex = 1;
else else
prtx_cfg.s.duplex = p->phydev->duplex; prtx_cfg.s.duplex = phydev->duplex;
switch (p->phydev->speed) { switch (phydev->speed) {
case 10: case 10:
prtx_cfg.s.speed = 0; prtx_cfg.s.speed = 0;
prtx_cfg.s.slottime = 0; prtx_cfg.s.slottime = 0;
...@@ -871,7 +870,7 @@ static void octeon_mgmt_update_link(struct octeon_mgmt *p) ...@@ -871,7 +870,7 @@ static void octeon_mgmt_update_link(struct octeon_mgmt *p)
prtx_cfg.s.speed_msb = 0; prtx_cfg.s.speed_msb = 0;
/* Only matters for half-duplex */ /* Only matters for half-duplex */
prtx_cfg.s.slottime = 1; prtx_cfg.s.slottime = 1;
prtx_cfg.s.burst = p->phydev->duplex; prtx_cfg.s.burst = phydev->duplex;
} }
break; break;
case 0: /* No link */ case 0: /* No link */
...@@ -894,9 +893,9 @@ static void octeon_mgmt_update_link(struct octeon_mgmt *p) ...@@ -894,9 +893,9 @@ static void octeon_mgmt_update_link(struct octeon_mgmt *p)
/* MII (both speeds) and RGMII 1000 speed. */ /* MII (both speeds) and RGMII 1000 speed. */
agl_clk.s.clk_cnt = 1; agl_clk.s.clk_cnt = 1;
if (prtx_ctl.s.mode == 0) { /* RGMII mode */ if (prtx_ctl.s.mode == 0) { /* RGMII mode */
if (p->phydev->speed == 10) if (phydev->speed == 10)
agl_clk.s.clk_cnt = 50; agl_clk.s.clk_cnt = 50;
else if (p->phydev->speed == 100) else if (phydev->speed == 100)
agl_clk.s.clk_cnt = 5; agl_clk.s.clk_cnt = 5;
} }
cvmx_write_csr(p->agl + AGL_GMX_TX_CLK, agl_clk.u64); cvmx_write_csr(p->agl + AGL_GMX_TX_CLK, agl_clk.u64);
...@@ -906,39 +905,40 @@ static void octeon_mgmt_update_link(struct octeon_mgmt *p) ...@@ -906,39 +905,40 @@ static void octeon_mgmt_update_link(struct octeon_mgmt *p)
static void octeon_mgmt_adjust_link(struct net_device *netdev) static void octeon_mgmt_adjust_link(struct net_device *netdev)
{ {
struct octeon_mgmt *p = netdev_priv(netdev); struct octeon_mgmt *p = netdev_priv(netdev);
struct phy_device *phydev = netdev->phydev;
unsigned long flags; unsigned long flags;
int link_changed = 0; int link_changed = 0;
if (!p->phydev) if (!phydev)
return; return;
spin_lock_irqsave(&p->lock, flags); spin_lock_irqsave(&p->lock, flags);
if (!p->phydev->link && p->last_link) if (!phydev->link && p->last_link)
link_changed = -1; link_changed = -1;
if (p->phydev->link if (phydev->link &&
&& (p->last_duplex != p->phydev->duplex (p->last_duplex != phydev->duplex ||
|| p->last_link != p->phydev->link p->last_link != phydev->link ||
|| p->last_speed != p->phydev->speed)) { p->last_speed != phydev->speed)) {
octeon_mgmt_disable_link(p); octeon_mgmt_disable_link(p);
link_changed = 1; link_changed = 1;
octeon_mgmt_update_link(p); octeon_mgmt_update_link(p);
octeon_mgmt_enable_link(p); octeon_mgmt_enable_link(p);
} }
p->last_link = p->phydev->link; p->last_link = phydev->link;
p->last_speed = p->phydev->speed; p->last_speed = phydev->speed;
p->last_duplex = p->phydev->duplex; p->last_duplex = phydev->duplex;
spin_unlock_irqrestore(&p->lock, flags); spin_unlock_irqrestore(&p->lock, flags);
if (link_changed != 0) { if (link_changed != 0) {
if (link_changed > 0) { if (link_changed > 0) {
pr_info("%s: Link is up - %d/%s\n", netdev->name, pr_info("%s: Link is up - %d/%s\n", netdev->name,
p->phydev->speed, phydev->speed,
DUPLEX_FULL == p->phydev->duplex ? phydev->duplex == DUPLEX_FULL ?
"Full" : "Half"); "Full" : "Half");
} else { } else {
pr_info("%s: Link is down\n", netdev->name); pr_info("%s: Link is down\n", netdev->name);
...@@ -949,6 +949,7 @@ static void octeon_mgmt_adjust_link(struct net_device *netdev) ...@@ -949,6 +949,7 @@ static void octeon_mgmt_adjust_link(struct net_device *netdev)
static int octeon_mgmt_init_phy(struct net_device *netdev) static int octeon_mgmt_init_phy(struct net_device *netdev)
{ {
struct octeon_mgmt *p = netdev_priv(netdev); struct octeon_mgmt *p = netdev_priv(netdev);
struct phy_device *phydev = NULL;
if (octeon_is_simulation() || p->phy_np == NULL) { if (octeon_is_simulation() || p->phy_np == NULL) {
/* No PHYs in the simulator. */ /* No PHYs in the simulator. */
...@@ -956,11 +957,11 @@ static int octeon_mgmt_init_phy(struct net_device *netdev) ...@@ -956,11 +957,11 @@ static int octeon_mgmt_init_phy(struct net_device *netdev)
return 0; return 0;
} }
p->phydev = of_phy_connect(netdev, p->phy_np, phydev = of_phy_connect(netdev, p->phy_np,
octeon_mgmt_adjust_link, 0, octeon_mgmt_adjust_link, 0,
PHY_INTERFACE_MODE_MII); PHY_INTERFACE_MODE_MII);
if (!p->phydev) if (!phydev)
return -ENODEV; return -ENODEV;
return 0; return 0;
...@@ -1080,9 +1081,9 @@ static int octeon_mgmt_open(struct net_device *netdev) ...@@ -1080,9 +1081,9 @@ static int octeon_mgmt_open(struct net_device *netdev)
} }
/* Set the mode of the interface, RGMII/MII. */ /* Set the mode of the interface, RGMII/MII. */
if (OCTEON_IS_MODEL(OCTEON_CN6XXX) && p->phydev) { if (OCTEON_IS_MODEL(OCTEON_CN6XXX) && netdev->phydev) {
union cvmx_agl_prtx_ctl agl_prtx_ctl; union cvmx_agl_prtx_ctl agl_prtx_ctl;
int rgmii_mode = (p->phydev->supported & int rgmii_mode = (netdev->phydev->supported &
(SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)) != 0; (SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)) != 0;
agl_prtx_ctl.u64 = cvmx_read_csr(p->agl_prt_ctl); agl_prtx_ctl.u64 = cvmx_read_csr(p->agl_prt_ctl);
...@@ -1205,7 +1206,7 @@ static int octeon_mgmt_open(struct net_device *netdev) ...@@ -1205,7 +1206,7 @@ static int octeon_mgmt_open(struct net_device *netdev)
/* Configure the port duplex, speed and enables */ /* Configure the port duplex, speed and enables */
octeon_mgmt_disable_link(p); octeon_mgmt_disable_link(p);
if (p->phydev) if (netdev->phydev)
octeon_mgmt_update_link(p); octeon_mgmt_update_link(p);
octeon_mgmt_enable_link(p); octeon_mgmt_enable_link(p);
...@@ -1214,9 +1215,9 @@ static int octeon_mgmt_open(struct net_device *netdev) ...@@ -1214,9 +1215,9 @@ static int octeon_mgmt_open(struct net_device *netdev)
/* PHY is not present in simulator. The carrier is enabled /* PHY is not present in simulator. The carrier is enabled
* while initializing the phy for simulator, leave it enabled. * while initializing the phy for simulator, leave it enabled.
*/ */
if (p->phydev) { if (netdev->phydev) {
netif_carrier_off(netdev); netif_carrier_off(netdev);
phy_start_aneg(p->phydev); phy_start_aneg(netdev->phydev);
} }
netif_wake_queue(netdev); netif_wake_queue(netdev);
...@@ -1244,9 +1245,8 @@ static int octeon_mgmt_stop(struct net_device *netdev) ...@@ -1244,9 +1245,8 @@ static int octeon_mgmt_stop(struct net_device *netdev)
napi_disable(&p->napi); napi_disable(&p->napi);
netif_stop_queue(netdev); netif_stop_queue(netdev);
if (p->phydev) if (netdev->phydev)
phy_disconnect(p->phydev); phy_disconnect(netdev->phydev);
p->phydev = NULL;
netif_carrier_off(netdev); netif_carrier_off(netdev);
...@@ -1349,10 +1349,8 @@ static void octeon_mgmt_get_drvinfo(struct net_device *netdev, ...@@ -1349,10 +1349,8 @@ static void octeon_mgmt_get_drvinfo(struct net_device *netdev,
static int octeon_mgmt_get_settings(struct net_device *netdev, static int octeon_mgmt_get_settings(struct net_device *netdev,
struct ethtool_cmd *cmd) struct ethtool_cmd *cmd)
{ {
struct octeon_mgmt *p = netdev_priv(netdev); if (netdev->phydev)
return phy_ethtool_gset(netdev->phydev, cmd);
if (p->phydev)
return phy_ethtool_gset(p->phydev, cmd);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1360,26 +1358,22 @@ static int octeon_mgmt_get_settings(struct net_device *netdev, ...@@ -1360,26 +1358,22 @@ static int octeon_mgmt_get_settings(struct net_device *netdev,
static int octeon_mgmt_set_settings(struct net_device *netdev, static int octeon_mgmt_set_settings(struct net_device *netdev,
struct ethtool_cmd *cmd) struct ethtool_cmd *cmd)
{ {
struct octeon_mgmt *p = netdev_priv(netdev);
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (p->phydev) if (netdev->phydev)
return phy_ethtool_sset(p->phydev, cmd); return phy_ethtool_sset(netdev->phydev, cmd);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static int octeon_mgmt_nway_reset(struct net_device *dev) static int octeon_mgmt_nway_reset(struct net_device *dev)
{ {
struct octeon_mgmt *p = netdev_priv(dev);
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (p->phydev) if (dev->phydev)
return phy_start_aneg(p->phydev); return phy_start_aneg(dev->phydev);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment