mei: bus: add client dma interface
Subsystems (3)
PATCH v8 1/6 mei: bus: add client dma interface
From: Alexander Usyskin <[email protected]>
Expose the client dma mapping via mei client bus interface. The client dma has to be mapped before the device is enabled, therefore we need to create device linking already during mapping and we need to unmap after the client is disable hence we need to postpone the unlink and flush till unmapping or when destroying the device.
--- drivers/misc/mei/bus.c | 67 ++++++++++++++++++++++++++++++++++++-- drivers/misc/mei/client.c | 3 ++ drivers/misc/mei/hw.h | 5 +++ include/linux/mei_cl_bus.h | 3 ++ 4 files changed, 75 insertions(+), 3 deletions(-)
drivers/misc/mei/bus.c +64 -3
@@ -643,6 +643,64 @@ static void mei_cl_bus_vtag_free(struct mei_cl_device *cldev)kfree (cl_vtag); } +void *mei_cldev_dma_map (struct mei_cl_device *cldev,u8 buffer_id,size_t size) +{ +struct mei_device *bus; +struct mei_cl *cl; +int ret; + +if (!cldev || !buffer_id || !size) +return ERR_PTR (-EINVAL ); + +if (!IS_ALIGNED (size,MEI_FW_PAGE_SIZE )) { +dev_err (&cldev->dev,"Map size should be aligned to %lu\n" , +MEI_FW_PAGE_SIZE ); +return ERR_PTR (-EINVAL ); + } + + cl = cldev->cl; + bus = cldev->bus; + +mutex_lock (&bus->device_lock); +if (cl->state ==MEI_FILE_UNINITIALIZED ) { + ret =mei_cl_link (cl); +if (ret) + goto out; +/* update pointers */ + cl->cldev = cldev; + } + + ret =mei_cl_dma_alloc_and_map (cl,NULL , buffer_id, size); +out: +mutex_unlock (&bus->device_lock); +if (ret) +return ERR_PTR (ret); +return cl->dma.vaddr; +} +EXPORT_SYMBOL_GPL (mei_cldev_dma_map); + +int mei_cldev_dma_unmap (struct mei_cl_device *cldev) +{ +struct mei_device *bus; +struct mei_cl *cl; +int ret; + +if (!cldev) +return -EINVAL ; + + cl = cldev->cl; + bus = cldev->bus; + +mutex_lock (&bus->device_lock); + ret =mei_cl_dma_unmap (cl,NULL ); + +mei_cl_flush_queues (cl,NULL ); +mei_cl_unlink (cl); +mutex_unlock (&bus->device_lock); +return ret; +} +EXPORT_SYMBOL_GPL (mei_cldev_dma_unmap); +/** * mei_cldev_enable - enable me client device * create connection with me client
@@ -753,9 +811,11 @@ int mei_cldev_disable(struct mei_cl_device *cldev)dev_err (bus->dev,"Could not disconnect from the ME client\n" ); out: -/* Flush queues and remove any pending read */ -mei_cl_flush_queues (cl,NULL ); -mei_cl_unlink (cl); +/* Flush queues and remove any pending read unless we have mapped DMA */ +if (!cl->dma_mapped) { +mei_cl_flush_queues (cl,NULL ); +mei_cl_unlink (cl); + }mutex_unlock (&bus->device_lock);return err;
@@ -1052,6 +1112,7 @@ static void mei_cl_bus_dev_release(struct device *dev)if (!cldev)return ; +mei_cl_flush_queues (cldev->cl,NULL );mei_me_cl_put (cldev->me_cl);mei_dev_bus_put (cldev->bus);mei_cl_unlink (cldev->cl);
drivers/misc/mei/client.c +3 -0
@@ -700,6 +700,9 @@ int mei_cl_unlink(struct mei_cl *cl)cl_dbg (dev, cl,"unlink client" ); +if (cl->state ==MEI_FILE_UNINITIALIZED ) +return 0 ; +if (dev->open_handle_count >0 ) dev->open_handle_count--;
drivers/misc/mei/hw.h +5 -0
@@ -22,6 +22,11 @@#define MEI_D0I3_TIMEOUT 5/* D0i3 set/unset max response time */ #define MEI_HBM_TIMEOUT 1/* 1 second */ +/* +* FW page size for DMA allocations +*/ +#define MEI_FW_PAGE_SIZE 4096UL +/* * MEI Version */
include/linux/mei_cl_bus.h +3 -0
@@ -117,4 +117,7 @@ int mei_cldev_enable(struct mei_cl_device *cldev);int mei_cldev_disable (struct mei_cl_device *cldev);bool mei_cldev_enabled (const struct mei_cl_device *cldev); +void *mei_cldev_dma_map (struct mei_cl_device *cldev,u8 buffer_id,size_t size); +int mei_cldev_dma_unmap (struct mei_cl_device *cldev); +#endif /* _LINUX_MEI_CL_BUS_H */
Signature · 1 line
2.25.1
PATCH v8 2/6 iwlwifi: mei: add the driver to allow cooperation with CSME
CSME in two words
-----------------
CSME stands for Converged Security and Management Engine. It is a CPU on the chipset and runs a dedicated firmware.
AMT (Active Management Technology) is one of the applications that run on that CPU. AMT allows to control the platform remotely. Here is a partial list of the use cases:
* View the screen of the plaform, with keyboard and mouse (KVM)
* Attach a remote IDE device
* Have a serial console to the device
* Query the state of the platform
* Reset / shut down / boot the platform
Networking in CSME
------------------
For those uses cases, CSME's firmware has an embedded network stack and is able to use the network devices of the system: LAN and WLAN. This is thanks to the CSME's firmware WLAN driver.
One can add a profile (SSID / key / certificate) to the CSME's OS and CSME will connect to that profile. Then, one can use the WLAN link to access the applications that run on CSME (AMT is one of them). Note that CSME is active during power state and power state transitions. For example, it is possible to have a KVM session open to the system while the system is rebooting and actually configure the BIOS remotely over WLAN thanks to AMT.
How all this is related to Linux
--------------------------------
In Linux, there is a driver that allows the OS to talk to the CSME firmware, this driver is drivers/misc/mei. This driver advertises a bus that allows other kernel drivers or even user space) to talk to components inside the CSME firmware. In practice, the system advertises a PCI device that allows to send / receive data to / from the CSME firmware. The mei bus drivers in drivers/misc/mei is an abstration on top of this PCI device.
The driver being added here is called iwlmei and talks to the WLAN driver inside the CSME firmware through the mei bus driver. Note that the mei bus driver only gives bus services, it doesn't define the content of the communication.
Why do we need this driver?
--------------------------
CSME uses the same WLAN device that the OS is expecting to see hence we need an arbitration mechanism. This is what iwlmei is in charge of. iwlmei maintains the communication with the CSME firmware's WLAN driver. The language / protocol that is used between the CSME's firmware WLAN driver and iwlmei is OS agnostic and is called SAP which stands for Software Abritration Protocol. With SAP, iwlmei will be able to tell the CSME firmware's WLAN driver:
1) Please give me the device.
2) Please note that the SW/HW rfkill state change.
3) Please note that I am now associated to X.
4) Please note that I received this packet.
etc...
There are messages that go the opposite direction as well:
1) Please note that AMT is en/disable.
2) Please note that I believe the OS is broken and hence I'll take the device *now*, whether you like it or not, to make sure that connectivity is preserved.
3) Please note that I am willing to give the device if the OS needs it.
4) Please give me any packet that is sent on UDP / TCP on IP address XX.XX.XX.XX and an port ZZ.
5) Please send this packet.
etc...
Please check drivers/net/wireless/intel/iwlwifi/mei/sap.h for the full protocol specification.
Arbitration is not the only purpose of iwlmei and SAP. SAP also allows to maintain the AMT's functionality even when the OS owns the device. To connect to AMT, one needs to initiate an HTTP connection to port 16992. iwlmei will listen to the Rx path and forward (through SAP) to the CSME firmware the data it got. Then, the embedded HTTP server in the chipset will reply to the request and send a SAP notification to ask iwlmei to send the reply. This way, AMT running on the CSME can still work.
In practice this means that all the use cases quoted above (KVM, remote IDE device, etc...) will work even when the OS uses the WLAN device.
How to disable all this?
---------------------------
iwlmei won't be able to do anything if the CSME's networking stack is not enabled. By default, CSME's networking stack is disabled (this is a BIOS setting).
In case the CSME's networking stack is disabled, iwlwifi will just get access to the device because there is no contention with any other actor and, hence, no arbitration is needed.
In this patch, I only add the iwlmei driver. Integration with iwlwifi will be implemented in the next one.
v2: fix a few warnings raised by the different bots
v3: rewrite the commit message
v4: put the debugfs content in a different patch
v5: fix a NULL pointer dereference upon DHCP TX if SAP is connected
since we now have the required cfg80211 bits in wl-drv-next, add the RFKILL handling patch to this series.
v6: change the SAP API to inherit the values from iwl-mei.h removing
the need to ensure the values are equal with a BUILD_BUG_ON. This was suggested by Arend
v7: * fix a locking issue in case of CSME firmware reset:
When the CSME firmware resets, we need to unregister the netdev, first take the mutex, and only then, rely on it being taken.
* Add a comment to explain why it is ok to have static variables (iwlmei can't have more than a single instance).
* Add a define for 26 + 8 + 8
* Add a define SEND_SAP_MAX_WAIT_ITERATION
* make struct const
* Reword a bit the Kconfig help message
* Ayala added her Signed-off
* fixed an RCU annotation
v8: do not require ownership upfront, use NIC_OWNER instead. This fixes
a deadlock when CSME does not have the right WiFi FW. Add more documentation about the owernship transition
--- drivers/net/wireless/intel/iwlwifi/Kconfig | 26 + drivers/net/wireless/intel/iwlwifi/Makefile | 1 + .../net/wireless/intel/iwlwifi/mei/Makefile | 8 + .../net/wireless/intel/iwlwifi/mei/internal.h | 20 + .../net/wireless/intel/iwlwifi/mei/iwl-mei.h | 505 +++++ drivers/net/wireless/intel/iwlwifi/mei/main.c | 1901 +++++++++++++++++ drivers/net/wireless/intel/iwlwifi/mei/net.c | 409 ++++ drivers/net/wireless/intel/iwlwifi/mei/sap.h | 733 +++++++ .../wireless/intel/iwlwifi/mei/trace-data.h | 69 + .../net/wireless/intel/iwlwifi/mei/trace.c | 15 + .../net/wireless/intel/iwlwifi/mei/trace.h | 62 + 11 files changed, 3749 insertions(+) create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/Makefile create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/internal.h create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/iwl-mei.h create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/main.c create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/net.c create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/sap.h create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/trace-data.h create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/trace.c create mode 100644 drivers/net/wireless/intel/iwlwifi/mei/trace.h
drivers/net/wireless/intel/iwlwifi/Kconfig +26 -0
@@ -92,6 +92,32 @@ config IWLWIFI_BCAST_FILTERING If unsure, don't enable this option, as some programs might expect incoming broadcasts for their normal operations. +config IWLMEI + tristate "Intel Management Engine communication over WLAN" + depends on INTEL_MEI + depends on PM + depends on IWLMVM + help + Enables the iwlmei kernel module. + + CSME stands for Converged Security and Management Engine. It is a CPU + on the chipset and runs a dedicated firmware. AMT (Active Management + Technology) is one of the applications that run on that CPU. AMT + allows to control the platform remotely. + + This kernel module allows to communicate with the Intel Management + Engine over Wifi. This is supported starting from Tiger Lake + platforms and has been tested on 9260 devices only. + If AMT is configured not to use the wireless device, this module is + harmless (and useless). + Enabling this option on a platform that has a different device and + has Wireless enabled on AMT can prevent WiFi from working correctly. + + For more information see + <https://software.intel.com/en-us/manageability/> + + If unsure, say N. + menu "Debugging Options" config IWLWIFI_DEBUG
drivers/net/wireless/intel/iwlwifi/Makefile +1 -0
@@ -30,5 +30,6 @@ ccflags-y += -I$(src) obj-$(CONFIG_IWLDVM) += dvm/ obj-$(CONFIG_IWLMVM) += mvm/ +obj-$(CONFIG_IWLMEI) += mei/ CFLAGS_iwl-devtrace.o := -I$(src)
drivers/net/wireless/intel/iwlwifi/mei/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_IWLMEI) += iwlmei.o +iwlmei-y += main.o +iwlmei-y += net.o +iwlmei-$(CONFIG_IWLWIFI_DEVICE_TRACING) += trace.o +CFLAGS_trace.o := -I$(src) + +ccflags-y += -I $(srctree)/$(src)/../
drivers/net/wireless/intel/iwlwifi/mei/internal.h new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2021 Intel Corporation +*/ + +#ifndef __IWLMEI_INTERNAL_H_ +#define __IWLMEI_INTERNAL_H_ + +#include <uapi/linux/if_ether.h> +#include <linux/netdevice.h> + +#include "sap.h" + +rx_handler_result_t iwl_mei_rx_filter (struct sk_buff *skb, +const struct iwl_sap_oob_filters *filters, +bool *pass_to_csme); + +void iwl_mei_add_data_to_ring (struct sk_buff *skb,bool cb_tx); + +#endif /* __IWLMEI_INTERNAL_H_ */
drivers/net/wireless/intel/iwlwifi/mei/iwl-mei.h new file +505 -0
505 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +1901 -0
1,901 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mei/net.c new file +409 -0
409 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mei/sap.h new file +733 -0
119 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mei/trace-data.h new file +69 -0
69 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mei/trace.c new file +15 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireless/intel/iwlwifi/mei/trace.h new file +62 -0
62 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v8 2/6] iwlwifi: mei: add the driver to allow cooperation with CSME
Quoted 4 lines · Emmanuel Grumbach
CSME in two words
-----------------
CSME stands for Converged Security and Management Engine. It is a CPU on the chipset and runs a dedicated firmware.
Quoted 8 lines
AMT (Active Management Technology) is one of the applications that run on that CPU. AMT allows to control the platform remotely. Here is a partial list of the use cases:
* View the screen of the plaform, with keyboard and mouse (KVM)
* Attach a remote IDE device
* Have a serial console to the device
* Query the state of the platform
* Reset / shut down / boot the platform
Hi,
this patch causes link failures:
Quoted 4 lines
MODPOST modules-only.symvers
ERROR: modpost: "__SCT__tp_func_iwlmei_sap_data" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
ERROR: modpost: "__SCT__tp_func_iwlmei_me_msg" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
ERROR: modpost: "__tracepoint_iwlmei_sap_cmd" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
Quoted 8 lines
ERROR: modpost: "
__tracepoint_iwlmei_me_msg" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
ERROR: modpost: "__SCK__tp_func_iwlmei_me_msg" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
ERROR: modpost: "__SCK__tp_func_iwlmei_sap_data" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
ERROR: modpost: "__tracepoint_iwlmei_sap_data" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
ERROR: modpost: "__SCT__tp_func_iwlmei_sap_cmd" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
ERROR: modpost: "__SCK__tp_func_iwlmei_sap_cmd" [drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined! make[1]: *** [../scripts/Makefile.modpost:134: modules-only.symvers] Error 1
make: *** [../Makefile:1904: modules] Error 2
with this config:
https://raw.githubusercontent.com/openSUSE/kernel-source/linux-next/config/x86_64/vanilla
regards,
Signature · 2 lines
js suse labs
RE: [PATCH v8 2/6] iwlwifi: mei: add the driver to allow cooperation with CSME
Hi Jiri,
Quoted 35 lines · Emmanuel Grumbach
Quoted 4 lines
CSME in two words
-----------------
CSME stands for Converged Security and Management Engine. It is a CPU on the chipset and runs a dedicated firmware.Quoted 8 lines
AMT (Active Management Technology) is one of the applications that run on that CPU. AMT allows to control the platform remotely. Here is a partial list of the use cases:
* View the screen of the plaform, with keyboard and mouse (KVM)
* Attach a remote IDE device
* Have a serial console to the device
* Query the state of the platform
* Reset / shut down / boot the platformHi,
this patch causes link failures:
Quoted 2 lines
MODPOST modules-only.symvers
ERROR: modpost: "__SCT__tp_func_iwlmei_sap_data"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
ERROR: modpost: "
__SCT__tp_func_iwlmei_me_msg"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
ERROR: modpost: "
__tracepoint_iwlmei_sap_cmd"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
ERROR: modpost: "
__tracepoint_iwlmei_me_msg"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
ERROR: modpost: "
__SCK__tp_func_iwlmei_me_msg"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
ERROR: modpost: "
__SCK__tp_func_iwlmei_sap_data"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
ERROR: modpost: "
__tracepoint_iwlmei_sap_data"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
ERROR: modpost: "
__SCT__tp_func_iwlmei_sap_cmd"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!
Quoted 9 lines
Quoted 1 line
ERROR: modpost: "
__SCK__tp_func_iwlmei_sap_cmd"[
drivers/net/wireless/intel/iwlwifi/mei/iwlmei.ko] undefined!Quoted 1 line
make[1]: *** [../scripts/Makefile.modpost:134: modules-only.symvers]
Error 1 > make: *** [../Makefile:1904: modules] Error 2
with this config:
https://raw.githubusercontent.com/openSUSE/kernel-source/linux-
next/config/x86_64/vanilla
Thanks for reporting.
I sent a patch to fix this:
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/
Thanks again.
PATCH v8 3/6 iwlwifi: mei: add debugfs hooks
In reply to Emmanuel GrumbachAdd 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).
--- drivers/net/wireless/intel/iwlwifi/mei/main.c | 85 ++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mei/main.c +83 -2
@@ -11,6 +11,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>
@@ -149,6 +150,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;
@@ -167,6 +169,8 @@ struct iwl_mei {atomic_t sap_seq_no;atomic_t seq_no; + +struct dentry *dbgfs_dir; };/**
@@ -1695,6 +1699,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 *
@@ -1733,6 +1809,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.
@@ -1741,14 +1819,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);
@@ -1868,6 +1947,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);
Signature · 1 line
2.25.1
PATCH v8 4/6 iwlwifi: integrate with iwlmei
In reply to Emmanuel Grumbachiwlmei needs to know about the follwing events:
* Association
* De-association
* Country Code change
* SW Rfkill change
* SAR table changes
iwlmei can take the device away from us, so report the new rfkill type when this happens.
Advertise the required data from the CSME firmware to the
usersapce: mostly, the AP that the CSME firmware is currently associated to in case there is an active link protection session.
Generate the HOST_ASSOC / HOST_DISSASSOC messages.
Don't support WPA1 (non-RSNA) for now.
Don't support shared wep either.
We can then determine the AUTH parameter by checking the AKM. Feed the cipher from the key installation.
SW Rfkill will be implemented later when cfg80211 will allow us to read the SW Rfkill state.
v7: Ayala added her signed-off
remove pointless function declaration
fix a bug due to merge conflict in the HOST_ASSOC message
v8: leave a print if we have a SAP connection on a device we do
not support (yet)
--- .../wireless/intel/iwlwifi/iwl-nvm-parse.c | 61 ++++++ .../wireless/intel/iwlwifi/iwl-nvm-parse.h | 11 +- .../net/wireless/intel/iwlwifi/iwl-trans.h | 2 + drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 3 +- .../net/wireless/intel/iwlwifi/mvm/mac80211.c | 114 +++++++++- drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 62 ++++++ drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 200 +++++++++++++++++- drivers/net/wireless/intel/iwlwifi/mvm/sta.h | 4 +- drivers/net/wireless/intel/iwlwifi/mvm/tx.c | 7 +- drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 25 ++- .../net/wireless/intel/iwlwifi/pcie/trans.c | 21 +- 11 files changed, 481 insertions(+), 29 deletions(-)
drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c +61 -0
@@ -22,6 +22,7 @@#include "fw/api/commands.h" #include "fw/api/cmdhdr.h" #include "fw/img.h" +#include "mei/iwl-mei.h" /* NVM offsets (in words) definitions */ enum nvm_offsets {
@@ -1114,6 +1115,66 @@ iwl_nvm_no_wide_in_5ghz(struct iwl_trans *trans, const struct iwl_cfg *cfg,return false; } +struct iwl_nvm_data * +iwl_parse_mei_nvm_data (struct iwl_trans *trans,const struct iwl_cfg *cfg, +const struct iwl_mei_nvm *mei_nvm, +const struct iwl_fw *fw) +{ +struct iwl_nvm_data *data; +u32 sbands_flags =0 ; +u8 rx_chains = fw->valid_rx_ant; +u8 tx_chains = fw->valid_rx_ant; + +if (cfg->uhb_supported) + data =kzalloc (struct_size (data, channels, +IWL_NVM_NUM_CHANNELS_UHB ), +GFP_KERNEL ); +else + data =kzalloc (struct_size (data, channels, +IWL_NVM_NUM_CHANNELS_EXT ), +GFP_KERNEL ); +if (!data) +return NULL ; + +BUILD_BUG_ON (ARRAY_SIZE (mei_nvm->channels) != +IWL_NVM_NUM_CHANNELS_UHB ); + data->nvm_version = mei_nvm->nvm_version; + +iwl_set_radio_cfg (cfg, data, mei_nvm->radio_cfg); +if (data->valid_tx_ant) + tx_chains &= data->valid_tx_ant; +if (data->valid_rx_ant) + rx_chains &= data->valid_rx_ant; + + data->sku_cap_mimo_disabled = false; + data->sku_cap_band_24ghz_enable = true; + data->sku_cap_band_52ghz_enable = true; + data->sku_cap_11n_enable = + !(iwlwifi_mod_params.disable_11n &IWL_DISABLE_HT_ALL ); + data->sku_cap_11ac_enable = true; + data->sku_cap_11ax_enable = + mei_nvm->caps &MEI_NVM_CAPS_11AX_SUPPORT ; + + data->lar_enabled = mei_nvm->caps &MEI_NVM_CAPS_LARI_SUPPORT ; + + data->n_hw_addrs = mei_nvm->n_hw_addrs; +/* If no valid mac address was found - bail out */ +if (iwl_set_hw_address (trans, cfg, data,NULL ,NULL )) { +kfree (data); +return NULL ; + } + +if (data->lar_enabled && +fw_has_capa (&fw->ucode_capa,IWL_UCODE_TLV_CAPA_LAR_SUPPORT )) + sbands_flags |=IWL_NVM_SBANDS_FLAGS_LAR ; + +iwl_init_sbands (trans, data, mei_nvm->channels, tx_chains, rx_chains, + sbands_flags, true, fw); + +return data; +} +IWL_EXPORT_SYMBOL (iwl_parse_mei_nvm_data); +struct iwl_nvm_data * iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg, const struct iwl_fw *fw,
drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h +10 -1
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* -* Copyright (C) 2005-2015, 2018-2020 Intel Corporation +* Copyright (C) 2005-2015, 2018-2021 Intel Corporation * Copyright (C) 2016-2017 Intel Deutschland GmbH */ #ifndef __iwl_nvm_parse_h__
@@ -8,6 +8,7 @@#include <net/cfg80211.h> #include "iwl-eeprom-parse.h" +#include "mei/iwl-mei.h" /** * enum iwl_nvm_sbands_flags - modification flags for the channel profiles
@@ -81,4 +82,12 @@ void iwl_nvm_fixups(u32 hw_id, unsigned int section, u8 *data,struct iwl_nvm_data *iwl_get_nvm (struct iwl_trans *trans,const struct iwl_fw *fw); +/** +* iwl_parse_mei_nvm_data - parse the mei_nvm_data and get an iwl_nvm_data +*/ +struct iwl_nvm_data * +iwl_parse_mei_nvm_data (struct iwl_trans *trans,const struct iwl_cfg *cfg, +const struct iwl_mei_nvm *mei_nvm, +const struct iwl_fw *fw); +#endif /* __iwl_nvm_parse_h__ */
drivers/net/wireless/intel/iwlwifi/iwl-trans.h +2 -0
@@ -924,6 +924,7 @@ struct iwl_trans_txqs {/** * struct iwl_trans - transport common data * +* @csme_own - true if we couldn't get ownership on the device * @ops - pointer to iwl_trans_ops * @op_mode - pointer to the op_mode * @trans_cfg: the trans-specific configuration part
@@ -958,6 +959,7 @@ struct iwl_trans_txqs {* @iwl_trans_txqs: transport tx queues data. */ struct iwl_trans { +bool csme_own;const struct iwl_trans_ops *ops;struct iwl_op_mode *op_mode;const struct iwl_cfg_trans_params *trans_cfg;
drivers/net/wireless/intel/iwlwifi/mvm/fw.c +2 -1
@@ -757,6 +757,8 @@ int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)if (ret)return ret; +iwl_mei_set_power_limit (per_chain); +IWL_DEBUG_RADIO (mvm,"Sending REDUCE_TX_POWER_CMD per chain\n" );return iwl_mvm_send_cmd_pdu (mvm,REDUCE_TX_POWER_CMD ,0 , len, &cmd); }
@@ -1401,7 +1403,6 @@ static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)if (iwl_mvm_has_unified_ucode (mvm))return iwl_run_unified_mvm_ucode (mvm); -WARN_ON (!mvm->nvm_data); ret =iwl_run_init_mvm_ucode (mvm);if (ret) {
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +110 -4
198 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +62 -0
90 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mvm/ops.c +190 -10
306 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mvm/sta.h +3 -1
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* -* Copyright (C) 2012-2014, 2018-2020 Intel Corporation +* Copyright (C) 2012-2014, 2018-2021 Intel Corporation * Copyright (C) 2013-2014 Intel Mobile Communications GmbH * Copyright (C) 2015-2016 Intel Deutschland GmbH */
@@ -373,6 +373,7 @@ struct iwl_mvm_rxq_dup_data {* @tx_ant: the index of the antenna to use for data tx to this station. Only * used during connection establishment (e.g. for the 4 way handshake * exchange). +* @pairwise_cipher: used to feed iwlmei upon authorization * * When mac80211 creates a station it reserves some space (hw->sta_data_size) * in the structure for use by driver. This structure is placed in that
@@ -415,6 +416,7 @@ struct iwl_mvm_sta {u8 sleep_tx_count;u8 avg_energy;u8 tx_ant; +u32 pairwise_cipher; };u16 iwl_mvm_tid_queued (struct iwl_mvm *mvm,struct iwl_mvm_tid_data *tid_data);
drivers/net/wireless/intel/iwlwifi/mvm/tx.c +6 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* -* Copyright (C) 2012-2014, 2018-2020 Intel Corporation +* Copyright (C) 2012-2014, 2018-2021 Intel Corporation * Copyright (C) 2013-2015 Intel Mobile Communications GmbH * Copyright (C) 2016-2017 Intel Deutschland GmbH */
@@ -1128,6 +1128,11 @@ static int iwl_mvm_tx_mpdu(struct iwl_mvm *mvm, struct sk_buff *skb,/* From now on, we cannot access info->control */ iwl_mvm_skb_prepare_status (skb, dev_cmd); +if (ieee80211_is_data (fc)) +iwl_mvm_mei_tx_copy_to_csme (mvm, skb, + info->control.hw_key ? + info->control.hw_key->iv_len :0 ); +if (iwl_trans_tx (mvm->trans, skb, dev_cmd, txq_id)) goto drop_unlock_sta;
drivers/net/wireless/intel/iwlwifi/pcie/drv.c +16 -9
@@ -1422,15 +1422,18 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)* first trying to load the firmware etc. and potentially only * detecting any problems when the first interface is brought up. */ - ret =iwl_finish_nic_init (iwl_trans); -if (ret) - goto out_free_trans; -if (iwl_trans_grab_nic_access (iwl_trans)) { -/* all good */ -iwl_trans_release_nic_access (iwl_trans); - }else { - ret = -EIO ; - goto out_free_trans; + ret =iwl_pcie_prepare_card_hw (iwl_trans); +if (!ret) { + ret =iwl_finish_nic_init (iwl_trans); +if (ret) + goto out_free_trans; +if (iwl_trans_grab_nic_access (iwl_trans)) { +/* all good */ +iwl_trans_release_nic_access (iwl_trans); + }else { + ret = -EIO ; + goto out_free_trans; + } } iwl_trans->hw_rf_id =iwl_read32 (iwl_trans,CSR_HW_RF_ID );
@@ -1563,6 +1566,10 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto out_free_trans;pci_set_drvdata (pdev, iwl_trans); + +/* try to get ownership so that we'll know if we don't own it */ +iwl_pcie_prepare_card_hw (iwl_trans); + iwl_trans->drv =iwl_drv_start (iwl_trans);if (IS_ERR (iwl_trans->drv)) {
drivers/net/wireless/intel/iwlwifi/pcie/trans.c +19 -2
@@ -24,6 +24,7 @@#include "fw/error-dump.h" #include "fw/dbg.h" #include "fw/api/tx.h" +#include "mei/iwl-mei.h" #include "internal.h" #include "iwl-fh.h" #include "iwl-context-info-gen3.h"
@@ -594,8 +595,10 @@ int iwl_pcie_prepare_card_hw(struct iwl_trans *trans) ret =iwl_pcie_set_hw_ready (trans);/* If the card is ready, exit 0 */ -if (ret >=0 ) +if (ret >=0 ) { + trans->csme_own = false;return 0 ; + }iwl_set_bit (trans,CSR_DBG_LINK_PWR_MGMT_REG ,CSR_RESET_LINK_PWR_MGMT_DISABLED );
@@ -608,8 +611,22 @@ int iwl_pcie_prepare_card_hw(struct iwl_trans *trans) do { ret = iwl_pcie_set_hw_ready(trans); - if (ret >= 0) + if (ret >= 0) { + trans->csme_own = false; return 0; + } + + if (iwl_mei_is_connected()) { + IWL_DEBUG_INFO(trans, + "Couldn't prepare the card but SAP is connected\n"); + trans->csme_own = true; + if (trans->trans_cfg->device_family != + IWL_DEVICE_FAMILY_9000) + IWL_ERR(trans, + "SAP not supported for this NIC family\n"); + + return -EBUSY; + } usleep_range(200, 1000); t += 200;
Signature · 1 line
2.25.1
PATCH v8 5/6 iwlwifi: mvm: add vendor commands needed for iwlmei
In reply to Emmanuel GrumbachAdd the vendor commands that must be used by the network manager to allow proper operation of iwlmei.
* Send information on the AP CSME is connected to
* Notify the userspace when roaming is forbidden
* Allow the userspace to require ownership
v6: remove the VENDOR_CMDS Kconfig option and make the whole infra
depend on IWLMEI directly
v7: remove // comments
remove an unneeded function
--- .../net/wireless/intel/iwlwifi/mvm/Makefile | 1 + .../net/wireless/intel/iwlwifi/mvm/mac80211.c | 2 + drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 20 ++- .../wireless/intel/iwlwifi/mvm/vendor-cmd.c | 151 ++++++++++++++++++ 4 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 drivers/net/wireless/intel/iwlwifi/mvm/vendor-cmd.c
drivers/net/wireless/intel/iwlwifi/mvm/Makefile +1 -0
@@ -10,5 +10,6 @@ iwlmvm-y += rfi.o iwlmvm-$(CONFIG_IWLWIFI_DEBUGFS) += debugfs.o debugfs-vif.o iwlmvm-$(CONFIG_IWLWIFI_LEDS) += led.o iwlmvm-$(CONFIG_PM) += d3.o +iwlmvm-$(CONFIG_IWLMEI) += vendor-cmd.o ccflags-y += -I $(srctree)/$(src)/../
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +2 -0
@@ -720,6 +720,8 @@ int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)wiphy_ext_feature_set (hw->wiphy,NL80211_EXT_FEATURE_PROTECTED_TWT ); +iwl_mvm_vendor_cmds_register (mvm); + hw->wiphy->available_antennas_tx =iwl_mvm_get_valid_tx_ant (mvm); hw->wiphy->available_antennas_rx =iwl_mvm_get_valid_rx_ant (mvm);
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +14 -6
@@ -1959,6 +1959,17 @@ void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm);int iwl_mvm_send_temp_report_ths_cmd (struct iwl_mvm *mvm);int iwl_mvm_ctdp_command (struct iwl_mvm *mvm,u32 op,u32 budget); +#if IS_ENABLED (CONFIG_IWLMEI ) + +/* vendor commands */ +void iwl_mvm_vendor_cmds_register (struct iwl_mvm *mvm); + +#else + +static inline void iwl_mvm_vendor_cmds_register (struct iwl_mvm *mvm) {} + +#endif +/* Location Aware Regulatory */ struct iwl_mcc_update_resp * iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2,
@@ -2213,11 +2224,8 @@ static inline void iwl_mvm_mei_set_sw_rfkill_state(struct iwl_mvm *mvm, bool sw_ iwl_mei_set_rfkill_state(iwl_mvm_is_radio_killed(mvm), sw_rfkill); } -static inline void iwl_mvm_send_roaming_forbidden_event (struct iwl_mvm *mvm, -struct ieee80211_vif *vif, -bool forbidden) -{ -/* TODO */ -} +void iwl_mvm_send_roaming_forbidden_event (struct iwl_mvm *mvm, +struct ieee80211_vif *vif, +bool forbidden);#endif /* __IWL_MVM_H__ */
drivers/net/wireless/intel/iwlwifi/mvm/vendor-cmd.c new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 6/6 iwlwifi: mvm: read the rfkill state and feed it to iwlmei
In reply to Emmanuel GrumbachRead the rfkill state upon boot, mac start and mac stop.
--- drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c | 4 ++++ drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 8 ++++++-- drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +4 -0
@@ -1148,6 +1148,8 @@ static int iwl_mvm_mac_start(struct ieee80211_hw *hw) ret =__iwl_mvm_mac_start (mvm);mutex_unlock (&mvm->mutex); +iwl_mvm_mei_set_sw_rfkill_state (mvm); +return ret; }
@@ -1265,6 +1267,8 @@ static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)*/ flush_work (&mvm->roc_done_wk); +iwl_mvm_mei_set_sw_rfkill_state (mvm); +mutex_lock (&mvm->mutex);__iwl_mvm_mac_stop (mvm);mutex_unlock (&mvm->mutex);
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +6 -2
@@ -2218,10 +2218,14 @@ static inline void iwl_mvm_mei_device_down(struct iwl_mvm *mvm)iwl_mei_device_down (); } -static inline void iwl_mvm_mei_set_sw_rfkill_state (struct iwl_mvm *mvm,bool sw_rfkill) +static inline void iwl_mvm_mei_set_sw_rfkill_state (struct iwl_mvm *mvm) { +bool sw_rfkill = + mvm->hw_registered ?rfkill_blocked (mvm->hw->wiphy->rfkill) : false; +if (mvm->mei_registered) -iwl_mei_set_rfkill_state (iwl_mvm_is_radio_killed (mvm), sw_rfkill); +iwl_mei_set_rfkill_state (iwl_mvm_is_radio_killed (mvm), + sw_rfkill); } void iwl_mvm_send_roaming_forbidden_event(struct iwl_mvm *mvm,
drivers/net/wireless/intel/iwlwifi/mvm/ops.c +3 -0
@@ -756,6 +756,9 @@ static int iwl_mvm_start_post_nvm(struct iwl_mvm *mvm)wiphy_rfkill_set_hw_state_reason (mvm->hw->wiphy, mvm->mei_rfkill_blocked,RFKILL_HARD_BLOCK_NOT_OWNER ); + +iwl_mvm_mei_set_sw_rfkill_state (mvm); +return 0 ; }
Signature · 1 line
2.25.1
Quoted 9 lines · Emmanuel Grumbach
From: Alexander Usyskin <[email protected]>
Expose the client dma mapping via mei client bus interface. The client dma has to be mapped before the device is enabled, therefore we need to create device linking already during mapping and we need to unmap after the client is disable hence we need to postpone the unlink and flush till unmapping or when destroying the device.
Quoted 6 lines
Signed-off-by Alexander Usyskin <[email protected]>Co-developed-by Tomas Winkler <[email protected]>Signed-off-by Tomas Winkler <[email protected]>Signed-off-by Emmanuel Grumbach <[email protected]>
6 patches applied to wireless-drivers-next.git, thanks.
2cca3465147d mei: bus: add client dma interface2da4366f9e2c iwlwifi: mei: add the driver to allow cooperation with CSME 4ea7da5fad43 iwlwifi: mei: add debugfs hooks6d19a5eba5cd iwlwifi: integrate with iwlmeibfcfdb59b669 iwlwifi: mvm: add vendor commands needed for iwlmei 7ce1f2157e14 iwlwifi: mvm: read the rfkill state and feed it to iwlmei
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches