#include "ice_lib.h"
#include "ice_iflib.h"
#include <sys/queue.h>
#include <sys/sdt.h>
SDT_PROVIDER_DEFINE(ice_fwlog);
SDT_PROBE_DEFINE2(ice_fwlog, , , message, "uint8_t *", "int");
static int ice_reconfig_fw_log(struct ice_softc *sc, struct ice_fwlog_cfg *cfg);
static int ice_sysctl_fwlog_set_cfg_options(SYSCTL_HANDLER_ARGS);
static int ice_sysctl_fwlog_log_resolution(SYSCTL_HANDLER_ARGS);
static int ice_sysctl_fwlog_register(SYSCTL_HANDLER_ARGS);
static int ice_sysctl_fwlog_module_log_severity(SYSCTL_HANDLER_ARGS);
static int
ice_reconfig_fw_log(struct ice_softc *sc, struct ice_fwlog_cfg *cfg)
{
int status;
ice_fwlog_init(&sc->hw, cfg);
if (!ice_check_sq_alive(&sc->hw, &sc->hw.adminq))
return (0);
if (!ice_fwlog_supported(&sc->hw))
return (0);
status = ice_fwlog_set(&sc->hw, cfg);
if (status) {
device_printf(sc->dev,
"Failed to reconfigure firmware logging, err %s aq_err %s\n",
ice_status_str(status),
ice_aq_str(sc->hw.adminq.sq_last_status));
return (ENODEV);
}
return (0);
}
#define ICE_SYSCTL_HELP_FWLOG_LOG_RESOLUTION \
"\nControl firmware message limit to send per ARQ event" \
"\t\nMin: 1" \
"\t\nMax: 128"
#define ICE_SYSCTL_HELP_FWLOG_ARQ_ENA \
"\nControl whether to enable/disable reporting to admin Rx queue" \
"\n0 - Enable firmware reporting via ARQ" \
"\n1 - Disable firmware reporting via ARQ"
#define ICE_SYSCTL_HELP_FWLOG_UART_ENA \
"\nControl whether to enable/disable reporting to UART" \
"\n0 - Enable firmware reporting via UART" \
"\n1 - Disable firmware reporting via UART"
#define ICE_SYSCTL_HELP_FWLOG_ENABLE_ON_LOAD \
"\nControl whether to enable logging during the attach phase" \
"\n0 - Enable firmware logging during attach phase" \
"\n1 - Disable firmware logging during attach phase"
#define ICE_SYSCTL_HELP_FWLOG_REGISTER \
"\nControl whether to enable/disable firmware logging" \
"\n0 - Enable firmware logging" \
"\n1 - Disable firmware logging"
#define ICE_SYSCTL_HELP_FWLOG_MODULE_SEVERITY \
"\nControl the level of log output messages for this module" \
"\n\tverbose <4> - Verbose messages + (Error|Warning|Normal)" \
"\n\tnormal <3> - Normal messages + (Error|Warning)" \
"\n\twarning <2> - Warning messages + (Error)" \
"\n\terror <1> - Error messages" \
"\n\tnone <0> - Disables all logging for this module"
static int
ice_sysctl_fwlog_set_cfg_options(SYSCTL_HANDLER_ARGS)
{
struct ice_softc *sc = (struct ice_softc *)arg1;
struct ice_fwlog_cfg *cfg = &sc->hw.fwlog_cfg;
int error;
u16 option = (u16)arg2;
bool enabled;
enabled = !!(cfg->options & option);
error = sysctl_handle_bool(oidp, &enabled, 0, req);
if ((error) || (req->newptr == NULL))
return (error);
if (enabled)
cfg->options |= option;
else
cfg->options &= ~option;
return ice_reconfig_fw_log(sc, cfg);
}
static int
ice_sysctl_fwlog_log_resolution(SYSCTL_HANDLER_ARGS)
{
struct ice_softc *sc = (struct ice_softc *)arg1;
struct ice_fwlog_cfg *cfg = &sc->hw.fwlog_cfg;
int error;
u8 resolution;
UNREFERENCED_PARAMETER(arg2);
resolution = cfg->log_resolution;
error = sysctl_handle_8(oidp, &resolution, 0, req);
if ((error) || (req->newptr == NULL))
return (error);
if ((resolution < ICE_AQC_FW_LOG_MIN_RESOLUTION) ||
(resolution > ICE_AQC_FW_LOG_MAX_RESOLUTION)) {
device_printf(sc->dev, "Log resolution out-of-bounds\n");
return (EINVAL);
}
cfg->log_resolution = resolution;
return ice_reconfig_fw_log(sc, cfg);
}
static int
ice_sysctl_fwlog_register(SYSCTL_HANDLER_ARGS)
{
struct ice_softc *sc = (struct ice_softc *)arg1;
struct ice_fwlog_cfg *cfg = &sc->hw.fwlog_cfg;
int status;
int error;
u8 enabled;
UNREFERENCED_PARAMETER(arg2);
if (ice_test_state(&sc->state, ICE_STATE_ATTACHING)) {
device_printf(sc->dev, "Registering FW Logging via kenv is supported with the on_load option\n");
return (EIO);
}
if (cfg->options & ICE_FWLOG_OPTION_IS_REGISTERED)
enabled = true;
else
enabled = false;
error = sysctl_handle_bool(oidp, &enabled, 0, req);
if ((error) || (req->newptr == NULL))
return (error);
if (!ice_check_sq_alive(&sc->hw, &sc->hw.adminq))
return (0);
if (enabled) {
status = ice_fwlog_register(&sc->hw);
if (!status)
ice_set_bit(ICE_FEATURE_FW_LOGGING, sc->feat_en);
} else {
status = ice_fwlog_unregister(&sc->hw);
if (!status)
ice_clear_bit(ICE_FEATURE_FW_LOGGING, sc->feat_en);
}
if (status)
return (EIO);
return (0);
}
static int
ice_sysctl_fwlog_module_log_severity(SYSCTL_HANDLER_ARGS)
{
struct ice_softc *sc = (struct ice_softc *)arg1;
struct ice_fwlog_cfg *cfg = &sc->hw.fwlog_cfg;
struct sbuf *sbuf;
char *sev_str_end;
enum ice_aqc_fw_logging_mod module = (enum ice_aqc_fw_logging_mod)arg2;
int error, ll_num;
u8 log_level;
char sev_str[16];
bool sev_set = false;
log_level = cfg->module_entries[module].log_level;
sbuf = sbuf_new(NULL, sev_str, sizeof(sev_str), SBUF_FIXEDLEN);
sbuf_printf(sbuf, "%d<%s>", log_level, ice_log_sev_str(log_level));
sbuf_finish(sbuf);
sbuf_delete(sbuf);
error = sysctl_handle_string(oidp, sev_str, sizeof(sev_str), req);
if ((error) || (req->newptr == NULL))
return (error);
if (strcasecmp(ice_log_sev_str(ICE_FWLOG_LEVEL_VERBOSE), sev_str) == 0) {
log_level = ICE_FWLOG_LEVEL_VERBOSE;
sev_set = true;
} else if (strcasecmp(ice_log_sev_str(ICE_FWLOG_LEVEL_NORMAL), sev_str) == 0) {
log_level = ICE_FWLOG_LEVEL_NORMAL;
sev_set = true;
} else if (strcasecmp(ice_log_sev_str(ICE_FWLOG_LEVEL_WARNING), sev_str) == 0) {
log_level = ICE_FWLOG_LEVEL_WARNING;
sev_set = true;
} else if (strcasecmp(ice_log_sev_str(ICE_FWLOG_LEVEL_ERROR), sev_str) == 0) {
log_level = ICE_FWLOG_LEVEL_ERROR;
sev_set = true;
} else if (strcasecmp(ice_log_sev_str(ICE_FWLOG_LEVEL_NONE), sev_str) == 0) {
log_level = ICE_FWLOG_LEVEL_NONE;
sev_set = true;
}
if (!sev_set) {
ll_num = strtol(sev_str, &sev_str_end, 0);
if (sev_str_end == sev_str)
ll_num = -1;
if ((ll_num >= ICE_FWLOG_LEVEL_NONE) &&
(ll_num < ICE_FWLOG_LEVEL_INVALID))
log_level = ll_num;
else {
device_printf(sc->dev,
"%s: \"%s\" is not a valid log level\n",
__func__, sev_str);
return (EINVAL);
}
}
cfg->module_entries[module].log_level = log_level;
return ice_reconfig_fw_log(sc, cfg);
}
void
ice_add_fw_logging_tunables(struct ice_softc *sc, struct sysctl_oid *parent)
{
struct sysctl_oid_list *parent_list, *fwlog_list, *module_list;
struct sysctl_oid *fwlog_node, *module_node;
struct sysctl_ctx_list *ctx;
struct ice_hw *hw = &sc->hw;
struct ice_fwlog_cfg *cfg;
device_t dev = sc->dev;
enum ice_aqc_fw_logging_mod module;
u16 i;
cfg = &hw->fwlog_cfg;
ctx = device_get_sysctl_ctx(dev);
parent_list = SYSCTL_CHILDREN(parent);
fwlog_node = SYSCTL_ADD_NODE(ctx, parent_list, OID_AUTO, "fw_log",
ICE_CTLFLAG_DEBUG | CTLFLAG_RD, NULL,
"Firmware Logging");
fwlog_list = SYSCTL_CHILDREN(fwlog_node);
SYSCTL_ADD_PROC(ctx, fwlog_list, OID_AUTO, "on_load",
ICE_CTLFLAG_DEBUG | CTLTYPE_U8 | CTLFLAG_RWTUN, sc,
ICE_FWLOG_OPTION_REGISTER_ON_INIT, ice_sysctl_fwlog_set_cfg_options,
"CU", ICE_SYSCTL_HELP_FWLOG_ENABLE_ON_LOAD);
SYSCTL_ADD_PROC(ctx, fwlog_list, OID_AUTO, "register",
ICE_CTLFLAG_DEBUG | CTLTYPE_U8 | CTLFLAG_RWTUN, sc,
0, ice_sysctl_fwlog_register,
"CU", ICE_SYSCTL_HELP_FWLOG_REGISTER);
hw->pf_id = ice_get_pf_id(hw);
if (hw->pf_id == 0) {
module_node = SYSCTL_ADD_NODE(ctx, fwlog_list, OID_AUTO, "severity",
ICE_CTLFLAG_DEBUG | CTLFLAG_RD, NULL,
"Level of log output");
module_list = SYSCTL_CHILDREN(module_node);
for (i = 0; i < ICE_AQC_FW_LOG_ID_MAX; i++) {
cfg->module_entries[i].module_id = i;
cfg->module_entries[i].log_level = ICE_FWLOG_LEVEL_NONE;
module = (enum ice_aqc_fw_logging_mod)i;
SYSCTL_ADD_PROC(ctx, module_list,
OID_AUTO, ice_fw_module_str(module),
ICE_CTLFLAG_DEBUG | CTLTYPE_STRING | CTLFLAG_RWTUN, sc,
module, ice_sysctl_fwlog_module_log_severity,
"A", ICE_SYSCTL_HELP_FWLOG_MODULE_SEVERITY);
}
cfg->log_resolution = 10;
SYSCTL_ADD_PROC(ctx, fwlog_list, OID_AUTO, "log_resolution",
ICE_CTLFLAG_DEBUG | CTLTYPE_U8 | CTLFLAG_RWTUN, sc,
0, ice_sysctl_fwlog_log_resolution,
"CU", ICE_SYSCTL_HELP_FWLOG_LOG_RESOLUTION);
cfg->options |= ICE_FWLOG_OPTION_ARQ_ENA;
SYSCTL_ADD_PROC(ctx, fwlog_list, OID_AUTO, "arq_en",
ICE_CTLFLAG_DEBUG | CTLTYPE_U8 | CTLFLAG_RWTUN, sc,
ICE_FWLOG_OPTION_ARQ_ENA, ice_sysctl_fwlog_set_cfg_options,
"CU", ICE_SYSCTL_HELP_FWLOG_ARQ_ENA);
SYSCTL_ADD_PROC(ctx, fwlog_list, OID_AUTO, "uart_en",
ICE_CTLFLAG_DEBUG | CTLTYPE_U8 | CTLFLAG_RWTUN, sc,
ICE_FWLOG_OPTION_UART_ENA, ice_sysctl_fwlog_set_cfg_options,
"CU", ICE_SYSCTL_HELP_FWLOG_UART_ENA);
}
}
void
ice_handle_fw_log_event(struct ice_softc *sc, struct ice_aq_desc *desc,
void *buf)
{
SDT_PROBE2(ice_fwlog, , , message, (const u8 *)buf, desc->datalen);
ice_fwlog_event_dump(&sc->hw, desc, buf);
}