Skip to content

Commit 73671c3

Browse files
pmstillwanguy11
authored andcommitted
ice: enable FW logging
Once users have configured the FW logging then allow them to enable it by writing to the 'fwlog/enable' file. The file accepts a boolean value (0 or 1) where 1 means enable FW logging and 0 means disable FW logging. # echo <value> > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/enable Where <value> is 0 or 1. The user can read the 'fwlog/enable' file to see whether logging is enabled or not. Reading the actual data is a separate patch. To see the current value then: # cat /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/enable Signed-off-by: Paul M Stillwell Jr <[email protected]> Tested-by: Pucha Himasekhar Reddy <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent 96a9a93 commit 73671c3

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

drivers/net/ethernet/intel/ice/ice_adminq_cmd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,7 @@ enum ice_aqc_fw_logging_mod {
23932393
};
23942394

23952395
/* Set FW Logging configuration (indirect 0xFF30)
2396+
* Register for FW Logging (indirect 0xFF31)
23962397
* Query FW Logging (indirect 0xFF32)
23972398
*/
23982399
struct ice_aqc_fw_log {
@@ -2401,6 +2402,7 @@ struct ice_aqc_fw_log {
24012402
#define ICE_AQC_FW_LOG_CONF_AQ_EN BIT(1)
24022403
#define ICE_AQC_FW_LOG_QUERY_REGISTERED BIT(2)
24032404
#define ICE_AQC_FW_LOG_CONF_SET_VALID BIT(3)
2405+
#define ICE_AQC_FW_LOG_AQ_REGISTER BIT(0)
24042406
#define ICE_AQC_FW_LOG_AQ_QUERY BIT(2)
24052407

24062408
u8 rsp_flag;
@@ -2722,6 +2724,7 @@ enum ice_adminq_opc {
27222724

27232725
/* FW Logging Commands */
27242726
ice_aqc_opc_fw_logs_config = 0xFF30,
2727+
ice_aqc_opc_fw_logs_register = 0xFF31,
27252728
ice_aqc_opc_fw_logs_query = 0xFF32,
27262729
};
27272730

drivers/net/ethernet/intel/ice/ice_debugfs.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,101 @@ static const struct file_operations ice_debugfs_nr_messages_fops = {
281281
.write = ice_debugfs_nr_messages_write,
282282
};
283283

284+
/**
285+
* ice_debugfs_enable_read - read from 'enable' file
286+
* @filp: the opened file
287+
* @buffer: where to write the data for the user to read
288+
* @count: the size of the user's buffer
289+
* @ppos: file position offset
290+
*/
291+
static ssize_t ice_debugfs_enable_read(struct file *filp,
292+
char __user *buffer, size_t count,
293+
loff_t *ppos)
294+
{
295+
struct ice_pf *pf = filp->private_data;
296+
struct ice_hw *hw = &pf->hw;
297+
char buff[32] = {};
298+
299+
snprintf(buff, sizeof(buff), "%u\n",
300+
(u16)(hw->fwlog_cfg.options &
301+
ICE_FWLOG_OPTION_IS_REGISTERED) >> 3);
302+
303+
return simple_read_from_buffer(buffer, count, ppos, buff, strlen(buff));
304+
}
305+
306+
/**
307+
* ice_debugfs_enable_write - write into 'enable' file
308+
* @filp: the opened file
309+
* @buf: where to find the user's data
310+
* @count: the length of the user's data
311+
* @ppos: file position offset
312+
*/
313+
static ssize_t
314+
ice_debugfs_enable_write(struct file *filp, const char __user *buf,
315+
size_t count, loff_t *ppos)
316+
{
317+
struct ice_pf *pf = filp->private_data;
318+
struct ice_hw *hw = &pf->hw;
319+
char user_val[8], *cmd_buf;
320+
bool enable;
321+
ssize_t ret;
322+
323+
/* don't allow partial writes or invalid input */
324+
if (*ppos != 0 || count > 2)
325+
return -EINVAL;
326+
327+
cmd_buf = memdup_user(buf, count);
328+
if (IS_ERR(cmd_buf))
329+
return PTR_ERR(cmd_buf);
330+
331+
ret = sscanf(cmd_buf, "%s", user_val);
332+
if (ret != 1)
333+
return -EINVAL;
334+
335+
ret = kstrtobool(user_val, &enable);
336+
if (ret)
337+
goto enable_write_error;
338+
339+
if (enable)
340+
hw->fwlog_cfg.options |= ICE_FWLOG_OPTION_ARQ_ENA;
341+
else
342+
hw->fwlog_cfg.options &= ~ICE_FWLOG_OPTION_ARQ_ENA;
343+
344+
ret = ice_fwlog_set(hw, &hw->fwlog_cfg);
345+
if (ret)
346+
goto enable_write_error;
347+
348+
if (enable)
349+
ret = ice_fwlog_register(hw);
350+
else
351+
ret = ice_fwlog_unregister(hw);
352+
353+
if (ret)
354+
goto enable_write_error;
355+
356+
/* if we get here, nothing went wrong; return count since we didn't
357+
* really write anything
358+
*/
359+
ret = (ssize_t)count;
360+
361+
enable_write_error:
362+
/* This function always consumes all of the written input, or produces
363+
* an error. Check and enforce this. Otherwise, the write operation
364+
* won't complete properly.
365+
*/
366+
if (WARN_ON(ret != (ssize_t)count && ret >= 0))
367+
ret = -EIO;
368+
369+
return ret;
370+
}
371+
372+
static const struct file_operations ice_debugfs_enable_fops = {
373+
.owner = THIS_MODULE,
374+
.open = simple_open,
375+
.read = ice_debugfs_enable_read,
376+
.write = ice_debugfs_enable_write,
377+
};
378+
284379
/**
285380
* ice_debugfs_fwlog_init - setup the debugfs directory
286381
* @pf: the ice that is starting up
@@ -332,6 +427,9 @@ void ice_debugfs_fwlog_init(struct ice_pf *pf)
332427

333428
pf->ice_debugfs_pf_fwlog_modules = fw_modules;
334429

430+
debugfs_create_file("enable", 0600, pf->ice_debugfs_pf_fwlog,
431+
pf, &ice_debugfs_enable_fops);
432+
335433
return;
336434

337435
err_create_module_files:

drivers/net/ethernet/intel/ice/ice_fwlog.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void ice_fwlog_deinit(struct ice_hw *hw)
6363
kfree(pf->ice_debugfs_pf_fwlog_modules);
6464

6565
pf->ice_debugfs_pf_fwlog_modules = NULL;
66+
67+
status = ice_fwlog_unregister(hw);
68+
if (status)
69+
dev_warn(ice_hw_to_dev(hw), "Unable to unregister FW logging, status: %d\n",
70+
status);
6671
}
6772

6873
/**
@@ -197,6 +202,8 @@ static int ice_aq_fwlog_get(struct ice_hw *hw, struct ice_fwlog_cfg *cfg)
197202
cfg->options |= ICE_FWLOG_OPTION_ARQ_ENA;
198203
if (cmd->cmd_flags & ICE_AQC_FW_LOG_CONF_UART_EN)
199204
cfg->options |= ICE_FWLOG_OPTION_UART_ENA;
205+
if (cmd->cmd_flags & ICE_AQC_FW_LOG_QUERY_REGISTERED)
206+
cfg->options |= ICE_FWLOG_OPTION_IS_REGISTERED;
200207

201208
fw_modules = (struct ice_aqc_fw_log_cfg_resp *)buf;
202209

@@ -226,6 +233,66 @@ int ice_fwlog_get(struct ice_hw *hw, struct ice_fwlog_cfg *cfg)
226233
return ice_aq_fwlog_get(hw, cfg);
227234
}
228235

236+
/**
237+
* ice_aq_fwlog_register - Register PF for firmware logging events (0xFF31)
238+
* @hw: pointer to the HW structure
239+
* @reg: true to register and false to unregister
240+
*/
241+
static int ice_aq_fwlog_register(struct ice_hw *hw, bool reg)
242+
{
243+
struct ice_aq_desc desc;
244+
245+
ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_fw_logs_register);
246+
247+
if (reg)
248+
desc.params.fw_log.cmd_flags = ICE_AQC_FW_LOG_AQ_REGISTER;
249+
250+
return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
251+
}
252+
253+
/**
254+
* ice_fwlog_register - Register the PF for firmware logging
255+
* @hw: pointer to the HW structure
256+
*
257+
* After this call the PF will start to receive firmware logging based on the
258+
* configuration set in ice_fwlog_set.
259+
*/
260+
int ice_fwlog_register(struct ice_hw *hw)
261+
{
262+
int status;
263+
264+
if (!ice_fwlog_supported(hw))
265+
return -EOPNOTSUPP;
266+
267+
status = ice_aq_fwlog_register(hw, true);
268+
if (status)
269+
ice_debug(hw, ICE_DBG_FW_LOG, "Failed to register for firmware logging events over ARQ\n");
270+
else
271+
hw->fwlog_cfg.options |= ICE_FWLOG_OPTION_IS_REGISTERED;
272+
273+
return status;
274+
}
275+
276+
/**
277+
* ice_fwlog_unregister - Unregister the PF from firmware logging
278+
* @hw: pointer to the HW structure
279+
*/
280+
int ice_fwlog_unregister(struct ice_hw *hw)
281+
{
282+
int status;
283+
284+
if (!ice_fwlog_supported(hw))
285+
return -EOPNOTSUPP;
286+
287+
status = ice_aq_fwlog_register(hw, false);
288+
if (status)
289+
ice_debug(hw, ICE_DBG_FW_LOG, "Failed to unregister from firmware logging events over ARQ\n");
290+
else
291+
hw->fwlog_cfg.options &= ~ICE_FWLOG_OPTION_IS_REGISTERED;
292+
293+
return status;
294+
}
295+
229296
/**
230297
* ice_fwlog_set_supported - Set if FW logging is supported by FW
231298
* @hw: pointer to the HW struct

drivers/net/ethernet/intel/ice/ice_fwlog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ int ice_fwlog_init(struct ice_hw *hw);
5353
void ice_fwlog_deinit(struct ice_hw *hw);
5454
int ice_fwlog_set(struct ice_hw *hw, struct ice_fwlog_cfg *cfg);
5555
int ice_fwlog_get(struct ice_hw *hw, struct ice_fwlog_cfg *cfg);
56+
int ice_fwlog_register(struct ice_hw *hw);
57+
int ice_fwlog_unregister(struct ice_hw *hw);
5658
#endif /* _ICE_FWLOG_H_ */

0 commit comments

Comments
 (0)