]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * smc91x.c | |
3 | * This is a driver for SMSC's 91C9x/91C1xx single-chip Ethernet devices. | |
4 | * | |
5 | * Copyright (C) 1996 by Erik Stahlman | |
6 | * Copyright (C) 2001 Standard Microsystems Corporation | |
7 | * Developed by Simple Network Magic Corporation | |
8 | * Copyright (C) 2003 Monta Vista Software, Inc. | |
9 | * Unified SMC91x driver by Nicolas Pitre | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
0ab75ae8 | 22 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
1da177e4 LT |
23 | * |
24 | * Arguments: | |
25 | * io = for the base address | |
26 | * irq = for the IRQ | |
27 | * nowait = 0 for normal wait states, 1 eliminates additional wait states | |
28 | * | |
29 | * original author: | |
30 | * Erik Stahlman <erik@vt.edu> | |
31 | * | |
32 | * hardware multicast code: | |
33 | * Peter Cammaert <pc@denkart.be> | |
34 | * | |
35 | * contributors: | |
36 | * Daris A Nevil <dnevil@snmc.com> | |
2f82af08 | 37 | * Nicolas Pitre <nico@fluxnic.net> |
1da177e4 LT |
38 | * Russell King <rmk@arm.linux.org.uk> |
39 | * | |
40 | * History: | |
41 | * 08/20/00 Arnaldo Melo fix kfree(skb) in smc_hardware_send_packet | |
42 | * 12/15/00 Christian Jullien fix "Warning: kfree_skb on hard IRQ" | |
43 | * 03/16/01 Daris A Nevil modified smc9194.c for use with LAN91C111 | |
44 | * 08/22/01 Scott Anderson merge changes from smc9194 to smc91111 | |
45 | * 08/21/01 Pramod B Bhardwaj added support for RevB of LAN91C111 | |
46 | * 12/20/01 Jeff Sutherland initial port to Xscale PXA with DMA support | |
47 | * 04/07/03 Nicolas Pitre unified SMC91x driver, killed irq races, | |
48 | * more bus abstraction, big cleanup, etc. | |
49 | * 29/09/03 Russell King - add driver model support | |
50 | * - ethtool support | |
51 | * - convert to use generic MII interface | |
52 | * - add link up/down notification | |
53 | * - don't try to handle full negotiation in | |
54 | * smc_phy_configure | |
55 | * - clean up (and fix stack overrun) in PHY | |
56 | * MII read/write functions | |
57 | * 22/09/04 Nicolas Pitre big update (see commit log for details) | |
58 | */ | |
59 | static const char version[] = | |
6389aa45 | 60 | "smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@fluxnic.net>"; |
1da177e4 LT |
61 | |
62 | /* Debugging level */ | |
63 | #ifndef SMC_DEBUG | |
64 | #define SMC_DEBUG 0 | |
65 | #endif | |
66 | ||
67 | ||
1da177e4 LT |
68 | #include <linux/module.h> |
69 | #include <linux/kernel.h> | |
70 | #include <linux/sched.h> | |
1da177e4 LT |
71 | #include <linux/delay.h> |
72 | #include <linux/interrupt.h> | |
476c32c4 | 73 | #include <linux/irq.h> |
1da177e4 LT |
74 | #include <linux/errno.h> |
75 | #include <linux/ioport.h> | |
76 | #include <linux/crc32.h> | |
d052d1be | 77 | #include <linux/platform_device.h> |
1da177e4 LT |
78 | #include <linux/spinlock.h> |
79 | #include <linux/ethtool.h> | |
80 | #include <linux/mii.h> | |
81 | #include <linux/workqueue.h> | |
682a1694 | 82 | #include <linux/of.h> |
3f823c15 | 83 | #include <linux/of_device.h> |
7d2911c4 | 84 | #include <linux/of_gpio.h> |
1da177e4 LT |
85 | |
86 | #include <linux/netdevice.h> | |
87 | #include <linux/etherdevice.h> | |
88 | #include <linux/skbuff.h> | |
89 | ||
90 | #include <asm/io.h> | |
1da177e4 LT |
91 | |
92 | #include "smc91x.h" | |
93 | ||
b70661c7 | 94 | #if defined(CONFIG_ASSABET_NEPONSET) |
04b91701 | 95 | #include <mach/assabet.h> |
b70661c7 AB |
96 | #include <mach/neponset.h> |
97 | #endif | |
98 | ||
1da177e4 LT |
99 | #ifndef SMC_NOWAIT |
100 | # define SMC_NOWAIT 0 | |
101 | #endif | |
102 | static int nowait = SMC_NOWAIT; | |
103 | module_param(nowait, int, 0400); | |
104 | MODULE_PARM_DESC(nowait, "set to 1 for no wait state"); | |
105 | ||
106 | /* | |
107 | * Transmit timeout, default 5 seconds. | |
108 | */ | |
ea937560 | 109 | static int watchdog = 1000; |
1da177e4 LT |
110 | module_param(watchdog, int, 0400); |
111 | MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); | |
112 | ||
113 | MODULE_LICENSE("GPL"); | |
72abb461 | 114 | MODULE_ALIAS("platform:smc91x"); |
1da177e4 LT |
115 | |
116 | /* | |
117 | * The internal workings of the driver. If you are changing anything | |
118 | * here with the SMC stuff, you should have the datasheet and know | |
119 | * what you are doing. | |
120 | */ | |
121 | #define CARDNAME "smc91x" | |
122 | ||
123 | /* | |
124 | * Use power-down feature of the chip | |
125 | */ | |
126 | #define POWER_DOWN 1 | |
127 | ||
128 | /* | |
129 | * Wait time for memory to be free. This probably shouldn't be | |
130 | * tuned that much, as waiting for this means nothing else happens | |
131 | * in the system | |
132 | */ | |
133 | #define MEMORY_WAIT_TIME 16 | |
134 | ||
5d0571d9 NP |
135 | /* |
136 | * The maximum number of processing loops allowed for each call to the | |
6aa20a22 | 137 | * IRQ handler. |
5d0571d9 NP |
138 | */ |
139 | #define MAX_IRQ_LOOPS 8 | |
140 | ||
1da177e4 LT |
141 | /* |
142 | * This selects whether TX packets are sent one by one to the SMC91x internal | |
143 | * memory and throttled until transmission completes. This may prevent | |
144 | * RX overruns a litle by keeping much of the memory free for RX packets | |
145 | * but to the expense of reduced TX throughput and increased IRQ overhead. | |
146 | * Note this is not a cure for a too slow data bus or too high IRQ latency. | |
147 | */ | |
148 | #define THROTTLE_TX_PKTS 0 | |
149 | ||
150 | /* | |
151 | * The MII clock high/low times. 2x this number gives the MII clock period | |
152 | * in microseconds. (was 50, but this gives 6.4ms for each MII transaction!) | |
153 | */ | |
154 | #define MII_DELAY 1 | |
155 | ||
a450a685 ZSL |
156 | #define DBG(n, dev, fmt, ...) \ |
157 | do { \ | |
158 | if (SMC_DEBUG >= (n)) \ | |
159 | netdev_dbg(dev, fmt, ##__VA_ARGS__); \ | |
1da177e4 LT |
160 | } while (0) |
161 | ||
a450a685 ZSL |
162 | #define PRINTK(dev, fmt, ...) \ |
163 | do { \ | |
164 | if (SMC_DEBUG > 0) \ | |
165 | netdev_info(dev, fmt, ##__VA_ARGS__); \ | |
166 | else \ | |
167 | netdev_dbg(dev, fmt, ##__VA_ARGS__); \ | |
168 | } while (0) | |
1da177e4 LT |
169 | |
170 | #if SMC_DEBUG > 3 | |
171 | static void PRINT_PKT(u_char *buf, int length) | |
172 | { | |
173 | int i; | |
174 | int remainder; | |
175 | int lines; | |
176 | ||
177 | lines = length / 16; | |
178 | remainder = length % 16; | |
179 | ||
180 | for (i = 0; i < lines ; i ++) { | |
181 | int cur; | |
6389aa45 | 182 | printk(KERN_DEBUG); |
1da177e4 LT |
183 | for (cur = 0; cur < 8; cur++) { |
184 | u_char a, b; | |
185 | a = *buf++; | |
186 | b = *buf++; | |
6389aa45 | 187 | pr_cont("%02x%02x ", a, b); |
1da177e4 | 188 | } |
6389aa45 | 189 | pr_cont("\n"); |
1da177e4 | 190 | } |
6389aa45 | 191 | printk(KERN_DEBUG); |
1da177e4 LT |
192 | for (i = 0; i < remainder/2 ; i++) { |
193 | u_char a, b; | |
194 | a = *buf++; | |
195 | b = *buf++; | |
6389aa45 | 196 | pr_cont("%02x%02x ", a, b); |
1da177e4 | 197 | } |
6389aa45 | 198 | pr_cont("\n"); |
1da177e4 LT |
199 | } |
200 | #else | |
a450a685 | 201 | static inline void PRINT_PKT(u_char *buf, int length) { } |
1da177e4 LT |
202 | #endif |
203 | ||
204 | ||
205 | /* this enables an interrupt in the interrupt mask register */ | |
cfdfa865 | 206 | #define SMC_ENABLE_INT(lp, x) do { \ |
1da177e4 | 207 | unsigned char mask; \ |
8ff499e4 DD |
208 | unsigned long smc_enable_flags; \ |
209 | spin_lock_irqsave(&lp->lock, smc_enable_flags); \ | |
cfdfa865 | 210 | mask = SMC_GET_INT_MASK(lp); \ |
1da177e4 | 211 | mask |= (x); \ |
cfdfa865 | 212 | SMC_SET_INT_MASK(lp, mask); \ |
8ff499e4 | 213 | spin_unlock_irqrestore(&lp->lock, smc_enable_flags); \ |
1da177e4 LT |
214 | } while (0) |
215 | ||
216 | /* this disables an interrupt from the interrupt mask register */ | |
cfdfa865 | 217 | #define SMC_DISABLE_INT(lp, x) do { \ |
1da177e4 | 218 | unsigned char mask; \ |
8ff499e4 DD |
219 | unsigned long smc_disable_flags; \ |
220 | spin_lock_irqsave(&lp->lock, smc_disable_flags); \ | |
cfdfa865 | 221 | mask = SMC_GET_INT_MASK(lp); \ |
1da177e4 | 222 | mask &= ~(x); \ |
cfdfa865 | 223 | SMC_SET_INT_MASK(lp, mask); \ |
8ff499e4 | 224 | spin_unlock_irqrestore(&lp->lock, smc_disable_flags); \ |
1da177e4 LT |
225 | } while (0) |
226 | ||
227 | /* | |
228 | * Wait while MMU is busy. This is usually in the order of a few nanosecs | |
229 | * if at all, but let's avoid deadlocking the system if the hardware | |
230 | * decides to go south. | |
231 | */ | |
cfdfa865 MD |
232 | #define SMC_WAIT_MMU_BUSY(lp) do { \ |
233 | if (unlikely(SMC_GET_MMU_CMD(lp) & MC_BUSY)) { \ | |
1da177e4 | 234 | unsigned long timeout = jiffies + 2; \ |
cfdfa865 | 235 | while (SMC_GET_MMU_CMD(lp) & MC_BUSY) { \ |
1da177e4 | 236 | if (time_after(jiffies, timeout)) { \ |
6389aa45 BB |
237 | netdev_dbg(dev, "timeout %s line %d\n", \ |
238 | __FILE__, __LINE__); \ | |
1da177e4 LT |
239 | break; \ |
240 | } \ | |
241 | cpu_relax(); \ | |
242 | } \ | |
243 | } \ | |
244 | } while (0) | |
245 | ||
246 | ||
247 | /* | |
248 | * this does a soft reset on the device | |
249 | */ | |
250 | static void smc_reset(struct net_device *dev) | |
251 | { | |
252 | struct smc_local *lp = netdev_priv(dev); | |
253 | void __iomem *ioaddr = lp->base; | |
254 | unsigned int ctl, cfg; | |
be83668a | 255 | struct sk_buff *pending_skb; |
1da177e4 | 256 | |
6389aa45 | 257 | DBG(2, dev, "%s\n", __func__); |
1da177e4 | 258 | |
be83668a | 259 | /* Disable all interrupts, block TX tasklet */ |
76cb4fe7 | 260 | spin_lock_irq(&lp->lock); |
cfdfa865 MD |
261 | SMC_SELECT_BANK(lp, 2); |
262 | SMC_SET_INT_MASK(lp, 0); | |
be83668a NP |
263 | pending_skb = lp->pending_tx_skb; |
264 | lp->pending_tx_skb = NULL; | |
76cb4fe7 | 265 | spin_unlock_irq(&lp->lock); |
1da177e4 | 266 | |
be83668a NP |
267 | /* free any pending tx skb */ |
268 | if (pending_skb) { | |
269 | dev_kfree_skb(pending_skb); | |
09f75cd7 JG |
270 | dev->stats.tx_errors++; |
271 | dev->stats.tx_aborted_errors++; | |
be83668a NP |
272 | } |
273 | ||
1da177e4 LT |
274 | /* |
275 | * This resets the registers mostly to defaults, but doesn't | |
276 | * affect EEPROM. That seems unnecessary | |
277 | */ | |
cfdfa865 MD |
278 | SMC_SELECT_BANK(lp, 0); |
279 | SMC_SET_RCR(lp, RCR_SOFTRST); | |
1da177e4 LT |
280 | |
281 | /* | |
282 | * Setup the Configuration Register | |
283 | * This is necessary because the CONFIG_REG is not affected | |
284 | * by a soft reset | |
285 | */ | |
cfdfa865 | 286 | SMC_SELECT_BANK(lp, 1); |
1da177e4 LT |
287 | |
288 | cfg = CONFIG_DEFAULT; | |
289 | ||
290 | /* | |
291 | * Setup for fast accesses if requested. If the card/system | |
292 | * can't handle it then there will be no recovery except for | |
293 | * a hard reset or power cycle | |
294 | */ | |
c4f0e767 | 295 | if (lp->cfg.flags & SMC91X_NOWAIT) |
1da177e4 LT |
296 | cfg |= CONFIG_NO_WAIT; |
297 | ||
298 | /* | |
299 | * Release from possible power-down state | |
300 | * Configuration register is not affected by Soft Reset | |
301 | */ | |
302 | cfg |= CONFIG_EPH_POWER_EN; | |
303 | ||
cfdfa865 | 304 | SMC_SET_CONFIG(lp, cfg); |
1da177e4 LT |
305 | |
306 | /* this should pause enough for the chip to be happy */ | |
307 | /* | |
308 | * elaborate? What does the chip _need_? --jgarzik | |
309 | * | |
310 | * This seems to be undocumented, but something the original | |
311 | * driver(s) have always done. Suspect undocumented timing | |
312 | * info/determined empirically. --rmk | |
313 | */ | |
314 | udelay(1); | |
315 | ||
316 | /* Disable transmit and receive functionality */ | |
cfdfa865 MD |
317 | SMC_SELECT_BANK(lp, 0); |
318 | SMC_SET_RCR(lp, RCR_CLEAR); | |
319 | SMC_SET_TCR(lp, TCR_CLEAR); | |
1da177e4 | 320 | |
cfdfa865 MD |
321 | SMC_SELECT_BANK(lp, 1); |
322 | ctl = SMC_GET_CTL(lp) | CTL_LE_ENABLE; | |
1da177e4 LT |
323 | |
324 | /* | |
325 | * Set the control register to automatically release successfully | |
326 | * transmitted packets, to make the best use out of our limited | |
327 | * memory | |
328 | */ | |
329 | if(!THROTTLE_TX_PKTS) | |
330 | ctl |= CTL_AUTO_RELEASE; | |
331 | else | |
332 | ctl &= ~CTL_AUTO_RELEASE; | |
cfdfa865 | 333 | SMC_SET_CTL(lp, ctl); |
1da177e4 LT |
334 | |
335 | /* Reset the MMU */ | |
cfdfa865 MD |
336 | SMC_SELECT_BANK(lp, 2); |
337 | SMC_SET_MMU_CMD(lp, MC_RESET); | |
338 | SMC_WAIT_MMU_BUSY(lp); | |
1da177e4 LT |
339 | } |
340 | ||
341 | /* | |
342 | * Enable Interrupts, Receive, and Transmit | |
343 | */ | |
344 | static void smc_enable(struct net_device *dev) | |
345 | { | |
346 | struct smc_local *lp = netdev_priv(dev); | |
347 | void __iomem *ioaddr = lp->base; | |
348 | int mask; | |
349 | ||
6389aa45 | 350 | DBG(2, dev, "%s\n", __func__); |
1da177e4 LT |
351 | |
352 | /* see the header file for options in TCR/RCR DEFAULT */ | |
cfdfa865 MD |
353 | SMC_SELECT_BANK(lp, 0); |
354 | SMC_SET_TCR(lp, lp->tcr_cur_mode); | |
355 | SMC_SET_RCR(lp, lp->rcr_cur_mode); | |
1da177e4 | 356 | |
cfdfa865 MD |
357 | SMC_SELECT_BANK(lp, 1); |
358 | SMC_SET_MAC_ADDR(lp, dev->dev_addr); | |
1da177e4 LT |
359 | |
360 | /* now, enable interrupts */ | |
361 | mask = IM_EPH_INT|IM_RX_OVRN_INT|IM_RCV_INT; | |
362 | if (lp->version >= (CHIP_91100 << 4)) | |
363 | mask |= IM_MDINT; | |
cfdfa865 MD |
364 | SMC_SELECT_BANK(lp, 2); |
365 | SMC_SET_INT_MASK(lp, mask); | |
1da177e4 LT |
366 | |
367 | /* | |
368 | * From this point the register bank must _NOT_ be switched away | |
369 | * to something else than bank 2 without proper locking against | |
370 | * races with any tasklet or interrupt handlers until smc_shutdown() | |
371 | * or smc_reset() is called. | |
372 | */ | |
373 | } | |
374 | ||
375 | /* | |
376 | * this puts the device in an inactive state | |
377 | */ | |
378 | static void smc_shutdown(struct net_device *dev) | |
379 | { | |
380 | struct smc_local *lp = netdev_priv(dev); | |
381 | void __iomem *ioaddr = lp->base; | |
be83668a | 382 | struct sk_buff *pending_skb; |
1da177e4 | 383 | |
6389aa45 | 384 | DBG(2, dev, "%s: %s\n", CARDNAME, __func__); |
1da177e4 LT |
385 | |
386 | /* no more interrupts for me */ | |
76cb4fe7 | 387 | spin_lock_irq(&lp->lock); |
cfdfa865 MD |
388 | SMC_SELECT_BANK(lp, 2); |
389 | SMC_SET_INT_MASK(lp, 0); | |
be83668a NP |
390 | pending_skb = lp->pending_tx_skb; |
391 | lp->pending_tx_skb = NULL; | |
76cb4fe7 | 392 | spin_unlock_irq(&lp->lock); |
be83668a NP |
393 | if (pending_skb) |
394 | dev_kfree_skb(pending_skb); | |
1da177e4 LT |
395 | |
396 | /* and tell the card to stay away from that nasty outside world */ | |
cfdfa865 MD |
397 | SMC_SELECT_BANK(lp, 0); |
398 | SMC_SET_RCR(lp, RCR_CLEAR); | |
399 | SMC_SET_TCR(lp, TCR_CLEAR); | |
1da177e4 LT |
400 | |
401 | #ifdef POWER_DOWN | |
402 | /* finally, shut the chip down */ | |
cfdfa865 MD |
403 | SMC_SELECT_BANK(lp, 1); |
404 | SMC_SET_CONFIG(lp, SMC_GET_CONFIG(lp) & ~CONFIG_EPH_POWER_EN); | |
1da177e4 LT |
405 | #endif |
406 | } | |
407 | ||
408 | /* | |
409 | * This is the procedure to handle the receipt of a packet. | |
410 | */ | |
411 | static inline void smc_rcv(struct net_device *dev) | |
412 | { | |
413 | struct smc_local *lp = netdev_priv(dev); | |
414 | void __iomem *ioaddr = lp->base; | |
415 | unsigned int packet_number, status, packet_len; | |
416 | ||
6389aa45 | 417 | DBG(3, dev, "%s\n", __func__); |
1da177e4 | 418 | |
cfdfa865 | 419 | packet_number = SMC_GET_RXFIFO(lp); |
1da177e4 | 420 | if (unlikely(packet_number & RXFIFO_REMPTY)) { |
6389aa45 | 421 | PRINTK(dev, "smc_rcv with nothing on FIFO.\n"); |
1da177e4 LT |
422 | return; |
423 | } | |
424 | ||
425 | /* read from start of packet */ | |
cfdfa865 | 426 | SMC_SET_PTR(lp, PTR_READ | PTR_RCV | PTR_AUTOINC); |
1da177e4 LT |
427 | |
428 | /* First two words are status and packet length */ | |
cfdfa865 | 429 | SMC_GET_PKT_HDR(lp, status, packet_len); |
1da177e4 | 430 | packet_len &= 0x07ff; /* mask off top bits */ |
6389aa45 BB |
431 | DBG(2, dev, "RX PNR 0x%x STATUS 0x%04x LENGTH 0x%04x (%d)\n", |
432 | packet_number, status, packet_len, packet_len); | |
1da177e4 LT |
433 | |
434 | back: | |
435 | if (unlikely(packet_len < 6 || status & RS_ERRORS)) { | |
436 | if (status & RS_TOOLONG && packet_len <= (1514 + 4 + 6)) { | |
437 | /* accept VLAN packets */ | |
438 | status &= ~RS_TOOLONG; | |
439 | goto back; | |
440 | } | |
441 | if (packet_len < 6) { | |
442 | /* bloody hardware */ | |
6389aa45 BB |
443 | netdev_err(dev, "fubar (rxlen %u status %x\n", |
444 | packet_len, status); | |
1da177e4 LT |
445 | status |= RS_TOOSHORT; |
446 | } | |
cfdfa865 MD |
447 | SMC_WAIT_MMU_BUSY(lp); |
448 | SMC_SET_MMU_CMD(lp, MC_RELEASE); | |
09f75cd7 | 449 | dev->stats.rx_errors++; |
1da177e4 | 450 | if (status & RS_ALGNERR) |
09f75cd7 | 451 | dev->stats.rx_frame_errors++; |
1da177e4 | 452 | if (status & (RS_TOOSHORT | RS_TOOLONG)) |
09f75cd7 | 453 | dev->stats.rx_length_errors++; |
1da177e4 | 454 | if (status & RS_BADCRC) |
09f75cd7 | 455 | dev->stats.rx_crc_errors++; |
1da177e4 LT |
456 | } else { |
457 | struct sk_buff *skb; | |
458 | unsigned char *data; | |
459 | unsigned int data_len; | |
460 | ||
461 | /* set multicast stats */ | |
462 | if (status & RS_MULTICAST) | |
09f75cd7 | 463 | dev->stats.multicast++; |
1da177e4 LT |
464 | |
465 | /* | |
466 | * Actual payload is packet_len - 6 (or 5 if odd byte). | |
467 | * We want skb_reserve(2) and the final ctrl word | |
468 | * (2 bytes, possibly containing the payload odd byte). | |
469 | * Furthermore, we add 2 bytes to allow rounding up to | |
470 | * multiple of 4 bytes on 32 bit buses. | |
471 | * Hence packet_len - 6 + 2 + 2 + 2. | |
472 | */ | |
dae2e9f4 | 473 | skb = netdev_alloc_skb(dev, packet_len); |
1da177e4 | 474 | if (unlikely(skb == NULL)) { |
cfdfa865 MD |
475 | SMC_WAIT_MMU_BUSY(lp); |
476 | SMC_SET_MMU_CMD(lp, MC_RELEASE); | |
09f75cd7 | 477 | dev->stats.rx_dropped++; |
1da177e4 LT |
478 | return; |
479 | } | |
480 | ||
481 | /* Align IP header to 32 bits */ | |
482 | skb_reserve(skb, 2); | |
483 | ||
484 | /* BUG: the LAN91C111 rev A never sets this bit. Force it. */ | |
485 | if (lp->version == 0x90) | |
486 | status |= RS_ODDFRAME; | |
487 | ||
488 | /* | |
489 | * If odd length: packet_len - 5, | |
490 | * otherwise packet_len - 6. | |
491 | * With the trailing ctrl byte it's packet_len - 4. | |
492 | */ | |
493 | data_len = packet_len - ((status & RS_ODDFRAME) ? 5 : 6); | |
494 | data = skb_put(skb, data_len); | |
cfdfa865 | 495 | SMC_PULL_DATA(lp, data, packet_len - 4); |
1da177e4 | 496 | |
cfdfa865 MD |
497 | SMC_WAIT_MMU_BUSY(lp); |
498 | SMC_SET_MMU_CMD(lp, MC_RELEASE); | |
1da177e4 LT |
499 | |
500 | PRINT_PKT(data, packet_len - 4); | |
501 | ||
1da177e4 LT |
502 | skb->protocol = eth_type_trans(skb, dev); |
503 | netif_rx(skb); | |
09f75cd7 JG |
504 | dev->stats.rx_packets++; |
505 | dev->stats.rx_bytes += data_len; | |
1da177e4 LT |
506 | } |
507 | } | |
508 | ||
509 | #ifdef CONFIG_SMP | |
510 | /* | |
511 | * On SMP we have the following problem: | |
512 | * | |
513 | * A = smc_hardware_send_pkt() | |
514 | * B = smc_hard_start_xmit() | |
515 | * C = smc_interrupt() | |
516 | * | |
517 | * A and B can never be executed simultaneously. However, at least on UP, | |
518 | * it is possible (and even desirable) for C to interrupt execution of | |
519 | * A or B in order to have better RX reliability and avoid overruns. | |
520 | * C, just like A and B, must have exclusive access to the chip and | |
521 | * each of them must lock against any other concurrent access. | |
522 | * Unfortunately this is not possible to have C suspend execution of A or | |
523 | * B taking place on another CPU. On UP this is no an issue since A and B | |
524 | * are run from softirq context and C from hard IRQ context, and there is | |
525 | * no other CPU where concurrent access can happen. | |
526 | * If ever there is a way to force at least B and C to always be executed | |
527 | * on the same CPU then we could use read/write locks to protect against | |
528 | * any other concurrent access and C would always interrupt B. But life | |
529 | * isn't that easy in a SMP world... | |
530 | */ | |
8ff499e4 | 531 | #define smc_special_trylock(lock, flags) \ |
1da177e4 LT |
532 | ({ \ |
533 | int __ret; \ | |
8ff499e4 | 534 | local_irq_save(flags); \ |
1da177e4 LT |
535 | __ret = spin_trylock(lock); \ |
536 | if (!__ret) \ | |
8ff499e4 | 537 | local_irq_restore(flags); \ |
1da177e4 LT |
538 | __ret; \ |
539 | }) | |
0b4f2928 | 540 | #define smc_special_lock(lock, flags) spin_lock_irqsave(lock, flags) |
8ff499e4 | 541 | #define smc_special_unlock(lock, flags) spin_unlock_irqrestore(lock, flags) |
1da177e4 | 542 | #else |
e3ebd894 | 543 | #define smc_special_trylock(lock, flags) ((void)flags, true) |
fd0775bf MF |
544 | #define smc_special_lock(lock, flags) do { flags = 0; } while (0) |
545 | #define smc_special_unlock(lock, flags) do { flags = 0; } while (0) | |
1da177e4 LT |
546 | #endif |
547 | ||
548 | /* | |
549 | * This is called to actually send a packet to the chip. | |
550 | */ | |
551 | static void smc_hardware_send_pkt(unsigned long data) | |
552 | { | |
553 | struct net_device *dev = (struct net_device *)data; | |
554 | struct smc_local *lp = netdev_priv(dev); | |
555 | void __iomem *ioaddr = lp->base; | |
556 | struct sk_buff *skb; | |
557 | unsigned int packet_no, len; | |
558 | unsigned char *buf; | |
8ff499e4 | 559 | unsigned long flags; |
1da177e4 | 560 | |
6389aa45 | 561 | DBG(3, dev, "%s\n", __func__); |
1da177e4 | 562 | |
8ff499e4 | 563 | if (!smc_special_trylock(&lp->lock, flags)) { |
1da177e4 LT |
564 | netif_stop_queue(dev); |
565 | tasklet_schedule(&lp->tx_task); | |
566 | return; | |
567 | } | |
568 | ||
569 | skb = lp->pending_tx_skb; | |
be83668a | 570 | if (unlikely(!skb)) { |
8ff499e4 | 571 | smc_special_unlock(&lp->lock, flags); |
be83668a NP |
572 | return; |
573 | } | |
1da177e4 | 574 | lp->pending_tx_skb = NULL; |
be83668a | 575 | |
cfdfa865 | 576 | packet_no = SMC_GET_AR(lp); |
1da177e4 | 577 | if (unlikely(packet_no & AR_FAILED)) { |
6389aa45 | 578 | netdev_err(dev, "Memory allocation failed.\n"); |
09f75cd7 JG |
579 | dev->stats.tx_errors++; |
580 | dev->stats.tx_fifo_errors++; | |
8ff499e4 | 581 | smc_special_unlock(&lp->lock, flags); |
1da177e4 LT |
582 | goto done; |
583 | } | |
584 | ||
585 | /* point to the beginning of the packet */ | |
cfdfa865 MD |
586 | SMC_SET_PN(lp, packet_no); |
587 | SMC_SET_PTR(lp, PTR_AUTOINC); | |
1da177e4 LT |
588 | |
589 | buf = skb->data; | |
590 | len = skb->len; | |
6389aa45 BB |
591 | DBG(2, dev, "TX PNR 0x%x LENGTH 0x%04x (%d) BUF 0x%p\n", |
592 | packet_no, len, len, buf); | |
1da177e4 LT |
593 | PRINT_PKT(buf, len); |
594 | ||
595 | /* | |
596 | * Send the packet length (+6 for status words, length, and ctl. | |
597 | * The card will pad to 64 bytes with zeroes if packet is too small. | |
598 | */ | |
cfdfa865 | 599 | SMC_PUT_PKT_HDR(lp, 0, len + 6); |
1da177e4 LT |
600 | |
601 | /* send the actual data */ | |
cfdfa865 | 602 | SMC_PUSH_DATA(lp, buf, len & ~1); |
1da177e4 LT |
603 | |
604 | /* Send final ctl word with the last byte if there is one */ | |
d09d747a RJ |
605 | SMC_outw(lp, ((len & 1) ? (0x2000 | buf[len - 1]) : 0), ioaddr, |
606 | DATA_REG(lp)); | |
1da177e4 LT |
607 | |
608 | /* | |
ea937560 NP |
609 | * If THROTTLE_TX_PKTS is set, we stop the queue here. This will |
610 | * have the effect of having at most one packet queued for TX | |
611 | * in the chip's memory at all time. | |
612 | * | |
613 | * If THROTTLE_TX_PKTS is not set then the queue is stopped only | |
614 | * when memory allocation (MC_ALLOC) does not succeed right away. | |
1da177e4 | 615 | */ |
ea937560 | 616 | if (THROTTLE_TX_PKTS) |
1da177e4 LT |
617 | netif_stop_queue(dev); |
618 | ||
619 | /* queue the packet for TX */ | |
cfdfa865 | 620 | SMC_SET_MMU_CMD(lp, MC_ENQUEUE); |
8ff499e4 | 621 | smc_special_unlock(&lp->lock, flags); |
1da177e4 | 622 | |
860e9538 | 623 | netif_trans_update(dev); |
09f75cd7 JG |
624 | dev->stats.tx_packets++; |
625 | dev->stats.tx_bytes += len; | |
1da177e4 | 626 | |
cfdfa865 | 627 | SMC_ENABLE_INT(lp, IM_TX_INT | IM_TX_EMPTY_INT); |
1da177e4 LT |
628 | |
629 | done: if (!THROTTLE_TX_PKTS) | |
630 | netif_wake_queue(dev); | |
631 | ||
4b61fe26 | 632 | dev_consume_skb_any(skb); |
1da177e4 LT |
633 | } |
634 | ||
635 | /* | |
636 | * Since I am not sure if I will have enough room in the chip's ram | |
637 | * to store the packet, I call this routine which either sends it | |
638 | * now, or set the card to generates an interrupt when ready | |
639 | * for the packet. | |
640 | */ | |
4107662b Y |
641 | static netdev_tx_t |
642 | smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
1da177e4 LT |
643 | { |
644 | struct smc_local *lp = netdev_priv(dev); | |
645 | void __iomem *ioaddr = lp->base; | |
646 | unsigned int numPages, poll_count, status; | |
8ff499e4 | 647 | unsigned long flags; |
1da177e4 | 648 | |
6389aa45 | 649 | DBG(3, dev, "%s\n", __func__); |
1da177e4 LT |
650 | |
651 | BUG_ON(lp->pending_tx_skb != NULL); | |
1da177e4 LT |
652 | |
653 | /* | |
654 | * The MMU wants the number of pages to be the number of 256 bytes | |
655 | * 'pages', minus 1 (since a packet can't ever have 0 pages :)) | |
656 | * | |
657 | * The 91C111 ignores the size bits, but earlier models don't. | |
658 | * | |
659 | * Pkt size for allocating is data length +6 (for additional status | |
660 | * words, length and ctl) | |
661 | * | |
662 | * If odd size then last byte is included in ctl word. | |
663 | */ | |
664 | numPages = ((skb->len & ~1) + (6 - 1)) >> 8; | |
665 | if (unlikely(numPages > 7)) { | |
6389aa45 | 666 | netdev_warn(dev, "Far too big packet error.\n"); |
09f75cd7 JG |
667 | dev->stats.tx_errors++; |
668 | dev->stats.tx_dropped++; | |
4b61fe26 | 669 | dev_kfree_skb_any(skb); |
6ed10654 | 670 | return NETDEV_TX_OK; |
1da177e4 LT |
671 | } |
672 | ||
8ff499e4 | 673 | smc_special_lock(&lp->lock, flags); |
1da177e4 LT |
674 | |
675 | /* now, try to allocate the memory */ | |
cfdfa865 | 676 | SMC_SET_MMU_CMD(lp, MC_ALLOC | numPages); |
1da177e4 LT |
677 | |
678 | /* | |
679 | * Poll the chip for a short amount of time in case the | |
680 | * allocation succeeds quickly. | |
681 | */ | |
682 | poll_count = MEMORY_WAIT_TIME; | |
683 | do { | |
cfdfa865 | 684 | status = SMC_GET_INT(lp); |
1da177e4 | 685 | if (status & IM_ALLOC_INT) { |
cfdfa865 | 686 | SMC_ACK_INT(lp, IM_ALLOC_INT); |
1da177e4 LT |
687 | break; |
688 | } | |
689 | } while (--poll_count); | |
690 | ||
8ff499e4 | 691 | smc_special_unlock(&lp->lock, flags); |
1da177e4 | 692 | |
be83668a | 693 | lp->pending_tx_skb = skb; |
1da177e4 LT |
694 | if (!poll_count) { |
695 | /* oh well, wait until the chip finds memory later */ | |
696 | netif_stop_queue(dev); | |
6389aa45 | 697 | DBG(2, dev, "TX memory allocation deferred.\n"); |
cfdfa865 | 698 | SMC_ENABLE_INT(lp, IM_ALLOC_INT); |
1da177e4 LT |
699 | } else { |
700 | /* | |
701 | * Allocation succeeded: push packet to the chip's own memory | |
702 | * immediately. | |
6aa20a22 | 703 | */ |
1da177e4 LT |
704 | smc_hardware_send_pkt((unsigned long)dev); |
705 | } | |
706 | ||
6ed10654 | 707 | return NETDEV_TX_OK; |
1da177e4 LT |
708 | } |
709 | ||
710 | /* | |
711 | * This handles a TX interrupt, which is only called when: | |
712 | * - a TX error occurred, or | |
713 | * - CTL_AUTO_RELEASE is not set and TX of a packet completed. | |
714 | */ | |
715 | static void smc_tx(struct net_device *dev) | |
716 | { | |
717 | struct smc_local *lp = netdev_priv(dev); | |
718 | void __iomem *ioaddr = lp->base; | |
719 | unsigned int saved_packet, packet_no, tx_status, pkt_len; | |
720 | ||
6389aa45 | 721 | DBG(3, dev, "%s\n", __func__); |
1da177e4 LT |
722 | |
723 | /* If the TX FIFO is empty then nothing to do */ | |
cfdfa865 | 724 | packet_no = SMC_GET_TXFIFO(lp); |
1da177e4 | 725 | if (unlikely(packet_no & TXFIFO_TEMPTY)) { |
6389aa45 | 726 | PRINTK(dev, "smc_tx with nothing on FIFO.\n"); |
1da177e4 LT |
727 | return; |
728 | } | |
729 | ||
730 | /* select packet to read from */ | |
cfdfa865 MD |
731 | saved_packet = SMC_GET_PN(lp); |
732 | SMC_SET_PN(lp, packet_no); | |
1da177e4 LT |
733 | |
734 | /* read the first word (status word) from this packet */ | |
cfdfa865 MD |
735 | SMC_SET_PTR(lp, PTR_AUTOINC | PTR_READ); |
736 | SMC_GET_PKT_HDR(lp, tx_status, pkt_len); | |
6389aa45 BB |
737 | DBG(2, dev, "TX STATUS 0x%04x PNR 0x%02x\n", |
738 | tx_status, packet_no); | |
1da177e4 | 739 | |
8de90115 | 740 | if (!(tx_status & ES_TX_SUC)) |
09f75cd7 | 741 | dev->stats.tx_errors++; |
8de90115 NP |
742 | |
743 | if (tx_status & ES_LOSTCARR) | |
09f75cd7 | 744 | dev->stats.tx_carrier_errors++; |
1da177e4 | 745 | |
8de90115 | 746 | if (tx_status & (ES_LATCOL | ES_16COL)) { |
6389aa45 | 747 | PRINTK(dev, "%s occurred on last xmit\n", |
8de90115 NP |
748 | (tx_status & ES_LATCOL) ? |
749 | "late collision" : "too many collisions"); | |
09f75cd7 JG |
750 | dev->stats.tx_window_errors++; |
751 | if (!(dev->stats.tx_window_errors & 63) && net_ratelimit()) { | |
6389aa45 | 752 | netdev_info(dev, "unexpectedly large number of bad collisions. Please check duplex setting.\n"); |
1da177e4 LT |
753 | } |
754 | } | |
755 | ||
756 | /* kill the packet */ | |
cfdfa865 MD |
757 | SMC_WAIT_MMU_BUSY(lp); |
758 | SMC_SET_MMU_CMD(lp, MC_FREEPKT); | |
1da177e4 LT |
759 | |
760 | /* Don't restore Packet Number Reg until busy bit is cleared */ | |
cfdfa865 MD |
761 | SMC_WAIT_MMU_BUSY(lp); |
762 | SMC_SET_PN(lp, saved_packet); | |
1da177e4 LT |
763 | |
764 | /* re-enable transmit */ | |
cfdfa865 MD |
765 | SMC_SELECT_BANK(lp, 0); |
766 | SMC_SET_TCR(lp, lp->tcr_cur_mode); | |
767 | SMC_SELECT_BANK(lp, 2); | |
1da177e4 LT |
768 | } |
769 | ||
770 | ||
771 | /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/ | |
772 | ||
773 | static void smc_mii_out(struct net_device *dev, unsigned int val, int bits) | |
774 | { | |
775 | struct smc_local *lp = netdev_priv(dev); | |
776 | void __iomem *ioaddr = lp->base; | |
777 | unsigned int mii_reg, mask; | |
778 | ||
cfdfa865 | 779 | mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO); |
1da177e4 LT |
780 | mii_reg |= MII_MDOE; |
781 | ||
782 | for (mask = 1 << (bits - 1); mask; mask >>= 1) { | |
783 | if (val & mask) | |
784 | mii_reg |= MII_MDO; | |
785 | else | |
786 | mii_reg &= ~MII_MDO; | |
787 | ||
cfdfa865 | 788 | SMC_SET_MII(lp, mii_reg); |
1da177e4 | 789 | udelay(MII_DELAY); |
cfdfa865 | 790 | SMC_SET_MII(lp, mii_reg | MII_MCLK); |
1da177e4 LT |
791 | udelay(MII_DELAY); |
792 | } | |
793 | } | |
794 | ||
795 | static unsigned int smc_mii_in(struct net_device *dev, int bits) | |
796 | { | |
797 | struct smc_local *lp = netdev_priv(dev); | |
798 | void __iomem *ioaddr = lp->base; | |
799 | unsigned int mii_reg, mask, val; | |
800 | ||
cfdfa865 MD |
801 | mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO); |
802 | SMC_SET_MII(lp, mii_reg); | |
1da177e4 LT |
803 | |
804 | for (mask = 1 << (bits - 1), val = 0; mask; mask >>= 1) { | |
cfdfa865 | 805 | if (SMC_GET_MII(lp) & MII_MDI) |
1da177e4 LT |
806 | val |= mask; |
807 | ||
cfdfa865 | 808 | SMC_SET_MII(lp, mii_reg); |
1da177e4 | 809 | udelay(MII_DELAY); |
cfdfa865 | 810 | SMC_SET_MII(lp, mii_reg | MII_MCLK); |
1da177e4 LT |
811 | udelay(MII_DELAY); |
812 | } | |
813 | ||
814 | return val; | |
815 | } | |
816 | ||
817 | /* | |
818 | * Reads a register from the MII Management serial interface | |
819 | */ | |
820 | static int smc_phy_read(struct net_device *dev, int phyaddr, int phyreg) | |
821 | { | |
822 | struct smc_local *lp = netdev_priv(dev); | |
823 | void __iomem *ioaddr = lp->base; | |
824 | unsigned int phydata; | |
825 | ||
cfdfa865 | 826 | SMC_SELECT_BANK(lp, 3); |
1da177e4 LT |
827 | |
828 | /* Idle - 32 ones */ | |
829 | smc_mii_out(dev, 0xffffffff, 32); | |
830 | ||
831 | /* Start code (01) + read (10) + phyaddr + phyreg */ | |
832 | smc_mii_out(dev, 6 << 10 | phyaddr << 5 | phyreg, 14); | |
833 | ||
834 | /* Turnaround (2bits) + phydata */ | |
835 | phydata = smc_mii_in(dev, 18); | |
836 | ||
837 | /* Return to idle state */ | |
cfdfa865 | 838 | SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO)); |
1da177e4 | 839 | |
6389aa45 BB |
840 | DBG(3, dev, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n", |
841 | __func__, phyaddr, phyreg, phydata); | |
1da177e4 | 842 | |
cfdfa865 | 843 | SMC_SELECT_BANK(lp, 2); |
1da177e4 LT |
844 | return phydata; |
845 | } | |
846 | ||
847 | /* | |
848 | * Writes a register to the MII Management serial interface | |
849 | */ | |
850 | static void smc_phy_write(struct net_device *dev, int phyaddr, int phyreg, | |
851 | int phydata) | |
852 | { | |
853 | struct smc_local *lp = netdev_priv(dev); | |
854 | void __iomem *ioaddr = lp->base; | |
855 | ||
cfdfa865 | 856 | SMC_SELECT_BANK(lp, 3); |
1da177e4 LT |
857 | |
858 | /* Idle - 32 ones */ | |
859 | smc_mii_out(dev, 0xffffffff, 32); | |
860 | ||
861 | /* Start code (01) + write (01) + phyaddr + phyreg + turnaround + phydata */ | |
862 | smc_mii_out(dev, 5 << 28 | phyaddr << 23 | phyreg << 18 | 2 << 16 | phydata, 32); | |
863 | ||
864 | /* Return to idle state */ | |
cfdfa865 | 865 | SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO)); |
1da177e4 | 866 | |
6389aa45 BB |
867 | DBG(3, dev, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n", |
868 | __func__, phyaddr, phyreg, phydata); | |
1da177e4 | 869 | |
cfdfa865 | 870 | SMC_SELECT_BANK(lp, 2); |
1da177e4 LT |
871 | } |
872 | ||
873 | /* | |
874 | * Finds and reports the PHY address | |
875 | */ | |
876 | static void smc_phy_detect(struct net_device *dev) | |
877 | { | |
878 | struct smc_local *lp = netdev_priv(dev); | |
879 | int phyaddr; | |
880 | ||
6389aa45 | 881 | DBG(2, dev, "%s\n", __func__); |
1da177e4 LT |
882 | |
883 | lp->phy_type = 0; | |
884 | ||
885 | /* | |
886 | * Scan all 32 PHY addresses if necessary, starting at | |
887 | * PHY#1 to PHY#31, and then PHY#0 last. | |
888 | */ | |
889 | for (phyaddr = 1; phyaddr < 33; ++phyaddr) { | |
890 | unsigned int id1, id2; | |
891 | ||
892 | /* Read the PHY identifiers */ | |
893 | id1 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID1); | |
894 | id2 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID2); | |
895 | ||
6389aa45 BB |
896 | DBG(3, dev, "phy_id1=0x%x, phy_id2=0x%x\n", |
897 | id1, id2); | |
1da177e4 LT |
898 | |
899 | /* Make sure it is a valid identifier */ | |
900 | if (id1 != 0x0000 && id1 != 0xffff && id1 != 0x8000 && | |
901 | id2 != 0x0000 && id2 != 0xffff && id2 != 0x8000) { | |
902 | /* Save the PHY's address */ | |
903 | lp->mii.phy_id = phyaddr & 31; | |
904 | lp->phy_type = id1 << 16 | id2; | |
905 | break; | |
906 | } | |
907 | } | |
908 | } | |
909 | ||
910 | /* | |
911 | * Sets the PHY to a configuration as determined by the user | |
912 | */ | |
913 | static int smc_phy_fixed(struct net_device *dev) | |
914 | { | |
915 | struct smc_local *lp = netdev_priv(dev); | |
916 | void __iomem *ioaddr = lp->base; | |
917 | int phyaddr = lp->mii.phy_id; | |
918 | int bmcr, cfg1; | |
919 | ||
6389aa45 | 920 | DBG(3, dev, "%s\n", __func__); |
1da177e4 LT |
921 | |
922 | /* Enter Link Disable state */ | |
923 | cfg1 = smc_phy_read(dev, phyaddr, PHY_CFG1_REG); | |
924 | cfg1 |= PHY_CFG1_LNKDIS; | |
925 | smc_phy_write(dev, phyaddr, PHY_CFG1_REG, cfg1); | |
926 | ||
927 | /* | |
928 | * Set our fixed capabilities | |
929 | * Disable auto-negotiation | |
930 | */ | |
931 | bmcr = 0; | |
932 | ||
933 | if (lp->ctl_rfduplx) | |
934 | bmcr |= BMCR_FULLDPLX; | |
935 | ||
936 | if (lp->ctl_rspeed == 100) | |
937 | bmcr |= BMCR_SPEED100; | |
938 | ||
939 | /* Write our capabilities to the phy control register */ | |
940 | smc_phy_write(dev, phyaddr, MII_BMCR, bmcr); | |
941 | ||
942 | /* Re-Configure the Receive/Phy Control register */ | |
cfdfa865 MD |
943 | SMC_SELECT_BANK(lp, 0); |
944 | SMC_SET_RPC(lp, lp->rpc_cur_mode); | |
945 | SMC_SELECT_BANK(lp, 2); | |
1da177e4 LT |
946 | |
947 | return 1; | |
948 | } | |
949 | ||
49ce9c2c | 950 | /** |
1da177e4 LT |
951 | * smc_phy_reset - reset the phy |
952 | * @dev: net device | |
953 | * @phy: phy address | |
954 | * | |
955 | * Issue a software reset for the specified PHY and | |
956 | * wait up to 100ms for the reset to complete. We should | |
957 | * not access the PHY for 50ms after issuing the reset. | |
958 | * | |
959 | * The time to wait appears to be dependent on the PHY. | |
960 | * | |
961 | * Must be called with lp->lock locked. | |
962 | */ | |
963 | static int smc_phy_reset(struct net_device *dev, int phy) | |
964 | { | |
965 | struct smc_local *lp = netdev_priv(dev); | |
966 | unsigned int bmcr; | |
967 | int timeout; | |
968 | ||
969 | smc_phy_write(dev, phy, MII_BMCR, BMCR_RESET); | |
970 | ||
971 | for (timeout = 2; timeout; timeout--) { | |
972 | spin_unlock_irq(&lp->lock); | |
973 | msleep(50); | |
974 | spin_lock_irq(&lp->lock); | |
975 | ||
976 | bmcr = smc_phy_read(dev, phy, MII_BMCR); | |
977 | if (!(bmcr & BMCR_RESET)) | |
978 | break; | |
979 | } | |
980 | ||
981 | return bmcr & BMCR_RESET; | |
982 | } | |
983 | ||
49ce9c2c | 984 | /** |
1da177e4 LT |
985 | * smc_phy_powerdown - powerdown phy |
986 | * @dev: net device | |
987 | * | |
988 | * Power down the specified PHY | |
989 | */ | |
990 | static void smc_phy_powerdown(struct net_device *dev) | |
991 | { | |
992 | struct smc_local *lp = netdev_priv(dev); | |
993 | unsigned int bmcr; | |
994 | int phy = lp->mii.phy_id; | |
995 | ||
996 | if (lp->phy_type == 0) | |
997 | return; | |
998 | ||
999 | /* We need to ensure that no calls to smc_phy_configure are | |
1000 | pending. | |
1da177e4 | 1001 | */ |
4bb073c0 | 1002 | cancel_work_sync(&lp->phy_configure); |
1da177e4 LT |
1003 | |
1004 | bmcr = smc_phy_read(dev, phy, MII_BMCR); | |
1005 | smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN); | |
1006 | } | |
1007 | ||
49ce9c2c | 1008 | /** |
1da177e4 LT |
1009 | * smc_phy_check_media - check the media status and adjust TCR |
1010 | * @dev: net device | |
1011 | * @init: set true for initialisation | |
1012 | * | |
1013 | * Select duplex mode depending on negotiation state. This | |
1014 | * also updates our carrier state. | |
1015 | */ | |
1016 | static void smc_phy_check_media(struct net_device *dev, int init) | |
1017 | { | |
1018 | struct smc_local *lp = netdev_priv(dev); | |
1019 | void __iomem *ioaddr = lp->base; | |
1020 | ||
1021 | if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) { | |
1022 | /* duplex state has changed */ | |
1023 | if (lp->mii.full_duplex) { | |
1024 | lp->tcr_cur_mode |= TCR_SWFDUP; | |
1025 | } else { | |
1026 | lp->tcr_cur_mode &= ~TCR_SWFDUP; | |
1027 | } | |
1028 | ||
cfdfa865 MD |
1029 | SMC_SELECT_BANK(lp, 0); |
1030 | SMC_SET_TCR(lp, lp->tcr_cur_mode); | |
1da177e4 LT |
1031 | } |
1032 | } | |
1033 | ||
1034 | /* | |
1035 | * Configures the specified PHY through the MII management interface | |
1036 | * using Autonegotiation. | |
1037 | * Calls smc_phy_fixed() if the user has requested a certain config. | |
1038 | * If RPC ANEG bit is set, the media selection is dependent purely on | |
1039 | * the selection by the MII (either in the MII BMCR reg or the result | |
1040 | * of autonegotiation.) If the RPC ANEG bit is cleared, the selection | |
1041 | * is controlled by the RPC SPEED and RPC DPLX bits. | |
1042 | */ | |
6d5aefb8 | 1043 | static void smc_phy_configure(struct work_struct *work) |
1da177e4 | 1044 | { |
6d5aefb8 DH |
1045 | struct smc_local *lp = |
1046 | container_of(work, struct smc_local, phy_configure); | |
1047 | struct net_device *dev = lp->dev; | |
1da177e4 LT |
1048 | void __iomem *ioaddr = lp->base; |
1049 | int phyaddr = lp->mii.phy_id; | |
1050 | int my_phy_caps; /* My PHY capabilities */ | |
1051 | int my_ad_caps; /* My Advertised capabilities */ | |
1052 | int status; | |
1053 | ||
6389aa45 | 1054 | DBG(3, dev, "smc_program_phy()\n"); |
1da177e4 LT |
1055 | |
1056 | spin_lock_irq(&lp->lock); | |
1057 | ||
1058 | /* | |
1059 | * We should not be called if phy_type is zero. | |
1060 | */ | |
1061 | if (lp->phy_type == 0) | |
1062 | goto smc_phy_configure_exit; | |
1063 | ||
1064 | if (smc_phy_reset(dev, phyaddr)) { | |
6389aa45 | 1065 | netdev_info(dev, "PHY reset timed out\n"); |
1da177e4 LT |
1066 | goto smc_phy_configure_exit; |
1067 | } | |
1068 | ||
1069 | /* | |
1070 | * Enable PHY Interrupts (for register 18) | |
1071 | * Interrupts listed here are disabled | |
1072 | */ | |
1073 | smc_phy_write(dev, phyaddr, PHY_MASK_REG, | |
1074 | PHY_INT_LOSSSYNC | PHY_INT_CWRD | PHY_INT_SSD | | |
1075 | PHY_INT_ESD | PHY_INT_RPOL | PHY_INT_JAB | | |
1076 | PHY_INT_SPDDET | PHY_INT_DPLXDET); | |
1077 | ||
1078 | /* Configure the Receive/Phy Control register */ | |
cfdfa865 MD |
1079 | SMC_SELECT_BANK(lp, 0); |
1080 | SMC_SET_RPC(lp, lp->rpc_cur_mode); | |
1da177e4 LT |
1081 | |
1082 | /* If the user requested no auto neg, then go set his request */ | |
1083 | if (lp->mii.force_media) { | |
1084 | smc_phy_fixed(dev); | |
1085 | goto smc_phy_configure_exit; | |
1086 | } | |
1087 | ||
1088 | /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */ | |
1089 | my_phy_caps = smc_phy_read(dev, phyaddr, MII_BMSR); | |
1090 | ||
1091 | if (!(my_phy_caps & BMSR_ANEGCAPABLE)) { | |
6389aa45 | 1092 | netdev_info(dev, "Auto negotiation NOT supported\n"); |
1da177e4 LT |
1093 | smc_phy_fixed(dev); |
1094 | goto smc_phy_configure_exit; | |
1095 | } | |
1096 | ||
1097 | my_ad_caps = ADVERTISE_CSMA; /* I am CSMA capable */ | |
1098 | ||
1099 | if (my_phy_caps & BMSR_100BASE4) | |
1100 | my_ad_caps |= ADVERTISE_100BASE4; | |
1101 | if (my_phy_caps & BMSR_100FULL) | |
1102 | my_ad_caps |= ADVERTISE_100FULL; | |
1103 | if (my_phy_caps & BMSR_100HALF) | |
1104 | my_ad_caps |= ADVERTISE_100HALF; | |
1105 | if (my_phy_caps & BMSR_10FULL) | |
1106 | my_ad_caps |= ADVERTISE_10FULL; | |
1107 | if (my_phy_caps & BMSR_10HALF) | |
1108 | my_ad_caps |= ADVERTISE_10HALF; | |
1109 | ||
1110 | /* Disable capabilities not selected by our user */ | |
1111 | if (lp->ctl_rspeed != 100) | |
1112 | my_ad_caps &= ~(ADVERTISE_100BASE4|ADVERTISE_100FULL|ADVERTISE_100HALF); | |
1113 | ||
1114 | if (!lp->ctl_rfduplx) | |
1115 | my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL); | |
1116 | ||
1117 | /* Update our Auto-Neg Advertisement Register */ | |
1118 | smc_phy_write(dev, phyaddr, MII_ADVERTISE, my_ad_caps); | |
1119 | lp->mii.advertising = my_ad_caps; | |
1120 | ||
1121 | /* | |
1122 | * Read the register back. Without this, it appears that when | |
1123 | * auto-negotiation is restarted, sometimes it isn't ready and | |
1124 | * the link does not come up. | |
1125 | */ | |
1126 | status = smc_phy_read(dev, phyaddr, MII_ADVERTISE); | |
1127 | ||
6389aa45 BB |
1128 | DBG(2, dev, "phy caps=%x\n", my_phy_caps); |
1129 | DBG(2, dev, "phy advertised caps=%x\n", my_ad_caps); | |
1da177e4 LT |
1130 | |
1131 | /* Restart auto-negotiation process in order to advertise my caps */ | |
1132 | smc_phy_write(dev, phyaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART); | |
1133 | ||
1134 | smc_phy_check_media(dev, 1); | |
1135 | ||
1136 | smc_phy_configure_exit: | |
cfdfa865 | 1137 | SMC_SELECT_BANK(lp, 2); |
1da177e4 | 1138 | spin_unlock_irq(&lp->lock); |
1da177e4 LT |
1139 | } |
1140 | ||
1141 | /* | |
1142 | * smc_phy_interrupt | |
1143 | * | |
1144 | * Purpose: Handle interrupts relating to PHY register 18. This is | |
1145 | * called from the "hard" interrupt handler under our private spinlock. | |
1146 | */ | |
1147 | static void smc_phy_interrupt(struct net_device *dev) | |
1148 | { | |
1149 | struct smc_local *lp = netdev_priv(dev); | |
1150 | int phyaddr = lp->mii.phy_id; | |
1151 | int phy18; | |
1152 | ||
6389aa45 | 1153 | DBG(2, dev, "%s\n", __func__); |
1da177e4 LT |
1154 | |
1155 | if (lp->phy_type == 0) | |
1156 | return; | |
1157 | ||
1158 | for(;;) { | |
1159 | smc_phy_check_media(dev, 0); | |
1160 | ||
1161 | /* Read PHY Register 18, Status Output */ | |
1162 | phy18 = smc_phy_read(dev, phyaddr, PHY_INT_REG); | |
1163 | if ((phy18 & PHY_INT_INT) == 0) | |
1164 | break; | |
1165 | } | |
1166 | } | |
1167 | ||
1168 | /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/ | |
1169 | ||
1170 | static void smc_10bt_check_media(struct net_device *dev, int init) | |
1171 | { | |
1172 | struct smc_local *lp = netdev_priv(dev); | |
1173 | void __iomem *ioaddr = lp->base; | |
1174 | unsigned int old_carrier, new_carrier; | |
1175 | ||
1176 | old_carrier = netif_carrier_ok(dev) ? 1 : 0; | |
1177 | ||
cfdfa865 MD |
1178 | SMC_SELECT_BANK(lp, 0); |
1179 | new_carrier = (SMC_GET_EPH_STATUS(lp) & ES_LINK_OK) ? 1 : 0; | |
1180 | SMC_SELECT_BANK(lp, 2); | |
1da177e4 LT |
1181 | |
1182 | if (init || (old_carrier != new_carrier)) { | |
1183 | if (!new_carrier) { | |
1184 | netif_carrier_off(dev); | |
1185 | } else { | |
1186 | netif_carrier_on(dev); | |
1187 | } | |
1188 | if (netif_msg_link(lp)) | |
6389aa45 BB |
1189 | netdev_info(dev, "link %s\n", |
1190 | new_carrier ? "up" : "down"); | |
1da177e4 LT |
1191 | } |
1192 | } | |
1193 | ||
1194 | static void smc_eph_interrupt(struct net_device *dev) | |
1195 | { | |
1196 | struct smc_local *lp = netdev_priv(dev); | |
1197 | void __iomem *ioaddr = lp->base; | |
1198 | unsigned int ctl; | |
1199 | ||
1200 | smc_10bt_check_media(dev, 0); | |
1201 | ||
cfdfa865 MD |
1202 | SMC_SELECT_BANK(lp, 1); |
1203 | ctl = SMC_GET_CTL(lp); | |
1204 | SMC_SET_CTL(lp, ctl & ~CTL_LE_ENABLE); | |
1205 | SMC_SET_CTL(lp, ctl); | |
1206 | SMC_SELECT_BANK(lp, 2); | |
1da177e4 LT |
1207 | } |
1208 | ||
1209 | /* | |
1210 | * This is the main routine of the driver, to handle the device when | |
1211 | * it needs some attention. | |
1212 | */ | |
7d12e780 | 1213 | static irqreturn_t smc_interrupt(int irq, void *dev_id) |
1da177e4 LT |
1214 | { |
1215 | struct net_device *dev = dev_id; | |
1216 | struct smc_local *lp = netdev_priv(dev); | |
1217 | void __iomem *ioaddr = lp->base; | |
1218 | int status, mask, timeout, card_stats; | |
1219 | int saved_pointer; | |
1220 | ||
6389aa45 | 1221 | DBG(3, dev, "%s\n", __func__); |
1da177e4 LT |
1222 | |
1223 | spin_lock(&lp->lock); | |
1224 | ||
1225 | /* A preamble may be used when there is a potential race | |
1226 | * between the interruptible transmit functions and this | |
1227 | * ISR. */ | |
1228 | SMC_INTERRUPT_PREAMBLE; | |
1229 | ||
cfdfa865 MD |
1230 | saved_pointer = SMC_GET_PTR(lp); |
1231 | mask = SMC_GET_INT_MASK(lp); | |
1232 | SMC_SET_INT_MASK(lp, 0); | |
1da177e4 LT |
1233 | |
1234 | /* set a timeout value, so I don't stay here forever */ | |
5d0571d9 | 1235 | timeout = MAX_IRQ_LOOPS; |
1da177e4 LT |
1236 | |
1237 | do { | |
cfdfa865 | 1238 | status = SMC_GET_INT(lp); |
1da177e4 | 1239 | |
6389aa45 BB |
1240 | DBG(2, dev, "INT 0x%02x MASK 0x%02x MEM 0x%04x FIFO 0x%04x\n", |
1241 | status, mask, | |
1242 | ({ int meminfo; SMC_SELECT_BANK(lp, 0); | |
1243 | meminfo = SMC_GET_MIR(lp); | |
1244 | SMC_SELECT_BANK(lp, 2); meminfo; }), | |
1245 | SMC_GET_FIFO(lp)); | |
1da177e4 LT |
1246 | |
1247 | status &= mask; | |
1248 | if (!status) | |
1249 | break; | |
1250 | ||
ea937560 NP |
1251 | if (status & IM_TX_INT) { |
1252 | /* do this before RX as it will free memory quickly */ | |
6389aa45 | 1253 | DBG(3, dev, "TX int\n"); |
1da177e4 | 1254 | smc_tx(dev); |
cfdfa865 | 1255 | SMC_ACK_INT(lp, IM_TX_INT); |
1da177e4 LT |
1256 | if (THROTTLE_TX_PKTS) |
1257 | netif_wake_queue(dev); | |
ea937560 | 1258 | } else if (status & IM_RCV_INT) { |
6389aa45 | 1259 | DBG(3, dev, "RX irq\n"); |
ea937560 | 1260 | smc_rcv(dev); |
1da177e4 | 1261 | } else if (status & IM_ALLOC_INT) { |
6389aa45 | 1262 | DBG(3, dev, "Allocation irq\n"); |
1da177e4 LT |
1263 | tasklet_hi_schedule(&lp->tx_task); |
1264 | mask &= ~IM_ALLOC_INT; | |
1265 | } else if (status & IM_TX_EMPTY_INT) { | |
6389aa45 | 1266 | DBG(3, dev, "TX empty\n"); |
1da177e4 LT |
1267 | mask &= ~IM_TX_EMPTY_INT; |
1268 | ||
1269 | /* update stats */ | |
cfdfa865 MD |
1270 | SMC_SELECT_BANK(lp, 0); |
1271 | card_stats = SMC_GET_COUNTER(lp); | |
1272 | SMC_SELECT_BANK(lp, 2); | |
1da177e4 LT |
1273 | |
1274 | /* single collisions */ | |
09f75cd7 | 1275 | dev->stats.collisions += card_stats & 0xF; |
1da177e4 LT |
1276 | card_stats >>= 4; |
1277 | ||
1278 | /* multiple collisions */ | |
09f75cd7 | 1279 | dev->stats.collisions += card_stats & 0xF; |
1da177e4 | 1280 | } else if (status & IM_RX_OVRN_INT) { |
6389aa45 BB |
1281 | DBG(1, dev, "RX overrun (EPH_ST 0x%04x)\n", |
1282 | ({ int eph_st; SMC_SELECT_BANK(lp, 0); | |
1283 | eph_st = SMC_GET_EPH_STATUS(lp); | |
1284 | SMC_SELECT_BANK(lp, 2); eph_st; })); | |
cfdfa865 | 1285 | SMC_ACK_INT(lp, IM_RX_OVRN_INT); |
09f75cd7 JG |
1286 | dev->stats.rx_errors++; |
1287 | dev->stats.rx_fifo_errors++; | |
1da177e4 LT |
1288 | } else if (status & IM_EPH_INT) { |
1289 | smc_eph_interrupt(dev); | |
1290 | } else if (status & IM_MDINT) { | |
cfdfa865 | 1291 | SMC_ACK_INT(lp, IM_MDINT); |
1da177e4 LT |
1292 | smc_phy_interrupt(dev); |
1293 | } else if (status & IM_ERCV_INT) { | |
cfdfa865 | 1294 | SMC_ACK_INT(lp, IM_ERCV_INT); |
6389aa45 | 1295 | PRINTK(dev, "UNSUPPORTED: ERCV INTERRUPT\n"); |
1da177e4 LT |
1296 | } |
1297 | } while (--timeout); | |
1298 | ||
1299 | /* restore register states */ | |
cfdfa865 MD |
1300 | SMC_SET_PTR(lp, saved_pointer); |
1301 | SMC_SET_INT_MASK(lp, mask); | |
1da177e4 LT |
1302 | spin_unlock(&lp->lock); |
1303 | ||
c500cb26 | 1304 | #ifndef CONFIG_NET_POLL_CONTROLLER |
5d0571d9 | 1305 | if (timeout == MAX_IRQ_LOOPS) |
6389aa45 BB |
1306 | PRINTK(dev, "spurious interrupt (mask = 0x%02x)\n", |
1307 | mask); | |
c500cb26 | 1308 | #endif |
6389aa45 BB |
1309 | DBG(3, dev, "Interrupt done (%d loops)\n", |
1310 | MAX_IRQ_LOOPS - timeout); | |
1da177e4 LT |
1311 | |
1312 | /* | |
1313 | * We return IRQ_HANDLED unconditionally here even if there was | |
1314 | * nothing to do. There is a possibility that a packet might | |
1315 | * get enqueued into the chip right after TX_EMPTY_INT is raised | |
1316 | * but just before the CPU acknowledges the IRQ. | |
1317 | * Better take an unneeded IRQ in some occasions than complexifying | |
1318 | * the code for all cases. | |
1319 | */ | |
1320 | return IRQ_HANDLED; | |
1321 | } | |
1322 | ||
1323 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
1324 | /* | |
1325 | * Polling receive - used by netconsole and other diagnostic tools | |
1326 | * to allow network i/o with interrupts disabled. | |
1327 | */ | |
1328 | static void smc_poll_controller(struct net_device *dev) | |
1329 | { | |
1330 | disable_irq(dev->irq); | |
9c8e7f5c | 1331 | smc_interrupt(dev->irq, dev); |
1da177e4 LT |
1332 | enable_irq(dev->irq); |
1333 | } | |
1334 | #endif | |
1335 | ||
1336 | /* Our watchdog timed out. Called by the networking layer */ | |
1337 | static void smc_timeout(struct net_device *dev) | |
1338 | { | |
1339 | struct smc_local *lp = netdev_priv(dev); | |
1340 | void __iomem *ioaddr = lp->base; | |
8de90115 | 1341 | int status, mask, eph_st, meminfo, fifo; |
1da177e4 | 1342 | |
6389aa45 | 1343 | DBG(2, dev, "%s\n", __func__); |
1da177e4 LT |
1344 | |
1345 | spin_lock_irq(&lp->lock); | |
cfdfa865 MD |
1346 | status = SMC_GET_INT(lp); |
1347 | mask = SMC_GET_INT_MASK(lp); | |
1348 | fifo = SMC_GET_FIFO(lp); | |
1349 | SMC_SELECT_BANK(lp, 0); | |
1350 | eph_st = SMC_GET_EPH_STATUS(lp); | |
1351 | meminfo = SMC_GET_MIR(lp); | |
1352 | SMC_SELECT_BANK(lp, 2); | |
1da177e4 | 1353 | spin_unlock_irq(&lp->lock); |
6389aa45 BB |
1354 | PRINTK(dev, "TX timeout (INT 0x%02x INTMASK 0x%02x MEM 0x%04x FIFO 0x%04x EPH_ST 0x%04x)\n", |
1355 | status, mask, meminfo, fifo, eph_st); | |
1da177e4 LT |
1356 | |
1357 | smc_reset(dev); | |
1358 | smc_enable(dev); | |
1359 | ||
1360 | /* | |
1361 | * Reconfiguring the PHY doesn't seem like a bad idea here, but | |
1362 | * smc_phy_configure() calls msleep() which calls schedule_timeout() | |
1363 | * which calls schedule(). Hence we use a work queue. | |
1364 | */ | |
4bb073c0 DM |
1365 | if (lp->phy_type != 0) |
1366 | schedule_work(&lp->phy_configure); | |
1da177e4 LT |
1367 | |
1368 | /* We can accept TX packets again */ | |
860e9538 | 1369 | netif_trans_update(dev); /* prevent tx timeout */ |
1da177e4 LT |
1370 | netif_wake_queue(dev); |
1371 | } | |
1372 | ||
1373 | /* | |
1374 | * This routine will, depending on the values passed to it, | |
1375 | * either make it accept multicast packets, go into | |
1376 | * promiscuous mode (for TCPDUMP and cousins) or accept | |
1377 | * a select set of multicast packets | |
1378 | */ | |
1379 | static void smc_set_multicast_list(struct net_device *dev) | |
1380 | { | |
1381 | struct smc_local *lp = netdev_priv(dev); | |
1382 | void __iomem *ioaddr = lp->base; | |
1383 | unsigned char multicast_table[8]; | |
1384 | int update_multicast = 0; | |
1385 | ||
6389aa45 | 1386 | DBG(2, dev, "%s\n", __func__); |
1da177e4 LT |
1387 | |
1388 | if (dev->flags & IFF_PROMISC) { | |
6389aa45 | 1389 | DBG(2, dev, "RCR_PRMS\n"); |
1da177e4 LT |
1390 | lp->rcr_cur_mode |= RCR_PRMS; |
1391 | } | |
1392 | ||
1393 | /* BUG? I never disable promiscuous mode if multicasting was turned on. | |
1394 | Now, I turn off promiscuous mode, but I don't do anything to multicasting | |
1395 | when promiscuous mode is turned on. | |
1396 | */ | |
1397 | ||
1398 | /* | |
1399 | * Here, I am setting this to accept all multicast packets. | |
1400 | * I don't need to zero the multicast table, because the flag is | |
1401 | * checked before the table is | |
1402 | */ | |
4cd24eaf | 1403 | else if (dev->flags & IFF_ALLMULTI || netdev_mc_count(dev) > 16) { |
6389aa45 | 1404 | DBG(2, dev, "RCR_ALMUL\n"); |
1da177e4 LT |
1405 | lp->rcr_cur_mode |= RCR_ALMUL; |
1406 | } | |
1407 | ||
1408 | /* | |
1409 | * This sets the internal hardware table to filter out unwanted | |
1410 | * multicast packets before they take up memory. | |
1411 | * | |
1412 | * The SMC chip uses a hash table where the high 6 bits of the CRC of | |
1413 | * address are the offset into the table. If that bit is 1, then the | |
1414 | * multicast packet is accepted. Otherwise, it's dropped silently. | |
1415 | * | |
1416 | * To use the 6 bits as an offset into the table, the high 3 bits are | |
1417 | * the number of the 8 bit register, while the low 3 bits are the bit | |
1418 | * within that register. | |
1419 | */ | |
4cd24eaf | 1420 | else if (!netdev_mc_empty(dev)) { |
22bedad3 | 1421 | struct netdev_hw_addr *ha; |
1da177e4 LT |
1422 | |
1423 | /* table for flipping the order of 3 bits */ | |
1424 | static const unsigned char invert3[] = {0, 4, 2, 6, 1, 5, 3, 7}; | |
1425 | ||
1426 | /* start with a table of all zeros: reject all */ | |
1427 | memset(multicast_table, 0, sizeof(multicast_table)); | |
1428 | ||
22bedad3 | 1429 | netdev_for_each_mc_addr(ha, dev) { |
1da177e4 LT |
1430 | int position; |
1431 | ||
1da177e4 | 1432 | /* only use the low order bits */ |
22bedad3 | 1433 | position = crc32_le(~0, ha->addr, 6) & 0x3f; |
1da177e4 LT |
1434 | |
1435 | /* do some messy swapping to put the bit in the right spot */ | |
1436 | multicast_table[invert3[position&7]] |= | |
1437 | (1<<invert3[(position>>3)&7]); | |
1438 | } | |
1439 | ||
1440 | /* be sure I get rid of flags I might have set */ | |
1441 | lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL); | |
1442 | ||
1443 | /* now, the table can be loaded into the chipset */ | |
1444 | update_multicast = 1; | |
1445 | } else { | |
6389aa45 | 1446 | DBG(2, dev, "~(RCR_PRMS|RCR_ALMUL)\n"); |
1da177e4 LT |
1447 | lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL); |
1448 | ||
1449 | /* | |
1450 | * since I'm disabling all multicast entirely, I need to | |
1451 | * clear the multicast list | |
1452 | */ | |
1453 | memset(multicast_table, 0, sizeof(multicast_table)); | |
1454 | update_multicast = 1; | |
1455 | } | |
1456 | ||
1457 | spin_lock_irq(&lp->lock); | |
cfdfa865 MD |
1458 | SMC_SELECT_BANK(lp, 0); |
1459 | SMC_SET_RCR(lp, lp->rcr_cur_mode); | |
1da177e4 | 1460 | if (update_multicast) { |
cfdfa865 MD |
1461 | SMC_SELECT_BANK(lp, 3); |
1462 | SMC_SET_MCAST(lp, multicast_table); | |
1da177e4 | 1463 | } |
cfdfa865 | 1464 | SMC_SELECT_BANK(lp, 2); |
1da177e4 LT |
1465 | spin_unlock_irq(&lp->lock); |
1466 | } | |
1467 | ||
1468 | ||
1469 | /* | |
1470 | * Open and Initialize the board | |
1471 | * | |
1472 | * Set up everything, reset the card, etc.. | |
1473 | */ | |
1474 | static int | |
1475 | smc_open(struct net_device *dev) | |
1476 | { | |
1477 | struct smc_local *lp = netdev_priv(dev); | |
1478 | ||
6389aa45 | 1479 | DBG(2, dev, "%s\n", __func__); |
1da177e4 | 1480 | |
1da177e4 LT |
1481 | /* Setup the default Register Modes */ |
1482 | lp->tcr_cur_mode = TCR_DEFAULT; | |
1483 | lp->rcr_cur_mode = RCR_DEFAULT; | |
b0dbcf51 RK |
1484 | lp->rpc_cur_mode = RPC_DEFAULT | |
1485 | lp->cfg.leda << RPC_LSXA_SHFT | | |
1486 | lp->cfg.ledb << RPC_LSXB_SHFT; | |
1da177e4 LT |
1487 | |
1488 | /* | |
1489 | * If we are not using a MII interface, we need to | |
1490 | * monitor our own carrier signal to detect faults. | |
1491 | */ | |
1492 | if (lp->phy_type == 0) | |
1493 | lp->tcr_cur_mode |= TCR_MON_CSN; | |
1494 | ||
1495 | /* reset the hardware */ | |
1496 | smc_reset(dev); | |
1497 | smc_enable(dev); | |
1498 | ||
1499 | /* Configure the PHY, initialize the link state */ | |
1500 | if (lp->phy_type != 0) | |
6d5aefb8 | 1501 | smc_phy_configure(&lp->phy_configure); |
1da177e4 LT |
1502 | else { |
1503 | spin_lock_irq(&lp->lock); | |
1504 | smc_10bt_check_media(dev, 1); | |
1505 | spin_unlock_irq(&lp->lock); | |
1506 | } | |
1507 | ||
1508 | netif_start_queue(dev); | |
1509 | return 0; | |
1510 | } | |
1511 | ||
1512 | /* | |
1513 | * smc_close | |
1514 | * | |
1515 | * this makes the board clean up everything that it can | |
1516 | * and not talk to the outside world. Caused by | |
1517 | * an 'ifconfig ethX down' | |
1518 | */ | |
1519 | static int smc_close(struct net_device *dev) | |
1520 | { | |
1521 | struct smc_local *lp = netdev_priv(dev); | |
1522 | ||
6389aa45 | 1523 | DBG(2, dev, "%s\n", __func__); |
1da177e4 LT |
1524 | |
1525 | netif_stop_queue(dev); | |
1526 | netif_carrier_off(dev); | |
1527 | ||
1528 | /* clear everything */ | |
1529 | smc_shutdown(dev); | |
be83668a | 1530 | tasklet_kill(&lp->tx_task); |
1da177e4 | 1531 | smc_phy_powerdown(dev); |
1da177e4 LT |
1532 | return 0; |
1533 | } | |
1534 | ||
1da177e4 LT |
1535 | /* |
1536 | * Ethtool support | |
1537 | */ | |
1538 | static int | |
7b022a1b PR |
1539 | smc_ethtool_get_link_ksettings(struct net_device *dev, |
1540 | struct ethtool_link_ksettings *cmd) | |
1da177e4 LT |
1541 | { |
1542 | struct smc_local *lp = netdev_priv(dev); | |
1da177e4 | 1543 | |
1da177e4 LT |
1544 | if (lp->phy_type != 0) { |
1545 | spin_lock_irq(&lp->lock); | |
82c01a84 | 1546 | mii_ethtool_get_link_ksettings(&lp->mii, cmd); |
1da177e4 LT |
1547 | spin_unlock_irq(&lp->lock); |
1548 | } else { | |
7b022a1b | 1549 | u32 supported = SUPPORTED_10baseT_Half | |
1da177e4 LT |
1550 | SUPPORTED_10baseT_Full | |
1551 | SUPPORTED_TP | SUPPORTED_AUI; | |
1552 | ||
1553 | if (lp->ctl_rspeed == 10) | |
7b022a1b | 1554 | cmd->base.speed = SPEED_10; |
1da177e4 | 1555 | else if (lp->ctl_rspeed == 100) |
7b022a1b PR |
1556 | cmd->base.speed = SPEED_100; |
1557 | ||
1558 | cmd->base.autoneg = AUTONEG_DISABLE; | |
1559 | cmd->base.port = 0; | |
1560 | cmd->base.duplex = lp->tcr_cur_mode & TCR_SWFDUP ? | |
1561 | DUPLEX_FULL : DUPLEX_HALF; | |
1da177e4 | 1562 | |
7b022a1b PR |
1563 | ethtool_convert_legacy_u32_to_link_mode( |
1564 | cmd->link_modes.supported, supported); | |
1da177e4 LT |
1565 | } |
1566 | ||
82c01a84 | 1567 | return 0; |
1da177e4 LT |
1568 | } |
1569 | ||
1570 | static int | |
7b022a1b PR |
1571 | smc_ethtool_set_link_ksettings(struct net_device *dev, |
1572 | const struct ethtool_link_ksettings *cmd) | |
1da177e4 LT |
1573 | { |
1574 | struct smc_local *lp = netdev_priv(dev); | |
1575 | int ret; | |
1576 | ||
1577 | if (lp->phy_type != 0) { | |
1578 | spin_lock_irq(&lp->lock); | |
7b022a1b | 1579 | ret = mii_ethtool_set_link_ksettings(&lp->mii, cmd); |
1da177e4 LT |
1580 | spin_unlock_irq(&lp->lock); |
1581 | } else { | |
7b022a1b PR |
1582 | if (cmd->base.autoneg != AUTONEG_DISABLE || |
1583 | cmd->base.speed != SPEED_10 || | |
1584 | (cmd->base.duplex != DUPLEX_HALF && | |
1585 | cmd->base.duplex != DUPLEX_FULL) || | |
1586 | (cmd->base.port != PORT_TP && cmd->base.port != PORT_AUI)) | |
1da177e4 LT |
1587 | return -EINVAL; |
1588 | ||
7b022a1b PR |
1589 | // lp->port = cmd->base.port; |
1590 | lp->ctl_rfduplx = cmd->base.duplex == DUPLEX_FULL; | |
1da177e4 LT |
1591 | |
1592 | // if (netif_running(dev)) | |
1593 | // smc_set_port(dev); | |
1594 | ||
1595 | ret = 0; | |
1596 | } | |
1597 | ||
1598 | return ret; | |
1599 | } | |
1600 | ||
1601 | static void | |
1602 | smc_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | |
1603 | { | |
7826d43f JP |
1604 | strlcpy(info->driver, CARDNAME, sizeof(info->driver)); |
1605 | strlcpy(info->version, version, sizeof(info->version)); | |
1606 | strlcpy(info->bus_info, dev_name(dev->dev.parent), | |
1607 | sizeof(info->bus_info)); | |
1da177e4 LT |
1608 | } |
1609 | ||
1610 | static int smc_ethtool_nwayreset(struct net_device *dev) | |
1611 | { | |
1612 | struct smc_local *lp = netdev_priv(dev); | |
1613 | int ret = -EINVAL; | |
1614 | ||
1615 | if (lp->phy_type != 0) { | |
1616 | spin_lock_irq(&lp->lock); | |
1617 | ret = mii_nway_restart(&lp->mii); | |
1618 | spin_unlock_irq(&lp->lock); | |
1619 | } | |
1620 | ||
1621 | return ret; | |
1622 | } | |
1623 | ||
1624 | static u32 smc_ethtool_getmsglevel(struct net_device *dev) | |
1625 | { | |
1626 | struct smc_local *lp = netdev_priv(dev); | |
1627 | return lp->msg_enable; | |
1628 | } | |
1629 | ||
1630 | static void smc_ethtool_setmsglevel(struct net_device *dev, u32 level) | |
1631 | { | |
1632 | struct smc_local *lp = netdev_priv(dev); | |
1633 | lp->msg_enable = level; | |
1634 | } | |
1635 | ||
357fe2c6 VS |
1636 | static int smc_write_eeprom_word(struct net_device *dev, u16 addr, u16 word) |
1637 | { | |
1638 | u16 ctl; | |
1639 | struct smc_local *lp = netdev_priv(dev); | |
1640 | void __iomem *ioaddr = lp->base; | |
1641 | ||
1642 | spin_lock_irq(&lp->lock); | |
1643 | /* load word into GP register */ | |
1644 | SMC_SELECT_BANK(lp, 1); | |
1645 | SMC_SET_GP(lp, word); | |
1646 | /* set the address to put the data in EEPROM */ | |
1647 | SMC_SELECT_BANK(lp, 2); | |
1648 | SMC_SET_PTR(lp, addr); | |
1649 | /* tell it to write */ | |
1650 | SMC_SELECT_BANK(lp, 1); | |
1651 | ctl = SMC_GET_CTL(lp); | |
1652 | SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_STORE)); | |
1653 | /* wait for it to finish */ | |
1654 | do { | |
1655 | udelay(1); | |
1656 | } while (SMC_GET_CTL(lp) & CTL_STORE); | |
1657 | /* clean up */ | |
1658 | SMC_SET_CTL(lp, ctl); | |
1659 | SMC_SELECT_BANK(lp, 2); | |
1660 | spin_unlock_irq(&lp->lock); | |
1661 | return 0; | |
1662 | } | |
1663 | ||
1664 | static int smc_read_eeprom_word(struct net_device *dev, u16 addr, u16 *word) | |
1665 | { | |
1666 | u16 ctl; | |
1667 | struct smc_local *lp = netdev_priv(dev); | |
1668 | void __iomem *ioaddr = lp->base; | |
1669 | ||
1670 | spin_lock_irq(&lp->lock); | |
1671 | /* set the EEPROM address to get the data from */ | |
1672 | SMC_SELECT_BANK(lp, 2); | |
1673 | SMC_SET_PTR(lp, addr | PTR_READ); | |
1674 | /* tell it to load */ | |
1675 | SMC_SELECT_BANK(lp, 1); | |
1676 | SMC_SET_GP(lp, 0xffff); /* init to known */ | |
1677 | ctl = SMC_GET_CTL(lp); | |
1678 | SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_RELOAD)); | |
1679 | /* wait for it to finish */ | |
1680 | do { | |
1681 | udelay(1); | |
1682 | } while (SMC_GET_CTL(lp) & CTL_RELOAD); | |
1683 | /* read word from GP register */ | |
1684 | *word = SMC_GET_GP(lp); | |
1685 | /* clean up */ | |
1686 | SMC_SET_CTL(lp, ctl); | |
1687 | SMC_SELECT_BANK(lp, 2); | |
1688 | spin_unlock_irq(&lp->lock); | |
1689 | return 0; | |
1690 | } | |
1691 | ||
1692 | static int smc_ethtool_geteeprom_len(struct net_device *dev) | |
1693 | { | |
1694 | return 0x23 * 2; | |
1695 | } | |
1696 | ||
1697 | static int smc_ethtool_geteeprom(struct net_device *dev, | |
1698 | struct ethtool_eeprom *eeprom, u8 *data) | |
1699 | { | |
1700 | int i; | |
1701 | int imax; | |
1702 | ||
6389aa45 | 1703 | DBG(1, dev, "Reading %d bytes at %d(0x%x)\n", |
357fe2c6 VS |
1704 | eeprom->len, eeprom->offset, eeprom->offset); |
1705 | imax = smc_ethtool_geteeprom_len(dev); | |
1706 | for (i = 0; i < eeprom->len; i += 2) { | |
1707 | int ret; | |
1708 | u16 wbuf; | |
1709 | int offset = i + eeprom->offset; | |
1710 | if (offset > imax) | |
1711 | break; | |
1712 | ret = smc_read_eeprom_word(dev, offset >> 1, &wbuf); | |
1713 | if (ret != 0) | |
1714 | return ret; | |
6389aa45 | 1715 | DBG(2, dev, "Read 0x%x from 0x%x\n", wbuf, offset >> 1); |
357fe2c6 VS |
1716 | data[i] = (wbuf >> 8) & 0xff; |
1717 | data[i+1] = wbuf & 0xff; | |
1718 | } | |
1719 | return 0; | |
1720 | } | |
1721 | ||
1722 | static int smc_ethtool_seteeprom(struct net_device *dev, | |
1723 | struct ethtool_eeprom *eeprom, u8 *data) | |
1724 | { | |
1725 | int i; | |
1726 | int imax; | |
1727 | ||
6389aa45 BB |
1728 | DBG(1, dev, "Writing %d bytes to %d(0x%x)\n", |
1729 | eeprom->len, eeprom->offset, eeprom->offset); | |
357fe2c6 VS |
1730 | imax = smc_ethtool_geteeprom_len(dev); |
1731 | for (i = 0; i < eeprom->len; i += 2) { | |
1732 | int ret; | |
1733 | u16 wbuf; | |
1734 | int offset = i + eeprom->offset; | |
1735 | if (offset > imax) | |
1736 | break; | |
1737 | wbuf = (data[i] << 8) | data[i + 1]; | |
6389aa45 | 1738 | DBG(2, dev, "Writing 0x%x to 0x%x\n", wbuf, offset >> 1); |
357fe2c6 VS |
1739 | ret = smc_write_eeprom_word(dev, offset >> 1, wbuf); |
1740 | if (ret != 0) | |
1741 | return ret; | |
1742 | } | |
1743 | return 0; | |
1744 | } | |
1745 | ||
1746 | ||
7282d491 | 1747 | static const struct ethtool_ops smc_ethtool_ops = { |
1da177e4 LT |
1748 | .get_drvinfo = smc_ethtool_getdrvinfo, |
1749 | ||
1750 | .get_msglevel = smc_ethtool_getmsglevel, | |
1751 | .set_msglevel = smc_ethtool_setmsglevel, | |
1752 | .nway_reset = smc_ethtool_nwayreset, | |
1753 | .get_link = ethtool_op_get_link, | |
357fe2c6 VS |
1754 | .get_eeprom_len = smc_ethtool_geteeprom_len, |
1755 | .get_eeprom = smc_ethtool_geteeprom, | |
1756 | .set_eeprom = smc_ethtool_seteeprom, | |
7b022a1b PR |
1757 | .get_link_ksettings = smc_ethtool_get_link_ksettings, |
1758 | .set_link_ksettings = smc_ethtool_set_link_ksettings, | |
1da177e4 LT |
1759 | }; |
1760 | ||
a528079e MD |
1761 | static const struct net_device_ops smc_netdev_ops = { |
1762 | .ndo_open = smc_open, | |
1763 | .ndo_stop = smc_close, | |
1764 | .ndo_start_xmit = smc_hard_start_xmit, | |
1765 | .ndo_tx_timeout = smc_timeout, | |
afc4b13d | 1766 | .ndo_set_rx_mode = smc_set_multicast_list, |
a528079e MD |
1767 | .ndo_validate_addr = eth_validate_addr, |
1768 | .ndo_set_mac_address = eth_mac_addr, | |
1769 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
1770 | .ndo_poll_controller = smc_poll_controller, | |
1771 | #endif | |
1772 | }; | |
1773 | ||
1da177e4 LT |
1774 | /* |
1775 | * smc_findirq | |
1776 | * | |
1777 | * This routine has a simple purpose -- make the SMC chip generate an | |
1778 | * interrupt, so an auto-detect routine can detect it, and find the IRQ, | |
1779 | */ | |
1780 | /* | |
1781 | * does this still work? | |
1782 | * | |
1783 | * I just deleted auto_irq.c, since it was never built... | |
1784 | * --jgarzik | |
1785 | */ | |
1e48fea4 | 1786 | static int smc_findirq(struct smc_local *lp) |
1da177e4 | 1787 | { |
cfdfa865 | 1788 | void __iomem *ioaddr = lp->base; |
1da177e4 LT |
1789 | int timeout = 20; |
1790 | unsigned long cookie; | |
1791 | ||
702b3468 | 1792 | DBG(2, lp->dev, "%s: %s\n", CARDNAME, __func__); |
1da177e4 LT |
1793 | |
1794 | cookie = probe_irq_on(); | |
1795 | ||
1796 | /* | |
1797 | * What I try to do here is trigger an ALLOC_INT. This is done | |
1798 | * by allocating a small chunk of memory, which will give an interrupt | |
1799 | * when done. | |
1800 | */ | |
1801 | /* enable ALLOCation interrupts ONLY */ | |
cfdfa865 MD |
1802 | SMC_SELECT_BANK(lp, 2); |
1803 | SMC_SET_INT_MASK(lp, IM_ALLOC_INT); | |
1da177e4 LT |
1804 | |
1805 | /* | |
1806 | * Allocate 512 bytes of memory. Note that the chip was just | |
1807 | * reset so all the memory is available | |
1808 | */ | |
cfdfa865 | 1809 | SMC_SET_MMU_CMD(lp, MC_ALLOC | 1); |
1da177e4 LT |
1810 | |
1811 | /* | |
1812 | * Wait until positive that the interrupt has been generated | |
1813 | */ | |
1814 | do { | |
1815 | int int_status; | |
1816 | udelay(10); | |
cfdfa865 | 1817 | int_status = SMC_GET_INT(lp); |
1da177e4 LT |
1818 | if (int_status & IM_ALLOC_INT) |
1819 | break; /* got the interrupt */ | |
1820 | } while (--timeout); | |
1821 | ||
1822 | /* | |
1823 | * there is really nothing that I can do here if timeout fails, | |
1824 | * as autoirq_report will return a 0 anyway, which is what I | |
1825 | * want in this case. Plus, the clean up is needed in both | |
1826 | * cases. | |
1827 | */ | |
1828 | ||
1829 | /* and disable all interrupts again */ | |
cfdfa865 | 1830 | SMC_SET_INT_MASK(lp, 0); |
1da177e4 LT |
1831 | |
1832 | /* and return what I found */ | |
1833 | return probe_irq_off(cookie); | |
1834 | } | |
1835 | ||
1836 | /* | |
1837 | * Function: smc_probe(unsigned long ioaddr) | |
1838 | * | |
1839 | * Purpose: | |
1840 | * Tests to see if a given ioaddr points to an SMC91x chip. | |
1841 | * Returns a 0 on success | |
1842 | * | |
1843 | * Algorithm: | |
1844 | * (1) see if the high byte of BANK_SELECT is 0x33 | |
1845 | * (2) compare the ioaddr with the base register's address | |
1846 | * (3) see if I recognize the chip ID in the appropriate register | |
1847 | * | |
1848 | * Here I do typical initialization tasks. | |
1849 | * | |
1850 | * o Initialize the structure if needed | |
1851 | * o print out my vanity message if not done so already | |
1852 | * o print out what type of hardware is detected | |
1853 | * o print out the ethernet address | |
1854 | * o find the IRQ | |
1855 | * o set up my private data | |
1856 | * o configure the dev structure with my subroutines | |
1857 | * o actually GRAB the irq. | |
1858 | * o GRAB the region | |
1859 | */ | |
1e48fea4 | 1860 | static int smc_probe(struct net_device *dev, void __iomem *ioaddr, |
1dd06ae8 | 1861 | unsigned long irq_flags) |
1da177e4 LT |
1862 | { |
1863 | struct smc_local *lp = netdev_priv(dev); | |
0795af57 | 1864 | int retval; |
1da177e4 LT |
1865 | unsigned int val, revision_register; |
1866 | const char *version_string; | |
1867 | ||
6389aa45 | 1868 | DBG(2, dev, "%s: %s\n", CARDNAME, __func__); |
1da177e4 LT |
1869 | |
1870 | /* First, see if the high byte is 0x33 */ | |
cfdfa865 | 1871 | val = SMC_CURRENT_BANK(lp); |
6389aa45 BB |
1872 | DBG(2, dev, "%s: bank signature probe returned 0x%04x\n", |
1873 | CARDNAME, val); | |
1da177e4 LT |
1874 | if ((val & 0xFF00) != 0x3300) { |
1875 | if ((val & 0xFF) == 0x33) { | |
6389aa45 BB |
1876 | netdev_warn(dev, |
1877 | "%s: Detected possible byte-swapped interface at IOADDR %p\n", | |
1878 | CARDNAME, ioaddr); | |
1da177e4 LT |
1879 | } |
1880 | retval = -ENODEV; | |
1881 | goto err_out; | |
1882 | } | |
1883 | ||
1884 | /* | |
1885 | * The above MIGHT indicate a device, but I need to write to | |
1886 | * further test this. | |
1887 | */ | |
cfdfa865 MD |
1888 | SMC_SELECT_BANK(lp, 0); |
1889 | val = SMC_CURRENT_BANK(lp); | |
1da177e4 LT |
1890 | if ((val & 0xFF00) != 0x3300) { |
1891 | retval = -ENODEV; | |
1892 | goto err_out; | |
1893 | } | |
1894 | ||
1895 | /* | |
1896 | * well, we've already written once, so hopefully another | |
1897 | * time won't hurt. This time, I need to switch the bank | |
1898 | * register to bank 1, so I can access the base address | |
1899 | * register | |
1900 | */ | |
cfdfa865 MD |
1901 | SMC_SELECT_BANK(lp, 1); |
1902 | val = SMC_GET_BASE(lp); | |
1da177e4 | 1903 | val = ((val & 0x1F00) >> 3) << SMC_IO_SHIFT; |
6bc21eed | 1904 | if (((unsigned long)ioaddr & (0x3e0 << SMC_IO_SHIFT)) != val) { |
6389aa45 BB |
1905 | netdev_warn(dev, "%s: IOADDR %p doesn't match configuration (%x).\n", |
1906 | CARDNAME, ioaddr, val); | |
1da177e4 LT |
1907 | } |
1908 | ||
1909 | /* | |
1910 | * check if the revision register is something that I | |
1911 | * recognize. These might need to be added to later, | |
1912 | * as future revisions could be added. | |
1913 | */ | |
cfdfa865 MD |
1914 | SMC_SELECT_BANK(lp, 3); |
1915 | revision_register = SMC_GET_REV(lp); | |
6389aa45 | 1916 | DBG(2, dev, "%s: revision = 0x%04x\n", CARDNAME, revision_register); |
1da177e4 LT |
1917 | version_string = chip_ids[ (revision_register >> 4) & 0xF]; |
1918 | if (!version_string || (revision_register & 0xff00) != 0x3300) { | |
1919 | /* I don't recognize this chip, so... */ | |
6389aa45 BB |
1920 | netdev_warn(dev, "%s: IO %p: Unrecognized revision register 0x%04x, Contact author.\n", |
1921 | CARDNAME, ioaddr, revision_register); | |
1da177e4 LT |
1922 | |
1923 | retval = -ENODEV; | |
1924 | goto err_out; | |
1925 | } | |
1926 | ||
1927 | /* At this point I'll assume that the chip is an SMC91x. */ | |
6389aa45 | 1928 | pr_info_once("%s\n", version); |
1da177e4 LT |
1929 | |
1930 | /* fill in some of the fields */ | |
1931 | dev->base_addr = (unsigned long)ioaddr; | |
1932 | lp->base = ioaddr; | |
1933 | lp->version = revision_register & 0xff; | |
1934 | spin_lock_init(&lp->lock); | |
1935 | ||
1936 | /* Get the MAC address */ | |
cfdfa865 MD |
1937 | SMC_SELECT_BANK(lp, 1); |
1938 | SMC_GET_MAC_ADDR(lp, dev->dev_addr); | |
1da177e4 LT |
1939 | |
1940 | /* now, reset the chip, and put it into a known state */ | |
1941 | smc_reset(dev); | |
1942 | ||
1943 | /* | |
1944 | * If dev->irq is 0, then the device has to be banged on to see | |
1945 | * what the IRQ is. | |
6389aa45 | 1946 | * |
1da177e4 LT |
1947 | * This banging doesn't always detect the IRQ, for unknown reasons. |
1948 | * a workaround is to reset the chip and try again. | |
1949 | * | |
1950 | * Interestingly, the DOS packet driver *SETS* the IRQ on the card to | |
1951 | * be what is requested on the command line. I don't do that, mostly | |
1952 | * because the card that I have uses a non-standard method of accessing | |
1953 | * the IRQs, and because this _should_ work in most configurations. | |
1954 | * | |
1955 | * Specifying an IRQ is done with the assumption that the user knows | |
1956 | * what (s)he is doing. No checking is done!!!! | |
1957 | */ | |
1958 | if (dev->irq < 1) { | |
1959 | int trials; | |
1960 | ||
1961 | trials = 3; | |
1962 | while (trials--) { | |
cfdfa865 | 1963 | dev->irq = smc_findirq(lp); |
1da177e4 LT |
1964 | if (dev->irq) |
1965 | break; | |
1966 | /* kick the card and try again */ | |
1967 | smc_reset(dev); | |
1968 | } | |
1969 | } | |
1970 | if (dev->irq == 0) { | |
6389aa45 | 1971 | netdev_warn(dev, "Couldn't autodetect your IRQ. Use irq=xx.\n"); |
1da177e4 LT |
1972 | retval = -ENODEV; |
1973 | goto err_out; | |
1974 | } | |
1975 | dev->irq = irq_canonicalize(dev->irq); | |
1976 | ||
1da177e4 | 1977 | dev->watchdog_timeo = msecs_to_jiffies(watchdog); |
a528079e | 1978 | dev->netdev_ops = &smc_netdev_ops; |
1da177e4 | 1979 | dev->ethtool_ops = &smc_ethtool_ops; |
1da177e4 LT |
1980 | |
1981 | tasklet_init(&lp->tx_task, smc_hardware_send_pkt, (unsigned long)dev); | |
6d5aefb8 DH |
1982 | INIT_WORK(&lp->phy_configure, smc_phy_configure); |
1983 | lp->dev = dev; | |
1da177e4 LT |
1984 | lp->mii.phy_id_mask = 0x1f; |
1985 | lp->mii.reg_num_mask = 0x1f; | |
1986 | lp->mii.force_media = 0; | |
1987 | lp->mii.full_duplex = 0; | |
1988 | lp->mii.dev = dev; | |
1989 | lp->mii.mdio_read = smc_phy_read; | |
1990 | lp->mii.mdio_write = smc_phy_write; | |
1991 | ||
1992 | /* | |
1993 | * Locate the phy, if any. | |
1994 | */ | |
1995 | if (lp->version >= (CHIP_91100 << 4)) | |
1996 | smc_phy_detect(dev); | |
1997 | ||
99e1baf8 NP |
1998 | /* then shut everything down to save power */ |
1999 | smc_shutdown(dev); | |
2000 | smc_phy_powerdown(dev); | |
2001 | ||
1da177e4 LT |
2002 | /* Set default parameters */ |
2003 | lp->msg_enable = NETIF_MSG_LINK; | |
2004 | lp->ctl_rfduplx = 0; | |
2005 | lp->ctl_rspeed = 10; | |
2006 | ||
2007 | if (lp->version >= (CHIP_91100 << 4)) { | |
2008 | lp->ctl_rfduplx = 1; | |
2009 | lp->ctl_rspeed = 100; | |
2010 | } | |
2011 | ||
2012 | /* Grab the IRQ */ | |
a0607fd3 | 2013 | retval = request_irq(dev->irq, smc_interrupt, irq_flags, dev->name, dev); |
1da177e4 LT |
2014 | if (retval) |
2015 | goto err_out; | |
2016 | ||
52256c0e EM |
2017 | #ifdef CONFIG_ARCH_PXA |
2018 | # ifdef SMC_USE_PXA_DMA | |
2019 | lp->cfg.flags |= SMC91X_USE_DMA; | |
2020 | # endif | |
2021 | if (lp->cfg.flags & SMC91X_USE_DMA) { | |
d24c8f24 RJ |
2022 | dma_cap_mask_t mask; |
2023 | struct pxad_param param; | |
2024 | ||
2025 | dma_cap_zero(mask); | |
2026 | dma_cap_set(DMA_SLAVE, mask); | |
2027 | param.prio = PXAD_PRIO_LOWEST; | |
2028 | param.drcmr = -1UL; | |
2029 | ||
2030 | lp->dma_chan = | |
2031 | dma_request_slave_channel_compat(mask, pxad_filter_fn, | |
2032 | ¶m, &dev->dev, | |
2033 | "data"); | |
1da177e4 LT |
2034 | } |
2035 | #endif | |
2036 | ||
2037 | retval = register_netdev(dev); | |
2038 | if (retval == 0) { | |
2039 | /* now, print out the card info, in a short format.. */ | |
6389aa45 BB |
2040 | netdev_info(dev, "%s (rev %d) at %p IRQ %d", |
2041 | version_string, revision_register & 0x0f, | |
2042 | lp->base, dev->irq); | |
1da177e4 | 2043 | |
d24c8f24 RJ |
2044 | if (lp->dma_chan) |
2045 | pr_cont(" DMA %p", lp->dma_chan); | |
1da177e4 | 2046 | |
6389aa45 | 2047 | pr_cont("%s%s\n", |
d6bc372e | 2048 | lp->cfg.flags & SMC91X_NOWAIT ? " [nowait]" : "", |
1da177e4 LT |
2049 | THROTTLE_TX_PKTS ? " [throttle_tx]" : ""); |
2050 | ||
2051 | if (!is_valid_ether_addr(dev->dev_addr)) { | |
6389aa45 | 2052 | netdev_warn(dev, "Invalid ethernet MAC address. Please set using ifconfig\n"); |
1da177e4 LT |
2053 | } else { |
2054 | /* Print the Ethernet address */ | |
6389aa45 BB |
2055 | netdev_info(dev, "Ethernet addr: %pM\n", |
2056 | dev->dev_addr); | |
1da177e4 LT |
2057 | } |
2058 | ||
2059 | if (lp->phy_type == 0) { | |
6389aa45 | 2060 | PRINTK(dev, "No PHY found\n"); |
1da177e4 | 2061 | } else if ((lp->phy_type & 0xfffffff0) == 0x0016f840) { |
6389aa45 | 2062 | PRINTK(dev, "PHY LAN83C183 (LAN91C111 Internal)\n"); |
1da177e4 | 2063 | } else if ((lp->phy_type & 0xfffffff0) == 0x02821c50) { |
6389aa45 | 2064 | PRINTK(dev, "PHY LAN83C180\n"); |
1da177e4 LT |
2065 | } |
2066 | } | |
2067 | ||
2068 | err_out: | |
52256c0e | 2069 | #ifdef CONFIG_ARCH_PXA |
d24c8f24 RJ |
2070 | if (retval && lp->dma_chan) |
2071 | dma_release_channel(lp->dma_chan); | |
1da177e4 LT |
2072 | #endif |
2073 | return retval; | |
2074 | } | |
2075 | ||
2076 | static int smc_enable_device(struct platform_device *pdev) | |
2077 | { | |
3e947943 MD |
2078 | struct net_device *ndev = platform_get_drvdata(pdev); |
2079 | struct smc_local *lp = netdev_priv(ndev); | |
1da177e4 LT |
2080 | unsigned long flags; |
2081 | unsigned char ecor, ecsr; | |
2082 | void __iomem *addr; | |
2083 | struct resource * res; | |
2084 | ||
2085 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib"); | |
2086 | if (!res) | |
2087 | return 0; | |
2088 | ||
2089 | /* | |
2090 | * Map the attribute space. This is overkill, but clean. | |
2091 | */ | |
2092 | addr = ioremap(res->start, ATTRIB_SIZE); | |
2093 | if (!addr) | |
2094 | return -ENOMEM; | |
2095 | ||
2096 | /* | |
2097 | * Reset the device. We must disable IRQs around this | |
2098 | * since a reset causes the IRQ line become active. | |
2099 | */ | |
2100 | local_irq_save(flags); | |
2101 | ecor = readb(addr + (ECOR << SMC_IO_SHIFT)) & ~ECOR_RESET; | |
2102 | writeb(ecor | ECOR_RESET, addr + (ECOR << SMC_IO_SHIFT)); | |
2103 | readb(addr + (ECOR << SMC_IO_SHIFT)); | |
2104 | ||
2105 | /* | |
2106 | * Wait 100us for the chip to reset. | |
2107 | */ | |
2108 | udelay(100); | |
2109 | ||
2110 | /* | |
2111 | * The device will ignore all writes to the enable bit while | |
2112 | * reset is asserted, even if the reset bit is cleared in the | |
2113 | * same write. Must clear reset first, then enable the device. | |
2114 | */ | |
2115 | writeb(ecor, addr + (ECOR << SMC_IO_SHIFT)); | |
2116 | writeb(ecor | ECOR_ENABLE, addr + (ECOR << SMC_IO_SHIFT)); | |
2117 | ||
2118 | /* | |
2119 | * Set the appropriate byte/word mode. | |
2120 | */ | |
2121 | ecsr = readb(addr + (ECSR << SMC_IO_SHIFT)) & ~ECSR_IOIS8; | |
3e947943 | 2122 | if (!SMC_16BIT(lp)) |
09779c6d | 2123 | ecsr |= ECSR_IOIS8; |
1da177e4 LT |
2124 | writeb(ecsr, addr + (ECSR << SMC_IO_SHIFT)); |
2125 | local_irq_restore(flags); | |
2126 | ||
2127 | iounmap(addr); | |
2128 | ||
2129 | /* | |
2130 | * Wait for the chip to wake up. We could poll the control | |
2131 | * register in the main register space, but that isn't mapped | |
2132 | * yet. We know this is going to take 750us. | |
2133 | */ | |
2134 | msleep(1); | |
2135 | ||
2136 | return 0; | |
2137 | } | |
2138 | ||
15919886 EM |
2139 | static int smc_request_attrib(struct platform_device *pdev, |
2140 | struct net_device *ndev) | |
1da177e4 LT |
2141 | { |
2142 | struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib"); | |
55c8eb6c | 2143 | struct smc_local *lp __maybe_unused = netdev_priv(ndev); |
1da177e4 LT |
2144 | |
2145 | if (!res) | |
2146 | return 0; | |
2147 | ||
2148 | if (!request_mem_region(res->start, ATTRIB_SIZE, CARDNAME)) | |
2149 | return -EBUSY; | |
2150 | ||
2151 | return 0; | |
2152 | } | |
2153 | ||
15919886 EM |
2154 | static void smc_release_attrib(struct platform_device *pdev, |
2155 | struct net_device *ndev) | |
1da177e4 LT |
2156 | { |
2157 | struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib"); | |
55c8eb6c | 2158 | struct smc_local *lp __maybe_unused = netdev_priv(ndev); |
1da177e4 LT |
2159 | |
2160 | if (res) | |
2161 | release_mem_region(res->start, ATTRIB_SIZE); | |
2162 | } | |
2163 | ||
09779c6d | 2164 | static inline void smc_request_datacs(struct platform_device *pdev, struct net_device *ndev) |
1da177e4 | 2165 | { |
09779c6d NP |
2166 | if (SMC_CAN_USE_DATACS) { |
2167 | struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32"); | |
2168 | struct smc_local *lp = netdev_priv(ndev); | |
1da177e4 | 2169 | |
09779c6d NP |
2170 | if (!res) |
2171 | return; | |
1da177e4 | 2172 | |
09779c6d | 2173 | if(!request_mem_region(res->start, SMC_DATA_EXTENT, CARDNAME)) { |
6389aa45 BB |
2174 | netdev_info(ndev, "%s: failed to request datacs memory region.\n", |
2175 | CARDNAME); | |
09779c6d NP |
2176 | return; |
2177 | } | |
1da177e4 | 2178 | |
09779c6d NP |
2179 | lp->datacs = ioremap(res->start, SMC_DATA_EXTENT); |
2180 | } | |
1da177e4 LT |
2181 | } |
2182 | ||
2183 | static void smc_release_datacs(struct platform_device *pdev, struct net_device *ndev) | |
2184 | { | |
09779c6d NP |
2185 | if (SMC_CAN_USE_DATACS) { |
2186 | struct smc_local *lp = netdev_priv(ndev); | |
2187 | struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32"); | |
1da177e4 | 2188 | |
09779c6d NP |
2189 | if (lp->datacs) |
2190 | iounmap(lp->datacs); | |
1da177e4 | 2191 | |
09779c6d | 2192 | lp->datacs = NULL; |
1da177e4 | 2193 | |
09779c6d NP |
2194 | if (res) |
2195 | release_mem_region(res->start, SMC_DATA_EXTENT); | |
2196 | } | |
1da177e4 | 2197 | } |
1da177e4 | 2198 | |
8876d94b JL |
2199 | static const struct acpi_device_id smc91x_acpi_match[] = { |
2200 | { "LNRO0003", 0 }, | |
2201 | { } | |
2202 | }; | |
2203 | MODULE_DEVICE_TABLE(acpi, smc91x_acpi_match); | |
2204 | ||
3f823c15 TL |
2205 | #if IS_BUILTIN(CONFIG_OF) |
2206 | static const struct of_device_id smc91x_match[] = { | |
2207 | { .compatible = "smsc,lan91c94", }, | |
2208 | { .compatible = "smsc,lan91c111", }, | |
2209 | {}, | |
2210 | }; | |
2211 | MODULE_DEVICE_TABLE(of, smc91x_match); | |
7d2911c4 TL |
2212 | |
2213 | /** | |
2214 | * of_try_set_control_gpio - configure a gpio if it exists | |
2215 | */ | |
2216 | static int try_toggle_control_gpio(struct device *dev, | |
2217 | struct gpio_desc **desc, | |
2218 | const char *name, int index, | |
2219 | int value, unsigned int nsdelay) | |
2220 | { | |
2221 | struct gpio_desc *gpio = *desc; | |
cb6e0b36 | 2222 | enum gpiod_flags flags = value ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH; |
7d2911c4 | 2223 | |
cb6e0b36 UKK |
2224 | gpio = devm_gpiod_get_index_optional(dev, name, index, flags); |
2225 | if (IS_ERR(gpio)) | |
7d2911c4 | 2226 | return PTR_ERR(gpio); |
cb6e0b36 UKK |
2227 | |
2228 | if (gpio) { | |
2229 | if (nsdelay) | |
2230 | usleep_range(nsdelay, 2 * nsdelay); | |
2231 | gpiod_set_value_cansleep(gpio, value); | |
7d2911c4 | 2232 | } |
7d2911c4 TL |
2233 | *desc = gpio; |
2234 | ||
2235 | return 0; | |
2236 | } | |
3f823c15 TL |
2237 | #endif |
2238 | ||
1da177e4 LT |
2239 | /* |
2240 | * smc_init(void) | |
2241 | * Input parameters: | |
2242 | * dev->base_addr == 0, try to find all possible locations | |
2243 | * dev->base_addr > 0x1ff, this is the address to check | |
2244 | * dev->base_addr == <anything else>, return failure code | |
2245 | * | |
2246 | * Output: | |
2247 | * 0 --> there is a device | |
2248 | * anything else, error | |
2249 | */ | |
1e48fea4 | 2250 | static int smc_drv_probe(struct platform_device *pdev) |
1da177e4 | 2251 | { |
f64deaca | 2252 | struct smc91x_platdata *pd = dev_get_platdata(&pdev->dev); |
3f823c15 | 2253 | const struct of_device_id *match = NULL; |
3e947943 | 2254 | struct smc_local *lp; |
1da177e4 | 2255 | struct net_device *ndev; |
a2d4fcb8 | 2256 | struct resource *res; |
1da177e4 | 2257 | unsigned int __iomem *addr; |
d280eadc | 2258 | unsigned long irq_flags = SMC_IRQ_FLAGS; |
a2d4fcb8 | 2259 | unsigned long irq_resflags; |
1da177e4 LT |
2260 | int ret; |
2261 | ||
1da177e4 LT |
2262 | ndev = alloc_etherdev(sizeof(struct smc_local)); |
2263 | if (!ndev) { | |
1da177e4 | 2264 | ret = -ENOMEM; |
15919886 | 2265 | goto out; |
1da177e4 | 2266 | } |
3ae5eaec | 2267 | SET_NETDEV_DEV(ndev, &pdev->dev); |
1da177e4 | 2268 | |
3e947943 MD |
2269 | /* get configuration from platform data, only allow use of |
2270 | * bus width if both SMC_CAN_USE_xxx and SMC91X_USE_xxx are set. | |
2271 | */ | |
2272 | ||
2273 | lp = netdev_priv(ndev); | |
3f823c15 | 2274 | lp->cfg.flags = 0; |
3e947943 | 2275 | |
15919886 | 2276 | if (pd) { |
3e947943 | 2277 | memcpy(&lp->cfg, pd, sizeof(lp->cfg)); |
15919886 | 2278 | lp->io_shift = SMC91X_IO_SHIFT(lp->cfg.flags); |
2fb04fdf RK |
2279 | |
2280 | if (!SMC_8BIT(lp) && !SMC_16BIT(lp)) { | |
2281 | dev_err(&pdev->dev, | |
2282 | "at least one of 8-bit or 16-bit access support is required.\n"); | |
2283 | ret = -ENXIO; | |
2284 | goto out_free_netdev; | |
2285 | } | |
3f823c15 TL |
2286 | } |
2287 | ||
2288 | #if IS_BUILTIN(CONFIG_OF) | |
2289 | match = of_match_device(of_match_ptr(smc91x_match), &pdev->dev); | |
2290 | if (match) { | |
3f823c15 TL |
2291 | u32 val; |
2292 | ||
7d2911c4 TL |
2293 | /* Optional pwrdwn GPIO configured? */ |
2294 | ret = try_toggle_control_gpio(&pdev->dev, &lp->power_gpio, | |
2295 | "power", 0, 0, 100); | |
2296 | if (ret) | |
2297 | return ret; | |
2298 | ||
2299 | /* | |
2300 | * Optional reset GPIO configured? Minimum 100 ns reset needed | |
2301 | * according to LAN91C96 datasheet page 14. | |
2302 | */ | |
2303 | ret = try_toggle_control_gpio(&pdev->dev, &lp->reset_gpio, | |
2304 | "reset", 0, 0, 100); | |
2305 | if (ret) | |
2306 | return ret; | |
2307 | ||
2308 | /* | |
2309 | * Need to wait for optional EEPROM to load, max 750 us according | |
2310 | * to LAN91C96 datasheet page 55. | |
2311 | */ | |
2312 | if (lp->reset_gpio) | |
2313 | usleep_range(750, 1000); | |
2314 | ||
3f823c15 | 2315 | /* Combination of IO widths supported, default to 16-bit */ |
8876d94b JL |
2316 | if (!device_property_read_u32(&pdev->dev, "reg-io-width", |
2317 | &val)) { | |
3f823c15 TL |
2318 | if (val & 1) |
2319 | lp->cfg.flags |= SMC91X_USE_8BIT; | |
2320 | if ((val == 0) || (val & 2)) | |
2321 | lp->cfg.flags |= SMC91X_USE_16BIT; | |
2322 | if (val & 4) | |
2323 | lp->cfg.flags |= SMC91X_USE_32BIT; | |
2324 | } else { | |
2325 | lp->cfg.flags |= SMC91X_USE_16BIT; | |
2326 | } | |
876a55b8 RJ |
2327 | if (!device_property_read_u32(&pdev->dev, "reg-shift", |
2328 | &val)) | |
2329 | lp->io_shift = val; | |
9c365f31 RJ |
2330 | lp->cfg.pxa_u16_align4 = |
2331 | device_property_read_bool(&pdev->dev, "pxa-u16-align4"); | |
3f823c15 TL |
2332 | } |
2333 | #endif | |
2334 | ||
2335 | if (!pd && !match) { | |
fa6d3be0 EM |
2336 | lp->cfg.flags |= (SMC_CAN_USE_8BIT) ? SMC91X_USE_8BIT : 0; |
2337 | lp->cfg.flags |= (SMC_CAN_USE_16BIT) ? SMC91X_USE_16BIT : 0; | |
2338 | lp->cfg.flags |= (SMC_CAN_USE_32BIT) ? SMC91X_USE_32BIT : 0; | |
c4f0e767 | 2339 | lp->cfg.flags |= (nowait) ? SMC91X_NOWAIT : 0; |
3e947943 MD |
2340 | } |
2341 | ||
b0dbcf51 RK |
2342 | if (!lp->cfg.leda && !lp->cfg.ledb) { |
2343 | lp->cfg.leda = RPC_LSA_DEFAULT; | |
2344 | lp->cfg.ledb = RPC_LSB_DEFAULT; | |
2345 | } | |
2346 | ||
1da177e4 | 2347 | ndev->dma = (unsigned char)-1; |
e7b3dc7e | 2348 | |
15919886 EM |
2349 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs"); |
2350 | if (!res) | |
2351 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
2352 | if (!res) { | |
2353 | ret = -ENODEV; | |
2354 | goto out_free_netdev; | |
2355 | } | |
2356 | ||
2357 | ||
2358 | if (!request_mem_region(res->start, SMC_IO_EXTENT, CARDNAME)) { | |
2359 | ret = -EBUSY; | |
2360 | goto out_free_netdev; | |
2361 | } | |
2362 | ||
a2d4fcb8 | 2363 | ndev->irq = platform_get_irq(pdev, 0); |
bd59cfc5 RJ |
2364 | if (ndev->irq < 0) { |
2365 | ret = ndev->irq; | |
15919886 | 2366 | goto out_release_io; |
48944738 | 2367 | } |
a2d4fcb8 DM |
2368 | /* |
2369 | * If this platform does not specify any special irqflags, or if | |
2370 | * the resource supplies a trigger, override the irqflags with | |
2371 | * the trigger flags from the resource. | |
2372 | */ | |
2373 | irq_resflags = irqd_get_trigger_type(irq_get_irq_data(ndev->irq)); | |
2374 | if (irq_flags == -1 || irq_resflags & IRQF_TRIGGER_MASK) | |
2375 | irq_flags = irq_resflags & IRQF_TRIGGER_MASK; | |
e7b3dc7e | 2376 | |
15919886 | 2377 | ret = smc_request_attrib(pdev, ndev); |
1da177e4 | 2378 | if (ret) |
15919886 | 2379 | goto out_release_io; |
b70661c7 AB |
2380 | #if defined(CONFIG_ASSABET_NEPONSET) |
2381 | if (machine_is_assabet() && machine_has_neponset()) | |
2382 | neponset_ncr_set(NCR_ENET_OSC_EN); | |
1da177e4 | 2383 | #endif |
3e947943 | 2384 | platform_set_drvdata(pdev, ndev); |
1da177e4 LT |
2385 | ret = smc_enable_device(pdev); |
2386 | if (ret) | |
2387 | goto out_release_attrib; | |
2388 | ||
2389 | addr = ioremap(res->start, SMC_IO_EXTENT); | |
2390 | if (!addr) { | |
2391 | ret = -ENOMEM; | |
2392 | goto out_release_attrib; | |
2393 | } | |
2394 | ||
52256c0e | 2395 | #ifdef CONFIG_ARCH_PXA |
073ac8fd | 2396 | { |
1da177e4 | 2397 | struct smc_local *lp = netdev_priv(ndev); |
073ac8fd | 2398 | lp->device = &pdev->dev; |
1da177e4 | 2399 | lp->physaddr = res->start; |
d24c8f24 | 2400 | |
1da177e4 LT |
2401 | } |
2402 | #endif | |
2403 | ||
d280eadc | 2404 | ret = smc_probe(ndev, addr, irq_flags); |
073ac8fd RK |
2405 | if (ret != 0) |
2406 | goto out_iounmap; | |
2407 | ||
1da177e4 LT |
2408 | smc_request_datacs(pdev, ndev); |
2409 | ||
2410 | return 0; | |
2411 | ||
2412 | out_iounmap: | |
1da177e4 LT |
2413 | iounmap(addr); |
2414 | out_release_attrib: | |
15919886 | 2415 | smc_release_attrib(pdev, ndev); |
1da177e4 LT |
2416 | out_release_io: |
2417 | release_mem_region(res->start, SMC_IO_EXTENT); | |
15919886 EM |
2418 | out_free_netdev: |
2419 | free_netdev(ndev); | |
1da177e4 | 2420 | out: |
6389aa45 | 2421 | pr_info("%s: not found (%d).\n", CARDNAME, ret); |
1da177e4 LT |
2422 | |
2423 | return ret; | |
2424 | } | |
2425 | ||
1e48fea4 | 2426 | static int smc_drv_remove(struct platform_device *pdev) |
1da177e4 | 2427 | { |
3ae5eaec | 2428 | struct net_device *ndev = platform_get_drvdata(pdev); |
1da177e4 LT |
2429 | struct smc_local *lp = netdev_priv(ndev); |
2430 | struct resource *res; | |
2431 | ||
1da177e4 LT |
2432 | unregister_netdev(ndev); |
2433 | ||
2434 | free_irq(ndev->irq, ndev); | |
2435 | ||
52256c0e | 2436 | #ifdef CONFIG_ARCH_PXA |
d24c8f24 RJ |
2437 | if (lp->dma_chan) |
2438 | dma_release_channel(lp->dma_chan); | |
1da177e4 LT |
2439 | #endif |
2440 | iounmap(lp->base); | |
2441 | ||
2442 | smc_release_datacs(pdev,ndev); | |
15919886 | 2443 | smc_release_attrib(pdev,ndev); |
1da177e4 LT |
2444 | |
2445 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs"); | |
2446 | if (!res) | |
6fc30db5 | 2447 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1da177e4 LT |
2448 | release_mem_region(res->start, SMC_IO_EXTENT); |
2449 | ||
2450 | free_netdev(ndev); | |
2451 | ||
2452 | return 0; | |
2453 | } | |
2454 | ||
9f950f72 | 2455 | static int smc_drv_suspend(struct device *dev) |
1da177e4 | 2456 | { |
9f950f72 KH |
2457 | struct platform_device *pdev = to_platform_device(dev); |
2458 | struct net_device *ndev = platform_get_drvdata(pdev); | |
1da177e4 | 2459 | |
9480e307 | 2460 | if (ndev) { |
1da177e4 LT |
2461 | if (netif_running(ndev)) { |
2462 | netif_device_detach(ndev); | |
2463 | smc_shutdown(ndev); | |
2464 | smc_phy_powerdown(ndev); | |
2465 | } | |
2466 | } | |
2467 | return 0; | |
2468 | } | |
2469 | ||
9f950f72 | 2470 | static int smc_drv_resume(struct device *dev) |
1da177e4 | 2471 | { |
9f950f72 KH |
2472 | struct platform_device *pdev = to_platform_device(dev); |
2473 | struct net_device *ndev = platform_get_drvdata(pdev); | |
1da177e4 | 2474 | |
9480e307 | 2475 | if (ndev) { |
1da177e4 | 2476 | struct smc_local *lp = netdev_priv(ndev); |
5fc34413 | 2477 | smc_enable_device(pdev); |
1da177e4 LT |
2478 | if (netif_running(ndev)) { |
2479 | smc_reset(ndev); | |
2480 | smc_enable(ndev); | |
2481 | if (lp->phy_type != 0) | |
6d5aefb8 | 2482 | smc_phy_configure(&lp->phy_configure); |
1da177e4 LT |
2483 | netif_device_attach(ndev); |
2484 | } | |
2485 | } | |
2486 | return 0; | |
2487 | } | |
2488 | ||
d19724ec | 2489 | static const struct dev_pm_ops smc_drv_pm_ops = { |
9f950f72 KH |
2490 | .suspend = smc_drv_suspend, |
2491 | .resume = smc_drv_resume, | |
2492 | }; | |
2493 | ||
3ae5eaec | 2494 | static struct platform_driver smc_driver = { |
1da177e4 | 2495 | .probe = smc_drv_probe, |
1e48fea4 | 2496 | .remove = smc_drv_remove, |
3ae5eaec RK |
2497 | .driver = { |
2498 | .name = CARDNAME, | |
9f950f72 | 2499 | .pm = &smc_drv_pm_ops, |
8876d94b JL |
2500 | .of_match_table = of_match_ptr(smc91x_match), |
2501 | .acpi_match_table = smc91x_acpi_match, | |
3ae5eaec | 2502 | }, |
1da177e4 LT |
2503 | }; |
2504 | ||
db62f684 | 2505 | module_platform_driver(smc_driver); |