| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* Copyright(c) 2023 Advanced Micro Devices, Inc */ |
| 3 |
|
| 4 |
#include "core.h" |
| 5 |
#include <linux/pds/pds_auxbus.h> |
| 6 |
|
| 7 |
static struct |
| 8 |
pdsc_viftype *pdsc_dl_find_viftype_by_id(struct pdsc *pdsc, |
| 9 |
enum devlink_param_type dl_id) |
| 10 |
{ |
| 11 |
int vt; |
| 12 |
|
| 13 |
if (!pdsc->viftype_status) |
| 14 |
return NULL; |
| 15 |
|
| 16 |
for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) { |
| 17 |
if (pdsc->viftype_status[vt].dl_id == dl_id) |
| 18 |
return &pdsc->viftype_status[vt]; |
| 19 |
} |
| 20 |
|
| 21 |
return NULL; |
| 22 |
} |
| 23 |
|
| 24 |
int pdsc_dl_enable_get(struct devlink *dl, u32 id, |
| 25 |
struct devlink_param_gset_ctx *ctx, |
| 26 |
struct netlink_ext_ack *extack) |
| 27 |
{ |
| 28 |
struct pdsc *pdsc = devlink_priv(dl); |
| 29 |
struct pdsc_viftype *vt_entry; |
| 30 |
|
| 31 |
vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id); |
| 32 |
if (!vt_entry) |
| 33 |
return -ENOENT; |
| 34 |
|
| 35 |
ctx->val.vbool = vt_entry->enabled; |
| 36 |
|
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
int pdsc_dl_enable_set(struct devlink *dl, u32 id, |
| 41 |
struct devlink_param_gset_ctx *ctx, |
| 42 |
struct netlink_ext_ack *extack) |
| 43 |
{ |
| 44 |
struct pdsc *pdsc = devlink_priv(dl); |
| 45 |
struct pdsc_viftype *vt_entry; |
| 46 |
int err = 0; |
| 47 |
int vf_id; |
| 48 |
|
| 49 |
vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id); |
| 50 |
if (!vt_entry || !vt_entry->supported) |
| 51 |
return -EOPNOTSUPP; |
| 52 |
|
| 53 |
if (vt_entry->enabled == ctx->val.vbool) |
| 54 |
return 0; |
| 55 |
|
| 56 |
vt_entry->enabled = ctx->val.vbool; |
| 57 |
for (vf_id = 0; vf_id < pdsc->num_vfs; vf_id++) { |
| 58 |
struct pdsc *vf = pdsc->vfs[vf_id].vf; |
| 59 |
|
| 60 |
if (ctx->val.vbool) |
| 61 |
err = pdsc_auxbus_dev_add(vf, pdsc, vt_entry->vif_id, |
| 62 |
&pdsc->vfs[vf_id].padev); |
| 63 |
else |
| 64 |
pdsc_auxbus_dev_del(vf, pdsc, &pdsc->vfs[vf_id].padev); |
| 65 |
} |
| 66 |
|
| 67 |
return err; |
| 68 |
} |
| 69 |
|
| 70 |
int pdsc_dl_enable_validate(struct devlink *dl, u32 id, |
| 71 |
union devlink_param_value val, |
| 72 |
struct netlink_ext_ack *extack) |
| 73 |
{ |
| 74 |
struct pdsc *pdsc = devlink_priv(dl); |
| 75 |
struct pdsc_viftype *vt_entry; |
| 76 |
|
| 77 |
vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id); |
| 78 |
if (!vt_entry || !vt_entry->supported) |
| 79 |
return -EOPNOTSUPP; |
| 80 |
|
| 81 |
if (!pdsc->viftype_status[vt_entry->vif_id].supported) |
| 82 |
return -ENODEV; |
| 83 |
|
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
int pdsc_dl_flash_update(struct devlink *dl, |
| 88 |
struct devlink_flash_update_params *params, |
| 89 |
struct netlink_ext_ack *extack) |
| 90 |
{ |
| 91 |
struct pdsc *pdsc = devlink_priv(dl); |
| 92 |
|
| 93 |
return pdsc_firmware_update(pdsc, params->fw, extack); |
| 94 |
} |
| 95 |
|
| 96 |
static char *fw_slotnames[] = { |
| 97 |
"fw.goldfw", |
| 98 |
"fw.mainfwa", |
| 99 |
"fw.mainfwb", |
| 100 |
}; |
| 101 |
|
| 102 |
int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req, |
| 103 |
struct netlink_ext_ack *extack) |
| 104 |
{ |
| 105 |
union pds_core_dev_cmd cmd = { |
| 106 |
.fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, |
| 107 |
.fw_control.oper = PDS_CORE_FW_GET_LIST, |
| 108 |
}; |
| 109 |
struct pds_core_fw_list_info fw_list = {}; |
| 110 |
struct pdsc *pdsc = devlink_priv(dl); |
| 111 |
union pds_core_dev_comp comp; |
| 112 |
char buf[32]; |
| 113 |
int listlen; |
| 114 |
int err; |
| 115 |
int i; |
| 116 |
|
| 117 |
mutex_lock(&pdsc->devcmd_lock); |
| 118 |
err = pdsc_devcmd_locked(pdsc, &cmd, &comp, pdsc->devcmd_timeout * 2); |
| 119 |
if (!err) |
| 120 |
memcpy_fromio(&fw_list, pdsc->cmd_regs->data, sizeof(fw_list)); |
| 121 |
mutex_unlock(&pdsc->devcmd_lock); |
| 122 |
|
| 123 |
listlen = min(fw_list.num_fw_slots, ARRAY_SIZE(fw_list.fw_names)); |
| 124 |
for (i = 0; i < listlen; i++) { |
| 125 |
char *fw_ver = fw_list.fw_names[i].fw_version; |
| 126 |
|
| 127 |
if (i < ARRAY_SIZE(fw_slotnames)) |
| 128 |
strscpy(buf, fw_slotnames[i], sizeof(buf)); |
| 129 |
else |
| 130 |
snprintf(buf, sizeof(buf), "fw.slot_%d", i); |
| 131 |
fw_ver[sizeof(fw_list.fw_names[i].fw_version) - 1] = '\0'; |
| 132 |
err = devlink_info_version_stored_put(req, buf, fw_ver); |
| 133 |
if (err) |
| 134 |
return err; |
| 135 |
} |
| 136 |
|
| 137 |
err = devlink_info_version_running_put(req, |
| 138 |
DEVLINK_INFO_VERSION_GENERIC_FW, |
| 139 |
pdsc->dev_info.fw_version); |
| 140 |
if (err) |
| 141 |
return err; |
| 142 |
|
| 143 |
snprintf(buf, sizeof(buf), "0x%x", pdsc->dev_info.asic_type); |
| 144 |
err = devlink_info_version_fixed_put(req, |
| 145 |
DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, |
| 146 |
buf); |
| 147 |
if (err) |
| 148 |
return err; |
| 149 |
|
| 150 |
snprintf(buf, sizeof(buf), "0x%x", pdsc->dev_info.asic_rev); |
| 151 |
err = devlink_info_version_fixed_put(req, |
| 152 |
DEVLINK_INFO_VERSION_GENERIC_ASIC_REV, |
| 153 |
buf); |
| 154 |
if (err) |
| 155 |
return err; |
| 156 |
|
| 157 |
return devlink_info_serial_number_put(req, pdsc->dev_info.serial_num); |
| 158 |
} |
| 159 |
|
| 160 |
int pdsc_fw_reporter_diagnose(struct devlink_health_reporter *reporter, |
| 161 |
struct devlink_fmsg *fmsg, |
| 162 |
struct netlink_ext_ack *extack) |
| 163 |
{ |
| 164 |
struct pdsc *pdsc = devlink_health_reporter_priv(reporter); |
| 165 |
|
| 166 |
mutex_lock(&pdsc->config_lock); |
| 167 |
if (test_bit(PDSC_S_FW_DEAD, &pdsc->state)) |
| 168 |
devlink_fmsg_string_pair_put(fmsg, "Status", "dead"); |
| 169 |
else if (!pdsc_is_fw_good(pdsc)) |
| 170 |
devlink_fmsg_string_pair_put(fmsg, "Status", "unhealthy"); |
| 171 |
else |
| 172 |
devlink_fmsg_string_pair_put(fmsg, "Status", "healthy"); |
| 173 |
mutex_unlock(&pdsc->config_lock); |
| 174 |
|
| 175 |
devlink_fmsg_u32_pair_put(fmsg, "State", |
| 176 |
pdsc->fw_status & ~PDS_CORE_FW_STS_F_GENERATION); |
| 177 |
devlink_fmsg_u32_pair_put(fmsg, "Generation", pdsc->fw_generation >> 4); |
| 178 |
devlink_fmsg_u32_pair_put(fmsg, "Recoveries", pdsc->fw_recoveries); |
| 179 |
|
| 180 |
return 0; |
| 181 |
} |