Skip to content

Commit eeef2f6

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Start adding phylink support
Start adding the phylink callbacks. Signed-off-by: Jose Abreu <joabreu@synopsys.com> Cc: Joao Pinto <jpinto@synopsys.com> Cc: David S. Miller <davem@davemloft.net> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com> Cc: Alexandre Torgue <alexandre.torgue@st.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9ad372f commit eeef2f6

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

drivers/net/ethernet/stmicro/stmmac/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config STMMAC_ETH
44
depends on HAS_IOMEM && HAS_DMA
55
select MII
66
select PHYLIB
7+
select PHYLINK
78
select CRC32
89
imply PTP_1588_CLOCK
910
select RESET_CONTROLLER

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/clk.h>
2626
#include <linux/stmmac.h>
2727
#include <linux/phy.h>
28+
#include <linux/phylink.h>
2829
#include <linux/pci.h>
2930
#include "common.h"
3031
#include <linux/ptp_clock_kernel.h>
@@ -155,6 +156,9 @@ struct stmmac_priv {
155156
struct mii_bus *mii;
156157
int mii_irq[PHY_MAX_ADDR];
157158

159+
struct phylink_config phylink_config;
160+
struct phylink *phylink;
161+
158162
struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
159163
struct stmmac_safety_stats sstats;
160164
struct plat_stmmacenet_data *plat;

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
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, 1000baseT_Full);
864+
phylink_set(mask, 1000baseX_Full);
865+
}
866+
867+
/* Half-Duplex can only work with single queue */
868+
if (tx_cnt > 1) {
869+
phylink_set(mask, 10baseT_Half);
870+
phylink_set(mask, 100baseT_Half);
871+
phylink_set(mask, 1000baseT_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+
851885
static 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+
903942
static 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

Comments
 (0)