diff mbox

[1/1] forcedeth: add MII ioctls support

Message ID 1386829089-24477-1-git-send-email-noureddine@aristanetworks.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Salam Noureddine Dec. 12, 2013, 6:18 a.m. UTC
Signed-off-by: Salam Noureddine <noureddine@aristanetworks.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c |   34 +++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

Comments

Florian Fainelli Dec. 12, 2013, 6:17 p.m. UTC | #1
2013/12/11 Salam Noureddine <noureddine@aristanetworks.com>:
>
> Signed-off-by: Salam Noureddine <noureddine@aristanetworks.com>

Would you consider implementing the PHY library knobs instead? You
would get all of that basically for free.

> ---
>  drivers/net/ethernet/nvidia/forcedeth.c |   34 +++++++++++++++++++++++++++++++
>  1 files changed, 34 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/net/ethernet/nvidia/forcedeth.c b/drivers/net/ethernet/nvidia/forcedeth.c
> index 2d045be..0d8c88a 100644
> --- a/drivers/net/ethernet/nvidia/forcedeth.c
> +++ b/drivers/net/ethernet/nvidia/forcedeth.c
> @@ -5558,6 +5558,38 @@ static int nv_close(struct net_device *dev)
>         return 0;
>  }
>
> +static int nv_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
> +{
> +       int ret = 0;
> +       u32 val;
> +       struct fe_priv *np = netdev_priv(dev);
> +       struct mii_ioctl_data *data = (struct mii_ioctl_data *) &req->ifr_data;
> +
> +       switch (cmd) {
> +       case SIOCGMIIPHY:
> +               data->phy_id = np->phyaddr;
> +               break;
> +       case SIOCGMIIREG:
> +               spin_lock_irq(&np->lock);
> +               val = mii_rw(dev, np->phyaddr, data->reg_num & 0x1f, MII_READ);
> +               spin_unlock_irq(&np->lock);
> +               data->val_out = val;
> +               break;
> +       case SIOCSMIIREG:
> +               if (!capable(CAP_NET_ADMIN))
> +                       return -EPERM;
> +               spin_lock_irq(&np->lock);
> +               ret = mii_rw(dev, np->phyaddr, data->reg_num & 0x1f,
> +                            data->val_in);
> +               spin_unlock_irq(&np->lock);
> +               break;
> +       default:
> +               return -EOPNOTSUPP;
> +       }
> +
> +       return ret;
> +}
> +
>  static const struct net_device_ops nv_netdev_ops = {
>         .ndo_open               = nv_open,
>         .ndo_stop               = nv_close,
> @@ -5568,6 +5600,7 @@ static const struct net_device_ops nv_netdev_ops = {
>         .ndo_fix_features       = nv_fix_features,
>         .ndo_set_features       = nv_set_features,
>         .ndo_validate_addr      = eth_validate_addr,
> +       .ndo_do_ioctl           = nv_ioctl,
>         .ndo_set_mac_address    = nv_set_mac_address,
>         .ndo_set_rx_mode        = nv_set_multicast,
>  #ifdef CONFIG_NET_POLL_CONTROLLER
> @@ -5585,6 +5618,7 @@ static const struct net_device_ops nv_netdev_ops_optimized = {
>         .ndo_fix_features       = nv_fix_features,
>         .ndo_set_features       = nv_set_features,
>         .ndo_validate_addr      = eth_validate_addr,
> +       .ndo_do_ioctl           = nv_ioctl,
>         .ndo_set_mac_address    = nv_set_mac_address,
>         .ndo_set_rx_mode        = nv_set_multicast,
>  #ifdef CONFIG_NET_POLL_CONTROLLER
> --
> 1.7.4.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Dec. 12, 2013, 6:56 p.m. UTC | #2
From: Salam Noureddine <noureddine@aristanetworks.com>
Date: Wed, 11 Dec 2013 22:18:09 -0800

> Signed-off-by: Salam Noureddine <noureddine@aristanetworks.com>

I agree with Florian that using phylib would be a cleaner way to get
this facility (and more).
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Salam Noureddine Dec. 12, 2013, 7:08 p.m. UTC | #3
Will look into that.Thanks!

On Thu, Dec 12, 2013 at 10:56 AM, David Miller <davem@davemloft.net> wrote:
> From: Salam Noureddine <noureddine@aristanetworks.com>
> Date: Wed, 11 Dec 2013 22:18:09 -0800
>
>> Signed-off-by: Salam Noureddine <noureddine@aristanetworks.com>
>
> I agree with Florian that using phylib would be a cleaner way to get
> this facility (and more).
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c b/drivers/net/ethernet/nvidia/forcedeth.c
index 2d045be..0d8c88a 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -5558,6 +5558,38 @@  static int nv_close(struct net_device *dev)
 	return 0;
 }
 
+static int nv_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
+{
+	int ret = 0;
+	u32 val;
+	struct fe_priv *np = netdev_priv(dev);
+	struct mii_ioctl_data *data = (struct mii_ioctl_data *) &req->ifr_data;
+
+	switch (cmd) {
+	case SIOCGMIIPHY:
+		data->phy_id = np->phyaddr;
+		break;
+	case SIOCGMIIREG:
+		spin_lock_irq(&np->lock);
+		val = mii_rw(dev, np->phyaddr, data->reg_num & 0x1f, MII_READ);
+		spin_unlock_irq(&np->lock);
+		data->val_out = val;
+		break;
+	case SIOCSMIIREG:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		spin_lock_irq(&np->lock);
+		ret = mii_rw(dev, np->phyaddr, data->reg_num & 0x1f,
+			     data->val_in);
+		spin_unlock_irq(&np->lock);
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return ret;
+}
+
 static const struct net_device_ops nv_netdev_ops = {
 	.ndo_open		= nv_open,
 	.ndo_stop		= nv_close,
@@ -5568,6 +5600,7 @@  static const struct net_device_ops nv_netdev_ops = {
 	.ndo_fix_features	= nv_fix_features,
 	.ndo_set_features	= nv_set_features,
 	.ndo_validate_addr	= eth_validate_addr,
+	.ndo_do_ioctl		= nv_ioctl,
 	.ndo_set_mac_address	= nv_set_mac_address,
 	.ndo_set_rx_mode	= nv_set_multicast,
 #ifdef CONFIG_NET_POLL_CONTROLLER
@@ -5585,6 +5618,7 @@  static const struct net_device_ops nv_netdev_ops_optimized = {
 	.ndo_fix_features	= nv_fix_features,
 	.ndo_set_features	= nv_set_features,
 	.ndo_validate_addr	= eth_validate_addr,
+	.ndo_do_ioctl		= nv_ioctl,
 	.ndo_set_mac_address	= nv_set_mac_address,
 	.ndo_set_rx_mode	= nv_set_multicast,
 #ifdef CONFIG_NET_POLL_CONTROLLER