2019-05-29 22:18:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-10-15 06:13:45 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
This is the driver for the GMAC on-chip Ethernet controller for ST SoCs.
|
|
|
|
DWC Ether MAC 10/100/1000 Universal version 3.41a has been used for
|
|
|
|
developing this code.
|
|
|
|
|
2010-04-14 04:21:12 +08:00
|
|
|
This contains the functions to handle the dma.
|
2010-01-07 07:07:20 +08:00
|
|
|
|
2009-10-15 06:13:45 +08:00
|
|
|
Copyright (C) 2007-2009 STMicroelectronics Ltd
|
|
|
|
|
|
|
|
|
|
|
|
Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2011-06-16 19:01:34 +08:00
|
|
|
#include <asm/io.h>
|
2010-01-07 07:07:20 +08:00
|
|
|
#include "dwmac1000.h"
|
2010-01-07 07:07:18 +08:00
|
|
|
#include "dwmac_dma.h"
|
2009-10-15 06:13:45 +08:00
|
|
|
|
2016-02-29 21:27:28 +08:00
|
|
|
static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
|
|
|
|
{
|
|
|
|
u32 value = readl(ioaddr + DMA_AXI_BUS_MODE);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pr_info("dwmac1000: Master AXI performs %s burst length\n",
|
|
|
|
!(value & DMA_AXI_UNDEF) ? "fixed" : "any");
|
|
|
|
|
|
|
|
if (axi->axi_lpi_en)
|
|
|
|
value |= DMA_AXI_EN_LPI;
|
|
|
|
if (axi->axi_xit_frm)
|
|
|
|
value |= DMA_AXI_LPI_XIT_FRM;
|
|
|
|
|
2016-12-06 01:12:54 +08:00
|
|
|
value &= ~DMA_AXI_WR_OSR_LMT;
|
2016-02-29 21:27:28 +08:00
|
|
|
value |= (axi->axi_wr_osr_lmt & DMA_AXI_WR_OSR_LMT_MASK) <<
|
|
|
|
DMA_AXI_WR_OSR_LMT_SHIFT;
|
|
|
|
|
2016-12-06 01:12:54 +08:00
|
|
|
value &= ~DMA_AXI_RD_OSR_LMT;
|
2016-02-29 21:27:28 +08:00
|
|
|
value |= (axi->axi_rd_osr_lmt & DMA_AXI_RD_OSR_LMT_MASK) <<
|
|
|
|
DMA_AXI_RD_OSR_LMT_SHIFT;
|
|
|
|
|
|
|
|
/* Depending on the UNDEF bit the Master AXI will perform any burst
|
|
|
|
* length according to the BLEN programmed (by default all BLEN are
|
|
|
|
* set).
|
|
|
|
*/
|
|
|
|
for (i = 0; i < AXI_BLEN; i++) {
|
|
|
|
switch (axi->axi_blen[i]) {
|
|
|
|
case 256:
|
|
|
|
value |= DMA_AXI_BLEN256;
|
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
value |= DMA_AXI_BLEN128;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
value |= DMA_AXI_BLEN64;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
value |= DMA_AXI_BLEN32;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
value |= DMA_AXI_BLEN16;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
value |= DMA_AXI_BLEN8;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
value |= DMA_AXI_BLEN4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(value, ioaddr + DMA_AXI_BUS_MODE);
|
|
|
|
}
|
|
|
|
|
2016-12-07 22:20:04 +08:00
|
|
|
static void dwmac1000_dma_init(void __iomem *ioaddr,
|
2018-05-18 21:56:05 +08:00
|
|
|
struct stmmac_dma_cfg *dma_cfg, int atds)
|
2009-10-15 06:13:45 +08:00
|
|
|
{
|
2016-02-29 21:27:28 +08:00
|
|
|
u32 value = readl(ioaddr + DMA_BUS_MODE);
|
net: stmmac: add support for independent DMA pbl for tx/rx
GMAC and newer supports independent programmable burst lengths for
DMA tx/rx. Add new optional devicetree properties representing this.
To be backwards compatible, snps,pbl will still be valid, but
snps,txpbl/snps,rxpbl will override the value in snps,pbl if set.
If the IP is synthesized to use the AXI interface, there is a register
and a matching DT property inside the optional stmmac-axi-config DT node
for controlling burst lengths, named snps,blen.
However, using this register, it is not possible to control tx and rx
independently. Also, this register is not available if the IP was
synthesized with, e.g., the AHB interface.
Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Acked-by: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-12-07 22:20:07 +08:00
|
|
|
int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
|
|
|
|
int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
2012-04-04 12:33:23 +08:00
|
|
|
/*
|
2016-02-29 21:27:28 +08:00
|
|
|
* Set the DMA PBL (Programmable Burst Length) mode.
|
|
|
|
*
|
|
|
|
* Note: before stmmac core 3.50 this mode bit was 4xPBL, and
|
2012-04-04 12:33:23 +08:00
|
|
|
* post 3.5 mode bit acts as 8*PBL.
|
|
|
|
*/
|
2016-12-07 22:20:08 +08:00
|
|
|
if (dma_cfg->pblx8)
|
|
|
|
value |= DMA_BUS_MODE_MAXPBL;
|
net: stmmac: add support for independent DMA pbl for tx/rx
GMAC and newer supports independent programmable burst lengths for
DMA tx/rx. Add new optional devicetree properties representing this.
To be backwards compatible, snps,pbl will still be valid, but
snps,txpbl/snps,rxpbl will override the value in snps,pbl if set.
If the IP is synthesized to use the AXI interface, there is a register
and a matching DT property inside the optional stmmac-axi-config DT node
for controlling burst lengths, named snps,blen.
However, using this register, it is not possible to control tx and rx
independently. Also, this register is not available if the IP was
synthesized with, e.g., the AHB interface.
Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Acked-by: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-12-07 22:20:07 +08:00
|
|
|
value |= DMA_BUS_MODE_USP;
|
|
|
|
value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
|
|
|
|
value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
|
|
|
|
value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
|
2012-04-04 12:33:23 +08:00
|
|
|
|
|
|
|
/* Set the Fixed burst mode */
|
2016-12-07 22:20:04 +08:00
|
|
|
if (dma_cfg->fixed_burst)
|
2012-04-04 12:33:23 +08:00
|
|
|
value |= DMA_BUS_MODE_FB;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
2012-05-14 06:18:42 +08:00
|
|
|
/* Mixed Burst has no effect when fb is set */
|
2016-12-07 22:20:04 +08:00
|
|
|
if (dma_cfg->mixed_burst)
|
2012-05-14 06:18:42 +08:00
|
|
|
value |= DMA_BUS_MODE_MB;
|
|
|
|
|
2013-03-26 12:43:06 +08:00
|
|
|
if (atds)
|
|
|
|
value |= DMA_BUS_MODE_ATDS;
|
|
|
|
|
2016-12-07 22:20:04 +08:00
|
|
|
if (dma_cfg->aal)
|
2016-02-29 21:27:28 +08:00
|
|
|
value |= DMA_BUS_MODE_AAL;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
2016-02-29 21:27:28 +08:00
|
|
|
writel(value, ioaddr + DMA_BUS_MODE);
|
2012-04-04 12:33:23 +08:00
|
|
|
|
2009-10-15 06:13:45 +08:00
|
|
|
/* Mask interrupts by writing to CSR7 */
|
|
|
|
writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
|
2018-05-18 21:56:05 +08:00
|
|
|
}
|
2009-10-15 06:13:45 +08:00
|
|
|
|
2018-05-18 21:56:05 +08:00
|
|
|
static void dwmac1000_dma_init_rx(void __iomem *ioaddr,
|
|
|
|
struct stmmac_dma_cfg *dma_cfg,
|
2019-07-09 16:02:59 +08:00
|
|
|
dma_addr_t dma_rx_phy, u32 chan)
|
2018-05-18 21:56:05 +08:00
|
|
|
{
|
|
|
|
/* RX descriptor base address list must be written into DMA CSR3 */
|
2019-07-09 16:02:59 +08:00
|
|
|
writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
|
2018-05-18 21:56:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dwmac1000_dma_init_tx(void __iomem *ioaddr,
|
|
|
|
struct stmmac_dma_cfg *dma_cfg,
|
2019-07-09 16:02:59 +08:00
|
|
|
dma_addr_t dma_tx_phy, u32 chan)
|
2018-05-18 21:56:05 +08:00
|
|
|
{
|
|
|
|
/* TX descriptor base address list must be written into DMA CSR4 */
|
2019-07-09 16:02:59 +08:00
|
|
|
writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
|
2009-10-15 06:13:45 +08:00
|
|
|
}
|
|
|
|
|
2015-04-16 00:17:42 +08:00
|
|
|
static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
|
|
|
|
{
|
|
|
|
csr6 &= ~DMA_CONTROL_RFA_MASK;
|
|
|
|
csr6 &= ~DMA_CONTROL_RFD_MASK;
|
|
|
|
|
|
|
|
/* Leave flow control disabled if receive fifo size is less than
|
|
|
|
* 4K or 0. Otherwise, send XOFF when fifo is 1K less than full,
|
|
|
|
* and send XON when 2K less than full.
|
|
|
|
*/
|
|
|
|
if (rxfifosz < 4096) {
|
|
|
|
csr6 &= ~DMA_CONTROL_EFC;
|
|
|
|
pr_debug("GMAC: disabling flow control, rxfifo too small(%d)\n",
|
|
|
|
rxfifosz);
|
|
|
|
} else {
|
|
|
|
csr6 |= DMA_CONTROL_EFC;
|
|
|
|
csr6 |= RFA_FULL_MINUS_1K;
|
|
|
|
csr6 |= RFD_FULL_MINUS_2K;
|
|
|
|
}
|
|
|
|
return csr6;
|
|
|
|
}
|
|
|
|
|
2018-05-18 21:56:02 +08:00
|
|
|
static void dwmac1000_dma_operation_mode_rx(void __iomem *ioaddr, int mode,
|
|
|
|
u32 channel, int fifosz, u8 qmode)
|
2009-10-15 06:13:45 +08:00
|
|
|
{
|
|
|
|
u32 csr6 = readl(ioaddr + DMA_CONTROL);
|
|
|
|
|
2018-05-18 21:56:02 +08:00
|
|
|
if (mode == SF_DMA_MODE) {
|
|
|
|
pr_debug("GMAC: enable RX store and forward mode\n");
|
|
|
|
csr6 |= DMA_CONTROL_RSF;
|
|
|
|
} else {
|
|
|
|
pr_debug("GMAC: disable RX SF mode (threshold %d)\n", mode);
|
|
|
|
csr6 &= ~DMA_CONTROL_RSF;
|
|
|
|
csr6 &= DMA_CONTROL_TC_RX_MASK;
|
|
|
|
if (mode <= 32)
|
|
|
|
csr6 |= DMA_CONTROL_RTC_32;
|
|
|
|
else if (mode <= 64)
|
|
|
|
csr6 |= DMA_CONTROL_RTC_64;
|
|
|
|
else if (mode <= 96)
|
|
|
|
csr6 |= DMA_CONTROL_RTC_96;
|
|
|
|
else
|
|
|
|
csr6 |= DMA_CONTROL_RTC_128;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure flow control based on rx fifo size */
|
|
|
|
csr6 = dwmac1000_configure_fc(csr6, fifosz);
|
|
|
|
|
|
|
|
writel(csr6, ioaddr + DMA_CONTROL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dwmac1000_dma_operation_mode_tx(void __iomem *ioaddr, int mode,
|
|
|
|
u32 channel, int fifosz, u8 qmode)
|
|
|
|
{
|
|
|
|
u32 csr6 = readl(ioaddr + DMA_CONTROL);
|
|
|
|
|
|
|
|
if (mode == SF_DMA_MODE) {
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("GMAC: enable TX store and forward mode\n");
|
2009-10-15 06:13:45 +08:00
|
|
|
/* Transmit COE type 2 cannot be done in cut-through mode. */
|
|
|
|
csr6 |= DMA_CONTROL_TSF;
|
|
|
|
/* Operating on second frame increase the performance
|
2013-04-08 10:10:01 +08:00
|
|
|
* especially when transmit store-and-forward is used.
|
|
|
|
*/
|
2009-10-15 06:13:45 +08:00
|
|
|
csr6 |= DMA_CONTROL_OSF;
|
|
|
|
} else {
|
2018-05-18 21:56:02 +08:00
|
|
|
pr_debug("GMAC: disabling TX SF (threshold %d)\n", mode);
|
2009-10-15 06:13:45 +08:00
|
|
|
csr6 &= ~DMA_CONTROL_TSF;
|
|
|
|
csr6 &= DMA_CONTROL_TC_TX_MASK;
|
tree-wide: fix assorted typos all over the place
That is "success", "unknown", "through", "performance", "[re|un]mapping"
, "access", "default", "reasonable", "[con]currently", "temperature"
, "channel", "[un]used", "application", "example","hierarchy", "therefore"
, "[over|under]flow", "contiguous", "threshold", "enough" and others.
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2009-11-14 23:09:05 +08:00
|
|
|
/* Set the transmit threshold */
|
2018-05-18 21:56:02 +08:00
|
|
|
if (mode <= 32)
|
2009-10-15 06:13:45 +08:00
|
|
|
csr6 |= DMA_CONTROL_TTC_32;
|
2018-05-18 21:56:02 +08:00
|
|
|
else if (mode <= 64)
|
2009-10-15 06:13:45 +08:00
|
|
|
csr6 |= DMA_CONTROL_TTC_64;
|
2018-05-18 21:56:02 +08:00
|
|
|
else if (mode <= 128)
|
2009-10-15 06:13:45 +08:00
|
|
|
csr6 |= DMA_CONTROL_TTC_128;
|
2018-05-18 21:56:02 +08:00
|
|
|
else if (mode <= 192)
|
2009-10-15 06:13:45 +08:00
|
|
|
csr6 |= DMA_CONTROL_TTC_192;
|
|
|
|
else
|
|
|
|
csr6 |= DMA_CONTROL_TTC_256;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(csr6, ioaddr + DMA_CONTROL);
|
|
|
|
}
|
|
|
|
|
2017-02-23 21:12:25 +08:00
|
|
|
static void dwmac1000_dump_dma_regs(void __iomem *ioaddr, u32 *reg_space)
|
2009-10-15 06:13:45 +08:00
|
|
|
{
|
|
|
|
int i;
|
2017-02-23 21:12:25 +08:00
|
|
|
|
2017-07-22 05:35:09 +08:00
|
|
|
for (i = 0; i < NUM_DWMAC1000_DMA_REGS; i++)
|
2017-06-28 06:16:27 +08:00
|
|
|
if ((i < 12) || (i > 17))
|
2017-02-23 21:12:25 +08:00
|
|
|
reg_space[DMA_BUS_MODE / 4 + i] =
|
|
|
|
readl(ioaddr + DMA_BUS_MODE + i * 4);
|
2009-10-15 06:13:45 +08:00
|
|
|
}
|
|
|
|
|
2016-04-01 17:37:25 +08:00
|
|
|
static void dwmac1000_get_hw_feature(void __iomem *ioaddr,
|
|
|
|
struct dma_features *dma_cap)
|
2011-09-02 05:51:41 +08:00
|
|
|
{
|
2016-04-01 17:37:25 +08:00
|
|
|
u32 hw_cap = readl(ioaddr + DMA_HW_FEATURE);
|
|
|
|
|
|
|
|
dma_cap->mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
|
|
|
|
dma_cap->mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
|
|
|
|
dma_cap->half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
|
|
|
|
dma_cap->hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
|
|
|
|
dma_cap->multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5;
|
|
|
|
dma_cap->pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
|
|
|
|
dma_cap->sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
|
|
|
|
dma_cap->pmt_remote_wake_up = (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
|
|
|
|
dma_cap->pmt_magic_frame = (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
|
|
|
|
/* MMC */
|
|
|
|
dma_cap->rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
|
|
|
|
/* IEEE 1588-2002 */
|
|
|
|
dma_cap->time_stamp =
|
|
|
|
(hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
|
|
|
|
/* IEEE 1588-2008 */
|
|
|
|
dma_cap->atime_stamp = (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
|
|
|
|
/* 802.3az - Energy-Efficient Ethernet (EEE) */
|
|
|
|
dma_cap->eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
|
|
|
|
dma_cap->av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
|
|
|
|
/* TX and RX csum */
|
|
|
|
dma_cap->tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
|
|
|
|
dma_cap->rx_coe_type1 = (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
|
|
|
|
dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
|
|
|
|
dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
|
|
|
|
/* TX and RX number of channels */
|
|
|
|
dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
|
|
|
|
dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
|
|
|
|
/* Alternate (enhanced) DESC mode */
|
|
|
|
dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
|
2011-09-02 05:51:41 +08:00
|
|
|
}
|
|
|
|
|
2017-03-15 19:04:50 +08:00
|
|
|
static void dwmac1000_rx_watchdog(void __iomem *ioaddr, u32 riwt,
|
|
|
|
u32 number_chan)
|
2012-11-26 07:10:43 +08:00
|
|
|
{
|
|
|
|
writel(riwt, ioaddr + DMA_RX_WATCHDOG);
|
|
|
|
}
|
|
|
|
|
2010-10-13 22:51:25 +08:00
|
|
|
const struct stmmac_dma_ops dwmac1000_dma_ops = {
|
2016-02-29 21:27:27 +08:00
|
|
|
.reset = dwmac_dma_reset,
|
2010-01-07 07:07:20 +08:00
|
|
|
.init = dwmac1000_dma_init,
|
2018-05-18 21:56:05 +08:00
|
|
|
.init_rx_chan = dwmac1000_dma_init_rx,
|
|
|
|
.init_tx_chan = dwmac1000_dma_init_tx,
|
2016-02-29 21:27:28 +08:00
|
|
|
.axi = dwmac1000_dma_axi,
|
2010-01-07 07:07:20 +08:00
|
|
|
.dump_regs = dwmac1000_dump_dma_regs,
|
2018-05-18 21:56:02 +08:00
|
|
|
.dma_rx_mode = dwmac1000_dma_operation_mode_rx,
|
|
|
|
.dma_tx_mode = dwmac1000_dma_operation_mode_tx,
|
2010-01-07 07:07:18 +08:00
|
|
|
.enable_dma_transmission = dwmac_enable_dma_transmission,
|
|
|
|
.enable_dma_irq = dwmac_enable_dma_irq,
|
|
|
|
.disable_dma_irq = dwmac_disable_dma_irq,
|
|
|
|
.start_tx = dwmac_dma_start_tx,
|
|
|
|
.stop_tx = dwmac_dma_stop_tx,
|
|
|
|
.start_rx = dwmac_dma_start_rx,
|
|
|
|
.stop_rx = dwmac_dma_stop_rx,
|
|
|
|
.dma_interrupt = dwmac_dma_interrupt,
|
2011-09-02 05:51:41 +08:00
|
|
|
.get_hw_feature = dwmac1000_get_hw_feature,
|
2012-11-26 07:10:43 +08:00
|
|
|
.rx_watchdog = dwmac1000_rx_watchdog,
|
2010-01-07 07:07:17 +08:00
|
|
|
};
|