1 /*
2 	drivers/net/tulip/media.c
3 
4 	Maintained by Jeff Garzik <jgarzik@pobox.com>
5 	Copyright 2000,2001  The Linux Kernel Team
6 	Written/copyright 1994-2001 by Donald Becker.
7 
8 	This software may be used and distributed according to the terms
9 	of the GNU General Public License, incorporated herein by reference.
10 
11 	Please refer to Documentation/DocBook/tulip.{pdf,ps,html}
12 	for more information on this driver, or visit the project
13 	Web page at http://sourceforge.net/projects/tulip/
14 
15 */
16 
17 #include <linux/kernel.h>
18 #include <linux/mii.h>
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/pci.h>
22 #include "tulip.h"
23 
24 
25 /* This is a mysterious value that can be written to CSR11 in the 21040 (only)
26    to support a pre-NWay full-duplex signaling mechanism using short frames.
27    No one knows what it should be, but if left at its default value some
28    10base2(!) packets trigger a full-duplex-request interrupt. */
29 #define FULL_DUPLEX_MAGIC	0x6969
30 
31 /* The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
32    met by back-to-back PCI I/O cycles, but we insert a delay to avoid
33    "overclocking" issues or future 66Mhz PCI. */
34 #define mdio_delay() inl(mdio_addr)
35 
36 /* Read and write the MII registers using software-generated serial
37    MDIO protocol.  It is just different enough from the EEPROM protocol
38    to not share code.  The maxium data clock rate is 2.5 Mhz. */
39 #define MDIO_SHIFT_CLK		0x10000
40 #define MDIO_DATA_WRITE0	0x00000
41 #define MDIO_DATA_WRITE1	0x20000
42 #define MDIO_ENB		0x00000 /* Ignore the 0x02000 databook setting. */
43 #define MDIO_ENB_IN		0x40000
44 #define MDIO_DATA_READ		0x80000
45 
46 static const unsigned char comet_miireg2offset[32] = {
47 	0xB4, 0xB8, 0xBC, 0xC0,  0xC4, 0xC8, 0xCC, 0,  0,0,0,0,  0,0,0,0,
48 	0,0xD0,0,0,  0,0,0,0,  0,0,0,0, 0, 0xD4, 0xD8, 0xDC, };
49 
50 
51 /* MII transceiver control section.
52    Read and write the MII registers using software-generated serial
53    MDIO protocol.  See the MII specifications or DP83840A data sheet
54    for details. */
55 
tulip_mdio_read(struct net_device * dev,int phy_id,int location)56 int tulip_mdio_read(struct net_device *dev, int phy_id, int location)
57 {
58 	struct tulip_private *tp = (struct tulip_private *)dev->priv;
59 	int i;
60 	int read_cmd = (0xf6 << 10) | ((phy_id & 0x1f) << 5) | location;
61 	int retval = 0;
62 	long ioaddr = dev->base_addr;
63 	long mdio_addr = ioaddr + CSR9;
64 	unsigned long flags;
65 
66 	if (location & ~0x1f)
67 		return 0xffff;
68 
69 	if (tp->chip_id == COMET  &&  phy_id == 30) {
70 		if (comet_miireg2offset[location])
71 			return inl(ioaddr + comet_miireg2offset[location]);
72 		return 0xffff;
73 	}
74 
75 	spin_lock_irqsave(&tp->mii_lock, flags);
76 	if (tp->chip_id == LC82C168) {
77 		int i = 1000;
78 		outl(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0);
79 		inl(ioaddr + 0xA0);
80 		inl(ioaddr + 0xA0);
81 		while (--i > 0) {
82 			barrier();
83 			if ( ! ((retval = inl(ioaddr + 0xA0)) & 0x80000000))
84 				break;
85 		}
86 		spin_unlock_irqrestore(&tp->mii_lock, flags);
87 		return retval & 0xffff;
88 	}
89 
90 	/* Establish sync by sending at least 32 logic ones. */
91 	for (i = 32; i >= 0; i--) {
92 		outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
93 		mdio_delay();
94 		outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
95 		mdio_delay();
96 	}
97 	/* Shift the read command bits out. */
98 	for (i = 15; i >= 0; i--) {
99 		int dataval = (read_cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
100 
101 		outl(MDIO_ENB | dataval, mdio_addr);
102 		mdio_delay();
103 		outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
104 		mdio_delay();
105 	}
106 	/* Read the two transition, 16 data, and wire-idle bits. */
107 	for (i = 19; i > 0; i--) {
108 		outl(MDIO_ENB_IN, mdio_addr);
109 		mdio_delay();
110 		retval = (retval << 1) | ((inl(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
111 		outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
112 		mdio_delay();
113 	}
114 
115 	spin_unlock_irqrestore(&tp->mii_lock, flags);
116 	return (retval>>1) & 0xffff;
117 }
118 
tulip_mdio_write(struct net_device * dev,int phy_id,int location,int val)119 void tulip_mdio_write(struct net_device *dev, int phy_id, int location, int val)
120 {
121 	struct tulip_private *tp = (struct tulip_private *)dev->priv;
122 	int i;
123 	int cmd = (0x5002 << 16) | ((phy_id & 0x1f) << 23) | (location<<18) | (val & 0xffff);
124 	long ioaddr = dev->base_addr;
125 	long mdio_addr = ioaddr + CSR9;
126 	unsigned long flags;
127 
128 	if (location & ~0x1f)
129 		return;
130 
131 	if (tp->chip_id == COMET && phy_id == 30) {
132 		if (comet_miireg2offset[location])
133 			outl(val, ioaddr + comet_miireg2offset[location]);
134 		return;
135 	}
136 
137 	spin_lock_irqsave(&tp->mii_lock, flags);
138 	if (tp->chip_id == LC82C168) {
139 		int i = 1000;
140 		outl(cmd, ioaddr + 0xA0);
141 		do {
142 			barrier();
143 			if ( ! (inl(ioaddr + 0xA0) & 0x80000000))
144 				break;
145 		} while (--i > 0);
146 		spin_unlock_irqrestore(&tp->mii_lock, flags);
147 		return;
148 	}
149 
150 	/* Establish sync by sending 32 logic ones. */
151 	for (i = 32; i >= 0; i--) {
152 		outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
153 		mdio_delay();
154 		outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
155 		mdio_delay();
156 	}
157 	/* Shift the command bits out. */
158 	for (i = 31; i >= 0; i--) {
159 		int dataval = (cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
160 		outl(MDIO_ENB | dataval, mdio_addr);
161 		mdio_delay();
162 		outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
163 		mdio_delay();
164 	}
165 	/* Clear out extra bits. */
166 	for (i = 2; i > 0; i--) {
167 		outl(MDIO_ENB_IN, mdio_addr);
168 		mdio_delay();
169 		outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
170 		mdio_delay();
171 	}
172 
173 	spin_unlock_irqrestore(&tp->mii_lock, flags);
174 }
175 
176 
177 /* Set up the transceiver control registers for the selected media type. */
tulip_select_media(struct net_device * dev,int startup)178 void tulip_select_media(struct net_device *dev, int startup)
179 {
180 	long ioaddr = dev->base_addr;
181 	struct tulip_private *tp = (struct tulip_private *)dev->priv;
182 	struct mediatable *mtable = tp->mtable;
183 	u32 new_csr6;
184 	int i;
185 
186 	if (mtable) {
187 		struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index];
188 		unsigned char *p = mleaf->leafdata;
189 		switch (mleaf->type) {
190 		case 0:					/* 21140 non-MII xcvr. */
191 			if (tulip_debug > 1)
192 				printk(KERN_DEBUG "%s: Using a 21140 non-MII transceiver"
193 					   " with control setting %2.2x.\n",
194 					   dev->name, p[1]);
195 			dev->if_port = p[0];
196 			if (startup)
197 				outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
198 			outl(p[1], ioaddr + CSR12);
199 			new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);
200 			break;
201 		case 2: case 4: {
202 			u16 setup[5];
203 			u32 csr13val, csr14val, csr15dir, csr15val;
204 			for (i = 0; i < 5; i++)
205 				setup[i] = get_u16(&p[i*2 + 1]);
206 
207 			dev->if_port = p[0] & MEDIA_MASK;
208 			if (tulip_media_cap[dev->if_port] & MediaAlwaysFD)
209 				tp->full_duplex = 1;
210 
211 			if (startup && mtable->has_reset) {
212 				struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset];
213 				unsigned char *rst = rleaf->leafdata;
214 				if (tulip_debug > 1)
215 					printk(KERN_DEBUG "%s: Resetting the transceiver.\n",
216 						   dev->name);
217 				for (i = 0; i < rst[0]; i++)
218 					outl(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15);
219 			}
220 			if (tulip_debug > 1)
221 				printk(KERN_DEBUG "%s: 21143 non-MII %s transceiver control "
222 					   "%4.4x/%4.4x.\n",
223 					   dev->name, medianame[dev->if_port], setup[0], setup[1]);
224 			if (p[0] & 0x40) {	/* SIA (CSR13-15) setup values are provided. */
225 				csr13val = setup[0];
226 				csr14val = setup[1];
227 				csr15dir = (setup[3]<<16) | setup[2];
228 				csr15val = (setup[4]<<16) | setup[2];
229 				outl(0, ioaddr + CSR13);
230 				outl(csr14val, ioaddr + CSR14);
231 				outl(csr15dir, ioaddr + CSR15);	/* Direction */
232 				outl(csr15val, ioaddr + CSR15);	/* Data */
233 				outl(csr13val, ioaddr + CSR13);
234 			} else {
235 				csr13val = 1;
236 				csr14val = 0;
237 				csr15dir = (setup[0]<<16) | 0x0008;
238 				csr15val = (setup[1]<<16) | 0x0008;
239 				if (dev->if_port <= 4)
240 					csr14val = t21142_csr14[dev->if_port];
241 				if (startup) {
242 					outl(0, ioaddr + CSR13);
243 					outl(csr14val, ioaddr + CSR14);
244 				}
245 				outl(csr15dir, ioaddr + CSR15);	/* Direction */
246 				outl(csr15val, ioaddr + CSR15);	/* Data */
247 				if (startup) outl(csr13val, ioaddr + CSR13);
248 			}
249 			if (tulip_debug > 1)
250 				printk(KERN_DEBUG "%s:  Setting CSR15 to %8.8x/%8.8x.\n",
251 					   dev->name, csr15dir, csr15val);
252 			if (mleaf->type == 4)
253 				new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18);
254 			else
255 				new_csr6 = 0x82420000;
256 			break;
257 		}
258 		case 1: case 3: {
259 			int phy_num = p[0];
260 			int init_length = p[1];
261 			u16 *misc_info, tmp_info;
262 
263 			dev->if_port = 11;
264 			new_csr6 = 0x020E0000;
265 			if (mleaf->type == 3) {	/* 21142 */
266 				u16 *init_sequence = (u16*)(p+2);
267 				u16 *reset_sequence = &((u16*)(p+3))[init_length];
268 				int reset_length = p[2 + init_length*2];
269 				misc_info = reset_sequence + reset_length;
270 				if (startup)
271 					for (i = 0; i < reset_length; i++)
272 						outl(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);
273 				for (i = 0; i < init_length; i++)
274 					outl(get_u16(&init_sequence[i]) << 16, ioaddr + CSR15);
275 			} else {
276 				u8 *init_sequence = p + 2;
277 				u8 *reset_sequence = p + 3 + init_length;
278 				int reset_length = p[2 + init_length];
279 				misc_info = (u16*)(reset_sequence + reset_length);
280 				if (startup) {
281 					outl(mtable->csr12dir | 0x100, ioaddr + CSR12);
282 					for (i = 0; i < reset_length; i++)
283 						outl(reset_sequence[i], ioaddr + CSR12);
284 				}
285 				for (i = 0; i < init_length; i++)
286 					outl(init_sequence[i], ioaddr + CSR12);
287 			}
288 			tmp_info = get_u16(&misc_info[1]);
289 			if (tmp_info)
290 				tp->advertising[phy_num] = tmp_info | 1;
291 			if (tmp_info && startup < 2) {
292 				if (tp->mii_advertise == 0)
293 					tp->mii_advertise = tp->advertising[phy_num];
294 				if (tulip_debug > 1)
295 					printk(KERN_DEBUG "%s:  Advertising %4.4x on MII %d.\n",
296 					       dev->name, tp->mii_advertise, tp->phys[phy_num]);
297 				tulip_mdio_write(dev, tp->phys[phy_num], 4, tp->mii_advertise);
298 			}
299 			break;
300 		}
301 		case 5: case 6: {
302 			u16 setup[5];
303 
304 			new_csr6 = 0; /* FIXME */
305 
306 			for (i = 0; i < 5; i++)
307 				setup[i] = get_u16(&p[i*2 + 1]);
308 
309 			if (startup && mtable->has_reset) {
310 				struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset];
311 				unsigned char *rst = rleaf->leafdata;
312 				if (tulip_debug > 1)
313 					printk(KERN_DEBUG "%s: Resetting the transceiver.\n",
314 						   dev->name);
315 				for (i = 0; i < rst[0]; i++)
316 					outl(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15);
317 			}
318 
319 			break;
320 		}
321 		default:
322 			printk(KERN_DEBUG "%s:  Invalid media table selection %d.\n",
323 					   dev->name, mleaf->type);
324 			new_csr6 = 0x020E0000;
325 		}
326 		if (tulip_debug > 1)
327 			printk(KERN_DEBUG "%s: Using media type %s, CSR12 is %2.2x.\n",
328 				   dev->name, medianame[dev->if_port],
329 				   inl(ioaddr + CSR12) & 0xff);
330 	} else if (tp->chip_id == DC21041) {
331 		int port = dev->if_port <= 4 ? dev->if_port : 0;
332 		if (tulip_debug > 1)
333 			printk(KERN_DEBUG "%s: 21041 using media %s, CSR12 is %4.4x.\n",
334 				   dev->name, medianame[port == 3 ? 12: port],
335 				   inl(ioaddr + CSR12));
336 		outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
337 		outl(t21041_csr14[port], ioaddr + CSR14);
338 		outl(t21041_csr15[port], ioaddr + CSR15);
339 		outl(t21041_csr13[port], ioaddr + CSR13);
340 		new_csr6 = 0x80020000;
341 	} else if (tp->chip_id == LC82C168) {
342 		if (startup && ! tp->medialock)
343 			dev->if_port = tp->mii_cnt ? 11 : 0;
344 		if (tulip_debug > 1)
345 			printk(KERN_DEBUG "%s: PNIC PHY status is %3.3x, media %s.\n",
346 				   dev->name, inl(ioaddr + 0xB8), medianame[dev->if_port]);
347 		if (tp->mii_cnt) {
348 			new_csr6 = 0x810C0000;
349 			outl(0x0001, ioaddr + CSR15);
350 			outl(0x0201B07A, ioaddr + 0xB8);
351 		} else if (startup) {
352 			/* Start with 10mbps to do autonegotiation. */
353 			outl(0x32, ioaddr + CSR12);
354 			new_csr6 = 0x00420000;
355 			outl(0x0001B078, ioaddr + 0xB8);
356 			outl(0x0201B078, ioaddr + 0xB8);
357 		} else if (dev->if_port == 3  ||  dev->if_port == 5) {
358 			outl(0x33, ioaddr + CSR12);
359 			new_csr6 = 0x01860000;
360 			/* Trigger autonegotiation. */
361 			outl(startup ? 0x0201F868 : 0x0001F868, ioaddr + 0xB8);
362 		} else {
363 			outl(0x32, ioaddr + CSR12);
364 			new_csr6 = 0x00420000;
365 			outl(0x1F078, ioaddr + 0xB8);
366 		}
367 	} else if (tp->chip_id == DC21040) {					/* 21040 */
368 		/* Turn on the xcvr interface. */
369 		int csr12 = inl(ioaddr + CSR12);
370 		if (tulip_debug > 1)
371 			printk(KERN_DEBUG "%s: 21040 media type is %s, CSR12 is %2.2x.\n",
372 				   dev->name, medianame[dev->if_port], csr12);
373 		if (tulip_media_cap[dev->if_port] & MediaAlwaysFD)
374 			tp->full_duplex = 1;
375 		new_csr6 = 0x20000;
376 		/* Set the full duplux match frame. */
377 		outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11);
378 		outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */
379 		if (t21040_csr13[dev->if_port] & 8) {
380 			outl(0x0705, ioaddr + CSR14);
381 			outl(0x0006, ioaddr + CSR15);
382 		} else {
383 			outl(0xffff, ioaddr + CSR14);
384 			outl(0x0000, ioaddr + CSR15);
385 		}
386 		outl(0x8f01 | t21040_csr13[dev->if_port], ioaddr + CSR13);
387 	} else {					/* Unknown chip type with no media table. */
388 		if (tp->default_port == 0)
389 			dev->if_port = tp->mii_cnt ? 11 : 3;
390 		if (tulip_media_cap[dev->if_port] & MediaIsMII) {
391 			new_csr6 = 0x020E0000;
392 		} else if (tulip_media_cap[dev->if_port] & MediaIsFx) {
393 			new_csr6 = 0x02860000;
394 		} else
395 			new_csr6 = 0x03860000;
396 		if (tulip_debug > 1)
397 			printk(KERN_DEBUG "%s: No media description table, assuming "
398 				   "%s transceiver, CSR12 %2.2x.\n",
399 				   dev->name, medianame[dev->if_port],
400 				   inl(ioaddr + CSR12));
401 	}
402 
403 	tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);
404 	return;
405 }
406 
407 /*
408   Check the MII negotiated duplex and change the CSR6 setting if
409   required.
410   Return 0 if everything is OK.
411   Return < 0 if the transceiver is missing or has no link beat.
412   */
tulip_check_duplex(struct net_device * dev)413 int tulip_check_duplex(struct net_device *dev)
414 {
415 	struct tulip_private *tp = dev->priv;
416 	unsigned int bmsr, lpa, negotiated, new_csr6;
417 
418 	bmsr = tulip_mdio_read(dev, tp->phys[0], MII_BMSR);
419 	lpa = tulip_mdio_read(dev, tp->phys[0], MII_LPA);
420 	if (tulip_debug > 1)
421 		printk(KERN_INFO "%s: MII status %4.4x, Link partner report "
422 			   "%4.4x.\n", dev->name, bmsr, lpa);
423 	if (bmsr == 0xffff)
424 		return -2;
425 	if ((bmsr & BMSR_LSTATUS) == 0) {
426 		int new_bmsr = tulip_mdio_read(dev, tp->phys[0], MII_BMSR);
427 		if ((new_bmsr & BMSR_LSTATUS) == 0) {
428 			if (tulip_debug  > 1)
429 				printk(KERN_INFO "%s: No link beat on the MII interface,"
430 					   " status %4.4x.\n", dev->name, new_bmsr);
431 			return -1;
432 		}
433 	}
434 	negotiated = lpa & tp->advertising[0];
435 	tp->full_duplex = mii_duplex(tp->full_duplex_lock, negotiated);
436 
437 	new_csr6 = tp->csr6;
438 
439 	if (negotiated & LPA_100) new_csr6 &= ~TxThreshold;
440 	else			  new_csr6 |= TxThreshold;
441 	if (tp->full_duplex) new_csr6 |= FullDuplex;
442 	else		     new_csr6 &= ~FullDuplex;
443 
444 	if (new_csr6 != tp->csr6) {
445 		tp->csr6 = new_csr6;
446 		tulip_restart_rxtx(tp);
447 
448 		if (tulip_debug > 0)
449 			printk(KERN_INFO "%s: Setting %s-duplex based on MII"
450 				   "#%d link partner capability of %4.4x.\n",
451 				   dev->name, tp->full_duplex ? "full" : "half",
452 				   tp->phys[0], lpa);
453 		return 1;
454 	}
455 
456 	return 0;
457 }
458 
tulip_find_mii(struct net_device * dev,int board_idx)459 void __devinit tulip_find_mii (struct net_device *dev, int board_idx)
460 {
461 	struct tulip_private *tp = dev->priv;
462 	int phyn, phy_idx = 0;
463 	int mii_reg0;
464 	int mii_advert;
465 	unsigned int to_advert, new_bmcr, ane_switch;
466 
467 	/* Find the connected MII xcvrs.
468 	   Doing this in open() would allow detecting external xcvrs later,
469 	   but takes much time. */
470 	for (phyn = 1; phyn <= 32 && phy_idx < sizeof (tp->phys); phyn++) {
471 		int phy = phyn & 0x1f;
472 		int mii_status = tulip_mdio_read (dev, phy, MII_BMSR);
473 		if ((mii_status & 0x8301) == 0x8001 ||
474 		    ((mii_status & BMSR_100BASE4) == 0
475 		     && (mii_status & 0x7800) != 0)) {
476 			/* preserve Becker logic, gain indentation level */
477 		} else {
478 			continue;
479 		}
480 
481 		mii_reg0 = tulip_mdio_read (dev, phy, MII_BMCR);
482 		mii_advert = tulip_mdio_read (dev, phy, MII_ADVERTISE);
483 		ane_switch = 0;
484 
485 		/* if not advertising at all, gen an
486 		 * advertising value from the capability
487 		 * bits in BMSR
488 		 */
489 		if ((mii_advert & ADVERTISE_ALL) == 0) {
490 			unsigned int tmpadv = tulip_mdio_read (dev, phy, MII_BMSR);
491 			mii_advert = ((tmpadv >> 6) & 0x3e0) | 1;
492 		}
493 
494 		if (tp->mii_advertise) {
495 			tp->advertising[phy_idx] =
496 			to_advert = tp->mii_advertise;
497 		} else if (tp->advertising[phy_idx]) {
498 			to_advert = tp->advertising[phy_idx];
499 		} else {
500 			tp->advertising[phy_idx] =
501 			tp->mii_advertise =
502 			to_advert = mii_advert;
503 		}
504 
505 		tp->phys[phy_idx++] = phy;
506 
507 		printk (KERN_INFO "tulip%d:  MII transceiver #%d "
508 			"config %4.4x status %4.4x advertising %4.4x.\n",
509 			board_idx, phy, mii_reg0, mii_status, mii_advert);
510 
511 		/* Fixup for DLink with miswired PHY. */
512 		if (mii_advert != to_advert) {
513 			printk (KERN_DEBUG "tulip%d:  Advertising %4.4x on PHY %d,"
514 				" previously advertising %4.4x.\n",
515 				board_idx, to_advert, phy, mii_advert);
516 			tulip_mdio_write (dev, phy, 4, to_advert);
517 		}
518 
519 		/* Enable autonegotiation: some boards default to off. */
520 		if (tp->default_port == 0) {
521 			new_bmcr = mii_reg0 | BMCR_ANENABLE;
522 			if (new_bmcr != mii_reg0) {
523 				new_bmcr |= BMCR_ANRESTART;
524 				ane_switch = 1;
525 			}
526 		}
527 		/* ...or disable nway, if forcing media */
528 		else {
529 			new_bmcr = mii_reg0 & ~BMCR_ANENABLE;
530 			if (new_bmcr != mii_reg0)
531 				ane_switch = 1;
532 		}
533 
534 		/* clear out bits we never want at this point */
535 		new_bmcr &= ~(BMCR_CTST | BMCR_FULLDPLX | BMCR_ISOLATE |
536 			      BMCR_PDOWN | BMCR_SPEED100 | BMCR_LOOPBACK |
537 			      BMCR_RESET);
538 
539 		if (tp->full_duplex)
540 			new_bmcr |= BMCR_FULLDPLX;
541 		if (tulip_media_cap[tp->default_port] & MediaIs100)
542 			new_bmcr |= BMCR_SPEED100;
543 
544 		if (new_bmcr != mii_reg0) {
545 			/* some phys need the ANE switch to
546 			 * happen before forced media settings
547 			 * will "take."  However, we write the
548 			 * same value twice in order not to
549 			 * confuse the sane phys.
550 			 */
551 			if (ane_switch) {
552 				tulip_mdio_write (dev, phy, MII_BMCR, new_bmcr);
553 				udelay (10);
554 			}
555 			tulip_mdio_write (dev, phy, MII_BMCR, new_bmcr);
556 		}
557 	}
558 	tp->mii_cnt = phy_idx;
559 	if (tp->mtable && tp->mtable->has_mii && phy_idx == 0) {
560 		printk (KERN_INFO "tulip%d: ***WARNING***: No MII transceiver found!\n",
561 			board_idx);
562 		tp->phys[0] = 1;
563 	}
564 }
565