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