Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

stmmac: support new GMAC4

This patch adds the whole GMAC4 support inside the
stmmac d.d. now able to use the new HW and some new features
i.e.: TSO.
It is missing the multi-queue and split Header support at this
stage.
This patch also updates the driver version and the stmmac.txt.

Signed-off-by: Alexandre TORGUE <alexandre.torgue@st.com>
Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alexandre TORGUE and committed by
David S. Miller
f748be53 ee2ae1ed

+444 -54
+4
drivers/net/ethernet/stmicro/stmmac/common.h
··· 169 169 unsigned long mtl_rx_fifo_ctrl_active; 170 170 unsigned long mac_rx_frame_ctrl_fifo; 171 171 unsigned long mac_gmii_rx_proto_engine; 172 + /* TSO */ 173 + unsigned long tx_tso_frames; 174 + unsigned long tx_tso_nfrags; 172 175 }; 173 176 174 177 /* CSR Frequency Access Defines*/ ··· 548 545 void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr); 549 546 extern const struct stmmac_mode_ops ring_mode_ops; 550 547 extern const struct stmmac_mode_ops chain_mode_ops; 548 + extern const struct stmmac_desc_ops dwmac4_desc_ops; 551 549 552 550 /** 553 551 * stmmac_get_synopsys_id - return the SYINID.
+5 -1
drivers/net/ethernet/stmicro/stmmac/stmmac.h
··· 24 24 #define __STMMAC_H__ 25 25 26 26 #define STMMAC_RESOURCE_NAME "stmmaceth" 27 - #define DRV_MODULE_VERSION "Oct_2015" 27 + #define DRV_MODULE_VERSION "Dec_2015" 28 28 29 29 #include <linux/clk.h> 30 30 #include <linux/stmmac.h> ··· 67 67 spinlock_t tx_lock; 68 68 bool tx_path_in_lpi_mode; 69 69 struct timer_list txtimer; 70 + bool tso; 70 71 71 72 struct dma_desc *dma_rx ____cacheline_aligned_in_smp; 72 73 struct dma_extended_desc *dma_erx; ··· 130 129 int irq_wake; 131 130 spinlock_t ptp_lock; 132 131 void __iomem *mmcaddr; 132 + u32 rx_tail_addr; 133 + u32 tx_tail_addr; 134 + u32 mss; 133 135 134 136 #ifdef CONFIG_DEBUG_FS 135 137 struct dentry *dbgfs_dir;
+4 -1
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
··· 161 161 STMMAC_STAT(mtl_rx_fifo_ctrl_active), 162 162 STMMAC_STAT(mac_rx_frame_ctrl_fifo), 163 163 STMMAC_STAT(mac_gmii_rx_proto_engine), 164 + /* TSO */ 165 + STMMAC_STAT(tx_tso_frames), 166 + STMMAC_STAT(tx_tso_nfrags), 164 167 }; 165 168 #define STMMAC_STATS_LEN ARRAY_SIZE(stmmac_gstrings_stats) 166 169 ··· 502 499 int i, j = 0; 503 500 504 501 /* Update the DMA HW counters for dwmac10/100 */ 505 - if (!priv->plat->has_gmac) 502 + if (priv->hw->dma->dma_diagnostic_fr) 506 503 priv->hw->dma->dma_diagnostic_fr(&dev->stats, 507 504 (void *) &priv->xstats, 508 505 priv->ioaddr);
+431 -52
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 56 56 #include "dwmac1000.h" 57 57 58 58 #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x) 59 + #define TSO_MAX_BUFF_SIZE (SZ_16K - 1) 59 60 60 61 /* Module parameters */ 61 62 #define TX_TIMEO 5000 ··· 726 725 new_state = 1; 727 726 switch (phydev->speed) { 728 727 case 1000: 729 - if (likely(priv->plat->has_gmac)) 728 + if (likely((priv->plat->has_gmac) || 729 + (priv->plat->has_gmac4))) 730 730 ctrl &= ~priv->hw->link.port; 731 731 stmmac_hw_fix_mac_speed(priv); 732 732 break; 733 733 case 100: 734 734 case 10: 735 - if (priv->plat->has_gmac) { 735 + if (likely((priv->plat->has_gmac) || 736 + (priv->plat->has_gmac4))) { 736 737 ctrl |= priv->hw->link.port; 737 738 if (phydev->speed == SPEED_100) { 738 739 ctrl |= priv->hw->link.speed; ··· 974 971 return -EINVAL; 975 972 } 976 973 977 - p->des2 = priv->rx_skbuff_dma[i]; 974 + if (priv->synopsys_id >= DWMAC_CORE_4_00) 975 + p->des0 = priv->rx_skbuff_dma[i]; 976 + else 977 + p->des2 = priv->rx_skbuff_dma[i]; 978 978 979 979 if ((priv->hw->mode->init_desc3) && 980 980 (priv->dma_buf_sz == BUF_SIZE_16KiB)) ··· 1068 1062 p = &((priv->dma_etx + i)->basic); 1069 1063 else 1070 1064 p = priv->dma_tx + i; 1071 - p->des2 = 0; 1065 + 1066 + if (priv->synopsys_id >= DWMAC_CORE_4_00) { 1067 + p->des0 = 0; 1068 + p->des1 = 0; 1069 + p->des2 = 0; 1070 + p->des3 = 0; 1071 + } else { 1072 + p->des2 = 0; 1073 + } 1074 + 1072 1075 priv->tx_skbuff_dma[i].buf = 0; 1073 1076 priv->tx_skbuff_dma[i].map_as_page = false; 1074 1077 priv->tx_skbuff_dma[i].len = 0; ··· 1340 1325 priv->tx_skbuff_dma[entry].len, 1341 1326 DMA_TO_DEVICE); 1342 1327 priv->tx_skbuff_dma[entry].buf = 0; 1328 + priv->tx_skbuff_dma[entry].len = 0; 1343 1329 priv->tx_skbuff_dma[entry].map_as_page = false; 1344 1330 } 1345 - priv->hw->mode->clean_desc3(priv, p); 1331 + 1332 + if (priv->hw->mode->clean_desc3) 1333 + priv->hw->mode->clean_desc3(priv, p); 1334 + 1346 1335 priv->tx_skbuff_dma[entry].last_segment = false; 1347 1336 priv->tx_skbuff_dma[entry].is_jumbo = false; 1348 1337 ··· 1471 1452 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET | 1472 1453 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET; 1473 1454 1474 - priv->mmcaddr = priv->ioaddr + MMC_GMAC3_X_OFFSET; 1455 + if (priv->synopsys_id >= DWMAC_CORE_4_00) 1456 + priv->mmcaddr = priv->ioaddr + MMC_GMAC4_OFFSET; 1457 + else 1458 + priv->mmcaddr = priv->ioaddr + MMC_GMAC3_X_OFFSET; 1475 1459 1476 1460 dwmac_mmc_intr_all_mask(priv->mmcaddr); 1477 1461 ··· 1586 1564 priv->hw->dma->init(priv->ioaddr, pbl, fixed_burst, mixed_burst, 1587 1565 aal, priv->dma_tx_phy, priv->dma_rx_phy, atds); 1588 1566 1589 - if ((priv->synopsys_id >= DWMAC_CORE_3_50) && 1590 - (priv->plat->axi && priv->hw->dma->axi)) 1567 + if (priv->synopsys_id >= DWMAC_CORE_4_00) { 1568 + priv->rx_tail_addr = priv->dma_rx_phy + 1569 + (DMA_RX_SIZE * sizeof(struct dma_desc)); 1570 + priv->hw->dma->set_rx_tail_ptr(priv->ioaddr, priv->rx_tail_addr, 1571 + STMMAC_CHAN0); 1572 + 1573 + priv->tx_tail_addr = priv->dma_tx_phy + 1574 + (DMA_TX_SIZE * sizeof(struct dma_desc)); 1575 + priv->hw->dma->set_tx_tail_ptr(priv->ioaddr, priv->tx_tail_addr, 1576 + STMMAC_CHAN0); 1577 + } 1578 + 1579 + if (priv->plat->axi && priv->hw->dma->axi) 1591 1580 priv->hw->dma->axi(priv->ioaddr, priv->plat->axi); 1592 1581 1593 1582 return ret; ··· 1678 1645 } 1679 1646 1680 1647 /* Enable the MAC Rx/Tx */ 1681 - stmmac_set_mac(priv->ioaddr, true); 1648 + if (priv->synopsys_id >= DWMAC_CORE_4_00) 1649 + stmmac_dwmac4_set_mac(priv->ioaddr, true); 1650 + else 1651 + stmmac_set_mac(priv->ioaddr, true); 1682 1652 1683 1653 /* Set the HW DMA mode and the COE */ 1684 1654 stmmac_dma_operation_mode(priv); ··· 1718 1682 1719 1683 if (priv->pcs && priv->hw->mac->ctrl_ane) 1720 1684 priv->hw->mac->ctrl_ane(priv->hw, 0); 1685 + 1686 + /* set TX ring length */ 1687 + if (priv->hw->dma->set_tx_ring_len) 1688 + priv->hw->dma->set_tx_ring_len(priv->ioaddr, 1689 + (DMA_TX_SIZE - 1)); 1690 + /* set RX ring length */ 1691 + if (priv->hw->dma->set_rx_ring_len) 1692 + priv->hw->dma->set_rx_ring_len(priv->ioaddr, 1693 + (DMA_RX_SIZE - 1)); 1694 + /* Enable TSO */ 1695 + if (priv->tso) 1696 + priv->hw->dma->enable_tso(priv->ioaddr, 1, STMMAC_CHAN0); 1721 1697 1722 1698 return 0; 1723 1699 } ··· 1896 1848 } 1897 1849 1898 1850 /** 1851 + * stmmac_tso_allocator - close entry point of the driver 1852 + * @priv: driver private structure 1853 + * @des: buffer start address 1854 + * @total_len: total length to fill in descriptors 1855 + * @last_segmant: condition for the last descriptor 1856 + * Description: 1857 + * This function fills descriptor and request new descriptors according to 1858 + * buffer length to fill 1859 + */ 1860 + static void stmmac_tso_allocator(struct stmmac_priv *priv, unsigned int des, 1861 + int total_len, bool last_segment) 1862 + { 1863 + struct dma_desc *desc; 1864 + int tmp_len; 1865 + u32 buff_size; 1866 + 1867 + tmp_len = total_len; 1868 + 1869 + while (tmp_len > 0) { 1870 + priv->cur_tx = STMMAC_GET_ENTRY(priv->cur_tx, DMA_TX_SIZE); 1871 + desc = priv->dma_tx + priv->cur_tx; 1872 + 1873 + desc->des0 = des + (total_len - tmp_len); 1874 + buff_size = tmp_len >= TSO_MAX_BUFF_SIZE ? 1875 + TSO_MAX_BUFF_SIZE : tmp_len; 1876 + 1877 + priv->hw->desc->prepare_tso_tx_desc(desc, 0, buff_size, 1878 + 0, 1, 1879 + (last_segment) && (buff_size < TSO_MAX_BUFF_SIZE), 1880 + 0, 0); 1881 + 1882 + tmp_len -= TSO_MAX_BUFF_SIZE; 1883 + } 1884 + } 1885 + 1886 + /** 1887 + * stmmac_tso_xmit - Tx entry point of the driver for oversized frames (TSO) 1888 + * @skb : the socket buffer 1889 + * @dev : device pointer 1890 + * Description: this is the transmit function that is called on TSO frames 1891 + * (support available on GMAC4 and newer chips). 1892 + * Diagram below show the ring programming in case of TSO frames: 1893 + * 1894 + * First Descriptor 1895 + * -------- 1896 + * | DES0 |---> buffer1 = L2/L3/L4 header 1897 + * | DES1 |---> TCP Payload (can continue on next descr...) 1898 + * | DES2 |---> buffer 1 and 2 len 1899 + * | DES3 |---> must set TSE, TCP hdr len-> [22:19]. TCP payload len [17:0] 1900 + * -------- 1901 + * | 1902 + * ... 1903 + * | 1904 + * -------- 1905 + * | DES0 | --| Split TCP Payload on Buffers 1 and 2 1906 + * | DES1 | --| 1907 + * | DES2 | --> buffer 1 and 2 len 1908 + * | DES3 | 1909 + * -------- 1910 + * 1911 + * mss is fixed when enable tso, so w/o programming the TDES3 ctx field. 1912 + */ 1913 + static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) 1914 + { 1915 + u32 pay_len, mss; 1916 + int tmp_pay_len = 0; 1917 + struct stmmac_priv *priv = netdev_priv(dev); 1918 + int nfrags = skb_shinfo(skb)->nr_frags; 1919 + unsigned int first_entry, des; 1920 + struct dma_desc *desc, *first, *mss_desc = NULL; 1921 + u8 proto_hdr_len; 1922 + int i; 1923 + 1924 + spin_lock(&priv->tx_lock); 1925 + 1926 + /* Compute header lengths */ 1927 + proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); 1928 + 1929 + /* Desc availability based on threshold should be enough safe */ 1930 + if (unlikely(stmmac_tx_avail(priv) < 1931 + (((skb->len - proto_hdr_len) / TSO_MAX_BUFF_SIZE + 1)))) { 1932 + if (!netif_queue_stopped(dev)) { 1933 + netif_stop_queue(dev); 1934 + /* This is a hard error, log it. */ 1935 + pr_err("%s: Tx Ring full when queue awake\n", __func__); 1936 + } 1937 + spin_unlock(&priv->tx_lock); 1938 + return NETDEV_TX_BUSY; 1939 + } 1940 + 1941 + pay_len = skb_headlen(skb) - proto_hdr_len; /* no frags */ 1942 + 1943 + mss = skb_shinfo(skb)->gso_size; 1944 + 1945 + /* set new MSS value if needed */ 1946 + if (mss != priv->mss) { 1947 + mss_desc = priv->dma_tx + priv->cur_tx; 1948 + priv->hw->desc->set_mss(mss_desc, mss); 1949 + priv->mss = mss; 1950 + priv->cur_tx = STMMAC_GET_ENTRY(priv->cur_tx, DMA_TX_SIZE); 1951 + } 1952 + 1953 + if (netif_msg_tx_queued(priv)) { 1954 + pr_info("%s: tcphdrlen %d, hdr_len %d, pay_len %d, mss %d\n", 1955 + __func__, tcp_hdrlen(skb), proto_hdr_len, pay_len, mss); 1956 + pr_info("\tskb->len %d, skb->data_len %d\n", skb->len, 1957 + skb->data_len); 1958 + } 1959 + 1960 + first_entry = priv->cur_tx; 1961 + 1962 + desc = priv->dma_tx + first_entry; 1963 + first = desc; 1964 + 1965 + /* first descriptor: fill Headers on Buf1 */ 1966 + des = dma_map_single(priv->device, skb->data, skb_headlen(skb), 1967 + DMA_TO_DEVICE); 1968 + if (dma_mapping_error(priv->device, des)) 1969 + goto dma_map_err; 1970 + 1971 + priv->tx_skbuff_dma[first_entry].buf = des; 1972 + priv->tx_skbuff_dma[first_entry].len = skb_headlen(skb); 1973 + priv->tx_skbuff[first_entry] = skb; 1974 + 1975 + first->des0 = des; 1976 + 1977 + /* Fill start of payload in buff2 of first descriptor */ 1978 + if (pay_len) 1979 + first->des1 = des + proto_hdr_len; 1980 + 1981 + /* If needed take extra descriptors to fill the remaining payload */ 1982 + tmp_pay_len = pay_len - TSO_MAX_BUFF_SIZE; 1983 + 1984 + stmmac_tso_allocator(priv, des, tmp_pay_len, (nfrags == 0)); 1985 + 1986 + /* Prepare fragments */ 1987 + for (i = 0; i < nfrags; i++) { 1988 + const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1989 + 1990 + des = skb_frag_dma_map(priv->device, frag, 0, 1991 + skb_frag_size(frag), 1992 + DMA_TO_DEVICE); 1993 + 1994 + stmmac_tso_allocator(priv, des, skb_frag_size(frag), 1995 + (i == nfrags - 1)); 1996 + 1997 + priv->tx_skbuff_dma[priv->cur_tx].buf = des; 1998 + priv->tx_skbuff_dma[priv->cur_tx].len = skb_frag_size(frag); 1999 + priv->tx_skbuff[priv->cur_tx] = NULL; 2000 + priv->tx_skbuff_dma[priv->cur_tx].map_as_page = true; 2001 + } 2002 + 2003 + priv->tx_skbuff_dma[priv->cur_tx].last_segment = true; 2004 + 2005 + priv->cur_tx = STMMAC_GET_ENTRY(priv->cur_tx, DMA_TX_SIZE); 2006 + 2007 + if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) { 2008 + if (netif_msg_hw(priv)) 2009 + pr_debug("%s: stop transmitted packets\n", __func__); 2010 + netif_stop_queue(dev); 2011 + } 2012 + 2013 + dev->stats.tx_bytes += skb->len; 2014 + priv->xstats.tx_tso_frames++; 2015 + priv->xstats.tx_tso_nfrags += nfrags; 2016 + 2017 + /* Manage tx mitigation */ 2018 + priv->tx_count_frames += nfrags + 1; 2019 + if (likely(priv->tx_coal_frames > priv->tx_count_frames)) { 2020 + mod_timer(&priv->txtimer, 2021 + STMMAC_COAL_TIMER(priv->tx_coal_timer)); 2022 + } else { 2023 + priv->tx_count_frames = 0; 2024 + priv->hw->desc->set_tx_ic(desc); 2025 + priv->xstats.tx_set_ic_bit++; 2026 + } 2027 + 2028 + if (!priv->hwts_tx_en) 2029 + skb_tx_timestamp(skb); 2030 + 2031 + if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && 2032 + priv->hwts_tx_en)) { 2033 + /* declare that device is doing timestamping */ 2034 + skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 2035 + priv->hw->desc->enable_tx_timestamp(first); 2036 + } 2037 + 2038 + /* Complete the first descriptor before granting the DMA */ 2039 + priv->hw->desc->prepare_tso_tx_desc(first, 1, 2040 + proto_hdr_len, 2041 + pay_len, 2042 + 1, priv->tx_skbuff_dma[first_entry].last_segment, 2043 + tcp_hdrlen(skb) / 4, (skb->len - proto_hdr_len)); 2044 + 2045 + /* If context desc is used to change MSS */ 2046 + if (mss_desc) 2047 + priv->hw->desc->set_tx_owner(mss_desc); 2048 + 2049 + /* The own bit must be the latest setting done when prepare the 2050 + * descriptor and then barrier is needed to make sure that 2051 + * all is coherent before granting the DMA engine. 2052 + */ 2053 + smp_wmb(); 2054 + 2055 + if (netif_msg_pktdata(priv)) { 2056 + pr_info("%s: curr=%d dirty=%d f=%d, e=%d, f_p=%p, nfrags %d\n", 2057 + __func__, priv->cur_tx, priv->dirty_tx, first_entry, 2058 + priv->cur_tx, first, nfrags); 2059 + 2060 + priv->hw->desc->display_ring((void *)priv->dma_tx, DMA_TX_SIZE, 2061 + 0); 2062 + 2063 + pr_info(">>> frame to be transmitted: "); 2064 + print_pkt(skb->data, skb_headlen(skb)); 2065 + } 2066 + 2067 + netdev_sent_queue(dev, skb->len); 2068 + 2069 + priv->hw->dma->set_tx_tail_ptr(priv->ioaddr, priv->tx_tail_addr, 2070 + STMMAC_CHAN0); 2071 + 2072 + spin_unlock(&priv->tx_lock); 2073 + return NETDEV_TX_OK; 2074 + 2075 + dma_map_err: 2076 + spin_unlock(&priv->tx_lock); 2077 + dev_err(priv->device, "Tx dma map failed\n"); 2078 + dev_kfree_skb(skb); 2079 + priv->dev->stats.tx_dropped++; 2080 + return NETDEV_TX_OK; 2081 + } 2082 + 2083 + /** 1899 2084 * stmmac_xmit - Tx entry point of the driver 1900 2085 * @skb : the socket buffer 1901 2086 * @dev : device pointer ··· 2145 1864 unsigned int entry, first_entry; 2146 1865 struct dma_desc *desc, *first; 2147 1866 unsigned int enh_desc; 1867 + unsigned int des; 1868 + 1869 + /* Manage oversized TCP frames for GMAC4 device */ 1870 + if (skb_is_gso(skb) && priv->tso) { 1871 + if (ip_hdr(skb)->protocol == IPPROTO_TCP) 1872 + return stmmac_tso_xmit(skb, dev); 1873 + } 2148 1874 2149 1875 spin_lock(&priv->tx_lock); 2150 1876 ··· 2187 1899 if (enh_desc) 2188 1900 is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc); 2189 1901 2190 - if (unlikely(is_jumbo)) { 1902 + if (unlikely(is_jumbo) && likely(priv->synopsys_id < 1903 + DWMAC_CORE_4_00)) { 2191 1904 entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion); 2192 1905 if (unlikely(entry < 0)) 2193 1906 goto dma_map_err; ··· 2206 1917 else 2207 1918 desc = priv->dma_tx + entry; 2208 1919 2209 - desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len, 2210 - DMA_TO_DEVICE); 2211 - if (dma_mapping_error(priv->device, desc->des2)) 1920 + des = skb_frag_dma_map(priv->device, frag, 0, len, 1921 + DMA_TO_DEVICE); 1922 + if (dma_mapping_error(priv->device, des)) 2212 1923 goto dma_map_err; /* should reuse desc w/o issues */ 2213 1924 2214 1925 priv->tx_skbuff[entry] = NULL; 2215 - priv->tx_skbuff_dma[entry].buf = desc->des2; 1926 + 1927 + if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) { 1928 + desc->des0 = des; 1929 + priv->tx_skbuff_dma[entry].buf = desc->des0; 1930 + } else { 1931 + desc->des2 = des; 1932 + priv->tx_skbuff_dma[entry].buf = desc->des2; 1933 + } 1934 + 2216 1935 priv->tx_skbuff_dma[entry].map_as_page = true; 2217 1936 priv->tx_skbuff_dma[entry].len = len; 2218 1937 priv->tx_skbuff_dma[entry].last_segment = last_segment; ··· 2285 1988 if (likely(!is_jumbo)) { 2286 1989 bool last_segment = (nfrags == 0); 2287 1990 2288 - first->des2 = dma_map_single(priv->device, skb->data, 2289 - nopaged_len, DMA_TO_DEVICE); 2290 - if (dma_mapping_error(priv->device, first->des2)) 1991 + des = dma_map_single(priv->device, skb->data, 1992 + nopaged_len, DMA_TO_DEVICE); 1993 + if (dma_mapping_error(priv->device, des)) 2291 1994 goto dma_map_err; 2292 1995 2293 - priv->tx_skbuff_dma[first_entry].buf = first->des2; 1996 + if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) { 1997 + first->des0 = des; 1998 + priv->tx_skbuff_dma[first_entry].buf = first->des0; 1999 + } else { 2000 + first->des2 = des; 2001 + priv->tx_skbuff_dma[first_entry].buf = first->des2; 2002 + } 2003 + 2294 2004 priv->tx_skbuff_dma[first_entry].len = nopaged_len; 2295 2005 priv->tx_skbuff_dma[first_entry].last_segment = last_segment; 2296 2006 ··· 2321 2017 } 2322 2018 2323 2019 netdev_sent_queue(dev, skb->len); 2324 - priv->hw->dma->enable_dma_transmission(priv->ioaddr); 2020 + 2021 + if (priv->synopsys_id < DWMAC_CORE_4_00) 2022 + priv->hw->dma->enable_dma_transmission(priv->ioaddr); 2023 + else 2024 + priv->hw->dma->set_tx_tail_ptr(priv->ioaddr, priv->tx_tail_addr, 2025 + STMMAC_CHAN0); 2325 2026 2326 2027 spin_unlock(&priv->tx_lock); 2327 2028 return NETDEV_TX_OK; ··· 2408 2099 dev_kfree_skb(skb); 2409 2100 break; 2410 2101 } 2411 - p->des2 = priv->rx_skbuff_dma[entry]; 2412 2102 2413 - priv->hw->mode->refill_desc3(priv, p); 2103 + if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) { 2104 + p->des0 = priv->rx_skbuff_dma[entry]; 2105 + p->des1 = 0; 2106 + } else { 2107 + p->des2 = priv->rx_skbuff_dma[entry]; 2108 + } 2109 + if (priv->hw->mode->refill_desc3) 2110 + priv->hw->mode->refill_desc3(priv, p); 2414 2111 2415 2112 if (priv->rx_zeroc_thresh > 0) 2416 2113 priv->rx_zeroc_thresh--; ··· 2424 2109 if (netif_msg_rx_status(priv)) 2425 2110 pr_debug("\trefill entry #%d\n", entry); 2426 2111 } 2427 - 2428 2112 wmb(); 2429 - priv->hw->desc->set_rx_owner(p); 2113 + 2114 + if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) 2115 + priv->hw->desc->init_rx_desc(p, priv->use_riwt, 0, 0); 2116 + else 2117 + priv->hw->desc->set_rx_owner(p); 2118 + 2430 2119 wmb(); 2431 2120 2432 2121 entry = STMMAC_GET_ENTRY(entry, DMA_RX_SIZE); ··· 2511 2192 } else { 2512 2193 struct sk_buff *skb; 2513 2194 int frame_len; 2195 + unsigned int des; 2196 + 2197 + if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) 2198 + des = p->des0; 2199 + else 2200 + des = p->des2; 2514 2201 2515 2202 frame_len = priv->hw->desc->get_rx_frame_len(p, coe); 2516 2203 2517 - /* check if frame_len fits the preallocated memory */ 2204 + /* If frame length is greather than skb buffer size 2205 + * (preallocated during init) then the packet is 2206 + * ignored 2207 + */ 2518 2208 if (frame_len > priv->dma_buf_sz) { 2209 + pr_err("%s: len %d larger than size (%d)\n", 2210 + priv->dev->name, frame_len, 2211 + priv->dma_buf_sz); 2519 2212 priv->dev->stats.rx_length_errors++; 2520 2213 break; 2521 2214 } ··· 2540 2209 2541 2210 if (netif_msg_rx_status(priv)) { 2542 2211 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n", 2543 - p, entry, p->des2); 2212 + p, entry, des); 2544 2213 if (frame_len > ETH_FRAME_LEN) 2545 2214 pr_debug("\tframe size %d, COE: %d\n", 2546 2215 frame_len, status); 2547 2216 } 2548 2217 2549 - if (unlikely((frame_len < priv->rx_copybreak) || 2550 - stmmac_rx_threshold_count(priv))) { 2218 + /* The zero-copy is always used for all the sizes 2219 + * in case of GMAC4 because it needs 2220 + * to refill the used descriptors, always. 2221 + */ 2222 + if (unlikely(!priv->plat->has_gmac4 && 2223 + ((frame_len < priv->rx_copybreak) || 2224 + stmmac_rx_threshold_count(priv)))) { 2551 2225 skb = netdev_alloc_skb_ip_align(priv->dev, 2552 2226 frame_len); 2553 2227 if (unlikely(!skb)) { ··· 2704 2368 return -EBUSY; 2705 2369 } 2706 2370 2707 - if (priv->plat->enh_desc) 2371 + if ((priv->plat->enh_desc) || (priv->synopsys_id >= DWMAC_CORE_4_00)) 2708 2372 max_mtu = JUMBO_LEN; 2709 2373 else 2710 2374 max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN); ··· 2718 2382 } 2719 2383 2720 2384 dev->mtu = new_mtu; 2385 + 2721 2386 netdev_update_features(dev); 2722 2387 2723 2388 return 0; ··· 2742 2405 */ 2743 2406 if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN)) 2744 2407 features &= ~NETIF_F_CSUM_MASK; 2408 + 2409 + /* Disable tso if asked by ethtool */ 2410 + if ((priv->plat->tso_en) && (priv->dma_cap.tsoen)) { 2411 + if (features & NETIF_F_TSO) 2412 + priv->tso = true; 2413 + else 2414 + priv->tso = false; 2415 + } 2745 2416 2746 2417 return features; 2747 2418 } ··· 2797 2452 } 2798 2453 2799 2454 /* To handle GMAC own interrupts */ 2800 - if (priv->plat->has_gmac) { 2455 + if ((priv->plat->has_gmac) || (priv->plat->has_gmac4)) { 2801 2456 int status = priv->hw->mac->host_irq_status(priv->hw, 2802 2457 &priv->xstats); 2803 2458 if (unlikely(status)) { ··· 2806 2461 priv->tx_path_in_lpi_mode = true; 2807 2462 if (status & CORE_IRQ_TX_PATH_EXIT_LPI_MODE) 2808 2463 priv->tx_path_in_lpi_mode = false; 2464 + if (status & CORE_IRQ_MTL_RX_OVERFLOW) 2465 + priv->hw->dma->set_rx_tail_ptr(priv->ioaddr, 2466 + priv->rx_tail_addr, 2467 + STMMAC_CHAN0); 2809 2468 } 2810 2469 } 2811 2470 ··· 2882 2533 x = *(u64 *) ep; 2883 2534 seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n", 2884 2535 i, (unsigned int)virt_to_phys(ep), 2885 - (unsigned int)x, (unsigned int)(x >> 32), 2536 + ep->basic.des0, ep->basic.des1, 2886 2537 ep->basic.des2, ep->basic.des3); 2887 2538 ep++; 2888 2539 } else { 2889 2540 x = *(u64 *) p; 2890 2541 seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n", 2891 2542 i, (unsigned int)virt_to_phys(ep), 2892 - (unsigned int)x, (unsigned int)(x >> 32), 2893 - p->des2, p->des3); 2543 + p->des0, p->des1, p->des2, p->des3); 2894 2544 p++; 2895 2545 } 2896 2546 seq_printf(seq, "\n"); ··· 2972 2624 seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N"); 2973 2625 seq_printf(seq, "\tChecksum Offload in TX: %s\n", 2974 2626 (priv->dma_cap.tx_coe) ? "Y" : "N"); 2975 - seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n", 2976 - (priv->dma_cap.rx_coe_type1) ? "Y" : "N"); 2977 - seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n", 2978 - (priv->dma_cap.rx_coe_type2) ? "Y" : "N"); 2627 + if (priv->synopsys_id >= DWMAC_CORE_4_00) { 2628 + seq_printf(seq, "\tIP Checksum Offload in RX: %s\n", 2629 + (priv->dma_cap.rx_coe) ? "Y" : "N"); 2630 + } else { 2631 + seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n", 2632 + (priv->dma_cap.rx_coe_type1) ? "Y" : "N"); 2633 + seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n", 2634 + (priv->dma_cap.rx_coe_type2) ? "Y" : "N"); 2635 + } 2979 2636 seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n", 2980 2637 (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N"); 2981 2638 seq_printf(seq, "\tNumber of Additional RX channel: %d\n", ··· 3091 2738 priv->plat->multicast_filter_bins, 3092 2739 priv->plat->unicast_filter_entries, 3093 2740 &priv->synopsys_id); 2741 + } else if (priv->plat->has_gmac4) { 2742 + priv->dev->priv_flags |= IFF_UNICAST_FLT; 2743 + mac = dwmac4_setup(priv->ioaddr, 2744 + priv->plat->multicast_filter_bins, 2745 + priv->plat->unicast_filter_entries, 2746 + &priv->synopsys_id); 3094 2747 } else { 3095 2748 mac = dwmac100_setup(priv->ioaddr, &priv->synopsys_id); 3096 2749 } ··· 3106 2747 priv->hw = mac; 3107 2748 3108 2749 /* To use the chained or ring mode */ 3109 - if (chain_mode) { 3110 - priv->hw->mode = &chain_mode_ops; 3111 - pr_info(" Chain mode enabled\n"); 3112 - priv->mode = STMMAC_CHAIN_MODE; 2750 + if (priv->synopsys_id >= DWMAC_CORE_4_00) { 2751 + priv->hw->mode = &dwmac4_ring_mode_ops; 3113 2752 } else { 3114 - priv->hw->mode = &ring_mode_ops; 3115 - pr_info(" Ring mode enabled\n"); 3116 - priv->mode = STMMAC_RING_MODE; 2753 + if (chain_mode) { 2754 + priv->hw->mode = &chain_mode_ops; 2755 + pr_info(" Chain mode enabled\n"); 2756 + priv->mode = STMMAC_CHAIN_MODE; 2757 + } else { 2758 + priv->hw->mode = &ring_mode_ops; 2759 + pr_info(" Ring mode enabled\n"); 2760 + priv->mode = STMMAC_RING_MODE; 2761 + } 3117 2762 } 3118 2763 3119 2764 /* Get the HW capability (new GMAC newer than 3.50a) */ ··· 3133 2770 priv->plat->enh_desc = priv->dma_cap.enh_desc; 3134 2771 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up; 3135 2772 3136 - /* TXCOE doesn't work in thresh DMA mode */ 3137 - if (priv->plat->force_thresh_dma_mode) 3138 - priv->plat->tx_coe = 0; 3139 - else 3140 - priv->plat->tx_coe = priv->dma_cap.tx_coe; 2773 + priv->plat->tx_coe = priv->dma_cap.tx_coe; 2774 + /* In case of GMAC4 rx_coe is from HW cap register. */ 2775 + priv->plat->rx_coe = priv->dma_cap.rx_coe; 3141 2776 3142 2777 if (priv->dma_cap.rx_coe_type2) 3143 2778 priv->plat->rx_coe = STMMAC_RX_COE_TYPE2; ··· 3145 2784 } else 3146 2785 pr_info(" No HW DMA feature register supported"); 3147 2786 3148 - /* To use alternate (extended) or normal descriptor structures */ 3149 - stmmac_selec_desc_mode(priv); 2787 + /* To use alternate (extended), normal or GMAC4 descriptor structures */ 2788 + if (priv->synopsys_id >= DWMAC_CORE_4_00) 2789 + priv->hw->desc = &dwmac4_desc_ops; 2790 + else 2791 + stmmac_selec_desc_mode(priv); 3150 2792 3151 2793 if (priv->plat->rx_coe) { 3152 2794 priv->hw->rx_csum = priv->plat->rx_coe; 3153 - pr_info(" RX Checksum Offload Engine supported (type %d)\n", 3154 - priv->plat->rx_coe); 2795 + pr_info(" RX Checksum Offload Engine supported\n"); 2796 + if (priv->synopsys_id < DWMAC_CORE_4_00) 2797 + pr_info("\tCOE Type %d\n", priv->hw->rx_csum); 3155 2798 } 3156 2799 if (priv->plat->tx_coe) 3157 2800 pr_info(" TX Checksum insertion supported\n"); ··· 3164 2799 pr_info(" Wake-Up On Lan supported\n"); 3165 2800 device_set_wakeup_capable(priv->device, 1); 3166 2801 } 2802 + 2803 + if (priv->dma_cap.tsoen) 2804 + pr_info(" TSO supported\n"); 3167 2805 3168 2806 return 0; 3169 2807 } ··· 3271 2903 3272 2904 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 3273 2905 NETIF_F_RXCSUM; 2906 + 2907 + if ((priv->plat->tso_en) && (priv->dma_cap.tsoen)) { 2908 + ndev->hw_features |= NETIF_F_TSO; 2909 + priv->tso = true; 2910 + pr_info(" TSO feature enabled\n"); 2911 + } 3274 2912 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; 3275 2913 ndev->watchdog_timeo = msecs_to_jiffies(watchdog); 3276 2914 #ifdef STMMAC_VLAN_TAG_USED ··· 3471 3097 priv->dirty_rx = 0; 3472 3098 priv->dirty_tx = 0; 3473 3099 priv->cur_tx = 0; 3100 + /* reset private mss value to force mss context settings at 3101 + * next tso xmit (only used for gmac4). 3102 + */ 3103 + priv->mss = 0; 3104 + 3474 3105 stmmac_clear_descriptors(priv); 3475 3106 3476 3107 stmmac_hw_setup(ndev, false);