Message ID | 20250213035529.2402283-8-shaojijie@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Support some enhances features for the HIBMCGE driver | expand |
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@huawei.com> > --- > .../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
on 2025/2/14 4:13, Andrew Lunn wrote: > 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@huawei.com> >> --- >> .../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 Yes, of course So I think I can just use: .ndo_eth_ioctl = phy_do_ioctl, No other code is required. Thanks, Jijie Shao
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; + } +} + static const struct net_device_ops hbg_netdev_ops = { .ndo_open = hbg_net_open, .ndo_stop = hbg_net_stop, @@ -284,6 +301,7 @@ static const struct net_device_ops hbg_netdev_ops = { .ndo_set_rx_mode = hbg_net_set_rx_mode, .ndo_get_stats64 = hbg_net_get_stats, .ndo_fix_features = hbg_net_fix_features, + .ndo_eth_ioctl = hbg_net_eth_ioctl, }; static void hbg_service_task(struct work_struct *work) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c index 8de6d57bd5f3..7080f3011f2d 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c @@ -246,3 +246,13 @@ int hbg_mdio_init(struct hbg_priv *priv) hbg_mdio_init_hw(priv); return hbg_phy_connect(priv); } + +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); +} diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h index febd02a309c7..3edca6cd0801 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.h @@ -9,4 +9,6 @@ int hbg_mdio_init(struct hbg_priv *priv); void hbg_phy_start(struct hbg_priv *priv); void hbg_phy_stop(struct hbg_priv *priv); +int hbg_mdio_ioctl(struct hbg_priv *priv, struct ifreq *ifr, int cmd); + #endif
This patch implements the ioctl interface to read and write the PHY register. Signed-off-by: Jijie Shao <shaojijie@huawei.com> --- .../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(+)