Re: [PATCH net-next v7 4/4] net: phy: realtek: load firmware for RTL8261C_CG
From: Andrew Lunn
Date: Tue Jun 30 2026 - 18:11:14 EST
On Mon, Jun 29, 2026 at 02:47:18PM +0800, javen wrote:
> From: Javen Xu <javen_xu@xxxxxxxxxxxxxx>
>
> This patch adds support for loading firmware. Download some parameters
> for RTL8261C_CG.
>
> Signed-off-by: Javen Xu <javen_xu@xxxxxxxxxxxxxx>
> ---
> Changes in v2:
> - remove __pack, struct rtl8261x_fw_header and rtl8261x_fw_entry will not pad
> - reverse xmas tree for some definition
> - add explanation on rtl_phy_write_mmd_bits()
>
> Changes in v3:
> - add struct rtl8261x_priv
>
> Changes in v4:
> - add struct device *dev
>
> Changes in v5:
> - no changes
>
> Changes in v6:
> - replace rtl_phy_write_mmd_bits with phy_modify_mmd, keep mdio lock
> - check msb and lsb at the beginning of rtl8261x_fw_execute_entry()
> - add comments on rtl8261x_config_init()
>
> Changes in v7:
> - no changes
> ---
> drivers/net/phy/realtek/realtek_main.c | 220 +++++++++++++++++++++++++
> 1 file changed, 220 insertions(+)
>
> diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
> index ef3700894ebf..bf7bc19fb44c 100644
> --- a/drivers/net/phy/realtek/realtek_main.c
> +++ b/drivers/net/phy/realtek/realtek_main.c
> @@ -8,7 +8,9 @@
> * Copyright (c) 2004 Freescale Semiconductor, Inc.
> */
> #include <linux/bitops.h>
> +#include <linux/crc32.h>
> #include <linux/ethtool_netlink.h>
> +#include <linux/firmware.h>
> #include <linux/of.h>
> #include <linux/phy.h>
> #include <linux/pm_wakeirq.h>
> @@ -281,6 +283,42 @@
> RTL8261X_INT_ALDPS_CHG | \
> RTL8261X_INT_JABBER)
>
> +#define FW_MAIN_MAGIC 0x52544C38
> +#define FW_SUB_MAGIC_8261C 0x32363143
> +#define RTL8261X_POLL_TIMEOUT_MS 100
> +
> +#define RTL8261C_CE_FW_NAME "rtl_nic/rtl8261c.bin"
> +MODULE_FIRMWARE(RTL8261C_CE_FW_NAME);
> +
> +enum rtl8261x_fw_op {
> + OP_WRITE = 0x00, /* Write */
> + OP_POLL = 0x02, /* Polling */
> +};
> +
> +struct rtl8261x_fw_header {
> + __le32 main_magic; /* Main magic number 0x52544C38 ("RTL8") */
> + __le32 sub_magic; /* Sub magic number */
> + __le16 version_major; /* Major version */
> + __le16 version_minor; /* Minor version */
> + __le16 num_entries; /* Number of entries */
> + __le16 reserved; /* Reserved */
> + __le32 crc32; /* CRC32 checksum */
> +};
> +
> +struct rtl8261x_fw_entry {
> + __u8 type; /* Operation type (OP_*) */
> + __u8 dev; /* MMD device */
> + __le16 addr; /* Register address */
> + __u8 msb; /* MSB bit position */
> + __u8 lsb; /* LSB bit position */
> + __le16 value; /* Value to write/compare */
> + __le16 timeout_ms; /* Poll timeout in milliseconds */
> + __u8 poll_set; /* Poll for set (1) or clear (0) */
> + __u8 reserved; /* Reserved */
> +};
Are there other devices which need firmware download? Do they use the
same header? I'm just wondering if this will be reused by other
devices?
Andrew