48 #include <asm/byteorder.h>
50 #include <linux/compiler.h>
56 #include <linux/if_ether.h>
57 #include <linux/if_vlan.h>
64 #include <linux/mii.h>
65 #include <linux/module.h>
67 #include <linux/net.h>
68 #include <linux/netdevice.h>
69 #include <linux/pci.h>
73 #include <linux/slab.h>
75 #include <linux/string.h>
76 #include <linux/tcp.h>
78 #include <linux/types.h>
85 #define ATLX_DRIVER_VERSION "2.1.3"
101 #define ATL1_MAX_NIC 4
103 #define OPTION_UNSET -1
104 #define OPTION_DISABLED 0
105 #define OPTION_ENABLED 1
107 #define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET }
117 static unsigned int num_int_mod_timer;
119 &num_int_mod_timer, 0);
122 #define DEFAULT_INT_MOD_CNT 100
123 #define MAX_INT_MOD_CNT 65000
124 #define MIN_INT_MOD_CNT 50
138 struct atl1_opt_list {
166 if (*value >= opt->
arg.
r.min && *value <= opt->
arg.r.max) {
174 struct atl1_opt_list *
ent;
176 for (i = 0; i < opt->
arg.
l.nr; i++) {
177 ent = &opt->
arg.
l.p[
i];
178 if (*value == ent->i) {
179 if (ent->str[0] !=
'\0')
192 dev_info(&pdev->
dev,
"invalid %s specified (%i) %s\n",
212 dev_notice(&pdev->
dev,
"no configuration for board#%i\n", bd);
213 dev_notice(&pdev->
dev,
"using defaults for all values\n");
218 .name =
"Interrupt Moderator Timer",
219 .err =
"using default of "
226 if (num_int_mod_timer > bd) {
227 val = int_mod_timer[bd];
228 atl1_validate_option(&val, &opt, pdev);
248 static int debug = -1;
289 for (i = 0; i < 10; i++) {
313 static int atl1_check_eeprom_exist(
struct atl1_hw *hw)
318 value &= ~SPI_FLASH_CTRL_EN_VPD;
323 return ((value & 0xFF00) == 0x6C00) ? 0 : 1;
340 for (i = 0; i < 10; i++) {
377 *phy_data = (
u16) val;
383 #define CUSTOM_SPI_CS_SETUP 2
384 #define CUSTOM_SPI_CLK_HI 2
385 #define CUSTOM_SPI_CLK_LO 2
386 #define CUSTOM_SPI_CS_HOLD 2
387 #define CUSTOM_SPI_CS_HI 3
416 for (i = 0; i < 10; i++) {
435 static int atl1_get_permanent_address(
struct atl1_hw *hw)
447 addr[0] = addr[1] = 0;
449 if (!atl1_check_eeprom_exist(hw)) {
455 if (atl1_read_eeprom(hw, i + 0x100, &control)) {
462 }
else if ((control & 0xff) == 0x5A) {
464 reg = (
u16) (control >> 16);
475 if (is_valid_ether_addr(eth_addr)) {
482 addr[0] = addr[1] = 0;
487 if (atl1_spi_read(hw, i + 0x1f000, &control)) {
494 }
else if ((control & 0xff) == 0x5A) {
496 reg = (
u16) (control >> 16);
508 if (is_valid_ether_addr(eth_addr)) {
523 if (is_valid_ether_addr(eth_addr)) {
535 static s32 atl1_read_mac_addr(
struct atl1_hw *hw)
540 if (atl1_get_permanent_address(hw)) {
562 static u32 atl1_hash_mc_addr(
struct atl1_hw *hw,
u8 *mc_addr)
568 for (i = 0; i < 32; i++)
569 value |= (((crc32 >> i) & 1) << (31 - i));
579 static void atl1_hash_set(
struct atl1_hw *hw,
u32 hash_value)
581 u32 hash_bit, hash_reg;
593 hash_reg = (hash_value >> 31) & 0x1;
594 hash_bit = (hash_value >> 26) & 0x1F;
596 mta |= (1 << hash_bit);
606 static s32 atl1_write_phy_reg(
struct atl1_hw *hw,
u32 reg_addr,
u16 phy_data)
637 static s32 atl1_phy_leave_power_saving(
struct atl1_hw *hw)
640 ret = atl1_write_phy_reg(hw, 29, 0x0029);
643 return atl1_write_phy_reg(hw, 30, 0);
683 ret_val = atl1_write_phy_reg(hw,
MII_BMCR, phy_data);
691 for (i = 0; i < 25; i++) {
701 "pcie link down at least 25ms\n");
712 static s32 atl1_phy_setup_autoneg_adv(
struct atl1_hw *hw)
715 s16 mii_autoneg_adv_reg;
716 s16 mii_1000t_ctrl_reg;
772 ret_val = atl1_write_phy_reg(hw,
MII_ADVERTISE, mii_autoneg_adv_reg);
776 ret_val = atl1_write_phy_reg(hw,
MII_ATLX_CR, mii_1000t_ctrl_reg);
789 static s32 atl1_setup_link(
struct atl1_hw *hw)
801 ret_val = atl1_phy_setup_autoneg_adv(hw);
805 "error setting up autonegotiation\n");
809 ret_val = atl1_phy_reset(hw);
819 static void atl1_init_flash_opcode(
struct atl1_hw *hw)
861 atl1_init_flash_opcode(hw);
865 ret_val = atl1_write_phy_reg(hw, 18, 0xC00);
869 ret_val = atl1_phy_leave_power_saving(hw);
873 ret_val = atl1_setup_link(hw);
923 static void atl1_set_mac_addr(
struct atl1_hw *hw)
959 adapter->
ict = 50000;
1004 atl1_read_phy_reg(&adapter->
hw, reg_num & 0x1f, &result);
1014 atl1_write_phy_reg(&adapter->
hw, reg_num, val);
1020 unsigned long flags;
1023 if (!netif_running(netdev))
1028 spin_unlock_irqrestore(&adapter->
lock, flags);
1053 dev_err(&pdev->
dev,
"kzalloc failed , size = D%d\n",
1065 ring_header->
size = size =
1077 dev_err(&pdev->
dev,
"pci_alloc_consistent failed\n");
1084 tpd_ring->
dma = ring_header->
dma;
1085 offset = (tpd_ring->
dma & 0x7) ? (8 - (ring_header->
dma & 0x7)) : 0;
1087 tpd_ring->
desc = (
u8 *) ring_header->
desc + offset;
1091 rfd_ring->
dma = tpd_ring->
dma + tpd_ring->
size;
1092 offset = (rfd_ring->
dma & 0x7) ? (8 - (rfd_ring->
dma & 0x7)) : 0;
1094 rfd_ring->
desc = (
u8 *) tpd_ring->
desc + (tpd_ring->
size + offset);
1099 rrd_ring->
dma = rfd_ring->
dma + rfd_ring->
size;
1100 offset = (rrd_ring->
dma & 0x7) ? (8 - (rrd_ring->
dma & 0x7)) : 0;
1102 rrd_ring->
desc = (
u8 *) rfd_ring->
desc + (rfd_ring->
size + offset);
1107 adapter->
cmb.dma = rrd_ring->
dma + rrd_ring->
size;
1108 offset = (adapter->
cmb.dma & 0x7) ? (8 - (adapter->
cmb.dma & 0x7)) : 0;
1115 offset = (adapter->
smb.dma & 0x7) ? (8 - (adapter->
smb.dma & 0x7)) : 0;
1118 ((
u8 *) adapter->
cmb.cmb +
1128 static void atl1_init_ring_ptrs(
struct atl1_adapter *adapter)
1148 static void atl1_clean_rx_ring(
struct atl1_adapter *adapter)
1158 for (i = 0; i < rfd_ring->
count; i++) {
1160 if (buffer_info->
dma) {
1161 pci_unmap_page(pdev, buffer_info->
dma,
1163 buffer_info->
dma = 0;
1165 if (buffer_info->
skb) {
1166 dev_kfree_skb(buffer_info->
skb);
1188 static void atl1_clean_tx_ring(
struct atl1_adapter *adapter)
1197 for (i = 0; i < tpd_ring->
count; i++) {
1199 if (buffer_info->
dma) {
1200 pci_unmap_page(pdev, buffer_info->
dma,
1202 buffer_info->
dma = 0;
1206 for (i = 0; i < tpd_ring->
count; i++) {
1208 if (buffer_info->
skb) {
1230 static void atl1_free_ring_resources(
struct atl1_adapter *adapter)
1238 atl1_clean_tx_ring(adapter);
1239 atl1_clean_rx_ring(adapter);
1256 adapter->
cmb.dma = 0;
1259 adapter->
smb.dma = 0;
1263 static void atl1_setup_mac_ctrl(
struct atl1_adapter *adapter)
1282 value |= (((
u32) adapter->
hw.preamble_len
1285 __atlx_vlan_mode(netdev->
features, &value);
1309 atl1_read_phy_reg(hw,
MII_BMSR, &phy_data);
1310 atl1_read_phy_reg(hw,
MII_BMSR, &phy_data);
1313 if (netif_carrier_ok(netdev)) {
1324 ret_val = atl1_get_speed_and_duplex(hw, &speed, &duplex);
1357 atl1_setup_mac_ctrl(adapter);
1360 "%s link is up %d Mbps %s\n",
1363 "full duplex" :
"half duplex");
1365 if (!netif_carrier_ok(netdev)) {
1373 if (netif_carrier_ok(netdev)) {
1376 netif_stop_queue(netdev);
1398 atl1_write_phy_reg(hw,
MII_BMCR, phy_data);
1412 static void set_flow_ctrl_old(
struct atl1_adapter *adapter)
1438 static void set_flow_ctrl_new(
struct atl1_hw *hw)
1573 set_flow_ctrl_old(adapter);
1576 set_flow_ctrl_new(hw);
1647 static void atl1_pcie_patch(
struct atl1_adapter *adapter)
1655 value =
ioread32(adapter->
hw.hw_addr + 0x1008);
1666 static void atl1_via_workaround(
struct atl1_adapter *adapter)
1668 unsigned long value;
1672 value &= ~PCI_COMMAND_INTX_DISABLE;
1728 netdev->
stats.rx_over_errors =
1730 netdev->
stats.rx_length_errors =
1733 netdev->
stats.rx_frame_errors =
1736 netdev->
stats.rx_missed_errors =
1740 netdev->
stats.tx_aborted_errors =
1742 netdev->
stats.tx_window_errors =
1744 netdev->
stats.tx_carrier_errors =
1748 static void atl1_update_mailbox(
struct atl1_adapter *adapter)
1750 unsigned long flags;
1751 u32 tpd_next_to_use;
1752 u32 rfd_next_to_use;
1753 u32 rrd_next_to_clean;
1770 spin_unlock_irqrestore(&adapter->
mb_lock, flags);
1773 static void atl1_clean_alloc_flag(
struct atl1_adapter *adapter,
1786 static void atl1_update_rfd_index(
struct atl1_adapter *adapter,
1795 atl1_clean_alloc_flag(adapter, rrd, num_buf);
1798 static void atl1_rx_checksum(
struct atl1_adapter *adapter,
1814 skb_checksum_none_assert(skb);
1822 "rx checksum error\n");
1854 u16 rfd_next_to_use, next_next;
1858 if (++next_next == rfd_ring->
count)
1860 buffer_info = &rfd_ring->
buffer_info[rfd_next_to_use];
1864 if (buffer_info->
skb) {
1871 skb = netdev_alloc_skb_ip_align(adapter->
netdev,
1875 adapter->
netdev->stats.rx_dropped++;
1884 buffer_info->
dma = pci_map_page(pdev, page, offset,
1892 rfd_next_to_use = next_next;
1896 buffer_info = &rfd_ring->
buffer_info[rfd_next_to_use];
1918 u16 rrd_next_to_clean;
1930 while (count < budget) {
1940 "unexpected RRD buffer count\n");
1942 "rx_buf_len = %d\n",
1945 "RRD num_buf = %d\n",
1948 "RRD pkt_len = %d\n",
1951 "RRD pkt_flg = 0x%08X\n",
1954 "RRD err_flg = 0x%08X\n",
1957 "RRD vlan_tag = 0x%08X\n",
1973 atl1_update_rfd_index(adapter, rrd);
1977 if (++rrd_next_to_clean == rrd_ring->
count)
1978 rrd_next_to_clean = 0;
1987 atl1_clean_alloc_flag(adapter, rrd, 0);
1994 if (++rrd_next_to_clean == rrd_ring->
count)
1995 rrd_next_to_clean = 0;
2010 pci_unmap_page(adapter->
pdev, buffer_info->
dma,
2012 buffer_info->
dma = 0;
2013 skb = buffer_info->
skb;
2019 atl1_rx_checksum(adapter, rrd, skb);
2027 __vlan_hwaccel_put_tag(skb, vlan_tag);
2039 atl1_alloc_rx_buffers(adapter);
2043 u32 tpd_next_to_use;
2044 u32 rfd_next_to_use;
2060 spin_unlock(&adapter->
mb_lock);
2070 u16 sw_tpd_next_to_clean;
2071 u16 cmb_tpd_next_to_clean;
2075 cmb_tpd_next_to_clean =
le16_to_cpu(adapter->
cmb.cmb->tpd_cons_idx);
2077 while (cmb_tpd_next_to_clean != sw_tpd_next_to_clean) {
2078 buffer_info = &tpd_ring->
buffer_info[sw_tpd_next_to_clean];
2079 if (buffer_info->
dma) {
2080 pci_unmap_page(adapter->
pdev, buffer_info->
dma,
2082 buffer_info->
dma = 0;
2085 if (buffer_info->
skb) {
2090 if (++sw_tpd_next_to_clean == tpd_ring->
count)
2091 sw_tpd_next_to_clean = 0;
2097 if (netif_queue_stopped(adapter->
netdev) &&
2098 netif_carrier_ok(adapter->
netdev))
2099 netif_wake_queue(adapter->
netdev);
2108 return (next_to_clean > next_to_use) ?
2109 next_to_clean - next_to_use - 1 :
2110 tpd_ring->
count + next_to_clean - next_to_use - 1;
2120 if (skb_shinfo(skb)->gso_size) {
2121 if (skb_header_cloned(skb)) {
2128 struct iphdr *iph = ip_hdr(skb);
2130 real_len = (((
unsigned char *)iph - skb->
data) +
2132 if (real_len < skb->len)
2133 pskb_trim(skb, real_len);
2134 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
2135 if (skb->
len == hdr_len) {
2137 tcp_hdr(skb)->check =
2139 iph->
daddr, tcp_hdrlen(skb),
2143 ptpd->
word3 |= ((tcp_hdrlen(skb) >> 2) &
2154 ip_off = (
unsigned char *)iph -
2155 (
unsigned char *) skb_network_header(skb);
2158 else if (ip_off != 0)
2163 ptpd->
word3 |= ((tcp_hdrlen(skb) >> 2) &
2165 ptpd->
word3 |= (skb_shinfo(skb)->gso_size &
2180 css = skb_checksum_start_offset(skb);
2186 "payload offset not an even number\n");
2207 unsigned int nr_frags;
2215 nr_frags = skb_shinfo(skb)->nr_frags;
2217 buffer_info = &tpd_ring->
buffer_info[next_to_use];
2225 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2229 buffer_info->
dma = pci_map_page(adapter->
pdev, page,
2233 if (++next_to_use == tpd_ring->
count)
2236 if (buf_len > hdr_len) {
2242 for (i = 0; i < nseg; i++) {
2249 data_len -= buffer_info->
length;
2252 offset = (
unsigned long)(skb->
data +
2255 buffer_info->
dma = pci_map_page(adapter->
pdev,
2256 page, offset, buffer_info->
length,
2258 if (++next_to_use == tpd_ring->
count)
2264 buffer_info->
length = buf_len;
2267 buffer_info->
dma = pci_map_page(adapter->
pdev, page,
2269 if (++next_to_use == tpd_ring->
count)
2273 for (f = 0; f < nr_frags; f++) {
2277 frag = &skb_shinfo(skb)->frags[
f];
2278 buf_len = skb_frag_size(frag);
2282 for (i = 0; i < nseg; i++) {
2283 buffer_info = &tpd_ring->
buffer_info[next_to_use];
2289 buf_len -= buffer_info->
length;
2290 buffer_info->
dma = skb_frag_dma_map(&adapter->
pdev->dev,
2294 if (++next_to_use == tpd_ring->
count)
2313 for (j = 0; j <
count; j++) {
2314 buffer_info = &tpd_ring->
buffer_info[next_to_use];
2336 if (j == (count - 1))
2339 if (++next_to_use == tpd_ring->
count)
2364 unsigned int nr_frags = 0;
2365 unsigned int mss = 0;
2367 unsigned int proto_hdr_len;
2369 len = skb_headlen(skb);
2376 nr_frags = skb_shinfo(skb)->nr_frags;
2377 for (f = 0; f < nr_frags; f++) {
2378 unsigned int f_size = skb_frag_size(&skb_shinfo(skb)->frags[f]);
2383 mss = skb_shinfo(skb)->gso_size;
2386 proto_hdr_len = (skb_transport_offset(skb) +
2388 if (
unlikely(proto_hdr_len > len)) {
2393 if (proto_hdr_len != len)
2394 count += (len - proto_hdr_len +
2402 netif_stop_queue(netdev);
2415 vlan_tag = (vlan_tag << 4) | (vlan_tag >> 13) |
2416 ((vlan_tag >> 9) & 0x8);
2422 tso = atl1_tso(adapter, skb, ptpd);
2429 ret_val = atl1_tx_csum(adapter, skb, ptpd);
2436 atl1_tx_map(adapter, skb, ptpd);
2437 atl1_tx_queue(adapter, count, ptpd);
2438 atl1_update_mailbox(adapter);
2446 int work_done = atl1_intr_rx(adapter, budget);
2448 if (atl1_intr_tx(adapter))
2452 if (work_done >= budget)
2462 static inline int atl1_sched_rings_clean(
struct atl1_adapter* adapter)
2464 if (!napi_schedule_prep(&adapter->
napi))
2496 status = adapter->
cmb.cmb->int_stats;
2508 atlx_clear_phy_int(adapter);
2515 atl1_inc_smb(adapter);
2521 "pcie phy link down %x\n", status);
2522 if (netif_running(adapter->
netdev)) {
2523 atlx_irq_disable(adapter);
2533 "pcie DMA r/w error (status = 0x%x)\n",
2535 atlx_irq_disable(adapter);
2541 if (status & ISR_GPHY) {
2543 atl1_check_for_link(adapter);
2548 atl1_sched_rings_clean(adapter))
2549 adapter->
cmb.cmb->int_stats = adapter->
cmb.cmb->int_stats &
2558 &adapter->
pdev->dev,
2559 "rx exception, ISR = 0x%x\n",
2561 atl1_sched_rings_clean(adapter);
2574 static void atl1_phy_config(
unsigned long data)
2578 unsigned long flags;
2585 spin_unlock_irqrestore(&adapter->
lock, flags);
2602 ret = atl1_reset_hw(&adapter->
hw);
2605 return atl1_init_hw(&adapter->
hw);
2615 atlx_set_multi(netdev);
2616 atl1_init_ring_ptrs(adapter);
2617 atlx_restore_vlan(adapter);
2618 err = atl1_alloc_rx_buffers(adapter);
2623 if (
unlikely(atl1_configure(adapter))) {
2628 err = pci_enable_msi(adapter->
pdev);
2632 "Unable to enable MSI: %d\n", err);
2637 netdev->
name, netdev);
2641 napi_enable(&adapter->
napi);
2642 atlx_irq_enable(adapter);
2643 atl1_check_link(adapter);
2644 netif_start_queue(netdev);
2650 atl1_clean_rx_ring(adapter);
2658 napi_disable(&adapter->
napi);
2659 netif_stop_queue(netdev);
2663 atlx_irq_disable(adapter);
2666 atl1_reset_hw(&adapter->
hw);
2667 adapter->
cmb.cmb->int_stats = 0;
2673 atl1_clean_tx_ring(adapter);
2674 atl1_clean_rx_ring(adapter);
2696 static int atl1_change_mtu(
struct net_device *netdev,
int new_mtu)
2699 int old_mtu = netdev->
mtu;
2705 dev_warn(&adapter->
pdev->dev,
"invalid MTU setting\n");
2709 adapter->
hw.max_frame_size = max_frame;
2710 adapter->
hw.tx_jumbo_task_th = (max_frame + 7) >> 3;
2714 netdev->
mtu = new_mtu;
2715 if ((old_mtu != new_mtu) && netif_running(netdev)) {
2735 static int atl1_open(
struct net_device *netdev)
2743 err = atl1_setup_ring_resources(adapter);
2747 err = atl1_up(adapter);
2754 atl1_reset(adapter);
2769 static int atl1_close(
struct net_device *netdev)
2773 atl1_free_ring_resources(adapter);
2778 static int atl1_suspend(
struct device *
dev)
2781 struct net_device *netdev = pci_get_drvdata(pdev);
2791 if (netif_running(netdev))
2803 val = atl1_get_speed_and_duplex(hw, &speed, &duplex);
2807 "error getting speed/duplex\n");
2825 ctrl |= (((
u32)adapter->
hw.preamble_len &
2827 __atlx_vlan_mode(netdev->
features, &ctrl);
2828 if (wufc & ATLX_WUFC_MAG)
2861 static int atl1_resume(
struct device *dev)
2864 struct net_device *netdev = pci_get_drvdata(pdev);
2869 atl1_reset_hw(&adapter->
hw);
2871 if (netif_running(netdev)) {
2872 adapter->
cmb.cmb->int_stats = 0;
2881 #define ATL1_PM_OPS (&atl1_pm_ops)
2885 static int atl1_suspend(
struct device *dev) {
return 0; }
2887 #define ATL1_PM_OPS NULL
2890 static void atl1_shutdown(
struct pci_dev *pdev)
2892 struct net_device *netdev = pci_get_drvdata(pdev);
2895 atl1_suspend(&pdev->
dev);
2900 #ifdef CONFIG_NET_POLL_CONTROLLER
2901 static void atl1_poll_controller(
struct net_device *netdev)
2904 atl1_intr(netdev->
irq, netdev);
2910 .ndo_open = atl1_open,
2911 .ndo_stop = atl1_close,
2912 .ndo_start_xmit = atl1_xmit_frame,
2913 .ndo_set_rx_mode = atlx_set_multi,
2915 .ndo_set_mac_address = atl1_set_mac,
2916 .ndo_change_mtu = atl1_change_mtu,
2917 .ndo_fix_features = atlx_fix_features,
2918 .ndo_set_features = atlx_set_features,
2919 .ndo_do_ioctl = atlx_ioctl,
2920 .ndo_tx_timeout = atlx_tx_timeout,
2921 #ifdef CONFIG_NET_POLL_CONTROLLER
2922 .ndo_poll_controller = atl1_poll_controller,
2942 static int cards_found = 0;
2961 dev_err(&pdev->
dev,
"no usable DMA configuration\n");
2970 goto err_request_regions;
2981 goto err_alloc_etherdev;
2985 pci_set_drvdata(pdev, netdev);
2986 adapter = netdev_priv(netdev);
2990 adapter->
msg_enable = netif_msg_init(debug, atl1_default_msg);
2992 adapter->
hw.hw_addr = pci_iomap(pdev, 0, 0);
2993 if (!adapter->
hw.hw_addr) {
3008 adapter->
mii.mdio_read = mdio_read;
3009 adapter->
mii.mdio_write = mdio_write;
3010 adapter->
mii.phy_id_mask = 0x1f;
3011 adapter->
mii.reg_num_mask = 0x1f;
3021 err = atl1_sw_init(adapter);
3049 if (atl1_reset_hw(&adapter->
hw)) {
3055 if (atl1_read_mac_addr(&adapter->
hw)) {
3061 if (!is_valid_ether_addr(netdev->
dev_addr)) {
3066 atl1_check_options(adapter);
3069 err = atl1_init_hw(&adapter->
hw);
3075 atl1_pcie_patch(adapter);
3080 (
unsigned long)adapter);
3092 atl1_via_workaround(adapter);
3102 err_request_regions:
3118 struct net_device *netdev = pci_get_drvdata(pdev);
3124 adapter = netdev_priv(netdev);
3132 memcpy(adapter->
hw.mac_addr, adapter->
hw.perm_mac_addr,
3134 atl1_set_mac_addr(&adapter->
hw);
3147 .id_table = atl1_pci_tbl,
3148 .probe = atl1_probe,
3150 .shutdown = atl1_shutdown,
3160 static void __exit atl1_exit_module(
void)
3171 static int __init atl1_init_module(
void)
3173 return pci_register_driver(&atl1_driver);
3185 #define ATL1_STAT(m) \
3186 sizeof(((struct atl1_adapter *)0)->m), offsetof(struct atl1_adapter, m)
3188 static struct atl1_stats atl1_gstrings_stats[] = {
3189 {
"rx_packets",
ATL1_STAT(soft_stats.rx_packets)},
3190 {
"tx_packets",
ATL1_STAT(soft_stats.tx_packets)},
3191 {
"rx_bytes",
ATL1_STAT(soft_stats.rx_bytes)},
3192 {
"tx_bytes",
ATL1_STAT(soft_stats.tx_bytes)},
3193 {
"rx_errors",
ATL1_STAT(soft_stats.rx_errors)},
3194 {
"tx_errors",
ATL1_STAT(soft_stats.tx_errors)},
3195 {
"multicast",
ATL1_STAT(soft_stats.multicast)},
3196 {
"collisions",
ATL1_STAT(soft_stats.collisions)},
3197 {
"rx_length_errors",
ATL1_STAT(soft_stats.rx_length_errors)},
3198 {
"rx_over_errors",
ATL1_STAT(soft_stats.rx_missed_errors)},
3199 {
"rx_crc_errors",
ATL1_STAT(soft_stats.rx_crc_errors)},
3200 {
"rx_frame_errors",
ATL1_STAT(soft_stats.rx_frame_errors)},
3201 {
"rx_fifo_errors",
ATL1_STAT(soft_stats.rx_fifo_errors)},
3202 {
"rx_missed_errors",
ATL1_STAT(soft_stats.rx_missed_errors)},
3203 {
"tx_aborted_errors",
ATL1_STAT(soft_stats.tx_aborted_errors)},
3204 {
"tx_carrier_errors",
ATL1_STAT(soft_stats.tx_carrier_errors)},
3205 {
"tx_fifo_errors",
ATL1_STAT(soft_stats.tx_fifo_errors)},
3206 {
"tx_window_errors",
ATL1_STAT(soft_stats.tx_window_errors)},
3207 {
"tx_abort_exce_coll",
ATL1_STAT(soft_stats.excecol)},
3208 {
"tx_abort_late_coll",
ATL1_STAT(soft_stats.latecol)},
3209 {
"tx_deferred_ok",
ATL1_STAT(soft_stats.deffer)},
3210 {
"tx_single_coll_ok",
ATL1_STAT(soft_stats.scc)},
3211 {
"tx_multi_coll_ok",
ATL1_STAT(soft_stats.mcc)},
3212 {
"tx_underun",
ATL1_STAT(soft_stats.tx_underun)},
3213 {
"tx_trunc",
ATL1_STAT(soft_stats.tx_trunc)},
3214 {
"tx_pause",
ATL1_STAT(soft_stats.tx_pause)},
3215 {
"rx_pause",
ATL1_STAT(soft_stats.rx_pause)},
3216 {
"rx_rrd_ov",
ATL1_STAT(soft_stats.rx_rrd_ov)},
3217 {
"rx_trunc",
ATL1_STAT(soft_stats.rx_trunc)}
3220 static void atl1_get_ethtool_stats(
struct net_device *netdev,
3227 for (i = 0; i <
ARRAY_SIZE(atl1_gstrings_stats); i++) {
3228 p = (
char *)adapter+atl1_gstrings_stats[i].stat_offset;
3235 static int atl1_get_sset_count(
struct net_device *netdev,
int sset)
3245 static int atl1_get_settings(
struct net_device *netdev,
3276 if (netif_carrier_ok(adapter->
netdev)) {
3278 atl1_get_speed_and_duplex(hw, &link_speed, &link_duplex);
3279 ethtool_cmd_speed_set(ecmd, link_speed);
3285 ethtool_cmd_speed_set(ecmd, -1);
3297 static int atl1_set_settings(
struct net_device *netdev,
3306 if (netif_running(adapter->
netdev)) {
3309 "ethtool shutting down adapter\n");
3316 u32 speed = ethtool_cmd_speed(ecmd);
3321 "1000M half is invalid\n");
3357 if (atl1_phy_setup_autoneg_adv(hw)) {
3361 "invalid ethtool speed/duplex setting\n");
3387 atl1_write_phy_reg(hw,
MII_BMCR, phy_data);
3392 if (netif_running(adapter->
netdev)) {
3395 "ethtool starting adapter\n");
3397 }
else if (!ret_val) {
3400 "ethtool resetting adapter\n");
3401 atl1_reset(adapter);
3406 static void atl1_get_drvinfo(
struct net_device *netdev,
3419 static void atl1_get_wol(
struct net_device *netdev,
3426 if (adapter->
wol & ATLX_WUFC_MAG)
3430 static int atl1_set_wol(
struct net_device *netdev,
3453 static void atl1_set_msglevel(
struct net_device *netdev,
u32 value)
3459 static int atl1_get_regs_len(
struct net_device *netdev)
3510 static void atl1_get_ringparam(
struct net_device *netdev,
3523 static int atl1_set_ringparam(
struct net_device *netdev,
3544 if (netif_running(adapter->
netdev))
3558 if (netif_running(adapter->
netdev)) {
3560 err = atl1_setup_ring_resources(adapter);
3562 goto err_setup_ring;
3583 atl1_free_ring_resources(adapter);
3591 err = atl1_up(adapter);
3606 static void atl1_get_pauseparam(
struct net_device *netdev,
3622 static int atl1_set_pauseparam(
struct net_device *netdev,
3641 static void atl1_get_strings(
struct net_device *netdev,
u32 stringset,
3647 switch (stringset) {
3649 for (i = 0; i <
ARRAY_SIZE(atl1_gstrings_stats); i++) {
3650 memcpy(p, atl1_gstrings_stats[i].stat_string,
3658 static int atl1_nway_reset(
struct net_device *netdev)
3663 if (netif_running(netdev)) {
3688 atl1_write_phy_reg(hw,
MII_BMCR, phy_data);
3694 static const struct ethtool_ops atl1_ethtool_ops = {
3695 .get_settings = atl1_get_settings,
3696 .set_settings = atl1_set_settings,
3697 .get_drvinfo = atl1_get_drvinfo,
3698 .get_wol = atl1_get_wol,
3699 .set_wol = atl1_set_wol,
3700 .get_msglevel = atl1_get_msglevel,
3701 .set_msglevel = atl1_set_msglevel,
3702 .get_regs_len = atl1_get_regs_len,
3703 .get_regs = atl1_get_regs,
3704 .get_ringparam = atl1_get_ringparam,
3705 .set_ringparam = atl1_set_ringparam,
3706 .get_pauseparam = atl1_get_pauseparam,
3707 .set_pauseparam = atl1_set_pauseparam,
3709 .get_strings = atl1_get_strings,
3710 .nway_reset = atl1_nway_reset,
3711 .get_ethtool_stats = atl1_get_ethtool_stats,
3712 .get_sset_count = atl1_get_sset_count,