Re: [PATCH net-next 7/7] net: hibmcge: Add ioctl supported in this module
From: Andrew Lunn
Date: Thu Feb 13 2025 - 15:13:25 EST
On Thu, Feb 13, 2025 at 11:55:29AM +0800, Jijie Shao wrote:
> This patch implements the ioctl interface to
> read and write the PHY register.
>
> Signed-off-by: Jijie Shao <shaojijie@xxxxxxxxxx>
> ---
> .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 18 ++++++++++++++++++
> .../net/ethernet/hisilicon/hibmcge/hbg_mdio.c | 10 ++++++++++
> .../net/ethernet/hisilicon/hibmcge/hbg_mdio.h | 2 ++
> 3 files changed, 30 insertions(+)
>
> diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c
> index 78999d41f41d..afd04ed65eee 100644
> --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c
> +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c
> @@ -273,6 +273,23 @@ static netdev_features_t hbg_net_fix_features(struct net_device *netdev,
> return features & HBG_SUPPORT_FEATURES;
> }
>
> +static int hbg_net_eth_ioctl(struct net_device *dev, struct ifreq *ifr, s32 cmd)
> +{
> + struct hbg_priv *priv = netdev_priv(dev);
> +
> + if (test_bit(HBG_NIC_STATE_RESETTING, &priv->state))
> + return -EBUSY;
> +
> + switch (cmd) {
> + case SIOCGMIIPHY:
> + case SIOCGMIIREG:
> + case SIOCSMIIREG:
> + return hbg_mdio_ioctl(priv, ifr, cmd);
> + default:
> + return -EOPNOTSUPP;
> + }
No need for this switch statement. phy_mii_ioctl() will return
EOPNOTSUPP for any it does not support.
The general structure of an IOCTL handler is to have a switch
statements for any IOCTL which are handled at this level and the
default: case then calls into the next layer down.
> +int hbg_mdio_ioctl(struct hbg_priv *priv, struct ifreq *ifr, int cmd)
> +{
> + struct hbg_mac *mac = &priv->mac;
> +
> + if (!mac->phydev)
> + return -ENODEV;
> +
> + return phy_mii_ioctl(mac->phydev, ifr, cmd);
phy_do_ioctl(). This is assuming you follow the normal pattern of
keeping the phydev pointer in the net_device structure.
Andrew