2 /* Advanced Micro Devices Inc. AMD8111E Linux Network Driver
3 * Copyright (C) 2004 Advanced Micro Devices
6 * Copyright 2001,2002 Jeff Garzik <jgarzik@mandrakesoft.com> [ 8139cp.c,tg3.c ]
7 * Copyright (C) 2001, 2002 David S. Miller (davem@redhat.com)[ tg3.c]
8 * Copyright 1996-1999 Thomas Bogendoerfer [ pcnet32.c ]
9 * Derived from the lance driver written 1993,1994,1995 by Donald Becker.
10 * Copyright 1993 United States Government as represented by the
11 * Director, National Security Agency.[ pcnet32.c ]
12 * Carsten Langgaard, carstenl@mips.com [ pcnet32.c ]
13 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
37 AMD8111 based 10/100 Ethernet Controller Driver.
47 1. Dynamic interrupt coalescing.
48 2. Removed prev_stats.
50 4. Dynamic IPG support
52 1. Bug fix: Fixed failure to send jumbo packets larger than 4k.
53 2. Bug fix: Fixed VLAN support failure.
54 3. Bug fix: Fixed receive interrupt coalescing bug.
55 4. Dynamic IPG support is disabled by default.
57 1. Bug fix: Fixed failure to close the interface if SMP is enabled.
59 1. Added set_mac_address routine for bonding driver support.
60 2. Tested the driver for bonding support
61 3. Bug fix: Fixed mismach in actual receive buffer lenth and lenth
63 4. Modified amd8111e_rx() routine to receive all the received packets
64 in the first interrupt.
65 5. Bug fix: Corrected rx_errors reported in get_stats() function.
72 #include <linux/config.h>
73 #include <linux/module.h>
74 #include <linux/kernel.h>
75 #include <linux/types.h>
76 #include <linux/compiler.h>
77 #include <linux/slab.h>
78 #include <linux/delay.h>
79 #include <linux/init.h>
80 #include <linux/ioport.h>
81 #include <linux/pci.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/skbuff.h>
85 #include <linux/ethtool.h>
86 #include <linux/mii.h>
87 #include <linux/if_vlan.h>
88 #include <linux/ctype.h>
89 #include <linux/crc32.h>
90 #include <linux/dma-mapping.h>
92 #include <asm/system.h>
94 #include <asm/byteorder.h>
95 #include <asm/uaccess.h>
97 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
98 #define AMD8111E_VLAN_TAG_USED 1
100 #define AMD8111E_VLAN_TAG_USED 0
103 #include "amd8111e.h"
104 #define MODULE_NAME "amd8111e"
105 #define MODULE_VERS "3.0.5"
106 MODULE_AUTHOR("Advanced Micro Devices, Inc.");
107 MODULE_DESCRIPTION ("AMD8111 based 10/100 Ethernet Controller. Driver Version 3.0.3");
108 MODULE_LICENSE("GPL");
109 MODULE_DEVICE_TABLE(pci
, amd8111e_pci_tbl
);
110 module_param_array(speed_duplex
, int, NULL
, 0);
111 MODULE_PARM_DESC(speed_duplex
, "Set device speed and duplex modes, 0: Auto Negotitate, 1: 10Mbps Half Duplex, 2: 10Mbps Full Duplex, 3: 100Mbps Half Duplex, 4: 100Mbps Full Duplex");
112 module_param_array(coalesce
, bool, NULL
, 0);
113 MODULE_PARM_DESC(coalesce
, "Enable or Disable interrupt coalescing, 1: Enable, 0: Disable");
114 module_param_array(dynamic_ipg
, bool, NULL
, 0);
115 MODULE_PARM_DESC(dynamic_ipg
, "Enable or Disable dynamic IPG, 1: Enable, 0: Disable");
117 static struct pci_device_id amd8111e_pci_tbl
[] = {
119 { PCI_VENDOR_ID_AMD
, PCI_DEVICE_ID_AMD8111E_7462
,
120 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
125 This function will read the PHY registers.
127 static int amd8111e_read_phy(struct amd8111e_priv
* lp
, int phy_id
, int reg
, u32
* val
)
129 void __iomem
*mmio
= lp
->mmio
;
130 unsigned int reg_val
;
131 unsigned int repeat
= REPEAT_CNT
;
133 reg_val
= readl(mmio
+ PHY_ACCESS
);
134 while (reg_val
& PHY_CMD_ACTIVE
)
135 reg_val
= readl( mmio
+ PHY_ACCESS
);
137 writel( PHY_RD_CMD
| ((phy_id
& 0x1f) << 21) |
138 ((reg
& 0x1f) << 16), mmio
+PHY_ACCESS
);
140 reg_val
= readl(mmio
+ PHY_ACCESS
);
141 udelay(30); /* It takes 30 us to read/write data */
142 } while (--repeat
&& (reg_val
& PHY_CMD_ACTIVE
));
143 if(reg_val
& PHY_RD_ERR
)
146 *val
= reg_val
& 0xffff;
155 This function will write into PHY registers.
157 static int amd8111e_write_phy(struct amd8111e_priv
* lp
,int phy_id
, int reg
, u32 val
)
159 unsigned int repeat
= REPEAT_CNT
160 void __iomem
*mmio
= lp
->mmio
;
161 unsigned int reg_val
;
163 reg_val
= readl(mmio
+ PHY_ACCESS
);
164 while (reg_val
& PHY_CMD_ACTIVE
)
165 reg_val
= readl( mmio
+ PHY_ACCESS
);
167 writel( PHY_WR_CMD
| ((phy_id
& 0x1f) << 21) |
168 ((reg
& 0x1f) << 16)|val
, mmio
+ PHY_ACCESS
);
171 reg_val
= readl(mmio
+ PHY_ACCESS
);
172 udelay(30); /* It takes 30 us to read/write the data */
173 } while (--repeat
&& (reg_val
& PHY_CMD_ACTIVE
));
175 if(reg_val
& PHY_RD_ERR
)
185 This is the mii register read function provided to the mii interface.
187 static int amd8111e_mdio_read(struct net_device
* dev
, int phy_id
, int reg_num
)
189 struct amd8111e_priv
* lp
= netdev_priv(dev
);
190 unsigned int reg_val
;
192 amd8111e_read_phy(lp
,phy_id
,reg_num
,®_val
);
198 This is the mii register write function provided to the mii interface.
200 static void amd8111e_mdio_write(struct net_device
* dev
, int phy_id
, int reg_num
, int val
)
202 struct amd8111e_priv
* lp
= netdev_priv(dev
);
204 amd8111e_write_phy(lp
, phy_id
, reg_num
, val
);
208 This function will set PHY speed. During initialization sets the original speed to 100 full.
210 static void amd8111e_set_ext_phy(struct net_device
*dev
)
212 struct amd8111e_priv
*lp
= netdev_priv(dev
);
215 /* Determine mii register values to set the speed */
216 advert
= amd8111e_mdio_read(dev
, lp
->ext_phy_addr
, MII_ADVERTISE
);
217 tmp
= advert
& ~(ADVERTISE_ALL
| ADVERTISE_100BASE4
);
218 switch (lp
->ext_phy_option
){
221 case SPEED_AUTONEG
: /* advertise all values */
222 tmp
|= ( ADVERTISE_10HALF
|ADVERTISE_10FULL
|
223 ADVERTISE_100HALF
|ADVERTISE_100FULL
) ;
226 tmp
|= ADVERTISE_10HALF
;
229 tmp
|= ADVERTISE_10FULL
;
232 tmp
|= ADVERTISE_100HALF
;
235 tmp
|= ADVERTISE_100FULL
;
240 amd8111e_mdio_write(dev
, lp
->ext_phy_addr
, MII_ADVERTISE
, tmp
);
241 /* Restart auto negotiation */
242 bmcr
= amd8111e_mdio_read(dev
, lp
->ext_phy_addr
, MII_BMCR
);
243 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
244 amd8111e_mdio_write(dev
, lp
->ext_phy_addr
, MII_BMCR
, bmcr
);
249 This function will unmap skb->data space and will free
250 all transmit and receive skbuffs.
252 static int amd8111e_free_skbs(struct net_device
*dev
)
254 struct amd8111e_priv
*lp
= netdev_priv(dev
);
255 struct sk_buff
* rx_skbuff
;
258 /* Freeing transmit skbs */
259 for(i
= 0; i
< NUM_TX_BUFFERS
; i
++){
260 if(lp
->tx_skbuff
[i
]){
261 pci_unmap_single(lp
->pci_dev
,lp
->tx_dma_addr
[i
], lp
->tx_skbuff
[i
]->len
,PCI_DMA_TODEVICE
);
262 dev_kfree_skb (lp
->tx_skbuff
[i
]);
263 lp
->tx_skbuff
[i
] = NULL
;
264 lp
->tx_dma_addr
[i
] = 0;
267 /* Freeing previously allocated receive buffers */
268 for (i
= 0; i
< NUM_RX_BUFFERS
; i
++){
269 rx_skbuff
= lp
->rx_skbuff
[i
];
270 if(rx_skbuff
!= NULL
){
271 pci_unmap_single(lp
->pci_dev
,lp
->rx_dma_addr
[i
],
272 lp
->rx_buff_len
- 2,PCI_DMA_FROMDEVICE
);
273 dev_kfree_skb(lp
->rx_skbuff
[i
]);
274 lp
->rx_skbuff
[i
] = NULL
;
275 lp
->rx_dma_addr
[i
] = 0;
283 This will set the receive buffer length corresponding to the mtu size of networkinterface.
285 static inline void amd8111e_set_rx_buff_len(struct net_device
* dev
)
287 struct amd8111e_priv
* lp
= netdev_priv(dev
);
288 unsigned int mtu
= dev
->mtu
;
290 if (mtu
> ETH_DATA_LEN
){
291 /* MTU + ethernet header + FCS
292 + optional VLAN tag + skb reserve space 2 */
294 lp
->rx_buff_len
= mtu
+ ETH_HLEN
+ 10;
295 lp
->options
|= OPTION_JUMBO_ENABLE
;
297 lp
->rx_buff_len
= PKT_BUFF_SZ
;
298 lp
->options
&= ~OPTION_JUMBO_ENABLE
;
303 This function will free all the previously allocated buffers, determine new receive buffer length and will allocate new receive buffers. This function also allocates and initializes both the transmitter and receive hardware descriptors.
305 static int amd8111e_init_ring(struct net_device
*dev
)
307 struct amd8111e_priv
*lp
= netdev_priv(dev
);
310 lp
->rx_idx
= lp
->tx_idx
= 0;
311 lp
->tx_complete_idx
= 0;
316 /* Free previously allocated transmit and receive skbs */
317 amd8111e_free_skbs(dev
);
320 /* allocate the tx and rx descriptors */
321 if((lp
->tx_ring
= pci_alloc_consistent(lp
->pci_dev
,
322 sizeof(struct amd8111e_tx_dr
)*NUM_TX_RING_DR
,
323 &lp
->tx_ring_dma_addr
)) == NULL
)
327 if((lp
->rx_ring
= pci_alloc_consistent(lp
->pci_dev
,
328 sizeof(struct amd8111e_rx_dr
)*NUM_RX_RING_DR
,
329 &lp
->rx_ring_dma_addr
)) == NULL
)
331 goto err_free_tx_ring
;
334 /* Set new receive buff size */
335 amd8111e_set_rx_buff_len(dev
);
337 /* Allocating receive skbs */
338 for (i
= 0; i
< NUM_RX_BUFFERS
; i
++) {
340 if (!(lp
->rx_skbuff
[i
] = dev_alloc_skb(lp
->rx_buff_len
))) {
341 /* Release previos allocated skbs */
342 for(--i
; i
>= 0 ;i
--)
343 dev_kfree_skb(lp
->rx_skbuff
[i
]);
344 goto err_free_rx_ring
;
346 skb_reserve(lp
->rx_skbuff
[i
],2);
348 /* Initilaizing receive descriptors */
349 for (i
= 0; i
< NUM_RX_BUFFERS
; i
++) {
350 lp
->rx_dma_addr
[i
] = pci_map_single(lp
->pci_dev
,
351 lp
->rx_skbuff
[i
]->data
,lp
->rx_buff_len
-2, PCI_DMA_FROMDEVICE
);
353 lp
->rx_ring
[i
].buff_phy_addr
= cpu_to_le32(lp
->rx_dma_addr
[i
]);
354 lp
->rx_ring
[i
].buff_count
= cpu_to_le16(lp
->rx_buff_len
-2);
356 lp
->rx_ring
[i
].rx_flags
= cpu_to_le16(OWN_BIT
);
359 /* Initializing transmit descriptors */
360 for (i
= 0; i
< NUM_TX_RING_DR
; i
++) {
361 lp
->tx_ring
[i
].buff_phy_addr
= 0;
362 lp
->tx_ring
[i
].tx_flags
= 0;
363 lp
->tx_ring
[i
].buff_count
= 0;
370 pci_free_consistent(lp
->pci_dev
,
371 sizeof(struct amd8111e_rx_dr
)*NUM_RX_RING_DR
,lp
->rx_ring
,
372 lp
->rx_ring_dma_addr
);
376 pci_free_consistent(lp
->pci_dev
,
377 sizeof(struct amd8111e_tx_dr
)*NUM_TX_RING_DR
,lp
->tx_ring
,
378 lp
->tx_ring_dma_addr
);
383 /* This function will set the interrupt coalescing according to the input arguments */
384 static int amd8111e_set_coalesce(struct net_device
* dev
, enum coal_mode cmod
)
386 unsigned int timeout
;
387 unsigned int event_count
;
389 struct amd8111e_priv
*lp
= netdev_priv(dev
);
390 void __iomem
*mmio
= lp
->mmio
;
391 struct amd8111e_coalesce_conf
* coal_conf
= &lp
->coal_conf
;
397 timeout
= coal_conf
->rx_timeout
;
398 event_count
= coal_conf
->rx_event_count
;
399 if( timeout
> MAX_TIMEOUT
||
400 event_count
> MAX_EVENT_COUNT
)
403 timeout
= timeout
* DELAY_TIMER_CONV
;
404 writel(VAL0
|STINTEN
, mmio
+INTEN0
);
405 writel((u32
)DLY_INT_A_R0
|( event_count
<< 16 )|timeout
,
410 timeout
= coal_conf
->tx_timeout
;
411 event_count
= coal_conf
->tx_event_count
;
412 if( timeout
> MAX_TIMEOUT
||
413 event_count
> MAX_EVENT_COUNT
)
417 timeout
= timeout
* DELAY_TIMER_CONV
;
418 writel(VAL0
|STINTEN
,mmio
+INTEN0
);
419 writel((u32
)DLY_INT_B_T0
|( event_count
<< 16 )|timeout
,
424 writel(0,mmio
+STVAL
);
425 writel(STINTEN
, mmio
+INTEN0
);
426 writel(0, mmio
+DLY_INT_B
);
427 writel(0, mmio
+DLY_INT_A
);
430 /* Start the timer */
431 writel((u32
)SOFT_TIMER_FREQ
, mmio
+STVAL
); /* 0.5 sec */
432 writel(VAL0
|STINTEN
, mmio
+INTEN0
);
443 This function initializes the device registers and starts the device.
445 static int amd8111e_restart(struct net_device
*dev
)
447 struct amd8111e_priv
*lp
= netdev_priv(dev
);
448 void __iomem
*mmio
= lp
->mmio
;
452 writel(RUN
, mmio
+ CMD0
);
454 if(amd8111e_init_ring(dev
))
457 /* enable the port manager and set auto negotiation always */
458 writel((u32
) VAL1
|EN_PMGR
, mmio
+ CMD3
);
459 writel((u32
)XPHYANE
|XPHYRST
, mmio
+ CTRL2
);
461 amd8111e_set_ext_phy(dev
);
463 /* set control registers */
464 reg_val
= readl(mmio
+ CTRL1
);
465 reg_val
&= ~XMTSP_MASK
;
466 writel( reg_val
| XMTSP_128
| CACHE_ALIGN
, mmio
+ CTRL1
);
468 /* enable interrupt */
469 writel( APINT5EN
| APINT4EN
| APINT3EN
| APINT2EN
| APINT1EN
|
470 APINT0EN
| MIIPDTINTEN
| MCCIINTEN
| MCCINTEN
| MREINTEN
|
471 SPNDINTEN
| MPINTEN
| SINTEN
| STINTEN
, mmio
+ INTEN0
);
473 writel(VAL3
| LCINTEN
| VAL1
| TINTEN0
| VAL0
| RINTEN0
, mmio
+ INTEN0
);
475 /* initialize tx and rx ring base addresses */
476 writel((u32
)lp
->tx_ring_dma_addr
,mmio
+ XMT_RING_BASE_ADDR0
);
477 writel((u32
)lp
->rx_ring_dma_addr
,mmio
+ RCV_RING_BASE_ADDR0
);
479 writew((u32
)NUM_TX_RING_DR
, mmio
+ XMT_RING_LEN0
);
480 writew((u16
)NUM_RX_RING_DR
, mmio
+ RCV_RING_LEN0
);
482 /* set default IPG to 96 */
483 writew((u32
)DEFAULT_IPG
,mmio
+IPG
);
484 writew((u32
)(DEFAULT_IPG
-IFS1_DELTA
), mmio
+ IFS1
);
486 if(lp
->options
& OPTION_JUMBO_ENABLE
){
487 writel((u32
)VAL2
|JUMBO
, mmio
+ CMD3
);
489 writel( REX_UFLO
, mmio
+ CMD2
);
490 /* Should not set REX_UFLO for jumbo frames */
491 writel( VAL0
| APAD_XMT
|REX_RTRY
, mmio
+ CMD2
);
493 writel( VAL0
| APAD_XMT
| REX_RTRY
|REX_UFLO
, mmio
+ CMD2
);
494 writel((u32
)JUMBO
, mmio
+ CMD3
);
497 #if AMD8111E_VLAN_TAG_USED
498 writel((u32
) VAL2
|VSIZE
|VL_TAG_DEL
, mmio
+ CMD3
);
500 writel( VAL0
| APAD_XMT
| REX_RTRY
, mmio
+ CMD2
);
502 /* Setting the MAC address to the device */
503 for(i
= 0; i
< ETH_ADDR_LEN
; i
++)
504 writeb( dev
->dev_addr
[i
], mmio
+ PADR
+ i
);
506 /* Enable interrupt coalesce */
507 if(lp
->options
& OPTION_INTR_COAL_ENABLE
){
508 printk(KERN_INFO
"%s: Interrupt Coalescing Enabled.\n",
510 amd8111e_set_coalesce(dev
,ENABLE_COAL
);
513 /* set RUN bit to start the chip */
514 writel(VAL2
| RDMD0
, mmio
+ CMD0
);
515 writel(VAL0
| INTREN
| RUN
, mmio
+ CMD0
);
517 /* To avoid PCI posting bug */
522 This function clears necessary the device registers.
524 static void amd8111e_init_hw_default( struct amd8111e_priv
* lp
)
526 unsigned int reg_val
;
527 unsigned int logic_filter
[2] ={0,};
528 void __iomem
*mmio
= lp
->mmio
;
532 writel(RUN
, mmio
+ CMD0
);
534 /* AUTOPOLL0 Register *//*TBD default value is 8100 in FPS */
535 writew( 0x8100 | lp
->ext_phy_addr
, mmio
+ AUTOPOLL0
);
537 /* Clear RCV_RING_BASE_ADDR */
538 writel(0, mmio
+ RCV_RING_BASE_ADDR0
);
540 /* Clear XMT_RING_BASE_ADDR */
541 writel(0, mmio
+ XMT_RING_BASE_ADDR0
);
542 writel(0, mmio
+ XMT_RING_BASE_ADDR1
);
543 writel(0, mmio
+ XMT_RING_BASE_ADDR2
);
544 writel(0, mmio
+ XMT_RING_BASE_ADDR3
);
547 writel(CMD0_CLEAR
,mmio
+ CMD0
);
550 writel(CMD2_CLEAR
, mmio
+CMD2
);
553 writel(CMD7_CLEAR
, mmio
+ CMD7
);
555 /* Clear DLY_INT_A and DLY_INT_B */
556 writel(0x0, mmio
+ DLY_INT_A
);
557 writel(0x0, mmio
+ DLY_INT_B
);
559 /* Clear FLOW_CONTROL */
560 writel(0x0, mmio
+ FLOW_CONTROL
);
562 /* Clear INT0 write 1 to clear register */
563 reg_val
= readl(mmio
+ INT0
);
564 writel(reg_val
, mmio
+ INT0
);
567 writel(0x0, mmio
+ STVAL
);
570 writel( INTEN0_CLEAR
, mmio
+ INTEN0
);
573 writel(0x0 , mmio
+ LADRF
);
575 /* Set SRAM_SIZE & SRAM_BOUNDARY registers */
576 writel( 0x80010,mmio
+ SRAM_SIZE
);
578 /* Clear RCV_RING0_LEN */
579 writel(0x0, mmio
+ RCV_RING_LEN0
);
581 /* Clear XMT_RING0/1/2/3_LEN */
582 writel(0x0, mmio
+ XMT_RING_LEN0
);
583 writel(0x0, mmio
+ XMT_RING_LEN1
);
584 writel(0x0, mmio
+ XMT_RING_LEN2
);
585 writel(0x0, mmio
+ XMT_RING_LEN3
);
587 /* Clear XMT_RING_LIMIT */
588 writel(0x0, mmio
+ XMT_RING_LIMIT
);
591 writew(MIB_CLEAR
, mmio
+ MIB_ADDR
);
594 amd8111e_writeq(*(u64
*)logic_filter
,mmio
+LADRF
);
596 /* SRAM_SIZE register */
597 reg_val
= readl(mmio
+ SRAM_SIZE
);
599 if(lp
->options
& OPTION_JUMBO_ENABLE
)
600 writel( VAL2
|JUMBO
, mmio
+ CMD3
);
601 #if AMD8111E_VLAN_TAG_USED
602 writel(VAL2
|VSIZE
|VL_TAG_DEL
, mmio
+ CMD3
);
604 /* Set default value to CTRL1 Register */
605 writel(CTRL1_DEFAULT
, mmio
+ CTRL1
);
607 /* To avoid PCI posting bug */
613 This function disables the interrupt and clears all the pending
616 static void amd8111e_disable_interrupt(struct amd8111e_priv
* lp
)
620 /* Disable interrupt */
621 writel(INTREN
, lp
->mmio
+ CMD0
);
624 intr0
= readl(lp
->mmio
+ INT0
);
625 writel(intr0
, lp
->mmio
+ INT0
);
627 /* To avoid PCI posting bug */
628 readl(lp
->mmio
+ INT0
);
633 This function stops the chip.
635 static void amd8111e_stop_chip(struct amd8111e_priv
* lp
)
637 writel(RUN
, lp
->mmio
+ CMD0
);
639 /* To avoid PCI posting bug */
640 readl(lp
->mmio
+ CMD0
);
644 This function frees the transmiter and receiver descriptor rings.
646 static void amd8111e_free_ring(struct amd8111e_priv
* lp
)
649 /* Free transmit and receive skbs */
650 amd8111e_free_skbs(lp
->amd8111e_net_dev
);
652 /* Free transmit and receive descriptor rings */
654 pci_free_consistent(lp
->pci_dev
,
655 sizeof(struct amd8111e_rx_dr
)*NUM_RX_RING_DR
,
656 lp
->rx_ring
, lp
->rx_ring_dma_addr
);
661 pci_free_consistent(lp
->pci_dev
,
662 sizeof(struct amd8111e_tx_dr
)*NUM_TX_RING_DR
,
663 lp
->tx_ring
, lp
->tx_ring_dma_addr
);
669 #if AMD8111E_VLAN_TAG_USED
671 This is the receive indication function for packets with vlan tag.
673 static int amd8111e_vlan_rx(struct amd8111e_priv
*lp
, struct sk_buff
*skb
, u16 vlan_tag
)
675 #ifdef CONFIG_AMD8111E_NAPI
676 return vlan_hwaccel_receive_skb(skb
, lp
->vlgrp
,vlan_tag
);
678 return vlan_hwaccel_rx(skb
, lp
->vlgrp
, vlan_tag
);
679 #endif /* CONFIG_AMD8111E_NAPI */
684 This function will free all the transmit skbs that are actually transmitted by the device. It will check the ownership of the skb before freeing the skb.
686 static int amd8111e_tx(struct net_device
*dev
)
688 struct amd8111e_priv
* lp
= netdev_priv(dev
);
689 int tx_index
= lp
->tx_complete_idx
& TX_RING_DR_MOD_MASK
;
691 /* Complete all the transmit packet */
692 while (lp
->tx_complete_idx
!= lp
->tx_idx
){
693 tx_index
= lp
->tx_complete_idx
& TX_RING_DR_MOD_MASK
;
694 status
= le16_to_cpu(lp
->tx_ring
[tx_index
].tx_flags
);
697 break; /* It still hasn't been Txed */
699 lp
->tx_ring
[tx_index
].buff_phy_addr
= 0;
701 /* We must free the original skb */
702 if (lp
->tx_skbuff
[tx_index
]) {
703 pci_unmap_single(lp
->pci_dev
, lp
->tx_dma_addr
[tx_index
],
704 lp
->tx_skbuff
[tx_index
]->len
,
706 dev_kfree_skb_irq (lp
->tx_skbuff
[tx_index
]);
707 lp
->tx_skbuff
[tx_index
] = NULL
;
708 lp
->tx_dma_addr
[tx_index
] = 0;
710 lp
->tx_complete_idx
++;
711 /*COAL update tx coalescing parameters */
712 lp
->coal_conf
.tx_packets
++;
713 lp
->coal_conf
.tx_bytes
+= lp
->tx_ring
[tx_index
].buff_count
;
715 if (netif_queue_stopped(dev
) &&
716 lp
->tx_complete_idx
> lp
->tx_idx
- NUM_TX_BUFFERS
+2){
717 /* The ring is no longer full, clear tbusy. */
718 /* lp->tx_full = 0; */
719 netif_wake_queue (dev
);
725 #ifdef CONFIG_AMD8111E_NAPI
726 /* This function handles the driver receive operation in polling mode */
727 static int amd8111e_rx_poll(struct net_device
*dev
, int * budget
)
729 struct amd8111e_priv
*lp
= netdev_priv(dev
);
730 int rx_index
= lp
->rx_idx
& RX_RING_DR_MOD_MASK
;
731 void __iomem
*mmio
= lp
->mmio
;
732 struct sk_buff
*skb
,*new_skb
;
733 int min_pkt_len
, status
;
736 /*int max_rx_pkt = NUM_RX_BUFFERS;*/
738 #if AMD8111E_VLAN_TAG_USED
741 int rx_pkt_limit
= dev
->quota
;
745 /* process receive packets until we use the quota*/
746 /* If we own the next entry, it's a new packet. Send it up. */
748 status
= le16_to_cpu(lp
->rx_ring
[rx_index
].rx_flags
);
749 if (status
& OWN_BIT
)
753 * There is a tricky error noted by John Murphy,
754 * <murf@perftech.com> to Russ Nelson: Even with
755 * full-sized * buffers it's possible for a
756 * jabber packet to use two buffers, with only
757 * the last correctly noting the error.
760 if(status
& ERR_BIT
) {
762 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
765 /* check for STP and ENP */
766 if(!((status
& STP_BIT
) && (status
& ENP_BIT
))){
768 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
771 pkt_len
= le16_to_cpu(lp
->rx_ring
[rx_index
].msg_count
) - 4;
773 #if AMD8111E_VLAN_TAG_USED
774 vtag
= status
& TT_MASK
;
775 /*MAC will strip vlan tag*/
776 if(lp
->vlgrp
!= NULL
&& vtag
!=0)
777 min_pkt_len
=MIN_PKT_LEN
- 4;
780 min_pkt_len
=MIN_PKT_LEN
;
782 if (pkt_len
< min_pkt_len
) {
783 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
787 if(--rx_pkt_limit
< 0)
789 if(!(new_skb
= dev_alloc_skb(lp
->rx_buff_len
))){
790 /* if allocation fail,
791 ignore that pkt and go to next one */
792 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
797 skb_reserve(new_skb
, 2);
798 skb
= lp
->rx_skbuff
[rx_index
];
799 pci_unmap_single(lp
->pci_dev
,lp
->rx_dma_addr
[rx_index
],
800 lp
->rx_buff_len
-2, PCI_DMA_FROMDEVICE
);
801 skb_put(skb
, pkt_len
);
803 lp
->rx_skbuff
[rx_index
] = new_skb
;
805 lp
->rx_dma_addr
[rx_index
] = pci_map_single(lp
->pci_dev
,
810 skb
->protocol
= eth_type_trans(skb
, dev
);
812 #if AMD8111E_VLAN_TAG_USED
813 if(lp
->vlgrp
!= NULL
&& (vtag
== TT_VLAN_TAGGED
)){
814 amd8111e_vlan_rx(lp
, skb
,
815 le16_to_cpu(lp
->rx_ring
[rx_index
].tag_ctrl_info
));
818 netif_receive_skb(skb
);
819 /*COAL update rx coalescing parameters*/
820 lp
->coal_conf
.rx_packets
++;
821 lp
->coal_conf
.rx_bytes
+= pkt_len
;
823 dev
->last_rx
= jiffies
;
826 lp
->rx_ring
[rx_index
].buff_phy_addr
827 = cpu_to_le32(lp
->rx_dma_addr
[rx_index
]);
828 lp
->rx_ring
[rx_index
].buff_count
=
829 cpu_to_le16(lp
->rx_buff_len
-2);
831 lp
->rx_ring
[rx_index
].rx_flags
|= cpu_to_le16(OWN_BIT
);
832 rx_index
= (++lp
->rx_idx
) & RX_RING_DR_MOD_MASK
;
834 /* Check the interrupt status register for more packets in the
835 mean time. Process them since we have not used up our quota.*/
837 intr0
= readl(mmio
+ INT0
);
838 /*Ack receive packets */
839 writel(intr0
& RINT0
,mmio
+ INT0
);
841 } while(intr0
& RINT0
);
843 /* Receive descriptor is empty now */
844 dev
->quota
-= num_rx_pkt
;
845 *budget
-= num_rx_pkt
;
847 spin_lock_irqsave(&lp
->lock
, flags
);
848 netif_rx_complete(dev
);
849 writel(VAL0
|RINTEN0
, mmio
+ INTEN0
);
850 writel(VAL2
| RDMD0
, mmio
+ CMD0
);
851 spin_unlock_irqrestore(&lp
->lock
, flags
);
855 /* Do not call a netif_rx_complete */
856 dev
->quota
-= num_rx_pkt
;
857 *budget
-= num_rx_pkt
;
863 This function will check the ownership of receive buffers and descriptors. It will indicate to kernel up to half the number of maximum receive buffers in the descriptor ring, in a single receive interrupt. It will also replenish the descriptors with new skbs.
865 static int amd8111e_rx(struct net_device
*dev
)
867 struct amd8111e_priv
*lp
= netdev_priv(dev
);
868 struct sk_buff
*skb
,*new_skb
;
869 int rx_index
= lp
->rx_idx
& RX_RING_DR_MOD_MASK
;
870 int min_pkt_len
, status
;
872 int max_rx_pkt
= NUM_RX_BUFFERS
;
874 #if AMD8111E_VLAN_TAG_USED
878 /* If we own the next entry, it's a new packet. Send it up. */
879 while(++num_rx_pkt
<= max_rx_pkt
){
880 status
= le16_to_cpu(lp
->rx_ring
[rx_index
].rx_flags
);
884 /* check if err summary bit is set */
885 if(status
& ERR_BIT
){
887 * There is a tricky error noted by John Murphy,
888 * <murf@perftech.com> to Russ Nelson: Even with full-sized
889 * buffers it's possible for a jabber packet to use two
890 * buffers, with only the last correctly noting the error. */
892 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
895 /* check for STP and ENP */
896 if(!((status
& STP_BIT
) && (status
& ENP_BIT
))){
898 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
901 pkt_len
= le16_to_cpu(lp
->rx_ring
[rx_index
].msg_count
) - 4;
903 #if AMD8111E_VLAN_TAG_USED
904 vtag
= status
& TT_MASK
;
905 /*MAC will strip vlan tag*/
906 if(lp
->vlgrp
!= NULL
&& vtag
!=0)
907 min_pkt_len
=MIN_PKT_LEN
- 4;
910 min_pkt_len
=MIN_PKT_LEN
;
912 if (pkt_len
< min_pkt_len
) {
913 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
917 if(!(new_skb
= dev_alloc_skb(lp
->rx_buff_len
))){
918 /* if allocation fail,
919 ignore that pkt and go to next one */
920 lp
->rx_ring
[rx_index
].rx_flags
&= RESET_RX_FLAGS
;
925 skb_reserve(new_skb
, 2);
926 skb
= lp
->rx_skbuff
[rx_index
];
927 pci_unmap_single(lp
->pci_dev
,lp
->rx_dma_addr
[rx_index
],
928 lp
->rx_buff_len
-2, PCI_DMA_FROMDEVICE
);
929 skb_put(skb
, pkt_len
);
931 lp
->rx_skbuff
[rx_index
] = new_skb
;
933 lp
->rx_dma_addr
[rx_index
] = pci_map_single(lp
->pci_dev
,
934 new_skb
->data
, lp
->rx_buff_len
-2,PCI_DMA_FROMDEVICE
);
936 skb
->protocol
= eth_type_trans(skb
, dev
);
938 #if AMD8111E_VLAN_TAG_USED
939 if(lp
->vlgrp
!= NULL
&& (vtag
== TT_VLAN_TAGGED
)){
940 amd8111e_vlan_rx(lp
, skb
,
941 le16_to_cpu(lp
->rx_ring
[rx_index
].tag_ctrl_info
));
946 /*COAL update rx coalescing parameters*/
947 lp
->coal_conf
.rx_packets
++;
948 lp
->coal_conf
.rx_bytes
+= pkt_len
;
950 dev
->last_rx
= jiffies
;
953 lp
->rx_ring
[rx_index
].buff_phy_addr
954 = cpu_to_le32(lp
->rx_dma_addr
[rx_index
]);
955 lp
->rx_ring
[rx_index
].buff_count
=
956 cpu_to_le16(lp
->rx_buff_len
-2);
958 lp
->rx_ring
[rx_index
].rx_flags
|= cpu_to_le16(OWN_BIT
);
959 rx_index
= (++lp
->rx_idx
) & RX_RING_DR_MOD_MASK
;
964 #endif /* CONFIG_AMD8111E_NAPI */
966 This function will indicate the link status to the kernel.
968 static int amd8111e_link_change(struct net_device
* dev
)
970 struct amd8111e_priv
*lp
= netdev_priv(dev
);
973 /* read the link change */
974 status0
= readl(lp
->mmio
+ STAT0
);
976 if(status0
& LINK_STATS
){
977 if(status0
& AUTONEG_COMPLETE
)
978 lp
->link_config
.autoneg
= AUTONEG_ENABLE
;
980 lp
->link_config
.autoneg
= AUTONEG_DISABLE
;
982 if(status0
& FULL_DPLX
)
983 lp
->link_config
.duplex
= DUPLEX_FULL
;
985 lp
->link_config
.duplex
= DUPLEX_HALF
;
986 speed
= (status0
& SPEED_MASK
) >> 7;
987 if(speed
== PHY_SPEED_10
)
988 lp
->link_config
.speed
= SPEED_10
;
989 else if(speed
== PHY_SPEED_100
)
990 lp
->link_config
.speed
= SPEED_100
;
992 printk(KERN_INFO
"%s: Link is Up. Speed is %s Mbps %s Duplex\n", dev
->name
,
993 (lp
->link_config
.speed
== SPEED_100
) ? "100": "10",
994 (lp
->link_config
.duplex
== DUPLEX_FULL
)? "Full": "Half");
995 netif_carrier_on(dev
);
998 lp
->link_config
.speed
= SPEED_INVALID
;
999 lp
->link_config
.duplex
= DUPLEX_INVALID
;
1000 lp
->link_config
.autoneg
= AUTONEG_INVALID
;
1001 printk(KERN_INFO
"%s: Link is Down.\n",dev
->name
);
1002 netif_carrier_off(dev
);
1008 This function reads the mib counters.
1010 static int amd8111e_read_mib(void __iomem
*mmio
, u8 MIB_COUNTER
)
1012 unsigned int status
;
1014 unsigned int repeat
= REPEAT_CNT
;
1016 writew( MIB_RD_CMD
| MIB_COUNTER
, mmio
+ MIB_ADDR
);
1018 status
= readw(mmio
+ MIB_ADDR
);
1019 udelay(2); /* controller takes MAX 2 us to get mib data */
1021 while (--repeat
&& (status
& MIB_CMD_ACTIVE
));
1023 data
= readl(mmio
+ MIB_DATA
);
1028 This function reads the mib registers and returns the hardware statistics. It updates previous internal driver statistics with new values.
1030 static struct net_device_stats
*amd8111e_get_stats(struct net_device
* dev
)
1032 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1033 void __iomem
*mmio
= lp
->mmio
;
1034 unsigned long flags
;
1035 /* struct net_device_stats *prev_stats = &lp->prev_stats; */
1036 struct net_device_stats
* new_stats
= &lp
->stats
;
1040 spin_lock_irqsave (&lp
->lock
, flags
);
1042 /* stats.rx_packets */
1043 new_stats
->rx_packets
= amd8111e_read_mib(mmio
, rcv_broadcast_pkts
)+
1044 amd8111e_read_mib(mmio
, rcv_multicast_pkts
)+
1045 amd8111e_read_mib(mmio
, rcv_unicast_pkts
);
1047 /* stats.tx_packets */
1048 new_stats
->tx_packets
= amd8111e_read_mib(mmio
, xmt_packets
);
1051 new_stats
->rx_bytes
= amd8111e_read_mib(mmio
, rcv_octets
);
1053 /* stats.tx_bytes */
1054 new_stats
->tx_bytes
= amd8111e_read_mib(mmio
, xmt_octets
);
1056 /* stats.rx_errors */
1057 /* hw errors + errors driver reported */
1058 new_stats
->rx_errors
= amd8111e_read_mib(mmio
, rcv_undersize_pkts
)+
1059 amd8111e_read_mib(mmio
, rcv_fragments
)+
1060 amd8111e_read_mib(mmio
, rcv_jabbers
)+
1061 amd8111e_read_mib(mmio
, rcv_alignment_errors
)+
1062 amd8111e_read_mib(mmio
, rcv_fcs_errors
)+
1063 amd8111e_read_mib(mmio
, rcv_miss_pkts
)+
1066 /* stats.tx_errors */
1067 new_stats
->tx_errors
= amd8111e_read_mib(mmio
, xmt_underrun_pkts
);
1069 /* stats.rx_dropped*/
1070 new_stats
->rx_dropped
= amd8111e_read_mib(mmio
, rcv_miss_pkts
);
1072 /* stats.tx_dropped*/
1073 new_stats
->tx_dropped
= amd8111e_read_mib(mmio
, xmt_underrun_pkts
);
1075 /* stats.multicast*/
1076 new_stats
->multicast
= amd8111e_read_mib(mmio
, rcv_multicast_pkts
);
1078 /* stats.collisions*/
1079 new_stats
->collisions
= amd8111e_read_mib(mmio
, xmt_collisions
);
1081 /* stats.rx_length_errors*/
1082 new_stats
->rx_length_errors
=
1083 amd8111e_read_mib(mmio
, rcv_undersize_pkts
)+
1084 amd8111e_read_mib(mmio
, rcv_oversize_pkts
);
1086 /* stats.rx_over_errors*/
1087 new_stats
->rx_over_errors
= amd8111e_read_mib(mmio
, rcv_miss_pkts
);
1089 /* stats.rx_crc_errors*/
1090 new_stats
->rx_crc_errors
= amd8111e_read_mib(mmio
, rcv_fcs_errors
);
1092 /* stats.rx_frame_errors*/
1093 new_stats
->rx_frame_errors
=
1094 amd8111e_read_mib(mmio
, rcv_alignment_errors
);
1096 /* stats.rx_fifo_errors */
1097 new_stats
->rx_fifo_errors
= amd8111e_read_mib(mmio
, rcv_miss_pkts
);
1099 /* stats.rx_missed_errors */
1100 new_stats
->rx_missed_errors
= amd8111e_read_mib(mmio
, rcv_miss_pkts
);
1102 /* stats.tx_aborted_errors*/
1103 new_stats
->tx_aborted_errors
=
1104 amd8111e_read_mib(mmio
, xmt_excessive_collision
);
1106 /* stats.tx_carrier_errors*/
1107 new_stats
->tx_carrier_errors
=
1108 amd8111e_read_mib(mmio
, xmt_loss_carrier
);
1110 /* stats.tx_fifo_errors*/
1111 new_stats
->tx_fifo_errors
= amd8111e_read_mib(mmio
, xmt_underrun_pkts
);
1113 /* stats.tx_window_errors*/
1114 new_stats
->tx_window_errors
=
1115 amd8111e_read_mib(mmio
, xmt_late_collision
);
1117 /* Reset the mibs for collecting new statistics */
1118 /* writew(MIB_CLEAR, mmio + MIB_ADDR);*/
1120 spin_unlock_irqrestore (&lp
->lock
, flags
);
1124 /* This function recalculate the interupt coalescing mode on every interrupt
1125 according to the datarate and the packet rate.
1127 static int amd8111e_calc_coalesce(struct net_device
*dev
)
1129 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1130 struct amd8111e_coalesce_conf
* coal_conf
= &lp
->coal_conf
;
1138 tx_pkt_rate
= coal_conf
->tx_packets
- coal_conf
->tx_prev_packets
;
1139 coal_conf
->tx_prev_packets
= coal_conf
->tx_packets
;
1141 tx_data_rate
= coal_conf
->tx_bytes
- coal_conf
->tx_prev_bytes
;
1142 coal_conf
->tx_prev_bytes
= coal_conf
->tx_bytes
;
1144 rx_pkt_rate
= coal_conf
->rx_packets
- coal_conf
->rx_prev_packets
;
1145 coal_conf
->rx_prev_packets
= coal_conf
->rx_packets
;
1147 rx_data_rate
= coal_conf
->rx_bytes
- coal_conf
->rx_prev_bytes
;
1148 coal_conf
->rx_prev_bytes
= coal_conf
->rx_bytes
;
1150 if(rx_pkt_rate
< 800){
1151 if(coal_conf
->rx_coal_type
!= NO_COALESCE
){
1153 coal_conf
->rx_timeout
= 0x0;
1154 coal_conf
->rx_event_count
= 0;
1155 amd8111e_set_coalesce(dev
,RX_INTR_COAL
);
1156 coal_conf
->rx_coal_type
= NO_COALESCE
;
1161 rx_pkt_size
= rx_data_rate
/rx_pkt_rate
;
1162 if (rx_pkt_size
< 128){
1163 if(coal_conf
->rx_coal_type
!= NO_COALESCE
){
1165 coal_conf
->rx_timeout
= 0;
1166 coal_conf
->rx_event_count
= 0;
1167 amd8111e_set_coalesce(dev
,RX_INTR_COAL
);
1168 coal_conf
->rx_coal_type
= NO_COALESCE
;
1172 else if ( (rx_pkt_size
>= 128) && (rx_pkt_size
< 512) ){
1174 if(coal_conf
->rx_coal_type
!= LOW_COALESCE
){
1175 coal_conf
->rx_timeout
= 1;
1176 coal_conf
->rx_event_count
= 4;
1177 amd8111e_set_coalesce(dev
,RX_INTR_COAL
);
1178 coal_conf
->rx_coal_type
= LOW_COALESCE
;
1181 else if ((rx_pkt_size
>= 512) && (rx_pkt_size
< 1024)){
1183 if(coal_conf
->rx_coal_type
!= MEDIUM_COALESCE
){
1184 coal_conf
->rx_timeout
= 1;
1185 coal_conf
->rx_event_count
= 4;
1186 amd8111e_set_coalesce(dev
,RX_INTR_COAL
);
1187 coal_conf
->rx_coal_type
= MEDIUM_COALESCE
;
1191 else if(rx_pkt_size
>= 1024){
1192 if(coal_conf
->rx_coal_type
!= HIGH_COALESCE
){
1193 coal_conf
->rx_timeout
= 2;
1194 coal_conf
->rx_event_count
= 3;
1195 amd8111e_set_coalesce(dev
,RX_INTR_COAL
);
1196 coal_conf
->rx_coal_type
= HIGH_COALESCE
;
1200 /* NOW FOR TX INTR COALESC */
1201 if(tx_pkt_rate
< 800){
1202 if(coal_conf
->tx_coal_type
!= NO_COALESCE
){
1204 coal_conf
->tx_timeout
= 0x0;
1205 coal_conf
->tx_event_count
= 0;
1206 amd8111e_set_coalesce(dev
,TX_INTR_COAL
);
1207 coal_conf
->tx_coal_type
= NO_COALESCE
;
1212 tx_pkt_size
= tx_data_rate
/tx_pkt_rate
;
1213 if (tx_pkt_size
< 128){
1215 if(coal_conf
->tx_coal_type
!= NO_COALESCE
){
1217 coal_conf
->tx_timeout
= 0;
1218 coal_conf
->tx_event_count
= 0;
1219 amd8111e_set_coalesce(dev
,TX_INTR_COAL
);
1220 coal_conf
->tx_coal_type
= NO_COALESCE
;
1224 else if ( (tx_pkt_size
>= 128) && (tx_pkt_size
< 512) ){
1226 if(coal_conf
->tx_coal_type
!= LOW_COALESCE
){
1227 coal_conf
->tx_timeout
= 1;
1228 coal_conf
->tx_event_count
= 2;
1229 amd8111e_set_coalesce(dev
,TX_INTR_COAL
);
1230 coal_conf
->tx_coal_type
= LOW_COALESCE
;
1234 else if ((tx_pkt_size
>= 512) && (tx_pkt_size
< 1024)){
1236 if(coal_conf
->tx_coal_type
!= MEDIUM_COALESCE
){
1237 coal_conf
->tx_timeout
= 2;
1238 coal_conf
->tx_event_count
= 5;
1239 amd8111e_set_coalesce(dev
,TX_INTR_COAL
);
1240 coal_conf
->tx_coal_type
= MEDIUM_COALESCE
;
1244 else if(tx_pkt_size
>= 1024){
1245 if (tx_pkt_size
>= 1024){
1246 if(coal_conf
->tx_coal_type
!= HIGH_COALESCE
){
1247 coal_conf
->tx_timeout
= 4;
1248 coal_conf
->tx_event_count
= 8;
1249 amd8111e_set_coalesce(dev
,TX_INTR_COAL
);
1250 coal_conf
->tx_coal_type
= HIGH_COALESCE
;
1259 This is device interrupt function. It handles transmit, receive,link change and hardware timer interrupts.
1261 static irqreturn_t
amd8111e_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1264 struct net_device
* dev
= (struct net_device
*) dev_id
;
1265 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1266 void __iomem
*mmio
= lp
->mmio
;
1267 unsigned int intr0
, intren0
;
1268 unsigned int handled
= 1;
1270 if(unlikely(dev
== NULL
))
1273 spin_lock(&lp
->lock
);
1275 /* disabling interrupt */
1276 writel(INTREN
, mmio
+ CMD0
);
1278 /* Read interrupt status */
1279 intr0
= readl(mmio
+ INT0
);
1280 intren0
= readl(mmio
+ INTEN0
);
1282 /* Process all the INT event until INTR bit is clear. */
1284 if (!(intr0
& INTR
)){
1286 goto err_no_interrupt
;
1289 /* Current driver processes 4 interrupts : RINT,TINT,LCINT,STINT */
1290 writel(intr0
, mmio
+ INT0
);
1292 /* Check if Receive Interrupt has occurred. */
1293 #ifdef CONFIG_AMD8111E_NAPI
1295 if(netif_rx_schedule_prep(dev
)){
1296 /* Disable receive interupts */
1297 writel(RINTEN0
, mmio
+ INTEN0
);
1298 /* Schedule a polling routine */
1299 __netif_rx_schedule(dev
);
1301 else if (intren0
& RINTEN0
) {
1302 printk("************Driver bug! \
1303 interrupt while in poll\n");
1304 /* Fix by disable receive interrupts */
1305 writel(RINTEN0
, mmio
+ INTEN0
);
1311 writel(VAL2
| RDMD0
, mmio
+ CMD0
);
1313 #endif /* CONFIG_AMD8111E_NAPI */
1314 /* Check if Transmit Interrupt has occurred. */
1318 /* Check if Link Change Interrupt has occurred. */
1320 amd8111e_link_change(dev
);
1322 /* Check if Hardware Timer Interrupt has occurred. */
1324 amd8111e_calc_coalesce(dev
);
1327 writel( VAL0
| INTREN
,mmio
+ CMD0
);
1329 spin_unlock(&lp
->lock
);
1331 return IRQ_RETVAL(handled
);
1334 #ifdef CONFIG_NET_POLL_CONTROLLER
1335 static void amd8111e_poll(struct net_device
*dev
)
1337 unsigned long flags
;
1338 local_save_flags(flags
);
1339 local_irq_disable();
1340 amd8111e_interrupt(0, dev
, NULL
);
1341 local_irq_restore(flags
);
1347 This function closes the network interface and updates the statistics so that most recent statistics will be available after the interface is down.
1349 static int amd8111e_close(struct net_device
* dev
)
1351 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1352 netif_stop_queue(dev
);
1354 spin_lock_irq(&lp
->lock
);
1356 amd8111e_disable_interrupt(lp
);
1357 amd8111e_stop_chip(lp
);
1358 amd8111e_free_ring(lp
);
1360 netif_carrier_off(lp
->amd8111e_net_dev
);
1362 /* Delete ipg timer */
1363 if(lp
->options
& OPTION_DYN_IPG_ENABLE
)
1364 del_timer_sync(&lp
->ipg_data
.ipg_timer
);
1366 spin_unlock_irq(&lp
->lock
);
1367 free_irq(dev
->irq
, dev
);
1369 /* Update the statistics before closing */
1370 amd8111e_get_stats(dev
);
1374 /* This function opens new interface.It requests irq for the device, initializes the device,buffers and descriptors, and starts the device.
1376 static int amd8111e_open(struct net_device
* dev
)
1378 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1380 if(dev
->irq
==0 || request_irq(dev
->irq
, amd8111e_interrupt
, SA_SHIRQ
,
1384 spin_lock_irq(&lp
->lock
);
1386 amd8111e_init_hw_default(lp
);
1388 if(amd8111e_restart(dev
)){
1389 spin_unlock_irq(&lp
->lock
);
1391 free_irq(dev
->irq
, dev
);
1394 /* Start ipg timer */
1395 if(lp
->options
& OPTION_DYN_IPG_ENABLE
){
1396 add_timer(&lp
->ipg_data
.ipg_timer
);
1397 printk(KERN_INFO
"%s: Dynamic IPG Enabled.\n",dev
->name
);
1402 spin_unlock_irq(&lp
->lock
);
1404 netif_start_queue(dev
);
1409 This function checks if there is any transmit descriptors available to queue more packet.
1411 static int amd8111e_tx_queue_avail(struct amd8111e_priv
* lp
)
1413 int tx_index
= lp
->tx_idx
& TX_BUFF_MOD_MASK
;
1414 if(lp
->tx_skbuff
[tx_index
] != 0)
1421 This function will queue the transmit packets to the descriptors and will trigger the send operation. It also initializes the transmit descriptors with buffer physical address, byte count, ownership to hardware etc.
1424 static int amd8111e_start_xmit(struct sk_buff
*skb
, struct net_device
* dev
)
1426 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1428 unsigned long flags
;
1430 spin_lock_irqsave(&lp
->lock
, flags
);
1432 tx_index
= lp
->tx_idx
& TX_RING_DR_MOD_MASK
;
1434 lp
->tx_ring
[tx_index
].buff_count
= cpu_to_le16(skb
->len
);
1436 lp
->tx_skbuff
[tx_index
] = skb
;
1437 lp
->tx_ring
[tx_index
].tx_flags
= 0;
1439 #if AMD8111E_VLAN_TAG_USED
1440 if((lp
->vlgrp
!= NULL
) && vlan_tx_tag_present(skb
)){
1441 lp
->tx_ring
[tx_index
].tag_ctrl_cmd
|=
1442 cpu_to_le16(TCC_VLAN_INSERT
);
1443 lp
->tx_ring
[tx_index
].tag_ctrl_info
=
1444 cpu_to_le16(vlan_tx_tag_get(skb
));
1448 lp
->tx_dma_addr
[tx_index
] =
1449 pci_map_single(lp
->pci_dev
, skb
->data
, skb
->len
, PCI_DMA_TODEVICE
);
1450 lp
->tx_ring
[tx_index
].buff_phy_addr
=
1451 (u32
) cpu_to_le32(lp
->tx_dma_addr
[tx_index
]);
1453 /* Set FCS and LTINT bits */
1455 lp
->tx_ring
[tx_index
].tx_flags
|=
1456 cpu_to_le16(OWN_BIT
| STP_BIT
| ENP_BIT
|ADD_FCS_BIT
|LTINT_BIT
);
1460 /* Trigger an immediate send poll. */
1461 writel( VAL1
| TDMD0
, lp
->mmio
+ CMD0
);
1462 writel( VAL2
| RDMD0
,lp
->mmio
+ CMD0
);
1464 dev
->trans_start
= jiffies
;
1466 if(amd8111e_tx_queue_avail(lp
) < 0){
1467 netif_stop_queue(dev
);
1469 spin_unlock_irqrestore(&lp
->lock
, flags
);
1473 This function returns all the memory mapped registers of the device.
1475 static void amd8111e_read_regs(struct amd8111e_priv
*lp
, u32
*buf
)
1477 void __iomem
*mmio
= lp
->mmio
;
1478 /* Read only necessary registers */
1479 buf
[0] = readl(mmio
+ XMT_RING_BASE_ADDR0
);
1480 buf
[1] = readl(mmio
+ XMT_RING_LEN0
);
1481 buf
[2] = readl(mmio
+ RCV_RING_BASE_ADDR0
);
1482 buf
[3] = readl(mmio
+ RCV_RING_LEN0
);
1483 buf
[4] = readl(mmio
+ CMD0
);
1484 buf
[5] = readl(mmio
+ CMD2
);
1485 buf
[6] = readl(mmio
+ CMD3
);
1486 buf
[7] = readl(mmio
+ CMD7
);
1487 buf
[8] = readl(mmio
+ INT0
);
1488 buf
[9] = readl(mmio
+ INTEN0
);
1489 buf
[10] = readl(mmio
+ LADRF
);
1490 buf
[11] = readl(mmio
+ LADRF
+4);
1491 buf
[12] = readl(mmio
+ STAT0
);
1495 amd8111e crc generator implementation is different from the kernel
1496 ether_crc() function.
1498 static int amd8111e_ether_crc(int len
, char* mac_addr
)
1501 unsigned char octet
;
1504 for(byte
=0; byte
< len
; byte
++){
1505 octet
= mac_addr
[byte
];
1506 for( i
=0;i
< 8; i
++){
1507 /*If the next bit form the input stream is 1,subtract the divisor (CRC32) from the dividend(crc).*/
1508 if( (octet
& 0x1) ^ (crc
& 0x1) ){
1521 This function sets promiscuos mode, all-multi mode or the multicast address
1524 static void amd8111e_set_multicast_list(struct net_device
*dev
)
1526 struct dev_mc_list
* mc_ptr
;
1527 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1530 if(dev
->flags
& IFF_PROMISC
){
1531 printk(KERN_INFO
"%s: Setting promiscuous mode.\n",dev
->name
);
1532 writel( VAL2
| PROM
, lp
->mmio
+ CMD2
);
1536 writel( PROM
, lp
->mmio
+ CMD2
);
1537 if(dev
->flags
& IFF_ALLMULTI
|| dev
->mc_count
> MAX_FILTER_SIZE
){
1538 /* get all multicast packet */
1539 mc_filter
[1] = mc_filter
[0] = 0xffffffff;
1540 lp
->mc_list
= dev
->mc_list
;
1541 lp
->options
|= OPTION_MULTICAST_ENABLE
;
1542 amd8111e_writeq(*(u64
*)mc_filter
,lp
->mmio
+ LADRF
);
1545 if( dev
->mc_count
== 0 ){
1546 /* get only own packets */
1547 mc_filter
[1] = mc_filter
[0] = 0;
1549 lp
->options
&= ~OPTION_MULTICAST_ENABLE
;
1550 amd8111e_writeq(*(u64
*)mc_filter
,lp
->mmio
+ LADRF
);
1551 /* disable promiscous mode */
1552 writel(PROM
, lp
->mmio
+ CMD2
);
1555 /* load all the multicast addresses in the logic filter */
1556 lp
->options
|= OPTION_MULTICAST_ENABLE
;
1557 lp
->mc_list
= dev
->mc_list
;
1558 mc_filter
[1] = mc_filter
[0] = 0;
1559 for (i
= 0, mc_ptr
= dev
->mc_list
; mc_ptr
&& i
< dev
->mc_count
;
1560 i
++, mc_ptr
= mc_ptr
->next
) {
1561 bit_num
= ( amd8111e_ether_crc(ETH_ALEN
,mc_ptr
->dmi_addr
) >> 26 ) & 0x3f;
1562 mc_filter
[bit_num
>> 5] |= 1 << (bit_num
& 31);
1564 amd8111e_writeq(*(u64
*)mc_filter
,lp
->mmio
+ LADRF
);
1566 /* To eliminate PCI posting bug */
1567 readl(lp
->mmio
+ CMD2
);
1571 static void amd8111e_get_drvinfo(struct net_device
* dev
, struct ethtool_drvinfo
*info
)
1573 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1574 struct pci_dev
*pci_dev
= lp
->pci_dev
;
1575 strcpy (info
->driver
, MODULE_NAME
);
1576 strcpy (info
->version
, MODULE_VERS
);
1577 sprintf(info
->fw_version
,"%u",chip_version
);
1578 strcpy (info
->bus_info
, pci_name(pci_dev
));
1581 static int amd8111e_get_regs_len(struct net_device
*dev
)
1583 return AMD8111E_REG_DUMP_LEN
;
1586 static void amd8111e_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *buf
)
1588 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1590 amd8111e_read_regs(lp
, buf
);
1593 static int amd8111e_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1595 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1596 spin_lock_irq(&lp
->lock
);
1597 mii_ethtool_gset(&lp
->mii_if
, ecmd
);
1598 spin_unlock_irq(&lp
->lock
);
1602 static int amd8111e_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1604 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1606 spin_lock_irq(&lp
->lock
);
1607 res
= mii_ethtool_sset(&lp
->mii_if
, ecmd
);
1608 spin_unlock_irq(&lp
->lock
);
1612 static int amd8111e_nway_reset(struct net_device
*dev
)
1614 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1615 return mii_nway_restart(&lp
->mii_if
);
1618 static u32
amd8111e_get_link(struct net_device
*dev
)
1620 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1621 return mii_link_ok(&lp
->mii_if
);
1624 static void amd8111e_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol_info
)
1626 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1627 wol_info
->supported
= WAKE_MAGIC
|WAKE_PHY
;
1628 if (lp
->options
& OPTION_WOL_ENABLE
)
1629 wol_info
->wolopts
= WAKE_MAGIC
;
1632 static int amd8111e_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol_info
)
1634 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1635 if (wol_info
->wolopts
& ~(WAKE_MAGIC
|WAKE_PHY
))
1637 spin_lock_irq(&lp
->lock
);
1638 if (wol_info
->wolopts
& WAKE_MAGIC
)
1640 (OPTION_WOL_ENABLE
| OPTION_WAKE_MAGIC_ENABLE
);
1641 else if(wol_info
->wolopts
& WAKE_PHY
)
1643 (OPTION_WOL_ENABLE
| OPTION_WAKE_PHY_ENABLE
);
1645 lp
->options
&= ~OPTION_WOL_ENABLE
;
1646 spin_unlock_irq(&lp
->lock
);
1650 static struct ethtool_ops ops
= {
1651 .get_drvinfo
= amd8111e_get_drvinfo
,
1652 .get_regs_len
= amd8111e_get_regs_len
,
1653 .get_regs
= amd8111e_get_regs
,
1654 .get_settings
= amd8111e_get_settings
,
1655 .set_settings
= amd8111e_set_settings
,
1656 .nway_reset
= amd8111e_nway_reset
,
1657 .get_link
= amd8111e_get_link
,
1658 .get_wol
= amd8111e_get_wol
,
1659 .set_wol
= amd8111e_set_wol
,
1663 This function handles all the ethtool ioctls. It gives driver info, gets/sets driver speed, gets memory mapped register values, forces auto negotiation, sets/gets WOL options for ethtool application.
1666 static int amd8111e_ioctl(struct net_device
* dev
, struct ifreq
*ifr
, int cmd
)
1668 struct mii_ioctl_data
*data
= if_mii(ifr
);
1669 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1673 if (!capable(CAP_NET_ADMIN
))
1678 data
->phy_id
= lp
->ext_phy_addr
;
1683 spin_lock_irq(&lp
->lock
);
1684 err
= amd8111e_read_phy(lp
, data
->phy_id
,
1685 data
->reg_num
& PHY_REG_ADDR_MASK
, &mii_regval
);
1686 spin_unlock_irq(&lp
->lock
);
1688 data
->val_out
= mii_regval
;
1693 spin_lock_irq(&lp
->lock
);
1694 err
= amd8111e_write_phy(lp
, data
->phy_id
,
1695 data
->reg_num
& PHY_REG_ADDR_MASK
, data
->val_in
);
1696 spin_unlock_irq(&lp
->lock
);
1706 static int amd8111e_set_mac_address(struct net_device
*dev
, void *p
)
1708 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1710 struct sockaddr
*addr
= p
;
1712 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1713 spin_lock_irq(&lp
->lock
);
1714 /* Setting the MAC address to the device */
1715 for(i
= 0; i
< ETH_ADDR_LEN
; i
++)
1716 writeb( dev
->dev_addr
[i
], lp
->mmio
+ PADR
+ i
);
1718 spin_unlock_irq(&lp
->lock
);
1724 This function changes the mtu of the device. It restarts the device to initialize the descriptor with new receive buffers.
1726 static int amd8111e_change_mtu(struct net_device
*dev
, int new_mtu
)
1728 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1731 if ((new_mtu
< AMD8111E_MIN_MTU
) || (new_mtu
> AMD8111E_MAX_MTU
))
1734 if (!netif_running(dev
)) {
1735 /* new_mtu will be used
1736 when device starts netxt time */
1741 spin_lock_irq(&lp
->lock
);
1744 writel(RUN
, lp
->mmio
+ CMD0
);
1748 err
= amd8111e_restart(dev
);
1749 spin_unlock_irq(&lp
->lock
);
1751 netif_start_queue(dev
);
1755 #if AMD8111E_VLAN_TAG_USED
1756 static void amd8111e_vlan_rx_register(struct net_device
*dev
, struct vlan_group
*grp
)
1758 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1759 spin_lock_irq(&lp
->lock
);
1761 spin_unlock_irq(&lp
->lock
);
1764 static void amd8111e_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
1766 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1767 spin_lock_irq(&lp
->lock
);
1769 lp
->vlgrp
->vlan_devices
[vid
] = NULL
;
1770 spin_unlock_irq(&lp
->lock
);
1773 static int amd8111e_enable_magicpkt(struct amd8111e_priv
* lp
)
1775 writel( VAL1
|MPPLBA
, lp
->mmio
+ CMD3
);
1776 writel( VAL0
|MPEN_SW
, lp
->mmio
+ CMD7
);
1778 /* To eliminate PCI posting bug */
1779 readl(lp
->mmio
+ CMD7
);
1783 static int amd8111e_enable_link_change(struct amd8111e_priv
* lp
)
1786 /* Adapter is already stoped/suspended/interrupt-disabled */
1787 writel(VAL0
|LCMODE_SW
,lp
->mmio
+ CMD7
);
1789 /* To eliminate PCI posting bug */
1790 readl(lp
->mmio
+ CMD7
);
1793 /* This function is called when a packet transmission fails to complete within a resonable period, on the assumption that an interrupts have been failed or the interface is locked up. This function will reinitialize the hardware */
1795 static void amd8111e_tx_timeout(struct net_device
*dev
)
1797 struct amd8111e_priv
* lp
= netdev_priv(dev
);
1800 printk(KERN_ERR
"%s: transmit timed out, resetting\n",
1802 spin_lock_irq(&lp
->lock
);
1803 err
= amd8111e_restart(dev
);
1804 spin_unlock_irq(&lp
->lock
);
1806 netif_wake_queue(dev
);
1808 static int amd8111e_suspend(struct pci_dev
*pci_dev
, pm_message_t state
)
1810 struct net_device
*dev
= pci_get_drvdata(pci_dev
);
1811 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1813 if (!netif_running(dev
))
1816 /* disable the interrupt */
1817 spin_lock_irq(&lp
->lock
);
1818 amd8111e_disable_interrupt(lp
);
1819 spin_unlock_irq(&lp
->lock
);
1821 netif_device_detach(dev
);
1824 spin_lock_irq(&lp
->lock
);
1825 if(lp
->options
& OPTION_DYN_IPG_ENABLE
)
1826 del_timer_sync(&lp
->ipg_data
.ipg_timer
);
1827 amd8111e_stop_chip(lp
);
1828 spin_unlock_irq(&lp
->lock
);
1830 if(lp
->options
& OPTION_WOL_ENABLE
){
1832 if(lp
->options
& OPTION_WAKE_MAGIC_ENABLE
)
1833 amd8111e_enable_magicpkt(lp
);
1834 if(lp
->options
& OPTION_WAKE_PHY_ENABLE
)
1835 amd8111e_enable_link_change(lp
);
1837 pci_enable_wake(pci_dev
, PCI_D3hot
, 1);
1838 pci_enable_wake(pci_dev
, PCI_D3cold
, 1);
1842 pci_enable_wake(pci_dev
, PCI_D3hot
, 0);
1843 pci_enable_wake(pci_dev
, PCI_D3cold
, 0);
1846 pci_save_state(pci_dev
);
1847 pci_set_power_state(pci_dev
, PCI_D3hot
);
1851 static int amd8111e_resume(struct pci_dev
*pci_dev
)
1853 struct net_device
*dev
= pci_get_drvdata(pci_dev
);
1854 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1856 if (!netif_running(dev
))
1859 pci_set_power_state(pci_dev
, PCI_D0
);
1860 pci_restore_state(pci_dev
);
1862 pci_enable_wake(pci_dev
, PCI_D3hot
, 0);
1863 pci_enable_wake(pci_dev
, PCI_D3cold
, 0); /* D3 cold */
1865 netif_device_attach(dev
);
1867 spin_lock_irq(&lp
->lock
);
1868 amd8111e_restart(dev
);
1869 /* Restart ipg timer */
1870 if(lp
->options
& OPTION_DYN_IPG_ENABLE
)
1871 mod_timer(&lp
->ipg_data
.ipg_timer
,
1872 jiffies
+ IPG_CONVERGE_JIFFIES
);
1873 spin_unlock_irq(&lp
->lock
);
1879 static void __devexit
amd8111e_remove_one(struct pci_dev
*pdev
)
1881 struct net_device
*dev
= pci_get_drvdata(pdev
);
1883 unregister_netdev(dev
);
1884 iounmap(((struct amd8111e_priv
*)netdev_priv(dev
))->mmio
);
1886 pci_release_regions(pdev
);
1887 pci_disable_device(pdev
);
1888 pci_set_drvdata(pdev
, NULL
);
1891 static void amd8111e_config_ipg(struct net_device
* dev
)
1893 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1894 struct ipg_info
* ipg_data
= &lp
->ipg_data
;
1895 void __iomem
*mmio
= lp
->mmio
;
1896 unsigned int prev_col_cnt
= ipg_data
->col_cnt
;
1897 unsigned int total_col_cnt
;
1898 unsigned int tmp_ipg
;
1900 if(lp
->link_config
.duplex
== DUPLEX_FULL
){
1901 ipg_data
->ipg
= DEFAULT_IPG
;
1905 if(ipg_data
->ipg_state
== SSTATE
){
1907 if(ipg_data
->timer_tick
== IPG_STABLE_TIME
){
1909 ipg_data
->timer_tick
= 0;
1910 ipg_data
->ipg
= MIN_IPG
- IPG_STEP
;
1911 ipg_data
->current_ipg
= MIN_IPG
;
1912 ipg_data
->diff_col_cnt
= 0xFFFFFFFF;
1913 ipg_data
->ipg_state
= CSTATE
;
1916 ipg_data
->timer_tick
++;
1919 if(ipg_data
->ipg_state
== CSTATE
){
1921 /* Get the current collision count */
1923 total_col_cnt
= ipg_data
->col_cnt
=
1924 amd8111e_read_mib(mmio
, xmt_collisions
);
1926 if ((total_col_cnt
- prev_col_cnt
) <
1927 (ipg_data
->diff_col_cnt
)){
1929 ipg_data
->diff_col_cnt
=
1930 total_col_cnt
- prev_col_cnt
;
1932 ipg_data
->ipg
= ipg_data
->current_ipg
;
1935 ipg_data
->current_ipg
+= IPG_STEP
;
1937 if (ipg_data
->current_ipg
<= MAX_IPG
)
1938 tmp_ipg
= ipg_data
->current_ipg
;
1940 tmp_ipg
= ipg_data
->ipg
;
1941 ipg_data
->ipg_state
= SSTATE
;
1943 writew((u32
)tmp_ipg
, mmio
+ IPG
);
1944 writew((u32
)(tmp_ipg
- IFS1_DELTA
), mmio
+ IFS1
);
1946 mod_timer(&lp
->ipg_data
.ipg_timer
, jiffies
+ IPG_CONVERGE_JIFFIES
);
1951 static void __devinit
amd8111e_probe_ext_phy(struct net_device
* dev
)
1953 struct amd8111e_priv
*lp
= netdev_priv(dev
);
1956 for (i
= 0x1e; i
>= 0; i
--) {
1959 if (amd8111e_read_phy(lp
, i
, MII_PHYSID1
, &id1
))
1961 if (amd8111e_read_phy(lp
, i
, MII_PHYSID2
, &id2
))
1963 lp
->ext_phy_id
= (id1
<< 16) | id2
;
1964 lp
->ext_phy_addr
= i
;
1968 lp
->ext_phy_addr
= 1;
1971 static int __devinit
amd8111e_probe_one(struct pci_dev
*pdev
,
1972 const struct pci_device_id
*ent
)
1975 unsigned long reg_addr
,reg_len
;
1976 struct amd8111e_priv
* lp
;
1977 struct net_device
* dev
;
1979 err
= pci_enable_device(pdev
);
1981 printk(KERN_ERR
"amd8111e: Cannot enable new PCI device,"
1986 if(!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)){
1987 printk(KERN_ERR
"amd8111e: Cannot find PCI base address"
1990 goto err_disable_pdev
;
1993 err
= pci_request_regions(pdev
, MODULE_NAME
);
1995 printk(KERN_ERR
"amd8111e: Cannot obtain PCI resources, "
1997 goto err_disable_pdev
;
2000 pci_set_master(pdev
);
2002 /* Find power-management capability. */
2003 if((pm_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PM
))==0){
2004 printk(KERN_ERR
"amd8111e: No Power Management capability, "
2009 /* Initialize DMA */
2010 if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
) < 0) {
2011 printk(KERN_ERR
"amd8111e: DMA not supported,"
2016 reg_addr
= pci_resource_start(pdev
, 0);
2017 reg_len
= pci_resource_len(pdev
, 0);
2019 dev
= alloc_etherdev(sizeof(struct amd8111e_priv
));
2021 printk(KERN_ERR
"amd8111e: Etherdev alloc failed, exiting.\n");
2026 SET_MODULE_OWNER(dev
);
2027 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2029 #if AMD8111E_VLAN_TAG_USED
2030 dev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
;
2031 dev
->vlan_rx_register
=amd8111e_vlan_rx_register
;
2032 dev
->vlan_rx_kill_vid
= amd8111e_vlan_rx_kill_vid
;
2035 lp
= netdev_priv(dev
);
2037 lp
->amd8111e_net_dev
= dev
;
2038 lp
->pm_cap
= pm_cap
;
2040 spin_lock_init(&lp
->lock
);
2042 lp
->mmio
= ioremap(reg_addr
, reg_len
);
2043 if (lp
->mmio
== 0) {
2044 printk(KERN_ERR
"amd8111e: Cannot map device registers, "
2050 /* Initializing MAC address */
2051 for(i
= 0; i
< ETH_ADDR_LEN
; i
++)
2052 dev
->dev_addr
[i
] =readb(lp
->mmio
+ PADR
+ i
);
2054 /* Setting user defined parametrs */
2055 lp
->ext_phy_option
= speed_duplex
[card_idx
];
2056 if(coalesce
[card_idx
])
2057 lp
->options
|= OPTION_INTR_COAL_ENABLE
;
2058 if(dynamic_ipg
[card_idx
++])
2059 lp
->options
|= OPTION_DYN_IPG_ENABLE
;
2061 /* Initialize driver entry points */
2062 dev
->open
= amd8111e_open
;
2063 dev
->hard_start_xmit
= amd8111e_start_xmit
;
2064 dev
->stop
= amd8111e_close
;
2065 dev
->get_stats
= amd8111e_get_stats
;
2066 dev
->set_multicast_list
= amd8111e_set_multicast_list
;
2067 dev
->set_mac_address
= amd8111e_set_mac_address
;
2068 dev
->do_ioctl
= amd8111e_ioctl
;
2069 dev
->change_mtu
= amd8111e_change_mtu
;
2070 SET_ETHTOOL_OPS(dev
, &ops
);
2071 dev
->irq
=pdev
->irq
;
2072 dev
->tx_timeout
= amd8111e_tx_timeout
;
2073 dev
->watchdog_timeo
= AMD8111E_TX_TIMEOUT
;
2074 #ifdef CONFIG_AMD8111E_NAPI
2075 dev
->poll
= amd8111e_rx_poll
;
2078 #ifdef CONFIG_NET_POLL_CONTROLLER
2079 dev
->poll_controller
= amd8111e_poll
;
2082 #if AMD8111E_VLAN_TAG_USED
2083 dev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
;
2084 dev
->vlan_rx_register
=amd8111e_vlan_rx_register
;
2085 dev
->vlan_rx_kill_vid
= amd8111e_vlan_rx_kill_vid
;
2087 /* Probe the external PHY */
2088 amd8111e_probe_ext_phy(dev
);
2090 /* setting mii default values */
2091 lp
->mii_if
.dev
= dev
;
2092 lp
->mii_if
.mdio_read
= amd8111e_mdio_read
;
2093 lp
->mii_if
.mdio_write
= amd8111e_mdio_write
;
2094 lp
->mii_if
.phy_id
= lp
->ext_phy_addr
;
2096 /* Set receive buffer length and set jumbo option*/
2097 amd8111e_set_rx_buff_len(dev
);
2100 err
= register_netdev(dev
);
2102 printk(KERN_ERR
"amd8111e: Cannot register net device, "
2107 pci_set_drvdata(pdev
, dev
);
2109 /* Initialize software ipg timer */
2110 if(lp
->options
& OPTION_DYN_IPG_ENABLE
){
2111 init_timer(&lp
->ipg_data
.ipg_timer
);
2112 lp
->ipg_data
.ipg_timer
.data
= (unsigned long) dev
;
2113 lp
->ipg_data
.ipg_timer
.function
= (void *)&amd8111e_config_ipg
;
2114 lp
->ipg_data
.ipg_timer
.expires
= jiffies
+
2115 IPG_CONVERGE_JIFFIES
;
2116 lp
->ipg_data
.ipg
= DEFAULT_IPG
;
2117 lp
->ipg_data
.ipg_state
= CSTATE
;
2120 /* display driver and device information */
2122 chip_version
= (readl(lp
->mmio
+ CHIPID
) & 0xf0000000)>>28;
2123 printk(KERN_INFO
"%s: AMD-8111e Driver Version: %s\n", dev
->name
,MODULE_VERS
);
2124 printk(KERN_INFO
"%s: [ Rev %x ] PCI 10/100BaseT Ethernet ", dev
->name
, chip_version
);
2125 for (i
= 0; i
< 6; i
++)
2126 printk("%2.2x%c",dev
->dev_addr
[i
],i
== 5 ? ' ' : ':');
2129 printk(KERN_INFO
"%s: Found MII PHY ID 0x%08x at address 0x%02x\n",
2130 dev
->name
, lp
->ext_phy_id
, lp
->ext_phy_addr
);
2132 printk(KERN_INFO
"%s: Couldn't detect MII PHY, assuming address 0x01\n",
2142 pci_release_regions(pdev
);
2145 pci_disable_device(pdev
);
2146 pci_set_drvdata(pdev
, NULL
);
2151 static struct pci_driver amd8111e_driver
= {
2152 .name
= MODULE_NAME
,
2153 .id_table
= amd8111e_pci_tbl
,
2154 .probe
= amd8111e_probe_one
,
2155 .remove
= __devexit_p(amd8111e_remove_one
),
2156 .suspend
= amd8111e_suspend
,
2157 .resume
= amd8111e_resume
2160 static int __init
amd8111e_init(void)
2162 return pci_module_init(&amd8111e_driver
);
2165 static void __exit
amd8111e_cleanup(void)
2167 pci_unregister_driver(&amd8111e_driver
);
2170 module_init(amd8111e_init
);
2171 module_exit(amd8111e_cleanup
);