Lines Matching +full:one +full:- +full:shot

1 // SPDX-License-Identifier: GPL-2.0-or-later
16 * See "Documentation/ABI/testing/sysfs-class-net-grcan" for information on the
19 * See "Documentation/admin-guide/kernel-parameters.rst" for information on the module
38 #include <linux/dma-mapping.h>
44 #define GRCAN_RESERVE_SIZE(slot1, slot2) (((slot2) - (slot1)) / 4 - 1)
51 u32 smask; /* 0x18 - CanMASK */
52 u32 scode; /* 0x1c - CanCODE */
202 #define GRCAN_MSG_DATA_SHIFT(i) ((3 - (i) % 4) * 8)
264 * handling"-comment for grcan_start_xmit for more details.
371 return sum - size; in grcan_ring_add()
377 return grcan_ring_add(a, size - b, size); in grcan_ring_sub()
383 u32 slots = txsize / GRCAN_MSG_SIZE - 1; in grcan_txspace()
386 return slots - used; in grcan_txspace()
408 struct grcan_registers __iomem *regs = priv->regs; in grcan_set_bittiming()
409 struct can_bittiming *bt = &priv->can.bittiming; in grcan_set_bittiming()
413 /* Should never happen - function will not be called when in grcan_set_bittiming()
416 if (grcan_read_bits(&regs->ctrl, GRCAN_CTRL_ENABLE)) in grcan_set_bittiming()
417 return -EBUSY; in grcan_set_bittiming()
420 rsj = bt->sjw; in grcan_set_bittiming()
421 ps1 = (bt->prop_seg + bt->phase_seg1) - 1; /* tseg1 - 1 */ in grcan_set_bittiming()
422 ps2 = bt->phase_seg2; in grcan_set_bittiming()
423 scaler = (bt->brp - 1); in grcan_set_bittiming()
429 return -EINVAL; in grcan_set_bittiming()
434 return -EINVAL; in grcan_set_bittiming()
443 grcan_write_bits(&regs->conf, timing, GRCAN_CONF_TIMING); in grcan_set_bittiming()
452 struct grcan_registers __iomem *regs = priv->regs; in grcan_get_berr_counter()
453 u32 status = grcan_read_reg(&regs->stat); in grcan_get_berr_counter()
455 bec->txerr = (status & GRCAN_STAT_TXERRCNT) >> GRCAN_STAT_TXERRCNT_BIT; in grcan_get_berr_counter()
456 bec->rxerr = (status & GRCAN_STAT_RXERRCNT) >> GRCAN_STAT_RXERRCNT_BIT; in grcan_get_berr_counter()
466 struct grcan_registers __iomem *regs = priv->regs; in grcan_reset()
467 u32 config = grcan_read_reg(&regs->conf); in grcan_reset()
469 grcan_set_bits(&regs->ctrl, GRCAN_CTRL_RESET); in grcan_reset()
470 grcan_write_reg(&regs->conf, config); in grcan_reset()
472 priv->eskbp = grcan_read_reg(&regs->txrd); in grcan_reset()
473 priv->can.state = CAN_STATE_STOPPED; in grcan_reset()
475 /* Turn off hardware filtering - regs->rxcode set to 0 by reset */ in grcan_reset()
476 grcan_write_reg(&regs->rxmask, 0); in grcan_reset()
483 struct grcan_registers __iomem *regs = priv->regs; in grcan_stop_hardware()
485 grcan_write_reg(&regs->imr, GRCAN_IRQ_NONE); in grcan_stop_hardware()
486 grcan_clear_bits(&regs->txctrl, GRCAN_TXCTRL_ENABLE); in grcan_stop_hardware()
487 grcan_clear_bits(&regs->rxctrl, GRCAN_RXCTRL_ENABLE); in grcan_stop_hardware()
488 grcan_clear_bits(&regs->ctrl, GRCAN_CTRL_ENABLE); in grcan_stop_hardware()
491 /* Let priv->eskbp catch up to regs->txrd and echo back the skbs if echo
495 * continue until priv->eskbp catches up to regs->txrd.
497 * priv->lock *must* be held when calling this function
502 struct grcan_registers __iomem *regs = priv->regs; in catch_up_echo_skb()
503 struct grcan_dma *dma = &priv->dma; in catch_up_echo_skb()
504 struct net_device_stats *stats = &dev->stats; in catch_up_echo_skb()
507 /* Updates to priv->eskbp and wake-ups of the queue needs to in catch_up_echo_skb()
508 * be atomic towards the reads of priv->eskbp and shut-downs in catch_up_echo_skb()
511 u32 txrd = grcan_read_reg(&regs->txrd); in catch_up_echo_skb()
514 if (priv->eskbp == txrd) in catch_up_echo_skb()
516 i = priv->eskbp / GRCAN_MSG_SIZE; in catch_up_echo_skb()
519 stats->tx_packets++; in catch_up_echo_skb()
520 stats->tx_bytes += can_get_echo_skb(dev, i, NULL); in catch_up_echo_skb()
526 priv->eskbp = grcan_ring_add(priv->eskbp, GRCAN_MSG_SIZE, in catch_up_echo_skb()
527 dma->tx.size); in catch_up_echo_skb()
528 txrd = grcan_read_reg(&regs->txrd); in catch_up_echo_skb()
536 struct grcan_registers __iomem *regs = priv->regs; in grcan_lost_one_shot_frame()
537 struct grcan_dma *dma = &priv->dma; in grcan_lost_one_shot_frame()
541 spin_lock_irqsave(&priv->lock, flags); in grcan_lost_one_shot_frame()
543 catch_up_echo_skb(dev, -1, true); in grcan_lost_one_shot_frame()
545 if (unlikely(grcan_read_bits(&regs->txctrl, GRCAN_TXCTRL_ENABLE))) { in grcan_lost_one_shot_frame()
547 netdev_err(dev, "TXCTRL enabled at TXLOSS in one shot mode\n"); in grcan_lost_one_shot_frame()
550 * one-shot mode there is no problem in writing in grcan_lost_one_shot_frame()
553 * in one-shot mode. in grcan_lost_one_shot_frame()
556 /* Skip message and discard echo-skb */ in grcan_lost_one_shot_frame()
557 txrd = grcan_read_reg(&regs->txrd); in grcan_lost_one_shot_frame()
558 txrd = grcan_ring_add(txrd, GRCAN_MSG_SIZE, dma->tx.size); in grcan_lost_one_shot_frame()
559 grcan_write_reg(&regs->txrd, txrd); in grcan_lost_one_shot_frame()
560 catch_up_echo_skb(dev, -1, false); in grcan_lost_one_shot_frame()
562 if (!priv->resetting && !priv->closing && in grcan_lost_one_shot_frame()
563 !(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) { in grcan_lost_one_shot_frame()
565 grcan_set_bits(&regs->txctrl, GRCAN_TXCTRL_ENABLE); in grcan_lost_one_shot_frame()
569 spin_unlock_irqrestore(&priv->lock, flags); in grcan_lost_one_shot_frame()
575 struct grcan_registers __iomem *regs = priv->regs; in grcan_err()
576 struct grcan_dma *dma = &priv->dma; in grcan_err()
577 struct net_device_stats *stats = &dev->stats; in grcan_err()
584 * is also triggered when there is no one else on the can bus or when in grcan_err()
590 /* Take care of failed one-shot transmit */ in grcan_err()
591 if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT) in grcan_err()
599 stats->tx_errors++; in grcan_err()
609 enum can_state state = priv->can.state; in grcan_err()
632 netdev_dbg(dev, "bus-off\n"); in grcan_err()
634 priv->can.can_stats.bus_off++; in grcan_err()
639 if (!priv->can.restart_ms) in grcan_err()
647 priv->can.can_stats.error_passive++; in grcan_err()
658 priv->can.can_stats.error_warning++; in grcan_err()
679 priv->can.state = state; in grcan_err()
683 if (priv->can.restart_ms && oldstate == CAN_STATE_BUS_OFF) { in grcan_err()
688 priv->can.can_stats.restarts++; in grcan_err()
691 spin_lock_irqsave(&priv->lock, flags); in grcan_err()
693 if (!priv->resetting && !priv->closing) { in grcan_err()
694 u32 txwr = grcan_read_reg(&regs->txwr); in grcan_err()
696 if (grcan_txspace(dma->tx.size, txwr, in grcan_err()
697 priv->eskbp)) in grcan_err()
701 spin_unlock_irqrestore(&priv->lock, flags); in grcan_err()
708 stats->rx_over_errors++; in grcan_err()
709 stats->rx_errors++; in grcan_err()
715 /* AHB bus error interrupts (not CAN bus errors) - shut down the in grcan_err()
725 stats->tx_errors++; in grcan_err()
728 stats->rx_errors++; in grcan_err()
730 netdev_err(dev, "Fatal AHB bus error %s- halting device\n", in grcan_err()
733 spin_lock_irqsave(&priv->lock, flags); in grcan_err()
736 priv->closing = true; in grcan_err()
739 priv->can.state = CAN_STATE_STOPPED; in grcan_err()
741 spin_unlock_irqrestore(&priv->lock, flags); in grcan_err()
755 skb_cf->can_id |= cf.can_id; in grcan_err()
756 memcpy(skb_cf->data, cf.data, sizeof(cf.data)); in grcan_err()
766 struct grcan_registers __iomem *regs = priv->regs; in grcan_interrupt()
770 sources = grcan_read_reg(&regs->pimsr); in grcan_interrupt()
773 grcan_write_reg(&regs->picr, sources); in grcan_interrupt()
774 status = grcan_read_reg(&regs->stat); in grcan_interrupt()
779 if (priv->need_txbug_workaround && in grcan_interrupt()
781 del_timer(&priv->hang_timer); in grcan_interrupt()
790 grcan_clear_bits(&regs->imr, GRCAN_IRQ_TX | GRCAN_IRQ_RX); in grcan_interrupt()
791 napi_schedule(&priv->napi); in grcan_interrupt()
805 * for single shot)
810 struct net_device *dev = priv->dev; in grcan_running_reset()
811 struct grcan_registers __iomem *regs = priv->regs; in grcan_running_reset()
815 * priv->lock in grcan_running_reset()
817 spin_lock_irqsave(&priv->lock, flags); in grcan_running_reset()
819 priv->resetting = false; in grcan_running_reset()
820 del_timer(&priv->hang_timer); in grcan_running_reset()
821 del_timer(&priv->rr_timer); in grcan_running_reset()
823 if (!priv->closing) { in grcan_running_reset()
824 /* Save and reset - config register preserved by grcan_reset */ in grcan_running_reset()
825 u32 imr = grcan_read_reg(&regs->imr); in grcan_running_reset()
827 u32 txaddr = grcan_read_reg(&regs->txaddr); in grcan_running_reset()
828 u32 txsize = grcan_read_reg(&regs->txsize); in grcan_running_reset()
829 u32 txwr = grcan_read_reg(&regs->txwr); in grcan_running_reset()
830 u32 txrd = grcan_read_reg(&regs->txrd); in grcan_running_reset()
831 u32 eskbp = priv->eskbp; in grcan_running_reset()
833 u32 rxaddr = grcan_read_reg(&regs->rxaddr); in grcan_running_reset()
834 u32 rxsize = grcan_read_reg(&regs->rxsize); in grcan_running_reset()
835 u32 rxwr = grcan_read_reg(&regs->rxwr); in grcan_running_reset()
836 u32 rxrd = grcan_read_reg(&regs->rxrd); in grcan_running_reset()
841 grcan_write_reg(&regs->txaddr, txaddr); in grcan_running_reset()
842 grcan_write_reg(&regs->txsize, txsize); in grcan_running_reset()
843 grcan_write_reg(&regs->txwr, txwr); in grcan_running_reset()
844 grcan_write_reg(&regs->txrd, txrd); in grcan_running_reset()
845 priv->eskbp = eskbp; in grcan_running_reset()
847 grcan_write_reg(&regs->rxaddr, rxaddr); in grcan_running_reset()
848 grcan_write_reg(&regs->rxsize, rxsize); in grcan_running_reset()
849 grcan_write_reg(&regs->rxwr, rxwr); in grcan_running_reset()
850 grcan_write_reg(&regs->rxrd, rxrd); in grcan_running_reset()
853 grcan_write_reg(&regs->imr, imr); in grcan_running_reset()
854 priv->can.state = CAN_STATE_ERROR_ACTIVE; in grcan_running_reset()
855 grcan_write_reg(&regs->txctrl, GRCAN_TXCTRL_ENABLE in grcan_running_reset()
856 | (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT in grcan_running_reset()
858 grcan_write_reg(&regs->rxctrl, GRCAN_RXCTRL_ENABLE); in grcan_running_reset()
859 grcan_write_reg(&regs->ctrl, GRCAN_CTRL_ENABLE); in grcan_running_reset()
861 /* Start queue if there is size and listen-onle mode is not in grcan_running_reset()
864 if (grcan_txspace(priv->dma.tx.size, txwr, priv->eskbp) && in grcan_running_reset()
865 !(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) in grcan_running_reset()
869 spin_unlock_irqrestore(&priv->lock, flags); in grcan_running_reset()
901 struct net_device *dev = priv->dev; in grcan_initiate_running_reset()
902 struct grcan_registers __iomem *regs = priv->regs; in grcan_initiate_running_reset()
905 netdev_err(dev, "Device seems hanged - reset scheduled\n"); in grcan_initiate_running_reset()
907 spin_lock_irqsave(&priv->lock, flags); in grcan_initiate_running_reset()
912 if (!priv->resetting && !priv->closing) { in grcan_initiate_running_reset()
913 priv->resetting = true; in grcan_initiate_running_reset()
915 grcan_clear_bits(&regs->txctrl, GRCAN_TXCTRL_ENABLE); in grcan_initiate_running_reset()
916 grcan_clear_bits(&regs->rxctrl, GRCAN_RXCTRL_ENABLE); in grcan_initiate_running_reset()
917 grcan_reset_timer(&priv->rr_timer, priv->can.bittiming.bitrate); in grcan_initiate_running_reset()
920 spin_unlock_irqrestore(&priv->lock, flags); in grcan_initiate_running_reset()
926 struct grcan_dma *dma = &priv->dma; in grcan_free_dma_buffers()
928 dma_free_coherent(priv->ofdev_dev, dma->base_size, dma->base_buf, in grcan_free_dma_buffers()
929 dma->base_handle); in grcan_free_dma_buffers()
937 struct grcan_dma *dma = &priv->dma; in grcan_allocate_dma_buffers()
938 struct grcan_dma_buffer *large = rsize > tsize ? &dma->rx : &dma->tx; in grcan_allocate_dma_buffers()
939 struct grcan_dma_buffer *small = rsize > tsize ? &dma->tx : &dma->rx; in grcan_allocate_dma_buffers()
952 dma->base_size = lsize + ssize + GRCAN_BUFFER_ALIGNMENT; in grcan_allocate_dma_buffers()
953 dma->base_buf = dma_alloc_coherent(priv->ofdev_dev, in grcan_allocate_dma_buffers()
954 dma->base_size, in grcan_allocate_dma_buffers()
955 &dma->base_handle, in grcan_allocate_dma_buffers()
958 if (!dma->base_buf) in grcan_allocate_dma_buffers()
959 return -ENOMEM; in grcan_allocate_dma_buffers()
961 dma->tx.size = tsize; in grcan_allocate_dma_buffers()
962 dma->rx.size = rsize; in grcan_allocate_dma_buffers()
964 large->handle = ALIGN(dma->base_handle, GRCAN_BUFFER_ALIGNMENT); in grcan_allocate_dma_buffers()
965 small->handle = large->handle + lsize; in grcan_allocate_dma_buffers()
966 shift = large->handle - dma->base_handle; in grcan_allocate_dma_buffers()
968 large->buf = dma->base_buf + shift; in grcan_allocate_dma_buffers()
969 small->buf = large->buf + lsize; in grcan_allocate_dma_buffers()
974 /* priv->lock *must* be held when calling this function */
978 struct grcan_registers __iomem *regs = priv->regs; in grcan_start()
983 grcan_write_reg(&regs->txaddr, priv->dma.tx.handle); in grcan_start()
984 grcan_write_reg(&regs->txsize, priv->dma.tx.size); in grcan_start()
985 /* regs->txwr, regs->txrd and priv->eskbp already set to 0 by reset */ in grcan_start()
987 grcan_write_reg(&regs->rxaddr, priv->dma.rx.handle); in grcan_start()
988 grcan_write_reg(&regs->rxsize, priv->dma.rx.size); in grcan_start()
989 /* regs->rxwr and regs->rxrd already set to 0 by reset */ in grcan_start()
992 grcan_read_reg(&regs->pir); in grcan_start()
993 grcan_write_reg(&regs->imr, GRCAN_IRQ_DEFAULT); in grcan_start()
997 | (priv->config.enable0 ? GRCAN_CONF_ENABLE0 : 0) in grcan_start()
998 | (priv->config.enable1 ? GRCAN_CONF_ENABLE1 : 0) in grcan_start()
999 | (priv->config.select ? GRCAN_CONF_SELECT : 0) in grcan_start()
1000 | (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY ? in grcan_start()
1002 | (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES ? in grcan_start()
1004 grcan_write_bits(&regs->conf, confop, GRCAN_CONF_OPERATION); in grcan_start()
1006 | (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT in grcan_start()
1008 grcan_write_reg(&regs->txctrl, txctrl); in grcan_start()
1009 grcan_write_reg(&regs->rxctrl, GRCAN_RXCTRL_ENABLE); in grcan_start()
1010 grcan_write_reg(&regs->ctrl, GRCAN_CTRL_ENABLE); in grcan_start()
1012 priv->can.state = CAN_STATE_ERROR_ACTIVE; in grcan_start()
1027 spin_lock_irqsave(&priv->lock, flags); in grcan_set_mode()
1028 if (priv->closing || priv->resetting) { in grcan_set_mode()
1029 err = -EBUSY; in grcan_set_mode()
1033 if (!(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) in grcan_set_mode()
1036 spin_unlock_irqrestore(&priv->lock, flags); in grcan_set_mode()
1039 return -EOPNOTSUPP; in grcan_set_mode()
1045 struct grcan_dma *dma = &priv->dma; in grcan_open()
1050 err = grcan_allocate_dma_buffers(dev, priv->config.txsize, in grcan_open()
1051 priv->config.rxsize); in grcan_open()
1057 priv->echo_skb = kcalloc(dma->tx.size, sizeof(*priv->echo_skb), in grcan_open()
1059 if (!priv->echo_skb) { in grcan_open()
1060 err = -ENOMEM; in grcan_open()
1063 priv->can.echo_skb_max = dma->tx.size; in grcan_open()
1064 priv->can.echo_skb = priv->echo_skb; in grcan_open()
1071 err = request_irq(dev->irq, grcan_interrupt, IRQF_SHARED, in grcan_open()
1072 dev->name, dev); in grcan_open()
1076 spin_lock_irqsave(&priv->lock, flags); in grcan_open()
1078 napi_enable(&priv->napi); in grcan_open()
1080 if (!(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) in grcan_open()
1082 priv->resetting = false; in grcan_open()
1083 priv->closing = false; in grcan_open()
1085 spin_unlock_irqrestore(&priv->lock, flags); in grcan_open()
1092 kfree(priv->echo_skb); in grcan_open()
1103 napi_disable(&priv->napi); in grcan_close()
1105 spin_lock_irqsave(&priv->lock, flags); in grcan_close()
1107 priv->closing = true; in grcan_close()
1108 if (priv->need_txbug_workaround) { in grcan_close()
1109 spin_unlock_irqrestore(&priv->lock, flags); in grcan_close()
1110 del_timer_sync(&priv->hang_timer); in grcan_close()
1111 del_timer_sync(&priv->rr_timer); in grcan_close()
1112 spin_lock_irqsave(&priv->lock, flags); in grcan_close()
1116 priv->can.state = CAN_STATE_STOPPED; in grcan_close()
1118 spin_unlock_irqrestore(&priv->lock, flags); in grcan_close()
1120 free_irq(dev->irq, dev); in grcan_close()
1124 priv->can.echo_skb_max = 0; in grcan_close()
1125 priv->can.echo_skb = NULL; in grcan_close()
1126 kfree(priv->echo_skb); in grcan_close()
1137 spin_lock_irqsave(&priv->lock, flags); in grcan_transmit_catch_up()
1139 work_done = catch_up_echo_skb(dev, -1, true); in grcan_transmit_catch_up()
1141 if (!priv->resetting && !priv->closing && in grcan_transmit_catch_up()
1142 !(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) in grcan_transmit_catch_up()
1148 if (priv->need_txbug_workaround) in grcan_transmit_catch_up()
1149 del_timer(&priv->hang_timer); in grcan_transmit_catch_up()
1152 spin_unlock_irqrestore(&priv->lock, flags); in grcan_transmit_catch_up()
1158 struct grcan_registers __iomem *regs = priv->regs; in grcan_receive()
1159 struct grcan_dma *dma = &priv->dma; in grcan_receive()
1160 struct net_device_stats *stats = &dev->stats; in grcan_receive()
1168 rd = grcan_read_reg(&regs->rxrd); in grcan_receive()
1172 wr = grcan_read_reg(&regs->rxwr); in grcan_receive()
1181 stats->rx_dropped++; in grcan_receive()
1185 slot = dma->rx.buf + rd; in grcan_receive()
1189 cf->can_id = ((slot[0] & GRCAN_MSG_EID) in grcan_receive()
1191 cf->can_id |= CAN_EFF_FLAG; in grcan_receive()
1193 cf->can_id = ((slot[0] & GRCAN_MSG_BID) in grcan_receive()
1196 cf->len = can_cc_dlc2len((slot[1] & GRCAN_MSG_DLC) in grcan_receive()
1199 cf->can_id |= CAN_RTR_FLAG; in grcan_receive()
1201 for (i = 0; i < cf->len; i++) { in grcan_receive()
1204 cf->data[i] = (u8)(slot[j] >> shift); in grcan_receive()
1207 stats->rx_bytes += cf->len; in grcan_receive()
1209 stats->rx_packets++; in grcan_receive()
1213 rd = grcan_ring_add(rd, GRCAN_MSG_SIZE, dma->rx.size); in grcan_receive()
1221 /* Update read pointer - no need to check for ongoing */ in grcan_receive()
1223 grcan_write_reg(&regs->rxrd, rd); in grcan_receive()
1231 struct net_device *dev = priv->dev; in grcan_poll()
1232 struct grcan_registers __iomem *regs = priv->regs; in grcan_poll()
1246 spin_lock_irqsave(&priv->lock, flags); in grcan_poll()
1249 * priv->closing as napi_disable in grcan_close is waiting for in grcan_poll()
1252 grcan_set_bits(&regs->imr, GRCAN_IRQ_TX | GRCAN_IRQ_RX); in grcan_poll()
1254 spin_unlock_irqrestore(&priv->lock, flags); in grcan_poll()
1261 * drop a frame in one-shot mode or indicate a busy device otherwise.
1271 struct grcan_registers __iomem *regs = priv->regs; in grcan_txbug_workaround()
1272 struct grcan_dma *dma = &priv->dma; in grcan_txbug_workaround()
1278 * GRCAN in which ONGOING is not cleared properly one-shot mode when a in grcan_txbug_workaround()
1283 if (!grcan_read_bits(&regs->txctrl, GRCAN_TXCTRL_ONGOING) || in grcan_txbug_workaround()
1284 grcan_read_reg(&regs->txrd) == txwr) { in grcan_txbug_workaround()
1290 spin_lock_irqsave(&priv->lock, flags); in grcan_txbug_workaround()
1291 if (!priv->resetting && !priv->closing) { in grcan_txbug_workaround()
1293 if (grcan_txspace(dma->tx.size, txwr, priv->eskbp)) in grcan_txbug_workaround()
1296 if (!timer_pending(&priv->hang_timer)) in grcan_txbug_workaround()
1297 grcan_reset_timer(&priv->hang_timer, in grcan_txbug_workaround()
1298 priv->can.bittiming.bitrate); in grcan_txbug_workaround()
1300 spin_unlock_irqrestore(&priv->lock, flags); in grcan_txbug_workaround()
1303 /* In one-shot mode we should never end up here because in grcan_txbug_workaround()
1305 * but it is consistent with one-shot mode to drop the in grcan_txbug_workaround()
1311 /* In normal mode the socket-can transmission queue get in grcan_txbug_workaround()
1317 return -EBUSY; in grcan_txbug_workaround()
1322 * regs->txwr - the next slot for the driver to put data to be sent
1323 * regs->txrd - the next slot for the device to read data
1324 * priv->eskbp - the next slot for the driver to call can_put_echo_skb for
1326 * grcan_start_xmit can enter more messages as long as regs->txwr does
1327 * not reach priv->eskbp (within 1 message gap)
1329 * The device sends messages until regs->txrd reaches regs->txwr
1332 * priv->eskbp reaches regs->txrd
1338 struct grcan_registers __iomem *regs = priv->regs; in grcan_start_xmit()
1339 struct grcan_dma *dma = &priv->dma; in grcan_start_xmit()
1340 struct can_frame *cf = (struct can_frame *)skb->data; in grcan_start_xmit()
1347 u32 oneshotmode = priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT; in grcan_start_xmit()
1353 * this should never happen - the queue should not have been started. in grcan_start_xmit()
1355 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) in grcan_start_xmit()
1358 /* Reads of priv->eskbp and shut-downs of the queue needs to in grcan_start_xmit()
1359 * be atomic towards the updates to priv->eskbp and wake-ups in grcan_start_xmit()
1362 spin_lock_irqsave(&priv->lock, flags); in grcan_start_xmit()
1364 txwr = grcan_read_reg(&regs->txwr); in grcan_start_xmit()
1365 space = grcan_txspace(dma->tx.size, txwr, priv->eskbp); in grcan_start_xmit()
1368 slot = dma->tx.buf + txwr; in grcan_start_xmit()
1373 spin_unlock_irqrestore(&priv->lock, flags); in grcan_start_xmit()
1380 netdev_err(dev, "No buffer space, but queue is non-stopped.\n"); in grcan_start_xmit()
1385 eff = cf->can_id & CAN_EFF_FLAG; in grcan_start_xmit()
1386 rtr = cf->can_id & CAN_RTR_FLAG; in grcan_start_xmit()
1387 id = cf->can_id & (eff ? CAN_EFF_MASK : CAN_SFF_MASK); in grcan_start_xmit()
1388 dlc = cf->len; in grcan_start_xmit()
1401 slot[j] |= cf->data[i] << shift; in grcan_start_xmit()
1407 txctrl = grcan_read_reg(&regs->txctrl); in grcan_start_xmit()
1412 netdev_err(dev, "one-shot mode spuriously disabled\n"); in grcan_start_xmit()
1418 if (priv->need_txbug_workaround) { in grcan_start_xmit()
1419 txrd = grcan_read_reg(&regs->txrd); in grcan_start_xmit()
1420 if (unlikely(grcan_ring_sub(txwr, txrd, dma->tx.size) == 1)) { in grcan_start_xmit()
1444 grcan_write_reg(&regs->txwr, in grcan_start_xmit()
1445 grcan_ring_add(txwr, GRCAN_MSG_SIZE, dma->tx.size)); in grcan_start_xmit()
1460 dev_err(&pd->dev, \
1462 #name " - setting default\n"); \
1481 if (dev->flags & IFF_UP) \
1482 return -EBUSY; \
1485 return -EINVAL; \
1486 priv->config.name = val; \
1495 return sprintf(buf, "%d\n", priv->config.name); \
1581 return -ENOMEM; in grcan_setup_netdev()
1583 dev->irq = irq; in grcan_setup_netdev()
1584 dev->flags |= IFF_ECHO; in grcan_setup_netdev()
1585 dev->netdev_ops = &grcan_netdev_ops; in grcan_setup_netdev()
1586 dev->ethtool_ops = &grcan_ethtool_ops; in grcan_setup_netdev()
1587 dev->sysfs_groups[0] = &sysfs_grcan_group; in grcan_setup_netdev()
1590 memcpy(&priv->config, &grcan_module_config, in grcan_setup_netdev()
1592 priv->dev = dev; in grcan_setup_netdev()
1593 priv->ofdev_dev = &ofdev->dev; in grcan_setup_netdev()
1594 priv->regs = base; in grcan_setup_netdev()
1595 priv->can.bittiming_const = &grcan_bittiming_const; in grcan_setup_netdev()
1596 priv->can.do_set_bittiming = grcan_set_bittiming; in grcan_setup_netdev()
1597 priv->can.do_set_mode = grcan_set_mode; in grcan_setup_netdev()
1598 priv->can.do_get_berr_counter = grcan_get_berr_counter; in grcan_setup_netdev()
1599 priv->can.clock.freq = ambafreq; in grcan_setup_netdev()
1600 priv->can.ctrlmode_supported = in grcan_setup_netdev()
1602 priv->need_txbug_workaround = txbug; in grcan_setup_netdev()
1605 regs = priv->regs; in grcan_setup_netdev()
1606 grcan_set_bits(&regs->ctrl, GRCAN_CTRL_RESET); in grcan_setup_netdev()
1607 grcan_set_bits(&regs->conf, GRCAN_CONF_SAM); in grcan_setup_netdev()
1608 if (grcan_read_bits(&regs->conf, GRCAN_CONF_SAM)) { in grcan_setup_netdev()
1609 priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES; in grcan_setup_netdev()
1610 dev_dbg(&ofdev->dev, "Hardware supports triple-sampling\n"); in grcan_setup_netdev()
1613 spin_lock_init(&priv->lock); in grcan_setup_netdev()
1615 if (priv->need_txbug_workaround) { in grcan_setup_netdev()
1616 timer_setup(&priv->rr_timer, grcan_running_reset, 0); in grcan_setup_netdev()
1617 timer_setup(&priv->hang_timer, grcan_initiate_running_reset, 0); in grcan_setup_netdev()
1620 netif_napi_add_weight(dev, &priv->napi, grcan_poll, GRCAN_NAPI_WEIGHT); in grcan_setup_netdev()
1622 SET_NETDEV_DEV(dev, &ofdev->dev); in grcan_setup_netdev()
1623 dev_info(&ofdev->dev, "regs=0x%p, irq=%d, clock=%d\n", in grcan_setup_netdev()
1624 priv->regs, dev->irq, priv->can.clock.freq); in grcan_setup_netdev()
1632 /* Reset device to allow bit-timing to be set. No need to call in grcan_setup_netdev()
1635 grcan_write_reg(&regs->ctrl, GRCAN_CTRL_RESET); in grcan_setup_netdev()
1645 struct device_node *np = ofdev->dev.of_node; in grcan_probe()
1666 dev_err(&ofdev->dev, "unable to fetch \"freq\" property\n"); in grcan_probe()
1678 dev_err(&ofdev->dev, "no irq found\n"); in grcan_probe()
1679 err = -ENODEV; in grcan_probe()
1694 dev_err(&ofdev->dev, in grcan_probe()
1707 irq_dispose_mapping(dev->irq); in grcan_remove()
1708 netif_napi_del(&priv->napi); in grcan_remove()