brgphy.c revision 1.60 1 1.60 tsutsui /* $NetBSD: brgphy.c,v 1.60 2012/09/17 11:45:56 tsutsui Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 thorpej * NASA Ames Research Center.
10 1.1 thorpej *
11 1.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1 thorpej * modification, are permitted provided that the following conditions
13 1.1 thorpej * are met:
14 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1 thorpej *
20 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
31 1.1 thorpej */
32 1.1 thorpej
33 1.1 thorpej /*
34 1.1 thorpej * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
35 1.1 thorpej *
36 1.1 thorpej * Redistribution and use in source and binary forms, with or without
37 1.1 thorpej * modification, are permitted provided that the following conditions
38 1.1 thorpej * are met:
39 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
40 1.1 thorpej * notice, this list of conditions and the following disclaimer.
41 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
43 1.1 thorpej * documentation and/or other materials provided with the distribution.
44 1.1 thorpej *
45 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
46 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
49 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
52 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
54 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 1.1 thorpej */
56 1.1 thorpej
57 1.1 thorpej /*
58 1.57 jym * driver for the Broadcom BCM5400 and BCM5700 Gig-E PHYs.
59 1.1 thorpej *
60 1.1 thorpej * Programming information for this PHY was gleaned from FreeBSD
61 1.1 thorpej * (they were apparently able to get a datasheet from Broadcom).
62 1.1 thorpej */
63 1.5 lukem
64 1.5 lukem #include <sys/cdefs.h>
65 1.60 tsutsui __KERNEL_RCSID(0, "$NetBSD: brgphy.c,v 1.60 2012/09/17 11:45:56 tsutsui Exp $");
66 1.1 thorpej
67 1.1 thorpej #include <sys/param.h>
68 1.1 thorpej #include <sys/systm.h>
69 1.1 thorpej #include <sys/kernel.h>
70 1.1 thorpej #include <sys/device.h>
71 1.1 thorpej #include <sys/socket.h>
72 1.1 thorpej #include <sys/errno.h>
73 1.44 msaitoh #include <prop/proplib.h>
74 1.1 thorpej
75 1.1 thorpej #include <net/if.h>
76 1.1 thorpej #include <net/if_media.h>
77 1.1 thorpej
78 1.1 thorpej #include <dev/mii/mii.h>
79 1.1 thorpej #include <dev/mii/miivar.h>
80 1.1 thorpej #include <dev/mii/miidevs.h>
81 1.1 thorpej #include <dev/mii/brgphyreg.h>
82 1.1 thorpej
83 1.43 msaitoh #include <dev/pci/if_bgereg.h>
84 1.43 msaitoh #include <dev/pci/if_bnxreg.h>
85 1.43 msaitoh
86 1.39 xtraeme static int brgphymatch(device_t, cfdata_t, void *);
87 1.39 xtraeme static void brgphyattach(device_t, device_t, void *);
88 1.1 thorpej
89 1.44 msaitoh struct brgphy_softc {
90 1.44 msaitoh struct mii_softc sc_mii;
91 1.54 dyoung bool sc_isbge;
92 1.54 dyoung bool sc_isbnx;
93 1.58 jym uint32_t sc_chipid; /* parent's chipid */
94 1.58 jym uint32_t sc_phyflags; /* parent's phyflags */
95 1.44 msaitoh };
96 1.44 msaitoh
97 1.44 msaitoh CFATTACH_DECL3_NEW(brgphy, sizeof(struct brgphy_softc),
98 1.42 dyoung brgphymatch, brgphyattach, mii_phy_detach, mii_phy_activate, NULL, NULL,
99 1.42 dyoung DVF_DETACH_SHUTDOWN);
100 1.1 thorpej
101 1.21 thorpej static int brgphy_service(struct mii_softc *, struct mii_data *, int);
102 1.21 thorpej static void brgphy_status(struct mii_softc *);
103 1.32 msaitoh static int brgphy_mii_phy_auto(struct mii_softc *);
104 1.32 msaitoh static void brgphy_loop(struct mii_softc *);
105 1.43 msaitoh static void brgphy_reset(struct mii_softc *);
106 1.43 msaitoh static void brgphy_bcm5401_dspcode(struct mii_softc *);
107 1.43 msaitoh static void brgphy_bcm5411_dspcode(struct mii_softc *);
108 1.43 msaitoh static void brgphy_bcm5421_dspcode(struct mii_softc *);
109 1.43 msaitoh static void brgphy_bcm54k2_dspcode(struct mii_softc *);
110 1.43 msaitoh static void brgphy_adc_bug(struct mii_softc *);
111 1.43 msaitoh static void brgphy_5704_a0_bug(struct mii_softc *);
112 1.43 msaitoh static void brgphy_ber_bug(struct mii_softc *);
113 1.43 msaitoh static void brgphy_crc_bug(struct mii_softc *);
114 1.58 jym static void brgphy_disable_early_dac(struct mii_softc *);
115 1.52 msaitoh static void brgphy_jumbo_settings(struct mii_softc *);
116 1.52 msaitoh static void brgphy_eth_wirespeed(struct mii_softc *);
117 1.1 thorpej
118 1.10 thorpej
119 1.21 thorpej static const struct mii_phy_funcs brgphy_funcs = {
120 1.43 msaitoh brgphy_service, brgphy_status, brgphy_reset,
121 1.34 markd };
122 1.34 markd
123 1.21 thorpej static const struct mii_phydesc brgphys[] = {
124 1.1 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5400,
125 1.1 thorpej MII_STR_BROADCOM_BCM5400 },
126 1.2 thorpej
127 1.1 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5401,
128 1.1 thorpej MII_STR_BROADCOM_BCM5401 },
129 1.2 thorpej
130 1.1 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5411,
131 1.1 thorpej MII_STR_BROADCOM_BCM5411 },
132 1.9 thorpej
133 1.9 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5421,
134 1.9 thorpej MII_STR_BROADCOM_BCM5421 },
135 1.7 fvdl
136 1.53 kiyohara { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5462,
137 1.53 kiyohara MII_STR_BROADCOM_BCM5462 },
138 1.43 msaitoh
139 1.52 msaitoh { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5461,
140 1.52 msaitoh MII_STR_BROADCOM_BCM5461 },
141 1.49 simonb
142 1.53 kiyohara { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM54K2,
143 1.53 kiyohara MII_STR_BROADCOM_BCM54K2 },
144 1.43 msaitoh
145 1.52 msaitoh { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5464,
146 1.52 msaitoh MII_STR_BROADCOM_BCM5464 },
147 1.52 msaitoh
148 1.7 fvdl { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5701,
149 1.7 fvdl MII_STR_BROADCOM_BCM5701 },
150 1.14 matt
151 1.14 matt { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5703,
152 1.14 matt MII_STR_BROADCOM_BCM5703 },
153 1.1 thorpej
154 1.15 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5704,
155 1.15 jonathan MII_STR_BROADCOM_BCM5704 },
156 1.15 jonathan
157 1.25 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5705,
158 1.25 jonathan MII_STR_BROADCOM_BCM5705 },
159 1.25 jonathan
160 1.24 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5714,
161 1.24 jonathan MII_STR_BROADCOM_BCM5714 },
162 1.18 hannken
163 1.22 cube { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5750,
164 1.22 cube MII_STR_BROADCOM_BCM5750 },
165 1.22 cube
166 1.31 tsutsui { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5752,
167 1.31 tsutsui MII_STR_BROADCOM_BCM5752 },
168 1.31 tsutsui
169 1.27 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5780,
170 1.27 jonathan MII_STR_BROADCOM_BCM5780 },
171 1.27 jonathan
172 1.36 markd { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5708C,
173 1.36 markd MII_STR_BROADCOM_BCM5708C },
174 1.36 markd
175 1.55 pgoyette { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5481,
176 1.55 pgoyette MII_STR_BROADCOM2_BCM5481 },
177 1.55 pgoyette
178 1.53 kiyohara { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5482,
179 1.53 kiyohara MII_STR_BROADCOM2_BCM5482 },
180 1.53 kiyohara
181 1.51 bouyer { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5709C,
182 1.51 bouyer MII_STR_BROADCOM2_BCM5709C },
183 1.51 bouyer
184 1.57 jym { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5709S,
185 1.57 jym MII_STR_BROADCOM2_BCM5709S },
186 1.57 jym
187 1.51 bouyer { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5709CAX,
188 1.51 bouyer MII_STR_BROADCOM2_BCM5709CAX },
189 1.51 bouyer
190 1.43 msaitoh { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5722,
191 1.43 msaitoh MII_STR_BROADCOM2_BCM5722 },
192 1.43 msaitoh
193 1.53 kiyohara { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5754,
194 1.53 kiyohara MII_STR_BROADCOM2_BCM5754 },
195 1.53 kiyohara
196 1.34 markd { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5755,
197 1.34 markd MII_STR_BROADCOM2_BCM5755 },
198 1.34 markd
199 1.52 msaitoh { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5761,
200 1.52 msaitoh MII_STR_BROADCOM2_BCM5761 },
201 1.52 msaitoh
202 1.52 msaitoh { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5784,
203 1.52 msaitoh MII_STR_BROADCOM2_BCM5784 },
204 1.52 msaitoh
205 1.59 cegger { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5785,
206 1.59 cegger MII_STR_BROADCOM2_BCM5785 },
207 1.59 cegger
208 1.60 tsutsui { MII_OUI_BROADCOM3, MII_MODEL_BROADCOM3_BCM57765,
209 1.60 tsutsui MII_STR_BROADCOM3_BCM57765 },
210 1.60 tsutsui
211 1.40 cegger { MII_OUI_xxBROADCOM_ALT1, MII_MODEL_xxBROADCOM_ALT1_BCM5906,
212 1.40 cegger MII_STR_xxBROADCOM_ALT1_BCM5906 },
213 1.40 cegger
214 1.1 thorpej { 0, 0,
215 1.1 thorpej NULL },
216 1.1 thorpej };
217 1.1 thorpej
218 1.21 thorpej static int
219 1.48 tsutsui brgphymatch(device_t parent, cfdata_t match, void *aux)
220 1.1 thorpej {
221 1.1 thorpej struct mii_attach_args *ma = aux;
222 1.1 thorpej
223 1.2 thorpej if (mii_phy_match(ma, brgphys) != NULL)
224 1.1 thorpej return (10);
225 1.1 thorpej
226 1.1 thorpej return (0);
227 1.1 thorpej }
228 1.1 thorpej
229 1.21 thorpej static void
230 1.46 cegger brgphyattach(device_t parent, device_t self, void *aux)
231 1.1 thorpej {
232 1.44 msaitoh struct brgphy_softc *bsc = device_private(self);
233 1.44 msaitoh struct mii_softc *sc = &bsc->sc_mii;
234 1.1 thorpej struct mii_attach_args *ma = aux;
235 1.1 thorpej struct mii_data *mii = ma->mii_data;
236 1.2 thorpej const struct mii_phydesc *mpd;
237 1.44 msaitoh prop_dictionary_t dict;
238 1.1 thorpej
239 1.2 thorpej mpd = mii_phy_match(ma, brgphys);
240 1.17 thorpej aprint_naive(": Media interface\n");
241 1.17 thorpej aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
242 1.1 thorpej
243 1.39 xtraeme sc->mii_dev = self;
244 1.1 thorpej sc->mii_inst = mii->mii_instance;
245 1.1 thorpej sc->mii_phy = ma->mii_phyno;
246 1.32 msaitoh sc->mii_mpd_model = MII_MODEL(ma->mii_id2);
247 1.43 msaitoh sc->mii_mpd_rev = MII_REV(ma->mii_id2);
248 1.1 thorpej sc->mii_pdata = mii;
249 1.6 thorpej sc->mii_flags = ma->mii_flags;
250 1.30 christos sc->mii_anegticks = MII_ANEGTICKS;
251 1.43 msaitoh sc->mii_funcs = &brgphy_funcs;
252 1.10 thorpej
253 1.1 thorpej PHY_RESET(sc);
254 1.1 thorpej
255 1.1 thorpej sc->mii_capabilities =
256 1.1 thorpej PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
257 1.1 thorpej if (sc->mii_capabilities & BMSR_EXTSTAT)
258 1.1 thorpej sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
259 1.1 thorpej
260 1.44 msaitoh
261 1.58 jym if (device_is_a(parent, "bge"))
262 1.54 dyoung bsc->sc_isbge = true;
263 1.58 jym else if (device_is_a(parent, "bnx"))
264 1.54 dyoung bsc->sc_isbnx = true;
265 1.58 jym
266 1.58 jym if (bsc->sc_isbge || bsc->sc_isbnx) {
267 1.44 msaitoh dict = device_properties(parent);
268 1.57 jym if (!prop_dictionary_get_uint32(dict, "phyflags",
269 1.58 jym &bsc->sc_phyflags))
270 1.58 jym aprint_error_dev(self, "failed to get phyflags\n");
271 1.58 jym if (!prop_dictionary_get_uint32(dict, "chipid",
272 1.58 jym &bsc->sc_chipid))
273 1.58 jym aprint_error_dev(self, "failed to get chipid\n");
274 1.44 msaitoh }
275 1.57 jym
276 1.57 jym aprint_normal_dev(self, "");
277 1.57 jym if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0 &&
278 1.57 jym (sc->mii_extcapabilities & EXTSR_MEDIAMASK) == 0)
279 1.57 jym aprint_error("no media present");
280 1.57 jym else {
281 1.57 jym if (sc->mii_flags & MIIF_HAVEFIBER) {
282 1.57 jym sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
283 1.57 jym
284 1.57 jym /*
285 1.57 jym * Set the proper bits for capabilities so that the
286 1.57 jym * correct media get selected by mii_phy_add_media()
287 1.57 jym */
288 1.57 jym sc->mii_capabilities |= BMSR_ANEG;
289 1.57 jym sc->mii_capabilities &= ~BMSR_100T4;
290 1.57 jym sc->mii_extcapabilities |= EXTSR_1000XFDX;
291 1.57 jym
292 1.57 jym if (bsc->sc_isbnx) {
293 1.57 jym /*
294 1.57 jym * 2.5Gb support is a software enabled feature
295 1.57 jym * on the BCM5708S and BCM5709S controllers.
296 1.57 jym */
297 1.57 jym #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
298 1.58 jym if (bsc->sc_phyflags
299 1.57 jym & BNX_PHY_2_5G_CAPABLE_FLAG) {
300 1.57 jym ADD(IFM_MAKEWORD(IFM_ETHER, IFM_2500_SX,
301 1.57 jym IFM_FDX, sc->mii_inst), 0);
302 1.57 jym aprint_normal("2500baseSX-FDX, ");
303 1.57 jym #undef ADD
304 1.57 jym }
305 1.57 jym }
306 1.57 jym }
307 1.57 jym mii_phy_add_media(sc);
308 1.57 jym }
309 1.57 jym aprint_normal("\n");
310 1.57 jym
311 1.1 thorpej }
312 1.1 thorpej
313 1.21 thorpej static int
314 1.4 thorpej brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
315 1.1 thorpej {
316 1.1 thorpej struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
317 1.32 msaitoh int reg, speed, gig;
318 1.1 thorpej
319 1.1 thorpej switch (cmd) {
320 1.1 thorpej case MII_POLLSTAT:
321 1.1 thorpej /*
322 1.1 thorpej * If we're not polling our PHY instance, just return.
323 1.1 thorpej */
324 1.1 thorpej if (IFM_INST(ife->ifm_media) != sc->mii_inst)
325 1.1 thorpej return (0);
326 1.1 thorpej break;
327 1.1 thorpej
328 1.1 thorpej case MII_MEDIACHG:
329 1.1 thorpej /*
330 1.1 thorpej * If the media indicates a different PHY instance,
331 1.1 thorpej * isolate ourselves.
332 1.1 thorpej */
333 1.1 thorpej if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
334 1.1 thorpej reg = PHY_READ(sc, MII_BMCR);
335 1.1 thorpej PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
336 1.1 thorpej return (0);
337 1.1 thorpej }
338 1.1 thorpej
339 1.1 thorpej /*
340 1.1 thorpej * If the interface is not up, don't do anything.
341 1.1 thorpej */
342 1.1 thorpej if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
343 1.1 thorpej break;
344 1.1 thorpej
345 1.32 msaitoh PHY_RESET(sc); /* XXX hardware bug work-around */
346 1.32 msaitoh
347 1.32 msaitoh switch (IFM_SUBTYPE(ife->ifm_media)) {
348 1.32 msaitoh case IFM_AUTO:
349 1.32 msaitoh (void) brgphy_mii_phy_auto(sc);
350 1.32 msaitoh break;
351 1.32 msaitoh case IFM_1000_T:
352 1.32 msaitoh speed = BMCR_S1000;
353 1.32 msaitoh goto setit;
354 1.32 msaitoh case IFM_100_TX:
355 1.32 msaitoh speed = BMCR_S100;
356 1.32 msaitoh goto setit;
357 1.32 msaitoh case IFM_10_T:
358 1.32 msaitoh speed = BMCR_S10;
359 1.32 msaitoh setit:
360 1.32 msaitoh brgphy_loop(sc);
361 1.32 msaitoh if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
362 1.32 msaitoh speed |= BMCR_FDX;
363 1.32 msaitoh gig = GTCR_ADV_1000TFDX;
364 1.32 msaitoh } else {
365 1.32 msaitoh gig = GTCR_ADV_1000THDX;
366 1.32 msaitoh }
367 1.32 msaitoh
368 1.32 msaitoh PHY_WRITE(sc, MII_100T2CR, 0);
369 1.51 bouyer PHY_WRITE(sc, MII_ANAR, ANAR_CSMA);
370 1.32 msaitoh PHY_WRITE(sc, MII_BMCR, speed);
371 1.32 msaitoh
372 1.32 msaitoh if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
373 1.32 msaitoh break;
374 1.32 msaitoh
375 1.32 msaitoh PHY_WRITE(sc, MII_100T2CR, gig);
376 1.32 msaitoh PHY_WRITE(sc, MII_BMCR,
377 1.32 msaitoh speed|BMCR_AUTOEN|BMCR_STARTNEG);
378 1.32 msaitoh
379 1.32 msaitoh if (sc->mii_mpd_model != MII_MODEL_BROADCOM_BCM5701)
380 1.33 msaitoh break;
381 1.32 msaitoh
382 1.32 msaitoh if (mii->mii_media.ifm_media & IFM_ETH_MASTER)
383 1.32 msaitoh gig |= GTCR_MAN_MS | GTCR_ADV_MS;
384 1.32 msaitoh PHY_WRITE(sc, MII_100T2CR, gig);
385 1.32 msaitoh break;
386 1.32 msaitoh default:
387 1.32 msaitoh return (EINVAL);
388 1.32 msaitoh }
389 1.1 thorpej break;
390 1.1 thorpej
391 1.1 thorpej case MII_TICK:
392 1.1 thorpej /*
393 1.1 thorpej * If we're not currently selected, just return.
394 1.1 thorpej */
395 1.1 thorpej if (IFM_INST(ife->ifm_media) != sc->mii_inst)
396 1.1 thorpej return (0);
397 1.1 thorpej
398 1.1 thorpej if (mii_phy_tick(sc) == EJUSTRETURN)
399 1.1 thorpej return (0);
400 1.1 thorpej break;
401 1.1 thorpej
402 1.1 thorpej case MII_DOWN:
403 1.1 thorpej mii_phy_down(sc);
404 1.1 thorpej return (0);
405 1.1 thorpej }
406 1.1 thorpej
407 1.1 thorpej /* Update the media status. */
408 1.1 thorpej mii_phy_status(sc);
409 1.1 thorpej
410 1.10 thorpej /*
411 1.32 msaitoh * Callback if something changed. Note that we need to poke the DSP on
412 1.32 msaitoh * the Broadcom PHYs if the media changes.
413 1.10 thorpej */
414 1.23 perry if (sc->mii_media_active != mii->mii_media_active ||
415 1.10 thorpej sc->mii_media_status != mii->mii_media_status ||
416 1.10 thorpej cmd == MII_MEDIACHG) {
417 1.43 msaitoh switch (sc->mii_mpd_model) {
418 1.43 msaitoh case MII_MODEL_BROADCOM_BCM5400:
419 1.43 msaitoh brgphy_bcm5401_dspcode(sc);
420 1.43 msaitoh break;
421 1.43 msaitoh case MII_MODEL_BROADCOM_BCM5401:
422 1.43 msaitoh if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
423 1.43 msaitoh brgphy_bcm5401_dspcode(sc);
424 1.43 msaitoh break;
425 1.43 msaitoh case MII_MODEL_BROADCOM_BCM5411:
426 1.43 msaitoh brgphy_bcm5411_dspcode(sc);
427 1.43 msaitoh break;
428 1.43 msaitoh }
429 1.10 thorpej }
430 1.43 msaitoh
431 1.43 msaitoh /* Callback if something changed. */
432 1.43 msaitoh mii_phy_update(sc, cmd);
433 1.1 thorpej return (0);
434 1.1 thorpej }
435 1.1 thorpej
436 1.21 thorpej static void
437 1.4 thorpej brgphy_status(struct mii_softc *sc)
438 1.1 thorpej {
439 1.1 thorpej struct mii_data *mii = sc->mii_pdata;
440 1.1 thorpej struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
441 1.57 jym int bmcr, bmsr, auxsts, gtsr;
442 1.1 thorpej
443 1.1 thorpej mii->mii_media_status = IFM_AVALID;
444 1.1 thorpej mii->mii_media_active = IFM_ETHER;
445 1.1 thorpej
446 1.57 jym bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
447 1.57 jym if (bmsr & BMSR_LINK)
448 1.1 thorpej mii->mii_media_status |= IFM_ACTIVE;
449 1.1 thorpej
450 1.1 thorpej bmcr = PHY_READ(sc, MII_BMCR);
451 1.1 thorpej if (bmcr & BMCR_ISO) {
452 1.1 thorpej mii->mii_media_active |= IFM_NONE;
453 1.1 thorpej mii->mii_media_status = 0;
454 1.1 thorpej return;
455 1.1 thorpej }
456 1.1 thorpej
457 1.1 thorpej if (bmcr & BMCR_LOOP)
458 1.1 thorpej mii->mii_media_active |= IFM_LOOP;
459 1.1 thorpej
460 1.1 thorpej if (bmcr & BMCR_AUTOEN) {
461 1.1 thorpej /*
462 1.1 thorpej * The media status bits are only valid of autonegotiation
463 1.1 thorpej * has completed (or it's disabled).
464 1.1 thorpej */
465 1.57 jym if ((bmsr & BMSR_ACOMP) == 0) {
466 1.1 thorpej /* Erg, still trying, I guess... */
467 1.1 thorpej mii->mii_media_active |= IFM_NONE;
468 1.1 thorpej return;
469 1.1 thorpej }
470 1.1 thorpej
471 1.57 jym if (sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5709S) {
472 1.57 jym
473 1.57 jym /* 5709S has its own general purpose status registers */
474 1.57 jym
475 1.57 jym PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
476 1.57 jym BRGPHY_BLOCK_ADDR_GP_STATUS);
477 1.57 jym
478 1.57 jym auxsts = PHY_READ(sc, BRGPHY_GP_STATUS_TOP_ANEG_STATUS);
479 1.57 jym
480 1.57 jym PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
481 1.57 jym BRGPHY_BLOCK_ADDR_COMBO_IEEE0);
482 1.57 jym
483 1.57 jym switch (auxsts & BRGPHY_GP_STATUS_TOP_ANEG_SPEED_MASK) {
484 1.57 jym case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_10:
485 1.57 jym mii->mii_media_active |= IFM_10_FL;
486 1.57 jym break;
487 1.57 jym case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_100:
488 1.57 jym mii->mii_media_active |= IFM_100_FX;
489 1.57 jym break;
490 1.57 jym case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_1G:
491 1.57 jym mii->mii_media_active |= IFM_1000_SX;
492 1.57 jym break;
493 1.57 jym case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_25G:
494 1.57 jym mii->mii_media_active |= IFM_2500_SX;
495 1.57 jym break;
496 1.57 jym default:
497 1.57 jym mii->mii_media_active |= IFM_NONE;
498 1.57 jym mii->mii_media_status = 0;
499 1.57 jym break;
500 1.57 jym }
501 1.57 jym
502 1.57 jym if (auxsts & BRGPHY_GP_STATUS_TOP_ANEG_FDX)
503 1.57 jym mii->mii_media_active |= IFM_FDX;
504 1.57 jym else
505 1.57 jym mii->mii_media_active |= IFM_HDX;
506 1.57 jym
507 1.57 jym } else {
508 1.57 jym auxsts = PHY_READ(sc, BRGPHY_MII_AUXSTS);
509 1.57 jym
510 1.57 jym switch (auxsts & BRGPHY_AUXSTS_AN_RES) {
511 1.57 jym case BRGPHY_RES_1000FD:
512 1.57 jym mii->mii_media_active |= IFM_1000_T|IFM_FDX;
513 1.57 jym gtsr = PHY_READ(sc, MII_100T2SR);
514 1.57 jym if (gtsr & GTSR_MS_RES)
515 1.57 jym mii->mii_media_active |= IFM_ETH_MASTER;
516 1.57 jym break;
517 1.1 thorpej
518 1.57 jym case BRGPHY_RES_1000HD:
519 1.57 jym mii->mii_media_active |= IFM_1000_T;
520 1.57 jym gtsr = PHY_READ(sc, MII_100T2SR);
521 1.57 jym if (gtsr & GTSR_MS_RES)
522 1.57 jym mii->mii_media_active |= IFM_ETH_MASTER;
523 1.57 jym break;
524 1.1 thorpej
525 1.57 jym case BRGPHY_RES_100FD:
526 1.57 jym mii->mii_media_active |= IFM_100_TX|IFM_FDX;
527 1.57 jym break;
528 1.1 thorpej
529 1.57 jym case BRGPHY_RES_100T4:
530 1.57 jym mii->mii_media_active |= IFM_100_T4;
531 1.57 jym break;
532 1.1 thorpej
533 1.57 jym case BRGPHY_RES_100HD:
534 1.57 jym mii->mii_media_active |= IFM_100_TX;
535 1.57 jym break;
536 1.1 thorpej
537 1.57 jym case BRGPHY_RES_10FD:
538 1.57 jym mii->mii_media_active |= IFM_10_T|IFM_FDX;
539 1.57 jym break;
540 1.1 thorpej
541 1.57 jym case BRGPHY_RES_10HD:
542 1.57 jym mii->mii_media_active |= IFM_10_T;
543 1.57 jym break;
544 1.1 thorpej
545 1.57 jym default:
546 1.57 jym mii->mii_media_active |= IFM_NONE;
547 1.57 jym mii->mii_media_status = 0;
548 1.57 jym }
549 1.1 thorpej }
550 1.57 jym
551 1.19 thorpej if (mii->mii_media_active & IFM_FDX)
552 1.20 thorpej mii->mii_media_active |= mii_phy_flowstatus(sc);
553 1.57 jym
554 1.1 thorpej } else
555 1.1 thorpej mii->mii_media_active = ife->ifm_media;
556 1.10 thorpej }
557 1.10 thorpej
558 1.32 msaitoh int
559 1.32 msaitoh brgphy_mii_phy_auto(struct mii_softc *sc)
560 1.32 msaitoh {
561 1.32 msaitoh int anar, ktcr = 0;
562 1.32 msaitoh
563 1.32 msaitoh brgphy_loop(sc);
564 1.32 msaitoh PHY_RESET(sc);
565 1.57 jym
566 1.32 msaitoh ktcr = GTCR_ADV_1000TFDX|GTCR_ADV_1000THDX;
567 1.32 msaitoh if (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5701)
568 1.32 msaitoh ktcr |= GTCR_MAN_MS|GTCR_ADV_MS;
569 1.32 msaitoh PHY_WRITE(sc, MII_100T2CR, ktcr);
570 1.32 msaitoh ktcr = PHY_READ(sc, MII_100T2CR);
571 1.32 msaitoh DELAY(1000);
572 1.32 msaitoh
573 1.57 jym if (sc->mii_flags & MIIF_HAVEFIBER) {
574 1.57 jym anar = ANAR_X_FD | ANAR_X_HD;
575 1.57 jym if (sc->mii_flags & MIIF_DOPAUSE)
576 1.57 jym anar |= BRGPHY_SERDES_ANAR_BOTH_PAUSE;
577 1.57 jym } else {
578 1.57 jym anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
579 1.57 jym if (sc->mii_flags & MIIF_DOPAUSE)
580 1.57 jym anar |= ANAR_FC | ANAR_X_PAUSE_ASYM;
581 1.57 jym }
582 1.32 msaitoh PHY_WRITE(sc, MII_ANAR, anar);
583 1.32 msaitoh DELAY(1000);
584 1.57 jym
585 1.57 jym /* Start autonegotiation */
586 1.32 msaitoh PHY_WRITE(sc, MII_BMCR,
587 1.32 msaitoh BMCR_AUTOEN | BMCR_STARTNEG);
588 1.32 msaitoh PHY_WRITE(sc, BRGPHY_MII_IMR, 0xFF00);
589 1.32 msaitoh
590 1.32 msaitoh return (EJUSTRETURN);
591 1.32 msaitoh }
592 1.32 msaitoh
593 1.32 msaitoh void
594 1.32 msaitoh brgphy_loop(struct mii_softc *sc)
595 1.32 msaitoh {
596 1.32 msaitoh u_int32_t bmsr;
597 1.32 msaitoh int i;
598 1.32 msaitoh
599 1.32 msaitoh PHY_WRITE(sc, MII_BMCR, BMCR_LOOP);
600 1.33 msaitoh for (i = 0; i < 15000; i++) {
601 1.32 msaitoh bmsr = PHY_READ(sc, MII_BMSR);
602 1.32 msaitoh if (!(bmsr & BMSR_LINK))
603 1.32 msaitoh break;
604 1.32 msaitoh DELAY(10);
605 1.32 msaitoh }
606 1.32 msaitoh }
607 1.32 msaitoh
608 1.21 thorpej static void
609 1.43 msaitoh brgphy_reset(struct mii_softc *sc)
610 1.10 thorpej {
611 1.56 jym struct brgphy_softc *bsc = device_private(sc->mii_dev);
612 1.10 thorpej
613 1.10 thorpej mii_phy_reset(sc);
614 1.10 thorpej
615 1.43 msaitoh switch (sc->mii_mpd_model) {
616 1.43 msaitoh case MII_MODEL_BROADCOM_BCM5400:
617 1.43 msaitoh brgphy_bcm5401_dspcode(sc);
618 1.43 msaitoh break;
619 1.43 msaitoh case MII_MODEL_BROADCOM_BCM5401:
620 1.43 msaitoh if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
621 1.43 msaitoh brgphy_bcm5401_dspcode(sc);
622 1.43 msaitoh break;
623 1.43 msaitoh case MII_MODEL_BROADCOM_BCM5411:
624 1.43 msaitoh brgphy_bcm5411_dspcode(sc);
625 1.43 msaitoh break;
626 1.43 msaitoh case MII_MODEL_BROADCOM_BCM5421:
627 1.43 msaitoh brgphy_bcm5421_dspcode(sc);
628 1.43 msaitoh break;
629 1.43 msaitoh case MII_MODEL_BROADCOM_BCM54K2:
630 1.43 msaitoh brgphy_bcm54k2_dspcode(sc);
631 1.43 msaitoh break;
632 1.43 msaitoh }
633 1.15 jonathan
634 1.43 msaitoh /* Handle any bge (NetXtreme/NetLink) workarounds. */
635 1.54 dyoung if (bsc->sc_isbge) {
636 1.43 msaitoh if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
637 1.43 msaitoh
638 1.58 jym if (bsc->sc_phyflags & BGE_PHY_ADC_BUG)
639 1.43 msaitoh brgphy_adc_bug(sc);
640 1.58 jym if (bsc->sc_phyflags & BGE_PHY_5704_A0_BUG)
641 1.43 msaitoh brgphy_5704_a0_bug(sc);
642 1.58 jym if (bsc->sc_phyflags & BGE_PHY_BER_BUG)
643 1.43 msaitoh brgphy_ber_bug(sc);
644 1.58 jym else if (bsc->sc_phyflags & BGE_PHY_JITTER_BUG) {
645 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0c00);
646 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG,
647 1.43 msaitoh 0x000a);
648 1.43 msaitoh
649 1.58 jym if (bsc->sc_phyflags
650 1.58 jym & BGE_PHY_ADJUST_TRIM) {
651 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
652 1.43 msaitoh 0x110b);
653 1.43 msaitoh PHY_WRITE(sc, BRGPHY_TEST1,
654 1.43 msaitoh BRGPHY_TEST1_TRIM_EN | 0x4);
655 1.43 msaitoh } else {
656 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
657 1.43 msaitoh 0x010b);
658 1.43 msaitoh }
659 1.15 jonathan
660 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0400);
661 1.43 msaitoh }
662 1.58 jym if (bsc->sc_phyflags & BGE_PHY_CRC_BUG)
663 1.43 msaitoh brgphy_crc_bug(sc);
664 1.15 jonathan
665 1.43 msaitoh /* Set Jumbo frame settings in the PHY. */
666 1.58 jym if (bsc->sc_phyflags & BGE_JUMBO_CAPABLE)
667 1.43 msaitoh brgphy_jumbo_settings(sc);
668 1.43 msaitoh
669 1.43 msaitoh /* Adjust output voltage */
670 1.43 msaitoh if (sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5906)
671 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_EPHY_PTEST, 0x12);
672 1.43 msaitoh
673 1.43 msaitoh /* Enable Ethernet@Wirespeed */
674 1.58 jym if (!(bsc->sc_phyflags & BGE_NO_ETH_WIRE_SPEED))
675 1.43 msaitoh brgphy_eth_wirespeed(sc);
676 1.43 msaitoh
677 1.52 msaitoh #if 0
678 1.43 msaitoh /* Enable Link LED on Dell boxes */
679 1.58 jym if (bsc->sc_phyflags & BGE_NO_3LED) {
680 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL,
681 1.43 msaitoh PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL)
682 1.43 msaitoh & ~BRGPHY_PHY_EXTCTL_3_LED);
683 1.43 msaitoh }
684 1.43 msaitoh #endif
685 1.43 msaitoh }
686 1.57 jym /* Handle any bnx (NetXtreme II) workarounds. */
687 1.57 jym } else if (bsc->sc_isbnx) {
688 1.43 msaitoh #if 0 /* not yet */
689 1.43 msaitoh if (sc->mii_mpd_model == MII_MODEL_xxBROADCOM2_BCM5708S) {
690 1.43 msaitoh /* Store autoneg capabilities/results in digital block (Page 0) */
691 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG3_PG2);
692 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_PG2_DIGCTL_3_0,
693 1.43 msaitoh BRGPHY_5708S_PG2_DIGCTL_3_0_USE_IEEE);
694 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG_PG0);
695 1.43 msaitoh
696 1.43 msaitoh /* Enable fiber mode and autodetection */
697 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL1,
698 1.43 msaitoh PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL1) |
699 1.43 msaitoh BRGPHY_5708S_PG0_1000X_CTL1_AUTODET_EN |
700 1.43 msaitoh BRGPHY_5708S_PG0_1000X_CTL1_FIBER_MODE);
701 1.43 msaitoh
702 1.43 msaitoh /* Enable parallel detection */
703 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL2,
704 1.43 msaitoh PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL2) |
705 1.43 msaitoh BRGPHY_5708S_PG0_1000X_CTL2_PAR_DET_EN);
706 1.43 msaitoh
707 1.43 msaitoh /* Advertise 2.5G support through next page during autoneg */
708 1.43 msaitoh if (bnx_sc->bnx_phy_flags & BNX_PHY_2_5G_CAPABLE_FLAG)
709 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1,
710 1.43 msaitoh PHY_READ(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1) |
711 1.43 msaitoh BRGPHY_5708S_ANEG_NXT_PG_XMIT1_25G);
712 1.43 msaitoh
713 1.43 msaitoh /* Increase TX signal amplitude */
714 1.43 msaitoh if ((BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_A0) ||
715 1.43 msaitoh (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B0) ||
716 1.43 msaitoh (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B1)) {
717 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
718 1.43 msaitoh BRGPHY_5708S_TX_MISC_PG5);
719 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL1,
720 1.43 msaitoh PHY_READ(sc, BRGPHY_5708S_PG5_TXACTL1) &
721 1.43 msaitoh ~BRGPHY_5708S_PG5_TXACTL1_VCM);
722 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
723 1.43 msaitoh BRGPHY_5708S_DIG_PG0);
724 1.43 msaitoh }
725 1.15 jonathan
726 1.43 msaitoh /* Backplanes use special driver/pre-driver/pre-emphasis values. */
727 1.43 msaitoh if ((bnx_sc->bnx_shared_hw_cfg & BNX_SHARED_HW_CFG_PHY_BACKPLANE) &&
728 1.43 msaitoh (bnx_sc->bnx_port_hw_cfg & BNX_PORT_HW_CFG_CFG_TXCTL3_MASK)) {
729 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
730 1.43 msaitoh BRGPHY_5708S_TX_MISC_PG5);
731 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL3,
732 1.43 msaitoh bnx_sc->bnx_port_hw_cfg &
733 1.43 msaitoh BNX_PORT_HW_CFG_CFG_TXCTL3_MASK);
734 1.43 msaitoh PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
735 1.43 msaitoh BRGPHY_5708S_DIG_PG0);
736 1.43 msaitoh }
737 1.57 jym } else
738 1.57 jym #endif
739 1.57 jym if (sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5709S) {
740 1.57 jym /* Select the SerDes Digital block of the AN MMD. */
741 1.57 jym PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
742 1.57 jym BRGPHY_BLOCK_ADDR_SERDES_DIG);
743 1.57 jym
744 1.57 jym PHY_WRITE(sc, BRGPHY_SERDES_DIG_1000X_CTL1,
745 1.57 jym (PHY_READ(sc, BRGPHY_SERDES_DIG_1000X_CTL1) &
746 1.57 jym ~BRGPHY_SD_DIG_1000X_CTL1_AUTODET) |
747 1.57 jym BRGPHY_SD_DIG_1000X_CTL1_FIBER);
748 1.57 jym
749 1.58 jym if (bsc->sc_phyflags & BNX_PHY_2_5G_CAPABLE_FLAG) {
750 1.57 jym /* Select the Over 1G block of the AN MMD. */
751 1.57 jym PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
752 1.57 jym BRGPHY_BLOCK_ADDR_OVER_1G);
753 1.57 jym
754 1.57 jym /*
755 1.57 jym * Enable autoneg "Next Page" to advertise
756 1.57 jym * 2.5G support.
757 1.57 jym */
758 1.57 jym PHY_WRITE(sc, BRGPHY_OVER_1G_UNFORMAT_PG1,
759 1.57 jym PHY_READ(sc, BRGPHY_OVER_1G_UNFORMAT_PG1) |
760 1.57 jym BRGPHY_5708S_ANEG_NXT_PG_XMIT1_25G);
761 1.57 jym }
762 1.57 jym
763 1.57 jym /*
764 1.57 jym * Select the Multi-Rate Backplane Ethernet block of
765 1.57 jym * the AN MMD.
766 1.57 jym */
767 1.57 jym PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
768 1.57 jym BRGPHY_BLOCK_ADDR_MRBE);
769 1.57 jym
770 1.57 jym /* Enable MRBE speed autoneg. */
771 1.57 jym PHY_WRITE(sc, BRGPHY_MRBE_MSG_PG5_NP,
772 1.57 jym PHY_READ(sc, BRGPHY_MRBE_MSG_PG5_NP) |
773 1.57 jym BRGPHY_MRBE_MSG_PG5_NP_MBRE |
774 1.57 jym BRGPHY_MRBE_MSG_PG5_NP_T2);
775 1.57 jym
776 1.57 jym /* Select the Clause 73 User B0 block of the AN MMD. */
777 1.57 jym PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
778 1.57 jym BRGPHY_BLOCK_ADDR_CL73_USER_B0);
779 1.57 jym
780 1.57 jym /* Enable MRBE speed autoneg. */
781 1.57 jym PHY_WRITE(sc, BRGPHY_CL73_USER_B0_MBRE_CTL1,
782 1.57 jym BRGPHY_CL73_USER_B0_MBRE_CTL1_NP_AFT_BP |
783 1.57 jym BRGPHY_CL73_USER_B0_MBRE_CTL1_STA_MGR |
784 1.57 jym BRGPHY_CL73_USER_B0_MBRE_CTL1_ANEG);
785 1.57 jym
786 1.57 jym PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
787 1.57 jym BRGPHY_BLOCK_ADDR_COMBO_IEEE0);
788 1.57 jym
789 1.58 jym } else if (_BNX_CHIP_NUM(bsc->sc_chipid) == BNX_CHIP_NUM_5709) {
790 1.58 jym if (_BNX_CHIP_REV(bsc->sc_chipid) == BNX_CHIP_REV_Ax ||
791 1.58 jym _BNX_CHIP_REV(bsc->sc_chipid) == BNX_CHIP_REV_Bx)
792 1.58 jym brgphy_disable_early_dac(sc);
793 1.58 jym
794 1.58 jym /* Set Jumbo frame settings in the PHY. */
795 1.58 jym brgphy_jumbo_settings(sc);
796 1.58 jym
797 1.58 jym /* Enable Ethernet@Wirespeed */
798 1.58 jym brgphy_eth_wirespeed(sc);
799 1.43 msaitoh } else {
800 1.43 msaitoh if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
801 1.43 msaitoh brgphy_ber_bug(sc);
802 1.18 hannken
803 1.43 msaitoh /* Set Jumbo frame settings in the PHY. */
804 1.43 msaitoh brgphy_jumbo_settings(sc);
805 1.18 hannken
806 1.43 msaitoh /* Enable Ethernet@Wirespeed */
807 1.43 msaitoh brgphy_eth_wirespeed(sc);
808 1.43 msaitoh }
809 1.43 msaitoh }
810 1.43 msaitoh }
811 1.34 markd }
812 1.34 markd
813 1.16 jonathan /* Turn off tap power management on 5401. */
814 1.10 thorpej static void
815 1.43 msaitoh brgphy_bcm5401_dspcode(struct mii_softc *sc)
816 1.10 thorpej {
817 1.10 thorpej static const struct {
818 1.10 thorpej int reg;
819 1.10 thorpej uint16_t val;
820 1.10 thorpej } dspcode[] = {
821 1.16 jonathan { BRGPHY_MII_AUXCTL, 0x0c20 },
822 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x0012 },
823 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x1804 },
824 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x0013 },
825 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x1204 },
826 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x8006 },
827 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x0132 },
828 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x8006 },
829 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x0232 },
830 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x201f },
831 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x0a20 },
832 1.10 thorpej { 0, 0 },
833 1.10 thorpej };
834 1.10 thorpej int i;
835 1.10 thorpej
836 1.10 thorpej for (i = 0; dspcode[i].reg != 0; i++)
837 1.10 thorpej PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
838 1.16 jonathan delay(40);
839 1.10 thorpej }
840 1.10 thorpej
841 1.10 thorpej static void
842 1.43 msaitoh brgphy_bcm5411_dspcode(struct mii_softc *sc)
843 1.10 thorpej {
844 1.10 thorpej static const struct {
845 1.10 thorpej int reg;
846 1.10 thorpej uint16_t val;
847 1.10 thorpej } dspcode[] = {
848 1.10 thorpej { 0x1c, 0x8c23 },
849 1.10 thorpej { 0x1c, 0x8ca3 },
850 1.10 thorpej { 0x1c, 0x8c23 },
851 1.15 jonathan { 0, 0 },
852 1.15 jonathan };
853 1.15 jonathan int i;
854 1.15 jonathan
855 1.15 jonathan for (i = 0; dspcode[i].reg != 0; i++)
856 1.15 jonathan PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
857 1.15 jonathan }
858 1.15 jonathan
859 1.43 msaitoh void
860 1.43 msaitoh brgphy_bcm5421_dspcode(struct mii_softc *sc)
861 1.43 msaitoh {
862 1.43 msaitoh uint16_t data;
863 1.43 msaitoh
864 1.43 msaitoh /* Set Class A mode */
865 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x1007);
866 1.43 msaitoh data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
867 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0400);
868 1.43 msaitoh
869 1.43 msaitoh /* Set FFE gamma override to -0.125 */
870 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0007);
871 1.43 msaitoh data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
872 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0800);
873 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG, 0x000a);
874 1.43 msaitoh data = PHY_READ(sc, BRGPHY_MII_DSP_RW_PORT);
875 1.43 msaitoh PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT, data | 0x0200);
876 1.43 msaitoh }
877 1.43 msaitoh
878 1.43 msaitoh void
879 1.43 msaitoh brgphy_bcm54k2_dspcode(struct mii_softc *sc)
880 1.43 msaitoh {
881 1.43 msaitoh static const struct {
882 1.43 msaitoh int reg;
883 1.43 msaitoh uint16_t val;
884 1.43 msaitoh } dspcode[] = {
885 1.43 msaitoh { 4, 0x01e1 },
886 1.43 msaitoh { 9, 0x0300 },
887 1.43 msaitoh { 0, 0 },
888 1.43 msaitoh };
889 1.43 msaitoh int i;
890 1.43 msaitoh
891 1.43 msaitoh for (i = 0; dspcode[i].reg != 0; i++)
892 1.43 msaitoh PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
893 1.43 msaitoh }
894 1.43 msaitoh
895 1.15 jonathan static void
896 1.43 msaitoh brgphy_adc_bug(struct mii_softc *sc)
897 1.15 jonathan {
898 1.15 jonathan static const struct {
899 1.15 jonathan int reg;
900 1.15 jonathan uint16_t val;
901 1.15 jonathan } dspcode[] = {
902 1.15 jonathan { BRGPHY_MII_AUXCTL, 0x0c00 },
903 1.15 jonathan { BRGPHY_MII_DSP_ADDR_REG, 0x201f },
904 1.15 jonathan { BRGPHY_MII_DSP_RW_PORT, 0x2aaa },
905 1.43 msaitoh { BRGPHY_MII_DSP_ADDR_REG, 0x000a },
906 1.43 msaitoh { BRGPHY_MII_DSP_RW_PORT, 0x0323 },
907 1.43 msaitoh { BRGPHY_MII_AUXCTL, 0x0400 },
908 1.15 jonathan { 0, 0 },
909 1.15 jonathan };
910 1.15 jonathan int i;
911 1.15 jonathan
912 1.15 jonathan for (i = 0; dspcode[i].reg != 0; i++)
913 1.15 jonathan PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
914 1.15 jonathan }
915 1.15 jonathan
916 1.15 jonathan static void
917 1.43 msaitoh brgphy_5704_a0_bug(struct mii_softc *sc)
918 1.15 jonathan {
919 1.15 jonathan static const struct {
920 1.15 jonathan int reg;
921 1.15 jonathan uint16_t val;
922 1.15 jonathan } dspcode[] = {
923 1.15 jonathan { 0x1c, 0x8d68 },
924 1.33 msaitoh { 0x1c, 0x8d68 },
925 1.10 thorpej { 0, 0 },
926 1.10 thorpej };
927 1.10 thorpej int i;
928 1.10 thorpej
929 1.10 thorpej for (i = 0; dspcode[i].reg != 0; i++)
930 1.10 thorpej PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
931 1.1 thorpej }
932 1.22 cube
933 1.22 cube static void
934 1.43 msaitoh brgphy_ber_bug(struct mii_softc *sc)
935 1.22 cube {
936 1.22 cube static const struct {
937 1.22 cube int reg;
938 1.22 cube uint16_t val;
939 1.22 cube } dspcode[] = {
940 1.22 cube { BRGPHY_MII_AUXCTL, 0x0c00 },
941 1.22 cube { BRGPHY_MII_DSP_ADDR_REG, 0x000a },
942 1.22 cube { BRGPHY_MII_DSP_RW_PORT, 0x310b },
943 1.22 cube { BRGPHY_MII_DSP_ADDR_REG, 0x201f },
944 1.22 cube { BRGPHY_MII_DSP_RW_PORT, 0x9506 },
945 1.22 cube { BRGPHY_MII_DSP_ADDR_REG, 0x401f },
946 1.22 cube { BRGPHY_MII_DSP_RW_PORT, 0x14e2 },
947 1.22 cube { BRGPHY_MII_AUXCTL, 0x0400 },
948 1.22 cube { 0, 0 },
949 1.22 cube };
950 1.22 cube int i;
951 1.22 cube
952 1.22 cube for (i = 0; dspcode[i].reg != 0; i++)
953 1.22 cube PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
954 1.22 cube }
955 1.34 markd
956 1.43 msaitoh /* BCM5701 A0/B0 CRC bug workaround */
957 1.43 msaitoh void
958 1.43 msaitoh brgphy_crc_bug(struct mii_softc *sc)
959 1.34 markd {
960 1.34 markd static const struct {
961 1.34 markd int reg;
962 1.34 markd uint16_t val;
963 1.34 markd } dspcode[] = {
964 1.43 msaitoh { BRGPHY_MII_DSP_ADDR_REG, 0x0a75 },
965 1.43 msaitoh { 0x1c, 0x8c68 },
966 1.43 msaitoh { 0x1c, 0x8d68 },
967 1.43 msaitoh { 0x1c, 0x8c68 },
968 1.34 markd { 0, 0 },
969 1.34 markd };
970 1.34 markd int i;
971 1.34 markd
972 1.34 markd for (i = 0; dspcode[i].reg != 0; i++)
973 1.34 markd PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
974 1.34 markd }
975 1.52 msaitoh
976 1.52 msaitoh static void
977 1.58 jym brgphy_disable_early_dac(struct mii_softc *sc)
978 1.58 jym {
979 1.58 jym uint32_t val;
980 1.58 jym
981 1.58 jym PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG, 0x0f08);
982 1.58 jym val = PHY_READ(sc, BRGPHY_MII_DSP_RW_PORT);
983 1.58 jym val &= ~(1 << 8);
984 1.58 jym PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT, val);
985 1.58 jym
986 1.58 jym }
987 1.58 jym
988 1.58 jym static void
989 1.52 msaitoh brgphy_jumbo_settings(struct mii_softc *sc)
990 1.52 msaitoh {
991 1.52 msaitoh u_int32_t val;
992 1.52 msaitoh
993 1.52 msaitoh /* Set Jumbo frame settings in the PHY. */
994 1.52 msaitoh if (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5401) {
995 1.52 msaitoh /* Cannot do read-modify-write on the BCM5401 */
996 1.52 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x4c20);
997 1.52 msaitoh } else {
998 1.52 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x7);
999 1.52 msaitoh val = PHY_READ(sc, BRGPHY_MII_AUXCTL);
1000 1.52 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL,
1001 1.52 msaitoh val & ~(BRGPHY_AUXCTL_LONG_PKT | 0x7));
1002 1.52 msaitoh }
1003 1.52 msaitoh
1004 1.52 msaitoh val = PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL);
1005 1.52 msaitoh PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL,
1006 1.52 msaitoh val & ~BRGPHY_PHY_EXTCTL_HIGH_LA);
1007 1.52 msaitoh }
1008 1.52 msaitoh
1009 1.52 msaitoh static void
1010 1.52 msaitoh brgphy_eth_wirespeed(struct mii_softc *sc)
1011 1.52 msaitoh {
1012 1.52 msaitoh u_int32_t val;
1013 1.52 msaitoh
1014 1.52 msaitoh /* Enable Ethernet@Wirespeed */
1015 1.52 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x7007);
1016 1.52 msaitoh val = PHY_READ(sc, BRGPHY_MII_AUXCTL);
1017 1.52 msaitoh PHY_WRITE(sc, BRGPHY_MII_AUXCTL,
1018 1.52 msaitoh (val | (1 << 15) | (1 << 4)));
1019 1.52 msaitoh }
1020