forked from Minki/linux
RDMA: Simplify get firmware interface
There is a need to forward FW version to user space application through RDMA netlink. In order to make it safe, there is need to declare nla_policy and limit the size of FW string. The new define IB_FW_VERSION_NAME_MAX will limit the size of FW version string. That define was chosen to be equal to ETHTOOL_FWVERS_LEN, because many drivers anyway are limited by that value indirectly. The introduction of this define allows us to remove the string size from get_fw_str function signature. Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
This commit is contained in:
parent
ac50525374
commit
9abb0d1bbd
@ -336,10 +336,10 @@ static int read_port_immutable(struct ib_device *device)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ib_get_device_fw_str(struct ib_device *dev, char *str, size_t str_len)
|
||||
void ib_get_device_fw_str(struct ib_device *dev, char *str)
|
||||
{
|
||||
if (dev->get_dev_fw_str)
|
||||
dev->get_dev_fw_str(dev, str, str_len);
|
||||
dev->get_dev_fw_str(dev, str);
|
||||
else
|
||||
str[0] = '\0';
|
||||
}
|
||||
|
@ -1210,8 +1210,8 @@ static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr,
|
||||
{
|
||||
struct ib_device *dev = container_of(device, struct ib_device, dev);
|
||||
|
||||
ib_get_device_fw_str(dev, buf, PAGE_SIZE);
|
||||
strlcat(buf, "\n", PAGE_SIZE);
|
||||
ib_get_device_fw_str(dev, buf);
|
||||
strlcat(buf, "\n", IB_FW_VERSION_NAME_MAX);
|
||||
return strlen(buf);
|
||||
}
|
||||
|
||||
|
@ -1336,8 +1336,7 @@ static int iwch_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_dev_fw_ver_str(struct ib_device *ibdev, char *str,
|
||||
size_t str_len)
|
||||
static void get_dev_fw_ver_str(struct ib_device *ibdev, char *str)
|
||||
{
|
||||
struct iwch_dev *iwch_dev = to_iwch_dev(ibdev);
|
||||
struct ethtool_drvinfo info;
|
||||
@ -1345,7 +1344,7 @@ static void get_dev_fw_ver_str(struct ib_device *ibdev, char *str,
|
||||
|
||||
pr_debug("%s dev 0x%p\n", __func__, iwch_dev);
|
||||
lldev->ethtool_ops->get_drvinfo(lldev, &info);
|
||||
snprintf(str, str_len, "%s", info.fw_version);
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", info.fw_version);
|
||||
}
|
||||
|
||||
int iwch_register_device(struct iwch_dev *dev)
|
||||
|
@ -517,14 +517,13 @@ static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_dev_fw_str(struct ib_device *dev, char *str,
|
||||
size_t str_len)
|
||||
static void get_dev_fw_str(struct ib_device *dev, char *str)
|
||||
{
|
||||
struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
|
||||
ibdev);
|
||||
pr_debug("%s dev 0x%p\n", __func__, dev);
|
||||
|
||||
snprintf(str, str_len, "%u.%u.%u.%u",
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u.%u",
|
||||
FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
|
||||
FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
|
||||
FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
|
||||
|
@ -1561,14 +1561,13 @@ static void init_ibport(struct hfi1_pportdata *ppd)
|
||||
RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
|
||||
}
|
||||
|
||||
static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str,
|
||||
size_t str_len)
|
||||
static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str)
|
||||
{
|
||||
struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
|
||||
struct hfi1_ibdev *dev = dev_from_rdi(rdi);
|
||||
u32 ver = dd_from_dev(dev)->dc8051_ver;
|
||||
|
||||
snprintf(str, str_len, "%u.%u.%u", dc8051_ver_maj(ver),
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u", dc8051_ver_maj(ver),
|
||||
dc8051_ver_min(ver), dc8051_ver_patch(ver));
|
||||
}
|
||||
|
||||
|
@ -2584,13 +2584,12 @@ static const char * const i40iw_hw_stat_names[] = {
|
||||
"iwRdmaInv"
|
||||
};
|
||||
|
||||
static void i40iw_get_dev_fw_str(struct ib_device *dev, char *str,
|
||||
size_t str_len)
|
||||
static void i40iw_get_dev_fw_str(struct ib_device *dev, char *str)
|
||||
{
|
||||
u32 firmware_version = I40IW_FW_VERSION;
|
||||
|
||||
snprintf(str, str_len, "%u.%u", firmware_version,
|
||||
(firmware_version & 0x000000ff));
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u", firmware_version,
|
||||
(firmware_version & 0x000000ff));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2587,12 +2587,11 @@ static int mlx4_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_fw_ver_str(struct ib_device *device, char *str,
|
||||
size_t str_len)
|
||||
static void get_fw_ver_str(struct ib_device *device, char *str)
|
||||
{
|
||||
struct mlx4_ib_dev *dev =
|
||||
container_of(device, struct mlx4_ib_dev, ib_dev);
|
||||
snprintf(str, str_len, "%d.%d.%d",
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%d",
|
||||
(int) (dev->dev->caps.fw_ver >> 32),
|
||||
(int) (dev->dev->caps.fw_ver >> 16) & 0xffff,
|
||||
(int) dev->dev->caps.fw_ver & 0xffff);
|
||||
|
@ -3285,13 +3285,13 @@ static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_dev_fw_str(struct ib_device *ibdev, char *str,
|
||||
size_t str_len)
|
||||
static void get_dev_fw_str(struct ib_device *ibdev, char *str)
|
||||
{
|
||||
struct mlx5_ib_dev *dev =
|
||||
container_of(ibdev, struct mlx5_ib_dev, ib_dev);
|
||||
snprintf(str, str_len, "%d.%d.%04d", fw_rev_maj(dev->mdev),
|
||||
fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev));
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%04d",
|
||||
fw_rev_maj(dev->mdev), fw_rev_min(dev->mdev),
|
||||
fw_rev_sub(dev->mdev));
|
||||
}
|
||||
|
||||
static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev)
|
||||
|
@ -1178,12 +1178,11 @@ static int mthca_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_dev_fw_str(struct ib_device *device, char *str,
|
||||
size_t str_len)
|
||||
static void get_dev_fw_str(struct ib_device *device, char *str)
|
||||
{
|
||||
struct mthca_dev *dev =
|
||||
container_of(device, struct mthca_dev, ib_dev);
|
||||
snprintf(str, str_len, "%d.%d.%d",
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%d",
|
||||
(int) (dev->fw_ver >> 32),
|
||||
(int) (dev->fw_ver >> 16) & 0xffff,
|
||||
(int) dev->fw_ver & 0xffff);
|
||||
|
@ -3672,15 +3672,14 @@ static int nes_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_dev_fw_str(struct ib_device *dev, char *str,
|
||||
size_t str_len)
|
||||
static void get_dev_fw_str(struct ib_device *dev, char *str)
|
||||
{
|
||||
struct nes_ib_device *nesibdev =
|
||||
container_of(dev, struct nes_ib_device, ibdev);
|
||||
struct nes_vnic *nesvnic = nesibdev->nesvnic;
|
||||
|
||||
nes_debug(NES_DBG_INIT, "\n");
|
||||
snprintf(str, str_len, "%u.%u",
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u",
|
||||
(nesvnic->nesdev->nesadapter->firmware_version >> 16),
|
||||
(nesvnic->nesdev->nesadapter->firmware_version & 0x000000ff));
|
||||
}
|
||||
|
@ -107,12 +107,11 @@ static int ocrdma_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_dev_fw_str(struct ib_device *device, char *str,
|
||||
size_t str_len)
|
||||
static void get_dev_fw_str(struct ib_device *device, char *str)
|
||||
{
|
||||
struct ocrdma_dev *dev = get_ocrdma_dev(device);
|
||||
|
||||
snprintf(str, str_len, "%s", &dev->attr.fw_ver[0]);
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", &dev->attr.fw_ver[0]);
|
||||
}
|
||||
|
||||
static int ocrdma_register_device(struct ocrdma_dev *dev)
|
||||
|
@ -68,13 +68,12 @@ static enum rdma_link_layer qedr_link_layer(struct ib_device *device,
|
||||
return IB_LINK_LAYER_ETHERNET;
|
||||
}
|
||||
|
||||
static void qedr_get_dev_fw_str(struct ib_device *ibdev, char *str,
|
||||
size_t str_len)
|
||||
static void qedr_get_dev_fw_str(struct ib_device *ibdev, char *str)
|
||||
{
|
||||
struct qedr_dev *qedr = get_qedr_dev(ibdev);
|
||||
u32 fw_ver = (u32)qedr->attr.fw_ver;
|
||||
|
||||
snprintf(str, str_len, "%d. %d. %d. %d",
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%d. %d. %d. %d",
|
||||
(fw_ver >> 24) & 0xFF, (fw_ver >> 16) & 0xFF,
|
||||
(fw_ver >> 8) & 0xFF, fw_ver & 0xFF);
|
||||
}
|
||||
|
@ -333,9 +333,7 @@ static int usnic_port_immutable(struct ib_device *ibdev, u8 port_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usnic_get_dev_fw_str(struct ib_device *device,
|
||||
char *str,
|
||||
size_t str_len)
|
||||
static void usnic_get_dev_fw_str(struct ib_device *device, char *str)
|
||||
{
|
||||
struct usnic_ib_dev *us_ibdev =
|
||||
container_of(device, struct usnic_ib_dev, ib_dev);
|
||||
@ -345,7 +343,7 @@ static void usnic_get_dev_fw_str(struct ib_device *device,
|
||||
us_ibdev->netdev->ethtool_ops->get_drvinfo(us_ibdev->netdev, &info);
|
||||
mutex_unlock(&us_ibdev->usdev_lock);
|
||||
|
||||
snprintf(str, str_len, "%s", info.fw_version);
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", info.fw_version);
|
||||
}
|
||||
|
||||
/* Start of PF discovery section */
|
||||
|
@ -102,12 +102,11 @@ static struct device_attribute *pvrdma_class_attributes[] = {
|
||||
&dev_attr_board_id
|
||||
};
|
||||
|
||||
static void pvrdma_get_fw_ver_str(struct ib_device *device, char *str,
|
||||
size_t str_len)
|
||||
static void pvrdma_get_fw_ver_str(struct ib_device *device, char *str)
|
||||
{
|
||||
struct pvrdma_dev *dev =
|
||||
container_of(device, struct pvrdma_dev, ib_dev);
|
||||
snprintf(str, str_len, "%d.%d.%d\n",
|
||||
snprintf(str, IB_FW_VERSION_NAME_MAX, "%d.%d.%d\n",
|
||||
(int) (dev->dsr->caps.fw_ver >> 32),
|
||||
(int) (dev->dsr->caps.fw_ver >> 16) & 0xffff,
|
||||
(int) dev->dsr->caps.fw_ver & 0xffff);
|
||||
|
@ -62,8 +62,7 @@ static void ipoib_get_drvinfo(struct net_device *netdev,
|
||||
{
|
||||
struct ipoib_dev_priv *priv = ipoib_priv(netdev);
|
||||
|
||||
ib_get_device_fw_str(priv->ca, drvinfo->fw_version,
|
||||
sizeof(drvinfo->fw_version));
|
||||
ib_get_device_fw_str(priv->ca, drvinfo->fw_version);
|
||||
|
||||
strlcpy(drvinfo->bus_info, dev_name(priv->ca->dev.parent),
|
||||
sizeof(drvinfo->bus_info));
|
||||
|
@ -64,6 +64,8 @@
|
||||
#include <linux/cgroup_rdma.h>
|
||||
#include <uapi/rdma/ib_user_verbs.h>
|
||||
|
||||
#define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN
|
||||
|
||||
extern struct workqueue_struct *ib_wq;
|
||||
extern struct workqueue_struct *ib_comp_wq;
|
||||
|
||||
@ -2307,7 +2309,7 @@ struct ib_device {
|
||||
* in fast paths.
|
||||
*/
|
||||
int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
|
||||
void (*get_dev_fw_str)(struct ib_device *, char *str, size_t str_len);
|
||||
void (*get_dev_fw_str)(struct ib_device *, char *str);
|
||||
};
|
||||
|
||||
struct ib_client {
|
||||
@ -2343,7 +2345,7 @@ struct ib_client {
|
||||
struct ib_device *ib_alloc_device(size_t size);
|
||||
void ib_dealloc_device(struct ib_device *device);
|
||||
|
||||
void ib_get_device_fw_str(struct ib_device *device, char *str, size_t str_len);
|
||||
void ib_get_device_fw_str(struct ib_device *device, char *str);
|
||||
|
||||
int ib_register_device(struct ib_device *device,
|
||||
int (*port_callback)(struct ib_device *,
|
||||
|
Loading…
Reference in New Issue
Block a user