Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Network device driver for Cell Processor-Based Blade |
| 3 | * |
| 4 | * (C) Copyright IBM Corp. 2005 |
| 5 | * |
| 6 | * Authors : Utz Bacher <utz.bacher@de.ibm.com> |
| 7 | * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 24 | #include <linux/compiler.h> |
| 25 | #include <linux/crc32.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/ethtool.h> |
| 29 | #include <linux/firmware.h> |
| 30 | #include <linux/if_vlan.h> |
Arnd Bergmann | 7c5c220 | 2006-01-12 17:16:45 -0500 | [diff] [blame] | 31 | #include <linux/in.h> |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/ioport.h> |
| 34 | #include <linux/ip.h> |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/mii.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/device.h> |
| 40 | #include <linux/pci.h> |
| 41 | #include <linux/skbuff.h> |
| 42 | #include <linux/slab.h> |
| 43 | #include <linux/tcp.h> |
| 44 | #include <linux/types.h> |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 45 | #include <linux/vmalloc.h> |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 46 | #include <linux/wait.h> |
| 47 | #include <linux/workqueue.h> |
| 48 | #include <asm/bitops.h> |
| 49 | #include <asm/pci-bridge.h> |
| 50 | #include <net/checksum.h> |
| 51 | |
| 52 | #include "spider_net.h" |
| 53 | |
| 54 | MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com> and Jens Osterkamp " \ |
| 55 | "<Jens.Osterkamp@de.ibm.com>"); |
| 56 | MODULE_DESCRIPTION("Spider Southbridge Gigabit Ethernet driver"); |
| 57 | MODULE_LICENSE("GPL"); |
Linas Vepstas | 90f1084 | 2006-10-10 15:56:04 -0500 | [diff] [blame] | 58 | MODULE_VERSION(VERSION); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 59 | |
| 60 | static int rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_DEFAULT; |
| 61 | static int tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_DEFAULT; |
| 62 | |
Linas Vepstas | e2874f2 | 2006-10-10 15:59:02 -0500 | [diff] [blame] | 63 | module_param(rx_descriptors, int, 0444); |
| 64 | module_param(tx_descriptors, int, 0444); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 65 | |
| 66 | MODULE_PARM_DESC(rx_descriptors, "number of descriptors used " \ |
| 67 | "in rx chains"); |
| 68 | MODULE_PARM_DESC(tx_descriptors, "number of descriptors used " \ |
| 69 | "in tx chain"); |
| 70 | |
| 71 | char spider_net_driver_name[] = "spidernet"; |
| 72 | |
| 73 | static struct pci_device_id spider_net_pci_tbl[] = { |
| 74 | { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SPIDER_NET, |
| 75 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, |
| 76 | { 0, } |
| 77 | }; |
| 78 | |
| 79 | MODULE_DEVICE_TABLE(pci, spider_net_pci_tbl); |
| 80 | |
| 81 | /** |
| 82 | * spider_net_read_reg - reads an SMMIO register of a card |
| 83 | * @card: device structure |
| 84 | * @reg: register to read from |
| 85 | * |
| 86 | * returns the content of the specified SMMIO register. |
| 87 | */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 88 | static inline u32 |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 89 | spider_net_read_reg(struct spider_net_card *card, u32 reg) |
| 90 | { |
| 91 | u32 value; |
| 92 | |
| 93 | value = readl(card->regs + reg); |
| 94 | value = le32_to_cpu(value); |
| 95 | |
| 96 | return value; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * spider_net_write_reg - writes to an SMMIO register of a card |
| 101 | * @card: device structure |
| 102 | * @reg: register to write to |
| 103 | * @value: value to write into the specified SMMIO register |
| 104 | */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 105 | static inline void |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 106 | spider_net_write_reg(struct spider_net_card *card, u32 reg, u32 value) |
| 107 | { |
| 108 | value = cpu_to_le32(value); |
| 109 | writel(value, card->regs + reg); |
| 110 | } |
| 111 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 112 | /** spider_net_write_phy - write to phy register |
| 113 | * @netdev: adapter to be written to |
| 114 | * @mii_id: id of MII |
| 115 | * @reg: PHY register |
| 116 | * @val: value to be written to phy register |
| 117 | * |
| 118 | * spider_net_write_phy_register writes to an arbitrary PHY |
| 119 | * register via the spider GPCWOPCMD register. We assume the queue does |
| 120 | * not run full (not more than 15 commands outstanding). |
| 121 | **/ |
| 122 | static void |
| 123 | spider_net_write_phy(struct net_device *netdev, int mii_id, |
| 124 | int reg, int val) |
| 125 | { |
| 126 | struct spider_net_card *card = netdev_priv(netdev); |
| 127 | u32 writevalue; |
| 128 | |
| 129 | writevalue = ((u32)mii_id << 21) | |
| 130 | ((u32)reg << 16) | ((u32)val); |
| 131 | |
| 132 | spider_net_write_reg(card, SPIDER_NET_GPCWOPCMD, writevalue); |
| 133 | } |
| 134 | |
| 135 | /** spider_net_read_phy - read from phy register |
| 136 | * @netdev: network device to be read from |
| 137 | * @mii_id: id of MII |
| 138 | * @reg: PHY register |
| 139 | * |
| 140 | * Returns value read from PHY register |
| 141 | * |
| 142 | * spider_net_write_phy reads from an arbitrary PHY |
| 143 | * register via the spider GPCROPCMD register |
| 144 | **/ |
| 145 | static int |
| 146 | spider_net_read_phy(struct net_device *netdev, int mii_id, int reg) |
| 147 | { |
| 148 | struct spider_net_card *card = netdev_priv(netdev); |
| 149 | u32 readvalue; |
| 150 | |
| 151 | readvalue = ((u32)mii_id << 21) | ((u32)reg << 16); |
| 152 | spider_net_write_reg(card, SPIDER_NET_GPCROPCMD, readvalue); |
| 153 | |
| 154 | /* we don't use semaphores to wait for an SPIDER_NET_GPROPCMPINT |
| 155 | * interrupt, as we poll for the completion of the read operation |
| 156 | * in spider_net_read_phy. Should take about 50 us */ |
| 157 | do { |
| 158 | readvalue = spider_net_read_reg(card, SPIDER_NET_GPCROPCMD); |
| 159 | } while (readvalue & SPIDER_NET_GPREXEC); |
| 160 | |
| 161 | readvalue &= SPIDER_NET_GPRDAT_MASK; |
| 162 | |
| 163 | return readvalue; |
| 164 | } |
| 165 | |
| 166 | /** |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 167 | * spider_net_rx_irq_off - switch off rx irq on this spider card |
| 168 | * @card: device structure |
| 169 | * |
| 170 | * switches off rx irq by masking them out in the GHIINTnMSK register |
| 171 | */ |
| 172 | static void |
| 173 | spider_net_rx_irq_off(struct spider_net_card *card) |
| 174 | { |
| 175 | u32 regvalue; |
| 176 | |
| 177 | regvalue = SPIDER_NET_INT0_MASK_VALUE & (~SPIDER_NET_RXINT); |
| 178 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, regvalue); |
| 179 | } |
| 180 | |
| 181 | /** |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 182 | * spider_net_rx_irq_on - switch on rx irq on this spider card |
| 183 | * @card: device structure |
| 184 | * |
| 185 | * switches on rx irq by enabling them in the GHIINTnMSK register |
| 186 | */ |
| 187 | static void |
| 188 | spider_net_rx_irq_on(struct spider_net_card *card) |
| 189 | { |
| 190 | u32 regvalue; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 191 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 192 | regvalue = SPIDER_NET_INT0_MASK_VALUE | SPIDER_NET_RXINT; |
| 193 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, regvalue); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * spider_net_set_promisc - sets the unicast address or the promiscuous mode |
| 198 | * @card: card structure |
| 199 | * |
| 200 | * spider_net_set_promisc sets the unicast destination address filter and |
| 201 | * thus either allows for non-promisc mode or promisc mode |
| 202 | */ |
| 203 | static void |
| 204 | spider_net_set_promisc(struct spider_net_card *card) |
| 205 | { |
| 206 | u32 macu, macl; |
| 207 | struct net_device *netdev = card->netdev; |
| 208 | |
| 209 | if (netdev->flags & IFF_PROMISC) { |
| 210 | /* clear destination entry 0 */ |
| 211 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR, 0); |
| 212 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR + 0x04, 0); |
| 213 | spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, |
| 214 | SPIDER_NET_PROMISC_VALUE); |
| 215 | } else { |
| 216 | macu = netdev->dev_addr[0]; |
| 217 | macu <<= 8; |
| 218 | macu |= netdev->dev_addr[1]; |
| 219 | memcpy(&macl, &netdev->dev_addr[2], sizeof(macl)); |
| 220 | |
| 221 | macu |= SPIDER_NET_UA_DESCR_VALUE; |
| 222 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR, macu); |
| 223 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR + 0x04, macl); |
| 224 | spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, |
| 225 | SPIDER_NET_NONPROMISC_VALUE); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * spider_net_get_mac_address - read mac address from spider card |
| 231 | * @card: device structure |
| 232 | * |
| 233 | * reads MAC address from GMACUNIMACU and GMACUNIMACL registers |
| 234 | */ |
| 235 | static int |
| 236 | spider_net_get_mac_address(struct net_device *netdev) |
| 237 | { |
| 238 | struct spider_net_card *card = netdev_priv(netdev); |
| 239 | u32 macl, macu; |
| 240 | |
| 241 | macl = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACL); |
| 242 | macu = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACU); |
| 243 | |
| 244 | netdev->dev_addr[0] = (macu >> 24) & 0xff; |
| 245 | netdev->dev_addr[1] = (macu >> 16) & 0xff; |
| 246 | netdev->dev_addr[2] = (macu >> 8) & 0xff; |
| 247 | netdev->dev_addr[3] = macu & 0xff; |
| 248 | netdev->dev_addr[4] = (macl >> 8) & 0xff; |
| 249 | netdev->dev_addr[5] = macl & 0xff; |
| 250 | |
| 251 | if (!is_valid_ether_addr(&netdev->dev_addr[0])) |
| 252 | return -EINVAL; |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * spider_net_get_descr_status -- returns the status of a descriptor |
| 259 | * @descr: descriptor to look at |
| 260 | * |
| 261 | * returns the status as in the dmac_cmd_status field of the descriptor |
| 262 | */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 263 | static inline int |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 264 | spider_net_get_descr_status(struct spider_net_descr *descr) |
| 265 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 266 | return descr->dmac_cmd_status & SPIDER_NET_DESCR_IND_PROC_MASK; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /** |
| 270 | * spider_net_free_chain - free descriptor chain |
| 271 | * @card: card structure |
| 272 | * @chain: address of chain |
| 273 | * |
| 274 | */ |
| 275 | static void |
| 276 | spider_net_free_chain(struct spider_net_card *card, |
| 277 | struct spider_net_descr_chain *chain) |
| 278 | { |
| 279 | struct spider_net_descr *descr; |
| 280 | |
| 281 | for (descr = chain->tail; !descr->bus_addr; descr = descr->next) { |
| 282 | pci_unmap_single(card->pdev, descr->bus_addr, |
| 283 | SPIDER_NET_DESCR_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 284 | descr->bus_addr = 0; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * spider_net_init_chain - links descriptor chain |
| 290 | * @card: card structure |
| 291 | * @chain: address of chain |
| 292 | * @start_descr: address of descriptor array |
| 293 | * @no: number of descriptors |
| 294 | * |
| 295 | * we manage a circular list that mirrors the hardware structure, |
| 296 | * except that the hardware uses bus addresses. |
| 297 | * |
| 298 | * returns 0 on success, <0 on failure |
| 299 | */ |
| 300 | static int |
| 301 | spider_net_init_chain(struct spider_net_card *card, |
| 302 | struct spider_net_descr_chain *chain, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 303 | struct spider_net_descr *start_descr, |
| 304 | int direction, int no) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 305 | { |
| 306 | int i; |
| 307 | struct spider_net_descr *descr; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 308 | dma_addr_t buf; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 309 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 310 | descr = start_descr; |
| 311 | memset(descr, 0, sizeof(*descr) * no); |
| 312 | |
| 313 | /* set up the hardware pointers in each descriptor */ |
| 314 | for (i=0; i<no; i++, descr++) { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 315 | descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 316 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 317 | buf = pci_map_single(card->pdev, descr, |
| 318 | SPIDER_NET_DESCR_SIZE, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 319 | direction); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 320 | |
Olof Johansson | d4b0a4c | 2006-09-27 14:02:26 -0500 | [diff] [blame] | 321 | if (pci_dma_mapping_error(buf)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 322 | goto iommu_error; |
| 323 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 324 | descr->bus_addr = buf; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 325 | descr->next = descr + 1; |
| 326 | descr->prev = descr - 1; |
| 327 | |
| 328 | } |
| 329 | /* do actual circular list */ |
| 330 | (descr-1)->next = start_descr; |
| 331 | start_descr->prev = descr-1; |
| 332 | |
| 333 | descr = start_descr; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 334 | if (direction == PCI_DMA_FROMDEVICE) |
| 335 | for (i=0; i < no; i++, descr++) |
| 336 | descr->next_descr_addr = descr->next->bus_addr; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 337 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 338 | spin_lock_init(&chain->lock); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 339 | chain->head = start_descr; |
| 340 | chain->tail = start_descr; |
| 341 | |
| 342 | return 0; |
| 343 | |
| 344 | iommu_error: |
| 345 | descr = start_descr; |
| 346 | for (i=0; i < no; i++, descr++) |
| 347 | if (descr->bus_addr) |
| 348 | pci_unmap_single(card->pdev, descr->bus_addr, |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 349 | SPIDER_NET_DESCR_SIZE, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 350 | direction); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * spider_net_free_rx_chain_contents - frees descr contents in rx chain |
| 356 | * @card: card structure |
| 357 | * |
| 358 | * returns 0 on success, <0 on failure |
| 359 | */ |
| 360 | static void |
| 361 | spider_net_free_rx_chain_contents(struct spider_net_card *card) |
| 362 | { |
| 363 | struct spider_net_descr *descr; |
| 364 | |
| 365 | descr = card->rx_chain.head; |
| 366 | while (descr->next != card->rx_chain.head) { |
| 367 | if (descr->skb) { |
| 368 | dev_kfree_skb(descr->skb); |
| 369 | pci_unmap_single(card->pdev, descr->buf_addr, |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 370 | SPIDER_NET_MAX_FRAME, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 371 | PCI_DMA_FROMDEVICE); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 372 | } |
| 373 | descr = descr->next; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * spider_net_prepare_rx_descr - reinitializes a rx descriptor |
| 379 | * @card: card structure |
| 380 | * @descr: descriptor to re-init |
| 381 | * |
| 382 | * return 0 on succes, <0 on failure |
| 383 | * |
| 384 | * allocates a new rx skb, iommu-maps it and attaches it to the descriptor. |
| 385 | * Activate the descriptor state-wise |
| 386 | */ |
| 387 | static int |
| 388 | spider_net_prepare_rx_descr(struct spider_net_card *card, |
| 389 | struct spider_net_descr *descr) |
| 390 | { |
Arnd Bergmann | 8e0a613 | 2006-01-12 17:16:43 -0500 | [diff] [blame] | 391 | dma_addr_t buf; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 392 | int error = 0; |
| 393 | int offset; |
| 394 | int bufsize; |
| 395 | |
| 396 | /* we need to round up the buffer size to a multiple of 128 */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 397 | bufsize = (SPIDER_NET_MAX_FRAME + SPIDER_NET_RXBUF_ALIGN - 1) & |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 398 | (~(SPIDER_NET_RXBUF_ALIGN - 1)); |
| 399 | |
| 400 | /* and we need to have it 128 byte aligned, therefore we allocate a |
| 401 | * bit more */ |
| 402 | /* allocate an skb */ |
| 403 | descr->skb = dev_alloc_skb(bufsize + SPIDER_NET_RXBUF_ALIGN - 1); |
| 404 | if (!descr->skb) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 405 | if (netif_msg_rx_err(card) && net_ratelimit()) |
| 406 | pr_err("Not enough memory to allocate rx buffer\n"); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 407 | card->spider_stats.alloc_rx_skb_error++; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 408 | return -ENOMEM; |
| 409 | } |
| 410 | descr->buf_size = bufsize; |
| 411 | descr->result_size = 0; |
| 412 | descr->valid_size = 0; |
| 413 | descr->data_status = 0; |
| 414 | descr->data_error = 0; |
| 415 | |
| 416 | offset = ((unsigned long)descr->skb->data) & |
| 417 | (SPIDER_NET_RXBUF_ALIGN - 1); |
| 418 | if (offset) |
| 419 | skb_reserve(descr->skb, SPIDER_NET_RXBUF_ALIGN - offset); |
| 420 | /* io-mmu-map the skb */ |
Arnd Bergmann | 8e0a613 | 2006-01-12 17:16:43 -0500 | [diff] [blame] | 421 | buf = pci_map_single(card->pdev, descr->skb->data, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 422 | SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE); |
Arnd Bergmann | 8e0a613 | 2006-01-12 17:16:43 -0500 | [diff] [blame] | 423 | descr->buf_addr = buf; |
Olof Johansson | d4b0a4c | 2006-09-27 14:02:26 -0500 | [diff] [blame] | 424 | if (pci_dma_mapping_error(buf)) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 425 | dev_kfree_skb_any(descr->skb); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 426 | if (netif_msg_rx_err(card) && net_ratelimit()) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 427 | pr_err("Could not iommu-map rx buffer\n"); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 428 | card->spider_stats.rx_iommu_map_error++; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 429 | descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 430 | } else { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 431 | descr->dmac_cmd_status = SPIDER_NET_DESCR_CARDOWNED | |
| 432 | SPIDER_NET_DMAC_NOINTR_COMPLETE; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | return error; |
| 436 | } |
| 437 | |
| 438 | /** |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 439 | * spider_net_enable_rxchtails - sets RX dmac chain tail addresses |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 440 | * @card: card structure |
| 441 | * |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 442 | * spider_net_enable_rxchtails sets the RX DMAC chain tail adresses in the |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 443 | * chip by writing to the appropriate register. DMA is enabled in |
| 444 | * spider_net_enable_rxdmac. |
| 445 | */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 446 | static inline void |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 447 | spider_net_enable_rxchtails(struct spider_net_card *card) |
| 448 | { |
| 449 | /* assume chain is aligned correctly */ |
| 450 | spider_net_write_reg(card, SPIDER_NET_GDADCHA , |
| 451 | card->rx_chain.tail->bus_addr); |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * spider_net_enable_rxdmac - enables a receive DMA controller |
| 456 | * @card: card structure |
| 457 | * |
| 458 | * spider_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN |
| 459 | * in the GDADMACCNTR register |
| 460 | */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 461 | static inline void |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 462 | spider_net_enable_rxdmac(struct spider_net_card *card) |
| 463 | { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 464 | wmb(); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 465 | spider_net_write_reg(card, SPIDER_NET_GDADMACCNTR, |
| 466 | SPIDER_NET_DMA_RX_VALUE); |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * spider_net_refill_rx_chain - refills descriptors/skbs in the rx chains |
| 471 | * @card: card structure |
| 472 | * |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 473 | * refills descriptors in the rx chain: allocates skbs and iommu-maps them. |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 474 | */ |
| 475 | static void |
| 476 | spider_net_refill_rx_chain(struct spider_net_card *card) |
| 477 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 478 | struct spider_net_descr_chain *chain = &card->rx_chain; |
| 479 | unsigned long flags; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 480 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 481 | /* one context doing the refill (and a second context seeing that |
| 482 | * and omitting it) is ok. If called by NAPI, we'll be called again |
| 483 | * as spider_net_decode_one_descr is called several times. If some |
| 484 | * interrupt calls us, the NAPI is about to clean up anyway. */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 485 | if (!spin_trylock_irqsave(&chain->lock, flags)) |
| 486 | return; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 487 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 488 | while (spider_net_get_descr_status(chain->head) == |
| 489 | SPIDER_NET_DESCR_NOT_IN_USE) { |
| 490 | if (spider_net_prepare_rx_descr(card, chain->head)) |
| 491 | break; |
| 492 | chain->head = chain->head->next; |
| 493 | } |
| 494 | |
| 495 | spin_unlock_irqrestore(&chain->lock, flags); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /** |
| 499 | * spider_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains |
| 500 | * @card: card structure |
| 501 | * |
| 502 | * returns 0 on success, <0 on failure |
| 503 | */ |
| 504 | static int |
| 505 | spider_net_alloc_rx_skbs(struct spider_net_card *card) |
| 506 | { |
| 507 | int result; |
| 508 | struct spider_net_descr_chain *chain; |
| 509 | |
| 510 | result = -ENOMEM; |
| 511 | |
| 512 | chain = &card->rx_chain; |
| 513 | /* put at least one buffer into the chain. if this fails, |
| 514 | * we've got a problem. if not, spider_net_refill_rx_chain |
| 515 | * will do the rest at the end of this function */ |
| 516 | if (spider_net_prepare_rx_descr(card, chain->head)) |
| 517 | goto error; |
| 518 | else |
| 519 | chain->head = chain->head->next; |
| 520 | |
| 521 | /* this will allocate the rest of the rx buffers; if not, it's |
| 522 | * business as usual later on */ |
| 523 | spider_net_refill_rx_chain(card); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 524 | spider_net_enable_rxdmac(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 525 | return 0; |
| 526 | |
| 527 | error: |
| 528 | spider_net_free_rx_chain_contents(card); |
| 529 | return result; |
| 530 | } |
| 531 | |
| 532 | /** |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 533 | * spider_net_get_multicast_hash - generates hash for multicast filter table |
| 534 | * @addr: multicast address |
| 535 | * |
| 536 | * returns the hash value. |
| 537 | * |
| 538 | * spider_net_get_multicast_hash calculates a hash value for a given multicast |
| 539 | * address, that is used to set the multicast filter tables |
| 540 | */ |
| 541 | static u8 |
| 542 | spider_net_get_multicast_hash(struct net_device *netdev, __u8 *addr) |
| 543 | { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 544 | u32 crc; |
| 545 | u8 hash; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 546 | char addr_for_crc[ETH_ALEN] = { 0, }; |
| 547 | int i, bit; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 548 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 549 | for (i = 0; i < ETH_ALEN * 8; i++) { |
| 550 | bit = (addr[i / 8] >> (i % 8)) & 1; |
| 551 | addr_for_crc[ETH_ALEN - 1 - i / 8] += bit << (7 - (i % 8)); |
| 552 | } |
| 553 | |
| 554 | crc = crc32_be(~0, addr_for_crc, netdev->addr_len); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 555 | |
| 556 | hash = (crc >> 27); |
| 557 | hash <<= 3; |
| 558 | hash |= crc & 7; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 559 | hash &= 0xff; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 560 | |
| 561 | return hash; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * spider_net_set_multi - sets multicast addresses and promisc flags |
| 566 | * @netdev: interface device structure |
| 567 | * |
| 568 | * spider_net_set_multi configures multicast addresses as needed for the |
| 569 | * netdev interface. It also sets up multicast, allmulti and promisc |
| 570 | * flags appropriately |
| 571 | */ |
| 572 | static void |
| 573 | spider_net_set_multi(struct net_device *netdev) |
| 574 | { |
| 575 | struct dev_mc_list *mc; |
| 576 | u8 hash; |
| 577 | int i; |
| 578 | u32 reg; |
| 579 | struct spider_net_card *card = netdev_priv(netdev); |
| 580 | unsigned long bitmask[SPIDER_NET_MULTICAST_HASHES / BITS_PER_LONG] = |
| 581 | {0, }; |
| 582 | |
| 583 | spider_net_set_promisc(card); |
| 584 | |
| 585 | if (netdev->flags & IFF_ALLMULTI) { |
| 586 | for (i = 0; i < SPIDER_NET_MULTICAST_HASHES; i++) { |
| 587 | set_bit(i, bitmask); |
| 588 | } |
| 589 | goto write_hash; |
| 590 | } |
| 591 | |
| 592 | /* well, we know, what the broadcast hash value is: it's xfd |
| 593 | hash = spider_net_get_multicast_hash(netdev, netdev->broadcast); */ |
| 594 | set_bit(0xfd, bitmask); |
| 595 | |
| 596 | for (mc = netdev->mc_list; mc; mc = mc->next) { |
| 597 | hash = spider_net_get_multicast_hash(netdev, mc->dmi_addr); |
| 598 | set_bit(hash, bitmask); |
| 599 | } |
| 600 | |
| 601 | write_hash: |
| 602 | for (i = 0; i < SPIDER_NET_MULTICAST_HASHES / 4; i++) { |
| 603 | reg = 0; |
| 604 | if (test_bit(i * 4, bitmask)) |
| 605 | reg += 0x08; |
| 606 | reg <<= 8; |
| 607 | if (test_bit(i * 4 + 1, bitmask)) |
| 608 | reg += 0x08; |
| 609 | reg <<= 8; |
| 610 | if (test_bit(i * 4 + 2, bitmask)) |
| 611 | reg += 0x08; |
| 612 | reg <<= 8; |
| 613 | if (test_bit(i * 4 + 3, bitmask)) |
| 614 | reg += 0x08; |
| 615 | |
| 616 | spider_net_write_reg(card, SPIDER_NET_GMRMHFILnR + i * 4, reg); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | /** |
| 621 | * spider_net_disable_rxdmac - disables the receive DMA controller |
| 622 | * @card: card structure |
| 623 | * |
| 624 | * spider_net_disable_rxdmac terminates processing on the DMA controller by |
| 625 | * turing off DMA and issueing a force end |
| 626 | */ |
| 627 | static void |
| 628 | spider_net_disable_rxdmac(struct spider_net_card *card) |
| 629 | { |
| 630 | spider_net_write_reg(card, SPIDER_NET_GDADMACCNTR, |
| 631 | SPIDER_NET_DMA_RX_FEND_VALUE); |
| 632 | } |
| 633 | |
| 634 | /** |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 635 | * spider_net_prepare_tx_descr - fill tx descriptor with skb data |
| 636 | * @card: card structure |
| 637 | * @descr: descriptor structure to fill out |
| 638 | * @skb: packet to use |
| 639 | * |
| 640 | * returns 0 on success, <0 on failure. |
| 641 | * |
| 642 | * fills out the descriptor structure with skb data and len. Copies data, |
| 643 | * if needed (32bit DMA!) |
| 644 | */ |
| 645 | static int |
| 646 | spider_net_prepare_tx_descr(struct spider_net_card *card, |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 647 | struct sk_buff *skb) |
| 648 | { |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 649 | struct spider_net_descr *descr; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 650 | dma_addr_t buf; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 651 | unsigned long flags; |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 652 | int length; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 653 | |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 654 | length = skb->len; |
| 655 | if (length < ETH_ZLEN) { |
| 656 | if (skb_pad(skb, ETH_ZLEN-length)) |
| 657 | return 0; |
| 658 | length = ETH_ZLEN; |
| 659 | } |
| 660 | |
| 661 | buf = pci_map_single(card->pdev, skb->data, length, PCI_DMA_TODEVICE); |
Olof Johansson | d4b0a4c | 2006-09-27 14:02:26 -0500 | [diff] [blame] | 662 | if (pci_dma_mapping_error(buf)) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 663 | if (netif_msg_tx_err(card) && net_ratelimit()) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 664 | pr_err("could not iommu-map packet (%p, %i). " |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 665 | "Dropping packet\n", skb->data, length); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 666 | card->spider_stats.tx_iommu_map_error++; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 667 | return -ENOMEM; |
| 668 | } |
| 669 | |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 670 | spin_lock_irqsave(&card->tx_chain.lock, flags); |
| 671 | descr = card->tx_chain.head; |
| 672 | card->tx_chain.head = descr->next; |
| 673 | |
Arnd Bergmann | 8e0a613 | 2006-01-12 17:16:43 -0500 | [diff] [blame] | 674 | descr->buf_addr = buf; |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 675 | descr->buf_size = length; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 676 | descr->next_descr_addr = 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 677 | descr->skb = skb; |
| 678 | descr->data_status = 0; |
| 679 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 680 | descr->dmac_cmd_status = |
| 681 | SPIDER_NET_DESCR_CARDOWNED | SPIDER_NET_DMAC_NOCS; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 682 | spin_unlock_irqrestore(&card->tx_chain.lock, flags); |
| 683 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 684 | if (skb->protocol == htons(ETH_P_IP)) |
| 685 | switch (skb->nh.iph->protocol) { |
| 686 | case IPPROTO_TCP: |
| 687 | descr->dmac_cmd_status |= SPIDER_NET_DMAC_TCP; |
| 688 | break; |
| 689 | case IPPROTO_UDP: |
| 690 | descr->dmac_cmd_status |= SPIDER_NET_DMAC_UDP; |
| 691 | break; |
| 692 | } |
| 693 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 694 | /* Chain the bus address, so that the DMA engine finds this descr. */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 695 | descr->prev->next_descr_addr = descr->bus_addr; |
| 696 | |
Linas Vepstas | 917a5b8 | 2006-10-10 16:01:51 -0500 | [diff] [blame] | 697 | card->netdev->trans_start = jiffies; /* set netdev watchdog timer */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 698 | return 0; |
| 699 | } |
| 700 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 701 | static void |
| 702 | spider_net_set_low_watermark(struct spider_net_card *card) |
| 703 | { |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 704 | unsigned long flags; |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 705 | int status; |
| 706 | int cnt=0; |
| 707 | int i; |
| 708 | struct spider_net_descr *descr = card->tx_chain.tail; |
| 709 | |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 710 | /* Measure the length of the queue. Measurement does not |
| 711 | * need to be precise -- does not need a lock. */ |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 712 | while (descr != card->tx_chain.head) { |
| 713 | status = descr->dmac_cmd_status & SPIDER_NET_DESCR_NOT_IN_USE; |
| 714 | if (status == SPIDER_NET_DESCR_NOT_IN_USE) |
| 715 | break; |
| 716 | descr = descr->next; |
| 717 | cnt++; |
| 718 | } |
| 719 | |
| 720 | /* If TX queue is short, don't even bother with interrupts */ |
| 721 | if (cnt < card->tx_desc/4) |
| 722 | return; |
| 723 | |
| 724 | /* Set low-watermark 3/4th's of the way into the queue. */ |
| 725 | descr = card->tx_chain.tail; |
| 726 | cnt = (cnt*3)/4; |
| 727 | for (i=0;i<cnt; i++) |
| 728 | descr = descr->next; |
| 729 | |
| 730 | /* Set the new watermark, clear the old watermark */ |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 731 | spin_lock_irqsave(&card->tx_chain.lock, flags); |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 732 | descr->dmac_cmd_status |= SPIDER_NET_DESCR_TXDESFLG; |
| 733 | if (card->low_watermark && card->low_watermark != descr) |
| 734 | card->low_watermark->dmac_cmd_status = |
| 735 | card->low_watermark->dmac_cmd_status & ~SPIDER_NET_DESCR_TXDESFLG; |
| 736 | card->low_watermark = descr; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 737 | spin_unlock_irqrestore(&card->tx_chain.lock, flags); |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 738 | } |
| 739 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 740 | /** |
| 741 | * spider_net_release_tx_chain - processes sent tx descriptors |
| 742 | * @card: adapter structure |
| 743 | * @brutal: if set, don't care about whether descriptor seems to be in use |
| 744 | * |
| 745 | * returns 0 if the tx ring is empty, otherwise 1. |
| 746 | * |
| 747 | * spider_net_release_tx_chain releases the tx descriptors that spider has |
| 748 | * finished with (if non-brutal) or simply release tx descriptors (if brutal). |
| 749 | * If some other context is calling this function, we return 1 so that we're |
| 750 | * scheduled again (if we were scheduled) and will not loose initiative. |
| 751 | */ |
| 752 | static int |
| 753 | spider_net_release_tx_chain(struct spider_net_card *card, int brutal) |
| 754 | { |
| 755 | struct spider_net_descr_chain *chain = &card->tx_chain; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 756 | struct spider_net_descr *descr; |
| 757 | struct sk_buff *skb; |
| 758 | u32 buf_addr; |
| 759 | unsigned long flags; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 760 | int status; |
| 761 | |
| 762 | spider_net_read_reg(card, SPIDER_NET_GDTDMACCNTR); |
| 763 | |
| 764 | while (chain->tail != chain->head) { |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 765 | spin_lock_irqsave(&chain->lock, flags); |
| 766 | descr = chain->tail; |
| 767 | |
| 768 | status = spider_net_get_descr_status(descr); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 769 | switch (status) { |
| 770 | case SPIDER_NET_DESCR_COMPLETE: |
| 771 | card->netdev_stats.tx_packets++; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 772 | card->netdev_stats.tx_bytes += descr->skb->len; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 773 | break; |
| 774 | |
| 775 | case SPIDER_NET_DESCR_CARDOWNED: |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 776 | if (!brutal) { |
| 777 | spin_unlock_irqrestore(&chain->lock, flags); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 778 | return 1; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 779 | } |
| 780 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 781 | /* fallthrough, if we release the descriptors |
| 782 | * brutally (then we don't care about |
| 783 | * SPIDER_NET_DESCR_CARDOWNED) */ |
| 784 | |
| 785 | case SPIDER_NET_DESCR_RESPONSE_ERROR: |
| 786 | case SPIDER_NET_DESCR_PROTECTION_ERROR: |
| 787 | case SPIDER_NET_DESCR_FORCE_END: |
| 788 | if (netif_msg_tx_err(card)) |
| 789 | pr_err("%s: forcing end of tx descriptor " |
| 790 | "with status x%02x\n", |
| 791 | card->netdev->name, status); |
| 792 | card->netdev_stats.tx_errors++; |
| 793 | break; |
| 794 | |
| 795 | default: |
| 796 | card->netdev_stats.tx_dropped++; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 797 | if (!brutal) { |
| 798 | spin_unlock_irqrestore(&chain->lock, flags); |
Linas Vepstas | c3fee4c | 2006-10-10 16:00:04 -0500 | [diff] [blame] | 799 | return 1; |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 800 | } |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 801 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 802 | |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 803 | chain->tail = descr->next; |
| 804 | descr->dmac_cmd_status |= SPIDER_NET_DESCR_NOT_IN_USE; |
| 805 | skb = descr->skb; |
| 806 | buf_addr = descr->buf_addr; |
| 807 | spin_unlock_irqrestore(&chain->lock, flags); |
| 808 | |
| 809 | /* unmap the skb */ |
| 810 | if (skb) { |
| 811 | int len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len; |
| 812 | pci_unmap_single(card->pdev, buf_addr, len, PCI_DMA_TODEVICE); |
| 813 | dev_kfree_skb(skb); |
| 814 | } |
| 815 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * spider_net_kick_tx_dma - enables TX DMA processing |
| 821 | * @card: card structure |
| 822 | * @descr: descriptor address to enable TX processing at |
| 823 | * |
| 824 | * spider_net_kick_tx_dma writes the current tx chain head as start address |
| 825 | * of the tx descriptor chain and enables the transmission DMA engine |
| 826 | */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 827 | static inline void |
| 828 | spider_net_kick_tx_dma(struct spider_net_card *card) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 829 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 830 | struct spider_net_descr *descr; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 831 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 832 | if (spider_net_read_reg(card, SPIDER_NET_GDTDMACCNTR) & |
| 833 | SPIDER_NET_TX_DMA_EN) |
| 834 | goto out; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 835 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 836 | descr = card->tx_chain.tail; |
| 837 | for (;;) { |
| 838 | if (spider_net_get_descr_status(descr) == |
| 839 | SPIDER_NET_DESCR_CARDOWNED) { |
| 840 | spider_net_write_reg(card, SPIDER_NET_GDTDCHA, |
| 841 | descr->bus_addr); |
| 842 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, |
| 843 | SPIDER_NET_DMA_TX_VALUE); |
| 844 | break; |
| 845 | } |
| 846 | if (descr == card->tx_chain.head) |
| 847 | break; |
| 848 | descr = descr->next; |
| 849 | } |
| 850 | |
| 851 | out: |
| 852 | mod_timer(&card->tx_timer, jiffies + SPIDER_NET_TX_TIMER); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /** |
| 856 | * spider_net_xmit - transmits a frame over the device |
| 857 | * @skb: packet to send out |
| 858 | * @netdev: interface device structure |
| 859 | * |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 860 | * returns 0 on success, !0 on failure |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 861 | */ |
| 862 | static int |
| 863 | spider_net_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 864 | { |
| 865 | struct spider_net_card *card = netdev_priv(netdev); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 866 | struct spider_net_descr_chain *chain = &card->tx_chain; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 867 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 868 | spider_net_release_tx_chain(card, 0); |
| 869 | |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 870 | if ((chain->head->next == chain->tail->prev) || |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 871 | (spider_net_prepare_tx_descr(card, skb) != 0)) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 872 | |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 873 | card->netdev_stats.tx_dropped++; |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 874 | netif_stop_queue(netdev); |
| 875 | return NETDEV_TX_BUSY; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 876 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 877 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 878 | spider_net_set_low_watermark(card); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 879 | spider_net_kick_tx_dma(card); |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 880 | return NETDEV_TX_OK; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | /** |
| 884 | * spider_net_cleanup_tx_ring - cleans up the TX ring |
| 885 | * @card: card structure |
| 886 | * |
Linas Vepstas | 68a8c60 | 2006-10-10 16:13:05 -0500 | [diff] [blame] | 887 | * spider_net_cleanup_tx_ring is called by either the tx_timer |
| 888 | * or from the NAPI polling routine. |
| 889 | * This routine releases resources associted with transmitted |
| 890 | * packets, including updating the queue tail pointer. |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 891 | */ |
| 892 | static void |
| 893 | spider_net_cleanup_tx_ring(struct spider_net_card *card) |
| 894 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 895 | if ((spider_net_release_tx_chain(card, 0) != 0) && |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 896 | (card->netdev->flags & IFF_UP)) { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 897 | spider_net_kick_tx_dma(card); |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 898 | netif_wake_queue(card->netdev); |
| 899 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** |
| 903 | * spider_net_do_ioctl - called for device ioctls |
| 904 | * @netdev: interface device structure |
| 905 | * @ifr: request parameter structure for ioctl |
| 906 | * @cmd: command code for ioctl |
| 907 | * |
| 908 | * returns 0 on success, <0 on failure. Currently, we have no special ioctls. |
| 909 | * -EOPNOTSUPP is returned, if an unknown ioctl was requested |
| 910 | */ |
| 911 | static int |
| 912 | spider_net_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 913 | { |
| 914 | switch (cmd) { |
| 915 | default: |
| 916 | return -EOPNOTSUPP; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on |
| 922 | * @descr: descriptor to process |
| 923 | * @card: card structure |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 924 | * @napi: whether caller is in NAPI context |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 925 | * |
| 926 | * returns 1 on success, 0 if no packet was passed to the stack |
| 927 | * |
| 928 | * iommu-unmaps the skb, fills out skb structure and passes the data to the |
| 929 | * stack. The descriptor state is not changed. |
| 930 | */ |
| 931 | static int |
| 932 | spider_net_pass_skb_up(struct spider_net_descr *descr, |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 933 | struct spider_net_card *card, int napi) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 934 | { |
| 935 | struct sk_buff *skb; |
| 936 | struct net_device *netdev; |
| 937 | u32 data_status, data_error; |
| 938 | |
| 939 | data_status = descr->data_status; |
| 940 | data_error = descr->data_error; |
| 941 | |
| 942 | netdev = card->netdev; |
| 943 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 944 | /* unmap descriptor */ |
| 945 | pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_FRAME, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 946 | PCI_DMA_FROMDEVICE); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 947 | |
| 948 | /* the cases we'll throw away the packet immediately */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 949 | if (data_error & SPIDER_NET_DESTROY_RX_FLAGS) { |
| 950 | if (netif_msg_rx_err(card)) |
| 951 | pr_err("error in received descriptor found, " |
| 952 | "data_status=x%08x, data_error=x%08x\n", |
| 953 | data_status, data_error); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 954 | card->spider_stats.rx_desc_error++; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 955 | return 0; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 956 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 957 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 958 | skb = descr->skb; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 959 | skb->dev = netdev; |
| 960 | skb_put(skb, descr->valid_size); |
| 961 | |
| 962 | /* the card seems to add 2 bytes of junk in front |
| 963 | * of the ethernet frame */ |
| 964 | #define SPIDER_MISALIGN 2 |
| 965 | skb_pull(skb, SPIDER_MISALIGN); |
| 966 | skb->protocol = eth_type_trans(skb, netdev); |
| 967 | |
| 968 | /* checksum offload */ |
| 969 | if (card->options.rx_csum) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 970 | if ( ( (data_status & SPIDER_NET_DATA_STATUS_CKSUM_MASK) == |
| 971 | SPIDER_NET_DATA_STATUS_CKSUM_MASK) && |
| 972 | !(data_error & SPIDER_NET_DATA_ERR_CKSUM_MASK)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 973 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 974 | else |
| 975 | skb->ip_summed = CHECKSUM_NONE; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 976 | } else |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 977 | skb->ip_summed = CHECKSUM_NONE; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 978 | |
| 979 | if (data_status & SPIDER_NET_VLAN_PACKET) { |
| 980 | /* further enhancements: HW-accel VLAN |
| 981 | * vlan_hwaccel_receive_skb |
| 982 | */ |
| 983 | } |
| 984 | |
| 985 | /* pass skb up to stack */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 986 | if (napi) |
| 987 | netif_receive_skb(skb); |
| 988 | else |
| 989 | netif_rx_ni(skb); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 990 | |
| 991 | /* update netdevice statistics */ |
| 992 | card->netdev_stats.rx_packets++; |
| 993 | card->netdev_stats.rx_bytes += skb->len; |
| 994 | |
| 995 | return 1; |
| 996 | } |
| 997 | |
| 998 | /** |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 999 | * spider_net_decode_one_descr - processes an rx descriptor |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1000 | * @card: card structure |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1001 | * @napi: whether caller is in NAPI context |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1002 | * |
| 1003 | * returns 1 if a packet has been sent to the stack, otherwise 0 |
| 1004 | * |
| 1005 | * processes an rx descriptor by iommu-unmapping the data buffer and passing |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1006 | * the packet up to the stack. This function is called in softirq |
| 1007 | * context, e.g. either bottom half from interrupt or NAPI polling context |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1008 | */ |
| 1009 | static int |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1010 | spider_net_decode_one_descr(struct spider_net_card *card, int napi) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1011 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1012 | struct spider_net_descr_chain *chain = &card->rx_chain; |
| 1013 | struct spider_net_descr *descr = chain->tail; |
| 1014 | int status; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1015 | int result; |
| 1016 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1017 | status = spider_net_get_descr_status(descr); |
| 1018 | |
| 1019 | if (status == SPIDER_NET_DESCR_CARDOWNED) { |
| 1020 | /* nothing in the descriptor yet */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1021 | result=0; |
| 1022 | goto out; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | if (status == SPIDER_NET_DESCR_NOT_IN_USE) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1026 | /* not initialized yet, the ring must be empty */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1027 | spider_net_refill_rx_chain(card); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1028 | spider_net_enable_rxdmac(card); |
| 1029 | result=0; |
| 1030 | goto out; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1033 | /* descriptor definitively used -- move on tail */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1034 | chain->tail = descr->next; |
| 1035 | |
| 1036 | result = 0; |
| 1037 | if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) || |
| 1038 | (status == SPIDER_NET_DESCR_PROTECTION_ERROR) || |
| 1039 | (status == SPIDER_NET_DESCR_FORCE_END) ) { |
| 1040 | if (netif_msg_rx_err(card)) |
| 1041 | pr_err("%s: dropping RX descriptor with state %d\n", |
| 1042 | card->netdev->name, status); |
| 1043 | card->netdev_stats.rx_dropped++; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1044 | pci_unmap_single(card->pdev, descr->buf_addr, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1045 | SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1046 | dev_kfree_skb_irq(descr->skb); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1047 | goto refill; |
| 1048 | } |
| 1049 | |
| 1050 | if ( (status != SPIDER_NET_DESCR_COMPLETE) && |
| 1051 | (status != SPIDER_NET_DESCR_FRAME_END) ) { |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 1052 | if (netif_msg_rx_err(card)) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1053 | pr_err("%s: RX descriptor with state %d\n", |
| 1054 | card->netdev->name, status); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 1055 | card->spider_stats.rx_desc_unk_state++; |
| 1056 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1057 | goto refill; |
| 1058 | } |
| 1059 | |
| 1060 | /* ok, we've got a packet in descr */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1061 | result = spider_net_pass_skb_up(descr, card, napi); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1062 | refill: |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1063 | descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1064 | /* change the descriptor state: */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1065 | if (!napi) |
| 1066 | spider_net_refill_rx_chain(card); |
| 1067 | out: |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1068 | return result; |
| 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * spider_net_poll - NAPI poll function called by the stack to return packets |
| 1073 | * @netdev: interface device structure |
| 1074 | * @budget: number of packets we can pass to the stack at most |
| 1075 | * |
| 1076 | * returns 0 if no more packets available to the driver/stack. Returns 1, |
| 1077 | * if the quota is exceeded, but the driver has still packets. |
| 1078 | * |
| 1079 | * spider_net_poll returns all packets from the rx descriptors to the stack |
| 1080 | * (using netif_receive_skb). If all/enough packets are up, the driver |
| 1081 | * reenables interrupts and returns 0. If not, 1 is returned. |
| 1082 | */ |
| 1083 | static int |
| 1084 | spider_net_poll(struct net_device *netdev, int *budget) |
| 1085 | { |
| 1086 | struct spider_net_card *card = netdev_priv(netdev); |
| 1087 | int packets_to_do, packets_done = 0; |
| 1088 | int no_more_packets = 0; |
| 1089 | |
Linas Vepstas | 68a8c60 | 2006-10-10 16:13:05 -0500 | [diff] [blame] | 1090 | spider_net_cleanup_tx_ring(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1091 | packets_to_do = min(*budget, netdev->quota); |
| 1092 | |
| 1093 | while (packets_to_do) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1094 | if (spider_net_decode_one_descr(card, 1)) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1095 | packets_done++; |
| 1096 | packets_to_do--; |
| 1097 | } else { |
| 1098 | /* no more packets for the stack */ |
| 1099 | no_more_packets = 1; |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | netdev->quota -= packets_done; |
| 1105 | *budget -= packets_done; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1106 | spider_net_refill_rx_chain(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1107 | |
| 1108 | /* if all packets are in the stack, enable interrupts and return 0 */ |
| 1109 | /* if not, return 1 */ |
| 1110 | if (no_more_packets) { |
| 1111 | netif_rx_complete(netdev); |
| 1112 | spider_net_rx_irq_on(card); |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | return 1; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * spider_net_vlan_rx_reg - initializes VLAN structures in the driver and card |
| 1121 | * @netdev: interface device structure |
| 1122 | * @grp: vlan_group structure that is registered (NULL on destroying interface) |
| 1123 | */ |
| 1124 | static void |
| 1125 | spider_net_vlan_rx_reg(struct net_device *netdev, struct vlan_group *grp) |
| 1126 | { |
| 1127 | /* further enhancement... yet to do */ |
| 1128 | return; |
| 1129 | } |
| 1130 | |
| 1131 | /** |
| 1132 | * spider_net_vlan_rx_add - adds VLAN id to the card filter |
| 1133 | * @netdev: interface device structure |
| 1134 | * @vid: VLAN id to add |
| 1135 | */ |
| 1136 | static void |
| 1137 | spider_net_vlan_rx_add(struct net_device *netdev, uint16_t vid) |
| 1138 | { |
| 1139 | /* further enhancement... yet to do */ |
| 1140 | /* add vid to card's VLAN filter table */ |
| 1141 | return; |
| 1142 | } |
| 1143 | |
| 1144 | /** |
| 1145 | * spider_net_vlan_rx_kill - removes VLAN id to the card filter |
| 1146 | * @netdev: interface device structure |
| 1147 | * @vid: VLAN id to remove |
| 1148 | */ |
| 1149 | static void |
| 1150 | spider_net_vlan_rx_kill(struct net_device *netdev, uint16_t vid) |
| 1151 | { |
| 1152 | /* further enhancement... yet to do */ |
| 1153 | /* remove vid from card's VLAN filter table */ |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * spider_net_get_stats - get interface statistics |
| 1158 | * @netdev: interface device structure |
| 1159 | * |
| 1160 | * returns the interface statistics residing in the spider_net_card struct |
| 1161 | */ |
| 1162 | static struct net_device_stats * |
| 1163 | spider_net_get_stats(struct net_device *netdev) |
| 1164 | { |
| 1165 | struct spider_net_card *card = netdev_priv(netdev); |
| 1166 | struct net_device_stats *stats = &card->netdev_stats; |
| 1167 | return stats; |
| 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * spider_net_change_mtu - changes the MTU of an interface |
| 1172 | * @netdev: interface device structure |
| 1173 | * @new_mtu: new MTU value |
| 1174 | * |
| 1175 | * returns 0 on success, <0 on failure |
| 1176 | */ |
| 1177 | static int |
| 1178 | spider_net_change_mtu(struct net_device *netdev, int new_mtu) |
| 1179 | { |
| 1180 | /* no need to re-alloc skbs or so -- the max mtu is about 2.3k |
| 1181 | * and mtu is outbound only anyway */ |
| 1182 | if ( (new_mtu < SPIDER_NET_MIN_MTU ) || |
| 1183 | (new_mtu > SPIDER_NET_MAX_MTU) ) |
| 1184 | return -EINVAL; |
| 1185 | netdev->mtu = new_mtu; |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * spider_net_set_mac - sets the MAC of an interface |
| 1191 | * @netdev: interface device structure |
| 1192 | * @ptr: pointer to new MAC address |
| 1193 | * |
| 1194 | * Returns 0 on success, <0 on failure. Currently, we don't support this |
| 1195 | * and will always return EOPNOTSUPP. |
| 1196 | */ |
| 1197 | static int |
| 1198 | spider_net_set_mac(struct net_device *netdev, void *p) |
| 1199 | { |
| 1200 | struct spider_net_card *card = netdev_priv(netdev); |
Jens Osterkamp | 054034d | 2005-09-06 19:30:55 -0700 | [diff] [blame] | 1201 | u32 macl, macu, regvalue; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1202 | struct sockaddr *addr = p; |
| 1203 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1204 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1205 | return -EADDRNOTAVAIL; |
| 1206 | |
Jens Osterkamp | 054034d | 2005-09-06 19:30:55 -0700 | [diff] [blame] | 1207 | /* switch off GMACTPE and GMACRPE */ |
| 1208 | regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD); |
| 1209 | regvalue &= ~((1 << 5) | (1 << 6)); |
| 1210 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); |
| 1211 | |
| 1212 | /* write mac */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1213 | macu = (addr->sa_data[0]<<24) + (addr->sa_data[1]<<16) + |
| 1214 | (addr->sa_data[2]<<8) + (addr->sa_data[3]); |
| 1215 | macl = (addr->sa_data[4]<<8) + (addr->sa_data[5]); |
| 1216 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACU, macu); |
| 1217 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACL, macl); |
| 1218 | |
Jens Osterkamp | 054034d | 2005-09-06 19:30:55 -0700 | [diff] [blame] | 1219 | /* switch GMACTPE and GMACRPE back on */ |
| 1220 | regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD); |
| 1221 | regvalue |= ((1 << 5) | (1 << 6)); |
| 1222 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); |
| 1223 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1224 | spider_net_set_promisc(card); |
| 1225 | |
| 1226 | /* look up, whether we have been successful */ |
| 1227 | if (spider_net_get_mac_address(netdev)) |
| 1228 | return -EADDRNOTAVAIL; |
| 1229 | if (memcmp(netdev->dev_addr,addr->sa_data,netdev->addr_len)) |
| 1230 | return -EADDRNOTAVAIL; |
| 1231 | |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
| 1235 | /** |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1236 | * spider_net_handle_rxram_full - cleans up RX ring upon RX RAM full interrupt |
| 1237 | * @card: card structure |
| 1238 | * |
| 1239 | * spider_net_handle_rxram_full empties the RX ring so that spider can put |
| 1240 | * more packets in it and empty its RX RAM. This is called in bottom half |
| 1241 | * context |
| 1242 | */ |
| 1243 | static void |
| 1244 | spider_net_handle_rxram_full(struct spider_net_card *card) |
| 1245 | { |
| 1246 | while (spider_net_decode_one_descr(card, 0)) |
| 1247 | ; |
| 1248 | spider_net_enable_rxchtails(card); |
| 1249 | spider_net_enable_rxdmac(card); |
| 1250 | netif_rx_schedule(card->netdev); |
| 1251 | } |
| 1252 | |
| 1253 | /** |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1254 | * spider_net_handle_error_irq - handles errors raised by an interrupt |
| 1255 | * @card: card structure |
| 1256 | * @status_reg: interrupt status register 0 (GHIINT0STS) |
| 1257 | * |
| 1258 | * spider_net_handle_error_irq treats or ignores all error conditions |
| 1259 | * found when an interrupt is presented |
| 1260 | */ |
| 1261 | static void |
| 1262 | spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg) |
| 1263 | { |
| 1264 | u32 error_reg1, error_reg2; |
| 1265 | u32 i; |
| 1266 | int show_error = 1; |
| 1267 | |
| 1268 | error_reg1 = spider_net_read_reg(card, SPIDER_NET_GHIINT1STS); |
| 1269 | error_reg2 = spider_net_read_reg(card, SPIDER_NET_GHIINT2STS); |
| 1270 | |
| 1271 | /* check GHIINT0STS ************************************/ |
| 1272 | if (status_reg) |
| 1273 | for (i = 0; i < 32; i++) |
| 1274 | if (status_reg & (1<<i)) |
| 1275 | switch (i) |
| 1276 | { |
| 1277 | /* let error_reg1 and error_reg2 evaluation decide, what to do |
| 1278 | case SPIDER_NET_PHYINT: |
| 1279 | case SPIDER_NET_GMAC2INT: |
| 1280 | case SPIDER_NET_GMAC1INT: |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1281 | case SPIDER_NET_GFIFOINT: |
| 1282 | case SPIDER_NET_DMACINT: |
| 1283 | case SPIDER_NET_GSYSINT: |
| 1284 | break; */ |
| 1285 | |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1286 | case SPIDER_NET_GIPSINT: |
| 1287 | show_error = 0; |
| 1288 | break; |
| 1289 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1290 | case SPIDER_NET_GPWOPCMPINT: |
| 1291 | /* PHY write operation completed */ |
| 1292 | show_error = 0; |
| 1293 | break; |
| 1294 | case SPIDER_NET_GPROPCMPINT: |
| 1295 | /* PHY read operation completed */ |
| 1296 | /* we don't use semaphores, as we poll for the completion |
| 1297 | * of the read operation in spider_net_read_phy. Should take |
| 1298 | * about 50 us */ |
| 1299 | show_error = 0; |
| 1300 | break; |
| 1301 | case SPIDER_NET_GPWFFINT: |
| 1302 | /* PHY command queue full */ |
| 1303 | if (netif_msg_intr(card)) |
| 1304 | pr_err("PHY write queue full\n"); |
| 1305 | show_error = 0; |
| 1306 | break; |
| 1307 | |
| 1308 | /* case SPIDER_NET_GRMDADRINT: not used. print a message */ |
| 1309 | /* case SPIDER_NET_GRMARPINT: not used. print a message */ |
| 1310 | /* case SPIDER_NET_GRMMPINT: not used. print a message */ |
| 1311 | |
| 1312 | case SPIDER_NET_GDTDEN0INT: |
| 1313 | /* someone has set TX_DMA_EN to 0 */ |
| 1314 | show_error = 0; |
| 1315 | break; |
| 1316 | |
| 1317 | case SPIDER_NET_GDDDEN0INT: /* fallthrough */ |
| 1318 | case SPIDER_NET_GDCDEN0INT: /* fallthrough */ |
| 1319 | case SPIDER_NET_GDBDEN0INT: /* fallthrough */ |
| 1320 | case SPIDER_NET_GDADEN0INT: |
| 1321 | /* someone has set RX_DMA_EN to 0 */ |
| 1322 | show_error = 0; |
| 1323 | break; |
| 1324 | |
| 1325 | /* RX interrupts */ |
| 1326 | case SPIDER_NET_GDDFDCINT: |
| 1327 | case SPIDER_NET_GDCFDCINT: |
| 1328 | case SPIDER_NET_GDBFDCINT: |
| 1329 | case SPIDER_NET_GDAFDCINT: |
| 1330 | /* case SPIDER_NET_GDNMINT: not used. print a message */ |
| 1331 | /* case SPIDER_NET_GCNMINT: not used. print a message */ |
| 1332 | /* case SPIDER_NET_GBNMINT: not used. print a message */ |
| 1333 | /* case SPIDER_NET_GANMINT: not used. print a message */ |
| 1334 | /* case SPIDER_NET_GRFNMINT: not used. print a message */ |
| 1335 | show_error = 0; |
| 1336 | break; |
| 1337 | |
| 1338 | /* TX interrupts */ |
| 1339 | case SPIDER_NET_GDTFDCINT: |
| 1340 | show_error = 0; |
| 1341 | break; |
| 1342 | case SPIDER_NET_GTTEDINT: |
| 1343 | show_error = 0; |
| 1344 | break; |
| 1345 | case SPIDER_NET_GDTDCEINT: |
| 1346 | /* chain end. If a descriptor should be sent, kick off |
| 1347 | * tx dma |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1348 | if (card->tx_chain.tail != card->tx_chain.head) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1349 | spider_net_kick_tx_dma(card); |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1350 | */ |
| 1351 | show_error = 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1352 | break; |
| 1353 | |
| 1354 | /* case SPIDER_NET_G1TMCNTINT: not used. print a message */ |
| 1355 | /* case SPIDER_NET_GFREECNTINT: not used. print a message */ |
| 1356 | } |
| 1357 | |
| 1358 | /* check GHIINT1STS ************************************/ |
| 1359 | if (error_reg1) |
| 1360 | for (i = 0; i < 32; i++) |
| 1361 | if (error_reg1 & (1<<i)) |
| 1362 | switch (i) |
| 1363 | { |
| 1364 | case SPIDER_NET_GTMFLLINT: |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1365 | if (netif_msg_intr(card) && net_ratelimit()) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1366 | pr_err("Spider TX RAM full\n"); |
| 1367 | show_error = 0; |
| 1368 | break; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1369 | case SPIDER_NET_GRFDFLLINT: /* fallthrough */ |
| 1370 | case SPIDER_NET_GRFCFLLINT: /* fallthrough */ |
| 1371 | case SPIDER_NET_GRFBFLLINT: /* fallthrough */ |
| 1372 | case SPIDER_NET_GRFAFLLINT: /* fallthrough */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1373 | case SPIDER_NET_GRMFLLINT: |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1374 | if (netif_msg_intr(card) && net_ratelimit()) |
Jens Osterkamp | 4e5077b | 2006-03-28 15:59:55 +0200 | [diff] [blame] | 1375 | pr_debug("Spider RX RAM full, incoming packets " |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1376 | "might be discarded!\n"); |
| 1377 | spider_net_rx_irq_off(card); |
| 1378 | tasklet_schedule(&card->rxram_full_tl); |
| 1379 | show_error = 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1380 | break; |
| 1381 | |
| 1382 | /* case SPIDER_NET_GTMSHTINT: problem, print a message */ |
| 1383 | case SPIDER_NET_GDTINVDINT: |
| 1384 | /* allrighty. tx from previous descr ok */ |
| 1385 | show_error = 0; |
| 1386 | break; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1387 | |
| 1388 | /* chain end */ |
| 1389 | case SPIDER_NET_GDDDCEINT: /* fallthrough */ |
| 1390 | case SPIDER_NET_GDCDCEINT: /* fallthrough */ |
| 1391 | case SPIDER_NET_GDBDCEINT: /* fallthrough */ |
| 1392 | case SPIDER_NET_GDADCEINT: |
| 1393 | if (netif_msg_intr(card)) |
| 1394 | pr_err("got descriptor chain end interrupt, " |
| 1395 | "restarting DMAC %c.\n", |
Linas Vepstas | 37aad75 | 2006-10-10 16:06:53 -0500 | [diff] [blame] | 1396 | 'D'-(i-SPIDER_NET_GDDDCEINT)/3); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1397 | spider_net_refill_rx_chain(card); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1398 | spider_net_enable_rxdmac(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1399 | show_error = 0; |
| 1400 | break; |
| 1401 | |
| 1402 | /* invalid descriptor */ |
| 1403 | case SPIDER_NET_GDDINVDINT: /* fallthrough */ |
| 1404 | case SPIDER_NET_GDCINVDINT: /* fallthrough */ |
| 1405 | case SPIDER_NET_GDBINVDINT: /* fallthrough */ |
| 1406 | case SPIDER_NET_GDAINVDINT: |
| 1407 | /* could happen when rx chain is full */ |
| 1408 | spider_net_refill_rx_chain(card); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1409 | spider_net_enable_rxdmac(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1410 | show_error = 0; |
| 1411 | break; |
| 1412 | |
| 1413 | /* case SPIDER_NET_GDTRSERINT: problem, print a message */ |
| 1414 | /* case SPIDER_NET_GDDRSERINT: problem, print a message */ |
| 1415 | /* case SPIDER_NET_GDCRSERINT: problem, print a message */ |
| 1416 | /* case SPIDER_NET_GDBRSERINT: problem, print a message */ |
| 1417 | /* case SPIDER_NET_GDARSERINT: problem, print a message */ |
| 1418 | /* case SPIDER_NET_GDSERINT: problem, print a message */ |
| 1419 | /* case SPIDER_NET_GDTPTERINT: problem, print a message */ |
| 1420 | /* case SPIDER_NET_GDDPTERINT: problem, print a message */ |
| 1421 | /* case SPIDER_NET_GDCPTERINT: problem, print a message */ |
| 1422 | /* case SPIDER_NET_GDBPTERINT: problem, print a message */ |
| 1423 | /* case SPIDER_NET_GDAPTERINT: problem, print a message */ |
| 1424 | default: |
| 1425 | show_error = 1; |
| 1426 | break; |
| 1427 | } |
| 1428 | |
| 1429 | /* check GHIINT2STS ************************************/ |
| 1430 | if (error_reg2) |
| 1431 | for (i = 0; i < 32; i++) |
| 1432 | if (error_reg2 & (1<<i)) |
| 1433 | switch (i) |
| 1434 | { |
| 1435 | /* there is nothing we can (want to) do at this time. Log a |
| 1436 | * message, we can switch on and off the specific values later on |
| 1437 | case SPIDER_NET_GPROPERINT: |
| 1438 | case SPIDER_NET_GMCTCRSNGINT: |
| 1439 | case SPIDER_NET_GMCTLCOLINT: |
| 1440 | case SPIDER_NET_GMCTTMOTINT: |
| 1441 | case SPIDER_NET_GMCRCAERINT: |
| 1442 | case SPIDER_NET_GMCRCALERINT: |
| 1443 | case SPIDER_NET_GMCRALNERINT: |
| 1444 | case SPIDER_NET_GMCROVRINT: |
| 1445 | case SPIDER_NET_GMCRRNTINT: |
| 1446 | case SPIDER_NET_GMCRRXERINT: |
| 1447 | case SPIDER_NET_GTITCSERINT: |
| 1448 | case SPIDER_NET_GTIFMTERINT: |
| 1449 | case SPIDER_NET_GTIPKTRVKINT: |
| 1450 | case SPIDER_NET_GTISPINGINT: |
| 1451 | case SPIDER_NET_GTISADNGINT: |
| 1452 | case SPIDER_NET_GTISPDNGINT: |
| 1453 | case SPIDER_NET_GRIFMTERINT: |
| 1454 | case SPIDER_NET_GRIPKTRVKINT: |
| 1455 | case SPIDER_NET_GRISPINGINT: |
| 1456 | case SPIDER_NET_GRISADNGINT: |
| 1457 | case SPIDER_NET_GRISPDNGINT: |
| 1458 | break; |
| 1459 | */ |
| 1460 | default: |
| 1461 | break; |
| 1462 | } |
| 1463 | |
| 1464 | if ((show_error) && (netif_msg_intr(card))) |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1465 | pr_err("Got error interrupt on %s, GHIINT0STS = 0x%08x, " |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1466 | "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n", |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1467 | card->netdev->name, |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1468 | status_reg, error_reg1, error_reg2); |
| 1469 | |
| 1470 | /* clear interrupt sources */ |
| 1471 | spider_net_write_reg(card, SPIDER_NET_GHIINT1STS, error_reg1); |
| 1472 | spider_net_write_reg(card, SPIDER_NET_GHIINT2STS, error_reg2); |
| 1473 | } |
| 1474 | |
| 1475 | /** |
| 1476 | * spider_net_interrupt - interrupt handler for spider_net |
| 1477 | * @irq: interupt number |
| 1478 | * @ptr: pointer to net_device |
| 1479 | * @regs: PU registers |
| 1480 | * |
| 1481 | * returns IRQ_HANDLED, if interrupt was for driver, or IRQ_NONE, if no |
| 1482 | * interrupt found raised by card. |
| 1483 | * |
| 1484 | * This is the interrupt handler, that turns off |
| 1485 | * interrupts for this device and makes the stack poll the driver |
| 1486 | */ |
| 1487 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1488 | spider_net_interrupt(int irq, void *ptr) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1489 | { |
| 1490 | struct net_device *netdev = ptr; |
| 1491 | struct spider_net_card *card = netdev_priv(netdev); |
| 1492 | u32 status_reg; |
| 1493 | |
| 1494 | status_reg = spider_net_read_reg(card, SPIDER_NET_GHIINT0STS); |
| 1495 | |
| 1496 | if (!status_reg) |
| 1497 | return IRQ_NONE; |
| 1498 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1499 | if (status_reg & SPIDER_NET_RXINT ) { |
| 1500 | spider_net_rx_irq_off(card); |
| 1501 | netif_rx_schedule(netdev); |
| 1502 | } |
Linas Vepstas | 68a8c60 | 2006-10-10 16:13:05 -0500 | [diff] [blame] | 1503 | if (status_reg & SPIDER_NET_TXINT) |
| 1504 | netif_rx_schedule(netdev); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1505 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1506 | if (status_reg & SPIDER_NET_ERRINT ) |
| 1507 | spider_net_handle_error_irq(card, status_reg); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1508 | |
| 1509 | /* clear interrupt sources */ |
| 1510 | spider_net_write_reg(card, SPIDER_NET_GHIINT0STS, status_reg); |
| 1511 | |
| 1512 | return IRQ_HANDLED; |
| 1513 | } |
| 1514 | |
| 1515 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1516 | /** |
| 1517 | * spider_net_poll_controller - artificial interrupt for netconsole etc. |
| 1518 | * @netdev: interface device structure |
| 1519 | * |
| 1520 | * see Documentation/networking/netconsole.txt |
| 1521 | */ |
| 1522 | static void |
| 1523 | spider_net_poll_controller(struct net_device *netdev) |
| 1524 | { |
| 1525 | disable_irq(netdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1526 | spider_net_interrupt(netdev->irq, netdev); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1527 | enable_irq(netdev->irq); |
| 1528 | } |
| 1529 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 1530 | |
| 1531 | /** |
| 1532 | * spider_net_init_card - initializes the card |
| 1533 | * @card: card structure |
| 1534 | * |
| 1535 | * spider_net_init_card initializes the card so that other registers can |
| 1536 | * be used |
| 1537 | */ |
| 1538 | static void |
| 1539 | spider_net_init_card(struct spider_net_card *card) |
| 1540 | { |
| 1541 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1542 | SPIDER_NET_CKRCTRL_STOP_VALUE); |
| 1543 | |
| 1544 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1545 | SPIDER_NET_CKRCTRL_RUN_VALUE); |
| 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * spider_net_enable_card - enables the card by setting all kinds of regs |
| 1550 | * @card: card structure |
| 1551 | * |
| 1552 | * spider_net_enable_card sets a lot of SMMIO registers to enable the device |
| 1553 | */ |
| 1554 | static void |
| 1555 | spider_net_enable_card(struct spider_net_card *card) |
| 1556 | { |
| 1557 | int i; |
| 1558 | /* the following array consists of (register),(value) pairs |
| 1559 | * that are set in this function. A register of 0 ends the list */ |
| 1560 | u32 regs[][2] = { |
| 1561 | { SPIDER_NET_GRESUMINTNUM, 0 }, |
| 1562 | { SPIDER_NET_GREINTNUM, 0 }, |
| 1563 | |
| 1564 | /* set interrupt frame number registers */ |
| 1565 | /* clear the single DMA engine registers first */ |
| 1566 | { SPIDER_NET_GFAFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1567 | { SPIDER_NET_GFBFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1568 | { SPIDER_NET_GFCFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1569 | { SPIDER_NET_GFDFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1570 | /* then set, what we really need */ |
| 1571 | { SPIDER_NET_GFFRMNUM, SPIDER_NET_FRAMENUM_VALUE }, |
| 1572 | |
| 1573 | /* timer counter registers and stuff */ |
| 1574 | { SPIDER_NET_GFREECNNUM, 0 }, |
| 1575 | { SPIDER_NET_GONETIMENUM, 0 }, |
| 1576 | { SPIDER_NET_GTOUTFRMNUM, 0 }, |
| 1577 | |
| 1578 | /* RX mode setting */ |
| 1579 | { SPIDER_NET_GRXMDSET, SPIDER_NET_RXMODE_VALUE }, |
| 1580 | /* TX mode setting */ |
| 1581 | { SPIDER_NET_GTXMDSET, SPIDER_NET_TXMODE_VALUE }, |
| 1582 | /* IPSEC mode setting */ |
| 1583 | { SPIDER_NET_GIPSECINIT, SPIDER_NET_IPSECINIT_VALUE }, |
| 1584 | |
| 1585 | { SPIDER_NET_GFTRESTRT, SPIDER_NET_RESTART_VALUE }, |
| 1586 | |
| 1587 | { SPIDER_NET_GMRWOLCTRL, 0 }, |
Jens Osterkamp | b636d17 | 2006-05-04 05:59:56 -0400 | [diff] [blame] | 1588 | { SPIDER_NET_GTESTMD, 0x10000000 }, |
| 1589 | { SPIDER_NET_GTTQMSK, 0x00400040 }, |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1590 | |
| 1591 | { SPIDER_NET_GMACINTEN, 0 }, |
| 1592 | |
| 1593 | /* flow control stuff */ |
| 1594 | { SPIDER_NET_GMACAPAUSE, SPIDER_NET_MACAPAUSE_VALUE }, |
| 1595 | { SPIDER_NET_GMACTXPAUSE, SPIDER_NET_TXPAUSE_VALUE }, |
| 1596 | |
| 1597 | { SPIDER_NET_GMACBSTLMT, SPIDER_NET_BURSTLMT_VALUE }, |
| 1598 | { 0, 0} |
| 1599 | }; |
| 1600 | |
| 1601 | i = 0; |
| 1602 | while (regs[i][0]) { |
| 1603 | spider_net_write_reg(card, regs[i][0], regs[i][1]); |
| 1604 | i++; |
| 1605 | } |
| 1606 | |
| 1607 | /* clear unicast filter table entries 1 to 14 */ |
| 1608 | for (i = 1; i <= 14; i++) { |
| 1609 | spider_net_write_reg(card, |
| 1610 | SPIDER_NET_GMRUAFILnR + i * 8, |
| 1611 | 0x00080000); |
| 1612 | spider_net_write_reg(card, |
| 1613 | SPIDER_NET_GMRUAFILnR + i * 8 + 4, |
| 1614 | 0x00000000); |
| 1615 | } |
| 1616 | |
| 1617 | spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, 0x08080000); |
| 1618 | |
| 1619 | spider_net_write_reg(card, SPIDER_NET_ECMODE, SPIDER_NET_ECMODE_VALUE); |
| 1620 | |
| 1621 | /* set chain tail adress for RX chains and |
| 1622 | * enable DMA */ |
| 1623 | spider_net_enable_rxchtails(card); |
| 1624 | spider_net_enable_rxdmac(card); |
| 1625 | |
| 1626 | spider_net_write_reg(card, SPIDER_NET_GRXDMAEN, SPIDER_NET_WOL_VALUE); |
| 1627 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1628 | spider_net_write_reg(card, SPIDER_NET_GMACLENLMT, |
| 1629 | SPIDER_NET_LENLMT_VALUE); |
| 1630 | spider_net_write_reg(card, SPIDER_NET_GMACMODE, |
| 1631 | SPIDER_NET_MACMODE_VALUE); |
| 1632 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, |
| 1633 | SPIDER_NET_OPMODE_VALUE); |
| 1634 | |
| 1635 | /* set interrupt mask registers */ |
| 1636 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, |
| 1637 | SPIDER_NET_INT0_MASK_VALUE); |
| 1638 | spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, |
| 1639 | SPIDER_NET_INT1_MASK_VALUE); |
| 1640 | spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, |
| 1641 | SPIDER_NET_INT2_MASK_VALUE); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1642 | |
| 1643 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, |
Linas Vepstas | ded8028 | 2006-10-10 16:02:54 -0500 | [diff] [blame] | 1644 | SPIDER_NET_GDTBSTA | SPIDER_NET_GDTDCEIDIS); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | /** |
| 1648 | * spider_net_open - called upon ifonfig up |
| 1649 | * @netdev: interface device structure |
| 1650 | * |
| 1651 | * returns 0 on success, <0 on failure |
| 1652 | * |
| 1653 | * spider_net_open allocates all the descriptors and memory needed for |
| 1654 | * operation, sets up multicast list and enables interrupts |
| 1655 | */ |
| 1656 | int |
| 1657 | spider_net_open(struct net_device *netdev) |
| 1658 | { |
| 1659 | struct spider_net_card *card = netdev_priv(netdev); |
| 1660 | int result; |
| 1661 | |
| 1662 | result = -ENOMEM; |
Jim Lewis | b68a60e | 2006-08-14 23:00:23 -0700 | [diff] [blame] | 1663 | if (spider_net_init_chain(card, &card->tx_chain, card->descr, |
| 1664 | PCI_DMA_TODEVICE, card->tx_desc)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1665 | goto alloc_tx_failed; |
Linas Vepstas | b21606a | 2006-10-10 16:09:40 -0500 | [diff] [blame] | 1666 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 1667 | card->low_watermark = NULL; |
| 1668 | |
Linas Vepstas | b21606a | 2006-10-10 16:09:40 -0500 | [diff] [blame] | 1669 | /* rx_chain is after tx_chain, so offset is descr + tx_count */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1670 | if (spider_net_init_chain(card, &card->rx_chain, |
Linas Vepstas | b21606a | 2006-10-10 16:09:40 -0500 | [diff] [blame] | 1671 | card->descr + card->tx_desc, |
Jim Lewis | b68a60e | 2006-08-14 23:00:23 -0700 | [diff] [blame] | 1672 | PCI_DMA_FROMDEVICE, card->rx_desc)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1673 | goto alloc_rx_failed; |
| 1674 | |
| 1675 | /* allocate rx skbs */ |
| 1676 | if (spider_net_alloc_rx_skbs(card)) |
| 1677 | goto alloc_skbs_failed; |
| 1678 | |
| 1679 | spider_net_set_multi(netdev); |
| 1680 | |
| 1681 | /* further enhancement: setup hw vlan, if needed */ |
| 1682 | |
| 1683 | result = -EBUSY; |
| 1684 | if (request_irq(netdev->irq, spider_net_interrupt, |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 1685 | IRQF_SHARED, netdev->name, netdev)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1686 | goto register_int_failed; |
| 1687 | |
| 1688 | spider_net_enable_card(card); |
| 1689 | |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 1690 | netif_start_queue(netdev); |
| 1691 | netif_carrier_on(netdev); |
| 1692 | netif_poll_enable(netdev); |
| 1693 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1694 | return 0; |
| 1695 | |
| 1696 | register_int_failed: |
| 1697 | spider_net_free_rx_chain_contents(card); |
| 1698 | alloc_skbs_failed: |
| 1699 | spider_net_free_chain(card, &card->rx_chain); |
| 1700 | alloc_rx_failed: |
| 1701 | spider_net_free_chain(card, &card->tx_chain); |
| 1702 | alloc_tx_failed: |
| 1703 | return result; |
| 1704 | } |
| 1705 | |
| 1706 | /** |
| 1707 | * spider_net_setup_phy - setup PHY |
| 1708 | * @card: card structure |
| 1709 | * |
| 1710 | * returns 0 on success, <0 on failure |
| 1711 | * |
| 1712 | * spider_net_setup_phy is used as part of spider_net_probe. Sets |
| 1713 | * the PHY to 1000 Mbps |
| 1714 | **/ |
| 1715 | static int |
| 1716 | spider_net_setup_phy(struct spider_net_card *card) |
| 1717 | { |
| 1718 | struct mii_phy *phy = &card->phy; |
| 1719 | |
| 1720 | spider_net_write_reg(card, SPIDER_NET_GDTDMASEL, |
| 1721 | SPIDER_NET_DMASEL_VALUE); |
| 1722 | spider_net_write_reg(card, SPIDER_NET_GPCCTRL, |
| 1723 | SPIDER_NET_PHY_CTRL_VALUE); |
| 1724 | phy->mii_id = 1; |
| 1725 | phy->dev = card->netdev; |
| 1726 | phy->mdio_read = spider_net_read_phy; |
| 1727 | phy->mdio_write = spider_net_write_phy; |
| 1728 | |
| 1729 | mii_phy_probe(phy, phy->mii_id); |
| 1730 | |
| 1731 | if (phy->def->ops->setup_forced) |
| 1732 | phy->def->ops->setup_forced(phy, SPEED_1000, DUPLEX_FULL); |
| 1733 | |
Jens Osterkamp | 8ec9345 | 2006-05-04 05:59:41 -0400 | [diff] [blame] | 1734 | phy->def->ops->enable_fiber(phy); |
Jens Osterkamp | 53abbf7 | 2005-09-16 08:55:33 +0200 | [diff] [blame] | 1735 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1736 | phy->def->ops->read_link(phy); |
| 1737 | pr_info("Found %s with %i Mbps, %s-duplex.\n", phy->def->name, |
| 1738 | phy->speed, phy->duplex==1 ? "Full" : "Half"); |
| 1739 | |
| 1740 | return 0; |
| 1741 | } |
| 1742 | |
| 1743 | /** |
| 1744 | * spider_net_download_firmware - loads firmware into the adapter |
| 1745 | * @card: card structure |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1746 | * @firmware_ptr: pointer to firmware data |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1747 | * |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1748 | * spider_net_download_firmware loads the firmware data into the |
| 1749 | * adapter. It assumes the length etc. to be allright. |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1750 | */ |
Arnd Bergmann | 0d3ea16 | 2006-01-12 17:16:41 -0500 | [diff] [blame] | 1751 | static int |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1752 | spider_net_download_firmware(struct spider_net_card *card, |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1753 | const void *firmware_ptr) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1754 | { |
| 1755 | int sequencer, i; |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1756 | const u32 *fw_ptr = firmware_ptr; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1757 | |
| 1758 | /* stop sequencers */ |
| 1759 | spider_net_write_reg(card, SPIDER_NET_GSINIT, |
| 1760 | SPIDER_NET_STOP_SEQ_VALUE); |
| 1761 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1762 | for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS; |
| 1763 | sequencer++) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1764 | spider_net_write_reg(card, |
| 1765 | SPIDER_NET_GSnPRGADR + sequencer * 8, 0); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1766 | for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1767 | spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + |
| 1768 | sequencer * 8, *fw_ptr); |
| 1769 | fw_ptr++; |
| 1770 | } |
| 1771 | } |
| 1772 | |
Arnd Bergmann | 0d3ea16 | 2006-01-12 17:16:41 -0500 | [diff] [blame] | 1773 | if (spider_net_read_reg(card, SPIDER_NET_GSINIT)) |
| 1774 | return -EIO; |
| 1775 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1776 | spider_net_write_reg(card, SPIDER_NET_GSINIT, |
| 1777 | SPIDER_NET_RUN_SEQ_VALUE); |
Arnd Bergmann | 0d3ea16 | 2006-01-12 17:16:41 -0500 | [diff] [blame] | 1778 | |
| 1779 | return 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | /** |
| 1783 | * spider_net_init_firmware - reads in firmware parts |
| 1784 | * @card: card structure |
| 1785 | * |
| 1786 | * Returns 0 on success, <0 on failure |
| 1787 | * |
| 1788 | * spider_net_init_firmware opens the sequencer firmware and does some basic |
| 1789 | * checks. This function opens and releases the firmware structure. A call |
| 1790 | * to download the firmware is performed before the release. |
| 1791 | * |
| 1792 | * Firmware format |
| 1793 | * =============== |
| 1794 | * spider_fw.bin is expected to be a file containing 6*1024*4 bytes, 4k being |
| 1795 | * the program for each sequencer. Use the command |
| 1796 | * tail -q -n +2 Seq_code1_0x088.txt Seq_code2_0x090.txt \ |
| 1797 | * Seq_code3_0x098.txt Seq_code4_0x0A0.txt Seq_code5_0x0A8.txt \ |
| 1798 | * Seq_code6_0x0B0.txt | xxd -r -p -c4 > spider_fw.bin |
| 1799 | * |
| 1800 | * to generate spider_fw.bin, if you have sequencer programs with something |
| 1801 | * like the following contents for each sequencer: |
| 1802 | * <ONE LINE COMMENT> |
| 1803 | * <FIRST 4-BYTES-WORD FOR SEQUENCER> |
| 1804 | * <SECOND 4-BYTES-WORD FOR SEQUENCER> |
| 1805 | * ... |
| 1806 | * <1024th 4-BYTES-WORD FOR SEQUENCER> |
| 1807 | */ |
| 1808 | static int |
| 1809 | spider_net_init_firmware(struct spider_net_card *card) |
| 1810 | { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1811 | struct firmware *firmware = NULL; |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1812 | struct device_node *dn; |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1813 | const u8 *fw_prop = NULL; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1814 | int err = -ENOENT; |
| 1815 | int fw_size; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1816 | |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1817 | if (request_firmware((const struct firmware **)&firmware, |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1818 | SPIDER_NET_FIRMWARE_NAME, &card->pdev->dev) == 0) { |
| 1819 | if ( (firmware->size != SPIDER_NET_FIRMWARE_LEN) && |
| 1820 | netif_msg_probe(card) ) { |
| 1821 | pr_err("Incorrect size of spidernet firmware in " \ |
| 1822 | "filesystem. Looking in host firmware...\n"); |
| 1823 | goto try_host_fw; |
| 1824 | } |
| 1825 | err = spider_net_download_firmware(card, firmware->data); |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1826 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1827 | release_firmware(firmware); |
| 1828 | if (err) |
| 1829 | goto try_host_fw; |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1830 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1831 | goto done; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1834 | try_host_fw: |
| 1835 | dn = pci_device_to_OF_node(card->pdev); |
| 1836 | if (!dn) |
| 1837 | goto out_err; |
| 1838 | |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1839 | fw_prop = get_property(dn, "firmware", &fw_size); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1840 | if (!fw_prop) |
| 1841 | goto out_err; |
| 1842 | |
| 1843 | if ( (fw_size != SPIDER_NET_FIRMWARE_LEN) && |
| 1844 | netif_msg_probe(card) ) { |
| 1845 | pr_err("Incorrect size of spidernet firmware in " \ |
| 1846 | "host firmware\n"); |
| 1847 | goto done; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1850 | err = spider_net_download_firmware(card, fw_prop); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1851 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1852 | done: |
| 1853 | return err; |
| 1854 | out_err: |
| 1855 | if (netif_msg_probe(card)) |
| 1856 | pr_err("Couldn't find spidernet firmware in filesystem " \ |
| 1857 | "or host firmware\n"); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1858 | return err; |
| 1859 | } |
| 1860 | |
| 1861 | /** |
| 1862 | * spider_net_workaround_rxramfull - work around firmware bug |
| 1863 | * @card: card structure |
| 1864 | * |
| 1865 | * no return value |
| 1866 | **/ |
| 1867 | static void |
| 1868 | spider_net_workaround_rxramfull(struct spider_net_card *card) |
| 1869 | { |
| 1870 | int i, sequencer = 0; |
| 1871 | |
| 1872 | /* cancel reset */ |
| 1873 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1874 | SPIDER_NET_CKRCTRL_RUN_VALUE); |
| 1875 | |
| 1876 | /* empty sequencer data */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1877 | for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS; |
| 1878 | sequencer++) { |
Jens Osterkamp | ee962a5 | 2006-07-13 11:54:23 +0200 | [diff] [blame] | 1879 | spider_net_write_reg(card, SPIDER_NET_GSnPRGADR + |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1880 | sequencer * 8, 0x0); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1881 | for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1882 | spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + |
| 1883 | sequencer * 8, 0x0); |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | /* set sequencer operation */ |
| 1888 | spider_net_write_reg(card, SPIDER_NET_GSINIT, 0x000000fe); |
| 1889 | |
| 1890 | /* reset */ |
| 1891 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1892 | SPIDER_NET_CKRCTRL_STOP_VALUE); |
| 1893 | } |
| 1894 | |
| 1895 | /** |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1896 | * spider_net_stop - called upon ifconfig down |
| 1897 | * @netdev: interface device structure |
| 1898 | * |
| 1899 | * always returns 0 |
| 1900 | */ |
| 1901 | int |
| 1902 | spider_net_stop(struct net_device *netdev) |
| 1903 | { |
| 1904 | struct spider_net_card *card = netdev_priv(netdev); |
| 1905 | |
| 1906 | tasklet_kill(&card->rxram_full_tl); |
| 1907 | netif_poll_disable(netdev); |
| 1908 | netif_carrier_off(netdev); |
| 1909 | netif_stop_queue(netdev); |
| 1910 | del_timer_sync(&card->tx_timer); |
| 1911 | |
| 1912 | /* disable/mask all interrupts */ |
| 1913 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0); |
| 1914 | spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0); |
| 1915 | spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0); |
| 1916 | |
| 1917 | /* free_irq(netdev->irq, netdev);*/ |
| 1918 | free_irq(to_pci_dev(netdev->class_dev.dev)->irq, netdev); |
| 1919 | |
| 1920 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, |
| 1921 | SPIDER_NET_DMA_TX_FEND_VALUE); |
| 1922 | |
| 1923 | /* turn off DMA, force end */ |
| 1924 | spider_net_disable_rxdmac(card); |
| 1925 | |
| 1926 | /* release chains */ |
Linas Vepstas | 9cc7bf7 | 2006-10-10 16:14:29 -0500 | [diff] [blame^] | 1927 | spider_net_release_tx_chain(card, 1); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1928 | |
| 1929 | spider_net_free_chain(card, &card->tx_chain); |
| 1930 | spider_net_free_chain(card, &card->rx_chain); |
| 1931 | |
| 1932 | return 0; |
| 1933 | } |
| 1934 | |
| 1935 | /** |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1936 | * spider_net_tx_timeout_task - task scheduled by the watchdog timeout |
| 1937 | * function (to be called not under interrupt status) |
| 1938 | * @data: data, is interface device structure |
| 1939 | * |
| 1940 | * called as task when tx hangs, resets interface (if interface is up) |
| 1941 | */ |
| 1942 | static void |
| 1943 | spider_net_tx_timeout_task(void *data) |
| 1944 | { |
| 1945 | struct net_device *netdev = data; |
| 1946 | struct spider_net_card *card = netdev_priv(netdev); |
| 1947 | |
| 1948 | if (!(netdev->flags & IFF_UP)) |
| 1949 | goto out; |
| 1950 | |
| 1951 | netif_device_detach(netdev); |
| 1952 | spider_net_stop(netdev); |
| 1953 | |
| 1954 | spider_net_workaround_rxramfull(card); |
| 1955 | spider_net_init_card(card); |
| 1956 | |
| 1957 | if (spider_net_setup_phy(card)) |
| 1958 | goto out; |
| 1959 | if (spider_net_init_firmware(card)) |
| 1960 | goto out; |
| 1961 | |
| 1962 | spider_net_open(netdev); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1963 | spider_net_kick_tx_dma(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1964 | netif_device_attach(netdev); |
| 1965 | |
| 1966 | out: |
| 1967 | atomic_dec(&card->tx_timeout_task_counter); |
| 1968 | } |
| 1969 | |
| 1970 | /** |
| 1971 | * spider_net_tx_timeout - called when the tx timeout watchdog kicks in. |
| 1972 | * @netdev: interface device structure |
| 1973 | * |
| 1974 | * called, if tx hangs. Schedules a task that resets the interface |
| 1975 | */ |
| 1976 | static void |
| 1977 | spider_net_tx_timeout(struct net_device *netdev) |
| 1978 | { |
| 1979 | struct spider_net_card *card; |
| 1980 | |
| 1981 | card = netdev_priv(netdev); |
| 1982 | atomic_inc(&card->tx_timeout_task_counter); |
| 1983 | if (netdev->flags & IFF_UP) |
| 1984 | schedule_work(&card->tx_timeout_task); |
| 1985 | else |
| 1986 | atomic_dec(&card->tx_timeout_task_counter); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 1987 | card->spider_stats.tx_timeouts++; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | /** |
| 1991 | * spider_net_setup_netdev_ops - initialization of net_device operations |
| 1992 | * @netdev: net_device structure |
| 1993 | * |
| 1994 | * fills out function pointers in the net_device structure |
| 1995 | */ |
| 1996 | static void |
| 1997 | spider_net_setup_netdev_ops(struct net_device *netdev) |
| 1998 | { |
| 1999 | netdev->open = &spider_net_open; |
| 2000 | netdev->stop = &spider_net_stop; |
| 2001 | netdev->hard_start_xmit = &spider_net_xmit; |
| 2002 | netdev->get_stats = &spider_net_get_stats; |
| 2003 | netdev->set_multicast_list = &spider_net_set_multi; |
| 2004 | netdev->set_mac_address = &spider_net_set_mac; |
| 2005 | netdev->change_mtu = &spider_net_change_mtu; |
| 2006 | netdev->do_ioctl = &spider_net_do_ioctl; |
| 2007 | /* tx watchdog */ |
| 2008 | netdev->tx_timeout = &spider_net_tx_timeout; |
| 2009 | netdev->watchdog_timeo = SPIDER_NET_WATCHDOG_TIMEOUT; |
| 2010 | /* NAPI */ |
| 2011 | netdev->poll = &spider_net_poll; |
| 2012 | netdev->weight = SPIDER_NET_NAPI_WEIGHT; |
| 2013 | /* HW VLAN */ |
| 2014 | netdev->vlan_rx_register = &spider_net_vlan_rx_reg; |
| 2015 | netdev->vlan_rx_add_vid = &spider_net_vlan_rx_add; |
| 2016 | netdev->vlan_rx_kill_vid = &spider_net_vlan_rx_kill; |
| 2017 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2018 | /* poll controller */ |
| 2019 | netdev->poll_controller = &spider_net_poll_controller; |
| 2020 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 2021 | /* ethtool ops */ |
| 2022 | netdev->ethtool_ops = &spider_net_ethtool_ops; |
| 2023 | } |
| 2024 | |
| 2025 | /** |
| 2026 | * spider_net_setup_netdev - initialization of net_device |
| 2027 | * @card: card structure |
| 2028 | * |
| 2029 | * Returns 0 on success or <0 on failure |
| 2030 | * |
| 2031 | * spider_net_setup_netdev initializes the net_device structure |
| 2032 | **/ |
| 2033 | static int |
| 2034 | spider_net_setup_netdev(struct spider_net_card *card) |
| 2035 | { |
| 2036 | int result; |
| 2037 | struct net_device *netdev = card->netdev; |
| 2038 | struct device_node *dn; |
| 2039 | struct sockaddr addr; |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 2040 | const u8 *mac; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2041 | |
| 2042 | SET_MODULE_OWNER(netdev); |
| 2043 | SET_NETDEV_DEV(netdev, &card->pdev->dev); |
| 2044 | |
| 2045 | pci_set_drvdata(card->pdev, netdev); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 2046 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 2047 | card->rxram_full_tl.data = (unsigned long) card; |
| 2048 | card->rxram_full_tl.func = |
| 2049 | (void (*)(unsigned long)) spider_net_handle_rxram_full; |
| 2050 | init_timer(&card->tx_timer); |
| 2051 | card->tx_timer.function = |
| 2052 | (void (*)(unsigned long)) spider_net_cleanup_tx_ring; |
| 2053 | card->tx_timer.data = (unsigned long) card; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2054 | netdev->irq = card->pdev->irq; |
| 2055 | |
| 2056 | card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT; |
| 2057 | |
Jim Lewis | b68a60e | 2006-08-14 23:00:23 -0700 | [diff] [blame] | 2058 | card->tx_desc = tx_descriptors; |
| 2059 | card->rx_desc = rx_descriptors; |
| 2060 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2061 | spider_net_setup_netdev_ops(netdev); |
| 2062 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 2063 | netdev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2064 | /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | |
| 2065 | * NETIF_F_HW_VLAN_FILTER */ |
| 2066 | |
| 2067 | netdev->irq = card->pdev->irq; |
| 2068 | |
| 2069 | dn = pci_device_to_OF_node(card->pdev); |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 2070 | if (!dn) |
| 2071 | return -EIO; |
| 2072 | |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 2073 | mac = get_property(dn, "local-mac-address", NULL); |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 2074 | if (!mac) |
| 2075 | return -EIO; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2076 | memcpy(addr.sa_data, mac, ETH_ALEN); |
| 2077 | |
| 2078 | result = spider_net_set_mac(netdev, &addr); |
| 2079 | if ((result) && (netif_msg_probe(card))) |
| 2080 | pr_err("Failed to set MAC address: %i\n", result); |
| 2081 | |
| 2082 | result = register_netdev(netdev); |
| 2083 | if (result) { |
| 2084 | if (netif_msg_probe(card)) |
| 2085 | pr_err("Couldn't register net_device: %i\n", |
| 2086 | result); |
| 2087 | return result; |
| 2088 | } |
| 2089 | |
| 2090 | if (netif_msg_probe(card)) |
| 2091 | pr_info("Initialized device %s.\n", netdev->name); |
| 2092 | |
| 2093 | return 0; |
| 2094 | } |
| 2095 | |
| 2096 | /** |
| 2097 | * spider_net_alloc_card - allocates net_device and card structure |
| 2098 | * |
| 2099 | * returns the card structure or NULL in case of errors |
| 2100 | * |
| 2101 | * the card and net_device structures are linked to each other |
| 2102 | */ |
| 2103 | static struct spider_net_card * |
| 2104 | spider_net_alloc_card(void) |
| 2105 | { |
| 2106 | struct net_device *netdev; |
| 2107 | struct spider_net_card *card; |
| 2108 | size_t alloc_size; |
| 2109 | |
| 2110 | alloc_size = sizeof (*card) + |
| 2111 | sizeof (struct spider_net_descr) * rx_descriptors + |
| 2112 | sizeof (struct spider_net_descr) * tx_descriptors; |
| 2113 | netdev = alloc_etherdev(alloc_size); |
| 2114 | if (!netdev) |
| 2115 | return NULL; |
| 2116 | |
| 2117 | card = netdev_priv(netdev); |
| 2118 | card->netdev = netdev; |
| 2119 | card->msg_enable = SPIDER_NET_DEFAULT_MSG; |
| 2120 | INIT_WORK(&card->tx_timeout_task, spider_net_tx_timeout_task, netdev); |
| 2121 | init_waitqueue_head(&card->waitq); |
| 2122 | atomic_set(&card->tx_timeout_task_counter, 0); |
| 2123 | |
| 2124 | return card; |
| 2125 | } |
| 2126 | |
| 2127 | /** |
| 2128 | * spider_net_undo_pci_setup - releases PCI ressources |
| 2129 | * @card: card structure |
| 2130 | * |
| 2131 | * spider_net_undo_pci_setup releases the mapped regions |
| 2132 | */ |
| 2133 | static void |
| 2134 | spider_net_undo_pci_setup(struct spider_net_card *card) |
| 2135 | { |
| 2136 | iounmap(card->regs); |
| 2137 | pci_release_regions(card->pdev); |
| 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * spider_net_setup_pci_dev - sets up the device in terms of PCI operations |
| 2142 | * @card: card structure |
| 2143 | * @pdev: PCI device |
| 2144 | * |
| 2145 | * Returns the card structure or NULL if any errors occur |
| 2146 | * |
| 2147 | * spider_net_setup_pci_dev initializes pdev and together with the |
| 2148 | * functions called in spider_net_open configures the device so that |
| 2149 | * data can be transferred over it |
| 2150 | * The net_device structure is attached to the card structure, if the |
| 2151 | * function returns without error. |
| 2152 | **/ |
| 2153 | static struct spider_net_card * |
| 2154 | spider_net_setup_pci_dev(struct pci_dev *pdev) |
| 2155 | { |
| 2156 | struct spider_net_card *card; |
| 2157 | unsigned long mmio_start, mmio_len; |
| 2158 | |
| 2159 | if (pci_enable_device(pdev)) { |
| 2160 | pr_err("Couldn't enable PCI device\n"); |
| 2161 | return NULL; |
| 2162 | } |
| 2163 | |
| 2164 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 2165 | pr_err("Couldn't find proper PCI device base address.\n"); |
| 2166 | goto out_disable_dev; |
| 2167 | } |
| 2168 | |
| 2169 | if (pci_request_regions(pdev, spider_net_driver_name)) { |
| 2170 | pr_err("Couldn't obtain PCI resources, aborting.\n"); |
| 2171 | goto out_disable_dev; |
| 2172 | } |
| 2173 | |
| 2174 | pci_set_master(pdev); |
| 2175 | |
| 2176 | card = spider_net_alloc_card(); |
| 2177 | if (!card) { |
| 2178 | pr_err("Couldn't allocate net_device structure, " |
| 2179 | "aborting.\n"); |
| 2180 | goto out_release_regions; |
| 2181 | } |
| 2182 | card->pdev = pdev; |
| 2183 | |
| 2184 | /* fetch base address and length of first resource */ |
| 2185 | mmio_start = pci_resource_start(pdev, 0); |
| 2186 | mmio_len = pci_resource_len(pdev, 0); |
| 2187 | |
| 2188 | card->netdev->mem_start = mmio_start; |
| 2189 | card->netdev->mem_end = mmio_start + mmio_len; |
| 2190 | card->regs = ioremap(mmio_start, mmio_len); |
| 2191 | |
| 2192 | if (!card->regs) { |
| 2193 | pr_err("Couldn't obtain PCI resources, aborting.\n"); |
| 2194 | goto out_release_regions; |
| 2195 | } |
| 2196 | |
| 2197 | return card; |
| 2198 | |
| 2199 | out_release_regions: |
| 2200 | pci_release_regions(pdev); |
| 2201 | out_disable_dev: |
| 2202 | pci_disable_device(pdev); |
| 2203 | pci_set_drvdata(pdev, NULL); |
| 2204 | return NULL; |
| 2205 | } |
| 2206 | |
| 2207 | /** |
| 2208 | * spider_net_probe - initialization of a device |
| 2209 | * @pdev: PCI device |
| 2210 | * @ent: entry in the device id list |
| 2211 | * |
| 2212 | * Returns 0 on success, <0 on failure |
| 2213 | * |
| 2214 | * spider_net_probe initializes pdev and registers a net_device |
| 2215 | * structure for it. After that, the device can be ifconfig'ed up |
| 2216 | **/ |
| 2217 | static int __devinit |
| 2218 | spider_net_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 2219 | { |
| 2220 | int err = -EIO; |
| 2221 | struct spider_net_card *card; |
| 2222 | |
| 2223 | card = spider_net_setup_pci_dev(pdev); |
| 2224 | if (!card) |
| 2225 | goto out; |
| 2226 | |
| 2227 | spider_net_workaround_rxramfull(card); |
| 2228 | spider_net_init_card(card); |
| 2229 | |
| 2230 | err = spider_net_setup_phy(card); |
| 2231 | if (err) |
| 2232 | goto out_undo_pci; |
| 2233 | |
| 2234 | err = spider_net_init_firmware(card); |
| 2235 | if (err) |
| 2236 | goto out_undo_pci; |
| 2237 | |
| 2238 | err = spider_net_setup_netdev(card); |
| 2239 | if (err) |
| 2240 | goto out_undo_pci; |
| 2241 | |
| 2242 | return 0; |
| 2243 | |
| 2244 | out_undo_pci: |
| 2245 | spider_net_undo_pci_setup(card); |
| 2246 | free_netdev(card->netdev); |
| 2247 | out: |
| 2248 | return err; |
| 2249 | } |
| 2250 | |
| 2251 | /** |
| 2252 | * spider_net_remove - removal of a device |
| 2253 | * @pdev: PCI device |
| 2254 | * |
| 2255 | * Returns 0 on success, <0 on failure |
| 2256 | * |
| 2257 | * spider_net_remove is called to remove the device and unregisters the |
| 2258 | * net_device |
| 2259 | **/ |
| 2260 | static void __devexit |
| 2261 | spider_net_remove(struct pci_dev *pdev) |
| 2262 | { |
| 2263 | struct net_device *netdev; |
| 2264 | struct spider_net_card *card; |
| 2265 | |
| 2266 | netdev = pci_get_drvdata(pdev); |
| 2267 | card = netdev_priv(netdev); |
| 2268 | |
| 2269 | wait_event(card->waitq, |
| 2270 | atomic_read(&card->tx_timeout_task_counter) == 0); |
| 2271 | |
| 2272 | unregister_netdev(netdev); |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 2273 | |
| 2274 | /* switch off card */ |
| 2275 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 2276 | SPIDER_NET_CKRCTRL_STOP_VALUE); |
| 2277 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 2278 | SPIDER_NET_CKRCTRL_RUN_VALUE); |
| 2279 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2280 | spider_net_undo_pci_setup(card); |
| 2281 | free_netdev(netdev); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | static struct pci_driver spider_net_driver = { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2285 | .name = spider_net_driver_name, |
| 2286 | .id_table = spider_net_pci_tbl, |
| 2287 | .probe = spider_net_probe, |
| 2288 | .remove = __devexit_p(spider_net_remove) |
| 2289 | }; |
| 2290 | |
| 2291 | /** |
| 2292 | * spider_net_init - init function when the driver is loaded |
| 2293 | * |
| 2294 | * spider_net_init registers the device driver |
| 2295 | */ |
| 2296 | static int __init spider_net_init(void) |
| 2297 | { |
Linas Vepstas | 90f1084 | 2006-10-10 15:56:04 -0500 | [diff] [blame] | 2298 | printk(KERN_INFO "Spidernet version %s.\n", VERSION); |
| 2299 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2300 | if (rx_descriptors < SPIDER_NET_RX_DESCRIPTORS_MIN) { |
| 2301 | rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MIN; |
| 2302 | pr_info("adjusting rx descriptors to %i.\n", rx_descriptors); |
| 2303 | } |
| 2304 | if (rx_descriptors > SPIDER_NET_RX_DESCRIPTORS_MAX) { |
| 2305 | rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MAX; |
| 2306 | pr_info("adjusting rx descriptors to %i.\n", rx_descriptors); |
| 2307 | } |
| 2308 | if (tx_descriptors < SPIDER_NET_TX_DESCRIPTORS_MIN) { |
| 2309 | tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MIN; |
| 2310 | pr_info("adjusting tx descriptors to %i.\n", tx_descriptors); |
| 2311 | } |
| 2312 | if (tx_descriptors > SPIDER_NET_TX_DESCRIPTORS_MAX) { |
| 2313 | tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MAX; |
| 2314 | pr_info("adjusting tx descriptors to %i.\n", tx_descriptors); |
| 2315 | } |
| 2316 | |
| 2317 | return pci_register_driver(&spider_net_driver); |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * spider_net_cleanup - exit function when driver is unloaded |
| 2322 | * |
| 2323 | * spider_net_cleanup unregisters the device driver |
| 2324 | */ |
| 2325 | static void __exit spider_net_cleanup(void) |
| 2326 | { |
| 2327 | pci_unregister_driver(&spider_net_driver); |
| 2328 | } |
| 2329 | |
| 2330 | module_init(spider_net_init); |
| 2331 | module_exit(spider_net_cleanup); |