net: phy: Add driver for Motorcomm Quad 2.5GbE phy
Subsystems (5)
v18 cover net: phy: Add driver for Motorcomm Quad 2.5GbE phy
changes in v18:
1. Split the template_testmode() into a small patch and optimize the implementation.
2. Optimize the definition and initialization of interface_mode by adopting the existing approach.
changes in v17:
patch 1: Remove redundant description.
Use phy-mode instead of motorcomm,interface to describe the interface.
Add the required checks.
patch 2: Use phy-mode to get interface mode.
Need return after init configuration is done to avoid falling into the error path.
changes in v16:
1. Add DTS documentation.
2. Fix redundant initialization.
changes in v14:
1. Refactor the error return path to preserve and return the initial error, rather than letting later errors mask it.
changes in v13:
1. Fix the lock release issue on the error path to prevent potential deadlock or resource leak.
2. Add a func yt8824_restore_defaults() to restore configuration on the error path,ensuring the hardware/device is left in a known good state upon failure.
changes in v12:
1. Refactor the yt8824_read_status() function to ensure proper state synchronization between hardware registers and the phy_device structure.
changes in v11:
1. Clean build_clang warning.
changes in v10:
1. Within the interface that swaps to the USXGMII reg space,the lock include shared_lock and mdio mutex must remain held throughout the entire operation and should only be released after all steps have completed.
2. Improve the template interface in phy-c45.c
3. Fix the handling of some failure paths.
changes in v9:
1. Add shared_lock mutex prevents UTPs from interfering with each other due to swapping reg space.
change in v8:
1. Clean up format warning.
2. Fix exception handling code logic based on Sashiko/Gemini.
3. Remove interrupt/handle function
changes in v7:
1. Refactor the using of mdio lock
In all cases of swapping to the USXGMII side interface, lock the MDIO bus at the beginning, switch to the UTP address space after the operation is completed, and then release the lock.The purpose of doing this is to ensure that it will not affect other UTPs operating in the UTP address space.
2. Rename YT8824_RSSR_FIBER_SPACE to YT8824_RSSR_USXGMII_SPACE.
changes in v6:
1. Add test mode helper in phy-c45.c
2. Refactor the using of swapping paged for utp and fiber
changes in v5:
1. Fix diffs issue which caused by unexpected whitespace.
2. Fix "exceeding 80 columns" warning.
changes in v4:
1. Remove motorcomm,yt8xxx.yaml, will update in other patch thread
2. Fix locking issue. Since every interface requires switching of space, the bus is already locked during the space switching process in phy_select_page(), other operations within the interface cannot be locked again before unlock in phy_restore_page().
3. Fix warning log identified during the inspection process using checkpatch.pl.
4. Fix the way of using common api in phy_package.c
changes in v3:
1. Using common apis defined in phy_package.c to handle shared top extend register space.
2. Add dts demo in motorcomm,yt8xxx.yaml.
3. Fix unnecessary redundant judgments.
4. Fix BMCR registers operation using magic number.
5. Rename function based on its approximate functionality.
changes in v2:
1. Remove duplicate code and replace it with existing api.
Kyle Switch (3):
dt-bindings: net: Document Motorcomm YT8824 PHY package
net: phy: Add support for Template Control register for PMA
net: phy: Add driver for Motorcomm Quad 2.5GbE phy
.../bindings/net/motorcomm,yt8824.yaml | 59 + drivers/net/phy/Kconfig | 3 +- drivers/net/phy/motorcomm.c | 1571 ++++++++++++++++- drivers/net/phy/phy-c45.c | 24 + include/linux/phy.h | 1 + include/uapi/linux/mdio.h | 12 + 6 files changed, 1667 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Signature · 1 line
2.25.1
PATCH v18 2/3 net: phy: Add support for Template Control register for PMA
Add support for the 10GBASE-T PMA Template Test Mode register field, which allows selecting one of eight test modes (Normal and TestMode1..TestMode7) used for PHY validation.
--- drivers/net/phy/phy-c45.c | 24 ++++++++++++++++++++++++ include/linux/phy.h | 1 + include/uapi/linux/mdio.h | 12 ++++++++++++ 3 files changed, 37 insertions(+)
drivers/net/phy/phy-c45.c +24 -0
@@ -1408,6 +1408,30 @@ int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) }EXPORT_SYMBOL_GPL (genphy_c45_fast_retrain); +/** +* genphy_c45_template_testmode - configure template testmode registers +* @phydev: target phy_device struct +* @test_mode: testmode includes Normal to Test mode 7 +* +* Description: Set template testmode include Normal to Test mode 7 +* +* Return: 0 on success, or a negative error code on failure (e.g. register +* read/write error). +*/ +int genphy_c45_template_testmode (struct phy_device *phydev,int test_mode) +{ +int ctrl; + +if (test_mode <MDIO_PMA_10GBT_TESTMODE_NORMAL || + test_mode >MDIO_PMA_10GBT_TESTMODE_7 ) +return -EOPNOTSUPP ; + + ctrl =FIELD_PREP (MDIO_PMA_10GBT_TESTMODE_MASK , test_mode); +return phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,MDIO_PMA_10GBT_TESTMODE , +MDIO_PMA_10GBT_TESTMODE_MASK , ctrl); +} +EXPORT_SYMBOL_GPL (genphy_c45_template_testmode); +/** * genphy_c45_plca_get_cfg - get PLCA configuration from standard registers * @phydev: target phy_device struct
include/linux/phy.h +1 -0
@@ -2357,6 +2357,7 @@ int genphy_c45_loopback(struct phy_device *phydev, bool enable, int speed);int genphy_c45_pma_resume (struct phy_device *phydev);int genphy_c45_pma_suspend (struct phy_device *phydev);int genphy_c45_fast_retrain (struct phy_device *phydev,bool enable); +int genphy_c45_template_testmode (struct phy_device *phydev,int test_mode);int genphy_c45_plca_get_cfg (struct phy_device *phydev,struct phy_plca_cfg *plca_cfg); int genphy_c45_plca_set_cfg(struct phy_device *phydev,
include/uapi/linux/mdio.h +12 -0
@@ -63,6 +63,7 @@/* Media-dependent registers. */ #define MDIO_PMA_10GBT_SWAPPOL 130/* 10GBASE-T pair swap & polarity */ #define MDIO_PMA_10GBT_TXPWR 131/* 10GBASE-T TX power control */ +#define MDIO_PMA_10GBT_TESTMODE 132/* Test mode control */ #define MDIO_PMA_10GBT_SNR 133/* 10GBASE-T SNR margin, lane A. * Lanes B-D are numbered 134-136. */ #define MDIO_PMA_10GBR_FSRT_CSR 147/* 10GBASE-R fast retrain status and control */
@@ -320,6 +321,17 @@/* PMA 10GBASE-R Fast Retrain status and control register. */ #define MDIO_PMA_10GBR_FSRT_ENABLE 0x0001/* Fast retrain enable */ +/* PMA 10GBASE-T Template Test Mode Register*/ +#define MDIO_PMA_10GBT_TESTMODE_MASK GENMASK(15, 13)/* Template test mode */ +#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0/* Template Normal */ +#define MDIO_PMA_10GBT_TESTMODE_1 0x1/* Template TestMode1 */ +#define MDIO_PMA_10GBT_TESTMODE_2 0x2/* Template TestMode2 */ +#define MDIO_PMA_10GBT_TESTMODE_3 0x3/* Template TestMode3 */ +#define MDIO_PMA_10GBT_TESTMODE_4 0x4/* Template TestMode4 */ +#define MDIO_PMA_10GBT_TESTMODE_5 0x5/* Template TestMode5 */ +#define MDIO_PMA_10GBT_TESTMODE_6 0x6/* Template TestMode6 */ +#define MDIO_PMA_10GBT_TESTMODE_7 0x7/* Template TestMode7 */ +/* PCS 10GBASE-R/-T status register 1. */ #define MDIO_PCS_10GBRT_STAT1_BLKLK 0x0001/* Block lock attained */
Signature · 1 line
2.25.1
PATCH v18 3/3 net: phy: Add driver for Motorcomm Quad 2.5GbE phy
In reply to Kyle SwitchAdd support for Motorcomm YT8824 quad-port 2.5G PHY to the existing motorcomm driver, using the phy_package helpers for the shared top extended register space
--- drivers/net/phy/Kconfig | 3 +- drivers/net/phy/motorcomm.c | 1571 ++++++++++++++++++++++++++++++++++- 2 files changed, 1571 insertions(+), 3 deletions(-)
drivers/net/phy/Kconfig +2 -1
@@ -361,9 +361,10 @@ config MICROSEMI_PHY config MOTORCOMM_PHY tristate "Motorcomm PHYs" + select PHY_PACKAGE help Enables support for Motorcomm network PHYs. - Currently supports YT85xx Gigabit Ethernet PHYs. + Currently supports YT85xx Gigabit Ethernet PHYs and YT8824 4 * 2.5G PHY. config NATIONAL_PHY tristate "National Semiconductor PHYs"
drivers/net/phy/motorcomm.c +1569 -2
1,648 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v18 1/3 dt-bindings: net: Document Motorcomm YT8824 PHY package
In reply to Kyle SwitchMotorcomm YT8824 Ethernet PHY is PHY package of 4 PHY-s.
--- .../bindings/net/motorcomm,yt8824.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml
Documentation/devicetree/bindings/net/motorcomm,yt8824.yaml new file +59 -0
@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/motorcomm,yt8824.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MotorComm YT8824 Ethernet PHY + +maintainers: + - Kyle Switch <[email protected]> + +description: + Motorcomm YT8824 Ethernet PHY is a PHY package of 4 PHYs. + +$ref: ethernet-phy-package.yaml# + +properties: + compatible: + enum: + - motorcomm,yt8824-package + +required: + - compatible + - phy-mode + - reg + +unevaluatedProperties: false + +examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy-package@0 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "motorcomm,yt8824-package"; + reg = <9>; + + phy-mode = "internal"; + + ethernet-phy@4 { + reg = <4>; + }; + + ethernet-phy@5 { + reg = <5>; + }; + + ethernet-phy@6 { + reg = <6>; + }; + + ethernet-phy@7 { + reg = <7>; + }; + }; + };
Signature · 1 line
2.25.1
Re: [PATCH net-next v18 1/3] dt-bindings: net: Document Motorcomm YT8824 PHY package
Quoted 3 lines · Kyle Switch
Motorcomm YT8824 Ethernet PHY is PHY package of 4 PHY-s.
Signed-off-by Kyle Switch <[email protected]>
I already asked you to Cc the right addresses. That was two months ago. I don't understand why can't you just use tools which do all this correctly, but repeating same feedback and expecting different results is pointless, so shortly:
NAK
Longer explanation below.
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.
You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.
Please kindly resend and include all necessary To/Cc entries.
Best regards,
Krzysztof
Andrew Lunn
maintainerRe: [PATCH net-next v18 2/3] net: phy: Add support for Template Control register for PMA
In reply to Kyle Switchdrivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1423
Quoted 13 lines
drivers/net/phy/phy-c45.c +13
-0+/** +* genphy_c45_template_testmode - configure template testmode registers +* @phydev: target phy_device struct +* @test_mode: testmode includes Normal to Test mode 7 +* +* Description: Set template testmode include Normal to Test mode 7 +* +* Return: 0 on success, or a negative error code on failure (e.g. register +* read/write error). +*/ +int genphy_c45_template_testmode (struct phy_device *phydev,int test_mode) +{ +int ctrl;
I would suggest test_mode is a u16, or at least an unsigned type. ctrl should be a u16, since phy_modify_mmd() and phy_write() etc take a u16.
drivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1427
Quoted 4 lines
drivers/net/phy/phy-c45.c +4
-0+ +if (test_mode <MDIO_PMA_10GBT_TESTMODE_NORMAL || + test_mode >MDIO_PMA_10GBT_TESTMODE_7 ) +return -EOPNOTSUPP ;
And once test_mode is unsigned, you don't need to test if its is less than 0.
Andrew
---
pw-bot: cr
Andrew Lunn
maintainerQuoted 5 lines
+ *
yt8824_utp_invalid_test_mode_paged()- config YT8824 to invalid test mode.
+ * @phydev: a pointer to a &structphy_device
+ *
+ * Returns: 0 or negative errno code
+ */
drivers/net/phy/motorcomm.c static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) · line 786
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+static int yt8824_utp_invalid_test_mode_paged (struct phy_device *phydev) +{ +int ret; + + ret =phy8824_page_write_with_lock (phydev,YT8824_RSSR_UTP_SPACE ); +if (ret <0 ) +return ret; + +return genphy_c45_template_testmode + (phydev,MDIO_PMA_10GBT_TESTMODE_1 );
MDIO_PMA_10GBT_TESTMODE_1 is defined by 802.3. How can it be invalid?
Is the description wrong, and this hardware does not support test mode 1?
Andrew
Andrew Lunn
maintainerdrivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 4626
Quoted 4 lines
drivers/net/phy/motorcomm.c +4
-0+ res =of_get_phy_mode (np, &priv->interface_mode); +if (res <0 ) { +phydev_warn (phydev,"%s, phy-mode missing in DTS.\n" , __func__); + priv->interface_mode =PHY_INTERFACE_MODE_INTERNAL ;
In the binding you say phy-mode is a required property. So if it is missing, it should be a fatal error.
Andrew
Re: [PATCH net-next v18 1/3] dt-bindings: net: Document Motorcomm YT8824 PHY package
In reply to Krzysztof KozlowskiQuoted 26 lines · Krzysztof Kozlowski
Quoted 3 lines · Kyle Switch
Motorcomm YT8824 Ethernet PHY is PHY package of 4 PHY-s.
Signed-off-by Kyle Switch <[email protected]>I already asked you to Cc the right addresses. That was two months ago. I don't understand why can't you just use tools which do all this correctly, but repeating same feedback and expecting different results is pointless, so shortly:
NAK
Longer explanation below.
Please use
scripts/get_maintainers.plto get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.Tools like b4 or
scripts/get_maintainer.plprovide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember aboutb4 prep --auto-to-ccif you added new patches to the patchset.
Quoted 5 lines
You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.
Please kindly resend and include all necessary To/Cc entries.
Ans: sorry for this, it will be done ASAP.
Quoted 2 lines
Best regards,
Krzysztof
Quoted 6 lines · Andrew Lunn
drivers/net/phy/motorcomm.c static int yt8821_resume(struct phy_device *phydev) · line 4626
Quoted 4 lines
drivers/net/phy/motorcomm.c +4
-0+ res =of_get_phy_mode (np, &priv->interface_mode); +if (res <0 ) { +phydev_warn (phydev,"%s, phy-mode missing in DTS.\n" , __func__); + priv->interface_mode =PHY_INTERFACE_MODE_INTERNAL ;In the binding you say phy-mode is a required property. So if it is missing, it should be a fatal error.
Ans: I had considered this issue before submitting the patch.
Between using a default value and returning an exception,
the code currently chooses to provide a default. This will be
changed to return an fatal error in a later version.
Quoted 2 lines
Andrew
Quoted 17 lines · Andrew Lunn
Quoted 5 lines
+ *
yt8824_utp_invalid_test_mode_paged()- config YT8824 to invalid test mode.
+ * @phydev: a pointer to a &structphy_device
+ *
+ * Returns: 0 or negative errno code
+ */drivers/net/phy/motorcomm.c static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) · line 786
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+static int yt8824_utp_invalid_test_mode_paged (struct phy_device *phydev) +{ +int ret; + + ret =phy8824_page_write_with_lock (phydev,YT8824_RSSR_UTP_SPACE ); +if (ret <0 ) +return ret; + +return genphy_c45_template_testmode + (phydev,MDIO_PMA_10GBT_TESTMODE_1 );
MDIO_PMA_10GBT_TESTMODE_1is defined by 802.3. How can it be invalid?
Quoted 2 lines
Is the description wrong, and this hardware does not support test mode 1?
Ans: What's expressed here is switching to a test mode — other modes
would work too. Here it defaults to switching to testmode1. Later on,
I'm considering either renaming the function or just renaming directly
to testmode1.
Quoted 2 lines
Andrew
Re: [PATCH net-next v18 2/3] net: phy: Add support for Template Control register for PMA
In reply to Andrew LunnQuoted 17 lines · Andrew Lunn
drivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1423
Quoted 13 lines
drivers/net/phy/phy-c45.c +13
-0+/** +* genphy_c45_template_testmode - configure template testmode registers +* @phydev: target phy_device struct +* @test_mode: testmode includes Normal to Test mode 7 +* +* Description: Set template testmode include Normal to Test mode 7 +* +* Return: 0 on success, or a negative error code on failure (e.g. register +* read/write error). +*/ +int genphy_c45_template_testmode (struct phy_device *phydev,int test_mode) +{ +int ctrl;I would suggest
test_modeis a u16, or at least an unsigned type. ctrl should be a u16, sincephy_modify_mmd()andphy_write()etc take a u16.
Quoted 6 lines
drivers/net/phy/phy-c45.c int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable) · line 1427
Quoted 4 lines
drivers/net/phy/phy-c45.c +4
-0+ +if (test_mode <MDIO_PMA_10GBT_TESTMODE_NORMAL || + test_mode >MDIO_PMA_10GBT_TESTMODE_7 ) +return -EOPNOTSUPP ;And once
test_modeis unsigned, you don't need to test if its is less than 0.
Ans: okay, will be fixed in next patch.
Quoted 5 lines
Andrew
---
pw-bot: cr