Lines Matching +full:canfd +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2005 Marc Kleine-Budde, Pengutronix
4 * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com>
13 #include <linux/can/can-ml.h>
24 if (new_state <= priv->state) in can_update_state_error_stats()
29 priv->can_stats.error_warning++; in can_update_state_error_stats()
32 priv->can_stats.error_passive++; in can_update_state_error_stats()
35 priv->can_stats.bus_off++; in can_update_state_error_stats()
110 *tx_state = can_state_err_to_state(bec->txerr); in can_state_get_by_berr_counter()
111 *rx_state = can_state_err_to_state(bec->rxerr); in can_state_get_by_berr_counter()
121 if (unlikely(new_state == priv->state)) { in can_change_state()
127 can_get_state_str(priv->state), priv->state, in can_change_state()
131 priv->state = new_state; in can_change_state()
137 cf->can_id |= CAN_ERR_BUSOFF; in can_change_state()
141 cf->can_id |= CAN_ERR_CRTL; in can_change_state()
142 cf->data[1] |= tx_state >= rx_state ? in can_change_state()
144 cf->data[1] |= tx_state <= rx_state ? in can_change_state()
149 /* CAN device restart for bus-off recovery */
158 netdev_err(dev, "Attempt to restart for bus-off recovery, but carrier is OK?\n"); in can_restart()
160 /* No synchronization needed because the device is bus-off and in can_restart()
168 cf->can_id |= CAN_ERR_RESTARTED; in can_restart()
174 err = priv->do_set_mode(dev, CAN_MODE_START); in can_restart()
180 priv->can_stats.restarts++; in can_restart()
190 can_restart(priv->dev); in can_restart_work()
198 * disabled and the device is in the bus-off state in can_restart_now()
200 if (priv->restart_ms) in can_restart_now()
201 return -EINVAL; in can_restart_now()
202 if (priv->state != CAN_STATE_BUS_OFF) in can_restart_now()
203 return -EBUSY; in can_restart_now()
205 cancel_delayed_work_sync(&priv->restart_work); in can_restart_now()
211 /* CAN bus-off
213 * This functions should be called when the device goes bus-off to
215 * If enabled, a timer is started to trigger bus-off recovery.
221 if (priv->restart_ms) in can_bus_off()
222 netdev_info(dev, "bus-off, scheduling restart in %d ms\n", in can_bus_off()
223 priv->restart_ms); in can_bus_off()
225 netdev_info(dev, "bus-off\n"); in can_bus_off()
229 if (priv->restart_ms) in can_bus_off()
230 schedule_delayed_work(&priv->restart_work, in can_bus_off()
231 msecs_to_jiffies(priv->restart_ms)); in can_bus_off()
237 dev->type = ARPHRD_CAN; in can_setup()
238 dev->mtu = CAN_MTU; in can_setup()
239 dev->hard_header_len = 0; in can_setup()
240 dev->addr_len = 0; in can_setup()
241 dev->tx_queue_len = 10; in can_setup()
243 /* New-style flags. */ in can_setup()
244 dev->flags = IFF_NOARP; in can_setup()
245 dev->features = NETIF_F_HW_CSUM; in can_setup()
261 * +-------------------------+ in alloc_candev_mqs()
263 * +-------------------------+ in alloc_candev_mqs()
265 * +-------------------------+ in alloc_candev_mqs()
267 * +-------------------------+ in alloc_candev_mqs()
282 priv->dev = dev; in alloc_candev_mqs()
288 priv->echo_skb_max = echo_skb_max; in alloc_candev_mqs()
289 priv->echo_skb = (void *)priv + in alloc_candev_mqs()
290 (size - echo_skb_max * sizeof(struct sk_buff *)); in alloc_candev_mqs()
293 priv->state = CAN_STATE_STOPPED; in alloc_candev_mqs()
295 INIT_DELAYED_WORK(&priv->restart_work, can_restart_work); in alloc_candev_mqs()
308 /* changing MTU and control mode for CAN/CANFD devices */
315 if (dev->flags & IFF_UP) in can_change_mtu()
316 return -EBUSY; in can_change_mtu()
318 /* allow change of MTU according to the CANFD ability of the device */ in can_change_mtu()
321 /* 'CANFD-only' controllers can not switch to CAN_MTU */ in can_change_mtu()
323 return -EINVAL; in can_change_mtu()
325 priv->ctrlmode &= ~CAN_CTRLMODE_FD; in can_change_mtu()
329 /* check for potential CANFD ability */ in can_change_mtu()
330 if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) && in can_change_mtu()
332 return -EINVAL; in can_change_mtu()
334 priv->ctrlmode |= CAN_CTRLMODE_FD; in can_change_mtu()
338 return -EINVAL; in can_change_mtu()
341 WRITE_ONCE(dev->mtu, new_mtu); in can_change_mtu()
355 if (copy_from_user(&hwts_cfg, ifr->ifr_data, sizeof(hwts_cfg))) in can_eth_ioctl_hwts()
356 return -EFAULT; in can_eth_ioctl_hwts()
360 return -ERANGE; in can_eth_ioctl_hwts()
365 if (copy_to_user(ifr->ifr_data, &hwts_cfg, sizeof(hwts_cfg))) in can_eth_ioctl_hwts()
366 return -EFAULT; in can_eth_ioctl_hwts()
370 return -EOPNOTSUPP; in can_eth_ioctl_hwts()
381 info->so_timestamping = in can_ethtool_op_get_ts_info_hwts()
386 info->tx_types = BIT(HWTSTAMP_TX_ON); in can_ethtool_op_get_ts_info_hwts()
387 info->rx_filters = BIT(HWTSTAMP_FILTER_ALL); in can_ethtool_op_get_ts_info_hwts()
402 if (!priv->bittiming.bitrate) { in open_candev()
403 netdev_err(dev, "bit-timing not yet defined\n"); in open_candev()
404 return -EINVAL; in open_candev()
408 if ((priv->ctrlmode & CAN_CTRLMODE_FD) && in open_candev()
409 (!priv->data_bittiming.bitrate || in open_candev()
410 priv->data_bittiming.bitrate < priv->bittiming.bitrate)) { in open_candev()
411 netdev_err(dev, "incorrect/missing data bit-timing\n"); in open_candev()
412 return -EINVAL; in open_candev()
415 /* Switch carrier on if device was stopped while in bus-off state */ in open_candev()
432 struct device_node *np = dev->dev.parent->of_node; in of_can_transceiver()
435 dn = of_get_child_by_name(np, "can-transceiver"); in of_can_transceiver()
439 ret = of_property_read_u32(dn, "max-bitrate", &priv->bitrate_max); in of_can_transceiver()
441 if ((ret && ret != -EINVAL) || (!ret && !priv->bitrate_max)) in of_can_transceiver()
456 cancel_delayed_work_sync(&priv->restart_work); in close_candev()
466 if (term == priv->termination_gpio_ohms[CAN_TERMINATION_GPIO_ENABLED]) in can_set_termination()
467 set = 1; in can_set_termination()
471 gpiod_set_value(priv->termination_gpio, set); in can_set_termination()
479 struct device *dev = ndev->dev.parent; in can_get_termination()
490 "Cannot get termination-gpios\n"); in can_get_termination()
495 ret = device_property_read_u32(dev, "termination-ohms", &term); in can_get_termination()
497 netdev_err(ndev, "Cannot get termination-ohms: %pe\n", in can_get_termination()
503 netdev_err(ndev, "Invalid termination-ohms value (%u > %u)\n", in can_get_termination()
505 return -EINVAL; in can_get_termination()
508 priv->termination_const_cnt = ARRAY_SIZE(priv->termination_gpio_ohms); in can_get_termination()
509 priv->termination_const = priv->termination_gpio_ohms; in can_get_termination()
510 priv->termination_gpio = gpio; in can_get_termination()
511 priv->termination_gpio_ohms[CAN_TERMINATION_GPIO_DISABLED] = in can_get_termination()
513 priv->termination_gpio_ohms[CAN_TERMINATION_GPIO_ENABLED] = term; in can_get_termination()
514 priv->do_set_termination = can_set_termination; in can_get_termination()
525 if (!btc->sjw_max) in can_bittiming_const_valid()
541 if ((!priv->termination_const != !priv->termination_const_cnt) || in register_candev()
542 (!priv->termination_const != !priv->do_set_termination)) in register_candev()
543 return -EINVAL; in register_candev()
545 if (!priv->bitrate_const != !priv->bitrate_const_cnt) in register_candev()
546 return -EINVAL; in register_candev()
548 if (!priv->data_bitrate_const != !priv->data_bitrate_const_cnt) in register_candev()
549 return -EINVAL; in register_candev()
552 if ((priv->bitrate_const || priv->data_bitrate_const) && in register_candev()
553 (priv->bittiming_const || priv->data_bittiming_const)) in register_candev()
554 return -EINVAL; in register_candev()
556 if (!can_bittiming_const_valid(priv->bittiming_const) || in register_candev()
557 !can_bittiming_const_valid(priv->data_bittiming_const)) in register_candev()
558 return -EINVAL; in register_candev()
560 if (!priv->termination_const) { in register_candev()
566 dev->rtnl_link_ops = &can_link_ops; in register_candev()
585 if (dev->type != ARPHRD_CAN || dev->rtnl_link_ops != &can_link_ops) in safe_candev_priv()