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