Lines Matching full:can
9 #include <linux/can/dev.h>
22 MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
63 /* Kvaser KCAN CAN controller registers */
150 /* FDF bit when controller is in classic CAN mode */
166 /* Controller got CAN FD capability */
185 /* Classic CAN mode */
191 /* CAN FD non-ISO */
408 struct can_priv can; member
424 struct kvaser_pciefd_can *can[KVASER_PCIEFD_MAX_CAN_CHANNELS]; member
510 static inline void kvaser_pciefd_send_kcan_cmd(struct kvaser_pciefd_can *can, u32 cmd) in kvaser_pciefd_send_kcan_cmd() argument
513 FIELD_PREP(KVASER_PCIEFD_KCAN_CMD_SEQ_MASK, ++can->cmd_seq), in kvaser_pciefd_send_kcan_cmd()
514 can->reg_base + KVASER_PCIEFD_KCAN_CMD_REG); in kvaser_pciefd_send_kcan_cmd()
517 static inline void kvaser_pciefd_request_status(struct kvaser_pciefd_can *can) in kvaser_pciefd_request_status() argument
519 kvaser_pciefd_send_kcan_cmd(can, KVASER_PCIEFD_KCAN_CMD_SRQ); in kvaser_pciefd_request_status()
522 static inline void kvaser_pciefd_abort_flush_reset(struct kvaser_pciefd_can *can) in kvaser_pciefd_abort_flush_reset() argument
524 kvaser_pciefd_send_kcan_cmd(can, KVASER_PCIEFD_KCAN_CMD_AT); in kvaser_pciefd_abort_flush_reset()
527 static void kvaser_pciefd_enable_err_gen(struct kvaser_pciefd_can *can) in kvaser_pciefd_enable_err_gen() argument
532 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_enable_err_gen()
533 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_enable_err_gen()
536 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_enable_err_gen()
538 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_enable_err_gen()
541 static void kvaser_pciefd_disable_err_gen(struct kvaser_pciefd_can *can) in kvaser_pciefd_disable_err_gen() argument
546 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_disable_err_gen()
547 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_disable_err_gen()
549 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_disable_err_gen()
550 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_disable_err_gen()
553 static inline void kvaser_pciefd_set_tx_irq(struct kvaser_pciefd_can *can) in kvaser_pciefd_set_tx_irq() argument
563 iowrite32(msk, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_set_tx_irq()
573 static void kvaser_pciefd_setup_controller(struct kvaser_pciefd_can *can) in kvaser_pciefd_setup_controller() argument
578 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_setup_controller()
579 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_setup_controller()
580 if (can->can.ctrlmode & CAN_CTRLMODE_FD) { in kvaser_pciefd_setup_controller()
582 if (can->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO) in kvaser_pciefd_setup_controller()
591 if (can->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) in kvaser_pciefd_setup_controller()
600 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_setup_controller()
602 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_setup_controller()
605 static void kvaser_pciefd_start_controller_flush(struct kvaser_pciefd_can *can) in kvaser_pciefd_start_controller_flush() argument
610 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_start_controller_flush()
611 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_start_controller_flush()
613 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_start_controller_flush()
614 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_start_controller_flush()
617 kvaser_pciefd_abort_flush_reset(can); in kvaser_pciefd_start_controller_flush()
622 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_start_controller_flush()
624 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_start_controller_flush()
626 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_start_controller_flush()
629 static int kvaser_pciefd_bus_on(struct kvaser_pciefd_can *can) in kvaser_pciefd_bus_on() argument
634 del_timer(&can->bec_poll_timer); in kvaser_pciefd_bus_on()
635 if (!completion_done(&can->flush_comp)) in kvaser_pciefd_bus_on()
636 kvaser_pciefd_start_controller_flush(can); in kvaser_pciefd_bus_on()
638 if (!wait_for_completion_timeout(&can->flush_comp, in kvaser_pciefd_bus_on()
640 netdev_err(can->can.dev, "Timeout during bus on flush\n"); in kvaser_pciefd_bus_on()
644 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_bus_on()
645 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_bus_on()
646 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_bus_on()
648 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_bus_on()
649 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_bus_on()
651 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_bus_on()
652 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_bus_on()
654 if (!wait_for_completion_timeout(&can->start_comp, in kvaser_pciefd_bus_on()
656 netdev_err(can->can.dev, "Timeout during bus on reset\n"); in kvaser_pciefd_bus_on()
660 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_bus_on()
661 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_bus_on()
663 kvaser_pciefd_set_tx_irq(can); in kvaser_pciefd_bus_on()
664 kvaser_pciefd_setup_controller(can); in kvaser_pciefd_bus_on()
665 can->can.state = CAN_STATE_ERROR_ACTIVE; in kvaser_pciefd_bus_on()
666 netif_wake_queue(can->can.dev); in kvaser_pciefd_bus_on()
667 can->bec.txerr = 0; in kvaser_pciefd_bus_on()
668 can->bec.rxerr = 0; in kvaser_pciefd_bus_on()
669 can->err_rep_cnt = 0; in kvaser_pciefd_bus_on()
674 static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) in kvaser_pciefd_pwm_stop() argument
680 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_pwm_stop()
681 pwm_ctrl = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_stop()
685 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_stop()
686 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_pwm_stop()
689 static void kvaser_pciefd_pwm_start(struct kvaser_pciefd_can *can) in kvaser_pciefd_pwm_start() argument
695 kvaser_pciefd_pwm_stop(can); in kvaser_pciefd_pwm_start()
696 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_pwm_start()
698 top = can->kv_pcie->bus_freq / (2 * 500000) - 1; in kvaser_pciefd_pwm_start()
702 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_start()
708 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_start()
709 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_pwm_start()
715 struct kvaser_pciefd_can *can = netdev_priv(netdev); in kvaser_pciefd_open() local
721 ret = kvaser_pciefd_bus_on(can); in kvaser_pciefd_open()
732 struct kvaser_pciefd_can *can = netdev_priv(netdev); in kvaser_pciefd_stop() local
736 if (!completion_done(&can->flush_comp)) in kvaser_pciefd_stop()
737 kvaser_pciefd_start_controller_flush(can); in kvaser_pciefd_stop()
739 if (!wait_for_completion_timeout(&can->flush_comp, in kvaser_pciefd_stop()
741 netdev_err(can->can.dev, "Timeout during stop\n"); in kvaser_pciefd_stop()
744 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_stop()
745 del_timer(&can->bec_poll_timer); in kvaser_pciefd_stop()
747 can->can.state = CAN_STATE_STOPPED; in kvaser_pciefd_stop()
754 struct kvaser_pciefd_can *can, in kvaser_pciefd_prepare_tx_packet() argument
759 int seq = can->echo_idx; in kvaser_pciefd_prepare_tx_packet()
762 if (can->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT) in kvaser_pciefd_prepare_tx_packet()
785 can_get_cc_dlc((struct can_frame *)cf, can->can.ctrlmode)); in kvaser_pciefd_prepare_tx_packet()
799 struct kvaser_pciefd_can *can = netdev_priv(netdev); in kvaser_pciefd_start_xmit() local
808 nr_words = kvaser_pciefd_prepare_tx_packet(&packet, can, skb); in kvaser_pciefd_start_xmit()
810 spin_lock_irqsave(&can->echo_lock, irq_flags); in kvaser_pciefd_start_xmit()
812 can_put_echo_skb(skb, netdev, can->echo_idx, 0); in kvaser_pciefd_start_xmit()
815 can->echo_idx = (can->echo_idx + 1) % can->can.echo_skb_max; in kvaser_pciefd_start_xmit()
819 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG); in kvaser_pciefd_start_xmit()
821 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG); in kvaser_pciefd_start_xmit()
827 iowrite32_rep(can->reg_base + in kvaser_pciefd_start_xmit()
831 __raw_writel(data_last, can->reg_base + in kvaser_pciefd_start_xmit()
835 __raw_writel(0, can->reg_base + in kvaser_pciefd_start_xmit()
840 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_start_xmit()
844 if (count >= can->can.echo_skb_max || can->can.echo_skb[can->echo_idx]) in kvaser_pciefd_start_xmit()
846 spin_unlock_irqrestore(&can->echo_lock, irq_flags); in kvaser_pciefd_start_xmit()
851 static int kvaser_pciefd_set_bittiming(struct kvaser_pciefd_can *can, bool data) in kvaser_pciefd_set_bittiming() argument
859 bt = &can->can.data_bittiming; in kvaser_pciefd_set_bittiming()
861 bt = &can->can.bittiming; in kvaser_pciefd_set_bittiming()
868 spin_lock_irqsave(&can->lock, irq_flags); in kvaser_pciefd_set_bittiming()
869 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_set_bittiming()
872 can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_set_bittiming()
874 /* Can only set bittiming if in reset mode */ in kvaser_pciefd_set_bittiming()
875 ret = readl_poll_timeout(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG, in kvaser_pciefd_set_bittiming()
878 spin_unlock_irqrestore(&can->lock, irq_flags); in kvaser_pciefd_set_bittiming()
883 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRD_REG); in kvaser_pciefd_set_bittiming()
885 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRN_REG); in kvaser_pciefd_set_bittiming()
887 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_set_bittiming()
888 spin_unlock_irqrestore(&can->lock, irq_flags); in kvaser_pciefd_set_bittiming()
905 struct kvaser_pciefd_can *can = netdev_priv(ndev); in kvaser_pciefd_set_mode() local
910 if (!can->can.restart_ms) in kvaser_pciefd_set_mode()
911 ret = kvaser_pciefd_bus_on(can); in kvaser_pciefd_set_mode()
923 struct kvaser_pciefd_can *can = netdev_priv(ndev); in kvaser_pciefd_get_berr_counter() local
925 bec->rxerr = can->bec.rxerr; in kvaser_pciefd_get_berr_counter()
926 bec->txerr = can->bec.txerr; in kvaser_pciefd_get_berr_counter()
933 struct kvaser_pciefd_can *can = from_timer(can, data, bec_poll_timer); in kvaser_pciefd_bec_poll_timer() local
935 kvaser_pciefd_enable_err_gen(can); in kvaser_pciefd_bec_poll_timer()
936 kvaser_pciefd_request_status(can); in kvaser_pciefd_bec_poll_timer()
937 can->err_rep_cnt = 0; in kvaser_pciefd_bec_poll_timer()
958 struct kvaser_pciefd_can *can; in kvaser_pciefd_setup_can_ctrls() local
966 can = netdev_priv(netdev); in kvaser_pciefd_setup_can_ctrls()
969 can->reg_base = KVASER_PCIEFD_KCAN_CHX_ADDR(pcie, i); in kvaser_pciefd_setup_can_ctrls()
970 can->kv_pcie = pcie; in kvaser_pciefd_setup_can_ctrls()
971 can->cmd_seq = 0; in kvaser_pciefd_setup_can_ctrls()
972 can->err_rep_cnt = 0; in kvaser_pciefd_setup_can_ctrls()
973 can->bec.txerr = 0; in kvaser_pciefd_setup_can_ctrls()
974 can->bec.rxerr = 0; in kvaser_pciefd_setup_can_ctrls()
976 init_completion(&can->start_comp); in kvaser_pciefd_setup_can_ctrls()
977 init_completion(&can->flush_comp); in kvaser_pciefd_setup_can_ctrls()
978 timer_setup(&can->bec_poll_timer, kvaser_pciefd_bec_poll_timer, 0); in kvaser_pciefd_setup_can_ctrls()
981 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_BUS_LOAD_REG); in kvaser_pciefd_setup_can_ctrls()
985 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_setup_can_ctrls()
987 can->can.clock.freq = pcie->freq; in kvaser_pciefd_setup_can_ctrls()
988 can->can.echo_skb_max = min(KVASER_PCIEFD_CAN_TX_MAX_COUNT, tx_nr_packets_max - 1); in kvaser_pciefd_setup_can_ctrls()
989 can->echo_idx = 0; in kvaser_pciefd_setup_can_ctrls()
990 spin_lock_init(&can->echo_lock); in kvaser_pciefd_setup_can_ctrls()
991 spin_lock_init(&can->lock); in kvaser_pciefd_setup_can_ctrls()
993 can->can.bittiming_const = &kvaser_pciefd_bittiming_const; in kvaser_pciefd_setup_can_ctrls()
994 can->can.data_bittiming_const = &kvaser_pciefd_bittiming_const; in kvaser_pciefd_setup_can_ctrls()
995 can->can.do_set_bittiming = kvaser_pciefd_set_nominal_bittiming; in kvaser_pciefd_setup_can_ctrls()
996 can->can.do_set_data_bittiming = kvaser_pciefd_set_data_bittiming; in kvaser_pciefd_setup_can_ctrls()
997 can->can.do_set_mode = kvaser_pciefd_set_mode; in kvaser_pciefd_setup_can_ctrls()
998 can->can.do_get_berr_counter = kvaser_pciefd_get_berr_counter; in kvaser_pciefd_setup_can_ctrls()
999 can->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | in kvaser_pciefd_setup_can_ctrls()
1004 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_setup_can_ctrls()
1007 "CAN FD not supported as expected %d\n", i); in kvaser_pciefd_setup_can_ctrls()
1014 can->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT; in kvaser_pciefd_setup_can_ctrls()
1019 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_setup_can_ctrls()
1021 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_setup_can_ctrls()
1023 pcie->can[i] = can; in kvaser_pciefd_setup_can_ctrls()
1024 kvaser_pciefd_pwm_start(can); in kvaser_pciefd_setup_can_ctrls()
1035 int ret = register_candev(pcie->can[i]->can.dev); in kvaser_pciefd_reg_candev()
1042 unregister_candev(pcie->can[j]->can.dev); in kvaser_pciefd_reg_candev()
1196 priv = &pcie->can[ch_id]->can; in kvaser_pciefd_handle_data_packet()
1236 static void kvaser_pciefd_change_state(struct kvaser_pciefd_can *can, in kvaser_pciefd_change_state() argument
1242 can_change_state(can->can.dev, cf, tx_state, rx_state); in kvaser_pciefd_change_state()
1245 struct net_device *ndev = can->can.dev; in kvaser_pciefd_change_state()
1248 spin_lock_irqsave(&can->lock, irq_flags); in kvaser_pciefd_change_state()
1249 netif_stop_queue(can->can.dev); in kvaser_pciefd_change_state()
1250 spin_unlock_irqrestore(&can->lock, irq_flags); in kvaser_pciefd_change_state()
1251 /* Prevent CAN controller from auto recover from bus off */ in kvaser_pciefd_change_state()
1252 if (!can->can.restart_ms) { in kvaser_pciefd_change_state()
1253 kvaser_pciefd_start_controller_flush(can); in kvaser_pciefd_change_state()
1285 static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, in kvaser_pciefd_rx_error_frame() argument
1290 struct net_device *ndev = can->can.dev; in kvaser_pciefd_rx_error_frame()
1294 old_state = can->can.state; in kvaser_pciefd_rx_error_frame()
1302 kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state); in kvaser_pciefd_rx_error_frame()
1305 can->can.restart_ms) { in kvaser_pciefd_rx_error_frame()
1306 can->can.can_stats.restarts++; in kvaser_pciefd_rx_error_frame()
1312 can->err_rep_cnt++; in kvaser_pciefd_rx_error_frame()
1313 can->can.can_stats.bus_error++; in kvaser_pciefd_rx_error_frame()
1319 can->bec.txerr = bec.txerr; in kvaser_pciefd_rx_error_frame()
1320 can->bec.rxerr = bec.rxerr; in kvaser_pciefd_rx_error_frame()
1327 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_rx_error_frame()
1340 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_error_packet() local
1346 can = pcie->can[ch_id]; in kvaser_pciefd_handle_error_packet()
1347 kvaser_pciefd_rx_error_frame(can, p); in kvaser_pciefd_handle_error_packet()
1348 if (can->err_rep_cnt >= KVASER_PCIEFD_MAX_ERR_REP) in kvaser_pciefd_handle_error_packet()
1350 kvaser_pciefd_disable_err_gen(can); in kvaser_pciefd_handle_error_packet()
1352 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_error_packet()
1357 static int kvaser_pciefd_handle_status_resp(struct kvaser_pciefd_can *can, in kvaser_pciefd_handle_status_resp() argument
1363 old_state = can->can.state; in kvaser_pciefd_handle_status_resp()
1370 struct net_device *ndev = can->can.dev; in kvaser_pciefd_handle_status_resp()
1380 kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state); in kvaser_pciefd_handle_status_resp()
1383 can->can.restart_ms) { in kvaser_pciefd_handle_status_resp()
1384 can->can.can_stats.restarts++; in kvaser_pciefd_handle_status_resp()
1388 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_handle_status_resp()
1395 can->bec.txerr = bec.txerr; in kvaser_pciefd_handle_status_resp()
1396 can->bec.rxerr = bec.rxerr; in kvaser_pciefd_handle_status_resp()
1399 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_status_resp()
1407 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_status_packet() local
1415 can = pcie->can[ch_id]; in kvaser_pciefd_handle_status_packet()
1417 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_handle_status_packet()
1427 can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_handle_status_packet()
1428 kvaser_pciefd_abort_flush_reset(can); in kvaser_pciefd_handle_status_packet()
1437 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_handle_status_packet()
1441 can->reg_base + KVASER_PCIEFD_KCAN_CTRL_REG); in kvaser_pciefd_handle_status_packet()
1445 kvaser_pciefd_handle_status_resp(can, p); in kvaser_pciefd_handle_status_packet()
1446 if (can->can.state != CAN_STATE_BUS_OFF && in kvaser_pciefd_handle_status_packet()
1447 can->can.state != CAN_STATE_ERROR_ACTIVE) { in kvaser_pciefd_handle_status_packet()
1448 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_status_packet()
1453 if (!completion_done(&can->start_comp)) in kvaser_pciefd_handle_status_packet()
1454 complete(&can->start_comp); in kvaser_pciefd_handle_status_packet()
1460 static void kvaser_pciefd_handle_nack_packet(struct kvaser_pciefd_can *can, in kvaser_pciefd_handle_nack_packet() argument
1466 skb = alloc_can_err_skb(can->can.dev, &cf); in kvaser_pciefd_handle_nack_packet()
1467 can->can.dev->stats.tx_errors++; in kvaser_pciefd_handle_nack_packet()
1471 can->can.can_stats.arbitration_lost++; in kvaser_pciefd_handle_nack_packet()
1478 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_handle_nack_packet()
1481 can->can.dev->stats.rx_dropped++; in kvaser_pciefd_handle_nack_packet()
1482 netdev_warn(can->can.dev, "No memory left for err_skb\n"); in kvaser_pciefd_handle_nack_packet()
1489 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_ack_packet() local
1496 can = pcie->can[ch_id]; in kvaser_pciefd_handle_ack_packet()
1502 kvaser_pciefd_handle_nack_packet(can, p); in kvaser_pciefd_handle_ack_packet()
1507 netdev_dbg(can->can.dev, "Packet was flushed\n"); in kvaser_pciefd_handle_ack_packet()
1514 skb = can->can.echo_skb[echo_idx]; in kvaser_pciefd_handle_ack_packet()
1517 len = can_get_echo_skb(can->can.dev, echo_idx, NULL); in kvaser_pciefd_handle_ack_packet()
1519 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_handle_ack_packet()
1521 if (count < can->can.echo_skb_max && netif_queue_stopped(can->can.dev)) in kvaser_pciefd_handle_ack_packet()
1522 netif_wake_queue(can->can.dev); in kvaser_pciefd_handle_ack_packet()
1525 can->can.dev->stats.tx_bytes += len; in kvaser_pciefd_handle_ack_packet()
1526 can->can.dev->stats.tx_packets++; in kvaser_pciefd_handle_ack_packet()
1536 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_eflush_packet() local
1542 can = pcie->can[ch_id]; in kvaser_pciefd_handle_eflush_packet()
1544 if (!completion_done(&can->flush_comp)) in kvaser_pciefd_handle_eflush_packet()
1545 complete(&can->flush_comp); in kvaser_pciefd_handle_eflush_packet()
1666 static void kvaser_pciefd_transmit_irq(struct kvaser_pciefd_can *can) in kvaser_pciefd_transmit_irq() argument
1668 u32 irq = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_transmit_irq()
1671 netdev_err(can->can.dev, "Tx FIFO overflow\n"); in kvaser_pciefd_transmit_irq()
1674 netdev_err(can->can.dev, in kvaser_pciefd_transmit_irq()
1678 netdev_err(can->can.dev, "CAN FD frame in CAN mode\n"); in kvaser_pciefd_transmit_irq()
1681 netdev_err(can->can.dev, "Rx FIFO overflow\n"); in kvaser_pciefd_transmit_irq()
1683 iowrite32(irq, can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_transmit_irq()
1703 kvaser_pciefd_transmit_irq(pcie->can[i]); in kvaser_pciefd_irq_handler()
1723 struct kvaser_pciefd_can *can = pcie->can[i]; in kvaser_pciefd_teardown_can_ctrls() local
1725 if (can) { in kvaser_pciefd_teardown_can_ctrls()
1726 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_teardown_can_ctrls()
1727 kvaser_pciefd_pwm_stop(can); in kvaser_pciefd_teardown_can_ctrls()
1728 free_candev(can->can.dev); in kvaser_pciefd_teardown_can_ctrls()
1849 struct kvaser_pciefd_can *can = pcie->can[i]; in kvaser_pciefd_remove_all_ctrls() local
1851 if (can) { in kvaser_pciefd_remove_all_ctrls()
1852 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_remove_all_ctrls()
1853 unregister_candev(can->can.dev); in kvaser_pciefd_remove_all_ctrls()
1854 del_timer(&can->bec_poll_timer); in kvaser_pciefd_remove_all_ctrls()
1855 kvaser_pciefd_pwm_stop(can); in kvaser_pciefd_remove_all_ctrls()
1856 free_candev(can->can.dev); in kvaser_pciefd_remove_all_ctrls()