2010-01-07 07:07:18 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
Copyright (C) 2007-2009 STMicroelectronics Ltd
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms and conditions of the GNU General Public License,
|
|
|
|
version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
The full GNU General Public License is included in this distribution in
|
|
|
|
the file called "COPYING".
|
|
|
|
|
|
|
|
Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "dwmac_dma.h"
|
|
|
|
|
2012-05-14 06:18:41 +08:00
|
|
|
#define GMAC_HI_REG_AE 0x80000000
|
|
|
|
|
2010-01-07 07:07:18 +08:00
|
|
|
/* CSR1 enables the transmit DMA to check for new descriptor */
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_enable_dma_transmission(void __iomem *ioaddr)
|
2010-01-07 07:07:18 +08:00
|
|
|
{
|
|
|
|
writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_enable_dma_irq(void __iomem *ioaddr)
|
2010-01-07 07:07:18 +08:00
|
|
|
{
|
|
|
|
writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_disable_dma_irq(void __iomem *ioaddr)
|
2010-01-07 07:07:18 +08:00
|
|
|
{
|
|
|
|
writel(0, ioaddr + DMA_INTR_ENA);
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_dma_start_tx(void __iomem *ioaddr)
|
2010-01-07 07:07:18 +08:00
|
|
|
{
|
|
|
|
u32 value = readl(ioaddr + DMA_CONTROL);
|
|
|
|
value |= DMA_CONTROL_ST;
|
|
|
|
writel(value, ioaddr + DMA_CONTROL);
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_dma_stop_tx(void __iomem *ioaddr)
|
2010-01-07 07:07:18 +08:00
|
|
|
{
|
|
|
|
u32 value = readl(ioaddr + DMA_CONTROL);
|
|
|
|
value &= ~DMA_CONTROL_ST;
|
|
|
|
writel(value, ioaddr + DMA_CONTROL);
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_dma_start_rx(void __iomem *ioaddr)
|
2010-01-07 07:07:18 +08:00
|
|
|
{
|
|
|
|
u32 value = readl(ioaddr + DMA_CONTROL);
|
|
|
|
value |= DMA_CONTROL_SR;
|
|
|
|
writel(value, ioaddr + DMA_CONTROL);
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_dma_stop_rx(void __iomem *ioaddr)
|
2010-01-07 07:07:18 +08:00
|
|
|
{
|
|
|
|
u32 value = readl(ioaddr + DMA_CONTROL);
|
|
|
|
value &= ~DMA_CONTROL_SR;
|
|
|
|
writel(value, ioaddr + DMA_CONTROL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DWMAC_DMA_DEBUG
|
|
|
|
static void show_tx_process_state(unsigned int status)
|
|
|
|
{
|
|
|
|
unsigned int state;
|
|
|
|
state = (status & DMA_STATUS_TS_MASK) >> DMA_STATUS_TS_SHIFT;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- TX (Stopped): Reset or Stop command\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- TX (Running):Fetching the Tx desc\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- TX (Running): Waiting for end of tx\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- TX (Running): Reading the data "
|
2010-01-07 07:07:18 +08:00
|
|
|
"and queuing the data into the Tx buf\n");
|
|
|
|
break;
|
|
|
|
case 6:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- TX (Suspended): Tx Buff Underflow "
|
2010-01-07 07:07:18 +08:00
|
|
|
"or an unavailable Transmit descriptor\n");
|
|
|
|
break;
|
|
|
|
case 7:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- TX (Running): Closing Tx descriptor\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_rx_process_state(unsigned int status)
|
|
|
|
{
|
|
|
|
unsigned int state;
|
|
|
|
state = (status & DMA_STATUS_RS_MASK) >> DMA_STATUS_RS_SHIFT;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX (Stopped): Reset or Stop command\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX (Running): Fetching the Rx desc\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX (Running):Checking for end of pkt\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX (Running): Waiting for Rx pkt\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX (Suspended): Unavailable Rx buf\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 5:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX (Running): Closing Rx descriptor\n");
|
2010-01-07 07:07:18 +08:00
|
|
|
break;
|
|
|
|
case 6:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX(Running): Flushing the current frame"
|
2010-01-07 07:07:18 +08:00
|
|
|
" from the Rx buf\n");
|
|
|
|
break;
|
|
|
|
case 7:
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_debug("- RX (Running): Queuing the Rx frame"
|
2010-01-07 07:07:18 +08:00
|
|
|
" from the Rx buf into memory\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
int dwmac_dma_interrupt(void __iomem *ioaddr,
|
2010-01-07 07:07:18 +08:00
|
|
|
struct stmmac_extra_stats *x)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
/* read the status register (CSR5) */
|
|
|
|
u32 intr_status = readl(ioaddr + DMA_STATUS);
|
|
|
|
|
|
|
|
#ifdef DWMAC_DMA_DEBUG
|
2013-07-02 20:12:36 +08:00
|
|
|
/* Enable it to monitor DMA rx/tx status in case of critical problems */
|
|
|
|
pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
|
2010-01-07 07:07:18 +08:00
|
|
|
show_tx_process_state(intr_status);
|
|
|
|
show_rx_process_state(intr_status);
|
|
|
|
#endif
|
|
|
|
/* ABNORMAL interrupts */
|
|
|
|
if (unlikely(intr_status & DMA_STATUS_AIS)) {
|
|
|
|
if (unlikely(intr_status & DMA_STATUS_UNF)) {
|
|
|
|
ret = tx_hard_error_bump_tc;
|
|
|
|
x->tx_undeflow_irq++;
|
|
|
|
}
|
2013-07-02 20:12:36 +08:00
|
|
|
if (unlikely(intr_status & DMA_STATUS_TJT))
|
2010-01-07 07:07:18 +08:00
|
|
|
x->tx_jabber_irq++;
|
2013-07-02 20:12:36 +08:00
|
|
|
|
|
|
|
if (unlikely(intr_status & DMA_STATUS_OVF))
|
2010-01-07 07:07:18 +08:00
|
|
|
x->rx_overflow_irq++;
|
2013-07-02 20:12:36 +08:00
|
|
|
|
|
|
|
if (unlikely(intr_status & DMA_STATUS_RU))
|
2010-01-07 07:07:18 +08:00
|
|
|
x->rx_buf_unav_irq++;
|
2013-07-02 20:12:36 +08:00
|
|
|
if (unlikely(intr_status & DMA_STATUS_RPS))
|
2010-01-07 07:07:18 +08:00
|
|
|
x->rx_process_stopped_irq++;
|
2013-07-02 20:12:36 +08:00
|
|
|
if (unlikely(intr_status & DMA_STATUS_RWT))
|
2010-01-07 07:07:18 +08:00
|
|
|
x->rx_watchdog_irq++;
|
2013-07-02 20:12:36 +08:00
|
|
|
if (unlikely(intr_status & DMA_STATUS_ETI))
|
2010-01-07 07:07:18 +08:00
|
|
|
x->tx_early_irq++;
|
|
|
|
if (unlikely(intr_status & DMA_STATUS_TPS)) {
|
|
|
|
x->tx_process_stopped_irq++;
|
|
|
|
ret = tx_hard_error;
|
|
|
|
}
|
|
|
|
if (unlikely(intr_status & DMA_STATUS_FBI)) {
|
|
|
|
x->fatal_bus_error_irq++;
|
|
|
|
ret = tx_hard_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* TX/RX NORMAL interrupts */
|
2012-11-26 07:10:43 +08:00
|
|
|
if (likely(intr_status & DMA_STATUS_NIS)) {
|
2010-01-07 07:07:18 +08:00
|
|
|
x->normal_irq_n++;
|
2012-11-26 07:10:43 +08:00
|
|
|
if (likely(intr_status & DMA_STATUS_RI)) {
|
|
|
|
u32 value = readl(ioaddr + DMA_INTR_ENA);
|
|
|
|
/* to schedule NAPI on real RIE event. */
|
|
|
|
if (likely(value & DMA_INTR_ENA_RIE)) {
|
|
|
|
x->rx_normal_irq_n++;
|
|
|
|
ret |= handle_rx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (likely(intr_status & DMA_STATUS_TI)) {
|
|
|
|
x->tx_normal_irq_n++;
|
2012-11-26 07:10:42 +08:00
|
|
|
ret |= handle_tx;
|
2012-11-26 07:10:43 +08:00
|
|
|
}
|
|
|
|
if (unlikely(intr_status & DMA_STATUS_ERI))
|
|
|
|
x->rx_early_irq++;
|
2010-01-07 07:07:18 +08:00
|
|
|
}
|
|
|
|
/* Optional hardware blocks, interrupts should be disabled */
|
|
|
|
if (unlikely(intr_status &
|
|
|
|
(DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
|
2013-07-02 20:12:36 +08:00
|
|
|
pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
|
2012-11-26 07:10:43 +08:00
|
|
|
|
2010-01-07 07:07:18 +08:00
|
|
|
/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
|
|
|
|
writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr)
|
2010-04-14 04:21:13 +08:00
|
|
|
{
|
|
|
|
u32 csr6 = readl(ioaddr + DMA_CONTROL);
|
|
|
|
writel((csr6 | DMA_CONTROL_FTF), ioaddr + DMA_CONTROL);
|
|
|
|
|
|
|
|
do {} while ((readl(ioaddr + DMA_CONTROL) & DMA_CONTROL_FTF));
|
|
|
|
}
|
2010-01-07 07:07:18 +08:00
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
|
2010-01-07 07:07:18 +08:00
|
|
|
unsigned int high, unsigned int low)
|
|
|
|
{
|
|
|
|
unsigned long data;
|
|
|
|
|
|
|
|
data = (addr[5] << 8) | addr[4];
|
2012-05-14 06:18:41 +08:00
|
|
|
/* For MAC Addr registers se have to set the Address Enable (AE)
|
|
|
|
* bit that has no effect on the High Reg 0 where the bit 31 (MO)
|
|
|
|
* is RO.
|
|
|
|
*/
|
|
|
|
writel(data | GMAC_HI_REG_AE, ioaddr + high);
|
2010-01-07 07:07:18 +08:00
|
|
|
data = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
|
|
|
|
writel(data, ioaddr + low);
|
|
|
|
}
|
|
|
|
|
2011-12-21 11:58:19 +08:00
|
|
|
/* Enable disable MAC RX/TX */
|
|
|
|
void stmmac_set_mac(void __iomem *ioaddr, bool enable)
|
|
|
|
{
|
|
|
|
u32 value = readl(ioaddr + MAC_CTRL_REG);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
value |= MAC_RNABLE_RX | MAC_ENABLE_TX;
|
|
|
|
else
|
|
|
|
value &= ~(MAC_ENABLE_TX | MAC_RNABLE_RX);
|
|
|
|
|
|
|
|
writel(value, ioaddr + MAC_CTRL_REG);
|
|
|
|
}
|
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
|
2010-01-07 07:07:18 +08:00
|
|
|
unsigned int high, unsigned int low)
|
|
|
|
{
|
|
|
|
unsigned int hi_addr, lo_addr;
|
|
|
|
|
|
|
|
/* Read the MAC address from the hardware */
|
|
|
|
hi_addr = readl(ioaddr + high);
|
|
|
|
lo_addr = readl(ioaddr + low);
|
|
|
|
|
|
|
|
/* Extract the MAC address from the high and low words */
|
|
|
|
addr[0] = lo_addr & 0xff;
|
|
|
|
addr[1] = (lo_addr >> 8) & 0xff;
|
|
|
|
addr[2] = (lo_addr >> 16) & 0xff;
|
|
|
|
addr[3] = (lo_addr >> 24) & 0xff;
|
|
|
|
addr[4] = hi_addr & 0xff;
|
|
|
|
addr[5] = (hi_addr >> 8) & 0xff;
|
|
|
|
}
|
|
|
|
|