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