Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* 3c527.c: 3Com Etherlink/MC32 driver for Linux 2.4 and 2.6. |
| 2 | * |
| 3 | * (c) Copyright 1998 Red Hat Software Inc |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 4 | * Written by Alan Cox. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Further debugging by Carl Drougge. |
| 6 | * Initial SMP support by Felipe W Damasio <felipewd@terra.com.br> |
| 7 | * Heavily modified by Richard Procter <rnp@paradise.net.nz> |
| 8 | * |
| 9 | * Based on skeleton.c written 1993-94 by Donald Becker and ne2.c |
| 10 | * (for the MCA stuff) written by Wim Dumon. |
| 11 | * |
| 12 | * Thanks to 3Com for making this possible by providing me with the |
| 13 | * documentation. |
| 14 | * |
| 15 | * This software may be used and distributed according to the terms |
| 16 | * of the GNU General Public License, incorporated herein by reference. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #define DRV_NAME "3c527" |
| 21 | #define DRV_VERSION "0.7-SMP" |
| 22 | #define DRV_RELDATE "2003/09/21" |
| 23 | |
| 24 | static const char *version = |
| 25 | DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Richard Procter <rnp@paradise.net.nz>\n"; |
| 26 | |
| 27 | /** |
| 28 | * DOC: Traps for the unwary |
| 29 | * |
| 30 | * The diagram (Figure 1-1) and the POS summary disagree with the |
| 31 | * "Interrupt Level" section in the manual. |
| 32 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 33 | * The manual contradicts itself when describing the minimum number |
| 34 | * buffers in the 'configure lists' command. |
| 35 | * My card accepts a buffer config of 4/4. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * |
| 37 | * Setting the SAV BP bit does not save bad packets, but |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 38 | * only enables RX on-card stats collection. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * |
| 40 | * The documentation in places seems to miss things. In actual fact |
| 41 | * I've always eventually found everything is documented, it just |
| 42 | * requires careful study. |
| 43 | * |
| 44 | * DOC: Theory Of Operation |
| 45 | * |
| 46 | * The 3com 3c527 is a 32bit MCA bus mastering adapter with a large |
| 47 | * amount of on board intelligence that housekeeps a somewhat dumber |
| 48 | * Intel NIC. For performance we want to keep the transmit queue deep |
| 49 | * as the card can transmit packets while fetching others from main |
| 50 | * memory by bus master DMA. Transmission and reception are driven by |
| 51 | * circular buffer queues. |
| 52 | * |
| 53 | * The mailboxes can be used for controlling how the card traverses |
| 54 | * its buffer rings, but are used only for inital setup in this |
| 55 | * implementation. The exec mailbox allows a variety of commands to |
| 56 | * be executed. Each command must complete before the next is |
| 57 | * executed. Primarily we use the exec mailbox for controlling the |
| 58 | * multicast lists. We have to do a certain amount of interesting |
| 59 | * hoop jumping as the multicast list changes can occur in interrupt |
| 60 | * state when the card has an exec command pending. We defer such |
| 61 | * events until the command completion interrupt. |
| 62 | * |
| 63 | * A copy break scheme (taken from 3c59x.c) is employed whereby |
| 64 | * received frames exceeding a configurable length are passed |
| 65 | * directly to the higher networking layers without incuring a copy, |
| 66 | * in what amounts to a time/space trade-off. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 67 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * The card also keeps a large amount of statistical information |
| 69 | * on-board. In a perfect world, these could be used safely at no |
| 70 | * cost. However, lacking information to the contrary, processing |
| 71 | * them without races would involve so much extra complexity as to |
| 72 | * make it unworthwhile to do so. In the end, a hybrid SW/HW |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 73 | * implementation was made necessary --- see mc32_update_stats(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * |
| 75 | * DOC: Notes |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 76 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * It should be possible to use two or more cards, but at this stage |
| 78 | * only by loading two copies of the same module. |
| 79 | * |
| 80 | * The on-board 82586 NIC has trouble receiving multiple |
| 81 | * back-to-back frames and so is likely to drop packets from fast |
| 82 | * senders. |
| 83 | **/ |
| 84 | |
| 85 | #include <linux/module.h> |
| 86 | |
| 87 | #include <linux/errno.h> |
| 88 | #include <linux/netdevice.h> |
| 89 | #include <linux/etherdevice.h> |
| 90 | #include <linux/if_ether.h> |
| 91 | #include <linux/init.h> |
| 92 | #include <linux/kernel.h> |
| 93 | #include <linux/types.h> |
| 94 | #include <linux/fcntl.h> |
| 95 | #include <linux/interrupt.h> |
| 96 | #include <linux/mca-legacy.h> |
| 97 | #include <linux/ioport.h> |
| 98 | #include <linux/in.h> |
| 99 | #include <linux/skbuff.h> |
| 100 | #include <linux/slab.h> |
| 101 | #include <linux/string.h> |
| 102 | #include <linux/wait.h> |
| 103 | #include <linux/ethtool.h> |
| 104 | #include <linux/completion.h> |
| 105 | #include <linux/bitops.h> |
Matthew Wilcox | 6188e10 | 2008-04-18 22:21:05 -0400 | [diff] [blame] | 106 | #include <linux/semaphore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #include <asm/uaccess.h> |
| 109 | #include <asm/system.h> |
| 110 | #include <asm/io.h> |
| 111 | #include <asm/dma.h> |
| 112 | |
| 113 | #include "3c527.h" |
| 114 | |
| 115 | MODULE_LICENSE("GPL"); |
| 116 | |
| 117 | /* |
| 118 | * The name of the card. Is used for messages and in the requests for |
| 119 | * io regions, irqs and dma channels |
| 120 | */ |
| 121 | static const char* cardname = DRV_NAME; |
| 122 | |
| 123 | /* use 0 for production, 1 for verification, >2 for debug */ |
| 124 | #ifndef NET_DEBUG |
| 125 | #define NET_DEBUG 2 |
| 126 | #endif |
| 127 | |
| 128 | #undef DEBUG_IRQ |
| 129 | |
| 130 | static unsigned int mc32_debug = NET_DEBUG; |
| 131 | |
| 132 | /* The number of low I/O ports used by the ethercard. */ |
| 133 | #define MC32_IO_EXTENT 8 |
| 134 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 135 | /* As implemented, values must be a power-of-2 -- 4/8/16/32 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #define TX_RING_LEN 32 /* Typically the card supports 37 */ |
| 137 | #define RX_RING_LEN 8 /* " " " */ |
| 138 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 139 | /* Copy break point, see above for details. |
| 140 | * Setting to > 1512 effectively disables this feature. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | #define RX_COPYBREAK 200 /* Value from 3c59x.c */ |
| 142 | |
| 143 | /* Issue the 82586 workaround command - this is for "busy lans", but |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 144 | * basically means for all lans now days - has a performance (latency) |
| 145 | * cost, but best set. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | static const int WORKAROUND_82586=1; |
| 147 | |
| 148 | /* Pointers to buffers and their on-card records */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 149 | struct mc32_ring_desc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 151 | volatile struct skb_header *p; |
| 152 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | /* Information that needs to be kept for each board. */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 156 | struct mc32_local |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | int slot; |
| 159 | |
| 160 | u32 base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | volatile struct mc32_mailbox *rx_box; |
| 162 | volatile struct mc32_mailbox *tx_box; |
| 163 | volatile struct mc32_mailbox *exec_box; |
| 164 | volatile struct mc32_stats *stats; /* Start of on-card statistics */ |
| 165 | u16 tx_chain; /* Transmit list start offset */ |
| 166 | u16 rx_chain; /* Receive list start offset */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 167 | u16 tx_len; /* Transmit list count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | u16 rx_len; /* Receive list count */ |
| 169 | |
| 170 | u16 xceiver_desired_state; /* HALTED or RUNNING */ |
| 171 | u16 cmd_nonblocking; /* Thread is uninterested in command result */ |
| 172 | u16 mc_reload_wait; /* A multicast load request is pending */ |
| 173 | u32 mc_list_valid; /* True when the mclist is set */ |
| 174 | |
| 175 | struct mc32_ring_desc tx_ring[TX_RING_LEN]; /* Host Transmit ring */ |
| 176 | struct mc32_ring_desc rx_ring[RX_RING_LEN]; /* Host Receive ring */ |
| 177 | |
| 178 | atomic_t tx_count; /* buffers left */ |
| 179 | atomic_t tx_ring_head; /* index to tx en-queue end */ |
| 180 | u16 tx_ring_tail; /* index to tx de-queue end */ |
| 181 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 182 | u16 rx_ring_tail; /* index to rx de-queue end */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | struct semaphore cmd_mutex; /* Serialises issuing of execute commands */ |
| 185 | struct completion execution_cmd; /* Card has completed an execute command */ |
| 186 | struct completion xceiver_cmd; /* Card has completed a tx or rx command */ |
| 187 | }; |
| 188 | |
| 189 | /* The station (ethernet) address prefix, used for a sanity check. */ |
| 190 | #define SA_ADDR0 0x02 |
| 191 | #define SA_ADDR1 0x60 |
| 192 | #define SA_ADDR2 0xAC |
| 193 | |
| 194 | struct mca_adapters_t { |
| 195 | unsigned int id; |
| 196 | char *name; |
| 197 | }; |
| 198 | |
| 199 | static const struct mca_adapters_t mc32_adapters[] = { |
| 200 | { 0x0041, "3COM EtherLink MC/32" }, |
| 201 | { 0x8EF5, "IBM High Performance Lan Adapter" }, |
| 202 | { 0x0000, NULL } |
| 203 | }; |
| 204 | |
| 205 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 206 | /* Macros for ring index manipulations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | static inline u16 next_rx(u16 rx) { return (rx+1)&(RX_RING_LEN-1); }; |
| 208 | static inline u16 prev_rx(u16 rx) { return (rx-1)&(RX_RING_LEN-1); }; |
| 209 | |
| 210 | static inline u16 next_tx(u16 tx) { return (tx+1)&(TX_RING_LEN-1); }; |
| 211 | |
| 212 | |
| 213 | /* Index to functions, as function prototypes. */ |
| 214 | static int mc32_probe1(struct net_device *dev, int ioaddr); |
| 215 | static int mc32_command(struct net_device *dev, u16 cmd, void *data, int len); |
| 216 | static int mc32_open(struct net_device *dev); |
| 217 | static void mc32_timeout(struct net_device *dev); |
| 218 | static int mc32_send_packet(struct sk_buff *skb, struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 219 | static irqreturn_t mc32_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | static int mc32_close(struct net_device *dev); |
| 221 | static struct net_device_stats *mc32_get_stats(struct net_device *dev); |
| 222 | static void mc32_set_multicast_list(struct net_device *dev); |
| 223 | static void mc32_reset_multicast_list(struct net_device *dev); |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 224 | static const struct ethtool_ops netdev_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | static void cleanup_card(struct net_device *dev) |
| 227 | { |
| 228 | struct mc32_local *lp = netdev_priv(dev); |
| 229 | unsigned slot = lp->slot; |
| 230 | mca_mark_as_unused(slot); |
| 231 | mca_set_adapter_name(slot, NULL); |
| 232 | free_irq(dev->irq, dev); |
| 233 | release_region(dev->base_addr, MC32_IO_EXTENT); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * mc32_probe - Search for supported boards |
| 238 | * @unit: interface number to use |
| 239 | * |
| 240 | * Because MCA bus is a real bus and we can scan for cards we could do a |
| 241 | * single scan for all boards here. Right now we use the passed in device |
| 242 | * structure and scan for only one board. This needs fixing for modules |
| 243 | * in particular. |
| 244 | */ |
| 245 | |
| 246 | struct net_device *__init mc32_probe(int unit) |
| 247 | { |
| 248 | struct net_device *dev = alloc_etherdev(sizeof(struct mc32_local)); |
| 249 | static int current_mca_slot = -1; |
| 250 | int i; |
| 251 | int err; |
| 252 | |
| 253 | if (!dev) |
| 254 | return ERR_PTR(-ENOMEM); |
| 255 | |
| 256 | if (unit >= 0) |
| 257 | sprintf(dev->name, "eth%d", unit); |
| 258 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 259 | /* Do not check any supplied i/o locations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | POS registers usually don't fail :) */ |
| 261 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 262 | /* MCA cards have POS registers. |
| 263 | Autodetecting MCA cards is extremely simple. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | Just search for the card. */ |
| 265 | |
| 266 | for(i = 0; (mc32_adapters[i].name != NULL); i++) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 267 | current_mca_slot = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | mca_find_unused_adapter(mc32_adapters[i].id, 0); |
| 269 | |
| 270 | if(current_mca_slot != MCA_NOTFOUND) { |
| 271 | if(!mc32_probe1(dev, current_mca_slot)) |
| 272 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 273 | mca_set_adapter_name(current_mca_slot, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | mc32_adapters[i].name); |
| 275 | mca_mark_as_used(current_mca_slot); |
| 276 | err = register_netdev(dev); |
| 277 | if (err) { |
| 278 | cleanup_card(dev); |
| 279 | free_netdev(dev); |
| 280 | dev = ERR_PTR(err); |
| 281 | } |
| 282 | return dev; |
| 283 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | free_netdev(dev); |
| 288 | return ERR_PTR(-ENODEV); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * mc32_probe1 - Check a given slot for a board and test the card |
| 293 | * @dev: Device structure to fill in |
| 294 | * @slot: The MCA bus slot being used by this card |
| 295 | * |
| 296 | * Decode the slot data and configure the card structures. Having done this we |
| 297 | * can reset the card and configure it. The card does a full self test cycle |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 298 | * in firmware so we have to wait for it to return and post us either a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | * failure case or some addresses we use to find the board internals. |
| 300 | */ |
| 301 | |
| 302 | static int __init mc32_probe1(struct net_device *dev, int slot) |
| 303 | { |
| 304 | static unsigned version_printed; |
| 305 | int i, err; |
| 306 | u8 POS; |
| 307 | u32 base; |
| 308 | struct mc32_local *lp = netdev_priv(dev); |
| 309 | static u16 mca_io_bases[]={ |
| 310 | 0x7280,0x7290, |
| 311 | 0x7680,0x7690, |
| 312 | 0x7A80,0x7A90, |
| 313 | 0x7E80,0x7E90 |
| 314 | }; |
| 315 | static u32 mca_mem_bases[]={ |
| 316 | 0x00C0000, |
| 317 | 0x00C4000, |
| 318 | 0x00C8000, |
| 319 | 0x00CC000, |
| 320 | 0x00D0000, |
| 321 | 0x00D4000, |
| 322 | 0x00D8000, |
| 323 | 0x00DC000 |
| 324 | }; |
| 325 | static char *failures[]={ |
| 326 | "Processor instruction", |
| 327 | "Processor data bus", |
| 328 | "Processor data bus", |
| 329 | "Processor data bus", |
| 330 | "Adapter bus", |
| 331 | "ROM checksum", |
| 332 | "Base RAM", |
| 333 | "Extended RAM", |
| 334 | "82586 internal loopback", |
| 335 | "82586 initialisation failure", |
| 336 | "Adapter list configuration error" |
| 337 | }; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 338 | DECLARE_MAC_BUF(mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | /* Time to play MCA games */ |
| 341 | |
| 342 | if (mc32_debug && version_printed++ == 0) |
| 343 | printk(KERN_DEBUG "%s", version); |
| 344 | |
| 345 | printk(KERN_INFO "%s: %s found in slot %d:", dev->name, cardname, slot); |
| 346 | |
| 347 | POS = mca_read_stored_pos(slot, 2); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | if(!(POS&1)) |
| 350 | { |
| 351 | printk(" disabled.\n"); |
| 352 | return -ENODEV; |
| 353 | } |
| 354 | |
| 355 | /* Fill in the 'dev' fields. */ |
| 356 | dev->base_addr = mca_io_bases[(POS>>1)&7]; |
| 357 | dev->mem_start = mca_mem_bases[(POS>>4)&7]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | POS = mca_read_stored_pos(slot, 4); |
| 360 | if(!(POS&1)) |
| 361 | { |
| 362 | printk("memory window disabled.\n"); |
| 363 | return -ENODEV; |
| 364 | } |
| 365 | |
| 366 | POS = mca_read_stored_pos(slot, 5); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | i=(POS>>4)&3; |
| 369 | if(i==3) |
| 370 | { |
| 371 | printk("invalid memory window.\n"); |
| 372 | return -ENODEV; |
| 373 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | i*=16384; |
| 376 | i+=16384; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | dev->mem_end=dev->mem_start + i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | dev->irq = ((POS>>2)&3)+9; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if(!request_region(dev->base_addr, MC32_IO_EXTENT, cardname)) |
| 383 | { |
| 384 | printk("io 0x%3lX, which is busy.\n", dev->base_addr); |
| 385 | return -EBUSY; |
| 386 | } |
| 387 | |
| 388 | printk("io 0x%3lX irq %d mem 0x%lX (%dK)\n", |
| 389 | dev->base_addr, dev->irq, dev->mem_start, i/1024); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 390 | |
| 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* We ought to set the cache line size here.. */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 393 | |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | /* |
| 396 | * Go PROM browsing |
| 397 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | /* Retrieve and print the ethernet address. */ |
| 400 | for (i = 0; i < 6; i++) |
| 401 | { |
| 402 | mca_write_pos(slot, 6, i+12); |
| 403 | mca_write_pos(slot, 7, 0); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 404 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 405 | dev->dev_addr[i] = mca_read_pos(slot,3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 408 | printk("%s: Address %s", dev->name, print_mac(mac, dev->dev_addr)); |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | mca_write_pos(slot, 6, 0); |
| 411 | mca_write_pos(slot, 7, 0); |
| 412 | |
| 413 | POS = mca_read_stored_pos(slot, 4); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if(POS&2) |
| 416 | printk(" : BNC port selected.\n"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 417 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | printk(" : AUI port selected.\n"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | POS=inb(dev->base_addr+HOST_CTRL); |
| 421 | POS|=HOST_CTRL_ATTN|HOST_CTRL_RESET; |
| 422 | POS&=~HOST_CTRL_INTE; |
| 423 | outb(POS, dev->base_addr+HOST_CTRL); |
| 424 | /* Reset adapter */ |
| 425 | udelay(100); |
| 426 | /* Reset off */ |
| 427 | POS&=~(HOST_CTRL_ATTN|HOST_CTRL_RESET); |
| 428 | outb(POS, dev->base_addr+HOST_CTRL); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | udelay(300); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* |
| 433 | * Grab the IRQ |
| 434 | */ |
| 435 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 436 | err = request_irq(dev->irq, &mc32_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM, DRV_NAME, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | if (err) { |
| 438 | release_region(dev->base_addr, MC32_IO_EXTENT); |
| 439 | printk(KERN_ERR "%s: unable to get IRQ %d.\n", DRV_NAME, dev->irq); |
| 440 | goto err_exit_ports; |
| 441 | } |
| 442 | |
| 443 | memset(lp, 0, sizeof(struct mc32_local)); |
| 444 | lp->slot = slot; |
| 445 | |
| 446 | i=0; |
| 447 | |
| 448 | base = inb(dev->base_addr); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | while(base == 0xFF) |
| 451 | { |
| 452 | i++; |
| 453 | if(i == 1000) |
| 454 | { |
| 455 | printk(KERN_ERR "%s: failed to boot adapter.\n", dev->name); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 456 | err = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | goto err_exit_irq; |
| 458 | } |
| 459 | udelay(1000); |
| 460 | if(inb(dev->base_addr+2)&(1<<5)) |
| 461 | base = inb(dev->base_addr); |
| 462 | } |
| 463 | |
| 464 | if(base>0) |
| 465 | { |
| 466 | if(base < 0x0C) |
| 467 | printk(KERN_ERR "%s: %s%s.\n", dev->name, failures[base-1], |
| 468 | base<0x0A?" test failure":""); |
| 469 | else |
| 470 | printk(KERN_ERR "%s: unknown failure %d.\n", dev->name, base); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 471 | err = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | goto err_exit_irq; |
| 473 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | base=0; |
| 476 | for(i=0;i<4;i++) |
| 477 | { |
| 478 | int n=0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | while(!(inb(dev->base_addr+2)&(1<<5))) |
| 481 | { |
| 482 | n++; |
| 483 | udelay(50); |
| 484 | if(n>100) |
| 485 | { |
| 486 | printk(KERN_ERR "%s: mailbox read fail (%d).\n", dev->name, i); |
| 487 | err = -ENODEV; |
| 488 | goto err_exit_irq; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | base|=(inb(dev->base_addr)<<(8*i)); |
| 493 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | lp->exec_box=isa_bus_to_virt(dev->mem_start+base); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 496 | |
| 497 | base=lp->exec_box->data[1]<<16|lp->exec_box->data[0]; |
| 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | lp->base = dev->mem_start+base; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 500 | |
| 501 | lp->rx_box=isa_bus_to_virt(lp->base + lp->exec_box->data[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | lp->tx_box=isa_bus_to_virt(lp->base + lp->exec_box->data[3]); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | lp->stats = isa_bus_to_virt(lp->base + lp->exec_box->data[5]); |
| 505 | |
| 506 | /* |
| 507 | * Descriptor chains (card relative) |
| 508 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | lp->tx_chain = lp->exec_box->data[8]; /* Transmit list start offset */ |
| 511 | lp->rx_chain = lp->exec_box->data[10]; /* Receive list start offset */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 512 | lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | lp->rx_len = lp->exec_box->data[11]; /* Receive list count */ |
| 514 | |
| 515 | init_MUTEX_LOCKED(&lp->cmd_mutex); |
| 516 | init_completion(&lp->execution_cmd); |
| 517 | init_completion(&lp->xceiver_cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | printk("%s: Firmware Rev %d. %d RX buffers, %d TX buffers. Base of 0x%08X.\n", |
| 520 | dev->name, lp->exec_box->data[12], lp->rx_len, lp->tx_len, lp->base); |
| 521 | |
| 522 | dev->open = mc32_open; |
| 523 | dev->stop = mc32_close; |
| 524 | dev->hard_start_xmit = mc32_send_packet; |
| 525 | dev->get_stats = mc32_get_stats; |
| 526 | dev->set_multicast_list = mc32_set_multicast_list; |
| 527 | dev->tx_timeout = mc32_timeout; |
| 528 | dev->watchdog_timeo = HZ*5; /* Board does all the work */ |
| 529 | dev->ethtool_ops = &netdev_ethtool_ops; |
| 530 | |
| 531 | return 0; |
| 532 | |
| 533 | err_exit_irq: |
| 534 | free_irq(dev->irq, dev); |
| 535 | err_exit_ports: |
| 536 | release_region(dev->base_addr, MC32_IO_EXTENT); |
| 537 | return err; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | /** |
| 542 | * mc32_ready_poll - wait until we can feed it a command |
| 543 | * @dev: The device to wait for |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 544 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | * Wait until the card becomes ready to accept a command via the |
| 546 | * command register. This tells us nothing about the completion |
| 547 | * status of any pending commands and takes very little time at all. |
| 548 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | static inline void mc32_ready_poll(struct net_device *dev) |
| 551 | { |
| 552 | int ioaddr = dev->base_addr; |
| 553 | while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR)); |
| 554 | } |
| 555 | |
| 556 | |
| 557 | /** |
| 558 | * mc32_command_nowait - send a command non blocking |
| 559 | * @dev: The 3c527 to issue the command to |
| 560 | * @cmd: The command word to write to the mailbox |
| 561 | * @data: A data block if the command expects one |
| 562 | * @len: Length of the data block |
| 563 | * |
| 564 | * Send a command from interrupt state. If there is a command |
| 565 | * currently being executed then we return an error of -1. It |
| 566 | * simply isn't viable to wait around as commands may be |
| 567 | * slow. This can theoretically be starved on SMP, but it's hard |
| 568 | * to see a realistic situation. We do not wait for the command |
| 569 | * to complete --- we rely on the interrupt handler to tidy up |
| 570 | * after us. |
| 571 | */ |
| 572 | |
| 573 | static int mc32_command_nowait(struct net_device *dev, u16 cmd, void *data, int len) |
| 574 | { |
| 575 | struct mc32_local *lp = netdev_priv(dev); |
| 576 | int ioaddr = dev->base_addr; |
| 577 | int ret = -1; |
| 578 | |
| 579 | if (down_trylock(&lp->cmd_mutex) == 0) |
| 580 | { |
| 581 | lp->cmd_nonblocking=1; |
| 582 | lp->exec_box->mbox=0; |
| 583 | lp->exec_box->mbox=cmd; |
| 584 | memcpy((void *)lp->exec_box->data, data, len); |
| 585 | barrier(); /* the memcpy forgot the volatile so be sure */ |
| 586 | |
| 587 | /* Send the command */ |
| 588 | mc32_ready_poll(dev); |
| 589 | outb(1<<6, ioaddr+HOST_CMD); |
| 590 | |
| 591 | ret = 0; |
| 592 | |
| 593 | /* Interrupt handler will signal mutex on completion */ |
| 594 | } |
| 595 | |
| 596 | return ret; |
| 597 | } |
| 598 | |
| 599 | |
| 600 | /** |
| 601 | * mc32_command - send a command and sleep until completion |
| 602 | * @dev: The 3c527 card to issue the command to |
| 603 | * @cmd: The command word to write to the mailbox |
| 604 | * @data: A data block if the command expects one |
| 605 | * @len: Length of the data block |
| 606 | * |
| 607 | * Sends exec commands in a user context. This permits us to wait around |
| 608 | * for the replies and also to wait for the command buffer to complete |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 609 | * from a previous command before we execute our command. After our |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | * command completes we will attempt any pending multicast reload |
| 611 | * we blocked off by hogging the exec buffer. |
| 612 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 613 | * You feed the card a command, you wait, it interrupts you get a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | * reply. All well and good. The complication arises because you use |
| 615 | * commands for filter list changes which come in at bh level from things |
| 616 | * like IPV6 group stuff. |
| 617 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | static int mc32_command(struct net_device *dev, u16 cmd, void *data, int len) |
| 620 | { |
| 621 | struct mc32_local *lp = netdev_priv(dev); |
| 622 | int ioaddr = dev->base_addr; |
| 623 | int ret = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | down(&lp->cmd_mutex); |
| 626 | |
| 627 | /* |
| 628 | * My Turn |
| 629 | */ |
| 630 | |
| 631 | lp->cmd_nonblocking=0; |
| 632 | lp->exec_box->mbox=0; |
| 633 | lp->exec_box->mbox=cmd; |
| 634 | memcpy((void *)lp->exec_box->data, data, len); |
| 635 | barrier(); /* the memcpy forgot the volatile so be sure */ |
| 636 | |
| 637 | mc32_ready_poll(dev); |
| 638 | outb(1<<6, ioaddr+HOST_CMD); |
| 639 | |
| 640 | wait_for_completion(&lp->execution_cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if(lp->exec_box->mbox&(1<<13)) |
| 643 | ret = -1; |
| 644 | |
| 645 | up(&lp->cmd_mutex); |
| 646 | |
| 647 | /* |
| 648 | * A multicast set got blocked - try it now |
| 649 | */ |
| 650 | |
| 651 | if(lp->mc_reload_wait) |
| 652 | { |
| 653 | mc32_reset_multicast_list(dev); |
| 654 | } |
| 655 | |
| 656 | return ret; |
| 657 | } |
| 658 | |
| 659 | |
| 660 | /** |
| 661 | * mc32_start_transceiver - tell board to restart tx/rx |
| 662 | * @dev: The 3c527 card to issue the command to |
| 663 | * |
| 664 | * This may be called from the interrupt state, where it is used |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 665 | * to restart the rx ring if the card runs out of rx buffers. |
| 666 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | * We must first check if it's ok to (re)start the transceiver. See |
| 668 | * mc32_close for details. |
| 669 | */ |
| 670 | |
| 671 | static void mc32_start_transceiver(struct net_device *dev) { |
| 672 | |
| 673 | struct mc32_local *lp = netdev_priv(dev); |
| 674 | int ioaddr = dev->base_addr; |
| 675 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 676 | /* Ignore RX overflow on device closure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | if (lp->xceiver_desired_state==HALTED) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 678 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
| 680 | /* Give the card the offset to the post-EOL-bit RX descriptor */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 681 | mc32_ready_poll(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | lp->rx_box->mbox=0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 683 | lp->rx_box->data[0]=lp->rx_ring[prev_rx(lp->rx_ring_tail)].p->next; |
| 684 | outb(HOST_CMD_START_RX, ioaddr+HOST_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 686 | mc32_ready_poll(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | lp->tx_box->mbox=0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 688 | outb(HOST_CMD_RESTRT_TX, ioaddr+HOST_CMD); /* card ignores this on RX restart */ |
| 689 | |
| 690 | /* We are not interrupted on start completion */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | |
| 694 | /** |
| 695 | * mc32_halt_transceiver - tell board to stop tx/rx |
| 696 | * @dev: The 3c527 card to issue the command to |
| 697 | * |
| 698 | * We issue the commands to halt the card's transceiver. In fact, |
| 699 | * after some experimenting we now simply tell the card to |
| 700 | * suspend. When issuing aborts occasionally odd things happened. |
| 701 | * |
| 702 | * We then sleep until the card has notified us that both rx and |
| 703 | * tx have been suspended. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 704 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 706 | static void mc32_halt_transceiver(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | { |
| 708 | struct mc32_local *lp = netdev_priv(dev); |
| 709 | int ioaddr = dev->base_addr; |
| 710 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 711 | mc32_ready_poll(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | lp->rx_box->mbox=0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 713 | outb(HOST_CMD_SUSPND_RX, ioaddr+HOST_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | wait_for_completion(&lp->xceiver_cmd); |
| 715 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 716 | mc32_ready_poll(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | lp->tx_box->mbox=0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 718 | outb(HOST_CMD_SUSPND_TX, ioaddr+HOST_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | wait_for_completion(&lp->xceiver_cmd); |
| 720 | } |
| 721 | |
| 722 | |
| 723 | /** |
| 724 | * mc32_load_rx_ring - load the ring of receive buffers |
| 725 | * @dev: 3c527 to build the ring for |
| 726 | * |
| 727 | * This initalises the on-card and driver datastructures to |
| 728 | * the point where mc32_start_transceiver() can be called. |
| 729 | * |
| 730 | * The card sets up the receive ring for us. We are required to use the |
| 731 | * ring it provides, although the size of the ring is configurable. |
| 732 | * |
| 733 | * We allocate an sk_buff for each ring entry in turn and |
| 734 | * initalise its house-keeping info. At the same time, we read |
| 735 | * each 'next' pointer in our rx_ring array. This reduces slow |
| 736 | * shared-memory reads and makes it easy to access predecessor |
| 737 | * descriptors. |
| 738 | * |
| 739 | * We then set the end-of-list bit for the last entry so that the |
| 740 | * card will know when it has run out of buffers. |
| 741 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | static int mc32_load_rx_ring(struct net_device *dev) |
| 744 | { |
| 745 | struct mc32_local *lp = netdev_priv(dev); |
| 746 | int i; |
| 747 | u16 rx_base; |
| 748 | volatile struct skb_header *p; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | rx_base=lp->rx_chain; |
| 751 | |
| 752 | for(i=0; i<RX_RING_LEN; i++) { |
| 753 | lp->rx_ring[i].skb=alloc_skb(1532, GFP_KERNEL); |
| 754 | if (lp->rx_ring[i].skb==NULL) { |
| 755 | for (;i>=0;i--) |
| 756 | kfree_skb(lp->rx_ring[i].skb); |
| 757 | return -ENOBUFS; |
| 758 | } |
| 759 | skb_reserve(lp->rx_ring[i].skb, 18); |
| 760 | |
| 761 | p=isa_bus_to_virt(lp->base+rx_base); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | p->control=0; |
| 764 | p->data=isa_virt_to_bus(lp->rx_ring[i].skb->data); |
| 765 | p->status=0; |
| 766 | p->length=1532; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 767 | |
| 768 | lp->rx_ring[i].p=p; |
| 769 | rx_base=p->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | lp->rx_ring[i-1].p->control |= CONTROL_EOL; |
| 773 | |
| 774 | lp->rx_ring_tail=0; |
| 775 | |
| 776 | return 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 777 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | |
| 780 | /** |
| 781 | * mc32_flush_rx_ring - free the ring of receive buffers |
| 782 | * @lp: Local data of 3c527 to flush the rx ring of |
| 783 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 784 | * Free the buffer for each ring slot. This may be called |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | * before mc32_load_rx_ring(), eg. on error in mc32_open(). |
| 786 | * Requires rx skb pointers to point to a valid skb, or NULL. |
| 787 | */ |
| 788 | |
| 789 | static void mc32_flush_rx_ring(struct net_device *dev) |
| 790 | { |
| 791 | struct mc32_local *lp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 792 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 794 | for(i=0; i < RX_RING_LEN; i++) |
| 795 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | if (lp->rx_ring[i].skb) { |
| 797 | dev_kfree_skb(lp->rx_ring[i].skb); |
| 798 | lp->rx_ring[i].skb = NULL; |
| 799 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 800 | lp->rx_ring[i].p=NULL; |
| 801 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | |
| 805 | /** |
| 806 | * mc32_load_tx_ring - load transmit ring |
| 807 | * @dev: The 3c527 card to issue the command to |
| 808 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 809 | * This sets up the host transmit data-structures. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | * |
| 811 | * First, we obtain from the card it's current postion in the tx |
| 812 | * ring, so that we will know where to begin transmitting |
| 813 | * packets. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 814 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | * Then, we read the 'next' pointers from the on-card tx ring into |
| 816 | * our tx_ring array to reduce slow shared-mem reads. Finally, we |
| 817 | * intitalise the tx house keeping variables. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 818 | * |
| 819 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | static void mc32_load_tx_ring(struct net_device *dev) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 822 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | struct mc32_local *lp = netdev_priv(dev); |
| 824 | volatile struct skb_header *p; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 825 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | u16 tx_base; |
| 827 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 828 | tx_base=lp->tx_box->data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | for(i=0 ; i<TX_RING_LEN ; i++) |
| 831 | { |
| 832 | p=isa_bus_to_virt(lp->base+tx_base); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 833 | lp->tx_ring[i].p=p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | lp->tx_ring[i].skb=NULL; |
| 835 | |
| 836 | tx_base=p->next; |
| 837 | } |
| 838 | |
| 839 | /* -1 so that tx_ring_head cannot "lap" tx_ring_tail */ |
| 840 | /* see mc32_tx_ring */ |
| 841 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 842 | atomic_set(&lp->tx_count, TX_RING_LEN-1); |
| 843 | atomic_set(&lp->tx_ring_head, 0); |
| 844 | lp->tx_ring_tail=0; |
| 845 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
| 847 | |
| 848 | /** |
| 849 | * mc32_flush_tx_ring - free transmit ring |
| 850 | * @lp: Local data of 3c527 to flush the tx ring of |
| 851 | * |
| 852 | * If the ring is non-empty, zip over the it, freeing any |
| 853 | * allocated skb_buffs. The tx ring house-keeping variables are |
| 854 | * then reset. Requires rx skb pointers to point to a valid skb, |
| 855 | * or NULL. |
| 856 | */ |
| 857 | |
| 858 | static void mc32_flush_tx_ring(struct net_device *dev) |
| 859 | { |
| 860 | struct mc32_local *lp = netdev_priv(dev); |
| 861 | int i; |
| 862 | |
| 863 | for (i=0; i < TX_RING_LEN; i++) |
| 864 | { |
| 865 | if (lp->tx_ring[i].skb) |
| 866 | { |
| 867 | dev_kfree_skb(lp->tx_ring[i].skb); |
| 868 | lp->tx_ring[i].skb = NULL; |
| 869 | } |
| 870 | } |
| 871 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 872 | atomic_set(&lp->tx_count, 0); |
| 873 | atomic_set(&lp->tx_ring_head, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | lp->tx_ring_tail=0; |
| 875 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | /** |
| 879 | * mc32_open - handle 'up' of card |
| 880 | * @dev: device to open |
| 881 | * |
| 882 | * The user is trying to bring the card into ready state. This requires |
| 883 | * a brief dialogue with the card. Firstly we enable interrupts and then |
| 884 | * 'indications'. Without these enabled the card doesn't bother telling |
| 885 | * us what it has done. This had me puzzled for a week. |
| 886 | * |
| 887 | * We configure the number of card descriptors, then load the network |
| 888 | * address and multicast filters. Turn on the workaround mode. This |
| 889 | * works around a bug in the 82586 - it asks the firmware to do |
| 890 | * so. It has a performance (latency) hit but is needed on busy |
| 891 | * [read most] lans. We load the ring with buffers then we kick it |
| 892 | * all off. |
| 893 | */ |
| 894 | |
| 895 | static int mc32_open(struct net_device *dev) |
| 896 | { |
| 897 | int ioaddr = dev->base_addr; |
| 898 | struct mc32_local *lp = netdev_priv(dev); |
| 899 | u8 one=1; |
| 900 | u8 regs; |
| 901 | u16 descnumbuffs[2] = {TX_RING_LEN, RX_RING_LEN}; |
| 902 | |
| 903 | /* |
| 904 | * Interrupts enabled |
| 905 | */ |
| 906 | |
| 907 | regs=inb(ioaddr+HOST_CTRL); |
| 908 | regs|=HOST_CTRL_INTE; |
| 909 | outb(regs, ioaddr+HOST_CTRL); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | /* |
| 912 | * Allow ourselves to issue commands |
| 913 | */ |
| 914 | |
| 915 | up(&lp->cmd_mutex); |
| 916 | |
| 917 | |
| 918 | /* |
| 919 | * Send the indications on command |
| 920 | */ |
| 921 | |
| 922 | mc32_command(dev, 4, &one, 2); |
| 923 | |
| 924 | /* |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 925 | * Poke it to make sure it's really dead. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | */ |
| 927 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 928 | mc32_halt_transceiver(dev); |
| 929 | mc32_flush_tx_ring(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 931 | /* |
| 932 | * Ask card to set up on-card descriptors to our spec |
| 933 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 935 | if(mc32_command(dev, 8, descnumbuffs, 4)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | printk("%s: %s rejected our buffer configuration!\n", |
| 937 | dev->name, cardname); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 938 | mc32_close(dev); |
| 939 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 941 | |
| 942 | /* Report new configuration */ |
| 943 | mc32_command(dev, 6, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| 945 | lp->tx_chain = lp->exec_box->data[8]; /* Transmit list start offset */ |
| 946 | lp->rx_chain = lp->exec_box->data[10]; /* Receive list start offset */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 947 | lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | lp->rx_len = lp->exec_box->data[11]; /* Receive list count */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | /* Set Network Address */ |
| 951 | mc32_command(dev, 1, dev->dev_addr, 6); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | /* Set the filters */ |
| 954 | mc32_set_multicast_list(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 955 | |
| 956 | if (WORKAROUND_82586) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | u16 zero_word=0; |
| 958 | mc32_command(dev, 0x0D, &zero_word, 2); /* 82586 bug workaround on */ |
| 959 | } |
| 960 | |
| 961 | mc32_load_tx_ring(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 962 | |
| 963 | if(mc32_load_rx_ring(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
| 965 | mc32_close(dev); |
| 966 | return -ENOBUFS; |
| 967 | } |
| 968 | |
| 969 | lp->xceiver_desired_state = RUNNING; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | /* And finally, set the ball rolling... */ |
| 972 | mc32_start_transceiver(dev); |
| 973 | |
| 974 | netif_start_queue(dev); |
| 975 | |
| 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | |
| 980 | /** |
| 981 | * mc32_timeout - handle a timeout from the network layer |
| 982 | * @dev: 3c527 that timed out |
| 983 | * |
| 984 | * Handle a timeout on transmit from the 3c527. This normally means |
| 985 | * bad things as the hardware handles cable timeouts and mess for |
| 986 | * us. |
| 987 | * |
| 988 | */ |
| 989 | |
| 990 | static void mc32_timeout(struct net_device *dev) |
| 991 | { |
| 992 | printk(KERN_WARNING "%s: transmit timed out?\n", dev->name); |
| 993 | /* Try to restart the adaptor. */ |
| 994 | netif_wake_queue(dev); |
| 995 | } |
| 996 | |
| 997 | |
| 998 | /** |
| 999 | * mc32_send_packet - queue a frame for transmit |
| 1000 | * @skb: buffer to transmit |
| 1001 | * @dev: 3c527 to send it out of |
| 1002 | * |
| 1003 | * Transmit a buffer. This normally means throwing the buffer onto |
| 1004 | * the transmit queue as the queue is quite large. If the queue is |
| 1005 | * full then we set tx_busy and return. Once the interrupt handler |
| 1006 | * gets messages telling it to reclaim transmit queue entries, we will |
| 1007 | * clear tx_busy and the kernel will start calling this again. |
| 1008 | * |
| 1009 | * We do not disable interrupts or acquire any locks; this can |
| 1010 | * run concurrently with mc32_tx_ring(), and the function itself |
| 1011 | * is serialised at a higher layer. However, similarly for the |
| 1012 | * card itself, we must ensure that we update tx_ring_head only |
| 1013 | * after we've established a valid packet on the tx ring (and |
| 1014 | * before we let the card "see" it, to prevent it racing with the |
| 1015 | * irq handler). |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1016 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | */ |
| 1018 | |
| 1019 | static int mc32_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 1020 | { |
| 1021 | struct mc32_local *lp = netdev_priv(dev); |
| 1022 | u32 head = atomic_read(&lp->tx_ring_head); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | volatile struct skb_header *p, *np; |
| 1025 | |
| 1026 | netif_stop_queue(dev); |
| 1027 | |
| 1028 | if(atomic_read(&lp->tx_count)==0) { |
| 1029 | return 1; |
| 1030 | } |
| 1031 | |
Herbert Xu | 5b057c6 | 2006-06-23 02:06:41 -0700 | [diff] [blame] | 1032 | if (skb_padto(skb, ETH_ZLEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | netif_wake_queue(dev); |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1037 | atomic_dec(&lp->tx_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
| 1039 | /* P is the last sending/sent buffer as a pointer */ |
| 1040 | p=lp->tx_ring[head].p; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | head = next_tx(head); |
| 1043 | |
| 1044 | /* NP is the buffer we will be loading */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1045 | np=lp->tx_ring[head].p; |
| 1046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | /* We will need this to flush the buffer out */ |
| 1048 | lp->tx_ring[head].skb=skb; |
| 1049 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1050 | np->length = unlikely(skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | np->data = isa_virt_to_bus(skb->data); |
| 1052 | np->status = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1053 | np->control = CONTROL_EOP | CONTROL_EOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | wmb(); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | /* |
| 1057 | * The new frame has been setup; we can now |
| 1058 | * let the interrupt handler and card "see" it |
| 1059 | */ |
| 1060 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1061 | atomic_set(&lp->tx_ring_head, head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | p->control &= ~CONTROL_EOL; |
| 1063 | |
| 1064 | netif_wake_queue(dev); |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | /** |
| 1070 | * mc32_update_stats - pull off the on board statistics |
| 1071 | * @dev: 3c527 to service |
| 1072 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1073 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | * Query and reset the on-card stats. There's the small possibility |
| 1075 | * of a race here, which would result in an underestimation of |
| 1076 | * actual errors. As such, we'd prefer to keep all our stats |
| 1077 | * collection in software. As a rule, we do. However it can't be |
| 1078 | * used for rx errors and collisions as, by default, the card discards |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1079 | * bad rx packets. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | * |
| 1081 | * Setting the SAV BP in the rx filter command supposedly |
| 1082 | * stops this behaviour. However, testing shows that it only seems to |
| 1083 | * enable the collation of on-card rx statistics --- the driver |
| 1084 | * never sees an RX descriptor with an error status set. |
| 1085 | * |
| 1086 | */ |
| 1087 | |
| 1088 | static void mc32_update_stats(struct net_device *dev) |
| 1089 | { |
| 1090 | struct mc32_local *lp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1091 | volatile struct mc32_stats *st = lp->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1093 | u32 rx_errors=0; |
| 1094 | |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1095 | rx_errors+=dev->stats.rx_crc_errors +=st->rx_crc_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | st->rx_crc_errors=0; |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1097 | rx_errors+=dev->stats.rx_fifo_errors +=st->rx_overrun_errors; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1098 | st->rx_overrun_errors=0; |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1099 | rx_errors+=dev->stats.rx_frame_errors +=st->rx_alignment_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | st->rx_alignment_errors=0; |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1101 | rx_errors+=dev->stats.rx_length_errors+=st->rx_tooshort_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | st->rx_tooshort_errors=0; |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1103 | rx_errors+=dev->stats.rx_missed_errors+=st->rx_outofresource_errors; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1104 | st->rx_outofresource_errors=0; |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1105 | dev->stats.rx_errors=rx_errors; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | /* Number of packets which saw one collision */ |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1108 | dev->stats.collisions+=st->dataC[10]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1109 | st->dataC[10]=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1111 | /* Number of packets which saw 2--15 collisions */ |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1112 | dev->stats.collisions+=st->dataC[11]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1113 | st->dataC[11]=0; |
| 1114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
| 1116 | |
| 1117 | /** |
| 1118 | * mc32_rx_ring - process the receive ring |
| 1119 | * @dev: 3c527 that needs its receive ring processing |
| 1120 | * |
| 1121 | * |
| 1122 | * We have received one or more indications from the card that a |
| 1123 | * receive has completed. The buffer ring thus contains dirty |
| 1124 | * entries. We walk the ring by iterating over the circular rx_ring |
| 1125 | * array, starting at the next dirty buffer (which happens to be the |
| 1126 | * one we finished up at last time around). |
| 1127 | * |
| 1128 | * For each completed packet, we will either copy it and pass it up |
| 1129 | * the stack or, if the packet is near MTU sized, we allocate |
| 1130 | * another buffer and flip the old one up the stack. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1131 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | * We must succeed in keeping a buffer on the ring. If necessary we |
| 1133 | * will toss a received packet rather than lose a ring entry. Once |
| 1134 | * the first uncompleted descriptor is found, we move the |
| 1135 | * End-Of-List bit to include the buffers just processed. |
| 1136 | * |
| 1137 | */ |
| 1138 | |
| 1139 | static void mc32_rx_ring(struct net_device *dev) |
| 1140 | { |
| 1141 | struct mc32_local *lp = netdev_priv(dev); |
| 1142 | volatile struct skb_header *p; |
| 1143 | u16 rx_ring_tail; |
| 1144 | u16 rx_old_tail; |
| 1145 | int x=0; |
| 1146 | |
| 1147 | rx_old_tail = rx_ring_tail = lp->rx_ring_tail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1149 | do |
| 1150 | { |
| 1151 | p=lp->rx_ring[rx_ring_tail].p; |
| 1152 | |
| 1153 | if(!(p->status & (1<<7))) { /* Not COMPLETED */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | if(p->status & (1<<6)) /* COMPLETED_OK */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1157 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
| 1159 | u16 length=p->length; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1160 | struct sk_buff *skb; |
| 1161 | struct sk_buff *newskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
| 1163 | /* Try to save time by avoiding a copy on big frames */ |
| 1164 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1165 | if ((length > RX_COPYBREAK) |
| 1166 | && ((newskb=dev_alloc_skb(1532)) != NULL)) |
| 1167 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | skb=lp->rx_ring[rx_ring_tail].skb; |
| 1169 | skb_put(skb, length); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1170 | |
| 1171 | skb_reserve(newskb,18); |
| 1172 | lp->rx_ring[rx_ring_tail].skb=newskb; |
| 1173 | p->data=isa_virt_to_bus(newskb->data); |
| 1174 | } |
| 1175 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1177 | skb=dev_alloc_skb(length+2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
| 1179 | if(skb==NULL) { |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1180 | dev->stats.rx_dropped++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1181 | goto dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | skb_reserve(skb,2); |
| 1185 | memcpy(skb_put(skb, length), |
| 1186 | lp->rx_ring[rx_ring_tail].skb->data, length); |
| 1187 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1188 | |
| 1189 | skb->protocol=eth_type_trans(skb,dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | dev->last_rx = jiffies; |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1191 | dev->stats.rx_packets++; |
| 1192 | dev->stats.rx_bytes += length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | netif_rx(skb); |
| 1194 | } |
| 1195 | |
| 1196 | dropped: |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1197 | p->length = 1532; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | p->status = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1199 | |
| 1200 | rx_ring_tail=next_rx(rx_ring_tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1202 | while(x++<48); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1204 | /* If there was actually a frame to be processed, place the EOL bit */ |
| 1205 | /* at the descriptor prior to the one to be filled next */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1207 | if (rx_ring_tail != rx_old_tail) |
| 1208 | { |
| 1209 | lp->rx_ring[prev_rx(rx_ring_tail)].p->control |= CONTROL_EOL; |
| 1210 | lp->rx_ring[prev_rx(rx_old_tail)].p->control &= ~CONTROL_EOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1212 | lp->rx_ring_tail=rx_ring_tail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | |
| 1217 | /** |
| 1218 | * mc32_tx_ring - process completed transmits |
| 1219 | * @dev: 3c527 that needs its transmit ring processing |
| 1220 | * |
| 1221 | * |
| 1222 | * This operates in a similar fashion to mc32_rx_ring. We iterate |
| 1223 | * over the transmit ring. For each descriptor which has been |
| 1224 | * processed by the card, we free its associated buffer and note |
| 1225 | * any errors. This continues until the transmit ring is emptied |
| 1226 | * or we reach a descriptor that hasn't yet been processed by the |
| 1227 | * card. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1228 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | */ |
| 1230 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1231 | static void mc32_tx_ring(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
| 1233 | struct mc32_local *lp = netdev_priv(dev); |
| 1234 | volatile struct skb_header *np; |
| 1235 | |
| 1236 | /* |
| 1237 | * We rely on head==tail to mean 'queue empty'. |
| 1238 | * This is why lp->tx_count=TX_RING_LEN-1: in order to prevent |
| 1239 | * tx_ring_head wrapping to tail and confusing a 'queue empty' |
| 1240 | * condition with 'queue full' |
| 1241 | */ |
| 1242 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1243 | while (lp->tx_ring_tail != atomic_read(&lp->tx_ring_head)) |
| 1244 | { |
| 1245 | u16 t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1247 | t=next_tx(lp->tx_ring_tail); |
| 1248 | np=lp->tx_ring[t].p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1250 | if(!(np->status & (1<<7))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1252 | /* Not COMPLETED */ |
| 1253 | break; |
| 1254 | } |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1255 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | if(!(np->status & (1<<6))) /* Not COMPLETED_OK */ |
| 1257 | { |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1258 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | switch(np->status&0x0F) |
| 1261 | { |
| 1262 | case 1: |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1263 | dev->stats.tx_aborted_errors++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1264 | break; /* Max collisions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | case 2: |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1266 | dev->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | break; |
| 1268 | case 3: |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1269 | dev->stats.tx_carrier_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | break; |
| 1271 | case 4: |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1272 | dev->stats.tx_window_errors++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1273 | break; /* CTS Lost */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | case 5: |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1275 | dev->stats.tx_aborted_errors++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1276 | break; /* Transmit timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | /* Packets are sent in order - this is |
| 1280 | basically a FIFO queue of buffers matching |
| 1281 | the card ring */ |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1282 | dev->stats.tx_bytes+=lp->tx_ring[t].skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | dev_kfree_skb_irq(lp->tx_ring[t].skb); |
| 1284 | lp->tx_ring[t].skb=NULL; |
| 1285 | atomic_inc(&lp->tx_count); |
| 1286 | netif_wake_queue(dev); |
| 1287 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1288 | lp->tx_ring_tail=t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
| 1293 | |
| 1294 | /** |
| 1295 | * mc32_interrupt - handle an interrupt from a 3c527 |
| 1296 | * @irq: Interrupt number |
| 1297 | * @dev_id: 3c527 that requires servicing |
| 1298 | * @regs: Registers (unused) |
| 1299 | * |
| 1300 | * |
| 1301 | * An interrupt is raised whenever the 3c527 writes to the command |
| 1302 | * register. This register contains the message it wishes to send us |
| 1303 | * packed into a single byte field. We keep reading status entries |
| 1304 | * until we have processed all the control items, but simply count |
| 1305 | * transmit and receive reports. When all reports are in we empty the |
| 1306 | * transceiver rings as appropriate. This saves the overhead of |
| 1307 | * multiple command requests. |
| 1308 | * |
| 1309 | * Because MCA is level-triggered, we shouldn't miss indications. |
| 1310 | * Therefore, we needn't ask the card to suspend interrupts within |
| 1311 | * this handler. The card receives an implicit acknowledgment of the |
| 1312 | * current interrupt when we read the command register. |
| 1313 | * |
| 1314 | */ |
| 1315 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1316 | static irqreturn_t mc32_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | { |
| 1318 | struct net_device *dev = dev_id; |
| 1319 | struct mc32_local *lp; |
| 1320 | int ioaddr, status, boguscount = 0; |
| 1321 | int rx_event = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1322 | int tx_event = 0; |
| 1323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | ioaddr = dev->base_addr; |
| 1325 | lp = netdev_priv(dev); |
| 1326 | |
| 1327 | /* See whats cooking */ |
| 1328 | |
| 1329 | while((inb(ioaddr+HOST_STATUS)&HOST_STATUS_CWR) && boguscount++<2000) |
| 1330 | { |
| 1331 | status=inb(ioaddr+HOST_CMD); |
| 1332 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1333 | #ifdef DEBUG_IRQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | printk("Status TX%d RX%d EX%d OV%d BC%d\n", |
| 1335 | (status&7), (status>>3)&7, (status>>6)&1, |
| 1336 | (status>>7)&1, boguscount); |
| 1337 | #endif |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | switch(status&7) |
| 1340 | { |
| 1341 | case 0: |
| 1342 | break; |
| 1343 | case 6: /* TX fail */ |
| 1344 | case 2: /* TX ok */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1345 | tx_event = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | break; |
| 1347 | case 3: /* Halt */ |
| 1348 | case 4: /* Abort */ |
| 1349 | complete(&lp->xceiver_cmd); |
| 1350 | break; |
| 1351 | default: |
| 1352 | printk("%s: strange tx ack %d\n", dev->name, status&7); |
| 1353 | } |
| 1354 | status>>=3; |
| 1355 | switch(status&7) |
| 1356 | { |
| 1357 | case 0: |
| 1358 | break; |
| 1359 | case 2: /* RX */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1360 | rx_event=1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | break; |
| 1362 | case 3: /* Halt */ |
| 1363 | case 4: /* Abort */ |
| 1364 | complete(&lp->xceiver_cmd); |
| 1365 | break; |
| 1366 | case 6: |
| 1367 | /* Out of RX buffers stat */ |
| 1368 | /* Must restart rx */ |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1369 | dev->stats.rx_dropped++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1370 | mc32_rx_ring(dev); |
| 1371 | mc32_start_transceiver(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | break; |
| 1373 | default: |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1374 | printk("%s: strange rx ack %d\n", |
| 1375 | dev->name, status&7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | } |
| 1377 | status>>=3; |
| 1378 | if(status&1) |
| 1379 | { |
| 1380 | /* |
| 1381 | * No thread is waiting: we need to tidy |
| 1382 | * up ourself. |
| 1383 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | if (lp->cmd_nonblocking) { |
| 1386 | up(&lp->cmd_mutex); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1387 | if (lp->mc_reload_wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | mc32_reset_multicast_list(dev); |
| 1389 | } |
| 1390 | else complete(&lp->execution_cmd); |
| 1391 | } |
| 1392 | if(status&2) |
| 1393 | { |
| 1394 | /* |
| 1395 | * We get interrupted once per |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1396 | * counter that is about to overflow. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | */ |
| 1398 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1399 | mc32_update_stats(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | /* |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1405 | * Process the transmit and receive rings |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | */ |
| 1407 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1408 | if(tx_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | mc32_tx_ring(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1410 | |
| 1411 | if(rx_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | mc32_rx_ring(dev); |
| 1413 | |
| 1414 | return IRQ_HANDLED; |
| 1415 | } |
| 1416 | |
| 1417 | |
| 1418 | /** |
| 1419 | * mc32_close - user configuring the 3c527 down |
| 1420 | * @dev: 3c527 card to shut down |
| 1421 | * |
| 1422 | * The 3c527 is a bus mastering device. We must be careful how we |
| 1423 | * shut it down. It may also be running shared interrupt so we have |
| 1424 | * to be sure to silence it properly |
| 1425 | * |
| 1426 | * We indicate that the card is closing to the rest of the |
| 1427 | * driver. Otherwise, it is possible that the card may run out |
| 1428 | * of receive buffers and restart the transceiver while we're |
| 1429 | * trying to close it. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1430 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | * We abort any receive and transmits going on and then wait until |
| 1432 | * any pending exec commands have completed in other code threads. |
| 1433 | * In theory we can't get here while that is true, in practice I am |
| 1434 | * paranoid |
| 1435 | * |
| 1436 | * We turn off the interrupt enable for the board to be sure it can't |
| 1437 | * intefere with other devices. |
| 1438 | */ |
| 1439 | |
| 1440 | static int mc32_close(struct net_device *dev) |
| 1441 | { |
| 1442 | struct mc32_local *lp = netdev_priv(dev); |
| 1443 | int ioaddr = dev->base_addr; |
| 1444 | |
| 1445 | u8 regs; |
| 1446 | u16 one=1; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | lp->xceiver_desired_state = HALTED; |
| 1449 | netif_stop_queue(dev); |
| 1450 | |
| 1451 | /* |
| 1452 | * Send the indications on command (handy debug check) |
| 1453 | */ |
| 1454 | |
| 1455 | mc32_command(dev, 4, &one, 2); |
| 1456 | |
| 1457 | /* Shut down the transceiver */ |
| 1458 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1459 | mc32_halt_transceiver(dev); |
| 1460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | /* Ensure we issue no more commands beyond this point */ |
| 1462 | |
| 1463 | down(&lp->cmd_mutex); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1464 | |
| 1465 | /* Ok the card is now stopping */ |
| 1466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | regs=inb(ioaddr+HOST_CTRL); |
| 1468 | regs&=~HOST_CTRL_INTE; |
| 1469 | outb(regs, ioaddr+HOST_CTRL); |
| 1470 | |
| 1471 | mc32_flush_rx_ring(dev); |
| 1472 | mc32_flush_tx_ring(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1473 | |
| 1474 | mc32_update_stats(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | |
| 1480 | /** |
| 1481 | * mc32_get_stats - hand back stats to network layer |
| 1482 | * @dev: The 3c527 card to handle |
| 1483 | * |
| 1484 | * We've collected all the stats we can in software already. Now |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1485 | * it's time to update those kept on-card and return the lot. |
| 1486 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | */ |
| 1488 | |
| 1489 | static struct net_device_stats *mc32_get_stats(struct net_device *dev) |
| 1490 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1491 | mc32_update_stats(dev); |
Paulius Zaleckas | 4711c84 | 2008-04-29 12:09:38 +0300 | [diff] [blame^] | 1492 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | |
| 1496 | /** |
| 1497 | * do_mc32_set_multicast_list - attempt to update multicasts |
| 1498 | * @dev: 3c527 device to load the list on |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1499 | * @retry: indicates this is not the first call. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | * |
| 1501 | * |
| 1502 | * Actually set or clear the multicast filter for this adaptor. The |
| 1503 | * locking issues are handled by this routine. We have to track |
| 1504 | * state as it may take multiple calls to get the command sequence |
| 1505 | * completed. We just keep trying to schedule the loads until we |
| 1506 | * manage to process them all. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1508 | * num_addrs == -1 Promiscuous mode, receive all packets |
| 1509 | * |
| 1510 | * num_addrs == 0 Normal mode, clear multicast list |
| 1511 | * |
| 1512 | * num_addrs > 0 Multicast mode, receive normal and MC packets, |
| 1513 | * and do best-effort filtering. |
| 1514 | * |
| 1515 | * See mc32_update_stats() regards setting the SAV BP bit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | * |
| 1517 | */ |
| 1518 | |
| 1519 | static void do_mc32_set_multicast_list(struct net_device *dev, int retry) |
| 1520 | { |
| 1521 | struct mc32_local *lp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1522 | u16 filt = (1<<2); /* Save Bad Packets, for stats purposes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
| 1524 | if (dev->flags&IFF_PROMISC) |
| 1525 | /* Enable promiscuous mode */ |
| 1526 | filt |= 1; |
| 1527 | else if((dev->flags&IFF_ALLMULTI) || dev->mc_count > 10) |
| 1528 | { |
| 1529 | dev->flags|=IFF_PROMISC; |
| 1530 | filt |= 1; |
| 1531 | } |
| 1532 | else if(dev->mc_count) |
| 1533 | { |
| 1534 | unsigned char block[62]; |
| 1535 | unsigned char *bp; |
| 1536 | struct dev_mc_list *dmc=dev->mc_list; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | if(retry==0) |
| 1541 | lp->mc_list_valid = 0; |
| 1542 | if(!lp->mc_list_valid) |
| 1543 | { |
| 1544 | block[1]=0; |
| 1545 | block[0]=dev->mc_count; |
| 1546 | bp=block+2; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | for(i=0;i<dev->mc_count;i++) |
| 1549 | { |
| 1550 | memcpy(bp, dmc->dmi_addr, 6); |
| 1551 | bp+=6; |
| 1552 | dmc=dmc->next; |
| 1553 | } |
| 1554 | if(mc32_command_nowait(dev, 2, block, 2+6*dev->mc_count)==-1) |
| 1555 | { |
| 1556 | lp->mc_reload_wait = 1; |
| 1557 | return; |
| 1558 | } |
| 1559 | lp->mc_list_valid=1; |
| 1560 | } |
| 1561 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1562 | |
| 1563 | if(mc32_command_nowait(dev, 0, &filt, 2)==-1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | { |
| 1565 | lp->mc_reload_wait = 1; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1566 | } |
| 1567 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | lp->mc_reload_wait = 0; |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | |
| 1573 | /** |
| 1574 | * mc32_set_multicast_list - queue multicast list update |
| 1575 | * @dev: The 3c527 to use |
| 1576 | * |
| 1577 | * Commence loading the multicast list. This is called when the kernel |
| 1578 | * changes the lists. It will override any pending list we are trying to |
| 1579 | * load. |
| 1580 | */ |
| 1581 | |
| 1582 | static void mc32_set_multicast_list(struct net_device *dev) |
| 1583 | { |
| 1584 | do_mc32_set_multicast_list(dev,0); |
| 1585 | } |
| 1586 | |
| 1587 | |
| 1588 | /** |
| 1589 | * mc32_reset_multicast_list - reset multicast list |
| 1590 | * @dev: The 3c527 to use |
| 1591 | * |
| 1592 | * Attempt the next step in loading the multicast lists. If this attempt |
| 1593 | * fails to complete then it will be scheduled and this function called |
| 1594 | * again later from elsewhere. |
| 1595 | */ |
| 1596 | |
| 1597 | static void mc32_reset_multicast_list(struct net_device *dev) |
| 1598 | { |
| 1599 | do_mc32_set_multicast_list(dev,1); |
| 1600 | } |
| 1601 | |
| 1602 | static void netdev_get_drvinfo(struct net_device *dev, |
| 1603 | struct ethtool_drvinfo *info) |
| 1604 | { |
| 1605 | strcpy(info->driver, DRV_NAME); |
| 1606 | strcpy(info->version, DRV_VERSION); |
| 1607 | sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr); |
| 1608 | } |
| 1609 | |
| 1610 | static u32 netdev_get_msglevel(struct net_device *dev) |
| 1611 | { |
| 1612 | return mc32_debug; |
| 1613 | } |
| 1614 | |
| 1615 | static void netdev_set_msglevel(struct net_device *dev, u32 level) |
| 1616 | { |
| 1617 | mc32_debug = level; |
| 1618 | } |
| 1619 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1620 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | .get_drvinfo = netdev_get_drvinfo, |
| 1622 | .get_msglevel = netdev_get_msglevel, |
| 1623 | .set_msglevel = netdev_set_msglevel, |
| 1624 | }; |
| 1625 | |
| 1626 | #ifdef MODULE |
| 1627 | |
| 1628 | static struct net_device *this_device; |
| 1629 | |
| 1630 | /** |
| 1631 | * init_module - entry point |
| 1632 | * |
| 1633 | * Probe and locate a 3c527 card. This really should probe and locate |
| 1634 | * all the 3c527 cards in the machine not just one of them. Yes you can |
| 1635 | * insmod multiple modules for now but it's a hack. |
| 1636 | */ |
| 1637 | |
Randy Dunlap | 96e672c | 2006-06-10 13:33:48 -0700 | [diff] [blame] | 1638 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | { |
| 1640 | this_device = mc32_probe(-1); |
| 1641 | if (IS_ERR(this_device)) |
| 1642 | return PTR_ERR(this_device); |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | /** |
| 1647 | * cleanup_module - free resources for an unload |
| 1648 | * |
| 1649 | * Unloading time. We release the MCA bus resources and the interrupt |
| 1650 | * at which point everything is ready to unload. The card must be stopped |
| 1651 | * at this point or we would not have been called. When we unload we |
| 1652 | * leave the card stopped but not totally shut down. When the card is |
| 1653 | * initialized it must be rebooted or the rings reloaded before any |
| 1654 | * transmit operations are allowed to start scribbling into memory. |
| 1655 | */ |
| 1656 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 1657 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | { |
| 1659 | unregister_netdev(this_device); |
| 1660 | cleanup_card(this_device); |
| 1661 | free_netdev(this_device); |
| 1662 | } |
| 1663 | |
| 1664 | #endif /* MODULE */ |