Commit ac6f929d authored by Jakub Kicinski's avatar Jakub Kicinski

Merge tag 'linux-can-fixes-for-5.10-20201103' of...

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

Marc Kleine-Budde says:

====================
pull-request: can 2020-11-03

The first two patches are by Oleksij Rempel and they add a generic
can-controller Device Tree yaml binding and convert the text based binding
of the flexcan driver to a yaml based binding.

Zhang Changzhong's patch fixes a remove_proc_entry warning in the AF_CAN
core.

A patch by me fixes a kfree_skb() call from IRQ context in the rx-offload
helper.

Vincent Mailhol contributes a patch to prevent a call to kfree_skb() in
hard IRQ context in can_get_echo_skb().

Oliver Hartkopp's patch fixes the length calculation for RTR CAN frames
in the __can_get_echo_skb() helper.

Oleksij Rempel's patch fixes a use-after-free that shows up with j1939 in
can_create_echo_skb().

Yegor Yefremov contributes 4 patches to enhance the j1939 documentation.

Zhang Changzhong's patch fixes a hanging task problem in j1939_sk_bind()
if the netdev is down.

Then there are three patches for the newly added CAN_ISOTP protocol. Geert
Uytterhoeven enhances the kconfig help text. Oliver Hartkopp's patch adds
missing RX timeout handling in listen-only mode and Colin Ian King's patch
decreases the generated object code by 926 bytes.

Zhang Changzhong contributes a patch for the ti_hecc driver that fixes the
error path in the probe function.

Navid Emamdoost's patch for the xilinx_can driver fixes the error handling
in case of failing pm_runtime_get_sync().

There are two patches for the peak_usb driver. Dan Carpenter adds range
checking in decode operations and Stephane Grosjean's patch fixes
a timestamp wrapping problem.

Stephane Grosjean's patch for th peak_canfd driver fixes echo management if
loopback is on.

The next three patches all target the mcp251xfd driver. The first one is
by me and it increased the severity of CRC read error messages. The kernel
test robot removes an unneeded semicolon and Tom Rix removes unneeded
break in several switch-cases.

The last 4 patches are by Joakim Zhang and target the flexcan driver,
the first three fix ECC related device specific quirks for the LS1021A,
LX2160A and the VF610 SoC. The last patch disable wakeup completely upon
driver remove.

* tag 'linux-can-fixes-for-5.10-20201103' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: (27 commits)
  can: flexcan: flexcan_remove(): disable wakeup completely
  can: flexcan: add ECC initialization for VF610
  can: flexcan: add ECC initialization for LX2160A
  can: flexcan: remove FLEXCAN_QUIRK_DISABLE_MECR quirk for LS1021A
  can: mcp251xfd: remove unneeded break
  can: mcp251xfd: mcp251xfd_regmap_nocrc_read(): fix semicolon.cocci warnings
  can: mcp251xfd: mcp251xfd_regmap_crc_read(): increase severity of CRC read error messages
  can: peak_canfd: pucan_handle_can_rx(): fix echo management when loopback is on
  can: peak_usb: peak_usb_get_ts_time(): fix timestamp wrapping
  can: peak_usb: add range checking in decode operations
  can: xilinx_can: handle failure cases of pm_runtime_get_sync
  can: ti_hecc: ti_hecc_probe(): add missed clk_disable_unprepare() in error path
  can: isotp: padlen(): make const array static, makes object smaller
  can: isotp: isotp_rcv_cf(): enable RX timeout handling in listen-only mode
  can: isotp: Explain PDU in CAN_ISOTP help text
  can: j1939: j1939_sk_bind(): return failure if netdev is down
  can: j1939: use backquotes for code samples
  can: j1939: swap addr and pgn in the send example
  can: j1939: fix syntax and spelling
  can: j1939: rename jacd tool
  ...
====================

Link: https://lore.kernel.org/r/<20201103220636.972106-1-mkl@pengutronix.de>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 2da4c187 ab07ff1c
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/net/can/can-controller.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: CAN Controller Generic Binding
maintainers:
- Marc Kleine-Budde <mkl@pengutronix.de>
properties:
$nodename:
pattern: "^can(@.*)?$"
additionalProperties: true
...
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/net/can/fsl,flexcan.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title:
Flexcan CAN controller on Freescale's ARM and PowerPC system-on-a-chip (SOC).
maintainers:
- Marc Kleine-Budde <mkl@pengutronix.de>
allOf:
- $ref: can-controller.yaml#
properties:
compatible:
oneOf:
- enum:
- fsl,imx8qm-flexcan
- fsl,imx8mp-flexcan
- fsl,imx6q-flexcan
- fsl,imx53-flexcan
- fsl,imx35-flexcan
- fsl,imx28-flexcan
- fsl,imx25-flexcan
- fsl,p1010-flexcan
- fsl,vf610-flexcan
- fsl,ls1021ar2-flexcan
- fsl,lx2160ar1-flexcan
- items:
- enum:
- fsl,imx7d-flexcan
- fsl,imx6ul-flexcan
- fsl,imx6sx-flexcan
- const: fsl,imx6q-flexcan
- items:
- enum:
- fsl,ls1028ar1-flexcan
- const: fsl,lx2160ar1-flexcan
reg:
maxItems: 1
interrupts:
maxItems: 1
clocks:
maxItems: 2
clock-names:
items:
- const: ipg
- const: per
clock-frequency:
description: |
The oscillator frequency driving the flexcan device, filled in by the
boot loader. This property should only be used the used operating system
doesn't support the clocks and clock-names property.
xceiver-supply:
description: Regulator that powers the CAN transceiver.
big-endian:
$ref: /schemas/types.yaml#/definitions/flag
description: |
This means the registers of FlexCAN controller are big endian. This is
optional property.i.e. if this property is not present in device tree
node then controller is assumed to be little endian. If this property is
present then controller is assumed to be big endian.
fsl,stop-mode:
description: |
Register bits of stop mode control.
The format should be as follows:
<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.
$ref: /schemas/types.yaml#/definitions/phandle-array
items:
- description: The 'gpr' is the phandle to general purpose register node.
- description: The 'req_gpr' is the gpr register offset of CAN stop request.
maximum: 0xff
- description: The 'req_bit' is the bit offset of CAN stop request.
maximum: 0x1f
fsl,clk-source:
description: |
Select the clock source to the CAN Protocol Engine (PE). It's SoC
implementation dependent. Refer to RM for detailed definition. If this
property is not set in device tree node then driver selects clock source 1
by default.
0: clock source 0 (oscillator clock)
1: clock source 1 (peripheral clock)
$ref: /schemas/types.yaml#/definitions/uint32
default: 1
minimum: 0
maximum: 1
wakeup-source:
$ref: /schemas/types.yaml#/definitions/flag
description:
Enable CAN remote wakeup.
required:
- compatible
- reg
- interrupts
additionalProperties: false
examples:
- |
can@1c000 {
compatible = "fsl,p1010-flexcan";
reg = <0x1c000 0x1000>;
interrupts = <48 0x2>;
interrupt-parent = <&mpic>;
clock-frequency = <200000000>;
fsl,clk-source = <0>;
};
- |
#include <dt-bindings/interrupt-controller/irq.h>
can@2090000 {
compatible = "fsl,imx6q-flexcan";
reg = <0x02090000 0x4000>;
interrupts = <0 110 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clks 1>, <&clks 2>;
clock-names = "ipg", "per";
fsl,stop-mode = <&gpr 0x34 28>;
};
Flexcan CAN controller on Freescale's ARM and PowerPC system-on-a-chip (SOC).
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:
- fsl,p1010-flexcan
- reg : Offset and length of the register set for this device
- interrupts : Interrupt tuple for this device
Optional properties:
- clock-frequency : The oscillator frequency driving the flexcan device
- xceiver-supply: Regulator that powers the CAN transceiver
- big-endian: This means the registers of FlexCAN controller are big endian.
This is optional property.i.e. if this property is not present in
device tree node then controller is assumed to be little endian.
if this property is present then controller is assumed to be big
endian.
- fsl,stop-mode: register bits of stop mode control, the format is
<&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.
- fsl,clk-source: Select the clock source to the CAN Protocol Engine (PE).
It's SoC Implementation dependent. Refer to RM for detailed
definition. If this property is not set in device tree node
then driver selects clock source 1 by default.
0: clock source 0 (oscillator clock)
1: clock source 1 (peripheral clock)
- wakeup-source: enable CAN remote wakeup
Example:
can@1c000 {
compatible = "fsl,p1010-flexcan";
reg = <0x1c000 0x1000>;
interrupts = <48 0x2>;
interrupt-parent = <&mpic>;
clock-frequency = <200000000>; // filled in by bootloader
fsl,clk-source = <0>; // select clock source 0 for PE
};
This diff is collapsed.
...@@ -512,9 +512,13 @@ __can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr) ...@@ -512,9 +512,13 @@ __can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
*/ */
struct sk_buff *skb = priv->echo_skb[idx]; struct sk_buff *skb = priv->echo_skb[idx];
struct canfd_frame *cf = (struct canfd_frame *)skb->data; struct canfd_frame *cf = (struct canfd_frame *)skb->data;
u8 len = cf->len;
*len_ptr = len; /* get the real payload length for netdev statistics */
if (cf->can_id & CAN_RTR_FLAG)
*len_ptr = 0;
else
*len_ptr = cf->len;
priv->echo_skb[idx] = NULL; priv->echo_skb[idx] = NULL;
return skb; return skb;
...@@ -538,7 +542,11 @@ unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx) ...@@ -538,7 +542,11 @@ unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx)
if (!skb) if (!skb)
return 0; return 0;
netif_rx(skb); skb_get(skb);
if (netif_rx(skb) == NET_RX_SUCCESS)
dev_consume_skb_any(skb);
else
dev_kfree_skb_any(skb);
return len; return len;
} }
......
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
* MX8MP FlexCAN3 03.00.17.01 yes yes no yes yes yes * MX8MP FlexCAN3 03.00.17.01 yes yes no yes yes yes
* VF610 FlexCAN3 ? no yes no yes yes? no * VF610 FlexCAN3 ? no yes no yes yes? no
* LS1021A FlexCAN2 03.00.04.00 no yes no no yes no * LS1021A FlexCAN2 03.00.04.00 no yes no no yes no
* LX2160A FlexCAN3 03.00.23.00 no yes no no yes yes * LX2160A FlexCAN3 03.00.23.00 no yes no yes yes yes
* *
* Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected. * Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected.
*/ */
...@@ -400,19 +400,19 @@ static struct flexcan_devtype_data fsl_imx8mp_devtype_data = { ...@@ -400,19 +400,19 @@ static struct flexcan_devtype_data fsl_imx8mp_devtype_data = {
static const struct flexcan_devtype_data fsl_vf610_devtype_data = { static const struct flexcan_devtype_data fsl_vf610_devtype_data = {
.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS | .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP |
FLEXCAN_QUIRK_BROKEN_PERR_STATE, FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_SUPPORT_ECC,
}; };
static const struct flexcan_devtype_data fsl_ls1021a_r2_devtype_data = { static const struct flexcan_devtype_data fsl_ls1021a_r2_devtype_data = {
.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS | .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
}; };
static const struct flexcan_devtype_data fsl_lx2160a_r1_devtype_data = { static const struct flexcan_devtype_data fsl_lx2160a_r1_devtype_data = {
.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS | .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_SUPPORT_FD, FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_SUPPORT_FD |
FLEXCAN_QUIRK_SUPPORT_ECC,
}; };
static const struct can_bittiming_const flexcan_bittiming_const = { static const struct can_bittiming_const flexcan_bittiming_const = {
...@@ -2062,6 +2062,8 @@ static int flexcan_remove(struct platform_device *pdev) ...@@ -2062,6 +2062,8 @@ static int flexcan_remove(struct platform_device *pdev)
{ {
struct net_device *dev = platform_get_drvdata(pdev); struct net_device *dev = platform_get_drvdata(pdev);
device_set_wakeup_enable(&pdev->dev, false);
device_set_wakeup_capable(&pdev->dev, false);
unregister_flexcandev(dev); unregister_flexcandev(dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
free_candev(dev); free_candev(dev);
......
...@@ -262,8 +262,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv, ...@@ -262,8 +262,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
cf_len = get_can_dlc(pucan_msg_get_dlc(msg)); cf_len = get_can_dlc(pucan_msg_get_dlc(msg));
/* if this frame is an echo, */ /* if this frame is an echo, */
if ((rx_msg_flags & PUCAN_MSG_LOOPED_BACK) && if (rx_msg_flags & PUCAN_MSG_LOOPED_BACK) {
!(rx_msg_flags & PUCAN_MSG_SELF_RECEIVE)) {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&priv->echo_lock, flags); spin_lock_irqsave(&priv->echo_lock, flags);
...@@ -277,6 +276,12 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv, ...@@ -277,6 +276,12 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
netif_wake_queue(priv->ndev); netif_wake_queue(priv->ndev);
spin_unlock_irqrestore(&priv->echo_lock, flags); spin_unlock_irqrestore(&priv->echo_lock, flags);
/* if this frame is only an echo, stop here. Otherwise,
* continue to push this application self-received frame into
* its own rx queue.
*/
if (!(rx_msg_flags & PUCAN_MSG_SELF_RECEIVE))
return 0; return 0;
} }
......
...@@ -245,7 +245,7 @@ int can_rx_offload_queue_sorted(struct can_rx_offload *offload, ...@@ -245,7 +245,7 @@ int can_rx_offload_queue_sorted(struct can_rx_offload *offload,
if (skb_queue_len(&offload->skb_queue) > if (skb_queue_len(&offload->skb_queue) >
offload->skb_queue_len_max) { offload->skb_queue_len_max) {
kfree_skb(skb); dev_kfree_skb_any(skb);
return -ENOBUFS; return -ENOBUFS;
} }
...@@ -290,7 +290,7 @@ int can_rx_offload_queue_tail(struct can_rx_offload *offload, ...@@ -290,7 +290,7 @@ int can_rx_offload_queue_tail(struct can_rx_offload *offload,
{ {
if (skb_queue_len(&offload->skb_queue) > if (skb_queue_len(&offload->skb_queue) >
offload->skb_queue_len_max) { offload->skb_queue_len_max) {
kfree_skb(skb); dev_kfree_skb_any(skb);
return -ENOBUFS; return -ENOBUFS;
} }
......
...@@ -75,11 +75,11 @@ static const char *__mcp251xfd_get_model_str(enum mcp251xfd_model model) ...@@ -75,11 +75,11 @@ static const char *__mcp251xfd_get_model_str(enum mcp251xfd_model model)
{ {
switch (model) { switch (model) {
case MCP251XFD_MODEL_MCP2517FD: case MCP251XFD_MODEL_MCP2517FD:
return "MCP2517FD"; break; return "MCP2517FD";
case MCP251XFD_MODEL_MCP2518FD: case MCP251XFD_MODEL_MCP2518FD:
return "MCP2518FD"; break; return "MCP2518FD";
case MCP251XFD_MODEL_MCP251XFD: case MCP251XFD_MODEL_MCP251XFD:
return "MCP251xFD"; break; return "MCP251xFD";
} }
return "<unknown>"; return "<unknown>";
...@@ -95,21 +95,21 @@ static const char *mcp251xfd_get_mode_str(const u8 mode) ...@@ -95,21 +95,21 @@ static const char *mcp251xfd_get_mode_str(const u8 mode)
{ {
switch (mode) { switch (mode) {
case MCP251XFD_REG_CON_MODE_MIXED: case MCP251XFD_REG_CON_MODE_MIXED:
return "Mixed (CAN FD/CAN 2.0)"; break; return "Mixed (CAN FD/CAN 2.0)";
case MCP251XFD_REG_CON_MODE_SLEEP: case MCP251XFD_REG_CON_MODE_SLEEP:
return "Sleep"; break; return "Sleep";
case MCP251XFD_REG_CON_MODE_INT_LOOPBACK: case MCP251XFD_REG_CON_MODE_INT_LOOPBACK:
return "Internal Loopback"; break; return "Internal Loopback";
case MCP251XFD_REG_CON_MODE_LISTENONLY: case MCP251XFD_REG_CON_MODE_LISTENONLY:
return "Listen Only"; break; return "Listen Only";
case MCP251XFD_REG_CON_MODE_CONFIG: case MCP251XFD_REG_CON_MODE_CONFIG:
return "Configuration"; break; return "Configuration";
case MCP251XFD_REG_CON_MODE_EXT_LOOPBACK: case MCP251XFD_REG_CON_MODE_EXT_LOOPBACK:
return "External Loopback"; break; return "External Loopback";
case MCP251XFD_REG_CON_MODE_CAN2_0: case MCP251XFD_REG_CON_MODE_CAN2_0:
return "CAN 2.0"; break; return "CAN 2.0";
case MCP251XFD_REG_CON_MODE_RESTRICTED: case MCP251XFD_REG_CON_MODE_RESTRICTED:
return "Restricted Operation"; break; return "Restricted Operation";
} }
return "<unknown>"; return "<unknown>";
......
...@@ -173,7 +173,7 @@ mcp251xfd_regmap_nocrc_read(void *context, ...@@ -173,7 +173,7 @@ mcp251xfd_regmap_nocrc_read(void *context,
memcpy(&buf_tx->cmd, reg, sizeof(buf_tx->cmd)); memcpy(&buf_tx->cmd, reg, sizeof(buf_tx->cmd));
if (MCP251XFD_SANITIZE_SPI) if (MCP251XFD_SANITIZE_SPI)
memset(buf_tx->data, 0x0, val_len); memset(buf_tx->data, 0x0, val_len);
}; }
err = spi_sync(spi, &msg); err = spi_sync(spi, &msg);
if (err) if (err)
...@@ -330,14 +330,14 @@ mcp251xfd_regmap_crc_read(void *context, ...@@ -330,14 +330,14 @@ mcp251xfd_regmap_crc_read(void *context,
goto out; goto out;
} }
netdev_dbg(priv->ndev, netdev_info(priv->ndev,
"CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x) retrying.\n", "CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x) retrying.\n",
reg, val_len, (int)val_len, buf_rx->data, reg, val_len, (int)val_len, buf_rx->data,
get_unaligned_be16(buf_rx->data + val_len)); get_unaligned_be16(buf_rx->data + val_len));
} }
if (err) { if (err) {
netdev_info(priv->ndev, netdev_err(priv->ndev,
"CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x).\n", "CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x).\n",
reg, val_len, (int)val_len, buf_rx->data, reg, val_len, (int)val_len, buf_rx->data,
get_unaligned_be16(buf_rx->data + val_len)); get_unaligned_be16(buf_rx->data + val_len));
......
...@@ -933,7 +933,7 @@ static int ti_hecc_probe(struct platform_device *pdev) ...@@ -933,7 +933,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
err = clk_prepare_enable(priv->clk); err = clk_prepare_enable(priv->clk);
if (err) { if (err) {
dev_err(&pdev->dev, "clk_prepare_enable() failed\n"); dev_err(&pdev->dev, "clk_prepare_enable() failed\n");
goto probe_exit_clk; goto probe_exit_release_clk;
} }
priv->offload.mailbox_read = ti_hecc_mailbox_read; priv->offload.mailbox_read = ti_hecc_mailbox_read;
...@@ -942,7 +942,7 @@ static int ti_hecc_probe(struct platform_device *pdev) ...@@ -942,7 +942,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
err = can_rx_offload_add_timestamp(ndev, &priv->offload); err = can_rx_offload_add_timestamp(ndev, &priv->offload);
if (err) { if (err) {
dev_err(&pdev->dev, "can_rx_offload_add_timestamp() failed\n"); dev_err(&pdev->dev, "can_rx_offload_add_timestamp() failed\n");
goto probe_exit_clk; goto probe_exit_disable_clk;
} }
err = register_candev(ndev); err = register_candev(ndev);
...@@ -960,7 +960,9 @@ static int ti_hecc_probe(struct platform_device *pdev) ...@@ -960,7 +960,9 @@ static int ti_hecc_probe(struct platform_device *pdev)
probe_exit_offload: probe_exit_offload:
can_rx_offload_del(&priv->offload); can_rx_offload_del(&priv->offload);
probe_exit_clk: probe_exit_disable_clk:
clk_disable_unprepare(priv->clk);
probe_exit_release_clk:
clk_put(priv->clk); clk_put(priv->clk);
probe_exit_candev: probe_exit_candev:
free_candev(ndev); free_candev(ndev);
......
...@@ -130,14 +130,55 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time) ...@@ -130,14 +130,55 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)
/* protect from getting time before setting now */ /* protect from getting time before setting now */
if (ktime_to_ns(time_ref->tv_host)) { if (ktime_to_ns(time_ref->tv_host)) {
u64 delta_us; u64 delta_us;
s64 delta_ts = 0;
delta_us = ts - time_ref->ts_dev_2; /* General case: dev_ts_1 < dev_ts_2 < ts, with:
if (ts < time_ref->ts_dev_2) *
delta_us &= (1 << time_ref->adapter->ts_used_bits) - 1; * - dev_ts_1 = previous sync timestamp
* - dev_ts_2 = last sync timestamp
* - ts = event timestamp
* - ts_period = known sync period (theoretical)
* ~ dev_ts2 - dev_ts1
* *but*:
*
* - time counters wrap (see adapter->ts_used_bits)
* - sometimes, dev_ts_1 < ts < dev_ts2
*
* "normal" case (sync time counters increase):
* must take into account case when ts wraps (tsw)
*
* < ts_period > < >
* | | |
* ---+--------+----+-------0-+--+-->
* ts_dev_1 | ts_dev_2 |
* ts tsw
*/
if (time_ref->ts_dev_1 < time_ref->ts_dev_2) {
/* case when event time (tsw) wraps */
if (ts < time_ref->ts_dev_1)
delta_ts = 1 << time_ref->adapter->ts_used_bits;
/* Otherwise, sync time counter (ts_dev_2) has wrapped:
* handle case when event time (tsn) hasn't.
*
* < ts_period > < >
* | | |
* ---+--------+--0-+---------+--+-->
* ts_dev_1 | ts_dev_2 |
* tsn ts
*/
} else if (time_ref->ts_dev_1 < ts) {
delta_ts = -(1 << time_ref->adapter->ts_used_bits);
}
/* add delay between last sync and event timestamps */
delta_ts += (signed int)(ts - time_ref->ts_dev_2);
delta_us += time_ref->ts_total; /* add time from beginning to last sync */
delta_ts += time_ref->ts_total;
delta_us *= time_ref->adapter->us_per_ts_scale; /* convert ticks number into microseconds */
delta_us = delta_ts * time_ref->adapter->us_per_ts_scale;
delta_us >>= time_ref->adapter->us_per_ts_shift; delta_us >>= time_ref->adapter->us_per_ts_shift;
*time = ktime_add_us(time_ref->tv_host_0, delta_us); *time = ktime_add_us(time_ref->tv_host_0, delta_us);
......
...@@ -468,12 +468,18 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if, ...@@ -468,12 +468,18 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,
struct pucan_msg *rx_msg) struct pucan_msg *rx_msg)
{ {
struct pucan_rx_msg *rm = (struct pucan_rx_msg *)rx_msg; struct pucan_rx_msg *rm = (struct pucan_rx_msg *)rx_msg;
struct peak_usb_device *dev = usb_if->dev[pucan_msg_get_channel(rm)]; struct peak_usb_device *dev;
struct net_device *netdev = dev->netdev; struct net_device *netdev;
struct canfd_frame *cfd; struct canfd_frame *cfd;
struct sk_buff *skb; struct sk_buff *skb;
const u16 rx_msg_flags = le16_to_cpu(rm->flags); const u16 rx_msg_flags = le16_to_cpu(rm->flags);
if (pucan_msg_get_channel(rm) >= ARRAY_SIZE(usb_if->dev))
return -ENOMEM;
dev = usb_if->dev[pucan_msg_get_channel(rm)];
netdev = dev->netdev;
if (rx_msg_flags & PUCAN_MSG_EXT_DATA_LEN) { if (rx_msg_flags & PUCAN_MSG_EXT_DATA_LEN) {
/* CANFD frame case */ /* CANFD frame case */
skb = alloc_canfd_skb(netdev, &cfd); skb = alloc_canfd_skb(netdev, &cfd);
...@@ -519,15 +525,21 @@ static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if, ...@@ -519,15 +525,21 @@ static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if,
struct pucan_msg *rx_msg) struct pucan_msg *rx_msg)
{ {
struct pucan_status_msg *sm = (struct pucan_status_msg *)rx_msg; struct pucan_status_msg *sm = (struct pucan_status_msg *)rx_msg;
struct peak_usb_device *dev = usb_if->dev[pucan_stmsg_get_channel(sm)]; struct pcan_usb_fd_device *pdev;
struct pcan_usb_fd_device *pdev =
container_of(dev, struct pcan_usb_fd_device, dev);
enum can_state new_state = CAN_STATE_ERROR_ACTIVE; enum can_state new_state = CAN_STATE_ERROR_ACTIVE;
enum can_state rx_state, tx_state; enum can_state rx_state, tx_state;
struct net_device *netdev = dev->netdev; struct peak_usb_device *dev;
struct net_device *netdev;
struct can_frame *cf; struct can_frame *cf;
struct sk_buff *skb; struct sk_buff *skb;
if (pucan_stmsg_get_channel(sm) >= ARRAY_SIZE(usb_if->dev))
return -ENOMEM;
dev = usb_if->dev[pucan_stmsg_get_channel(sm)];
pdev = container_of(dev, struct pcan_usb_fd_device, dev);
netdev = dev->netdev;
/* nothing should be sent while in BUS_OFF state */ /* nothing should be sent while in BUS_OFF state */
if (dev->can.state == CAN_STATE_BUS_OFF) if (dev->can.state == CAN_STATE_BUS_OFF)
return 0; return 0;
...@@ -579,9 +591,14 @@ static int pcan_usb_fd_decode_error(struct pcan_usb_fd_if *usb_if, ...@@ -579,9 +591,14 @@ static int pcan_usb_fd_decode_error(struct pcan_usb_fd_if *usb_if,
struct pucan_msg *rx_msg) struct pucan_msg *rx_msg)
{ {
struct pucan_error_msg *er = (struct pucan_error_msg *)rx_msg; struct pucan_error_msg *er = (struct pucan_error_msg *)rx_msg;
struct peak_usb_device *dev = usb_if->dev[pucan_ermsg_get_channel(er)]; struct pcan_usb_fd_device *pdev;
struct pcan_usb_fd_device *pdev = struct peak_usb_device *dev;
container_of(dev, struct pcan_usb_fd_device, dev);
if (pucan_ermsg_get_channel(er) >= ARRAY_SIZE(usb_if->dev))
return -EINVAL;
dev = usb_if->dev[pucan_ermsg_get_channel(er)];
pdev = container_of(dev, struct pcan_usb_fd_device, dev);
/* keep a trace of tx and rx error counters for later use */ /* keep a trace of tx and rx error counters for later use */
pdev->bec.txerr = er->tx_err_cnt; pdev->bec.txerr = er->tx_err_cnt;
...@@ -595,11 +612,17 @@ static int pcan_usb_fd_decode_overrun(struct pcan_usb_fd_if *usb_if, ...@@ -595,11 +612,17 @@ static int pcan_usb_fd_decode_overrun(struct pcan_usb_fd_if *usb_if,
struct pucan_msg *rx_msg) struct pucan_msg *rx_msg)
{ {
struct pcan_ufd_ovr_msg *ov = (struct pcan_ufd_ovr_msg *)rx_msg; struct pcan_ufd_ovr_msg *ov = (struct pcan_ufd_ovr_msg *)rx_msg;
struct peak_usb_device *dev = usb_if->dev[pufd_omsg_get_channel(ov)]; struct peak_usb_device *dev;
struct net_device *netdev = dev->netdev; struct net_device *netdev;
struct can_frame *cf; struct can_frame *cf;
struct sk_buff *skb; struct sk_buff *skb;
if (pufd_omsg_get_channel(ov) >= ARRAY_SIZE(usb_if->dev))
return -EINVAL;
dev = usb_if->dev[pufd_omsg_get_channel(ov)];
netdev = dev->netdev;
/* allocate an skb to store the error frame */ /* allocate an skb to store the error frame */
skb = alloc_can_err_skb(netdev, &cf); skb = alloc_can_err_skb(netdev, &cf);
if (!skb) if (!skb)
...@@ -716,6 +739,9 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, ...@@ -716,6 +739,9 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev,
u16 tx_msg_size, tx_msg_flags; u16 tx_msg_size, tx_msg_flags;
u8 can_dlc; u8 can_dlc;
if (cfd->len > CANFD_MAX_DLEN)
return -EINVAL;
tx_msg_size = ALIGN(sizeof(struct pucan_tx_msg) + cfd->len, 4); tx_msg_size = ALIGN(sizeof(struct pucan_tx_msg) + cfd->len, 4);
tx_msg->size = cpu_to_le16(tx_msg_size); tx_msg->size = cpu_to_le16(tx_msg_size);
tx_msg->type = cpu_to_le16(PUCAN_MSG_CAN_TX); tx_msg->type = cpu_to_le16(PUCAN_MSG_CAN_TX);
......
...@@ -1395,7 +1395,7 @@ static int xcan_open(struct net_device *ndev) ...@@ -1395,7 +1395,7 @@ static int xcan_open(struct net_device *ndev)
if (ret < 0) { if (ret < 0) {
netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n", netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
__func__, ret); __func__, ret);
return ret; goto err;
} }
ret = request_irq(ndev->irq, xcan_interrupt, priv->irq_flags, ret = request_irq(ndev->irq, xcan_interrupt, priv->irq_flags,
...@@ -1479,6 +1479,7 @@ static int xcan_get_berr_counter(const struct net_device *ndev, ...@@ -1479,6 +1479,7 @@ static int xcan_get_berr_counter(const struct net_device *ndev,
if (ret < 0) { if (ret < 0) {
netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n", netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
__func__, ret); __func__, ret);
pm_runtime_put(priv->dev);
return ret; return ret;
} }
...@@ -1793,7 +1794,7 @@ static int xcan_probe(struct platform_device *pdev) ...@@ -1793,7 +1794,7 @@ static int xcan_probe(struct platform_device *pdev)
if (ret < 0) { if (ret < 0) {
netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n", netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
__func__, ret); __func__, ret);
goto err_pmdisable; goto err_disableclks;
} }
if (priv->read_reg(priv, XCAN_SR_OFFSET) != XCAN_SR_CONFIG_MASK) { if (priv->read_reg(priv, XCAN_SR_OFFSET) != XCAN_SR_CONFIG_MASK) {
...@@ -1828,7 +1829,6 @@ static int xcan_probe(struct platform_device *pdev) ...@@ -1828,7 +1829,6 @@ static int xcan_probe(struct platform_device *pdev)
err_disableclks: err_disableclks:
pm_runtime_put(priv->dev); pm_runtime_put(priv->dev);
err_pmdisable:
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
err_free: err_free:
free_candev(ndev); free_candev(ndev);
......
...@@ -61,21 +61,17 @@ static inline void can_skb_set_owner(struct sk_buff *skb, struct sock *sk) ...@@ -61,21 +61,17 @@ static inline void can_skb_set_owner(struct sk_buff *skb, struct sock *sk)
*/ */
static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb) static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb)
{ {
if (skb_shared(skb)) { struct sk_buff *nskb;
struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
if (likely(nskb)) { nskb = skb_clone(skb, GFP_ATOMIC);
can_skb_set_owner(nskb, skb->sk); if (unlikely(!nskb)) {
consume_skb(skb);
return nskb;
} else {
kfree_skb(skb); kfree_skb(skb);
return NULL; return NULL;
} }
}
/* we can assume to have an unshared skb with proper owner */ can_skb_set_owner(nskb, skb->sk);
return skb; consume_skb(skb);
return nskb;
} }
#endif /* !_CAN_SKB_H */ #endif /* !_CAN_SKB_H */
...@@ -62,8 +62,9 @@ config CAN_ISOTP ...@@ -62,8 +62,9 @@ config CAN_ISOTP
communication between CAN nodes via two defined CAN Identifiers. communication between CAN nodes via two defined CAN Identifiers.
As CAN frames can only transport a small amount of data bytes 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 (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 segmentation is needed to transport longer Protocol Data Units (PDU)
vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic. as needed e.g. for vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN
traffic.
This protocol driver implements data transfers according to This protocol driver implements data transfers according to
ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types. ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.
If you want to perform automotive vehicle diagnostic services (UDS), If you want to perform automotive vehicle diagnostic services (UDS),
......
...@@ -252,14 +252,16 @@ static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk) ...@@ -252,14 +252,16 @@ static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
static u8 padlen(u8 datalen) static u8 padlen(u8 datalen)
{ {
const u8 plen[] = {8, 8, 8, 8, 8, 8, 8, 8, 8, /* 0 - 8 */ static const u8 plen[] = {
8, 8, 8, 8, 8, 8, 8, 8, 8, /* 0 - 8 */
12, 12, 12, 12, /* 9 - 12 */ 12, 12, 12, 12, /* 9 - 12 */
16, 16, 16, 16, /* 13 - 16 */ 16, 16, 16, 16, /* 13 - 16 */
20, 20, 20, 20, /* 17 - 20 */ 20, 20, 20, 20, /* 17 - 20 */
24, 24, 24, 24, /* 21 - 24 */ 24, 24, 24, 24, /* 21 - 24 */
32, 32, 32, 32, 32, 32, 32, 32, /* 25 - 32 */ 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, /* 33 - 40 */
48, 48, 48, 48, 48, 48, 48, 48}; /* 41 - 48 */ 48, 48, 48, 48, 48, 48, 48, 48 /* 41 - 48 */
};
if (datalen > 48) if (datalen > 48)
return 64; return 64;
...@@ -569,10 +571,6 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae, ...@@ -569,10 +571,6 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
return 0; return 0;
} }
/* no creation of flow control frames */
if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
return 0;
/* perform blocksize handling, if enabled */ /* perform blocksize handling, if enabled */
if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs) { if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs) {
/* start rx timeout watchdog */ /* start rx timeout watchdog */
...@@ -581,6 +579,10 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae, ...@@ -581,6 +579,10 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
return 0; return 0;
} }
/* no creation of flow control frames */
if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
return 0;
/* we reached the specified blocksize so->rxfc.bs */ /* we reached the specified blocksize so->rxfc.bs */
isotp_send_fc(sk, ae, ISOTP_FC_CTS); isotp_send_fc(sk, ae, ISOTP_FC_CTS);
return 0; return 0;
......
...@@ -475,6 +475,12 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len) ...@@ -475,6 +475,12 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
goto out_release_sock; goto out_release_sock;
} }
if (!(ndev->flags & IFF_UP)) {
dev_put(ndev);
ret = -ENETDOWN;
goto out_release_sock;
}
priv = j1939_netdev_start(ndev); priv = j1939_netdev_start(ndev);
dev_put(ndev); dev_put(ndev);
if (IS_ERR(priv)) { if (IS_ERR(priv)) {
......
...@@ -462,6 +462,9 @@ void can_init_proc(struct net *net) ...@@ -462,6 +462,9 @@ void can_init_proc(struct net *net)
*/ */
void can_remove_proc(struct net *net) void can_remove_proc(struct net *net)
{ {
if (!net->can.proc_dir)
return;
if (net->can.pde_stats) if (net->can.pde_stats)
remove_proc_entry(CAN_PROC_STATS, net->can.proc_dir); remove_proc_entry(CAN_PROC_STATS, net->can.proc_dir);
...@@ -486,6 +489,5 @@ void can_remove_proc(struct net *net) ...@@ -486,6 +489,5 @@ void can_remove_proc(struct net *net)
if (net->can.pde_rcvlist_sff) if (net->can.pde_rcvlist_sff)
remove_proc_entry(CAN_PROC_RCVLIST_SFF, net->can.proc_dir); remove_proc_entry(CAN_PROC_RCVLIST_SFF, net->can.proc_dir);
if (net->can.proc_dir)
remove_proc_entry("can", net->proc_net); remove_proc_entry("can", net->proc_net);
} }
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