Lines Matching full:ocelot

13 #include <linux/dsa/ocelot.h>
22 static void ocelot_fdma_writel(struct ocelot *ocelot, u32 reg, u32 data) in ocelot_fdma_writel() argument
24 regmap_write(ocelot->targets[FDMA], reg, data); in ocelot_fdma_writel()
27 static u32 ocelot_fdma_readl(struct ocelot *ocelot, u32 reg) in ocelot_fdma_readl() argument
31 regmap_read(ocelot->targets[FDMA], reg, &retval); in ocelot_fdma_readl()
85 static void ocelot_fdma_activate_chan(struct ocelot *ocelot, dma_addr_t dma, in ocelot_fdma_activate_chan() argument
88 ocelot_fdma_writel(ocelot, MSCC_FDMA_DCB_LLP(chan), dma); in ocelot_fdma_activate_chan()
93 ocelot_fdma_writel(ocelot, MSCC_FDMA_CH_ACTIVATE, BIT(chan)); in ocelot_fdma_activate_chan()
96 static u32 ocelot_fdma_read_ch_safe(struct ocelot *ocelot) in ocelot_fdma_read_ch_safe() argument
98 return ocelot_fdma_readl(ocelot, MSCC_FDMA_CH_SAFE); in ocelot_fdma_read_ch_safe()
101 static int ocelot_fdma_wait_chan_safe(struct ocelot *ocelot, int chan) in ocelot_fdma_wait_chan_safe() argument
105 return readx_poll_timeout_atomic(ocelot_fdma_read_ch_safe, ocelot, safe, in ocelot_fdma_wait_chan_safe()
122 static bool ocelot_fdma_rx_alloc_page(struct ocelot *ocelot, in ocelot_fdma_rx_alloc_page() argument
132 mapping = dma_map_page(ocelot->dev, page, 0, PAGE_SIZE, in ocelot_fdma_rx_alloc_page()
134 if (unlikely(dma_mapping_error(ocelot->dev, mapping))) { in ocelot_fdma_rx_alloc_page()
146 static int ocelot_fdma_alloc_rx_buffs(struct ocelot *ocelot, u16 alloc_cnt) in ocelot_fdma_alloc_rx_buffs() argument
148 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_alloc_rx_buffs()
163 if (unlikely(!ocelot_fdma_rx_alloc_page(ocelot, rxb))) { in ocelot_fdma_alloc_rx_buffs()
164 dev_err_ratelimited(ocelot->dev, in ocelot_fdma_alloc_rx_buffs()
186 static bool ocelot_fdma_tx_dcb_set_skb(struct ocelot *ocelot, in ocelot_fdma_tx_dcb_set_skb() argument
193 mapping = dma_map_single(ocelot->dev, skb->data, skb->len, in ocelot_fdma_tx_dcb_set_skb()
195 if (unlikely(dma_mapping_error(ocelot->dev, mapping))) in ocelot_fdma_tx_dcb_set_skb()
208 static bool ocelot_fdma_check_stop_rx(struct ocelot *ocelot) in ocelot_fdma_check_stop_rx() argument
213 llp = ocelot_fdma_readl(ocelot, MSCC_FDMA_DCB_LLP(MSCC_FDMA_XTR_CHAN)); in ocelot_fdma_check_stop_rx()
217 ocelot_fdma_writel(ocelot, MSCC_FDMA_CH_DISABLE, in ocelot_fdma_check_stop_rx()
234 static void ocelot_fdma_rx_restart(struct ocelot *ocelot) in ocelot_fdma_rx_restart() argument
236 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_rx_restart()
245 ret = ocelot_fdma_wait_chan_safe(ocelot, chan); in ocelot_fdma_rx_restart()
247 dev_err_ratelimited(ocelot->dev, in ocelot_fdma_rx_restart()
258 llp_prev = ocelot_fdma_readl(ocelot, MSCC_FDMA_DCB_LLP_PREV(chan)); in ocelot_fdma_rx_restart()
267 ocelot_fdma_activate_chan(ocelot, new_llp, chan); in ocelot_fdma_rx_restart()
295 static void ocelot_fdma_reuse_rx_page(struct ocelot *ocelot, in ocelot_fdma_reuse_rx_page() argument
298 struct ocelot_fdma_rx_ring *rx_ring = &ocelot->fdma->rx_ring; in ocelot_fdma_reuse_rx_page()
309 dma_sync_single_range_for_device(ocelot->dev, old_rxb->dma_addr, in ocelot_fdma_reuse_rx_page()
314 static struct sk_buff *ocelot_fdma_get_skb(struct ocelot *ocelot, u32 stat, in ocelot_fdma_get_skb() argument
327 dev_err_ratelimited(ocelot->dev, in ocelot_fdma_get_skb()
334 dma_sync_single_range_for_cpu(ocelot->dev, rxb->dma_addr, in ocelot_fdma_get_skb()
340 ocelot_fdma_reuse_rx_page(ocelot, rxb); in ocelot_fdma_get_skb()
343 dma_unmap_page(ocelot->dev, rxb->dma_addr, PAGE_SIZE, in ocelot_fdma_get_skb()
353 static bool ocelot_fdma_receive_skb(struct ocelot *ocelot, struct sk_buff *skb) in ocelot_fdma_receive_skb() argument
363 if (unlikely(src_port >= ocelot->num_phys_ports)) in ocelot_fdma_receive_skb()
366 ndev = ocelot_port_to_netdev(ocelot, src_port); in ocelot_fdma_receive_skb()
378 if (ocelot->ptp) { in ocelot_fdma_receive_skb()
380 ocelot_ptp_rx_timestamp(ocelot, skb, timestamp); in ocelot_fdma_receive_skb()
389 static int ocelot_fdma_rx_get(struct ocelot *ocelot, int budget) in ocelot_fdma_rx_get() argument
391 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_rx_get()
422 skb = ocelot_fdma_get_skb(ocelot, stat, rxb, skb); in ocelot_fdma_rx_get()
434 dev_err_ratelimited(ocelot->dev, in ocelot_fdma_rx_get()
447 if (unlikely(!ocelot_fdma_receive_skb(ocelot, skb))) in ocelot_fdma_rx_get()
456 ocelot_fdma_alloc_rx_buffs(ocelot, cleaned_cnt); in ocelot_fdma_rx_get()
461 static void ocelot_fdma_wakeup_netdev(struct ocelot *ocelot) in ocelot_fdma_wakeup_netdev() argument
468 for (port = 0; port < ocelot->num_phys_ports; port++) { in ocelot_fdma_wakeup_netdev()
469 ocelot_port = ocelot->ports[port]; in ocelot_fdma_wakeup_netdev()
481 static void ocelot_fdma_tx_cleanup(struct ocelot *ocelot, int budget) in ocelot_fdma_tx_cleanup() argument
483 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_tx_cleanup()
508 dma_unmap_single(ocelot->dev, dma_unmap_addr(buf, dma_addr), in ocelot_fdma_tx_cleanup()
526 ocelot_fdma_wakeup_netdev(ocelot); in ocelot_fdma_tx_cleanup()
534 ret = ocelot_fdma_wait_chan_safe(ocelot, MSCC_FDMA_INJ_CHAN); in ocelot_fdma_tx_cleanup()
536 dev_warn(ocelot->dev, in ocelot_fdma_tx_cleanup()
548 ocelot_fdma_activate_chan(ocelot, dma, MSCC_FDMA_INJ_CHAN); in ocelot_fdma_tx_cleanup()
554 struct ocelot *ocelot = fdma->ocelot; in ocelot_fdma_napi_poll() local
558 ocelot_fdma_tx_cleanup(ocelot, budget); in ocelot_fdma_napi_poll()
560 rx_stopped = ocelot_fdma_check_stop_rx(ocelot); in ocelot_fdma_napi_poll()
562 work_done = ocelot_fdma_rx_get(ocelot, budget); in ocelot_fdma_napi_poll()
565 ocelot_fdma_rx_restart(ocelot); in ocelot_fdma_napi_poll()
569 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_ENA, in ocelot_fdma_napi_poll()
580 struct ocelot *ocelot = dev_id; in ocelot_fdma_interrupt() local
582 ident = ocelot_fdma_readl(ocelot, MSCC_FDMA_INTR_IDENT); in ocelot_fdma_interrupt()
583 frm = ocelot_fdma_readl(ocelot, MSCC_FDMA_INTR_FRM); in ocelot_fdma_interrupt()
584 llp = ocelot_fdma_readl(ocelot, MSCC_FDMA_INTR_LLP); in ocelot_fdma_interrupt()
586 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_LLP, llp & ident); in ocelot_fdma_interrupt()
587 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_FRM, frm & ident); in ocelot_fdma_interrupt()
589 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_ENA, 0); in ocelot_fdma_interrupt()
590 napi_schedule(&ocelot->fdma->napi); in ocelot_fdma_interrupt()
593 err = ocelot_fdma_readl(ocelot, MSCC_FDMA_EVT_ERR); in ocelot_fdma_interrupt()
595 err_code = ocelot_fdma_readl(ocelot, MSCC_FDMA_EVT_ERR_CODE); in ocelot_fdma_interrupt()
596 dev_err_ratelimited(ocelot->dev, in ocelot_fdma_interrupt()
600 ocelot_fdma_writel(ocelot, MSCC_FDMA_EVT_ERR, err); in ocelot_fdma_interrupt()
601 ocelot_fdma_writel(ocelot, MSCC_FDMA_EVT_ERR_CODE, err_code); in ocelot_fdma_interrupt()
607 static void ocelot_fdma_send_skb(struct ocelot *ocelot, in ocelot_fdma_send_skb() argument
618 if (!ocelot_fdma_tx_dcb_set_skb(ocelot, tx_buf, dcb, skb)) { in ocelot_fdma_send_skb()
631 ocelot_fdma_activate_chan(ocelot, dma, MSCC_FDMA_INJ_CHAN); in ocelot_fdma_send_skb()
640 static int ocelot_fdma_prepare_skb(struct ocelot *ocelot, int port, u32 rew_op, in ocelot_fdma_prepare_skb() argument
668 ocelot_ifh_set_basic(ifh, ocelot, port, rew_op, skb); in ocelot_fdma_prepare_skb()
673 int ocelot_fdma_inject_frame(struct ocelot *ocelot, int port, u32 rew_op, in ocelot_fdma_inject_frame() argument
676 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_inject_frame()
687 if (ocelot_fdma_prepare_skb(ocelot, port, rew_op, skb, dev)) in ocelot_fdma_inject_frame()
690 ocelot_fdma_send_skb(ocelot, fdma, skb); in ocelot_fdma_inject_frame()
698 static void ocelot_fdma_free_rx_ring(struct ocelot *ocelot) in ocelot_fdma_free_rx_ring() argument
700 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_free_rx_ring()
711 dma_unmap_page(ocelot->dev, rxb->dma_addr, PAGE_SIZE, in ocelot_fdma_free_rx_ring()
721 static void ocelot_fdma_free_tx_ring(struct ocelot *ocelot) in ocelot_fdma_free_tx_ring() argument
723 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_free_tx_ring()
735 dma_unmap_single(ocelot->dev, dma_unmap_addr(txb, dma_addr), in ocelot_fdma_free_tx_ring()
742 static int ocelot_fdma_rings_alloc(struct ocelot *ocelot) in ocelot_fdma_rings_alloc() argument
744 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_rings_alloc()
751 fdma->dcbs_base = dmam_alloc_coherent(ocelot->dev, in ocelot_fdma_rings_alloc()
774 ret = ocelot_fdma_alloc_rx_buffs(ocelot, in ocelot_fdma_rings_alloc()
777 ocelot_fdma_free_rx_ring(ocelot); in ocelot_fdma_rings_alloc()
789 void ocelot_fdma_netdev_init(struct ocelot *ocelot, struct net_device *dev) in ocelot_fdma_netdev_init() argument
791 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_netdev_init()
804 void ocelot_fdma_netdev_deinit(struct ocelot *ocelot, struct net_device *dev) in ocelot_fdma_netdev_deinit() argument
806 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_netdev_deinit()
814 void ocelot_fdma_init(struct platform_device *pdev, struct ocelot *ocelot) in ocelot_fdma_init() argument
816 struct device *dev = ocelot->dev; in ocelot_fdma_init()
824 ocelot->fdma = fdma; in ocelot_fdma_init()
825 ocelot->dev->coherent_dma_mask = DMA_BIT_MASK(32); in ocelot_fdma_init()
827 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_ENA, 0); in ocelot_fdma_init()
829 fdma->ocelot = ocelot; in ocelot_fdma_init()
832 dev_name(dev), ocelot); in ocelot_fdma_init()
836 ret = ocelot_fdma_rings_alloc(ocelot); in ocelot_fdma_init()
849 ocelot->fdma = NULL; in ocelot_fdma_init()
852 void ocelot_fdma_start(struct ocelot *ocelot) in ocelot_fdma_start() argument
854 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_start()
857 ocelot_write_rix(ocelot, QS_INJ_GRP_CFG_MODE(2), QS_INJ_GRP_CFG, 0); in ocelot_fdma_start()
858 ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(0), QS_INJ_CTRL, 0); in ocelot_fdma_start()
860 ocelot_write_rix(ocelot, QS_XTR_GRP_CFG_MODE(2), QS_XTR_GRP_CFG, 0); in ocelot_fdma_start()
862 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_LLP, 0xffffffff); in ocelot_fdma_start()
863 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_FRM, 0xffffffff); in ocelot_fdma_start()
865 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_LLP_ENA, in ocelot_fdma_start()
867 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_FRM_ENA, in ocelot_fdma_start()
869 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_ENA, in ocelot_fdma_start()
874 ocelot_fdma_activate_chan(ocelot, ocelot->fdma->rx_ring.dcbs_dma, in ocelot_fdma_start()
878 void ocelot_fdma_deinit(struct ocelot *ocelot) in ocelot_fdma_deinit() argument
880 struct ocelot_fdma *fdma = ocelot->fdma; in ocelot_fdma_deinit()
882 ocelot_fdma_writel(ocelot, MSCC_FDMA_INTR_ENA, 0); in ocelot_fdma_deinit()
883 ocelot_fdma_writel(ocelot, MSCC_FDMA_CH_FORCEDIS, in ocelot_fdma_deinit()
885 ocelot_fdma_writel(ocelot, MSCC_FDMA_CH_FORCEDIS, in ocelot_fdma_deinit()
890 ocelot_fdma_free_rx_ring(ocelot); in ocelot_fdma_deinit()
891 ocelot_fdma_free_tx_ring(ocelot); in ocelot_fdma_deinit()