Lines Matching +full:pcie +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
4 * - Kvaser linux pciefd driver (version 5.42)
5 * - PEAK linux canfd driver
22 MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
54 /* Altera SerDes Enable 64-bit DMA address translation */
96 #define KVASER_PCIEFD_SYSID_BUILD_SEQ_MASK GENMASK(15, 1)
98 /* Reset DMA buffer 0, 1 and FIFO offset */
103 /* DMA underflow, buffer 0 and 1 */
106 /* DMA overflow, buffer 0 and 1 */
109 /* DMA packet done, buffer 0 and 1 */
134 #define KVASER_PCIEFD_KCAN_CMD_AT BIT(1)
155 #define KVASER_PCIEFD_KCAN_IRQ_TAE BIT(1)
168 /* Controller got one-shot capability */
191 /* CAN FD non-ISO */
261 #define KVASER_PCIEFD_GET_BLOCK_ADDR(pcie, block) \ argument
262 ((pcie)->reg_base + (pcie)->driver_data->address_offset->block)
263 #define KVASER_PCIEFD_PCI_IEN_ADDR(pcie) \ argument
264 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), pci_ien))
265 #define KVASER_PCIEFD_PCI_IRQ_ADDR(pcie) \ argument
266 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), pci_irq))
267 #define KVASER_PCIEFD_SERDES_ADDR(pcie) \ argument
268 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), serdes))
269 #define KVASER_PCIEFD_SYSID_ADDR(pcie) \ argument
270 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), sysid))
271 #define KVASER_PCIEFD_LOOPBACK_ADDR(pcie) \ argument
272 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), loopback))
273 #define KVASER_PCIEFD_SRB_FIFO_ADDR(pcie) \ argument
274 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), kcan_srb_fifo))
275 #define KVASER_PCIEFD_SRB_ADDR(pcie) \ argument
276 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), kcan_srb))
277 #define KVASER_PCIEFD_KCAN_CH0_ADDR(pcie) \ argument
278 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), kcan_ch0))
279 #define KVASER_PCIEFD_KCAN_CH1_ADDR(pcie) \ argument
280 (KVASER_PCIEFD_GET_BLOCK_ADDR((pcie), kcan_ch1))
281 #define KVASER_PCIEFD_KCAN_CHANNEL_SPAN(pcie) \ argument
282 (KVASER_PCIEFD_KCAN_CH1_ADDR((pcie)) - KVASER_PCIEFD_KCAN_CH0_ADDR((pcie)))
283 #define KVASER_PCIEFD_KCAN_CHX_ADDR(pcie, i) \ argument
284 (KVASER_PCIEFD_KCAN_CH0_ADDR((pcie)) + (i) * KVASER_PCIEFD_KCAN_CHANNEL_SPAN((pcie)))
287 static void kvaser_pciefd_write_dma_map_altera(struct kvaser_pciefd *pcie,
289 static void kvaser_pciefd_write_dma_map_sf2(struct kvaser_pciefd *pcie,
291 static void kvaser_pciefd_write_dma_map_xilinx(struct kvaser_pciefd *pcie,
307 void (*kvaser_pciefd_write_dma_map)(struct kvaser_pciefd *pcie,
361 .kcan_tx = { BIT(0), BIT(1), BIT(2), BIT(3) },
445 .tseg1_min = 1,
447 .tseg2_min = 1,
450 .brp_min = 1,
452 .brp_inc = 1,
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()
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()
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()
563 iowrite32(msk, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_set_tx_irq()
566 static inline void kvaser_pciefd_set_skb_timestamp(const struct kvaser_pciefd *pcie, in kvaser_pciefd_set_skb_timestamp() argument
569 skb_hwtstamps(skb)->hwtstamp = in kvaser_pciefd_set_skb_timestamp()
570 ns_to_ktime(div_u64(timestamp * 1000, pcie->freq_to_ticks_div)); in kvaser_pciefd_set_skb_timestamp()
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()
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()
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()
634 del_timer(&can->bec_poll_timer); in kvaser_pciefd_bus_on()
635 if (!completion_done(&can->flush_comp)) 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()
641 return -ETIMEDOUT; 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()
657 return -ETIMEDOUT; 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()
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()
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()
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()
705 trigger = (100 * top - 95 * (top + 1) + 50) / 100; 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()
736 if (!completion_done(&can->flush_comp)) 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()
742 ret = -ETIMEDOUT; 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()
757 struct canfd_frame *cf = (struct canfd_frame *)skb->data; in kvaser_pciefd_prepare_tx_packet()
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()
763 p->header[1] |= KVASER_PCIEFD_TPACKET_SMS; in kvaser_pciefd_prepare_tx_packet()
765 if (cf->can_id & CAN_RTR_FLAG) in kvaser_pciefd_prepare_tx_packet()
766 p->header[0] |= KVASER_PCIEFD_RPACKET_RTR; in kvaser_pciefd_prepare_tx_packet()
768 if (cf->can_id & CAN_EFF_FLAG) in kvaser_pciefd_prepare_tx_packet()
769 p->header[0] |= KVASER_PCIEFD_RPACKET_IDE; in kvaser_pciefd_prepare_tx_packet()
771 p->header[0] |= FIELD_PREP(KVASER_PCIEFD_RPACKET_ID_MASK, cf->can_id); in kvaser_pciefd_prepare_tx_packet()
772 p->header[1] |= KVASER_PCIEFD_TPACKET_AREQ; in kvaser_pciefd_prepare_tx_packet()
775 p->header[1] |= FIELD_PREP(KVASER_PCIEFD_RPACKET_DLC_MASK, in kvaser_pciefd_prepare_tx_packet()
776 can_fd_len2dlc(cf->len)); in kvaser_pciefd_prepare_tx_packet()
777 p->header[1] |= KVASER_PCIEFD_RPACKET_FDF; in kvaser_pciefd_prepare_tx_packet()
778 if (cf->flags & CANFD_BRS) in kvaser_pciefd_prepare_tx_packet()
779 p->header[1] |= KVASER_PCIEFD_RPACKET_BRS; in kvaser_pciefd_prepare_tx_packet()
780 if (cf->flags & CANFD_ESI) in kvaser_pciefd_prepare_tx_packet()
781 p->header[1] |= KVASER_PCIEFD_RPACKET_ESI; in kvaser_pciefd_prepare_tx_packet()
783 p->header[1] |= in kvaser_pciefd_prepare_tx_packet()
785 can_get_cc_dlc((struct can_frame *)cf, can->can.ctrlmode)); in kvaser_pciefd_prepare_tx_packet()
788 p->header[1] |= FIELD_PREP(KVASER_PCIEFD_PACKET_SEQ_MASK, seq); in kvaser_pciefd_prepare_tx_packet()
790 packet_size = cf->len; in kvaser_pciefd_prepare_tx_packet()
791 memcpy(p->data, cf->data, packet_size); in kvaser_pciefd_prepare_tx_packet()
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()
820 iowrite32(packet.header[1], in kvaser_pciefd_start_xmit()
821 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG); in kvaser_pciefd_start_xmit()
824 u32 data_last = ((u32 *)packet.data)[nr_words - 1]; in kvaser_pciefd_start_xmit()
827 iowrite32_rep(can->reg_base + in kvaser_pciefd_start_xmit()
829 nr_words - 1); 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()
859 bt = &can->can.data_bittiming; in kvaser_pciefd_set_bittiming()
861 bt = &can->can.bittiming; in kvaser_pciefd_set_bittiming()
863 btrn = FIELD_PREP(KVASER_PCIEFD_KCAN_BTRN_TSEG2_MASK, bt->phase_seg2 - 1) | in kvaser_pciefd_set_bittiming()
864 FIELD_PREP(KVASER_PCIEFD_KCAN_BTRN_TSEG1_MASK, bt->prop_seg + bt->phase_seg1 - 1) | in kvaser_pciefd_set_bittiming()
865 FIELD_PREP(KVASER_PCIEFD_KCAN_BTRN_SJW_MASK, bt->sjw - 1) | in kvaser_pciefd_set_bittiming()
866 FIELD_PREP(KVASER_PCIEFD_KCAN_BTRN_BRP_MASK, bt->brp - 1); 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()
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()
879 return -EBUSY; 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()
910 if (!can->can.restart_ms) in kvaser_pciefd_set_mode()
914 return -EOPNOTSUPP; in kvaser_pciefd_set_mode()
925 bec->rxerr = can->bec.rxerr; in kvaser_pciefd_get_berr_counter()
926 bec->txerr = can->bec.txerr; in kvaser_pciefd_get_berr_counter()
937 can->err_rep_cnt = 0; in kvaser_pciefd_bec_poll_timer()
952 static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie) in kvaser_pciefd_setup_can_ctrls() argument
956 for (i = 0; i < pcie->nr_channels; i++) { in kvaser_pciefd_setup_can_ctrls()
964 return -ENOMEM; in kvaser_pciefd_setup_can_ctrls()
967 netdev->netdev_ops = &kvaser_pciefd_netdev_ops; in kvaser_pciefd_setup_can_ctrls()
968 netdev->ethtool_ops = &kvaser_pciefd_ethtool_ops; 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()
1005 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_setup_can_ctrls()
1007 dev_err(&pcie->pci->dev, in kvaser_pciefd_setup_can_ctrls()
1011 return -ENODEV; in kvaser_pciefd_setup_can_ctrls()
1015 can->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT; in kvaser_pciefd_setup_can_ctrls()
1017 netdev->flags |= IFF_ECHO; in kvaser_pciefd_setup_can_ctrls()
1018 SET_NETDEV_DEV(netdev, &pcie->pci->dev); in kvaser_pciefd_setup_can_ctrls()
1020 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_setup_can_ctrls()
1022 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_setup_can_ctrls()
1024 pcie->can[i] = can; in kvaser_pciefd_setup_can_ctrls()
1031 static int kvaser_pciefd_reg_candev(struct kvaser_pciefd *pcie) in kvaser_pciefd_reg_candev() argument
1035 for (i = 0; i < pcie->nr_channels; i++) { in kvaser_pciefd_reg_candev()
1036 int ret = register_candev(pcie->can[i]->can.dev); in kvaser_pciefd_reg_candev()
1043 unregister_candev(pcie->can[j]->can.dev); in kvaser_pciefd_reg_candev()
1051 static void kvaser_pciefd_write_dma_map_altera(struct kvaser_pciefd *pcie, in kvaser_pciefd_write_dma_map_altera() argument
1064 serdes_base = KVASER_PCIEFD_SERDES_ADDR(pcie) + 0x8 * index; in kvaser_pciefd_write_dma_map_altera()
1069 static void kvaser_pciefd_write_dma_map_sf2(struct kvaser_pciefd *pcie, in kvaser_pciefd_write_dma_map_sf2() argument
1079 serdes_base = KVASER_PCIEFD_SERDES_ADDR(pcie) + 0x10 * index; in kvaser_pciefd_write_dma_map_sf2()
1084 static void kvaser_pciefd_write_dma_map_xilinx(struct kvaser_pciefd *pcie, in kvaser_pciefd_write_dma_map_xilinx() argument
1094 serdes_base = KVASER_PCIEFD_SERDES_ADDR(pcie) + 0x8 * index; in kvaser_pciefd_write_dma_map_xilinx()
1099 static int kvaser_pciefd_setup_dma(struct kvaser_pciefd *pcie) in kvaser_pciefd_setup_dma() argument
1107 iowrite32(0, KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CTRL_REG); in kvaser_pciefd_setup_dma()
1109 dma_set_mask_and_coherent(&pcie->pci->dev, DMA_BIT_MASK(64)); in kvaser_pciefd_setup_dma()
1112 pcie->dma_data[i] = dmam_alloc_coherent(&pcie->pci->dev, in kvaser_pciefd_setup_dma()
1117 if (!pcie->dma_data[i] || !dma_addr[i]) { in kvaser_pciefd_setup_dma()
1118 dev_err(&pcie->pci->dev, "Rx dma_alloc(%u) failure\n", in kvaser_pciefd_setup_dma()
1120 return -ENOMEM; in kvaser_pciefd_setup_dma()
1122 pcie->driver_data->ops->kvaser_pciefd_write_dma_map(pcie, dma_addr[i], i); in kvaser_pciefd_setup_dma()
1128 KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CMD_REG); in kvaser_pciefd_setup_dma()
1132 ioread32(KVASER_PCIEFD_SRB_ADDR(pcie) + in kvaser_pciefd_setup_dma()
1136 ioread32(KVASER_PCIEFD_SRB_FIFO_ADDR(pcie) + KVASER_PCIEFD_SRB_FIFO_LAST_REG); in kvaser_pciefd_setup_dma()
1137 srb_packet_count--; in kvaser_pciefd_setup_dma()
1140 srb_status = ioread32(KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_STAT_REG); in kvaser_pciefd_setup_dma()
1142 dev_err(&pcie->pci->dev, "DMA not idle before enabling\n"); in kvaser_pciefd_setup_dma()
1143 return -EIO; in kvaser_pciefd_setup_dma()
1148 KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CTRL_REG); in kvaser_pciefd_setup_dma()
1153 static int kvaser_pciefd_setup_board(struct kvaser_pciefd *pcie) in kvaser_pciefd_setup_board() argument
1157 version = ioread32(KVASER_PCIEFD_SYSID_ADDR(pcie) + KVASER_PCIEFD_SYSID_VERSION_REG); in kvaser_pciefd_setup_board()
1158 pcie->nr_channels = min(KVASER_PCIEFD_MAX_CAN_CHANNELS, in kvaser_pciefd_setup_board()
1161 build = ioread32(KVASER_PCIEFD_SYSID_ADDR(pcie) + KVASER_PCIEFD_SYSID_BUILD_REG); in kvaser_pciefd_setup_board()
1162 dev_dbg(&pcie->pci->dev, "Version %lu.%lu.%lu\n", in kvaser_pciefd_setup_board()
1167 srb_status = ioread32(KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_STAT_REG); in kvaser_pciefd_setup_board()
1169 dev_err(&pcie->pci->dev, "Hardware without DMA is not supported\n"); in kvaser_pciefd_setup_board()
1170 return -ENODEV; in kvaser_pciefd_setup_board()
1173 pcie->bus_freq = ioread32(KVASER_PCIEFD_SYSID_ADDR(pcie) + KVASER_PCIEFD_SYSID_BUSFREQ_REG); in kvaser_pciefd_setup_board()
1174 pcie->freq = ioread32(KVASER_PCIEFD_SYSID_ADDR(pcie) + KVASER_PCIEFD_SYSID_CANFREQ_REG); in kvaser_pciefd_setup_board()
1175 pcie->freq_to_ticks_div = pcie->freq / 1000000; in kvaser_pciefd_setup_board()
1176 if (pcie->freq_to_ticks_div == 0) in kvaser_pciefd_setup_board()
1177 pcie->freq_to_ticks_div = 1; in kvaser_pciefd_setup_board()
1179 iowrite32(0, KVASER_PCIEFD_LOOPBACK_ADDR(pcie)); in kvaser_pciefd_setup_board()
1184 static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie, in kvaser_pciefd_handle_data_packet() argument
1191 u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]); in kvaser_pciefd_handle_data_packet()
1194 if (ch_id >= pcie->nr_channels) in kvaser_pciefd_handle_data_packet()
1195 return -EIO; in kvaser_pciefd_handle_data_packet()
1197 priv = &pcie->can[ch_id]->can; in kvaser_pciefd_handle_data_packet()
1198 dlc = FIELD_GET(KVASER_PCIEFD_RPACKET_DLC_MASK, p->header[1]); in kvaser_pciefd_handle_data_packet()
1200 if (p->header[1] & KVASER_PCIEFD_RPACKET_FDF) { in kvaser_pciefd_handle_data_packet()
1201 skb = alloc_canfd_skb(priv->dev, &cf); in kvaser_pciefd_handle_data_packet()
1203 priv->dev->stats.rx_dropped++; in kvaser_pciefd_handle_data_packet()
1204 return -ENOMEM; in kvaser_pciefd_handle_data_packet()
1207 cf->len = can_fd_dlc2len(dlc); in kvaser_pciefd_handle_data_packet()
1208 if (p->header[1] & KVASER_PCIEFD_RPACKET_BRS) in kvaser_pciefd_handle_data_packet()
1209 cf->flags |= CANFD_BRS; in kvaser_pciefd_handle_data_packet()
1210 if (p->header[1] & KVASER_PCIEFD_RPACKET_ESI) in kvaser_pciefd_handle_data_packet()
1211 cf->flags |= CANFD_ESI; in kvaser_pciefd_handle_data_packet()
1213 skb = alloc_can_skb(priv->dev, (struct can_frame **)&cf); in kvaser_pciefd_handle_data_packet()
1215 priv->dev->stats.rx_dropped++; in kvaser_pciefd_handle_data_packet()
1216 return -ENOMEM; in kvaser_pciefd_handle_data_packet()
1218 can_frame_set_cc_len((struct can_frame *)cf, dlc, priv->ctrlmode); in kvaser_pciefd_handle_data_packet()
1221 cf->can_id = FIELD_GET(KVASER_PCIEFD_RPACKET_ID_MASK, p->header[0]); in kvaser_pciefd_handle_data_packet()
1222 if (p->header[0] & KVASER_PCIEFD_RPACKET_IDE) in kvaser_pciefd_handle_data_packet()
1223 cf->can_id |= CAN_EFF_FLAG; in kvaser_pciefd_handle_data_packet()
1225 if (p->header[0] & KVASER_PCIEFD_RPACKET_RTR) { in kvaser_pciefd_handle_data_packet()
1226 cf->can_id |= CAN_RTR_FLAG; in kvaser_pciefd_handle_data_packet()
1228 memcpy(cf->data, data, cf->len); in kvaser_pciefd_handle_data_packet()
1229 priv->dev->stats.rx_bytes += cf->len; in kvaser_pciefd_handle_data_packet()
1231 priv->dev->stats.rx_packets++; in kvaser_pciefd_handle_data_packet()
1232 kvaser_pciefd_set_skb_timestamp(pcie, skb, p->timestamp); in kvaser_pciefd_handle_data_packet()
1246 old_state = can->can.state; in kvaser_pciefd_change_state()
1247 can_change_state(can->can.dev, cf, tx_state, rx_state); in kvaser_pciefd_change_state()
1250 struct net_device *ndev = can->can.dev; in kvaser_pciefd_change_state()
1253 spin_lock_irqsave(&can->lock, irq_flags); in kvaser_pciefd_change_state()
1254 netif_stop_queue(can->can.dev); in kvaser_pciefd_change_state()
1255 spin_unlock_irqrestore(&can->lock, irq_flags); in kvaser_pciefd_change_state()
1257 if (!can->can.restart_ms) { in kvaser_pciefd_change_state()
1264 can->can.restart_ms) { in kvaser_pciefd_change_state()
1265 can->can.can_stats.restarts++; in kvaser_pciefd_change_state()
1267 cf->can_id |= CAN_ERR_RESTARTED; in kvaser_pciefd_change_state()
1270 cf->can_id |= CAN_ERR_CNT; in kvaser_pciefd_change_state()
1271 cf->data[6] = bec->txerr; in kvaser_pciefd_change_state()
1272 cf->data[7] = bec->rxerr; in kvaser_pciefd_change_state()
1282 if (p->header[0] & KVASER_PCIEFD_SPACK_BOFF || in kvaser_pciefd_packet_to_state()
1283 p->header[0] & KVASER_PCIEFD_SPACK_IRM) in kvaser_pciefd_packet_to_state()
1285 else if (bec->txerr >= 255 || bec->rxerr >= 255) in kvaser_pciefd_packet_to_state()
1287 else if (p->header[1] & KVASER_PCIEFD_SPACK_EPLR) in kvaser_pciefd_packet_to_state()
1289 else if (bec->txerr >= 128 || bec->rxerr >= 128) in kvaser_pciefd_packet_to_state()
1291 else if (p->header[1] & KVASER_PCIEFD_SPACK_EWLR) in kvaser_pciefd_packet_to_state()
1293 else if (bec->txerr >= 96 || bec->rxerr >= 96) in kvaser_pciefd_packet_to_state()
1298 *tx_state = bec->txerr >= bec->rxerr ? *new_state : 0; in kvaser_pciefd_packet_to_state()
1299 *rx_state = bec->txerr <= bec->rxerr ? *new_state : 0; in kvaser_pciefd_packet_to_state()
1307 struct net_device *ndev = can->can.dev; in kvaser_pciefd_rx_error_frame()
1311 old_state = can->can.state; in kvaser_pciefd_rx_error_frame()
1313 bec.txerr = FIELD_GET(KVASER_PCIEFD_SPACK_TXERR_MASK, p->header[0]); in kvaser_pciefd_rx_error_frame()
1314 bec.rxerr = FIELD_GET(KVASER_PCIEFD_SPACK_RXERR_MASK, p->header[0]); in kvaser_pciefd_rx_error_frame()
1317 if (can->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) in kvaser_pciefd_rx_error_frame()
1323 can->err_rep_cnt++; in kvaser_pciefd_rx_error_frame()
1324 can->can.can_stats.bus_error++; in kvaser_pciefd_rx_error_frame()
1325 if (p->header[1] & KVASER_PCIEFD_EPACK_DIR_TX) in kvaser_pciefd_rx_error_frame()
1326 ndev->stats.tx_errors++; in kvaser_pciefd_rx_error_frame()
1328 ndev->stats.rx_errors++; in kvaser_pciefd_rx_error_frame()
1330 can->bec.txerr = bec.txerr; in kvaser_pciefd_rx_error_frame()
1331 can->bec.rxerr = bec.rxerr; in kvaser_pciefd_rx_error_frame()
1333 if (can->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) { in kvaser_pciefd_rx_error_frame()
1336 ndev->stats.rx_dropped++; in kvaser_pciefd_rx_error_frame()
1337 return -ENOMEM; in kvaser_pciefd_rx_error_frame()
1339 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_rx_error_frame()
1340 cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_CNT; in kvaser_pciefd_rx_error_frame()
1341 cf->data[6] = bec.txerr; in kvaser_pciefd_rx_error_frame()
1342 cf->data[7] = bec.rxerr; in kvaser_pciefd_rx_error_frame()
1349 static int kvaser_pciefd_handle_error_packet(struct kvaser_pciefd *pcie, in kvaser_pciefd_handle_error_packet() argument
1353 u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]); in kvaser_pciefd_handle_error_packet()
1355 if (ch_id >= pcie->nr_channels) in kvaser_pciefd_handle_error_packet()
1356 return -EIO; in kvaser_pciefd_handle_error_packet()
1358 can = pcie->can[ch_id]; in kvaser_pciefd_handle_error_packet()
1360 if (can->err_rep_cnt >= KVASER_PCIEFD_MAX_ERR_REP) in kvaser_pciefd_handle_error_packet()
1364 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_error_packet()
1376 old_state = can->can.state; in kvaser_pciefd_handle_status_resp()
1378 bec.txerr = FIELD_GET(KVASER_PCIEFD_SPACK_TXERR_MASK, p->header[0]); in kvaser_pciefd_handle_status_resp()
1379 bec.rxerr = FIELD_GET(KVASER_PCIEFD_SPACK_RXERR_MASK, p->header[0]); in kvaser_pciefd_handle_status_resp()
1383 struct net_device *ndev = can->can.dev; in kvaser_pciefd_handle_status_resp()
1390 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_handle_status_resp()
1393 ndev->stats.rx_dropped++; in kvaser_pciefd_handle_status_resp()
1395 ret = -ENOMEM; in kvaser_pciefd_handle_status_resp()
1398 can->bec.txerr = bec.txerr; in kvaser_pciefd_handle_status_resp()
1399 can->bec.rxerr = bec.rxerr; in kvaser_pciefd_handle_status_resp()
1402 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_status_resp()
1407 static int kvaser_pciefd_handle_status_packet(struct kvaser_pciefd *pcie, in kvaser_pciefd_handle_status_packet() argument
1413 u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]); in kvaser_pciefd_handle_status_packet()
1415 if (ch_id >= pcie->nr_channels) in kvaser_pciefd_handle_status_packet()
1416 return -EIO; in kvaser_pciefd_handle_status_packet()
1418 can = pcie->can[ch_id]; in kvaser_pciefd_handle_status_packet()
1420 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG); in kvaser_pciefd_handle_status_packet()
1424 if (p->header[0] & KVASER_PCIEFD_SPACK_IRM && in kvaser_pciefd_handle_status_packet()
1425 p->header[0] & KVASER_PCIEFD_SPACK_RMCD && in kvaser_pciefd_handle_status_packet()
1426 p->header[1] & KVASER_PCIEFD_SPACK_AUTO && in kvaser_pciefd_handle_status_packet()
1427 cmdseq == FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[1]) && in kvaser_pciefd_handle_status_packet()
1430 can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_handle_status_packet()
1432 } else if (p->header[0] & KVASER_PCIEFD_SPACK_IDET && in kvaser_pciefd_handle_status_packet()
1433 p->header[0] & KVASER_PCIEFD_SPACK_IRM && in kvaser_pciefd_handle_status_packet()
1434 cmdseq == FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[1]) && in kvaser_pciefd_handle_status_packet()
1440 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_handle_status_packet()
1444 can->reg_base + KVASER_PCIEFD_KCAN_CTRL_REG); in kvaser_pciefd_handle_status_packet()
1445 } else if (!(p->header[1] & KVASER_PCIEFD_SPACK_AUTO) && in kvaser_pciefd_handle_status_packet()
1446 cmdseq == FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[1])) { in kvaser_pciefd_handle_status_packet()
1449 if (can->can.state != CAN_STATE_BUS_OFF && in kvaser_pciefd_handle_status_packet()
1450 can->can.state != CAN_STATE_ERROR_ACTIVE) { in kvaser_pciefd_handle_status_packet()
1451 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ); in kvaser_pciefd_handle_status_packet()
1453 } else if (p->header[0] & KVASER_PCIEFD_SPACK_RMCD && in kvaser_pciefd_handle_status_packet()
1456 if (!completion_done(&can->start_comp)) in kvaser_pciefd_handle_status_packet()
1457 complete(&can->start_comp); in kvaser_pciefd_handle_status_packet()
1469 skb = alloc_can_err_skb(can->can.dev, &cf); in kvaser_pciefd_handle_nack_packet()
1470 can->can.dev->stats.tx_errors++; in kvaser_pciefd_handle_nack_packet()
1471 if (p->header[0] & KVASER_PCIEFD_APACKET_ABL) { in kvaser_pciefd_handle_nack_packet()
1473 cf->can_id |= CAN_ERR_LOSTARB; in kvaser_pciefd_handle_nack_packet()
1474 can->can.can_stats.arbitration_lost++; in kvaser_pciefd_handle_nack_packet()
1476 cf->can_id |= CAN_ERR_ACK; in kvaser_pciefd_handle_nack_packet()
1480 cf->can_id |= CAN_ERR_BUSERROR; in kvaser_pciefd_handle_nack_packet()
1481 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp); in kvaser_pciefd_handle_nack_packet()
1484 can->can.dev->stats.rx_dropped++; in kvaser_pciefd_handle_nack_packet()
1485 netdev_warn(can->can.dev, "No memory left for err_skb\n"); in kvaser_pciefd_handle_nack_packet()
1489 static int kvaser_pciefd_handle_ack_packet(struct kvaser_pciefd *pcie, in kvaser_pciefd_handle_ack_packet() argument
1494 u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]); in kvaser_pciefd_handle_ack_packet()
1496 if (ch_id >= pcie->nr_channels) in kvaser_pciefd_handle_ack_packet()
1497 return -EIO; in kvaser_pciefd_handle_ack_packet()
1499 can = pcie->can[ch_id]; in kvaser_pciefd_handle_ack_packet()
1501 if (p->header[0] & KVASER_PCIEFD_APACKET_CT) in kvaser_pciefd_handle_ack_packet()
1504 if (p->header[0] & KVASER_PCIEFD_APACKET_NACK) { in kvaser_pciefd_handle_ack_packet()
1509 if (p->header[0] & KVASER_PCIEFD_APACKET_FLU) { in kvaser_pciefd_handle_ack_packet()
1510 netdev_dbg(can->can.dev, "Packet was flushed\n"); in kvaser_pciefd_handle_ack_packet()
1512 int echo_idx = FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[0]); in kvaser_pciefd_handle_ack_packet()
1517 skb = can->can.echo_skb[echo_idx]; in kvaser_pciefd_handle_ack_packet()
1519 kvaser_pciefd_set_skb_timestamp(pcie, skb, p->timestamp); in kvaser_pciefd_handle_ack_packet()
1520 len = can_get_echo_skb(can->can.dev, echo_idx, NULL); in kvaser_pciefd_handle_ack_packet()
1522 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG)); in kvaser_pciefd_handle_ack_packet()
1524 if (count < can->can.echo_skb_max && netif_queue_stopped(can->can.dev)) in kvaser_pciefd_handle_ack_packet()
1525 netif_wake_queue(can->can.dev); in kvaser_pciefd_handle_ack_packet()
1528 can->can.dev->stats.tx_bytes += len; in kvaser_pciefd_handle_ack_packet()
1529 can->can.dev->stats.tx_packets++; in kvaser_pciefd_handle_ack_packet()
1536 static int kvaser_pciefd_handle_eflush_packet(struct kvaser_pciefd *pcie, in kvaser_pciefd_handle_eflush_packet() argument
1540 u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]); in kvaser_pciefd_handle_eflush_packet()
1542 if (ch_id >= pcie->nr_channels) in kvaser_pciefd_handle_eflush_packet()
1543 return -EIO; in kvaser_pciefd_handle_eflush_packet()
1545 can = pcie->can[ch_id]; in kvaser_pciefd_handle_eflush_packet()
1547 if (!completion_done(&can->flush_comp)) in kvaser_pciefd_handle_eflush_packet()
1548 complete(&can->flush_comp); in kvaser_pciefd_handle_eflush_packet()
1553 static int kvaser_pciefd_read_packet(struct kvaser_pciefd *pcie, int *start_pos, in kvaser_pciefd_read_packet() argument
1556 __le32 *buffer = pcie->dma_data[dma_buf]; in kvaser_pciefd_read_packet()
1571 p->header[0] = le32_to_cpu(buffer[pos++]); in kvaser_pciefd_read_packet()
1572 p->header[1] = le32_to_cpu(buffer[pos++]); in kvaser_pciefd_read_packet()
1574 /* Read 64-bit timestamp */ in kvaser_pciefd_read_packet()
1577 p->timestamp = le64_to_cpu(timestamp); in kvaser_pciefd_read_packet()
1579 type = FIELD_GET(KVASER_PCIEFD_PACKET_TYPE_MASK, p->header[1]); in kvaser_pciefd_read_packet()
1582 ret = kvaser_pciefd_handle_data_packet(pcie, p, &buffer[pos]); in kvaser_pciefd_read_packet()
1583 if (!(p->header[0] & KVASER_PCIEFD_RPACKET_RTR)) { in kvaser_pciefd_read_packet()
1587 p->header[1])); in kvaser_pciefd_read_packet()
1593 ret = kvaser_pciefd_handle_ack_packet(pcie, p); in kvaser_pciefd_read_packet()
1597 ret = kvaser_pciefd_handle_status_packet(pcie, p); in kvaser_pciefd_read_packet()
1601 ret = kvaser_pciefd_handle_error_packet(pcie, p); in kvaser_pciefd_read_packet()
1605 ret = kvaser_pciefd_handle_eflush_packet(pcie, p); in kvaser_pciefd_read_packet()
1612 dev_info(&pcie->pci->dev, in kvaser_pciefd_read_packet()
1617 dev_err(&pcie->pci->dev, "Unknown packet type 0x%08X\n", type); in kvaser_pciefd_read_packet()
1618 ret = -EIO; in kvaser_pciefd_read_packet()
1629 return -EIO; in kvaser_pciefd_read_packet()
1637 static int kvaser_pciefd_read_buffer(struct kvaser_pciefd *pcie, int dma_buf) in kvaser_pciefd_read_buffer() argument
1643 res = kvaser_pciefd_read_packet(pcie, &pos, dma_buf); in kvaser_pciefd_read_buffer()
1649 static u32 kvaser_pciefd_receive_irq(struct kvaser_pciefd *pcie) in kvaser_pciefd_receive_irq() argument
1651 u32 irq = ioread32(KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_IRQ_REG); in kvaser_pciefd_receive_irq()
1654 kvaser_pciefd_read_buffer(pcie, 0); in kvaser_pciefd_receive_irq()
1657 kvaser_pciefd_read_buffer(pcie, 1); in kvaser_pciefd_receive_irq()
1663 dev_err(&pcie->pci->dev, "DMA IRQ error 0x%08X\n", irq); in kvaser_pciefd_receive_irq()
1665 iowrite32(irq, KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_IRQ_REG); in kvaser_pciefd_receive_irq()
1671 u32 irq = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_transmit_irq()
1674 netdev_err(can->can.dev, "Tx FIFO overflow\n"); in kvaser_pciefd_transmit_irq()
1677 netdev_err(can->can.dev, in kvaser_pciefd_transmit_irq()
1681 netdev_err(can->can.dev, "CAN FD frame in CAN mode\n"); in kvaser_pciefd_transmit_irq()
1684 netdev_err(can->can.dev, "Rx FIFO overflow\n"); in kvaser_pciefd_transmit_irq()
1686 iowrite32(irq, can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG); in kvaser_pciefd_transmit_irq()
1691 struct kvaser_pciefd *pcie = (struct kvaser_pciefd *)dev; in kvaser_pciefd_irq_handler() local
1692 const struct kvaser_pciefd_irq_mask *irq_mask = pcie->driver_data->irq_mask; in kvaser_pciefd_irq_handler()
1693 u32 pci_irq = ioread32(KVASER_PCIEFD_PCI_IRQ_ADDR(pcie)); in kvaser_pciefd_irq_handler()
1698 if (!(pci_irq & irq_mask->all)) in kvaser_pciefd_irq_handler()
1701 if (pci_irq & irq_mask->kcan_rx0) in kvaser_pciefd_irq_handler()
1702 srb_irq = kvaser_pciefd_receive_irq(pcie); in kvaser_pciefd_irq_handler()
1704 for (i = 0; i < pcie->nr_channels; i++) { in kvaser_pciefd_irq_handler()
1705 if (pci_irq & irq_mask->kcan_tx[i]) in kvaser_pciefd_irq_handler()
1706 kvaser_pciefd_transmit_irq(pcie->can[i]); in kvaser_pciefd_irq_handler()
1716 iowrite32(srb_release, KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CMD_REG); in kvaser_pciefd_irq_handler()
1721 static void kvaser_pciefd_teardown_can_ctrls(struct kvaser_pciefd *pcie) in kvaser_pciefd_teardown_can_ctrls() argument
1725 for (i = 0; i < pcie->nr_channels; i++) { in kvaser_pciefd_teardown_can_ctrls()
1726 struct kvaser_pciefd_can *can = pcie->can[i]; in kvaser_pciefd_teardown_can_ctrls()
1729 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_teardown_can_ctrls()
1731 free_candev(can->can.dev); in kvaser_pciefd_teardown_can_ctrls()
1740 struct kvaser_pciefd *pcie; in kvaser_pciefd_probe() local
1744 pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); in kvaser_pciefd_probe()
1745 if (!pcie) in kvaser_pciefd_probe()
1746 return -ENOMEM; in kvaser_pciefd_probe()
1748 pci_set_drvdata(pdev, pcie); in kvaser_pciefd_probe()
1749 pcie->pci = pdev; in kvaser_pciefd_probe()
1750 pcie->driver_data = (const struct kvaser_pciefd_driver_data *)id->driver_data; in kvaser_pciefd_probe()
1751 irq_mask = pcie->driver_data->irq_mask; in kvaser_pciefd_probe()
1761 pcie->reg_base = pci_iomap(pdev, 0, 0); in kvaser_pciefd_probe()
1762 if (!pcie->reg_base) { in kvaser_pciefd_probe()
1763 ret = -ENOMEM; in kvaser_pciefd_probe()
1767 ret = kvaser_pciefd_setup_board(pcie); in kvaser_pciefd_probe()
1771 ret = kvaser_pciefd_setup_dma(pcie); in kvaser_pciefd_probe()
1777 ret = kvaser_pciefd_setup_can_ctrls(pcie); in kvaser_pciefd_probe()
1781 ret = pci_alloc_irq_vectors(pcie->pci, 1, 1, PCI_IRQ_INTX | PCI_IRQ_MSI); in kvaser_pciefd_probe()
1783 dev_err(&pcie->pci->dev, "Failed to allocate IRQ vectors.\n"); in kvaser_pciefd_probe()
1787 ret = pci_irq_vector(pcie->pci, 0); in kvaser_pciefd_probe()
1791 pcie->pci->irq = ret; in kvaser_pciefd_probe()
1793 ret = request_irq(pcie->pci->irq, kvaser_pciefd_irq_handler, in kvaser_pciefd_probe()
1794 IRQF_SHARED, KVASER_PCIEFD_DRV_NAME, pcie); in kvaser_pciefd_probe()
1796 dev_err(&pcie->pci->dev, "Failed to request IRQ %d\n", pcie->pci->irq); in kvaser_pciefd_probe()
1800 KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_IRQ_REG); in kvaser_pciefd_probe()
1805 KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_IEN_REG); in kvaser_pciefd_probe()
1808 irq_en_base = KVASER_PCIEFD_PCI_IEN_ADDR(pcie); in kvaser_pciefd_probe()
1809 iowrite32(irq_mask->all, irq_en_base); in kvaser_pciefd_probe()
1812 KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CMD_REG); in kvaser_pciefd_probe()
1814 KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CMD_REG); in kvaser_pciefd_probe()
1816 ret = kvaser_pciefd_reg_candev(pcie); in kvaser_pciefd_probe()
1825 free_irq(pcie->pci->irq, pcie); in kvaser_pciefd_probe()
1828 pci_free_irq_vectors(pcie->pci); in kvaser_pciefd_probe()
1831 kvaser_pciefd_teardown_can_ctrls(pcie); in kvaser_pciefd_probe()
1832 iowrite32(0, KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CTRL_REG); in kvaser_pciefd_probe()
1836 pci_iounmap(pdev, pcie->reg_base); in kvaser_pciefd_probe()
1847 static void kvaser_pciefd_remove_all_ctrls(struct kvaser_pciefd *pcie) in kvaser_pciefd_remove_all_ctrls() argument
1851 for (i = 0; i < pcie->nr_channels; i++) { in kvaser_pciefd_remove_all_ctrls()
1852 struct kvaser_pciefd_can *can = pcie->can[i]; in kvaser_pciefd_remove_all_ctrls()
1855 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG); in kvaser_pciefd_remove_all_ctrls()
1856 unregister_candev(can->can.dev); in kvaser_pciefd_remove_all_ctrls()
1857 del_timer(&can->bec_poll_timer); in kvaser_pciefd_remove_all_ctrls()
1859 free_candev(can->can.dev); in kvaser_pciefd_remove_all_ctrls()
1866 struct kvaser_pciefd *pcie = pci_get_drvdata(pdev); in kvaser_pciefd_remove() local
1868 kvaser_pciefd_remove_all_ctrls(pcie); in kvaser_pciefd_remove()
1871 iowrite32(0, KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CTRL_REG); in kvaser_pciefd_remove()
1872 iowrite32(0, KVASER_PCIEFD_PCI_IEN_ADDR(pcie)); in kvaser_pciefd_remove()
1874 free_irq(pcie->pci->irq, pcie); in kvaser_pciefd_remove()
1875 pci_free_irq_vectors(pcie->pci); in kvaser_pciefd_remove()
1876 pci_iounmap(pdev, pcie->reg_base); in kvaser_pciefd_remove()