net/mlx5: support reading module EEPROM data
This patch implements ethdev operations get_module_info and get_module_eeprom, to support ethtool commands ETHTOOL_GMODULEINFO and ETHTOOL_GMODULEEEPROM. New functions mlx5_get_module_info() and mlx5_get_module_eeprom() added in mlx5_ethdev.c. Signed-off-by: Dekel Peled <dekelp@mellanox.com> Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
This commit is contained in:
parent
5f163d520c
commit
8a6a09f853
@ -996,6 +996,8 @@ const struct eth_dev_ops mlx5_dev_ops = {
|
||||
.rx_queue_intr_disable = mlx5_rx_intr_disable,
|
||||
.is_removed = mlx5_is_removed,
|
||||
.udp_tunnel_port_add = mlx5_udp_tunnel_port_add,
|
||||
.get_module_info = mlx5_get_module_info,
|
||||
.get_module_eeprom = mlx5_get_module_eeprom,
|
||||
};
|
||||
|
||||
/* Available operations from secondary process. */
|
||||
@ -1009,6 +1011,8 @@ static const struct eth_dev_ops mlx5_dev_sec_ops = {
|
||||
.dev_infos_get = mlx5_dev_infos_get,
|
||||
.rx_descriptor_status = mlx5_rx_descriptor_status,
|
||||
.tx_descriptor_status = mlx5_tx_descriptor_status,
|
||||
.get_module_info = mlx5_get_module_info,
|
||||
.get_module_eeprom = mlx5_get_module_eeprom,
|
||||
};
|
||||
|
||||
/* Available operations in flow isolated mode. */
|
||||
@ -1052,6 +1056,8 @@ const struct eth_dev_ops mlx5_dev_ops_isolate = {
|
||||
.rx_queue_intr_enable = mlx5_rx_intr_enable,
|
||||
.rx_queue_intr_disable = mlx5_rx_intr_disable,
|
||||
.is_removed = mlx5_is_removed,
|
||||
.get_module_info = mlx5_get_module_info,
|
||||
.get_module_eeprom = mlx5_get_module_eeprom,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -728,6 +728,10 @@ void mlx5_translate_port_name(const char *port_name_in,
|
||||
struct mlx5_switch_info *port_info_out);
|
||||
void mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
|
||||
rte_intr_callback_fn cb_fn, void *cb_arg);
|
||||
int mlx5_get_module_info(struct rte_eth_dev *dev,
|
||||
struct rte_eth_dev_module_info *modinfo);
|
||||
int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
|
||||
struct rte_dev_eeprom_info *info);
|
||||
|
||||
/* mlx5_mac.c */
|
||||
|
||||
|
@ -1928,3 +1928,89 @@ mlx5_translate_port_name(const char *port_name_in,
|
||||
port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* DPDK callback to retrieve plug-in module EEPROM information (type and size).
|
||||
*
|
||||
* @param dev
|
||||
* Pointer to Ethernet device structure.
|
||||
* @param[out] modinfo
|
||||
* Storage for plug-in module EEPROM information.
|
||||
*
|
||||
* @return
|
||||
* 0 on success, a negative errno value otherwise and rte_errno is set.
|
||||
*/
|
||||
int
|
||||
mlx5_get_module_info(struct rte_eth_dev *dev,
|
||||
struct rte_eth_dev_module_info *modinfo)
|
||||
{
|
||||
struct ethtool_modinfo info = {
|
||||
.cmd = ETHTOOL_GMODULEINFO,
|
||||
};
|
||||
struct ifreq ifr = (struct ifreq) {
|
||||
.ifr_data = (void *)&info,
|
||||
};
|
||||
int ret = 0;
|
||||
|
||||
if (!dev || !modinfo) {
|
||||
DRV_LOG(WARNING, "missing argument, cannot get module info");
|
||||
rte_errno = EINVAL;
|
||||
return -rte_errno;
|
||||
}
|
||||
ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
|
||||
if (ret) {
|
||||
DRV_LOG(WARNING, "port %u ioctl(SIOCETHTOOL) failed: %s",
|
||||
dev->data->port_id, strerror(rte_errno));
|
||||
return ret;
|
||||
}
|
||||
modinfo->type = info.type;
|
||||
modinfo->eeprom_len = info.eeprom_len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* DPDK callback to retrieve plug-in module EEPROM data.
|
||||
*
|
||||
* @param dev
|
||||
* Pointer to Ethernet device structure.
|
||||
* @param[out] info
|
||||
* Storage for plug-in module EEPROM data.
|
||||
*
|
||||
* @return
|
||||
* 0 on success, a negative errno value otherwise and rte_errno is set.
|
||||
*/
|
||||
int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
|
||||
struct rte_dev_eeprom_info *info)
|
||||
{
|
||||
struct ethtool_eeprom *eeprom;
|
||||
struct ifreq ifr;
|
||||
int ret = 0;
|
||||
|
||||
if (!dev || !info) {
|
||||
DRV_LOG(WARNING, "missing argument, cannot get module eeprom");
|
||||
rte_errno = EINVAL;
|
||||
return -rte_errno;
|
||||
}
|
||||
eeprom = rte_calloc(__func__, 1,
|
||||
(sizeof(struct ethtool_eeprom) + info->length), 0);
|
||||
if (!eeprom) {
|
||||
DRV_LOG(WARNING, "port %u cannot allocate memory for "
|
||||
"eeprom data", dev->data->port_id);
|
||||
rte_errno = ENOMEM;
|
||||
return -rte_errno;
|
||||
}
|
||||
eeprom->cmd = ETHTOOL_GMODULEEEPROM;
|
||||
eeprom->offset = info->offset;
|
||||
eeprom->len = info->length;
|
||||
ifr = (struct ifreq) {
|
||||
.ifr_data = (void *)eeprom,
|
||||
};
|
||||
ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
|
||||
if (ret)
|
||||
DRV_LOG(WARNING, "port %u ioctl(SIOCETHTOOL) failed: %s",
|
||||
dev->data->port_id, strerror(rte_errno));
|
||||
else
|
||||
rte_memcpy(info->data, eeprom->data, info->length);
|
||||
rte_free(eeprom);
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user