Re: pull-request: can-next 2018-11-28,pull-request: can-next 2018-11-28

2018-11-28 Thread Marc Kleine-Budde
On 11/28/18 8:21 PM, David Miller wrote:
> From: Marc Kleine-Budde 
> Date: Wed, 28 Nov 2018 17:01:13 +0100
> 
>>   
>> ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git
>>  tags/linux-can-next-for-4.21-20181128
> 
> This doesn't work for me at all.
> 
> I'm not adding a custom .ssh config entry to point gitolite.kernel.org
> to the same SSH key that I use for gitol...@ra.kernel.org, no way.
> 
> I don't want to see these SSH based URLs any more, they are a pain and
> add overhead to my workflow.

Ok, I've adjusted my scripts.

> Please just use plain git:// URLs, thank you.

Done, here's the pull request with the git:// URL:

---

This is a pull request for net-next/master consisting of 18 patches.

The first patch is by Colin Ian King and fixes the spelling in the ucan
driver.

The next three patches target the xilinx driver. YueHaibing's patch
fixes the return type of ndo_start_xmit function. Two patches by
Shubhrajyoti Datta add support for the CAN FD 2.0 controllers.

Flavio Suligoi's patch for the sja1000 driver add support for the ASEM
CAN raw hardware.

Wolfram Sang's and Kuninori Morimoto's patches switch the rcar driver to
use SPDX license identifiers.

The remaining 111 patches improve the flexcan driver. Pankaj Bansal's
patch enables the driver in Kconfig on all architectures with IOMEM
support. The next four patches by me fix indention, add missing
parentheses and comments. Aisheng Dong's patches add self wake support
and document it in the DT bindings. The remaining patches by Pankaj
Bansal first fix the loopback support and prepare the driver for the
CAN-FD support needed for the LX2160A SoC. The actual CAN-FD support
will be added in a later patch series.

regards,
Marc

---

The following changes since commit 86d1d8b72caf648e5b14ac274f9afeaab58bbae1:

  net/ipv4: Fix missing raw_init when CONFIG_PROC_FS is disabled (2018-11-27 
20:58:02 -0800)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git 
tags/linux-can-next-for-4.21-20181128

for you to fetch changes up to 6cbf76028dcac01129211828d62314285231f79e:

  can: flexcan: split the Message Buffer RAM area (2018-11-28 16:52:25 +0100)


linux-can-next-for-4.21-20181128


Aisheng Dong (2):
  dt-bindings: can: flexcan: add stop mode property to device tree
  can: flexcan: add self wakeup support

Colin Ian King (1):
  can: ucan: fix spelling mistake: "resumbmitting" -> "resubmitting"

Flavio Suligoi (1):
  can: sja1000: plx_pci: add support for ASEM CAN raw device

Kuninori Morimoto (1):
      can: rcar: add SPDX identifiers to Kconfig and Makefile

Marc Kleine-Budde (4):
  can: flexcan: flexcan_start_xmit(): fix indention
  can: flexcan: flexcan_irq(): fix indention
  can: flexcan: FLEXCAN_IFLAG_MB: add () around macro argument
  can: flexcan: flexcan_chip_start(): adjust comment to match the code

Pankaj Bansal (5):
  can: flexcan: enable flexcan for all architectures
  can: flexcan: flexcan_chip_start(): enable loopback mode in flexcan
  can: flexcan: move rx_offload_add() from flexcan_probe() to flexcan_open()
  can: flexcan: Add provision for variable payload size
  can: flexcan: split the Message Buffer RAM area

Shubhrajyoti Datta (2):
  dt-bindings: can: xilinx_can: add Xilinx CAN FD 2.0 bindings
  can: xilinx: add can 2.0 support

Wolfram Sang (1):
  can: rcar: use SPDX identifier for Renesas drivers

YueHaibing (1):
  can: xilinx: fix return type of ndo_start_xmit function

 .../devicetree/bindings/net/can/fsl-flexcan.txt|   8 +
 .../devicetree/bindings/net/can/xilinx_can.txt |   1 +
 drivers/net/can/Kconfig|   2 +-
 drivers/net/can/flexcan.c  | 365 -
 drivers/net/can/rcar/Kconfig   |   1 +
 drivers/net/can/rcar/Makefile  |   1 +
 drivers/net/can/rcar/rcar_can.c|   6 +-
 drivers/net/can/rcar/rcar_canfd.c  |   6 +-
 drivers/net/can/sja1000/Kconfig|   1 +
 drivers/net/can/sja1000/plx_pci.c  |  65 +++-
 drivers/net/can/usb/ucan.c |   2 +-
 drivers/net/can/xilinx_can.c   |  36 +-
 12 files changed, 402 insertions(+), 92 deletions(-)

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


pull-request: can-next 2018-11-28

2018-11-28 Thread Marc Kleine-Budde
Hello David,

this is a pull request for net-next/master consisting of 18 patches.

The first patch is by Colin Ian King and fixes the spelling in the ucan
driver.

The next three patches target the xilinx driver. YueHaibing's patch
fixes the return type of ndo_start_xmit function. Two patches by
Shubhrajyoti Datta add support for the CAN FD 2.0 controllers.

Flavio Suligoi's patch for the sja1000 driver add support for the ASEM
CAN raw hardware.

Wolfram Sang's and Kuninori Morimoto's patches switch the rcar driver to
use SPDX license identifiers.

The remaining 111 patches improve the flexcan driver. Pankaj Bansal's
patch enables the driver in Kconfig on all architectures with IOMEM
support. The next four patches by me fix indention, add missing
parentheses and comments. Aisheng Dong's patches add self wake support
and document it in the DT bindings. The remaining patches by Pankaj
Bansal first fix the loopback support and prepare the driver for the
CAN-FD support needed for the LX2160A SoC. The actual CAN-FD support
will be added in a later patch series.

regards,
Marc

---
The following changes since commit 86d1d8b72caf648e5b14ac274f9afeaab58bbae1:

  net/ipv4: Fix missing raw_init when CONFIG_PROC_FS is disabled (2018-11-27 
20:58:02 -0800)

are available in the Git repository at:

  
ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git 
tags/linux-can-next-for-4.21-20181128

for you to fetch changes up to 6cbf76028dcac01129211828d62314285231f79e:

  can: flexcan: split the Message Buffer RAM area (2018-11-28 16:52:25 +0100)


linux-can-next-for-4.21-20181128


Aisheng Dong (2):
  dt-bindings: can: flexcan: add stop mode property to device tree
  can: flexcan: add self wakeup support

Colin Ian King (1):
  can: ucan: fix spelling mistake: "resumbmitting" -> "resubmitting"

Flavio Suligoi (1):
  can: sja1000: plx_pci: add support for ASEM CAN raw device

Kuninori Morimoto (1):
  can: rcar: add SPDX identifiers to Kconfig and Makefile

Marc Kleine-Budde (4):
  can: flexcan: flexcan_start_xmit(): fix indention
  can: flexcan: flexcan_irq(): fix indention
  can: flexcan: FLEXCAN_IFLAG_MB: add () around macro argument
  can: flexcan: flexcan_chip_start(): adjust comment to match the code

Pankaj Bansal (5):
  can: flexcan: enable flexcan for all architectures
  can: flexcan: flexcan_chip_start(): enable loopback mode in flexcan
  can: flexcan: move rx_offload_add() from flexcan_probe() to flexcan_open()
  can: flexcan: Add provision for variable payload size
  can: flexcan: split the Message Buffer RAM area

Shubhrajyoti Datta (2):
  dt-bindings: can: xilinx_can: add Xilinx CAN FD 2.0 bindings
  can: xilinx: add can 2.0 support

Wolfram Sang (1):
  can: rcar: use SPDX identifier for Renesas drivers

YueHaibing (1):
  can: xilinx: fix return type of ndo_start_xmit function

 .../devicetree/bindings/net/can/fsl-flexcan.txt|   8 +
 .../devicetree/bindings/net/can/xilinx_can.txt |   1 +
 drivers/net/can/Kconfig|   2 +-
 drivers/net/can/flexcan.c  | 365 -
 drivers/net/can/rcar/Kconfig   |   1 +
 drivers/net/can/rcar/Makefile  |   1 +
 drivers/net/can/rcar/rcar_can.c|   6 +-
 drivers/net/can/rcar/rcar_canfd.c  |   6 +-
 drivers/net/can/sja1000/Kconfig|   1 +
 drivers/net/can/sja1000/plx_pci.c  |  65 +++-
 drivers/net/can/usb/ucan.c |   2 +-
 drivers/net/can/xilinx_can.c   |  36 +-
 12 files changed, 402 insertions(+), 92 deletions(-)

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |-
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |





signature.asc
Description: OpenPGP digital signature


Re: [PATCHv2 1/2] can: xilinx: add can 2.0 support

2018-11-23 Thread Marc Kleine-Budde
On 10/12/18 6:25 AM, shubhrajyoti.da...@gmail.com wrote:
> From: Shubhrajyoti Datta 
> 
> Add support for can 2.0.
> 
> Signed-off-by: Shubhrajyoti Datta 

Added to linux-can-next.

Tnx,
Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


[PATCH 02/20] can: kvaser_usb: Fix potential uninitialized variable use

2018-11-12 Thread Marc Kleine-Budde
From: Jimmy Assarsson 

If alloc_can_err_skb() fails, cf is never initialized.
Move assignment of cf inside check.

Reported-by: Dan Carpenter 
Signed-off-by: Jimmy Assarsson 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c 
b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
index c084bae5ec0a..5fc0be564274 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
@@ -1019,6 +1019,11 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv 
*priv,
new_state : CAN_STATE_ERROR_ACTIVE;
 
can_change_state(netdev, cf, tx_state, rx_state);
+
+   if (priv->can.restart_ms &&
+   old_state >= CAN_STATE_BUS_OFF &&
+   new_state < CAN_STATE_BUS_OFF)
+   cf->can_id |= CAN_ERR_RESTARTED;
}
 
if (new_state == CAN_STATE_BUS_OFF) {
@@ -1028,11 +1033,6 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv 
*priv,
 
can_bus_off(netdev);
}
-
-   if (priv->can.restart_ms &&
-   old_state >= CAN_STATE_BUS_OFF &&
-   new_state < CAN_STATE_BUS_OFF)
-   cf->can_id |= CAN_ERR_RESTARTED;
}
 
if (!skb) {
-- 
2.19.1



[PATCH 04/20] can: ucan: remove set but not used variable 'udev'

2018-11-12 Thread Marc Kleine-Budde
From: YueHaibing 

Fixes gcc '-Wunused-but-set-variable' warning:

drivers/net/can/usb/ucan.c: In function 'ucan_disconnect':
drivers/net/can/usb/ucan.c:1578:21: warning:
 variable 'udev' set but not used [-Wunused-but-set-variable]
  struct usb_device *udev;

Signed-off-by: YueHaibing 
Reviewed-by: Martin Elshuber 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/usb/ucan.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c
index 0678a38b1af4..c9fd83e8d947 100644
--- a/drivers/net/can/usb/ucan.c
+++ b/drivers/net/can/usb/ucan.c
@@ -1575,11 +1575,8 @@ static int ucan_probe(struct usb_interface *intf,
 /* disconnect the device */
 static void ucan_disconnect(struct usb_interface *intf)
 {
-   struct usb_device *udev;
struct ucan_priv *up = usb_get_intfdata(intf);
 
-   udev = interface_to_usbdev(intf);
-
usb_set_intfdata(intf, NULL);
 
if (up) {
-- 
2.19.1



[PATCH 03/20] can: kvaser_usb: Fix accessing freed memory in kvaser_usb_start_xmit()

2018-11-12 Thread Marc Kleine-Budde
From: Jimmy Assarsson 

The call to can_put_echo_skb() may result in the skb being freed. The skb
is later used in the call to dev->ops->dev_frame_to_cmd().

This is avoided by moving the call to can_put_echo_skb() after
dev->ops->dev_frame_to_cmd().

Reported-by: Dan Carpenter 
Signed-off-by: Jimmy Assarsson 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c 
b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
index b939a4c10b84..c89c7d4900d7 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
@@ -528,7 +528,6 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff 
*skb,
context = >tx_contexts[i];
 
context->echo_index = i;
-   can_put_echo_skb(skb, netdev, context->echo_index);
++priv->active_tx_contexts;
if (priv->active_tx_contexts >= (int)dev->max_tx_urbs)
netif_stop_queue(netdev);
@@ -553,7 +552,6 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff 
*skb,
dev_kfree_skb(skb);
spin_lock_irqsave(>tx_contexts_lock, flags);
 
-   can_free_echo_skb(netdev, context->echo_index);
context->echo_index = dev->max_tx_urbs;
--priv->active_tx_contexts;
netif_wake_queue(netdev);
@@ -564,6 +562,8 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff 
*skb,
 
context->priv = priv;
 
+   can_put_echo_skb(skb, netdev, context->echo_index);
+
usb_fill_bulk_urb(urb, dev->udev,
  usb_sndbulkpipe(dev->udev,
  dev->bulk_out->bEndpointAddress),
-- 
2.19.1



[PATCH 01/20] can: raw: check for CAN FD capable netdev in raw_sendmsg()

2018-11-12 Thread Marc Kleine-Budde
From: Oliver Hartkopp 

When the socket is CAN FD enabled it can handle CAN FD frame
transmissions.  Add an additional check in raw_sendmsg() as a CAN2.0 CAN
driver (non CAN FD) should never see a CAN FD frame. Due to the commonly
used can_dropped_invalid_skb() function the CAN 2.0 driver would drop
that CAN FD frame anyway - but with this patch the user gets a proper
-EINVAL return code.

Signed-off-by: Oliver Hartkopp 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 net/can/raw.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/net/can/raw.c b/net/can/raw.c
index 1051eee82581..3aab7664933f 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -745,18 +745,19 @@ static int raw_sendmsg(struct socket *sock, struct msghdr 
*msg, size_t size)
} else
ifindex = ro->ifindex;
 
-   if (ro->fd_frames) {
+   dev = dev_get_by_index(sock_net(sk), ifindex);
+   if (!dev)
+   return -ENXIO;
+
+   err = -EINVAL;
+   if (ro->fd_frames && dev->mtu == CANFD_MTU) {
if (unlikely(size != CANFD_MTU && size != CAN_MTU))
-   return -EINVAL;
+   goto put_dev;
} else {
if (unlikely(size != CAN_MTU))
-   return -EINVAL;
+   goto put_dev;
}
 
-   dev = dev_get_by_index(sock_net(sk), ifindex);
-   if (!dev)
-   return -ENXIO;
-
skb = sock_alloc_send_skb(sk, size + sizeof(struct can_skb_priv),
  msg->msg_flags & MSG_DONTWAIT, );
if (!skb)
-- 
2.19.1



[PATCH 07/20] can: rcar_can: Fix erroneous registration

2018-11-12 Thread Marc Kleine-Budde
From: Fabrizio Castro 

Assigning 2 to "renesas,can-clock-select" tricks the driver into
registering the CAN interface, even though we don't want that.
This patch improves one of the checks to prevent that from happening.

Fixes: 862e2b6af9413b43 ("can: rcar_can: support all input clocks")
Signed-off-by: Fabrizio Castro 
Signed-off-by: Chris Paterson 
Reviewed-by: Simon Horman 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/rcar/rcar_can.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c
index 11662f479e76..771a46083739 100644
--- a/drivers/net/can/rcar/rcar_can.c
+++ b/drivers/net/can/rcar/rcar_can.c
@@ -24,6 +24,9 @@
 
 #define RCAR_CAN_DRV_NAME  "rcar_can"
 
+#define RCAR_SUPPORTED_CLOCKS  (BIT(CLKR_CLKP1) | BIT(CLKR_CLKP2) | \
+BIT(CLKR_CLKEXT))
+
 /* Mailbox configuration:
  * mailbox 60 - 63 - Rx FIFO mailboxes
  * mailbox 56 - 59 - Tx FIFO mailboxes
@@ -789,7 +792,7 @@ static int rcar_can_probe(struct platform_device *pdev)
goto fail_clk;
}
 
-   if (clock_select >= ARRAY_SIZE(clock_names)) {
+   if (!(BIT(clock_select) & RCAR_SUPPORTED_CLOCKS)) {
err = -EINVAL;
dev_err(>dev, "invalid CAN clock selected\n");
goto fail_clk;
-- 
2.19.1



[PATCH 08/20] dt-bindings: can: rcar_can: Add r8a774a1 support

2018-11-12 Thread Marc Kleine-Budde
From: Fabrizio Castro 

Document RZ/G2M (r8a774a1) SoC specific bindings.

Signed-off-by: Fabrizio Castro 
Signed-off-by: Chris Paterson 
Reviewed-by: Biju Das 
Reviewed-by: Rob Herring 
Reviewed-by: Simon Horman 
Signed-off-by: Marc Kleine-Budde 
---
 .../devicetree/bindings/net/can/rcar_can.txt   | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_can.txt 
b/Documentation/devicetree/bindings/net/can/rcar_can.txt
index 47fc68148f38..9936b9ee67c3 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_can.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_can.txt
@@ -5,6 +5,7 @@ Required properties:
 - compatible: "renesas,can-r8a7743" if CAN controller is a part of R8A7743 SoC.
  "renesas,can-r8a7744" if CAN controller is a part of R8A7744 SoC.
  "renesas,can-r8a7745" if CAN controller is a part of R8A7745 SoC.
+ "renesas,can-r8a774a1" if CAN controller is a part of R8A774A1 
SoC.
  "renesas,can-r8a7778" if CAN controller is a part of R8A7778 SoC.
  "renesas,can-r8a7779" if CAN controller is a part of R8A7779 SoC.
  "renesas,can-r8a7790" if CAN controller is a part of R8A7790 SoC.
@@ -18,15 +19,21 @@ Required properties:
  "renesas,rcar-gen1-can" for a generic R-Car Gen1 compatible 
device.
  "renesas,rcar-gen2-can" for a generic R-Car Gen2 or RZ/G1
  compatible device.
- "renesas,rcar-gen3-can" for a generic R-Car Gen3 compatible 
device.
+ "renesas,rcar-gen3-can" for a generic R-Car Gen3 or RZ/G2
+ compatible device.
  When compatible with the generic version, nodes must list the
  SoC-specific version corresponding to the platform first
  followed by the generic version.
 
 - reg: physical base address and size of the R-Car CAN register map.
 - interrupts: interrupt specifier for the sole interrupt.
-- clocks: phandles and clock specifiers for 3 CAN clock inputs.
-- clock-names: 3 clock input name strings: "clkp1", "clkp2", "can_clk".
+- clocks: phandles and clock specifiers for 2 CAN clock inputs for RZ/G2
+ devices.
+ phandles and clock specifiers for 3 CAN clock inputs for every other
+ SoC.
+- clock-names: 2 clock input name strings for RZ/G2: "clkp1", "can_clk".
+  3 clock input name strings for every other SoC: "clkp1", "clkp2",
+  "can_clk".
 - pinctrl-0: pin control group to be used for this controller.
 - pinctrl-names: must be "default".
 
@@ -42,8 +49,9 @@ using the below properties:
 Optional properties:
 - renesas,can-clock-select: R-Car CAN Clock Source Select. Valid values are:
<0x0> (default) : Peripheral clock (clkp1)
-   <0x1> : Peripheral clock (clkp2)
-   <0x3> : Externally input clock
+   <0x1> : Peripheral clock (clkp2) (not supported by
+   RZ/G2 devices)
+   <0x3> : External input clock
 
 Example
 ---
-- 
2.19.1



[PATCH 05/20] can: ucan: remove duplicated include from ucan.c

2018-11-12 Thread Marc Kleine-Budde
From: YueHaibing 

Remove duplicated include.

Signed-off-by: YueHaibing 
Reviewed-by: Martin Elshuber 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/usb/ucan.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c
index c9fd83e8d947..f3d5bda012a1 100644
--- a/drivers/net/can/usb/ucan.c
+++ b/drivers/net/can/usb/ucan.c
@@ -35,10 +35,6 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-
 #define UCAN_DRIVER_NAME "ucan"
 #define UCAN_MAX_RX_URBS 8
 /* the CAN controller needs a while to enable/disable the bus */
-- 
2.19.1



[PATCH 11/20] can: flexcan: Always use last mailbox for TX

2018-11-12 Thread Marc Kleine-Budde
From: Alexander Stein 

Essentially this patch moves the TX mailbox to position 63, regardless
of timestamp based offloading or RX FIFO. So mainly the iflag register
usage regarding TX has changed. The rest is consolidating RX FIFO and
timestamp offloading as they now use both the same TX mailbox.

The reason is a very annoying behavior regarding sending RTR frames when
_not_ using RX FIFO:

If a TX mailbox sent a RTR frame it becomes a RX mailbox. For that
reason flexcan_irq disables the TX mailbox again. But if during the time
the RTR was sent and the TX mailbox is disabled a new CAN frames is
received, it is lost without notice. The reason is that so-called
"Move-in" process starts from the lowest mailbox which happen to be a TX
mailbox set to EMPTY.

Steps to reproduce (I used an imx7d):
1. generate regular bursts of messages
2. send a RTR from flexcan with higher priority than burst messages every
   1ms, e.g. cangen -I 0x100 -L 0 -g 1 -R can0
3. notice a lost message without notification after some seconds

When running an iperf in parallel this problem is occurring even more
frequently. Using filters is not possible as at least one single CAN-ID
is allowed. Handling the TX MB during RX is also not possible as there
is no race-free disable of RX MB.

There is still a slight window when the described problem can occur. But
for that all RX MB must be in use which is essentially next to an
overrun. Still there will be no indication if it ever occurs.

Signed-off-by: Alexander Stein 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/flexcan.c | 67 +++
 1 file changed, 33 insertions(+), 34 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 0431f8d05518..677c41701cf3 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -135,13 +135,12 @@
 
 /* FLEXCAN interrupt flag register (IFLAG) bits */
 /* Errata ERR005829 step7: Reserve first valid MB */
-#define FLEXCAN_TX_MB_RESERVED_OFF_FIFO8
-#define FLEXCAN_TX_MB_OFF_FIFO 9
+#define FLEXCAN_TX_MB_RESERVED_OFF_FIFO8
 #define FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP   0
-#define FLEXCAN_TX_MB_OFF_TIMESTAMP1
-#define FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST  (FLEXCAN_TX_MB_OFF_TIMESTAMP + 
1)
-#define FLEXCAN_RX_MB_OFF_TIMESTAMP_LAST   63
-#define FLEXCAN_IFLAG_MB(x)BIT(x)
+#define FLEXCAN_TX_MB  63
+#define FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST  
(FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP + 1)
+#define FLEXCAN_RX_MB_OFF_TIMESTAMP_LAST   (FLEXCAN_TX_MB - 1)
+#define FLEXCAN_IFLAG_MB(x)BIT(x & 0x1f)
 #define FLEXCAN_IFLAG_RX_FIFO_OVERFLOW BIT(7)
 #define FLEXCAN_IFLAG_RX_FIFO_WARN BIT(6)
 #define FLEXCAN_IFLAG_RX_FIFO_AVAILABLEBIT(5)
@@ -737,9 +736,9 @@ static inline u64 flexcan_read_reg_iflag_rx(struct 
flexcan_priv *priv)
struct flexcan_regs __iomem *regs = priv->regs;
u32 iflag1, iflag2;
 
-   iflag2 = priv->read(>iflag2) & priv->reg_imask2_default;
-   iflag1 = priv->read(>iflag1) & priv->reg_imask1_default &
+   iflag2 = priv->read(>iflag2) & priv->reg_imask2_default &
~FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
+   iflag1 = priv->read(>iflag1) & priv->reg_imask1_default;
 
return (u64)iflag2 << 32 | iflag1;
 }
@@ -751,11 +750,9 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
struct flexcan_priv *priv = netdev_priv(dev);
struct flexcan_regs __iomem *regs = priv->regs;
irqreturn_t handled = IRQ_NONE;
-   u32 reg_iflag1, reg_esr;
+   u32 reg_iflag2, reg_esr;
enum can_state last_state = priv->can.state;
 
-   reg_iflag1 = priv->read(>iflag1);
-
/* reception interrupt */
if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
u64 reg_iflag;
@@ -769,6 +766,9 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
break;
}
} else {
+   u32 reg_iflag1;
+
+   reg_iflag1 = priv->read(>iflag1);
if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) {
handled = IRQ_HANDLED;
can_rx_offload_irq_offload_fifo(>offload);
@@ -784,8 +784,10 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
}
}
 
+   reg_iflag2 = priv->read(>iflag2);
+
/* transmission complete interrupt */
-   if (reg_iflag1 & FLEXCAN_IFLAG_MB(priv->tx_mb_idx)) {
+   if (reg_iflag2 & FLEXCAN_IFLAG_MB(priv->tx_mb_idx)) {
handled = IRQ_HANDLED;
stats->tx_bytes += can_get_echo_skb(dev, 0);
stats->tx_packets++;
@@ -794,7 +796,7 @@ static irqreturn_t flexcan_

[PATCH 12/20] can: flexcan: remove not needed struct flexcan_priv::tx_mb and struct flexcan_priv::tx_mb_idx

2018-11-12 Thread Marc Kleine-Budde
The previous patch changes the TX path to always use the last mailbox
regardless of the used offload scheme (rx-fifo or timestamp based). This
means members "tx_mb" and "tx_mb_idx" of the struct flexcan_priv don't
depend on the offload scheme, so replace them by compile time constants.

Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/flexcan.c | 27 ---
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 677c41701cf3..68b46395c580 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -258,9 +258,7 @@ struct flexcan_priv {
struct can_rx_offload offload;
 
struct flexcan_regs __iomem *regs;
-   struct flexcan_mb __iomem *tx_mb;
struct flexcan_mb __iomem *tx_mb_reserved;
-   u8 tx_mb_idx;
u32 reg_ctrl_default;
u32 reg_imask1_default;
u32 reg_imask2_default;
@@ -514,6 +512,7 @@ static int flexcan_get_berr_counter(const struct net_device 
*dev,
 static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device 
*dev)
 {
const struct flexcan_priv *priv = netdev_priv(dev);
+   struct flexcan_regs __iomem *regs = priv->regs;
struct can_frame *cf = (struct can_frame *)skb->data;
u32 can_id;
u32 data;
@@ -536,17 +535,17 @@ static netdev_tx_t flexcan_start_xmit(struct sk_buff 
*skb, struct net_device *de
 
if (cf->can_dlc > 0) {
data = be32_to_cpup((__be32 *)>data[0]);
-   priv->write(data, >tx_mb->data[0]);
+   priv->write(data, >mb[FLEXCAN_TX_MB].data[0]);
}
if (cf->can_dlc > 4) {
data = be32_to_cpup((__be32 *)>data[4]);
-   priv->write(data, >tx_mb->data[1]);
+   priv->write(data, >mb[FLEXCAN_TX_MB].data[1]);
}
 
can_put_echo_skb(skb, dev, 0);
 
-   priv->write(can_id, >tx_mb->can_id);
-   priv->write(ctrl, >tx_mb->can_ctrl);
+   priv->write(can_id, >mb[FLEXCAN_TX_MB].can_id);
+   priv->write(ctrl, >mb[FLEXCAN_TX_MB].can_ctrl);
 
/* Errata ERR005829 step8:
 * Write twice INACTIVE(0x8) code to first MB.
@@ -737,7 +736,7 @@ static inline u64 flexcan_read_reg_iflag_rx(struct 
flexcan_priv *priv)
u32 iflag1, iflag2;
 
iflag2 = priv->read(>iflag2) & priv->reg_imask2_default &
-   ~FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
+   ~FLEXCAN_IFLAG_MB(FLEXCAN_TX_MB);
iflag1 = priv->read(>iflag1) & priv->reg_imask1_default;
 
return (u64)iflag2 << 32 | iflag1;
@@ -787,7 +786,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
reg_iflag2 = priv->read(>iflag2);
 
/* transmission complete interrupt */
-   if (reg_iflag2 & FLEXCAN_IFLAG_MB(priv->tx_mb_idx)) {
+   if (reg_iflag2 & FLEXCAN_IFLAG_MB(FLEXCAN_TX_MB)) {
handled = IRQ_HANDLED;
stats->tx_bytes += can_get_echo_skb(dev, 0);
stats->tx_packets++;
@@ -795,8 +794,8 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 
/* after sending a RTR frame MB is in RX mode */
priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
-   >tx_mb->can_ctrl);
-   priv->write(FLEXCAN_IFLAG_MB(priv->tx_mb_idx), >iflag2);
+   >mb[FLEXCAN_TX_MB].can_ctrl);
+   priv->write(FLEXCAN_IFLAG_MB(FLEXCAN_TX_MB), >iflag2);
netif_wake_queue(dev);
}
 
@@ -938,7 +937,7 @@ static int flexcan_chip_start(struct net_device *dev)
reg_mcr &= ~FLEXCAN_MCR_MAXMB(0xff);
reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT | FLEXCAN_MCR_SUPV |
FLEXCAN_MCR_WRN_EN | FLEXCAN_MCR_SRX_DIS | FLEXCAN_MCR_IRMQ |
-   FLEXCAN_MCR_IDAM_C | FLEXCAN_MCR_MAXMB(priv->tx_mb_idx);
+   FLEXCAN_MCR_IDAM_C | FLEXCAN_MCR_MAXMB(FLEXCAN_TX_MB);
 
if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP)
reg_mcr &= ~FLEXCAN_MCR_FEN;
@@ -1006,7 +1005,7 @@ static int flexcan_chip_start(struct net_device *dev)
 
/* mark TX mailbox as INACTIVE */
priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
-   >tx_mb->can_ctrl);
+   >mb[FLEXCAN_TX_MB].can_ctrl);
 
/* acceptance mask/acceptance code (accept everything) */
priv->write(0x0, >rxgmask);
@@ -1365,11 +1364,9 @@ static int flexcan_probe(struct platform_device *pdev)
priv->tx_mb_reserved = 
>mb[FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP];
else
priv->tx_mb_reserved = 
>mb[FLEXCAN_TX_MB_RESERVED_OFF_FIFO];
-   priv->tx_mb_idx = FLEXCAN_TX_MB;
-   pri

[PATCH 17/20] can: rx-offload: introduce can_rx_offload_get_echo_skb() and can_rx_offload_queue_sorted() functions

2018-11-12 Thread Marc Kleine-Budde
From: Oleksij Rempel 

Current CAN framework can't guarantee proper/chronological order
of RX and TX-ECHO messages. To make this possible, drivers should use
this functions instead of can_get_echo_skb().

Signed-off-by: Oleksij Rempel 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/rx-offload.c   | 46 ++
 include/linux/can/rx-offload.h |  4 +++
 2 files changed, 50 insertions(+)

diff --git a/drivers/net/can/rx-offload.c b/drivers/net/can/rx-offload.c
index c7d05027a7a0..c368686e2164 100644
--- a/drivers/net/can/rx-offload.c
+++ b/drivers/net/can/rx-offload.c
@@ -211,6 +211,52 @@ int can_rx_offload_irq_offload_fifo(struct can_rx_offload 
*offload)
 }
 EXPORT_SYMBOL_GPL(can_rx_offload_irq_offload_fifo);
 
+int can_rx_offload_queue_sorted(struct can_rx_offload *offload,
+   struct sk_buff *skb, u32 timestamp)
+{
+   struct can_rx_offload_cb *cb;
+   unsigned long flags;
+
+   if (skb_queue_len(>skb_queue) >
+   offload->skb_queue_len_max)
+   return -ENOMEM;
+
+   cb = can_rx_offload_get_cb(skb);
+   cb->timestamp = timestamp;
+
+   spin_lock_irqsave(>skb_queue.lock, flags);
+   __skb_queue_add_sort(>skb_queue, skb, can_rx_offload_compare);
+   spin_unlock_irqrestore(>skb_queue.lock, flags);
+
+   can_rx_offload_schedule(offload);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(can_rx_offload_queue_sorted);
+
+unsigned int can_rx_offload_get_echo_skb(struct can_rx_offload *offload,
+unsigned int idx, u32 timestamp)
+{
+   struct net_device *dev = offload->dev;
+   struct net_device_stats *stats = >stats;
+   struct sk_buff *skb;
+   u8 len;
+   int err;
+
+   skb = __can_get_echo_skb(dev, idx, );
+   if (!skb)
+   return 0;
+
+   err = can_rx_offload_queue_sorted(offload, skb, timestamp);
+   if (err) {
+   stats->rx_errors++;
+   stats->tx_fifo_errors++;
+   }
+
+   return len;
+}
+EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb);
+
 int can_rx_offload_irq_queue_err_skb(struct can_rx_offload *offload, struct 
sk_buff *skb)
 {
if (skb_queue_len(>skb_queue) >
diff --git a/include/linux/can/rx-offload.h b/include/linux/can/rx-offload.h
index cb31683bbe15..01a7c9e5d8d8 100644
--- a/include/linux/can/rx-offload.h
+++ b/include/linux/can/rx-offload.h
@@ -41,6 +41,10 @@ int can_rx_offload_add_timestamp(struct net_device *dev, 
struct can_rx_offload *
 int can_rx_offload_add_fifo(struct net_device *dev, struct can_rx_offload 
*offload, unsigned int weight);
 int can_rx_offload_irq_offload_timestamp(struct can_rx_offload *offload, u64 
reg);
 int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload);
+int can_rx_offload_queue_sorted(struct can_rx_offload *offload,
+   struct sk_buff *skb, u32 timestamp);
+unsigned int can_rx_offload_get_echo_skb(struct can_rx_offload *offload,
+unsigned int idx, u32 timestamp);
 int can_rx_offload_irq_queue_err_skb(struct can_rx_offload *offload, struct 
sk_buff *skb);
 void can_rx_offload_reset(struct can_rx_offload *offload);
 void can_rx_offload_del(struct can_rx_offload *offload);
-- 
2.19.1



[PATCH 09/20] can: hi311x: Use level-triggered interrupt

2018-11-12 Thread Marc Kleine-Budde
From: Lukas Wunner 

If the hi3110 shares the SPI bus with another traffic-intensive device
and packets are received in high volume (by a separate machine sending
with "cangen -g 0 -i -x"), reception stops after a few minutes and the
counter in /proc/interrupts stops incrementing.  Bus state is "active".
Bringing the interface down and back up reconvenes the reception.  The
issue is not observed when the hi3110 is the sole device on the SPI bus.

Using a level-triggered interrupt makes the issue go away and lets the
hi3110 successfully receive 2 GByte over the course of 5 days while a
ks8851 Ethernet chip on the same SPI bus handles 6 GByte of traffic.

Unfortunately the hi3110 datasheet is mum on the trigger type.  The pin
description on page 3 only specifies the polarity (active high):
http://www.holtic.com/documents/371-hi-3110_v-rev-kpdf.do

Cc: Mathias Duckeck 
Cc: Akshay Bhat 
Cc: Casey Fitzpatrick 
Signed-off-by: Lukas Wunner 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 Documentation/devicetree/bindings/net/can/holt_hi311x.txt | 2 +-
 drivers/net/can/spi/hi311x.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/holt_hi311x.txt 
b/Documentation/devicetree/bindings/net/can/holt_hi311x.txt
index 903a78da65be..3a9926f99937 100644
--- a/Documentation/devicetree/bindings/net/can/holt_hi311x.txt
+++ b/Documentation/devicetree/bindings/net/can/holt_hi311x.txt
@@ -17,7 +17,7 @@ Example:
reg = <1>;
clocks = <>;
interrupt-parent = <>;
-   interrupts = <13 IRQ_TYPE_EDGE_RISING>;
+   interrupts = <13 IRQ_TYPE_LEVEL_HIGH>;
vdd-supply = <>;
xceiver-supply = <>;
};
diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index 53e320c92a8b..ddaf46239e39 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -760,7 +760,7 @@ static int hi3110_open(struct net_device *net)
 {
struct hi3110_priv *priv = netdev_priv(net);
struct spi_device *spi = priv->spi;
-   unsigned long flags = IRQF_ONESHOT | IRQF_TRIGGER_RISING;
+   unsigned long flags = IRQF_ONESHOT | IRQF_TRIGGER_HIGH;
int ret;
 
ret = open_candev(net);
-- 
2.19.1



[PATCH 19/20] can: rx-offload: rename can_rx_offload_irq_queue_err_skb() to can_rx_offload_queue_tail()

2018-11-12 Thread Marc Kleine-Budde
From: Oleksij Rempel 

This function has nothing todo with error.

Signed-off-by: Oleksij Rempel 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/flexcan.c  | 4 ++--
 drivers/net/can/rx-offload.c   | 5 +++--
 include/linux/can/rx-offload.h | 3 ++-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 41a175f80c4b..5923bd0ec118 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -610,7 +610,7 @@ static void flexcan_irq_bus_err(struct net_device *dev, u32 
reg_esr)
if (tx_errors)
dev->stats.tx_errors++;
 
-   can_rx_offload_irq_queue_err_skb(>offload, skb);
+   can_rx_offload_queue_tail(>offload, skb);
 }
 
 static void flexcan_irq_state(struct net_device *dev, u32 reg_esr)
@@ -650,7 +650,7 @@ static void flexcan_irq_state(struct net_device *dev, u32 
reg_esr)
if (unlikely(new_state == CAN_STATE_BUS_OFF))
can_bus_off(dev);
 
-   can_rx_offload_irq_queue_err_skb(>offload, skb);
+   can_rx_offload_queue_tail(>offload, skb);
 }
 
 static inline struct flexcan_priv *rx_offload_to_priv(struct can_rx_offload 
*offload)
diff --git a/drivers/net/can/rx-offload.c b/drivers/net/can/rx-offload.c
index c368686e2164..2ce4fa8698c7 100644
--- a/drivers/net/can/rx-offload.c
+++ b/drivers/net/can/rx-offload.c
@@ -257,7 +257,8 @@ unsigned int can_rx_offload_get_echo_skb(struct 
can_rx_offload *offload,
 }
 EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb);
 
-int can_rx_offload_irq_queue_err_skb(struct can_rx_offload *offload, struct 
sk_buff *skb)
+int can_rx_offload_queue_tail(struct can_rx_offload *offload,
+ struct sk_buff *skb)
 {
if (skb_queue_len(>skb_queue) >
offload->skb_queue_len_max)
@@ -268,7 +269,7 @@ int can_rx_offload_irq_queue_err_skb(struct can_rx_offload 
*offload, struct sk_b
 
return 0;
 }
-EXPORT_SYMBOL_GPL(can_rx_offload_irq_queue_err_skb);
+EXPORT_SYMBOL_GPL(can_rx_offload_queue_tail);
 
 static int can_rx_offload_init_queue(struct net_device *dev, struct 
can_rx_offload *offload, unsigned int weight)
 {
diff --git a/include/linux/can/rx-offload.h b/include/linux/can/rx-offload.h
index 01a7c9e5d8d8..8268811a697e 100644
--- a/include/linux/can/rx-offload.h
+++ b/include/linux/can/rx-offload.h
@@ -45,7 +45,8 @@ int can_rx_offload_queue_sorted(struct can_rx_offload 
*offload,
struct sk_buff *skb, u32 timestamp);
 unsigned int can_rx_offload_get_echo_skb(struct can_rx_offload *offload,
 unsigned int idx, u32 timestamp);
-int can_rx_offload_irq_queue_err_skb(struct can_rx_offload *offload, struct 
sk_buff *skb);
+int can_rx_offload_queue_tail(struct can_rx_offload *offload,
+ struct sk_buff *skb);
 void can_rx_offload_reset(struct can_rx_offload *offload);
 void can_rx_offload_del(struct can_rx_offload *offload);
 void can_rx_offload_enable(struct can_rx_offload *offload);
-- 
2.19.1



[PATCH 20/20] can: flexcan: use can_rx_offload_queue_sorted() for flexcan_irq_bus_*()

2018-11-12 Thread Marc Kleine-Budde
From: Oleksij Rempel 

Currently, in case of bus error, driver will generate error message and put
in the tail of the message queue. To avoid confusions, this change should
place the bus related messages in proper order.

Signed-off-by: Oleksij Rempel 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/flexcan.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 5923bd0ec118..75ce11395ee8 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -561,9 +561,13 @@ static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, 
struct net_device *de
 static void flexcan_irq_bus_err(struct net_device *dev, u32 reg_esr)
 {
struct flexcan_priv *priv = netdev_priv(dev);
+   struct flexcan_regs __iomem *regs = priv->regs;
struct sk_buff *skb;
struct can_frame *cf;
bool rx_errors = false, tx_errors = false;
+   u32 timestamp;
+
+   timestamp = priv->read(>timer) << 16;
 
skb = alloc_can_err_skb(dev, );
if (unlikely(!skb))
@@ -610,17 +614,21 @@ static void flexcan_irq_bus_err(struct net_device *dev, 
u32 reg_esr)
if (tx_errors)
dev->stats.tx_errors++;
 
-   can_rx_offload_queue_tail(>offload, skb);
+   can_rx_offload_queue_sorted(>offload, skb, timestamp);
 }
 
 static void flexcan_irq_state(struct net_device *dev, u32 reg_esr)
 {
struct flexcan_priv *priv = netdev_priv(dev);
+   struct flexcan_regs __iomem *regs = priv->regs;
struct sk_buff *skb;
struct can_frame *cf;
enum can_state new_state, rx_state, tx_state;
int flt;
struct can_berr_counter bec;
+   u32 timestamp;
+
+   timestamp = priv->read(>timer) << 16;
 
flt = reg_esr & FLEXCAN_ESR_FLT_CONF_MASK;
if (likely(flt == FLEXCAN_ESR_FLT_CONF_ACTIVE)) {
@@ -650,7 +658,7 @@ static void flexcan_irq_state(struct net_device *dev, u32 
reg_esr)
if (unlikely(new_state == CAN_STATE_BUS_OFF))
can_bus_off(dev);
 
-   can_rx_offload_queue_tail(>offload, skb);
+   can_rx_offload_queue_sorted(>offload, skb, timestamp);
 }
 
 static inline struct flexcan_priv *rx_offload_to_priv(struct can_rx_offload 
*offload)
-- 
2.19.1



[PATCH 16/20] can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb

2018-11-12 Thread Marc Kleine-Budde
Prior to echoing a successfully transmitted CAN frame (by calling
can_get_echo_skb()), CAN drivers have to put the CAN frame (by calling
can_put_echo_skb() in the transmit function). These put and get function
take an index as parameter, which is used to identify the CAN frame.

A driver calling can_get_echo_skb() with a index not pointing to a skb
is a BUG, so add an appropriate error message.

Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/dev.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index c05e4d50d43d..3b3f88ffab53 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -480,6 +480,8 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb);
 struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, 
u8 *len_ptr)
 {
struct can_priv *priv = netdev_priv(dev);
+   struct sk_buff *skb = priv->echo_skb[idx];
+   struct canfd_frame *cf;
 
if (idx >= priv->echo_skb_max) {
netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb 
out of bounds (%u/max %u)\n",
@@ -487,21 +489,20 @@ struct sk_buff *__can_get_echo_skb(struct net_device 
*dev, unsigned int idx, u8
return NULL;
}
 
-   if (priv->echo_skb[idx]) {
-   /* Using "struct canfd_frame::len" for the frame
-* length is supported on both CAN and CANFD frames.
-*/
-   struct sk_buff *skb = priv->echo_skb[idx];
-   struct canfd_frame *cf = (struct canfd_frame *)skb->data;
-   u8 len = cf->len;
-
-   *len_ptr = len;
-   priv->echo_skb[idx] = NULL;
-
-   return skb;
+   if (!skb) {
+   netdev_err(dev, "%s: BUG! Trying to echo non existing skb: 
can_priv::echo_skb[%u]\n",
+  __func__, idx);
+   return NULL;
}
 
-   return NULL;
+   /* Using "struct canfd_frame::len" for the frame
+* length is supported on both CAN and CANFD frames.
+*/
+   cf = (struct canfd_frame *)skb->data;
+   *len_ptr = cf->len;
+   priv->echo_skb[idx] = NULL;
+
+   return skb;
 }
 
 /*
-- 
2.19.1



[PATCH 15/20] can: dev: __can_get_echo_skb(): Don't crash the kernel if can_priv::echo_skb is accessed out of bounds

2018-11-12 Thread Marc Kleine-Budde
If the "struct can_priv::echo_skb" is accessed out of bounds would lead
to a kernel crash. Better print a sensible warning message instead and
try to recover.

Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/dev.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 46cc5fec4043..c05e4d50d43d 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -481,7 +481,11 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, 
unsigned int idx, u8
 {
struct can_priv *priv = netdev_priv(dev);
 
-   BUG_ON(idx >= priv->echo_skb_max);
+   if (idx >= priv->echo_skb_max) {
+   netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb 
out of bounds (%u/max %u)\n",
+  __func__, idx, priv->echo_skb_max);
+   return NULL;
+   }
 
if (priv->echo_skb[idx]) {
/* Using "struct canfd_frame::len" for the frame
-- 
2.19.1



[PATCH 14/20] can: dev: __can_get_echo_skb(): replace struct can_frame by canfd_frame to access frame length

2018-11-12 Thread Marc Kleine-Budde
This patch replaces the use of "struct can_frame::can_dlc" by "struct
canfd_frame::len" to access the frame's length. As it is ensured that
both structures have a compatible memory layout for this member this is
no functional change. Futher, this compatibility is documented in a
comment.

Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/dev.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 80530ab37b1e..46cc5fec4043 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -484,11 +484,14 @@ struct sk_buff *__can_get_echo_skb(struct net_device 
*dev, unsigned int idx, u8
BUG_ON(idx >= priv->echo_skb_max);
 
if (priv->echo_skb[idx]) {
+   /* Using "struct canfd_frame::len" for the frame
+* length is supported on both CAN and CANFD frames.
+*/
struct sk_buff *skb = priv->echo_skb[idx];
-   struct can_frame *cf = (struct can_frame *)skb->data;
-   u8 dlc = cf->can_dlc;
+   struct canfd_frame *cf = (struct canfd_frame *)skb->data;
+   u8 len = cf->len;
 
-   *len_ptr = dlc;
+   *len_ptr = len;
priv->echo_skb[idx] = NULL;
 
return skb;
-- 
2.19.1



[PATCH 18/20] can: flexcan: handle tx-complete CAN frames via rx-offload infrastructure

2018-11-12 Thread Marc Kleine-Budde
From: Oleksij Rempel 

Current flexcan driver will put TX-ECHO in regular unsorted way, in
this case TX-ECHO can come after the response to the same TXed message.
In some cases, for example for J1939 stack, things will break.
This patch is using new rx-offload API to put the messages just in the
right place.

Signed-off-by: Oleksij Rempel 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/flexcan.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 68b46395c580..41a175f80c4b 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -787,8 +787,11 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 
/* transmission complete interrupt */
if (reg_iflag2 & FLEXCAN_IFLAG_MB(FLEXCAN_TX_MB)) {
+   u32 reg_ctrl = priv->read(>mb[FLEXCAN_TX_MB].can_ctrl);
+
handled = IRQ_HANDLED;
-   stats->tx_bytes += can_get_echo_skb(dev, 0);
+   stats->tx_bytes += can_rx_offload_get_echo_skb(>offload,
+  0, reg_ctrl << 
16);
stats->tx_packets++;
can_led_event(dev, CAN_LED_EVENT_TX);
 
-- 
2.19.1



[PATCH 13/20] can: dev: can_get_echo_skb(): factor out non sending code to __can_get_echo_skb()

2018-11-12 Thread Marc Kleine-Budde
This patch factors out all non sending parts of can_get_echo_skb() into
a seperate function __can_get_echo_skb(), so that it can be re-used in
an upcoming patch.

Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/dev.c   | 36 +---
 include/linux/can/dev.h |  1 +
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 49163570a63a..80530ab37b1e 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -477,14 +477,7 @@ void can_put_echo_skb(struct sk_buff *skb, struct 
net_device *dev,
 }
 EXPORT_SYMBOL_GPL(can_put_echo_skb);
 
-/*
- * Get the skb from the stack and loop it back locally
- *
- * The function is typically called when the TX done interrupt
- * is handled in the device driver. The driver must protect
- * access to priv->echo_skb, if necessary.
- */
-unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx)
+struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, 
u8 *len_ptr)
 {
struct can_priv *priv = netdev_priv(dev);
 
@@ -495,13 +488,34 @@ unsigned int can_get_echo_skb(struct net_device *dev, 
unsigned int idx)
struct can_frame *cf = (struct can_frame *)skb->data;
u8 dlc = cf->can_dlc;
 
-   netif_rx(priv->echo_skb[idx]);
+   *len_ptr = dlc;
priv->echo_skb[idx] = NULL;
 
-   return dlc;
+   return skb;
}
 
-   return 0;
+   return NULL;
+}
+
+/*
+ * Get the skb from the stack and loop it back locally
+ *
+ * The function is typically called when the TX done interrupt
+ * is handled in the device driver. The driver must protect
+ * access to priv->echo_skb, if necessary.
+ */
+unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx)
+{
+   struct sk_buff *skb;
+   u8 len;
+
+   skb = __can_get_echo_skb(dev, idx, );
+   if (!skb)
+   return 0;
+
+   netif_rx(skb);
+
+   return len;
 }
 EXPORT_SYMBOL_GPL(can_get_echo_skb);
 
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index a83e1f632eb7..f01623aef2f7 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -169,6 +169,7 @@ void can_change_state(struct net_device *dev, struct 
can_frame *cf,
 
 void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
  unsigned int idx);
+struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, 
u8 *len_ptr);
 unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx);
 void can_free_echo_skb(struct net_device *dev, unsigned int idx);
 
-- 
2.19.1



[PATCH 10/20] can: flexcan: Unlock the MB unconditionally

2018-11-12 Thread Marc Kleine-Budde
From: Pankaj Bansal 

Unlock the MB irrespective of reception method being FIFO or timestamp
based. It is optional but recommended to unlock Mailbox as soon as
possible and make it available for reception.

Reported-by: Alexander Stein 
Signed-off-by: Pankaj Bansal 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/flexcan.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 8e972ef08637..0431f8d05518 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -720,9 +720,14 @@ static unsigned int flexcan_mailbox_read(struct 
can_rx_offload *offload,
priv->write(BIT(n - 32), >iflag2);
} else {
priv->write(FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, >iflag1);
-   priv->read(>timer);
}
 
+   /* Read the Free Running Timer. It is optional but recommended
+* to unlock Mailbox as soon as possible and make it available
+* for reception.
+*/
+   priv->read(>timer);
+
return 1;
 }
 
-- 
2.19.1



pull-request: can 2018-11-09

2018-11-12 Thread Marc Kleine-Budde
Hello David,

this is a pull request of 20 patches for net/master.

First we have a patch by Oliver Hartkopp which changes the raw socket's
raw_sendmsg() to return an error value if the user tries to send a CANFD
frame to a CAN-2.0 device.

The next two patches are by Jimmy Assarsson and fix potential problems
in the kvaser_usb driver.

YueHaibing's patches for the ucan driver fix a compile time warning and
remove a duplicate include.

Eugeniu Rosca patch adds more binding documentation to the rcar_can
driver bindings. The next two patches are by Fabrizio Castro for the
rcar_can driver and fixes a problem in the driver's probe function and
document the r8a774a1 binding.

Lukas Wunner's patch fixes a recpetion problem in hi311x driver by
switching from edge to level triggered interruts.

The next three patches all target the flexcan driver. Pankaj Bansal's
patch unconditionally unlocks the last mailbox used for RX. Alexander
Stein provides a better workaround for a hardware limitation when
sending RTR frames, by using the last mailbox for TX, resulting in fewer
lost frames. The patch by me simplyfies the driver, by making a runtime
value a compile time constant.

The following 4 patches are by me and provide the groundwork for the
next patches by Oleksij Rempel. To avoid code duplication common code in
the common CAN driver infrastructure is factured out and error handling
is cleaned up.

The next 4 patches are by Oleksij Rempel and fix the problem in the
flexcan driver that other processes see TX frames arrive out of order
with ragards to a RX'ed frame (which are send by a different system on
the CAN bus as the result of our TX frame).

regards,
Marc

---

The following changes since commit 85b18b0237ce9986a81a1b9534b5e2ee116f5504:

  net: smsc95xx: Fix MTU range (2018-11-08 19:54:49 -0800)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.20-20181109

for you to fetch changes up to d788905f68fd4714c82936f6f7f1d3644d7ae7ef:

  can: flexcan: use can_rx_offload_queue_sorted() for flexcan_irq_bus_*() 
(2018-11-09 17:33:33 +0100)


linux-can-fixes-for-4.20-20181109


Alexander Stein (1):
  can: flexcan: Always use last mailbox for TX

Eugeniu Rosca (1):
  dt-bindings: can: rcar_can: document r8a77965 support

Fabrizio Castro (2):
  can: rcar_can: Fix erroneous registration
  dt-bindings: can: rcar_can: Add r8a774a1 support

Jimmy Assarsson (2):
  can: kvaser_usb: Fix potential uninitialized variable use
  can: kvaser_usb: Fix accessing freed memory in kvaser_usb_start_xmit()

Lukas Wunner (1):
  can: hi311x: Use level-triggered interrupt

Marc Kleine-Budde (5):
  can: flexcan: remove not needed struct flexcan_priv::tx_mb and struct 
flexcan_priv::tx_mb_idx
  can: dev: can_get_echo_skb(): factor out non sending code to 
__can_get_echo_skb()
  can: dev: __can_get_echo_skb(): replace struct can_frame by canfd_frame 
to access frame length
  can: dev: __can_get_echo_skb(): Don't crash the kernel if 
can_priv::echo_skb is accessed out of bounds
  can: dev: __can_get_echo_skb(): print error message, if trying to echo 
non existing skb

Oleksij Rempel (4):
  can: rx-offload: introduce can_rx_offload_get_echo_skb() and 
can_rx_offload_queue_sorted() functions
  can: flexcan: handle tx-complete CAN frames via rx-offload infrastructure
  can: rx-offload: rename can_rx_offload_irq_queue_err_skb() to 
can_rx_offload_queue_tail()
  can: flexcan: use can_rx_offload_queue_sorted() for flexcan_irq_bus_*()

Oliver Hartkopp (1):
  can: raw: check for CAN FD capable netdev in raw_sendmsg()

Pankaj Bansal (1):
  can: flexcan: Unlock the MB unconditionally

YueHaibing (2):
  can: ucan: remove set but not used variable 'udev'
  can: ucan: remove duplicated include from ucan.c

 .../devicetree/bindings/net/can/holt_hi311x.txt|   2 +-
 .../devicetree/bindings/net/can/rcar_can.txt   |  28 --
 drivers/net/can/dev.c  |  48 ++---
 drivers/net/can/flexcan.c  | 108 -
 drivers/net/can/rcar/rcar_can.c|   5 +-
 drivers/net/can/rx-offload.c   |  51 +-
 drivers/net/can/spi/hi311x.c   |   2 +-
 drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c   |   4 +-
 drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c  |  10 +-
 drivers/net/can/usb/ucan.c |   7 --
 include/linux/can/dev.h|   1 +
 include/linux/can/rx-offload.h |   7 +-
 net/can/raw.c  |  15 +--
 13 files changed, 190 insertions(+), 98 deletions(-)




[PATCH 06/20] dt-bindings: can: rcar_can: document r8a77965 support

2018-11-12 Thread Marc Kleine-Budde
From: Eugeniu Rosca 

Document the support for rcar_can on R8A77965 SoC devices.
Add R8A77965 to the list of SoCs which require the "assigned-clocks" and
"assigned-clock-rates" properties (thanks, Sergei).

Signed-off-by: Eugeniu Rosca 
Reviewed-by: Simon Horman 
Reviewed-by: Kieran Bingham 
Reviewed-by: Rob Herring 
Signed-off-by: Marc Kleine-Budde 
---
 Documentation/devicetree/bindings/net/can/rcar_can.txt | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_can.txt 
b/Documentation/devicetree/bindings/net/can/rcar_can.txt
index cc4372842bf3..47fc68148f38 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_can.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_can.txt
@@ -14,6 +14,7 @@ Required properties:
  "renesas,can-r8a7794" if CAN controller is a part of R8A7794 SoC.
  "renesas,can-r8a7795" if CAN controller is a part of R8A7795 SoC.
  "renesas,can-r8a7796" if CAN controller is a part of R8A7796 SoC.
+ "renesas,can-r8a77965" if CAN controller is a part of R8A77965 
SoC.
  "renesas,rcar-gen1-can" for a generic R-Car Gen1 compatible 
device.
  "renesas,rcar-gen2-can" for a generic R-Car Gen2 or RZ/G1
  compatible device.
@@ -29,11 +30,10 @@ Required properties:
 - pinctrl-0: pin control group to be used for this controller.
 - pinctrl-names: must be "default".
 
-Required properties for "renesas,can-r8a7795" and "renesas,can-r8a7796"
-compatible:
-In R8A7795 and R8A7796 SoCs, "clkp2" can be CANFD clock. This is a div6 clock
-and can be used by both CAN and CAN FD controller at the same time. It needs to
-be scaled to maximum frequency if any of these controllers use it. This is done
+Required properties for R8A7795, R8A7796 and R8A77965:
+For the denoted SoCs, "clkp2" can be CANFD clock. This is a div6 clock and can
+be used by both CAN and CAN FD controller at the same time. It needs to be
+scaled to maximum frequency if any of these controllers use it. This is done
 using the below properties:
 
 - assigned-clocks: phandle of clkp2(CANFD) clock.
-- 
2.19.1



Re: [PATCH v1 0/5] can: add SAE J1939 protocol

2018-10-30 Thread Marc Kleine-Budde
On 10/08/2018 11:48 AM, Oleksij Rempel wrote:
> This series adds SAE J1939 support to the current kernel v4.19-rc6.
> 
> This stack has long history, starting back in 27 Apr 2011, if not
> earlier:
> https://lists.openwall.net/netdev/2011/04/27/45
> 
> After major rework and testing it is a time to send it mainline.

I've removed some trailing newlines and added the stack to
linux-can-next/j1939.

Marc

-- 
Pengutronix e.K.          | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH can-next] can: ucan: remove duplicated include from ucan.c

2018-09-27 Thread Marc Kleine-Budde
On 08/29/2018 03:25 AM, YueHaibing wrote:
> Remove duplicated include.
> 
> Signed-off-by: YueHaibing 

Applied to linux-can.

Tnx,
Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH can-next] can: ucan: remove set but not used variable 'udev'

2018-09-27 Thread Marc Kleine-Budde
On 08/29/2018 03:46 AM, YueHaibing wrote:
> Fixes gcc '-Wunused-but-set-variable' warning:
> 
> drivers/net/can/usb/ucan.c: In function 'ucan_disconnect':
> drivers/net/can/usb/ucan.c:1578:21: warning:
>  variable 'udev' set but not used [-Wunused-but-set-variable]
>   struct usb_device *udev;
> 
> Signed-off-by: YueHaibing 

Applied to linux-can.

tnx.
Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: pull-request: can 2018-07-30

2018-07-30 Thread Marc Kleine-Budde
On 07/30/2018 06:16 PM, David Miller wrote:
> From: Marc Kleine-Budde 
> Date: Mon, 30 Jul 2018 11:08:21 +0200
> 
>> Hello David,
>>
>> this is a pull request of one patch for net/master.
>>
>> The patch by Anton Vasilyev and the Linux Driver Verification project
>> fixes a memory leak in the ems_usb driver's disconnect function.
> 
> Where is the GIT URL you want me to pull from? :)

Oops, it's definitely too hot in the office at the moment. here it it:

---

The following changes since commit 25432eba9cd8f2ef5afef55be811b010a004b5fa:

  openvswitch: meter: Fix setting meter id for new entries (2018-07-29 13:20:54 
-0700)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.18-20180730

for you to fetch changes up to 72c05f32f4a5055c9c8fe889bb6903ec959c0aad:

  can: ems_usb: Fix memory leak on ems_usb_disconnect() (2018-07-30 11:04:27 
+0200)


linux-can-fixes-for-4.18-20180730


Anton Vasilyev (1):
  can: ems_usb: Fix memory leak on ems_usb_disconnect()

 drivers/net/can/usb/ems_usb.c | 1 +
 1 file changed, 1 insertion(+)

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


[PATCH] can: ems_usb: Fix memory leak on ems_usb_disconnect()

2018-07-30 Thread Marc Kleine-Budde
From: Anton Vasilyev 

ems_usb_probe() allocates memory for dev->tx_msg_buffer, but there
is no its deallocation in ems_usb_disconnect().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/usb/ems_usb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 12ff0020ecd6..b7dfd4109d24 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -1072,6 +1072,7 @@ static void ems_usb_disconnect(struct usb_interface *intf)
usb_free_urb(dev->intr_urb);
 
kfree(dev->intr_in_buffer);
+   kfree(dev->tx_msg_buffer);
}
 }
 
-- 
2.18.0



pull-request: can 2018-07-30

2018-07-30 Thread Marc Kleine-Budde
Hello David,

this is a pull request of one patch for net/master.

The patch by Anton Vasilyev and the Linux Driver Verification project
fixes a memory leak in the ems_usb driver's disconnect function.

regards,
Marc




pull-request: can-next 2018-01-16

2018-07-27 Thread Marc Kleine-Budde
Hello David,

this is a pull request for net-next/master consisting of 38 patches.

Dan Murphy's patch fixes the path to a file in the comment of the CAN
Error Message Frame Mask structure.

A patch by Colin Ian King fixes a typo in the cc770 driver.

The next patch is by me an sorts the Kconfigand Makefile entries of the
CAN-USB driver subdir alphabetically.

The patch by Jakob Unterwurzacher adds support for the UCAN USB-CAN
adapter.

YueHaibing's patch replaces a open coded skb_put()+memset() by
skb_put_zero() in the CAN-dev infrastructure.

Zhu Yi provides a patch to enable multi-queue CAN devices.

Three patches by Luc Van Oostenryck fix the return value of several
driver's xmit function, I contribute a patch for the a fourth driver.

Fabio Estevam's patch switches the flexcan driver to SPDX identifier.

Two patches by Jia-Ju Bai replace the mdelay() by a usleep_range() in
the sja1000 drivers.

The next 6 patches are by Anssi Hannula and refactor the xilinx CAN
driver and add support for the xilinx CAN FD core.

A patch by Gustavo A. R. Silva adds fallthrough annotation to the
peak_usb driver.

5 patches by Stephane Grosjean for the peak CANFD driver do some
cleanups and provide more improvements for further firmware releases.

The remaining 13 patches are by Jimmy Assarsson and the first clean up
the kvaser_usb driver, so that the later patches add support for the
Kvaser USB hydra family.

regards,
Marc

---

The following changes since commit ecbcd689d74a394b711d2360aef7e5d007ec9d98:

  Merge tag 'mlx5e-updates-2018-07-26' of 
git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux (2018-07-26 21:33:24 
-0700)

are available in the Git repository at:

  
ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git 
tags/linux-can-next-for-4.19-20180727

for you to fetch changes up to 1f6ed42c742e8d1cfd3811ef7a134eaa75a511d6:

  can: kvaser_usb: Simplify struct kvaser_cmd_cardinfo (2018-07-27 10:40:19 
+0200)


linux-can-next-for-4.19-20180727


Anssi Hannula (6):
  can: xilinx_can: only report warning and passive states on state changes
  can: xilinx_can: use can_change_state()
  can: xilinx_can: update stats.tx_bytes after transmission
  dt-bindings: can: xilinx_can: add Xilinx CAN FD bindings
  can: xilinx_can: refactor code in preparation for CAN FD support
  can: xilinx_can: add support for Xilinx CAN FD core

Colin Ian King (1):
  can: cc770: fix spelling mistake: "comptibility" -> "compatibility"

Dan Murphy (1):
  can: uapi: can.h: Fix can error class mask dir path

Fabio Estevam (1):
  can: flexcan: Switch to SPDX identifier

Gustavo A. R. Silva (1):
  can: peak_usb: mark expected switch fall-throughs

Jakob Unterwurzacher (1):
  can: ucan: add driver for Theobroma Systems UCAN devices

Jia-Ju Bai (2):
  can: sja1000: Replace mdelay with usleep_range in peak_pci_probe
  can: sja1000: Replace mdelay with usleep_range in pcan_add_channels

Jimmy Assarsson (13):
  can: kvaser_usb: Remove unnecessary return
  can: kvaser_usb: Remove unused commands and defines
  can: kvaser_usb: Rename message/msg to command/cmd
  can: kvaser_usb: Replace USB timeout constants with one define
  can: kvaser_usb: Add pointer to struct usb_interface into struct 
kvaser_usb
  can: kvaser_usb: Refactor kvaser_usb_get_endpoints()
  can: kvaser_usb: Refactor kvaser_usb_init_one()
  can: kvaser_usb: Improve logging messages
  can: kvaser_usb: Fix typos
  can: kvaser_usb: Add SPDX GPL-2.0 license identifier
  can: kvaser_usb: Split driver into kvaser_usb_core.c and kvaser_usb_leaf.c
  can: kvaser_usb: Add support for Kvaser USB hydra family
  can: kvaser_usb: Simplify struct kvaser_cmd_cardinfo

Luc Van Oostenryck (3):
  can: janz-ican3: fix ican3_xmit()'s return type
  can: sun4i: fix sun4ican_start_xmit()'s return type
  can: xilinx: fix xcan_start_xmit()'s return type

Marc Kleine-Budde (2):
  can: usb: Kconfig/Makefile: sort alphabetically
  can: flexcan: fix flexcan_start_xmit()'s return type

Stephane Grosjean (5):
  can: peak_canfd: improves 32-bit alignment
  can: peak_canfd: remove useless defined symbols
  can: peak_canfd: use ndev irq instead of pci_dev one
  can: peak_canfd: fix typo in error message
  can: peak_canfd: rearrange the way resources are released

YueHaibing (1):
  can: dev: use skb_put_zero to simplfy code

Zhu Yi (1):
  can: dev: enable multi-queue for SocketCAN devices

 .../devicetree/bindings/net/can/xilinx_can.txt |   35 +-
 Documentation/networking/can_ucan_protocol.rst |  332 
 Documentation/networking/index.rst |1 +
 drivers/net/can/cc770/cc770.c  |2 +-
 drivers/net/can/dev.c  |  

Re: pull-request: can 2018-07-23

2018-07-26 Thread Marc Kleine-Budde
On 07/26/2018 01:26 AM, David Miller wrote:
> From: Marc Kleine-Budde 
> Date: Tue, 24 Jul 2018 09:27:30 +0200
> 
>> Thanks David. Can you please merge net into next-next, as I've some
>> patches for net-next that would result in a merge conflict between net
>> and net-next later.
> 
> This has now been done.

Thanks.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: pull-request: can 2018-07-23

2018-07-24 Thread Marc Kleine-Budde
On 07/23/2018 08:02 PM, David Miller wrote:
> From: Marc Kleine-Budde 
> Date: Mon, 23 Jul 2018 14:58:31 +0200
> 
>> this is a pull request of 12 patches for net/master.
>>
>> The patch by Stephane Grosjean for the peak_canfd CAN driver fixes a problem
>> with older firmware. The next patch is by Roman Fietze and fixes the setup of
>> the CCCR register in the m_can driver. Nicholas Mc Guire's patch for the
>> mpc5xxx_can driver adds missing error checking. The two patches by Faiz Abbas
>> fix the runtime resume and clean up the probe function in the m_can driver. 
>> The
>> last 7 patches by Anssi Hannula fix several problem in the xilinx_can driver.
> 
> Pulled, thanks Marc.

Thanks David. Can you please merge net into next-next, as I've some
patches for net-next that would result in a merge conflict between net
and net-next later.

regards,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


[PATCH 03/12] can: mpc5xxx_can: check of_iomap return before use

2018-07-23 Thread Marc Kleine-Budde
From: Nicholas Mc Guire 

of_iomap() can return NULL so that return needs to be checked and NULL
treated as failure. While at it also take care of the missing
of_node_put() in the error path.

Signed-off-by: Nicholas Mc Guire 
Fixes: commit afa17a500a36 ("net/can: add driver for mscan family & 
mpc52xx_mscan")
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/mscan/mpc5xxx_can.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/can/mscan/mpc5xxx_can.c 
b/drivers/net/can/mscan/mpc5xxx_can.c
index c7427bdd3a4b..2949a381a94d 100644
--- a/drivers/net/can/mscan/mpc5xxx_can.c
+++ b/drivers/net/can/mscan/mpc5xxx_can.c
@@ -86,6 +86,11 @@ static u32 mpc52xx_can_get_clock(struct platform_device 
*ofdev,
return 0;
}
cdm = of_iomap(np_cdm, 0);
+   if (!cdm) {
+   of_node_put(np_cdm);
+   dev_err(>dev, "can't map clock node!\n");
+   return 0;
+   }
 
if (in_8(>ipb_clk_sel) & 0x1)
freq *= 2;
-- 
2.18.0



[PATCH 01/12] can: peak_canfd: fix firmware < v3.3.0: limit allocation to 32-bit DMA addr only

2018-07-23 Thread Marc Kleine-Budde
From: Stephane Grosjean 

The DMA logic in firmwares < v3.3.0 embedded in the PCAN-PCIe FD cards
family is not capable of handling a mix of 32-bit and 64-bit logical
addresses. If the board is equipped with 2 or 4 CAN ports, then such a
situation might lead to a PCIe Bus Error "Malformed TLP" packet
as well as "irq xx: nobody cared" issue.

This patch adds a workaround that requests only 32-bit DMA addresses
when these might be allocated outside of the 4 GB area.

This issue has been fixed in firmware v3.3.0 and next.

Signed-off-by: Stephane Grosjean 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/peak_canfd/peak_pciefd_main.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/drivers/net/can/peak_canfd/peak_pciefd_main.c 
b/drivers/net/can/peak_canfd/peak_pciefd_main.c
index b9e28578bc7b..455a3797a200 100644
--- a/drivers/net/can/peak_canfd/peak_pciefd_main.c
+++ b/drivers/net/can/peak_canfd/peak_pciefd_main.c
@@ -58,6 +58,10 @@ MODULE_LICENSE("GPL v2");
 #define PCIEFD_REG_SYS_VER10x0040  /* version reg #1 */
 #define PCIEFD_REG_SYS_VER20x0044  /* version reg #2 */
 
+#define PCIEFD_FW_VERSION(x, y, z) (((u32)(x) << 24) | \
+((u32)(y) << 16) | \
+((u32)(z) << 8))
+
 /* System Control Registers Bits */
 #define PCIEFD_SYS_CTL_TS_RST  0x0001  /* timestamp clock */
 #define PCIEFD_SYS_CTL_CLK_EN  0x0002  /* system clock */
@@ -782,6 +786,21 @@ static int peak_pciefd_probe(struct pci_dev *pdev,
 "%ux CAN-FD PCAN-PCIe FPGA v%u.%u.%u:\n", can_count,
 hw_ver_major, hw_ver_minor, hw_ver_sub);
 
+#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
+   /* FW < v3.3.0 DMA logic doesn't handle correctly the mix of 32-bit and
+* 64-bit logical addresses: this workaround forces usage of 32-bit
+* DMA addresses only when such a fw is detected.
+*/
+   if (PCIEFD_FW_VERSION(hw_ver_major, hw_ver_minor, hw_ver_sub) <
+   PCIEFD_FW_VERSION(3, 3, 0)) {
+   err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32));
+   if (err)
+   dev_warn(>dev,
+"warning: can't set DMA mask %llxh (err %d)\n",
+DMA_BIT_MASK(32), err);
+   }
+#endif
+
/* stop system clock */
pciefd_sys_writereg(pciefd, PCIEFD_SYS_CTL_CLK_EN,
PCIEFD_REG_SYS_CTL_CLR);
-- 
2.18.0



[PATCH 04/12] can: m_can: Fix runtime resume call

2018-07-23 Thread Marc Kleine-Budde
From: Faiz Abbas 

pm_runtime_get_sync() returns a 1 if the state of the device is already
'active'. This is not a failure case and should return a success.

Therefore fix error handling for pm_runtime_get_sync() call such that
it returns success when the value is 1.

Also cleanup the TODO for using runtime PM for sleep mode as that is
implemented.

Signed-off-by: Faiz Abbas 
Cc: 
---
 drivers/net/can/m_can/m_can.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 8e2b7f873c4d..e2f965c2e3aa 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -634,10 +634,12 @@ static int m_can_clk_start(struct m_can_priv *priv)
int err;
 
err = pm_runtime_get_sync(priv->device);
-   if (err)
+   if (err < 0) {
pm_runtime_put_noidle(priv->device);
+   return err;
+   }
 
-   return err;
+   return 0;
 }
 
 static void m_can_clk_stop(struct m_can_priv *priv)
@@ -1688,8 +1690,6 @@ static int m_can_plat_probe(struct platform_device *pdev)
return ret;
 }
 
-/* TODO: runtime PM with power down or sleep mode  */
-
 static __maybe_unused int m_can_suspend(struct device *dev)
 {
struct net_device *ndev = dev_get_drvdata(dev);
-- 
2.18.0



[PATCH 05/12] can: m_can: Move accessing of message ram to after clocks are enabled

2018-07-23 Thread Marc Kleine-Budde
From: Faiz Abbas 

MCAN message ram should only be accessed once clocks are enabled.
Therefore, move the call to parse/init the message ram to after
clocks are enabled.

Signed-off-by: Faiz Abbas 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/m_can/m_can.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index e2f965c2e3aa..9b449400376b 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1645,8 +1645,6 @@ static int m_can_plat_probe(struct platform_device *pdev)
priv->can.clock.freq = clk_get_rate(cclk);
priv->mram_base = mram_addr;
 
-   m_can_of_parse_mram(priv, mram_config_vals);
-
platform_set_drvdata(pdev, dev);
SET_NETDEV_DEV(dev, >dev);
 
@@ -1669,6 +1667,8 @@ static int m_can_plat_probe(struct platform_device *pdev)
goto clk_disable;
}
 
+   m_can_of_parse_mram(priv, mram_config_vals);
+
devm_can_led_init(dev);
 
of_can_transceiver(dev);
@@ -1716,8 +1716,6 @@ static __maybe_unused int m_can_resume(struct device *dev)
 
pinctrl_pm_select_default_state(dev);
 
-   m_can_init_ram(priv);
-
priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
if (netif_running(ndev)) {
@@ -1727,6 +1725,7 @@ static __maybe_unused int m_can_resume(struct device *dev)
if (ret)
return ret;
 
+   m_can_init_ram(priv);
m_can_start(ndev);
netif_device_attach(ndev);
netif_start_queue(ndev);
-- 
2.18.0



[PATCH 06/12] can: xilinx_can: fix device dropping off bus on RX overrun

2018-07-23 Thread Marc Kleine-Budde
From: Anssi Hannula 

The xilinx_can driver performs a software reset when an RX overrun is
detected. This causes the device to enter Configuration mode where no
messages are received or transmitted.

The documentation does not mention any need to perform a reset on an RX
overrun, and testing by inducing an RX overflow also indicated that the
device continues to work just fine without a reset.

Remove the software reset.

Tested with the integrated CAN on Zynq-7000 SoC.

Fixes: b1201e44f50b ("can: xilinx CAN controller support")
Signed-off-by: Anssi Hannula 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/xilinx_can.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 89aec07c225f..389a9603db8c 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -600,7 +600,6 @@ static void xcan_err_interrupt(struct net_device *ndev, u32 
isr)
if (isr & XCAN_IXR_RXOFLW_MASK) {
stats->rx_over_errors++;
stats->rx_errors++;
-   priv->write_reg(priv, XCAN_SRR_OFFSET, XCAN_SRR_RESET_MASK);
if (skb) {
cf->can_id |= CAN_ERR_CRTL;
cf->data[1] |= CAN_ERR_CRTL_RX_OVERFLOW;
-- 
2.18.0



[PATCH 09/12] can: xilinx_can: keep only 1-2 frames in TX FIFO to fix TX accounting

2018-07-23 Thread Marc Kleine-Budde
From: Anssi Hannula 

The xilinx_can driver assumes that the TXOK interrupt only clears after
it has been acknowledged as many times as there have been successfully
sent frames.

However, the documentation does not mention such behavior, instead
saying just that the interrupt is cleared when the clear bit is set.

Similarly, testing seems to also suggest that it is immediately cleared
regardless of the amount of frames having been sent. Performing some
heavy TX load and then going back to idle has the tx_head drifting
further away from tx_tail over time, steadily reducing the amount of
frames the driver keeps in the TX FIFO (but not to zero, as the TXOK
interrupt always frees up space for 1 frame from the driver's
perspective, so frames continue to be sent) and delaying the local echo
frames.

The TX FIFO tracking is also otherwise buggy as it does not account for
TX FIFO being cleared after software resets, causing
  BUG!, TX FIFO full when queue awake!
messages to be output.

There does not seem to be any way to accurately track the state of the
TX FIFO for local echo support while using the full TX FIFO.

The Zynq version of the HW (but not the soft-AXI version) has watermark
programming support and with it an additional TX-FIFO-empty interrupt
bit.

Modify the driver to only put 1 frame into TX FIFO at a time on soft-AXI
and 2 frames at a time on Zynq. On Zynq the TXFEMP interrupt bit is used
to detect whether 1 or 2 frames have been sent at interrupt processing
time.

Tested with the integrated CAN on Zynq-7000 SoC. The 1-frame-FIFO mode
was also tested.

An alternative way to solve this would be to drop local echo support but
keep using the full TX FIFO.

v2: Add FIFO space check before TX queue wake with locking to
synchronize with queue stop. This avoids waking the queue when xmit()
had just filled it.

v3: Keep local echo support and reduce the amount of frames in FIFO
instead as suggested by Marc Kleine-Budde.

Fixes: b1201e44f50b ("can: xilinx CAN controller support")
Signed-off-by: Anssi Hannula 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/xilinx_can.c | 139 +++
 1 file changed, 123 insertions(+), 16 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 763408a3eafb..dcbdc3cd651c 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -26,8 +26,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -119,6 +121,7 @@ enum xcan_reg {
 /**
  * struct xcan_priv - This definition define CAN driver instance
  * @can:   CAN private data structure.
+ * @tx_lock:   Lock for synchronizing TX interrupt handling
  * @tx_head:   Tx CAN packets ready to send on the queue
  * @tx_tail:   Tx CAN packets successfully sended on the queue
  * @tx_max:Maximum number packets the driver can send
@@ -133,6 +136,7 @@ enum xcan_reg {
  */
 struct xcan_priv {
struct can_priv can;
+   spinlock_t tx_lock;
unsigned int tx_head;
unsigned int tx_tail;
unsigned int tx_max;
@@ -160,6 +164,11 @@ static const struct can_bittiming_const 
xcan_bittiming_const = {
.brp_inc = 1,
 };
 
+#define XCAN_CAP_WATERMARK 0x0001
+struct xcan_devtype_data {
+   unsigned int caps;
+};
+
 /**
  * xcan_write_reg_le - Write a value to the device register little endian
  * @priv:  Driver private data structure
@@ -239,6 +248,10 @@ static int set_reset_mode(struct net_device *ndev)
usleep_range(500, 1);
}
 
+   /* reset clears FIFOs */
+   priv->tx_head = 0;
+   priv->tx_tail = 0;
+
return 0;
 }
 
@@ -393,6 +406,7 @@ static int xcan_start_xmit(struct sk_buff *skb, struct 
net_device *ndev)
struct net_device_stats *stats = >stats;
struct can_frame *cf = (struct can_frame *)skb->data;
u32 id, dlc, data[2] = {0, 0};
+   unsigned long flags;
 
if (can_dropped_invalid_skb(ndev, skb))
return NETDEV_TX_OK;
@@ -440,6 +454,9 @@ static int xcan_start_xmit(struct sk_buff *skb, struct 
net_device *ndev)
data[1] = be32_to_cpup((__be32 *)(cf->data + 4));
 
can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max);
+
+   spin_lock_irqsave(>tx_lock, flags);
+
priv->tx_head++;
 
/* Write the Frame to Xilinx CAN TX FIFO */
@@ -455,10 +472,16 @@ static int xcan_start_xmit(struct sk_buff *skb, struct 
net_device *ndev)
stats->tx_bytes += cf->can_dlc;
}
 
+   /* Clear TX-FIFO-empty interrupt for xcan_tx_interrupt() */
+   if (priv->tx_max > 1)
+   priv->write_reg(priv, XCAN_ICR_OFFSET, XCAN_IXR_TXFEMP_MASK);
+
/* Check if the TX buffer is full */
if ((priv->tx_head - priv->tx_ta

[PATCH 11/12] can: xilinx_can: fix incorrect clear of non-processed interrupts

2018-07-23 Thread Marc Kleine-Budde
From: Anssi Hannula 

xcan_interrupt() clears ERROR|RXOFLV|BSOFF|ARBLST interrupts if any of
them is asserted. This does not take into account that some of them
could have been asserted between interrupt status read and interrupt
clear, therefore clearing them without handling them.

Fix the code to only clear those interrupts that it knows are asserted
and therefore going to be processed in xcan_err_interrupt().

Fixes: b1201e44f50b ("can: xilinx CAN controller support")
Signed-off-by: Anssi Hannula 
Cc: Michal Simek 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/xilinx_can.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index ea9f9d1a5ba7..cb80a9aa7281 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -938,6 +938,7 @@ static irqreturn_t xcan_interrupt(int irq, void *dev_id)
struct net_device *ndev = (struct net_device *)dev_id;
struct xcan_priv *priv = netdev_priv(ndev);
u32 isr, ier;
+   u32 isr_errors;
 
/* Get the interrupt status from Xilinx CAN */
isr = priv->read_reg(priv, XCAN_ISR_OFFSET);
@@ -956,11 +957,10 @@ static irqreturn_t xcan_interrupt(int irq, void *dev_id)
xcan_tx_interrupt(ndev, isr);
 
/* Check for the type of error interrupt and Processing it */
-   if (isr & (XCAN_IXR_ERROR_MASK | XCAN_IXR_RXOFLW_MASK |
-   XCAN_IXR_BSOFF_MASK | XCAN_IXR_ARBLST_MASK)) {
-   priv->write_reg(priv, XCAN_ICR_OFFSET, (XCAN_IXR_ERROR_MASK |
-   XCAN_IXR_RXOFLW_MASK | XCAN_IXR_BSOFF_MASK |
-   XCAN_IXR_ARBLST_MASK));
+   isr_errors = isr & (XCAN_IXR_ERROR_MASK | XCAN_IXR_RXOFLW_MASK |
+   XCAN_IXR_BSOFF_MASK | XCAN_IXR_ARBLST_MASK);
+   if (isr_errors) {
+   priv->write_reg(priv, XCAN_ICR_OFFSET, isr_errors);
xcan_err_interrupt(ndev, isr);
}
 
-- 
2.18.0



[PATCH 08/12] can: xilinx_can: fix recovery from error states not being propagated

2018-07-23 Thread Marc Kleine-Budde
From: Anssi Hannula 

The xilinx_can driver contains no mechanism for propagating recovery
from CAN_STATE_ERROR_WARNING and CAN_STATE_ERROR_PASSIVE.

Add such a mechanism by factoring the handling of
XCAN_STATE_ERROR_PASSIVE and XCAN_STATE_ERROR_WARNING out of
xcan_err_interrupt and checking for recovery after RX and TX if the
interface is in one of those states.

Tested with the integrated CAN on Zynq-7000 SoC.

Fixes: b1201e44f50b ("can: xilinx CAN controller support")
Signed-off-by: Anssi Hannula 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/xilinx_can.c | 155 ---
 1 file changed, 127 insertions(+), 28 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 1bda47aa62f5..763408a3eafb 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2012 - 2014 Xilinx, Inc.
  * Copyright (C) 2009 PetaLogix. All rights reserved.
+ * Copyright (C) 2017 Sandvik Mining and Construction Oy
  *
  * Description:
  * This driver is developed for Axi CAN IP and for Zynq CANPS Controller.
@@ -529,6 +530,123 @@ static int xcan_rx(struct net_device *ndev)
return 1;
 }
 
+/**
+ * xcan_current_error_state - Get current error state from HW
+ * @ndev:  Pointer to net_device structure
+ *
+ * Checks the current CAN error state from the HW. Note that this
+ * only checks for ERROR_PASSIVE and ERROR_WARNING.
+ *
+ * Return:
+ * ERROR_PASSIVE or ERROR_WARNING if either is active, ERROR_ACTIVE
+ * otherwise.
+ */
+static enum can_state xcan_current_error_state(struct net_device *ndev)
+{
+   struct xcan_priv *priv = netdev_priv(ndev);
+   u32 status = priv->read_reg(priv, XCAN_SR_OFFSET);
+
+   if ((status & XCAN_SR_ESTAT_MASK) == XCAN_SR_ESTAT_MASK)
+   return CAN_STATE_ERROR_PASSIVE;
+   else if (status & XCAN_SR_ERRWRN_MASK)
+   return CAN_STATE_ERROR_WARNING;
+   else
+   return CAN_STATE_ERROR_ACTIVE;
+}
+
+/**
+ * xcan_set_error_state - Set new CAN error state
+ * @ndev:  Pointer to net_device structure
+ * @new_state: The new CAN state to be set
+ * @cf:Error frame to be populated or NULL
+ *
+ * Set new CAN error state for the device, updating statistics and
+ * populating the error frame if given.
+ */
+static void xcan_set_error_state(struct net_device *ndev,
+enum can_state new_state,
+struct can_frame *cf)
+{
+   struct xcan_priv *priv = netdev_priv(ndev);
+   u32 ecr = priv->read_reg(priv, XCAN_ECR_OFFSET);
+   u32 txerr = ecr & XCAN_ECR_TEC_MASK;
+   u32 rxerr = (ecr & XCAN_ECR_REC_MASK) >> XCAN_ESR_REC_SHIFT;
+
+   priv->can.state = new_state;
+
+   if (cf) {
+   cf->can_id |= CAN_ERR_CRTL;
+   cf->data[6] = txerr;
+   cf->data[7] = rxerr;
+   }
+
+   switch (new_state) {
+   case CAN_STATE_ERROR_PASSIVE:
+   priv->can.can_stats.error_passive++;
+   if (cf)
+   cf->data[1] = (rxerr > 127) ?
+   CAN_ERR_CRTL_RX_PASSIVE :
+   CAN_ERR_CRTL_TX_PASSIVE;
+   break;
+   case CAN_STATE_ERROR_WARNING:
+   priv->can.can_stats.error_warning++;
+   if (cf)
+   cf->data[1] |= (txerr > rxerr) ?
+   CAN_ERR_CRTL_TX_WARNING :
+   CAN_ERR_CRTL_RX_WARNING;
+   break;
+   case CAN_STATE_ERROR_ACTIVE:
+   if (cf)
+   cf->data[1] |= CAN_ERR_CRTL_ACTIVE;
+   break;
+   default:
+   /* non-ERROR states are handled elsewhere */
+   WARN_ON(1);
+   break;
+   }
+}
+
+/**
+ * xcan_update_error_state_after_rxtx - Update CAN error state after RX/TX
+ * @ndev:  Pointer to net_device structure
+ *
+ * If the device is in a ERROR-WARNING or ERROR-PASSIVE state, check if
+ * the performed RX/TX has caused it to drop to a lesser state and set
+ * the interface state accordingly.
+ */
+static void xcan_update_error_state_after_rxtx(struct net_device *ndev)
+{
+   struct xcan_priv *priv = netdev_priv(ndev);
+   enum can_state old_state = priv->can.state;
+   enum can_state new_state;
+
+   /* changing error state due to successful frame RX/TX can only
+* occur from these states
+*/
+   if (old_state != CAN_STATE_ERROR_WARNING &&
+   old_state != CAN_STATE_ERROR_PASSIVE)
+   return;
+
+   new_state = xcan_current_error_state(ndev);
+
+   if (new_state != old_state) {
+   struct sk_buff *skb;
+   struct can_frame *cf;
+
+   skb = alloc_can_err_sk

[PATCH 07/12] can: xilinx_can: fix RX loop if RXNEMP is asserted without RXOK

2018-07-23 Thread Marc Kleine-Budde
From: Anssi Hannula 

If the device gets into a state where RXNEMP (RX FIFO not empty)
interrupt is asserted without RXOK (new frame received successfully)
interrupt being asserted, xcan_rx_poll() will continue to try to clear
RXNEMP without actually reading frames from RX FIFO. If the RX FIFO is
not empty, the interrupt will not be cleared and napi_schedule() will
just be called again.

This situation can occur when:

(a) xcan_rx() returns without reading RX FIFO due to an error condition.
The code tries to clear both RXOK and RXNEMP but RXNEMP will not clear
due to a frame still being in the FIFO. The frame will never be read
from the FIFO as RXOK is no longer set.

(b) A frame is received between xcan_rx_poll() reading interrupt status
and clearing RXOK. RXOK will be cleared, but RXNEMP will again remain
set as the new message is still in the FIFO.

I'm able to trigger case (b) by flooding the bus with frames under load.

There does not seem to be any benefit in using both RXNEMP and RXOK in
the way the driver does, and the polling example in the reference manual
(UG585 v1.10 18.3.7 Read Messages from RxFIFO) also says that either
RXOK or RXNEMP can be used for detecting incoming messages.

Fix the issue and simplify the RX processing by only using RXNEMP
without RXOK.

Tested with the integrated CAN on Zynq-7000 SoC.

Fixes: b1201e44f50b ("can: xilinx CAN controller support")
Signed-off-by: Anssi Hannula 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/xilinx_can.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 389a9603db8c..1bda47aa62f5 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -101,7 +101,7 @@ enum xcan_reg {
 #define XCAN_INTR_ALL  (XCAN_IXR_TXOK_MASK | XCAN_IXR_BSOFF_MASK |\
 XCAN_IXR_WKUP_MASK | XCAN_IXR_SLP_MASK | \
 XCAN_IXR_RXNEMP_MASK | XCAN_IXR_ERROR_MASK | \
-XCAN_IXR_ARBLST_MASK | XCAN_IXR_RXOK_MASK)
+XCAN_IXR_ARBLST_MASK)
 
 /* CAN register bit shift - XCAN___SHIFT */
 #define XCAN_BTR_SJW_SHIFT 7  /* Synchronous jump width */
@@ -708,15 +708,7 @@ static int xcan_rx_poll(struct napi_struct *napi, int 
quota)
 
isr = priv->read_reg(priv, XCAN_ISR_OFFSET);
while ((isr & XCAN_IXR_RXNEMP_MASK) && (work_done < quota)) {
-   if (isr & XCAN_IXR_RXOK_MASK) {
-   priv->write_reg(priv, XCAN_ICR_OFFSET,
-   XCAN_IXR_RXOK_MASK);
-   work_done += xcan_rx(ndev);
-   } else {
-   priv->write_reg(priv, XCAN_ICR_OFFSET,
-   XCAN_IXR_RXNEMP_MASK);
-   break;
-   }
+   work_done += xcan_rx(ndev);
priv->write_reg(priv, XCAN_ICR_OFFSET, XCAN_IXR_RXNEMP_MASK);
isr = priv->read_reg(priv, XCAN_ISR_OFFSET);
}
@@ -727,7 +719,7 @@ static int xcan_rx_poll(struct napi_struct *napi, int quota)
if (work_done < quota) {
napi_complete_done(napi, work_done);
ier = priv->read_reg(priv, XCAN_IER_OFFSET);
-   ier |= (XCAN_IXR_RXOK_MASK | XCAN_IXR_RXNEMP_MASK);
+   ier |= XCAN_IXR_RXNEMP_MASK;
priv->write_reg(priv, XCAN_IER_OFFSET, ier);
}
return work_done;
@@ -799,9 +791,9 @@ static irqreturn_t xcan_interrupt(int irq, void *dev_id)
}
 
/* Check for the type of receive interrupt and Processing it */
-   if (isr & (XCAN_IXR_RXNEMP_MASK | XCAN_IXR_RXOK_MASK)) {
+   if (isr & XCAN_IXR_RXNEMP_MASK) {
ier = priv->read_reg(priv, XCAN_IER_OFFSET);
-   ier &= ~(XCAN_IXR_RXNEMP_MASK | XCAN_IXR_RXOK_MASK);
+   ier &= ~XCAN_IXR_RXNEMP_MASK;
priv->write_reg(priv, XCAN_IER_OFFSET, ier);
napi_schedule(>napi);
}
-- 
2.18.0



[PATCH 12/12] can: xilinx_can: fix power management handling

2018-07-23 Thread Marc Kleine-Budde
From: Anssi Hannula 

There are several issues with the suspend/resume handling code of the
driver:

- The device is attached and detached in the runtime_suspend() and
  runtime_resume() callbacks if the interface is running. However,
  during xcan_chip_start() the interface is considered running,
  causing the resume handler to incorrectly call netif_start_queue()
  at the beginning of xcan_chip_start(), and on xcan_chip_start() error
  return the suspend handler detaches the device leaving the user
  unable to bring-up the device anymore.

- The device is not brought properly up on system resume. A reset is
  done and the code tries to determine the bus state after that.
  However, after reset the device is always in Configuration mode
  (down), so the state checking code does not make sense and
  communication will also not work.

- The suspend callback tries to set the device to sleep mode (low-power
  mode which monitors the bus and brings the device back to normal mode
  on activity), but then immediately disables the clocks (possibly
  before the device reaches the sleep mode), which does not make sense
  to me. If a clean shutdown is wanted before disabling clocks, we can
  just bring it down completely instead of only sleep mode.

Reorganize the PM code so that only the clock logic remains in the
runtime PM callbacks and the system PM callbacks contain the device
bring-up/down logic. This makes calling the runtime PM callbacks during
e.g. xcan_chip_start() safe.

The system PM callbacks now simply call common code to start/stop the
HW if the interface was running, replacing the broken code from before.

xcan_chip_stop() is updated to use the common reset code so that it will
wait for the reset to complete. Reset also disables all interrupts so do
not do that separately.

Also, the device_may_wakeup() checks are removed as the driver does not
have wakeup support.

Tested on Zynq-7000 integrated CAN.

Signed-off-by: Anssi Hannula 
Cc: Michal Simek 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/xilinx_can.c | 69 +++-
 1 file changed, 28 insertions(+), 41 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index cb80a9aa7281..5a24039733ef 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -984,13 +984,9 @@ static irqreturn_t xcan_interrupt(int irq, void *dev_id)
 static void xcan_chip_stop(struct net_device *ndev)
 {
struct xcan_priv *priv = netdev_priv(ndev);
-   u32 ier;
 
/* Disable interrupts and leave the can in configuration mode */
-   ier = priv->read_reg(priv, XCAN_IER_OFFSET);
-   ier &= ~XCAN_INTR_ALL;
-   priv->write_reg(priv, XCAN_IER_OFFSET, ier);
-   priv->write_reg(priv, XCAN_SRR_OFFSET, XCAN_SRR_RESET_MASK);
+   set_reset_mode(ndev);
priv->can.state = CAN_STATE_STOPPED;
 }
 
@@ -1123,10 +1119,15 @@ static const struct net_device_ops xcan_netdev_ops = {
  */
 static int __maybe_unused xcan_suspend(struct device *dev)
 {
-   if (!device_may_wakeup(dev))
-   return pm_runtime_force_suspend(dev);
+   struct net_device *ndev = dev_get_drvdata(dev);
 
-   return 0;
+   if (netif_running(ndev)) {
+   netif_stop_queue(ndev);
+   netif_device_detach(ndev);
+   xcan_chip_stop(ndev);
+   }
+
+   return pm_runtime_force_suspend(dev);
 }
 
 /**
@@ -1138,11 +1139,27 @@ static int __maybe_unused xcan_suspend(struct device 
*dev)
  */
 static int __maybe_unused xcan_resume(struct device *dev)
 {
-   if (!device_may_wakeup(dev))
-   return pm_runtime_force_resume(dev);
+   struct net_device *ndev = dev_get_drvdata(dev);
+   int ret;
 
-   return 0;
+   ret = pm_runtime_force_resume(dev);
+   if (ret) {
+   dev_err(dev, "pm_runtime_force_resume failed on resume\n");
+   return ret;
+   }
+
+   if (netif_running(ndev)) {
+   ret = xcan_chip_start(ndev);
+   if (ret) {
+   dev_err(dev, "xcan_chip_start failed on resume\n");
+   return ret;
+   }
 
+   netif_device_attach(ndev);
+   netif_start_queue(ndev);
+   }
+
+   return 0;
 }
 
 /**
@@ -1157,14 +1174,6 @@ static int __maybe_unused xcan_runtime_suspend(struct 
device *dev)
struct net_device *ndev = dev_get_drvdata(dev);
struct xcan_priv *priv = netdev_priv(ndev);
 
-   if (netif_running(ndev)) {
-   netif_stop_queue(ndev);
-   netif_device_detach(ndev);
-   }
-
-   priv->write_reg(priv, XCAN_MSR_OFFSET, XCAN_MSR_SLEEP_MASK);
-   priv->can.state = CAN_STATE_SLEEPING;
-
clk_disable_unprepare(priv->bus_clk);
clk_disable_unprepare(priv->can_clk);
 
@@ -1183,7 +1192,6 @@ static int __maybe_unused xcan_runtime_resume(struct 
device *dev)
 

[PATCH 10/12] can: xilinx_can: fix RX overflow interrupt not being enabled

2018-07-23 Thread Marc Kleine-Budde
From: Anssi Hannula 

RX overflow interrupt (RXOFLW) is disabled even though xcan_interrupt()
processes it. This means that an RX overflow interrupt will only be
processed when another interrupt gets asserted (e.g. for RX/TX).

Fix that by enabling the RXOFLW interrupt.

Fixes: b1201e44f50b ("can: xilinx CAN controller support")
Signed-off-by: Anssi Hannula 
Cc: Michal Simek 
Cc: 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/xilinx_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index dcbdc3cd651c..ea9f9d1a5ba7 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -104,7 +104,7 @@ enum xcan_reg {
 #define XCAN_INTR_ALL  (XCAN_IXR_TXOK_MASK | XCAN_IXR_BSOFF_MASK |\
 XCAN_IXR_WKUP_MASK | XCAN_IXR_SLP_MASK | \
 XCAN_IXR_RXNEMP_MASK | XCAN_IXR_ERROR_MASK | \
-XCAN_IXR_ARBLST_MASK)
+XCAN_IXR_RXOFLW_MASK | XCAN_IXR_ARBLST_MASK)
 
 /* CAN register bit shift - XCAN___SHIFT */
 #define XCAN_BTR_SJW_SHIFT 7  /* Synchronous jump width */
-- 
2.18.0



pull-request: can 2018-07-23

2018-07-23 Thread Marc Kleine-Budde
Hello David,

this is a pull request of 12 patches for net/master.

The patch by Stephane Grosjean for the peak_canfd CAN driver fixes a problem
with older firmware. The next patch is by Roman Fietze and fixes the setup of
the CCCR register in the m_can driver. Nicholas Mc Guire's patch for the
mpc5xxx_can driver adds missing error checking. The two patches by Faiz Abbas
fix the runtime resume and clean up the probe function in the m_can driver. The
last 7 patches by Anssi Hannula fix several problem in the xilinx_can driver.

regards,
Marc

---

The following changes since commit c9ce1fa1c24b08e13c2a3b5b1f94a19c9eaa982c:

  net: prevent ISA drivers from building on PPC32 (2018-07-22 11:12:29 -0700)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.18-20180723

for you to fetch changes up to 8ebd83bdb027f29870d96649dba18b91581ea829:

  can: xilinx_can: fix power management handling (2018-07-23 14:34:46 +0200)


linux-can-fixes-for-4.18-20180723


Anssi Hannula (7):
  can: xilinx_can: fix device dropping off bus on RX overrun
  can: xilinx_can: fix RX loop if RXNEMP is asserted without RXOK
  can: xilinx_can: fix recovery from error states not being propagated
  can: xilinx_can: keep only 1-2 frames in TX FIFO to fix TX accounting
  can: xilinx_can: fix RX overflow interrupt not being enabled
  can: xilinx_can: fix incorrect clear of non-processed interrupts
  can: xilinx_can: fix power management handling

Faiz Abbas (2):
  can: m_can: Fix runtime resume call
  can: m_can: Move accessing of message ram to after clocks are enabled

Nicholas Mc Guire (1):
  can: mpc5xxx_can: check of_iomap return before use

Roman Fietze (1):
  can: m_can.c: fix setup of CCCR register: clear CCCR NISO bit before 
checking can.ctrlmode

Stephane Grosjean (1):
  can: peak_canfd: fix firmware < v3.3.0: limit allocation to 32-bit DMA 
addr only

 drivers/net/can/m_can/m_can.c |  18 +-
 drivers/net/can/mscan/mpc5xxx_can.c   |   5 +
 drivers/net/can/peak_canfd/peak_pciefd_main.c |  19 ++
 drivers/net/can/xilinx_can.c  | 392 +++---
 4 files changed, 321 insertions(+), 113 deletions(-)




[PATCH 02/12] can: m_can.c: fix setup of CCCR register: clear CCCR NISO bit before checking can.ctrlmode

2018-07-23 Thread Marc Kleine-Budde
From: Roman Fietze 

Inside m_can_chip_config(), when setting up the new value of the CCCR,
the CCCR_NISO bit is not cleared like the others, CCCR_TEST, CCCR_MON,
CCCR_BRSE and CCCR_FDOE, before checking the can.ctrlmode bits for
CAN_CTRLMODE_FD_NON_ISO.

This way once the controller was configured for CAN_CTRLMODE_FD_NON_ISO,
this mode could never be cleared again.

This fix is only relevant for controllers with version 3.1.x or 3.2.x.
Older versions do not support NISO.

Signed-off-by: Roman Fietze 
Cc: linux-stable 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/net/can/m_can/m_can.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index b397a33f3d32..8e2b7f873c4d 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1109,7 +1109,8 @@ static void m_can_chip_config(struct net_device *dev)
 
} else {
/* Version 3.1.x or 3.2.x */
-   cccr &= ~(CCCR_TEST | CCCR_MON | CCCR_BRSE | CCCR_FDOE);
+   cccr &= ~(CCCR_TEST | CCCR_MON | CCCR_BRSE | CCCR_FDOE |
+ CCCR_NISO);
 
/* Only 3.2.x has NISO Bit implemented */
if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
-- 
2.18.0



[PATCH 2/2] can: hi311x: Work around TX complete interrupt erratum

2018-05-10 Thread Marc Kleine-Budde
From: Lukas Wunner <lu...@wunner.de>

When sending packets as fast as possible using "cangen -g 0 -i -x", the
HI-3110 occasionally latches the interrupt pin high on completion of a
packet, but doesn't set the TXCPLT bit in the INTF register.  The INTF
register contains 0x00 as if no interrupt has occurred.  Even waiting
for a few milliseconds after the interrupt doesn't help.

Work around this apparent erratum by instead checking the TXMTY bit in
the STATF register ("TX FIFO empty").  We know that we've queued up a
packet for transmission if priv->tx_len is nonzero.  If the TX FIFO is
empty, transmission of that packet must have completed.

Note that this is congruent with our handling of received packets, which
likewise gleans from the STATF register whether a packet is waiting in
the RX FIFO, instead of looking at the INTF register.

Cc: Mathias Duckeck <m.duck...@kunbus.de>
Cc: Akshay Bhat <akshay.b...@timesys.com>
Cc: Casey Fitzpatrick <casey.fitzpatr...@timesys.com>
Cc: sta...@vger.kernel.org # v4.12+
Signed-off-by: Lukas Wunner <lu...@wunner.de>
Acked-by: Akshay Bhat <akshay.b...@timesys.com>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/spi/hi311x.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index c2cf254e4e95..53e320c92a8b 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -91,6 +91,7 @@
 #define HI3110_STAT_BUSOFF BIT(2)
 #define HI3110_STAT_ERRP BIT(3)
 #define HI3110_STAT_ERRW BIT(4)
+#define HI3110_STAT_TXMTY BIT(7)
 
 #define HI3110_BTR0_SJW_SHIFT 6
 #define HI3110_BTR0_BRP_SHIFT 0
@@ -737,10 +738,7 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)
}
}
 
-   if (intf == 0)
-   break;
-
-   if (intf & HI3110_INT_TXCPLT) {
+   if (priv->tx_len && statf & HI3110_STAT_TXMTY) {
net->stats.tx_packets++;
net->stats.tx_bytes += priv->tx_len - 1;
can_led_event(net, CAN_LED_EVENT_TX);
@@ -750,6 +748,9 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)
}
netif_wake_queue(net);
}
+
+   if (intf == 0)
+   break;
}
mutex_unlock(>hi3110_lock);
return IRQ_HANDLED;
-- 
2.17.0



[PATCH 1/2] can: hi311x: Acquire SPI lock on ->do_get_berr_counter

2018-05-10 Thread Marc Kleine-Budde
From: Lukas Wunner <lu...@wunner.de>

hi3110_get_berr_counter() may run concurrently to the rest of the driver
but neglects to acquire the lock protecting access to the SPI device.
As a result, it and the rest of the driver may clobber each other's tx
and rx buffers.

We became aware of this issue because transmission of packets with
"cangen -g 0 -i -x" frequently hung.  It turns out that agetty executes
->do_get_berr_counter every few seconds via the following call stack:

CPU: 2 PID: 1605 Comm: agetty
[<7f3f7500>] (hi3110_get_berr_counter [hi311x])
[<7f130204>] (can_fill_info [can_dev])
[<80693bc0>] (rtnl_fill_ifinfo)
[<806949ec>] (rtnl_dump_ifinfo)
[<806b4834>] (netlink_dump)
[<806b4bc8>] (netlink_recvmsg)
[<8065f180>] (sock_recvmsg)
[<80660f90>] (___sys_recvmsg)
[<80661e7c>] (__sys_recvmsg)
[<80661ec0>] (SyS_recvmsg)
[<80108b20>] (ret_fast_syscall+0x0/0x1c)

agetty listens to netlink messages in order to update the login prompt
when IP addresses change (if /etc/issue contains \4 or \6 escape codes):
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=e36deb6424e8

It's a useful feature, though it seems questionable that it causes CAN
bit error statistics to be queried.

Be that as it may, if hi3110_get_berr_counter() is invoked while a frame
is sent by hi3110_hw_tx(), bogus SPI transfers like the following may
occur:

=> 12 00 (hi3110_get_berr_counter() wanted to transmit
  EC 00 to query the transmit error counter,
  but the first byte was overwritten by
  hi3110_hw_tx_frame())

=> EA 00 3E 80 01 FB (hi3110_hw_tx_frame() wanted to transmit a
  frame, but the first byte was overwritten by
  hi3110_get_berr_counter() because it wanted
  to query the receive error counter)

This sequence hangs the transmission because the driver believes it has
sent a frame and waits for the interrupt signaling completion, but in
reality the chip has never sent away the frame since the commands it
received were malformed.

Fix by acquiring the SPI lock in hi3110_get_berr_counter().

I've scrutinized the entire driver for further unlocked SPI accesses but
found no others.

Cc: Mathias Duckeck <m.duck...@kunbus.de>
Cc: Akshay Bhat <akshay.b...@timesys.com>
Cc: Casey Fitzpatrick <casey.fitzpatr...@timesys.com>
Cc: Stef Walter <st...@redhat.com>
Cc: Karel Zak <k...@redhat.com>
Cc: sta...@vger.kernel.org # v4.12+
Signed-off-by: Lukas Wunner <lu...@wunner.de>
Reviewed-by: Akshay Bhat <akshay.b...@timesys.com>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/spi/hi311x.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index 5590c559a8ca..c2cf254e4e95 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -427,8 +427,10 @@ static int hi3110_get_berr_counter(const struct net_device 
*net,
struct hi3110_priv *priv = netdev_priv(net);
struct spi_device *spi = priv->spi;
 
+   mutex_lock(>hi3110_lock);
bec->txerr = hi3110_read(spi, HI3110_READ_TEC);
bec->rxerr = hi3110_read(spi, HI3110_READ_REC);
+   mutex_unlock(>hi3110_lock);
 
return 0;
 }
-- 
2.17.0



pull-request: can 2018-05-10

2018-05-10 Thread Marc Kleine-Budde
Hello David,

this is a pull request for net/master consisting of 2 patches.

Both patches are from Lukas Wunner and fix two problems found in the hi311x CAN
driver under high load situations.

regards,
Marc

---

The following changes since commit 4a026da91caaa36004a53a844dd00959370ea8fc:

  net/9p: correct some comment errors in 9p file system code (2018-05-10 
08:21:53 -0400)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.17-20180510

for you to fetch changes up to 32bee8f48fa048a3198109de50e51c092507ff52:

  can: hi311x: Work around TX complete interrupt erratum (2018-05-10 18:25:30 
+0200)


linux-can-fixes-for-4.17-20180510


Lukas Wunner (2):
  can: hi311x: Acquire SPI lock on ->do_get_berr_counter
  can: hi311x: Work around TX complete interrupt erratum

 drivers/net/can/spi/hi311x.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)




Re: [PATCH] can: hi311x: Work around TX complete interrupt erratum

2018-05-10 Thread Marc Kleine-Budde
On 05/09/2018 02:43 PM, Lukas Wunner wrote:
> When sending packets as fast as possible using "cangen -g 0 -i -x", the
> HI-3110 occasionally latches the interrupt pin high on completion of a
> packet, but doesn't set the TXCPLT bit in the INTF register.  The INTF
> register contains 0x00 as if no interrupt has occurred.  Even waiting
> for a few milliseconds after the interrupt doesn't help.
> 
> Work around this apparent erratum by instead checking the TXMTY bit in
> the STATF register ("TX FIFO empty").  We know that we've queued up a
> packet for transmission if priv->tx_len is nonzero.  If the TX FIFO is
> empty, transmission of that packet must have completed.
> 
> Note that this is congruent with our handling of received packets, which
> likewise gleans from the STATF register whether a packet is waiting in
> the RX FIFO, instead of looking at the INTF register.
> 
> Cc: Mathias Duckeck <m.duck...@kunbus.de>
> Cc: Akshay Bhat <akshay.b...@timesys.com>
> Cc: Casey Fitzpatrick <casey.fitzpatr...@timesys.com>
> Cc: sta...@vger.kernel.org # v4.12+
> Signed-off-by: Lukas Wunner <lu...@wunner.de>

Applied to can.

Tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


Re: [PATCH] can: hi311x: Acquire SPI lock on ->do_get_berr_counter

2018-05-10 Thread Marc Kleine-Budde
On 05/09/2018 02:38 PM, Lukas Wunner wrote:
> hi3110_get_berr_counter() may run concurrently to the rest of the driver
> but neglects to acquire the lock protecting access to the SPI device.
> As a result, it and the rest of the driver may clobber each other's tx
> and rx buffers.
> 
> We became aware of this issue because transmission of packets with
> "cangen -g 0 -i -x" frequently hung.  It turns out that agetty executes
> ->do_get_berr_counter every few seconds via the following call stack:
> 
> CPU: 2 PID: 1605 Comm: agetty
> [<7f3f7500>] (hi3110_get_berr_counter [hi311x])
> [<7f130204>] (can_fill_info [can_dev])
> [<80693bc0>] (rtnl_fill_ifinfo)
> [<806949ec>] (rtnl_dump_ifinfo)
> [<806b4834>] (netlink_dump)
> [<806b4bc8>] (netlink_recvmsg)
> [<8065f180>] (sock_recvmsg)
> [<80660f90>] (___sys_recvmsg)
> [<80661e7c>] (__sys_recvmsg)
> [<80661ec0>] (SyS_recvmsg)
> [<80108b20>] (ret_fast_syscall+0x0/0x1c)
> 
> agetty listens to netlink messages in order to update the login prompt
> when IP addresses change (if /etc/issue contains \4 or \6 escape codes):
> https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=e36deb6424e8
> 
> It's a useful feature, though it seems questionable that it causes CAN
> bit error statistics to be queried.
> 
> Be that as it may, if hi3110_get_berr_counter() is invoked while a frame
> is sent by hi3110_hw_tx(), bogus SPI transfers like the following may
> occur:
> 
> => 12 00 (hi3110_get_berr_counter() wanted to transmit
>   EC 00 to query the transmit error counter,
>   but the first byte was overwritten by
>   hi3110_hw_tx_frame())
> 
> => EA 00 3E 80 01 FB (hi3110_hw_tx_frame() wanted to transmit a
>   frame, but the first byte was overwritten by
>   hi3110_get_berr_counter() because it wanted
>   to query the receive error counter)
> 
> This sequence hangs the transmission because the driver believes it has
> sent a frame and waits for the interrupt signaling completion, but in
> reality the chip has never sent away the frame since the commands it
> received were malformed.
> 
> Fix by acquiring the SPI lock in hi3110_get_berr_counter().
> 
> I've scrutinized the entire driver for further unlocked SPI accesses but
> found no others.
> 
> Cc: Mathias Duckeck <m.duck...@kunbus.de>
> Cc: Akshay Bhat <akshay.b...@timesys.com>
> Cc: Casey Fitzpatrick <casey.fitzpatr...@timesys.com>
> Cc: Stef Walter <st...@redhat.com>
> Cc: Karel Zak <k...@redhat.com>
> Cc: sta...@vger.kernel.org # v4.12+
> Signed-off-by: Lukas Wunner <lu...@wunner.de>

Applied to can.

Tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[PATCH 3/7] arm: dts: imx[35]*: declare flexcan devices to be compatible to imx25's flexcan

2018-05-08 Thread Marc Kleine-Budde
From: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>

Commit d50f4630c2e1 ("arm: dts: Remove p1010-flexcan compatible from imx
series dts") removed the fallback compatible "fsl,p1010-flexcan" from
the imx device trees. As the flexcan cores on i.MX25, i.MX35 and i.MX53
are identical, introduce the first as fallback for the two latter ones.

Fixes: d50f4630c2e1 ("arm: dts: Remove p1010-flexcan compatible from imx series 
dts")
Signed-off-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
Cc: linux-stable <sta...@vger.kernel.org> # >= v4.16
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 arch/arm/boot/dts/imx35.dtsi | 4 ++--
 arch/arm/boot/dts/imx53.dtsi | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/imx35.dtsi b/arch/arm/boot/dts/imx35.dtsi
index bf343195697e..54111ed218b1 100644
--- a/arch/arm/boot/dts/imx35.dtsi
+++ b/arch/arm/boot/dts/imx35.dtsi
@@ -303,7 +303,7 @@
};
 
can1: can@53fe4000 {
-   compatible = "fsl,imx35-flexcan";
+   compatible = "fsl,imx35-flexcan", 
"fsl,imx25-flexcan";
reg = <0x53fe4000 0x1000>;
clocks = < 33>, < 33>;
clock-names = "ipg", "per";
@@ -312,7 +312,7 @@
};
 
can2: can@53fe8000 {
-   compatible = "fsl,imx35-flexcan";
+   compatible = "fsl,imx35-flexcan", 
"fsl,imx25-flexcan";
reg = <0x53fe8000 0x1000>;
clocks = < 34>, < 34>;
clock-names = "ipg", "per";
diff --git a/arch/arm/boot/dts/imx53.dtsi b/arch/arm/boot/dts/imx53.dtsi
index 7d647d043f52..3d65c0192f69 100644
--- a/arch/arm/boot/dts/imx53.dtsi
+++ b/arch/arm/boot/dts/imx53.dtsi
@@ -551,7 +551,7 @@
};
 
can1: can@53fc8000 {
-   compatible = "fsl,imx53-flexcan";
+   compatible = "fsl,imx53-flexcan", 
"fsl,imx25-flexcan";
reg = <0x53fc8000 0x4000>;
interrupts = <82>;
clocks = < IMX5_CLK_CAN1_IPG_GATE>,
@@ -561,7 +561,7 @@
};
 
can2: can@53fcc000 {
-   compatible = "fsl,imx53-flexcan";
+   compatible = "fsl,imx53-flexcan", 
"fsl,imx25-flexcan";
reg = <0x53fcc000 0x4000>;
interrupts = <83>;
clocks = < IMX5_CLK_CAN2_IPG_GATE>,
-- 
2.17.0



[PATCH 4/7] can: kvaser_usb: Increase correct stats counter in kvaser_usb_rx_can_msg()

2018-05-08 Thread Marc Kleine-Budde
From: Jimmy Assarsson <ex...@kvaser.com>

Increase rx_dropped, if alloc_can_skb() fails, not tx_dropped.

Signed-off-by: Jimmy Assarsson <ex...@kvaser.com>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/usb/kvaser_usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 63587b8e6825..daed57d3d209 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -1179,7 +1179,7 @@ static void kvaser_usb_rx_can_msg(const struct kvaser_usb 
*dev,
 
skb = alloc_can_skb(priv->netdev, );
if (!skb) {
-   stats->tx_dropped++;
+   stats->rx_dropped++;
return;
}
 
-- 
2.17.0



[PATCH 5/7] dt-bindings: can: rcar_can: Fix R8A7796 SoC name

2018-05-08 Thread Marc Kleine-Budde
From: Geert Uytterhoeven <geert+rene...@glider.be>

R8A7796 is R-Car M3-W.

Signed-off-by: Geert Uytterhoeven <geert+rene...@glider.be>
Reviewed-by: Simon Horman <horms+rene...@verge.net.au>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/rcar_canfd.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt 
b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
index 93c3a6ae32f9..1a4ee1d2506d 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
@@ -5,7 +5,7 @@ Required properties:
 - compatible: Must contain one or more of the following:
   - "renesas,rcar-gen3-canfd" for R-Car Gen3 compatible controller.
   - "renesas,r8a7795-canfd" for R8A7795 (R-Car H3) compatible controller.
-  - "renesas,r8a7796-canfd" for R8A7796 (R-Car M3) compatible controller.
+  - "renesas,r8a7796-canfd" for R8A7796 (R-Car M3-W) compatible controller.
 
   When compatible with the generic version, nodes must list the
   SoC-specific version corresponding to the platform first, followed by the
-- 
2.17.0



[PATCH 2/7] can: flexcan: fix endianess detection

2018-05-08 Thread Marc Kleine-Budde
From: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>

In commit 88462d2a7830 ("can: flexcan: Remodel FlexCAN register r/w APIs
for big endian FlexCAN controllers.") the following logic was
implemented:

if the dt property "big-endian" is given or
   the device is compatible to "fsl,p1010-flexcan":
use big-endian mode;
else
use little-endian mode;

This relies on commit d50f4630c2e1 ("arm: dts: Remove p1010-flexcan
compatible from imx series dts") which was applied a few commits later.
Without this commit (or an old device tree used for booting a new
kernel) the flexcan devices on i.MX25, i.MX28, i.MX35 and i.MX53 match
the 'the device is compatible to "fsl,p1010-flexcan"' test and so are
switched erroneously to big endian mode.

Instead of the check above put a quirk in devtype data and rely on
of_match_device yielding the most compatible match

Fixes: 88462d2a7830 ("can: flexcan: Remodel FlexCAN register r/w APIs for big 
endian FlexCAN controllers.")
Signed-off-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
Tested-by: Gavin Schenk <g.sch...@eckelmann.de>
Cc: linux-stable <sta...@vger.kernel.org> # >= v4.16
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/flexcan.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 634c51e6b8ae..d53a45bf2a72 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -200,6 +200,7 @@
 #define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) /* Disable Memory error 
detection */
 #define FLEXCAN_QUIRK_USE_OFF_TIMESTAMPBIT(5) /* Use timestamp based 
offloading */
 #define FLEXCAN_QUIRK_BROKEN_PERR_STATEBIT(6) /* No interrupt for 
error passive */
+#define FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN   BIT(7) /* default to BE 
register access */
 
 /* Structure of the message buffer */
 struct flexcan_mb {
@@ -287,6 +288,12 @@ struct flexcan_priv {
 };
 
 static const struct flexcan_devtype_data fsl_p1010_devtype_data = {
+   .quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE |
+   FLEXCAN_QUIRK_BROKEN_PERR_STATE |
+   FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN,
+};
+
+static const struct flexcan_devtype_data fsl_imx25_devtype_data = {
.quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE |
FLEXCAN_QUIRK_BROKEN_PERR_STATE,
 };
@@ -1251,9 +1258,9 @@ static void unregister_flexcandev(struct net_device *dev)
 static const struct of_device_id flexcan_of_match[] = {
{ .compatible = "fsl,imx6q-flexcan", .data = _imx6q_devtype_data, },
{ .compatible = "fsl,imx28-flexcan", .data = _imx28_devtype_data, },
-   { .compatible = "fsl,imx53-flexcan", .data = _p1010_devtype_data, },
-   { .compatible = "fsl,imx35-flexcan", .data = _p1010_devtype_data, },
-   { .compatible = "fsl,imx25-flexcan", .data = _p1010_devtype_data, },
+   { .compatible = "fsl,imx53-flexcan", .data = _imx25_devtype_data, },
+   { .compatible = "fsl,imx35-flexcan", .data = _imx25_devtype_data, },
+   { .compatible = "fsl,imx25-flexcan", .data = _imx25_devtype_data, },
{ .compatible = "fsl,p1010-flexcan", .data = _p1010_devtype_data, },
{ .compatible = "fsl,vf610-flexcan", .data = _vf610_devtype_data, },
{ .compatible = "fsl,ls1021ar2-flexcan", .data = 
_ls1021a_r2_devtype_data, },
@@ -1337,18 +1344,13 @@ static int flexcan_probe(struct platform_device *pdev)
 
priv = netdev_priv(dev);
 
-   if (of_property_read_bool(pdev->dev.of_node, "big-endian")) {
+   if (of_property_read_bool(pdev->dev.of_node, "big-endian") ||
+   devtype_data->quirks & FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN) {
priv->read = flexcan_read_be;
priv->write = flexcan_write_be;
} else {
-   if (of_device_is_compatible(pdev->dev.of_node,
-   "fsl,p1010-flexcan")) {
-   priv->read = flexcan_read_be;
-   priv->write = flexcan_write_be;
-   } else {
-   priv->read = flexcan_read_le;
-   priv->write = flexcan_write_le;
-   }
+   priv->read = flexcan_read_le;
+   priv->write = flexcan_write_le;
}
 
priv->can.clock.freq = clock_freq;
-- 
2.17.0



[PATCH 1/7] can: dev: increase bus-off message severity

2018-05-08 Thread Marc Kleine-Budde
From: Jakob Unterwurzacher <jakob.unterwurzac...@theobroma-systems.com>

bus-off is usually caused by hardware malfunction or configuration error
(baud rate mismatch) and causes a complete loss of communication.

Increase the "bus-off" message's severity from netdev_dbg() to
netdev_info() to make it visible to the user.

A can interface going into bus-off is similar in severity to ethernet's
"Link is Down" message, which is also printed at info level.

It is debatable whether the the "restarted" message should also be
changed to netdev_info() to make the interface state changes
comprehensible from the kernel log. I have chosen to keep the
"restarted" message at dbg for now as the "bus-off" message should be
enough for the user to notice and investigate the problem.

Signed-off-by: Jakob Unterwurzacher <jakob.unterwurzac...@theobroma-systems.com>
Cc: linux-...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index b1779566c5bb..3c71f1cb205f 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -605,7 +605,7 @@ void can_bus_off(struct net_device *dev)
 {
struct can_priv *priv = netdev_priv(dev);
 
-   netdev_dbg(dev, "bus-off\n");
+   netdev_info(dev, "bus-off\n");
 
netif_carrier_off(dev);
 
-- 
2.17.0



[PATCH 7/7] DT: net: can: rcar_canfd: document R8A77980 bindings

2018-05-08 Thread Marc Kleine-Budde
From: Sergei Shtylyov <sergei.shtyl...@cogentembedded.com>

Document the R-Car V3H (R8A77980) SoC support in the R-Car CAN-FD bindings.

Signed-off-by: Sergei Shtylyov <sergei.shtyl...@cogentembedded.com>
Reviewed-by: Simon Horman <horms+rene...@verge.net.au>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/rcar_canfd.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt 
b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
index 59dd13aab97f..ac71daa46195 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
@@ -7,6 +7,7 @@ Required properties:
   - "renesas,r8a7795-canfd" for R8A7795 (R-Car H3) compatible controller.
   - "renesas,r8a7796-canfd" for R8A7796 (R-Car M3-W) compatible controller.
   - "renesas,r8a77970-canfd" for R8A77970 (R-Car V3M) compatible controller.
+  - "renesas,r8a77980-canfd" for R8A77980 (R-Car V3H) compatible controller.
 
   When compatible with the generic version, nodes must list the
   SoC-specific version corresponding to the platform first, followed by the
-- 
2.17.0



[PATCH 6/7] DT: net: can: rcar_canfd: document R8A77970 bindings

2018-05-08 Thread Marc Kleine-Budde
From: Sergei Shtylyov <sergei.shtyl...@cogentembedded.com>

Document the R-Car V3M (R8A77970) SoC support in the R-Car CAN-FD bindings.

Signed-off-by: Sergei Shtylyov <sergei.shtyl...@cogentembedded.com>
Reviewed-by: Ramesh Shanmugasundaram <ramesh.shanmugasunda...@bp.renesas.com>
Reviewed-by: Simon Horman <horms+rene...@verge.net.au>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/rcar_canfd.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt 
b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
index 1a4ee1d2506d..59dd13aab97f 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
@@ -6,6 +6,7 @@ Required properties:
   - "renesas,rcar-gen3-canfd" for R-Car Gen3 compatible controller.
   - "renesas,r8a7795-canfd" for R8A7795 (R-Car H3) compatible controller.
   - "renesas,r8a7796-canfd" for R8A7796 (R-Car M3-W) compatible controller.
+  - "renesas,r8a77970-canfd" for R8A77970 (R-Car V3M) compatible controller.
 
   When compatible with the generic version, nodes must list the
   SoC-specific version corresponding to the platform first, followed by the
-- 
2.17.0



pull-request: can 2018-05-08

2018-05-08 Thread Marc Kleine-Budde
Hello David,

this is a pull request for 7 patches for net/master.

The first patch is by Jakob Unterwurzacher and increases the severity of
bus-off messages in the generic CAN device infrastructure. The next two patches
are by Uwe Kleine-König and fix the endianess detection in the flexcan driver.
Jimmy Assarsson's patch for the kvaser driver corrects the stats counter for
dropped tx-messages. Geert Uytterhoeven provides one patch and Sergei Shtylyov
two patches for the rcan_canfd device tree binding description.

regards,
Marc

---

The following changes since commit 2c5d5b13c6eb79f5677e206b8aad59b3a2097f60:

  llc: better deal with too small mtu (2018-05-08 00:11:40 -0400)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.17-20180508

for you to fetch changes up to 7a25ac2f71a409e77dd5c85cf3cbe1cbf2ae77f3:

  DT: net: can: rcar_canfd: document R8A77980 bindings (2018-05-08 10:41:38 
+0200)


linux-can-fixes-for-4.17-20180508


Geert Uytterhoeven (1):
  dt-bindings: can: rcar_can: Fix R8A7796 SoC name

Jakob Unterwurzacher (1):
  can: dev: increase bus-off message severity

Jimmy Assarsson (1):
  can: kvaser_usb: Increase correct stats counter in kvaser_usb_rx_can_msg()

Sergei Shtylyov (2):
  DT: net: can: rcar_canfd: document R8A77970 bindings
  DT: net: can: rcar_canfd: document R8A77980 bindings

Uwe Kleine-König (2):
  can: flexcan: fix endianess detection
  arm: dts: imx[35]*: declare flexcan devices to be compatible to imx25's 
flexcan

 .../devicetree/bindings/net/can/rcar_canfd.txt |  4 +++-
 arch/arm/boot/dts/imx35.dtsi   |  4 ++--
 arch/arm/boot/dts/imx53.dtsi   |  4 ++--
 drivers/net/can/dev.c  |  2 +-
 drivers/net/can/flexcan.c  | 26 --
 drivers/net/can/usb/kvaser_usb.c   |  2 +-
 6 files changed, 23 insertions(+), 19 deletions(-)




Re: [PATCH] dt-bindings: can: rcar_can: Fix R8A7796 SoC name

2018-05-05 Thread Marc Kleine-Budde
On 05/03/2018 03:02 PM, Geert Uytterhoeven wrote:
> R8A7796 is R-Car M3-W.
> 
> Signed-off-by: Geert Uytterhoeven <geert+rene...@glider.be>

Applied to linux-can.

thnx,
Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] DT: net: can: rcar_canfd: document R8A77980 bindings

2018-04-30 Thread Marc Kleine-Budde
On 04/27/2018 08:53 PM, Sergei Shtylyov wrote:
> Document the R-Car V3H (R8A77980) SoC support in the R-Car CAN-FD bindings.
> 
> Signed-off-by: Sergei Shtylyov <sergei.shtyl...@cogentembedded.com>

Applied to linux-can.

tnx,
Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] DT: net: can: rcar_canfd: document R8A77970 bindings

2018-04-30 Thread Marc Kleine-Budde
On 04/27/2018 01:33 PM, Ramesh Shanmugasundaram wrote:
> Hello Sergei,
> 
> Thanks for your patch.
> 
>> Subject: [PATCH] DT: net: can: rcar_canfd: document R8A77970 bindings
>>
>> Document the R-Car V3M (R8A77970) SoC support in the R-Car CAN-FD
>> bindings.
>>
>> Signed-off-by: Sergei Shtylyov <sergei.shtyl...@cogentembedded.com>
> 
> Reviewed-by: Ramesh Shanmugasundaram <ramesh.shanmugasunda...@bp.renesas.com>

Applied to linux-can.

tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: cc770: fix spelling mistake: "comptibility" -> "compatibility"

2018-04-30 Thread Marc Kleine-Budde
On 04/29/2018 12:16 AM, Colin King wrote:
> From: Colin Ian King <colin.k...@canonical.com>
> 
> Trivial fix to spelling mistake in module parameter description text
> 
> Signed-off-by: Colin Ian King <colin.k...@canonical.com>

Added to linux-can-next.

Thnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH net-next] can: dev: use skb_put_zero to simplfy code

2018-04-30 Thread Marc Kleine-Budde
On 04/28/2018 09:49 AM, YueHaibing wrote:
> use helper skb_put_zero to replace the pattern of skb_put() && memset()
> 
> Signed-off-by: YueHaibing <yuehaib...@huawei.com>

Applied to linux-can-next.

Tnx,
Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 3/3] can: xilinx: fix xcan_start_xmit()'s return type

2018-04-27 Thread Marc Kleine-Budde
On 04/27/2018 09:49 AM, Michal Simek wrote:
> On 26.4.2018 23:13, Luc Van Oostenryck wrote:
>> The method ndo_start_xmit() is defined as returning an 'netdev_tx_t',
>> which is a typedef for an enum type, but the implementation in this
>> driver returns an 'int'.
>>
>> Fix this by returning 'netdev_tx_t' in this driver too.
>>
>> Signed-off-by: Luc Van Oostenryck <luc.vanoostenr...@gmail.com>
>> ---
>>  drivers/net/can/xilinx_can.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
>> index 89aec07c2..a19648606 100644
>> --- a/drivers/net/can/xilinx_can.c
>> +++ b/drivers/net/can/xilinx_can.c
>> @@ -386,7 +386,7 @@ static int xcan_do_set_mode(struct net_device *ndev, 
>> enum can_mode mode)
>>   *
>>   * Return: 0 on success and failure value on error
>>   */
>> -static int xcan_start_xmit(struct sk_buff *skb, struct net_device *ndev)
>> +static netdev_tx_t xcan_start_xmit(struct sk_buff *skb, struct net_device 
>> *ndev)
>>  {
>>  struct xcan_priv *priv = netdev_priv(ndev);
>>  struct net_device_stats *stats = >stats;
>>
> 
> It was applied already but there should be also kernel-doc update too to
> use enum values instead of 0.

Like this:

> diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
> index f07ce4945356..d0ad1473f689 100644
> --- a/drivers/net/can/xilinx_can.c
> +++ b/drivers/net/can/xilinx_can.c
> @@ -398,7 +398,7 @@ static int xcan_do_set_mode(struct net_device *ndev, enum 
> can_mode mode)
>   * function uses the next available free txbuff and populates their fields to
>   * start the transmission.
>   *
> - * Return: 0 on success and failure value on error
> + * Return: NETDEV_TX_OK on success and NETDEV_TX_BUSY when the tx queue is 
> full
>   */
>  static netdev_tx_t xcan_start_xmit(struct sk_buff *skb, struct net_device 
> *ndev)
>  {

I can squash in that change.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 0/3] can: fix ndo_start_xmit()'s return type

2018-04-27 Thread Marc Kleine-Budde
On 04/26/2018 11:13 PM, Luc Van Oostenryck wrote:
> ndo_start_xmit() is defined as returing an 'netdev_tx_t'.
> However, several can drivers use 'int' as the return type
> of their start_xmit() method.
> This series contains the fix for all three of them.
> 
> Luc Van Oostenryck (3):
>   can: janz-ican3: fix ican3_xmit()'s return type
>   can: sun4i: fix sun4ican_start_xmit()'s return type
>   can: xilinx: fix xcan_start_xmit()'s return type
> 
>  drivers/net/can/janz-ican3.c | 2 +-
>  drivers/net/can/sun4i_can.c  | 2 +-
>  drivers/net/can/xilinx_can.c | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)

Applied all 3 to linux-can-next, added similar patch for the flexcan driver.

Tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 1/2] net: can: sja1000: Replace mdelay with usleep_range in peak_pci_probe

2018-04-25 Thread Marc Kleine-Budde
On 04/11/2018 03:42 AM, Jia-Ju Bai wrote:
> peak_pci_probe() is never called in atomic context.
> 
> peak_pci_probe() is set as ".probe" in struct pci_driver.
> 
> Despite never getting called from atomic context, peak_pci_probe()
> calls mdelay() to busily wait.
> This is not necessary and can be replaced with usleep_range() to
> avoid busy waiting.
> 
> This is found by a static analysis tool named DCNS written by myself.
> And I also manually check it.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1...@gmail.com>

Applied both to linux-can-next.

tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: janz-ican3: fix ican3_xmit()'s return type

2018-04-25 Thread Marc Kleine-Budde
On 04/24/2018 03:16 PM, Luc Van Oostenryck wrote:
> The method ndo_start_xmit() is defined as returning an 'netdev_tx_t',
> which is a typedef for an enum type, but the implementation in this
> driver returns an 'int'.
> 
> Fix this by returning 'netdev_tx_t' in this driver too.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenr...@gmail.com>
> ---

Can you send a series fixing the return type in all CAN drivers?

Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


pull-request: can 2018-03-19

2018-03-19 Thread Marc Kleine-Budde
Hello David,

this is a pull reqeust of one patch for net/master.

The patch is by Andri Yngvason and fixes a potential use-after-free bug
in the cc770 driver introduced in the previous pull-request.

regards,
Marc

---

The following changes since commit a069215cf5985f3aa1bba550264907d6bd05c5f7:

  net: fec: Fix unbalanced PM runtime calls (2018-03-18 16:32:47 -0400)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.16-20180319

for you to fetch changes up to 9ffd7503944ec7c0ef41c3245d1306c221aef2be:

  can: cc770: Fix use after free in cc770_tx_interrupt() (2018-03-19 10:57:29 
+0100)


linux-can-fixes-for-4.16-20180319


Andri Yngvason (1):
  can: cc770: Fix use after free in cc770_tx_interrupt()

 drivers/net/can/cc770/cc770.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)



[PATCH] can: cc770: Fix use after free in cc770_tx_interrupt()

2018-03-19 Thread Marc Kleine-Budde
From: Andri Yngvason <andri.yngva...@marel.com>

This fixes use after free introduced by the last cc770 patch.

Signed-off-by: Andri Yngvason <andri.yngva...@marel.com>
Fixes: 746201235b3f ("can: cc770: Fix queue stall & dropped RTR reply")
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/cc770/cc770.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/cc770/cc770.c b/drivers/net/can/cc770/cc770.c
index 2743d82d4424..6da69af103e6 100644
--- a/drivers/net/can/cc770/cc770.c
+++ b/drivers/net/can/cc770/cc770.c
@@ -706,13 +706,12 @@ static void cc770_tx_interrupt(struct net_device *dev, 
unsigned int o)
return;
}
 
-   can_put_echo_skb(priv->tx_skb, dev, 0);
-   can_get_echo_skb(dev, 0);
-
cf = (struct can_frame *)priv->tx_skb->data;
stats->tx_bytes += cf->can_dlc;
stats->tx_packets++;
 
+   can_put_echo_skb(priv->tx_skb, dev, 0);
+   can_get_echo_skb(dev, 0);
priv->tx_skb = NULL;
 
netif_wake_queue(dev);
-- 
2.16.2



Re: [PATCH] can: enable multi-queue for SocketCAN devices

2018-03-15 Thread Marc Kleine-Budde
On 03/15/2018 10:08 AM, Jonas Mark (BT-FIR/ENG1) wrote:
>> Normal SPI?
> 
> Yes, normal SPI (CLK, MOSI, MISO, SEL) plus two GPIOs for flow control.
> The CAN peripheral (SPI slave) asserts the additional signals to
> request a transfer and to signal that it is busy.

Sounds interesting.

>>> I will have to check but I am pretty confident that we would be willing
>>> to publish the driver on these mailing lists as well. We will anyhow
>>> ship the source code (or a written offer) with every distribution.
>>
>> Sure - can I find your devices used and low priced on ebay :) ?
>
> That is rather unlikely. Though, you could buy a building containing
> one.

One building one device sounds like a bad deal to me :)

>>> If you are really serious about the review I will get the process
>>> rolling for an early publication of our driver.
>>
>> Yes, please go ahead!
> 
> Ok, I'll kick off the process and start to collect the required signatures.

Tnx.

regards,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: enable multi-queue for SocketCAN devices

2018-03-15 Thread Marc Kleine-Budde
On 03/14/2018 05:51 PM, Jonas Mark (BT-FIR/ENG1) wrote:
>> That doesn't matter. It would be the first driver that makes use of the
>> feature, so we can learn from it. And you might get a free review of
>> your driver.
> 
> Of course we would be happy if somebody was volunteering to review
> our driver for free.

If my time permits, I'll throw some eyeballs on the driver.

> The driver consists of two layers because the HW is accessed via SPI.

Normal SPI?

> So there is a SPI driver of 1000 lines. On top of that is the CAN
> driver and it has 600 lines. Because the HW does more than just
> CAN there is another driver which implements a char device with
> additional 300 lines.
> 
> Are there still volunteers?

The SPI and the CAN driver would be the most interesting ones.

>>> Our motivation to separate this patch from the proprietary SocketCAN
>>> driver
>>
>> Looking at your email address I assume your employer sells devices with
>> this hardware and the driver. So someone has to provide the sources for
>> it anyways to fulfil the GPL license requirements. :)
> 
> I will have to check but I am pretty confident that we would be willing
> to publish the driver on these mailing lists as well. We will anyhow
> ship the source code (or a written offer) with every distribution.

Sure - can I find your devices used and low priced on ebay :) ?

> If you are really serious about the review I will get the process
> rolling for an early publication of our driver.

Yes, please go ahead!

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: pull-request: can 2018-03-14

2018-03-14 Thread Marc Kleine-Budde
On 03/14/2018 01:24 PM, Andri Yngvason wrote:
> On Wed, Mar 14, 2018 at 01:05:21PM +0100, Marc Kleine-Budde wrote:
>> Hello David,
>>
>> this is a pull request of two patches for net/master.
>>
>> Both patches are by Andri Yngvason and fix problems in the cc770 driver,
>> that show up quite fast on RT systems, but also on non RT setups.
>>
>> regards,
>> Marc
>>
>> ---
>>
>> The following changes since commit f89782c2d131e6eae0d1ea2569ba76bc4c5875fe:
>>
>>   qed: Use after free in qed_rdma_free() (2018-03-13 10:54:17 -0400)
>>
>> are available in the Git repository at:
>>
>>   ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
>> tags/linux-can-fixes-for-4.16-20180314
>>
>> for you to fetch changes up to 746201235b3f876792099079f4c6fea941d76183:
>>
>>   can: cc770: Fix queue stall & dropped RTR reply (2018-03-14 13:01:22 +0100)
>>
>> 
>> linux-can-fixes-for-4.16-20180314
>>
>> 
>> Andri Yngvason (2):
>>   can: cc770: Fix stalls on rt-linux, remove redundant IRQ ack
>>   can: cc770: Fix queue stall & dropped RTR reply
>>
>>  drivers/net/can/cc770/cc770.c | 103 
>> ++
>>  drivers/net/can/cc770/cc770.h |   2 +
>>  2 files changed, 65 insertions(+), 40 deletions(-)
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-can" in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> Wait, do we not want Wolfgang's signed-off-by or reviewed-by?

In the review Wolfgang was involved in "[PATCH v2 2/3] can: cc770: Stop
queue on NETDEV_TX_BUSY" and we all agreed to drop the patch.

The other patches were successfully tested by Richard, AFAIK there are
no open points anymore and there was no discussion on these patches for
more than 10 days. So assumed the patches are "ready" for upstreaming now.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: enable multi-queue for SocketCAN devices

2018-03-14 Thread Marc Kleine-Budde
On 03/14/2018 01:26 PM, Jonas Mark (BT-FIR/ENG1) wrote:
>> Do you have a driver or a patch to make a driver mq aware?
> 
> Yes, we have CAN hardware with multiple queues and we also have a
> SocketCAN driver for it.
> 
> IMHO the driver will be of very little use for the Linux community
> because the HW is proprietary.

That doesn't matter. It would be the first driver that makes use of the
feature, so we can learn from it. And you might get a free review of
your driver.

> Our motivation to separate this patch from the proprietary SocketCAN
> driver

Looking at your email address I assume your employer sells devices with
this hardware and the driver. So someone has to provide the sources for
it anyways to fulfil the GPL license requirements. :)

> is that we felt it was odd that the multi-queue infrastructure is in
> place and only very few lines of code are missing to offer it to the
> CAN networking subsystem as well.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


[PATCH 2/2] can: cc770: Fix queue stall & dropped RTR reply

2018-03-14 Thread Marc Kleine-Budde
From: Andri Yngvason <andri.yngva...@marel.com>

While waiting for the TX object to send an RTR, an external message with a
matching id can overwrite the TX data. In this case we must call the rx
routine and then try transmitting the message that was overwritten again.

The queue was being stalled because the RX event did not generate an
interrupt to wake up the queue again and the TX event did not happen
because the TXRQST flag is reset by the chip when new data is received.

According to the CC770 datasheet the id of a message object should not be
changed while the MSGVAL bit is set. This has been fixed by resetting the
MSGVAL bit before modifying the object in the transmit function and setting
it after. It is not enough to set & reset CPUUPD.

It is important to keep the MSGVAL bit reset while the message object is
being modified. Otherwise, during RTR transmission, a frame with matching
id could trigger an rx-interrupt, which would cause a race condition
between the interrupt routine and the transmit function.

Signed-off-by: Andri Yngvason <andri.yngva...@marel.com>
Tested-by: Richard Weinberger <rich...@nod.at>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/cc770/cc770.c | 94 ++-
 drivers/net/can/cc770/cc770.h |  2 +
 2 files changed, 68 insertions(+), 28 deletions(-)

diff --git a/drivers/net/can/cc770/cc770.c b/drivers/net/can/cc770/cc770.c
index 9fed163262e0..2743d82d4424 100644
--- a/drivers/net/can/cc770/cc770.c
+++ b/drivers/net/can/cc770/cc770.c
@@ -390,37 +390,23 @@ static int cc770_get_berr_counter(const struct net_device 
*dev,
return 0;
 }
 
-static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, struct net_device 
*dev)
+static void cc770_tx(struct net_device *dev, int mo)
 {
struct cc770_priv *priv = netdev_priv(dev);
-   struct net_device_stats *stats = >stats;
-   struct can_frame *cf = (struct can_frame *)skb->data;
-   unsigned int mo = obj2msgobj(CC770_OBJ_TX);
+   struct can_frame *cf = (struct can_frame *)priv->tx_skb->data;
u8 dlc, rtr;
u32 id;
int i;
 
-   if (can_dropped_invalid_skb(dev, skb))
-   return NETDEV_TX_OK;
-
-   if ((cc770_read_reg(priv,
-   msgobj[mo].ctrl1) & TXRQST_UNC) == TXRQST_SET) {
-   netdev_err(dev, "TX register is still occupied!\n");
-   return NETDEV_TX_BUSY;
-   }
-
-   netif_stop_queue(dev);
-
dlc = cf->can_dlc;
id = cf->can_id;
-   if (cf->can_id & CAN_RTR_FLAG)
-   rtr = 0;
-   else
-   rtr = MSGCFG_DIR;
+   rtr = cf->can_id & CAN_RTR_FLAG ? 0 : MSGCFG_DIR;
+
+   cc770_write_reg(priv, msgobj[mo].ctrl0,
+   MSGVAL_RES | TXIE_RES | RXIE_RES | INTPND_RES);
cc770_write_reg(priv, msgobj[mo].ctrl1,
RMTPND_RES | TXRQST_RES | CPUUPD_SET | NEWDAT_RES);
-   cc770_write_reg(priv, msgobj[mo].ctrl0,
-   MSGVAL_SET | TXIE_SET | RXIE_RES | INTPND_RES);
+
if (id & CAN_EFF_FLAG) {
id &= CAN_EFF_MASK;
cc770_write_reg(priv, msgobj[mo].config,
@@ -439,13 +425,30 @@ static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
for (i = 0; i < dlc; i++)
cc770_write_reg(priv, msgobj[mo].data[i], cf->data[i]);
 
-   /* Store echo skb before starting the transfer */
-   can_put_echo_skb(skb, dev, 0);
-
cc770_write_reg(priv, msgobj[mo].ctrl1,
-   RMTPND_RES | TXRQST_SET | CPUUPD_RES | NEWDAT_UNC);
+   RMTPND_UNC | TXRQST_SET | CPUUPD_RES | NEWDAT_UNC);
+   cc770_write_reg(priv, msgobj[mo].ctrl0,
+   MSGVAL_SET | TXIE_SET | RXIE_SET | INTPND_UNC);
+}
+
+static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, struct net_device 
*dev)
+{
+   struct cc770_priv *priv = netdev_priv(dev);
+   unsigned int mo = obj2msgobj(CC770_OBJ_TX);
+
+   if (can_dropped_invalid_skb(dev, skb))
+   return NETDEV_TX_OK;
 
-   stats->tx_bytes += dlc;
+   netif_stop_queue(dev);
+
+   if ((cc770_read_reg(priv,
+   msgobj[mo].ctrl1) & TXRQST_UNC) == TXRQST_SET) {
+   netdev_err(dev, "TX register is still occupied!\n");
+   return NETDEV_TX_BUSY;
+   }
+
+   priv->tx_skb = skb;
+   cc770_tx(dev, mo);
 
return NETDEV_TX_OK;
 }
@@ -671,13 +674,47 @@ static void cc770_tx_interrupt(struct net_device *dev, 
unsigned int o)
struct cc770_priv *priv = netdev_priv(dev);
struct net_device_stats *stats = >stats;
unsigned int mo = obj2msgobj(o);
+   struct can_frame *cf;
+   u8 ctrl1;
+
+   ctrl1 = cc770_read_reg(priv, msgobj[m

[PATCH 1/2] can: cc770: Fix stalls on rt-linux, remove redundant IRQ ack

2018-03-14 Thread Marc Kleine-Budde
From: Andri Yngvason <andri.yngva...@marel.com>

This has been reported to cause stalls on rt-linux.

Suggested-by: Richard Weinberger <rich...@nod.at>
Tested-by: Richard Weinberger <rich...@nod.at>
Signed-off-by: Andri Yngvason <andri.yngva...@marel.com>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/cc770/cc770.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/net/can/cc770/cc770.c b/drivers/net/can/cc770/cc770.c
index 1e37313054f3..9fed163262e0 100644
--- a/drivers/net/can/cc770/cc770.c
+++ b/drivers/net/can/cc770/cc770.c
@@ -447,15 +447,6 @@ static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
 
stats->tx_bytes += dlc;
 
-
-   /*
-* HM: We had some cases of repeated IRQs so make sure the
-* INT is acknowledged I know it's already further up, but
-* doing again fixed the issue
-*/
-   cc770_write_reg(priv, msgobj[mo].ctrl0,
-   MSGVAL_UNC | TXIE_UNC | RXIE_UNC | INTPND_RES);
-
return NETDEV_TX_OK;
 }
 
@@ -684,12 +675,6 @@ static void cc770_tx_interrupt(struct net_device *dev, 
unsigned int o)
/* Nothing more to send, switch off interrupts */
cc770_write_reg(priv, msgobj[mo].ctrl0,
MSGVAL_RES | TXIE_RES | RXIE_RES | INTPND_RES);
-   /*
-* We had some cases of repeated IRQ so make sure the
-* INT is acknowledged
-*/
-   cc770_write_reg(priv, msgobj[mo].ctrl0,
-   MSGVAL_UNC | TXIE_UNC | RXIE_UNC | INTPND_RES);
 
stats->tx_packets++;
can_get_echo_skb(dev, 0);
-- 
2.16.1



pull-request: can 2018-03-14

2018-03-14 Thread Marc Kleine-Budde
Hello David,

this is a pull request of two patches for net/master.

Both patches are by Andri Yngvason and fix problems in the cc770 driver,
that show up quite fast on RT systems, but also on non RT setups.

regards,
Marc

---

The following changes since commit f89782c2d131e6eae0d1ea2569ba76bc4c5875fe:

  qed: Use after free in qed_rdma_free() (2018-03-13 10:54:17 -0400)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.16-20180314

for you to fetch changes up to 746201235b3f876792099079f4c6fea941d76183:

  can: cc770: Fix queue stall & dropped RTR reply (2018-03-14 13:01:22 +0100)


linux-can-fixes-for-4.16-20180314


Andri Yngvason (2):
  can: cc770: Fix stalls on rt-linux, remove redundant IRQ ack
  can: cc770: Fix queue stall & dropped RTR reply

 drivers/net/can/cc770/cc770.c | 103 ++
 drivers/net/can/cc770/cc770.h |   2 +
 2 files changed, 65 insertions(+), 40 deletions(-)



Re: [PATCH] can: enable multi-queue for SocketCAN devices

2018-03-14 Thread Marc Kleine-Budde
On 03/14/2018 11:33 AM, Mark Jonas wrote:
> From: Zhu Yi <yi.z...@cn.bosch.com>
> 
> The existing SocketCAN implementation provides alloc_candev() to
> allocate a CAN device using a single Tx and Rx queue. This can lead to
> priority inversion in case the single Tx queue is already full with low
> priority messages and a high priority message needs to be sent while the
> bus is fully loaded with medium priority messages.
> 
> This problem can be solved by using the existing multi-queue support of
> the network subsystem. The commit makes it possible to use multi-queue in
> the CAN subsystem in the same way it is used in the Ethernet subsystem
> by adding an alloc_candev_mqs() call and accompanying macros. With this
> support a CAN device can use multi-queue qdisc (e.g. mqprio) to avoid
> the aforementioned priority inversion.
> 
> The existing functionality of alloc_candev() is the same as before.
> 
> CAN devices need to have prioritized multiple hardware queues or are
> able to abort waiting for arbitration to make sensible use of
> multi-queues.
> 
> Signed-off-by: Zhu Yi <yi.z...@cn.bosch.com>
> Signed-off-by: Mark Jonas <mark.jo...@de.bosch.com>
> Reviewed-by: Heiko Schocher <h...@denx.de>

Do you have a driver or a patch to make a driver mq aware?

> ---
>  drivers/net/can/dev.c   | 8 +---
>  include/linux/can/dev.h | 7 ++-
>  2 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> index b177956..636f853 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -703,7 +703,8 @@ EXPORT_SYMBOL_GPL(alloc_can_err_skb);
>  /*
>   * Allocate and setup space for the CAN network device
>   */
> -struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
> +struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int 
> echo_skb_max,
> + unsigned int txqs, unsigned int rxqs)
>  {
>   struct net_device *dev;
>   struct can_priv *priv;
> @@ -715,7 +716,8 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned 
> int echo_skb_max)
>   else
>   size = sizeof_priv;
>  
> - dev = alloc_netdev(size, "can%d", NET_NAME_UNKNOWN, can_setup);
> + dev = alloc_netdev_mqs(size, "can%d", NET_NAME_UNKNOWN, can_setup,
> +txqs, rxqs);
>   if (!dev)
>   return NULL;
>  
> @@ -734,7 +736,7 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned 
> int echo_skb_max)
>  
>   return dev;
>  }
> -EXPORT_SYMBOL_GPL(alloc_candev);
> +EXPORT_SYMBOL_GPL(alloc_candev_mqs);
>  
>  /*
>   * Free space of the CAN network device
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 055aaf5..a83e1f6 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -143,7 +143,12 @@ u8 can_dlc2len(u8 can_dlc);
>  /* map the sanitized data length to an appropriate data length code */
>  u8 can_len2dlc(u8 len);
>  
> -struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
> +struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int 
> echo_skb_max,
> + unsigned int txqs, unsigned int rxqs);
> +#define alloc_candev(sizeof_priv, echo_skb_max) \
> + alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1)
> +#define alloc_candev_mq(sizeof_priv, echo_skb_max, count) \
> + alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count)

Can you make this a static inline function.

>  void free_candev(struct net_device *dev);
>  
>  /* a candev safe wrapper around netdev_priv */
> 

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


[PATCH 5/6] can: peak/pcie_fd: remove useless code when interface starts

2018-03-12 Thread Marc Kleine-Budde
From: Stephane Grosjean <s.grosj...@peak-system.com>

When an interface starts, the echo_skb array is empty and the network
queue should be started only. This patch replaces useless code and locks
when the internal RX_BARRIER message is received from the IP core, telling
the driver that tx may start.

Signed-off-by: Stephane Grosjean <s.grosj...@peak-system.com>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/peak_canfd/peak_canfd.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/net/can/peak_canfd/peak_canfd.c 
b/drivers/net/can/peak_canfd/peak_canfd.c
index 6fa66231ed8e..ed8561d4a90f 100644
--- a/drivers/net/can/peak_canfd/peak_canfd.c
+++ b/drivers/net/can/peak_canfd/peak_canfd.c
@@ -333,7 +333,6 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
 
/* this STATUS is the CNF of the RX_BARRIER: Tx path can be setup */
if (pucan_status_is_rx_barrier(msg)) {
-   unsigned long flags;
 
if (priv->enable_tx_path) {
int err = priv->enable_tx_path(priv);
@@ -342,16 +341,8 @@ static int pucan_handle_status(struct peak_canfd_priv 
*priv,
return err;
}
 
-   /* restart network queue only if echo skb array is free */
-   spin_lock_irqsave(>echo_lock, flags);
-
-   if (!priv->can.echo_skb[priv->echo_idx]) {
-   spin_unlock_irqrestore(>echo_lock, flags);
-
-   netif_wake_queue(ndev);
-   } else {
-   spin_unlock_irqrestore(>echo_lock, flags);
-   }
+   /* start network queue (echo_skb array is empty) */
+   netif_start_queue(ndev);
 
return 0;
}
-- 
2.16.1



[PATCH 6/6] can: m_can: select pinctrl state in each suspend/resume function

2018-03-12 Thread Marc Kleine-Budde
From: Bich HEMON <bich.he...@st.com>

Make sure to apply the correct pin state in suspend/resume callbacks.
Putting pins in sleep state saves power.

Signed-off-by: Bich Hemon <bich.he...@st.com>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 74170b0d23cf..b397a33f3d32 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* napi related */
 #define M_CAN_NAPI_WEIGHT  64
@@ -1700,6 +1701,8 @@ static __maybe_unused int m_can_suspend(struct device 
*dev)
m_can_clk_stop(priv);
}
 
+   pinctrl_pm_select_sleep_state(dev);
+
priv->can.state = CAN_STATE_SLEEPING;
 
return 0;
@@ -1710,6 +1713,8 @@ static __maybe_unused int m_can_resume(struct device *dev)
struct net_device *ndev = dev_get_drvdata(dev);
struct m_can_priv *priv = netdev_priv(ndev);
 
+   pinctrl_pm_select_default_state(dev);
+
m_can_init_ram(priv);
 
priv->can.state = CAN_STATE_ERROR_ACTIVE;
-- 
2.16.1



[PATCH 2/6] can: ifi: Check core revision upon probe

2018-03-12 Thread Marc Kleine-Budde
From: Marek Vasut <ma...@denx.de>

Older versions of the core are not compatible with the driver due
to various intrusive fixes of the core. Read out the VER register,
check the core revision bitfield and verify if the core in use is
new enough (rev 2.1 or newer) to work correctly with this driver.

Signed-off-by: Marek Vasut <ma...@denx.de>
Cc: Heiko Schocher <h...@denx.de>
Cc: Markus Marb <mar...@marb.org>
Cc: Marc Kleine-Budde <m...@pengutronix.de>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/ifi_canfd/ifi_canfd.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c 
b/drivers/net/can/ifi_canfd/ifi_canfd.c
index 2772d05ff11c..9fd396c3569a 100644
--- a/drivers/net/can/ifi_canfd/ifi_canfd.c
+++ b/drivers/net/can/ifi_canfd/ifi_canfd.c
@@ -136,6 +136,8 @@
 #define IFI_CANFD_SYSCLOCK 0x50
 
 #define IFI_CANFD_VER  0x54
+#define IFI_CANFD_VER_REV_MASK 0xff
+#define IFI_CANFD_VER_REV_MIN_SUPPORTED0x15
 
 #define IFI_CANFD_IP_ID0x58
 #define IFI_CANFD_IP_ID_VALUE  0xD073CAFD
@@ -933,7 +935,7 @@ static int ifi_canfd_plat_probe(struct platform_device 
*pdev)
struct resource *res;
void __iomem *addr;
int irq, ret;
-   u32 id;
+   u32 id, rev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
addr = devm_ioremap_resource(dev, res);
@@ -947,6 +949,13 @@ static int ifi_canfd_plat_probe(struct platform_device 
*pdev)
return -EINVAL;
}
 
+   rev = readl(addr + IFI_CANFD_VER) & IFI_CANFD_VER_REV_MASK;
+   if (rev < IFI_CANFD_VER_REV_MIN_SUPPORTED) {
+   dev_err(dev, "This block is too old (rev %i), minimum supported 
is rev %i\n",
+   rev, IFI_CANFD_VER_REV_MIN_SUPPORTED);
+   return -EINVAL;
+   }
+
ndev = alloc_candev(sizeof(*priv), 1);
if (!ndev)
return -ENOMEM;
-- 
2.16.1



[PATCH 4/6] can: peak/pcie_fd: fix echo_skb is occupied! bug

2018-03-12 Thread Marc Kleine-Budde
From: Stephane Grosjean <s.grosj...@peak-system.com>

This patch makes atomic the handling of the linux-can echo_skb array and
the network tx queue. This prevents from the "BUG! echo_skb is occupied!"
message to be printed by the linux-can core, in SMP environments.

Reported-by: Diana Burgess <di...@peloton-tech.com>
Signed-off-by: Stephane Grosjean <s.grosj...@peak-system.com>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/peak_canfd/peak_canfd.c   | 12 ++--
 drivers/net/can/peak_canfd/peak_pciefd_main.c |  8 ++--
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/peak_canfd/peak_canfd.c 
b/drivers/net/can/peak_canfd/peak_canfd.c
index 55513411a82e..6fa66231ed8e 100644
--- a/drivers/net/can/peak_canfd/peak_canfd.c
+++ b/drivers/net/can/peak_canfd/peak_canfd.c
@@ -262,7 +262,6 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
 
spin_lock_irqsave(>echo_lock, flags);
can_get_echo_skb(priv->ndev, msg->client);
-   spin_unlock_irqrestore(>echo_lock, flags);
 
/* count bytes of the echo instead of skb */
stats->tx_bytes += cf_len;
@@ -271,6 +270,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
/* restart tx queue (a slot is free) */
netif_wake_queue(priv->ndev);
 
+   spin_unlock_irqrestore(>echo_lock, flags);
return 0;
}
 
@@ -726,11 +726,6 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff 
*skb,
 */
should_stop_tx_queue = !!(priv->can.echo_skb[priv->echo_idx]);
 
-   spin_unlock_irqrestore(>echo_lock, flags);
-
-   /* write the skb on the interface */
-   priv->write_tx_msg(priv, msg);
-
/* stop network tx queue if not enough room to save one more msg too */
if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
should_stop_tx_queue |= (room_left <
@@ -742,6 +737,11 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff 
*skb,
if (should_stop_tx_queue)
netif_stop_queue(ndev);
 
+   spin_unlock_irqrestore(>echo_lock, flags);
+
+   /* write the skb on the interface */
+   priv->write_tx_msg(priv, msg);
+
return NETDEV_TX_OK;
 }
 
diff --git a/drivers/net/can/peak_canfd/peak_pciefd_main.c 
b/drivers/net/can/peak_canfd/peak_pciefd_main.c
index 788c3464a3b0..3c51a884db87 100644
--- a/drivers/net/can/peak_canfd/peak_pciefd_main.c
+++ b/drivers/net/can/peak_canfd/peak_pciefd_main.c
@@ -349,8 +349,12 @@ static irqreturn_t pciefd_irq_handler(int irq, void *arg)
priv->tx_pages_free++;
spin_unlock_irqrestore(>tx_lock, flags);
 
-   /* wake producer up */
-   netif_wake_queue(priv->ucan.ndev);
+   /* wake producer up (only if enough room in echo_skb array) */
+   spin_lock_irqsave(>ucan.echo_lock, flags);
+   if (!priv->ucan.can.echo_skb[priv->ucan.echo_idx])
+   netif_wake_queue(priv->ucan.ndev);
+
+   spin_unlock_irqrestore(>ucan.echo_lock, flags);
}
 
/* re-enable Rx DMA transfer for this CAN */
-- 
2.16.1



[PATCH 3/6] can: ifi: Repair the error handling

2018-03-12 Thread Marc Kleine-Budde
From: Marek Vasut <ma...@denx.de>

The new version of the IFI CANFD core has significantly less complex
error state indication logic. In particular, the warning/error state
bits are no longer all over the place, but are all present in the
STATUS register. Moreover, there is a new IRQ register bit indicating
transition between error states (active/warning/passive/busoff).

This patch makes use of this bit to weed out the obscure selective
INTERRUPT register clearing, which was used to carry over the error
state indication into the poll function. While at it, this patch
fixes the handling of the ACTIVE state, since the hardware provides
indication of the core being in ACTIVE state and that in turn fixes
the state transition indication toward userspace. Finally, register
reads in the poll function are moved to the matching subfunctions
since those are also no longer needed in the poll function.

Signed-off-by: Marek Vasut <ma...@denx.de>
Cc: Heiko Schocher <h...@denx.de>
Cc: Markus Marb <mar...@marb.org>
Cc: Marc Kleine-Budde <m...@pengutronix.de>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/ifi_canfd/ifi_canfd.c | 64 ---
 1 file changed, 37 insertions(+), 27 deletions(-)

diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c 
b/drivers/net/can/ifi_canfd/ifi_canfd.c
index 9fd396c3569a..fedd927ba6ed 100644
--- a/drivers/net/can/ifi_canfd/ifi_canfd.c
+++ b/drivers/net/can/ifi_canfd/ifi_canfd.c
@@ -30,6 +30,7 @@
 #define IFI_CANFD_STCMD_ERROR_ACTIVE   BIT(2)
 #define IFI_CANFD_STCMD_ERROR_PASSIVE  BIT(3)
 #define IFI_CANFD_STCMD_BUSOFF BIT(4)
+#define IFI_CANFD_STCMD_ERROR_WARNING  BIT(5)
 #define IFI_CANFD_STCMD_BUSMONITOR BIT(16)
 #define IFI_CANFD_STCMD_LOOPBACK   BIT(18)
 #define IFI_CANFD_STCMD_DISABLE_CANFD  BIT(24)
@@ -52,7 +53,10 @@
 #define IFI_CANFD_TXSTCMD_OVERFLOW BIT(13)
 
 #define IFI_CANFD_INTERRUPT0xc
+#define IFI_CANFD_INTERRUPT_ERROR_BUSOFF   BIT(0)
 #define IFI_CANFD_INTERRUPT_ERROR_WARNING  BIT(1)
+#define IFI_CANFD_INTERRUPT_ERROR_STATE_CHGBIT(2)
+#define IFI_CANFD_INTERRUPT_ERROR_REC_TEC_INC  BIT(3)
 #define IFI_CANFD_INTERRUPT_ERROR_COUNTER  BIT(10)
 #define IFI_CANFD_INTERRUPT_TXFIFO_EMPTY   BIT(16)
 #define IFI_CANFD_INTERRUPT_TXFIFO_REMOVE  BIT(22)
@@ -61,6 +65,10 @@
 #define IFI_CANFD_INTERRUPT_SET_IRQ((u32)BIT(31))
 
 #define IFI_CANFD_IRQMASK  0x10
+#define IFI_CANFD_IRQMASK_ERROR_BUSOFF BIT(0)
+#define IFI_CANFD_IRQMASK_ERROR_WARNINGBIT(1)
+#define IFI_CANFD_IRQMASK_ERROR_STATE_CHG  BIT(2)
+#define IFI_CANFD_IRQMASK_ERROR_REC_TEC_INCBIT(3)
 #define IFI_CANFD_IRQMASK_SET_ERR  BIT(7)
 #define IFI_CANFD_IRQMASK_SET_TS   BIT(15)
 #define IFI_CANFD_IRQMASK_TXFIFO_EMPTY BIT(16)
@@ -222,7 +230,10 @@ static void ifi_canfd_irq_enable(struct net_device *ndev, 
bool enable)
 
if (enable) {
enirq = IFI_CANFD_IRQMASK_TXFIFO_EMPTY |
-   IFI_CANFD_IRQMASK_RXFIFO_NEMPTY;
+   IFI_CANFD_IRQMASK_RXFIFO_NEMPTY |
+   IFI_CANFD_IRQMASK_ERROR_STATE_CHG |
+   IFI_CANFD_IRQMASK_ERROR_WARNING |
+   IFI_CANFD_IRQMASK_ERROR_BUSOFF;
if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
enirq |= IFI_CANFD_INTERRUPT_ERROR_COUNTER;
}
@@ -363,12 +374,13 @@ static int ifi_canfd_handle_lost_msg(struct net_device 
*ndev)
return 1;
 }
 
-static int ifi_canfd_handle_lec_err(struct net_device *ndev, const u32 errctr)
+static int ifi_canfd_handle_lec_err(struct net_device *ndev)
 {
struct ifi_canfd_priv *priv = netdev_priv(ndev);
struct net_device_stats *stats = >stats;
struct can_frame *cf;
struct sk_buff *skb;
+   u32 errctr = readl(priv->base + IFI_CANFD_ERROR_CTR);
const u32 errmask = IFI_CANFD_ERROR_CTR_OVERLOAD_FIRST |
IFI_CANFD_ERROR_CTR_ACK_ERROR_FIRST |
IFI_CANFD_ERROR_CTR_BIT0_ERROR_FIRST |
@@ -451,6 +463,11 @@ static int ifi_canfd_handle_state_change(struct net_device 
*ndev,
 
switch (new_state) {
case CAN_STATE_ERROR_ACTIVE:
+   /* error active state */
+   priv->can.can_stats.error_warning++;
+   priv->can.state = CAN_STATE_ERROR_ACTIVE;
+   break;
+   case CAN_STATE_ERROR_WARNING:
/* error warning state */
priv->can.can_stats.error_warning++;
priv->can.state = CAN_STATE_ERROR_WARNING;
@@ -479,7 +496,7 @@ static int ifi_canfd_handle_state_change(struct net_device 
*ndev,
ifi_canfd_get_berr_counter(ndev, );
 
swi

[PATCH 1/6] can: m_can: change comparison to bitshift when dealing with a mask

2018-03-12 Thread Marc Kleine-Budde
From: Wolfram Sang <wsa+rene...@sang-engineering.com>

Due to a typo, the mask was destroyed by a comparison instead of a bit
shift.

Reported-by: Geert Uytterhoeven <geert+rene...@glider.be>
Signed-off-by: Wolfram Sang <wsa+rene...@sang-engineering.com>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 2594f7779c6f..74170b0d23cf 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -253,7 +253,7 @@ enum m_can_mram_cfg {
 
 /* Rx FIFO 0/1 Configuration (RXF0C/RXF1C) */
 #define RXFC_FWM_SHIFT 24
-#define RXFC_FWM_MASK  (0x7f < RXFC_FWM_SHIFT)
+#define RXFC_FWM_MASK  (0x7f << RXFC_FWM_SHIFT)
 #define RXFC_FS_SHIFT  16
 #define RXFC_FS_MASK   (0x7f << RXFC_FS_SHIFT)
 
-- 
2.16.1



pull-request: can 2018-03-12

2018-03-12 Thread Marc Kleine-Budde
Hello David,

this is a pull reqeust of 6 patches for net/master.

The first patch is by Wolfram Sang and fixes a bitshift vs. comparison mistake
in the m_can driver. Two patches of Marek Vasut repair the error handling in
the ifi driver. The two patches by Stephane Grosjean fix a "echo_skb is
occupied!" bug in the peak/pcie_fd driver. Bich HEMON's patch adds pinctrl
select state calls to the m_can's driver to further improve power saving during
suspend.

regards,
Marc

---

The following changes since commit ddc502dfed600bff0b61d899f70d95b76223fdfc:

  openvswitch: meter: fix the incorrect calculation of max delta_t (2018-03-11 
22:48:59 -0400)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.16-20180312

for you to fetch changes up to c9b3bce18da4a0aebc27853052dea39aa64b7d75:

  can: m_can: select pinctrl state in each suspend/resume function (2018-03-12 
10:38:20 +0100)


linux-can-fixes-for-4.16-20180312


Bich HEMON (1):
  can: m_can: select pinctrl state in each suspend/resume function

Marek Vasut (2):
  can: ifi: Check core revision upon probe
  can: ifi: Repair the error handling

Stephane Grosjean (2):
  can: peak/pcie_fd: fix echo_skb is occupied! bug
  can: peak/pcie_fd: remove useless code when interface starts

Wolfram Sang (1):
  can: m_can: change comparison to bitshift when dealing with a mask

 drivers/net/can/ifi_canfd/ifi_canfd.c | 75 +--
 drivers/net/can/m_can/m_can.c |  7 ++-
 drivers/net/can/peak_canfd/peak_canfd.c   | 25 +++--
 drivers/net/can/peak_canfd/peak_pciefd_main.c |  8 ++-
 4 files changed, 67 insertions(+), 48 deletions(-)



Re: [PATCH] can: m_can: select pinctrl state in each suspend/resume function

2018-03-12 Thread Marc Kleine-Budde
On 03/12/2018 09:52 AM, Bich HEMON wrote:
> Make sure to apply the correct pin state in suspend/resume callbacks.
> Putting pins in sleep state saves power.
> 
> Signed-off-by: Bich Hemon <bich.he...@st.com>
> ---

Doesn't compile:

>   CHECK   /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c:1703:9: 
> error: undefined identifier 'pinctrl_pm_select_sleep_state'
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c:1715:9: 
> error: undefined identifier 'pinctrl_pm_select_default_state'
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c:1703:38: 
> warning: call with no type!
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c:1715:40: 
> warning: call with no type!
>   CC [M]  drivers/net/can/m_can/m_can.o
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c: In function 
> 'm_can_suspend':
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c:1703:2: 
> error: implicit declaration of function 'pinctrl_pm_select_sleep_state' 
> [-Werror=implicit-function-declaration]
>   pinctrl_pm_select_sleep_state(dev);
>   ^
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c: In function 
> 'm_can_resume':
> /srv/work/frogger/socketcan/linux/drivers/net/can/m_can/m_can.c:1715:2: 
> error: implicit declaration of function 'pinctrl_pm_select_default_state' 
> [-Werror=implicit-function-declaration]
>   pinctrl_pm_select_default_state(dev);
>   ^

Fixed while applying the patch.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


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

2018-02-08 Thread Marc Kleine-Budde
On 02/08/2018 08:22 PM, Marek Vasut wrote:
> On 02/08/2018 03:46 PM, Marc Kleine-Budde wrote:
>> On 02/08/2018 07:47 AM, Heiko Schocher wrote:
>>> 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.
>>>
>>> Signed-off-by: Heiko Schocher <h...@denx.de>
>>> Reviewed-by: Marek Vasut <ma...@denx.de>
>>
>> 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

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


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

2018-02-08 Thread Marc Kleine-Budde
On 02/08/2018 07:47 AM, Heiko Schocher wrote:
> 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.
> 
> Signed-off-by: Heiko Schocher <h...@denx.de>
> Reviewed-by: Marek Vasut <ma...@denx.de>

Applied both to linux-can.

Tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: m_can: change comparison to bitshift when dealing with a mask

2018-02-08 Thread Marc Kleine-Budde
On 02/06/2018 09:52 AM, Wolfram Sang wrote:
> Due to a typo, the mask was destroyed by a comparison instead of a bit
> shift.
> 
> Reported-by: Geert Uytterhoeven <geert+rene...@glider.be>
> Signed-off-by: Wolfram Sang <wsa+rene...@sang-engineering.com>
> ---
> Only build tested.

Applied to can. Luckily that define is not used :)

Tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: m_can: change comparison to bitshift when dealing with a mask

2018-02-08 Thread Marc Kleine-Budde
On 02/06/2018 09:52 AM, Wolfram Sang wrote:
> Due to a typo, the mask was destroyed by a comparison instead of a bit
> shift.
> 
> Reported-by: Geert Uytterhoeven <geert+rene...@glider.be>
> Signed-off-by: Wolfram Sang <wsa+rene...@sang-engineering.com>

Applied to can.

tnx,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 1/8] dt-bindings: can: rcar_can: document r8a774[35] can support

2018-01-26 Thread Marc Kleine-Budde
On 01/25/2018 09:53 AM, Marc Kleine-Budde wrote:
> On 01/24/2018 06:22 PM, Fabrizio Castro wrote:
>> thank you for Acking the patch, just wondering if this patch has any
>> chance to end up in v4.16?
> 
> I can take this via the linux-can tree, if no one else takes it.

Done - included in the latest pull request.

Marc

-- 
Pengutronix e.K.          | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


pull-request: can-next 2018-01-26

2018-01-26 Thread Marc Kleine-Budde
Hello David,

this is a pull request for net-next/master consisting of 3 patches.

The first two patches target the CAN documentation. The first is by me
and fixes pointer to location of fsl,mpc5200-mscan node in the mpc5200
documentation. The second patch is by Robert Schwebel and it converts
the plain ASCII documentation to restructured text.

The third patch is by Fabrizio Castro add the r8a774[35] support to the
rcar_can dt-bindings documentation.

regards,
Marc

---

The following changes since commit 9515a2e082f91457db0ecff4b65371d0fb5d9aad:

  net/ipv4: Allow send to local broadcast from a socket bound to a VRF 
(2018-01-25 21:51:31 -0500)

are available in the Git repository at:

  
ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git 
tags/linux-can-next-for-4.16-20180126

for you to fetch changes up to 216bf2f490c214b8a0702b52cc957138ba24bc3f:

  dt-bindings: can: rcar_can: document r8a774[35] can support (2018-01-26 
10:47:17 +0100)


linux-can-next-for-4.16-20180126


Fabrizio Castro (1):
  dt-bindings: can: rcar_can: document r8a774[35] can support

Marc Kleine-Budde (1):
  Documentation/devicetree: mpc5200.txt: fix pointer to location of 
fsl,mpc5200-mscan node

Robert Schwebel (1):
  can: migrate documentation to restructured text

 .../devicetree/bindings/net/can/rcar_can.txt   |7 +-
 .../devicetree/bindings/powerpc/fsl/mpc5200.txt|2 +-
 Documentation/networking/00-INDEX  |2 -
 Documentation/networking/can.rst   | 1437 
 Documentation/networking/can.txt   | 1308 --
 Documentation/networking/index.rst |1 +
 MAINTAINERS|2 +-
 drivers/net/can/dev.c  |2 +-
 drivers/net/can/vcan.c |2 +-
 net/can/Kconfig|2 +-
 10 files changed, 1448 insertions(+), 1317 deletions(-)
 create mode 100644 Documentation/networking/can.rst
 delete mode 100644 Documentation/networking/can.txt

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 1/8] dt-bindings: can: rcar_can: document r8a774[35] can support

2018-01-25 Thread Marc Kleine-Budde
On 01/24/2018 06:22 PM, Fabrizio Castro wrote:
> thank you for Acking the patch, just wondering if this patch has any
> chance to end up in v4.16?

I can take this via the linux-can tree, if no one else takes it.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


pull-request: can-next 2018-01-16

2018-01-19 Thread Marc Kleine-Budde
Hello David,

this is a pull request for net-next/master consisting of 1 patch.

This patch by Arnd Bergmann for the m_can driver silences a compiler
warning if CONFIG_PM is not selected.

regards,
Marc

---

The following changes since commit ef58ca38dbda0642e293bcaa2e05edc79677c617:

  net/sched/sch_prio.c: work around gcc-4.4.4 union initializer issues 
(2018-01-18 21:11:31 -0500)

are available in the Git repository at:

  
ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git 
tags/linux-can-next-for-4.16-20180119

for you to fetch changes up to 58359193193c4261d340b2f7f028e5096d4e4d15:

  can: m_can: mark runtime-PM handlers as __maybe_unused (2018-01-19 10:41:15 
+0100)


linux-can-next-for-4.16-20180119


Arnd Bergmann (1):
  can: m_can: mark runtime-PM handlers as __maybe_unused

 drivers/net/can/m_can/m_can.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: m_can: mark runtime-PM handlers as __maybe_unused

2018-01-18 Thread Marc Kleine-Budde
On 01/18/2018 02:04 PM, Arnd Bergmann wrote:
> Building without CONFIG_PM results in a harmless warning:
> 
> drivers/net/can/m_can/m_can.c:1763:12: error: 'm_can_runtime_resume' defined 
> but not used [-Werror=unused-function]
> drivers/net/can/m_can/m_can.c:1752:12: error: 'm_can_runtime_suspend' defined 
> but not used [-Werror=unused-function]
> 
> Marking the functions as __maybe_unused lets the compiler
> silently drop them instead.
> 
> Fixes: cdf8259d6573 ("can: m_can: Add PM Support")
> Signed-off-by: Arnd Bergmann <a...@arndb.de>

Tnx - applied.

However all archs using this driver have mandatory PM support and the
driver depends on it.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


[PATCH 2/2] can: af_can: canfd_rcv(): replace WARN_ONCE by pr_warn_once

2018-01-18 Thread Marc Kleine-Budde
If an invalid CANFD frame is received, from a driver or from a tun
interface, a Kernel warning is generated.

This patch replaces the WARN_ONCE by a simple pr_warn_once, so that a
kernel, bootet with panic_on_warn, does not panic. A printk seems to be
more appropriate here.

Reported-by: syzbot+e3b775f40babeff6e...@syzkaller.appspotmail.com
Suggested-by: Dmitry Vyukov <dvyu...@google.com>
Acked-by: Oliver Hartkopp <socket...@hartkopp.net>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 net/can/af_can.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index ae835382e678..4d7f988a3130 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -738,20 +738,16 @@ static int canfd_rcv(struct sk_buff *skb, struct 
net_device *dev,
 {
struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
 
-   if (WARN_ONCE(dev->type != ARPHRD_CAN ||
- skb->len != CANFD_MTU ||
- cfd->len > CANFD_MAX_DLEN,
- "PF_CAN: dropped non conform CAN FD skbuf: "
- "dev type %d, len %d, datalen %d\n",
- dev->type, skb->len, cfd->len))
-   goto drop;
+   if (unlikely(dev->type != ARPHRD_CAN || skb->len != CANFD_MTU ||
+cfd->len > CANFD_MAX_DLEN)) {
+   pr_warn_once("PF_CAN: dropped non conform CAN FD skbuf: dev 
type %d, len %d, datalen %d\n",
+dev->type, skb->len, cfd->len);
+   kfree_skb(skb);
+   return NET_RX_DROP;
+   }
 
can_receive(skb, dev);
return NET_RX_SUCCESS;
-
-drop:
-   kfree_skb(skb);
-   return NET_RX_DROP;
 }
 
 /*
-- 
2.15.1



[PATCH 1/2] can: af_can: can_rcv(): replace WARN_ONCE by pr_warn_once

2018-01-18 Thread Marc Kleine-Budde
If an invalid CAN frame is received, from a driver or from a tun
interface, a Kernel warning is generated.

This patch replaces the WARN_ONCE by a simple pr_warn_once, so that a
kernel, bootet with panic_on_warn, does not panic. A printk seems to be
more appropriate here.

Reported-by: syzbot+4386709c0c1284dca...@syzkaller.appspotmail.com
Suggested-by: Dmitry Vyukov <dvyu...@google.com>
Acked-by: Oliver Hartkopp <socket...@hartkopp.net>
Cc: linux-stable <sta...@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de>
---
 net/can/af_can.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 003b2d6d655f..ae835382e678 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -721,20 +721,16 @@ static int can_rcv(struct sk_buff *skb, struct net_device 
*dev,
 {
struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
 
-   if (WARN_ONCE(dev->type != ARPHRD_CAN ||
- skb->len != CAN_MTU ||
- cfd->len > CAN_MAX_DLEN,
- "PF_CAN: dropped non conform CAN skbuf: "
- "dev type %d, len %d, datalen %d\n",
- dev->type, skb->len, cfd->len))
-   goto drop;
+   if (unlikely(dev->type != ARPHRD_CAN || skb->len != CAN_MTU ||
+cfd->len > CAN_MAX_DLEN)) {
+   pr_warn_once("PF_CAN: dropped non conform CAN skbuf: dev type 
%d, len %d, datalen %d\n",
+dev->type, skb->len, cfd->len);
+   kfree_skb(skb);
+   return NET_RX_DROP;
+   }
 
can_receive(skb, dev);
return NET_RX_SUCCESS;
-
-drop:
-   kfree_skb(skb);
-   return NET_RX_DROP;
 }
 
 static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
-- 
2.15.1



pull-request: can 2018-01-18

2018-01-18 Thread Marc Kleine-Budde
Hello David,

this is a pull reqeust of two patches for net/master:

The syzkaller project triggered two WARN_ONCE() in the af_can code from
userspace and we decided to replace it by a pr_warn_once().

regards,
Marc

---

The following changes since commit ad9294dbc227cbc8e173b3b963e7dd9af5314f77:

  bpf: fix cls_bpf on filter replace (2018-01-17 17:14:06 -0500)

are available in the Git repository at:

  ssh://g...@gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git 
tags/linux-can-fixes-for-4.15-20180118

for you to fetch changes up to d4689846881d160a4d12a514e991a740bcb5d65a:

  can: af_can: canfd_rcv(): replace WARN_ONCE by pr_warn_once (2018-01-18 
09:32:54 +0100)


linux-can-fixes-for-4.15-20180118


Marc Kleine-Budde (2):
  can: af_can: can_rcv(): replace WARN_ONCE by pr_warn_once
  can: af_can: canfd_rcv(): replace WARN_ONCE by pr_warn_once

 net/can/af_can.c | 36 ++--
 1 file changed, 14 insertions(+), 22 deletions(-)



Re: WARNING in can_rcv

2018-01-17 Thread Marc Kleine-Budde
On 01/17/2018 05:29 PM, Oliver Hartkopp wrote:
>> Is this an Acked-by for both patches?
>>
> 
> Yes :-)
> 
> Acked-by: Oliver Hartkopp <socket...@hartkopp.net>

Tnx

> I just did not expect that you wanted to update the patches before 
> sending ...

Why not :)

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: WARNING in can_rcv

2018-01-17 Thread Marc Kleine-Budde
On 01/17/2018 09:07 AM, Oliver Hartkopp wrote:
> 
> 
> On 01/17/2018 08:12 AM, Eric Biggers wrote:
>> On Wed, Jan 17, 2018 at 07:39:24AM +0100, Oliver Hartkopp wrote:
>>>
>>>
>>> On 01/16/2018 07:11 PM, Dmitry Vyukov wrote:
>>>> On Tue, Jan 16, 2018 at 7:07 PM, Marc Kleine-Budde <m...@pengutronix.de> 
>>>> wrote:
>>>>> On 01/16/2018 06:58 PM, syzbot wrote:
>>>>>> Hello,
>>>>>>
>>>>>> syzkaller hit the following crash on
>>>>>> a8750ddca918032d6349adbf9a4b6555e7db20da
>>>>>> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
>>>>>> compiler: gcc (GCC) 7.1.1 20170620
>>>>>> .config is attached
>>>>>> Raw console output is attached.
>>>>>> C reproducer is attached
>>>>>> syzkaller reproducer is attached. See https://goo.gl/kgGztJ
>>>>>> for information about syzkaller reproducers
>>>>>>
>>>>>>
>>>>>> IMPORTANT: if you fix the bug, please add the following tag to the 
>>>>>> commit:
>>>>>> Reported-by: syzbot+4386709c0c1284dca...@syzkaller.appspotmail.com
>>>>>> It will help syzbot understand when the bug is fixed. See footer for
>>>>>> details.
>>>>>> If you forward the report, please keep this part and the footer.
>>>>>>
>>>>>> device eql entered promiscuous mode
>>>>>> [ cut here ]
>>>>>> PF_CAN: dropped non conform CAN skbuf: dev type 65534, len 42, datalen 0
>>>>>> WARNING: CPU: 0 PID: 3650 at net/can/af_can.c:729 can_rcv+0x1c5/0x200
>>>>>> net/can/af_can.c:724
>>>>>> Kernel panic - not syncing: panic_on_warn set ...
>>>>>
>>>>> Invalid packages generate a warning (WARN_ONCE()), and you have
>>>>> panic_on_warn active. Should we better silently drop these CAN packages?
>>>>
>>>> Hi,
>>>>
>>>> pr_warn_once() will be more appropriate. It prints a single line.
>>>>
>>>
>>> The idea behind this WARN() is to detect really bad things that might have
>>> happen on network driver level:
>>>
>>> The CAN subsystem registers with dev_add_pack() for ETH_P_CAN and
>>> ETH_P_CANFD only. These ETH_P_ types are only allowed to be created by CAN
>>> network devices (like vcan, vxcan, and real CAN drivers).
>>>
>>> I don't have any strong opinion on using WARN() or pr_warn_once().
>>> Is this detected violation worth using WARN(), as something already must
>>> have gone really wrong to trigger this issue?
>>>
>>
>> WARN() indicates a kernel bug.  If it's instead "userspace did something
>> stupid", or "someone sent some unexpected network packet", it needs to be
>> pr_warn_once(), pr_warn_ratelimited(), or removed entirely.
> 
> Ok. Thanks for the explanation!
> It is "some bogus network driver sent something unexpected" - but that 
> does not harm the entire system.
> 
> pr_warn_once() seems the right way to go then.

Is this an Acked-by for both patches?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


  1   2   3   4   5   >