Commit 1cc5a735185a ("stmmac: do not discard frame on dribbling bit assert") removed the packet drop condition for descriptors which report only a dribble error for Normal and Enhanced descriptors, since a dribble error with the correct FCS doesn't necessarily mean a bad packet. Do the same for dwmac4; accept receive frames with dribble-only errors while still counting them in the error statistics. Signed-off-by: Mohd Ayaan Anwar --- drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 4 +++- drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c index c6a8f8d73501..2549ffaf9cef 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c @@ -102,7 +102,9 @@ static int dwmac4_wrback_get_rx_status(struct stmmac_extra_stats *x, if (unlikely(rdes3 & RDES3_DRIBBLE_ERROR)) x->dribbling_bit++; - ret = discard_frame; + if ((rdes3 & RDES3_ERROR_SUMMARY_MASK) != + RDES3_DRIBBLE_ERROR) + ret = discard_frame; } message_type = FIELD_GET(RDES1_PTP_MSG_TYPE_MASK, rdes1); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h index fb1fea5b0e6e..8e8762f9e0c8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h @@ -120,6 +120,7 @@ #define RDES3_RECEIVE_WATCHDOG BIT(22) #define RDES3_GIANT_PACKET BIT(23) #define RDES3_CRC_ERROR BIT(24) +#define RDES3_ERROR_SUMMARY_MASK GENMASK(24, 19) #define RDES3_RDES0_VALID BIT(25) #define RDES3_RDES1_VALID BIT(26) #define RDES3_RDES2_VALID BIT(27) -- 2.34.1 The Qualcomm ETHQOS core supports RMII in MAC master mode. Add support for it by programming the required IO_MACRO registers and running its link clock at the 50 MHz reference rate required by RMII. A brief explanation of the programmed IO_MACRO bitfield configurations: - INTF_SEL = 1 selects the RMII interface rather than RGMII (00) / MII (10). - DDR_MODE = 0 selects SDR rather than DDR. - CLK_DIVIDE_SEL = 1 selects TX_CLK as the divider source. - TX_CLK_PHASE_SHIFT_EN = 0 implies the use of normal divided clock instead of the phase-shifted clock. Signed-off-by: Mohd Ayaan Anwar --- .../ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index d24509a4b4d7..683c6c3f3f37 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -71,6 +71,7 @@ /* RGMII_IO_MACRO_CONFIG2 fields */ #define RGMII_CONFIG2_RSVD_CONFIG15 GENMASK(31, 17) #define RGMII_CONFIG2_RGMII_CLK_SEL_CFG BIT(16) +#define RGMII_CONFIG2_RGMII_CFG_REV1 BIT(15) #define RGMII_CONFIG2_TX_TO_RX_LOOPBACK_EN BIT(13) #define RGMII_CONFIG2_CLK_DIVIDE_SEL BIT(12) #define RGMII_CONFIG2_RX_PROG_SWAP BIT(7) @@ -81,6 +82,7 @@ #define SGMII_PHY_CNTRL1_SGMII_TX_TO_RX_LOOPBACK_EN BIT(3) #define SGMII_10M_RX_CLK_DVDR 0x31 +#define RMII_REF_CLK_RATE 50000000 struct qcom_ethqos; @@ -182,6 +184,9 @@ static int ethqos_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i, struct qcom_ethqos *ethqos = bsp_priv; long rate; + if (interface == PHY_INTERFACE_MODE_RMII) + return clk_set_rate(ethqos->link_clk, RMII_REF_CLK_RATE); + if (!phy_interface_mode_is_rgmii(interface)) return 0; @@ -523,6 +528,38 @@ static int ethqos_rgmii_macro_init(struct qcom_ethqos *ethqos, int speed) return 0; } +static void ethqos_rmii_macro_init(struct qcom_ethqos *ethqos) +{ + rgmii_clrmask(ethqos, RGMII_CONFIG_POS_NEG_DATA_SEL, + RGMII_IO_MACRO_CONFIG); + rgmii_updatel(ethqos, RGMII_CONFIG_INTF_SEL, + FIELD_PREP(RGMII_CONFIG_INTF_SEL, 1), + RGMII_IO_MACRO_CONFIG); + rgmii_setmask(ethqos, RGMII_CONFIG_BYPASS_TX_ID_EN, + RGMII_IO_MACRO_CONFIG); + rgmii_setmask(ethqos, RGMII_CONFIG_LOOPBACK_EN, + RGMII_IO_MACRO_CONFIG); + rgmii_clrmask(ethqos, RGMII_CONFIG_DDR_MODE, RGMII_IO_MACRO_CONFIG); + + rgmii_setmask(ethqos, RGMII_CONFIG2_RGMII_CFG_REV1, + RGMII_IO_MACRO_CONFIG2); + rgmii_clrmask(ethqos, RGMII_CONFIG2_TX_TO_RX_LOOPBACK_EN, + RGMII_IO_MACRO_CONFIG2); + rgmii_setmask(ethqos, RGMII_CONFIG2_CLK_DIVIDE_SEL, + RGMII_IO_MACRO_CONFIG2); + rgmii_clrmask(ethqos, RGMII_CONFIG2_TX_CLK_PHASE_SHIFT_EN, + RGMII_IO_MACRO_CONFIG2); +} + +static void ethqos_fix_mac_speed_rmii(void *bsp_priv, + phy_interface_t interface, int speed, + unsigned int mode) +{ + struct qcom_ethqos *ethqos = bsp_priv; + + ethqos_rmii_macro_init(ethqos); +} + static void ethqos_fix_mac_speed_rgmii(void *bsp_priv, phy_interface_t interface, int speed, unsigned int mode) @@ -710,6 +747,13 @@ static int ethqos_clks_config(void *priv, bool enabled) */ qcom_ethqos_set_sgmii_loopback(ethqos, true); ethqos_set_func_clk_en(ethqos); + + /* The RMII PHY has no clock until the I/O macro drives the + * 50 MHz reference, so it needs to be programmed during probe + * itself. + */ + if (ethqos->phy_mode == PHY_INTERFACE_MODE_RMII) + ethqos_rmii_macro_init(ethqos); } else { clk_disable_unprepare(ethqos->link_clk); } @@ -771,6 +815,9 @@ static int ethqos_hlos_setup(struct qcom_ethqos *ethqos, ethqos_set_func_clk_en(ethqos); switch (ethqos->phy_mode) { + case PHY_INTERFACE_MODE_RMII: + plat_dat->fix_mac_speed = ethqos_fix_mac_speed_rmii; + break; case PHY_INTERFACE_MODE_RGMII: case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_RXID: @@ -897,6 +944,8 @@ static int qcom_ethqos_probe(struct platform_device *pdev) ethqos->phy_mode = plat_dat->phy_interface; switch (ethqos->phy_mode) { + case PHY_INTERFACE_MODE_RMII: + break; case PHY_INTERFACE_MODE_RGMII: case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_RXID: -- 2.34.1