History

can: kvaser_pciefd: Refactor code

Refactor code; - Format code - Rename variables and macros - Remove intermediate variables - Add/remove blank lines - Reduce scope of variables - Add helper functions

Jimmy Assarsson committed 3 years ago

Commit f4845741 parent f07008a1 file · +87 −134Browse files

Unified · Split

drivers/net/can/kvaser_pciefd.c+87−134
@@ -70,7 +70,7 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices"); · 69 unmodified lines
70#define KVASER_PCIEFD_KCAN_CMD_REG 0x40070#define KVASER_PCIEFD_KCAN_CMD_REG 0x400
71#define KVASER_PCIEFD_KCAN_IEN_REG 0x40871#define KVASER_PCIEFD_KCAN_IEN_REG 0x408
72#define KVASER_PCIEFD_KCAN_IRQ_REG 0x41072#define KVASER_PCIEFD_KCAN_IRQ_REG 0x410
73#define KVASER_PCIEFD_KCAN_TX_NPACKETS_REG 0x41473#define KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG 0x414
74#define KVASER_PCIEFD_KCAN_STAT_REG 0x41874#define KVASER_PCIEFD_KCAN_STAT_REG 0x418
75#define KVASER_PCIEFD_KCAN_MODE_REG 0x41c75#define KVASER_PCIEFD_KCAN_MODE_REG 0x41c
76#define KVASER_PCIEFD_KCAN_BTRN_REG 0x42076#define KVASER_PCIEFD_KCAN_BTRN_REG 0x420
@@ -124,6 +124,8 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices"); · 47 unmodified lines
124 124
125/* Command sequence number */125/* Command sequence number */
126#define KVASER_PCIEFD_KCAN_CMD_SEQ_MASK GENMASK(23, 16)126#define KVASER_PCIEFD_KCAN_CMD_SEQ_MASK GENMASK(23, 16)
127/* Command bits */
128#define KVASER_PCIEFD_KCAN_CMD_MASK GENMASK(5, 0)
127/* Abort, flush and reset */129/* Abort, flush and reset */
128#define KVASER_PCIEFD_KCAN_CMD_AT BIT(1)130#define KVASER_PCIEFD_KCAN_CMD_AT BIT(1)
129/* Request status packet */131/* Request status packet */
@@ -172,9 +174,9 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices"); · 42 unmodified lines
172/* Abort request */174/* Abort request */
173#define KVASER_PCIEFD_KCAN_STAT_AR BIT(7)175#define KVASER_PCIEFD_KCAN_STAT_AR BIT(7)
174/* Controller is bus off */176/* Controller is bus off */
175#define KVASER_PCIEFD_KCAN_STAT_BUS_OFF_MSK (KVASER_PCIEFD_KCAN_STAT_AR | \177#define KVASER_PCIEFD_KCAN_STAT_BUS_OFF_MASK \
176 KVASER_PCIEFD_KCAN_STAT_BOFF | KVASER_PCIEFD_KCAN_STAT_RMR | \178 (KVASER_PCIEFD_KCAN_STAT_AR | KVASER_PCIEFD_KCAN_STAT_BOFF | \
177 KVASER_PCIEFD_KCAN_STAT_IRM)179 KVASER_PCIEFD_KCAN_STAT_RMR | KVASER_PCIEFD_KCAN_STAT_IRM)
178 180
179/* Classic CAN mode */181/* Classic CAN mode */
180#define KVASER_PCIEFD_KCAN_MODE_CCM BIT(31)182#define KVASER_PCIEFD_KCAN_MODE_CCM BIT(31)
@@ -202,15 +204,15 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices"); · 21 unmodified lines
202#define KVASER_PCIEFD_KCAN_PWM_TRIGGER_MASK GENMASK(7, 0)204#define KVASER_PCIEFD_KCAN_PWM_TRIGGER_MASK GENMASK(7, 0)
203 205
204/* KCAN packet type IDs */206/* KCAN packet type IDs */
205#define KVASER_PCIEFD_PACK_TYPE_DATA 0207#define KVASER_PCIEFD_PACK_TYPE_DATA 0x0
206#define KVASER_PCIEFD_PACK_TYPE_ACK 1208#define KVASER_PCIEFD_PACK_TYPE_ACK 0x1
207#define KVASER_PCIEFD_PACK_TYPE_TXRQ 2209#define KVASER_PCIEFD_PACK_TYPE_TXRQ 0x2
208#define KVASER_PCIEFD_PACK_TYPE_ERROR 3210#define KVASER_PCIEFD_PACK_TYPE_ERROR 0x3
209#define KVASER_PCIEFD_PACK_TYPE_EFLUSH_ACK 4211#define KVASER_PCIEFD_PACK_TYPE_EFLUSH_ACK 0x4
210#define KVASER_PCIEFD_PACK_TYPE_EFRAME_ACK 5212#define KVASER_PCIEFD_PACK_TYPE_EFRAME_ACK 0x5
211#define KVASER_PCIEFD_PACK_TYPE_ACK_DATA 6213#define KVASER_PCIEFD_PACK_TYPE_ACK_DATA 0x6
212#define KVASER_PCIEFD_PACK_TYPE_STATUS 8214#define KVASER_PCIEFD_PACK_TYPE_STATUS 0x8
213#define KVASER_PCIEFD_PACK_TYPE_BUS_LOAD 9215#define KVASER_PCIEFD_PACK_TYPE_BUS_LOAD 0x9
214 216
215/* Common KCAN packet definitions, second word */217/* Common KCAN packet definitions, second word */
216#define KVASER_PCIEFD_PACKET_TYPE_MASK GENMASK(31, 28)218#define KVASER_PCIEFD_PACKET_TYPE_MASK GENMASK(31, 28)
@@ -322,13 +324,21 @@ static struct pci_device_id kvaser_pciefd_id_table[] = { · 105 unmodified lines
322};324};
323MODULE_DEVICE_TABLE(pci, kvaser_pciefd_id_table);325MODULE_DEVICE_TABLE(pci, kvaser_pciefd_id_table);
324 326
325static void kvaser_pciefd_request_status(struct kvaser_pciefd_can *can)327static inline void kvaser_pciefd_send_kcan_cmd(struct kvaser_pciefd_can *can, u32 cmd)
326{328{
327 u32 cmd;329 iowrite32(FIELD_PREP(KVASER_PCIEFD_KCAN_CMD_MASK, cmd) |
330 FIELD_PREP(KVASER_PCIEFD_KCAN_CMD_SEQ_MASK, ++can->cmd_seq),
331 can->reg_base + KVASER_PCIEFD_KCAN_CMD_REG);
332}
333
334static inline void kvaser_pciefd_request_status(struct kvaser_pciefd_can *can)
335{
336 kvaser_pciefd_send_kcan_cmd(can, KVASER_PCIEFD_KCAN_CMD_SRQ);
337}
328 338
329 cmd = KVASER_PCIEFD_KCAN_CMD_SRQ;339static inline void kvaser_pciefd_abort_flush_reset(struct kvaser_pciefd_can *can)
330 cmd |= FIELD_PREP(KVASER_PCIEFD_KCAN_CMD_SEQ_MASK, ++can->cmd_seq);340{
331 iowrite32(cmd, can->reg_base + KVASER_PCIEFD_KCAN_CMD_REG);341 kvaser_pciefd_send_kcan_cmd(can, KVASER_PCIEFD_KCAN_CMD_AT);
332}342}
333 343
334static void kvaser_pciefd_enable_err_gen(struct kvaser_pciefd_can *can)344static void kvaser_pciefd_enable_err_gen(struct kvaser_pciefd_can *can)
@@ -383,7 +393,6 @@ static void kvaser_pciefd_setup_controller(struct kvaser_pciefd_can *can) · 48 unmodified lines
383 unsigned long irq;393 unsigned long irq;
384 394
385 spin_lock_irqsave(&can->lock, irq);395 spin_lock_irqsave(&can->lock, irq);
386
387 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);396 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);
388 if (can->can.ctrlmode & CAN_CTRLMODE_FD) {397 if (can->can.ctrlmode & CAN_CTRLMODE_FD) {
389 mode &= ~KVASER_PCIEFD_KCAN_MODE_CCM;398 mode &= ~KVASER_PCIEFD_KCAN_MODE_CCM;
@@ -400,7 +409,6 @@ static void kvaser_pciefd_setup_controller(struct kvaser_pciefd_can *can) · 10 unmodified lines
400 mode |= KVASER_PCIEFD_KCAN_MODE_LOM;409 mode |= KVASER_PCIEFD_KCAN_MODE_LOM;
401 else410 else
402 mode &= ~KVASER_PCIEFD_KCAN_MODE_LOM;411 mode &= ~KVASER_PCIEFD_KCAN_MODE_LOM;
403
404 mode |= KVASER_PCIEFD_KCAN_MODE_EEN;412 mode |= KVASER_PCIEFD_KCAN_MODE_EEN;
405 mode |= KVASER_PCIEFD_KCAN_MODE_EPEN;413 mode |= KVASER_PCIEFD_KCAN_MODE_EPEN;
406 /* Use ACK packet type */414 /* Use ACK packet type */
@@ -417,18 +425,13 @@ static void kvaser_pciefd_start_controller_flush(struct kvaser_pciefd_can *can) · 10 unmodified lines
417 unsigned long irq;425 unsigned long irq;
418 426
419 spin_lock_irqsave(&can->lock, irq);427 spin_lock_irqsave(&can->lock, irq);
420 iowrite32(-1, can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);428 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);
421 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,429 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,
422 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);430 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
423
424 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG);431 status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG);
425 if (status & KVASER_PCIEFD_KCAN_STAT_IDLE) {432 if (status & KVASER_PCIEFD_KCAN_STAT_IDLE) {
426 u32 cmd;
427
428 /* If controller is already idle, run abort, flush and reset */433 /* If controller is already idle, run abort, flush and reset */
429 cmd = KVASER_PCIEFD_KCAN_CMD_AT;434 kvaser_pciefd_abort_flush_reset(can);
430 cmd |= FIELD_PREP(KVASER_PCIEFD_KCAN_CMD_SEQ_MASK, ++can->cmd_seq);
431 iowrite32(cmd, can->reg_base + KVASER_PCIEFD_KCAN_CMD_REG);
432 } else if (!(status & KVASER_PCIEFD_KCAN_STAT_RMR)) {435 } else if (!(status & KVASER_PCIEFD_KCAN_STAT_RMR)) {
433 u32 mode;436 u32 mode;
434 437
@@ -437,7 +440,6 @@ static void kvaser_pciefd_start_controller_flush(struct kvaser_pciefd_can *can) · 2 unmodified lines
437 mode |= KVASER_PCIEFD_KCAN_MODE_RM;440 mode |= KVASER_PCIEFD_KCAN_MODE_RM;
438 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);441 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);
439 }442 }
440
441 spin_unlock_irqrestore(&can->lock, irq);443 spin_unlock_irqrestore(&can->lock, irq);
442}444}
443 445
@@ -447,7 +449,6 @@ static int kvaser_pciefd_bus_on(struct kvaser_pciefd_can *can) · 3 unmodified lines
447 unsigned long irq;449 unsigned long irq;
448 450
449 del_timer(&can->bec_poll_timer);451 del_timer(&can->bec_poll_timer);
450
451 if (!completion_done(&can->flush_comp))452 if (!completion_done(&can->flush_comp))
452 kvaser_pciefd_start_controller_flush(can);453 kvaser_pciefd_start_controller_flush(can);
453 454
@@ -459,11 +460,9 @@ static int kvaser_pciefd_bus_on(struct kvaser_pciefd_can *can) · 5 unmodified lines
459 460
460 spin_lock_irqsave(&can->lock, irq);461 spin_lock_irqsave(&can->lock, irq);
461 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);462 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
462 iowrite32(-1, can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);463 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);
463
464 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,464 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,
465 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);465 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
466
467 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);466 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);
468 mode &= ~KVASER_PCIEFD_KCAN_MODE_RM;467 mode &= ~KVASER_PCIEFD_KCAN_MODE_RM;
469 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);468 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);
@@ -476,11 +475,10 @@ static int kvaser_pciefd_bus_on(struct kvaser_pciefd_can *can) · 6 unmodified lines
476 }475 }
477 /* Reset interrupt handling */476 /* Reset interrupt handling */
478 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);477 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
479 iowrite32(-1, can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);478 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);
480 479
481 kvaser_pciefd_set_tx_irq(can);480 kvaser_pciefd_set_tx_irq(can);
482 kvaser_pciefd_setup_controller(can);481 kvaser_pciefd_setup_controller(can);
483
484 can->can.state = CAN_STATE_ERROR_ACTIVE;482 can->can.state = CAN_STATE_ERROR_ACTIVE;
485 netif_wake_queue(can->can.dev);483 netif_wake_queue(can->can.dev);
486 can->bec.txerr = 0;484 can->bec.txerr = 0;
@@ -499,7 +497,6 @@ static void kvaser_pciefd_pwm_stop(struct kvaser_pciefd_can *can) · 12 unmodified lines
499 spin_lock_irqsave(&can->lock, irq);497 spin_lock_irqsave(&can->lock, irq);
500 pwm_ctrl = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);498 pwm_ctrl = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);
501 top = FIELD_GET(KVASER_PCIEFD_KCAN_PWM_TOP_MASK, pwm_ctrl);499 top = FIELD_GET(KVASER_PCIEFD_KCAN_PWM_TOP_MASK, pwm_ctrl);
502
503 /* Set duty cycle to zero */500 /* Set duty cycle to zero */
504 pwm_ctrl |= FIELD_PREP(KVASER_PCIEFD_KCAN_PWM_TRIGGER_MASK, top);501 pwm_ctrl |= FIELD_PREP(KVASER_PCIEFD_KCAN_PWM_TRIGGER_MASK, top);
505 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);502 iowrite32(pwm_ctrl, can->reg_base + KVASER_PCIEFD_KCAN_PWM_REG);
@@ -514,8 +511,7 @@ static void kvaser_pciefd_pwm_start(struct kvaser_pciefd_can *can) · 8 unmodified lines
514 511
515 kvaser_pciefd_pwm_stop(can);512 kvaser_pciefd_pwm_stop(can);
516 spin_lock_irqsave(&can->lock, irq);513 spin_lock_irqsave(&can->lock, irq);
517 514 /* Set frequency to 500 KHz */
518 /* Set frequency to 500 KHz*/
519 top = can->kv_pcie->bus_freq / (2 * 500000) - 1;515 top = can->kv_pcie->bus_freq / (2 * 500000) - 1;
520 516
521 pwm_ctrl = FIELD_PREP(KVASER_PCIEFD_KCAN_PWM_TRIGGER_MASK, top);517 pwm_ctrl = FIELD_PREP(KVASER_PCIEFD_KCAN_PWM_TRIGGER_MASK, top);
@@ -580,7 +576,6 @@ static int kvaser_pciefd_prepare_tx_packet(struct kvaser_pciefd_tx_packet *p, · 58 unmodified lines
580 int seq = can->echo_idx;576 int seq = can->echo_idx;
581 577
582 memset(p, 0, sizeof(*p));578 memset(p, 0, sizeof(*p));
583
584 if (can->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT)579 if (can->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT)
585 p->header[1] |= KVASER_PCIEFD_TPACKET_SMS;580 p->header[1] |= KVASER_PCIEFD_TPACKET_SMS;
586 581
@@ -621,16 +616,15 @@ static netdev_tx_t kvaser_pciefd_start_xmit(struct sk_buff *skb, · 34 unmodified lines
621 struct kvaser_pciefd_can *can = netdev_priv(netdev);616 struct kvaser_pciefd_can *can = netdev_priv(netdev);
622 unsigned long irq_flags;617 unsigned long irq_flags;
623 struct kvaser_pciefd_tx_packet packet;618 struct kvaser_pciefd_tx_packet packet;
624 int nwords;619 int nr_words;
625 u8 count;620 u8 count;
626 621
627 if (can_dev_dropped_skb(netdev, skb))622 if (can_dev_dropped_skb(netdev, skb))
628 return NETDEV_TX_OK;623 return NETDEV_TX_OK;
629 624
630 nwords = kvaser_pciefd_prepare_tx_packet(&packet, can, skb);625 nr_words = kvaser_pciefd_prepare_tx_packet(&packet, can, skb);
631 626
632 spin_lock_irqsave(&can->echo_lock, irq_flags);627 spin_lock_irqsave(&can->echo_lock, irq_flags);
633
634 /* Prepare and save echo skb in internal slot */628 /* Prepare and save echo skb in internal slot */
635 can_put_echo_skb(skb, netdev, can->echo_idx, 0);629 can_put_echo_skb(skb, netdev, can->echo_idx, 0);
636 630
@@ -643,13 +637,13 @@ static netdev_tx_t kvaser_pciefd_start_xmit(struct sk_buff *skb, · 6 unmodified lines
643 iowrite32(packet.header[1],637 iowrite32(packet.header[1],
644 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);638 can->reg_base + KVASER_PCIEFD_KCAN_FIFO_REG);
645 639
646 if (nwords) {640 if (nr_words) {
647 u32 data_last = ((u32 *)packet.data)[nwords - 1];641 u32 data_last = ((u32 *)packet.data)[nr_words - 1];
648 642
649 /* Write data to fifo, except last word */643 /* Write data to fifo, except last word */
650 iowrite32_rep(can->reg_base +644 iowrite32_rep(can->reg_base +
651 KVASER_PCIEFD_KCAN_FIFO_REG, packet.data,645 KVASER_PCIEFD_KCAN_FIFO_REG, packet.data,
652 nwords - 1);646 nr_words - 1);
653 /* Write last word to end of fifo */647 /* Write last word to end of fifo */
654 __raw_writel(data_last, can->reg_base +648 __raw_writel(data_last, can->reg_base +
655 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);649 KVASER_PCIEFD_KCAN_FIFO_LAST_REG);
@@ -660,14 +654,13 @@ static netdev_tx_t kvaser_pciefd_start_xmit(struct sk_buff *skb, · 4 unmodified lines
660 }654 }
661 655
662 count = FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_CURRENT_MASK,656 count = FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_CURRENT_MASK,
663 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NPACKETS_REG));657 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG));
664 /* No room for a new message, stop the queue until at least one658 /* No room for a new message, stop the queue until at least one
665 * successful transmit659 * successful transmit
666 */660 */
667 if (count >= KVASER_PCIEFD_CAN_TX_MAX_COUNT ||661 if (count >= KVASER_PCIEFD_CAN_TX_MAX_COUNT ||
668 can->can.echo_skb[can->echo_idx])662 can->can.echo_skb[can->echo_idx])
669 netif_stop_queue(netdev);663 netif_stop_queue(netdev);
670
671 spin_unlock_irqrestore(&can->echo_lock, irq_flags);664 spin_unlock_irqrestore(&can->echo_lock, irq_flags);
672 665
673 return NETDEV_TX_OK;666 return NETDEV_TX_OK;
@@ -692,16 +685,13 @@ static int kvaser_pciefd_set_bittiming(struct kvaser_pciefd_can *can, bool data) · 18 unmodified lines
692 685
693 spin_lock_irqsave(&can->lock, irq_flags);686 spin_lock_irqsave(&can->lock, irq_flags);
694 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);687 mode = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);
695
696 /* Put the circuit in reset mode */688 /* Put the circuit in reset mode */
697 iowrite32(mode | KVASER_PCIEFD_KCAN_MODE_RM,689 iowrite32(mode | KVASER_PCIEFD_KCAN_MODE_RM,
698 can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);690 can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);
699 691
700 /* Can only set bittiming if in reset mode */692 /* Can only set bittiming if in reset mode */
701 ret = readl_poll_timeout(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG,693 ret = readl_poll_timeout(can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG,
702 test, test & KVASER_PCIEFD_KCAN_MODE_RM,694 test, test & KVASER_PCIEFD_KCAN_MODE_RM, 0, 10);
703 0, 10);
704
705 if (ret) {695 if (ret) {
706 spin_unlock_irqrestore(&can->lock, irq_flags);696 spin_unlock_irqrestore(&can->lock, irq_flags);
707 return -EBUSY;697 return -EBUSY;
@@ -711,11 +701,10 @@ static int kvaser_pciefd_set_bittiming(struct kvaser_pciefd_can *can, bool data) · 3 unmodified lines
711 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRD_REG);701 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRD_REG);
712 else702 else
713 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRN_REG);703 iowrite32(btrn, can->reg_base + KVASER_PCIEFD_KCAN_BTRN_REG);
714
715 /* Restore previous reset mode status */704 /* Restore previous reset mode status */
716 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);705 iowrite32(mode, can->reg_base + KVASER_PCIEFD_KCAN_MODE_REG);
717
718 spin_unlock_irqrestore(&can->lock, irq_flags);706 spin_unlock_irqrestore(&can->lock, irq_flags);
707
719 return 0;708 return 0;
720}709}
721 710
@@ -753,6 +742,7 @@ static int kvaser_pciefd_get_berr_counter(const struct net_device *ndev, · 31 unmodified lines
753 742
754 bec->rxerr = can->bec.rxerr;743 bec->rxerr = can->bec.rxerr;
755 bec->txerr = can->bec.txerr;744 bec->txerr = can->bec.txerr;
745
756 return 0;746 return 0;
757}747}
758 748
@@ -796,7 +786,6 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie) · 37 unmodified lines
796 netdev->ethtool_ops = &kvaser_pciefd_ethtool_ops;786 netdev->ethtool_ops = &kvaser_pciefd_ethtool_ops;
797 can->reg_base = pcie->reg_base + KVASER_PCIEFD_KCAN0_BASE +787 can->reg_base = pcie->reg_base + KVASER_PCIEFD_KCAN0_BASE +
798 i * KVASER_PCIEFD_KCAN_BASE_OFFSET;788 i * KVASER_PCIEFD_KCAN_BASE_OFFSET;
799
800 can->kv_pcie = pcie;789 can->kv_pcie = pcie;
801 can->cmd_seq = 0;790 can->cmd_seq = 0;
802 can->err_rep_cnt = 0;791 can->err_rep_cnt = 0;
@@ -805,15 +794,14 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie) · 2 unmodified lines
805 794
806 init_completion(&can->start_comp);795 init_completion(&can->start_comp);
807 init_completion(&can->flush_comp);796 init_completion(&can->flush_comp);
808 timer_setup(&can->bec_poll_timer, kvaser_pciefd_bec_poll_timer,797 timer_setup(&can->bec_poll_timer, kvaser_pciefd_bec_poll_timer, 0);
809 0);
810 798
811 /* Disable Bus load reporting */799 /* Disable Bus load reporting */
812 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_BUS_LOAD_REG);800 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_BUS_LOAD_REG);
813 801
814 tx_nr_packets_max =802 tx_nr_packets_max =
815 FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_MAX_MASK,803 FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_MAX_MASK,
816 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NPACKETS_REG));804 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG));
817 if (tx_nr_packets_max < KVASER_PCIEFD_CAN_TX_MAX_COUNT) {805 if (tx_nr_packets_max < KVASER_PCIEFD_CAN_TX_MAX_COUNT) {
818 dev_err(&pcie->pci->dev,806 dev_err(&pcie->pci->dev,
819 "Max Tx count is smaller than expected\n");807 "Max Tx count is smaller than expected\n");
@@ -827,16 +815,13 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie) · 7 unmodified lines
827 can->echo_idx = 0;815 can->echo_idx = 0;
828 spin_lock_init(&can->echo_lock);816 spin_lock_init(&can->echo_lock);
829 spin_lock_init(&can->lock);817 spin_lock_init(&can->lock);
818
830 can->can.bittiming_const = &kvaser_pciefd_bittiming_const;819 can->can.bittiming_const = &kvaser_pciefd_bittiming_const;
831 can->can.data_bittiming_const = &kvaser_pciefd_bittiming_const;820 can->can.data_bittiming_const = &kvaser_pciefd_bittiming_const;
832
833 can->can.do_set_bittiming = kvaser_pciefd_set_nominal_bittiming;821 can->can.do_set_bittiming = kvaser_pciefd_set_nominal_bittiming;
834 can->can.do_set_data_bittiming =822 can->can.do_set_data_bittiming = kvaser_pciefd_set_data_bittiming;
835 kvaser_pciefd_set_data_bittiming;
836
837 can->can.do_set_mode = kvaser_pciefd_set_mode;823 can->can.do_set_mode = kvaser_pciefd_set_mode;
838 can->can.do_get_berr_counter = kvaser_pciefd_get_berr_counter;824 can->can.do_get_berr_counter = kvaser_pciefd_get_berr_counter;
839
840 can->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |825 can->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
841 CAN_CTRLMODE_FD |826 CAN_CTRLMODE_FD |
842 CAN_CTRLMODE_FD_NON_ISO |827 CAN_CTRLMODE_FD_NON_ISO |
@@ -855,10 +840,9 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie) · 12 unmodified lines
855 can->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT;840 can->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT;
856 841
857 netdev->flags |= IFF_ECHO;842 netdev->flags |= IFF_ECHO;
858
859 SET_NETDEV_DEV(netdev, &pcie->pci->dev);843 SET_NETDEV_DEV(netdev, &pcie->pci->dev);
860 844
861 iowrite32(-1, can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);845 iowrite32(GENMASK(31, 0), can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);
862 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,846 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,
863 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);847 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
864 848
@@ -917,18 +901,16 @@ static int kvaser_pciefd_setup_dma(struct kvaser_pciefd *pcie) · 52 unmodified lines
917 for (i = 0; i < KVASER_PCIEFD_DMA_COUNT; i++) {901 for (i = 0; i < KVASER_PCIEFD_DMA_COUNT; i++) {
918 unsigned int offset = KVASER_PCIEFD_DMA_MAP_BASE + 8 * i;902 unsigned int offset = KVASER_PCIEFD_DMA_MAP_BASE + 8 * i;
919 903
920 pcie->dma_data[i] =904 pcie->dma_data[i] = dmam_alloc_coherent(&pcie->pci->dev,
921 dmam_alloc_coherent(&pcie->pci->dev,905 KVASER_PCIEFD_DMA_SIZE,
922 KVASER_PCIEFD_DMA_SIZE,906 &dma_addr[i],
923 &dma_addr[i],907 GFP_KERNEL);
924 GFP_KERNEL);
925 908
926 if (!pcie->dma_data[i] || !dma_addr[i]) {909 if (!pcie->dma_data[i] || !dma_addr[i]) {
927 dev_err(&pcie->pci->dev, "Rx dma_alloc(%u) failure\n",910 dev_err(&pcie->pci->dev, "Rx dma_alloc(%u) failure\n",
928 KVASER_PCIEFD_DMA_SIZE);911 KVASER_PCIEFD_DMA_SIZE);
929 return -ENOMEM;912 return -ENOMEM;
930 }913 }
931
932 kvaser_pciefd_write_dma_map(pcie, dma_addr[i], offset);914 kvaser_pciefd_write_dma_map(pcie, dma_addr[i], offset);
933 }915 }
934 916
@@ -936,7 +918,6 @@ static int kvaser_pciefd_setup_dma(struct kvaser_pciefd *pcie) · 1 unmodified line
936 iowrite32(KVASER_PCIEFD_SRB_CMD_FOR | KVASER_PCIEFD_SRB_CMD_RDB0 |918 iowrite32(KVASER_PCIEFD_SRB_CMD_FOR | KVASER_PCIEFD_SRB_CMD_RDB0 |
937 KVASER_PCIEFD_SRB_CMD_RDB1,919 KVASER_PCIEFD_SRB_CMD_RDB1,
938 pcie->reg_base + KVASER_PCIEFD_SRB_CMD_REG);920 pcie->reg_base + KVASER_PCIEFD_SRB_CMD_REG);
939
940 /* Empty Rx FIFO */921 /* Empty Rx FIFO */
941 srb_packet_count =922 srb_packet_count =
942 FIELD_GET(KVASER_PCIEFD_SRB_RX_NR_PACKETS_MASK,923 FIELD_GET(KVASER_PCIEFD_SRB_RX_NR_PACKETS_MASK,
@@ -976,8 +957,7 @@ static int kvaser_pciefd_setup_board(struct kvaser_pciefd *pcie) · 33 unmodified lines
976 957
977 srb_status = ioread32(pcie->reg_base + KVASER_PCIEFD_SRB_STAT_REG);958 srb_status = ioread32(pcie->reg_base + KVASER_PCIEFD_SRB_STAT_REG);
978 if (!(srb_status & KVASER_PCIEFD_SRB_STAT_DMA)) {959 if (!(srb_status & KVASER_PCIEFD_SRB_STAT_DMA)) {
979 dev_err(&pcie->pci->dev,960 dev_err(&pcie->pci->dev, "Hardware without DMA is not supported\n");
980 "Hardware without DMA is not supported\n");
981 return -ENODEV;961 return -ENODEV;
982 }962 }
983 963
@@ -987,9 +967,9 @@ static int kvaser_pciefd_setup_board(struct kvaser_pciefd *pcie) · 3 unmodified lines
987 pcie->freq_to_ticks_div = pcie->freq / 1000000;967 pcie->freq_to_ticks_div = pcie->freq / 1000000;
988 if (pcie->freq_to_ticks_div == 0)968 if (pcie->freq_to_ticks_div == 0)
989 pcie->freq_to_ticks_div = 1;969 pcie->freq_to_ticks_div = 1;
990
991 /* Turn off all loopback functionality */970 /* Turn off all loopback functionality */
992 iowrite32(0, pcie->reg_base + KVASER_PCIEFD_LOOP_REG);971 iowrite32(0, pcie->reg_base + KVASER_PCIEFD_LOOP_REG);
972
993 return 0;973 return 0;
994}974}
995 975
@@ -1000,7 +980,6 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie, · 4 unmodified lines
1000 struct sk_buff *skb;980 struct sk_buff *skb;
1001 struct canfd_frame *cf;981 struct canfd_frame *cf;
1002 struct can_priv *priv;982 struct can_priv *priv;
1003 struct net_device_stats *stats;
1004 u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]);983 u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]);
1005 u8 dlc;984 u8 dlc;
1006 985
@@ -1008,26 +987,24 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie, · 1 unmodified line
1008 return -EIO;987 return -EIO;
1009 988
1010 priv = &pcie->can[ch_id]->can;989 priv = &pcie->can[ch_id]->can;
1011 stats = &priv->dev->stats;
1012 dlc = FIELD_GET(KVASER_PCIEFD_RPACKET_DLC_MASK, p->header[1]);990 dlc = FIELD_GET(KVASER_PCIEFD_RPACKET_DLC_MASK, p->header[1]);
1013 991
1014 if (p->header[1] & KVASER_PCIEFD_RPACKET_FDF) {992 if (p->header[1] & KVASER_PCIEFD_RPACKET_FDF) {
1015 skb = alloc_canfd_skb(priv->dev, &cf);993 skb = alloc_canfd_skb(priv->dev, &cf);
1016 if (!skb) {994 if (!skb) {
1017 stats->rx_dropped++;995 priv->dev->stats.rx_dropped++;
1018 return -ENOMEM;996 return -ENOMEM;
1019 }997 }
1020 998
1021 cf->len = can_fd_dlc2len(dlc);999 cf->len = can_fd_dlc2len(dlc);
1022 if (p->header[1] & KVASER_PCIEFD_RPACKET_BRS)1000 if (p->header[1] & KVASER_PCIEFD_RPACKET_BRS)
1023 cf->flags |= CANFD_BRS;1001 cf->flags |= CANFD_BRS;
1024
1025 if (p->header[1] & KVASER_PCIEFD_RPACKET_ESI)1002 if (p->header[1] & KVASER_PCIEFD_RPACKET_ESI)
1026 cf->flags |= CANFD_ESI;1003 cf->flags |= CANFD_ESI;
1027 } else {1004 } else {
1028 skb = alloc_can_skb(priv->dev, (struct can_frame **)&cf);1005 skb = alloc_can_skb(priv->dev, (struct can_frame **)&cf);
1029 if (!skb) {1006 if (!skb) {
1030 stats->rx_dropped++;1007 priv->dev->stats.rx_dropped++;
1031 return -ENOMEM;1008 return -ENOMEM;
1032 }1009 }
1033 can_frame_set_cc_len((struct can_frame *)cf, dlc, priv->ctrlmode);1010 can_frame_set_cc_len((struct can_frame *)cf, dlc, priv->ctrlmode);
@@ -1041,10 +1018,9 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie, · 7 unmodified lines
1041 cf->can_id |= CAN_RTR_FLAG;1018 cf->can_id |= CAN_RTR_FLAG;
1042 } else {1019 } else {
1043 memcpy(cf->data, data, cf->len);1020 memcpy(cf->data, data, cf->len);
1044 1021 priv->dev->stats.rx_bytes += cf->len;
1045 stats->rx_bytes += cf->len;
1046 }1022 }
1047 stats->rx_packets++;1023 priv->dev->stats.rx_packets++;
1048 kvaser_pciefd_set_skb_timestamp(pcie, skb, p->timestamp);1024 kvaser_pciefd_set_skb_timestamp(pcie, skb, p->timestamp);
1049 1025
1050 return netif_rx(skb);1026 return netif_rx(skb);
@@ -1065,7 +1041,6 @@ static void kvaser_pciefd_change_state(struct kvaser_pciefd_can *can, · 14 unmodified lines
1065 spin_lock_irqsave(&can->lock, irq_flags);1041 spin_lock_irqsave(&can->lock, irq_flags);
1066 netif_stop_queue(can->can.dev);1042 netif_stop_queue(can->can.dev);
1067 spin_unlock_irqrestore(&can->lock, irq_flags);1043 spin_unlock_irqrestore(&can->lock, irq_flags);
1068
1069 /* Prevent CAN controller from auto recover from bus off */1044 /* Prevent CAN controller from auto recover from bus off */
1070 if (!can->can.restart_ms) {1045 if (!can->can.restart_ms) {
1071 kvaser_pciefd_start_controller_flush(can);1046 kvaser_pciefd_start_controller_flush(can);
@@ -1083,7 +1058,7 @@ static void kvaser_pciefd_packet_to_state(struct kvaser_pciefd_rx_packet *p, · 11 unmodified lines
1083 if (p->header[0] & KVASER_PCIEFD_SPACK_BOFF ||1058 if (p->header[0] & KVASER_PCIEFD_SPACK_BOFF ||
1084 p->header[0] & KVASER_PCIEFD_SPACK_IRM)1059 p->header[0] & KVASER_PCIEFD_SPACK_IRM)
1085 *new_state = CAN_STATE_BUS_OFF;1060 *new_state = CAN_STATE_BUS_OFF;
1086 else if (bec->txerr >= 255 || bec->rxerr >= 255)1061 else if (bec->txerr >= 255 || bec->rxerr >= 255)
1087 *new_state = CAN_STATE_BUS_OFF;1062 *new_state = CAN_STATE_BUS_OFF;
1088 else if (p->header[1] & KVASER_PCIEFD_SPACK_EPLR)1063 else if (p->header[1] & KVASER_PCIEFD_SPACK_EPLR)
1089 *new_state = CAN_STATE_ERROR_PASSIVE;1064 *new_state = CAN_STATE_ERROR_PASSIVE;
@@ -1108,22 +1083,16 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, · 18 unmodified lines
1108 struct net_device *ndev = can->can.dev;1083 struct net_device *ndev = can->can.dev;
1109 struct sk_buff *skb;1084 struct sk_buff *skb;
1110 struct can_frame *cf = NULL;1085 struct can_frame *cf = NULL;
1111 struct net_device_stats *stats = &ndev->stats;
1112 1086
1113 old_state = can->can.state;1087 old_state = can->can.state;
1114 1088
1115 bec.txerr = FIELD_GET(KVASER_PCIEFD_SPACK_TXERR_MASK, p->header[0]);1089 bec.txerr = FIELD_GET(KVASER_PCIEFD_SPACK_TXERR_MASK, p->header[0]);
1116 bec.rxerr = FIELD_GET(KVASER_PCIEFD_SPACK_RXERR_MASK, p->header[0]);1090 bec.rxerr = FIELD_GET(KVASER_PCIEFD_SPACK_RXERR_MASK, p->header[0]);
1117 1091
1118 kvaser_pciefd_packet_to_state(p, &bec, &new_state, &tx_state,1092 kvaser_pciefd_packet_to_state(p, &bec, &new_state, &tx_state, &rx_state);
1119 &rx_state);
1120
1121 skb = alloc_can_err_skb(ndev, &cf);1093 skb = alloc_can_err_skb(ndev, &cf);
1122
1123 if (new_state != old_state) {1094 if (new_state != old_state) {
1124 kvaser_pciefd_change_state(can, cf, new_state, tx_state,1095 kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state);
1125 rx_state);
1126
1127 if (old_state == CAN_STATE_BUS_OFF &&1096 if (old_state == CAN_STATE_BUS_OFF &&
1128 new_state == CAN_STATE_ERROR_ACTIVE &&1097 new_state == CAN_STATE_ERROR_ACTIVE &&
1129 can->can.restart_ms) {1098 can->can.restart_ms) {
@@ -1136,25 +1105,25 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, · 6 unmodified lines
1136 can->err_rep_cnt++;1105 can->err_rep_cnt++;
1137 can->can.can_stats.bus_error++;1106 can->can.can_stats.bus_error++;
1138 if (p->header[1] & KVASER_PCIEFD_EPACK_DIR_TX)1107 if (p->header[1] & KVASER_PCIEFD_EPACK_DIR_TX)
1139 stats->tx_errors++;1108 ndev->stats.tx_errors++;
1140 else1109 else
1141 stats->rx_errors++;1110 ndev->stats.rx_errors++;
1142 1111
1143 can->bec.txerr = bec.txerr;1112 can->bec.txerr = bec.txerr;
1144 can->bec.rxerr = bec.rxerr;1113 can->bec.rxerr = bec.rxerr;
1145 1114
1146 if (!skb) {1115 if (!skb) {
1147 stats->rx_dropped++;1116 ndev->stats.rx_dropped++;
1148 return -ENOMEM;1117 return -ENOMEM;
1149 }1118 }
1150 1119
1151 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp);1120 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp);
1152 cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_CNT;1121 cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_CNT;
1153
1154 cf->data[6] = bec.txerr;1122 cf->data[6] = bec.txerr;
1155 cf->data[7] = bec.rxerr;1123 cf->data[7] = bec.rxerr;
1156 1124
1157 netif_rx(skb);1125 netif_rx(skb);
1126
1158 return 0;1127 return 0;
1159}1128}
1160 1129
@@ -1168,13 +1137,13 @@ static int kvaser_pciefd_handle_error_packet(struct kvaser_pciefd *pcie, · 7 unmodified lines
1168 return -EIO;1137 return -EIO;
1169 1138
1170 can = pcie->can[ch_id];1139 can = pcie->can[ch_id];
1171
1172 kvaser_pciefd_rx_error_frame(can, p);1140 kvaser_pciefd_rx_error_frame(can, p);
1173 if (can->err_rep_cnt >= KVASER_PCIEFD_MAX_ERR_REP)1141 if (can->err_rep_cnt >= KVASER_PCIEFD_MAX_ERR_REP)
1174 /* Do not report more errors, until bec_poll_timer expires */1142 /* Do not report more errors, until bec_poll_timer expires */
1175 kvaser_pciefd_disable_err_gen(can);1143 kvaser_pciefd_disable_err_gen(can);
1176 /* Start polling the error counters */1144 /* Start polling the error counters */
1177 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ);1145 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ);
1146
1178 return 0;1147 return 0;
1179}1148}
1180 1149
@@ -1189,9 +1158,7 @@ static int kvaser_pciefd_handle_status_resp(struct kvaser_pciefd_can *can, · 8 unmodified lines
1189 bec.txerr = FIELD_GET(KVASER_PCIEFD_SPACK_TXERR_MASK, p->header[0]);1158 bec.txerr = FIELD_GET(KVASER_PCIEFD_SPACK_TXERR_MASK, p->header[0]);
1190 bec.rxerr = FIELD_GET(KVASER_PCIEFD_SPACK_RXERR_MASK, p->header[0]);1159 bec.rxerr = FIELD_GET(KVASER_PCIEFD_SPACK_RXERR_MASK, p->header[0]);
1191 1160
1192 kvaser_pciefd_packet_to_state(p, &bec, &new_state, &tx_state,1161 kvaser_pciefd_packet_to_state(p, &bec, &new_state, &tx_state, &rx_state);
1193 &rx_state);
1194
1195 if (new_state != old_state) {1162 if (new_state != old_state) {
1196 struct net_device *ndev = can->can.dev;1163 struct net_device *ndev = can->can.dev;
1197 struct sk_buff *skb;1164 struct sk_buff *skb;
@@ -1199,15 +1166,11 @@ static int kvaser_pciefd_handle_status_resp(struct kvaser_pciefd_can *can, · 1 unmodified line
1199 1166
1200 skb = alloc_can_err_skb(ndev, &cf);1167 skb = alloc_can_err_skb(ndev, &cf);
1201 if (!skb) {1168 if (!skb) {
1202 struct net_device_stats *stats = &ndev->stats;1169 ndev->stats.rx_dropped++;
1203
1204 stats->rx_dropped++;
1205 return -ENOMEM;1170 return -ENOMEM;
1206 }1171 }
1207 1172
1208 kvaser_pciefd_change_state(can, cf, new_state, tx_state,1173 kvaser_pciefd_change_state(can, cf, new_state, tx_state, rx_state);
1209 rx_state);
1210
1211 if (old_state == CAN_STATE_BUS_OFF &&1174 if (old_state == CAN_STATE_BUS_OFF &&
1212 new_state == CAN_STATE_ERROR_ACTIVE &&1175 new_state == CAN_STATE_ERROR_ACTIVE &&
1213 can->can.restart_ms) {1176 can->can.restart_ms) {
@@ -1253,21 +1216,18 @@ static int kvaser_pciefd_handle_status_packet(struct kvaser_pciefd *pcie, · 39 unmodified lines
1253 p->header[1] & KVASER_PCIEFD_SPACK_AUTO &&1216 p->header[1] & KVASER_PCIEFD_SPACK_AUTO &&
1254 cmdseq == FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[1]) &&1217 cmdseq == FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[1]) &&
1255 status & KVASER_PCIEFD_KCAN_STAT_IDLE) {1218 status & KVASER_PCIEFD_KCAN_STAT_IDLE) {
1256 u32 cmd;
1257
1258 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,1219 iowrite32(KVASER_PCIEFD_KCAN_IRQ_ABD,
1259 can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);1220 can->reg_base + KVASER_PCIEFD_KCAN_IRQ_REG);
1260 cmd = KVASER_PCIEFD_KCAN_CMD_AT;1221 kvaser_pciefd_abort_flush_reset(can);
1261 cmd |= FIELD_PREP(KVASER_PCIEFD_KCAN_CMD_SEQ_MASK, ++can->cmd_seq);
1262 iowrite32(cmd, can->reg_base + KVASER_PCIEFD_KCAN_CMD_REG);
1263 } else if (p->header[0] & KVASER_PCIEFD_SPACK_IDET &&1222 } else if (p->header[0] & KVASER_PCIEFD_SPACK_IDET &&
1264 p->header[0] & KVASER_PCIEFD_SPACK_IRM &&1223 p->header[0] & KVASER_PCIEFD_SPACK_IRM &&
1265 cmdseq == FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[1]) &&1224 cmdseq == FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[1]) &&
1266 status & KVASER_PCIEFD_KCAN_STAT_IDLE) {1225 status & KVASER_PCIEFD_KCAN_STAT_IDLE) {
1267 /* Reset detected, send end of flush if no packet are in FIFO */1226 /* Reset detected, send end of flush if no packet are in FIFO */
1268 u8 count = FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_CURRENT_MASK,1227 u8 count;
1269 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NPACKETS_REG));
1270 1228
1229 count = FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_CURRENT_MASK,
1230 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG));
1271 if (!count)1231 if (!count)
1272 iowrite32(FIELD_PREP(KVASER_PCIEFD_KCAN_CTRL_TYPE_MASK,1232 iowrite32(FIELD_PREP(KVASER_PCIEFD_KCAN_CTRL_TYPE_MASK,
1273 KVASER_PCIEFD_KCAN_CTRL_TYPE_EFLUSH),1233 KVASER_PCIEFD_KCAN_CTRL_TYPE_EFLUSH),
@@ -1278,11 +1238,10 @@ static int kvaser_pciefd_handle_status_packet(struct kvaser_pciefd *pcie, · 4 unmodified lines
1278 kvaser_pciefd_handle_status_resp(can, p);1238 kvaser_pciefd_handle_status_resp(can, p);
1279 if (can->can.state != CAN_STATE_BUS_OFF &&1239 if (can->can.state != CAN_STATE_BUS_OFF &&
1280 can->can.state != CAN_STATE_ERROR_ACTIVE) {1240 can->can.state != CAN_STATE_ERROR_ACTIVE) {
1281 mod_timer(&can->bec_poll_timer,1241 mod_timer(&can->bec_poll_timer, KVASER_PCIEFD_BEC_POLL_FREQ);
1282 KVASER_PCIEFD_BEC_POLL_FREQ);
1283 }1242 }
1284 } else if (p->header[0] & KVASER_PCIEFD_SPACK_RMCD &&1243 } else if (p->header[0] & KVASER_PCIEFD_SPACK_RMCD &&
1285 !(status & KVASER_PCIEFD_KCAN_STAT_BUS_OFF_MSK)) {1244 !(status & KVASER_PCIEFD_KCAN_STAT_BUS_OFF_MASK)) {
1286 /* Reset to bus on detected */1245 /* Reset to bus on detected */
1287 if (!completion_done(&can->start_comp))1246 if (!completion_done(&can->start_comp))
1288 complete(&can->start_comp);1247 complete(&can->start_comp);
@@ -1295,12 +1254,10 @@ static void kvaser_pciefd_handle_nack_packet(struct kvaser_pciefd_can *can, · 6 unmodified lines
1295 struct kvaser_pciefd_rx_packet *p)1254 struct kvaser_pciefd_rx_packet *p)
1296{1255{
1297 struct sk_buff *skb;1256 struct sk_buff *skb;
1298 struct net_device_stats *stats = &can->can.dev->stats;
1299 struct can_frame *cf;1257 struct can_frame *cf;
1300 1258
1301 skb = alloc_can_err_skb(can->can.dev, &cf);1259 skb = alloc_can_err_skb(can->can.dev, &cf);
1302 1260 can->can.dev->stats.tx_errors++;
1303 stats->tx_errors++;
1304 if (p->header[0] & KVASER_PCIEFD_APACKET_ABL) {1261 if (p->header[0] & KVASER_PCIEFD_APACKET_ABL) {
1305 if (skb)1262 if (skb)
1306 cf->can_id |= CAN_ERR_LOSTARB;1263 cf->can_id |= CAN_ERR_LOSTARB;
@@ -1314,7 +1271,7 @@ static void kvaser_pciefd_handle_nack_packet(struct kvaser_pciefd_can *can, · 7 unmodified lines
1314 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp);1271 kvaser_pciefd_set_skb_timestamp(can->kv_pcie, skb, p->timestamp);
1315 netif_rx(skb);1272 netif_rx(skb);
1316 } else {1273 } else {
1317 stats->rx_dropped++;1274 can->can.dev->stats.rx_dropped++;
1318 netdev_warn(can->can.dev, "No memory left for err_skb\n");1275 netdev_warn(can->can.dev, "No memory left for err_skb\n");
1319 }1276 }
1320}1277}
@@ -1343,26 +1300,24 @@ static int kvaser_pciefd_handle_ack_packet(struct kvaser_pciefd *pcie, · 22 unmodified lines
1343 netdev_dbg(can->can.dev, "Packet was flushed\n");1300 netdev_dbg(can->can.dev, "Packet was flushed\n");
1344 } else {1301 } else {
1345 int echo_idx = FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[0]);1302 int echo_idx = FIELD_GET(KVASER_PCIEFD_PACKET_SEQ_MASK, p->header[0]);
1346 int dlc;1303 int len;
1347 u8 count;1304 u8 count;
1348 struct sk_buff *skb;1305 struct sk_buff *skb;
1349 1306
1350 skb = can->can.echo_skb[echo_idx];1307 skb = can->can.echo_skb[echo_idx];
1351 if (skb)1308 if (skb)
1352 kvaser_pciefd_set_skb_timestamp(pcie, skb, p->timestamp);1309 kvaser_pciefd_set_skb_timestamp(pcie, skb, p->timestamp);
1353 dlc = can_get_echo_skb(can->can.dev, echo_idx, NULL);1310 len = can_get_echo_skb(can->can.dev, echo_idx, NULL);
1354 count = FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_CURRENT_MASK,1311 count = FIELD_GET(KVASER_PCIEFD_KCAN_TX_NR_PACKETS_CURRENT_MASK,
1355 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NPACKETS_REG));1312 ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG));
1356 1313
1357 if (count < KVASER_PCIEFD_CAN_TX_MAX_COUNT &&1314 if (count < KVASER_PCIEFD_CAN_TX_MAX_COUNT &&
1358 netif_queue_stopped(can->can.dev))1315 netif_queue_stopped(can->can.dev))
1359 netif_wake_queue(can->can.dev);1316 netif_wake_queue(can->can.dev);
1360 1317
1361 if (!one_shot_fail) {1318 if (!one_shot_fail) {
1362 struct net_device_stats *stats = &can->can.dev->stats;1319 can->can.dev->stats.tx_bytes += len;
1363 1320 can->can.dev->stats.tx_packets++;
1364 stats->tx_bytes += dlc;
1365 stats->tx_packets++;
1366 }1321 }
1367 }1322 }
1368 1323
@@ -1562,13 +1517,12 @@ static irqreturn_t kvaser_pciefd_irq_handler(int irq, void *dev) · 193 unmodified lines
1562static void kvaser_pciefd_teardown_can_ctrls(struct kvaser_pciefd *pcie)1517static void kvaser_pciefd_teardown_can_ctrls(struct kvaser_pciefd *pcie)
1563{1518{
1564 int i;1519 int i;
1565 struct kvaser_pciefd_can *can;
1566 1520
1567 for (i = 0; i < pcie->nr_channels; i++) {1521 for (i = 0; i < pcie->nr_channels; i++) {
1568 can = pcie->can[i];1522 struct kvaser_pciefd_can *can = pcie->can[i];
1523
1569 if (can) {1524 if (can) {
1570 iowrite32(0,1525 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
1571 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
1572 kvaser_pciefd_pwm_stop(can);1526 kvaser_pciefd_pwm_stop(can);
1573 free_candev(can->can.dev);1527 free_candev(can->can.dev);
1574 }1528 }
@@ -1669,14 +1623,13 @@ err_disable_pci: · 94 unmodified lines
1669 1623
1670static void kvaser_pciefd_remove_all_ctrls(struct kvaser_pciefd *pcie)1624static void kvaser_pciefd_remove_all_ctrls(struct kvaser_pciefd *pcie)
1671{1625{
1672 struct kvaser_pciefd_can *can;
1673 int i;1626 int i;
1674 1627
1675 for (i = 0; i < pcie->nr_channels; i++) {1628 for (i = 0; i < pcie->nr_channels; i++) {
1676 can = pcie->can[i];1629 struct kvaser_pciefd_can *can = pcie->can[i];
1630
1677 if (can) {1631 if (can) {
1678 iowrite32(0,1632 iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
1679 can->reg_base + KVASER_PCIEFD_KCAN_IEN_REG);
1680 unregister_candev(can->can.dev);1633 unregister_candev(can->can.dev);
1681 del_timer(&can->bec_poll_timer);1634 del_timer(&can->bec_poll_timer);
1682 kvaser_pciefd_pwm_stop(can);1635 kvaser_pciefd_pwm_stop(can);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t