From: Leonardo Costa phylink manages SFP ports in in-band mode and takes the MAC side link state from the PCS, so without one a 10GBASE-R port connected to an SFP+ cage never comes up. Add a phylink PCS for the 10GBASE-R PCS (PCSR) of the port, reporting link up when the PCSR receive status has block lock and no high BER. The PCSR has no interrupt, so the link state is polled. Signed-off-by: Leonardo Costa --- Running sashiko locally, it pointed out that the AM65_CPSW_XGMII_PCSR_RX_STATUS_REG register read in am65_cpsw_pcsr_get_state() may need to be done twice if the RX_BLOCK_LOCK and RX_HI_BER bits are latched. Checking the CPSW PCSR registers on the J784S4 TRM register map, these bits are not latched. They are marked with "R" in the "Access" column, while a latched bit would be marked with "R/WC", such as TX_FAULT for example, which requires a write to clear. A single readl is enough for this case. --- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 64 ++++++++++++++++++++++++++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.h | 2 + 2 files changed, 66 insertions(+) diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index f04ed95ba2ca8..c49e3db7f5852 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -45,6 +45,7 @@ #define AM65_CPSW_SS_BASE 0x0 #define AM65_CPSW_SGMII_BASE 0x100 #define AM65_CPSW_XGMII_BASE 0x2100 +#define AM65_CPSW_XGMII_PORT_OFFSET 0x100 #define AM65_CPSW_CPSW_NU_BASE 0x20000 #define AM65_CPSW_NU_PORTS_BASE 0x1000 #define AM65_CPSW_NU_FRAM_BASE 0x12000 @@ -85,6 +86,10 @@ #define AM65_CPSW_SGMII_MR_ADV_ABILITY_REG 0x018 #define AM65_CPSW_SGMII_CONTROL_MR_AN_ENABLE BIT(0) +#define AM65_CPSW_XGMII_PCSR_RX_STATUS_REG 0x00c +#define AM65_CPSW_XGMII_PCSR_RX_HI_BER BIT(31) +#define AM65_CPSW_XGMII_PCSR_RX_BLOCK_LOCK BIT(30) + #define AM65_CPSW_CTL_VLAN_AWARE BIT(1) #define AM65_CPSW_CTL_P0_ENABLE BIT(2) #define AM65_CPSW_CTL_P0_TX_CRC_REMOVE BIT(13) @@ -2160,7 +2165,57 @@ static void am65_cpsw_nuss_mac_link_up(struct phylink_config *config, struct phy netif_tx_wake_all_queues(ndev); } +static unsigned int am65_cpsw_pcsr_inband_caps(struct phylink_pcs *pcs, + phy_interface_t interface) +{ + return LINK_INBAND_DISABLE; +} + +static void am65_cpsw_pcsr_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, + struct phylink_link_state *state) +{ + struct am65_cpsw_port *port = container_of(pcs, struct am65_cpsw_port, slave.pcsr); + u32 val; + + val = readl(port->xgmii_base + AM65_CPSW_XGMII_PCSR_RX_STATUS_REG); + + state->link = (val & AM65_CPSW_XGMII_PCSR_RX_BLOCK_LOCK) && + !(val & AM65_CPSW_XGMII_PCSR_RX_HI_BER); + if (!state->link) + return; + + state->speed = SPEED_10000; + state->duplex = DUPLEX_FULL; +} + +static int am65_cpsw_pcsr_config(struct phylink_pcs *pcs, unsigned int neg_mode, + phy_interface_t interface, + const unsigned long *advertising, + bool permit_pause_to_mac) +{ + return 0; +} + +static const struct phylink_pcs_ops am65_cpsw_pcsr_ops = { + .pcs_inband_caps = am65_cpsw_pcsr_inband_caps, + .pcs_get_state = am65_cpsw_pcsr_get_state, + .pcs_config = am65_cpsw_pcsr_config, +}; + +static struct phylink_pcs *am65_cpsw_nuss_mac_select_pcs(struct phylink_config *config, + phy_interface_t interface) +{ + struct am65_cpsw_slave_data *slave = container_of(config, struct am65_cpsw_slave_data, + phylink_config); + + if (interface == PHY_INTERFACE_MODE_10GBASER) + return &slave->pcsr; + + return NULL; +} + static const struct phylink_mac_ops am65_cpsw_phylink_mac_ops = { + .mac_select_pcs = am65_cpsw_nuss_mac_select_pcs, .mac_config = am65_cpsw_nuss_mac_config, .mac_link_down = am65_cpsw_nuss_mac_link_down, .mac_link_up = am65_cpsw_nuss_mac_link_up, @@ -2633,6 +2688,9 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common) AM65_CPSW_NU_PORTS_OFFSET * (port_id); if (common->pdata.extra_modes) port->sgmii_base = common->ss_base + AM65_CPSW_SGMII_BASE * (port_id); + if (common->pdata.extra_modes & BIT(PHY_INTERFACE_MODE_10GBASER)) + port->xgmii_base = common->ss_base + AM65_CPSW_XGMII_BASE + + AM65_CPSW_XGMII_PORT_OFFSET * (port_id - 1); port->stat_base = common->cpsw_base + AM65_CPSW_NU_STATS_BASE + (AM65_CPSW_NU_STATS_PORT_OFFSET * port_id); port->name = of_get_property(port_np, "label", NULL); @@ -2848,6 +2906,12 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx) return -EOPNOTSUPP; } + if (port->xgmii_base) { + port->slave.pcsr.ops = &am65_cpsw_pcsr_ops; + port->slave.pcsr.poll = true; + __set_bit(PHY_INTERFACE_MODE_10GBASER, port->slave.pcsr.supported_interfaces); + } + phylink = phylink_create(&port->slave.phylink_config, of_fwnode_handle(port->slave.port_np), port->slave.phy_if, diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.h b/drivers/net/ethernet/ti/am65-cpsw-nuss.h index 7750448e47468..df2a6ef866ee4 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.h +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.h @@ -38,6 +38,7 @@ struct am65_cpsw_slave_data { int port_vlan; struct phylink *phylink; struct phylink_config phylink_config; + struct phylink_pcs pcsr; }; struct am65_cpsw_port { @@ -47,6 +48,7 @@ struct am65_cpsw_port { u32 port_id; void __iomem *port_base; void __iomem *sgmii_base; + void __iomem *xgmii_base; void __iomem *stat_base; void __iomem *fetch_ram_base; bool disabled; -- 2.43.0