• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/net/tulip/
1/*
2	drivers/net/tulip/21142.c
3
4	Copyright 2000,2001  The Linux Kernel Team
5	Written/copyright 1994-2001 by Donald Becker.
6
7	This software may be used and distributed according to the terms
8	of the GNU General Public License, incorporated herein by reference.
9
10	Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html}
11	for more information on this driver.
12
13	DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller
14	Hardware Reference Manual" is currently available at :
15	http://developer.intel.com/design/network/manuals/278074.htm
16
17	Please submit bugs to http://bugzilla.kernel.org/ .
18*/
19
20#include <linux/delay.h>
21#include "tulip.h"
22
23
24static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
25u16 t21142_csr14[] =	    { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
26static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
27
28
29/* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
30   of available transceivers.  */
31void t21142_media_task(struct work_struct *work)
32{
33	struct tulip_private *tp =
34		container_of(work, struct tulip_private, media_work);
35	struct net_device *dev = tp->dev;
36	void __iomem *ioaddr = tp->base_addr;
37	int csr12 = ioread32(ioaddr + CSR12);
38	int next_tick = 60*HZ;
39	int new_csr6 = 0;
40	int csr14 = ioread32(ioaddr + CSR14);
41
42	/* CSR12[LS10,LS100] are not reliable during autonegotiation */
43	if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
44		csr12 |= 6;
45	if (tulip_debug > 2)
46		dev_info(&dev->dev, "21143 negotiation status %08x, %s\n",
47			 csr12, medianame[dev->if_port]);
48	if (tulip_media_cap[dev->if_port] & MediaIsMII) {
49		if (tulip_check_duplex(dev) < 0) {
50			netif_carrier_off(dev);
51			next_tick = 3*HZ;
52		} else {
53			netif_carrier_on(dev);
54			next_tick = 60*HZ;
55		}
56	} else if (tp->nwayset) {
57		/* Don't screw up a negotiated session! */
58		if (tulip_debug > 1)
59			dev_info(&dev->dev,
60				 "Using NWay-set %s media, csr12 %08x\n",
61				 medianame[dev->if_port], csr12);
62	} else if (tp->medialock) {
63			;
64	} else if (dev->if_port == 3) {
65		if (csr12 & 2) {	/* No 100mbps link beat, revert to 10mbps. */
66			if (tulip_debug > 1)
67				dev_info(&dev->dev,
68					 "No 21143 100baseTx link beat, %08x, trying NWay\n",
69					 csr12);
70			t21142_start_nway(dev);
71			next_tick = 3*HZ;
72		}
73	} else if ((csr12 & 0x7000) != 0x5000) {
74		/* Negotiation failed.  Search media types. */
75		if (tulip_debug > 1)
76			dev_info(&dev->dev,
77				 "21143 negotiation failed, status %08x\n",
78				 csr12);
79		if (!(csr12 & 4)) {		/* 10mbps link beat good. */
80			new_csr6 = 0x82420000;
81			dev->if_port = 0;
82			iowrite32(0, ioaddr + CSR13);
83			iowrite32(0x0003FFFF, ioaddr + CSR14);
84			iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15);
85			iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13);
86		} else {
87			/* Select 100mbps port to check for link beat. */
88			new_csr6 = 0x83860000;
89			dev->if_port = 3;
90			iowrite32(0, ioaddr + CSR13);
91			iowrite32(0x0003FFFF, ioaddr + CSR14);
92			iowrite16(8, ioaddr + CSR15);
93			iowrite32(1, ioaddr + CSR13);
94		}
95		if (tulip_debug > 1)
96			dev_info(&dev->dev, "Testing new 21143 media %s\n",
97				 medianame[dev->if_port]);
98		if (new_csr6 != (tp->csr6 & ~0x00D5)) {
99			tp->csr6 &= 0x00D5;
100			tp->csr6 |= new_csr6;
101			iowrite32(0x0301, ioaddr + CSR12);
102			tulip_restart_rxtx(tp);
103		}
104		next_tick = 3*HZ;
105	}
106
107	/* mod_timer synchronizes us with potential add_timer calls
108	 * from interrupts.
109	 */
110	mod_timer(&tp->timer, RUN_AT(next_tick));
111}
112
113
114void t21142_start_nway(struct net_device *dev)
115{
116	struct tulip_private *tp = netdev_priv(dev);
117	void __iomem *ioaddr = tp->base_addr;
118	int csr14 = ((tp->sym_advertise & 0x0780) << 9)  |
119		((tp->sym_advertise & 0x0020) << 1) | 0xffbf;
120
121	dev->if_port = 0;
122	tp->nway = tp->mediasense = 1;
123	tp->nwayset = tp->lpar = 0;
124	if (tulip_debug > 1)
125		printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%08x\n",
126		       dev->name, csr14);
127	iowrite32(0x0001, ioaddr + CSR13);
128	udelay(100);
129	iowrite32(csr14, ioaddr + CSR14);
130	tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
131	iowrite32(tp->csr6, ioaddr + CSR6);
132	if (tp->mtable  &&  tp->mtable->csr15dir) {
133		iowrite32(tp->mtable->csr15dir, ioaddr + CSR15);
134		iowrite32(tp->mtable->csr15val, ioaddr + CSR15);
135	} else
136		iowrite16(0x0008, ioaddr + CSR15);
137	iowrite32(0x1301, ioaddr + CSR12); 		/* Trigger NWAY. */
138}
139
140
141
142void t21142_lnk_change(struct net_device *dev, int csr5)
143{
144	struct tulip_private *tp = netdev_priv(dev);
145	void __iomem *ioaddr = tp->base_addr;
146	int csr12 = ioread32(ioaddr + CSR12);
147	int csr14 = ioread32(ioaddr + CSR14);
148
149	/* CSR12[LS10,LS100] are not reliable during autonegotiation */
150	if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
151		csr12 |= 6;
152	if (tulip_debug > 1)
153		dev_info(&dev->dev,
154			 "21143 link status interrupt %08x, CSR5 %x, %08x\n",
155			 csr12, csr5, csr14);
156
157	/* If NWay finished and we have a negotiated partner capability. */
158	if (tp->nway  &&  !tp->nwayset  &&  (csr12 & 0x7000) == 0x5000) {
159		int setup_done = 0;
160		int negotiated = tp->sym_advertise & (csr12 >> 16);
161		tp->lpar = csr12 >> 16;
162		tp->nwayset = 1;
163		/* If partner cannot negotiate, it is 10Mbps Half Duplex */
164		if (!(csr12 & 0x8000))		dev->if_port = 0;
165		else if (negotiated & 0x0100)	dev->if_port = 5;
166		else if (negotiated & 0x0080)	dev->if_port = 3;
167		else if (negotiated & 0x0040)	dev->if_port = 4;
168		else if (negotiated & 0x0020)	dev->if_port = 0;
169		else {
170			tp->nwayset = 0;
171			if ((csr12 & 2) == 0  &&  (tp->sym_advertise & 0x0180))
172				dev->if_port = 3;
173		}
174		tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
175
176		if (tulip_debug > 1) {
177			if (tp->nwayset)
178				dev_info(&dev->dev,
179					 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
180					 medianame[dev->if_port],
181					 tp->sym_advertise, tp->lpar,
182					 negotiated);
183			else
184				dev_info(&dev->dev,
185					 "Autonegotiation failed, using %s, link beat status %04x\n",
186					 medianame[dev->if_port], csr12);
187		}
188
189		if (tp->mtable) {
190			int i;
191			for (i = 0; i < tp->mtable->leafcount; i++)
192				if (tp->mtable->mleaf[i].media == dev->if_port) {
193					int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
194					tp->cur_index = i;
195					tulip_select_media(dev, startup);
196					setup_done = 1;
197					break;
198				}
199		}
200		if ( ! setup_done) {
201			tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
202			if (tp->full_duplex)
203				tp->csr6 |= 0x0200;
204			iowrite32(1, ioaddr + CSR13);
205		}
206		tulip_start_rxtx(tp);
207		if (tulip_debug > 2)
208			printk(KERN_DEBUG "%s:  Setting CSR6 %08x/%x CSR12 %08x\n",
209			       dev->name, tp->csr6, ioread32(ioaddr + CSR6),
210			       ioread32(ioaddr + CSR12));
211	} else if ((tp->nwayset  &&  (csr5 & 0x08000000) &&
212		    (dev->if_port == 3  ||  dev->if_port == 5) &&
213		    (csr12 & 2) == 2) ||
214		   (tp->nway && (csr5 & (TPLnkFail)))) {
215		/* Link blew? Maybe restart NWay. */
216		del_timer_sync(&tp->timer);
217		t21142_start_nway(dev);
218		tp->timer.expires = RUN_AT(3*HZ);
219		add_timer(&tp->timer);
220	} else if (dev->if_port == 3  ||  dev->if_port == 5) {
221		if (tulip_debug > 1)
222			dev_info(&dev->dev, "21143 %s link beat %s\n",
223				 medianame[dev->if_port],
224				 (csr12 & 2) ? "failed" : "good");
225		if ((csr12 & 2)  &&  ! tp->medialock) {
226			del_timer_sync(&tp->timer);
227			t21142_start_nway(dev);
228			tp->timer.expires = RUN_AT(3*HZ);
229			add_timer(&tp->timer);
230		} else if (dev->if_port == 5)
231			iowrite32(csr14 & ~0x080, ioaddr + CSR14);
232	} else if (dev->if_port == 0  ||  dev->if_port == 4) {
233		if ((csr12 & 4) == 0)
234			dev_info(&dev->dev, "21143 10baseT link beat good\n");
235	} else if (!(csr12 & 4)) {		/* 10mbps link beat good. */
236		if (tulip_debug)
237			dev_info(&dev->dev, "21143 10mbps sensed media\n");
238		dev->if_port = 0;
239	} else if (tp->nwayset) {
240		if (tulip_debug)
241			dev_info(&dev->dev, "21143 using NWay-set %s, csr6 %08x\n",
242				 medianame[dev->if_port], tp->csr6);
243	} else {		/* 100mbps link beat good. */
244		if (tulip_debug)
245			dev_info(&dev->dev, "21143 100baseTx sensed media\n");
246		dev->if_port = 3;
247		tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
248		iowrite32(0x0003FF7F, ioaddr + CSR14);
249		iowrite32(0x0301, ioaddr + CSR12);
250		tulip_restart_rxtx(tp);
251	}
252}
253