150 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
154 #include <linux/module.h>
156 #include <linux/kernel.h>
157 #include <linux/types.h>
158 #include <linux/sched.h>
159 #include <linux/slab.h>
162 #include <linux/pci.h>
165 #include <linux/netdevice.h>
167 #include <linux/mii.h>
168 #include <linux/if_vlan.h>
170 #include <linux/ethtool.h>
171 #include <linux/string.h>
173 #include <linux/rtnetlink.h>
174 #include <asm/unaligned.h>
177 #define DRV_NAME "e100"
178 #define DRV_EXT "-NAPI"
179 #define DRV_VERSION "3.5.24-k2"DRV_EXT
180 #define DRV_DESCRIPTION "Intel(R) PRO/100 Network Driver"
181 #define DRV_COPYRIGHT "Copyright(c) 1999-2006 Intel Corporation"
183 #define E100_WATCHDOG_PERIOD (2 * HZ)
184 #define E100_NAPI_WEIGHT 16
186 #define FIRMWARE_D101M "e100/d101m_ucode.bin"
187 #define FIRMWARE_D101S "e100/d101s_ucode.bin"
188 #define FIRMWARE_D102E "e100/d102e_ucode.bin"
198 static int debug = 3;
199 static int eeprom_bad_csum_allow = 0;
200 static int use_io = 0;
208 #define INTEL_8255X_ETHERNET_DEVICE(device_id, ich) {\
209 PCI_VENDOR_ID_INTEL, device_id, PCI_ANY_ID, PCI_ANY_ID, \
210 PCI_CLASS_NETWORK_ETHERNET << 8, 0xFFFF00, ich }
450 #if defined(__BIG_ENDIAN_BITFIELD)
457 u8 X(
X(rx_fifo_limit:4, tx_fifo_limit:3),
pad1:1);
459 u8 X(
X(
X(
X(mwi_enable:1, type_enable:1), read_align_enable:1),
460 term_write_cache_line:1),
pad3:4);
461 u8 X(rx_dma_max_count:7,
pad4:1);
462 u8 X(tx_dma_max_count:7, dma_max_count_enable:1);
463 u8 X(
X(
X(
X(
X(
X(
X(late_scb_update:1, direct_rx_dma:1),
464 tno_intr:1), cna_intr:1), standard_tcb:1), standard_stat_counter:1),
465 rx_save_overruns : 1), rx_save_bad_frames : 1);
466 u8 X(
X(
X(
X(
X(rx_discard_short_frames:1, tx_underrun_retry:2),
467 pad7:2), rx_extended_rfd:1), tx_two_frames_in_fifo:1),
469 u8 X(
X(mii_mode:1, pad8:6), csma_disabled:1);
470 u8 X(
X(
X(
X(
X(rx_tcpudp_checksum:1, pad9:3), vlan_arp_tco:1),
471 link_status_wake:1), arp_wake:1), mcmatch_wake:1);
472 u8 X(
X(
X(pad10:3, no_source_addr_insertion:1), preamble_length:2),
474 u8 X(linear_priority:3, pad11:5);
475 u8 X(
X(linear_priority_mode:1, pad12:3),
ifs:4);
478 u8 X(
X(
X(
X(
X(
X(
X(promiscuous_mode:1, broadcast_disabled:1),
479 wait_after_win:1), pad15_1:1), ignore_ul_bit:1), crc_16_bit:1),
480 pad15_2:1), crs_or_cdt:1);
483 u8 X(
X(
X(
X(
X(rx_stripping:1, tx_padding:1), rx_crc_transfer:1),
484 rx_long_ok:1), fc_priority_threshold:3), pad18:1);
485 u8 X(
X(
X(
X(
X(
X(
X(addr_wake:1, magic_packet_disable:1),
486 fc_disable:1), fc_restop:1), fc_restart:1), fc_reject:1),
487 full_duplex_force:1), full_duplex_pin:1);
488 u8 X(
X(
X(pad20_1:5, fc_priority_location:1), multi_ia:1), pad20_2:1);
489 u8 X(
X(pad21_1:3, multicast_all:1), pad21_2:4);
490 u8 X(
X(rx_d102_mode:1, rx_vlan_drop:1), pad22:6);
494 #define E100_MAX_MULTICAST_ADDRS 64
501 #define UCODE_SIZE 134
573 struct rx *rx_to_use;
574 struct rx *rx_to_clean;
575 struct rfd blank_rfd;
582 unsigned int cbs_avail;
585 struct cb *cb_to_use;
586 struct cb *cb_to_send;
587 struct cb *cb_to_clean;
593 promiscuous = (1 << 1),
594 multicast_all = (1 << 2),
595 wol_magic = (1 << 3),
596 ich_10h_workaround = (1 << 4),
610 struct pci_pool *cbs_pool;
617 u32 tx_single_collisions;
618 u32 tx_multiple_collisions;
623 u32 rx_fc_unsupported;
625 u32 rx_short_frame_errors;
626 u32 rx_over_length_errors;
634 static inline void e100_write_flush(
struct nic *nic)
641 static void e100_enable_irq(
struct nic *nic)
647 e100_write_flush(nic);
648 spin_unlock_irqrestore(&nic->cmd_lock, flags);
651 static void e100_disable_irq(
struct nic *nic)
657 e100_write_flush(nic);
658 spin_unlock_irqrestore(&nic->cmd_lock, flags);
661 static void e100_hw_reset(
struct nic *nic)
666 e100_write_flush(nic);
udelay(20);
670 e100_write_flush(nic);
udelay(20);
673 e100_disable_irq(nic);
676 static int e100_self_test(
struct nic *nic)
683 nic->mem->selftest.signature = 0;
684 nic->mem->selftest.result = 0xFFFFFFFF;
687 e100_write_flush(nic);
692 e100_disable_irq(nic);
695 if (nic->mem->selftest.result != 0) {
697 "Self-test failed: result=0x%08X\n",
698 nic->mem->selftest.result);
701 if (nic->mem->selftest.signature == 0) {
702 netif_err(nic,
hw, nic->netdev,
"Self-test failed: timed out\n");
711 u32 cmd_addr_data[3];
716 cmd_addr_data[0] =
op_ewen << (addr_len - 2);
717 cmd_addr_data[1] = (((
op_write << addr_len) | addr) << 16) |
719 cmd_addr_data[2] =
op_ewds << (addr_len - 2);
722 for (j = 0; j < 3; j++) {
726 e100_write_flush(nic);
udelay(4);
728 for (i = 31; i >= 0; i--) {
729 ctrl = (cmd_addr_data[
j] & (1 <<
i)) ?
731 iowrite8(ctrl, &nic->csr->eeprom_ctrl_lo);
732 e100_write_flush(nic);
udelay(4);
735 e100_write_flush(nic);
udelay(4);
741 iowrite8(0, &nic->csr->eeprom_ctrl_lo);
742 e100_write_flush(nic);
udelay(4);
747 static __le16 e100_eeprom_read(
struct nic *nic,
u16 *addr_len,
u16 addr)
754 cmd_addr_data = ((
op_read << *addr_len) | addr) << 16;
758 e100_write_flush(nic);
udelay(4);
761 for (i = 31; i >= 0; i--) {
763 iowrite8(ctrl, &nic->csr->eeprom_ctrl_lo);
764 e100_write_flush(nic);
udelay(4);
767 e100_write_flush(nic);
udelay(4);
771 ctrl =
ioread8(&nic->csr->eeprom_ctrl_lo);
772 if (!(ctrl &
eedo) && i > 16) {
773 *addr_len -= (i - 16);
777 data = (data << 1) | (ctrl & eedo ? 1 : 0);
781 iowrite8(0, &nic->csr->eeprom_ctrl_lo);
782 e100_write_flush(nic);
udelay(4);
788 static int e100_eeprom_load(
struct nic *nic)
793 e100_eeprom_read(nic, &addr_len, 0);
794 nic->eeprom_wc = 1 << addr_len;
796 for (addr = 0; addr < nic->eeprom_wc; addr++) {
797 nic->eeprom[
addr] = e100_eeprom_read(nic, &addr_len, addr);
798 if (addr < nic->eeprom_wc - 1)
805 netif_err(nic, probe, nic->netdev,
"EEPROM corrupted\n");
806 if (!eeprom_bad_csum_allow)
819 e100_eeprom_read(nic, &addr_len, 0);
820 nic->eeprom_wc = 1 << addr_len;
822 if (start + count >= nic->eeprom_wc)
825 for (addr = start; addr < start +
count; addr++)
826 e100_eeprom_write(nic, addr_len, addr, nic->eeprom[addr]);
830 for (addr = 0; addr < nic->eeprom_wc - 1; addr++)
833 e100_eeprom_write(nic, addr_len, nic->eeprom_wc - 1,
834 nic->eeprom[nic->eeprom_wc - 1]);
839 #define E100_WAIT_SCB_TIMEOUT 20000
840 #define E100_WAIT_SCB_FAST 20
857 if (
unlikely(i == E100_WAIT_SCB_TIMEOUT)) {
863 iowrite32(dma_addr, &nic->csr->scb.gen_ptr);
864 iowrite8(cmd, &nic->csr->scb.cmd_lo);
867 spin_unlock_irqrestore(&nic->cmd_lock, flags);
872 static int e100_exec_cb(
struct nic *nic,
struct sk_buff *
skb,
873 void (*cb_prepare)(
struct nic *,
struct cb *,
struct sk_buff *))
887 nic->cb_to_use = cb->
next;
894 cb_prepare(nic, cb, skb);
902 while (nic->cb_to_send != nic->cb_to_use) {
903 if (
unlikely(e100_exec_cmd(nic, nic->cuc_cmd,
904 nic->cb_to_send->dma_addr))) {
917 nic->cb_to_send = nic->cb_to_send->next;
922 spin_unlock_irqrestore(&nic->cb_lock, flags);
927 static int mdio_read(
struct net_device *netdev,
int addr,
int reg)
929 struct nic *nic = netdev_priv(netdev);
930 return nic->mdio_ctrl(nic, addr,
mdi_read, reg, 0);
933 static void mdio_write(
struct net_device *netdev,
int addr,
int reg,
int data)
935 struct nic *nic = netdev_priv(netdev);
937 nic->mdio_ctrl(nic, addr,
mdi_write, reg, data);
941 static u16 mdio_ctrl_hw(
struct nic *nic,
u32 addr,
u32 dir,
u32 reg,
u16 data)
955 for (i = 100;
i; --
i) {
961 netdev_err(nic->netdev,
"e100.mdio_ctrl won't go Ready\n");
962 spin_unlock_irqrestore(&nic->mdio_lock, flags);
965 iowrite32((reg << 16) | (addr << 21) | dir | data, &nic->csr->mdi_ctrl);
967 for (i = 0; i < 100; i++) {
972 spin_unlock_irqrestore(&nic->mdio_lock, flags);
974 "%s:addr=%d, reg=%d, data_in=0x%04X, data_out=0x%04X\n",
976 addr, reg, data, data_out);
977 return (
u16)data_out;
981 static u16 mdio_ctrl_phy_82552_v(
struct nic *nic,
989 u16 advert = mdio_read(nic->netdev, nic->mii.phy_id,
1002 return mdio_ctrl_hw(nic, addr, dir, reg, data);
1011 static u16 mdio_ctrl_phy_mii_emulated(
struct nic *nic,
1037 "%s:addr=%d, reg=%d, data=0x%04X: unimplemented emulation!\n",
1038 dir ==
mdi_read ?
"READ" :
"WRITE",
1046 "%s:addr=%d, reg=%d, data=0x%04X: unimplemented emulation!\n",
1047 dir ==
mdi_read ?
"READ" :
"WRITE",
1053 static inline int e100_phy_supports_mii(
struct nic *nic)
1058 return (nic->mdio_ctrl != mdio_ctrl_phy_mii_emulated);
1061 static void e100_get_defaults(
struct nic *nic)
1063 struct param_range rfds = { .
min = 16, .max = 256, .count = 256 };
1064 struct param_range cbs = { .min = 64, .max = 256, .count = 128 };
1067 nic->mac = (nic->flags & ich) ?
mac_82559_D101M : nic->pdev->revision;
1071 nic->params.rfds = rfds;
1072 nic->params.cbs =
cbs;
1075 nic->tx_threshold = 0xE0;
1082 nic->blank_rfd.command = 0;
1087 nic->mii.phy_id_mask = 0x1F;
1088 nic->mii.reg_num_mask = 0x1F;
1089 nic->mii.dev = nic->netdev;
1090 nic->mii.mdio_read = mdio_read;
1091 nic->mii.mdio_write = mdio_write;
1094 static void e100_configure(
struct nic *nic,
struct cb *cb,
struct sk_buff *skb)
1097 u8 *
c = (
u8 *)config;
1102 memset(config, 0,
sizeof(
struct config));
1104 config->byte_count = 0x16;
1105 config->rx_fifo_limit = 0x8;
1106 config->direct_rx_dma = 0x1;
1107 config->standard_tcb = 0x1;
1108 config->standard_stat_counter = 0x1;
1109 config->rx_discard_short_frames = 0x1;
1110 config->tx_underrun_retry = 0x3;
1111 if (e100_phy_supports_mii(nic))
1112 config->mii_mode = 1;
1113 config->pad10 = 0x6;
1114 config->no_source_addr_insertion = 0x1;
1115 config->preamble_length = 0x2;
1118 config->pad15_1 = 0x1;
1119 config->pad15_2 = 0x1;
1120 config->crs_or_cdt = 0x0;
1122 config->tx_padding = 0x1;
1123 config->fc_priority_threshold = 0x7;
1124 config->pad18 = 0x1;
1125 config->full_duplex_pin = 0x1;
1126 config->pad20_1 = 0x1F;
1127 config->fc_priority_location = 0x1;
1128 config->pad21_1 = 0x5;
1131 config->loopback = nic->loopback;
1133 if (nic->mii.force_media && nic->mii.full_duplex)
1134 config->full_duplex_force = 0x1;
1136 if (nic->flags & promiscuous || nic->loopback) {
1137 config->rx_save_bad_frames = 0x1;
1138 config->rx_discard_short_frames = 0x0;
1139 config->promiscuous_mode = 0x1;
1143 config->rx_crc_transfer = 0x1;
1145 if (nic->flags & multicast_all)
1146 config->multicast_all = 0x1;
1149 if (netif_running(nic->netdev) || !(nic->flags & wol_magic))
1150 config->magic_packet_disable = 0x1;
1153 config->fc_disable = 0x1;
1154 config->mwi_enable = 0x1;
1155 config->standard_tcb = 0x0;
1156 config->rx_long_ok = 0x1;
1158 config->tno_intr = 0x1;
1161 config->byte_count = 0x20;
1162 config->rx_d102_mode = 0x1;
1165 config->standard_stat_counter = 0x0;
1170 config->rx_save_overruns = 0x1;
1171 config->rx_save_bad_frames = 0x1;
1172 config->rx_discard_short_frames = 0x0;
1176 "[00-07]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1177 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
1179 "[08-15]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1180 c[8], c[9], c[10], c[11], c[12], c[13], c[14], c[15]);
1182 "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1183 c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
1241 #define BUNDLESMALL 1
1242 #define BUNDLEMAX (u16)6
1243 #define INTDELAY (u16)1536
1246 static const struct firmware *e100_request_firmware(
struct nic *nic)
1252 bool required =
false;
1255 if (nic->flags & ich)
1293 "Failed to load firmware \"%s\": %d\n",
1295 return ERR_PTR(err);
1298 "CPUSaver disabled. Needs \"%s\": %d\n",
1308 "Firmware \"%s\" has wrong size %zu\n",
1322 "\"%s\" has bogus offset values (0x%x,0x%x,0x%x)\n",
1323 fw_name, timer, bundle, min_size);
1334 static void e100_setup_ucode(
struct nic *nic,
struct cb *cb,
1363 static inline int e100_load_ucode_wait(
struct nic *nic)
1367 struct cb *cb = nic->cb_to_clean;
1369 fw = e100_request_firmware(nic);
1371 if (!fw || IS_ERR(fw))
1374 if ((err = e100_exec_cb(nic, (
void *)fw, e100_setup_ucode)))
1376 "ucode cmd failed with error %d\n", err);
1382 e100_write_flush(nic);
1392 iowrite8(~0, &nic->csr->scb.stat_ack);
1396 netif_err(nic, probe, nic->netdev,
"ucode load failed\n");
1403 static void e100_setup_iaaddr(
struct nic *nic,
struct cb *cb,
1410 static void e100_dump(
struct nic *nic,
struct cb *cb,
struct sk_buff *skb)
1417 static int e100_phy_check_without_mii(
struct nic *nic)
1435 "found MII-less i82503 or 80c24 or other PHY\n");
1437 nic->mdio_ctrl = mdio_ctrl_phy_mii_emulated;
1438 nic->mii.phy_id = 0;
1453 #define NCONFIG_AUTO_SWITCH 0x0080
1454 #define MII_NSC_CONG MII_RESV1
1455 #define NSC_CONG_ENABLE 0x0100
1456 #define NSC_CONG_TXREADY 0x0400
1457 #define ADVERTISE_FC_SUPPORTED 0x0400
1458 static int e100_phy_init(
struct nic *nic)
1462 u16 bmcr,
stat, id_lo, id_hi, cong;
1465 for (addr = 0; addr < 32; addr++) {
1466 nic->mii.phy_id = (addr == 0) ? 1 : (addr == 1) ? 0 :
addr;
1467 bmcr = mdio_read(netdev, nic->mii.phy_id,
MII_BMCR);
1468 stat = mdio_read(netdev, nic->mii.phy_id,
MII_BMSR);
1469 stat = mdio_read(netdev, nic->mii.phy_id,
MII_BMSR);
1470 if (!((bmcr == 0xFFFF) || ((stat == 0) && (bmcr == 0))))
1478 if (e100_phy_check_without_mii(nic))
1483 "Failed to locate any known PHY, aborting\n");
1488 "phy_addr = %d\n", nic->mii.phy_id);
1491 id_lo = mdio_read(netdev, nic->mii.phy_id,
MII_PHYSID1);
1492 id_hi = mdio_read(netdev, nic->mii.phy_id,
MII_PHYSID2);
1493 nic->phy = (
u32)id_hi << 16 | (
u32)id_lo;
1495 "phy ID = 0x%08X\n", nic->phy);
1498 for (addr = 0; addr < 32; addr++) {
1499 if (addr != nic->mii.phy_id) {
1502 bmcr = mdio_read(netdev, addr,
MII_BMCR);
1513 mdio_write(netdev, nic->mii.phy_id,
MII_BMCR,
1517 #define NCS_PHY_MODEL_MASK 0xFFF0FFFF
1520 cong = mdio_read(netdev, nic->mii.phy_id,
MII_NSC_CONG);
1523 mdio_write(netdev, nic->mii.phy_id,
MII_NSC_CONG, cong);
1530 nic->mdio_ctrl = mdio_ctrl_phy_82552_v;
1537 bmcr = mdio_read(netdev, nic->mii.phy_id,
MII_BMCR);
1539 mdio_write(netdev, nic->mii.phy_id,
MII_BMCR, bmcr);
1540 }
else if ((nic->mac >=
mac_82550_D102) || ((nic->flags & ich) &&
1541 (mdio_read(netdev, nic->mii.phy_id,
MII_TPISTATUS) & 0x8000) &&
1551 static int e100_hw_init(
struct nic *nic)
1557 netif_err(nic,
hw, nic->netdev,
"e100_hw_init\n");
1561 if ((err = e100_phy_init(nic)))
1567 if ((err = e100_load_ucode_wait(nic)))
1569 if ((err = e100_exec_cb(nic,
NULL, e100_configure)))
1571 if ((err = e100_exec_cb(nic,
NULL, e100_setup_iaaddr)))
1579 e100_disable_irq(nic);
1584 static void e100_multi(
struct nic *nic,
struct cb *cb,
struct sk_buff *skb)
1601 static void e100_set_multicast_list(
struct net_device *netdev)
1603 struct nic *nic = netdev_priv(netdev);
1606 "mc_count=%d, flags=0x%04X\n",
1610 nic->flags |= promiscuous;
1612 nic->flags &= ~promiscuous;
1616 nic->flags |= multicast_all;
1618 nic->flags &= ~multicast_all;
1620 e100_exec_cb(nic,
NULL, e100_configure);
1621 e100_exec_cb(nic,
NULL, e100_multi);
1624 static void e100_update_stats(
struct nic *nic)
1628 struct stats *
s = &nic->mem->stats;
1648 nic->rx_short_frame_errors +=
1651 nic->rx_over_length_errors;
1662 nic->tx_single_collisions +=
1664 nic->tx_multiple_collisions +=
1669 nic->rx_fc_unsupported +=
1672 nic->tx_tco_frames +=
1674 nic->rx_tco_frames +=
1683 "exec cuc_dump_reset failed\n");
1686 static void e100_adjust_adaptive_ifs(
struct nic *nic,
int speed,
int duplex)
1695 if ((nic->tx_frames / 32 < nic->tx_collisions) &&
1696 (nic->tx_frames > min_frames)) {
1697 if (nic->adaptive_ifs < 60)
1698 nic->adaptive_ifs += 5;
1699 }
else if (nic->tx_frames < min_frames) {
1700 if (nic->adaptive_ifs >= 5)
1701 nic->adaptive_ifs -= 5;
1703 if (nic->adaptive_ifs != prev)
1704 e100_exec_cb(nic,
NULL, e100_configure);
1708 static void e100_watchdog(
unsigned long data)
1710 struct nic *nic = (
struct nic *)data;
1715 "right now = %ld\n", jiffies);
1720 speed = ethtool_cmd_speed(&cmd);
1722 if (
mii_link_ok(&nic->mii) && !netif_carrier_ok(nic->netdev)) {
1723 netdev_info(nic->netdev,
"NIC Link is Up %u Mbps %s Duplex\n",
1726 }
else if (!
mii_link_ok(&nic->mii) && netif_carrier_ok(nic->netdev)) {
1727 netdev_info(nic->netdev,
"NIC Link is Down\n");
1737 spin_lock_irq(&nic->cmd_lock);
1739 e100_write_flush(nic);
1740 spin_unlock_irq(&nic->cmd_lock);
1742 e100_update_stats(nic);
1743 e100_adjust_adaptive_ifs(nic, speed, cmd.
duplex);
1747 e100_set_multicast_list(nic->netdev);
1751 nic->flags |= ich_10h_workaround;
1753 nic->flags &= ~ich_10h_workaround;
1759 static void e100_xmit_prepare(
struct nic *nic,
struct cb *cb,
1762 cb->
command = nic->tx_command;
1774 if ((nic->cbs_avail & ~15) == nic->cbs_avail)
1777 cb->
u.
tcb.tcb_byte_count = 0;
1778 cb->
u.
tcb.threshold = nic->tx_threshold;
1779 cb->
u.
tcb.tbd_count = 1;
1784 skb_tx_timestamp(skb);
1790 struct nic *nic = netdev_priv(netdev);
1793 if (nic->flags & ich_10h_workaround) {
1797 if (e100_exec_cmd(nic,
cuc_nop, 0))
1799 "exec cuc_nop failed\n");
1803 err = e100_exec_cb(nic, skb, e100_xmit_prepare);
1809 "No space for CB\n");
1810 netif_stop_queue(netdev);
1815 "Out of Tx resources, returning skb\n");
1816 netif_stop_queue(netdev);
1823 static int e100_tx_clean(
struct nic *nic)
1829 spin_lock(&nic->cb_lock);
1832 for (cb = nic->cb_to_clean;
1834 cb = nic->cb_to_clean = cb->
next) {
1837 "cb[%d]->status = 0x%04X\n",
1838 (
int)(((
void*)cb - (
void*)nic->cbs)/
sizeof(
struct cb)),
1842 dev->
stats.tx_packets++;
1843 dev->
stats.tx_bytes += cb->
skb->len;
1845 pci_unmap_single(nic->pdev,
1857 spin_unlock(&nic->cb_lock);
1860 if (
unlikely(tx_cleaned && netif_queue_stopped(nic->netdev)))
1861 netif_wake_queue(nic->netdev);
1866 static void e100_clean_cbs(
struct nic *nic)
1869 while (nic->cbs_avail != nic->params.cbs.count) {
1870 struct cb *cb = nic->cb_to_clean;
1872 pci_unmap_single(nic->pdev,
1876 dev_kfree_skb(cb->
skb);
1878 nic->cb_to_clean = nic->cb_to_clean->next;
1881 pci_pool_free(nic->cbs_pool, nic->cbs, nic->cbs_dma_addr);
1886 nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean =
1890 static int e100_alloc_cbs(
struct nic *nic)
1893 unsigned int i, count = nic->params.cbs.count;
1896 nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean =
NULL;
1899 nic->cbs = pci_pool_alloc(nic->cbs_pool,
GFP_KERNEL,
1900 &nic->cbs_dma_addr);
1903 memset(nic->cbs, 0, count *
sizeof(
struct cb));
1905 for (cb = nic->cbs, i = 0; i < count; cb++, i++) {
1906 cb->
next = (i + 1 <
count) ? cb + 1 : nic->cbs;
1907 cb->
prev = (i == 0) ? nic->cbs + count - 1 : cb - 1;
1909 cb->
dma_addr = nic->cbs_dma_addr + i *
sizeof(
struct cb);
1911 ((i+1) % count) *
sizeof(
struct cb));
1914 nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = nic->cbs;
1915 nic->cbs_avail =
count;
1920 static inline void e100_start_receiver(
struct nic *nic,
struct rx *
rx)
1922 if (!nic->rxs)
return;
1926 if (!rx) rx = nic->rxs;
1935 #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
1936 static int e100_rx_alloc_skb(
struct nic *nic,
struct rx *rx)
1938 if (!(rx->
skb = netdev_alloc_skb_ip_align(nic->netdev,
RFD_BUF_LEN)))
1942 skb_copy_to_linear_data(rx->
skb, &nic->blank_rfd,
sizeof(
struct rfd));
1943 rx->
dma_addr = pci_map_single(nic->pdev, rx->
skb->data,
1946 if (pci_dma_mapping_error(nic->pdev, rx->
dma_addr)) {
1956 if (rx->
prev->skb) {
1957 struct rfd *prev_rfd = (
struct rfd *)rx->
prev->skb->data;
1959 pci_dma_sync_single_for_device(nic->pdev, rx->
prev->dma_addr,
1966 static int e100_rx_indicate(
struct nic *nic,
struct rx *rx,
1967 unsigned int *work_done,
unsigned int work_to_do)
1975 if (
unlikely(work_done && *work_done >= work_to_do))
1979 pci_dma_sync_single_for_cpu(nic->pdev, rx->
dma_addr,
1984 "status=0x%04X\n", rfd_status);
1999 pci_dma_sync_single_for_device(nic->pdev, rx->
dma_addr,
2013 pci_unmap_single(nic->pdev, rx->
dma_addr,
2030 skb_reserve(skb,
sizeof(
struct rfd));
2040 nic->rx_over_length_errors++;
2049 nic->rx_over_length_errors++;
2053 dev->
stats.rx_packets++;
2065 static void e100_rx_clean(
struct nic *nic,
unsigned int *work_done,
2066 unsigned int work_to_do)
2069 int restart_required = 0, err = 0;
2070 struct rx *old_before_last_rx, *new_before_last_rx;
2071 struct rfd *old_before_last_rfd, *new_before_last_rfd;
2074 for (rx = nic->rx_to_clean; rx->
skb; rx = nic->rx_to_clean = rx->
next) {
2075 err = e100_rx_indicate(nic, rx, work_done, work_to_do);
2089 restart_required = 1;
2091 old_before_last_rx = nic->rx_to_use->prev->prev;
2092 old_before_last_rfd = (
struct rfd *)old_before_last_rx->
skb->data;
2095 for (rx = nic->rx_to_use; !rx->
skb; rx = nic->rx_to_use = rx->
next) {
2096 if (
unlikely(e100_rx_alloc_skb(nic, rx)))
2100 new_before_last_rx = nic->rx_to_use->prev->prev;
2101 if (new_before_last_rx != old_before_last_rx) {
2111 new_before_last_rfd =
2112 (
struct rfd *)new_before_last_rx->
skb->data;
2113 new_before_last_rfd->
size = 0;
2115 pci_dma_sync_single_for_device(nic->pdev,
2116 new_before_last_rx->
dma_addr,
sizeof(
struct rfd),
2123 pci_dma_sync_single_for_device(nic->pdev,
2124 old_before_last_rx->
dma_addr,
sizeof(
struct rfd),
2128 pci_dma_sync_single_for_device(nic->pdev,
2129 old_before_last_rx->
dma_addr,
sizeof(
struct rfd),
2133 if (restart_required) {
2136 e100_start_receiver(nic, nic->rx_to_clean);
2142 static void e100_rx_clean_list(
struct nic *nic)
2145 unsigned int i, count = nic->params.rfds.count;
2150 for (rx = nic->rxs, i = 0; i < count; rx++, i++) {
2152 pci_unmap_single(nic->pdev, rx->
dma_addr,
2154 dev_kfree_skb(rx->
skb);
2161 nic->rx_to_use = nic->rx_to_clean =
NULL;
2164 static int e100_rx_alloc_list(
struct nic *nic)
2167 unsigned int i, count = nic->params.rfds.count;
2168 struct rfd *before_last;
2170 nic->rx_to_use = nic->rx_to_clean =
NULL;
2173 if (!(nic->rxs = kcalloc(count,
sizeof(
struct rx),
GFP_ATOMIC)))
2176 for (rx = nic->rxs, i = 0; i < count; rx++, i++) {
2177 rx->
next = (i + 1 <
count) ? rx + 1 : nic->rxs;
2178 rx->
prev = (i == 0) ? nic->rxs + count - 1 : rx - 1;
2179 if (e100_rx_alloc_skb(nic, rx)) {
2180 e100_rx_clean_list(nic);
2191 rx = nic->rxs->prev->prev;
2192 before_last = (
struct rfd *)rx->
skb->data;
2194 before_last->
size = 0;
2195 pci_dma_sync_single_for_device(nic->pdev, rx->
dma_addr,
2198 nic->rx_to_use = nic->rx_to_clean = nic->rxs;
2207 struct nic *nic = netdev_priv(netdev);
2208 u8 stat_ack =
ioread8(&nic->csr->scb.stat_ack);
2211 "stat_ack = 0x%02X\n", stat_ack);
2218 iowrite8(stat_ack, &nic->csr->scb.stat_ack);
2224 if (
likely(napi_schedule_prep(&nic->napi))) {
2225 e100_disable_irq(nic);
2234 struct nic *nic =
container_of(napi,
struct nic, napi);
2235 unsigned int work_done = 0;
2237 e100_rx_clean(nic, &work_done, budget);
2241 if (work_done < budget) {
2243 e100_enable_irq(nic);
2249 #ifdef CONFIG_NET_POLL_CONTROLLER
2250 static void e100_netpoll(
struct net_device *netdev)
2252 struct nic *nic = netdev_priv(netdev);
2254 e100_disable_irq(nic);
2255 e100_intr(nic->pdev->irq, netdev);
2257 e100_enable_irq(nic);
2261 static int e100_set_mac_address(
struct net_device *netdev,
void *
p)
2263 struct nic *nic = netdev_priv(netdev);
2266 if (!is_valid_ether_addr(addr->
sa_data))
2270 e100_exec_cb(nic,
NULL, e100_setup_iaaddr);
2275 static int e100_change_mtu(
struct net_device *netdev,
int new_mtu)
2279 netdev->
mtu = new_mtu;
2283 static int e100_asf(
struct nic *nic)
2286 return (nic->pdev->device >= 0x1050) && (nic->pdev->device <= 0x1057) &&
2292 static int e100_up(
struct nic *nic)
2296 if ((err = e100_rx_alloc_list(nic)))
2298 if ((err = e100_alloc_cbs(nic)))
2299 goto err_rx_clean_list;
2300 if ((err = e100_hw_init(nic)))
2302 e100_set_multicast_list(nic->netdev);
2303 e100_start_receiver(nic,
NULL);
2306 nic->netdev->name, nic->netdev)))
2308 netif_wake_queue(nic->netdev);
2309 napi_enable(&nic->napi);
2312 e100_enable_irq(nic);
2318 e100_clean_cbs(nic);
2320 e100_rx_clean_list(nic);
2324 static void e100_down(
struct nic *nic)
2327 napi_disable(&nic->napi);
2328 netif_stop_queue(nic->netdev);
2330 free_irq(nic->pdev->irq, nic->netdev);
2333 e100_clean_cbs(nic);
2334 e100_rx_clean_list(nic);
2337 static void e100_tx_timeout(
struct net_device *netdev)
2339 struct nic *nic = netdev_priv(netdev);
2348 struct nic *nic =
container_of(work,
struct nic, tx_timeout_task);
2352 "scb.status=0x%02X\n",
ioread8(&nic->csr->scb.status));
2355 if (netif_running(netdev)) {
2356 e100_down(netdev_priv(netdev));
2357 e100_up(netdev_priv(netdev));
2362 static int e100_loopback_test(
struct nic *nic,
enum loopback loopback_mode)
2372 if ((err = e100_rx_alloc_list(nic)))
2374 if ((err = e100_alloc_cbs(nic)))
2378 if (nic->flags & ich && loopback_mode ==
lb_phy)
2381 nic->loopback = loopback_mode;
2382 if ((err = e100_hw_init(nic)))
2383 goto err_loopback_none;
2385 if (loopback_mode ==
lb_phy)
2386 mdio_write(nic->netdev, nic->mii.phy_id,
MII_BMCR,
2389 e100_start_receiver(nic,
NULL);
2391 if (!(skb = netdev_alloc_skb(nic->netdev,
ETH_DATA_LEN))) {
2393 goto err_loopback_none;
2397 e100_xmit_frame(skb, nic->netdev);
2401 pci_dma_sync_single_for_cpu(nic->pdev, nic->rx_to_clean->dma_addr,
2404 if (
memcmp(nic->rx_to_clean->skb->data +
sizeof(
struct rfd),
2409 mdio_write(nic->netdev, nic->mii.phy_id,
MII_BMCR, 0);
2411 e100_clean_cbs(nic);
2414 e100_rx_clean_list(nic);
2418 #define MII_LED_CONTROL 0x1B
2419 #define E100_82552_LED_OVERRIDE 0x19
2420 #define E100_82552_LED_ON 0x000F
2421 #define E100_82552_LED_OFF 0x000A
2425 struct nic *nic = netdev_priv(netdev);
2431 struct nic *nic = netdev_priv(netdev);
2436 e100_exec_cb(nic,
NULL, e100_configure);
2441 static void e100_get_drvinfo(
struct net_device *netdev,
2444 struct nic *nic = netdev_priv(netdev);
2451 #define E100_PHY_REGS 0x1C
2452 static int e100_get_regs_len(
struct net_device *netdev)
2454 struct nic *nic = netdev_priv(netdev);
2458 static void e100_get_regs(
struct net_device *netdev,
2461 struct nic *nic = netdev_priv(netdev);
2465 regs->
version = (1 << 24) | nic->pdev->revision;
2466 buff[0] =
ioread8(&nic->csr->scb.cmd_hi) << 24 |
2467 ioread8(&nic->csr->scb.cmd_lo) << 16 |
2471 mdio_read(netdev, nic->mii.phy_id, i);
2472 memset(nic->mem->dump_buf, 0,
sizeof(nic->mem->dump_buf));
2473 e100_exec_cb(nic,
NULL, e100_dump);
2476 sizeof(nic->mem->dump_buf));
2481 struct nic *nic = netdev_priv(netdev);
2488 struct nic *nic = netdev_priv(netdev);
2491 !device_can_wakeup(&nic->pdev->dev))
2495 nic->flags |= wol_magic;
2497 nic->flags &= ~wol_magic;
2501 e100_exec_cb(nic,
NULL, e100_configure);
2508 struct nic *nic = netdev_priv(netdev);
2509 return nic->msg_enable;
2514 struct nic *nic = netdev_priv(netdev);
2515 nic->msg_enable =
value;
2518 static int e100_nway_reset(
struct net_device *netdev)
2520 struct nic *nic = netdev_priv(netdev);
2526 struct nic *nic = netdev_priv(netdev);
2530 static int e100_get_eeprom_len(
struct net_device *netdev)
2532 struct nic *nic = netdev_priv(netdev);
2533 return nic->eeprom_wc << 1;
2536 #define E100_EEPROM_MAGIC 0x1234
2537 static int e100_get_eeprom(
struct net_device *netdev,
2540 struct nic *nic = netdev_priv(netdev);
2548 static int e100_set_eeprom(
struct net_device *netdev,
2551 struct nic *nic = netdev_priv(netdev);
2558 return e100_eeprom_save(nic, eeprom->
offset >> 1,
2559 (eeprom->
len >> 1) + 1);
2562 static void e100_get_ringparam(
struct net_device *netdev,
2565 struct nic *nic = netdev_priv(netdev);
2575 static int e100_set_ringparam(
struct net_device *netdev,
2578 struct nic *nic = netdev_priv(netdev);
2585 if (netif_running(netdev))
2591 netif_info(nic, drv, nic->netdev,
"Ring Param settings: rx: %d, tx %d\n",
2593 if (netif_running(netdev))
2600 "Link test (on/offline)",
2601 "Eeprom test (on/offline)",
2602 "Self test (offline)",
2603 "Mac loopback (offline)",
2604 "Phy loopback (offline)",
2606 #define E100_TEST_LEN ARRAY_SIZE(e100_gstrings_test)
2608 static void e100_diag_test(
struct net_device *netdev,
2612 struct nic *nic = netdev_priv(netdev);
2617 data[1] = e100_eeprom_load(nic);
2623 if (netif_running(netdev))
2625 data[2] = e100_self_test(nic);
2626 data[3] = e100_loopback_test(nic,
lb_mac);
2627 data[4] = e100_loopback_test(nic,
lb_phy);
2632 if (netif_running(netdev))
2641 static int e100_set_phys_id(
struct net_device *netdev,
2644 struct nic *nic = netdev_priv(netdev);
2672 mdio_write(netdev, nic->mii.phy_id, led_reg, leds);
2677 "rx_packets",
"tx_packets",
"rx_bytes",
"tx_bytes",
"rx_errors",
2678 "tx_errors",
"rx_dropped",
"tx_dropped",
"multicast",
"collisions",
2679 "rx_length_errors",
"rx_over_errors",
"rx_crc_errors",
2680 "rx_frame_errors",
"rx_fifo_errors",
"rx_missed_errors",
2681 "tx_aborted_errors",
"tx_carrier_errors",
"tx_fifo_errors",
2682 "tx_heartbeat_errors",
"tx_window_errors",
2684 "tx_deferred",
"tx_single_collisions",
"tx_multi_collisions",
2685 "tx_flow_control_pause",
"rx_flow_control_pause",
2686 "rx_flow_control_unsupported",
"tx_tco_packets",
"rx_tco_packets",
2687 "rx_short_frame_errors",
"rx_over_length_errors",
2689 #define E100_NET_STATS_LEN 21
2690 #define E100_STATS_LEN ARRAY_SIZE(e100_gstrings_stats)
2692 static int e100_get_sset_count(
struct net_device *netdev,
int sset)
2704 static void e100_get_ethtool_stats(
struct net_device *netdev,
2707 struct nic *nic = netdev_priv(netdev);
2711 data[i] = ((
unsigned long *)&netdev->
stats)[
i];
2713 data[i++] = nic->tx_deferred;
2714 data[i++] = nic->tx_single_collisions;
2715 data[i++] = nic->tx_multiple_collisions;
2716 data[i++] = nic->tx_fc_pause;
2717 data[i++] = nic->rx_fc_pause;
2718 data[i++] = nic->rx_fc_unsupported;
2719 data[i++] = nic->tx_tco_frames;
2720 data[i++] = nic->rx_tco_frames;
2721 data[i++] = nic->rx_short_frame_errors;
2722 data[i++] = nic->rx_over_length_errors;
2725 static void e100_get_strings(
struct net_device *netdev,
u32 stringset,
u8 *data)
2727 switch (stringset) {
2729 memcpy(data, *e100_gstrings_test,
sizeof(e100_gstrings_test));
2732 memcpy(data, *e100_gstrings_stats,
sizeof(e100_gstrings_stats));
2737 static const struct ethtool_ops e100_ethtool_ops = {
2738 .get_settings = e100_get_settings,
2739 .set_settings = e100_set_settings,
2740 .get_drvinfo = e100_get_drvinfo,
2741 .get_regs_len = e100_get_regs_len,
2742 .get_regs = e100_get_regs,
2743 .get_wol = e100_get_wol,
2744 .set_wol = e100_set_wol,
2745 .get_msglevel = e100_get_msglevel,
2746 .set_msglevel = e100_set_msglevel,
2747 .nway_reset = e100_nway_reset,
2748 .get_link = e100_get_link,
2749 .get_eeprom_len = e100_get_eeprom_len,
2750 .get_eeprom = e100_get_eeprom,
2751 .set_eeprom = e100_set_eeprom,
2752 .get_ringparam = e100_get_ringparam,
2753 .set_ringparam = e100_set_ringparam,
2754 .self_test = e100_diag_test,
2755 .get_strings = e100_get_strings,
2756 .set_phys_id = e100_set_phys_id,
2757 .get_ethtool_stats = e100_get_ethtool_stats,
2758 .get_sset_count = e100_get_sset_count,
2762 static int e100_do_ioctl(
struct net_device *netdev,
struct ifreq *ifr,
int cmd)
2764 struct nic *nic = netdev_priv(netdev);
2769 static int e100_alloc(
struct nic *nic)
2773 return nic->mem ? 0 : -
ENOMEM;
2776 static void e100_free(
struct nic *nic)
2780 nic->mem, nic->dma_addr);
2785 static int e100_open(
struct net_device *netdev)
2787 struct nic *nic = netdev_priv(netdev);
2791 if ((err = e100_up(nic)))
2792 netif_err(nic, ifup, nic->netdev,
"Cannot open interface, aborting\n");
2796 static int e100_close(
struct net_device *netdev)
2798 e100_down(netdev_priv(netdev));
2802 static int e100_set_features(
struct net_device *netdev,
2805 struct nic *nic = netdev_priv(netdev);
2812 e100_exec_cb(nic,
NULL, e100_configure);
2817 .ndo_open = e100_open,
2818 .ndo_stop = e100_close,
2819 .ndo_start_xmit = e100_xmit_frame,
2821 .ndo_set_rx_mode = e100_set_multicast_list,
2822 .ndo_set_mac_address = e100_set_mac_address,
2823 .ndo_change_mtu = e100_change_mtu,
2824 .ndo_do_ioctl = e100_do_ioctl,
2825 .ndo_tx_timeout = e100_tx_timeout,
2826 #ifdef CONFIG_NET_POLL_CONTROLLER
2827 .ndo_poll_controller = e100_netpoll,
2829 .ndo_set_features = e100_set_features,
2839 if (!(netdev = alloc_etherdev(
sizeof(
struct nic))))
2851 nic = netdev_priv(netdev);
2853 nic->netdev = netdev;
2855 nic->msg_enable = (1 <<
debug) - 1;
2856 nic->mdio_ctrl = mdio_ctrl_hw;
2857 pci_set_drvdata(pdev, netdev);
2860 netif_err(nic, probe, nic->netdev,
"Cannot enable PCI device, aborting\n");
2861 goto err_out_free_dev;
2865 netif_err(nic, probe, nic->netdev,
"Cannot find proper PCI device base address, aborting\n");
2867 goto err_out_disable_pdev;
2871 netif_err(nic, probe, nic->netdev,
"Cannot obtain PCI resources, aborting\n");
2872 goto err_out_disable_pdev;
2875 if ((err = pci_set_dma_mask(pdev,
DMA_BIT_MASK(32)))) {
2876 netif_err(nic, probe, nic->netdev,
"No usable DMA configuration, aborting\n");
2877 goto err_out_free_res;
2883 netif_info(nic, probe, nic->netdev,
"using i/o access mode\n");
2885 nic->csr = pci_iomap(pdev, (use_io ? 1 : 0),
sizeof(
struct csr));
2887 netif_err(nic, probe, nic->netdev,
"Cannot map device registers, aborting\n");
2889 goto err_out_free_res;
2897 e100_get_defaults(nic);
2916 nic->watchdog.function = e100_watchdog;
2917 nic->watchdog.data = (
unsigned long)nic;
2919 INIT_WORK(&nic->tx_timeout_task, e100_tx_timeout_task);
2921 if ((err = e100_alloc(nic))) {
2922 netif_err(nic, probe, nic->netdev,
"Cannot alloc driver memory, aborting\n");
2923 goto err_out_iounmap;
2926 if ((err = e100_eeprom_load(nic)))
2933 if (!is_valid_ether_addr(netdev->
perm_addr)) {
2934 if (!eeprom_bad_csum_allow) {
2935 netif_err(nic, probe, nic->netdev,
"Invalid MAC address from EEPROM, aborting\n");
2939 netif_err(nic, probe, nic->netdev,
"Invalid MAC address from EEPROM, you MUST configure one.\n");
2946 nic->flags |= wol_magic;
2955 netif_err(nic, probe, nic->netdev,
"Cannot register net device, aborting\n");
2958 nic->cbs_pool = pci_pool_create(netdev->
name,
2960 nic->params.cbs.max *
sizeof(
struct cb),
2964 "addr 0x%llx, irq %d, MAC addr %pM\n",
2976 err_out_disable_pdev:
2979 pci_set_drvdata(pdev,
NULL);
2986 struct net_device *netdev = pci_get_drvdata(pdev);
2989 struct nic *nic = netdev_priv(netdev);
2993 pci_pool_destroy(nic->cbs_pool);
2997 pci_set_drvdata(pdev,
NULL);
3001 #define E100_82552_SMARTSPEED 0x14
3002 #define E100_82552_REV_ANEG 0x0200
3003 #define E100_82552_ANEG_NOW 0x0400
3004 static void __e100_shutdown(
struct pci_dev *pdev,
bool *enable_wake)
3006 struct net_device *netdev = pci_get_drvdata(pdev);
3007 struct nic *nic = netdev_priv(netdev);
3009 if (netif_running(netdev))
3015 if ((nic->flags & wol_magic) | e100_asf(nic)) {
3018 u16 smartspeed = mdio_read(netdev, nic->mii.phy_id,
3021 mdio_write(netdev, nic->mii.phy_id,
3025 *enable_wake =
true;
3027 *enable_wake =
false;
3033 static int __e100_power_off(
struct pci_dev *pdev,
bool wake)
3048 __e100_shutdown(pdev, &wake);
3049 return __e100_power_off(pdev, wake);
3052 static int e100_resume(
struct pci_dev *pdev)
3054 struct net_device *netdev = pci_get_drvdata(pdev);
3055 struct nic *nic = netdev_priv(netdev);
3060 pci_enable_wake(pdev, 0, 0);
3064 u16 smartspeed = mdio_read(netdev, nic->mii.phy_id,
3067 mdio_write(netdev, nic->mii.phy_id,
3073 if (netif_running(netdev))
3080 static void e100_shutdown(
struct pci_dev *pdev)
3083 __e100_shutdown(pdev, &wake);
3085 __e100_power_off(pdev, wake);
3096 struct net_device *netdev = pci_get_drvdata(pdev);
3097 struct nic *nic = netdev_priv(netdev);
3104 if (netif_running(netdev))
3120 struct net_device *netdev = pci_get_drvdata(pdev);
3121 struct nic *nic = netdev_priv(netdev);
3124 pr_err(
"Cannot re-enable PCI device after reset\n");
3145 static void e100_io_resume(
struct pci_dev *pdev)
3147 struct net_device *netdev = pci_get_drvdata(pdev);
3148 struct nic *nic = netdev_priv(netdev);
3151 pci_enable_wake(pdev, 0, 0);
3154 if (netif_running(netdev)) {
3161 .error_detected = e100_io_error_detected,
3162 .slot_reset = e100_io_slot_reset,
3163 .resume = e100_io_resume,
3168 .id_table = e100_id_table,
3169 .probe = e100_probe,
3173 .suspend = e100_suspend,
3174 .resume = e100_resume,
3176 .shutdown = e100_shutdown,
3177 .err_handler = &e100_err_handler,
3180 static int __init e100_init_module(
void)
3186 return pci_register_driver(&e100_driver);
3189 static void __exit e100_cleanup_module(
void)