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 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 649 | struct spider_net_descr *descr = card->tx_chain.head; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 650 | dma_addr_t buf; |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 651 | int length; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 652 | |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 653 | length = skb->len; |
| 654 | if (length < ETH_ZLEN) { |
| 655 | if (skb_pad(skb, ETH_ZLEN-length)) |
| 656 | return 0; |
| 657 | length = ETH_ZLEN; |
| 658 | } |
| 659 | |
| 660 | buf = pci_map_single(card->pdev, skb->data, length, PCI_DMA_TODEVICE); |
Olof Johansson | d4b0a4c | 2006-09-27 14:02:26 -0500 | [diff] [blame] | 661 | if (pci_dma_mapping_error(buf)) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 662 | if (netif_msg_tx_err(card) && net_ratelimit()) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 663 | pr_err("could not iommu-map packet (%p, %i). " |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 664 | "Dropping packet\n", skb->data, length); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 665 | card->spider_stats.tx_iommu_map_error++; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 666 | return -ENOMEM; |
| 667 | } |
| 668 | |
Arnd Bergmann | 8e0a613 | 2006-01-12 17:16:43 -0500 | [diff] [blame] | 669 | descr->buf_addr = buf; |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 670 | descr->buf_size = length; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 671 | descr->next_descr_addr = 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 672 | descr->skb = skb; |
| 673 | descr->data_status = 0; |
| 674 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 675 | descr->dmac_cmd_status = |
| 676 | SPIDER_NET_DESCR_CARDOWNED | SPIDER_NET_DMAC_NOCS; |
| 677 | if (skb->protocol == htons(ETH_P_IP)) |
| 678 | switch (skb->nh.iph->protocol) { |
| 679 | case IPPROTO_TCP: |
| 680 | descr->dmac_cmd_status |= SPIDER_NET_DMAC_TCP; |
| 681 | break; |
| 682 | case IPPROTO_UDP: |
| 683 | descr->dmac_cmd_status |= SPIDER_NET_DMAC_UDP; |
| 684 | break; |
| 685 | } |
| 686 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 687 | /* Chain the bus address, so that the DMA engine finds this descr. */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 688 | descr->prev->next_descr_addr = descr->bus_addr; |
| 689 | |
Linas Vepstas | 917a5b8 | 2006-10-10 16:01:51 -0500 | [diff] [blame] | 690 | card->netdev->trans_start = jiffies; /* set netdev watchdog timer */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * spider_net_release_tx_descr - processes a used tx descriptor |
| 696 | * @card: card structure |
| 697 | * @descr: descriptor to release |
| 698 | * |
| 699 | * releases a used tx descriptor (unmapping, freeing of skb) |
| 700 | */ |
| 701 | static inline void |
| 702 | spider_net_release_tx_descr(struct spider_net_card *card) |
| 703 | { |
| 704 | struct spider_net_descr *descr = card->tx_chain.tail; |
| 705 | struct sk_buff *skb; |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 706 | unsigned int len; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 707 | |
| 708 | card->tx_chain.tail = card->tx_chain.tail->next; |
| 709 | descr->dmac_cmd_status |= SPIDER_NET_DESCR_NOT_IN_USE; |
| 710 | |
| 711 | /* unmap the skb */ |
| 712 | skb = descr->skb; |
Linas Vepstas | c3fee4c | 2006-10-10 16:00:04 -0500 | [diff] [blame] | 713 | if (!skb) |
| 714 | return; |
Linas Vepstas | 808999c | 2006-10-10 16:01:00 -0500 | [diff] [blame] | 715 | len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len; |
| 716 | pci_unmap_single(card->pdev, descr->buf_addr, len, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 717 | PCI_DMA_TODEVICE); |
Linas Vepstas | 68a8c60 | 2006-10-10 16:13:05 -0500 | [diff] [blame^] | 718 | dev_kfree_skb(skb); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 719 | } |
| 720 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 721 | static void |
| 722 | spider_net_set_low_watermark(struct spider_net_card *card) |
| 723 | { |
| 724 | int status; |
| 725 | int cnt=0; |
| 726 | int i; |
| 727 | struct spider_net_descr *descr = card->tx_chain.tail; |
| 728 | |
| 729 | /* Measure the length of the queue. */ |
| 730 | while (descr != card->tx_chain.head) { |
| 731 | status = descr->dmac_cmd_status & SPIDER_NET_DESCR_NOT_IN_USE; |
| 732 | if (status == SPIDER_NET_DESCR_NOT_IN_USE) |
| 733 | break; |
| 734 | descr = descr->next; |
| 735 | cnt++; |
| 736 | } |
| 737 | |
| 738 | /* If TX queue is short, don't even bother with interrupts */ |
| 739 | if (cnt < card->tx_desc/4) |
| 740 | return; |
| 741 | |
| 742 | /* Set low-watermark 3/4th's of the way into the queue. */ |
| 743 | descr = card->tx_chain.tail; |
| 744 | cnt = (cnt*3)/4; |
| 745 | for (i=0;i<cnt; i++) |
| 746 | descr = descr->next; |
| 747 | |
| 748 | /* Set the new watermark, clear the old watermark */ |
| 749 | descr->dmac_cmd_status |= SPIDER_NET_DESCR_TXDESFLG; |
| 750 | if (card->low_watermark && card->low_watermark != descr) |
| 751 | card->low_watermark->dmac_cmd_status = |
| 752 | card->low_watermark->dmac_cmd_status & ~SPIDER_NET_DESCR_TXDESFLG; |
| 753 | card->low_watermark = descr; |
| 754 | } |
| 755 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 756 | /** |
| 757 | * spider_net_release_tx_chain - processes sent tx descriptors |
| 758 | * @card: adapter structure |
| 759 | * @brutal: if set, don't care about whether descriptor seems to be in use |
| 760 | * |
| 761 | * returns 0 if the tx ring is empty, otherwise 1. |
| 762 | * |
| 763 | * spider_net_release_tx_chain releases the tx descriptors that spider has |
| 764 | * finished with (if non-brutal) or simply release tx descriptors (if brutal). |
| 765 | * If some other context is calling this function, we return 1 so that we're |
| 766 | * scheduled again (if we were scheduled) and will not loose initiative. |
| 767 | */ |
| 768 | static int |
| 769 | spider_net_release_tx_chain(struct spider_net_card *card, int brutal) |
| 770 | { |
| 771 | struct spider_net_descr_chain *chain = &card->tx_chain; |
| 772 | int status; |
| 773 | |
| 774 | spider_net_read_reg(card, SPIDER_NET_GDTDMACCNTR); |
| 775 | |
| 776 | while (chain->tail != chain->head) { |
| 777 | status = spider_net_get_descr_status(chain->tail); |
| 778 | switch (status) { |
| 779 | case SPIDER_NET_DESCR_COMPLETE: |
| 780 | card->netdev_stats.tx_packets++; |
| 781 | card->netdev_stats.tx_bytes += chain->tail->skb->len; |
| 782 | break; |
| 783 | |
| 784 | case SPIDER_NET_DESCR_CARDOWNED: |
| 785 | if (!brutal) |
| 786 | return 1; |
| 787 | /* fallthrough, if we release the descriptors |
| 788 | * brutally (then we don't care about |
| 789 | * SPIDER_NET_DESCR_CARDOWNED) */ |
| 790 | |
| 791 | case SPIDER_NET_DESCR_RESPONSE_ERROR: |
| 792 | case SPIDER_NET_DESCR_PROTECTION_ERROR: |
| 793 | case SPIDER_NET_DESCR_FORCE_END: |
| 794 | if (netif_msg_tx_err(card)) |
| 795 | pr_err("%s: forcing end of tx descriptor " |
| 796 | "with status x%02x\n", |
| 797 | card->netdev->name, status); |
| 798 | card->netdev_stats.tx_errors++; |
| 799 | break; |
| 800 | |
| 801 | default: |
| 802 | card->netdev_stats.tx_dropped++; |
Linas Vepstas | c3fee4c | 2006-10-10 16:00:04 -0500 | [diff] [blame] | 803 | if (!brutal) |
| 804 | return 1; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 805 | } |
| 806 | spider_net_release_tx_descr(card); |
| 807 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * spider_net_kick_tx_dma - enables TX DMA processing |
| 814 | * @card: card structure |
| 815 | * @descr: descriptor address to enable TX processing at |
| 816 | * |
| 817 | * spider_net_kick_tx_dma writes the current tx chain head as start address |
| 818 | * of the tx descriptor chain and enables the transmission DMA engine |
| 819 | */ |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 820 | static inline void |
| 821 | spider_net_kick_tx_dma(struct spider_net_card *card) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 822 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 823 | struct spider_net_descr *descr; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 824 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 825 | if (spider_net_read_reg(card, SPIDER_NET_GDTDMACCNTR) & |
| 826 | SPIDER_NET_TX_DMA_EN) |
| 827 | goto out; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 828 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 829 | descr = card->tx_chain.tail; |
| 830 | for (;;) { |
| 831 | if (spider_net_get_descr_status(descr) == |
| 832 | SPIDER_NET_DESCR_CARDOWNED) { |
| 833 | spider_net_write_reg(card, SPIDER_NET_GDTDCHA, |
| 834 | descr->bus_addr); |
| 835 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, |
| 836 | SPIDER_NET_DMA_TX_VALUE); |
| 837 | break; |
| 838 | } |
| 839 | if (descr == card->tx_chain.head) |
| 840 | break; |
| 841 | descr = descr->next; |
| 842 | } |
| 843 | |
| 844 | out: |
| 845 | mod_timer(&card->tx_timer, jiffies + SPIDER_NET_TX_TIMER); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /** |
| 849 | * spider_net_xmit - transmits a frame over the device |
| 850 | * @skb: packet to send out |
| 851 | * @netdev: interface device structure |
| 852 | * |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 853 | * returns 0 on success, !0 on failure |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 854 | */ |
| 855 | static int |
| 856 | spider_net_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 857 | { |
| 858 | struct spider_net_card *card = netdev_priv(netdev); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 859 | struct spider_net_descr_chain *chain = &card->tx_chain; |
| 860 | struct spider_net_descr *descr = chain->head; |
| 861 | unsigned long flags; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 862 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 863 | spin_lock_irqsave(&chain->lock, flags); |
| 864 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 865 | spider_net_release_tx_chain(card, 0); |
| 866 | |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 867 | if ((chain->head->next == chain->tail->prev) || |
| 868 | (spider_net_get_descr_status(descr) != SPIDER_NET_DESCR_NOT_IN_USE) || |
| 869 | (spider_net_prepare_tx_descr(card, skb) != 0)) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 870 | |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 871 | card->netdev_stats.tx_dropped++; |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 872 | spin_unlock_irqrestore(&chain->lock, flags); |
| 873 | netif_stop_queue(netdev); |
| 874 | return NETDEV_TX_BUSY; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 875 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 876 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 877 | spider_net_set_low_watermark(card); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 878 | spider_net_kick_tx_dma(card); |
| 879 | card->tx_chain.head = card->tx_chain.head->next; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 880 | spin_unlock_irqrestore(&chain->lock, flags); |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 881 | return NETDEV_TX_OK; |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | /** |
| 885 | * spider_net_cleanup_tx_ring - cleans up the TX ring |
| 886 | * @card: card structure |
| 887 | * |
Linas Vepstas | 68a8c60 | 2006-10-10 16:13:05 -0500 | [diff] [blame^] | 888 | * spider_net_cleanup_tx_ring is called by either the tx_timer |
| 889 | * or from the NAPI polling routine. |
| 890 | * This routine releases resources associted with transmitted |
| 891 | * packets, including updating the queue tail pointer. |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 892 | */ |
| 893 | static void |
| 894 | spider_net_cleanup_tx_ring(struct spider_net_card *card) |
| 895 | { |
| 896 | unsigned long flags; |
| 897 | |
| 898 | spin_lock_irqsave(&card->tx_chain.lock, flags); |
| 899 | |
| 900 | if ((spider_net_release_tx_chain(card, 0) != 0) && |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 901 | (card->netdev->flags & IFF_UP)) { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 902 | spider_net_kick_tx_dma(card); |
Linas Vepstas | 313ef4b | 2006-10-10 16:04:00 -0500 | [diff] [blame] | 903 | netif_wake_queue(card->netdev); |
| 904 | } |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 905 | spin_unlock_irqrestore(&card->tx_chain.lock, flags); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | /** |
| 909 | * spider_net_do_ioctl - called for device ioctls |
| 910 | * @netdev: interface device structure |
| 911 | * @ifr: request parameter structure for ioctl |
| 912 | * @cmd: command code for ioctl |
| 913 | * |
| 914 | * returns 0 on success, <0 on failure. Currently, we have no special ioctls. |
| 915 | * -EOPNOTSUPP is returned, if an unknown ioctl was requested |
| 916 | */ |
| 917 | static int |
| 918 | spider_net_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 919 | { |
| 920 | switch (cmd) { |
| 921 | default: |
| 922 | return -EOPNOTSUPP; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on |
| 928 | * @descr: descriptor to process |
| 929 | * @card: card structure |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 930 | * @napi: whether caller is in NAPI context |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 931 | * |
| 932 | * returns 1 on success, 0 if no packet was passed to the stack |
| 933 | * |
| 934 | * iommu-unmaps the skb, fills out skb structure and passes the data to the |
| 935 | * stack. The descriptor state is not changed. |
| 936 | */ |
| 937 | static int |
| 938 | spider_net_pass_skb_up(struct spider_net_descr *descr, |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 939 | struct spider_net_card *card, int napi) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 940 | { |
| 941 | struct sk_buff *skb; |
| 942 | struct net_device *netdev; |
| 943 | u32 data_status, data_error; |
| 944 | |
| 945 | data_status = descr->data_status; |
| 946 | data_error = descr->data_error; |
| 947 | |
| 948 | netdev = card->netdev; |
| 949 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 950 | /* unmap descriptor */ |
| 951 | pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_FRAME, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 952 | PCI_DMA_FROMDEVICE); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 953 | |
| 954 | /* the cases we'll throw away the packet immediately */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 955 | if (data_error & SPIDER_NET_DESTROY_RX_FLAGS) { |
| 956 | if (netif_msg_rx_err(card)) |
| 957 | pr_err("error in received descriptor found, " |
| 958 | "data_status=x%08x, data_error=x%08x\n", |
| 959 | data_status, data_error); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 960 | card->spider_stats.rx_desc_error++; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 961 | return 0; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 962 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 963 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 964 | skb = descr->skb; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 965 | skb->dev = netdev; |
| 966 | skb_put(skb, descr->valid_size); |
| 967 | |
| 968 | /* the card seems to add 2 bytes of junk in front |
| 969 | * of the ethernet frame */ |
| 970 | #define SPIDER_MISALIGN 2 |
| 971 | skb_pull(skb, SPIDER_MISALIGN); |
| 972 | skb->protocol = eth_type_trans(skb, netdev); |
| 973 | |
| 974 | /* checksum offload */ |
| 975 | if (card->options.rx_csum) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 976 | if ( ( (data_status & SPIDER_NET_DATA_STATUS_CKSUM_MASK) == |
| 977 | SPIDER_NET_DATA_STATUS_CKSUM_MASK) && |
| 978 | !(data_error & SPIDER_NET_DATA_ERR_CKSUM_MASK)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 979 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 980 | else |
| 981 | skb->ip_summed = CHECKSUM_NONE; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 982 | } else |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 983 | skb->ip_summed = CHECKSUM_NONE; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 984 | |
| 985 | if (data_status & SPIDER_NET_VLAN_PACKET) { |
| 986 | /* further enhancements: HW-accel VLAN |
| 987 | * vlan_hwaccel_receive_skb |
| 988 | */ |
| 989 | } |
| 990 | |
| 991 | /* pass skb up to stack */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 992 | if (napi) |
| 993 | netif_receive_skb(skb); |
| 994 | else |
| 995 | netif_rx_ni(skb); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 996 | |
| 997 | /* update netdevice statistics */ |
| 998 | card->netdev_stats.rx_packets++; |
| 999 | card->netdev_stats.rx_bytes += skb->len; |
| 1000 | |
| 1001 | return 1; |
| 1002 | } |
| 1003 | |
| 1004 | /** |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1005 | * spider_net_decode_one_descr - processes an rx descriptor |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1006 | * @card: card structure |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1007 | * @napi: whether caller is in NAPI context |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1008 | * |
| 1009 | * returns 1 if a packet has been sent to the stack, otherwise 0 |
| 1010 | * |
| 1011 | * processes an rx descriptor by iommu-unmapping the data buffer and passing |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1012 | * the packet up to the stack. This function is called in softirq |
| 1013 | * context, e.g. either bottom half from interrupt or NAPI polling context |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1014 | */ |
| 1015 | static int |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1016 | spider_net_decode_one_descr(struct spider_net_card *card, int napi) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1017 | { |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1018 | struct spider_net_descr_chain *chain = &card->rx_chain; |
| 1019 | struct spider_net_descr *descr = chain->tail; |
| 1020 | int status; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1021 | int result; |
| 1022 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1023 | status = spider_net_get_descr_status(descr); |
| 1024 | |
| 1025 | if (status == SPIDER_NET_DESCR_CARDOWNED) { |
| 1026 | /* nothing in the descriptor yet */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1027 | result=0; |
| 1028 | goto out; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | if (status == SPIDER_NET_DESCR_NOT_IN_USE) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1032 | /* not initialized yet, the ring must be empty */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1033 | spider_net_refill_rx_chain(card); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1034 | spider_net_enable_rxdmac(card); |
| 1035 | result=0; |
| 1036 | goto out; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1039 | /* descriptor definitively used -- move on tail */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1040 | chain->tail = descr->next; |
| 1041 | |
| 1042 | result = 0; |
| 1043 | if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) || |
| 1044 | (status == SPIDER_NET_DESCR_PROTECTION_ERROR) || |
| 1045 | (status == SPIDER_NET_DESCR_FORCE_END) ) { |
| 1046 | if (netif_msg_rx_err(card)) |
| 1047 | pr_err("%s: dropping RX descriptor with state %d\n", |
| 1048 | card->netdev->name, status); |
| 1049 | card->netdev_stats.rx_dropped++; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1050 | pci_unmap_single(card->pdev, descr->buf_addr, |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1051 | SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1052 | dev_kfree_skb_irq(descr->skb); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1053 | goto refill; |
| 1054 | } |
| 1055 | |
| 1056 | if ( (status != SPIDER_NET_DESCR_COMPLETE) && |
| 1057 | (status != SPIDER_NET_DESCR_FRAME_END) ) { |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 1058 | if (netif_msg_rx_err(card)) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1059 | pr_err("%s: RX descriptor with state %d\n", |
| 1060 | card->netdev->name, status); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 1061 | card->spider_stats.rx_desc_unk_state++; |
| 1062 | } |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1063 | goto refill; |
| 1064 | } |
| 1065 | |
| 1066 | /* ok, we've got a packet in descr */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1067 | result = spider_net_pass_skb_up(descr, card, napi); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1068 | refill: |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1069 | descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1070 | /* change the descriptor state: */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1071 | if (!napi) |
| 1072 | spider_net_refill_rx_chain(card); |
| 1073 | out: |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1074 | return result; |
| 1075 | } |
| 1076 | |
| 1077 | /** |
| 1078 | * spider_net_poll - NAPI poll function called by the stack to return packets |
| 1079 | * @netdev: interface device structure |
| 1080 | * @budget: number of packets we can pass to the stack at most |
| 1081 | * |
| 1082 | * returns 0 if no more packets available to the driver/stack. Returns 1, |
| 1083 | * if the quota is exceeded, but the driver has still packets. |
| 1084 | * |
| 1085 | * spider_net_poll returns all packets from the rx descriptors to the stack |
| 1086 | * (using netif_receive_skb). If all/enough packets are up, the driver |
| 1087 | * reenables interrupts and returns 0. If not, 1 is returned. |
| 1088 | */ |
| 1089 | static int |
| 1090 | spider_net_poll(struct net_device *netdev, int *budget) |
| 1091 | { |
| 1092 | struct spider_net_card *card = netdev_priv(netdev); |
| 1093 | int packets_to_do, packets_done = 0; |
| 1094 | int no_more_packets = 0; |
| 1095 | |
Linas Vepstas | 68a8c60 | 2006-10-10 16:13:05 -0500 | [diff] [blame^] | 1096 | spider_net_cleanup_tx_ring(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1097 | packets_to_do = min(*budget, netdev->quota); |
| 1098 | |
| 1099 | while (packets_to_do) { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1100 | if (spider_net_decode_one_descr(card, 1)) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1101 | packets_done++; |
| 1102 | packets_to_do--; |
| 1103 | } else { |
| 1104 | /* no more packets for the stack */ |
| 1105 | no_more_packets = 1; |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | netdev->quota -= packets_done; |
| 1111 | *budget -= packets_done; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1112 | spider_net_refill_rx_chain(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1113 | |
| 1114 | /* if all packets are in the stack, enable interrupts and return 0 */ |
| 1115 | /* if not, return 1 */ |
| 1116 | if (no_more_packets) { |
| 1117 | netif_rx_complete(netdev); |
| 1118 | spider_net_rx_irq_on(card); |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
| 1122 | return 1; |
| 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * spider_net_vlan_rx_reg - initializes VLAN structures in the driver and card |
| 1127 | * @netdev: interface device structure |
| 1128 | * @grp: vlan_group structure that is registered (NULL on destroying interface) |
| 1129 | */ |
| 1130 | static void |
| 1131 | spider_net_vlan_rx_reg(struct net_device *netdev, struct vlan_group *grp) |
| 1132 | { |
| 1133 | /* further enhancement... yet to do */ |
| 1134 | return; |
| 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * spider_net_vlan_rx_add - adds VLAN id to the card filter |
| 1139 | * @netdev: interface device structure |
| 1140 | * @vid: VLAN id to add |
| 1141 | */ |
| 1142 | static void |
| 1143 | spider_net_vlan_rx_add(struct net_device *netdev, uint16_t vid) |
| 1144 | { |
| 1145 | /* further enhancement... yet to do */ |
| 1146 | /* add vid to card's VLAN filter table */ |
| 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * spider_net_vlan_rx_kill - removes VLAN id to the card filter |
| 1152 | * @netdev: interface device structure |
| 1153 | * @vid: VLAN id to remove |
| 1154 | */ |
| 1155 | static void |
| 1156 | spider_net_vlan_rx_kill(struct net_device *netdev, uint16_t vid) |
| 1157 | { |
| 1158 | /* further enhancement... yet to do */ |
| 1159 | /* remove vid from card's VLAN filter table */ |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * spider_net_get_stats - get interface statistics |
| 1164 | * @netdev: interface device structure |
| 1165 | * |
| 1166 | * returns the interface statistics residing in the spider_net_card struct |
| 1167 | */ |
| 1168 | static struct net_device_stats * |
| 1169 | spider_net_get_stats(struct net_device *netdev) |
| 1170 | { |
| 1171 | struct spider_net_card *card = netdev_priv(netdev); |
| 1172 | struct net_device_stats *stats = &card->netdev_stats; |
| 1173 | return stats; |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * spider_net_change_mtu - changes the MTU of an interface |
| 1178 | * @netdev: interface device structure |
| 1179 | * @new_mtu: new MTU value |
| 1180 | * |
| 1181 | * returns 0 on success, <0 on failure |
| 1182 | */ |
| 1183 | static int |
| 1184 | spider_net_change_mtu(struct net_device *netdev, int new_mtu) |
| 1185 | { |
| 1186 | /* no need to re-alloc skbs or so -- the max mtu is about 2.3k |
| 1187 | * and mtu is outbound only anyway */ |
| 1188 | if ( (new_mtu < SPIDER_NET_MIN_MTU ) || |
| 1189 | (new_mtu > SPIDER_NET_MAX_MTU) ) |
| 1190 | return -EINVAL; |
| 1191 | netdev->mtu = new_mtu; |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * spider_net_set_mac - sets the MAC of an interface |
| 1197 | * @netdev: interface device structure |
| 1198 | * @ptr: pointer to new MAC address |
| 1199 | * |
| 1200 | * Returns 0 on success, <0 on failure. Currently, we don't support this |
| 1201 | * and will always return EOPNOTSUPP. |
| 1202 | */ |
| 1203 | static int |
| 1204 | spider_net_set_mac(struct net_device *netdev, void *p) |
| 1205 | { |
| 1206 | struct spider_net_card *card = netdev_priv(netdev); |
Jens Osterkamp | 054034d | 2005-09-06 19:30:55 -0700 | [diff] [blame] | 1207 | u32 macl, macu, regvalue; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1208 | struct sockaddr *addr = p; |
| 1209 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1210 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1211 | return -EADDRNOTAVAIL; |
| 1212 | |
Jens Osterkamp | 054034d | 2005-09-06 19:30:55 -0700 | [diff] [blame] | 1213 | /* switch off GMACTPE and GMACRPE */ |
| 1214 | regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD); |
| 1215 | regvalue &= ~((1 << 5) | (1 << 6)); |
| 1216 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); |
| 1217 | |
| 1218 | /* write mac */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1219 | macu = (addr->sa_data[0]<<24) + (addr->sa_data[1]<<16) + |
| 1220 | (addr->sa_data[2]<<8) + (addr->sa_data[3]); |
| 1221 | macl = (addr->sa_data[4]<<8) + (addr->sa_data[5]); |
| 1222 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACU, macu); |
| 1223 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACL, macl); |
| 1224 | |
Jens Osterkamp | 054034d | 2005-09-06 19:30:55 -0700 | [diff] [blame] | 1225 | /* switch GMACTPE and GMACRPE back on */ |
| 1226 | regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD); |
| 1227 | regvalue |= ((1 << 5) | (1 << 6)); |
| 1228 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue); |
| 1229 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1230 | spider_net_set_promisc(card); |
| 1231 | |
| 1232 | /* look up, whether we have been successful */ |
| 1233 | if (spider_net_get_mac_address(netdev)) |
| 1234 | return -EADDRNOTAVAIL; |
| 1235 | if (memcmp(netdev->dev_addr,addr->sa_data,netdev->addr_len)) |
| 1236 | return -EADDRNOTAVAIL; |
| 1237 | |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1242 | * spider_net_handle_rxram_full - cleans up RX ring upon RX RAM full interrupt |
| 1243 | * @card: card structure |
| 1244 | * |
| 1245 | * spider_net_handle_rxram_full empties the RX ring so that spider can put |
| 1246 | * more packets in it and empty its RX RAM. This is called in bottom half |
| 1247 | * context |
| 1248 | */ |
| 1249 | static void |
| 1250 | spider_net_handle_rxram_full(struct spider_net_card *card) |
| 1251 | { |
| 1252 | while (spider_net_decode_one_descr(card, 0)) |
| 1253 | ; |
| 1254 | spider_net_enable_rxchtails(card); |
| 1255 | spider_net_enable_rxdmac(card); |
| 1256 | netif_rx_schedule(card->netdev); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1260 | * spider_net_handle_error_irq - handles errors raised by an interrupt |
| 1261 | * @card: card structure |
| 1262 | * @status_reg: interrupt status register 0 (GHIINT0STS) |
| 1263 | * |
| 1264 | * spider_net_handle_error_irq treats or ignores all error conditions |
| 1265 | * found when an interrupt is presented |
| 1266 | */ |
| 1267 | static void |
| 1268 | spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg) |
| 1269 | { |
| 1270 | u32 error_reg1, error_reg2; |
| 1271 | u32 i; |
| 1272 | int show_error = 1; |
| 1273 | |
| 1274 | error_reg1 = spider_net_read_reg(card, SPIDER_NET_GHIINT1STS); |
| 1275 | error_reg2 = spider_net_read_reg(card, SPIDER_NET_GHIINT2STS); |
| 1276 | |
| 1277 | /* check GHIINT0STS ************************************/ |
| 1278 | if (status_reg) |
| 1279 | for (i = 0; i < 32; i++) |
| 1280 | if (status_reg & (1<<i)) |
| 1281 | switch (i) |
| 1282 | { |
| 1283 | /* let error_reg1 and error_reg2 evaluation decide, what to do |
| 1284 | case SPIDER_NET_PHYINT: |
| 1285 | case SPIDER_NET_GMAC2INT: |
| 1286 | case SPIDER_NET_GMAC1INT: |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1287 | case SPIDER_NET_GFIFOINT: |
| 1288 | case SPIDER_NET_DMACINT: |
| 1289 | case SPIDER_NET_GSYSINT: |
| 1290 | break; */ |
| 1291 | |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1292 | case SPIDER_NET_GIPSINT: |
| 1293 | show_error = 0; |
| 1294 | break; |
| 1295 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1296 | case SPIDER_NET_GPWOPCMPINT: |
| 1297 | /* PHY write operation completed */ |
| 1298 | show_error = 0; |
| 1299 | break; |
| 1300 | case SPIDER_NET_GPROPCMPINT: |
| 1301 | /* PHY read operation completed */ |
| 1302 | /* we don't use semaphores, as we poll for the completion |
| 1303 | * of the read operation in spider_net_read_phy. Should take |
| 1304 | * about 50 us */ |
| 1305 | show_error = 0; |
| 1306 | break; |
| 1307 | case SPIDER_NET_GPWFFINT: |
| 1308 | /* PHY command queue full */ |
| 1309 | if (netif_msg_intr(card)) |
| 1310 | pr_err("PHY write queue full\n"); |
| 1311 | show_error = 0; |
| 1312 | break; |
| 1313 | |
| 1314 | /* case SPIDER_NET_GRMDADRINT: not used. print a message */ |
| 1315 | /* case SPIDER_NET_GRMARPINT: not used. print a message */ |
| 1316 | /* case SPIDER_NET_GRMMPINT: not used. print a message */ |
| 1317 | |
| 1318 | case SPIDER_NET_GDTDEN0INT: |
| 1319 | /* someone has set TX_DMA_EN to 0 */ |
| 1320 | show_error = 0; |
| 1321 | break; |
| 1322 | |
| 1323 | case SPIDER_NET_GDDDEN0INT: /* fallthrough */ |
| 1324 | case SPIDER_NET_GDCDEN0INT: /* fallthrough */ |
| 1325 | case SPIDER_NET_GDBDEN0INT: /* fallthrough */ |
| 1326 | case SPIDER_NET_GDADEN0INT: |
| 1327 | /* someone has set RX_DMA_EN to 0 */ |
| 1328 | show_error = 0; |
| 1329 | break; |
| 1330 | |
| 1331 | /* RX interrupts */ |
| 1332 | case SPIDER_NET_GDDFDCINT: |
| 1333 | case SPIDER_NET_GDCFDCINT: |
| 1334 | case SPIDER_NET_GDBFDCINT: |
| 1335 | case SPIDER_NET_GDAFDCINT: |
| 1336 | /* case SPIDER_NET_GDNMINT: not used. print a message */ |
| 1337 | /* case SPIDER_NET_GCNMINT: not used. print a message */ |
| 1338 | /* case SPIDER_NET_GBNMINT: not used. print a message */ |
| 1339 | /* case SPIDER_NET_GANMINT: not used. print a message */ |
| 1340 | /* case SPIDER_NET_GRFNMINT: not used. print a message */ |
| 1341 | show_error = 0; |
| 1342 | break; |
| 1343 | |
| 1344 | /* TX interrupts */ |
| 1345 | case SPIDER_NET_GDTFDCINT: |
| 1346 | show_error = 0; |
| 1347 | break; |
| 1348 | case SPIDER_NET_GTTEDINT: |
| 1349 | show_error = 0; |
| 1350 | break; |
| 1351 | case SPIDER_NET_GDTDCEINT: |
| 1352 | /* chain end. If a descriptor should be sent, kick off |
| 1353 | * tx dma |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1354 | if (card->tx_chain.tail != card->tx_chain.head) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1355 | spider_net_kick_tx_dma(card); |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1356 | */ |
| 1357 | show_error = 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1358 | break; |
| 1359 | |
| 1360 | /* case SPIDER_NET_G1TMCNTINT: not used. print a message */ |
| 1361 | /* case SPIDER_NET_GFREECNTINT: not used. print a message */ |
| 1362 | } |
| 1363 | |
| 1364 | /* check GHIINT1STS ************************************/ |
| 1365 | if (error_reg1) |
| 1366 | for (i = 0; i < 32; i++) |
| 1367 | if (error_reg1 & (1<<i)) |
| 1368 | switch (i) |
| 1369 | { |
| 1370 | case SPIDER_NET_GTMFLLINT: |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1371 | if (netif_msg_intr(card) && net_ratelimit()) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1372 | pr_err("Spider TX RAM full\n"); |
| 1373 | show_error = 0; |
| 1374 | break; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1375 | case SPIDER_NET_GRFDFLLINT: /* fallthrough */ |
| 1376 | case SPIDER_NET_GRFCFLLINT: /* fallthrough */ |
| 1377 | case SPIDER_NET_GRFBFLLINT: /* fallthrough */ |
| 1378 | case SPIDER_NET_GRFAFLLINT: /* fallthrough */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1379 | case SPIDER_NET_GRMFLLINT: |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1380 | if (netif_msg_intr(card) && net_ratelimit()) |
Jens Osterkamp | 4e5077b | 2006-03-28 15:59:55 +0200 | [diff] [blame] | 1381 | pr_debug("Spider RX RAM full, incoming packets " |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1382 | "might be discarded!\n"); |
| 1383 | spider_net_rx_irq_off(card); |
| 1384 | tasklet_schedule(&card->rxram_full_tl); |
| 1385 | show_error = 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1386 | break; |
| 1387 | |
| 1388 | /* case SPIDER_NET_GTMSHTINT: problem, print a message */ |
| 1389 | case SPIDER_NET_GDTINVDINT: |
| 1390 | /* allrighty. tx from previous descr ok */ |
| 1391 | show_error = 0; |
| 1392 | break; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1393 | |
| 1394 | /* chain end */ |
| 1395 | case SPIDER_NET_GDDDCEINT: /* fallthrough */ |
| 1396 | case SPIDER_NET_GDCDCEINT: /* fallthrough */ |
| 1397 | case SPIDER_NET_GDBDCEINT: /* fallthrough */ |
| 1398 | case SPIDER_NET_GDADCEINT: |
| 1399 | if (netif_msg_intr(card)) |
| 1400 | pr_err("got descriptor chain end interrupt, " |
| 1401 | "restarting DMAC %c.\n", |
Linas Vepstas | 37aad75 | 2006-10-10 16:06:53 -0500 | [diff] [blame] | 1402 | 'D'-(i-SPIDER_NET_GDDDCEINT)/3); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1403 | spider_net_refill_rx_chain(card); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1404 | spider_net_enable_rxdmac(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1405 | show_error = 0; |
| 1406 | break; |
| 1407 | |
| 1408 | /* invalid descriptor */ |
| 1409 | case SPIDER_NET_GDDINVDINT: /* fallthrough */ |
| 1410 | case SPIDER_NET_GDCINVDINT: /* fallthrough */ |
| 1411 | case SPIDER_NET_GDBINVDINT: /* fallthrough */ |
| 1412 | case SPIDER_NET_GDAINVDINT: |
| 1413 | /* could happen when rx chain is full */ |
| 1414 | spider_net_refill_rx_chain(card); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1415 | spider_net_enable_rxdmac(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1416 | show_error = 0; |
| 1417 | break; |
| 1418 | |
| 1419 | /* case SPIDER_NET_GDTRSERINT: problem, print a message */ |
| 1420 | /* case SPIDER_NET_GDDRSERINT: problem, print a message */ |
| 1421 | /* case SPIDER_NET_GDCRSERINT: problem, print a message */ |
| 1422 | /* case SPIDER_NET_GDBRSERINT: problem, print a message */ |
| 1423 | /* case SPIDER_NET_GDARSERINT: problem, print a message */ |
| 1424 | /* case SPIDER_NET_GDSERINT: problem, print a message */ |
| 1425 | /* case SPIDER_NET_GDTPTERINT: problem, print a message */ |
| 1426 | /* case SPIDER_NET_GDDPTERINT: problem, print a message */ |
| 1427 | /* case SPIDER_NET_GDCPTERINT: problem, print a message */ |
| 1428 | /* case SPIDER_NET_GDBPTERINT: problem, print a message */ |
| 1429 | /* case SPIDER_NET_GDAPTERINT: problem, print a message */ |
| 1430 | default: |
| 1431 | show_error = 1; |
| 1432 | break; |
| 1433 | } |
| 1434 | |
| 1435 | /* check GHIINT2STS ************************************/ |
| 1436 | if (error_reg2) |
| 1437 | for (i = 0; i < 32; i++) |
| 1438 | if (error_reg2 & (1<<i)) |
| 1439 | switch (i) |
| 1440 | { |
| 1441 | /* there is nothing we can (want to) do at this time. Log a |
| 1442 | * message, we can switch on and off the specific values later on |
| 1443 | case SPIDER_NET_GPROPERINT: |
| 1444 | case SPIDER_NET_GMCTCRSNGINT: |
| 1445 | case SPIDER_NET_GMCTLCOLINT: |
| 1446 | case SPIDER_NET_GMCTTMOTINT: |
| 1447 | case SPIDER_NET_GMCRCAERINT: |
| 1448 | case SPIDER_NET_GMCRCALERINT: |
| 1449 | case SPIDER_NET_GMCRALNERINT: |
| 1450 | case SPIDER_NET_GMCROVRINT: |
| 1451 | case SPIDER_NET_GMCRRNTINT: |
| 1452 | case SPIDER_NET_GMCRRXERINT: |
| 1453 | case SPIDER_NET_GTITCSERINT: |
| 1454 | case SPIDER_NET_GTIFMTERINT: |
| 1455 | case SPIDER_NET_GTIPKTRVKINT: |
| 1456 | case SPIDER_NET_GTISPINGINT: |
| 1457 | case SPIDER_NET_GTISADNGINT: |
| 1458 | case SPIDER_NET_GTISPDNGINT: |
| 1459 | case SPIDER_NET_GRIFMTERINT: |
| 1460 | case SPIDER_NET_GRIPKTRVKINT: |
| 1461 | case SPIDER_NET_GRISPINGINT: |
| 1462 | case SPIDER_NET_GRISADNGINT: |
| 1463 | case SPIDER_NET_GRISPDNGINT: |
| 1464 | break; |
| 1465 | */ |
| 1466 | default: |
| 1467 | break; |
| 1468 | } |
| 1469 | |
| 1470 | if ((show_error) && (netif_msg_intr(card))) |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1471 | pr_err("Got error interrupt on %s, GHIINT0STS = 0x%08x, " |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1472 | "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n", |
Linas Vepstas | 98b9040 | 2006-10-10 16:08:42 -0500 | [diff] [blame] | 1473 | card->netdev->name, |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1474 | status_reg, error_reg1, error_reg2); |
| 1475 | |
| 1476 | /* clear interrupt sources */ |
| 1477 | spider_net_write_reg(card, SPIDER_NET_GHIINT1STS, error_reg1); |
| 1478 | spider_net_write_reg(card, SPIDER_NET_GHIINT2STS, error_reg2); |
| 1479 | } |
| 1480 | |
| 1481 | /** |
| 1482 | * spider_net_interrupt - interrupt handler for spider_net |
| 1483 | * @irq: interupt number |
| 1484 | * @ptr: pointer to net_device |
| 1485 | * @regs: PU registers |
| 1486 | * |
| 1487 | * returns IRQ_HANDLED, if interrupt was for driver, or IRQ_NONE, if no |
| 1488 | * interrupt found raised by card. |
| 1489 | * |
| 1490 | * This is the interrupt handler, that turns off |
| 1491 | * interrupts for this device and makes the stack poll the driver |
| 1492 | */ |
| 1493 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1494 | spider_net_interrupt(int irq, void *ptr) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1495 | { |
| 1496 | struct net_device *netdev = ptr; |
| 1497 | struct spider_net_card *card = netdev_priv(netdev); |
| 1498 | u32 status_reg; |
| 1499 | |
| 1500 | status_reg = spider_net_read_reg(card, SPIDER_NET_GHIINT0STS); |
| 1501 | |
| 1502 | if (!status_reg) |
| 1503 | return IRQ_NONE; |
| 1504 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1505 | if (status_reg & SPIDER_NET_RXINT ) { |
| 1506 | spider_net_rx_irq_off(card); |
| 1507 | netif_rx_schedule(netdev); |
| 1508 | } |
Linas Vepstas | 68a8c60 | 2006-10-10 16:13:05 -0500 | [diff] [blame^] | 1509 | if (status_reg & SPIDER_NET_TXINT) |
| 1510 | netif_rx_schedule(netdev); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1511 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1512 | if (status_reg & SPIDER_NET_ERRINT ) |
| 1513 | spider_net_handle_error_irq(card, status_reg); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1514 | |
| 1515 | /* clear interrupt sources */ |
| 1516 | spider_net_write_reg(card, SPIDER_NET_GHIINT0STS, status_reg); |
| 1517 | |
| 1518 | return IRQ_HANDLED; |
| 1519 | } |
| 1520 | |
| 1521 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1522 | /** |
| 1523 | * spider_net_poll_controller - artificial interrupt for netconsole etc. |
| 1524 | * @netdev: interface device structure |
| 1525 | * |
| 1526 | * see Documentation/networking/netconsole.txt |
| 1527 | */ |
| 1528 | static void |
| 1529 | spider_net_poll_controller(struct net_device *netdev) |
| 1530 | { |
| 1531 | disable_irq(netdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1532 | spider_net_interrupt(netdev->irq, netdev); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1533 | enable_irq(netdev->irq); |
| 1534 | } |
| 1535 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 1536 | |
| 1537 | /** |
| 1538 | * spider_net_init_card - initializes the card |
| 1539 | * @card: card structure |
| 1540 | * |
| 1541 | * spider_net_init_card initializes the card so that other registers can |
| 1542 | * be used |
| 1543 | */ |
| 1544 | static void |
| 1545 | spider_net_init_card(struct spider_net_card *card) |
| 1546 | { |
| 1547 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1548 | SPIDER_NET_CKRCTRL_STOP_VALUE); |
| 1549 | |
| 1550 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1551 | SPIDER_NET_CKRCTRL_RUN_VALUE); |
| 1552 | } |
| 1553 | |
| 1554 | /** |
| 1555 | * spider_net_enable_card - enables the card by setting all kinds of regs |
| 1556 | * @card: card structure |
| 1557 | * |
| 1558 | * spider_net_enable_card sets a lot of SMMIO registers to enable the device |
| 1559 | */ |
| 1560 | static void |
| 1561 | spider_net_enable_card(struct spider_net_card *card) |
| 1562 | { |
| 1563 | int i; |
| 1564 | /* the following array consists of (register),(value) pairs |
| 1565 | * that are set in this function. A register of 0 ends the list */ |
| 1566 | u32 regs[][2] = { |
| 1567 | { SPIDER_NET_GRESUMINTNUM, 0 }, |
| 1568 | { SPIDER_NET_GREINTNUM, 0 }, |
| 1569 | |
| 1570 | /* set interrupt frame number registers */ |
| 1571 | /* clear the single DMA engine registers first */ |
| 1572 | { SPIDER_NET_GFAFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1573 | { SPIDER_NET_GFBFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1574 | { SPIDER_NET_GFCFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1575 | { SPIDER_NET_GFDFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, |
| 1576 | /* then set, what we really need */ |
| 1577 | { SPIDER_NET_GFFRMNUM, SPIDER_NET_FRAMENUM_VALUE }, |
| 1578 | |
| 1579 | /* timer counter registers and stuff */ |
| 1580 | { SPIDER_NET_GFREECNNUM, 0 }, |
| 1581 | { SPIDER_NET_GONETIMENUM, 0 }, |
| 1582 | { SPIDER_NET_GTOUTFRMNUM, 0 }, |
| 1583 | |
| 1584 | /* RX mode setting */ |
| 1585 | { SPIDER_NET_GRXMDSET, SPIDER_NET_RXMODE_VALUE }, |
| 1586 | /* TX mode setting */ |
| 1587 | { SPIDER_NET_GTXMDSET, SPIDER_NET_TXMODE_VALUE }, |
| 1588 | /* IPSEC mode setting */ |
| 1589 | { SPIDER_NET_GIPSECINIT, SPIDER_NET_IPSECINIT_VALUE }, |
| 1590 | |
| 1591 | { SPIDER_NET_GFTRESTRT, SPIDER_NET_RESTART_VALUE }, |
| 1592 | |
| 1593 | { SPIDER_NET_GMRWOLCTRL, 0 }, |
Jens Osterkamp | b636d17 | 2006-05-04 05:59:56 -0400 | [diff] [blame] | 1594 | { SPIDER_NET_GTESTMD, 0x10000000 }, |
| 1595 | { SPIDER_NET_GTTQMSK, 0x00400040 }, |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1596 | |
| 1597 | { SPIDER_NET_GMACINTEN, 0 }, |
| 1598 | |
| 1599 | /* flow control stuff */ |
| 1600 | { SPIDER_NET_GMACAPAUSE, SPIDER_NET_MACAPAUSE_VALUE }, |
| 1601 | { SPIDER_NET_GMACTXPAUSE, SPIDER_NET_TXPAUSE_VALUE }, |
| 1602 | |
| 1603 | { SPIDER_NET_GMACBSTLMT, SPIDER_NET_BURSTLMT_VALUE }, |
| 1604 | { 0, 0} |
| 1605 | }; |
| 1606 | |
| 1607 | i = 0; |
| 1608 | while (regs[i][0]) { |
| 1609 | spider_net_write_reg(card, regs[i][0], regs[i][1]); |
| 1610 | i++; |
| 1611 | } |
| 1612 | |
| 1613 | /* clear unicast filter table entries 1 to 14 */ |
| 1614 | for (i = 1; i <= 14; i++) { |
| 1615 | spider_net_write_reg(card, |
| 1616 | SPIDER_NET_GMRUAFILnR + i * 8, |
| 1617 | 0x00080000); |
| 1618 | spider_net_write_reg(card, |
| 1619 | SPIDER_NET_GMRUAFILnR + i * 8 + 4, |
| 1620 | 0x00000000); |
| 1621 | } |
| 1622 | |
| 1623 | spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, 0x08080000); |
| 1624 | |
| 1625 | spider_net_write_reg(card, SPIDER_NET_ECMODE, SPIDER_NET_ECMODE_VALUE); |
| 1626 | |
| 1627 | /* set chain tail adress for RX chains and |
| 1628 | * enable DMA */ |
| 1629 | spider_net_enable_rxchtails(card); |
| 1630 | spider_net_enable_rxdmac(card); |
| 1631 | |
| 1632 | spider_net_write_reg(card, SPIDER_NET_GRXDMAEN, SPIDER_NET_WOL_VALUE); |
| 1633 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1634 | spider_net_write_reg(card, SPIDER_NET_GMACLENLMT, |
| 1635 | SPIDER_NET_LENLMT_VALUE); |
| 1636 | spider_net_write_reg(card, SPIDER_NET_GMACMODE, |
| 1637 | SPIDER_NET_MACMODE_VALUE); |
| 1638 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, |
| 1639 | SPIDER_NET_OPMODE_VALUE); |
| 1640 | |
| 1641 | /* set interrupt mask registers */ |
| 1642 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, |
| 1643 | SPIDER_NET_INT0_MASK_VALUE); |
| 1644 | spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, |
| 1645 | SPIDER_NET_INT1_MASK_VALUE); |
| 1646 | spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, |
| 1647 | SPIDER_NET_INT2_MASK_VALUE); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1648 | |
| 1649 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, |
Linas Vepstas | ded8028 | 2006-10-10 16:02:54 -0500 | [diff] [blame] | 1650 | SPIDER_NET_GDTBSTA | SPIDER_NET_GDTDCEIDIS); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | /** |
| 1654 | * spider_net_open - called upon ifonfig up |
| 1655 | * @netdev: interface device structure |
| 1656 | * |
| 1657 | * returns 0 on success, <0 on failure |
| 1658 | * |
| 1659 | * spider_net_open allocates all the descriptors and memory needed for |
| 1660 | * operation, sets up multicast list and enables interrupts |
| 1661 | */ |
| 1662 | int |
| 1663 | spider_net_open(struct net_device *netdev) |
| 1664 | { |
| 1665 | struct spider_net_card *card = netdev_priv(netdev); |
| 1666 | int result; |
| 1667 | |
| 1668 | result = -ENOMEM; |
Jim Lewis | b68a60e | 2006-08-14 23:00:23 -0700 | [diff] [blame] | 1669 | if (spider_net_init_chain(card, &card->tx_chain, card->descr, |
| 1670 | PCI_DMA_TODEVICE, card->tx_desc)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1671 | goto alloc_tx_failed; |
Linas Vepstas | b21606a | 2006-10-10 16:09:40 -0500 | [diff] [blame] | 1672 | |
Linas Vepstas | 204e5fa | 2006-10-10 16:11:33 -0500 | [diff] [blame] | 1673 | card->low_watermark = NULL; |
| 1674 | |
Linas Vepstas | b21606a | 2006-10-10 16:09:40 -0500 | [diff] [blame] | 1675 | /* rx_chain is after tx_chain, so offset is descr + tx_count */ |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1676 | if (spider_net_init_chain(card, &card->rx_chain, |
Linas Vepstas | b21606a | 2006-10-10 16:09:40 -0500 | [diff] [blame] | 1677 | card->descr + card->tx_desc, |
Jim Lewis | b68a60e | 2006-08-14 23:00:23 -0700 | [diff] [blame] | 1678 | PCI_DMA_FROMDEVICE, card->rx_desc)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1679 | goto alloc_rx_failed; |
| 1680 | |
| 1681 | /* allocate rx skbs */ |
| 1682 | if (spider_net_alloc_rx_skbs(card)) |
| 1683 | goto alloc_skbs_failed; |
| 1684 | |
| 1685 | spider_net_set_multi(netdev); |
| 1686 | |
| 1687 | /* further enhancement: setup hw vlan, if needed */ |
| 1688 | |
| 1689 | result = -EBUSY; |
| 1690 | if (request_irq(netdev->irq, spider_net_interrupt, |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 1691 | IRQF_SHARED, netdev->name, netdev)) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1692 | goto register_int_failed; |
| 1693 | |
| 1694 | spider_net_enable_card(card); |
| 1695 | |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 1696 | netif_start_queue(netdev); |
| 1697 | netif_carrier_on(netdev); |
| 1698 | netif_poll_enable(netdev); |
| 1699 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1700 | return 0; |
| 1701 | |
| 1702 | register_int_failed: |
| 1703 | spider_net_free_rx_chain_contents(card); |
| 1704 | alloc_skbs_failed: |
| 1705 | spider_net_free_chain(card, &card->rx_chain); |
| 1706 | alloc_rx_failed: |
| 1707 | spider_net_free_chain(card, &card->tx_chain); |
| 1708 | alloc_tx_failed: |
| 1709 | return result; |
| 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * spider_net_setup_phy - setup PHY |
| 1714 | * @card: card structure |
| 1715 | * |
| 1716 | * returns 0 on success, <0 on failure |
| 1717 | * |
| 1718 | * spider_net_setup_phy is used as part of spider_net_probe. Sets |
| 1719 | * the PHY to 1000 Mbps |
| 1720 | **/ |
| 1721 | static int |
| 1722 | spider_net_setup_phy(struct spider_net_card *card) |
| 1723 | { |
| 1724 | struct mii_phy *phy = &card->phy; |
| 1725 | |
| 1726 | spider_net_write_reg(card, SPIDER_NET_GDTDMASEL, |
| 1727 | SPIDER_NET_DMASEL_VALUE); |
| 1728 | spider_net_write_reg(card, SPIDER_NET_GPCCTRL, |
| 1729 | SPIDER_NET_PHY_CTRL_VALUE); |
| 1730 | phy->mii_id = 1; |
| 1731 | phy->dev = card->netdev; |
| 1732 | phy->mdio_read = spider_net_read_phy; |
| 1733 | phy->mdio_write = spider_net_write_phy; |
| 1734 | |
| 1735 | mii_phy_probe(phy, phy->mii_id); |
| 1736 | |
| 1737 | if (phy->def->ops->setup_forced) |
| 1738 | phy->def->ops->setup_forced(phy, SPEED_1000, DUPLEX_FULL); |
| 1739 | |
Jens Osterkamp | 8ec9345 | 2006-05-04 05:59:41 -0400 | [diff] [blame] | 1740 | phy->def->ops->enable_fiber(phy); |
Jens Osterkamp | 53abbf7 | 2005-09-16 08:55:33 +0200 | [diff] [blame] | 1741 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1742 | phy->def->ops->read_link(phy); |
| 1743 | pr_info("Found %s with %i Mbps, %s-duplex.\n", phy->def->name, |
| 1744 | phy->speed, phy->duplex==1 ? "Full" : "Half"); |
| 1745 | |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
| 1749 | /** |
| 1750 | * spider_net_download_firmware - loads firmware into the adapter |
| 1751 | * @card: card structure |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1752 | * @firmware_ptr: pointer to firmware data |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1753 | * |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1754 | * spider_net_download_firmware loads the firmware data into the |
| 1755 | * adapter. It assumes the length etc. to be allright. |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1756 | */ |
Arnd Bergmann | 0d3ea16 | 2006-01-12 17:16:41 -0500 | [diff] [blame] | 1757 | static int |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1758 | spider_net_download_firmware(struct spider_net_card *card, |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1759 | const void *firmware_ptr) |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1760 | { |
| 1761 | int sequencer, i; |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1762 | const u32 *fw_ptr = firmware_ptr; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1763 | |
| 1764 | /* stop sequencers */ |
| 1765 | spider_net_write_reg(card, SPIDER_NET_GSINIT, |
| 1766 | SPIDER_NET_STOP_SEQ_VALUE); |
| 1767 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1768 | for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS; |
| 1769 | sequencer++) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1770 | spider_net_write_reg(card, |
| 1771 | SPIDER_NET_GSnPRGADR + sequencer * 8, 0); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1772 | for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1773 | spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + |
| 1774 | sequencer * 8, *fw_ptr); |
| 1775 | fw_ptr++; |
| 1776 | } |
| 1777 | } |
| 1778 | |
Arnd Bergmann | 0d3ea16 | 2006-01-12 17:16:41 -0500 | [diff] [blame] | 1779 | if (spider_net_read_reg(card, SPIDER_NET_GSINIT)) |
| 1780 | return -EIO; |
| 1781 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1782 | spider_net_write_reg(card, SPIDER_NET_GSINIT, |
| 1783 | SPIDER_NET_RUN_SEQ_VALUE); |
Arnd Bergmann | 0d3ea16 | 2006-01-12 17:16:41 -0500 | [diff] [blame] | 1784 | |
| 1785 | return 0; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * spider_net_init_firmware - reads in firmware parts |
| 1790 | * @card: card structure |
| 1791 | * |
| 1792 | * Returns 0 on success, <0 on failure |
| 1793 | * |
| 1794 | * spider_net_init_firmware opens the sequencer firmware and does some basic |
| 1795 | * checks. This function opens and releases the firmware structure. A call |
| 1796 | * to download the firmware is performed before the release. |
| 1797 | * |
| 1798 | * Firmware format |
| 1799 | * =============== |
| 1800 | * spider_fw.bin is expected to be a file containing 6*1024*4 bytes, 4k being |
| 1801 | * the program for each sequencer. Use the command |
| 1802 | * tail -q -n +2 Seq_code1_0x088.txt Seq_code2_0x090.txt \ |
| 1803 | * Seq_code3_0x098.txt Seq_code4_0x0A0.txt Seq_code5_0x0A8.txt \ |
| 1804 | * Seq_code6_0x0B0.txt | xxd -r -p -c4 > spider_fw.bin |
| 1805 | * |
| 1806 | * to generate spider_fw.bin, if you have sequencer programs with something |
| 1807 | * like the following contents for each sequencer: |
| 1808 | * <ONE LINE COMMENT> |
| 1809 | * <FIRST 4-BYTES-WORD FOR SEQUENCER> |
| 1810 | * <SECOND 4-BYTES-WORD FOR SEQUENCER> |
| 1811 | * ... |
| 1812 | * <1024th 4-BYTES-WORD FOR SEQUENCER> |
| 1813 | */ |
| 1814 | static int |
| 1815 | spider_net_init_firmware(struct spider_net_card *card) |
| 1816 | { |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1817 | struct firmware *firmware = NULL; |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1818 | struct device_node *dn; |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1819 | const u8 *fw_prop = NULL; |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1820 | int err = -ENOENT; |
| 1821 | int fw_size; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1822 | |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1823 | if (request_firmware((const struct firmware **)&firmware, |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1824 | SPIDER_NET_FIRMWARE_NAME, &card->pdev->dev) == 0) { |
| 1825 | if ( (firmware->size != SPIDER_NET_FIRMWARE_LEN) && |
| 1826 | netif_msg_probe(card) ) { |
| 1827 | pr_err("Incorrect size of spidernet firmware in " \ |
| 1828 | "filesystem. Looking in host firmware...\n"); |
| 1829 | goto try_host_fw; |
| 1830 | } |
| 1831 | err = spider_net_download_firmware(card, firmware->data); |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1832 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1833 | release_firmware(firmware); |
| 1834 | if (err) |
| 1835 | goto try_host_fw; |
Arnd Bergmann | 030d675 | 2006-01-12 17:16:42 -0500 | [diff] [blame] | 1836 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1837 | goto done; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1840 | try_host_fw: |
| 1841 | dn = pci_device_to_OF_node(card->pdev); |
| 1842 | if (!dn) |
| 1843 | goto out_err; |
| 1844 | |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 1845 | fw_prop = get_property(dn, "firmware", &fw_size); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1846 | if (!fw_prop) |
| 1847 | goto out_err; |
| 1848 | |
| 1849 | if ( (fw_size != SPIDER_NET_FIRMWARE_LEN) && |
| 1850 | netif_msg_probe(card) ) { |
| 1851 | pr_err("Incorrect size of spidernet firmware in " \ |
| 1852 | "host firmware\n"); |
| 1853 | goto done; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1856 | err = spider_net_download_firmware(card, fw_prop); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1857 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1858 | done: |
| 1859 | return err; |
| 1860 | out_err: |
| 1861 | if (netif_msg_probe(card)) |
| 1862 | pr_err("Couldn't find spidernet firmware in filesystem " \ |
| 1863 | "or host firmware\n"); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1864 | return err; |
| 1865 | } |
| 1866 | |
| 1867 | /** |
| 1868 | * spider_net_workaround_rxramfull - work around firmware bug |
| 1869 | * @card: card structure |
| 1870 | * |
| 1871 | * no return value |
| 1872 | **/ |
| 1873 | static void |
| 1874 | spider_net_workaround_rxramfull(struct spider_net_card *card) |
| 1875 | { |
| 1876 | int i, sequencer = 0; |
| 1877 | |
| 1878 | /* cancel reset */ |
| 1879 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1880 | SPIDER_NET_CKRCTRL_RUN_VALUE); |
| 1881 | |
| 1882 | /* empty sequencer data */ |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1883 | for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS; |
| 1884 | sequencer++) { |
Jens Osterkamp | ee962a5 | 2006-07-13 11:54:23 +0200 | [diff] [blame] | 1885 | spider_net_write_reg(card, SPIDER_NET_GSnPRGADR + |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1886 | sequencer * 8, 0x0); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 1887 | for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1888 | spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + |
| 1889 | sequencer * 8, 0x0); |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | /* set sequencer operation */ |
| 1894 | spider_net_write_reg(card, SPIDER_NET_GSINIT, 0x000000fe); |
| 1895 | |
| 1896 | /* reset */ |
| 1897 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 1898 | SPIDER_NET_CKRCTRL_STOP_VALUE); |
| 1899 | } |
| 1900 | |
| 1901 | /** |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1902 | * spider_net_stop - called upon ifconfig down |
| 1903 | * @netdev: interface device structure |
| 1904 | * |
| 1905 | * always returns 0 |
| 1906 | */ |
| 1907 | int |
| 1908 | spider_net_stop(struct net_device *netdev) |
| 1909 | { |
| 1910 | struct spider_net_card *card = netdev_priv(netdev); |
| 1911 | |
| 1912 | tasklet_kill(&card->rxram_full_tl); |
| 1913 | netif_poll_disable(netdev); |
| 1914 | netif_carrier_off(netdev); |
| 1915 | netif_stop_queue(netdev); |
| 1916 | del_timer_sync(&card->tx_timer); |
| 1917 | |
| 1918 | /* disable/mask all interrupts */ |
| 1919 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0); |
| 1920 | spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0); |
| 1921 | spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0); |
| 1922 | |
| 1923 | /* free_irq(netdev->irq, netdev);*/ |
| 1924 | free_irq(to_pci_dev(netdev->class_dev.dev)->irq, netdev); |
| 1925 | |
| 1926 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, |
| 1927 | SPIDER_NET_DMA_TX_FEND_VALUE); |
| 1928 | |
| 1929 | /* turn off DMA, force end */ |
| 1930 | spider_net_disable_rxdmac(card); |
| 1931 | |
| 1932 | /* release chains */ |
| 1933 | if (spin_trylock(&card->tx_chain.lock)) { |
| 1934 | spider_net_release_tx_chain(card, 1); |
| 1935 | spin_unlock(&card->tx_chain.lock); |
| 1936 | } |
| 1937 | |
| 1938 | spider_net_free_chain(card, &card->tx_chain); |
| 1939 | spider_net_free_chain(card, &card->rx_chain); |
| 1940 | |
| 1941 | return 0; |
| 1942 | } |
| 1943 | |
| 1944 | /** |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1945 | * spider_net_tx_timeout_task - task scheduled by the watchdog timeout |
| 1946 | * function (to be called not under interrupt status) |
| 1947 | * @data: data, is interface device structure |
| 1948 | * |
| 1949 | * called as task when tx hangs, resets interface (if interface is up) |
| 1950 | */ |
| 1951 | static void |
| 1952 | spider_net_tx_timeout_task(void *data) |
| 1953 | { |
| 1954 | struct net_device *netdev = data; |
| 1955 | struct spider_net_card *card = netdev_priv(netdev); |
| 1956 | |
| 1957 | if (!(netdev->flags & IFF_UP)) |
| 1958 | goto out; |
| 1959 | |
| 1960 | netif_device_detach(netdev); |
| 1961 | spider_net_stop(netdev); |
| 1962 | |
| 1963 | spider_net_workaround_rxramfull(card); |
| 1964 | spider_net_init_card(card); |
| 1965 | |
| 1966 | if (spider_net_setup_phy(card)) |
| 1967 | goto out; |
| 1968 | if (spider_net_init_firmware(card)) |
| 1969 | goto out; |
| 1970 | |
| 1971 | spider_net_open(netdev); |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 1972 | spider_net_kick_tx_dma(card); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1973 | netif_device_attach(netdev); |
| 1974 | |
| 1975 | out: |
| 1976 | atomic_dec(&card->tx_timeout_task_counter); |
| 1977 | } |
| 1978 | |
| 1979 | /** |
| 1980 | * spider_net_tx_timeout - called when the tx timeout watchdog kicks in. |
| 1981 | * @netdev: interface device structure |
| 1982 | * |
| 1983 | * called, if tx hangs. Schedules a task that resets the interface |
| 1984 | */ |
| 1985 | static void |
| 1986 | spider_net_tx_timeout(struct net_device *netdev) |
| 1987 | { |
| 1988 | struct spider_net_card *card; |
| 1989 | |
| 1990 | card = netdev_priv(netdev); |
| 1991 | atomic_inc(&card->tx_timeout_task_counter); |
| 1992 | if (netdev->flags & IFF_UP) |
| 1993 | schedule_work(&card->tx_timeout_task); |
| 1994 | else |
| 1995 | atomic_dec(&card->tx_timeout_task_counter); |
Jim Lewis | 9b6b0b8 | 2006-09-22 17:22:53 -0700 | [diff] [blame] | 1996 | card->spider_stats.tx_timeouts++; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | /** |
| 2000 | * spider_net_setup_netdev_ops - initialization of net_device operations |
| 2001 | * @netdev: net_device structure |
| 2002 | * |
| 2003 | * fills out function pointers in the net_device structure |
| 2004 | */ |
| 2005 | static void |
| 2006 | spider_net_setup_netdev_ops(struct net_device *netdev) |
| 2007 | { |
| 2008 | netdev->open = &spider_net_open; |
| 2009 | netdev->stop = &spider_net_stop; |
| 2010 | netdev->hard_start_xmit = &spider_net_xmit; |
| 2011 | netdev->get_stats = &spider_net_get_stats; |
| 2012 | netdev->set_multicast_list = &spider_net_set_multi; |
| 2013 | netdev->set_mac_address = &spider_net_set_mac; |
| 2014 | netdev->change_mtu = &spider_net_change_mtu; |
| 2015 | netdev->do_ioctl = &spider_net_do_ioctl; |
| 2016 | /* tx watchdog */ |
| 2017 | netdev->tx_timeout = &spider_net_tx_timeout; |
| 2018 | netdev->watchdog_timeo = SPIDER_NET_WATCHDOG_TIMEOUT; |
| 2019 | /* NAPI */ |
| 2020 | netdev->poll = &spider_net_poll; |
| 2021 | netdev->weight = SPIDER_NET_NAPI_WEIGHT; |
| 2022 | /* HW VLAN */ |
| 2023 | netdev->vlan_rx_register = &spider_net_vlan_rx_reg; |
| 2024 | netdev->vlan_rx_add_vid = &spider_net_vlan_rx_add; |
| 2025 | netdev->vlan_rx_kill_vid = &spider_net_vlan_rx_kill; |
| 2026 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2027 | /* poll controller */ |
| 2028 | netdev->poll_controller = &spider_net_poll_controller; |
| 2029 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 2030 | /* ethtool ops */ |
| 2031 | netdev->ethtool_ops = &spider_net_ethtool_ops; |
| 2032 | } |
| 2033 | |
| 2034 | /** |
| 2035 | * spider_net_setup_netdev - initialization of net_device |
| 2036 | * @card: card structure |
| 2037 | * |
| 2038 | * Returns 0 on success or <0 on failure |
| 2039 | * |
| 2040 | * spider_net_setup_netdev initializes the net_device structure |
| 2041 | **/ |
| 2042 | static int |
| 2043 | spider_net_setup_netdev(struct spider_net_card *card) |
| 2044 | { |
| 2045 | int result; |
| 2046 | struct net_device *netdev = card->netdev; |
| 2047 | struct device_node *dn; |
| 2048 | struct sockaddr addr; |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 2049 | const u8 *mac; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2050 | |
| 2051 | SET_MODULE_OWNER(netdev); |
| 2052 | SET_NETDEV_DEV(netdev, &card->pdev->dev); |
| 2053 | |
| 2054 | pci_set_drvdata(card->pdev, netdev); |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 2055 | |
Arnd Bergmann | 11f1a52 | 2006-01-12 17:16:44 -0500 | [diff] [blame] | 2056 | card->rxram_full_tl.data = (unsigned long) card; |
| 2057 | card->rxram_full_tl.func = |
| 2058 | (void (*)(unsigned long)) spider_net_handle_rxram_full; |
| 2059 | init_timer(&card->tx_timer); |
| 2060 | card->tx_timer.function = |
| 2061 | (void (*)(unsigned long)) spider_net_cleanup_tx_ring; |
| 2062 | card->tx_timer.data = (unsigned long) card; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2063 | netdev->irq = card->pdev->irq; |
| 2064 | |
| 2065 | card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT; |
| 2066 | |
Jim Lewis | b68a60e | 2006-08-14 23:00:23 -0700 | [diff] [blame] | 2067 | card->tx_desc = tx_descriptors; |
| 2068 | card->rx_desc = rx_descriptors; |
| 2069 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2070 | spider_net_setup_netdev_ops(netdev); |
| 2071 | |
Jens Osterkamp | bdd0150 | 2006-07-13 11:54:08 +0200 | [diff] [blame] | 2072 | netdev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2073 | /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | |
| 2074 | * NETIF_F_HW_VLAN_FILTER */ |
| 2075 | |
| 2076 | netdev->irq = card->pdev->irq; |
| 2077 | |
| 2078 | dn = pci_device_to_OF_node(card->pdev); |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 2079 | if (!dn) |
| 2080 | return -EIO; |
| 2081 | |
Jeremy Kerr | 1a2509c | 2006-07-12 15:41:03 +1000 | [diff] [blame] | 2082 | mac = get_property(dn, "local-mac-address", NULL); |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 2083 | if (!mac) |
| 2084 | return -EIO; |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2085 | memcpy(addr.sa_data, mac, ETH_ALEN); |
| 2086 | |
| 2087 | result = spider_net_set_mac(netdev, &addr); |
| 2088 | if ((result) && (netif_msg_probe(card))) |
| 2089 | pr_err("Failed to set MAC address: %i\n", result); |
| 2090 | |
| 2091 | result = register_netdev(netdev); |
| 2092 | if (result) { |
| 2093 | if (netif_msg_probe(card)) |
| 2094 | pr_err("Couldn't register net_device: %i\n", |
| 2095 | result); |
| 2096 | return result; |
| 2097 | } |
| 2098 | |
| 2099 | if (netif_msg_probe(card)) |
| 2100 | pr_info("Initialized device %s.\n", netdev->name); |
| 2101 | |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | /** |
| 2106 | * spider_net_alloc_card - allocates net_device and card structure |
| 2107 | * |
| 2108 | * returns the card structure or NULL in case of errors |
| 2109 | * |
| 2110 | * the card and net_device structures are linked to each other |
| 2111 | */ |
| 2112 | static struct spider_net_card * |
| 2113 | spider_net_alloc_card(void) |
| 2114 | { |
| 2115 | struct net_device *netdev; |
| 2116 | struct spider_net_card *card; |
| 2117 | size_t alloc_size; |
| 2118 | |
| 2119 | alloc_size = sizeof (*card) + |
| 2120 | sizeof (struct spider_net_descr) * rx_descriptors + |
| 2121 | sizeof (struct spider_net_descr) * tx_descriptors; |
| 2122 | netdev = alloc_etherdev(alloc_size); |
| 2123 | if (!netdev) |
| 2124 | return NULL; |
| 2125 | |
| 2126 | card = netdev_priv(netdev); |
| 2127 | card->netdev = netdev; |
| 2128 | card->msg_enable = SPIDER_NET_DEFAULT_MSG; |
| 2129 | INIT_WORK(&card->tx_timeout_task, spider_net_tx_timeout_task, netdev); |
| 2130 | init_waitqueue_head(&card->waitq); |
| 2131 | atomic_set(&card->tx_timeout_task_counter, 0); |
| 2132 | |
| 2133 | return card; |
| 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * spider_net_undo_pci_setup - releases PCI ressources |
| 2138 | * @card: card structure |
| 2139 | * |
| 2140 | * spider_net_undo_pci_setup releases the mapped regions |
| 2141 | */ |
| 2142 | static void |
| 2143 | spider_net_undo_pci_setup(struct spider_net_card *card) |
| 2144 | { |
| 2145 | iounmap(card->regs); |
| 2146 | pci_release_regions(card->pdev); |
| 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * spider_net_setup_pci_dev - sets up the device in terms of PCI operations |
| 2151 | * @card: card structure |
| 2152 | * @pdev: PCI device |
| 2153 | * |
| 2154 | * Returns the card structure or NULL if any errors occur |
| 2155 | * |
| 2156 | * spider_net_setup_pci_dev initializes pdev and together with the |
| 2157 | * functions called in spider_net_open configures the device so that |
| 2158 | * data can be transferred over it |
| 2159 | * The net_device structure is attached to the card structure, if the |
| 2160 | * function returns without error. |
| 2161 | **/ |
| 2162 | static struct spider_net_card * |
| 2163 | spider_net_setup_pci_dev(struct pci_dev *pdev) |
| 2164 | { |
| 2165 | struct spider_net_card *card; |
| 2166 | unsigned long mmio_start, mmio_len; |
| 2167 | |
| 2168 | if (pci_enable_device(pdev)) { |
| 2169 | pr_err("Couldn't enable PCI device\n"); |
| 2170 | return NULL; |
| 2171 | } |
| 2172 | |
| 2173 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 2174 | pr_err("Couldn't find proper PCI device base address.\n"); |
| 2175 | goto out_disable_dev; |
| 2176 | } |
| 2177 | |
| 2178 | if (pci_request_regions(pdev, spider_net_driver_name)) { |
| 2179 | pr_err("Couldn't obtain PCI resources, aborting.\n"); |
| 2180 | goto out_disable_dev; |
| 2181 | } |
| 2182 | |
| 2183 | pci_set_master(pdev); |
| 2184 | |
| 2185 | card = spider_net_alloc_card(); |
| 2186 | if (!card) { |
| 2187 | pr_err("Couldn't allocate net_device structure, " |
| 2188 | "aborting.\n"); |
| 2189 | goto out_release_regions; |
| 2190 | } |
| 2191 | card->pdev = pdev; |
| 2192 | |
| 2193 | /* fetch base address and length of first resource */ |
| 2194 | mmio_start = pci_resource_start(pdev, 0); |
| 2195 | mmio_len = pci_resource_len(pdev, 0); |
| 2196 | |
| 2197 | card->netdev->mem_start = mmio_start; |
| 2198 | card->netdev->mem_end = mmio_start + mmio_len; |
| 2199 | card->regs = ioremap(mmio_start, mmio_len); |
| 2200 | |
| 2201 | if (!card->regs) { |
| 2202 | pr_err("Couldn't obtain PCI resources, aborting.\n"); |
| 2203 | goto out_release_regions; |
| 2204 | } |
| 2205 | |
| 2206 | return card; |
| 2207 | |
| 2208 | out_release_regions: |
| 2209 | pci_release_regions(pdev); |
| 2210 | out_disable_dev: |
| 2211 | pci_disable_device(pdev); |
| 2212 | pci_set_drvdata(pdev, NULL); |
| 2213 | return NULL; |
| 2214 | } |
| 2215 | |
| 2216 | /** |
| 2217 | * spider_net_probe - initialization of a device |
| 2218 | * @pdev: PCI device |
| 2219 | * @ent: entry in the device id list |
| 2220 | * |
| 2221 | * Returns 0 on success, <0 on failure |
| 2222 | * |
| 2223 | * spider_net_probe initializes pdev and registers a net_device |
| 2224 | * structure for it. After that, the device can be ifconfig'ed up |
| 2225 | **/ |
| 2226 | static int __devinit |
| 2227 | spider_net_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 2228 | { |
| 2229 | int err = -EIO; |
| 2230 | struct spider_net_card *card; |
| 2231 | |
| 2232 | card = spider_net_setup_pci_dev(pdev); |
| 2233 | if (!card) |
| 2234 | goto out; |
| 2235 | |
| 2236 | spider_net_workaround_rxramfull(card); |
| 2237 | spider_net_init_card(card); |
| 2238 | |
| 2239 | err = spider_net_setup_phy(card); |
| 2240 | if (err) |
| 2241 | goto out_undo_pci; |
| 2242 | |
| 2243 | err = spider_net_init_firmware(card); |
| 2244 | if (err) |
| 2245 | goto out_undo_pci; |
| 2246 | |
| 2247 | err = spider_net_setup_netdev(card); |
| 2248 | if (err) |
| 2249 | goto out_undo_pci; |
| 2250 | |
| 2251 | return 0; |
| 2252 | |
| 2253 | out_undo_pci: |
| 2254 | spider_net_undo_pci_setup(card); |
| 2255 | free_netdev(card->netdev); |
| 2256 | out: |
| 2257 | return err; |
| 2258 | } |
| 2259 | |
| 2260 | /** |
| 2261 | * spider_net_remove - removal of a device |
| 2262 | * @pdev: PCI device |
| 2263 | * |
| 2264 | * Returns 0 on success, <0 on failure |
| 2265 | * |
| 2266 | * spider_net_remove is called to remove the device and unregisters the |
| 2267 | * net_device |
| 2268 | **/ |
| 2269 | static void __devexit |
| 2270 | spider_net_remove(struct pci_dev *pdev) |
| 2271 | { |
| 2272 | struct net_device *netdev; |
| 2273 | struct spider_net_card *card; |
| 2274 | |
| 2275 | netdev = pci_get_drvdata(pdev); |
| 2276 | card = netdev_priv(netdev); |
| 2277 | |
| 2278 | wait_event(card->waitq, |
| 2279 | atomic_read(&card->tx_timeout_task_counter) == 0); |
| 2280 | |
| 2281 | unregister_netdev(netdev); |
Jens Osterkamp | 543cec5 | 2005-09-06 19:30:54 -0700 | [diff] [blame] | 2282 | |
| 2283 | /* switch off card */ |
| 2284 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 2285 | SPIDER_NET_CKRCTRL_STOP_VALUE); |
| 2286 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, |
| 2287 | SPIDER_NET_CKRCTRL_RUN_VALUE); |
| 2288 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2289 | spider_net_undo_pci_setup(card); |
| 2290 | free_netdev(netdev); |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | static struct pci_driver spider_net_driver = { |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2294 | .name = spider_net_driver_name, |
| 2295 | .id_table = spider_net_pci_tbl, |
| 2296 | .probe = spider_net_probe, |
| 2297 | .remove = __devexit_p(spider_net_remove) |
| 2298 | }; |
| 2299 | |
| 2300 | /** |
| 2301 | * spider_net_init - init function when the driver is loaded |
| 2302 | * |
| 2303 | * spider_net_init registers the device driver |
| 2304 | */ |
| 2305 | static int __init spider_net_init(void) |
| 2306 | { |
Linas Vepstas | 90f1084 | 2006-10-10 15:56:04 -0500 | [diff] [blame] | 2307 | printk(KERN_INFO "Spidernet version %s.\n", VERSION); |
| 2308 | |
Jens Osterkamp | aaec0fa | 2005-09-05 15:19:29 -0700 | [diff] [blame] | 2309 | if (rx_descriptors < SPIDER_NET_RX_DESCRIPTORS_MIN) { |
| 2310 | rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MIN; |
| 2311 | pr_info("adjusting rx descriptors to %i.\n", rx_descriptors); |
| 2312 | } |
| 2313 | if (rx_descriptors > SPIDER_NET_RX_DESCRIPTORS_MAX) { |
| 2314 | rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MAX; |
| 2315 | pr_info("adjusting rx descriptors to %i.\n", rx_descriptors); |
| 2316 | } |
| 2317 | if (tx_descriptors < SPIDER_NET_TX_DESCRIPTORS_MIN) { |
| 2318 | tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MIN; |
| 2319 | pr_info("adjusting tx descriptors to %i.\n", tx_descriptors); |
| 2320 | } |
| 2321 | if (tx_descriptors > SPIDER_NET_TX_DESCRIPTORS_MAX) { |
| 2322 | tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MAX; |
| 2323 | pr_info("adjusting tx descriptors to %i.\n", tx_descriptors); |
| 2324 | } |
| 2325 | |
| 2326 | return pci_register_driver(&spider_net_driver); |
| 2327 | } |
| 2328 | |
| 2329 | /** |
| 2330 | * spider_net_cleanup - exit function when driver is unloaded |
| 2331 | * |
| 2332 | * spider_net_cleanup unregisters the device driver |
| 2333 | */ |
| 2334 | static void __exit spider_net_cleanup(void) |
| 2335 | { |
| 2336 | pci_unregister_driver(&spider_net_driver); |
| 2337 | } |
| 2338 | |
| 2339 | module_init(spider_net_init); |
| 2340 | module_exit(spider_net_cleanup); |