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