2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-10-06 20:35:35 +00:00
|
|
|
/*
|
2021-06-24 06:34:41 +00:00
|
|
|
* Copyright (C) 2021 Waymo LLC
|
2011-10-06 20:35:35 +00:00
|
|
|
* Copyright (C) 2011 Michal Simek <monstr@monstr.eu>
|
|
|
|
* Copyright (C) 2011 PetaLogix
|
|
|
|
* Copyright (C) 2010 Xilinx, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2022-07-31 18:28:48 +00:00
|
|
|
#include <display_options.h>
|
2015-12-08 14:44:41 +00:00
|
|
|
#include <dm.h>
|
2022-09-29 04:56:05 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2011-10-06 20:35:35 +00:00
|
|
|
#include <net.h>
|
|
|
|
#include <malloc.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2011-10-06 20:35:35 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <miiphy.h>
|
2017-01-06 10:48:50 +00:00
|
|
|
#include <wait_bit.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2022-05-10 11:26:09 +00:00
|
|
|
#include <eth_phy.h>
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
/* Link setup */
|
|
|
|
#define XAE_EMMC_LINKSPEED_MASK 0xC0000000 /* Link speed */
|
|
|
|
#define XAE_EMMC_LINKSPD_10 0x00000000 /* Link Speed mask for 10 Mbit */
|
|
|
|
#define XAE_EMMC_LINKSPD_100 0x40000000 /* Link Speed mask for 100 Mbit */
|
|
|
|
#define XAE_EMMC_LINKSPD_1000 0x80000000 /* Link Speed mask for 1000 Mbit */
|
|
|
|
|
|
|
|
/* Interrupt Status/Enable/Mask Registers bit definitions */
|
|
|
|
#define XAE_INT_RXRJECT_MASK 0x00000008 /* Rx frame rejected */
|
|
|
|
#define XAE_INT_MGTRDY_MASK 0x00000080 /* MGT clock Lock */
|
|
|
|
|
|
|
|
/* Receive Configuration Word 1 (RCW1) Register bit definitions */
|
|
|
|
#define XAE_RCW1_RX_MASK 0x10000000 /* Receiver enable */
|
|
|
|
|
|
|
|
/* Transmitter Configuration (TC) Register bit definitions */
|
|
|
|
#define XAE_TC_TX_MASK 0x10000000 /* Transmitter enable */
|
|
|
|
|
|
|
|
#define XAE_UAW1_UNICASTADDR_MASK 0x0000FFFF
|
|
|
|
|
|
|
|
/* MDIO Management Configuration (MC) Register bit definitions */
|
|
|
|
#define XAE_MDIO_MC_MDIOEN_MASK 0x00000040 /* MII management enable*/
|
|
|
|
|
|
|
|
/* MDIO Management Control Register (MCR) Register bit definitions */
|
|
|
|
#define XAE_MDIO_MCR_PHYAD_MASK 0x1F000000 /* Phy Address Mask */
|
|
|
|
#define XAE_MDIO_MCR_PHYAD_SHIFT 24 /* Phy Address Shift */
|
|
|
|
#define XAE_MDIO_MCR_REGAD_MASK 0x001F0000 /* Reg Address Mask */
|
|
|
|
#define XAE_MDIO_MCR_REGAD_SHIFT 16 /* Reg Address Shift */
|
|
|
|
#define XAE_MDIO_MCR_OP_READ_MASK 0x00008000 /* Op Code Read Mask */
|
|
|
|
#define XAE_MDIO_MCR_OP_WRITE_MASK 0x00004000 /* Op Code Write Mask */
|
|
|
|
#define XAE_MDIO_MCR_INITIATE_MASK 0x00000800 /* Ready Mask */
|
|
|
|
#define XAE_MDIO_MCR_READY_MASK 0x00000080 /* Ready Mask */
|
|
|
|
|
|
|
|
#define XAE_MDIO_DIV_DFT 29 /* Default MDIO clock divisor */
|
|
|
|
|
2017-01-06 10:57:15 +00:00
|
|
|
#define XAXIDMA_BD_STS_ACTUAL_LEN_MASK 0x007FFFFF /* Actual len */
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
/* DMA macros */
|
|
|
|
/* Bitmasks of XAXIDMA_CR_OFFSET register */
|
|
|
|
#define XAXIDMA_CR_RUNSTOP_MASK 0x00000001 /* Start/stop DMA channel */
|
|
|
|
#define XAXIDMA_CR_RESET_MASK 0x00000004 /* Reset DMA engine */
|
|
|
|
|
|
|
|
/* Bitmasks of XAXIDMA_SR_OFFSET register */
|
|
|
|
#define XAXIDMA_HALTED_MASK 0x00000001 /* DMA channel halted */
|
|
|
|
|
|
|
|
/* Bitmask for interrupts */
|
|
|
|
#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion intr */
|
|
|
|
#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay interrupt */
|
|
|
|
#define XAXIDMA_IRQ_ALL_MASK 0x00007000 /* All interrupts */
|
|
|
|
|
|
|
|
/* Bitmasks of XAXIDMA_BD_CTRL_OFFSET register */
|
|
|
|
#define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000 /* First tx packet */
|
|
|
|
#define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000 /* Last tx packet */
|
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
/* Bitmasks for XXV Ethernet MAC */
|
|
|
|
#define XXV_TC_TX_MASK 0x00000001
|
|
|
|
#define XXV_TC_FCS_MASK 0x00000002
|
|
|
|
#define XXV_RCW1_RX_MASK 0x00000001
|
|
|
|
#define XXV_RCW1_FCS_MASK 0x00000002
|
|
|
|
|
|
|
|
#define DMAALIGN 128
|
|
|
|
#define XXV_MIN_PKT_SIZE 60
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
static u8 rxframe[PKTSIZE_ALIGN] __attribute((aligned(DMAALIGN)));
|
2021-06-24 06:34:41 +00:00
|
|
|
static u8 txminframe[XXV_MIN_PKT_SIZE] __attribute((aligned(DMAALIGN)));
|
|
|
|
|
|
|
|
enum emac_variant {
|
|
|
|
EMAC_1G = 0,
|
|
|
|
EMAC_10G_25G = 1,
|
|
|
|
};
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Reflect dma offsets */
|
|
|
|
struct axidma_reg {
|
|
|
|
u32 control; /* DMACR */
|
|
|
|
u32 status; /* DMASR */
|
2018-01-23 09:22:35 +00:00
|
|
|
u32 current; /* CURDESC low 32 bit */
|
|
|
|
u32 current_hi; /* CURDESC high 32 bit */
|
|
|
|
u32 tail; /* TAILDESC low 32 bit */
|
|
|
|
u32 tail_hi; /* TAILDESC high 32 bit */
|
2011-10-06 20:35:35 +00:00
|
|
|
};
|
|
|
|
|
2021-06-24 06:34:40 +00:00
|
|
|
/* Platform data structures */
|
|
|
|
struct axidma_plat {
|
|
|
|
struct eth_pdata eth_pdata;
|
|
|
|
struct axidma_reg *dmatx;
|
|
|
|
struct axidma_reg *dmarx;
|
2022-11-01 03:57:59 +00:00
|
|
|
int pcsaddr;
|
2021-06-24 06:34:40 +00:00
|
|
|
int phyaddr;
|
|
|
|
u8 eth_hasnobuf;
|
2023-08-11 07:43:51 +00:00
|
|
|
ofnode phynode;
|
2021-06-24 06:34:41 +00:00
|
|
|
enum emac_variant mactype;
|
2021-06-24 06:34:40 +00:00
|
|
|
};
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
/* Private driver structures */
|
|
|
|
struct axidma_priv {
|
|
|
|
struct axidma_reg *dmatx;
|
|
|
|
struct axidma_reg *dmarx;
|
2022-11-01 03:57:59 +00:00
|
|
|
int pcsaddr;
|
2011-10-06 20:35:35 +00:00
|
|
|
int phyaddr;
|
2015-12-09 13:39:42 +00:00
|
|
|
struct axi_regs *iobase;
|
2015-12-08 14:44:41 +00:00
|
|
|
phy_interface_t interface;
|
2011-10-06 20:35:35 +00:00
|
|
|
struct phy_device *phydev;
|
|
|
|
struct mii_dev *bus;
|
2017-01-06 10:57:15 +00:00
|
|
|
u8 eth_hasnobuf;
|
2023-08-11 07:43:51 +00:00
|
|
|
ofnode phynode;
|
2021-06-24 06:34:41 +00:00
|
|
|
enum emac_variant mactype;
|
2011-10-06 20:35:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* BD descriptors */
|
|
|
|
struct axidma_bd {
|
2020-09-03 14:36:43 +00:00
|
|
|
u32 next_desc; /* Next descriptor pointer */
|
|
|
|
u32 next_desc_msb;
|
|
|
|
u32 buf_addr; /* Buffer address */
|
|
|
|
u32 buf_addr_msb;
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 reserved3;
|
|
|
|
u32 reserved4;
|
|
|
|
u32 cntrl; /* Control */
|
|
|
|
u32 status; /* Status */
|
|
|
|
u32 app0;
|
|
|
|
u32 app1; /* TX start << 16 | insert */
|
|
|
|
u32 app2; /* TX csum seed */
|
|
|
|
u32 app3;
|
|
|
|
u32 app4;
|
|
|
|
u32 sw_id_offset;
|
|
|
|
u32 reserved5;
|
|
|
|
u32 reserved6;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Static BDs - driver uses only one BD */
|
|
|
|
static struct axidma_bd tx_bd __attribute((aligned(DMAALIGN)));
|
|
|
|
static struct axidma_bd rx_bd __attribute((aligned(DMAALIGN)));
|
|
|
|
|
|
|
|
struct axi_regs {
|
|
|
|
u32 reserved[3];
|
|
|
|
u32 is; /* 0xC: Interrupt status */
|
|
|
|
u32 reserved2;
|
|
|
|
u32 ie; /* 0x14: Interrupt enable */
|
|
|
|
u32 reserved3[251];
|
|
|
|
u32 rcw1; /* 0x404: Rx Configuration Word 1 */
|
|
|
|
u32 tc; /* 0x408: Tx Configuration */
|
|
|
|
u32 reserved4;
|
|
|
|
u32 emmc; /* 0x410: EMAC mode configuration */
|
|
|
|
u32 reserved5[59];
|
|
|
|
u32 mdio_mc; /* 0x500: MII Management Config */
|
|
|
|
u32 mdio_mcr; /* 0x504: MII Management Control */
|
|
|
|
u32 mdio_mwd; /* 0x508: MII Management Write Data */
|
|
|
|
u32 mdio_mrd; /* 0x50C: MII Management Read Data */
|
|
|
|
u32 reserved6[124];
|
|
|
|
u32 uaw0; /* 0x700: Unicast address word 0 */
|
|
|
|
u32 uaw1; /* 0x704: Unicast address word 1 */
|
|
|
|
};
|
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
struct xxv_axi_regs {
|
|
|
|
u32 gt_reset; /* 0x0 */
|
|
|
|
u32 reserved[2];
|
|
|
|
u32 tc; /* 0xC: Tx Configuration */
|
|
|
|
u32 reserved2;
|
|
|
|
u32 rcw1; /* 0x14: Rx Configuration Word 1 */
|
|
|
|
};
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
/* Use MII register 1 (MII status register) to detect PHY */
|
|
|
|
#define PHY_DETECT_REG 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mask used to verify certain PHY features (or register contents)
|
|
|
|
* in the register above:
|
|
|
|
* 0x1000: 10Mbps full duplex support
|
|
|
|
* 0x0800: 10Mbps half duplex support
|
|
|
|
* 0x0008: Auto-negotiation support
|
|
|
|
*/
|
|
|
|
#define PHY_DETECT_MASK 0x1808
|
|
|
|
|
2015-12-09 13:36:31 +00:00
|
|
|
static inline int mdio_wait(struct axi_regs *regs)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
|
|
|
u32 timeout = 200;
|
|
|
|
|
|
|
|
/* Wait till MDIO interface is ready to accept a new transaction. */
|
2017-11-23 06:53:12 +00:00
|
|
|
while (timeout && (!(readl(®s->mdio_mcr)
|
2011-10-06 20:35:35 +00:00
|
|
|
& XAE_MDIO_MCR_READY_MASK))) {
|
|
|
|
timeout--;
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
if (!timeout) {
|
|
|
|
printf("%s: Timeout\n", __func__);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-23 09:22:35 +00:00
|
|
|
/**
|
|
|
|
* axienet_dma_write - Memory mapped Axi DMA register Buffer Descriptor write.
|
|
|
|
* @bd: pointer to BD descriptor structure
|
|
|
|
* @desc: Address offset of DMA descriptors
|
|
|
|
*
|
|
|
|
* This function writes the value into the corresponding Axi DMA register.
|
|
|
|
*/
|
|
|
|
static inline void axienet_dma_write(struct axidma_bd *bd, u32 *desc)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
2020-09-03 14:36:43 +00:00
|
|
|
writeq((unsigned long)bd, desc);
|
2018-01-23 09:22:35 +00:00
|
|
|
#else
|
|
|
|
writel((u32)bd, desc);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-12-09 13:44:38 +00:00
|
|
|
static u32 phyread(struct axidma_priv *priv, u32 phyaddress, u32 registernum,
|
|
|
|
u16 *val)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-09 13:44:38 +00:00
|
|
|
struct axi_regs *regs = priv->iobase;
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 mdioctrlreg = 0;
|
|
|
|
|
2015-12-09 13:36:31 +00:00
|
|
|
if (mdio_wait(regs))
|
2011-10-06 20:35:35 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
mdioctrlreg = ((phyaddress << XAE_MDIO_MCR_PHYAD_SHIFT) &
|
|
|
|
XAE_MDIO_MCR_PHYAD_MASK) |
|
|
|
|
((registernum << XAE_MDIO_MCR_REGAD_SHIFT)
|
|
|
|
& XAE_MDIO_MCR_REGAD_MASK) |
|
|
|
|
XAE_MDIO_MCR_INITIATE_MASK |
|
|
|
|
XAE_MDIO_MCR_OP_READ_MASK;
|
|
|
|
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(mdioctrlreg, ®s->mdio_mcr);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2015-12-09 13:36:31 +00:00
|
|
|
if (mdio_wait(regs))
|
2011-10-06 20:35:35 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Read data */
|
2017-11-23 06:53:12 +00:00
|
|
|
*val = readl(®s->mdio_mrd);
|
2011-10-06 20:35:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-09 13:44:38 +00:00
|
|
|
static u32 phywrite(struct axidma_priv *priv, u32 phyaddress, u32 registernum,
|
|
|
|
u32 data)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-09 13:44:38 +00:00
|
|
|
struct axi_regs *regs = priv->iobase;
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 mdioctrlreg = 0;
|
|
|
|
|
2015-12-09 13:36:31 +00:00
|
|
|
if (mdio_wait(regs))
|
2011-10-06 20:35:35 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
mdioctrlreg = ((phyaddress << XAE_MDIO_MCR_PHYAD_SHIFT) &
|
|
|
|
XAE_MDIO_MCR_PHYAD_MASK) |
|
|
|
|
((registernum << XAE_MDIO_MCR_REGAD_SHIFT)
|
|
|
|
& XAE_MDIO_MCR_REGAD_MASK) |
|
|
|
|
XAE_MDIO_MCR_INITIATE_MASK |
|
|
|
|
XAE_MDIO_MCR_OP_WRITE_MASK;
|
|
|
|
|
|
|
|
/* Write data */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(data, ®s->mdio_mwd);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(mdioctrlreg, ®s->mdio_mcr);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2015-12-09 13:36:31 +00:00
|
|
|
if (mdio_wait(regs))
|
2011-10-06 20:35:35 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-08 15:10:05 +00:00
|
|
|
static int axiemac_phy_init(struct udevice *dev)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
|
|
|
u16 phyreg;
|
2020-06-03 12:18:04 +00:00
|
|
|
int i;
|
|
|
|
u32 ret;
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
2015-12-09 13:39:42 +00:00
|
|
|
struct axi_regs *regs = priv->iobase;
|
2011-10-06 20:35:35 +00:00
|
|
|
struct phy_device *phydev;
|
|
|
|
|
|
|
|
u32 supported = SUPPORTED_10baseT_Half |
|
|
|
|
SUPPORTED_10baseT_Full |
|
|
|
|
SUPPORTED_100baseT_Half |
|
|
|
|
SUPPORTED_100baseT_Full |
|
|
|
|
SUPPORTED_1000baseT_Half |
|
|
|
|
SUPPORTED_1000baseT_Full;
|
|
|
|
|
2015-12-08 15:10:05 +00:00
|
|
|
/* Set default MDIO divisor */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, ®s->mdio_mc);
|
2015-12-08 15:10:05 +00:00
|
|
|
|
2022-05-10 11:26:09 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DM_ETH_PHY))
|
|
|
|
priv->phyaddr = eth_phy_get_addr(dev);
|
|
|
|
|
2022-11-01 03:57:59 +00:00
|
|
|
/*
|
|
|
|
* Set address of PCS/PMA PHY to the one pointed by phy-handle for
|
|
|
|
* backward compatibility.
|
|
|
|
*/
|
|
|
|
if (priv->phyaddr != -1 && priv->pcsaddr == 0)
|
|
|
|
priv->pcsaddr = priv->phyaddr;
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
if (priv->phyaddr == -1) {
|
|
|
|
/* Detect the PHY address */
|
|
|
|
for (i = 31; i >= 0; i--) {
|
2015-12-09 13:44:38 +00:00
|
|
|
ret = phyread(priv, i, PHY_DETECT_REG, &phyreg);
|
2011-10-06 20:35:35 +00:00
|
|
|
if (!ret && (phyreg != 0xFFFF) &&
|
|
|
|
((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
|
|
|
|
/* Found a valid PHY address */
|
|
|
|
priv->phyaddr = i;
|
|
|
|
debug("axiemac: Found valid phy address, %x\n",
|
2015-12-09 09:54:53 +00:00
|
|
|
i);
|
2011-10-06 20:35:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interface - look at tsec */
|
2016-02-21 10:16:14 +00:00
|
|
|
phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface);
|
2022-09-29 04:56:05 +00:00
|
|
|
if (IS_ERR_OR_NULL(phydev)) {
|
|
|
|
dev_err(dev, "phy_connect() failed\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
phydev->supported &= supported;
|
|
|
|
phydev->advertising = phydev->supported;
|
|
|
|
priv->phydev = phydev;
|
2023-08-11 07:43:51 +00:00
|
|
|
if (ofnode_valid(priv->phynode))
|
|
|
|
priv->phydev->node = priv->phynode;
|
2011-10-06 20:35:35 +00:00
|
|
|
phy_config(phydev);
|
2015-12-08 15:10:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-01 03:58:00 +00:00
|
|
|
static int pcs_pma_startup(struct axidma_priv *priv)
|
|
|
|
{
|
|
|
|
u32 rc, retry_cnt = 0;
|
|
|
|
u16 mii_reg;
|
|
|
|
|
|
|
|
rc = phyread(priv, priv->pcsaddr, MII_BMCR, &mii_reg);
|
|
|
|
if (rc)
|
|
|
|
goto failed_mdio;
|
|
|
|
|
|
|
|
if (!(mii_reg & BMCR_ANENABLE)) {
|
|
|
|
mii_reg |= BMCR_ANENABLE;
|
|
|
|
if (phywrite(priv, priv->pcsaddr, MII_BMCR, mii_reg))
|
|
|
|
goto failed_mdio;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the internal PHY status and warn user if the link between it
|
|
|
|
* and the external PHY is not obtained.
|
|
|
|
*/
|
|
|
|
debug("axiemac: waiting for link status of the PCS/PMA PHY");
|
|
|
|
while (retry_cnt * 10 < PHY_ANEG_TIMEOUT) {
|
|
|
|
rc = phyread(priv, priv->pcsaddr, MII_BMSR, &mii_reg);
|
|
|
|
if ((mii_reg & BMSR_LSTATUS) && mii_reg != 0xffff && !rc) {
|
|
|
|
debug(".Done\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((retry_cnt++ % 10) == 0)
|
|
|
|
debug(".");
|
|
|
|
mdelay(10);
|
|
|
|
}
|
|
|
|
debug("\n");
|
|
|
|
printf("axiemac: Warning, PCS/PMA PHY@%d is not ready, link is down\n",
|
|
|
|
priv->pcsaddr);
|
|
|
|
return 1;
|
|
|
|
failed_mdio:
|
|
|
|
printf("axiemac: MDIO to the PCS/PMA PHY has failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-08 15:10:05 +00:00
|
|
|
/* Setting axi emac and phy to proper setting */
|
|
|
|
static int setup_phy(struct udevice *dev)
|
|
|
|
{
|
2016-02-21 10:16:15 +00:00
|
|
|
u16 temp;
|
|
|
|
u32 speed, emmc_reg, ret;
|
2015-12-08 15:10:05 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
|
|
|
struct axi_regs *regs = priv->iobase;
|
|
|
|
struct phy_device *phydev = priv->phydev;
|
|
|
|
|
2016-02-21 10:16:15 +00:00
|
|
|
if (priv->interface == PHY_INTERFACE_MODE_SGMII) {
|
|
|
|
/*
|
|
|
|
* In SGMII cases the isolate bit might set
|
|
|
|
* after DMA and ethernet resets and hence
|
|
|
|
* check and clear if set.
|
|
|
|
*/
|
2022-11-01 03:57:59 +00:00
|
|
|
ret = phyread(priv, priv->pcsaddr, MII_BMCR, &temp);
|
2016-02-21 10:16:15 +00:00
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
if (temp & BMCR_ISOLATE) {
|
|
|
|
temp &= ~BMCR_ISOLATE;
|
2022-11-01 03:57:59 +00:00
|
|
|
ret = phywrite(priv, priv->pcsaddr, MII_BMCR, temp);
|
2016-02-21 10:16:15 +00:00
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 08:52:43 +00:00
|
|
|
if (phy_startup(phydev)) {
|
|
|
|
printf("axiemac: could not initialize PHY %s\n",
|
|
|
|
phydev->dev->name);
|
|
|
|
return 0;
|
|
|
|
}
|
2022-11-01 03:58:00 +00:00
|
|
|
if (priv->interface == PHY_INTERFACE_MODE_SGMII ||
|
|
|
|
priv->interface == PHY_INTERFACE_MODE_1000BASEX) {
|
|
|
|
if (pcs_pma_startup(priv))
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-21 15:15:51 +00:00
|
|
|
if (!phydev->link) {
|
|
|
|
printf("%s: No link.\n", phydev->dev->name);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
switch (phydev->speed) {
|
|
|
|
case 1000:
|
|
|
|
speed = XAE_EMMC_LINKSPD_1000;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
speed = XAE_EMMC_LINKSPD_100;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
speed = XAE_EMMC_LINKSPD_10;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the emac for the phy speed */
|
2017-11-23 06:53:12 +00:00
|
|
|
emmc_reg = readl(®s->emmc);
|
2011-10-06 20:35:35 +00:00
|
|
|
emmc_reg &= ~XAE_EMMC_LINKSPEED_MASK;
|
|
|
|
emmc_reg |= speed;
|
|
|
|
|
|
|
|
/* Write new speed setting out to Axi Ethernet */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(emmc_reg, ®s->emmc);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting the operating speed of the MAC needs a delay. There
|
|
|
|
* doesn't seem to be register to poll, so please consider this
|
|
|
|
* during your application design.
|
|
|
|
*/
|
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STOP DMA transfers */
|
2015-12-16 08:18:12 +00:00
|
|
|
static void axiemac_stop(struct udevice *dev)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 temp;
|
|
|
|
|
|
|
|
/* Stop the hardware */
|
2017-11-23 06:53:12 +00:00
|
|
|
temp = readl(&priv->dmatx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
temp &= ~XAXIDMA_CR_RUNSTOP_MASK;
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(temp, &priv->dmatx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2017-11-23 06:53:12 +00:00
|
|
|
temp = readl(&priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
temp &= ~XAXIDMA_CR_RUNSTOP_MASK;
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(temp, &priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
debug("axiemac: Halted\n");
|
|
|
|
}
|
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
static int xxv_axi_ethernet_init(struct axidma_priv *priv)
|
|
|
|
{
|
|
|
|
struct xxv_axi_regs *regs = (struct xxv_axi_regs *)priv->iobase;
|
|
|
|
|
|
|
|
writel(readl(®s->rcw1) | XXV_RCW1_FCS_MASK, ®s->rcw1);
|
|
|
|
writel(readl(®s->tc) | XXV_TC_FCS_MASK, ®s->tc);
|
|
|
|
writel(readl(®s->tc) | XXV_TC_TX_MASK, ®s->tc);
|
|
|
|
writel(readl(®s->rcw1) | XXV_RCW1_RX_MASK, ®s->rcw1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-09 13:53:51 +00:00
|
|
|
static int axi_ethernet_init(struct axidma_priv *priv)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-09 13:53:51 +00:00
|
|
|
struct axi_regs *regs = priv->iobase;
|
2017-01-06 10:48:50 +00:00
|
|
|
int err;
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the status of the MgtRdy bit in the interrupt status
|
|
|
|
* registers. This must be done to allow the MGT clock to become stable
|
|
|
|
* for the Sgmii and 1000BaseX PHY interfaces. No other register reads
|
|
|
|
* will be valid until this bit is valid.
|
|
|
|
* The bit is always a 1 for all other PHY interfaces.
|
2017-01-06 10:57:15 +00:00
|
|
|
* Interrupt status and enable registers are not available in non
|
|
|
|
* processor mode and hence bypass in this mode
|
2011-10-06 20:35:35 +00:00
|
|
|
*/
|
2017-01-06 10:57:15 +00:00
|
|
|
if (!priv->eth_hasnobuf) {
|
2018-01-23 16:14:55 +00:00
|
|
|
err = wait_for_bit_le32(®s->is, XAE_INT_MGTRDY_MASK,
|
|
|
|
true, 200, false);
|
2017-01-06 10:57:15 +00:00
|
|
|
if (err) {
|
|
|
|
printf("%s: Timeout\n", __func__);
|
|
|
|
return 1;
|
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2017-01-06 10:57:15 +00:00
|
|
|
/*
|
|
|
|
* Stop the device and reset HW
|
|
|
|
* Disable interrupts
|
|
|
|
*/
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(0, ®s->ie);
|
2017-01-06 10:57:15 +00:00
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Disable the receiver */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(readl(®s->rcw1) & ~XAE_RCW1_RX_MASK, ®s->rcw1);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stopping the receiver in mid-packet causes a dropped packet
|
|
|
|
* indication from HW. Clear it.
|
|
|
|
*/
|
2017-01-06 10:57:15 +00:00
|
|
|
if (!priv->eth_hasnobuf) {
|
|
|
|
/* Set the interrupt status register to clear the interrupt */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(XAE_INT_RXRJECT_MASK, ®s->is);
|
2017-01-06 10:57:15 +00:00
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Setup HW */
|
|
|
|
/* Set default MDIO divisor */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, ®s->mdio_mc);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
debug("axiemac: InitHw done\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-16 08:18:12 +00:00
|
|
|
static int axiemac_write_hwaddr(struct udevice *dev)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
|
|
|
struct axi_regs *regs = priv->iobase;
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
if (priv->mactype != EMAC_1G)
|
|
|
|
return 0;
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
/* Set the MAC address */
|
2015-12-08 14:44:41 +00:00
|
|
|
int val = ((pdata->enetaddr[3] << 24) | (pdata->enetaddr[2] << 16) |
|
|
|
|
(pdata->enetaddr[1] << 8) | (pdata->enetaddr[0]));
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(val, ®s->uaw0);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
val = (pdata->enetaddr[5] << 8) | pdata->enetaddr[4];
|
2017-11-23 06:53:12 +00:00
|
|
|
val |= readl(®s->uaw1) & ~XAE_UAW1_UNICASTADDR_MASK;
|
|
|
|
writel(val, ®s->uaw1);
|
2011-10-06 20:35:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset DMA engine */
|
2015-12-09 13:53:51 +00:00
|
|
|
static void axi_dma_init(struct axidma_priv *priv)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
|
|
|
u32 timeout = 500;
|
|
|
|
|
|
|
|
/* Reset the engine so the hardware starts from a known state */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(XAXIDMA_CR_RESET_MASK, &priv->dmatx->control);
|
|
|
|
writel(XAXIDMA_CR_RESET_MASK, &priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* At the initialization time, hardware should finish reset quickly */
|
|
|
|
while (timeout--) {
|
|
|
|
/* Check transmit/receive channel */
|
|
|
|
/* Reset is done when the reset bit is low */
|
2017-11-23 06:53:12 +00:00
|
|
|
if (!((readl(&priv->dmatx->control) |
|
|
|
|
readl(&priv->dmarx->control))
|
2015-10-28 10:00:47 +00:00
|
|
|
& XAXIDMA_CR_RESET_MASK)) {
|
2011-10-06 20:35:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!timeout)
|
|
|
|
printf("%s: Timeout\n", __func__);
|
|
|
|
}
|
|
|
|
|
2015-12-16 08:18:12 +00:00
|
|
|
static int axiemac_start(struct udevice *dev)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 temp;
|
|
|
|
|
|
|
|
debug("axiemac: Init started\n");
|
|
|
|
/*
|
|
|
|
* Initialize AXIDMA engine. AXIDMA engine must be initialized before
|
|
|
|
* AxiEthernet. During AXIDMA engine initialization, AXIDMA hardware is
|
|
|
|
* reset, and since AXIDMA reset line is connected to AxiEthernet, this
|
|
|
|
* would ensure a reset of AxiEthernet.
|
|
|
|
*/
|
2015-12-09 13:53:51 +00:00
|
|
|
axi_dma_init(priv);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Initialize AxiEthernet hardware. */
|
2021-06-24 06:34:41 +00:00
|
|
|
if (priv->mactype == EMAC_1G) {
|
|
|
|
if (axi_ethernet_init(priv))
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
if (xxv_axi_ethernet_init(priv))
|
|
|
|
return -1;
|
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Disable all RX interrupts before RxBD space setup */
|
2017-11-23 06:53:12 +00:00
|
|
|
temp = readl(&priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
temp &= ~XAXIDMA_IRQ_ALL_MASK;
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(temp, &priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Start DMA RX channel. Now it's ready to receive data.*/
|
2018-01-23 09:22:35 +00:00
|
|
|
axienet_dma_write(&rx_bd, &priv->dmarx->current);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Setup the BD. */
|
|
|
|
memset(&rx_bd, 0, sizeof(rx_bd));
|
2020-09-03 14:36:43 +00:00
|
|
|
rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd);
|
|
|
|
rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe);
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd);
|
|
|
|
rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe);
|
|
|
|
#endif
|
2011-10-06 20:35:35 +00:00
|
|
|
rx_bd.cntrl = sizeof(rxframe);
|
|
|
|
/* Flush the last BD so DMA core could see the updates */
|
2020-09-03 14:36:44 +00:00
|
|
|
flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd));
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* It is necessary to flush rxframe because if you don't do it
|
|
|
|
* then cache can contain uninitialized data */
|
2020-09-03 14:36:44 +00:00
|
|
|
flush_cache((phys_addr_t)&rxframe, sizeof(rxframe));
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Start the hardware */
|
2017-11-23 06:53:12 +00:00
|
|
|
temp = readl(&priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
temp |= XAXIDMA_CR_RUNSTOP_MASK;
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(temp, &priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Rx BD is ready - start */
|
2018-01-23 09:22:35 +00:00
|
|
|
axienet_dma_write(&rx_bd, &priv->dmarx->tail);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
if (priv->mactype == EMAC_1G) {
|
|
|
|
struct axi_regs *regs = priv->iobase;
|
|
|
|
/* Enable TX */
|
|
|
|
writel(XAE_TC_TX_MASK, ®s->tc);
|
|
|
|
/* Enable RX */
|
|
|
|
writel(XAE_RCW1_RX_MASK, ®s->rcw1);
|
|
|
|
|
|
|
|
/* PHY setup */
|
|
|
|
if (!setup_phy(dev)) {
|
|
|
|
axiemac_stop(dev);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct xxv_axi_regs *regs = (struct xxv_axi_regs *)priv->iobase;
|
|
|
|
/* Enable TX */
|
|
|
|
writel(readl(®s->tc) | XXV_TC_TX_MASK, ®s->tc);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
/* Enable RX */
|
|
|
|
writel(readl(®s->rcw1) | XXV_RCW1_RX_MASK, ®s->rcw1);
|
2011-10-06 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug("axiemac: Init complete\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
static int axiemac_send(struct udevice *dev, void *ptr, int len)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 timeout;
|
|
|
|
|
|
|
|
if (len > PKTSIZE_ALIGN)
|
|
|
|
len = PKTSIZE_ALIGN;
|
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
/* If size is less than min packet size, pad to min size */
|
|
|
|
if (priv->mactype == EMAC_10G_25G && len < XXV_MIN_PKT_SIZE) {
|
|
|
|
memset(txminframe, 0, XXV_MIN_PKT_SIZE);
|
|
|
|
memcpy(txminframe, ptr, len);
|
|
|
|
len = XXV_MIN_PKT_SIZE;
|
|
|
|
ptr = txminframe;
|
|
|
|
}
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
/* Flush packet to main memory to be trasfered by DMA */
|
2020-09-03 14:36:44 +00:00
|
|
|
flush_cache((phys_addr_t)ptr, len);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Setup Tx BD */
|
|
|
|
memset(&tx_bd, 0, sizeof(tx_bd));
|
|
|
|
/* At the end of the ring, link the last BD back to the top */
|
2020-09-03 14:36:43 +00:00
|
|
|
tx_bd.next_desc = lower_32_bits((unsigned long)&tx_bd);
|
|
|
|
tx_bd.buf_addr = lower_32_bits((unsigned long)ptr);
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
tx_bd.next_desc_msb = upper_32_bits((unsigned long)&tx_bd);
|
|
|
|
tx_bd.buf_addr_msb = upper_32_bits((unsigned long)ptr);
|
|
|
|
#endif
|
2011-10-06 20:35:35 +00:00
|
|
|
/* Save len */
|
|
|
|
tx_bd.cntrl = len | XAXIDMA_BD_CTRL_TXSOF_MASK |
|
|
|
|
XAXIDMA_BD_CTRL_TXEOF_MASK;
|
|
|
|
|
|
|
|
/* Flush the last BD so DMA core could see the updates */
|
2020-09-03 14:36:44 +00:00
|
|
|
flush_cache((phys_addr_t)&tx_bd, sizeof(tx_bd));
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2017-11-23 06:53:12 +00:00
|
|
|
if (readl(&priv->dmatx->status) & XAXIDMA_HALTED_MASK) {
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 temp;
|
2018-01-23 09:22:35 +00:00
|
|
|
axienet_dma_write(&tx_bd, &priv->dmatx->current);
|
2011-10-06 20:35:35 +00:00
|
|
|
/* Start the hardware */
|
2017-11-23 06:53:12 +00:00
|
|
|
temp = readl(&priv->dmatx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
temp |= XAXIDMA_CR_RUNSTOP_MASK;
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(temp, &priv->dmatx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start transfer */
|
2018-01-23 09:22:35 +00:00
|
|
|
axienet_dma_write(&tx_bd, &priv->dmatx->tail);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Wait for transmission to complete */
|
|
|
|
debug("axiemac: Waiting for tx to be done\n");
|
|
|
|
timeout = 200;
|
2017-11-23 06:53:12 +00:00
|
|
|
while (timeout && (!(readl(&priv->dmatx->status) &
|
2015-10-28 10:00:47 +00:00
|
|
|
(XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK)))) {
|
2011-10-06 20:35:35 +00:00
|
|
|
timeout--;
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
if (!timeout) {
|
|
|
|
printf("%s: Timeout\n", __func__);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("axiemac: Sending complete\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-09 13:53:51 +00:00
|
|
|
static int isrxready(struct axidma_priv *priv)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
|
|
|
u32 status;
|
|
|
|
|
|
|
|
/* Read pending interrupts */
|
2017-11-23 06:53:12 +00:00
|
|
|
status = readl(&priv->dmarx->status);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Acknowledge pending interrupts */
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(status & XAXIDMA_IRQ_ALL_MASK, &priv->dmarx->status);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If Reception done interrupt is asserted, call RX call back function
|
|
|
|
* to handle the processed BDs and then raise the according flag.
|
|
|
|
*/
|
|
|
|
if ((status & (XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
static int axiemac_recv(struct udevice *dev, int flags, uchar **packetp)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
|
|
|
u32 length;
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
2011-10-06 20:35:35 +00:00
|
|
|
u32 temp;
|
|
|
|
|
|
|
|
/* Wait for an incoming packet */
|
2015-12-09 13:53:51 +00:00
|
|
|
if (!isrxready(priv))
|
2023-07-19 06:53:37 +00:00
|
|
|
return -EAGAIN;
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
debug("axiemac: RX data ready\n");
|
|
|
|
|
|
|
|
/* Disable IRQ for a moment till packet is handled */
|
2017-11-23 06:53:12 +00:00
|
|
|
temp = readl(&priv->dmarx->control);
|
2011-10-06 20:35:35 +00:00
|
|
|
temp &= ~XAXIDMA_IRQ_ALL_MASK;
|
2017-11-23 06:53:12 +00:00
|
|
|
writel(temp, &priv->dmarx->control);
|
2021-06-24 06:34:41 +00:00
|
|
|
if (!priv->eth_hasnobuf && priv->mactype == EMAC_1G)
|
2017-01-06 10:57:15 +00:00
|
|
|
length = rx_bd.app4 & 0xFFFF; /* max length mask */
|
|
|
|
else
|
|
|
|
length = rx_bd.status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
print_buffer(&rxframe, &rxframe[0], 1, length, 16);
|
|
|
|
#endif
|
2015-12-09 13:13:23 +00:00
|
|
|
|
|
|
|
*packetp = rxframe;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int axiemac_free_pkt(struct udevice *dev, uchar *packet, int length)
|
|
|
|
{
|
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* It is useful to clear buffer to be sure that it is consistent */
|
|
|
|
memset(rxframe, 0, sizeof(rxframe));
|
|
|
|
#endif
|
|
|
|
/* Setup RxBD */
|
|
|
|
/* Clear the whole buffer and setup it again - all flags are cleared */
|
|
|
|
memset(&rx_bd, 0, sizeof(rx_bd));
|
2020-09-03 14:36:43 +00:00
|
|
|
rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd);
|
|
|
|
rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe);
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd);
|
|
|
|
rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe);
|
|
|
|
#endif
|
2011-10-06 20:35:35 +00:00
|
|
|
rx_bd.cntrl = sizeof(rxframe);
|
|
|
|
|
|
|
|
/* Write bd to HW */
|
2020-09-03 14:36:44 +00:00
|
|
|
flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd));
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* It is necessary to flush rxframe because if you don't do it
|
|
|
|
* then cache will contain previous packet */
|
2020-09-03 14:36:44 +00:00
|
|
|
flush_cache((phys_addr_t)&rxframe, sizeof(rxframe));
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
/* Rx BD is ready - start again */
|
2018-01-23 09:22:35 +00:00
|
|
|
axienet_dma_write(&rx_bd, &priv->dmarx->tail);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
|
|
|
debug("axiemac: RX completed, framelength = %d\n", length);
|
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
return 0;
|
2011-10-06 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
static int axiemac_miiphy_read(struct mii_dev *bus, int addr,
|
|
|
|
int devad, int reg)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-08 14:44:41 +00:00
|
|
|
int ret;
|
|
|
|
u16 value;
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
ret = phyread(bus->priv, addr, reg, &value);
|
|
|
|
debug("axiemac: Read MII 0x%x, 0x%x, 0x%x, %d\n", addr, reg,
|
|
|
|
value, ret);
|
|
|
|
return value;
|
2011-10-06 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
static int axiemac_miiphy_write(struct mii_dev *bus, int addr, int devad,
|
|
|
|
int reg, u16 value)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-08 14:44:41 +00:00
|
|
|
debug("axiemac: Write MII 0x%x, 0x%x, 0x%x\n", addr, reg, value);
|
|
|
|
return phywrite(bus->priv, addr, reg, value);
|
2011-10-06 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
static int axi_emac_probe(struct udevice *dev)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2021-06-24 06:34:40 +00:00
|
|
|
struct axidma_plat *plat = dev_get_plat(dev);
|
|
|
|
struct eth_pdata *pdata = &plat->eth_pdata;
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
2021-06-24 06:34:40 +00:00
|
|
|
priv->iobase = (struct axi_regs *)pdata->iobase;
|
|
|
|
priv->dmatx = plat->dmatx;
|
|
|
|
/* RX channel offset is 0x30 */
|
|
|
|
priv->dmarx = (struct axidma_reg *)((phys_addr_t)priv->dmatx + 0x30);
|
2021-06-24 06:34:41 +00:00
|
|
|
priv->mactype = plat->mactype;
|
|
|
|
|
|
|
|
if (priv->mactype == EMAC_1G) {
|
|
|
|
priv->eth_hasnobuf = plat->eth_hasnobuf;
|
2022-11-01 03:57:59 +00:00
|
|
|
priv->pcsaddr = plat->pcsaddr;
|
2021-06-24 06:34:41 +00:00
|
|
|
priv->phyaddr = plat->phyaddr;
|
2023-08-11 07:43:51 +00:00
|
|
|
priv->phynode = plat->phynode;
|
2021-06-24 06:34:41 +00:00
|
|
|
priv->interface = pdata->phy_interface;
|
2021-06-24 06:34:40 +00:00
|
|
|
|
2022-05-10 11:26:09 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DM_ETH_PHY))
|
|
|
|
priv->bus = eth_phy_get_mdio_bus(dev);
|
2015-12-08 14:44:41 +00:00
|
|
|
|
2022-05-10 11:26:09 +00:00
|
|
|
if (!priv->bus) {
|
|
|
|
priv->bus = mdio_alloc();
|
|
|
|
priv->bus->read = axiemac_miiphy_read;
|
|
|
|
priv->bus->write = axiemac_miiphy_write;
|
|
|
|
priv->bus->priv = priv;
|
|
|
|
|
|
|
|
ret = mdio_register_seq(priv->bus, dev_seq(dev));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_DM_ETH_PHY))
|
|
|
|
eth_phy_set_mdio_bus(dev, priv->bus);
|
2015-12-08 14:44:41 +00:00
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
axiemac_phy_init(dev);
|
|
|
|
}
|
2015-12-08 15:10:05 +00:00
|
|
|
|
2022-05-10 11:26:09 +00:00
|
|
|
printf("AXI EMAC: %lx, phyaddr %d, interface %s\n", (ulong)pdata->iobase,
|
|
|
|
priv->phyaddr, phy_string_for_interface(pdata->phy_interface));
|
|
|
|
|
2011-10-06 20:35:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
static int axi_emac_remove(struct udevice *dev)
|
2011-10-06 20:35:35 +00:00
|
|
|
{
|
2015-12-08 14:44:41 +00:00
|
|
|
struct axidma_priv *priv = dev_get_priv(dev);
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
if (priv->mactype == EMAC_1G) {
|
|
|
|
free(priv->phydev);
|
|
|
|
mdio_unregister(priv->bus);
|
|
|
|
mdio_free(priv->bus);
|
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
static const struct eth_ops axi_emac_ops = {
|
2015-12-16 08:18:12 +00:00
|
|
|
.start = axiemac_start,
|
2015-12-08 14:44:41 +00:00
|
|
|
.send = axiemac_send,
|
|
|
|
.recv = axiemac_recv,
|
2015-12-09 13:13:23 +00:00
|
|
|
.free_pkt = axiemac_free_pkt,
|
2015-12-16 08:18:12 +00:00
|
|
|
.stop = axiemac_stop,
|
|
|
|
.write_hwaddr = axiemac_write_hwaddr,
|
2015-12-08 14:44:41 +00:00
|
|
|
};
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int axi_emac_of_to_plat(struct udevice *dev)
|
2015-12-08 14:44:41 +00:00
|
|
|
{
|
2021-06-24 06:34:40 +00:00
|
|
|
struct axidma_plat *plat = dev_get_plat(dev);
|
|
|
|
struct eth_pdata *pdata = &plat->eth_pdata;
|
2023-08-11 07:43:51 +00:00
|
|
|
struct ofnode_phandle_args pcs_node, axistream_node;
|
|
|
|
ofnode phynode;
|
|
|
|
int ret;
|
2015-12-08 14:44:41 +00:00
|
|
|
|
2020-07-17 05:36:48 +00:00
|
|
|
pdata->iobase = dev_read_addr(dev);
|
2021-06-24 06:34:41 +00:00
|
|
|
plat->mactype = dev_get_driver_data(dev);
|
2015-12-08 14:44:41 +00:00
|
|
|
|
2023-08-11 07:43:51 +00:00
|
|
|
ret = dev_read_phandle_with_args(dev, "axistream-connected", NULL, 0, 0,
|
|
|
|
&axistream_node);
|
2023-11-16 16:40:24 +00:00
|
|
|
if (!ret)
|
|
|
|
plat->dmatx = (struct axidma_reg *)ofnode_get_addr(axistream_node.node);
|
|
|
|
else
|
|
|
|
plat->dmatx = (struct axidma_reg *)dev_read_addr_index(dev, 1);
|
2023-08-11 07:43:51 +00:00
|
|
|
|
2021-06-24 06:34:40 +00:00
|
|
|
if (!plat->dmatx) {
|
2015-12-08 14:44:41 +00:00
|
|
|
printf("%s: axi_dma register space not found\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-06-24 06:34:41 +00:00
|
|
|
if (plat->mactype == EMAC_1G) {
|
|
|
|
plat->phyaddr = -1;
|
2022-11-01 03:57:59 +00:00
|
|
|
/* PHYAD 0 always redirects to the PCS/PMA PHY */
|
|
|
|
plat->pcsaddr = 0;
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2023-08-11 07:43:51 +00:00
|
|
|
phynode = dev_get_phy_node(dev);
|
|
|
|
if (ofnode_valid(phynode)) {
|
2022-05-10 11:26:09 +00:00
|
|
|
if (!(IS_ENABLED(CONFIG_DM_ETH_PHY)))
|
2023-08-11 07:43:51 +00:00
|
|
|
plat->phyaddr = ofnode_read_u32_default(phynode,
|
|
|
|
"reg", -1);
|
|
|
|
plat->phynode = phynode;
|
2021-06-24 06:34:41 +00:00
|
|
|
}
|
2015-12-08 14:44:41 +00:00
|
|
|
|
2022-04-06 22:33:01 +00:00
|
|
|
pdata->phy_interface = dev_read_phy_mode(dev);
|
2022-04-06 22:33:03 +00:00
|
|
|
if (pdata->phy_interface == PHY_INTERFACE_MODE_NA)
|
2021-06-24 06:34:41 +00:00
|
|
|
return -EINVAL;
|
2011-10-06 20:35:35 +00:00
|
|
|
|
2023-08-11 07:43:51 +00:00
|
|
|
plat->eth_hasnobuf = dev_read_bool(dev, "xlnx,eth-hasnobuf");
|
2022-11-01 03:57:59 +00:00
|
|
|
|
|
|
|
if (pdata->phy_interface == PHY_INTERFACE_MODE_SGMII ||
|
|
|
|
pdata->phy_interface == PHY_INTERFACE_MODE_1000BASEX) {
|
2023-08-11 07:43:51 +00:00
|
|
|
ret = dev_read_phandle_with_args(dev, "pcs-handle", NULL, 0, 0,
|
|
|
|
&pcs_node);
|
|
|
|
if (!ret) {
|
|
|
|
plat->pcsaddr = ofnode_read_u32_default(pcs_node.node,
|
|
|
|
"reg", -1);
|
2022-11-01 03:57:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-24 06:34:41 +00:00
|
|
|
}
|
2017-01-06 10:57:15 +00:00
|
|
|
|
2015-12-08 14:44:41 +00:00
|
|
|
return 0;
|
2011-10-06 20:35:35 +00:00
|
|
|
}
|
2015-12-08 14:44:41 +00:00
|
|
|
|
|
|
|
static const struct udevice_id axi_emac_ids[] = {
|
2021-06-24 06:34:41 +00:00
|
|
|
{ .compatible = "xlnx,axi-ethernet-1.00.a", .data = (uintptr_t)EMAC_1G },
|
|
|
|
{ .compatible = "xlnx,xxv-ethernet-1.0", .data = (uintptr_t)EMAC_10G_25G },
|
2015-12-08 14:44:41 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(axi_emac) = {
|
|
|
|
.name = "axi_emac",
|
|
|
|
.id = UCLASS_ETH,
|
|
|
|
.of_match = axi_emac_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = axi_emac_of_to_plat,
|
2015-12-08 14:44:41 +00:00
|
|
|
.probe = axi_emac_probe,
|
|
|
|
.remove = axi_emac_remove,
|
|
|
|
.ops = &axi_emac_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct axidma_priv),
|
2021-06-24 06:34:40 +00:00
|
|
|
.plat_auto = sizeof(struct axidma_plat),
|
2015-12-08 14:44:41 +00:00
|
|
|
};
|