diff mbox series

[net-next,7/7] net: hibmcge: Add ioctl supported in this module

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

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 49 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jijie Shao Feb. 13, 2025, 3:55 a.m. UTC
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(+)

Comments

Andrew Lunn Feb. 13, 2025, 8:13 p.m. UTC | #1
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
Jijie Shao Feb. 14, 2025, 2:30 a.m. UTC | #2
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 mbox series

Patch

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