148863ce5SAlexandre TORGUE /* 248863ce5SAlexandre TORGUE * This is the driver for the GMAC on-chip Ethernet controller for ST SoCs. 348863ce5SAlexandre TORGUE * DWC Ether MAC version 4.xx has been used for developing this code. 448863ce5SAlexandre TORGUE * 548863ce5SAlexandre TORGUE * This contains the functions to handle the dma. 648863ce5SAlexandre TORGUE * 748863ce5SAlexandre TORGUE * Copyright (C) 2015 STMicroelectronics Ltd 848863ce5SAlexandre TORGUE * 948863ce5SAlexandre TORGUE * This program is free software; you can redistribute it and/or modify it 1048863ce5SAlexandre TORGUE * under the terms and conditions of the GNU General Public License, 1148863ce5SAlexandre TORGUE * version 2, as published by the Free Software Foundation. 1248863ce5SAlexandre TORGUE * 1348863ce5SAlexandre TORGUE * Author: Alexandre Torgue <alexandre.torgue@st.com> 1448863ce5SAlexandre TORGUE */ 1548863ce5SAlexandre TORGUE 1648863ce5SAlexandre TORGUE #include <linux/io.h> 1748863ce5SAlexandre TORGUE #include "dwmac4.h" 1848863ce5SAlexandre TORGUE #include "dwmac4_dma.h" 1948863ce5SAlexandre TORGUE 2048863ce5SAlexandre TORGUE static void dwmac4_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) 2148863ce5SAlexandre TORGUE { 2248863ce5SAlexandre TORGUE u32 value = readl(ioaddr + DMA_SYS_BUS_MODE); 2348863ce5SAlexandre TORGUE int i; 2448863ce5SAlexandre TORGUE 2548863ce5SAlexandre TORGUE pr_info("dwmac4: Master AXI performs %s burst length\n", 2648863ce5SAlexandre TORGUE (value & DMA_SYS_BUS_FB) ? "fixed" : "any"); 2748863ce5SAlexandre TORGUE 2848863ce5SAlexandre TORGUE if (axi->axi_lpi_en) 2948863ce5SAlexandre TORGUE value |= DMA_AXI_EN_LPI; 3048863ce5SAlexandre TORGUE if (axi->axi_xit_frm) 3148863ce5SAlexandre TORGUE value |= DMA_AXI_LPI_XIT_FRM; 3248863ce5SAlexandre TORGUE 336b3374cbSNiklas Cassel value &= ~DMA_AXI_WR_OSR_LMT; 3448863ce5SAlexandre TORGUE value |= (axi->axi_wr_osr_lmt & DMA_AXI_OSR_MAX) << 3548863ce5SAlexandre TORGUE DMA_AXI_WR_OSR_LMT_SHIFT; 3648863ce5SAlexandre TORGUE 376b3374cbSNiklas Cassel value &= ~DMA_AXI_RD_OSR_LMT; 3848863ce5SAlexandre TORGUE value |= (axi->axi_rd_osr_lmt & DMA_AXI_OSR_MAX) << 3948863ce5SAlexandre TORGUE DMA_AXI_RD_OSR_LMT_SHIFT; 4048863ce5SAlexandre TORGUE 4148863ce5SAlexandre TORGUE /* Depending on the UNDEF bit the Master AXI will perform any burst 4248863ce5SAlexandre TORGUE * length according to the BLEN programmed (by default all BLEN are 4348863ce5SAlexandre TORGUE * set). 4448863ce5SAlexandre TORGUE */ 4548863ce5SAlexandre TORGUE for (i = 0; i < AXI_BLEN; i++) { 4648863ce5SAlexandre TORGUE switch (axi->axi_blen[i]) { 4748863ce5SAlexandre TORGUE case 256: 4848863ce5SAlexandre TORGUE value |= DMA_AXI_BLEN256; 4948863ce5SAlexandre TORGUE break; 5048863ce5SAlexandre TORGUE case 128: 5148863ce5SAlexandre TORGUE value |= DMA_AXI_BLEN128; 5248863ce5SAlexandre TORGUE break; 5348863ce5SAlexandre TORGUE case 64: 5448863ce5SAlexandre TORGUE value |= DMA_AXI_BLEN64; 5548863ce5SAlexandre TORGUE break; 5648863ce5SAlexandre TORGUE case 32: 5748863ce5SAlexandre TORGUE value |= DMA_AXI_BLEN32; 5848863ce5SAlexandre TORGUE break; 5948863ce5SAlexandre TORGUE case 16: 6048863ce5SAlexandre TORGUE value |= DMA_AXI_BLEN16; 6148863ce5SAlexandre TORGUE break; 6248863ce5SAlexandre TORGUE case 8: 6348863ce5SAlexandre TORGUE value |= DMA_AXI_BLEN8; 6448863ce5SAlexandre TORGUE break; 6548863ce5SAlexandre TORGUE case 4: 6648863ce5SAlexandre TORGUE value |= DMA_AXI_BLEN4; 6748863ce5SAlexandre TORGUE break; 6848863ce5SAlexandre TORGUE } 6948863ce5SAlexandre TORGUE } 7048863ce5SAlexandre TORGUE 7148863ce5SAlexandre TORGUE writel(value, ioaddr + DMA_SYS_BUS_MODE); 7248863ce5SAlexandre TORGUE } 7348863ce5SAlexandre TORGUE 7447f2a9ceSJoao Pinto void dwmac4_dma_init_rx_chan(void __iomem *ioaddr, 7589caaa2dSNiklas Cassel struct stmmac_dma_cfg *dma_cfg, 7647f2a9ceSJoao Pinto u32 dma_rx_phy, u32 chan) 7748863ce5SAlexandre TORGUE { 7848863ce5SAlexandre TORGUE u32 value; 7947f2a9ceSJoao Pinto u32 rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl; 8048863ce5SAlexandre TORGUE 8147f2a9ceSJoao Pinto value = readl(ioaddr + DMA_CHAN_RX_CONTROL(chan)); 8247f2a9ceSJoao Pinto value = value | (rxpbl << DMA_BUS_MODE_RPBL_SHIFT); 8347f2a9ceSJoao Pinto writel(value, ioaddr + DMA_CHAN_RX_CONTROL(chan)); 8447f2a9ceSJoao Pinto 8547f2a9ceSJoao Pinto writel(dma_rx_phy, ioaddr + DMA_CHAN_RX_BASE_ADDR(chan)); 8647f2a9ceSJoao Pinto } 8747f2a9ceSJoao Pinto 8847f2a9ceSJoao Pinto void dwmac4_dma_init_tx_chan(void __iomem *ioaddr, 8947f2a9ceSJoao Pinto struct stmmac_dma_cfg *dma_cfg, 9047f2a9ceSJoao Pinto u32 dma_tx_phy, u32 chan) 9147f2a9ceSJoao Pinto { 9247f2a9ceSJoao Pinto u32 value; 9347f2a9ceSJoao Pinto u32 txpbl = dma_cfg->txpbl ?: dma_cfg->pbl; 9447f2a9ceSJoao Pinto 9547f2a9ceSJoao Pinto value = readl(ioaddr + DMA_CHAN_TX_CONTROL(chan)); 9647f2a9ceSJoao Pinto value = value | (txpbl << DMA_BUS_MODE_PBL_SHIFT); 9747f2a9ceSJoao Pinto writel(value, ioaddr + DMA_CHAN_TX_CONTROL(chan)); 9847f2a9ceSJoao Pinto 9947f2a9ceSJoao Pinto writel(dma_tx_phy, ioaddr + DMA_CHAN_TX_BASE_ADDR(chan)); 10047f2a9ceSJoao Pinto } 10147f2a9ceSJoao Pinto 10247f2a9ceSJoao Pinto void dwmac4_dma_init_channel(void __iomem *ioaddr, 10347f2a9ceSJoao Pinto struct stmmac_dma_cfg *dma_cfg, u32 chan) 10447f2a9ceSJoao Pinto { 10547f2a9ceSJoao Pinto u32 value; 10647f2a9ceSJoao Pinto 10747f2a9ceSJoao Pinto /* common channel control register config */ 10847f2a9ceSJoao Pinto value = readl(ioaddr + DMA_CHAN_CONTROL(chan)); 1094022d039SNiklas Cassel if (dma_cfg->pblx8) 11048863ce5SAlexandre TORGUE value = value | DMA_BUS_MODE_PBL; 11147f2a9ceSJoao Pinto writel(value, ioaddr + DMA_CHAN_CONTROL(chan)); 11248863ce5SAlexandre TORGUE 11348863ce5SAlexandre TORGUE /* Mask interrupts by writing to CSR7 */ 11447f2a9ceSJoao Pinto writel(DMA_CHAN_INTR_DEFAULT_MASK, 11547f2a9ceSJoao Pinto ioaddr + DMA_CHAN_INTR_ENA(chan)); 11648863ce5SAlexandre TORGUE } 11748863ce5SAlexandre TORGUE 11850ca903aSNiklas Cassel static void dwmac4_dma_init(void __iomem *ioaddr, 11950ca903aSNiklas Cassel struct stmmac_dma_cfg *dma_cfg, 12050ca903aSNiklas Cassel u32 dma_tx, u32 dma_rx, int atds) 12148863ce5SAlexandre TORGUE { 12248863ce5SAlexandre TORGUE u32 value = readl(ioaddr + DMA_SYS_BUS_MODE); 12348863ce5SAlexandre TORGUE 12448863ce5SAlexandre TORGUE /* Set the Fixed burst mode */ 12550ca903aSNiklas Cassel if (dma_cfg->fixed_burst) 12648863ce5SAlexandre TORGUE value |= DMA_SYS_BUS_FB; 12748863ce5SAlexandre TORGUE 12848863ce5SAlexandre TORGUE /* Mixed Burst has no effect when fb is set */ 12950ca903aSNiklas Cassel if (dma_cfg->mixed_burst) 13048863ce5SAlexandre TORGUE value |= DMA_SYS_BUS_MB; 13148863ce5SAlexandre TORGUE 13250ca903aSNiklas Cassel if (dma_cfg->aal) 13348863ce5SAlexandre TORGUE value |= DMA_SYS_BUS_AAL; 13448863ce5SAlexandre TORGUE 13548863ce5SAlexandre TORGUE writel(value, ioaddr + DMA_SYS_BUS_MODE); 13648863ce5SAlexandre TORGUE } 13748863ce5SAlexandre TORGUE 138fbf68229SLABBE Corentin static void _dwmac4_dump_dma_regs(void __iomem *ioaddr, u32 channel, 139fbf68229SLABBE Corentin u32 *reg_space) 14048863ce5SAlexandre TORGUE { 141fbf68229SLABBE Corentin reg_space[DMA_CHAN_CONTROL(channel) / 4] = 142fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_CONTROL(channel)); 143fbf68229SLABBE Corentin reg_space[DMA_CHAN_TX_CONTROL(channel) / 4] = 144fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_TX_CONTROL(channel)); 145fbf68229SLABBE Corentin reg_space[DMA_CHAN_RX_CONTROL(channel) / 4] = 146fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_RX_CONTROL(channel)); 147fbf68229SLABBE Corentin reg_space[DMA_CHAN_TX_BASE_ADDR(channel) / 4] = 148fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_TX_BASE_ADDR(channel)); 149fbf68229SLABBE Corentin reg_space[DMA_CHAN_RX_BASE_ADDR(channel) / 4] = 150fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_RX_BASE_ADDR(channel)); 151fbf68229SLABBE Corentin reg_space[DMA_CHAN_TX_END_ADDR(channel) / 4] = 152fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_TX_END_ADDR(channel)); 153fbf68229SLABBE Corentin reg_space[DMA_CHAN_RX_END_ADDR(channel) / 4] = 154fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_RX_END_ADDR(channel)); 155fbf68229SLABBE Corentin reg_space[DMA_CHAN_TX_RING_LEN(channel) / 4] = 156fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_TX_RING_LEN(channel)); 157fbf68229SLABBE Corentin reg_space[DMA_CHAN_RX_RING_LEN(channel) / 4] = 158fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_RX_RING_LEN(channel)); 159fbf68229SLABBE Corentin reg_space[DMA_CHAN_INTR_ENA(channel) / 4] = 160fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_INTR_ENA(channel)); 161fbf68229SLABBE Corentin reg_space[DMA_CHAN_RX_WATCHDOG(channel) / 4] = 162fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_RX_WATCHDOG(channel)); 163fbf68229SLABBE Corentin reg_space[DMA_CHAN_SLOT_CTRL_STATUS(channel) / 4] = 164fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_SLOT_CTRL_STATUS(channel)); 165fbf68229SLABBE Corentin reg_space[DMA_CHAN_CUR_TX_DESC(channel) / 4] = 166fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_CUR_TX_DESC(channel)); 167fbf68229SLABBE Corentin reg_space[DMA_CHAN_CUR_RX_DESC(channel) / 4] = 168fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_CUR_RX_DESC(channel)); 169fbf68229SLABBE Corentin reg_space[DMA_CHAN_CUR_TX_BUF_ADDR(channel) / 4] = 170fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_CUR_TX_BUF_ADDR(channel)); 171fbf68229SLABBE Corentin reg_space[DMA_CHAN_CUR_RX_BUF_ADDR(channel) / 4] = 172fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_CUR_RX_BUF_ADDR(channel)); 173fbf68229SLABBE Corentin reg_space[DMA_CHAN_STATUS(channel) / 4] = 174fbf68229SLABBE Corentin readl(ioaddr + DMA_CHAN_STATUS(channel)); 17548863ce5SAlexandre TORGUE } 17648863ce5SAlexandre TORGUE 177fbf68229SLABBE Corentin static void dwmac4_dump_dma_regs(void __iomem *ioaddr, u32 *reg_space) 17848863ce5SAlexandre TORGUE { 17948863ce5SAlexandre TORGUE int i; 18048863ce5SAlexandre TORGUE 18148863ce5SAlexandre TORGUE for (i = 0; i < DMA_CHANNEL_NB_MAX; i++) 182fbf68229SLABBE Corentin _dwmac4_dump_dma_regs(ioaddr, i, reg_space); 18348863ce5SAlexandre TORGUE } 18448863ce5SAlexandre TORGUE 1853c55d4d0SJoao Pinto static void dwmac4_rx_watchdog(void __iomem *ioaddr, u32 riwt, u32 number_chan) 18648863ce5SAlexandre TORGUE { 1873c55d4d0SJoao Pinto u32 chan; 18848863ce5SAlexandre TORGUE 1893c55d4d0SJoao Pinto for (chan = 0; chan < number_chan; chan++) 1903c55d4d0SJoao Pinto writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(chan)); 19148863ce5SAlexandre TORGUE } 19248863ce5SAlexandre TORGUE 1936deee222SJoao Pinto static void dwmac4_dma_rx_chan_op_mode(void __iomem *ioaddr, int mode, 1946deee222SJoao Pinto u32 channel, int fifosz) 19548863ce5SAlexandre TORGUE { 1966deee222SJoao Pinto unsigned int rqs = fifosz / 256 - 1; 1976deee222SJoao Pinto u32 mtl_rx_op, mtl_rx_int; 19848863ce5SAlexandre TORGUE 19948863ce5SAlexandre TORGUE mtl_rx_op = readl(ioaddr + MTL_CHAN_RX_OP_MODE(channel)); 20048863ce5SAlexandre TORGUE 2016deee222SJoao Pinto if (mode == SF_DMA_MODE) { 20248863ce5SAlexandre TORGUE pr_debug("GMAC: enable RX store and forward mode\n"); 20348863ce5SAlexandre TORGUE mtl_rx_op |= MTL_OP_MODE_RSF; 20448863ce5SAlexandre TORGUE } else { 2056deee222SJoao Pinto pr_debug("GMAC: disable RX SF mode (threshold %d)\n", mode); 20648863ce5SAlexandre TORGUE mtl_rx_op &= ~MTL_OP_MODE_RSF; 20748863ce5SAlexandre TORGUE mtl_rx_op &= MTL_OP_MODE_RTC_MASK; 2086deee222SJoao Pinto if (mode <= 32) 20948863ce5SAlexandre TORGUE mtl_rx_op |= MTL_OP_MODE_RTC_32; 2106deee222SJoao Pinto else if (mode <= 64) 21148863ce5SAlexandre TORGUE mtl_rx_op |= MTL_OP_MODE_RTC_64; 2126deee222SJoao Pinto else if (mode <= 96) 21348863ce5SAlexandre TORGUE mtl_rx_op |= MTL_OP_MODE_RTC_96; 21448863ce5SAlexandre TORGUE else 21548863ce5SAlexandre TORGUE mtl_rx_op |= MTL_OP_MODE_RTC_128; 21648863ce5SAlexandre TORGUE } 21748863ce5SAlexandre TORGUE 218356b7557SThierry Reding mtl_rx_op &= ~MTL_OP_MODE_RQS_MASK; 219356b7557SThierry Reding mtl_rx_op |= rqs << MTL_OP_MODE_RQS_SHIFT; 220356b7557SThierry Reding 221356b7557SThierry Reding /* enable flow control only if each channel gets 4 KiB or more FIFO */ 2226deee222SJoao Pinto if (fifosz >= 4096) { 223356b7557SThierry Reding unsigned int rfd, rfa; 224356b7557SThierry Reding 225356b7557SThierry Reding mtl_rx_op |= MTL_OP_MODE_EHFC; 226356b7557SThierry Reding 227356b7557SThierry Reding /* Set Threshold for Activating Flow Control to min 2 frames, 228356b7557SThierry Reding * i.e. 1500 * 2 = 3000 bytes. 229356b7557SThierry Reding * 230356b7557SThierry Reding * Set Threshold for Deactivating Flow Control to min 1 frame, 231356b7557SThierry Reding * i.e. 1500 bytes. 232356b7557SThierry Reding */ 2336deee222SJoao Pinto switch (fifosz) { 234356b7557SThierry Reding case 4096: 235356b7557SThierry Reding /* This violates the above formula because of FIFO size 236356b7557SThierry Reding * limit therefore overflow may occur in spite of this. 237356b7557SThierry Reding */ 238356b7557SThierry Reding rfd = 0x03; /* Full-2.5K */ 239356b7557SThierry Reding rfa = 0x01; /* Full-1.5K */ 240356b7557SThierry Reding break; 241356b7557SThierry Reding 242356b7557SThierry Reding case 8192: 243356b7557SThierry Reding rfd = 0x06; /* Full-4K */ 244356b7557SThierry Reding rfa = 0x0a; /* Full-6K */ 245356b7557SThierry Reding break; 246356b7557SThierry Reding 247356b7557SThierry Reding case 16384: 248356b7557SThierry Reding rfd = 0x06; /* Full-4K */ 249356b7557SThierry Reding rfa = 0x12; /* Full-10K */ 250356b7557SThierry Reding break; 251356b7557SThierry Reding 252356b7557SThierry Reding default: 253356b7557SThierry Reding rfd = 0x06; /* Full-4K */ 254356b7557SThierry Reding rfa = 0x1e; /* Full-16K */ 255356b7557SThierry Reding break; 256356b7557SThierry Reding } 257356b7557SThierry Reding 258356b7557SThierry Reding mtl_rx_op &= ~MTL_OP_MODE_RFD_MASK; 259356b7557SThierry Reding mtl_rx_op |= rfd << MTL_OP_MODE_RFD_SHIFT; 260356b7557SThierry Reding 261356b7557SThierry Reding mtl_rx_op &= ~MTL_OP_MODE_RFA_MASK; 262356b7557SThierry Reding mtl_rx_op |= rfa << MTL_OP_MODE_RFA_SHIFT; 263356b7557SThierry Reding } 264356b7557SThierry Reding 26548863ce5SAlexandre TORGUE writel(mtl_rx_op, ioaddr + MTL_CHAN_RX_OP_MODE(channel)); 26648863ce5SAlexandre TORGUE 26748863ce5SAlexandre TORGUE /* Enable MTL RX overflow */ 26848863ce5SAlexandre TORGUE mtl_rx_int = readl(ioaddr + MTL_CHAN_INT_CTRL(channel)); 26948863ce5SAlexandre TORGUE writel(mtl_rx_int | MTL_RX_OVERFLOW_INT_EN, 27048863ce5SAlexandre TORGUE ioaddr + MTL_CHAN_INT_CTRL(channel)); 27148863ce5SAlexandre TORGUE } 27248863ce5SAlexandre TORGUE 2736deee222SJoao Pinto static void dwmac4_dma_tx_chan_op_mode(void __iomem *ioaddr, int mode, 2746deee222SJoao Pinto u32 channel) 27548863ce5SAlexandre TORGUE { 2766deee222SJoao Pinto u32 mtl_tx_op = readl(ioaddr + MTL_CHAN_TX_OP_MODE(channel)); 2776deee222SJoao Pinto 2786deee222SJoao Pinto if (mode == SF_DMA_MODE) { 2796deee222SJoao Pinto pr_debug("GMAC: enable TX store and forward mode\n"); 2806deee222SJoao Pinto /* Transmit COE type 2 cannot be done in cut-through mode. */ 2816deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TSF; 2826deee222SJoao Pinto } else { 2836deee222SJoao Pinto pr_debug("GMAC: disabling TX SF (threshold %d)\n", mode); 2846deee222SJoao Pinto mtl_tx_op &= ~MTL_OP_MODE_TSF; 2856deee222SJoao Pinto mtl_tx_op &= MTL_OP_MODE_TTC_MASK; 2866deee222SJoao Pinto /* Set the transmit threshold */ 2876deee222SJoao Pinto if (mode <= 32) 2886deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_32; 2896deee222SJoao Pinto else if (mode <= 64) 2906deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_64; 2916deee222SJoao Pinto else if (mode <= 96) 2926deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_96; 2936deee222SJoao Pinto else if (mode <= 128) 2946deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_128; 2956deee222SJoao Pinto else if (mode <= 192) 2966deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_192; 2976deee222SJoao Pinto else if (mode <= 256) 2986deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_256; 2996deee222SJoao Pinto else if (mode <= 384) 3006deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_384; 3016deee222SJoao Pinto else 3026deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TTC_512; 3036deee222SJoao Pinto } 3046deee222SJoao Pinto /* For an IP with DWC_EQOS_NUM_TXQ == 1, the fields TXQEN and TQS are RO 3056deee222SJoao Pinto * with reset values: TXQEN on, TQS == DWC_EQOS_TXFIFO_SIZE. 3066deee222SJoao Pinto * For an IP with DWC_EQOS_NUM_TXQ > 1, the fields TXQEN and TQS are R/W 3076deee222SJoao Pinto * with reset values: TXQEN off, TQS 256 bytes. 3086deee222SJoao Pinto * 3096deee222SJoao Pinto * Write the bits in both cases, since it will have no effect when RO. 3106deee222SJoao Pinto * For DWC_EQOS_NUM_TXQ > 1, the top bits in MTL_OP_MODE_TQS_MASK might 3116deee222SJoao Pinto * be RO, however, writing the whole TQS field will result in a value 3126deee222SJoao Pinto * equal to DWC_EQOS_TXFIFO_SIZE, just like for DWC_EQOS_NUM_TXQ == 1. 3136deee222SJoao Pinto */ 3146deee222SJoao Pinto mtl_tx_op |= MTL_OP_MODE_TXQEN | MTL_OP_MODE_TQS_MASK; 3156deee222SJoao Pinto writel(mtl_tx_op, ioaddr + MTL_CHAN_TX_OP_MODE(channel)); 31648863ce5SAlexandre TORGUE } 31748863ce5SAlexandre TORGUE 31848863ce5SAlexandre TORGUE static void dwmac4_get_hw_feature(void __iomem *ioaddr, 31948863ce5SAlexandre TORGUE struct dma_features *dma_cap) 32048863ce5SAlexandre TORGUE { 32148863ce5SAlexandre TORGUE u32 hw_cap = readl(ioaddr + GMAC_HW_FEATURE0); 32248863ce5SAlexandre TORGUE 32348863ce5SAlexandre TORGUE /* MAC HW feature0 */ 32448863ce5SAlexandre TORGUE dma_cap->mbps_10_100 = (hw_cap & GMAC_HW_FEAT_MIISEL); 32548863ce5SAlexandre TORGUE dma_cap->mbps_1000 = (hw_cap & GMAC_HW_FEAT_GMIISEL) >> 1; 32648863ce5SAlexandre TORGUE dma_cap->half_duplex = (hw_cap & GMAC_HW_FEAT_HDSEL) >> 2; 32748863ce5SAlexandre TORGUE dma_cap->hash_filter = (hw_cap & GMAC_HW_FEAT_VLHASH) >> 4; 32848863ce5SAlexandre TORGUE dma_cap->multi_addr = (hw_cap & GMAC_HW_FEAT_ADDMAC) >> 18; 32948863ce5SAlexandre TORGUE dma_cap->pcs = (hw_cap & GMAC_HW_FEAT_PCSSEL) >> 3; 33048863ce5SAlexandre TORGUE dma_cap->sma_mdio = (hw_cap & GMAC_HW_FEAT_SMASEL) >> 5; 33148863ce5SAlexandre TORGUE dma_cap->pmt_remote_wake_up = (hw_cap & GMAC_HW_FEAT_RWKSEL) >> 6; 33248863ce5SAlexandre TORGUE dma_cap->pmt_magic_frame = (hw_cap & GMAC_HW_FEAT_MGKSEL) >> 7; 33348863ce5SAlexandre TORGUE /* MMC */ 33448863ce5SAlexandre TORGUE dma_cap->rmon = (hw_cap & GMAC_HW_FEAT_MMCSEL) >> 8; 33548863ce5SAlexandre TORGUE /* IEEE 1588-2008 */ 33648863ce5SAlexandre TORGUE dma_cap->atime_stamp = (hw_cap & GMAC_HW_FEAT_TSSEL) >> 12; 33748863ce5SAlexandre TORGUE /* 802.3az - Energy-Efficient Ethernet (EEE) */ 33848863ce5SAlexandre TORGUE dma_cap->eee = (hw_cap & GMAC_HW_FEAT_EEESEL) >> 13; 33948863ce5SAlexandre TORGUE /* TX and RX csum */ 34048863ce5SAlexandre TORGUE dma_cap->tx_coe = (hw_cap & GMAC_HW_FEAT_TXCOSEL) >> 14; 34148863ce5SAlexandre TORGUE dma_cap->rx_coe = (hw_cap & GMAC_HW_FEAT_RXCOESEL) >> 16; 34248863ce5SAlexandre TORGUE 34348863ce5SAlexandre TORGUE /* MAC HW feature1 */ 34448863ce5SAlexandre TORGUE hw_cap = readl(ioaddr + GMAC_HW_FEATURE1); 34548863ce5SAlexandre TORGUE dma_cap->av = (hw_cap & GMAC_HW_FEAT_AVSEL) >> 20; 34648863ce5SAlexandre TORGUE dma_cap->tsoen = (hw_cap & GMAC_HW_TSOEN) >> 18; 34711fbf811SThierry Reding /* RX and TX FIFO sizes are encoded as log2(n / 128). Undo that by 34811fbf811SThierry Reding * shifting and store the sizes in bytes. 34911fbf811SThierry Reding */ 35011fbf811SThierry Reding dma_cap->tx_fifo_size = 128 << ((hw_cap & GMAC_HW_TXFIFOSIZE) >> 6); 35111fbf811SThierry Reding dma_cap->rx_fifo_size = 128 << ((hw_cap & GMAC_HW_RXFIFOSIZE) >> 0); 35248863ce5SAlexandre TORGUE /* MAC HW feature2 */ 35348863ce5SAlexandre TORGUE hw_cap = readl(ioaddr + GMAC_HW_FEATURE2); 35448863ce5SAlexandre TORGUE /* TX and RX number of channels */ 35548863ce5SAlexandre TORGUE dma_cap->number_rx_channel = 35648863ce5SAlexandre TORGUE ((hw_cap & GMAC_HW_FEAT_RXCHCNT) >> 12) + 1; 35748863ce5SAlexandre TORGUE dma_cap->number_tx_channel = 35848863ce5SAlexandre TORGUE ((hw_cap & GMAC_HW_FEAT_TXCHCNT) >> 18) + 1; 3599eb12474Sjpinto /* TX and RX number of queues */ 3609eb12474Sjpinto dma_cap->number_rx_queues = 3619eb12474Sjpinto ((hw_cap & GMAC_HW_FEAT_RXQCNT) >> 0) + 1; 3629eb12474Sjpinto dma_cap->number_tx_queues = 3639eb12474Sjpinto ((hw_cap & GMAC_HW_FEAT_TXQCNT) >> 6) + 1; 36448863ce5SAlexandre TORGUE 36548863ce5SAlexandre TORGUE /* IEEE 1588-2002 */ 36648863ce5SAlexandre TORGUE dma_cap->time_stamp = 0; 36748863ce5SAlexandre TORGUE } 36848863ce5SAlexandre TORGUE 36948863ce5SAlexandre TORGUE /* Enable/disable TSO feature and set MSS */ 37048863ce5SAlexandre TORGUE static void dwmac4_enable_tso(void __iomem *ioaddr, bool en, u32 chan) 37148863ce5SAlexandre TORGUE { 37248863ce5SAlexandre TORGUE u32 value; 37348863ce5SAlexandre TORGUE 37448863ce5SAlexandre TORGUE if (en) { 37548863ce5SAlexandre TORGUE /* enable TSO */ 37648863ce5SAlexandre TORGUE value = readl(ioaddr + DMA_CHAN_TX_CONTROL(chan)); 37748863ce5SAlexandre TORGUE writel(value | DMA_CONTROL_TSE, 37848863ce5SAlexandre TORGUE ioaddr + DMA_CHAN_TX_CONTROL(chan)); 37948863ce5SAlexandre TORGUE } else { 38048863ce5SAlexandre TORGUE /* enable TSO */ 38148863ce5SAlexandre TORGUE value = readl(ioaddr + DMA_CHAN_TX_CONTROL(chan)); 38248863ce5SAlexandre TORGUE writel(value & ~DMA_CONTROL_TSE, 38348863ce5SAlexandre TORGUE ioaddr + DMA_CHAN_TX_CONTROL(chan)); 38448863ce5SAlexandre TORGUE } 38548863ce5SAlexandre TORGUE } 38648863ce5SAlexandre TORGUE 38748863ce5SAlexandre TORGUE const struct stmmac_dma_ops dwmac4_dma_ops = { 38848863ce5SAlexandre TORGUE .reset = dwmac4_dma_reset, 38948863ce5SAlexandre TORGUE .init = dwmac4_dma_init, 39047f2a9ceSJoao Pinto .init_chan = dwmac4_dma_init_channel, 39147f2a9ceSJoao Pinto .init_rx_chan = dwmac4_dma_init_rx_chan, 39247f2a9ceSJoao Pinto .init_tx_chan = dwmac4_dma_init_tx_chan, 39348863ce5SAlexandre TORGUE .axi = dwmac4_dma_axi, 39448863ce5SAlexandre TORGUE .dump_regs = dwmac4_dump_dma_regs, 3956deee222SJoao Pinto .dma_rx_mode = dwmac4_dma_rx_chan_op_mode, 3966deee222SJoao Pinto .dma_tx_mode = dwmac4_dma_tx_chan_op_mode, 39748863ce5SAlexandre TORGUE .enable_dma_irq = dwmac4_enable_dma_irq, 39848863ce5SAlexandre TORGUE .disable_dma_irq = dwmac4_disable_dma_irq, 39948863ce5SAlexandre TORGUE .start_tx = dwmac4_dma_start_tx, 40048863ce5SAlexandre TORGUE .stop_tx = dwmac4_dma_stop_tx, 40148863ce5SAlexandre TORGUE .start_rx = dwmac4_dma_start_rx, 40248863ce5SAlexandre TORGUE .stop_rx = dwmac4_dma_stop_rx, 40348863ce5SAlexandre TORGUE .dma_interrupt = dwmac4_dma_interrupt, 40448863ce5SAlexandre TORGUE .get_hw_feature = dwmac4_get_hw_feature, 40548863ce5SAlexandre TORGUE .rx_watchdog = dwmac4_rx_watchdog, 40648863ce5SAlexandre TORGUE .set_rx_ring_len = dwmac4_set_rx_ring_len, 40748863ce5SAlexandre TORGUE .set_tx_ring_len = dwmac4_set_tx_ring_len, 40848863ce5SAlexandre TORGUE .set_rx_tail_ptr = dwmac4_set_rx_tail_ptr, 40948863ce5SAlexandre TORGUE .set_tx_tail_ptr = dwmac4_set_tx_tail_ptr, 41048863ce5SAlexandre TORGUE .enable_tso = dwmac4_enable_tso, 41148863ce5SAlexandre TORGUE }; 41248863ce5SAlexandre TORGUE 41348863ce5SAlexandre TORGUE const struct stmmac_dma_ops dwmac410_dma_ops = { 41448863ce5SAlexandre TORGUE .reset = dwmac4_dma_reset, 41548863ce5SAlexandre TORGUE .init = dwmac4_dma_init, 41647f2a9ceSJoao Pinto .init_chan = dwmac4_dma_init_channel, 41747f2a9ceSJoao Pinto .init_rx_chan = dwmac4_dma_init_rx_chan, 41847f2a9ceSJoao Pinto .init_tx_chan = dwmac4_dma_init_tx_chan, 41948863ce5SAlexandre TORGUE .axi = dwmac4_dma_axi, 42048863ce5SAlexandre TORGUE .dump_regs = dwmac4_dump_dma_regs, 4216deee222SJoao Pinto .dma_rx_mode = dwmac4_dma_rx_chan_op_mode, 4226deee222SJoao Pinto .dma_tx_mode = dwmac4_dma_tx_chan_op_mode, 42348863ce5SAlexandre TORGUE .enable_dma_irq = dwmac410_enable_dma_irq, 42448863ce5SAlexandre TORGUE .disable_dma_irq = dwmac4_disable_dma_irq, 42548863ce5SAlexandre TORGUE .start_tx = dwmac4_dma_start_tx, 42648863ce5SAlexandre TORGUE .stop_tx = dwmac4_dma_stop_tx, 42748863ce5SAlexandre TORGUE .start_rx = dwmac4_dma_start_rx, 42848863ce5SAlexandre TORGUE .stop_rx = dwmac4_dma_stop_rx, 42948863ce5SAlexandre TORGUE .dma_interrupt = dwmac4_dma_interrupt, 43048863ce5SAlexandre TORGUE .get_hw_feature = dwmac4_get_hw_feature, 43148863ce5SAlexandre TORGUE .rx_watchdog = dwmac4_rx_watchdog, 43248863ce5SAlexandre TORGUE .set_rx_ring_len = dwmac4_set_rx_ring_len, 43348863ce5SAlexandre TORGUE .set_tx_ring_len = dwmac4_set_tx_ring_len, 43448863ce5SAlexandre TORGUE .set_rx_tail_ptr = dwmac4_set_rx_tail_ptr, 43548863ce5SAlexandre TORGUE .set_tx_tail_ptr = dwmac4_set_tx_tail_ptr, 43648863ce5SAlexandre TORGUE .enable_tso = dwmac4_enable_tso, 43748863ce5SAlexandre TORGUE }; 438