Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 2 | * xircom_cb: A driver for the (tulip-like) Xircom Cardbus ethernet cards |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * This software is (C) by the respective authors, and licensed under the GPL |
| 5 | * License. |
| 6 | * |
| 7 | * Written by Arjan van de Ven for Red Hat, Inc. |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 8 | * Based on work by Jeff Garzik, Doug Ledford and Donald Becker |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This software may be used and distributed according to the terms |
| 11 | * of the GNU General Public License, incorporated herein by reference. |
| 12 | * |
| 13 | * |
| 14 | * $Id: xircom_cb.c,v 1.33 2001/03/19 14:02:07 arjanv Exp $ |
| 15 | */ |
| 16 | |
Joe Perches | 44298ec | 2010-01-28 20:59:29 +0000 | [diff] [blame] | 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/pci.h> |
| 27 | #include <linux/netdevice.h> |
| 28 | #include <linux/etherdevice.h> |
| 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/bitops.h> |
| 33 | |
| 34 | #include <asm/uaccess.h> |
| 35 | #include <asm/io.h> |
Al Viro | 8272997 | 2005-12-06 05:53:04 -0500 | [diff] [blame] | 36 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 37 | #include <asm/irq.h> |
| 38 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | MODULE_DESCRIPTION("Xircom Cardbus ethernet driver"); |
| 41 | MODULE_AUTHOR("Arjan van de Ven <arjanv@redhat.com>"); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | |
| 44 | |
| 45 | |
| 46 | /* IO registers on the card, offsets */ |
| 47 | #define CSR0 0x00 |
| 48 | #define CSR1 0x08 |
| 49 | #define CSR2 0x10 |
| 50 | #define CSR3 0x18 |
| 51 | #define CSR4 0x20 |
| 52 | #define CSR5 0x28 |
| 53 | #define CSR6 0x30 |
| 54 | #define CSR7 0x38 |
| 55 | #define CSR8 0x40 |
| 56 | #define CSR9 0x48 |
| 57 | #define CSR10 0x50 |
| 58 | #define CSR11 0x58 |
| 59 | #define CSR12 0x60 |
| 60 | #define CSR13 0x68 |
| 61 | #define CSR14 0x70 |
| 62 | #define CSR15 0x78 |
| 63 | #define CSR16 0x80 |
| 64 | |
| 65 | /* PCI registers */ |
| 66 | #define PCI_POWERMGMT 0x40 |
| 67 | |
| 68 | /* Offsets of the buffers within the descriptor pages, in bytes */ |
| 69 | |
| 70 | #define NUMDESCRIPTORS 4 |
| 71 | |
| 72 | static int bufferoffsets[NUMDESCRIPTORS] = {128,2048,4096,6144}; |
| 73 | |
| 74 | |
| 75 | struct xircom_private { |
| 76 | /* Send and receive buffers, kernel-addressable and dma addressable forms */ |
| 77 | |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 78 | __le32 *rx_buffer; |
| 79 | __le32 *tx_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | dma_addr_t rx_dma_handle; |
| 82 | dma_addr_t tx_dma_handle; |
| 83 | |
| 84 | struct sk_buff *tx_skb[4]; |
| 85 | |
| 86 | unsigned long io_port; |
| 87 | int open; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* transmit_used is the rotating counter that indicates which transmit |
| 90 | descriptor has to be used next */ |
| 91 | int transmit_used; |
| 92 | |
| 93 | /* Spinlock to serialize register operations. |
| 94 | It must be helt while manipulating the following registers: |
| 95 | CSR0, CSR6, CSR7, CSR9, CSR10, CSR15 |
| 96 | */ |
| 97 | spinlock_t lock; |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | struct pci_dev *pdev; |
| 100 | struct net_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | |
| 104 | /* Function prototypes */ |
| 105 | static int xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id); |
| 106 | static void xircom_remove(struct pci_dev *pdev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 107 | static irqreturn_t xircom_interrupt(int irq, void *dev_instance); |
Stephen Hemminger | ad09646 | 2009-08-31 19:50:53 +0000 | [diff] [blame] | 108 | static netdev_tx_t xircom_start_xmit(struct sk_buff *skb, |
| 109 | struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | static int xircom_open(struct net_device *dev); |
| 111 | static int xircom_close(struct net_device *dev); |
| 112 | static void xircom_up(struct xircom_private *card); |
Keith Owens | 3be034b | 2005-09-13 15:05:13 +1000 | [diff] [blame] | 113 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static void xircom_poll_controller(struct net_device *dev); |
| 115 | #endif |
| 116 | |
| 117 | static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset); |
| 118 | static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset); |
| 119 | static void read_mac_address(struct xircom_private *card); |
| 120 | static void transceiver_voodoo(struct xircom_private *card); |
| 121 | static void initialize_card(struct xircom_private *card); |
| 122 | static void trigger_transmit(struct xircom_private *card); |
| 123 | static void trigger_receive(struct xircom_private *card); |
| 124 | static void setup_descriptors(struct xircom_private *card); |
| 125 | static void remove_descriptors(struct xircom_private *card); |
| 126 | static int link_status_changed(struct xircom_private *card); |
| 127 | static void activate_receiver(struct xircom_private *card); |
| 128 | static void deactivate_receiver(struct xircom_private *card); |
| 129 | static void activate_transmitter(struct xircom_private *card); |
| 130 | static void deactivate_transmitter(struct xircom_private *card); |
| 131 | static void enable_transmit_interrupt(struct xircom_private *card); |
| 132 | static void enable_receive_interrupt(struct xircom_private *card); |
| 133 | static void enable_link_interrupt(struct xircom_private *card); |
| 134 | static void disable_all_interrupts(struct xircom_private *card); |
| 135 | static int link_status(struct xircom_private *card); |
| 136 | |
| 137 | |
| 138 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 139 | static DEFINE_PCI_DEVICE_TABLE(xircom_pci_table) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | {0x115D, 0x0003, PCI_ANY_ID, PCI_ANY_ID,}, |
| 141 | {0,}, |
| 142 | }; |
| 143 | MODULE_DEVICE_TABLE(pci, xircom_pci_table); |
| 144 | |
| 145 | static struct pci_driver xircom_ops = { |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 146 | .name = "xircom_cb", |
| 147 | .id_table = xircom_pci_table, |
| 148 | .probe = xircom_probe, |
| 149 | .remove = xircom_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | .suspend =NULL, |
| 151 | .resume =NULL |
| 152 | }; |
| 153 | |
| 154 | |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 155 | #if defined DEBUG && DEBUG > 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | static void print_binary(unsigned int number) |
| 157 | { |
| 158 | int i,i2; |
| 159 | char buffer[64]; |
| 160 | memset(buffer,0,64); |
| 161 | i2=0; |
| 162 | for (i=31;i>=0;i--) { |
| 163 | if (number & (1<<i)) |
| 164 | buffer[i2++]='1'; |
| 165 | else |
| 166 | buffer[i2++]='0'; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 167 | if ((i&3)==0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | buffer[i2++]=' '; |
| 169 | } |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 170 | pr_debug("%s\n",buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | #endif |
| 173 | |
Stephen Hemminger | 1034c9f | 2009-01-07 18:00:55 -0800 | [diff] [blame] | 174 | static const struct net_device_ops netdev_ops = { |
| 175 | .ndo_open = xircom_open, |
| 176 | .ndo_stop = xircom_close, |
| 177 | .ndo_start_xmit = xircom_start_xmit, |
| 178 | .ndo_change_mtu = eth_change_mtu, |
| 179 | .ndo_set_mac_address = eth_mac_addr, |
| 180 | .ndo_validate_addr = eth_validate_addr, |
| 181 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 182 | .ndo_poll_controller = xircom_poll_controller, |
| 183 | #endif |
| 184 | }; |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* xircom_probe is the code that gets called on device insertion. |
| 187 | it sets up the hardware and registers the device to the networklayer. |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | TODO: Send 1 or 2 "dummy" packets here as the card seems to discard the |
| 190 | first two packets that get send, and pump hates that. |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | */ |
| 193 | static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 194 | { |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 195 | struct device *d = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | struct net_device *dev = NULL; |
| 197 | struct xircom_private *private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | unsigned long flags; |
| 199 | unsigned short tmp16; |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 200 | int rc; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | /* First do the PCI initialisation */ |
| 203 | |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 204 | rc = pci_enable_device(pdev); |
| 205 | if (rc < 0) |
| 206 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | /* disable all powermanagement */ |
| 209 | pci_write_config_dword(pdev, PCI_POWERMGMT, 0x0000); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | pci_set_master(pdev); /* Why isn't this done by pci_enable_device ?*/ |
| 212 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 213 | /* clear PCI status, if any */ |
| 214 | pci_read_config_word (pdev,PCI_STATUS, &tmp16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | pci_write_config_word (pdev, PCI_STATUS,tmp16); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 216 | |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 217 | rc = pci_request_regions(pdev, "xircom_cb"); |
| 218 | if (rc < 0) { |
Joe Perches | 44298ec | 2010-01-28 20:59:29 +0000 | [diff] [blame] | 219 | pr_err("%s: failed to allocate io-region\n", __func__); |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 220 | goto err_disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 223 | rc = -ENOMEM; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 224 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | Before changing the hardware, allocate the memory. |
| 226 | This way, we can fail gracefully if not enough memory |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 227 | is available. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | */ |
| 229 | dev = alloc_etherdev(sizeof(struct xircom_private)); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 230 | if (!dev) |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 231 | goto err_release; |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | private = netdev_priv(dev); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | /* Allocate the send/receive buffers */ |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 236 | private->rx_buffer = dma_alloc_coherent(d, 8192, |
| 237 | &private->rx_dma_handle, |
| 238 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | if (private->rx_buffer == NULL) { |
Joe Perches | 44298ec | 2010-01-28 20:59:29 +0000 | [diff] [blame] | 240 | pr_err("%s: no memory for rx buffer\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | goto rx_buf_fail; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 242 | } |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 243 | private->tx_buffer = dma_alloc_coherent(d, 8192, |
| 244 | &private->tx_dma_handle, |
| 245 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | if (private->tx_buffer == NULL) { |
Joe Perches | 44298ec | 2010-01-28 20:59:29 +0000 | [diff] [blame] | 247 | pr_err("%s: no memory for tx buffer\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | goto tx_buf_fail; |
| 249 | } |
| 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 252 | |
| 253 | |
| 254 | private->dev = dev; |
| 255 | private->pdev = pdev; |
| 256 | private->io_port = pci_resource_start(pdev, 0); |
| 257 | spin_lock_init(&private->lock); |
| 258 | dev->irq = pdev->irq; |
| 259 | dev->base_addr = private->io_port; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | initialize_card(private); |
| 262 | read_mac_address(private); |
| 263 | setup_descriptors(private); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 264 | |
Stephen Hemminger | 1034c9f | 2009-01-07 18:00:55 -0800 | [diff] [blame] | 265 | dev->netdev_ops = &netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | pci_set_drvdata(pdev, dev); |
| 267 | |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 268 | rc = register_netdev(dev); |
| 269 | if (rc < 0) { |
Joe Perches | 44298ec | 2010-01-28 20:59:29 +0000 | [diff] [blame] | 270 | pr_err("%s: netdevice registration failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | goto reg_fail; |
| 272 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 273 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 274 | netdev_info(dev, "Xircom cardbus revision %i at irq %i\n", |
| 275 | pdev->revision, pdev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* start the transmitter to get a heartbeat */ |
| 277 | /* TODO: send 2 dummy packets here */ |
| 278 | transceiver_voodoo(private); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | spin_lock_irqsave(&private->lock,flags); |
| 281 | activate_transmitter(private); |
| 282 | activate_receiver(private); |
| 283 | spin_unlock_irqrestore(&private->lock,flags); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | trigger_receive(private); |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 286 | out: |
| 287 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | reg_fail: |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 290 | pci_set_drvdata(pdev, NULL); |
| 291 | dma_free_coherent(d, 8192, private->tx_buffer, private->tx_dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | tx_buf_fail: |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 293 | dma_free_coherent(d, 8192, private->rx_buffer, private->rx_dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | rx_buf_fail: |
| 295 | free_netdev(dev); |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 296 | err_release: |
| 297 | pci_release_regions(pdev); |
| 298 | err_disable: |
| 299 | pci_disable_device(pdev); |
| 300 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | |
| 304 | /* |
| 305 | xircom_remove is called on module-unload or on device-eject. |
| 306 | it unregisters the irq, io-region and network device. |
| 307 | Interrupts and such are already stopped in the "ifconfig ethX down" |
| 308 | code. |
| 309 | */ |
| 310 | static void __devexit xircom_remove(struct pci_dev *pdev) |
| 311 | { |
| 312 | struct net_device *dev = pci_get_drvdata(pdev); |
| 313 | struct xircom_private *card = netdev_priv(dev); |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 314 | struct device *d = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | unregister_netdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | pci_set_drvdata(pdev, NULL); |
Francois Romieu | d59a188 | 2012-03-11 23:34:54 +0100 | [diff] [blame^] | 318 | dma_free_coherent(d, 8192, card->tx_buffer, card->tx_dma_handle); |
| 319 | dma_free_coherent(d, 8192, card->rx_buffer, card->rx_dma_handle); |
| 320 | free_netdev(dev); |
| 321 | pci_release_regions(pdev); |
| 322 | pci_disable_device(pdev); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 325 | static irqreturn_t xircom_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
| 327 | struct net_device *dev = (struct net_device *) dev_instance; |
| 328 | struct xircom_private *card = netdev_priv(dev); |
| 329 | unsigned int status; |
| 330 | int i; |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | spin_lock(&card->lock); |
| 333 | status = inl(card->io_port+CSR5); |
| 334 | |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 335 | #if defined DEBUG && DEBUG > 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | print_binary(status); |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 337 | pr_debug("tx status 0x%08x 0x%08x\n", |
| 338 | card->tx_buffer[0], card->tx_buffer[4]); |
| 339 | pr_debug("rx status 0x%08x 0x%08x\n", |
| 340 | card->rx_buffer[0], card->rx_buffer[4]); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 341 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /* Handle shared irq and hotplug */ |
| 343 | if (status == 0 || status == 0xffffffff) { |
| 344 | spin_unlock(&card->lock); |
| 345 | return IRQ_NONE; |
| 346 | } |
| 347 | |
| 348 | if (link_status_changed(card)) { |
| 349 | int newlink; |
Joe Perches | 726b65a | 2011-05-09 09:45:22 +0000 | [diff] [blame] | 350 | netdev_dbg(dev, "Link status has changed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | newlink = link_status(card); |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 352 | netdev_info(dev, "Link is %d mbit\n", newlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (newlink) |
| 354 | netif_carrier_on(dev); |
| 355 | else |
| 356 | netif_carrier_off(dev); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 360 | /* Clear all remaining interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | status |= 0xffffffff; /* FIXME: make this clear only the |
| 362 | real existing bits */ |
| 363 | outl(status,card->io_port+CSR5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 365 | |
| 366 | for (i=0;i<NUMDESCRIPTORS;i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | investigate_write_descriptor(dev,card,i,bufferoffsets[i]); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 368 | for (i=0;i<NUMDESCRIPTORS;i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | investigate_read_descriptor(dev,card,i,bufferoffsets[i]); |
| 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | spin_unlock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | return IRQ_HANDLED; |
| 373 | } |
| 374 | |
Stephen Hemminger | ad09646 | 2009-08-31 19:50:53 +0000 | [diff] [blame] | 375 | static netdev_tx_t xircom_start_xmit(struct sk_buff *skb, |
| 376 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | struct xircom_private *card; |
| 379 | unsigned long flags; |
| 380 | int nextdescriptor; |
| 381 | int desc; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | card = netdev_priv(dev); |
| 384 | spin_lock_irqsave(&card->lock,flags); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /* First see if we can free some descriptors */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 387 | for (desc=0;desc<NUMDESCRIPTORS;desc++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | investigate_write_descriptor(dev,card,desc,bufferoffsets[desc]); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 389 | |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | nextdescriptor = (card->transmit_used +1) % (NUMDESCRIPTORS); |
| 392 | desc = card->transmit_used; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | /* only send the packet if the descriptor is free */ |
| 395 | if (card->tx_buffer[4*desc]==0) { |
| 396 | /* Copy the packet data; zero the memory first as the card |
| 397 | sometimes sends more than you ask it to. */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | memset(&card->tx_buffer[bufferoffsets[desc]/4],0,1536); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 400 | skb_copy_from_linear_data(skb, |
| 401 | &(card->tx_buffer[bufferoffsets[desc] / 4]), |
| 402 | skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | /* FIXME: The specification tells us that the length we send HAS to be a multiple of |
| 404 | 4 bytes. */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 405 | |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 406 | card->tx_buffer[4*desc+1] = cpu_to_le32(skb->len); |
| 407 | if (desc == NUMDESCRIPTORS - 1) /* bit 25: last descriptor of the ring */ |
| 408 | card->tx_buffer[4*desc+1] |= cpu_to_le32(1<<25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 410 | card->tx_buffer[4*desc+1] |= cpu_to_le32(0xF0000000); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 411 | /* 0xF0... means want interrupts*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | card->tx_skb[desc] = skb; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | wmb(); |
| 415 | /* This gives the descriptor to the card */ |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 416 | card->tx_buffer[4*desc] = cpu_to_le32(0x80000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | trigger_transmit(card); |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 418 | if (card->tx_buffer[nextdescriptor*4] & cpu_to_le32(0x8000000)) { |
| 419 | /* next descriptor is occupied... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | netif_stop_queue(dev); |
| 421 | } |
| 422 | card->transmit_used = nextdescriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | spin_unlock_irqrestore(&card->lock,flags); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 424 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | /* Uh oh... no free descriptor... drop the packet */ |
| 428 | netif_stop_queue(dev); |
| 429 | spin_unlock_irqrestore(&card->lock,flags); |
| 430 | trigger_transmit(card); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 431 | |
Erik Mouw | 06f7525 | 2008-02-04 18:56:54 +0100 | [diff] [blame] | 432 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | static int xircom_open(struct net_device *dev) |
| 439 | { |
| 440 | struct xircom_private *xp = netdev_priv(dev); |
| 441 | int retval; |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 442 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 443 | netdev_info(dev, "xircom cardbus adaptor found, using irq %i\n", |
| 444 | dev->irq); |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 445 | retval = request_irq(dev->irq, xircom_interrupt, IRQF_SHARED, dev->name, dev); |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 446 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | return retval; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | xircom_up(xp); |
| 450 | xp->open = 1; |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int xircom_close(struct net_device *dev) |
| 456 | { |
| 457 | struct xircom_private *card; |
| 458 | unsigned long flags; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | card = netdev_priv(dev); |
| 461 | netif_stop_queue(dev); /* we don't want new packets */ |
| 462 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | spin_lock_irqsave(&card->lock,flags); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | disable_all_interrupts(card); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 467 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | /* We can enable this again once we send dummy packets on ifconfig ethX up */ |
| 469 | deactivate_receiver(card); |
| 470 | deactivate_transmitter(card); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 471 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | remove_descriptors(card); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | spin_unlock_irqrestore(&card->lock,flags); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | card->open = 0; |
| 477 | free_irq(dev->irq,dev); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | return 0; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 485 | static void xircom_poll_controller(struct net_device *dev) |
| 486 | { |
| 487 | disable_irq(dev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 488 | xircom_interrupt(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | enable_irq(dev->irq); |
| 490 | } |
| 491 | #endif |
| 492 | |
| 493 | |
| 494 | static void initialize_card(struct xircom_private *card) |
| 495 | { |
| 496 | unsigned int val; |
| 497 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | spin_lock_irqsave(&card->lock, flags); |
| 500 | |
| 501 | /* First: reset the card */ |
| 502 | val = inl(card->io_port + CSR0); |
| 503 | val |= 0x01; /* Software reset */ |
| 504 | outl(val, card->io_port + CSR0); |
| 505 | |
| 506 | udelay(100); /* give the card some time to reset */ |
| 507 | |
| 508 | val = inl(card->io_port + CSR0); |
| 509 | val &= ~0x01; /* disable Software reset */ |
| 510 | outl(val, card->io_port + CSR0); |
| 511 | |
| 512 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 513 | val = 0; /* Value 0x00 is a safe and conservative value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | for the PCI configuration settings */ |
| 515 | outl(val, card->io_port + CSR0); |
| 516 | |
| 517 | |
| 518 | disable_all_interrupts(card); |
| 519 | deactivate_receiver(card); |
| 520 | deactivate_transmitter(card); |
| 521 | |
| 522 | spin_unlock_irqrestore(&card->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /* |
| 526 | trigger_transmit causes the card to check for frames to be transmitted. |
| 527 | This is accomplished by writing to the CSR1 port. The documentation |
| 528 | claims that the act of writing is sufficient and that the value is |
| 529 | ignored; I chose zero. |
| 530 | */ |
| 531 | static void trigger_transmit(struct xircom_private *card) |
| 532 | { |
| 533 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | val = 0; |
| 536 | outl(val, card->io_port + CSR1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* |
| 540 | trigger_receive causes the card to check for empty frames in the |
| 541 | descriptor list in which packets can be received. |
| 542 | This is accomplished by writing to the CSR2 port. The documentation |
| 543 | claims that the act of writing is sufficient and that the value is |
| 544 | ignored; I chose zero. |
| 545 | */ |
| 546 | static void trigger_receive(struct xircom_private *card) |
| 547 | { |
| 548 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
| 550 | val = 0; |
| 551 | outl(val, card->io_port + CSR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* |
| 555 | setup_descriptors initializes the send and receive buffers to be valid |
| 556 | descriptors and programs the addresses into the card. |
| 557 | */ |
| 558 | static void setup_descriptors(struct xircom_private *card) |
| 559 | { |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 560 | u32 address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Eric Sesterhenn / snakebyte | a707cd6 | 2006-01-26 22:02:51 +0100 | [diff] [blame] | 563 | BUG_ON(card->rx_buffer == NULL); |
| 564 | BUG_ON(card->tx_buffer == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
| 566 | /* Receive descriptors */ |
| 567 | memset(card->rx_buffer, 0, 128); /* clear the descriptors */ |
| 568 | for (i=0;i<NUMDESCRIPTORS;i++ ) { |
| 569 | |
| 570 | /* Rx Descr0: It's empty, let the card own it, no errors -> 0x80000000 */ |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 571 | card->rx_buffer[i*4 + 0] = cpu_to_le32(0x80000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | /* Rx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */ |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 573 | card->rx_buffer[i*4 + 1] = cpu_to_le32(1536); |
| 574 | if (i == NUMDESCRIPTORS - 1) /* bit 25 is "last descriptor" */ |
| 575 | card->rx_buffer[i*4 + 1] |= cpu_to_le32(1 << 25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | /* Rx Descr2: address of the buffer |
| 578 | we store the buffer at the 2nd half of the page */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 579 | |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 580 | address = card->rx_dma_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | card->rx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]); |
| 582 | /* Rx Desc3: address of 2nd buffer -> 0 */ |
| 583 | card->rx_buffer[i*4 + 3] = 0; |
| 584 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | wmb(); |
| 587 | /* Write the receive descriptor ring address to the card */ |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 588 | address = card->rx_dma_handle; |
| 589 | outl(address, card->io_port + CSR3); /* Receive descr list address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 591 | |
| 592 | /* transmit descriptors */ |
| 593 | memset(card->tx_buffer, 0, 128); /* clear the descriptors */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | for (i=0;i<NUMDESCRIPTORS;i++ ) { |
| 596 | /* Tx Descr0: Empty, we own it, no errors -> 0x00000000 */ |
| 597 | card->tx_buffer[i*4 + 0] = 0x00000000; |
| 598 | /* Tx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */ |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 599 | card->tx_buffer[i*4 + 1] = cpu_to_le32(1536); |
| 600 | if (i == NUMDESCRIPTORS - 1) /* bit 25 is "last descriptor" */ |
| 601 | card->tx_buffer[i*4 + 1] |= cpu_to_le32(1 << 25); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | /* Tx Descr2: address of the buffer |
| 604 | we store the buffer at the 2nd half of the page */ |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 605 | address = card->tx_dma_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | card->tx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]); |
| 607 | /* Tx Desc3: address of 2nd buffer -> 0 */ |
| 608 | card->tx_buffer[i*4 + 3] = 0; |
| 609 | } |
| 610 | |
| 611 | wmb(); |
| 612 | /* wite the transmit descriptor ring to the card */ |
Al Viro | 6f35d5d | 2007-12-23 20:01:04 +0000 | [diff] [blame] | 613 | address = card->tx_dma_handle; |
| 614 | outl(address, card->io_port + CSR4); /* xmit descr list address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /* |
| 618 | remove_descriptors informs the card the descriptors are no longer |
| 619 | valid by setting the address in the card to 0x00. |
| 620 | */ |
| 621 | static void remove_descriptors(struct xircom_private *card) |
| 622 | { |
| 623 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | val = 0; |
| 626 | outl(val, card->io_port + CSR3); /* Receive descriptor address */ |
| 627 | outl(val, card->io_port + CSR4); /* Send descriptor address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* |
| 631 | link_status_changed returns 1 if the card has indicated that |
| 632 | the link status has changed. The new link status has to be read from CSR12. |
| 633 | |
| 634 | This function also clears the status-bit. |
| 635 | */ |
| 636 | static int link_status_changed(struct xircom_private *card) |
| 637 | { |
| 638 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | val = inl(card->io_port + CSR5); /* Status register */ |
| 641 | |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 642 | if ((val & (1 << 27)) == 0) /* no change */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | /* clear the event by writing a 1 to the bit in the |
| 646 | status register. */ |
| 647 | val = (1 << 27); |
| 648 | outl(val, card->io_port + CSR5); |
| 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | return 1; |
| 651 | } |
| 652 | |
| 653 | |
| 654 | /* |
| 655 | transmit_active returns 1 if the transmitter on the card is |
| 656 | in a non-stopped state. |
| 657 | */ |
| 658 | static int transmit_active(struct xircom_private *card) |
| 659 | { |
| 660 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
| 662 | val = inl(card->io_port + CSR5); /* Status register */ |
| 663 | |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 664 | if ((val & (7 << 20)) == 0) /* transmitter disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | return 1; |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | receive_active returns 1 if the receiver on the card is |
| 672 | in a non-stopped state. |
| 673 | */ |
| 674 | static int receive_active(struct xircom_private *card) |
| 675 | { |
| 676 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
| 678 | val = inl(card->io_port + CSR5); /* Status register */ |
| 679 | |
Joe Perches | 54668b8 | 2011-05-09 09:45:20 +0000 | [diff] [blame] | 680 | if ((val & (7 << 17)) == 0) /* receiver disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | return 1; |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | activate_receiver enables the receiver on the card. |
| 688 | Before being allowed to active the receiver, the receiver |
| 689 | must be completely de-activated. To achieve this, |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 690 | this code actually disables the receiver first; then it waits for the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | receiver to become inactive, then it activates the receiver and then |
| 692 | it waits for the receiver to be active. |
| 693 | |
| 694 | must be called with the lock held and interrupts disabled. |
| 695 | */ |
| 696 | static void activate_receiver(struct xircom_private *card) |
| 697 | { |
| 698 | unsigned int val; |
| 699 | int counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | val = inl(card->io_port + CSR6); /* Operation mode */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | /* If the "active" bit is set and the receiver is already |
| 704 | active, no need to do the expensive thing */ |
| 705 | if ((val&2) && (receive_active(card))) |
| 706 | return; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 707 | |
| 708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | val = val & ~2; /* disable the receiver */ |
| 710 | outl(val, card->io_port + CSR6); |
| 711 | |
| 712 | counter = 10; |
| 713 | while (counter > 0) { |
| 714 | if (!receive_active(card)) |
| 715 | break; |
| 716 | /* wait a while */ |
| 717 | udelay(50); |
| 718 | counter--; |
| 719 | if (counter <= 0) |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 720 | netdev_err(card->dev, "Receiver failed to deactivate\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /* enable the receiver */ |
| 724 | val = inl(card->io_port + CSR6); /* Operation mode */ |
| 725 | val = val | 2; /* enable the receiver */ |
| 726 | outl(val, card->io_port + CSR6); |
| 727 | |
| 728 | /* now wait for the card to activate again */ |
| 729 | counter = 10; |
| 730 | while (counter > 0) { |
| 731 | if (receive_active(card)) |
| 732 | break; |
| 733 | /* wait a while */ |
| 734 | udelay(50); |
| 735 | counter--; |
| 736 | if (counter <= 0) |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 737 | netdev_err(card->dev, |
| 738 | "Receiver failed to re-activate\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /* |
| 743 | deactivate_receiver disables the receiver on the card. |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 744 | To achieve this this code disables the receiver first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | then it waits for the receiver to become inactive. |
| 746 | |
| 747 | must be called with the lock held and interrupts disabled. |
| 748 | */ |
| 749 | static void deactivate_receiver(struct xircom_private *card) |
| 750 | { |
| 751 | unsigned int val; |
| 752 | int counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | val = inl(card->io_port + CSR6); /* Operation mode */ |
| 755 | val = val & ~2; /* disable the receiver */ |
| 756 | outl(val, card->io_port + CSR6); |
| 757 | |
| 758 | counter = 10; |
| 759 | while (counter > 0) { |
| 760 | if (!receive_active(card)) |
| 761 | break; |
| 762 | /* wait a while */ |
| 763 | udelay(50); |
| 764 | counter--; |
| 765 | if (counter <= 0) |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 766 | netdev_err(card->dev, "Receiver failed to deactivate\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | |
| 771 | /* |
| 772 | activate_transmitter enables the transmitter on the card. |
| 773 | Before being allowed to active the transmitter, the transmitter |
| 774 | must be completely de-activated. To achieve this, |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 775 | this code actually disables the transmitter first; then it waits for the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | transmitter to become inactive, then it activates the transmitter and then |
| 777 | it waits for the transmitter to be active again. |
| 778 | |
| 779 | must be called with the lock held and interrupts disabled. |
| 780 | */ |
| 781 | static void activate_transmitter(struct xircom_private *card) |
| 782 | { |
| 783 | unsigned int val; |
| 784 | int counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | val = inl(card->io_port + CSR6); /* Operation mode */ |
| 787 | |
| 788 | /* If the "active" bit is set and the receiver is already |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 789 | active, no need to do the expensive thing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | if ((val&(1<<13)) && (transmit_active(card))) |
| 791 | return; |
| 792 | |
| 793 | val = val & ~(1 << 13); /* disable the transmitter */ |
| 794 | outl(val, card->io_port + CSR6); |
| 795 | |
| 796 | counter = 10; |
| 797 | while (counter > 0) { |
| 798 | if (!transmit_active(card)) |
| 799 | break; |
| 800 | /* wait a while */ |
| 801 | udelay(50); |
| 802 | counter--; |
| 803 | if (counter <= 0) |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 804 | netdev_err(card->dev, |
| 805 | "Transmitter failed to deactivate\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* enable the transmitter */ |
| 809 | val = inl(card->io_port + CSR6); /* Operation mode */ |
| 810 | val = val | (1 << 13); /* enable the transmitter */ |
| 811 | outl(val, card->io_port + CSR6); |
| 812 | |
| 813 | /* now wait for the card to activate again */ |
| 814 | counter = 10; |
| 815 | while (counter > 0) { |
| 816 | if (transmit_active(card)) |
| 817 | break; |
| 818 | /* wait a while */ |
| 819 | udelay(50); |
| 820 | counter--; |
| 821 | if (counter <= 0) |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 822 | netdev_err(card->dev, |
| 823 | "Transmitter failed to re-activate\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | /* |
| 828 | deactivate_transmitter disables the transmitter on the card. |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 829 | To achieve this this code disables the transmitter first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | then it waits for the transmitter to become inactive. |
| 831 | |
| 832 | must be called with the lock held and interrupts disabled. |
| 833 | */ |
| 834 | static void deactivate_transmitter(struct xircom_private *card) |
| 835 | { |
| 836 | unsigned int val; |
| 837 | int counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | val = inl(card->io_port + CSR6); /* Operation mode */ |
| 840 | val = val & ~2; /* disable the transmitter */ |
| 841 | outl(val, card->io_port + CSR6); |
| 842 | |
| 843 | counter = 20; |
| 844 | while (counter > 0) { |
| 845 | if (!transmit_active(card)) |
| 846 | break; |
| 847 | /* wait a while */ |
| 848 | udelay(50); |
| 849 | counter--; |
| 850 | if (counter <= 0) |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 851 | netdev_err(card->dev, |
| 852 | "Transmitter failed to deactivate\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | |
| 857 | /* |
| 858 | enable_transmit_interrupt enables the transmit interrupt |
| 859 | |
| 860 | must be called with the lock held and interrupts disabled. |
| 861 | */ |
| 862 | static void enable_transmit_interrupt(struct xircom_private *card) |
| 863 | { |
| 864 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | val = inl(card->io_port + CSR7); /* Interrupt enable register */ |
| 867 | val |= 1; /* enable the transmit interrupt */ |
| 868 | outl(val, card->io_port + CSR7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | |
| 872 | /* |
| 873 | enable_receive_interrupt enables the receive interrupt |
| 874 | |
| 875 | must be called with the lock held and interrupts disabled. |
| 876 | */ |
| 877 | static void enable_receive_interrupt(struct xircom_private *card) |
| 878 | { |
| 879 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | val = inl(card->io_port + CSR7); /* Interrupt enable register */ |
| 882 | val = val | (1 << 6); /* enable the receive interrupt */ |
| 883 | outl(val, card->io_port + CSR7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /* |
| 887 | enable_link_interrupt enables the link status change interrupt |
| 888 | |
| 889 | must be called with the lock held and interrupts disabled. |
| 890 | */ |
| 891 | static void enable_link_interrupt(struct xircom_private *card) |
| 892 | { |
| 893 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | val = inl(card->io_port + CSR7); /* Interrupt enable register */ |
| 896 | val = val | (1 << 27); /* enable the link status chage interrupt */ |
| 897 | outl(val, card->io_port + CSR7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | |
| 901 | |
| 902 | /* |
| 903 | disable_all_interrupts disables all interrupts |
| 904 | |
| 905 | must be called with the lock held and interrupts disabled. |
| 906 | */ |
| 907 | static void disable_all_interrupts(struct xircom_private *card) |
| 908 | { |
| 909 | unsigned int val; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | val = 0; /* disable all interrupts */ |
| 912 | outl(val, card->io_port + CSR7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /* |
| 916 | enable_common_interrupts enables several weird interrupts |
| 917 | |
| 918 | must be called with the lock held and interrupts disabled. |
| 919 | */ |
| 920 | static void enable_common_interrupts(struct xircom_private *card) |
| 921 | { |
| 922 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
| 924 | val = inl(card->io_port + CSR7); /* Interrupt enable register */ |
| 925 | val |= (1<<16); /* Normal Interrupt Summary */ |
| 926 | val |= (1<<15); /* Abnormal Interrupt Summary */ |
| 927 | val |= (1<<13); /* Fatal bus error */ |
| 928 | val |= (1<<8); /* Receive Process Stopped */ |
| 929 | val |= (1<<7); /* Receive Buffer Unavailable */ |
| 930 | val |= (1<<5); /* Transmit Underflow */ |
| 931 | val |= (1<<2); /* Transmit Buffer Unavailable */ |
| 932 | val |= (1<<1); /* Transmit Process Stopped */ |
| 933 | outl(val, card->io_port + CSR7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /* |
| 937 | enable_promisc starts promisc mode |
| 938 | |
| 939 | must be called with the lock held and interrupts disabled. |
| 940 | */ |
| 941 | static int enable_promisc(struct xircom_private *card) |
| 942 | { |
| 943 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 945 | val = inl(card->io_port + CSR6); |
| 946 | val = val | (1 << 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | outl(val, card->io_port + CSR6); |
| 948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | return 1; |
| 950 | } |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 955 | /* |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 956 | link_status() checks the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
| 958 | Must be called in locked state with interrupts disabled |
| 959 | */ |
| 960 | static int link_status(struct xircom_private *card) |
| 961 | { |
| 962 | unsigned int val; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | val = inb(card->io_port + CSR12); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | if (!(val&(1<<2))) /* bit 2 is 0 for 10mbit link, 1 for not an 10mbit link */ |
| 967 | return 10; |
| 968 | if (!(val&(1<<1))) /* bit 1 is 0 for 100mbit link, 1 for not an 100mbit link */ |
| 969 | return 100; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 970 | |
| 971 | /* If we get here -> no link at all */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | /* |
| 981 | read_mac_address() reads the MAC address from the NIC and stores it in the "dev" structure. |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | This function will take the spinlock itself and can, as a result, not be called with the lock helt. |
| 984 | */ |
| 985 | static void read_mac_address(struct xircom_private *card) |
| 986 | { |
| 987 | unsigned char j, tuple, link, data_id, data_count; |
| 988 | unsigned long flags; |
| 989 | int i; |
| 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | spin_lock_irqsave(&card->lock, flags); |
| 992 | |
| 993 | outl(1 << 12, card->io_port + CSR9); /* enable boot rom access */ |
| 994 | for (i = 0x100; i < 0x1f7; i += link + 2) { |
| 995 | outl(i, card->io_port + CSR10); |
| 996 | tuple = inl(card->io_port + CSR9) & 0xff; |
| 997 | outl(i + 1, card->io_port + CSR10); |
| 998 | link = inl(card->io_port + CSR9) & 0xff; |
| 999 | outl(i + 2, card->io_port + CSR10); |
| 1000 | data_id = inl(card->io_port + CSR9) & 0xff; |
| 1001 | outl(i + 3, card->io_port + CSR10); |
| 1002 | data_count = inl(card->io_port + CSR9) & 0xff; |
| 1003 | if ((tuple == 0x22) && (data_id == 0x04) && (data_count == 0x06)) { |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1004 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | * This is it. We have the data we want. |
| 1006 | */ |
| 1007 | for (j = 0; j < 6; j++) { |
| 1008 | outl(i + j + 4, card->io_port + CSR10); |
| 1009 | card->dev->dev_addr[j] = inl(card->io_port + CSR9) & 0xff; |
| 1010 | } |
| 1011 | break; |
| 1012 | } else if (link == 0) { |
| 1013 | break; |
| 1014 | } |
| 1015 | } |
| 1016 | spin_unlock_irqrestore(&card->lock, flags); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1017 | pr_debug(" %pM\n", card->dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | /* |
| 1022 | transceiver_voodoo() enables the external UTP plug thingy. |
| 1023 | it's called voodoo as I stole this code and cannot cross-reference |
| 1024 | it with the specification. |
| 1025 | */ |
| 1026 | static void transceiver_voodoo(struct xircom_private *card) |
| 1027 | { |
| 1028 | unsigned long flags; |
| 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | /* disable all powermanagement */ |
| 1031 | pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000); |
| 1032 | |
| 1033 | setup_descriptors(card); |
| 1034 | |
| 1035 | spin_lock_irqsave(&card->lock, flags); |
| 1036 | |
| 1037 | outl(0x0008, card->io_port + CSR15); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1038 | udelay(25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | outl(0xa8050000, card->io_port + CSR15); |
| 1040 | udelay(25); |
| 1041 | outl(0xa00f0000, card->io_port + CSR15); |
| 1042 | udelay(25); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | spin_unlock_irqrestore(&card->lock, flags); |
| 1045 | |
| 1046 | netif_start_queue(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | static void xircom_up(struct xircom_private *card) |
| 1051 | { |
| 1052 | unsigned long flags; |
| 1053 | int i; |
| 1054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | /* disable all powermanagement */ |
| 1056 | pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000); |
| 1057 | |
| 1058 | setup_descriptors(card); |
| 1059 | |
| 1060 | spin_lock_irqsave(&card->lock, flags); |
| 1061 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | enable_link_interrupt(card); |
| 1064 | enable_transmit_interrupt(card); |
| 1065 | enable_receive_interrupt(card); |
| 1066 | enable_common_interrupts(card); |
| 1067 | enable_promisc(card); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | /* The card can have received packets already, read them away now */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1070 | for (i=0;i<NUMDESCRIPTORS;i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | investigate_read_descriptor(card->dev,card,i,bufferoffsets[i]); |
| 1072 | |
| 1073 | |
| 1074 | spin_unlock_irqrestore(&card->lock, flags); |
| 1075 | trigger_receive(card); |
| 1076 | trigger_transmit(card); |
| 1077 | netif_start_queue(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | /* Bufferoffset is in BYTES */ |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1081 | static void |
| 1082 | investigate_read_descriptor(struct net_device *dev, struct xircom_private *card, |
| 1083 | int descnr, unsigned int bufferoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | { |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1085 | int status; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1086 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1087 | status = le32_to_cpu(card->rx_buffer[4*descnr]); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1088 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1089 | if (status > 0) { /* packet received */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1090 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1091 | /* TODO: discard error packets */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1092 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1093 | short pkt_len = ((status >> 16) & 0x7ff) - 4; |
| 1094 | /* minus 4, we don't want the CRC */ |
| 1095 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1097 | if (pkt_len > 1518) { |
| 1098 | netdev_err(dev, "Packet length %i is bogus\n", pkt_len); |
| 1099 | pkt_len = 1518; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | } |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1101 | |
Pradeep A Dalvi | 21a4e46 | 2012-02-05 02:50:10 +0000 | [diff] [blame] | 1102 | skb = netdev_alloc_skb(dev, pkt_len + 2); |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1103 | if (skb == NULL) { |
| 1104 | dev->stats.rx_dropped++; |
| 1105 | goto out; |
| 1106 | } |
| 1107 | skb_reserve(skb, 2); |
| 1108 | skb_copy_to_linear_data(skb, |
| 1109 | &card->rx_buffer[bufferoffset / 4], |
| 1110 | pkt_len); |
| 1111 | skb_put(skb, pkt_len); |
| 1112 | skb->protocol = eth_type_trans(skb, dev); |
| 1113 | netif_rx(skb); |
| 1114 | dev->stats.rx_packets++; |
| 1115 | dev->stats.rx_bytes += pkt_len; |
| 1116 | |
| 1117 | out: |
| 1118 | /* give the buffer back to the card */ |
| 1119 | card->rx_buffer[4*descnr] = cpu_to_le32(0x80000000); |
| 1120 | trigger_receive(card); |
| 1121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | |
| 1125 | /* Bufferoffset is in BYTES */ |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1126 | static void |
| 1127 | investigate_write_descriptor(struct net_device *dev, |
| 1128 | struct xircom_private *card, |
| 1129 | int descnr, unsigned int bufferoffset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | { |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1131 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1133 | status = le32_to_cpu(card->tx_buffer[4*descnr]); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1134 | #if 0 |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1135 | if (status & 0x8000) { /* Major error */ |
| 1136 | pr_err("Major transmit error status %x\n", status); |
| 1137 | card->tx_buffer[4*descnr] = 0; |
| 1138 | netif_wake_queue (dev); |
| 1139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | #endif |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1141 | if (status > 0) { /* bit 31 is 0 when done */ |
| 1142 | if (card->tx_skb[descnr]!=NULL) { |
| 1143 | dev->stats.tx_bytes += card->tx_skb[descnr]->len; |
| 1144 | dev_kfree_skb_irq(card->tx_skb[descnr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
Joe Perches | 163ef0b | 2011-05-09 09:45:21 +0000 | [diff] [blame] | 1146 | card->tx_skb[descnr] = NULL; |
| 1147 | /* Bit 8 in the status field is 1 if there was a collision */ |
| 1148 | if (status & (1 << 8)) |
| 1149 | dev->stats.collisions++; |
| 1150 | card->tx_buffer[4*descnr] = 0; /* descriptor is free again */ |
| 1151 | netif_wake_queue (dev); |
| 1152 | dev->stats.tx_packets++; |
| 1153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | static int __init xircom_init(void) |
| 1157 | { |
Alexey Dobriyan | ec42cdb | 2006-08-14 23:00:28 -0700 | [diff] [blame] | 1158 | return pci_register_driver(&xircom_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | static void __exit xircom_exit(void) |
| 1162 | { |
| 1163 | pci_unregister_driver(&xircom_ops); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1166 | module_init(xircom_init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | module_exit(xircom_exit) |
| 1168 | |