Skip to contentSkip to conversation

net, can, ifi: fix "write buffer full" error

PATCH Applied Heiko Schocher 3 participants 6 messages Feb 8, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 net, can, ifi: fix "write buffer full" error

the driver reads in the ISR first the IRQpending register, and clears after that in a write *all* bits in it.

It could happen that the isr register raise bits between this 2 register accesses, which leads in lost bits ...

In case it clears "TX message sent successfully", the driver never sends any Tx data, and buffers to userspace run over.

Fixed this:
clear only the bits in the IRQpending register, the driver had read.

---

Changes in v2:
- add Reviewed-by from Marek

 drivers/net/can/ifi_canfd/ifi_canfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/ifi_canfd/ifi_canfd.c +1 -1
index 2772d05ff11c..05feb8177936 100644
@@ -607,7 +607,7 @@ static irqreturn_t ifi_canfd_isr(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	/* Clear all pending interrupts but ErrWarn */
-	writel(clr_irq_mask, priv->base + IFI_CANFD_INTERRUPT);
+	writel(isr & clr_irq_mask, priv->base + IFI_CANFD_INTERRUPT);
 
 	/* RX IRQ or bus warning, start NAPI */
 	if (isr & rx_irq_mask) {
Signature · 1 line
2.14.3
#1 lore raw

PATCH v2 2/2 net, can, ifi: loopback Tx message in IFI block

Current ifi driver reads first Rx messages, than loopback the Tx message, if the IFI_CANFD_INTERRUPT_TXFIFO_REMOVE bit is set. This can lead into the case, that Rx messages overhelm Tx messages!

Fixed this in the following way:

Set in the IFI_CANFD_TXFIFO_DLC register the FN value to 1, so the IFI block loopsback itself the Tx message when sended correctly on the canfd bus. Only the IFI block can insert the Tx message in the correct place.

The linux driver now needs only to free the skb, when the Tx message was sended correctly.

---

Changes in v2:
- add Reviewed-by from Marek, fixed comment into one liner

 drivers/net/can/ifi_canfd/ifi_canfd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/can/ifi_canfd/ifi_canfd.c +8 -1
index 05feb8177936..ee74ee8f9b38 100644
@@ -211,6 +211,7 @@ struct ifi_canfd_priv {
 	struct napi_struct	napi;
 	struct net_device	*ndev;
 	void __iomem		*base;
+	unsigned int		tx_len;
 };
 
 static void ifi_canfd_irq_enable(struct net_device *ndev, bool enable)
@@ -617,8 +618,10 @@ static irqreturn_t ifi_canfd_isr(int irq, void *dev_id)
 
 	/* TX IRQ */
 	if (isr & IFI_CANFD_INTERRUPT_TXFIFO_REMOVE) {
-		stats->tx_bytes += can_get_echo_skb(ndev, 0);
+		can_free_echo_skb(ndev, 0);
+		stats->tx_bytes += priv->tx_len;
 		stats->tx_packets++;
+		priv->tx_len = 0;
 		can_led_event(ndev, CAN_LED_EVENT_TX);
 	}
 
@@ -889,6 +892,7 @@ static netdev_tx_t ifi_canfd_start_xmit(struct sk_buff *skb,
 	}
 
 	txdlc = can_len2dlc(cf->len);
+	priv->tx_len = txdlc;
 	if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) && can_is_canfd_skb(skb)) {
 		txdlc |= IFI_CANFD_TXFIFO_DLC_EDL;
 		if (cf->flags & CANFD_BRS)
@@ -898,6 +902,9 @@ static netdev_tx_t ifi_canfd_start_xmit(struct sk_buff *skb,
 	if (cf->can_id & CAN_RTR_FLAG)
 		txdlc |= IFI_CANFD_TXFIFO_DLC_RTR;
 
+	/* set FNR to 1, so we get our Tx Message looped back into RxFIFO */
+	txdlc += (1 << IFI_CANFD_TXFIFO_DLC_FNR_OFFSET);
+
 	/* message ram configuration */
 	writel(txid, priv->base + IFI_CANFD_TXFIFO_ID);
 	writel(txdlc, priv->base + IFI_CANFD_TXFIFO_DLC);
Signature · 1 line
2.14.3
maintainer Applied
#2 lore raw
In reply to Heiko Schocher
Quoted 9 lines · Heiko Schocher

the driver reads in the ISR first the IRQpending register, and clears after that in a write *all* bits in it.

It could happen that the isr register raise bits between this 2 register accesses, which leads in lost bits ...

In case it clears "TX message sent successfully", the driver never sends any Tx data, and buffers to userspace run over.

Quoted 6 lines

Fixed this:
clear only the bits in the IRQpending register, the driver had read.

Applied both to linux-can.

Tnx,
Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#3 lore raw
Quoted 10 lines · Marc Kleine-Budde
Quoted 9 lines · Heiko Schocher

the driver reads in the ISR first the IRQpending register, and clears after that in a write *all* bits in it.

It could happen that the isr register raise bits between this 2 register accesses, which leads in lost bits ...

In case it clears "TX message sent successfully", the driver never sends any Tx data, and buffers to userspace run over.

Quoted 8 lines
Quoted 6 lines

Fixed this:
clear only the bits in the IRQpending register, the driver had read.

Applied both to linux-can.

Can you also apply them to stable, so they get into 4.9.x etc ?

Thanks!

Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw
Quoted 15 lines · Marek Vasut
Quoted 14 lines · Marc Kleine-Budde
Quoted 13 lines · Heiko Schocher

the driver reads in the ISR first the IRQpending register, and clears after that in a write *all* bits in it.

It could happen that the isr register raise bits between this 2 register accesses, which leads in lost bits ...

In case it clears "TX message sent successfully", the driver never sends any Tx data, and buffers to userspace run over.

Fixed this:
clear only the bits in the IRQpending register, the driver had read.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Applied both to linux-can.

Can you also apply them to stable, so they get into 4.9.x etc ?

I've already added stable on Cc, so they will be picked up by the stable maintainers.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#5 lore raw
Quoted 19 lines · Marc Kleine-Budde
Quoted 18 lines · Marek Vasut
Quoted 17 lines · Marc Kleine-Budde
Quoted 15 lines · Heiko Schocher

the driver reads in the ISR first the IRQpending register, and clears after that in a write *all* bits in it.

It could happen that the isr register raise bits between this 2 register accesses, which leads in lost bits ...

In case it clears "TX message sent successfully", the driver never sends any Tx data, and buffers to userspace run over.

Fixed this:
clear only the bits in the IRQpending register, the driver had read.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Applied both to linux-can.

Can you also apply them to stable, so they get into 4.9.x etc ?

I've already added stable on Cc, so they will be picked up by the stable maintainers.

Thanks!

Signature · 2 lines
Best regards,
Marek Vasut