Skip to content

Commit 5e655aa

Browse files
committed
Merge tag 'linux-can-fixes-for-6.18-20251014' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2025-10-14 The first 2 paches are by Celeste Liu and target the gS_usb driver. The first patch remove the limitation to 3 CAN interface per USB device. The second patch adds the missing population of net_device->dev_port. The next 4 patches are by me and fix the m_can driver. They add a missing pm_runtime_disable(), fix the CAN state transition back to Error Active and fix the state after ifup and suspend/resume. Another patch by me targets the m_can driver, too and replaces Dong Aisheng's old email address. The next 2 patches are by Vincent Mailhol and update the CAN networking Documentation. Tetsuo Handa contributes the last patch that add missing cleanup calls in the NETDEV_UNREGISTER notification handler. * tag 'linux-can-fixes-for-6.18-20251014' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: j1939: add missing calls in NETDEV_UNREGISTER notification handler can: add Transmitter Delay Compensation (TDC) documentation can: remove false statement about 1:1 mapping between DLC and length can: m_can: replace Dong Aisheng's old email address can: m_can: fix CAN state in system PM can: m_can: m_can_chip_config(): bring up interface in correct state can: m_can: m_can_handle_state_errors(): fix CAN state transition to Error Active can: m_can: m_can_plat_remove(): add missing pm_runtime_disable() can: gs_usb: gs_make_candev(): populate net_device->dev_port can: gs_usb: increase max interface to U8_MAX ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 1a8fed5 + 93a27b5 commit 5e655aa

File tree

6 files changed

+122
-47
lines changed

6 files changed

+122
-47
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Dmitry Safonov <[email protected]> <[email protected]>
227227
228228
229229
Domen Puncer <[email protected]>
230+
230231
Douglas Gilbert <[email protected]>
231232
232233

Documentation/networking/can.rst

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,10 +1398,9 @@ second bit timing has to be specified in order to enable the CAN FD bitrate.
13981398
Additionally CAN FD capable CAN controllers support up to 64 bytes of
13991399
payload. The representation of this length in can_frame.len and
14001400
canfd_frame.len for userspace applications and inside the Linux network
1401-
layer is a plain value from 0 .. 64 instead of the CAN 'data length code'.
1402-
The data length code was a 1:1 mapping to the payload length in the Classical
1403-
CAN frames anyway. The payload length to the bus-relevant DLC mapping is
1404-
only performed inside the CAN drivers, preferably with the helper
1401+
layer is a plain value from 0 .. 64 instead of the Classical CAN length
1402+
which ranges from 0 to 8. The payload length to the bus-relevant DLC mapping
1403+
is only performed inside the CAN drivers, preferably with the helper
14051404
functions can_fd_dlc2len() and can_fd_len2dlc().
14061405

14071406
The CAN netdevice driver capabilities can be distinguished by the network
@@ -1465,6 +1464,70 @@ Example when 'fd-non-iso on' is added on this switchable CAN FD adapter::
14651464
can <FD,FD-NON-ISO> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
14661465

14671466

1467+
Transmitter Delay Compensation
1468+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1469+
1470+
At high bit rates, the propagation delay from the TX pin to the RX pin of
1471+
the transceiver might become greater than the actual bit time causing
1472+
measurement errors: the RX pin would still be measuring the previous bit.
1473+
1474+
The Transmitter Delay Compensation (thereafter, TDC) resolves this problem
1475+
by introducing a Secondary Sample Point (SSP) equal to the distance, in
1476+
minimum time quantum, from the start of the bit time on the TX pin to the
1477+
actual measurement on the RX pin. The SSP is calculated as the sum of two
1478+
configurable values: the TDC Value (TDCV) and the TDC offset (TDCO).
1479+
1480+
TDC, if supported by the device, can be configured together with CAN-FD
1481+
using the ip tool's "tdc-mode" argument as follow:
1482+
1483+
**omitted**
1484+
When no "tdc-mode" option is provided, the kernel will automatically
1485+
decide whether TDC should be turned on, in which case it will
1486+
calculate a default TDCO and use the TDCV as measured by the
1487+
device. This is the recommended method to use TDC.
1488+
1489+
**"tdc-mode off"**
1490+
TDC is explicitly disabled.
1491+
1492+
**"tdc-mode auto"**
1493+
The user must provide the "tdco" argument. The TDCV will be
1494+
automatically calculated by the device. This option is only
1495+
available if the device supports the TDC-AUTO CAN controller mode.
1496+
1497+
**"tdc-mode manual"**
1498+
The user must provide both the "tdco" and "tdcv" arguments. This
1499+
option is only available if the device supports the TDC-MANUAL CAN
1500+
controller mode.
1501+
1502+
Note that some devices may offer an additional parameter: "tdcf" (TDC Filter
1503+
window). If supported by your device, this can be added as an optional
1504+
argument to either "tdc-mode auto" or "tdc-mode manual".
1505+
1506+
Example configuring a 500 kbit/s arbitration bitrate, a 5 Mbit/s data
1507+
bitrate, a TDCO of 15 minimum time quantum and a TDCV automatically measured
1508+
by the device::
1509+
1510+
$ ip link set can0 up type can bitrate 500000 \
1511+
fd on dbitrate 4000000 \
1512+
tdc-mode auto tdco 15
1513+
$ ip -details link show can0
1514+
5: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP \
1515+
mode DEFAULT group default qlen 10
1516+
link/can promiscuity 0 allmulti 0 minmtu 72 maxmtu 72
1517+
can <FD,TDC-AUTO> state ERROR-ACTIVE restart-ms 0
1518+
bitrate 500000 sample-point 0.875
1519+
tq 12 prop-seg 69 phase-seg1 70 phase-seg2 20 sjw 10 brp 1
1520+
ES582.1/ES584.1: tseg1 2..256 tseg2 2..128 sjw 1..128 brp 1..512 \
1521+
brp_inc 1
1522+
dbitrate 4000000 dsample-point 0.750
1523+
dtq 12 dprop-seg 7 dphase-seg1 7 dphase-seg2 5 dsjw 2 dbrp 1
1524+
tdco 15 tdcf 0
1525+
ES582.1/ES584.1: dtseg1 2..32 dtseg2 1..16 dsjw 1..8 dbrp 1..32 \
1526+
dbrp_inc 1
1527+
tdco 0..127 tdcf 0..127
1528+
clock 80000000
1529+
1530+
14681531
Supported CAN Hardware
14691532
----------------------
14701533

drivers/net/can/m_can/m_can.c

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// CAN bus driver for Bosch M_CAN controller
33
// Copyright (C) 2014 Freescale Semiconductor, Inc.
4-
// Dong Aisheng <b29396@freescale.com>
4+
// Dong Aisheng <aisheng.dong@nxp.com>
55
// Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
66

77
/* Bosch M_CAN user manual can be obtained from:
@@ -812,6 +812,9 @@ static int m_can_handle_state_change(struct net_device *dev,
812812
u32 timestamp = 0;
813813

814814
switch (new_state) {
815+
case CAN_STATE_ERROR_ACTIVE:
816+
cdev->can.state = CAN_STATE_ERROR_ACTIVE;
817+
break;
815818
case CAN_STATE_ERROR_WARNING:
816819
/* error warning state */
817820
cdev->can.can_stats.error_warning++;
@@ -841,6 +844,12 @@ static int m_can_handle_state_change(struct net_device *dev,
841844
__m_can_get_berr_counter(dev, &bec);
842845

843846
switch (new_state) {
847+
case CAN_STATE_ERROR_ACTIVE:
848+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
849+
cf->data[1] = CAN_ERR_CRTL_ACTIVE;
850+
cf->data[6] = bec.txerr;
851+
cf->data[7] = bec.rxerr;
852+
break;
844853
case CAN_STATE_ERROR_WARNING:
845854
/* error warning state */
846855
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
@@ -877,30 +886,33 @@ static int m_can_handle_state_change(struct net_device *dev,
877886
return 1;
878887
}
879888

880-
static int m_can_handle_state_errors(struct net_device *dev, u32 psr)
889+
static enum can_state
890+
m_can_state_get_by_psr(struct m_can_classdev *cdev)
881891
{
882-
struct m_can_classdev *cdev = netdev_priv(dev);
883-
int work_done = 0;
892+
u32 reg_psr;
884893

885-
if (psr & PSR_EW && cdev->can.state != CAN_STATE_ERROR_WARNING) {
886-
netdev_dbg(dev, "entered error warning state\n");
887-
work_done += m_can_handle_state_change(dev,
888-
CAN_STATE_ERROR_WARNING);
889-
}
894+
reg_psr = m_can_read(cdev, M_CAN_PSR);
890895

891-
if (psr & PSR_EP && cdev->can.state != CAN_STATE_ERROR_PASSIVE) {
892-
netdev_dbg(dev, "entered error passive state\n");
893-
work_done += m_can_handle_state_change(dev,
894-
CAN_STATE_ERROR_PASSIVE);
895-
}
896+
if (reg_psr & PSR_BO)
897+
return CAN_STATE_BUS_OFF;
898+
if (reg_psr & PSR_EP)
899+
return CAN_STATE_ERROR_PASSIVE;
900+
if (reg_psr & PSR_EW)
901+
return CAN_STATE_ERROR_WARNING;
896902

897-
if (psr & PSR_BO && cdev->can.state != CAN_STATE_BUS_OFF) {
898-
netdev_dbg(dev, "entered error bus off state\n");
899-
work_done += m_can_handle_state_change(dev,
900-
CAN_STATE_BUS_OFF);
901-
}
903+
return CAN_STATE_ERROR_ACTIVE;
904+
}
902905

903-
return work_done;
906+
static int m_can_handle_state_errors(struct net_device *dev)
907+
{
908+
struct m_can_classdev *cdev = netdev_priv(dev);
909+
enum can_state new_state;
910+
911+
new_state = m_can_state_get_by_psr(cdev);
912+
if (new_state == cdev->can.state)
913+
return 0;
914+
915+
return m_can_handle_state_change(dev, new_state);
904916
}
905917

906918
static void m_can_handle_other_err(struct net_device *dev, u32 irqstatus)
@@ -1031,8 +1043,7 @@ static int m_can_rx_handler(struct net_device *dev, int quota, u32 irqstatus)
10311043
}
10321044

10331045
if (irqstatus & IR_ERR_STATE)
1034-
work_done += m_can_handle_state_errors(dev,
1035-
m_can_read(cdev, M_CAN_PSR));
1046+
work_done += m_can_handle_state_errors(dev);
10361047

10371048
if (irqstatus & IR_ERR_BUS_30X)
10381049
work_done += m_can_handle_bus_errors(dev, irqstatus,
@@ -1606,7 +1617,7 @@ static int m_can_start(struct net_device *dev)
16061617
netdev_queue_set_dql_min_limit(netdev_get_tx_queue(cdev->net, 0),
16071618
cdev->tx_max_coalesced_frames);
16081619

1609-
cdev->can.state = CAN_STATE_ERROR_ACTIVE;
1620+
cdev->can.state = m_can_state_get_by_psr(cdev);
16101621

16111622
m_can_enable_all_interrupts(cdev);
16121623

@@ -2492,12 +2503,11 @@ int m_can_class_suspend(struct device *dev)
24922503
}
24932504

24942505
m_can_clk_stop(cdev);
2506+
cdev->can.state = CAN_STATE_SLEEPING;
24952507
}
24962508

24972509
pinctrl_pm_select_sleep_state(dev);
24982510

2499-
cdev->can.state = CAN_STATE_SLEEPING;
2500-
25012511
return ret;
25022512
}
25032513
EXPORT_SYMBOL_GPL(m_can_class_suspend);
@@ -2510,8 +2520,6 @@ int m_can_class_resume(struct device *dev)
25102520

25112521
pinctrl_pm_select_default_state(dev);
25122522

2513-
cdev->can.state = CAN_STATE_ERROR_ACTIVE;
2514-
25152523
if (netif_running(ndev)) {
25162524
ret = m_can_clk_start(cdev);
25172525
if (ret)
@@ -2529,6 +2537,8 @@ int m_can_class_resume(struct device *dev)
25292537
if (cdev->ops->init)
25302538
ret = cdev->ops->init(cdev);
25312539

2540+
cdev->can.state = m_can_state_get_by_psr(cdev);
2541+
25322542
m_can_write(cdev, M_CAN_IE, cdev->active_interrupts);
25332543
} else {
25342544
ret = m_can_start(ndev);
@@ -2546,7 +2556,7 @@ int m_can_class_resume(struct device *dev)
25462556
}
25472557
EXPORT_SYMBOL_GPL(m_can_class_resume);
25482558

2549-
MODULE_AUTHOR("Dong Aisheng <b29396@freescale.com>");
2559+
MODULE_AUTHOR("Dong Aisheng <aisheng.dong@nxp.com>");
25502560
MODULE_AUTHOR("Dan Murphy <[email protected]>");
25512561
MODULE_LICENSE("GPL v2");
25522562
MODULE_DESCRIPTION("CAN bus driver for Bosch M_CAN controller");

drivers/net/can/m_can/m_can_platform.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// IOMapped CAN bus driver for Bosch M_CAN controller
33
// Copyright (C) 2014 Freescale Semiconductor, Inc.
4-
// Dong Aisheng <b29396@freescale.com>
4+
// Dong Aisheng <aisheng.dong@nxp.com>
55
//
66
// Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
77

@@ -180,7 +180,7 @@ static void m_can_plat_remove(struct platform_device *pdev)
180180
struct m_can_classdev *mcan_class = &priv->cdev;
181181

182182
m_can_class_unregister(mcan_class);
183-
183+
pm_runtime_disable(mcan_class->dev);
184184
m_can_class_free_dev(mcan_class->net);
185185
}
186186

@@ -236,7 +236,7 @@ static struct platform_driver m_can_plat_driver = {
236236

237237
module_platform_driver(m_can_plat_driver);
238238

239-
MODULE_AUTHOR("Dong Aisheng <b29396@freescale.com>");
239+
MODULE_AUTHOR("Dong Aisheng <aisheng.dong@nxp.com>");
240240
MODULE_AUTHOR("Dan Murphy <[email protected]>");
241241
MODULE_LICENSE("GPL v2");
242242
MODULE_DESCRIPTION("M_CAN driver for IO Mapped Bosch controllers");

drivers/net/can/usb/gs_usb.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ struct gs_host_frame {
289289
#define GS_MAX_RX_URBS 30
290290
#define GS_NAPI_WEIGHT 32
291291

292-
/* Maximum number of interfaces the driver supports per device.
293-
* Current hardware only supports 3 interfaces. The future may vary.
294-
*/
295-
#define GS_MAX_INTF 3
296-
297292
struct gs_tx_context {
298293
struct gs_can *dev;
299294
unsigned int echo_id;
@@ -324,7 +319,6 @@ struct gs_can {
324319

325320
/* usb interface struct */
326321
struct gs_usb {
327-
struct gs_can *canch[GS_MAX_INTF];
328322
struct usb_anchor rx_submitted;
329323
struct usb_device *udev;
330324

@@ -336,9 +330,11 @@ struct gs_usb {
336330

337331
unsigned int hf_size_rx;
338332
u8 active_channels;
333+
u8 channel_cnt;
339334

340335
unsigned int pipe_in;
341336
unsigned int pipe_out;
337+
struct gs_can *canch[] __counted_by(channel_cnt);
342338
};
343339

344340
/* 'allocate' a tx context.
@@ -599,7 +595,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
599595
}
600596

601597
/* device reports out of range channel id */
602-
if (hf->channel >= GS_MAX_INTF)
598+
if (hf->channel >= parent->channel_cnt)
603599
goto device_detach;
604600

605601
dev = parent->canch[hf->channel];
@@ -699,7 +695,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
699695
/* USB failure take down all interfaces */
700696
if (rc == -ENODEV) {
701697
device_detach:
702-
for (rc = 0; rc < GS_MAX_INTF; rc++) {
698+
for (rc = 0; rc < parent->channel_cnt; rc++) {
703699
if (parent->canch[rc])
704700
netif_device_detach(parent->canch[rc]->netdev);
705701
}
@@ -1249,6 +1245,7 @@ static struct gs_can *gs_make_candev(unsigned int channel,
12491245

12501246
netdev->flags |= IFF_ECHO; /* we support full roundtrip echo */
12511247
netdev->dev_id = channel;
1248+
netdev->dev_port = channel;
12521249

12531250
/* dev setup */
12541251
strcpy(dev->bt_const.name, KBUILD_MODNAME);
@@ -1460,17 +1457,19 @@ static int gs_usb_probe(struct usb_interface *intf,
14601457
icount = dconf.icount + 1;
14611458
dev_info(&intf->dev, "Configuring for %u interfaces\n", icount);
14621459

1463-
if (icount > GS_MAX_INTF) {
1460+
if (icount > type_max(parent->channel_cnt)) {
14641461
dev_err(&intf->dev,
14651462
"Driver cannot handle more that %u CAN interfaces\n",
1466-
GS_MAX_INTF);
1463+
type_max(parent->channel_cnt));
14671464
return -EINVAL;
14681465
}
14691466

1470-
parent = kzalloc(sizeof(*parent), GFP_KERNEL);
1467+
parent = kzalloc(struct_size(parent, canch, icount), GFP_KERNEL);
14711468
if (!parent)
14721469
return -ENOMEM;
14731470

1471+
parent->channel_cnt = icount;
1472+
14741473
init_usb_anchor(&parent->rx_submitted);
14751474

14761475
usb_set_intfdata(intf, parent);
@@ -1531,7 +1530,7 @@ static void gs_usb_disconnect(struct usb_interface *intf)
15311530
return;
15321531
}
15331532

1534-
for (i = 0; i < GS_MAX_INTF; i++)
1533+
for (i = 0; i < parent->channel_cnt; i++)
15351534
if (parent->canch[i])
15361535
gs_destroy_candev(parent->canch[i]);
15371536

net/can/j1939/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ static int j1939_netdev_notify(struct notifier_block *nb,
378378
j1939_ecu_unmap_all(priv);
379379
break;
380380
case NETDEV_UNREGISTER:
381+
j1939_cancel_active_session(priv, NULL);
382+
j1939_sk_netdev_event_netdown(priv);
381383
j1939_sk_netdev_event_unregister(priv);
382384
break;
383385
}

0 commit comments

Comments
 (0)