1 /*
2 	drivers/net/ethernet/dec/tulip/timer.c
3 
4 	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 
10 	Please submit bugs to http://bugzilla.kernel.org/ .
11 */
12 
13 
14 #include "tulip.h"
15 
16 
17 void tulip_media_task(struct work_struct *work)
18 {
19 	struct tulip_private *tp =
20 		container_of(work, struct tulip_private, media_work);
21 	struct net_device *dev = tp->dev;
22 	void __iomem *ioaddr = tp->base_addr;
23 	u32 csr12 = ioread32(ioaddr + CSR12);
24 	int next_tick = 2*HZ;
25 	unsigned long flags;
26 
27 	if (tulip_debug > 2) {
28 		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));
33 	}
34 	switch (tp->chip_id) {
35 	case DC21140:
36 	case DC21142:
37 	case MX98713:
38 	case COMPEX9881:
39 	case DM910X:
40 	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)
48 				netdev_dbg(dev, "network media monitor CSR6 %08x CSR12 0x%02x\n",
49 					   ioread32(ioaddr + CSR6),
50 					   csr12 & 0xff);
51 			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)
62 					netdev_dbg(dev, "Transceiver monitor tick CSR12=%#02x, no media sense\n",
63 						   csr12);
64 				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)
71 				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));
75 			/* 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)
79 					netdev_dbg(dev, "Link beat detected for %s\n",
80 						   medianame[mleaf->media & MEDIA_MASK]);
81 				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)
98 				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]);
101 			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 	}
124 
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 
133 	/* 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 
140 void 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) {
148 		dev_info(&dev->dev, "MXIC negotiation status %08x\n",
149 			 ioread32(ioaddr + CSR12));
150 	}
151 	if (next_tick) {
152 		mod_timer(&tp->timer, RUN_AT(next_tick));
153 	}
154 }
155 
156 
157 void comet_timer(unsigned long data)
158 {
159 	struct net_device *dev = (struct net_device *)data;
160 	struct tulip_private *tp = netdev_priv(dev);
161 	int next_tick = 2*HZ;
162 
163 	if (tulip_debug > 1)
164 		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));
167 	/* 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 
177