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.14-20250110' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

====================
pull-request: can-next 2025-01-10

Pierre-Henry Moussay adds PIC64GX compatibility to the DT bindings for
Microchip's mpfs-can IP core.

The next 3 patches are by Sean Nyekjaer and target the tcan4x5x
driver. First the DT bindings is converted to DT schema, then nWKRQ
voltage selection is added to the driver.

Dario Binacchi's patch for the sun4i_can makes the driver more
consistent by adding a likely() to the driver.

Another patch by Sean Nyekjaer for the tcan4x5x driver gets rid of a
false error message.

Charan Pedumuru converts the atmel-can DT bindings to DT schema.

The next 2 patches are by Oliver Hartkopp. The first one maps Oliver's
former mail addresses to a dedicated CAN mail address. The second one
assigns net/sched/em_canid.c additionally to the CAN maintainers.

Ariel Otilibili's patch removes dead code from the CAN dev helper.

The next 3 patches are by Sean Nyekjaer and add HW standby support to
the tcan4x5x driver.

A patch by Dario Binacchi fixes the DT bindings for the st,stm32-bxcan
driver.

The last 4 patches are by Jimmy Assarsson and target the kvaser_usb
and the kvaser_pciefd driver: error statistics are improved and
CAN_CTRLMODE_BERR_REPORTING is added.

* tag 'linux-can-next-for-6.14-20250110' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next:
can: kvaser_pciefd: Add support for CAN_CTRLMODE_BERR_REPORTING
can: kvaser_pciefd: Update stats and state even if alloc_can_err_skb() fails
can: kvaser_usb: Add support for CAN_CTRLMODE_BERR_REPORTING
can: kvaser_usb: Update stats and state even if alloc_can_err_skb() fails
dt-bindings: can: st,stm32-bxcan: fix st,gcan property type
can: m_can: call deinit/init callback when going into suspend/resume
can: tcan4x5x: add deinit callback to set standby mode
can: m_can: add deinit callback
can: dev: can_get_state_str(): Remove dead code
MAINTAINERS: assign em_canid.c additionally to CAN maintainers
mailmap: add an entry for Oliver Hartkopp
dt-bindings: net: can: atmel: Convert to json schema
can: tcan4x5x: get rid of false clock errors
can: sun4i_can: continue to use likely() to check skb
can: tcan4x5x: add option for selecting nWKRQ voltage
dt-bindings: can: tcan4x5x: Document the ti,nwkrq-voltage-vio option
dt-bindings: can: convert tcan4x5x.txt to DT schema
dt-bindings: can: mpfs: add PIC64GX CAN compatibility
====================

Link: https://patch.msgid.link/20250110112712.3214173-1-mkl@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+432 -213
+2
.mailmap
··· 529 529 Oleksij Rempel <linux@rempel-privat.de> <fixed-term.Oleksij.Rempel@de.bosch.com> 530 530 Oleksij Rempel <o.rempel@pengutronix.de> 531 531 Oleksij Rempel <o.rempel@pengutronix.de> <ore@pengutronix.de> 532 + Oliver Hartkopp <socketcan@hartkopp.net> <oliver.hartkopp@volkswagen.de> 533 + Oliver Hartkopp <socketcan@hartkopp.net> <oliver@hartkopp.net> 532 534 Oliver Upton <oliver.upton@linux.dev> <oupton@google.com> 533 535 Ondřej Jirman <megi@xff.cz> <megous@megous.com> 534 536 Oza Pawandeep <quic_poza@quicinc.com> <poza@codeaurora.org>
+58
Documentation/devicetree/bindings/net/can/atmel,at91sam9263-can.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/net/can/atmel,at91sam9263-can.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Microchip AT91 CAN Controller 8 + 9 + maintainers: 10 + - Nicolas Ferre <nicolas.ferre@microchip.com> 11 + 12 + allOf: 13 + - $ref: can-controller.yaml# 14 + 15 + properties: 16 + compatible: 17 + oneOf: 18 + - enum: 19 + - atmel,at91sam9263-can 20 + - atmel,at91sam9x5-can 21 + - items: 22 + - enum: 23 + - microchip,sam9x60-can 24 + - const: atmel,at91sam9x5-can 25 + 26 + reg: 27 + maxItems: 1 28 + 29 + interrupts: 30 + maxItems: 1 31 + 32 + clocks: 33 + maxItems: 1 34 + 35 + clock-names: 36 + items: 37 + - const: can_clk 38 + 39 + required: 40 + - compatible 41 + - reg 42 + - interrupts 43 + - clocks 44 + - clock-names 45 + 46 + unevaluatedProperties: false 47 + 48 + examples: 49 + - | 50 + #include <dt-bindings/interrupt-controller/irq.h> 51 + #include <dt-bindings/clock/at91.h> 52 + can@f000c000 { 53 + compatible = "atmel,at91sam9263-can"; 54 + reg = <0xf000c000 0x300>; 55 + interrupts = <30 IRQ_TYPE_LEVEL_HIGH 3>; 56 + clocks = <&pmc PMC_TYPE_PERIPHERAL 12>; 57 + clock-names = "can_clk"; 58 + };
-15
Documentation/devicetree/bindings/net/can/atmel-can.txt
··· 1 - * AT91 CAN * 2 - 3 - Required properties: 4 - - compatible: Should be "atmel,at91sam9263-can", "atmel,at91sam9x5-can" or 5 - "microchip,sam9x60-can" 6 - - reg: Should contain CAN controller registers location and length 7 - - interrupts: Should contain IRQ line for the CAN controller 8 - 9 - Example: 10 - 11 - can0: can@f000c000 { 12 - compatible = "atmel,at91sam9x5-can"; 13 - reg = <0xf000c000 0x300>; 14 - interrupts = <40 4 5> 15 - };
+5 -1
Documentation/devicetree/bindings/net/can/microchip,mpfs-can.yaml
··· 15 15 16 16 properties: 17 17 compatible: 18 - const: microchip,mpfs-can 18 + oneOf: 19 + - items: 20 + - const: microchip,pic64gx-can 21 + - const: microchip,mpfs-can 22 + - const: microchip,mpfs-can 19 23 20 24 reg: 21 25 maxItems: 1
+1 -1
Documentation/devicetree/bindings/net/can/st,stm32-bxcan.yaml
··· 63 63 maxItems: 1 64 64 65 65 st,gcan: 66 - $ref: /schemas/types.yaml#/definitions/phandle-array 66 + $ref: /schemas/types.yaml#/definitions/phandle 67 67 description: 68 68 The phandle to the gcan node which allows to access the 512-bytes 69 69 SRAM memory shared by the two bxCAN cells (CAN1 primary and CAN2
-48
Documentation/devicetree/bindings/net/can/tcan4x5x.txt
··· 1 - Texas Instruments TCAN4x5x CAN Controller 2 - ================================================ 3 - 4 - This file provides device node information for the TCAN4x5x interface contains. 5 - 6 - Required properties: 7 - - compatible: 8 - "ti,tcan4552", "ti,tcan4x5x" 9 - "ti,tcan4553", "ti,tcan4x5x" or 10 - "ti,tcan4x5x" 11 - - reg: 0 12 - - #address-cells: 1 13 - - #size-cells: 0 14 - - spi-max-frequency: Maximum frequency of the SPI bus the chip can 15 - operate at should be less than or equal to 18 MHz. 16 - - interrupt-parent: the phandle to the interrupt controller which provides 17 - the interrupt. 18 - - interrupts: interrupt specification for data-ready. 19 - 20 - See Documentation/devicetree/bindings/net/can/bosch,m_can.yaml for additional 21 - required property details. 22 - 23 - Optional properties: 24 - - reset-gpios: Hardwired output GPIO. If not defined then software 25 - reset. 26 - - device-state-gpios: Input GPIO that indicates if the device is in 27 - a sleep state or if the device is active. Not 28 - available with tcan4552/4553. 29 - - device-wake-gpios: Wake up GPIO to wake up the TCAN device. Not 30 - available with tcan4552/4553. 31 - - wakeup-source: Leave the chip running when suspended, and configure 32 - the RX interrupt to wake up the device. 33 - 34 - Example: 35 - tcan4x5x: tcan4x5x@0 { 36 - compatible = "ti,tcan4x5x"; 37 - reg = <0>; 38 - #address-cells = <1>; 39 - #size-cells = <1>; 40 - spi-max-frequency = <10000000>; 41 - bosch,mram-cfg = <0x0 0 0 16 0 0 1 1>; 42 - interrupt-parent = <&gpio1>; 43 - interrupts = <14 IRQ_TYPE_LEVEL_LOW>; 44 - device-state-gpios = <&gpio3 21 GPIO_ACTIVE_HIGH>; 45 - device-wake-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>; 46 - reset-gpios = <&gpio1 27 GPIO_ACTIVE_HIGH>; 47 - wakeup-source; 48 - };
+199
Documentation/devicetree/bindings/net/can/ti,tcan4x5x.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/net/can/ti,tcan4x5x.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments TCAN4x5x CAN Controller 8 + 9 + maintainers: 10 + - Marc Kleine-Budde <mkl@pengutronix.de> 11 + 12 + properties: 13 + compatible: 14 + oneOf: 15 + - items: 16 + - enum: 17 + - ti,tcan4552 18 + - ti,tcan4553 19 + - const: ti,tcan4x5x 20 + - const: ti,tcan4x5x 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + interrupts: 26 + maxItems: 1 27 + description: The GPIO parent interrupt. 28 + 29 + clocks: 30 + maxItems: 1 31 + 32 + clock-names: 33 + items: 34 + - const: cclk 35 + 36 + reset-gpios: 37 + description: Hardwired output GPIO. If not defined then software reset. 38 + maxItems: 1 39 + 40 + device-state-gpios: 41 + description: 42 + Input GPIO that indicates if the device is in a sleep state or if the 43 + device is active. Not available with tcan4552/4553. 44 + maxItems: 1 45 + 46 + device-wake-gpios: 47 + description: 48 + Wake up GPIO to wake up the TCAN device. 49 + Not available with tcan4552/4553. 50 + maxItems: 1 51 + 52 + bosch,mram-cfg: 53 + description: | 54 + Message RAM configuration data. 55 + Multiple M_CAN instances can share the same Message RAM 56 + and each element(e.g Rx FIFO or Tx Buffer and etc) number 57 + in Message RAM is also configurable, so this property is 58 + telling driver how the shared or private Message RAM are 59 + used by this M_CAN controller. 60 + 61 + The format should be as follows: 62 + <offset sidf_elems xidf_elems rxf0_elems rxf1_elems rxb_elems txe_elems txb_elems> 63 + The 'offset' is an address offset of the Message RAM where 64 + the following elements start from. This is usually set to 65 + 0x0 if you're using a private Message RAM. The remain cells 66 + are used to specify how many elements are used for each FIFO/Buffer. 67 + 68 + M_CAN includes the following elements according to user manual: 69 + 11-bit Filter 0-128 elements / 0-128 words 70 + 29-bit Filter 0-64 elements / 0-128 words 71 + Rx FIFO 0 0-64 elements / 0-1152 words 72 + Rx FIFO 1 0-64 elements / 0-1152 words 73 + Rx Buffers 0-64 elements / 0-1152 words 74 + Tx Event FIFO 0-32 elements / 0-64 words 75 + Tx Buffers 0-32 elements / 0-576 words 76 + 77 + Please refer to 2.4.1 Message RAM Configuration in Bosch 78 + M_CAN user manual for details. 79 + $ref: /schemas/types.yaml#/definitions/int32-array 80 + items: 81 + - description: The 'offset' is an address offset of the Message RAM where 82 + the following elements start from. This is usually set to 0x0 if 83 + you're using a private Message RAM. 84 + default: 0 85 + - description: 11-bit Filter 0-128 elements / 0-128 words 86 + minimum: 0 87 + maximum: 128 88 + - description: 29-bit Filter 0-64 elements / 0-128 words 89 + minimum: 0 90 + maximum: 64 91 + - description: Rx FIFO 0 0-64 elements / 0-1152 words 92 + minimum: 0 93 + maximum: 64 94 + - description: Rx FIFO 1 0-64 elements / 0-1152 words 95 + minimum: 0 96 + maximum: 64 97 + - description: Rx Buffers 0-64 elements / 0-1152 words 98 + minimum: 0 99 + maximum: 64 100 + - description: Tx Event FIFO 0-32 elements / 0-64 words 101 + minimum: 0 102 + maximum: 32 103 + - description: Tx Buffers 0-32 elements / 0-576 words 104 + minimum: 0 105 + maximum: 32 106 + minItems: 1 107 + 108 + spi-max-frequency: 109 + description: 110 + Must be half or less of "clocks" frequency. 111 + maximum: 18000000 112 + 113 + ti,nwkrq-voltage-vio: 114 + type: boolean 115 + description: 116 + nWKRQ Pin GPO buffer voltage configuration. 117 + Set nWKRQ to use VIO voltage rail. 118 + When not set nWKRQ will use internal voltage rail. 119 + 120 + wakeup-source: 121 + $ref: /schemas/types.yaml#/definitions/flag 122 + description: 123 + Enable CAN remote wakeup. 124 + 125 + allOf: 126 + - $ref: can-controller.yaml# 127 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 128 + - if: 129 + properties: 130 + compatible: 131 + contains: 132 + enum: 133 + - ti,tcan4552 134 + - ti,tcan4553 135 + then: 136 + properties: 137 + device-state-gpios: false 138 + device-wake-gpios: false 139 + 140 + required: 141 + - compatible 142 + - reg 143 + - interrupts 144 + - clocks 145 + - clock-names 146 + - bosch,mram-cfg 147 + 148 + unevaluatedProperties: false 149 + 150 + examples: 151 + - | 152 + #include <dt-bindings/gpio/gpio.h> 153 + #include <dt-bindings/interrupt-controller/irq.h> 154 + 155 + spi { 156 + #address-cells = <1>; 157 + #size-cells = <0>; 158 + 159 + can@0 { 160 + compatible = "ti,tcan4x5x"; 161 + reg = <0>; 162 + clocks = <&can0_osc>; 163 + clock-names = "cclk"; 164 + pinctrl-names = "default"; 165 + pinctrl-0 = <&can0_pins>; 166 + spi-max-frequency = <10000000>; 167 + bosch,mram-cfg = <0x0 0 0 16 0 0 1 1>; 168 + interrupt-parent = <&gpio1>; 169 + interrupts = <14 IRQ_TYPE_LEVEL_LOW>; 170 + device-state-gpios = <&gpio3 21 GPIO_ACTIVE_HIGH>; 171 + device-wake-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>; 172 + reset-gpios = <&gpio1 27 GPIO_ACTIVE_HIGH>; 173 + ti,nwkrq-voltage-vio; 174 + wakeup-source; 175 + }; 176 + }; 177 + - | 178 + #include <dt-bindings/gpio/gpio.h> 179 + #include <dt-bindings/interrupt-controller/irq.h> 180 + 181 + spi { 182 + #address-cells = <1>; 183 + #size-cells = <0>; 184 + 185 + can@0 { 186 + compatible = "ti,tcan4552", "ti,tcan4x5x"; 187 + reg = <0>; 188 + clocks = <&can0_osc>; 189 + clock-names = "cclk"; 190 + pinctrl-names = "default"; 191 + pinctrl-0 = <&can0_pins>; 192 + spi-max-frequency = <10000000>; 193 + bosch,mram-cfg = <0x0 0 0 16 0 0 1 1>; 194 + interrupt-parent = <&gpio1>; 195 + interrupts = <14 IRQ_TYPE_LEVEL_LOW>; 196 + reset-gpios = <&gpio1 27 GPIO_ACTIVE_HIGH>; 197 + wakeup-source; 198 + }; 199 + };
+1
MAINTAINERS
··· 5115 5115 F: include/uapi/linux/can/isotp.h 5116 5116 F: include/uapi/linux/can/raw.h 5117 5117 F: net/can/ 5118 + F: net/sched/em_canid.c 5118 5119 5119 5120 CAN-J1939 NETWORK LAYER 5120 5121 M: Robin van der Gracht <robin@protonic.nl>
-2
drivers/net/can/dev/dev.c
··· 85 85 default: 86 86 return "<unknown>"; 87 87 } 88 - 89 - return "<unknown>"; 90 88 } 91 89 EXPORT_SYMBOL_GPL(can_get_state_str); 92 90
+42 -39
drivers/net/can/kvaser_pciefd.c
··· 999 999 can->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | 1000 1000 CAN_CTRLMODE_FD | 1001 1001 CAN_CTRLMODE_FD_NON_ISO | 1002 - CAN_CTRLMODE_CC_LEN8_DLC; 1002 + CAN_CTRLMODE_CC_LEN8_DLC | 1003 + CAN_CTRLMODE_BERR_REPORTING; 1003 1004 1004 1005 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); 1005 1006 if (!(status & KVASER_PCIEFD_KCAN_STAT_FD)) { ··· 1235 1234 } 1236 1235 1237 1236 static void kvaser_pciefd_change_state(struct kvaser_pciefd_can *can, 1237 + const struct can_berr_counter *bec, 1238 1238 struct can_frame *cf, 1239 1239 enum can_state new_state, 1240 1240 enum can_state tx_state, 1241 1241 enum can_state rx_state) 1242 1242 { 1243 + enum can_state old_state; 1244 + 1245 + old_state = can->can.state; 1243 1246 can_change_state(can->can.dev, cf, tx_state, rx_state); 1244 1247 1245 1248 if (new_state == CAN_STATE_BUS_OFF) { ··· 1258 1253 kvaser_pciefd_start_controller_flush(can); 1259 1254 can_bus_off(ndev); 1260 1255 } 1256 + } 1257 + if (old_state == CAN_STATE_BUS_OFF && 1258 + new_state == CAN_STATE_ERROR_ACTIVE && 1259 + can->can.restart_ms) { 1260 + can->can.can_stats.restarts++; 1261 + if (cf) 1262 + cf->can_id |= CAN_ERR_RESTARTED; 1263 + } 1264 + if (cf && new_state != CAN_STATE_BUS_OFF) { 1265 + cf->can_id |= CAN_ERR_CNT; 1266 + cf->data[6] = bec->txerr; 1267 + cf->data[7] = bec->rxerr; 1261 1268 } 1262 1269 } 1263 1270 ··· 1305 1288 struct can_berr_counter bec; 1306 1289 enum can_state old_state, new_state, tx_state, rx_state; 1307 1290 struct net_device *ndev = can->can.dev; 1308 - struct sk_buff *skb; 1291 + struct sk_buff *skb = NULL; 1309 1292 struct can_frame *cf = NULL; 1310 1293 1311 1294 old_state = can->can.state; ··· 1314 1297 bec.rxerr = FIELD_GET(KVASER_PCIEFD_SPACK_RXERR_MASK, p->header[0]); 1315 1298 1316 1299 kvaser_pciefd_packet_to_state(p, &bec, &new_state, &tx_state, &rx_state); 1317 - skb = alloc_can_err_skb(ndev, &cf); 1300 + if (can->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) 1301 + skb = alloc_can_err_skb(ndev, &cf); 1318 1302 if (new_state != old_state) { 1319 - kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state); 1320 - if (old_state == CAN_STATE_BUS_OFF && 1321 - new_state == CAN_STATE_ERROR_ACTIVE && 1322 - can->can.restart_ms) { 1323 - can->can.can_stats.restarts++; 1324 - if (skb) 1325 - cf->can_id |= CAN_ERR_RESTARTED; 1326 - } 1303 + kvaser_pciefd_change_state(can, &bec, cf, new_state, tx_state, rx_state); 1327 1304 } 1328 1305 1329 1306 can->err_rep_cnt++; ··· 1330 1319 can->bec.txerr = bec.txerr; 1331 1320 can->bec.rxerr = bec.rxerr; 1332 1321 1333 - if (!skb) { 1334 - ndev->stats.rx_dropped++; 1335 - return -ENOMEM; 1322 + if (can->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) { 1323 + if (!skb) { 1324 + netdev_warn(ndev, "No memory left for err_skb\n"); 1325 + ndev->stats.rx_dropped++; 1326 + return -ENOMEM; 1327 + } 1328 + kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); 1329 + cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_CNT; 1330 + cf->data[6] = bec.txerr; 1331 + cf->data[7] = bec.rxerr; 1332 + netif_rx(skb); 1336 1333 } 1337 - 1338 - kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); 1339 - cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_CNT; 1340 - cf->data[6] = bec.txerr; 1341 - cf->data[7] = bec.rxerr; 1342 - 1343 - netif_rx(skb); 1344 1334 1345 1335 return 0; 1346 1336 } ··· 1371 1359 { 1372 1360 struct can_berr_counter bec; 1373 1361 enum can_state old_state, new_state, tx_state, rx_state; 1362 + int ret = 0; 1374 1363 1375 1364 old_state = can->can.state; 1376 1365 ··· 1385 1372 struct can_frame *cf; 1386 1373 1387 1374 skb = alloc_can_err_skb(ndev, &cf); 1388 - if (!skb) { 1375 + kvaser_pciefd_change_state(can, &bec, cf, new_state, tx_state, rx_state); 1376 + if (skb) { 1377 + kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); 1378 + netif_rx(skb); 1379 + } else { 1389 1380 ndev->stats.rx_dropped++; 1390 - return -ENOMEM; 1381 + netdev_warn(ndev, "No memory left for err_skb\n"); 1382 + ret = -ENOMEM; 1391 1383 } 1392 - 1393 - kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state); 1394 - if (old_state == CAN_STATE_BUS_OFF && 1395 - new_state == CAN_STATE_ERROR_ACTIVE && 1396 - can->can.restart_ms) { 1397 - can->can.can_stats.restarts++; 1398 - cf->can_id |= CAN_ERR_RESTARTED; 1399 - } 1400 - 1401 - kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); 1402 - 1403 - cf->data[6] = bec.txerr; 1404 - cf->data[7] = bec.rxerr; 1405 - 1406 - netif_rx(skb); 1407 1384 } 1408 1385 can->bec.txerr = bec.txerr; 1409 1386 can->bec.rxerr = bec.rxerr; ··· 1401 1398 if (bec.txerr || bec.rxerr) 1402 1399 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); 1403 1400 1404 - return 0; 1401 + return ret; 1405 1402 } 1406 1403 1407 1404 static int kvaser_pciefd_handle_status_packet(struct kvaser_pciefd *pcie,
+18 -4
drivers/net/can/m_can/m_can.c
··· 1785 1785 1786 1786 /* set the state as STOPPED */ 1787 1787 cdev->can.state = CAN_STATE_STOPPED; 1788 + 1789 + if (cdev->ops->deinit) { 1790 + ret = cdev->ops->deinit(cdev); 1791 + if (ret) 1792 + netdev_err(dev, "failed to deinitialize: %pe\n", 1793 + ERR_PTR(ret)); 1794 + } 1788 1795 } 1789 1796 1790 1797 static int m_can_close(struct net_device *dev) ··· 2473 2466 { 2474 2467 struct m_can_classdev *cdev = dev_get_drvdata(dev); 2475 2468 struct net_device *ndev = cdev->net; 2469 + int ret = 0; 2476 2470 2477 2471 if (netif_running(ndev)) { 2478 2472 netif_stop_queue(ndev); ··· 2486 2478 if (cdev->pm_wake_source) { 2487 2479 hrtimer_cancel(&cdev->hrtimer); 2488 2480 m_can_write(cdev, M_CAN_IE, IR_RF0N); 2481 + 2482 + if (cdev->ops->deinit) 2483 + ret = cdev->ops->deinit(cdev); 2489 2484 } else { 2490 2485 m_can_stop(ndev); 2491 2486 } ··· 2500 2489 2501 2490 cdev->can.state = CAN_STATE_SLEEPING; 2502 2491 2503 - return 0; 2492 + return ret; 2504 2493 } 2505 2494 EXPORT_SYMBOL_GPL(m_can_class_suspend); 2506 2495 ··· 2508 2497 { 2509 2498 struct m_can_classdev *cdev = dev_get_drvdata(dev); 2510 2499 struct net_device *ndev = cdev->net; 2500 + int ret = 0; 2511 2501 2512 2502 pinctrl_pm_select_default_state(dev); 2513 2503 2514 2504 cdev->can.state = CAN_STATE_ERROR_ACTIVE; 2515 2505 2516 2506 if (netif_running(ndev)) { 2517 - int ret; 2518 - 2519 2507 ret = m_can_clk_start(cdev); 2520 2508 if (ret) 2521 2509 return ret; ··· 2527 2517 * again. 2528 2518 */ 2529 2519 cdev->active_interrupts |= IR_RF0N | IR_TEFN; 2520 + 2521 + if (cdev->ops->init) 2522 + ret = cdev->ops->init(cdev); 2523 + 2530 2524 m_can_write(cdev, M_CAN_IE, cdev->active_interrupts); 2531 2525 } else { 2532 2526 ret = m_can_start(ndev); ··· 2544 2530 netif_start_queue(ndev); 2545 2531 } 2546 2532 2547 - return 0; 2533 + return ret; 2548 2534 } 2549 2535 EXPORT_SYMBOL_GPL(m_can_class_resume); 2550 2536
+1
drivers/net/can/m_can/m_can.h
··· 68 68 int (*write_fifo)(struct m_can_classdev *cdev, int addr_offset, 69 69 const void *val, size_t val_count); 70 70 int (*init)(struct m_can_classdev *cdev); 71 + int (*deinit)(struct m_can_classdev *cdev); 71 72 }; 72 73 73 74 struct m_can_tx_op {
+29 -1
drivers/net/can/m_can/tcan4x5x-core.c
··· 92 92 #define TCAN4X5X_MODE_STANDBY BIT(6) 93 93 #define TCAN4X5X_MODE_NORMAL BIT(7) 94 94 95 + #define TCAN4X5X_NWKRQ_VOLTAGE_VIO BIT(19) 96 + 95 97 #define TCAN4X5X_DISABLE_WAKE_MSK (BIT(31) | BIT(30)) 96 98 #define TCAN4X5X_DISABLE_INH_MSK BIT(9) 97 99 ··· 269 267 if (ret) 270 268 return ret; 271 269 270 + if (tcan4x5x->nwkrq_voltage_vio) { 271 + ret = regmap_set_bits(tcan4x5x->regmap, TCAN4X5X_CONFIG, 272 + TCAN4X5X_NWKRQ_VOLTAGE_VIO); 273 + if (ret) 274 + return ret; 275 + } 276 + 272 277 return ret; 273 278 } 279 + 280 + static int tcan4x5x_deinit(struct m_can_classdev *cdev) 281 + { 282 + struct tcan4x5x_priv *tcan4x5x = cdev_to_priv(cdev); 283 + 284 + return regmap_update_bits(tcan4x5x->regmap, TCAN4X5X_CONFIG, 285 + TCAN4X5X_MODE_SEL_MASK, TCAN4X5X_MODE_STANDBY); 286 + }; 274 287 275 288 static int tcan4x5x_disable_wake(struct m_can_classdev *cdev) 276 289 { ··· 335 318 return &tcan4x5x_versions[TCAN4X5X]; 336 319 } 337 320 321 + static void tcan4x5x_get_dt_data(struct m_can_classdev *cdev) 322 + { 323 + struct tcan4x5x_priv *tcan4x5x = cdev_to_priv(cdev); 324 + 325 + tcan4x5x->nwkrq_voltage_vio = 326 + of_property_read_bool(cdev->dev->of_node, "ti,nwkrq-voltage-vio"); 327 + } 328 + 338 329 static int tcan4x5x_get_gpios(struct m_can_classdev *cdev, 339 330 const struct tcan4x5x_version_info *version_info) 340 331 { ··· 384 359 385 360 static const struct m_can_ops tcan4x5x_ops = { 386 361 .init = tcan4x5x_init, 362 + .deinit = tcan4x5x_deinit, 387 363 .read_reg = tcan4x5x_read_reg, 388 364 .write_reg = tcan4x5x_write_reg, 389 365 .write_fifo = tcan4x5x_write_fifo, ··· 418 392 priv->power = NULL; 419 393 } 420 394 421 - m_can_class_get_clocks(mcan_class); 395 + mcan_class->cclk = devm_clk_get(mcan_class->dev, "cclk"); 422 396 if (IS_ERR(mcan_class->cclk)) { 423 397 dev_err(&spi->dev, "no CAN clock source defined\n"); 424 398 freq = TCAN4X5X_EXT_CLK_DEF; ··· 478 452 dev_err(&spi->dev, "Getting gpios failed %pe\n", ERR_PTR(ret)); 479 453 goto out_power; 480 454 } 455 + 456 + tcan4x5x_get_dt_data(mcan_class); 481 457 482 458 tcan4x5x_check_wake(priv); 483 459
+2
drivers/net/can/m_can/tcan4x5x.h
··· 42 42 43 43 struct tcan4x5x_map_buf map_buf_rx; 44 44 struct tcan4x5x_map_buf map_buf_tx; 45 + 46 + bool nwkrq_voltage_vio; 45 47 }; 46 48 47 49 static inline void
+1 -1
drivers/net/can/sun4i_can.c
··· 570 570 else 571 571 state = CAN_STATE_ERROR_ACTIVE; 572 572 } 573 - if (skb && state != CAN_STATE_BUS_OFF) { 573 + if (likely(skb) && state != CAN_STATE_BUS_OFF) { 574 574 cf->can_id |= CAN_ERR_CNT; 575 575 cf->data[6] = txerr; 576 576 cf->data[7] = rxerr;
+2 -1
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
··· 818 818 init_completion(&priv->stop_comp); 819 819 init_completion(&priv->flush_comp); 820 820 init_completion(&priv->get_busparams_comp); 821 - priv->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC; 821 + priv->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC | 822 + CAN_CTRLMODE_BERR_REPORTING; 822 823 823 824 priv->dev = dev; 824 825 priv->netdev = netdev;
+56 -77
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
··· 926 926 } 927 927 } 928 928 929 + static void kvaser_usb_hydra_change_state(struct kvaser_usb_net_priv *priv, 930 + const struct can_berr_counter *bec, 931 + struct can_frame *cf, 932 + enum can_state new_state) 933 + { 934 + struct net_device *netdev = priv->netdev; 935 + enum can_state old_state = priv->can.state; 936 + enum can_state tx_state, rx_state; 937 + 938 + tx_state = (bec->txerr >= bec->rxerr) ? 939 + new_state : CAN_STATE_ERROR_ACTIVE; 940 + rx_state = (bec->txerr <= bec->rxerr) ? 941 + new_state : CAN_STATE_ERROR_ACTIVE; 942 + can_change_state(netdev, cf, tx_state, rx_state); 943 + 944 + if (new_state == CAN_STATE_BUS_OFF && old_state < CAN_STATE_BUS_OFF) { 945 + if (priv->can.restart_ms == 0) 946 + kvaser_usb_hydra_send_simple_cmd_async(priv, CMD_STOP_CHIP_REQ); 947 + 948 + can_bus_off(netdev); 949 + } 950 + 951 + if (priv->can.restart_ms && 952 + old_state >= CAN_STATE_BUS_OFF && 953 + new_state < CAN_STATE_BUS_OFF) { 954 + priv->can.can_stats.restarts++; 955 + if (cf) 956 + cf->can_id |= CAN_ERR_RESTARTED; 957 + } 958 + if (cf && new_state != CAN_STATE_BUS_OFF) { 959 + cf->can_id |= CAN_ERR_CNT; 960 + cf->data[6] = bec->txerr; 961 + cf->data[7] = bec->rxerr; 962 + } 963 + } 964 + 929 965 static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, 930 966 u8 bus_status, 931 967 const struct can_berr_counter *bec) ··· 987 951 return; 988 952 989 953 skb = alloc_can_err_skb(netdev, &cf); 990 - if (skb) { 991 - enum can_state tx_state, rx_state; 992 - 993 - tx_state = (bec->txerr >= bec->rxerr) ? 994 - new_state : CAN_STATE_ERROR_ACTIVE; 995 - rx_state = (bec->txerr <= bec->rxerr) ? 996 - new_state : CAN_STATE_ERROR_ACTIVE; 997 - can_change_state(netdev, cf, tx_state, rx_state); 998 - } 999 - 1000 - if (new_state == CAN_STATE_BUS_OFF && old_state < CAN_STATE_BUS_OFF) { 1001 - if (!priv->can.restart_ms) 1002 - kvaser_usb_hydra_send_simple_cmd_async 1003 - (priv, CMD_STOP_CHIP_REQ); 1004 - 1005 - can_bus_off(netdev); 1006 - } 1007 - 1008 - if (!skb) { 954 + kvaser_usb_hydra_change_state(priv, bec, cf, new_state); 955 + if (skb) 956 + netif_rx(skb); 957 + else 1009 958 netdev_warn(netdev, "No memory left for err_skb\n"); 1010 - return; 1011 - } 1012 - 1013 - if (priv->can.restart_ms && 1014 - old_state >= CAN_STATE_BUS_OFF && 1015 - new_state < CAN_STATE_BUS_OFF) 1016 - priv->can.can_stats.restarts++; 1017 - 1018 - if (new_state != CAN_STATE_BUS_OFF) { 1019 - cf->can_id |= CAN_ERR_CNT; 1020 - cf->data[6] = bec->txerr; 1021 - cf->data[7] = bec->rxerr; 1022 - } 1023 - 1024 - netif_rx(skb); 1025 959 } 1026 960 1027 961 static void kvaser_usb_hydra_state_event(const struct kvaser_usb *dev, ··· 1084 1078 { 1085 1079 struct net_device *netdev = priv->netdev; 1086 1080 struct net_device_stats *stats = &netdev->stats; 1087 - struct can_frame *cf; 1088 - struct sk_buff *skb; 1089 - struct skb_shared_hwtstamps *shhwtstamps; 1081 + struct can_frame *cf = NULL; 1082 + struct sk_buff *skb = NULL; 1090 1083 struct can_berr_counter bec; 1091 1084 enum can_state new_state, old_state; 1092 1085 u8 bus_status; ··· 1101 1096 kvaser_usb_hydra_bus_status_to_can_state(priv, bus_status, &bec, 1102 1097 &new_state); 1103 1098 1104 - skb = alloc_can_err_skb(netdev, &cf); 1099 + if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) 1100 + skb = alloc_can_err_skb(netdev, &cf); 1101 + if (new_state != old_state) 1102 + kvaser_usb_hydra_change_state(priv, &bec, cf, new_state); 1105 1103 1106 - if (new_state != old_state) { 1104 + if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) { 1107 1105 if (skb) { 1108 - enum can_state tx_state, rx_state; 1106 + struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); 1109 1107 1110 - tx_state = (bec.txerr >= bec.rxerr) ? 1111 - new_state : CAN_STATE_ERROR_ACTIVE; 1112 - rx_state = (bec.txerr <= bec.rxerr) ? 1113 - new_state : CAN_STATE_ERROR_ACTIVE; 1114 - 1115 - can_change_state(netdev, cf, tx_state, rx_state); 1116 - 1117 - if (priv->can.restart_ms && 1118 - old_state >= CAN_STATE_BUS_OFF && 1119 - new_state < CAN_STATE_BUS_OFF) 1120 - cf->can_id |= CAN_ERR_RESTARTED; 1121 - } 1122 - 1123 - if (new_state == CAN_STATE_BUS_OFF) { 1124 - if (!priv->can.restart_ms) 1125 - kvaser_usb_hydra_send_simple_cmd_async 1126 - (priv, CMD_STOP_CHIP_REQ); 1127 - 1128 - can_bus_off(netdev); 1108 + shhwtstamps->hwtstamp = hwtstamp; 1109 + cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_CNT; 1110 + cf->data[6] = bec.txerr; 1111 + cf->data[7] = bec.rxerr; 1112 + netif_rx(skb); 1113 + } else { 1114 + stats->rx_dropped++; 1115 + netdev_warn(netdev, "No memory left for err_skb\n"); 1129 1116 } 1130 1117 } 1131 - 1132 - if (!skb) { 1133 - stats->rx_dropped++; 1134 - netdev_warn(netdev, "No memory left for err_skb\n"); 1135 - return; 1136 - } 1137 - 1138 - shhwtstamps = skb_hwtstamps(skb); 1139 - shhwtstamps->hwtstamp = hwtstamp; 1140 - 1141 - cf->can_id |= CAN_ERR_BUSERROR; 1142 - if (new_state != CAN_STATE_BUS_OFF) { 1143 - cf->can_id |= CAN_ERR_CNT; 1144 - cf->data[6] = bec.txerr; 1145 - cf->data[7] = bec.rxerr; 1146 - } 1147 - 1148 - netif_rx(skb); 1149 1118 1150 1119 priv->bec.txerr = bec.txerr; 1151 1120 priv->bec.rxerr = bec.rxerr;
+15 -23
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
··· 1120 1120 static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, 1121 1121 const struct kvaser_usb_err_summary *es) 1122 1122 { 1123 - struct can_frame *cf; 1124 - struct can_frame tmp_cf = { .can_id = CAN_ERR_FLAG, 1125 - .len = CAN_ERR_DLC }; 1126 - struct sk_buff *skb; 1123 + struct can_frame *cf = NULL; 1124 + struct sk_buff *skb = NULL; 1127 1125 struct net_device_stats *stats; 1128 1126 struct kvaser_usb_net_priv *priv; 1129 1127 struct kvaser_usb_net_leaf_priv *leaf; ··· 1141 1143 if (!netif_running(priv->netdev)) 1142 1144 return; 1143 1145 1144 - /* Update all of the CAN interface's state and error counters before 1145 - * trying any memory allocation that can actually fail with -ENOMEM. 1146 - * 1147 - * We send a temporary stack-allocated error CAN frame to 1148 - * can_change_state() for the very same reason. 1149 - * 1150 - * TODO: Split can_change_state() responsibility between updating the 1151 - * CAN interface's state and counters, and the setting up of CAN error 1152 - * frame ID and data to userspace. Remove stack allocation afterwards. 1153 - */ 1154 1146 old_state = priv->can.state; 1155 - kvaser_usb_leaf_rx_error_update_can_state(priv, es, &tmp_cf); 1147 + if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) 1148 + skb = alloc_can_err_skb(priv->netdev, &cf); 1149 + kvaser_usb_leaf_rx_error_update_can_state(priv, es, cf); 1156 1150 new_state = priv->can.state; 1157 1151 1158 1152 /* If there are errors, request status updates periodically as we do ··· 1158 1168 schedule_delayed_work(&leaf->chip_state_req_work, 1159 1169 msecs_to_jiffies(500)); 1160 1170 1161 - skb = alloc_can_err_skb(priv->netdev, &cf); 1162 - if (!skb) { 1163 - stats->rx_dropped++; 1164 - return; 1165 - } 1166 - memcpy(cf, &tmp_cf, sizeof(*cf)); 1167 - 1168 1171 if (new_state != old_state) { 1169 1172 if (es->status & 1170 1173 (M16C_STATE_BUS_OFF | M16C_STATE_BUS_RESET)) { ··· 1170 1187 if (priv->can.restart_ms && 1171 1188 old_state == CAN_STATE_BUS_OFF && 1172 1189 new_state < CAN_STATE_BUS_OFF) { 1173 - cf->can_id |= CAN_ERR_RESTARTED; 1190 + if (cf) 1191 + cf->can_id |= CAN_ERR_RESTARTED; 1174 1192 netif_carrier_on(priv->netdev); 1175 1193 } 1194 + } 1195 + 1196 + if (!skb) { 1197 + if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) { 1198 + stats->rx_dropped++; 1199 + netdev_warn(priv->netdev, "No memory left for err_skb\n"); 1200 + } 1201 + return; 1176 1202 } 1177 1203 1178 1204 switch (dev->driver_info->family) {