2 drivers/net/tulip/21142.c
4 Copyright 2000,2001 The Linux Kernel Team
5 Written/copyright 1994-2001 by Donald Becker.
7 This software may be used and distributed according to the terms
8 of the GNU General Public License, incorporated herein by reference.
10 Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html}
11 for more information on this driver.
12 Please submit bugs to http://bugzilla.kernel.org/ .
15 #include <linux/delay.h>
19 static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
20 u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
21 static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
24 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
25 of available transceivers. */
26 void t21142_media_task(struct work_struct *work)
28 struct tulip_private *tp =
29 container_of(work, struct tulip_private, media_work);
30 struct net_device *dev = tp->dev;
31 void __iomem *ioaddr = tp->base_addr;
32 int csr12 = ioread32(ioaddr + CSR12);
33 int next_tick = 60*HZ;
37 printk(KERN_INFO"%s: 21143 negotiation status %8.8x, %s.\n",
38 dev->name, csr12, medianame[dev->if_port]);
39 if (tulip_media_cap[dev->if_port] & MediaIsMII) {
40 if (tulip_check_duplex(dev) < 0) {
41 netif_carrier_off(dev);
44 netif_carrier_on(dev);
47 } else if (tp->nwayset) {
48 /* Don't screw up a negotiated session! */
50 printk(KERN_INFO"%s: Using NWay-set %s media, csr12 %8.8x.\n",
51 dev->name, medianame[dev->if_port], csr12);
52 } else if (tp->medialock) {
54 } else if (dev->if_port == 3) {
55 if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
57 printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
58 "trying NWay.\n", dev->name, csr12);
59 t21142_start_nway(dev);
62 } else if ((csr12 & 0x7000) != 0x5000) {
63 /* Negotiation failed. Search media types. */
65 printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
67 if (!(csr12 & 4)) { /* 10mbps link beat good. */
68 new_csr6 = 0x82420000;
70 iowrite32(0, ioaddr + CSR13);
71 iowrite32(0x0003FFFF, ioaddr + CSR14);
72 iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15);
73 iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13);
75 /* Select 100mbps port to check for link beat. */
76 new_csr6 = 0x83860000;
78 iowrite32(0, ioaddr + CSR13);
79 iowrite32(0x0003FF7F, ioaddr + CSR14);
80 iowrite16(8, ioaddr + CSR15);
81 iowrite32(1, ioaddr + CSR13);
84 printk(KERN_INFO"%s: Testing new 21143 media %s.\n",
85 dev->name, medianame[dev->if_port]);
86 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
89 iowrite32(0x0301, ioaddr + CSR12);
90 tulip_restart_rxtx(tp);
95 /* mod_timer synchronizes us with potential add_timer calls
98 mod_timer(&tp->timer, RUN_AT(next_tick));
102 void t21142_start_nway(struct net_device *dev)
104 struct tulip_private *tp = netdev_priv(dev);
105 void __iomem *ioaddr = tp->base_addr;
106 int csr14 = ((tp->sym_advertise & 0x0780) << 9) |
107 ((tp->sym_advertise & 0x0020) << 1) | 0xffbf;
110 tp->nway = tp->mediasense = 1;
111 tp->nwayset = tp->lpar = 0;
113 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%8.8x.\n",
115 iowrite32(0x0001, ioaddr + CSR13);
117 iowrite32(csr14, ioaddr + CSR14);
118 tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
119 iowrite32(tp->csr6, ioaddr + CSR6);
120 if (tp->mtable && tp->mtable->csr15dir) {
121 iowrite32(tp->mtable->csr15dir, ioaddr + CSR15);
122 iowrite32(tp->mtable->csr15val, ioaddr + CSR15);
124 iowrite16(0x0008, ioaddr + CSR15);
125 iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */
130 void t21142_lnk_change(struct net_device *dev, int csr5)
132 struct tulip_private *tp = netdev_priv(dev);
133 void __iomem *ioaddr = tp->base_addr;
134 int csr12 = ioread32(ioaddr + CSR12);
137 printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
138 "%8.8x.\n", dev->name, csr12, csr5, ioread32(ioaddr + CSR14));
140 /* If NWay finished and we have a negotiated partner capability. */
141 if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
143 int negotiated = tp->sym_advertise & (csr12 >> 16);
144 tp->lpar = csr12 >> 16;
146 if (negotiated & 0x0100) dev->if_port = 5;
147 else if (negotiated & 0x0080) dev->if_port = 3;
148 else if (negotiated & 0x0040) dev->if_port = 4;
149 else if (negotiated & 0x0020) dev->if_port = 0;
152 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
155 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
157 if (tulip_debug > 1) {
159 printk(KERN_INFO "%s: Switching to %s based on link "
160 "negotiation %4.4x & %4.4x = %4.4x.\n",
161 dev->name, medianame[dev->if_port], tp->sym_advertise,
162 tp->lpar, negotiated);
164 printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
165 " link beat status %4.4x.\n",
166 dev->name, medianame[dev->if_port], csr12);
171 for (i = 0; i < tp->mtable->leafcount; i++)
172 if (tp->mtable->mleaf[i].media == dev->if_port) {
173 int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
175 tulip_select_media(dev, startup);
181 tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
184 iowrite32(1, ioaddr + CSR13);
186 #if 0 /* Restart shouldn't be needed. */
187 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
189 printk(KERN_DEBUG "%s: Restarting Tx and Rx, CSR5 is %8.8x.\n",
190 dev->name, ioread32(ioaddr + CSR5));
192 tulip_start_rxtx(tp);
194 printk(KERN_DEBUG "%s: Setting CSR6 %8.8x/%x CSR12 %8.8x.\n",
195 dev->name, tp->csr6, ioread32(ioaddr + CSR6),
196 ioread32(ioaddr + CSR12));
197 } else if ((tp->nwayset && (csr5 & 0x08000000)
198 && (dev->if_port == 3 || dev->if_port == 5)
199 && (csr12 & 2) == 2) ||
200 (tp->nway && (csr5 & (TPLnkFail)))) {
201 /* Link blew? Maybe restart NWay. */
202 del_timer_sync(&tp->timer);
203 t21142_start_nway(dev);
204 tp->timer.expires = RUN_AT(3*HZ);
205 add_timer(&tp->timer);
206 } else if (dev->if_port == 3 || dev->if_port == 5) {
208 printk(KERN_INFO"%s: 21143 %s link beat %s.\n",
209 dev->name, medianame[dev->if_port],
210 (csr12 & 2) ? "failed" : "good");
211 if ((csr12 & 2) && ! tp->medialock) {
212 del_timer_sync(&tp->timer);
213 t21142_start_nway(dev);
214 tp->timer.expires = RUN_AT(3*HZ);
215 add_timer(&tp->timer);
216 } else if (dev->if_port == 5)
217 iowrite32(ioread32(ioaddr + CSR14) & ~0x080, ioaddr + CSR14);
218 } else if (dev->if_port == 0 || dev->if_port == 4) {
219 if ((csr12 & 4) == 0)
220 printk(KERN_INFO"%s: 21143 10baseT link beat good.\n",
222 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
224 printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
227 } else if (tp->nwayset) {
229 printk(KERN_INFO"%s: 21143 using NWay-set %s, csr6 %8.8x.\n",
230 dev->name, medianame[dev->if_port], tp->csr6);
231 } else { /* 100mbps link beat good. */
233 printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
236 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
237 iowrite32(0x0003FF7F, ioaddr + CSR14);
238 iowrite32(0x0301, ioaddr + CSR12);
239 tulip_restart_rxtx(tp);