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/pci.h>
18 #include <linux/delay.h>
22 static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
23 u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
24 static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
27 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
28 of available transceivers. */
29 void t21142_media_task(struct work_struct *work)
31 struct tulip_private *tp =
32 container_of(work, struct tulip_private, media_work);
33 struct net_device *dev = tp->dev;
34 void __iomem *ioaddr = tp->base_addr;
35 int csr12 = ioread32(ioaddr + CSR12);
36 int next_tick = 60*HZ;
40 printk(KERN_INFO"%s: 21143 negotiation status %8.8x, %s.\n",
41 dev->name, csr12, medianame[dev->if_port]);
42 if (tulip_media_cap[dev->if_port] & MediaIsMII) {
43 if (tulip_check_duplex(dev) < 0) {
44 netif_carrier_off(dev);
47 netif_carrier_on(dev);
50 } else if (tp->nwayset) {
51 /* Don't screw up a negotiated session! */
53 printk(KERN_INFO"%s: Using NWay-set %s media, csr12 %8.8x.\n",
54 dev->name, medianame[dev->if_port], csr12);
55 } else if (tp->medialock) {
57 } else if (dev->if_port == 3) {
58 if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
60 printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
61 "trying NWay.\n", dev->name, csr12);
62 t21142_start_nway(dev);
65 } else if ((csr12 & 0x7000) != 0x5000) {
66 /* Negotiation failed. Search media types. */
68 printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
70 if (!(csr12 & 4)) { /* 10mbps link beat good. */
71 new_csr6 = 0x82420000;
73 iowrite32(0, ioaddr + CSR13);
74 iowrite32(0x0003FFFF, ioaddr + CSR14);
75 iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15);
76 iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13);
78 /* Select 100mbps port to check for link beat. */
79 new_csr6 = 0x83860000;
81 iowrite32(0, ioaddr + CSR13);
82 iowrite32(0x0003FF7F, ioaddr + CSR14);
83 iowrite16(8, ioaddr + CSR15);
84 iowrite32(1, ioaddr + CSR13);
87 printk(KERN_INFO"%s: Testing new 21143 media %s.\n",
88 dev->name, medianame[dev->if_port]);
89 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
92 iowrite32(0x0301, ioaddr + CSR12);
93 tulip_restart_rxtx(tp);
98 /* mod_timer synchronizes us with potential add_timer calls
101 mod_timer(&tp->timer, RUN_AT(next_tick));
105 void t21142_start_nway(struct net_device *dev)
107 struct tulip_private *tp = netdev_priv(dev);
108 void __iomem *ioaddr = tp->base_addr;
109 int csr14 = ((tp->sym_advertise & 0x0780) << 9) |
110 ((tp->sym_advertise & 0x0020) << 1) | 0xffbf;
113 tp->nway = tp->mediasense = 1;
114 tp->nwayset = tp->lpar = 0;
116 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%8.8x.\n",
118 iowrite32(0x0001, ioaddr + CSR13);
120 iowrite32(csr14, ioaddr + CSR14);
121 tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
122 iowrite32(tp->csr6, ioaddr + CSR6);
123 if (tp->mtable && tp->mtable->csr15dir) {
124 iowrite32(tp->mtable->csr15dir, ioaddr + CSR15);
125 iowrite32(tp->mtable->csr15val, ioaddr + CSR15);
127 iowrite16(0x0008, ioaddr + CSR15);
128 iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */
133 void t21142_lnk_change(struct net_device *dev, int csr5)
135 struct tulip_private *tp = netdev_priv(dev);
136 void __iomem *ioaddr = tp->base_addr;
137 int csr12 = ioread32(ioaddr + CSR12);
140 printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
141 "%8.8x.\n", dev->name, csr12, csr5, ioread32(ioaddr + CSR14));
143 /* If NWay finished and we have a negotiated partner capability. */
144 if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
146 int negotiated = tp->sym_advertise & (csr12 >> 16);
147 tp->lpar = csr12 >> 16;
149 if (negotiated & 0x0100) dev->if_port = 5;
150 else if (negotiated & 0x0080) dev->if_port = 3;
151 else if (negotiated & 0x0040) dev->if_port = 4;
152 else if (negotiated & 0x0020) dev->if_port = 0;
155 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
158 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
160 if (tulip_debug > 1) {
162 printk(KERN_INFO "%s: Switching to %s based on link "
163 "negotiation %4.4x & %4.4x = %4.4x.\n",
164 dev->name, medianame[dev->if_port], tp->sym_advertise,
165 tp->lpar, negotiated);
167 printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
168 " link beat status %4.4x.\n",
169 dev->name, medianame[dev->if_port], csr12);
174 for (i = 0; i < tp->mtable->leafcount; i++)
175 if (tp->mtable->mleaf[i].media == dev->if_port) {
176 int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
178 tulip_select_media(dev, startup);
184 tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
187 iowrite32(1, ioaddr + CSR13);
189 #if 0 /* Restart shouldn't be needed. */
190 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
192 printk(KERN_DEBUG "%s: Restarting Tx and Rx, CSR5 is %8.8x.\n",
193 dev->name, ioread32(ioaddr + CSR5));
195 tulip_start_rxtx(tp);
197 printk(KERN_DEBUG "%s: Setting CSR6 %8.8x/%x CSR12 %8.8x.\n",
198 dev->name, tp->csr6, ioread32(ioaddr + CSR6),
199 ioread32(ioaddr + CSR12));
200 } else if ((tp->nwayset && (csr5 & 0x08000000)
201 && (dev->if_port == 3 || dev->if_port == 5)
202 && (csr12 & 2) == 2) ||
203 (tp->nway && (csr5 & (TPLnkFail)))) {
204 /* Link blew? Maybe restart NWay. */
205 del_timer_sync(&tp->timer);
206 t21142_start_nway(dev);
207 tp->timer.expires = RUN_AT(3*HZ);
208 add_timer(&tp->timer);
209 } else if (dev->if_port == 3 || dev->if_port == 5) {
211 printk(KERN_INFO"%s: 21143 %s link beat %s.\n",
212 dev->name, medianame[dev->if_port],
213 (csr12 & 2) ? "failed" : "good");
214 if ((csr12 & 2) && ! tp->medialock) {
215 del_timer_sync(&tp->timer);
216 t21142_start_nway(dev);
217 tp->timer.expires = RUN_AT(3*HZ);
218 add_timer(&tp->timer);
219 } else if (dev->if_port == 5)
220 iowrite32(ioread32(ioaddr + CSR14) & ~0x080, ioaddr + CSR14);
221 } else if (dev->if_port == 0 || dev->if_port == 4) {
222 if ((csr12 & 4) == 0)
223 printk(KERN_INFO"%s: 21143 10baseT link beat good.\n",
225 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
227 printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
230 } else if (tp->nwayset) {
232 printk(KERN_INFO"%s: 21143 using NWay-set %s, csr6 %8.8x.\n",
233 dev->name, medianame[dev->if_port], tp->csr6);
234 } else { /* 100mbps link beat good. */
236 printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
239 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
240 iowrite32(0x0003FF7F, ioaddr + CSR14);
241 iowrite32(0x0301, ioaddr + CSR12);
242 tulip_restart_rxtx(tp);