* [PATCH net-next 0/2] Fix TX Timeout and implement Safety Features
@ 2018-02-01 14:41 Jose Abreu
2018-02-01 14:41 ` [PATCH net-next 1/2] net: stmmac: Rework and fix TX Timeout code Jose Abreu
2018-02-01 14:41 ` [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features Jose Abreu
0 siblings, 2 replies; 9+ messages in thread
From: Jose Abreu @ 2018-02-01 14:41 UTC (permalink / raw)
To: netdev
Cc: Jose Abreu, David S. Miller, Joao Pinto, Giuseppe Cavallaro,
Alexandre Torgue
Fix the TX Timeout handler to correctly reconfigure the whole system and
start implementing features for DWMAC5 cores, specifically the Safety
Features.
Cc: David S. Miller <davem@davemloft.net>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Jose Abreu (2):
net: stmmac: Rework and fix TX Timeout code
net: stmmac: Add support for DWMAC5 and implement Safety Features
drivers/net/ethernet/stmicro/stmmac/Makefile | 2 +-
drivers/net/ethernet/stmicro/stmmac/common.h | 8 +
drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 4 +
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 38 +++-
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c | 6 +
drivers/net/ethernet/stmicro/stmmac/dwmac5.c | 242 +++++++++++++++++++++
drivers/net/ethernet/stmicro/stmmac/dwmac5.h | 49 ++++
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 11 +
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 101 ++++++++-
9 files changed, 454 insertions(+), 7 deletions(-)
create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac5.c
create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac5.h
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next 1/2] net: stmmac: Rework and fix TX Timeout code
2018-02-01 14:41 [PATCH net-next 0/2] Fix TX Timeout and implement Safety Features Jose Abreu
@ 2018-02-01 14:41 ` Jose Abreu
2018-02-01 14:41 ` [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features Jose Abreu
1 sibling, 0 replies; 9+ messages in thread
From: Jose Abreu @ 2018-02-01 14:41 UTC (permalink / raw)
To: netdev
Cc: Jose Abreu, David S. Miller, Joao Pinto, Giuseppe Cavallaro,
Alexandre Torgue
Currently TX Timeout handler does not behaves as expected and leads to
an unrecoverable state. Rework current implementation of TX Timeout
handling to actually perform a complete reset of the driver state and IP.
We use deferred work to init a task which will be responsible for
resetting the system.
Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 11 ++++
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 66 +++++++++++++++++++--
2 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index a916e13..c8b70a7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -145,6 +145,17 @@ struct stmmac_priv {
struct dentry *dbgfs_rings_status;
struct dentry *dbgfs_dma_cap;
#endif
+
+ unsigned long state;
+ struct workqueue_struct *wq;
+ struct work_struct service_task;
+};
+
+enum stmmac_state {
+ STMMAC_DOWN,
+ STMMAC_RESET_REQUESTED,
+ STMMAC_RESETING,
+ STMMAC_SERVICE_SCHED,
};
int stmmac_mdio_unregister(struct net_device *ndev);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 7ad8414..c84c24f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -196,6 +196,19 @@ static void stmmac_start_all_queues(struct stmmac_priv *priv)
netif_tx_start_queue(netdev_get_tx_queue(priv->dev, queue));
}
+static void stmmac_service_event_schedule(struct stmmac_priv *priv)
+{
+ if (!test_bit(STMMAC_DOWN, &priv->state) &&
+ !test_and_set_bit(STMMAC_SERVICE_SCHED, &priv->state))
+ queue_work(priv->wq, &priv->service_task);
+}
+
+static void stmmac_global_err(struct stmmac_priv *priv)
+{
+ set_bit(STMMAC_RESET_REQUESTED, &priv->state);
+ stmmac_service_event_schedule(priv);
+}
+
/**
* stmmac_clk_csr_set - dynamically set the MDC clock
* @priv: driver private structure
@@ -3572,12 +3585,8 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
static void stmmac_tx_timeout(struct net_device *dev)
{
struct stmmac_priv *priv = netdev_priv(dev);
- u32 tx_count = priv->plat->tx_queues_to_use;
- u32 chan;
- /* Clear Tx resources and restart transmitting again */
- for (chan = 0; chan < tx_count; chan++)
- stmmac_tx_err(priv, chan);
+ stmmac_global_err(priv);
}
/**
@@ -3701,6 +3710,10 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
return IRQ_NONE;
}
+ /* Check if adapter is up */
+ if (test_bit(STMMAC_DOWN, &priv->state))
+ return IRQ_HANDLED;
+
/* To handle GMAC own interrupts */
if ((priv->plat->has_gmac) || (priv->plat->has_gmac4)) {
int status = priv->hw->mac->host_irq_status(priv->hw,
@@ -4036,6 +4049,37 @@ static void stmmac_exit_fs(struct net_device *dev)
.ndo_set_mac_address = stmmac_set_mac_address,
};
+static void stmmac_reset_subtask(struct stmmac_priv *priv)
+{
+ if (!test_and_clear_bit(STMMAC_RESET_REQUESTED, &priv->state))
+ return;
+ if (test_bit(STMMAC_DOWN, &priv->state))
+ return;
+
+ netdev_err(priv->dev, "Reset adapter.\n");
+
+ rtnl_lock();
+ netif_trans_update(priv->dev);
+ while (test_and_set_bit(STMMAC_RESETING, &priv->state))
+ usleep_range(1000, 2000);
+
+ set_bit(STMMAC_DOWN, &priv->state);
+ dev_close(priv->dev);
+ dev_open(priv->dev);
+ clear_bit(STMMAC_DOWN, &priv->state);
+ clear_bit(STMMAC_RESETING, &priv->state);
+ rtnl_unlock();
+}
+
+static void stmmac_service_task(struct work_struct *work)
+{
+ struct stmmac_priv *priv = container_of(work, struct stmmac_priv,
+ service_task);
+
+ stmmac_reset_subtask(priv);
+ clear_bit(STMMAC_SERVICE_SCHED, &priv->state);
+}
+
/**
* stmmac_hw_init - Init the MAC device
* @priv: driver private structure
@@ -4197,6 +4241,15 @@ int stmmac_dvr_probe(struct device *device,
/* Verify driver arguments */
stmmac_verify_args();
+ /* Allocate workqueue */
+ priv->wq = create_singlethread_workqueue("stmmac_wq");
+ if (!priv->wq) {
+ dev_err(priv->device, "failed to create workqueue\n");
+ goto error_wq;
+ }
+
+ INIT_WORK(&priv->service_task, stmmac_service_task);
+
/* Override with kernel parameters if supplied XXX CRS XXX
* this needs to have multiple instances
*/
@@ -4327,6 +4380,8 @@ int stmmac_dvr_probe(struct device *device,
netif_napi_del(&rx_q->napi);
}
error_hw_init:
+ destroy_workqueue(priv->wq);
+error_wq:
free_netdev(ndev);
return ret;
@@ -4359,6 +4414,7 @@ int stmmac_dvr_remove(struct device *dev)
priv->hw->pcs != STMMAC_PCS_TBI &&
priv->hw->pcs != STMMAC_PCS_RTBI)
stmmac_mdio_unregister(ndev);
+ destroy_workqueue(priv->wq);
free_netdev(ndev);
return 0;
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
2018-02-01 14:41 [PATCH net-next 0/2] Fix TX Timeout and implement Safety Features Jose Abreu
2018-02-01 14:41 ` [PATCH net-next 1/2] net: stmmac: Rework and fix TX Timeout code Jose Abreu
@ 2018-02-01 14:41 ` Jose Abreu
2018-02-01 14:44 ` Joao Pinto
1 sibling, 1 reply; 9+ messages in thread
From: Jose Abreu @ 2018-02-01 14:41 UTC (permalink / raw)
To: netdev
Cc: Jose Abreu, David S. Miller, Joao Pinto, Giuseppe Cavallaro,
Alexandre Torgue
This adds initial suport for DWMAC5 and implements the Automotive Safety
Package which is available from core version 5.10.
The Automotive Safety Pacakge (also called Safety Features) offers us
with error protection in the core by implementing ECC Protection in
memories, on-chip data path parity protection, FSM parity and timeout
protection and Application/CSR interface timeout protection.
In case of an uncorrectable error we call stmmac_global_err() and
reconfigure the whole core.
Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
---
drivers/net/ethernet/stmicro/stmmac/Makefile | 2 +-
drivers/net/ethernet/stmicro/stmmac/common.h | 8 +
drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 4 +
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 38 +++-
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c | 6 +
drivers/net/ethernet/stmicro/stmmac/dwmac5.c | 242 +++++++++++++++++++++
drivers/net/ethernet/stmicro/stmmac/dwmac5.h | 49 ++++
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 35 +++
8 files changed, 382 insertions(+), 2 deletions(-)
create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac5.c
create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac5.h
diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index ff3f83b..972e4ef 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -4,7 +4,7 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \
chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o dwmac4_descs.o \
- dwmac4_dma.o dwmac4_lib.o dwmac4_core.o $(stmmac-y)
+ dwmac4_dma.o dwmac4_lib.o dwmac4_core.o dwmac5.o $(stmmac-y)
# Ordering matters. Generic driver must be last.
obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 2ffe76c..7bbd7eb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -38,6 +38,8 @@
#define DWMAC_CORE_3_40 0x34
#define DWMAC_CORE_3_50 0x35
#define DWMAC_CORE_4_00 0x40
+#define DWMAC_CORE_5_00 0x50
+#define DWMAC_CORE_5_10 0x51
#define STMMAC_CHAN0 0 /* Always supported and default for all chips */
/* These need to be power of two, and >= 4 */
@@ -336,6 +338,8 @@ struct dma_features {
/* TX and RX FIFO sizes */
unsigned int tx_fifo_size;
unsigned int rx_fifo_size;
+ /* Automotive Safety Package */
+ unsigned int asp;
};
/* GMAC TX FIFO is 8K, Rx FIFO is 16K */
@@ -532,6 +536,10 @@ struct stmmac_ops {
bool loopback);
void (*pcs_rane)(void __iomem *ioaddr, bool restart);
void (*pcs_get_adv_lp)(void __iomem *ioaddr, struct rgmii_adv *adv);
+ /* Safety Features */
+ int (*safety_feat_config)(void __iomem *ioaddr, unsigned int asp);
+ bool (*safety_feat_irq_status)(struct net_device *ndev,
+ void __iomem *ioaddr, unsigned int asp);
};
/* PTP and HW Timer helpers */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 789dad8..afe9834 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -39,6 +39,7 @@
#define GMAC_HW_FEATURE0 0x0000011c
#define GMAC_HW_FEATURE1 0x00000120
#define GMAC_HW_FEATURE2 0x00000124
+#define GMAC_HW_FEATURE3 0x00000128
#define GMAC_MDIO_ADDR 0x00000200
#define GMAC_MDIO_DATA 0x00000204
#define GMAC_ADDR_HIGH(reg) (0x300 + reg * 8)
@@ -192,6 +193,9 @@ enum power_event {
#define GMAC_HW_FEAT_TXQCNT GENMASK(9, 6)
#define GMAC_HW_FEAT_RXQCNT GENMASK(3, 0)
+/* MAC HW features3 bitmap */
+#define GMAC_HW_FEAT_ASP GENMASK(29, 28)
+
/* MAC HW ADDR regs */
#define GMAC_HI_DCS GENMASK(18, 16)
#define GMAC_HI_DCS_SHIFT 16
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index ed222b2..5a24a6f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -20,6 +20,7 @@
#include <net/dsa.h>
#include "stmmac_pcs.h"
#include "dwmac4.h"
+#include "dwmac5.h"
static void dwmac4_core_init(struct mac_device_info *hw,
struct net_device *dev)
@@ -767,6 +768,39 @@ static void dwmac4_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
.set_filter = dwmac4_set_filter,
};
+static const struct stmmac_ops dwmac510_ops = {
+ .core_init = dwmac4_core_init,
+ .set_mac = stmmac_dwmac4_set_mac,
+ .rx_ipc = dwmac4_rx_ipc_enable,
+ .rx_queue_enable = dwmac4_rx_queue_enable,
+ .rx_queue_prio = dwmac4_rx_queue_priority,
+ .tx_queue_prio = dwmac4_tx_queue_priority,
+ .rx_queue_routing = dwmac4_tx_queue_routing,
+ .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
+ .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
+ .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
+ .map_mtl_to_dma = dwmac4_map_mtl_dma,
+ .config_cbs = dwmac4_config_cbs,
+ .dump_regs = dwmac4_dump_regs,
+ .host_irq_status = dwmac4_irq_status,
+ .host_mtl_irq_status = dwmac4_irq_mtl_status,
+ .flow_ctrl = dwmac4_flow_ctrl,
+ .pmt = dwmac4_pmt,
+ .set_umac_addr = dwmac4_set_umac_addr,
+ .get_umac_addr = dwmac4_get_umac_addr,
+ .set_eee_mode = dwmac4_set_eee_mode,
+ .reset_eee_mode = dwmac4_reset_eee_mode,
+ .set_eee_timer = dwmac4_set_eee_timer,
+ .set_eee_pls = dwmac4_set_eee_pls,
+ .pcs_ctrl_ane = dwmac4_ctrl_ane,
+ .pcs_rane = dwmac4_rane,
+ .pcs_get_adv_lp = dwmac4_get_adv_lp,
+ .debug = dwmac4_debug,
+ .set_filter = dwmac4_set_filter,
+ .safety_feat_config = dwmac5_safety_feat_config,
+ .safety_feat_irq_status = dwmac5_safety_feat_irq_status,
+};
+
struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
int perfect_uc_entries, int *synopsys_id)
{
@@ -807,7 +841,9 @@ struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
else
mac->dma = &dwmac4_dma_ops;
- if (*synopsys_id >= DWMAC_CORE_4_00)
+ if (*synopsys_id >= DWMAC_CORE_5_10)
+ mac->mac = &dwmac510_ops;
+ else if (*synopsys_id >= DWMAC_CORE_4_00)
mac->mac = &dwmac410_ops;
else
mac->mac = &dwmac4_ops;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
index c110f68..d37d457 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
@@ -373,6 +373,12 @@ static void dwmac4_get_hw_feature(void __iomem *ioaddr,
/* IEEE 1588-2002 */
dma_cap->time_stamp = 0;
+
+ /* MAC HW feature3 */
+ hw_cap = readl(ioaddr + GMAC_HW_FEATURE3);
+
+ /* 5.10 Features */
+ dma_cap->asp = (hw_cap & GMAC_HW_FEAT_ASP) >> 28;
}
/* Enable/disable TSO feature and set MSS */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
new file mode 100644
index 0000000..f751cd8
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
@@ -0,0 +1,242 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+// Copyright (c) 2017 Synopsys, Inc. and/or its affiliates.
+// stmmac Support for 5.xx Ethernet QoS cores
+
+#include <linux/bitops.h>
+#include <linux/iopoll.h>
+#include "common.h"
+#include "dwmac4.h"
+#include "dwmac5.h"
+
+static void dwmac5_log_error(struct net_device *ndev, u32 value, bool corr,
+ const char *module_name, const char **errors_str)
+{
+ unsigned long loc, mask;
+
+ mask = value;
+ for_each_set_bit(loc, &mask, 32) {
+ netdev_err(ndev, "Found %s error in %s: '%s'\n", corr ?
+ "correctable" : "uncorrectable", module_name,
+ errors_str[loc]);
+ }
+}
+
+static const char *dwmac5_mac_errors[32] = {
+ "ATPES: Application Transmit Interface Parity Check Error",
+ "TPES: TSO Data Path Parity Check Error",
+ "RDPES: Read Descriptor Parity Check Error",
+ "MPES: MTL Data Path Parity Check Error",
+ "MTSPES: MTL TX Status Data Path Parity Check Error",
+ "ARPES: Application Receive Interface Data Path Parity Check Error",
+ "CWPES: CSR Write Data Path Parity Check Error",
+ "ASRPES: AXI Slave Read Data Path Parity Check Error",
+ "TTES: TX FSM Timeout Error",
+ "RTES: RX FSM Timeout Error",
+ "CTES: CSR FSM Timeout Error",
+ "ATES: APP FSM Timeout Error",
+ "PTES: PTP FSM Timeout Error",
+ "T125ES: TX125 FSM Timeout Error",
+ "R125ES: RX125 FSM Timeout Error",
+ "RVCTES: REV MDC FSM Timeout Error",
+ "MSTTES: Master Read/Write Timeout Error",
+ "SLVTES: Slave Read/Write Timeout Error",
+ "ATITES: Application Timeout on ATI Interface Error",
+ "ARITES: Application Timeout on ARI Interface Error",
+ "Unknown Error", /* 20 */
+ "Unknown Error", /* 21 */
+ "Unknown Error", /* 22 */
+ "Unknown Error", /* 23 */
+ "FSMPES: FSM State Parity Error",
+ "Unknown Error", /* 25 */
+ "Unknown Error", /* 26 */
+ "Unknown Error", /* 27 */
+ "Unknown Error", /* 28 */
+ "Unknown Error", /* 29 */
+ "Unknown Error", /* 30 */
+ "Unknown Error", /* 31 */
+};
+
+static bool dwmac5_handle_mac_err(struct net_device *ndev,
+ void __iomem *ioaddr, bool correctable)
+{
+ u32 value;
+
+ value = readl(ioaddr + MAC_DPP_FSM_INT_STATUS);
+ writel(value, ioaddr + MAC_DPP_FSM_INT_STATUS);
+
+ dwmac5_log_error(ndev, value, correctable, "MAC", dwmac5_mac_errors);
+ return !correctable;
+}
+
+static const char *dwmac5_mtl_errors[32] = {
+ "TXCES: MTL TX Memory Error",
+ "TXAMS: MTL TX Memory Address Mismatch Error",
+ "TXUES: MTL TX Memory Error",
+ "Unknown Error", /* 3 */
+ "RXCES: MTL RX Memory Error",
+ "RXAMS: MTL RX Memory Address Mismatch Error",
+ "RXUES: MTL RX Memory Error",
+ "Unknown Error", /* 7 */
+ "ECES: MTL EST Memory Error",
+ "EAMS: MTL EST Memory Address Mismatch Error",
+ "EUES: MTL EST Memory Error",
+ "Unknown Error", /* 11 */
+ "RPCES: MTL RX Parser Memory Error",
+ "RPAMS: MTL RX Parser Memory Address Mismatch Error",
+ "RPUES: MTL RX Parser Memory Error",
+ "Unknown Error", /* 15 */
+ "Unknown Error", /* 16 */
+ "Unknown Error", /* 17 */
+ "Unknown Error", /* 18 */
+ "Unknown Error", /* 19 */
+ "Unknown Error", /* 20 */
+ "Unknown Error", /* 21 */
+ "Unknown Error", /* 22 */
+ "Unknown Error", /* 23 */
+ "Unknown Error", /* 24 */
+ "Unknown Error", /* 25 */
+ "Unknown Error", /* 26 */
+ "Unknown Error", /* 27 */
+ "Unknown Error", /* 28 */
+ "Unknown Error", /* 29 */
+ "Unknown Error", /* 30 */
+ "Unknown Error", /* 31 */
+};
+
+static bool dwmac5_handle_mtl_err(struct net_device *ndev,
+ void __iomem *ioaddr, bool correctable)
+{
+ u32 value;
+
+ value = readl(ioaddr + MTL_ECC_INT_STATUS);
+ writel(value, ioaddr + MTL_ECC_INT_STATUS);
+
+ dwmac5_log_error(ndev, value, correctable, "MTL", dwmac5_mtl_errors);
+ return !correctable;
+}
+
+static const char *dwmac5_dma_errors[32] = {
+ "TCES: DMA TSO Memory Error",
+ "TAMS: DMA TSO Memory Address Mismatch Error",
+ "TUES: DMA TSO Memory Error",
+ "Unknown Error", /* 3 */
+ "Unknown Error", /* 4 */
+ "Unknown Error", /* 5 */
+ "Unknown Error", /* 6 */
+ "Unknown Error", /* 7 */
+ "Unknown Error", /* 8 */
+ "Unknown Error", /* 9 */
+ "Unknown Error", /* 10 */
+ "Unknown Error", /* 11 */
+ "Unknown Error", /* 12 */
+ "Unknown Error", /* 13 */
+ "Unknown Error", /* 14 */
+ "Unknown Error", /* 15 */
+ "Unknown Error", /* 16 */
+ "Unknown Error", /* 17 */
+ "Unknown Error", /* 18 */
+ "Unknown Error", /* 19 */
+ "Unknown Error", /* 20 */
+ "Unknown Error", /* 21 */
+ "Unknown Error", /* 22 */
+ "Unknown Error", /* 23 */
+ "Unknown Error", /* 24 */
+ "Unknown Error", /* 25 */
+ "Unknown Error", /* 26 */
+ "Unknown Error", /* 27 */
+ "Unknown Error", /* 28 */
+ "Unknown Error", /* 29 */
+ "Unknown Error", /* 30 */
+ "Unknown Error", /* 31 */
+};
+
+static bool dwmac5_handle_dma_err(struct net_device *ndev,
+ void __iomem *ioaddr, bool correctable)
+{
+ u32 value;
+
+ value = readl(ioaddr + DMA_ECC_INT_STATUS);
+ writel(value, ioaddr + DMA_ECC_INT_STATUS);
+
+ dwmac5_log_error(ndev, value, correctable, "DMA", dwmac5_dma_errors);
+ return !correctable;
+}
+
+int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp)
+{
+ u32 value;
+
+ if (!asp)
+ return -EINVAL;
+
+ /* 1. Enable Safety Features */
+ value = readl(ioaddr + MTL_ECC_CONTROL);
+ value |= TSOEE; /* TSO ECC */
+ value |= MRXPEE; /* MTL RX Parser ECC */
+ value |= MESTEE; /* MTL EST ECC */
+ value |= MRXEE; /* MTL RX FIFO ECC */
+ value |= MTXEE; /* MTL TX FIFO ECC */
+ writel(value, ioaddr + MTL_ECC_CONTROL);
+
+ /* 2. Enable MTL Safety Interrupts */
+ value = readl(ioaddr + MTL_ECC_INT_ENABLE);
+ value |= RPCEIE; /* RX Parser Memory Correctable Error */
+ value |= ECEIE; /* EST Memory Correctable Error */
+ value |= RXCEIE; /* RX Memory Correctable Error */
+ value |= TXCEIE; /* TX Memory Correctable Error */
+ writel(value, ioaddr + MTL_ECC_INT_ENABLE);
+
+ /* 3. Enable DMA Safety Interrupts */
+ value = readl(ioaddr + DMA_ECC_INT_ENABLE);
+ value |= TCEIE; /* TSO Memory Correctable Error */
+ writel(value, ioaddr + DMA_ECC_INT_ENABLE);
+
+ /* Only ECC Protection for External Memory feature is selected */
+ if (asp <= 0x1)
+ return 0;
+
+ /* 5. Enable Parity and Timeout for FSM */
+ value = readl(ioaddr + MAC_FSM_CONTROL);
+ value |= PRTYEN; /* FSM Parity Feature */
+ value |= TMOUTEN; /* FSM Timeout Feature */
+ writel(value, ioaddr + MAC_FSM_CONTROL);
+
+ /* 4. Enable Data Parity Protection */
+ value = readl(ioaddr + MTL_DPP_CONTROL);
+ value |= EDPP;
+ writel(value, ioaddr + MTL_DPP_CONTROL);
+
+ /*
+ * All the Automotive Safety features are selected without the "Parity
+ * Port Enable for external interface" feature.
+ */
+ if (asp <= 0x2)
+ return 0;
+
+ value |= EPSI;
+ writel(value, ioaddr + MTL_DPP_CONTROL);
+ return 0;
+}
+
+bool dwmac5_safety_feat_irq_status(struct net_device *ndev,
+ void __iomem *ioaddr, unsigned int asp)
+{
+ bool ret = false;
+ u32 mtl, dma;
+
+ if (!asp)
+ return false;
+
+ mtl = readl(ioaddr + MTL_SAFETY_INT_STATUS);
+ dma = readl(ioaddr + DMA_SAFETY_INT_STATUS);
+
+ if ((mtl & MCSIS) || (dma & MCSIS))
+ ret |= dwmac5_handle_mac_err(ndev, ioaddr, false);
+ if ((mtl & (MEUIS | MECIS)) || (dma & (MSUIS | MSCIS)))
+ ret |= dwmac5_handle_mtl_err(ndev, ioaddr,
+ (mtl & MECIS) || (dma & MSCIS));
+ if (dma & (DEUIS | DECIS))
+ ret |= dwmac5_handle_dma_err(ndev, ioaddr, dma & DECIS);
+
+ return ret;
+}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h
new file mode 100644
index 0000000..debbb8a
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+// Copyright (c) 2017 Synopsys, Inc. and/or its affiliates.
+// stmmac Support for 5.xx Ethernet QoS cores
+
+#ifndef __DWMAC5_H__
+#define __DWMAC5_H__
+
+#define MAC_DPP_FSM_INT_STATUS 0x00000140
+#define MAC_AXI_SLV_DPE_ADDR_STATUS 0x00000144
+#define MAC_FSM_CONTROL 0x00000148
+#define PRTYEN BIT(1)
+#define TMOUTEN BIT(0)
+
+#define MTL_ECC_CONTROL 0x00000cc0
+#define TSOEE BIT(4)
+#define MRXPEE BIT(3)
+#define MESTEE BIT(2)
+#define MRXEE BIT(1)
+#define MTXEE BIT(0)
+
+#define MTL_SAFETY_INT_STATUS 0x00000cc4
+#define MCSIS BIT(31)
+#define MEUIS BIT(1)
+#define MECIS BIT(0)
+#define MTL_ECC_INT_ENABLE 0x00000cc8
+#define RPCEIE BIT(12)
+#define ECEIE BIT(8)
+#define RXCEIE BIT(4)
+#define TXCEIE BIT(0)
+#define MTL_ECC_INT_STATUS 0x00000ccc
+#define MTL_DPP_CONTROL 0x00000ce0
+#define EPSI BIT(2)
+#define OPE BIT(1)
+#define EDPP BIT(0)
+
+#define DMA_SAFETY_INT_STATUS 0x00001080
+#define MSUIS BIT(29)
+#define MSCIS BIT(28)
+#define DEUIS BIT(1)
+#define DECIS BIT(0)
+#define DMA_ECC_INT_ENABLE 0x00001084
+#define TCEIE BIT(0)
+#define DMA_ECC_INT_STATUS 0x00001088
+
+int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp);
+bool dwmac5_safety_feat_irq_status(struct net_device *ndev,
+ void __iomem *ioaddr, unsigned int asp);
+
+#endif /* __DWMAC5_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c84c24f..97ab4ca 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -205,6 +205,7 @@ static void stmmac_service_event_schedule(struct stmmac_priv *priv)
static void stmmac_global_err(struct stmmac_priv *priv)
{
+ netif_carrier_off(priv->dev);
set_bit(STMMAC_RESET_REQUESTED, &priv->state);
stmmac_service_event_schedule(priv);
}
@@ -2006,6 +2007,22 @@ static void stmmac_set_dma_operation_mode(struct stmmac_priv *priv, u32 txmode,
}
}
+static bool stmmac_safety_feat_interrupt(struct stmmac_priv *priv)
+{
+ bool ret = false;
+
+ /* Safety features are only available in cores >= 5.10 */
+ if (priv->synopsys_id < DWMAC_CORE_5_10)
+ return ret;
+ if (priv->hw->mac->safety_feat_irq_status)
+ ret = priv->hw->mac->safety_feat_irq_status(priv->dev,
+ priv->ioaddr, priv->dma_cap.asp);
+
+ if (ret)
+ stmmac_global_err(priv);
+ return ret;
+}
+
/**
* stmmac_dma_interrupt - DMA ISR
* @priv: driver private structure
@@ -2495,6 +2512,17 @@ static void stmmac_mtl_configuration(struct stmmac_priv *priv)
stmmac_mac_config_rx_queues_routing(priv);
}
+static void stmmac_safety_feat_configuration(struct stmmac_priv *priv)
+{
+ if (priv->hw->mac->safety_feat_config && priv->dma_cap.asp) {
+ netdev_info(priv->dev, "Enabling Safety Features\n");
+ priv->hw->mac->safety_feat_config(priv->ioaddr,
+ priv->dma_cap.asp);
+ } else {
+ netdev_info(priv->dev, "No Safety Features support found\n");
+ }
+}
+
/**
* stmmac_hw_setup - setup mac in a usable state.
* @dev : pointer to the device structure.
@@ -2546,6 +2574,10 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
if (priv->synopsys_id >= DWMAC_CORE_4_00)
stmmac_mtl_configuration(priv);
+ /* Initialize Safety Features */
+ if (priv->synopsys_id >= DWMAC_CORE_5_10)
+ stmmac_safety_feat_configuration(priv);
+
ret = priv->hw->mac->rx_ipc(priv->hw);
if (!ret) {
netdev_warn(priv->dev, "RX IPC Checksum Offload disabled\n");
@@ -3713,6 +3745,9 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
/* Check if adapter is up */
if (test_bit(STMMAC_DOWN, &priv->state))
return IRQ_HANDLED;
+ /* Check if a fatal error happened */
+ if (stmmac_safety_feat_interrupt(priv))
+ return IRQ_HANDLED;
/* To handle GMAC own interrupts */
if ((priv->plat->has_gmac) || (priv->plat->has_gmac4)) {
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* RE: [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
2018-02-01 14:41 ` [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features Jose Abreu
@ 2018-02-01 14:44 ` Joao Pinto
2018-02-01 15:02 ` Andrew Lunn
0 siblings, 1 reply; 9+ messages in thread
From: Joao Pinto @ 2018-02-01 14:44 UTC (permalink / raw)
To: Jose Abreu, netdev@vger.kernel.org
Cc: Jose Abreu, David S. Miller, Giuseppe Cavallaro, Alexandre Torgue
Looking great!
-----Original Message-----
From: Jose Abreu [mailto:joabreu@synopsys.com]
Sent: Thursday, February 1, 2018 2:42 PM
To: netdev@vger.kernel.org
Cc: Jose Abreu <joabreu@synopsys.com>; David S. Miller <davem@davemloft.net>; Joao Pinto <jpinto@synopsys.com>; Giuseppe Cavallaro <peppe.cavallaro@st.com>; Alexandre Torgue <alexandre.torgue@st.com>
Subject: [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
This adds initial suport for DWMAC5 and implements the Automotive Safety Package which is available from core version 5.10.
The Automotive Safety Pacakge (also called Safety Features) offers us with error protection in the core by implementing ECC Protection in memories, on-chip data path parity protection, FSM parity and timeout protection and Application/CSR interface timeout protection.
In case of an uncorrectable error we call stmmac_global_err() and reconfigure the whole core.
Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
---
drivers/net/ethernet/stmicro/stmmac/Makefile | 2 +-
drivers/net/ethernet/stmicro/stmmac/common.h | 8 +
drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 4 +
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 38 +++-
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c | 6 +
drivers/net/ethernet/stmicro/stmmac/dwmac5.c | 242 +++++++++++++++++++++
drivers/net/ethernet/stmicro/stmmac/dwmac5.h | 49 ++++
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 35 +++
8 files changed, 382 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac5.c
create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac5.h
diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index ff3f83b..972e4ef 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -4,7 +4,7 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \
chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o dwmac4_descs.o \
- dwmac4_dma.o dwmac4_lib.o dwmac4_core.o $(stmmac-y)
+ dwmac4_dma.o dwmac4_lib.o dwmac4_core.o dwmac5.o $(stmmac-y)
# Ordering matters. Generic driver must be last.
obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 2ffe76c..7bbd7eb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -38,6 +38,8 @@
#define DWMAC_CORE_3_40 0x34
#define DWMAC_CORE_3_50 0x35
#define DWMAC_CORE_4_00 0x40
+#define DWMAC_CORE_5_00 0x50
+#define DWMAC_CORE_5_10 0x51
#define STMMAC_CHAN0 0 /* Always supported and default for all chips */
/* These need to be power of two, and >= 4 */ @@ -336,6 +338,8 @@ struct dma_features {
/* TX and RX FIFO sizes */
unsigned int tx_fifo_size;
unsigned int rx_fifo_size;
+ /* Automotive Safety Package */
+ unsigned int asp;
};
/* GMAC TX FIFO is 8K, Rx FIFO is 16K */ @@ -532,6 +536,10 @@ struct stmmac_ops {
bool loopback);
void (*pcs_rane)(void __iomem *ioaddr, bool restart);
void (*pcs_get_adv_lp)(void __iomem *ioaddr, struct rgmii_adv *adv);
+ /* Safety Features */
+ int (*safety_feat_config)(void __iomem *ioaddr, unsigned int asp);
+ bool (*safety_feat_irq_status)(struct net_device *ndev,
+ void __iomem *ioaddr, unsigned int asp);
};
/* PTP and HW Timer helpers */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 789dad8..afe9834 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -39,6 +39,7 @@
#define GMAC_HW_FEATURE0 0x0000011c
#define GMAC_HW_FEATURE1 0x00000120
#define GMAC_HW_FEATURE2 0x00000124
+#define GMAC_HW_FEATURE3 0x00000128
#define GMAC_MDIO_ADDR 0x00000200
#define GMAC_MDIO_DATA 0x00000204
#define GMAC_ADDR_HIGH(reg) (0x300 + reg * 8)
@@ -192,6 +193,9 @@ enum power_event {
#define GMAC_HW_FEAT_TXQCNT GENMASK(9, 6)
#define GMAC_HW_FEAT_RXQCNT GENMASK(3, 0)
+/* MAC HW features3 bitmap */
+#define GMAC_HW_FEAT_ASP GENMASK(29, 28)
+
/* MAC HW ADDR regs */
#define GMAC_HI_DCS GENMASK(18, 16)
#define GMAC_HI_DCS_SHIFT 16
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index ed222b2..5a24a6f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -20,6 +20,7 @@
#include <net/dsa.h>
#include "stmmac_pcs.h"
#include "dwmac4.h"
+#include "dwmac5.h"
static void dwmac4_core_init(struct mac_device_info *hw,
struct net_device *dev)
@@ -767,6 +768,39 @@ static void dwmac4_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
.set_filter = dwmac4_set_filter,
};
+static const struct stmmac_ops dwmac510_ops = {
+ .core_init = dwmac4_core_init,
+ .set_mac = stmmac_dwmac4_set_mac,
+ .rx_ipc = dwmac4_rx_ipc_enable,
+ .rx_queue_enable = dwmac4_rx_queue_enable,
+ .rx_queue_prio = dwmac4_rx_queue_priority,
+ .tx_queue_prio = dwmac4_tx_queue_priority,
+ .rx_queue_routing = dwmac4_tx_queue_routing,
+ .prog_mtl_rx_algorithms = dwmac4_prog_mtl_rx_algorithms,
+ .prog_mtl_tx_algorithms = dwmac4_prog_mtl_tx_algorithms,
+ .set_mtl_tx_queue_weight = dwmac4_set_mtl_tx_queue_weight,
+ .map_mtl_to_dma = dwmac4_map_mtl_dma,
+ .config_cbs = dwmac4_config_cbs,
+ .dump_regs = dwmac4_dump_regs,
+ .host_irq_status = dwmac4_irq_status,
+ .host_mtl_irq_status = dwmac4_irq_mtl_status,
+ .flow_ctrl = dwmac4_flow_ctrl,
+ .pmt = dwmac4_pmt,
+ .set_umac_addr = dwmac4_set_umac_addr,
+ .get_umac_addr = dwmac4_get_umac_addr,
+ .set_eee_mode = dwmac4_set_eee_mode,
+ .reset_eee_mode = dwmac4_reset_eee_mode,
+ .set_eee_timer = dwmac4_set_eee_timer,
+ .set_eee_pls = dwmac4_set_eee_pls,
+ .pcs_ctrl_ane = dwmac4_ctrl_ane,
+ .pcs_rane = dwmac4_rane,
+ .pcs_get_adv_lp = dwmac4_get_adv_lp,
+ .debug = dwmac4_debug,
+ .set_filter = dwmac4_set_filter,
+ .safety_feat_config = dwmac5_safety_feat_config,
+ .safety_feat_irq_status = dwmac5_safety_feat_irq_status, };
+
struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
int perfect_uc_entries, int *synopsys_id) { @@ -807,7 +841,9 @@ struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
else
mac->dma = &dwmac4_dma_ops;
- if (*synopsys_id >= DWMAC_CORE_4_00)
+ if (*synopsys_id >= DWMAC_CORE_5_10)
+ mac->mac = &dwmac510_ops;
+ else if (*synopsys_id >= DWMAC_CORE_4_00)
mac->mac = &dwmac410_ops;
else
mac->mac = &dwmac4_ops;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
index c110f68..d37d457 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
@@ -373,6 +373,12 @@ static void dwmac4_get_hw_feature(void __iomem *ioaddr,
/* IEEE 1588-2002 */
dma_cap->time_stamp = 0;
+
+ /* MAC HW feature3 */
+ hw_cap = readl(ioaddr + GMAC_HW_FEATURE3);
+
+ /* 5.10 Features */
+ dma_cap->asp = (hw_cap & GMAC_HW_FEAT_ASP) >> 28;
}
/* Enable/disable TSO feature and set MSS */ diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
new file mode 100644
index 0000000..f751cd8
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
@@ -0,0 +1,242 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT) // Copyright (c) 2017
+Synopsys, Inc. and/or its affiliates.
+// stmmac Support for 5.xx Ethernet QoS cores
+
+#include <linux/bitops.h>
+#include <linux/iopoll.h>
+#include "common.h"
+#include "dwmac4.h"
+#include "dwmac5.h"
+
+static void dwmac5_log_error(struct net_device *ndev, u32 value, bool corr,
+ const char *module_name, const char **errors_str) {
+ unsigned long loc, mask;
+
+ mask = value;
+ for_each_set_bit(loc, &mask, 32) {
+ netdev_err(ndev, "Found %s error in %s: '%s'\n", corr ?
+ "correctable" : "uncorrectable", module_name,
+ errors_str[loc]);
+ }
+}
+
+static const char *dwmac5_mac_errors[32] = {
+ "ATPES: Application Transmit Interface Parity Check Error",
+ "TPES: TSO Data Path Parity Check Error",
+ "RDPES: Read Descriptor Parity Check Error",
+ "MPES: MTL Data Path Parity Check Error",
+ "MTSPES: MTL TX Status Data Path Parity Check Error",
+ "ARPES: Application Receive Interface Data Path Parity Check Error",
+ "CWPES: CSR Write Data Path Parity Check Error",
+ "ASRPES: AXI Slave Read Data Path Parity Check Error",
+ "TTES: TX FSM Timeout Error",
+ "RTES: RX FSM Timeout Error",
+ "CTES: CSR FSM Timeout Error",
+ "ATES: APP FSM Timeout Error",
+ "PTES: PTP FSM Timeout Error",
+ "T125ES: TX125 FSM Timeout Error",
+ "R125ES: RX125 FSM Timeout Error",
+ "RVCTES: REV MDC FSM Timeout Error",
+ "MSTTES: Master Read/Write Timeout Error",
+ "SLVTES: Slave Read/Write Timeout Error",
+ "ATITES: Application Timeout on ATI Interface Error",
+ "ARITES: Application Timeout on ARI Interface Error",
+ "Unknown Error", /* 20 */
+ "Unknown Error", /* 21 */
+ "Unknown Error", /* 22 */
+ "Unknown Error", /* 23 */
+ "FSMPES: FSM State Parity Error",
+ "Unknown Error", /* 25 */
+ "Unknown Error", /* 26 */
+ "Unknown Error", /* 27 */
+ "Unknown Error", /* 28 */
+ "Unknown Error", /* 29 */
+ "Unknown Error", /* 30 */
+ "Unknown Error", /* 31 */
+};
+
+static bool dwmac5_handle_mac_err(struct net_device *ndev,
+ void __iomem *ioaddr, bool correctable) {
+ u32 value;
+
+ value = readl(ioaddr + MAC_DPP_FSM_INT_STATUS);
+ writel(value, ioaddr + MAC_DPP_FSM_INT_STATUS);
+
+ dwmac5_log_error(ndev, value, correctable, "MAC", dwmac5_mac_errors);
+ return !correctable;
+}
+
+static const char *dwmac5_mtl_errors[32] = {
+ "TXCES: MTL TX Memory Error",
+ "TXAMS: MTL TX Memory Address Mismatch Error",
+ "TXUES: MTL TX Memory Error",
+ "Unknown Error", /* 3 */
+ "RXCES: MTL RX Memory Error",
+ "RXAMS: MTL RX Memory Address Mismatch Error",
+ "RXUES: MTL RX Memory Error",
+ "Unknown Error", /* 7 */
+ "ECES: MTL EST Memory Error",
+ "EAMS: MTL EST Memory Address Mismatch Error",
+ "EUES: MTL EST Memory Error",
+ "Unknown Error", /* 11 */
+ "RPCES: MTL RX Parser Memory Error",
+ "RPAMS: MTL RX Parser Memory Address Mismatch Error",
+ "RPUES: MTL RX Parser Memory Error",
+ "Unknown Error", /* 15 */
+ "Unknown Error", /* 16 */
+ "Unknown Error", /* 17 */
+ "Unknown Error", /* 18 */
+ "Unknown Error", /* 19 */
+ "Unknown Error", /* 20 */
+ "Unknown Error", /* 21 */
+ "Unknown Error", /* 22 */
+ "Unknown Error", /* 23 */
+ "Unknown Error", /* 24 */
+ "Unknown Error", /* 25 */
+ "Unknown Error", /* 26 */
+ "Unknown Error", /* 27 */
+ "Unknown Error", /* 28 */
+ "Unknown Error", /* 29 */
+ "Unknown Error", /* 30 */
+ "Unknown Error", /* 31 */
+};
+
+static bool dwmac5_handle_mtl_err(struct net_device *ndev,
+ void __iomem *ioaddr, bool correctable) {
+ u32 value;
+
+ value = readl(ioaddr + MTL_ECC_INT_STATUS);
+ writel(value, ioaddr + MTL_ECC_INT_STATUS);
+
+ dwmac5_log_error(ndev, value, correctable, "MTL", dwmac5_mtl_errors);
+ return !correctable;
+}
+
+static const char *dwmac5_dma_errors[32] = {
+ "TCES: DMA TSO Memory Error",
+ "TAMS: DMA TSO Memory Address Mismatch Error",
+ "TUES: DMA TSO Memory Error",
+ "Unknown Error", /* 3 */
+ "Unknown Error", /* 4 */
+ "Unknown Error", /* 5 */
+ "Unknown Error", /* 6 */
+ "Unknown Error", /* 7 */
+ "Unknown Error", /* 8 */
+ "Unknown Error", /* 9 */
+ "Unknown Error", /* 10 */
+ "Unknown Error", /* 11 */
+ "Unknown Error", /* 12 */
+ "Unknown Error", /* 13 */
+ "Unknown Error", /* 14 */
+ "Unknown Error", /* 15 */
+ "Unknown Error", /* 16 */
+ "Unknown Error", /* 17 */
+ "Unknown Error", /* 18 */
+ "Unknown Error", /* 19 */
+ "Unknown Error", /* 20 */
+ "Unknown Error", /* 21 */
+ "Unknown Error", /* 22 */
+ "Unknown Error", /* 23 */
+ "Unknown Error", /* 24 */
+ "Unknown Error", /* 25 */
+ "Unknown Error", /* 26 */
+ "Unknown Error", /* 27 */
+ "Unknown Error", /* 28 */
+ "Unknown Error", /* 29 */
+ "Unknown Error", /* 30 */
+ "Unknown Error", /* 31 */
+};
+
+static bool dwmac5_handle_dma_err(struct net_device *ndev,
+ void __iomem *ioaddr, bool correctable) {
+ u32 value;
+
+ value = readl(ioaddr + DMA_ECC_INT_STATUS);
+ writel(value, ioaddr + DMA_ECC_INT_STATUS);
+
+ dwmac5_log_error(ndev, value, correctable, "DMA", dwmac5_dma_errors);
+ return !correctable;
+}
+
+int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp) {
+ u32 value;
+
+ if (!asp)
+ return -EINVAL;
+
+ /* 1. Enable Safety Features */
+ value = readl(ioaddr + MTL_ECC_CONTROL);
+ value |= TSOEE; /* TSO ECC */
+ value |= MRXPEE; /* MTL RX Parser ECC */
+ value |= MESTEE; /* MTL EST ECC */
+ value |= MRXEE; /* MTL RX FIFO ECC */
+ value |= MTXEE; /* MTL TX FIFO ECC */
+ writel(value, ioaddr + MTL_ECC_CONTROL);
+
+ /* 2. Enable MTL Safety Interrupts */
+ value = readl(ioaddr + MTL_ECC_INT_ENABLE);
+ value |= RPCEIE; /* RX Parser Memory Correctable Error */
+ value |= ECEIE; /* EST Memory Correctable Error */
+ value |= RXCEIE; /* RX Memory Correctable Error */
+ value |= TXCEIE; /* TX Memory Correctable Error */
+ writel(value, ioaddr + MTL_ECC_INT_ENABLE);
+
+ /* 3. Enable DMA Safety Interrupts */
+ value = readl(ioaddr + DMA_ECC_INT_ENABLE);
+ value |= TCEIE; /* TSO Memory Correctable Error */
+ writel(value, ioaddr + DMA_ECC_INT_ENABLE);
+
+ /* Only ECC Protection for External Memory feature is selected */
+ if (asp <= 0x1)
+ return 0;
+
+ /* 5. Enable Parity and Timeout for FSM */
+ value = readl(ioaddr + MAC_FSM_CONTROL);
+ value |= PRTYEN; /* FSM Parity Feature */
+ value |= TMOUTEN; /* FSM Timeout Feature */
+ writel(value, ioaddr + MAC_FSM_CONTROL);
+
+ /* 4. Enable Data Parity Protection */
+ value = readl(ioaddr + MTL_DPP_CONTROL);
+ value |= EDPP;
+ writel(value, ioaddr + MTL_DPP_CONTROL);
+
+ /*
+ * All the Automotive Safety features are selected without the "Parity
+ * Port Enable for external interface" feature.
+ */
+ if (asp <= 0x2)
+ return 0;
+
+ value |= EPSI;
+ writel(value, ioaddr + MTL_DPP_CONTROL);
+ return 0;
+}
+
+bool dwmac5_safety_feat_irq_status(struct net_device *ndev,
+ void __iomem *ioaddr, unsigned int asp) {
+ bool ret = false;
+ u32 mtl, dma;
+
+ if (!asp)
+ return false;
+
+ mtl = readl(ioaddr + MTL_SAFETY_INT_STATUS);
+ dma = readl(ioaddr + DMA_SAFETY_INT_STATUS);
+
+ if ((mtl & MCSIS) || (dma & MCSIS))
+ ret |= dwmac5_handle_mac_err(ndev, ioaddr, false);
+ if ((mtl & (MEUIS | MECIS)) || (dma & (MSUIS | MSCIS)))
+ ret |= dwmac5_handle_mtl_err(ndev, ioaddr,
+ (mtl & MECIS) || (dma & MSCIS));
+ if (dma & (DEUIS | DECIS))
+ ret |= dwmac5_handle_dma_err(ndev, ioaddr, dma & DECIS);
+
+ return ret;
+}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h
new file mode 100644
index 0000000..debbb8a
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT) // Copyright (c) 2017
+Synopsys, Inc. and/or its affiliates.
+// stmmac Support for 5.xx Ethernet QoS cores
+
+#ifndef __DWMAC5_H__
+#define __DWMAC5_H__
+
+#define MAC_DPP_FSM_INT_STATUS 0x00000140
+#define MAC_AXI_SLV_DPE_ADDR_STATUS 0x00000144
+#define MAC_FSM_CONTROL 0x00000148
+#define PRTYEN BIT(1)
+#define TMOUTEN BIT(0)
+
+#define MTL_ECC_CONTROL 0x00000cc0
+#define TSOEE BIT(4)
+#define MRXPEE BIT(3)
+#define MESTEE BIT(2)
+#define MRXEE BIT(1)
+#define MTXEE BIT(0)
+
+#define MTL_SAFETY_INT_STATUS 0x00000cc4
+#define MCSIS BIT(31)
+#define MEUIS BIT(1)
+#define MECIS BIT(0)
+#define MTL_ECC_INT_ENABLE 0x00000cc8
+#define RPCEIE BIT(12)
+#define ECEIE BIT(8)
+#define RXCEIE BIT(4)
+#define TXCEIE BIT(0)
+#define MTL_ECC_INT_STATUS 0x00000ccc
+#define MTL_DPP_CONTROL 0x00000ce0
+#define EPSI BIT(2)
+#define OPE BIT(1)
+#define EDPP BIT(0)
+
+#define DMA_SAFETY_INT_STATUS 0x00001080
+#define MSUIS BIT(29)
+#define MSCIS BIT(28)
+#define DEUIS BIT(1)
+#define DECIS BIT(0)
+#define DMA_ECC_INT_ENABLE 0x00001084
+#define TCEIE BIT(0)
+#define DMA_ECC_INT_STATUS 0x00001088
+
+int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp);
+bool dwmac5_safety_feat_irq_status(struct net_device *ndev,
+ void __iomem *ioaddr, unsigned int asp);
+
+#endif /* __DWMAC5_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c84c24f..97ab4ca 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -205,6 +205,7 @@ static void stmmac_service_event_schedule(struct stmmac_priv *priv)
static void stmmac_global_err(struct stmmac_priv *priv) {
+ netif_carrier_off(priv->dev);
set_bit(STMMAC_RESET_REQUESTED, &priv->state);
stmmac_service_event_schedule(priv);
}
@@ -2006,6 +2007,22 @@ static void stmmac_set_dma_operation_mode(struct stmmac_priv *priv, u32 txmode,
}
}
+static bool stmmac_safety_feat_interrupt(struct stmmac_priv *priv) {
+ bool ret = false;
+
+ /* Safety features are only available in cores >= 5.10 */
+ if (priv->synopsys_id < DWMAC_CORE_5_10)
+ return ret;
+ if (priv->hw->mac->safety_feat_irq_status)
+ ret = priv->hw->mac->safety_feat_irq_status(priv->dev,
+ priv->ioaddr, priv->dma_cap.asp);
+
+ if (ret)
+ stmmac_global_err(priv);
+ return ret;
+}
+
/**
* stmmac_dma_interrupt - DMA ISR
* @priv: driver private structure
@@ -2495,6 +2512,17 @@ static void stmmac_mtl_configuration(struct stmmac_priv *priv)
stmmac_mac_config_rx_queues_routing(priv);
}
+static void stmmac_safety_feat_configuration(struct stmmac_priv *priv)
+{
+ if (priv->hw->mac->safety_feat_config && priv->dma_cap.asp) {
+ netdev_info(priv->dev, "Enabling Safety Features\n");
+ priv->hw->mac->safety_feat_config(priv->ioaddr,
+ priv->dma_cap.asp);
+ } else {
+ netdev_info(priv->dev, "No Safety Features support found\n");
+ }
+}
+
/**
* stmmac_hw_setup - setup mac in a usable state.
* @dev : pointer to the device structure.
@@ -2546,6 +2574,10 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
if (priv->synopsys_id >= DWMAC_CORE_4_00)
stmmac_mtl_configuration(priv);
+ /* Initialize Safety Features */
+ if (priv->synopsys_id >= DWMAC_CORE_5_10)
+ stmmac_safety_feat_configuration(priv);
+
ret = priv->hw->mac->rx_ipc(priv->hw);
if (!ret) {
netdev_warn(priv->dev, "RX IPC Checksum Offload disabled\n"); @@ -3713,6 +3745,9 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
/* Check if adapter is up */
if (test_bit(STMMAC_DOWN, &priv->state))
return IRQ_HANDLED;
+ /* Check if a fatal error happened */
+ if (stmmac_safety_feat_interrupt(priv))
+ return IRQ_HANDLED;
/* To handle GMAC own interrupts */
if ((priv->plat->has_gmac) || (priv->plat->has_gmac4)) {
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
2018-02-01 14:44 ` Joao Pinto
@ 2018-02-01 15:02 ` Andrew Lunn
2018-02-01 15:09 ` David Miller
2018-02-01 15:18 ` Jose Abreu
0 siblings, 2 replies; 9+ messages in thread
From: Andrew Lunn @ 2018-02-01 15:02 UTC (permalink / raw)
To: Joao Pinto
Cc: Jose Abreu, netdev@vger.kernel.org, David S. Miller,
Giuseppe Cavallaro, Alexandre Torgue
> +static void dwmac5_log_error(struct net_device *ndev, u32 value, bool corr,
> + const char *module_name, const char **errors_str) {
> + unsigned long loc, mask;
> +
> + mask = value;
> + for_each_set_bit(loc, &mask, 32) {
> + netdev_err(ndev, "Found %s error in %s: '%s'\n", corr ?
> + "correctable" : "uncorrectable", module_name,
> + errors_str[loc]);
> + }
> +}
How about also adding ethtool -S stats. You have a text string, so all
you need to add is a counter. And i expect statistics are looked at
more than dmesg output.
> +
> +static bool dwmac5_handle_mac_err(struct net_device *ndev,
> + void __iomem *ioaddr, bool correctable) {
> + u32 value;
> +
> + value = readl(ioaddr + MAC_DPP_FSM_INT_STATUS);
> + writel(value, ioaddr + MAC_DPP_FSM_INT_STATUS);
> +
> + dwmac5_log_error(ndev, value, correctable, "MAC", dwmac5_mac_errors);
> + return !correctable;
> +}
Returning !correctable in all these functions seems pointless. None
of the handlers change its value. So just make these void functions.
> static void stmmac_global_err(struct stmmac_priv *priv) {
> + netif_carrier_off(priv->dev);
> set_bit(STMMAC_RESET_REQUESTED, &priv->state);
> stmmac_service_event_schedule(priv);
> }
This should be in a separate patch, with an explanation why it is
needed.
Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
2018-02-01 15:02 ` Andrew Lunn
@ 2018-02-01 15:09 ` David Miller
2018-02-01 15:26 ` Jose Abreu
2018-02-01 15:18 ` Jose Abreu
1 sibling, 1 reply; 9+ messages in thread
From: David Miller @ 2018-02-01 15:09 UTC (permalink / raw)
To: andrew; +Cc: Joao.Pinto, Jose.Abreu, netdev, peppe.cavallaro, alexandre.torgue
From: Andrew Lunn <andrew@lunn.ch>
Date: Thu, 1 Feb 2018 16:02:09 +0100
>> +static void dwmac5_log_error(struct net_device *ndev, u32 value, bool corr,
>> + const char *module_name, const char **errors_str) {
>> + unsigned long loc, mask;
>> +
>> + mask = value;
>> + for_each_set_bit(loc, &mask, 32) {
>> + netdev_err(ndev, "Found %s error in %s: '%s'\n", corr ?
>> + "correctable" : "uncorrectable", module_name,
>> + errors_str[loc]);
>> + }
>> +}
>
> How about also adding ethtool -S stats. You have a text string, so all
> you need to add is a counter. And i expect statistics are looked at
> more than dmesg output.
I agree. Perhaps for extremely catastrophic errors (those which
require a complete chip reset, for example), statistics are really the
way to go.
Also, all of these functions are not style properly. The openning
curly braces of a function belong on a separate line of their own, not
at the end of the arguments.
The braces for structure assignment blocks have a similar problem,
the final closing brace and semicolon should be on a line by itself.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
2018-02-01 15:02 ` Andrew Lunn
2018-02-01 15:09 ` David Miller
@ 2018-02-01 15:18 ` Jose Abreu
1 sibling, 0 replies; 9+ messages in thread
From: Jose Abreu @ 2018-02-01 15:18 UTC (permalink / raw)
To: Andrew Lunn, Joao Pinto
Cc: Jose Abreu, netdev@vger.kernel.org, David S. Miller,
Giuseppe Cavallaro, Alexandre Torgue
Hi Andrew,
On 01-02-2018 15:02, Andrew Lunn wrote:
>> +static void dwmac5_log_error(struct net_device *ndev, u32 value, bool corr,
>> + const char *module_name, const char **errors_str) {
>> + unsigned long loc, mask;
>> +
>> + mask = value;
>> + for_each_set_bit(loc, &mask, 32) {
>> + netdev_err(ndev, "Found %s error in %s: '%s'\n", corr ?
>> + "correctable" : "uncorrectable", module_name,
>> + errors_str[loc]);
>> + }
>> +}
> How about also adding ethtool -S stats. You have a text string, so all
> you need to add is a counter. And i expect statistics are looked at
> more than dmesg output.
Yes, I will add.
>
>> +
>> +static bool dwmac5_handle_mac_err(struct net_device *ndev,
>> + void __iomem *ioaddr, bool correctable) {
>> + u32 value;
>> +
>> + value = readl(ioaddr + MAC_DPP_FSM_INT_STATUS);
>> + writel(value, ioaddr + MAC_DPP_FSM_INT_STATUS);
>> +
>> + dwmac5_log_error(ndev, value, correctable, "MAC", dwmac5_mac_errors);
>> + return !correctable;
>> +}
> Returning !correctable in all these functions seems pointless. None
> of the handlers change its value. So just make these void functions.
Ok.
>
>> static void stmmac_global_err(struct stmmac_priv *priv) {
>> + netif_carrier_off(priv->dev);
>> set_bit(STMMAC_RESET_REQUESTED, &priv->state);
>> stmmac_service_event_schedule(priv);
>> }
> This should be in a separate patch, with an explanation why it is
> needed.
Yes it should belong in the first patch of this series.
Best Regards,
Jose Miguel Abreu
>
> Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
2018-02-01 15:09 ` David Miller
@ 2018-02-01 15:26 ` Jose Abreu
2018-02-01 15:33 ` David Miller
0 siblings, 1 reply; 9+ messages in thread
From: Jose Abreu @ 2018-02-01 15:26 UTC (permalink / raw)
To: David Miller, andrew
Cc: Joao.Pinto, Jose.Abreu, netdev, peppe.cavallaro, alexandre.torgue
Hi David,
On 01-02-2018 15:09, David Miller wrote:
> From: Andrew Lunn <andrew@lunn.ch>
> Date: Thu, 1 Feb 2018 16:02:09 +0100
>
>>> +static void dwmac5_log_error(struct net_device *ndev, u32 value, bool corr,
>>> + const char *module_name, const char **errors_str) {
>>> + unsigned long loc, mask;
>>> +
>>> + mask = value;
>>> + for_each_set_bit(loc, &mask, 32) {
>>> + netdev_err(ndev, "Found %s error in %s: '%s'\n", corr ?
>>> + "correctable" : "uncorrectable", module_name,
>>> + errors_str[loc]);
>>> + }
>>> +}
>> How about also adding ethtool -S stats. You have a text string, so all
>> you need to add is a counter. And i expect statistics are looked at
>> more than dmesg output.
> I agree. Perhaps for extremely catastrophic errors (those which
> require a complete chip reset, for example), statistics are really the
> way to go.
>
> Also, all of these functions are not style properly. The openning
> curly braces of a function belong on a separate line of their own, not
> at the end of the arguments.
Hmm, I have that locally and in the raw .patch file ... Maybe
there is something wrong with my git send-email?
>
> The braces for structure assignment blocks have a similar problem,
> the final closing brace and semicolon should be on a line by itself.
And I also have that ...
Best Regards,
Jose Miguel Abreu
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features
2018-02-01 15:26 ` Jose Abreu
@ 2018-02-01 15:33 ` David Miller
0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2018-02-01 15:33 UTC (permalink / raw)
To: Jose.Abreu; +Cc: andrew, Joao.Pinto, netdev, peppe.cavallaro, alexandre.torgue
From: Jose Abreu <Jose.Abreu@synopsys.com>
Date: Thu, 1 Feb 2018 15:26:44 +0000
> Hmm, I have that locally and in the raw .patch file ... Maybe
> there is something wrong with my git send-email?
That's for you to figure out I suppose :-)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-02-01 15:33 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-01 14:41 [PATCH net-next 0/2] Fix TX Timeout and implement Safety Features Jose Abreu
2018-02-01 14:41 ` [PATCH net-next 1/2] net: stmmac: Rework and fix TX Timeout code Jose Abreu
2018-02-01 14:41 ` [PATCH net-next 2/2] net: stmmac: Add support for DWMAC5 and implement Safety Features Jose Abreu
2018-02-01 14:44 ` Joao Pinto
2018-02-01 15:02 ` Andrew Lunn
2018-02-01 15:09 ` David Miller
2018-02-01 15:26 ` Jose Abreu
2018-02-01 15:33 ` David Miller
2018-02-01 15:18 ` Jose Abreu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).