From 107b14e36eaafebdc28666a9d5fecdd4044a59e3 Mon Sep 17 00:00:00 2001 From: Vladimir Oltean Date: Wed, 23 Feb 2022 15:20:55 +0200 Subject: [PATCH 01/41] net: phy: dp83867: avoid error in dp83867_of_init() when PHY has no OF node A DM_ETH driver may use phy_connect() towards a PHY address on an MDIO bus which is not specified in the device tree, as evidenced by: pfe_eth_probe -> pfe_phy_configure -> phy_connect When this happens, the PHY will have an invalid OF node. The dp83867_config() method has extra initialization steps which are bypassed when the PHY lacks an OF node, which is undesirable because it will lead to broken networking. Allow the rest of the code to run. Fixes: 085445ca4104 ("net: phy: ti: Allow the driver to be more configurable") Signed-off-by: Vladimir Oltean Reviewed-by: Ramon Fried --- drivers/net/phy/dp83867.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index eada4541c9c..49978d0f25f 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -158,7 +158,7 @@ static int dp83867_of_init(struct phy_device *phydev) node = phy_get_ofnode(phydev); if (!ofnode_valid(node)) - return -EINVAL; + return 0; /* Optional configuration */ ret = ofnode_read_u32(node, "ti,clk-output-sel", From 5faf161d07099d25fcb67f203c5576f258a11fbf Mon Sep 17 00:00:00 2001 From: Vladimir Oltean Date: Wed, 23 Feb 2022 15:20:56 +0200 Subject: [PATCH 02/41] net: phy: atheros: avoid error in ar803x_of_init() when PHY has no OF node A DM_ETH driver may use phy_connect() towards a PHY address on an MDIO bus which is not specified in the device tree, as evidenced by: pfe_eth_probe -> pfe_phy_configure -> phy_connect When this happens, the PHY will have an invalid OF node. When ar803x_config() runs, it silently fails at ar803x_of_init(), and therefore, fails to run the rest of the initialization. This makes MII_BMCR contain what it had after BMCR_RESET (0x8000) has been written into it by phy_reset(). Since BMCR_RESET is volatile and self-clearing, the MII_BMCR ends up having a value of 0x0. The further configuration of this register, which is supposed to be handled by genphy_config_aneg() lower in ar803x_config(), never gets a chance to run due to this early error from ar803x_of_init(). As a result of having MII_BMCR as 0, the following symptom appears: => setenv ethact pfe_eth0 => setenv ipaddr 10.0.0.1 => ping 10.0.0.2 pfe_eth0 Waiting for PHY auto negotiation to complete......... TIMEOUT ! Could not initialize PHY pfe_eth0 Manually writing 0x1140 into register 0 of the PHY makes the connection work, but it is rather desirable that the port works without any manual intervention. Fixes: fe6293a80959 ("phy: atheros: add device tree bindings and config") Signed-off-by: Vladimir Oltean Reviewed-by: Ramon Fried --- drivers/net/phy/atheros.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/atheros.c b/drivers/net/phy/atheros.c index f922fecd6b5..fa1fe08518f 100644 --- a/drivers/net/phy/atheros.c +++ b/drivers/net/phy/atheros.c @@ -199,7 +199,7 @@ static int ar803x_of_init(struct phy_device *phydev) node = phy_get_ofnode(phydev); if (!ofnode_valid(node)) - return -EINVAL; + return 0; priv = malloc(sizeof(*priv)); if (!priv) From e2b6cf5cadc0b71f4addbe0019f7da0c8578c194 Mon Sep 17 00:00:00 2001 From: Haolin Li Date: Sat, 19 Mar 2022 07:02:42 -0700 Subject: [PATCH 03/41] net: phy: dp83867: Fix a never true comparison The type of the return value of phy_read() and phy_read_mmd() is int. Change the variable to not be unsigned so that we not get into an unsigned compared against 0. Signed-off-by: Haolin Li Reviewed-by: Ramon Fried --- drivers/net/phy/dp83867.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index 49978d0f25f..3d862636b6b 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -266,7 +266,7 @@ static int dp83867_of_init(struct phy_device *phydev) static int dp83867_config(struct phy_device *phydev) { struct dp83867_private *dp83867; - unsigned int val, delay, cfg2; + int val, delay, cfg2; int ret, bs; dp83867 = (struct dp83867_private *)phydev->priv; @@ -291,8 +291,11 @@ static int dp83867_config(struct phy_device *phydev) if (phy_interface_is_rgmii(phydev)) { val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); - if (val < 0) + if (val < 0) { + ret = val; goto err_out; + } + val &= ~DP83867_PHYCR_FIFO_DEPTH_MASK; val |= (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT); From 6fb4482ea26e73e49ef7b77e74c81d54785d4619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:32:55 +0200 Subject: [PATCH 04/41] net: mdio-uclass: fix type for phy_mode_str and phy_handle_str MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These global variables should both have type static const char * const Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- net/mdio-uclass.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index e74e34f78f9..5735afe49e1 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -17,13 +17,14 @@ /* DT node properties for MAC-PHY interface */ #define PHY_MODE_STR_CNT 2 -static const char *phy_mode_str[PHY_MODE_STR_CNT] = { "phy-mode", - "phy-connection-type" }; +static const char * const phy_mode_str[PHY_MODE_STR_CNT] = { + "phy-mode", "phy-connection-type" +}; /* DT node properties that reference a PHY node */ #define PHY_HANDLE_STR_CNT 3 -const char *phy_handle_str[PHY_HANDLE_STR_CNT] = { "phy-handle", - "phy", - "phy-device" }; +static const char * const phy_handle_str[PHY_HANDLE_STR_CNT] = { + "phy-handle", "phy", "phy-device" +}; void dm_mdio_probe_devices(void) { From a7a96ef812976d9fa73376fa44686a1ee4af16ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:32:56 +0200 Subject: [PATCH 05/41] net: mdio-uclass: use ARRAY_SIZE() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the ARRAY_SIZE() macro instead of hardcoding sizes of arrays in macros. Signed-off-by: Marek Behún Reviewed-by: Vladimir Oltean --- net/mdio-uclass.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 5735afe49e1..649dc60f734 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -16,13 +16,12 @@ #include /* DT node properties for MAC-PHY interface */ -#define PHY_MODE_STR_CNT 2 -static const char * const phy_mode_str[PHY_MODE_STR_CNT] = { +static const char * const phy_mode_str[] = { "phy-mode", "phy-connection-type" }; + /* DT node properties that reference a PHY node */ -#define PHY_HANDLE_STR_CNT 3 -static const char * const phy_handle_str[PHY_HANDLE_STR_CNT] = { +static const char * const phy_handle_str[] = { "phy-handle", "phy", "phy-device" }; @@ -149,7 +148,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, goto out; } - for (i = 0; i < PHY_HANDLE_STR_CNT; i++) + for (i = 0; i < ARRAY_SIZE(phy_handle_str); i++) if (!dev_read_phandle_with_args(ethdev, phy_handle_str[i], NULL, 0, 0, &phandle)) break; @@ -199,7 +198,7 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) } interface = PHY_INTERFACE_MODE_NONE; - for (i = 0; i < PHY_MODE_STR_CNT; i++) { + for (i = 0; i < ARRAY_SIZE(phy_mode_str); i++) { if_str = dev_read_string(ethdev, phy_mode_str[i]); if (if_str) { interface = phy_get_interface_by_name(if_str); From f3dd213e151ece2a382e730f5e75156536b2419d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:32:57 +0200 Subject: [PATCH 06/41] net: introduce helpers to get PHY ofnode from MAC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add helpers ofnode_get_phy_node() and dev_get_phy_node() and use it in net/mdio-uclass.c function dm_eth_connect_phy_handle(). Also add corresponding UT test. This is useful because other part's of U-Boot may want to get PHY ofnode without connecting a PHY. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- arch/sandbox/dts/test.dts | 13 +++++++++++++ drivers/core/ofnode.c | 21 +++++++++++++++++++++ drivers/core/read.c | 5 +++++ include/dm/ofnode.h | 14 ++++++++++++++ include/dm/read.h | 19 +++++++++++++++++++ net/mdio-uclass.c | 24 ++++++------------------ test/dm/ofnode.c | 18 ++++++++++++++++++ 7 files changed, 96 insertions(+), 18 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 05c1cd5e1a5..e536943503d 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -530,6 +530,13 @@ fake-host-hwaddr = [00 00 66 44 22 22]; }; + phy_eth0: phy-test-eth { + compatible = "sandbox,eth"; + reg = <0x10007000 0x1000>; + fake-host-hwaddr = [00 00 66 44 22 77]; + phy-handle = <ðphy1>; + }; + dsa_eth0: dsa-test-eth { compatible = "sandbox,eth"; reg = <0x10006000 0x1000>; @@ -1555,6 +1562,12 @@ mdio: mdio-test { compatible = "sandbox,mdio"; + #address-cells = <1>; + #size-cells = <0>; + + ethphy1: ethernet-phy@1 { + reg = <1>; + }; }; pm-bus-test { diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8042847f3c1..445b7ad5add 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1198,3 +1198,24 @@ const char *ofnode_conf_read_str(const char *prop_name) return ofnode_read_string(node, prop_name); } + +ofnode ofnode_get_phy_node(ofnode node) +{ + /* DT node properties that reference a PHY node */ + static const char * const phy_handle_str[] = { + "phy-handle", "phy", "phy-device", + }; + struct ofnode_phandle_args args = { + .node = ofnode_null() + }; + int i; + + assert(ofnode_valid(node)); + + for (i = 0; i < ARRAY_SIZE(phy_handle_str); i++) + if (!ofnode_parse_phandle_with_args(node, phy_handle_str[i], + NULL, 0, 0, &args)) + break; + + return args.node; +} diff --git a/drivers/core/read.c b/drivers/core/read.c index 31f9e78a062..7ff100218d3 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -398,3 +398,8 @@ int dev_decode_display_timing(const struct udevice *dev, int index, { return ofnode_decode_display_timing(dev_ofnode(dev), index, config); } + +ofnode dev_get_phy_node(const struct udevice *dev) +{ + return ofnode_get_phy_node(dev_ofnode(dev)); +} diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 744dffe0a2d..429aee28126 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1217,4 +1217,18 @@ int ofnode_conf_read_int(const char *prop_name, int default_val); */ const char *ofnode_conf_read_str(const char *prop_name); +/** + * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link) + * + * This function parses PHY handle from the Ethernet controller's ofnode + * (trying all possible PHY handle property names), and returns the PHY ofnode. + * + * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and + * if the result to that is true, this function should not be called. + * + * @eth_node: ofnode belonging to the Ethernet controller + * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode + */ +ofnode ofnode_get_phy_node(ofnode eth_node); + #endif diff --git a/include/dm/read.h b/include/dm/read.h index 233af3c0634..899eb813fde 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -743,6 +743,20 @@ int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res); int dev_decode_display_timing(const struct udevice *dev, int index, struct display_timing *config); +/** + * dev_get_phy_node() - Get PHY node for a MAC (if not fixed-link) + * + * This function parses PHY handle from the Ethernet controller's ofnode + * (trying all possible PHY handle property names), and returns the PHY ofnode. + * + * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and + * if the result to that is true, this function should not be called. + * + * @dev: device representing the MAC + * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode + */ +ofnode dev_get_phy_node(const struct udevice *dev); + #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ #include @@ -1092,6 +1106,11 @@ static inline int dev_decode_display_timing(const struct udevice *dev, return ofnode_decode_display_timing(dev_ofnode(dev), index, config); } +static inline ofnode dev_get_phy_node(const struct udevice *dev) +{ + return ofnode_get_phy_node(dev_ofnode(dev)); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */ /** diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 649dc60f734..233b70171b5 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -20,11 +20,6 @@ static const char * const phy_mode_str[] = { "phy-mode", "phy-connection-type" }; -/* DT node properties that reference a PHY node */ -static const char * const phy_handle_str[] = { - "phy-handle", "phy", "phy-device" -}; - void dm_mdio_probe_devices(void) { struct udevice *it; @@ -137,23 +132,16 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, u32 phy_addr; struct udevice *mdiodev; struct phy_device *phy; - struct ofnode_phandle_args phandle = {.node = ofnode_null()}; ofnode phynode; - int i; if (CONFIG_IS_ENABLED(PHY_FIXED) && ofnode_phy_is_fixed_link(dev_ofnode(ethdev), &phynode)) { phy = phy_connect(NULL, 0, ethdev, interface); - phandle.node = phynode; goto out; } - for (i = 0; i < ARRAY_SIZE(phy_handle_str); i++) - if (!dev_read_phandle_with_args(ethdev, phy_handle_str[i], NULL, - 0, 0, &phandle)) - break; - - if (!ofnode_valid(phandle.node)) { + phynode = dev_get_phy_node(ethdev); + if (!ofnode_valid(phynode)) { dev_dbg(ethdev, "can't find PHY node\n"); return NULL; } @@ -162,16 +150,16 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, * reading 'reg' directly should be fine. This is a PHY node, the * address is always size 1 and requires no translation */ - if (ofnode_read_u32(phandle.node, "reg", &phy_addr)) { + if (ofnode_read_u32(phynode, "reg", &phy_addr)) { dev_dbg(ethdev, "missing reg property in phy node\n"); return NULL; } if (uclass_get_device_by_ofnode(UCLASS_MDIO, - ofnode_get_parent(phandle.node), + ofnode_get_parent(phynode), &mdiodev)) { dev_dbg(ethdev, "can't find MDIO bus for node %s\n", - ofnode_get_name(ofnode_get_parent(phandle.node))); + ofnode_get_name(ofnode_get_parent(phynode))); return NULL; } @@ -179,7 +167,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, out: if (phy) - phy->node = phandle.node; + phy->node = phynode; return phy; } diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index dab0480a42f..500c63aef5a 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -447,3 +447,21 @@ static int dm_test_ofnode_string_err(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_string_err, UT_TESTF_LIVE_TREE); + +static int dm_test_ofnode_get_phy(struct unit_test_state *uts) +{ + ofnode eth_node, phy_node; + u32 reg; + + eth_node = ofnode_path("/phy-test-eth"); + ut_assert(ofnode_valid(eth_node)); + + phy_node = ofnode_get_phy_node(eth_node); + ut_assert(ofnode_valid(phy_node)); + + reg = ofnode_read_u32_default(phy_node, "reg", -1U); + ut_asserteq_64(0x1, reg); + + return 0; +} +DM_TEST(dm_test_ofnode_get_phy, 0); From 351bfa6ebdcc454441b32976e895002a5b0523b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:32:58 +0200 Subject: [PATCH 07/41] net: mdio-uclass: add wrappers for read/write/reset operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add wrappers dm_mdio_read(), dm_mdio_write() and dm_mdio_reset() for DM MDIO's .read(), .write() and .reset() operations. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- include/miiphy.h | 31 +++++++++++++++++++++++++++++++ net/mdio-uclass.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/miiphy.h b/include/miiphy.h index 235ae066ddd..110921f20d2 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -157,6 +157,37 @@ struct mdio_ops { */ void dm_mdio_probe_devices(void); +/** + * dm_mdio_read - Wrapper over .read() operation for DM MDIO + * + * @mdiodev: mdio device + * @addr: PHY address on MDIO bus + * @devad: device address on PHY if C45; should be MDIO_DEVAD_NONE if C22 + * @reg: register address + * Return: register value if non-negative, -error code otherwise + */ +int dm_mdio_read(struct udevice *mdio_dev, int addr, int devad, int reg); + +/** + * dm_mdio_write - Wrapper over .write() operation for DM MDIO + * + * @mdiodev: mdio device + * @addr: PHY address on MDIO bus + * @devad: device address on PHY if C45; should be MDIO_DEVAD_NONE if C22 + * @reg: register address + * @val: value to write + * Return: 0 on success, -error code otherwise + */ +int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 val); + +/** + * dm_mdio_reset - Wrapper over .reset() operation for DM MDIO + * + * @mdiodev: mdio device + * Return: 0 on success, -error code otherwise + */ +int dm_mdio_reset(struct udevice *mdio_dev); + /** * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO * diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 233b70171b5..887c2281674 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -57,6 +57,37 @@ static int dm_mdio_post_bind(struct udevice *dev) return 0; } +int dm_mdio_read(struct udevice *mdio_dev, int addr, int devad, int reg) +{ + struct mdio_ops *ops = mdio_get_ops(mdio_dev); + + if (!ops->read) + return -ENOSYS; + + return ops->read(mdio_dev, addr, devad, reg); +} + +int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, + u16 val) +{ + struct mdio_ops *ops = mdio_get_ops(mdio_dev); + + if (!ops->write) + return -ENOSYS; + + return ops->write(mdio_dev, addr, devad, reg, val); +} + +int dm_mdio_reset(struct udevice *mdio_dev) +{ + struct mdio_ops *ops = mdio_get_ops(mdio_dev); + + if (!ops->reset) + return 0; + + return ops->reset(mdio_dev); +} + /* * Following read/write/reset functions are registered with legacy MII code. * These are called for PHY operations by upper layers and we further call the From 1776a24bbbb9afe9cc2a52990c1cee8c48faa20f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:32:59 +0200 Subject: [PATCH 08/41] treewide: use dm_mdio_read/write/reset() wrappers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new dm_mdio_read/write/reset() wrappers treewide, instead of always getting and dereferencing MDIO operations structure pointer. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- drivers/net/mdio_mux_sandbox.c | 6 ++---- net/mdio-mux-uclass.c | 16 ++++------------ net/mdio-uclass.c | 19 ++++--------------- test/dm/mdio.c | 18 +++++++++--------- test/dm/mdio_mux.c | 16 ++++++++-------- 5 files changed, 27 insertions(+), 48 deletions(-) diff --git a/drivers/net/mdio_mux_sandbox.c b/drivers/net/mdio_mux_sandbox.c index fff6ddb2f14..e1801c14267 100644 --- a/drivers/net/mdio_mux_sandbox.c +++ b/drivers/net/mdio_mux_sandbox.c @@ -20,7 +20,6 @@ struct mdio_mux_sandbox_priv { static int mdio_mux_sandbox_mark_selection(struct udevice *dev, int sel) { struct udevice *mdio; - struct mdio_ops *ops; int err; /* @@ -30,9 +29,8 @@ static int mdio_mux_sandbox_mark_selection(struct udevice *dev, int sel) err = uclass_get_device_by_name(UCLASS_MDIO, "mdio-test", &mdio); if (err) return err; - ops = mdio_get_ops(mdio); - return ops->write(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG_CNT - 1, (u16)sel); + return dm_mdio_write(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG_CNT - 1, (u16)sel); } static int mdio_mux_sandbox_select(struct udevice *dev, int cur, int sel) diff --git a/net/mdio-mux-uclass.c b/net/mdio-mux-uclass.c index 780526c19e3..94b90e06576 100644 --- a/net/mdio-mux-uclass.c +++ b/net/mdio-mux-uclass.c @@ -54,11 +54,6 @@ static struct udevice *mmux_get_parent_mdio(struct udevice *mux) return pdata->mdio_parent; } -static struct mdio_ops *mmux_get_mdio_parent_ops(struct udevice *mux) -{ - return mdio_get_ops(mmux_get_parent_mdio(mux)); -} - /* call driver select function before performing MDIO r/w */ static int mmux_change_sel(struct udevice *ch, bool sel) { @@ -90,14 +85,13 @@ static int mmux_read(struct udevice *ch, int addr, int devad, { struct udevice *mux = ch->parent; struct udevice *parent_mdio = mmux_get_parent_mdio(mux); - struct mdio_ops *parent_ops = mmux_get_mdio_parent_ops(mux); int err; err = mmux_change_sel(ch, true); if (err) return err; - err = parent_ops->read(parent_mdio, addr, devad, reg); + err = dm_mdio_read(parent_mdio, addr, devad, reg); mmux_change_sel(ch, false); return err; @@ -109,14 +103,13 @@ static int mmux_write(struct udevice *ch, int addr, int devad, { struct udevice *mux = ch->parent; struct udevice *parent_mdio = mmux_get_parent_mdio(mux); - struct mdio_ops *parent_ops = mmux_get_mdio_parent_ops(mux); int err; err = mmux_change_sel(ch, true); if (err) return err; - err = parent_ops->write(parent_mdio, addr, devad, reg, val); + err = dm_mdio_write(parent_mdio, addr, devad, reg, val); mmux_change_sel(ch, false); return err; @@ -127,18 +120,17 @@ static int mmux_reset(struct udevice *ch) { struct udevice *mux = ch->parent; struct udevice *parent_mdio = mmux_get_parent_mdio(mux); - struct mdio_ops *parent_ops = mmux_get_mdio_parent_ops(mux); int err; /* reset is optional, if it's not implemented just exit */ - if (!parent_ops->reset) + if (!mdio_get_ops(parent_mdio)->reset) return 0; err = mmux_change_sel(ch, true); if (err) return err; - err = parent_ops->reset(parent_mdio); + err = dm_mdio_reset(parent_mdio); mmux_change_sel(ch, false); return err; diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 887c2281674..bef8280e210 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -95,27 +95,18 @@ int dm_mdio_reset(struct udevice *mdio_dev) */ static int mdio_read(struct mii_dev *mii_bus, int addr, int devad, int reg) { - struct udevice *dev = mii_bus->priv; - - return mdio_get_ops(dev)->read(dev, addr, devad, reg); + return dm_mdio_read(mii_bus->priv, addr, devad, reg); } static int mdio_write(struct mii_dev *mii_bus, int addr, int devad, int reg, u16 val) { - struct udevice *dev = mii_bus->priv; - - return mdio_get_ops(dev)->write(dev, addr, devad, reg, val); + return dm_mdio_write(mii_bus->priv, addr, devad, reg, val); } static int mdio_reset(struct mii_dev *mii_bus) { - struct udevice *dev = mii_bus->priv; - - if (mdio_get_ops(dev)->reset) - return mdio_get_ops(dev)->reset(dev); - else - return 0; + return dm_mdio_reset(mii_bus->priv); } static int dm_mdio_post_probe(struct udevice *dev) @@ -135,10 +126,8 @@ static int dm_mdio_post_probe(struct udevice *dev) static int dm_mdio_pre_remove(struct udevice *dev) { struct mdio_perdev_priv *pdata = dev_get_uclass_priv(dev); - struct mdio_ops *ops = mdio_get_ops(dev); - if (ops->reset) - ops->reset(dev); + dm_mdio_reset(dev); mdio_unregister(pdata->mii_bus); mdio_free(pdata->mii_bus); diff --git a/test/dm/mdio.c b/test/dm/mdio.c index 64347e1275a..f863c52645b 100644 --- a/test/dm/mdio.c +++ b/test/dm/mdio.c @@ -38,18 +38,18 @@ static int dm_test_mdio(struct unit_test_state *uts) ut_assertnonnull(ops->read); ut_assertnonnull(ops->write); - ut_assertok(ops->write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG, TEST_REG_VALUE)); - reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG); + ut_assertok(dm_mdio_write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG, TEST_REG_VALUE)); + reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG); ut_asserteq(reg, TEST_REG_VALUE); - ut_assert(ops->read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG) != 0); + ut_assert(dm_mdio_read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG) != 0); - ut_assertok(ops->reset(dev)); - reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG); + ut_assertok(dm_mdio_reset(dev)); + reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG); ut_asserteq(reg, 0); return 0; diff --git a/test/dm/mdio_mux.c b/test/dm/mdio_mux.c index 950f385d17f..bfe3518221f 100644 --- a/test/dm/mdio_mux.c +++ b/test/dm/mdio_mux.c @@ -57,22 +57,22 @@ static int dm_test_mdio_mux(struct unit_test_state *uts) * is selected to the selection #. Just reading that register from * either of the child buses should return the id of the child bus */ - reg = ops->read(mdio_ch0, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG_CNT - 1); + reg = dm_mdio_read(mdio_ch0, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG_CNT - 1); ut_asserteq(reg, 0); - reg = ops->read(mdio_ch1, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG_CNT - 1); + reg = dm_mdio_read(mdio_ch1, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG_CNT - 1); ut_asserteq(reg, 1); mmops->select(mux, MDIO_MUX_SELECT_NONE, 5); - reg = ops_parent->read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG_CNT - 1); + reg = dm_mdio_read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG_CNT - 1); ut_asserteq(reg, 5); mmops->deselect(mux, 5); - reg = ops_parent->read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG_CNT - 1); + reg = dm_mdio_read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG_CNT - 1); ut_asserteq(reg, (u16)MDIO_MUX_SELECT_NONE); return 0; From 9c06b4815ce1d663085c214133762614bba79fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:00 +0200 Subject: [PATCH 09/41] net: phy: fix parsing wrong property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "phy-interface-type" property should be "phy-connection-type". Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- drivers/net/phy/phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 92fff5b72c0..c8289d38898 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -989,7 +989,7 @@ struct phy_device *fixed_phy_create(ofnode node) if_str = ofnode_read_string(node, "phy-mode"); if (!if_str) { - if_str = ofnode_read_string(node, "phy-interface-type"); + if_str = ofnode_read_string(node, "phy-connection-type"); } if (if_str) { interface = phy_get_interface_by_name(if_str); From 123ca114e07ecf28aa2538748d733e2b22d8b8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:01 +0200 Subject: [PATCH 10/41] net: introduce helpers to get PHY interface mode from a device/ofnode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add helpers ofnode_read_phy_mode() and dev_read_phy_mode() to parse the "phy-mode" / "phy-connection-type" property. Add corresponding UT test. Use them treewide. This allows us to inline the phy_get_interface_by_name() into ofnode_read_phy_mode(), since the former is not used anymore. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Tested-by: Patrice Chotard --- arch/sandbox/dts/test.dts | 1 + board/st/stm32f746-disco/stm32f746-disco.c | 13 +++----- drivers/core/ofnode.c | 23 ++++++++++++++ drivers/core/read.c | 5 +++ drivers/net/ag7xxx.c | 9 ++---- drivers/net/altera_tse.c | 11 ++----- drivers/net/bcm6348-eth.c | 6 +--- drivers/net/bcmgenet.c | 10 ++---- drivers/net/designware.c | 10 ++---- drivers/net/dwc_eth_qos.c | 36 +++------------------- drivers/net/fec_mxc.c | 11 ++----- drivers/net/fm/eth.c | 13 +------- drivers/net/fsl_enetc.c | 13 +++----- drivers/net/ftgmac100.c | 11 ++----- drivers/net/higmacv300.c | 9 ++---- drivers/net/ldpaa_eth/ldpaa_eth.c | 28 +++-------------- drivers/net/macb.c | 10 ++---- drivers/net/mt7620-eth.c | 35 +++++++-------------- drivers/net/mtk_eth.c | 8 ++--- drivers/net/mvgbe.c | 7 ++--- drivers/net/mvneta.c | 11 ++----- drivers/net/mvpp2.c | 9 ++---- drivers/net/phy/phy.c | 25 ++------------- drivers/net/pic32_eth.c | 11 ++----- drivers/net/qe/dm_qe_uec.c | 11 ++----- drivers/net/ravb.c | 15 +++------ drivers/net/sh_eth.c | 15 +++------ drivers/net/sni_ave.c | 12 ++------ drivers/net/sni_netsec.c | 10 ++---- drivers/net/sun8i_emac.c | 11 ++----- drivers/net/ti/am65-cpsw-nuss.c | 15 +++------ drivers/net/ti/cpsw.c | 10 ++---- drivers/net/ti/keystone_net.c | 24 +++++++-------- drivers/net/tsec.c | 9 ++---- drivers/net/xilinx_axi_emac.c | 10 ++---- drivers/net/zynq_gem.c | 9 ++---- include/dm/ofnode.h | 13 ++++++++ include/dm/read.h | 17 ++++++++++ include/phy.h | 8 ----- net/mdio-uclass.c | 18 +---------- test/dm/ofnode.c | 4 +++ 41 files changed, 165 insertions(+), 371 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index e536943503d..5b38ee4a5f9 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -535,6 +535,7 @@ reg = <0x10007000 0x1000>; fake-host-hwaddr = [00 00 66 44 22 77]; phy-handle = <ðphy1>; + phy-mode = "2500base-x"; }; dsa_eth0: dsa-test-eth { diff --git a/board/st/stm32f746-disco/stm32f746-disco.c b/board/st/stm32f746-disco/stm32f746-disco.c index 95d83e73ee8..69f657c54b8 100644 --- a/board/st/stm32f746-disco/stm32f746-disco.c +++ b/board/st/stm32f746-disco/stm32f746-disco.c @@ -117,16 +117,13 @@ int board_late_init(void) int board_init(void) { #ifdef CONFIG_ETH_DESIGNWARE - const char *phy_mode; - int node; + ofnode node; - node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,stm32-dwmac"); - if (node < 0) + node = ofnode_by_compatible(ofnode_null(), "st,stm32-dwmac"); + if (!ofnode_valid(node)) return -1; - phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); - - switch (phy_get_interface_by_name(phy_mode)) { + switch (ofnode_read_phy_mode(node)) { case PHY_INTERFACE_MODE_RMII: STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL; break; @@ -134,7 +131,7 @@ int board_init(void) STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL; break; default: - printf("PHY interface %s not supported !\n", phy_mode); + printf("Unsupported PHY interface!\n"); } #endif diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 445b7ad5add..f644a593d32 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1219,3 +1219,26 @@ ofnode ofnode_get_phy_node(ofnode node) return args.node; } + +phy_interface_t ofnode_read_phy_mode(ofnode node) +{ + const char *mode; + int i; + + assert(ofnode_valid(node)); + + mode = ofnode_read_string(node, "phy-mode"); + if (!mode) + mode = ofnode_read_string(node, "phy-connection-type"); + + if (!mode) + return PHY_INTERFACE_MODE_NONE; + + for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) + if (!strcmp(mode, phy_interface_strings[i])) + return i; + + debug("%s: Invalid PHY interface '%s'\n", __func__, mode); + + return PHY_INTERFACE_MODE_NONE; +} diff --git a/drivers/core/read.c b/drivers/core/read.c index 7ff100218d3..c73508d2760 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -403,3 +403,8 @@ ofnode dev_get_phy_node(const struct udevice *dev) { return ofnode_get_phy_node(dev_ofnode(dev)); } + +phy_interface_t dev_read_phy_mode(const struct udevice *dev) +{ + return ofnode_read_phy_mode(dev_ofnode(dev)); +} diff --git a/drivers/net/ag7xxx.c b/drivers/net/ag7xxx.c index 632ab3c1e5d..f24a917bd43 100644 --- a/drivers/net/ag7xxx.c +++ b/drivers/net/ag7xxx.c @@ -1254,7 +1254,6 @@ static const struct eth_ops ag7xxx_eth_ops = { static int ag7xxx_eth_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; int ret; pdata->iobase = dev_read_addr(dev); @@ -1265,13 +1264,9 @@ static int ag7xxx_eth_of_to_plat(struct udevice *dev) if (ret <= 0) return ret; - phy_mode = fdt_getprop(gd->fdt_blob, ret, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } return 0; } diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c index eb4cd96763b..25247472b03 100644 --- a/drivers/net/altera_tse.c +++ b/drivers/net/altera_tse.c @@ -676,17 +676,10 @@ static int altera_tse_probe(struct udevice *dev) static int altera_tse_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } return 0; } diff --git a/drivers/net/bcm6348-eth.c b/drivers/net/bcm6348-eth.c index 06e0dd74a5b..8f1864a334c 100644 --- a/drivers/net/bcm6348-eth.c +++ b/drivers/net/bcm6348-eth.c @@ -415,7 +415,6 @@ static int bcm6348_eth_probe(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct bcm6348_eth_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phy; - const char *phy_mode; int ret, i; /* get base address */ @@ -425,10 +424,7 @@ static int bcm6348_eth_probe(struct udevice *dev) pdata->iobase = (phys_addr_t) priv->base; /* get phy mode */ - pdata->phy_interface = PHY_INTERFACE_MODE_NONE; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -ENODEV; diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c index 67839563dbe..c6acb4932b4 100644 --- a/drivers/net/bcmgenet.c +++ b/drivers/net/bcmgenet.c @@ -690,20 +690,14 @@ static int bcmgenet_eth_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct bcmgenet_eth_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phy_node; - const char *phy_mode; int ret; pdata->iobase = dev_read_addr(dev); /* Get phy mode from DT */ - pdata->phy_interface = -1; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, &phy_node); diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 5aaac603a0e..7b7b0f65780 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -914,21 +914,15 @@ int designware_eth_of_to_plat(struct udevice *dev) struct dw_eth_dev *priv = dev_get_priv(dev); #endif struct eth_pdata *pdata = &dw_pdata->eth_pdata; - const char *phy_mode; #if CONFIG_IS_ENABLED(DM_GPIO) int reset_flags = GPIOD_IS_OUT; #endif int ret = 0; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c index 22dad5b2030..9777f6cb9c6 100644 --- a/drivers/net/dwc_eth_qos.c +++ b/drivers/net/dwc_eth_qos.c @@ -270,7 +270,7 @@ struct eqos_config { int config_mac; int config_mac_mdio; unsigned int axi_bus_width; - phy_interface_t (*interface)(struct udevice *dev); + phy_interface_t (*interface)(const struct udevice *dev); struct eqos_ops *ops; }; @@ -1729,21 +1729,7 @@ err_probe: return ret; } -static phy_interface_t eqos_get_interface_stm32(struct udevice *dev) -{ - const char *phy_mode; - phy_interface_t interface = PHY_INTERFACE_MODE_NONE; - - debug("%s(dev=%p):\n", __func__, dev); - - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - interface = phy_get_interface_by_name(phy_mode); - - return interface; -} - -static phy_interface_t eqos_get_interface_tegra186(struct udevice *dev) +static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev) { return PHY_INTERFACE_MODE_MII; } @@ -1766,20 +1752,6 @@ static int eqos_probe_resources_imx(struct udevice *dev) return 0; } -static phy_interface_t eqos_get_interface_imx(struct udevice *dev) -{ - const char *phy_mode; - phy_interface_t interface = PHY_INTERFACE_MODE_NONE; - - debug("%s(dev=%p):\n", __func__, dev); - - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - interface = phy_get_interface_by_name(phy_mode); - - return interface; -} - static int eqos_remove_resources_tegra186(struct udevice *dev) { struct eqos_priv *eqos = dev_get_priv(dev); @@ -1985,7 +1957,7 @@ static const struct eqos_config __maybe_unused eqos_stm32_config = { .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV, .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, .axi_bus_width = EQOS_AXI_WIDTH_64, - .interface = eqos_get_interface_stm32, + .interface = dev_read_phy_mode, .ops = &eqos_stm32_ops }; @@ -2013,7 +1985,7 @@ struct eqos_config __maybe_unused eqos_imx_config = { .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, .axi_bus_width = EQOS_AXI_WIDTH_64, - .interface = eqos_get_interface_imx, + .interface = dev_read_phy_mode, .ops = &eqos_imx_ops }; diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index e8ebef09032..22c2a3a30f2 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -1310,20 +1310,13 @@ static int fecmxc_of_to_plat(struct udevice *dev) int ret = 0; struct eth_pdata *pdata = dev_get_plat(dev); struct fec_priv *priv = dev_get_priv(dev); - const char *phy_mode; pdata->iobase = dev_read_addr(dev); priv->eth = (struct ethernet_regs *)pdata->iobase; - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } #ifdef CONFIG_DM_REGULATOR device_get_supply_regulator(dev, "phy-supply", &priv->phy_supply); diff --git a/drivers/net/fm/eth.c b/drivers/net/fm/eth.c index 5e0d0bca9b5..1ffe9e2b7a5 100644 --- a/drivers/net/fm/eth.c +++ b/drivers/net/fm/eth.c @@ -954,17 +954,6 @@ int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info) return 0; } #else /* CONFIG_DM_ETH */ -#ifdef CONFIG_PHYLIB -phy_interface_t fman_read_sys_if(struct udevice *dev) -{ - const char *if_str; - - if_str = ofnode_read_string(dev_ofnode(dev), "phy-connection-type"); - debug("MAC system interface mode %s\n", if_str); - - return phy_get_interface_by_name(if_str); -} -#endif static int fm_eth_bind(struct udevice *dev) { @@ -1038,7 +1027,7 @@ static int fm_eth_probe(struct udevice *dev) reg = (void *)(uintptr_t)dev_read_addr(dev); fm_eth->mac_type = dev_get_driver_data(dev); #ifdef CONFIG_PHYLIB - fm_eth->enet_if = fman_read_sys_if(dev); + fm_eth->enet_if = dev_read_phy_mode(dev); #else fm_eth->enet_if = PHY_INTERFACE_MODE_SGMII; printf("%s: warning - unable to determine interface type\n", __func__); diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c index 915c7c80256..8f5af1dbc03 100644 --- a/drivers/net/fsl_enetc.c +++ b/drivers/net/fsl_enetc.c @@ -260,9 +260,6 @@ static int enetc_init_sxgmii(struct udevice *dev) static void enetc_start_pcs(struct udevice *dev) { struct enetc_priv *priv = dev_get_priv(dev); - const char *if_str; - - priv->if_type = PHY_INTERFACE_MODE_NONE; /* register internal MDIO for debug purposes */ if (enetc_read_port(priv, ENETC_PCAPR0) & ENETC_PCAPRO_MDIO) { @@ -279,14 +276,12 @@ static void enetc_start_pcs(struct udevice *dev) return; } - if_str = ofnode_read_string(dev_ofnode(dev), "phy-mode"); - if (if_str) - priv->if_type = phy_get_interface_by_name(if_str); - else + priv->if_type = dev_read_phy_mode(dev); + if (priv->if_type == PHY_INTERFACE_MODE_NONE) { enetc_dbg(dev, "phy-mode property not found, defaulting to SGMII\n"); - if (priv->if_type < 0) - priv->if_type = PHY_INTERFACE_MODE_NONE; + priv->if_type = PHY_INTERFACE_MODE_SGMII; + } switch (priv->if_type) { case PHY_INTERFACE_MODE_SGMII: diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c index aa719d295f3..626c27d7bf8 100644 --- a/drivers/net/ftgmac100.c +++ b/drivers/net/ftgmac100.c @@ -549,17 +549,12 @@ static int ftgmac100_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); struct ftgmac100_data *priv = dev_get_priv(dev); - const char *phy_mode; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); diff --git a/drivers/net/higmacv300.c b/drivers/net/higmacv300.c index aa79d6eda81..ce8f2dfd098 100644 --- a/drivers/net/higmacv300.c +++ b/drivers/net/higmacv300.c @@ -561,19 +561,14 @@ static int higmac_remove(struct udevice *dev) static int higmac_of_to_plat(struct udevice *dev) { struct higmac_priv *priv = dev_get_priv(dev); - int phyintf = PHY_INTERFACE_MODE_NONE; - const char *phy_mode; ofnode phy_node; priv->base = dev_remap_addr_index(dev, 0); priv->macif_ctrl = dev_remap_addr_index(dev, 1); - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - phyintf = phy_get_interface_by_name(phy_mode); - if (phyintf == PHY_INTERFACE_MODE_NONE) + priv->phyintf = dev_read_phy_mode(dev); + if (priv->phyintf == PHY_INTERFACE_MODE_NONE) return -ENODEV; - priv->phyintf = phyintf; phy_node = dev_read_subnode(dev, "phy"); if (!ofnode_valid(phy_node)) { diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c index 725173f6273..c775598b91f 100644 --- a/drivers/net/ldpaa_eth/ldpaa_eth.c +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c @@ -1120,31 +1120,14 @@ static uint32_t ldpaa_eth_get_dpmac_id(struct udevice *dev) return fdtdec_get_uint(gd->fdt_blob, port_node, "reg", -1); } -static const char *ldpaa_eth_get_phy_mode_str(struct udevice *dev) -{ - int port_node = dev_of_offset(dev); - const char *phy_mode_str; - - phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, - "phy-connection-type", NULL); - if (phy_mode_str) - return phy_mode_str; - - phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL); - return phy_mode_str; -} - static int ldpaa_eth_bind(struct udevice *dev) { - const char *phy_mode_str = NULL; uint32_t dpmac_id; char eth_name[16]; int phy_mode = -1; - phy_mode_str = ldpaa_eth_get_phy_mode_str(dev); - if (phy_mode_str) - phy_mode = phy_get_interface_by_name(phy_mode_str); - if (phy_mode == -1) { + phy_mode = dev_read_phy_mode(dev); + if (phy_mode == PHY_INTERFACE_MODE_NONE) { dev_err(dev, "incorrect phy mode\n"); return -EINVAL; } @@ -1155,7 +1138,8 @@ static int ldpaa_eth_bind(struct udevice *dev) return -EINVAL; } - sprintf(eth_name, "DPMAC%d@%s", dpmac_id, phy_mode_str); + sprintf(eth_name, "DPMAC%d@%s", dpmac_id, + phy_string_for_interface(phy_mode)); device_set_name(dev, eth_name); return 0; @@ -1164,11 +1148,9 @@ static int ldpaa_eth_bind(struct udevice *dev) static int ldpaa_eth_of_to_plat(struct udevice *dev) { struct ldpaa_eth_priv *priv = dev_get_priv(dev); - const char *phy_mode_str; priv->dpmac_id = ldpaa_eth_get_dpmac_id(dev); - phy_mode_str = ldpaa_eth_get_phy_mode_str(dev); - priv->phy_mode = phy_get_interface_by_name(phy_mode_str); + priv->phy_mode = dev_read_phy_mode(dev); return 0; } diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 37eed59a69e..317b380e8fe 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -1360,17 +1360,11 @@ static int macb_eth_probe(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct macb_device *macb = dev_get_priv(dev); struct ofnode_phandle_args phandle_args; - const char *phy_mode; int ret; - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - - if (phy_mode) - macb->phy_interface = phy_get_interface_by_name(phy_mode); - if (macb->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + macb->phy_interface = dev_read_phy_mode(dev); + if (macb->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } /* Read phyaddr from DT */ if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, diff --git a/drivers/net/mt7620-eth.c b/drivers/net/mt7620-eth.c index 222250d52ad..24fcb9373f8 100644 --- a/drivers/net/mt7620-eth.c +++ b/drivers/net/mt7620-eth.c @@ -1048,33 +1048,20 @@ static int mt7620_eth_parse_gsw_port(struct mt7620_eth_priv *priv, u32 idx, ofnode node) { ofnode subnode; - const char *str; - int mode, speed, ret; + int speed, ret; u32 phy_addr; - str = ofnode_read_string(node, "phy-mode"); - if (str) { - mode = phy_get_interface_by_name(str); - if (mode < 0) { - dev_err(priv->dev, "mt7620_eth: invalid phy-mode\n"); - return -EINVAL; - } + priv->port_cfg[idx].mode = ofnode_read_phy_mode(node); - switch (mode) { - case PHY_INTERFACE_MODE_MII: - case PHY_INTERFACE_MODE_RMII: - case PHY_INTERFACE_MODE_RGMII: - case PHY_INTERFACE_MODE_NONE: - break; - default: - dev_err(priv->dev, - "mt7620_eth: unsupported phy-mode\n"); - return -ENOTSUPP; - } - - priv->port_cfg[idx].mode = mode; - } else { - priv->port_cfg[idx].mode = PHY_INTERFACE_MODE_NONE; + switch (priv->port_cfg[idx].mode) { + case PHY_INTERFACE_MODE_MII: + case PHY_INTERFACE_MODE_RMII: + case PHY_INTERFACE_MODE_RGMII: + case PHY_INTERFACE_MODE_NONE: + break; + default: + dev_err(priv->dev, "mt7620_eth: unsupported phy-mode\n"); + return -ENOTSUPP; } subnode = ofnode_find_subnode(node, "fixed-link"); diff --git a/drivers/net/mtk_eth.c b/drivers/net/mtk_eth.c index 26f02847a2e..d6065db5fb7 100644 --- a/drivers/net/mtk_eth.c +++ b/drivers/net/mtk_eth.c @@ -1447,11 +1447,9 @@ static int mtk_eth_of_to_plat(struct udevice *dev) priv->gmac_id = dev_read_u32_default(dev, "mediatek,gmac-id", 0); /* Interface mode is required */ - str = dev_read_string(dev, "phy-mode"); - if (str) { - pdata->phy_interface = phy_get_interface_by_name(str); - priv->phy_interface = pdata->phy_interface; - } else { + pdata->phy_interface = dev_read_phy_mode(dev); + priv->phy_interface = pdata->phy_interface; + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) { printf("error: phy-mode is not set\n"); return -EINVAL; } diff --git a/drivers/net/mvgbe.c b/drivers/net/mvgbe.c index 954bf86121a..32ec0b437d3 100644 --- a/drivers/net/mvgbe.c +++ b/drivers/net/mvgbe.c @@ -993,7 +993,6 @@ static int mvgbe_of_to_plat(struct udevice *dev) struct mvgbe_device *dmvgbe = dev_get_priv(dev); void *blob = (void *)gd->fdt_blob; int node = dev_of_offset(dev); - const char *phy_mode; int fl_node; int pnode; unsigned long addr; @@ -1005,10 +1004,8 @@ static int mvgbe_of_to_plat(struct udevice *dev) "marvell,kirkwood-eth-port"); /* Get phy-mode / phy_interface from DT */ - phy_mode = fdt_getprop(gd->fdt_blob, pnode, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - else + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) pdata->phy_interface = PHY_INTERFACE_MODE_GMII; dmvgbe->phy_interface = pdata->phy_interface; diff --git a/drivers/net/mvneta.c b/drivers/net/mvneta.c index 4a4268c2b2c..d31b96a9d82 100644 --- a/drivers/net/mvneta.c +++ b/drivers/net/mvneta.c @@ -1799,20 +1799,13 @@ static const struct eth_ops mvneta_ops = { static int mvneta_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; pdata->iobase = dev_read_addr(dev); /* Get phy-mode / phy_interface from DT */ - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } return 0; } diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c index 4c0a7b0a9f5..dfddac180fd 100644 --- a/drivers/net/mvpp2.c +++ b/drivers/net/mvpp2.c @@ -4786,11 +4786,9 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port) static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) { int port_node = dev_of_offset(dev); - const char *phy_mode_str; int phy_node; u32 id; u32 phyaddr = 0; - int phy_mode = -1; int fixed_link = 0; int ret; @@ -4821,10 +4819,8 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) phyaddr = PHY_MAX_ADDR; } - phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL); - if (phy_mode_str) - phy_mode = phy_get_interface_by_name(phy_mode_str); - if (phy_mode == -1) { + port->phy_interface = dev_read_phy_mode(dev); + if (port->phy_interface == PHY_INTERFACE_MODE_NONE) { dev_err(dev, "incorrect phy mode\n"); return -EINVAL; } @@ -4847,7 +4843,6 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) port->first_rxq = port->id * rxq_number; else port->first_rxq = port->id * port->priv->max_port_rxqs; - port->phy_interface = phy_mode; port->phyaddr = phyaddr; return 0; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index c8289d38898..ba7b361c3d9 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -982,25 +982,16 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, */ struct phy_device *fixed_phy_create(ofnode node) { - phy_interface_t interface = PHY_INTERFACE_MODE_NONE; struct phy_device *phydev; - const char *if_str; ofnode subnode; - if_str = ofnode_read_string(node, "phy-mode"); - if (!if_str) { - if_str = ofnode_read_string(node, "phy-connection-type"); - } - if (if_str) { - interface = phy_get_interface_by_name(if_str); - } - subnode = ofnode_find_subnode(node, "fixed-link"); if (!ofnode_valid(subnode)) { return NULL; } - phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface); + phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, + ofnode_read_phy_mode(node)); if (phydev) phydev->node = subnode; @@ -1098,15 +1089,3 @@ int phy_shutdown(struct phy_device *phydev) return 0; } - -int phy_get_interface_by_name(const char *str) -{ - int i; - - for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) { - if (!strcmp(str, phy_interface_strings[i])) - return i; - } - - return -1; -} diff --git a/drivers/net/pic32_eth.c b/drivers/net/pic32_eth.c index 5a678d1cf95..03eb51e51d5 100644 --- a/drivers/net/pic32_eth.c +++ b/drivers/net/pic32_eth.c @@ -534,7 +534,6 @@ static int pic32_eth_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); struct pic32eth_dev *priv = dev_get_priv(dev); - const char *phy_mode; void __iomem *iobase; fdt_addr_t addr; fdt_size_t size; @@ -550,15 +549,9 @@ static int pic32_eth_probe(struct udevice *dev) pdata->iobase = (phys_addr_t)addr; /* get phy mode */ - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } /* get phy addr */ offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev), diff --git a/drivers/net/qe/dm_qe_uec.c b/drivers/net/qe/dm_qe_uec.c index a12c8cd2ac5..5a66d726cd6 100644 --- a/drivers/net/qe/dm_qe_uec.c +++ b/drivers/net/qe/dm_qe_uec.c @@ -1133,19 +1133,12 @@ static int qe_uec_remove(struct udevice *dev) static int qe_uec_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; pdata->iobase = (phys_addr_t)devfdt_get_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), - "phy-connection-type", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } return 0; } diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 4078d33bb5e..f6d386bd6b8 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -674,20 +674,13 @@ static const struct eth_ops ravb_ops = { int ravb_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; const fdt32_t *cell; - int ret = 0; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } pdata->max_speed = 1000; cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL); @@ -696,7 +689,7 @@ int ravb_of_to_plat(struct udevice *dev) sprintf(bb_miiphy_buses[0].name, dev->name); - return ret; + return 0; } static const struct udevice_id ravb_ids[] = { diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 4055f07b2fe..04c9c2d968f 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -915,20 +915,13 @@ static const struct eth_ops sh_ether_ops = { int sh_ether_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; const fdt32_t *cell; - int ret = 0; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } pdata->max_speed = 1000; cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL); @@ -937,7 +930,7 @@ int sh_ether_of_to_plat(struct udevice *dev) sprintf(bb_miiphy_buses[0].name, dev->name); - return ret; + return 0; } static const struct udevice_id sh_ether_ids[] = { diff --git a/drivers/net/sni_ave.c b/drivers/net/sni_ave.c index ab51552ed88..0a368c6d03a 100644 --- a/drivers/net/sni_ave.c +++ b/drivers/net/sni_ave.c @@ -738,7 +738,6 @@ static int ave_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct ave_private *priv = dev_get_priv(dev); struct ofnode_phandle_args args; - const char *phy_mode; const u32 *valp; int ret, nc, nr; const char *name; @@ -748,15 +747,10 @@ static int ave_of_to_plat(struct udevice *dev) return -EINVAL; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } pdata->max_speed = 0; valp = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c index 4901321d0cf..693fd3a35db 100644 --- a/drivers/net/sni_netsec.c +++ b/drivers/net/sni_netsec.c @@ -1029,19 +1029,13 @@ static int netsec_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct netsec_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phandle_args; - const char *phy_mode; pdata->iobase = dev_read_addr_index(dev, 0); priv->eeprom_base = dev_read_addr_index(dev, 1) - EERPROM_MAP_OFFSET; - pdata->phy_interface = -1; - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - pr_err("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, &phandle_args)) diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c index 2e24d122141..5654a3430e2 100644 --- a/drivers/net/sun8i_emac.c +++ b/drivers/net/sun8i_emac.c @@ -882,7 +882,6 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) struct sun8i_eth_pdata *sun8i_pdata = dev_get_plat(dev); struct eth_pdata *pdata = &sun8i_pdata->eth_pdata; struct emac_eth_dev *priv = dev_get_priv(dev); - const char *phy_mode; const fdt32_t *reg; int node = dev_of_offset(dev); int offset = 0; @@ -946,16 +945,10 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) } priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1); - phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); - - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); printf("phy interface%d\n", pdata->phy_interface); - - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } if (priv->variant == H3_EMAC) { ret = sun8i_handle_internal_phy(dev, priv); diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c index 87f51b3b99b..c1da3347395 100644 --- a/drivers/net/ti/am65-cpsw-nuss.c +++ b/drivers/net/ti/am65-cpsw-nuss.c @@ -602,21 +602,14 @@ static int am65_cpsw_ofdata_parse_phy(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct am65_cpsw_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args out_args; - const char *phy_mode; int ret = 0; dev_read_u32(dev, "reg", &priv->port_id); - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) { - pdata->phy_interface = - phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - dev_err(dev, "Invalid PHY mode '%s', port %u\n", - phy_mode, priv->port_id); - ret = -EINVAL; - goto out; - } + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) { + dev_err(dev, "Invalid PHY mode, port %u\n", priv->port_id); + return -EINVAL; } dev_read_u32(dev, "max-speed", (u32 *)&pdata->max_speed); diff --git a/drivers/net/ti/cpsw.c b/drivers/net/ti/cpsw.c index 68f4191fe97..5b7bab734e4 100644 --- a/drivers/net/ti/cpsw.c +++ b/drivers/net/ti/cpsw.c @@ -1194,15 +1194,12 @@ static void cpsw_eth_of_parse_slave(struct cpsw_platform_data *data, { struct ofnode_phandle_args out_args; struct cpsw_slave_data *slave_data; - const char *phy_mode; u32 phy_id[2]; int ret; slave_data = &data->slave_data[slave_index]; - phy_mode = ofnode_read_string(subnode, "phy-mode"); - if (phy_mode) - slave_data->phy_if = phy_get_interface_by_name(phy_mode); + slave_data->phy_if = ofnode_read_phy_mode(subnode); ret = ofnode_parse_phandle_with_args(subnode, "phy-handle", NULL, 0, 0, &out_args); @@ -1348,11 +1345,8 @@ static int cpsw_eth_of_to_plat(struct udevice *dev) } pdata->phy_interface = data->slave_data[data->active_slave].phy_if; - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, - phy_string_for_interface(pdata->phy_interface)); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } return 0; } diff --git a/drivers/net/ti/keystone_net.c b/drivers/net/ti/keystone_net.c index 5e8f683c29e..b55e7da4c18 100644 --- a/drivers/net/ti/keystone_net.c +++ b/drivers/net/ti/keystone_net.c @@ -687,7 +687,6 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave, int phy; int dma_count; u32 dma_channel[8]; - const char *phy_mode; priv->slave_port = fdtdec_get_int(fdt, slave, "slave-port", -1); priv->net_rx_buffs.rx_flow = priv->slave_port * 8; @@ -728,20 +727,19 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave, priv->sgmii_link_type = SGMII_LINK_MAC_PHY; priv->has_mdio = true; } else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) { - phy_mode = fdt_getprop(fdt, slave, "phy-mode", NULL); - if (phy_mode) { - priv->phy_if = phy_get_interface_by_name(phy_mode); - if (priv->phy_if != PHY_INTERFACE_MODE_RGMII && - priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID && - priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID && - priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) { - pr_err("invalid phy-mode\n"); - return -EINVAL; - } - } else { + priv->phy_if = ofnode_read_phy_mode(offset_to_ofnode(slave)); + if (priv->phy_if == PHY_INTERFACE_MODE_NONE) priv->phy_if = PHY_INTERFACE_MODE_RGMII; - } pdata->phy_interface = priv->phy_if; + + if (priv->phy_if != PHY_INTERFACE_MODE_RGMII && + priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID && + priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID && + priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) { + pr_err("invalid phy-mode\n"); + return -EINVAL; + } + priv->has_mdio = true; } diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index beca886b256..fec051ebb7c 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -834,7 +834,6 @@ int tsec_probe(struct udevice *dev) struct ofnode_phandle_args phandle_args; u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE; struct tsec_data *data; - const char *phy_mode; ofnode parent, child; fdt_addr_t reg; u32 max_speed; @@ -894,12 +893,8 @@ int tsec_probe(struct udevice *dev) priv->tbiaddr = tbiaddr; - phy_mode = dev_read_prop(dev, "phy-connection-type", NULL); - if (!phy_mode) - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) pdata->phy_interface = tsec_get_interface(priv); priv->interface = pdata->phy_interface; diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c index f21addb4d08..02d13c3e0ad 100644 --- a/drivers/net/xilinx_axi_emac.c +++ b/drivers/net/xilinx_axi_emac.c @@ -821,7 +821,6 @@ static int axi_emac_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = &plat->eth_pdata; int node = dev_of_offset(dev); int offset = 0; - const char *phy_mode; pdata->iobase = dev_read_addr(dev); plat->mactype = dev_get_driver_data(dev); @@ -850,14 +849,9 @@ static int axi_emac_of_to_plat(struct udevice *dev) plat->phy_of_handle = offset; } - phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - printf("%s: Invalid PHY interface '%s'\n", __func__, - phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } plat->eth_hasnobuf = fdtdec_get_bool(gd->fdt_blob, node, "xlnx,eth-hasnobuf"); diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c index 3118d147266..0062851134d 100644 --- a/drivers/net/zynq_gem.c +++ b/drivers/net/zynq_gem.c @@ -827,7 +827,6 @@ static int zynq_gem_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct zynq_gem_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phandle_args; - const char *phy_mode; pdata->iobase = (phys_addr_t)dev_read_addr(dev); priv->iobase = (struct zynq_gem_regs *)pdata->iobase; @@ -859,13 +858,9 @@ static int zynq_gem_of_to_plat(struct udevice *dev) } } - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) return -EINVAL; - } priv->interface = pdata->phy_interface; priv->int_pcs = dev_read_bool(dev, "is-internal-pcspma"); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 429aee28126..3bd3ba49253 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -12,6 +12,7 @@ #include #include #include +#include /* Enable checks to protect against invalid calls */ #undef OF_CHECKS @@ -1231,4 +1232,16 @@ const char *ofnode_conf_read_str(const char *prop_name); */ ofnode ofnode_get_phy_node(ofnode eth_node); +/** + * ofnode_read_phy_mode() - Read PHY connection type from a MAC node + * + * This function parses the "phy-mode" / "phy-connection-type" property and + * returns the corresponding PHY interface type. + * + * @mac_node: ofnode containing the property + * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on + * error + */ +phy_interface_t ofnode_read_phy_mode(ofnode mac_node); + #endif diff --git a/include/dm/read.h b/include/dm/read.h index 899eb813fde..bfa26459674 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -757,6 +757,18 @@ int dev_decode_display_timing(const struct udevice *dev, int index, */ ofnode dev_get_phy_node(const struct udevice *dev); +/** + * dev_read_phy_mode() - Read PHY connection type from a MAC + * + * This function parses the "phy-mode" / "phy-connection-type" property and + * returns the corresponding PHY interface type. + * + * @dev: device representing the MAC + * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on + * error + */ +phy_interface_t dev_read_phy_mode(const struct udevice *dev); + #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ #include @@ -1111,6 +1123,11 @@ static inline ofnode dev_get_phy_node(const struct udevice *dev) return ofnode_get_phy_node(dev_ofnode(dev)); } +static inline phy_interface_t dev_read_phy_mode(const struct udevice *dev) +{ + return ofnode_read_phy_mode(dev_ofnode(dev)); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */ /** diff --git a/include/phy.h b/include/phy.h index 9ea4bd42db4..399e050abae 100644 --- a/include/phy.h +++ b/include/phy.h @@ -568,14 +568,6 @@ int phy_xilinx_gmii2rgmii_init(void); int board_phy_config(struct phy_device *phydev); int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id); -/** - * phy_get_interface_by_name() - Look up a PHY interface name - * - * @str: PHY interface name, e.g. "mii" - * @return: PHY_INTERFACE_MODE_... value, or -1 if not found - */ -int phy_get_interface_by_name(const char *str); - /** * phy_interface_is_rgmii - Convenience function for testing if a PHY interface * is RGMII (all variants) diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index bef8280e210..874f59413a2 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -15,11 +15,6 @@ #include #include -/* DT node properties for MAC-PHY interface */ -static const char * const phy_mode_str[] = { - "phy-mode", "phy-connection-type" -}; - void dm_mdio_probe_devices(void) { struct udevice *it; @@ -195,26 +190,15 @@ out: /* Connect to a PHY linked in eth DT node */ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) { - const char *if_str; phy_interface_t interface; struct phy_device *phy; - int i; if (!dev_has_ofnode(ethdev)) { debug("%s: supplied eth dev has no DT node!\n", ethdev->name); return NULL; } - interface = PHY_INTERFACE_MODE_NONE; - for (i = 0; i < ARRAY_SIZE(phy_mode_str); i++) { - if_str = dev_read_string(ethdev, phy_mode_str[i]); - if (if_str) { - interface = phy_get_interface_by_name(if_str); - break; - } - } - if (interface < 0) - interface = PHY_INTERFACE_MODE_NONE; + interface = dev_read_phy_mode(ethdev); if (interface == PHY_INTERFACE_MODE_NONE) dev_dbg(ethdev, "can't find interface mode, default to NONE\n"); diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 500c63aef5a..61ae1db62d7 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -451,11 +451,15 @@ DM_TEST(dm_test_ofnode_string_err, UT_TESTF_LIVE_TREE); static int dm_test_ofnode_get_phy(struct unit_test_state *uts) { ofnode eth_node, phy_node; + phy_interface_t mode; u32 reg; eth_node = ofnode_path("/phy-test-eth"); ut_assert(ofnode_valid(eth_node)); + mode = ofnode_read_phy_mode(eth_node); + ut_assert(mode == PHY_INTERFACE_MODE_2500BASEX); + phy_node = ofnode_get_phy_node(eth_node); ut_assert(ofnode_valid(phy_node)); From 6706d7dcbee15ac41f3ddb50b31ff96d16567883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:02 +0200 Subject: [PATCH 11/41] treewide: Rename PHY_INTERFACE_MODE_COUNT to PHY_INTERFACE_MODE_MAX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename constant PHY_INTERFACE_MODE_COUNT to PHY_INTERFACE_MODE_MAX to make it compatible with Linux' naming. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese Reviewed-by: Vladimir Oltean --- drivers/core/ofnode.c | 2 +- drivers/net/phy/aquantia.c | 2 +- include/phy_interface.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index f644a593d32..d9ccb1bad26 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1234,7 +1234,7 @@ phy_interface_t ofnode_read_phy_mode(ofnode node) if (!mode) return PHY_INTERFACE_MODE_NONE; - for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) + for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) if (!strcmp(mode, phy_interface_strings[i])) return i; diff --git a/drivers/net/phy/aquantia.c b/drivers/net/phy/aquantia.c index 83075f78c98..7e950fe0c2f 100644 --- a/drivers/net/phy/aquantia.c +++ b/drivers/net/phy/aquantia.c @@ -305,7 +305,7 @@ struct { u16 syscfg; int cnt; u16 start_rate; -} aquantia_syscfg[PHY_INTERFACE_MODE_COUNT] = { +} aquantia_syscfg[PHY_INTERFACE_MODE_MAX] = { [PHY_INTERFACE_MODE_SGMII] = {0x04b, AQUANTIA_VND1_GSYSCFG_1G, AQUANTIA_VND1_GSTART_RATE_1G}, [PHY_INTERFACE_MODE_2500BASEX] = {0x144, AQUANTIA_VND1_GSYSCFG_2_5G, diff --git a/include/phy_interface.h b/include/phy_interface.h index f075abe9c9c..494bc87e679 100644 --- a/include/phy_interface.h +++ b/include/phy_interface.h @@ -41,7 +41,7 @@ typedef enum { PHY_INTERFACE_MODE_USXGMII, PHY_INTERFACE_MODE_NONE, /* Must be last */ - PHY_INTERFACE_MODE_COUNT, + PHY_INTERFACE_MODE_MAX, } phy_interface_t; static const char * const phy_interface_strings[] = { From ffb0f6f488b9eee2822c3c691778a26e1590694c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:03 +0200 Subject: [PATCH 12/41] treewide: Rename PHY_INTERFACE_MODE_NONE to PHY_INTERFACE_MODE_NA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename constant PHY_INTERFACE_MODE_NONE to PHY_INTERFACE_MODE_NA to make it compatible with Linux' naming. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- board/freescale/corenet_ds/eth_hydra.c | 2 +- board/freescale/corenet_ds/eth_superhydra.c | 4 ++-- board/freescale/t104xrdb/eth.c | 4 ++-- drivers/core/ofnode.c | 4 ++-- drivers/net/ag7xxx.c | 2 +- drivers/net/altera_tse.c | 2 +- drivers/net/bcm6348-eth.c | 2 +- drivers/net/bcmgenet.c | 2 +- drivers/net/designware.c | 2 +- drivers/net/dwc_eth_qos.c | 4 ++-- drivers/net/fec_mxc.c | 2 +- drivers/net/fm/b4860.c | 8 ++++---- drivers/net/fm/init.c | 8 ++++---- drivers/net/fm/ls1043.c | 6 +++--- drivers/net/fm/ls1046.c | 8 ++++---- drivers/net/fm/p1023.c | 4 ++-- drivers/net/fm/p4080.c | 6 +++--- drivers/net/fm/p5020.c | 6 +++--- drivers/net/fm/p5040.c | 6 +++--- drivers/net/fm/t1024.c | 4 ++-- drivers/net/fm/t1040.c | 4 ++-- drivers/net/fm/t2080.c | 6 +++--- drivers/net/fm/t4240.c | 6 +++--- drivers/net/fsl_enetc.c | 2 +- drivers/net/ftgmac100.c | 2 +- drivers/net/higmacv300.c | 2 +- drivers/net/ldpaa_eth/ldpaa_eth.c | 2 +- drivers/net/ldpaa_eth/ldpaa_wriop.c | 10 +++++----- drivers/net/ldpaa_eth/ls1088a.c | 4 ++-- drivers/net/ldpaa_eth/ls2080a.c | 4 ++-- drivers/net/ldpaa_eth/lx2160a.c | 4 ++-- drivers/net/macb.c | 2 +- drivers/net/mscc_eswitch/jr2_switch.c | 2 +- drivers/net/mscc_eswitch/luton_switch.c | 2 +- drivers/net/mscc_eswitch/ocelot_switch.c | 2 +- drivers/net/mscc_eswitch/serval_switch.c | 2 +- drivers/net/mscc_eswitch/servalt_switch.c | 2 +- drivers/net/mt7620-eth.c | 12 ++++++------ drivers/net/mtk_eth.c | 2 +- drivers/net/mvgbe.c | 2 +- drivers/net/mvneta.c | 2 +- drivers/net/mvpp2.c | 2 +- drivers/net/pic32_eth.c | 2 +- drivers/net/qe/dm_qe_uec.c | 2 +- drivers/net/ravb.c | 2 +- drivers/net/sh_eth.c | 2 +- drivers/net/sni_ave.c | 2 +- drivers/net/sni_netsec.c | 2 +- drivers/net/sun8i_emac.c | 2 +- drivers/net/ti/am65-cpsw-nuss.c | 2 +- drivers/net/ti/cpsw.c | 2 +- drivers/net/ti/keystone_net.c | 2 +- drivers/net/tsec.c | 2 +- drivers/net/xilinx_axi_emac.c | 2 +- drivers/net/zynq_gem.c | 2 +- include/dm/ofnode.h | 2 +- include/dm/read.h | 2 +- include/fm_eth.h | 2 +- include/phy_interface.h | 8 ++++---- include/vsc9953.h | 2 +- net/mdio-uclass.c | 4 ++-- 61 files changed, 105 insertions(+), 105 deletions(-) diff --git a/board/freescale/corenet_ds/eth_hydra.c b/board/freescale/corenet_ds/eth_hydra.c index 6500c2fcf67..a27e905ace9 100644 --- a/board/freescale/corenet_ds/eth_hydra.c +++ b/board/freescale/corenet_ds/eth_hydra.c @@ -471,7 +471,7 @@ int board_eth_init(struct bd_info *bis) fm_info_set_mdio(i, miiphy_get_dev_by_name("HYDRA_RGMII_MDIO")); break; - case PHY_INTERFACE_MODE_NONE: + case PHY_INTERFACE_MODE_NA: fm_info_set_phy_address(i, 0); break; default: diff --git a/board/freescale/corenet_ds/eth_superhydra.c b/board/freescale/corenet_ds/eth_superhydra.c index de7b692f3fe..55bac0f7615 100644 --- a/board/freescale/corenet_ds/eth_superhydra.c +++ b/board/freescale/corenet_ds/eth_superhydra.c @@ -583,7 +583,7 @@ int board_eth_init(struct bd_info *bis) fm_info_set_mdio(i, miiphy_get_dev_by_name("SUPER_HYDRA_RGMII_MDIO")); break; - case PHY_INTERFACE_MODE_NONE: + case PHY_INTERFACE_MODE_NA: fm_info_set_phy_address(i, 0); break; default: @@ -733,7 +733,7 @@ int board_eth_init(struct bd_info *bis) fm_info_set_mdio(i, miiphy_get_dev_by_name("SUPER_HYDRA_RGMII_MDIO")); break; - case PHY_INTERFACE_MODE_NONE: + case PHY_INTERFACE_MODE_NA: fm_info_set_phy_address(i, 0); break; default: diff --git a/board/freescale/t104xrdb/eth.c b/board/freescale/t104xrdb/eth.c index b034f11d68a..3ae5d722aab 100644 --- a/board/freescale/t104xrdb/eth.c +++ b/board/freescale/t104xrdb/eth.c @@ -89,7 +89,7 @@ int board_eth_init(struct bd_info *bis) case PHY_INTERFACE_MODE_QSGMII: fm_info_set_phy_address(i, 0); break; - case PHY_INTERFACE_MODE_NONE: + case PHY_INTERFACE_MODE_NA: fm_info_set_phy_address(i, 0); break; default: @@ -99,7 +99,7 @@ int board_eth_init(struct bd_info *bis) break; } if (fm_info_get_enet_if(i) == PHY_INTERFACE_MODE_QSGMII || - fm_info_get_enet_if(i) == PHY_INTERFACE_MODE_NONE) + fm_info_get_enet_if(i) == PHY_INTERFACE_MODE_NA) fm_info_set_mdio(i, NULL); else fm_info_set_mdio(i, diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index d9ccb1bad26..a59832ebbfb 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1232,7 +1232,7 @@ phy_interface_t ofnode_read_phy_mode(ofnode node) mode = ofnode_read_string(node, "phy-connection-type"); if (!mode) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) if (!strcmp(mode, phy_interface_strings[i])) @@ -1240,5 +1240,5 @@ phy_interface_t ofnode_read_phy_mode(ofnode node) debug("%s: Invalid PHY interface '%s'\n", __func__, mode); - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/ag7xxx.c b/drivers/net/ag7xxx.c index f24a917bd43..a16c998b2ab 100644 --- a/drivers/net/ag7xxx.c +++ b/drivers/net/ag7xxx.c @@ -1265,7 +1265,7 @@ static int ag7xxx_eth_of_to_plat(struct udevice *dev) return ret; pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; return 0; diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c index 25247472b03..b1e5c5890aa 100644 --- a/drivers/net/altera_tse.c +++ b/drivers/net/altera_tse.c @@ -678,7 +678,7 @@ static int altera_tse_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; return 0; diff --git a/drivers/net/bcm6348-eth.c b/drivers/net/bcm6348-eth.c index 8f1864a334c..53171736117 100644 --- a/drivers/net/bcm6348-eth.c +++ b/drivers/net/bcm6348-eth.c @@ -425,7 +425,7 @@ static int bcm6348_eth_probe(struct udevice *dev) /* get phy mode */ pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -ENODEV; /* get phy */ diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c index c6acb4932b4..ef321f28399 100644 --- a/drivers/net/bcmgenet.c +++ b/drivers/net/bcmgenet.c @@ -696,7 +696,7 @@ static int bcmgenet_eth_of_to_plat(struct udevice *dev) /* Get phy mode from DT */ pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 7b7b0f65780..1584b9eac17 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -921,7 +921,7 @@ int designware_eth_of_to_plat(struct udevice *dev) pdata->iobase = dev_read_addr(dev); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c index 9777f6cb9c6..39aedc80f44 100644 --- a/drivers/net/dwc_eth_qos.c +++ b/drivers/net/dwc_eth_qos.c @@ -1682,7 +1682,7 @@ static int eqos_probe_resources_stm32(struct udevice *dev) interface = eqos->config->interface(dev); - if (interface == PHY_INTERFACE_MODE_NONE) { + if (interface == PHY_INTERFACE_MODE_NA) { pr_err("Invalid PHY interface\n"); return -EINVAL; } @@ -1743,7 +1743,7 @@ static int eqos_probe_resources_imx(struct udevice *dev) interface = eqos->config->interface(dev); - if (interface == PHY_INTERFACE_MODE_NONE) { + if (interface == PHY_INTERFACE_MODE_NA) { pr_err("Invalid PHY interface\n"); return -EINVAL; } diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 22c2a3a30f2..3ac8e2a9cd1 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -1315,7 +1315,7 @@ static int fecmxc_of_to_plat(struct udevice *dev) priv->eth = (struct ethernet_regs *)pdata->iobase; pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; #ifdef CONFIG_DM_REGULATOR diff --git a/drivers/net/fm/b4860.c b/drivers/net/fm/b4860.c index 6e3d008199a..e622d86ba38 100644 --- a/drivers/net/fm/b4860.c +++ b/drivers/net/fm/b4860.c @@ -55,7 +55,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) #endif if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; /*B4860 has two 10Gig Mac*/ if ((port == FM1_10GEC1 || port == FM1_10GEC2) && @@ -112,7 +112,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) (port == FM1_DTSEC2) || (port == FM1_DTSEC3) || (port == FM1_DTSEC4)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } } } @@ -131,8 +131,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/init.c b/drivers/net/fm/init.c index 2fed64205cb..af94dabe291 100644 --- a/drivers/net/fm/init.c +++ b/drivers/net/fm/init.c @@ -130,7 +130,7 @@ static int fm_port_to_index(enum fm_port port) /* * Determine if an interface is actually active based on HW config - * we expect fman_port_enet_if() to report PHY_INTERFACE_MODE_NONE if + * we expect fman_port_enet_if() to report PHY_INTERFACE_MODE_NA if * the interface is not active based on HW cfg of the SoC */ void fman_enet_init(void) @@ -141,7 +141,7 @@ void fman_enet_init(void) phy_interface_t enet_if; enet_if = fman_port_enet_if(fm_info[i].port); - if (enet_if != PHY_INTERFACE_MODE_NONE) { + if (enet_if != PHY_INTERFACE_MODE_NA) { fm_info[i].enabled = 1; fm_info[i].enet_if = enet_if; } else { @@ -221,12 +221,12 @@ phy_interface_t fm_info_get_enet_if(enum fm_port port) int i = fm_port_to_index(port); if (i == -1) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (fm_info[i].enabled) return fm_info[i].enet_if; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } static void diff --git a/drivers/net/fm/ls1043.c b/drivers/net/fm/ls1043.c index e1abf8f6bb7..cd8376a6150 100644 --- a/drivers/net/fm/ls1043.c +++ b/drivers/net/fm/ls1043.c @@ -54,13 +54,13 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XFI_FM1_MAC9))) return PHY_INTERFACE_MODE_XGMII; if ((port == FM1_DTSEC9) && (is_serdes_configured(XFI_FM1_MAC9))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (port == FM1_DTSEC3) if ((rcwsr13 & FSL_CHASSIS2_RCWSR13_EC1) == @@ -107,5 +107,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/ls1046.c b/drivers/net/fm/ls1046.c index 09df0aa5376..876f48b1477 100644 --- a/drivers/net/fm/ls1046.c +++ b/drivers/net/fm/ls1046.c @@ -54,19 +54,19 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XFI_FM1_MAC9))) return PHY_INTERFACE_MODE_XGMII; if ((port == FM1_DTSEC9) && (is_serdes_configured(XFI_FM1_MAC9))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC2) && (is_serdes_configured(XFI_FM1_MAC10))) return PHY_INTERFACE_MODE_XGMII; if ((port == FM1_DTSEC10) && (is_serdes_configured(XFI_FM1_MAC10))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (port == FM1_DTSEC3) if ((rcwsr13 & FSL_CHASSIS2_RCWSR13_EC1) == @@ -118,5 +118,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p1023.c b/drivers/net/fm/p1023.c index d4167e4d696..c9b85fc8a8a 100644 --- a/drivers/net/fm/p1023.c +++ b/drivers/net/fm/p1023.c @@ -46,7 +46,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 pordevsr = in_be32(&gur->pordevsr); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; /* DTSEC1 can be SGMII, RGMII or RMII */ if (port == FM1_DTSEC1) { @@ -68,5 +68,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_RGMII; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p4080.c b/drivers/net/fm/p4080.c index b78b02d8284..577ee22cb0a 100644 --- a/drivers/net/fm/p4080.c +++ b/drivers/net/fm/p4080.c @@ -54,7 +54,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr11 = in_be32(&gur->rcwsr[11]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1))) return PHY_INTERFACE_MODE_XGMII; @@ -91,8 +91,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p5020.c b/drivers/net/fm/p5020.c index 81895312153..8ecc48276a9 100644 --- a/drivers/net/fm/p5020.c +++ b/drivers/net/fm/p5020.c @@ -50,7 +50,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr11 = in_be32(&gur->rcwsr[11]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1))) return PHY_INTERFACE_MODE_XGMII; @@ -82,8 +82,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p5040.c b/drivers/net/fm/p5040.c index 38744e7b7b3..3a1494d1315 100644 --- a/drivers/net/fm/p5040.c +++ b/drivers/net/fm/p5040.c @@ -56,7 +56,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr11 = in_be32(&gur->rcwsr[11]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1))) return PHY_INTERFACE_MODE_XGMII; @@ -99,8 +99,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t1024.c b/drivers/net/fm/t1024.c index 696e74c9e6f..7110fb4fb11 100644 --- a/drivers/net/fm/t1024.c +++ b/drivers/net/fm/t1024.c @@ -39,7 +39,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XFI_FM1_MAC1))) return PHY_INTERFACE_MODE_XGMII; @@ -83,5 +83,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t1040.c b/drivers/net/fm/t1040.c index af4f5c56107..192f1c6c81e 100644 --- a/drivers/net/fm/t1040.c +++ b/drivers/net/fm/t1040.c @@ -56,8 +56,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t2080.c b/drivers/net/fm/t2080.c index f4d8d2d869a..bfbd8de9cf1 100644 --- a/drivers/net/fm/t2080.c +++ b/drivers/net/fm/t2080.c @@ -47,7 +47,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1 || port == FM1_10GEC2) && ((is_serdes_configured(XAUI_FM1_MAC9)) || @@ -85,8 +85,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t4240.c b/drivers/net/fm/t4240.c index f8e63c3d719..ba7b86282fb 100644 --- a/drivers/net/fm/t4240.c +++ b/drivers/net/fm/t4240.c @@ -61,7 +61,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1 || port == FM1_10GEC2) && ((is_serdes_configured(XAUI_FM1_MAC9)) || @@ -73,7 +73,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) if ((port == FM1_DTSEC9 || port == FM1_DTSEC10) && ((is_serdes_configured(XFI_FM1_MAC9)) || (is_serdes_configured(XFI_FM1_MAC10)))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM2_10GEC1 || port == FM2_10GEC2) && ((is_serdes_configured(XAUI_FM2_MAC9)) || @@ -166,5 +166,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c index 8f5af1dbc03..1724f948bcd 100644 --- a/drivers/net/fsl_enetc.c +++ b/drivers/net/fsl_enetc.c @@ -277,7 +277,7 @@ static void enetc_start_pcs(struct udevice *dev) } priv->if_type = dev_read_phy_mode(dev); - if (priv->if_type == PHY_INTERFACE_MODE_NONE) { + if (priv->if_type == PHY_INTERFACE_MODE_NA) { enetc_dbg(dev, "phy-mode property not found, defaulting to SGMII\n"); priv->if_type = PHY_INTERFACE_MODE_SGMII; diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c index 626c27d7bf8..78779d7d60b 100644 --- a/drivers/net/ftgmac100.c +++ b/drivers/net/ftgmac100.c @@ -553,7 +553,7 @@ static int ftgmac100_of_to_plat(struct udevice *dev) pdata->iobase = dev_read_addr(dev); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); diff --git a/drivers/net/higmacv300.c b/drivers/net/higmacv300.c index ce8f2dfd098..1862235d0cd 100644 --- a/drivers/net/higmacv300.c +++ b/drivers/net/higmacv300.c @@ -567,7 +567,7 @@ static int higmac_of_to_plat(struct udevice *dev) priv->macif_ctrl = dev_remap_addr_index(dev, 1); priv->phyintf = dev_read_phy_mode(dev); - if (priv->phyintf == PHY_INTERFACE_MODE_NONE) + if (priv->phyintf == PHY_INTERFACE_MODE_NA) return -ENODEV; phy_node = dev_read_subnode(dev, "phy"); diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c index c775598b91f..b6f589eb91a 100644 --- a/drivers/net/ldpaa_eth/ldpaa_eth.c +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c @@ -1127,7 +1127,7 @@ static int ldpaa_eth_bind(struct udevice *dev) int phy_mode = -1; phy_mode = dev_read_phy_mode(dev); - if (phy_mode == PHY_INTERFACE_MODE_NONE) { + if (phy_mode == PHY_INTERFACE_MODE_NA) { dev_err(dev, "incorrect phy mode\n"); return -EINVAL; } diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c index 06a284ad684..adecb813576 100644 --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c @@ -16,7 +16,7 @@ struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS]; __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc) { - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl) @@ -26,10 +26,10 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl) dpmac_info[dpmac_id].enabled = 0; dpmac_info[dpmac_id].id = 0; - dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE; + dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA; enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); - if (enet_if != PHY_INTERFACE_MODE_NONE) { + if (enet_if != PHY_INTERFACE_MODE_NA) { dpmac_info[dpmac_id].enabled = 1; dpmac_info[dpmac_id].id = dpmac_id; dpmac_info[dpmac_id].enet_if = enet_if; @@ -183,10 +183,10 @@ phy_interface_t wriop_get_enet_if(int dpmac_id) int i = wriop_dpmac_to_index(dpmac_id); if (i == -1) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (dpmac_info[i].enabled) return dpmac_info[i].enet_if; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/ldpaa_eth/ls1088a.c b/drivers/net/ldpaa_eth/ls1088a.c index 54cb16e51b1..943113b20aa 100644 --- a/drivers/net/ldpaa_eth/ls1088a.c +++ b/drivers/net/ldpaa_eth/ls1088a.c @@ -50,7 +50,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) enum srds_prtcl; if (is_device_disabled(dpmac_id + 1)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; switch (lane_prtcl) { case SGMII1: @@ -66,7 +66,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) if (lane_prtcl >= QSGMII_A && lane_prtcl <= QSGMII_B) return PHY_INTERFACE_MODE_QSGMII; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl) diff --git a/drivers/net/ldpaa_eth/ls2080a.c b/drivers/net/ldpaa_eth/ls2080a.c index 49eee044f35..62e1d6b8691 100644 --- a/drivers/net/ldpaa_eth/ls2080a.c +++ b/drivers/net/ldpaa_eth/ls2080a.c @@ -62,7 +62,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) enum srds_prtcl; if (is_device_disabled(dpmac_id + 1)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (lane_prtcl >= SGMII1 && lane_prtcl <= SGMII16) return PHY_INTERFACE_MODE_SGMII; @@ -76,7 +76,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) if (lane_prtcl >= QSGMII_A && lane_prtcl <= QSGMII_D) return PHY_INTERFACE_MODE_QSGMII; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl) diff --git a/drivers/net/ldpaa_eth/lx2160a.c b/drivers/net/ldpaa_eth/lx2160a.c index e57f1a19a59..f0f8ee1d4de 100644 --- a/drivers/net/ldpaa_eth/lx2160a.c +++ b/drivers/net/ldpaa_eth/lx2160a.c @@ -58,7 +58,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) enum srds_prtcl; if (is_device_disabled(dpmac_id)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (lane_prtcl >= SGMII1 && lane_prtcl <= SGMII18) return PHY_INTERFACE_MODE_SGMII; @@ -78,7 +78,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) if (lane_prtcl >= _100GE1 && lane_prtcl <= _100GE2) return PHY_INTERFACE_MODE_CAUI4; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } #ifdef CONFIG_SYS_FSL_HAS_RGMII diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 317b380e8fe..e02a57b4114 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -1363,7 +1363,7 @@ static int macb_eth_probe(struct udevice *dev) int ret; macb->phy_interface = dev_read_phy_mode(dev); - if (macb->phy_interface == PHY_INTERFACE_MODE_NONE) + if (macb->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; /* Read phyaddr from DT */ diff --git a/drivers/net/mscc_eswitch/jr2_switch.c b/drivers/net/mscc_eswitch/jr2_switch.c index d1e5b61ea54..1462b8f3bc8 100644 --- a/drivers/net/mscc_eswitch/jr2_switch.c +++ b/drivers/net/mscc_eswitch/jr2_switch.c @@ -954,7 +954,7 @@ static int jr2_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/luton_switch.c b/drivers/net/mscc_eswitch/luton_switch.c index 73c950d118f..5e4f00c4f4d 100644 --- a/drivers/net/mscc_eswitch/luton_switch.c +++ b/drivers/net/mscc_eswitch/luton_switch.c @@ -685,7 +685,7 @@ static int luton_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy && i >= MAX_INT_PORT) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/ocelot_switch.c b/drivers/net/mscc_eswitch/ocelot_switch.c index d1d0a489ab4..1bf6c42c0fc 100644 --- a/drivers/net/mscc_eswitch/ocelot_switch.c +++ b/drivers/net/mscc_eswitch/ocelot_switch.c @@ -608,7 +608,7 @@ static int ocelot_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy && external_bus(priv, i)) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/serval_switch.c b/drivers/net/mscc_eswitch/serval_switch.c index c4b81f75294..38ddba12b66 100644 --- a/drivers/net/mscc_eswitch/serval_switch.c +++ b/drivers/net/mscc_eswitch/serval_switch.c @@ -561,7 +561,7 @@ static int serval_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/servalt_switch.c b/drivers/net/mscc_eswitch/servalt_switch.c index f114086ece6..db863c2a9ff 100644 --- a/drivers/net/mscc_eswitch/servalt_switch.c +++ b/drivers/net/mscc_eswitch/servalt_switch.c @@ -482,7 +482,7 @@ static int servalt_probe(struct udevice *dev) continue; phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); } return 0; diff --git a/drivers/net/mt7620-eth.c b/drivers/net/mt7620-eth.c index 24fcb9373f8..038cba12407 100644 --- a/drivers/net/mt7620-eth.c +++ b/drivers/net/mt7620-eth.c @@ -596,7 +596,7 @@ static int mt7620_setup_gmac_mode(struct mt7620_eth_priv *priv, u32 gmac, case PHY_INTERFACE_MODE_RGMII: ge_mode = MT7620_SYSC_GE_RGMII; break; - case PHY_INTERFACE_MODE_NONE: + case PHY_INTERFACE_MODE_NA: if (gmac == 2) ge_mode = MT7620_SYSC_GE_ESW_PHY; else @@ -620,7 +620,7 @@ static void mt7620_gsw_setup_port(struct mt7620_eth_priv *priv, u32 port, { u32 pmcr; - if (port_cfg->mode == PHY_INTERFACE_MODE_NONE) { + if (port_cfg->mode == PHY_INTERFACE_MODE_NA) { if (port == 5) { gsw_write(priv, GSW_PMCR(port), FORCE_MODE); return; @@ -666,7 +666,7 @@ static void mt7620_gsw_setup_phy_polling(struct mt7620_eth_priv *priv) { int phy_addr_st, phy_addr_end; - if (priv->port_cfg[0].mode == PHY_INTERFACE_MODE_NONE) + if (priv->port_cfg[0].mode == PHY_INTERFACE_MODE_NA) priv->ephy_num = NUM_FE_PHYS; else priv->ephy_num = NUM_FE_PHYS - 1; @@ -1057,7 +1057,7 @@ static int mt7620_eth_parse_gsw_port(struct mt7620_eth_priv *priv, u32 idx, case PHY_INTERFACE_MODE_MII: case PHY_INTERFACE_MODE_RMII: case PHY_INTERFACE_MODE_RGMII: - case PHY_INTERFACE_MODE_NONE: + case PHY_INTERFACE_MODE_NA: break; default: dev_err(priv->dev, "mt7620_eth: unsupported phy-mode\n"); @@ -1128,14 +1128,14 @@ static int mt7620_eth_parse_gsw_cfg(struct udevice *dev) if (ret) return ret; } else { - priv->port_cfg[0].mode = PHY_INTERFACE_MODE_NONE; + priv->port_cfg[0].mode = PHY_INTERFACE_MODE_NA; } subnode = ofnode_find_subnode(dev_ofnode(dev), "port5"); if (ofnode_valid(subnode)) return mt7620_eth_parse_gsw_port(priv, 1, subnode); - priv->port_cfg[1].mode = PHY_INTERFACE_MODE_NONE; + priv->port_cfg[1].mode = PHY_INTERFACE_MODE_NA; return 0; } diff --git a/drivers/net/mtk_eth.c b/drivers/net/mtk_eth.c index d6065db5fb7..666ddeb10d1 100644 --- a/drivers/net/mtk_eth.c +++ b/drivers/net/mtk_eth.c @@ -1449,7 +1449,7 @@ static int mtk_eth_of_to_plat(struct udevice *dev) /* Interface mode is required */ pdata->phy_interface = dev_read_phy_mode(dev); priv->phy_interface = pdata->phy_interface; - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) { + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) { printf("error: phy-mode is not set\n"); return -EINVAL; } diff --git a/drivers/net/mvgbe.c b/drivers/net/mvgbe.c index 32ec0b437d3..bf5ed5513ba 100644 --- a/drivers/net/mvgbe.c +++ b/drivers/net/mvgbe.c @@ -1005,7 +1005,7 @@ static int mvgbe_of_to_plat(struct udevice *dev) /* Get phy-mode / phy_interface from DT */ pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) pdata->phy_interface = PHY_INTERFACE_MODE_GMII; dmvgbe->phy_interface = pdata->phy_interface; diff --git a/drivers/net/mvneta.c b/drivers/net/mvneta.c index d31b96a9d82..e2ac4d801dc 100644 --- a/drivers/net/mvneta.c +++ b/drivers/net/mvneta.c @@ -1804,7 +1804,7 @@ static int mvneta_of_to_plat(struct udevice *dev) /* Get phy-mode / phy_interface from DT */ pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; return 0; diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c index dfddac180fd..8c9afdf79ab 100644 --- a/drivers/net/mvpp2.c +++ b/drivers/net/mvpp2.c @@ -4820,7 +4820,7 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) } port->phy_interface = dev_read_phy_mode(dev); - if (port->phy_interface == PHY_INTERFACE_MODE_NONE) { + if (port->phy_interface == PHY_INTERFACE_MODE_NA) { dev_err(dev, "incorrect phy mode\n"); return -EINVAL; } diff --git a/drivers/net/pic32_eth.c b/drivers/net/pic32_eth.c index 03eb51e51d5..1333a3aa7e4 100644 --- a/drivers/net/pic32_eth.c +++ b/drivers/net/pic32_eth.c @@ -550,7 +550,7 @@ static int pic32_eth_probe(struct udevice *dev) /* get phy mode */ pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; /* get phy addr */ diff --git a/drivers/net/qe/dm_qe_uec.c b/drivers/net/qe/dm_qe_uec.c index 5a66d726cd6..8fec1c21e10 100644 --- a/drivers/net/qe/dm_qe_uec.c +++ b/drivers/net/qe/dm_qe_uec.c @@ -1137,7 +1137,7 @@ static int qe_uec_of_to_plat(struct udevice *dev) pdata->iobase = (phys_addr_t)devfdt_get_addr(dev); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; return 0; diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index f6d386bd6b8..5c152d6e0a5 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -679,7 +679,7 @@ int ravb_of_to_plat(struct udevice *dev) pdata->iobase = dev_read_addr(dev); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; pdata->max_speed = 1000; diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 04c9c2d968f..5c57e3dfcd4 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -920,7 +920,7 @@ int sh_ether_of_to_plat(struct udevice *dev) pdata->iobase = dev_read_addr(dev); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; pdata->max_speed = 1000; diff --git a/drivers/net/sni_ave.c b/drivers/net/sni_ave.c index 0a368c6d03a..d684e60e72f 100644 --- a/drivers/net/sni_ave.c +++ b/drivers/net/sni_ave.c @@ -749,7 +749,7 @@ static int ave_of_to_plat(struct udevice *dev) pdata->iobase = dev_read_addr(dev); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; pdata->max_speed = 0; diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c index 693fd3a35db..24caacf8470 100644 --- a/drivers/net/sni_netsec.c +++ b/drivers/net/sni_netsec.c @@ -1034,7 +1034,7 @@ static int netsec_of_to_plat(struct udevice *dev) priv->eeprom_base = dev_read_addr_index(dev, 1) - EERPROM_MAP_OFFSET; pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c index 5654a3430e2..5943a5e3f0a 100644 --- a/drivers/net/sun8i_emac.c +++ b/drivers/net/sun8i_emac.c @@ -947,7 +947,7 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) pdata->phy_interface = dev_read_phy_mode(dev); printf("phy interface%d\n", pdata->phy_interface); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; if (priv->variant == H3_EMAC) { diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c index c1da3347395..9580fa37eaf 100644 --- a/drivers/net/ti/am65-cpsw-nuss.c +++ b/drivers/net/ti/am65-cpsw-nuss.c @@ -607,7 +607,7 @@ static int am65_cpsw_ofdata_parse_phy(struct udevice *dev) dev_read_u32(dev, "reg", &priv->port_id); pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) { + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) { dev_err(dev, "Invalid PHY mode, port %u\n", priv->port_id); return -EINVAL; } diff --git a/drivers/net/ti/cpsw.c b/drivers/net/ti/cpsw.c index 5b7bab734e4..8988c21e667 100644 --- a/drivers/net/ti/cpsw.c +++ b/drivers/net/ti/cpsw.c @@ -1345,7 +1345,7 @@ static int cpsw_eth_of_to_plat(struct udevice *dev) } pdata->phy_interface = data->slave_data[data->active_slave].phy_if; - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; return 0; diff --git a/drivers/net/ti/keystone_net.c b/drivers/net/ti/keystone_net.c index b55e7da4c18..16e3f32bb03 100644 --- a/drivers/net/ti/keystone_net.c +++ b/drivers/net/ti/keystone_net.c @@ -728,7 +728,7 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave, priv->has_mdio = true; } else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) { priv->phy_if = ofnode_read_phy_mode(offset_to_ofnode(slave)); - if (priv->phy_if == PHY_INTERFACE_MODE_NONE) + if (priv->phy_if == PHY_INTERFACE_MODE_NA) priv->phy_if = PHY_INTERFACE_MODE_RGMII; pdata->phy_interface = priv->phy_if; diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index fec051ebb7c..d69a9ff4773 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -894,7 +894,7 @@ int tsec_probe(struct udevice *dev) priv->tbiaddr = tbiaddr; pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) pdata->phy_interface = tsec_get_interface(priv); priv->interface = pdata->phy_interface; diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c index 02d13c3e0ad..a4715735c3c 100644 --- a/drivers/net/xilinx_axi_emac.c +++ b/drivers/net/xilinx_axi_emac.c @@ -850,7 +850,7 @@ static int axi_emac_of_to_plat(struct udevice *dev) } pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; plat->eth_hasnobuf = fdtdec_get_bool(gd->fdt_blob, node, diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c index 0062851134d..cf6c53c8afb 100644 --- a/drivers/net/zynq_gem.c +++ b/drivers/net/zynq_gem.c @@ -859,7 +859,7 @@ static int zynq_gem_of_to_plat(struct udevice *dev) } pdata->phy_interface = dev_read_phy_mode(dev); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; priv->interface = pdata->phy_interface; diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 3bd3ba49253..f27aca5877a 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1239,7 +1239,7 @@ ofnode ofnode_get_phy_node(ofnode eth_node); * returns the corresponding PHY interface type. * * @mac_node: ofnode containing the property - * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on + * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on * error */ phy_interface_t ofnode_read_phy_mode(ofnode mac_node); diff --git a/include/dm/read.h b/include/dm/read.h index bfa26459674..1b54b69acf0 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -764,7 +764,7 @@ ofnode dev_get_phy_node(const struct udevice *dev); * returns the corresponding PHY interface type. * * @dev: device representing the MAC - * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on + * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on * error */ phy_interface_t dev_read_phy_mode(const struct udevice *dev); diff --git a/include/fm_eth.h b/include/fm_eth.h index 44da014c66c..bf9570679d2 100644 --- a/include/fm_eth.h +++ b/include/fm_eth.h @@ -72,7 +72,7 @@ enum fm_eth_type { #define FM_ETH_INFO_INITIALIZER(idx, pregs) \ .fm = idx, \ .phy_regs = (void *)pregs, \ - .enet_if = PHY_INTERFACE_MODE_NONE, \ + .enet_if = PHY_INTERFACE_MODE_NA, \ #ifdef CONFIG_SYS_FMAN_V3 #define FM_DTSEC_INFO_INITIALIZER(idx, n) \ diff --git a/include/phy_interface.h b/include/phy_interface.h index 494bc87e679..59e119a6399 100644 --- a/include/phy_interface.h +++ b/include/phy_interface.h @@ -39,7 +39,7 @@ typedef enum { PHY_INTERFACE_MODE_NCSI, PHY_INTERFACE_MODE_10GBASER, PHY_INTERFACE_MODE_USXGMII, - PHY_INTERFACE_MODE_NONE, /* Must be last */ + PHY_INTERFACE_MODE_NA, /* Must be last */ PHY_INTERFACE_MODE_MAX, } phy_interface_t; @@ -71,7 +71,7 @@ static const char * const phy_interface_strings[] = { [PHY_INTERFACE_MODE_NCSI] = "NC-SI", [PHY_INTERFACE_MODE_10GBASER] = "10gbase-r", [PHY_INTERFACE_MODE_USXGMII] = "usxgmii", - [PHY_INTERFACE_MODE_NONE] = "", + [PHY_INTERFACE_MODE_NA] = "", }; /* Backplane modes: @@ -86,8 +86,8 @@ static const char * const backplane_mode_strings[] = { static inline const char *phy_string_for_interface(phy_interface_t i) { /* Default to unknown */ - if (i > PHY_INTERFACE_MODE_NONE) - i = PHY_INTERFACE_MODE_NONE; + if (i > PHY_INTERFACE_MODE_NA) + i = PHY_INTERFACE_MODE_NA; return phy_interface_strings[i]; } diff --git a/include/vsc9953.h b/include/vsc9953.h index a9c84b4b50c..fd52c93044b 100644 --- a/include/vsc9953.h +++ b/include/vsc9953.h @@ -691,7 +691,7 @@ struct vsc9953_vcap { .phyaddr = 0, \ .index = idx, \ .phy_regs = NULL, \ - .enet_if = PHY_INTERFACE_MODE_NONE, \ + .enet_if = PHY_INTERFACE_MODE_NA, \ .bus = NULL, \ .phydev = NULL, \ } diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 874f59413a2..7593618d9ad 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -199,8 +199,8 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) } interface = dev_read_phy_mode(ethdev); - if (interface == PHY_INTERFACE_MODE_NONE) - dev_dbg(ethdev, "can't find interface mode, default to NONE\n"); + if (interface == PHY_INTERFACE_MODE_NA) + dev_dbg(ethdev, "can't find interface mode, default to NA\n"); phy = dm_eth_connect_phy_handle(ethdev, interface); From c677fb1e3196e1be1fcbbdb04650eed262708317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:04 +0200 Subject: [PATCH 13/41] phy: Move PHY_INTERFACE_MODE_NA to the beginning of the enum definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move PHY_INTERFACE_MODE_NA to the beginning of the enum definition to make it have zero value. This makes it possible (although not encouraged) to test for invalid/nonexistent interface mode with !val instead of val == PHY_INTERFACE_MODE_NA. The comment near the definition says "Must be last", because when the constant was introduced in commit 5f184715ecd3 ("Create PHY Lib for U-Boot"), it was used as the maximum value when interating over the constants. But this is no longer true - we use PHY_INTERFACE_MODE_MAX for that now, and so we can move it. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese Reviewed-by: Ramon Fried --- include/phy_interface.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/phy_interface.h b/include/phy_interface.h index 59e119a6399..ce3b5004ec2 100644 --- a/include/phy_interface.h +++ b/include/phy_interface.h @@ -13,6 +13,7 @@ #include typedef enum { + PHY_INTERFACE_MODE_NA, /* don't touch */ PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_SGMII, @@ -39,12 +40,11 @@ typedef enum { PHY_INTERFACE_MODE_NCSI, PHY_INTERFACE_MODE_10GBASER, PHY_INTERFACE_MODE_USXGMII, - PHY_INTERFACE_MODE_NA, /* Must be last */ - PHY_INTERFACE_MODE_MAX, } phy_interface_t; static const char * const phy_interface_strings[] = { + [PHY_INTERFACE_MODE_NA] = "", [PHY_INTERFACE_MODE_MII] = "mii", [PHY_INTERFACE_MODE_GMII] = "gmii", [PHY_INTERFACE_MODE_SGMII] = "sgmii", @@ -71,7 +71,6 @@ static const char * const phy_interface_strings[] = { [PHY_INTERFACE_MODE_NCSI] = "NC-SI", [PHY_INTERFACE_MODE_10GBASER] = "10gbase-r", [PHY_INTERFACE_MODE_USXGMII] = "usxgmii", - [PHY_INTERFACE_MODE_NA] = "", }; /* Backplane modes: From f961b3abf88d2922e064a0b83525929aab917f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:05 +0200 Subject: [PATCH 14/41] net: phy: xilinx: Check interface type in ->config(), not ->probe() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to be able to have phydev->interface uninitialized during ->probe(). We should assume that phydev->interface is initialized only before ->config(). Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/phy/xilinx_gmii2rgmii.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 635c0570efe..d92a364365c 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -26,6 +26,11 @@ static int xilinxgmiitorgmii_config(struct phy_device *phydev) debug("%s\n", __func__); + if (phydev->interface != PHY_INTERFACE_MODE_GMII) { + printf("Incorrect interface type\n"); + return -EINVAL; + } + if (!ofnode_valid(node)) return -EINVAL; @@ -114,11 +119,6 @@ static int xilinxgmiitorgmii_probe(struct phy_device *phydev) { debug("%s\n", __func__); - if (phydev->interface != PHY_INTERFACE_MODE_GMII) { - printf("Incorrect interface type\n"); - return -EINVAL; - } - phydev->flags |= PHY_FLAG_BROKEN_RESET; return 0; From 79bef5fb1f0ce6b090017d2525a42f94e1577673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:06 +0200 Subject: [PATCH 15/41] net: phy: use ->is_c45 instead of is_10g_interface() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use phydev->is_c45 instead of is_10g_interface(phydev->interface) to determine whether clause 45 protocol should be used. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/phy/phy.c | 8 ++++---- include/phy.h | 12 ------------ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index ba7b361c3d9..7f21c5535ba 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -632,10 +632,10 @@ static int phy_probe(struct phy_device *phydev) return err; } -static struct phy_driver *generic_for_interface(phy_interface_t interface) +static struct phy_driver *generic_for_phy(struct phy_device *phydev) { #ifdef CONFIG_PHYLIB_10G - if (is_10g_interface(interface)) + if (phydev->is_c45) return &gen10g_driver; #endif @@ -656,7 +656,7 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev, } /* If we made it here, there's no driver for this PHY */ - return generic_for_interface(interface); + return generic_for_phy(phydev); } struct phy_device *phy_device_create(struct mii_dev *bus, int addr, @@ -859,7 +859,7 @@ int phy_reset(struct phy_device *phydev) #ifdef CONFIG_PHYLIB_10G /* If it's 10G, we need to issue reset through one of the MMDs */ - if (is_10g_interface(phydev->interface)) { + if (phydev->is_c45) { if (!phydev->mmds) gen10g_discover_mmds(phydev); diff --git a/include/phy.h b/include/phy.h index 399e050abae..c7fa0ffba43 100644 --- a/include/phy.h +++ b/include/phy.h @@ -359,18 +359,6 @@ static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad, #ifdef CONFIG_PHYLIB_10G extern struct phy_driver gen10g_driver; - -/* - * List all 10G interfaces here, the assumption being that PHYs on these - * interfaces are C45 - */ -static inline int is_10g_interface(phy_interface_t interface) -{ - return interface == PHY_INTERFACE_MODE_XGMII || - interface == PHY_INTERFACE_MODE_USXGMII || - interface == PHY_INTERFACE_MODE_10GBASER; -} - #endif /** From b638814e91f772beb1c05e4d04cf6513ac37af59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:07 +0200 Subject: [PATCH 16/41] bcmgenet, sun8i_emac: Don't connect PHY two times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bcmgenet and sun8i_emac drivers call phy_connect(), which finds / creates the PHY and also connects it to the eth device via phy_connect_dev(), then set some phydev members (bcmgenet only), and then call phy_connect_dev() explicitly again. Drop the second phy_connect_dev(), since it is unnecesary. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/bcmgenet.c | 2 -- drivers/net/sun8i_emac.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c index ef321f28399..4e1f8ed7a4a 100644 --- a/drivers/net/bcmgenet.c +++ b/drivers/net/bcmgenet.c @@ -526,8 +526,6 @@ static int bcmgenet_phy_init(struct bcmgenet_eth_priv *priv, void *dev) } phydev->advertising = phydev->supported; - phy_connect_dev(phydev, dev); - priv->phydev = phydev; phy_config(priv->phydev); diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c index 5943a5e3f0a..906a8ec5d09 100644 --- a/drivers/net/sun8i_emac.c +++ b/drivers/net/sun8i_emac.c @@ -391,8 +391,6 @@ static int sun8i_phy_init(struct emac_eth_dev *priv, void *dev) if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); - priv->phydev = phydev; phy_config(priv->phydev); From e24b58f5ed4f9a0b5b1c80a5f35aa71fcad7f233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:08 +0200 Subject: [PATCH 17/41] net: phy: don't require PHY interface mode during PHY creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we require PHY interface mode to be known when finding/creating the PHY - the functions * phy_connect_phy_id() * phy_device_create() * create_phy_by_mask() * search_for_existing_phy() * get_phy_device_by_mask() * phy_find_by_mask() all require the interface parameter, but the only thing done with it is that it is assigned to phydev->interface. This makes it impossible to find a PHY device without overwriting the set mode. Since the interface mode is not used during .probe() and should be used at first in .config(), drop the interface parameter from these functions. Make the default value of phydev->interface (in phy_device_create()) to be PHY_INTERFACE_MODE_NA. Move the interface parameter to phy_connect_dev(), where it should be. Change all occurrences treewide. In occurrences where we don't call phy_connect_dev() for some reason (they only configure the PHY without connecting it to an ethernet controller), set phydev->interface = value from phy_find_by_mask call. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- board/CZ.NIC/turris_mox/turris_mox.c | 2 +- board/boundary/nitrogen6x/nitrogen6x.c | 2 +- board/gdsys/a38x/controlcenterdc.c | 7 +- board/gdsys/a38x/ihs_phys.c | 6 +- drivers/net/altera_tse.c | 4 +- drivers/net/ethoc.c | 4 +- drivers/net/pch_gbe.c | 4 +- drivers/net/phy/ethernet_id.c | 5 +- drivers/net/phy/phy.c | 88 +++++++++++--------------- drivers/net/phy/xilinx_gmii2rgmii.c | 4 +- drivers/net/ravb.c | 4 +- drivers/net/sh_eth.c | 4 +- drivers/net/sni_ave.c | 4 +- drivers/net/sunxi_emac.c | 5 +- include/_exports.h | 3 +- include/exports.h | 3 +- include/phy.h | 20 +++--- 17 files changed, 75 insertions(+), 94 deletions(-) diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 8888a2dcabc..9702d1fc782 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -396,7 +396,7 @@ static void mox_phy_leds_start_blinking(void) return; } - phydev = phy_find_by_mask(bus, BIT(1), PHY_INTERFACE_MODE_RGMII); + phydev = phy_find_by_mask(bus, BIT(1)); if (!phydev) { printf("Cannot get ethernet PHY!\n"); return; diff --git a/board/boundary/nitrogen6x/nitrogen6x.c b/board/boundary/nitrogen6x/nitrogen6x.c index 8566c22a98f..83bb445d481 100644 --- a/board/boundary/nitrogen6x/nitrogen6x.c +++ b/board/boundary/nitrogen6x/nitrogen6x.c @@ -345,7 +345,7 @@ int board_eth_init(struct bd_info *bis) if (!bus) return -EINVAL; /* scan phy 4,5,6,7 */ - phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII); + phydev = phy_find_by_mask(bus, (0xf << 4)); if (!phydev) { ret = -EINVAL; goto free_bus; diff --git a/board/gdsys/a38x/controlcenterdc.c b/board/gdsys/a38x/controlcenterdc.c index 7d65400ccb0..ccebba72721 100644 --- a/board/gdsys/a38x/controlcenterdc.c +++ b/board/gdsys/a38x/controlcenterdc.c @@ -194,11 +194,12 @@ void init_host_phys(struct mii_dev *bus) for (k = 0; k < 2; ++k) { struct phy_device *phydev; - phydev = phy_find_by_mask(bus, 1 << k, - PHY_INTERFACE_MODE_SGMII); + phydev = phy_find_by_mask(bus, 1 << k); - if (phydev) + if (phydev) { + phydev->interface = PHY_INTERFACE_MODE_SGMII; phy_config(phydev); + } } } diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index e09c0006b76..60a5c37aeff 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -28,6 +28,7 @@ static void ihs_phy_config(struct phy_device *phydev, bool qinpn, bool qoutpn) { u16 reg; + phydev->interface = PHY_INTERFACE_MODE_MII; phy_config(phydev); /* enable QSGMII autonegotiation with flow control */ @@ -142,10 +143,9 @@ struct porttype *get_porttype(uint octo_phy_mask, uint k) int init_single_phy(struct porttype *porttype, struct mii_dev *bus, uint bus_idx, uint m, uint phy_idx) { - struct phy_device *phydev = phy_find_by_mask( - bus, 1 << (m * 8 + phy_idx), - PHY_INTERFACE_MODE_MII); + struct phy_device *phydev; + phydev = phy_find_by_mask(bus, BIT(m * 8 + phy_idx)); printf(" %u", bus_idx * 32 + m * 8 + phy_idx); if (!phydev) diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c index b1e5c5890aa..912d28fca2e 100644 --- a/drivers/net/altera_tse.c +++ b/drivers/net/altera_tse.c @@ -435,11 +435,11 @@ static int tse_phy_init(struct altera_tse_priv *priv, void *dev) if (priv->phyaddr) mask = 1 << priv->phyaddr; - phydev = phy_find_by_mask(priv->bus, mask, priv->interface); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, priv->interface); phydev->supported &= PHY_GBIT_FEATURES; phydev->advertising = phydev->supported; diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c index 7f146d4c8b4..a219affb58a 100644 --- a/drivers/net/ethoc.c +++ b/drivers/net/ethoc.c @@ -614,11 +614,11 @@ static int ethoc_phy_init(struct ethoc *priv, void *dev) mask = 1 << CONFIG_PHY_ADDR; #endif - phydev = phy_find_by_mask(priv->bus, mask, PHY_INTERFACE_MODE_MII); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, PHY_INTERFACE_MODE_MII); phydev->supported &= PHY_BASIC_FEATURES; phydev->advertising = phydev->supported; diff --git a/drivers/net/pch_gbe.c b/drivers/net/pch_gbe.c index fabcf85c0de..f1895246b93 100644 --- a/drivers/net/pch_gbe.c +++ b/drivers/net/pch_gbe.c @@ -416,13 +416,13 @@ static int pch_gbe_phy_init(struct udevice *dev) struct phy_device *phydev; int mask = 0xffffffff; - phydev = phy_find_by_mask(priv->bus, mask, plat->phy_interface); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) { printf("pch_gbe: cannot find the phy\n"); return -1; } - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, plat->phy_interface); phydev->supported &= PHY_GBIT_FEATURES; phydev->advertising = phydev->supported; diff --git a/drivers/net/phy/ethernet_id.c b/drivers/net/phy/ethernet_id.c index 5617ac3ad62..38a8dca347b 100644 --- a/drivers/net/phy/ethernet_id.c +++ b/drivers/net/phy/ethernet_id.c @@ -11,8 +11,7 @@ #include #include -struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, - phy_interface_t interface) +struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev) { struct phy_device *phydev; struct ofnode_phandle_args phandle_args; @@ -61,7 +60,7 @@ struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, } id = vendor << 16 | device; - phydev = phy_device_create(bus, 0, id, false, interface); + phydev = phy_device_create(bus, 0, id, false); if (phydev) phydev->node = node; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 7f21c5535ba..bc838466062 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -642,8 +642,7 @@ static struct phy_driver *generic_for_phy(struct phy_device *phydev) return &genphy_driver; } -static struct phy_driver *get_phy_driver(struct phy_device *phydev, - phy_interface_t interface) +static struct phy_driver *get_phy_driver(struct phy_device *phydev) { struct list_head *entry; int phy_id = phydev->phy_id; @@ -660,8 +659,7 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev, } struct phy_device *phy_device_create(struct mii_dev *bus, int addr, - u32 phy_id, bool is_c45, - phy_interface_t interface) + u32 phy_id, bool is_c45) { struct phy_device *dev; @@ -680,7 +678,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, dev->duplex = -1; dev->link = 0; - dev->interface = interface; + dev->interface = PHY_INTERFACE_MODE_NA; #ifdef CONFIG_DM_ETH dev->node = ofnode_null(); @@ -693,7 +691,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, dev->is_c45 = is_c45; dev->bus = bus; - dev->drv = get_phy_driver(dev, interface); + dev->drv = get_phy_driver(dev); if (phy_probe(dev)) { printf("%s, PHY probe failed\n", __func__); @@ -742,8 +740,7 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) } static struct phy_device *create_phy_by_mask(struct mii_dev *bus, - uint phy_mask, int devad, - phy_interface_t interface) + uint phy_mask, int devad) { u32 phy_id = 0xffffffff; bool is_c45; @@ -764,8 +761,7 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus, /* If the PHY ID is mostly f's, we didn't find anything */ if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) { is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true; - return phy_device_create(bus, addr, phy_id, is_c45, - interface); + return phy_device_create(bus, addr, phy_id, is_c45); } next: phy_mask &= ~(1 << addr); @@ -774,25 +770,22 @@ next: } static struct phy_device *search_for_existing_phy(struct mii_dev *bus, - uint phy_mask, - phy_interface_t interface) + uint phy_mask) { /* If we have one, return the existing device, with new interface */ while (phy_mask) { int addr = ffs(phy_mask) - 1; - if (bus->phymap[addr]) { - bus->phymap[addr]->interface = interface; + if (bus->phymap[addr]) return bus->phymap[addr]; - } + phy_mask &= ~(1 << addr); } return NULL; } static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, - uint phy_mask, - phy_interface_t interface) + uint phy_mask) { struct phy_device *phydev; int devad[] = { @@ -808,13 +801,12 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, int i, devad_cnt; devad_cnt = sizeof(devad)/sizeof(int); - phydev = search_for_existing_phy(bus, phy_mask, interface); + phydev = search_for_existing_phy(bus, phy_mask); if (phydev) return phydev; /* try different access clauses */ for (i = 0; i < devad_cnt; i++) { - phydev = create_phy_by_mask(bus, phy_mask, - devad[i], interface); + phydev = create_phy_by_mask(bus, phy_mask, devad[i]); if (IS_ERR(phydev)) return NULL; if (phydev) @@ -842,10 +834,9 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, * Description: Reads the ID registers of the PHY at @addr on the * @bus, then allocates and returns the phy_device to represent it. */ -static struct phy_device *get_phy_device(struct mii_dev *bus, int addr, - phy_interface_t interface) +static struct phy_device *get_phy_device(struct mii_dev *bus, int addr) { - return get_phy_device_by_mask(bus, 1 << addr, interface); + return get_phy_device_by_mask(bus, 1 << addr); } int phy_reset(struct phy_device *phydev) @@ -904,18 +895,12 @@ int miiphy_reset(const char *devname, unsigned char addr) struct mii_dev *bus = miiphy_get_dev_by_name(devname); struct phy_device *phydev; - /* - * miiphy_reset was only used on standard PHYs, so we'll fake it here. - * If later code tries to connect with the right interface, this will - * be corrected by get_phy_device in phy_connect() - */ - phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII); + phydev = get_phy_device(bus, addr); return phy_reset(phydev); } -struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask, - phy_interface_t interface) +struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask) { /* Reset the bus */ if (bus->reset) { @@ -925,13 +910,15 @@ struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask, mdelay(15); } - return get_phy_device_by_mask(bus, phy_mask, interface); + return get_phy_device_by_mask(bus, phy_mask); } #ifdef CONFIG_DM_ETH -void phy_connect_dev(struct phy_device *phydev, struct udevice *dev) +void phy_connect_dev(struct phy_device *phydev, struct udevice *dev, + phy_interface_t interface) #else -void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) +void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev, + phy_interface_t interface) #endif { /* Soft Reset the PHY */ @@ -942,13 +929,14 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) phydev->dev->name, dev->name); } phydev->dev = dev; - debug("%s connected to %s\n", dev->name, phydev->drv->name); + phydev->interface = interface; + debug("%s connected to %s mode %s\n", dev->name, phydev->drv->name, + phy_string_for_interface(interface)); } #ifdef CONFIG_PHY_XILINX_GMII2RGMII static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, - struct udevice *dev, - phy_interface_t interface) + struct udevice *dev) { struct phy_device *phydev = NULL; ofnode node; @@ -957,8 +945,7 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, node = ofnode_by_compatible(node, "xlnx,gmii-to-rgmii-1.0"); if (ofnode_valid(node)) { phydev = phy_device_create(bus, 0, - PHY_GMII2RGMII_ID, false, - interface); + PHY_GMII2RGMII_ID, false); if (phydev) phydev->node = node; break; @@ -990,24 +977,23 @@ struct phy_device *fixed_phy_create(ofnode node) return NULL; } - phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, - ofnode_read_phy_mode(node)); + phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false); if (phydev) phydev->node = subnode; + phydev->interface = ofnode_read_phy_mode(node); + return phydev; } static struct phy_device *phy_connect_fixed(struct mii_dev *bus, - struct udevice *dev, - phy_interface_t interface) + struct udevice *dev) { ofnode node = dev_ofnode(dev), subnode; struct phy_device *phydev = NULL; if (ofnode_phy_is_fixed_link(node, &subnode)) { - phydev = phy_device_create(bus, 0, PHY_FIXED_ID, - false, interface); + phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false); if (phydev) phydev->node = subnode; } @@ -1030,29 +1016,29 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff; #ifdef CONFIG_PHY_FIXED - phydev = phy_connect_fixed(bus, dev, interface); + phydev = phy_connect_fixed(bus, dev); #endif #ifdef CONFIG_PHY_NCSI if (!phydev) - phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface); + phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false); #endif #ifdef CONFIG_PHY_ETHERNET_ID if (!phydev) - phydev = phy_connect_phy_id(bus, dev, interface); + phydev = phy_connect_phy_id(bus, dev); #endif #ifdef CONFIG_PHY_XILINX_GMII2RGMII if (!phydev) - phydev = phy_connect_gmii2rgmii(bus, dev, interface); + phydev = phy_connect_gmii2rgmii(bus, dev); #endif if (!phydev) - phydev = phy_find_by_mask(bus, mask, interface); + phydev = phy_find_by_mask(bus, mask); if (phydev) - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, interface); else printf("Could not get PHY for %s: addr %d\n", bus->name, addr); return phydev; diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index d92a364365c..73762839565 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -42,13 +42,13 @@ static int xilinxgmiitorgmii_config(struct phy_device *phydev) ext_phyaddr = ofnode_read_u32_default(phandle.node, "reg", -1); ext_phydev = phy_find_by_mask(phydev->bus, - 1 << ext_phyaddr, - PHY_INTERFACE_MODE_RGMII); + 1 << ext_phyaddr); if (!ext_phydev) { printf("%s, No external phy device found\n", __func__); return -EINVAL; } + ext_phydev->interface = PHY_INTERFACE_MODE_RGMII; ext_phydev->node = phandle.node; phydev->priv = ext_phydev; diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 5c152d6e0a5..c28680565fc 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -319,11 +319,11 @@ static int ravb_phy_config(struct udevice *dev) mdelay(1); } - phydev = phy_find_by_mask(eth->bus, mask, pdata->phy_interface); + phydev = phy_find_by_mask(eth->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, pdata->phy_interface); eth->phydev = phydev; diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 5c57e3dfcd4..1de3ff8add2 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -762,11 +762,11 @@ static int sh_eth_phy_config(struct udevice *dev) struct phy_device *phydev; int mask = 0xffffffff; - phydev = phy_find_by_mask(priv->bus, mask, pdata->phy_interface); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, pdata->phy_interface); port_info->phydev = phydev; phy_config(phydev); diff --git a/drivers/net/sni_ave.c b/drivers/net/sni_ave.c index d684e60e72f..58276a40c77 100644 --- a/drivers/net/sni_ave.c +++ b/drivers/net/sni_ave.c @@ -393,11 +393,11 @@ static int ave_phy_init(struct ave_private *priv, void *dev) struct phy_device *phydev; int mask = GENMASK(31, 0), ret; - phydev = phy_find_by_mask(priv->bus, mask, priv->phy_mode); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, priv->phy_mode); phydev->supported &= PHY_GBIT_FEATURES; if (priv->max_speed) { diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sunxi_emac.c index 17ad88e732e..4c7ef2525bc 100644 --- a/drivers/net/sunxi_emac.c +++ b/drivers/net/sunxi_emac.c @@ -272,12 +272,11 @@ static int sunxi_emac_init_phy(struct emac_eth_dev *priv, void *dev) if (ret) return ret; - priv->phydev = phy_find_by_mask(priv->bus, mask, - PHY_INTERFACE_MODE_MII); + priv->phydev = phy_find_by_mask(priv->bus, mask); if (!priv->phydev) return -ENODEV; - phy_connect_dev(priv->phydev, dev); + phy_connect_dev(priv->phydev, dev, PHY_INTERFACE_MODE_MII); phy_config(priv->phydev); return 0; diff --git a/include/_exports.h b/include/_exports.h index 8030d70c0bc..f6df8b61073 100644 --- a/include/_exports.h +++ b/include/_exports.h @@ -77,8 +77,7 @@ EXPORT_FUNC(mdio_get_current_dev, struct mii_dev *, mdio_get_current_dev, void) EXPORT_FUNC(phy_find_by_mask, struct phy_device *, phy_find_by_mask, - struct mii_dev *bus, unsigned phy_mask, - phy_interface_t interface) + struct mii_dev *bus, unsigned phy_mask) EXPORT_FUNC(mdio_phydev_for_ethname, struct phy_device *, mdio_phydev_for_ethname, const char *ethname) EXPORT_FUNC(miiphy_set_current_dev, int, miiphy_set_current_dev, diff --git a/include/exports.h b/include/exports.h index 550cafdc7a1..6f8c9cf4517 100644 --- a/include/exports.h +++ b/include/exports.h @@ -55,8 +55,7 @@ int i2c_read (uchar, uint, int , uchar* , int); #endif #ifdef CONFIG_PHY_AQUANTIA struct mii_dev *mdio_get_current_dev(void); -struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask, - phy_interface_t interface); +struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask); struct phy_device *mdio_phydev_for_ethname(const char *ethname); int miiphy_set_current_dev(const char *devname); #endif diff --git a/include/phy.h b/include/phy.h index c7fa0ffba43..30af8bfa0e6 100644 --- a/include/phy.h +++ b/include/phy.h @@ -388,11 +388,9 @@ int phy_reset(struct phy_device *phydev); * * @bus: MII/MDIO bus to scan * @phy_mask: bitmap of PYH addresses to scan - * @interface: type of MAC-PHY interface * @return: pointer to phy_device if a PHY is found, or NULL otherwise */ -struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask, - phy_interface_t interface); +struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask); #ifdef CONFIG_PHY_FIXED @@ -421,8 +419,10 @@ static inline struct phy_device *fixed_phy_create(ofnode node) * phy_connect_dev() - Associates the given pair of PHY and Ethernet devices * @phydev: PHY device * @dev: Ethernet device + * @interface: type of MAC-PHY interface */ -void phy_connect_dev(struct phy_device *phydev, struct udevice *dev); +void phy_connect_dev(struct phy_device *phydev, struct udevice *dev, + phy_interface_t interface); /** * phy_connect() - Creates a PHY device for the Ethernet interface @@ -449,12 +449,10 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, * @addr: PHY address on MDIO bus * @phy_id: where to store the ID retrieved * @is_c45: Device Identifiers if is_c45 - * @interface: interface between the MAC and PHY * @return: pointer to phy_device if a PHY is found, or NULL otherwise */ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, - u32 phy_id, bool is_c45, - phy_interface_t interface); + u32 phy_id, bool is_c45); /** * phy_connect_phy_id() - Connect to phy device by reading PHY id @@ -462,12 +460,10 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, * * @bus: MII/MDIO bus that hosts the PHY * @dev: Ethernet device to associate to the PHY - * @interface: Interface between the MAC and PHY * @return: pointer to phy_device if a PHY is found, * or NULL otherwise */ -struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, - phy_interface_t interface); +struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev); static inline ofnode phy_get_ofnode(struct phy_device *phydev) { @@ -482,8 +478,10 @@ static inline ofnode phy_get_ofnode(struct phy_device *phydev) * phy_connect_dev() - Associates the given pair of PHY and Ethernet devices * @phydev: PHY device * @dev: Ethernet device + * @interface: type of MAC-PHY interface */ -void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev); +void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev, + phy_interface_t interface); /** * phy_connect() - Creates a PHY device for the Ethernet interface From 4223fb0ee18d11462c55ac94198fdc2055f2c27c Mon Sep 17 00:00:00 2001 From: Tim Harvey Date: Tue, 1 Mar 2022 12:15:01 -0800 Subject: [PATCH 18/41] net: fec: prevent undesired de-assertion of phy-reset on request When gpio_request_by_name allocates a gpio output it by default will de-assert the gpio which for phy-reset will take the PHY out of reset. As this occurs before fec_gpio_reset is called to assert the reset line it can cause undesired affects if reset timings are not properly met. Configure the gpio with GPIOD_IS_OUT_ACTIVE so that reset is kept active (reset asserted) to avoid this. Cc: Sean Anderson Signed-off-by: Tim Harvey Acked-by: Joe Hershberger Tested-by: Adam Ford #imx8mm-beacon Reviewed-by: Ramon Fried --- drivers/net/fec_mxc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 3ac8e2a9cd1..a623a5c45e4 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -1324,7 +1324,7 @@ static int fecmxc_of_to_plat(struct udevice *dev) #if CONFIG_IS_ENABLED(DM_GPIO) ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, - &priv->phy_reset_gpio, GPIOD_IS_OUT); + &priv->phy_reset_gpio, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); if (ret < 0) return 0; /* property is optional, don't return error! */ From f3409d7ae6127b6aa33ec9cdb63808745ed4b56e Mon Sep 17 00:00:00 2001 From: Tim Harvey Date: Tue, 1 Mar 2022 12:15:02 -0800 Subject: [PATCH 19/41] net: eth-phy: prevent undesired de-assertion of phy-reset on request When gpio_request_by_name allocates a gpio output it by default will de-assert the gpio which for phy-reset will take the PHY out of reset. As this occurs before eth_phy_reset is called to assert the reset line it can cause undesired affects if reset timings are not properly met. Configure the gpio with GPIOD_IS_OUT_ACTIVE so that reset is kept active (reset asserted) to avoid this. Cc: Sean Anderson Signed-off-by: Tim Harvey Acked-by: Joe Hershberger Reviewed-by: Ramon Fried --- drivers/net/eth-phy-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c index 1f285f7afd2..27b77444a0c 100644 --- a/drivers/net/eth-phy-uclass.c +++ b/drivers/net/eth-phy-uclass.c @@ -137,7 +137,7 @@ static int eth_phy_of_to_plat(struct udevice *dev) /* search "reset-gpios" in phy node */ ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset_gpio, - GPIOD_IS_OUT); + GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); if (ret && ret != -ENOENT) return ret; From d79f1a85697e3af24a97728f6e4f16635bdc8290 Mon Sep 17 00:00:00 2001 From: Nate Drude Date: Fri, 8 Apr 2022 11:28:14 -0500 Subject: [PATCH 20/41] phy: adin: add driver for Analog Devices ADIN1300 PHY The current implementation configures RGMII using device tree phy-mode property and then calls genphy_config adin_config_rgmii_mode is derived from: https://github.com/varigit/linux-imx/blob/lf-5.10.y_var04/drivers/net/phy/adin.c#L218-L262 Signed-off-by: Nate Drude Reviewed-by: Ramon Fried --- doc/device-tree-bindings/net/phy/adin.txt | 26 +++ drivers/net/phy/Kconfig | 5 + drivers/net/phy/Makefile | 1 + drivers/net/phy/adin.c | 228 ++++++++++++++++++++++ drivers/net/phy/phy.c | 3 + include/phy.h | 1 + 6 files changed, 264 insertions(+) create mode 100644 doc/device-tree-bindings/net/phy/adin.txt create mode 100644 drivers/net/phy/adin.c diff --git a/doc/device-tree-bindings/net/phy/adin.txt b/doc/device-tree-bindings/net/phy/adin.txt new file mode 100644 index 00000000000..d4bab57e2d5 --- /dev/null +++ b/doc/device-tree-bindings/net/phy/adin.txt @@ -0,0 +1,26 @@ +* Analog Devices ADIN PHY Device Tree binding + +Required properties: +- reg: PHY address + +Optional properties: +- adi,rx-internal-delay-ps: RGMII RX Clock Delay used only when PHY operates + in RGMII mode with internal delay (phy-mode is 'rgmii-id' or + 'rgmii-rxid') in pico-seconds. +- adi,tx-internal-delay-ps: RGMII TX Clock Delay used only when PHY operates + in RGMII mode with internal delay (phy-mode is 'rgmii-id' or + 'rgmii-txid') in pico-seconds. +- adi,phy-mode-override: Override phy-mode property for adin. This is useful + when a single device tree supports an adin PHY (e.g. ADIN1300) + or another PHY (e.g. AR8033) at the same address, but they require + different phy-modes. + +Example: + + ethernet-phy@0 { + reg = <0>; + + adi,rx-internal-delay-ps = <1800>; + adi,tx-internal-delay-ps = <2200>; + adi,phy-mode-override = "rgmii-id"; + }; diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 014a4de223e..2f90ab0d2cc 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -68,6 +68,11 @@ endif # MV88E61XX_SWITCH config PHYLIB_10G bool "Generic 10G PHY support" +config PHY_ADIN + bool "Analog Devices Industrial Ethernet PHYs" + help + Add support for configuring RGMII on Analog Devices ADIN PHYs. + menuconfig PHY_AQUANTIA bool "Aquantia Ethernet PHYs support" select PHY_GIGE diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index b28440bc4e5..a4dd1052e1b 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_MV88E6352_SWITCH) += mv88e6352.o obj-$(CONFIG_PHYLIB) += phy.o obj-$(CONFIG_PHYLIB_10G) += generic_10g.o +obj-$(CONFIG_PHY_ADIN) += adin.o obj-$(CONFIG_PHY_AQUANTIA) += aquantia.o obj-$(CONFIG_PHY_ATHEROS) += atheros.o obj-$(CONFIG_PHY_BROADCOM) += broadcom.o diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c new file mode 100644 index 00000000000..cff841ab3dd --- /dev/null +++ b/drivers/net/phy/adin.c @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: GPL-2.0+ +/** + * Driver for Analog Devices Industrial Ethernet PHYs + * + * Copyright 2019 Analog Devices Inc. + * Copyright 2022 Variscite Ltd. + */ +#include +#include +#include +#include + +#define PHY_ID_ADIN1300 0x0283bc30 +#define ADIN1300_EXT_REG_PTR 0x10 +#define ADIN1300_EXT_REG_DATA 0x11 +#define ADIN1300_GE_RGMII_CFG 0xff23 +#define ADIN1300_GE_RGMII_RX_MSK GENMASK(8, 6) +#define ADIN1300_GE_RGMII_RX_SEL(x) \ + FIELD_PREP(ADIN1300_GE_RGMII_RX_MSK, x) +#define ADIN1300_GE_RGMII_GTX_MSK GENMASK(5, 3) +#define ADIN1300_GE_RGMII_GTX_SEL(x) \ + FIELD_PREP(ADIN1300_GE_RGMII_GTX_MSK, x) +#define ADIN1300_GE_RGMII_RXID_EN BIT(2) +#define ADIN1300_GE_RGMII_TXID_EN BIT(1) +#define ADIN1300_GE_RGMII_EN BIT(0) + +/* RGMII internal delay settings for rx and tx for ADIN1300 */ +#define ADIN1300_RGMII_1_60_NS 0x0001 +#define ADIN1300_RGMII_1_80_NS 0x0002 +#define ADIN1300_RGMII_2_00_NS 0x0000 +#define ADIN1300_RGMII_2_20_NS 0x0006 +#define ADIN1300_RGMII_2_40_NS 0x0007 + +/** + * struct adin_cfg_reg_map - map a config value to aregister value + * @cfg value in device configuration + * @reg value in the register + */ +struct adin_cfg_reg_map { + int cfg; + int reg; +}; + +static const struct adin_cfg_reg_map adin_rgmii_delays[] = { + { 1600, ADIN1300_RGMII_1_60_NS }, + { 1800, ADIN1300_RGMII_1_80_NS }, + { 2000, ADIN1300_RGMII_2_00_NS }, + { 2200, ADIN1300_RGMII_2_20_NS }, + { 2400, ADIN1300_RGMII_2_40_NS }, + { }, +}; + +static int adin_lookup_reg_value(const struct adin_cfg_reg_map *tbl, int cfg) +{ + size_t i; + + for (i = 0; tbl[i].cfg; i++) { + if (tbl[i].cfg == cfg) + return tbl[i].reg; + } + + return -EINVAL; +} + +static u32 adin_get_reg_value(struct phy_device *phydev, + const char *prop_name, + const struct adin_cfg_reg_map *tbl, + u32 dflt) +{ + u32 val; + int rc; + + ofnode node = phy_get_ofnode(phydev); + if (!ofnode_valid(node)) { + printf("%s: failed to get node\n", __func__); + return -EINVAL; + } + + if (ofnode_read_u32(node, prop_name, &val)) { + printf("%s: failed to find %s, using default %d\n", + __func__, prop_name, dflt); + return dflt; + } + + debug("%s: %s = '%d'\n", __func__, prop_name, val); + + rc = adin_lookup_reg_value(tbl, val); + if (rc < 0) { + printf("%s: Unsupported value %u for %s using default (%u)\n", + __func__, val, prop_name, dflt); + return dflt; + } + + return rc; +} + +/** + * adin_get_phy_mode_override - Get phy-mode override for adin PHY + * + * The function gets phy-mode string from property 'adi,phy-mode-override' + * and return its index in phy_interface_strings table, or -1 in error case. + */ +int adin_get_phy_mode_override(struct phy_device *phydev) +{ + ofnode node = phy_get_ofnode(phydev); + const char *phy_mode_override; + const char *prop_phy_mode_override = "adi,phy-mode-override"; + int override_interface; + + phy_mode_override = ofnode_read_string(node, prop_phy_mode_override); + if (!phy_mode_override) + return -ENODEV; + + debug("%s: %s = '%s'\n", + __func__, prop_phy_mode_override, phy_mode_override); + + override_interface = phy_get_interface_by_name(phy_mode_override); + + if (override_interface < 0) + printf("%s: %s = '%s' is not valid\n", + __func__, prop_phy_mode_override, phy_mode_override); + + return override_interface; +} + +static u16 adin_ext_read(struct phy_device *phydev, const u32 regnum) +{ + u16 val; + + phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_PTR, regnum); + val = phy_read(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_DATA); + + debug("%s: adin@0x%x 0x%x=0x%x\n", __func__, phydev->addr, regnum, val); + + return val; +} + +static int adin_ext_write(struct phy_device *phydev, const u32 regnum, const u16 val) +{ + debug("%s: adin@0x%x 0x%x=0x%x\n", __func__, phydev->addr, regnum, val); + + phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_PTR, regnum); + + return phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_DATA, val); +} + +static int adin_config_rgmii_mode(struct phy_device *phydev) +{ + u16 reg_val; + u32 val; + int phy_mode_override = adin_get_phy_mode_override(phydev); + + if (phy_mode_override >= 0) { + phydev->interface = (phy_interface_t) phy_mode_override; + } + + reg_val = adin_ext_read(phydev, ADIN1300_GE_RGMII_CFG); + + if (!phy_interface_is_rgmii(phydev)) { + /* Disable RGMII */ + reg_val &= ~ADIN1300_GE_RGMII_EN; + return adin_ext_write(phydev, ADIN1300_GE_RGMII_CFG, reg_val); + } + + /* Enable RGMII */ + reg_val |= ADIN1300_GE_RGMII_EN; + + /* Enable / Disable RGMII RX Delay */ + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { + reg_val |= ADIN1300_GE_RGMII_RXID_EN; + + val = adin_get_reg_value(phydev, "adi,rx-internal-delay-ps", + adin_rgmii_delays, + ADIN1300_RGMII_2_00_NS); + reg_val &= ~ADIN1300_GE_RGMII_RX_MSK; + reg_val |= ADIN1300_GE_RGMII_RX_SEL(val); + } else { + reg_val &= ~ADIN1300_GE_RGMII_RXID_EN; + } + + /* Enable / Disable RGMII RX Delay */ + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { + reg_val |= ADIN1300_GE_RGMII_TXID_EN; + + val = adin_get_reg_value(phydev, "adi,tx-internal-delay-ps", + adin_rgmii_delays, + ADIN1300_RGMII_2_00_NS); + reg_val &= ~ADIN1300_GE_RGMII_GTX_MSK; + reg_val |= ADIN1300_GE_RGMII_GTX_SEL(val); + } else { + reg_val &= ~ADIN1300_GE_RGMII_TXID_EN; + } + + return adin_ext_write(phydev, ADIN1300_GE_RGMII_CFG, reg_val); +} + +static int adin1300_config(struct phy_device *phydev) +{ + int ret; + + printf("ADIN1300 PHY detected at addr %d\n", phydev->addr); + + ret = adin_config_rgmii_mode(phydev); + + if (ret < 0) + return ret; + + return genphy_config(phydev); +} + +static struct phy_driver ADIN1300_driver = { + .name = "ADIN1300", + .uid = PHY_ID_ADIN1300, + .mask = 0xffffffff, + .features = PHY_GBIT_FEATURES, + .config = adin1300_config, + .startup = genphy_startup, + .shutdown = genphy_shutdown, +}; + +int phy_adin_init(void) +{ + phy_register(&ADIN1300_driver); + + return 0; +} diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index bc838466062..e0b37a9542e 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -490,6 +490,9 @@ int phy_init(void) #ifdef CONFIG_MV88E61XX_SWITCH phy_mv88e61xx_init(); #endif +#ifdef CONFIG_PHY_ADIN + phy_adin_init(); +#endif #ifdef CONFIG_PHY_AQUANTIA phy_aquantia_init(); #endif diff --git a/include/phy.h b/include/phy.h index 30af8bfa0e6..37b2a0281e3 100644 --- a/include/phy.h +++ b/include/phy.h @@ -526,6 +526,7 @@ int gen10g_discover_mmds(struct phy_device *phydev); int phy_b53_init(void); int phy_mv88e61xx_init(void); +int phy_adin_init(void); int phy_aquantia_init(void); int phy_atheros_init(void); int phy_broadcom_init(void); From 1ffe366881a3fd474737f67f2e9fb5bf40104fd3 Mon Sep 17 00:00:00 2001 From: Arjan Minzinga Zijlstra Date: Thu, 31 Mar 2022 08:03:16 +0000 Subject: [PATCH 21/41] net: tftp: fix tftp server initialization Some globals where not properly initialized causing timeouts as data packets where not immediately acknowledged. Fixes: cc6b87ecaa96 ("net: tftp: Add client support for RFC 7440") Signed-off-by: Arjan Minzinga Zijlstra Reviewed-by: Ramon Fried --- net/tftp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/tftp.c b/net/tftp.c index e1e359732ee..bfc4c9bde9c 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -906,6 +906,8 @@ void tftp_start_server(void) tftp_block_size = TFTP_BLOCK_SIZE; tftp_cur_block = 0; tftp_our_port = WELL_KNOWN_PORT; + tftp_windowsize = 1; + tftp_next_ack = tftp_windowsize; #ifdef CONFIG_TFTP_TSIZE tftp_tsize = 0; From 71f473916db507d287d2a64806b2184dae629da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Mon, 11 Apr 2022 21:20:53 +0200 Subject: [PATCH 22/41] driver: net: ti: keystone_net: Deduplicate code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deduplicate common code in ks2_eth_bind_slaves(). Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/ti/keystone_net.c | 75 ++++++++++++++++------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/drivers/net/ti/keystone_net.c b/drivers/net/ti/keystone_net.c index 16e3f32bb03..3ee4740ec5e 100644 --- a/drivers/net/ti/keystone_net.c +++ b/drivers/net/ti/keystone_net.c @@ -621,58 +621,51 @@ static const struct eth_ops ks2_eth_ops = { .write_hwaddr = ks2_eth_write_hwaddr, }; -static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0) +static int ks2_bind_one_slave(struct udevice *dev, int slave, int *gbe_0) { const void *fdt = gd->fdt_blob; - struct udevice *sl_dev; - int interfaces; - int sec_slave; - int slave; - int ret; char *slave_name; + int slave_no; + int ret; + + slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); + if (slave_no == -ENOENT) + return 0; + + if (gbe_0 && slave_no == 0) { + /* This is the current eth device */ + *gbe_0 = slave; + return 0; + } + + /* Slave devices to be registered */ + slave_name = malloc(20); + snprintf(slave_name, 20, "netcp@slave-%d", slave_no); + ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, + offset_to_ofnode(slave), NULL); + if (ret) + pr_err("ks2_net - not able to bind slave interfaces\n"); + + return ret; +} + +static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0) +{ + int interfaces, sec_slave, slave, ret; + const void *fdt = gd->fdt_blob; interfaces = fdt_subnode_offset(fdt, gbe, "interfaces"); fdt_for_each_subnode(slave, fdt, interfaces) { - int slave_no; - - slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); - if (slave_no == -ENOENT) - continue; - - if (slave_no == 0) { - /* This is the current eth device */ - *gbe_0 = slave; - } else { - /* Slave devices to be registered */ - slave_name = malloc(20); - snprintf(slave_name, 20, "netcp@slave-%d", slave_no); - ret = device_bind_driver_to_node(dev, "eth_ks2_sl", - slave_name, offset_to_ofnode(slave), - &sl_dev); - if (ret) { - pr_err("ks2_net - not able to bind slave interfaces\n"); - return ret; - } - } + ret = ks2_bind_one_slave(dev, slave, gbe_0); + if (ret) + return ret; } sec_slave = fdt_subnode_offset(fdt, gbe, "secondary-slave-ports"); fdt_for_each_subnode(slave, fdt, sec_slave) { - int slave_no; - - slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); - if (slave_no == -ENOENT) - continue; - - /* Slave devices to be registered */ - slave_name = malloc(20); - snprintf(slave_name, 20, "netcp@slave-%d", slave_no); - ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, - offset_to_ofnode(slave), &sl_dev); - if (ret) { - pr_err("ks2_net - not able to bind slave interfaces\n"); + ret = ks2_bind_one_slave(dev, slave, NULL); + if (ret) return ret; - } } return 0; From 71b65d8210934d8d3fa4b9b697ff088b21a0f838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Mon, 11 Apr 2022 21:20:54 +0200 Subject: [PATCH 23/41] driver: net: ti: keystone_net: Convert to ofnode functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert fdt parsing functions to ofnode parsing functions. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/ti/keystone_net.c | 111 ++++++++++++++-------------------- 1 file changed, 47 insertions(+), 64 deletions(-) diff --git a/drivers/net/ti/keystone_net.c b/drivers/net/ti/keystone_net.c index 3ee4740ec5e..3c1f6160861 100644 --- a/drivers/net/ti/keystone_net.c +++ b/drivers/net/ti/keystone_net.c @@ -23,7 +23,6 @@ #include #include #include -#include #include "cpsw_mdio.h" @@ -91,9 +90,9 @@ struct ks2_eth_priv { struct mii_dev *mdio_bus; int phy_addr; phy_interface_t phy_if; - int phy_of_handle; + ofnode phy_ofnode; int sgmii_link_type; - void *mdio_base; + void * mdio_base; struct rx_buff_desc net_rx_buffs; struct pktdma_cfg *netcp_pktdma; void *hd; @@ -593,8 +592,8 @@ static int ks2_eth_probe(struct udevice *dev) priv->phydev = phy_connect(priv->mdio_bus, priv->phy_addr, dev, priv->phy_if); #ifdef CONFIG_DM_ETH - if (priv->phy_of_handle) - priv->phydev->node = offset_to_ofnode(priv->phy_of_handle); + if (ofnode_valid(priv->phy_ofnode)) + priv->phydev->node = priv->phy_ofnode; #endif phy_config(priv->phydev); } @@ -621,15 +620,13 @@ static const struct eth_ops ks2_eth_ops = { .write_hwaddr = ks2_eth_write_hwaddr, }; -static int ks2_bind_one_slave(struct udevice *dev, int slave, int *gbe_0) +static int ks2_bind_one_slave(struct udevice *dev, ofnode slave, ofnode *gbe_0) { - const void *fdt = gd->fdt_blob; char *slave_name; - int slave_no; + u32 slave_no; int ret; - slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); - if (slave_no == -ENOENT) + if (ofnode_read_u32(slave, "slave-port", &slave_no)) return 0; if (gbe_0 && slave_no == 0) { @@ -641,28 +638,28 @@ static int ks2_bind_one_slave(struct udevice *dev, int slave, int *gbe_0) /* Slave devices to be registered */ slave_name = malloc(20); snprintf(slave_name, 20, "netcp@slave-%d", slave_no); - ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, - offset_to_ofnode(slave), NULL); + ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, slave, + NULL); if (ret) pr_err("ks2_net - not able to bind slave interfaces\n"); return ret; } -static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0) +static int ks2_eth_bind_slaves(struct udevice *dev, ofnode gbe, ofnode *gbe_0) { - int interfaces, sec_slave, slave, ret; - const void *fdt = gd->fdt_blob; + ofnode interfaces, sec_slave, slave; + int ret; - interfaces = fdt_subnode_offset(fdt, gbe, "interfaces"); - fdt_for_each_subnode(slave, fdt, interfaces) { + interfaces = ofnode_find_subnode(gbe, "interfaces"); + ofnode_for_each_subnode(slave, interfaces) { ret = ks2_bind_one_slave(dev, slave, gbe_0); if (ret) return ret; } - sec_slave = fdt_subnode_offset(fdt, gbe, "secondary-slave-ports"); - fdt_for_each_subnode(slave, fdt, sec_slave) { + sec_slave = ofnode_find_subnode(gbe, "secondary-slave-ports"); + ofnode_for_each_subnode(slave, sec_slave) { ret = ks2_bind_one_slave(dev, slave, NULL); if (ret) return ret; @@ -671,47 +668,40 @@ static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0) return 0; } -static int ks2_eth_parse_slave_interface(int netcp, int slave, +static int ks2_eth_parse_slave_interface(ofnode netcp, ofnode slave, struct ks2_eth_priv *priv, struct eth_pdata *pdata) { - const void *fdt = gd->fdt_blob; - int mdio; - int phy; + struct ofnode_phandle_args dma_args; + ofnode phy, mdio; int dma_count; - u32 dma_channel[8]; - priv->slave_port = fdtdec_get_int(fdt, slave, "slave-port", -1); + priv->slave_port = ofnode_read_s32_default(slave, "slave-port", -1); priv->net_rx_buffs.rx_flow = priv->slave_port * 8; /* U-Boot slave port number starts with 1 instead of 0 */ priv->slave_port += 1; - dma_count = fdtdec_get_int_array_count(fdt, netcp, - "ti,navigator-dmas", - dma_channel, 8); + dma_count = ofnode_count_phandle_with_args(netcp, "ti,navigator-dmas", + NULL, 1); + if (priv->slave_port < dma_count && + !ofnode_parse_phandle_with_args(netcp, "ti,navigator-dmas", NULL, 1, + priv->slave_port - 1, &dma_args)) + priv->net_rx_buffs.rx_flow = dma_args.args[0]; - if (dma_count > (2 * priv->slave_port)) { - int dma_idx; + priv->link_type = ofnode_read_s32_default(slave, "link-interface", -1); - dma_idx = priv->slave_port * 2 - 1; - priv->net_rx_buffs.rx_flow = dma_channel[dma_idx]; - } + phy = ofnode_get_phy_node(slave); + priv->phy_ofnode = phy; + if (ofnode_valid(phy)) { + priv->phy_addr = ofnode_read_s32_default(phy, "reg", -1); - priv->link_type = fdtdec_get_int(fdt, slave, "link-interface", -1); - - phy = fdtdec_lookup_phandle(fdt, slave, "phy-handle"); - - if (phy >= 0) { - priv->phy_of_handle = phy; - priv->phy_addr = fdtdec_get_int(fdt, phy, "reg", -1); - - mdio = fdt_parent_offset(fdt, phy); - if (mdio < 0) { + mdio = ofnode_get_parent(phy); + if (!ofnode_valid(mdio)) { pr_err("mdio dt not found\n"); return -ENODEV; } - priv->mdio_base = (void *)fdtdec_get_addr(fdt, mdio, "reg"); + priv->mdio_base = (void *)ofnode_get_addr(mdio); } if (priv->link_type == LINK_TYPE_SGMII_MAC_TO_PHY_MODE) { @@ -720,7 +710,7 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave, priv->sgmii_link_type = SGMII_LINK_MAC_PHY; priv->has_mdio = true; } else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) { - priv->phy_if = ofnode_read_phy_mode(offset_to_ofnode(slave)); + priv->phy_if = ofnode_read_phy_mode(slave); if (priv->phy_if == PHY_INTERFACE_MODE_NA) priv->phy_if = PHY_INTERFACE_MODE_RGMII; pdata->phy_interface = priv->phy_if; @@ -741,23 +731,19 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave, static int ks2_sl_eth_of_to_plat(struct udevice *dev) { + ofnode slave, interfaces, gbe, netcp_devices, netcp; struct ks2_eth_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); - const void *fdt = gd->fdt_blob; - int slave = dev_of_offset(dev); - int interfaces; - int gbe; - int netcp_devices; - int netcp; - interfaces = fdt_parent_offset(fdt, slave); - gbe = fdt_parent_offset(fdt, interfaces); - netcp_devices = fdt_parent_offset(fdt, gbe); - netcp = fdt_parent_offset(fdt, netcp_devices); + slave = dev_ofnode(dev); + interfaces = ofnode_get_parent(slave); + gbe = ofnode_get_parent(interfaces); + netcp_devices = ofnode_get_parent(gbe); + netcp = ofnode_get_parent(netcp_devices); ks2_eth_parse_slave_interface(netcp, slave, priv, pdata); - pdata->iobase = fdtdec_get_addr(fdt, netcp, "reg"); + pdata->iobase = ofnode_get_addr(netcp); return 0; } @@ -766,18 +752,15 @@ static int ks2_eth_of_to_plat(struct udevice *dev) { struct ks2_eth_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); - const void *fdt = gd->fdt_blob; - int gbe_0 = -ENODEV; - int netcp_devices; - int gbe; + ofnode netcp_devices, gbe, gbe_0; - netcp_devices = fdt_subnode_offset(fdt, dev_of_offset(dev), - "netcp-devices"); - gbe = fdt_subnode_offset(fdt, netcp_devices, "gbe"); + netcp_devices = dev_read_subnode(dev, "netcp-devices"); + gbe = ofnode_find_subnode(netcp_devices, "gbe"); + gbe_0 = ofnode_null(); ks2_eth_bind_slaves(dev, gbe, &gbe_0); - ks2_eth_parse_slave_interface(dev_of_offset(dev), gbe_0, priv, pdata); + ks2_eth_parse_slave_interface(dev_ofnode(dev), gbe_0, priv, pdata); pdata->iobase = dev_read_addr(dev); From af8b0a8d2c983a15232ff125292a65e4e6b8bd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Mon, 11 Apr 2022 21:20:55 +0200 Subject: [PATCH 24/41] driver: net: ti: keystone_net: Change priv member type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change type of private struct member mdio_base from void * to phys_addr_t. This allows us to drop 2 casts. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/ti/keystone_net.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ti/keystone_net.c b/drivers/net/ti/keystone_net.c index 3c1f6160861..fbec69f5717 100644 --- a/drivers/net/ti/keystone_net.c +++ b/drivers/net/ti/keystone_net.c @@ -92,7 +92,7 @@ struct ks2_eth_priv { phy_interface_t phy_if; ofnode phy_ofnode; int sgmii_link_type; - void * mdio_base; + phys_addr_t mdio_base; struct rx_buff_desc net_rx_buffs; struct pktdma_cfg *netcp_pktdma; void *hd; @@ -569,7 +569,7 @@ static int ks2_eth_probe(struct udevice *dev) * to re-use the same */ mdio_bus = cpsw_mdio_init("ethernet-mdio", - (u32)priv->mdio_base, + priv->mdio_base, EMAC_MDIO_CLOCK_FREQ, EMAC_MDIO_BUS_FREQ); if (!mdio_bus) { @@ -701,7 +701,7 @@ static int ks2_eth_parse_slave_interface(ofnode netcp, ofnode slave, pr_err("mdio dt not found\n"); return -ENODEV; } - priv->mdio_base = (void *)ofnode_get_addr(mdio); + priv->mdio_base = ofnode_get_addr(mdio); } if (priv->link_type == LINK_TYPE_SGMII_MAC_TO_PHY_MODE) { From ff61d4eb74bab01f358706d1530d4fcf898cf383 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:23 +0200 Subject: [PATCH 25/41] net: dm9000: Make accessor names lowercase Make accessor names lowercase to be consistent with coding style. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 214 +++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 4f062e99d9b..93699135f75 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -104,24 +104,24 @@ static board_info_t dm9000_info; static int dm9000_probe(void); static u16 dm9000_phy_read(int); static void dm9000_phy_write(int, u16); -static u8 DM9000_ior(int); -static void DM9000_iow(int reg, u8 value); +static u8 dm9000_ior(int); +static void dm9000_iow(int reg, u8 value); /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED -#define DM9000_outb(d,r) writeb(d, (volatile u8 *)(r)) -#define DM9000_outw(d,r) writew(d, (volatile u16 *)(r)) -#define DM9000_outl(d,r) writel(d, (volatile u32 *)(r)) -#define DM9000_inb(r) readb((volatile u8 *)(r)) -#define DM9000_inw(r) readw((volatile u16 *)(r)) -#define DM9000_inl(r) readl((volatile u32 *)(r)) +#define dm9000_outb(d,r) writeb(d, (volatile u8 *)(r)) +#define dm9000_outw(d,r) writew(d, (volatile u16 *)(r)) +#define dm9000_outl(d,r) writel(d, (volatile u32 *)(r)) +#define dm9000_inb(r) readb((volatile u8 *)(r)) +#define dm9000_inw(r) readw((volatile u16 *)(r)) +#define dm9000_inl(r) readl((volatile u32 *)(r)) #else -#define DM9000_outb(d, r) __raw_writeb(d, r) -#define DM9000_outw(d, r) __raw_writew(d, r) -#define DM9000_outl(d, r) __raw_writel(d, r) -#define DM9000_inb(r) __raw_readb(r) -#define DM9000_inw(r) __raw_readw(r) -#define DM9000_inl(r) __raw_readl(r) +#define dm9000_outb(d, r) __raw_writeb(d, r) +#define dm9000_outw(d, r) __raw_writew(d, r) +#define dm9000_outl(d, r) __raw_writel(d, r) +#define dm9000_inb(r) __raw_readb(r) +#define dm9000_inw(r) __raw_readw(r) +#define dm9000_inl(r) __raw_readl(r) #endif #ifdef CONFIG_DM9000_DEBUG @@ -129,14 +129,14 @@ static void dump_regs(void) { DM9000_DBG("\n"); - DM9000_DBG("NCR (0x00): %02x\n", DM9000_ior(0)); - DM9000_DBG("NSR (0x01): %02x\n", DM9000_ior(1)); - DM9000_DBG("TCR (0x02): %02x\n", DM9000_ior(2)); - DM9000_DBG("TSRI (0x03): %02x\n", DM9000_ior(3)); - DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4)); - DM9000_DBG("RCR (0x05): %02x\n", DM9000_ior(5)); - DM9000_DBG("RSR (0x06): %02x\n", DM9000_ior(6)); - DM9000_DBG("ISR (0xFE): %02x\n", DM9000_ior(DM9000_ISR)); + DM9000_DBG("NCR (0x00): %02x\n", dm9000_ior(0)); + DM9000_DBG("NSR (0x01): %02x\n", dm9000_ior(1)); + DM9000_DBG("TCR (0x02): %02x\n", dm9000_ior(2)); + DM9000_DBG("TSRI (0x03): %02x\n", dm9000_ior(3)); + DM9000_DBG("TSRII (0x04): %02x\n", dm9000_ior(4)); + DM9000_DBG("RCR (0x05): %02x\n", dm9000_ior(5)); + DM9000_DBG("RSR (0x06): %02x\n", dm9000_ior(6)); + DM9000_DBG("ISR (0xFE): %02x\n", dm9000_ior(DM9000_ISR)); DM9000_DBG("\n"); } #endif @@ -145,7 +145,7 @@ static void dm9000_outblk_8bit(volatile void *data_ptr, int count) { int i; for (i = 0; i < count; i++) - DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA); + dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA); } static void dm9000_outblk_16bit(volatile void *data_ptr, int count) @@ -154,7 +154,7 @@ static void dm9000_outblk_16bit(volatile void *data_ptr, int count) u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA); + dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA); } static void dm9000_outblk_32bit(volatile void *data_ptr, int count) { @@ -162,14 +162,14 @@ static void dm9000_outblk_32bit(volatile void *data_ptr, int count) u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA); + dm9000_outl(((u32 *) data_ptr)[i], DM9000_DATA); } static void dm9000_inblk_8bit(void *data_ptr, int count) { int i; for (i = 0; i < count; i++) - ((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA); + ((u8 *) data_ptr)[i] = dm9000_inb(DM9000_DATA); } static void dm9000_inblk_16bit(void *data_ptr, int count) @@ -178,7 +178,7 @@ static void dm9000_inblk_16bit(void *data_ptr, int count) u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - ((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA); + ((u16 *) data_ptr)[i] = dm9000_inw(DM9000_DATA); } static void dm9000_inblk_32bit(void *data_ptr, int count) { @@ -186,38 +186,38 @@ static void dm9000_inblk_32bit(void *data_ptr, int count) u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - ((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA); + ((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA); } static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen) { u32 tmpdata; - DM9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, DM9000_IO); - tmpdata = DM9000_inl(DM9000_DATA); + tmpdata = dm9000_inl(DM9000_DATA); *RxStatus = __le16_to_cpu(tmpdata); *RxLen = __le16_to_cpu(tmpdata >> 16); } static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen) { - DM9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, DM9000_IO); - *RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA)); - *RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA)); + *RxStatus = __le16_to_cpu(dm9000_inw(DM9000_DATA)); + *RxLen = __le16_to_cpu(dm9000_inw(DM9000_DATA)); } static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen) { - DM9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, DM9000_IO); *RxStatus = - __le16_to_cpu(DM9000_inb(DM9000_DATA) + - (DM9000_inb(DM9000_DATA) << 8)); + __le16_to_cpu(dm9000_inb(DM9000_DATA) + + (dm9000_inb(DM9000_DATA) << 8)); *RxLen = - __le16_to_cpu(DM9000_inb(DM9000_DATA) + - (DM9000_inb(DM9000_DATA) << 8)); + __le16_to_cpu(dm9000_inb(DM9000_DATA) + + (dm9000_inb(DM9000_DATA) << 8)); } /* @@ -227,10 +227,10 @@ int dm9000_probe(void) { u32 id_val; - id_val = DM9000_ior(DM9000_VIDL); - id_val |= DM9000_ior(DM9000_VIDH) << 8; - id_val |= DM9000_ior(DM9000_PIDL) << 16; - id_val |= DM9000_ior(DM9000_PIDH) << 24; + id_val = dm9000_ior(DM9000_VIDL); + id_val |= dm9000_ior(DM9000_VIDH) << 8; + id_val |= dm9000_ior(DM9000_PIDL) << 16; + id_val |= dm9000_ior(DM9000_PIDH) << 24; if (id_val == DM9000_ID) { printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE, id_val); @@ -252,28 +252,28 @@ dm9000_reset(void) see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */ /* DEBUG: Make all GPIO0 outputs, all others inputs */ - DM9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT); + dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT); /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */ - DM9000_iow(DM9000_GPR, 0); + dm9000_iow(DM9000_GPR, 0); /* Step 2: Software reset */ - DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); + dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); do { DM9000_DBG("resetting the DM9000, 1st reset\n"); udelay(25); /* Wait at least 20 us */ - } while (DM9000_ior(DM9000_NCR) & 1); + } while (dm9000_ior(DM9000_NCR) & 1); - DM9000_iow(DM9000_NCR, 0); - DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ + dm9000_iow(DM9000_NCR, 0); + dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ do { DM9000_DBG("resetting the DM9000, 2nd reset\n"); udelay(25); /* Wait at least 20 us */ - } while (DM9000_ior(DM9000_NCR) & 1); + } while (dm9000_ior(DM9000_NCR) & 1); /* Check whether the ethernet controller is present */ - if ((DM9000_ior(DM9000_PIDL) != 0x0) || - (DM9000_ior(DM9000_PIDH) != 0x90)) + if ((dm9000_ior(DM9000_PIDL) != 0x0) || + (dm9000_ior(DM9000_PIDH) != 0x90)) printf("ERROR: resetting DM9000 -> not responding\n"); } @@ -294,7 +294,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) return -1; /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */ - io_mode = DM9000_ior(DM9000_ISR) >> 6; + io_mode = dm9000_ior(DM9000_ISR) >> 6; switch (io_mode) { case 0x0: /* 16-bit mode */ @@ -325,21 +325,21 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) } /* Program operating register, only internal phy supported */ - DM9000_iow(DM9000_NCR, 0x0); + dm9000_iow(DM9000_NCR, 0x0); /* TX Polling clear */ - DM9000_iow(DM9000_TCR, 0); + dm9000_iow(DM9000_TCR, 0); /* Less 3Kb, 200us */ - DM9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US); + dm9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US); /* Flow Control : High/Low Water */ - DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); + dm9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); /* SH FIXME: This looks strange! Flow Control */ - DM9000_iow(DM9000_FCR, 0x0); + dm9000_iow(DM9000_FCR, 0x0); /* Special Mode */ - DM9000_iow(DM9000_SMCR, 0); + dm9000_iow(DM9000_SMCR, 0); /* clear TX status */ - DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); + dm9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); /* Clear interrupt status */ - DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); + dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); printf("MAC: %pM\n", dev->enetaddr); if (!is_valid_ethaddr(dev->enetaddr)) { @@ -348,20 +348,20 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) /* fill device MAC address registers */ for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) - DM9000_iow(oft, dev->enetaddr[i]); + dm9000_iow(oft, dev->enetaddr[i]); for (i = 0, oft = 0x16; i < 8; i++, oft++) - DM9000_iow(oft, 0xff); + dm9000_iow(oft, 0xff); /* read back mac, just to be sure */ for (i = 0, oft = 0x10; i < 6; i++, oft++) - DM9000_DBG("%02x:", DM9000_ior(oft)); + DM9000_DBG("%02x:", dm9000_ior(oft)); DM9000_DBG("\n"); /* Activate DM9000 */ /* RX enable */ - DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); + dm9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); /* Enable TX/RX interrupt mask */ - DM9000_iow(DM9000_IMR, IMR_PAR); + dm9000_iow(DM9000_IMR, IMR_PAR); i = 0; while (!(dm9000_phy_read(1) & 0x20)) { /* autonegation complete bit */ @@ -408,31 +408,31 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length) DM9000_DMP_PACKET(__func__ , packet, length); - DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ + dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ /* Move data to DM9000 TX RAM */ - DM9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */ + dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */ /* push the data to the TX-fifo */ (db->outblk)(packet, length); /* Set TX length to DM9000 */ - DM9000_iow(DM9000_TXPLL, length & 0xff); - DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff); + dm9000_iow(DM9000_TXPLL, length & 0xff); + dm9000_iow(DM9000_TXPLH, (length >> 8) & 0xff); /* Issue TX polling command */ - DM9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ + dm9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ /* wait for end of transmission */ tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; - while ( !(DM9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || - !(DM9000_ior(DM9000_ISR) & IMR_PTM) ) { + while ( !(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || + !(dm9000_ior(DM9000_ISR) & IMR_PTM) ) { if (get_timer(0) >= tmo) { printf("transmission timeout\n"); break; } } - DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ + dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ DM9000_DBG("transmit done\n\n"); return 0; @@ -448,9 +448,9 @@ static void dm9000_halt(struct eth_device *netdev) /* RESET devie */ dm9000_phy_write(0, 0x8000); /* PHY RESET */ - DM9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */ - DM9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */ - DM9000_iow(DM9000_RCR, 0x00); /* Disable RX */ + dm9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */ + dm9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */ + dm9000_iow(DM9000_RCR, 0x00); /* Disable RX */ } /* @@ -465,23 +465,23 @@ static int dm9000_rx(struct eth_device *netdev) /* Check packet ready or not, we must check the ISR status first for DM9000A */ - if (!(DM9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ + if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ return 0; - DM9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ + dm9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ /* There is _at least_ 1 package in the fifo, read them all */ for (;;) { - DM9000_ior(DM9000_MRCMDX); /* Dummy read */ + dm9000_ior(DM9000_MRCMDX); /* Dummy read */ /* Get most updated data, only look at bits 0:1, See application notes DM9000 */ - rxbyte = DM9000_inb(DM9000_DATA) & 0x03; + rxbyte = dm9000_inb(DM9000_DATA) & 0x03; /* Status check: this byte must be 0 or 1 */ if (rxbyte > DM9000_PKT_RDY) { - DM9000_iow(DM9000_RCR, 0x00); /* Stop Device */ - DM9000_iow(DM9000_ISR, 0x80); /* Stop INT request */ + dm9000_iow(DM9000_RCR, 0x00); /* Stop Device */ + dm9000_iow(DM9000_ISR, 0x80); /* Stop INT request */ printf("DM9000 error: status check fail: 0x%x\n", rxbyte); return 0; @@ -532,22 +532,22 @@ static int dm9000_rx(struct eth_device *netdev) #if !defined(CONFIG_DM9000_NO_SROM) void dm9000_read_srom_word(int offset, u8 *to) { - DM9000_iow(DM9000_EPAR, offset); - DM9000_iow(DM9000_EPCR, 0x4); + dm9000_iow(DM9000_EPAR, offset); + dm9000_iow(DM9000_EPCR, 0x4); udelay(8000); - DM9000_iow(DM9000_EPCR, 0x0); - to[0] = DM9000_ior(DM9000_EPDRL); - to[1] = DM9000_ior(DM9000_EPDRH); + dm9000_iow(DM9000_EPCR, 0x0); + to[0] = dm9000_ior(DM9000_EPDRL); + to[1] = dm9000_ior(DM9000_EPDRH); } void dm9000_write_srom_word(int offset, u16 val) { - DM9000_iow(DM9000_EPAR, offset); - DM9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff)); - DM9000_iow(DM9000_EPDRL, (val & 0xff)); - DM9000_iow(DM9000_EPCR, 0x12); + dm9000_iow(DM9000_EPAR, offset); + dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff)); + dm9000_iow(DM9000_EPDRL, (val & 0xff)); + dm9000_iow(DM9000_EPCR, 0x12); udelay(8000); - DM9000_iow(DM9000_EPCR, 0); + dm9000_iow(DM9000_EPCR, 0); } #endif @@ -564,20 +564,20 @@ static void dm9000_get_enetaddr(struct eth_device *dev) Read a byte from I/O port */ static u8 -DM9000_ior(int reg) +dm9000_ior(int reg) { - DM9000_outb(reg, DM9000_IO); - return DM9000_inb(DM9000_DATA); + dm9000_outb(reg, DM9000_IO); + return dm9000_inb(DM9000_DATA); } /* Write a byte to I/O port */ static void -DM9000_iow(int reg, u8 value) +dm9000_iow(int reg, u8 value) { - DM9000_outb(reg, DM9000_IO); - DM9000_outb(value, DM9000_DATA); + dm9000_outb(reg, DM9000_IO); + dm9000_outb(value, DM9000_DATA); } /* @@ -589,11 +589,11 @@ dm9000_phy_read(int reg) u16 val; /* Fill the phyxcer register into REG_0C */ - DM9000_iow(DM9000_EPAR, DM9000_PHY | reg); - DM9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ + dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); + dm9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ udelay(100); /* Wait read complete */ - DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ - val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL); + dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ + val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL); /* The read data keeps on REG_0D & REG_0E */ DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val); @@ -608,14 +608,14 @@ dm9000_phy_write(int reg, u16 value) { /* Fill the phyxcer register into REG_0C */ - DM9000_iow(DM9000_EPAR, DM9000_PHY | reg); + dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); /* Fill the written data into REG_0D & REG_0E */ - DM9000_iow(DM9000_EPDRL, (value & 0xff)); - DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff)); - DM9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ + dm9000_iow(DM9000_EPDRL, (value & 0xff)); + dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff)); + dm9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ udelay(500); /* Wait write complete */ - DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ + dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value); } From 42a7e0f2d745348d623cd2f83fa0138abc27d5f2 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:24 +0200 Subject: [PATCH 26/41] net: dm9000: Replace DM9000_DBG() with debug() Use standard debug() macro to print debug messages instead of reinventing driver-specific macro again. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 48 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 93699135f75..e83b838fd82 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -63,7 +63,6 @@ TODO: external MII is not functional, only internal at the moment. /* #define CONFIG_DM9000_DEBUG */ #ifdef CONFIG_DM9000_DEBUG -#define DM9000_DBG(fmt,args...) printf(fmt, ##args) #define DM9000_DMP_PACKET(func,packet,length) \ do { \ int i; \ @@ -75,7 +74,6 @@ TODO: external MII is not functional, only internal at the moment. } printf("\n"); \ } while(0) #else -#define DM9000_DBG(fmt,args...) #define DM9000_DMP_PACKET(func,packet,length) #endif @@ -128,16 +126,16 @@ static void dm9000_iow(int reg, u8 value); static void dump_regs(void) { - DM9000_DBG("\n"); - DM9000_DBG("NCR (0x00): %02x\n", dm9000_ior(0)); - DM9000_DBG("NSR (0x01): %02x\n", dm9000_ior(1)); - DM9000_DBG("TCR (0x02): %02x\n", dm9000_ior(2)); - DM9000_DBG("TSRI (0x03): %02x\n", dm9000_ior(3)); - DM9000_DBG("TSRII (0x04): %02x\n", dm9000_ior(4)); - DM9000_DBG("RCR (0x05): %02x\n", dm9000_ior(5)); - DM9000_DBG("RSR (0x06): %02x\n", dm9000_ior(6)); - DM9000_DBG("ISR (0xFE): %02x\n", dm9000_ior(DM9000_ISR)); - DM9000_DBG("\n"); + debug("\n"); + debug("NCR (0x00): %02x\n", dm9000_ior(0)); + debug("NSR (0x01): %02x\n", dm9000_ior(1)); + debug("TCR (0x02): %02x\n", dm9000_ior(2)); + debug("TSRI (0x03): %02x\n", dm9000_ior(3)); + debug("TSRII (0x04): %02x\n", dm9000_ior(4)); + debug("RCR (0x05): %02x\n", dm9000_ior(5)); + debug("RSR (0x06): %02x\n", dm9000_ior(6)); + debug("ISR (0xFE): %02x\n", dm9000_ior(DM9000_ISR)); + debug("\n"); } #endif @@ -246,7 +244,7 @@ dm9000_probe(void) static void dm9000_reset(void) { - DM9000_DBG("resetting DM9000\n"); + debug("resetting DM9000\n"); /* Reset DM9000, see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */ @@ -259,7 +257,7 @@ dm9000_reset(void) dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); do { - DM9000_DBG("resetting the DM9000, 1st reset\n"); + debug("resetting the DM9000, 1st reset\n"); udelay(25); /* Wait at least 20 us */ } while (dm9000_ior(DM9000_NCR) & 1); @@ -267,7 +265,7 @@ dm9000_reset(void) dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ do { - DM9000_DBG("resetting the DM9000, 2nd reset\n"); + debug("resetting the DM9000, 2nd reset\n"); udelay(25); /* Wait at least 20 us */ } while (dm9000_ior(DM9000_NCR) & 1); @@ -285,7 +283,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) u8 io_mode; struct board_info *db = &dm9000_info; - DM9000_DBG("%s\n", __func__); + debug("%s\n", __func__); /* RESET device */ dm9000_reset(); @@ -354,8 +352,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) /* read back mac, just to be sure */ for (i = 0, oft = 0x10; i < 6; i++, oft++) - DM9000_DBG("%02x:", dm9000_ior(oft)); - DM9000_DBG("\n"); + debug("%02x:", dm9000_ior(oft)); + debug("\n"); /* Activate DM9000 */ /* RX enable */ @@ -434,7 +432,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length) } dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ - DM9000_DBG("transmit done\n\n"); + debug("transmit done\n\n"); return 0; } @@ -444,7 +442,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length) */ static void dm9000_halt(struct eth_device *netdev) { - DM9000_DBG("%s\n", __func__); + debug("%s\n", __func__); /* RESET devie */ dm9000_phy_write(0, 0x8000); /* PHY RESET */ @@ -490,12 +488,12 @@ static int dm9000_rx(struct eth_device *netdev) if (rxbyte != DM9000_PKT_RDY) return 0; /* No packet received, ignore */ - DM9000_DBG("receiving packet\n"); + debug("receiving packet\n"); /* A packet ready now & Get status/length */ (db->rx_status)(&RxStatus, &RxLen); - DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen); + debug("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen); /* Move data from DM9000 */ /* Read received packet from RX SRAM */ @@ -519,7 +517,7 @@ static int dm9000_rx(struct eth_device *netdev) } else { DM9000_DMP_PACKET(__func__ , rdptr, RxLen); - DM9000_DBG("passing packet to upper layer\n"); + debug("passing packet to upper layer\n"); net_process_received_packet(net_rx_packets[0], RxLen); } } @@ -596,7 +594,7 @@ dm9000_phy_read(int reg) val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL); /* The read data keeps on REG_0D & REG_0E */ - DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val); + debug("dm9000_phy_read(0x%x): 0x%x\n", reg, val); return val; } @@ -616,7 +614,7 @@ dm9000_phy_write(int reg, u16 value) dm9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ udelay(500); /* Wait write complete */ dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ - DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value); + debug("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value); } int dm9000_initialize(struct bd_info *bis) From d8f21b23586f9b460e5a3e791bb59087ed5e0070 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:25 +0200 Subject: [PATCH 27/41] net: dm9000: Make RxLen and RxStatus lowercase Rename variables to lowercase to be consistent with coding style. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index e83b838fd82..a99a901e828 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -92,7 +92,7 @@ typedef struct board_info { unsigned char srom[128]; void (*outblk)(volatile void *data_ptr, int count); void (*inblk)(void *data_ptr, int count); - void (*rx_status)(u16 *RxStatus, u16 *RxLen); + void (*rx_status)(u16 *rxstatus, u16 *rxlen); struct eth_device netdev; } board_info_t; static board_info_t dm9000_info; @@ -187,33 +187,33 @@ static void dm9000_inblk_32bit(void *data_ptr, int count) ((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA); } -static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen) +static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen) { u32 tmpdata; dm9000_outb(DM9000_MRCMD, DM9000_IO); tmpdata = dm9000_inl(DM9000_DATA); - *RxStatus = __le16_to_cpu(tmpdata); - *RxLen = __le16_to_cpu(tmpdata >> 16); + *rxstatus = __le16_to_cpu(tmpdata); + *rxlen = __le16_to_cpu(tmpdata >> 16); } -static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen) +static void dm9000_rx_status_16bit(u16 *rxstatus, u16 *rxlen) { dm9000_outb(DM9000_MRCMD, DM9000_IO); - *RxStatus = __le16_to_cpu(dm9000_inw(DM9000_DATA)); - *RxLen = __le16_to_cpu(dm9000_inw(DM9000_DATA)); + *rxstatus = __le16_to_cpu(dm9000_inw(DM9000_DATA)); + *rxlen = __le16_to_cpu(dm9000_inw(DM9000_DATA)); } -static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen) +static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen) { dm9000_outb(DM9000_MRCMD, DM9000_IO); - *RxStatus = + *rxstatus = __le16_to_cpu(dm9000_inb(DM9000_DATA) + (dm9000_inb(DM9000_DATA) << 8)); - *RxLen = + *rxlen = __le16_to_cpu(dm9000_inb(DM9000_DATA) + (dm9000_inb(DM9000_DATA) << 8)); } @@ -458,7 +458,7 @@ static int dm9000_rx(struct eth_device *netdev) { u8 rxbyte; u8 *rdptr = (u8 *)net_rx_packets[0]; - u16 RxStatus, RxLen = 0; + u16 rxstatus, rxlen = 0; struct board_info *db = &dm9000_info; /* Check packet ready or not, we must check @@ -491,34 +491,34 @@ static int dm9000_rx(struct eth_device *netdev) debug("receiving packet\n"); /* A packet ready now & Get status/length */ - (db->rx_status)(&RxStatus, &RxLen); + (db->rx_status)(&rxstatus, &rxlen); - debug("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen); + debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen); /* Move data from DM9000 */ /* Read received packet from RX SRAM */ - (db->inblk)(rdptr, RxLen); + (db->inblk)(rdptr, rxlen); - if ((RxStatus & 0xbf00) || (RxLen < 0x40) - || (RxLen > DM9000_PKT_MAX)) { - if (RxStatus & 0x100) { + if ((rxstatus & 0xbf00) || (rxlen < 0x40) + || (rxlen > DM9000_PKT_MAX)) { + if (rxstatus & 0x100) { printf("rx fifo error\n"); } - if (RxStatus & 0x200) { + if (rxstatus & 0x200) { printf("rx crc error\n"); } - if (RxStatus & 0x8000) { + if (rxstatus & 0x8000) { printf("rx length error\n"); } - if (RxLen > DM9000_PKT_MAX) { + if (rxlen > DM9000_PKT_MAX) { printf("rx length too big\n"); dm9000_reset(); } } else { - DM9000_DMP_PACKET(__func__ , rdptr, RxLen); + DM9000_DMP_PACKET(__func__ , rdptr, rxlen); debug("passing packet to upper layer\n"); - net_process_received_packet(net_rx_packets[0], RxLen); + net_process_received_packet(net_rx_packets[0], rxlen); } } return 0; From d1854794c04b4a8151a89baab4f507824c2cd1d9 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:26 +0200 Subject: [PATCH 28/41] net: dm9000: Drop unused dump_regs() Drop unused function dump_regs() because it is unused. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index a99a901e828..223df944a48 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -122,23 +122,6 @@ static void dm9000_iow(int reg, u8 value); #define dm9000_inl(r) __raw_readl(r) #endif -#ifdef CONFIG_DM9000_DEBUG -static void -dump_regs(void) -{ - debug("\n"); - debug("NCR (0x00): %02x\n", dm9000_ior(0)); - debug("NSR (0x01): %02x\n", dm9000_ior(1)); - debug("TCR (0x02): %02x\n", dm9000_ior(2)); - debug("TSRI (0x03): %02x\n", dm9000_ior(3)); - debug("TSRII (0x04): %02x\n", dm9000_ior(4)); - debug("RCR (0x05): %02x\n", dm9000_ior(5)); - debug("RSR (0x06): %02x\n", dm9000_ior(6)); - debug("ISR (0xFE): %02x\n", dm9000_ior(DM9000_ISR)); - debug("\n"); -} -#endif - static void dm9000_outblk_8bit(volatile void *data_ptr, int count) { int i; From c7b7ee52b2818a891f5a974a4bdc4a5808a1885b Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:27 +0200 Subject: [PATCH 29/41] net: dm9000: Turn DM9000_DMP_PACKET() into a function Rework DM9000_DMP_PACKET() into dm9000_dump_packet() function, this brings better type checking. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 223df944a48..da16b64610b 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -58,25 +58,6 @@ TODO: external MII is not functional, only internal at the moment. #include "dm9000x.h" -/* Board/System/Debug information/definition ---------------- */ - -/* #define CONFIG_DM9000_DEBUG */ - -#ifdef CONFIG_DM9000_DEBUG -#define DM9000_DMP_PACKET(func,packet,length) \ - do { \ - int i; \ - printf("%s: length: %d\n", func, length); \ - for (i = 0; i < length; i++) { \ - if (i % 8 == 0) \ - printf("\n%s: %02x: ", func, i); \ - printf("%02x ", ((unsigned char *) packet)[i]); \ - } printf("\n"); \ - } while(0) -#else -#define DM9000_DMP_PACKET(func,packet,length) -#endif - /* Structure/enum declaration ------------------------------- */ typedef struct board_info { u32 runt_length_counter; /* counter: RX length < 64byte */ @@ -122,6 +103,25 @@ static void dm9000_iow(int reg, u8 value); #define dm9000_inl(r) __raw_readl(r) #endif +#ifdef DEBUG +static void dm9000_dump_packet(const char *func, u8 *packet, int length) +{ + int i; + + printf("%s: length: %d\n", func, length); + + for (i = 0; i < length; i++) { + if (i % 8 == 0) + printf("\n%s: %02x: ", func, i); + printf("%02x ", packet[i]); + } + + printf("\n"); +} +#else +static void dm9000_dump_packet(const char *func, u8 *packet, int length) {} +#endif + static void dm9000_outblk_8bit(volatile void *data_ptr, int count) { int i; @@ -387,7 +387,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length) int tmo; struct board_info *db = &dm9000_info; - DM9000_DMP_PACKET(__func__ , packet, length); + dm9000_dump_packet(__func__ , packet, length); dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ @@ -498,7 +498,7 @@ static int dm9000_rx(struct eth_device *netdev) dm9000_reset(); } } else { - DM9000_DMP_PACKET(__func__ , rdptr, rxlen); + dm9000_dump_packet(__func__ , rdptr, rxlen); debug("passing packet to upper layer\n"); net_process_received_packet(net_rx_packets[0], rxlen); From 6d3de0f6db043cfe6c9ab51d0755ff0e31348160 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:28 +0200 Subject: [PATCH 30/41] net: dm9000: Drop volatiles Remove volatile keyword usage from arrays, they are not really volatile in any way, so this keyword is misused here. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index da16b64610b..aacf5f670e9 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -71,7 +71,7 @@ typedef struct board_info { u8 phy_addr; u8 device_wait_reset; /* device state */ unsigned char srom[128]; - void (*outblk)(volatile void *data_ptr, int count); + void (*outblk)(void *data_ptr, int count); void (*inblk)(void *data_ptr, int count); void (*rx_status)(u16 *rxstatus, u16 *rxlen); struct eth_device netdev; @@ -88,12 +88,12 @@ static void dm9000_iow(int reg, u8 value); /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED -#define dm9000_outb(d,r) writeb(d, (volatile u8 *)(r)) -#define dm9000_outw(d,r) writew(d, (volatile u16 *)(r)) -#define dm9000_outl(d,r) writel(d, (volatile u32 *)(r)) -#define dm9000_inb(r) readb((volatile u8 *)(r)) -#define dm9000_inw(r) readw((volatile u16 *)(r)) -#define dm9000_inl(r) readl((volatile u32 *)(r)) +#define dm9000_outb(d,r) writeb((d), (r)) +#define dm9000_outw(d,r) writew((d), (r)) +#define dm9000_outl(d,r) writel((d), (r)) +#define dm9000_inb(r) readb(r) +#define dm9000_inw(r) readw(r) +#define dm9000_inl(r) readl(r) #else #define dm9000_outb(d, r) __raw_writeb(d, r) #define dm9000_outw(d, r) __raw_writew(d, r) @@ -122,14 +122,14 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length) static void dm9000_dump_packet(const char *func, u8 *packet, int length) {} #endif -static void dm9000_outblk_8bit(volatile void *data_ptr, int count) +static void dm9000_outblk_8bit(void *data_ptr, int count) { int i; for (i = 0; i < count; i++) dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA); } -static void dm9000_outblk_16bit(volatile void *data_ptr, int count) +static void dm9000_outblk_16bit(void *data_ptr, int count) { int i; u32 tmplen = (count + 1) / 2; @@ -137,7 +137,7 @@ static void dm9000_outblk_16bit(volatile void *data_ptr, int count) for (i = 0; i < tmplen; i++) dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA); } -static void dm9000_outblk_32bit(volatile void *data_ptr, int count) +static void dm9000_outblk_32bit(void *data_ptr, int count) { int i; u32 tmplen = (count + 3) / 4; From a7bebf8d4d325a7cce9fab92018bb331d06e32ca Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:29 +0200 Subject: [PATCH 31/41] net: dm9000: Checkpatch cleanup Fix checkpatch errors and warnings. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 251 +++++++++++++++++++++--------------------- 1 file changed, 126 insertions(+), 125 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index aacf5f670e9..becf7aec828 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -1,53 +1,53 @@ // SPDX-License-Identifier: GPL-2.0+ /* - dm9000.c: Version 1.2 12/15/2003 - - A Davicom DM9000 ISA NIC fast Ethernet driver for Linux. - Copyright (C) 1997 Sten Wang - - (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. - -V0.11 06/20/2001 REG_0A bit3=1, default enable BP with DA match - 06/22/2001 Support DM9801 progrmming - E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000 - E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200 - R17 = (R17 & 0xfff0) | NF + 3 - E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200 - R17 = (R17 & 0xfff0) | NF - -v1.00 modify by simon 2001.9.5 - change for kernel 2.4.x - -v1.1 11/09/2001 fix force mode bug - -v1.2 03/18/2003 Weilun Huang : - Fixed phy reset. - Added tx/rx 32 bit mode. - Cleaned up for kernel merge. - --------------------------------------- - - 12/15/2003 Initial port to u-boot by - Sascha Hauer - - 06/03/2008 Remy Bohmer - - Fixed the driver to work with DM9000A. - (check on ISR receive status bit before reading the - FIFO as described in DM9000 programming guide and - application notes) - - Added autodetect of databus width. - - Made debug code compile again. - - Adapt eth_send such that it matches the DM9000* - application notes. Needed to make it work properly - for DM9000A. - - Adapted reset procedure to match DM9000 application - notes (i.e. double reset) - - some minor code cleanups - These changes are tested with DM9000{A,EP,E} together - with a 200MHz Atmel AT91SAM9261 core - -TODO: external MII is not functional, only internal at the moment. -*/ + * dm9000.c: Version 1.2 12/15/2003 + * + * A Davicom DM9000 ISA NIC fast Ethernet driver for Linux. + * Copyright (C) 1997 Sten Wang + * + * (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. + * + * V0.11 06/20/2001 REG_0A bit3=1, default enable BP with DA match + * 06/22/2001 Support DM9801 progrmming + * E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000 + * E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200 + * R17 = (R17 & 0xfff0) | NF + 3 + * E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200 + * R17 = (R17 & 0xfff0) | NF + * + * v1.00 modify by simon 2001.9.5 + * change for kernel 2.4.x + * + * v1.1 11/09/2001 fix force mode bug + * + * v1.2 03/18/2003 Weilun Huang : + * Fixed phy reset. + * Added tx/rx 32 bit mode. + * Cleaned up for kernel merge. + * + * -------------------------------------- + * + * 12/15/2003 Initial port to u-boot by + * Sascha Hauer + * + * 06/03/2008 Remy Bohmer + * - Fixed the driver to work with DM9000A. + * (check on ISR receive status bit before reading the + * FIFO as described in DM9000 programming guide and + * application notes) + * - Added autodetect of databus width. + * - Made debug code compile again. + * - Adapt eth_send such that it matches the DM9000* + * application notes. Needed to make it work properly + * for DM9000A. + * - Adapted reset procedure to match DM9000 application + * notes (i.e. double reset) + * - some minor code cleanups + * These changes are tested with DM9000{A,EP,E} together + * with a 200MHz Atmel AT91SAM9261 core + * + * TODO: external MII is not functional, only internal at the moment. + */ #include #include @@ -59,7 +59,7 @@ TODO: external MII is not functional, only internal at the moment. #include "dm9000x.h" /* Structure/enum declaration ------------------------------- */ -typedef struct board_info { +struct board_info { u32 runt_length_counter; /* counter: RX length < 64byte */ u32 long_length_counter; /* counter: RX length > 1514byte */ u32 reset_counter; /* counter: RESET */ @@ -75,9 +75,9 @@ typedef struct board_info { void (*inblk)(void *data_ptr, int count); void (*rx_status)(u16 *rxstatus, u16 *rxlen); struct eth_device netdev; -} board_info_t; -static board_info_t dm9000_info; +}; +static struct board_info dm9000_info; /* function declaration ------------------------------------- */ static int dm9000_probe(void); @@ -88,9 +88,9 @@ static void dm9000_iow(int reg, u8 value); /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED -#define dm9000_outb(d,r) writeb((d), (r)) -#define dm9000_outw(d,r) writew((d), (r)) -#define dm9000_outl(d,r) writel((d), (r)) +#define dm9000_outb(d, r) writeb((d), (r)) +#define dm9000_outw(d, r) writew((d), (r)) +#define dm9000_outl(d, r) writel((d), (r)) #define dm9000_inb(r) readb(r) #define dm9000_inw(r) readw(r) #define dm9000_inl(r) readl(r) @@ -125,8 +125,9 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length) {} static void dm9000_outblk_8bit(void *data_ptr, int count) { int i; + for (i = 0; i < count; i++) - dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA); + dm9000_outb((((u8 *)data_ptr)[i] & 0xff), DM9000_DATA); } static void dm9000_outblk_16bit(void *data_ptr, int count) @@ -135,22 +136,24 @@ static void dm9000_outblk_16bit(void *data_ptr, int count) u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA); + dm9000_outw(((u16 *)data_ptr)[i], DM9000_DATA); } + static void dm9000_outblk_32bit(void *data_ptr, int count) { int i; u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - dm9000_outl(((u32 *) data_ptr)[i], DM9000_DATA); + dm9000_outl(((u32 *)data_ptr)[i], DM9000_DATA); } static void dm9000_inblk_8bit(void *data_ptr, int count) { int i; + for (i = 0; i < count; i++) - ((u8 *) data_ptr)[i] = dm9000_inb(DM9000_DATA); + ((u8 *)data_ptr)[i] = dm9000_inb(DM9000_DATA); } static void dm9000_inblk_16bit(void *data_ptr, int count) @@ -159,15 +162,16 @@ static void dm9000_inblk_16bit(void *data_ptr, int count) u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - ((u16 *) data_ptr)[i] = dm9000_inw(DM9000_DATA); + ((u16 *)data_ptr)[i] = dm9000_inw(DM9000_DATA); } + static void dm9000_inblk_32bit(void *data_ptr, int count) { int i; u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - ((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA); + ((u32 *)data_ptr)[i] = dm9000_inl(DM9000_DATA); } static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen) @@ -202,25 +206,25 @@ static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen) } /* - Search DM9000 board, allocate space and register it -*/ + * Search DM9000 board, allocate space and register it + */ int dm9000_probe(void) { u32 id_val; + id_val = dm9000_ior(DM9000_VIDL); id_val |= dm9000_ior(DM9000_VIDH) << 8; id_val |= dm9000_ior(DM9000_PIDL) << 16; id_val |= dm9000_ior(DM9000_PIDH) << 24; - if (id_val == DM9000_ID) { - printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE, - id_val); - return 0; - } else { + if (id_val != DM9000_ID) { printf("dm9000 not found at 0x%08x id: 0x%08x\n", CONFIG_DM9000_BASE, id_val); return -1; } + + printf("dm9000 i/o: 0x%x, id: 0x%x\n", CONFIG_DM9000_BASE, id_val); + return 0; } /* General Purpose dm9000 reset routine */ @@ -229,8 +233,10 @@ dm9000_reset(void) { debug("resetting DM9000\n"); - /* Reset DM9000, - see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */ + /* + * Reset DM9000, + * see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 + */ /* DEBUG: Make all GPIO0 outputs, all others inputs */ dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT); @@ -258,16 +264,13 @@ dm9000_reset(void) printf("ERROR: resetting DM9000 -> not responding\n"); } -/* Initialize dm9000 board -*/ +/* Initialize dm9000 board */ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) { int i, oft, lnk; u8 io_mode; struct board_info *db = &dm9000_info; - debug("%s\n", __func__); - /* RESET device */ dm9000_reset(); @@ -323,9 +326,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); printf("MAC: %pM\n", dev->enetaddr); - if (!is_valid_ethaddr(dev->enetaddr)) { + if (!is_valid_ethaddr(dev->enetaddr)) printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n"); - } /* fill device MAC address registers */ for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) @@ -379,15 +381,15 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) } /* - Hardware start transmission. - Send a packet to media from the upper layer. -*/ + * Hardware start transmission. + * Send a packet to media from the upper layer. + */ static int dm9000_send(struct eth_device *netdev, void *packet, int length) { int tmo; struct board_info *db = &dm9000_info; - dm9000_dump_packet(__func__ , packet, length); + dm9000_dump_packet(__func__, packet, length); dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ @@ -395,7 +397,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length) dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */ /* push the data to the TX-fifo */ - (db->outblk)(packet, length); + db->outblk(packet, length); /* Set TX length to DM9000 */ dm9000_iow(DM9000_TXPLL, length & 0xff); @@ -406,8 +408,8 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length) /* wait for end of transmission */ tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; - while ( !(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || - !(dm9000_ior(DM9000_ISR) & IMR_PTM) ) { + while (!(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || + !(dm9000_ior(DM9000_ISR) & IMR_PTM)) { if (get_timer(0) >= tmo) { printf("transmission timeout\n"); break; @@ -420,14 +422,12 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length) } /* - Stop the interface. - The interface is stopped when it is brought. -*/ + * Stop the interface. + * The interface is stopped when it is brought. + */ static void dm9000_halt(struct eth_device *netdev) { - debug("%s\n", __func__); - - /* RESET devie */ + /* RESET device */ dm9000_phy_write(0, 0x8000); /* PHY RESET */ dm9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */ dm9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */ @@ -435,8 +435,8 @@ static void dm9000_halt(struct eth_device *netdev) } /* - Received a packet and pass to upper layer -*/ + * Received a packet and pass to upper layer + */ static int dm9000_rx(struct eth_device *netdev) { u8 rxbyte; @@ -444,8 +444,10 @@ static int dm9000_rx(struct eth_device *netdev) u16 rxstatus, rxlen = 0; struct board_info *db = &dm9000_info; - /* Check packet ready or not, we must check - the ISR status first for DM9000A */ + /* + * Check packet ready or not, we must check + * the ISR status first for DM9000A + */ if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ return 0; @@ -455,8 +457,10 @@ static int dm9000_rx(struct eth_device *netdev) for (;;) { dm9000_ior(DM9000_MRCMDX); /* Dummy read */ - /* Get most updated data, - only look at bits 0:1, See application notes DM9000 */ + /* + * Get most updated data, + * only look at bits 0:1, See application notes DM9000 + */ rxbyte = dm9000_inb(DM9000_DATA) & 0x03; /* Status check: this byte must be 0 or 1 */ @@ -464,7 +468,7 @@ static int dm9000_rx(struct eth_device *netdev) dm9000_iow(DM9000_RCR, 0x00); /* Stop Device */ dm9000_iow(DM9000_ISR, 0x80); /* Stop INT request */ printf("DM9000 error: status check fail: 0x%x\n", - rxbyte); + rxbyte); return 0; } @@ -474,31 +478,28 @@ static int dm9000_rx(struct eth_device *netdev) debug("receiving packet\n"); /* A packet ready now & Get status/length */ - (db->rx_status)(&rxstatus, &rxlen); + db->rx_status(&rxstatus, &rxlen); debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen); /* Move data from DM9000 */ /* Read received packet from RX SRAM */ - (db->inblk)(rdptr, rxlen); + db->inblk(rdptr, rxlen); - if ((rxstatus & 0xbf00) || (rxlen < 0x40) - || (rxlen > DM9000_PKT_MAX)) { - if (rxstatus & 0x100) { + if (rxstatus & 0xbf00 || rxlen < 0x40 || + rxlen > DM9000_PKT_MAX) { + if (rxstatus & 0x100) printf("rx fifo error\n"); - } - if (rxstatus & 0x200) { + if (rxstatus & 0x200) printf("rx crc error\n"); - } - if (rxstatus & 0x8000) { + if (rxstatus & 0x8000) printf("rx length error\n"); - } if (rxlen > DM9000_PKT_MAX) { printf("rx length too big\n"); dm9000_reset(); } } else { - dm9000_dump_packet(__func__ , rdptr, rxlen); + dm9000_dump_packet(__func__, rdptr, rxlen); debug("passing packet to upper layer\n"); net_process_received_packet(net_rx_packets[0], rxlen); @@ -508,14 +509,14 @@ static int dm9000_rx(struct eth_device *netdev) } /* - Read a word data from SROM -*/ + * Read a word data from SROM + */ #if !defined(CONFIG_DM9000_NO_SROM) void dm9000_read_srom_word(int offset, u8 *to) { dm9000_iow(DM9000_EPAR, offset); dm9000_iow(DM9000_EPCR, 0x4); - udelay(8000); + mdelay(8); dm9000_iow(DM9000_EPCR, 0x0); to[0] = dm9000_ior(DM9000_EPDRL); to[1] = dm9000_ior(DM9000_EPDRH); @@ -527,23 +528,24 @@ void dm9000_write_srom_word(int offset, u16 val) dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff)); dm9000_iow(DM9000_EPDRL, (val & 0xff)); dm9000_iow(DM9000_EPCR, 0x12); - udelay(8000); + mdelay(8); dm9000_iow(DM9000_EPCR, 0); } -#endif static void dm9000_get_enetaddr(struct eth_device *dev) { -#if !defined(CONFIG_DM9000_NO_SROM) int i; + for (i = 0; i < 3; i++) dm9000_read_srom_word(i, dev->enetaddr + (2 * i)); -#endif } +#else +static void dm9000_get_enetaddr(struct eth_device *dev) {} +#endif /* - Read a byte from I/O port -*/ + * Read a byte from I/O port + */ static u8 dm9000_ior(int reg) { @@ -552,8 +554,8 @@ dm9000_ior(int reg) } /* - Write a byte to I/O port -*/ + * Write a byte to I/O port + */ static void dm9000_iow(int reg, u8 value) { @@ -562,8 +564,8 @@ dm9000_iow(int reg, u8 value) } /* - Read a word from phyxcer -*/ + * Read a word from phyxcer + */ static u16 dm9000_phy_read(int reg) { @@ -577,17 +579,16 @@ dm9000_phy_read(int reg) val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL); /* The read data keeps on REG_0D & REG_0E */ - debug("dm9000_phy_read(0x%x): 0x%x\n", reg, val); + debug("%s(0x%x): 0x%x\n", __func__, reg, val); return val; } /* - Write a word to phyxcer -*/ + * Write a word to phyxcer + */ static void dm9000_phy_write(int reg, u16 value) { - /* Fill the phyxcer register into REG_0C */ dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); @@ -597,12 +598,12 @@ dm9000_phy_write(int reg, u16 value) dm9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ udelay(500); /* Wait write complete */ dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ - debug("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value); + debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value); } int dm9000_initialize(struct bd_info *bis) { - struct eth_device *dev = &(dm9000_info.netdev); + struct eth_device *dev = &dm9000_info.netdev; /* Load MAC address from EEPROM */ dm9000_get_enetaddr(dev); From a2e92304bba1b1c3f3f9442cadd6c3b81d2cc0be Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:30 +0200 Subject: [PATCH 32/41] net: dm9000: Reorder and staticize Reorder the driver functions to get rid of forward declarations. Staticize whatever is possible. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 122 +++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 67 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index becf7aec828..85f3c079ec1 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -79,13 +79,6 @@ struct board_info { static struct board_info dm9000_info; -/* function declaration ------------------------------------- */ -static int dm9000_probe(void); -static u16 dm9000_phy_read(int); -static void dm9000_phy_write(int, u16); -static u8 dm9000_ior(int); -static void dm9000_iow(int reg, u8 value); - /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED #define dm9000_outb(d, r) writeb((d), (r)) @@ -205,11 +198,64 @@ static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen) (dm9000_inb(DM9000_DATA) << 8)); } +/* + * Read a byte from I/O port + */ +static u8 dm9000_ior(int reg) +{ + dm9000_outb(reg, DM9000_IO); + return dm9000_inb(DM9000_DATA); +} + +/* + * Write a byte to I/O port + */ +static void dm9000_iow(int reg, u8 value) +{ + dm9000_outb(reg, DM9000_IO); + dm9000_outb(value, DM9000_DATA); +} + +/* + * Read a word from phyxcer + */ +static u16 dm9000_phy_read(int reg) +{ + u16 val; + + /* Fill the phyxcer register into REG_0C */ + dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); + dm9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ + udelay(100); /* Wait read complete */ + dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ + val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL); + + /* The read data keeps on REG_0D & REG_0E */ + debug("%s(0x%x): 0x%x\n", __func__, reg, val); + return val; +} + +/* + * Write a word to phyxcer + */ +static void dm9000_phy_write(int reg, u16 value) +{ + /* Fill the phyxcer register into REG_0C */ + dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); + + /* Fill the written data into REG_0D & REG_0E */ + dm9000_iow(DM9000_EPDRL, (value & 0xff)); + dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff)); + dm9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ + udelay(500); /* Wait write complete */ + dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ + debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value); +} + /* * Search DM9000 board, allocate space and register it */ -int -dm9000_probe(void) +static int dm9000_probe(void) { u32 id_val; @@ -543,64 +589,6 @@ static void dm9000_get_enetaddr(struct eth_device *dev) static void dm9000_get_enetaddr(struct eth_device *dev) {} #endif -/* - * Read a byte from I/O port - */ -static u8 -dm9000_ior(int reg) -{ - dm9000_outb(reg, DM9000_IO); - return dm9000_inb(DM9000_DATA); -} - -/* - * Write a byte to I/O port - */ -static void -dm9000_iow(int reg, u8 value) -{ - dm9000_outb(reg, DM9000_IO); - dm9000_outb(value, DM9000_DATA); -} - -/* - * Read a word from phyxcer - */ -static u16 -dm9000_phy_read(int reg) -{ - u16 val; - - /* Fill the phyxcer register into REG_0C */ - dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); - dm9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ - udelay(100); /* Wait read complete */ - dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ - val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL); - - /* The read data keeps on REG_0D & REG_0E */ - debug("%s(0x%x): 0x%x\n", __func__, reg, val); - return val; -} - -/* - * Write a word to phyxcer - */ -static void -dm9000_phy_write(int reg, u16 value) -{ - /* Fill the phyxcer register into REG_0C */ - dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); - - /* Fill the written data into REG_0D & REG_0E */ - dm9000_iow(DM9000_EPDRL, (value & 0xff)); - dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff)); - dm9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ - udelay(500); /* Wait write complete */ - dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ - debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value); -} - int dm9000_initialize(struct bd_info *bis) { struct eth_device *dev = &dm9000_info.netdev; From 8371edd52f5adc36ea5b6811e7fa213e4c6daa37 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:31 +0200 Subject: [PATCH 33/41] net: dm9000: Rename board_info to dm9000_priv Rename board_info structure to dm9000_priv to make it clear what this structure really contains, the driver private data. No functional change. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 85f3c079ec1..7e1368a1be9 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -59,7 +59,7 @@ #include "dm9000x.h" /* Structure/enum declaration ------------------------------- */ -struct board_info { +struct dm9000_priv { u32 runt_length_counter; /* counter: RX length < 64byte */ u32 long_length_counter; /* counter: RX length > 1514byte */ u32 reset_counter; /* counter: RESET */ @@ -77,7 +77,7 @@ struct board_info { struct eth_device netdev; }; -static struct board_info dm9000_info; +static struct dm9000_priv dm9000_info; /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED @@ -315,7 +315,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) { int i, oft, lnk; u8 io_mode; - struct board_info *db = &dm9000_info; + struct dm9000_priv *db = &dm9000_info; /* RESET device */ dm9000_reset(); @@ -433,7 +433,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) static int dm9000_send(struct eth_device *netdev, void *packet, int length) { int tmo; - struct board_info *db = &dm9000_info; + struct dm9000_priv *db = &dm9000_info; dm9000_dump_packet(__func__, packet, length); @@ -488,7 +488,7 @@ static int dm9000_rx(struct eth_device *netdev) u8 rxbyte; u8 *rdptr = (u8 *)net_rx_packets[0]; u16 rxstatus, rxlen = 0; - struct board_info *db = &dm9000_info; + struct dm9000_priv *db = &dm9000_info; /* * Check packet ready or not, we must check From 3928055e4fd2d2b00cacadebee6233e869eadbfc Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:32 +0200 Subject: [PATCH 34/41] net: dm9000: Drop static device private data Allocate driver private data dynamically in its init function and drop the static driver private data variable. Pass the dynamic private data throughout the driver. This is done in preparation for DM conversion. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 7e1368a1be9..36411bd8ebd 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -74,11 +75,9 @@ struct dm9000_priv { void (*outblk)(void *data_ptr, int count); void (*inblk)(void *data_ptr, int count); void (*rx_status)(u16 *rxstatus, u16 *rxlen); - struct eth_device netdev; + struct eth_device dev; }; -static struct dm9000_priv dm9000_info; - /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED #define dm9000_outb(d, r) writeb((d), (r)) @@ -313,9 +312,9 @@ dm9000_reset(void) /* Initialize dm9000 board */ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int i, oft, lnk; u8 io_mode; - struct dm9000_priv *db = &dm9000_info; /* RESET device */ dm9000_reset(); @@ -430,10 +429,10 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) * Hardware start transmission. * Send a packet to media from the upper layer. */ -static int dm9000_send(struct eth_device *netdev, void *packet, int length) +static int dm9000_send(struct eth_device *dev, void *packet, int length) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int tmo; - struct dm9000_priv *db = &dm9000_info; dm9000_dump_packet(__func__, packet, length); @@ -483,12 +482,12 @@ static void dm9000_halt(struct eth_device *netdev) /* * Received a packet and pass to upper layer */ -static int dm9000_rx(struct eth_device *netdev) +static int dm9000_rx(struct eth_device *dev) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); u8 rxbyte; u8 *rdptr = (u8 *)net_rx_packets[0]; u16 rxstatus, rxlen = 0; - struct dm9000_priv *db = &dm9000_info; /* * Check packet ready or not, we must check @@ -591,10 +590,17 @@ static void dm9000_get_enetaddr(struct eth_device *dev) {} int dm9000_initialize(struct bd_info *bis) { - struct eth_device *dev = &dm9000_info.netdev; + struct dm9000_priv *priv; + struct eth_device *dev; + + priv = calloc(1, sizeof(*priv)); + if (!priv) + return -ENOMEM; + + dev = &priv->dev; /* Load MAC address from EEPROM */ - dm9000_get_enetaddr(dev); + dm9000_get_enetaddr(&priv->dev); dev->init = dm9000_init; dev->halt = dm9000_halt; @@ -602,7 +608,7 @@ int dm9000_initialize(struct bd_info *bis) dev->recv = dm9000_rx; strcpy(dev->name, "dm9000"); - eth_register(dev); + eth_register(&priv->dev); return 0; } From 1494a4aacef17a3fc94847104e98d083da7659c9 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:33 +0200 Subject: [PATCH 35/41] net: dm9000: Drop dm9000.h and staticize SROM access Dispose of dm9000.h because none of the function prototypes declared in it are called anywhere in the codebase. Staticize dm9000_read_srom_word() because it is now called only from within the dm9000 driver. Drop dm9000_write_srom_word() because it is no longer used. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 13 +------------ include/dm9000.h | 16 ---------------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 include/dm9000.h diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 36411bd8ebd..a8ce8ac02ee 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -54,7 +54,6 @@ #include #include #include -#include #include #include "dm9000x.h" @@ -557,7 +556,7 @@ static int dm9000_rx(struct eth_device *dev) * Read a word data from SROM */ #if !defined(CONFIG_DM9000_NO_SROM) -void dm9000_read_srom_word(int offset, u8 *to) +static void dm9000_read_srom_word(int offset, u8 *to) { dm9000_iow(DM9000_EPAR, offset); dm9000_iow(DM9000_EPCR, 0x4); @@ -567,16 +566,6 @@ void dm9000_read_srom_word(int offset, u8 *to) to[1] = dm9000_ior(DM9000_EPDRH); } -void dm9000_write_srom_word(int offset, u16 val) -{ - dm9000_iow(DM9000_EPAR, offset); - dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff)); - dm9000_iow(DM9000_EPDRL, (val & 0xff)); - dm9000_iow(DM9000_EPCR, 0x12); - mdelay(8); - dm9000_iow(DM9000_EPCR, 0); -} - static void dm9000_get_enetaddr(struct eth_device *dev) { int i; diff --git a/include/dm9000.h b/include/dm9000.h deleted file mode 100644 index f780e513f69..00000000000 --- a/include/dm9000.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * NOTE: DAVICOM DM9000 ethernet driver interface - * - * Authors: Remy Bohmer - */ -#ifndef __DM9000_H__ -#define __DM9000_H__ - -/****************** function prototypes **********************/ -#if !defined(CONFIG_DM9000_NO_SROM) -void dm9000_write_srom_word(int offset, u16 val); -void dm9000_read_srom_word(int offset, u8 *to); -#endif - -#endif /* __DM9000_H__ */ From f0d1a29dc5e2dbdc42223d409b72ae110e95dc28 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:34 +0200 Subject: [PATCH 36/41] net: dm9000: Pass private data around for IO Pass private data into IO accessors and use the base addresses of IO and DATA window from the private data instead of using the hard coded macros DM9000_IO/DM9000_DATA. Currently both the DM9000_IO and DM9000_DATA are assigned to the respecive private data fields for the non-DM case backward compatibility. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 230 ++++++++++++++++++++++-------------------- 1 file changed, 119 insertions(+), 111 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index a8ce8ac02ee..a40e60bbe61 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -71,10 +71,12 @@ struct dm9000_priv { u8 phy_addr; u8 device_wait_reset; /* device state */ unsigned char srom[128]; - void (*outblk)(void *data_ptr, int count); - void (*inblk)(void *data_ptr, int count); - void (*rx_status)(u16 *rxstatus, u16 *rxlen); + void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count); + void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count); + void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen); struct eth_device dev; + void __iomem *base_io; + void __iomem *base_data; }; /* DM9000 network board routine ---------------------------- */ @@ -113,120 +115,121 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length) static void dm9000_dump_packet(const char *func, u8 *packet, int length) {} #endif -static void dm9000_outblk_8bit(void *data_ptr, int count) +static void dm9000_outblk_8bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; for (i = 0; i < count; i++) - dm9000_outb((((u8 *)data_ptr)[i] & 0xff), DM9000_DATA); + dm9000_outb((((u8 *)data_ptr)[i] & 0xff), db->base_data); } -static void dm9000_outblk_16bit(void *data_ptr, int count) +static void dm9000_outblk_16bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - dm9000_outw(((u16 *)data_ptr)[i], DM9000_DATA); + dm9000_outw(((u16 *)data_ptr)[i], db->base_data); } -static void dm9000_outblk_32bit(void *data_ptr, int count) +static void dm9000_outblk_32bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - dm9000_outl(((u32 *)data_ptr)[i], DM9000_DATA); + dm9000_outl(((u32 *)data_ptr)[i], db->base_data); } -static void dm9000_inblk_8bit(void *data_ptr, int count) +static void dm9000_inblk_8bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; for (i = 0; i < count; i++) - ((u8 *)data_ptr)[i] = dm9000_inb(DM9000_DATA); + ((u8 *)data_ptr)[i] = dm9000_inb(db->base_data); } -static void dm9000_inblk_16bit(void *data_ptr, int count) +static void dm9000_inblk_16bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - ((u16 *)data_ptr)[i] = dm9000_inw(DM9000_DATA); + ((u16 *)data_ptr)[i] = dm9000_inw(db->base_data); } -static void dm9000_inblk_32bit(void *data_ptr, int count) +static void dm9000_inblk_32bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - ((u32 *)data_ptr)[i] = dm9000_inl(DM9000_DATA); + ((u32 *)data_ptr)[i] = dm9000_inl(db->base_data); } -static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen) +static void dm9000_rx_status_32bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen) { u32 tmpdata; - dm9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, db->base_io); - tmpdata = dm9000_inl(DM9000_DATA); + tmpdata = dm9000_inl(db->base_data); *rxstatus = __le16_to_cpu(tmpdata); *rxlen = __le16_to_cpu(tmpdata >> 16); } -static void dm9000_rx_status_16bit(u16 *rxstatus, u16 *rxlen) +static void dm9000_rx_status_16bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen) { - dm9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, db->base_io); - *rxstatus = __le16_to_cpu(dm9000_inw(DM9000_DATA)); - *rxlen = __le16_to_cpu(dm9000_inw(DM9000_DATA)); + *rxstatus = __le16_to_cpu(dm9000_inw(db->base_data)); + *rxlen = __le16_to_cpu(dm9000_inw(db->base_data)); } -static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen) +static void dm9000_rx_status_8bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen) { - dm9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, db->base_io); *rxstatus = - __le16_to_cpu(dm9000_inb(DM9000_DATA) + - (dm9000_inb(DM9000_DATA) << 8)); + __le16_to_cpu(dm9000_inb(db->base_data) + + (dm9000_inb(db->base_data) << 8)); *rxlen = - __le16_to_cpu(dm9000_inb(DM9000_DATA) + - (dm9000_inb(DM9000_DATA) << 8)); + __le16_to_cpu(dm9000_inb(db->base_data) + + (dm9000_inb(db->base_data) << 8)); } /* * Read a byte from I/O port */ -static u8 dm9000_ior(int reg) +static u8 dm9000_ior(struct dm9000_priv *db, int reg) { - dm9000_outb(reg, DM9000_IO); - return dm9000_inb(DM9000_DATA); + dm9000_outb(reg, db->base_io); + return dm9000_inb(db->base_data); } /* * Write a byte to I/O port */ -static void dm9000_iow(int reg, u8 value) +static void dm9000_iow(struct dm9000_priv *db, int reg, u8 value) { - dm9000_outb(reg, DM9000_IO); - dm9000_outb(value, DM9000_DATA); + dm9000_outb(reg, db->base_io); + dm9000_outb(value, db->base_data); } /* * Read a word from phyxcer */ -static u16 dm9000_phy_read(int reg) +static u16 dm9000_phy_read(struct dm9000_priv *db, int reg) { u16 val; /* Fill the phyxcer register into REG_0C */ - dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); - dm9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ + dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg); + dm9000_iow(db, DM9000_EPCR, 0xc); /* Issue phyxcer read command */ udelay(100); /* Wait read complete */ - dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ - val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL); + dm9000_iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */ + val = (dm9000_ior(db, DM9000_EPDRH) << 8) | + dm9000_ior(db, DM9000_EPDRL); /* The read data keeps on REG_0D & REG_0E */ debug("%s(0x%x): 0x%x\n", __func__, reg, val); @@ -236,44 +239,43 @@ static u16 dm9000_phy_read(int reg) /* * Write a word to phyxcer */ -static void dm9000_phy_write(int reg, u16 value) +static void dm9000_phy_write(struct dm9000_priv *db, int reg, u16 value) { /* Fill the phyxcer register into REG_0C */ - dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); + dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg); /* Fill the written data into REG_0D & REG_0E */ - dm9000_iow(DM9000_EPDRL, (value & 0xff)); - dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff)); - dm9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ + dm9000_iow(db, DM9000_EPDRL, (value & 0xff)); + dm9000_iow(db, DM9000_EPDRH, ((value >> 8) & 0xff)); + dm9000_iow(db, DM9000_EPCR, 0xa); /* Issue phyxcer write command */ udelay(500); /* Wait write complete */ - dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ + dm9000_iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */ debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value); } /* * Search DM9000 board, allocate space and register it */ -static int dm9000_probe(void) +static int dm9000_probe(struct dm9000_priv *db) { u32 id_val; - id_val = dm9000_ior(DM9000_VIDL); - id_val |= dm9000_ior(DM9000_VIDH) << 8; - id_val |= dm9000_ior(DM9000_PIDL) << 16; - id_val |= dm9000_ior(DM9000_PIDH) << 24; + id_val = dm9000_ior(db, DM9000_VIDL); + id_val |= dm9000_ior(db, DM9000_VIDH) << 8; + id_val |= dm9000_ior(db, DM9000_PIDL) << 16; + id_val |= dm9000_ior(db, DM9000_PIDH) << 24; if (id_val != DM9000_ID) { - printf("dm9000 not found at 0x%08x id: 0x%08x\n", - CONFIG_DM9000_BASE, id_val); + printf("dm9000 not found at 0x%p id: 0x%08x\n", + db->base_io, id_val); return -1; } - printf("dm9000 i/o: 0x%x, id: 0x%x\n", CONFIG_DM9000_BASE, id_val); + printf("dm9000 i/o: 0x%p, id: 0x%x\n", db->base_io, id_val); return 0; } /* General Purpose dm9000 reset routine */ -static void -dm9000_reset(void) +static void dm9000_reset(struct dm9000_priv *db) { debug("resetting DM9000\n"); @@ -283,28 +285,28 @@ dm9000_reset(void) */ /* DEBUG: Make all GPIO0 outputs, all others inputs */ - dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT); + dm9000_iow(db, DM9000_GPCR, GPCR_GPIO0_OUT); /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */ - dm9000_iow(DM9000_GPR, 0); + dm9000_iow(db, DM9000_GPR, 0); /* Step 2: Software reset */ - dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); + dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); do { debug("resetting the DM9000, 1st reset\n"); udelay(25); /* Wait at least 20 us */ - } while (dm9000_ior(DM9000_NCR) & 1); + } while (dm9000_ior(db, DM9000_NCR) & 1); - dm9000_iow(DM9000_NCR, 0); - dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ + dm9000_iow(db, DM9000_NCR, 0); + dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ do { debug("resetting the DM9000, 2nd reset\n"); udelay(25); /* Wait at least 20 us */ - } while (dm9000_ior(DM9000_NCR) & 1); + } while (dm9000_ior(db, DM9000_NCR) & 1); /* Check whether the ethernet controller is present */ - if ((dm9000_ior(DM9000_PIDL) != 0x0) || - (dm9000_ior(DM9000_PIDH) != 0x90)) + if ((dm9000_ior(db, DM9000_PIDL) != 0x0) || + (dm9000_ior(db, DM9000_PIDH) != 0x90)) printf("ERROR: resetting DM9000 -> not responding\n"); } @@ -316,13 +318,13 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) u8 io_mode; /* RESET device */ - dm9000_reset(); + dm9000_reset(db); - if (dm9000_probe() < 0) + if (dm9000_probe(db) < 0) return -1; /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */ - io_mode = dm9000_ior(DM9000_ISR) >> 6; + io_mode = dm9000_ior(db, DM9000_ISR) >> 6; switch (io_mode) { case 0x0: /* 16-bit mode */ @@ -353,21 +355,21 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) } /* Program operating register, only internal phy supported */ - dm9000_iow(DM9000_NCR, 0x0); + dm9000_iow(db, DM9000_NCR, 0x0); /* TX Polling clear */ - dm9000_iow(DM9000_TCR, 0); + dm9000_iow(db, DM9000_TCR, 0); /* Less 3Kb, 200us */ - dm9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US); + dm9000_iow(db, DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US); /* Flow Control : High/Low Water */ - dm9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); + dm9000_iow(db, DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); /* SH FIXME: This looks strange! Flow Control */ - dm9000_iow(DM9000_FCR, 0x0); + dm9000_iow(db, DM9000_FCR, 0x0); /* Special Mode */ - dm9000_iow(DM9000_SMCR, 0); + dm9000_iow(db, DM9000_SMCR, 0); /* clear TX status */ - dm9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); + dm9000_iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); /* Clear interrupt status */ - dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); + dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); printf("MAC: %pM\n", dev->enetaddr); if (!is_valid_ethaddr(dev->enetaddr)) @@ -375,23 +377,23 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) /* fill device MAC address registers */ for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) - dm9000_iow(oft, dev->enetaddr[i]); + dm9000_iow(db, oft, dev->enetaddr[i]); for (i = 0, oft = 0x16; i < 8; i++, oft++) - dm9000_iow(oft, 0xff); + dm9000_iow(db, oft, 0xff); /* read back mac, just to be sure */ for (i = 0, oft = 0x10; i < 6; i++, oft++) - debug("%02x:", dm9000_ior(oft)); + debug("%02x:", dm9000_ior(db, oft)); debug("\n"); /* Activate DM9000 */ /* RX enable */ - dm9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); + dm9000_iow(db, DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); /* Enable TX/RX interrupt mask */ - dm9000_iow(DM9000_IMR, IMR_PAR); + dm9000_iow(db, DM9000_IMR, IMR_PAR); i = 0; - while (!(dm9000_phy_read(1) & 0x20)) { /* autonegation complete bit */ + while (!(dm9000_phy_read(db, 1) & 0x20)) { /* autonegation complete bit */ udelay(1000); i++; if (i == 10000) { @@ -401,7 +403,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) } /* see what we've got */ - lnk = dm9000_phy_read(17) >> 12; + lnk = dm9000_phy_read(db, 17) >> 12; printf("operating at "); switch (lnk) { case 1: @@ -435,31 +437,31 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length) dm9000_dump_packet(__func__, packet, length); - dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ + dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ /* Move data to DM9000 TX RAM */ - dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */ + dm9000_outb(DM9000_MWCMD, db->base_io); /* Prepare for TX-data */ /* push the data to the TX-fifo */ - db->outblk(packet, length); + db->outblk(db, packet, length); /* Set TX length to DM9000 */ - dm9000_iow(DM9000_TXPLL, length & 0xff); - dm9000_iow(DM9000_TXPLH, (length >> 8) & 0xff); + dm9000_iow(db, DM9000_TXPLL, length & 0xff); + dm9000_iow(db, DM9000_TXPLH, (length >> 8) & 0xff); /* Issue TX polling command */ - dm9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ + dm9000_iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ /* wait for end of transmission */ tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; - while (!(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || - !(dm9000_ior(DM9000_ISR) & IMR_PTM)) { + while (!(dm9000_ior(db, DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || + !(dm9000_ior(db, DM9000_ISR) & IMR_PTM)) { if (get_timer(0) >= tmo) { printf("transmission timeout\n"); break; } } - dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ + dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ debug("transmit done\n\n"); return 0; @@ -471,11 +473,13 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length) */ static void dm9000_halt(struct eth_device *netdev) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + /* RESET device */ - dm9000_phy_write(0, 0x8000); /* PHY RESET */ - dm9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */ - dm9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */ - dm9000_iow(DM9000_RCR, 0x00); /* Disable RX */ + dm9000_phy_write(db, 0, 0x8000); /* PHY RESET */ + dm9000_iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */ + dm9000_iow(db, DM9000_IMR, 0x80); /* Disable all interrupt */ + dm9000_iow(db, DM9000_RCR, 0x00); /* Disable RX */ } /* @@ -492,25 +496,25 @@ static int dm9000_rx(struct eth_device *dev) * Check packet ready or not, we must check * the ISR status first for DM9000A */ - if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ + if (!(dm9000_ior(db, DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ return 0; - dm9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ + dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ /* There is _at least_ 1 package in the fifo, read them all */ for (;;) { - dm9000_ior(DM9000_MRCMDX); /* Dummy read */ + dm9000_ior(db, DM9000_MRCMDX); /* Dummy read */ /* * Get most updated data, * only look at bits 0:1, See application notes DM9000 */ - rxbyte = dm9000_inb(DM9000_DATA) & 0x03; + rxbyte = dm9000_inb(db->base_data) & 0x03; /* Status check: this byte must be 0 or 1 */ if (rxbyte > DM9000_PKT_RDY) { - dm9000_iow(DM9000_RCR, 0x00); /* Stop Device */ - dm9000_iow(DM9000_ISR, 0x80); /* Stop INT request */ + dm9000_iow(db, DM9000_RCR, 0x00); /* Stop Device */ + dm9000_iow(db, DM9000_ISR, 0x80); /* Stop INT request */ printf("DM9000 error: status check fail: 0x%x\n", rxbyte); return 0; @@ -522,13 +526,13 @@ static int dm9000_rx(struct eth_device *dev) debug("receiving packet\n"); /* A packet ready now & Get status/length */ - db->rx_status(&rxstatus, &rxlen); + db->rx_status(db, &rxstatus, &rxlen); debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen); /* Move data from DM9000 */ /* Read received packet from RX SRAM */ - db->inblk(rdptr, rxlen); + db->inblk(db, rdptr, rxlen); if (rxstatus & 0xbf00 || rxlen < 0x40 || rxlen > DM9000_PKT_MAX) { @@ -540,7 +544,7 @@ static int dm9000_rx(struct eth_device *dev) printf("rx length error\n"); if (rxlen > DM9000_PKT_MAX) { printf("rx length too big\n"); - dm9000_reset(); + dm9000_reset(db); } } else { dm9000_dump_packet(__func__, rdptr, rxlen); @@ -556,22 +560,23 @@ static int dm9000_rx(struct eth_device *dev) * Read a word data from SROM */ #if !defined(CONFIG_DM9000_NO_SROM) -static void dm9000_read_srom_word(int offset, u8 *to) +static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to) { - dm9000_iow(DM9000_EPAR, offset); - dm9000_iow(DM9000_EPCR, 0x4); + dm9000_iow(db, DM9000_EPAR, offset); + dm9000_iow(db, DM9000_EPCR, 0x4); mdelay(8); - dm9000_iow(DM9000_EPCR, 0x0); - to[0] = dm9000_ior(DM9000_EPDRL); - to[1] = dm9000_ior(DM9000_EPDRH); + dm9000_iow(db, DM9000_EPCR, 0x0); + to[0] = dm9000_ior(db, DM9000_EPDRL); + to[1] = dm9000_ior(db, DM9000_EPDRH); } static void dm9000_get_enetaddr(struct eth_device *dev) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int i; for (i = 0; i < 3; i++) - dm9000_read_srom_word(i, dev->enetaddr + (2 * i)); + dm9000_read_srom_word(db, i, dev->enetaddr + (2 * i)); } #else static void dm9000_get_enetaddr(struct eth_device *dev) {} @@ -588,6 +593,9 @@ int dm9000_initialize(struct bd_info *bis) dev = &priv->dev; + priv->base_io = (void __iomem *)DM9000_IO; + priv->base_data = (void __iomem *)DM9000_DATA; + /* Load MAC address from EEPROM */ dm9000_get_enetaddr(&priv->dev); From 85a72601863570c6c455ccaaa098fbd03af3ecd8 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:35 +0200 Subject: [PATCH 37/41] net: dm9000: Split non-DM specific bits from common code Split network handling functions into non-DM specific parts and common code in preparation for conversion to DM. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 58 +++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index a40e60bbe61..639977ad6e6 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -311,9 +311,8 @@ static void dm9000_reset(struct dm9000_priv *db) } /* Initialize dm9000 board */ -static int dm9000_init(struct eth_device *dev, struct bd_info *bd) +static int dm9000_init_common(struct dm9000_priv *db, u8 enetaddr[6]) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int i, oft, lnk; u8 io_mode; @@ -371,13 +370,13 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) /* Clear interrupt status */ dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); - printf("MAC: %pM\n", dev->enetaddr); - if (!is_valid_ethaddr(dev->enetaddr)) + printf("MAC: %pM\n", enetaddr); + if (!is_valid_ethaddr(enetaddr)) printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n"); /* fill device MAC address registers */ for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) - dm9000_iow(db, oft, dev->enetaddr[i]); + dm9000_iow(db, oft, enetaddr[i]); for (i = 0, oft = 0x16; i < 8; i++, oft++) dm9000_iow(db, oft, 0xff); @@ -430,9 +429,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) * Hardware start transmission. * Send a packet to media from the upper layer. */ -static int dm9000_send(struct eth_device *dev, void *packet, int length) +static int dm9000_send_common(struct dm9000_priv *db, void *packet, int length) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int tmo; dm9000_dump_packet(__func__, packet, length); @@ -471,10 +469,8 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length) * Stop the interface. * The interface is stopped when it is brought. */ -static void dm9000_halt(struct eth_device *netdev) +static void dm9000_halt_common(struct dm9000_priv *db) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); - /* RESET device */ dm9000_phy_write(db, 0, 0x8000); /* PHY RESET */ dm9000_iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */ @@ -485,9 +481,8 @@ static void dm9000_halt(struct eth_device *netdev) /* * Received a packet and pass to upper layer */ -static int dm9000_rx(struct eth_device *dev) +static int dm9000_recv_common(struct dm9000_priv *db) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); u8 rxbyte; u8 *rdptr = (u8 *)net_rx_packets[0]; u16 rxstatus, rxlen = 0; @@ -570,18 +565,45 @@ static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to) to[1] = dm9000_ior(db, DM9000_EPDRH); } -static void dm9000_get_enetaddr(struct eth_device *dev) +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) { - struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); int i; for (i = 0; i < 3; i++) - dm9000_read_srom_word(db, i, dev->enetaddr + (2 * i)); + dm9000_read_srom_word(db, i, enetaddr + (2 * i)); } #else -static void dm9000_get_enetaddr(struct eth_device *dev) {} +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {} #endif +static int dm9000_init(struct eth_device *dev, struct bd_info *bd) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + return dm9000_init_common(db, dev->enetaddr); +} + +static void dm9000_halt(struct eth_device *dev) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + dm9000_halt_common(db); +} + +static int dm9000_send(struct eth_device *dev, void *packet, int length) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + return dm9000_send_common(db, packet, length); +} + +static int dm9000_recv(struct eth_device *dev) +{ + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + return dm9000_recv_common(db); +} + int dm9000_initialize(struct bd_info *bis) { struct dm9000_priv *priv; @@ -597,12 +619,12 @@ int dm9000_initialize(struct bd_info *bis) priv->base_data = (void __iomem *)DM9000_DATA; /* Load MAC address from EEPROM */ - dm9000_get_enetaddr(&priv->dev); + dm9000_get_enetaddr(priv, dev->enetaddr); dev->init = dm9000_init; dev->halt = dm9000_halt; dev->send = dm9000_send; - dev->recv = dm9000_rx; + dev->recv = dm9000_recv; strcpy(dev->name, "dm9000"); eth_register(&priv->dev); From 84bf20f6ce8beb014bb77eab00cd96fe2fbfd689 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:36 +0200 Subject: [PATCH 38/41] net: dm9000: Receive one packet per recv call Instead of reading out the entire FIFO and possibly overwriting U-Boot memory, read out one packet per recv call, pass it to U-Boot network stack, and repeat. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 102 +++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 639977ad6e6..6552079748a 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -481,10 +481,9 @@ static void dm9000_halt_common(struct dm9000_priv *db) /* * Received a packet and pass to upper layer */ -static int dm9000_recv_common(struct dm9000_priv *db) +static int dm9000_recv_common(struct dm9000_priv *db, uchar *rdptr) { u8 rxbyte; - u8 *rdptr = (u8 *)net_rx_packets[0]; u16 rxstatus, rxlen = 0; /* @@ -497,58 +496,52 @@ static int dm9000_recv_common(struct dm9000_priv *db) dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ /* There is _at least_ 1 package in the fifo, read them all */ - for (;;) { - dm9000_ior(db, DM9000_MRCMDX); /* Dummy read */ + dm9000_ior(db, DM9000_MRCMDX); /* Dummy read */ - /* - * Get most updated data, - * only look at bits 0:1, See application notes DM9000 - */ - rxbyte = dm9000_inb(db->base_data) & 0x03; + /* + * Get most updated data, + * only look at bits 0:1, See application notes DM9000 + */ + rxbyte = dm9000_inb(db->base_data) & 0x03; - /* Status check: this byte must be 0 or 1 */ - if (rxbyte > DM9000_PKT_RDY) { - dm9000_iow(db, DM9000_RCR, 0x00); /* Stop Device */ - dm9000_iow(db, DM9000_ISR, 0x80); /* Stop INT request */ - printf("DM9000 error: status check fail: 0x%x\n", - rxbyte); - return 0; - } - - if (rxbyte != DM9000_PKT_RDY) - return 0; /* No packet received, ignore */ - - debug("receiving packet\n"); - - /* A packet ready now & Get status/length */ - db->rx_status(db, &rxstatus, &rxlen); - - debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen); - - /* Move data from DM9000 */ - /* Read received packet from RX SRAM */ - db->inblk(db, rdptr, rxlen); - - if (rxstatus & 0xbf00 || rxlen < 0x40 || - rxlen > DM9000_PKT_MAX) { - if (rxstatus & 0x100) - printf("rx fifo error\n"); - if (rxstatus & 0x200) - printf("rx crc error\n"); - if (rxstatus & 0x8000) - printf("rx length error\n"); - if (rxlen > DM9000_PKT_MAX) { - printf("rx length too big\n"); - dm9000_reset(db); - } - } else { - dm9000_dump_packet(__func__, rdptr, rxlen); - - debug("passing packet to upper layer\n"); - net_process_received_packet(net_rx_packets[0], rxlen); - } + /* Status check: this byte must be 0 or 1 */ + if (rxbyte > DM9000_PKT_RDY) { + dm9000_iow(db, DM9000_RCR, 0x00); /* Stop Device */ + dm9000_iow(db, DM9000_ISR, 0x80); /* Stop INT request */ + printf("DM9000 error: status check fail: 0x%x\n", + rxbyte); + return -EINVAL; } - return 0; + + if (rxbyte != DM9000_PKT_RDY) + return 0; /* No packet received, ignore */ + + debug("receiving packet\n"); + + /* A packet ready now & Get status/length */ + db->rx_status(db, &rxstatus, &rxlen); + + debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen); + + /* Move data from DM9000 */ + /* Read received packet from RX SRAM */ + db->inblk(db, rdptr, rxlen); + + if (rxstatus & 0xbf00 || rxlen < 0x40 || rxlen > DM9000_PKT_MAX) { + if (rxstatus & 0x100) + printf("rx fifo error\n"); + if (rxstatus & 0x200) + printf("rx crc error\n"); + if (rxstatus & 0x8000) + printf("rx length error\n"); + if (rxlen > DM9000_PKT_MAX) { + printf("rx length too big\n"); + dm9000_reset(db); + } + return -EINVAL; + } + + return rxlen; } /* @@ -600,8 +593,13 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length) static int dm9000_recv(struct eth_device *dev) { struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + int ret; - return dm9000_recv_common(db); + ret = dm9000_recv_common(db, net_rx_packets[0]); + if (ret > 0) + net_process_received_packet(net_rx_packets[0], ret); + + return ret; } int dm9000_initialize(struct bd_info *bis) From 41e10bea31f1292b762ec1f4dafae6ca0eeb0f33 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:37 +0200 Subject: [PATCH 39/41] net: dm9000: Add DM support Add support for U-Boot DM and DT probing. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/dm9000x.c | 118 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 6552079748a..78ce536d4a3 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -74,7 +75,9 @@ struct dm9000_priv { void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count); void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count); void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen); +#ifndef CONFIG_DM_ETH struct eth_device dev; +#endif void __iomem *base_io; void __iomem *base_data; }; @@ -569,6 +572,7 @@ static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {} #endif +#ifndef CONFIG_DM_ETH static int dm9000_init(struct eth_device *dev, struct bd_info *bd) { struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); @@ -629,3 +633,117 @@ int dm9000_initialize(struct bd_info *bis) return 0; } +#else /* ifdef CONFIG_DM_ETH */ +static int dm9000_start(struct udevice *dev) +{ + struct dm9000_priv *db = dev_get_priv(dev); + struct eth_pdata *pdata = dev_get_plat(dev); + + return dm9000_init_common(db, pdata->enetaddr); +} + +static void dm9000_stop(struct udevice *dev) +{ + struct dm9000_priv *db = dev_get_priv(dev); + + dm9000_halt_common(db); +} + +static int dm9000_send(struct udevice *dev, void *packet, int length) +{ + struct dm9000_priv *db = dev_get_priv(dev); + int ret; + + ret = dm9000_send_common(db, packet, length); + + return ret ? 0 : -ETIMEDOUT; +} + +static int dm9000_recv(struct udevice *dev, int flags, uchar **packetp) +{ + struct dm9000_priv *db = dev_get_priv(dev); + uchar *data = net_rx_packets[0]; + int ret; + + ret = dm9000_recv_common(db, data); + if (ret) + *packetp = (void *)data; + + return ret ? ret : -EAGAIN; +} + +static int dm9000_write_hwaddr(struct udevice *dev) +{ + struct dm9000_priv *db = dev_get_priv(dev); + struct eth_pdata *pdata = dev_get_plat(dev); + int i, oft; + + /* fill device MAC address registers */ + for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) + dm9000_iow(db, oft, pdata->enetaddr[i]); + + for (i = 0, oft = 0x16; i < 8; i++, oft++) + dm9000_iow(db, oft, 0xff); + + /* read back mac, just to be sure */ + for (i = 0, oft = 0x10; i < 6; i++, oft++) + debug("%02x:", dm9000_ior(db, oft)); + + debug("\n"); + + return 0; +} + +static int dm9000_read_rom_hwaddr(struct udevice *dev) +{ + struct dm9000_priv *db = dev_get_priv(dev); + struct eth_pdata *pdata = dev_get_plat(dev); + + dm9000_get_enetaddr(db, pdata->enetaddr); + + return !is_valid_ethaddr(pdata->enetaddr); +} + +static int dm9000_bind(struct udevice *dev) +{ + return device_set_name(dev, dev->name); +} + +static int dm9000_of_to_plat(struct udevice *dev) +{ + struct dm9000_priv *db = dev_get_priv(dev); + struct eth_pdata *pdata = dev_get_plat(dev); + + pdata->iobase = dev_read_addr_index(dev, 0); + db->base_io = (void __iomem *)pdata->iobase; + db->base_data = (void __iomem *)dev_read_addr_index(dev, 1); + + return 0; +} + +static const struct eth_ops dm9000_ops = { + .start = dm9000_start, + .stop = dm9000_stop, + .send = dm9000_send, + .recv = dm9000_recv, + .write_hwaddr = dm9000_write_hwaddr, + .read_rom_hwaddr = dm9000_read_rom_hwaddr, +}; + +static const struct udevice_id dm9000_ids[] = { + { .compatible = "davicom,dm9000" }, + { } +}; + +U_BOOT_DRIVER(dm9000) = { + .name = "eth_dm9000", + .id = UCLASS_ETH, + .of_match = dm9000_ids, + .bind = dm9000_bind, + .of_to_plat = dm9000_of_to_plat, + .ops = &dm9000_ops, + .priv_auto = sizeof(struct dm9000_priv), + .plat_auto = sizeof(struct eth_pdata), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +}; +#endif From f478da938f5e0687a1bc975543155d108483286a Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:38 +0200 Subject: [PATCH 40/41] net: dm9000: Add Kconfig entry Add Kconfig entry for the DM9000 MAC. Reviewed-by: Ramon Fried Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried --- drivers/net/Kconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index a6171a7c7ff..347fe8aa425 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -191,6 +191,11 @@ config CALXEDA_XGMAC This driver supports the XGMAC in Calxeda Highbank and Midway machines. +config DRIVER_DM9000 + bool "Davicom DM9000 controller driver" + help + The Davicom DM9000 parallel bus external ethernet interface chip. + config DWC_ETH_QOS bool "Synopsys DWC Ethernet QOS device support" depends on DM_ETH From 0154e6de37e8bbaac837939391f6d4a8f0b3fd18 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Apr 2022 04:15:39 +0200 Subject: [PATCH 41/41] configs: net: dm9000: Move new Kconfig option to board configs Drop legacy #define CONFIG_DRIVER_DM9000 from board include/configs/ and enable the same in Kconfig configs/ . Signed-off-by: Marek Vasut Cc: Joe Hershberger Cc: Ramon Fried Reviewed-by: Ramon Fried --- configs/M5253DEMO_defconfig | 1 + configs/at91sam9261ek_dataflash_cs0_defconfig | 1 + configs/at91sam9261ek_dataflash_cs3_defconfig | 1 + configs/at91sam9261ek_nandflash_defconfig | 1 + configs/ci20_mmc_defconfig | 1 + configs/colibri_pxa270_defconfig | 1 + configs/devkit8000_defconfig | 1 + include/configs/M5253DEMO.h | 1 - include/configs/at91sam9261ek.h | 1 - include/configs/ci20.h | 1 - include/configs/colibri_pxa270.h | 1 - include/configs/devkit8000.h | 1 - 12 files changed, 7 insertions(+), 5 deletions(-) diff --git a/configs/M5253DEMO_defconfig b/configs/M5253DEMO_defconfig index d5a02cdeac6..0d298e34ded 100644 --- a/configs/M5253DEMO_defconfig +++ b/configs/M5253DEMO_defconfig @@ -37,4 +37,5 @@ CONFIG_SYS_I2C_SLAVE=0x7F CONFIG_SYS_I2C_SPEED=80000 CONFIG_MTD_NOR_FLASH=y CONFIG_USE_SYS_MAX_FLASH_BANKS=y +CONFIG_DRIVER_DM9000=y CONFIG_MCFUART=y diff --git a/configs/at91sam9261ek_dataflash_cs0_defconfig b/configs/at91sam9261ek_dataflash_cs0_defconfig index 76e9314d5f8..d1119ac6b0c 100644 --- a/configs/at91sam9261ek_dataflash_cs0_defconfig +++ b/configs/at91sam9261ek_dataflash_cs0_defconfig @@ -53,6 +53,7 @@ CONFIG_NAND_ATMEL=y CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_DATAFLASH=y +CONFIG_DRIVER_DM9000=y CONFIG_PINCTRL=y CONFIG_PINCTRL_AT91=y CONFIG_DM_SERIAL=y diff --git a/configs/at91sam9261ek_dataflash_cs3_defconfig b/configs/at91sam9261ek_dataflash_cs3_defconfig index 2bdac9c19c0..1fa960814be 100644 --- a/configs/at91sam9261ek_dataflash_cs3_defconfig +++ b/configs/at91sam9261ek_dataflash_cs3_defconfig @@ -53,6 +53,7 @@ CONFIG_NAND_ATMEL=y CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_DATAFLASH=y +CONFIG_DRIVER_DM9000=y CONFIG_PINCTRL=y CONFIG_PINCTRL_AT91=y CONFIG_DM_SERIAL=y diff --git a/configs/at91sam9261ek_nandflash_defconfig b/configs/at91sam9261ek_nandflash_defconfig index 20909d86bd7..36677c7e015 100644 --- a/configs/at91sam9261ek_nandflash_defconfig +++ b/configs/at91sam9261ek_nandflash_defconfig @@ -51,6 +51,7 @@ CONFIG_NAND_ATMEL=y CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_DATAFLASH=y +CONFIG_DRIVER_DM9000=y CONFIG_PINCTRL=y CONFIG_PINCTRL_AT91=y CONFIG_DM_SERIAL=y diff --git a/configs/ci20_mmc_defconfig b/configs/ci20_mmc_defconfig index 96221570156..e7a60aa5b4a 100644 --- a/configs/ci20_mmc_defconfig +++ b/configs/ci20_mmc_defconfig @@ -49,6 +49,7 @@ CONFIG_MMC_UHS_SUPPORT=y CONFIG_MMC_HS400_SUPPORT=y # CONFIG_MMC_VERBOSE is not set CONFIG_JZ47XX_MMC=y +CONFIG_DRIVER_DM9000=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPL_TINY_MEMSET=y diff --git a/configs/colibri_pxa270_defconfig b/configs/colibri_pxa270_defconfig index c2c0a2bc4a2..f23f6fb2e33 100644 --- a/configs/colibri_pxa270_defconfig +++ b/configs/colibri_pxa270_defconfig @@ -48,6 +48,7 @@ CONFIG_FLASH_CFI_DRIVER=y CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y CONFIG_SYS_FLASH_PROTECTION=y CONFIG_SYS_FLASH_CFI=y +CONFIG_DRIVER_DM9000=y CONFIG_DM_SERIAL=y CONFIG_PXA_SERIAL=y CONFIG_USB=y diff --git a/configs/devkit8000_defconfig b/configs/devkit8000_defconfig index e009f21ecd6..2bff7dfbf42 100644 --- a/configs/devkit8000_defconfig +++ b/configs/devkit8000_defconfig @@ -57,6 +57,7 @@ CONFIG_SYS_NAND_OOBSIZE=0x40 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000 +CONFIG_DRIVER_DM9000=y CONFIG_CONS_INDEX=3 CONFIG_JFFS2_NAND=y CONFIG_OF_LIBFDT=y diff --git a/include/configs/M5253DEMO.h b/include/configs/M5253DEMO.h index b7fdd7135f2..079675be5bc 100644 --- a/include/configs/M5253DEMO.h +++ b/include/configs/M5253DEMO.h @@ -25,7 +25,6 @@ # undef CONFIG_LBA48 #endif -#define CONFIG_DRIVER_DM9000 #ifdef CONFIG_DRIVER_DM9000 # define CONFIG_DM9000_BASE (CONFIG_SYS_CS1_BASE | 0x300) # define DM9000_IO CONFIG_DM9000_BASE diff --git a/include/configs/at91sam9261ek.h b/include/configs/at91sam9261ek.h index 55ddb38c70a..2089fe52e45 100644 --- a/include/configs/at91sam9261ek.h +++ b/include/configs/at91sam9261ek.h @@ -44,7 +44,6 @@ #endif /* Ethernet */ -#define CONFIG_DRIVER_DM9000 #define CONFIG_DM9000_BASE 0x30000000 #define DM9000_IO CONFIG_DM9000_BASE #define DM9000_DATA (CONFIG_DM9000_BASE + 4) diff --git a/include/configs/ci20.h b/include/configs/ci20.h index ea9440dac07..cc70a59e728 100644 --- a/include/configs/ci20.h +++ b/include/configs/ci20.h @@ -24,7 +24,6 @@ #define CONFIG_SYS_NS16550_CLK 48000000 /* Ethernet: davicom DM9000 */ -#define CONFIG_DRIVER_DM9000 1 #define CONFIG_DM9000_BASE 0xb6000000 #define DM9000_IO CONFIG_DM9000_BASE #define DM9000_DATA (CONFIG_DM9000_BASE + 2) diff --git a/include/configs/colibri_pxa270.h b/include/configs/colibri_pxa270.h index 99645f3f7ad..ca57f541574 100644 --- a/include/configs/colibri_pxa270.h +++ b/include/configs/colibri_pxa270.h @@ -45,7 +45,6 @@ */ #ifdef CONFIG_CMD_NET -#define CONFIG_DRIVER_DM9000 1 #define CONFIG_DM9000_BASE 0x08000000 #define DM9000_IO (CONFIG_DM9000_BASE) #define DM9000_DATA (CONFIG_DM9000_BASE + 4) diff --git a/include/configs/devkit8000.h b/include/configs/devkit8000.h index 16b36501329..5dbd126a2a0 100644 --- a/include/configs/devkit8000.h +++ b/include/configs/devkit8000.h @@ -35,7 +35,6 @@ /* Hardware drivers */ /* DM9000 */ -#define CONFIG_DRIVER_DM9000 1 #define CONFIG_DM9000_BASE 0x2c000000 #define DM9000_IO CONFIG_DM9000_BASE #define DM9000_DATA (CONFIG_DM9000_BASE + 0x400)