3529f8c901b539f69120cbc361009f2852ae45ee
[openwrt.git] / target / linux / brcm47xx / patches-3.10 / 790-tg3-phylib.patch
1 --- a/drivers/net/ethernet/broadcom/tg3.c
2 +++ b/drivers/net/ethernet/broadcom/tg3.c
3 @@ -1367,7 +1367,7 @@ static int tg3_mdio_read(struct mii_bus
4  
5         spin_lock_bh(&tp->lock);
6  
7 -       if (tg3_readphy(tp, reg, &val))
8 +       if (__tg3_readphy(tp, mii_id, reg, &val))
9                 val = -EIO;
10  
11         spin_unlock_bh(&tp->lock);
12 @@ -1382,7 +1382,7 @@ static int tg3_mdio_write(struct mii_bus
13  
14         spin_lock_bh(&tp->lock);
15  
16 -       if (tg3_writephy(tp, reg, val))
17 +       if (__tg3_writephy(tp, mii_id, reg, val))
18                 ret = -EIO;
19  
20         spin_unlock_bh(&tp->lock);
21 @@ -1400,7 +1400,7 @@ static void tg3_mdio_config_5785(struct
22         u32 val;
23         struct phy_device *phydev;
24  
25 -       phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
26 +       phydev = tp->mdio_bus->phy_map[tp->phy_addr];
27         switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) {
28         case PHY_ID_BCM50610:
29         case PHY_ID_BCM50610M:
30 @@ -1505,6 +1505,13 @@ static int tg3_mdio_init(struct tg3 *tp)
31                                     TG3_CPMU_PHY_STRAP_IS_SERDES;
32                 if (is_serdes)
33                         tp->phy_addr += 7;
34 +       } else if (tg3_flag(tp, IS_SSB_CORE) && tg3_flag(tp, ROBOSWITCH)) {
35 +               int addr;
36 +
37 +               addr = ssb_gige_get_phyaddr(tp->pdev);
38 +               if (addr < 0)
39 +                       return addr;
40 +               tp->phy_addr = addr;
41         } else
42                 tp->phy_addr = TG3_PHY_MII_ADDR;
43  
44 @@ -1525,7 +1532,7 @@ static int tg3_mdio_init(struct tg3 *tp)
45         tp->mdio_bus->read     = &tg3_mdio_read;
46         tp->mdio_bus->write    = &tg3_mdio_write;
47         tp->mdio_bus->reset    = &tg3_mdio_reset;
48 -       tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR);
49 +       tp->mdio_bus->phy_mask = ~(1 << tp->phy_addr);
50         tp->mdio_bus->irq      = &tp->mdio_irq[0];
51  
52         for (i = 0; i < PHY_MAX_ADDR; i++)
53 @@ -1546,7 +1553,7 @@ static int tg3_mdio_init(struct tg3 *tp)
54                 return i;
55         }
56  
57 -       phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
58 +       phydev = tp->mdio_bus->phy_map[tp->phy_addr];
59  
60         if (!phydev || !phydev->drv) {
61                 dev_warn(&tp->pdev->dev, "No PHY devices\n");
62 @@ -1963,7 +1970,7 @@ static void tg3_setup_flow_control(struc
63         u32 old_tx_mode = tp->tx_mode;
64  
65         if (tg3_flag(tp, USE_PHYLIB))
66 -               autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg;
67 +               autoneg = tp->mdio_bus->phy_map[tp->phy_addr]->autoneg;
68         else
69                 autoneg = tp->link_config.autoneg;
70  
71 @@ -1999,7 +2006,7 @@ static void tg3_adjust_link(struct net_d
72         u8 oldflowctrl, linkmesg = 0;
73         u32 mac_mode, lcl_adv, rmt_adv;
74         struct tg3 *tp = netdev_priv(dev);
75 -       struct phy_device *phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
76 +       struct phy_device *phydev = tp->mdio_bus->phy_map[tp->phy_addr];
77  
78         spin_lock_bh(&tp->lock);
79  
80 @@ -2088,7 +2095,7 @@ static int tg3_phy_init(struct tg3 *tp)
81         /* Bring the PHY back to a known state. */
82         tg3_bmcr_reset(tp);
83  
84 -       phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
85 +       phydev = tp->mdio_bus->phy_map[tp->phy_addr];
86  
87         /* Attach the MAC to the PHY. */
88         phydev = phy_connect(tp->dev, dev_name(&phydev->dev),
89 @@ -2115,7 +2122,7 @@ static int tg3_phy_init(struct tg3 *tp)
90                                       SUPPORTED_Asym_Pause);
91                 break;
92         default:
93 -               phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
94 +               phy_disconnect(tp->mdio_bus->phy_map[tp->phy_addr]);
95                 return -EINVAL;
96         }
97  
98 @@ -2133,7 +2140,7 @@ static void tg3_phy_start(struct tg3 *tp
99         if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
100                 return;
101  
102 -       phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
103 +       phydev = tp->mdio_bus->phy_map[tp->phy_addr];
104  
105         if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) {
106                 tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER;
107 @@ -2153,13 +2160,13 @@ static void tg3_phy_stop(struct tg3 *tp)
108         if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
109                 return;
110  
111 -       phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
112 +       phy_stop(tp->mdio_bus->phy_map[tp->phy_addr]);
113  }
114  
115  static void tg3_phy_fini(struct tg3 *tp)
116  {
117         if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) {
118 -               phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
119 +               phy_disconnect(tp->mdio_bus->phy_map[tp->phy_addr]);
120                 tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED;
121         }
122  }
123 @@ -3999,7 +4006,7 @@ static int tg3_power_down_prepare(struct
124                         struct phy_device *phydev;
125                         u32 phyid, advertising;
126  
127 -                       phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
128 +                       phydev = tp->mdio_bus->phy_map[tp->phy_addr];
129  
130                         tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER;
131  
132 @@ -11783,7 +11790,7 @@ static int tg3_get_settings(struct net_d
133                 struct phy_device *phydev;
134                 if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
135                         return -EAGAIN;
136 -               phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
137 +               phydev = tp->mdio_bus->phy_map[tp->phy_addr];
138                 return phy_ethtool_gset(phydev, cmd);
139         }
140  
141 @@ -11850,7 +11857,7 @@ static int tg3_set_settings(struct net_d
142                 struct phy_device *phydev;
143                 if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
144                         return -EAGAIN;
145 -               phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
146 +               phydev = tp->mdio_bus->phy_map[tp->phy_addr];
147                 return phy_ethtool_sset(phydev, cmd);
148         }
149  
150 @@ -12007,7 +12014,7 @@ static int tg3_nway_reset(struct net_dev
151         if (tg3_flag(tp, USE_PHYLIB)) {
152                 if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
153                         return -EAGAIN;
154 -               r = phy_start_aneg(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]);
155 +               r = phy_start_aneg(tp->mdio_bus->phy_map[tp->phy_addr]);
156         } else {
157                 u32 bmcr;
158  
159 @@ -12123,7 +12130,7 @@ static int tg3_set_pauseparam(struct net
160                 u32 newadv;
161                 struct phy_device *phydev;
162  
163 -               phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
164 +               phydev = tp->mdio_bus->phy_map[tp->phy_addr];
165  
166                 if (!(phydev->supported & SUPPORTED_Pause) ||
167                     (!(phydev->supported & SUPPORTED_Asym_Pause) &&
168 @@ -13557,7 +13564,7 @@ static int tg3_ioctl(struct net_device *
169                 struct phy_device *phydev;
170                 if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED))
171                         return -EAGAIN;
172 -               phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
173 +               phydev = tp->mdio_bus->phy_map[tp->phy_addr];
174                 return phy_mii_ioctl(phydev, ifr, cmd);
175         }
176  
177 @@ -17190,8 +17197,10 @@ static int tg3_init_one(struct pci_dev *
178                         tg3_flag_set(tp, FLUSH_POSTED_WRITES);
179                 if (ssb_gige_one_dma_at_once(pdev))
180                         tg3_flag_set(tp, ONE_DMA_AT_ONCE);
181 -               if (ssb_gige_have_roboswitch(pdev))
182 +               if (ssb_gige_have_roboswitch(pdev)) {
183 +                       tg3_flag_set(tp, USE_PHYLIB);
184                         tg3_flag_set(tp, ROBOSWITCH);
185 +               }
186                 if (ssb_gige_is_rgmii(pdev))
187                         tg3_flag_set(tp, RGMII_MODE);
188         }
189 @@ -17461,7 +17470,7 @@ static int tg3_init_one(struct pci_dev *
190  
191         if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) {
192                 struct phy_device *phydev;
193 -               phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR];
194 +               phydev = tp->mdio_bus->phy_map[tp->phy_addr];
195                 netdev_info(dev,
196                             "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n",
197                             phydev->drv->name, dev_name(&phydev->dev));
198 --- a/include/linux/ssb/ssb_driver_gige.h
199 +++ b/include/linux/ssb/ssb_driver_gige.h
200 @@ -108,6 +108,16 @@ static inline int ssb_gige_get_macaddr(s
201         return 0;
202  }
203  
204 +/* Get the device phy address */
205 +static inline int ssb_gige_get_phyaddr(struct pci_dev *pdev)
206 +{
207 +       struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
208 +       if (!dev)
209 +               return -ENODEV;
210 +
211 +       return dev->dev->bus->sprom.et0phyaddr;
212 +}
213 +
214  extern int ssb_gige_pcibios_plat_dev_init(struct ssb_device *sdev,
215                                           struct pci_dev *pdev);
216  extern int ssb_gige_map_irq(struct ssb_device *sdev,
217 @@ -174,6 +184,10 @@ static inline int ssb_gige_get_macaddr(s
218  {
219         return -ENODEV;
220  }
221 +static inline int ssb_gige_get_phyaddr(struct pci_dev *pdev)
222 +{
223 +       return -ENODEV;
224 +}
225  
226  #endif /* CONFIG_SSB_DRIVER_GIGE */
227  #endif /* LINUX_SSB_DRIVER_GIGE_H_ */