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