Merge branch 'upstream-net26' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6] / drivers / net / tulip / 21142.c
1 /*
2         drivers/net/tulip/21142.c
3
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.
7
8         This software may be used and distributed according to the terms
9         of the GNU General Public License, incorporated herein by reference.
10
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/
14
15 */
16
17 #include <linux/delay.h>
18 #include "tulip.h"
19
20
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, };
24
25
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)
29 {
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;
36         int new_csr6 = 0;
37
38         if (tulip_debug > 2)
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);
44                         next_tick = 3*HZ;
45                 } else {
46                         netif_carrier_on(dev);
47                         next_tick = 60*HZ;
48                 }
49         } else if (tp->nwayset) {
50                 /* Don't screw up a negotiated session! */
51                 if (tulip_debug > 1)
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) {
55                         ;
56         } else if (dev->if_port == 3) {
57                 if (csr12 & 2) {        /* No 100mbps link beat, revert to 10mbps. */
58                         if (tulip_debug > 1)
59                                 printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
60                                            "trying NWay.\n", dev->name, csr12);
61                         t21142_start_nway(dev);
62                         next_tick = 3*HZ;
63                 }
64         } else if ((csr12 & 0x7000) != 0x5000) {
65                 /* Negotiation failed.  Search media types. */
66                 if (tulip_debug > 1)
67                         printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
68                                    dev->name, csr12);
69                 if (!(csr12 & 4)) {             /* 10mbps link beat good. */
70                         new_csr6 = 0x82420000;
71                         dev->if_port = 0;
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);
76                 } else {
77                         /* Select 100mbps port to check for link beat. */
78                         new_csr6 = 0x83860000;
79                         dev->if_port = 3;
80                         iowrite32(0, ioaddr + CSR13);
81                         iowrite32(0x0003FF7F, ioaddr + CSR14);
82                         iowrite16(8, ioaddr + CSR15);
83                         iowrite32(1, ioaddr + CSR13);
84                 }
85                 if (tulip_debug > 1)
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)) {
89                         tp->csr6 &= 0x00D5;
90                         tp->csr6 |= new_csr6;
91                         iowrite32(0x0301, ioaddr + CSR12);
92                         tulip_restart_rxtx(tp);
93                 }
94                 next_tick = 3*HZ;
95         }
96
97         /* mod_timer synchronizes us with potential add_timer calls
98          * from interrupts.
99          */
100         mod_timer(&tp->timer, RUN_AT(next_tick));
101 }
102
103
104 void t21142_start_nway(struct net_device *dev)
105 {
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;
110
111         dev->if_port = 0;
112         tp->nway = tp->mediasense = 1;
113         tp->nwayset = tp->lpar = 0;
114         if (tulip_debug > 1)
115                 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%8.8x.\n",
116                            dev->name, csr14);
117         iowrite32(0x0001, ioaddr + CSR13);
118         udelay(100);
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);
125         } else
126                 iowrite16(0x0008, ioaddr + CSR15);
127         iowrite32(0x1301, ioaddr + CSR12);              /* Trigger NWAY. */
128 }
129
130
131
132 void t21142_lnk_change(struct net_device *dev, int csr5)
133 {
134         struct tulip_private *tp = netdev_priv(dev);
135         void __iomem *ioaddr = tp->base_addr;
136         int csr12 = ioread32(ioaddr + CSR12);
137
138         if (tulip_debug > 1)
139                 printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
140                            "%8.8x.\n", dev->name, csr12, csr5, ioread32(ioaddr + CSR14));
141
142         /* If NWay finished and we have a negotiated partner capability. */
143         if (tp->nway  &&  !tp->nwayset  &&  (csr12 & 0x7000) == 0x5000) {
144                 int setup_done = 0;
145                 int negotiated = tp->sym_advertise & (csr12 >> 16);
146                 tp->lpar = csr12 >> 16;
147                 tp->nwayset = 1;
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;
152                 else {
153                         tp->nwayset = 0;
154                         if ((csr12 & 2) == 0  &&  (tp->sym_advertise & 0x0180))
155                                 dev->if_port = 3;
156                 }
157                 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
158
159                 if (tulip_debug > 1) {
160                         if (tp->nwayset)
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);
165                         else
166                                 printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
167                                            " link beat status %4.4x.\n",
168                                            dev->name, medianame[dev->if_port], csr12);
169                 }
170
171                 if (tp->mtable) {
172                         int i;
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)));
176                                         tp->cur_index = i;
177                                         tulip_select_media(dev, startup);
178                                         setup_done = 1;
179                                         break;
180                                 }
181                 }
182                 if ( ! setup_done) {
183                         tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
184                         if (tp->full_duplex)
185                                 tp->csr6 |= 0x0200;
186                         iowrite32(1, ioaddr + CSR13);
187                 }
188 #if 0                                                   /* Restart shouldn't be needed. */
189                 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
190                 if (tulip_debug > 2)
191                         printk(KERN_DEBUG "%s:  Restarting Tx and Rx, CSR5 is %8.8x.\n",
192                                    dev->name, ioread32(ioaddr + CSR5));
193 #endif
194                 tulip_start_rxtx(tp);
195                 if (tulip_debug > 2)
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) {
209                 if (tulip_debug > 1)
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",
223                                    dev->name);
224         } else if (!(csr12 & 4)) {              /* 10mbps link beat good. */
225                 if (tulip_debug)
226                         printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
227                                    dev->name);
228                 dev->if_port = 0;
229         } else if (tp->nwayset) {
230                 if (tulip_debug)
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. */
234                 if (tulip_debug)
235                         printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
236                                    dev->name);
237                 dev->if_port = 3;
238                 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
239                 iowrite32(0x0003FF7F, ioaddr + CSR14);
240                 iowrite32(0x0301, ioaddr + CSR12);
241                 tulip_restart_rxtx(tp);
242         }
243 }
244
245