make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / drivers / net / tulip / timer.c
1 /*
2         drivers/net/tulip/timer.c
3
4         Maintained by Jeff Garzik <jgarzik@pobox.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.{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 "tulip.h"
18
19
20 void tulip_timer(unsigned long data)
21 {
22         struct net_device *dev = (struct net_device *)data;
23         struct tulip_private *tp = (struct tulip_private *)dev->priv;
24         long ioaddr = dev->base_addr;
25         u32 csr12 = inl(ioaddr + CSR12);
26         int next_tick = 2*HZ;
27
28         if (tulip_debug > 2) {
29                 printk(KERN_DEBUG "%s: Media selection tick, %s, status %8.8x mode"
30                            " %8.8x SIA %8.8x %8.8x %8.8x %8.8x.\n",
31                            dev->name, medianame[dev->if_port], inl(ioaddr + CSR5),
32                            inl(ioaddr + CSR6), csr12, inl(ioaddr + CSR13),
33                            inl(ioaddr + CSR14), inl(ioaddr + CSR15));
34         }
35         switch (tp->chip_id) {
36         case DC21040:
37                 if (!tp->medialock  &&  csr12 & 0x0002) { /* Network error */
38                         printk(KERN_INFO "%s: No link beat found.\n",
39                                    dev->name);
40                         dev->if_port = (dev->if_port == 2 ? 0 : 2);
41                         tulip_select_media(dev, 0);
42                         dev->trans_start = jiffies;
43                 }
44                 break;
45         case DC21041:
46                 if (tulip_debug > 2)
47                         printk(KERN_DEBUG "%s: 21041 media tick  CSR12 %8.8x.\n",
48                                    dev->name, csr12);
49                 if (tp->medialock) break;
50                 switch (dev->if_port) {
51                 case 0: case 3: case 4:
52                   if (csr12 & 0x0004) { /*LnkFail */
53                         /* 10baseT is dead.  Check for activity on alternate port. */
54                         tp->mediasense = 1;
55                         if (csr12 & 0x0200)
56                                 dev->if_port = 2;
57                         else
58                                 dev->if_port = 1;
59                         printk(KERN_INFO "%s: No 21041 10baseT link beat, Media switched to %s.\n",
60                                    dev->name, medianame[dev->if_port]);
61                         outl(0, ioaddr + CSR13); /* Reset */
62                         outl(t21041_csr14[dev->if_port], ioaddr + CSR14);
63                         outl(t21041_csr15[dev->if_port], ioaddr + CSR15);
64                         outl(t21041_csr13[dev->if_port], ioaddr + CSR13);
65                         next_tick = 10*HZ;                      /* 2.4 sec. */
66                   } else
67                         next_tick = 30*HZ;
68                   break;
69                 case 1:                                 /* 10base2 */
70                 case 2:                                 /* AUI */
71                         if (csr12 & 0x0100) {
72                                 next_tick = (30*HZ);                    /* 30 sec. */
73                                 tp->mediasense = 0;
74                         } else if ((csr12 & 0x0004) == 0) {
75                                 printk(KERN_INFO "%s: 21041 media switched to 10baseT.\n",
76                                            dev->name);
77                                 dev->if_port = 0;
78                                 tulip_select_media(dev, 0);
79                                 next_tick = (24*HZ)/10;                         /* 2.4 sec. */
80                         } else if (tp->mediasense || (csr12 & 0x0002)) {
81                                 dev->if_port = 3 - dev->if_port; /* Swap ports. */
82                                 tulip_select_media(dev, 0);
83                                 next_tick = 20*HZ;
84                         } else {
85                                 next_tick = 20*HZ;
86                         }
87                         break;
88                 }
89                 break;
90         case DC21140:
91         case DC21142:
92         case MX98713:
93         case COMPEX9881:
94         case DM910X:
95         default: {
96                 struct medialeaf *mleaf;
97                 unsigned char *p;
98                 if (tp->mtable == NULL) {       /* No EEPROM info, use generic code. */
99                         /* Not much that can be done.
100                            Assume this a generic MII or SYM transceiver. */
101                         next_tick = 60*HZ;
102                         if (tulip_debug > 2)
103                                 printk(KERN_DEBUG "%s: network media monitor CSR6 %8.8x "
104                                            "CSR12 0x%2.2x.\n",
105                                            dev->name, inl(ioaddr + CSR6), csr12 & 0xff);
106                         break;
107                 }
108                 mleaf = &tp->mtable->mleaf[tp->cur_index];
109                 p = mleaf->leafdata;
110                 switch (mleaf->type) {
111                 case 0: case 4: {
112                         /* Type 0 serial or 4 SYM transceiver.  Check the link beat bit. */
113                         int offset = mleaf->type == 4 ? 5 : 2;
114                         s8 bitnum = p[offset];
115                         if (p[offset+1] & 0x80) {
116                                 if (tulip_debug > 1)
117                                         printk(KERN_DEBUG"%s: Transceiver monitor tick "
118                                                    "CSR12=%#2.2x, no media sense.\n",
119                                                    dev->name, csr12);
120                                 if (mleaf->type == 4) {
121                                         if (mleaf->media == 3 && (csr12 & 0x02))
122                                                 goto select_next_media;
123                                 }
124                                 break;
125                         }
126                         if (tulip_debug > 2)
127                                 printk(KERN_DEBUG "%s: Transceiver monitor tick: CSR12=%#2.2x"
128                                            " bit %d is %d, expecting %d.\n",
129                                            dev->name, csr12, (bitnum >> 1) & 7,
130                                            (csr12 & (1 << ((bitnum >> 1) & 7))) != 0,
131                                            (bitnum >= 0));
132                         /* Check that the specified bit has the proper value. */
133                         if ((bitnum < 0) !=
134                                 ((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) {
135                                 if (tulip_debug > 2)
136                                         printk(KERN_DEBUG "%s: Link beat detected for %s.\n", dev->name,
137                                                medianame[mleaf->media & MEDIA_MASK]);
138                                 if ((p[2] & 0x61) == 0x01)      /* Bogus Znyx board. */
139                                         goto actually_mii;
140                                 /* netif_carrier_on(dev); */
141                                 break;
142                         }
143                         /* netif_carrier_off(dev); */
144                         if (tp->medialock)
145                                 break;
146           select_next_media:
147                         if (--tp->cur_index < 0) {
148                                 /* We start again, but should instead look for default. */
149                                 tp->cur_index = tp->mtable->leafcount - 1;
150                         }
151                         dev->if_port = tp->mtable->mleaf[tp->cur_index].media;
152                         if (tulip_media_cap[dev->if_port] & MediaIsFD)
153                                 goto select_next_media; /* Skip FD entries. */
154                         if (tulip_debug > 1)
155                                 printk(KERN_DEBUG "%s: No link beat on media %s,"
156                                        " trying transceiver type %s.\n",
157                                        dev->name, medianame[mleaf->media & MEDIA_MASK],
158                                        medianame[tp->mtable->mleaf[tp->cur_index].media]);
159                         tulip_select_media(dev, 0);
160                         /* Restart the transmit process. */
161                         tulip_restart_rxtx(tp);
162                         next_tick = (24*HZ)/10;
163                         break;
164                 }
165                 case 1:  case 3:                /* 21140, 21142 MII */
166                 actually_mii:
167                         if (tulip_check_duplex(dev) < 0)
168                                 { /* netif_carrier_off(dev); */ }
169                         else
170                                 { /* netif_carrier_on(dev); */ }
171                         next_tick = 60*HZ;
172                         break;
173                 case 2:                                 /* 21142 serial block has no link beat. */
174                 default:
175                         break;
176                 }
177         }
178         break;
179         }
180         /* mod_timer synchronizes us with potential add_timer calls
181          * from interrupts.
182          */
183         mod_timer(&tp->timer, RUN_AT(next_tick));
184 }
185
186
187 void mxic_timer(unsigned long data)
188 {
189         struct net_device *dev = (struct net_device *)data;
190         struct tulip_private *tp = (struct tulip_private *)dev->priv;
191         long ioaddr = dev->base_addr;
192         int next_tick = 60*HZ;
193
194         if (tulip_debug > 3) {
195                 printk(KERN_INFO"%s: MXIC negotiation status %8.8x.\n", dev->name,
196                            inl(ioaddr + CSR12));
197         }
198         if (next_tick) {
199                 mod_timer(&tp->timer, RUN_AT(next_tick));
200         }
201 }
202
203
204 void comet_timer(unsigned long data)
205 {
206         struct net_device *dev = (struct net_device *)data;
207         struct tulip_private *tp = (struct tulip_private *)dev->priv;
208         long ioaddr = dev->base_addr;
209         int next_tick = 60*HZ;
210
211         if (tulip_debug > 1)
212                 printk(KERN_DEBUG "%s: Comet link status %4.4x partner capability "
213                            "%4.4x.\n",
214                            dev->name, inl(ioaddr + 0xB8), inl(ioaddr + 0xC8));
215         /* mod_timer synchronizes us with potential add_timer calls
216          * from interrupts.
217          */
218         mod_timer(&tp->timer, RUN_AT(next_tick));
219 }
220