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