staging: mt7621-eth: add the drivers core files
Original comment: This patch adds the main chunk of the driver. The ethernet core is used in all of the Mediatek/Ralink Wireless SoCs. Over the years we have seen various changes to * the register layout * the type of ports (single/dual gbit, internal FE/Gbit switch) * dma engine (PDMA/QDMA) and new offloading features were added, such as * checksum * VLAN TX/RX * TSO * LRO The core functionality has however remained the same allowing us to use the same code for all SoCs. The abstraction for the various SoCs uses the typical ops struct pattern which allows us to extend or override the core functionality depending on which SoC we are on. The code to bring up the switches and external ports has also been split into separate files. There are 2 types of DMA engine, PDMA and the newer QDMA. PDMA uses a typical ring buffer while QDMA uses a linked list. Unfortunatley we have the MT7621 which has a few silicon issues. Due to these issues we need to PDMA for RX and QDMA for TX. All SoCs newer than the MT7621 can can run on QDMA exclusively. Most of the SoCs have a switch frontend. Older silicon has a so called ESW (Ethernet Switch) while newer cores have a GSW (Gigabit switch). Additionally there is a MDIO bus that can be used to talk to PHYs. In these cases one switch port get changed into a normal MAC port. Some SoCs have a dual MAC, we currently only support this on MT7623. NeilBrown: - removed everything not closely related to mt7621, as that is all I can test - converted ethtool.c to new ethtool_link_ksettings interfaces. Doesn't work yet. - updated some phydev interface use: e.g. dev_name() -> phydev_name() - updated mdio to use mdiobus_get_phy() - added some missing export_symbols - updated get_stats64 interface - TX_DMA_FPORT and TX_DMA_TSO to tx dma descriptor - range checked RX_DMA_FPORT in rx dma descriptor - tell hardware what mac address was chosen - fixed MT7620_GDMA1_FWD_CFG which was using wrong value Signed-off-by: John Crispin <blogic@openwrt.org> Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: Michael Lee <igvtee@gmail.com> Signed-off-by: NeilBrown <neil@brown.name> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
eb4afe3002
commit
e3cbf478f8
@ -1,4 +1,7 @@
|
||||
|
||||
- verify devicetree documentation is consistent with code
|
||||
- fix ethtool - currently doesn't return valid data.
|
||||
- general code review and clean up
|
||||
- add support for second MAC on mt7621
|
||||
|
||||
Cc: NeilBrown <neil@brown.name>
|
||||
|
225
drivers/staging/mt7621-eth/ethtool.c
Normal file
225
drivers/staging/mt7621-eth/ethtool.c
Normal file
@ -0,0 +1,225 @@
|
||||
/* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License
|
||||
*
|
||||
* This program is distributed in the hope that 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.
|
||||
*
|
||||
* Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
|
||||
* Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
|
||||
* Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
|
||||
*/
|
||||
|
||||
#include "mtk_eth_soc.h"
|
||||
|
||||
static const char mtk_gdma_str[][ETH_GSTRING_LEN] = {
|
||||
#define _FE(x...) # x,
|
||||
MTK_STAT_REG_DECLARE
|
||||
#undef _FE
|
||||
};
|
||||
|
||||
static int mtk_get_link_ksettings(struct net_device *dev,
|
||||
struct ethtool_link_ksettings *cmd)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
int err;
|
||||
|
||||
if (!mac->phy_dev)
|
||||
return -ENODEV;
|
||||
|
||||
if (mac->phy_flags == MTK_PHY_FLAG_ATTACH) {
|
||||
err = phy_read_status(mac->phy_dev);
|
||||
if (err)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
phy_ethtool_ksettings_get(mac->phy_dev, cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtk_set_link_ksettings(struct net_device *dev,
|
||||
const struct ethtool_link_ksettings *cmd)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
|
||||
if (!mac->phy_dev)
|
||||
return -ENODEV;
|
||||
|
||||
if (cmd->base.phy_address != mac->phy_dev->mdio.addr) {
|
||||
if (mac->hw->phy->phy_node[cmd->base.phy_address]) {
|
||||
mac->phy_dev = mac->hw->phy->phy[cmd->base.phy_address];
|
||||
mac->phy_flags = MTK_PHY_FLAG_PORT;
|
||||
} else if (mac->hw->mii_bus) {
|
||||
mac->phy_dev = mdiobus_get_phy(mac->hw->mii_bus, cmd->base.phy_address);
|
||||
if (!mac->phy_dev)
|
||||
return -ENODEV;
|
||||
mac->phy_flags = MTK_PHY_FLAG_ATTACH;
|
||||
} else {
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
|
||||
return phy_ethtool_ksettings_set(mac->phy_dev, cmd);
|
||||
|
||||
}
|
||||
|
||||
static void mtk_get_drvinfo(struct net_device *dev,
|
||||
struct ethtool_drvinfo *info)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
struct mtk_soc_data *soc = mac->hw->soc;
|
||||
|
||||
strlcpy(info->driver, mac->hw->dev->driver->name, sizeof(info->driver));
|
||||
strlcpy(info->bus_info, dev_name(mac->hw->dev), sizeof(info->bus_info));
|
||||
|
||||
if (soc->reg_table[MTK_REG_MTK_COUNTER_BASE])
|
||||
info->n_stats = ARRAY_SIZE(mtk_gdma_str);
|
||||
}
|
||||
|
||||
static u32 mtk_get_msglevel(struct net_device *dev)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
|
||||
return mac->hw->msg_enable;
|
||||
}
|
||||
|
||||
static void mtk_set_msglevel(struct net_device *dev, u32 value)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
|
||||
mac->hw->msg_enable = value;
|
||||
}
|
||||
|
||||
static int mtk_nway_reset(struct net_device *dev)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
|
||||
if (!mac->phy_dev)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return genphy_restart_aneg(mac->phy_dev);
|
||||
}
|
||||
|
||||
static u32 mtk_get_link(struct net_device *dev)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
int err;
|
||||
|
||||
if (!mac->phy_dev)
|
||||
goto out_get_link;
|
||||
|
||||
if (mac->phy_flags == MTK_PHY_FLAG_ATTACH) {
|
||||
err = genphy_update_link(mac->phy_dev);
|
||||
if (err)
|
||||
goto out_get_link;
|
||||
}
|
||||
|
||||
return mac->phy_dev->link;
|
||||
|
||||
out_get_link:
|
||||
return ethtool_op_get_link(dev);
|
||||
}
|
||||
|
||||
static int mtk_set_ringparam(struct net_device *dev,
|
||||
struct ethtool_ringparam *ring)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
|
||||
if ((ring->tx_pending < 2) ||
|
||||
(ring->rx_pending < 2) ||
|
||||
(ring->rx_pending > mac->hw->soc->dma_ring_size) ||
|
||||
(ring->tx_pending > mac->hw->soc->dma_ring_size))
|
||||
return -EINVAL;
|
||||
|
||||
dev->netdev_ops->ndo_stop(dev);
|
||||
|
||||
mac->hw->tx_ring.tx_ring_size = BIT(fls(ring->tx_pending) - 1);
|
||||
mac->hw->rx_ring[0].rx_ring_size = BIT(fls(ring->rx_pending) - 1);
|
||||
|
||||
return dev->netdev_ops->ndo_open(dev);
|
||||
}
|
||||
|
||||
static void mtk_get_ringparam(struct net_device *dev,
|
||||
struct ethtool_ringparam *ring)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
|
||||
ring->rx_max_pending = mac->hw->soc->dma_ring_size;
|
||||
ring->tx_max_pending = mac->hw->soc->dma_ring_size;
|
||||
ring->rx_pending = mac->hw->rx_ring[0].rx_ring_size;
|
||||
ring->tx_pending = mac->hw->tx_ring.tx_ring_size;
|
||||
}
|
||||
|
||||
static void mtk_get_strings(struct net_device *dev, u32 stringset, u8 *data)
|
||||
{
|
||||
switch (stringset) {
|
||||
case ETH_SS_STATS:
|
||||
memcpy(data, *mtk_gdma_str, sizeof(mtk_gdma_str));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int mtk_get_sset_count(struct net_device *dev, int sset)
|
||||
{
|
||||
switch (sset) {
|
||||
case ETH_SS_STATS:
|
||||
return ARRAY_SIZE(mtk_gdma_str);
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
static void mtk_get_ethtool_stats(struct net_device *dev,
|
||||
struct ethtool_stats *stats, u64 *data)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(dev);
|
||||
struct mtk_hw_stats *hwstats = mac->hw_stats;
|
||||
u64 *data_src, *data_dst;
|
||||
unsigned int start;
|
||||
int i;
|
||||
|
||||
if (netif_running(dev) && netif_device_present(dev)) {
|
||||
if (spin_trylock(&hwstats->stats_lock)) {
|
||||
mtk_stats_update_mac(mac);
|
||||
spin_unlock(&hwstats->stats_lock);
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
data_src = &hwstats->tx_bytes;
|
||||
data_dst = data;
|
||||
start = u64_stats_fetch_begin_irq(&hwstats->syncp);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mtk_gdma_str); i++)
|
||||
*data_dst++ = *data_src++;
|
||||
|
||||
} while (u64_stats_fetch_retry_irq(&hwstats->syncp, start));
|
||||
}
|
||||
|
||||
static struct ethtool_ops mtk_ethtool_ops = {
|
||||
.get_link_ksettings = mtk_get_link_ksettings,
|
||||
.set_link_ksettings = mtk_set_link_ksettings,
|
||||
.get_drvinfo = mtk_get_drvinfo,
|
||||
.get_msglevel = mtk_get_msglevel,
|
||||
.set_msglevel = mtk_set_msglevel,
|
||||
.nway_reset = mtk_nway_reset,
|
||||
.get_link = mtk_get_link,
|
||||
.set_ringparam = mtk_set_ringparam,
|
||||
.get_ringparam = mtk_get_ringparam,
|
||||
};
|
||||
|
||||
void mtk_set_ethtool_ops(struct net_device *netdev)
|
||||
{
|
||||
struct mtk_mac *mac = netdev_priv(netdev);
|
||||
struct mtk_soc_data *soc = mac->hw->soc;
|
||||
|
||||
if (soc->reg_table[MTK_REG_MTK_COUNTER_BASE]) {
|
||||
mtk_ethtool_ops.get_strings = mtk_get_strings;
|
||||
mtk_ethtool_ops.get_sset_count = mtk_get_sset_count;
|
||||
mtk_ethtool_ops.get_ethtool_stats = mtk_get_ethtool_stats;
|
||||
}
|
||||
|
||||
netdev->ethtool_ops = &mtk_ethtool_ops;
|
||||
}
|
22
drivers/staging/mt7621-eth/ethtool.h
Normal file
22
drivers/staging/mt7621-eth/ethtool.h
Normal file
@ -0,0 +1,22 @@
|
||||
/* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License
|
||||
*
|
||||
* This program is distributed in the hope that 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.
|
||||
*
|
||||
* Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
|
||||
* Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
|
||||
* Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef MTK_ETHTOOL_H
|
||||
#define MTK_ETHTOOL_H
|
||||
|
||||
#include <linux/ethtool.h>
|
||||
|
||||
void mtk_set_ethtool_ops(struct net_device *netdev);
|
||||
|
||||
#endif /* MTK_ETHTOOL_H */
|
271
drivers/staging/mt7621-eth/mdio.c
Normal file
271
drivers/staging/mt7621-eth/mdio.c
Normal file
@ -0,0 +1,271 @@
|
||||
/* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License
|
||||
*
|
||||
* Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
|
||||
* Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
|
||||
* Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/phy.h>
|
||||
#include <linux/of_net.h>
|
||||
#include <linux/of_mdio.h>
|
||||
|
||||
#include "mtk_eth_soc.h"
|
||||
#include "mdio.h"
|
||||
|
||||
static int mtk_mdio_reset(struct mii_bus *bus)
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mtk_phy_link_adjust(struct net_device *dev)
|
||||
{
|
||||
struct mtk_eth *eth = netdev_priv(dev);
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
spin_lock_irqsave(ð->phy->lock, flags);
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (eth->phy->phy_node[i]) {
|
||||
struct phy_device *phydev = eth->phy->phy[i];
|
||||
int status_change = 0;
|
||||
|
||||
if (phydev->link)
|
||||
if (eth->phy->duplex[i] != phydev->duplex ||
|
||||
eth->phy->speed[i] != phydev->speed)
|
||||
status_change = 1;
|
||||
|
||||
if (phydev->link != eth->link[i])
|
||||
status_change = 1;
|
||||
|
||||
switch (phydev->speed) {
|
||||
case SPEED_1000:
|
||||
case SPEED_100:
|
||||
case SPEED_10:
|
||||
eth->link[i] = phydev->link;
|
||||
eth->phy->duplex[i] = phydev->duplex;
|
||||
eth->phy->speed[i] = phydev->speed;
|
||||
|
||||
if (status_change &&
|
||||
eth->soc->mdio_adjust_link)
|
||||
eth->soc->mdio_adjust_link(eth, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int mtk_connect_phy_node(struct mtk_eth *eth, struct mtk_mac *mac,
|
||||
struct device_node *phy_node)
|
||||
{
|
||||
const __be32 *_port = NULL;
|
||||
struct phy_device *phydev;
|
||||
int phy_mode, port;
|
||||
|
||||
_port = of_get_property(phy_node, "reg", NULL);
|
||||
|
||||
if (!_port || (be32_to_cpu(*_port) >= 0x20)) {
|
||||
pr_err("%s: invalid port id\n", phy_node->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
port = be32_to_cpu(*_port);
|
||||
phy_mode = of_get_phy_mode(phy_node);
|
||||
if (phy_mode < 0) {
|
||||
dev_err(eth->dev, "incorrect phy-mode %d\n", phy_mode);
|
||||
eth->phy->phy_node[port] = NULL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
phydev = of_phy_connect(eth->netdev[mac->id], phy_node,
|
||||
mtk_phy_link_adjust, 0, phy_mode);
|
||||
if (IS_ERR(phydev)) {
|
||||
dev_err(eth->dev, "could not connect to PHY\n");
|
||||
eth->phy->phy_node[port] = NULL;
|
||||
return PTR_ERR(phydev);
|
||||
}
|
||||
|
||||
phydev->supported &= PHY_GBIT_FEATURES;
|
||||
phydev->advertising = phydev->supported;
|
||||
|
||||
dev_info(eth->dev,
|
||||
"connected port %d to PHY at %s [uid=%08x, driver=%s]\n",
|
||||
port, phydev_name(phydev), phydev->phy_id,
|
||||
phydev->drv->name);
|
||||
|
||||
eth->phy->phy[port] = phydev;
|
||||
eth->link[port] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void phy_init(struct mtk_eth *eth, struct mtk_mac *mac,
|
||||
struct phy_device *phy)
|
||||
{
|
||||
phy_attach(eth->netdev[mac->id], phydev_name(phy),
|
||||
PHY_INTERFACE_MODE_MII);
|
||||
|
||||
phy->autoneg = AUTONEG_ENABLE;
|
||||
phy->speed = 0;
|
||||
phy->duplex = 0;
|
||||
phy->supported &= PHY_BASIC_FEATURES;
|
||||
phy->advertising = phy->supported | ADVERTISED_Autoneg;
|
||||
|
||||
phy_start_aneg(phy);
|
||||
}
|
||||
|
||||
static int mtk_phy_connect(struct mtk_mac *mac)
|
||||
{
|
||||
struct mtk_eth *eth = mac->hw;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (eth->phy->phy_node[i]) {
|
||||
if (!mac->phy_dev) {
|
||||
mac->phy_dev = eth->phy->phy[i];
|
||||
mac->phy_flags = MTK_PHY_FLAG_PORT;
|
||||
}
|
||||
} else if (eth->mii_bus) {
|
||||
struct phy_device *phy;
|
||||
phy = mdiobus_get_phy(eth->mii_bus, i);
|
||||
if (phy) {
|
||||
phy_init(eth, mac, phy);
|
||||
if (!mac->phy_dev) {
|
||||
mac->phy_dev = phy;
|
||||
mac->phy_flags = MTK_PHY_FLAG_ATTACH;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mtk_phy_disconnect(struct mtk_mac *mac)
|
||||
{
|
||||
struct mtk_eth *eth = mac->hw;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
if (eth->phy->phy_fixed[i]) {
|
||||
spin_lock_irqsave(ð->phy->lock, flags);
|
||||
eth->link[i] = 0;
|
||||
if (eth->soc->mdio_adjust_link)
|
||||
eth->soc->mdio_adjust_link(eth, i);
|
||||
spin_unlock_irqrestore(ð->phy->lock, flags);
|
||||
} else if (eth->phy->phy[i]) {
|
||||
phy_disconnect(eth->phy->phy[i]);
|
||||
} else if (eth->mii_bus) {
|
||||
struct phy_device *phy = mdiobus_get_phy(eth->mii_bus, i);
|
||||
if (phy)
|
||||
phy_detach(phy);
|
||||
}
|
||||
}
|
||||
|
||||
static void mtk_phy_start(struct mtk_mac *mac)
|
||||
{
|
||||
struct mtk_eth *eth = mac->hw;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (eth->phy->phy_fixed[i]) {
|
||||
spin_lock_irqsave(ð->phy->lock, flags);
|
||||
eth->link[i] = 1;
|
||||
if (eth->soc->mdio_adjust_link)
|
||||
eth->soc->mdio_adjust_link(eth, i);
|
||||
spin_unlock_irqrestore(ð->phy->lock, flags);
|
||||
} else if (eth->phy->phy[i]) {
|
||||
phy_start(eth->phy->phy[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mtk_phy_stop(struct mtk_mac *mac)
|
||||
{
|
||||
struct mtk_eth *eth = mac->hw;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
if (eth->phy->phy_fixed[i]) {
|
||||
spin_lock_irqsave(ð->phy->lock, flags);
|
||||
eth->link[i] = 0;
|
||||
if (eth->soc->mdio_adjust_link)
|
||||
eth->soc->mdio_adjust_link(eth, i);
|
||||
spin_unlock_irqrestore(ð->phy->lock, flags);
|
||||
} else if (eth->phy->phy[i]) {
|
||||
phy_stop(eth->phy->phy[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static struct mtk_phy phy_ralink = {
|
||||
.connect = mtk_phy_connect,
|
||||
.disconnect = mtk_phy_disconnect,
|
||||
.start = mtk_phy_start,
|
||||
.stop = mtk_phy_stop,
|
||||
};
|
||||
|
||||
int mtk_mdio_init(struct mtk_eth *eth)
|
||||
{
|
||||
struct device_node *mii_np;
|
||||
int err;
|
||||
|
||||
if (!eth->soc->mdio_read || !eth->soc->mdio_write)
|
||||
return 0;
|
||||
|
||||
spin_lock_init(&phy_ralink.lock);
|
||||
eth->phy = &phy_ralink;
|
||||
|
||||
mii_np = of_get_child_by_name(eth->dev->of_node, "mdio-bus");
|
||||
if (!mii_np) {
|
||||
dev_err(eth->dev, "no %s child node found", "mdio-bus");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!of_device_is_available(mii_np)) {
|
||||
err = 0;
|
||||
goto err_put_node;
|
||||
}
|
||||
|
||||
eth->mii_bus = mdiobus_alloc();
|
||||
if (!eth->mii_bus) {
|
||||
err = -ENOMEM;
|
||||
goto err_put_node;
|
||||
}
|
||||
|
||||
eth->mii_bus->name = "mdio";
|
||||
eth->mii_bus->read = eth->soc->mdio_read;
|
||||
eth->mii_bus->write = eth->soc->mdio_write;
|
||||
eth->mii_bus->reset = mtk_mdio_reset;
|
||||
eth->mii_bus->priv = eth;
|
||||
eth->mii_bus->parent = eth->dev;
|
||||
|
||||
snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%s", mii_np->name);
|
||||
err = of_mdiobus_register(eth->mii_bus, mii_np);
|
||||
if (err)
|
||||
goto err_free_bus;
|
||||
|
||||
return 0;
|
||||
|
||||
err_free_bus:
|
||||
kfree(eth->mii_bus);
|
||||
err_put_node:
|
||||
of_node_put(mii_np);
|
||||
eth->mii_bus = NULL;
|
||||
return err;
|
||||
}
|
||||
|
||||
void mtk_mdio_cleanup(struct mtk_eth *eth)
|
||||
{
|
||||
if (!eth->mii_bus)
|
||||
return;
|
||||
|
||||
mdiobus_unregister(eth->mii_bus);
|
||||
of_node_put(eth->mii_bus->dev.of_node);
|
||||
kfree(eth->mii_bus);
|
||||
}
|
27
drivers/staging/mt7621-eth/mdio.h
Normal file
27
drivers/staging/mt7621-eth/mdio.h
Normal file
@ -0,0 +1,27 @@
|
||||
/* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License
|
||||
*
|
||||
* This program is distributed in the hope that 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.
|
||||
*
|
||||
* Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
|
||||
* Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
|
||||
* Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _RALINK_MDIO_H__
|
||||
#define _RALINK_MDIO_H__
|
||||
|
||||
#ifdef CONFIG_NET_MEDIATEK_MDIO
|
||||
int mtk_mdio_init(struct mtk_eth *eth);
|
||||
void mtk_mdio_cleanup(struct mtk_eth *eth);
|
||||
int mtk_connect_phy_node(struct mtk_eth *eth, struct mtk_mac *mac,
|
||||
struct device_node *phy_node);
|
||||
#else
|
||||
static inline int mtk_mdio_init(struct mtk_eth *eth) { return 0; }
|
||||
static inline void mtk_mdio_cleanup(struct mtk_eth *eth) {}
|
||||
#endif
|
||||
#endif
|
2178
drivers/staging/mt7621-eth/mtk_eth_soc.c
Normal file
2178
drivers/staging/mt7621-eth/mtk_eth_soc.c
Normal file
File diff suppressed because it is too large
Load Diff
721
drivers/staging/mt7621-eth/mtk_eth_soc.h
Normal file
721
drivers/staging/mt7621-eth/mtk_eth_soc.h
Normal file
@ -0,0 +1,721 @@
|
||||
/* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License
|
||||
*
|
||||
* This program is distributed in the hope that 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.
|
||||
*
|
||||
* Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
|
||||
* Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
|
||||
* Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef MTK_ETH_H
|
||||
#define MTK_ETH_H
|
||||
|
||||
#include <linux/mii.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/phy.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/atomic.h>
|
||||
|
||||
/* these registers have different offsets depending on the SoC. we use a lookup
|
||||
* table for these
|
||||
*/
|
||||
enum mtk_reg {
|
||||
MTK_REG_PDMA_GLO_CFG = 0,
|
||||
MTK_REG_PDMA_RST_CFG,
|
||||
MTK_REG_DLY_INT_CFG,
|
||||
MTK_REG_TX_BASE_PTR0,
|
||||
MTK_REG_TX_MAX_CNT0,
|
||||
MTK_REG_TX_CTX_IDX0,
|
||||
MTK_REG_TX_DTX_IDX0,
|
||||
MTK_REG_RX_BASE_PTR0,
|
||||
MTK_REG_RX_MAX_CNT0,
|
||||
MTK_REG_RX_CALC_IDX0,
|
||||
MTK_REG_RX_DRX_IDX0,
|
||||
MTK_REG_MTK_INT_ENABLE,
|
||||
MTK_REG_MTK_INT_STATUS,
|
||||
MTK_REG_MTK_DMA_VID_BASE,
|
||||
MTK_REG_MTK_COUNTER_BASE,
|
||||
MTK_REG_MTK_RST_GL,
|
||||
MTK_REG_MTK_INT_STATUS2,
|
||||
MTK_REG_COUNT
|
||||
};
|
||||
|
||||
/* delayed interrupt bits */
|
||||
#define MTK_DELAY_EN_INT 0x80
|
||||
#define MTK_DELAY_MAX_INT 0x04
|
||||
#define MTK_DELAY_MAX_TOUT 0x04
|
||||
#define MTK_DELAY_TIME 20
|
||||
#define MTK_DELAY_CHAN (((MTK_DELAY_EN_INT | MTK_DELAY_MAX_INT) << 8) \
|
||||
| MTK_DELAY_MAX_TOUT)
|
||||
#define MTK_DELAY_INIT ((MTK_DELAY_CHAN << 16) | MTK_DELAY_CHAN)
|
||||
#define MTK_PSE_FQFC_CFG_INIT 0x80504000
|
||||
#define MTK_PSE_FQFC_CFG_256Q 0xff908000
|
||||
|
||||
/* interrupt bits */
|
||||
#define MTK_CNT_PPE_AF BIT(31)
|
||||
#define MTK_CNT_GDM_AF BIT(29)
|
||||
#define MTK_PSE_P2_FC BIT(26)
|
||||
#define MTK_PSE_BUF_DROP BIT(24)
|
||||
#define MTK_GDM_OTHER_DROP BIT(23)
|
||||
#define MTK_PSE_P1_FC BIT(22)
|
||||
#define MTK_PSE_P0_FC BIT(21)
|
||||
#define MTK_PSE_FQ_EMPTY BIT(20)
|
||||
#define MTK_GE1_STA_CHG BIT(18)
|
||||
#define MTK_TX_COHERENT BIT(17)
|
||||
#define MTK_RX_COHERENT BIT(16)
|
||||
#define MTK_TX_DONE_INT3 BIT(11)
|
||||
#define MTK_TX_DONE_INT2 BIT(10)
|
||||
#define MTK_TX_DONE_INT1 BIT(9)
|
||||
#define MTK_TX_DONE_INT0 BIT(8)
|
||||
#define MTK_RX_DONE_INT0 BIT(2)
|
||||
#define MTK_TX_DLY_INT BIT(1)
|
||||
#define MTK_RX_DLY_INT BIT(0)
|
||||
|
||||
#define MTK_RX_DONE_INT MTK_RX_DONE_INT0
|
||||
#define MTK_TX_DONE_INT (MTK_TX_DONE_INT0 | MTK_TX_DONE_INT1 | \
|
||||
MTK_TX_DONE_INT2 | MTK_TX_DONE_INT3)
|
||||
|
||||
#define RT5350_RX_DLY_INT BIT(30)
|
||||
#define RT5350_TX_DLY_INT BIT(28)
|
||||
#define RT5350_RX_DONE_INT1 BIT(17)
|
||||
#define RT5350_RX_DONE_INT0 BIT(16)
|
||||
#define RT5350_TX_DONE_INT3 BIT(3)
|
||||
#define RT5350_TX_DONE_INT2 BIT(2)
|
||||
#define RT5350_TX_DONE_INT1 BIT(1)
|
||||
#define RT5350_TX_DONE_INT0 BIT(0)
|
||||
|
||||
#define RT5350_RX_DONE_INT (RT5350_RX_DONE_INT0 | RT5350_RX_DONE_INT1)
|
||||
#define RT5350_TX_DONE_INT (RT5350_TX_DONE_INT0 | RT5350_TX_DONE_INT1 | \
|
||||
RT5350_TX_DONE_INT2 | RT5350_TX_DONE_INT3)
|
||||
|
||||
/* registers */
|
||||
#define MTK_GDMA_OFFSET 0x0020
|
||||
#define MTK_PSE_OFFSET 0x0040
|
||||
#define MTK_GDMA2_OFFSET 0x0060
|
||||
#define MTK_CDMA_OFFSET 0x0080
|
||||
#define MTK_DMA_VID0 0x00a8
|
||||
#define MTK_PDMA_OFFSET 0x0100
|
||||
#define MTK_PPE_OFFSET 0x0200
|
||||
#define MTK_CMTABLE_OFFSET 0x0400
|
||||
#define MTK_POLICYTABLE_OFFSET 0x1000
|
||||
|
||||
#define MT7621_GDMA_OFFSET 0x0500
|
||||
#define MT7620_GDMA_OFFSET 0x0600
|
||||
|
||||
#define RT5350_PDMA_OFFSET 0x0800
|
||||
#define RT5350_SDM_OFFSET 0x0c00
|
||||
|
||||
#define MTK_MDIO_ACCESS 0x00
|
||||
#define MTK_MDIO_CFG 0x04
|
||||
#define MTK_GLO_CFG 0x08
|
||||
#define MTK_RST_GL 0x0C
|
||||
#define MTK_INT_STATUS 0x10
|
||||
#define MTK_INT_ENABLE 0x14
|
||||
#define MTK_MDIO_CFG2 0x18
|
||||
#define MTK_FOC_TS_T 0x1C
|
||||
|
||||
#define MTK_GDMA1_FWD_CFG (MTK_GDMA_OFFSET + 0x00)
|
||||
#define MTK_GDMA1_SCH_CFG (MTK_GDMA_OFFSET + 0x04)
|
||||
#define MTK_GDMA1_SHPR_CFG (MTK_GDMA_OFFSET + 0x08)
|
||||
#define MTK_GDMA1_MAC_ADRL (MTK_GDMA_OFFSET + 0x0C)
|
||||
#define MTK_GDMA1_MAC_ADRH (MTK_GDMA_OFFSET + 0x10)
|
||||
|
||||
#define MTK_GDMA2_FWD_CFG (MTK_GDMA2_OFFSET + 0x00)
|
||||
#define MTK_GDMA2_SCH_CFG (MTK_GDMA2_OFFSET + 0x04)
|
||||
#define MTK_GDMA2_SHPR_CFG (MTK_GDMA2_OFFSET + 0x08)
|
||||
#define MTK_GDMA2_MAC_ADRL (MTK_GDMA2_OFFSET + 0x0C)
|
||||
#define MTK_GDMA2_MAC_ADRH (MTK_GDMA2_OFFSET + 0x10)
|
||||
|
||||
#define MTK_PSE_FQ_CFG (MTK_PSE_OFFSET + 0x00)
|
||||
#define MTK_CDMA_FC_CFG (MTK_PSE_OFFSET + 0x04)
|
||||
#define MTK_GDMA1_FC_CFG (MTK_PSE_OFFSET + 0x08)
|
||||
#define MTK_GDMA2_FC_CFG (MTK_PSE_OFFSET + 0x0C)
|
||||
|
||||
#define MTK_CDMA_CSG_CFG (MTK_CDMA_OFFSET + 0x00)
|
||||
#define MTK_CDMA_SCH_CFG (MTK_CDMA_OFFSET + 0x04)
|
||||
|
||||
#define MT7621_GDMA_FWD_CFG(x) (MT7621_GDMA_OFFSET + (x * 0x1000))
|
||||
|
||||
/* FIXME this might be different for different SOCs */
|
||||
#define MT7620_GDMA1_FWD_CFG (MT7621_GDMA_OFFSET + 0x00)
|
||||
|
||||
#define RT5350_TX_BASE_PTR0 (RT5350_PDMA_OFFSET + 0x00)
|
||||
#define RT5350_TX_MAX_CNT0 (RT5350_PDMA_OFFSET + 0x04)
|
||||
#define RT5350_TX_CTX_IDX0 (RT5350_PDMA_OFFSET + 0x08)
|
||||
#define RT5350_TX_DTX_IDX0 (RT5350_PDMA_OFFSET + 0x0C)
|
||||
#define RT5350_TX_BASE_PTR1 (RT5350_PDMA_OFFSET + 0x10)
|
||||
#define RT5350_TX_MAX_CNT1 (RT5350_PDMA_OFFSET + 0x14)
|
||||
#define RT5350_TX_CTX_IDX1 (RT5350_PDMA_OFFSET + 0x18)
|
||||
#define RT5350_TX_DTX_IDX1 (RT5350_PDMA_OFFSET + 0x1C)
|
||||
#define RT5350_TX_BASE_PTR2 (RT5350_PDMA_OFFSET + 0x20)
|
||||
#define RT5350_TX_MAX_CNT2 (RT5350_PDMA_OFFSET + 0x24)
|
||||
#define RT5350_TX_CTX_IDX2 (RT5350_PDMA_OFFSET + 0x28)
|
||||
#define RT5350_TX_DTX_IDX2 (RT5350_PDMA_OFFSET + 0x2C)
|
||||
#define RT5350_TX_BASE_PTR3 (RT5350_PDMA_OFFSET + 0x30)
|
||||
#define RT5350_TX_MAX_CNT3 (RT5350_PDMA_OFFSET + 0x34)
|
||||
#define RT5350_TX_CTX_IDX3 (RT5350_PDMA_OFFSET + 0x38)
|
||||
#define RT5350_TX_DTX_IDX3 (RT5350_PDMA_OFFSET + 0x3C)
|
||||
#define RT5350_RX_BASE_PTR0 (RT5350_PDMA_OFFSET + 0x100)
|
||||
#define RT5350_RX_MAX_CNT0 (RT5350_PDMA_OFFSET + 0x104)
|
||||
#define RT5350_RX_CALC_IDX0 (RT5350_PDMA_OFFSET + 0x108)
|
||||
#define RT5350_RX_DRX_IDX0 (RT5350_PDMA_OFFSET + 0x10C)
|
||||
#define RT5350_RX_BASE_PTR1 (RT5350_PDMA_OFFSET + 0x110)
|
||||
#define RT5350_RX_MAX_CNT1 (RT5350_PDMA_OFFSET + 0x114)
|
||||
#define RT5350_RX_CALC_IDX1 (RT5350_PDMA_OFFSET + 0x118)
|
||||
#define RT5350_RX_DRX_IDX1 (RT5350_PDMA_OFFSET + 0x11C)
|
||||
#define RT5350_PDMA_GLO_CFG (RT5350_PDMA_OFFSET + 0x204)
|
||||
#define RT5350_PDMA_RST_CFG (RT5350_PDMA_OFFSET + 0x208)
|
||||
#define RT5350_DLY_INT_CFG (RT5350_PDMA_OFFSET + 0x20c)
|
||||
#define RT5350_MTK_INT_STATUS (RT5350_PDMA_OFFSET + 0x220)
|
||||
#define RT5350_MTK_INT_ENABLE (RT5350_PDMA_OFFSET + 0x228)
|
||||
#define RT5350_PDMA_SCH_CFG (RT5350_PDMA_OFFSET + 0x280)
|
||||
|
||||
#define MTK_PDMA_GLO_CFG (MTK_PDMA_OFFSET + 0x00)
|
||||
#define MTK_PDMA_RST_CFG (MTK_PDMA_OFFSET + 0x04)
|
||||
#define MTK_PDMA_SCH_CFG (MTK_PDMA_OFFSET + 0x08)
|
||||
#define MTK_DLY_INT_CFG (MTK_PDMA_OFFSET + 0x0C)
|
||||
#define MTK_TX_BASE_PTR0 (MTK_PDMA_OFFSET + 0x10)
|
||||
#define MTK_TX_MAX_CNT0 (MTK_PDMA_OFFSET + 0x14)
|
||||
#define MTK_TX_CTX_IDX0 (MTK_PDMA_OFFSET + 0x18)
|
||||
#define MTK_TX_DTX_IDX0 (MTK_PDMA_OFFSET + 0x1C)
|
||||
#define MTK_TX_BASE_PTR1 (MTK_PDMA_OFFSET + 0x20)
|
||||
#define MTK_TX_MAX_CNT1 (MTK_PDMA_OFFSET + 0x24)
|
||||
#define MTK_TX_CTX_IDX1 (MTK_PDMA_OFFSET + 0x28)
|
||||
#define MTK_TX_DTX_IDX1 (MTK_PDMA_OFFSET + 0x2C)
|
||||
#define MTK_RX_BASE_PTR0 (MTK_PDMA_OFFSET + 0x30)
|
||||
#define MTK_RX_MAX_CNT0 (MTK_PDMA_OFFSET + 0x34)
|
||||
#define MTK_RX_CALC_IDX0 (MTK_PDMA_OFFSET + 0x38)
|
||||
#define MTK_RX_DRX_IDX0 (MTK_PDMA_OFFSET + 0x3C)
|
||||
#define MTK_TX_BASE_PTR2 (MTK_PDMA_OFFSET + 0x40)
|
||||
#define MTK_TX_MAX_CNT2 (MTK_PDMA_OFFSET + 0x44)
|
||||
#define MTK_TX_CTX_IDX2 (MTK_PDMA_OFFSET + 0x48)
|
||||
#define MTK_TX_DTX_IDX2 (MTK_PDMA_OFFSET + 0x4C)
|
||||
#define MTK_TX_BASE_PTR3 (MTK_PDMA_OFFSET + 0x50)
|
||||
#define MTK_TX_MAX_CNT3 (MTK_PDMA_OFFSET + 0x54)
|
||||
#define MTK_TX_CTX_IDX3 (MTK_PDMA_OFFSET + 0x58)
|
||||
#define MTK_TX_DTX_IDX3 (MTK_PDMA_OFFSET + 0x5C)
|
||||
#define MTK_RX_BASE_PTR1 (MTK_PDMA_OFFSET + 0x60)
|
||||
#define MTK_RX_MAX_CNT1 (MTK_PDMA_OFFSET + 0x64)
|
||||
#define MTK_RX_CALC_IDX1 (MTK_PDMA_OFFSET + 0x68)
|
||||
#define MTK_RX_DRX_IDX1 (MTK_PDMA_OFFSET + 0x6C)
|
||||
|
||||
/* Switch DMA configuration */
|
||||
#define RT5350_SDM_CFG (RT5350_SDM_OFFSET + 0x00)
|
||||
#define RT5350_SDM_RRING (RT5350_SDM_OFFSET + 0x04)
|
||||
#define RT5350_SDM_TRING (RT5350_SDM_OFFSET + 0x08)
|
||||
#define RT5350_SDM_MAC_ADRL (RT5350_SDM_OFFSET + 0x0C)
|
||||
#define RT5350_SDM_MAC_ADRH (RT5350_SDM_OFFSET + 0x10)
|
||||
#define RT5350_SDM_TPCNT (RT5350_SDM_OFFSET + 0x100)
|
||||
#define RT5350_SDM_TBCNT (RT5350_SDM_OFFSET + 0x104)
|
||||
#define RT5350_SDM_RPCNT (RT5350_SDM_OFFSET + 0x108)
|
||||
#define RT5350_SDM_RBCNT (RT5350_SDM_OFFSET + 0x10C)
|
||||
#define RT5350_SDM_CS_ERR (RT5350_SDM_OFFSET + 0x110)
|
||||
|
||||
#define RT5350_SDM_ICS_EN BIT(16)
|
||||
#define RT5350_SDM_TCS_EN BIT(17)
|
||||
#define RT5350_SDM_UCS_EN BIT(18)
|
||||
|
||||
/* QDMA registers */
|
||||
#define MTK_QTX_CFG(x) (0x1800 + (x * 0x10))
|
||||
#define MTK_QTX_SCH(x) (0x1804 + (x * 0x10))
|
||||
#define MTK_QRX_BASE_PTR0 0x1900
|
||||
#define MTK_QRX_MAX_CNT0 0x1904
|
||||
#define MTK_QRX_CRX_IDX0 0x1908
|
||||
#define MTK_QRX_DRX_IDX0 0x190C
|
||||
#define MTK_QDMA_GLO_CFG 0x1A04
|
||||
#define MTK_QDMA_RST_IDX 0x1A08
|
||||
#define MTK_QDMA_DELAY_INT 0x1A0C
|
||||
#define MTK_QDMA_FC_THRES 0x1A10
|
||||
#define MTK_QMTK_INT_STATUS 0x1A18
|
||||
#define MTK_QMTK_INT_ENABLE 0x1A1C
|
||||
#define MTK_QDMA_HRED2 0x1A44
|
||||
|
||||
#define MTK_QTX_CTX_PTR 0x1B00
|
||||
#define MTK_QTX_DTX_PTR 0x1B04
|
||||
|
||||
#define MTK_QTX_CRX_PTR 0x1B10
|
||||
#define MTK_QTX_DRX_PTR 0x1B14
|
||||
|
||||
#define MTK_QDMA_FQ_HEAD 0x1B20
|
||||
#define MTK_QDMA_FQ_TAIL 0x1B24
|
||||
#define MTK_QDMA_FQ_CNT 0x1B28
|
||||
#define MTK_QDMA_FQ_BLEN 0x1B2C
|
||||
|
||||
#define QDMA_PAGE_SIZE 2048
|
||||
#define QDMA_TX_OWNER_CPU BIT(31)
|
||||
#define QDMA_TX_SWC BIT(14)
|
||||
#define TX_QDMA_SDL(_x) (((_x) & 0x3fff) << 16)
|
||||
#define QDMA_RES_THRES 4
|
||||
|
||||
/* MDIO_CFG register bits */
|
||||
#define MTK_MDIO_CFG_AUTO_POLL_EN BIT(29)
|
||||
#define MTK_MDIO_CFG_GP1_BP_EN BIT(16)
|
||||
#define MTK_MDIO_CFG_GP1_FRC_EN BIT(15)
|
||||
#define MTK_MDIO_CFG_GP1_SPEED_10 (0 << 13)
|
||||
#define MTK_MDIO_CFG_GP1_SPEED_100 (1 << 13)
|
||||
#define MTK_MDIO_CFG_GP1_SPEED_1000 (2 << 13)
|
||||
#define MTK_MDIO_CFG_GP1_DUPLEX BIT(12)
|
||||
#define MTK_MDIO_CFG_GP1_FC_TX BIT(11)
|
||||
#define MTK_MDIO_CFG_GP1_FC_RX BIT(10)
|
||||
#define MTK_MDIO_CFG_GP1_LNK_DWN BIT(9)
|
||||
#define MTK_MDIO_CFG_GP1_AN_FAIL BIT(8)
|
||||
#define MTK_MDIO_CFG_MDC_CLK_DIV_1 (0 << 6)
|
||||
#define MTK_MDIO_CFG_MDC_CLK_DIV_2 (1 << 6)
|
||||
#define MTK_MDIO_CFG_MDC_CLK_DIV_4 (2 << 6)
|
||||
#define MTK_MDIO_CFG_MDC_CLK_DIV_8 (3 << 6)
|
||||
#define MTK_MDIO_CFG_TURBO_MII_FREQ BIT(5)
|
||||
#define MTK_MDIO_CFG_TURBO_MII_MODE BIT(4)
|
||||
#define MTK_MDIO_CFG_RX_CLK_SKEW_0 (0 << 2)
|
||||
#define MTK_MDIO_CFG_RX_CLK_SKEW_200 (1 << 2)
|
||||
#define MTK_MDIO_CFG_RX_CLK_SKEW_400 (2 << 2)
|
||||
#define MTK_MDIO_CFG_RX_CLK_SKEW_INV (3 << 2)
|
||||
#define MTK_MDIO_CFG_TX_CLK_SKEW_0 0
|
||||
#define MTK_MDIO_CFG_TX_CLK_SKEW_200 1
|
||||
#define MTK_MDIO_CFG_TX_CLK_SKEW_400 2
|
||||
#define MTK_MDIO_CFG_TX_CLK_SKEW_INV 3
|
||||
|
||||
/* uni-cast port */
|
||||
#define MTK_GDM1_JMB_LEN_MASK 0xf
|
||||
#define MTK_GDM1_JMB_LEN_SHIFT 28
|
||||
#define MTK_GDM1_ICS_EN BIT(22)
|
||||
#define MTK_GDM1_TCS_EN BIT(21)
|
||||
#define MTK_GDM1_UCS_EN BIT(20)
|
||||
#define MTK_GDM1_JMB_EN BIT(19)
|
||||
#define MTK_GDM1_STRPCRC BIT(16)
|
||||
#define MTK_GDM1_UFRC_P_CPU (0 << 12)
|
||||
#define MTK_GDM1_UFRC_P_GDMA1 (1 << 12)
|
||||
#define MTK_GDM1_UFRC_P_PPE (6 << 12)
|
||||
|
||||
/* checksums */
|
||||
#define MTK_ICS_GEN_EN BIT(2)
|
||||
#define MTK_UCS_GEN_EN BIT(1)
|
||||
#define MTK_TCS_GEN_EN BIT(0)
|
||||
|
||||
/* dma mode */
|
||||
#define MTK_PDMA BIT(0)
|
||||
#define MTK_QDMA BIT(1)
|
||||
#define MTK_PDMA_RX_QDMA_TX (MTK_PDMA | MTK_QDMA)
|
||||
|
||||
/* dma ring */
|
||||
#define MTK_PST_DRX_IDX0 BIT(16)
|
||||
#define MTK_PST_DTX_IDX3 BIT(3)
|
||||
#define MTK_PST_DTX_IDX2 BIT(2)
|
||||
#define MTK_PST_DTX_IDX1 BIT(1)
|
||||
#define MTK_PST_DTX_IDX0 BIT(0)
|
||||
|
||||
#define MTK_RX_2B_OFFSET BIT(31)
|
||||
#define MTK_TX_WB_DDONE BIT(6)
|
||||
#define MTK_RX_DMA_BUSY BIT(3)
|
||||
#define MTK_TX_DMA_BUSY BIT(1)
|
||||
#define MTK_RX_DMA_EN BIT(2)
|
||||
#define MTK_TX_DMA_EN BIT(0)
|
||||
|
||||
#define MTK_PDMA_SIZE_4DWORDS (0 << 4)
|
||||
#define MTK_PDMA_SIZE_8DWORDS (1 << 4)
|
||||
#define MTK_PDMA_SIZE_16DWORDS (2 << 4)
|
||||
|
||||
#define MTK_US_CYC_CNT_MASK 0xff
|
||||
#define MTK_US_CYC_CNT_SHIFT 0x8
|
||||
#define MTK_US_CYC_CNT_DIVISOR 1000000
|
||||
|
||||
/* PDMA descriptor rxd2 */
|
||||
#define RX_DMA_DONE BIT(31)
|
||||
#define RX_DMA_LSO BIT(30)
|
||||
#define RX_DMA_PLEN0(_x) (((_x) & 0x3fff) << 16)
|
||||
#define RX_DMA_GET_PLEN0(_x) (((_x) >> 16) & 0x3fff)
|
||||
#define RX_DMA_TAG BIT(15)
|
||||
|
||||
/* PDMA descriptor rxd3 */
|
||||
#define RX_DMA_TPID(_x) (((_x) >> 16) & 0xffff)
|
||||
#define RX_DMA_VID(_x) ((_x) & 0xfff)
|
||||
|
||||
/* PDMA descriptor rxd4 */
|
||||
#define RX_DMA_L4VALID BIT(30)
|
||||
#define RX_DMA_FPORT_SHIFT 19
|
||||
#define RX_DMA_FPORT_MASK 0x7
|
||||
|
||||
struct mtk_rx_dma {
|
||||
unsigned int rxd1;
|
||||
unsigned int rxd2;
|
||||
unsigned int rxd3;
|
||||
unsigned int rxd4;
|
||||
} __packed __aligned(4);
|
||||
|
||||
/* PDMA tx descriptor bits */
|
||||
#define TX_DMA_BUF_LEN 0x3fff
|
||||
#define TX_DMA_PLEN0_MASK (TX_DMA_BUF_LEN << 16)
|
||||
#define TX_DMA_PLEN0(_x) (((_x) & TX_DMA_BUF_LEN) << 16)
|
||||
#define TX_DMA_PLEN1(_x) ((_x) & TX_DMA_BUF_LEN)
|
||||
#define TX_DMA_GET_PLEN0(_x) (((_x) >> 16) & TX_DMA_BUF_LEN)
|
||||
#define TX_DMA_GET_PLEN1(_x) ((_x) & TX_DMA_BUF_LEN)
|
||||
#define TX_DMA_LS1 BIT(14)
|
||||
#define TX_DMA_LS0 BIT(30)
|
||||
#define TX_DMA_DONE BIT(31)
|
||||
#define TX_DMA_FPORT_SHIFT 25
|
||||
#define TX_DMA_FPORT_MASK 0x7
|
||||
#define TX_DMA_INS_VLAN_MT7621 BIT(16)
|
||||
#define TX_DMA_INS_VLAN BIT(7)
|
||||
#define TX_DMA_INS_PPPOE BIT(12)
|
||||
#define TX_DMA_TAG BIT(15)
|
||||
#define TX_DMA_TAG_MASK BIT(15)
|
||||
#define TX_DMA_QN(_x) ((_x) << 16)
|
||||
#define TX_DMA_PN(_x) ((_x) << 24)
|
||||
#define TX_DMA_QN_MASK TX_DMA_QN(0x7)
|
||||
#define TX_DMA_PN_MASK TX_DMA_PN(0x7)
|
||||
#define TX_DMA_UDF BIT(20)
|
||||
#define TX_DMA_CHKSUM (0x7 << 29)
|
||||
#define TX_DMA_TSO BIT(28)
|
||||
#define TX_DMA_DESP4_DEF (TX_DMA_QN(3) | TX_DMA_PN(1))
|
||||
|
||||
/* frame engine counters */
|
||||
#define MTK_PPE_AC_BCNT0 (MTK_CMTABLE_OFFSET + 0x00)
|
||||
#define MTK_GDMA1_TX_GBCNT (MTK_CMTABLE_OFFSET + 0x300)
|
||||
#define MTK_GDMA2_TX_GBCNT (MTK_GDMA1_TX_GBCNT + 0x40)
|
||||
|
||||
/* phy device flags */
|
||||
#define MTK_PHY_FLAG_PORT BIT(0)
|
||||
#define MTK_PHY_FLAG_ATTACH BIT(1)
|
||||
|
||||
struct mtk_tx_dma {
|
||||
unsigned int txd1;
|
||||
unsigned int txd2;
|
||||
unsigned int txd3;
|
||||
unsigned int txd4;
|
||||
} __packed __aligned(4);
|
||||
|
||||
struct mtk_eth;
|
||||
struct mtk_mac;
|
||||
|
||||
/* manage the attached phys */
|
||||
struct mtk_phy {
|
||||
spinlock_t lock;
|
||||
|
||||
struct phy_device *phy[8];
|
||||
struct device_node *phy_node[8];
|
||||
const __be32 *phy_fixed[8];
|
||||
int duplex[8];
|
||||
int speed[8];
|
||||
int tx_fc[8];
|
||||
int rx_fc[8];
|
||||
int (*connect)(struct mtk_mac *mac);
|
||||
void (*disconnect)(struct mtk_mac *mac);
|
||||
void (*start)(struct mtk_mac *mac);
|
||||
void (*stop)(struct mtk_mac *mac);
|
||||
};
|
||||
|
||||
/* struct mtk_soc_data - the structure that holds the SoC specific data
|
||||
* @reg_table: Some of the legacy registers changed their location
|
||||
* over time. Their offsets are stored in this table
|
||||
*
|
||||
* @init_data: Some features depend on the silicon revision. This
|
||||
* callback allows runtime modification of the content of
|
||||
* this struct
|
||||
* @reset_fe: This callback is used to trigger the reset of the frame
|
||||
* engine
|
||||
* @set_mac: This callback is used to set the unicast mac address
|
||||
* filter
|
||||
* @fwd_config: This callback is used to setup the forward config
|
||||
* register of the MAC
|
||||
* @switch_init: This callback is used to bring up the switch core
|
||||
* @port_init: Some SoCs have ports that can be router to a switch port
|
||||
* or an external PHY. This callback is used to setup these
|
||||
* ports.
|
||||
* @has_carrier: This callback allows driver to check if there is a cable
|
||||
* attached.
|
||||
* @mdio_init: This callbck is used to setup the MDIO bus if one is
|
||||
* present
|
||||
* @mdio_cleanup: This callback is used to cleanup the MDIO state.
|
||||
* @mdio_write: This callback is used to write data to the MDIO bus.
|
||||
* @mdio_read: This callback is used to write data to the MDIO bus.
|
||||
* @mdio_adjust_link: This callback is used to apply the PHY settings.
|
||||
* @piac_offset: the PIAC register has a different different base offset
|
||||
* @hw_features: feature set depends on the SoC type
|
||||
* @dma_ring_size: allow GBit SoCs to set bigger rings than FE SoCs
|
||||
* @napi_weight: allow GBit SoCs to set bigger napi weight than FE SoCs
|
||||
* @dma_type: SoCs is PDMA, QDMA or a mix of the 2
|
||||
* @pdma_glo_cfg: the default DMA configuration
|
||||
* @rx_int: the TX interrupt bits used by the SoC
|
||||
* @tx_int: the TX interrupt bits used by the SoC
|
||||
* @status_int: the Status interrupt bits used by the SoC
|
||||
* @checksum_bit: the bits used to turn on HW checksumming
|
||||
* @txd4: default value of the TXD4 descriptor
|
||||
* @mac_count: the number of MACs that the SoC has
|
||||
* @new_stats: there is a old and new way to read hardware stats
|
||||
* registers
|
||||
* @jumbo_frame: does the SoC support jumbo frames ?
|
||||
* @rx_2b_offset: tell the rx dma to offset the data by 2 bytes
|
||||
* @rx_sg_dma: scatter gather support
|
||||
* @padding_64b enable 64 bit padding
|
||||
* @padding_bug: rt2880 has a padding bug
|
||||
* @has_switch: does the SoC have a built-in switch
|
||||
*
|
||||
* Although all of the supported SoCs share the same basic functionality, there
|
||||
* are several SoC specific functions and features that we need to support. This
|
||||
* struct holds the SoC specific data so that the common core can figure out
|
||||
* how to setup and use these differences.
|
||||
*/
|
||||
struct mtk_soc_data {
|
||||
const u16 *reg_table;
|
||||
|
||||
void (*init_data)(struct mtk_soc_data *data, struct net_device *netdev);
|
||||
void (*reset_fe)(struct mtk_eth *eth);
|
||||
void (*set_mac)(struct mtk_mac *mac, unsigned char *macaddr);
|
||||
int (*fwd_config)(struct mtk_eth *eth);
|
||||
int (*switch_init)(struct mtk_eth *eth);
|
||||
void (*port_init)(struct mtk_eth *eth, struct mtk_mac *mac,
|
||||
struct device_node *port);
|
||||
int (*has_carrier)(struct mtk_eth *eth);
|
||||
int (*mdio_init)(struct mtk_eth *eth);
|
||||
void (*mdio_cleanup)(struct mtk_eth *eth);
|
||||
int (*mdio_write)(struct mii_bus *bus, int phy_addr, int phy_reg,
|
||||
u16 val);
|
||||
int (*mdio_read)(struct mii_bus *bus, int phy_addr, int phy_reg);
|
||||
void (*mdio_adjust_link)(struct mtk_eth *eth, int port);
|
||||
u32 piac_offset;
|
||||
netdev_features_t hw_features;
|
||||
u32 dma_ring_size;
|
||||
u32 napi_weight;
|
||||
u32 dma_type;
|
||||
u32 pdma_glo_cfg;
|
||||
u32 rx_int;
|
||||
u32 tx_int;
|
||||
u32 status_int;
|
||||
u32 checksum_bit;
|
||||
u32 txd4;
|
||||
u32 mac_count;
|
||||
|
||||
u32 new_stats:1;
|
||||
u32 jumbo_frame:1;
|
||||
u32 rx_2b_offset:1;
|
||||
u32 rx_sg_dma:1;
|
||||
u32 padding_64b:1;
|
||||
u32 padding_bug:1;
|
||||
u32 has_switch:1;
|
||||
};
|
||||
|
||||
/* ugly macro hack to make sure hw_stats and ethtool strings are consistent */
|
||||
#define MTK_STAT_OFFSET 0x40
|
||||
#define MTK_STAT_REG_DECLARE \
|
||||
_FE(tx_bytes) \
|
||||
_FE(tx_packets) \
|
||||
_FE(tx_skip) \
|
||||
_FE(tx_collisions) \
|
||||
_FE(rx_bytes) \
|
||||
_FE(rx_packets) \
|
||||
_FE(rx_overflow) \
|
||||
_FE(rx_fcs_errors) \
|
||||
_FE(rx_short_errors) \
|
||||
_FE(rx_long_errors) \
|
||||
_FE(rx_checksum_errors) \
|
||||
_FE(rx_flow_control_packets)
|
||||
|
||||
/* struct mtk_hw_stats - the structure that holds the traffic statistics.
|
||||
* @stats_lock: make sure that stats operations are atomic
|
||||
* @reg_offset: the status register offset of the SoC
|
||||
* @syncp: the refcount
|
||||
*
|
||||
* All of the supported SoCs have hardware counters for traffic statstics.
|
||||
* Whenever the status IRQ triggers we can read the latest stats from these
|
||||
* counters and store them in this struct.
|
||||
*/
|
||||
struct mtk_hw_stats {
|
||||
spinlock_t stats_lock;
|
||||
u32 reg_offset;
|
||||
struct u64_stats_sync syncp;
|
||||
|
||||
#define _FE(x) u64 x;
|
||||
MTK_STAT_REG_DECLARE
|
||||
#undef _FE
|
||||
};
|
||||
|
||||
/* PDMA descriptor can point at 1-2 segments. This enum allows us to track how
|
||||
* memory was allocated so that it can be freed properly
|
||||
*/
|
||||
enum mtk_tx_flags {
|
||||
MTK_TX_FLAGS_SINGLE0 = 0x01,
|
||||
MTK_TX_FLAGS_PAGE0 = 0x02,
|
||||
MTK_TX_FLAGS_PAGE1 = 0x04,
|
||||
};
|
||||
|
||||
/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at
|
||||
* by the TX descriptor s
|
||||
* @skb: The SKB pointer of the packet being sent
|
||||
* @dma_addr0: The base addr of the first segment
|
||||
* @dma_len0: The length of the first segment
|
||||
* @dma_addr1: The base addr of the second segment
|
||||
* @dma_len1: The length of the second segment
|
||||
*/
|
||||
struct mtk_tx_buf {
|
||||
struct sk_buff *skb;
|
||||
u32 flags;
|
||||
DEFINE_DMA_UNMAP_ADDR(dma_addr0);
|
||||
DEFINE_DMA_UNMAP_LEN(dma_len0);
|
||||
DEFINE_DMA_UNMAP_ADDR(dma_addr1);
|
||||
DEFINE_DMA_UNMAP_LEN(dma_len1);
|
||||
};
|
||||
|
||||
/* struct mtk_tx_ring - This struct holds info describing a TX ring
|
||||
* @tx_dma: The descriptor ring
|
||||
* @tx_buf: The memory pointed at by the ring
|
||||
* @tx_phys: The physical addr of tx_buf
|
||||
* @tx_next_free: Pointer to the next free descriptor
|
||||
* @tx_last_free: Pointer to the last free descriptor
|
||||
* @tx_thresh: The threshold of minimum amount of free descriptors
|
||||
* @tx_map: Callback to map a new packet into the ring
|
||||
* @tx_poll: Callback for the housekeeping function
|
||||
* @tx_clean: Callback for the cleanup function
|
||||
* @tx_ring_size: How many descriptors are in the ring
|
||||
* @tx_free_idx: The index of th next free descriptor
|
||||
* @tx_next_idx: QDMA uses a linked list. This element points to the next
|
||||
* free descriptor in the list
|
||||
* @tx_free_count: QDMA uses a linked list. Track how many free descriptors
|
||||
* are present
|
||||
*/
|
||||
struct mtk_tx_ring {
|
||||
struct mtk_tx_dma *tx_dma;
|
||||
struct mtk_tx_buf *tx_buf;
|
||||
dma_addr_t tx_phys;
|
||||
struct mtk_tx_dma *tx_next_free;
|
||||
struct mtk_tx_dma *tx_last_free;
|
||||
u16 tx_thresh;
|
||||
int (*tx_map)(struct sk_buff *skb, struct net_device *dev, int tx_num,
|
||||
struct mtk_tx_ring *ring, bool gso);
|
||||
int (*tx_poll)(struct mtk_eth *eth, int budget, bool *tx_again);
|
||||
void (*tx_clean)(struct mtk_eth *eth);
|
||||
|
||||
/* PDMA only */
|
||||
u16 tx_ring_size;
|
||||
u16 tx_free_idx;
|
||||
|
||||
/* QDMA only */
|
||||
u16 tx_next_idx;
|
||||
atomic_t tx_free_count;
|
||||
};
|
||||
|
||||
/* struct mtk_rx_ring - This struct holds info describing a RX ring
|
||||
* @rx_dma: The descriptor ring
|
||||
* @rx_data: The memory pointed at by the ring
|
||||
* @trx_phys: The physical addr of rx_buf
|
||||
* @rx_ring_size: How many descriptors are in the ring
|
||||
* @rx_buf_size: The size of each packet buffer
|
||||
* @rx_calc_idx: The current head of ring
|
||||
*/
|
||||
struct mtk_rx_ring {
|
||||
struct mtk_rx_dma *rx_dma;
|
||||
u8 **rx_data;
|
||||
dma_addr_t rx_phys;
|
||||
u16 rx_ring_size;
|
||||
u16 frag_size;
|
||||
u16 rx_buf_size;
|
||||
u16 rx_calc_idx;
|
||||
};
|
||||
|
||||
/* currently no SoC has more than 2 macs */
|
||||
#define MTK_MAX_DEVS 2
|
||||
|
||||
/* struct mtk_eth - This is the main datasructure for holding the state
|
||||
* of the driver
|
||||
* @dev: The device pointer
|
||||
* @base: The mapped register i/o base
|
||||
* @page_lock: Make sure that register operations are atomic
|
||||
* @soc: pointer to our SoC specific data
|
||||
* @dummy_dev: we run 2 netdevs on 1 physical DMA ring and need a
|
||||
* dummy for NAPI to work
|
||||
* @netdev: The netdev instances
|
||||
* @mac: Each netdev is linked to a physical MAC
|
||||
* @switch_np: The phandle for the switch
|
||||
* @irq: The IRQ that we are using
|
||||
* @msg_enable: Ethtool msg level
|
||||
* @ysclk: The sysclk rate - neeed for calibration
|
||||
* @ethsys: The register map pointing at the range used to setup
|
||||
* MII modes
|
||||
* @dma_refcnt: track how many netdevs are using the DMA engine
|
||||
* @tx_ring: Pointer to the memore holding info about the TX ring
|
||||
* @rx_ring: Pointer to the memore holding info about the RX ring
|
||||
* @rx_napi: The NAPI struct
|
||||
* @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
|
||||
* @scratch_head: The scratch memory that scratch_ring points to.
|
||||
* @phy: Info about the attached PHYs
|
||||
* @mii_bus: If there is a bus we need to create an instance for it
|
||||
* @link: Track if the ports have a physical link
|
||||
* @sw_priv: Pointer to the switches private data
|
||||
* @vlan_map: RX VID tracking
|
||||
*/
|
||||
|
||||
struct mtk_eth {
|
||||
struct device *dev;
|
||||
void __iomem *base;
|
||||
spinlock_t page_lock;
|
||||
struct mtk_soc_data *soc;
|
||||
struct net_device dummy_dev;
|
||||
struct net_device *netdev[MTK_MAX_DEVS];
|
||||
struct mtk_mac *mac[MTK_MAX_DEVS];
|
||||
struct device_node *switch_np;
|
||||
int irq;
|
||||
u32 msg_enable;
|
||||
unsigned long sysclk;
|
||||
struct regmap *ethsys;
|
||||
atomic_t dma_refcnt;
|
||||
struct mtk_tx_ring tx_ring;
|
||||
struct mtk_rx_ring rx_ring[2];
|
||||
struct napi_struct rx_napi;
|
||||
struct mtk_tx_dma *scratch_ring;
|
||||
void *scratch_head;
|
||||
struct mtk_phy *phy;
|
||||
struct mii_bus *mii_bus;
|
||||
int link[8];
|
||||
void *sw_priv;
|
||||
unsigned long vlan_map;
|
||||
};
|
||||
|
||||
/* struct mtk_mac - the structure that holds the info about the MACs of the
|
||||
* SoC
|
||||
* @id: The number of the MAC
|
||||
* @of_node: Our devicetree node
|
||||
* @hw: Backpointer to our main datastruture
|
||||
* @hw_stats: Packet statistics counter
|
||||
* @phy_dev: The attached PHY if available
|
||||
* @phy_flags: The PHYs flags
|
||||
* @pending_work: The workqueue used to reset the dma ring
|
||||
*/
|
||||
struct mtk_mac {
|
||||
int id;
|
||||
struct device_node *of_node;
|
||||
struct mtk_eth *hw;
|
||||
struct mtk_hw_stats *hw_stats;
|
||||
struct phy_device *phy_dev;
|
||||
u32 phy_flags;
|
||||
struct work_struct pending_work;
|
||||
};
|
||||
|
||||
/* the struct describing the SoC. these are declared in the soc_xyz.c files */
|
||||
extern const struct of_device_id of_mtk_match[];
|
||||
|
||||
/* read the hardware status register */
|
||||
void mtk_stats_update_mac(struct mtk_mac *mac);
|
||||
|
||||
/* default checksum setup handler */
|
||||
void mtk_reset(struct mtk_eth *eth, u32 reset_bits);
|
||||
|
||||
/* register i/o wrappers */
|
||||
void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
|
||||
u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
|
||||
|
||||
/* default clock calibration handler */
|
||||
int mtk_set_clock_cycle(struct mtk_eth *eth);
|
||||
|
||||
/* default checksum setup handler */
|
||||
void mtk_csum_config(struct mtk_eth *eth);
|
||||
|
||||
/* default forward config handler */
|
||||
void mtk_fwd_config(struct mtk_eth *eth);
|
||||
|
||||
#endif /* MTK_ETH_H */
|
Loading…
Reference in New Issue
Block a user