net: ethernet: mtk_eth_soc: various enhancements
Subsystems (9)
Daniel Golle
maintainerv14 cover net: ethernet: mtk_eth_soc: various enhancements
This series brings a variety of fixes and enhancements for mtk_eth_soc, adds support for the MT7981 SoC and facilitates sharing the SGMII PCS code between mtk_eth_soc and mt7530.
The whole series has been tested on MT7622+MT7531 (BPi-R64), MT7623+MT7530 (BPi-R2), MT7981+GPY211 (GL.iNet GL-MT3000) and MT7986+MT7531 (BPi-R3). On the BananaPi R3 a variete of SFP modules have been tested, all of them (some SGMII with PHY, others 2500Base-X or 1000Base-X without PHY) are working well now, however, some of them need manually disabling of autonegotiation for the link to come up.
Changes since v13:
* no longer pile Lorenzo's patches on top, they will be submitted separately
* patches fixing existing code have been submitted already via 'net' tree, so they are no longer included in this series.
Changes since v12:
* remove patches "fixing" ????Base-X modes. Turns out the cause are buggy SFP modules for which we will need to introduce quirks rather than trying to address this in the Ethernet driver.
Changes since v11:
* remove patch "net: ethernet: mtk_eth_soc: fix RX data corruption issue" as it has already been merged via net tree
* add commits fixing 1000Base-X and 2500Base-X modes after phylink_pcs conversion
* completely remove mtk_sgmii.c as only about 20 lines were left in that file
* Add commits from Lorenzo for MT7988 as requested by him
Changes since v10:
* improve mediatek,mt7981-eth dt-bindings
* use regmap_set_bits instead of regmap_update_bits where possible
* completely remove mtk_sgmii.c
* no need to keep struct mtk_sgmii either as it had only a single element
Changes since v9:
* fix path in mediatek,sgmiisys dt-binding
Changes since v8:
* move mediatek,sgmiisys dt-bindings to correct net/pcs folder
* rebase on top of net-next/main so series applies cleanly again
Changes since v7:
* move mediatek,sgmiisys.yaml to more appropriate folder
* don't include <linux/phylink.h> twice in PCS driver, sort includes
Changes since v6:
* label MAC MCR bit 12 in 08/12, MediaTek replied explaining its function
Changes since v5:
* drop dev pointer also from struct mtk_sgmii, pass it as function parameter instead
* address comments left for dt-bindings
* minor improvements to commit messages
Changes since v4:
* remove unused dev pointer in struct pcs_mtk_lynxi
* squash link timer check into correct follow-up patch
Changes since v3:
* remove unused #define's
* use BMCR_* instead of #define'ing our own constants
* return before changing registers in case of invalid link timer
Changes since v2:
* improve dt-bindings, convert sgmisys bindings to dt-schema yaml
* fix typo
Changes since v1:
* apply reverse xmas tree everywhere
* improve commit descriptions
* add dt binding documentation
* various small changes addressing all comments received for v1
Daniel Golle (9):
net: ethernet: mtk_eth_soc: add support for MT7981 SoC
dt-bindings: net: mediatek,net: add mt7981-eth binding
dt-bindings: arm: mediatek: sgmiisys: Convert to DT schema
dt-bindings: net: pcs: mediatek,sgmiisys: add MT7981 SoC
net: ethernet: mtk_eth_soc: set MDIO bus clock frequency
net: ethernet: mtk_eth_soc: ppe: add support for flow accounting
net: pcs: add driver for MediaTek SGMII PCS
net: ethernet: mtk_eth_soc: switch to external PCS driver
net: dsa: mt7530: use external PCS driver
.../arm/mediatek/mediatek,sgmiisys.txt | 27 -- .../devicetree/bindings/net/mediatek,net.yaml | 53 ++- .../bindings/net/pcs/mediatek,sgmiisys.yaml | 55 ++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 1 + drivers/net/dsa/mt7530.c | 277 ++++------------ drivers/net/dsa/mt7530.h | 47 +-- drivers/net/ethernet/mediatek/Kconfig | 2 + drivers/net/ethernet/mediatek/Makefile | 2 +- drivers/net/ethernet/mediatek/mtk_eth_path.c | 14 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 111 ++++++- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 118 +++---- drivers/net/ethernet/mediatek/mtk_ppe.c | 114 ++++++- drivers/net/ethernet/mediatek/mtk_ppe.h | 25 +- .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 9 +- .../net/ethernet/mediatek/mtk_ppe_offload.c | 8 + drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 14 + drivers/net/ethernet/mediatek/mtk_sgmii.c | 207 ------------ drivers/net/pcs/Kconfig | 7 + drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs-mtk-lynxi.c | 305 ++++++++++++++++++ include/linux/pcs/pcs-mtk-lynxi.h | 13 + 22 files changed, 819 insertions(+), 599 deletions(-) delete mode 100644 Documentation/devicetree/bindings/arm/mediatek/mediatek,sgmiisys.txt create mode 100644 Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml delete mode 100644 drivers/net/ethernet/mediatek/mtk_sgmii.c create mode 100644 drivers/net/pcs/pcs-mtk-lynxi.c create mode 100644 include/linux/pcs/pcs-mtk-lynxi.h
base-commit: 105a201ebf3312990b96c4fbaade22e31402f8cc
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v14 1/9 net: ethernet: mtk_eth_soc: add support for MT7981 SoC
The MediaTek MT7981 SoC comes with two 1G/2.5G SGMII ports, just like MT7986.
In addition MT7981 is equipped with a built-in 1000Base-T PHY which can be used with GMAC1.
As many MT7981 boards make use of inverting SGMII signal polarity, add new device-tree attribute 'mediatek,pn_swap' to support them.
--- drivers/net/ethernet/mediatek/mtk_eth_path.c | 14 +++++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 21 +++++++++++++ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 31 ++++++++++++++++++++ drivers/net/ethernet/mediatek/mtk_sgmii.c | 10 +++++++ 4 files changed, 73 insertions(+), 3 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_path.c +11 -3
@@ -96,12 +96,20 @@ static int set_mux_gmac2_gmac0_to_gephy(struct mtk_eth *eth, int path)static int set_mux_u3_gmac2_to_qphy (struct mtk_eth *eth,int path) { -unsigned int val =0 ; +unsigned int val =0 , mask =0 , reg =0 ;bool updated = true;switch (path) {case MTK_ETH_PATH_GMAC2_SGMII : - val =CO_QPHY_SEL ; +if (MTK_HAS_CAPS (eth->soc->caps,MTK_U3_COPHY_V2 )) { + reg =USB_PHY_SWITCH_REG ; + val =SGMII_QPHY_SEL ; + mask =QPHY_SEL_MASK ; + }else { + reg =INFRA_MISC2 ; + val =CO_QPHY_SEL ; + mask = val; + }break ;default : updated = false;
@@ -109,7 +117,7 @@ static int set_mux_u3_gmac2_to_qphy(struct mtk_eth *eth, int path) }if (updated) -regmap_update_bits (eth->infra,INFRA_MISC2 ,CO_QPHY_SEL , val); +regmap_update_bits (eth->infra, reg, mask, val);dev_dbg (eth->dev,"path %s in %s updated = %d\n" ,mtk_eth_path_name (path), __func__, updated);
drivers/net/ethernet/mediatek/mtk_eth_soc.c +21 -0
@@ -4846,6 +4846,26 @@ static const struct mtk_soc_data mt7629_data = { }, }; +static const struct mtk_soc_data mt7981_data = { + .reg_map = &mt7986_reg_map, + .ana_rgc3 =0x128 , + .caps =MT7981_CAPS , + .hw_features =MTK_HW_FEATURES , + .required_clks =MT7981_CLKS_BITMAP , + .required_pctl = false, + .offload_version =2 , + .hash_offset =4 , + .foe_entry_size =sizeof (struct mtk_foe_entry ), + .txrx = { + .txd_size =sizeof (struct mtk_tx_dma_v2 ), + .rxd_size =sizeof (struct mtk_rx_dma_v2 ), + .rx_irq_done_mask =MTK_RX_DONE_INT_V2 , + .rx_dma_l4_valid =RX_DMA_L4_VALID_V2 , + .dma_max_len =MTK_TX_DMA_BUF_LEN_V2 , + .dma_len_offset =8 , + }, +}; +static const struct mtk_soc_data mt7986_data = { .reg_map = &mt7986_reg_map, .ana_rgc3 =0x128 ,
@@ -4888,6 +4908,7 @@ const struct of_device_id of_mtk_match[] = { { .compatible = "mediatek,mt7622-eth", .data = &mt7622_data}, { .compatible = "mediatek,mt7623-eth", .data = &mt7623_data}, { .compatible = "mediatek,mt7629-eth", .data = &mt7629_data}, + { .compatible = "mediatek,mt7981-eth", .data = &mt7981_data}, { .compatible = "mediatek,mt7986-eth", .data = &mt7986_data}, { .compatible = "ralink,rt5350-eth", .data = &rt5350_data}, {},
drivers/net/ethernet/mediatek/mtk_eth_soc.h +31 -0
@@ -556,11 +556,22 @@#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8#define SGMII_PHYA_PWD BIT(4) +/* Register to QPHY wrapper control */ +#define SGMSYS_QPHY_WRAP_CTRL 0xec +#define SGMII_PN_SWAP_MASK GENMASK(1, 0) +#define SGMII_PN_SWAP_TX_RX (BIT(0) | BIT(1)) +#define MTK_SGMII_FLAG_PN_SWAP BIT(0) +/* Infrasys subsystem config registers */ #define INFRA_MISC2 0x70c#define CO_QPHY_SEL BIT(0)#define GEPHY_MAC_SEL BIT(1) +/* Top misc registers */ +#define USB_PHY_SWITCH_REG 0x218 +#define QPHY_SEL_MASK GENMASK(1, 0) +#define SGMII_QPHY_SEL 0x2 +/* MT7628/88 specific stuff */ #define MT7628_PDMA_OFFSET 0x0800#define MT7628_SDM_OFFSET 0x0c00
@@ -741,6 +752,17 @@ enum mtk_clks_map { BIT(MTK_CLK_SGMII2_CDR_FB) | \ BIT(MTK_CLK_SGMII_CK) | \ BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP)) +#define MT7981_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \ + BIT(MTK_CLK_WOCPU0) | \ + BIT(MTK_CLK_SGMII_TX_250M) | \ + BIT(MTK_CLK_SGMII_RX_250M) | \ + BIT(MTK_CLK_SGMII_CDR_REF) | \ + BIT(MTK_CLK_SGMII_CDR_FB) | \ + BIT(MTK_CLK_SGMII2_TX_250M) | \ + BIT(MTK_CLK_SGMII2_RX_250M) | \ + BIT(MTK_CLK_SGMII2_CDR_REF) | \ + BIT(MTK_CLK_SGMII2_CDR_FB) | \ + BIT(MTK_CLK_SGMII_CK))#define MT7986_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \ BIT(MTK_CLK_WOCPU1) | BIT(MTK_CLK_WOCPU0) | \ BIT(MTK_CLK_SGMII_TX_250M) | \
@@ -854,6 +876,7 @@ enum mkt_eth_capabilities {MTK_NETSYS_V2_BIT ,MTK_SOC_MT7628_BIT ,MTK_RSTCTRL_PPE1_BIT , +MTK_U3_COPHY_V2_BIT ,/* MUX BITS*/ MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
@@ -888,6 +911,7 @@ enum mkt_eth_capabilities {#define MTK_NETSYS_V2 BIT(MTK_NETSYS_V2_BIT)#define MTK_SOC_MT7628 BIT(MTK_SOC_MT7628_BIT)#define MTK_RSTCTRL_PPE1 BIT(MTK_RSTCTRL_PPE1_BIT) +#define MTK_U3_COPHY_V2 BIT(MTK_U3_COPHY_V2_BIT)#define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \ BIT(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
@@ -960,6 +984,11 @@ enum mkt_eth_capabilities { MTK_MUX_U3_GMAC2_TO_QPHY | \ MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA) +#define MT7981_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \ + MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \ + MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \ + MTK_NETSYS_V2 | MTK_RSTCTRL_PPE1) +#define MT7986_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \ MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \ MTK_NETSYS_V2 | MTK_RSTCTRL_PPE1)
@@ -1073,12 +1102,14 @@ struct mtk_soc_data {* @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap * @interface: Currently configured interface mode * @pcs: Phylink PCS structure +* @flags: Flags indicating hardware properties */ struct mtk_pcs {struct regmap *regmap;u32 ana_rgc3;phy_interface_t interface;struct phylink_pcs pcs; +u32 flags; };/* struct mtk_sgmii - This is the structure holding sgmii regmap and its
drivers/net/ethernet/mediatek/mtk_sgmii.c +10 -0
@@ -91,6 +91,11 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,regmap_update_bits (mpcs->regmap,SGMII_RESERVED_0 ,SGMII_SW_RESET ,SGMII_SW_RESET ); +if (mpcs->flags &MTK_SGMII_FLAG_PN_SWAP ) +regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_WRAP_CTRL , +SGMII_PN_SWAP_MASK , +SGMII_PN_SWAP_TX_RX ); +if (interface ==PHY_INTERFACE_MODE_2500BASEX ) rgc3 =RG_PHY_SPEED_3_125G ;else
@@ -186,6 +191,11 @@ int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *r, u32 ana_rgc3) ss->pcs[i].ana_rgc3 = ana_rgc3; ss->pcs[i].regmap =syscon_node_to_regmap (np); + + ss->pcs[i].flags =0 ; +if (of_property_read_bool (np,"mediatek,pnswap" )) + ss->pcs[i].flags |=MTK_SGMII_FLAG_PN_SWAP ; +of_node_put (np);if (IS_ERR (ss->pcs[i].regmap))return PTR_ERR (ss->pcs[i].regmap);
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v14 2/9 dt-bindings: net: mediatek,net: add mt7981-eth binding
In reply to Daniel GolleIntroduce DT bindings for the MT7981 SoC to mediatek,net.yaml.
--- .../devicetree/bindings/net/mediatek,net.yaml | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/net/mediatek,net.yaml +48 -5
@@ -21,6 +21,7 @@ properties: - mediatek,mt7623-eth - mediatek,mt7622-eth - mediatek,mt7629-eth + - mediatek,mt7981-eth - mediatek,mt7986-eth - ralink,rt5350-eth
@@ -78,6 +79,11 @@ properties: description: List of phandles to wireless ethernet dispatch nodes. + mediatek,wed-pcie: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to the mediatek wed-pcie controller. + dma-coherent: true mdio-bus:
@@ -123,6 +129,8 @@ allOf: mediatek,wed: false + mediatek,wed-pcie: false + - if: properties: compatible:
@@ -160,6 +168,8 @@ allOf: description: Phandle to the mediatek pcie-mirror controller. + mediatek,wed-pcie: false + - if: properties: compatible:
@@ -206,6 +216,44 @@ allOf: mediatek,wed: false + mediatek,wed-pcie: false + + - if: + properties: + compatible: + contains: + const: mediatek,mt7981-eth + then: + properties: + interrupts: + minItems: 4 + + clocks: + minItems: 15 + maxItems: 15 + + clock-names: + items: + - const: fe + - const: gp2 + - const: gp1 + - const: wocpu0 + - const: sgmii_ck + - const: sgmii_tx250m + - const: sgmii_rx250m + - const: sgmii_cdr_ref + - const: sgmii_cdr_fb + - const: sgmii2_tx250m + - const: sgmii2_rx250m + - const: sgmii2_cdr_ref + - const: sgmii2_cdr_fb + - const: netsys0 + - const: netsys1 + + mediatek,sgmiisys: + minItems: 2 + maxItems: 2 + - if: properties: compatible:
@@ -242,11 +290,6 @@ allOf: minItems: 2 maxItems: 2 - mediatek,wed-pcie: - $ref: /schemas/types.yaml#/definitions/phandle - description: - Phandle to the mediatek wed-pcie controller. - patternProperties: "^mac@[0-1]$": type: object
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v14 3/9 dt-bindings: arm: mediatek: sgmiisys: Convert to DT schema
In reply to Daniel GolleConvert mediatek,sgmiiisys bindings to DT schema format.
Add maintainer Matthias Brugger, no maintainers were listed in the original documentation.
As this node is also referenced by the Ethernet controller and used as SGMII PCS add this fact to the description.
Move the file to Documentation/devicetree/bindings/net/pcs/ which seems more appropriate given that the great majority of registers are related to SGMII PCS functionality and only one register represents clock bits.
--- .../arm/mediatek/mediatek,sgmiisys.txt | 27 ---------- .../bindings/net/pcs/mediatek,sgmiisys.yaml | 49 +++++++++++++++++++ 2 files changed, 49 insertions(+), 27 deletions(-) delete mode 100644 Documentation/devicetree/bindings/arm/mediatek/mediatek,sgmiisys.txt create mode 100644 Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml
Documentation/devicetree/bindings/arm/mediatek/mediatek,sgmiisys.txt deleted +0 -27
@@ -1,27 +0,0 @@ -MediaTek SGMIISYS controller -============================ - -The MediaTek SGMIISYS controller provides various clocks to the system. - -Required Properties: - -- compatible: Should be: - - "mediatek,mt7622-sgmiisys", "syscon" - - "mediatek,mt7629-sgmiisys", "syscon" - - "mediatek,mt7981-sgmiisys_0", "syscon" - - "mediatek,mt7981-sgmiisys_1", "syscon" - - "mediatek,mt7986-sgmiisys_0", "syscon" - - "mediatek,mt7986-sgmiisys_1", "syscon" -- #clock-cells: Must be 1 - -The SGMIISYS controller uses the common clk binding from -Documentation/devicetree/bindings/clock/clock-bindings.txt -The available clocks are defined in dt-bindings/clock/mt*-clk.h. - -Example: - -sgmiisys: sgmiisys@1b128000 { - compatible = "mediatek,mt7622-sgmiisys", "syscon"; - reg = <0 0x1b128000 0 0x1000>; - #clock-cells = <1>; -};
Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v14 4/9 dt-bindings: net: pcs: mediatek,sgmiisys: add MT7981 SoC
In reply to Daniel GolleAdd mediatek,pnswap boolean property needed on many boards using the MediaTek MT7981 SoC.
--- .../devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml +6 -0
@@ -19,6 +19,8 @@ properties: - enum: - mediatek,mt7622-sgmiisys - mediatek,mt7629-sgmiisys + - mediatek,mt7981-sgmiisys_0 + - mediatek,mt7981-sgmiisys_1 - mediatek,mt7986-sgmiisys_0 - mediatek,mt7986-sgmiisys_1 - const: syscon
@@ -29,6 +31,10 @@ properties: '#clock-cells': const: 1 + mediatek,pnswap: + description: Invert polarity of the SGMII data lanes + type: boolean + required: - compatible - reg
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v14 5/9 net: ethernet: mtk_eth_soc: set MDIO bus clock frequency
In reply to Daniel GolleSet MDIO bus clock frequency and allow setting a custom maximum frequency from device tree.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 21 +++++++++++++++++++++ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 7 +++++++ 2 files changed, 28 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +21 -0
@@ -765,8 +765,10 @@ static const struct phylink_mac_ops mtk_phylink_ops = {static int mtk_mdio_init (struct mtk_eth *eth) { +unsigned int max_clk =2500000 , divider;struct device_node *mii_np;int ret; +u32 val; mii_np =of_get_child_by_name (eth->dev->of_node,"mdio-bus" );if (!mii_np) {
@@ -794,6 +796,25 @@ static int mtk_mdio_init(struct mtk_eth *eth) eth->mii_bus->parent = eth->dev;snprintf (eth->mii_bus->id,MII_BUS_ID_SIZE ,"%pOFn" , mii_np); + +if (!of_property_read_u32 (mii_np,"clock-frequency" , &val)) { +if (val >MDC_MAX_FREQ || val <MDC_MAX_FREQ /MDC_MAX_DIVIDER ) { +dev_err (eth->dev,"MDIO clock frequency out of range" ); + ret = -EINVAL ; + goto err_put_node; + } + max_clk = val; + } + divider = min_t(unsigned int, DIV_ROUND_UP(MDC_MAX_FREQ, max_clk), 63); + +/* Configure MDC Divider */ + val =mtk_r32 (eth,MTK_PPSC ); + val &= ~PPSC_MDC_CFG ; + val |=FIELD_PREP (PPSC_MDC_CFG , divider) |PPSC_MDC_TURBO ; +mtk_w32 (eth, val,MTK_PPSC ); + +dev_dbg (eth->dev,"MDC is running on %d Hz\n" ,MDC_MAX_FREQ / divider); + ret =of_mdiobus_register (eth->mii_bus, mii_np); err_put_node:
drivers/net/ethernet/mediatek/mtk_eth_soc.h +7 -0
@@ -363,6 +363,13 @@#define RX_DMA_VTAG_V2 BIT(0)#define RX_DMA_L4_VALID_V2 BIT(2) +/* PHY Polling and SMI Master Control registers */ +#define MTK_PPSC 0x10000 +#define PPSC_MDC_CFG GENMASK(29, 24) +#define PPSC_MDC_TURBO BIT(20) +#define MDC_MAX_FREQ 25000000 +#define MDC_MAX_DIVIDER 63 +/* PHY Indirect Access Control registers */ #define MTK_PHY_IAC 0x10004#define PHY_IAC_ACCESS BIT(31)
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v14 6/9 net: ethernet: mtk_eth_soc: ppe: add support for flow accounting
In reply to Daniel GolleThe PPE units found in MT7622 and newer support packet and byte accounting of hw-offloaded flows. Add support for reading those counters as found in MediaTek's SDK[1].
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 +- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 3 + drivers/net/ethernet/mediatek/mtk_ppe.c | 114 +++++++++++++++++- drivers/net/ethernet/mediatek/mtk_ppe.h | 25 +++- .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 9 +- .../net/ethernet/mediatek/mtk_ppe_offload.c | 8 ++ drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 14 +++ 7 files changed, 172 insertions(+), 9 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -2
@@ -4697,8 +4697,8 @@ static int mtk_probe(struct platform_device *pdev)for (i =0 ; i < num_ppe; i++) {u32 ppe_addr = eth->soc->reg_map->ppe_base + i *0x400 ; - eth->ppe[i] =mtk_ppe_init (eth, eth->base + ppe_addr, - eth->soc->offload_version, i); + eth->ppe[i] =mtk_ppe_init (eth, eth->base + ppe_addr, i); +if (!eth->ppe[i]) { err = -ENOMEM ; goto err_deinit_ppe;
@@ -4820,6 +4820,7 @@ static const struct mtk_soc_data mt7622_data = { .required_pctl = false, .offload_version = 2, .hash_offset = 2, + .has_accounting = true, .foe_entry_size = sizeof(struct mtk_foe_entry) - 16, .txrx = { .txd_size = sizeof(struct mtk_tx_dma),
@@ -4857,6 +4858,7 @@ static const struct mtk_soc_data mt7629_data = { .hw_features = MTK_HW_FEATURES, .required_clks = MT7629_CLKS_BITMAP, .required_pctl = false, + .has_accounting = true, .txrx = { .txd_size = sizeof(struct mtk_tx_dma), .rxd_size = sizeof(struct mtk_rx_dma),
@@ -4877,6 +4879,7 @@ static const struct mtk_soc_data mt7981_data = { .offload_version = 2, .hash_offset = 4, .foe_entry_size = sizeof(struct mtk_foe_entry), + .has_accounting = true, .txrx = { .txd_size = sizeof(struct mtk_tx_dma_v2), .rxd_size = sizeof(struct mtk_rx_dma_v2),
@@ -4897,6 +4900,7 @@ static const struct mtk_soc_data mt7986_data = { .offload_version = 2, .hash_offset = 4, .foe_entry_size = sizeof(struct mtk_foe_entry), + .has_accounting = true, .txrx = { .txd_size = sizeof(struct mtk_tx_dma_v2), .rxd_size = sizeof(struct mtk_rx_dma_v2),
drivers/net/ethernet/mediatek/mtk_eth_soc.h +3 -0
@@ -1070,6 +1070,8 @@ struct mtk_reg_map {* the extra setup for those pins used by GMAC. * @hash_offset Flow table hash offset. * @foe_entry_size Foe table entry size. +* @has_accounting Bool indicating support for accounting of +* offloaded flows. * @txd_size Tx DMA descriptor size. * @rxd_size Rx DMA descriptor size. * @rx_irq_done_mask Rx irq done register mask.
@@ -1087,6 +1089,7 @@ struct mtk_soc_data {u8 hash_offset;u16 foe_entry_size;netdev_features_t hw_features; +bool has_accounting;struct {u32 txd_size;u32 rxd_size;
drivers/net/ethernet/mediatek/mtk_ppe.c +111 -3
159 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_ppe.h +23 -2
@@ -57,6 +57,7 @@ enum {#define MTK_FOE_IB2_MULTICAST BIT(8)#define MTK_FOE_IB2_WDMA_QID2 GENMASK(13, 12) +#define MTK_FOE_IB2_MIB_CNT BIT(15)#define MTK_FOE_IB2_WDMA_DEVIDX BIT(16)#define MTK_FOE_IB2_WDMA_WINFO BIT(17)
@@ -285,16 +286,34 @@ struct mtk_flow_entry {unsigned long cookie; }; +struct mtk_mib_entry { +u32 byt_cnt_l; +u16 byt_cnt_h; +u32 pkt_cnt_l; +u8 pkt_cnt_h; +u8 _rsv0; +u32 _rsv1; +} __packed; + +struct mtk_foe_accounting { +u64 bytes; +u64 packets; +}; +struct mtk_ppe {struct mtk_eth *eth;struct device *dev;void __iomem *base;int version;char dirname[5 ]; +bool accounting;void *foe_table;dma_addr_t foe_phys; +struct mtk_mib_entry *mib_table; +dma_addr_t mib_phys; +u16 foe_check_time[MTK_PPE_ENTRIES ];struct hlist_head *foe_flow;
@@ -303,8 +322,8 @@ struct mtk_ppe {void *acct_table; }; -struct mtk_ppe *mtk_ppe_init (struct mtk_eth *eth,void __iomem *base, -int version,int index); +struct mtk_ppe *mtk_ppe_init (struct mtk_eth *eth,void __iomem *base,int index); +void mtk_ppe_deinit (struct mtk_eth *eth);void mtk_ppe_start (struct mtk_ppe *ppe);int mtk_ppe_stop (struct mtk_ppe *ppe);
@@ -359,5 +378,7 @@ int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);void mtk_foe_entry_clear (struct mtk_ppe *ppe,struct mtk_flow_entry *entry);int mtk_foe_entry_idle_time (struct mtk_ppe *ppe,struct mtk_flow_entry *entry);int mtk_ppe_debugfs_init (struct mtk_ppe *ppe,int index); +struct mtk_foe_accounting *mtk_foe_entry_get_mib (struct mtk_ppe *ppe,u32 index, +struct mtk_foe_accounting *diff);#endif
drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c +7 -2
@@ -82,6 +82,7 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)struct mtk_foe_entry *entry =mtk_foe_get_entry (ppe, i);struct mtk_foe_mac_info *l2;struct mtk_flow_addr_info ai = {}; +struct mtk_foe_accounting *acct;unsigned char h_source[ETH_ALEN ];unsigned char h_dest[ETH_ALEN ];int type, state;
@@ -95,6 +96,8 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)if (bind && state !=MTK_FOE_STATE_BIND )continue ; + acct =mtk_foe_entry_get_mib (ppe, i,NULL ); + type =FIELD_GET (MTK_FOE_IB1_PACKET_TYPE , entry->ib1); seq_printf(m, "%05x %s %7s", i, mtk_foe_entry_state_str(state),
@@ -153,9 +156,11 @@ mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind) *((__be16 *)&h_dest[4 ]) =htons (l2->dest_mac_lo);seq_printf (m," eth=%pM->%pM etype=%04x" -" vlan=%d,%d ib1=%08x ib2=%08x\n" , +" vlan=%d,%d ib1=%08x ib2=%08x" +" packets=%llu bytes=%llu\n" , h_source, h_dest,ntohs (l2->etype), - l2->vlan1, l2->vlan2, entry->ib1, ib2); + l2->vlan1, l2->vlan2, entry->ib1, ib2, + acct ? acct->packets :0 , acct ? acct->bytes :0 ); }return 0 ;
drivers/net/ethernet/mediatek/mtk_ppe_offload.c +8 -0
@@ -497,6 +497,7 @@ static int mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f) { struct mtk_flow_entry *entry; +struct mtk_foe_accounting diff;u32 idle; entry = rhashtable_lookup(ð->flow_table, &f->cookie,
@@ -507,6 +508,13 @@ mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f) idle =mtk_foe_entry_idle_time (eth->ppe[entry->ppe_index], entry); f->stats.lastused = jiffies - idle *HZ ; +if (entry->hash !=0xFFFF && +mtk_foe_entry_get_mib (eth->ppe[entry->ppe_index], entry->hash, + &diff)) { + f->stats.pkts += diff.packets; + f->stats.bytes += diff.bytes; + } +return 0 ; }
drivers/net/ethernet/mediatek/mtk_ppe_regs.h +14 -0
@@ -149,6 +149,20 @@ enum {#define MTK_PPE_MIB_TB_BASE 0x338 +#define MTK_PPE_MIB_SER_CR 0x33C +#define MTK_PPE_MIB_SER_CR_ST BIT(16) +#define MTK_PPE_MIB_SER_CR_ADDR GENMASK(13, 0) + +#define MTK_PPE_MIB_SER_R0 0x340 +#define MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW GENMASK(31, 0) + +#define MTK_PPE_MIB_SER_R1 0x344 +#define MTK_PPE_MIB_SER_R1_PKT_CNT_LOW GENMASK(31, 16) +#define MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH GENMASK(15, 0) + +#define MTK_PPE_MIB_SER_R2 0x348 +#define MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH GENMASK(23, 0) +#define MTK_PPE_MIB_CACHE_CTL 0x350#define MTK_PPE_MIB_CACHE_CTL_EN BIT(0)#define MTK_PPE_MIB_CACHE_CTL_FLUSH BIT(2)
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v14 7/9 net: pcs: add driver for MediaTek SGMII PCS
In reply to Daniel GolleThe SGMII core found in several MediaTek SoCs is identical to what can also be found in MediaTek's MT7531 Ethernet switch IC.
As this has not always been clear, both drivers developed different implementations to deal with the PCS.
Recently Alexander Couzens pointed out this fact which lead to the development of this shared driver.
Add a dedicated driver, mostly by copying the code now found in the Ethernet driver. The now redundant code will be removed by a follow-up commit.
--- MAINTAINERS | 8 + drivers/net/pcs/Kconfig | 7 + drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs-mtk-lynxi.c | 305 ++++++++++++++++++++++++++++++ include/linux/pcs/pcs-mtk-lynxi.h | 13 ++ 5 files changed, 334 insertions(+) create mode 100644 drivers/net/pcs/pcs-mtk-lynxi.c create mode 100644 include/linux/pcs/pcs-mtk-lynxi.h
MAINTAINERS +8 -0
@@ -13042,6 +13042,14 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/mediatek/ +MEDIATEK ETHERNET PCS DRIVER +M: Alexander Couzens <[email protected]> +M: Daniel Golle <[email protected]> +L: [email protected] +S: Maintained +F: drivers/net/pcs/pcs-mtk-lynxi.c +F: include/linux/pcs/pcs-mtk-lynxi.h + MEDIATEK I2C CONTROLLER DRIVER M: Qii Wang <[email protected]> L: [email protected]
drivers/net/pcs/Kconfig +7 -0
@@ -18,6 +18,13 @@ config PCS_LYNX This module provides helpers to phylink for managing the Lynx PCS which is part of the Layerscape and QorIQ Ethernet SERDES. +config PCS_MTK_LYNXI + tristate + select REGMAP + help + This module provides helpers to phylink for managing the LynxI PCS + which is part of MediaTek's SoC and Ethernet switch ICs. + config PCS_RZN1_MIIC tristate "Renesas RZ/N1 MII converter" depends on OF && (ARCH_RZN1 || COMPILE_TEST)
drivers/net/pcs/Makefile +1 -0
@@ -5,5 +5,6 @@ pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o +obj-$(CONFIG_PCS_MTK_LYNXI) += pcs-mtk-lynxi.o obj-$(CONFIG_PCS_RZN1_MIIC) += pcs-rzn1-miic.o obj-$(CONFIG_PCS_ALTERA_TSE) += pcs-altera-tse.o
drivers/net/pcs/pcs-mtk-lynxi.c new file +305 -0
305 lines not on this page · raw message
include/linux/pcs/pcs-mtk-lynxi.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_PCS_MTK_LYNXI_H +#define __LINUX_PCS_MTK_LYNXI_H + +#include <linux/phylink.h> +#include <linux/regmap.h> + +#define MTK_SGMII_FLAG_PN_SWAP BIT(0) +struct phylink_pcs *mtk_pcs_lynxi_create (struct device *dev, +struct regmap *regmap, +u32 ana_rgc3,u32 flags); +void mtk_pcs_lynxi_destroy (struct phylink_pcs *pcs); +#endif
Signature · 1 line
2.39.2
Aw: [PATCH net-next v14 7/9] net: pcs: add driver for MediaTek SGMII PCS
Re: [PATCH net-next v14 7/9] net: pcs: add driver for MediaTek SGMII PCS
In reply to Daniel GolleQuoted 7 lines · Daniel Golle
The SGMII core found in several MediaTek SoCs is identical to what can also be found in MediaTek's MT7531 Ethernet switch IC.
As this has not always been clear, both drivers developed different implementations to deal with the PCS.
Recently Alexander Couzens pointed out this fact which lead to the development of this shared driver.
Quoted 7 lines
Add a dedicated driver, mostly by copying the code now found in the Ethernet driver. The now redundant code will be removed by a follow-up commit.
Suggested-by Alexander Couzens <[email protected]>Suggested-by Russell King (Oracle) <[email protected]>Signed-off-by Daniel Golle <[email protected]>
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Daniel Golle
maintainerPATCH v14 8/9 net: ethernet: mtk_eth_soc: switch to external PCS driver
In reply to Daniel GolleNow that we got a PCS driver, use it and remove the now redundant PCS code and it's header macros from the Ethernet driver.
--- drivers/net/ethernet/mediatek/Kconfig | 2 + drivers/net/ethernet/mediatek/Makefile | 2 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 61 +++++- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 93 +-------- drivers/net/ethernet/mediatek/mtk_sgmii.c | 217 -------------------- 5 files changed, 56 insertions(+), 319 deletions(-) delete mode 100644 drivers/net/ethernet/mediatek/mtk_sgmii.c
drivers/net/ethernet/mediatek/Kconfig +2 -0
@@ -19,6 +19,8 @@ config NET_MEDIATEK_SOC select DIMLIB select PAGE_POOL select PAGE_POOL_STATS + select PCS_MTK_LYNXI + select REGMAP_MMIO help This driver supports the gigabit ethernet MACs in the MediaTek SoC family.
drivers/net/ethernet/mediatek/Makefile +1 -1
@@ -4,7 +4,7 @@ # obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth.o -mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o mtk_ppe_offload.o +mtk_eth-y := mtk_eth_soc.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o mtk_ppe_offload.o mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o mtk_wed_mcu.o mtk_wed_wo.o ifdef CONFIG_DEBUG_FS mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_debugfs.o
drivers/net/ethernet/mediatek/mtk_eth_soc.c +50 -11
110 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_eth_soc.h +3 -90
123 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_sgmii.c deleted +0 -217
217 lines not on this page · raw message
Signature · 1 line
2.39.2
Aw: [PATCH net-next v14 8/9] net: ethernet: mtk_eth_soc: switch to external PCS driver
Re: [PATCH net-next v14 8/9] net: ethernet: mtk_eth_soc: switch to external PCS driver
In reply to Daniel GolleQuoted 4 lines · Daniel Golle
Now that we got a PCS driver, use it and remove the now redundant PCS code and it's header macros from the Ethernet driver.
Signed-off-by Daniel Golle <[email protected]>
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Daniel Golle
maintainerPATCH v14 9/9 net: dsa: mt7530: use external PCS driver
In reply to Daniel GolleImplement regmap access wrappers, for now only to be used by the pcs-mtk-lynxi driver.
Make use of this external PCS driver and drop the now reduntant implementation in mt7530.c.
As a nice side effect the SGMII registers can now also more easily be inspected for debugging via /sys/kernel/debug/regmap.
--- drivers/net/dsa/Kconfig | 1 + drivers/net/dsa/mt7530.c | 277 ++++++++++----------------------------- drivers/net/dsa/mt7530.h | 47 +------ 3 files changed, 71 insertions(+), 254 deletions(-)
drivers/net/dsa/Kconfig +1 -0
@@ -38,6 +38,7 @@ config NET_DSA_MT7530 tristate "MediaTek MT7530 and MT7531 Ethernet switch support" select NET_DSA_TAG_MTK select MEDIATEK_GE_PHY + select PCS_MTK_LYNXI help This enables support for the MediaTek MT7530 and MT7531 Ethernet switch chips. Multi-chip module MT7530 in MT7621AT, MT7621DAT,
drivers/net/dsa/mt7530.c +66 -211
360 lines not on this page · raw message
drivers/net/dsa/mt7530.h +4 -43
64 lines not on this page · raw message
Signature · 1 line
2.39.2
Aw: [PATCH net-next v14 9/9] net: dsa: mt7530: use external PCS driver
Re: [PATCH net-next v14 9/9] net: dsa: mt7530: use external PCS driver
In reply to Daniel GolleQuoted 10 lines · Daniel Golle
Implement regmap access wrappers, for now only to be used by the pcs-mtk-lynxi driver.
Make use of this external PCS driver and drop the now reduntant implementation inmt7530.c.
As a nice side effect the SGMII registers can now also more easily be inspected for debugging via/sys/kernel/debug/regmap.Reviewed-by Russell King (Oracle) <[email protected]>Tested-by Bjørn Mork <[email protected]>Signed-off-by Daniel Golle <[email protected]>
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 4 lines · On Sun, 19 Mar 2023 12:56:07 +0000 you wrote:
This series brings a variety of fixes and enhancements for
mtk_eth_soc, adds support for the MT7981 SoC and facilitates sharing the SGMII PCS code betweenmtk_eth_socand mt7530.
Quoted 8 lines
The whole series has been tested on MT7622+MT7531 (BPi-R64), MT7623+MT7530 (BPi-R2), MT7981+GPY211 (GL.iNet GL-MT3000) and MT7986+MT7531 (BPi-R3). On the BananaPi R3 a variete of SFP modules have been tested, all of them (some SGMII with PHY, others 2500Base-X or 1000Base-X without PHY) are working well now, however, some of them need manually disabling of autonegotiation for the link to come up.
[...]
Here is the summary with links:
- [net-next,v14,1/9] net: ethernet: mtk_eth_soc: add support for MT7981 SoC
https://git.kernel.org/netdev/net-next/c/f5d43ddd334b - [net-next,v14,2/9] dt-bindings: net: mediatek,net: add mt7981-eth binding https://git.kernel.org/netdev/net-next/c/e3ac1c270466 - [net-next,v14,3/9] dt-bindings: arm: mediatek: sgmiisys: Convert to DT schema https://git.kernel.org/netdev/net-next/c/d4f08a703565 - [net-next,v14,4/9] dt-bindings: net: pcs: mediatek,sgmiisys: add MT7981 SoC https://git.kernel.org/netdev/net-next/c/4f7eb19c4f44 - [net-next,v14,5/9] net: ethernet: mtk_eth_soc: set MDIO bus clock frequency https://git.kernel.org/netdev/net-next/c/c0a440031d43 - [net-next,v14,6/9] net: ethernet: mtk_eth_soc: ppe: add support for flow accounting https://git.kernel.org/netdev/net-next/c/3fbe4d8c0e53 - [net-next,v14,7/9] net: pcs: add driver for MediaTek SGMII PCS https://git.kernel.org/netdev/net-next/c/4765a9722e09 - [net-next,v14,8/9] net: ethernet: mtk_eth_soc: switch to external PCS driver https://git.kernel.org/netdev/net-next/c/2a3ec7ae3133 - [net-next,v14,9/9] net: dsa: mt7530: use external PCS driver https://git.kernel.org/netdev/net-next/c/5b89aeae6e00
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html