Lines Matching +full:echo +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0+
17 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
20 * Copyright (c) 2004-2006 Macq Electronique SA.
22 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
196 { .compatible = "fsl,imx25-fec", .data = &fec_imx25_info, },
197 { .compatible = "fsl,imx27-fec", .data = &fec_imx27_info, },
198 { .compatible = "fsl,imx28-fec", .data = &fec_imx28_info, },
199 { .compatible = "fsl,imx6q-fec", .data = &fec_imx6q_info, },
200 { .compatible = "fsl,mvf600-fec", .data = &fec_mvf600_info, },
201 { .compatible = "fsl,imx6sx-fec", .data = &fec_imx6x_info, },
202 { .compatible = "fsl,imx6ul-fec", .data = &fec_imx6ul_info, },
203 { .compatible = "fsl,imx8mq-fec", .data = &fec_imx8mq_info, },
204 { .compatible = "fsl,imx8qm-fec", .data = &fec_imx8qm_info, },
205 { .compatible = "fsl,s32v234-fec", .data = &fec_s32v234_info, },
217 * if this is non-zero then assume it is the address to get MAC from.
239 #define PKT_MAXBUF_SIZE (round_down(2048 - 64, 64))
295 ((addr >= txq->tso_hdrs_dma) && \
296 (addr < txq->tso_hdrs_dma + txq->bd.ring_size * TSO_HEADER_SIZE))
303 return (bdp >= bd->last) ? bd->base in fec_enet_get_nextdesc()
304 : (struct bufdesc *)(((void *)bdp) + bd->dsize); in fec_enet_get_nextdesc()
310 return (bdp <= bd->base) ? bd->last in fec_enet_get_prevdesc()
311 : (struct bufdesc *)(((void *)bdp) - bd->dsize); in fec_enet_get_prevdesc()
317 return ((const char *)bdp - (const char *)bd->base) >> bd->dsize_log2; in fec_enet_get_bd_index()
324 entries = (((const char *)txq->dirty_tx - in fec_enet_get_free_txdesc_num()
325 (const char *)txq->bd.cur) >> txq->bd.dsize_log2) - 1; in fec_enet_get_free_txdesc_num()
327 return entries >= 0 ? entries : entries + txq->bd.ring_size; in fec_enet_get_free_txdesc_num()
349 txq = fep->tx_queue[0]; in fec_dump()
350 bdp = txq->bd.base; in fec_dump()
355 bdp == txq->bd.cur ? 'S' : ' ', in fec_dump()
356 bdp == txq->dirty_tx ? 'H' : ' ', in fec_dump()
357 fec16_to_cpu(bdp->cbd_sc), in fec_dump()
358 fec32_to_cpu(bdp->cbd_bufaddr), in fec_dump()
359 fec16_to_cpu(bdp->cbd_datlen), in fec_dump()
360 txq->tx_buf[index].buf_p); in fec_dump()
361 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_dump()
363 } while (bdp != txq->bd.base); in fec_dump()
368 * a band-aid with a manual flush in fec_enet_rx_queue.
406 fec_dma_free(dev, this->size, this->vaddr, this->dma_handle); in fec_dmam_release()
423 dr->vaddr = vaddr; in fec_dmam_alloc()
424 dr->dma_handle = *handle; in fec_dmam_alloc()
425 dr->size = size; in fec_dmam_alloc()
432 return skb->protocol == htons(ETH_P_IP) && ip_hdr(skb)->version == 4; in is_ipv4_pkt()
439 if (skb->ip_summed != CHECKSUM_PARTIAL) in fec_enet_clear_csum()
443 return -1; in fec_enet_clear_csum()
446 ip_hdr(skb)->check = 0; in fec_enet_clear_csum()
447 *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0; in fec_enet_clear_csum()
456 struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog); in fec_enet_create_page_pool()
461 .nid = dev_to_node(&fep->pdev->dev), in fec_enet_create_page_pool()
462 .dev = &fep->pdev->dev, in fec_enet_create_page_pool()
469 rxq->page_pool = page_pool_create(&pp_params); in fec_enet_create_page_pool()
470 if (IS_ERR(rxq->page_pool)) { in fec_enet_create_page_pool()
471 err = PTR_ERR(rxq->page_pool); in fec_enet_create_page_pool()
472 rxq->page_pool = NULL; in fec_enet_create_page_pool()
476 err = xdp_rxq_info_reg(&rxq->xdp_rxq, fep->netdev, rxq->id, 0); in fec_enet_create_page_pool()
480 err = xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq, MEM_TYPE_PAGE_POOL, in fec_enet_create_page_pool()
481 rxq->page_pool); in fec_enet_create_page_pool()
488 xdp_rxq_info_unreg(&rxq->xdp_rxq); in fec_enet_create_page_pool()
490 page_pool_destroy(rxq->page_pool); in fec_enet_create_page_pool()
491 rxq->page_pool = NULL; in fec_enet_create_page_pool()
501 struct bufdesc *bdp = txq->bd.cur; in fec_enet_txq_submit_frag_skb()
503 int nr_frags = skb_shinfo(skb)->nr_frags; in fec_enet_txq_submit_frag_skb()
514 this_frag = &skb_shinfo(skb)->frags[frag]; in fec_enet_txq_submit_frag_skb()
515 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_txq_submit_frag_skb()
518 status = fec16_to_cpu(bdp->cbd_sc); in fec_enet_txq_submit_frag_skb()
521 frag_len = skb_frag_size(&skb_shinfo(skb)->frags[frag]); in fec_enet_txq_submit_frag_skb()
524 if (frag == nr_frags - 1) { in fec_enet_txq_submit_frag_skb()
526 if (fep->bufdesc_ex) { in fec_enet_txq_submit_frag_skb()
528 if (unlikely(skb_shinfo(skb)->tx_flags & in fec_enet_txq_submit_frag_skb()
529 SKBTX_HW_TSTAMP && fep->hwts_tx_en)) in fec_enet_txq_submit_frag_skb()
534 if (fep->bufdesc_ex) { in fec_enet_txq_submit_frag_skb()
535 if (fep->quirks & FEC_QUIRK_HAS_AVB) in fec_enet_txq_submit_frag_skb()
536 estatus |= FEC_TX_BD_FTYPE(txq->bd.qid); in fec_enet_txq_submit_frag_skb()
537 if (skb->ip_summed == CHECKSUM_PARTIAL) in fec_enet_txq_submit_frag_skb()
540 ebdp->cbd_bdu = 0; in fec_enet_txq_submit_frag_skb()
541 ebdp->cbd_esc = cpu_to_fec32(estatus); in fec_enet_txq_submit_frag_skb()
546 index = fec_enet_get_bd_index(bdp, &txq->bd); in fec_enet_txq_submit_frag_skb()
547 if (((unsigned long) bufaddr) & fep->tx_align || in fec_enet_txq_submit_frag_skb()
548 fep->quirks & FEC_QUIRK_SWAP_FRAME) { in fec_enet_txq_submit_frag_skb()
549 memcpy(txq->tx_bounce[index], bufaddr, frag_len); in fec_enet_txq_submit_frag_skb()
550 bufaddr = txq->tx_bounce[index]; in fec_enet_txq_submit_frag_skb()
552 if (fep->quirks & FEC_QUIRK_SWAP_FRAME) in fec_enet_txq_submit_frag_skb()
556 addr = dma_map_single(&fep->pdev->dev, bufaddr, frag_len, in fec_enet_txq_submit_frag_skb()
558 if (dma_mapping_error(&fep->pdev->dev, addr)) { in fec_enet_txq_submit_frag_skb()
564 bdp->cbd_bufaddr = cpu_to_fec32(addr); in fec_enet_txq_submit_frag_skb()
565 bdp->cbd_datlen = cpu_to_fec16(frag_len); in fec_enet_txq_submit_frag_skb()
570 bdp->cbd_sc = cpu_to_fec16(status); in fec_enet_txq_submit_frag_skb()
575 bdp = txq->bd.cur; in fec_enet_txq_submit_frag_skb()
577 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_txq_submit_frag_skb()
578 dma_unmap_single(&fep->pdev->dev, fec32_to_cpu(bdp->cbd_bufaddr), in fec_enet_txq_submit_frag_skb()
579 fec16_to_cpu(bdp->cbd_datlen), DMA_TO_DEVICE); in fec_enet_txq_submit_frag_skb()
581 return ERR_PTR(-ENOMEM); in fec_enet_txq_submit_frag_skb()
588 int nr_frags = skb_shinfo(skb)->nr_frags; in fec_enet_txq_submit_skb()
606 /* Protocol checksum off-load for TCP and UDP. */ in fec_enet_txq_submit_skb()
613 bdp = txq->bd.cur; in fec_enet_txq_submit_skb()
615 status = fec16_to_cpu(bdp->cbd_sc); in fec_enet_txq_submit_skb()
619 bufaddr = skb->data; in fec_enet_txq_submit_skb()
622 index = fec_enet_get_bd_index(bdp, &txq->bd); in fec_enet_txq_submit_skb()
623 if (((unsigned long) bufaddr) & fep->tx_align || in fec_enet_txq_submit_skb()
624 fep->quirks & FEC_QUIRK_SWAP_FRAME) { in fec_enet_txq_submit_skb()
625 memcpy(txq->tx_bounce[index], skb->data, buflen); in fec_enet_txq_submit_skb()
626 bufaddr = txq->tx_bounce[index]; in fec_enet_txq_submit_skb()
628 if (fep->quirks & FEC_QUIRK_SWAP_FRAME) in fec_enet_txq_submit_skb()
633 addr = dma_map_single(&fep->pdev->dev, bufaddr, buflen, DMA_TO_DEVICE); in fec_enet_txq_submit_skb()
634 if (dma_mapping_error(&fep->pdev->dev, addr)) { in fec_enet_txq_submit_skb()
644 dma_unmap_single(&fep->pdev->dev, addr, in fec_enet_txq_submit_skb()
651 if (fep->bufdesc_ex) { in fec_enet_txq_submit_skb()
653 if (unlikely(skb_shinfo(skb)->tx_flags & in fec_enet_txq_submit_skb()
654 SKBTX_HW_TSTAMP && fep->hwts_tx_en)) in fec_enet_txq_submit_skb()
658 bdp->cbd_bufaddr = cpu_to_fec32(addr); in fec_enet_txq_submit_skb()
659 bdp->cbd_datlen = cpu_to_fec16(buflen); in fec_enet_txq_submit_skb()
661 if (fep->bufdesc_ex) { in fec_enet_txq_submit_skb()
665 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && in fec_enet_txq_submit_skb()
666 fep->hwts_tx_en)) in fec_enet_txq_submit_skb()
667 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in fec_enet_txq_submit_skb()
669 if (fep->quirks & FEC_QUIRK_HAS_AVB) in fec_enet_txq_submit_skb()
670 estatus |= FEC_TX_BD_FTYPE(txq->bd.qid); in fec_enet_txq_submit_skb()
672 if (skb->ip_summed == CHECKSUM_PARTIAL) in fec_enet_txq_submit_skb()
675 ebdp->cbd_bdu = 0; in fec_enet_txq_submit_skb()
676 ebdp->cbd_esc = cpu_to_fec32(estatus); in fec_enet_txq_submit_skb()
679 index = fec_enet_get_bd_index(last_bdp, &txq->bd); in fec_enet_txq_submit_skb()
681 txq->tx_buf[index].buf_p = skb; in fec_enet_txq_submit_skb()
692 bdp->cbd_sc = cpu_to_fec16(status); in fec_enet_txq_submit_skb()
695 bdp = fec_enet_get_nextdesc(last_bdp, &txq->bd); in fec_enet_txq_submit_skb()
699 /* Make sure the update to bdp is performed before txq->bd.cur. */ in fec_enet_txq_submit_skb()
701 txq->bd.cur = bdp; in fec_enet_txq_submit_skb()
704 writel(0, txq->bd.reg_desc_active); in fec_enet_txq_submit_skb()
721 status = fec16_to_cpu(bdp->cbd_sc); in fec_enet_txq_put_data_tso()
726 if (((unsigned long) data) & fep->tx_align || in fec_enet_txq_put_data_tso()
727 fep->quirks & FEC_QUIRK_SWAP_FRAME) { in fec_enet_txq_put_data_tso()
728 memcpy(txq->tx_bounce[index], data, size); in fec_enet_txq_put_data_tso()
729 data = txq->tx_bounce[index]; in fec_enet_txq_put_data_tso()
731 if (fep->quirks & FEC_QUIRK_SWAP_FRAME) in fec_enet_txq_put_data_tso()
735 addr = dma_map_single(&fep->pdev->dev, data, size, DMA_TO_DEVICE); in fec_enet_txq_put_data_tso()
736 if (dma_mapping_error(&fep->pdev->dev, addr)) { in fec_enet_txq_put_data_tso()
743 bdp->cbd_datlen = cpu_to_fec16(size); in fec_enet_txq_put_data_tso()
744 bdp->cbd_bufaddr = cpu_to_fec32(addr); in fec_enet_txq_put_data_tso()
746 if (fep->bufdesc_ex) { in fec_enet_txq_put_data_tso()
747 if (fep->quirks & FEC_QUIRK_HAS_AVB) in fec_enet_txq_put_data_tso()
748 estatus |= FEC_TX_BD_FTYPE(txq->bd.qid); in fec_enet_txq_put_data_tso()
749 if (skb->ip_summed == CHECKSUM_PARTIAL) in fec_enet_txq_put_data_tso()
751 ebdp->cbd_bdu = 0; in fec_enet_txq_put_data_tso()
752 ebdp->cbd_esc = cpu_to_fec32(estatus); in fec_enet_txq_put_data_tso()
760 if (fep->bufdesc_ex) in fec_enet_txq_put_data_tso()
761 ebdp->cbd_esc |= cpu_to_fec32(BD_ENET_TX_INT); in fec_enet_txq_put_data_tso()
764 bdp->cbd_sc = cpu_to_fec16(status); in fec_enet_txq_put_data_tso()
782 status = fec16_to_cpu(bdp->cbd_sc); in fec_enet_txq_put_hdr_tso()
786 bufaddr = txq->tso_hdrs + index * TSO_HEADER_SIZE; in fec_enet_txq_put_hdr_tso()
787 dmabuf = txq->tso_hdrs_dma + index * TSO_HEADER_SIZE; in fec_enet_txq_put_hdr_tso()
788 if (((unsigned long)bufaddr) & fep->tx_align || in fec_enet_txq_put_hdr_tso()
789 fep->quirks & FEC_QUIRK_SWAP_FRAME) { in fec_enet_txq_put_hdr_tso()
790 memcpy(txq->tx_bounce[index], skb->data, hdr_len); in fec_enet_txq_put_hdr_tso()
791 bufaddr = txq->tx_bounce[index]; in fec_enet_txq_put_hdr_tso()
793 if (fep->quirks & FEC_QUIRK_SWAP_FRAME) in fec_enet_txq_put_hdr_tso()
796 dmabuf = dma_map_single(&fep->pdev->dev, bufaddr, in fec_enet_txq_put_hdr_tso()
798 if (dma_mapping_error(&fep->pdev->dev, dmabuf)) { in fec_enet_txq_put_hdr_tso()
806 bdp->cbd_bufaddr = cpu_to_fec32(dmabuf); in fec_enet_txq_put_hdr_tso()
807 bdp->cbd_datlen = cpu_to_fec16(hdr_len); in fec_enet_txq_put_hdr_tso()
809 if (fep->bufdesc_ex) { in fec_enet_txq_put_hdr_tso()
810 if (fep->quirks & FEC_QUIRK_HAS_AVB) in fec_enet_txq_put_hdr_tso()
811 estatus |= FEC_TX_BD_FTYPE(txq->bd.qid); in fec_enet_txq_put_hdr_tso()
812 if (skb->ip_summed == CHECKSUM_PARTIAL) in fec_enet_txq_put_hdr_tso()
814 ebdp->cbd_bdu = 0; in fec_enet_txq_put_hdr_tso()
815 ebdp->cbd_esc = cpu_to_fec32(estatus); in fec_enet_txq_put_hdr_tso()
818 bdp->cbd_sc = cpu_to_fec16(status); in fec_enet_txq_put_hdr_tso()
829 struct bufdesc *bdp = txq->bd.cur; in fec_enet_txq_submit_tso()
841 /* Protocol checksum off-load for TCP and UDP. */ in fec_enet_txq_submit_tso()
850 total_len = skb->len - hdr_len; in fec_enet_txq_submit_tso()
854 index = fec_enet_get_bd_index(bdp, &txq->bd); in fec_enet_txq_submit_tso()
855 data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len); in fec_enet_txq_submit_tso()
856 total_len -= data_left; in fec_enet_txq_submit_tso()
859 hdr = txq->tso_hdrs + index * TSO_HEADER_SIZE; in fec_enet_txq_submit_tso()
869 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_txq_submit_tso()
870 index = fec_enet_get_bd_index(bdp, &txq->bd); in fec_enet_txq_submit_tso()
879 data_left -= size; in fec_enet_txq_submit_tso()
883 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_txq_submit_tso()
887 txq->tx_buf[index].buf_p = skb; in fec_enet_txq_submit_tso()
890 txq->bd.cur = bdp; in fec_enet_txq_submit_tso()
893 if (!(fep->quirks & FEC_QUIRK_ERR007885) || in fec_enet_txq_submit_tso()
894 !readl(txq->bd.reg_desc_active) || in fec_enet_txq_submit_tso()
895 !readl(txq->bd.reg_desc_active) || in fec_enet_txq_submit_tso()
896 !readl(txq->bd.reg_desc_active) || in fec_enet_txq_submit_tso()
897 !readl(txq->bd.reg_desc_active)) in fec_enet_txq_submit_tso()
898 writel(0, txq->bd.reg_desc_active); in fec_enet_txq_submit_tso()
918 txq = fep->tx_queue[queue]; in fec_enet_start_xmit()
929 if (entries_free <= txq->tx_stop_threshold) in fec_enet_start_xmit()
946 for (q = 0; q < fep->num_rx_queues; q++) { in fec_enet_bd_init()
948 rxq = fep->rx_queue[q]; in fec_enet_bd_init()
949 bdp = rxq->bd.base; in fec_enet_bd_init()
951 for (i = 0; i < rxq->bd.ring_size; i++) { in fec_enet_bd_init()
954 if (bdp->cbd_bufaddr) in fec_enet_bd_init()
955 bdp->cbd_sc = cpu_to_fec16(BD_ENET_RX_EMPTY); in fec_enet_bd_init()
957 bdp->cbd_sc = cpu_to_fec16(0); in fec_enet_bd_init()
958 bdp = fec_enet_get_nextdesc(bdp, &rxq->bd); in fec_enet_bd_init()
962 bdp = fec_enet_get_prevdesc(bdp, &rxq->bd); in fec_enet_bd_init()
963 bdp->cbd_sc |= cpu_to_fec16(BD_SC_WRAP); in fec_enet_bd_init()
965 rxq->bd.cur = rxq->bd.base; in fec_enet_bd_init()
968 for (q = 0; q < fep->num_tx_queues; q++) { in fec_enet_bd_init()
970 txq = fep->tx_queue[q]; in fec_enet_bd_init()
971 bdp = txq->bd.base; in fec_enet_bd_init()
972 txq->bd.cur = bdp; in fec_enet_bd_init()
974 for (i = 0; i < txq->bd.ring_size; i++) { in fec_enet_bd_init()
976 bdp->cbd_sc = cpu_to_fec16(0); in fec_enet_bd_init()
977 if (txq->tx_buf[i].type == FEC_TXBUF_T_SKB) { in fec_enet_bd_init()
978 if (bdp->cbd_bufaddr && in fec_enet_bd_init()
979 !IS_TSO_HEADER(txq, fec32_to_cpu(bdp->cbd_bufaddr))) in fec_enet_bd_init()
980 dma_unmap_single(&fep->pdev->dev, in fec_enet_bd_init()
981 fec32_to_cpu(bdp->cbd_bufaddr), in fec_enet_bd_init()
982 fec16_to_cpu(bdp->cbd_datlen), in fec_enet_bd_init()
984 if (txq->tx_buf[i].buf_p) in fec_enet_bd_init()
985 dev_kfree_skb_any(txq->tx_buf[i].buf_p); in fec_enet_bd_init()
986 } else if (txq->tx_buf[i].type == FEC_TXBUF_T_XDP_NDO) { in fec_enet_bd_init()
987 if (bdp->cbd_bufaddr) in fec_enet_bd_init()
988 dma_unmap_single(&fep->pdev->dev, in fec_enet_bd_init()
989 fec32_to_cpu(bdp->cbd_bufaddr), in fec_enet_bd_init()
990 fec16_to_cpu(bdp->cbd_datlen), in fec_enet_bd_init()
993 if (txq->tx_buf[i].buf_p) in fec_enet_bd_init()
994 xdp_return_frame(txq->tx_buf[i].buf_p); in fec_enet_bd_init()
996 struct page *page = txq->tx_buf[i].buf_p; in fec_enet_bd_init()
999 page_pool_put_page(page->pp, page, 0, false); in fec_enet_bd_init()
1002 txq->tx_buf[i].buf_p = NULL; in fec_enet_bd_init()
1004 txq->tx_buf[i].type = FEC_TXBUF_T_SKB; in fec_enet_bd_init()
1005 bdp->cbd_bufaddr = cpu_to_fec32(0); in fec_enet_bd_init()
1006 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_bd_init()
1010 bdp = fec_enet_get_prevdesc(bdp, &txq->bd); in fec_enet_bd_init()
1011 bdp->cbd_sc |= cpu_to_fec16(BD_SC_WRAP); in fec_enet_bd_init()
1012 txq->dirty_tx = bdp; in fec_enet_bd_init()
1021 for (i = 0; i < fep->num_rx_queues; i++) in fec_enet_active_rxring()
1022 writel(0, fep->rx_queue[i]->bd.reg_desc_active); in fec_enet_active_rxring()
1032 for (i = 0; i < fep->num_rx_queues; i++) { in fec_enet_enable_ring()
1033 rxq = fep->rx_queue[i]; in fec_enet_enable_ring()
1034 writel(rxq->bd.dma, fep->hwp + FEC_R_DES_START(i)); in fec_enet_enable_ring()
1035 writel(PKT_MAXBUF_SIZE, fep->hwp + FEC_R_BUFF_SIZE(i)); in fec_enet_enable_ring()
1040 fep->hwp + FEC_RCMR(i)); in fec_enet_enable_ring()
1043 for (i = 0; i < fep->num_tx_queues; i++) { in fec_enet_enable_ring()
1044 txq = fep->tx_queue[i]; in fec_enet_enable_ring()
1045 writel(txq->bd.dma, fep->hwp + FEC_X_DES_START(i)); in fec_enet_enable_ring()
1050 fep->hwp + FEC_DMA_CFG(i)); in fec_enet_enable_ring()
1071 if (fep->quirks & FEC_QUIRK_HAS_MULTI_QUEUES || in fec_restart()
1072 ((fep->quirks & FEC_QUIRK_NO_HARD_RESET) && fep->link)) { in fec_restart()
1073 writel(0, fep->hwp + FEC_ECNTRL); in fec_restart()
1075 writel(1, fep->hwp + FEC_ECNTRL); in fec_restart()
1080 * enet-mac reset will reset mac address registers too, in fec_restart()
1083 memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN); in fec_restart()
1085 fep->hwp + FEC_ADDR_LOW); in fec_restart()
1087 fep->hwp + FEC_ADDR_HIGH); in fec_restart()
1090 writel((0xffffffff & ~FEC_ENET_MII), fep->hwp + FEC_IEVENT); in fec_restart()
1097 if (fep->full_duplex == DUPLEX_FULL) { in fec_restart()
1099 writel(0x04, fep->hwp + FEC_X_CNTRL); in fec_restart()
1103 writel(0x0, fep->hwp + FEC_X_CNTRL); in fec_restart()
1107 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); in fec_restart()
1110 if (fep->quirks & FEC_QUIRK_HAS_RACC) { in fec_restart()
1111 u32 val = readl(fep->hwp + FEC_RACC); in fec_restart()
1115 if (fep->csum_flags & FLAG_RX_CSUM_ENABLED) in fec_restart()
1120 writel(val, fep->hwp + FEC_RACC); in fec_restart()
1121 writel(PKT_MAXBUF_SIZE, fep->hwp + FEC_FTRL); in fec_restart()
1127 * differently on enet-mac. in fec_restart()
1129 if (fep->quirks & FEC_QUIRK_ENET_MAC) { in fec_restart()
1134 if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII || in fec_restart()
1135 fep->phy_interface == PHY_INTERFACE_MODE_RGMII_ID || in fec_restart()
1136 fep->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID || in fec_restart()
1137 fep->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) in fec_restart()
1139 else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) in fec_restart()
1145 if (ndev->phydev) { in fec_restart()
1146 if (ndev->phydev->speed == SPEED_1000) in fec_restart()
1148 else if (ndev->phydev->speed == SPEED_100) in fec_restart()
1155 if (fep->quirks & FEC_QUIRK_USE_GASKET) { in fec_restart()
1158 writel(0, fep->hwp + FEC_MIIGSK_ENR); in fec_restart()
1159 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4) in fec_restart()
1164 * RMII, 50 MHz, no loopback, no echo in fec_restart()
1165 * MII, 25 MHz, no loopback, no echo in fec_restart()
1167 cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII) in fec_restart()
1169 if (ndev->phydev && ndev->phydev->speed == SPEED_10) in fec_restart()
1171 writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR); in fec_restart()
1173 /* re-enable the gasket */ in fec_restart()
1174 writel(2, fep->hwp + FEC_MIIGSK_ENR); in fec_restart()
1181 if ((fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) || in fec_restart()
1182 ((fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) && in fec_restart()
1183 ndev->phydev && ndev->phydev->pause)) { in fec_restart()
1187 writel(FEC_ENET_RSEM_V, fep->hwp + FEC_R_FIFO_RSEM); in fec_restart()
1188 writel(FEC_ENET_RSFL_V, fep->hwp + FEC_R_FIFO_RSFL); in fec_restart()
1189 writel(FEC_ENET_RAEM_V, fep->hwp + FEC_R_FIFO_RAEM); in fec_restart()
1190 writel(FEC_ENET_RAFL_V, fep->hwp + FEC_R_FIFO_RAFL); in fec_restart()
1193 writel(FEC_ENET_OPD_V, fep->hwp + FEC_OPD); in fec_restart()
1199 writel(rcntl, fep->hwp + FEC_R_CNTRL); in fec_restart()
1204 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH); in fec_restart()
1205 writel(0, fep->hwp + FEC_HASH_TABLE_LOW); in fec_restart()
1208 if (fep->quirks & FEC_QUIRK_ENET_MAC) { in fec_restart()
1212 writel(1 << 8, fep->hwp + FEC_X_WMRK); in fec_restart()
1215 if (fep->bufdesc_ex) in fec_restart()
1218 if (fep->quirks & FEC_QUIRK_DELAYED_CLKS_SUPPORT && in fec_restart()
1219 fep->rgmii_txc_dly) in fec_restart()
1221 if (fep->quirks & FEC_QUIRK_DELAYED_CLKS_SUPPORT && in fec_restart()
1222 fep->rgmii_rxc_dly) in fec_restart()
1227 writel(0 << 31, fep->hwp + FEC_MIB_CTRLSTAT); in fec_restart()
1231 writel(ecntl, fep->hwp + FEC_ECNTRL); in fec_restart()
1234 if (fep->bufdesc_ex) in fec_restart()
1238 if (fep->link) in fec_restart()
1239 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); in fec_restart()
1241 writel(0, fep->hwp + FEC_IMASK); in fec_restart()
1244 if (fep->quirks & FEC_QUIRK_HAS_COALESCE) in fec_restart()
1255 return imx_scu_get_handle(&fep->ipc_handle); in fec_enet_ipc_handle_init()
1260 struct device_node *np = fep->pdev->dev.of_node; in fec_enet_ipg_stop_set()
1264 if (!np || !fep->ipc_handle) in fec_enet_ipg_stop_set()
1273 imx_sc_misc_set_control(fep->ipc_handle, rsrc_id, IMX_SC_C_IPG_STOP, val); in fec_enet_ipg_stop_set()
1278 struct fec_platform_data *pdata = fep->pdev->dev.platform_data; in fec_enet_stop_mode()
1279 struct fec_stop_mode_gpr *stop_gpr = &fep->stop_gpr; in fec_enet_stop_mode()
1281 if (stop_gpr->gpr) { in fec_enet_stop_mode()
1283 regmap_update_bits(stop_gpr->gpr, stop_gpr->reg, in fec_enet_stop_mode()
1284 BIT(stop_gpr->bit), in fec_enet_stop_mode()
1285 BIT(stop_gpr->bit)); in fec_enet_stop_mode()
1287 regmap_update_bits(stop_gpr->gpr, stop_gpr->reg, in fec_enet_stop_mode()
1288 BIT(stop_gpr->bit), 0); in fec_enet_stop_mode()
1289 } else if (pdata && pdata->sleep_mode_enable) { in fec_enet_stop_mode()
1290 pdata->sleep_mode_enable(enabled); in fec_enet_stop_mode()
1300 writel(0, fep->hwp + FEC_IMASK); in fec_irqs_disable()
1307 writel(0, fep->hwp + FEC_IMASK); in fec_irqs_disable_except_wakeup()
1308 writel(FEC_ENET_WAKEUP, fep->hwp + FEC_IMASK); in fec_irqs_disable_except_wakeup()
1315 u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8); in fec_stop()
1319 if (fep->link) { in fec_stop()
1320 writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */ in fec_stop()
1322 if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA)) in fec_stop()
1330 if (!(fep->wol_flag & FEC_WOL_FLAG_SLEEP_ON)) { in fec_stop()
1331 if (fep->quirks & FEC_QUIRK_HAS_MULTI_QUEUES) { in fec_stop()
1332 writel(0, fep->hwp + FEC_ECNTRL); in fec_stop()
1334 writel(1, fep->hwp + FEC_ECNTRL); in fec_stop()
1338 val = readl(fep->hwp + FEC_ECNTRL); in fec_stop()
1340 writel(val, fep->hwp + FEC_ECNTRL); in fec_stop()
1342 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); in fec_stop()
1343 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); in fec_stop()
1346 if (fep->quirks & FEC_QUIRK_ENET_MAC && in fec_stop()
1347 !(fep->wol_flag & FEC_WOL_FLAG_SLEEP_ON)) { in fec_stop()
1348 writel(2, fep->hwp + FEC_ECNTRL); in fec_stop()
1349 writel(rmii_mode, fep->hwp + FEC_R_CNTRL); in fec_stop()
1361 ndev->stats.tx_errors++; in fec_timeout()
1363 schedule_work(&fep->tx_timeout_work); in fec_timeout()
1370 struct net_device *ndev = fep->netdev; in fec_enet_timeout_work()
1374 napi_disable(&fep->napi); in fec_enet_timeout_work()
1379 napi_enable(&fep->napi); in fec_enet_timeout_work()
1391 spin_lock_irqsave(&fep->tmreg_lock, flags); in fec_enet_hwtstamp()
1392 ns = timecounter_cyc2time(&fep->tc, ts); in fec_enet_hwtstamp()
1393 spin_unlock_irqrestore(&fep->tmreg_lock, flags); in fec_enet_hwtstamp()
1396 hwtstamps->hwtstamp = ns_to_ktime(ns); in fec_enet_hwtstamp()
1416 txq = fep->tx_queue[queue_id]; in fec_enet_tx_queue()
1419 bdp = txq->dirty_tx; in fec_enet_tx_queue()
1422 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_tx_queue()
1424 while (bdp != READ_ONCE(txq->bd.cur)) { in fec_enet_tx_queue()
1427 status = fec16_to_cpu(READ_ONCE(bdp->cbd_sc)); in fec_enet_tx_queue()
1431 index = fec_enet_get_bd_index(bdp, &txq->bd); in fec_enet_tx_queue()
1433 if (txq->tx_buf[index].type == FEC_TXBUF_T_SKB) { in fec_enet_tx_queue()
1434 skb = txq->tx_buf[index].buf_p; in fec_enet_tx_queue()
1435 if (bdp->cbd_bufaddr && in fec_enet_tx_queue()
1436 !IS_TSO_HEADER(txq, fec32_to_cpu(bdp->cbd_bufaddr))) in fec_enet_tx_queue()
1437 dma_unmap_single(&fep->pdev->dev, in fec_enet_tx_queue()
1438 fec32_to_cpu(bdp->cbd_bufaddr), in fec_enet_tx_queue()
1439 fec16_to_cpu(bdp->cbd_datlen), in fec_enet_tx_queue()
1441 bdp->cbd_bufaddr = cpu_to_fec32(0); in fec_enet_tx_queue()
1453 if (txq->tx_buf[index].type == FEC_TXBUF_T_XDP_NDO) { in fec_enet_tx_queue()
1454 xdpf = txq->tx_buf[index].buf_p; in fec_enet_tx_queue()
1455 if (bdp->cbd_bufaddr) in fec_enet_tx_queue()
1456 dma_unmap_single(&fep->pdev->dev, in fec_enet_tx_queue()
1457 fec32_to_cpu(bdp->cbd_bufaddr), in fec_enet_tx_queue()
1458 fec16_to_cpu(bdp->cbd_datlen), in fec_enet_tx_queue()
1461 page = txq->tx_buf[index].buf_p; in fec_enet_tx_queue()
1464 bdp->cbd_bufaddr = cpu_to_fec32(0); in fec_enet_tx_queue()
1465 if (unlikely(!txq->tx_buf[index].buf_p)) { in fec_enet_tx_queue()
1466 txq->tx_buf[index].type = FEC_TXBUF_T_SKB; in fec_enet_tx_queue()
1470 frame_len = fec16_to_cpu(bdp->cbd_datlen); in fec_enet_tx_queue()
1477 ndev->stats.tx_errors++; in fec_enet_tx_queue()
1479 ndev->stats.tx_heartbeat_errors++; in fec_enet_tx_queue()
1481 ndev->stats.tx_window_errors++; in fec_enet_tx_queue()
1483 ndev->stats.tx_aborted_errors++; in fec_enet_tx_queue()
1485 ndev->stats.tx_fifo_errors++; in fec_enet_tx_queue()
1487 ndev->stats.tx_carrier_errors++; in fec_enet_tx_queue()
1489 ndev->stats.tx_packets++; in fec_enet_tx_queue()
1491 if (txq->tx_buf[index].type == FEC_TXBUF_T_SKB) in fec_enet_tx_queue()
1492 ndev->stats.tx_bytes += skb->len; in fec_enet_tx_queue()
1494 ndev->stats.tx_bytes += frame_len; in fec_enet_tx_queue()
1501 ndev->stats.collisions++; in fec_enet_tx_queue()
1503 if (txq->tx_buf[index].type == FEC_TXBUF_T_SKB) { in fec_enet_tx_queue()
1508 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS && in fec_enet_tx_queue()
1509 fep->hwts_tx_en) && fep->bufdesc_ex) { in fec_enet_tx_queue()
1513 fec_enet_hwtstamp(fep, fec32_to_cpu(ebdp->ts), &shhwtstamps); in fec_enet_tx_queue()
1519 } else if (txq->tx_buf[index].type == FEC_TXBUF_T_XDP_NDO) { in fec_enet_tx_queue()
1523 page_pool_put_page(page->pp, page, 0, true); in fec_enet_tx_queue()
1526 txq->tx_buf[index].buf_p = NULL; in fec_enet_tx_queue()
1528 txq->tx_buf[index].type = FEC_TXBUF_T_SKB; in fec_enet_tx_queue()
1535 txq->dirty_tx = bdp; in fec_enet_tx_queue()
1538 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_tx_queue()
1544 if (entries_free >= txq->tx_wake_threshold) in fec_enet_tx_queue()
1550 if (bdp != txq->bd.cur && in fec_enet_tx_queue()
1551 readl(txq->bd.reg_desc_active) == 0) in fec_enet_tx_queue()
1552 writel(0, txq->bd.reg_desc_active); in fec_enet_tx_queue()
1561 for (i = fep->num_tx_queues - 1; i >= 0; i--) in fec_enet_tx()
1571 new_page = page_pool_dev_alloc_pages(rxq->page_pool); in fec_enet_update_cbd()
1573 rxq->rx_skb_info[index].page = new_page; in fec_enet_update_cbd()
1575 rxq->rx_skb_info[index].offset = FEC_ENET_XDP_HEADROOM; in fec_enet_update_cbd()
1577 bdp->cbd_bufaddr = cpu_to_fec32(phys_addr); in fec_enet_update_cbd()
1584 unsigned int sync, len = xdp->data_end - xdp->data; in fec_enet_run_xdp()
1595 sync = xdp->data_end - xdp->data; in fec_enet_run_xdp()
1600 rxq->stats[RX_XDP_PASS]++; in fec_enet_run_xdp()
1605 rxq->stats[RX_XDP_REDIRECT]++; in fec_enet_run_xdp()
1606 err = xdp_do_redirect(fep->netdev, xdp, prog); in fec_enet_run_xdp()
1614 rxq->stats[RX_XDP_TX]++; in fec_enet_run_xdp()
1617 rxq->stats[RX_XDP_TX_ERRORS]++; in fec_enet_run_xdp()
1625 bpf_warn_invalid_xdp_action(fep->netdev, prog, act); in fec_enet_run_xdp()
1632 rxq->stats[RX_XDP_DROP]++; in fec_enet_run_xdp()
1635 page = virt_to_head_page(xdp->data); in fec_enet_run_xdp()
1636 page_pool_put_page(rxq->page_pool, page, sync, true); in fec_enet_run_xdp()
1638 trace_xdp_exception(fep->netdev, prog, act); in fec_enet_run_xdp()
1665 bool need_swap = fep->quirks & FEC_QUIRK_SWAP_FRAME; in fec_enet_rx_queue()
1666 struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog); in fec_enet_rx_queue()
1678 if (fep->quirks & FEC_QUIRK_HAS_RACC) { in fec_enet_rx_queue()
1691 rxq = fep->rx_queue[queue_id]; in fec_enet_rx_queue()
1696 bdp = rxq->bd.cur; in fec_enet_rx_queue()
1697 xdp_init_buff(&xdp, PAGE_SIZE, &rxq->xdp_rxq); in fec_enet_rx_queue()
1699 while (!((status = fec16_to_cpu(bdp->cbd_sc)) & BD_ENET_RX_EMPTY)) { in fec_enet_rx_queue()
1705 writel(FEC_ENET_RXF_GET(queue_id), fep->hwp + FEC_IEVENT); in fec_enet_rx_queue()
1712 ndev->stats.rx_errors++; in fec_enet_rx_queue()
1715 ndev->stats.rx_fifo_errors++; in fec_enet_rx_queue()
1721 ndev->stats.rx_length_errors++; in fec_enet_rx_queue()
1726 ndev->stats.rx_crc_errors++; in fec_enet_rx_queue()
1729 ndev->stats.rx_frame_errors++; in fec_enet_rx_queue()
1734 ndev->stats.rx_packets++; in fec_enet_rx_queue()
1735 pkt_len = fec16_to_cpu(bdp->cbd_datlen); in fec_enet_rx_queue()
1736 ndev->stats.rx_bytes += pkt_len; in fec_enet_rx_queue()
1738 index = fec_enet_get_bd_index(bdp, &rxq->bd); in fec_enet_rx_queue()
1739 page = rxq->rx_skb_info[index].page; in fec_enet_rx_queue()
1740 dma_sync_single_for_cpu(&fep->pdev->dev, in fec_enet_rx_queue()
1741 fec32_to_cpu(bdp->cbd_bufaddr), in fec_enet_rx_queue()
1751 data_start, pkt_len - sub_len, false); in fec_enet_rx_queue()
1764 page_pool_recycle_direct(rxq->page_pool, page); in fec_enet_rx_queue()
1765 ndev->stats.rx_dropped++; in fec_enet_rx_queue()
1772 skb_put(skb, pkt_len - sub_len); in fec_enet_rx_queue()
1779 data = skb->data; in fec_enet_rx_queue()
1783 if (fep->bufdesc_ex) in fec_enet_rx_queue()
1788 if ((ndev->features & NETIF_F_HW_VLAN_CTAG_RX) && in fec_enet_rx_queue()
1789 fep->bufdesc_ex && in fec_enet_rx_queue()
1790 (ebdp->cbd_esc & cpu_to_fec32(BD_ENET_RX_VLAN))) { in fec_enet_rx_queue()
1794 vlan_tag = ntohs(vlan_header->h_vlan_TCI); in fec_enet_rx_queue()
1798 memmove(skb->data + VLAN_HLEN, data, ETH_ALEN * 2); in fec_enet_rx_queue()
1802 skb->protocol = eth_type_trans(skb, ndev); in fec_enet_rx_queue()
1805 if (fep->hwts_rx_en && fep->bufdesc_ex) in fec_enet_rx_queue()
1806 fec_enet_hwtstamp(fep, fec32_to_cpu(ebdp->ts), in fec_enet_rx_queue()
1809 if (fep->bufdesc_ex && in fec_enet_rx_queue()
1810 (fep->csum_flags & FLAG_RX_CSUM_ENABLED)) { in fec_enet_rx_queue()
1811 if (!(ebdp->cbd_esc & cpu_to_fec32(FLAG_RX_CSUM_ERROR))) { in fec_enet_rx_queue()
1813 skb->ip_summed = CHECKSUM_UNNECESSARY; in fec_enet_rx_queue()
1826 napi_gro_receive(&fep->napi, skb); in fec_enet_rx_queue()
1835 if (fep->bufdesc_ex) { in fec_enet_rx_queue()
1838 ebdp->cbd_esc = cpu_to_fec32(BD_ENET_RX_INT); in fec_enet_rx_queue()
1839 ebdp->cbd_prot = 0; in fec_enet_rx_queue()
1840 ebdp->cbd_bdu = 0; in fec_enet_rx_queue()
1846 bdp->cbd_sc = cpu_to_fec16(status); in fec_enet_rx_queue()
1849 bdp = fec_enet_get_nextdesc(bdp, &rxq->bd); in fec_enet_rx_queue()
1855 writel(0, rxq->bd.reg_desc_active); in fec_enet_rx_queue()
1857 rxq->bd.cur = bdp; in fec_enet_rx_queue()
1871 for (i = fep->num_rx_queues - 1; i >= 0; i--) in fec_enet_rx()
1872 done += fec_enet_rx_queue(ndev, budget - done, i); in fec_enet_rx()
1881 int_events = readl(fep->hwp + FEC_IEVENT); in fec_enet_collect_events()
1886 writel(int_events, fep->hwp + FEC_IEVENT); in fec_enet_collect_events()
1898 if (fec_enet_collect_events(fep) && fep->link) { in fec_enet_interrupt()
1901 if (napi_schedule_prep(&fep->napi)) { in fec_enet_interrupt()
1903 writel(0, fep->hwp + FEC_IMASK); in fec_enet_interrupt()
1904 __napi_schedule(&fep->napi); in fec_enet_interrupt()
1913 struct net_device *ndev = napi->dev; in fec_enet_rx_napi()
1918 done += fec_enet_rx(ndev, budget - done); in fec_enet_rx_napi()
1924 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); in fec_enet_rx_napi()
1930 /* ------------------------------------------------------------------------- */
1949 struct device_node *np = fep->pdev->dev.of_node; in fec_get_mac()
1954 else if (ret == -EPROBE_DEFER) in fec_get_mac()
1967 struct fec_platform_data *pdata = dev_get_platdata(&fep->pdev->dev); in fec_get_mac()
1970 iap = (unsigned char *)&pdata->mac; in fec_get_mac()
1979 cpu_to_be32(readl(fep->hwp + FEC_ADDR_LOW)); in fec_get_mac()
1981 cpu_to_be16(readl(fep->hwp + FEC_ADDR_HIGH) >> 16); in fec_get_mac()
1990 dev_err(&fep->pdev->dev, "Invalid MAC address: %pM\n", iap); in fec_get_mac()
1992 dev_info(&fep->pdev->dev, "Using random MAC address: %pM\n", in fec_get_mac()
1993 ndev->dev_addr); in fec_get_mac()
1998 eth_hw_addr_gen(ndev, iap, iap == macaddr ? fep->dev_id : 0); in fec_get_mac()
2003 /* ------------------------------------------------------------------------- */
2011 struct phy_device *phy_dev = ndev->phydev; in fec_enet_adjust_link()
2020 fep->link = 0; in fec_enet_adjust_link()
2021 } else if (phy_dev->link) { in fec_enet_adjust_link()
2022 if (!fep->link) { in fec_enet_adjust_link()
2023 fep->link = phy_dev->link; in fec_enet_adjust_link()
2027 if (fep->full_duplex != phy_dev->duplex) { in fec_enet_adjust_link()
2028 fep->full_duplex = phy_dev->duplex; in fec_enet_adjust_link()
2032 if (phy_dev->speed != fep->speed) { in fec_enet_adjust_link()
2033 fep->speed = phy_dev->speed; in fec_enet_adjust_link()
2040 napi_disable(&fep->napi); in fec_enet_adjust_link()
2045 napi_enable(&fep->napi); in fec_enet_adjust_link()
2048 if (fep->link) { in fec_enet_adjust_link()
2050 napi_disable(&fep->napi); in fec_enet_adjust_link()
2054 napi_enable(&fep->napi); in fec_enet_adjust_link()
2055 fep->link = phy_dev->link; in fec_enet_adjust_link()
2069 ret = readl_poll_timeout_atomic(fep->hwp + FEC_IEVENT, ievent, in fec_enet_mdio_wait()
2073 writel(FEC_ENET_MII, fep->hwp + FEC_IEVENT); in fec_enet_mdio_wait()
2080 struct fec_enet_private *fep = bus->priv; in fec_enet_mdio_read_c22()
2081 struct device *dev = &fep->pdev->dev; in fec_enet_mdio_read_c22()
2096 FEC_MMFR_TA, fep->hwp + FEC_MII_DATA); in fec_enet_mdio_read_c22()
2101 netdev_err(fep->netdev, "MDIO read timeout\n"); in fec_enet_mdio_read_c22()
2105 ret = FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA)); in fec_enet_mdio_read_c22()
2117 struct fec_enet_private *fep = bus->priv; in fec_enet_mdio_read_c45()
2118 struct device *dev = &fep->pdev->dev; in fec_enet_mdio_read_c45()
2131 fep->hwp + FEC_MII_DATA); in fec_enet_mdio_read_c45()
2136 netdev_err(fep->netdev, "MDIO address write timeout\n"); in fec_enet_mdio_read_c45()
2145 FEC_MMFR_TA, fep->hwp + FEC_MII_DATA); in fec_enet_mdio_read_c45()
2150 netdev_err(fep->netdev, "MDIO read timeout\n"); in fec_enet_mdio_read_c45()
2154 ret = FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA)); in fec_enet_mdio_read_c45()
2166 struct fec_enet_private *fep = bus->priv; in fec_enet_mdio_write_c22()
2167 struct device *dev = &fep->pdev->dev; in fec_enet_mdio_write_c22()
2182 fep->hwp + FEC_MII_DATA); in fec_enet_mdio_write_c22()
2187 netdev_err(fep->netdev, "MDIO write timeout\n"); in fec_enet_mdio_write_c22()
2198 struct fec_enet_private *fep = bus->priv; in fec_enet_mdio_write_c45()
2199 struct device *dev = &fep->pdev->dev; in fec_enet_mdio_write_c45()
2212 fep->hwp + FEC_MII_DATA); in fec_enet_mdio_write_c45()
2217 netdev_err(fep->netdev, "MDIO address write timeout\n"); in fec_enet_mdio_write_c45()
2225 fep->hwp + FEC_MII_DATA); in fec_enet_mdio_write_c45()
2230 netdev_err(fep->netdev, "MDIO write timeout\n"); in fec_enet_mdio_write_c45()
2242 struct phy_device *phy_dev = ndev->phydev; in fec_enet_phy_reset_after_clk_enable()
2246 } else if (fep->phy_node) { in fec_enet_phy_reset_after_clk_enable()
2254 phy_dev = of_phy_find_device(fep->phy_node); in fec_enet_phy_reset_after_clk_enable()
2256 put_device(&phy_dev->mdio.dev); in fec_enet_phy_reset_after_clk_enable()
2266 ret = clk_prepare_enable(fep->clk_enet_out); in fec_enet_clk_enable()
2270 if (fep->clk_ptp) { in fec_enet_clk_enable()
2271 mutex_lock(&fep->ptp_clk_mutex); in fec_enet_clk_enable()
2272 ret = clk_prepare_enable(fep->clk_ptp); in fec_enet_clk_enable()
2274 mutex_unlock(&fep->ptp_clk_mutex); in fec_enet_clk_enable()
2277 fep->ptp_clk_on = true; in fec_enet_clk_enable()
2279 mutex_unlock(&fep->ptp_clk_mutex); in fec_enet_clk_enable()
2282 ret = clk_prepare_enable(fep->clk_ref); in fec_enet_clk_enable()
2286 ret = clk_prepare_enable(fep->clk_2x_txclk); in fec_enet_clk_enable()
2292 clk_disable_unprepare(fep->clk_enet_out); in fec_enet_clk_enable()
2293 if (fep->clk_ptp) { in fec_enet_clk_enable()
2294 mutex_lock(&fep->ptp_clk_mutex); in fec_enet_clk_enable()
2295 clk_disable_unprepare(fep->clk_ptp); in fec_enet_clk_enable()
2296 fep->ptp_clk_on = false; in fec_enet_clk_enable()
2297 mutex_unlock(&fep->ptp_clk_mutex); in fec_enet_clk_enable()
2299 clk_disable_unprepare(fep->clk_ref); in fec_enet_clk_enable()
2300 clk_disable_unprepare(fep->clk_2x_txclk); in fec_enet_clk_enable()
2306 if (fep->clk_ref) in fec_enet_clk_enable()
2307 clk_disable_unprepare(fep->clk_ref); in fec_enet_clk_enable()
2309 if (fep->clk_ptp) { in fec_enet_clk_enable()
2310 mutex_lock(&fep->ptp_clk_mutex); in fec_enet_clk_enable()
2311 clk_disable_unprepare(fep->clk_ptp); in fec_enet_clk_enable()
2312 fep->ptp_clk_on = false; in fec_enet_clk_enable()
2313 mutex_unlock(&fep->ptp_clk_mutex); in fec_enet_clk_enable()
2316 clk_disable_unprepare(fep->clk_enet_out); in fec_enet_clk_enable()
2327 if (!of_property_read_u32(np, "tx-internal-delay-ps", &rgmii_tx_delay)) { in fec_enet_parse_rgmii_delay()
2329 dev_err(&fep->pdev->dev, "The only allowed RGMII TX delay values are: 0ps, 2000ps"); in fec_enet_parse_rgmii_delay()
2330 return -EINVAL; in fec_enet_parse_rgmii_delay()
2332 fep->rgmii_txc_dly = true; in fec_enet_parse_rgmii_delay()
2337 if (!of_property_read_u32(np, "rx-internal-delay-ps", &rgmii_rx_delay)) { in fec_enet_parse_rgmii_delay()
2339 dev_err(&fep->pdev->dev, "The only allowed RGMII RX delay values are: 0ps, 2000ps"); in fec_enet_parse_rgmii_delay()
2340 return -EINVAL; in fec_enet_parse_rgmii_delay()
2342 fep->rgmii_rxc_dly = true; in fec_enet_parse_rgmii_delay()
2356 int dev_id = fep->dev_id; in fec_enet_mii_probe()
2358 if (fep->phy_node) { in fec_enet_mii_probe()
2359 phy_dev = of_phy_connect(ndev, fep->phy_node, in fec_enet_mii_probe()
2361 fep->phy_interface); in fec_enet_mii_probe()
2364 return -ENODEV; in fec_enet_mii_probe()
2369 if (!mdiobus_is_registered_device(fep->mii_bus, phy_id)) in fec_enet_mii_probe()
2371 if (dev_id--) in fec_enet_mii_probe()
2373 strscpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE); in fec_enet_mii_probe()
2379 strscpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE); in fec_enet_mii_probe()
2386 fep->phy_interface); in fec_enet_mii_probe()
2395 if (fep->quirks & FEC_QUIRK_HAS_GBIT) { in fec_enet_mii_probe()
2406 fep->link = 0; in fec_enet_mii_probe()
2407 fep->full_duplex = 0; in fec_enet_mii_probe()
2409 phy_dev->mac_managed_pm = true; in fec_enet_mii_probe()
2423 int err = -ENXIO; in fec_enet_mii_init()
2431 * - fec0 supports MII & RMII modes while fec1 only supports RMII in fec_enet_mii_init()
2432 * - fec0 acts as the 1588 time master while fec1 is slave in fec_enet_mii_init()
2433 * - external phys can only be configured by fec0 in fec_enet_mii_init()
2443 if ((fep->quirks & FEC_QUIRK_SINGLE_MDIO) && fep->dev_id > 0) { in fec_enet_mii_init()
2446 fep->mii_bus = fec0_mii_bus; in fec_enet_mii_init()
2450 return -ENOENT; in fec_enet_mii_init()
2454 node = of_get_child_by_name(pdev->dev.of_node, "mdio"); in fec_enet_mii_init()
2456 of_property_read_u32(node, "clock-frequency", &bus_freq); in fec_enet_mii_init()
2458 "suppress-preamble"); in fec_enet_mii_init()
2465 * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'. The i.MX28 in fec_enet_mii_init()
2469 mii_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg), bus_freq * 2); in fec_enet_mii_init()
2470 if (fep->quirks & FEC_QUIRK_ENET_MAC) in fec_enet_mii_init()
2471 mii_speed--; in fec_enet_mii_init()
2473 dev_err(&pdev->dev, in fec_enet_mii_init()
2475 clk_get_rate(fep->clk_ipg)); in fec_enet_mii_init()
2476 err = -EINVAL; in fec_enet_mii_init()
2492 holdtime = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg), 100000000) - 1; in fec_enet_mii_init()
2494 fep->phy_speed = mii_speed << 1 | holdtime << 8; in fec_enet_mii_init()
2497 fep->phy_speed |= BIT(7); in fec_enet_mii_init()
2499 if (fep->quirks & FEC_QUIRK_CLEAR_SETUP_MII) { in fec_enet_mii_init()
2502 * - writing MSCR: in fec_enet_mii_init()
2503 * - mmfr[31:0]_not_zero & mscr[7:0]_is_zero & in fec_enet_mii_init()
2505 * - writing MMFR: in fec_enet_mii_init()
2506 * - mscr[7:0]_not_zero in fec_enet_mii_init()
2508 writel(0, fep->hwp + FEC_MII_DATA); in fec_enet_mii_init()
2511 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); in fec_enet_mii_init()
2514 writel(FEC_ENET_MII, fep->hwp + FEC_IEVENT); in fec_enet_mii_init()
2516 fep->mii_bus = mdiobus_alloc(); in fec_enet_mii_init()
2517 if (fep->mii_bus == NULL) { in fec_enet_mii_init()
2518 err = -ENOMEM; in fec_enet_mii_init()
2522 fep->mii_bus->name = "fec_enet_mii_bus"; in fec_enet_mii_init()
2523 fep->mii_bus->read = fec_enet_mdio_read_c22; in fec_enet_mii_init()
2524 fep->mii_bus->write = fec_enet_mdio_write_c22; in fec_enet_mii_init()
2525 if (fep->quirks & FEC_QUIRK_HAS_MDIO_C45) { in fec_enet_mii_init()
2526 fep->mii_bus->read_c45 = fec_enet_mdio_read_c45; in fec_enet_mii_init()
2527 fep->mii_bus->write_c45 = fec_enet_mdio_write_c45; in fec_enet_mii_init()
2529 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", in fec_enet_mii_init()
2530 pdev->name, fep->dev_id + 1); in fec_enet_mii_init()
2531 fep->mii_bus->priv = fep; in fec_enet_mii_init()
2532 fep->mii_bus->parent = &pdev->dev; in fec_enet_mii_init()
2534 err = of_mdiobus_register(fep->mii_bus, node); in fec_enet_mii_init()
2542 if (fep->quirks & FEC_QUIRK_SINGLE_MDIO) in fec_enet_mii_init()
2543 fec0_mii_bus = fep->mii_bus; in fec_enet_mii_init()
2548 mdiobus_free(fep->mii_bus); in fec_enet_mii_init()
2556 if (--mii_cnt == 0) { in fec_enet_mii_remove()
2557 mdiobus_unregister(fep->mii_bus); in fec_enet_mii_remove()
2558 mdiobus_free(fep->mii_bus); in fec_enet_mii_remove()
2567 strscpy(info->driver, fep->pdev->dev.driver->name, in fec_enet_get_drvinfo()
2568 sizeof(info->driver)); in fec_enet_get_drvinfo()
2569 strscpy(info->bus_info, dev_name(&ndev->dev), sizeof(info->bus_info)); in fec_enet_get_drvinfo()
2578 r = platform_get_resource(fep->pdev, IORESOURCE_MEM, 0); in fec_enet_get_regs_len()
2663 u32 __iomem *theregs = (u32 __iomem *)fep->hwp; in fec_enet_get_regs()
2664 struct device *dev = &fep->pdev->dev; in fec_enet_get_regs()
2690 regs->version = fec_enet_register_version; in fec_enet_get_regs()
2692 memset(buf, 0, regs->len); in fec_enet_get_regs()
2698 !(fep->quirks & FEC_QUIRK_HAS_FRREG)) in fec_enet_get_regs()
2714 if (fep->bufdesc_ex) { in fec_enet_get_ts_info()
2716 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | in fec_enet_get_ts_info()
2722 if (fep->ptp_clock) in fec_enet_get_ts_info()
2723 info->phc_index = ptp_clock_index(fep->ptp_clock); in fec_enet_get_ts_info()
2725 info->phc_index = -1; in fec_enet_get_ts_info()
2727 info->tx_types = (1 << HWTSTAMP_TX_OFF) | in fec_enet_get_ts_info()
2730 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | in fec_enet_get_ts_info()
2745 pause->autoneg = (fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) != 0; in fec_enet_get_pauseparam()
2746 pause->tx_pause = (fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) != 0; in fec_enet_get_pauseparam()
2747 pause->rx_pause = pause->tx_pause; in fec_enet_get_pauseparam()
2755 if (!ndev->phydev) in fec_enet_set_pauseparam()
2756 return -ENODEV; in fec_enet_set_pauseparam()
2758 if (pause->tx_pause != pause->rx_pause) { in fec_enet_set_pauseparam()
2761 return -EINVAL; in fec_enet_set_pauseparam()
2764 fep->pause_flag = 0; in fec_enet_set_pauseparam()
2767 fep->pause_flag |= pause->rx_pause ? FEC_PAUSE_FLAG_ENABLE : 0; in fec_enet_set_pauseparam()
2768 fep->pause_flag |= pause->autoneg ? FEC_PAUSE_FLAG_AUTONEG : 0; in fec_enet_set_pauseparam()
2770 phy_set_sym_pause(ndev->phydev, pause->rx_pause, pause->tx_pause, in fec_enet_set_pauseparam()
2771 pause->autoneg); in fec_enet_set_pauseparam()
2773 if (pause->autoneg) { in fec_enet_set_pauseparam()
2776 phy_start_aneg(ndev->phydev); in fec_enet_set_pauseparam()
2779 napi_disable(&fep->napi); in fec_enet_set_pauseparam()
2784 napi_enable(&fep->napi); in fec_enet_set_pauseparam()
2874 fep->ethtool_stats[i] = readl(fep->hwp + fec_stats[i].offset); in fec_enet_update_ethtool_stats()
2883 for (i = fep->num_rx_queues - 1; i >= 0; i--) { in fec_enet_get_xdp_stats()
2884 rxq = fep->rx_queue[i]; in fec_enet_get_xdp_stats()
2887 xdp_stats[j] += rxq->stats[j]; in fec_enet_get_xdp_stats()
2900 for (i = fep->num_rx_queues - 1; i >= 0; i--) { in fec_enet_page_pool_stats()
2901 rxq = fep->rx_queue[i]; in fec_enet_page_pool_stats()
2903 if (!rxq->page_pool) in fec_enet_page_pool_stats()
2906 page_pool_get_stats(rxq->page_pool, &stats); in fec_enet_page_pool_stats()
2921 memcpy(data, fep->ethtool_stats, FEC_STATS_SIZE); in fec_enet_get_ethtool_stats()
2964 return -EOPNOTSUPP; in fec_enet_get_sset_count()
2975 writel(FEC_MIB_CTRLSTAT_DISABLE, fep->hwp + FEC_MIB_CTRLSTAT); in fec_enet_clear_ethtool_stats()
2978 writel(0, fep->hwp + fec_stats[i].offset); in fec_enet_clear_ethtool_stats()
2980 for (i = fep->num_rx_queues - 1; i >= 0; i--) { in fec_enet_clear_ethtool_stats()
2981 rxq = fep->rx_queue[i]; in fec_enet_clear_ethtool_stats()
2983 rxq->stats[j] = 0; in fec_enet_clear_ethtool_stats()
2987 writel(0, fep->hwp + FEC_MIB_CTRLSTAT); in fec_enet_clear_ethtool_stats()
3009 return us * (fep->itr_clk_rate / 64000) / 1000; in fec_enet_us_to_itr_clock()
3019 if (!fep->rx_time_itr || !fep->rx_pkts_itr || in fec_enet_itr_coal_set()
3020 !fep->tx_time_itr || !fep->tx_pkts_itr) in fec_enet_itr_coal_set()
3030 rx_itr |= FEC_ITR_ICFT(fep->rx_pkts_itr); in fec_enet_itr_coal_set()
3031 rx_itr |= FEC_ITR_ICTT(fec_enet_us_to_itr_clock(ndev, fep->rx_time_itr)); in fec_enet_itr_coal_set()
3032 tx_itr |= FEC_ITR_ICFT(fep->tx_pkts_itr); in fec_enet_itr_coal_set()
3033 tx_itr |= FEC_ITR_ICTT(fec_enet_us_to_itr_clock(ndev, fep->tx_time_itr)); in fec_enet_itr_coal_set()
3038 writel(tx_itr, fep->hwp + FEC_TXIC0); in fec_enet_itr_coal_set()
3039 writel(rx_itr, fep->hwp + FEC_RXIC0); in fec_enet_itr_coal_set()
3040 if (fep->quirks & FEC_QUIRK_HAS_MULTI_QUEUES) { in fec_enet_itr_coal_set()
3041 writel(tx_itr, fep->hwp + FEC_TXIC1); in fec_enet_itr_coal_set()
3042 writel(rx_itr, fep->hwp + FEC_RXIC1); in fec_enet_itr_coal_set()
3043 writel(tx_itr, fep->hwp + FEC_TXIC2); in fec_enet_itr_coal_set()
3044 writel(rx_itr, fep->hwp + FEC_RXIC2); in fec_enet_itr_coal_set()
3055 if (!(fep->quirks & FEC_QUIRK_HAS_COALESCE)) in fec_enet_get_coalesce()
3056 return -EOPNOTSUPP; in fec_enet_get_coalesce()
3058 ec->rx_coalesce_usecs = fep->rx_time_itr; in fec_enet_get_coalesce()
3059 ec->rx_max_coalesced_frames = fep->rx_pkts_itr; in fec_enet_get_coalesce()
3061 ec->tx_coalesce_usecs = fep->tx_time_itr; in fec_enet_get_coalesce()
3062 ec->tx_max_coalesced_frames = fep->tx_pkts_itr; in fec_enet_get_coalesce()
3073 struct device *dev = &fep->pdev->dev; in fec_enet_set_coalesce()
3076 if (!(fep->quirks & FEC_QUIRK_HAS_COALESCE)) in fec_enet_set_coalesce()
3077 return -EOPNOTSUPP; in fec_enet_set_coalesce()
3079 if (ec->rx_max_coalesced_frames > 255) { in fec_enet_set_coalesce()
3081 return -EINVAL; in fec_enet_set_coalesce()
3084 if (ec->tx_max_coalesced_frames > 255) { in fec_enet_set_coalesce()
3086 return -EINVAL; in fec_enet_set_coalesce()
3089 cycle = fec_enet_us_to_itr_clock(ndev, ec->rx_coalesce_usecs); in fec_enet_set_coalesce()
3092 return -EINVAL; in fec_enet_set_coalesce()
3095 cycle = fec_enet_us_to_itr_clock(ndev, ec->tx_coalesce_usecs); in fec_enet_set_coalesce()
3098 return -EINVAL; in fec_enet_set_coalesce()
3101 fep->rx_time_itr = ec->rx_coalesce_usecs; in fec_enet_set_coalesce()
3102 fep->rx_pkts_itr = ec->rx_max_coalesced_frames; in fec_enet_set_coalesce()
3104 fep->tx_time_itr = ec->tx_coalesce_usecs; in fec_enet_set_coalesce()
3105 fep->tx_pkts_itr = ec->tx_max_coalesced_frames; in fec_enet_set_coalesce()
3119 return us * (fep->clk_ref_rate / 1000) / 1000; in fec_enet_us_to_tx_cycle()
3125 struct ethtool_eee *p = &fep->eee; in fec_enet_eee_mode_set()
3130 ret = phy_init_eee(ndev->phydev, false); in fec_enet_eee_mode_set()
3134 sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer); in fec_enet_eee_mode_set()
3141 p->tx_lpi_enabled = enable; in fec_enet_eee_mode_set()
3142 p->eee_enabled = enable; in fec_enet_eee_mode_set()
3143 p->eee_active = enable; in fec_enet_eee_mode_set()
3145 writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP); in fec_enet_eee_mode_set()
3146 writel(wake_cycle, fep->hwp + FEC_LPI_WAKE); in fec_enet_eee_mode_set()
3155 struct ethtool_eee *p = &fep->eee; in fec_enet_get_eee()
3157 if (!(fep->quirks & FEC_QUIRK_HAS_EEE)) in fec_enet_get_eee()
3158 return -EOPNOTSUPP; in fec_enet_get_eee()
3161 return -ENETDOWN; in fec_enet_get_eee()
3163 edata->eee_enabled = p->eee_enabled; in fec_enet_get_eee()
3164 edata->eee_active = p->eee_active; in fec_enet_get_eee()
3165 edata->tx_lpi_timer = p->tx_lpi_timer; in fec_enet_get_eee()
3166 edata->tx_lpi_enabled = p->tx_lpi_enabled; in fec_enet_get_eee()
3168 return phy_ethtool_get_eee(ndev->phydev, edata); in fec_enet_get_eee()
3175 struct ethtool_eee *p = &fep->eee; in fec_enet_set_eee()
3178 if (!(fep->quirks & FEC_QUIRK_HAS_EEE)) in fec_enet_set_eee()
3179 return -EOPNOTSUPP; in fec_enet_set_eee()
3182 return -ENETDOWN; in fec_enet_set_eee()
3184 p->tx_lpi_timer = edata->tx_lpi_timer; in fec_enet_set_eee()
3186 if (!edata->eee_enabled || !edata->tx_lpi_enabled || in fec_enet_set_eee()
3187 !edata->tx_lpi_timer) in fec_enet_set_eee()
3195 return phy_ethtool_set_eee(ndev->phydev, edata); in fec_enet_set_eee()
3203 if (fep->wol_flag & FEC_WOL_HAS_MAGIC_PACKET) { in fec_enet_get_wol()
3204 wol->supported = WAKE_MAGIC; in fec_enet_get_wol()
3205 wol->wolopts = fep->wol_flag & FEC_WOL_FLAG_ENABLE ? WAKE_MAGIC : 0; in fec_enet_get_wol()
3207 wol->supported = wol->wolopts = 0; in fec_enet_get_wol()
3216 if (!(fep->wol_flag & FEC_WOL_HAS_MAGIC_PACKET)) in fec_enet_set_wol()
3217 return -EINVAL; in fec_enet_set_wol()
3219 if (wol->wolopts & ~WAKE_MAGIC) in fec_enet_set_wol()
3220 return -EINVAL; in fec_enet_set_wol()
3222 device_set_wakeup_enable(&ndev->dev, wol->wolopts & WAKE_MAGIC); in fec_enet_set_wol()
3223 if (device_may_wakeup(&ndev->dev)) in fec_enet_set_wol()
3224 fep->wol_flag |= FEC_WOL_FLAG_ENABLE; in fec_enet_set_wol()
3226 fep->wol_flag &= (~FEC_WOL_FLAG_ENABLE); in fec_enet_set_wol()
3266 for (q = 0; q < fep->num_rx_queues; q++) { in fec_enet_free_buffers()
3267 rxq = fep->rx_queue[q]; in fec_enet_free_buffers()
3268 for (i = 0; i < rxq->bd.ring_size; i++) in fec_enet_free_buffers()
3269 page_pool_put_full_page(rxq->page_pool, rxq->rx_skb_info[i].page, false); in fec_enet_free_buffers()
3272 rxq->stats[i] = 0; in fec_enet_free_buffers()
3274 if (xdp_rxq_info_is_reg(&rxq->xdp_rxq)) in fec_enet_free_buffers()
3275 xdp_rxq_info_unreg(&rxq->xdp_rxq); in fec_enet_free_buffers()
3276 page_pool_destroy(rxq->page_pool); in fec_enet_free_buffers()
3277 rxq->page_pool = NULL; in fec_enet_free_buffers()
3280 for (q = 0; q < fep->num_tx_queues; q++) { in fec_enet_free_buffers()
3281 txq = fep->tx_queue[q]; in fec_enet_free_buffers()
3282 for (i = 0; i < txq->bd.ring_size; i++) { in fec_enet_free_buffers()
3283 kfree(txq->tx_bounce[i]); in fec_enet_free_buffers()
3284 txq->tx_bounce[i] = NULL; in fec_enet_free_buffers()
3286 if (!txq->tx_buf[i].buf_p) { in fec_enet_free_buffers()
3287 txq->tx_buf[i].type = FEC_TXBUF_T_SKB; in fec_enet_free_buffers()
3291 if (txq->tx_buf[i].type == FEC_TXBUF_T_SKB) { in fec_enet_free_buffers()
3292 dev_kfree_skb(txq->tx_buf[i].buf_p); in fec_enet_free_buffers()
3293 } else if (txq->tx_buf[i].type == FEC_TXBUF_T_XDP_NDO) { in fec_enet_free_buffers()
3294 xdp_return_frame(txq->tx_buf[i].buf_p); in fec_enet_free_buffers()
3296 struct page *page = txq->tx_buf[i].buf_p; in fec_enet_free_buffers()
3298 page_pool_put_page(page->pp, page, 0, false); in fec_enet_free_buffers()
3301 txq->tx_buf[i].buf_p = NULL; in fec_enet_free_buffers()
3302 txq->tx_buf[i].type = FEC_TXBUF_T_SKB; in fec_enet_free_buffers()
3313 for (i = 0; i < fep->num_tx_queues; i++) in fec_enet_free_queue()
3314 if (fep->tx_queue[i] && fep->tx_queue[i]->tso_hdrs) { in fec_enet_free_queue()
3315 txq = fep->tx_queue[i]; in fec_enet_free_queue()
3316 fec_dma_free(&fep->pdev->dev, in fec_enet_free_queue()
3317 txq->bd.ring_size * TSO_HEADER_SIZE, in fec_enet_free_queue()
3318 txq->tso_hdrs, txq->tso_hdrs_dma); in fec_enet_free_queue()
3321 for (i = 0; i < fep->num_rx_queues; i++) in fec_enet_free_queue()
3322 kfree(fep->rx_queue[i]); in fec_enet_free_queue()
3323 for (i = 0; i < fep->num_tx_queues; i++) in fec_enet_free_queue()
3324 kfree(fep->tx_queue[i]); in fec_enet_free_queue()
3334 for (i = 0; i < fep->num_tx_queues; i++) { in fec_enet_alloc_queue()
3337 ret = -ENOMEM; in fec_enet_alloc_queue()
3341 fep->tx_queue[i] = txq; in fec_enet_alloc_queue()
3342 txq->bd.ring_size = TX_RING_SIZE; in fec_enet_alloc_queue()
3343 fep->total_tx_ring_size += fep->tx_queue[i]->bd.ring_size; in fec_enet_alloc_queue()
3345 txq->tx_stop_threshold = FEC_MAX_SKB_DESCS; in fec_enet_alloc_queue()
3346 txq->tx_wake_threshold = FEC_MAX_SKB_DESCS + 2 * MAX_SKB_FRAGS; in fec_enet_alloc_queue()
3348 txq->tso_hdrs = fec_dma_alloc(&fep->pdev->dev, in fec_enet_alloc_queue()
3349 txq->bd.ring_size * TSO_HEADER_SIZE, in fec_enet_alloc_queue()
3350 &txq->tso_hdrs_dma, GFP_KERNEL); in fec_enet_alloc_queue()
3351 if (!txq->tso_hdrs) { in fec_enet_alloc_queue()
3352 ret = -ENOMEM; in fec_enet_alloc_queue()
3357 for (i = 0; i < fep->num_rx_queues; i++) { in fec_enet_alloc_queue()
3358 fep->rx_queue[i] = kzalloc(sizeof(*fep->rx_queue[i]), in fec_enet_alloc_queue()
3360 if (!fep->rx_queue[i]) { in fec_enet_alloc_queue()
3361 ret = -ENOMEM; in fec_enet_alloc_queue()
3365 fep->rx_queue[i]->bd.ring_size = RX_RING_SIZE; in fec_enet_alloc_queue()
3366 fep->total_rx_ring_size += fep->rx_queue[i]->bd.ring_size; in fec_enet_alloc_queue()
3385 rxq = fep->rx_queue[queue]; in fec_enet_alloc_rxq_buffers()
3386 bdp = rxq->bd.base; in fec_enet_alloc_rxq_buffers()
3388 err = fec_enet_create_page_pool(fep, rxq, rxq->bd.ring_size); in fec_enet_alloc_rxq_buffers()
3394 for (i = 0; i < rxq->bd.ring_size; i++) { in fec_enet_alloc_rxq_buffers()
3395 page = page_pool_dev_alloc_pages(rxq->page_pool); in fec_enet_alloc_rxq_buffers()
3400 bdp->cbd_bufaddr = cpu_to_fec32(phys_addr); in fec_enet_alloc_rxq_buffers()
3402 rxq->rx_skb_info[i].page = page; in fec_enet_alloc_rxq_buffers()
3403 rxq->rx_skb_info[i].offset = FEC_ENET_XDP_HEADROOM; in fec_enet_alloc_rxq_buffers()
3404 bdp->cbd_sc = cpu_to_fec16(BD_ENET_RX_EMPTY); in fec_enet_alloc_rxq_buffers()
3406 if (fep->bufdesc_ex) { in fec_enet_alloc_rxq_buffers()
3408 ebdp->cbd_esc = cpu_to_fec32(BD_ENET_RX_INT); in fec_enet_alloc_rxq_buffers()
3411 bdp = fec_enet_get_nextdesc(bdp, &rxq->bd); in fec_enet_alloc_rxq_buffers()
3415 bdp = fec_enet_get_prevdesc(bdp, &rxq->bd); in fec_enet_alloc_rxq_buffers()
3416 bdp->cbd_sc |= cpu_to_fec16(BD_SC_WRAP); in fec_enet_alloc_rxq_buffers()
3421 return -ENOMEM; in fec_enet_alloc_rxq_buffers()
3432 txq = fep->tx_queue[queue]; in fec_enet_alloc_txq_buffers()
3433 bdp = txq->bd.base; in fec_enet_alloc_txq_buffers()
3434 for (i = 0; i < txq->bd.ring_size; i++) { in fec_enet_alloc_txq_buffers()
3435 txq->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL); in fec_enet_alloc_txq_buffers()
3436 if (!txq->tx_bounce[i]) in fec_enet_alloc_txq_buffers()
3439 bdp->cbd_sc = cpu_to_fec16(0); in fec_enet_alloc_txq_buffers()
3440 bdp->cbd_bufaddr = cpu_to_fec32(0); in fec_enet_alloc_txq_buffers()
3442 if (fep->bufdesc_ex) { in fec_enet_alloc_txq_buffers()
3444 ebdp->cbd_esc = cpu_to_fec32(BD_ENET_TX_INT); in fec_enet_alloc_txq_buffers()
3447 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_alloc_txq_buffers()
3451 bdp = fec_enet_get_prevdesc(bdp, &txq->bd); in fec_enet_alloc_txq_buffers()
3452 bdp->cbd_sc |= cpu_to_fec16(BD_SC_WRAP); in fec_enet_alloc_txq_buffers()
3458 return -ENOMEM; in fec_enet_alloc_txq_buffers()
3466 for (i = 0; i < fep->num_rx_queues; i++) in fec_enet_alloc_buffers()
3468 return -ENOMEM; in fec_enet_alloc_buffers()
3470 for (i = 0; i < fep->num_tx_queues; i++) in fec_enet_alloc_buffers()
3472 return -ENOMEM; in fec_enet_alloc_buffers()
3483 ret = pm_runtime_resume_and_get(&fep->pdev->dev); in fec_enet_open()
3487 pinctrl_pm_select_default_state(&fep->pdev->dev); in fec_enet_open()
3498 if (ndev->phydev && ndev->phydev->drv) in fec_enet_open()
3525 if (fep->quirks & FEC_QUIRK_ERR006687) in fec_enet_open()
3528 if (fep->quirks & FEC_QUIRK_HAS_PMQOS) in fec_enet_open()
3529 cpu_latency_qos_add_request(&fep->pm_qos_req, 0); in fec_enet_open()
3531 napi_enable(&fep->napi); in fec_enet_open()
3532 phy_start(ndev->phydev); in fec_enet_open()
3535 device_set_wakeup_enable(&ndev->dev, fep->wol_flag & in fec_enet_open()
3545 pm_runtime_mark_last_busy(&fep->pdev->dev); in fec_enet_open()
3546 pm_runtime_put_autosuspend(&fep->pdev->dev); in fec_enet_open()
3547 pinctrl_pm_select_sleep_state(&fep->pdev->dev); in fec_enet_open()
3556 phy_stop(ndev->phydev); in fec_enet_close()
3559 napi_disable(&fep->napi); in fec_enet_close()
3564 phy_disconnect(ndev->phydev); in fec_enet_close()
3566 if (fep->quirks & FEC_QUIRK_ERR006687) in fec_enet_close()
3572 if (fep->quirks & FEC_QUIRK_HAS_PMQOS) in fec_enet_close()
3573 cpu_latency_qos_remove_request(&fep->pm_qos_req); in fec_enet_close()
3575 pinctrl_pm_select_sleep_state(&fep->pdev->dev); in fec_enet_close()
3576 pm_runtime_mark_last_busy(&fep->pdev->dev); in fec_enet_close()
3577 pm_runtime_put_autosuspend(&fep->pdev->dev); in fec_enet_close()
3604 if (ndev->flags & IFF_PROMISC) { in set_multicast_list()
3605 tmp = readl(fep->hwp + FEC_R_CNTRL); in set_multicast_list()
3607 writel(tmp, fep->hwp + FEC_R_CNTRL); in set_multicast_list()
3611 tmp = readl(fep->hwp + FEC_R_CNTRL); in set_multicast_list()
3613 writel(tmp, fep->hwp + FEC_R_CNTRL); in set_multicast_list()
3615 if (ndev->flags & IFF_ALLMULTI) { in set_multicast_list()
3619 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); in set_multicast_list()
3620 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW); in set_multicast_list()
3628 crc = ether_crc_le(ndev->addr_len, ha->addr); in set_multicast_list()
3633 hash = (crc >> (32 - FEC_HASH_BITS)) & 0x3f; in set_multicast_list()
3636 hash_high |= 1 << (hash - 32); in set_multicast_list()
3641 writel(hash_high, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); in set_multicast_list()
3642 writel(hash_low, fep->hwp + FEC_GRP_HASH_TABLE_LOW); in set_multicast_list()
3653 if (!is_valid_ether_addr(addr->sa_data)) in fec_set_mac_address()
3654 return -EADDRNOTAVAIL; in fec_set_mac_address()
3655 eth_hw_addr_set(ndev, addr->sa_data); in fec_set_mac_address()
3666 writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) | in fec_set_mac_address()
3667 (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24), in fec_set_mac_address()
3668 fep->hwp + FEC_ADDR_LOW); in fec_set_mac_address()
3669 writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24), in fec_set_mac_address()
3670 fep->hwp + FEC_ADDR_HIGH); in fec_set_mac_address()
3676 * fec_poll_controller - FEC Poll controller function
3688 if (fep->irq[i] > 0) { in fec_poll_controller()
3689 disable_irq(fep->irq[i]); in fec_poll_controller()
3690 fec_enet_interrupt(fep->irq[i], dev); in fec_poll_controller()
3691 enable_irq(fep->irq[i]); in fec_poll_controller()
3701 netdev_features_t changed = features ^ netdev->features; in fec_enet_set_netdev_features()
3703 netdev->features = features; in fec_enet_set_netdev_features()
3708 fep->csum_flags |= FLAG_RX_CSUM_ENABLED; in fec_enet_set_netdev_features()
3710 fep->csum_flags &= ~FLAG_RX_CSUM_ENABLED; in fec_enet_set_netdev_features()
3718 netdev_features_t changed = features ^ netdev->features; in fec_set_features()
3721 napi_disable(&fep->napi); in fec_set_features()
3728 napi_enable(&fep->napi); in fec_set_features()
3742 if (!(fep->quirks & FEC_QUIRK_HAS_AVB)) in fec_enet_select_queue()
3746 if (eth_type_vlan(skb->protocol)) { in fec_enet_select_queue()
3749 vlan_tag = ntohs(vhdr->h_vlan_TCI); in fec_enet_select_queue()
3752 vlan_tag = skb->vlan_tci; in fec_enet_select_queue()
3766 switch (bpf->command) { in fec_enet_bpf()
3772 if (fep->quirks & FEC_QUIRK_SWAP_FRAME) in fec_enet_bpf()
3773 return -EOPNOTSUPP; in fec_enet_bpf()
3775 if (!bpf->prog) in fec_enet_bpf()
3779 napi_disable(&fep->napi); in fec_enet_bpf()
3783 old_prog = xchg(&fep->xdp_prog, bpf->prog); in fec_enet_bpf()
3790 napi_enable(&fep->napi); in fec_enet_bpf()
3794 if (bpf->prog) in fec_enet_bpf()
3800 return -EOPNOTSUPP; in fec_enet_bpf()
3803 return -EOPNOTSUPP; in fec_enet_bpf()
3813 return (index % fep->num_tx_queues); in fec_enet_xdp_get_tx_queue()
3829 netdev_err_once(fep->netdev, "NOT enough BD for SG!\n"); in fec_enet_txq_xmit_frame()
3830 return -EBUSY; in fec_enet_txq_xmit_frame()
3834 bdp = txq->bd.cur; in fec_enet_txq_xmit_frame()
3835 status = fec16_to_cpu(bdp->cbd_sc); in fec_enet_txq_xmit_frame()
3838 index = fec_enet_get_bd_index(bdp, &txq->bd); in fec_enet_txq_xmit_frame()
3843 dma_addr = dma_map_single(&fep->pdev->dev, xdpf->data, in fec_enet_txq_xmit_frame()
3844 xdpf->len, DMA_TO_DEVICE); in fec_enet_txq_xmit_frame()
3845 if (dma_mapping_error(&fep->pdev->dev, dma_addr)) in fec_enet_txq_xmit_frame()
3846 return -ENOMEM; in fec_enet_txq_xmit_frame()
3848 frame_len = xdpf->len; in fec_enet_txq_xmit_frame()
3849 txq->tx_buf[index].buf_p = xdpf; in fec_enet_txq_xmit_frame()
3850 txq->tx_buf[index].type = FEC_TXBUF_T_XDP_NDO; in fec_enet_txq_xmit_frame()
3855 page = virt_to_page(xdpb->data); in fec_enet_txq_xmit_frame()
3857 (xdpb->data - xdpb->data_hard_start); in fec_enet_txq_xmit_frame()
3858 dma_sync_single_for_device(&fep->pdev->dev, dma_addr, in fec_enet_txq_xmit_frame()
3860 frame_len = xdpb->data_end - xdpb->data; in fec_enet_txq_xmit_frame()
3861 txq->tx_buf[index].buf_p = page; in fec_enet_txq_xmit_frame()
3862 txq->tx_buf[index].type = FEC_TXBUF_T_XDP_TX; in fec_enet_txq_xmit_frame()
3866 if (fep->bufdesc_ex) in fec_enet_txq_xmit_frame()
3869 bdp->cbd_bufaddr = cpu_to_fec32(dma_addr); in fec_enet_txq_xmit_frame()
3870 bdp->cbd_datlen = cpu_to_fec16(frame_len); in fec_enet_txq_xmit_frame()
3872 if (fep->bufdesc_ex) { in fec_enet_txq_xmit_frame()
3875 if (fep->quirks & FEC_QUIRK_HAS_AVB) in fec_enet_txq_xmit_frame()
3876 estatus |= FEC_TX_BD_FTYPE(txq->bd.qid); in fec_enet_txq_xmit_frame()
3878 ebdp->cbd_bdu = 0; in fec_enet_txq_xmit_frame()
3879 ebdp->cbd_esc = cpu_to_fec32(estatus); in fec_enet_txq_xmit_frame()
3891 bdp->cbd_sc = cpu_to_fec16(status); in fec_enet_txq_xmit_frame()
3894 bdp = fec_enet_get_nextdesc(bdp, &txq->bd); in fec_enet_txq_xmit_frame()
3896 /* Make sure the update to bdp are performed before txq->bd.cur. */ in fec_enet_txq_xmit_frame()
3899 txq->bd.cur = bdp; in fec_enet_txq_xmit_frame()
3902 writel(0, txq->bd.reg_desc_active); in fec_enet_txq_xmit_frame()
3916 txq = fep->tx_queue[queue]; in fec_enet_xdp_tx_xmit()
3917 nq = netdev_get_tx_queue(fep->netdev, queue); in fec_enet_xdp_tx_xmit()
3944 txq = fep->tx_queue[queue]; in fec_enet_xdp_xmit()
3945 nq = netdev_get_tx_queue(fep->netdev, queue); in fec_enet_xdp_xmit()
3968 return -EINVAL; in fec_hwtstamp_get()
3970 if (!fep->bufdesc_ex) in fec_hwtstamp_get()
3971 return -EOPNOTSUPP; in fec_hwtstamp_get()
3985 return -EINVAL; in fec_hwtstamp_set()
3987 if (!fep->bufdesc_ex) in fec_hwtstamp_set()
3988 return -EOPNOTSUPP; in fec_hwtstamp_set()
4032 unsigned dsize = fep->bufdesc_ex ? sizeof(struct bufdesc_ex) : in fec_enet_init()
4039 fep->rx_align = 0xf; in fec_enet_init()
4040 fep->tx_align = 0xf; in fec_enet_init()
4042 fep->rx_align = 0x3; in fec_enet_init()
4043 fep->tx_align = 0x3; in fec_enet_init()
4045 fep->rx_pkts_itr = FEC_ITR_ICFT_DEFAULT; in fec_enet_init()
4046 fep->tx_pkts_itr = FEC_ITR_ICFT_DEFAULT; in fec_enet_init()
4047 fep->rx_time_itr = FEC_ITR_ICTT_DEFAULT; in fec_enet_init()
4048 fep->tx_time_itr = FEC_ITR_ICTT_DEFAULT; in fec_enet_init()
4051 ret = dma_set_mask_and_coherent(&fep->pdev->dev, DMA_BIT_MASK(32)); in fec_enet_init()
4053 dev_warn(&fep->pdev->dev, "No suitable DMA available\n"); in fec_enet_init()
4061 bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize; in fec_enet_init()
4064 cbd_base = fec_dmam_alloc(&fep->pdev->dev, bd_size, &bd_dma, in fec_enet_init()
4067 ret = -ENOMEM; in fec_enet_init()
4077 for (i = 0; i < fep->num_rx_queues; i++) { in fec_enet_init()
4078 struct fec_enet_priv_rx_q *rxq = fep->rx_queue[i]; in fec_enet_init()
4079 unsigned size = dsize * rxq->bd.ring_size; in fec_enet_init()
4081 rxq->bd.qid = i; in fec_enet_init()
4082 rxq->bd.base = cbd_base; in fec_enet_init()
4083 rxq->bd.cur = cbd_base; in fec_enet_init()
4084 rxq->bd.dma = bd_dma; in fec_enet_init()
4085 rxq->bd.dsize = dsize; in fec_enet_init()
4086 rxq->bd.dsize_log2 = dsize_log2; in fec_enet_init()
4087 rxq->bd.reg_desc_active = fep->hwp + offset_des_active_rxq[i]; in fec_enet_init()
4090 rxq->bd.last = (struct bufdesc *)(((void *)cbd_base) - dsize); in fec_enet_init()
4093 for (i = 0; i < fep->num_tx_queues; i++) { in fec_enet_init()
4094 struct fec_enet_priv_tx_q *txq = fep->tx_queue[i]; in fec_enet_init()
4095 unsigned size = dsize * txq->bd.ring_size; in fec_enet_init()
4097 txq->bd.qid = i; in fec_enet_init()
4098 txq->bd.base = cbd_base; in fec_enet_init()
4099 txq->bd.cur = cbd_base; in fec_enet_init()
4100 txq->bd.dma = bd_dma; in fec_enet_init()
4101 txq->bd.dsize = dsize; in fec_enet_init()
4102 txq->bd.dsize_log2 = dsize_log2; in fec_enet_init()
4103 txq->bd.reg_desc_active = fep->hwp + offset_des_active_txq[i]; in fec_enet_init()
4106 txq->bd.last = (struct bufdesc *)(((void *)cbd_base) - dsize); in fec_enet_init()
4111 ndev->watchdog_timeo = TX_TIMEOUT; in fec_enet_init()
4112 ndev->netdev_ops = &fec_netdev_ops; in fec_enet_init()
4113 ndev->ethtool_ops = &fec_enet_ethtool_ops; in fec_enet_init()
4115 writel(FEC_RX_DISABLED_IMASK, fep->hwp + FEC_IMASK); in fec_enet_init()
4116 netif_napi_add(ndev, &fep->napi, fec_enet_rx_napi); in fec_enet_init()
4118 if (fep->quirks & FEC_QUIRK_HAS_VLAN) in fec_enet_init()
4120 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; in fec_enet_init()
4122 if (fep->quirks & FEC_QUIRK_HAS_CSUM) { in fec_enet_init()
4126 ndev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM in fec_enet_init()
4128 fep->csum_flags |= FLAG_RX_CSUM_ENABLED; in fec_enet_init()
4131 if (fep->quirks & FEC_QUIRK_HAS_MULTI_QUEUES) { in fec_enet_init()
4132 fep->tx_align = 0; in fec_enet_init()
4133 fep->rx_align = 0x3f; in fec_enet_init()
4136 ndev->hw_features = ndev->features; in fec_enet_init()
4138 if (!(fep->quirks & FEC_QUIRK_SWAP_FRAME)) in fec_enet_init()
4139 ndev->xdp_features = NETDEV_XDP_ACT_BASIC | in fec_enet_init()
4144 if (fep->quirks & FEC_QUIRK_MIB_CLEAR) in fec_enet_init()
4161 struct device_node *np = pdev->dev.of_node; in fec_reset_phy()
4167 err = of_property_read_u32(np, "phy-reset-duration", &msec); in fec_reset_phy()
4172 err = of_property_read_u32(np, "phy-reset-post-delay", &phy_post_delay); in fec_reset_phy()
4175 return -EINVAL; in fec_reset_phy()
4177 phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset", in fec_reset_phy()
4180 return dev_err_probe(&pdev->dev, PTR_ERR(phy_reset), in fec_reset_phy()
4181 "failed to get phy-reset-gpios\n"); in fec_reset_phy()
4218 struct device_node *np = pdev->dev.of_node; in fec_enet_get_queue_num()
4226 of_property_read_u32(np, "fsl,num-tx-queues", num_tx); in fec_enet_get_queue_num()
4228 of_property_read_u32(np, "fsl,num-rx-queues", num_rx); in fec_enet_get_queue_num()
4231 dev_warn(&pdev->dev, "Invalid num_tx(=%d), fall back to 1\n", in fec_enet_get_queue_num()
4238 dev_warn(&pdev->dev, "Invalid num_rx(=%d), fall back to 1\n", in fec_enet_get_queue_num()
4264 if (fep->quirks & FEC_QUIRK_WAKEUP_FROM_INT2) in fec_enet_get_wakeup_irq()
4265 fep->wake_irq = fep->irq[2]; in fec_enet_get_wakeup_irq()
4267 fep->wake_irq = fep->irq[0]; in fec_enet_get_wakeup_irq()
4277 gpr_np = of_parse_phandle(np, "fsl,stop-mode", 0); in fec_enet_init_stop_mode()
4281 ret = of_property_read_u32_array(np, "fsl,stop-mode", out_val, in fec_enet_init_stop_mode()
4284 dev_dbg(&fep->pdev->dev, "no stop mode property\n"); in fec_enet_init_stop_mode()
4288 fep->stop_gpr.gpr = syscon_node_to_regmap(gpr_np); in fec_enet_init_stop_mode()
4289 if (IS_ERR(fep->stop_gpr.gpr)) { in fec_enet_init_stop_mode()
4290 dev_err(&fep->pdev->dev, "could not find gpr regmap\n"); in fec_enet_init_stop_mode()
4291 ret = PTR_ERR(fep->stop_gpr.gpr); in fec_enet_init_stop_mode()
4292 fep->stop_gpr.gpr = NULL; in fec_enet_init_stop_mode()
4296 fep->stop_gpr.reg = out_val[1]; in fec_enet_init_stop_mode()
4297 fep->stop_gpr.bit = out_val[2]; in fec_enet_init_stop_mode()
4314 struct device_node *np = pdev->dev.of_node, *phy_node; in fec_probe()
4327 return -ENOMEM; in fec_probe()
4329 SET_NETDEV_DEV(ndev, &pdev->dev); in fec_probe()
4334 dev_info = device_get_match_data(&pdev->dev); in fec_probe()
4336 dev_info = (const struct fec_devinfo *)pdev->id_entry->driver_data; in fec_probe()
4338 fep->quirks = dev_info->quirks; in fec_probe()
4340 fep->netdev = ndev; in fec_probe()
4341 fep->num_rx_queues = num_rx_qs; in fec_probe()
4342 fep->num_tx_queues = num_tx_qs; in fec_probe()
4346 if (fep->quirks & FEC_QUIRK_HAS_GBIT) in fec_probe()
4347 fep->pause_flag |= FEC_PAUSE_FLAG_AUTONEG; in fec_probe()
4351 pinctrl_pm_select_default_state(&pdev->dev); in fec_probe()
4353 fep->hwp = devm_platform_ioremap_resource(pdev, 0); in fec_probe()
4354 if (IS_ERR(fep->hwp)) { in fec_probe()
4355 ret = PTR_ERR(fep->hwp); in fec_probe()
4359 fep->pdev = pdev; in fec_probe()
4360 fep->dev_id = dev_id++; in fec_probe()
4366 !of_property_read_bool(np, "fsl,err006687-workaround-present")) in fec_probe()
4367 fep->quirks |= FEC_QUIRK_ERR006687; in fec_probe()
4373 if (of_property_read_bool(np, "fsl,magic-packet")) in fec_probe()
4374 fep->wol_flag |= FEC_WOL_HAS_MAGIC_PACKET; in fec_probe()
4380 phy_node = of_parse_phandle(np, "phy-handle", 0); in fec_probe()
4384 dev_err(&pdev->dev, in fec_probe()
4385 "broken fixed-link specification\n"); in fec_probe()
4390 fep->phy_node = phy_node; in fec_probe()
4392 ret = of_get_phy_mode(pdev->dev.of_node, &interface); in fec_probe()
4394 pdata = dev_get_platdata(&pdev->dev); in fec_probe()
4396 fep->phy_interface = pdata->phy; in fec_probe()
4398 fep->phy_interface = PHY_INTERFACE_MODE_MII; in fec_probe()
4400 fep->phy_interface = interface; in fec_probe()
4407 fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in fec_probe()
4408 if (IS_ERR(fep->clk_ipg)) { in fec_probe()
4409 ret = PTR_ERR(fep->clk_ipg); in fec_probe()
4413 fep->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); in fec_probe()
4414 if (IS_ERR(fep->clk_ahb)) { in fec_probe()
4415 ret = PTR_ERR(fep->clk_ahb); in fec_probe()
4419 fep->itr_clk_rate = clk_get_rate(fep->clk_ahb); in fec_probe()
4422 fep->clk_enet_out = devm_clk_get_optional(&pdev->dev, "enet_out"); in fec_probe()
4423 if (IS_ERR(fep->clk_enet_out)) { in fec_probe()
4424 ret = PTR_ERR(fep->clk_enet_out); in fec_probe()
4428 fep->ptp_clk_on = false; in fec_probe()
4429 mutex_init(&fep->ptp_clk_mutex); in fec_probe()
4432 fep->clk_ref = devm_clk_get_optional(&pdev->dev, "enet_clk_ref"); in fec_probe()
4433 if (IS_ERR(fep->clk_ref)) { in fec_probe()
4434 ret = PTR_ERR(fep->clk_ref); in fec_probe()
4437 fep->clk_ref_rate = clk_get_rate(fep->clk_ref); in fec_probe()
4440 if (fep->rgmii_txc_dly || fep->rgmii_rxc_dly) { in fec_probe()
4441 fep->clk_2x_txclk = devm_clk_get(&pdev->dev, "enet_2x_txclk"); in fec_probe()
4442 if (IS_ERR(fep->clk_2x_txclk)) in fec_probe()
4443 fep->clk_2x_txclk = NULL; in fec_probe()
4446 fep->bufdesc_ex = fep->quirks & FEC_QUIRK_HAS_BUFDESC_EX; in fec_probe()
4447 fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp"); in fec_probe()
4448 if (IS_ERR(fep->clk_ptp)) { in fec_probe()
4449 fep->clk_ptp = NULL; in fec_probe()
4450 fep->bufdesc_ex = false; in fec_probe()
4457 ret = clk_prepare_enable(fep->clk_ipg); in fec_probe()
4460 ret = clk_prepare_enable(fep->clk_ahb); in fec_probe()
4464 fep->reg_phy = devm_regulator_get_optional(&pdev->dev, "phy"); in fec_probe()
4465 if (!IS_ERR(fep->reg_phy)) { in fec_probe()
4466 ret = regulator_enable(fep->reg_phy); in fec_probe()
4468 dev_err(&pdev->dev, in fec_probe()
4473 if (PTR_ERR(fep->reg_phy) == -EPROBE_DEFER) { in fec_probe()
4474 ret = -EPROBE_DEFER; in fec_probe()
4477 fep->reg_phy = NULL; in fec_probe()
4480 pm_runtime_set_autosuspend_delay(&pdev->dev, FEC_MDIO_PM_TIMEOUT); in fec_probe()
4481 pm_runtime_use_autosuspend(&pdev->dev); in fec_probe()
4482 pm_runtime_get_noresume(&pdev->dev); in fec_probe()
4483 pm_runtime_set_active(&pdev->dev); in fec_probe()
4484 pm_runtime_enable(&pdev->dev); in fec_probe()
4491 if (fep->bufdesc_ex) in fec_probe()
4507 ret = devm_request_irq(&pdev->dev, irq, fec_enet_interrupt, in fec_probe()
4508 0, pdev->name, ndev); in fec_probe()
4512 fep->irq[i] = irq; in fec_probe()
4525 pinctrl_pm_select_sleep_state(&pdev->dev); in fec_probe()
4527 ndev->max_mtu = PKT_MAXBUF_SIZE - ETH_HLEN - ETH_FCS_LEN; in fec_probe()
4533 device_init_wakeup(&ndev->dev, fep->wol_flag & in fec_probe()
4536 if (fep->bufdesc_ex && fep->ptp_clock) in fec_probe()
4537 netdev_info(ndev, "registered PHC device %d\n", fep->dev_id); in fec_probe()
4539 INIT_WORK(&fep->tx_timeout_work, fec_enet_timeout_work); in fec_probe()
4541 pm_runtime_mark_last_busy(&pdev->dev); in fec_probe()
4542 pm_runtime_put_autosuspend(&pdev->dev); in fec_probe()
4553 pm_runtime_put_noidle(&pdev->dev); in fec_probe()
4554 pm_runtime_disable(&pdev->dev); in fec_probe()
4555 if (fep->reg_phy) in fec_probe()
4556 regulator_disable(fep->reg_phy); in fec_probe()
4558 clk_disable_unprepare(fep->clk_ahb); in fec_probe()
4560 clk_disable_unprepare(fep->clk_ipg); in fec_probe()
4571 dev_id--; in fec_probe()
4583 struct device_node *np = pdev->dev.of_node; in fec_drv_remove()
4586 ret = pm_runtime_get_sync(&pdev->dev); in fec_drv_remove()
4588 dev_err(&pdev->dev, in fec_drv_remove()
4592 cancel_work_sync(&fep->tx_timeout_work); in fec_drv_remove()
4596 if (fep->reg_phy) in fec_drv_remove()
4597 regulator_disable(fep->reg_phy); in fec_drv_remove()
4601 of_node_put(fep->phy_node); in fec_drv_remove()
4607 clk_disable_unprepare(fep->clk_ahb); in fec_drv_remove()
4608 clk_disable_unprepare(fep->clk_ipg); in fec_drv_remove()
4610 pm_runtime_put_noidle(&pdev->dev); in fec_drv_remove()
4611 pm_runtime_disable(&pdev->dev); in fec_drv_remove()
4624 if (fep->wol_flag & FEC_WOL_FLAG_ENABLE) in fec_suspend()
4625 fep->wol_flag |= FEC_WOL_FLAG_SLEEP_ON; in fec_suspend()
4626 phy_stop(ndev->phydev); in fec_suspend()
4627 napi_disable(&fep->napi); in fec_suspend()
4632 if (!(fep->wol_flag & FEC_WOL_FLAG_ENABLE)) { in fec_suspend()
4634 pinctrl_pm_select_sleep_state(&fep->pdev->dev); in fec_suspend()
4637 if (fep->wake_irq > 0) { in fec_suspend()
4638 disable_irq(fep->wake_irq); in fec_suspend()
4639 enable_irq_wake(fep->wake_irq); in fec_suspend()
4646 fep->rpm_active = !pm_runtime_status_suspended(dev); in fec_suspend()
4647 if (fep->rpm_active) { in fec_suspend()
4657 if (fep->reg_phy && !(fep->wol_flag & FEC_WOL_FLAG_ENABLE)) in fec_suspend()
4658 regulator_disable(fep->reg_phy); in fec_suspend()
4663 if (fep->clk_enet_out || fep->reg_phy) in fec_suspend()
4664 fep->link = 0; in fec_suspend()
4676 if (fep->reg_phy && !(fep->wol_flag & FEC_WOL_FLAG_ENABLE)) { in fec_resume()
4677 ret = regulator_enable(fep->reg_phy); in fec_resume()
4684 if (fep->rpm_active) in fec_resume()
4692 if (fep->wol_flag & FEC_WOL_FLAG_ENABLE) { in fec_resume()
4694 if (fep->wake_irq) { in fec_resume()
4695 disable_irq_wake(fep->wake_irq); in fec_resume()
4696 enable_irq(fep->wake_irq); in fec_resume()
4699 val = readl(fep->hwp + FEC_ECNTRL); in fec_resume()
4701 writel(val, fep->hwp + FEC_ECNTRL); in fec_resume()
4702 fep->wol_flag &= ~FEC_WOL_FLAG_SLEEP_ON; in fec_resume()
4704 pinctrl_pm_select_default_state(&fep->pdev->dev); in fec_resume()
4710 napi_enable(&fep->napi); in fec_resume()
4711 phy_init_hw(ndev->phydev); in fec_resume()
4712 phy_start(ndev->phydev); in fec_resume()
4719 if (fep->reg_phy) in fec_resume()
4720 regulator_disable(fep->reg_phy); in fec_resume()
4729 clk_disable_unprepare(fep->clk_ahb); in fec_runtime_suspend()
4730 clk_disable_unprepare(fep->clk_ipg); in fec_runtime_suspend()
4741 ret = clk_prepare_enable(fep->clk_ahb); in fec_runtime_resume()
4744 ret = clk_prepare_enable(fep->clk_ipg); in fec_runtime_resume()
4751 clk_disable_unprepare(fep->clk_ahb); in fec_runtime_resume()