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