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