Commit | Line | Data |
---|---|---|
1da177e4 LT |
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-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 "tulip.h" | |
19 | ||
20 | ||
21 | void tulip_timer(unsigned long data) | |
22 | { | |
23 | struct net_device *dev = (struct net_device *)data; | |
24 | struct tulip_private *tp = netdev_priv(dev); | |
25 | void __iomem *ioaddr = tp->base_addr; | |
26 | u32 csr12 = ioread32(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], ioread32(ioaddr + CSR5), | |
33 | ioread32(ioaddr + CSR6), csr12, ioread32(ioaddr + CSR13), | |
34 | ioread32(ioaddr + CSR14), ioread32(ioaddr + CSR15)); | |
35 | } | |
36 | switch (tp->chip_id) { | |
37 | case DC21140: | |
38 | case DC21142: | |
39 | case MX98713: | |
40 | case COMPEX9881: | |
41 | case DM910X: | |
1da177e4 LT |
42 | default: { |
43 | struct medialeaf *mleaf; | |
44 | unsigned char *p; | |
45 | if (tp->mtable == NULL) { /* No EEPROM info, use generic code. */ | |
46 | /* Not much that can be done. | |
47 | Assume this a generic MII or SYM transceiver. */ | |
48 | next_tick = 60*HZ; | |
49 | if (tulip_debug > 2) | |
50 | printk(KERN_DEBUG "%s: network media monitor CSR6 %8.8x " | |
51 | "CSR12 0x%2.2x.\n", | |
52 | dev->name, ioread32(ioaddr + CSR6), csr12 & 0xff); | |
53 | break; | |
54 | } | |
55 | mleaf = &tp->mtable->mleaf[tp->cur_index]; | |
56 | p = mleaf->leafdata; | |
57 | switch (mleaf->type) { | |
58 | case 0: case 4: { | |
59 | /* Type 0 serial or 4 SYM transceiver. Check the link beat bit. */ | |
60 | int offset = mleaf->type == 4 ? 5 : 2; | |
61 | s8 bitnum = p[offset]; | |
62 | if (p[offset+1] & 0x80) { | |
63 | if (tulip_debug > 1) | |
64 | printk(KERN_DEBUG"%s: Transceiver monitor tick " | |
65 | "CSR12=%#2.2x, no media sense.\n", | |
66 | dev->name, csr12); | |
67 | if (mleaf->type == 4) { | |
68 | if (mleaf->media == 3 && (csr12 & 0x02)) | |
69 | goto select_next_media; | |
70 | } | |
71 | break; | |
72 | } | |
73 | if (tulip_debug > 2) | |
74 | printk(KERN_DEBUG "%s: Transceiver monitor tick: CSR12=%#2.2x" | |
75 | " bit %d is %d, expecting %d.\n", | |
76 | dev->name, csr12, (bitnum >> 1) & 7, | |
77 | (csr12 & (1 << ((bitnum >> 1) & 7))) != 0, | |
78 | (bitnum >= 0)); | |
79 | /* Check that the specified bit has the proper value. */ | |
80 | if ((bitnum < 0) != | |
81 | ((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) { | |
82 | if (tulip_debug > 2) | |
83 | printk(KERN_DEBUG "%s: Link beat detected for %s.\n", dev->name, | |
84 | medianame[mleaf->media & MEDIA_MASK]); | |
85 | if ((p[2] & 0x61) == 0x01) /* Bogus Znyx board. */ | |
86 | goto actually_mii; | |
87 | netif_carrier_on(dev); | |
88 | break; | |
89 | } | |
90 | netif_carrier_off(dev); | |
91 | if (tp->medialock) | |
92 | break; | |
93 | select_next_media: | |
94 | if (--tp->cur_index < 0) { | |
95 | /* We start again, but should instead look for default. */ | |
96 | tp->cur_index = tp->mtable->leafcount - 1; | |
97 | } | |
98 | dev->if_port = tp->mtable->mleaf[tp->cur_index].media; | |
99 | if (tulip_media_cap[dev->if_port] & MediaIsFD) | |
100 | goto select_next_media; /* Skip FD entries. */ | |
101 | if (tulip_debug > 1) | |
102 | printk(KERN_DEBUG "%s: No link beat on media %s," | |
103 | " trying transceiver type %s.\n", | |
104 | dev->name, medianame[mleaf->media & MEDIA_MASK], | |
105 | medianame[tp->mtable->mleaf[tp->cur_index].media]); | |
106 | tulip_select_media(dev, 0); | |
107 | /* Restart the transmit process. */ | |
108 | tulip_restart_rxtx(tp); | |
109 | next_tick = (24*HZ)/10; | |
110 | break; | |
111 | } | |
112 | case 1: case 3: /* 21140, 21142 MII */ | |
113 | actually_mii: | |
114 | if (tulip_check_duplex(dev) < 0) { | |
115 | netif_carrier_off(dev); | |
116 | next_tick = 3*HZ; | |
117 | } else { | |
118 | netif_carrier_on(dev); | |
119 | next_tick = 60*HZ; | |
120 | } | |
121 | break; | |
122 | case 2: /* 21142 serial block has no link beat. */ | |
123 | default: | |
124 | break; | |
125 | } | |
126 | } | |
127 | break; | |
128 | } | |
129 | /* mod_timer synchronizes us with potential add_timer calls | |
130 | * from interrupts. | |
131 | */ | |
132 | mod_timer(&tp->timer, RUN_AT(next_tick)); | |
133 | } | |
134 | ||
135 | ||
136 | void mxic_timer(unsigned long data) | |
137 | { | |
138 | struct net_device *dev = (struct net_device *)data; | |
139 | struct tulip_private *tp = netdev_priv(dev); | |
140 | void __iomem *ioaddr = tp->base_addr; | |
141 | int next_tick = 60*HZ; | |
142 | ||
143 | if (tulip_debug > 3) { | |
144 | printk(KERN_INFO"%s: MXIC negotiation status %8.8x.\n", dev->name, | |
145 | ioread32(ioaddr + CSR12)); | |
146 | } | |
147 | if (next_tick) { | |
148 | mod_timer(&tp->timer, RUN_AT(next_tick)); | |
149 | } | |
150 | } | |
151 | ||
152 | ||
153 | void comet_timer(unsigned long data) | |
154 | { | |
155 | struct net_device *dev = (struct net_device *)data; | |
156 | struct tulip_private *tp = netdev_priv(dev); | |
157 | int next_tick = 60*HZ; | |
158 | ||
159 | if (tulip_debug > 1) | |
160 | printk(KERN_DEBUG "%s: Comet link status %4.4x partner capability " | |
161 | "%4.4x.\n", | |
162 | dev->name, | |
163 | tulip_mdio_read(dev, tp->phys[0], 1), | |
164 | tulip_mdio_read(dev, tp->phys[0], 5)); | |
165 | /* mod_timer synchronizes us with potential add_timer calls | |
166 | * from interrupts. | |
167 | */ | |
168 | if (tulip_check_duplex(dev) < 0) | |
169 | { netif_carrier_off(dev); } | |
170 | else | |
171 | { netif_carrier_on(dev); } | |
172 | mod_timer(&tp->timer, RUN_AT(next_tick)); | |
173 | } | |
174 |