ethtool: Extend the ethtool API to obtain plugin module eeprom data

ETHTOOL_GMODULEINFO returns a new struct ethtool_modinfo that will return the
type and size of plug-in module eeprom (such as SFP+) for parsing
by userland program.

ETHTOOL_GMODULEEEPROM returns the raw eeprom information
using the existing ethtool_eeprom structture to return the data

Signed-off-by: Stuart Hodgson <smhodgson@solarflare.com>
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
This commit is contained in:
Stuart Hodgson
2012-04-19 09:44:42 +01:00
committed by Ben Hutchings
parent 081d094eaa
commit 41c3cb6d20
2 changed files with 80 additions and 0 deletions

View File

@@ -1335,6 +1335,47 @@ static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
return err;
}
static int ethtool_get_module_info(struct net_device *dev,
void __user *useraddr)
{
int ret;
struct ethtool_modinfo modinfo;
const struct ethtool_ops *ops = dev->ethtool_ops;
if (!ops->get_module_info)
return -EOPNOTSUPP;
if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
return -EFAULT;
ret = ops->get_module_info(dev, &modinfo);
if (ret)
return ret;
if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
return -EFAULT;
return 0;
}
static int ethtool_get_module_eeprom(struct net_device *dev,
void __user *useraddr)
{
int ret;
struct ethtool_modinfo modinfo;
const struct ethtool_ops *ops = dev->ethtool_ops;
if (!ops->get_module_info || !ops->get_module_eeprom)
return -EOPNOTSUPP;
ret = ops->get_module_info(dev, &modinfo);
if (ret)
return ret;
return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
modinfo.eeprom_len);
}
/* The main entry point in this file. Called from net/core/dev.c */
int dev_ethtool(struct net *net, struct ifreq *ifr)
@@ -1559,6 +1600,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
case ETHTOOL_GET_TS_INFO:
rc = ethtool_get_ts_info(dev, useraddr);
break;
case ETHTOOL_GMODULEINFO:
rc = ethtool_get_module_info(dev, useraddr);
break;
case ETHTOOL_GMODULEEEPROM:
rc = ethtool_get_module_eeprom(dev, useraddr);
break;
default:
rc = -EOPNOTSUPP;
}