Merge branch 'devel' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa...
[linux-2.6] / drivers / net / tulip / 21142.c
1 /*
2         drivers/net/tulip/21142.c
3
4         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}
11         for more information on this driver.
12
13         DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller
14         Hardware Reference Manual" is currently available at :
15         http://developer.intel.com/design/network/manuals/278074.htm
16
17         Please submit bugs to http://bugzilla.kernel.org/ .
18 */
19
20 #include <linux/delay.h>
21 #include "tulip.h"
22
23
24 static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
25 u16 t21142_csr14[] =        { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
26 static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
27
28
29 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
30    of available transceivers.  */
31 void t21142_media_task(struct work_struct *work)
32 {
33         struct tulip_private *tp =
34                 container_of(work, struct tulip_private, media_work);
35         struct net_device *dev = tp->dev;
36         void __iomem *ioaddr = tp->base_addr;
37         int csr12 = ioread32(ioaddr + CSR12);
38         int next_tick = 60*HZ;
39         int new_csr6 = 0;
40         int csr14 = ioread32(ioaddr + CSR14);
41
42         /* CSR12[LS10,LS100] are not reliable during autonegotiation */
43         if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
44                 csr12 |= 6;
45         if (tulip_debug > 2)
46                 printk(KERN_INFO"%s: 21143 negotiation status %8.8x, %s.\n",
47                            dev->name, csr12, medianame[dev->if_port]);
48         if (tulip_media_cap[dev->if_port] & MediaIsMII) {
49                 if (tulip_check_duplex(dev) < 0) {
50                         netif_carrier_off(dev);
51                         next_tick = 3*HZ;
52                 } else {
53                         netif_carrier_on(dev);
54                         next_tick = 60*HZ;
55                 }
56         } else if (tp->nwayset) {
57                 /* Don't screw up a negotiated session! */
58                 if (tulip_debug > 1)
59                         printk(KERN_INFO"%s: Using NWay-set %s media, csr12 %8.8x.\n",
60                                    dev->name, medianame[dev->if_port], csr12);
61         } else if (tp->medialock) {
62                         ;
63         } else if (dev->if_port == 3) {
64                 if (csr12 & 2) {        /* No 100mbps link beat, revert to 10mbps. */
65                         if (tulip_debug > 1)
66                                 printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
67                                            "trying NWay.\n", dev->name, csr12);
68                         t21142_start_nway(dev);
69                         next_tick = 3*HZ;
70                 }
71         } else if ((csr12 & 0x7000) != 0x5000) {
72                 /* Negotiation failed.  Search media types. */
73                 if (tulip_debug > 1)
74                         printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
75                                    dev->name, csr12);
76                 if (!(csr12 & 4)) {             /* 10mbps link beat good. */
77                         new_csr6 = 0x82420000;
78                         dev->if_port = 0;
79                         iowrite32(0, ioaddr + CSR13);
80                         iowrite32(0x0003FFFF, ioaddr + CSR14);
81                         iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15);
82                         iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13);
83                 } else {
84                         /* Select 100mbps port to check for link beat. */
85                         new_csr6 = 0x83860000;
86                         dev->if_port = 3;
87                         iowrite32(0, ioaddr + CSR13);
88                         iowrite32(0x0003FFFF, ioaddr + CSR14);
89                         iowrite16(8, ioaddr + CSR15);
90                         iowrite32(1, ioaddr + CSR13);
91                 }
92                 if (tulip_debug > 1)
93                         printk(KERN_INFO"%s: Testing new 21143 media %s.\n",
94                                    dev->name, medianame[dev->if_port]);
95                 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
96                         tp->csr6 &= 0x00D5;
97                         tp->csr6 |= new_csr6;
98                         iowrite32(0x0301, ioaddr + CSR12);
99                         tulip_restart_rxtx(tp);
100                 }
101                 next_tick = 3*HZ;
102         }
103
104         /* mod_timer synchronizes us with potential add_timer calls
105          * from interrupts.
106          */
107         mod_timer(&tp->timer, RUN_AT(next_tick));
108 }
109
110
111 void t21142_start_nway(struct net_device *dev)
112 {
113         struct tulip_private *tp = netdev_priv(dev);
114         void __iomem *ioaddr = tp->base_addr;
115         int csr14 = ((tp->sym_advertise & 0x0780) << 9)  |
116                 ((tp->sym_advertise & 0x0020) << 1) | 0xffbf;
117
118         dev->if_port = 0;
119         tp->nway = tp->mediasense = 1;
120         tp->nwayset = tp->lpar = 0;
121         if (tulip_debug > 1)
122                 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%8.8x.\n",
123                            dev->name, csr14);
124         iowrite32(0x0001, ioaddr + CSR13);
125         udelay(100);
126         iowrite32(csr14, ioaddr + CSR14);
127         tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
128         iowrite32(tp->csr6, ioaddr + CSR6);
129         if (tp->mtable  &&  tp->mtable->csr15dir) {
130                 iowrite32(tp->mtable->csr15dir, ioaddr + CSR15);
131                 iowrite32(tp->mtable->csr15val, ioaddr + CSR15);
132         } else
133                 iowrite16(0x0008, ioaddr + CSR15);
134         iowrite32(0x1301, ioaddr + CSR12);              /* Trigger NWAY. */
135 }
136
137
138
139 void t21142_lnk_change(struct net_device *dev, int csr5)
140 {
141         struct tulip_private *tp = netdev_priv(dev);
142         void __iomem *ioaddr = tp->base_addr;
143         int csr12 = ioread32(ioaddr + CSR12);
144         int csr14 = ioread32(ioaddr + CSR14);
145
146         /* CSR12[LS10,LS100] are not reliable during autonegotiation */
147         if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
148                 csr12 |= 6;
149         if (tulip_debug > 1)
150                 printk(KERN_INFO"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
151                            "%8.8x.\n", dev->name, csr12, csr5, csr14);
152
153         /* If NWay finished and we have a negotiated partner capability. */
154         if (tp->nway  &&  !tp->nwayset  &&  (csr12 & 0x7000) == 0x5000) {
155                 int setup_done = 0;
156                 int negotiated = tp->sym_advertise & (csr12 >> 16);
157                 tp->lpar = csr12 >> 16;
158                 tp->nwayset = 1;
159                 /* If partner cannot negotiate, it is 10Mbps Half Duplex */
160                 if (!(csr12 & 0x8000))          dev->if_port = 0;
161                 else if (negotiated & 0x0100)   dev->if_port = 5;
162                 else if (negotiated & 0x0080)   dev->if_port = 3;
163                 else if (negotiated & 0x0040)   dev->if_port = 4;
164                 else if (negotiated & 0x0020)   dev->if_port = 0;
165                 else {
166                         tp->nwayset = 0;
167                         if ((csr12 & 2) == 0  &&  (tp->sym_advertise & 0x0180))
168                                 dev->if_port = 3;
169                 }
170                 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
171
172                 if (tulip_debug > 1) {
173                         if (tp->nwayset)
174                                 printk(KERN_INFO "%s: Switching to %s based on link "
175                                            "negotiation %4.4x & %4.4x = %4.4x.\n",
176                                            dev->name, medianame[dev->if_port], tp->sym_advertise,
177                                            tp->lpar, negotiated);
178                         else
179                                 printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
180                                            " link beat status %4.4x.\n",
181                                            dev->name, medianame[dev->if_port], csr12);
182                 }
183
184                 if (tp->mtable) {
185                         int i;
186                         for (i = 0; i < tp->mtable->leafcount; i++)
187                                 if (tp->mtable->mleaf[i].media == dev->if_port) {
188                                         int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
189                                         tp->cur_index = i;
190                                         tulip_select_media(dev, startup);
191                                         setup_done = 1;
192                                         break;
193                                 }
194                 }
195                 if ( ! setup_done) {
196                         tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
197                         if (tp->full_duplex)
198                                 tp->csr6 |= 0x0200;
199                         iowrite32(1, ioaddr + CSR13);
200                 }
201 #if 0                                                   /* Restart shouldn't be needed. */
202                 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
203                 if (tulip_debug > 2)
204                         printk(KERN_DEBUG "%s:  Restarting Tx and Rx, CSR5 is %8.8x.\n",
205                                    dev->name, ioread32(ioaddr + CSR5));
206 #endif
207                 tulip_start_rxtx(tp);
208                 if (tulip_debug > 2)
209                         printk(KERN_DEBUG "%s:  Setting CSR6 %8.8x/%x CSR12 %8.8x.\n",
210                                    dev->name, tp->csr6, ioread32(ioaddr + CSR6),
211                                    ioread32(ioaddr + CSR12));
212         } else if ((tp->nwayset  &&  (csr5 & 0x08000000)
213                                 && (dev->if_port == 3  ||  dev->if_port == 5)
214                                 && (csr12 & 2) == 2) ||
215                            (tp->nway && (csr5 & (TPLnkFail)))) {
216                 /* Link blew? Maybe restart NWay. */
217                 del_timer_sync(&tp->timer);
218                 t21142_start_nway(dev);
219                 tp->timer.expires = RUN_AT(3*HZ);
220                 add_timer(&tp->timer);
221         } else if (dev->if_port == 3  ||  dev->if_port == 5) {
222                 if (tulip_debug > 1)
223                         printk(KERN_INFO"%s: 21143 %s link beat %s.\n",
224                                    dev->name, medianame[dev->if_port],
225                                    (csr12 & 2) ? "failed" : "good");
226                 if ((csr12 & 2)  &&  ! tp->medialock) {
227                         del_timer_sync(&tp->timer);
228                         t21142_start_nway(dev);
229                         tp->timer.expires = RUN_AT(3*HZ);
230                         add_timer(&tp->timer);
231                 } else if (dev->if_port == 5)
232                         iowrite32(csr14 & ~0x080, ioaddr + CSR14);
233         } else if (dev->if_port == 0  ||  dev->if_port == 4) {
234                 if ((csr12 & 4) == 0)
235                         printk(KERN_INFO"%s: 21143 10baseT link beat good.\n",
236                                    dev->name);
237         } else if (!(csr12 & 4)) {              /* 10mbps link beat good. */
238                 if (tulip_debug)
239                         printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
240                                    dev->name);
241                 dev->if_port = 0;
242         } else if (tp->nwayset) {
243                 if (tulip_debug)
244                         printk(KERN_INFO"%s: 21143 using NWay-set %s, csr6 %8.8x.\n",
245                                    dev->name, medianame[dev->if_port], tp->csr6);
246         } else {                /* 100mbps link beat good. */
247                 if (tulip_debug)
248                         printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
249                                    dev->name);
250                 dev->if_port = 3;
251                 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
252                 iowrite32(0x0003FF7F, ioaddr + CSR14);
253                 iowrite32(0x0301, ioaddr + CSR12);
254                 tulip_restart_rxtx(tp);
255         }
256 }
257
258