Commit 8f5e71b9 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge tag 'linux-can-next-for-5.10-20201007' of...

Merge tag 'linux-can-next-for-5.10-20201007' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

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

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.
====================
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 3b8f56ee 164ab90d
...@@ -4,6 +4,12 @@ Required properties: ...@@ -4,6 +4,12 @@ Required properties:
- compatible : Should be "fsl,<processor>-flexcan" - 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 An implementation should also claim any of the following compatibles
that it is fully backwards compatible with: that it is fully backwards compatible with:
...@@ -25,12 +31,10 @@ Optional properties: ...@@ -25,12 +31,10 @@ Optional properties:
endian. endian.
- fsl,stop-mode: register bits of stop mode control, the format is - 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. gpr is the phandle to general purpose register node.
req_gpr is the gpr register offset of CAN stop request. req_gpr is the gpr register offset of CAN stop request.
req_bit is the bit 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). - fsl,clk-source: Select the clock source to the CAN Protocol Engine (PE).
It's SoC Implementation dependent. Refer to RM for detailed It's SoC Implementation dependent. Refer to RM for detailed
......
...@@ -2,13 +2,15 @@ Renesas R-Car CAN controller Device Tree Bindings ...@@ -2,13 +2,15 @@ Renesas R-Car CAN controller Device Tree Bindings
------------------------------------------------- -------------------------------------------------
Required properties: 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-r8a7744" if CAN controller is a part of R8A7744 SoC.
"renesas,can-r8a7745" if CAN controller is a part of R8A7745 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. "renesas,can-r8a77470" if CAN controller is a part of R8A77470 SoC.
"renesas,can-r8a774a1" if CAN controller is a part of R8A774A1 SoC. "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-r8a774b1" if CAN controller is a part of R8A774B1 SoC.
"renesas,can-r8a774c0" if CAN controller is a part of R8A774C0 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-r8a7778" if CAN controller is a part of R8A7778 SoC.
"renesas,can-r8a7779" if CAN controller is a part of R8A7779 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. "renesas,can-r8a7790" if CAN controller is a part of R8A7790 SoC.
...@@ -37,8 +39,8 @@ Required properties: ...@@ -37,8 +39,8 @@ Required properties:
- pinctrl-0: pin control group to be used for this controller. - pinctrl-0: pin control group to be used for this controller.
- pinctrl-names: must be "default". - pinctrl-names: must be "default".
Required properties for R8A774A1, R8A774B1, R8A774C0, R8A7795, R8A7796, Required properties for R8A774A1, R8A774B1, R8A774C0, R8A774E1, R8A7795,
R8A77965, R8A77990, and R8A77995: R8A7796, R8A77965, R8A77990, and R8A77995:
For the denoted SoCs, "clkp2" can be CANFD clock. This is a div6 clock and can 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 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 scaled to maximum frequency if any of these controllers use it. This is done
......
...@@ -7,6 +7,7 @@ Required properties: ...@@ -7,6 +7,7 @@ Required properties:
- "renesas,r8a774a1-canfd" for R8A774A1 (RZ/G2M) compatible controller. - "renesas,r8a774a1-canfd" for R8A774A1 (RZ/G2M) compatible controller.
- "renesas,r8a774b1-canfd" for R8A774B1 (RZ/G2N) compatible controller. - "renesas,r8a774b1-canfd" for R8A774B1 (RZ/G2N) compatible controller.
- "renesas,r8a774c0-canfd" for R8A774C0 (RZ/G2E) 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,r8a7795-canfd" for R8A7795 (R-Car H3) compatible controller.
- "renesas,r8a7796-canfd" for R8A7796 (R-Car M3-W) compatible controller. - "renesas,r8a7796-canfd" for R8A7796 (R-Car M3-W) compatible controller.
- "renesas,r8a77965-canfd" for R8A77965 (R-Car M3-N) 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 ...@@ -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 child node supports the "status" property only, which is used to
enable/disable the respective channel. enable/disable the respective channel.
Required properties for R8A774A1, R8A774B1, R8A774C0, R8A7795, R8A7796, Required properties for R8A774A1, R8A774B1, R8A774C0, R8A774E1, R8A7795,
R8A77965, R8A77990, and R8A77995: R8A7796, R8A77965, R8A77990, and R8A77995:
In the denoted SoCs, canfd clock is a div6 clock and can be used by both CAN 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 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 frequency if any of these controllers use it. This is done using the below
......
...@@ -3917,6 +3917,7 @@ F: include/net/netns/can.h ...@@ -3917,6 +3917,7 @@ F: include/net/netns/can.h
F: include/uapi/linux/can.h F: include/uapi/linux/can.h
F: include/uapi/linux/can/bcm.h F: include/uapi/linux/can/bcm.h
F: include/uapi/linux/can/gw.h F: include/uapi/linux/can/gw.h
F: include/uapi/linux/can/isotp.h
F: include/uapi/linux/can/raw.h F: include/uapi/linux/can/raw.h
F: net/can/ F: net/can/
...@@ -10680,14 +10681,14 @@ L: linux-input@vger.kernel.org ...@@ -10680,14 +10681,14 @@ L: linux-input@vger.kernel.org
S: Maintained S: Maintained
F: drivers/hid/hid-mcp2221.c F: drivers/hid/hid-mcp2221.c
MCP25XXFD SPI-CAN NETWORK DRIVER MCP251XFD SPI-CAN NETWORK DRIVER
M: Marc Kleine-Budde <mkl@pengutronix.de> M: Marc Kleine-Budde <mkl@pengutronix.de>
M: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> M: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
R: Thomas Kopp <thomas.kopp@microchip.com> R: Thomas Kopp <thomas.kopp@microchip.com>
L: linux-can@vger.kernel.org L: linux-can@vger.kernel.org
S: Maintained S: Maintained
F: Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.yaml F: Documentation/devicetree/bindings/net/can/microchip,mcp251xfd.yaml
F: drivers/net/can/spi/mcp25xxfd/ F: drivers/net/can/spi/mcp251xfd/
MCP4018 AND MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVERS MCP4018 AND MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVERS
M: Peter Rosin <peda@axentia.se> M: Peter Rosin <peda@axentia.se>
......
...@@ -81,7 +81,7 @@ enum reg { ...@@ -81,7 +81,7 @@ enum reg {
C_CAN_FUNCTION_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_CTRL_REG] = 0x00,
[C_CAN_STS_REG] = 0x02, [C_CAN_STS_REG] = 0x02,
[C_CAN_ERR_CNT_REG] = 0x04, [C_CAN_ERR_CNT_REG] = 0x04,
...@@ -121,7 +121,7 @@ static const u16 reg_map_c_can[] = { ...@@ -121,7 +121,7 @@ static const u16 reg_map_c_can[] = {
[C_CAN_MSGVAL2_REG] = 0xB2, [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_REG] = 0x00,
[C_CAN_CTRL_EX_REG] = 0x02, [C_CAN_CTRL_EX_REG] = 0x02,
[C_CAN_STS_REG] = 0x04, [C_CAN_STS_REG] = 0x04,
......
...@@ -60,7 +60,6 @@ EXPORT_SYMBOL_GPL(can_len2dlc); ...@@ -60,7 +60,6 @@ EXPORT_SYMBOL_GPL(can_len2dlc);
#ifdef CONFIG_CAN_CALC_BITTIMING #ifdef CONFIG_CAN_CALC_BITTIMING
#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */ #define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
#define CAN_CALC_SYNC_SEG 1
/* Bit-timing calculation derived from: /* Bit-timing calculation derived from:
* *
...@@ -86,8 +85,8 @@ can_update_sample_point(const struct can_bittiming_const *btc, ...@@ -86,8 +85,8 @@ can_update_sample_point(const struct can_bittiming_const *btc,
int i; int i;
for (i = 0; i <= 1; i++) { for (i = 0; i <= 1; i++) {
tseg2 = tseg + CAN_CALC_SYNC_SEG - tseg2 = tseg + CAN_SYNC_SEG -
(sample_point_nominal * (tseg + CAN_CALC_SYNC_SEG)) / (sample_point_nominal * (tseg + CAN_SYNC_SEG)) /
1000 - i; 1000 - i;
tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max); tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max);
tseg1 = tseg - tseg2; tseg1 = tseg - tseg2;
...@@ -96,8 +95,8 @@ can_update_sample_point(const struct can_bittiming_const *btc, ...@@ -96,8 +95,8 @@ can_update_sample_point(const struct can_bittiming_const *btc,
tseg2 = tseg - tseg1; tseg2 = tseg - tseg1;
} }
sample_point = 1000 * (tseg + CAN_CALC_SYNC_SEG - tseg2) / sample_point = 1000 * (tseg + CAN_SYNC_SEG - tseg2) /
(tseg + CAN_CALC_SYNC_SEG); (tseg + CAN_SYNC_SEG);
sample_point_error = abs(sample_point_nominal - sample_point); sample_point_error = abs(sample_point_nominal - sample_point);
if (sample_point <= sample_point_nominal && if (sample_point <= sample_point_nominal &&
...@@ -145,7 +144,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -145,7 +144,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
/* tseg even = round down, odd = round up */ /* tseg even = round down, odd = round up */
for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1; for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1;
tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) { 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) */ /* Compute all possible tseg choices (tseg=tseg1+tseg2) */
brp = priv->clock.freq / (tsegall * bt->bitrate) + tseg % 2; 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, ...@@ -223,7 +222,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
/* real bitrate */ /* real bitrate */
bt->bitrate = priv->clock.freq / bt->bitrate = priv->clock.freq /
(bt->brp * (CAN_CALC_SYNC_SEG + tseg1 + tseg2)); (bt->brp * (CAN_SYNC_SEG + tseg1 + tseg2));
return 0; return 0;
} }
......
...@@ -333,8 +333,6 @@ struct flexcan_stop_mode { ...@@ -333,8 +333,6 @@ struct flexcan_stop_mode {
struct regmap *gpr; struct regmap *gpr;
u8 req_gpr; u8 req_gpr;
u8 req_bit; u8 req_bit;
u8 ack_gpr;
u8 ack_bit;
}; };
struct flexcan_priv { struct flexcan_priv {
...@@ -1847,14 +1845,14 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev) ...@@ -1847,14 +1845,14 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
struct device_node *gpr_np; struct device_node *gpr_np;
struct flexcan_priv *priv; struct flexcan_priv *priv;
phandle phandle; phandle phandle;
u32 out_val[5]; u32 out_val[3];
int ret; int ret;
if (!np) if (!np)
return -EINVAL; return -EINVAL;
/* stop mode property format is: /* 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, ret = of_property_read_u32_array(np, "fsl,stop-mode", out_val,
ARRAY_SIZE(out_val)); ARRAY_SIZE(out_val));
...@@ -1880,13 +1878,10 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev) ...@@ -1880,13 +1878,10 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
priv->stm.req_gpr = out_val[1]; priv->stm.req_gpr = out_val[1];
priv->stm.req_bit = out_val[2]; 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, dev_dbg(&pdev->dev,
"gpr %s req_gpr=0x02%x req_bit=%u ack_gpr=0x02%x ack_bit=%u\n", "gpr %s req_gpr=0x02%x req_bit=%u\n",
gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit, gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit);
priv->stm.ack_gpr, priv->stm.ack_bit);
device_set_wakeup_capable(&pdev->dev, true); device_set_wakeup_capable(&pdev->dev, true);
......
...@@ -447,8 +447,9 @@ static void softing_card_shutdown(struct softing *card) ...@@ -447,8 +447,9 @@ static void softing_card_shutdown(struct softing *card)
{ {
int fw_up = 0; int fw_up = 0;
if (mutex_lock_interruptible(&card->fw.lock)) if (mutex_lock_interruptible(&card->fw.lock)) {
/* return -ERESTARTSYS */; /* return -ERESTARTSYS */;
}
fw_up = card->fw.up; fw_up = card->fw.up;
card->fw.up = 0; card->fw.up = 0;
......
...@@ -259,7 +259,7 @@ static const struct can_bittiming_const xcan_bittiming_const_canfd2 = { ...@@ -259,7 +259,7 @@ static const struct can_bittiming_const xcan_bittiming_const_canfd2 = {
.tseg2_min = 1, .tseg2_min = 1,
.tseg2_max = 128, .tseg2_max = 128,
.sjw_max = 128, .sjw_max = 128,
.brp_min = 1, .brp_min = 2,
.brp_max = 256, .brp_max = 256,
.brp_inc = 1, .brp_inc = 1,
}; };
...@@ -272,7 +272,7 @@ static struct can_bittiming_const xcan_data_bittiming_const_canfd2 = { ...@@ -272,7 +272,7 @@ static struct can_bittiming_const xcan_data_bittiming_const_canfd2 = {
.tseg2_min = 1, .tseg2_min = 1,
.tseg2_max = 16, .tseg2_max = 16,
.sjw_max = 16, .sjw_max = 16,
.brp_min = 1, .brp_min = 2,
.brp_max = 256, .brp_max = 256,
.brp_inc = 1, .brp_inc = 1,
}; };
...@@ -1369,9 +1369,13 @@ static irqreturn_t xcan_interrupt(int irq, void *dev_id) ...@@ -1369,9 +1369,13 @@ static irqreturn_t xcan_interrupt(int irq, void *dev_id)
static void xcan_chip_stop(struct net_device *ndev) static void xcan_chip_stop(struct net_device *ndev)
{ {
struct xcan_priv *priv = netdev_priv(ndev); struct xcan_priv *priv = netdev_priv(ndev);
int ret;
/* Disable interrupts and leave the can in configuration mode */ /* 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; priv->can.state = CAN_STATE_STOPPED;
} }
...@@ -1667,7 +1671,7 @@ static int xcan_probe(struct platform_device *pdev) ...@@ -1667,7 +1671,7 @@ static int xcan_probe(struct platform_device *pdev)
void __iomem *addr; void __iomem *addr;
int ret; int ret;
int rx_max, tx_max; 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; const char *hw_tx_max_property;
/* Get the virtual base address for the device */ /* Get the virtual base address for the device */
...@@ -1720,7 +1724,7 @@ static int xcan_probe(struct platform_device *pdev) ...@@ -1720,7 +1724,7 @@ static int xcan_probe(struct platform_device *pdev)
*/ */
if (!(devtype->flags & XCAN_FLAG_TX_MAILBOXES) && if (!(devtype->flags & XCAN_FLAG_TX_MAILBOXES) &&
(devtype->flags & XCAN_FLAG_TXFEMP)) (devtype->flags & XCAN_FLAG_TXFEMP))
tx_max = min(hw_tx_max, 2); tx_max = min(hw_tx_max, 2U);
else else
tx_max = 1; tx_max = 1;
......
...@@ -82,15 +82,30 @@ struct can_priv { ...@@ -82,15 +82,30 @@ struct can_priv {
#endif #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) * 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 * To be used in the CAN netdriver receive path to ensure conformance with
* ISO 11898-1 Chapter 8.4.2.3 (DLC field) * ISO 11898-1 Chapter 8.4.2.3 (DLC field)
*/ */
#define get_can_dlc(i) (min_t(__u8, (i), CAN_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)) #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 */ /* Check for outgoing skbs that have not been created by the CAN subsystem */
static inline bool can_skb_headroom_valid(struct net_device *dev, static inline bool can_skb_headroom_valid(struct net_device *dev,
......
/* 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 */
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
#include <linux/can.h> #include <linux/can.h>
#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW) #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) */ /* for socket options affecting the socket (not the global system) */
......
...@@ -55,6 +55,19 @@ config CAN_GW ...@@ -55,6 +55,19 @@ config CAN_GW
source "net/can/j1939/Kconfig" 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" source "drivers/net/can/Kconfig"
endif endif
...@@ -17,3 +17,6 @@ obj-$(CONFIG_CAN_GW) += can-gw.o ...@@ -17,3 +17,6 @@ obj-$(CONFIG_CAN_GW) += can-gw.o
can-gw-y := gw.o can-gw-y := gw.o
obj-$(CONFIG_CAN_J1939) += j1939/ obj-$(CONFIG_CAN_J1939) += j1939/
obj-$(CONFIG_CAN_ISOTP) += can-isotp.o
can-isotp-y := isotp.o
...@@ -338,7 +338,7 @@ static unsigned int effhash(canid_t can_id) ...@@ -338,7 +338,7 @@ static unsigned int effhash(canid_t can_id)
* can_rcv_list_find - determine optimal filterlist inside device filter struct * can_rcv_list_find - determine optimal filterlist inside device filter struct
* @can_id: pointer to CAN identifier of a given can_filter * @can_id: pointer to CAN identifier of a given can_filter
* @mask: pointer to CAN mask 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: * Description:
* Returns the optimal filterlist to reduce the filter handling in the * Returns the optimal filterlist to reduce the filter handling in the
......
This diff is collapsed.
...@@ -804,6 +804,10 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, ...@@ -804,6 +804,10 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
noblock = flags & MSG_DONTWAIT; noblock = flags & MSG_DONTWAIT;
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); skb = skb_recv_datagram(sk, flags, noblock, &err);
if (!skb) if (!skb)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment