72 #include <linux/module.h>
73 #include <linux/kernel.h>
74 #include <linux/types.h>
75 #include <linux/compiler.h>
80 #include <linux/pci.h>
81 #include <linux/netdevice.h>
84 #include <linux/ethtool.h>
85 #include <linux/mii.h>
86 #include <linux/if_vlan.h>
87 #include <linux/ctype.h>
92 #include <asm/byteorder.h>
93 #include <asm/uaccess.h>
95 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
96 #define AMD8111E_VLAN_TAG_USED 1
98 #define AMD8111E_VLAN_TAG_USED 0
102 #define MODULE_NAME "amd8111e"
103 #define MODULE_VERS "3.0.7"
109 MODULE_PARM_DESC(speed_duplex,
"Set device speed and duplex modes, 0: Auto Negotiate, 1: 10Mbps Half Duplex, 2: 10Mbps Full Duplex, 3: 100Mbps Half Duplex, 4: 100Mbps Full Duplex");
111 MODULE_PARM_DESC(coalesce,
"Enable or Disable interrupt coalescing, 1: Enable, 0: Disable");
113 MODULE_PARM_DESC(dynamic_ipg,
"Enable or Disable dynamic IPG, 1: Enable, 0: Disable");
140 }
while (--repeat && (reg_val & PHY_CMD_ACTIVE));
144 *val = reg_val & 0xffff;
155 static int amd8111e_write_phy(
struct amd8111e_priv* lp,
int phy_id,
int reg,
u32 val)
162 while (reg_val & PHY_CMD_ACTIVE)
171 }
while (--repeat && (reg_val & PHY_CMD_ACTIVE));
185 static int amd8111e_mdio_read(
struct net_device *
dev,
int phy_id,
int reg_num)
190 amd8111e_read_phy(lp,phy_id,reg_num,®_val);
198 static void amd8111e_mdio_write(
struct net_device *
dev,
int phy_id,
int reg_num,
int val)
202 amd8111e_write_phy(lp, phy_id, reg_num, val);
250 static int amd8111e_free_skbs(
struct net_device *dev)
268 if(rx_skbuff !=
NULL){
283 static inline void amd8111e_set_rx_buff_len(
struct net_device* dev)
286 unsigned int mtu = dev->
mtu;
303 static int amd8111e_init_ring(
struct net_device *dev)
315 amd8111e_free_skbs(dev);
329 goto err_free_tx_ring;
333 amd8111e_set_rx_buff_len(dev);
341 for(--i; i >= 0 ;i--)
343 goto err_free_rx_ring;
386 unsigned int event_count;
444 static int amd8111e_restart(
struct net_device *dev)
453 if(amd8111e_init_ring(dev))
460 amd8111e_set_ext_phy(dev);
496 #if AMD8111E_VLAN_TAG_USED
523 static void amd8111e_init_hw_default(
struct amd8111e_priv* lp)
526 unsigned int logic_filter[2] ={0,};
600 #if AMD8111E_VLAN_TAG_USED
615 static void amd8111e_disable_interrupt(
struct amd8111e_priv* lp)
668 static int amd8111e_tx(
struct net_device *dev)
681 lp->
tx_ring[tx_index].buff_phy_addr = 0;
698 if (netif_queue_stopped(dev) &&
702 netif_wake_queue (dev);
720 #if AMD8111E_VLAN_TAG_USED
723 int rx_pkt_limit = budget;
731 if (status & OWN_BIT)
755 #if AMD8111E_VLAN_TAG_USED
764 if (pkt_len < min_pkt_len) {
769 if(--rx_pkt_limit < 0)
780 skb_reserve(new_skb, 2);
793 #if AMD8111E_VLAN_TAG_USED
796 __vlan_hwaccel_put_tag(skb, vlan_tag);
806 lp->
rx_ring[rx_index].buff_phy_addr
808 lp->
rx_ring[rx_index].buff_count =
821 }
while(intr0 &
RINT0);
823 if (rx_pkt_limit > 0) {
829 spin_unlock_irqrestore(&lp->
lock, flags);
839 static int amd8111e_link_change(
struct net_device* dev)
881 static int amd8111e_read_mib(
void __iomem *mmio,
u8 MIB_COUNTER)
991 spin_unlock_irqrestore (&lp->
lock, flags);
998 static int amd8111e_calc_coalesce(
struct net_device *dev)
1021 if(rx_pkt_rate < 800){
1032 rx_pkt_size = rx_data_rate/rx_pkt_rate;
1033 if (rx_pkt_size < 128){
1043 else if ( (rx_pkt_size >= 128) && (rx_pkt_size < 512) ){
1052 else if ((rx_pkt_size >= 512) && (rx_pkt_size < 1024)){
1062 else if(rx_pkt_size >= 1024){
1072 if(tx_pkt_rate < 800){
1083 tx_pkt_size = tx_data_rate/tx_pkt_rate;
1084 if (tx_pkt_size < 128){
1095 else if ( (tx_pkt_size >= 128) && (tx_pkt_size < 512) ){
1105 else if ((tx_pkt_size >= 512) && (tx_pkt_size < 1024)){
1115 else if(tx_pkt_size >= 1024){
1116 if (tx_pkt_size >= 1024){
1138 unsigned int intr0, intren0;
1139 unsigned int handled = 1;
1144 spin_lock(&lp->
lock);
1155 if (!(intr0 &
INTR)){
1157 goto err_no_interrupt;
1164 if (intr0 & RINT0) {
1165 if (napi_schedule_prep(&lp->
napi)) {
1170 }
else if (intren0 &
RINTEN0) {
1171 printk(
"************Driver bug! interrupt while in poll\n");
1183 amd8111e_link_change(dev);
1187 amd8111e_calc_coalesce(dev);
1192 spin_unlock(&lp->
lock);
1197 #ifdef CONFIG_NET_POLL_CONTROLLER
1198 static void amd8111e_poll(
struct net_device *dev)
1200 unsigned long flags;
1202 amd8111e_interrupt(0, dev);
1211 static int amd8111e_close(
struct net_device * dev)
1214 netif_stop_queue(dev);
1216 napi_disable(&lp->
napi);
1218 spin_lock_irq(&lp->
lock);
1220 amd8111e_disable_interrupt(lp);
1221 amd8111e_stop_chip(lp);
1232 spin_unlock_irq(&lp->
lock);
1234 amd8111e_free_ring(lp);
1237 amd8111e_get_stats(dev);
1243 static int amd8111e_open(
struct net_device * dev )
1251 napi_enable(&lp->
napi);
1253 spin_lock_irq(&lp->
lock);
1255 amd8111e_init_hw_default(lp);
1257 if(amd8111e_restart(dev)){
1258 spin_unlock_irq(&lp->
lock);
1259 napi_disable(&lp->
napi);
1272 spin_unlock_irq(&lp->
lock);
1274 netif_start_queue(dev);
1281 static int amd8111e_tx_queue_avail(
struct amd8111e_priv* lp )
1299 unsigned long flags;
1308 lp->
tx_ring[tx_index].tx_flags = 0;
1310 #if AMD8111E_VLAN_TAG_USED
1312 lp->
tx_ring[tx_index].tag_ctrl_cmd |=
1314 lp->
tx_ring[tx_index].tag_ctrl_info =
1321 lp->
tx_ring[tx_index].buff_phy_addr =
1326 lp->
tx_ring[tx_index].tx_flags |=
1335 if(amd8111e_tx_queue_avail(lp) < 0){
1336 netif_stop_queue(dev);
1338 spin_unlock_irqrestore(&lp->
lock, flags);
1368 static void amd8111e_set_multicast_list(
struct net_device *dev)
1384 mc_filter[1] = mc_filter[0] = 0xffffffff;
1391 mc_filter[1] = mc_filter[0] = 0;
1400 mc_filter[1] = mc_filter[0] = 0;
1403 mc_filter[bit_num >> 5] |= 1 << (bit_num & 31);
1423 static int amd8111e_get_regs_len(
struct net_device *dev)
1432 amd8111e_read_regs(lp, buf);
1438 spin_lock_irq(&lp->
lock);
1440 spin_unlock_irq(&lp->
lock);
1448 spin_lock_irq(&lp->
lock);
1450 spin_unlock_irq(&lp->
lock);
1454 static int amd8111e_nway_reset(
struct net_device *dev)
1479 spin_lock_irq(&lp->
lock);
1488 spin_unlock_irq(&lp->
lock);
1493 .get_drvinfo = amd8111e_get_drvinfo,
1494 .get_regs_len = amd8111e_get_regs_len,
1495 .get_regs = amd8111e_get_regs,
1496 .get_settings = amd8111e_get_settings,
1497 .set_settings = amd8111e_set_settings,
1498 .nway_reset = amd8111e_nway_reset,
1499 .get_link = amd8111e_get_link,
1500 .get_wol = amd8111e_get_wol,
1501 .set_wol = amd8111e_set_wol,
1522 spin_lock_irq(&lp->
lock);
1523 err = amd8111e_read_phy(lp, data->
phy_id,
1525 spin_unlock_irq(&lp->
lock);
1532 spin_lock_irq(&lp->
lock);
1533 err = amd8111e_write_phy(lp, data->
phy_id,
1535 spin_unlock_irq(&lp->
lock);
1545 static int amd8111e_set_mac_address(
struct net_device *dev,
void *
p)
1552 spin_lock_irq(&lp->
lock);
1557 spin_unlock_irq(&lp->
lock);
1565 static int amd8111e_change_mtu(
struct net_device *dev,
int new_mtu)
1573 if (!netif_running(dev)) {
1580 spin_lock_irq(&lp->
lock);
1587 err = amd8111e_restart(dev);
1588 spin_unlock_irq(&lp->
lock);
1590 netif_start_queue(dev);
1594 static int amd8111e_enable_magicpkt(
struct amd8111e_priv* lp)
1604 static int amd8111e_enable_link_change(
struct amd8111e_priv* lp)
1621 static void amd8111e_tx_timeout(
struct net_device *dev)
1628 spin_lock_irq(&lp->
lock);
1629 err = amd8111e_restart(dev);
1630 spin_unlock_irq(&lp->
lock);
1632 netif_wake_queue(dev);
1636 struct net_device *dev = pci_get_drvdata(pci_dev);
1639 if (!netif_running(dev))
1643 spin_lock_irq(&lp->
lock);
1644 amd8111e_disable_interrupt(lp);
1645 spin_unlock_irq(&lp->
lock);
1650 spin_lock_irq(&lp->
lock);
1653 amd8111e_stop_chip(lp);
1654 spin_unlock_irq(&lp->
lock);
1659 amd8111e_enable_magicpkt(lp);
1661 amd8111e_enable_link_change(lp);
1677 static int amd8111e_resume(
struct pci_dev *pci_dev)
1679 struct net_device *dev = pci_get_drvdata(pci_dev);
1682 if (!netif_running(dev))
1693 spin_lock_irq(&lp->
lock);
1694 amd8111e_restart(dev);
1699 spin_unlock_irq(&lp->
lock);
1705 static void __devexit amd8111e_remove_one(
struct pci_dev *pdev)
1707 struct net_device *dev = pci_get_drvdata(pdev);
1714 pci_set_drvdata(pdev,
NULL);
1717 static void amd8111e_config_ipg(
struct net_device* dev)
1722 unsigned int prev_col_cnt = ipg_data->
col_cnt;
1723 unsigned int total_col_cnt;
1724 unsigned int tmp_ipg;
1749 total_col_cnt = ipg_data->
col_cnt =
1752 if ((total_col_cnt - prev_col_cnt) <
1756 total_col_cnt - prev_col_cnt ;
1766 tmp_ipg = ipg_data->
ipg;
1782 for (i = 0x1e; i >= 0; i--) {
1798 .ndo_open = amd8111e_open,
1799 .ndo_stop = amd8111e_close,
1800 .ndo_start_xmit = amd8111e_start_xmit,
1801 .ndo_tx_timeout = amd8111e_tx_timeout,
1802 .ndo_get_stats = amd8111e_get_stats,
1803 .ndo_set_rx_mode = amd8111e_set_multicast_list,
1805 .ndo_set_mac_address = amd8111e_set_mac_address,
1806 .ndo_do_ioctl = amd8111e_ioctl,
1807 .ndo_change_mtu = amd8111e_change_mtu,
1808 #ifdef CONFIG_NET_POLL_CONTROLLER
1809 .ndo_poll_controller = amd8111e_poll,
1813 static int __devinit amd8111e_probe_one(
struct pci_dev *pdev,
1832 goto err_disable_pdev;
1839 goto err_disable_pdev;
1871 #if AMD8111E_VLAN_TAG_USED
1875 lp = netdev_priv(dev);
1896 if(coalesce[card_idx])
1898 if(dynamic_ipg[card_idx++])
1909 #if AMD8111E_VLAN_TAG_USED
1913 amd8111e_probe_ext_phy(dev);
1917 lp->
mii_if.mdio_read = amd8111e_mdio_read;
1918 lp->
mii_if.mdio_write = amd8111e_mdio_write;
1922 amd8111e_set_rx_buff_len(dev);
1932 pci_set_drvdata(pdev, dev);
1938 lp->
ipg_data.ipg_timer.function = (
void *)&amd8111e_config_ipg;
1956 printk(
KERN_INFO "%s: Couldn't detect MII PHY, assuming address 0x01\n",
1970 pci_set_drvdata(pdev,
NULL);
1977 .id_table = amd8111e_pci_tbl,
1978 .probe = amd8111e_probe_one,
1980 .suspend = amd8111e_suspend,
1981 .resume = amd8111e_resume
1984 static int __init amd8111e_init(
void)
1986 return pci_register_driver(&amd8111e_driver);
1989 static void __exit amd8111e_cleanup(
void)