Skip to content

Commit

Permalink
ice: add ability to read and configure FW log data
Browse files Browse the repository at this point in the history
Once logging is enabled the user should read the data from the 'data'
file. The data is in the form of a binary blob that can be sent to Intel
for decoding. To read the data use a command like:

  # cat /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/data > log_data.bin

If the user wants to clear the FW log data that has been stored in the
driver then they can write any value to the 'data' file and that will clear
the data. An example is:

  # echo 34 > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/data

In addition to being able to read the data the user can configure how
much memory is used to store FW log data. This allows the user to
increase/decrease the amount of memory based on the users situation.
The data is stored such that if the memory fills up then the oldest data
will get overwritten in a circular manner. To change the amount of
memory the user can write to the 'log_size' file like this:

  # echo <value> > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/log_size

Where <value> is one of 128K, 256K, 512K, 1M, and 2M. The default value
is 1M.

The user can see the current value of 'log_size' by reading the file:

  # cat /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/log_size

Signed-off-by: Paul M Stillwell Jr <paul.m.stillwell.jr@intel.com>
Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
  • Loading branch information
Paul M Stillwell Jr authored and Tony Nguyen committed Dec 14, 2023
1 parent 73671c3 commit 9d3535e
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,7 @@ enum ice_aqc_fw_logging_mod {
/* Set FW Logging configuration (indirect 0xFF30)
* Register for FW Logging (indirect 0xFF31)
* Query FW Logging (indirect 0xFF32)
* FW Log Event (indirect 0xFF33)
*/
struct ice_aqc_fw_log {
u8 cmd_flags;
Expand Down Expand Up @@ -2726,6 +2727,7 @@ enum ice_adminq_opc {
ice_aqc_opc_fw_logs_config = 0xFF30,
ice_aqc_opc_fw_logs_register = 0xFF31,
ice_aqc_opc_fw_logs_query = 0xFF32,
ice_aqc_opc_fw_logs_event = 0xFF33,
};

#endif /* _ICE_ADMINQ_CMD_H_ */
210 changes: 210 additions & 0 deletions drivers/net/ethernet/intel/ice/ice_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ static const char * const ice_fwlog_level_string[] = {
"verbose",
};

/* the order in this array is important. it matches the ordering of the
* values in the FW so the index is the same value as in ice_fwlog_level
*/
static const char * const ice_fwlog_log_size[] = {
"128K",
"256K",
"512K",
"1M",
"2M",
};

/**
* ice_fwlog_print_module_cfg - print current FW logging module configuration
* @hw: pointer to the HW structure
Expand Down Expand Up @@ -376,6 +387,199 @@ static const struct file_operations ice_debugfs_enable_fops = {
.write = ice_debugfs_enable_write,
};

/**
* ice_debugfs_log_size_read - read from 'log_size' file
* @filp: the opened file
* @buffer: where to write the data for the user to read
* @count: the size of the user's buffer
* @ppos: file position offset
*/
static ssize_t ice_debugfs_log_size_read(struct file *filp,
char __user *buffer, size_t count,
loff_t *ppos)
{
struct ice_pf *pf = filp->private_data;
struct ice_hw *hw = &pf->hw;
char buff[32] = {};
int index;

index = hw->fwlog_ring.index;
snprintf(buff, sizeof(buff), "%s\n", ice_fwlog_log_size[index]);

return simple_read_from_buffer(buffer, count, ppos, buff, strlen(buff));
}

/**
* ice_debugfs_log_size_write - write into 'log_size' file
* @filp: the opened file
* @buf: where to find the user's data
* @count: the length of the user's data
* @ppos: file position offset
*/
static ssize_t
ice_debugfs_log_size_write(struct file *filp, const char __user *buf,
size_t count, loff_t *ppos)
{
struct ice_pf *pf = filp->private_data;
struct device *dev = ice_pf_to_dev(pf);
struct ice_hw *hw = &pf->hw;
char user_val[8], *cmd_buf;
ssize_t ret;
int index;

/* don't allow partial writes or invalid input */
if (*ppos != 0 || count > 5)
return -EINVAL;

cmd_buf = memdup_user(buf, count);
if (IS_ERR(cmd_buf))
return PTR_ERR(cmd_buf);

ret = sscanf(cmd_buf, "%s", user_val);
if (ret != 1)
return -EINVAL;

index = sysfs_match_string(ice_fwlog_log_size, user_val);
if (index < 0) {
dev_info(dev, "Invalid log size '%s'. The value must be one of 128K, 256K, 512K, 1M, 2M\n",
user_val);
ret = -EINVAL;
goto log_size_write_error;
} else if (hw->fwlog_cfg.options & ICE_FWLOG_OPTION_IS_REGISTERED) {
dev_info(dev, "FW logging is currently running. Please disable FW logging to change log_size\n");
ret = -EINVAL;
goto log_size_write_error;
}

/* free all the buffers and the tracking info and resize */
ice_fwlog_realloc_rings(hw, index);

/* if we get here, nothing went wrong; return count since we didn't
* really write anything
*/
ret = (ssize_t)count;

log_size_write_error:
/* This function always consumes all of the written input, or produces
* an error. Check and enforce this. Otherwise, the write operation
* won't complete properly.
*/
if (WARN_ON(ret != (ssize_t)count && ret >= 0))
ret = -EIO;

return ret;
}

static const struct file_operations ice_debugfs_log_size_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = ice_debugfs_log_size_read,
.write = ice_debugfs_log_size_write,
};

/**
* ice_debugfs_data_read - read from 'data' file
* @filp: the opened file
* @buffer: where to write the data for the user to read
* @count: the size of the user's buffer
* @ppos: file position offset
*/
static ssize_t ice_debugfs_data_read(struct file *filp, char __user *buffer,
size_t count, loff_t *ppos)
{
struct ice_pf *pf = filp->private_data;
struct ice_hw *hw = &pf->hw;
int data_copied = 0;
bool done = false;

if (ice_fwlog_ring_empty(&hw->fwlog_ring))
return 0;

while (!ice_fwlog_ring_empty(&hw->fwlog_ring) && !done) {
struct ice_fwlog_data *log;
u16 cur_buf_len;

log = &hw->fwlog_ring.rings[hw->fwlog_ring.head];
cur_buf_len = log->data_size;
if (cur_buf_len >= count) {
done = true;
continue;
}

if (copy_to_user(buffer, log->data, cur_buf_len)) {
/* if there is an error then bail and return whatever
* the driver has copied so far
*/
done = true;
continue;
}

data_copied += cur_buf_len;
buffer += cur_buf_len;
count -= cur_buf_len;
*ppos += cur_buf_len;
ice_fwlog_ring_increment(&hw->fwlog_ring.head,
hw->fwlog_ring.size);
}

return data_copied;
}

/**
* ice_debugfs_data_write - write into 'data' file
* @filp: the opened file
* @buf: where to find the user's data
* @count: the length of the user's data
* @ppos: file position offset
*/
static ssize_t
ice_debugfs_data_write(struct file *filp, const char __user *buf, size_t count,
loff_t *ppos)
{
struct ice_pf *pf = filp->private_data;
struct device *dev = ice_pf_to_dev(pf);
struct ice_hw *hw = &pf->hw;
ssize_t ret;

/* don't allow partial writes */
if (*ppos != 0)
return 0;

/* any value is allowed to clear the buffer so no need to even look at
* what the value is
*/
if (!(hw->fwlog_cfg.options & ICE_FWLOG_OPTION_IS_REGISTERED)) {
hw->fwlog_ring.head = 0;
hw->fwlog_ring.tail = 0;
} else {
dev_info(dev, "Can't clear FW log data while FW log running\n");
ret = -EINVAL;
goto nr_buffs_write_error;
}

/* if we get here, nothing went wrong; return count since we didn't
* really write anything
*/
ret = (ssize_t)count;

nr_buffs_write_error:
/* This function always consumes all of the written input, or produces
* an error. Check and enforce this. Otherwise, the write operation
* won't complete properly.
*/
if (WARN_ON(ret != (ssize_t)count && ret >= 0))
ret = -EIO;

return ret;
}

static const struct file_operations ice_debugfs_data_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = ice_debugfs_data_read,
.write = ice_debugfs_data_write,
};

/**
* ice_debugfs_fwlog_init - setup the debugfs directory
* @pf: the ice that is starting up
Expand Down Expand Up @@ -430,6 +634,12 @@ void ice_debugfs_fwlog_init(struct ice_pf *pf)
debugfs_create_file("enable", 0600, pf->ice_debugfs_pf_fwlog,
pf, &ice_debugfs_enable_fops);

debugfs_create_file("log_size", 0600, pf->ice_debugfs_pf_fwlog,
pf, &ice_debugfs_log_size_fops);

debugfs_create_file("data", 0600, pf->ice_debugfs_pf_fwlog,
pf, &ice_debugfs_data_fops);

return;

err_create_module_files:
Expand Down
Loading

0 comments on commit 9d3535e

Please sign in to comment.