Commit 281f8203 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'net-devlink-return-the-driver-name-in-devlink_nl_info_fill'

Vincent Mailhol says:

====================
net: devlink: return the driver name in devlink_nl_info_fill

The driver name is available in device_driver::name. Right now,
drivers still have to report this piece of information themselves in
their devlink_ops::info_get callback function.

The goal of this series is to have the devlink core to report this
information instead of the drivers.

The first patch fulfills the actual goal of this series: modify
devlink core to report the driver name and clean-up all drivers. Both
have to be done in an atomic change to avoid attribute
duplication. This same patch also removes the
devlink_info_driver_name_put() function to prevent future drivers from
reporting the driver name themselves.

The second patch allows the core to call devlink_nl_info_fill() even
if the devlink_ops::info_get() callback is NULL. This leads to the
third and final patch which cleans up the drivers which have an empty
info_get().
====================

Link: https://lore.kernel.org/r/20221129095140.3913303-1-mailhol.vincent@wanadoo.frSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents a933e7f0 cf4590b9
...@@ -76,10 +76,6 @@ static int otx2_cpt_devlink_info_get(struct devlink *dl, ...@@ -76,10 +76,6 @@ static int otx2_cpt_devlink_info_get(struct devlink *dl,
struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf; struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
int err; int err;
err = devlink_info_driver_name_put(req, "rvu_cptpf");
if (err)
return err;
err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp, err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,
"fw.ae", OTX2_CPT_AE_TYPES); "fw.ae", OTX2_CPT_AE_TYPES);
if (err) if (err)
......
...@@ -1176,11 +1176,6 @@ static int hellcreek_devlink_info_get(struct dsa_switch *ds, ...@@ -1176,11 +1176,6 @@ static int hellcreek_devlink_info_get(struct dsa_switch *ds,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct hellcreek *hellcreek = ds->priv; struct hellcreek *hellcreek = ds->priv;
int ret;
ret = devlink_info_driver_name_put(req, "hellcreek");
if (ret)
return ret;
return devlink_info_version_fixed_put(req, return devlink_info_version_fixed_put(req,
DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
......
...@@ -821,11 +821,6 @@ int mv88e6xxx_devlink_info_get(struct dsa_switch *ds, ...@@ -821,11 +821,6 @@ int mv88e6xxx_devlink_info_get(struct dsa_switch *ds,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err;
err = devlink_info_driver_name_put(req, "mv88e6xxx");
if (err)
return err;
return devlink_info_version_fixed_put(req, return devlink_info_version_fixed_put(req,
DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
......
...@@ -120,16 +120,10 @@ int sja1105_devlink_info_get(struct dsa_switch *ds, ...@@ -120,16 +120,10 @@ int sja1105_devlink_info_get(struct dsa_switch *ds,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct sja1105_private *priv = ds->priv; struct sja1105_private *priv = ds->priv;
int rc;
rc = devlink_info_driver_name_put(req, "sja1105");
if (rc)
return rc;
rc = devlink_info_version_fixed_put(req, return devlink_info_version_fixed_put(req,
DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
priv->info->name); priv->info->name);
return rc;
} }
int sja1105_devlink_setup(struct dsa_switch *ds) int sja1105_devlink_setup(struct dsa_switch *ds)
......
...@@ -892,10 +892,6 @@ static int bnxt_dl_info_get(struct devlink *dl, struct devlink_info_req *req, ...@@ -892,10 +892,6 @@ static int bnxt_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
u32 ver = 0; u32 ver = 0;
int rc; int rc;
rc = devlink_info_driver_name_put(req, DRV_MODULE_NAME);
if (rc)
return rc;
if (BNXT_PF(bp) && (bp->flags & BNXT_FLAG_DSN_VALID)) { if (BNXT_PF(bp) && (bp->flags & BNXT_FLAG_DSN_VALID)) {
sprintf(buf, "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X", sprintf(buf, "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X",
bp->dsn[7], bp->dsn[6], bp->dsn[5], bp->dsn[4], bp->dsn[7], bp->dsn[6], bp->dsn[5], bp->dsn[4],
......
...@@ -37,18 +37,9 @@ static int dpaa2_eth_dl_info_get(struct devlink *devlink, ...@@ -37,18 +37,9 @@ static int dpaa2_eth_dl_info_get(struct devlink *devlink,
struct dpaa2_eth_devlink_priv *dl_priv = devlink_priv(devlink); struct dpaa2_eth_devlink_priv *dl_priv = devlink_priv(devlink);
struct dpaa2_eth_priv *priv = dl_priv->dpaa2_priv; struct dpaa2_eth_priv *priv = dl_priv->dpaa2_priv;
char buf[10]; char buf[10];
int err;
err = devlink_info_driver_name_put(req, KBUILD_MODNAME);
if (err)
return err;
scnprintf(buf, 10, "%d.%d", priv->dpni_ver_major, priv->dpni_ver_minor); scnprintf(buf, 10, "%d.%d", priv->dpni_ver_major, priv->dpni_ver_minor);
err = devlink_info_version_running_put(req, "dpni", buf); return devlink_info_version_running_put(req, "dpni", buf);
if (err)
return err;
return 0;
} }
static struct dpaa2_eth_trap_item * static struct dpaa2_eth_trap_item *
......
...@@ -3,14 +3,7 @@ ...@@ -3,14 +3,7 @@
#include "funeth.h" #include "funeth.h"
#include "funeth_devlink.h" #include "funeth_devlink.h"
static int fun_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
struct netlink_ext_ack *extack)
{
return devlink_info_driver_name_put(req, KBUILD_MODNAME);
}
static const struct devlink_ops fun_dl_ops = { static const struct devlink_ops fun_dl_ops = {
.info_get = fun_dl_info_get,
}; };
struct devlink *fun_devlink_alloc(struct device *dev) struct devlink *fun_devlink_alloc(struct device *dev)
......
...@@ -13,11 +13,6 @@ static int hclge_devlink_info_get(struct devlink *devlink, ...@@ -13,11 +13,6 @@ static int hclge_devlink_info_get(struct devlink *devlink,
struct hclge_devlink_priv *priv = devlink_priv(devlink); struct hclge_devlink_priv *priv = devlink_priv(devlink);
char version_str[HCLGE_DEVLINK_FW_STRING_LEN]; char version_str[HCLGE_DEVLINK_FW_STRING_LEN];
struct hclge_dev *hdev = priv->hdev; struct hclge_dev *hdev = priv->hdev;
int ret;
ret = devlink_info_driver_name_put(req, KBUILD_MODNAME);
if (ret)
return ret;
snprintf(version_str, sizeof(version_str), "%lu.%lu.%lu.%lu", snprintf(version_str, sizeof(version_str), "%lu.%lu.%lu.%lu",
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE3_MASK, hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
......
...@@ -13,11 +13,6 @@ static int hclgevf_devlink_info_get(struct devlink *devlink, ...@@ -13,11 +13,6 @@ static int hclgevf_devlink_info_get(struct devlink *devlink,
struct hclgevf_devlink_priv *priv = devlink_priv(devlink); struct hclgevf_devlink_priv *priv = devlink_priv(devlink);
char version_str[HCLGEVF_DEVLINK_FW_STRING_LEN]; char version_str[HCLGEVF_DEVLINK_FW_STRING_LEN];
struct hclgevf_dev *hdev = priv->hdev; struct hclgevf_dev *hdev = priv->hdev;
int ret;
ret = devlink_info_driver_name_put(req, KBUILD_MODNAME);
if (ret)
return ret;
snprintf(version_str, sizeof(version_str), "%lu.%lu.%lu.%lu", snprintf(version_str, sizeof(version_str), "%lu.%lu.%lu.%lu",
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE3_MASK, hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
......
...@@ -311,12 +311,6 @@ static int ice_devlink_info_get(struct devlink *devlink, ...@@ -311,12 +311,6 @@ static int ice_devlink_info_get(struct devlink *devlink,
} }
} }
err = devlink_info_driver_name_put(req, KBUILD_MODNAME);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Unable to set driver name");
goto out_free_ctx;
}
ice_info_get_dsn(pf, ctx); ice_info_get_dsn(pf, ctx);
err = devlink_info_serial_number_put(req, ctx->buf); err = devlink_info_serial_number_put(req, ctx->buf);
......
...@@ -1547,14 +1547,7 @@ static int rvu_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, ...@@ -1547,14 +1547,7 @@ static int rvu_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
return 0; return 0;
} }
static int rvu_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
struct netlink_ext_ack *extack)
{
return devlink_info_driver_name_put(req, DRV_NAME);
}
static const struct devlink_ops rvu_devlink_ops = { static const struct devlink_ops rvu_devlink_ops = {
.info_get = rvu_devlink_info_get,
.eswitch_mode_get = rvu_devlink_eswitch_mode_get, .eswitch_mode_get = rvu_devlink_eswitch_mode_get,
.eswitch_mode_set = rvu_devlink_eswitch_mode_set, .eswitch_mode_set = rvu_devlink_eswitch_mode_set,
}; };
......
...@@ -77,22 +77,7 @@ static const struct devlink_param otx2_dl_params[] = { ...@@ -77,22 +77,7 @@ static const struct devlink_param otx2_dl_params[] = {
otx2_dl_mcam_count_validate), otx2_dl_mcam_count_validate),
}; };
/* Devlink OPs */
static int otx2_devlink_info_get(struct devlink *devlink,
struct devlink_info_req *req,
struct netlink_ext_ack *extack)
{
struct otx2_devlink *otx2_dl = devlink_priv(devlink);
struct otx2_nic *pfvf = otx2_dl->pfvf;
if (is_otx2_vf(pfvf->pcifunc))
return devlink_info_driver_name_put(req, "rvu_nicvf");
return devlink_info_driver_name_put(req, "rvu_nicpf");
}
static const struct devlink_ops otx2_devlink_ops = { static const struct devlink_ops otx2_devlink_ops = {
.info_get = otx2_devlink_info_get,
}; };
int otx2_register_dl(struct otx2_nic *pfvf) int otx2_register_dl(struct otx2_nic *pfvf)
......
...@@ -355,11 +355,6 @@ static int prestera_dl_info_get(struct devlink *dl, ...@@ -355,11 +355,6 @@ static int prestera_dl_info_get(struct devlink *dl,
{ {
struct prestera_switch *sw = devlink_priv(dl); struct prestera_switch *sw = devlink_priv(dl);
char buf[16]; char buf[16];
int err;
err = devlink_info_driver_name_put(req, PRESTERA_DRV_NAME);
if (err)
return err;
snprintf(buf, sizeof(buf), "%d.%d.%d", snprintf(buf, sizeof(buf), "%d.%d.%d",
sw->dev->fw_rev.maj, sw->dev->fw_rev.maj,
......
...@@ -46,10 +46,6 @@ mlx5_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, ...@@ -46,10 +46,6 @@ mlx5_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
u32 running_fw, stored_fw; u32 running_fw, stored_fw;
int err; int err;
err = devlink_info_driver_name_put(req, KBUILD_MODNAME);
if (err)
return err;
err = devlink_info_version_fixed_put(req, "fw.psid", dev->board_id); err = devlink_info_version_fixed_put(req, "fw.psid", dev->board_id);
if (err) if (err)
return err; return err;
......
...@@ -1459,11 +1459,6 @@ mlxsw_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, ...@@ -1459,11 +1459,6 @@ mlxsw_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
char buf[32]; char buf[32];
int err; int err;
err = devlink_info_driver_name_put(req,
mlxsw_core->bus_info->device_kind);
if (err)
return err;
mlxsw_reg_mgir_pack(mgir_pl); mlxsw_reg_mgir_pack(mgir_pl);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mgir), mgir_pl); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mgir), mgir_pl);
if (err) if (err)
......
...@@ -239,10 +239,6 @@ nfp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, ...@@ -239,10 +239,6 @@ nfp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
char *buf = NULL; char *buf = NULL;
int err; int err;
err = devlink_info_driver_name_put(req, "nfp");
if (err)
return err;
vendor = nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor"); vendor = nfp_hwinfo_lookup(pf->hwinfo, "assembly.vendor");
part = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno"); part = nfp_hwinfo_lookup(pf->hwinfo, "assembly.partno");
sn = nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial"); sn = nfp_hwinfo_lookup(pf->hwinfo, "assembly.serial");
......
...@@ -26,10 +26,6 @@ static int ionic_dl_info_get(struct devlink *dl, struct devlink_info_req *req, ...@@ -26,10 +26,6 @@ static int ionic_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
char buf[16]; char buf[16];
int err = 0; int err = 0;
err = devlink_info_driver_name_put(req, IONIC_DRV_NAME);
if (err)
return err;
err = devlink_info_version_running_put(req, err = devlink_info_version_running_put(req,
DEVLINK_INFO_VERSION_GENERIC_FW, DEVLINK_INFO_VERSION_GENERIC_FW,
idev->dev_info.fw_version); idev->dev_info.fw_version);
......
...@@ -162,10 +162,6 @@ static int qed_devlink_info_get(struct devlink *devlink, ...@@ -162,10 +162,6 @@ static int qed_devlink_info_get(struct devlink *devlink,
dev_info = &cdev->common_dev_info; dev_info = &cdev->common_dev_info;
err = devlink_info_driver_name_put(req, KBUILD_MODNAME);
if (err)
return err;
memcpy(buf, cdev->hwfns[0].hw_info.part_num, sizeof(cdev->hwfns[0].hw_info.part_num)); memcpy(buf, cdev->hwfns[0].hw_info.part_num, sizeof(cdev->hwfns[0].hw_info.part_num));
buf[sizeof(cdev->hwfns[0].hw_info.part_num)] = 0; buf[sizeof(cdev->hwfns[0].hw_info.part_num)] = 0;
......
...@@ -994,9 +994,6 @@ static int nsim_dev_info_get(struct devlink *devlink, ...@@ -994,9 +994,6 @@ static int nsim_dev_info_get(struct devlink *devlink,
{ {
int err; int err;
err = devlink_info_driver_name_put(req, DRV_NAME);
if (err)
return err;
err = devlink_info_version_stored_put_ext(req, "fw.mgmt", "10.20.30", err = devlink_info_version_stored_put_ext(req, "fw.mgmt", "10.20.30",
DEVLINK_INFO_VERSION_TYPE_COMPONENT); DEVLINK_INFO_VERSION_TYPE_COMPONENT);
if (err) if (err)
......
...@@ -1647,10 +1647,6 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, ...@@ -1647,10 +1647,6 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
char buf[32]; char buf[32];
int err; int err;
err = devlink_info_driver_name_put(req, KBUILD_MODNAME);
if (err)
return err;
fw_image = bp->fw_loader ? "loader" : "fw"; fw_image = bp->fw_loader ? "loader" : "fw";
sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version); sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version);
err = devlink_info_version_running_put(req, fw_image, buf); err = devlink_info_version_running_put(req, fw_image, buf);
......
...@@ -1762,8 +1762,6 @@ int devlink_region_snapshot_create(struct devlink_region *region, ...@@ -1762,8 +1762,6 @@ int devlink_region_snapshot_create(struct devlink_region *region,
u8 *data, u32 snapshot_id); u8 *data, u32 snapshot_id);
int devlink_info_serial_number_put(struct devlink_info_req *req, int devlink_info_serial_number_put(struct devlink_info_req *req,
const char *sn); const char *sn);
int devlink_info_driver_name_put(struct devlink_info_req *req,
const char *name);
int devlink_info_board_serial_number_put(struct devlink_info_req *req, int devlink_info_board_serial_number_put(struct devlink_info_req *req,
const char *bsn); const char *bsn);
......
...@@ -6707,14 +6707,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, ...@@ -6707,14 +6707,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
return err; return err;
} }
int devlink_info_driver_name_put(struct devlink_info_req *req, const char *name)
{
if (!req->msg)
return 0;
return nla_put_string(req->msg, DEVLINK_ATTR_INFO_DRIVER_NAME, name);
}
EXPORT_SYMBOL_GPL(devlink_info_driver_name_put);
int devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn) int devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn)
{ {
if (!req->msg) if (!req->msg)
...@@ -6823,11 +6815,25 @@ int devlink_info_version_running_put_ext(struct devlink_info_req *req, ...@@ -6823,11 +6815,25 @@ int devlink_info_version_running_put_ext(struct devlink_info_req *req,
} }
EXPORT_SYMBOL_GPL(devlink_info_version_running_put_ext); EXPORT_SYMBOL_GPL(devlink_info_version_running_put_ext);
static int devlink_nl_driver_info_get(struct device_driver *drv,
struct devlink_info_req *req)
{
if (!drv)
return 0;
if (drv->name[0])
return nla_put_string(req->msg, DEVLINK_ATTR_INFO_DRIVER_NAME,
drv->name);
return 0;
}
static int static int
devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink,
enum devlink_command cmd, u32 portid, enum devlink_command cmd, u32 portid,
u32 seq, int flags, struct netlink_ext_ack *extack) u32 seq, int flags, struct netlink_ext_ack *extack)
{ {
struct device *dev = devlink_to_dev(devlink);
struct devlink_info_req req = {}; struct devlink_info_req req = {};
void *hdr; void *hdr;
int err; int err;
...@@ -6841,7 +6847,13 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, ...@@ -6841,7 +6847,13 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink,
goto err_cancel_msg; goto err_cancel_msg;
req.msg = msg; req.msg = msg;
err = devlink->ops->info_get(devlink, &req, extack); if (devlink->ops->info_get) {
err = devlink->ops->info_get(devlink, &req, extack);
if (err)
goto err_cancel_msg;
}
err = devlink_nl_driver_info_get(dev->driver, &req);
if (err) if (err)
goto err_cancel_msg; goto err_cancel_msg;
...@@ -6860,9 +6872,6 @@ static int devlink_nl_cmd_info_get_doit(struct sk_buff *skb, ...@@ -6860,9 +6872,6 @@ static int devlink_nl_cmd_info_get_doit(struct sk_buff *skb,
struct sk_buff *msg; struct sk_buff *msg;
int err; int err;
if (!devlink->ops->info_get)
return -EOPNOTSUPP;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
...@@ -6888,7 +6897,7 @@ static int devlink_nl_cmd_info_get_dumpit(struct sk_buff *msg, ...@@ -6888,7 +6897,7 @@ static int devlink_nl_cmd_info_get_dumpit(struct sk_buff *msg,
int err = 0; int err = 0;
devlinks_xa_for_each_registered_get(sock_net(msg->sk), index, devlink) { devlinks_xa_for_each_registered_get(sock_net(msg->sk), index, devlink) {
if (idx < start || !devlink->ops->info_get) if (idx < start)
goto inc; goto inc;
devl_lock(devlink); devl_lock(devlink);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment