All of lore.kernel.org
 help / color / mirror / Atom feed
* pull-request: can-next 2020-10-07
@ 2020-10-07 21:31 Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 01/17] can: af_can: can_rcv_list_find(): fix kernel doc after variable renaming Marc Kleine-Budde
                   ` (17 more replies)
  0 siblings, 18 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel

Hello David,

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

The first 3 patches are by me and fix several warnings found when compiling the 
kernel with W=1.

Lukas Bulwahn's patch adjusts the MAINTAINERS file, to accommodate the renaming 
of the mcp251xfd driver.

Vincent Mailhol contributes 3 patches for the CAN networking layer. First error
queue support is added the the CAN RAW protocol. The second patch converts the
get_can_dlc() and get_canfd_dlc() in-Kernel-only macros from using __u8 to u8.
The third patch adds a helper function to calculate the length of one bit in in
multiple of time quanta.

Oliver Hartkopp's patch add support for the ISO 15765-2:2016 transport protocol
to the CAN stack.

Three patches by Lad Prabhakar add documentation for various new rcar
controllers to the device tree bindings of the rcar_can and rcan_canfd driver.

Michael Walle's patch adds various processors to the flexcan driver binding
documentation.

The next two patches are by me and target the flexcan driver aswell. The remove
the ack_grp and ack_bit from the fsl,stop-mode DT property and the driver, as
they are not used anymore. As these are the last two arguments this change will
not break existing device trees.

The last three patches are by Srinivas Neeli and target the xilinx_can driver.
The first one increases the lower limit for the bit rate prescaler to 2, the
other two fix sparse and coverity findings.

regards,
Marc

---

The following changes since commit 9faebeb2d80065926dfbc09cb73b1bb7779a89cd:

  Merge branch 'ethtool-allow-dumping-policies-to-user-space' (2020-10-06 06:25:56 -0700)

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-5.10-20201007

for you to fetch changes up to 164ab90d0d8644d13ca498146a1732d1fff82d89:

  can: xilinx_can: Fix incorrect variable and initialize with a default value (2020-10-07 23:18:34 +0200)

----------------------------------------------------------------
linux-can-next-for-5.10-20201007

----------------------------------------------------------------
Lad Prabhakar (3):
      dt-bindings: can: rcar_can: Add r8a7742 support
      dt-bindings: can: rcar_canfd: Document r8a774e1 support
      dt-bindings: can: rcar_can: Document r8a774e1 support

Lukas Bulwahn (1):
      MAINTAINERS: adjust to mcp251xfd file renaming

Marc Kleine-Budde (5):
      can: af_can: can_rcv_list_find(): fix kernel doc after variable renaming
      can: softing: softing_card_shutdown(): add  braces around empty body in an 'if' statement
      can: c_can: reg_map_{c,d}_can: mark as __maybe_unused
      dt-bindings: can: flexcan: remove ack_grp and ack_bit from fsl,stop-mode
      can: flexcan: remove ack_grp and ack_bit handling from driver

Michael Walle (1):
      dt-bindings: can: flexcan: list supported processors

Oliver Hartkopp (1):
      can: add ISO 15765-2:2016 transport protocol

Srinivas Neeli (3):
      can: xilinx_can: Limit CANFD brp to 2
      can: xilinx_can: Check return value of set_reset_mode
      can: xilinx_can: Fix incorrect variable and initialize with a default value

Vincent Mailhol (3):
      can: raw: add missing error queue support
      can: dev: fix type of get_can_dlc() and get_canfd_dlc() macros
      can: dev: add a helper function to calculate the duration of one bit

 .../devicetree/bindings/net/can/fsl-flexcan.txt    |   10 +-
 .../devicetree/bindings/net/can/rcar_can.txt       |    8 +-
 .../devicetree/bindings/net/can/rcar_canfd.txt     |    5 +-
 MAINTAINERS                                        |    7 +-
 drivers/net/can/c_can/c_can.h                      |    4 +-
 drivers/net/can/dev.c                              |   13 +-
 drivers/net/can/flexcan.c                          |   13 +-
 drivers/net/can/softing/softing_main.c             |    3 +-
 drivers/net/can/xilinx_can.c                       |   14 +-
 include/linux/can/dev.h                            |   21 +-
 include/uapi/linux/can/isotp.h                     |  166 +++
 include/uapi/linux/can/raw.h                       |    3 +
 net/can/Kconfig                                    |   13 +
 net/can/Makefile                                   |    3 +
 net/can/af_can.c                                   |    2 +-
 net/can/isotp.c                                    | 1426 ++++++++++++++++++++
 net/can/raw.c                                      |    4 +
 17 files changed, 1676 insertions(+), 39 deletions(-)
 create mode 100644 include/uapi/linux/can/isotp.h
 create mode 100644 net/can/isotp.c



^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 01/17] can: af_can: can_rcv_list_find(): fix kernel doc after variable renaming
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 02/17] can: softing: softing_card_shutdown(): add braces around empty body in an 'if' statement Marc Kleine-Budde
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Marc Kleine-Budde

This patch fixes the kernel doc for can_rcv_list_find() which was broken in commit:

    3ee6d2bebef8 ("can: af_can: rename find_rcv_list() to can_rcv_list_find()")

while renaming a variable, but forgetting to rename the kernel doc, too.

Link: http://lore.kernel.org/r/20201006203748.1750156-2-mkl@pengutronix.de
Fixes: 3ee6d2bebef8 ("can: af_can: rename find_rcv_list() to can_rcv_list_find()")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/af_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index ea29a6d97ef5..b7d0f6500893 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -338,7 +338,7 @@ static unsigned int effhash(canid_t can_id)
  * can_rcv_list_find - determine optimal filterlist inside device filter struct
  * @can_id: pointer to CAN identifier of a given can_filter
  * @mask: pointer to CAN mask of a given can_filter
- * @d: pointer to the device filter struct
+ * @dev_rcv_lists: pointer to the device filter struct
  *
  * Description:
  *  Returns the optimal filterlist to reduce the filter handling in the
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 02/17] can: softing: softing_card_shutdown(): add  braces around empty body in an 'if' statement
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 01/17] can: af_can: can_rcv_list_find(): fix kernel doc after variable renaming Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 03/17] can: c_can: reg_map_{c,d}_can: mark as __maybe_unused Marc Kleine-Budde
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Marc Kleine-Budde

This patch fixes the following warning when building the kernel with "W=1":

    warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]

Link: http://lore.kernel.org/r/20201006203748.1750156-3-mkl@pengutronix.de
Fixes: 03fd3cf5a179 ("can: add driver for Softing card")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/softing/softing_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c
index 11b0f3bcfe80..9d2faaa39ce4 100644
--- a/drivers/net/can/softing/softing_main.c
+++ b/drivers/net/can/softing/softing_main.c
@@ -447,8 +447,9 @@ static void softing_card_shutdown(struct softing *card)
 {
 	int fw_up = 0;
 
-	if (mutex_lock_interruptible(&card->fw.lock))
+	if (mutex_lock_interruptible(&card->fw.lock)) {
 		/* return -ERESTARTSYS */;
+	}
 	fw_up = card->fw.up;
 	card->fw.up = 0;
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 03/17] can: c_can: reg_map_{c,d}_can: mark as __maybe_unused
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 01/17] can: af_can: can_rcv_list_find(): fix kernel doc after variable renaming Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 02/17] can: softing: softing_card_shutdown(): add braces around empty body in an 'if' statement Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 04/17] MAINTAINERS: adjust to mcp251xfd file renaming Marc Kleine-Budde
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Marc Kleine-Budde

This patch marks the arrays reg_map_c_can and reg_map_d_can as __maybe_unused,
as they are indeed unused in the c_can driver. This warning shows up, when
compiling the kernel with "W=1":

    drivers/net/can/c_can/c_can.c:45:
    drivers/net/can/c_can/c_can.h:124:18: warning: ‘reg_map_d_can’ defined but not used [-Wunused-const-variable=]
    drivers/net/can/c_can/c_can.h:84:18: warning: ‘reg_map_c_can’ defined but not used [-Wunused-const-variable=]

Link: http://lore.kernel.org/r/20201006203748.1750156-4-mkl@pengutronix.de
Fixes: 33f810097769 ("can: c_can: Move overlay structure to array with offset as index")
Fixes: 69927fccd96b ("can: c_can: Add support for Bosch D_CAN controller")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index d5567a7c1c6d..92213d3d96eb 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -81,7 +81,7 @@ enum reg {
 	C_CAN_FUNCTION_REG,
 };
 
-static const u16 reg_map_c_can[] = {
+static const u16 __maybe_unused reg_map_c_can[] = {
 	[C_CAN_CTRL_REG]	= 0x00,
 	[C_CAN_STS_REG]		= 0x02,
 	[C_CAN_ERR_CNT_REG]	= 0x04,
@@ -121,7 +121,7 @@ static const u16 reg_map_c_can[] = {
 	[C_CAN_MSGVAL2_REG]	= 0xB2,
 };
 
-static const u16 reg_map_d_can[] = {
+static const u16 __maybe_unused reg_map_d_can[] = {
 	[C_CAN_CTRL_REG]	= 0x00,
 	[C_CAN_CTRL_EX_REG]	= 0x02,
 	[C_CAN_STS_REG]		= 0x04,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 04/17] MAINTAINERS: adjust to mcp251xfd file renaming
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 03/17] can: c_can: reg_map_{c,d}_can: mark as __maybe_unused Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 05/17] can: raw: add missing error queue support Marc Kleine-Budde
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Lukas Bulwahn, Marc Kleine-Budde

From: Lukas Bulwahn <lukas.bulwahn@gmail.com>

Commit 27cf93863cbc ("MAINTAINERS: Add entry for Microchip MCP25XXFD
SPI-CAN network driver"), added the MCP25XXFD SPI-CAN NETWORK DRIVER
section with the following two file entries:

F:      Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.yaml
F:      drivers/net/can/spi/mcp25xxfd/

Commit 1f0e21a0c065 ("can: mcp251xfd: rename driver files and subdir to
mcp251xfd") renamed the files from mcp25xxfd to mcp251xfd, but missed to
adjust the MAINTAINERS section.

Hence, ./scripts/get_maintainer.pl --self-test=patterns complains:

  warning: no file matches    F: \
      Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.yaml
  warning: no file matches    F:    drivers/net/can/spi/mcp25xxfd/

Adjust the MCP251XFD SPI-CAN NETWORK DRIVER section to this driver file
renaming.

Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Link: https://lore.kernel.org/r/20201003075500.12477-1-lukas.bulwahn@gmail.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 MAINTAINERS | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 734d4dc61084..d651a0934be7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10675,14 +10675,14 @@ L:	linux-input@vger.kernel.org
 S:	Maintained
 F:	drivers/hid/hid-mcp2221.c
 
-MCP25XXFD SPI-CAN NETWORK DRIVER
+MCP251XFD SPI-CAN NETWORK DRIVER
 M:	Marc Kleine-Budde <mkl@pengutronix.de>
 M:	Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
 R:	Thomas Kopp <thomas.kopp@microchip.com>
 L:	linux-can@vger.kernel.org
 S:	Maintained
-F:	Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.yaml
-F:	drivers/net/can/spi/mcp25xxfd/
+F:	Documentation/devicetree/bindings/net/can/microchip,mcp251xfd.yaml
+F:	drivers/net/can/spi/mcp251xfd/
 
 MCP4018 AND MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVERS
 M:	Peter Rosin <peda@axentia.se>
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 05/17] can: raw: add missing error queue support
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 04/17] MAINTAINERS: adjust to mcp251xfd file renaming Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 06/17] can: dev: fix type of get_can_dlc() and get_canfd_dlc() macros Marc Kleine-Budde
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Vincent Mailhol, Oliver Hartkopp,
	Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

Error queue are not yet implemented in CAN-raw sockets.

The problem: a userland call to recvmsg(soc, msg, MSG_ERRQUEUE) on a
CAN-raw socket would unqueue messages from the normal queue without
any kind of error or warning. As such, it prevented CAN drivers from
using the functionalities that relies on the error queue such as
skb_tx_timestamp().

SCM_CAN_RAW_ERRQUEUE is defined as the type for the CAN raw error
queue. SCM stands for "Socket control messages". The name is inspired
from SCM_J1939_ERRQUEUE of include/uapi/linux/can/j1939.h.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/r/20200926162527.270030-1-mailhol.vincent@wanadoo.fr
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 include/uapi/linux/can/raw.h | 3 +++
 net/can/raw.c                | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/include/uapi/linux/can/raw.h b/include/uapi/linux/can/raw.h
index 6a11d308eb5c..3386aa81fdf2 100644
--- a/include/uapi/linux/can/raw.h
+++ b/include/uapi/linux/can/raw.h
@@ -49,6 +49,9 @@
 #include <linux/can.h>
 
 #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+enum {
+	SCM_CAN_RAW_ERRQUEUE = 1,
+};
 
 /* for socket options affecting the socket (not the global system) */
 
diff --git a/net/can/raw.c b/net/can/raw.c
index 24db4b4afdc7..ea70850f9152 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -804,6 +804,10 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
 	noblock = flags & MSG_DONTWAIT;
 	flags &= ~MSG_DONTWAIT;
 
+	if (flags & MSG_ERRQUEUE)
+		return sock_recv_errqueue(sk, msg, size,
+					  SOL_CAN_RAW, SCM_CAN_RAW_ERRQUEUE);
+
 	skb = skb_recv_datagram(sk, flags, noblock, &err);
 	if (!skb)
 		return err;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 06/17] can: dev: fix type of get_can_dlc() and get_canfd_dlc() macros
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 05/17] can: raw: add missing error queue support Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 07/17] can: dev: add a helper function to calculate the duration of one bit Marc Kleine-Budde
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Vincent Mailhol, Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

The macros get_can_dlc() and get_canfd_dlc() are not visible in
userland. As such, type u8 should be preferred over type __u8.

Reference: https://lkml.org/lkml/2020/10/1/708
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/r/20201002154219.4887-3-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 include/linux/can/dev.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index ed0482b2f4b2..f8975d0b90bb 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -84,13 +84,13 @@ struct can_priv {
 
 /*
  * get_can_dlc(value) - helper macro to cast a given data length code (dlc)
- * to __u8 and ensure the dlc value to be max. 8 bytes.
+ * to u8 and ensure the dlc value to be max. 8 bytes.
  *
  * To be used in the CAN netdriver receive path to ensure conformance with
  * ISO 11898-1 Chapter 8.4.2.3 (DLC field)
  */
-#define get_can_dlc(i)		(min_t(__u8, (i), CAN_MAX_DLC))
-#define get_canfd_dlc(i)	(min_t(__u8, (i), CANFD_MAX_DLC))
+#define get_can_dlc(i)		(min_t(u8, (i), CAN_MAX_DLC))
+#define get_canfd_dlc(i)	(min_t(u8, (i), CANFD_MAX_DLC))
 
 /* Check for outgoing skbs that have not been created by the CAN subsystem */
 static inline bool can_skb_headroom_valid(struct net_device *dev,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 07/17] can: dev: add a helper function to calculate the duration of one bit
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 06/17] can: dev: fix type of get_can_dlc() and get_canfd_dlc() macros Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol Marc Kleine-Budde
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Vincent Mailhol, Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

Rename macro CAN_CALC_SYNC_SEG to CAN_SYNC_SEG and make it available
through include/linux/can/dev.h

Add an helper function can_bit_time() which returns the duration (in
time quanta) of one CAN bit.

Rationale for this patch: the sync segment and the bit time are two
concepts which are defined in the CAN ISO standard. Device drivers for
CAN might need those.

Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for
additional information.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/r/20201002154219.4887-6-mailhol.vincent@wanadoo.fr
[mkl: Let can_bit_time() return an unsinged int, make argument const]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/dev.c   | 13 ++++++-------
 include/linux/can/dev.h | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 3c40bba71d5b..b70ded3760f2 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -60,7 +60,6 @@ EXPORT_SYMBOL_GPL(can_len2dlc);
 
 #ifdef CONFIG_CAN_CALC_BITTIMING
 #define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
-#define CAN_CALC_SYNC_SEG 1
 
 /* Bit-timing calculation derived from:
  *
@@ -86,8 +85,8 @@ can_update_sample_point(const struct can_bittiming_const *btc,
 	int i;
 
 	for (i = 0; i <= 1; i++) {
-		tseg2 = tseg + CAN_CALC_SYNC_SEG -
-			(sample_point_nominal * (tseg + CAN_CALC_SYNC_SEG)) /
+		tseg2 = tseg + CAN_SYNC_SEG -
+			(sample_point_nominal * (tseg + CAN_SYNC_SEG)) /
 			1000 - i;
 		tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max);
 		tseg1 = tseg - tseg2;
@@ -96,8 +95,8 @@ can_update_sample_point(const struct can_bittiming_const *btc,
 			tseg2 = tseg - tseg1;
 		}
 
-		sample_point = 1000 * (tseg + CAN_CALC_SYNC_SEG - tseg2) /
-			(tseg + CAN_CALC_SYNC_SEG);
+		sample_point = 1000 * (tseg + CAN_SYNC_SEG - tseg2) /
+			(tseg + CAN_SYNC_SEG);
 		sample_point_error = abs(sample_point_nominal - sample_point);
 
 		if (sample_point <= sample_point_nominal &&
@@ -145,7 +144,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
 	/* tseg even = round down, odd = round up */
 	for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1;
 	     tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) {
-		tsegall = CAN_CALC_SYNC_SEG + tseg / 2;
+		tsegall = CAN_SYNC_SEG + tseg / 2;
 
 		/* Compute all possible tseg choices (tseg=tseg1+tseg2) */
 		brp = priv->clock.freq / (tsegall * bt->bitrate) + tseg % 2;
@@ -223,7 +222,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
 
 	/* real bitrate */
 	bt->bitrate = priv->clock.freq /
-		(bt->brp * (CAN_CALC_SYNC_SEG + tseg1 + tseg2));
+		(bt->brp * (CAN_SYNC_SEG + tseg1 + tseg2));
 
 	return 0;
 }
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index f8975d0b90bb..41ff31795320 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -82,6 +82,21 @@ struct can_priv {
 #endif
 };
 
+#define CAN_SYNC_SEG 1
+
+/*
+ * can_bit_time() - Duration of one bit
+ *
+ * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for
+ * additional information.
+ *
+ * Return: the number of time quanta in one bit.
+ */
+static inline unsigned int can_bit_time(const struct can_bittiming *bt)
+{
+	return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2;
+}
+
 /*
  * get_can_dlc(value) - helper macro to cast a given data length code (dlc)
  * to u8 and ensure the dlc value to be max. 8 bytes.
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 07/17] can: dev: add a helper function to calculate the duration of one bit Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-10  0:57   ` Jakub Kicinski
  2020-10-07 21:31 ` [PATCH 09/17] dt-bindings: can: rcar_can: Add r8a7742 support Marc Kleine-Budde
                   ` (9 subsequent siblings)
  17 siblings, 1 reply; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Oliver Hartkopp, Marc Kleine-Budde

From: Oliver Hartkopp <socketcan@hartkopp.net>

CAN Transport Protocols offer support for segmented Point-to-Point
communication between CAN nodes via two defined CAN Identifiers.
As CAN frames can only transport a small amount of data bytes
(max. 8 bytes for 'classic' CAN and max. 64 bytes for CAN FD) this
segmentation is needed to transport longer PDUs as needed e.g. for
vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic.
This protocol driver implements data transfers according to
ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/r/20200928200404.82229-1-socketcan@hartkopp.net
[mkl: Removed "WITH Linux-syscall-note" from isotp.c.
      Fixed indention, a checkpatch warning and typos.
      Replaced __u{8,32} by u{8,32}.
      Removed always false (optlen < 0) check in isotp_setsockopt().]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 MAINTAINERS                    |    1 +
 include/uapi/linux/can/isotp.h |  166 ++++
 net/can/Kconfig                |   13 +
 net/can/Makefile               |    3 +
 net/can/isotp.c                | 1426 ++++++++++++++++++++++++++++++++
 5 files changed, 1609 insertions(+)
 create mode 100644 include/uapi/linux/can/isotp.h
 create mode 100644 net/can/isotp.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d651a0934be7..7a8a53adba91 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3912,6 +3912,7 @@ F:	include/net/netns/can.h
 F:	include/uapi/linux/can.h
 F:	include/uapi/linux/can/bcm.h
 F:	include/uapi/linux/can/gw.h
+F:	include/uapi/linux/can/isotp.h
 F:	include/uapi/linux/can/raw.h
 F:	net/can/
 
diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
new file mode 100644
index 000000000000..553006509f4e
--- /dev/null
+++ b/include/uapi/linux/can/isotp.h
@@ -0,0 +1,166 @@
+/* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */
+/*
+ * linux/can/isotp.h
+ *
+ * Definitions for isotp CAN sockets (ISO 15765-2:2016)
+ *
+ * Copyright (c) 2020 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Volkswagen nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License ("GPL") version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+#ifndef _UAPI_CAN_ISOTP_H
+#define _UAPI_CAN_ISOTP_H
+
+#include <linux/types.h>
+#include <linux/can.h>
+
+#define SOL_CAN_ISOTP (SOL_CAN_BASE + CAN_ISOTP)
+
+/* for socket options affecting the socket (not the global system) */
+
+#define CAN_ISOTP_OPTS		1	/* pass struct can_isotp_options */
+
+#define CAN_ISOTP_RECV_FC	2	/* pass struct can_isotp_fc_options */
+
+/* sockopts to force stmin timer values for protocol regression tests */
+
+#define CAN_ISOTP_TX_STMIN	3	/* pass __u32 value in nano secs    */
+					/* use this time instead of value   */
+					/* provided in FC from the receiver */
+
+#define CAN_ISOTP_RX_STMIN	4	/* pass __u32 value in nano secs   */
+					/* ignore received CF frames which */
+					/* timestamps differ less than val */
+
+#define CAN_ISOTP_LL_OPTS	5	/* pass struct can_isotp_ll_options */
+
+struct can_isotp_options {
+
+	__u32 flags;		/* set flags for isotp behaviour.	*/
+				/* __u32 value : flags see below	*/
+
+	__u32 frame_txtime;	/* frame transmission time (N_As/N_Ar)	*/
+				/* __u32 value : time in nano secs	*/
+
+	__u8  ext_address;	/* set address for extended addressing	*/
+				/* __u8 value : extended address	*/
+
+	__u8  txpad_content;	/* set content of padding byte (tx)	*/
+				/* __u8 value : content	on tx path	*/
+
+	__u8  rxpad_content;	/* set content of padding byte (rx)	*/
+				/* __u8 value : content	on rx path	*/
+
+	__u8  rx_ext_address;	/* set address for extended addressing	*/
+				/* __u8 value : extended address (rx)	*/
+};
+
+struct can_isotp_fc_options {
+
+	__u8  bs;		/* blocksize provided in FC frame	*/
+				/* __u8 value : blocksize. 0 = off	*/
+
+	__u8  stmin;		/* separation time provided in FC frame	*/
+				/* __u8 value :				*/
+				/* 0x00 - 0x7F : 0 - 127 ms		*/
+				/* 0x80 - 0xF0 : reserved		*/
+				/* 0xF1 - 0xF9 : 100 us - 900 us	*/
+				/* 0xFA - 0xFF : reserved		*/
+
+	__u8  wftmax;		/* max. number of wait frame transmiss.	*/
+				/* __u8 value : 0 = omit FC N_PDU WT	*/
+};
+
+struct can_isotp_ll_options {
+
+	__u8  mtu;		/* generated & accepted CAN frame type	*/
+				/* __u8 value :				*/
+				/* CAN_MTU   (16) -> standard CAN 2.0	*/
+				/* CANFD_MTU (72) -> CAN FD frame	*/
+
+	__u8  tx_dl;		/* tx link layer data length in bytes	*/
+				/* (configured maximum payload length)	*/
+				/* __u8 value : 8,12,16,20,24,32,48,64	*/
+				/* => rx path supports all LL_DL values */
+
+	__u8  tx_flags;		/* set into struct canfd_frame.flags	*/
+				/* at frame creation: e.g. CANFD_BRS	*/
+				/* Obsolete when the BRS flag is fixed	*/
+				/* by the CAN netdriver configuration	*/
+};
+
+/* flags for isotp behaviour */
+
+#define CAN_ISOTP_LISTEN_MODE	0x001	/* listen only (do not send FC) */
+#define CAN_ISOTP_EXTEND_ADDR	0x002	/* enable extended addressing */
+#define CAN_ISOTP_TX_PADDING	0x004	/* enable CAN frame padding tx path */
+#define CAN_ISOTP_RX_PADDING	0x008	/* enable CAN frame padding rx path */
+#define CAN_ISOTP_CHK_PAD_LEN	0x010	/* check received CAN frame padding */
+#define CAN_ISOTP_CHK_PAD_DATA	0x020	/* check received CAN frame padding */
+#define CAN_ISOTP_HALF_DUPLEX	0x040	/* half duplex error state handling */
+#define CAN_ISOTP_FORCE_TXSTMIN	0x080	/* ignore stmin from received FC */
+#define CAN_ISOTP_FORCE_RXSTMIN	0x100	/* ignore CFs depending on rx stmin */
+#define CAN_ISOTP_RX_EXT_ADDR	0x200	/* different rx extended addressing */
+#define CAN_ISOTP_WAIT_TX_DONE	0x400	/* wait for tx completion */
+
+
+/* default values */
+
+#define CAN_ISOTP_DEFAULT_FLAGS		0
+#define CAN_ISOTP_DEFAULT_EXT_ADDRESS	0x00
+#define CAN_ISOTP_DEFAULT_PAD_CONTENT	0xCC /* prevent bit-stuffing */
+#define CAN_ISOTP_DEFAULT_FRAME_TXTIME	0
+#define CAN_ISOTP_DEFAULT_RECV_BS	0
+#define CAN_ISOTP_DEFAULT_RECV_STMIN	0x00
+#define CAN_ISOTP_DEFAULT_RECV_WFTMAX	0
+
+#define CAN_ISOTP_DEFAULT_LL_MTU	CAN_MTU
+#define CAN_ISOTP_DEFAULT_LL_TX_DL	CAN_MAX_DLEN
+#define CAN_ISOTP_DEFAULT_LL_TX_FLAGS	0
+
+/*
+ * Remark on CAN_ISOTP_DEFAULT_RECV_* values:
+ *
+ * We can strongly assume, that the Linux Kernel implementation of
+ * CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0.
+ * But as we like to be able to behave as a commonly available ECU,
+ * these default settings can be changed via sockopts.
+ * For that reason the STmin value is intentionally _not_ checked for
+ * consistency and copied directly into the flow control (FC) frame.
+ *
+ */
+
+#endif /* !_UAPI_CAN_ISOTP_H */
diff --git a/net/can/Kconfig b/net/can/Kconfig
index 25436a715db3..021fe03a8ed6 100644
--- a/net/can/Kconfig
+++ b/net/can/Kconfig
@@ -55,6 +55,19 @@ config CAN_GW
 
 source "net/can/j1939/Kconfig"
 
+config CAN_ISOTP
+	tristate "ISO 15765-2:2016 CAN transport protocol"
+	default y
+	help
+	  CAN Transport Protocols offer support for segmented Point-to-Point
+	  communication between CAN nodes via two defined CAN Identifiers.
+	  As CAN frames can only transport a small amount of data bytes
+	  (max. 8 bytes for 'classic' CAN and max. 64 bytes for CAN FD) this
+	  segmentation is needed to transport longer PDUs as needed e.g. for
+	  vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic.
+	  This protocol driver implements data transfers according to
+	  ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.
+
 source "drivers/net/can/Kconfig"
 
 endif
diff --git a/net/can/Makefile b/net/can/Makefile
index 08bd217fc051..58f2c31c1ef3 100644
--- a/net/can/Makefile
+++ b/net/can/Makefile
@@ -17,3 +17,6 @@ obj-$(CONFIG_CAN_GW)	+= can-gw.o
 can-gw-y		:= gw.o
 
 obj-$(CONFIG_CAN_J1939)	+= j1939/
+
+obj-$(CONFIG_CAN_ISOTP)	+= can-isotp.o
+can-isotp-y		:= isotp.o
diff --git a/net/can/isotp.c b/net/can/isotp.c
new file mode 100644
index 000000000000..e6ff032b5426
--- /dev/null
+++ b/net/can/isotp.c
@@ -0,0 +1,1426 @@
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+/* isotp.c - ISO 15765-2 CAN transport protocol for protocol family CAN
+ *
+ * This implementation does not provide ISO-TP specific return values to the
+ * userspace.
+ *
+ * - RX path timeout of data reception leads to -ETIMEDOUT
+ * - RX path SN mismatch leads to -EILSEQ
+ * - RX path data reception with wrong padding leads to -EBADMSG
+ * - TX path flowcontrol reception timeout leads to -ECOMM
+ * - TX path flowcontrol reception overflow leads to -EMSGSIZE
+ * - TX path flowcontrol reception with wrong layout/padding leads to -EBADMSG
+ * - when a transfer (tx) is on the run the next write() blocks until it's done
+ * - use CAN_ISOTP_WAIT_TX_DONE flag to block the caller until the PDU is sent
+ * - as we have static buffers the check whether the PDU fits into the buffer
+ *   is done at FF reception time (no support for sending 'wait frames')
+ * - take care of the tx-queue-len as traffic shaping is still on the TODO list
+ *
+ * Copyright (c) 2020 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Volkswagen nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License ("GPL") version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/hrtimer.h>
+#include <linux/wait.h>
+#include <linux/uio.h>
+#include <linux/net.h>
+#include <linux/netdevice.h>
+#include <linux/socket.h>
+#include <linux/if_arp.h>
+#include <linux/skbuff.h>
+#include <linux/can.h>
+#include <linux/can/core.h>
+#include <linux/can/skb.h>
+#include <linux/can/isotp.h>
+#include <linux/slab.h>
+#include <net/sock.h>
+#include <net/net_namespace.h>
+
+#define CAN_ISOTP_VERSION "20200928"
+
+MODULE_DESCRIPTION("PF_CAN isotp 15765-2:2016 protocol");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_AUTHOR("Oliver Hartkopp <socketcan@hartkopp.net>");
+MODULE_ALIAS("can-proto-6");
+
+#define SINGLE_MASK(id) (((id) & CAN_EFF_FLAG) ? \
+			 (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \
+			 (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG))
+
+/* ISO 15765-2:2016 supports more than 4095 byte per ISO PDU as the FF_DL can
+ * take full 32 bit values (4 Gbyte). We would need some good concept to handle
+ * this between user space and kernel space. For now increase the static buffer
+ * to something about 8 kbyte to be able to test this new functionality.
+ */
+#define MAX_MSG_LENGTH 8200
+
+/* N_PCI type values in bits 7-4 of N_PCI bytes */
+#define N_PCI_SF 0x00	/* single frame */
+#define N_PCI_FF 0x10	/* first frame */
+#define N_PCI_CF 0x20	/* consecutive frame */
+#define N_PCI_FC 0x30	/* flow control */
+
+#define N_PCI_SZ 1	/* size of the PCI byte #1 */
+#define SF_PCI_SZ4 1	/* size of SingleFrame PCI including 4 bit SF_DL */
+#define SF_PCI_SZ8 2	/* size of SingleFrame PCI including 8 bit SF_DL */
+#define FF_PCI_SZ12 2	/* size of FirstFrame PCI including 12 bit FF_DL */
+#define FF_PCI_SZ32 6	/* size of FirstFrame PCI including 32 bit FF_DL */
+#define FC_CONTENT_SZ 3	/* flow control content size in byte (FS/BS/STmin) */
+
+#define ISOTP_CHECK_PADDING (CAN_ISOTP_CHK_PAD_LEN | CAN_ISOTP_CHK_PAD_DATA)
+
+/* Flow Status given in FC frame */
+#define ISOTP_FC_CTS 0		/* clear to send */
+#define ISOTP_FC_WT 1		/* wait */
+#define ISOTP_FC_OVFLW 2	/* overflow */
+
+enum {
+	ISOTP_IDLE = 0,
+	ISOTP_WAIT_FIRST_FC,
+	ISOTP_WAIT_FC,
+	ISOTP_WAIT_DATA,
+	ISOTP_SENDING
+};
+
+struct tpcon {
+	int idx;
+	int len;
+	u8 state;
+	u8 bs;
+	u8 sn;
+	u8 ll_dl;
+	u8 buf[MAX_MSG_LENGTH + 1];
+};
+
+struct isotp_sock {
+	struct sock sk;
+	int bound;
+	int ifindex;
+	canid_t txid;
+	canid_t rxid;
+	ktime_t tx_gap;
+	ktime_t lastrxcf_tstamp;
+	struct hrtimer rxtimer, txtimer;
+	struct can_isotp_options opt;
+	struct can_isotp_fc_options rxfc, txfc;
+	struct can_isotp_ll_options ll;
+	u32 force_tx_stmin;
+	u32 force_rx_stmin;
+	struct tpcon rx, tx;
+	struct notifier_block notifier;
+	wait_queue_head_t wait;
+};
+
+static inline struct isotp_sock *isotp_sk(const struct sock *sk)
+{
+	return (struct isotp_sock *)sk;
+}
+
+static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
+{
+	struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
+					     rxtimer);
+	struct sock *sk = &so->sk;
+
+	if (so->rx.state == ISOTP_WAIT_DATA) {
+		/* we did not get new data frames in time */
+
+		/* report 'connection timed out' */
+		sk->sk_err = ETIMEDOUT;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+
+		/* reset rx state */
+		so->rx.state = ISOTP_IDLE;
+	}
+
+	return HRTIMER_NORESTART;
+}
+
+static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
+{
+	struct net_device *dev;
+	struct sk_buff *nskb;
+	struct canfd_frame *ncf;
+	struct isotp_sock *so = isotp_sk(sk);
+	int can_send_ret;
+
+	nskb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv), gfp_any());
+	if (!nskb)
+		return 1;
+
+	dev = dev_get_by_index(sock_net(sk), so->ifindex);
+	if (!dev) {
+		kfree_skb(nskb);
+		return 1;
+	}
+
+	can_skb_reserve(nskb);
+	can_skb_prv(nskb)->ifindex = dev->ifindex;
+	can_skb_prv(nskb)->skbcnt = 0;
+
+	nskb->dev = dev;
+	can_skb_set_owner(nskb, sk);
+	ncf = (struct canfd_frame *)nskb->data;
+	skb_put(nskb, so->ll.mtu);
+
+	/* create & send flow control reply */
+	ncf->can_id = so->txid;
+
+	if (so->opt.flags & CAN_ISOTP_TX_PADDING) {
+		memset(ncf->data, so->opt.txpad_content, CAN_MAX_DLEN);
+		ncf->len = CAN_MAX_DLEN;
+	} else {
+		ncf->len = ae + FC_CONTENT_SZ;
+	}
+
+	ncf->data[ae] = N_PCI_FC | flowstatus;
+	ncf->data[ae + 1] = so->rxfc.bs;
+	ncf->data[ae + 2] = so->rxfc.stmin;
+
+	if (ae)
+		ncf->data[0] = so->opt.ext_address;
+
+	if (so->ll.mtu == CANFD_MTU)
+		ncf->flags = so->ll.tx_flags;
+
+	can_send_ret = can_send(nskb, 1);
+	if (can_send_ret)
+		printk_once(KERN_NOTICE "can-isotp: %s: can_send_ret %d\n",
+			    __func__, can_send_ret);
+
+	dev_put(dev);
+
+	/* reset blocksize counter */
+	so->rx.bs = 0;
+
+	/* reset last CF frame rx timestamp for rx stmin enforcement */
+	so->lastrxcf_tstamp = ktime_set(0, 0);
+
+	/* start rx timeout watchdog */
+	hrtimer_start(&so->rxtimer, ktime_set(1, 0), HRTIMER_MODE_REL_SOFT);
+	return 0;
+}
+
+static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
+{
+	struct sockaddr_can *addr = (struct sockaddr_can *)skb->cb;
+
+	BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can));
+
+	memset(addr, 0, sizeof(*addr));
+	addr->can_family = AF_CAN;
+	addr->can_ifindex = skb->dev->ifindex;
+
+	if (sock_queue_rcv_skb(sk, skb) < 0)
+		kfree_skb(skb);
+}
+
+static u8 padlen(u8 datalen)
+{
+	const u8 plen[] = {8, 8, 8, 8, 8, 8, 8, 8, 8,		/* 0 - 8 */
+			   12, 12, 12, 12,			/* 9 - 12 */
+			   16, 16, 16, 16,			/* 13 - 16 */
+			   20, 20, 20, 20,			/* 17 - 20 */
+			   24, 24, 24, 24,			/* 21 - 24 */
+			   32, 32, 32, 32, 32, 32, 32, 32,	/* 25 - 32 */
+			   48, 48, 48, 48, 48, 48, 48, 48,	/* 33 - 40 */
+			   48, 48, 48, 48, 48, 48, 48, 48};	/* 41 - 48 */
+
+	if (datalen > 48)
+		return 64;
+
+	return plen[datalen];
+}
+
+/* check for length optimization and return 1/true when the check fails */
+static int check_optimized(struct canfd_frame *cf, int start_index)
+{
+	/* for CAN_DL <= 8 the start_index is equal to the CAN_DL as the
+	 * padding would start at this point. E.g. if the padding would
+	 * start at cf.data[7] cf->len has to be 7 to be optimal.
+	 * Note: The data[] index starts with zero.
+	 */
+	if (cf->len <= CAN_MAX_DLEN)
+		return (cf->len != start_index);
+
+	/* This relation is also valid in the non-linear DLC range, where
+	 * we need to take care of the minimal next possible CAN_DL.
+	 * The correct check would be (padlen(cf->len) != padlen(start_index)).
+	 * But as cf->len can only take discrete values from 12, .., 64 at this
+	 * point the padlen(cf->len) is always equal to cf->len.
+	 */
+	return (cf->len != padlen(start_index));
+}
+
+/* check padding and return 1/true when the check fails */
+static int check_pad(struct isotp_sock *so, struct canfd_frame *cf,
+		     int start_index, u8 content)
+{
+	int i;
+
+	/* no RX_PADDING value => check length of optimized frame length */
+	if (!(so->opt.flags & CAN_ISOTP_RX_PADDING)) {
+		if (so->opt.flags & CAN_ISOTP_CHK_PAD_LEN)
+			return check_optimized(cf, start_index);
+
+		/* no valid test against empty value => ignore frame */
+		return 1;
+	}
+
+	/* check datalength of correctly padded CAN frame */
+	if ((so->opt.flags & CAN_ISOTP_CHK_PAD_LEN) &&
+	    cf->len != padlen(cf->len))
+		return 1;
+
+	/* check padding content */
+	if (so->opt.flags & CAN_ISOTP_CHK_PAD_DATA) {
+		for (i = start_index; i < cf->len; i++)
+			if (cf->data[i] != content)
+				return 1;
+	}
+	return 0;
+}
+
+static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
+{
+	struct sock *sk = &so->sk;
+
+	if (so->tx.state != ISOTP_WAIT_FC &&
+	    so->tx.state != ISOTP_WAIT_FIRST_FC)
+		return 0;
+
+	hrtimer_cancel(&so->txtimer);
+
+	if ((cf->len < ae + FC_CONTENT_SZ) ||
+	    ((so->opt.flags & ISOTP_CHECK_PADDING) &&
+	     check_pad(so, cf, ae + FC_CONTENT_SZ, so->opt.rxpad_content))) {
+		/* malformed PDU - report 'not a data message' */
+		sk->sk_err = EBADMSG;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+
+		so->tx.state = ISOTP_IDLE;
+		wake_up_interruptible(&so->wait);
+		return 1;
+	}
+
+	/* get communication parameters only from the first FC frame */
+	if (so->tx.state == ISOTP_WAIT_FIRST_FC) {
+		so->txfc.bs = cf->data[ae + 1];
+		so->txfc.stmin = cf->data[ae + 2];
+
+		/* fix wrong STmin values according spec */
+		if (so->txfc.stmin > 0x7F &&
+		    (so->txfc.stmin < 0xF1 || so->txfc.stmin > 0xF9))
+			so->txfc.stmin = 0x7F;
+
+		so->tx_gap = ktime_set(0, 0);
+		/* add transmission time for CAN frame N_As */
+		so->tx_gap = ktime_add_ns(so->tx_gap, so->opt.frame_txtime);
+		/* add waiting time for consecutive frames N_Cs */
+		if (so->opt.flags & CAN_ISOTP_FORCE_TXSTMIN)
+			so->tx_gap = ktime_add_ns(so->tx_gap,
+						  so->force_tx_stmin);
+		else if (so->txfc.stmin < 0x80)
+			so->tx_gap = ktime_add_ns(so->tx_gap,
+						  so->txfc.stmin * 1000000);
+		else
+			so->tx_gap = ktime_add_ns(so->tx_gap,
+						  (so->txfc.stmin - 0xF0)
+						  * 100000);
+		so->tx.state = ISOTP_WAIT_FC;
+	}
+
+	switch (cf->data[ae] & 0x0F) {
+	case ISOTP_FC_CTS:
+		so->tx.bs = 0;
+		so->tx.state = ISOTP_SENDING;
+		/* start cyclic timer for sending CF frame */
+		hrtimer_start(&so->txtimer, so->tx_gap,
+			      HRTIMER_MODE_REL_SOFT);
+		break;
+
+	case ISOTP_FC_WT:
+		/* start timer to wait for next FC frame */
+		hrtimer_start(&so->txtimer, ktime_set(1, 0),
+			      HRTIMER_MODE_REL_SOFT);
+		break;
+
+	case ISOTP_FC_OVFLW:
+		/* overflow on receiver side - report 'message too long' */
+		sk->sk_err = EMSGSIZE;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+		fallthrough;
+
+	default:
+		/* stop this tx job */
+		so->tx.state = ISOTP_IDLE;
+		wake_up_interruptible(&so->wait);
+	}
+	return 0;
+}
+
+static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
+			struct sk_buff *skb, int len)
+{
+	struct isotp_sock *so = isotp_sk(sk);
+	struct sk_buff *nskb;
+
+	hrtimer_cancel(&so->rxtimer);
+	so->rx.state = ISOTP_IDLE;
+
+	if (!len || len > cf->len - pcilen)
+		return 1;
+
+	if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
+	    check_pad(so, cf, pcilen + len, so->opt.rxpad_content)) {
+		/* malformed PDU - report 'not a data message' */
+		sk->sk_err = EBADMSG;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+		return 1;
+	}
+
+	nskb = alloc_skb(len, gfp_any());
+	if (!nskb)
+		return 1;
+
+	memcpy(skb_put(nskb, len), &cf->data[pcilen], len);
+
+	nskb->tstamp = skb->tstamp;
+	nskb->dev = skb->dev;
+	isotp_rcv_skb(nskb, sk);
+	return 0;
+}
+
+static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
+{
+	struct isotp_sock *so = isotp_sk(sk);
+	int i;
+	int off;
+	int ff_pci_sz;
+
+	hrtimer_cancel(&so->rxtimer);
+	so->rx.state = ISOTP_IDLE;
+
+	/* get the used sender LL_DL from the (first) CAN frame data length */
+	so->rx.ll_dl = padlen(cf->len);
+
+	/* the first frame has to use the entire frame up to LL_DL length */
+	if (cf->len != so->rx.ll_dl)
+		return 1;
+
+	/* get the FF_DL */
+	so->rx.len = (cf->data[ae] & 0x0F) << 8;
+	so->rx.len += cf->data[ae + 1];
+
+	/* Check for FF_DL escape sequence supporting 32 bit PDU length */
+	if (so->rx.len) {
+		ff_pci_sz = FF_PCI_SZ12;
+	} else {
+		/* FF_DL = 0 => get real length from next 4 bytes */
+		so->rx.len = cf->data[ae + 2] << 24;
+		so->rx.len += cf->data[ae + 3] << 16;
+		so->rx.len += cf->data[ae + 4] << 8;
+		so->rx.len += cf->data[ae + 5];
+		ff_pci_sz = FF_PCI_SZ32;
+	}
+
+	/* take care of a potential SF_DL ESC offset for TX_DL > 8 */
+	off = (so->rx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
+
+	if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl)
+		return 1;
+
+	if (so->rx.len > MAX_MSG_LENGTH) {
+		/* send FC frame with overflow status */
+		isotp_send_fc(sk, ae, ISOTP_FC_OVFLW);
+		return 1;
+	}
+
+	/* copy the first received data bytes */
+	so->rx.idx = 0;
+	for (i = ae + ff_pci_sz; i < so->rx.ll_dl; i++)
+		so->rx.buf[so->rx.idx++] = cf->data[i];
+
+	/* initial setup for this pdu reception */
+	so->rx.sn = 1;
+	so->rx.state = ISOTP_WAIT_DATA;
+
+	/* no creation of flow control frames */
+	if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
+		return 0;
+
+	/* send our first FC frame */
+	isotp_send_fc(sk, ae, ISOTP_FC_CTS);
+	return 0;
+}
+
+static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
+			struct sk_buff *skb)
+{
+	struct isotp_sock *so = isotp_sk(sk);
+	struct sk_buff *nskb;
+	int i;
+
+	if (so->rx.state != ISOTP_WAIT_DATA)
+		return 0;
+
+	/* drop if timestamp gap is less than force_rx_stmin nano secs */
+	if (so->opt.flags & CAN_ISOTP_FORCE_RXSTMIN) {
+		if (ktime_to_ns(ktime_sub(skb->tstamp, so->lastrxcf_tstamp)) <
+		    so->force_rx_stmin)
+			return 0;
+
+		so->lastrxcf_tstamp = skb->tstamp;
+	}
+
+	hrtimer_cancel(&so->rxtimer);
+
+	/* CFs are never longer than the FF */
+	if (cf->len > so->rx.ll_dl)
+		return 1;
+
+	/* CFs have usually the LL_DL length */
+	if (cf->len < so->rx.ll_dl) {
+		/* this is only allowed for the last CF */
+		if (so->rx.len - so->rx.idx > so->rx.ll_dl - ae - N_PCI_SZ)
+			return 1;
+	}
+
+	if ((cf->data[ae] & 0x0F) != so->rx.sn) {
+		/* wrong sn detected - report 'illegal byte sequence' */
+		sk->sk_err = EILSEQ;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+
+		/* reset rx state */
+		so->rx.state = ISOTP_IDLE;
+		return 1;
+	}
+	so->rx.sn++;
+	so->rx.sn %= 16;
+
+	for (i = ae + N_PCI_SZ; i < cf->len; i++) {
+		so->rx.buf[so->rx.idx++] = cf->data[i];
+		if (so->rx.idx >= so->rx.len)
+			break;
+	}
+
+	if (so->rx.idx >= so->rx.len) {
+		/* we are done */
+		so->rx.state = ISOTP_IDLE;
+
+		if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
+		    check_pad(so, cf, i + 1, so->opt.rxpad_content)) {
+			/* malformed PDU - report 'not a data message' */
+			sk->sk_err = EBADMSG;
+			if (!sock_flag(sk, SOCK_DEAD))
+				sk->sk_error_report(sk);
+			return 1;
+		}
+
+		nskb = alloc_skb(so->rx.len, gfp_any());
+		if (!nskb)
+			return 1;
+
+		memcpy(skb_put(nskb, so->rx.len), so->rx.buf,
+		       so->rx.len);
+
+		nskb->tstamp = skb->tstamp;
+		nskb->dev = skb->dev;
+		isotp_rcv_skb(nskb, sk);
+		return 0;
+	}
+
+	/* no creation of flow control frames */
+	if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
+		return 0;
+
+	/* perform blocksize handling, if enabled */
+	if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs) {
+		/* start rx timeout watchdog */
+		hrtimer_start(&so->rxtimer, ktime_set(1, 0),
+			      HRTIMER_MODE_REL_SOFT);
+		return 0;
+	}
+
+	/* we reached the specified blocksize so->rxfc.bs */
+	isotp_send_fc(sk, ae, ISOTP_FC_CTS);
+	return 0;
+}
+
+static void isotp_rcv(struct sk_buff *skb, void *data)
+{
+	struct sock *sk = (struct sock *)data;
+	struct isotp_sock *so = isotp_sk(sk);
+	struct canfd_frame *cf;
+	int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
+	u8 n_pci_type, sf_dl;
+
+	/* Strictly receive only frames with the configured MTU size
+	 * => clear separation of CAN2.0 / CAN FD transport channels
+	 */
+	if (skb->len != so->ll.mtu)
+		return;
+
+	cf = (struct canfd_frame *)skb->data;
+
+	/* if enabled: check reception of my configured extended address */
+	if (ae && cf->data[0] != so->opt.rx_ext_address)
+		return;
+
+	n_pci_type = cf->data[ae] & 0xF0;
+
+	if (so->opt.flags & CAN_ISOTP_HALF_DUPLEX) {
+		/* check rx/tx path half duplex expectations */
+		if ((so->tx.state != ISOTP_IDLE && n_pci_type != N_PCI_FC) ||
+		    (so->rx.state != ISOTP_IDLE && n_pci_type == N_PCI_FC))
+			return;
+	}
+
+	switch (n_pci_type) {
+	case N_PCI_FC:
+		/* tx path: flow control frame containing the FC parameters */
+		isotp_rcv_fc(so, cf, ae);
+		break;
+
+	case N_PCI_SF:
+		/* rx path: single frame
+		 *
+		 * As we do not have a rx.ll_dl configuration, we can only test
+		 * if the CAN frames payload length matches the LL_DL == 8
+		 * requirements - no matter if it's CAN 2.0 or CAN FD
+		 */
+
+		/* get the SF_DL from the N_PCI byte */
+		sf_dl = cf->data[ae] & 0x0F;
+
+		if (cf->len <= CAN_MAX_DLEN) {
+			isotp_rcv_sf(sk, cf, SF_PCI_SZ4 + ae, skb, sf_dl);
+		} else {
+			if (skb->len == CANFD_MTU) {
+				/* We have a CAN FD frame and CAN_DL is greater than 8:
+				 * Only frames with the SF_DL == 0 ESC value are valid.
+				 *
+				 * If so take care of the increased SF PCI size
+				 * (SF_PCI_SZ8) to point to the message content behind
+				 * the extended SF PCI info and get the real SF_DL
+				 * length value from the formerly first data byte.
+				 */
+				if (sf_dl == 0)
+					isotp_rcv_sf(sk, cf, SF_PCI_SZ8 + ae, skb,
+						     cf->data[SF_PCI_SZ4 + ae]);
+			}
+		}
+		break;
+
+	case N_PCI_FF:
+		/* rx path: first frame */
+		isotp_rcv_ff(sk, cf, ae);
+		break;
+
+	case N_PCI_CF:
+		/* rx path: consecutive frame */
+		isotp_rcv_cf(sk, cf, ae, skb);
+		break;
+	}
+}
+
+static void isotp_fill_dataframe(struct canfd_frame *cf, struct isotp_sock *so,
+				 int ae, int off)
+{
+	int pcilen = N_PCI_SZ + ae + off;
+	int space = so->tx.ll_dl - pcilen;
+	int num = min_t(int, so->tx.len - so->tx.idx, space);
+	int i;
+
+	cf->can_id = so->txid;
+	cf->len = num + pcilen;
+
+	if (num < space) {
+		if (so->opt.flags & CAN_ISOTP_TX_PADDING) {
+			/* user requested padding */
+			cf->len = padlen(cf->len);
+			memset(cf->data, so->opt.txpad_content, cf->len);
+		} else if (cf->len > CAN_MAX_DLEN) {
+			/* mandatory padding for CAN FD frames */
+			cf->len = padlen(cf->len);
+			memset(cf->data, CAN_ISOTP_DEFAULT_PAD_CONTENT,
+			       cf->len);
+		}
+	}
+
+	for (i = 0; i < num; i++)
+		cf->data[pcilen + i] = so->tx.buf[so->tx.idx++];
+
+	if (ae)
+		cf->data[0] = so->opt.ext_address;
+}
+
+static void isotp_create_fframe(struct canfd_frame *cf, struct isotp_sock *so,
+				int ae)
+{
+	int i;
+	int ff_pci_sz;
+
+	cf->can_id = so->txid;
+	cf->len = so->tx.ll_dl;
+	if (ae)
+		cf->data[0] = so->opt.ext_address;
+
+	/* create N_PCI bytes with 12/32 bit FF_DL data length */
+	if (so->tx.len > 4095) {
+		/* use 32 bit FF_DL notation */
+		cf->data[ae] = N_PCI_FF;
+		cf->data[ae + 1] = 0;
+		cf->data[ae + 2] = (u8)(so->tx.len >> 24) & 0xFFU;
+		cf->data[ae + 3] = (u8)(so->tx.len >> 16) & 0xFFU;
+		cf->data[ae + 4] = (u8)(so->tx.len >> 8) & 0xFFU;
+		cf->data[ae + 5] = (u8)so->tx.len & 0xFFU;
+		ff_pci_sz = FF_PCI_SZ32;
+	} else {
+		/* use 12 bit FF_DL notation */
+		cf->data[ae] = (u8)(so->tx.len >> 8) | N_PCI_FF;
+		cf->data[ae + 1] = (u8)so->tx.len & 0xFFU;
+		ff_pci_sz = FF_PCI_SZ12;
+	}
+
+	/* add first data bytes depending on ae */
+	for (i = ae + ff_pci_sz; i < so->tx.ll_dl; i++)
+		cf->data[i] = so->tx.buf[so->tx.idx++];
+
+	so->tx.sn = 1;
+	so->tx.state = ISOTP_WAIT_FIRST_FC;
+}
+
+static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
+{
+	struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
+					     txtimer);
+	struct sock *sk = &so->sk;
+	struct sk_buff *skb;
+	struct net_device *dev;
+	struct canfd_frame *cf;
+	enum hrtimer_restart restart = HRTIMER_NORESTART;
+	int can_send_ret;
+	int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
+
+	switch (so->tx.state) {
+	case ISOTP_WAIT_FC:
+	case ISOTP_WAIT_FIRST_FC:
+
+		/* we did not get any flow control frame in time */
+
+		/* report 'communication error on send' */
+		sk->sk_err = ECOMM;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+
+		/* reset tx state */
+		so->tx.state = ISOTP_IDLE;
+		wake_up_interruptible(&so->wait);
+		break;
+
+	case ISOTP_SENDING:
+
+		/* push out the next segmented pdu */
+		dev = dev_get_by_index(sock_net(sk), so->ifindex);
+		if (!dev)
+			break;
+
+isotp_tx_burst:
+		skb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv),
+				gfp_any());
+		if (!skb) {
+			dev_put(dev);
+			break;
+		}
+
+		can_skb_reserve(skb);
+		can_skb_prv(skb)->ifindex = dev->ifindex;
+		can_skb_prv(skb)->skbcnt = 0;
+
+		cf = (struct canfd_frame *)skb->data;
+		skb_put(skb, so->ll.mtu);
+
+		/* create consecutive frame */
+		isotp_fill_dataframe(cf, so, ae, 0);
+
+		/* place consecutive frame N_PCI in appropriate index */
+		cf->data[ae] = N_PCI_CF | so->tx.sn++;
+		so->tx.sn %= 16;
+		so->tx.bs++;
+
+		if (so->ll.mtu == CANFD_MTU)
+			cf->flags = so->ll.tx_flags;
+
+		skb->dev = dev;
+		can_skb_set_owner(skb, sk);
+
+		can_send_ret = can_send(skb, 1);
+		if (can_send_ret)
+			printk_once(KERN_NOTICE "can-isotp: %s: can_send_ret %d\n",
+				    __func__, can_send_ret);
+
+		if (so->tx.idx >= so->tx.len) {
+			/* we are done */
+			so->tx.state = ISOTP_IDLE;
+			dev_put(dev);
+			wake_up_interruptible(&so->wait);
+			break;
+		}
+
+		if (so->txfc.bs && so->tx.bs >= so->txfc.bs) {
+			/* stop and wait for FC */
+			so->tx.state = ISOTP_WAIT_FC;
+			dev_put(dev);
+			hrtimer_set_expires(&so->txtimer,
+					    ktime_add(ktime_get(),
+						      ktime_set(1, 0)));
+			restart = HRTIMER_RESTART;
+			break;
+		}
+
+		/* no gap between data frames needed => use burst mode */
+		if (!so->tx_gap)
+			goto isotp_tx_burst;
+
+		/* start timer to send next data frame with correct delay */
+		dev_put(dev);
+		hrtimer_set_expires(&so->txtimer,
+				    ktime_add(ktime_get(), so->tx_gap));
+		restart = HRTIMER_RESTART;
+		break;
+
+	default:
+		WARN_ON_ONCE(1);
+	}
+
+	return restart;
+}
+
+static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
+{
+	struct sock *sk = sock->sk;
+	struct isotp_sock *so = isotp_sk(sk);
+	struct sk_buff *skb;
+	struct net_device *dev;
+	struct canfd_frame *cf;
+	int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
+	int wait_tx_done = (so->opt.flags & CAN_ISOTP_WAIT_TX_DONE) ? 1 : 0;
+	int off;
+	int err;
+
+	if (!so->bound)
+		return -EADDRNOTAVAIL;
+
+	/* we do not support multiple buffers - for now */
+	if (so->tx.state != ISOTP_IDLE || wq_has_sleeper(&so->wait)) {
+		if (msg->msg_flags & MSG_DONTWAIT)
+			return -EAGAIN;
+
+		/* wait for complete transmission of current pdu */
+		wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
+	}
+
+	if (!size || size > MAX_MSG_LENGTH)
+		return -EINVAL;
+
+	err = memcpy_from_msg(so->tx.buf, msg, size);
+	if (err < 0)
+		return err;
+
+	dev = dev_get_by_index(sock_net(sk), so->ifindex);
+	if (!dev)
+		return -ENXIO;
+
+	skb = sock_alloc_send_skb(sk, so->ll.mtu + sizeof(struct can_skb_priv),
+				  msg->msg_flags & MSG_DONTWAIT, &err);
+	if (!skb) {
+		dev_put(dev);
+		return err;
+	}
+
+	can_skb_reserve(skb);
+	can_skb_prv(skb)->ifindex = dev->ifindex;
+	can_skb_prv(skb)->skbcnt = 0;
+
+	so->tx.state = ISOTP_SENDING;
+	so->tx.len = size;
+	so->tx.idx = 0;
+
+	cf = (struct canfd_frame *)skb->data;
+	skb_put(skb, so->ll.mtu);
+
+	/* take care of a potential SF_DL ESC offset for TX_DL > 8 */
+	off = (so->tx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
+
+	/* check for single frame transmission depending on TX_DL */
+	if (size <= so->tx.ll_dl - SF_PCI_SZ4 - ae - off) {
+		/* The message size generally fits into a SingleFrame - good.
+		 *
+		 * SF_DL ESC offset optimization:
+		 *
+		 * When TX_DL is greater 8 but the message would still fit
+		 * into a 8 byte CAN frame, we can omit the offset.
+		 * This prevents a protocol caused length extension from
+		 * CAN_DL = 8 to CAN_DL = 12 due to the SF_SL ESC handling.
+		 */
+		if (size <= CAN_MAX_DLEN - SF_PCI_SZ4 - ae)
+			off = 0;
+
+		isotp_fill_dataframe(cf, so, ae, off);
+
+		/* place single frame N_PCI w/o length in appropriate index */
+		cf->data[ae] = N_PCI_SF;
+
+		/* place SF_DL size value depending on the SF_DL ESC offset */
+		if (off)
+			cf->data[SF_PCI_SZ4 + ae] = size;
+		else
+			cf->data[ae] |= size;
+
+		so->tx.state = ISOTP_IDLE;
+		wake_up_interruptible(&so->wait);
+
+		/* don't enable wait queue for a single frame transmission */
+		wait_tx_done = 0;
+	} else {
+		/* send first frame and wait for FC */
+
+		isotp_create_fframe(cf, so, ae);
+
+		/* start timeout for FC */
+		hrtimer_start(&so->txtimer, ktime_set(1, 0), HRTIMER_MODE_REL_SOFT);
+	}
+
+	/* send the first or only CAN frame */
+	if (so->ll.mtu == CANFD_MTU)
+		cf->flags = so->ll.tx_flags;
+
+	skb->dev = dev;
+	skb->sk = sk;
+	err = can_send(skb, 1);
+	dev_put(dev);
+	if (err) {
+		printk_once(KERN_NOTICE "can-isotp: %s: can_send_ret %d\n",
+			    __func__, err);
+		return err;
+	}
+
+	if (wait_tx_done) {
+		/* wait for complete transmission of current pdu */
+		wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
+	}
+
+	return size;
+}
+
+static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
+			 int flags)
+{
+	struct sock *sk = sock->sk;
+	struct sk_buff *skb;
+	int err = 0;
+	int noblock;
+
+	noblock = flags & MSG_DONTWAIT;
+	flags &= ~MSG_DONTWAIT;
+
+	skb = skb_recv_datagram(sk, flags, noblock, &err);
+	if (!skb)
+		return err;
+
+	if (size < skb->len)
+		msg->msg_flags |= MSG_TRUNC;
+	else
+		size = skb->len;
+
+	err = memcpy_to_msg(msg, skb->data, size);
+	if (err < 0) {
+		skb_free_datagram(sk, skb);
+		return err;
+	}
+
+	sock_recv_timestamp(msg, sk, skb);
+
+	if (msg->msg_name) {
+		msg->msg_namelen = sizeof(struct sockaddr_can);
+		memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
+	}
+
+	skb_free_datagram(sk, skb);
+
+	return size;
+}
+
+static int isotp_release(struct socket *sock)
+{
+	struct sock *sk = sock->sk;
+	struct isotp_sock *so;
+	struct net *net;
+
+	if (!sk)
+		return 0;
+
+	so = isotp_sk(sk);
+	net = sock_net(sk);
+
+	/* wait for complete transmission of current pdu */
+	wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
+
+	unregister_netdevice_notifier(&so->notifier);
+
+	lock_sock(sk);
+
+	hrtimer_cancel(&so->txtimer);
+	hrtimer_cancel(&so->rxtimer);
+
+	/* remove current filters & unregister */
+	if (so->bound) {
+		if (so->ifindex) {
+			struct net_device *dev;
+
+			dev = dev_get_by_index(net, so->ifindex);
+			if (dev) {
+				can_rx_unregister(net, dev, so->rxid,
+						  SINGLE_MASK(so->rxid),
+						  isotp_rcv, sk);
+				dev_put(dev);
+			}
+		}
+	}
+
+	so->ifindex = 0;
+	so->bound = 0;
+
+	sock_orphan(sk);
+	sock->sk = NULL;
+
+	release_sock(sk);
+	sock_put(sk);
+
+	return 0;
+}
+
+static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
+{
+	struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
+	struct sock *sk = sock->sk;
+	struct isotp_sock *so = isotp_sk(sk);
+	struct net *net = sock_net(sk);
+	int ifindex;
+	struct net_device *dev;
+	int err = 0;
+	int notify_enetdown = 0;
+
+	if (len < CAN_REQUIRED_SIZE(struct sockaddr_can, can_addr.tp))
+		return -EINVAL;
+
+	if (addr->can_addr.tp.rx_id == addr->can_addr.tp.tx_id)
+		return -EADDRNOTAVAIL;
+
+	if ((addr->can_addr.tp.rx_id | addr->can_addr.tp.tx_id) &
+	    (CAN_ERR_FLAG | CAN_RTR_FLAG))
+		return -EADDRNOTAVAIL;
+
+	if (!addr->can_ifindex)
+		return -ENODEV;
+
+	lock_sock(sk);
+
+	if (so->bound && addr->can_ifindex == so->ifindex &&
+	    addr->can_addr.tp.rx_id == so->rxid &&
+	    addr->can_addr.tp.tx_id == so->txid)
+		goto out;
+
+	dev = dev_get_by_index(net, addr->can_ifindex);
+	if (!dev) {
+		err = -ENODEV;
+		goto out;
+	}
+	if (dev->type != ARPHRD_CAN) {
+		dev_put(dev);
+		err = -ENODEV;
+		goto out;
+	}
+	if (dev->mtu < so->ll.mtu) {
+		dev_put(dev);
+		err = -EINVAL;
+		goto out;
+	}
+	if (!(dev->flags & IFF_UP))
+		notify_enetdown = 1;
+
+	ifindex = dev->ifindex;
+
+	can_rx_register(net, dev, addr->can_addr.tp.rx_id,
+			SINGLE_MASK(addr->can_addr.tp.rx_id), isotp_rcv, sk,
+			"isotp", sk);
+
+	dev_put(dev);
+
+	if (so->bound) {
+		/* unregister old filter */
+		if (so->ifindex) {
+			dev = dev_get_by_index(net, so->ifindex);
+			if (dev) {
+				can_rx_unregister(net, dev, so->rxid,
+						  SINGLE_MASK(so->rxid),
+						  isotp_rcv, sk);
+				dev_put(dev);
+			}
+		}
+	}
+
+	/* switch to new settings */
+	so->ifindex = ifindex;
+	so->rxid = addr->can_addr.tp.rx_id;
+	so->txid = addr->can_addr.tp.tx_id;
+	so->bound = 1;
+
+out:
+	release_sock(sk);
+
+	if (notify_enetdown) {
+		sk->sk_err = ENETDOWN;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+	}
+
+	return err;
+}
+
+static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)
+{
+	struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
+	struct sock *sk = sock->sk;
+	struct isotp_sock *so = isotp_sk(sk);
+
+	if (peer)
+		return -EOPNOTSUPP;
+
+	addr->can_family = AF_CAN;
+	addr->can_ifindex = so->ifindex;
+	addr->can_addr.tp.rx_id = so->rxid;
+	addr->can_addr.tp.tx_id = so->txid;
+
+	return sizeof(*addr);
+}
+
+static int isotp_setsockopt(struct socket *sock, int level, int optname,
+			    sockptr_t optval, unsigned int optlen)
+{
+	struct sock *sk = sock->sk;
+	struct isotp_sock *so = isotp_sk(sk);
+	int ret = 0;
+
+	if (level != SOL_CAN_ISOTP)
+		return -EINVAL;
+
+	switch (optname) {
+	case CAN_ISOTP_OPTS:
+		if (optlen != sizeof(struct can_isotp_options))
+			return -EINVAL;
+
+		if (copy_from_sockptr(&so->opt, optval, optlen))
+			return -EFAULT;
+
+		/* no separate rx_ext_address is given => use ext_address */
+		if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR))
+			so->opt.rx_ext_address = so->opt.ext_address;
+		break;
+
+	case CAN_ISOTP_RECV_FC:
+		if (optlen != sizeof(struct can_isotp_fc_options))
+			return -EINVAL;
+
+		if (copy_from_sockptr(&so->rxfc, optval, optlen))
+			return -EFAULT;
+		break;
+
+	case CAN_ISOTP_TX_STMIN:
+		if (optlen != sizeof(u32))
+			return -EINVAL;
+
+		if (copy_from_sockptr(&so->force_tx_stmin, optval, optlen))
+			return -EFAULT;
+		break;
+
+	case CAN_ISOTP_RX_STMIN:
+		if (optlen != sizeof(u32))
+			return -EINVAL;
+
+		if (copy_from_sockptr(&so->force_rx_stmin, optval, optlen))
+			return -EFAULT;
+		break;
+
+	case CAN_ISOTP_LL_OPTS:
+		if (optlen == sizeof(struct can_isotp_ll_options)) {
+			struct can_isotp_ll_options ll;
+
+			if (copy_from_sockptr(&ll, optval, optlen))
+				return -EFAULT;
+
+			/* check for correct ISO 11898-1 DLC data length */
+			if (ll.tx_dl != padlen(ll.tx_dl))
+				return -EINVAL;
+
+			if (ll.mtu != CAN_MTU && ll.mtu != CANFD_MTU)
+				return -EINVAL;
+
+			if (ll.mtu == CAN_MTU && ll.tx_dl > CAN_MAX_DLEN)
+				return -EINVAL;
+
+			memcpy(&so->ll, &ll, sizeof(ll));
+
+			/* set ll_dl for tx path to similar place as for rx */
+			so->tx.ll_dl = ll.tx_dl;
+		} else {
+			return -EINVAL;
+		}
+		break;
+
+	default:
+		ret = -ENOPROTOOPT;
+	}
+
+	return ret;
+}
+
+static int isotp_getsockopt(struct socket *sock, int level, int optname,
+			    char __user *optval, int __user *optlen)
+{
+	struct sock *sk = sock->sk;
+	struct isotp_sock *so = isotp_sk(sk);
+	int len;
+	void *val;
+
+	if (level != SOL_CAN_ISOTP)
+		return -EINVAL;
+	if (get_user(len, optlen))
+		return -EFAULT;
+	if (len < 0)
+		return -EINVAL;
+
+	switch (optname) {
+	case CAN_ISOTP_OPTS:
+		len = min_t(int, len, sizeof(struct can_isotp_options));
+		val = &so->opt;
+		break;
+
+	case CAN_ISOTP_RECV_FC:
+		len = min_t(int, len, sizeof(struct can_isotp_fc_options));
+		val = &so->rxfc;
+		break;
+
+	case CAN_ISOTP_TX_STMIN:
+		len = min_t(int, len, sizeof(u32));
+		val = &so->force_tx_stmin;
+		break;
+
+	case CAN_ISOTP_RX_STMIN:
+		len = min_t(int, len, sizeof(u32));
+		val = &so->force_rx_stmin;
+		break;
+
+	case CAN_ISOTP_LL_OPTS:
+		len = min_t(int, len, sizeof(struct can_isotp_ll_options));
+		val = &so->ll;
+		break;
+
+	default:
+		return -ENOPROTOOPT;
+	}
+
+	if (put_user(len, optlen))
+		return -EFAULT;
+	if (copy_to_user(optval, val, len))
+		return -EFAULT;
+	return 0;
+}
+
+static int isotp_notifier(struct notifier_block *nb, unsigned long msg,
+			  void *ptr)
+{
+	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+	struct isotp_sock *so = container_of(nb, struct isotp_sock, notifier);
+	struct sock *sk = &so->sk;
+
+	if (!net_eq(dev_net(dev), sock_net(sk)))
+		return NOTIFY_DONE;
+
+	if (dev->type != ARPHRD_CAN)
+		return NOTIFY_DONE;
+
+	if (so->ifindex != dev->ifindex)
+		return NOTIFY_DONE;
+
+	switch (msg) {
+	case NETDEV_UNREGISTER:
+		lock_sock(sk);
+		/* remove current filters & unregister */
+		if (so->bound)
+			can_rx_unregister(dev_net(dev), dev, so->rxid,
+					  SINGLE_MASK(so->rxid),
+					  isotp_rcv, sk);
+
+		so->ifindex = 0;
+		so->bound  = 0;
+		release_sock(sk);
+
+		sk->sk_err = ENODEV;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+		break;
+
+	case NETDEV_DOWN:
+		sk->sk_err = ENETDOWN;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_error_report(sk);
+		break;
+	}
+
+	return NOTIFY_DONE;
+}
+
+static int isotp_init(struct sock *sk)
+{
+	struct isotp_sock *so = isotp_sk(sk);
+
+	so->ifindex = 0;
+	so->bound = 0;
+
+	so->opt.flags = CAN_ISOTP_DEFAULT_FLAGS;
+	so->opt.ext_address = CAN_ISOTP_DEFAULT_EXT_ADDRESS;
+	so->opt.rx_ext_address = CAN_ISOTP_DEFAULT_EXT_ADDRESS;
+	so->opt.rxpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT;
+	so->opt.txpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT;
+	so->opt.frame_txtime = CAN_ISOTP_DEFAULT_FRAME_TXTIME;
+	so->rxfc.bs = CAN_ISOTP_DEFAULT_RECV_BS;
+	so->rxfc.stmin = CAN_ISOTP_DEFAULT_RECV_STMIN;
+	so->rxfc.wftmax = CAN_ISOTP_DEFAULT_RECV_WFTMAX;
+	so->ll.mtu = CAN_ISOTP_DEFAULT_LL_MTU;
+	so->ll.tx_dl = CAN_ISOTP_DEFAULT_LL_TX_DL;
+	so->ll.tx_flags = CAN_ISOTP_DEFAULT_LL_TX_FLAGS;
+
+	/* set ll_dl for tx path to similar place as for rx */
+	so->tx.ll_dl = so->ll.tx_dl;
+
+	so->rx.state = ISOTP_IDLE;
+	so->tx.state = ISOTP_IDLE;
+
+	hrtimer_init(&so->rxtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
+	so->rxtimer.function = isotp_rx_timer_handler;
+	hrtimer_init(&so->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
+	so->txtimer.function = isotp_tx_timer_handler;
+
+	init_waitqueue_head(&so->wait);
+
+	so->notifier.notifier_call = isotp_notifier;
+	register_netdevice_notifier(&so->notifier);
+
+	return 0;
+}
+
+static int isotp_sock_no_ioctlcmd(struct socket *sock, unsigned int cmd,
+				  unsigned long arg)
+{
+	/* no ioctls for socket layer -> hand it down to NIC layer */
+	return -ENOIOCTLCMD;
+}
+
+static const struct proto_ops isotp_ops = {
+	.family = PF_CAN,
+	.release = isotp_release,
+	.bind = isotp_bind,
+	.connect = sock_no_connect,
+	.socketpair = sock_no_socketpair,
+	.accept = sock_no_accept,
+	.getname = isotp_getname,
+	.poll = datagram_poll,
+	.ioctl = isotp_sock_no_ioctlcmd,
+	.gettstamp = sock_gettstamp,
+	.listen = sock_no_listen,
+	.shutdown = sock_no_shutdown,
+	.setsockopt = isotp_setsockopt,
+	.getsockopt = isotp_getsockopt,
+	.sendmsg = isotp_sendmsg,
+	.recvmsg = isotp_recvmsg,
+	.mmap = sock_no_mmap,
+	.sendpage = sock_no_sendpage,
+};
+
+static struct proto isotp_proto __read_mostly = {
+	.name = "CAN_ISOTP",
+	.owner = THIS_MODULE,
+	.obj_size = sizeof(struct isotp_sock),
+	.init = isotp_init,
+};
+
+static const struct can_proto isotp_can_proto = {
+	.type = SOCK_DGRAM,
+	.protocol = CAN_ISOTP,
+	.ops = &isotp_ops,
+	.prot = &isotp_proto,
+};
+
+static __init int isotp_module_init(void)
+{
+	int err;
+
+	pr_info("can: isotp protocol (rev " CAN_ISOTP_VERSION ")\n");
+
+	err = can_proto_register(&isotp_can_proto);
+	if (err < 0)
+		pr_err("can: registration of isotp protocol failed\n");
+
+	return err;
+}
+
+static __exit void isotp_module_exit(void)
+{
+	can_proto_unregister(&isotp_can_proto);
+}
+
+module_init(isotp_module_init);
+module_exit(isotp_module_exit);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 09/17] dt-bindings: can: rcar_can: Add r8a7742 support
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (7 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 10/17] dt-bindings: can: rcar_canfd: Document r8a774e1 support Marc Kleine-Budde
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Lad Prabhakar, Chris Paterson,
	Geert Uytterhoeven, Rob Herring, Marc Kleine-Budde

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Document RZ/G1H (r8a7742) SoC specific bindings. The R8A7742 CAN module
is identical to R-Car Gen2 family.

No driver change is needed due to the fallback compatible value
"renesas,rcar-gen2-can".

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Chris Paterson <Chris.Paterson2@renesas.com>
Link: https://lore.kernel.org/r/20200816190732.6905-3-prabhakar.mahadev-lad.rj@bp.renesas.com
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/rcar_can.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_can.txt b/Documentation/devicetree/bindings/net/can/rcar_can.txt
index 85c6551b602a..2099ce809ae7 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_can.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_can.txt
@@ -2,7 +2,8 @@ Renesas R-Car CAN controller Device Tree Bindings
 -------------------------------------------------
 
 Required properties:
-- compatible: "renesas,can-r8a7743" if CAN controller is a part of R8A7743 SoC.
+- compatible: "renesas,can-r8a7742" if CAN controller is a part of R8A7742 SoC.
+	      "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-r8a77470" if CAN controller is a part of R8A77470 SoC.
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 10/17] dt-bindings: can: rcar_canfd: Document r8a774e1 support
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (8 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 09/17] dt-bindings: can: rcar_can: Add r8a7742 support Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 11/17] dt-bindings: can: rcar_can: " Marc Kleine-Budde
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Lad Prabhakar, Marian-Cristian Rotariu,
	Geert Uytterhoeven, Rob Herring, Marc Kleine-Budde

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Document the support for rcar_canfd on R8A774E1 SoC devices.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Marian-Cristian Rotariu <marian-cristian.rotariu.rb@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20201005081319.29322-2-prabhakar.mahadev-lad.rj@bp.renesas.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/rcar_canfd.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
index 13a4e34c0c73..22cf2a889b2c 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,r8a774a1-canfd" for R8A774A1 (RZ/G2M) compatible controller.
   - "renesas,r8a774b1-canfd" for R8A774B1 (RZ/G2N) compatible controller.
   - "renesas,r8a774c0-canfd" for R8A774C0 (RZ/G2E) compatible controller.
+  - "renesas,r8a774e1-canfd" for R8A774E1 (RZ/G2H) compatible controller.
   - "renesas,r8a7795-canfd" for R8A7795 (R-Car H3) compatible controller.
   - "renesas,r8a7796-canfd" for R8A7796 (R-Car M3-W) compatible controller.
   - "renesas,r8a77965-canfd" for R8A77965 (R-Car M3-N) compatible controller.
@@ -32,8 +33,8 @@ The name of the child nodes are "channel0" and "channel1" respectively. Each
 child node supports the "status" property only, which is used to
 enable/disable the respective channel.
 
-Required properties for R8A774A1, R8A774B1, R8A774C0, R8A7795, R8A7796,
-R8A77965, R8A77990, and R8A77995:
+Required properties for R8A774A1, R8A774B1, R8A774C0, R8A774E1, R8A7795,
+R8A7796, R8A77965, R8A77990, and R8A77995:
 In the denoted SoCs, canfd clock 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
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 11/17] dt-bindings: can: rcar_can: Document r8a774e1 support
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (9 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 10/17] dt-bindings: can: rcar_canfd: Document r8a774e1 support Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 12/17] dt-bindings: can: flexcan: list supported processors Marc Kleine-Budde
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Lad Prabhakar, Marian-Cristian Rotariu,
	Geert Uytterhoeven, Rob Herring, Marc Kleine-Budde

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Document SoC specific bindings for RZ/G2H (R8A774E1) SoC.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Marian-Cristian Rotariu <marian-cristian.rotariu.rb@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20201005081319.29322-3-prabhakar.mahadev-lad.rj@bp.renesas.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/rcar_can.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/rcar_can.txt b/Documentation/devicetree/bindings/net/can/rcar_can.txt
index 2099ce809ae7..6a5956347816 100644
--- a/Documentation/devicetree/bindings/net/can/rcar_can.txt
+++ b/Documentation/devicetree/bindings/net/can/rcar_can.txt
@@ -10,6 +10,7 @@ Required properties:
 	      "renesas,can-r8a774a1" if CAN controller is a part of R8A774A1 SoC.
 	      "renesas,can-r8a774b1" if CAN controller is a part of R8A774B1 SoC.
 	      "renesas,can-r8a774c0" if CAN controller is a part of R8A774C0 SoC.
+	      "renesas,can-r8a774e1" if CAN controller is a part of R8A774E1 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.
@@ -38,8 +39,8 @@ Required properties:
 - pinctrl-0: pin control group to be used for this controller.
 - pinctrl-names: must be "default".
 
-Required properties for R8A774A1, R8A774B1, R8A774C0, R8A7795, R8A7796,
-R8A77965, R8A77990, and R8A77995:
+Required properties for R8A774A1, R8A774B1, R8A774C0, R8A774E1, R8A7795,
+R8A7796, R8A77965, R8A77990, and R8A77995:
 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
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 12/17] dt-bindings: can: flexcan: list supported processors
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (10 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 11/17] dt-bindings: can: rcar_can: " Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 13/17] dt-bindings: can: flexcan: remove ack_grp and ack_bit from fsl,stop-mode Marc Kleine-Budde
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Michael Walle, Marc Kleine-Budde

From: Michael Walle <michael@walle.cc>

The compatible is a pattern match. Explicitly list all possible values.
Also mention that the ls1028ar1 must be followed by lx2160ar1.

Signed-off-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20201001091131.30514-2-michael@walle.cc
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/fsl-flexcan.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
index 94c0f8bf4deb..c6152dc2d2d0 100644
--- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
+++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
@@ -4,6 +4,12 @@ Required properties:
 
 - compatible : Should be "fsl,<processor>-flexcan"
 
+  where <processor> is imx8qm, imx6q, imx28, imx53, imx35, imx25, p1010,
+  vf610, ls1021ar2, lx2160ar1, ls1028ar1.
+
+  The ls1028ar1 must be followed by lx2160ar1, e.g.
+   - "fsl,ls1028ar1-flexcan", "fsl,lx2160ar1-flexcan"
+
   An implementation should also claim any of the following compatibles
   that it is fully backwards compatible with:
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 13/17] dt-bindings: can: flexcan: remove ack_grp and ack_bit from fsl,stop-mode
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (11 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 12/17] dt-bindings: can: flexcan: list supported processors Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from driver Marc Kleine-Budde
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Marc Kleine-Budde, devicetree,
	Joakim Zhang, Rob Herring

Since commit:

    048e3a34a2e7 can: flexcan: poll MCR_LPM_ACK instead of GPR ACK for stop mode acknowledgment

the driver polls the IP core's internal bit MCR[LPM_ACK] as stop mode
acknowledge and not the acknowledgment on chip level.

This means the 4th and 5th value of the property "fsl,stop-mode" isn't used
anymore. It will be removed from the driver in the next patch, so remove it
from the binding documentation.

Link: http://lore.kernel.org/r/20201006203748.1750156-14-mkl@pengutronix.de
Fixes: 048e3a34a2e7 ("can: flexcan: poll MCR_LPM_ACK instead of GPR ACK for stop mode acknowledgment")
Cc: devicetree <devicetree@vger.kernel.org>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 Documentation/devicetree/bindings/net/can/fsl-flexcan.txt | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
index c6152dc2d2d0..e10b6eb955e1 100644
--- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
+++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
@@ -31,12 +31,10 @@ Optional properties:
               endian.
 
 - fsl,stop-mode: register bits of stop mode control, the format is
-		 <&gpr req_gpr req_bit ack_gpr ack_bit>.
+		 <&gpr req_gpr req_bit>.
 		 gpr is the phandle to general purpose register node.
 		 req_gpr is the gpr register offset of CAN stop request.
 		 req_bit is the bit offset of CAN stop request.
-		 ack_gpr is the gpr register offset of CAN stop acknowledge.
-		 ack_bit is the bit offset of CAN stop acknowledge.
 
 - fsl,clk-source: Select the clock source to the CAN Protocol Engine (PE).
 		  It's SoC Implementation dependent. Refer to RM for detailed
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from driver
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (12 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 13/17] dt-bindings: can: flexcan: remove ack_grp and ack_bit from fsl,stop-mode Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-14  8:53   ` Joakim Zhang
  2020-10-07 21:31 ` [PATCH 15/17] can: xilinx_can: Limit CANFD brp to 2 Marc Kleine-Budde
                   ` (3 subsequent siblings)
  17 siblings, 1 reply; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Marc Kleine-Budde, Joakim Zhang

Since commit:

    048e3a34a2e7 can: flexcan: poll MCR_LPM_ACK instead of GPR ACK for stop mode acknowledgment

the driver polls the IP core's internal bit MCR[LPM_ACK] as stop mode
acknowledge and not the acknowledgment on chip level.

This means the 4th and 5th value of the property "fsl,stop-mode" isn't used
anymore. This patch removes the used "ack_gpr" and "ack_bit" from the driver.

Link: http://lore.kernel.org/r/20201006203748.1750156-15-mkl@pengutronix.de
Fixes: 048e3a34a2e7 ("can: flexcan: poll MCR_LPM_ACK instead of GPR ACK for stop mode acknowledgment")
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index fbdd9a8c9374..4d594e977497 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -333,8 +333,6 @@ struct flexcan_stop_mode {
 	struct regmap *gpr;
 	u8 req_gpr;
 	u8 req_bit;
-	u8 ack_gpr;
-	u8 ack_bit;
 };
 
 struct flexcan_priv {
@@ -1847,14 +1845,14 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
 	struct device_node *gpr_np;
 	struct flexcan_priv *priv;
 	phandle phandle;
-	u32 out_val[5];
+	u32 out_val[3];
 	int ret;
 
 	if (!np)
 		return -EINVAL;
 
 	/* stop mode property format is:
-	 * <&gpr req_gpr req_bit ack_gpr ack_bit>.
+	 * <&gpr req_gpr>.
 	 */
 	ret = of_property_read_u32_array(np, "fsl,stop-mode", out_val,
 					 ARRAY_SIZE(out_val));
@@ -1880,13 +1878,10 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
 
 	priv->stm.req_gpr = out_val[1];
 	priv->stm.req_bit = out_val[2];
-	priv->stm.ack_gpr = out_val[3];
-	priv->stm.ack_bit = out_val[4];
 
 	dev_dbg(&pdev->dev,
-		"gpr %s req_gpr=0x02%x req_bit=%u ack_gpr=0x02%x ack_bit=%u\n",
-		gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit,
-		priv->stm.ack_gpr, priv->stm.ack_bit);
+		"gpr %s req_gpr=0x02%x req_bit=%u\n",
+		gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit);
 
 	device_set_wakeup_capable(&pdev->dev, true);
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 15/17] can: xilinx_can: Limit CANFD brp to 2
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (13 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from driver Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 16/17] can: xilinx_can: Check return value of set_reset_mode Marc Kleine-Budde
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Srinivas Neeli, Michal Simek,
	Marc Kleine-Budde

From: Srinivas Neeli <srinivas.neeli@xilinx.com>

Bit enlarging is observed for CANFD2.0 when brp is 1,
So change brp_min value to 2.

Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Link: https://lore.kernel.org/r/bca871d7f3ca9c653d50e63c5b60028f2bdf3fb0.1600073396.git.michal.simek@xilinx.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/xilinx_can.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 7ae268468d2c..d3c41e6c275d 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -259,7 +259,7 @@ static const struct can_bittiming_const xcan_bittiming_const_canfd2 = {
 	.tseg2_min = 1,
 	.tseg2_max = 128,
 	.sjw_max = 128,
-	.brp_min = 1,
+	.brp_min = 2,
 	.brp_max = 256,
 	.brp_inc = 1,
 };
@@ -272,7 +272,7 @@ static struct can_bittiming_const xcan_data_bittiming_const_canfd2 = {
 	.tseg2_min = 1,
 	.tseg2_max = 16,
 	.sjw_max = 16,
-	.brp_min = 1,
+	.brp_min = 2,
 	.brp_max = 256,
 	.brp_inc = 1,
 };
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 16/17] can: xilinx_can: Check return value of set_reset_mode
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (14 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 15/17] can: xilinx_can: Limit CANFD brp to 2 Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-07 21:31 ` [PATCH 17/17] can: xilinx_can: Fix incorrect variable and initialize with a default value Marc Kleine-Budde
  2020-10-10  1:09 ` pull-request: can-next 2020-10-07 Jakub Kicinski
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Srinivas Neeli, Michal Simek,
	Marc Kleine-Budde

From: Srinivas Neeli <srinivas.neeli@xilinx.com>

Check return value of set_reset_mode() for error.

Addresses-Coverity: "check_return"
Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Link: https://lore.kernel.org/r/bac2c2b857986472a11db341b3f6f7a8905ad0dd.1600073396.git.michal.simek@xilinx.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/xilinx_can.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index d3c41e6c275d..9ea6ad73b07d 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -1369,9 +1369,13 @@ 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);
+	int ret;
 
 	/* Disable interrupts and leave the can in configuration mode */
-	set_reset_mode(ndev);
+	ret = set_reset_mode(ndev);
+	if (ret < 0)
+		netdev_dbg(ndev, "set_reset_mode() Failed\n");
+
 	priv->can.state = CAN_STATE_STOPPED;
 }
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 17/17] can: xilinx_can: Fix incorrect variable and initialize with a default value
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (15 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 16/17] can: xilinx_can: Check return value of set_reset_mode Marc Kleine-Budde
@ 2020-10-07 21:31 ` Marc Kleine-Budde
  2020-10-10  1:09 ` pull-request: can-next 2020-10-07 Jakub Kicinski
  17 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-07 21:31 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Srinivas Neeli, Michal Simek,
	Marc Kleine-Budde

From: Srinivas Neeli <srinivas.neeli@xilinx.com>

Some variables with incorrect type were passed to "of_property_read_u32"
API, "of_property_read_u32" API was expecting an "u32 *" but the formal
parameter that was passed was of type "int *". Fixed the issue by
changing the variable types from "int" to "u32" and initialized with a
default value. Fixed sparse warning.

Addresses-Coverity: "incompatible_param"
Addresses-Coverity: "UNINIT(Using uninitialized value)"
Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Link: https://lore.kernel.org/r/0651544d22f3c25893ca9d445b14823f0dfddfc8.1600073396.git.michal.simek@xilinx.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/xilinx_can.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 9ea6ad73b07d..6c4d00d2dbdc 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -1671,7 +1671,7 @@ static int xcan_probe(struct platform_device *pdev)
 	void __iomem *addr;
 	int ret;
 	int rx_max, tx_max;
-	int hw_tx_max, hw_rx_max;
+	u32 hw_tx_max = 0, hw_rx_max = 0;
 	const char *hw_tx_max_property;
 
 	/* Get the virtual base address for the device */
@@ -1724,7 +1724,7 @@ static int xcan_probe(struct platform_device *pdev)
 	 */
 	if (!(devtype->flags & XCAN_FLAG_TX_MAILBOXES) &&
 	    (devtype->flags & XCAN_FLAG_TXFEMP))
-		tx_max = min(hw_tx_max, 2);
+		tx_max = min(hw_tx_max, 2U);
 	else
 		tx_max = 1;
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol
  2020-10-07 21:31 ` [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol Marc Kleine-Budde
@ 2020-10-10  0:57   ` Jakub Kicinski
  2020-10-10 14:29     ` Oliver Hartkopp
  0 siblings, 1 reply; 27+ messages in thread
From: Jakub Kicinski @ 2020-10-10  0:57 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel, Oliver Hartkopp

On Wed,  7 Oct 2020 23:31:50 +0200 Marc Kleine-Budde wrote:
> From: Oliver Hartkopp <socketcan@hartkopp.net>
> 
> CAN Transport Protocols offer support for segmented Point-to-Point
> communication between CAN nodes via two defined CAN Identifiers.
> As CAN frames can only transport a small amount of data bytes
> (max. 8 bytes for 'classic' CAN and max. 64 bytes for CAN FD) this
> segmentation is needed to transport longer PDUs as needed e.g. for
> vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic.
> This protocol driver implements data transfers according to
> ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.

A few random things jump out here at a quick scan. Most of them are 
not important enough to have to be addressed, but please follow up on
the 'default y' thing ASAP.

> +/*
> + * Remark on CAN_ISOTP_DEFAULT_RECV_* values:
> + *
> + * We can strongly assume, that the Linux Kernel implementation of
> + * CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0.
> + * But as we like to be able to behave as a commonly available ECU,
> + * these default settings can be changed via sockopts.
> + * For that reason the STmin value is intentionally _not_ checked for
> + * consistency and copied directly into the flow control (FC) frame.
> + *

spurious empty comment line

> + */
> +
> +#endif /* !_UAPI_CAN_ISOTP_H */
> diff --git a/net/can/Kconfig b/net/can/Kconfig
> index 25436a715db3..021fe03a8ed6 100644
> --- a/net/can/Kconfig
> +++ b/net/can/Kconfig
> @@ -55,6 +55,19 @@ config CAN_GW
>  
>  source "net/can/j1939/Kconfig"
>  
> +config CAN_ISOTP
> +	tristate "ISO 15765-2:2016 CAN transport protocol"
> +	default y

default should not be y unless there is a very good reason.
I don't see such reason here. This is new functionality, users
can enable it if they need it.

> +	help
> +	  CAN Transport Protocols offer support for segmented Point-to-Point
> +	  communication between CAN nodes via two defined CAN Identifiers.
> +	  As CAN frames can only transport a small amount of data bytes
> +	  (max. 8 bytes for 'classic' CAN and max. 64 bytes for CAN FD) this
> +	  segmentation is needed to transport longer PDUs as needed e.g. for
> +	  vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic.
> +	  This protocol driver implements data transfers according to
> +	  ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.
> +
>  source "drivers/net/can/Kconfig"
>  
>  endif

> +#define CAN_ISOTP_VERSION "20200928"

We've been removing such version strings throughout the drivers.
Kernel version should be sufficient for in-tree modules.

> +static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
> +{
> +	struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
> +					     txtimer);
> +	struct sock *sk = &so->sk;
> +	struct sk_buff *skb;
> +	struct net_device *dev;
> +	struct canfd_frame *cf;
> +	enum hrtimer_restart restart = HRTIMER_NORESTART;
> +	int can_send_ret;
> +	int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
> +
> +	switch (so->tx.state) {
> +	case ISOTP_WAIT_FC:
> +	case ISOTP_WAIT_FIRST_FC:
> +
> +		/* we did not get any flow control frame in time */
> +
> +		/* report 'communication error on send' */
> +		sk->sk_err = ECOMM;
> +		if (!sock_flag(sk, SOCK_DEAD))
> +			sk->sk_error_report(sk);
> +
> +		/* reset tx state */
> +		so->tx.state = ISOTP_IDLE;
> +		wake_up_interruptible(&so->wait);
> +		break;
> +
> +	case ISOTP_SENDING:
> +
> +		/* push out the next segmented pdu */
> +		dev = dev_get_by_index(sock_net(sk), so->ifindex);
> +		if (!dev)
> +			break;
> +
> +isotp_tx_burst:
> +		skb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv),
> +				gfp_any());

This is always in a timer context, so no need for gfp_any(), right?

> +		if (!skb) {
> +			dev_put(dev);
> +			break;
> +		}
> +
> +		can_skb_reserve(skb);
> +		can_skb_prv(skb)->ifindex = dev->ifindex;
> +		can_skb_prv(skb)->skbcnt = 0;
> +
> +		cf = (struct canfd_frame *)skb->data;
> +		skb_put(skb, so->ll.mtu);
> +
> +		/* create consecutive frame */
> +		isotp_fill_dataframe(cf, so, ae, 0);
> +
> +		/* place consecutive frame N_PCI in appropriate index */
> +		cf->data[ae] = N_PCI_CF | so->tx.sn++;
> +		so->tx.sn %= 16;
> +		so->tx.bs++;
> +
> +		if (so->ll.mtu == CANFD_MTU)
> +			cf->flags = so->ll.tx_flags;
> +
> +		skb->dev = dev;
> +		can_skb_set_owner(skb, sk);
> +
> +		can_send_ret = can_send(skb, 1);
> +		if (can_send_ret)
> +			printk_once(KERN_NOTICE "can-isotp: %s: can_send_ret %d\n",
> +				    __func__, can_send_ret);

pr_notice_once()

> +
> +		if (so->tx.idx >= so->tx.len) {
> +			/* we are done */
> +			so->tx.state = ISOTP_IDLE;
> +			dev_put(dev);
> +			wake_up_interruptible(&so->wait);
> +			break;
> +		}
> +
> +		if (so->txfc.bs && so->tx.bs >= so->txfc.bs) {
> +			/* stop and wait for FC */
> +			so->tx.state = ISOTP_WAIT_FC;
> +			dev_put(dev);
> +			hrtimer_set_expires(&so->txtimer,
> +					    ktime_add(ktime_get(),
> +						      ktime_set(1, 0)));
> +			restart = HRTIMER_RESTART;
> +			break;
> +		}
> +
> +		/* no gap between data frames needed => use burst mode */
> +		if (!so->tx_gap)
> +			goto isotp_tx_burst;
> +
> +		/* start timer to send next data frame with correct delay */
> +		dev_put(dev);
> +		hrtimer_set_expires(&so->txtimer,
> +				    ktime_add(ktime_get(), so->tx_gap));
> +		restart = HRTIMER_RESTART;
> +		break;
> +
> +	default:
> +		WARN_ON_ONCE(1);
> +	}
> +
> +	return restart;
> +}

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: pull-request: can-next 2020-10-07
  2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
                   ` (16 preceding siblings ...)
  2020-10-07 21:31 ` [PATCH 17/17] can: xilinx_can: Fix incorrect variable and initialize with a default value Marc Kleine-Budde
@ 2020-10-10  1:09 ` Jakub Kicinski
  17 siblings, 0 replies; 27+ messages in thread
From: Jakub Kicinski @ 2020-10-10  1:09 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel

On Wed,  7 Oct 2020 23:31:42 +0200 Marc Kleine-Budde wrote:
> The first 3 patches are by me and fix several warnings found when compiling the 
> kernel with W=1.
> 
> Lukas Bulwahn's patch adjusts the MAINTAINERS file, to accommodate the renaming 
> of the mcp251xfd driver.
> 
> Vincent Mailhol contributes 3 patches for the CAN networking layer. First error
> queue support is added the the CAN RAW protocol. The second patch converts the
> get_can_dlc() and get_canfd_dlc() in-Kernel-only macros from using __u8 to u8.
> The third patch adds a helper function to calculate the length of one bit in in
> multiple of time quanta.
> 
> Oliver Hartkopp's patch add support for the ISO 15765-2:2016 transport protocol
> to the CAN stack.
> 
> Three patches by Lad Prabhakar add documentation for various new rcar
> controllers to the device tree bindings of the rcar_can and rcan_canfd driver.
> 
> Michael Walle's patch adds various processors to the flexcan driver binding
> documentation.
> 
> The next two patches are by me and target the flexcan driver aswell. The remove
> the ack_grp and ack_bit from the fsl,stop-mode DT property and the driver, as
> they are not used anymore. As these are the last two arguments this change will
> not break existing device trees.
> 
> The last three patches are by Srinivas Neeli and target the xilinx_can driver.
> The first one increases the lower limit for the bit rate prescaler to 2, the
> other two fix sparse and coverity findings.

Pulled, thank you!

Would you mind in the future adding net-next to the patch subject like
we do for normal patches directly applied to net-next? That way our
build bot will test the patches. I should just teach it to recognize
PRs but I haven't found the time, yet :(

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol
  2020-10-10  0:57   ` Jakub Kicinski
@ 2020-10-10 14:29     ` Oliver Hartkopp
  2020-10-10 15:44       ` Jakub Kicinski
  0 siblings, 1 reply; 27+ messages in thread
From: Oliver Hartkopp @ 2020-10-10 14:29 UTC (permalink / raw)
  To: Jakub Kicinski, Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel



On 10.10.20 02:57, Jakub Kicinski wrote:
> On Wed,  7 Oct 2020 23:31:50 +0200 Marc Kleine-Budde wrote:
>> From: Oliver Hartkopp <socketcan@hartkopp.net>
>>
>> CAN Transport Protocols offer support for segmented Point-to-Point
>> communication between CAN nodes via two defined CAN Identifiers.
>> As CAN frames can only transport a small amount of data bytes
>> (max. 8 bytes for 'classic' CAN and max. 64 bytes for CAN FD) this
>> segmentation is needed to transport longer PDUs as needed e.g. for
>> vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic.
>> This protocol driver implements data transfers according to
>> ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.
> 
> A few random things jump out here at a quick scan. Most of them are
> not important enough to have to be addressed, but please follow up on
> the 'default y' thing ASAP.
> 
>> +/*
>> + * Remark on CAN_ISOTP_DEFAULT_RECV_* values:
>> + *
>> + * We can strongly assume, that the Linux Kernel implementation of
>> + * CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0.
>> + * But as we like to be able to behave as a commonly available ECU,
>> + * these default settings can be changed via sockopts.
>> + * For that reason the STmin value is intentionally _not_ checked for
>> + * consistency and copied directly into the flow control (FC) frame.
>> + *
> 
> spurious empty comment line
> 

Oh, yes - at the front and at the end. I will fix that.

>> + */
>> +
>> +#endif /* !_UAPI_CAN_ISOTP_H */
>> diff --git a/net/can/Kconfig b/net/can/Kconfig
>> index 25436a715db3..021fe03a8ed6 100644
>> --- a/net/can/Kconfig
>> +++ b/net/can/Kconfig
>> @@ -55,6 +55,19 @@ config CAN_GW
>>   
>>   source "net/can/j1939/Kconfig"
>>   
>> +config CAN_ISOTP
>> +	tristate "ISO 15765-2:2016 CAN transport protocol"
>> +	default y
> 
> default should not be y unless there is a very good reason.
> I don't see such reason here. This is new functionality, users
> can enable it if they need it.
> 

Yes. I agree. But there is a good reason for it.
The ISO 15765-2 protocol is used for vehicle diagnosis and is a *very* 
common CAN bus use case.

The config item only shows up when CONFIG_CAN is selected and then ISO 
15765-2 should be enabled too. I have implemented and maintained the 
out-of-tree driver for ~12 years now and the people have real problems 
using e.g. Ubuntu with signed kernel modules when they need this protocol.

Therefore the option should default to 'y' to make sure the common 
distros (that enable CONFIG_CAN) enable ISO-TP too.

>> +	help
>> +	  CAN Transport Protocols offer support for segmented Point-to-Point
>> +	  communication between CAN nodes via two defined CAN Identifiers.
>> +	  As CAN frames can only transport a small amount of data bytes
>> +	  (max. 8 bytes for 'classic' CAN and max. 64 bytes for CAN FD) this
>> +	  segmentation is needed to transport longer PDUs as needed e.g. for
>> +	  vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic.
>> +	  This protocol driver implements data transfers according to
>> +	  ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.
>> +
>>   source "drivers/net/can/Kconfig"
>>   
>>   endif
> 
>> +#define CAN_ISOTP_VERSION "20200928"
> 
> We've been removing such version strings throughout the drivers.
> Kernel version should be sufficient for in-tree modules.

Yes. Good point.
I will send a separate patch which removes all the VERSION information 
from the entire CAN bus subsystem (core, raw, bcm, gw).

>> +static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
>> +{
>> +	struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
>> +					     txtimer);
>> +	struct sock *sk = &so->sk;
>> +	struct sk_buff *skb;
>> +	struct net_device *dev;
>> +	struct canfd_frame *cf;
>> +	enum hrtimer_restart restart = HRTIMER_NORESTART;
>> +	int can_send_ret;
>> +	int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
>> +
>> +	switch (so->tx.state) {
>> +	case ISOTP_WAIT_FC:
>> +	case ISOTP_WAIT_FIRST_FC:
>> +
>> +		/* we did not get any flow control frame in time */
>> +
>> +		/* report 'communication error on send' */
>> +		sk->sk_err = ECOMM;
>> +		if (!sock_flag(sk, SOCK_DEAD))
>> +			sk->sk_error_report(sk);
>> +
>> +		/* reset tx state */
>> +		so->tx.state = ISOTP_IDLE;
>> +		wake_up_interruptible(&so->wait);
>> +		break;
>> +
>> +	case ISOTP_SENDING:
>> +
>> +		/* push out the next segmented pdu */
>> +		dev = dev_get_by_index(sock_net(sk), so->ifindex);
>> +		if (!dev)
>> +			break;
>> +
>> +isotp_tx_burst:
>> +		skb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv),
>> +				gfp_any());
> 
> This is always in a timer context, so no need for gfp_any(), right?
> 

Some code from the time where hrtimer was only in hard-irq context. Will 
fix that too.

>> +		if (!skb) {
>> +			dev_put(dev);
>> +			break;
>> +		}
>> +
>> +		can_skb_reserve(skb);
>> +		can_skb_prv(skb)->ifindex = dev->ifindex;
>> +		can_skb_prv(skb)->skbcnt = 0;
>> +
>> +		cf = (struct canfd_frame *)skb->data;
>> +		skb_put(skb, so->ll.mtu);
>> +
>> +		/* create consecutive frame */
>> +		isotp_fill_dataframe(cf, so, ae, 0);
>> +
>> +		/* place consecutive frame N_PCI in appropriate index */
>> +		cf->data[ae] = N_PCI_CF | so->tx.sn++;
>> +		so->tx.sn %= 16;
>> +		so->tx.bs++;
>> +
>> +		if (so->ll.mtu == CANFD_MTU)
>> +			cf->flags = so->ll.tx_flags;
>> +
>> +		skb->dev = dev;
>> +		can_skb_set_owner(skb, sk);
>> +
>> +		can_send_ret = can_send(skb, 1);
>> +		if (can_send_ret)
>> +			printk_once(KERN_NOTICE "can-isotp: %s: can_send_ret %d\n",
>> +				    __func__, can_send_ret);
> 
> pr_notice_once()

Ok. Will change that at the several occurrences.

>> +
>> +		if (so->tx.idx >= so->tx.len) {
>> +			/* we are done */
>> +			so->tx.state = ISOTP_IDLE;
>> +			dev_put(dev);
>> +			wake_up_interruptible(&so->wait);
>> +			break;
>> +		}
>> +
>> +		if (so->txfc.bs && so->tx.bs >= so->txfc.bs) {
>> +			/* stop and wait for FC */
>> +			so->tx.state = ISOTP_WAIT_FC;
>> +			dev_put(dev);
>> +			hrtimer_set_expires(&so->txtimer,
>> +					    ktime_add(ktime_get(),
>> +						      ktime_set(1, 0)));
>> +			restart = HRTIMER_RESTART;
>> +			break;
>> +		}
>> +
>> +		/* no gap between data frames needed => use burst mode */
>> +		if (!so->tx_gap)
>> +			goto isotp_tx_burst;
>> +
>> +		/* start timer to send next data frame with correct delay */
>> +		dev_put(dev);
>> +		hrtimer_set_expires(&so->txtimer,
>> +				    ktime_add(ktime_get(), so->tx_gap));
>> +		restart = HRTIMER_RESTART;
>> +		break;
>> +
>> +	default:
>> +		WARN_ON_ONCE(1);
>> +	}
>> +
>> +	return restart;
>> +}

Thanks for the review!

Will send the patches for the net-next tree later this day.

Best regards,
Oliver

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol
  2020-10-10 14:29     ` Oliver Hartkopp
@ 2020-10-10 15:44       ` Jakub Kicinski
  2020-10-10 16:24         ` Oliver Hartkopp
  0 siblings, 1 reply; 27+ messages in thread
From: Jakub Kicinski @ 2020-10-10 15:44 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: Marc Kleine-Budde, netdev, davem, linux-can, kernel

On Sat, 10 Oct 2020 16:29:06 +0200 Oliver Hartkopp wrote:
> >> diff --git a/net/can/Kconfig b/net/can/Kconfig
> >> index 25436a715db3..021fe03a8ed6 100644
> >> --- a/net/can/Kconfig
> >> +++ b/net/can/Kconfig
> >> @@ -55,6 +55,19 @@ config CAN_GW
> >>   
> >>   source "net/can/j1939/Kconfig"
> >>   
> >> +config CAN_ISOTP
> >> +	tristate "ISO 15765-2:2016 CAN transport protocol"
> >> +	default y  
> > 
> > default should not be y unless there is a very good reason.
> > I don't see such reason here. This is new functionality, users
> > can enable it if they need it.
> 
> Yes. I agree. But there is a good reason for it.
> The ISO 15765-2 protocol is used for vehicle diagnosis and is a *very* 
> common CAN bus use case.

More common than j1939? (Google uses words like 'widely used' and
'common' :)) To give you some perspective we don't enable Ethernet 
vlan support by default, vlans are pretty common, too.

> The config item only shows up when CONFIG_CAN is selected and then ISO 
> 15765-2 should be enabled too. I have implemented and maintained the 
> out-of-tree driver for ~12 years now and the people have real problems 
> using e.g. Ubuntu with signed kernel modules when they need this protocol.
> 
> Therefore the option should default to 'y' to make sure the common 
> distros (that enable CONFIG_CAN) enable ISO-TP too.

I understand the motivation, but Linus had pushed back on defaulting to
'y' many times over the years, please read this:

https://lkml.org/lkml/2012/1/6/354

This really must not pop up on his screen as default 'y' when he does
an oldconfig after pulling the networking tree..

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol
  2020-10-10 15:44       ` Jakub Kicinski
@ 2020-10-10 16:24         ` Oliver Hartkopp
  2020-10-10 16:34           ` Jakub Kicinski
  0 siblings, 1 reply; 27+ messages in thread
From: Oliver Hartkopp @ 2020-10-10 16:24 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Marc Kleine-Budde, netdev, davem, linux-can, kernel



On 10.10.20 17:44, Jakub Kicinski wrote:
> On Sat, 10 Oct 2020 16:29:06 +0200 Oliver Hartkopp wrote:
>>>> diff --git a/net/can/Kconfig b/net/can/Kconfig
>>>> index 25436a715db3..021fe03a8ed6 100644
>>>> --- a/net/can/Kconfig
>>>> +++ b/net/can/Kconfig
>>>> @@ -55,6 +55,19 @@ config CAN_GW
>>>>    
>>>>    source "net/can/j1939/Kconfig"
>>>>    
>>>> +config CAN_ISOTP
>>>> +	tristate "ISO 15765-2:2016 CAN transport protocol"
>>>> +	default y
>>>
>>> default should not be y unless there is a very good reason.
>>> I don't see such reason here. This is new functionality, users
>>> can enable it if they need it.
>>
>> Yes. I agree. But there is a good reason for it.
>> The ISO 15765-2 protocol is used for vehicle diagnosis and is a *very*
>> common CAN bus use case.
> 
> More common than j1939? (Google uses words like 'widely used' and
> 'common' :)) To give you some perspective we don't enable Ethernet
> vlan support by default, vlans are pretty common, too.
> 
>> The config item only shows up when CONFIG_CAN is selected and then ISO
>> 15765-2 should be enabled too. I have implemented and maintained the
>> out-of-tree driver for ~12 years now and the people have real problems
>> using e.g. Ubuntu with signed kernel modules when they need this protocol.
>>
>> Therefore the option should default to 'y' to make sure the common
>> distros (that enable CONFIG_CAN) enable ISO-TP too.
> 
> I understand the motivation, but Linus had pushed back on defaulting to
> 'y' many times over the years, please read this:
> 
> https://lkml.org/lkml/2012/1/6/354
> 
> This really must not pop up on his screen as default 'y' when he does
> an oldconfig after pulling the networking tree..
> 

Ok. Understood.

I'll remove the default=y then. Would it be ok to add some text like

If you want to perfrom automotive vehicle diagnostic services (UDS), say 
'y'.

?

Best regards,
Oliver

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol
  2020-10-10 16:24         ` Oliver Hartkopp
@ 2020-10-10 16:34           ` Jakub Kicinski
  0 siblings, 0 replies; 27+ messages in thread
From: Jakub Kicinski @ 2020-10-10 16:34 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: Marc Kleine-Budde, netdev, davem, linux-can, kernel

On Sat, 10 Oct 2020 18:24:48 +0200 Oliver Hartkopp wrote:
> Ok. Understood.
> 
> I'll remove the default=y then. Would it be ok to add some text like
> 
> If you want to perfrom automotive vehicle diagnostic services (UDS), say 
> 'y'.

Most certainly, feel free to provide whatever description you reckon
will help users who need this to identify the option.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from driver
  2020-10-07 21:31 ` [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from driver Marc Kleine-Budde
@ 2020-10-14  8:53   ` Joakim Zhang
  2020-10-14 10:17     ` Marc Kleine-Budde
  0 siblings, 1 reply; 27+ messages in thread
From: Joakim Zhang @ 2020-10-14  8:53 UTC (permalink / raw)
  To: Marc Kleine-Budde, netdev; +Cc: davem, linux-can, kernel


> -----Original Message-----
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Sent: 2020年10月8日 5:32
> To: netdev@vger.kernel.org
> Cc: davem@davemloft.net; linux-can@vger.kernel.org;
> kernel@pengutronix.de; Marc Kleine-Budde <mkl@pengutronix.de>; Joakim
> Zhang <qiangqing.zhang@nxp.com>
> Subject: [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from
> driver
> 
> Since commit:
> 
>     048e3a34a2e7 can: flexcan: poll MCR_LPM_ACK instead of GPR ACK for
> stop mode acknowledgment
> 
> the driver polls the IP core's internal bit MCR[LPM_ACK] as stop mode
> acknowledge and not the acknowledgment on chip level.
> 
> This means the 4th and 5th value of the property "fsl,stop-mode" isn't used
> anymore. This patch removes the used "ack_gpr" and "ack_bit" from the
> driver.
> 
> Link:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flore.kern
> el.org%2Fr%2F20201006203748.1750156-15-mkl%40pengutronix.de&amp;dat
> a=02%7C01%7Cqiangqing.zhang%40nxp.com%7C1540ad5bf7bd4a1e10a508d8
> 6b087a67%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637377031
> 436785787&amp;sdata=ierIIVdSqZFLklIvgMokHX6LU77cEWQgUGzUi6CHdDI%
> 3D&amp;reserved=0
> Fixes: 048e3a34a2e7 ("can: flexcan: poll MCR_LPM_ACK instead of GPR ACK
> for stop mode acknowledgment")
> Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

[...]
>  	/* stop mode property format is:
> -	 * <&gpr req_gpr req_bit ack_gpr ack_bit>.
> +	 * <&gpr req_gpr>.

Hi Marc,

Sorry for response delay, stop mode property format should be "<&gpr req_gpr req_bit>", I saw this code change has went into linux-next, so I will correct it by the way next time when I upsteam wakeup function for i.MX8.

Need I update stop mode property in dts file? Although this function won't be broken without dts update.

Best Regards,
Joakim Zhang

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from driver
  2020-10-14  8:53   ` Joakim Zhang
@ 2020-10-14 10:17     ` Marc Kleine-Budde
  0 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-14 10:17 UTC (permalink / raw)
  To: Joakim Zhang, netdev; +Cc: davem, linux-can, kernel


[-- Attachment #1.1: Type: text/plain, Size: 2046 bytes --]

On 10/14/20 10:53 AM, Joakim Zhang wrote:
>> Since commit:
>>
>>     048e3a34a2e7 can: flexcan: poll MCR_LPM_ACK instead of GPR ACK for
>> stop mode acknowledgment
>>
>> the driver polls the IP core's internal bit MCR[LPM_ACK] as stop mode
>> acknowledge and not the acknowledgment on chip level.
>>
>> This means the 4th and 5th value of the property "fsl,stop-mode" isn't used
>> anymore. This patch removes the used "ack_gpr" and "ack_bit" from the
>> driver.
>>
>> Link:
>> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flore.kern
>> el.org%2Fr%2F20201006203748.1750156-15-mkl%40pengutronix.de&amp;dat
>> a=02%7C01%7Cqiangqing.zhang%40nxp.com%7C1540ad5bf7bd4a1e10a508d8
>> 6b087a67%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637377031
>> 436785787&amp;sdata=ierIIVdSqZFLklIvgMokHX6LU77cEWQgUGzUi6CHdDI%
>> 3D&amp;reserved=0
>> Fixes: 048e3a34a2e7 ("can: flexcan: poll MCR_LPM_ACK instead of GPR ACK
>> for stop mode acknowledgment")
>> Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> 
> [...]
>>  	/* stop mode property format is:
>> -	 * <&gpr req_gpr req_bit ack_gpr ack_bit>.
>> +	 * <&gpr req_gpr>.
> 
> Hi Marc,
> 
> Sorry for response delay, stop mode property format should be "<&gpr req_gpr
> req_bit>", I saw this code change has went into linux-next, so I will correct
> it by the way next time when I upsteam wakeup function for i.MX8.

Doh! I wrongly deleted "req_bit" in the comment, but the code should be all
right. I'll add that back.

> Need I update stop mode property in dts file? Although this function won't be
> broken without dts update.

Yes, you can send patches to update the dts (after net-next was merged to linus).

Marc

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 03/17] can: c_can: reg_map_{c,d}_can: mark as __maybe_unused
  2020-10-06 20:37 [RFC]: can-next 2020-10-06 Marc Kleine-Budde
@ 2020-10-06 20:37 ` Marc Kleine-Budde
  0 siblings, 0 replies; 27+ messages in thread
From: Marc Kleine-Budde @ 2020-10-06 20:37 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Marc Kleine-Budde

This patch marks the arrays reg_map_c_can and reg_map_d_can as __maybe_unused,
as they are indeed unused in the c_can driver. This warning shows up, when
compiling the kernel with "W=1":

    drivers/net/can/c_can/c_can.c:45:
    drivers/net/can/c_can/c_can.h:124:18: warning: ‘reg_map_d_can’ defined but not used [-Wunused-const-variable=]
    drivers/net/can/c_can/c_can.h:84:18: warning: ‘reg_map_c_can’ defined but not used [-Wunused-const-variable=]

Fixes: 33f810097769 ("can: c_can: Move overlay structure to array with offset as index")
Fixes: 69927fccd96b ("can: c_can: Add support for Bosch D_CAN controller")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index d5567a7c1c6d..92213d3d96eb 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -81,7 +81,7 @@ enum reg {
 	C_CAN_FUNCTION_REG,
 };
 
-static const u16 reg_map_c_can[] = {
+static const u16 __maybe_unused reg_map_c_can[] = {
 	[C_CAN_CTRL_REG]	= 0x00,
 	[C_CAN_STS_REG]		= 0x02,
 	[C_CAN_ERR_CNT_REG]	= 0x04,
@@ -121,7 +121,7 @@ static const u16 reg_map_c_can[] = {
 	[C_CAN_MSGVAL2_REG]	= 0xB2,
 };
 
-static const u16 reg_map_d_can[] = {
+static const u16 __maybe_unused reg_map_d_can[] = {
 	[C_CAN_CTRL_REG]	= 0x00,
 	[C_CAN_CTRL_EX_REG]	= 0x02,
 	[C_CAN_STS_REG]		= 0x04,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-10-14 10:17 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 21:31 pull-request: can-next 2020-10-07 Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 01/17] can: af_can: can_rcv_list_find(): fix kernel doc after variable renaming Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 02/17] can: softing: softing_card_shutdown(): add braces around empty body in an 'if' statement Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 03/17] can: c_can: reg_map_{c,d}_can: mark as __maybe_unused Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 04/17] MAINTAINERS: adjust to mcp251xfd file renaming Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 05/17] can: raw: add missing error queue support Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 06/17] can: dev: fix type of get_can_dlc() and get_canfd_dlc() macros Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 07/17] can: dev: add a helper function to calculate the duration of one bit Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 08/17] can: add ISO 15765-2:2016 transport protocol Marc Kleine-Budde
2020-10-10  0:57   ` Jakub Kicinski
2020-10-10 14:29     ` Oliver Hartkopp
2020-10-10 15:44       ` Jakub Kicinski
2020-10-10 16:24         ` Oliver Hartkopp
2020-10-10 16:34           ` Jakub Kicinski
2020-10-07 21:31 ` [PATCH 09/17] dt-bindings: can: rcar_can: Add r8a7742 support Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 10/17] dt-bindings: can: rcar_canfd: Document r8a774e1 support Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 11/17] dt-bindings: can: rcar_can: " Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 12/17] dt-bindings: can: flexcan: list supported processors Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 13/17] dt-bindings: can: flexcan: remove ack_grp and ack_bit from fsl,stop-mode Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 14/17] can: flexcan: remove ack_grp and ack_bit handling from driver Marc Kleine-Budde
2020-10-14  8:53   ` Joakim Zhang
2020-10-14 10:17     ` Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 15/17] can: xilinx_can: Limit CANFD brp to 2 Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 16/17] can: xilinx_can: Check return value of set_reset_mode Marc Kleine-Budde
2020-10-07 21:31 ` [PATCH 17/17] can: xilinx_can: Fix incorrect variable and initialize with a default value Marc Kleine-Budde
2020-10-10  1:09 ` pull-request: can-next 2020-10-07 Jakub Kicinski
  -- strict thread matches above, loose matches on Subject: below --
2020-10-06 20:37 [RFC]: can-next 2020-10-06 Marc Kleine-Budde
2020-10-06 20:37 ` [PATCH 03/17] can: c_can: reg_map_{c,d}_can: mark as __maybe_unused Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.