Commit 2acbeb5d authored by Jakub Kicinski's avatar Jakub Kicinski

Merge tag 'linux-can-next-for-6.4-20230404-2' of...

Merge tag 'linux-can-next-for-6.4-20230404-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

====================
pull-request: can-next 2023-04-04-2

The first patch is by Oliver Hartkopp and makes the maximum pdu size
of the CAN ISOTP protocol configurable.

The following 5 patches are by Dario Binacchi and add support for the
bxCAN controller by ST.

Geert Uytterhoeven's patch for the rcar_canfd driver fixes a sparse
warning.

Peng Fan's patch adds an optional power-domains property to the
flexcan device tree binding.

Frank Jungclaus adds support for CAN_CTRLMODE_BERR_REPORTING to the
esd_usb driver.

The last patch is by Oliver Hartkopp and converts the USB IDs of the
kvaser_usb driver to hexadecimal values.

* tag 'linux-can-next-for-6.4-20230404-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next:
  kvaser_usb: convert USB IDs to hexadecimal values
  can: esd_usb: Add support for CAN_CTRLMODE_BERR_REPORTING
  dt-bindings: can: fsl,flexcan: add optional power-domains property
  can: rcar_canfd: rcar_canfd_probe(): fix plain integer in transceivers[] init
  can: bxcan: add support for ST bxCAN controller
  ARM: dts: stm32: add pin map for CAN controller on stm32f4
  ARM: dts: stm32: add CAN support on stm32f429
  dt-bindings: net: can: add STM32 bxcan DT bindings
  dt-bindings: arm: stm32: add compatible for syscon gcan node
  can: isotp: add module parameter for maximum pdu size
====================

Link: https://lore.kernel.org/r/20230404145908.1714400-1-mkl@pengutronix.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 054fbf7f 1afae605
...@@ -20,6 +20,7 @@ properties: ...@@ -20,6 +20,7 @@ properties:
- st,stm32-syscfg - st,stm32-syscfg
- st,stm32-power-config - st,stm32-power-config
- st,stm32-tamp - st,stm32-tamp
- st,stm32f4-gcan
- const: syscon - const: syscon
- items: - items:
- const: st,stm32-tamp - const: st,stm32-tamp
...@@ -42,6 +43,7 @@ if: ...@@ -42,6 +43,7 @@ if:
contains: contains:
enum: enum:
- st,stm32mp157-syscfg - st,stm32mp157-syscfg
- st,stm32f4-gcan
then: then:
required: required:
- clocks - clocks
......
...@@ -63,6 +63,9 @@ properties: ...@@ -63,6 +63,9 @@ properties:
boot loader. This property should only be used the used operating system boot loader. This property should only be used the used operating system
doesn't support the clocks and clock-names property. doesn't support the clocks and clock-names property.
power-domains:
maxItems: 1
xceiver-supply: xceiver-supply:
description: Regulator that powers the CAN transceiver. description: Regulator that powers the CAN transceiver.
......
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/net/can/st,stm32-bxcan.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: STMicroelectronics bxCAN controller
description: STMicroelectronics BxCAN controller for CAN bus
maintainers:
- Dario Binacchi <dario.binacchi@amarulasolutions.com>
allOf:
- $ref: can-controller.yaml#
properties:
compatible:
enum:
- st,stm32f4-bxcan
st,can-primary:
description:
Primary and secondary mode of the bxCAN peripheral is only relevant
if the chip has two CAN peripherals. In that case they share some
of the required logic.
To avoid misunderstandings, it should be noted that ST documentation
uses the terms master/slave instead of primary/secondary.
type: boolean
reg:
maxItems: 1
interrupts:
items:
- description: transmit interrupt
- description: FIFO 0 receive interrupt
- description: FIFO 1 receive interrupt
- description: status change error interrupt
interrupt-names:
items:
- const: tx
- const: rx0
- const: rx1
- const: sce
resets:
maxItems: 1
clocks:
maxItems: 1
st,gcan:
$ref: /schemas/types.yaml#/definitions/phandle-array
description:
The phandle to the gcan node which allows to access the 512-bytes
SRAM memory shared by the two bxCAN cells (CAN1 primary and CAN2
secondary) in dual CAN peripheral configuration.
required:
- compatible
- reg
- interrupts
- resets
- clocks
- st,gcan
additionalProperties: false
examples:
- |
#include <dt-bindings/clock/stm32fx-clock.h>
#include <dt-bindings/mfd/stm32f4-rcc.h>
can1: can@40006400 {
compatible = "st,stm32f4-bxcan";
reg = <0x40006400 0x200>;
interrupts = <19>, <20>, <21>, <22>;
interrupt-names = "tx", "rx0", "rx1", "sce";
resets = <&rcc STM32F4_APB1_RESET(CAN1)>;
clocks = <&rcc 0 STM32F4_APB1_CLOCK(CAN1)>;
st,can-primary;
st,gcan = <&gcan>;
};
...@@ -4431,6 +4431,13 @@ S: Maintained ...@@ -4431,6 +4431,13 @@ S: Maintained
F: drivers/scsi/BusLogic.* F: drivers/scsi/BusLogic.*
F: drivers/scsi/FlashPoint.* F: drivers/scsi/FlashPoint.*
BXCAN CAN NETWORK DRIVER
M: Dario Binacchi <dario.binacchi@amarulasolutions.com>
L: linux-can@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/net/can/st,stm32-bxcan.yaml
F: drivers/net/can/bxcan.c
C-MEDIA CMI8788 DRIVER C-MEDIA CMI8788 DRIVER
M: Clemens Ladisch <clemens@ladisch.de> M: Clemens Ladisch <clemens@ladisch.de>
L: alsa-devel@alsa-project.org (moderated for non-subscribers) L: alsa-devel@alsa-project.org (moderated for non-subscribers)
......
...@@ -447,6 +447,36 @@ pins2 { ...@@ -447,6 +447,36 @@ pins2 {
slew-rate = <2>; slew-rate = <2>;
}; };
}; };
can1_pins_a: can1-0 {
pins1 {
pinmux = <STM32_PINMUX('B', 9, AF9)>; /* CAN1_TX */
};
pins2 {
pinmux = <STM32_PINMUX('B', 8, AF9)>; /* CAN1_RX */
bias-pull-up;
};
};
can2_pins_a: can2-0 {
pins1 {
pinmux = <STM32_PINMUX('B', 13, AF9)>; /* CAN2_TX */
};
pins2 {
pinmux = <STM32_PINMUX('B', 5, AF9)>; /* CAN2_RX */
bias-pull-up;
};
};
can2_pins_b: can2-1 {
pins1 {
pinmux = <STM32_PINMUX('B', 13, AF9)>; /* CAN2_TX */
};
pins2 {
pinmux = <STM32_PINMUX('B', 12, AF9)>; /* CAN2_RX */
bias-pull-up;
};
};
}; };
}; };
}; };
...@@ -362,6 +362,35 @@ i2c3: i2c@40005c00 { ...@@ -362,6 +362,35 @@ i2c3: i2c@40005c00 {
status = "disabled"; status = "disabled";
}; };
can1: can@40006400 {
compatible = "st,stm32f4-bxcan";
reg = <0x40006400 0x200>;
interrupts = <19>, <20>, <21>, <22>;
interrupt-names = "tx", "rx0", "rx1", "sce";
resets = <&rcc STM32F4_APB1_RESET(CAN1)>;
clocks = <&rcc 0 STM32F4_APB1_CLOCK(CAN1)>;
st,can-primary;
st,gcan = <&gcan>;
status = "disabled";
};
gcan: gcan@40006600 {
compatible = "st,stm32f4-gcan", "syscon";
reg = <0x40006600 0x200>;
clocks = <&rcc 0 STM32F4_APB1_CLOCK(CAN1)>;
};
can2: can@40006800 {
compatible = "st,stm32f4-bxcan";
reg = <0x40006800 0x200>;
interrupts = <63>, <64>, <65>, <66>;
interrupt-names = "tx", "rx0", "rx1", "sce";
resets = <&rcc STM32F4_APB1_RESET(CAN2)>;
clocks = <&rcc 0 STM32F4_APB1_CLOCK(CAN2)>;
st,gcan = <&gcan>;
status = "disabled";
};
dac: dac@40007400 { dac: dac@40007400 {
compatible = "st,stm32f4-dac-core"; compatible = "st,stm32f4-dac-core";
reg = <0x40007400 0x400>; reg = <0x40007400 0x400>;
......
...@@ -93,6 +93,18 @@ config CAN_AT91 ...@@ -93,6 +93,18 @@ config CAN_AT91
This is a driver for the SoC CAN controller in Atmel's AT91SAM9263 This is a driver for the SoC CAN controller in Atmel's AT91SAM9263
and AT91SAM9X5 processors. and AT91SAM9X5 processors.
config CAN_BXCAN
tristate "STM32 Basic Extended CAN (bxCAN) devices"
depends on OF || ARCH_STM32 || COMPILE_TEST
depends on HAS_IOMEM
select CAN_RX_OFFLOAD
help
Say yes here to build support for the STMicroelectronics STM32 basic
extended CAN Controller (bxCAN).
This driver can also be built as a module. If so, the module
will be called bxcan.
config CAN_CAN327 config CAN_CAN327
tristate "Serial / USB serial ELM327 based OBD-II Interfaces (can327)" tristate "Serial / USB serial ELM327 based OBD-II Interfaces (can327)"
depends on TTY depends on TTY
......
...@@ -14,6 +14,7 @@ obj-y += usb/ ...@@ -14,6 +14,7 @@ obj-y += usb/
obj-y += softing/ obj-y += softing/
obj-$(CONFIG_CAN_AT91) += at91_can.o obj-$(CONFIG_CAN_AT91) += at91_can.o
obj-$(CONFIG_CAN_BXCAN) += bxcan.o
obj-$(CONFIG_CAN_CAN327) += can327.o obj-$(CONFIG_CAN_CAN327) += can327.o
obj-$(CONFIG_CAN_CC770) += cc770/ obj-$(CONFIG_CAN_CC770) += cc770/
obj-$(CONFIG_CAN_C_CAN) += c_can/ obj-$(CONFIG_CAN_C_CAN) += c_can/
......
This diff is collapsed.
...@@ -1848,7 +1848,7 @@ static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch) ...@@ -1848,7 +1848,7 @@ static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch)
static int rcar_canfd_probe(struct platform_device *pdev) static int rcar_canfd_probe(struct platform_device *pdev)
{ {
struct phy *transceivers[RCANFD_NUM_CHANNELS] = { 0, }; struct phy *transceivers[RCANFD_NUM_CHANNELS] = { NULL, };
const struct rcar_canfd_hw_info *info; const struct rcar_canfd_hw_info *info;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
void __iomem *addr; void __iomem *addr;
......
...@@ -237,14 +237,23 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, ...@@ -237,14 +237,23 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
if (id == ESD_EV_CAN_ERROR_EXT) { if (id == ESD_EV_CAN_ERROR_EXT) {
u8 state = msg->rx.ev_can_err_ext.status; u8 state = msg->rx.ev_can_err_ext.status;
u8 ecc = msg->rx.ev_can_err_ext.ecc; u8 ecc = msg->rx.ev_can_err_ext.ecc;
u8 rxerr = msg->rx.ev_can_err_ext.rec;
u8 txerr = msg->rx.ev_can_err_ext.tec; priv->bec.rxerr = msg->rx.ev_can_err_ext.rec;
priv->bec.txerr = msg->rx.ev_can_err_ext.tec;
netdev_dbg(priv->netdev, netdev_dbg(priv->netdev,
"CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n", "CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n",
msg->rx.dlc, state, ecc, rxerr, txerr); msg->rx.dlc, state, ecc,
priv->bec.rxerr, priv->bec.txerr);
/* if berr-reporting is off, only pass through on state change ... */
if (!(priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) &&
state == priv->old_state)
return;
skb = alloc_can_err_skb(priv->netdev, &cf); skb = alloc_can_err_skb(priv->netdev, &cf);
if (!skb)
stats->rx_dropped++;
if (state != priv->old_state) { if (state != priv->old_state) {
enum can_state tx_state, rx_state; enum can_state tx_state, rx_state;
...@@ -265,14 +274,14 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, ...@@ -265,14 +274,14 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
break; break;
default: default:
new_state = CAN_STATE_ERROR_ACTIVE; new_state = CAN_STATE_ERROR_ACTIVE;
txerr = 0; priv->bec.txerr = 0;
rxerr = 0; priv->bec.rxerr = 0;
break; break;
} }
if (new_state != priv->can.state) { if (new_state != priv->can.state) {
tx_state = (txerr >= rxerr) ? new_state : 0; tx_state = (priv->bec.txerr >= priv->bec.rxerr) ? new_state : 0;
rx_state = (txerr <= rxerr) ? new_state : 0; rx_state = (priv->bec.txerr <= priv->bec.rxerr) ? new_state : 0;
can_change_state(priv->netdev, cf, can_change_state(priv->netdev, cf,
tx_state, rx_state); tx_state, rx_state);
} }
...@@ -304,17 +313,12 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, ...@@ -304,17 +313,12 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
cf->data[3] = ecc & SJA1000_ECC_SEG; cf->data[3] = ecc & SJA1000_ECC_SEG;
} }
priv->bec.txerr = txerr;
priv->bec.rxerr = rxerr;
if (skb) { if (skb) {
cf->can_id |= CAN_ERR_CNT; cf->can_id |= CAN_ERR_CNT;
cf->data[6] = txerr; cf->data[6] = priv->bec.txerr;
cf->data[7] = rxerr; cf->data[7] = priv->bec.rxerr;
netif_rx(skb); netif_rx(skb);
} else {
stats->rx_dropped++;
} }
} }
} }
...@@ -1016,7 +1020,8 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index) ...@@ -1016,7 +1020,8 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
priv->can.state = CAN_STATE_STOPPED; priv->can.state = CAN_STATE_STOPPED;
priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
CAN_CTRLMODE_CC_LEN8_DLC; CAN_CTRLMODE_CC_LEN8_DLC |
CAN_CTRLMODE_BERR_REPORTING;
if (le16_to_cpu(dev->udev->descriptor.idProduct) == if (le16_to_cpu(dev->udev->descriptor.idProduct) ==
USB_CANUSBM_PRODUCT_ID) USB_CANUSBM_PRODUCT_ID)
......
...@@ -31,63 +31,63 @@ ...@@ -31,63 +31,63 @@
#include "kvaser_usb.h" #include "kvaser_usb.h"
/* Kvaser USB vendor id. */ /* Kvaser USB vendor id. */
#define KVASER_VENDOR_ID 0x0bfd #define KVASER_VENDOR_ID 0x0bfd
/* Kvaser Leaf USB devices product ids */ /* Kvaser Leaf USB devices product ids */
#define USB_LEAF_DEVEL_PRODUCT_ID 10 #define USB_LEAF_DEVEL_PRODUCT_ID 0x000a
#define USB_LEAF_LITE_PRODUCT_ID 11 #define USB_LEAF_LITE_PRODUCT_ID 0x000b
#define USB_LEAF_PRO_PRODUCT_ID 12 #define USB_LEAF_PRO_PRODUCT_ID 0x000c
#define USB_LEAF_SPRO_PRODUCT_ID 14 #define USB_LEAF_SPRO_PRODUCT_ID 0x000e
#define USB_LEAF_PRO_LS_PRODUCT_ID 15 #define USB_LEAF_PRO_LS_PRODUCT_ID 0x000f
#define USB_LEAF_PRO_SWC_PRODUCT_ID 16 #define USB_LEAF_PRO_SWC_PRODUCT_ID 0x0010
#define USB_LEAF_PRO_LIN_PRODUCT_ID 17 #define USB_LEAF_PRO_LIN_PRODUCT_ID 0x0011
#define USB_LEAF_SPRO_LS_PRODUCT_ID 18 #define USB_LEAF_SPRO_LS_PRODUCT_ID 0x0012
#define USB_LEAF_SPRO_SWC_PRODUCT_ID 19 #define USB_LEAF_SPRO_SWC_PRODUCT_ID 0x0013
#define USB_MEMO2_DEVEL_PRODUCT_ID 22 #define USB_MEMO2_DEVEL_PRODUCT_ID 0x0016
#define USB_MEMO2_HSHS_PRODUCT_ID 23 #define USB_MEMO2_HSHS_PRODUCT_ID 0x0017
#define USB_UPRO_HSHS_PRODUCT_ID 24 #define USB_UPRO_HSHS_PRODUCT_ID 0x0018
#define USB_LEAF_LITE_GI_PRODUCT_ID 25 #define USB_LEAF_LITE_GI_PRODUCT_ID 0x0019
#define USB_LEAF_PRO_OBDII_PRODUCT_ID 26 #define USB_LEAF_PRO_OBDII_PRODUCT_ID 0x001a
#define USB_MEMO2_HSLS_PRODUCT_ID 27 #define USB_MEMO2_HSLS_PRODUCT_ID 0x001b
#define USB_LEAF_LITE_CH_PRODUCT_ID 28 #define USB_LEAF_LITE_CH_PRODUCT_ID 0x001c
#define USB_BLACKBIRD_SPRO_PRODUCT_ID 29 #define USB_BLACKBIRD_SPRO_PRODUCT_ID 0x001d
#define USB_OEM_MERCURY_PRODUCT_ID 34 #define USB_OEM_MERCURY_PRODUCT_ID 0x0022
#define USB_OEM_LEAF_PRODUCT_ID 35 #define USB_OEM_LEAF_PRODUCT_ID 0x0023
#define USB_CAN_R_PRODUCT_ID 39 #define USB_CAN_R_PRODUCT_ID 0x0027
#define USB_LEAF_LITE_V2_PRODUCT_ID 288 #define USB_LEAF_LITE_V2_PRODUCT_ID 0x0120
#define USB_MINI_PCIE_HS_PRODUCT_ID 289 #define USB_MINI_PCIE_HS_PRODUCT_ID 0x0121
#define USB_LEAF_LIGHT_HS_V2_OEM_PRODUCT_ID 290 #define USB_LEAF_LIGHT_HS_V2_OEM_PRODUCT_ID 0x0122
#define USB_USBCAN_LIGHT_2HS_PRODUCT_ID 291 #define USB_USBCAN_LIGHT_2HS_PRODUCT_ID 0x0123
#define USB_MINI_PCIE_2HS_PRODUCT_ID 292 #define USB_MINI_PCIE_2HS_PRODUCT_ID 0x0124
#define USB_USBCAN_R_V2_PRODUCT_ID 294 #define USB_USBCAN_R_V2_PRODUCT_ID 0x0126
#define USB_LEAF_LIGHT_R_V2_PRODUCT_ID 295 #define USB_LEAF_LIGHT_R_V2_PRODUCT_ID 0x0127
#define USB_LEAF_LIGHT_HS_V2_OEM2_PRODUCT_ID 296 #define USB_LEAF_LIGHT_HS_V2_OEM2_PRODUCT_ID 0x0128
/* Kvaser USBCan-II devices product ids */ /* Kvaser USBCan-II devices product ids */
#define USB_USBCAN_REVB_PRODUCT_ID 2 #define USB_USBCAN_REVB_PRODUCT_ID 0x0002
#define USB_VCI2_PRODUCT_ID 3 #define USB_VCI2_PRODUCT_ID 0x0003
#define USB_USBCAN2_PRODUCT_ID 4 #define USB_USBCAN2_PRODUCT_ID 0x0004
#define USB_MEMORATOR_PRODUCT_ID 5 #define USB_MEMORATOR_PRODUCT_ID 0x0005
/* Kvaser Minihydra USB devices product ids */ /* Kvaser Minihydra USB devices product ids */
#define USB_BLACKBIRD_V2_PRODUCT_ID 258 #define USB_BLACKBIRD_V2_PRODUCT_ID 0x0102
#define USB_MEMO_PRO_5HS_PRODUCT_ID 260 #define USB_MEMO_PRO_5HS_PRODUCT_ID 0x0104
#define USB_USBCAN_PRO_5HS_PRODUCT_ID 261 #define USB_USBCAN_PRO_5HS_PRODUCT_ID 0x0105
#define USB_USBCAN_LIGHT_4HS_PRODUCT_ID 262 #define USB_USBCAN_LIGHT_4HS_PRODUCT_ID 0x0106
#define USB_LEAF_PRO_HS_V2_PRODUCT_ID 263 #define USB_LEAF_PRO_HS_V2_PRODUCT_ID 0x0107
#define USB_USBCAN_PRO_2HS_V2_PRODUCT_ID 264 #define USB_USBCAN_PRO_2HS_V2_PRODUCT_ID 0x0108
#define USB_MEMO_2HS_PRODUCT_ID 265 #define USB_MEMO_2HS_PRODUCT_ID 0x0109
#define USB_MEMO_PRO_2HS_V2_PRODUCT_ID 266 #define USB_MEMO_PRO_2HS_V2_PRODUCT_ID 0x010a
#define USB_HYBRID_2CANLIN_PRODUCT_ID 267 #define USB_HYBRID_2CANLIN_PRODUCT_ID 0x010b
#define USB_ATI_USBCAN_PRO_2HS_V2_PRODUCT_ID 268 #define USB_ATI_USBCAN_PRO_2HS_V2_PRODUCT_ID 0x010c
#define USB_ATI_MEMO_PRO_2HS_V2_PRODUCT_ID 269 #define USB_ATI_MEMO_PRO_2HS_V2_PRODUCT_ID 0x010d
#define USB_HYBRID_PRO_2CANLIN_PRODUCT_ID 270 #define USB_HYBRID_PRO_2CANLIN_PRODUCT_ID 0x010e
#define USB_U100_PRODUCT_ID 273 #define USB_U100_PRODUCT_ID 0x0111
#define USB_U100P_PRODUCT_ID 274 #define USB_U100P_PRODUCT_ID 0x0112
#define USB_U100S_PRODUCT_ID 275 #define USB_U100S_PRODUCT_ID 0x0113
#define USB_USBCAN_PRO_4HS_PRODUCT_ID 276 #define USB_USBCAN_PRO_4HS_PRODUCT_ID 0x0114
#define USB_HYBRID_CANLIN_PRODUCT_ID 277 #define USB_HYBRID_CANLIN_PRODUCT_ID 0x0115
#define USB_HYBRID_PRO_CANLIN_PRODUCT_ID 278 #define USB_HYBRID_PRO_CANLIN_PRODUCT_ID 0x0116
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_hydra = { static const struct kvaser_usb_driver_info kvaser_usb_driver_info_hydra = {
.quirks = KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP, .quirks = KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP,
......
...@@ -85,10 +85,21 @@ MODULE_ALIAS("can-proto-6"); ...@@ -85,10 +85,21 @@ MODULE_ALIAS("can-proto-6");
/* ISO 15765-2:2016 supports more than 4095 byte per ISO PDU as the FF_DL can /* 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 * 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 * this between user space and kernel space. For now set the static buffer to
* to something about 64 kbyte to be able to test this new functionality. * something about 8 kbyte to be able to test this new functionality.
*/ */
#define MAX_MSG_LENGTH 66000 #define DEFAULT_MAX_PDU_SIZE 8300
/* maximum PDU size before ISO 15765-2:2016 extension was 4095 */
#define MAX_12BIT_PDU_SIZE 4095
/* limit the isotp pdu size from the optional module parameter to 1MByte */
#define MAX_PDU_SIZE (1025 * 1024U)
static unsigned int max_pdu_size __read_mostly = DEFAULT_MAX_PDU_SIZE;
module_param(max_pdu_size, uint, 0444);
MODULE_PARM_DESC(max_pdu_size, "maximum isotp pdu size (default "
__stringify(DEFAULT_MAX_PDU_SIZE) ")");
/* N_PCI type values in bits 7-4 of N_PCI bytes */ /* N_PCI type values in bits 7-4 of N_PCI bytes */
#define N_PCI_SF 0x00 /* single frame */ #define N_PCI_SF 0x00 /* single frame */
...@@ -123,13 +134,15 @@ enum { ...@@ -123,13 +134,15 @@ enum {
}; };
struct tpcon { struct tpcon {
unsigned int idx; u8 *buf;
unsigned int buflen;
unsigned int len; unsigned int len;
unsigned int idx;
u32 state; u32 state;
u8 bs; u8 bs;
u8 sn; u8 sn;
u8 ll_dl; u8 ll_dl;
u8 buf[MAX_MSG_LENGTH + 1]; u8 sbuf[DEFAULT_MAX_PDU_SIZE];
}; };
struct isotp_sock { struct isotp_sock {
...@@ -503,7 +516,17 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae) ...@@ -503,7 +516,17 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl) if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl)
return 1; return 1;
if (so->rx.len > MAX_MSG_LENGTH) { /* PDU size > default => try max_pdu_size */
if (so->rx.len > so->rx.buflen && so->rx.buflen < max_pdu_size) {
u8 *newbuf = kmalloc(max_pdu_size, GFP_ATOMIC);
if (newbuf) {
so->rx.buf = newbuf;
so->rx.buflen = max_pdu_size;
}
}
if (so->rx.len > so->rx.buflen) {
/* send FC frame with overflow status */ /* send FC frame with overflow status */
isotp_send_fc(sk, ae, ISOTP_FC_OVFLW); isotp_send_fc(sk, ae, ISOTP_FC_OVFLW);
return 1; return 1;
...@@ -807,7 +830,7 @@ static void isotp_create_fframe(struct canfd_frame *cf, struct isotp_sock *so, ...@@ -807,7 +830,7 @@ static void isotp_create_fframe(struct canfd_frame *cf, struct isotp_sock *so,
cf->data[0] = so->opt.ext_address; cf->data[0] = so->opt.ext_address;
/* create N_PCI bytes with 12/32 bit FF_DL data length */ /* create N_PCI bytes with 12/32 bit FF_DL data length */
if (so->tx.len > 4095) { if (so->tx.len > MAX_12BIT_PDU_SIZE) {
/* use 32 bit FF_DL notation */ /* use 32 bit FF_DL notation */
cf->data[ae] = N_PCI_FF; cf->data[ae] = N_PCI_FF;
cf->data[ae + 1] = 0; cf->data[ae + 1] = 0;
...@@ -947,7 +970,17 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) ...@@ -947,7 +970,17 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
so->tx.state = ISOTP_SENDING; so->tx.state = ISOTP_SENDING;
} }
if (!size || size > MAX_MSG_LENGTH) { /* PDU size > default => try max_pdu_size */
if (size > so->tx.buflen && so->tx.buflen < max_pdu_size) {
u8 *newbuf = kmalloc(max_pdu_size, GFP_KERNEL);
if (newbuf) {
so->tx.buf = newbuf;
so->tx.buflen = max_pdu_size;
}
}
if (!size || size > so->tx.buflen) {
err = -EINVAL; err = -EINVAL;
goto err_out_drop; goto err_out_drop;
} }
...@@ -1195,6 +1228,12 @@ static int isotp_release(struct socket *sock) ...@@ -1195,6 +1228,12 @@ static int isotp_release(struct socket *sock)
so->ifindex = 0; so->ifindex = 0;
so->bound = 0; so->bound = 0;
if (so->rx.buf != so->rx.sbuf)
kfree(so->rx.buf);
if (so->tx.buf != so->tx.sbuf)
kfree(so->tx.buf);
sock_orphan(sk); sock_orphan(sk);
sock->sk = NULL; sock->sk = NULL;
...@@ -1591,6 +1630,11 @@ static int isotp_init(struct sock *sk) ...@@ -1591,6 +1630,11 @@ static int isotp_init(struct sock *sk)
so->rx.state = ISOTP_IDLE; so->rx.state = ISOTP_IDLE;
so->tx.state = ISOTP_IDLE; so->tx.state = ISOTP_IDLE;
so->rx.buf = so->rx.sbuf;
so->tx.buf = so->tx.sbuf;
so->rx.buflen = ARRAY_SIZE(so->rx.sbuf);
so->tx.buflen = ARRAY_SIZE(so->tx.sbuf);
hrtimer_init(&so->rxtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); hrtimer_init(&so->rxtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
so->rxtimer.function = isotp_rx_timer_handler; so->rxtimer.function = isotp_rx_timer_handler;
hrtimer_init(&so->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); hrtimer_init(&so->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
...@@ -1658,7 +1702,10 @@ static __init int isotp_module_init(void) ...@@ -1658,7 +1702,10 @@ static __init int isotp_module_init(void)
{ {
int err; int err;
pr_info("can: isotp protocol\n"); max_pdu_size = max_t(unsigned int, max_pdu_size, MAX_12BIT_PDU_SIZE);
max_pdu_size = min_t(unsigned int, max_pdu_size, MAX_PDU_SIZE);
pr_info("can: isotp protocol (max_pdu_size %d)\n", max_pdu_size);
err = can_proto_register(&isotp_can_proto); err = can_proto_register(&isotp_can_proto);
if (err < 0) if (err < 0)
......
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