From: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
To: luciano.coelho@intel.com, kvalo@codeaurora.org,
linux-wireless@vger.kernel.org
Cc: egrumbach@gmail.com, Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Subject: [PATCH v5 3/7] iwlwifi: mei: add debugfs hooks
Date: Tue, 27 Jul 2021 09:51:30 +0300 [thread overview]
Message-ID: <20210727065134.3902-3-emmanuel.grumbach@intel.com> (raw)
In-Reply-To: <20210727065134.3902-1-emmanuel.grumbach@intel.com>
Add three debugfs hooks:
* status: Check if we have a connection with the CSME
firwmare. This hook is a read only.
* req_ownership: Send a SAP command to request ownership. This
flow should be triggered by iwlwifi (from user space through
vendor commands really), but being able to trigger an ownership
request from debugfs allows us to request ownership without
connecting afterwards. This is an "error" flow that the CSME
firmware is designed to handle this way:
+ Grant ownership since the host asked for it
+ Wait 3 seconds to let the host connect
+ If the host didn't connect, take the device back (forcefully).
+ Don't grant any new ownership request in the following 30
seconds.
This debugfs hook allows us to test this flow.
* send_start_message: Restart the communication with the CSME
firmware from the very beginning. At the very beginning (upon
iwlwifi start), iwlmei send a special message: SAP_ME_MSG_START.
This hook allows to send it again and this will retrigger the
whole flow. It is important to test this restart in the middle
of normal operation since it can happen (in case the CSME
firmware decided to reset for example).
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
---
drivers/net/wireless/intel/iwlwifi/mei/main.c | 85 ++++++++++++++++++-
1 file changed, 83 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/intel/iwlwifi/mei/main.c b/drivers/net/wireless/intel/iwlwifi/mei/main.c
index d0ddb707d4da..101ff7533af3 100644
--- a/drivers/net/wireless/intel/iwlwifi/mei/main.c
+++ b/drivers/net/wireless/intel/iwlwifi/mei/main.c
@@ -10,6 +10,7 @@
#include <linux/moduleparam.h>
#include <linux/mei_cl_bus.h>
#include <linux/rcupdate.h>
+#include <linux/debugfs.h>
#include <linux/skbuff.h>
#include <linux/wait.h>
#include <linux/slab.h>
@@ -144,6 +145,7 @@ struct iwl_mei_filters {
* accessed without the mutex.
* @sap_seq_no: the sequence number for the SAP messages
* @seq_no: the sequence number for the SAP messages
+ * @dbgfs_dir: the debugfs dir entry
*/
struct iwl_mei {
wait_queue_head_t get_nvm_wq;
@@ -162,6 +164,8 @@ struct iwl_mei {
atomic_t sap_seq_no;
atomic_t seq_no;
+
+ struct dentry *dbgfs_dir;
};
/**
@@ -1693,6 +1697,78 @@ void iwl_mei_unregister_complete(void)
}
EXPORT_SYMBOL_GPL(iwl_mei_unregister_complete);
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+static ssize_t
+iwl_mei_dbgfs_send_start_message_write(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ int ret;
+
+ mutex_lock(&iwl_mei_mutex);
+
+ if (!iwl_mei_global_cldev) {
+ ret = -ENODEV;
+ goto out;
+ }
+
+ ret = iwl_mei_send_start(iwl_mei_global_cldev);
+
+out:
+ mutex_unlock(&iwl_mei_mutex);
+ return ret ?: count;
+}
+
+static const struct file_operations iwl_mei_dbgfs_send_start_message_ops = {
+ .write = iwl_mei_dbgfs_send_start_message_write,
+ .open = simple_open,
+ .llseek = default_llseek,
+};
+
+static ssize_t iwl_mei_dbgfs_req_ownership_write(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ iwl_mei_get_ownership();
+
+ return count;
+}
+
+static const struct file_operations iwl_mei_dbgfs_req_ownership_ops = {
+ .write = iwl_mei_dbgfs_req_ownership_write,
+ .open = simple_open,
+ .llseek = default_llseek,
+};
+
+static void iwl_mei_dbgfs_register(struct iwl_mei *mei)
+{
+ mei->dbgfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
+
+ if (!mei->dbgfs_dir)
+ return;
+
+ debugfs_create_ulong("status", S_IRUSR,
+ mei->dbgfs_dir, &iwl_mei_status);
+ debugfs_create_file("send_start_message", S_IWUSR, mei->dbgfs_dir,
+ mei, &iwl_mei_dbgfs_send_start_message_ops);
+ debugfs_create_file("req_ownserhip", S_IWUSR, mei->dbgfs_dir,
+ mei, &iwl_mei_dbgfs_req_ownership_ops);
+}
+
+static void iwl_mei_dbgfs_unregister(struct iwl_mei *mei)
+{
+ debugfs_remove_recursive(mei->dbgfs_dir);
+ mei->dbgfs_dir = NULL;
+}
+
+#else
+
+static void iwl_mei_dbgfs_register(struct iwl_mei *mei) {}
+static void iwl_mei_dbgfs_unregister(struct iwl_mei *mei) {}
+
+#endif /* CONFIG_DEBUG_FS */
+
/**
* iwl_mei_probe - the probe function called by the mei bus enumeration
*
@@ -1731,6 +1807,8 @@ static int iwl_mei_probe(struct mei_cl_device *cldev,
if (ret)
goto free_shared_mem;
+ iwl_mei_dbgfs_register(mei);
+
/*
* We now have a Rx function in place, start the SAP procotol
* we expect to get the SAP_ME_MSG_START_OK response later on.
@@ -1739,14 +1817,15 @@ static int iwl_mei_probe(struct mei_cl_device *cldev,
ret = iwl_mei_send_start(cldev);
mutex_unlock(&iwl_mei_mutex);
if (ret)
- goto disable;
+ goto debugfs_unregister;
/* must be last */
iwl_mei_global_cldev = cldev;
return 0;
-disable:
+debugfs_unregister:
+ iwl_mei_dbgfs_unregister(mei);
mei_cldev_disable(cldev);
free_shared_mem:
iwl_mei_free_shared_mem(cldev);
@@ -1857,6 +1936,8 @@ static void iwl_mei_remove(struct mei_cl_device *cldev)
iwl_mei_free_shared_mem(cldev);
+ iwl_mei_dbgfs_unregister(mei);
+
mei_cldev_set_drvdata(cldev, NULL);
kfree(mei->nvm);
--
2.25.1
next prev parent reply other threads:[~2021-07-27 6:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 6:51 [PATCH v5 1/7] mei: bus: add client dma interface Emmanuel Grumbach
2021-07-27 6:51 ` [PATCH v5 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME Emmanuel Grumbach
2021-07-27 6:51 ` Emmanuel Grumbach [this message]
2021-07-27 6:51 ` [PATCH v5 4/7] iwlwifi: integrate with iwlmei Emmanuel Grumbach
2021-07-27 6:51 ` [PATCH v5 5/7] nl80211: vendor-cmd: add Intel vendor commands for iwlmei usage Emmanuel Grumbach
2021-07-27 6:51 ` [PATCH v5 6/7] iwlwifi: mvm: add vendor commands needed for iwlmei Emmanuel Grumbach
2021-07-27 6:51 ` [PATCH v5 7/7] iwlwifi: mvm: read the rfkill state and feed it to iwlmei Emmanuel Grumbach
2021-08-02 18:33 ` [PATCH v5 1/7] mei: bus: add client dma interface Grumbach, Emmanuel
2021-08-02 18:54 ` Coelho, Luciano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210727065134.3902-3-emmanuel.grumbach@intel.com \
--to=emmanuel.grumbach@intel.com \
--cc=egrumbach@gmail.com \
--cc=kvalo@codeaurora.org \
--cc=linux-wireless@vger.kernel.org \
--cc=luciano.coelho@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).