Skip to content

Commit 7e8c182

Browse files
committed
Merge tag 'linux-can-fixes-for-5.19-20220704' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== can 2022-07-04 The 1st patch is by Oliver Hartkopp, targets the BCM CAN protocol and converts a costly synchronize_rcu() to call_rcu() to fix a performance regression. Srinivas Neeli's patch for the xilinx_can driver drops the brp limit down to 1, as only the pre-production silicon have an issue with a brp of 1. The next patch is by Duy Nguyen and fixes the data transmission on R-Car V3U SoCs in the rcar_canfd driver. Rhett Aultman's patch fixes a DMA memory leak in the gs_usb driver. Liang He's patch removes an extra of_node_get() in the grcan driver. The next 2 patches are by me, target the m_can driver and fix the timestamp handling used for peripheral devices like the tcan4x5x. Jimmy Assarsson contributes 3 patches for the kvaser_usb driver and fixes CAN clock and bit timing related issues. The remaining 5 patches target the mcp251xfd driver. Thomas Kopp contributes 2 patches to improve the workaround for broken CRC when reading the TBC register. 3 patches by me add a missing hrtimer_cancel() during the ndo_stop() callback, and fix the reading of the Device ID register. * tag 'linux-can-fixes-for-5.19-20220704' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: mcp251xfd: mcp251xfd_register_get_dev_id(): fix endianness conversion can: mcp251xfd: mcp251xfd_register_get_dev_id(): use correct length to read dev_id can: mcp251xfd: mcp251xfd_stop(): add missing hrtimer_cancel() can: mcp251xfd: mcp251xfd_regmap_crc_read(): update workaround broken CRC on TBC register can: mcp251xfd: mcp251xfd_regmap_crc_read(): improve workaround handling for mcp2517fd can: kvaser_usb: kvaser_usb_leaf: fix bittiming limits can: kvaser_usb: kvaser_usb_leaf: fix CAN clock frequency regression can: kvaser_usb: replace run-time checks with struct kvaser_usb_driver_info can: m_can: m_can_{read_fifo,echo_tx_event}(): shift timestamp to full 32 bits can: m_can: m_can_chip_config(): actually enable internal timestamping can: grcan: grcan_probe(): remove extra of_node_get() can: gs_usb: gs_usb_open/close(): fix memory leak can: rcar_canfd: Fix data transmission failed on R-Car V3U Revert "can: xilinx_can: Limit CANFD brp to 2" can: bcm: use call_rcu() instead of costly synchronize_rcu() ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 1b18f09 + 1c0e78a commit 7e8c182

File tree

12 files changed

+304
-216
lines changed

12 files changed

+304
-216
lines changed

drivers/net/can/grcan.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,6 @@ static int grcan_probe(struct platform_device *ofdev)
16461646
*/
16471647
sysid_parent = of_find_node_by_path("/ambapp0");
16481648
if (sysid_parent) {
1649-
of_node_get(sysid_parent);
16501649
err = of_property_read_u32(sysid_parent, "systemid", &sysid);
16511650
if (!err && ((sysid & GRLIB_VERSION_MASK) >=
16521651
GRCAN_TXBUG_SAFE_GRLIB_VERSION))

drivers/net/can/m_can/m_can.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
529529
/* acknowledge rx fifo 0 */
530530
m_can_write(cdev, M_CAN_RXF0A, fgi);
531531

532-
timestamp = FIELD_GET(RX_BUF_RXTS_MASK, fifo_header.dlc);
532+
timestamp = FIELD_GET(RX_BUF_RXTS_MASK, fifo_header.dlc) << 16;
533533

534534
m_can_receive_skb(cdev, skb, timestamp);
535535

@@ -1030,7 +1030,7 @@ static int m_can_echo_tx_event(struct net_device *dev)
10301030
}
10311031

10321032
msg_mark = FIELD_GET(TX_EVENT_MM_MASK, txe);
1033-
timestamp = FIELD_GET(TX_EVENT_TXTS_MASK, txe);
1033+
timestamp = FIELD_GET(TX_EVENT_TXTS_MASK, txe) << 16;
10341034

10351035
/* ack txe element */
10361036
m_can_write(cdev, M_CAN_TXEFA, FIELD_PREP(TXEFA_EFAI_MASK,
@@ -1351,7 +1351,9 @@ static void m_can_chip_config(struct net_device *dev)
13511351
/* enable internal timestamp generation, with a prescalar of 16. The
13521352
* prescalar is applied to the nominal bit timing
13531353
*/
1354-
m_can_write(cdev, M_CAN_TSCC, FIELD_PREP(TSCC_TCP_MASK, 0xf));
1354+
m_can_write(cdev, M_CAN_TSCC,
1355+
FIELD_PREP(TSCC_TCP_MASK, 0xf) |
1356+
FIELD_PREP(TSCC_TSS_MASK, TSCC_TSS_INTERNAL));
13551357

13561358
m_can_config_endisable(cdev, false);
13571359

drivers/net/can/rcar/rcar_canfd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,10 @@ static void rcar_canfd_set_bittiming(struct net_device *dev)
13321332
cfg = (RCANFD_DCFG_DTSEG1(gpriv, tseg1) | RCANFD_DCFG_DBRP(brp) |
13331333
RCANFD_DCFG_DSJW(sjw) | RCANFD_DCFG_DTSEG2(gpriv, tseg2));
13341334

1335-
rcar_canfd_write(priv->base, RCANFD_F_DCFG(ch), cfg);
1335+
if (is_v3u(gpriv))
1336+
rcar_canfd_write(priv->base, RCANFD_V3U_DCFG(ch), cfg);
1337+
else
1338+
rcar_canfd_write(priv->base, RCANFD_F_DCFG(ch), cfg);
13361339
netdev_dbg(priv->ndev, "drate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n",
13371340
brp, sjw, tseg1, tseg2);
13381341
} else {

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// Copyright (c) 2019 Martin Sperl <[email protected]>
1313
//
1414

15+
#include <asm/unaligned.h>
1516
#include <linux/bitfield.h>
1617
#include <linux/clk.h>
1718
#include <linux/device.h>
@@ -1650,6 +1651,7 @@ static int mcp251xfd_stop(struct net_device *ndev)
16501651
netif_stop_queue(ndev);
16511652
set_bit(MCP251XFD_FLAGS_DOWN, priv->flags);
16521653
hrtimer_cancel(&priv->rx_irq_timer);
1654+
hrtimer_cancel(&priv->tx_irq_timer);
16531655
mcp251xfd_chip_interrupts_disable(priv);
16541656
free_irq(ndev->irq, priv);
16551657
can_rx_offload_disable(&priv->offload);
@@ -1777,7 +1779,7 @@ mcp251xfd_register_get_dev_id(const struct mcp251xfd_priv *priv, u32 *dev_id,
17771779
xfer[0].len = sizeof(buf_tx->cmd);
17781780
xfer[0].speed_hz = priv->spi_max_speed_hz_slow;
17791781
xfer[1].rx_buf = buf_rx->data;
1780-
xfer[1].len = sizeof(dev_id);
1782+
xfer[1].len = sizeof(*dev_id);
17811783
xfer[1].speed_hz = priv->spi_max_speed_hz_fast;
17821784

17831785
mcp251xfd_spi_cmd_read_nocrc(&buf_tx->cmd, MCP251XFD_REG_DEVID);
@@ -1786,7 +1788,7 @@ mcp251xfd_register_get_dev_id(const struct mcp251xfd_priv *priv, u32 *dev_id,
17861788
if (err)
17871789
goto out_kfree_buf_tx;
17881790

1789-
*dev_id = be32_to_cpup((__be32 *)buf_rx->data);
1791+
*dev_id = get_unaligned_le32(buf_rx->data);
17901792
*effective_speed_hz_slow = xfer[0].effective_speed_hz;
17911793
*effective_speed_hz_fast = xfer[1].effective_speed_hz;
17921794

drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,21 @@ mcp251xfd_regmap_crc_read(void *context,
334334
* register. It increments once per SYS clock tick,
335335
* which is 20 or 40 MHz.
336336
*
337-
* Observation shows that if the lowest byte (which is
338-
* transferred first on the SPI bus) of that register
339-
* is 0x00 or 0x80 the calculated CRC doesn't always
340-
* match the transferred one.
337+
* Observation on the mcp2518fd shows that if the
338+
* lowest byte (which is transferred first on the SPI
339+
* bus) of that register is 0x00 or 0x80 the
340+
* calculated CRC doesn't always match the transferred
341+
* one. On the mcp2517fd this problem is not limited
342+
* to the first byte being 0x00 or 0x80.
341343
*
342344
* If the highest bit in the lowest byte is flipped
343345
* the transferred CRC matches the calculated one. We
344-
* assume for now the CRC calculation in the chip
345-
* works on wrong data and the transferred data is
346-
* correct.
346+
* assume for now the CRC operates on the correct
347+
* data.
347348
*/
348349
if (reg == MCP251XFD_REG_TBC &&
349-
(buf_rx->data[0] == 0x0 || buf_rx->data[0] == 0x80)) {
350+
((buf_rx->data[0] & 0xf8) == 0x0 ||
351+
(buf_rx->data[0] & 0xf8) == 0x80)) {
350352
/* Flip highest bit in lowest byte of le32 */
351353
buf_rx->data[0] ^= 0x80;
352354

@@ -356,10 +358,8 @@ mcp251xfd_regmap_crc_read(void *context,
356358
val_len);
357359
if (!err) {
358360
/* If CRC is now correct, assume
359-
* transferred data was OK, flip bit
360-
* back to original value.
361+
* flipped data is OK.
361362
*/
362-
buf_rx->data[0] ^= 0x80;
363363
goto out;
364364
}
365365
}

drivers/net/can/usb/gs_usb.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ struct gs_can {
268268

269269
struct usb_anchor tx_submitted;
270270
atomic_t active_tx_urbs;
271+
void *rxbuf[GS_MAX_RX_URBS];
272+
dma_addr_t rxbuf_dma[GS_MAX_RX_URBS];
271273
};
272274

273275
/* usb interface struct */
@@ -742,6 +744,7 @@ static int gs_can_open(struct net_device *netdev)
742744
for (i = 0; i < GS_MAX_RX_URBS; i++) {
743745
struct urb *urb;
744746
u8 *buf;
747+
dma_addr_t buf_dma;
745748

746749
/* alloc rx urb */
747750
urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -752,14 +755,16 @@ static int gs_can_open(struct net_device *netdev)
752755
buf = usb_alloc_coherent(dev->udev,
753756
dev->parent->hf_size_rx,
754757
GFP_KERNEL,
755-
&urb->transfer_dma);
758+
&buf_dma);
756759
if (!buf) {
757760
netdev_err(netdev,
758761
"No memory left for USB buffer\n");
759762
usb_free_urb(urb);
760763
return -ENOMEM;
761764
}
762765

766+
urb->transfer_dma = buf_dma;
767+
763768
/* fill, anchor, and submit rx urb */
764769
usb_fill_bulk_urb(urb,
765770
dev->udev,
@@ -781,10 +786,17 @@ static int gs_can_open(struct net_device *netdev)
781786
"usb_submit failed (err=%d)\n", rc);
782787

783788
usb_unanchor_urb(urb);
789+
usb_free_coherent(dev->udev,
790+
sizeof(struct gs_host_frame),
791+
buf,
792+
buf_dma);
784793
usb_free_urb(urb);
785794
break;
786795
}
787796

797+
dev->rxbuf[i] = buf;
798+
dev->rxbuf_dma[i] = buf_dma;
799+
788800
/* Drop reference,
789801
* USB core will take care of freeing it
790802
*/
@@ -842,13 +854,20 @@ static int gs_can_close(struct net_device *netdev)
842854
int rc;
843855
struct gs_can *dev = netdev_priv(netdev);
844856
struct gs_usb *parent = dev->parent;
857+
unsigned int i;
845858

846859
netif_stop_queue(netdev);
847860

848861
/* Stop polling */
849862
parent->active_channels--;
850-
if (!parent->active_channels)
863+
if (!parent->active_channels) {
851864
usb_kill_anchored_urbs(&parent->rx_submitted);
865+
for (i = 0; i < GS_MAX_RX_URBS; i++)
866+
usb_free_coherent(dev->udev,
867+
sizeof(struct gs_host_frame),
868+
dev->rxbuf[i],
869+
dev->rxbuf_dma[i]);
870+
}
852871

853872
/* Stop sending URBs */
854873
usb_kill_anchored_urbs(&dev->tx_submitted);

drivers/net/can/usb/kvaser_usb/kvaser_usb.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
#define KVASER_USB_RX_BUFFER_SIZE 3072
3636
#define KVASER_USB_MAX_NET_DEVICES 5
3737

38-
/* USB devices features */
39-
#define KVASER_USB_HAS_SILENT_MODE BIT(0)
40-
#define KVASER_USB_HAS_TXRX_ERRORS BIT(1)
38+
/* Kvaser USB device quirks */
39+
#define KVASER_USB_QUIRK_HAS_SILENT_MODE BIT(0)
40+
#define KVASER_USB_QUIRK_HAS_TXRX_ERRORS BIT(1)
41+
#define KVASER_USB_QUIRK_IGNORE_CLK_FREQ BIT(2)
4142

4243
/* Device capabilities */
4344
#define KVASER_USB_CAP_BERR_CAP 0x01
@@ -65,12 +66,7 @@ struct kvaser_usb_dev_card_data_hydra {
6566
struct kvaser_usb_dev_card_data {
6667
u32 ctrlmode_supported;
6768
u32 capabilities;
68-
union {
69-
struct {
70-
enum kvaser_usb_leaf_family family;
71-
} leaf;
72-
struct kvaser_usb_dev_card_data_hydra hydra;
73-
};
69+
struct kvaser_usb_dev_card_data_hydra hydra;
7470
};
7571

7672
/* Context for an outstanding, not yet ACKed, transmission */
@@ -83,7 +79,7 @@ struct kvaser_usb {
8379
struct usb_device *udev;
8480
struct usb_interface *intf;
8581
struct kvaser_usb_net_priv *nets[KVASER_USB_MAX_NET_DEVICES];
86-
const struct kvaser_usb_dev_ops *ops;
82+
const struct kvaser_usb_driver_info *driver_info;
8783
const struct kvaser_usb_dev_cfg *cfg;
8884

8985
struct usb_endpoint_descriptor *bulk_in, *bulk_out;
@@ -165,6 +161,12 @@ struct kvaser_usb_dev_ops {
165161
u16 transid);
166162
};
167163

164+
struct kvaser_usb_driver_info {
165+
u32 quirks;
166+
enum kvaser_usb_leaf_family family;
167+
const struct kvaser_usb_dev_ops *ops;
168+
};
169+
168170
struct kvaser_usb_dev_cfg {
169171
const struct can_clock clock;
170172
const unsigned int timestamp_freq;
@@ -184,4 +186,7 @@ int kvaser_usb_send_cmd_async(struct kvaser_usb_net_priv *priv, void *cmd,
184186
int len);
185187

186188
int kvaser_usb_can_rx_over_error(struct net_device *netdev);
189+
190+
extern const struct can_bittiming_const kvaser_usb_flexc_bittiming_const;
191+
187192
#endif /* KVASER_USB_H */

0 commit comments

Comments
 (0)