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/config.h>
25 #include <linux/compiler.h>
26 #include <linux/crc32.h>
27 #include <linux/delay.h>
28 #include <linux/etherdevice.h>
29 #include <linux/ethtool.h>
30 #include <linux/firmware.h>
31 #include <linux/if_vlan.h>
33 #include <linux/init.h>
34 #include <linux/ioport.h>
36 #include <linux/kernel.h>
37 #include <linux/mii.h>
38 #include <linux/module.h>
39 #include <linux/netdevice.h>
40 #include <linux/device.h>
41 #include <linux/pci.h>
42 #include <linux/skbuff.h>
43 #include <linux/slab.h>
44 #include <linux/tcp.h>
45 #include <linux/types.h>
46 #include <linux/vmalloc.h>
47 #include <linux/wait.h>
48 #include <linux/workqueue.h>
49 #include <asm/bitops.h>
50 #include <asm/pci-bridge.h>
51 #include <net/checksum.h>
53 #include "spider_net.h"
55 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com> and Jens Osterkamp " \
56 "<Jens.Osterkamp@de.ibm.com>");
57 MODULE_DESCRIPTION("Spider Southbridge Gigabit Ethernet driver");
58 MODULE_LICENSE("GPL");
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, 0644);
64 module_param(tx_descriptors
, int, 0644);
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
)
93 value
= readl(card
->regs
+ reg
);
94 value
= le32_to_cpu(value
);
100 * spider_net_write_reg - writes to an SMMIO register of a card
101 * @card: device structure
102 * @reg: register to write to
103 * @value: value to write into the specified SMMIO register
106 spider_net_write_reg(struct spider_net_card
*card
, u32 reg
, u32 value
)
108 value
= cpu_to_le32(value
);
109 writel(value
, card
->regs
+ reg
);
112 /** spider_net_write_phy - write to phy register
113 * @netdev: adapter to be written to
116 * @val: value to be written to phy register
118 * spider_net_write_phy_register writes to an arbitrary PHY
119 * register via the spider GPCWOPCMD register. We assume the queue does
120 * not run full (not more than 15 commands outstanding).
123 spider_net_write_phy(struct net_device
*netdev
, int mii_id
,
126 struct spider_net_card
*card
= netdev_priv(netdev
);
129 writevalue
= ((u32
)mii_id
<< 21) |
130 ((u32
)reg
<< 16) | ((u32
)val
);
132 spider_net_write_reg(card
, SPIDER_NET_GPCWOPCMD
, writevalue
);
135 /** spider_net_read_phy - read from phy register
136 * @netdev: network device to be read from
140 * Returns value read from PHY register
142 * spider_net_write_phy reads from an arbitrary PHY
143 * register via the spider GPCROPCMD register
146 spider_net_read_phy(struct net_device
*netdev
, int mii_id
, int reg
)
148 struct spider_net_card
*card
= netdev_priv(netdev
);
151 readvalue
= ((u32
)mii_id
<< 21) | ((u32
)reg
<< 16);
152 spider_net_write_reg(card
, SPIDER_NET_GPCROPCMD
, readvalue
);
154 /* we don't use semaphores to wait for an SPIDER_NET_GPROPCMPINT
155 * interrupt, as we poll for the completion of the read operation
156 * in spider_net_read_phy. Should take about 50 us */
158 readvalue
= spider_net_read_reg(card
, SPIDER_NET_GPCROPCMD
);
159 } while (readvalue
& SPIDER_NET_GPREXEC
);
161 readvalue
&= SPIDER_NET_GPRDAT_MASK
;
167 * spider_net_rx_irq_off - switch off rx irq on this spider card
168 * @card: device structure
170 * switches off rx irq by masking them out in the GHIINTnMSK register
173 spider_net_rx_irq_off(struct spider_net_card
*card
)
177 regvalue
= SPIDER_NET_INT0_MASK_VALUE
& (~SPIDER_NET_RXINT
);
178 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
, regvalue
);
182 * spider_net_rx_irq_on - switch on rx irq on this spider card
183 * @card: device structure
185 * switches on rx irq by enabling them in the GHIINTnMSK register
188 spider_net_rx_irq_on(struct spider_net_card
*card
)
192 regvalue
= SPIDER_NET_INT0_MASK_VALUE
| SPIDER_NET_RXINT
;
193 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
, regvalue
);
197 * spider_net_set_promisc - sets the unicast address or the promiscuous mode
198 * @card: card structure
200 * spider_net_set_promisc sets the unicast destination address filter and
201 * thus either allows for non-promisc mode or promisc mode
204 spider_net_set_promisc(struct spider_net_card
*card
)
207 struct net_device
*netdev
= card
->netdev
;
209 if (netdev
->flags
& IFF_PROMISC
) {
210 /* clear destination entry 0 */
211 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
, 0);
212 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
+ 0x04, 0);
213 spider_net_write_reg(card
, SPIDER_NET_GMRUA0FIL15R
,
214 SPIDER_NET_PROMISC_VALUE
);
216 macu
= netdev
->dev_addr
[0];
218 macu
|= netdev
->dev_addr
[1];
219 memcpy(&macl
, &netdev
->dev_addr
[2], sizeof(macl
));
221 macu
|= SPIDER_NET_UA_DESCR_VALUE
;
222 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
, macu
);
223 spider_net_write_reg(card
, SPIDER_NET_GMRUAFILnR
+ 0x04, macl
);
224 spider_net_write_reg(card
, SPIDER_NET_GMRUA0FIL15R
,
225 SPIDER_NET_NONPROMISC_VALUE
);
230 * spider_net_get_mac_address - read mac address from spider card
231 * @card: device structure
233 * reads MAC address from GMACUNIMACU and GMACUNIMACL registers
236 spider_net_get_mac_address(struct net_device
*netdev
)
238 struct spider_net_card
*card
= netdev_priv(netdev
);
241 macl
= spider_net_read_reg(card
, SPIDER_NET_GMACUNIMACL
);
242 macu
= spider_net_read_reg(card
, SPIDER_NET_GMACUNIMACU
);
244 netdev
->dev_addr
[0] = (macu
>> 24) & 0xff;
245 netdev
->dev_addr
[1] = (macu
>> 16) & 0xff;
246 netdev
->dev_addr
[2] = (macu
>> 8) & 0xff;
247 netdev
->dev_addr
[3] = macu
& 0xff;
248 netdev
->dev_addr
[4] = (macl
>> 8) & 0xff;
249 netdev
->dev_addr
[5] = macl
& 0xff;
251 if (!is_valid_ether_addr(&netdev
->dev_addr
[0]))
258 * spider_net_get_descr_status -- returns the status of a descriptor
259 * @descr: descriptor to look at
261 * returns the status as in the dmac_cmd_status field of the descriptor
263 static enum spider_net_descr_status
264 spider_net_get_descr_status(struct spider_net_descr
*descr
)
268 cmd_status
= descr
->dmac_cmd_status
;
269 cmd_status
>>= SPIDER_NET_DESCR_IND_PROC_SHIFT
;
270 /* no need to mask out any bits, as cmd_status is 32 bits wide only
276 * spider_net_set_descr_status -- sets the status of a descriptor
277 * @descr: descriptor to change
278 * @status: status to set in the descriptor
280 * changes the status to the specified value. Doesn't change other bits
284 spider_net_set_descr_status(struct spider_net_descr
*descr
,
285 enum spider_net_descr_status status
)
288 /* read the status */
289 cmd_status
= descr
->dmac_cmd_status
;
290 /* clean the upper 4 bits */
291 cmd_status
&= SPIDER_NET_DESCR_IND_PROC_MASKO
;
292 /* add the status to it */
293 cmd_status
|= ((u32
)status
)<<SPIDER_NET_DESCR_IND_PROC_SHIFT
;
294 /* and write it back */
295 descr
->dmac_cmd_status
= cmd_status
;
299 * spider_net_free_chain - free descriptor chain
300 * @card: card structure
301 * @chain: address of chain
305 spider_net_free_chain(struct spider_net_card
*card
,
306 struct spider_net_descr_chain
*chain
)
308 struct spider_net_descr
*descr
;
310 for (descr
= chain
->tail
; !descr
->bus_addr
; descr
= descr
->next
) {
311 pci_unmap_single(card
->pdev
, descr
->bus_addr
,
312 SPIDER_NET_DESCR_SIZE
, PCI_DMA_BIDIRECTIONAL
);
318 * spider_net_init_chain - links descriptor chain
319 * @card: card structure
320 * @chain: address of chain
321 * @start_descr: address of descriptor array
322 * @no: number of descriptors
324 * we manage a circular list that mirrors the hardware structure,
325 * except that the hardware uses bus addresses.
327 * returns 0 on success, <0 on failure
330 spider_net_init_chain(struct spider_net_card
*card
,
331 struct spider_net_descr_chain
*chain
,
332 struct spider_net_descr
*start_descr
, int no
)
335 struct spider_net_descr
*descr
;
338 atomic_set(&card
->rx_chain_refill
,0);
341 memset(descr
, 0, sizeof(*descr
) * no
);
343 /* set up the hardware pointers in each descriptor */
344 for (i
=0; i
<no
; i
++, descr
++) {
345 spider_net_set_descr_status(descr
, SPIDER_NET_DESCR_NOT_IN_USE
);
347 buf
= pci_map_single(card
->pdev
, descr
,
348 SPIDER_NET_DESCR_SIZE
,
349 PCI_DMA_BIDIRECTIONAL
);
351 if (buf
== DMA_ERROR_CODE
)
354 descr
->bus_addr
= buf
;
355 descr
->next
= descr
+ 1;
356 descr
->prev
= descr
- 1;
359 /* do actual circular list */
360 (descr
-1)->next
= start_descr
;
361 start_descr
->prev
= descr
-1;
364 for (i
=0; i
< no
; i
++, descr
++) {
365 descr
->next_descr_addr
= descr
->next
->bus_addr
;
368 chain
->head
= start_descr
;
369 chain
->tail
= start_descr
;
375 for (i
=0; i
< no
; i
++, descr
++)
377 pci_unmap_single(card
->pdev
, descr
->bus_addr
,
378 SPIDER_NET_DESCR_SIZE
,
379 PCI_DMA_BIDIRECTIONAL
);
384 * spider_net_free_rx_chain_contents - frees descr contents in rx chain
385 * @card: card structure
387 * returns 0 on success, <0 on failure
390 spider_net_free_rx_chain_contents(struct spider_net_card
*card
)
392 struct spider_net_descr
*descr
;
394 descr
= card
->rx_chain
.head
;
395 while (descr
->next
!= card
->rx_chain
.head
) {
397 dev_kfree_skb(descr
->skb
);
398 pci_unmap_single(card
->pdev
, descr
->buf_addr
,
399 SPIDER_NET_MAX_FRAME
,
400 PCI_DMA_BIDIRECTIONAL
);
407 * spider_net_prepare_rx_descr - reinitializes a rx descriptor
408 * @card: card structure
409 * @descr: descriptor to re-init
411 * return 0 on succes, <0 on failure
413 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
414 * Activate the descriptor state-wise
417 spider_net_prepare_rx_descr(struct spider_net_card
*card
,
418 struct spider_net_descr
*descr
)
425 /* we need to round up the buffer size to a multiple of 128 */
426 bufsize
= (SPIDER_NET_MAX_FRAME
+ SPIDER_NET_RXBUF_ALIGN
- 1) &
427 (~(SPIDER_NET_RXBUF_ALIGN
- 1));
429 /* and we need to have it 128 byte aligned, therefore we allocate a
431 /* allocate an skb */
432 descr
->skb
= dev_alloc_skb(bufsize
+ SPIDER_NET_RXBUF_ALIGN
- 1);
434 if (netif_msg_rx_err(card
) && net_ratelimit())
435 pr_err("Not enough memory to allocate rx buffer\n");
438 descr
->buf_size
= bufsize
;
439 descr
->result_size
= 0;
440 descr
->valid_size
= 0;
441 descr
->data_status
= 0;
442 descr
->data_error
= 0;
444 offset
= ((unsigned long)descr
->skb
->data
) &
445 (SPIDER_NET_RXBUF_ALIGN
- 1);
447 skb_reserve(descr
->skb
, SPIDER_NET_RXBUF_ALIGN
- offset
);
448 /* io-mmu-map the skb */
449 buf
= pci_map_single(card
->pdev
, descr
->skb
->data
,
450 SPIDER_NET_MAX_FRAME
, PCI_DMA_BIDIRECTIONAL
);
451 descr
->buf_addr
= buf
;
452 if (buf
== DMA_ERROR_CODE
) {
453 dev_kfree_skb_any(descr
->skb
);
454 if (netif_msg_rx_err(card
) && net_ratelimit())
455 pr_err("Could not iommu-map rx buffer\n");
456 spider_net_set_descr_status(descr
, SPIDER_NET_DESCR_NOT_IN_USE
);
458 descr
->dmac_cmd_status
= SPIDER_NET_DMAC_RX_CARDOWNED
;
465 * spider_net_enable_rxchtails - sets RX dmac chain tail addresses
466 * @card: card structure
468 * spider_net_enable_rxchtails sets the RX DMAC chain tail adresses in the
469 * chip by writing to the appropriate register. DMA is enabled in
470 * spider_net_enable_rxdmac.
473 spider_net_enable_rxchtails(struct spider_net_card
*card
)
475 /* assume chain is aligned correctly */
476 spider_net_write_reg(card
, SPIDER_NET_GDADCHA
,
477 card
->rx_chain
.tail
->bus_addr
);
481 * spider_net_enable_rxdmac - enables a receive DMA controller
482 * @card: card structure
484 * spider_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
485 * in the GDADMACCNTR register
488 spider_net_enable_rxdmac(struct spider_net_card
*card
)
491 spider_net_write_reg(card
, SPIDER_NET_GDADMACCNTR
,
492 SPIDER_NET_DMA_RX_VALUE
);
496 * spider_net_refill_rx_chain - refills descriptors/skbs in the rx chains
497 * @card: card structure
499 * refills descriptors in the rx chain: allocates skbs and iommu-maps them.
502 spider_net_refill_rx_chain(struct spider_net_card
*card
)
504 struct spider_net_descr_chain
*chain
;
506 chain
= &card
->rx_chain
;
508 /* one context doing the refill (and a second context seeing that
509 * and omitting it) is ok. If called by NAPI, we'll be called again
510 * as spider_net_decode_one_descr is called several times. If some
511 * interrupt calls us, the NAPI is about to clean up anyway. */
512 if (atomic_inc_return(&card
->rx_chain_refill
) == 1)
513 while (spider_net_get_descr_status(chain
->head
) ==
514 SPIDER_NET_DESCR_NOT_IN_USE
) {
515 if (spider_net_prepare_rx_descr(card
, chain
->head
))
517 chain
->head
= chain
->head
->next
;
520 atomic_dec(&card
->rx_chain_refill
);
524 * spider_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
525 * @card: card structure
527 * returns 0 on success, <0 on failure
530 spider_net_alloc_rx_skbs(struct spider_net_card
*card
)
533 struct spider_net_descr_chain
*chain
;
537 chain
= &card
->rx_chain
;
538 /* put at least one buffer into the chain. if this fails,
539 * we've got a problem. if not, spider_net_refill_rx_chain
540 * will do the rest at the end of this function */
541 if (spider_net_prepare_rx_descr(card
, chain
->head
))
544 chain
->head
= chain
->head
->next
;
546 /* this will allocate the rest of the rx buffers; if not, it's
547 * business as usual later on */
548 spider_net_refill_rx_chain(card
);
549 spider_net_enable_rxdmac(card
);
553 spider_net_free_rx_chain_contents(card
);
558 * spider_net_release_tx_descr - processes a used tx descriptor
559 * @card: card structure
560 * @descr: descriptor to release
562 * releases a used tx descriptor (unmapping, freeing of skb)
565 spider_net_release_tx_descr(struct spider_net_card
*card
,
566 struct spider_net_descr
*descr
)
572 pci_unmap_single(card
->pdev
, descr
->buf_addr
, skb
->len
,
573 PCI_DMA_BIDIRECTIONAL
);
575 dev_kfree_skb_any(skb
);
577 /* set status to not used */
578 spider_net_set_descr_status(descr
, SPIDER_NET_DESCR_NOT_IN_USE
);
582 * spider_net_release_tx_chain - processes sent tx descriptors
583 * @card: adapter structure
584 * @brutal: if set, don't care about whether descriptor seems to be in use
586 * returns 0 if the tx ring is empty, otherwise 1.
588 * spider_net_release_tx_chain releases the tx descriptors that spider has
589 * finished with (if non-brutal) or simply release tx descriptors (if brutal).
590 * If some other context is calling this function, we return 1 so that we're
591 * scheduled again (if we were scheduled) and will not loose initiative.
594 spider_net_release_tx_chain(struct spider_net_card
*card
, int brutal
)
596 struct spider_net_descr_chain
*tx_chain
= &card
->tx_chain
;
597 enum spider_net_descr_status status
;
599 if (atomic_inc_return(&card
->tx_chain_release
) != 1) {
600 atomic_dec(&card
->tx_chain_release
);
605 status
= spider_net_get_descr_status(tx_chain
->tail
);
607 case SPIDER_NET_DESCR_CARDOWNED
:
610 /* fallthrough, if we release the descriptors
611 * brutally (then we don't care about
612 * SPIDER_NET_DESCR_CARDOWNED) */
613 case SPIDER_NET_DESCR_RESPONSE_ERROR
:
614 case SPIDER_NET_DESCR_PROTECTION_ERROR
:
615 case SPIDER_NET_DESCR_FORCE_END
:
616 if (netif_msg_tx_err(card
))
617 pr_err("%s: forcing end of tx descriptor "
618 "with status x%02x\n",
619 card
->netdev
->name
, status
);
620 card
->netdev_stats
.tx_dropped
++;
623 case SPIDER_NET_DESCR_COMPLETE
:
624 card
->netdev_stats
.tx_packets
++;
625 card
->netdev_stats
.tx_bytes
+=
626 tx_chain
->tail
->skb
->len
;
629 default: /* any other value (== SPIDER_NET_DESCR_NOT_IN_USE) */
632 spider_net_release_tx_descr(card
, tx_chain
->tail
);
633 tx_chain
->tail
= tx_chain
->tail
->next
;
636 atomic_dec(&card
->tx_chain_release
);
638 netif_wake_queue(card
->netdev
);
640 if (status
== SPIDER_NET_DESCR_CARDOWNED
)
646 * spider_net_cleanup_tx_ring - cleans up the TX ring
647 * @card: card structure
649 * spider_net_cleanup_tx_ring is called by the tx_timer (as we don't use
650 * interrupts to cleanup our TX ring) and returns sent packets to the stack
654 spider_net_cleanup_tx_ring(struct spider_net_card
*card
)
656 if ( (spider_net_release_tx_chain(card
, 0)) &&
657 (card
->netdev
->flags
& IFF_UP
) ) {
658 mod_timer(&card
->tx_timer
, jiffies
+ SPIDER_NET_TX_TIMER
);
663 * spider_net_get_multicast_hash - generates hash for multicast filter table
664 * @addr: multicast address
666 * returns the hash value.
668 * spider_net_get_multicast_hash calculates a hash value for a given multicast
669 * address, that is used to set the multicast filter tables
672 spider_net_get_multicast_hash(struct net_device
*netdev
, __u8
*addr
)
676 char addr_for_crc
[ETH_ALEN
] = { 0, };
679 for (i
= 0; i
< ETH_ALEN
* 8; i
++) {
680 bit
= (addr
[i
/ 8] >> (i
% 8)) & 1;
681 addr_for_crc
[ETH_ALEN
- 1 - i
/ 8] += bit
<< (7 - (i
% 8));
684 crc
= crc32_be(~0, addr_for_crc
, netdev
->addr_len
);
695 * spider_net_set_multi - sets multicast addresses and promisc flags
696 * @netdev: interface device structure
698 * spider_net_set_multi configures multicast addresses as needed for the
699 * netdev interface. It also sets up multicast, allmulti and promisc
700 * flags appropriately
703 spider_net_set_multi(struct net_device
*netdev
)
705 struct dev_mc_list
*mc
;
709 struct spider_net_card
*card
= netdev_priv(netdev
);
710 unsigned long bitmask
[SPIDER_NET_MULTICAST_HASHES
/ BITS_PER_LONG
] =
713 spider_net_set_promisc(card
);
715 if (netdev
->flags
& IFF_ALLMULTI
) {
716 for (i
= 0; i
< SPIDER_NET_MULTICAST_HASHES
; i
++) {
722 /* well, we know, what the broadcast hash value is: it's xfd
723 hash = spider_net_get_multicast_hash(netdev, netdev->broadcast); */
724 set_bit(0xfd, bitmask
);
726 for (mc
= netdev
->mc_list
; mc
; mc
= mc
->next
) {
727 hash
= spider_net_get_multicast_hash(netdev
, mc
->dmi_addr
);
728 set_bit(hash
, bitmask
);
732 for (i
= 0; i
< SPIDER_NET_MULTICAST_HASHES
/ 4; i
++) {
734 if (test_bit(i
* 4, bitmask
))
737 if (test_bit(i
* 4 + 1, bitmask
))
740 if (test_bit(i
* 4 + 2, bitmask
))
743 if (test_bit(i
* 4 + 3, bitmask
))
746 spider_net_write_reg(card
, SPIDER_NET_GMRMHFILnR
+ i
* 4, reg
);
751 * spider_net_disable_rxdmac - disables the receive DMA controller
752 * @card: card structure
754 * spider_net_disable_rxdmac terminates processing on the DMA controller by
755 * turing off DMA and issueing a force end
758 spider_net_disable_rxdmac(struct spider_net_card
*card
)
760 spider_net_write_reg(card
, SPIDER_NET_GDADMACCNTR
,
761 SPIDER_NET_DMA_RX_FEND_VALUE
);
765 * spider_net_stop - called upon ifconfig down
766 * @netdev: interface device structure
771 spider_net_stop(struct net_device
*netdev
)
773 struct spider_net_card
*card
= netdev_priv(netdev
);
775 tasklet_kill(&card
->rxram_full_tl
);
776 netif_poll_disable(netdev
);
777 netif_carrier_off(netdev
);
778 netif_stop_queue(netdev
);
779 del_timer_sync(&card
->tx_timer
);
781 /* disable/mask all interrupts */
782 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
, 0);
783 spider_net_write_reg(card
, SPIDER_NET_GHIINT1MSK
, 0);
784 spider_net_write_reg(card
, SPIDER_NET_GHIINT2MSK
, 0);
786 /* free_irq(netdev->irq, netdev);*/
787 free_irq(to_pci_dev(netdev
->class_dev
.dev
)->irq
, netdev
);
789 spider_net_write_reg(card
, SPIDER_NET_GDTDMACCNTR
,
790 SPIDER_NET_DMA_TX_FEND_VALUE
);
792 /* turn off DMA, force end */
793 spider_net_disable_rxdmac(card
);
796 spider_net_release_tx_chain(card
, 1);
798 spider_net_free_chain(card
, &card
->tx_chain
);
799 spider_net_free_chain(card
, &card
->rx_chain
);
805 * spider_net_get_next_tx_descr - returns the next available tx descriptor
806 * @card: device structure to get descriptor from
808 * returns the address of the next descriptor, or NULL if not available.
810 static struct spider_net_descr
*
811 spider_net_get_next_tx_descr(struct spider_net_card
*card
)
813 /* check, if head points to not-in-use descr */
814 if ( spider_net_get_descr_status(card
->tx_chain
.head
) ==
815 SPIDER_NET_DESCR_NOT_IN_USE
) {
816 return card
->tx_chain
.head
;
823 * spider_net_set_txdescr_cmdstat - sets the tx descriptor command field
824 * @descr: descriptor structure to fill out
825 * @skb: packet to consider
827 * fills out the command and status field of the descriptor structure,
828 * depending on hardware checksum settings.
831 spider_net_set_txdescr_cmdstat(struct spider_net_descr
*descr
,
834 /* make sure the other fields in the descriptor are written */
837 if (skb
->ip_summed
!= CHECKSUM_HW
) {
838 descr
->dmac_cmd_status
= SPIDER_NET_DMAC_CMDSTAT_NOCS
;
843 * if yes: tcp? udp? */
844 if (skb
->protocol
== htons(ETH_P_IP
)) {
845 if (skb
->nh
.iph
->protocol
== IPPROTO_TCP
)
846 descr
->dmac_cmd_status
= SPIDER_NET_DMAC_CMDSTAT_TCPCS
;
847 else if (skb
->nh
.iph
->protocol
== IPPROTO_UDP
)
848 descr
->dmac_cmd_status
= SPIDER_NET_DMAC_CMDSTAT_UDPCS
;
849 else /* the stack should checksum non-tcp and non-udp
850 packets on his own: NETIF_F_IP_CSUM */
851 descr
->dmac_cmd_status
= SPIDER_NET_DMAC_CMDSTAT_NOCS
;
856 * spider_net_prepare_tx_descr - fill tx descriptor with skb data
857 * @card: card structure
858 * @descr: descriptor structure to fill out
859 * @skb: packet to use
861 * returns 0 on success, <0 on failure.
863 * fills out the descriptor structure with skb data and len. Copies data,
864 * if needed (32bit DMA!)
867 spider_net_prepare_tx_descr(struct spider_net_card
*card
,
868 struct spider_net_descr
*descr
,
873 buf
= pci_map_single(card
->pdev
, skb
->data
,
874 skb
->len
, PCI_DMA_BIDIRECTIONAL
);
875 if (buf
== DMA_ERROR_CODE
) {
876 if (netif_msg_tx_err(card
) && net_ratelimit())
877 pr_err("could not iommu-map packet (%p, %i). "
878 "Dropping packet\n", skb
->data
, skb
->len
);
882 descr
->buf_addr
= buf
;
883 descr
->buf_size
= skb
->len
;
885 descr
->data_status
= 0;
887 spider_net_set_txdescr_cmdstat(descr
,skb
);
893 * spider_net_kick_tx_dma - enables TX DMA processing
894 * @card: card structure
895 * @descr: descriptor address to enable TX processing at
897 * spider_net_kick_tx_dma writes the current tx chain head as start address
898 * of the tx descriptor chain and enables the transmission DMA engine
901 spider_net_kick_tx_dma(struct spider_net_card
*card
,
902 struct spider_net_descr
*descr
)
904 /* this is the only descriptor in the output chain.
907 spider_net_write_reg(card
, SPIDER_NET_GDTDCHA
,
910 spider_net_write_reg(card
, SPIDER_NET_GDTDMACCNTR
,
911 SPIDER_NET_DMA_TX_VALUE
);
915 * spider_net_xmit - transmits a frame over the device
916 * @skb: packet to send out
917 * @netdev: interface device structure
919 * returns 0 on success, <0 on failure
922 spider_net_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
924 struct spider_net_card
*card
= netdev_priv(netdev
);
925 struct spider_net_descr
*descr
;
928 spider_net_release_tx_chain(card
, 0);
930 descr
= spider_net_get_next_tx_descr(card
);
935 result
= spider_net_prepare_tx_descr(card
, descr
, skb
);
939 card
->tx_chain
.head
= card
->tx_chain
.head
->next
;
941 if (spider_net_get_descr_status(descr
->prev
) !=
942 SPIDER_NET_DESCR_CARDOWNED
) {
943 /* make sure the current descriptor is in memory. Then
944 * kicking it on again makes sense, if the previous is not
945 * card-owned anymore. Check the previous descriptor twice
946 * to omit an mb() in heavy traffic cases */
948 if (spider_net_get_descr_status(descr
->prev
) !=
949 SPIDER_NET_DESCR_CARDOWNED
)
950 spider_net_kick_tx_dma(card
, descr
);
953 mod_timer(&card
->tx_timer
, jiffies
+ SPIDER_NET_TX_TIMER
);
958 card
->netdev_stats
.tx_dropped
++;
959 return NETDEV_TX_BUSY
;
963 * spider_net_do_ioctl - called for device ioctls
964 * @netdev: interface device structure
965 * @ifr: request parameter structure for ioctl
966 * @cmd: command code for ioctl
968 * returns 0 on success, <0 on failure. Currently, we have no special ioctls.
969 * -EOPNOTSUPP is returned, if an unknown ioctl was requested
972 spider_net_do_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
981 * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on
982 * @descr: descriptor to process
983 * @card: card structure
984 * @napi: whether caller is in NAPI context
986 * returns 1 on success, 0 if no packet was passed to the stack
988 * iommu-unmaps the skb, fills out skb structure and passes the data to the
989 * stack. The descriptor state is not changed.
992 spider_net_pass_skb_up(struct spider_net_descr
*descr
,
993 struct spider_net_card
*card
, int napi
)
996 struct net_device
*netdev
;
997 u32 data_status
, data_error
;
999 data_status
= descr
->data_status
;
1000 data_error
= descr
->data_error
;
1002 netdev
= card
->netdev
;
1004 /* unmap descriptor */
1005 pci_unmap_single(card
->pdev
, descr
->buf_addr
, SPIDER_NET_MAX_FRAME
,
1006 PCI_DMA_BIDIRECTIONAL
);
1008 /* the cases we'll throw away the packet immediately */
1009 if (data_error
& SPIDER_NET_DESTROY_RX_FLAGS
) {
1010 if (netif_msg_rx_err(card
))
1011 pr_err("error in received descriptor found, "
1012 "data_status=x%08x, data_error=x%08x\n",
1013 data_status
, data_error
);
1019 skb_put(skb
, descr
->valid_size
);
1021 /* the card seems to add 2 bytes of junk in front
1022 * of the ethernet frame */
1023 #define SPIDER_MISALIGN 2
1024 skb_pull(skb
, SPIDER_MISALIGN
);
1025 skb
->protocol
= eth_type_trans(skb
, netdev
);
1027 /* checksum offload */
1028 if (card
->options
.rx_csum
) {
1029 if ( ( (data_status
& SPIDER_NET_DATA_STATUS_CKSUM_MASK
) ==
1030 SPIDER_NET_DATA_STATUS_CKSUM_MASK
) &&
1031 !(data_error
& SPIDER_NET_DATA_ERR_CKSUM_MASK
))
1032 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1034 skb
->ip_summed
= CHECKSUM_NONE
;
1036 skb
->ip_summed
= CHECKSUM_NONE
;
1038 if (data_status
& SPIDER_NET_VLAN_PACKET
) {
1039 /* further enhancements: HW-accel VLAN
1040 * vlan_hwaccel_receive_skb
1044 /* pass skb up to stack */
1046 netif_receive_skb(skb
);
1050 /* update netdevice statistics */
1051 card
->netdev_stats
.rx_packets
++;
1052 card
->netdev_stats
.rx_bytes
+= skb
->len
;
1058 * spider_net_decode_one_descr - processes an rx descriptor
1059 * @card: card structure
1060 * @napi: whether caller is in NAPI context
1062 * returns 1 if a packet has been sent to the stack, otherwise 0
1064 * processes an rx descriptor by iommu-unmapping the data buffer and passing
1065 * the packet up to the stack. This function is called in softirq
1066 * context, e.g. either bottom half from interrupt or NAPI polling context
1069 spider_net_decode_one_descr(struct spider_net_card
*card
, int napi
)
1071 enum spider_net_descr_status status
;
1072 struct spider_net_descr
*descr
;
1073 struct spider_net_descr_chain
*chain
;
1076 chain
= &card
->rx_chain
;
1077 descr
= chain
->tail
;
1079 status
= spider_net_get_descr_status(descr
);
1081 if (status
== SPIDER_NET_DESCR_CARDOWNED
) {
1082 /* nothing in the descriptor yet */
1087 if (status
== SPIDER_NET_DESCR_NOT_IN_USE
) {
1088 /* not initialized yet, the ring must be empty */
1089 spider_net_refill_rx_chain(card
);
1090 spider_net_enable_rxdmac(card
);
1095 /* descriptor definitively used -- move on tail */
1096 chain
->tail
= descr
->next
;
1099 if ( (status
== SPIDER_NET_DESCR_RESPONSE_ERROR
) ||
1100 (status
== SPIDER_NET_DESCR_PROTECTION_ERROR
) ||
1101 (status
== SPIDER_NET_DESCR_FORCE_END
) ) {
1102 if (netif_msg_rx_err(card
))
1103 pr_err("%s: dropping RX descriptor with state %d\n",
1104 card
->netdev
->name
, status
);
1105 card
->netdev_stats
.rx_dropped
++;
1106 pci_unmap_single(card
->pdev
, descr
->buf_addr
,
1107 SPIDER_NET_MAX_FRAME
, PCI_DMA_BIDIRECTIONAL
);
1108 dev_kfree_skb_irq(descr
->skb
);
1112 if ( (status
!= SPIDER_NET_DESCR_COMPLETE
) &&
1113 (status
!= SPIDER_NET_DESCR_FRAME_END
) ) {
1114 if (netif_msg_rx_err(card
))
1115 pr_err("%s: RX descriptor with state %d\n",
1116 card
->netdev
->name
, status
);
1120 /* ok, we've got a packet in descr */
1121 result
= spider_net_pass_skb_up(descr
, card
, napi
);
1123 spider_net_set_descr_status(descr
, SPIDER_NET_DESCR_NOT_IN_USE
);
1124 /* change the descriptor state: */
1126 spider_net_refill_rx_chain(card
);
1132 * spider_net_poll - NAPI poll function called by the stack to return packets
1133 * @netdev: interface device structure
1134 * @budget: number of packets we can pass to the stack at most
1136 * returns 0 if no more packets available to the driver/stack. Returns 1,
1137 * if the quota is exceeded, but the driver has still packets.
1139 * spider_net_poll returns all packets from the rx descriptors to the stack
1140 * (using netif_receive_skb). If all/enough packets are up, the driver
1141 * reenables interrupts and returns 0. If not, 1 is returned.
1144 spider_net_poll(struct net_device
*netdev
, int *budget
)
1146 struct spider_net_card
*card
= netdev_priv(netdev
);
1147 int packets_to_do
, packets_done
= 0;
1148 int no_more_packets
= 0;
1150 packets_to_do
= min(*budget
, netdev
->quota
);
1152 while (packets_to_do
) {
1153 if (spider_net_decode_one_descr(card
, 1)) {
1157 /* no more packets for the stack */
1158 no_more_packets
= 1;
1163 netdev
->quota
-= packets_done
;
1164 *budget
-= packets_done
;
1165 spider_net_refill_rx_chain(card
);
1167 /* if all packets are in the stack, enable interrupts and return 0 */
1168 /* if not, return 1 */
1169 if (no_more_packets
) {
1170 netif_rx_complete(netdev
);
1171 spider_net_rx_irq_on(card
);
1179 * spider_net_vlan_rx_reg - initializes VLAN structures in the driver and card
1180 * @netdev: interface device structure
1181 * @grp: vlan_group structure that is registered (NULL on destroying interface)
1184 spider_net_vlan_rx_reg(struct net_device
*netdev
, struct vlan_group
*grp
)
1186 /* further enhancement... yet to do */
1191 * spider_net_vlan_rx_add - adds VLAN id to the card filter
1192 * @netdev: interface device structure
1193 * @vid: VLAN id to add
1196 spider_net_vlan_rx_add(struct net_device
*netdev
, uint16_t vid
)
1198 /* further enhancement... yet to do */
1199 /* add vid to card's VLAN filter table */
1204 * spider_net_vlan_rx_kill - removes VLAN id to the card filter
1205 * @netdev: interface device structure
1206 * @vid: VLAN id to remove
1209 spider_net_vlan_rx_kill(struct net_device
*netdev
, uint16_t vid
)
1211 /* further enhancement... yet to do */
1212 /* remove vid from card's VLAN filter table */
1216 * spider_net_get_stats - get interface statistics
1217 * @netdev: interface device structure
1219 * returns the interface statistics residing in the spider_net_card struct
1221 static struct net_device_stats
*
1222 spider_net_get_stats(struct net_device
*netdev
)
1224 struct spider_net_card
*card
= netdev_priv(netdev
);
1225 struct net_device_stats
*stats
= &card
->netdev_stats
;
1230 * spider_net_change_mtu - changes the MTU of an interface
1231 * @netdev: interface device structure
1232 * @new_mtu: new MTU value
1234 * returns 0 on success, <0 on failure
1237 spider_net_change_mtu(struct net_device
*netdev
, int new_mtu
)
1239 /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
1240 * and mtu is outbound only anyway */
1241 if ( (new_mtu
< SPIDER_NET_MIN_MTU
) ||
1242 (new_mtu
> SPIDER_NET_MAX_MTU
) )
1244 netdev
->mtu
= new_mtu
;
1249 * spider_net_set_mac - sets the MAC of an interface
1250 * @netdev: interface device structure
1251 * @ptr: pointer to new MAC address
1253 * Returns 0 on success, <0 on failure. Currently, we don't support this
1254 * and will always return EOPNOTSUPP.
1257 spider_net_set_mac(struct net_device
*netdev
, void *p
)
1259 struct spider_net_card
*card
= netdev_priv(netdev
);
1260 u32 macl
, macu
, regvalue
;
1261 struct sockaddr
*addr
= p
;
1263 if (!is_valid_ether_addr(addr
->sa_data
))
1264 return -EADDRNOTAVAIL
;
1266 /* switch off GMACTPE and GMACRPE */
1267 regvalue
= spider_net_read_reg(card
, SPIDER_NET_GMACOPEMD
);
1268 regvalue
&= ~((1 << 5) | (1 << 6));
1269 spider_net_write_reg(card
, SPIDER_NET_GMACOPEMD
, regvalue
);
1272 macu
= (addr
->sa_data
[0]<<24) + (addr
->sa_data
[1]<<16) +
1273 (addr
->sa_data
[2]<<8) + (addr
->sa_data
[3]);
1274 macl
= (addr
->sa_data
[4]<<8) + (addr
->sa_data
[5]);
1275 spider_net_write_reg(card
, SPIDER_NET_GMACUNIMACU
, macu
);
1276 spider_net_write_reg(card
, SPIDER_NET_GMACUNIMACL
, macl
);
1278 /* switch GMACTPE and GMACRPE back on */
1279 regvalue
= spider_net_read_reg(card
, SPIDER_NET_GMACOPEMD
);
1280 regvalue
|= ((1 << 5) | (1 << 6));
1281 spider_net_write_reg(card
, SPIDER_NET_GMACOPEMD
, regvalue
);
1283 spider_net_set_promisc(card
);
1285 /* look up, whether we have been successful */
1286 if (spider_net_get_mac_address(netdev
))
1287 return -EADDRNOTAVAIL
;
1288 if (memcmp(netdev
->dev_addr
,addr
->sa_data
,netdev
->addr_len
))
1289 return -EADDRNOTAVAIL
;
1295 * spider_net_enable_txdmac - enables a TX DMA controller
1296 * @card: card structure
1298 * spider_net_enable_txdmac enables the TX DMA controller by setting the
1299 * descriptor chain tail address
1302 spider_net_enable_txdmac(struct spider_net_card
*card
)
1304 /* assume chain is aligned correctly */
1305 spider_net_write_reg(card
, SPIDER_NET_GDTDCHA
,
1306 card
->tx_chain
.tail
->bus_addr
);
1310 * spider_net_handle_rxram_full - cleans up RX ring upon RX RAM full interrupt
1311 * @card: card structure
1313 * spider_net_handle_rxram_full empties the RX ring so that spider can put
1314 * more packets in it and empty its RX RAM. This is called in bottom half
1318 spider_net_handle_rxram_full(struct spider_net_card
*card
)
1320 while (spider_net_decode_one_descr(card
, 0))
1322 spider_net_enable_rxchtails(card
);
1323 spider_net_enable_rxdmac(card
);
1324 netif_rx_schedule(card
->netdev
);
1328 * spider_net_handle_error_irq - handles errors raised by an interrupt
1329 * @card: card structure
1330 * @status_reg: interrupt status register 0 (GHIINT0STS)
1332 * spider_net_handle_error_irq treats or ignores all error conditions
1333 * found when an interrupt is presented
1336 spider_net_handle_error_irq(struct spider_net_card
*card
, u32 status_reg
)
1338 u32 error_reg1
, error_reg2
;
1342 error_reg1
= spider_net_read_reg(card
, SPIDER_NET_GHIINT1STS
);
1343 error_reg2
= spider_net_read_reg(card
, SPIDER_NET_GHIINT2STS
);
1345 /* check GHIINT0STS ************************************/
1347 for (i
= 0; i
< 32; i
++)
1348 if (status_reg
& (1<<i
))
1351 /* let error_reg1 and error_reg2 evaluation decide, what to do
1352 case SPIDER_NET_PHYINT:
1353 case SPIDER_NET_GMAC2INT:
1354 case SPIDER_NET_GMAC1INT:
1355 case SPIDER_NET_GIPSINT:
1356 case SPIDER_NET_GFIFOINT:
1357 case SPIDER_NET_DMACINT:
1358 case SPIDER_NET_GSYSINT:
1361 case SPIDER_NET_GPWOPCMPINT
:
1362 /* PHY write operation completed */
1365 case SPIDER_NET_GPROPCMPINT
:
1366 /* PHY read operation completed */
1367 /* we don't use semaphores, as we poll for the completion
1368 * of the read operation in spider_net_read_phy. Should take
1372 case SPIDER_NET_GPWFFINT
:
1373 /* PHY command queue full */
1374 if (netif_msg_intr(card
))
1375 pr_err("PHY write queue full\n");
1379 /* case SPIDER_NET_GRMDADRINT: not used. print a message */
1380 /* case SPIDER_NET_GRMARPINT: not used. print a message */
1381 /* case SPIDER_NET_GRMMPINT: not used. print a message */
1383 case SPIDER_NET_GDTDEN0INT
:
1384 /* someone has set TX_DMA_EN to 0 */
1388 case SPIDER_NET_GDDDEN0INT
: /* fallthrough */
1389 case SPIDER_NET_GDCDEN0INT
: /* fallthrough */
1390 case SPIDER_NET_GDBDEN0INT
: /* fallthrough */
1391 case SPIDER_NET_GDADEN0INT
:
1392 /* someone has set RX_DMA_EN to 0 */
1397 case SPIDER_NET_GDDFDCINT
:
1398 case SPIDER_NET_GDCFDCINT
:
1399 case SPIDER_NET_GDBFDCINT
:
1400 case SPIDER_NET_GDAFDCINT
:
1401 /* case SPIDER_NET_GDNMINT: not used. print a message */
1402 /* case SPIDER_NET_GCNMINT: not used. print a message */
1403 /* case SPIDER_NET_GBNMINT: not used. print a message */
1404 /* case SPIDER_NET_GANMINT: not used. print a message */
1405 /* case SPIDER_NET_GRFNMINT: not used. print a message */
1410 case SPIDER_NET_GDTFDCINT
:
1413 case SPIDER_NET_GTTEDINT
:
1416 case SPIDER_NET_GDTDCEINT
:
1417 /* chain end. If a descriptor should be sent, kick off
1419 if (card->tx_chain.tail == card->tx_chain.head)
1420 spider_net_kick_tx_dma(card);
1424 /* case SPIDER_NET_G1TMCNTINT: not used. print a message */
1425 /* case SPIDER_NET_GFREECNTINT: not used. print a message */
1428 /* check GHIINT1STS ************************************/
1430 for (i
= 0; i
< 32; i
++)
1431 if (error_reg1
& (1<<i
))
1434 case SPIDER_NET_GTMFLLINT
:
1435 if (netif_msg_intr(card
) && net_ratelimit())
1436 pr_err("Spider TX RAM full\n");
1439 case SPIDER_NET_GRFDFLLINT
: /* fallthrough */
1440 case SPIDER_NET_GRFCFLLINT
: /* fallthrough */
1441 case SPIDER_NET_GRFBFLLINT
: /* fallthrough */
1442 case SPIDER_NET_GRFAFLLINT
: /* fallthrough */
1443 case SPIDER_NET_GRMFLLINT
:
1444 if (netif_msg_intr(card
) && net_ratelimit())
1445 pr_err("Spider RX RAM full, incoming packets "
1446 "might be discarded!\n");
1447 spider_net_rx_irq_off(card
);
1448 tasklet_schedule(&card
->rxram_full_tl
);
1452 /* case SPIDER_NET_GTMSHTINT: problem, print a message */
1453 case SPIDER_NET_GDTINVDINT
:
1454 /* allrighty. tx from previous descr ok */
1459 case SPIDER_NET_GDDDCEINT
: /* fallthrough */
1460 case SPIDER_NET_GDCDCEINT
: /* fallthrough */
1461 case SPIDER_NET_GDBDCEINT
: /* fallthrough */
1462 case SPIDER_NET_GDADCEINT
:
1463 if (netif_msg_intr(card
))
1464 pr_err("got descriptor chain end interrupt, "
1465 "restarting DMAC %c.\n",
1466 'D'+i
-SPIDER_NET_GDDDCEINT
);
1467 spider_net_refill_rx_chain(card
);
1468 spider_net_enable_rxdmac(card
);
1472 /* invalid descriptor */
1473 case SPIDER_NET_GDDINVDINT
: /* fallthrough */
1474 case SPIDER_NET_GDCINVDINT
: /* fallthrough */
1475 case SPIDER_NET_GDBINVDINT
: /* fallthrough */
1476 case SPIDER_NET_GDAINVDINT
:
1477 /* could happen when rx chain is full */
1478 spider_net_refill_rx_chain(card
);
1479 spider_net_enable_rxdmac(card
);
1483 /* case SPIDER_NET_GDTRSERINT: problem, print a message */
1484 /* case SPIDER_NET_GDDRSERINT: problem, print a message */
1485 /* case SPIDER_NET_GDCRSERINT: problem, print a message */
1486 /* case SPIDER_NET_GDBRSERINT: problem, print a message */
1487 /* case SPIDER_NET_GDARSERINT: problem, print a message */
1488 /* case SPIDER_NET_GDSERINT: problem, print a message */
1489 /* case SPIDER_NET_GDTPTERINT: problem, print a message */
1490 /* case SPIDER_NET_GDDPTERINT: problem, print a message */
1491 /* case SPIDER_NET_GDCPTERINT: problem, print a message */
1492 /* case SPIDER_NET_GDBPTERINT: problem, print a message */
1493 /* case SPIDER_NET_GDAPTERINT: problem, print a message */
1499 /* check GHIINT2STS ************************************/
1501 for (i
= 0; i
< 32; i
++)
1502 if (error_reg2
& (1<<i
))
1505 /* there is nothing we can (want to) do at this time. Log a
1506 * message, we can switch on and off the specific values later on
1507 case SPIDER_NET_GPROPERINT:
1508 case SPIDER_NET_GMCTCRSNGINT:
1509 case SPIDER_NET_GMCTLCOLINT:
1510 case SPIDER_NET_GMCTTMOTINT:
1511 case SPIDER_NET_GMCRCAERINT:
1512 case SPIDER_NET_GMCRCALERINT:
1513 case SPIDER_NET_GMCRALNERINT:
1514 case SPIDER_NET_GMCROVRINT:
1515 case SPIDER_NET_GMCRRNTINT:
1516 case SPIDER_NET_GMCRRXERINT:
1517 case SPIDER_NET_GTITCSERINT:
1518 case SPIDER_NET_GTIFMTERINT:
1519 case SPIDER_NET_GTIPKTRVKINT:
1520 case SPIDER_NET_GTISPINGINT:
1521 case SPIDER_NET_GTISADNGINT:
1522 case SPIDER_NET_GTISPDNGINT:
1523 case SPIDER_NET_GRIFMTERINT:
1524 case SPIDER_NET_GRIPKTRVKINT:
1525 case SPIDER_NET_GRISPINGINT:
1526 case SPIDER_NET_GRISADNGINT:
1527 case SPIDER_NET_GRISPDNGINT:
1534 if ((show_error
) && (netif_msg_intr(card
)))
1535 pr_err("Got error interrupt, GHIINT0STS = 0x%08x, "
1536 "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n",
1537 status_reg
, error_reg1
, error_reg2
);
1539 /* clear interrupt sources */
1540 spider_net_write_reg(card
, SPIDER_NET_GHIINT1STS
, error_reg1
);
1541 spider_net_write_reg(card
, SPIDER_NET_GHIINT2STS
, error_reg2
);
1545 * spider_net_interrupt - interrupt handler for spider_net
1546 * @irq: interupt number
1547 * @ptr: pointer to net_device
1548 * @regs: PU registers
1550 * returns IRQ_HANDLED, if interrupt was for driver, or IRQ_NONE, if no
1551 * interrupt found raised by card.
1553 * This is the interrupt handler, that turns off
1554 * interrupts for this device and makes the stack poll the driver
1557 spider_net_interrupt(int irq
, void *ptr
, struct pt_regs
*regs
)
1559 struct net_device
*netdev
= ptr
;
1560 struct spider_net_card
*card
= netdev_priv(netdev
);
1563 status_reg
= spider_net_read_reg(card
, SPIDER_NET_GHIINT0STS
);
1568 if (status_reg
& SPIDER_NET_RXINT
) {
1569 spider_net_rx_irq_off(card
);
1570 netif_rx_schedule(netdev
);
1573 if (status_reg
& SPIDER_NET_ERRINT
)
1574 spider_net_handle_error_irq(card
, status_reg
);
1576 /* clear interrupt sources */
1577 spider_net_write_reg(card
, SPIDER_NET_GHIINT0STS
, status_reg
);
1582 #ifdef CONFIG_NET_POLL_CONTROLLER
1584 * spider_net_poll_controller - artificial interrupt for netconsole etc.
1585 * @netdev: interface device structure
1587 * see Documentation/networking/netconsole.txt
1590 spider_net_poll_controller(struct net_device
*netdev
)
1592 disable_irq(netdev
->irq
);
1593 spider_net_interrupt(netdev
->irq
, netdev
, NULL
);
1594 enable_irq(netdev
->irq
);
1596 #endif /* CONFIG_NET_POLL_CONTROLLER */
1599 * spider_net_init_card - initializes the card
1600 * @card: card structure
1602 * spider_net_init_card initializes the card so that other registers can
1606 spider_net_init_card(struct spider_net_card
*card
)
1608 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1609 SPIDER_NET_CKRCTRL_STOP_VALUE
);
1611 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1612 SPIDER_NET_CKRCTRL_RUN_VALUE
);
1616 * spider_net_enable_card - enables the card by setting all kinds of regs
1617 * @card: card structure
1619 * spider_net_enable_card sets a lot of SMMIO registers to enable the device
1622 spider_net_enable_card(struct spider_net_card
*card
)
1625 /* the following array consists of (register),(value) pairs
1626 * that are set in this function. A register of 0 ends the list */
1628 { SPIDER_NET_GRESUMINTNUM
, 0 },
1629 { SPIDER_NET_GREINTNUM
, 0 },
1631 /* set interrupt frame number registers */
1632 /* clear the single DMA engine registers first */
1633 { SPIDER_NET_GFAFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1634 { SPIDER_NET_GFBFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1635 { SPIDER_NET_GFCFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1636 { SPIDER_NET_GFDFRMNUM
, SPIDER_NET_GFXFRAMES_VALUE
},
1637 /* then set, what we really need */
1638 { SPIDER_NET_GFFRMNUM
, SPIDER_NET_FRAMENUM_VALUE
},
1640 /* timer counter registers and stuff */
1641 { SPIDER_NET_GFREECNNUM
, 0 },
1642 { SPIDER_NET_GONETIMENUM
, 0 },
1643 { SPIDER_NET_GTOUTFRMNUM
, 0 },
1645 /* RX mode setting */
1646 { SPIDER_NET_GRXMDSET
, SPIDER_NET_RXMODE_VALUE
},
1647 /* TX mode setting */
1648 { SPIDER_NET_GTXMDSET
, SPIDER_NET_TXMODE_VALUE
},
1649 /* IPSEC mode setting */
1650 { SPIDER_NET_GIPSECINIT
, SPIDER_NET_IPSECINIT_VALUE
},
1652 { SPIDER_NET_GFTRESTRT
, SPIDER_NET_RESTART_VALUE
},
1654 { SPIDER_NET_GMRWOLCTRL
, 0 },
1655 { SPIDER_NET_GTESTMD
, 0 },
1657 { SPIDER_NET_GMACINTEN
, 0 },
1659 /* flow control stuff */
1660 { SPIDER_NET_GMACAPAUSE
, SPIDER_NET_MACAPAUSE_VALUE
},
1661 { SPIDER_NET_GMACTXPAUSE
, SPIDER_NET_TXPAUSE_VALUE
},
1663 { SPIDER_NET_GMACBSTLMT
, SPIDER_NET_BURSTLMT_VALUE
},
1668 while (regs
[i
][0]) {
1669 spider_net_write_reg(card
, regs
[i
][0], regs
[i
][1]);
1673 /* clear unicast filter table entries 1 to 14 */
1674 for (i
= 1; i
<= 14; i
++) {
1675 spider_net_write_reg(card
,
1676 SPIDER_NET_GMRUAFILnR
+ i
* 8,
1678 spider_net_write_reg(card
,
1679 SPIDER_NET_GMRUAFILnR
+ i
* 8 + 4,
1683 spider_net_write_reg(card
, SPIDER_NET_GMRUA0FIL15R
, 0x08080000);
1685 spider_net_write_reg(card
, SPIDER_NET_ECMODE
, SPIDER_NET_ECMODE_VALUE
);
1687 /* set chain tail adress for RX chains and
1689 spider_net_enable_rxchtails(card
);
1690 spider_net_enable_rxdmac(card
);
1692 spider_net_write_reg(card
, SPIDER_NET_GRXDMAEN
, SPIDER_NET_WOL_VALUE
);
1694 /* set chain tail adress for TX chain */
1695 spider_net_enable_txdmac(card
);
1697 spider_net_write_reg(card
, SPIDER_NET_GMACLENLMT
,
1698 SPIDER_NET_LENLMT_VALUE
);
1699 spider_net_write_reg(card
, SPIDER_NET_GMACMODE
,
1700 SPIDER_NET_MACMODE_VALUE
);
1701 spider_net_write_reg(card
, SPIDER_NET_GMACOPEMD
,
1702 SPIDER_NET_OPMODE_VALUE
);
1704 /* set interrupt mask registers */
1705 spider_net_write_reg(card
, SPIDER_NET_GHIINT0MSK
,
1706 SPIDER_NET_INT0_MASK_VALUE
);
1707 spider_net_write_reg(card
, SPIDER_NET_GHIINT1MSK
,
1708 SPIDER_NET_INT1_MASK_VALUE
);
1709 spider_net_write_reg(card
, SPIDER_NET_GHIINT2MSK
,
1710 SPIDER_NET_INT2_MASK_VALUE
);
1714 * spider_net_open - called upon ifonfig up
1715 * @netdev: interface device structure
1717 * returns 0 on success, <0 on failure
1719 * spider_net_open allocates all the descriptors and memory needed for
1720 * operation, sets up multicast list and enables interrupts
1723 spider_net_open(struct net_device
*netdev
)
1725 struct spider_net_card
*card
= netdev_priv(netdev
);
1729 if (spider_net_init_chain(card
, &card
->tx_chain
,
1730 card
->descr
, tx_descriptors
))
1731 goto alloc_tx_failed
;
1732 if (spider_net_init_chain(card
, &card
->rx_chain
,
1733 card
->descr
+ tx_descriptors
, rx_descriptors
))
1734 goto alloc_rx_failed
;
1736 /* allocate rx skbs */
1737 if (spider_net_alloc_rx_skbs(card
))
1738 goto alloc_skbs_failed
;
1740 spider_net_set_multi(netdev
);
1742 /* further enhancement: setup hw vlan, if needed */
1745 if (request_irq(netdev
->irq
, spider_net_interrupt
,
1746 SA_SHIRQ
, netdev
->name
, netdev
))
1747 goto register_int_failed
;
1749 spider_net_enable_card(card
);
1751 netif_start_queue(netdev
);
1752 netif_carrier_on(netdev
);
1753 netif_poll_enable(netdev
);
1757 register_int_failed
:
1758 spider_net_free_rx_chain_contents(card
);
1760 spider_net_free_chain(card
, &card
->rx_chain
);
1762 spider_net_free_chain(card
, &card
->tx_chain
);
1768 * spider_net_setup_phy - setup PHY
1769 * @card: card structure
1771 * returns 0 on success, <0 on failure
1773 * spider_net_setup_phy is used as part of spider_net_probe. Sets
1774 * the PHY to 1000 Mbps
1777 spider_net_setup_phy(struct spider_net_card
*card
)
1779 struct mii_phy
*phy
= &card
->phy
;
1781 spider_net_write_reg(card
, SPIDER_NET_GDTDMASEL
,
1782 SPIDER_NET_DMASEL_VALUE
);
1783 spider_net_write_reg(card
, SPIDER_NET_GPCCTRL
,
1784 SPIDER_NET_PHY_CTRL_VALUE
);
1786 phy
->dev
= card
->netdev
;
1787 phy
->mdio_read
= spider_net_read_phy
;
1788 phy
->mdio_write
= spider_net_write_phy
;
1790 mii_phy_probe(phy
, phy
->mii_id
);
1792 if (phy
->def
->ops
->setup_forced
)
1793 phy
->def
->ops
->setup_forced(phy
, SPEED_1000
, DUPLEX_FULL
);
1795 /* the following two writes could be moved to sungem_phy.c */
1796 /* enable fiber mode */
1797 spider_net_write_phy(card
->netdev
, 1, MII_NCONFIG
, 0x9020);
1798 /* LEDs active in both modes, autosense prio = fiber */
1799 spider_net_write_phy(card
->netdev
, 1, MII_NCONFIG
, 0x945f);
1801 /* switch off fibre autoneg */
1802 spider_net_write_phy(card
->netdev
, 1, MII_NCONFIG
, 0xfc01);
1803 spider_net_write_phy(card
->netdev
, 1, 0x0b, 0x0004);
1805 phy
->def
->ops
->read_link(phy
);
1806 pr_info("Found %s with %i Mbps, %s-duplex.\n", phy
->def
->name
,
1807 phy
->speed
, phy
->duplex
==1 ? "Full" : "Half");
1813 * spider_net_download_firmware - loads firmware into the adapter
1814 * @card: card structure
1815 * @firmware_ptr: pointer to firmware data
1817 * spider_net_download_firmware loads the firmware data into the
1818 * adapter. It assumes the length etc. to be allright.
1821 spider_net_download_firmware(struct spider_net_card
*card
,
1825 u32
*fw_ptr
= (u32
*)firmware_ptr
;
1827 /* stop sequencers */
1828 spider_net_write_reg(card
, SPIDER_NET_GSINIT
,
1829 SPIDER_NET_STOP_SEQ_VALUE
);
1831 for (sequencer
= 0; sequencer
< SPIDER_NET_FIRMWARE_SEQS
;
1833 spider_net_write_reg(card
,
1834 SPIDER_NET_GSnPRGADR
+ sequencer
* 8, 0);
1835 for (i
= 0; i
< SPIDER_NET_FIRMWARE_SEQWORDS
; i
++) {
1836 spider_net_write_reg(card
, SPIDER_NET_GSnPRGDAT
+
1837 sequencer
* 8, *fw_ptr
);
1842 if (spider_net_read_reg(card
, SPIDER_NET_GSINIT
))
1845 spider_net_write_reg(card
, SPIDER_NET_GSINIT
,
1846 SPIDER_NET_RUN_SEQ_VALUE
);
1852 * spider_net_init_firmware - reads in firmware parts
1853 * @card: card structure
1855 * Returns 0 on success, <0 on failure
1857 * spider_net_init_firmware opens the sequencer firmware and does some basic
1858 * checks. This function opens and releases the firmware structure. A call
1859 * to download the firmware is performed before the release.
1863 * spider_fw.bin is expected to be a file containing 6*1024*4 bytes, 4k being
1864 * the program for each sequencer. Use the command
1865 * tail -q -n +2 Seq_code1_0x088.txt Seq_code2_0x090.txt \
1866 * Seq_code3_0x098.txt Seq_code4_0x0A0.txt Seq_code5_0x0A8.txt \
1867 * Seq_code6_0x0B0.txt | xxd -r -p -c4 > spider_fw.bin
1869 * to generate spider_fw.bin, if you have sequencer programs with something
1870 * like the following contents for each sequencer:
1871 * <ONE LINE COMMENT>
1872 * <FIRST 4-BYTES-WORD FOR SEQUENCER>
1873 * <SECOND 4-BYTES-WORD FOR SEQUENCER>
1875 * <1024th 4-BYTES-WORD FOR SEQUENCER>
1878 spider_net_init_firmware(struct spider_net_card
*card
)
1880 struct firmware
*firmware
= NULL
;
1881 struct device_node
*dn
;
1886 if (request_firmware((const struct firmware
**)&firmware
,
1887 SPIDER_NET_FIRMWARE_NAME
, &card
->pdev
->dev
) == 0) {
1888 if ( (firmware
->size
!= SPIDER_NET_FIRMWARE_LEN
) &&
1889 netif_msg_probe(card
) ) {
1890 pr_err("Incorrect size of spidernet firmware in " \
1891 "filesystem. Looking in host firmware...\n");
1894 err
= spider_net_download_firmware(card
, firmware
->data
);
1896 release_firmware(firmware
);
1904 dn
= pci_device_to_OF_node(card
->pdev
);
1908 fw_prop
= (u8
*)get_property(dn
, "firmware", &fw_size
);
1912 if ( (fw_size
!= SPIDER_NET_FIRMWARE_LEN
) &&
1913 netif_msg_probe(card
) ) {
1914 pr_err("Incorrect size of spidernet firmware in " \
1919 err
= spider_net_download_firmware(card
, fw_prop
);
1924 if (netif_msg_probe(card
))
1925 pr_err("Couldn't find spidernet firmware in filesystem " \
1926 "or host firmware\n");
1931 * spider_net_workaround_rxramfull - work around firmware bug
1932 * @card: card structure
1937 spider_net_workaround_rxramfull(struct spider_net_card
*card
)
1939 int i
, sequencer
= 0;
1942 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1943 SPIDER_NET_CKRCTRL_RUN_VALUE
);
1945 /* empty sequencer data */
1946 for (sequencer
= 0; sequencer
< SPIDER_NET_FIRMWARE_SEQS
;
1948 spider_net_write_reg(card
, SPIDER_NET_GSnPRGDAT
+
1949 sequencer
* 8, 0x0);
1950 for (i
= 0; i
< SPIDER_NET_FIRMWARE_SEQWORDS
; i
++) {
1951 spider_net_write_reg(card
, SPIDER_NET_GSnPRGDAT
+
1952 sequencer
* 8, 0x0);
1956 /* set sequencer operation */
1957 spider_net_write_reg(card
, SPIDER_NET_GSINIT
, 0x000000fe);
1960 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
1961 SPIDER_NET_CKRCTRL_STOP_VALUE
);
1965 * spider_net_tx_timeout_task - task scheduled by the watchdog timeout
1966 * function (to be called not under interrupt status)
1967 * @data: data, is interface device structure
1969 * called as task when tx hangs, resets interface (if interface is up)
1972 spider_net_tx_timeout_task(void *data
)
1974 struct net_device
*netdev
= data
;
1975 struct spider_net_card
*card
= netdev_priv(netdev
);
1977 if (!(netdev
->flags
& IFF_UP
))
1980 netif_device_detach(netdev
);
1981 spider_net_stop(netdev
);
1983 spider_net_workaround_rxramfull(card
);
1984 spider_net_init_card(card
);
1986 if (spider_net_setup_phy(card
))
1988 if (spider_net_init_firmware(card
))
1991 spider_net_open(netdev
);
1992 spider_net_kick_tx_dma(card
, card
->tx_chain
.head
);
1993 netif_device_attach(netdev
);
1996 atomic_dec(&card
->tx_timeout_task_counter
);
2000 * spider_net_tx_timeout - called when the tx timeout watchdog kicks in.
2001 * @netdev: interface device structure
2003 * called, if tx hangs. Schedules a task that resets the interface
2006 spider_net_tx_timeout(struct net_device
*netdev
)
2008 struct spider_net_card
*card
;
2010 card
= netdev_priv(netdev
);
2011 atomic_inc(&card
->tx_timeout_task_counter
);
2012 if (netdev
->flags
& IFF_UP
)
2013 schedule_work(&card
->tx_timeout_task
);
2015 atomic_dec(&card
->tx_timeout_task_counter
);
2019 * spider_net_setup_netdev_ops - initialization of net_device operations
2020 * @netdev: net_device structure
2022 * fills out function pointers in the net_device structure
2025 spider_net_setup_netdev_ops(struct net_device
*netdev
)
2027 netdev
->open
= &spider_net_open
;
2028 netdev
->stop
= &spider_net_stop
;
2029 netdev
->hard_start_xmit
= &spider_net_xmit
;
2030 netdev
->get_stats
= &spider_net_get_stats
;
2031 netdev
->set_multicast_list
= &spider_net_set_multi
;
2032 netdev
->set_mac_address
= &spider_net_set_mac
;
2033 netdev
->change_mtu
= &spider_net_change_mtu
;
2034 netdev
->do_ioctl
= &spider_net_do_ioctl
;
2036 netdev
->tx_timeout
= &spider_net_tx_timeout
;
2037 netdev
->watchdog_timeo
= SPIDER_NET_WATCHDOG_TIMEOUT
;
2039 netdev
->poll
= &spider_net_poll
;
2040 netdev
->weight
= SPIDER_NET_NAPI_WEIGHT
;
2042 netdev
->vlan_rx_register
= &spider_net_vlan_rx_reg
;
2043 netdev
->vlan_rx_add_vid
= &spider_net_vlan_rx_add
;
2044 netdev
->vlan_rx_kill_vid
= &spider_net_vlan_rx_kill
;
2045 #ifdef CONFIG_NET_POLL_CONTROLLER
2046 /* poll controller */
2047 netdev
->poll_controller
= &spider_net_poll_controller
;
2048 #endif /* CONFIG_NET_POLL_CONTROLLER */
2050 netdev
->ethtool_ops
= &spider_net_ethtool_ops
;
2054 * spider_net_setup_netdev - initialization of net_device
2055 * @card: card structure
2057 * Returns 0 on success or <0 on failure
2059 * spider_net_setup_netdev initializes the net_device structure
2062 spider_net_setup_netdev(struct spider_net_card
*card
)
2065 struct net_device
*netdev
= card
->netdev
;
2066 struct device_node
*dn
;
2067 struct sockaddr addr
;
2070 SET_MODULE_OWNER(netdev
);
2071 SET_NETDEV_DEV(netdev
, &card
->pdev
->dev
);
2073 pci_set_drvdata(card
->pdev
, netdev
);
2075 atomic_set(&card
->tx_chain_release
,0);
2076 card
->rxram_full_tl
.data
= (unsigned long) card
;
2077 card
->rxram_full_tl
.func
=
2078 (void (*)(unsigned long)) spider_net_handle_rxram_full
;
2079 init_timer(&card
->tx_timer
);
2080 card
->tx_timer
.function
=
2081 (void (*)(unsigned long)) spider_net_cleanup_tx_ring
;
2082 card
->tx_timer
.data
= (unsigned long) card
;
2083 netdev
->irq
= card
->pdev
->irq
;
2085 card
->options
.rx_csum
= SPIDER_NET_RX_CSUM_DEFAULT
;
2087 spider_net_setup_netdev_ops(netdev
);
2089 netdev
->features
= 0;
2090 /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
2091 * NETIF_F_HW_VLAN_FILTER */
2093 netdev
->irq
= card
->pdev
->irq
;
2095 dn
= pci_device_to_OF_node(card
->pdev
);
2099 mac
= (u8
*)get_property(dn
, "local-mac-address", NULL
);
2102 memcpy(addr
.sa_data
, mac
, ETH_ALEN
);
2104 result
= spider_net_set_mac(netdev
, &addr
);
2105 if ((result
) && (netif_msg_probe(card
)))
2106 pr_err("Failed to set MAC address: %i\n", result
);
2108 result
= register_netdev(netdev
);
2110 if (netif_msg_probe(card
))
2111 pr_err("Couldn't register net_device: %i\n",
2116 if (netif_msg_probe(card
))
2117 pr_info("Initialized device %s.\n", netdev
->name
);
2123 * spider_net_alloc_card - allocates net_device and card structure
2125 * returns the card structure or NULL in case of errors
2127 * the card and net_device structures are linked to each other
2129 static struct spider_net_card
*
2130 spider_net_alloc_card(void)
2132 struct net_device
*netdev
;
2133 struct spider_net_card
*card
;
2136 alloc_size
= sizeof (*card
) +
2137 sizeof (struct spider_net_descr
) * rx_descriptors
+
2138 sizeof (struct spider_net_descr
) * tx_descriptors
;
2139 netdev
= alloc_etherdev(alloc_size
);
2143 card
= netdev_priv(netdev
);
2144 card
->netdev
= netdev
;
2145 card
->msg_enable
= SPIDER_NET_DEFAULT_MSG
;
2146 INIT_WORK(&card
->tx_timeout_task
, spider_net_tx_timeout_task
, netdev
);
2147 init_waitqueue_head(&card
->waitq
);
2148 atomic_set(&card
->tx_timeout_task_counter
, 0);
2154 * spider_net_undo_pci_setup - releases PCI ressources
2155 * @card: card structure
2157 * spider_net_undo_pci_setup releases the mapped regions
2160 spider_net_undo_pci_setup(struct spider_net_card
*card
)
2162 iounmap(card
->regs
);
2163 pci_release_regions(card
->pdev
);
2167 * spider_net_setup_pci_dev - sets up the device in terms of PCI operations
2168 * @card: card structure
2171 * Returns the card structure or NULL if any errors occur
2173 * spider_net_setup_pci_dev initializes pdev and together with the
2174 * functions called in spider_net_open configures the device so that
2175 * data can be transferred over it
2176 * The net_device structure is attached to the card structure, if the
2177 * function returns without error.
2179 static struct spider_net_card
*
2180 spider_net_setup_pci_dev(struct pci_dev
*pdev
)
2182 struct spider_net_card
*card
;
2183 unsigned long mmio_start
, mmio_len
;
2185 if (pci_enable_device(pdev
)) {
2186 pr_err("Couldn't enable PCI device\n");
2190 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
2191 pr_err("Couldn't find proper PCI device base address.\n");
2192 goto out_disable_dev
;
2195 if (pci_request_regions(pdev
, spider_net_driver_name
)) {
2196 pr_err("Couldn't obtain PCI resources, aborting.\n");
2197 goto out_disable_dev
;
2200 pci_set_master(pdev
);
2202 card
= spider_net_alloc_card();
2204 pr_err("Couldn't allocate net_device structure, "
2206 goto out_release_regions
;
2210 /* fetch base address and length of first resource */
2211 mmio_start
= pci_resource_start(pdev
, 0);
2212 mmio_len
= pci_resource_len(pdev
, 0);
2214 card
->netdev
->mem_start
= mmio_start
;
2215 card
->netdev
->mem_end
= mmio_start
+ mmio_len
;
2216 card
->regs
= ioremap(mmio_start
, mmio_len
);
2219 pr_err("Couldn't obtain PCI resources, aborting.\n");
2220 goto out_release_regions
;
2225 out_release_regions
:
2226 pci_release_regions(pdev
);
2228 pci_disable_device(pdev
);
2229 pci_set_drvdata(pdev
, NULL
);
2234 * spider_net_probe - initialization of a device
2236 * @ent: entry in the device id list
2238 * Returns 0 on success, <0 on failure
2240 * spider_net_probe initializes pdev and registers a net_device
2241 * structure for it. After that, the device can be ifconfig'ed up
2243 static int __devinit
2244 spider_net_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2247 struct spider_net_card
*card
;
2249 card
= spider_net_setup_pci_dev(pdev
);
2253 spider_net_workaround_rxramfull(card
);
2254 spider_net_init_card(card
);
2256 err
= spider_net_setup_phy(card
);
2260 err
= spider_net_init_firmware(card
);
2264 err
= spider_net_setup_netdev(card
);
2271 spider_net_undo_pci_setup(card
);
2272 free_netdev(card
->netdev
);
2278 * spider_net_remove - removal of a device
2281 * Returns 0 on success, <0 on failure
2283 * spider_net_remove is called to remove the device and unregisters the
2286 static void __devexit
2287 spider_net_remove(struct pci_dev
*pdev
)
2289 struct net_device
*netdev
;
2290 struct spider_net_card
*card
;
2292 netdev
= pci_get_drvdata(pdev
);
2293 card
= netdev_priv(netdev
);
2295 wait_event(card
->waitq
,
2296 atomic_read(&card
->tx_timeout_task_counter
) == 0);
2298 unregister_netdev(netdev
);
2300 /* switch off card */
2301 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
2302 SPIDER_NET_CKRCTRL_STOP_VALUE
);
2303 spider_net_write_reg(card
, SPIDER_NET_CKRCTRL
,
2304 SPIDER_NET_CKRCTRL_RUN_VALUE
);
2306 spider_net_undo_pci_setup(card
);
2307 free_netdev(netdev
);
2310 static struct pci_driver spider_net_driver
= {
2311 .name
= spider_net_driver_name
,
2312 .id_table
= spider_net_pci_tbl
,
2313 .probe
= spider_net_probe
,
2314 .remove
= __devexit_p(spider_net_remove
)
2318 * spider_net_init - init function when the driver is loaded
2320 * spider_net_init registers the device driver
2322 static int __init
spider_net_init(void)
2324 if (rx_descriptors
< SPIDER_NET_RX_DESCRIPTORS_MIN
) {
2325 rx_descriptors
= SPIDER_NET_RX_DESCRIPTORS_MIN
;
2326 pr_info("adjusting rx descriptors to %i.\n", rx_descriptors
);
2328 if (rx_descriptors
> SPIDER_NET_RX_DESCRIPTORS_MAX
) {
2329 rx_descriptors
= SPIDER_NET_RX_DESCRIPTORS_MAX
;
2330 pr_info("adjusting rx descriptors to %i.\n", rx_descriptors
);
2332 if (tx_descriptors
< SPIDER_NET_TX_DESCRIPTORS_MIN
) {
2333 tx_descriptors
= SPIDER_NET_TX_DESCRIPTORS_MIN
;
2334 pr_info("adjusting tx descriptors to %i.\n", tx_descriptors
);
2336 if (tx_descriptors
> SPIDER_NET_TX_DESCRIPTORS_MAX
) {
2337 tx_descriptors
= SPIDER_NET_TX_DESCRIPTORS_MAX
;
2338 pr_info("adjusting tx descriptors to %i.\n", tx_descriptors
);
2341 return pci_register_driver(&spider_net_driver
);
2345 * spider_net_cleanup - exit function when driver is unloaded
2347 * spider_net_cleanup unregisters the device driver
2349 static void __exit
spider_net_cleanup(void)
2351 pci_unregister_driver(&spider_net_driver
);
2354 module_init(spider_net_init
);
2355 module_exit(spider_net_cleanup
);