Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

linux-can-next-for-6.6-20230728

Marc Kleine-Budde says:

====================
Hello netdev-team,

this is a pull request of 21 patches for net-next/master.

The 1st patch is by Gerhard Uttenthaler, which adds Gerhard as the
maintainer ems_pci driver.

Peter Seiderer's patch removes a unused function from the peak_usb
driver.

The next 4 patches are by John Watts and add support for the sun4i_can
driver on the Allwinner D1.

Rob Herring's patch corrects the DT includes in various CAN drivers.

Followed by 14 patches from me concerning the gs_usb driver. The first
11 are various cleanups consisting of coding style improvements, error
path printout cleanups, and removal of unneeded
usb_kill_anchored_urbs(). The last 3 convert the driver to use NAPI to
avoid out-of-order reception of CAN frames.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+225 -124
+4 -2
Documentation/devicetree/bindings/net/can/allwinner,sun4i-a10-can.yaml
··· 21 21 - const: allwinner,sun4i-a10-can 22 22 - const: allwinner,sun4i-a10-can 23 23 - const: allwinner,sun8i-r40-can 24 + - const: allwinner,sun20i-d1-can 24 25 25 26 reg: 26 27 maxItems: 1 ··· 38 37 if: 39 38 properties: 40 39 compatible: 41 - contains: 42 - const: allwinner,sun8i-r40-can 40 + enum: 41 + - allwinner,sun8i-r40-can 42 + - allwinner,sun20i-d1-can 43 43 44 44 then: 45 45 required:
+7
MAINTAINERS
··· 7606 7606 S: Supported 7607 7607 F: drivers/mmc/host/cqhci* 7608 7608 7609 + EMS CPC-PCI CAN DRIVER 7610 + M: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com> 7611 + M: support@ems-wuensche.com 7612 + L: linux-can@vger.kernel.org 7613 + S: Maintained 7614 + F: drivers/net/can/sja1000/ems_pci.c 7615 + 7609 7616 EMULEX 10Gbps iSCSI - OneConnect DRIVER 7610 7617 M: Ketan Mukadam <ketan.mukadam@broadcom.com> 7611 7618 L: linux-scsi@vger.kernel.org
+30
arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi
··· 131 131 pins = "PB6", "PB7"; 132 132 function = "uart3"; 133 133 }; 134 + 135 + /omit-if-no-ref/ 136 + can0_pins: can0-pins { 137 + pins = "PB2", "PB3"; 138 + function = "can0"; 139 + }; 140 + 141 + /omit-if-no-ref/ 142 + can1_pins: can1-pins { 143 + pins = "PB4", "PB5"; 144 + function = "can1"; 145 + }; 134 146 }; 135 147 136 148 ccu: clock-controller@2001000 { ··· 890 878 <&r_ccu CLK_R_AHB>; 891 879 clock-names = "bus", "hosc", "ahb"; 892 880 #clock-cells = <1>; 881 + }; 882 + 883 + can0: can@2504000 { 884 + compatible = "allwinner,sun20i-d1-can"; 885 + reg = <0x02504000 0x400>; 886 + interrupts = <SOC_PERIPHERAL_IRQ(21) IRQ_TYPE_LEVEL_HIGH>; 887 + clocks = <&ccu CLK_BUS_CAN0>; 888 + resets = <&ccu RST_BUS_CAN0>; 889 + status = "disabled"; 890 + }; 891 + 892 + can1: can@2504400 { 893 + compatible = "allwinner,sun20i-d1-can"; 894 + reg = <0x02504400 0x400>; 895 + interrupts = <SOC_PERIPHERAL_IRQ(22) IRQ_TYPE_LEVEL_HIGH>; 896 + clocks = <&ccu CLK_BUS_CAN1>; 897 + resets = <&ccu RST_BUS_CAN1>; 898 + status = "disabled"; 893 899 }; 894 900 }; 895 901 };
+2 -2
drivers/net/can/Kconfig
··· 190 190 191 191 config CAN_SUN4I 192 192 tristate "Allwinner A10 CAN controller" 193 - depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST 193 + depends on MACH_SUN4I || MACH_SUN7I || RISCV || COMPILE_TEST 194 194 help 195 195 Say Y here if you want to use CAN controller found on Allwinner 196 - A10/A20 SoCs. 196 + A10/A20/D1 SoCs. 197 197 198 198 To compile this driver as a module, choose M here: the module will 199 199 be called sun4i_can.
-1
drivers/net/can/bxcan.c
··· 23 23 #include <linux/mfd/syscon.h> 24 24 #include <linux/module.h> 25 25 #include <linux/of.h> 26 - #include <linux/of_device.h> 27 26 #include <linux/platform_device.h> 28 27 #include <linux/regmap.h> 29 28
+31 -5
drivers/net/can/dev/rx-offload.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* Copyright (c) 2014 Protonic Holland, 3 3 * David Jander 4 - * Copyright (C) 2014-2021 Pengutronix, 4 + * Copyright (C) 2014-2021, 2023 Pengutronix, 5 5 * Marc Kleine-Budde <kernel@pengutronix.de> 6 6 */ 7 7 ··· 240 240 } 241 241 EXPORT_SYMBOL_GPL(can_rx_offload_queue_timestamp); 242 242 243 - unsigned int can_rx_offload_get_echo_skb(struct can_rx_offload *offload, 244 - unsigned int idx, u32 timestamp, 245 - unsigned int *frame_len_ptr) 243 + unsigned int 244 + can_rx_offload_get_echo_skb_queue_timestamp(struct can_rx_offload *offload, 245 + unsigned int idx, u32 timestamp, 246 + unsigned int *frame_len_ptr) 246 247 { 247 248 struct net_device *dev = offload->dev; 248 249 struct net_device_stats *stats = &dev->stats; ··· 263 262 264 263 return len; 265 264 } 266 - EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb); 265 + EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb_queue_timestamp); 267 266 268 267 int can_rx_offload_queue_tail(struct can_rx_offload *offload, 269 268 struct sk_buff *skb) ··· 279 278 return 0; 280 279 } 281 280 EXPORT_SYMBOL_GPL(can_rx_offload_queue_tail); 281 + 282 + unsigned int 283 + can_rx_offload_get_echo_skb_queue_tail(struct can_rx_offload *offload, 284 + unsigned int idx, 285 + unsigned int *frame_len_ptr) 286 + { 287 + struct net_device *dev = offload->dev; 288 + struct net_device_stats *stats = &dev->stats; 289 + struct sk_buff *skb; 290 + unsigned int len; 291 + int err; 292 + 293 + skb = __can_get_echo_skb(dev, idx, &len, frame_len_ptr); 294 + if (!skb) 295 + return 0; 296 + 297 + err = can_rx_offload_queue_tail(offload, skb); 298 + if (err) { 299 + stats->rx_errors++; 300 + stats->tx_fifo_errors++; 301 + } 302 + 303 + return len; 304 + } 305 + EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb_queue_tail); 282 306 283 307 void can_rx_offload_irq_finish(struct can_rx_offload *offload) 284 308 {
+2 -2
drivers/net/can/flexcan/flexcan-core.c
··· 1097 1097 1098 1098 handled = IRQ_HANDLED; 1099 1099 stats->tx_bytes += 1100 - can_rx_offload_get_echo_skb(&priv->offload, 0, 1101 - reg_ctrl << 16, NULL); 1100 + can_rx_offload_get_echo_skb_queue_timestamp(&priv->offload, 0, 1101 + reg_ctrl << 16, NULL); 1102 1102 stats->tx_packets++; 1103 1103 1104 1104 /* after sending a RTR frame MB is in RX mode */
-1
drivers/net/can/ifi_canfd/ifi_canfd.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/netdevice.h> 22 22 #include <linux/of.h> 23 - #include <linux/of_device.h> 24 23 #include <linux/platform_device.h> 25 24 26 25 #include <linux/can/dev.h>
+4 -5
drivers/net/can/m_can/m_can.c
··· 19 19 #include <linux/module.h> 20 20 #include <linux/netdevice.h> 21 21 #include <linux/of.h> 22 - #include <linux/of_device.h> 23 22 #include <linux/phy/phy.h> 24 23 #include <linux/pinctrl/consumer.h> 25 24 #include <linux/platform_device.h> ··· 1016 1017 1017 1018 if (cdev->is_peripheral) 1018 1019 stats->tx_bytes += 1019 - can_rx_offload_get_echo_skb(&cdev->offload, 1020 - msg_mark, 1021 - timestamp, 1022 - NULL); 1020 + can_rx_offload_get_echo_skb_queue_timestamp(&cdev->offload, 1021 + msg_mark, 1022 + timestamp, 1023 + NULL); 1023 1024 else 1024 1025 stats->tx_bytes += can_get_echo_skb(dev, msg_mark, NULL); 1025 1026
-1
drivers/net/can/m_can/m_can.h
··· 23 23 #include <linux/module.h> 24 24 #include <linux/netdevice.h> 25 25 #include <linux/of.h> 26 - #include <linux/of_device.h> 27 26 #include <linux/phy/phy.h> 28 27 #include <linux/pinctrl/consumer.h> 29 28 #include <linux/pm_runtime.h>
-1
drivers/net/can/rcar/rcar_canfd.c
··· 34 34 #include <linux/moduleparam.h> 35 35 #include <linux/netdevice.h> 36 36 #include <linux/of.h> 37 - #include <linux/of_device.h> 38 37 #include <linux/phy/phy.h> 39 38 #include <linux/platform_device.h> 40 39 #include <linux/reset.h>
-1
drivers/net/can/sja1000/sja1000_platform.c
··· 17 17 #include <linux/clk.h> 18 18 #include <linux/io.h> 19 19 #include <linux/of.h> 20 - #include <linux/of_device.h> 21 20 22 21 #include "sja1000.h" 23 22
+3 -3
drivers/net/can/spi/mcp251xfd/mcp251xfd-tef.c
··· 111 111 if (skb) 112 112 mcp251xfd_skb_set_timestamp(priv, skb, hw_tef_obj->ts); 113 113 stats->tx_bytes += 114 - can_rx_offload_get_echo_skb(&priv->offload, 115 - tef_tail, hw_tef_obj->ts, 116 - frame_len_ptr); 114 + can_rx_offload_get_echo_skb_queue_timestamp(&priv->offload, 115 + tef_tail, hw_tef_obj->ts, 116 + frame_len_ptr); 117 117 stats->tx_packets++; 118 118 priv->tef->tail++; 119 119
+19 -4
drivers/net/can/sun4i_can.c
··· 59 59 #include <linux/io.h> 60 60 #include <linux/module.h> 61 61 #include <linux/of.h> 62 - #include <linux/of_device.h> 63 62 #include <linux/platform_device.h> 64 63 #include <linux/reset.h> 65 64 ··· 90 91 #define SUN4I_REG_BUF12_ADDR 0x0070 /* CAN Tx/Rx Buffer 12 */ 91 92 #define SUN4I_REG_ACPC_ADDR 0x0040 /* CAN Acceptance Code 0 */ 92 93 #define SUN4I_REG_ACPM_ADDR 0x0044 /* CAN Acceptance Mask 0 */ 94 + #define SUN4I_REG_ACPC_ADDR_D1 0x0028 /* CAN Acceptance Code 0 on the D1 */ 95 + #define SUN4I_REG_ACPM_ADDR_D1 0x002C /* CAN Acceptance Mask 0 on the D1 */ 93 96 #define SUN4I_REG_RBUF_RBACK_START_ADDR 0x0180 /* CAN transmit buffer start */ 94 97 #define SUN4I_REG_RBUF_RBACK_END_ADDR 0x01b0 /* CAN transmit buffer end */ 95 98 ··· 206 205 * struct sun4ican_quirks - Differences between SoC variants. 207 206 * 208 207 * @has_reset: SoC needs reset deasserted. 208 + * @acp_offset: Offset of ACPC and ACPM registers 209 209 */ 210 210 struct sun4ican_quirks { 211 211 bool has_reset; 212 + int acp_offset; 212 213 }; 213 214 214 215 struct sun4ican_priv { ··· 219 216 struct clk *clk; 220 217 struct reset_control *reset; 221 218 spinlock_t cmdreg_lock; /* lock for concurrent cmd register writes */ 219 + int acp_offset; 222 220 }; 223 221 224 222 static const struct can_bittiming_const sun4ican_bittiming_const = { ··· 342 338 } 343 339 344 340 /* set filters - we accept all */ 345 - writel(0x00000000, priv->base + SUN4I_REG_ACPC_ADDR); 346 - writel(0xFFFFFFFF, priv->base + SUN4I_REG_ACPM_ADDR); 341 + writel(0x00000000, priv->base + SUN4I_REG_ACPC_ADDR + priv->acp_offset); 342 + writel(0xFFFFFFFF, priv->base + SUN4I_REG_ACPM_ADDR + priv->acp_offset); 347 343 348 344 /* clear error counters and error code capture */ 349 345 writel(0, priv->base + SUN4I_REG_ERRC_ADDR); ··· 772 768 773 769 static const struct sun4ican_quirks sun4ican_quirks_a10 = { 774 770 .has_reset = false, 771 + .acp_offset = 0, 775 772 }; 776 773 777 774 static const struct sun4ican_quirks sun4ican_quirks_r40 = { 778 775 .has_reset = true, 776 + .acp_offset = 0, 777 + }; 778 + 779 + static const struct sun4ican_quirks sun4ican_quirks_d1 = { 780 + .has_reset = true, 781 + .acp_offset = (SUN4I_REG_ACPC_ADDR_D1 - SUN4I_REG_ACPC_ADDR), 779 782 }; 780 783 781 784 static const struct of_device_id sun4ican_of_match[] = { ··· 795 784 }, { 796 785 .compatible = "allwinner,sun8i-r40-can", 797 786 .data = &sun4ican_quirks_r40 787 + }, { 788 + .compatible = "allwinner,sun20i-d1-can", 789 + .data = &sun4ican_quirks_d1 798 790 }, { 799 791 /* sentinel */ 800 792 }, ··· 884 870 priv->base = addr; 885 871 priv->clk = clk; 886 872 priv->reset = reset; 873 + priv->acp_offset = quirks->acp_offset; 887 874 spin_lock_init(&priv->cmdreg_lock); 888 875 889 876 platform_set_drvdata(pdev, dev); ··· 922 907 MODULE_AUTHOR("Peter Chen <xingkongcp@gmail.com>"); 923 908 MODULE_AUTHOR("Gerhard Bertelsmann <info@gerhard-bertelsmann.de>"); 924 909 MODULE_LICENSE("Dual BSD/GPL"); 925 - MODULE_DESCRIPTION("CAN driver for Allwinner SoCs (A10/A20)"); 910 + MODULE_DESCRIPTION("CAN driver for Allwinner SoCs (A10/A20/D1)");
+2 -3
drivers/net/can/ti_hecc.c
··· 21 21 #include <linux/clk.h> 22 22 #include <linux/io.h> 23 23 #include <linux/of.h> 24 - #include <linux/of_device.h> 25 24 #include <linux/regulator/consumer.h> 26 25 27 26 #include <linux/can/dev.h> ··· 747 748 spin_unlock_irqrestore(&priv->mbx_lock, flags); 748 749 stamp = hecc_read_stamp(priv, mbxno); 749 750 stats->tx_bytes += 750 - can_rx_offload_get_echo_skb(&priv->offload, 751 - mbxno, stamp, NULL); 751 + can_rx_offload_get_echo_skb_queue_timestamp(&priv->offload, 752 + mbxno, stamp, NULL); 752 753 stats->tx_packets++; 753 754 --priv->tx_tail; 754 755 }
+1
drivers/net/can/usb/Kconfig
··· 52 52 53 53 config CAN_GS_USB 54 54 tristate "Geschwister Schneider UG and candleLight compatible interfaces" 55 + select CAN_RX_OFFLOAD 55 56 help 56 57 This driver supports the Geschwister Schneider and 57 58 bytewerk.org candleLight compatible
+113 -74
drivers/net/can/usb/gs_usb.c
··· 5 5 * Copyright (C) 2013-2016 Geschwister Schneider Technologie-, 6 6 * Entwicklungs- und Vertriebs UG (Haftungsbeschränkt). 7 7 * Copyright (C) 2016 Hubert Denkmair 8 + * Copyright (c) 2023 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de> 8 9 * 9 10 * Many thanks to all socketcan devs! 10 11 */ ··· 25 24 #include <linux/can.h> 26 25 #include <linux/can/dev.h> 27 26 #include <linux/can/error.h> 27 + #include <linux/can/rx-offload.h> 28 28 29 29 /* Device specific constants */ 30 30 #define USB_GS_USB_1_VENDOR_ID 0x1d50 ··· 284 282 #define GS_MAX_TX_URBS 10 285 283 /* Only launch a max of GS_MAX_RX_URBS usb requests at a time. */ 286 284 #define GS_MAX_RX_URBS 30 285 + #define GS_NAPI_WEIGHT 32 286 + 287 287 /* Maximum number of interfaces the driver supports per device. 288 288 * Current hardware only supports 3 interfaces. The future may vary. 289 289 */ ··· 299 295 struct gs_can { 300 296 struct can_priv can; /* must be the first member */ 301 297 298 + struct can_rx_offload offload; 302 299 struct gs_usb *parent; 303 300 304 301 struct net_device *netdev; ··· 511 506 } 512 507 } 513 508 514 - static void gs_usb_set_timestamp(struct gs_can *dev, struct sk_buff *skb, 515 - const struct gs_host_frame *hf) 509 + static u32 gs_usb_set_timestamp(struct gs_can *dev, struct sk_buff *skb, 510 + const struct gs_host_frame *hf) 516 511 { 517 512 u32 timestamp; 518 - 519 - if (!(dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)) 520 - return; 521 513 522 514 if (hf->flags & GS_CAN_FLAG_FD) 523 515 timestamp = le32_to_cpu(hf->canfd_ts->timestamp_us); 524 516 else 525 517 timestamp = le32_to_cpu(hf->classic_can_ts->timestamp_us); 526 518 527 - gs_usb_skb_set_timestamp(dev, skb, timestamp); 519 + if (skb) 520 + gs_usb_skb_set_timestamp(dev, skb, timestamp); 528 521 529 - return; 522 + return timestamp; 523 + } 524 + 525 + static void gs_usb_rx_offload(struct gs_can *dev, struct sk_buff *skb, 526 + const struct gs_host_frame *hf) 527 + { 528 + struct can_rx_offload *offload = &dev->offload; 529 + int rc; 530 + 531 + if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) { 532 + const u32 ts = gs_usb_set_timestamp(dev, skb, hf); 533 + 534 + rc = can_rx_offload_queue_timestamp(offload, skb, ts); 535 + } else { 536 + rc = can_rx_offload_queue_tail(offload, skb); 537 + } 538 + 539 + if (rc) 540 + dev->netdev->stats.rx_fifo_errors++; 541 + } 542 + 543 + static unsigned int 544 + gs_usb_get_echo_skb(struct gs_can *dev, struct sk_buff *skb, 545 + const struct gs_host_frame *hf) 546 + { 547 + struct can_rx_offload *offload = &dev->offload; 548 + const u32 echo_id = hf->echo_id; 549 + unsigned int len; 550 + 551 + if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) { 552 + const u32 ts = gs_usb_set_timestamp(dev, skb, hf); 553 + 554 + len = can_rx_offload_get_echo_skb_queue_timestamp(offload, echo_id, 555 + ts, NULL); 556 + } else { 557 + len = can_rx_offload_get_echo_skb_queue_tail(offload, echo_id, 558 + NULL); 559 + } 560 + 561 + return len; 530 562 } 531 563 532 564 static void gs_usb_receive_bulk_callback(struct urb *urb) 533 565 { 534 - struct gs_usb *usbcan = urb->context; 566 + struct gs_usb *parent = urb->context; 535 567 struct gs_can *dev; 536 568 struct net_device *netdev; 537 569 int rc; ··· 579 537 struct canfd_frame *cfd; 580 538 struct sk_buff *skb; 581 539 582 - BUG_ON(!usbcan); 540 + BUG_ON(!parent); 583 541 584 542 switch (urb->status) { 585 543 case 0: /* success */ ··· 596 554 if (hf->channel >= GS_MAX_INTF) 597 555 goto device_detach; 598 556 599 - dev = usbcan->canch[hf->channel]; 557 + dev = parent->canch[hf->channel]; 600 558 601 559 netdev = dev->netdev; 602 560 stats = &netdev->stats; ··· 609 567 610 568 if (hf->echo_id == -1) { /* normal rx */ 611 569 if (hf->flags & GS_CAN_FLAG_FD) { 612 - skb = alloc_canfd_skb(dev->netdev, &cfd); 570 + skb = alloc_canfd_skb(netdev, &cfd); 613 571 if (!skb) 614 572 return; 615 573 ··· 622 580 623 581 memcpy(cfd->data, hf->canfd->data, cfd->len); 624 582 } else { 625 - skb = alloc_can_skb(dev->netdev, &cf); 583 + skb = alloc_can_skb(netdev, &cf); 626 584 if (!skb) 627 585 return; 628 586 ··· 636 594 gs_update_state(dev, cf); 637 595 } 638 596 639 - gs_usb_set_timestamp(dev, skb, hf); 640 - 641 - netdev->stats.rx_packets++; 642 - netdev->stats.rx_bytes += hf->can_dlc; 643 - 644 - netif_rx(skb); 597 + gs_usb_rx_offload(dev, skb, hf); 645 598 } else { /* echo_id == hf->echo_id */ 646 599 if (hf->echo_id >= GS_MAX_TX_URBS) { 647 600 netdev_err(netdev, ··· 656 619 } 657 620 658 621 skb = dev->can.echo_skb[hf->echo_id]; 659 - gs_usb_set_timestamp(dev, skb, hf); 660 - 661 - netdev->stats.tx_packets++; 662 - netdev->stats.tx_bytes += can_get_echo_skb(netdev, hf->echo_id, 663 - NULL); 664 - 622 + stats->tx_packets++; 623 + stats->tx_bytes += gs_usb_get_echo_skb(dev, skb, hf); 665 624 gs_free_tx_context(txc); 666 625 667 626 atomic_dec(&dev->active_tx_urbs); ··· 666 633 } 667 634 668 635 if (hf->flags & GS_CAN_FLAG_OVERFLOW) { 636 + stats->rx_over_errors++; 637 + stats->rx_errors++; 638 + 669 639 skb = alloc_can_err_skb(netdev, &cf); 670 640 if (!skb) 671 641 goto resubmit_urb; ··· 676 640 cf->can_id |= CAN_ERR_CRTL; 677 641 cf->len = CAN_ERR_DLC; 678 642 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; 679 - stats->rx_over_errors++; 680 - stats->rx_errors++; 681 - netif_rx(skb); 643 + 644 + gs_usb_rx_offload(dev, skb, hf); 682 645 } 683 646 684 - resubmit_urb: 685 - usb_fill_bulk_urb(urb, usbcan->udev, 686 - usb_rcvbulkpipe(usbcan->udev, GS_USB_ENDPOINT_IN), 647 + can_rx_offload_irq_finish(&dev->offload); 648 + 649 + resubmit_urb: 650 + usb_fill_bulk_urb(urb, parent->udev, 651 + usb_rcvbulkpipe(parent->udev, GS_USB_ENDPOINT_IN), 687 652 hf, dev->parent->hf_size_rx, 688 - gs_usb_receive_bulk_callback, usbcan); 653 + gs_usb_receive_bulk_callback, parent); 689 654 690 655 rc = usb_submit_urb(urb, GFP_ATOMIC); 691 656 692 657 /* USB failure take down all interfaces */ 693 658 if (rc == -ENODEV) { 694 - device_detach: 659 + device_detach: 695 660 for (rc = 0; rc < GS_MAX_INTF; rc++) { 696 - if (usbcan->canch[rc]) 697 - netif_device_detach(usbcan->canch[rc]->netdev); 661 + if (parent->canch[rc]) 662 + netif_device_detach(parent->canch[rc]->netdev); 698 663 } 699 664 } 700 665 } ··· 779 742 goto nomem_urb; 780 743 781 744 hf = kmalloc(dev->hf_size_tx, GFP_ATOMIC); 782 - if (!hf) { 783 - netdev_err(netdev, "No memory left for USB buffer\n"); 745 + if (!hf) 784 746 goto nomem_hf; 785 - } 786 747 787 748 idx = txc->echo_id; 788 749 ··· 853 818 854 819 return NETDEV_TX_OK; 855 820 856 - badidx: 821 + badidx: 857 822 kfree(hf); 858 - nomem_hf: 823 + nomem_hf: 859 824 usb_free_urb(urb); 860 825 861 - nomem_urb: 826 + nomem_urb: 862 827 gs_free_tx_context(txc); 863 828 dev_kfree_skb(skb); 864 829 stats->tx_dropped++; ··· 895 860 dev->hf_size_tx = struct_size(hf, classic_can, 1); 896 861 } 897 862 863 + can_rx_offload_enable(&dev->offload); 864 + 898 865 if (!parent->active_channels) { 899 866 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 900 867 gs_usb_timestamp_init(parent); ··· 915 878 buf = kmalloc(dev->parent->hf_size_rx, 916 879 GFP_KERNEL); 917 880 if (!buf) { 918 - netdev_err(netdev, 919 - "No memory left for USB buffer\n"); 920 881 rc = -ENOMEM; 921 882 goto out_usb_free_urb; 922 883 } ··· 937 902 netif_device_detach(dev->netdev); 938 903 939 904 netdev_err(netdev, 940 - "usb_submit failed (err=%d)\n", rc); 905 + "usb_submit_urb() failed, error %pe\n", 906 + ERR_PTR(rc)); 941 907 942 908 goto out_usb_unanchor_urb; 943 909 } ··· 1005 969 gs_usb_timestamp_stop(parent); 1006 970 } 1007 971 972 + can_rx_offload_disable(&dev->offload); 1008 973 close_candev(netdev); 1009 974 1010 975 return rc; ··· 1070 1033 dev->can.state = CAN_STATE_STOPPED; 1071 1034 1072 1035 /* reset the device */ 1073 - rc = gs_cmd_reset(dev); 1074 - if (rc < 0) 1075 - netdev_warn(netdev, "Couldn't shutdown device (err=%d)", rc); 1036 + gs_cmd_reset(dev); 1076 1037 1077 1038 /* reset tx contexts */ 1078 1039 for (rc = 0; rc < GS_MAX_TX_URBS; rc++) { 1079 1040 dev->tx_context[rc].dev = dev; 1080 1041 dev->tx_context[rc].echo_id = GS_MAX_TX_URBS; 1081 1042 } 1043 + 1044 + can_rx_offload_disable(&dev->offload); 1082 1045 1083 1046 /* close the netdev */ 1084 1047 close_candev(netdev); ··· 1379 1342 dev->can.data_bittiming_const = &dev->data_bt_const; 1380 1343 } 1381 1344 1345 + can_rx_offload_add_manual(netdev, &dev->offload, GS_NAPI_WEIGHT); 1382 1346 SET_NETDEV_DEV(netdev, &intf->dev); 1383 1347 1384 1348 rc = register_candev(dev->netdev); ··· 1387 1349 dev_err(&intf->dev, 1388 1350 "Couldn't register candev for channel %d (%pe)\n", 1389 1351 channel, ERR_PTR(rc)); 1390 - goto out_free_candev; 1352 + goto out_can_rx_offload_del; 1391 1353 } 1392 1354 1393 1355 return dev; 1394 1356 1395 - out_free_candev: 1357 + out_can_rx_offload_del: 1358 + can_rx_offload_del(&dev->offload); 1359 + out_free_candev: 1396 1360 free_candev(dev->netdev); 1397 1361 return ERR_PTR(rc); 1398 1362 } ··· 1402 1362 static void gs_destroy_candev(struct gs_can *dev) 1403 1363 { 1404 1364 unregister_candev(dev->netdev); 1405 - usb_kill_anchored_urbs(&dev->tx_submitted); 1365 + can_rx_offload_del(&dev->offload); 1406 1366 free_candev(dev->netdev); 1407 1367 } 1408 1368 ··· 1411 1371 { 1412 1372 struct usb_device *udev = interface_to_usbdev(intf); 1413 1373 struct gs_host_frame *hf; 1414 - struct gs_usb *dev; 1374 + struct gs_usb *parent; 1415 1375 struct gs_host_config hconf = { 1416 1376 .byte_order = cpu_to_le32(0x0000beef), 1417 1377 }; ··· 1454 1414 return -EINVAL; 1455 1415 } 1456 1416 1457 - dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1458 - if (!dev) 1417 + parent = kzalloc(sizeof(*parent), GFP_KERNEL); 1418 + if (!parent) 1459 1419 return -ENOMEM; 1460 1420 1461 - init_usb_anchor(&dev->rx_submitted); 1421 + init_usb_anchor(&parent->rx_submitted); 1462 1422 1463 - usb_set_intfdata(intf, dev); 1464 - dev->udev = udev; 1423 + usb_set_intfdata(intf, parent); 1424 + parent->udev = udev; 1465 1425 1466 1426 for (i = 0; i < icount; i++) { 1467 1427 unsigned int hf_size_rx = 0; 1468 1428 1469 - dev->canch[i] = gs_make_candev(i, intf, &dconf); 1470 - if (IS_ERR_OR_NULL(dev->canch[i])) { 1429 + parent->canch[i] = gs_make_candev(i, intf, &dconf); 1430 + if (IS_ERR_OR_NULL(parent->canch[i])) { 1471 1431 /* save error code to return later */ 1472 - rc = PTR_ERR(dev->canch[i]); 1432 + rc = PTR_ERR(parent->canch[i]); 1473 1433 1474 1434 /* on failure destroy previously created candevs */ 1475 1435 icount = i; 1476 1436 for (i = 0; i < icount; i++) 1477 - gs_destroy_candev(dev->canch[i]); 1437 + gs_destroy_candev(parent->canch[i]); 1478 1438 1479 - usb_kill_anchored_urbs(&dev->rx_submitted); 1480 - kfree(dev); 1439 + usb_kill_anchored_urbs(&parent->rx_submitted); 1440 + kfree(parent); 1481 1441 return rc; 1482 1442 } 1483 - dev->canch[i]->parent = dev; 1443 + parent->canch[i]->parent = parent; 1484 1444 1485 1445 /* set RX packet size based on FD and if hardware 1486 - * timestamps are supported. 1487 - */ 1488 - if (dev->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) { 1489 - if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1446 + * timestamps are supported. 1447 + */ 1448 + if (parent->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) { 1449 + if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1490 1450 hf_size_rx = struct_size(hf, canfd_ts, 1); 1491 1451 else 1492 1452 hf_size_rx = struct_size(hf, canfd, 1); 1493 1453 } else { 1494 - if (dev->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1454 + if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1495 1455 hf_size_rx = struct_size(hf, classic_can_ts, 1); 1496 1456 else 1497 1457 hf_size_rx = struct_size(hf, classic_can, 1); 1498 1458 } 1499 - dev->hf_size_rx = max(dev->hf_size_rx, hf_size_rx); 1459 + parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx); 1500 1460 } 1501 1461 1502 1462 return 0; ··· 1504 1464 1505 1465 static void gs_usb_disconnect(struct usb_interface *intf) 1506 1466 { 1507 - struct gs_usb *dev = usb_get_intfdata(intf); 1467 + struct gs_usb *parent = usb_get_intfdata(intf); 1508 1468 unsigned int i; 1509 1469 1510 1470 usb_set_intfdata(intf, NULL); 1511 1471 1512 - if (!dev) { 1472 + if (!parent) { 1513 1473 dev_err(&intf->dev, "Disconnect (nodata)\n"); 1514 1474 return; 1515 1475 } 1516 1476 1517 1477 for (i = 0; i < GS_MAX_INTF; i++) 1518 - if (dev->canch[i]) 1519 - gs_destroy_candev(dev->canch[i]); 1478 + if (parent->canch[i]) 1479 + gs_destroy_candev(parent->canch[i]); 1520 1480 1521 - usb_kill_anchored_urbs(&dev->rx_submitted); 1522 - kfree(dev); 1481 + kfree(parent); 1523 1482 } 1524 1483 1525 1484 static const struct usb_device_id gs_usb_table[] = {
-13
drivers/net/can/usb/peak_usb/pcan_usb_core.c
··· 214 214 } 215 215 } 216 216 217 - /* 218 - * post received skb after having set any hw timestamp 219 - */ 220 - int peak_usb_netif_rx(struct sk_buff *skb, 221 - struct peak_time_ref *time_ref, u32 ts_low) 222 - { 223 - struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb); 224 - 225 - peak_usb_get_ts_time(time_ref, ts_low, &hwts->hwtstamp); 226 - 227 - return netif_rx(skb); 228 - } 229 - 230 217 /* post received skb with native 64-bit hw timestamp */ 231 218 int peak_usb_netif_rx_64(struct sk_buff *skb, u32 ts_low, u32 ts_high) 232 219 {
-2
drivers/net/can/usb/peak_usb/pcan_usb_core.h
··· 142 142 void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now); 143 143 void peak_usb_set_ts_now(struct peak_time_ref *time_ref, u32 ts_now); 144 144 void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *tv); 145 - int peak_usb_netif_rx(struct sk_buff *skb, 146 - struct peak_time_ref *time_ref, u32 ts_low); 147 145 int peak_usb_netif_rx_64(struct sk_buff *skb, u32 ts_low, u32 ts_high); 148 146 void peak_usb_async_complete(struct urb *urb); 149 147 void peak_usb_restart_complete(struct peak_usb_device *dev);
+7 -4
include/linux/can/rx-offload.h
··· 3 3 * linux/can/rx-offload.h 4 4 * 5 5 * Copyright (c) 2014 David Jander, Protonic Holland 6 - * Copyright (c) 2014-2017 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de> 6 + * Copyright (c) 2014-2017, 2023 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de> 7 7 */ 8 8 9 9 #ifndef _CAN_RX_OFFLOAD_H ··· 44 44 int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload); 45 45 int can_rx_offload_queue_timestamp(struct can_rx_offload *offload, 46 46 struct sk_buff *skb, u32 timestamp); 47 - unsigned int can_rx_offload_get_echo_skb(struct can_rx_offload *offload, 48 - unsigned int idx, u32 timestamp, 49 - unsigned int *frame_len_ptr); 47 + unsigned int can_rx_offload_get_echo_skb_queue_timestamp(struct can_rx_offload *offload, 48 + unsigned int idx, u32 timestamp, 49 + unsigned int *frame_len_ptr); 50 50 int can_rx_offload_queue_tail(struct can_rx_offload *offload, 51 51 struct sk_buff *skb); 52 + unsigned int can_rx_offload_get_echo_skb_queue_tail(struct can_rx_offload *offload, 53 + unsigned int idx, 54 + unsigned int *frame_len_ptr); 52 55 void can_rx_offload_irq_finish(struct can_rx_offload *offload); 53 56 void can_rx_offload_threaded_irq_finish(struct can_rx_offload *offload); 54 57 void can_rx_offload_del(struct can_rx_offload *offload);