Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * 3c359.c (c) 2000 Mike Phillips (mikep@linuxtr.net) All Rights Reserved |
| 3 | * |
| 4 | * Linux driver for 3Com 3c359 Tokenlink Velocity XL PCI NIC |
| 5 | * |
| 6 | * Base Driver Olympic: |
| 7 | * Written 1999 Peter De Schrijver & Mike Phillips |
| 8 | * |
| 9 | * This software may be used and distributed according to the terms |
| 10 | * of the GNU General Public License, incorporated herein by reference. |
| 11 | * |
| 12 | * 7/17/00 - Clean up, version number 0.9.0. Ready to release to the world. |
| 13 | * |
| 14 | * 2/16/01 - Port up to kernel 2.4.2 ready for submission into the kernel. |
| 15 | * 3/05/01 - Last clean up stuff before submission. |
| 16 | * 2/15/01 - Finally, update to new pci api. |
| 17 | * |
| 18 | * To Do: |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Technical Card Details |
| 23 | * |
| 24 | * All access to data is done with 16/8 bit transfers. The transfer |
| 25 | * method really sucks. You can only read or write one location at a time. |
| 26 | * |
| 27 | * Also, the microcode for the card must be uploaded if the card does not have |
| 28 | * the flashrom on board. This is a 28K bloat in the driver when compiled |
| 29 | * as a module. |
| 30 | * |
| 31 | * Rx is very simple, status into a ring of descriptors, dma data transfer, |
| 32 | * interrupts to tell us when a packet is received. |
| 33 | * |
| 34 | * Tx is a little more interesting. Similar scenario, descriptor and dma data |
| 35 | * transfers, but we don't have to interrupt the card to tell it another packet |
| 36 | * is ready for transmission, we are just doing simple memory writes, not io or mmio |
| 37 | * writes. The card can be set up to simply poll on the next |
| 38 | * descriptor pointer and when this value is non-zero will automatically download |
| 39 | * the next packet. The card then interrupts us when the packet is done. |
| 40 | * |
| 41 | */ |
| 42 | |
| 43 | #define XL_DEBUG 0 |
| 44 | |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 45 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/module.h> |
| 47 | #include <linux/kernel.h> |
| 48 | #include <linux/errno.h> |
| 49 | #include <linux/timer.h> |
| 50 | #include <linux/in.h> |
| 51 | #include <linux/ioport.h> |
| 52 | #include <linux/string.h> |
| 53 | #include <linux/proc_fs.h> |
| 54 | #include <linux/ptrace.h> |
| 55 | #include <linux/skbuff.h> |
| 56 | #include <linux/interrupt.h> |
| 57 | #include <linux/delay.h> |
| 58 | #include <linux/netdevice.h> |
| 59 | #include <linux/trdevice.h> |
| 60 | #include <linux/stddef.h> |
| 61 | #include <linux/init.h> |
| 62 | #include <linux/pci.h> |
| 63 | #include <linux/spinlock.h> |
| 64 | #include <linux/bitops.h> |
| 65 | |
| 66 | #include <net/checksum.h> |
| 67 | |
| 68 | #include <asm/io.h> |
| 69 | #include <asm/system.h> |
| 70 | |
| 71 | #include "3c359.h" |
| 72 | |
| 73 | static char version[] __devinitdata = |
| 74 | "3c359.c v1.2.0 2/17/01 - Mike Phillips (mikep@linuxtr.net)" ; |
| 75 | |
| 76 | MODULE_AUTHOR("Mike Phillips <mikep@linuxtr.net>") ; |
| 77 | MODULE_DESCRIPTION("3Com 3C359 Velocity XL Token Ring Adapter Driver \n") ; |
| 78 | |
| 79 | /* Module paramters */ |
| 80 | |
| 81 | /* Ring Speed 0,4,16 |
| 82 | * 0 = Autosense |
| 83 | * 4,16 = Selected speed only, no autosense |
| 84 | * This allows the card to be the first on the ring |
| 85 | * and become the active monitor. |
| 86 | * |
| 87 | * WARNING: Some hubs will allow you to insert |
| 88 | * at the wrong speed. |
| 89 | * |
| 90 | * The adapter will _not_ fail to open if there are no |
| 91 | * active monitors on the ring, it will simply open up in |
| 92 | * its last known ringspeed if no ringspeed is specified. |
| 93 | */ |
| 94 | |
| 95 | static int ringspeed[XL_MAX_ADAPTERS] = {0,} ; |
| 96 | |
| 97 | module_param_array(ringspeed, int, NULL, 0); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 98 | MODULE_PARM_DESC(ringspeed,"3c359: Ringspeed selection - 4,16 or 0") ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* Packet buffer size */ |
| 101 | |
| 102 | static int pkt_buf_sz[XL_MAX_ADAPTERS] = {0,} ; |
| 103 | |
| 104 | module_param_array(pkt_buf_sz, int, NULL, 0) ; |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 105 | MODULE_PARM_DESC(pkt_buf_sz,"3c359: Initial buffer size") ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* Message Level */ |
| 107 | |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 108 | static int message_level[XL_MAX_ADAPTERS] = {0,} ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | module_param_array(message_level, int, NULL, 0) ; |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 111 | MODULE_PARM_DESC(message_level, "3c359: Level of reported messages") ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* |
| 113 | * This is a real nasty way of doing this, but otherwise you |
| 114 | * will be stuck with 1555 lines of hex #'s in the code. |
| 115 | */ |
| 116 | |
| 117 | #include "3c359_microcode.h" |
| 118 | |
| 119 | static struct pci_device_id xl_pci_tbl[] = |
| 120 | { |
| 121 | {PCI_VENDOR_ID_3COM,PCI_DEVICE_ID_3COM_3C359, PCI_ANY_ID, PCI_ANY_ID, }, |
| 122 | { } /* terminate list */ |
| 123 | }; |
| 124 | MODULE_DEVICE_TABLE(pci,xl_pci_tbl) ; |
| 125 | |
| 126 | static int xl_init(struct net_device *dev); |
| 127 | static int xl_open(struct net_device *dev); |
| 128 | static int xl_open_hw(struct net_device *dev) ; |
| 129 | static int xl_hw_reset(struct net_device *dev); |
| 130 | static int xl_xmit(struct sk_buff *skb, struct net_device *dev); |
| 131 | static void xl_dn_comp(struct net_device *dev); |
| 132 | static int xl_close(struct net_device *dev); |
| 133 | static void xl_set_rx_mode(struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 134 | static irqreturn_t xl_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | static int xl_set_mac_address(struct net_device *dev, void *addr) ; |
| 136 | static void xl_arb_cmd(struct net_device *dev); |
| 137 | static void xl_asb_cmd(struct net_device *dev) ; |
| 138 | static void xl_srb_cmd(struct net_device *dev, int srb_cmd) ; |
| 139 | static void xl_wait_misr_flags(struct net_device *dev) ; |
| 140 | static int xl_change_mtu(struct net_device *dev, int mtu); |
| 141 | static void xl_srb_bh(struct net_device *dev) ; |
| 142 | static void xl_asb_bh(struct net_device *dev) ; |
| 143 | static void xl_reset(struct net_device *dev) ; |
| 144 | static void xl_freemem(struct net_device *dev) ; |
| 145 | |
| 146 | |
| 147 | /* EEProm Access Functions */ |
| 148 | static u16 xl_ee_read(struct net_device *dev, int ee_addr) ; |
| 149 | static void xl_ee_write(struct net_device *dev, int ee_addr, u16 ee_value) ; |
| 150 | |
| 151 | /* Debugging functions */ |
| 152 | #if XL_DEBUG |
| 153 | static void print_tx_state(struct net_device *dev) ; |
| 154 | static void print_rx_state(struct net_device *dev) ; |
| 155 | |
| 156 | static void print_tx_state(struct net_device *dev) |
| 157 | { |
| 158 | |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 159 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | struct xl_tx_desc *txd ; |
| 161 | u8 __iomem *xl_mmio = xl_priv->xl_mmio ; |
| 162 | int i ; |
| 163 | |
| 164 | printk("tx_ring_head: %d, tx_ring_tail: %d, free_ent: %d \n",xl_priv->tx_ring_head, |
| 165 | xl_priv->tx_ring_tail, xl_priv->free_ring_entries) ; |
| 166 | printk("Ring , Address , FSH , DnNextPtr, Buffer, Buffer_Len \n"); |
| 167 | for (i = 0; i < 16; i++) { |
| 168 | txd = &(xl_priv->xl_tx_ring[i]) ; |
| 169 | printk("%d, %08lx, %08x, %08x, %08x, %08x \n", i, virt_to_bus(txd), |
| 170 | txd->framestartheader, txd->dnnextptr, txd->buffer, txd->buffer_length ) ; |
| 171 | } |
| 172 | |
| 173 | printk("DNLISTPTR = %04x \n", readl(xl_mmio + MMIO_DNLISTPTR) ); |
| 174 | |
| 175 | printk("DmaCtl = %04x \n", readl(xl_mmio + MMIO_DMA_CTRL) ); |
| 176 | printk("Queue status = %0x \n",netif_running(dev) ) ; |
| 177 | } |
| 178 | |
| 179 | static void print_rx_state(struct net_device *dev) |
| 180 | { |
| 181 | |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 182 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | struct xl_rx_desc *rxd ; |
| 184 | u8 __iomem *xl_mmio = xl_priv->xl_mmio ; |
| 185 | int i ; |
| 186 | |
| 187 | printk("rx_ring_tail: %d \n", xl_priv->rx_ring_tail) ; |
| 188 | printk("Ring , Address , FrameState , UPNextPtr, FragAddr, Frag_Len \n"); |
| 189 | for (i = 0; i < 16; i++) { |
| 190 | /* rxd = (struct xl_rx_desc *)xl_priv->rx_ring_dma_addr + (i * sizeof(struct xl_rx_desc)) ; */ |
| 191 | rxd = &(xl_priv->xl_rx_ring[i]) ; |
| 192 | printk("%d, %08lx, %08x, %08x, %08x, %08x \n", i, virt_to_bus(rxd), |
| 193 | rxd->framestatus, rxd->upnextptr, rxd->upfragaddr, rxd->upfraglen ) ; |
| 194 | } |
| 195 | |
| 196 | printk("UPLISTPTR = %04x \n", readl(xl_mmio + MMIO_UPLISTPTR) ); |
| 197 | |
| 198 | printk("DmaCtl = %04x \n", readl(xl_mmio + MMIO_DMA_CTRL) ); |
| 199 | printk("Queue status = %0x \n",netif_running(dev) ) ; |
| 200 | } |
| 201 | #endif |
| 202 | |
| 203 | /* |
| 204 | * Read values from the on-board EEProm. This looks very strange |
| 205 | * but you have to wait for the EEProm to get/set the value before |
| 206 | * passing/getting the next value from the nic. As with all requests |
| 207 | * on this nic it has to be done in two stages, a) tell the nic which |
| 208 | * memory address you want to access and b) pass/get the value from the nic. |
| 209 | * With the EEProm, you have to wait before and inbetween access a) and b). |
| 210 | * As this is only read at initialization time and the wait period is very |
| 211 | * small we shouldn't have to worry about scheduling issues. |
| 212 | */ |
| 213 | |
| 214 | static u16 xl_ee_read(struct net_device *dev, int ee_addr) |
| 215 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 216 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | u8 __iomem *xl_mmio = xl_priv->xl_mmio ; |
| 218 | |
| 219 | /* Wait for EEProm to not be busy */ |
| 220 | writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 221 | while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ; |
| 222 | |
| 223 | /* Tell EEProm what we want to do and where */ |
| 224 | writel(IO_WORD_WRITE | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 225 | writew(EEREAD + ee_addr, xl_mmio + MMIO_MACDATA) ; |
| 226 | |
| 227 | /* Wait for EEProm to not be busy */ |
| 228 | writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 229 | while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ; |
| 230 | |
| 231 | /* Tell EEProm what we want to do and where */ |
| 232 | writel(IO_WORD_WRITE | EECONTROL , xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 233 | writew(EEREAD + ee_addr, xl_mmio + MMIO_MACDATA) ; |
| 234 | |
| 235 | /* Finally read the value from the EEProm */ |
| 236 | writel(IO_WORD_READ | EEDATA , xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 237 | return readw(xl_mmio + MMIO_MACDATA) ; |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * Write values to the onboard eeprom. As with eeprom read you need to |
| 242 | * set which location to write, wait, value to write, wait, with the |
| 243 | * added twist of having to enable eeprom writes as well. |
| 244 | */ |
| 245 | |
| 246 | static void xl_ee_write(struct net_device *dev, int ee_addr, u16 ee_value) |
| 247 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 248 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | u8 __iomem *xl_mmio = xl_priv->xl_mmio ; |
| 250 | |
| 251 | /* Wait for EEProm to not be busy */ |
| 252 | writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 253 | while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ; |
| 254 | |
| 255 | /* Enable write/erase */ |
| 256 | writel(IO_WORD_WRITE | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 257 | writew(EE_ENABLE_WRITE, xl_mmio + MMIO_MACDATA) ; |
| 258 | |
| 259 | /* Wait for EEProm to not be busy */ |
| 260 | writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 261 | while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ; |
| 262 | |
| 263 | /* Put the value we want to write into EEDATA */ |
| 264 | writel(IO_WORD_WRITE | EEDATA, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 265 | writew(ee_value, xl_mmio + MMIO_MACDATA) ; |
| 266 | |
| 267 | /* Tell EEProm to write eevalue into ee_addr */ |
| 268 | writel(IO_WORD_WRITE | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 269 | writew(EEWRITE + ee_addr, xl_mmio + MMIO_MACDATA) ; |
| 270 | |
| 271 | /* Wait for EEProm to not be busy, to ensure write gets done */ |
| 272 | writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 273 | while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ; |
| 274 | |
| 275 | return ; |
| 276 | } |
| 277 | |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 278 | static int __devinit xl_probe(struct pci_dev *pdev, |
| 279 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
| 281 | struct net_device *dev ; |
| 282 | struct xl_private *xl_priv ; |
| 283 | static int card_no = -1 ; |
| 284 | int i ; |
| 285 | |
| 286 | card_no++ ; |
| 287 | |
| 288 | if (pci_enable_device(pdev)) { |
| 289 | return -ENODEV ; |
| 290 | } |
| 291 | |
| 292 | pci_set_master(pdev); |
| 293 | |
| 294 | if ((i = pci_request_regions(pdev,"3c359"))) { |
| 295 | return i ; |
| 296 | } ; |
| 297 | |
| 298 | /* |
| 299 | * Allowing init_trdev to allocate the dev->priv structure will align xl_private |
| 300 | * on a 32 bytes boundary which we need for the rx/tx descriptors |
| 301 | */ |
| 302 | |
| 303 | dev = alloc_trdev(sizeof(struct xl_private)) ; |
| 304 | if (!dev) { |
| 305 | pci_release_regions(pdev) ; |
| 306 | return -ENOMEM ; |
| 307 | } |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 308 | xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | #if XL_DEBUG |
| 311 | printk("pci_device: %p, dev:%p, dev->priv: %p, ba[0]: %10x, ba[1]:%10x\n", |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 312 | pdev, dev, netdev_priv(dev), (unsigned int)pdev->resource[0].start, (unsigned int)pdev->resource[1].start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | #endif |
| 314 | |
| 315 | dev->irq=pdev->irq; |
| 316 | dev->base_addr=pci_resource_start(pdev,0) ; |
| 317 | xl_priv->xl_card_name = pci_name(pdev); |
| 318 | xl_priv->xl_mmio=ioremap(pci_resource_start(pdev,1), XL_IO_SPACE); |
| 319 | xl_priv->pdev = pdev ; |
| 320 | |
| 321 | if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000) ) |
| 322 | xl_priv->pkt_buf_sz = PKT_BUF_SZ ; |
| 323 | else |
| 324 | xl_priv->pkt_buf_sz = pkt_buf_sz[card_no] ; |
| 325 | |
| 326 | dev->mtu = xl_priv->pkt_buf_sz - TR_HLEN ; |
| 327 | xl_priv->xl_ring_speed = ringspeed[card_no] ; |
| 328 | xl_priv->xl_message_level = message_level[card_no] ; |
| 329 | xl_priv->xl_functional_addr[0] = xl_priv->xl_functional_addr[1] = xl_priv->xl_functional_addr[2] = xl_priv->xl_functional_addr[3] = 0 ; |
| 330 | xl_priv->xl_copy_all_options = 0 ; |
| 331 | |
| 332 | if((i = xl_init(dev))) { |
| 333 | iounmap(xl_priv->xl_mmio) ; |
| 334 | free_netdev(dev) ; |
| 335 | pci_release_regions(pdev) ; |
| 336 | return i ; |
| 337 | } |
| 338 | |
| 339 | dev->open=&xl_open; |
| 340 | dev->hard_start_xmit=&xl_xmit; |
| 341 | dev->change_mtu=&xl_change_mtu; |
| 342 | dev->stop=&xl_close; |
| 343 | dev->do_ioctl=NULL; |
| 344 | dev->set_multicast_list=&xl_set_rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | dev->set_mac_address=&xl_set_mac_address ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 347 | |
| 348 | pci_set_drvdata(pdev,dev) ; |
| 349 | if ((i = register_netdev(dev))) { |
| 350 | printk(KERN_ERR "3C359, register netdev failed\n") ; |
| 351 | pci_set_drvdata(pdev,NULL) ; |
| 352 | iounmap(xl_priv->xl_mmio) ; |
| 353 | free_netdev(dev) ; |
| 354 | pci_release_regions(pdev) ; |
| 355 | return i ; |
| 356 | } |
| 357 | |
| 358 | printk(KERN_INFO "3C359: %s registered as: %s\n",xl_priv->xl_card_name,dev->name) ; |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | |
Adrian Bunk | 9b5587c | 2007-07-10 14:44:37 +0200 | [diff] [blame] | 364 | static int __devinit xl_init(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 366 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | printk(KERN_INFO "%s \n", version); |
| 369 | printk(KERN_INFO "%s: I/O at %hx, MMIO at %p, using irq %d\n", |
| 370 | xl_priv->xl_card_name, (unsigned int)dev->base_addr ,xl_priv->xl_mmio, dev->irq); |
| 371 | |
| 372 | spin_lock_init(&xl_priv->xl_lock) ; |
| 373 | |
| 374 | return xl_hw_reset(dev) ; |
| 375 | |
| 376 | } |
| 377 | |
| 378 | |
| 379 | /* |
| 380 | * Hardware reset. This needs to be a separate entity as we need to reset the card |
| 381 | * when we change the EEProm settings. |
| 382 | */ |
| 383 | |
| 384 | static int xl_hw_reset(struct net_device *dev) |
| 385 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 386 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | u8 __iomem *xl_mmio = xl_priv->xl_mmio ; |
| 388 | unsigned long t ; |
| 389 | u16 i ; |
| 390 | u16 result_16 ; |
| 391 | u8 result_8 ; |
| 392 | u16 start ; |
| 393 | int j ; |
| 394 | |
| 395 | /* |
| 396 | * Reset the card. If the card has got the microcode on board, we have |
| 397 | * missed the initialization interrupt, so we must always do this. |
| 398 | */ |
| 399 | |
| 400 | writew( GLOBAL_RESET, xl_mmio + MMIO_COMMAND ) ; |
| 401 | |
| 402 | /* |
| 403 | * Must wait for cmdInProgress bit (12) to clear before continuing with |
| 404 | * card configuration. |
| 405 | */ |
| 406 | |
| 407 | t=jiffies; |
| 408 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { |
| 409 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 410 | if (time_after(jiffies, t + 40 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | printk(KERN_ERR "%s: 3COM 3C359 Velocity XL card not responding to global reset.\n", dev->name); |
| 412 | return -ENODEV; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | * Enable pmbar by setting bit in CPAttention |
| 418 | */ |
| 419 | |
| 420 | writel( (IO_BYTE_READ | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 421 | result_8 = readb(xl_mmio + MMIO_MACDATA) ; |
| 422 | result_8 = result_8 | CPA_PMBARVIS ; |
| 423 | writel( (IO_BYTE_WRITE | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 424 | writeb(result_8, xl_mmio + MMIO_MACDATA) ; |
| 425 | |
| 426 | /* |
| 427 | * Read cpHold bit in pmbar, if cleared we have got Flashrom on board. |
| 428 | * If not, we need to upload the microcode to the card |
| 429 | */ |
| 430 | |
| 431 | writel( (IO_WORD_READ | PMBAR),xl_mmio + MMIO_MAC_ACCESS_CMD); |
| 432 | |
| 433 | #if XL_DEBUG |
| 434 | printk(KERN_INFO "Read from PMBAR = %04x \n", readw(xl_mmio + MMIO_MACDATA)) ; |
| 435 | #endif |
| 436 | |
| 437 | if ( readw( (xl_mmio + MMIO_MACDATA)) & PMB_CPHOLD ) { |
| 438 | |
| 439 | /* Set PmBar, privateMemoryBase bits (8:2) to 0 */ |
| 440 | |
| 441 | writel( (IO_WORD_READ | PMBAR),xl_mmio + MMIO_MAC_ACCESS_CMD); |
| 442 | result_16 = readw(xl_mmio + MMIO_MACDATA) ; |
| 443 | result_16 = result_16 & ~((0x7F) << 2) ; |
| 444 | writel( (IO_WORD_WRITE | PMBAR), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 445 | writew(result_16,xl_mmio + MMIO_MACDATA) ; |
| 446 | |
| 447 | /* Set CPAttention, memWrEn bit */ |
| 448 | |
| 449 | writel( (IO_BYTE_READ | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 450 | result_8 = readb(xl_mmio + MMIO_MACDATA) ; |
| 451 | result_8 = result_8 | CPA_MEMWREN ; |
| 452 | writel( (IO_BYTE_WRITE | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 453 | writeb(result_8, xl_mmio + MMIO_MACDATA) ; |
| 454 | |
| 455 | /* |
| 456 | * Now to write the microcode into the shared ram |
| 457 | * The microcode must finish at position 0xFFFF, so we must subtract |
| 458 | * to get the start position for the code |
| 459 | */ |
| 460 | |
| 461 | start = (0xFFFF - (mc_size) + 1 ) ; /* Looks strange but ensures compiler only uses 16 bit unsigned int for this */ |
| 462 | |
| 463 | printk(KERN_INFO "3C359: Uploading Microcode: "); |
| 464 | |
| 465 | for (i = start, j = 0; j < mc_size; i++, j++) { |
| 466 | writel(MEM_BYTE_WRITE | 0XD0000 | i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 467 | writeb(microcode[j],xl_mmio + MMIO_MACDATA) ; |
| 468 | if (j % 1024 == 0) |
| 469 | printk("."); |
| 470 | } |
| 471 | printk("\n") ; |
| 472 | |
| 473 | for (i=0;i < 16; i++) { |
| 474 | writel( (MEM_BYTE_WRITE | 0xDFFF0) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 475 | writeb(microcode[mc_size - 16 + i], xl_mmio + MMIO_MACDATA) ; |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * Have to write the start address of the upload to FFF4, but |
| 480 | * the address must be >> 4. You do not want to know how long |
| 481 | * it took me to discover this. |
| 482 | */ |
| 483 | |
| 484 | writel(MEM_WORD_WRITE | 0xDFFF4, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 485 | writew(start >> 4, xl_mmio + MMIO_MACDATA); |
| 486 | |
| 487 | /* Clear the CPAttention, memWrEn Bit */ |
| 488 | |
| 489 | writel( (IO_BYTE_READ | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 490 | result_8 = readb(xl_mmio + MMIO_MACDATA) ; |
| 491 | result_8 = result_8 & ~CPA_MEMWREN ; |
| 492 | writel( (IO_BYTE_WRITE | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 493 | writeb(result_8, xl_mmio + MMIO_MACDATA) ; |
| 494 | |
| 495 | /* Clear the cpHold bit in pmbar */ |
| 496 | |
| 497 | writel( (IO_WORD_READ | PMBAR),xl_mmio + MMIO_MAC_ACCESS_CMD); |
| 498 | result_16 = readw(xl_mmio + MMIO_MACDATA) ; |
| 499 | result_16 = result_16 & ~PMB_CPHOLD ; |
| 500 | writel( (IO_WORD_WRITE | PMBAR), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 501 | writew(result_16,xl_mmio + MMIO_MACDATA) ; |
| 502 | |
| 503 | |
| 504 | } /* If microcode upload required */ |
| 505 | |
| 506 | /* |
| 507 | * The card should now go though a self test procedure and get itself ready |
| 508 | * to be opened, we must wait for an srb response with the initialization |
| 509 | * information. |
| 510 | */ |
| 511 | |
| 512 | #if XL_DEBUG |
| 513 | printk(KERN_INFO "%s: Microcode uploaded, must wait for the self test to complete\n", dev->name); |
| 514 | #endif |
| 515 | |
| 516 | writew(SETINDENABLE | 0xFFF, xl_mmio + MMIO_COMMAND) ; |
| 517 | |
| 518 | t=jiffies; |
| 519 | while ( !(readw(xl_mmio + MMIO_INTSTATUS_AUTO) & INTSTAT_SRB) ) { |
| 520 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 521 | if (time_after(jiffies, t + 15 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | printk(KERN_ERR "3COM 3C359 Velocity XL card not responding.\n"); |
| 523 | return -ENODEV; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | * Write the RxBufArea with D000, RxEarlyThresh, TxStartThresh, |
| 529 | * DnPriReqThresh, read the tech docs if you want to know what |
| 530 | * values they need to be. |
| 531 | */ |
| 532 | |
| 533 | writel(MMIO_WORD_WRITE | RXBUFAREA, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 534 | writew(0xD000, xl_mmio + MMIO_MACDATA) ; |
| 535 | |
| 536 | writel(MMIO_WORD_WRITE | RXEARLYTHRESH, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 537 | writew(0X0020, xl_mmio + MMIO_MACDATA) ; |
| 538 | |
| 539 | writew( SETTXSTARTTHRESH | 0x40 , xl_mmio + MMIO_COMMAND) ; |
| 540 | |
| 541 | writeb(0x04, xl_mmio + MMIO_DNBURSTTHRESH) ; |
| 542 | writeb(0x04, xl_mmio + DNPRIREQTHRESH) ; |
| 543 | |
| 544 | /* |
| 545 | * Read WRBR to provide the location of the srb block, have to use byte reads not word reads. |
| 546 | * Tech docs have this wrong !!!! |
| 547 | */ |
| 548 | |
| 549 | writel(MMIO_BYTE_READ | WRBR, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 550 | xl_priv->srb = readb(xl_mmio + MMIO_MACDATA) << 8 ; |
| 551 | writel( (MMIO_BYTE_READ | WRBR) + 1, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 552 | xl_priv->srb = xl_priv->srb | readb(xl_mmio + MMIO_MACDATA) ; |
| 553 | |
| 554 | #if XL_DEBUG |
| 555 | writel(IO_WORD_READ | SWITCHSETTINGS, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 556 | if ( readw(xl_mmio + MMIO_MACDATA) & 2) { |
| 557 | printk(KERN_INFO "Default ring speed 4 mbps \n") ; |
| 558 | } else { |
| 559 | printk(KERN_INFO "Default ring speed 16 mbps \n") ; |
| 560 | } |
| 561 | printk(KERN_INFO "%s: xl_priv->srb = %04x\n",xl_priv->xl_card_name, xl_priv->srb); |
| 562 | #endif |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static int xl_open(struct net_device *dev) |
| 568 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 569 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | u8 __iomem *xl_mmio = xl_priv->xl_mmio ; |
| 571 | u8 i ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 572 | __le16 hwaddr[3] ; /* Should be u8[6] but we get word return values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | int open_err ; |
| 574 | |
| 575 | u16 switchsettings, switchsettings_eeprom ; |
| 576 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 577 | if(request_irq(dev->irq, &xl_interrupt, IRQF_SHARED , "3c359", dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return -EAGAIN; |
| 579 | } |
| 580 | |
| 581 | /* |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 582 | * Read the information from the EEPROM that we need. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | */ |
| 584 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 585 | hwaddr[0] = cpu_to_le16(xl_ee_read(dev,0x10)); |
| 586 | hwaddr[1] = cpu_to_le16(xl_ee_read(dev,0x11)); |
| 587 | hwaddr[2] = cpu_to_le16(xl_ee_read(dev,0x12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
| 589 | /* Ring speed */ |
| 590 | |
| 591 | switchsettings_eeprom = xl_ee_read(dev,0x08) ; |
| 592 | switchsettings = switchsettings_eeprom ; |
| 593 | |
| 594 | if (xl_priv->xl_ring_speed != 0) { |
| 595 | if (xl_priv->xl_ring_speed == 4) |
| 596 | switchsettings = switchsettings | 0x02 ; |
| 597 | else |
| 598 | switchsettings = switchsettings & ~0x02 ; |
| 599 | } |
| 600 | |
| 601 | /* Only write EEProm if there has been a change */ |
| 602 | if (switchsettings != switchsettings_eeprom) { |
| 603 | xl_ee_write(dev,0x08,switchsettings) ; |
| 604 | /* Hardware reset after changing EEProm */ |
| 605 | xl_hw_reset(dev) ; |
| 606 | } |
| 607 | |
| 608 | memcpy(dev->dev_addr,hwaddr,dev->addr_len) ; |
| 609 | |
| 610 | open_err = xl_open_hw(dev) ; |
| 611 | |
| 612 | /* |
| 613 | * This really needs to be cleaned up with better error reporting. |
| 614 | */ |
| 615 | |
| 616 | if (open_err != 0) { /* Something went wrong with the open command */ |
| 617 | if (open_err & 0x07) { /* Wrong speed, retry at different speed */ |
| 618 | printk(KERN_WARNING "%s: Open Error, retrying at different ringspeed \n", dev->name) ; |
| 619 | switchsettings = switchsettings ^ 2 ; |
| 620 | xl_ee_write(dev,0x08,switchsettings) ; |
| 621 | xl_hw_reset(dev) ; |
| 622 | open_err = xl_open_hw(dev) ; |
| 623 | if (open_err != 0) { |
| 624 | printk(KERN_WARNING "%s: Open error returned a second time, we're bombing out now\n", dev->name); |
| 625 | free_irq(dev->irq,dev) ; |
| 626 | return -ENODEV ; |
| 627 | } |
| 628 | } else { |
| 629 | printk(KERN_WARNING "%s: Open Error = %04x\n", dev->name, open_err) ; |
| 630 | free_irq(dev->irq,dev) ; |
| 631 | return -ENODEV ; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Now to set up the Rx and Tx buffer structures |
| 637 | */ |
| 638 | /* These MUST be on 8 byte boundaries */ |
Surya Prabhakar N | c821d55 | 2007-08-13 15:43:30 +0530 | [diff] [blame] | 639 | xl_priv->xl_tx_ring = kzalloc((sizeof(struct xl_tx_desc) * XL_TX_RING_SIZE) + 7, GFP_DMA | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | if (xl_priv->xl_tx_ring == NULL) { |
Jirka Pirko | 138a5cd | 2008-11-24 14:48:25 -0800 | [diff] [blame] | 641 | printk(KERN_WARNING "%s: Not enough memory to allocate tx buffers.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | dev->name); |
| 643 | free_irq(dev->irq,dev); |
| 644 | return -ENOMEM; |
| 645 | } |
Surya Prabhakar N | c821d55 | 2007-08-13 15:43:30 +0530 | [diff] [blame] | 646 | xl_priv->xl_rx_ring = kzalloc((sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE) +7, GFP_DMA | GFP_KERNEL); |
Jirka Pirko | d0cc10a | 2008-11-24 14:47:53 -0800 | [diff] [blame] | 647 | if (xl_priv->xl_rx_ring == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers.\n", |
| 649 | dev->name); |
| 650 | free_irq(dev->irq,dev); |
| 651 | kfree(xl_priv->xl_tx_ring); |
| 652 | return -ENOMEM; |
| 653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
| 655 | /* Setup Rx Ring */ |
| 656 | for (i=0 ; i < XL_RX_RING_SIZE ; i++) { |
| 657 | struct sk_buff *skb ; |
| 658 | |
| 659 | skb = dev_alloc_skb(xl_priv->pkt_buf_sz) ; |
| 660 | if (skb==NULL) |
| 661 | break ; |
| 662 | |
| 663 | skb->dev = dev ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 664 | xl_priv->xl_rx_ring[i].upfragaddr = cpu_to_le32(pci_map_single(xl_priv->pdev, skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE)); |
| 665 | xl_priv->xl_rx_ring[i].upfraglen = cpu_to_le32(xl_priv->pkt_buf_sz) | RXUPLASTFRAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | xl_priv->rx_ring_skb[i] = skb ; |
| 667 | } |
| 668 | |
| 669 | if (i==0) { |
| 670 | printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabled \n",dev->name) ; |
| 671 | free_irq(dev->irq,dev) ; |
Jirka Pirko | 5c94afd | 2008-11-24 14:49:11 -0800 | [diff] [blame^] | 672 | kfree(xl_priv->xl_tx_ring); |
| 673 | kfree(xl_priv->xl_rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | return -EIO ; |
| 675 | } |
| 676 | |
| 677 | xl_priv->rx_ring_no = i ; |
| 678 | xl_priv->rx_ring_tail = 0 ; |
| 679 | xl_priv->rx_ring_dma_addr = pci_map_single(xl_priv->pdev,xl_priv->xl_rx_ring, sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE, PCI_DMA_TODEVICE) ; |
| 680 | for (i=0;i<(xl_priv->rx_ring_no-1);i++) { |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 681 | xl_priv->xl_rx_ring[i].upnextptr = cpu_to_le32(xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * (i+1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | xl_priv->xl_rx_ring[i].upnextptr = 0 ; |
| 684 | |
| 685 | writel(xl_priv->rx_ring_dma_addr, xl_mmio + MMIO_UPLISTPTR) ; |
| 686 | |
| 687 | /* Setup Tx Ring */ |
| 688 | |
| 689 | xl_priv->tx_ring_dma_addr = pci_map_single(xl_priv->pdev,xl_priv->xl_tx_ring, sizeof(struct xl_tx_desc) * XL_TX_RING_SIZE,PCI_DMA_TODEVICE) ; |
| 690 | |
| 691 | xl_priv->tx_ring_head = 1 ; |
| 692 | xl_priv->tx_ring_tail = 255 ; /* Special marker for first packet */ |
| 693 | xl_priv->free_ring_entries = XL_TX_RING_SIZE ; |
| 694 | |
| 695 | /* |
| 696 | * Setup the first dummy DPD entry for polling to start working. |
| 697 | */ |
| 698 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 699 | xl_priv->xl_tx_ring[0].framestartheader = TXDPDEMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | xl_priv->xl_tx_ring[0].buffer = 0 ; |
| 701 | xl_priv->xl_tx_ring[0].buffer_length = 0 ; |
| 702 | xl_priv->xl_tx_ring[0].dnnextptr = 0 ; |
| 703 | |
| 704 | writel(xl_priv->tx_ring_dma_addr, xl_mmio + MMIO_DNLISTPTR) ; |
| 705 | writel(DNUNSTALL, xl_mmio + MMIO_COMMAND) ; |
| 706 | writel(UPUNSTALL, xl_mmio + MMIO_COMMAND) ; |
| 707 | writel(DNENABLE, xl_mmio + MMIO_COMMAND) ; |
| 708 | writeb(0x40, xl_mmio + MMIO_DNPOLL) ; |
| 709 | |
| 710 | /* |
| 711 | * Enable interrupts on the card |
| 712 | */ |
| 713 | |
| 714 | writel(SETINTENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ; |
| 715 | writel(SETINDENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ; |
| 716 | |
| 717 | netif_start_queue(dev) ; |
| 718 | return 0; |
| 719 | |
| 720 | } |
| 721 | |
| 722 | static int xl_open_hw(struct net_device *dev) |
| 723 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 724 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | u8 __iomem *xl_mmio = xl_priv->xl_mmio ; |
| 726 | u16 vsoff ; |
| 727 | char ver_str[33]; |
| 728 | int open_err ; |
| 729 | int i ; |
| 730 | unsigned long t ; |
| 731 | |
| 732 | /* |
| 733 | * Okay, let's build up the Open.NIC srb command |
| 734 | * |
| 735 | */ |
| 736 | |
| 737 | writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 738 | writeb(OPEN_NIC, xl_mmio + MMIO_MACDATA) ; |
| 739 | |
| 740 | /* |
| 741 | * Use this as a test byte, if it comes back with the same value, the command didn't work |
| 742 | */ |
| 743 | |
| 744 | writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb)+ 2, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 745 | writeb(0xff,xl_mmio + MMIO_MACDATA) ; |
| 746 | |
| 747 | /* Open options */ |
| 748 | writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + 8, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 749 | writeb(0x00, xl_mmio + MMIO_MACDATA) ; |
| 750 | writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + 9, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 751 | writeb(0x00, xl_mmio + MMIO_MACDATA) ; |
| 752 | |
| 753 | /* |
| 754 | * Node address, be careful here, the docs say you can just put zeros here and it will use |
| 755 | * the hardware address, it doesn't, you must include the node address in the open command. |
| 756 | */ |
| 757 | |
| 758 | if (xl_priv->xl_laa[0]) { /* If using a LAA address */ |
| 759 | for (i=10;i<16;i++) { |
| 760 | writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
Marcus Meissner | 9a7387c | 2007-10-13 10:19:37 +0200 | [diff] [blame] | 761 | writeb(xl_priv->xl_laa[i-10],xl_mmio + MMIO_MACDATA) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | memcpy(dev->dev_addr,xl_priv->xl_laa,dev->addr_len) ; |
| 764 | } else { /* Regular hardware address */ |
| 765 | for (i=10;i<16;i++) { |
| 766 | writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 767 | writeb(dev->dev_addr[i-10], xl_mmio + MMIO_MACDATA) ; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | /* Default everything else to 0 */ |
| 772 | for (i = 16; i < 34; i++) { |
| 773 | writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 774 | writeb(0x00,xl_mmio + MMIO_MACDATA) ; |
| 775 | } |
| 776 | |
| 777 | /* |
| 778 | * Set the csrb bit in the MISR register |
| 779 | */ |
| 780 | |
| 781 | xl_wait_misr_flags(dev) ; |
| 782 | writel(MEM_BYTE_WRITE | MF_CSRB, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 783 | writeb(0xFF, xl_mmio + MMIO_MACDATA) ; |
| 784 | writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 785 | writeb(MISR_CSRB , xl_mmio + MMIO_MACDATA) ; |
| 786 | |
| 787 | /* |
| 788 | * Now wait for the command to run |
| 789 | */ |
| 790 | |
| 791 | t=jiffies; |
| 792 | while (! (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_SRB)) { |
| 793 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 794 | if (time_after(jiffies, t + 40 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | printk(KERN_ERR "3COM 3C359 Velocity XL card not responding.\n"); |
| 796 | break ; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Let's interpret the open response |
| 802 | */ |
| 803 | |
| 804 | writel( (MEM_BYTE_READ | 0xD0000 | xl_priv->srb)+2, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 805 | if (readb(xl_mmio + MMIO_MACDATA)!=0) { |
| 806 | open_err = readb(xl_mmio + MMIO_MACDATA) << 8 ; |
| 807 | writel( (MEM_BYTE_READ | 0xD0000 | xl_priv->srb) + 7, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 808 | open_err |= readb(xl_mmio + MMIO_MACDATA) ; |
| 809 | return open_err ; |
| 810 | } else { |
| 811 | writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 8, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 812 | xl_priv->asb = swab16(readw(xl_mmio + MMIO_MACDATA)) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | printk(KERN_INFO "%s: Adapter Opened Details: ",dev->name) ; |
| 814 | printk("ASB: %04x",xl_priv->asb ) ; |
| 815 | writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 10, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 816 | printk(", SRB: %04x",swab16(readw(xl_mmio + MMIO_MACDATA)) ) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 12, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 819 | xl_priv->arb = swab16(readw(xl_mmio + MMIO_MACDATA)) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | printk(", ARB: %04x \n",xl_priv->arb ) ; |
| 821 | writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 14, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 822 | vsoff = swab16(readw(xl_mmio + MMIO_MACDATA)) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | /* |
| 825 | * Interesting, sending the individual characters directly to printk was causing klogd to use |
| 826 | * use 100% of processor time, so we build up the string and print that instead. |
| 827 | */ |
| 828 | |
| 829 | for (i=0;i<0x20;i++) { |
| 830 | writel( (MEM_BYTE_READ | 0xD0000 | vsoff) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 831 | ver_str[i] = readb(xl_mmio + MMIO_MACDATA) ; |
| 832 | } |
| 833 | ver_str[i] = '\0' ; |
| 834 | printk(KERN_INFO "%s: Microcode version String: %s \n",dev->name,ver_str); |
| 835 | } |
| 836 | |
| 837 | /* |
| 838 | * Issue the AckInterrupt |
| 839 | */ |
| 840 | writew(ACK_INTERRUPT | SRBRACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 841 | |
| 842 | return 0 ; |
| 843 | } |
| 844 | |
| 845 | /* |
| 846 | * There are two ways of implementing rx on the 359 NIC, either |
| 847 | * interrupt driven or polling. We are going to uses interrupts, |
| 848 | * it is the easier way of doing things. |
| 849 | * |
| 850 | * The Rx works with a ring of Rx descriptors. At initialise time the ring |
| 851 | * entries point to the next entry except for the last entry in the ring |
| 852 | * which points to 0. The card is programmed with the location of the first |
| 853 | * available descriptor and keeps reading the next_ptr until next_ptr is set |
| 854 | * to 0. Hopefully with a ring size of 16 the card will never get to read a next_ptr |
| 855 | * of 0. As the Rx interrupt is received we copy the frame up to the protocol layers |
| 856 | * and then point the end of the ring to our current position and point our current |
| 857 | * position to 0, therefore making the current position the last position on the ring. |
| 858 | * The last position on the ring therefore loops continually loops around the rx ring. |
| 859 | * |
| 860 | * rx_ring_tail is the position on the ring to process next. (Think of a snake, the head |
| 861 | * expands as the card adds new packets and we go around eating the tail processing the |
| 862 | * packets.) |
| 863 | * |
| 864 | * Undoubtably it could be streamlined and improved upon, but at the moment it works |
| 865 | * and the fast path through the routine is fine. |
| 866 | * |
| 867 | * adv_rx_ring could be inlined to increase performance, but its called a *lot* of times |
| 868 | * in xl_rx so would increase the size of the function significantly. |
| 869 | */ |
| 870 | |
| 871 | static void adv_rx_ring(struct net_device *dev) /* Advance rx_ring, cut down on bloat in xl_rx */ |
| 872 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 873 | struct xl_private *xl_priv=netdev_priv(dev); |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 874 | int n = xl_priv->rx_ring_tail; |
| 875 | int prev_ring_loc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 877 | prev_ring_loc = (n + XL_RX_RING_SIZE - 1) & (XL_RX_RING_SIZE - 1); |
| 878 | xl_priv->xl_rx_ring[prev_ring_loc].upnextptr = cpu_to_le32(xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * n)); |
| 879 | xl_priv->xl_rx_ring[n].framestatus = 0; |
| 880 | xl_priv->xl_rx_ring[n].upnextptr = 0; |
| 881 | xl_priv->rx_ring_tail++; |
| 882 | xl_priv->rx_ring_tail &= (XL_RX_RING_SIZE-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | static void xl_rx(struct net_device *dev) |
| 886 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 887 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 889 | struct sk_buff *skb, *skb2 ; |
| 890 | int frame_length = 0, copy_len = 0 ; |
| 891 | int temp_ring_loc ; |
| 892 | |
| 893 | /* |
| 894 | * Receive the next frame, loop around the ring until all frames |
| 895 | * have been received. |
| 896 | */ |
| 897 | |
| 898 | while (xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus & (RXUPDCOMPLETE | RXUPDFULL) ) { /* Descriptor to process */ |
| 899 | |
| 900 | if (xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus & RXUPDFULL ) { /* UpdFull, Multiple Descriptors used for the frame */ |
| 901 | |
| 902 | /* |
| 903 | * This is a pain, you need to go through all the descriptors until the last one |
| 904 | * for this frame to find the framelength |
| 905 | */ |
| 906 | |
| 907 | temp_ring_loc = xl_priv->rx_ring_tail ; |
| 908 | |
| 909 | while (xl_priv->xl_rx_ring[temp_ring_loc].framestatus & RXUPDFULL ) { |
| 910 | temp_ring_loc++ ; |
| 911 | temp_ring_loc &= (XL_RX_RING_SIZE-1) ; |
| 912 | } |
| 913 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 914 | frame_length = le32_to_cpu(xl_priv->xl_rx_ring[temp_ring_loc].framestatus) & 0x7FFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | skb = dev_alloc_skb(frame_length) ; |
| 917 | |
| 918 | if (skb==NULL) { /* No memory for frame, still need to roll forward the rx ring */ |
| 919 | printk(KERN_WARNING "%s: dev_alloc_skb failed - multi buffer !\n", dev->name) ; |
| 920 | while (xl_priv->rx_ring_tail != temp_ring_loc) |
| 921 | adv_rx_ring(dev) ; |
| 922 | |
| 923 | adv_rx_ring(dev) ; /* One more time just for luck :) */ |
Paulius Zaleckas | 94f9d29 | 2008-04-29 12:44:20 +0300 | [diff] [blame] | 924 | dev->stats.rx_dropped++ ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ; |
| 927 | return ; |
| 928 | } |
| 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | while (xl_priv->rx_ring_tail != temp_ring_loc) { |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 931 | copy_len = le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen) & 0x7FFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | frame_length -= copy_len ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 933 | pci_dma_sync_single_for_cpu(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 934 | skb_copy_from_linear_data(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail], |
| 935 | skb_put(skb, copy_len), |
| 936 | copy_len); |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 937 | pci_dma_sync_single_for_device(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | adv_rx_ring(dev) ; |
| 939 | } |
| 940 | |
| 941 | /* Now we have found the last fragment */ |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 942 | pci_dma_sync_single_for_cpu(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 943 | skb_copy_from_linear_data(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail], |
| 944 | skb_put(skb,copy_len), frame_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | /* memcpy(skb_put(skb,frame_length), bus_to_virt(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr), frame_length) ; */ |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 946 | pci_dma_sync_single_for_device(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | adv_rx_ring(dev) ; |
| 948 | skb->protocol = tr_type_trans(skb,dev) ; |
| 949 | netif_rx(skb) ; |
| 950 | |
| 951 | } else { /* Single Descriptor Used, simply swap buffers over, fast path */ |
| 952 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 953 | frame_length = le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus) & 0x7FFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | skb = dev_alloc_skb(xl_priv->pkt_buf_sz) ; |
| 956 | |
| 957 | if (skb==NULL) { /* Still need to fix the rx ring */ |
| 958 | printk(KERN_WARNING "%s: dev_alloc_skb failed in rx, single buffer \n",dev->name) ; |
| 959 | adv_rx_ring(dev) ; |
Paulius Zaleckas | 94f9d29 | 2008-04-29 12:44:20 +0300 | [diff] [blame] | 960 | dev->stats.rx_dropped++ ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ; |
| 962 | return ; |
| 963 | } |
| 964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | skb2 = xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 966 | pci_unmap_single(xl_priv->pdev, le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr), xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | skb_put(skb2, frame_length) ; |
| 968 | skb2->protocol = tr_type_trans(skb2,dev) ; |
| 969 | |
| 970 | xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] = skb ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 971 | xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr = cpu_to_le32(pci_map_single(xl_priv->pdev,skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE)); |
| 972 | xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen = cpu_to_le32(xl_priv->pkt_buf_sz) | RXUPLASTFRAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | adv_rx_ring(dev) ; |
Paulius Zaleckas | 94f9d29 | 2008-04-29 12:44:20 +0300 | [diff] [blame] | 974 | dev->stats.rx_packets++ ; |
| 975 | dev->stats.rx_bytes += frame_length ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
| 977 | netif_rx(skb2) ; |
| 978 | } /* if multiple buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } /* while packet to do */ |
| 980 | |
| 981 | /* Clear the updComplete interrupt */ |
| 982 | writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ; |
| 983 | return ; |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | * This is ruthless, it doesn't care what state the card is in it will |
| 988 | * completely reset the adapter. |
| 989 | */ |
| 990 | |
| 991 | static void xl_reset(struct net_device *dev) |
| 992 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 993 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 995 | unsigned long t; |
| 996 | |
| 997 | writew( GLOBAL_RESET, xl_mmio + MMIO_COMMAND ) ; |
| 998 | |
| 999 | /* |
| 1000 | * Must wait for cmdInProgress bit (12) to clear before continuing with |
| 1001 | * card configuration. |
| 1002 | */ |
| 1003 | |
| 1004 | t=jiffies; |
| 1005 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 1006 | if (time_after(jiffies, t + 40 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | printk(KERN_ERR "3COM 3C359 Velocity XL card not responding.\n"); |
| 1008 | break ; |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | } |
| 1013 | |
| 1014 | static void xl_freemem(struct net_device *dev) |
| 1015 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1016 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | int i ; |
| 1018 | |
| 1019 | for (i=0;i<XL_RX_RING_SIZE;i++) { |
| 1020 | dev_kfree_skb_irq(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail]) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1021 | pci_unmap_single(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | xl_priv->rx_ring_tail++ ; |
| 1023 | xl_priv->rx_ring_tail &= XL_RX_RING_SIZE-1; |
| 1024 | } |
| 1025 | |
| 1026 | /* unmap ring */ |
| 1027 | pci_unmap_single(xl_priv->pdev,xl_priv->rx_ring_dma_addr, sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE, PCI_DMA_FROMDEVICE) ; |
| 1028 | |
| 1029 | pci_unmap_single(xl_priv->pdev,xl_priv->tx_ring_dma_addr, sizeof(struct xl_tx_desc) * XL_TX_RING_SIZE, PCI_DMA_TODEVICE) ; |
| 1030 | |
| 1031 | kfree(xl_priv->xl_rx_ring) ; |
| 1032 | kfree(xl_priv->xl_tx_ring) ; |
| 1033 | |
| 1034 | return ; |
| 1035 | } |
| 1036 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1037 | static irqreturn_t xl_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | { |
| 1039 | struct net_device *dev = (struct net_device *)dev_id; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1040 | struct xl_private *xl_priv =netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1042 | u16 intstatus, macstatus ; |
| 1043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | intstatus = readw(xl_mmio + MMIO_INTSTATUS) ; |
| 1045 | |
| 1046 | if (!(intstatus & 1)) /* We didn't generate the interrupt */ |
| 1047 | return IRQ_NONE; |
| 1048 | |
| 1049 | spin_lock(&xl_priv->xl_lock) ; |
| 1050 | |
| 1051 | /* |
| 1052 | * Process the interrupt |
| 1053 | */ |
| 1054 | /* |
| 1055 | * Something fishy going on here, we shouldn't get 0001 ints, not fatal though. |
| 1056 | */ |
| 1057 | if (intstatus == 0x0001) { |
| 1058 | writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1059 | printk(KERN_INFO "%s: 00001 int received \n",dev->name) ; |
| 1060 | } else { |
| 1061 | if (intstatus & (HOSTERRINT | SRBRINT | ARBCINT | UPCOMPINT | DNCOMPINT | HARDERRINT | (1<<8) | TXUNDERRUN | ASBFINT)) { |
| 1062 | |
| 1063 | /* |
| 1064 | * Host Error. |
| 1065 | * It may be possible to recover from this, but usually it means something |
| 1066 | * is seriously fubar, so we just close the adapter. |
| 1067 | */ |
| 1068 | |
| 1069 | if (intstatus & HOSTERRINT) { |
| 1070 | printk(KERN_WARNING "%s: Host Error, performing global reset, intstatus = %04x \n",dev->name,intstatus) ; |
| 1071 | writew( GLOBAL_RESET, xl_mmio + MMIO_COMMAND ) ; |
| 1072 | printk(KERN_WARNING "%s: Resetting hardware: \n", dev->name); |
| 1073 | netif_stop_queue(dev) ; |
| 1074 | xl_freemem(dev) ; |
| 1075 | free_irq(dev->irq,dev); |
| 1076 | xl_reset(dev) ; |
| 1077 | writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1078 | spin_unlock(&xl_priv->xl_lock) ; |
| 1079 | return IRQ_HANDLED; |
| 1080 | } /* Host Error */ |
| 1081 | |
| 1082 | if (intstatus & SRBRINT ) { /* Srbc interrupt */ |
| 1083 | writel(ACK_INTERRUPT | SRBRACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1084 | if (xl_priv->srb_queued) |
| 1085 | xl_srb_bh(dev) ; |
| 1086 | } /* SRBR Interrupt */ |
| 1087 | |
| 1088 | if (intstatus & TXUNDERRUN) { /* Issue DnReset command */ |
| 1089 | writel(DNRESET, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1090 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { /* Wait for command to run */ |
| 1091 | /* !!! FIX-ME !!!! |
| 1092 | Must put a timeout check here ! */ |
| 1093 | /* Empty Loop */ |
| 1094 | } |
| 1095 | printk(KERN_WARNING "%s: TX Underrun received \n",dev->name) ; |
| 1096 | writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1097 | } /* TxUnderRun */ |
| 1098 | |
| 1099 | if (intstatus & ARBCINT ) { /* Arbc interrupt */ |
| 1100 | xl_arb_cmd(dev) ; |
| 1101 | } /* Arbc */ |
| 1102 | |
| 1103 | if (intstatus & ASBFINT) { |
| 1104 | if (xl_priv->asb_queued == 1) { |
| 1105 | xl_asb_cmd(dev) ; |
| 1106 | } else if (xl_priv->asb_queued == 2) { |
| 1107 | xl_asb_bh(dev) ; |
| 1108 | } else { |
| 1109 | writel(ACK_INTERRUPT | LATCH_ACK | ASBFACK, xl_mmio + MMIO_COMMAND) ; |
| 1110 | } |
| 1111 | } /* Asbf */ |
| 1112 | |
| 1113 | if (intstatus & UPCOMPINT ) /* UpComplete */ |
| 1114 | xl_rx(dev) ; |
| 1115 | |
| 1116 | if (intstatus & DNCOMPINT ) /* DnComplete */ |
| 1117 | xl_dn_comp(dev) ; |
| 1118 | |
| 1119 | if (intstatus & HARDERRINT ) { /* Hardware error */ |
| 1120 | writel(MMIO_WORD_READ | MACSTATUS, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1121 | macstatus = readw(xl_mmio + MMIO_MACDATA) ; |
| 1122 | printk(KERN_WARNING "%s: MacStatusError, details: ", dev->name); |
| 1123 | if (macstatus & (1<<14)) |
| 1124 | printk(KERN_WARNING "tchk error: Unrecoverable error \n") ; |
| 1125 | if (macstatus & (1<<3)) |
| 1126 | printk(KERN_WARNING "eint error: Internal watchdog timer expired \n") ; |
| 1127 | if (macstatus & (1<<2)) |
| 1128 | printk(KERN_WARNING "aint error: Host tried to perform invalid operation \n") ; |
| 1129 | printk(KERN_WARNING "Instatus = %02x, macstatus = %02x\n",intstatus,macstatus) ; |
| 1130 | printk(KERN_WARNING "%s: Resetting hardware: \n", dev->name); |
| 1131 | netif_stop_queue(dev) ; |
| 1132 | xl_freemem(dev) ; |
| 1133 | free_irq(dev->irq,dev); |
| 1134 | unregister_netdev(dev) ; |
| 1135 | free_netdev(dev) ; |
| 1136 | xl_reset(dev) ; |
| 1137 | writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1138 | spin_unlock(&xl_priv->xl_lock) ; |
| 1139 | return IRQ_HANDLED; |
| 1140 | } |
| 1141 | } else { |
| 1142 | printk(KERN_WARNING "%s: Received Unknown interrupt : %04x \n", dev->name, intstatus) ; |
| 1143 | writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | /* Turn interrupts back on */ |
| 1148 | |
| 1149 | writel( SETINDENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ; |
| 1150 | writel( SETINTENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ; |
| 1151 | |
| 1152 | spin_unlock(&xl_priv->xl_lock) ; |
| 1153 | return IRQ_HANDLED; |
| 1154 | } |
| 1155 | |
| 1156 | /* |
| 1157 | * Tx - Polling configuration |
| 1158 | */ |
| 1159 | |
| 1160 | static int xl_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1161 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1162 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | struct xl_tx_desc *txd ; |
| 1164 | int tx_head, tx_tail, tx_prev ; |
| 1165 | unsigned long flags ; |
| 1166 | |
| 1167 | spin_lock_irqsave(&xl_priv->xl_lock,flags) ; |
| 1168 | |
| 1169 | netif_stop_queue(dev) ; |
| 1170 | |
| 1171 | if (xl_priv->free_ring_entries > 1 ) { |
| 1172 | /* |
| 1173 | * Set up the descriptor for the packet |
| 1174 | */ |
| 1175 | tx_head = xl_priv->tx_ring_head ; |
| 1176 | tx_tail = xl_priv->tx_ring_tail ; |
| 1177 | |
| 1178 | txd = &(xl_priv->xl_tx_ring[tx_head]) ; |
| 1179 | txd->dnnextptr = 0 ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1180 | txd->framestartheader = cpu_to_le32(skb->len) | TXDNINDICATE; |
| 1181 | txd->buffer = cpu_to_le32(pci_map_single(xl_priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE)); |
| 1182 | txd->buffer_length = cpu_to_le32(skb->len) | TXDNFRAGLAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | xl_priv->tx_ring_skb[tx_head] = skb ; |
Paulius Zaleckas | 94f9d29 | 2008-04-29 12:44:20 +0300 | [diff] [blame] | 1184 | dev->stats.tx_packets++ ; |
| 1185 | dev->stats.tx_bytes += skb->len ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | /* |
| 1188 | * Set the nextptr of the previous descriptor equal to this descriptor, add XL_TX_RING_SIZE -1 |
| 1189 | * to ensure no negative numbers in unsigned locations. |
| 1190 | */ |
| 1191 | |
| 1192 | tx_prev = (xl_priv->tx_ring_head + XL_TX_RING_SIZE - 1) & (XL_TX_RING_SIZE - 1) ; |
| 1193 | |
| 1194 | xl_priv->tx_ring_head++ ; |
| 1195 | xl_priv->tx_ring_head &= (XL_TX_RING_SIZE - 1) ; |
| 1196 | xl_priv->free_ring_entries-- ; |
| 1197 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1198 | xl_priv->xl_tx_ring[tx_prev].dnnextptr = cpu_to_le32(xl_priv->tx_ring_dma_addr + (sizeof (struct xl_tx_desc) * tx_head)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | |
| 1200 | /* Sneaky, by doing a read on DnListPtr we can force the card to poll on the DnNextPtr */ |
| 1201 | /* readl(xl_mmio + MMIO_DNLISTPTR) ; */ |
| 1202 | |
| 1203 | netif_wake_queue(dev) ; |
| 1204 | |
| 1205 | spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ; |
| 1206 | |
| 1207 | return 0; |
| 1208 | } else { |
| 1209 | spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ; |
| 1210 | return 1; |
| 1211 | } |
| 1212 | |
| 1213 | } |
| 1214 | |
| 1215 | /* |
| 1216 | * The NIC has told us that a packet has been downloaded onto the card, we must |
| 1217 | * find out which packet it has done, clear the skb and information for the packet |
| 1218 | * then advance around the ring for all tranmitted packets |
| 1219 | */ |
| 1220 | |
| 1221 | static void xl_dn_comp(struct net_device *dev) |
| 1222 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1223 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1225 | struct xl_tx_desc *txd ; |
| 1226 | |
| 1227 | |
| 1228 | if (xl_priv->tx_ring_tail == 255) {/* First time */ |
| 1229 | xl_priv->xl_tx_ring[0].framestartheader = 0 ; |
| 1230 | xl_priv->xl_tx_ring[0].dnnextptr = 0 ; |
| 1231 | xl_priv->tx_ring_tail = 1 ; |
| 1232 | } |
| 1233 | |
| 1234 | while (xl_priv->xl_tx_ring[xl_priv->tx_ring_tail].framestartheader & TXDNCOMPLETE ) { |
| 1235 | txd = &(xl_priv->xl_tx_ring[xl_priv->tx_ring_tail]) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1236 | pci_unmap_single(xl_priv->pdev, le32_to_cpu(txd->buffer), xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]->len, PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | txd->framestartheader = 0 ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1238 | txd->buffer = cpu_to_le32(0xdeadbeef); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | txd->buffer_length = 0 ; |
| 1240 | dev_kfree_skb_irq(xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]) ; |
| 1241 | xl_priv->tx_ring_tail++ ; |
| 1242 | xl_priv->tx_ring_tail &= (XL_TX_RING_SIZE - 1) ; |
| 1243 | xl_priv->free_ring_entries++ ; |
| 1244 | } |
| 1245 | |
| 1246 | netif_wake_queue(dev) ; |
| 1247 | |
| 1248 | writel(ACK_INTERRUPT | DNCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ; |
| 1249 | } |
| 1250 | |
| 1251 | /* |
| 1252 | * Close the adapter properly. |
| 1253 | * This srb reply cannot be handled from interrupt context as we have |
| 1254 | * to free the interrupt from the driver. |
| 1255 | */ |
| 1256 | |
| 1257 | static int xl_close(struct net_device *dev) |
| 1258 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1259 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1261 | unsigned long t ; |
| 1262 | |
| 1263 | netif_stop_queue(dev) ; |
| 1264 | |
| 1265 | /* |
| 1266 | * Close the adapter, need to stall the rx and tx queues. |
| 1267 | */ |
| 1268 | |
| 1269 | writew(DNSTALL, xl_mmio + MMIO_COMMAND) ; |
| 1270 | t=jiffies; |
| 1271 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { |
| 1272 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 1273 | if (time_after(jiffies, t + 10 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-DNSTALL not responding.\n", dev->name); |
| 1275 | break ; |
| 1276 | } |
| 1277 | } |
| 1278 | writew(DNDISABLE, xl_mmio + MMIO_COMMAND) ; |
| 1279 | t=jiffies; |
| 1280 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { |
| 1281 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 1282 | if (time_after(jiffies, t + 10 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-DNDISABLE not responding.\n", dev->name); |
| 1284 | break ; |
| 1285 | } |
| 1286 | } |
| 1287 | writew(UPSTALL, xl_mmio + MMIO_COMMAND) ; |
| 1288 | t=jiffies; |
| 1289 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { |
| 1290 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 1291 | if (time_after(jiffies, t + 10 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-UPSTALL not responding.\n", dev->name); |
| 1293 | break ; |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | /* Turn off interrupts, we will still get the indication though |
| 1298 | * so we can trap it |
| 1299 | */ |
| 1300 | |
| 1301 | writel(SETINTENABLE, xl_mmio + MMIO_COMMAND) ; |
| 1302 | |
| 1303 | xl_srb_cmd(dev,CLOSE_NIC) ; |
| 1304 | |
| 1305 | t=jiffies; |
| 1306 | while (!(readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_SRB)) { |
| 1307 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 1308 | if (time_after(jiffies, t + 10 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-CLOSENIC not responding.\n", dev->name); |
| 1310 | break ; |
| 1311 | } |
| 1312 | } |
| 1313 | /* Read the srb response from the adapter */ |
| 1314 | |
| 1315 | writel(MEM_BYTE_READ | 0xd0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD); |
| 1316 | if (readb(xl_mmio + MMIO_MACDATA) != CLOSE_NIC) { |
| 1317 | printk(KERN_INFO "%s: CLOSE_NIC did not get a CLOSE_NIC response \n",dev->name) ; |
| 1318 | } else { |
| 1319 | writel((MEM_BYTE_READ | 0xd0000 | xl_priv->srb) +2, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1320 | if (readb(xl_mmio + MMIO_MACDATA)==0) { |
| 1321 | printk(KERN_INFO "%s: Adapter has been closed \n",dev->name) ; |
| 1322 | writew(ACK_INTERRUPT | SRBRACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1323 | |
| 1324 | xl_freemem(dev) ; |
| 1325 | free_irq(dev->irq,dev) ; |
| 1326 | } else { |
| 1327 | printk(KERN_INFO "%s: Close nic command returned error code %02x\n",dev->name, readb(xl_mmio + MMIO_MACDATA)) ; |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | /* Reset the upload and download logic */ |
| 1332 | |
| 1333 | writew(UPRESET, xl_mmio + MMIO_COMMAND) ; |
| 1334 | t=jiffies; |
| 1335 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { |
| 1336 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 1337 | if (time_after(jiffies, t + 10 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-UPRESET not responding.\n", dev->name); |
| 1339 | break ; |
| 1340 | } |
| 1341 | } |
| 1342 | writew(DNRESET, xl_mmio + MMIO_COMMAND) ; |
| 1343 | t=jiffies; |
| 1344 | while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { |
| 1345 | schedule(); |
S.Caglar Onur | b7aa690 | 2008-03-28 14:41:25 -0700 | [diff] [blame] | 1346 | if (time_after(jiffies, t + 10 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-DNRESET not responding.\n", dev->name); |
| 1348 | break ; |
| 1349 | } |
| 1350 | } |
| 1351 | xl_hw_reset(dev) ; |
| 1352 | return 0 ; |
| 1353 | } |
| 1354 | |
| 1355 | static void xl_set_rx_mode(struct net_device *dev) |
| 1356 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1357 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | struct dev_mc_list *dmi ; |
| 1359 | unsigned char dev_mc_address[4] ; |
| 1360 | u16 options ; |
| 1361 | int i ; |
| 1362 | |
| 1363 | if (dev->flags & IFF_PROMISC) |
| 1364 | options = 0x0004 ; |
| 1365 | else |
| 1366 | options = 0x0000 ; |
| 1367 | |
| 1368 | if (options ^ xl_priv->xl_copy_all_options) { /* Changed, must send command */ |
| 1369 | xl_priv->xl_copy_all_options = options ; |
| 1370 | xl_srb_cmd(dev, SET_RECEIVE_MODE) ; |
| 1371 | return ; |
| 1372 | } |
| 1373 | |
| 1374 | dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ; |
| 1375 | |
| 1376 | for (i=0,dmi=dev->mc_list;i < dev->mc_count; i++,dmi = dmi->next) { |
| 1377 | dev_mc_address[0] |= dmi->dmi_addr[2] ; |
| 1378 | dev_mc_address[1] |= dmi->dmi_addr[3] ; |
| 1379 | dev_mc_address[2] |= dmi->dmi_addr[4] ; |
| 1380 | dev_mc_address[3] |= dmi->dmi_addr[5] ; |
| 1381 | } |
| 1382 | |
| 1383 | if (memcmp(xl_priv->xl_functional_addr,dev_mc_address,4) != 0) { /* Options have changed, run the command */ |
| 1384 | memcpy(xl_priv->xl_functional_addr, dev_mc_address,4) ; |
| 1385 | xl_srb_cmd(dev, SET_FUNC_ADDRESS) ; |
| 1386 | } |
| 1387 | return ; |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | /* |
| 1392 | * We issued an srb command and now we must read |
| 1393 | * the response from the completed command. |
| 1394 | */ |
| 1395 | |
| 1396 | static void xl_srb_bh(struct net_device *dev) |
| 1397 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1398 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1400 | u8 srb_cmd, ret_code ; |
| 1401 | int i ; |
| 1402 | |
| 1403 | writel(MEM_BYTE_READ | 0xd0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1404 | srb_cmd = readb(xl_mmio + MMIO_MACDATA) ; |
| 1405 | writel((MEM_BYTE_READ | 0xd0000 | xl_priv->srb) +2, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1406 | ret_code = readb(xl_mmio + MMIO_MACDATA) ; |
| 1407 | |
| 1408 | /* Ret_code is standard across all commands */ |
| 1409 | |
| 1410 | switch (ret_code) { |
| 1411 | case 1: |
| 1412 | printk(KERN_INFO "%s: Command: %d - Invalid Command code\n",dev->name,srb_cmd) ; |
| 1413 | break ; |
| 1414 | case 4: |
| 1415 | printk(KERN_INFO "%s: Command: %d - Adapter is closed, must be open for this command \n",dev->name,srb_cmd) ; |
| 1416 | break ; |
| 1417 | |
| 1418 | case 6: |
| 1419 | printk(KERN_INFO "%s: Command: %d - Options Invalid for command \n",dev->name,srb_cmd) ; |
| 1420 | break ; |
| 1421 | |
| 1422 | case 0: /* Successful command execution */ |
| 1423 | switch (srb_cmd) { |
| 1424 | case READ_LOG: /* Returns 14 bytes of data from the NIC */ |
| 1425 | if(xl_priv->xl_message_level) |
| 1426 | printk(KERN_INFO "%s: READ.LOG 14 bytes of data ",dev->name) ; |
| 1427 | /* |
| 1428 | * We still have to read the log even if message_level = 0 and we don't want |
| 1429 | * to see it |
| 1430 | */ |
| 1431 | for (i=0;i<14;i++) { |
| 1432 | writel(MEM_BYTE_READ | 0xd0000 | xl_priv->srb | i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1433 | if(xl_priv->xl_message_level) |
| 1434 | printk("%02x:",readb(xl_mmio + MMIO_MACDATA)) ; |
| 1435 | } |
| 1436 | printk("\n") ; |
| 1437 | break ; |
| 1438 | case SET_FUNC_ADDRESS: |
| 1439 | if(xl_priv->xl_message_level) |
| 1440 | printk(KERN_INFO "%s: Functional Address Set \n",dev->name) ; |
| 1441 | break ; |
| 1442 | case CLOSE_NIC: |
| 1443 | if(xl_priv->xl_message_level) |
| 1444 | printk(KERN_INFO "%s: Received CLOSE_NIC interrupt in interrupt handler \n",dev->name) ; |
| 1445 | break ; |
| 1446 | case SET_MULTICAST_MODE: |
| 1447 | if(xl_priv->xl_message_level) |
| 1448 | printk(KERN_INFO "%s: Multicast options successfully changed\n",dev->name) ; |
| 1449 | break ; |
| 1450 | case SET_RECEIVE_MODE: |
| 1451 | if(xl_priv->xl_message_level) { |
| 1452 | if (xl_priv->xl_copy_all_options == 0x0004) |
| 1453 | printk(KERN_INFO "%s: Entering promiscuous mode \n", dev->name) ; |
| 1454 | else |
| 1455 | printk(KERN_INFO "%s: Entering normal receive mode \n",dev->name) ; |
| 1456 | } |
| 1457 | break ; |
| 1458 | |
| 1459 | } /* switch */ |
| 1460 | break ; |
| 1461 | } /* switch */ |
| 1462 | return ; |
| 1463 | } |
| 1464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | static int xl_set_mac_address (struct net_device *dev, void *addr) |
| 1466 | { |
| 1467 | struct sockaddr *saddr = addr ; |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1468 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
| 1470 | if (netif_running(dev)) { |
| 1471 | printk(KERN_WARNING "%s: Cannot set mac/laa address while card is open\n", dev->name) ; |
| 1472 | return -EIO ; |
| 1473 | } |
| 1474 | |
| 1475 | memcpy(xl_priv->xl_laa, saddr->sa_data,dev->addr_len) ; |
| 1476 | |
| 1477 | if (xl_priv->xl_message_level) { |
| 1478 | printk(KERN_INFO "%s: MAC/LAA Set to = %x.%x.%x.%x.%x.%x\n",dev->name, xl_priv->xl_laa[0], |
| 1479 | xl_priv->xl_laa[1], xl_priv->xl_laa[2], |
| 1480 | xl_priv->xl_laa[3], xl_priv->xl_laa[4], |
| 1481 | xl_priv->xl_laa[5]); |
| 1482 | } |
| 1483 | |
| 1484 | return 0 ; |
| 1485 | } |
| 1486 | |
| 1487 | static void xl_arb_cmd(struct net_device *dev) |
| 1488 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1489 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1491 | u8 arb_cmd ; |
| 1492 | u16 lan_status, lan_status_diff ; |
| 1493 | |
| 1494 | writel( ( MEM_BYTE_READ | 0xD0000 | xl_priv->arb), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1495 | arb_cmd = readb(xl_mmio + MMIO_MACDATA) ; |
| 1496 | |
| 1497 | if (arb_cmd == RING_STATUS_CHANGE) { /* Ring.Status.Change */ |
| 1498 | writel( ( (MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1499 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1500 | printk(KERN_INFO "%s: Ring Status Change: New Status = %04x\n", dev->name, swab16(readw(xl_mmio + MMIO_MACDATA) )) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1502 | lan_status = swab16(readw(xl_mmio + MMIO_MACDATA)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
| 1504 | /* Acknowledge interrupt, this tells nic we are done with the arb */ |
| 1505 | writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1506 | |
| 1507 | lan_status_diff = xl_priv->xl_lan_status ^ lan_status ; |
| 1508 | |
| 1509 | if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR) ) { |
| 1510 | if (lan_status_diff & LSC_LWF) |
| 1511 | printk(KERN_WARNING "%s: Short circuit detected on the lobe\n",dev->name); |
| 1512 | if (lan_status_diff & LSC_ARW) |
| 1513 | printk(KERN_WARNING "%s: Auto removal error\n",dev->name); |
| 1514 | if (lan_status_diff & LSC_FPE) |
| 1515 | printk(KERN_WARNING "%s: FDX Protocol Error\n",dev->name); |
| 1516 | if (lan_status_diff & LSC_RR) |
| 1517 | printk(KERN_WARNING "%s: Force remove MAC frame received\n",dev->name); |
| 1518 | |
| 1519 | /* Adapter has been closed by the hardware */ |
| 1520 | |
| 1521 | netif_stop_queue(dev); |
| 1522 | xl_freemem(dev) ; |
| 1523 | free_irq(dev->irq,dev); |
| 1524 | |
| 1525 | printk(KERN_WARNING "%s: Adapter has been closed \n", dev->name) ; |
| 1526 | } /* If serious error */ |
| 1527 | |
| 1528 | if (xl_priv->xl_message_level) { |
| 1529 | if (lan_status_diff & LSC_SIG_LOSS) |
| 1530 | printk(KERN_WARNING "%s: No receive signal detected \n", dev->name) ; |
| 1531 | if (lan_status_diff & LSC_HARD_ERR) |
| 1532 | printk(KERN_INFO "%s: Beaconing \n",dev->name); |
| 1533 | if (lan_status_diff & LSC_SOFT_ERR) |
| 1534 | printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame \n",dev->name); |
| 1535 | if (lan_status_diff & LSC_TRAN_BCN) |
| 1536 | printk(KERN_INFO "%s: We are tranmitting the beacon, aaah\n",dev->name); |
| 1537 | if (lan_status_diff & LSC_SS) |
| 1538 | printk(KERN_INFO "%s: Single Station on the ring \n", dev->name); |
| 1539 | if (lan_status_diff & LSC_RING_REC) |
| 1540 | printk(KERN_INFO "%s: Ring recovery ongoing\n",dev->name); |
| 1541 | if (lan_status_diff & LSC_FDX_MODE) |
| 1542 | printk(KERN_INFO "%s: Operating in FDX mode\n",dev->name); |
| 1543 | } |
| 1544 | |
| 1545 | if (lan_status_diff & LSC_CO) { |
| 1546 | if (xl_priv->xl_message_level) |
| 1547 | printk(KERN_INFO "%s: Counter Overflow \n", dev->name); |
| 1548 | /* Issue READ.LOG command */ |
| 1549 | xl_srb_cmd(dev, READ_LOG) ; |
| 1550 | } |
| 1551 | |
| 1552 | /* There is no command in the tech docs to issue the read_sr_counters */ |
| 1553 | if (lan_status_diff & LSC_SR_CO) { |
| 1554 | if (xl_priv->xl_message_level) |
| 1555 | printk(KERN_INFO "%s: Source routing counters overflow\n", dev->name); |
| 1556 | } |
| 1557 | |
| 1558 | xl_priv->xl_lan_status = lan_status ; |
| 1559 | |
| 1560 | } /* Lan.change.status */ |
| 1561 | else if ( arb_cmd == RECEIVE_DATA) { /* Received.Data */ |
| 1562 | #if XL_DEBUG |
| 1563 | printk(KERN_INFO "Received.Data \n") ; |
| 1564 | #endif |
| 1565 | writel( ((MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1566 | xl_priv->mac_buffer = swab16(readw(xl_mmio + MMIO_MACDATA)) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | |
| 1568 | /* Now we are going to be really basic here and not do anything |
| 1569 | * with the data at all. The tech docs do not give me enough |
| 1570 | * information to calculate the buffers properly so we're |
| 1571 | * just going to tell the nic that we've dealt with the frame |
| 1572 | * anyway. |
| 1573 | */ |
| 1574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | /* Acknowledge interrupt, this tells nic we are done with the arb */ |
| 1576 | writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; |
| 1577 | |
| 1578 | /* Is the ASB free ? */ |
| 1579 | |
| 1580 | xl_priv->asb_queued = 0 ; |
| 1581 | writel( ((MEM_BYTE_READ | 0xD0000 | xl_priv->asb) + 2), xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1582 | if (readb(xl_mmio + MMIO_MACDATA) != 0xff) { |
| 1583 | xl_priv->asb_queued = 1 ; |
| 1584 | |
| 1585 | xl_wait_misr_flags(dev) ; |
| 1586 | |
| 1587 | writel(MEM_BYTE_WRITE | MF_ASBFR, xl_mmio + MMIO_MAC_ACCESS_CMD); |
| 1588 | writeb(0xff, xl_mmio + MMIO_MACDATA) ; |
| 1589 | writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1590 | writeb(MISR_ASBFR, xl_mmio + MMIO_MACDATA) ; |
| 1591 | return ; |
| 1592 | /* Drop out and wait for the bottom half to be run */ |
| 1593 | } |
| 1594 | |
| 1595 | xl_asb_cmd(dev) ; |
| 1596 | |
| 1597 | } else { |
| 1598 | printk(KERN_WARNING "%s: Received unknown arb (xl_priv) command: %02x \n",dev->name,arb_cmd) ; |
| 1599 | } |
| 1600 | |
| 1601 | /* Acknowledge the arb interrupt */ |
| 1602 | |
| 1603 | writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ; |
| 1604 | |
| 1605 | return ; |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | /* |
| 1610 | * There is only one asb command, but we can get called from different |
| 1611 | * places. |
| 1612 | */ |
| 1613 | |
| 1614 | static void xl_asb_cmd(struct net_device *dev) |
| 1615 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1616 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1618 | |
| 1619 | if (xl_priv->asb_queued == 1) |
| 1620 | writel(ACK_INTERRUPT | LATCH_ACK | ASBFACK, xl_mmio + MMIO_COMMAND) ; |
| 1621 | |
| 1622 | writel(MEM_BYTE_WRITE | 0xd0000 | xl_priv->asb, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1623 | writeb(0x81, xl_mmio + MMIO_MACDATA) ; |
| 1624 | |
| 1625 | writel(MEM_WORD_WRITE | 0xd0000 | xl_priv->asb | 6, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
Al Viro | 9914cad | 2007-12-22 19:44:10 +0000 | [diff] [blame] | 1626 | writew(swab16(xl_priv->mac_buffer), xl_mmio + MMIO_MACDATA) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
| 1628 | xl_wait_misr_flags(dev) ; |
| 1629 | |
| 1630 | writel(MEM_BYTE_WRITE | MF_RASB, xl_mmio + MMIO_MAC_ACCESS_CMD); |
| 1631 | writeb(0xff, xl_mmio + MMIO_MACDATA) ; |
| 1632 | |
| 1633 | writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1634 | writeb(MISR_RASB, xl_mmio + MMIO_MACDATA) ; |
| 1635 | |
| 1636 | xl_priv->asb_queued = 2 ; |
| 1637 | |
| 1638 | return ; |
| 1639 | } |
| 1640 | |
| 1641 | /* |
| 1642 | * This will only get called if there was an error |
| 1643 | * from the asb cmd. |
| 1644 | */ |
| 1645 | static void xl_asb_bh(struct net_device *dev) |
| 1646 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1647 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1649 | u8 ret_code ; |
| 1650 | |
| 1651 | writel(MMIO_BYTE_READ | 0xd0000 | xl_priv->asb | 2, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1652 | ret_code = readb(xl_mmio + MMIO_MACDATA) ; |
| 1653 | switch (ret_code) { |
| 1654 | case 0x01: |
| 1655 | printk(KERN_INFO "%s: ASB Command, unrecognized command code \n",dev->name) ; |
| 1656 | break ; |
| 1657 | case 0x26: |
| 1658 | printk(KERN_INFO "%s: ASB Command, unexpected receive buffer \n", dev->name) ; |
| 1659 | break ; |
| 1660 | case 0x40: |
| 1661 | printk(KERN_INFO "%s: ASB Command, Invalid Station ID \n", dev->name) ; |
| 1662 | break ; |
| 1663 | } |
| 1664 | xl_priv->asb_queued = 0 ; |
| 1665 | writel(ACK_INTERRUPT | LATCH_ACK | ASBFACK, xl_mmio + MMIO_COMMAND) ; |
| 1666 | return ; |
| 1667 | } |
| 1668 | |
| 1669 | /* |
| 1670 | * Issue srb commands to the nic |
| 1671 | */ |
| 1672 | |
| 1673 | static void xl_srb_cmd(struct net_device *dev, int srb_cmd) |
| 1674 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1675 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1677 | |
| 1678 | switch (srb_cmd) { |
| 1679 | case READ_LOG: |
| 1680 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1681 | writeb(READ_LOG, xl_mmio + MMIO_MACDATA) ; |
| 1682 | break; |
| 1683 | |
| 1684 | case CLOSE_NIC: |
| 1685 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1686 | writeb(CLOSE_NIC, xl_mmio + MMIO_MACDATA) ; |
| 1687 | break ; |
| 1688 | |
| 1689 | case SET_RECEIVE_MODE: |
| 1690 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1691 | writeb(SET_RECEIVE_MODE, xl_mmio + MMIO_MACDATA) ; |
| 1692 | writel(MEM_WORD_WRITE | 0xD0000 | xl_priv->srb | 4, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1693 | writew(xl_priv->xl_copy_all_options, xl_mmio + MMIO_MACDATA) ; |
| 1694 | break ; |
| 1695 | |
| 1696 | case SET_FUNC_ADDRESS: |
| 1697 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1698 | writeb(SET_FUNC_ADDRESS, xl_mmio + MMIO_MACDATA) ; |
| 1699 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 6 , xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1700 | writeb(xl_priv->xl_functional_addr[0], xl_mmio + MMIO_MACDATA) ; |
| 1701 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 7 , xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1702 | writeb(xl_priv->xl_functional_addr[1], xl_mmio + MMIO_MACDATA) ; |
| 1703 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 8 , xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1704 | writeb(xl_priv->xl_functional_addr[2], xl_mmio + MMIO_MACDATA) ; |
| 1705 | writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 9 , xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1706 | writeb(xl_priv->xl_functional_addr[3], xl_mmio + MMIO_MACDATA) ; |
| 1707 | break ; |
| 1708 | } /* switch */ |
| 1709 | |
| 1710 | |
| 1711 | xl_wait_misr_flags(dev) ; |
| 1712 | |
| 1713 | /* Write 0xff to the CSRB flag */ |
| 1714 | writel(MEM_BYTE_WRITE | MF_CSRB , xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1715 | writeb(0xFF, xl_mmio + MMIO_MACDATA) ; |
| 1716 | /* Set csrb bit in MISR register to process command */ |
| 1717 | writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1718 | writeb(MISR_CSRB, xl_mmio + MMIO_MACDATA) ; |
| 1719 | xl_priv->srb_queued = 1 ; |
| 1720 | |
| 1721 | return ; |
| 1722 | } |
| 1723 | |
| 1724 | /* |
| 1725 | * This is nasty, to use the MISR command you have to wait for 6 memory locations |
| 1726 | * to be zero. This is the way the driver does on other OS'es so we should be ok with |
| 1727 | * the empty loop. |
| 1728 | */ |
| 1729 | |
| 1730 | static void xl_wait_misr_flags(struct net_device *dev) |
| 1731 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1732 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | u8 __iomem * xl_mmio = xl_priv->xl_mmio ; |
| 1734 | |
| 1735 | int i ; |
| 1736 | |
| 1737 | writel(MMIO_BYTE_READ | MISR_RW, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1738 | if (readb(xl_mmio + MMIO_MACDATA) != 0) { /* Misr not clear */ |
| 1739 | for (i=0; i<6; i++) { |
| 1740 | writel(MEM_BYTE_READ | 0xDFFE0 | i, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1741 | while (readb(xl_mmio + MMIO_MACDATA) != 0 ) {} ; /* Empty Loop */ |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | writel(MMIO_BYTE_WRITE | MISR_AND, xl_mmio + MMIO_MAC_ACCESS_CMD) ; |
| 1746 | writeb(0x80, xl_mmio + MMIO_MACDATA) ; |
| 1747 | |
| 1748 | return ; |
| 1749 | } |
| 1750 | |
| 1751 | /* |
| 1752 | * Change mtu size, this should work the same as olympic |
| 1753 | */ |
| 1754 | |
| 1755 | static int xl_change_mtu(struct net_device *dev, int mtu) |
| 1756 | { |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1757 | struct xl_private *xl_priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | u16 max_mtu ; |
| 1759 | |
| 1760 | if (xl_priv->xl_ring_speed == 4) |
| 1761 | max_mtu = 4500 ; |
| 1762 | else |
| 1763 | max_mtu = 18000 ; |
| 1764 | |
| 1765 | if (mtu > max_mtu) |
| 1766 | return -EINVAL ; |
| 1767 | if (mtu < 100) |
| 1768 | return -EINVAL ; |
| 1769 | |
| 1770 | dev->mtu = mtu ; |
| 1771 | xl_priv->pkt_buf_sz = mtu + TR_HLEN ; |
| 1772 | |
| 1773 | return 0 ; |
| 1774 | } |
| 1775 | |
| 1776 | static void __devexit xl_remove_one (struct pci_dev *pdev) |
| 1777 | { |
| 1778 | struct net_device *dev = pci_get_drvdata(pdev); |
Yoann Padioleau | eda1053 | 2007-07-23 15:18:21 +0200 | [diff] [blame] | 1779 | struct xl_private *xl_priv=netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | |
| 1781 | unregister_netdev(dev); |
| 1782 | iounmap(xl_priv->xl_mmio) ; |
| 1783 | pci_release_regions(pdev) ; |
| 1784 | pci_set_drvdata(pdev,NULL) ; |
| 1785 | free_netdev(dev); |
| 1786 | return ; |
| 1787 | } |
| 1788 | |
| 1789 | static struct pci_driver xl_3c359_driver = { |
| 1790 | .name = "3c359", |
| 1791 | .id_table = xl_pci_tbl, |
| 1792 | .probe = xl_probe, |
| 1793 | .remove = __devexit_p(xl_remove_one), |
| 1794 | }; |
| 1795 | |
| 1796 | static int __init xl_pci_init (void) |
| 1797 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 1798 | return pci_register_driver(&xl_3c359_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | static void __exit xl_pci_cleanup (void) |
| 1803 | { |
| 1804 | pci_unregister_driver (&xl_3c359_driver); |
| 1805 | } |
| 1806 | |
| 1807 | module_init(xl_pci_init); |
| 1808 | module_exit(xl_pci_cleanup); |
| 1809 | |
| 1810 | MODULE_LICENSE("GPL") ; |