Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4340314pxt; Wed, 11 Aug 2021 03:56:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQdS5EWUlNrKpCdVLBWS89fjzzuxwEY3SJtN4Xb7c/S1tzxRWbauCc2yAwwnPLGHWdcb+g X-Received: by 2002:a05:6e02:154b:: with SMTP id j11mr82049ilu.96.1628679378159; Wed, 11 Aug 2021 03:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628679378; cv=none; d=google.com; s=arc-20160816; b=HvRCAhVI3eg1Nk3cOKr8faaEW4l2jBJ3CNc106VLsZyA7EWTPIU6TWobRjoi/mr6wB lN+fCeMfYfLkcKzJXmkpI4m9OgUVkOWyqNiJveBm8LWCP6cDvd26G3NMGiJy8ePyr1e9 i1XRA7ZpxS5+RZDsRIgoCz6b8pWKj0sbFnZBW6JowdcjmbWWWepvHZm5K6VJEskSm9e0 LRIhcg1eP8jA4JCxfZz+GYYDUQl+FQgvW7m8q6Q0E4vYZO9gwBFDRaFh1g6zjvyuAWmS yBS6R7hYJMz3rG1Aqk1RsBLUH966gScCSG/nXeftwlcY1/zw775EJH1Ltfsw9rcgHQbT wAjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lEQhKh3ikvfPP6yRCQt7Lap3QHVaiisA/uigWBA5FBU=; b=AKLtKIhXNI3YZtsQhj5UzVpStcU6zMMF3IdKcsIfoPJoIS0QQW1rjTyF0tOiImyECH dO9dtEpgNO1DjXgJ3rbvDFmsSoXNlK+Cc82SOiGhiD4B2kH/H2gDfI4NCd/p9hywh9OK p5q96OQYY55lkbVo/pDT5XdGzxL7ju5v3bVON3+QJeL7ccuvOHAqCMaHjiMDKB/o3oic O5NipxfeAbYEqVJsUmkhNCbV7r7BUDSxhLST5qqx+0nH467K6ugCcfKgSJaL9DFLzt7I DRpu82qpc2Oru14CitC14QdI+uCyRMVciLkJMw2w9Bu6uFKk9GzZoBDarR5X6coahfBw MiRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b2si7451738jat.76.2021.08.11.03.56.02; Wed, 11 Aug 2021 03:56:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237162AbhHKK4Q (ORCPT + 99 others); Wed, 11 Aug 2021 06:56:16 -0400 Received: from mga17.intel.com ([192.55.52.151]:46893 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237053AbhHKK4O (ORCPT ); Wed, 11 Aug 2021 06:56:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10072"; a="195369027" X-IronPort-AV: E=Sophos;i="5.84,311,1620716400"; d="scan'208";a="195369027" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 03:55:50 -0700 X-IronPort-AV: E=Sophos;i="5.84,311,1620716400"; d="scan'208";a="516648138" Received: from kniesyn-mobl1.ger.corp.intel.com (HELO egrumbac-mobl1.lan) ([10.254.155.111]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 03:55:49 -0700 From: Emmanuel Grumbach To: kvalo@codeaurora.org Cc: linux-wireless@vger.kernel.org Subject: [PATCH v6 3/7] iwlwifi: mei: add debugfs hooks Date: Wed, 11 Aug 2021 13:55:37 +0300 Message-Id: <20210811105541.43426-3-emmanuel.grumbach@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210811105541.43426-1-emmanuel.grumbach@intel.com> References: <20210811105541.43426-1-emmanuel.grumbach@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 --- 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 fb154a424fd6..f1998e2132ba 100644 --- a/drivers/net/wireless/intel/iwlwifi/mei/main.c +++ b/drivers/net/wireless/intel/iwlwifi/mei/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -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; }; /** @@ -1675,6 +1679,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 * @@ -1713,6 +1789,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. @@ -1721,14 +1799,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); @@ -1839,6 +1918,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