Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux Ethernet device driver for the 3Com Etherlink Plus (3C505) |
| 3 | * By Craig Southeren, Juha Laiho and Philip Blundell |
| 4 | * |
| 5 | * 3c505.c This module implements an interface to the 3Com |
| 6 | * Etherlink Plus (3c505) Ethernet card. Linux device |
| 7 | * driver interface reverse engineered from the Linux 3C509 |
| 8 | * device drivers. Some 3C505 information gleaned from |
| 9 | * the Crynwr packet driver. Still this driver would not |
| 10 | * be here without 3C505 technical reference provided by |
| 11 | * 3Com. |
| 12 | * |
| 13 | * $Id: 3c505.c,v 1.10 1996/04/16 13:06:27 phil Exp $ |
| 14 | * |
| 15 | * Authors: Linux 3c505 device driver by |
| 16 | * Craig Southeren, <craigs@ineluki.apana.org.au> |
| 17 | * Final debugging by |
| 18 | * Andrew Tridgell, <tridge@nimbus.anu.edu.au> |
| 19 | * Auto irq/address, tuning, cleanup and v1.1.4+ kernel mods by |
| 20 | * Juha Laiho, <jlaiho@ichaos.nullnet.fi> |
| 21 | * Linux 3C509 driver by |
| 22 | * Donald Becker, <becker@super.org> |
| 23 | * (Now at <becker@scyld.com>) |
| 24 | * Crynwr packet driver by |
| 25 | * Krishnan Gopalan and Gregg Stefancik, |
| 26 | * Clemson University Engineering Computer Operations. |
| 27 | * Portions of the code have been adapted from the 3c505 |
| 28 | * driver for NCSA Telnet by Bruce Orchard and later |
| 29 | * modified by Warren Van Houten and krus@diku.dk. |
| 30 | * 3C505 technical information provided by |
| 31 | * Terry Murphy, of 3Com Network Adapter Division |
| 32 | * Linux 1.3.0 changes by |
| 33 | * Alan Cox <Alan.Cox@linux.org> |
| 34 | * More debugging, DMA support, currently maintained by |
| 35 | * Philip Blundell <philb@gnu.org> |
| 36 | * Multicard/soft configurable dma channel/rev 2 hardware support |
| 37 | * by Christopher Collins <ccollins@pcug.org.au> |
| 38 | * Ethtool support (jgarzik), 11/17/2001 |
| 39 | */ |
| 40 | |
| 41 | #define DRV_NAME "3c505" |
| 42 | #define DRV_VERSION "1.10a" |
| 43 | |
| 44 | |
| 45 | /* Theory of operation: |
| 46 | * |
| 47 | * The 3c505 is quite an intelligent board. All communication with it is done |
| 48 | * by means of Primary Command Blocks (PCBs); these are transferred using PIO |
| 49 | * through the command register. The card has 256k of on-board RAM, which is |
| 50 | * used to buffer received packets. It might seem at first that more buffers |
| 51 | * are better, but in fact this isn't true. From my tests, it seems that |
| 52 | * more than about 10 buffers are unnecessary, and there is a noticeable |
| 53 | * performance hit in having more active on the card. So the majority of the |
| 54 | * card's memory isn't, in fact, used. Sadly, the card only has one transmit |
| 55 | * buffer and, short of loading our own firmware into it (which is what some |
| 56 | * drivers resort to) there's nothing we can do about this. |
| 57 | * |
| 58 | * We keep up to 4 "receive packet" commands active on the board at a time. |
| 59 | * When a packet comes in, so long as there is a receive command active, the |
| 60 | * board will send us a "packet received" PCB and then add the data for that |
| 61 | * packet to the DMA queue. If a DMA transfer is not already in progress, we |
| 62 | * set one up to start uploading the data. We have to maintain a list of |
| 63 | * backlogged receive packets, because the card may decide to tell us about |
| 64 | * a newly-arrived packet at any time, and we may not be able to start a DMA |
| 65 | * transfer immediately (ie one may already be going on). We can't NAK the |
| 66 | * PCB, because then it would throw the packet away. |
| 67 | * |
| 68 | * Trying to send a PCB to the card at the wrong moment seems to have bad |
| 69 | * effects. If we send it a transmit PCB while a receive DMA is happening, |
| 70 | * it will just NAK the PCB and so we will have wasted our time. Worse, it |
| 71 | * sometimes seems to interrupt the transfer. The majority of the low-level |
| 72 | * code is protected by one huge semaphore -- "busy" -- which is set whenever |
| 73 | * it probably isn't safe to do anything to the card. The receive routine |
| 74 | * must gain a lock on "busy" before it can start a DMA transfer, and the |
| 75 | * transmit routine must gain a lock before it sends the first PCB to the card. |
| 76 | * The send_pcb() routine also has an internal semaphore to protect it against |
| 77 | * being re-entered (which would be disastrous) -- this is needed because |
| 78 | * several things can happen asynchronously (re-priming the receiver and |
| 79 | * asking the card for statistics, for example). send_pcb() will also refuse |
| 80 | * to talk to the card at all if a DMA upload is happening. The higher-level |
| 81 | * networking code will reschedule a later retry if some part of the driver |
| 82 | * is blocked. In practice, this doesn't seem to happen very often. |
| 83 | */ |
| 84 | |
| 85 | /* This driver may now work with revision 2.x hardware, since all the read |
| 86 | * operations on the HCR have been removed (we now keep our own softcopy). |
| 87 | * But I don't have an old card to test it on. |
| 88 | * |
| 89 | * This has had the bad effect that the autoprobe routine is now a bit |
| 90 | * less friendly to other devices. However, it was never very good. |
| 91 | * before, so I doubt it will hurt anybody. |
| 92 | */ |
| 93 | |
| 94 | /* The driver is a mess. I took Craig's and Juha's code, and hacked it firstly |
| 95 | * to make it more reliable, and secondly to add DMA mode. Many things could |
| 96 | * probably be done better; the concurrency protection is particularly awful. |
| 97 | */ |
| 98 | |
| 99 | #include <linux/module.h> |
| 100 | #include <linux/kernel.h> |
| 101 | #include <linux/string.h> |
| 102 | #include <linux/interrupt.h> |
| 103 | #include <linux/errno.h> |
| 104 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #include <linux/ioport.h> |
| 106 | #include <linux/spinlock.h> |
| 107 | #include <linux/ethtool.h> |
| 108 | #include <linux/delay.h> |
| 109 | #include <linux/bitops.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 110 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | #include <asm/uaccess.h> |
| 113 | #include <asm/io.h> |
| 114 | #include <asm/dma.h> |
| 115 | |
| 116 | #include <linux/netdevice.h> |
| 117 | #include <linux/etherdevice.h> |
| 118 | #include <linux/skbuff.h> |
| 119 | #include <linux/init.h> |
| 120 | |
| 121 | #include "3c505.h" |
| 122 | |
| 123 | /********************************************************* |
| 124 | * |
| 125 | * define debug messages here as common strings to reduce space |
| 126 | * |
| 127 | *********************************************************/ |
| 128 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 129 | #define timeout_msg "*** timeout at %s:%s (line %d) ***\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #define TIMEOUT_MSG(lineno) \ |
Andrew Morton | 23e0494 | 2011-11-01 00:53:33 -0400 | [diff] [blame] | 131 | pr_notice(timeout_msg, __FILE__, __func__, (lineno)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 133 | #define invalid_pcb_msg "*** invalid pcb length %d at %s:%s (line %d) ***\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #define INVALID_PCB_MSG(len) \ |
Andrew Morton | 23e0494 | 2011-11-01 00:53:33 -0400 | [diff] [blame] | 135 | pr_notice(invalid_pcb_msg, (len), __FILE__, __func__, __LINE__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 137 | #define search_msg "%s: Looking for 3c505 adapter at address %#x..." |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 139 | #define stilllooking_msg "still looking..." |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 141 | #define found_msg "found.\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 143 | #define notfound_msg "not found (reason = %d)\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 145 | #define couldnot_msg "%s: 3c505 not found\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | /********************************************************* |
| 148 | * |
| 149 | * various other debug stuff |
| 150 | * |
| 151 | *********************************************************/ |
| 152 | |
| 153 | #ifdef ELP_DEBUG |
| 154 | static int elp_debug = ELP_DEBUG; |
| 155 | #else |
| 156 | static int elp_debug; |
| 157 | #endif |
| 158 | #define debug elp_debug |
| 159 | |
| 160 | /* |
| 161 | * 0 = no messages (well, some) |
| 162 | * 1 = messages when high level commands performed |
| 163 | * 2 = messages when low level commands performed |
| 164 | * 3 = messages when interrupts received |
| 165 | */ |
| 166 | |
| 167 | /***************************************************************** |
| 168 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | * List of I/O-addresses we try to auto-sense |
| 170 | * Last element MUST BE 0! |
| 171 | *****************************************************************/ |
| 172 | |
| 173 | static int addr_list[] __initdata = {0x300, 0x280, 0x310, 0}; |
| 174 | |
| 175 | /* Dma Memory related stuff */ |
| 176 | |
| 177 | static unsigned long dma_mem_alloc(int size) |
| 178 | { |
| 179 | int order = get_order(size); |
| 180 | return __get_dma_pages(GFP_KERNEL, order); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /***************************************************************** |
| 185 | * |
| 186 | * Functions for I/O (note the inline !) |
| 187 | * |
| 188 | *****************************************************************/ |
| 189 | |
| 190 | static inline unsigned char inb_status(unsigned int base_addr) |
| 191 | { |
| 192 | return inb(base_addr + PORT_STATUS); |
| 193 | } |
| 194 | |
| 195 | static inline int inb_command(unsigned int base_addr) |
| 196 | { |
| 197 | return inb(base_addr + PORT_COMMAND); |
| 198 | } |
| 199 | |
| 200 | static inline void outb_control(unsigned char val, struct net_device *dev) |
| 201 | { |
| 202 | outb(val, dev->base_addr + PORT_CONTROL); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 203 | ((elp_device *)(netdev_priv(dev)))->hcr_val = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 206 | #define HCR_VAL(x) (((elp_device *)(netdev_priv(x)))->hcr_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | static inline void outb_command(unsigned char val, unsigned int base_addr) |
| 209 | { |
| 210 | outb(val, base_addr + PORT_COMMAND); |
| 211 | } |
| 212 | |
| 213 | static inline unsigned int backlog_next(unsigned int n) |
| 214 | { |
| 215 | return (n + 1) % BACKLOG_SIZE; |
| 216 | } |
| 217 | |
| 218 | /***************************************************************** |
| 219 | * |
| 220 | * useful functions for accessing the adapter |
| 221 | * |
| 222 | *****************************************************************/ |
| 223 | |
| 224 | /* |
| 225 | * use this routine when accessing the ASF bits as they are |
| 226 | * changed asynchronously by the adapter |
| 227 | */ |
| 228 | |
| 229 | /* get adapter PCB status */ |
| 230 | #define GET_ASF(addr) \ |
| 231 | (get_status(addr)&ASF_PCB_MASK) |
| 232 | |
| 233 | static inline int get_status(unsigned int base_addr) |
| 234 | { |
| 235 | unsigned long timeout = jiffies + 10*HZ/100; |
| 236 | register int stat1; |
| 237 | do { |
| 238 | stat1 = inb_status(base_addr); |
| 239 | } while (stat1 != inb_status(base_addr) && time_before(jiffies, timeout)); |
| 240 | if (time_after_eq(jiffies, timeout)) |
| 241 | TIMEOUT_MSG(__LINE__); |
| 242 | return stat1; |
| 243 | } |
| 244 | |
| 245 | static inline void set_hsf(struct net_device *dev, int hsf) |
| 246 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 247 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | unsigned long flags; |
| 249 | |
| 250 | spin_lock_irqsave(&adapter->lock, flags); |
| 251 | outb_control((HCR_VAL(dev) & ~HSF_PCB_MASK) | hsf, dev); |
| 252 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 253 | } |
| 254 | |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 255 | static bool start_receive(struct net_device *, pcb_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 257 | static inline void adapter_reset(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | unsigned long timeout; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 260 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | unsigned char orig_hcr = adapter->hcr_val; |
| 262 | |
| 263 | outb_control(0, dev); |
| 264 | |
| 265 | if (inb_status(dev->base_addr) & ACRF) { |
| 266 | do { |
| 267 | inb_command(dev->base_addr); |
| 268 | timeout = jiffies + 2*HZ/100; |
| 269 | while (time_before_eq(jiffies, timeout) && !(inb_status(dev->base_addr) & ACRF)); |
| 270 | } while (inb_status(dev->base_addr) & ACRF); |
| 271 | set_hsf(dev, HSF_PCB_NAK); |
| 272 | } |
| 273 | outb_control(adapter->hcr_val | ATTN | DIR, dev); |
| 274 | mdelay(10); |
| 275 | outb_control(adapter->hcr_val & ~ATTN, dev); |
| 276 | mdelay(10); |
| 277 | outb_control(adapter->hcr_val | FLSH, dev); |
| 278 | mdelay(10); |
| 279 | outb_control(adapter->hcr_val & ~FLSH, dev); |
| 280 | mdelay(10); |
| 281 | |
| 282 | outb_control(orig_hcr, dev); |
| 283 | if (!start_receive(dev, &adapter->tx_pcb)) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 284 | pr_err("%s: start receive command failed\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* Check to make sure that a DMA transfer hasn't timed out. This should |
| 288 | * never happen in theory, but seems to occur occasionally if the card gets |
| 289 | * prodded at the wrong time. |
| 290 | */ |
| 291 | static inline void check_3c505_dma(struct net_device *dev) |
| 292 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 293 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | if (adapter->dmaing && time_after(jiffies, adapter->current_dma.start_time + 10)) { |
| 295 | unsigned long flags, f; |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 296 | pr_err("%s: DMA %s timed out, %d bytes left\n", dev->name, |
| 297 | adapter->current_dma.direction ? "download" : "upload", |
| 298 | get_dma_residue(dev->dma)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | spin_lock_irqsave(&adapter->lock, flags); |
| 300 | adapter->dmaing = 0; |
| 301 | adapter->busy = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | f=claim_dma_lock(); |
| 304 | disable_dma(dev->dma); |
| 305 | release_dma_lock(f); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | if (adapter->rx_active) |
| 308 | adapter->rx_active--; |
| 309 | outb_control(adapter->hcr_val & ~(DMAE | TCEN | DIR), dev); |
| 310 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /* Primitive functions used by send_pcb() */ |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 315 | static inline bool send_pcb_slow(unsigned int base_addr, unsigned char byte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
| 317 | unsigned long timeout; |
| 318 | outb_command(byte, base_addr); |
| 319 | for (timeout = jiffies + 5*HZ/100; time_before(jiffies, timeout);) { |
| 320 | if (inb_status(base_addr) & HCRE) |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 321 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 323 | pr_warning("3c505: send_pcb_slow timed out\n"); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 324 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 327 | static inline bool send_pcb_fast(unsigned int base_addr, unsigned char byte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
| 329 | unsigned int timeout; |
| 330 | outb_command(byte, base_addr); |
| 331 | for (timeout = 0; timeout < 40000; timeout++) { |
| 332 | if (inb_status(base_addr) & HCRE) |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 333 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 335 | pr_warning("3c505: send_pcb_fast timed out\n"); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 336 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* Check to see if the receiver needs restarting, and kick it if so */ |
| 340 | static inline void prime_rx(struct net_device *dev) |
| 341 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 342 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | while (adapter->rx_active < ELP_RX_PCBS && netif_running(dev)) { |
| 344 | if (!start_receive(dev, &adapter->itx_pcb)) |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /***************************************************************** |
| 350 | * |
| 351 | * send_pcb |
| 352 | * Send a PCB to the adapter. |
| 353 | * |
| 354 | * output byte to command reg --<--+ |
| 355 | * wait until HCRE is non zero | |
| 356 | * loop until all bytes sent -->--+ |
| 357 | * set HSF1 and HSF2 to 1 |
| 358 | * output pcb length |
| 359 | * wait until ASF give ACK or NAK |
| 360 | * set HSF1 and HSF2 to 0 |
| 361 | * |
| 362 | *****************************************************************/ |
| 363 | |
| 364 | /* This can be quite slow -- the adapter is allowed to take up to 40ms |
| 365 | * to respond to the initial interrupt. |
| 366 | * |
| 367 | * We run initially with interrupts turned on, but with a semaphore set |
| 368 | * so that nobody tries to re-enter this code. Once the first byte has |
| 369 | * gone through, we turn interrupts off and then send the others (the |
| 370 | * timeout is reduced to 500us). |
| 371 | */ |
| 372 | |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 373 | static bool send_pcb(struct net_device *dev, pcb_struct * pcb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
| 375 | int i; |
| 376 | unsigned long timeout; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 377 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | unsigned long flags; |
| 379 | |
| 380 | check_3c505_dma(dev); |
| 381 | |
| 382 | if (adapter->dmaing && adapter->current_dma.direction == 0) |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 383 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
| 385 | /* Avoid contention */ |
| 386 | if (test_and_set_bit(1, &adapter->send_pcb_semaphore)) { |
| 387 | if (elp_debug >= 3) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 388 | pr_debug("%s: send_pcb entered while threaded\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 390 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | /* |
| 393 | * load each byte into the command register and |
| 394 | * wait for the HCRE bit to indicate the adapter |
| 395 | * had read the byte |
| 396 | */ |
| 397 | set_hsf(dev, 0); |
| 398 | |
| 399 | if (send_pcb_slow(dev->base_addr, pcb->command)) |
| 400 | goto abort; |
| 401 | |
| 402 | spin_lock_irqsave(&adapter->lock, flags); |
| 403 | |
| 404 | if (send_pcb_fast(dev->base_addr, pcb->length)) |
| 405 | goto sti_abort; |
| 406 | |
| 407 | for (i = 0; i < pcb->length; i++) { |
| 408 | if (send_pcb_fast(dev->base_addr, pcb->data.raw[i])) |
| 409 | goto sti_abort; |
| 410 | } |
| 411 | |
| 412 | outb_control(adapter->hcr_val | 3, dev); /* signal end of PCB */ |
| 413 | outb_command(2 + pcb->length, dev->base_addr); |
| 414 | |
| 415 | /* now wait for the acknowledgement */ |
| 416 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 417 | |
| 418 | for (timeout = jiffies + 5*HZ/100; time_before(jiffies, timeout);) { |
| 419 | switch (GET_ASF(dev->base_addr)) { |
| 420 | case ASF_PCB_ACK: |
| 421 | adapter->send_pcb_semaphore = 0; |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 422 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | case ASF_PCB_NAK: |
| 425 | #ifdef ELP_DEBUG |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 426 | pr_debug("%s: send_pcb got NAK\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | #endif |
| 428 | goto abort; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | if (elp_debug >= 1) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 433 | pr_debug("%s: timeout waiting for PCB acknowledge (status %02x)\n", |
| 434 | dev->name, inb_status(dev->base_addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | goto abort; |
| 436 | |
| 437 | sti_abort: |
| 438 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 439 | abort: |
| 440 | adapter->send_pcb_semaphore = 0; |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 441 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | |
| 445 | /***************************************************************** |
| 446 | * |
| 447 | * receive_pcb |
| 448 | * Read a PCB from the adapter |
| 449 | * |
| 450 | * wait for ACRF to be non-zero ---<---+ |
| 451 | * input a byte | |
| 452 | * if ASF1 and ASF2 were not both one | |
| 453 | * before byte was read, loop --->---+ |
| 454 | * set HSF1 and HSF2 for ack |
| 455 | * |
| 456 | *****************************************************************/ |
| 457 | |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 458 | static bool receive_pcb(struct net_device *dev, pcb_struct * pcb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
| 460 | int i, j; |
| 461 | int total_length; |
| 462 | int stat; |
| 463 | unsigned long timeout; |
| 464 | unsigned long flags; |
| 465 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 466 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | set_hsf(dev, 0); |
| 469 | |
| 470 | /* get the command code */ |
| 471 | timeout = jiffies + 2*HZ/100; |
| 472 | while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && time_before(jiffies, timeout)); |
| 473 | if (time_after_eq(jiffies, timeout)) { |
| 474 | TIMEOUT_MSG(__LINE__); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 475 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | pcb->command = inb_command(dev->base_addr); |
| 478 | |
| 479 | /* read the data length */ |
| 480 | timeout = jiffies + 3*HZ/100; |
| 481 | while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && time_before(jiffies, timeout)); |
| 482 | if (time_after_eq(jiffies, timeout)) { |
| 483 | TIMEOUT_MSG(__LINE__); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 484 | pr_info("%s: status %02x\n", dev->name, stat); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 485 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | pcb->length = inb_command(dev->base_addr); |
| 488 | |
| 489 | if (pcb->length > MAX_PCB_DATA) { |
| 490 | INVALID_PCB_MSG(pcb->length); |
| 491 | adapter_reset(dev); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 492 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | /* read the data */ |
| 495 | spin_lock_irqsave(&adapter->lock, flags); |
Roel Kluin | 501aa06 | 2009-02-12 16:52:31 -0800 | [diff] [blame] | 496 | for (i = 0; i < MAX_PCB_DATA; i++) { |
| 497 | for (j = 0; j < 20000; j++) { |
| 498 | stat = get_status(dev->base_addr); |
| 499 | if (stat & ACRF) |
| 500 | break; |
| 501 | } |
| 502 | pcb->data.raw[i] = inb_command(dev->base_addr); |
| 503 | if ((stat & ASF_PCB_MASK) == ASF_PCB_END || j >= 20000) |
| 504 | break; |
| 505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | spin_unlock_irqrestore(&adapter->lock, flags); |
Roel Kluin | 501aa06 | 2009-02-12 16:52:31 -0800 | [diff] [blame] | 507 | if (i >= MAX_PCB_DATA) { |
| 508 | INVALID_PCB_MSG(i); |
| 509 | return false; |
| 510 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (j >= 20000) { |
| 512 | TIMEOUT_MSG(__LINE__); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 513 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
Roel Kluin | 501aa06 | 2009-02-12 16:52:31 -0800 | [diff] [blame] | 515 | /* the last "data" byte was really the length! */ |
| 516 | total_length = pcb->data.raw[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | /* safety check total length vs data length */ |
| 519 | if (total_length != (pcb->length + 2)) { |
| 520 | if (elp_debug >= 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 521 | pr_warning("%s: mangled PCB received\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | set_hsf(dev, HSF_PCB_NAK); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 523 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | if (pcb->command == CMD_RECEIVE_PACKET_COMPLETE) { |
| 527 | if (test_and_set_bit(0, (void *) &adapter->busy)) { |
| 528 | if (backlog_next(adapter->rx_backlog.in) == adapter->rx_backlog.out) { |
| 529 | set_hsf(dev, HSF_PCB_NAK); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 530 | pr_warning("%s: PCB rejected, transfer in progress and backlog full\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | pcb->command = 0; |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 532 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } else { |
| 534 | pcb->command = 0xff; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | set_hsf(dev, HSF_PCB_ACK); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 539 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /****************************************************** |
| 543 | * |
| 544 | * queue a receive command on the adapter so we will get an |
| 545 | * interrupt when a packet is received. |
| 546 | * |
| 547 | ******************************************************/ |
| 548 | |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 549 | static bool start_receive(struct net_device *dev, pcb_struct * tx_pcb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 551 | bool status; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 552 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 555 | pr_debug("%s: restarting receiver\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | tx_pcb->command = CMD_RECEIVE_PACKET; |
| 557 | tx_pcb->length = sizeof(struct Rcv_pkt); |
| 558 | tx_pcb->data.rcv_pkt.buf_seg |
| 559 | = tx_pcb->data.rcv_pkt.buf_ofs = 0; /* Unused */ |
| 560 | tx_pcb->data.rcv_pkt.buf_len = 1600; |
| 561 | tx_pcb->data.rcv_pkt.timeout = 0; /* set timeout to zero */ |
| 562 | status = send_pcb(dev, tx_pcb); |
| 563 | if (status) |
| 564 | adapter->rx_active++; |
| 565 | return status; |
| 566 | } |
| 567 | |
| 568 | /****************************************************** |
| 569 | * |
| 570 | * extract a packet from the adapter |
| 571 | * this routine is only called from within the interrupt |
| 572 | * service routine, so no cli/sti calls are needed |
| 573 | * note that the length is always assumed to be even |
| 574 | * |
| 575 | ******************************************************/ |
| 576 | |
| 577 | static void receive_packet(struct net_device *dev, int len) |
| 578 | { |
| 579 | int rlen; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 580 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | void *target; |
| 582 | struct sk_buff *skb; |
| 583 | unsigned long flags; |
| 584 | |
| 585 | rlen = (len + 1) & ~1; |
Pradeep A Dalvi | c056b73 | 2012-02-05 02:50:38 +0000 | [diff] [blame] | 586 | skb = netdev_alloc_skb(dev, rlen + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | if (!skb) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 589 | pr_warning("%s: memory squeeze, dropping packet\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | target = adapter->dma_buffer; |
| 591 | adapter->current_dma.target = NULL; |
| 592 | /* FIXME: stats */ |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | skb_reserve(skb, 2); |
| 597 | target = skb_put(skb, rlen); |
| 598 | if ((unsigned long)(target + rlen) >= MAX_DMA_ADDRESS) { |
| 599 | adapter->current_dma.target = target; |
| 600 | target = adapter->dma_buffer; |
| 601 | } else { |
| 602 | adapter->current_dma.target = NULL; |
| 603 | } |
| 604 | |
| 605 | /* if this happens, we die */ |
| 606 | if (test_and_set_bit(0, (void *) &adapter->dmaing)) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 607 | pr_err("%s: rx blocked, DMA in progress, dir %d\n", |
| 608 | dev->name, adapter->current_dma.direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | adapter->current_dma.direction = 0; |
| 611 | adapter->current_dma.length = rlen; |
| 612 | adapter->current_dma.skb = skb; |
| 613 | adapter->current_dma.start_time = jiffies; |
| 614 | |
| 615 | outb_control(adapter->hcr_val | DIR | TCEN | DMAE, dev); |
| 616 | |
| 617 | flags=claim_dma_lock(); |
| 618 | disable_dma(dev->dma); |
| 619 | clear_dma_ff(dev->dma); |
| 620 | set_dma_mode(dev->dma, 0x04); /* dma read */ |
| 621 | set_dma_addr(dev->dma, isa_virt_to_bus(target)); |
| 622 | set_dma_count(dev->dma, rlen); |
| 623 | enable_dma(dev->dma); |
| 624 | release_dma_lock(flags); |
| 625 | |
| 626 | if (elp_debug >= 3) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 627 | pr_debug("%s: rx DMA transfer started\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | if (adapter->rx_active) |
| 631 | adapter->rx_active--; |
| 632 | |
| 633 | if (!adapter->busy) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 634 | pr_warning("%s: receive_packet called, busy not set.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /****************************************************** |
| 638 | * |
| 639 | * interrupt handler |
| 640 | * |
| 641 | ******************************************************/ |
| 642 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 643 | static irqreturn_t elp_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | { |
| 645 | int len; |
| 646 | int dlen; |
| 647 | int icount = 0; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 648 | struct net_device *dev = dev_id; |
| 649 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | unsigned long timeout; |
| 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | spin_lock(&adapter->lock); |
| 653 | |
| 654 | do { |
| 655 | /* |
| 656 | * has a DMA transfer finished? |
| 657 | */ |
| 658 | if (inb_status(dev->base_addr) & DONE) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 659 | if (!adapter->dmaing) |
| 660 | pr_warning("%s: phantom DMA completed\n", dev->name); |
| 661 | |
| 662 | if (elp_debug >= 3) |
| 663 | pr_debug("%s: %s DMA complete, status %02x\n", dev->name, |
| 664 | adapter->current_dma.direction ? "tx" : "rx", |
| 665 | inb_status(dev->base_addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | outb_control(adapter->hcr_val & ~(DMAE | TCEN | DIR), dev); |
| 668 | if (adapter->current_dma.direction) { |
| 669 | dev_kfree_skb_irq(adapter->current_dma.skb); |
| 670 | } else { |
| 671 | struct sk_buff *skb = adapter->current_dma.skb; |
| 672 | if (skb) { |
| 673 | if (adapter->current_dma.target) { |
| 674 | /* have already done the skb_put() */ |
| 675 | memcpy(adapter->current_dma.target, adapter->dma_buffer, adapter->current_dma.length); |
| 676 | } |
| 677 | skb->protocol = eth_type_trans(skb,dev); |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 678 | dev->stats.rx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | adapter->dmaing = 0; |
| 683 | if (adapter->rx_backlog.in != adapter->rx_backlog.out) { |
| 684 | int t = adapter->rx_backlog.length[adapter->rx_backlog.out]; |
| 685 | adapter->rx_backlog.out = backlog_next(adapter->rx_backlog.out); |
| 686 | if (elp_debug >= 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 687 | pr_debug("%s: receiving backlogged packet (%d)\n", dev->name, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | receive_packet(dev, t); |
| 689 | } else { |
| 690 | adapter->busy = 0; |
| 691 | } |
| 692 | } else { |
| 693 | /* has one timed out? */ |
| 694 | check_3c505_dma(dev); |
| 695 | } |
| 696 | |
| 697 | /* |
| 698 | * receive a PCB from the adapter |
| 699 | */ |
| 700 | timeout = jiffies + 3*HZ/100; |
| 701 | while ((inb_status(dev->base_addr) & ACRF) != 0 && time_before(jiffies, timeout)) { |
| 702 | if (receive_pcb(dev, &adapter->irx_pcb)) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 703 | switch (adapter->irx_pcb.command) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | { |
| 705 | case 0: |
| 706 | break; |
| 707 | /* |
| 708 | * received a packet - this must be handled fast |
| 709 | */ |
| 710 | case 0xff: |
| 711 | case CMD_RECEIVE_PACKET_COMPLETE: |
| 712 | /* if the device isn't open, don't pass packets up the stack */ |
| 713 | if (!netif_running(dev)) |
| 714 | break; |
| 715 | len = adapter->irx_pcb.data.rcv_resp.pkt_len; |
| 716 | dlen = adapter->irx_pcb.data.rcv_resp.buf_len; |
| 717 | if (adapter->irx_pcb.data.rcv_resp.timeout != 0) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 718 | pr_err("%s: interrupt - packet not received correctly\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } else { |
| 720 | if (elp_debug >= 3) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 721 | pr_debug("%s: interrupt - packet received of length %i (%i)\n", |
| 722 | dev->name, len, dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | if (adapter->irx_pcb.command == 0xff) { |
| 725 | if (elp_debug >= 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 726 | pr_debug("%s: adding packet to backlog (len = %d)\n", |
| 727 | dev->name, dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | adapter->rx_backlog.length[adapter->rx_backlog.in] = dlen; |
| 729 | adapter->rx_backlog.in = backlog_next(adapter->rx_backlog.in); |
| 730 | } else { |
| 731 | receive_packet(dev, dlen); |
| 732 | } |
| 733 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 734 | pr_debug("%s: packet received\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | break; |
| 737 | |
| 738 | /* |
| 739 | * 82586 configured correctly |
| 740 | */ |
| 741 | case CMD_CONFIGURE_82586_RESPONSE: |
| 742 | adapter->got[CMD_CONFIGURE_82586] = 1; |
| 743 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 744 | pr_debug("%s: interrupt - configure response received\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | break; |
| 746 | |
| 747 | /* |
| 748 | * Adapter memory configuration |
| 749 | */ |
| 750 | case CMD_CONFIGURE_ADAPTER_RESPONSE: |
| 751 | adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1; |
| 752 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 753 | pr_debug("%s: Adapter memory configuration %s.\n", dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | adapter->irx_pcb.data.failed ? "failed" : "succeeded"); |
| 755 | break; |
| 756 | |
| 757 | /* |
| 758 | * Multicast list loading |
| 759 | */ |
| 760 | case CMD_LOAD_MULTICAST_RESPONSE: |
| 761 | adapter->got[CMD_LOAD_MULTICAST_LIST] = 1; |
| 762 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 763 | pr_debug("%s: Multicast address list loading %s.\n", dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | adapter->irx_pcb.data.failed ? "failed" : "succeeded"); |
| 765 | break; |
| 766 | |
| 767 | /* |
| 768 | * Station address setting |
| 769 | */ |
| 770 | case CMD_SET_ADDRESS_RESPONSE: |
| 771 | adapter->got[CMD_SET_STATION_ADDRESS] = 1; |
| 772 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 773 | pr_debug("%s: Ethernet address setting %s.\n", dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | adapter->irx_pcb.data.failed ? "failed" : "succeeded"); |
| 775 | break; |
| 776 | |
| 777 | |
| 778 | /* |
| 779 | * received board statistics |
| 780 | */ |
| 781 | case CMD_NETWORK_STATISTICS_RESPONSE: |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 782 | dev->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv; |
| 783 | dev->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit; |
| 784 | dev->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC; |
| 785 | dev->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align; |
| 786 | dev->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun; |
| 787 | dev->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | adapter->got[CMD_NETWORK_STATISTICS] = 1; |
| 789 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 790 | pr_debug("%s: interrupt - statistics response received\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | break; |
| 792 | |
| 793 | /* |
| 794 | * sent a packet |
| 795 | */ |
| 796 | case CMD_TRANSMIT_PACKET_COMPLETE: |
| 797 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 798 | pr_debug("%s: interrupt - packet sent\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | if (!netif_running(dev)) |
| 800 | break; |
| 801 | switch (adapter->irx_pcb.data.xmit_resp.c_stat) { |
| 802 | case 0xffff: |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 803 | dev->stats.tx_aborted_errors++; |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 804 | pr_info("%s: transmit timed out, network cable problem?\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | break; |
| 806 | case 0xfffe: |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 807 | dev->stats.tx_fifo_errors++; |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 808 | pr_info("%s: transmit timed out, FIFO underrun\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | break; |
| 810 | } |
| 811 | netif_wake_queue(dev); |
| 812 | break; |
| 813 | |
| 814 | /* |
| 815 | * some unknown PCB |
| 816 | */ |
| 817 | default: |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 818 | pr_debug("%s: unknown PCB received - %2.2x\n", |
| 819 | dev->name, adapter->irx_pcb.command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | break; |
| 821 | } |
| 822 | } else { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 823 | pr_warning("%s: failed to read PCB on interrupt\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | adapter_reset(dev); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | } while (icount++ < 5 && (inb_status(dev->base_addr) & (ACRF | DONE))); |
| 829 | |
| 830 | prime_rx(dev); |
| 831 | |
| 832 | /* |
| 833 | * indicate no longer in interrupt routine |
| 834 | */ |
| 835 | spin_unlock(&adapter->lock); |
| 836 | return IRQ_HANDLED; |
| 837 | } |
| 838 | |
| 839 | |
| 840 | /****************************************************** |
| 841 | * |
| 842 | * open the board |
| 843 | * |
| 844 | ******************************************************/ |
| 845 | |
| 846 | static int elp_open(struct net_device *dev) |
| 847 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 848 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | int retval; |
| 850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 852 | pr_debug("%s: request to open device\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
| 854 | /* |
| 855 | * make sure we actually found the device |
| 856 | */ |
| 857 | if (adapter == NULL) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 858 | pr_err("%s: Opening a non-existent physical device\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | return -EAGAIN; |
| 860 | } |
| 861 | /* |
| 862 | * disable interrupts on the board |
| 863 | */ |
| 864 | outb_control(0, dev); |
| 865 | |
| 866 | /* |
| 867 | * clear any pending interrupts |
| 868 | */ |
| 869 | inb_command(dev->base_addr); |
| 870 | adapter_reset(dev); |
| 871 | |
| 872 | /* |
| 873 | * no receive PCBs active |
| 874 | */ |
| 875 | adapter->rx_active = 0; |
| 876 | |
| 877 | adapter->busy = 0; |
| 878 | adapter->send_pcb_semaphore = 0; |
| 879 | adapter->rx_backlog.in = 0; |
| 880 | adapter->rx_backlog.out = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | spin_lock_init(&adapter->lock); |
| 883 | |
| 884 | /* |
| 885 | * install our interrupt service routine |
| 886 | */ |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 887 | if ((retval = request_irq(dev->irq, elp_interrupt, 0, dev->name, dev))) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 888 | pr_err("%s: could not allocate IRQ%d\n", dev->name, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | return retval; |
| 890 | } |
| 891 | if ((retval = request_dma(dev->dma, dev->name))) { |
| 892 | free_irq(dev->irq, dev); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 893 | pr_err("%s: could not allocate DMA%d channel\n", dev->name, dev->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | return retval; |
| 895 | } |
| 896 | adapter->dma_buffer = (void *) dma_mem_alloc(DMA_BUFFER_SIZE); |
| 897 | if (!adapter->dma_buffer) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 898 | pr_err("%s: could not allocate DMA buffer\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | free_dma(dev->dma); |
| 900 | free_irq(dev->irq, dev); |
| 901 | return -ENOMEM; |
| 902 | } |
| 903 | adapter->dmaing = 0; |
| 904 | |
| 905 | /* |
| 906 | * enable interrupts on the board |
| 907 | */ |
| 908 | outb_control(CMDE, dev); |
| 909 | |
| 910 | /* |
| 911 | * configure adapter memory: we need 10 multicast addresses, default==0 |
| 912 | */ |
| 913 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 914 | pr_debug("%s: sending 3c505 memory configuration command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY; |
| 916 | adapter->tx_pcb.data.memconf.cmd_q = 10; |
| 917 | adapter->tx_pcb.data.memconf.rcv_q = 20; |
| 918 | adapter->tx_pcb.data.memconf.mcast = 10; |
| 919 | adapter->tx_pcb.data.memconf.frame = 20; |
| 920 | adapter->tx_pcb.data.memconf.rcv_b = 20; |
| 921 | adapter->tx_pcb.data.memconf.progs = 0; |
| 922 | adapter->tx_pcb.length = sizeof(struct Memconf); |
| 923 | adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0; |
| 924 | if (!send_pcb(dev, &adapter->tx_pcb)) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 925 | pr_err("%s: couldn't send memory configuration command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | else { |
| 927 | unsigned long timeout = jiffies + TIMEOUT; |
| 928 | while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && time_before(jiffies, timeout)); |
| 929 | if (time_after_eq(jiffies, timeout)) |
| 930 | TIMEOUT_MSG(__LINE__); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | /* |
| 935 | * configure adapter to receive broadcast messages and wait for response |
| 936 | */ |
| 937 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 938 | pr_debug("%s: sending 82586 configure command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | adapter->tx_pcb.command = CMD_CONFIGURE_82586; |
| 940 | adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD; |
| 941 | adapter->tx_pcb.length = 2; |
| 942 | adapter->got[CMD_CONFIGURE_82586] = 0; |
| 943 | if (!send_pcb(dev, &adapter->tx_pcb)) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 944 | pr_err("%s: couldn't send 82586 configure command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | else { |
| 946 | unsigned long timeout = jiffies + TIMEOUT; |
| 947 | while (adapter->got[CMD_CONFIGURE_82586] == 0 && time_before(jiffies, timeout)); |
| 948 | if (time_after_eq(jiffies, timeout)) |
| 949 | TIMEOUT_MSG(__LINE__); |
| 950 | } |
| 951 | |
| 952 | /* enable burst-mode DMA */ |
| 953 | /* outb(0x1, dev->base_addr + PORT_AUXDMA); */ |
| 954 | |
| 955 | /* |
| 956 | * queue receive commands to provide buffering |
| 957 | */ |
| 958 | prime_rx(dev); |
| 959 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 960 | pr_debug("%s: %d receive PCBs active\n", dev->name, adapter->rx_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | /* |
| 963 | * device is now officially open! |
| 964 | */ |
| 965 | |
| 966 | netif_start_queue(dev); |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | |
| 971 | /****************************************************** |
| 972 | * |
| 973 | * send a packet to the adapter |
| 974 | * |
| 975 | ******************************************************/ |
| 976 | |
Stephen Hemminger | 27a1de9 | 2009-08-31 19:50:54 +0000 | [diff] [blame] | 977 | static netdev_tx_t send_packet(struct net_device *dev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 979 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | unsigned long target; |
| 981 | unsigned long flags; |
| 982 | |
| 983 | /* |
| 984 | * make sure the length is even and no shorter than 60 bytes |
| 985 | */ |
| 986 | unsigned int nlen = (((skb->len < 60) ? 60 : skb->len) + 1) & (~1); |
| 987 | |
| 988 | if (test_and_set_bit(0, (void *) &adapter->busy)) { |
| 989 | if (elp_debug >= 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 990 | pr_debug("%s: transmit blocked\n", dev->name); |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 991 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 994 | dev->stats.tx_bytes += nlen; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | /* |
| 997 | * send the adapter a transmit packet command. Ignore segment and offset |
| 998 | * and make sure the length is even |
| 999 | */ |
| 1000 | adapter->tx_pcb.command = CMD_TRANSMIT_PACKET; |
| 1001 | adapter->tx_pcb.length = sizeof(struct Xmit_pkt); |
| 1002 | adapter->tx_pcb.data.xmit_pkt.buf_ofs |
| 1003 | = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0; /* Unused */ |
| 1004 | adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen; |
| 1005 | |
| 1006 | if (!send_pcb(dev, &adapter->tx_pcb)) { |
| 1007 | adapter->busy = 0; |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 1008 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | } |
| 1010 | /* if this happens, we die */ |
| 1011 | if (test_and_set_bit(0, (void *) &adapter->dmaing)) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1012 | pr_debug("%s: tx: DMA %d in progress\n", dev->name, adapter->current_dma.direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
| 1014 | adapter->current_dma.direction = 1; |
| 1015 | adapter->current_dma.start_time = jiffies; |
| 1016 | |
| 1017 | if ((unsigned long)(skb->data + nlen) >= MAX_DMA_ADDRESS || nlen != skb->len) { |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1018 | skb_copy_from_linear_data(skb, adapter->dma_buffer, nlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | memset(adapter->dma_buffer+skb->len, 0, nlen-skb->len); |
| 1020 | target = isa_virt_to_bus(adapter->dma_buffer); |
| 1021 | } |
| 1022 | else { |
| 1023 | target = isa_virt_to_bus(skb->data); |
| 1024 | } |
| 1025 | adapter->current_dma.skb = skb; |
| 1026 | |
| 1027 | flags=claim_dma_lock(); |
| 1028 | disable_dma(dev->dma); |
| 1029 | clear_dma_ff(dev->dma); |
| 1030 | set_dma_mode(dev->dma, 0x48); /* dma memory -> io */ |
| 1031 | set_dma_addr(dev->dma, target); |
| 1032 | set_dma_count(dev->dma, nlen); |
| 1033 | outb_control(adapter->hcr_val | DMAE | TCEN, dev); |
| 1034 | enable_dma(dev->dma); |
| 1035 | release_dma_lock(flags); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1038 | pr_debug("%s: DMA transfer started\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
Richard Knutsson | df570f9 | 2007-08-14 01:49:40 +0200 | [diff] [blame] | 1040 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* |
| 1044 | * The upper layer thinks we timed out |
| 1045 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | static void elp_timeout(struct net_device *dev) |
| 1048 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | int stat; |
| 1050 | |
| 1051 | stat = inb_status(dev->base_addr); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1052 | pr_warning("%s: transmit timed out, lost %s?\n", dev->name, |
| 1053 | (stat & ACRF) ? "interrupt" : "command"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | if (elp_debug >= 1) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1055 | pr_debug("%s: status %#02x\n", dev->name, stat); |
Eric Dumazet | 1ae5dc3 | 2010-05-10 05:01:31 -0700 | [diff] [blame] | 1056 | dev->trans_start = jiffies; /* prevent tx timeout */ |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 1057 | dev->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | netif_wake_queue(dev); |
| 1059 | } |
| 1060 | |
| 1061 | /****************************************************** |
| 1062 | * |
| 1063 | * start the transmitter |
| 1064 | * return 0 if sent OK, else return 1 |
| 1065 | * |
| 1066 | ******************************************************/ |
| 1067 | |
Stephen Hemminger | 27a1de9 | 2009-08-31 19:50:54 +0000 | [diff] [blame] | 1068 | static netdev_tx_t elp_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | { |
| 1070 | unsigned long flags; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1071 | elp_device *adapter = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | spin_lock_irqsave(&adapter->lock, flags); |
| 1074 | check_3c505_dma(dev); |
| 1075 | |
| 1076 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1077 | pr_debug("%s: request to send packet of length %d\n", dev->name, (int) skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | netif_stop_queue(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | /* |
| 1082 | * send the packet at skb->data for skb->len |
| 1083 | */ |
| 1084 | if (!send_packet(dev, skb)) { |
| 1085 | if (elp_debug >= 2) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1086 | pr_debug("%s: failed to transmit packet\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | } |
| 1088 | spin_unlock_irqrestore(&adapter->lock, flags); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1089 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1092 | pr_debug("%s: packet of length %d sent\n", dev->name, (int) skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | prime_rx(dev); |
| 1095 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1096 | netif_start_queue(dev); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1097 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /****************************************************** |
| 1101 | * |
| 1102 | * return statistics on the board |
| 1103 | * |
| 1104 | ******************************************************/ |
| 1105 | |
| 1106 | static struct net_device_stats *elp_get_stats(struct net_device *dev) |
| 1107 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1108 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
| 1110 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1111 | pr_debug("%s: request for stats\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
| 1113 | /* If the device is closed, just return the latest stats we have, |
| 1114 | - we cannot ask from the adapter without interrupts */ |
| 1115 | if (!netif_running(dev)) |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 1116 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
| 1118 | /* send a get statistics command to the board */ |
| 1119 | adapter->tx_pcb.command = CMD_NETWORK_STATISTICS; |
| 1120 | adapter->tx_pcb.length = 0; |
| 1121 | adapter->got[CMD_NETWORK_STATISTICS] = 0; |
| 1122 | if (!send_pcb(dev, &adapter->tx_pcb)) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1123 | pr_err("%s: couldn't send get statistics command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | else { |
| 1125 | unsigned long timeout = jiffies + TIMEOUT; |
| 1126 | while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && time_before(jiffies, timeout)); |
| 1127 | if (time_after_eq(jiffies, timeout)) { |
| 1128 | TIMEOUT_MSG(__LINE__); |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 1129 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | /* statistics are now up to date */ |
Paulius Zaleckas | ba0f6ca | 2008-04-29 02:27:37 +0300 | [diff] [blame] | 1134 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | static void netdev_get_drvinfo(struct net_device *dev, |
| 1139 | struct ethtool_drvinfo *info) |
| 1140 | { |
| 1141 | strcpy(info->driver, DRV_NAME); |
| 1142 | strcpy(info->version, DRV_VERSION); |
| 1143 | sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr); |
| 1144 | } |
| 1145 | |
| 1146 | static u32 netdev_get_msglevel(struct net_device *dev) |
| 1147 | { |
| 1148 | return debug; |
| 1149 | } |
| 1150 | |
| 1151 | static void netdev_set_msglevel(struct net_device *dev, u32 level) |
| 1152 | { |
| 1153 | debug = level; |
| 1154 | } |
| 1155 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1156 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | .get_drvinfo = netdev_get_drvinfo, |
| 1158 | .get_msglevel = netdev_get_msglevel, |
| 1159 | .set_msglevel = netdev_set_msglevel, |
| 1160 | }; |
| 1161 | |
| 1162 | /****************************************************** |
| 1163 | * |
| 1164 | * close the board |
| 1165 | * |
| 1166 | ******************************************************/ |
| 1167 | |
| 1168 | static int elp_close(struct net_device *dev) |
| 1169 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1170 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
| 1172 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1173 | pr_debug("%s: request to close device\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
| 1175 | netif_stop_queue(dev); |
| 1176 | |
| 1177 | /* Someone may request the device statistic information even when |
| 1178 | * the interface is closed. The following will update the statistics |
| 1179 | * structure in the driver, so we'll be able to give current statistics. |
| 1180 | */ |
| 1181 | (void) elp_get_stats(dev); |
| 1182 | |
| 1183 | /* |
| 1184 | * disable interrupts on the board |
| 1185 | */ |
| 1186 | outb_control(0, dev); |
| 1187 | |
| 1188 | /* |
| 1189 | * release the IRQ |
| 1190 | */ |
| 1191 | free_irq(dev->irq, dev); |
| 1192 | |
| 1193 | free_dma(dev->dma); |
| 1194 | free_pages((unsigned long) adapter->dma_buffer, get_order(DMA_BUFFER_SIZE)); |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | |
| 1200 | /************************************************************ |
| 1201 | * |
| 1202 | * Set multicast list |
| 1203 | * num_addrs==0: clear mc_list |
| 1204 | * num_addrs==-1: set promiscuous mode |
| 1205 | * num_addrs>0: set mc_list |
| 1206 | * |
| 1207 | ************************************************************/ |
| 1208 | |
| 1209 | static void elp_set_mc_list(struct net_device *dev) |
| 1210 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1211 | elp_device *adapter = netdev_priv(dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1212 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | int i; |
| 1214 | unsigned long flags; |
| 1215 | |
| 1216 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1217 | pr_debug("%s: request to set multicast list\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
| 1219 | spin_lock_irqsave(&adapter->lock, flags); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | if (!(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) { |
| 1222 | /* send a "load multicast list" command to the board, max 10 addrs/cmd */ |
| 1223 | /* if num_addrs==0 the list will be cleared */ |
| 1224 | adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST; |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1225 | adapter->tx_pcb.length = 6 * netdev_mc_count(dev); |
Jiri Pirko | 59ce25d | 2010-02-17 23:12:15 +0000 | [diff] [blame] | 1226 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1227 | netdev_for_each_mc_addr(ha, dev) |
| 1228 | memcpy(adapter->tx_pcb.data.multicast[i++], |
| 1229 | ha->addr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | adapter->got[CMD_LOAD_MULTICAST_LIST] = 0; |
| 1231 | if (!send_pcb(dev, &adapter->tx_pcb)) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1232 | pr_err("%s: couldn't send set_multicast command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | else { |
| 1234 | unsigned long timeout = jiffies + TIMEOUT; |
| 1235 | while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && time_before(jiffies, timeout)); |
| 1236 | if (time_after_eq(jiffies, timeout)) { |
| 1237 | TIMEOUT_MSG(__LINE__); |
| 1238 | } |
| 1239 | } |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1240 | if (!netdev_mc_empty(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI; |
| 1242 | else /* num_addrs == 0 */ |
| 1243 | adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD; |
| 1244 | } else |
| 1245 | adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC; |
| 1246 | /* |
| 1247 | * configure adapter to receive messages (as specified above) |
| 1248 | * and wait for response |
| 1249 | */ |
| 1250 | if (elp_debug >= 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1251 | pr_debug("%s: sending 82586 configure command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | adapter->tx_pcb.command = CMD_CONFIGURE_82586; |
| 1253 | adapter->tx_pcb.length = 2; |
| 1254 | adapter->got[CMD_CONFIGURE_82586] = 0; |
| 1255 | if (!send_pcb(dev, &adapter->tx_pcb)) |
| 1256 | { |
| 1257 | spin_unlock_irqrestore(&adapter->lock, flags); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1258 | pr_err("%s: couldn't send 82586 configure command\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
| 1260 | else { |
| 1261 | unsigned long timeout = jiffies + TIMEOUT; |
| 1262 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1263 | while (adapter->got[CMD_CONFIGURE_82586] == 0 && time_before(jiffies, timeout)); |
| 1264 | if (time_after_eq(jiffies, timeout)) |
| 1265 | TIMEOUT_MSG(__LINE__); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /************************************************************ |
| 1270 | * |
| 1271 | * A couple of tests to see if there's 3C505 or not |
| 1272 | * Called only by elp_autodetect |
| 1273 | ************************************************************/ |
| 1274 | |
| 1275 | static int __init elp_sense(struct net_device *dev) |
| 1276 | { |
| 1277 | int addr = dev->base_addr; |
| 1278 | const char *name = dev->name; |
| 1279 | byte orig_HSR; |
| 1280 | |
| 1281 | if (!request_region(addr, ELP_IO_EXTENT, "3c505")) |
| 1282 | return -ENODEV; |
| 1283 | |
| 1284 | orig_HSR = inb_status(addr); |
| 1285 | |
| 1286 | if (elp_debug > 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1287 | pr_debug(search_msg, name, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
| 1289 | if (orig_HSR == 0xff) { |
| 1290 | if (elp_debug > 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1291 | pr_cont(notfound_msg, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | goto out; |
| 1293 | } |
| 1294 | |
| 1295 | /* Wait for a while; the adapter may still be booting up */ |
| 1296 | if (elp_debug > 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1297 | pr_cont(stilllooking_msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | |
| 1299 | if (orig_HSR & DIR) { |
| 1300 | /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */ |
| 1301 | outb(0, dev->base_addr + PORT_CONTROL); |
Domen Puncer | c56943e | 2005-05-12 22:21:51 -0400 | [diff] [blame] | 1302 | msleep(300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | if (inb_status(addr) & DIR) { |
| 1304 | if (elp_debug > 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1305 | pr_cont(notfound_msg, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | goto out; |
| 1307 | } |
| 1308 | } else { |
| 1309 | /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */ |
| 1310 | outb(DIR, dev->base_addr + PORT_CONTROL); |
Domen Puncer | c56943e | 2005-05-12 22:21:51 -0400 | [diff] [blame] | 1311 | msleep(300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | if (!(inb_status(addr) & DIR)) { |
| 1313 | if (elp_debug > 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1314 | pr_cont(notfound_msg, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | goto out; |
| 1316 | } |
| 1317 | } |
| 1318 | /* |
| 1319 | * It certainly looks like a 3c505. |
| 1320 | */ |
| 1321 | if (elp_debug > 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1322 | pr_cont(found_msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
| 1324 | return 0; |
| 1325 | out: |
| 1326 | release_region(addr, ELP_IO_EXTENT); |
| 1327 | return -ENODEV; |
| 1328 | } |
| 1329 | |
| 1330 | /************************************************************* |
| 1331 | * |
| 1332 | * Search through addr_list[] and try to find a 3C505 |
| 1333 | * Called only by eplus_probe |
| 1334 | *************************************************************/ |
| 1335 | |
| 1336 | static int __init elp_autodetect(struct net_device *dev) |
| 1337 | { |
| 1338 | int idx = 0; |
| 1339 | |
| 1340 | /* if base address set, then only check that address |
| 1341 | otherwise, run through the table */ |
| 1342 | if (dev->base_addr != 0) { /* dev->base_addr == 0 ==> plain autodetect */ |
| 1343 | if (elp_sense(dev) == 0) |
| 1344 | return dev->base_addr; |
| 1345 | } else |
| 1346 | while ((dev->base_addr = addr_list[idx++])) { |
| 1347 | if (elp_sense(dev) == 0) |
| 1348 | return dev->base_addr; |
| 1349 | } |
| 1350 | |
| 1351 | /* could not find an adapter */ |
| 1352 | if (elp_debug > 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1353 | pr_debug(couldnot_msg, dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | |
| 1355 | return 0; /* Because of this, the layer above will return -ENODEV */ |
| 1356 | } |
| 1357 | |
Stephen Hemminger | e6c42b7 | 2009-01-09 13:01:12 +0000 | [diff] [blame] | 1358 | static const struct net_device_ops elp_netdev_ops = { |
| 1359 | .ndo_open = elp_open, |
| 1360 | .ndo_stop = elp_close, |
| 1361 | .ndo_get_stats = elp_get_stats, |
| 1362 | .ndo_start_xmit = elp_start_xmit, |
| 1363 | .ndo_tx_timeout = elp_timeout, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1364 | .ndo_set_rx_mode = elp_set_mc_list, |
Stephen Hemminger | e6c42b7 | 2009-01-09 13:01:12 +0000 | [diff] [blame] | 1365 | .ndo_change_mtu = eth_change_mtu, |
| 1366 | .ndo_set_mac_address = eth_mac_addr, |
| 1367 | .ndo_validate_addr = eth_validate_addr, |
| 1368 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | /****************************************************** |
| 1371 | * |
| 1372 | * probe for an Etherlink Plus board at the specified address |
| 1373 | * |
| 1374 | ******************************************************/ |
| 1375 | |
| 1376 | /* There are three situations we need to be able to detect here: |
| 1377 | |
| 1378 | * a) the card is idle |
| 1379 | * b) the card is still booting up |
| 1380 | * c) the card is stuck in a strange state (some DOS drivers do this) |
| 1381 | * |
| 1382 | * In case (a), all is well. In case (b), we wait 10 seconds to see if the |
| 1383 | * card finishes booting, and carry on if so. In case (c), we do a hard reset, |
| 1384 | * loop round, and hope for the best. |
| 1385 | * |
| 1386 | * This is all very unpleasant, but hopefully avoids the problems with the old |
| 1387 | * probe code (which had a 15-second delay if the card was idle, and didn't |
| 1388 | * work at all if it was in a weird state). |
| 1389 | */ |
| 1390 | |
| 1391 | static int __init elplus_setup(struct net_device *dev) |
| 1392 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1393 | elp_device *adapter = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | int i, tries, tries1, okay; |
| 1395 | unsigned long timeout; |
| 1396 | unsigned long cookie = 0; |
| 1397 | int err = -ENODEV; |
| 1398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | /* |
| 1400 | * setup adapter structure |
| 1401 | */ |
| 1402 | |
| 1403 | dev->base_addr = elp_autodetect(dev); |
| 1404 | if (!dev->base_addr) |
| 1405 | return -ENODEV; |
| 1406 | |
| 1407 | adapter->send_pcb_semaphore = 0; |
| 1408 | |
| 1409 | for (tries1 = 0; tries1 < 3; tries1++) { |
| 1410 | outb_control((adapter->hcr_val | CMDE) & ~DIR, dev); |
| 1411 | /* First try to write just one byte, to see if the card is |
| 1412 | * responding at all normally. |
| 1413 | */ |
| 1414 | timeout = jiffies + 5*HZ/100; |
| 1415 | okay = 0; |
| 1416 | while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE)); |
| 1417 | if ((inb_status(dev->base_addr) & HCRE)) { |
| 1418 | outb_command(0, dev->base_addr); /* send a spurious byte */ |
| 1419 | timeout = jiffies + 5*HZ/100; |
| 1420 | while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE)); |
| 1421 | if (inb_status(dev->base_addr) & HCRE) |
| 1422 | okay = 1; |
| 1423 | } |
| 1424 | if (!okay) { |
| 1425 | /* Nope, it's ignoring the command register. This means that |
| 1426 | * either it's still booting up, or it's died. |
| 1427 | */ |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1428 | pr_err("%s: command register wouldn't drain, ", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | if ((inb_status(dev->base_addr) & 7) == 3) { |
| 1430 | /* If the adapter status is 3, it *could* still be booting. |
| 1431 | * Give it the benefit of the doubt for 10 seconds. |
| 1432 | */ |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1433 | pr_cont("assuming 3c505 still starting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | timeout = jiffies + 10*HZ; |
| 1435 | while (time_before(jiffies, timeout) && (inb_status(dev->base_addr) & 7)); |
| 1436 | if (inb_status(dev->base_addr) & 7) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1437 | pr_err("%s: 3c505 failed to start\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | } else { |
| 1439 | okay = 1; /* It started */ |
| 1440 | } |
| 1441 | } else { |
| 1442 | /* Otherwise, it must just be in a strange |
| 1443 | * state. We probably need to kick it. |
| 1444 | */ |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1445 | pr_cont("3c505 is sulking\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | for (tries = 0; tries < 5 && okay; tries++) { |
| 1449 | |
| 1450 | /* |
| 1451 | * Try to set the Ethernet address, to make sure that the board |
| 1452 | * is working. |
| 1453 | */ |
| 1454 | adapter->tx_pcb.command = CMD_STATION_ADDRESS; |
| 1455 | adapter->tx_pcb.length = 0; |
| 1456 | cookie = probe_irq_on(); |
| 1457 | if (!send_pcb(dev, &adapter->tx_pcb)) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1458 | pr_err("%s: could not send first PCB\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | probe_irq_off(cookie); |
| 1460 | continue; |
| 1461 | } |
| 1462 | if (!receive_pcb(dev, &adapter->rx_pcb)) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1463 | pr_err("%s: could not read first PCB\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | probe_irq_off(cookie); |
| 1465 | continue; |
| 1466 | } |
| 1467 | if ((adapter->rx_pcb.command != CMD_ADDRESS_RESPONSE) || |
| 1468 | (adapter->rx_pcb.length != 6)) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1469 | pr_err("%s: first PCB wrong (%d, %d)\n", dev->name, |
| 1470 | adapter->rx_pcb.command, adapter->rx_pcb.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | probe_irq_off(cookie); |
| 1472 | continue; |
| 1473 | } |
| 1474 | goto okay; |
| 1475 | } |
| 1476 | /* It's broken. Do a hard reset to re-initialise the board, |
| 1477 | * and try again. |
| 1478 | */ |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1479 | pr_info("%s: resetting adapter\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | outb_control(adapter->hcr_val | FLSH | ATTN, dev); |
| 1481 | outb_control(adapter->hcr_val & ~(FLSH | ATTN), dev); |
| 1482 | } |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1483 | pr_err("%s: failed to initialise 3c505\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | goto out; |
| 1485 | |
| 1486 | okay: |
| 1487 | if (dev->irq) { /* Is there a preset IRQ? */ |
| 1488 | int rpt = probe_irq_off(cookie); |
| 1489 | if (dev->irq != rpt) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1490 | pr_warning("%s: warning, irq %d configured but %d detected\n", dev->name, dev->irq, rpt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | } |
| 1492 | /* if dev->irq == probe_irq_off(cookie), all is well */ |
| 1493 | } else /* No preset IRQ; just use what we can detect */ |
| 1494 | dev->irq = probe_irq_off(cookie); |
| 1495 | switch (dev->irq) { /* Legal, sane? */ |
| 1496 | case 0: |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1497 | pr_err("%s: IRQ probe failed: check 3c505 jumpers.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | dev->name); |
| 1499 | goto out; |
| 1500 | case 1: |
| 1501 | case 6: |
| 1502 | case 8: |
| 1503 | case 13: |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1504 | pr_err("%s: Impossible IRQ %d reported by probe_irq_off().\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | dev->name, dev->irq); |
| 1506 | goto out; |
| 1507 | } |
| 1508 | /* |
| 1509 | * Now we have the IRQ number so we can disable the interrupts from |
| 1510 | * the board until the board is opened. |
| 1511 | */ |
| 1512 | outb_control(adapter->hcr_val & ~CMDE, dev); |
| 1513 | |
| 1514 | /* |
| 1515 | * copy Ethernet address into structure |
| 1516 | */ |
| 1517 | for (i = 0; i < 6; i++) |
| 1518 | dev->dev_addr[i] = adapter->rx_pcb.data.eth_addr[i]; |
| 1519 | |
| 1520 | /* find a DMA channel */ |
| 1521 | if (!dev->dma) { |
| 1522 | if (dev->mem_start) { |
| 1523 | dev->dma = dev->mem_start & 7; |
| 1524 | } |
| 1525 | else { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1526 | pr_warning("%s: warning, DMA channel not specified, using default\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | dev->dma = ELP_DMA; |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | /* |
| 1532 | * print remainder of startup message |
| 1533 | */ |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1534 | pr_info("%s: 3c505 at %#lx, irq %d, dma %d, addr %pM, ", |
| 1535 | dev->name, dev->base_addr, dev->irq, dev->dma, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | /* |
| 1537 | * read more information from the adapter |
| 1538 | */ |
| 1539 | |
| 1540 | adapter->tx_pcb.command = CMD_ADAPTER_INFO; |
| 1541 | adapter->tx_pcb.length = 0; |
| 1542 | if (!send_pcb(dev, &adapter->tx_pcb) || |
| 1543 | !receive_pcb(dev, &adapter->rx_pcb) || |
| 1544 | (adapter->rx_pcb.command != CMD_ADAPTER_INFO_RESPONSE) || |
| 1545 | (adapter->rx_pcb.length != 10)) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1546 | pr_cont("not responding to second PCB\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | } |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1548 | pr_cont("rev %d.%d, %dk\n", adapter->rx_pcb.data.info.major_vers, |
| 1549 | adapter->rx_pcb.data.info.minor_vers, adapter->rx_pcb.data.info.RAM_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
| 1551 | /* |
| 1552 | * reconfigure the adapter memory to better suit our purposes |
| 1553 | */ |
| 1554 | adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY; |
| 1555 | adapter->tx_pcb.length = 12; |
| 1556 | adapter->tx_pcb.data.memconf.cmd_q = 8; |
| 1557 | adapter->tx_pcb.data.memconf.rcv_q = 8; |
| 1558 | adapter->tx_pcb.data.memconf.mcast = 10; |
| 1559 | adapter->tx_pcb.data.memconf.frame = 10; |
| 1560 | adapter->tx_pcb.data.memconf.rcv_b = 10; |
| 1561 | adapter->tx_pcb.data.memconf.progs = 0; |
| 1562 | if (!send_pcb(dev, &adapter->tx_pcb) || |
| 1563 | !receive_pcb(dev, &adapter->rx_pcb) || |
| 1564 | (adapter->rx_pcb.command != CMD_CONFIGURE_ADAPTER_RESPONSE) || |
| 1565 | (adapter->rx_pcb.length != 2)) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1566 | pr_err("%s: could not configure adapter memory\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | } |
| 1568 | if (adapter->rx_pcb.data.configure) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1569 | pr_err("%s: adapter configuration failed\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Stephen Hemminger | e6c42b7 | 2009-01-09 13:01:12 +0000 | [diff] [blame] | 1572 | dev->netdev_ops = &elp_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | dev->watchdog_timeo = 10*HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | dev->ethtool_ops = &netdev_ethtool_ops; /* local */ |
| 1575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | dev->mem_start = dev->mem_end = 0; |
| 1577 | |
| 1578 | err = register_netdev(dev); |
| 1579 | if (err) |
| 1580 | goto out; |
| 1581 | |
| 1582 | return 0; |
| 1583 | out: |
| 1584 | release_region(dev->base_addr, ELP_IO_EXTENT); |
| 1585 | return err; |
| 1586 | } |
| 1587 | |
| 1588 | #ifndef MODULE |
| 1589 | struct net_device * __init elplus_probe(int unit) |
| 1590 | { |
| 1591 | struct net_device *dev = alloc_etherdev(sizeof(elp_device)); |
| 1592 | int err; |
| 1593 | if (!dev) |
| 1594 | return ERR_PTR(-ENOMEM); |
| 1595 | |
| 1596 | sprintf(dev->name, "eth%d", unit); |
| 1597 | netdev_boot_setup_check(dev); |
| 1598 | |
| 1599 | err = elplus_setup(dev); |
| 1600 | if (err) { |
| 1601 | free_netdev(dev); |
| 1602 | return ERR_PTR(err); |
| 1603 | } |
| 1604 | return dev; |
| 1605 | } |
| 1606 | |
| 1607 | #else |
| 1608 | static struct net_device *dev_3c505[ELP_MAX_CARDS]; |
| 1609 | static int io[ELP_MAX_CARDS]; |
| 1610 | static int irq[ELP_MAX_CARDS]; |
| 1611 | static int dma[ELP_MAX_CARDS]; |
| 1612 | module_param_array(io, int, NULL, 0); |
| 1613 | module_param_array(irq, int, NULL, 0); |
| 1614 | module_param_array(dma, int, NULL, 0); |
| 1615 | MODULE_PARM_DESC(io, "EtherLink Plus I/O base address(es)"); |
| 1616 | MODULE_PARM_DESC(irq, "EtherLink Plus IRQ number(s) (assigned)"); |
| 1617 | MODULE_PARM_DESC(dma, "EtherLink Plus DMA channel(s)"); |
| 1618 | |
Randy Dunlap | 96e672c | 2006-06-10 13:33:48 -0700 | [diff] [blame] | 1619 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | { |
| 1621 | int this_dev, found = 0; |
| 1622 | |
| 1623 | for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) { |
| 1624 | struct net_device *dev = alloc_etherdev(sizeof(elp_device)); |
| 1625 | if (!dev) |
| 1626 | break; |
| 1627 | |
| 1628 | dev->irq = irq[this_dev]; |
| 1629 | dev->base_addr = io[this_dev]; |
| 1630 | if (dma[this_dev]) { |
| 1631 | dev->dma = dma[this_dev]; |
| 1632 | } else { |
| 1633 | dev->dma = ELP_DMA; |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1634 | pr_warning("3c505.c: warning, using default DMA channel,\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | } |
| 1636 | if (io[this_dev] == 0) { |
| 1637 | if (this_dev) { |
| 1638 | free_netdev(dev); |
| 1639 | break; |
| 1640 | } |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1641 | pr_notice("3c505.c: module autoprobe not recommended, give io=xx.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | } |
| 1643 | if (elplus_setup(dev) != 0) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 1644 | pr_warning("3c505.c: Failed to register card at 0x%x.\n", io[this_dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | free_netdev(dev); |
| 1646 | break; |
| 1647 | } |
| 1648 | dev_3c505[this_dev] = dev; |
| 1649 | found++; |
| 1650 | } |
| 1651 | if (!found) |
| 1652 | return -ENODEV; |
| 1653 | return 0; |
| 1654 | } |
| 1655 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 1656 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | { |
| 1658 | int this_dev; |
| 1659 | |
| 1660 | for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) { |
| 1661 | struct net_device *dev = dev_3c505[this_dev]; |
| 1662 | if (dev) { |
| 1663 | unregister_netdev(dev); |
| 1664 | release_region(dev->base_addr, ELP_IO_EXTENT); |
| 1665 | free_netdev(dev); |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | #endif /* MODULE */ |
| 1671 | MODULE_LICENSE("GPL"); |