100100/* VR MII EEE Control 1 defines */
101101#define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */
102102
103+ #define phylink_pcs_to_xpcs (pl_pcs ) \
104+ container_of((pl_pcs), struct mdio_xpcs_args, pcs)
105+
103106static const int xpcs_usxgmii_features [] = {
104107 ETHTOOL_LINK_MODE_Pause_BIT ,
105108 ETHTOOL_LINK_MODE_Asym_Pause_BIT ,
@@ -413,7 +416,7 @@ static int xpcs_get_max_usxgmii_speed(const unsigned long *supported)
413416 return max ;
414417}
415418
416- static int xpcs_config_usxgmii (struct mdio_xpcs_args * xpcs , int speed )
419+ static void xpcs_config_usxgmii (struct mdio_xpcs_args * xpcs , int speed )
417420{
418421 int ret , speed_sel ;
419422
@@ -438,33 +441,40 @@ static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed)
438441 break ;
439442 default :
440443 /* Nothing to do here */
441- return - EINVAL ;
444+ return ;
442445 }
443446
444447 ret = xpcs_read_vpcs (xpcs , MDIO_CTRL1 );
445448 if (ret < 0 )
446- return ret ;
449+ goto out ;
447450
448451 ret = xpcs_write_vpcs (xpcs , MDIO_CTRL1 , ret | DW_USXGMII_EN );
449452 if (ret < 0 )
450- return ret ;
453+ goto out ;
451454
452455 ret = xpcs_read (xpcs , MDIO_MMD_VEND2 , MDIO_CTRL1 );
453456 if (ret < 0 )
454- return ret ;
457+ goto out ;
455458
456459 ret &= ~DW_USXGMII_SS_MASK ;
457460 ret |= speed_sel | DW_USXGMII_FULL ;
458461
459462 ret = xpcs_write (xpcs , MDIO_MMD_VEND2 , MDIO_CTRL1 , ret );
460463 if (ret < 0 )
461- return ret ;
464+ goto out ;
462465
463466 ret = xpcs_read_vpcs (xpcs , MDIO_CTRL1 );
464467 if (ret < 0 )
465- return ret ;
468+ goto out ;
469+
470+ ret = xpcs_write_vpcs (xpcs , MDIO_CTRL1 , ret | DW_USXGMII_RST );
471+ if (ret < 0 )
472+ goto out ;
473+
474+ return ;
466475
467- return xpcs_write_vpcs (xpcs , MDIO_CTRL1 , ret | DW_USXGMII_RST );
476+ out :
477+ pr_err ("%s: XPCS access returned %pe\n" , __func__ , ERR_PTR (ret ));
468478}
469479
470480static int _xpcs_config_aneg_c73 (struct mdio_xpcs_args * xpcs ,
@@ -794,19 +804,19 @@ static int xpcs_config_aneg_c37_sgmii(struct mdio_xpcs_args *xpcs)
794804 return xpcs_write (xpcs , MDIO_MMD_VEND2 , DW_VR_MII_DIG_CTRL1 , ret );
795805}
796806
797- static int xpcs_config (struct mdio_xpcs_args * xpcs ,
798- const struct phylink_link_state * state )
807+ static int xpcs_do_config (struct mdio_xpcs_args * xpcs ,
808+ phy_interface_t interface , unsigned int mode )
799809{
800810 const struct xpcs_compat * compat ;
801811 int ret ;
802812
803- compat = xpcs_find_compat (xpcs -> id , state -> interface );
813+ compat = xpcs_find_compat (xpcs -> id , interface );
804814 if (!compat )
805815 return - ENODEV ;
806816
807817 switch (compat -> an_mode ) {
808818 case DW_AN_C73 :
809- if (state -> an_enabled ) {
819+ if (phylink_autoneg_inband ( mode ) ) {
810820 ret = xpcs_config_aneg_c73 (xpcs , compat );
811821 if (ret )
812822 return ret ;
@@ -824,6 +834,16 @@ static int xpcs_config(struct mdio_xpcs_args *xpcs,
824834 return 0 ;
825835}
826836
837+ static int xpcs_config (struct phylink_pcs * pcs , unsigned int mode ,
838+ phy_interface_t interface ,
839+ const unsigned long * advertising ,
840+ bool permit_pause_to_mac )
841+ {
842+ struct mdio_xpcs_args * xpcs = phylink_pcs_to_xpcs (pcs );
843+
844+ return xpcs_do_config (xpcs , interface , mode );
845+ }
846+
827847static int xpcs_get_state_c73 (struct mdio_xpcs_args * xpcs ,
828848 struct phylink_link_state * state ,
829849 const struct xpcs_compat * compat )
@@ -842,7 +862,7 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs,
842862
843863 state -> link = 0 ;
844864
845- return xpcs_config (xpcs , state );
865+ return xpcs_do_config (xpcs , state -> interface , MLO_AN_INBAND );
846866 }
847867
848868 if (state -> an_enabled && xpcs_aneg_done_c73 (xpcs , state , compat )) {
@@ -899,41 +919,45 @@ static int xpcs_get_state_c37_sgmii(struct mdio_xpcs_args *xpcs,
899919 return 0 ;
900920}
901921
902- static int xpcs_get_state (struct mdio_xpcs_args * xpcs ,
903- struct phylink_link_state * state )
922+ static void xpcs_get_state (struct phylink_pcs * pcs ,
923+ struct phylink_link_state * state )
904924{
925+ struct mdio_xpcs_args * xpcs = phylink_pcs_to_xpcs (pcs );
905926 const struct xpcs_compat * compat ;
906927 int ret ;
907928
908929 compat = xpcs_find_compat (xpcs -> id , state -> interface );
909930 if (!compat )
910- return - ENODEV ;
931+ return ;
911932
912933 switch (compat -> an_mode ) {
913934 case DW_AN_C73 :
914935 ret = xpcs_get_state_c73 (xpcs , state , compat );
915- if (ret )
916- return ret ;
936+ if (ret ) {
937+ pr_err ("xpcs_get_state_c73 returned %pe\n" ,
938+ ERR_PTR (ret ));
939+ return ;
940+ }
917941 break ;
918942 case DW_AN_C37_SGMII :
919943 ret = xpcs_get_state_c37_sgmii (xpcs , state );
920- if (ret )
921- return ret ;
944+ if (ret ) {
945+ pr_err ("xpcs_get_state_c37_sgmii returned %pe\n" ,
946+ ERR_PTR (ret ));
947+ }
922948 break ;
923949 default :
924- return -1 ;
950+ return ;
925951 }
926-
927- return 0 ;
928952}
929953
930- static int xpcs_link_up (struct mdio_xpcs_args * xpcs , int speed ,
931- phy_interface_t interface )
954+ static void xpcs_link_up (struct phylink_pcs * pcs , unsigned int mode ,
955+ phy_interface_t interface , int speed , int duplex )
932956{
957+ struct mdio_xpcs_args * xpcs = phylink_pcs_to_xpcs (pcs );
958+
933959 if (interface == PHY_INTERFACE_MODE_USXGMII )
934960 return xpcs_config_usxgmii (xpcs , speed );
935-
936- return 0 ;
937961}
938962
939963static u32 xpcs_get_id (struct mdio_xpcs_args * xpcs )
@@ -1009,6 +1033,12 @@ static const struct xpcs_id xpcs_id_list[] = {
10091033 },
10101034};
10111035
1036+ static const struct phylink_pcs_ops xpcs_phylink_ops = {
1037+ .pcs_config = xpcs_config ,
1038+ .pcs_get_state = xpcs_get_state ,
1039+ .pcs_link_up = xpcs_link_up ,
1040+ };
1041+
10121042struct mdio_xpcs_args * xpcs_create (struct mdio_device * mdiodev ,
10131043 phy_interface_t interface )
10141044{
@@ -1039,6 +1069,9 @@ struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev,
10391069 goto out ;
10401070 }
10411071
1072+ xpcs -> pcs .ops = & xpcs_phylink_ops ;
1073+ xpcs -> pcs .poll = true;
1074+
10421075 ret = xpcs_soft_reset (xpcs , compat );
10431076 if (ret )
10441077 goto out ;
@@ -1061,16 +1094,4 @@ void xpcs_destroy(struct mdio_xpcs_args *xpcs)
10611094}
10621095EXPORT_SYMBOL_GPL (xpcs_destroy );
10631096
1064- static struct mdio_xpcs_ops xpcs_ops = {
1065- .config = xpcs_config ,
1066- .get_state = xpcs_get_state ,
1067- .link_up = xpcs_link_up ,
1068- };
1069-
1070- struct mdio_xpcs_ops * mdio_xpcs_get_ops (void )
1071- {
1072- return & xpcs_ops ;
1073- }
1074- EXPORT_SYMBOL_GPL (mdio_xpcs_get_ops );
1075-
10761097MODULE_LICENSE ("GPL v2" );
0 commit comments