All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, linux-can@vger.kernel.org,
	kernel@pengutronix.de,
	Jeroen Hofstee <jhofstee@victronenergy.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH 25/33] can: ti_hecc: add fifo overflow error reporting
Date: Tue,  5 Nov 2019 17:32:07 +0100	[thread overview]
Message-ID: <20191105163215.30194-26-mkl@pengutronix.de> (raw)
In-Reply-To: <20191105163215.30194-1-mkl@pengutronix.de>

From: Jeroen Hofstee <jhofstee@victronenergy.com>

When the rx FIFO overflows the ti_hecc would silently drop them since
the overwrite protection is enabled for all mailboxes. So disable it for
the lowest priority mailbox and return a proper error value when receive
message lost is set. Drop the message itself in that case, since it
might be partially updated.

Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
Acked-by: Jeroen Hofstee <jhofstee@victronenergy.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/ti_hecc.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c
index 6ea29126c60b..b12fd0bd489d 100644
--- a/drivers/net/can/ti_hecc.c
+++ b/drivers/net/can/ti_hecc.c
@@ -73,6 +73,7 @@ MODULE_VERSION(HECC_MODULE_VERSION);
  */
 #define HECC_MAX_RX_MBOX	(HECC_MAX_MAILBOXES - HECC_MAX_TX_MBOX)
 #define HECC_RX_FIRST_MBOX	(HECC_MAX_MAILBOXES - 1)
+#define HECC_RX_LAST_MBOX	(HECC_MAX_TX_MBOX)
 
 /* TI HECC module registers */
 #define HECC_CANME		0x0	/* Mailbox enable */
@@ -82,7 +83,7 @@ MODULE_VERSION(HECC_MODULE_VERSION);
 #define HECC_CANTA		0x10	/* Transmission acknowledge */
 #define HECC_CANAA		0x14	/* Abort acknowledge */
 #define HECC_CANRMP		0x18	/* Receive message pending */
-#define HECC_CANRML		0x1C	/* Remote message lost */
+#define HECC_CANRML		0x1C	/* Receive message lost */
 #define HECC_CANRFP		0x20	/* Remote frame pending */
 #define HECC_CANGAM		0x24	/* SECC only:Global acceptance mask */
 #define HECC_CANMC		0x28	/* Master control */
@@ -385,8 +386,15 @@ static void ti_hecc_start(struct net_device *ndev)
 	/* Enable tx interrupts */
 	hecc_set_bit(priv, HECC_CANMIM, BIT(HECC_MAX_TX_MBOX) - 1);
 
-	/* Prevent message over-write & Enable interrupts */
-	hecc_write(priv, HECC_CANOPC, HECC_SET_REG);
+	/* Prevent message over-write to create a rx fifo, but not for
+	 * the lowest priority mailbox, since that allows detecting
+	 * overflows instead of the hardware silently dropping the
+	 * messages.
+	 */
+	mbx_mask = ~BIT(HECC_RX_LAST_MBOX);
+	hecc_write(priv, HECC_CANOPC, mbx_mask);
+
+	/* Enable interrupts */
 	if (priv->use_hecc1int) {
 		hecc_write(priv, HECC_CANMIL, HECC_SET_REG);
 		hecc_write(priv, HECC_CANGIM, HECC_CANGIM_DEF_MASK |
@@ -531,6 +539,7 @@ static unsigned int ti_hecc_mailbox_read(struct can_rx_offload *offload,
 {
 	struct ti_hecc_priv *priv = rx_offload_to_priv(offload);
 	u32 data, mbx_mask;
+	int ret = 1;
 
 	mbx_mask = BIT(mbxno);
 	data = hecc_read_mbx(priv, mbxno, HECC_CANMID);
@@ -552,9 +561,26 @@ static unsigned int ti_hecc_mailbox_read(struct can_rx_offload *offload,
 	}
 
 	*timestamp = hecc_read_stamp(priv, mbxno);
+
+	/* Check for FIFO overrun.
+	 *
+	 * All but the last RX mailbox have activated overwrite
+	 * protection. So skip check for overrun, if we're not
+	 * handling the last RX mailbox.
+	 *
+	 * As the overwrite protection for the last RX mailbox is
+	 * disabled, the CAN core might update while we're reading
+	 * it. This means the skb might be inconsistent.
+	 *
+	 * Return an error to let rx-offload discard this CAN frame.
+	 */
+	if (unlikely(mbxno == HECC_RX_LAST_MBOX &&
+		     hecc_read(priv, HECC_CANRML) & mbx_mask))
+		ret = -ENOBUFS;
+
 	hecc_write(priv, HECC_CANRMP, mbx_mask);
 
-	return 1;
+	return ret;
 }
 
 static int ti_hecc_error(struct net_device *ndev, int int_status,
@@ -884,7 +910,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
 
 	priv->offload.mailbox_read = ti_hecc_mailbox_read;
 	priv->offload.mb_first = HECC_RX_FIRST_MBOX;
-	priv->offload.mb_last = HECC_MAX_TX_MBOX;
+	priv->offload.mb_last = HECC_RX_LAST_MBOX;
 	err = can_rx_offload_add_timestamp(ndev, &priv->offload);
 	if (err) {
 		dev_err(&pdev->dev, "can_rx_offload_add_timestamp() failed\n");
-- 
2.24.0.rc1

  parent reply	other threads:[~2019-11-05 16:32 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05 16:31 pull-request: can 2019-11-05 Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 01/33] can: dev: add missing of_node_put() after calling of_get_child_by_name() Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 02/33] can: gs_usb: gs_can_open(): prevent memory leak Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 03/33] can: mcba_usb: fix use-after-free on disconnect Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 04/33] can: usb_8dev: " Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 05/33] can: flexcan: disable completely the ECC mechanism Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 06/33] can: peak_usb: fix a potential out-of-sync while decoding packets Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 07/33] can: peak_usb: fix slab info leak Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 08/33] can: peak_usb: report bus recovery as well Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 09/33] can: c_can: c_can_poll(): only read status register after status IRQ Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 10/33] can: c_can: D_CAN: c_can_chip_config(): perform a sofware reset on open Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 11/33] can: c_can: C_CAN: add bus recovery events Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 12/33] can: xilinx_can: Fix flags field initialization for axi can Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 13/33] can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem leak Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 14/33] can: rx-offload: can_rx_offload_queue_tail(): " Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 15/33] can: rx-offload: can_rx_offload_offload_one(): do not increase the skb_queue beyond skb_queue_len_max Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 16/33] can: rx-offload: can_rx_offload_offload_one(): increment rx_fifo_errors on queue overflow or OOM Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 17/33] can: rx-offload: can_rx_offload_offload_one(): use ERR_PTR() to propagate error value in case of errors Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 18/33] can: rx-offload: can_rx_offload_irq_offload_timestamp(): continue on error Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 19/33] can: rx-offload: can_rx_offload_irq_offload_fifo(): " Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 20/33] can: flexcan: increase error counters if skb enqueueing via can_rx_offload_queue_sorted() fails Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 21/33] can: ti_hecc: ti_hecc_error(): " Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 22/33] can: ti_hecc: ti_hecc_stop(): stop the CPK on down Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 23/33] can: ti_hecc: keep MIM and MD set Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 24/33] can: ti_hecc: release the mailbox a bit earlier Marc Kleine-Budde
2019-11-05 16:32 ` Marc Kleine-Budde [this message]
2019-11-05 16:32 ` [PATCH 26/33] can: ti_hecc: properly report state changes Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 27/33] can: ti_hecc: add missing " Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 28/33] can: j1939: fix resource leak of skb on error return paths Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 29/33] can: j1939: fix memory leak if filters was set Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 30/33] can: j1939: transport: j1939_session_fresh_new(): make sure EOMA is send with the total message size set Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 31/33] can: j1939: transport: j1939_xtp_rx_eoma_one(): Add sanity check for correct total message size Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 32/33] can: mcp251x: mcp251x_restart_work_handler(): Fix potential force_quit race condition Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 33/33] can: don't use deprecated license identifiers Marc Kleine-Budde
2019-11-05 21:30 ` pull-request: can 2019-11-05 David Miller
2019-11-05 21:36   ` Marc Kleine-Budde
2019-11-07  8:45 ` request: merge net/master into net-next/master Marc Kleine-Budde
2019-11-09 20:28   ` request: merge net/master into net-next/master,request: " David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191105163215.30194-26-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=jhofstee@victronenergy.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.