4545#include <linux/seq_file.h>
4646#endif /* CONFIG_DEBUG_FS */
4747#include <linux/net_tstamp.h>
48+ #include <linux/phylink.h>
4849#include <net/pkt_cls.h>
4950#include "stmmac_ptp.h"
5051#include "stmmac.h"
@@ -848,6 +849,39 @@ static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex)
848849 priv -> pause , tx_cnt );
849850}
850851
852+ static void stmmac_validate (struct phylink_config * config ,
853+ unsigned long * supported ,
854+ struct phylink_link_state * state )
855+ {
856+ struct stmmac_priv * priv = netdev_priv (to_net_dev (config -> dev ));
857+ __ETHTOOL_DECLARE_LINK_MODE_MASK (mask ) = { 0 , };
858+ int tx_cnt = priv -> plat -> tx_queues_to_use ;
859+ int max_speed = priv -> plat -> max_speed ;
860+
861+ /* Cut down 1G if asked to */
862+ if ((max_speed > 0 ) && (max_speed < 1000 )) {
863+ phylink_set (mask , 1000b aseT_Full );
864+ phylink_set (mask , 1000b aseX_Full );
865+ }
866+
867+ /* Half-Duplex can only work with single queue */
868+ if (tx_cnt > 1 ) {
869+ phylink_set (mask , 10b aseT_Half );
870+ phylink_set (mask , 100b aseT_Half );
871+ phylink_set (mask , 1000b aseT_Half );
872+ }
873+
874+ bitmap_andnot (supported , supported , mask , __ETHTOOL_LINK_MODE_MASK_NBITS );
875+ bitmap_andnot (state -> advertising , state -> advertising , mask ,
876+ __ETHTOOL_LINK_MODE_MASK_NBITS );
877+ }
878+
879+ static int stmmac_mac_link_state (struct phylink_config * config ,
880+ struct phylink_link_state * state )
881+ {
882+ return - EOPNOTSUPP ;
883+ }
884+
851885static void stmmac_mac_config (struct net_device * dev )
852886{
853887 struct stmmac_priv * priv = netdev_priv (dev );
@@ -900,6 +934,11 @@ static void stmmac_mac_config(struct net_device *dev)
900934 writel (ctrl , priv -> ioaddr + MAC_CTRL_REG );
901935}
902936
937+ static void stmmac_mac_an_restart (struct phylink_config * config )
938+ {
939+ /* Not Supported */
940+ }
941+
903942static void stmmac_mac_link_down (struct net_device * dev , bool autoneg )
904943{
905944 struct stmmac_priv * priv = netdev_priv (dev );
@@ -914,6 +953,15 @@ static void stmmac_mac_link_up(struct net_device *dev, bool autoneg)
914953 stmmac_mac_set (priv , priv -> ioaddr , true);
915954}
916955
956+ static const struct phylink_mac_ops __maybe_unused stmmac_phylink_mac_ops = {
957+ .validate = stmmac_validate ,
958+ .mac_link_state = stmmac_mac_link_state ,
959+ .mac_config = NULL , /* TO BE FILLED */
960+ .mac_an_restart = stmmac_mac_an_restart ,
961+ .mac_link_down = NULL , /* TO BE FILLED */
962+ .mac_link_up = NULL , /* TO BE FILLED */
963+ };
964+
917965/**
918966 * stmmac_adjust_link - adjusts the link parameters
919967 * @dev: net device structure
0 commit comments