net: ethernet: mtk_eth_soc: various enhancements
Subsystems (9)
Daniel Golle
maintainerv13 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.
Also prepare support for MT7988 which has been done while net-next was closed.
Note that this series depends on commit 697c3892d825 ("regmap: apply reg_base and reg_downshift for single register ops") to not break mt7530 pcs register access.
For SGMII and 1000Base-X mode to work well it also depends on commit 193250ace270 ("net: ethernet: mtk_eth_soc: fix RX data corruption issue") which has already been merged via the net tree.
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 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 (11):
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: arm: mediatek: sgmiisys: add MT7981 SoC
net: ethernet: mtk_eth_soc: set MDIO bus clock frequency
net: ethernet: mtk_eth_soc: reset PCS state
net: ethernet: mtk_eth_soc: only write values if needed
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
Lorenzo Bianconi (5):
net: ethernet: mtk_eth_soc: add MTK_NETSYS_V1 capability bit
net: ethernet: mtk_eth_soc: move MAX_DEVS in mtk_soc_data
net: ethernet: mtk_eth_soc: rely on num_devs and remove MTK_MAC_COUNT
net: ethernet: mtk_eth_soc: add MTK_NETSYS_V3 capability bit
net: ethernet: mtk_eth_soc: convert caps in mtk_soc_data struct to u64
.../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 | 36 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 314 ++++++++++++++---- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 207 ++++++------ 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 | 203 ----------- 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, 1050 insertions(+), 679 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: 46ca833c060cff588a5fc2c25a1def8a1b6284e2
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v13 2/16 dt-bindings: net: mediatek,net: add mt7981-eth binding
Introduce 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 v13 3/16 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/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 v13 4/16 dt-bindings: arm: 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 v13 1/16 net: ethernet: mtk_eth_soc: add support for MT7981 SoC
In reply to Daniel GolleThe 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
@@ -4845,6 +4845,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 ,
@@ -4887,6 +4907,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
@@ -551,11 +551,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
@@ -736,6 +747,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) | \
@@ -849,6 +871,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,
@@ -883,6 +906,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)
@@ -955,6 +979,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)
@@ -1068,12 +1097,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
@@ -88,6 +88,11 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL ,SGMII_PHYA_PWD ,SGMII_PHYA_PWD ); +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
@@ -182,6 +187,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 v13 5/16 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
@@ -764,8 +764,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) {
@@ -793,6 +795,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 v13 6/16 net: ethernet: mtk_eth_soc: reset PCS state
In reply to Daniel GolleReset the internal PCS state machine when changing interface mode. This prevents confusing the state machine when changing interface modes, e.g. from SGMII to 2500Base-X or vice-versa.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 4 ++++ drivers/net/ethernet/mediatek/mtk_sgmii.c | 4 ++++ 2 files changed, 8 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.h +4 -0
@@ -548,6 +548,10 @@#define SGMII_SEND_AN_ERROR_EN BIT(11)#define SGMII_IF_MODE_MASK GENMASK(5, 1) +/* Register to reset SGMII design */ +#define SGMII_RESERVED_0 0x34 +#define SGMII_SW_RESET BIT(0) +/* Register to set SGMII speed, ANA RG_ Control Signals III*/ #define SGMSYS_ANA_RG_CS3 0x2028#define RG_PHY_SPEED_MASK (BIT(2) | BIT(3))
drivers/net/ethernet/mediatek/mtk_sgmii.c +4 -0
@@ -88,6 +88,10 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL ,SGMII_PHYA_PWD ,SGMII_PHYA_PWD ); +/* Reset SGMII PCS state */ +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,
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v13 7/16 net: ethernet: mtk_eth_soc: only write values if needed
In reply to Daniel GolleOnly restart auto-negotiation and write link timer if actually necessary. This prevents losing the link in case of minor changes.
--- drivers/net/ethernet/mediatek/mtk_sgmii.c | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/mediatek/mtk_sgmii.c +12 -12
@@ -38,20 +38,16 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,const unsigned long *advertising, bool permit_pause_to_mac) { + bool mode_changed = false, changed, use_an;struct mtk_pcs *mpcs =pcs_to_mtk_pcs (pcs);unsigned int rgc3, sgm_mode, bmcr;int advertise, link_timer; -bool changed, use_an; advertise =phylink_mii_c22_pcs_encode_advertisement (interface, advertising);if (advertise <0 )return advertise; - link_timer =phylink_get_link_timer_ns (interface); -if (link_timer <0 ) -return link_timer; -/* Clearing IF_MODE_BIT0 switches the PCS to BASE-X mode, and * we assume that fixes it's speed at bitrate = line rate (in * other words, 1000Mbps or 2500Mbps).
@@ -77,13 +73,16 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, }if (use_an) { -/* FIXME: Do we need to set AN_RESTART here? */ - bmcr =SGMII_AN_RESTART |SGMII_AN_ENABLE ; + bmcr =SGMII_AN_ENABLE ; }else { bmcr =0 ; }if (mpcs->interface != interface) { + link_timer =phylink_get_link_timer_ns (interface); +if (link_timer <0 ) +return link_timer; +/* PHYA power down */ regmap_update_bits (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL ,SGMII_PHYA_PWD ,SGMII_PHYA_PWD );
@@ -106,16 +105,17 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,regmap_update_bits (mpcs->regmap, mpcs->ana_rgc3,RG_PHY_SPEED_3_125G , rgc3); +/* Setup the link timer */ +regmap_write (mpcs->regmap,SGMSYS_PCS_LINK_TIMER , link_timer /2 /8 ); + mpcs->interface = interface; + mode_changed = true; }/* Update the advertisement, noting whether it has changed */ regmap_update_bits_check (mpcs->regmap,SGMSYS_PCS_ADVERTISE ,SGMII_ADVERTISE , advertise, &changed); -/* Setup the link timer and QPHY power up inside SGMIISYS */ -regmap_write (mpcs->regmap,SGMSYS_PCS_LINK_TIMER , link_timer /2 /8 ); -/* Update the sgmsys mode register */ regmap_update_bits(mpcs->regmap, SGMSYS_SGMII_MODE, SGMII_REMOTE_FAULT_DIS | SGMII_SPEED_DUPLEX_AN |
@@ -123,7 +123,7 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,/* Update the BMCR */ regmap_update_bits (mpcs->regmap,SGMSYS_PCS_CONTROL_1 , -SGMII_AN_RESTART |SGMII_AN_ENABLE , bmcr); +SGMII_AN_ENABLE , bmcr);/* Release PHYA power down state * Only removing bit SGMII_PHYA_PWD isn't enough.
@@ -137,7 +137,7 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,usleep_range (50 ,100 );regmap_write (mpcs->regmap,SGMSYS_QPHY_PWR_STATE_CTRL ,0 ); -return changed; +return changed || mode_changed; }static void mtk_pcs_restart_an (struct phylink_pcs *pcs)
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v13 8/16 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
@@ -4696,8 +4696,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;
@@ -4819,6 +4819,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),
@@ -4856,6 +4857,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),
@@ -4876,6 +4878,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),
@@ -4896,6 +4899,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
@@ -1069,6 +1069,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.
@@ -1086,6 +1088,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 v13 9/16 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, 335 insertions(+) create mode 100644 drivers/net/pcs/pcs-mtk-lynxi.c create mode 100644 include/linux/pcs/pcs-mtk-lynxi.h
MAINTAINERS +8 -0
@@ -13047,6 +13047,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
Daniel Golle
maintainerPATCH v13 10/16 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
Daniel Golle
maintainerPATCH v13 11/16 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 driver.
Make use of external PCS driver and drop the 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
Daniel Golle
maintainerPATCH v13 12/16 net: ethernet: mtk_eth_soc: add MTK_NETSYS_V1 capability bit
In reply to Daniel GolleFrom: Lorenzo Bianconi <[email protected]>
Introduce MTK_NETSYS_V1 bit in the device capabilities for MT7621/MT7622/MT7623/MT7628/MT7629 SoCs.
Use !MTK_NETSYS_V1 instead of MTK_NETSYS_V2 in the driver codebase. This is a preliminary patch to introduce support for MT7988 SoC.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 30 +++++++------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 45 ++++++++++++--------- 2 files changed, 41 insertions(+), 34 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +15 -15
@@ -658,7 +658,7 @@ static void mtk_set_queue_speed(struct mtk_eth *eth, unsigned int idx,FIELD_PREP (MTK_QTX_SCH_MIN_RATE_MAN ,1 ) |FIELD_PREP (MTK_QTX_SCH_MIN_RATE_EXP ,4 ) |MTK_QTX_SCH_LEAKY_BUCKET_SIZE ; -if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) +if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) val |=MTK_QTX_SCH_LEAKY_BUCKET_EN ;if (IS_ENABLED (CONFIG_SOC_MT7621 )) {
@@ -1037,7 +1037,7 @@ static bool mtk_rx_get_desc(struct mtk_eth *eth, struct mtk_rx_dma_v2 *rxd, rxd->rxd1 =READ_ONCE (dma_rxd->rxd1); rxd->rxd3 =READ_ONCE (dma_rxd->rxd3); rxd->rxd4 =READ_ONCE (dma_rxd->rxd4); -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) { rxd->rxd5 =READ_ONCE (dma_rxd->rxd5); rxd->rxd6 =READ_ONCE (dma_rxd->rxd6); }
@@ -1095,7 +1095,7 @@ static int mtk_init_fq_dma(struct mtk_eth *eth) txd->txd3 =TX_DMA_PLEN0 (MTK_QDMA_PAGE_SIZE ); txd->txd4 =0 ; -if (MTK_HAS_CAPS (soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (soc->caps,MTK_NETSYS_V1 )) { txd->txd5 =0 ; txd->txd6 =0 ; txd->txd7 =0 ;
@@ -1286,7 +1286,7 @@ static void mtk_tx_set_dma_desc(struct net_device *dev, void *txd,struct mtk_mac *mac =netdev_priv (dev);struct mtk_eth *eth = mac->hw; -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 ))mtk_tx_set_dma_desc_v2 (dev, txd, info);else mtk_tx_set_dma_desc_v1 (dev, txd, info);
@@ -1937,7 +1937,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,break ;/* find out which mac the packet come from. values start at 1 */ -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) mac =RX_DMA_GET_SPORT_V2 (trxd.rxd5) -1 ;else if (!MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 ) && !(trxd.rxd4 &RX_DMA_SPECIAL_TAG ))
@@ -2033,7 +2033,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, skb->dev = netdev; bytes += skb->len; -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) { reason =FIELD_GET (MTK_RXD5_PPE_CPU_REASON , trxd.rxd5); hash = trxd.rxd5 &MTK_RXD5_FOE_ENTRY ;if (hash !=MTK_RXD5_FOE_ENTRY )
@@ -2059,7 +2059,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,mtk_ppe_check_skb (eth->ppe[0 ], skb, hash);if (netdev->features &NETIF_F_HW_VLAN_CTAG_RX ) { -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) {if (trxd.rxd3 &RX_DMA_VTAG_V2 ) { vlan_proto =RX_DMA_VPID (trxd.rxd4); vlan_tci =RX_DMA_VID (trxd.rxd4);
@@ -2384,7 +2384,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth) txd->txd2 = next_ptr; txd->txd3 =TX_DMA_LS0 |TX_DMA_OWNER_CPU ; txd->txd4 =0 ; -if (MTK_HAS_CAPS (soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (soc->caps,MTK_NETSYS_V1 )) { txd->txd5 =0 ; txd->txd6 =0 ; txd->txd7 =0 ;
@@ -2437,7 +2437,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)FIELD_PREP (MTK_QTX_SCH_MIN_RATE_MAN ,1 ) |FIELD_PREP (MTK_QTX_SCH_MIN_RATE_EXP ,4 ) |MTK_QTX_SCH_LEAKY_BUCKET_SIZE ; -if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) +if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) val |=MTK_QTX_SCH_LEAKY_BUCKET_EN ;mtk_w32 (eth, val, soc->reg_map->qdma.qtx_sch + ofs); ofs +=MTK_QTX_OFFSET ;
@@ -2573,7 +2573,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag) rxd->rxd3 =0 ; rxd->rxd4 =0 ; -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) { rxd->rxd5 =0 ; rxd->rxd6 =0 ; rxd->rxd7 =0 ;
@@ -3139,7 +3139,7 @@ static int mtk_start_dma(struct mtk_eth *eth)MTK_TX_BT_32DWORDS |MTK_NDP_CO_PRO |MTK_RX_2B_OFFSET |MTK_TX_WB_DDONE ; -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) val |=MTK_MUTLI_CNT |MTK_RESV_BUF |MTK_WCOMP_EN |MTK_DMAD_WR_WDONE |MTK_CHK_DDONE_EN |MTK_LEAKY_BUCKET_EN ;
@@ -3542,7 +3542,7 @@ static void mtk_hw_reset(struct mtk_eth *eth) {u32 val; -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) {regmap_write (eth->ethsys,ETHSYS_FE_RST_CHK_IDLE_EN ,0 ); val =RSTCTRL_PPE0_V2 ; }else {
@@ -3554,7 +3554,7 @@ static void mtk_hw_reset(struct mtk_eth *eth)ethsys_reset (eth,RSTCTRL_ETH |RSTCTRL_FE | val); -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 ))regmap_write (eth->ethsys,ETHSYS_FE_RST_CHK_IDLE_EN ,0x3ffffff ); }
@@ -3750,7 +3750,7 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset)else mtk_hw_reset (eth); -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) {/* Set FE to PDMAv2 if necessary */ val =mtk_r32 (eth,MTK_FE_GLO_MISC );mtk_w32 (eth, val |BIT (4 ),MTK_FE_GLO_MISC );
@@ -3787,7 +3787,7 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset)*/ val =mtk_r32 (eth,MTK_CDMQ_IG_CTRL );mtk_w32 (eth, val |MTK_CDMQ_STAG_EN ,MTK_CDMQ_IG_CTRL ); -if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) { val =mtk_r32 (eth,MTK_CDMP_IG_CTRL );mtk_w32 (eth, val |MTK_CDMP_STAG_EN ,MTK_CDMP_IG_CTRL ); }
drivers/net/ethernet/mediatek/mtk_eth_soc.h +26 -19
63 lines not on this page · raw message
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v13 13/16 net: ethernet: mtk_eth_soc: move MAX_DEVS in mtk_soc_data
In reply to Daniel GolleFrom: Lorenzo Bianconi <[email protected]>
This is a preliminary patch to add MT7988 SoC support since it runs 3 macs instead of 2.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 34 +++++++++++++++++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 11 +++---- 2 files changed, 36 insertions(+), 9 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +31 -3
@@ -4057,7 +4057,10 @@ static void mtk_sgmii_destroy(struct mtk_eth *eth) {int i; -for (i =0 ; i <MTK_MAX_DEVS ; i++) +if (!eth->sgmii_pcs) +return ; + +for (i =0 ; i < eth->soc->num_devs; i++)mtk_pcs_lynxi_destroy (eth->sgmii_pcs[i]); }
@@ -4516,7 +4519,12 @@ static int mtk_sgmii_init(struct mtk_eth *eth)u32 flags;int i; -for (i =0 ; i <MTK_MAX_DEVS ; i++) { + eth->sgmii_pcs =devm_kzalloc (eth->dev, +sizeof (*eth->sgmii_pcs) * + eth->soc->num_devs, +GFP_KERNEL ); + +for (i =0 ; i < eth->soc->num_devs; i++) { np =of_parse_phandle (eth->dev->of_node,"mediatek,sgmiisys" , i);if (!np)break ;
@@ -4561,6 +4569,18 @@ static int mtk_probe(struct platform_device *pdev)if (MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 )) eth->ip_align =NET_IP_ALIGN ; + eth->netdev =devm_kzalloc (eth->dev, +sizeof (*eth->netdev) * eth->soc->num_devs, +GFP_KERNEL ); +if (!eth->netdev) +return -ENOMEM ; + + eth->mac =devm_kzalloc (eth->dev, +sizeof (*eth->mac) * eth->soc->num_devs, +GFP_KERNEL ); +if (!eth->mac) +return -ENOMEM ; +spin_lock_init (ð->page_lock);spin_lock_init (ð->tx_irq_lock);spin_lock_init (ð->rx_irq_lock);
@@ -4746,7 +4766,7 @@ static int mtk_probe(struct platform_device *pdev) goto err_deinit_ppe; } -for (i =0 ; i <MTK_MAX_DEVS ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->netdev[i])continue ;
@@ -4820,6 +4840,7 @@ static const struct mtk_soc_data mt2701_data = { .hw_features = MTK_HW_FEATURES, .required_clks = MT7623_CLKS_BITMAP, .required_pctl = true, + .num_devs = 2, .txrx = { .txd_size = sizeof(struct mtk_tx_dma), .rxd_size = sizeof(struct mtk_rx_dma),
@@ -4838,6 +4859,7 @@ static const struct mtk_soc_data mt7621_data = { .required_pctl = false, .offload_version = 1, .hash_offset = 2, + .num_devs = 2, .foe_entry_size = sizeof(struct mtk_foe_entry) - 16, .txrx = { .txd_size = sizeof(struct mtk_tx_dma),
@@ -4859,6 +4881,7 @@ static const struct mtk_soc_data mt7622_data = { .offload_version = 2, .hash_offset = 2, .has_accounting = true, + .num_devs = 2, .foe_entry_size = sizeof(struct mtk_foe_entry) - 16, .txrx = { .txd_size = sizeof(struct mtk_tx_dma),
@@ -4878,6 +4901,7 @@ static const struct mtk_soc_data mt7623_data = { .required_pctl = true, .offload_version = 1, .hash_offset = 2, + .num_devs = 2, .foe_entry_size = sizeof(struct mtk_foe_entry) - 16, .txrx = { .txd_size = sizeof(struct mtk_tx_dma),
@@ -4897,6 +4921,7 @@ static const struct mtk_soc_data mt7629_data = { .required_clks = MT7629_CLKS_BITMAP, .required_pctl = false, .has_accounting = true, + .num_devs = 2, .txrx = { .txd_size = sizeof(struct mtk_tx_dma), .rxd_size = sizeof(struct mtk_rx_dma),
@@ -4918,6 +4943,7 @@ static const struct mtk_soc_data mt7981_data = { .hash_offset = 4, .foe_entry_size = sizeof(struct mtk_foe_entry), .has_accounting = true, + .num_devs = 2, .txrx = { .txd_size = sizeof(struct mtk_tx_dma_v2), .rxd_size = sizeof(struct mtk_rx_dma_v2),
@@ -4937,6 +4963,7 @@ static const struct mtk_soc_data mt7986_data = { .required_pctl = false, .offload_version = 2, .hash_offset = 4, + .num_devs = 2, .foe_entry_size = sizeof(struct mtk_foe_entry), .has_accounting = true, .txrx = {
@@ -4955,6 +4982,7 @@ static const struct mtk_soc_data rt5350_data = { .hw_features = MTK_HW_FEATURES_MT7628, .required_clks = MT7628_CLKS_BITMAP, .required_pctl = false, + .num_devs = 2, .txrx = { .txd_size = sizeof(struct mtk_tx_dma), .rxd_size = sizeof(struct mtk_rx_dma),
drivers/net/ethernet/mediatek/mtk_eth_soc.h +5 -6
@@ -1016,6 +1016,7 @@ struct mtk_reg_map {* @required_pctl A bool value to show whether the SoC requires * the extra setup for those pins used by GMAC. * @hash_offset Flow table hash offset. +* @num_devs SoC number of macs. * @foe_entry_size Foe table entry size. * @has_accounting Bool indicating support for accounting of * offloaded flows.
@@ -1034,6 +1035,7 @@ struct mtk_soc_data {bool required_pctl;u8 offload_version;u8 hash_offset; +u8 num_devs;u16 foe_entry_size;netdev_features_t hw_features;bool has_accounting;
@@ -1049,9 +1051,6 @@ struct mtk_soc_data {#define MTK_DMA_MONITOR_TIMEOUT msecs_to_jiffies(1000) -/* currently no SoC has more than 2 macs */ -#define MTK_MAX_DEVS 2 -/* struct mtk_eth - This is the main datasructure for holding the state * of the driver * @dev: The device pointer
@@ -1106,14 +1105,14 @@ struct mtk_eth {spinlock_t tx_irq_lock;spinlock_t rx_irq_lock;struct net_device dummy_dev; -struct net_device *netdev[MTK_MAX_DEVS ]; -struct mtk_mac *mac[MTK_MAX_DEVS ]; +struct net_device **netdev; +struct mtk_mac **mac;int irq[3 ];u32 msg_enable;unsigned long sysclk;struct regmap *ethsys;struct regmap *infra; -struct phylink_pcs *sgmii_pcs[MTK_MAX_DEVS ]; +struct phylink_pcs **sgmii_pcs;struct regmap *pctl;bool hwlro;refcount_t dma_refcnt;
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v13 14/16 net: ethernet: mtk_eth_soc: rely on num_devs and remove MTK_MAC_COUNT
In reply to Daniel GolleFrom: Lorenzo Bianconi <[email protected]>
Get rid of MTK_MAC_COUNT since it is a duplicated of eth->soc->num_devs.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 30 ++++++++++----------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 - 2 files changed, 15 insertions(+), 16 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +15 -15
@@ -963,7 +963,7 @@ static void mtk_stats_update(struct mtk_eth *eth) {int i; -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->mac[i] || !eth->mac[i]->hw_stats)continue ;if (spin_trylock (ð->mac[i]->hw_stats->stats_lock)) {
@@ -1468,7 +1468,7 @@ static int mtk_queue_stopped(struct mtk_eth *eth) {int i; -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->netdev[i])continue ;if (netif_queue_stopped (eth->netdev[i]))
@@ -1482,7 +1482,7 @@ static void mtk_wake_queue(struct mtk_eth *eth) {int i; -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->netdev[i])continue ;netif_tx_wake_all_queues (eth->netdev[i]);
@@ -1943,7 +1943,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, !(trxd.rxd4 & RX_DMA_SPECIAL_TAG)) mac =RX_DMA_GET_SPORT (trxd.rxd4) -1 ; -if (unlikely (mac <0 || mac >=MTK_MAC_COUNT || +if (unlikely (mac <0 || mac >= eth->soc->num_devs || !eth->netdev[mac])) goto release_desc;
@@ -2923,7 +2923,7 @@ static int mtk_set_features(struct net_device *dev, netdev_features_t features) MTK_CDMP_EG_CTRL);/* sync features with other MAC */ -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->netdev[i] || eth->netdev[i] == dev)continue ; eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX ;
@@ -3013,7 +3013,7 @@ static void mtk_dma_free(struct mtk_eth *eth)const struct mtk_soc_data *soc = eth->soc;int i; -for (i =0 ; i <MTK_MAC_COUNT ; i++) +for (i =0 ; i < soc->num_devs; i++)if (eth->netdev[i])netdev_reset_queue (eth->netdev[i]);if (eth->scratch_ring) {
@@ -3167,7 +3167,7 @@ static void mtk_gdm_config(struct mtk_eth *eth, u32 config)if (MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 ))return ; -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {u32 val =mtk_r32 (eth,MTK_GDMA_FWD_CFG (i));/* default setup the forward port to send frame to PDMA */
@@ -3771,7 +3771,7 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset)* up with the more appropriate value when mtk_mac_config call is being * invoked. */ -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {struct net_device *dev = eth->netdev[i];mtk_w32 (eth,MAC_MCR_FORCE_LINK_DOWN ,MTK_MAC_MCR (i));
@@ -3977,7 +3977,7 @@ static void mtk_pending_work(struct work_struct *work)mtk_prepare_for_reset (eth);/* stop all devices to make sure that dma is properly shut down */ -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->netdev[i] || !netif_running (eth->netdev[i]))continue ;
@@ -3993,7 +3993,7 @@ static void mtk_pending_work(struct work_struct *work)mtk_hw_init (eth, true);/* restart DMA and enable IRQs */ -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!test_bit (i, &restart))continue ;
@@ -4021,7 +4021,7 @@ static int mtk_free_dev(struct mtk_eth *eth) {int i; -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->netdev[i])continue ;free_netdev (eth->netdev[i]);
@@ -4040,7 +4040,7 @@ static int mtk_unreg_dev(struct mtk_eth *eth) {int i; -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {struct mtk_mac *mac;if (!eth->netdev[i])continue ;
@@ -4346,7 +4346,7 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) } id =be32_to_cpup (_id); -if (id >=MTK_MAC_COUNT ) { +if (id >= eth->soc->num_devs) {dev_err (eth->dev,"%d is not a valid mac id\n" , id);return -EINVAL ; }
@@ -4491,7 +4491,7 @@ void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev)rtnl_lock (); -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) { dev = eth->netdev[i];if (!dev || !(dev->flags &IFF_UP ))
@@ -4815,7 +4815,7 @@ static int mtk_remove(struct platform_device *pdev)int i;/* stop all devices to make sure that dma is properly shut down */ -for (i =0 ; i <MTK_MAC_COUNT ; i++) { +for (i =0 ; i < eth->soc->num_devs; i++) {if (!eth->netdev[i])continue ;mtk_stop (eth->netdev[i]);
drivers/net/ethernet/mediatek/mtk_eth_soc.h +0 -1
@@ -33,7 +33,6 @@#define MTK_TX_DMA_BUF_LEN_V2 0xffff#define MTK_QDMA_RING_SIZE 2048#define MTK_DMA_SIZE 512 -#define MTK_MAC_COUNT 2#define MTK_RX_ETH_HLEN (ETH_HLEN + ETH_FCS_LEN)#define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)#define MTK_DMA_DUMMY_DESC 0xffffffff
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v13 15/16 net: ethernet: mtk_eth_soc: add MTK_NETSYS_V3 capability bit
In reply to Daniel GolleFrom: Lorenzo Bianconi <[email protected]>
Introduce MTK_NETSYS_V3 bit in the device capabilities. This is a preliminary patch to introduce support for MT7988 SoC.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 115 ++++++++++++++++---- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 44 +++++++- 2 files changed, 134 insertions(+), 25 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +92 -23
@@ -943,17 +943,32 @@ void mtk_stats_update_mac(struct mtk_mac *mac)mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x20 + offs); hw_stats->rx_flow_control_packets +=mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x24 + offs); - hw_stats->tx_skip += -mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x28 + offs); - hw_stats->tx_collisions += -mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x2c + offs); - hw_stats->tx_bytes += -mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x30 + offs); - stats =mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x34 + offs); -if (stats) - hw_stats->tx_bytes += (stats <<32 ); - hw_stats->tx_packets += -mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x38 + offs); + +if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V3 )) { + hw_stats->tx_skip += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x50 + offs); + hw_stats->tx_collisions += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x54 + offs); + hw_stats->tx_bytes += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x40 + offs); + stats =mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x44 + offs); +if (stats) + hw_stats->tx_bytes += (stats <<32 ); + hw_stats->tx_packets += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x48 + offs); + }else { + hw_stats->tx_skip += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x28 + offs); + hw_stats->tx_collisions += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x2c + offs); + hw_stats->tx_bytes += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x30 + offs); + stats =mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x34 + offs); +if (stats) + hw_stats->tx_bytes += (stats <<32 ); + hw_stats->tx_packets += +mtk_r32 (mac->hw, reg_map->gdm1_cnt +0x38 + offs); + } }u64_stats_update_end (&hw_stats->syncp);
@@ -1257,7 +1272,10 @@ static void mtk_tx_set_dma_desc_v2(struct net_device *dev, void *txd, data |=TX_DMA_LS0 ;WRITE_ONCE (desc->txd3, data); - data = (mac->id +1 ) <<TX_DMA_FPORT_SHIFT_V2 ;/* forward port */ +if (mac->id ==MTK_GMAC3_ID ) + data =PSE_GDM3_PORT ; +else + data = (mac->id +1 ) <<TX_DMA_FPORT_SHIFT_V2 ;/* forward port */ data |=TX_DMA_SWC_V2 |QID_BITS_V2 (info->qid);WRITE_ONCE (desc->txd4, data);
@@ -1268,6 +1286,9 @@ static void mtk_tx_set_dma_desc_v2(struct net_device *dev, void *txd,/* tx checksum offload */ if (info->csum) data |=TX_DMA_CHKSUM_V2 ; +if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V3 ) && +netdev_uses_dsa (dev)) + data |=TX_DMA_SPTAG_V3 ; }WRITE_ONCE (desc->txd5, data);
@@ -1333,8 +1354,13 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,mtk_tx_set_dma_desc (dev, itxd, &txd_info); itx_buf->flags |=MTK_TX_FLAGS_SINGLE0 ; - itx_buf->flags |= (!mac->id) ?MTK_TX_FLAGS_FPORT0 : -MTK_TX_FLAGS_FPORT1 ; +if (mac->id ==MTK_GMAC1_ID ) + itx_buf->flags |=MTK_TX_FLAGS_FPORT0 ; +else if (mac->id ==MTK_GMAC2_ID ) + itx_buf->flags |=MTK_TX_FLAGS_FPORT1 ; +else + itx_buf->flags |=MTK_TX_FLAGS_FPORT2 ; +setup_tx_buf (eth, itx_buf, itxd_pdma, txd_info.addr, txd_info.size, k++);
@@ -1382,8 +1408,13 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,memset (tx_buf,0 ,sizeof (*tx_buf)); tx_buf->data = (void *)MTK_DMA_DUMMY_DESC ; tx_buf->flags |=MTK_TX_FLAGS_PAGE0 ; - tx_buf->flags |= (!mac->id) ?MTK_TX_FLAGS_FPORT0 : -MTK_TX_FLAGS_FPORT1 ; + +if (mac->id ==MTK_GMAC1_ID ) + tx_buf->flags |=MTK_TX_FLAGS_FPORT0 ; +else if (mac->id ==MTK_GMAC2_ID ) + tx_buf->flags |=MTK_TX_FLAGS_FPORT1 ; +else + tx_buf->flags |=MTK_TX_FLAGS_FPORT2 ;setup_tx_buf (eth, tx_buf, txd_pdma, txd_info.addr, txd_info.size, k++);
@@ -1937,11 +1968,24 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,break ;/* find out which mac the packet come from. values start at 1 */ -if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) - mac =RX_DMA_GET_SPORT_V2 (trxd.rxd5) -1 ; -else if (!MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 ) && - !(trxd.rxd4 &RX_DMA_SPECIAL_TAG )) +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V1 )) { +u32 val =RX_DMA_GET_SPORT_V2 (trxd.rxd5); + +switch (val) { +case PSE_GDM1_PORT : +case PSE_GDM2_PORT : + mac = val -1 ; +break ; +case PSE_GDM3_PORT : + mac =MTK_GMAC3_ID ; +break ; +default : +break ; + } + }else if (!MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 ) && + !(trxd.rxd4 &RX_DMA_SPECIAL_TAG )) { mac =RX_DMA_GET_SPORT (trxd.rxd4) -1 ; + }if (unlikely (mac <0 || mac >= eth->soc->num_devs || !eth->netdev[mac]))
@@ -2187,7 +2231,9 @@ static int mtk_poll_tx_qdma(struct mtk_eth *eth, int budget, tx_buf =mtk_desc_to_tx_buf (ring, desc, eth->soc->txrx.txd_size);if (tx_buf->flags &MTK_TX_FLAGS_FPORT1 ) - mac =1 ; + mac =MTK_GMAC2_ID ; +else if (tx_buf->flags &MTK_TX_FLAGS_FPORT2 ) + mac =MTK_GMAC3_ID ;if (!tx_buf->data)break ;
@@ -3810,7 +3856,26 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset)mtk_w32 (eth, eth->soc->txrx.rx_irq_done_mask, reg_map->qdma.int_grp +4 );mtk_w32 (eth,0x21021000 ,MTK_FE_INT_GRP ); -if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { +if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V3 )) { +/* PSE should not drop port1, port8 and port9 packets */ +mtk_w32 (eth,0x00000302 ,PSE_DROP_CFG ); + +/* GDM and CDM Threshold */ +mtk_w32 (eth,0x00000707 ,MTK_CDMW0_THRES ); +mtk_w32 (eth,0x00000077 ,MTK_CDMW1_THRES ); + +/* Disable GDM1 RX CRC stripping */ + val =mtk_r32 (eth,MTK_GDMA_FWD_CFG (0 )); + val &= ~MTK_GDMA_STRP_CRC ; +mtk_w32 (eth, val,MTK_GDMA_FWD_CFG (0 )); + +/* PSE GDM3 MIB counter has incorrect hw default values, +* so the driver ought to read clear the values beforehand +* in case ethtool retrieve wrong mib values. +*/ +for (i =0 ; i <0x80 ; i +=0x4 ) +mtk_r32 (eth, reg_map->gdm1_cnt +0x100 + i); + }else if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) {/* PSE should not drop port8 and port9 packets from WDMA Tx */ mtk_w32 (eth,0x00000300 ,PSE_DROP_CFG );
@@ -4383,7 +4448,11 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) }spin_lock_init (&mac->hw_stats->stats_lock);u64_stats_init (&mac->hw_stats->syncp); - mac->hw_stats->reg_offset = id *MTK_STAT_OFFSET ; + +if (MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V3 )) + mac->hw_stats->reg_offset = id *0x80 ; +else + mac->hw_stats->reg_offset = id *0x40 ;/* phylink create */ err =of_get_phy_mode (np, &phy_mode);
drivers/net/ethernet/mediatek/mtk_eth_soc.h +42 -2
86 lines not on this page · raw message
Signature · 1 line
2.39.2
Daniel Golle
maintainerPATCH v13 16/16 net: ethernet: mtk_eth_soc: convert caps in mtk_soc_data struct to u64
In reply to Daniel GolleFrom: Lorenzo Bianconi <[email protected]>
This is a preliminary patch to introduce support for MT7988 SoC.
--- drivers/net/ethernet/mediatek/mtk_eth_path.c | 22 ++++++++++---------- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_path.c +11 -11
@@ -15,10 +15,10 @@struct mtk_eth_muxc {const char *name;int cap_bit; -int (*set_path)(struct mtk_eth *eth,int path); +int (*set_path)(struct mtk_eth *eth,u64 path); }; -static const char *mtk_eth_path_name (int path) +static const char *mtk_eth_path_name (u64 path) {switch (path) {case MTK_ETH_PATH_GMAC1_RGMII :
@@ -40,7 +40,7 @@ static const char *mtk_eth_path_name(int path) } } -static int set_mux_gdm1_to_gmac1_esw (struct mtk_eth *eth,int path) +static int set_mux_gdm1_to_gmac1_esw (struct mtk_eth *eth,u64 path) {bool updated = true;u32 val, mask, set;
@@ -71,7 +71,7 @@ static int set_mux_gdm1_to_gmac1_esw(struct mtk_eth *eth, int path)return 0 ; } -static int set_mux_gmac2_gmac0_to_gephy (struct mtk_eth *eth,int path) +static int set_mux_gmac2_gmac0_to_gephy (struct mtk_eth *eth,u64 path) {unsigned int val =0 ;bool updated = true;
@@ -94,7 +94,7 @@ static int set_mux_gmac2_gmac0_to_gephy(struct mtk_eth *eth, int path)return 0 ; } -static int set_mux_u3_gmac2_to_qphy (struct mtk_eth *eth,int path) +static int set_mux_u3_gmac2_to_qphy (struct mtk_eth *eth,u64 path) {unsigned int val =0 , mask =0 , reg =0 ;bool updated = true;
@@ -125,7 +125,7 @@ static int set_mux_u3_gmac2_to_qphy(struct mtk_eth *eth, int path)return 0 ; } -static int set_mux_gmac1_gmac2_to_sgmii_rgmii (struct mtk_eth *eth,int path) +static int set_mux_gmac1_gmac2_to_sgmii_rgmii (struct mtk_eth *eth,u64 path) {unsigned int val =0 ;bool updated = true;
@@ -163,7 +163,7 @@ static int set_mux_gmac1_gmac2_to_sgmii_rgmii(struct mtk_eth *eth, int path)return 0 ; } -static int set_mux_gmac12_to_gephy_sgmii (struct mtk_eth *eth,int path) +static int set_mux_gmac12_to_gephy_sgmii (struct mtk_eth *eth,u64 path) {unsigned int val =0 ;bool updated = true;
@@ -218,7 +218,7 @@ static const struct mtk_eth_muxc mtk_eth_muxc[] = { }, }; -static int mtk_eth_mux_setup (struct mtk_eth *eth,int path) +static int mtk_eth_mux_setup (struct mtk_eth *eth,u64 path) {int i, err =0 ;
@@ -249,7 +249,7 @@ static int mtk_eth_mux_setup(struct mtk_eth *eth, int path)int mtk_gmac_sgmii_path_setup (struct mtk_eth *eth,int mac_id) { -int path; +u64 path; path = (mac_id ==0 ) ?MTK_ETH_PATH_GMAC1_SGMII :MTK_ETH_PATH_GMAC2_SGMII ;
@@ -260,7 +260,7 @@ int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id)int mtk_gmac_gephy_path_setup (struct mtk_eth *eth,int mac_id) { -int path =0 ; +u64 path =0 ;if (mac_id ==1 ) path =MTK_ETH_PATH_GMAC2_GEPHY ;
@@ -274,7 +274,7 @@ int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id)int mtk_gmac_rgmii_path_setup (struct mtk_eth *eth,int mac_id) { -int path; +u64 path; path = (mac_id ==0 ) ?MTK_ETH_PATH_GMAC1_RGMII :MTK_ETH_PATH_GMAC2_RGMII ;
drivers/net/ethernet/mediatek/mtk_eth_soc.h +1 -1
@@ -1069,7 +1069,7 @@ struct mtk_reg_map {struct mtk_soc_data {const struct mtk_reg_map *reg_map;u32 ana_rgc3; -u32 caps; +u64 caps;u32 required_clks;bool required_pctl;u8 offload_version;
Signature · 1 line
2.39.2
Aw: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
In reply to Daniel GolleHi,
have tested Parts 1-11 this on BananaPi-R3 (mt7986) with 1000Base-X Fibre SFP (no 2g5 available yet) on gmac1 and lan4 (mt7531 p5)
Thx Daniel for working on SFP support :)
regards Frank
Aw: [PATCH net-next v13 10/16] net: ethernet: mtk_eth_soc: switch to external PCS driver
In reply to Daniel GolleHi,
have tested Parts 1-11 this on bananapi-r3 (mt7986) with 1G Fiber SFP (no 2g5 available yet) on gmac1 and lan4 (mt7531 p5)
Thx Daniel for working on SFP support :)
regards Frank
Jakub Kicinski
maintainerQuoted 5 lines · On Thu, 9 Mar 2023 10:54:23 +0000 Daniel Golle 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.
Also prepare support for MT7988 which has been done while net-next was closed.
The netdev review queue is too long for me to comprehend, since the discussion is still ongoing on v12 (even tho seemingly tangential) I'll drop this, please repost once conclusion is reached.
Jakub Kicinski
maintainerRe: [PATCH net-next v13 16/16] net: ethernet: mtk_eth_soc: convert caps in mtk_soc_data struct to u64
In reply to Daniel GolleQuoted 3 lines · On Thu, 9 Mar 2023 10:58:58 +0000 Daniel Golle wrote:
From: Lorenzo Bianconi <[email protected]>
This is a preliminary patch to introduce support for MT7988 SoC.
When posting v14 please do us a favor and withhold this patch.
It looks like the series doesn't need it and the limit on patches in one series is 15.
Re: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
In reply to Daniel GolleQuoted 314 lines · Daniel Golle
Implement regmap access wrappers, for now only to be used by the pcs-mtk driver.
Make use of external PCS driver and drop the 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]>Tested-by Frank Wunderlich <[email protected]>--- 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 +24
-207@@ -14,6 +14,7 @@#include <linux/of_mdio.h> #include <linux/of_net.h> #include <linux/of_platform.h> +#include <linux/pcs/pcs-mtk-lynxi.h> #include <linux/phylink.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> @@ -2567,128 +2568,11 @@ static int mt7531_rgmii_setup(struct mt7530_priv *priv, u32 port,return 0 ; } -static void mt7531_pcs_link_up (struct phylink_pcs *pcs,unsigned int mode, -phy_interface_t interface,int speed,int duplex) -{ -struct mt7530_priv *priv =pcs_to_mt753x_pcs (pcs)->priv; -int port =pcs_to_mt753x_pcs (pcs)->port; -unsigned int val; - -/* For adjusting speed and duplex of SGMII force mode. */ -if (interface !=PHY_INTERFACE_MODE_SGMII || -phylink_autoneg_inband (mode)) -return ; - -/* SGMII force mode setting */ - val =mt7530_read (priv,MT7531_SGMII_MODE (port)); - val &= ~MT7531_SGMII_IF_MODE_MASK ; - -switch (speed) { -case SPEED_10 : - val |=MT7531_SGMII_FORCE_SPEED_10 ; -break ; -case SPEED_100 : - val |=MT7531_SGMII_FORCE_SPEED_100 ; -break ; -case SPEED_1000 : - val |=MT7531_SGMII_FORCE_SPEED_1000 ; -break ; - } - -/* MT7531 SGMII 1G force mode can only work in full duplex mode, -* no matter MT7531_SGMII_FORCE_HALF_DUPLEX is set or not. -* -* The speed check is unnecessary as the MAC capabilities apply -* this restriction. --rmk -*/ -if ((speed ==SPEED_10 || speed ==SPEED_100 ) && - duplex !=DUPLEX_FULL ) - val |=MT7531_SGMII_FORCE_HALF_DUPLEX ; - -mt7530_write (priv,MT7531_SGMII_MODE (port), val); -} -static bool mt753x_is_mac_port (u32 port) {return (port ==5 || port ==6 ); } -static int mt7531_sgmii_setup_mode_force (struct mt7530_priv *priv,u32 port, -phy_interface_t interface) -{ -u32 val; - -if (!mt753x_is_mac_port (port)) -return -EINVAL ; - -mt7530_set (priv,MT7531_QPHY_PWR_STATE_CTRL (port), -MT7531_SGMII_PHYA_PWD ); - - val =mt7530_read (priv,MT7531_PHYA_CTRL_SIGNAL3 (port)); - val &= ~MT7531_RG_TPHY_SPEED_MASK ; -/* Setup 2.5 times faster clock for 2.5Gbps data speeds with 10B/8B -* encoding. -*/ - val |= (interface ==PHY_INTERFACE_MODE_2500BASEX ) ? -MT7531_RG_TPHY_SPEED_3_125G :MT7531_RG_TPHY_SPEED_1_25G ; -mt7530_write (priv,MT7531_PHYA_CTRL_SIGNAL3 (port), val); - -mt7530_clear (priv,MT7531_PCS_CONTROL_1 (port),MT7531_SGMII_AN_ENABLE ); - -/* MT7531 SGMII 1G and 2.5G force mode can only work in full duplex -* mode, no matter MT7531_SGMII_FORCE_HALF_DUPLEX is set or not. -*/ -mt7530_rmw (priv,MT7531_SGMII_MODE (port), -MT7531_SGMII_IF_MODE_MASK |MT7531_SGMII_REMOTE_FAULT_DIS , -MT7531_SGMII_FORCE_SPEED_1000 ); - -mt7530_write (priv,MT7531_QPHY_PWR_STATE_CTRL (port),0 ); - -return 0 ; -} - -static int mt7531_sgmii_setup_mode_an (struct mt7530_priv *priv,int port, -phy_interface_t interface) -{ -if (!mt753x_is_mac_port (port)) -return -EINVAL ; - -mt7530_set (priv,MT7531_QPHY_PWR_STATE_CTRL (port), -MT7531_SGMII_PHYA_PWD ); - -mt7530_rmw (priv,MT7531_PHYA_CTRL_SIGNAL3 (port), -MT7531_RG_TPHY_SPEED_MASK ,MT7531_RG_TPHY_SPEED_1_25G ); - -mt7530_set (priv,MT7531_SGMII_MODE (port), -MT7531_SGMII_REMOTE_FAULT_DIS | -MT7531_SGMII_SPEED_DUPLEX_AN ); - -mt7530_rmw (priv,MT7531_PCS_SPEED_ABILITY (port), -MT7531_SGMII_TX_CONFIG_MASK ,1 ); - -mt7530_set (priv,MT7531_PCS_CONTROL_1 (port),MT7531_SGMII_AN_ENABLE ); - -mt7530_set (priv,MT7531_PCS_CONTROL_1 (port),MT7531_SGMII_AN_RESTART ); - -mt7530_write (priv,MT7531_QPHY_PWR_STATE_CTRL (port),0 ); - -return 0 ; -} - -static void mt7531_pcs_an_restart (struct phylink_pcs *pcs) -{ -struct mt7530_priv *priv =pcs_to_mt753x_pcs (pcs)->priv; -int port =pcs_to_mt753x_pcs (pcs)->port; -u32 val; - -/* Only restart AN when AN is enabled */ - val =mt7530_read (priv,MT7531_PCS_CONTROL_1 (port)); -if (val &MT7531_SGMII_AN_ENABLE ) { - val |=MT7531_SGMII_AN_RESTART ; -mt7530_write (priv,MT7531_PCS_CONTROL_1 (port), val); - } -} -static int mt7531_mac_config (struct dsa_switch *ds,int port,unsigned int mode,phy_interface_t interface)@@ -2711,11 +2595,11 @@ mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode, phydev = dp->slave->phydev;return mt7531_rgmii_setup (priv, port, interface, phydev);case PHY_INTERFACE_MODE_SGMII : -return mt7531_sgmii_setup_mode_an (priv, port, interface);case PHY_INTERFACE_MODE_NA :case PHY_INTERFACE_MODE_1000BASEX :case PHY_INTERFACE_MODE_2500BASEX : -return mt7531_sgmii_setup_mode_force (priv, port, interface); +/* handled in SGMII PCS driver */ +return 0 ;default :return -EINVAL ; }@@ -2740,11 +2624,11 @@ mt753x_phylink_mac_select_pcs(struct dsa_switch *ds, int port,switch (interface) {case PHY_INTERFACE_MODE_TRGMII : +return &priv->pcs[port].pcs;case PHY_INTERFACE_MODE_SGMII :case PHY_INTERFACE_MODE_1000BASEX :case PHY_INTERFACE_MODE_2500BASEX : -return &priv->pcs[port].pcs; - +return priv->ports[port].sgmii_pcs;default :return NULL ; }@@ -2982,86 +2866,6 @@ static void mt7530_pcs_get_state(struct phylink_pcs *pcs, state->pause |=MLO_PAUSE_TX ; } -static int -mt7531_sgmii_pcs_get_state_an (struct mt7530_priv *priv,int port, -struct phylink_link_state *state) -{ -u32 status, val; -u16 config_reg; - - status =mt7530_read (priv,MT7531_PCS_CONTROL_1 (port)); - state->link = !!(status &MT7531_SGMII_LINK_STATUS ); - state->an_complete = !!(status &MT7531_SGMII_AN_COMPLETE ); -if (state->interface ==PHY_INTERFACE_MODE_SGMII && - (status &MT7531_SGMII_AN_ENABLE )) { - val =mt7530_read (priv,MT7531_PCS_SPEED_ABILITY (port)); - config_reg = val >>16 ; - -switch (config_reg &LPA_SGMII_SPD_MASK ) { -case LPA_SGMII_1000 : - state->speed =SPEED_1000 ; -break ; -case LPA_SGMII_100 : - state->speed =SPEED_100 ; -break ; -case LPA_SGMII_10 : - state->speed =SPEED_10 ; -break ; -default : -dev_err (priv->dev,"invalid sgmii PHY speed\n" ); - state->link = false; -return -EINVAL ; - } - -if (config_reg &LPA_SGMII_FULL_DUPLEX ) - state->duplex =DUPLEX_FULL ; -else - state->duplex =DUPLEX_HALF ; - } - -return 0 ; -} - -static void -mt7531_sgmii_pcs_get_state_inband (struct mt7530_priv *priv,int port, -struct phylink_link_state *state) -{ -unsigned int val; - - val =mt7530_read (priv,MT7531_PCS_CONTROL_1 (port)); - state->link = !!(val &MT7531_SGMII_LINK_STATUS ); -if (!state->link) -return ; - - state->an_complete = state->link; - -if (state->interface ==PHY_INTERFACE_MODE_2500BASEX ) - state->speed =SPEED_2500 ; -else - state->speed =SPEED_1000 ; - - state->duplex =DUPLEX_FULL ; - state->pause =MLO_PAUSE_NONE ; -} - -static void mt7531_pcs_get_state (struct phylink_pcs *pcs, -struct phylink_link_state *state) -{ -struct mt7530_priv *priv =pcs_to_mt753x_pcs (pcs)->priv; -int port =pcs_to_mt753x_pcs (pcs)->port; - -if (state->interface ==PHY_INTERFACE_MODE_SGMII ) { -mt7531_sgmii_pcs_get_state_an (priv, port, state); -return ; - }else if ((state->interface ==PHY_INTERFACE_MODE_1000BASEX ) || - (state->interface ==PHY_INTERFACE_MODE_2500BASEX )) { -mt7531_sgmii_pcs_get_state_inband (priv, port, state); -return ; - } - - state->link = false; -} - static int mt753x_pcs_config(struct phylink_pcs *pcs, unsigned int mode, phy_interface_t interface, const unsigned long *advertising,@@ -3081,18 +2885,57 @@ static const struct phylink_pcs_ops mt7530_pcs_ops = { .pcs_an_restart = mt7530_pcs_an_restart, }; -static const struct phylink_pcs_ops mt7531_pcs_ops = { - .pcs_validate = mt753x_pcs_validate, - .pcs_get_state = mt7531_pcs_get_state, - .pcs_config = mt753x_pcs_config, - .pcs_an_restart = mt7531_pcs_an_restart, - .pcs_link_up = mt7531_pcs_link_up, +static int mt7530_regmap_read (void *context,unsigned int reg,unsigned int *val) +{ +struct mt7530_priv *priv = context; + + *val =mt7530_read (priv, reg); +return 0 ; +}; + +static int mt7530_regmap_write (void *context,unsigned int reg,unsigned int val) +{ +struct mt7530_priv *priv = context; + +mt7530_write (priv, reg, val); +return 0 ; +}; + +static int mt7530_regmap_update_bits (void *context,unsigned int reg, +unsigned int mask,unsigned int val) +{
drivers/net/dsa/mt7530.c static const struct phylink_pcs_ops mt7530_pcs_ops = { · line 2916
Quoted 10 lines
drivers/net/dsa/mt7530.c +10
-0+struct mt7530_priv *priv = context; + +mt7530_rmw (priv, reg, mask, val); +return 0 ; +}; + +static const struct regmap_bus mt7531_regmap_bus = { + .reg_write = mt7530_regmap_write, + .reg_read = mt7530_regmap_read, + .reg_update_bits = mt7530_regmap_update_bits,
These new functions can be used for both switches, mt7530 and mt7531, correct? If so, I believe they are supposed to be called mt753x since 88bdef8be9f6 ("net: dsa: mt7530: Extend device data ready for adding a new hardware").
mt753x: functions that can be used for mt7530 and mt7531 switches.
mt7530: functions specific to mt7530 switch.
mt7531: functions specific to mt7531 switch.
Arınç
Daniel Golle
maintainerRe: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
Quoted 26 lines · Arınç ÜNAL
Quoted 25 lines · Daniel Golle
[...]
drivers/net/dsa/mt7530.c +24
-0+static int mt7530_regmap_read (void *context,unsigned int reg,unsigned int *val) +{ +struct mt7530_priv *priv = context; + + *val =mt7530_read (priv, reg); +return 0 ; +}; + +static int mt7530_regmap_write (void *context,unsigned int reg,unsigned int val) +{ +struct mt7530_priv *priv = context; + +mt7530_write (priv, reg, val); +return 0 ; +}; + +static int mt7530_regmap_update_bits (void *context,unsigned int reg, +unsigned int mask,unsigned int val) +{ +struct mt7530_priv *priv = context; + +mt7530_rmw (priv, reg, mask, val); +return 0 ; +};
Quoted 8 lines
drivers/net/dsa/mt7530.c static const struct phylink_pcs_ops mt7530_pcs_ops = { · line 2916
Quoted 5 lines
drivers/net/dsa/mt7530.c +5
-0+ +static const struct regmap_bus mt7531_regmap_bus = { + .reg_write = mt7530_regmap_write, + .reg_read = mt7530_regmap_read, + .reg_update_bits = mt7530_regmap_update_bits,These new functions can be used for both switches, mt7530 and mt7531, correct?
In theory, yes, they could be used on all switch ICs supported by the mt7530.c driver. In practise they are used on MT7531 only because MT7530 and MT7621 don't have any SGMII/SerDes ports, but only MT7531 does.
Quoted 7 lines
If so, I believe they are supposed to be called mt753x since
88bdef8be9f6("net: dsa: mt7530: Extend device data ready for adding a new hardware").mt753x: functions that can be used for mt7530 and mt7531 switches.
mt7530: functions specific to mt7530 switch.
mt7531: functions specific to mt7531 switch.
Good catch, so mt7530_* is for sure not accurate. I used that naming due to existing function names mt7530_read, mt7530_write and mt7530_rmw.
Given the situation I've explained above I think that mt753x_* would be the best and I will change that for v14.
Thank you for reviewing!
Daniel
Re: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
Quoted 45 lines · Daniel Golle
Quoted 26 lines · Arınç ÜNAL
Quoted 25 lines · Daniel Golle
[...]
drivers/net/dsa/mt7530.c +24
-0+static int mt7530_regmap_read (void *context,unsigned int reg,unsigned int *val) +{ +struct mt7530_priv *priv = context; + + *val =mt7530_read (priv, reg); +return 0 ; +}; + +static int mt7530_regmap_write (void *context,unsigned int reg,unsigned int val) +{ +struct mt7530_priv *priv = context; + +mt7530_write (priv, reg, val); +return 0 ; +}; + +static int mt7530_regmap_update_bits (void *context,unsigned int reg, +unsigned int mask,unsigned int val) +{ +struct mt7530_priv *priv = context; + +mt7530_rmw (priv, reg, mask, val); +return 0 ; +};Quoted 8 lines
drivers/net/dsa/mt7530.c static const struct phylink_pcs_ops mt7530_pcs_ops = { · line 2916
Quoted 5 lines
drivers/net/dsa/mt7530.c +5
-0+ +static const struct regmap_bus mt7531_regmap_bus = { + .reg_write = mt7530_regmap_write, + .reg_read = mt7530_regmap_read, + .reg_update_bits = mt7530_regmap_update_bits,These new functions can be used for both switches, mt7530 and mt7531, correct?
In theory, yes, they could be used on all switch ICs supported by the
mt7530.cdriver. In practise they are used on MT7531 only because MT7530 and MT7621 don't have any SGMII/SerDes ports, but only MT7531 does.Quoted 4 lines
If so, I believe they are supposed to be called mt753x since
88bdef8be9f6("net: dsa: mt7530: Extend device data ready for adding a new hardware").
Quoted 6 lines
Quoted 3 lines
mt753x: functions that can be used for mt7530 and mt7531 switches.
mt7530: functions specific to mt7530 switch.
mt7531: functions specific to mt7531 switch.Good catch, so mt7530_* is for sure not accurate. I used that naming due to existing function names
mt7530_read,mt7530_writeandmt7530_rmw.
I was going to send a mail to netdev mailing list to ask for opinions whether we should rename the mt7530 DSA driver to mt753x and rename these functions you mentioned to mt753x so it's crystal clear what code is for what hardware. Now that we glossed over it here, I guess I can ask it here instead.
Quoted 5 lines
Given the situation I've explained above I think that mt753x_* would be the best and I will change that for v14.
Thank you for reviewing!
Sounds good, cheers.
Arınç
Re: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
Quoted 5 lines · Arınç ÜNAL
I was going to send a mail to netdev mailing list to ask for opinions whether we should rename the mt7530 DSA driver to mt753x and rename these functions you mentioned to mt753x so it's crystal clear what code is for what hardware. Now that we glossed over it here, I guess I can ask it here instead.
My 2 cents - make your first 100 useful commits on this driver, which at the very least produce a change in the compiled output, and then go on a renaming spree as much as you want.
Re: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
Quoted 10 lines · Vladimir Oltean
Quoted 5 lines · Arınç ÜNAL
I was going to send a mail to netdev mailing list to ask for opinions whether we should rename the mt7530 DSA driver to mt753x and rename these functions you mentioned to mt753x so it's crystal clear what code is for what hardware. Now that we glossed over it here, I guess I can ask it here instead.
My 2 cents - make your first 100 useful commits on this driver, which at the very least produce a change in the compiled output, and then go on a renaming spree as much as you want.
Look, I don't ask for renaming just for the sake of renaming things. I see a benefit which would make things clearer.
If you rather mean to, know the driver very well, by saying do 100 useful commits on the driver beforehand, that makes sense. But I think I'm capable of managing this. I've got the time and energy.
Arınç
Re: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
Quoted 6 lines · Arınç ÜNAL
Look, I don't ask for renaming just for the sake of renaming things. I see a benefit which would make things clearer.
If you rather mean to, know the driver very well, by saying do 100 useful commits on the driver beforehand, that makes sense. But I think I'm capable of managing this. I've got the time and energy.
I'm absolutely sure that you're capable of renaming mt7530 to mt753x, that's outside the question. That change can be made without even paying too much attention to the code, which is exactly the problem. If the proposal is to touch mt7530_read(), mt7530_write(), mt7530_rmw() (which it seems to be), then that's pretty much the entire driver.
Sorry for being skeptical by default, but generally such refactoring is done by people who have the commitment to stay around when shit hits the fan. Think of it as minimizing the time wasted by others due to that refactoring. That could be time spent by reviewers looking at the code being changed while trying to identify latent bugs; could be time spent by someone who fixes a bug that doesn't backport all the way to stable kernels because it conflicts with the refactoring. Ideally, after a large refactoring, you would be sufficiently active to find and fix bugs before others do, and have an eye for problematic code. Respectfully, you still need to prove all these things. It also helps a lot if you build a working relationship with the driver maintainers, or if you gain their trust and become a maintainer yourself. Otherwise, more work will just fall on the shoulders of fallback maintainers who don't have the hardware. If there is a self-sustaining development community and they take care of everything, I really have zero problems with large refactoring done even by newbies. But the mt7530 maintainers have gone pretty silent as of late, and I, as a fallback maintainer with no hardware, have had to send 2 bug fixes to the mt7530 and 1 to the mtk_eth_soc driver in the past month, to address the reports. Give me a reason not to refuse more potential work :)
It's great that you have the time and energy, but with the symbolic 100 commits I just meant: start somewhere else within the driver, build the experience, the knowledge of the development process and the appreciation for the existing code structure.
Russell King (Oracle)
reviewerRe: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
Quoted 4 lines · Vladimir Oltean
But the mt7530 maintainers have gone
pretty silent as of late, and I, as a fallback maintainer with no hardware, have had to send 2 bug fixes to the mt7530 and 1 to themtk_eth_socdriver in the past month, to address the reports.
That's an under-statement, and not just the DSA driver, but the ethernet driver too. It's been years trying to get the attention of anyone to sort out the pre-March 2020 crud in this driver, and no one seems to care, and none of the alleged maintainers bother replying.
I don't believe anyone who claims to be a maintainer for either the DSA or Ethernet driver has commented on any of my patches or provided any review.
In my mind, these drivers do not have maintainers.
What I have to resort to is spotting potential victims^wtesters on the mailing lists to try stuff out for me - which is really not how this should work.
It seems to me that this is the old "chuck code over the wall into mainline, then do a runner" approach to kernel maintenance.
So, honestly, the sooner these drivers get proper maintainers, the better - and if someone wants to step up to do that amongst those who are involved in the current work, I'm all for that - it would be a hell of a lot better than the current situation.
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!
Re: [PATCH net-next v13 11/16] net: dsa: mt7530: use external PCS driver
In reply to Vladimir OlteanQuoted 26 lines · Vladimir Oltean
Quoted 6 lines · Arınç ÜNAL
Look, I don't ask for renaming just for the sake of renaming things. I see a benefit which would make things clearer.
If you rather mean to, know the driver very well, by saying do 100 useful commits on the driver beforehand, that makes sense. But I think I'm capable of managing this. I've got the time and energy.
I'm absolutely sure that you're capable of renaming mt7530 to mt753x, that's outside the question. That change can be made without even paying too much attention to the code, which is exactly the problem. If the proposal is to touch
mt7530_read(),mt7530_write(),mt7530_rmw()(which it seems to be), then that's pretty much the entire driver.Sorry for being skeptical by default, but generally such refactoring is done by people who have the commitment to stay around when shit hits the fan. Think of it as minimizing the time wasted by others due to that refactoring. That could be time spent by reviewers looking at the code being changed while trying to identify latent bugs; could be time spent by someone who fixes a bug that doesn't backport all the way to stable kernels because it conflicts with the refactoring. Ideally, after a large refactoring, you would be sufficiently active to find and fix bugs before others do, and have an eye for problematic code. Respectfully, you still need to prove all these things. It also helps a lot if you build a working relationship with the driver maintainers, or if you gain their trust and become a maintainer yourself. Otherwise, more work will
Quoted 8 lines
just fall on the shoulders of fallback maintainers who don't have the hardware. If there is a self-sustaining development community and they take care of everything, I really have zero problems with large refactoring done even by newbies. But the mt7530 maintainers have gone pretty silent as of late, and I, as a fallback maintainer with no hardware, have had to send 2 bug fixes to the mt7530 and 1 to the
mtk_eth_socdriver in the past month, to address the reports. Give me a reason not to refuse more potential work :)
Now, I can find bugs if it's something that would appear on a daily use of the hardware, like those bugfixes you mentioned which I reported to you. I'm not confident in fixing them myself (yet!) due to my very slowly learning C but I'm willing to stick around for years to come so who knows what happens in a few years. I already do keep an eye on a very small problematic code at least.
I can be around as a maintainer to help backporting bugfixes that wouldn't apply cleanly due to my refactoring. So I don't add more workload to fallback maintainers like yourself. But that's all I can promise to maintain for now, not because of availability but experience, or rather the lack thereof.
Arınç