blob: fef455694d7ab221784d0c3dd562a0759dfe5bee [file] [log] [blame]
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001/*
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 Osterkampaaec0fa2005-09-05 15:19:29 -070024#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 Bergmann7c5c2202006-01-12 17:16:45 -050031#include <linux/in.h>
Jens Osterkampaaec0fa2005-09-05 15:19:29 -070032#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 Bergmann11f1a522006-01-12 17:16:44 -050045#include <linux/vmalloc.h>
Jens Osterkampaaec0fa2005-09-05 15:19:29 -070046#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
54MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com> and Jens Osterkamp " \
55 "<Jens.Osterkamp@de.ibm.com>");
56MODULE_DESCRIPTION("Spider Southbridge Gigabit Ethernet driver");
57MODULE_LICENSE("GPL");
Linas Vepstas90f10842006-10-10 15:56:04 -050058MODULE_VERSION(VERSION);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -070059
60static int rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_DEFAULT;
61static int tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_DEFAULT;
62
Linas Vepstase2874f22006-10-10 15:59:02 -050063module_param(rx_descriptors, int, 0444);
64module_param(tx_descriptors, int, 0444);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -070065
66MODULE_PARM_DESC(rx_descriptors, "number of descriptors used " \
67 "in rx chains");
68MODULE_PARM_DESC(tx_descriptors, "number of descriptors used " \
69 "in tx chain");
70
71char spider_net_driver_name[] = "spidernet";
72
73static 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
79MODULE_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 Osterkampbdd01502006-07-13 11:54:08 +020088static inline u32
Jens Osterkampaaec0fa2005-09-05 15:19:29 -070089spider_net_read_reg(struct spider_net_card *card, u32 reg)
90{
Benjamin Herrenschmidt3bc0f402006-11-11 17:25:13 +110091 /* 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 Osterkampaaec0fa2005-09-05 15:19:29 -070096}
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 Osterkampbdd01502006-07-13 11:54:08 +0200104static inline void
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700105spider_net_write_reg(struct spider_net_card *card, u32 reg, u32 value)
106{
Benjamin Herrenschmidt3bc0f402006-11-11 17:25:13 +1100107 /* 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 Osterkampaaec0fa2005-09-05 15:19:29 -0700112}
113
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700114/** 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 **/
124static void
125spider_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 **/
147static int
148spider_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 Ishizakiabdb66b2007-02-20 16:33:41 -0600169 * spider_net_setup_aneg - initial auto-negotiation setup
170 * @card: device structure
171 **/
172static void
173spider_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 Bergmann11f1a522006-01-12 17:16:44 -0500204 * 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 */
209static void
210spider_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 Osterkampaaec0fa2005-09-05 15:19:29 -0700219 * 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 */
224static void
225spider_net_rx_irq_on(struct spider_net_card *card)
226{
227 u32 regvalue;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700228
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500229 regvalue = SPIDER_NET_INT0_MASK_VALUE | SPIDER_NET_RXINT;
230 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, regvalue);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700231}
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 */
240static void
241spider_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 */
272static int
273spider_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 Osterkampbdd01502006-07-13 11:54:08 +0200300static inline int
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700301spider_net_get_descr_status(struct spider_net_descr *descr)
302{
Jens Osterkampbdd01502006-07-13 11:54:08 +0200303 return descr->dmac_cmd_status & SPIDER_NET_DESCR_IND_PROC_MASK;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700304}
305
306/**
307 * spider_net_free_chain - free descriptor chain
308 * @card: card structure
309 * @chain: address of chain
310 *
311 */
312static void
313spider_net_free_chain(struct spider_net_card *card,
314 struct spider_net_descr_chain *chain)
315{
316 struct spider_net_descr *descr;
317
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600318 descr = chain->ring;
319 do {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700320 descr->bus_addr = 0;
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600321 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 Osterkampaaec0fa2005-09-05 15:19:29 -0700327}
328
329/**
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600330 * spider_net_init_chain - alloc and link descriptor chain
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700331 * @card: card structure
332 * @chain: address of chain
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700333 *
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600334 * We manage a circular list that mirrors the hardware structure,
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700335 * except that the hardware uses bus addresses.
336 *
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600337 * Returns 0 on success, <0 on failure
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700338 */
339static int
340spider_net_init_chain(struct spider_net_card *card,
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600341 struct spider_net_descr_chain *chain)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700342{
343 int i;
344 struct spider_net_descr *descr;
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500345 dma_addr_t buf;
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600346 size_t alloc_size;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700347
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600348 alloc_size = chain->num_desc * sizeof (struct spider_net_descr);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700349
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600350 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 Osterkampbdd01502006-07-13 11:54:08 +0200362 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700363
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500364 descr->bus_addr = buf;
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600365 descr->next_descr_addr = 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700366 descr->next = descr + 1;
367 descr->prev = descr - 1;
368
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600369 buf += sizeof(struct spider_net_descr);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700370 }
371 /* do actual circular list */
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600372 (descr-1)->next = chain->ring;
373 chain->ring->prev = descr-1;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700374
Jens Osterkampbdd01502006-07-13 11:54:08 +0200375 spin_lock_init(&chain->lock);
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600376 chain->head = chain->ring;
377 chain->tail = chain->ring;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700378 return 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700379}
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 */
387static void
388spider_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 Vepstas64751912006-10-10 16:22:29 -0500393 do {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700394 if (descr->skb) {
395 dev_kfree_skb(descr->skb);
396 pci_unmap_single(card->pdev, descr->buf_addr,
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500397 SPIDER_NET_MAX_FRAME,
Linas Vepstas348bc2a2006-10-10 16:21:10 -0500398 PCI_DMA_BIDIRECTIONAL);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700399 }
400 descr = descr->next;
Linas Vepstas64751912006-10-10 16:22:29 -0500401 } while (descr != card->rx_chain.head);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700402}
403
404/**
Linas Vepstasa4182c52006-12-13 15:19:54 -0600405 * spider_net_prepare_rx_descr - Reinitialize RX descriptor
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700406 * @card: card structure
407 * @descr: descriptor to re-init
408 *
Linas Vepstasa4182c52006-12-13 15:19:54 -0600409 * Return 0 on succes, <0 on failure.
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700410 *
Linas Vepstasa4182c52006-12-13 15:19:54 -0600411 * Allocates a new rx skb, iommu-maps it and attaches it to the
412 * descriptor. Mark the descriptor as activated, ready-to-use.
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700413 */
414static int
415spider_net_prepare_rx_descr(struct spider_net_card *card,
416 struct spider_net_descr *descr)
417{
Arnd Bergmann8e0a6132006-01-12 17:16:43 -0500418 dma_addr_t buf;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700419 int offset;
420 int bufsize;
421
422 /* we need to round up the buffer size to a multiple of 128 */
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500423 bufsize = (SPIDER_NET_MAX_FRAME + SPIDER_NET_RXBUF_ALIGN - 1) &
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700424 (~(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 Bergmann11f1a522006-01-12 17:16:44 -0500431 if (netif_msg_rx_err(card) && net_ratelimit())
432 pr_err("Not enough memory to allocate rx buffer\n");
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700433 card->spider_stats.alloc_rx_skb_error++;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700434 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 Vepstasa4182c52006-12-13 15:19:54 -0600446 /* iommu-map the skb */
Arnd Bergmann8e0a6132006-01-12 17:16:43 -0500447 buf = pci_map_single(card->pdev, descr->skb->data,
Jens Osterkampbdd01502006-07-13 11:54:08 +0200448 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
Arnd Bergmann8e0a6132006-01-12 17:16:43 -0500449 descr->buf_addr = buf;
Olof Johanssond4b0a4c2006-09-27 14:02:26 -0500450 if (pci_dma_mapping_error(buf)) {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700451 dev_kfree_skb_any(descr->skb);
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500452 if (netif_msg_rx_err(card) && net_ratelimit())
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700453 pr_err("Could not iommu-map rx buffer\n");
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700454 card->spider_stats.rx_iommu_map_error++;
Jens Osterkampbdd01502006-07-13 11:54:08 +0200455 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700456 } else {
Linas Vepstasd9a97202007-02-05 16:29:43 -0800457 descr->next_descr_addr = 0;
Linas Vepstas90476a22006-12-13 15:22:04 -0600458 wmb();
Jens Osterkampbdd01502006-07-13 11:54:08 +0200459 descr->dmac_cmd_status = SPIDER_NET_DESCR_CARDOWNED |
460 SPIDER_NET_DMAC_NOINTR_COMPLETE;
Linas Vepstasd9a97202007-02-05 16:29:43 -0800461
462 wmb();
463 descr->prev->next_descr_addr = descr->bus_addr;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700464 }
465
Linas Vepstasa4182c52006-12-13 15:19:54 -0600466 return 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700467}
468
469/**
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500470 * spider_net_enable_rxchtails - sets RX dmac chain tail addresses
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700471 * @card: card structure
472 *
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500473 * spider_net_enable_rxchtails sets the RX DMAC chain tail adresses in the
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700474 * chip by writing to the appropriate register. DMA is enabled in
475 * spider_net_enable_rxdmac.
476 */
Jens Osterkampbdd01502006-07-13 11:54:08 +0200477static inline void
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700478spider_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 Osterkampbdd01502006-07-13 11:54:08 +0200492static inline void
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700493spider_net_enable_rxdmac(struct spider_net_card *card)
494{
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500495 wmb();
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700496 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 Bergmann11f1a522006-01-12 17:16:44 -0500504 * refills descriptors in the rx chain: allocates skbs and iommu-maps them.
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700505 */
506static void
507spider_net_refill_rx_chain(struct spider_net_card *card)
508{
Jens Osterkampbdd01502006-07-13 11:54:08 +0200509 struct spider_net_descr_chain *chain = &card->rx_chain;
510 unsigned long flags;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700511
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500512 /* 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 Osterkampbdd01502006-07-13 11:54:08 +0200516 if (!spin_trylock_irqsave(&chain->lock, flags))
517 return;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700518
Jens Osterkampbdd01502006-07-13 11:54:08 +0200519 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 Osterkampaaec0fa2005-09-05 15:19:29 -0700527}
528
529/**
Linas Vepstas2c307db2006-12-13 15:20:59 -0600530 * spider_net_alloc_rx_skbs - Allocates rx skbs in rx descriptor chains
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700531 * @card: card structure
532 *
Linas Vepstas2c307db2006-12-13 15:20:59 -0600533 * Returns 0 on success, <0 on failure.
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700534 */
535static int
536spider_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 Vepstas2c307db2006-12-13 15:20:59 -0600544 /* 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 Osterkampaaec0fa2005-09-05 15:19:29 -0700547 if (spider_net_prepare_rx_descr(card, chain->head))
548 goto error;
549 else
550 chain->head = chain->head->next;
551
Linas Vepstas2c307db2006-12-13 15:20:59 -0600552 /* This will allocate the rest of the rx buffers;
553 * if not, it's business as usual later on. */
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700554 spider_net_refill_rx_chain(card);
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500555 spider_net_enable_rxdmac(card);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700556 return 0;
557
558error:
559 spider_net_free_rx_chain_contents(card);
560 return result;
561}
562
563/**
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700564 * 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 */
572static u8
573spider_net_get_multicast_hash(struct net_device *netdev, __u8 *addr)
574{
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700575 u32 crc;
576 u8 hash;
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500577 char addr_for_crc[ETH_ALEN] = { 0, };
578 int i, bit;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700579
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500580 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 Osterkampaaec0fa2005-09-05 15:19:29 -0700586
587 hash = (crc >> 27);
588 hash <<= 3;
589 hash |= crc & 7;
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500590 hash &= 0xff;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700591
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 */
603static void
604spider_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
632write_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 */
658static void
659spider_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 Osterkampaaec0fa2005-09-05 15:19:29 -0700666 * 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 */
676static int
677spider_net_prepare_tx_descr(struct spider_net_card *card,
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700678 struct sk_buff *skb)
679{
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500680 struct spider_net_descr *descr;
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500681 dma_addr_t buf;
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500682 unsigned long flags;
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500683
James K Lewis9c434f52006-11-17 14:39:36 -0800684 buf = pci_map_single(card->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
Olof Johanssond4b0a4c2006-09-27 14:02:26 -0500685 if (pci_dma_mapping_error(buf)) {
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500686 if (netif_msg_tx_err(card) && net_ratelimit())
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700687 pr_err("could not iommu-map packet (%p, %i). "
James K Lewis9c434f52006-11-17 14:39:36 -0800688 "Dropping packet\n", skb->data, skb->len);
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700689 card->spider_stats.tx_iommu_map_error++;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700690 return -ENOMEM;
691 }
692
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500693 spin_lock_irqsave(&card->tx_chain.lock, flags);
694 descr = card->tx_chain.head;
695 card->tx_chain.head = descr->next;
696
Arnd Bergmann8e0a6132006-01-12 17:16:43 -0500697 descr->buf_addr = buf;
James K Lewis9c434f52006-11-17 14:39:36 -0800698 descr->buf_size = skb->len;
Jens Osterkampbdd01502006-07-13 11:54:08 +0200699 descr->next_descr_addr = 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700700 descr->skb = skb;
701 descr->data_status = 0;
702
Jens Osterkampbdd01502006-07-13 11:54:08 +0200703 descr->dmac_cmd_status =
704 SPIDER_NET_DESCR_CARDOWNED | SPIDER_NET_DMAC_NOCS;
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500705 spin_unlock_irqrestore(&card->tx_chain.lock, flags);
706
Jens Osterkampbdd01502006-07-13 11:54:08 +0200707 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 Vepstas204e5fa2006-10-10 16:11:33 -0500717 /* Chain the bus address, so that the DMA engine finds this descr. */
Jens Osterkampbdd01502006-07-13 11:54:08 +0200718 descr->prev->next_descr_addr = descr->bus_addr;
719
Linas Vepstas917a5b82006-10-10 16:01:51 -0500720 card->netdev->trans_start = jiffies; /* set netdev watchdog timer */
Jens Osterkampbdd01502006-07-13 11:54:08 +0200721 return 0;
722}
723
Linas Vepstasa664ccf2006-10-10 16:18:18 -0500724static int
Linas Vepstas204e5fa2006-10-10 16:11:33 -0500725spider_net_set_low_watermark(struct spider_net_card *card)
726{
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500727 unsigned long flags;
Linas Vepstas204e5fa2006-10-10 16:11:33 -0500728 int status;
729 int cnt=0;
730 int i;
731 struct spider_net_descr *descr = card->tx_chain.tail;
732
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500733 /* Measure the length of the queue. Measurement does not
734 * need to be precise -- does not need a lock. */
Linas Vepstas204e5fa2006-10-10 16:11:33 -0500735 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 Vepstasd4ed8f82006-12-13 15:06:59 -0600744 if (cnt < card->tx_chain.num_desc/4)
Linas Vepstasa664ccf2006-10-10 16:18:18 -0500745 return cnt;
Linas Vepstas204e5fa2006-10-10 16:11:33 -0500746
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 Vepstas9cc7bf7e2006-10-10 16:14:29 -0500754 spin_lock_irqsave(&card->tx_chain.lock, flags);
Linas Vepstas204e5fa2006-10-10 16:11:33 -0500755 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 Vepstas9cc7bf7e2006-10-10 16:14:29 -0500760 spin_unlock_irqrestore(&card->tx_chain.lock, flags);
Linas Vepstasa664ccf2006-10-10 16:18:18 -0500761 return cnt;
Linas Vepstas204e5fa2006-10-10 16:11:33 -0500762}
763
Jens Osterkampbdd01502006-07-13 11:54:08 +0200764/**
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 */
776static int
777spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
778{
779 struct spider_net_descr_chain *chain = &card->tx_chain;
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500780 struct spider_net_descr *descr;
781 struct sk_buff *skb;
782 u32 buf_addr;
783 unsigned long flags;
Jens Osterkampbdd01502006-07-13 11:54:08 +0200784 int status;
785
Jens Osterkampbdd01502006-07-13 11:54:08 +0200786 while (chain->tail != chain->head) {
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500787 spin_lock_irqsave(&chain->lock, flags);
788 descr = chain->tail;
789
790 status = spider_net_get_descr_status(descr);
Jens Osterkampbdd01502006-07-13 11:54:08 +0200791 switch (status) {
792 case SPIDER_NET_DESCR_COMPLETE:
793 card->netdev_stats.tx_packets++;
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500794 card->netdev_stats.tx_bytes += descr->skb->len;
Jens Osterkampbdd01502006-07-13 11:54:08 +0200795 break;
796
797 case SPIDER_NET_DESCR_CARDOWNED:
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500798 if (!brutal) {
799 spin_unlock_irqrestore(&chain->lock, flags);
Jens Osterkampbdd01502006-07-13 11:54:08 +0200800 return 1;
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500801 }
802
Jens Osterkampbdd01502006-07-13 11:54:08 +0200803 /* 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 Vepstas9cc7bf7e2006-10-10 16:14:29 -0500819 if (!brutal) {
820 spin_unlock_irqrestore(&chain->lock, flags);
Linas Vepstasc3fee4c2006-10-10 16:00:04 -0500821 return 1;
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500822 }
Jens Osterkampbdd01502006-07-13 11:54:08 +0200823 }
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700824
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500825 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 Lewis9c434f52006-11-17 14:39:36 -0800833 pci_unmap_single(card->pdev, buf_addr, skb->len,
834 PCI_DMA_TODEVICE);
Linas Vepstas9cc7bf7e2006-10-10 16:14:29 -0500835 dev_kfree_skb(skb);
836 }
837 }
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700838 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 Vepstasa664ccf2006-10-10 16:18:18 -0500846 * 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 Osterkampaaec0fa2005-09-05 15:19:29 -0700852 */
Jens Osterkampbdd01502006-07-13 11:54:08 +0200853static inline void
854spider_net_kick_tx_dma(struct spider_net_card *card)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700855{
Jens Osterkampbdd01502006-07-13 11:54:08 +0200856 struct spider_net_descr *descr;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700857
Jens Osterkampbdd01502006-07-13 11:54:08 +0200858 if (spider_net_read_reg(card, SPIDER_NET_GDTDMACCNTR) &
859 SPIDER_NET_TX_DMA_EN)
860 goto out;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700861
Jens Osterkampbdd01502006-07-13 11:54:08 +0200862 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
877out:
878 mod_timer(&card->tx_timer, jiffies + SPIDER_NET_TX_TIMER);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700879}
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 Osterkampbdd01502006-07-13 11:54:08 +0200886 * returns 0 on success, !0 on failure
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700887 */
888static int
889spider_net_xmit(struct sk_buff *skb, struct net_device *netdev)
890{
Linas Vepstasa664ccf2006-10-10 16:18:18 -0500891 int cnt;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700892 struct spider_net_card *card = netdev_priv(netdev);
Jens Osterkampbdd01502006-07-13 11:54:08 +0200893 struct spider_net_descr_chain *chain = &card->tx_chain;
Jens Osterkampbdd01502006-07-13 11:54:08 +0200894
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500895 spider_net_release_tx_chain(card, 0);
896
Linas Vepstas313ef4b2006-10-10 16:04:00 -0500897 if ((chain->head->next == chain->tail->prev) ||
Linas Vepstas313ef4b2006-10-10 16:04:00 -0500898 (spider_net_prepare_tx_descr(card, skb) != 0)) {
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500899
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700900 card->netdev_stats.tx_dropped++;
Linas Vepstas313ef4b2006-10-10 16:04:00 -0500901 netif_stop_queue(netdev);
902 return NETDEV_TX_BUSY;
Jens Osterkampbdd01502006-07-13 11:54:08 +0200903 }
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700904
Linas Vepstasa664ccf2006-10-10 16:18:18 -0500905 cnt = spider_net_set_low_watermark(card);
906 if (cnt < 5)
907 spider_net_kick_tx_dma(card);
Linas Vepstas313ef4b2006-10-10 16:04:00 -0500908 return NETDEV_TX_OK;
Jens Osterkampbdd01502006-07-13 11:54:08 +0200909}
910
911/**
912 * spider_net_cleanup_tx_ring - cleans up the TX ring
913 * @card: card structure
914 *
Linas Vepstas68a8c602006-10-10 16:13:05 -0500915 * 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 Osterkampbdd01502006-07-13 11:54:08 +0200919 */
920static void
921spider_net_cleanup_tx_ring(struct spider_net_card *card)
922{
Jens Osterkampbdd01502006-07-13 11:54:08 +0200923 if ((spider_net_release_tx_chain(card, 0) != 0) &&
Linas Vepstas313ef4b2006-10-10 16:04:00 -0500924 (card->netdev->flags & IFF_UP)) {
Jens Osterkampbdd01502006-07-13 11:54:08 +0200925 spider_net_kick_tx_dma(card);
Linas Vepstas313ef4b2006-10-10 16:04:00 -0500926 netif_wake_queue(card->netdev);
927 }
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700928}
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 */
939static int
940spider_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 Vepstas05b346b2006-12-13 15:15:15 -0600953 * Fills out skb structure and passes the data to the stack.
954 * The descriptor state is not changed.
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700955 */
Linas Vepstas7f7223b2006-12-13 15:17:39 -0600956static void
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700957spider_net_pass_skb_up(struct spider_net_descr *descr,
Linas Vepstas1cd173f2006-12-13 15:12:26 -0600958 struct spider_net_card *card)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700959{
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 Osterkampaaec0fa2005-09-05 15:19:29 -0700966 netdev = card->netdev;
967
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500968 skb = descr->skb;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700969 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 Bergmann11f1a522006-01-12 17:16:44 -0500980 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 Osterkampaaec0fa2005-09-05 15:19:29 -0700983 skb->ip_summed = CHECKSUM_UNNECESSARY;
984 else
985 skb->ip_summed = CHECKSUM_NONE;
Arnd Bergmann11f1a522006-01-12 17:16:44 -0500986 } else
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700987 skb->ip_summed = CHECKSUM_NONE;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700988
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 Vepstas1cd173f2006-12-13 15:12:26 -0600996 netif_receive_skb(skb);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700997
998 /* update netdevice statistics */
999 card->netdev_stats.rx_packets++;
1000 card->netdev_stats.rx_bytes += skb->len;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001001}
1002
Linas Vepstas6d249982006-12-13 15:23:56 -06001003#ifdef DEBUG
1004static 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 Osterkampaaec0fa2005-09-05 15:19:29 -07001031/**
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001032 * spider_net_decode_one_descr - processes an rx descriptor
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001033 * @card: card structure
1034 *
Linas Vepstas1cd173f2006-12-13 15:12:26 -06001035 * Returns 1 if a packet has been sent to the stack, otherwise 0
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001036 *
Linas Vepstas1cd173f2006-12-13 15:12:26 -06001037 * Processes an rx descriptor by iommu-unmapping the data buffer and passing
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001038 * 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 Osterkampaaec0fa2005-09-05 15:19:29 -07001040 */
1041static int
Linas Vepstas1cd173f2006-12-13 15:12:26 -06001042spider_net_decode_one_descr(struct spider_net_card *card)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001043{
Jens Osterkampbdd01502006-07-13 11:54:08 +02001044 struct spider_net_descr_chain *chain = &card->rx_chain;
1045 struct spider_net_descr *descr = chain->tail;
1046 int status;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001047
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001048 status = spider_net_get_descr_status(descr);
1049
Linas Vepstas80dab7c2006-12-13 15:18:52 -06001050 /* 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 Vepstas1cd173f2006-12-13 15:12:26 -06001053 return 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001054
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001055 /* descriptor definitively used -- move on tail */
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001056 chain->tail = descr->next;
1057
Linas Vepstas05b346b2006-12-13 15:15:15 -06001058 /* unmap descriptor */
1059 pci_unmap_single(card->pdev, descr->buf_addr,
1060 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
1061
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001062 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 Vepstas7f7223b2006-12-13 15:17:39 -06001069 goto bad_desc;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001070 }
1071
1072 if ( (status != SPIDER_NET_DESCR_COMPLETE) &&
1073 (status != SPIDER_NET_DESCR_FRAME_END) ) {
Linas Vepstas5a028872006-12-13 15:08:25 -06001074 if (netif_msg_rx_err(card))
Linas Vepstas05b346b2006-12-13 15:15:15 -06001075 pr_err("%s: RX descriptor with unkown state %d\n",
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001076 card->netdev->name, status);
Linas Vepstas5a028872006-12-13 15:08:25 -06001077 card->spider_stats.rx_desc_unk_state++;
Linas Vepstas7f7223b2006-12-13 15:17:39 -06001078 goto bad_desc;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001079 }
1080
Linas Vepstas366684b2006-12-13 15:16:18 -06001081 /* 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 Vepstas7f7223b2006-12-13 15:17:39 -06001088 goto bad_desc;
Linas Vepstas366684b2006-12-13 15:16:18 -06001089 }
1090
Linas Vepstas6d249982006-12-13 15:23:56 -06001091 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 Vepstas7f7223b2006-12-13 15:17:39 -06001109 /* Ok, we've got a packet in descr */
1110 spider_net_pass_skb_up(descr, card);
Linas Vepstas1cd173f2006-12-13 15:12:26 -06001111 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
Linas Vepstas7f7223b2006-12-13 15:17:39 -06001112 return 1;
1113
1114bad_desc:
1115 dev_kfree_skb_irq(descr->skb);
1116 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
1117 return 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001118}
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 */
1132static int
1133spider_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 Vepstas68a8c602006-10-10 16:13:05 -05001139 spider_net_cleanup_tx_ring(card);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001140 packets_to_do = min(*budget, netdev->quota);
1141
1142 while (packets_to_do) {
Linas Vepstas1cd173f2006-12-13 15:12:26 -06001143 if (spider_net_decode_one_descr(card)) {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001144 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 Bergmann11f1a522006-01-12 17:16:44 -05001155 spider_net_refill_rx_chain(card);
Linas Vepstas80dab7c2006-12-13 15:18:52 -06001156 spider_net_enable_rxdmac(card);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001157
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 */
1174static void
1175spider_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 */
1186static void
1187spider_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 */
1199static void
1200spider_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 */
1212static struct net_device_stats *
1213spider_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 */
1227static int
1228spider_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 */
1247static int
1248spider_net_set_mac(struct net_device *netdev, void *p)
1249{
1250 struct spider_net_card *card = netdev_priv(netdev);
Jens Osterkamp054034d2005-09-06 19:30:55 -07001251 u32 macl, macu, regvalue;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001252 struct sockaddr *addr = p;
1253
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001254 if (!is_valid_ether_addr(addr->sa_data))
1255 return -EADDRNOTAVAIL;
1256
Jens Osterkamp054034d2005-09-06 19:30:55 -07001257 /* 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 Osterkampaaec0fa2005-09-05 15:19:29 -07001263 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 Osterkamp054034d2005-09-06 19:30:55 -07001269 /* 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 Osterkampaaec0fa2005-09-05 15:19:29 -07001274 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 Ishizakiabdb66b2007-02-20 16:33:41 -06001286 * 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 */
1293static void
1294spider_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 Osterkampaaec0fa2005-09-05 15:19:29 -07001313 * 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 */
1320static void
1321spider_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 Osterkampaaec0fa2005-09-05 15:19:29 -07001340 case SPIDER_NET_GFIFOINT:
1341 case SPIDER_NET_DMACINT:
1342 case SPIDER_NET_GSYSINT:
1343 break; */
1344
Linas Vepstas98b90402006-10-10 16:08:42 -05001345 case SPIDER_NET_GIPSINT:
1346 show_error = 0;
1347 break;
1348
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001349 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 Vepstas98b90402006-10-10 16:08:42 -05001407 if (card->tx_chain.tail != card->tx_chain.head)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001408 spider_net_kick_tx_dma(card);
Linas Vepstas98b90402006-10-10 16:08:42 -05001409 */
1410 show_error = 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001411 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 Bergmann11f1a522006-01-12 17:16:44 -05001424 if (netif_msg_intr(card) && net_ratelimit())
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001425 pr_err("Spider TX RAM full\n");
1426 show_error = 0;
1427 break;
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001428 case SPIDER_NET_GRFDFLLINT: /* fallthrough */
1429 case SPIDER_NET_GRFCFLLINT: /* fallthrough */
1430 case SPIDER_NET_GRFBFLLINT: /* fallthrough */
1431 case SPIDER_NET_GRFAFLLINT: /* fallthrough */
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001432 case SPIDER_NET_GRMFLLINT:
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001433 if (netif_msg_intr(card) && net_ratelimit())
Linas Vepstas5a028872006-12-13 15:08:25 -06001434 pr_err("Spider RX RAM full, incoming packets "
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001435 "might be discarded!\n");
1436 spider_net_rx_irq_off(card);
Linas Vepstas75856172006-12-13 15:10:06 -06001437 netif_rx_schedule(card->netdev);
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001438 show_error = 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001439 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 Osterkampaaec0fa2005-09-05 15:19:29 -07001446
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 Vepstas5a028872006-12-13 15:08:25 -06001452 if (netif_msg_intr(card) && net_ratelimit())
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001453 pr_err("got descriptor chain end interrupt, "
1454 "restarting DMAC %c.\n",
Linas Vepstas37aad752006-10-10 16:06:53 -05001455 'D'-(i-SPIDER_NET_GDDDCEINT)/3);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001456 spider_net_refill_rx_chain(card);
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001457 spider_net_enable_rxdmac(card);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001458 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 Bergmann11f1a522006-01-12 17:16:44 -05001468 spider_net_enable_rxdmac(card);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001469 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 Vepstas5a028872006-12-13 15:08:25 -06001523 if ((show_error) && (netif_msg_intr(card)) && net_ratelimit())
Linas Vepstas98b90402006-10-10 16:08:42 -05001524 pr_err("Got error interrupt on %s, GHIINT0STS = 0x%08x, "
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001525 "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n",
Linas Vepstas98b90402006-10-10 16:08:42 -05001526 card->netdev->name,
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001527 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 */
1546static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001547spider_net_interrupt(int irq, void *ptr)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001548{
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 Osterkampaaec0fa2005-09-05 15:19:29 -07001558 if (status_reg & SPIDER_NET_RXINT ) {
1559 spider_net_rx_irq_off(card);
1560 netif_rx_schedule(netdev);
1561 }
Linas Vepstas68a8c602006-10-10 16:13:05 -05001562 if (status_reg & SPIDER_NET_TXINT)
1563 netif_rx_schedule(netdev);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001564
Kou Ishizakiabdb66b2007-02-20 16:33:41 -06001565 if (status_reg & SPIDER_NET_LINKINT)
1566 spider_net_link_reset(netdev);
1567
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001568 if (status_reg & SPIDER_NET_ERRINT )
1569 spider_net_handle_error_irq(card, status_reg);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001570
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 */
1584static void
1585spider_net_poll_controller(struct net_device *netdev)
1586{
1587 disable_irq(netdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01001588 spider_net_interrupt(netdev->irq, netdev);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001589 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 */
1600static void
1601spider_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 */
1616static void
1617spider_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 Osterkampb636d172006-05-04 05:59:56 -04001650 { SPIDER_NET_GTESTMD, 0x10000000 },
1651 { SPIDER_NET_GTTQMSK, 0x00400040 },
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001652
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 Osterkampaaec0fa2005-09-05 15:19:29 -07001690 spider_net_write_reg(card, SPIDER_NET_GMACLENLMT,
1691 SPIDER_NET_LENLMT_VALUE);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001692 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 Osterkampbdd01502006-07-13 11:54:08 +02001702
1703 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
Linas Vepstas7bd54c82006-11-17 14:39:40 -08001704 SPIDER_NET_GDTBSTA);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001705}
1706
1707/**
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001708 * spider_net_download_firmware - loads firmware into the adapter
1709 * @card: card structure
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001710 * @firmware_ptr: pointer to firmware data
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001711 *
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001712 * spider_net_download_firmware loads the firmware data into the
1713 * adapter. It assumes the length etc. to be allright.
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001714 */
Arnd Bergmann0d3ea162006-01-12 17:16:41 -05001715static int
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001716spider_net_download_firmware(struct spider_net_card *card,
Jeremy Kerr1a2509c2006-07-12 15:41:03 +10001717 const void *firmware_ptr)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001718{
1719 int sequencer, i;
Jeremy Kerr1a2509c2006-07-12 15:41:03 +10001720 const u32 *fw_ptr = firmware_ptr;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001721
1722 /* stop sequencers */
1723 spider_net_write_reg(card, SPIDER_NET_GSINIT,
1724 SPIDER_NET_STOP_SEQ_VALUE);
1725
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001726 for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS;
1727 sequencer++) {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001728 spider_net_write_reg(card,
1729 SPIDER_NET_GSnPRGADR + sequencer * 8, 0);
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001730 for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001731 spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT +
1732 sequencer * 8, *fw_ptr);
1733 fw_ptr++;
1734 }
1735 }
1736
Arnd Bergmann0d3ea162006-01-12 17:16:41 -05001737 if (spider_net_read_reg(card, SPIDER_NET_GSINIT))
1738 return -EIO;
1739
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001740 spider_net_write_reg(card, SPIDER_NET_GSINIT,
1741 SPIDER_NET_RUN_SEQ_VALUE);
Arnd Bergmann0d3ea162006-01-12 17:16:41 -05001742
1743 return 0;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001744}
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 */
1772static int
1773spider_net_init_firmware(struct spider_net_card *card)
1774{
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001775 struct firmware *firmware = NULL;
Arnd Bergmann030d6752006-01-12 17:16:42 -05001776 struct device_node *dn;
Jeremy Kerr1a2509c2006-07-12 15:41:03 +10001777 const u8 *fw_prop = NULL;
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001778 int err = -ENOENT;
1779 int fw_size;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001780
Arnd Bergmann030d6752006-01-12 17:16:42 -05001781 if (request_firmware((const struct firmware **)&firmware,
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001782 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 Bergmann030d6752006-01-12 17:16:42 -05001790
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001791 release_firmware(firmware);
1792 if (err)
1793 goto try_host_fw;
Arnd Bergmann030d6752006-01-12 17:16:42 -05001794
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001795 goto done;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001796 }
1797
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001798try_host_fw:
1799 dn = pci_device_to_OF_node(card->pdev);
1800 if (!dn)
1801 goto out_err;
1802
Jeremy Kerr1a2509c2006-07-12 15:41:03 +10001803 fw_prop = get_property(dn, "firmware", &fw_size);
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001804 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 Osterkampaaec0fa2005-09-05 15:19:29 -07001812 }
1813
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001814 err = spider_net_download_firmware(card, fw_prop);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001815
Arnd Bergmann11f1a522006-01-12 17:16:44 -05001816done:
1817 return err;
1818out_err:
1819 if (netif_msg_probe(card))
1820 pr_err("Couldn't find spidernet firmware in filesystem " \
1821 "or host firmware\n");
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001822 return err;
1823}
1824
1825/**
Kou Ishizaki3cf761d2007-02-20 16:34:50 -06001826 * 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 */
1834int
1835spider_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
1879register_int_failed:
1880 spider_net_free_rx_chain_contents(card);
1881alloc_skbs_failed:
1882 spider_net_free_chain(card, &card->rx_chain);
1883alloc_rx_failed:
1884 spider_net_free_chain(card, &card->tx_chain);
1885alloc_tx_failed:
1886 del_timer_sync(&card->aneg_timer);
1887init_firmware_failed:
1888 return result;
1889}
1890
1891/**
1892 * spider_net_link_phy
1893 * @data: used for pointer to card structure
1894 *
1895 */
1896static 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 **/
1970static int
1971spider_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 Osterkampaaec0fa2005-09-05 15:19:29 -07001999 * spider_net_workaround_rxramfull - work around firmware bug
2000 * @card: card structure
2001 *
2002 * no return value
2003 **/
2004static void
2005spider_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 Bergmann11f1a522006-01-12 17:16:44 -05002014 for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS;
2015 sequencer++) {
Jens Osterkampee962a52006-07-13 11:54:23 +02002016 spider_net_write_reg(card, SPIDER_NET_GSnPRGADR +
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002017 sequencer * 8, 0x0);
Arnd Bergmann11f1a522006-01-12 17:16:44 -05002018 for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002019 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 Osterkampbdd01502006-07-13 11:54:08 +02002033 * spider_net_stop - called upon ifconfig down
2034 * @netdev: interface device structure
2035 *
2036 * always returns 0
2037 */
2038int
2039spider_net_stop(struct net_device *netdev)
2040{
2041 struct spider_net_card *card = netdev_priv(netdev);
2042
Jens Osterkampbdd01502006-07-13 11:54:08 +02002043 netif_poll_disable(netdev);
2044 netif_carrier_off(netdev);
2045 netif_stop_queue(netdev);
2046 del_timer_sync(&card->tx_timer);
Kou Ishizakiabdb66b2007-02-20 16:33:41 -06002047 del_timer_sync(&card->aneg_timer);
Jens Osterkampbdd01502006-07-13 11:54:08 +02002048
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 Ishizakiabdb66b2007-02-20 16:33:41 -06002053 spider_net_write_reg(card, SPIDER_NET_GMACINTEN, 0);
Jens Osterkampbdd01502006-07-13 11:54:08 +02002054
Linas Vepstasd406eaf2007-02-20 16:32:00 -06002055 free_irq(netdev->irq, netdev);
Jens Osterkampbdd01502006-07-13 11:54:08 +02002056
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 Vepstas9cc7bf7e2006-10-10 16:14:29 -05002064 spider_net_release_tx_chain(card, 1);
Linas Vepstasd4ed8f82006-12-13 15:06:59 -06002065 spider_net_free_rx_chain_contents(card);
Jens Osterkampbdd01502006-07-13 11:54:08 +02002066
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 Osterkampaaec0fa2005-09-05 15:19:29 -07002074 * 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 */
2080static void
David Howellsc4028952006-11-22 14:57:56 +00002081spider_net_tx_timeout_task(struct work_struct *work)
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002082{
David Howellsc4028952006-11-22 14:57:56 +00002083 struct spider_net_card *card =
2084 container_of(work, struct spider_net_card, tx_timeout_task);
2085 struct net_device *netdev = card->netdev;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002086
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 Osterkampaaec0fa2005-09-05 15:19:29 -07002098
2099 spider_net_open(netdev);
Jens Osterkampbdd01502006-07-13 11:54:08 +02002100 spider_net_kick_tx_dma(card);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002101 netif_device_attach(netdev);
2102
2103out:
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 */
2113static void
2114spider_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 Lewis9b6b0b82006-09-22 17:22:53 -07002124 card->spider_stats.tx_timeouts++;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002125}
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 */
2133static void
2134spider_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 **/
2170static int
2171spider_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 Kerr1a2509c2006-07-12 15:41:03 +10002177 const u8 *mac;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002178
2179 SET_MODULE_OWNER(netdev);
2180 SET_NETDEV_DEV(netdev, &card->pdev->dev);
2181
2182 pci_set_drvdata(card->pdev, netdev);
Arnd Bergmann11f1a522006-01-12 17:16:44 -05002183
Arnd Bergmann11f1a522006-01-12 17:16:44 -05002184 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 Osterkampaaec0fa2005-09-05 15:19:29 -07002188 netdev->irq = card->pdev->irq;
2189
Kou Ishizakiabdb66b2007-02-20 16:33:41 -06002190 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 Osterkampaaec0fa2005-09-05 15:19:29 -07002195 card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT;
2196
Linas Vepstasd4ed8f82006-12-13 15:06:59 -06002197 card->tx_chain.num_desc = tx_descriptors;
2198 card->rx_chain.num_desc = rx_descriptors;
Jim Lewisb68a60e2006-08-14 23:00:23 -07002199
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002200 spider_net_setup_netdev_ops(netdev);
2201
Jens Osterkampbdd01502006-07-13 11:54:08 +02002202 netdev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002203 /* 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 Osterkamp543cec52005-09-06 19:30:54 -07002209 if (!dn)
2210 return -EIO;
2211
Jeremy Kerr1a2509c2006-07-12 15:41:03 +10002212 mac = get_property(dn, "local-mac-address", NULL);
Jens Osterkamp543cec52005-09-06 19:30:54 -07002213 if (!mac)
2214 return -EIO;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002215 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 */
2242static struct spider_net_card *
2243spider_net_alloc_card(void)
2244{
2245 struct net_device *netdev;
2246 struct spider_net_card *card;
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002247
Linas Vepstasd4ed8f82006-12-13 15:06:59 -06002248 netdev = alloc_etherdev(sizeof(struct spider_net_card));
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002249 if (!netdev)
2250 return NULL;
2251
2252 card = netdev_priv(netdev);
2253 card->netdev = netdev;
2254 card->msg_enable = SPIDER_NET_DEFAULT_MSG;
David Howellsc4028952006-11-22 14:57:56 +00002255 INIT_WORK(&card->tx_timeout_task, spider_net_tx_timeout_task);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002256 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 */
2268static void
2269spider_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 **/
2288static struct spider_net_card *
2289spider_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
2334out_release_regions:
2335 pci_release_regions(pdev);
2336out_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 **/
2352static int __devinit
2353spider_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 Osterkampaaec0fa2005-09-05 15:19:29 -07002369 err = spider_net_setup_netdev(card);
2370 if (err)
2371 goto out_undo_pci;
2372
2373 return 0;
2374
2375out_undo_pci:
2376 spider_net_undo_pci_setup(card);
2377 free_netdev(card->netdev);
2378out:
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 **/
2391static void __devexit
2392spider_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 Osterkamp543cec52005-09-06 19:30:54 -07002404
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 Osterkampaaec0fa2005-09-05 15:19:29 -07002411 spider_net_undo_pci_setup(card);
2412 free_netdev(netdev);
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002413}
2414
2415static struct pci_driver spider_net_driver = {
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002416 .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 */
2427static int __init spider_net_init(void)
2428{
Linas Vepstas90f10842006-10-10 15:56:04 -05002429 printk(KERN_INFO "Spidernet version %s.\n", VERSION);
2430
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07002431 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 */
2456static void __exit spider_net_cleanup(void)
2457{
2458 pci_unregister_driver(&spider_net_driver);
2459}
2460
2461module_init(spider_net_init);
2462module_exit(spider_net_cleanup);