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