From efe1d6303f243cf3588dd1974fbfdef0d7a02c42 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 1 Oct 2025 14:30:50 -0600 Subject: uthreads: Make use of CONFIG_IS_ENABLED consistently We do not yet support UTHREADS in xPL phases. However, we have the need to dummy out certain functions so that xPL can build when full U-Boot has UTHREADS enabled. Update the few places that need to use CONFIG_IS_ENABLED so that we have the correct dummy in xPL. Signed-off-by: Tom Rini Acked-by: Jerome Forissier --- include/uthread.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/uthread.h b/include/uthread.h index 11a19aa9488..78dab77f196 100644 --- a/include/uthread.h +++ b/include/uthread.h @@ -72,7 +72,7 @@ struct uthread_mutex { #define UTHREAD_MUTEX_INITIALIZER { .state = UTHREAD_MUTEX_UNLOCKED } -#ifdef CONFIG_UTHREAD +#if CONFIG_IS_ENABLED(UTHREAD) /** * uthread_create() - Create a uthread object and make it ready for execution @@ -184,5 +184,5 @@ static inline bool uthread_grp_done(unsigned int grp_id) #define uthread_mutex_trylock(_mutex) ({ 0 }) #define uthread_mutex_unlock(_mutex) ({ 0; }) -#endif /* CONFIG_UTHREAD */ +#endif /* CONFIG_IS_ENABLED(UTHREAD) */ #endif /* _UTHREAD_H_ */ -- cgit v1.3.1 From 4b8e78585171787794611205d661b97bc5f4dd83 Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Thu, 9 Oct 2025 14:30:14 +0200 Subject: net: make dhcp_run() common for NET and NET_LWIP There are currently two implementations of dhcp_run(): one in cmd/net.c for NET and one in net/lwip/dhcp.c for NET_LWIP. There is no justification for that. Therefore, move the NET version into net/net-common.c to be used by both stacks, and drop the NET_LWIP version which by the way does not look totally correct. Signed-off-by: Jerome Forissier Suggested-by: Tom Rini Acked-by: Benjamin Hahn --- cmd/net.c | 36 ++---------------------------------- include/net-common.h | 10 ++++++++++ include/net-lwip.h | 1 - net/lwip/dhcp.c | 22 ---------------------- net/net-common.c | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 57 deletions(-) (limited to 'include') diff --git a/cmd/net.c b/cmd/net.c index 886735ea14f..24099764493 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -134,8 +134,8 @@ U_BOOT_CMD(dhcp6, 3, 1, do_dhcp6, #endif #if defined(CONFIG_CMD_DHCP) -static int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) +int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) { return netboot_common(DHCP, cmdtp, argc, argv); } @@ -145,38 +145,6 @@ U_BOOT_CMD( "boot image via network using DHCP/TFTP protocol", "[loadAddress] [[hostIPaddr:]bootfilename]" ); - -int dhcp_run(ulong addr, const char *fname, bool autoload) -{ - char *dhcp_argv[] = {"dhcp", NULL, (char *)fname, NULL}; - struct cmd_tbl cmdtp = {}; /* dummy */ - char file_addr[17]; - int old_autoload; - int ret, result; - - log_debug("addr=%lx, fname=%s, autoload=%d\n", addr, fname, autoload); - old_autoload = env_get_yesno("autoload"); - ret = env_set("autoload", autoload ? "y" : "n"); - if (ret) - return log_msg_ret("en1", -EINVAL); - - if (autoload) { - sprintf(file_addr, "%lx", addr); - dhcp_argv[1] = file_addr; - } - - result = do_dhcp(&cmdtp, 0, !autoload ? 1 : fname ? 3 : 2, dhcp_argv); - - ret = env_set("autoload", old_autoload == -1 ? NULL : - old_autoload ? "y" : "n"); - if (ret) - return log_msg_ret("en2", -EINVAL); - - if (result) - return log_msg_ret("res", -ENOENT); - - return 0; -} #endif #if defined(CONFIG_CMD_NFS) diff --git a/include/net-common.h b/include/net-common.h index 1112af381a9..78d98e5bba0 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -479,6 +479,16 @@ int net_loop(enum proto_t protocol); */ int dhcp_run(ulong addr, const char *fname, bool autoload); +/** + * do_dhcp - Run the dhcp command + * + * @cmdtp: Unused + * @flag: Command flags (CMD_FLAG_...) + * @argc: Number of arguments + * @argv: List of arguments + * Return: result (see enum command_ret_t) + */ +int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); /** * do_ping - Run the ping command diff --git a/include/net-lwip.h b/include/net-lwip.h index e88e2186635..c910def5719 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -50,7 +50,6 @@ int net_lwip_dns_resolve(char *name_or_ip, ip_addr_t *ip); */ bool wget_validate_uri(char *uri); -int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c index 531bf2c6705..b798014ebcb 100644 --- a/net/lwip/dhcp.c +++ b/net/lwip/dhcp.c @@ -150,25 +150,3 @@ int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_SUCCESS; } - -int dhcp_run(ulong addr, const char *fname, bool autoload) -{ - char *dhcp_argv[] = {"dhcp", NULL, }; -#ifdef CONFIG_CMD_TFTPBOOT - char *tftp_argv[] = {"tftpboot", boot_file_name, NULL, }; -#endif - struct cmd_tbl cmdtp = {}; /* dummy */ - - if (autoload) { -#ifdef CONFIG_CMD_TFTPBOOT - /* Assume DHCP was already performed */ - if (boot_file_name[0]) - return do_tftpb(&cmdtp, 0, 2, tftp_argv); - return 0; -#else - return -EOPNOTSUPP; -#endif - } - - return do_dhcp(&cmdtp, 0, 1, dhcp_argv); -} diff --git a/net/net-common.c b/net/net-common.c index b064557d524..442b0597558 100644 --- a/net/net-common.c +++ b/net/net-common.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -48,3 +49,37 @@ void net_sntp_set_rtc(u32 seconds) tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); } + +#if defined(CONFIG_CMD_DHCP) +int dhcp_run(ulong addr, const char *fname, bool autoload) +{ + char *dhcp_argv[] = {"dhcp", NULL, (char *)fname, NULL}; + struct cmd_tbl cmdtp = {}; /* dummy */ + char file_addr[17]; + int old_autoload; + int ret, result; + + log_debug("addr=%lx, fname=%s, autoload=%d\n", addr, fname, autoload); + old_autoload = env_get_yesno("autoload"); + ret = env_set("autoload", autoload ? "y" : "n"); + if (ret) + return log_msg_ret("en1", -EINVAL); + + if (autoload) { + sprintf(file_addr, "%lx", addr); + dhcp_argv[1] = file_addr; + } + + result = do_dhcp(&cmdtp, 0, !autoload ? 1 : fname ? 3 : 2, dhcp_argv); + + ret = env_set("autoload", old_autoload == -1 ? NULL : + old_autoload ? "y" : "n"); + if (ret) + return log_msg_ret("en2", -EINVAL); + + if (result) + return log_msg_ret("res", -ENOENT); + + return 0; +} +#endif -- cgit v1.3.1 From 34369d34e413ac32a131dd144b55ad04873e4854 Mon Sep 17 00:00:00 2001 From: "Lucien.Jheng" Date: Mon, 6 Oct 2025 20:49:15 +0800 Subject: net: phy: add paged PHY register accessors Synchronize paged PHY helpers with Linux v6.17. Add support for PHY devices that use paged register access by implementing the following functions: - phy_save_page(): Save current page number - phy_select_page(): Switch to a specific page and return previous page - phy_restore_page(): Restore previously saved page Also adds read_page and write_page callbacks to the phy_driver structure to enable driver-specific page handling. These helpers allow safe access to paged PHY registers by ensuring proper page selection and restoration, even in error conditions, which will be used by the Airoha PHY driver. Signed-off-by: Lucien.Jheng --- drivers/net/phy/phy.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/phy.h | 8 ++++ 2 files changed, 121 insertions(+) (limited to 'include') diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 9702d042296..b58283fe3d5 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1250,3 +1250,116 @@ bool phy_interface_is_ncsi(void) return 0; #endif } + +/** + * __phy_read_page() - read the current page + * @phydev: a pointer to a &struct phy_device + * + * Returns page index or < 0 on error + */ +static int __phy_read_page(struct phy_device *phydev) +{ + struct phy_driver *drv = phydev->drv; + + if (!drv->read_page) { + debug("read_page callback not available, PHY driver not loaded?\n"); + return -EOPNOTSUPP; + } + + return drv->read_page(phydev); +} + +/** + * __phy_write_page() - Write a new page + * @phydev: a pointer to a &struct phy_device + * @page: page index to select + * + * Returns 0 or < 0 on error. + */ +static int __phy_write_page(struct phy_device *phydev, int page) +{ + struct phy_driver *drv = phydev->drv; + + if (!drv->write_page) { + debug("write_page callback not available, PHY driver not loaded?\n"); + return -EOPNOTSUPP; + } + + return drv->write_page(phydev, page); +} + +/** + * phy_save_page() - save the current page + * @phydev: a pointer to a &struct phy_device + * + * Return the current page number. On error, + * returns a negative errno. phy_restore_page() must always be called + * after this, irrespective of success or failure of this call. + */ +int phy_save_page(struct phy_device *phydev) +{ + return __phy_read_page(phydev); +} + +/** + * phy_select_page - Switch to a PHY page and return the previous page + * @phydev: a pointer to a &struct phy_device + * @page: desired page + * + * NOTE: Save the current PHY page, and set the current page. + * On error, returns a negative errno, otherwise returns the previous page number. + * phy_restore_page() must always be called after this, irrespective + * of success or failure of this call. + */ +int phy_select_page(struct phy_device *phydev, int page) +{ + int ret, oldpage; + + oldpage = ret = phy_save_page(phydev); + if (ret < 0) + return ret; + + if (oldpage != page) { + ret = __phy_write_page(phydev, page); + if (ret < 0) + return ret; + } + + return oldpage; +} + +/** + * phy_restore_page - Restore a previously saved page and propagate status + * @phydev: a pointer to a &struct phy_device + * @oldpage: the old page, return value from phy_save_page() or phy_select_page() + * @ret: operation's return code + * + * Restoring @oldpage if it is a valid page. + * This function propagates the earliest error code from the group of + * operations. + * + * Returns: + * @oldpage if it was a negative value, otherwise + * @ret if it was a negative errno value, otherwise + * phy_write_page()'s negative value if it were in error, otherwise + * @ret. + */ +int phy_restore_page(struct phy_device *phydev, int oldpage, int ret) +{ + int r; + + if (oldpage >= 0) { + r = __phy_write_page(phydev, oldpage); + + /* Propagate the operation return code if the page write + * was successful. + */ + if (ret >= 0 && r < 0) + ret = r; + } else { + /* Propagate the phy page selection error code */ + ret = oldpage; + } + + return ret; +} \ No newline at end of file diff --git a/include/phy.h b/include/phy.h index 36354aaf774..ae9fd1652cc 100644 --- a/include/phy.h +++ b/include/phy.h @@ -123,6 +123,11 @@ struct phy_driver { int (*write_mmd)(struct phy_device *phydev, int devad, int reg, u16 val); + /** @read_page: Return the current PHY register page number */ + int (*read_page)(struct phy_device *phydev); + /** @write_page: Set the current PHY register page number */ + int (*write_page)(struct phy_device *phydev, int page); + /* driver private data */ ulong data; }; @@ -314,6 +319,9 @@ int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum, u16 mask, u16 set); int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 mask, u16 set); +int phy_save_page(struct phy_device *phydev); +int phy_select_page(struct phy_device *phydev, int page); +int phy_restore_page(struct phy_device *phydev, int oldpage, int ret); int phy_startup(struct phy_device *phydev); int phy_config(struct phy_device *phydev); -- cgit v1.3.1