Commit 9a123496 authored by Reuben Dowle's avatar Reuben Dowle Committed by Marc Kleine-Budde

can: flexcan: Fix CAN_RAW_RECV_OWN_MSGS and CAN_RAW_LOOPBACK

Currently the flexcan driver uses hardware local echo. This blindly
echos all transmitted frames to all receiving sockets, regardless what
CAN_RAW_RECV_OWN_MSGS and CAN_RAW_LOOPBACK are set to.

This patch now submits transmitted frames to be echoed in the transmit
complete interrupt, preserving the reference to the sending
socket. This allows the can protocol to correctly handle the local
echo.

Further this patch moves tx_bytes statistic accounting into the tx_complete
handler.
Signed-off-by: default avatarReuben Dowle <reuben.dowle@navico.com>
[mkl: move tx_bytes accounting into tx_complete handler; cleanups]
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent cf5046b3
...@@ -269,7 +269,6 @@ static int flexcan_get_berr_counter(const struct net_device *dev, ...@@ -269,7 +269,6 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev) static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
const struct flexcan_priv *priv = netdev_priv(dev); const struct flexcan_priv *priv = netdev_priv(dev);
struct net_device_stats *stats = &dev->stats;
struct flexcan_regs __iomem *regs = priv->base; struct flexcan_regs __iomem *regs = priv->base;
struct can_frame *cf = (struct can_frame *)skb->data; struct can_frame *cf = (struct can_frame *)skb->data;
u32 can_id; u32 can_id;
...@@ -299,14 +298,11 @@ static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -299,14 +298,11 @@ static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
flexcan_write(data, &regs->cantxfg[FLEXCAN_TX_BUF_ID].data[1]); flexcan_write(data, &regs->cantxfg[FLEXCAN_TX_BUF_ID].data[1]);
} }
can_put_echo_skb(skb, dev, 0);
flexcan_write(can_id, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_id); flexcan_write(can_id, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_id);
flexcan_write(ctrl, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_ctrl); flexcan_write(ctrl, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_ctrl);
kfree_skb(skb);
/* tx_packets is incremented in flexcan_irq */
stats->tx_bytes += cf->can_dlc;
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
...@@ -609,7 +605,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id) ...@@ -609,7 +605,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
/* transmission complete interrupt */ /* transmission complete interrupt */
if (reg_iflag1 & (1 << FLEXCAN_TX_BUF_ID)) { if (reg_iflag1 & (1 << FLEXCAN_TX_BUF_ID)) {
/* tx_bytes is incremented in flexcan_start_xmit */ stats->tx_bytes += can_get_echo_skb(dev, 0);
stats->tx_packets++; stats->tx_packets++;
flexcan_write((1 << FLEXCAN_TX_BUF_ID), &regs->iflag1); flexcan_write((1 << FLEXCAN_TX_BUF_ID), &regs->iflag1);
netif_wake_queue(dev); netif_wake_queue(dev);
...@@ -697,12 +693,13 @@ static int flexcan_chip_start(struct net_device *dev) ...@@ -697,12 +693,13 @@ static int flexcan_chip_start(struct net_device *dev)
* only supervisor access * only supervisor access
* enable warning int * enable warning int
* choose format C * choose format C
* disable local echo
* *
*/ */
reg_mcr = flexcan_read(&regs->mcr); reg_mcr = flexcan_read(&regs->mcr);
reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_FEN | FLEXCAN_MCR_HALT | reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_FEN | FLEXCAN_MCR_HALT |
FLEXCAN_MCR_SUPV | FLEXCAN_MCR_WRN_EN | FLEXCAN_MCR_SUPV | FLEXCAN_MCR_WRN_EN |
FLEXCAN_MCR_IDAM_C; FLEXCAN_MCR_IDAM_C | FLEXCAN_MCR_SRX_DIS;
dev_dbg(dev->dev.parent, "%s: writing mcr=0x%08x", __func__, reg_mcr); dev_dbg(dev->dev.parent, "%s: writing mcr=0x%08x", __func__, reg_mcr);
flexcan_write(reg_mcr, &regs->mcr); flexcan_write(reg_mcr, &regs->mcr);
...@@ -970,7 +967,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev) ...@@ -970,7 +967,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
goto failed_map; goto failed_map;
} }
dev = alloc_candev(sizeof(struct flexcan_priv), 0); dev = alloc_candev(sizeof(struct flexcan_priv), 1);
if (!dev) { if (!dev) {
err = -ENOMEM; err = -ENOMEM;
goto failed_alloc; goto failed_alloc;
...@@ -978,7 +975,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev) ...@@ -978,7 +975,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
dev->netdev_ops = &flexcan_netdev_ops; dev->netdev_ops = &flexcan_netdev_ops;
dev->irq = irq; dev->irq = irq;
dev->flags |= IFF_ECHO; /* we support local echo in hardware */ dev->flags |= IFF_ECHO;
priv = netdev_priv(dev); priv = netdev_priv(dev);
priv->can.clock.freq = clock_freq; priv->can.clock.freq = clock_freq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment