2 drivers/net/tulip/21142.c
4 Maintained by Valerie Henson <val_henson@linux.intel.com>
5 Copyright 2000,2001 The Linux Kernel Team
6 Written/copyright 1994-2001 by Donald Becker.
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
11 Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html}
12 for more information on this driver, or visit the project
13 Web page at http://sourceforge.net/projects/tulip/
17 #include <linux/delay.h>
21 static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
22 u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
23 static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
26 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
27 of available transceivers. */
28 void t21142_media_task(struct work_struct *work)
30 struct tulip_private *tp =
31 container_of(work, struct tulip_private, media_work);
32 struct net_device *dev = tp->dev;
33 void __iomem *ioaddr = tp->base_addr;
34 int csr12 = ioread32(ioaddr + CSR12);
35 int next_tick = 60*HZ;
39 printk(KERN_INFO"%s: 21143 negotiation status %8.8x, %s.\n",
40 dev->name, csr12, medianame[dev->if_port]);
41 if (tulip_media_cap[dev->if_port] & MediaIsMII) {
42 if (tulip_check_duplex(dev) < 0) {
43 netif_carrier_off(dev);
46 netif_carrier_on(dev);
49 } else if (tp->nwayset) {
50 /* Don't screw up a negotiated session! */
52 printk(KERN_INFO"%s: Using NWay-set %s media, csr12 %8.8x.\n",
53 dev->name, medianame[dev->if_port], csr12);
54 } else if (tp->medialock) {
56 } else if (dev->if_port == 3) {
57 if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
59 printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
60 "trying NWay.\n", dev->name, csr12);
61 t21142_start_nway(dev);
64 } else if ((csr12 & 0x7000) != 0x5000) {
65 /* Negotiation failed. Search media types. */
67 printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
69 if (!(csr12 & 4)) { /* 10mbps link beat good. */
70 new_csr6 = 0x82420000;
72 iowrite32(0, ioaddr + CSR13);
73 iowrite32(0x0003FFFF, ioaddr + CSR14);
74 iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15);
75 iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13);
77 /* Select 100mbps port to check for link beat. */
78 new_csr6 = 0x83860000;
80 iowrite32(0, ioaddr + CSR13);
81 iowrite32(0x0003FF7F, ioaddr + CSR14);
82 iowrite16(8, ioaddr + CSR15);
83 iowrite32(1, ioaddr + CSR13);
86 printk(KERN_INFO"%s: Testing new 21143 media %s.\n",
87 dev->name, medianame[dev->if_port]);
88 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
91 iowrite32(0x0301, ioaddr + CSR12);
92 tulip_restart_rxtx(tp);
97 /* mod_timer synchronizes us with potential add_timer calls
100 mod_timer(&tp->timer, RUN_AT(next_tick));
104 void t21142_start_nway(struct net_device *dev)
106 struct tulip_private *tp = netdev_priv(dev);
107 void __iomem *ioaddr = tp->base_addr;
108 int csr14 = ((tp->sym_advertise & 0x0780) << 9) |
109 ((tp->sym_advertise & 0x0020) << 1) | 0xffbf;
112 tp->nway = tp->mediasense = 1;
113 tp->nwayset = tp->lpar = 0;
115 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%8.8x.\n",
117 iowrite32(0x0001, ioaddr + CSR13);
119 iowrite32(csr14, ioaddr + CSR14);
120 tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
121 iowrite32(tp->csr6, ioaddr + CSR6);
122 if (tp->mtable && tp->mtable->csr15dir) {
123 iowrite32(tp->mtable->csr15dir, ioaddr + CSR15);
124 iowrite32(tp->mtable->csr15val, ioaddr + CSR15);
126 iowrite16(0x0008, ioaddr + CSR15);
127 iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */
132 void t21142_lnk_change(struct net_device *dev, int csr5)
134 struct tulip_private *tp = netdev_priv(dev);
135 void __iomem *ioaddr = tp->base_addr;
136 int csr12 = ioread32(ioaddr + CSR12);
139 printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
140 "%8.8x.\n", dev->name, csr12, csr5, ioread32(ioaddr + CSR14));
142 /* If NWay finished and we have a negotiated partner capability. */
143 if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
145 int negotiated = tp->sym_advertise & (csr12 >> 16);
146 tp->lpar = csr12 >> 16;
148 if (negotiated & 0x0100) dev->if_port = 5;
149 else if (negotiated & 0x0080) dev->if_port = 3;
150 else if (negotiated & 0x0040) dev->if_port = 4;
151 else if (negotiated & 0x0020) dev->if_port = 0;
154 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
157 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
159 if (tulip_debug > 1) {
161 printk(KERN_INFO "%s: Switching to %s based on link "
162 "negotiation %4.4x & %4.4x = %4.4x.\n",
163 dev->name, medianame[dev->if_port], tp->sym_advertise,
164 tp->lpar, negotiated);
166 printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
167 " link beat status %4.4x.\n",
168 dev->name, medianame[dev->if_port], csr12);
173 for (i = 0; i < tp->mtable->leafcount; i++)
174 if (tp->mtable->mleaf[i].media == dev->if_port) {
175 int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
177 tulip_select_media(dev, startup);
183 tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
186 iowrite32(1, ioaddr + CSR13);
188 #if 0 /* Restart shouldn't be needed. */
189 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
191 printk(KERN_DEBUG "%s: Restarting Tx and Rx, CSR5 is %8.8x.\n",
192 dev->name, ioread32(ioaddr + CSR5));
194 tulip_start_rxtx(tp);
196 printk(KERN_DEBUG "%s: Setting CSR6 %8.8x/%x CSR12 %8.8x.\n",
197 dev->name, tp->csr6, ioread32(ioaddr + CSR6),
198 ioread32(ioaddr + CSR12));
199 } else if ((tp->nwayset && (csr5 & 0x08000000)
200 && (dev->if_port == 3 || dev->if_port == 5)
201 && (csr12 & 2) == 2) ||
202 (tp->nway && (csr5 & (TPLnkFail)))) {
203 /* Link blew? Maybe restart NWay. */
204 del_timer_sync(&tp->timer);
205 t21142_start_nway(dev);
206 tp->timer.expires = RUN_AT(3*HZ);
207 add_timer(&tp->timer);
208 } else if (dev->if_port == 3 || dev->if_port == 5) {
210 printk(KERN_INFO"%s: 21143 %s link beat %s.\n",
211 dev->name, medianame[dev->if_port],
212 (csr12 & 2) ? "failed" : "good");
213 if ((csr12 & 2) && ! tp->medialock) {
214 del_timer_sync(&tp->timer);
215 t21142_start_nway(dev);
216 tp->timer.expires = RUN_AT(3*HZ);
217 add_timer(&tp->timer);
218 } else if (dev->if_port == 5)
219 iowrite32(ioread32(ioaddr + CSR14) & ~0x080, ioaddr + CSR14);
220 } else if (dev->if_port == 0 || dev->if_port == 4) {
221 if ((csr12 & 4) == 0)
222 printk(KERN_INFO"%s: 21143 10baseT link beat good.\n",
224 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
226 printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
229 } else if (tp->nwayset) {
231 printk(KERN_INFO"%s: 21143 using NWay-set %s, csr6 %8.8x.\n",
232 dev->name, medianame[dev->if_port], tp->csr6);
233 } else { /* 100mbps link beat good. */
235 printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
238 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
239 iowrite32(0x0003FF7F, ioaddr + CSR14);
240 iowrite32(0x0301, ioaddr + CSR12);
241 tulip_restart_rxtx(tp);