Skip to contentSkip to conversation

add v2 FW logging for ice driver

GIT PULL Superseded Tony Nguyen 3 participants 12 messages Dec 5, 2023 – Dec 11, 2023

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Tony Nguyen

author maintainer
#0 lore raw

Paul Stillwell says:

Firmware (FW) log support was added to the ice driver, but that version is no longer supported. There is a newer version of FW logging (v2) that adds more control knobs to get the exact data out of the FW for debugging.

The interface for FW logging is debugfs. This was chosen based on discussions here:
https://lore.kernel.org/netdev/[email protected]/ and
https://lore.kernel.org/netdev/[email protected]/

We talked about using devlink in a variety of ways, but none of those options made any sense for the way the FW reports data. We briefly talked about using ethtool, but that seemed to go by the wayside. Ultimately it seems like using debugfs is the way to go so re-implement the code to use that.

FW logging is across all the PFs on the device so restrict the commands to only PF0.

If the device supports FW logging then a directory named 'fwlog' will be created under '/sys/kernel/debug/ice/<pci_dev>'. A variety of files will be created to manage the behavior of logging. The following files will be created:
- modules/<module>
- nr_messages
- enable
- log_size
- data

where
modules/<module> is used to read/write the log level for a specific module

nr_messages is used to determine how many events should be in each message sent to the driver

enable is used to start/stop FW logging. This is a boolean value so only 1 or 0 are permissible values

log_size is used to configure the amount of memory the driver uses for log data

data is used to read/clear the log data

Generally there is a lot of data and dumping that data to syslog will result in a loss of data. This causes problems when decoding the data and the user doesn't know that data is missing until later. Instead of dumping the FW log output to syslog use debugfs. This ensures that all the data the driver has gets retrieved correctly.

The FW log data is binary data that the FW team decodes to determine what happened in firmware. The binary blob is sent to Intel for decoding.
---
v5:
- changed the log level configuration from a single file for all modules to a file per module.
- changed 'nr_buffs' to 'log_size' because users understand memory sizes better than a number of buffers
- changed 'resolution' to 'nr_messages' to better reflect what it represents
- updated documentation to reflect these changes
- updated documentation to indicate that FW logging must be disabled to clear the data. also clarified that any value written to the 'data' file will clear the data

v4: https://lore.kernel.org/netdev/[email protected]/
- removed CONFIG_DEBUG_FS wrapper around code because the debugfs calls handle this case already
- moved ice_debugfs_exit() call to remove unreachable code issue
- minor changes to documentation based on feedback

v3: https://lore.kernel.org/netdev/[email protected]/
- Adjust error path cleanup in ice_module_init() for unreachable code.

v2: https://lore.kernel.org/netdev/[email protected]/
- Rewrote code to use debugfs instead of devlink

v1: https://lore.kernel.org/netdev/[email protected]/

Previous discussion:
https://lore.kernel.org/netdev/[email protected]/

The following are changes since commit fb70136ded2e1ea3cde27d0393cfadab4240a141:
ipvlan: implement .parse_protocol hook function in ipvlan_header_ops
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue 100GbE

Paul M Stillwell Jr (5):
ice: remove FW logging code
ice: configure FW logging
ice: enable FW logging
ice: add ability to read and configure FW log data
ice: add documentation for FW logging

 .../device_drivers/ethernet/intel/ice.rst     | 141 +++
 drivers/net/ethernet/intel/ice/Makefile       |   4 +-
 drivers/net/ethernet/intel/ice/ice.h          |   9 +
 .../net/ethernet/intel/ice/ice_adminq_cmd.h   | 161 ++--
 drivers/net/ethernet/intel/ice/ice_common.c   | 219 +----
 drivers/net/ethernet/intel/ice/ice_common.h   |   1 -
 drivers/net/ethernet/intel/ice/ice_debugfs.c  | 848 ++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_fwlog.c    | 475 ++++++++++
 drivers/net/ethernet/intel/ice/ice_fwlog.h    |  80 ++
 drivers/net/ethernet/intel/ice/ice_main.c     |  51 +-
 drivers/net/ethernet/intel/ice/ice_type.h     |  23 +-
 11 files changed, 1697 insertions(+), 315 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_debugfs.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_fwlog.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_fwlog.h
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH v5 1/5 ice: remove FW logging code

From: Paul M Stillwell Jr <[email protected]>

The FW logging code doesn't work because there is no way to set cq_ena or uart_ena so remove the code. This code is the original (v1) way of FW logging so it should be replaced with the v2 way.

---
 .../net/ethernet/intel/ice/ice_adminq_cmd.h   |  78 -------
 drivers/net/ethernet/intel/ice/ice_common.c   | 217 ------------------
 drivers/net/ethernet/intel/ice/ice_common.h   |   1 -
 drivers/net/ethernet/intel/ice/ice_main.c     |   3 -
 drivers/net/ethernet/intel/ice/ice_type.h     |  20 --
 5 files changed, 319 deletions(-)
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +0 -78
index f77a3c70f262..3999cf9d1a3c 100644
@@ -2094,78 +2094,6 @@ struct ice_aqc_add_rdma_qset_data {
 	struct ice_aqc_add_tx_rdma_qset_entry rdma_qsets[];
 };
 
-/* Configure Firmware Logging Command (indirect 0xFF09)
- * Logging Information Read Response (indirect 0xFF10)
- * Note: The 0xFF10 command has no input parameters.
- */
-struct ice_aqc_fw_logging {
-	u8 log_ctrl;
-#define ICE_AQC_FW_LOG_AQ_EN		BIT(0)
-#define ICE_AQC_FW_LOG_UART_EN		BIT(1)
-	u8 rsvd0;
-	u8 log_ctrl_valid; /* Not used by 0xFF10 Response */
-#define ICE_AQC_FW_LOG_AQ_VALID		BIT(0)
-#define ICE_AQC_FW_LOG_UART_VALID	BIT(1)
-	u8 rsvd1[5];
-	__le32 addr_high;
-	__le32 addr_low;
-};
-
-enum ice_aqc_fw_logging_mod {
-	ICE_AQC_FW_LOG_ID_GENERAL = 0,
-	ICE_AQC_FW_LOG_ID_CTRL,
-	ICE_AQC_FW_LOG_ID_LINK,
-	ICE_AQC_FW_LOG_ID_LINK_TOPO,
-	ICE_AQC_FW_LOG_ID_DNL,
-	ICE_AQC_FW_LOG_ID_I2C,
-	ICE_AQC_FW_LOG_ID_SDP,
-	ICE_AQC_FW_LOG_ID_MDIO,
-	ICE_AQC_FW_LOG_ID_ADMINQ,
-	ICE_AQC_FW_LOG_ID_HDMA,
-	ICE_AQC_FW_LOG_ID_LLDP,
-	ICE_AQC_FW_LOG_ID_DCBX,
-	ICE_AQC_FW_LOG_ID_DCB,
-	ICE_AQC_FW_LOG_ID_NETPROXY,
-	ICE_AQC_FW_LOG_ID_NVM,
-	ICE_AQC_FW_LOG_ID_AUTH,
-	ICE_AQC_FW_LOG_ID_VPD,
-	ICE_AQC_FW_LOG_ID_IOSF,
-	ICE_AQC_FW_LOG_ID_PARSER,
-	ICE_AQC_FW_LOG_ID_SW,
-	ICE_AQC_FW_LOG_ID_SCHEDULER,
-	ICE_AQC_FW_LOG_ID_TXQ,
-	ICE_AQC_FW_LOG_ID_RSVD,
-	ICE_AQC_FW_LOG_ID_POST,
-	ICE_AQC_FW_LOG_ID_WATCHDOG,
-	ICE_AQC_FW_LOG_ID_TASK_DISPATCH,
-	ICE_AQC_FW_LOG_ID_MNG,
-	ICE_AQC_FW_LOG_ID_MAX,
-};
-
-/* Defines for both above FW logging command/response buffers */
-#define ICE_AQC_FW_LOG_ID_S		0
-#define ICE_AQC_FW_LOG_ID_M		(0xFFF << ICE_AQC_FW_LOG_ID_S)
-
-#define ICE_AQC_FW_LOG_CONF_SUCCESS	0	/* Used by response */
-#define ICE_AQC_FW_LOG_CONF_BAD_INDX	BIT(12)	/* Used by response */
-
-#define ICE_AQC_FW_LOG_EN_S		12
-#define ICE_AQC_FW_LOG_EN_M		(0xF << ICE_AQC_FW_LOG_EN_S)
-#define ICE_AQC_FW_LOG_INFO_EN		BIT(12)	/* Used by command */
-#define ICE_AQC_FW_LOG_INIT_EN		BIT(13)	/* Used by command */
-#define ICE_AQC_FW_LOG_FLOW_EN		BIT(14)	/* Used by command */
-#define ICE_AQC_FW_LOG_ERR_EN		BIT(15)	/* Used by command */
-
-/* Get/Clear FW Log (indirect 0xFF11) */
-struct ice_aqc_get_clear_fw_log {
-	u8 flags;
-#define ICE_AQC_FW_LOG_CLEAR		BIT(0)
-#define ICE_AQC_FW_LOG_MORE_DATA_AVAIL	BIT(1)
-	u8 rsvd1[7];
-	__le32 addr_high;
-	__le32 addr_low;
-};
-
 /* Download Package (indirect 0x0C40) */
 /* Also used for Update Package (indirect 0x0C41 and 0x0C42) */
 struct ice_aqc_download_pkg {
@@ -2507,8 +2435,6 @@ struct ice_aq_desc {
 		struct ice_aqc_add_rdma_qset add_rdma_qset;
 		struct ice_aqc_add_get_update_free_vsi vsi_cmd;
 		struct ice_aqc_add_update_free_vsi_resp add_update_free_vsi_res;
-		struct ice_aqc_fw_logging fw_logging;
-		struct ice_aqc_get_clear_fw_log get_clear_fw_log;
 		struct ice_aqc_download_pkg download_pkg;
 		struct ice_aqc_set_cgu_input_config set_cgu_input_config;
 		struct ice_aqc_get_cgu_input_config get_cgu_input_config;
@@ -2717,10 +2643,6 @@ enum ice_adminq_opc {
 
 	/* Standalone Commands/Events */
 	ice_aqc_opc_event_lan_overflow			= 0x1001,
-
-	/* debug commands */
-	ice_aqc_opc_fw_logging				= 0xFF09,
-	ice_aqc_opc_fw_logging_info			= 0xFF10,
 };
 
 #endif /* _ICE_ADMINQ_CMD_H_ */
drivers/net/ethernet/intel/ice/ice_common.c +0 -217

235 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_common.h +0 -1
index 5f7aa293d4ae..9696ed59d1a8 100644
@@ -199,7 +199,6 @@ ice_aq_cfg_lan_txq(struct ice_hw *hw, struct ice_aqc_cfg_txqs_buf *buf,
 		   struct ice_sq_cd *cd);
 int ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle);
 void ice_replay_post(struct ice_hw *hw);
-void ice_output_fw_log(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf);
 struct ice_q_ctx *
 ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle);
 int ice_sbq_rw_reg(struct ice_hw *hw, struct ice_sbq_msg_input *in);
drivers/net/ethernet/intel/ice/ice_main.c +0 -3
index a39c2d9bdafe..91e4123d292c 100644
@@ -1533,9 +1533,6 @@ static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
 
 			ice_vc_process_vf_msg(pf, &event, &data);
 			break;
-		case ice_aqc_opc_fw_logging:
-			ice_output_fw_log(hw, &event.desc, event.msg_buf);
-			break;
 		case ice_aqc_opc_lldp_set_mib_change:
 			ice_dcb_process_lldp_set_mib_change(pf, &event);
 			break;
drivers/net/ethernet/intel/ice/ice_type.h +0 -20
index 2be3955e249e..eb092d63b111 100644
@@ -737,24 +737,6 @@ struct ice_switch_info {
 	DECLARE_BITMAP(prof_res_bm[ICE_MAX_NUM_PROFILES], ICE_MAX_FV_WORDS);
 };
 
-/* FW logging configuration */
-struct ice_fw_log_evnt {
-	u8 cfg : 4;	/* New event enables to configure */
-	u8 cur : 4;	/* Current/active event enables */
-};
-
-struct ice_fw_log_cfg {
-	u8 cq_en : 1;    /* FW logging is enabled via the control queue */
-	u8 uart_en : 1;  /* FW logging is enabled via UART for all PFs */
-	u8 actv_evnts;   /* Cumulation of currently enabled log events */
-
-#define ICE_FW_LOG_EVNT_INFO	(ICE_AQC_FW_LOG_INFO_EN >> ICE_AQC_FW_LOG_EN_S)
-#define ICE_FW_LOG_EVNT_INIT	(ICE_AQC_FW_LOG_INIT_EN >> ICE_AQC_FW_LOG_EN_S)
-#define ICE_FW_LOG_EVNT_FLOW	(ICE_AQC_FW_LOG_FLOW_EN >> ICE_AQC_FW_LOG_EN_S)
-#define ICE_FW_LOG_EVNT_ERR	(ICE_AQC_FW_LOG_ERR_EN >> ICE_AQC_FW_LOG_EN_S)
-	struct ice_fw_log_evnt evnts[ICE_AQC_FW_LOG_ID_MAX];
-};
-
 /* Enum defining the different states of the mailbox snapshot in the
  * PF-VF mailbox overflow detection algorithm. The snapshot can be in
  * states:
@@ -896,8 +878,6 @@ struct ice_hw {
 	u8 fw_patch;		/* firmware patch version */
 	u32 fw_build;		/* firmware build number */
 
-	struct ice_fw_log_cfg fw_log;
-
 /* Device max aggregate bandwidths corresponding to the GL_PWR_MODE_CTL
  * register. Used for determining the ITR/INTRL granularity during
  * initialization.
Signature · 1 line
2.41.0
author maintainer
#2 lore raw

PATCH v5 2/5 ice: configure FW logging

In reply to Tony Nguyen

From: Paul M Stillwell Jr <[email protected]>

Users want the ability to debug FW issues by retrieving the FW logs from the E8xx devices. Use debugfs to allow the user to configure the log level and number of messages for FW logging.

If FW logging is supported on the E8xx then the file 'fwlog' will be created under the PCI device ID for the ice driver. If the file does not exist then either the E8xx doesn't support FW logging or debugfs is not enabled on the system.

One thing users want to do is control which events are reported. The user can read and write the 'fwlog/modules/<module name>' to get/set the log levels. Each module in the FW that supports logging has a file under 'fwlog/modules' that supports reading (to see what the current log level is) and writing (to change the log level).

The format to set the log levels for a module are:

  # echo <log level> > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/<module>

The supported log levels are:

      *	none
      *	error
      *	warning
      *	normal
      *	verbose

Each level includes the messages from the previous/lower level

The modules that are supported are:

      *	general
      *	ctrl
      *	link
      *	link_topo
      *	dnl
      *	i2c
      *	sdp
      *	mdio
      *	adminq
      *	hdma
      *	lldp
      *	dcbx
      *	dcb
      *	xlr
      *	nvm
      *	auth
      *	vpd
      *	iosf
      *	parser
      *	sw
      *	scheduler
      *	txq
      *	rsvd
      *	post
      *	watchdog
      *	task_dispatch
      *	mng
      *	synce
      *	health
      *	tsdrv
      *	pfreg
      *	mdlver
      *	all

The module 'all' is a special module which allows the user to read or write to all of the modules.

The following example command would set the DCB module to the 'normal' log level:

  # echo normal > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/dcb

If the user wants to set the DCB, Link, and the AdminQ modules to 'verbose' then the commands are:

  # echo verbose > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/dcb
  # echo verbose > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/link
  # echo verbose > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/adminq

If the user wants to set all modules to the 'warning' level then the command is:

  # echo warning > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/all

If the user wants to disable logging for a module then they can set the level to 'none'. An example setting the 'watchdog' module is:

  # echo none > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/watchdog

If the user wants to see what the log level is for a specific module then the command is:

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

This will return the log level for the DCB module. If the user wants to see the log level for all the modules then the command is:

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

Writing to the module file will update the configuration, but NOT enable the configuration (that is a separate command).

In addition to configuring the modules, the user can also configure the number of log messages (nr_messages) to include in a single Admin Receive Queue (ARQ) event.The range is 1-128 (1 means push every log message, 128 means push only when the max AQ command buffer is full). The suggested value is 10.

To see/change the resolution the user can read/write the 'fwlog/nr_messages' file. An example changing the value to 50 is

  # echo 50 > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/nr_messages

To see the current value of 'nr_messages' then the command is:

  # cat /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/nr_messages
---
 drivers/net/ethernet/intel/ice/Makefile       |   4 +-
 drivers/net/ethernet/intel/ice/ice.h          |   9 +
 .../net/ethernet/intel/ice/ice_adminq_cmd.h   |  80 +++
 drivers/net/ethernet/intel/ice/ice_common.c   |   6 +
 drivers/net/ethernet/intel/ice/ice_debugfs.c  | 482 ++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_fwlog.c    | 260 ++++++++++
 drivers/net/ethernet/intel/ice/ice_fwlog.h    |  56 ++
 drivers/net/ethernet/intel/ice/ice_main.c     |  21 +
 drivers/net/ethernet/intel/ice/ice_type.h     |   4 +
 9 files changed, 921 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_debugfs.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_fwlog.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_fwlog.h
drivers/net/ethernet/intel/ice/Makefile +3 -1
index b40b4179b9f4..cddd82d4ca0f 100644
@@ -34,7 +34,9 @@ ice-y := ice_main.o	\
 	 ice_lag.o	\
 	 ice_ethtool.o  \
 	 ice_repr.o	\
-	 ice_tc_lib.o
+	 ice_tc_lib.o	\
+	 ice_fwlog.o	\
+	 ice_debugfs.o
 ice-$(CONFIG_PCI_IOV) +=	\
 	ice_sriov.o		\
 	ice_virtchnl.o		\
drivers/net/ethernet/intel/ice/ice.h +9 -0
index 3ea33947b878..8ff4751b0c42 100644
@@ -570,6 +570,10 @@ struct ice_pf {
 	struct ice_vsi_stats **vsi_stats;
 	struct ice_sw *first_sw;	/* first switch created by firmware */
 	u16 eswitch_mode;		/* current mode of eswitch */
+	struct dentry *ice_debugfs_pf;
+	struct dentry *ice_debugfs_pf_fwlog;
+	/* keep track of all the dentires for FW log modules */
+	struct dentry **ice_debugfs_pf_fwlog_modules;
 	struct ice_vfs vfs;
 	DECLARE_BITMAP(features, ICE_F_MAX);
 	DECLARE_BITMAP(state, ICE_STATE_NBITS);
@@ -889,6 +893,11 @@ static inline bool ice_is_adq_active(struct ice_pf *pf)
 	return false;
 }
 
+void ice_debugfs_fwlog_init(struct ice_pf *pf);
+void ice_debugfs_init(void);
+void ice_debugfs_exit(void);
+void ice_pf_fwlog_update_module(struct ice_pf *pf, int log_level, int module);
+
 bool netif_is_ice(const struct net_device *dev);
 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi);
 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi);
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +80 -0

98 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_common.c +6 -0
index 6e4a0837f6d5..08a1f699a34f 100644
@@ -990,6 +990,11 @@ int ice_init_hw(struct ice_hw *hw)
 	if (status)
 		goto err_unroll_cqinit;
 
+	status = ice_fwlog_init(hw);
+	if (status)
+		ice_debug(hw, ICE_DBG_FW_LOG, "Error initializing FW logging: %d\n",
+			  status);
+
 	status = ice_clear_pf_cfg(hw);
 	if (status)
 		goto err_unroll_cqinit;
@@ -1139,6 +1144,7 @@ void ice_deinit_hw(struct ice_hw *hw)
 	ice_free_hw_tbls(hw);
 	mutex_destroy(&hw->tnl_lock);
 
+	ice_fwlog_deinit(hw);
 	ice_destroy_all_ctrlq(hw);
 
 	/* Clear VSI contexts if not already cleared */
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +482 -0

482 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_fwlog.c new file +260 -0

260 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_fwlog.h new file +56 -0

56 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_main.c +21 -0
index 91e4123d292c..245c026deb54 100644
@@ -4360,6 +4360,22 @@ static void ice_print_wake_reason(struct ice_pf *pf)
 	dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str);
 }
 
+/**
+ * ice_pf_fwlog_update_module - update 1 module
+ * @pf: pointer to the PF struct
+ * @log_level: log_level to use for the @module
+ * @module: module to update
+ */
+void ice_pf_fwlog_update_module(struct ice_pf *pf, int log_level, int module)
+{
+	struct ice_fwlog_module_entry *entries;
+	struct ice_hw *hw = &pf->hw;
+
+	entries = (struct ice_fwlog_module_entry *)hw->fwlog_cfg.module_entries;
+
+	entries[module].log_level = log_level;
+}
+
 /**
  * ice_register_netdev - register netdev
  * @vsi: pointer to the VSI struct
@@ -5207,6 +5223,8 @@ static void ice_remove(struct pci_dev *pdev)
 		msleep(100);
 	}
 
+	ice_debugfs_exit();
+
 	if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
 		set_bit(ICE_VF_RESETS_DISABLED, pf->state);
 		ice_free_vfs(pf);
@@ -5678,6 +5696,8 @@ static int __init ice_module_init(void)
 		goto err_dest_wq;
 	}
 
+	ice_debugfs_init();
+
 	status = pci_register_driver(&ice_driver);
 	if (status) {
 		pr_err("failed to register PCI driver, err %d\n", status);
@@ -5688,6 +5708,7 @@ static int __init ice_module_init(void)
 
 err_dest_lag_wq:
 	destroy_workqueue(ice_lag_wq);
+	ice_debugfs_exit();
 err_dest_wq:
 	destroy_workqueue(ice_wq);
 	return status;
drivers/net/ethernet/intel/ice/ice_type.h +4 -0
index eb092d63b111..82e4afb2eb10 100644
@@ -17,6 +17,7 @@
 #include "ice_protocol_type.h"
 #include "ice_sbq_cmd.h"
 #include "ice_vlan_mode.h"
+#include "ice_fwlog.h"
 
 static inline bool ice_is_tc_ena(unsigned long bitmap, u8 tc)
 {
@@ -878,6 +879,9 @@ struct ice_hw {
 	u8 fw_patch;		/* firmware patch version */
 	u32 fw_build;		/* firmware build number */
 
+	struct ice_fwlog_cfg fwlog_cfg;
+	bool fwlog_supported; /* does hardware support FW logging? */
+
 /* Device max aggregate bandwidths corresponding to the GL_PWR_MODE_CTL
  * register. Used for determining the ITR/INTRL granularity during
  * initialization.
Signature · 1 line
2.41.0
maintainer
#3 lore raw

Re: [PATCH net-next v5 2/5] ice: configure FW logging

Quoted 20 lines · On Tue, 5 Dec 2023 13:12:45 -0800 Tony Nguyen wrote:
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +20 -0
+/**
+ * ice_debugfs_parse_cmd_line - Parse the command line that was passed in
+ * @src: pointer to a buffer holding the command line
+ * @len: size of the buffer in bytes
+ * @argv: pointer to store the command line items
+ * @argc: pointer to store the number of command line items
+ */
+static ssize_t ice_debugfs_parse_cmd_line(const char __user *src, size_t len,
+					  char ***argv, int *argc)
+{
+	char *cmd_buf, *cmd_buf_tmp;
+
+	cmd_buf = memdup_user(src, len);
+	if (IS_ERR(cmd_buf))
+		return PTR_ERR(cmd_buf);
+	cmd_buf[len] = '\0';
+
+	/* the cmd_buf has a newline at the end of the command so
+	 * remove it
+	 */

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

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +10 -0
+	cmd_buf_tmp = strchr(cmd_buf, '\n');
+	if (cmd_buf_tmp) {
+		*cmd_buf_tmp = '\0';
+		len = (size_t)cmd_buf_tmp - (size_t)cmd_buf;
+	}
+
+	*argv = argv_split(GFP_KERNEL, cmd_buf, argc);
+	kfree(cmd_buf);
+	if (!*argv)
+		return -ENOMEM;

I haven't spotted a single caller wanting this full argc/argv parsing. Can we please not add this complexity until its really needed?

Quoted 19 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +19 -0
+/**
+ * ice_debugfs_module_read - read from 'module' 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_module_read(struct file *filp, char __user *buffer,
+				       size_t count, loff_t *ppos)
+{
+	struct dentry *dentry = filp->f_path.dentry;
+	struct ice_pf *pf = filp->private_data;
+	int status, module;
+	char *data = NULL;
+
+	/* don't allow commands if the FW doesn't support it */
+	if (!ice_fwlog_supported(&pf->hw))
+		return -EOPNOTSUPP;
+

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

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +10 -0
+	module = ice_find_module_by_dentry(pf, dentry);
+	if (module < 0) {
+		dev_info(ice_pf_to_dev(pf), "unknown module\n");
+		return -EINVAL;
+	}
+
+	data = vzalloc(ICE_AQ_MAX_BUF_LEN);
+	if (!data) {
+		dev_warn(ice_pf_to_dev(pf), "Unable to allocate memory for FW configuration!\n");
+		return -ENOMEM;

Can we use seq_print() here? It should simplify the reading quite a bit, not sure how well it works with files that can also be written, tho.

Quoted 11 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +11 -0
+/**
+ * ice_debugfs_fwlog_init - setup the debugfs directory
+ * @pf: the ice that is starting up
+ */
+void ice_debugfs_fwlog_init(struct ice_pf *pf)
+{
+	const char *name = pci_name(pf->pdev);
+	struct dentry *fw_modules_dir;
+	struct dentry **fw_modules;
+	int i;
+

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

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +10 -0
+	/* only support fw log commands on PF 0 */
+	if (pf->hw.bus.func)
+		return;
+
+	/* allocate space for this first because if it fails then we don't
+	 * need to unwind
+	 */
+	fw_modules = kcalloc(ICE_NR_FW_LOG_MODULES, sizeof(*fw_modules),
+			     GFP_KERNEL);
+

nit: no new line between call and error check

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

Quoted 2 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +2 -0
+	if (!fw_modules) {
+		pr_info("Unable to allocate space for modules\n");

no warnings on allocation failures, there will be a splat for GFP_KERNEL (checkpatch should catch this)

Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +4 -0
+		return;
+	}
+
+	pf->ice_debugfs_pf = debugfs_create_dir(name, ice_debugfs_root);

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

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +10 -0
+	if (IS_ERR(pf->ice_debugfs_pf)) {
+		pr_info("init of debugfs PCI dir failed\n");
+		kfree(fw_modules);
+		return;
+	}
+
+	pf->ice_debugfs_pf_fwlog = debugfs_create_dir("fwlog",
+						      pf->ice_debugfs_pf);
+	if (IS_ERR(pf->ice_debugfs_pf)) {
+		pr_info("init of debugfs fwlog dir failed\n");

If GregKH sees all the info message on debugfs failures he may complain, DebugFS is supposed to be completely optional.

Also - free fw_modules ?

You probably want to use goto on all error paths here

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

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_fwlog.c new file +12 -0
+/**
+ * ice_fwlog_get - Get the firmware logging settings
+ * @hw: pointer to the HW structure
+ * @cfg: config to populate based on current firmware logging settings
+ */
+int ice_fwlog_get(struct ice_hw *hw, struct ice_fwlog_cfg *cfg)
+{
+	if (!ice_fwlog_supported(hw))
+		return -EOPNOTSUPP;
+
+	if (!cfg)
+		return -EINVAL;

can't be, let's avoid defensive programming

drivers/net/ethernet/intel/ice/ice_main.c static void ice_print_wake_reason(struct ice_pf *pf) · line 4377

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_main.c +10 -0
+	return ice_aq_fwlog_get(hw, cfg);
 
 
+void ice_pf_fwlog_update_module(struct ice_pf *pf, int log_level, int module)
+{
+	struct ice_fwlog_module_entry *entries;
+	struct ice_hw *hw = &pf->hw;
+
+	entries = (struct ice_fwlog_module_entry *)hw->fwlog_cfg.module_entries;
+
+	entries[module].log_level = log_level;
+}

Isn't this just

	hw->fwlog_cfg.module_entries[module].log_level = log_level;

? The cast specifically look alarming but unnecessary.

#4 lore raw

Re: [PATCH net-next v5 2/5] ice: configure FW logging

Quoted 26 lines · Jakub Kicinski
Quoted 25 lines · On Tue, 5 Dec 2023 13:12:45 -0800 Tony Nguyen wrote:
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +25 -0
+/**
+ * ice_debugfs_parse_cmd_line - Parse the command line that was passed in
+ * @src: pointer to a buffer holding the command line
+ * @len: size of the buffer in bytes
+ * @argv: pointer to store the command line items
+ * @argc: pointer to store the number of command line items
+ */
+static ssize_t ice_debugfs_parse_cmd_line(const char __user *src, size_t len,
+					  char ***argv, int *argc)
+{
+	char *cmd_buf, *cmd_buf_tmp;
+
+	cmd_buf = memdup_user(src, len);
+	if (IS_ERR(cmd_buf))
+		return PTR_ERR(cmd_buf);
+	cmd_buf[len] = '\0';
+
+	/* the cmd_buf has a newline at the end of the command so
+	 * remove it
+	 */
+	cmd_buf_tmp = strchr(cmd_buf, '\n');
+	if (cmd_buf_tmp) {
+		*cmd_buf_tmp = '\0';
+		len = (size_t)cmd_buf_tmp - (size_t)cmd_buf;
+	}
Quoted 9 lines

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

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +5 -0
+
+	*argv = argv_split(GFP_KERNEL, cmd_buf, argc);
+	kfree(cmd_buf);
+	if (!*argv)
+		return -ENOMEM;

I haven't spotted a single caller wanting this full argc/argv parsing. Can we please not add this complexity until its really needed?

I can remove it, but I use it in all the _write functions. I use the argc to make sure I'm only getting one value to a write and I use argv[0] to deal with the value.

Honestly I'm not sure how valuable it is to check for a single argument, but I'm fairly certain our validation team will file a bug if they pass more than one argument and something happens :)

Examples of using argv are on lines 358 and 466 of ice_debugfs.c

I'm open to changing it, just not sure to what

Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +24 -0
+/**
+ * ice_debugfs_module_read - read from 'module' 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_module_read(struct file *filp, char __user *buffer,
+				       size_t count, loff_t *ppos)
+{
+	struct dentry *dentry = filp->f_path.dentry;
+	struct ice_pf *pf = filp->private_data;
+	int status, module;
+	char *data = NULL;
+
+	/* don't allow commands if the FW doesn't support it */
+	if (!ice_fwlog_supported(&pf->hw))
+		return -EOPNOTSUPP;
+
+	module = ice_find_module_by_dentry(pf, dentry);
+	if (module < 0) {
+		dev_info(ice_pf_to_dev(pf), "unknown module\n");
+		return -EINVAL;
+	}
Quoted 9 lines

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

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +5 -0
+
+	data = vzalloc(ICE_AQ_MAX_BUF_LEN);
+	if (!data) {
+		dev_warn(ice_pf_to_dev(pf), "Unable to allocate memory for FW configuration!\n");
+		return -ENOMEM;

Can we use seq_print() here? It should simplify the reading quite a bit, not sure how well it works with files that can also be written, tho.

I'm probably missing something here, but how do we get more simple than snprintf? I have a function (ice_fwlog_print_module_cfg) that handles whether the user has passed a single module ID or they want data on all the modules, but it all boils down to snprintf.

I could get rid of ice_fwlog_print_module_cfg() and replace it inline with the if/else code if that would be clearer, but I'm not sure seq_printf() is helpful because each file is a single quantum of information (with the exception of the file that represents all the modules). I created a special file to represent all the modules, but maybe it's more confusing and I should get rid of it and just make the users specify all of the modules in a script.

Would that be easier? Then there is no if/else it's just a single snprintf.

Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +15 -0
+/**
+ * ice_debugfs_fwlog_init - setup the debugfs directory
+ * @pf: the ice that is starting up
+ */
+void ice_debugfs_fwlog_init(struct ice_pf *pf)
+{
+	const char *name = pci_name(pf->pdev);
+	struct dentry *fw_modules_dir;
+	struct dentry **fw_modules;
+	int i;
+
+	/* only support fw log commands on PF 0 */
+	if (pf->hw.bus.func)
+		return;
+
Quoted 9 lines

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

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +6 -0
+	/* allocate space for this first because if it fails then we don't
+	 * need to unwind
+	 */
+	fw_modules = kcalloc(ICE_NR_FW_LOG_MODULES, sizeof(*fw_modules),
+			     GFP_KERNEL);
+

nit: no new line between call and error check

Will fix

Quoted 6 lines

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

Quoted 2 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +2 -0
+	if (!fw_modules) {
+		pr_info("Unable to allocate space for modules\n");

no warnings on allocation failures, there will be a splat for GFP_KERNEL (checkpatch should catch this)

OK

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +9 -0
+		return;
+	}
+
+	pf->ice_debugfs_pf = debugfs_create_dir(name, ice_debugfs_root);
+	if (IS_ERR(pf->ice_debugfs_pf)) {
+		pr_info("init of debugfs PCI dir failed\n");
+		kfree(fw_modules);
+		return;
+	}
Quoted 9 lines

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

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +5 -0
+
+	pf->ice_debugfs_pf_fwlog = debugfs_create_dir("fwlog",
+						      pf->ice_debugfs_pf);
+	if (IS_ERR(pf->ice_debugfs_pf)) {
+		pr_info("init of debugfs fwlog dir failed\n");

If GregKH sees all the info message on debugfs failures he may complain, DebugFS is supposed to be completely optional.

I'll remove them

Quoted 2 lines

Also - free fw_modules ?

This will get fixed by using goto in error paths as you suggested below

Quoted 16 lines

You probably want to use goto on all error paths here

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

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_fwlog.c new file +12 -0
+/**
+ * ice_fwlog_get - Get the firmware logging settings
+ * @hw: pointer to the HW structure
+ * @cfg: config to populate based on current firmware logging settings
+ */
+int ice_fwlog_get(struct ice_hw *hw, struct ice_fwlog_cfg *cfg)
+{
+	if (!ice_fwlog_supported(hw))
+		return -EOPNOTSUPP;
+
+	if (!cfg)
+		return -EINVAL;

can't be, let's avoid defensive programming

OK

Quoted 15 lines

drivers/net/ethernet/intel/ice/ice_main.c static void ice_print_wake_reason(struct ice_pf *pf) · line 4377

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_main.c +10 -0
+	return ice_aq_fwlog_get(hw, cfg);
 
 
+void ice_pf_fwlog_update_module(struct ice_pf *pf, int log_level, int module)
+{
+	struct ice_fwlog_module_entry *entries;
+	struct ice_hw *hw = &pf->hw;
+
+	entries = (struct ice_fwlog_module_entry *)hw->fwlog_cfg.module_entries;
+
+	entries[module].log_level = log_level;
+}

Isn't this just

Quoted 3 lines
	hw->fwlog_cfg.module_entries[module].log_level = log_level;

? The cast specifically look alarming but unnecessary.

Will change

maintainer
#5 lore raw

Re: [PATCH net-next v5 2/5] ice: configure FW logging

Quoted 37 lines · On Thu, 7 Dec 2023 16:28:27 -0800 Paul M Stillwell Jr wrote:
Quoted 26 lines · Jakub Kicinski
Quoted 25 lines · On Tue, 5 Dec 2023 13:12:45 -0800 Tony Nguyen wrote:
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +25 -0
+/**
+ * ice_debugfs_parse_cmd_line - Parse the command line that was passed in
+ * @src: pointer to a buffer holding the command line
+ * @len: size of the buffer in bytes
+ * @argv: pointer to store the command line items
+ * @argc: pointer to store the number of command line items
+ */
+static ssize_t ice_debugfs_parse_cmd_line(const char __user *src, size_t len,
+					  char ***argv, int *argc)
+{
+	char *cmd_buf, *cmd_buf_tmp;
+
+	cmd_buf = memdup_user(src, len);
+	if (IS_ERR(cmd_buf))
+		return PTR_ERR(cmd_buf);
+	cmd_buf[len] = '\0';
+
+	/* the cmd_buf has a newline at the end of the command so
+	 * remove it
+	 */
+	cmd_buf_tmp = strchr(cmd_buf, '\n');
+	if (cmd_buf_tmp) {
+		*cmd_buf_tmp = '\0';
+		len = (size_t)cmd_buf_tmp - (size_t)cmd_buf;
+	}
Quoted 9 lines

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

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +5 -0
+
+	*argv = argv_split(GFP_KERNEL, cmd_buf, argc);
+	kfree(cmd_buf);
+	if (!*argv)
+		return -ENOMEM;  

I haven't spotted a single caller wanting this full argc/argv parsing. Can we please not add this complexity until its really needed?

Quoted 7 lines

I can remove it, but I use it in all the _write functions. I use the argc to make sure I'm only getting one value to a write and I use argv[0] to deal with the value.

Honestly I'm not sure how valuable it is to check for a single argument, but I'm fairly certain our validation team will file a bug if they pass more than one argument and something happens :)

Just eyeballing the code - you'd still accept

echo -e 'val1\0val2' > file

right? :) Perhaps less like that validation would come up with that but even the standard debugfs implementations don't seem to care too much (example of bool file in netdevsim):

# cat bpf_bind_accept
Y
# echo 'nbla' > bpf_bind_accept
# echo $?
0
# cat bpf_bind_accept
N
Quoted 38 lines

Examples of using argv are on lines 358 and 466 of ice_debugfs.c

I'm open to changing it, just not sure to what

Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +24 -0
+/**
+ * ice_debugfs_module_read - read from 'module' 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_module_read(struct file *filp, char __user *buffer,
+				       size_t count, loff_t *ppos)
+{
+	struct dentry *dentry = filp->f_path.dentry;
+	struct ice_pf *pf = filp->private_data;
+	int status, module;
+	char *data = NULL;
+
+	/* don't allow commands if the FW doesn't support it */
+	if (!ice_fwlog_supported(&pf->hw))
+		return -EOPNOTSUPP;
+
+	module = ice_find_module_by_dentry(pf, dentry);
+	if (module < 0) {
+		dev_info(ice_pf_to_dev(pf), "unknown module\n");
+		return -EINVAL;
+	}
Quoted 9 lines

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

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +5 -0
+
+	data = vzalloc(ICE_AQ_MAX_BUF_LEN);
+	if (!data) {
+		dev_warn(ice_pf_to_dev(pf), "Unable to allocate memory for FW configuration!\n");
+		return -ENOMEM;  

Can we use seq_print() here? It should simplify the reading quite a bit, not sure how well it works with files that can also be written, tho.

Quoted 4 lines

I'm probably missing something here, but how do we get more simple than snprintf? I have a function (ice_fwlog_print_module_cfg) that handles whether the user has passed a single module ID or they want data on all the modules, but it all boils down to snprintf.

You need to vzalloc() and worry about it overflowing.

Quoted 9 lines

I could get rid of ice_fwlog_print_module_cfg() and replace it inline with the if/else code if that would be clearer, but I'm not sure seq_printf() is helpful because each file is a single quantum of information (with the exception of the file that represents all the modules). I created a special file to represent all the modules, but maybe it's more confusing and I should get rid of it and just make the users specify all of the modules in a script.

Would that be easier? Then there is no if/else it's just a single snprintf.

The value of seq_print() here is the fact it will handle the memory allocation and copying to user space for you. Ignore the "seq" in the name.

#6 lore raw

Re: [PATCH net-next v5 2/5] ice: configure FW logging

Quoted 54 lines · Jakub Kicinski
Quoted 37 lines · On Thu, 7 Dec 2023 16:28:27 -0800 Paul M Stillwell Jr wrote:
Quoted 26 lines · Jakub Kicinski
Quoted 25 lines · On Tue, 5 Dec 2023 13:12:45 -0800 Tony Nguyen wrote:
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +25 -0
+/**
+ * ice_debugfs_parse_cmd_line - Parse the command line that was passed in
+ * @src: pointer to a buffer holding the command line
+ * @len: size of the buffer in bytes
+ * @argv: pointer to store the command line items
+ * @argc: pointer to store the number of command line items
+ */
+static ssize_t ice_debugfs_parse_cmd_line(const char __user *src, size_t len,
+					  char ***argv, int *argc)
+{
+	char *cmd_buf, *cmd_buf_tmp;
+
+	cmd_buf = memdup_user(src, len);
+	if (IS_ERR(cmd_buf))
+		return PTR_ERR(cmd_buf);
+	cmd_buf[len] = '\0';
+
+	/* the cmd_buf has a newline at the end of the command so
+	 * remove it
+	 */
+	cmd_buf_tmp = strchr(cmd_buf, '\n');
+	if (cmd_buf_tmp) {
+		*cmd_buf_tmp = '\0';
+		len = (size_t)cmd_buf_tmp - (size_t)cmd_buf;
+	}
Quoted 9 lines

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

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +5 -0
+
+	*argv = argv_split(GFP_KERNEL, cmd_buf, argc);
+	kfree(cmd_buf);
+	if (!*argv)
+		return -ENOMEM;

I haven't spotted a single caller wanting this full argc/argv parsing. Can we please not add this complexity until its really needed?

Quoted 7 lines

I can remove it, but I use it in all the _write functions. I use the argc to make sure I'm only getting one value to a write and I use argv[0] to deal with the value.

Honestly I'm not sure how valuable it is to check for a single argument, but I'm fairly certain our validation team will file a bug if they pass more than one argument and something happens :)

Just eyeballing the code - you'd still accept

   echo -e 'val1\0val2' > file

right? :) Perhaps less like that validation would come up with that but even the standard debugfs implementations don't seem to care too much (example of bool file in netdevsim):

Quoted 8 lines
# cat bpf_bind_accept
Y
# echo 'nbla' > bpf_bind_accept
# echo $?
0
# cat bpf_bind_accept
N

Good point, changed

Quoted 53 lines
Quoted 38 lines

Examples of using argv are on lines 358 and 466 of ice_debugfs.c

I'm open to changing it, just not sure to what

Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +24 -0
+/**
+ * ice_debugfs_module_read - read from 'module' 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_module_read(struct file *filp, char __user *buffer,
+				       size_t count, loff_t *ppos)
+{
+	struct dentry *dentry = filp->f_path.dentry;
+	struct ice_pf *pf = filp->private_data;
+	int status, module;
+	char *data = NULL;
+
+	/* don't allow commands if the FW doesn't support it */
+	if (!ice_fwlog_supported(&pf->hw))
+		return -EOPNOTSUPP;
+
+	module = ice_find_module_by_dentry(pf, dentry);
+	if (module < 0) {
+		dev_info(ice_pf_to_dev(pf), "unknown module\n");
+		return -EINVAL;
+	}
Quoted 9 lines

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

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_debugfs.c new file +5 -0
+
+	data = vzalloc(ICE_AQ_MAX_BUF_LEN);
+	if (!data) {
+		dev_warn(ice_pf_to_dev(pf), "Unable to allocate memory for FW configuration!\n");
+		return -ENOMEM;

Can we use seq_print() here? It should simplify the reading quite a bit, not sure how well it works with files that can also be written, tho.

Quoted 4 lines

I'm probably missing something here, but how do we get more simple than snprintf? I have a function (ice_fwlog_print_module_cfg) that handles whether the user has passed a single module ID or they want data on all the modules, but it all boils down to snprintf.

You need to vzalloc() and worry about it overflowing.

Quoted 8 lines

I could get rid of ice_fwlog_print_module_cfg() and replace it inline with the if/else code if that would be clearer, but I'm not sure seq_printf() is helpful because each file is a single quantum of information (with the exception of the file that represents all the modules). I created a special file to represent all the modules, but maybe it's more confusing and I should get rid of it and just make the users specify all of the modules in a script.

Quoted 5 lines
Quoted 1 line

Would that be easier? Then there is no if/else it's just a single snprintf.

The value of seq_print() here is the fact it will handle the memory allocation and copying to user space for you. Ignore the "seq" in the name.

Ah, I see your point now, thanks for the clarification. I've made this change to seq_printf() for printing the module info.

This brings up the question of whether I should use seq_printf() for all the other _read fucntions. It feels like a lot of extra code to do it for the other _read functions because they output so little info and we control the output so it seems to be overkill to use seq_printf() for those. What do you think?

maintainer
#7 lore raw

Re: [PATCH net-next v5 2/5] ice: configure FW logging

Quoted 5 lines · On Sat, 9 Dec 2023 16:09:40 -0800 Paul M Stillwell Jr wrote:

This brings up the question of whether I should use seq_printf() for all the other _read fucntions. It feels like a lot of extra code to do it for the other _read functions because they output so little info and we control the output so it seems to be overkill to use seq_printf() for those. What do you think?

My rule of thumb would be to use seq_printf() if you have to allocate a buffer on the heap for the output. If you can output directly to user space or the output is small enough to fit in an on-stack buffer - no need for seq_printf(). But YMMV.

#8 lore raw

Re: [PATCH net-next v5 2/5] ice: configure FW logging

Quoted 11 lines · Jakub Kicinski
Quoted 5 lines · On Sat, 9 Dec 2023 16:09:40 -0800 Paul M Stillwell Jr wrote:

This brings up the question of whether I should use seq_printf() for all the other _read fucntions. It feels like a lot of extra code to do it for the other _read functions because they output so little info and we control the output so it seems to be overkill to use seq_printf() for those. What do you think?

My rule of thumb would be to use seq_printf() if you have to allocate a buffer on the heap for the output. If you can output directly to user space or the output is small enough to fit in an on-stack buffer - no need for seq_printf(). But YMMV.

OK, thanks for the feedback!

author maintainer
#9 lore raw

PATCH v5 3/5 ice: enable FW logging

In reply to Tony Nguyen

From: Paul M Stillwell Jr <[email protected]>

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
---
 .../net/ethernet/intel/ice/ice_adminq_cmd.h   |   3 +
 drivers/net/ethernet/intel/ice/ice_debugfs.c  | 117 ++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_fwlog.c    |  67 ++++++++++
 drivers/net/ethernet/intel/ice/ice_fwlog.h    |   2 +
 4 files changed, 189 insertions(+)
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +3 -0
index 17e5544702f5..b5d9c4e38809 100644
@@ -2393,6 +2393,7 @@ enum ice_aqc_fw_logging_mod {
 };
 
 /* Set FW Logging configuration (indirect 0xFF30)
+ * Register for FW Logging (indirect 0xFF31)
  * Query FW Logging (indirect 0xFF32)
  */
 struct ice_aqc_fw_log {
@@ -2401,6 +2402,7 @@ struct ice_aqc_fw_log {
 #define ICE_AQC_FW_LOG_CONF_AQ_EN	BIT(1)
 #define ICE_AQC_FW_LOG_QUERY_REGISTERED	BIT(2)
 #define ICE_AQC_FW_LOG_CONF_SET_VALID	BIT(3)
+#define ICE_AQC_FW_LOG_AQ_REGISTER	BIT(0)
 #define ICE_AQC_FW_LOG_AQ_QUERY		BIT(2)
 
 	u8 rsp_flag;
@@ -2722,6 +2724,7 @@ enum ice_adminq_opc {
 
 	/* FW Logging Commands */
 	ice_aqc_opc_fw_logs_config			= 0xFF30,
+	ice_aqc_opc_fw_logs_register			= 0xFF31,
 	ice_aqc_opc_fw_logs_query			= 0xFF32,
 };
 
drivers/net/ethernet/intel/ice/ice_debugfs.c +117 -0

129 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_fwlog.c +67 -0

85 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_fwlog.h +2 -0
index 8e68ee02713b..45865558425d 100644
@@ -53,4 +53,6 @@ int ice_fwlog_init(struct ice_hw *hw);
 void ice_fwlog_deinit(struct ice_hw *hw);
 int ice_fwlog_set(struct ice_hw *hw, struct ice_fwlog_cfg *cfg);
 int ice_fwlog_get(struct ice_hw *hw, struct ice_fwlog_cfg *cfg);
+int ice_fwlog_register(struct ice_hw *hw);
+int ice_fwlog_unregister(struct ice_hw *hw);
 #endif /* _ICE_FWLOG_H_ */
Signature · 1 line
2.41.0
author maintainer
#10 lore raw

PATCH v5 4/5 ice: add ability to read and configure FW log data

In reply to Tony Nguyen

From: Paul M Stillwell Jr <[email protected]>

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
---
 .../net/ethernet/intel/ice/ice_adminq_cmd.h   |   2 +
 drivers/net/ethernet/intel/ice/ice_debugfs.c  | 249 ++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_fwlog.c    | 150 ++++++++++-
 drivers/net/ethernet/intel/ice/ice_fwlog.h    |  22 ++
 drivers/net/ethernet/intel/ice/ice_main.c     |  29 ++
 drivers/net/ethernet/intel/ice/ice_type.h     |   1 +
 6 files changed, 452 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +2 -0
index b5d9c4e38809..ef404bca5391 100644
@@ -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;
@@ -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_ */
drivers/net/ethernet/intel/ice/ice_debugfs.c +249 -0

267 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_fwlog.c +149 -1

181 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_fwlog.h +22 -0
index 45865558425d..65d9a1cbfa1c 100644
@@ -47,12 +47,34 @@ struct ice_fwlog_cfg {
 	u16 log_resolution;
 };
 
+struct ice_fwlog_data {
+	u16 data_size;
+	u8 *data;
+};
+
+struct ice_fwlog_ring {
+	struct ice_fwlog_data *rings;
+	u16 index;
+	u16 size;
+	u16 head;
+	u16 tail;
+};
+
+#define ICE_FWLOG_RING_SIZE_INDEX_DFLT 3
+#define ICE_FWLOG_RING_SIZE_DFLT 256
+#define ICE_FWLOG_RING_SIZE_MAX 512
+
+bool ice_fwlog_ring_full(struct ice_fwlog_ring *rings);
+bool ice_fwlog_ring_empty(struct ice_fwlog_ring *rings);
+void ice_fwlog_ring_increment(u16 *item, u16 size);
 void ice_fwlog_set_supported(struct ice_hw *hw);
 bool ice_fwlog_supported(struct ice_hw *hw);
 int ice_fwlog_init(struct ice_hw *hw);
 void ice_fwlog_deinit(struct ice_hw *hw);
+void ice_fwlog_deinit(struct ice_hw *hw);
 int ice_fwlog_set(struct ice_hw *hw, struct ice_fwlog_cfg *cfg);
 int ice_fwlog_get(struct ice_hw *hw, struct ice_fwlog_cfg *cfg);
 int ice_fwlog_register(struct ice_hw *hw);
 int ice_fwlog_unregister(struct ice_hw *hw);
+void ice_fwlog_realloc_rings(struct ice_hw *hw, int index);
 #endif /* _ICE_FWLOG_H_ */
drivers/net/ethernet/intel/ice/ice_main.c +29 -0
index 245c026deb54..54034ac7ebb3 100644
@@ -1252,6 +1252,32 @@ ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
 	return status;
 }
 
+/**
+ * ice_get_fwlog_data - copy the FW log data from ARQ event
+ * @pf: PF that the FW log event is associated with
+ * @event: event structure containing FW log data
+ */
+static void
+ice_get_fwlog_data(struct ice_pf *pf, struct ice_rq_event_info *event)
+{
+	struct ice_fwlog_data *fwlog;
+	struct ice_hw *hw = &pf->hw;
+
+	fwlog = &hw->fwlog_ring.rings[hw->fwlog_ring.tail];
+
+	memset(fwlog->data, 0, PAGE_SIZE);
+	fwlog->data_size = le16_to_cpu(event->desc.datalen);
+
+	memcpy(fwlog->data, event->msg_buf, fwlog->data_size);
+	ice_fwlog_ring_increment(&hw->fwlog_ring.tail, hw->fwlog_ring.size);
+
+	if (ice_fwlog_ring_full(&hw->fwlog_ring)) {
+		/* the rings are full so bump the head to create room */
+		ice_fwlog_ring_increment(&hw->fwlog_ring.head,
+					 hw->fwlog_ring.size);
+	}
+}
+
 /**
  * ice_aq_prep_for_event - Prepare to wait for an AdminQ event from firmware
  * @pf: pointer to the PF private structure
@@ -1533,6 +1559,9 @@ static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
 
 			ice_vc_process_vf_msg(pf, &event, &data);
 			break;
+		case ice_aqc_opc_fw_logs_event:
+			ice_get_fwlog_data(pf, &event);
+			break;
 		case ice_aqc_opc_lldp_set_mib_change:
 			ice_dcb_process_lldp_set_mib_change(pf, &event);
 			break;
drivers/net/ethernet/intel/ice/ice_type.h +1 -0
index 82e4afb2eb10..672baac2fba6 100644
@@ -881,6 +881,7 @@ struct ice_hw {
 
 	struct ice_fwlog_cfg fwlog_cfg;
 	bool fwlog_supported; /* does hardware support FW logging? */
+	struct ice_fwlog_ring fwlog_ring;
 
 /* Device max aggregate bandwidths corresponding to the GL_PWR_MODE_CTL
  * register. Used for determining the ITR/INTRL granularity during
Signature · 1 line
2.41.0
author maintainer
#11 lore raw

PATCH v5 5/5 ice: add documentation for FW logging

In reply to Tony Nguyen

From: Paul M Stillwell Jr <[email protected]>

Add documentation for FW logging in Documentation/networking/device_drivers/ethernet/intel/ice.rst

---
 .../device_drivers/ethernet/intel/ice.rst     | 141 ++++++++++++++++++
 1 file changed, 141 insertions(+)
Documentation/networking/device_drivers/ethernet/intel/ice.rst +141 -0
index e4d065c55ea8..5038e54586af 100644
@@ -895,6 +895,147 @@ driver writes raw bytes by the GNSS object to the receiver through i2c. Please
 refer to the hardware GNSS module documentation for configuration details.
 
 
+Firmware (FW) logging
+---------------------
+The driver supports FW logging via the debugfs interface on PF 0 only. The FW
+running on the NIC must support FW logging; if the FW doesn't support FW logging
+the 'fwlog' file will not get created in the ice debugfs directory.
+
+Module configuration
+~~~~~~~~~~~~~~~~~~~~
+Firmware logging is configured on a per module basis. Each module can be set to
+a value independent of the other modules (unless the module 'all' is specified).
+The modules will be instantiated under the 'fwlog/modules' directory.
+
+The user can set the log level for a module by writing to the module file like
+this::
+
+  # echo <log_level> > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/<module>
+
+where
+
+* log_level is a name as described below. Each level includes the
+  messages from the previous/lower level
+
+      *	none
+      *	error
+      *	warning
+      *	normal
+      *	verbose
+
+* module is a name that represents the module to receive events for. The
+  module names are
+
+      *	general
+      *	ctrl
+      *	link
+      *	link_topo
+      *	dnl
+      *	i2c
+      *	sdp
+      *	mdio
+      *	adminq
+      *	hdma
+      *	lldp
+      *	dcbx
+      *	dcb
+      *	xlr
+      *	nvm
+      *	auth
+      *	vpd
+      *	iosf
+      *	parser
+      *	sw
+      *	scheduler
+      *	txq
+      *	rsvd
+      *	post
+      *	watchdog
+      *	task_dispatch
+      *	mng
+      *	synce
+      *	health
+      *	tsdrv
+      *	pfreg
+      *	mdlver
+      *	all
+
+The name 'all' is special and allows the user to set all of the modules to the
+specified log_level or to read the log_level of all of the modules.
+
+Example usage to configure the modules
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+To set a single module to 'verbose'::
+
+  # echo verbose > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/link
+
+To set multiple modules then issue the command multiple times::
+
+  # echo verbose > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/link
+  # echo warning > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/ctrl
+  # echo none > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/dcb
+
+To set all the modules to the same value::
+
+  # echo normal > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/all
+
+To read the log_level of a specific module (e.g. module 'general')::
+
+  # cat /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/general
+
+To read the log_level of all the modules::
+
+  # cat /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/modules/all
+
+Enabling FW log
+~~~~~~~~~~~~~~~
+Configuring the modules indicates to the FW that the configured modules should
+generate events that the driver is interested in, but it **does not** send the
+events to the driver until the enable message is sent to the FW. To do this
+the user can write a 1 (enable) or 0 (disable) to 'fwlog/enable'. An example
+is::
+
+  # echo 1 > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/enable
+
+Retrieving FW log data
+~~~~~~~~~~~~~~~~~~~~~~
+The FW log data can be retrieved by reading from 'fwlog/data'. The user can
+write any value to 'fwlog/data' to clear the data. The data can only be cleared
+when FW logging is disabled. The FW log data is a binary file that is sent to
+Intel and used to help debug user issues.
+
+An example to read the data is::
+
+  # cat /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/data > fwlog.bin
+
+An example to clear the data is::
+
+  # echo 0 > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/data
+
+Changing how often the log events are sent to the driver
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The driver receives FW log data from the Admin Receive Queue (ARQ). The
+frequency that the FW sends the ARQ events can be configured by writing to
+'fwlog/nr_messages'. The range is 1-128 (1 means push every log message, 128
+means push only when the max AQ command buffer is full). The suggested value is
+10. The user can see what the value is configured to by reading
+'fwlog/nr_messages'. An example to set the value is::
+
+  # echo 50 > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/nr_messages
+
+Configuring the amount of memory used to store FW log data
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The driver stores FW log data within the driver. The default size of the memory
+used to store the data is 1MB. Some use cases may require more or less data so
+the user can change the amount of memory that is allocated for FW log data.
+To change the amount of memory then write to 'fwlog/log_size'. The value must be
+one of: 128K, 256K, 512K, 1M, or 2M. FW logging must be disabled to change the
+value. An example of changing the value is::
+
+  # echo 128K > /sys/kernel/debug/ice/0000\:18\:00.0/fwlog/log_size
+
+
 Performance Optimization
 ========================
 Driver defaults are meant to fit a wide variety of workloads, but if further
Signature · 1 line
2.41.0