2 * Network device driver for Cell Processor-Based Blade
4 * (C) Copyright IBM Corp. 2005
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
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)
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.
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.
24 #include <linux/compiler.h>
25 #include <linux/crc32.h>
26 #include <linux/delay.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ethtool.h>
29 #include <linux/firmware.h>
30 #include <linux/if_vlan.h>
32 #include <linux/init.h>
33 #include <linux/ioport.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>
45 #include <linux/vmalloc.h>
46 #include <linux/wait.h>
47 #include <linux/workqueue.h>
48 #include <asm/bitops.h>
49 #include <asm/pci-bridge.h>
50 #include <net/checksum.h>
52 #include "spider_net.h"
54 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com> and Jens Osterkamp " \
55 "<Jens.Osterkamp@de.ibm.com>");
56 MODULE_DESCRIPTION("Spider Southbridge Gigabit Ethernet driver");
57 MODULE_LICENSE("GPL");
58 MODULE_VERSION(VERSION
);
60 static int rx_descriptors
= SPIDER_NET_RX_DESCRIPTORS_DEFAULT
;
61 static int tx_descriptors
= SPIDER_NET_TX_DESCRIPTORS_DEFAULT
;
63 module_param(rx_descriptors
, int, 0444);
64 module_param(tx_descriptors
, int, 0444);
66 MODULE_PARM_DESC(rx_descriptors
, "number of descriptors used " \
68 MODULE_PARM_DESC(tx_descriptors
, "number of descriptors used " \
71 char spider_net_driver_name
[] = "spidernet";
73 static struct pci_device_id spider_net_pci_tbl
[] = {
74 { PCI_VENDOR_ID_TOSHIBA_2
, PCI_DEVICE_ID_TOSHIBA_SPIDER_NET
,
75 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
79 MODULE_DEVICE_TABLE(pci
, spider_net_pci_tbl
);
82 * spider_net_read_reg - reads an SMMIO register of a card
83 * @card: device structure
84 * @reg: register to read from
86 * returns the content of the specified SMMIO register.
89 spider_net_read_reg(struct spider_net_card
*card
, u32 reg
)
91 /* We use the powerpc specific variants instead of readl_be() because
92 * we know spidernet is not a real PCI device and we can thus avoid the
93 * performance hit caused by the PCI workarounds.
95 return in_be32(card
->regs
+ reg
);
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
105 spider_net_write_reg(struct spider_net_card
*card
, u32 reg
, u32 value
)
107 /* We use the powerpc specific variants instead of writel_be() because
108 * we know spidernet is not a real PCI device and we can thus avoid the
109 * performance hit caused by the PCI workarounds.
111 out_be32(card
->regs
+ reg
, value
);
114 /** spider_net_write_phy - write to phy register
115 * @netdev: adapter to be written to
118 * @val: value to be written to phy register
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).
125 spider_net_write_phy(struct net_device
*netdev
, int mii_id
,
128 struct spider_net_card
*card
= netdev_priv(netdev
);
131 writevalue
= ((u32
)mii_id
<< 21) |
132 ((u32
)reg
<< 16) | ((u32
)val
);
134 spider_net_write_reg(card
, SPIDER_NET_GPCWOPCMD
, writevalue
);
137 /** spider_net_read_phy - read from phy register
138 * @netdev: network device to be read from
142 * Returns value read from PHY register
144 * spider_net_write_phy reads from an arbitrary PHY
145 * register via the spider GPCROPCMD register
148 spider_net_read_phy(struct net_device
*netdev
, int mii_id
, int reg
)
150 struct spider_net_card
*card
= netdev_priv(netdev
);
153 readvalue
= ((u32
)mii_id
<< 21) | ((u32
)reg
<< 16);
154 spider_net_write_reg(card
, SPIDER_NET_GPCROPCMD
, readvalue
);
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 */
160 readvalue
= spider_net_read_reg(card
, SPIDER_NET_GPCROPCMD
);
161 } while (readvalue
& SPIDER_NET_GPREXEC
);
163 readvalue
&= SPIDER_NET_GPRDAT_MASK
;
169 * spider_net_rx_irq_off - switch off rx irq on this spider card
170 * @card: device structure
172 * switches off rx irq by masking them out in the GHIINTnMSK register
175 spider_net_rx_irq_off(struct spider_net_card
*card
)
179 regvalue
= SPIDER_NET_INT0_MASK_VALUE
& (~SPIDER_NET_RXINT
);
180 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
, regvalue
);
184 * spider_net_rx_irq_on - switch on rx irq on this spider card
185 * @card: device structure
187 * switches on rx irq by enabling them in the GHIINTnMSK register
190 spider_net_rx_irq_on(struct spider_net_card
*card
)
194 regvalue
= SPIDER_NET_INT0_MASK_VALUE
| SPIDER_NET_RXINT
;
195 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
, regvalue
);
199 * spider_net_set_promisc - sets the unicast address or the promiscuous mode
200 * @card: card structure
202 * spider_net_set_promisc sets the unicast destination address filter and
203 * thus either allows for non-promisc mode or promisc mode
206 spider_net_set_promisc(struct spider_net_card
*card
)
209 struct net_device
*netdev
= card
->netdev
;
211 if (netdev
->flags
& IFF_PROMISC
) {
212 /* clear destination entry 0 */
213 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
, 0);
214 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
+ 0x04, 0);
215 spider_net_write_reg(card
, SPIDER_NET_GMRUA0FIL15R
,
216 SPIDER_NET_PROMISC_VALUE
);
218 macu
= netdev
->dev_addr
[0];
220 macu
|= netdev
->dev_addr
[1];
221 memcpy(&macl
, &netdev
->dev_addr
[2], sizeof(macl
));
223 macu
|= SPIDER_NET_UA_DESCR_VALUE
;
224 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
, macu
);
225 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
+ 0x04, macl
);
226 spider_net_write_reg(card
, SPIDER_NET_GMRUA0FIL15R
,
227 SPIDER_NET_NONPROMISC_VALUE
);
232 * spider_net_get_mac_address - read mac address from spider card
233 * @card: device structure
235 * reads MAC address from GMACUNIMACU and GMACUNIMACL registers
238 spider_net_get_mac_address(struct net_device
*netdev
)
240 struct spider_net_card
*card
= netdev_priv(netdev
);
243 macl
= spider_net_read_reg(card
, SPIDER_NET_GMACUNIMACL
);
244 macu
= spider_net_read_reg(card
, SPIDER_NET_GMACUNIMACU
);
246 netdev
->dev_addr
[0] = (macu
>> 24) & 0xff;
247 netdev
->dev_addr
[1] = (macu
>> 16) & 0xff;
248 netdev
->dev_addr
[2] = (macu
>> 8) & 0xff;
249 netdev
->dev_addr
[3] = macu
& 0xff;
250 netdev
->dev_addr
[4] = (macl
>> 8) & 0xff;
251 netdev
->dev_addr
[5] = macl
& 0xff;
253 if (!is_valid_ether_addr(&netdev
->dev_addr
[0]))
260 * spider_net_get_descr_status -- returns the status of a descriptor
261 * @descr: descriptor to look at
263 * returns the status as in the dmac_cmd_status field of the descriptor
266 spider_net_get_descr_status(struct spider_net_descr
*descr
)
268 return descr
->dmac_cmd_status
& SPIDER_NET_DESCR_IND_PROC_MASK
;
272 * spider_net_free_chain - free descriptor chain
273 * @card: card structure
274 * @chain: address of chain
278 spider_net_free_chain(struct spider_net_card
*card
,
279 struct spider_net_descr_chain
*chain
)
281 struct spider_net_descr
*descr
;
283 for (descr
= chain
->tail
; !descr
->bus_addr
; descr
= descr
->next
) {
284 pci_unmap_single(card
->pdev
, descr
->bus_addr
,
285 SPIDER_NET_DESCR_SIZE
, PCI_DMA_BIDIRECTIONAL
);
291 * spider_net_init_chain - links descriptor chain
292 * @card: card structure
293 * @chain: address of chain
294 * @start_descr: address of descriptor array
295 * @no: number of descriptors
297 * we manage a circular list that mirrors the hardware structure,
298 * except that the hardware uses bus addresses.
300 * returns 0 on success, <0 on failure
303 spider_net_init_chain(struct spider_net_card
*card
,
304 struct spider_net_descr_chain
*chain
,
305 struct spider_net_descr
*start_descr
,
309 struct spider_net_descr
*descr
;
313 memset(descr
, 0, sizeof(*descr
) * no
);
315 /* set up the hardware pointers in each descriptor */
316 for (i
=0; i
<no
; i
++, descr
++) {
317 descr
->dmac_cmd_status
= SPIDER_NET_DESCR_NOT_IN_USE
;
319 buf
= pci_map_single(card
->pdev
, descr
,
320 SPIDER_NET_DESCR_SIZE
,
321 PCI_DMA_BIDIRECTIONAL
);
323 if (pci_dma_mapping_error(buf
))
326 descr
->bus_addr
= buf
;
327 descr
->next
= descr
+ 1;
328 descr
->prev
= descr
- 1;
331 /* do actual circular list */
332 (descr
-1)->next
= start_descr
;
333 start_descr
->prev
= descr
-1;
335 spin_lock_init(&chain
->lock
);
336 chain
->head
= start_descr
;
337 chain
->tail
= start_descr
;
343 for (i
=0; i
< no
; i
++, descr
++)
345 pci_unmap_single(card
->pdev
, descr
->bus_addr
,
346 SPIDER_NET_DESCR_SIZE
,
347 PCI_DMA_BIDIRECTIONAL
);
352 * spider_net_free_rx_chain_contents - frees descr contents in rx chain
353 * @card: card structure
355 * returns 0 on success, <0 on failure
358 spider_net_free_rx_chain_contents(struct spider_net_card
*card
)
360 struct spider_net_descr
*descr
;
362 descr
= card
->rx_chain
.head
;
365 dev_kfree_skb(descr
->skb
);
366 pci_unmap_single(card
->pdev
, descr
->buf_addr
,
367 SPIDER_NET_MAX_FRAME
,
368 PCI_DMA_BIDIRECTIONAL
);
371 } while (descr
!= card
->rx_chain
.head
);
375 * spider_net_prepare_rx_descr - reinitializes a rx descriptor
376 * @card: card structure
377 * @descr: descriptor to re-init
379 * return 0 on succes, <0 on failure
381 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
382 * Activate the descriptor state-wise
385 spider_net_prepare_rx_descr(struct spider_net_card
*card
,
386 struct spider_net_descr
*descr
)
393 /* we need to round up the buffer size to a multiple of 128 */
394 bufsize
= (SPIDER_NET_MAX_FRAME
+ SPIDER_NET_RXBUF_ALIGN
- 1) &
395 (~(SPIDER_NET_RXBUF_ALIGN
- 1));
397 /* and we need to have it 128 byte aligned, therefore we allocate a
399 /* allocate an skb */
400 descr
->skb
= dev_alloc_skb(bufsize
+ SPIDER_NET_RXBUF_ALIGN
- 1);
402 if (netif_msg_rx_err(card
) && net_ratelimit())
403 pr_err("Not enough memory to allocate rx buffer\n");
404 card
->spider_stats
.alloc_rx_skb_error
++;
407 descr
->buf_size
= bufsize
;
408 descr
->result_size
= 0;
409 descr
->valid_size
= 0;
410 descr
->data_status
= 0;
411 descr
->data_error
= 0;
413 offset
= ((unsigned long)descr
->skb
->data
) &
414 (SPIDER_NET_RXBUF_ALIGN
- 1);
416 skb_reserve(descr
->skb
, SPIDER_NET_RXBUF_ALIGN
- offset
);
417 /* io-mmu-map the skb */
418 buf
= pci_map_single(card
->pdev
, descr
->skb
->data
,
419 SPIDER_NET_MAX_FRAME
, PCI_DMA_FROMDEVICE
);
420 descr
->buf_addr
= buf
;
421 if (pci_dma_mapping_error(buf
)) {
422 dev_kfree_skb_any(descr
->skb
);
423 if (netif_msg_rx_err(card
) && net_ratelimit())
424 pr_err("Could not iommu-map rx buffer\n");
425 card
->spider_stats
.rx_iommu_map_error
++;
426 descr
->dmac_cmd_status
= SPIDER_NET_DESCR_NOT_IN_USE
;
428 descr
->dmac_cmd_status
= SPIDER_NET_DESCR_CARDOWNED
|
429 SPIDER_NET_DMAC_NOINTR_COMPLETE
;
436 * spider_net_enable_rxchtails - sets RX dmac chain tail addresses
437 * @card: card structure
439 * spider_net_enable_rxchtails sets the RX DMAC chain tail adresses in the
440 * chip by writing to the appropriate register. DMA is enabled in
441 * spider_net_enable_rxdmac.
444 spider_net_enable_rxchtails(struct spider_net_card
*card
)
446 /* assume chain is aligned correctly */
447 spider_net_write_reg(card
, SPIDER_NET_GDADCHA
,
448 card
->rx_chain
.tail
->bus_addr
);
452 * spider_net_enable_rxdmac - enables a receive DMA controller
453 * @card: card structure
455 * spider_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
456 * in the GDADMACCNTR register
459 spider_net_enable_rxdmac(struct spider_net_card
*card
)
462 spider_net_write_reg(card
, SPIDER_NET_GDADMACCNTR
,
463 SPIDER_NET_DMA_RX_VALUE
);
467 * spider_net_refill_rx_chain - refills descriptors/skbs in the rx chains
468 * @card: card structure
470 * refills descriptors in the rx chain: allocates skbs and iommu-maps them.
473 spider_net_refill_rx_chain(struct spider_net_card
*card
)
475 struct spider_net_descr_chain
*chain
= &card
->rx_chain
;
478 /* one context doing the refill (and a second context seeing that
479 * and omitting it) is ok. If called by NAPI, we'll be called again
480 * as spider_net_decode_one_descr is called several times. If some
481 * interrupt calls us, the NAPI is about to clean up anyway. */
482 if (!spin_trylock_irqsave(&chain
->lock
, flags
))
485 while (spider_net_get_descr_status(chain
->head
) ==
486 SPIDER_NET_DESCR_NOT_IN_USE
) {
487 if (spider_net_prepare_rx_descr(card
, chain
->head
))
489 chain
->head
= chain
->head
->next
;
492 spin_unlock_irqrestore(&chain
->lock
, flags
);
496 * spider_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
497 * @card: card structure
499 * returns 0 on success, <0 on failure
502 spider_net_alloc_rx_skbs(struct spider_net_card
*card
)
505 struct spider_net_descr_chain
*chain
;
509 chain
= &card
->rx_chain
;
510 /* put at least one buffer into the chain. if this fails,
511 * we've got a problem. if not, spider_net_refill_rx_chain
512 * will do the rest at the end of this function */
513 if (spider_net_prepare_rx_descr(card
, chain
->head
))
516 chain
->head
= chain
->head
->next
;
518 /* this will allocate the rest of the rx buffers; if not, it's
519 * business as usual later on */
520 spider_net_refill_rx_chain(card
);
521 spider_net_enable_rxdmac(card
);
525 spider_net_free_rx_chain_contents(card
);
530 * spider_net_get_multicast_hash - generates hash for multicast filter table
531 * @addr: multicast address
533 * returns the hash value.
535 * spider_net_get_multicast_hash calculates a hash value for a given multicast
536 * address, that is used to set the multicast filter tables
539 spider_net_get_multicast_hash(struct net_device
*netdev
, __u8
*addr
)
543 char addr_for_crc
[ETH_ALEN
] = { 0, };
546 for (i
= 0; i
< ETH_ALEN
* 8; i
++) {
547 bit
= (addr
[i
/ 8] >> (i
% 8)) & 1;
548 addr_for_crc
[ETH_ALEN
- 1 - i
/ 8] += bit
<< (7 - (i
% 8));
551 crc
= crc32_be(~0, addr_for_crc
, netdev
->addr_len
);
562 * spider_net_set_multi - sets multicast addresses and promisc flags
563 * @netdev: interface device structure
565 * spider_net_set_multi configures multicast addresses as needed for the
566 * netdev interface. It also sets up multicast, allmulti and promisc
567 * flags appropriately
570 spider_net_set_multi(struct net_device
*netdev
)
572 struct dev_mc_list
*mc
;
576 struct spider_net_card
*card
= netdev_priv(netdev
);
577 unsigned long bitmask
[SPIDER_NET_MULTICAST_HASHES
/ BITS_PER_LONG
] =
580 spider_net_set_promisc(card
);
582 if (netdev
->flags
& IFF_ALLMULTI
) {
583 for (i
= 0; i
< SPIDER_NET_MULTICAST_HASHES
; i
++) {
589 /* well, we know, what the broadcast hash value is: it's xfd
590 hash = spider_net_get_multicast_hash(netdev, netdev->broadcast); */
591 set_bit(0xfd, bitmask
);
593 for (mc
= netdev
->mc_list
; mc
; mc
= mc
->next
) {
594 hash
= spider_net_get_multicast_hash(netdev
, mc
->dmi_addr
);
595 set_bit(hash
, bitmask
);
599 for (i
= 0; i
< SPIDER_NET_MULTICAST_HASHES
/ 4; i
++) {
601 if (test_bit(i
* 4, bitmask
))
604 if (test_bit(i
* 4 + 1, bitmask
))
607 if (test_bit(i
* 4 + 2, bitmask
))
610 if (test_bit(i
* 4 + 3, bitmask
))
613 spider_net_write_reg(card
, SPIDER_NET_GMRMHFILnR
+ i
* 4, reg
);
618 * spider_net_disable_rxdmac - disables the receive DMA controller
619 * @card: card structure
621 * spider_net_disable_rxdmac terminates processing on the DMA controller by
622 * turing off DMA and issueing a force end
625 spider_net_disable_rxdmac(struct spider_net_card
*card
)
627 spider_net_write_reg(card
, SPIDER_NET_GDADMACCNTR
,
628 SPIDER_NET_DMA_RX_FEND_VALUE
);
632 * spider_net_prepare_tx_descr - fill tx descriptor with skb data
633 * @card: card structure
634 * @descr: descriptor structure to fill out
635 * @skb: packet to use
637 * returns 0 on success, <0 on failure.
639 * fills out the descriptor structure with skb data and len. Copies data,
640 * if needed (32bit DMA!)
643 spider_net_prepare_tx_descr(struct spider_net_card
*card
,
646 struct spider_net_descr
*descr
;
650 buf
= pci_map_single(card
->pdev
, skb
->data
, skb
->len
, PCI_DMA_TODEVICE
);
651 if (pci_dma_mapping_error(buf
)) {
652 if (netif_msg_tx_err(card
) && net_ratelimit())
653 pr_err("could not iommu-map packet (%p, %i). "
654 "Dropping packet\n", skb
->data
, skb
->len
);
655 card
->spider_stats
.tx_iommu_map_error
++;
659 spin_lock_irqsave(&card
->tx_chain
.lock
, flags
);
660 descr
= card
->tx_chain
.head
;
661 card
->tx_chain
.head
= descr
->next
;
663 descr
->buf_addr
= buf
;
664 descr
->buf_size
= skb
->len
;
665 descr
->next_descr_addr
= 0;
667 descr
->data_status
= 0;
669 descr
->dmac_cmd_status
=
670 SPIDER_NET_DESCR_CARDOWNED
| SPIDER_NET_DMAC_NOCS
;
671 spin_unlock_irqrestore(&card
->tx_chain
.lock
, flags
);
673 if (skb
->protocol
== htons(ETH_P_IP
))
674 switch (skb
->nh
.iph
->protocol
) {
676 descr
->dmac_cmd_status
|= SPIDER_NET_DMAC_TCP
;
679 descr
->dmac_cmd_status
|= SPIDER_NET_DMAC_UDP
;
683 /* Chain the bus address, so that the DMA engine finds this descr. */
684 descr
->prev
->next_descr_addr
= descr
->bus_addr
;
686 card
->netdev
->trans_start
= jiffies
; /* set netdev watchdog timer */
691 spider_net_set_low_watermark(struct spider_net_card
*card
)
697 struct spider_net_descr
*descr
= card
->tx_chain
.tail
;
699 /* Measure the length of the queue. Measurement does not
700 * need to be precise -- does not need a lock. */
701 while (descr
!= card
->tx_chain
.head
) {
702 status
= descr
->dmac_cmd_status
& SPIDER_NET_DESCR_NOT_IN_USE
;
703 if (status
== SPIDER_NET_DESCR_NOT_IN_USE
)
709 /* If TX queue is short, don't even bother with interrupts */
710 if (cnt
< card
->num_tx_desc
/4)
713 /* Set low-watermark 3/4th's of the way into the queue. */
714 descr
= card
->tx_chain
.tail
;
719 /* Set the new watermark, clear the old watermark */
720 spin_lock_irqsave(&card
->tx_chain
.lock
, flags
);
721 descr
->dmac_cmd_status
|= SPIDER_NET_DESCR_TXDESFLG
;
722 if (card
->low_watermark
&& card
->low_watermark
!= descr
)
723 card
->low_watermark
->dmac_cmd_status
=
724 card
->low_watermark
->dmac_cmd_status
& ~SPIDER_NET_DESCR_TXDESFLG
;
725 card
->low_watermark
= descr
;
726 spin_unlock_irqrestore(&card
->tx_chain
.lock
, flags
);
731 * spider_net_release_tx_chain - processes sent tx descriptors
732 * @card: adapter structure
733 * @brutal: if set, don't care about whether descriptor seems to be in use
735 * returns 0 if the tx ring is empty, otherwise 1.
737 * spider_net_release_tx_chain releases the tx descriptors that spider has
738 * finished with (if non-brutal) or simply release tx descriptors (if brutal).
739 * If some other context is calling this function, we return 1 so that we're
740 * scheduled again (if we were scheduled) and will not loose initiative.
743 spider_net_release_tx_chain(struct spider_net_card
*card
, int brutal
)
745 struct spider_net_descr_chain
*chain
= &card
->tx_chain
;
746 struct spider_net_descr
*descr
;
752 while (chain
->tail
!= chain
->head
) {
753 spin_lock_irqsave(&chain
->lock
, flags
);
756 status
= spider_net_get_descr_status(descr
);
758 case SPIDER_NET_DESCR_COMPLETE
:
759 card
->netdev_stats
.tx_packets
++;
760 card
->netdev_stats
.tx_bytes
+= descr
->skb
->len
;
763 case SPIDER_NET_DESCR_CARDOWNED
:
765 spin_unlock_irqrestore(&chain
->lock
, flags
);
769 /* fallthrough, if we release the descriptors
770 * brutally (then we don't care about
771 * SPIDER_NET_DESCR_CARDOWNED) */
773 case SPIDER_NET_DESCR_RESPONSE_ERROR
:
774 case SPIDER_NET_DESCR_PROTECTION_ERROR
:
775 case SPIDER_NET_DESCR_FORCE_END
:
776 if (netif_msg_tx_err(card
))
777 pr_err("%s: forcing end of tx descriptor "
778 "with status x%02x\n",
779 card
->netdev
->name
, status
);
780 card
->netdev_stats
.tx_errors
++;
784 card
->netdev_stats
.tx_dropped
++;
786 spin_unlock_irqrestore(&chain
->lock
, flags
);
791 chain
->tail
= descr
->next
;
792 descr
->dmac_cmd_status
|= SPIDER_NET_DESCR_NOT_IN_USE
;
794 buf_addr
= descr
->buf_addr
;
795 spin_unlock_irqrestore(&chain
->lock
, flags
);
799 pci_unmap_single(card
->pdev
, buf_addr
, skb
->len
,
808 * spider_net_kick_tx_dma - enables TX DMA processing
809 * @card: card structure
810 * @descr: descriptor address to enable TX processing at
812 * This routine will start the transmit DMA running if
813 * it is not already running. This routine ned only be
814 * called when queueing a new packet to an empty tx queue.
815 * Writes the current tx chain head as start address
816 * of the tx descriptor chain and enables the transmission
820 spider_net_kick_tx_dma(struct spider_net_card
*card
)
822 struct spider_net_descr
*descr
;
824 if (spider_net_read_reg(card
, SPIDER_NET_GDTDMACCNTR
) &
825 SPIDER_NET_TX_DMA_EN
)
828 descr
= card
->tx_chain
.tail
;
830 if (spider_net_get_descr_status(descr
) ==
831 SPIDER_NET_DESCR_CARDOWNED
) {
832 spider_net_write_reg(card
, SPIDER_NET_GDTDCHA
,
834 spider_net_write_reg(card
, SPIDER_NET_GDTDMACCNTR
,
835 SPIDER_NET_DMA_TX_VALUE
);
838 if (descr
== card
->tx_chain
.head
)
844 mod_timer(&card
->tx_timer
, jiffies
+ SPIDER_NET_TX_TIMER
);
848 * spider_net_xmit - transmits a frame over the device
849 * @skb: packet to send out
850 * @netdev: interface device structure
852 * returns 0 on success, !0 on failure
855 spider_net_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
858 struct spider_net_card
*card
= netdev_priv(netdev
);
859 struct spider_net_descr_chain
*chain
= &card
->tx_chain
;
861 spider_net_release_tx_chain(card
, 0);
863 if ((chain
->head
->next
== chain
->tail
->prev
) ||
864 (spider_net_prepare_tx_descr(card
, skb
) != 0)) {
866 card
->netdev_stats
.tx_dropped
++;
867 netif_stop_queue(netdev
);
868 return NETDEV_TX_BUSY
;
871 cnt
= spider_net_set_low_watermark(card
);
873 spider_net_kick_tx_dma(card
);
878 * spider_net_cleanup_tx_ring - cleans up the TX ring
879 * @card: card structure
881 * spider_net_cleanup_tx_ring is called by either the tx_timer
882 * or from the NAPI polling routine.
883 * This routine releases resources associted with transmitted
884 * packets, including updating the queue tail pointer.
887 spider_net_cleanup_tx_ring(struct spider_net_card
*card
)
889 if ((spider_net_release_tx_chain(card
, 0) != 0) &&
890 (card
->netdev
->flags
& IFF_UP
)) {
891 spider_net_kick_tx_dma(card
);
892 netif_wake_queue(card
->netdev
);
897 * spider_net_do_ioctl - called for device ioctls
898 * @netdev: interface device structure
899 * @ifr: request parameter structure for ioctl
900 * @cmd: command code for ioctl
902 * returns 0 on success, <0 on failure. Currently, we have no special ioctls.
903 * -EOPNOTSUPP is returned, if an unknown ioctl was requested
906 spider_net_do_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
915 * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on
916 * @descr: descriptor to process
917 * @card: card structure
918 * @napi: whether caller is in NAPI context
920 * returns 1 on success, 0 if no packet was passed to the stack
922 * iommu-unmaps the skb, fills out skb structure and passes the data to the
923 * stack. The descriptor state is not changed.
926 spider_net_pass_skb_up(struct spider_net_descr
*descr
,
927 struct spider_net_card
*card
, int napi
)
930 struct net_device
*netdev
;
931 u32 data_status
, data_error
;
933 data_status
= descr
->data_status
;
934 data_error
= descr
->data_error
;
936 netdev
= card
->netdev
;
938 /* unmap descriptor */
939 pci_unmap_single(card
->pdev
, descr
->buf_addr
, SPIDER_NET_MAX_FRAME
,
942 /* the cases we'll throw away the packet immediately */
943 if (data_error
& SPIDER_NET_DESTROY_RX_FLAGS
) {
944 if (netif_msg_rx_err(card
))
945 pr_err("error in received descriptor found, "
946 "data_status=x%08x, data_error=x%08x\n",
947 data_status
, data_error
);
948 card
->spider_stats
.rx_desc_error
++;
954 skb_put(skb
, descr
->valid_size
);
956 /* the card seems to add 2 bytes of junk in front
957 * of the ethernet frame */
958 #define SPIDER_MISALIGN 2
959 skb_pull(skb
, SPIDER_MISALIGN
);
960 skb
->protocol
= eth_type_trans(skb
, netdev
);
962 /* checksum offload */
963 if (card
->options
.rx_csum
) {
964 if ( ( (data_status
& SPIDER_NET_DATA_STATUS_CKSUM_MASK
) ==
965 SPIDER_NET_DATA_STATUS_CKSUM_MASK
) &&
966 !(data_error
& SPIDER_NET_DATA_ERR_CKSUM_MASK
))
967 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
969 skb
->ip_summed
= CHECKSUM_NONE
;
971 skb
->ip_summed
= CHECKSUM_NONE
;
973 if (data_status
& SPIDER_NET_VLAN_PACKET
) {
974 /* further enhancements: HW-accel VLAN
975 * vlan_hwaccel_receive_skb
979 /* pass skb up to stack */
981 netif_receive_skb(skb
);
985 /* update netdevice statistics */
986 card
->netdev_stats
.rx_packets
++;
987 card
->netdev_stats
.rx_bytes
+= skb
->len
;
993 * spider_net_decode_one_descr - processes an rx descriptor
994 * @card: card structure
995 * @napi: whether caller is in NAPI context
997 * returns 1 if a packet has been sent to the stack, otherwise 0
999 * processes an rx descriptor by iommu-unmapping the data buffer and passing
1000 * the packet up to the stack. This function is called in softirq
1001 * context, e.g. either bottom half from interrupt or NAPI polling context
1004 spider_net_decode_one_descr(struct spider_net_card
*card
, int napi
)
1006 struct spider_net_descr_chain
*chain
= &card
->rx_chain
;
1007 struct spider_net_descr
*descr
= chain
->tail
;
1011 status
= spider_net_get_descr_status(descr
);
1013 if (status
== SPIDER_NET_DESCR_CARDOWNED
) {
1014 /* nothing in the descriptor yet */
1019 if (status
== SPIDER_NET_DESCR_NOT_IN_USE
) {
1020 /* not initialized yet, the ring must be empty */
1021 spider_net_refill_rx_chain(card
);
1022 spider_net_enable_rxdmac(card
);
1027 /* descriptor definitively used -- move on tail */
1028 chain
->tail
= descr
->next
;
1031 if ( (status
== SPIDER_NET_DESCR_RESPONSE_ERROR
) ||
1032 (status
== SPIDER_NET_DESCR_PROTECTION_ERROR
) ||
1033 (status
== SPIDER_NET_DESCR_FORCE_END
) ) {
1034 if (netif_msg_rx_err(card
))
1035 pr_err("%s: dropping RX descriptor with state %d\n",
1036 card
->netdev
->name
, status
);
1037 card
->netdev_stats
.rx_dropped
++;
1038 pci_unmap_single(card
->pdev
, descr
->buf_addr
,
1039 SPIDER_NET_MAX_FRAME
, PCI_DMA_FROMDEVICE
);
1040 dev_kfree_skb_irq(descr
->skb
);
1044 if ( (status
!= SPIDER_NET_DESCR_COMPLETE
) &&
1045 (status
!= SPIDER_NET_DESCR_FRAME_END
) ) {
1046 if (netif_msg_rx_err(card
)) {
1047 pr_err("%s: RX descriptor with state %d\n",
1048 card
->netdev
->name
, status
);
1049 card
->spider_stats
.rx_desc_unk_state
++;
1054 /* ok, we've got a packet in descr */
1055 result
= spider_net_pass_skb_up(descr
, card
, napi
);
1057 descr
->dmac_cmd_status
= SPIDER_NET_DESCR_NOT_IN_USE
;
1058 /* change the descriptor state: */
1060 spider_net_refill_rx_chain(card
);
1066 * spider_net_poll - NAPI poll function called by the stack to return packets
1067 * @netdev: interface device structure
1068 * @budget: number of packets we can pass to the stack at most
1070 * returns 0 if no more packets available to the driver/stack. Returns 1,
1071 * if the quota is exceeded, but the driver has still packets.
1073 * spider_net_poll returns all packets from the rx descriptors to the stack
1074 * (using netif_receive_skb). If all/enough packets are up, the driver
1075 * reenables interrupts and returns 0. If not, 1 is returned.
1078 spider_net_poll(struct net_device
*netdev
, int *budget
)
1080 struct spider_net_card
*card
= netdev_priv(netdev
);
1081 int packets_to_do
, packets_done
= 0;
1082 int no_more_packets
= 0;
1084 spider_net_cleanup_tx_ring(card
);
1085 packets_to_do
= min(*budget
, netdev
->quota
);
1087 while (packets_to_do
) {
1088 if (spider_net_decode_one_descr(card
, 1)) {
1092 /* no more packets for the stack */
1093 no_more_packets
= 1;
1098 netdev
->quota
-= packets_done
;
1099 *budget
-= packets_done
;
1100 spider_net_refill_rx_chain(card
);
1102 /* if all packets are in the stack, enable interrupts and return 0 */
1103 /* if not, return 1 */
1104 if (no_more_packets
) {
1105 netif_rx_complete(netdev
);
1106 spider_net_rx_irq_on(card
);
1114 * spider_net_vlan_rx_reg - initializes VLAN structures in the driver and card
1115 * @netdev: interface device structure
1116 * @grp: vlan_group structure that is registered (NULL on destroying interface)
1119 spider_net_vlan_rx_reg(struct net_device
*netdev
, struct vlan_group
*grp
)
1121 /* further enhancement... yet to do */
1126 * spider_net_vlan_rx_add - adds VLAN id to the card filter
1127 * @netdev: interface device structure
1128 * @vid: VLAN id to add
1131 spider_net_vlan_rx_add(struct net_device
*netdev
, uint16_t vid
)
1133 /* further enhancement... yet to do */
1134 /* add vid to card's VLAN filter table */
1139 * spider_net_vlan_rx_kill - removes VLAN id to the card filter
1140 * @netdev: interface device structure
1141 * @vid: VLAN id to remove
1144 spider_net_vlan_rx_kill(struct net_device
*netdev
, uint16_t vid
)
1146 /* further enhancement... yet to do */
1147 /* remove vid from card's VLAN filter table */
1151 * spider_net_get_stats - get interface statistics
1152 * @netdev: interface device structure
1154 * returns the interface statistics residing in the spider_net_card struct
1156 static struct net_device_stats
*
1157 spider_net_get_stats(struct net_device
*netdev
)
1159 struct spider_net_card
*card
= netdev_priv(netdev
);
1160 struct net_device_stats
*stats
= &card
->netdev_stats
;
1165 * spider_net_change_mtu - changes the MTU of an interface
1166 * @netdev: interface device structure
1167 * @new_mtu: new MTU value
1169 * returns 0 on success, <0 on failure
1172 spider_net_change_mtu(struct net_device
*netdev
, int new_mtu
)
1174 /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
1175 * and mtu is outbound only anyway */
1176 if ( (new_mtu
< SPIDER_NET_MIN_MTU
) ||
1177 (new_mtu
> SPIDER_NET_MAX_MTU
) )
1179 netdev
->mtu
= new_mtu
;
1184 * spider_net_set_mac - sets the MAC of an interface
1185 * @netdev: interface device structure
1186 * @ptr: pointer to new MAC address
1188 * Returns 0 on success, <0 on failure. Currently, we don't support this
1189 * and will always return EOPNOTSUPP.
1192 spider_net_set_mac(struct net_device
*netdev
, void *p
)
1194 struct spider_net_card
*card
= netdev_priv(netdev
);
1195 u32 macl
, macu
, regvalue
;
1196 struct sockaddr
*addr
= p
;
1198 if (!is_valid_ether_addr(addr
->sa_data
))
1199 return -EADDRNOTAVAIL
;
1201 /* switch off GMACTPE and GMACRPE */
1202 regvalue
= spider_net_read_reg(card
, SPIDER_NET_GMACOPEMD
);
1203 regvalue
&= ~((1 << 5) | (1 << 6));
1204 spider_net_write_reg(card
, SPIDER_NET_GMACOPEMD
, regvalue
);
1207 macu
= (addr
->sa_data
[0]<<24) + (addr
->sa_data
[1]<<16) +
1208 (addr
->sa_data
[2]<<8) + (addr
->sa_data
[3]);
1209 macl
= (addr
->sa_data
[4]<<8) + (addr
->sa_data
[5]);
1210 spider_net_write_reg(card
, SPIDER_NET_GMACUNIMACU
, macu
);
1211 spider_net_write_reg(card
, SPIDER_NET_GMACUNIMACL
, macl
);
1213 /* switch GMACTPE and GMACRPE back on */
1214 regvalue
= spider_net_read_reg(card
, SPIDER_NET_GMACOPEMD
);
1215 regvalue
|= ((1 << 5) | (1 << 6));
1216 spider_net_write_reg(card
, SPIDER_NET_GMACOPEMD
, regvalue
);
1218 spider_net_set_promisc(card
);
1220 /* look up, whether we have been successful */
1221 if (spider_net_get_mac_address(netdev
))
1222 return -EADDRNOTAVAIL
;
1223 if (memcmp(netdev
->dev_addr
,addr
->sa_data
,netdev
->addr_len
))
1224 return -EADDRNOTAVAIL
;
1230 * spider_net_handle_rxram_full - cleans up RX ring upon RX RAM full interrupt
1231 * @card: card structure
1233 * spider_net_handle_rxram_full empties the RX ring so that spider can put
1234 * more packets in it and empty its RX RAM. This is called in bottom half
1238 spider_net_handle_rxram_full(struct spider_net_card
*card
)
1240 while (spider_net_decode_one_descr(card
, 0))
1242 spider_net_enable_rxchtails(card
);
1243 spider_net_enable_rxdmac(card
);
1244 netif_rx_schedule(card
->netdev
);
1248 * spider_net_handle_error_irq - handles errors raised by an interrupt
1249 * @card: card structure
1250 * @status_reg: interrupt status register 0 (GHIINT0STS)
1252 * spider_net_handle_error_irq treats or ignores all error conditions
1253 * found when an interrupt is presented
1256 spider_net_handle_error_irq(struct spider_net_card
*card
, u32 status_reg
)
1258 u32 error_reg1
, error_reg2
;
1262 error_reg1
= spider_net_read_reg(card
, SPIDER_NET_GHIINT1STS
);
1263 error_reg2
= spider_net_read_reg(card
, SPIDER_NET_GHIINT2STS
);
1265 /* check GHIINT0STS ************************************/
1267 for (i
= 0; i
< 32; i
++)
1268 if (status_reg
& (1<<i
))
1271 /* let error_reg1 and error_reg2 evaluation decide, what to do
1272 case SPIDER_NET_PHYINT:
1273 case SPIDER_NET_GMAC2INT:
1274 case SPIDER_NET_GMAC1INT:
1275 case SPIDER_NET_GFIFOINT:
1276 case SPIDER_NET_DMACINT:
1277 case SPIDER_NET_GSYSINT:
1280 case SPIDER_NET_GIPSINT
:
1284 case SPIDER_NET_GPWOPCMPINT
:
1285 /* PHY write operation completed */
1288 case SPIDER_NET_GPROPCMPINT
:
1289 /* PHY read operation completed */
1290 /* we don't use semaphores, as we poll for the completion
1291 * of the read operation in spider_net_read_phy. Should take
1295 case SPIDER_NET_GPWFFINT
:
1296 /* PHY command queue full */
1297 if (netif_msg_intr(card
))
1298 pr_err("PHY write queue full\n");
1302 /* case SPIDER_NET_GRMDADRINT: not used. print a message */
1303 /* case SPIDER_NET_GRMARPINT: not used. print a message */
1304 /* case SPIDER_NET_GRMMPINT: not used. print a message */
1306 case SPIDER_NET_GDTDEN0INT
:
1307 /* someone has set TX_DMA_EN to 0 */
1311 case SPIDER_NET_GDDDEN0INT
: /* fallthrough */
1312 case SPIDER_NET_GDCDEN0INT
: /* fallthrough */
1313 case SPIDER_NET_GDBDEN0INT
: /* fallthrough */
1314 case SPIDER_NET_GDADEN0INT
:
1315 /* someone has set RX_DMA_EN to 0 */
1320 case SPIDER_NET_GDDFDCINT
:
1321 case SPIDER_NET_GDCFDCINT
:
1322 case SPIDER_NET_GDBFDCINT
:
1323 case SPIDER_NET_GDAFDCINT
:
1324 /* case SPIDER_NET_GDNMINT: not used. print a message */
1325 /* case SPIDER_NET_GCNMINT: not used. print a message */
1326 /* case SPIDER_NET_GBNMINT: not used. print a message */
1327 /* case SPIDER_NET_GANMINT: not used. print a message */
1328 /* case SPIDER_NET_GRFNMINT: not used. print a message */
1333 case SPIDER_NET_GDTFDCINT
:
1336 case SPIDER_NET_GTTEDINT
:
1339 case SPIDER_NET_GDTDCEINT
:
1340 /* chain end. If a descriptor should be sent, kick off
1342 if (card->tx_chain.tail != card->tx_chain.head)
1343 spider_net_kick_tx_dma(card);
1348 /* case SPIDER_NET_G1TMCNTINT: not used. print a message */
1349 /* case SPIDER_NET_GFREECNTINT: not used. print a message */
1352 /* check GHIINT1STS ************************************/
1354 for (i
= 0; i
< 32; i
++)
1355 if (error_reg1
& (1<<i
))
1358 case SPIDER_NET_GTMFLLINT
:
1359 if (netif_msg_intr(card
) && net_ratelimit())
1360 pr_err("Spider TX RAM full\n");
1363 case SPIDER_NET_GRFDFLLINT
: /* fallthrough */
1364 case SPIDER_NET_GRFCFLLINT
: /* fallthrough */
1365 case SPIDER_NET_GRFBFLLINT
: /* fallthrough */
1366 case SPIDER_NET_GRFAFLLINT
: /* fallthrough */
1367 case SPIDER_NET_GRMFLLINT
:
1368 if (netif_msg_intr(card
) && net_ratelimit())
1369 pr_debug("Spider RX RAM full, incoming packets "
1370 "might be discarded!\n");
1371 spider_net_rx_irq_off(card
);
1372 tasklet_schedule(&card
->rxram_full_tl
);
1376 /* case SPIDER_NET_GTMSHTINT: problem, print a message */
1377 case SPIDER_NET_GDTINVDINT
:
1378 /* allrighty. tx from previous descr ok */
1383 case SPIDER_NET_GDDDCEINT
: /* fallthrough */
1384 case SPIDER_NET_GDCDCEINT
: /* fallthrough */
1385 case SPIDER_NET_GDBDCEINT
: /* fallthrough */
1386 case SPIDER_NET_GDADCEINT
:
1387 if (netif_msg_intr(card
))
1388 pr_err("got descriptor chain end interrupt, "
1389 "restarting DMAC %c.\n",
1390 'D'-(i
-SPIDER_NET_GDDDCEINT
)/3);
1391 spider_net_refill_rx_chain(card
);
1392 spider_net_enable_rxdmac(card
);
1396 /* invalid descriptor */
1397 case SPIDER_NET_GDDINVDINT
: /* fallthrough */
1398 case SPIDER_NET_GDCINVDINT
: /* fallthrough */
1399 case SPIDER_NET_GDBINVDINT
: /* fallthrough */
1400 case SPIDER_NET_GDAINVDINT
:
1401 /* could happen when rx chain is full */
1402 spider_net_refill_rx_chain(card
);
1403 spider_net_enable_rxdmac(card
);
1407 /* case SPIDER_NET_GDTRSERINT: problem, print a message */
1408 /* case SPIDER_NET_GDDRSERINT: problem, print a message */
1409 /* case SPIDER_NET_GDCRSERINT: problem, print a message */
1410 /* case SPIDER_NET_GDBRSERINT: problem, print a message */
1411 /* case SPIDER_NET_GDARSERINT: problem, print a message */
1412 /* case SPIDER_NET_GDSERINT: problem, print a message */
1413 /* case SPIDER_NET_GDTPTERINT: problem, print a message */
1414 /* case SPIDER_NET_GDDPTERINT: problem, print a message */
1415 /* case SPIDER_NET_GDCPTERINT: problem, print a message */
1416 /* case SPIDER_NET_GDBPTERINT: problem, print a message */
1417 /* case SPIDER_NET_GDAPTERINT: problem, print a message */
1423 /* check GHIINT2STS ************************************/
1425 for (i
= 0; i
< 32; i
++)
1426 if (error_reg2
& (1<<i
))
1429 /* there is nothing we can (want to) do at this time. Log a
1430 * message, we can switch on and off the specific values later on
1431 case SPIDER_NET_GPROPERINT:
1432 case SPIDER_NET_GMCTCRSNGINT:
1433 case SPIDER_NET_GMCTLCOLINT:
1434 case SPIDER_NET_GMCTTMOTINT:
1435 case SPIDER_NET_GMCRCAERINT:
1436 case SPIDER_NET_GMCRCALERINT:
1437 case SPIDER_NET_GMCRALNERINT:
1438 case SPIDER_NET_GMCROVRINT:
1439 case SPIDER_NET_GMCRRNTINT:
1440 case SPIDER_NET_GMCRRXERINT:
1441 case SPIDER_NET_GTITCSERINT:
1442 case SPIDER_NET_GTIFMTERINT:
1443 case SPIDER_NET_GTIPKTRVKINT:
1444 case SPIDER_NET_GTISPINGINT:
1445 case SPIDER_NET_GTISADNGINT:
1446 case SPIDER_NET_GTISPDNGINT:
1447 case SPIDER_NET_GRIFMTERINT:
1448 case SPIDER_NET_GRIPKTRVKINT:
1449 case SPIDER_NET_GRISPINGINT:
1450 case SPIDER_NET_GRISADNGINT:
1451 case SPIDER_NET_GRISPDNGINT:
1458 if ((show_error
) && (netif_msg_intr(card
)))
1459 pr_err("Got error interrupt on %s, GHIINT0STS = 0x%08x, "
1460 "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n",
1462 status_reg
, error_reg1
, error_reg2
);
1464 /* clear interrupt sources */
1465 spider_net_write_reg(card
, SPIDER_NET_GHIINT1STS
, error_reg1
);
1466 spider_net_write_reg(card
, SPIDER_NET_GHIINT2STS
, error_reg2
);
1470 * spider_net_interrupt - interrupt handler for spider_net
1471 * @irq: interupt number
1472 * @ptr: pointer to net_device
1473 * @regs: PU registers
1475 * returns IRQ_HANDLED, if interrupt was for driver, or IRQ_NONE, if no
1476 * interrupt found raised by card.
1478 * This is the interrupt handler, that turns off
1479 * interrupts for this device and makes the stack poll the driver
1482 spider_net_interrupt(int irq
, void *ptr
)
1484 struct net_device
*netdev
= ptr
;
1485 struct spider_net_card
*card
= netdev_priv(netdev
);
1488 status_reg
= spider_net_read_reg(card
, SPIDER_NET_GHIINT0STS
);
1493 if (status_reg
& SPIDER_NET_RXINT
) {
1494 spider_net_rx_irq_off(card
);
1495 netif_rx_schedule(netdev
);
1497 if (status_reg
& SPIDER_NET_TXINT
)
1498 netif_rx_schedule(netdev
);
1500 if (status_reg
& SPIDER_NET_ERRINT
)
1501 spider_net_handle_error_irq(card
, status_reg
);
1503 /* clear interrupt sources */
1504 spider_net_write_reg(card
, SPIDER_NET_GHIINT0STS
, status_reg
);
1509 #ifdef CONFIG_NET_POLL_CONTROLLER
1511 * spider_net_poll_controller - artificial interrupt for netconsole etc.
1512 * @netdev: interface device structure
1514 * see Documentation/networking/netconsole.txt
1517 spider_net_poll_controller(struct net_device
*netdev
)
1519 disable_irq(netdev
->irq
);
1520 spider_net_interrupt(netdev
->irq
, netdev
);
1521 enable_irq(netdev
->irq
);
1523 #endif /* CONFIG_NET_POLL_CONTROLLER */
1526 * spider_net_init_card - initializes the card
1527 * @card: card structure
1529 * spider_net_init_card initializes the card so that other registers can
1533 spider_net_init_card(struct spider_net_card
*card
)
1535 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1536 SPIDER_NET_CKRCTRL_STOP_VALUE
);
1538 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1539 SPIDER_NET_CKRCTRL_RUN_VALUE
);
1543 * spider_net_enable_card - enables the card by setting all kinds of regs
1544 * @card: card structure
1546 * spider_net_enable_card sets a lot of SMMIO registers to enable the device
1549 spider_net_enable_card(struct spider_net_card
*card
)
1552 /* the following array consists of (register),(value) pairs
1553 * that are set in this function. A register of 0 ends the list */
1555 { SPIDER_NET_GRESUMINTNUM
, 0 },
1556 { SPIDER_NET_GREINTNUM
, 0 },
1558 /* set interrupt frame number registers */
1559 /* clear the single DMA engine registers first */
1560 { SPIDER_NET_GFAFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1561 { SPIDER_NET_GFBFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1562 { SPIDER_NET_GFCFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1563 { SPIDER_NET_GFDFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1564 /* then set, what we really need */
1565 { SPIDER_NET_GFFRMNUM
, SPIDER_NET_FRAMENUM_VALUE
},
1567 /* timer counter registers and stuff */
1568 { SPIDER_NET_GFREECNNUM
, 0 },
1569 { SPIDER_NET_GONETIMENUM
, 0 },
1570 { SPIDER_NET_GTOUTFRMNUM
, 0 },
1572 /* RX mode setting */
1573 { SPIDER_NET_GRXMDSET
, SPIDER_NET_RXMODE_VALUE
},
1574 /* TX mode setting */
1575 { SPIDER_NET_GTXMDSET
, SPIDER_NET_TXMODE_VALUE
},
1576 /* IPSEC mode setting */
1577 { SPIDER_NET_GIPSECINIT
, SPIDER_NET_IPSECINIT_VALUE
},
1579 { SPIDER_NET_GFTRESTRT
, SPIDER_NET_RESTART_VALUE
},
1581 { SPIDER_NET_GMRWOLCTRL
, 0 },
1582 { SPIDER_NET_GTESTMD
, 0x10000000 },
1583 { SPIDER_NET_GTTQMSK
, 0x00400040 },
1585 { SPIDER_NET_GMACINTEN
, 0 },
1587 /* flow control stuff */
1588 { SPIDER_NET_GMACAPAUSE
, SPIDER_NET_MACAPAUSE_VALUE
},
1589 { SPIDER_NET_GMACTXPAUSE
, SPIDER_NET_TXPAUSE_VALUE
},
1591 { SPIDER_NET_GMACBSTLMT
, SPIDER_NET_BURSTLMT_VALUE
},
1596 while (regs
[i
][0]) {
1597 spider_net_write_reg(card
, regs
[i
][0], regs
[i
][1]);
1601 /* clear unicast filter table entries 1 to 14 */
1602 for (i
= 1; i
<= 14; i
++) {
1603 spider_net_write_reg(card
,
1604 SPIDER_NET_GMRUAFILnR
+ i
* 8,
1606 spider_net_write_reg(card
,
1607 SPIDER_NET_GMRUAFILnR
+ i
* 8 + 4,
1611 spider_net_write_reg(card
, SPIDER_NET_GMRUA0FIL15R
, 0x08080000);
1613 spider_net_write_reg(card
, SPIDER_NET_ECMODE
, SPIDER_NET_ECMODE_VALUE
);
1615 /* set chain tail adress for RX chains and
1617 spider_net_enable_rxchtails(card
);
1618 spider_net_enable_rxdmac(card
);
1620 spider_net_write_reg(card
, SPIDER_NET_GRXDMAEN
, SPIDER_NET_WOL_VALUE
);
1622 spider_net_write_reg(card
, SPIDER_NET_GMACLENLMT
,
1623 SPIDER_NET_LENLMT_VALUE
);
1624 spider_net_write_reg(card
, SPIDER_NET_GMACMODE
,
1625 SPIDER_NET_MACMODE_VALUE
);
1626 spider_net_write_reg(card
, SPIDER_NET_GMACOPEMD
,
1627 SPIDER_NET_OPMODE_VALUE
);
1629 /* set interrupt mask registers */
1630 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
,
1631 SPIDER_NET_INT0_MASK_VALUE
);
1632 spider_net_write_reg(card
, SPIDER_NET_GHIINT1MSK
,
1633 SPIDER_NET_INT1_MASK_VALUE
);
1634 spider_net_write_reg(card
, SPIDER_NET_GHIINT2MSK
,
1635 SPIDER_NET_INT2_MASK_VALUE
);
1637 spider_net_write_reg(card
, SPIDER_NET_GDTDMACCNTR
,
1638 SPIDER_NET_GDTBSTA
);
1642 * spider_net_open - called upon ifonfig up
1643 * @netdev: interface device structure
1645 * returns 0 on success, <0 on failure
1647 * spider_net_open allocates all the descriptors and memory needed for
1648 * operation, sets up multicast list and enables interrupts
1651 spider_net_open(struct net_device
*netdev
)
1653 struct spider_net_card
*card
= netdev_priv(netdev
);
1654 struct spider_net_descr
*descr
;
1658 if (spider_net_init_chain(card
, &card
->tx_chain
, card
->descr
,
1660 goto alloc_tx_failed
;
1662 card
->low_watermark
= NULL
;
1664 /* rx_chain is after tx_chain, so offset is descr + tx_count */
1665 if (spider_net_init_chain(card
, &card
->rx_chain
,
1666 card
->descr
+ card
->num_tx_desc
,
1668 goto alloc_rx_failed
;
1670 descr
= card
->rx_chain
.head
;
1671 for (i
=0; i
< card
->num_rx_desc
; i
++, descr
++)
1672 descr
->next_descr_addr
= descr
->next
->bus_addr
;
1674 /* allocate rx skbs */
1675 if (spider_net_alloc_rx_skbs(card
))
1676 goto alloc_skbs_failed
;
1678 spider_net_set_multi(netdev
);
1680 /* further enhancement: setup hw vlan, if needed */
1683 if (request_irq(netdev
->irq
, spider_net_interrupt
,
1684 IRQF_SHARED
, netdev
->name
, netdev
))
1685 goto register_int_failed
;
1687 spider_net_enable_card(card
);
1689 netif_start_queue(netdev
);
1690 netif_carrier_on(netdev
);
1691 netif_poll_enable(netdev
);
1695 register_int_failed
:
1696 spider_net_free_rx_chain_contents(card
);
1698 spider_net_free_chain(card
, &card
->rx_chain
);
1700 spider_net_free_chain(card
, &card
->tx_chain
);
1706 * spider_net_setup_phy - setup PHY
1707 * @card: card structure
1709 * returns 0 on success, <0 on failure
1711 * spider_net_setup_phy is used as part of spider_net_probe. Sets
1712 * the PHY to 1000 Mbps
1715 spider_net_setup_phy(struct spider_net_card
*card
)
1717 struct mii_phy
*phy
= &card
->phy
;
1719 spider_net_write_reg(card
, SPIDER_NET_GDTDMASEL
,
1720 SPIDER_NET_DMASEL_VALUE
);
1721 spider_net_write_reg(card
, SPIDER_NET_GPCCTRL
,
1722 SPIDER_NET_PHY_CTRL_VALUE
);
1724 phy
->dev
= card
->netdev
;
1725 phy
->mdio_read
= spider_net_read_phy
;
1726 phy
->mdio_write
= spider_net_write_phy
;
1728 mii_phy_probe(phy
, phy
->mii_id
);
1730 if (phy
->def
->ops
->setup_forced
)
1731 phy
->def
->ops
->setup_forced(phy
, SPEED_1000
, DUPLEX_FULL
);
1733 phy
->def
->ops
->enable_fiber(phy
);
1735 phy
->def
->ops
->read_link(phy
);
1736 pr_info("Found %s with %i Mbps, %s-duplex.\n", phy
->def
->name
,
1737 phy
->speed
, phy
->duplex
==1 ? "Full" : "Half");
1743 * spider_net_download_firmware - loads firmware into the adapter
1744 * @card: card structure
1745 * @firmware_ptr: pointer to firmware data
1747 * spider_net_download_firmware loads the firmware data into the
1748 * adapter. It assumes the length etc. to be allright.
1751 spider_net_download_firmware(struct spider_net_card
*card
,
1752 const void *firmware_ptr
)
1755 const u32
*fw_ptr
= firmware_ptr
;
1757 /* stop sequencers */
1758 spider_net_write_reg(card
, SPIDER_NET_GSINIT
,
1759 SPIDER_NET_STOP_SEQ_VALUE
);
1761 for (sequencer
= 0; sequencer
< SPIDER_NET_FIRMWARE_SEQS
;
1763 spider_net_write_reg(card
,
1764 SPIDER_NET_GSnPRGADR
+ sequencer
* 8, 0);
1765 for (i
= 0; i
< SPIDER_NET_FIRMWARE_SEQWORDS
; i
++) {
1766 spider_net_write_reg(card
, SPIDER_NET_GSnPRGDAT
+
1767 sequencer
* 8, *fw_ptr
);
1772 if (spider_net_read_reg(card
, SPIDER_NET_GSINIT
))
1775 spider_net_write_reg(card
, SPIDER_NET_GSINIT
,
1776 SPIDER_NET_RUN_SEQ_VALUE
);
1782 * spider_net_init_firmware - reads in firmware parts
1783 * @card: card structure
1785 * Returns 0 on success, <0 on failure
1787 * spider_net_init_firmware opens the sequencer firmware and does some basic
1788 * checks. This function opens and releases the firmware structure. A call
1789 * to download the firmware is performed before the release.
1793 * spider_fw.bin is expected to be a file containing 6*1024*4 bytes, 4k being
1794 * the program for each sequencer. Use the command
1795 * tail -q -n +2 Seq_code1_0x088.txt Seq_code2_0x090.txt \
1796 * Seq_code3_0x098.txt Seq_code4_0x0A0.txt Seq_code5_0x0A8.txt \
1797 * Seq_code6_0x0B0.txt | xxd -r -p -c4 > spider_fw.bin
1799 * to generate spider_fw.bin, if you have sequencer programs with something
1800 * like the following contents for each sequencer:
1801 * <ONE LINE COMMENT>
1802 * <FIRST 4-BYTES-WORD FOR SEQUENCER>
1803 * <SECOND 4-BYTES-WORD FOR SEQUENCER>
1805 * <1024th 4-BYTES-WORD FOR SEQUENCER>
1808 spider_net_init_firmware(struct spider_net_card
*card
)
1810 struct firmware
*firmware
= NULL
;
1811 struct device_node
*dn
;
1812 const u8
*fw_prop
= NULL
;
1816 if (request_firmware((const struct firmware
**)&firmware
,
1817 SPIDER_NET_FIRMWARE_NAME
, &card
->pdev
->dev
) == 0) {
1818 if ( (firmware
->size
!= SPIDER_NET_FIRMWARE_LEN
) &&
1819 netif_msg_probe(card
) ) {
1820 pr_err("Incorrect size of spidernet firmware in " \
1821 "filesystem. Looking in host firmware...\n");
1824 err
= spider_net_download_firmware(card
, firmware
->data
);
1826 release_firmware(firmware
);
1834 dn
= pci_device_to_OF_node(card
->pdev
);
1838 fw_prop
= get_property(dn
, "firmware", &fw_size
);
1842 if ( (fw_size
!= SPIDER_NET_FIRMWARE_LEN
) &&
1843 netif_msg_probe(card
) ) {
1844 pr_err("Incorrect size of spidernet firmware in " \
1849 err
= spider_net_download_firmware(card
, fw_prop
);
1854 if (netif_msg_probe(card
))
1855 pr_err("Couldn't find spidernet firmware in filesystem " \
1856 "or host firmware\n");
1861 * spider_net_workaround_rxramfull - work around firmware bug
1862 * @card: card structure
1867 spider_net_workaround_rxramfull(struct spider_net_card
*card
)
1869 int i
, sequencer
= 0;
1872 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1873 SPIDER_NET_CKRCTRL_RUN_VALUE
);
1875 /* empty sequencer data */
1876 for (sequencer
= 0; sequencer
< SPIDER_NET_FIRMWARE_SEQS
;
1878 spider_net_write_reg(card
, SPIDER_NET_GSnPRGADR
+
1879 sequencer
* 8, 0x0);
1880 for (i
= 0; i
< SPIDER_NET_FIRMWARE_SEQWORDS
; i
++) {
1881 spider_net_write_reg(card
, SPIDER_NET_GSnPRGDAT
+
1882 sequencer
* 8, 0x0);
1886 /* set sequencer operation */
1887 spider_net_write_reg(card
, SPIDER_NET_GSINIT
, 0x000000fe);
1890 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1891 SPIDER_NET_CKRCTRL_STOP_VALUE
);
1895 * spider_net_stop - called upon ifconfig down
1896 * @netdev: interface device structure
1901 spider_net_stop(struct net_device
*netdev
)
1903 struct spider_net_card
*card
= netdev_priv(netdev
);
1905 tasklet_kill(&card
->rxram_full_tl
);
1906 netif_poll_disable(netdev
);
1907 netif_carrier_off(netdev
);
1908 netif_stop_queue(netdev
);
1909 del_timer_sync(&card
->tx_timer
);
1911 /* disable/mask all interrupts */
1912 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
, 0);
1913 spider_net_write_reg(card
, SPIDER_NET_GHIINT1MSK
, 0);
1914 spider_net_write_reg(card
, SPIDER_NET_GHIINT2MSK
, 0);
1916 /* free_irq(netdev->irq, netdev);*/
1917 free_irq(to_pci_dev(netdev
->class_dev
.dev
)->irq
, netdev
);
1919 spider_net_write_reg(card
, SPIDER_NET_GDTDMACCNTR
,
1920 SPIDER_NET_DMA_TX_FEND_VALUE
);
1922 /* turn off DMA, force end */
1923 spider_net_disable_rxdmac(card
);
1925 /* release chains */
1926 spider_net_release_tx_chain(card
, 1);
1928 spider_net_free_rx_chain_contents(card
);
1930 spider_net_free_chain(card
, &card
->tx_chain
);
1931 spider_net_free_chain(card
, &card
->rx_chain
);
1937 * spider_net_tx_timeout_task - task scheduled by the watchdog timeout
1938 * function (to be called not under interrupt status)
1939 * @data: data, is interface device structure
1941 * called as task when tx hangs, resets interface (if interface is up)
1944 spider_net_tx_timeout_task(struct work_struct
*work
)
1946 struct spider_net_card
*card
=
1947 container_of(work
, struct spider_net_card
, tx_timeout_task
);
1948 struct net_device
*netdev
= card
->netdev
;
1950 if (!(netdev
->flags
& IFF_UP
))
1953 netif_device_detach(netdev
);
1954 spider_net_stop(netdev
);
1956 spider_net_workaround_rxramfull(card
);
1957 spider_net_init_card(card
);
1959 if (spider_net_setup_phy(card
))
1961 if (spider_net_init_firmware(card
))
1964 spider_net_open(netdev
);
1965 spider_net_kick_tx_dma(card
);
1966 netif_device_attach(netdev
);
1969 atomic_dec(&card
->tx_timeout_task_counter
);
1973 * spider_net_tx_timeout - called when the tx timeout watchdog kicks in.
1974 * @netdev: interface device structure
1976 * called, if tx hangs. Schedules a task that resets the interface
1979 spider_net_tx_timeout(struct net_device
*netdev
)
1981 struct spider_net_card
*card
;
1983 card
= netdev_priv(netdev
);
1984 atomic_inc(&card
->tx_timeout_task_counter
);
1985 if (netdev
->flags
& IFF_UP
)
1986 schedule_work(&card
->tx_timeout_task
);
1988 atomic_dec(&card
->tx_timeout_task_counter
);
1989 card
->spider_stats
.tx_timeouts
++;
1993 * spider_net_setup_netdev_ops - initialization of net_device operations
1994 * @netdev: net_device structure
1996 * fills out function pointers in the net_device structure
1999 spider_net_setup_netdev_ops(struct net_device
*netdev
)
2001 netdev
->open
= &spider_net_open
;
2002 netdev
->stop
= &spider_net_stop
;
2003 netdev
->hard_start_xmit
= &spider_net_xmit
;
2004 netdev
->get_stats
= &spider_net_get_stats
;
2005 netdev
->set_multicast_list
= &spider_net_set_multi
;
2006 netdev
->set_mac_address
= &spider_net_set_mac
;
2007 netdev
->change_mtu
= &spider_net_change_mtu
;
2008 netdev
->do_ioctl
= &spider_net_do_ioctl
;
2010 netdev
->tx_timeout
= &spider_net_tx_timeout
;
2011 netdev
->watchdog_timeo
= SPIDER_NET_WATCHDOG_TIMEOUT
;
2013 netdev
->poll
= &spider_net_poll
;
2014 netdev
->weight
= SPIDER_NET_NAPI_WEIGHT
;
2016 netdev
->vlan_rx_register
= &spider_net_vlan_rx_reg
;
2017 netdev
->vlan_rx_add_vid
= &spider_net_vlan_rx_add
;
2018 netdev
->vlan_rx_kill_vid
= &spider_net_vlan_rx_kill
;
2019 #ifdef CONFIG_NET_POLL_CONTROLLER
2020 /* poll controller */
2021 netdev
->poll_controller
= &spider_net_poll_controller
;
2022 #endif /* CONFIG_NET_POLL_CONTROLLER */
2024 netdev
->ethtool_ops
= &spider_net_ethtool_ops
;
2028 * spider_net_setup_netdev - initialization of net_device
2029 * @card: card structure
2031 * Returns 0 on success or <0 on failure
2033 * spider_net_setup_netdev initializes the net_device structure
2036 spider_net_setup_netdev(struct spider_net_card
*card
)
2039 struct net_device
*netdev
= card
->netdev
;
2040 struct device_node
*dn
;
2041 struct sockaddr addr
;
2044 SET_MODULE_OWNER(netdev
);
2045 SET_NETDEV_DEV(netdev
, &card
->pdev
->dev
);
2047 pci_set_drvdata(card
->pdev
, netdev
);
2049 card
->rxram_full_tl
.data
= (unsigned long) card
;
2050 card
->rxram_full_tl
.func
=
2051 (void (*)(unsigned long)) spider_net_handle_rxram_full
;
2052 init_timer(&card
->tx_timer
);
2053 card
->tx_timer
.function
=
2054 (void (*)(unsigned long)) spider_net_cleanup_tx_ring
;
2055 card
->tx_timer
.data
= (unsigned long) card
;
2056 netdev
->irq
= card
->pdev
->irq
;
2058 card
->options
.rx_csum
= SPIDER_NET_RX_CSUM_DEFAULT
;
2060 card
->num_tx_desc
= tx_descriptors
;
2061 card
->num_rx_desc
= rx_descriptors
;
2063 spider_net_setup_netdev_ops(netdev
);
2065 netdev
->features
= NETIF_F_HW_CSUM
| NETIF_F_LLTX
;
2066 /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
2067 * NETIF_F_HW_VLAN_FILTER */
2069 netdev
->irq
= card
->pdev
->irq
;
2071 dn
= pci_device_to_OF_node(card
->pdev
);
2075 mac
= get_property(dn
, "local-mac-address", NULL
);
2078 memcpy(addr
.sa_data
, mac
, ETH_ALEN
);
2080 result
= spider_net_set_mac(netdev
, &addr
);
2081 if ((result
) && (netif_msg_probe(card
)))
2082 pr_err("Failed to set MAC address: %i\n", result
);
2084 result
= register_netdev(netdev
);
2086 if (netif_msg_probe(card
))
2087 pr_err("Couldn't register net_device: %i\n",
2092 if (netif_msg_probe(card
))
2093 pr_info("Initialized device %s.\n", netdev
->name
);
2099 * spider_net_alloc_card - allocates net_device and card structure
2101 * returns the card structure or NULL in case of errors
2103 * the card and net_device structures are linked to each other
2105 static struct spider_net_card
*
2106 spider_net_alloc_card(void)
2108 struct net_device
*netdev
;
2109 struct spider_net_card
*card
;
2112 alloc_size
= sizeof (*card
) +
2113 sizeof (struct spider_net_descr
) * rx_descriptors
+
2114 sizeof (struct spider_net_descr
) * tx_descriptors
;
2115 netdev
= alloc_etherdev(alloc_size
);
2119 card
= netdev_priv(netdev
);
2120 card
->netdev
= netdev
;
2121 card
->msg_enable
= SPIDER_NET_DEFAULT_MSG
;
2122 INIT_WORK(&card
->tx_timeout_task
, spider_net_tx_timeout_task
);
2123 init_waitqueue_head(&card
->waitq
);
2124 atomic_set(&card
->tx_timeout_task_counter
, 0);
2130 * spider_net_undo_pci_setup - releases PCI ressources
2131 * @card: card structure
2133 * spider_net_undo_pci_setup releases the mapped regions
2136 spider_net_undo_pci_setup(struct spider_net_card
*card
)
2138 iounmap(card
->regs
);
2139 pci_release_regions(card
->pdev
);
2143 * spider_net_setup_pci_dev - sets up the device in terms of PCI operations
2144 * @card: card structure
2147 * Returns the card structure or NULL if any errors occur
2149 * spider_net_setup_pci_dev initializes pdev and together with the
2150 * functions called in spider_net_open configures the device so that
2151 * data can be transferred over it
2152 * The net_device structure is attached to the card structure, if the
2153 * function returns without error.
2155 static struct spider_net_card
*
2156 spider_net_setup_pci_dev(struct pci_dev
*pdev
)
2158 struct spider_net_card
*card
;
2159 unsigned long mmio_start
, mmio_len
;
2161 if (pci_enable_device(pdev
)) {
2162 pr_err("Couldn't enable PCI device\n");
2166 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
2167 pr_err("Couldn't find proper PCI device base address.\n");
2168 goto out_disable_dev
;
2171 if (pci_request_regions(pdev
, spider_net_driver_name
)) {
2172 pr_err("Couldn't obtain PCI resources, aborting.\n");
2173 goto out_disable_dev
;
2176 pci_set_master(pdev
);
2178 card
= spider_net_alloc_card();
2180 pr_err("Couldn't allocate net_device structure, "
2182 goto out_release_regions
;
2186 /* fetch base address and length of first resource */
2187 mmio_start
= pci_resource_start(pdev
, 0);
2188 mmio_len
= pci_resource_len(pdev
, 0);
2190 card
->netdev
->mem_start
= mmio_start
;
2191 card
->netdev
->mem_end
= mmio_start
+ mmio_len
;
2192 card
->regs
= ioremap(mmio_start
, mmio_len
);
2195 pr_err("Couldn't obtain PCI resources, aborting.\n");
2196 goto out_release_regions
;
2201 out_release_regions
:
2202 pci_release_regions(pdev
);
2204 pci_disable_device(pdev
);
2205 pci_set_drvdata(pdev
, NULL
);
2210 * spider_net_probe - initialization of a device
2212 * @ent: entry in the device id list
2214 * Returns 0 on success, <0 on failure
2216 * spider_net_probe initializes pdev and registers a net_device
2217 * structure for it. After that, the device can be ifconfig'ed up
2219 static int __devinit
2220 spider_net_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2223 struct spider_net_card
*card
;
2225 card
= spider_net_setup_pci_dev(pdev
);
2229 spider_net_workaround_rxramfull(card
);
2230 spider_net_init_card(card
);
2232 err
= spider_net_setup_phy(card
);
2236 err
= spider_net_init_firmware(card
);
2240 err
= spider_net_setup_netdev(card
);
2247 spider_net_undo_pci_setup(card
);
2248 free_netdev(card
->netdev
);
2254 * spider_net_remove - removal of a device
2257 * Returns 0 on success, <0 on failure
2259 * spider_net_remove is called to remove the device and unregisters the
2262 static void __devexit
2263 spider_net_remove(struct pci_dev
*pdev
)
2265 struct net_device
*netdev
;
2266 struct spider_net_card
*card
;
2268 netdev
= pci_get_drvdata(pdev
);
2269 card
= netdev_priv(netdev
);
2271 wait_event(card
->waitq
,
2272 atomic_read(&card
->tx_timeout_task_counter
) == 0);
2274 unregister_netdev(netdev
);
2276 /* switch off card */
2277 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
2278 SPIDER_NET_CKRCTRL_STOP_VALUE
);
2279 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
2280 SPIDER_NET_CKRCTRL_RUN_VALUE
);
2282 spider_net_undo_pci_setup(card
);
2283 free_netdev(netdev
);
2286 static struct pci_driver spider_net_driver
= {
2287 .name
= spider_net_driver_name
,
2288 .id_table
= spider_net_pci_tbl
,
2289 .probe
= spider_net_probe
,
2290 .remove
= __devexit_p(spider_net_remove
)
2294 * spider_net_init - init function when the driver is loaded
2296 * spider_net_init registers the device driver
2298 static int __init
spider_net_init(void)
2300 printk(KERN_INFO
"Spidernet version %s.\n", VERSION
);
2302 if (rx_descriptors
< SPIDER_NET_RX_DESCRIPTORS_MIN
) {
2303 rx_descriptors
= SPIDER_NET_RX_DESCRIPTORS_MIN
;
2304 pr_info("adjusting rx descriptors to %i.\n", rx_descriptors
);
2306 if (rx_descriptors
> SPIDER_NET_RX_DESCRIPTORS_MAX
) {
2307 rx_descriptors
= SPIDER_NET_RX_DESCRIPTORS_MAX
;
2308 pr_info("adjusting rx descriptors to %i.\n", rx_descriptors
);
2310 if (tx_descriptors
< SPIDER_NET_TX_DESCRIPTORS_MIN
) {
2311 tx_descriptors
= SPIDER_NET_TX_DESCRIPTORS_MIN
;
2312 pr_info("adjusting tx descriptors to %i.\n", tx_descriptors
);
2314 if (tx_descriptors
> SPIDER_NET_TX_DESCRIPTORS_MAX
) {
2315 tx_descriptors
= SPIDER_NET_TX_DESCRIPTORS_MAX
;
2316 pr_info("adjusting tx descriptors to %i.\n", tx_descriptors
);
2319 return pci_register_driver(&spider_net_driver
);
2323 * spider_net_cleanup - exit function when driver is unloaded
2325 * spider_net_cleanup unregisters the device driver
2327 static void __exit
spider_net_cleanup(void)
2329 pci_unregister_driver(&spider_net_driver
);
2332 module_init(spider_net_init
);
2333 module_exit(spider_net_cleanup
);