blob: 1210fb3748a74e7dfb085fb7cf4aa874a6455504 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 drivers/net/tulip/21142.c
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 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}
Grant Grundler78a65512008-06-05 00:38:55 -060011 for more information on this driver.
12 Please submit bugs to http://bugzilla.kernel.org/ .
Linus Torvalds1da177e2005-04-16 15:20:36 -070013*/
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/delay.h>
16#include "tulip.h"
17
18
19static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
20u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
21static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
22
23
24/* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
25 of available transceivers. */
David Howellsc4028952006-11-22 14:57:56 +000026void t21142_media_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
David Howellsc4028952006-11-22 14:57:56 +000028 struct tulip_private *tp =
29 container_of(work, struct tulip_private, media_work);
30 struct net_device *dev = tp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 void __iomem *ioaddr = tp->base_addr;
32 int csr12 = ioread32(ioaddr + CSR12);
33 int next_tick = 60*HZ;
34 int new_csr6 = 0;
35
36 if (tulip_debug > 2)
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);
42 next_tick = 3*HZ;
43 } else {
44 netif_carrier_on(dev);
45 next_tick = 60*HZ;
46 }
47 } else if (tp->nwayset) {
48 /* Don't screw up a negotiated session! */
49 if (tulip_debug > 1)
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) {
53 ;
54 } else if (dev->if_port == 3) {
55 if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
56 if (tulip_debug > 1)
57 printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
58 "trying NWay.\n", dev->name, csr12);
59 t21142_start_nway(dev);
60 next_tick = 3*HZ;
61 }
62 } else if ((csr12 & 0x7000) != 0x5000) {
63 /* Negotiation failed. Search media types. */
64 if (tulip_debug > 1)
65 printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
66 dev->name, csr12);
67 if (!(csr12 & 4)) { /* 10mbps link beat good. */
68 new_csr6 = 0x82420000;
69 dev->if_port = 0;
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);
74 } else {
75 /* Select 100mbps port to check for link beat. */
76 new_csr6 = 0x83860000;
77 dev->if_port = 3;
78 iowrite32(0, ioaddr + CSR13);
79 iowrite32(0x0003FF7F, ioaddr + CSR14);
80 iowrite16(8, ioaddr + CSR15);
81 iowrite32(1, ioaddr + CSR13);
82 }
83 if (tulip_debug > 1)
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)) {
87 tp->csr6 &= 0x00D5;
88 tp->csr6 |= new_csr6;
89 iowrite32(0x0301, ioaddr + CSR12);
90 tulip_restart_rxtx(tp);
91 }
92 next_tick = 3*HZ;
93 }
94
95 /* mod_timer synchronizes us with potential add_timer calls
96 * from interrupts.
97 */
98 mod_timer(&tp->timer, RUN_AT(next_tick));
99}
100
101
102void t21142_start_nway(struct net_device *dev)
103{
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;
108
109 dev->if_port = 0;
110 tp->nway = tp->mediasense = 1;
111 tp->nwayset = tp->lpar = 0;
112 if (tulip_debug > 1)
113 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%8.8x.\n",
114 dev->name, csr14);
115 iowrite32(0x0001, ioaddr + CSR13);
116 udelay(100);
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);
123 } else
124 iowrite16(0x0008, ioaddr + CSR15);
125 iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */
126}
127
128
129
130void t21142_lnk_change(struct net_device *dev, int csr5)
131{
132 struct tulip_private *tp = netdev_priv(dev);
133 void __iomem *ioaddr = tp->base_addr;
134 int csr12 = ioread32(ioaddr + CSR12);
135
136 if (tulip_debug > 1)
137 printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
138 "%8.8x.\n", dev->name, csr12, csr5, ioread32(ioaddr + CSR14));
139
140 /* If NWay finished and we have a negotiated partner capability. */
141 if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
142 int setup_done = 0;
143 int negotiated = tp->sym_advertise & (csr12 >> 16);
144 tp->lpar = csr12 >> 16;
145 tp->nwayset = 1;
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;
150 else {
151 tp->nwayset = 0;
152 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
153 dev->if_port = 3;
154 }
155 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
156
157 if (tulip_debug > 1) {
158 if (tp->nwayset)
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);
163 else
164 printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
165 " link beat status %4.4x.\n",
166 dev->name, medianame[dev->if_port], csr12);
167 }
168
169 if (tp->mtable) {
170 int i;
171 for (i = 0; i < tp->mtable->leafcount; i++)
172 if (tp->mtable->mleaf[i].media == dev->if_port) {
Philippe De Muyter32b5bfa2005-09-22 11:09:44 +0200173 int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 tp->cur_index = i;
175 tulip_select_media(dev, startup);
176 setup_done = 1;
177 break;
178 }
179 }
180 if ( ! setup_done) {
181 tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
182 if (tp->full_duplex)
183 tp->csr6 |= 0x0200;
184 iowrite32(1, ioaddr + CSR13);
185 }
186#if 0 /* Restart shouldn't be needed. */
187 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
188 if (tulip_debug > 2)
189 printk(KERN_DEBUG "%s: Restarting Tx and Rx, CSR5 is %8.8x.\n",
190 dev->name, ioread32(ioaddr + CSR5));
191#endif
192 tulip_start_rxtx(tp);
193 if (tulip_debug > 2)
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) {
207 if (tulip_debug > 1)
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",
221 dev->name);
222 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
223 if (tulip_debug)
224 printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
225 dev->name);
226 dev->if_port = 0;
227 } else if (tp->nwayset) {
228 if (tulip_debug)
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. */
232 if (tulip_debug)
233 printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
234 dev->name);
235 dev->if_port = 3;
236 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
237 iowrite32(0x0003FF7F, ioaddr + CSR14);
238 iowrite32(0x0301, ioaddr + CSR12);
239 tulip_restart_rxtx(tp);
240 }
241}
242
243