@@ -503,7 +503,7 @@ static void mtk_gmac0_rgmii_adjust(struct mtk_eth *eth,
503
503
static void mtk_setup_bridge_switch (struct mtk_eth * eth )
504
504
{
505
505
/* Force Port1 XGMAC Link Up */
506
- mtk_m32 (eth , 0 , MTK_XGMAC_FORCE_LINK (MTK_GMAC1_ID ),
506
+ mtk_m32 (eth , 0 , MTK_XGMAC_FORCE_MODE (MTK_GMAC1_ID ),
507
507
MTK_XGMAC_STS (MTK_GMAC1_ID ));
508
508
509
509
/* Adjust GSW bridge IPG to 11 */
@@ -532,6 +532,26 @@ static struct phylink_pcs *mtk_mac_select_pcs(struct phylink_config *config,
532
532
return NULL ;
533
533
}
534
534
535
+ static int mtk_mac_prepare (struct phylink_config * config , unsigned int mode ,
536
+ phy_interface_t iface )
537
+ {
538
+ struct mtk_mac * mac = container_of (config , struct mtk_mac ,
539
+ phylink_config );
540
+ struct mtk_eth * eth = mac -> hw ;
541
+
542
+ if (mtk_interface_mode_is_xgmii (eth , iface ) &&
543
+ mac -> id != MTK_GMAC1_ID ) {
544
+ mtk_m32 (mac -> hw , XMAC_MCR_TRX_DISABLE ,
545
+ XMAC_MCR_TRX_DISABLE , MTK_XMAC_MCR (mac -> id ));
546
+
547
+ mtk_m32 (mac -> hw , MTK_XGMAC_FORCE_MODE (mac -> id ) |
548
+ MTK_XGMAC_FORCE_LINK (mac -> id ),
549
+ MTK_XGMAC_FORCE_MODE (mac -> id ), MTK_XGMAC_STS (mac -> id ));
550
+ }
551
+
552
+ return 0 ;
553
+ }
554
+
535
555
static void mtk_mac_config (struct phylink_config * config , unsigned int mode ,
536
556
const struct phylink_link_state * state )
537
557
{
@@ -573,6 +593,12 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
573
593
}
574
594
break ;
575
595
case PHY_INTERFACE_MODE_INTERNAL :
596
+ if (mac -> id == MTK_GMAC2_ID &&
597
+ MTK_HAS_CAPS (eth -> soc -> caps , MTK_2P5GPHY )) {
598
+ err = mtk_gmac_2p5gphy_path_setup (eth , mac -> id );
599
+ if (err )
600
+ goto init_err ;
601
+ }
576
602
break ;
577
603
default :
578
604
goto err_phy ;
@@ -644,12 +670,12 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
644
670
}
645
671
646
672
/* Setup gmac */
647
- if (mtk_is_netsys_v3_or_greater (eth ) &&
648
- mac -> interface == PHY_INTERFACE_MODE_INTERNAL ) {
673
+ if (mtk_interface_mode_is_xgmii (eth , state -> interface )) {
649
674
mtk_w32 (mac -> hw , MTK_GDMA_XGDM_SEL , MTK_GDMA_EG_CTRL (mac -> id ));
650
675
mtk_w32 (mac -> hw , MAC_MCR_FORCE_LINK_DOWN , MTK_MAC_MCR (mac -> id ));
651
676
652
- mtk_setup_bridge_switch (eth );
677
+ if (mac -> id == MTK_GMAC1_ID )
678
+ mtk_setup_bridge_switch (eth );
653
679
}
654
680
655
681
return ;
@@ -696,10 +722,19 @@ static void mtk_mac_link_down(struct phylink_config *config, unsigned int mode,
696
722
{
697
723
struct mtk_mac * mac = container_of (config , struct mtk_mac ,
698
724
phylink_config );
699
- u32 mcr = mtk_r32 (mac -> hw , MTK_MAC_MCR (mac -> id ));
700
725
701
- mcr &= ~(MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK );
702
- mtk_w32 (mac -> hw , mcr , MTK_MAC_MCR (mac -> id ));
726
+ if (!mtk_interface_mode_is_xgmii (mac -> hw , interface )) {
727
+ /* GMAC modes */
728
+ mtk_m32 (mac -> hw ,
729
+ MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK , 0 ,
730
+ MTK_MAC_MCR (mac -> id ));
731
+ } else if (mac -> id != MTK_GMAC1_ID ) {
732
+ /* XGMAC except for built-in switch */
733
+ mtk_m32 (mac -> hw , XMAC_MCR_TRX_DISABLE , XMAC_MCR_TRX_DISABLE ,
734
+ MTK_XMAC_MCR (mac -> id ));
735
+ mtk_m32 (mac -> hw , MTK_XGMAC_FORCE_LINK (mac -> id ), 0 ,
736
+ MTK_XGMAC_STS (mac -> id ));
737
+ }
703
738
}
704
739
705
740
static void mtk_set_queue_speed (struct mtk_eth * eth , unsigned int idx ,
@@ -771,13 +806,12 @@ static void mtk_set_queue_speed(struct mtk_eth *eth, unsigned int idx,
771
806
mtk_w32 (eth , val , soc -> reg_map -> qdma .qtx_sch + ofs );
772
807
}
773
808
774
- static void mtk_mac_link_up (struct phylink_config * config ,
775
- struct phy_device * phy ,
776
- unsigned int mode , phy_interface_t interface ,
777
- int speed , int duplex , bool tx_pause , bool rx_pause )
809
+ static void mtk_gdm_mac_link_up (struct mtk_mac * mac ,
810
+ struct phy_device * phy ,
811
+ unsigned int mode , phy_interface_t interface ,
812
+ int speed , int duplex , bool tx_pause ,
813
+ bool rx_pause )
778
814
{
779
- struct mtk_mac * mac = container_of (config , struct mtk_mac ,
780
- phylink_config );
781
815
u32 mcr ;
782
816
783
817
mcr = mtk_r32 (mac -> hw , MTK_MAC_MCR (mac -> id ));
@@ -811,6 +845,56 @@ static void mtk_mac_link_up(struct phylink_config *config,
811
845
mtk_w32 (mac -> hw , mcr , MTK_MAC_MCR (mac -> id ));
812
846
}
813
847
848
+ static void mtk_xgdm_mac_link_up (struct mtk_mac * mac ,
849
+ struct phy_device * phy ,
850
+ unsigned int mode , phy_interface_t interface ,
851
+ int speed , int duplex , bool tx_pause ,
852
+ bool rx_pause )
853
+ {
854
+ u32 mcr ;
855
+
856
+ if (mac -> id == MTK_GMAC1_ID )
857
+ return ;
858
+
859
+ /* Eliminate the interference(before link-up) caused by PHY noise */
860
+ mtk_m32 (mac -> hw , XMAC_LOGIC_RST , 0 , MTK_XMAC_LOGIC_RST (mac -> id ));
861
+ mdelay (20 );
862
+ mtk_m32 (mac -> hw , XMAC_GLB_CNTCLR , XMAC_GLB_CNTCLR ,
863
+ MTK_XMAC_CNT_CTRL (mac -> id ));
864
+
865
+ mtk_m32 (mac -> hw , MTK_XGMAC_FORCE_LINK (mac -> id ),
866
+ MTK_XGMAC_FORCE_LINK (mac -> id ), MTK_XGMAC_STS (mac -> id ));
867
+
868
+ mcr = mtk_r32 (mac -> hw , MTK_XMAC_MCR (mac -> id ));
869
+ mcr &= ~(XMAC_MCR_FORCE_TX_FC | XMAC_MCR_FORCE_RX_FC |
870
+ XMAC_MCR_TRX_DISABLE );
871
+ /* Configure pause modes -
872
+ * phylink will avoid these for half duplex
873
+ */
874
+ if (tx_pause )
875
+ mcr |= XMAC_MCR_FORCE_TX_FC ;
876
+ if (rx_pause )
877
+ mcr |= XMAC_MCR_FORCE_RX_FC ;
878
+
879
+ mtk_w32 (mac -> hw , mcr , MTK_XMAC_MCR (mac -> id ));
880
+ }
881
+
882
+ static void mtk_mac_link_up (struct phylink_config * config ,
883
+ struct phy_device * phy ,
884
+ unsigned int mode , phy_interface_t interface ,
885
+ int speed , int duplex , bool tx_pause , bool rx_pause )
886
+ {
887
+ struct mtk_mac * mac = container_of (config , struct mtk_mac ,
888
+ phylink_config );
889
+
890
+ if (mtk_interface_mode_is_xgmii (mac -> hw , interface ))
891
+ mtk_xgdm_mac_link_up (mac , phy , mode , interface , speed , duplex ,
892
+ tx_pause , rx_pause );
893
+ else
894
+ mtk_gdm_mac_link_up (mac , phy , mode , interface , speed , duplex ,
895
+ tx_pause , rx_pause );
896
+ }
897
+
814
898
static void mtk_mac_disable_tx_lpi (struct phylink_config * config )
815
899
{
816
900
struct mtk_mac * mac = container_of (config , struct mtk_mac ,
@@ -828,6 +912,9 @@ static int mtk_mac_enable_tx_lpi(struct phylink_config *config, u32 timer,
828
912
struct mtk_eth * eth = mac -> hw ;
829
913
u32 val ;
830
914
915
+ if (mtk_interface_mode_is_xgmii (eth , mac -> interface ))
916
+ return - EOPNOTSUPP ;
917
+
831
918
/* Tx idle timer in ms */
832
919
timer = DIV_ROUND_UP (timer , 1000 );
833
920
@@ -858,6 +945,7 @@ static int mtk_mac_enable_tx_lpi(struct phylink_config *config, u32 timer,
858
945
}
859
946
860
947
static const struct phylink_mac_ops mtk_phylink_ops = {
948
+ .mac_prepare = mtk_mac_prepare ,
861
949
.mac_select_pcs = mtk_mac_select_pcs ,
862
950
.mac_config = mtk_mac_config ,
863
951
.mac_finish = mtk_mac_finish ,
@@ -4763,6 +4851,11 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
4763
4851
4764
4852
mac -> phylink = phylink ;
4765
4853
4854
+ if (MTK_HAS_CAPS (mac -> hw -> soc -> caps , MTK_2P5GPHY ) &&
4855
+ id == MTK_GMAC2_ID )
4856
+ __set_bit (PHY_INTERFACE_MODE_INTERNAL ,
4857
+ mac -> phylink_config .supported_interfaces );
4858
+
4766
4859
SET_NETDEV_DEV (eth -> netdev [id ], eth -> dev );
4767
4860
eth -> netdev [id ]-> watchdog_timeo = 5 * HZ ;
4768
4861
eth -> netdev [id ]-> netdev_ops = & mtk_netdev_ops ;
0 commit comments