diff options
author | Lennert Buytenhek <buytenh@marvell.com> | 2008-10-08 19:29:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-10-08 19:29:57 -0400 |
commit | 298cf9beb9679522de995e249eccbd82f7c51999 (patch) | |
tree | cabbc9c696a063982aea9a24d8caa667daa33a1a /drivers/net/tg3.c | |
parent | 18ee49ddb0d242ed1d0e273038d5e4f6de7379d3 (diff) |
phylib: move to dynamic allocation of struct mii_bus
This patch introduces mdiobus_alloc() and mdiobus_free(), and
makes all mdio bus drivers use these functions to allocate their
struct mii_bus'es dynamically.
Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Andy Fleming <afleming@freescale.com>
Diffstat (limited to 'drivers/net/tg3.c')
-rw-r--r-- | drivers/net/tg3.c | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index 4b8b75bcbde0..eb9f8f3638e1 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c | |||
@@ -876,7 +876,7 @@ static void tg3_mdio_config(struct tg3 *tp) | |||
876 | { | 876 | { |
877 | u32 val; | 877 | u32 val; |
878 | 878 | ||
879 | if (tp->mdio_bus.phy_map[PHY_ADDR]->interface != | 879 | if (tp->mdio_bus->phy_map[PHY_ADDR]->interface != |
880 | PHY_INTERFACE_MODE_RGMII) | 880 | PHY_INTERFACE_MODE_RGMII) |
881 | return; | 881 | return; |
882 | 882 | ||
@@ -920,9 +920,9 @@ static void tg3_mdio_config(struct tg3 *tp) | |||
920 | static void tg3_mdio_start(struct tg3 *tp) | 920 | static void tg3_mdio_start(struct tg3 *tp) |
921 | { | 921 | { |
922 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { | 922 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { |
923 | mutex_lock(&tp->mdio_bus.mdio_lock); | 923 | mutex_lock(&tp->mdio_bus->mdio_lock); |
924 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED; | 924 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED; |
925 | mutex_unlock(&tp->mdio_bus.mdio_lock); | 925 | mutex_unlock(&tp->mdio_bus->mdio_lock); |
926 | } | 926 | } |
927 | 927 | ||
928 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; | 928 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
@@ -936,9 +936,9 @@ static void tg3_mdio_start(struct tg3 *tp) | |||
936 | static void tg3_mdio_stop(struct tg3 *tp) | 936 | static void tg3_mdio_stop(struct tg3 *tp) |
937 | { | 937 | { |
938 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { | 938 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { |
939 | mutex_lock(&tp->mdio_bus.mdio_lock); | 939 | mutex_lock(&tp->mdio_bus->mdio_lock); |
940 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_PAUSED; | 940 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_PAUSED; |
941 | mutex_unlock(&tp->mdio_bus.mdio_lock); | 941 | mutex_unlock(&tp->mdio_bus->mdio_lock); |
942 | } | 942 | } |
943 | } | 943 | } |
944 | 944 | ||
@@ -947,7 +947,6 @@ static int tg3_mdio_init(struct tg3 *tp) | |||
947 | int i; | 947 | int i; |
948 | u32 reg; | 948 | u32 reg; |
949 | struct phy_device *phydev; | 949 | struct phy_device *phydev; |
950 | struct mii_bus *mdio_bus = &tp->mdio_bus; | ||
951 | 950 | ||
952 | tg3_mdio_start(tp); | 951 | tg3_mdio_start(tp); |
953 | 952 | ||
@@ -955,21 +954,23 @@ static int tg3_mdio_init(struct tg3 *tp) | |||
955 | (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED)) | 954 | (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED)) |
956 | return 0; | 955 | return 0; |
957 | 956 | ||
958 | memset(mdio_bus, 0, sizeof(*mdio_bus)); | 957 | tp->mdio_bus = mdiobus_alloc(); |
958 | if (tp->mdio_bus == NULL) | ||
959 | return -ENOMEM; | ||
959 | 960 | ||
960 | mdio_bus->name = "tg3 mdio bus"; | 961 | tp->mdio_bus->name = "tg3 mdio bus"; |
961 | snprintf(mdio_bus->id, MII_BUS_ID_SIZE, "%x", | 962 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
962 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); | 963 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
963 | mdio_bus->priv = tp; | 964 | tp->mdio_bus->priv = tp; |
964 | mdio_bus->parent = &tp->pdev->dev; | 965 | tp->mdio_bus->parent = &tp->pdev->dev; |
965 | mdio_bus->read = &tg3_mdio_read; | 966 | tp->mdio_bus->read = &tg3_mdio_read; |
966 | mdio_bus->write = &tg3_mdio_write; | 967 | tp->mdio_bus->write = &tg3_mdio_write; |
967 | mdio_bus->reset = &tg3_mdio_reset; | 968 | tp->mdio_bus->reset = &tg3_mdio_reset; |
968 | mdio_bus->phy_mask = ~(1 << PHY_ADDR); | 969 | tp->mdio_bus->phy_mask = ~(1 << PHY_ADDR); |
969 | mdio_bus->irq = &tp->mdio_irq[0]; | 970 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
970 | 971 | ||
971 | for (i = 0; i < PHY_MAX_ADDR; i++) | 972 | for (i = 0; i < PHY_MAX_ADDR; i++) |
972 | mdio_bus->irq[i] = PHY_POLL; | 973 | tp->mdio_bus->irq[i] = PHY_POLL; |
973 | 974 | ||
974 | /* The bus registration will look for all the PHYs on the mdio bus. | 975 | /* The bus registration will look for all the PHYs on the mdio bus. |
975 | * Unfortunately, it does not ensure the PHY is powered up before | 976 | * Unfortunately, it does not ensure the PHY is powered up before |
@@ -979,7 +980,7 @@ static int tg3_mdio_init(struct tg3 *tp) | |||
979 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) | 980 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
980 | tg3_bmcr_reset(tp); | 981 | tg3_bmcr_reset(tp); |
981 | 982 | ||
982 | i = mdiobus_register(mdio_bus); | 983 | i = mdiobus_register(tp->mdio_bus); |
983 | if (i) { | 984 | if (i) { |
984 | printk(KERN_WARNING "%s: mdiobus_reg failed (0x%x)\n", | 985 | printk(KERN_WARNING "%s: mdiobus_reg failed (0x%x)\n", |
985 | tp->dev->name, i); | 986 | tp->dev->name, i); |
@@ -988,7 +989,7 @@ static int tg3_mdio_init(struct tg3 *tp) | |||
988 | 989 | ||
989 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED; | 990 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED; |
990 | 991 | ||
991 | phydev = tp->mdio_bus.phy_map[PHY_ADDR]; | 992 | phydev = tp->mdio_bus->phy_map[PHY_ADDR]; |
992 | 993 | ||
993 | switch (phydev->phy_id) { | 994 | switch (phydev->phy_id) { |
994 | case TG3_PHY_ID_BCM50610: | 995 | case TG3_PHY_ID_BCM50610: |
@@ -1014,7 +1015,8 @@ static void tg3_mdio_fini(struct tg3 *tp) | |||
1014 | { | 1015 | { |
1015 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { | 1016 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { |
1016 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED; | 1017 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED; |
1017 | mdiobus_unregister(&tp->mdio_bus); | 1018 | mdiobus_unregister(tp->mdio_bus); |
1019 | mdiobus_free(tp->mdio_bus); | ||
1018 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED; | 1020 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED; |
1019 | } | 1021 | } |
1020 | } | 1022 | } |
@@ -1220,7 +1222,7 @@ static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv) | |||
1220 | u32 old_tx_mode = tp->tx_mode; | 1222 | u32 old_tx_mode = tp->tx_mode; |
1221 | 1223 | ||
1222 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) | 1224 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
1223 | autoneg = tp->mdio_bus.phy_map[PHY_ADDR]->autoneg; | 1225 | autoneg = tp->mdio_bus->phy_map[PHY_ADDR]->autoneg; |
1224 | else | 1226 | else |
1225 | autoneg = tp->link_config.autoneg; | 1227 | autoneg = tp->link_config.autoneg; |
1226 | 1228 | ||
@@ -1257,7 +1259,7 @@ static void tg3_adjust_link(struct net_device *dev) | |||
1257 | u8 oldflowctrl, linkmesg = 0; | 1259 | u8 oldflowctrl, linkmesg = 0; |
1258 | u32 mac_mode, lcl_adv, rmt_adv; | 1260 | u32 mac_mode, lcl_adv, rmt_adv; |
1259 | struct tg3 *tp = netdev_priv(dev); | 1261 | struct tg3 *tp = netdev_priv(dev); |
1260 | struct phy_device *phydev = tp->mdio_bus.phy_map[PHY_ADDR]; | 1262 | struct phy_device *phydev = tp->mdio_bus->phy_map[PHY_ADDR]; |
1261 | 1263 | ||
1262 | spin_lock(&tp->lock); | 1264 | spin_lock(&tp->lock); |
1263 | 1265 | ||
@@ -1334,7 +1336,7 @@ static int tg3_phy_init(struct tg3 *tp) | |||
1334 | /* Bring the PHY back to a known state. */ | 1336 | /* Bring the PHY back to a known state. */ |
1335 | tg3_bmcr_reset(tp); | 1337 | tg3_bmcr_reset(tp); |
1336 | 1338 | ||
1337 | phydev = tp->mdio_bus.phy_map[PHY_ADDR]; | 1339 | phydev = tp->mdio_bus->phy_map[PHY_ADDR]; |
1338 | 1340 | ||
1339 | /* Attach the MAC to the PHY. */ | 1341 | /* Attach the MAC to the PHY. */ |
1340 | phydev = phy_connect(tp->dev, phydev->dev.bus_id, tg3_adjust_link, | 1342 | phydev = phy_connect(tp->dev, phydev->dev.bus_id, tg3_adjust_link, |
@@ -1367,7 +1369,7 @@ static void tg3_phy_start(struct tg3 *tp) | |||
1367 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) | 1369 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
1368 | return; | 1370 | return; |
1369 | 1371 | ||
1370 | phydev = tp->mdio_bus.phy_map[PHY_ADDR]; | 1372 | phydev = tp->mdio_bus->phy_map[PHY_ADDR]; |
1371 | 1373 | ||
1372 | if (tp->link_config.phy_is_low_power) { | 1374 | if (tp->link_config.phy_is_low_power) { |
1373 | tp->link_config.phy_is_low_power = 0; | 1375 | tp->link_config.phy_is_low_power = 0; |
@@ -1387,13 +1389,13 @@ static void tg3_phy_stop(struct tg3 *tp) | |||
1387 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) | 1389 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
1388 | return; | 1390 | return; |
1389 | 1391 | ||
1390 | phy_stop(tp->mdio_bus.phy_map[PHY_ADDR]); | 1392 | phy_stop(tp->mdio_bus->phy_map[PHY_ADDR]); |
1391 | } | 1393 | } |
1392 | 1394 | ||
1393 | static void tg3_phy_fini(struct tg3 *tp) | 1395 | static void tg3_phy_fini(struct tg3 *tp) |
1394 | { | 1396 | { |
1395 | if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) { | 1397 | if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) { |
1396 | phy_disconnect(tp->mdio_bus.phy_map[PHY_ADDR]); | 1398 | phy_disconnect(tp->mdio_bus->phy_map[PHY_ADDR]); |
1397 | tp->tg3_flags3 &= ~TG3_FLG3_PHY_CONNECTED; | 1399 | tp->tg3_flags3 &= ~TG3_FLG3_PHY_CONNECTED; |
1398 | } | 1400 | } |
1399 | } | 1401 | } |
@@ -2049,7 +2051,7 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state) | |||
2049 | struct phy_device *phydev; | 2051 | struct phy_device *phydev; |
2050 | u32 advertising; | 2052 | u32 advertising; |
2051 | 2053 | ||
2052 | phydev = tp->mdio_bus.phy_map[PHY_ADDR]; | 2054 | phydev = tp->mdio_bus->phy_map[PHY_ADDR]; |
2053 | 2055 | ||
2054 | tp->link_config.phy_is_low_power = 1; | 2056 | tp->link_config.phy_is_low_power = 1; |
2055 | 2057 | ||
@@ -8954,7 +8956,7 @@ static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |||
8954 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { | 8956 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
8955 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) | 8957 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
8956 | return -EAGAIN; | 8958 | return -EAGAIN; |
8957 | return phy_ethtool_gset(tp->mdio_bus.phy_map[PHY_ADDR], cmd); | 8959 | return phy_ethtool_gset(tp->mdio_bus->phy_map[PHY_ADDR], cmd); |
8958 | } | 8960 | } |
8959 | 8961 | ||
8960 | cmd->supported = (SUPPORTED_Autoneg); | 8962 | cmd->supported = (SUPPORTED_Autoneg); |
@@ -8995,7 +8997,7 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |||
8995 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { | 8997 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
8996 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) | 8998 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
8997 | return -EAGAIN; | 8999 | return -EAGAIN; |
8998 | return phy_ethtool_sset(tp->mdio_bus.phy_map[PHY_ADDR], cmd); | 9000 | return phy_ethtool_sset(tp->mdio_bus->phy_map[PHY_ADDR], cmd); |
8999 | } | 9001 | } |
9000 | 9002 | ||
9001 | if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) { | 9003 | if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) { |
@@ -9143,7 +9145,7 @@ static int tg3_nway_reset(struct net_device *dev) | |||
9143 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { | 9145 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
9144 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) | 9146 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
9145 | return -EAGAIN; | 9147 | return -EAGAIN; |
9146 | r = phy_start_aneg(tp->mdio_bus.phy_map[PHY_ADDR]); | 9148 | r = phy_start_aneg(tp->mdio_bus->phy_map[PHY_ADDR]); |
9147 | } else { | 9149 | } else { |
9148 | u32 bmcr; | 9150 | u32 bmcr; |
9149 | 9151 | ||
@@ -9260,7 +9262,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam | |||
9260 | u32 newadv; | 9262 | u32 newadv; |
9261 | struct phy_device *phydev; | 9263 | struct phy_device *phydev; |
9262 | 9264 | ||
9263 | phydev = tp->mdio_bus.phy_map[PHY_ADDR]; | 9265 | phydev = tp->mdio_bus->phy_map[PHY_ADDR]; |
9264 | 9266 | ||
9265 | if (epause->rx_pause) { | 9267 | if (epause->rx_pause) { |
9266 | if (epause->tx_pause) | 9268 | if (epause->tx_pause) |
@@ -10242,7 +10244,7 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |||
10242 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { | 10244 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
10243 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) | 10245 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
10244 | return -EAGAIN; | 10246 | return -EAGAIN; |
10245 | return phy_mii_ioctl(tp->mdio_bus.phy_map[PHY_ADDR], data, cmd); | 10247 | return phy_mii_ioctl(tp->mdio_bus->phy_map[PHY_ADDR], data, cmd); |
10246 | } | 10248 | } |
10247 | 10249 | ||
10248 | switch(cmd) { | 10250 | switch(cmd) { |