blob: 523d9dde50a2278fd9ddc9d47dd5c51458bf75d7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Paul Gortmaker3396c782012-01-27 13:36:01 +00002 drivers/net/ethernet/dec/tulip/timer.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 Copyright 2000,2001 The Linux Kernel Team
5 Written/copyright 1994-2001 by Donald Becker.
6
7 This software may be used and distributed according to the terms
8 of the GNU General Public License, incorporated herein by reference.
9
Grant Grundler78a65512008-06-05 00:38:55 -060010 Please submit bugs to http://bugzilla.kernel.org/ .
Linus Torvalds1da177e2005-04-16 15:20:36 -070011*/
12
Grant Grundler78a65512008-06-05 00:38:55 -060013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "tulip.h"
15
16
David Howellsc4028952006-11-22 14:57:56 +000017void tulip_media_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018{
David Howellsc4028952006-11-22 14:57:56 +000019 struct tulip_private *tp =
20 container_of(work, struct tulip_private, media_work);
21 struct net_device *dev = tp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 void __iomem *ioaddr = tp->base_addr;
23 u32 csr12 = ioread32(ioaddr + CSR12);
24 int next_tick = 2*HZ;
Francois Romieu0bb3cf72006-09-08 11:15:38 -070025 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27 if (tulip_debug > 2) {
Joe Perches726b65a2011-05-09 09:45:22 +000028 netdev_dbg(dev, "Media selection tick, %s, status %08x mode %08x SIA %08x %08x %08x %08x\n",
29 medianame[dev->if_port],
30 ioread32(ioaddr + CSR5), ioread32(ioaddr + CSR6),
31 csr12, ioread32(ioaddr + CSR13),
32 ioread32(ioaddr + CSR14), ioread32(ioaddr + CSR15));
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 }
34 switch (tp->chip_id) {
35 case DC21140:
36 case DC21142:
37 case MX98713:
38 case COMPEX9881:
39 case DM910X:
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 default: {
41 struct medialeaf *mleaf;
42 unsigned char *p;
43 if (tp->mtable == NULL) { /* No EEPROM info, use generic code. */
44 /* Not much that can be done.
45 Assume this a generic MII or SYM transceiver. */
46 next_tick = 60*HZ;
47 if (tulip_debug > 2)
Joe Perches726b65a2011-05-09 09:45:22 +000048 netdev_dbg(dev, "network media monitor CSR6 %08x CSR12 0x%02x\n",
49 ioread32(ioaddr + CSR6),
50 csr12 & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 break;
52 }
53 mleaf = &tp->mtable->mleaf[tp->cur_index];
54 p = mleaf->leafdata;
55 switch (mleaf->type) {
56 case 0: case 4: {
57 /* Type 0 serial or 4 SYM transceiver. Check the link beat bit. */
58 int offset = mleaf->type == 4 ? 5 : 2;
59 s8 bitnum = p[offset];
60 if (p[offset+1] & 0x80) {
61 if (tulip_debug > 1)
Joe Perches726b65a2011-05-09 09:45:22 +000062 netdev_dbg(dev, "Transceiver monitor tick CSR12=%#02x, no media sense\n",
63 csr12);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 if (mleaf->type == 4) {
65 if (mleaf->media == 3 && (csr12 & 0x02))
66 goto select_next_media;
67 }
68 break;
69 }
70 if (tulip_debug > 2)
Joe Perches726b65a2011-05-09 09:45:22 +000071 netdev_dbg(dev, "Transceiver monitor tick: CSR12=%#02x bit %d is %d, expecting %d\n",
72 csr12, (bitnum >> 1) & 7,
73 (csr12 & (1 << ((bitnum >> 1) & 7))) != 0,
74 (bitnum >= 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 /* Check that the specified bit has the proper value. */
76 if ((bitnum < 0) !=
77 ((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) {
78 if (tulip_debug > 2)
Joe Perches726b65a2011-05-09 09:45:22 +000079 netdev_dbg(dev, "Link beat detected for %s\n",
80 medianame[mleaf->media & MEDIA_MASK]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 if ((p[2] & 0x61) == 0x01) /* Bogus Znyx board. */
82 goto actually_mii;
83 netif_carrier_on(dev);
84 break;
85 }
86 netif_carrier_off(dev);
87 if (tp->medialock)
88 break;
89 select_next_media:
90 if (--tp->cur_index < 0) {
91 /* We start again, but should instead look for default. */
92 tp->cur_index = tp->mtable->leafcount - 1;
93 }
94 dev->if_port = tp->mtable->mleaf[tp->cur_index].media;
95 if (tulip_media_cap[dev->if_port] & MediaIsFD)
96 goto select_next_media; /* Skip FD entries. */
97 if (tulip_debug > 1)
Joe Perches726b65a2011-05-09 09:45:22 +000098 netdev_dbg(dev, "No link beat on media %s, trying transceiver type %s\n",
99 medianame[mleaf->media & MEDIA_MASK],
100 medianame[tp->mtable->mleaf[tp->cur_index].media]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 tulip_select_media(dev, 0);
102 /* Restart the transmit process. */
103 tulip_restart_rxtx(tp);
104 next_tick = (24*HZ)/10;
105 break;
106 }
107 case 1: case 3: /* 21140, 21142 MII */
108 actually_mii:
109 if (tulip_check_duplex(dev) < 0) {
110 netif_carrier_off(dev);
111 next_tick = 3*HZ;
112 } else {
113 netif_carrier_on(dev);
114 next_tick = 60*HZ;
115 }
116 break;
117 case 2: /* 21142 serial block has no link beat. */
118 default:
119 break;
120 }
121 }
122 break;
123 }
Francois Romieu0bb3cf72006-09-08 11:15:38 -0700124
125
126 spin_lock_irqsave(&tp->lock, flags);
127 if (tp->timeout_recovery) {
128 tulip_tx_timeout_complete(tp, ioaddr);
129 tp->timeout_recovery = 0;
130 }
131 spin_unlock_irqrestore(&tp->lock, flags);
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 /* mod_timer synchronizes us with potential add_timer calls
134 * from interrupts.
135 */
136 mod_timer(&tp->timer, RUN_AT(next_tick));
137}
138
139
140void mxic_timer(unsigned long data)
141{
142 struct net_device *dev = (struct net_device *)data;
143 struct tulip_private *tp = netdev_priv(dev);
144 void __iomem *ioaddr = tp->base_addr;
145 int next_tick = 60*HZ;
146
147 if (tulip_debug > 3) {
Joe Perches27146c42010-01-28 20:59:26 +0000148 dev_info(&dev->dev, "MXIC negotiation status %08x\n",
149 ioread32(ioaddr + CSR12));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151 if (next_tick) {
152 mod_timer(&tp->timer, RUN_AT(next_tick));
153 }
154}
155
156
157void comet_timer(unsigned long data)
158{
159 struct net_device *dev = (struct net_device *)data;
160 struct tulip_private *tp = netdev_priv(dev);
Ondrej Zary143fa2e2014-06-22 12:01:12 +0200161 int next_tick = 2*HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 if (tulip_debug > 1)
Joe Perches726b65a2011-05-09 09:45:22 +0000164 netdev_dbg(dev, "Comet link status %04x partner capability %04x\n",
165 tulip_mdio_read(dev, tp->phys[0], 1),
166 tulip_mdio_read(dev, tp->phys[0], 5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 /* mod_timer synchronizes us with potential add_timer calls
168 * from interrupts.
169 */
170 if (tulip_check_duplex(dev) < 0)
171 { netif_carrier_off(dev); }
172 else
173 { netif_carrier_on(dev); }
174 mod_timer(&tp->timer, RUN_AT(next_tick));
175}
176