24 #define ATL1C_DRV_VERSION "1.0.1.0-NAPI"
55 static int atl1c_stop_mac(
struct atl1c_hw *
hw);
56 static void atl1c_disable_l0s_l1(
struct atl1c_hw *
hw);
60 int *work_done,
int work_to_do);
63 static int atl1c_reset_mac(
struct atl1c_hw *
hw);
68 static const u16 atl1c_pay_load_size[] = {
69 128, 256, 512, 1024, 2048, 4096,
75 static void atl1c_pcie_patch(
struct atl1c_hw *
hw)
92 mst_data | MASTER_CTRL_WAKEN_25M);
162 atl1c_pcie_patch(hw);
164 atl1c_disable_l0s_l1(hw);
186 static inline void atl1c_irq_disable(
struct atl1c_adapter *adapter)
199 static inline void atl1c_irq_reset(
struct atl1c_adapter *adapter)
202 atl1c_irq_enable(adapter);
209 static u32 atl1c_wait_until_idle(
struct atl1c_hw *hw,
u32 modu_ctrl)
216 if ((data & modu_ctrl) == 0)
227 static void atl1c_phy_config(
unsigned long data)
235 spin_unlock_irqrestore(&adapter->
mdio_lock, flags);
246 static void atl1c_check_link_status(
struct atl1c_adapter *adapter)
259 spin_unlock_irqrestore(&adapter->
mdio_lock, flags);
265 if (atl1c_reset_mac(hw) != 0)
270 atl1c_reset_dma_ring(adapter);
271 atl1c_configure(adapter);
277 spin_unlock_irqrestore(&adapter->
mdio_lock, flags);
285 atl1c_set_aspm(hw, speed);
287 atl1c_start_mac(adapter);
290 "%s: %s NIC Link is Up<%d Mbps %s>\n",
294 "Full Duplex" :
"Half Duplex");
296 if (!netif_carrier_ok(netdev))
301 static void atl1c_link_chg_event(
struct atl1c_adapter *adapter)
315 if (netif_carrier_ok(netdev)) {
320 "%s: %s NIC Link is Down\n",
350 atl1c_irq_disable(adapter);
351 atl1c_check_link_status(adapter);
352 atl1c_irq_enable(adapter);
367 static void atl1c_tx_timeout(
struct net_device *netdev)
385 static void atl1c_set_multi(
struct net_device *netdev)
429 static void atl1c_vlan_mode(
struct net_device *netdev,
434 u32 mac_ctrl_data = 0;
439 atl1c_irq_disable(adapter);
441 __atl1c_vlan_mode(features, &mac_ctrl_data);
443 atl1c_irq_enable(adapter);
446 static void atl1c_restore_vlan(
struct atl1c_adapter *adapter)
452 atl1c_vlan_mode(adapter->
netdev, adapter->
netdev->features);
462 static int atl1c_set_mac_addr(
struct net_device *netdev,
void *
p)
467 if (!is_valid_ether_addr(addr->
sa_data))
470 if (netif_running(netdev))
482 static void atl1c_set_rxbufsize(
struct atl1c_adapter *adapter,
509 static int atl1c_set_features(
struct net_device *netdev,
514 if (changed & NETIF_F_HW_VLAN_RX)
515 atl1c_vlan_mode(netdev, features);
527 static int atl1c_change_mtu(
struct net_device *netdev,
int new_mtu)
531 int old_mtu = netdev->
mtu;
545 if (old_mtu != new_mtu && netif_running(netdev)) {
548 netdev->
mtu = new_mtu;
549 adapter->
hw.max_frame_size = new_mtu;
550 atl1c_set_rxbufsize(adapter, netdev);
562 static int atl1c_mdio_read(
struct net_device *netdev,
int phy_id,
int reg_num)
572 int reg_num,
int val)
579 static int atl1c_mii_ioctl(
struct net_device *netdev,
588 if (!netif_running(netdev))
611 dev_dbg(&pdev->
dev,
"<atl1c_mii_ioctl> write %x %x",
625 spin_unlock_irqrestore(&adapter->
mdio_lock, flags);
629 static int atl1c_ioctl(
struct net_device *netdev,
struct ifreq *ifr,
int cmd)
635 return atl1c_mii_ioctl(netdev, ifr, cmd);
651 static void atl1c_set_mac_type(
struct atl1c_hw *hw)
677 static int atl1c_setup_mac_funcs(
struct atl1c_hw *hw)
681 atl1c_set_mac_type(hw);
703 #define ATL1C_LINK_PATCH 0x1
706 {0x2060, 0xC1, 0x1019, 0x8152, 0x1},
707 {0x2060, 0xC1, 0x1019, 0x2060, 0x1},
708 {0x2060, 0xC1, 0x1019, 0xE000, 0x1},
709 {0x2062, 0xC0, 0x1019, 0x8152, 0x1},
710 {0x2062, 0xC0, 0x1019, 0x2062, 0x1},
711 {0x2062, 0xC0, 0x1458, 0xE000, 0x1},
712 {0x2062, 0xC1, 0x1019, 0x8152, 0x1},
713 {0x2062, 0xC1, 0x1019, 0x2062, 0x1},
714 {0x2062, 0xC1, 0x1458, 0xE000, 0x1},
715 {0x2062, 0xC1, 0x1565, 0x2802, 0x1},
716 {0x2062, 0xC1, 0x1565, 0x2801, 0x1},
717 {0x1073, 0xC0, 0x1019, 0x8151, 0x1},
718 {0x1073, 0xC0, 0x1019, 0x1073, 0x1},
719 {0x1073, 0xC0, 0x1458, 0xE000, 0x1},
720 {0x1083, 0xC0, 0x1458, 0xE000, 0x1},
721 {0x1083, 0xC0, 0x1019, 0x8151, 0x1},
722 {0x1083, 0xC0, 0x1019, 0x1083, 0x1},
723 {0x1083, 0xC0, 0x1462, 0x7680, 0x1},
724 {0x1083, 0xC0, 0x1565, 0x2803, 0x1},
736 while (plats[i].pci_did != 0) {
790 if (atl1c_setup_mac_funcs(hw) != 0) {
791 dev_err(&pdev->
dev,
"set mac function pointers failed\n");
794 atl1c_patch_assign(hw);
814 if (atl1c_alloc_queues(adapter)) {
815 dev_err(&pdev->
dev,
"Unable to allocate memory for queues\n");
819 atl1c_set_rxbufsize(adapter, adapter->
netdev);
828 static inline void atl1c_clean_buffer(
struct pci_dev *pdev,
834 if (buffer_info->
dma) {
841 pci_unmap_single(pdev, buffer_info->
dma,
842 buffer_info->
length, pci_driection);
844 pci_unmap_page(pdev, buffer_info->
dma,
845 buffer_info->
length, pci_driection);
847 if (buffer_info->
skb) {
851 dev_kfree_skb(buffer_info->
skb);
853 buffer_info->
dma = 0;
861 static void atl1c_clean_tx_ring(
struct atl1c_adapter *adapter,
869 ring_count = tpd_ring->
count;
870 for (index = 0; index < ring_count; index++) {
872 atl1c_clean_buffer(pdev, buffer_info, 0);
886 static void atl1c_clean_rx_ring(
struct atl1c_adapter *adapter)
894 for (j = 0; j < rfd_ring->
count; j++) {
896 atl1c_clean_buffer(pdev, buffer_info, 0);
909 static void atl1c_init_ring_ptrs(
struct atl1c_adapter *adapter)
921 for (j = 0; j < tpd_ring->
count; j++)
929 for (j = 0; j < rfd_ring->
count; j++) {
941 static void atl1c_free_ring_resources(
struct atl1c_adapter *adapter)
952 if (adapter->
tpd_ring[0].buffer_info) {
964 static int atl1c_setup_ring_resources(
struct atl1c_adapter *adapter)
974 int rx_desc_count = 0;
979 tpd_ring[i].count = tpd_ring[0].count;
987 dev_err(&pdev->
dev,
"kzalloc failed, size = %d\n",
994 count += tpd_ring[
i].
count;
999 count += rfd_ring->
count;
1000 rx_desc_count += rfd_ring->
count;
1007 ring_header->
size = size =
1016 dev_err(&pdev->
dev,
"pci_alloc_consistend failed\n");
1023 offset = tpd_ring[0].
dma - ring_header->
dma;
1026 tpd_ring[
i].
desc = (
u8 *) ring_header->
desc + offset;
1029 offset +=
roundup(tpd_ring[i].size, 8);
1033 rfd_ring->
desc = (
u8 *) ring_header->
desc + offset;
1039 rrd_ring->
desc = (
u8 *) ring_header->
desc + offset;
1051 static void atl1c_configure_des_ring(
struct atl1c_adapter *adapter)
1105 static void atl1c_configure_tx(
struct atl1c_adapter *adapter)
1109 u16 tx_offload_thresh;
1132 static void atl1c_configure_rx(
struct atl1c_adapter *adapter)
1145 rxq_ctrl_data =
FIELD_SETX(rxq_ctrl_data, ASPM_THRUPUT_LIMIT,
1151 static void atl1c_configure_dma(
struct atl1c_adapter *adapter)
1170 static int atl1c_stop_mac(
struct atl1c_hw *hw)
1188 return (
int)atl1c_wait_until_idle(hw,
1229 static int atl1c_reset_mac(
struct atl1c_hw *hw)
1252 "MAC state machine can't be idle since"
1253 " disabled for 10ms second\n");
1282 static void atl1c_disable_l0s_l1(
struct atl1c_hw *hw)
1311 L1D_PMCTRL_L1_ENTRY_TM, link_l1_timer);
1318 PM_CTRL_L1_ENTRY_TIMER, link_l1_timer);
1345 FIELD_SETX(pm_ctrl_data, PM_CTRL_L1_ENTRY_TIMER, 0);
1373 static int atl1c_configure_mac(
struct atl1c_adapter *adapter)
1376 u32 master_ctrl_data = 0;
1377 u32 intr_modrt_data;
1404 atl1c_configure_des_ring(adapter);
1429 atl1c_configure_tx(adapter);
1430 atl1c_configure_rx(adapter);
1431 atl1c_configure_dma(adapter);
1441 atl1c_init_ring_ptrs(adapter);
1442 atl1c_set_multi(netdev);
1443 atl1c_restore_vlan(adapter);
1445 num = atl1c_alloc_rx_buffer(adapter);
1449 if (atl1c_configure_mac(adapter))
1455 static void atl1c_update_hw_stats(
struct atl1c_adapter *adapter)
1457 u16 hw_reg_addr = 0;
1458 unsigned long *stats_item =
NULL;
1463 stats_item = &adapter->
hw_stats.rx_ok;
1466 *stats_item +=
data;
1472 stats_item = &adapter->
hw_stats.tx_ok;
1475 *stats_item +=
data;
1494 atl1c_update_hw_stats(adapter);
1523 static inline void atl1c_clear_phy_int(
struct atl1c_adapter *adapter)
1532 static bool atl1c_clean_tx_irq(
struct atl1c_adapter *adapter,
1539 u16 hw_next_to_clean;
1546 while (next_to_clean != hw_next_to_clean) {
1547 buffer_info = &tpd_ring->
buffer_info[next_to_clean];
1548 atl1c_clean_buffer(pdev, buffer_info, 1);
1549 if (++next_to_clean == tpd_ring->
count)
1554 if (netif_queue_stopped(adapter->
netdev) &&
1555 netif_carrier_ok(adapter->
netdev)) {
1556 netif_wake_queue(adapter->
netdev);
1589 atl1c_clear_phy_int(adapter);
1593 if (
likely(napi_schedule_prep(&adapter->
napi))) {
1607 "atl1c hardware error (status = 0x%x)\n",
1608 status & ISR_ERROR);
1618 "TX/RX overflow (status = 0x%x)\n",
1623 netdev->
stats.tx_carrier_errors++;
1624 atl1c_link_chg_event(adapter);
1628 }
while (--max_ints > 0);
1634 static inline void atl1c_rx_checksum(
struct atl1c_adapter *adapter,
1642 skb_checksum_none_assert(skb);
1645 static int atl1c_alloc_rx_buffer(
struct atl1c_adapter *adapter)
1651 void *vir_addr =
NULL;
1653 u16 rfd_next_to_use, next_next;
1656 next_next = rfd_next_to_use = rfd_ring->
next_to_use;
1657 if (++next_next == rfd_ring->
count)
1659 buffer_info = &rfd_ring->
buffer_info[rfd_next_to_use];
1677 vir_addr = skb->
data;
1681 buffer_info->
dma = pci_map_single(pdev, vir_addr,
1687 rfd_next_to_use = next_next;
1688 if (++next_next == rfd_ring->
count)
1690 buffer_info = &rfd_ring->
buffer_info[rfd_next_to_use];
1728 for (i = 0; i < num; i++) {
1729 buffer_info[rfd_index].
skb =
NULL;
1732 if (++rfd_index == rfd_ring->
count)
1738 static void atl1c_clean_rx_irq(
struct atl1c_adapter *adapter,
1739 int *work_done,
int work_to_do)
1741 u16 rfd_num, rfd_index;
1753 if (*work_done >= work_to_do)
1763 "Multi rfd not support yet!\n");
1769 atl1c_clean_rrd(rrd_ring, rrs, rfd_num);
1771 atl1c_clean_rfd(rfd_ring, rrs, rfd_num);
1774 "wrong packet! rrs word3 is %x\n",
1782 if (
likely(rfd_num == 1)) {
1786 pci_unmap_single(pdev, buffer_info->
dma,
1788 skb = buffer_info->
skb;
1793 "Multi rfd not support yet!\n");
1796 atl1c_clean_rfd(rfd_ring, rrs, rfd_num);
1799 atl1c_rx_checksum(adapter, skb, rrs);
1805 __vlan_hwaccel_put_tag(skb, vlan);
1813 atl1c_alloc_rx_buffer(adapter);
1826 if (!netif_carrier_ok(adapter->
netdev))
1829 atl1c_clean_rx_irq(adapter, &work_done, budget);
1831 if (work_done < budget) {
1840 #ifdef CONFIG_NET_POLL_CONTROLLER
1847 static void atl1c_netpoll(
struct net_device *netdev)
1852 atl1c_intr(adapter->
pdev->irq, netdev);
1861 u16 next_to_clean = 0;
1867 (next_to_clean - next_to_use - 1) :
1868 (tpd_ring->
count + next_to_clean - next_to_use - 1);
1881 u16 next_to_use = 0;
1901 static u16 atl1c_cal_tpd_req(
const struct sk_buff *skb)
1904 u16 proto_hdr_len = 0;
1906 tpd_req = skb_shinfo(skb)->nr_frags + 1;
1908 if (skb_is_gso(skb)) {
1909 proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1910 if (proto_hdr_len < skb_headlen(skb))
1926 unsigned short offload_type;
1929 if (skb_is_gso(skb)) {
1930 if (skb_header_cloned(skb)) {
1935 offload_type = skb_shinfo(skb)->gso_type;
1938 real_len = (((
unsigned char *)ip_hdr(skb) - skb->
data)
1939 +
ntohs(ip_hdr(skb)->tot_len));
1941 if (real_len < skb->len)
1942 pskb_trim(skb, real_len);
1944 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
1949 "IPV4 tso with zero data??\n");
1952 ip_hdr(skb)->check = 0;
1966 *tpd = atl1c_get_tpd(adapter, type);
1967 ipv6_hdr(skb)->payload_len = 0;
1969 hdr_len = (skb_transport_offset(skb) + tcp_hdrlen(skb));
1974 "IPV6 tso with zero data??\n");
1978 &ipv6_hdr(skb)->
saddr,
1979 &ipv6_hdr(skb)->
daddr,
1990 (*tpd)->word1 |= (skb_shinfo(skb)->gso_size &
TPD_MSS_MASK) <<
1998 cso = skb_checksum_start_offset(skb);
2003 "payload offset should not an event number\n");
2024 u16 buf_len = skb_headlen(skb);
2032 nr_frags = skb_shinfo(skb)->nr_frags;
2036 map_len = hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2039 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
2040 buffer_info->
length = map_len;
2041 buffer_info->
dma = pci_map_single(adapter->
pdev,
2046 mapped_len += map_len;
2051 if (mapped_len < buf_len) {
2054 if (mapped_len == 0)
2057 use_tpd = atl1c_get_tpd(adapter, type);
2060 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
2061 buffer_info->
length = buf_len - mapped_len;
2063 pci_map_single(adapter->
pdev, skb->
data + mapped_len,
2072 for (f = 0; f < nr_frags; f++) {
2075 frag = &skb_shinfo(skb)->frags[
f];
2077 use_tpd = atl1c_get_tpd(adapter, type);
2080 buffer_info = atl1c_get_tx_buffer(adapter, use_tpd);
2081 buffer_info->
length = skb_frag_size(frag);
2082 buffer_info->
dma = skb_frag_dma_map(&adapter->
pdev->dev,
2114 unsigned long flags;
2124 tpd_req = atl1c_cal_tpd_req(skb);
2131 if (atl1c_tpd_avail(adapter, type) < tpd_req) {
2133 netif_stop_queue(netdev);
2134 spin_unlock_irqrestore(&adapter->
tx_lock, flags);
2138 tpd = atl1c_get_tpd(adapter, type);
2141 if (atl1c_tso_csum(adapter, skb, &tpd, type) != 0) {
2142 spin_unlock_irqrestore(&adapter->
tx_lock, flags);
2157 if (skb_network_offset(skb) !=
ETH_HLEN)
2160 atl1c_tx_map(adapter, skb, tpd, type);
2161 atl1c_tx_queue(adapter, skb, tpd, type);
2163 spin_unlock_irqrestore(&adapter->
tx_lock, flags);
2185 err = pci_enable_msi(adapter->
pdev);
2189 "Unable to allocate MSI interrupt Error: %d\n",
2197 netdev->
name, netdev);
2201 "Unable to allocate interrupt Error: %d\n",
2208 dev_dbg(&pdev->
dev,
"atl1c_request_irq OK\n");
2213 static void atl1c_reset_dma_ring(
struct atl1c_adapter *adapter)
2218 atl1c_clean_rx_ring(adapter);
2228 err = atl1c_configure(adapter);
2232 err = atl1c_request_irq(adapter);
2236 atl1c_check_link_status(adapter);
2238 napi_enable(&adapter->
napi);
2239 atl1c_irq_enable(adapter);
2240 netif_start_queue(netdev);
2244 atl1c_clean_rx_ring(adapter);
2252 atl1c_del_timer(adapter);
2258 napi_disable(&adapter->
napi);
2259 atl1c_irq_disable(adapter);
2260 atl1c_free_irq(adapter);
2262 atl1c_disable_l0s_l1(&adapter->
hw);
2264 atl1c_reset_mac(&adapter->
hw);
2269 atl1c_reset_dma_ring(adapter);
2284 static int atl1c_open(
struct net_device *netdev)
2294 err = atl1c_setup_ring_resources(adapter);
2298 err = atl1c_up(adapter);
2305 atl1c_free_irq(adapter);
2306 atl1c_free_ring_resources(adapter);
2307 atl1c_reset_mac(&adapter->
hw);
2322 static int atl1c_close(
struct net_device *netdev)
2329 atl1c_down(adapter);
2330 atl1c_free_ring_resources(adapter);
2334 static int atl1c_suspend(
struct device *dev)
2337 struct net_device *netdev = pci_get_drvdata(pdev);
2342 atl1c_disable_l0s_l1(hw);
2343 if (netif_running(netdev)) {
2345 atl1c_down(adapter);
2351 dev_dbg(&pdev->
dev,
"phy power saving failed");
2358 #ifdef CONFIG_PM_SLEEP
2359 static int atl1c_resume(
struct device *dev)
2362 struct net_device *netdev = pci_get_drvdata(pdev);
2369 atl1c_reset_mac(&adapter->
hw);
2374 pm_data &= ~PM_CTRLSTAT_PME_EN;
2379 if (netif_running(netdev))
2386 static void atl1c_shutdown(
struct pci_dev *pdev)
2388 struct net_device *netdev = pci_get_drvdata(pdev);
2391 atl1c_suspend(&pdev->
dev);
2397 .ndo_open = atl1c_open,
2398 .ndo_stop = atl1c_close,
2400 .ndo_start_xmit = atl1c_xmit_frame,
2401 .ndo_set_mac_address = atl1c_set_mac_addr,
2402 .ndo_set_rx_mode = atl1c_set_multi,
2403 .ndo_change_mtu = atl1c_change_mtu,
2404 .ndo_fix_features = atl1c_fix_features,
2405 .ndo_set_features = atl1c_set_features,
2406 .ndo_do_ioctl = atl1c_ioctl,
2407 .ndo_tx_timeout = atl1c_tx_timeout,
2408 .ndo_get_stats = atl1c_get_stats,
2409 #ifdef CONFIG_NET_POLL_CONTROLLER
2410 .ndo_poll_controller = atl1c_netpoll,
2417 pci_set_drvdata(pdev, netdev);
2426 NETIF_F_HW_VLAN_RX |
2450 static int cards_found;
2457 dev_err(&pdev->
dev,
"cannot enable PCI device\n");
2472 (pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32)) != 0)) {
2473 dev_err(&pdev->
dev,
"No usable DMA configuration,aborting\n");
2479 dev_err(&pdev->
dev,
"cannot obtain PCI resources\n");
2486 if (netdev ==
NULL) {
2488 goto err_alloc_etherdev;
2491 err = atl1c_init_netdev(netdev, pdev);
2493 dev_err(&pdev->
dev,
"init netdevice failed\n");
2494 goto err_init_netdev;
2496 adapter = netdev_priv(netdev);
2501 adapter->
msg_enable = netif_msg_init(-1, atl1c_default_msg);
2503 if (!adapter->
hw.hw_addr) {
2505 dev_err(&pdev->
dev,
"cannot map device registers\n");
2511 adapter->
mii.mdio_read = atl1c_mdio_read;
2512 adapter->
mii.mdio_write = atl1c_mdio_write;
2513 adapter->
mii.phy_id_mask = 0x1f;
2517 (
unsigned long)adapter);
2519 err = atl1c_sw_init(adapter);
2521 dev_err(&pdev->
dev,
"net device private data init failed\n");
2529 err = atl1c_reset_mac(&adapter->
hw);
2550 adapter->
hw.mac_addr);
2557 dev_err(&pdev->
dev,
"register netdevice failed\n");
2592 struct net_device *netdev = pci_get_drvdata(pdev);
2618 struct net_device *netdev = pci_get_drvdata(pdev);
2626 if (netif_running(netdev))
2627 atl1c_down(adapter);
2644 struct net_device *netdev = pci_get_drvdata(pdev);
2650 "Cannot re-enable PCI device after reset\n");
2658 atl1c_reset_mac(&adapter->
hw);
2671 static void atl1c_io_resume(
struct pci_dev *pdev)
2673 struct net_device *netdev = pci_get_drvdata(pdev);
2676 if (netif_running(netdev)) {
2677 if (atl1c_up(adapter)) {
2680 "Cannot bring device back up after reset\n");
2689 .error_detected = atl1c_io_error_detected,
2690 .slot_reset = atl1c_io_slot_reset,
2691 .resume = atl1c_io_resume,
2698 .id_table = atl1c_pci_tbl,
2699 .probe = atl1c_probe,
2701 .shutdown = atl1c_shutdown,
2702 .err_handler = &atl1c_err_handler,
2703 .driver.pm = &atl1c_pm_ops,
2712 static int __init atl1c_init_module(
void)
2714 return pci_register_driver(&atl1c_driver);
2723 static void __exit atl1c_exit_module(
void)