Lines Matching full:can

9 #include <linux/can/dev.h>
22 MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
56 /* Kvaser KCAN CAN controller registers */
143 /* FDF bit when controller is in classic CAN mode */
159 /* Controller got CAN FD capability */
178 /* Classic CAN mode */
184 /* CAN FD non-ISO */
371 struct can_priv can; member
387 struct kvaser_pciefd_can *can[KVASER_PCIEFD_MAX_CAN_CHANNELS]; member
465 static inline void kvaser_pciefd_send_kcan_cmd(struct kvaser_pciefd_can *can, u32 cmd) in kvaser_pciefd_send_kcan_cmd() argument
468 FIELD_PREP(KVASER_PCIEFD_KCAN_CMD_SEQ_MASK, ++can->cmd_seq), in kvaser_pciefd_send_kcan_cmd()
469 can->reg_base + KVASER_PCIEFD_KCAN_CMD_REG); in kvaser_pciefd_send_kcan_cmd()
472 static inline void kvaser_pciefd_request_status(struct kvaser_pciefd_can *can) in kvaser_pciefd_request_status() argument
474 kvaser_pciefd_send_kcan_cmd(can, KVASER_PCIEFD_KCAN_CMD_SRQ); in kvaser_pciefd_request_status()
477 static inline void kvaser_pciefd_abort_flush_reset(struct kvaser_pciefd_can *can) in kvaser_pciefd_abort_flush_reset() argument
479 kvaser_pciefd_send_kcan_cmd(can, KVASER_PCIEFD_KCAN_CMD_AT); in kvaser_pciefd_abort_flush_reset()
482 static void kvaser_pciefd_enable_err_gen(struct kvaser_pciefd_can *can) in kvaser_pciefd_enable_err_gen() argument
487 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_enable_err_gen()
488 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_enable_err_gen()
491 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_enable_err_gen()
493 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_enable_err_gen()
496 static void kvaser_pciefd_disable_err_gen(struct kvaser_pciefd_can *can) in kvaser_pciefd_disable_err_gen() argument
501 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_disable_err_gen()
502 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_disable_err_gen()
504 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_disable_err_gen()
505 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_disable_err_gen()
508 static void kvaser_pciefd_set_tx_irq(struct kvaser_pciefd_can *can) in kvaser_pciefd_set_tx_irq() argument
518 iowrite32(msk, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_set_tx_irq()
528 static void kvaser_pciefd_setup_controller(struct kvaser_pciefd_can *can) in kvaser_pciefd_setup_controller() argument
533 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_setup_controller()
534 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_setup_controller()
535 if (can->can.ctrlmode & CAN_CTRLMODE_FD) { in kvaser_pciefd_setup_controller()
537 if (can->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO) in kvaser_pciefd_setup_controller()
546 if (can->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) in kvaser_pciefd_setup_controller()
555 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_setup_controller()
557 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_setup_controller()
560 static void kvaser_pciefd_start_controller_flush(struct kvaser_pciefd_can *can) in kvaser_pciefd_start_controller_flush() argument
565 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_start_controller_flush()
566 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_start_controller_flush()
568 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_start_controller_flush()
569 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_start_controller_flush()
572 kvaser_pciefd_abort_flush_reset(can); in kvaser_pciefd_start_controller_flush()
577 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_start_controller_flush()
579 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_start_controller_flush()
581 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_start_controller_flush()
584 static int kvaser_pciefd_bus_on(struct kvaser_pciefd_can *can) in kvaser_pciefd_bus_on() argument
589 del_timer(&can->bec_poll_timer); in kvaser_pciefd_bus_on()
590 if (!completion_done(&can->flush_comp)) in kvaser_pciefd_bus_on()
591 kvaser_pciefd_start_controller_flush(can); in kvaser_pciefd_bus_on()
593 if (!wait_for_completion_timeout(&can->flush_comp, in kvaser_pciefd_bus_on()
595 netdev_err(can->can.dev, "Timeout during bus on flush\n"); in kvaser_pciefd_bus_on()
599 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_bus_on()
600 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_bus_on()
601 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_bus_on()
603 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_bus_on()
604 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_bus_on()
606 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_bus_on()
607 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_bus_on()
609 if (!wait_for_completion_timeout(&can->start_comp, in kvaser_pciefd_bus_on()
611 netdev_err(can->can.dev, "Timeout during bus on reset\n"); in kvaser_pciefd_bus_on()
615 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_bus_on()
616 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_bus_on()
618 kvaser_pciefd_set_tx_irq(can); in kvaser_pciefd_bus_on()
619 kvaser_pciefd_setup_controller(can); in kvaser_pciefd_bus_on()
620 can->can.state = CAN_STATE_ERROR_ACTIVE; in kvaser_pciefd_bus_on()
621 netif_wake_queue(can->can.dev); in kvaser_pciefd_bus_on()
622 can->bec.txerr = 0; in kvaser_pciefd_bus_on()
623 can->bec.rxerr = 0; in kvaser_pciefd_bus_on()
624 can->err_rep_cnt = 0; in kvaser_pciefd_bus_on()
629 static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) in kvaser_pciefd_pwm_stop() argument
635 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_pwm_stop()
636 pwm_ctrl = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_stop()
640 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_stop()
641 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_pwm_stop()
644 static void kvaser_pciefd_pwm_start(struct kvaser_pciefd_can *can) in kvaser_pciefd_pwm_start() argument
650 kvaser_pciefd_pwm_stop(can); in kvaser_pciefd_pwm_start()
651 spin_lock_irqsave(&can->lock, irq); in kvaser_pciefd_pwm_start()
653 top = can->kv_pcie->bus_freq / (2 * 500000) - 1; in kvaser_pciefd_pwm_start()
657 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_start()
663 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG); in kvaser_pciefd_pwm_start()
664 spin_unlock_irqrestore(&can->lock, irq); in kvaser_pciefd_pwm_start()
670 struct kvaser_pciefd_can *can = netdev_priv(netdev); in kvaser_pciefd_open() local
676 err = kvaser_pciefd_bus_on(can); in kvaser_pciefd_open()
687 struct kvaser_pciefd_can *can = netdev_priv(netdev); in kvaser_pciefd_stop() local
691 if (!completion_done(&can->flush_comp)) in kvaser_pciefd_stop()
692 kvaser_pciefd_start_controller_flush(can); in kvaser_pciefd_stop()
694 if (!wait_for_completion_timeout(&can->flush_comp, in kvaser_pciefd_stop()
696 netdev_err(can->can.dev, "Timeout during stop\n"); in kvaser_pciefd_stop()
699 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_stop()
700 del_timer(&can->bec_poll_timer); in kvaser_pciefd_stop()
702 can->can.state = CAN_STATE_STOPPED; in kvaser_pciefd_stop()
709 struct kvaser_pciefd_can *can, in kvaser_pciefd_prepare_tx_packet() argument
714 int seq = can->echo_idx; in kvaser_pciefd_prepare_tx_packet()
717 if (can->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT) in kvaser_pciefd_prepare_tx_packet()
740 can_get_cc_dlc((struct can_frame *)cf, can->can.ctrlmode)); in kvaser_pciefd_prepare_tx_packet()
754 struct kvaser_pciefd_can *can = netdev_priv(netdev); in kvaser_pciefd_start_xmit() local
763 nr_words = kvaser_pciefd_prepare_tx_packet(&packet, can, skb); in kvaser_pciefd_start_xmit()
765 spin_lock_irqsave(&can->echo_lock, irq_flags); in kvaser_pciefd_start_xmit()
767 can_put_echo_skb(skb, netdev, can->echo_idx, 0); in kvaser_pciefd_start_xmit()
770 can->echo_idx = (can->echo_idx + 1) % can->can.echo_skb_max; in kvaser_pciefd_start_xmit()
774 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG); in kvaser_pciefd_start_xmit()
776 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG); in kvaser_pciefd_start_xmit()
782 iowrite32_rep(can->reg_base + in kvaser_pciefd_start_xmit()
786 __raw_writel(data_last, can->reg_base + in kvaser_pciefd_start_xmit()
790 __raw_writel(0, can->reg_base + in kvaser_pciefd_start_xmit()
795 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_start_xmit()
799 if (count >= can->can.echo_skb_max || can->can.echo_skb[can->echo_idx]) in kvaser_pciefd_start_xmit()
801 spin_unlock_irqrestore(&can->echo_lock, irq_flags); in kvaser_pciefd_start_xmit()
806 static int kvaser_pciefd_set_bittiming(struct kvaser_pciefd_can *can, bool data) in kvaser_pciefd_set_bittiming() argument
814 bt = &can->can.data_bittiming; in kvaser_pciefd_set_bittiming()
816 bt = &can->can.bittiming; in kvaser_pciefd_set_bittiming()
823 spin_lock_irqsave(&can->lock, irq_flags); in kvaser_pciefd_set_bittiming()
824 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_set_bittiming()
827 can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_set_bittiming()
829 /* Can only set bittiming if in reset mode */ in kvaser_pciefd_set_bittiming()
830 ret = readl_poll_timeout(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG, in kvaser_pciefd_set_bittiming()
833 spin_unlock_irqrestore(&can->lock, irq_flags); in kvaser_pciefd_set_bittiming()
838 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRD_REG); in kvaser_pciefd_set_bittiming()
840 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRN_REG); in kvaser_pciefd_set_bittiming()
842 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG); in kvaser_pciefd_set_bittiming()
843 spin_unlock_irqrestore(&can->lock, irq_flags); in kvaser_pciefd_set_bittiming()
860 struct kvaser_pciefd_can *can = netdev_priv(ndev); in kvaser_pciefd_set_mode() local
865 if (!can->can.restart_ms) in kvaser_pciefd_set_mode()
866 ret = kvaser_pciefd_bus_on(can); in kvaser_pciefd_set_mode()
878 struct kvaser_pciefd_can *can = netdev_priv(ndev); in kvaser_pciefd_get_berr_counter() local
880 bec->rxerr = can->bec.rxerr; in kvaser_pciefd_get_berr_counter()
881 bec->txerr = can->bec.txerr; in kvaser_pciefd_get_berr_counter()
888 struct kvaser_pciefd_can *can = from_timer(can, data, bec_poll_timer); in kvaser_pciefd_bec_poll_timer() local
890 kvaser_pciefd_enable_err_gen(can); in kvaser_pciefd_bec_poll_timer()
891 kvaser_pciefd_request_status(can); in kvaser_pciefd_bec_poll_timer()
892 can->err_rep_cnt = 0; in kvaser_pciefd_bec_poll_timer()
913 struct kvaser_pciefd_can *can; in kvaser_pciefd_setup_can_ctrls() local
921 can = netdev_priv(netdev); in kvaser_pciefd_setup_can_ctrls()
924 can->reg_base = KVASER_PCIEFD_KCAN_CHX_ADDR(pcie, i); in kvaser_pciefd_setup_can_ctrls()
925 can->kv_pcie = pcie; in kvaser_pciefd_setup_can_ctrls()
926 can->cmd_seq = 0; in kvaser_pciefd_setup_can_ctrls()
927 can->err_rep_cnt = 0; in kvaser_pciefd_setup_can_ctrls()
928 can->bec.txerr = 0; in kvaser_pciefd_setup_can_ctrls()
929 can->bec.rxerr = 0; in kvaser_pciefd_setup_can_ctrls()
931 init_completion(&can->start_comp); in kvaser_pciefd_setup_can_ctrls()
932 init_completion(&can->flush_comp); in kvaser_pciefd_setup_can_ctrls()
933 timer_setup(&can->bec_poll_timer, kvaser_pciefd_bec_poll_timer, 0); in kvaser_pciefd_setup_can_ctrls()
936 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_BUS_LOAD_REG); in kvaser_pciefd_setup_can_ctrls()
940 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_setup_can_ctrls()
942 can->can.clock.freq = pcie->freq; in kvaser_pciefd_setup_can_ctrls()
943 can->can.echo_skb_max = min(KVASER_PCIEFD_CAN_TX_MAX_COUNT, tx_nr_packets_max - 1); in kvaser_pciefd_setup_can_ctrls()
944 can->echo_idx = 0; in kvaser_pciefd_setup_can_ctrls()
945 spin_lock_init(&can->echo_lock); in kvaser_pciefd_setup_can_ctrls()
946 spin_lock_init(&can->lock); in kvaser_pciefd_setup_can_ctrls()
948 can->can.bittiming_const = &kvaser_pciefd_bittiming_const; in kvaser_pciefd_setup_can_ctrls()
949 can->can.data_bittiming_const = &kvaser_pciefd_bittiming_const; in kvaser_pciefd_setup_can_ctrls()
950 can->can.do_set_bittiming = kvaser_pciefd_set_nominal_bittiming; in kvaser_pciefd_setup_can_ctrls()
951 can->can.do_set_data_bittiming = kvaser_pciefd_set_data_bittiming; in kvaser_pciefd_setup_can_ctrls()
952 can->can.do_set_mode = kvaser_pciefd_set_mode; in kvaser_pciefd_setup_can_ctrls()
953 can->can.do_get_berr_counter = kvaser_pciefd_get_berr_counter; in kvaser_pciefd_setup_can_ctrls()
954 can->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | in kvaser_pciefd_setup_can_ctrls()
959 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_setup_can_ctrls()
962 "CAN FD not supported as expected %d\n", i); in kvaser_pciefd_setup_can_ctrls()
969 can->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT; in kvaser_pciefd_setup_can_ctrls()
974 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_setup_can_ctrls()
976 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_setup_can_ctrls()
978 pcie->can[i] = can; in kvaser_pciefd_setup_can_ctrls()
979 kvaser_pciefd_pwm_start(can); in kvaser_pciefd_setup_can_ctrls()
990 int err = register_candev(pcie->can[i]->can.dev); in kvaser_pciefd_reg_candev()
997 unregister_candev(pcie->can[j]->can.dev); in kvaser_pciefd_reg_candev()
1133 priv = &pcie->can[ch_id]->can; in kvaser_pciefd_handle_data_packet()
1173 static void kvaser_pciefd_change_state(struct kvaser_pciefd_can *can, in kvaser_pciefd_change_state() argument
1179 can_change_state(can->can.dev, cf, tx_state, rx_state); in kvaser_pciefd_change_state()
1182 struct net_device *ndev = can->can.dev; in kvaser_pciefd_change_state()
1185 spin_lock_irqsave(&can->lock, irq_flags); in kvaser_pciefd_change_state()
1186 netif_stop_queue(can->can.dev); in kvaser_pciefd_change_state()
1187 spin_unlock_irqrestore(&can->lock, irq_flags); in kvaser_pciefd_change_state()
1188 /* Prevent CAN controller from auto recover from bus off */ in kvaser_pciefd_change_state()
1189 if (!can->can.restart_ms) { in kvaser_pciefd_change_state()
1190 kvaser_pciefd_start_controller_flush(can); in kvaser_pciefd_change_state()
1222 static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, in kvaser_pciefd_rx_error_frame() argument
1227 struct net_device *ndev = can->can.dev; in kvaser_pciefd_rx_error_frame()
1231 old_state = can->can.state; in kvaser_pciefd_rx_error_frame()
1239 kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state); in kvaser_pciefd_rx_error_frame()
1242 can->can.restart_ms) { in kvaser_pciefd_rx_error_frame()
1243 can->can.can_stats.restarts++; in kvaser_pciefd_rx_error_frame()
1249 can->err_rep_cnt++; in kvaser_pciefd_rx_error_frame()
1250 can->can.can_stats.bus_error++; in kvaser_pciefd_rx_error_frame()
1256 can->bec.txerr = bec.txerr; in kvaser_pciefd_rx_error_frame()
1257 can->bec.rxerr = bec.rxerr; in kvaser_pciefd_rx_error_frame()
1264 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_rx_error_frame()
1277 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_error_packet() local
1283 can = pcie->can[ch_id]; in kvaser_pciefd_handle_error_packet()
1284 kvaser_pciefd_rx_error_frame(can, p); in kvaser_pciefd_handle_error_packet()
1285 if (can->err_rep_cnt >= KVASER_PCIEFD_MAX_ERR_REP) in kvaser_pciefd_handle_error_packet()
1287 kvaser_pciefd_disable_err_gen(can); in kvaser_pciefd_handle_error_packet()
1289 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_error_packet()
1294 static int kvaser_pciefd_handle_status_resp(struct kvaser_pciefd_can *can, in kvaser_pciefd_handle_status_resp() argument
1300 old_state = can->can.state; in kvaser_pciefd_handle_status_resp()
1307 struct net_device *ndev = can->can.dev; in kvaser_pciefd_handle_status_resp()
1317 kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state); in kvaser_pciefd_handle_status_resp()
1320 can->can.restart_ms) { in kvaser_pciefd_handle_status_resp()
1321 can->can.can_stats.restarts++; in kvaser_pciefd_handle_status_resp()
1325 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_handle_status_resp()
1332 can->bec.txerr = bec.txerr; in kvaser_pciefd_handle_status_resp()
1333 can->bec.rxerr = bec.rxerr; in kvaser_pciefd_handle_status_resp()
1336 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_status_resp()
1344 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_status_packet() local
1352 can = pcie->can[ch_id]; in kvaser_pciefd_handle_status_packet()
1354 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_handle_status_packet()
1364 can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_handle_status_packet()
1365 kvaser_pciefd_abort_flush_reset(can); in kvaser_pciefd_handle_status_packet()
1374 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_handle_status_packet()
1378 can->reg_base + KVASER_PCIEFD_KCAN_CTRL_REG); in kvaser_pciefd_handle_status_packet()
1382 kvaser_pciefd_handle_status_resp(can, p); in kvaser_pciefd_handle_status_packet()
1383 if (can->can.state != CAN_STATE_BUS_OFF && in kvaser_pciefd_handle_status_packet()
1384 can->can.state != CAN_STATE_ERROR_ACTIVE) { in kvaser_pciefd_handle_status_packet()
1385 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_status_packet()
1390 if (!completion_done(&can->start_comp)) in kvaser_pciefd_handle_status_packet()
1391 complete(&can->start_comp); in kvaser_pciefd_handle_status_packet()
1397 static void kvaser_pciefd_handle_nack_packet(struct kvaser_pciefd_can *can, in kvaser_pciefd_handle_nack_packet() argument
1403 skb = alloc_can_err_skb(can->can.dev, &cf); in kvaser_pciefd_handle_nack_packet()
1404 can->can.dev->stats.tx_errors++; in kvaser_pciefd_handle_nack_packet()
1408 can->can.can_stats.arbitration_lost++; in kvaser_pciefd_handle_nack_packet()
1415 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_handle_nack_packet()
1418 can->can.dev->stats.rx_dropped++; in kvaser_pciefd_handle_nack_packet()
1419 netdev_warn(can->can.dev, "No memory left for err_skb\n"); in kvaser_pciefd_handle_nack_packet()
1426 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_ack_packet() local
1433 can = pcie->can[ch_id]; in kvaser_pciefd_handle_ack_packet()
1439 kvaser_pciefd_handle_nack_packet(can, p); in kvaser_pciefd_handle_ack_packet()
1444 netdev_dbg(can->can.dev, "Packet was flushed\n"); in kvaser_pciefd_handle_ack_packet()
1451 skb = can->can.echo_skb[echo_idx]; in kvaser_pciefd_handle_ack_packet()
1454 len = can_get_echo_skb(can->can.dev, echo_idx, NULL); in kvaser_pciefd_handle_ack_packet()
1456 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_handle_ack_packet()
1458 if (count < can->can.echo_skb_max && netif_queue_stopped(can->can.dev)) in kvaser_pciefd_handle_ack_packet()
1459 netif_wake_queue(can->can.dev); in kvaser_pciefd_handle_ack_packet()
1462 can->can.dev->stats.tx_bytes += len; in kvaser_pciefd_handle_ack_packet()
1463 can->can.dev->stats.tx_packets++; in kvaser_pciefd_handle_ack_packet()
1473 struct kvaser_pciefd_can *can; in kvaser_pciefd_handle_eflush_packet() local
1479 can = pcie->can[ch_id]; in kvaser_pciefd_handle_eflush_packet()
1481 if (!completion_done(&can->flush_comp)) in kvaser_pciefd_handle_eflush_packet()
1482 complete(&can->flush_comp); in kvaser_pciefd_handle_eflush_packet()
1603 static void kvaser_pciefd_transmit_irq(struct kvaser_pciefd_can *can) in kvaser_pciefd_transmit_irq() argument
1605 u32 irq = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_transmit_irq()
1608 netdev_err(can->can.dev, "Tx FIFO overflow\n"); in kvaser_pciefd_transmit_irq()
1611 netdev_err(can->can.dev, in kvaser_pciefd_transmit_irq()
1615 netdev_err(can->can.dev, "CAN FD frame in CAN mode\n"); in kvaser_pciefd_transmit_irq()
1618 netdev_err(can->can.dev, "Rx FIFO overflow\n"); in kvaser_pciefd_transmit_irq()
1620 iowrite32(irq, can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_transmit_irq()
1640 kvaser_pciefd_transmit_irq(pcie->can[i]); in kvaser_pciefd_irq_handler()
1660 struct kvaser_pciefd_can *can = pcie->can[i]; in kvaser_pciefd_teardown_can_ctrls() local
1662 if (can) { in kvaser_pciefd_teardown_can_ctrls()
1663 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_teardown_can_ctrls()
1664 kvaser_pciefd_pwm_stop(can); in kvaser_pciefd_teardown_can_ctrls()
1665 free_candev(can->can.dev); in kvaser_pciefd_teardown_can_ctrls()
1770 struct kvaser_pciefd_can *can = pcie->can[i]; in kvaser_pciefd_remove_all_ctrls() local
1772 if (can) { in kvaser_pciefd_remove_all_ctrls()
1773 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_remove_all_ctrls()
1774 unregister_candev(can->can.dev); in kvaser_pciefd_remove_all_ctrls()
1775 del_timer(&can->bec_poll_timer); in kvaser_pciefd_remove_all_ctrls()
1776 kvaser_pciefd_pwm_stop(can); in kvaser_pciefd_remove_all_ctrls()
1777 free_candev(can->can.dev); in kvaser_pciefd_remove_all_ctrls()