2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2003-10-15 23:53:47 +00:00
|
|
|
/*
|
2004-06-09 00:34:46 +00:00
|
|
|
* Freescale Three Speed Ethernet Controller driver
|
2003-10-15 23:53:47 +00:00
|
|
|
*
|
2013-09-30 09:44:42 +00:00
|
|
|
* Copyright 2004-2011, 2013 Freescale Semiconductor, Inc.
|
2003-10-15 23:53:47 +00:00
|
|
|
* (C) Copyright 2003, Motorola, Inc.
|
|
|
|
* author Andy Fleming
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <common.h>
|
2016-01-12 06:41:24 +00:00
|
|
|
#include <dm.h>
|
2003-10-15 23:53:47 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <command.h>
|
2008-08-31 21:33:25 +00:00
|
|
|
#include <tsec.h>
|
2011-04-08 07:10:54 +00:00
|
|
|
#include <fsl_mdio.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2020-07-16 10:09:12 +00:00
|
|
|
#include <miiphy.h>
|
2011-10-03 13:38:50 +00:00
|
|
|
#include <asm/processor.h>
|
2014-09-05 05:52:38 +00:00
|
|
|
#include <asm/io.h>
|
2003-10-15 23:53:47 +00:00
|
|
|
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2008-08-31 21:33:26 +00:00
|
|
|
/* Default initializations for TSEC controllers. */
|
|
|
|
|
|
|
|
static struct tsec_info_struct tsec_info[] = {
|
|
|
|
#ifdef CONFIG_TSEC1
|
|
|
|
STD_TSEC_INFO(1), /* TSEC1 */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_TSEC2
|
|
|
|
STD_TSEC_INFO(2), /* TSEC2 */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MPC85XX_FEC
|
|
|
|
{
|
2013-09-30 09:44:42 +00:00
|
|
|
.regs = TSEC_GET_REGS(2, 0x2000),
|
2008-08-31 21:33:26 +00:00
|
|
|
.devname = CONFIG_MPC85XX_FEC_NAME,
|
|
|
|
.phyaddr = FEC_PHY_ADDR,
|
2011-04-08 07:10:54 +00:00
|
|
|
.flags = FEC_FLAGS,
|
|
|
|
.mii_devname = DEFAULT_MII_NAME
|
2008-08-31 21:33:26 +00:00
|
|
|
}, /* FEC */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_TSEC3
|
|
|
|
STD_TSEC_INFO(3), /* TSEC3 */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_TSEC4
|
|
|
|
STD_TSEC_INFO(4), /* TSEC4 */
|
|
|
|
#endif
|
|
|
|
};
|
2016-01-12 06:41:24 +00:00
|
|
|
#endif /* CONFIG_DM_ETH */
|
2008-08-31 21:33:26 +00:00
|
|
|
|
2008-08-31 21:33:27 +00:00
|
|
|
#define TBIANA_SETTINGS ( \
|
|
|
|
TBIANA_ASYMMETRIC_PAUSE \
|
|
|
|
| TBIANA_SYMMETRIC_PAUSE \
|
|
|
|
| TBIANA_FULL_DUPLEX \
|
|
|
|
)
|
|
|
|
|
2010-06-27 22:57:39 +00:00
|
|
|
/* By default force the TBI PHY into 1000Mbps full duplex when in SGMII mode */
|
|
|
|
#ifndef CONFIG_TSEC_TBICR_SETTINGS
|
2010-12-02 04:55:54 +00:00
|
|
|
#define CONFIG_TSEC_TBICR_SETTINGS ( \
|
2008-08-31 21:33:27 +00:00
|
|
|
TBICR_PHY_RESET \
|
2010-12-02 04:55:54 +00:00
|
|
|
| TBICR_ANEG_ENABLE \
|
2008-08-31 21:33:27 +00:00
|
|
|
| TBICR_FULL_DUPLEX \
|
|
|
|
| TBICR_SPEED1_SET \
|
|
|
|
)
|
2010-06-27 22:57:39 +00:00
|
|
|
#endif /* CONFIG_TSEC_TBICR_SETTINGS */
|
2009-11-03 23:52:07 +00:00
|
|
|
|
2008-08-31 21:33:27 +00:00
|
|
|
/* Configure the TBI for SGMII operation */
|
|
|
|
static void tsec_configure_serdes(struct tsec_private *priv)
|
|
|
|
{
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Access TBI PHY registers at given TSEC register offset as opposed
|
|
|
|
* to the register offset used for external PHY accesses
|
|
|
|
*/
|
2011-04-08 07:10:54 +00:00
|
|
|
tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
|
2018-01-15 10:08:21 +00:00
|
|
|
0, TBI_ANA, TBIANA_SETTINGS);
|
2011-04-08 07:10:54 +00:00
|
|
|
tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
|
2018-01-15 10:08:21 +00:00
|
|
|
0, TBI_TBICON, TBICON_CLK_SELECT);
|
2011-04-08 07:10:54 +00:00
|
|
|
tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
|
2018-01-15 10:08:21 +00:00
|
|
|
0, TBI_CR, CONFIG_TSEC_TBICR_SETTINGS);
|
2004-06-09 00:34:46 +00:00
|
|
|
}
|
2003-10-15 23:53:47 +00:00
|
|
|
|
2018-11-26 08:00:28 +00:00
|
|
|
/* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c
|
|
|
|
* and this is the ethernet-crc method needed for TSEC -- and perhaps
|
|
|
|
* some other adapter -- hash tables
|
|
|
|
*/
|
|
|
|
#define CRCPOLY_LE 0xedb88320
|
|
|
|
static u32 ether_crc(size_t len, unsigned char const *p)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 crc;
|
|
|
|
|
|
|
|
crc = ~0;
|
|
|
|
while (len--) {
|
|
|
|
crc ^= *p++;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
|
|
|
|
}
|
|
|
|
/* an reverse the bits, cuz of way they arrive -- last-first */
|
|
|
|
crc = (crc >> 16) | (crc << 16);
|
|
|
|
crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00);
|
|
|
|
crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0);
|
|
|
|
crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc);
|
|
|
|
crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa);
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
|
|
|
|
|
|
|
|
/* Set the appropriate hash bit for the given addr */
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* The algorithm works like so:
|
2011-01-27 04:52:46 +00:00
|
|
|
* 1) Take the Destination Address (ie the multicast address), and
|
|
|
|
* do a CRC on it (little endian), and reverse the bits of the
|
|
|
|
* result.
|
|
|
|
* 2) Use the 8 most significant bits as a hash into a 256-entry
|
|
|
|
* table. The table is controlled through 8 32-bit registers:
|
2013-09-30 09:44:40 +00:00
|
|
|
* gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is entry
|
|
|
|
* 255. This means that the 3 most significant bits in the
|
2011-01-27 04:52:46 +00:00
|
|
|
* hash index which gaddr register to use, and the 5 other bits
|
|
|
|
* indicate which bit (assuming an IBM numbering scheme, which
|
2013-09-30 09:44:40 +00:00
|
|
|
* for PowerPC (tm) is usually the case) in the register holds
|
2016-01-12 06:41:18 +00:00
|
|
|
* the entry.
|
|
|
|
*/
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2018-11-26 08:00:29 +00:00
|
|
|
static int tsec_mcast_addr(struct eth_device *dev, const u8 *mcast_mac,
|
|
|
|
int join)
|
2016-01-12 06:41:24 +00:00
|
|
|
#else
|
2018-11-26 08:00:29 +00:00
|
|
|
static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join)
|
2016-01-12 06:41:24 +00:00
|
|
|
#endif
|
2011-01-27 04:52:46 +00:00
|
|
|
{
|
2013-09-30 09:44:41 +00:00
|
|
|
struct tsec_private *priv = (struct tsec_private *)dev->priv;
|
2013-09-30 09:44:40 +00:00
|
|
|
struct tsec __iomem *regs = priv->regs;
|
|
|
|
u32 result, value;
|
|
|
|
u8 whichbit, whichreg;
|
|
|
|
|
|
|
|
result = ether_crc(MAC_ADDR_LEN, mcast_mac);
|
|
|
|
whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */
|
|
|
|
whichreg = result >> 29; /* the 3 MSB = which reg to set it in */
|
|
|
|
|
2018-01-15 10:08:21 +00:00
|
|
|
value = BIT(31 - whichbit);
|
2013-09-30 09:44:40 +00:00
|
|
|
|
2018-11-26 08:00:29 +00:00
|
|
|
if (join)
|
2013-09-30 09:44:40 +00:00
|
|
|
setbits_be32(®s->hash.gaddr0 + whichreg, value);
|
|
|
|
else
|
|
|
|
clrbits_be32(®s->hash.gaddr0 + whichreg, value);
|
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Initialized required registers to appropriate values, zeroing
|
2011-01-27 04:52:46 +00:00
|
|
|
* those we don't care about (unless zero is bad, in which case,
|
|
|
|
* choose a more appropriate value)
|
|
|
|
*/
|
2013-09-30 09:44:42 +00:00
|
|
|
static void init_registers(struct tsec __iomem *regs)
|
2011-01-27 04:52:46 +00:00
|
|
|
{
|
|
|
|
/* Clear IEVENT */
|
|
|
|
out_be32(®s->ievent, IEVENT_INIT_CLEAR);
|
|
|
|
|
|
|
|
out_be32(®s->imask, IMASK_INIT_CLEAR);
|
|
|
|
|
|
|
|
out_be32(®s->hash.iaddr0, 0);
|
|
|
|
out_be32(®s->hash.iaddr1, 0);
|
|
|
|
out_be32(®s->hash.iaddr2, 0);
|
|
|
|
out_be32(®s->hash.iaddr3, 0);
|
|
|
|
out_be32(®s->hash.iaddr4, 0);
|
|
|
|
out_be32(®s->hash.iaddr5, 0);
|
|
|
|
out_be32(®s->hash.iaddr6, 0);
|
|
|
|
out_be32(®s->hash.iaddr7, 0);
|
|
|
|
|
|
|
|
out_be32(®s->hash.gaddr0, 0);
|
|
|
|
out_be32(®s->hash.gaddr1, 0);
|
|
|
|
out_be32(®s->hash.gaddr2, 0);
|
|
|
|
out_be32(®s->hash.gaddr3, 0);
|
|
|
|
out_be32(®s->hash.gaddr4, 0);
|
|
|
|
out_be32(®s->hash.gaddr5, 0);
|
|
|
|
out_be32(®s->hash.gaddr6, 0);
|
|
|
|
out_be32(®s->hash.gaddr7, 0);
|
|
|
|
|
|
|
|
out_be32(®s->rctrl, 0x00000000);
|
|
|
|
|
|
|
|
/* Init RMON mib registers */
|
2013-09-30 09:44:46 +00:00
|
|
|
memset((void *)®s->rmon, 0, sizeof(regs->rmon));
|
2011-01-27 04:52:46 +00:00
|
|
|
|
|
|
|
out_be32(®s->rmon.cam1, 0xffffffff);
|
|
|
|
out_be32(®s->rmon.cam2, 0xffffffff);
|
|
|
|
|
|
|
|
out_be32(®s->mrblr, MRBLR_INIT_SETTINGS);
|
|
|
|
|
|
|
|
out_be32(®s->minflr, MINFLR_INIT_SETTINGS);
|
|
|
|
|
|
|
|
out_be32(®s->attr, ATTR_INIT_SETTINGS);
|
|
|
|
out_be32(®s->attreli, ATTRELI_INIT_SETTINGS);
|
|
|
|
}
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Configure maccfg2 based on negotiated speed and duplex
|
2011-01-27 04:52:46 +00:00
|
|
|
* reported by PHY handling code
|
|
|
|
*/
|
2011-04-08 07:10:54 +00:00
|
|
|
static void adjust_link(struct tsec_private *priv, struct phy_device *phydev)
|
2011-01-27 04:52:46 +00:00
|
|
|
{
|
2013-09-30 09:44:42 +00:00
|
|
|
struct tsec __iomem *regs = priv->regs;
|
2011-01-27 04:52:46 +00:00
|
|
|
u32 ecntrl, maccfg2;
|
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
if (!phydev->link) {
|
|
|
|
printf("%s: No link.\n", phydev->dev->name);
|
2011-01-27 04:52:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear all bits relative with interface mode */
|
|
|
|
ecntrl = in_be32(®s->ecntrl);
|
|
|
|
ecntrl &= ~ECNTRL_R100;
|
|
|
|
|
|
|
|
maccfg2 = in_be32(®s->maccfg2);
|
|
|
|
maccfg2 &= ~(MACCFG2_IF | MACCFG2_FULL_DUPLEX);
|
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
if (phydev->duplex)
|
2011-01-27 04:52:46 +00:00
|
|
|
maccfg2 |= MACCFG2_FULL_DUPLEX;
|
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
switch (phydev->speed) {
|
2011-01-27 04:52:46 +00:00
|
|
|
case 1000:
|
|
|
|
maccfg2 |= MACCFG2_GMII;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
case 10:
|
|
|
|
maccfg2 |= MACCFG2_MII;
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Set R100 bit in all modes although
|
2011-01-27 04:52:46 +00:00
|
|
|
* it is only used in RGMII mode
|
|
|
|
*/
|
2011-04-08 07:10:54 +00:00
|
|
|
if (phydev->speed == 100)
|
2011-01-27 04:52:46 +00:00
|
|
|
ecntrl |= ECNTRL_R100;
|
|
|
|
break;
|
|
|
|
default:
|
2011-04-08 07:10:54 +00:00
|
|
|
printf("%s: Speed was bad\n", phydev->dev->name);
|
2011-01-27 04:52:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_be32(®s->ecntrl, ecntrl);
|
|
|
|
out_be32(®s->maccfg2, maccfg2);
|
2005-04-04 23:43:44 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
printf("Speed: %d, %s duplex%s\n", phydev->speed,
|
2018-01-15 10:08:21 +00:00
|
|
|
(phydev->duplex) ? "full" : "half",
|
|
|
|
(phydev->port == PORT_FIBRE) ? ", fiber mode" : "");
|
2011-01-27 04:52:46 +00:00
|
|
|
}
|
2005-03-14 23:56:42 +00:00
|
|
|
|
2016-01-12 06:41:21 +00:00
|
|
|
/*
|
|
|
|
* This returns the status bits of the device. The return value
|
|
|
|
* is never checked, and this is what the 8260 driver did, so we
|
|
|
|
* do the same. Presumably, this would be zero if there were no
|
|
|
|
* errors
|
|
|
|
*/
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2016-01-12 06:41:21 +00:00
|
|
|
static int tsec_send(struct eth_device *dev, void *packet, int length)
|
2016-01-12 06:41:24 +00:00
|
|
|
#else
|
|
|
|
static int tsec_send(struct udevice *dev, void *packet, int length)
|
|
|
|
#endif
|
2016-01-12 06:41:21 +00:00
|
|
|
{
|
|
|
|
struct tsec_private *priv = (struct tsec_private *)dev->priv;
|
|
|
|
struct tsec __iomem *regs = priv->regs;
|
|
|
|
int result = 0;
|
2019-07-18 21:29:55 +00:00
|
|
|
u16 status;
|
2016-01-12 06:41:21 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Find an empty buffer descriptor */
|
|
|
|
for (i = 0;
|
|
|
|
in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY;
|
|
|
|
i++) {
|
|
|
|
if (i >= TOUT_LOOP) {
|
2019-07-18 21:29:56 +00:00
|
|
|
printf("%s: tsec: tx buffers full\n", dev->name);
|
2016-01-12 06:41:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out_be32(&priv->txbd[priv->tx_idx].bufptr, (u32)packet);
|
|
|
|
out_be16(&priv->txbd[priv->tx_idx].length, length);
|
|
|
|
status = in_be16(&priv->txbd[priv->tx_idx].status);
|
|
|
|
out_be16(&priv->txbd[priv->tx_idx].status, status |
|
|
|
|
(TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT));
|
|
|
|
|
|
|
|
/* Tell the DMA to go */
|
|
|
|
out_be32(®s->tstat, TSTAT_CLEAR_THALT);
|
|
|
|
|
|
|
|
/* Wait for buffer to be transmitted */
|
|
|
|
for (i = 0;
|
|
|
|
in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY;
|
|
|
|
i++) {
|
|
|
|
if (i >= TOUT_LOOP) {
|
2019-07-18 21:29:56 +00:00
|
|
|
printf("%s: tsec: tx error\n", dev->name);
|
2016-01-12 06:41:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->tx_idx = (priv->tx_idx + 1) % TX_BUF_CNT;
|
|
|
|
result = in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_STATS;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2016-01-12 06:41:21 +00:00
|
|
|
static int tsec_recv(struct eth_device *dev)
|
|
|
|
{
|
|
|
|
struct tsec_private *priv = (struct tsec_private *)dev->priv;
|
|
|
|
struct tsec __iomem *regs = priv->regs;
|
|
|
|
|
|
|
|
while (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) {
|
|
|
|
int length = in_be16(&priv->rxbd[priv->rx_idx].length);
|
2018-01-15 10:08:21 +00:00
|
|
|
u16 status = in_be16(&priv->rxbd[priv->rx_idx].status);
|
2016-01-12 06:41:21 +00:00
|
|
|
uchar *packet = net_rx_packets[priv->rx_idx];
|
|
|
|
|
|
|
|
/* Send the packet up if there were no errors */
|
|
|
|
if (!(status & RXBD_STATS))
|
|
|
|
net_process_received_packet(packet, length - 4);
|
|
|
|
else
|
|
|
|
printf("Got error %x\n", (status & RXBD_STATS));
|
|
|
|
|
|
|
|
out_be16(&priv->rxbd[priv->rx_idx].length, 0);
|
|
|
|
|
|
|
|
status = RXBD_EMPTY;
|
|
|
|
/* Set the wrap bit if this is the last element in the list */
|
|
|
|
if ((priv->rx_idx + 1) == PKTBUFSRX)
|
|
|
|
status |= RXBD_WRAP;
|
|
|
|
out_be16(&priv->rxbd[priv->rx_idx].status, status);
|
|
|
|
|
|
|
|
priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_be32(®s->ievent) & IEVENT_BSY) {
|
|
|
|
out_be32(®s->ievent, IEVENT_BSY);
|
|
|
|
out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-01-12 06:41:24 +00:00
|
|
|
#else
|
|
|
|
static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
|
|
|
|
{
|
|
|
|
struct tsec_private *priv = (struct tsec_private *)dev->priv;
|
|
|
|
struct tsec __iomem *regs = priv->regs;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) {
|
|
|
|
int length = in_be16(&priv->rxbd[priv->rx_idx].length);
|
2018-01-15 10:08:21 +00:00
|
|
|
u16 status = in_be16(&priv->rxbd[priv->rx_idx].status);
|
|
|
|
u32 buf;
|
2016-01-12 06:41:24 +00:00
|
|
|
|
|
|
|
/* Send the packet up if there were no errors */
|
|
|
|
if (!(status & RXBD_STATS)) {
|
|
|
|
buf = in_be32(&priv->rxbd[priv->rx_idx].bufptr);
|
|
|
|
*packetp = (uchar *)buf;
|
|
|
|
ret = length - 4;
|
|
|
|
} else {
|
|
|
|
printf("Got error %x\n", (status & RXBD_STATS));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_be32(®s->ievent) & IEVENT_BSY) {
|
|
|
|
out_be32(®s->ievent, IEVENT_BSY);
|
|
|
|
out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length)
|
|
|
|
{
|
|
|
|
struct tsec_private *priv = (struct tsec_private *)dev->priv;
|
2018-01-15 10:08:21 +00:00
|
|
|
u16 status;
|
2016-01-12 06:41:24 +00:00
|
|
|
|
|
|
|
out_be16(&priv->rxbd[priv->rx_idx].length, 0);
|
|
|
|
|
|
|
|
status = RXBD_EMPTY;
|
|
|
|
/* Set the wrap bit if this is the last element in the list */
|
|
|
|
if ((priv->rx_idx + 1) == PKTBUFSRX)
|
|
|
|
status |= RXBD_WRAP;
|
|
|
|
out_be16(&priv->rxbd[priv->rx_idx].status, status);
|
|
|
|
|
|
|
|
priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2016-01-12 06:41:21 +00:00
|
|
|
|
|
|
|
/* Stop the interface */
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2016-01-12 06:41:21 +00:00
|
|
|
static void tsec_halt(struct eth_device *dev)
|
2016-01-12 06:41:24 +00:00
|
|
|
#else
|
|
|
|
static void tsec_halt(struct udevice *dev)
|
|
|
|
#endif
|
2016-01-12 06:41:21 +00:00
|
|
|
{
|
|
|
|
struct tsec_private *priv = (struct tsec_private *)dev->priv;
|
|
|
|
struct tsec __iomem *regs = priv->regs;
|
|
|
|
|
|
|
|
clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
|
|
|
|
setbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
|
|
|
|
|
|
|
|
while ((in_be32(®s->ievent) & (IEVENT_GRSC | IEVENT_GTSC))
|
|
|
|
!= (IEVENT_GRSC | IEVENT_GTSC))
|
|
|
|
;
|
|
|
|
|
|
|
|
clrbits_be32(®s->maccfg1, MACCFG1_TX_EN | MACCFG1_RX_EN);
|
|
|
|
|
|
|
|
/* Shut down the PHY, as needed */
|
|
|
|
phy_shutdown(priv->phydev);
|
|
|
|
}
|
|
|
|
|
2011-10-03 13:38:50 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129
|
|
|
|
/*
|
|
|
|
* When MACCFG1[Rx_EN] is enabled during system boot as part
|
|
|
|
* of the eTSEC port initialization sequence,
|
|
|
|
* the eTSEC Rx logic may not be properly initialized.
|
|
|
|
*/
|
2016-01-12 06:41:22 +00:00
|
|
|
void redundant_init(struct tsec_private *priv)
|
2011-10-03 13:38:50 +00:00
|
|
|
{
|
2013-09-30 09:44:42 +00:00
|
|
|
struct tsec __iomem *regs = priv->regs;
|
2011-10-03 13:38:50 +00:00
|
|
|
uint t, count = 0;
|
|
|
|
int fail = 1;
|
|
|
|
static const u8 pkt[] = {
|
|
|
|
0x00, 0x1e, 0x4f, 0x12, 0xcb, 0x2c, 0x00, 0x25,
|
|
|
|
0x64, 0xbb, 0xd1, 0xab, 0x08, 0x00, 0x45, 0x00,
|
|
|
|
0x00, 0x5c, 0xdd, 0x22, 0x00, 0x00, 0x80, 0x01,
|
|
|
|
0x1f, 0x71, 0x0a, 0xc1, 0x14, 0x22, 0x0a, 0xc1,
|
|
|
|
0x14, 0x6a, 0x08, 0x00, 0xef, 0x7e, 0x02, 0x00,
|
|
|
|
0x94, 0x05, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
|
|
|
|
0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
|
|
|
|
0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
|
|
|
|
0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
|
|
|
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
|
|
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
|
|
|
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
|
|
|
|
0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
|
|
|
|
0x71, 0x72};
|
|
|
|
|
|
|
|
/* Enable promiscuous mode */
|
|
|
|
setbits_be32(®s->rctrl, 0x8);
|
|
|
|
/* Enable loopback mode */
|
|
|
|
setbits_be32(®s->maccfg1, MACCFG1_LOOPBACK);
|
|
|
|
/* Enable transmit and receive */
|
|
|
|
setbits_be32(®s->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN);
|
|
|
|
|
|
|
|
/* Tell the DMA it is clear to go */
|
|
|
|
setbits_be32(®s->dmactrl, DMACTRL_INIT_SETTINGS);
|
|
|
|
out_be32(®s->tstat, TSTAT_CLEAR_THALT);
|
|
|
|
out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
|
|
|
|
clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
|
|
|
|
|
|
|
|
do {
|
2018-01-15 10:08:21 +00:00
|
|
|
u16 status;
|
|
|
|
|
2016-01-12 06:41:22 +00:00
|
|
|
tsec_send(priv->dev, (void *)pkt, sizeof(pkt));
|
2011-10-03 13:38:50 +00:00
|
|
|
|
|
|
|
/* Wait for buffer to be received */
|
2016-01-12 06:41:20 +00:00
|
|
|
for (t = 0;
|
|
|
|
in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY;
|
2016-01-12 06:41:19 +00:00
|
|
|
t++) {
|
2011-10-03 13:38:50 +00:00
|
|
|
if (t >= 10 * TOUT_LOOP) {
|
2016-01-12 06:41:22 +00:00
|
|
|
printf("%s: tsec: rx error\n", priv->dev->name);
|
2011-10-03 13:38:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 06:41:19 +00:00
|
|
|
if (!memcmp(pkt, net_rx_packets[priv->rx_idx], sizeof(pkt)))
|
2011-10-03 13:38:50 +00:00
|
|
|
fail = 0;
|
|
|
|
|
2016-01-12 06:41:20 +00:00
|
|
|
out_be16(&priv->rxbd[priv->rx_idx].length, 0);
|
2013-10-04 16:13:53 +00:00
|
|
|
status = RXBD_EMPTY;
|
2016-01-12 06:41:19 +00:00
|
|
|
if ((priv->rx_idx + 1) == PKTBUFSRX)
|
2013-10-04 16:13:53 +00:00
|
|
|
status |= RXBD_WRAP;
|
2016-01-12 06:41:20 +00:00
|
|
|
out_be16(&priv->rxbd[priv->rx_idx].status, status);
|
2016-01-12 06:41:19 +00:00
|
|
|
priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX;
|
2011-10-03 13:38:50 +00:00
|
|
|
|
|
|
|
if (in_be32(®s->ievent) & IEVENT_BSY) {
|
|
|
|
out_be32(®s->ievent, IEVENT_BSY);
|
|
|
|
out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
|
|
|
|
}
|
|
|
|
if (fail) {
|
|
|
|
printf("loopback recv packet error!\n");
|
|
|
|
clrbits_be32(®s->maccfg1, MACCFG1_RX_EN);
|
|
|
|
udelay(1000);
|
|
|
|
setbits_be32(®s->maccfg1, MACCFG1_RX_EN);
|
|
|
|
}
|
|
|
|
} while ((count++ < 4) && (fail == 1));
|
|
|
|
|
|
|
|
if (fail)
|
|
|
|
panic("eTSEC init fail!\n");
|
|
|
|
/* Disable promiscuous mode */
|
|
|
|
clrbits_be32(®s->rctrl, 0x8);
|
|
|
|
/* Disable loopback mode */
|
|
|
|
clrbits_be32(®s->maccfg1, MACCFG1_LOOPBACK);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Set up the buffers and their descriptors, and bring up the
|
2011-01-27 04:52:46 +00:00
|
|
|
* interface
|
2006-10-10 22:03:43 +00:00
|
|
|
*/
|
2016-01-12 06:41:22 +00:00
|
|
|
static void startup_tsec(struct tsec_private *priv)
|
2006-03-12 21:50:55 +00:00
|
|
|
{
|
2013-09-30 09:44:42 +00:00
|
|
|
struct tsec __iomem *regs = priv->regs;
|
2018-01-15 10:08:21 +00:00
|
|
|
u16 status;
|
2013-10-04 16:13:53 +00:00
|
|
|
int i;
|
2006-03-12 21:50:55 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
/* reset the indices to zero */
|
2016-01-12 06:41:19 +00:00
|
|
|
priv->rx_idx = 0;
|
|
|
|
priv->tx_idx = 0;
|
2011-10-03 13:38:50 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129
|
|
|
|
uint svr;
|
|
|
|
#endif
|
2011-04-08 07:10:54 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Point to the buffer descriptors */
|
2016-01-12 06:41:20 +00:00
|
|
|
out_be32(®s->tbase, (u32)&priv->txbd[0]);
|
|
|
|
out_be32(®s->rbase, (u32)&priv->rxbd[0]);
|
2006-03-12 21:50:55 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Initialize the Rx Buffer descriptors */
|
|
|
|
for (i = 0; i < PKTBUFSRX; i++) {
|
2016-01-12 06:41:20 +00:00
|
|
|
out_be16(&priv->rxbd[i].status, RXBD_EMPTY);
|
|
|
|
out_be16(&priv->rxbd[i].length, 0);
|
|
|
|
out_be32(&priv->rxbd[i].bufptr, (u32)net_rx_packets[i]);
|
2011-01-27 04:52:46 +00:00
|
|
|
}
|
2016-01-12 06:41:20 +00:00
|
|
|
status = in_be16(&priv->rxbd[PKTBUFSRX - 1].status);
|
|
|
|
out_be16(&priv->rxbd[PKTBUFSRX - 1].status, status | RXBD_WRAP);
|
2006-03-12 21:50:55 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Initialize the TX Buffer Descriptors */
|
|
|
|
for (i = 0; i < TX_BUF_CNT; i++) {
|
2016-01-12 06:41:20 +00:00
|
|
|
out_be16(&priv->txbd[i].status, 0);
|
|
|
|
out_be16(&priv->txbd[i].length, 0);
|
|
|
|
out_be32(&priv->txbd[i].bufptr, 0);
|
2006-03-12 21:50:55 +00:00
|
|
|
}
|
2016-01-12 06:41:20 +00:00
|
|
|
status = in_be16(&priv->txbd[TX_BUF_CNT - 1].status);
|
|
|
|
out_be16(&priv->txbd[TX_BUF_CNT - 1].status, status | TXBD_WRAP);
|
2006-03-12 21:50:55 +00:00
|
|
|
|
2011-10-03 13:38:50 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129
|
|
|
|
svr = get_svr();
|
|
|
|
if ((SVR_MAJ(svr) == 1) || IS_SVR_REV(svr, 2, 0))
|
2016-01-12 06:41:22 +00:00
|
|
|
redundant_init(priv);
|
2011-10-03 13:38:50 +00:00
|
|
|
#endif
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Enable Transmit and Receive */
|
|
|
|
setbits_be32(®s->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN);
|
|
|
|
|
|
|
|
/* Tell the DMA it is clear to go */
|
|
|
|
setbits_be32(®s->dmactrl, DMACTRL_INIT_SETTINGS);
|
|
|
|
out_be32(®s->tstat, TSTAT_CLEAR_THALT);
|
|
|
|
out_be32(®s->rstat, RSTAT_CLEAR_RHALT);
|
|
|
|
clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
|
2006-03-12 21:50:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Initializes data structures and registers for the controller,
|
|
|
|
* and brings the interface up. Returns the link status, meaning
|
2011-01-27 04:52:46 +00:00
|
|
|
* that it returns success if the link is up, failure otherwise.
|
2016-01-12 06:41:18 +00:00
|
|
|
* This allows U-Boot to find the first active controller.
|
2006-10-10 22:03:43 +00:00
|
|
|
*/
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2020-06-26 06:13:33 +00:00
|
|
|
static int tsec_init(struct eth_device *dev, struct bd_info *bd)
|
2016-01-12 06:41:24 +00:00
|
|
|
#else
|
|
|
|
static int tsec_init(struct udevice *dev)
|
|
|
|
#endif
|
2004-06-09 00:34:46 +00:00
|
|
|
{
|
2011-01-27 04:52:46 +00:00
|
|
|
struct tsec_private *priv = (struct tsec_private *)dev->priv;
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct eth_pdata *pdata = dev_get_platdata(dev);
|
2019-07-18 21:29:57 +00:00
|
|
|
#else
|
|
|
|
struct eth_device *pdata = dev;
|
2016-01-12 06:41:24 +00:00
|
|
|
#endif
|
2013-09-30 09:44:42 +00:00
|
|
|
struct tsec __iomem *regs = priv->regs;
|
2013-09-30 09:44:47 +00:00
|
|
|
u32 tempval;
|
2012-07-09 08:52:43 +00:00
|
|
|
int ret;
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Make sure the controller is stopped */
|
|
|
|
tsec_halt(dev);
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Init MACCFG2. Defaults to GMII */
|
|
|
|
out_be32(®s->maccfg2, MACCFG2_INIT_SETTINGS);
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Init ECNTRL */
|
|
|
|
out_be32(®s->ecntrl, ECNTRL_INIT_SETTINGS);
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Copy the station address into the address registers.
|
2013-09-30 09:44:47 +00:00
|
|
|
* For a station address of 0x12345678ABCD in transmission
|
|
|
|
* order (BE), MACnADDR1 is set to 0xCDAB7856 and
|
|
|
|
* MACnADDR2 is set to 0x34120000.
|
|
|
|
*/
|
2016-01-12 06:41:24 +00:00
|
|
|
tempval = (pdata->enetaddr[5] << 24) | (pdata->enetaddr[4] << 16) |
|
|
|
|
(pdata->enetaddr[3] << 8) | pdata->enetaddr[2];
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
out_be32(®s->macstnaddr1, tempval);
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2016-01-12 06:41:24 +00:00
|
|
|
tempval = (pdata->enetaddr[1] << 24) | (pdata->enetaddr[0] << 16);
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
out_be32(®s->macstnaddr2, tempval);
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Clear out (for the most part) the other registers */
|
|
|
|
init_registers(regs);
|
|
|
|
|
|
|
|
/* Ready the device for tx/rx */
|
2016-01-12 06:41:22 +00:00
|
|
|
startup_tsec(priv);
|
2011-01-27 04:52:46 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
/* Start up the PHY */
|
2012-07-09 08:52:43 +00:00
|
|
|
ret = phy_startup(priv->phydev);
|
|
|
|
if (ret) {
|
|
|
|
printf("Could not initialize PHY %s\n",
|
|
|
|
priv->phydev->dev->name);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
adjust_link(priv, priv->phydev);
|
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* If there's no link, fail */
|
2011-04-08 07:10:54 +00:00
|
|
|
return priv->phydev->link ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static phy_interface_t tsec_get_interface(struct tsec_private *priv)
|
|
|
|
{
|
2013-09-30 09:44:42 +00:00
|
|
|
struct tsec __iomem *regs = priv->regs;
|
2011-04-08 07:10:54 +00:00
|
|
|
u32 ecntrl;
|
|
|
|
|
|
|
|
ecntrl = in_be32(®s->ecntrl);
|
|
|
|
|
|
|
|
if (ecntrl & ECNTRL_SGMII_MODE)
|
|
|
|
return PHY_INTERFACE_MODE_SGMII;
|
|
|
|
|
|
|
|
if (ecntrl & ECNTRL_TBI_MODE) {
|
|
|
|
if (ecntrl & ECNTRL_REDUCED_MODE)
|
|
|
|
return PHY_INTERFACE_MODE_RTBI;
|
|
|
|
else
|
|
|
|
return PHY_INTERFACE_MODE_TBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ecntrl & ECNTRL_REDUCED_MODE) {
|
2018-01-15 10:08:21 +00:00
|
|
|
phy_interface_t interface;
|
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
if (ecntrl & ECNTRL_REDUCED_MII_MODE)
|
|
|
|
return PHY_INTERFACE_MODE_RMII;
|
2018-01-15 10:08:21 +00:00
|
|
|
|
|
|
|
interface = priv->interface;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This isn't autodetected, so it must
|
|
|
|
* be set by the platform code.
|
|
|
|
*/
|
|
|
|
if (interface == PHY_INTERFACE_MODE_RGMII_ID ||
|
|
|
|
interface == PHY_INTERFACE_MODE_RGMII_TXID ||
|
|
|
|
interface == PHY_INTERFACE_MODE_RGMII_RXID)
|
|
|
|
return interface;
|
|
|
|
|
|
|
|
return PHY_INTERFACE_MODE_RGMII;
|
2011-04-08 07:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->flags & TSEC_GIGABIT)
|
|
|
|
return PHY_INTERFACE_MODE_GMII;
|
|
|
|
|
|
|
|
return PHY_INTERFACE_MODE_MII;
|
2011-01-27 04:52:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Discover which PHY is attached to the device, and configure it
|
2011-01-27 04:52:46 +00:00
|
|
|
* properly. If the PHY is not recognized, then return 0
|
|
|
|
* (failure). Otherwise, return 1
|
2004-04-18 21:45:42 +00:00
|
|
|
*/
|
2016-01-12 06:41:22 +00:00
|
|
|
static int init_phy(struct tsec_private *priv)
|
2004-04-18 21:45:42 +00:00
|
|
|
{
|
2011-04-08 07:10:54 +00:00
|
|
|
struct phy_device *phydev;
|
2013-09-30 09:44:42 +00:00
|
|
|
struct tsec __iomem *regs = priv->regs;
|
2011-04-08 07:10:54 +00:00
|
|
|
u32 supported = (SUPPORTED_10baseT_Half |
|
|
|
|
SUPPORTED_10baseT_Full |
|
|
|
|
SUPPORTED_100baseT_Half |
|
|
|
|
SUPPORTED_100baseT_Full);
|
|
|
|
|
|
|
|
if (priv->flags & TSEC_GIGABIT)
|
|
|
|
supported |= SUPPORTED_1000baseT_Full;
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Assign a Physical address to the TBI */
|
2016-01-12 06:41:25 +00:00
|
|
|
out_be32(®s->tbipa, priv->tbiaddr);
|
2011-01-27 04:52:46 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
priv->interface = tsec_get_interface(priv);
|
2011-01-27 04:52:46 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
if (priv->interface == PHY_INTERFACE_MODE_SGMII)
|
|
|
|
tsec_configure_serdes(priv);
|
2011-01-27 04:52:46 +00:00
|
|
|
|
2020-07-16 10:09:12 +00:00
|
|
|
#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO)
|
2020-07-16 10:09:13 +00:00
|
|
|
if (ofnode_valid(ofnode_find_subnode(priv->dev->node, "fixed-link")))
|
|
|
|
phydev = phy_connect(NULL, 0, priv->dev, priv->interface);
|
|
|
|
else
|
|
|
|
phydev = dm_eth_phy_connect(priv->dev);
|
2020-07-16 10:09:12 +00:00
|
|
|
#else
|
2016-01-12 06:41:22 +00:00
|
|
|
phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev,
|
|
|
|
priv->interface);
|
2020-07-16 10:09:12 +00:00
|
|
|
#endif
|
2013-12-10 13:21:04 +00:00
|
|
|
if (!phydev)
|
|
|
|
return 0;
|
2004-04-18 21:45:42 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
phydev->supported &= supported;
|
|
|
|
phydev->advertising = phydev->supported;
|
2004-04-18 21:45:42 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
priv->phydev = phydev;
|
2011-01-27 04:52:46 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
phy_config(phydev);
|
2011-01-27 04:52:46 +00:00
|
|
|
|
|
|
|
return 1;
|
2004-04-18 21:45:42 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 06:41:24 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2016-01-12 06:41:18 +00:00
|
|
|
/*
|
|
|
|
* Initialize device structure. Returns success if PHY
|
2011-01-27 04:52:46 +00:00
|
|
|
* initialization succeeded (i.e. if it recognizes the PHY)
|
2004-04-18 21:45:42 +00:00
|
|
|
*/
|
2020-06-26 06:13:33 +00:00
|
|
|
static int tsec_initialize(struct bd_info *bis,
|
|
|
|
struct tsec_info_struct *tsec_info)
|
2004-04-18 21:45:42 +00:00
|
|
|
{
|
2019-07-18 21:29:55 +00:00
|
|
|
struct tsec_private *priv;
|
2011-01-27 04:52:46 +00:00
|
|
|
struct eth_device *dev;
|
|
|
|
int i;
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2018-01-15 10:08:21 +00:00
|
|
|
dev = (struct eth_device *)malloc(sizeof(*dev));
|
2004-04-18 21:45:42 +00:00
|
|
|
|
2018-01-15 10:08:21 +00:00
|
|
|
if (!dev)
|
2011-01-27 04:52:46 +00:00
|
|
|
return 0;
|
2004-04-18 21:45:42 +00:00
|
|
|
|
2018-01-15 10:08:21 +00:00
|
|
|
memset(dev, 0, sizeof(*dev));
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
priv = (struct tsec_private *)malloc(sizeof(*priv));
|
|
|
|
|
2018-01-15 10:08:22 +00:00
|
|
|
if (!priv) {
|
|
|
|
free(dev);
|
2011-01-27 04:52:46 +00:00
|
|
|
return 0;
|
2018-01-15 10:08:22 +00:00
|
|
|
}
|
2011-01-27 04:52:46 +00:00
|
|
|
|
|
|
|
priv->regs = tsec_info->regs;
|
|
|
|
priv->phyregs_sgmii = tsec_info->miiregs_sgmii;
|
|
|
|
|
|
|
|
priv->phyaddr = tsec_info->phyaddr;
|
2016-01-12 06:41:25 +00:00
|
|
|
priv->tbiaddr = CONFIG_SYS_TBIPA_VALUE;
|
2011-01-27 04:52:46 +00:00
|
|
|
priv->flags = tsec_info->flags;
|
2004-06-09 00:34:46 +00:00
|
|
|
|
2015-12-30 13:05:58 +00:00
|
|
|
strcpy(dev->name, tsec_info->devname);
|
2011-04-08 07:10:54 +00:00
|
|
|
priv->interface = tsec_info->interface;
|
|
|
|
priv->bus = miiphy_get_dev_by_name(tsec_info->mii_devname);
|
2016-01-12 06:41:22 +00:00
|
|
|
priv->dev = dev;
|
2011-01-27 04:52:46 +00:00
|
|
|
dev->iobase = 0;
|
|
|
|
dev->priv = priv;
|
|
|
|
dev->init = tsec_init;
|
|
|
|
dev->halt = tsec_halt;
|
|
|
|
dev->send = tsec_send;
|
|
|
|
dev->recv = tsec_recv;
|
|
|
|
dev->mcast = tsec_mcast_addr;
|
2007-06-11 15:41:07 +00:00
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/* Tell U-Boot to get the addr from the env */
|
2011-01-27 04:52:46 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
dev->enetaddr[i] = 0;
|
2007-06-11 15:41:07 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
eth_register(dev);
|
2007-06-11 15:41:07 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Reset the MAC */
|
|
|
|
setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
|
|
|
|
udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
|
|
|
|
clrbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
|
2007-06-11 15:41:07 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/* Try to initialize PHY here, and return */
|
2016-01-12 06:41:22 +00:00
|
|
|
return init_phy(priv);
|
2011-01-27 04:52:46 +00:00
|
|
|
}
|
2007-06-11 15:41:07 +00:00
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
/*
|
|
|
|
* Initialize all the TSEC devices
|
|
|
|
*
|
|
|
|
* Returns the number of TSEC devices that were initialized
|
|
|
|
*/
|
2020-06-26 06:13:33 +00:00
|
|
|
int tsec_eth_init(struct bd_info *bis, struct tsec_info_struct *tsecs,
|
|
|
|
int num)
|
2011-01-27 04:52:46 +00:00
|
|
|
{
|
|
|
|
int i;
|
2018-01-15 10:08:21 +00:00
|
|
|
int count = 0;
|
2011-01-27 04:52:46 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
2018-01-15 10:08:21 +00:00
|
|
|
int ret = tsec_initialize(bis, &tsecs[i]);
|
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
if (ret > 0)
|
|
|
|
count += ret;
|
2007-06-11 15:41:07 +00:00
|
|
|
}
|
2011-01-27 04:52:46 +00:00
|
|
|
|
|
|
|
return count;
|
2007-06-11 15:41:07 +00:00
|
|
|
}
|
2011-01-27 04:52:46 +00:00
|
|
|
|
2020-06-26 06:13:33 +00:00
|
|
|
int tsec_standard_init(struct bd_info *bis)
|
2011-01-27 04:52:46 +00:00
|
|
|
{
|
2011-04-08 07:10:54 +00:00
|
|
|
struct fsl_pq_mdio_info info;
|
|
|
|
|
2013-09-30 09:44:42 +00:00
|
|
|
info.regs = TSEC_GET_MDIO_REGS_BASE(1);
|
2011-04-08 07:10:54 +00:00
|
|
|
info.name = DEFAULT_MII_NAME;
|
|
|
|
|
|
|
|
fsl_pq_mdio_init(bis, &info);
|
|
|
|
|
2011-01-27 04:52:46 +00:00
|
|
|
return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
|
|
|
|
}
|
2016-01-12 06:41:24 +00:00
|
|
|
#else /* CONFIG_DM_ETH */
|
|
|
|
int tsec_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct eth_pdata *pdata = dev_get_platdata(dev);
|
2019-07-18 21:29:55 +00:00
|
|
|
struct tsec_private *priv = dev_get_priv(dev);
|
2018-01-15 10:08:23 +00:00
|
|
|
struct ofnode_phandle_args phandle_args;
|
2019-07-18 21:29:53 +00:00
|
|
|
u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
|
2020-07-16 10:09:14 +00:00
|
|
|
struct tsec_data *data;
|
2016-01-12 06:41:24 +00:00
|
|
|
const char *phy_mode;
|
2019-07-18 21:29:54 +00:00
|
|
|
fdt_addr_t reg;
|
2019-07-18 21:29:55 +00:00
|
|
|
ofnode parent;
|
2016-01-12 06:41:24 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-07-16 10:09:14 +00:00
|
|
|
data = (struct tsec_data *)dev_get_driver_data(dev);
|
|
|
|
|
2018-01-15 10:08:23 +00:00
|
|
|
pdata->iobase = (phys_addr_t)dev_read_addr(dev);
|
2020-05-03 14:48:42 +00:00
|
|
|
priv->regs = dev_remap_addr(dev);
|
2016-01-12 06:41:24 +00:00
|
|
|
|
2019-07-18 21:29:53 +00:00
|
|
|
ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
|
|
|
|
&phandle_args);
|
2020-05-03 14:48:43 +00:00
|
|
|
if (ret == 0) {
|
2019-07-18 21:29:53 +00:00
|
|
|
ofnode_read_u32(phandle_args.node, "reg", &tbiaddr);
|
|
|
|
|
2020-05-03 14:48:43 +00:00
|
|
|
parent = ofnode_get_parent(phandle_args.node);
|
|
|
|
if (!ofnode_valid(parent)) {
|
|
|
|
printf("No parent node for TBI PHY?\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = ofnode_get_addr_index(parent, 0);
|
|
|
|
if (reg == FDT_ADDR_T_NONE) {
|
|
|
|
printf("No 'reg' property of MII for TBI PHY\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-07-16 10:09:14 +00:00
|
|
|
priv->phyregs_sgmii = map_physmem(reg + data->mdio_regs_off,
|
2020-05-03 14:48:43 +00:00
|
|
|
0, MAP_NOCACHE);
|
|
|
|
}
|
|
|
|
|
2019-07-18 21:29:53 +00:00
|
|
|
priv->tbiaddr = tbiaddr;
|
2016-01-12 06:41:25 +00:00
|
|
|
|
2018-01-15 10:08:23 +00:00
|
|
|
phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
|
2016-01-12 06:41:24 +00:00
|
|
|
if (phy_mode)
|
|
|
|
pdata->phy_interface = phy_get_interface_by_name(phy_mode);
|
|
|
|
if (pdata->phy_interface == -1) {
|
2019-07-18 21:29:56 +00:00
|
|
|
printf("Invalid PHY interface '%s'\n", phy_mode);
|
2016-01-12 06:41:24 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
priv->interface = pdata->phy_interface;
|
|
|
|
|
|
|
|
/* Initialize flags */
|
|
|
|
priv->flags = TSEC_GIGABIT;
|
|
|
|
if (priv->interface == PHY_INTERFACE_MODE_SGMII)
|
|
|
|
priv->flags |= TSEC_SGMII;
|
|
|
|
|
|
|
|
/* Reset the MAC */
|
|
|
|
setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
|
|
|
|
udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
|
|
|
|
clrbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
|
|
|
|
|
|
|
|
priv->dev = dev;
|
|
|
|
priv->bus = miiphy_get_dev_by_name(dev->name);
|
|
|
|
|
|
|
|
/* Try to initialize PHY here, and return */
|
|
|
|
return !init_phy(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tsec_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct tsec_private *priv = dev->priv;
|
|
|
|
|
|
|
|
free(priv->phydev);
|
|
|
|
mdio_unregister(priv->bus);
|
|
|
|
mdio_free(priv->bus);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct eth_ops tsec_ops = {
|
|
|
|
.start = tsec_init,
|
|
|
|
.send = tsec_send,
|
|
|
|
.recv = tsec_recv,
|
|
|
|
.free_pkt = tsec_free_pkt,
|
|
|
|
.stop = tsec_halt,
|
|
|
|
.mcast = tsec_mcast_addr,
|
|
|
|
};
|
|
|
|
|
2020-07-16 10:09:14 +00:00
|
|
|
static struct tsec_data etsec2_data = {
|
|
|
|
.mdio_regs_off = TSEC_MDIO_REGS_OFFSET,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct tsec_data gianfar_data = {
|
|
|
|
.mdio_regs_off = 0x0,
|
|
|
|
};
|
|
|
|
|
2016-01-12 06:41:24 +00:00
|
|
|
static const struct udevice_id tsec_ids[] = {
|
2020-07-16 10:09:14 +00:00
|
|
|
{ .compatible = "fsl,etsec2", .data = (ulong)&etsec2_data },
|
|
|
|
{ .compatible = "gianfar", .data = (ulong)&gianfar_data },
|
2016-01-12 06:41:24 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(eth_tsec) = {
|
|
|
|
.name = "tsec",
|
|
|
|
.id = UCLASS_ETH,
|
|
|
|
.of_match = tsec_ids,
|
|
|
|
.probe = tsec_probe,
|
|
|
|
.remove = tsec_remove,
|
|
|
|
.ops = &tsec_ops,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct tsec_private),
|
|
|
|
.platdata_auto_alloc_size = sizeof(struct eth_pdata),
|
|
|
|
.flags = DM_FLAG_ALLOC_PRIV_DMA,
|
|
|
|
};
|
|
|
|
#endif /* CONFIG_DM_ETH */
|