mei: bus: add client dma interface
Subsystems (4)
PATCH v5 1/7 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;
@@ -1054,6 +1114,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
@@ -116,4 +116,7 @@ int mei_cldev_enable(struct mei_cl_device *cldev);int mei_cldev_disable (struct mei_cl_device *cldev);bool mei_cldev_enabled (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 v5 2/7 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.
--- drivers/net/wireless/intel/iwlwifi/Kconfig | 17 + 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 | 467 ++++ drivers/net/wireless/intel/iwlwifi/mei/main.c | 1890 +++++++++++++++++ drivers/net/wireless/intel/iwlwifi/mei/net.c | 409 ++++ drivers/net/wireless/intel/iwlwifi/mei/sap.h | 731 +++++++ .../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, 3689 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 +17 -0
@@ -92,6 +92,23 @@ 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. This 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. + 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 +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 +/* +* 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 +467 -0
467 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +1890 -0
1,890 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 +731 -0
177 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.
PATCH v5 3/7 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
@@ -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);
Signature · 1 line
2.25.1
PATCH v5 4/7 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.
--- .../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 | 73 +++++++ drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 205 +++++++++++++++++- 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 | 16 +- 11 files changed, 499 insertions(+), 22 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 {
@@ -1088,6 +1089,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
@@ -907,6 +907,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
@@ -941,6 +942,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
@@ -750,6 +750,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); }
@@ -1317,7 +1319,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 +73 -0
107 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mvm/ops.c +193 -12
305 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 */
@@ -1120,6 +1120,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 +25 -0
@@ -1151,6 +1151,27 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) trans_pcie =IWL_TRANS_GET_PCIE_TRANS (iwl_trans); +/* +* Let's try to grab NIC access early here. Sometimes, NICs may +* fail to initialize, and if that happens it's better if we see +* issues early on (and can reprobe, per the logic inside), than +* first trying to load the firmware etc. and potentially only +* detecting any problems when the first interface is brought up. +*/ + ret =iwl_pcie_prepare_card_hw (iwl_trans); +if (!ret) { + ret =iwl_finish_nic_init (iwl_trans, 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 );for (i =0 ; i <ARRAY_SIZE (iwl_dev_info_table); i++) {
@@ -1288,6 +1309,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 +14 -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"
@@ -576,8 +577,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 );
@@ -590,8 +593,17 @@ 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_WARN(trans, + "Couldn't prepare the card but SAP is connected\n"); + trans->csme_own = true; + return -EBUSY; + } usleep_range(200, 1000); t += 200;
Signature · 1 line
2.25.1
PATCH v5 5/7 nl80211: vendor-cmd: add Intel vendor commands for iwlmei usage
In reply to Emmanuel Grumbachiwlmei allows to integrate with the CSME firmware. There are flows that are prioprietary for this purpose:
* Get the information of the AP the CSME firmware is connected to. This is useful when we need to speed up the connection process in case the CSME firmware has a TCP connection that must be kept alive across the ownership transition.
* Forbid roaming, which will happen when the CSME firmware wants to tell the user space not disrupt the connection.
* Request ownership, upon driver boot when the CSME firmware owns the device. This is a notification sent by the kernel.
All those commands are expected to be used by any software managing the connection (mainly NetworkManager). Those commands are expected to be used only in case the CSME firmware owns the device and doesn't want to release the device unless the host made sure that it can keep the connectivity.
Here are the steps of the expected flow:
1) The machine boots while AMT has an active TCP connection
2) iwlwifi starts and tries to access the device
3) The device is not available because of the active TCP connection. (If there are no active connections, the CSME firmware would have allowed iwlwifi to use the device)
Note that all the steps up to here don't involve iwlmei. All this happens in iwlwifi (in iwl_pcie_prepare_card_hw).
4) iwlmei establishes a connection to the CSME firmware (through SAP)
Here iwlwifi uses iwlmei to access the device's capabilities (since it can't touch the device), but this is not relevant for the vendor commands.
5) The CSME firmware tells iwlmei that it uses the NIC and that there is an acitve TCP connection, and hence, the host needs to think twice before asking the CSME firmware to release the device
6) iwlmei tells iwlwifi to report HW RFKILL with a special reason
Up to here, there was no user space involved.
7) The user space (NetworkManager) boots and sees that the device is in RFKILL because the host doesn't own the device
8) The user space asks the kernel what AP the CSME firmware is connected to (with the first vendor command mentionned above)
9) The user space checks if it has a profile that matches the reply from the CSME firmware
10) The user space installs a network to the wpa_supplicant with a specific BSSID and a specific frequency
11) The user space prevents any type of full scan
12) The user space asks iwlmei to request ownership on the device (with the third vendor command)
13) iwlmei request ownership from the CSME firmware
14) The CSME firmware grants ownership
15) iwlmei tells iwlwifi to lift the RFKILL
16) RFKILL OFF is reported to userspace
17) The host boots the device, loads the firwmare, and connect to a specific BSSID without scanning including IP in less than 600ms (this is what I measured, of course it depends on many factors)
18) The host reports to the CSME firmware that there is a connection
19) The TCP connection is preserved and the host has now connectivity
20) Later, the TCP connection to the CSME firmware is terminated
21) The CSME firmware tells iwlmei that it is now free to do whatever it likes
22) iwlwifi sends the second vendor command to tell the user space that it can remove the special network configuration and pick any SSID / BSSID it likes.
--- include/uapi/linux/nl80211-vnd-intel.h | 77 ++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 include/uapi/linux/nl80211-vnd-intel.h
include/uapi/linux/nl80211-vnd-intel.h new file +77 -0
@@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (C) 2012-2014, 2018-2021 Intel Corporation +* Copyright (C) 2013-2015 Intel Mobile Communications GmbH +* Copyright (C) 2016-2017 Intel Deutschland GmbH +*/ +#ifndef __VENDOR_CMD_INTEL_H__ +#define __VENDOR_CMD_INTEL_H__ + +#define INTEL_OUI 0x001735 + +/** +* enum iwl_mvm_vendor_cmd - supported vendor commands +* @IWL_MVM_VENDOR_CMD_GET_CSME_CONN_INFO: reports CSME connection info. +* @IWL_MVM_VENDOR_CMD_HOST_GET_OWNERSHIP: asks for ownership on the device. +* @IWL_MVM_VENDOR_CMD_ROAMING_FORBIDDEN_EVENT: notifies if roaming is allowed. +* It contains a &IWL_MVM_VENDOR_ATTR_ROAMING_FORBIDDEN and a +* &IWL_MVM_VENDOR_ATTR_VIF_ADDR attributes. +*/ + +enum iwl_mvm_vendor_cmd { +IWL_MVM_VENDOR_CMD_GET_CSME_CONN_INFO =0x2d , +IWL_MVM_VENDOR_CMD_HOST_GET_OWNERSHIP =0x30 , +IWL_MVM_VENDOR_CMD_ROAMING_FORBIDDEN_EVENT =0x32 , +}; + +enum iwl_vendor_auth_akm_mode { +IWL_VENDOR_AUTH_OPEN , +IWL_VENDOR_AUTH_RSNA =0x6 , +IWL_VENDOR_AUTH_RSNA_PSK , +IWL_VENDOR_AUTH_SAE =0x9 , +IWL_VENDOR_AUTH_MAX , +}; + +/** +* enum iwl_mvm_vendor_attr - attributes used in vendor commands +* @__IWL_MVM_VENDOR_ATTR_INVALID: attribute 0 is invalid +* @IWL_MVM_VENDOR_ATTR_VIF_ADDR: interface MAC address +* @IWL_MVM_VENDOR_ATTR_ADDR: MAC address +* @IWL_MVM_VENDOR_ATTR_SSID: SSID (binary attribute, 0..32 octets) +* @IWL_MVM_VENDOR_ATTR_STA_CIPHER: the cipher to use for the station with the +* mac address specified in &IWL_MVM_VENDOR_ATTR_ADDR. +* @IWL_MVM_VENDOR_ATTR_ROAMING_FORBIDDEN: u8 attribute. Indicates whether +* roaming is forbidden or not. Value 1 means roaming is forbidden, +* 0 mean roaming is allowed. +* @IWL_MVM_VENDOR_ATTR_AUTH_MODE: u32 attribute. Authentication mode type +* as specified in &enum iwl_vendor_auth_akm_mode. +* @IWL_MVM_VENDOR_ATTR_CHANNEL_NUM: u8 attribute. Contains channel number. +* @IWL_MVM_VENDOR_ATTR_BAND: u8 attribute. +* 0 for 2.4 GHz band, 1 for 5.2GHz band and 2 for 6GHz band. +* @IWL_MVM_VENDOR_ATTR_COLLOC_CHANNEL: u32 attribute. Channel number of +* collocated AP. Relevant for 6GHz AP info. +* @IWL_MVM_VENDOR_ATTR_COLLOC_ADDR: MAC address of a collocated AP. +* Relevant for 6GHz AP info. +* +* @NUM_IWL_MVM_VENDOR_ATTR: number of vendor attributes +* @MAX_IWL_MVM_VENDOR_ATTR: highest vendor attribute number + +*/ +enum iwl_mvm_vendor_attr { + __IWL_MVM_VENDOR_ATTR_INVALID =0x00 , +IWL_MVM_VENDOR_ATTR_VIF_ADDR =0x02 , +IWL_MVM_VENDOR_ATTR_ADDR =0x0a , +IWL_MVM_VENDOR_ATTR_SSID =0x3d , +IWL_MVM_VENDOR_ATTR_STA_CIPHER =0x51 , +IWL_MVM_VENDOR_ATTR_ROAMING_FORBIDDEN =0x64 , +IWL_MVM_VENDOR_ATTR_AUTH_MODE =0x65 , +IWL_MVM_VENDOR_ATTR_CHANNEL_NUM =0x66 , +IWL_MVM_VENDOR_ATTR_BAND =0x69 , +IWL_MVM_VENDOR_ATTR_COLLOC_CHANNEL =0x70 , +IWL_MVM_VENDOR_ATTR_COLLOC_ADDR =0x71 , + +NUM_IWL_MVM_VENDOR_ATTR , +MAX_IWL_MVM_VENDOR_ATTR =NUM_IWL_MVM_VENDOR_ATTR -1 , +}; + +#endif /* __VENDOR_CMD_INTEL_H__ */
Signature · 1 line
2.25.1
PATCH v5 6/7 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
--- drivers/net/wireless/intel/iwlwifi/Kconfig | 11 ++ .../net/wireless/intel/iwlwifi/mvm/Makefile | 1 + .../net/wireless/intel/iwlwifi/mvm/mac80211.c | 2 + drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 9 +- .../wireless/intel/iwlwifi/mvm/vendor-cmd.c | 186 ++++++++++++++++++ 5 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 drivers/net/wireless/intel/iwlwifi/mvm/vendor-cmd.c
drivers/net/wireless/intel/iwlwifi/Kconfig +11 -0
@@ -92,11 +92,22 @@ config IWLWIFI_BCAST_FILTERING If unsure, don't enable this option, as some programs might expect incoming broadcasts for their normal operations. +config IWLMVM_VENDOR_CMDS + bool "Enable vendor commands" + depends on IWLMVM + help + This option enables support for vendor commands, including some + that don't have their own Kconfig option. Other Kconfig options + depend on this one as well. + + This is not enabled by default, if unsure, say N. + config IWLMEI tristate "Intel Management Engine communication over WLAN" depends on INTEL_MEI depends on PM depends on IWLMVM + select IWLMVM_VENDOR_CMDS help Enables the iwlmei kernel module. This allows to communicate with the Intel Management Engine over Wifi. This is supported starting
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_IWLMVM_VENDOR_CMDS) += vendor-cmd.o ccflags-y += -I $(srctree)/$(src)/../
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +2 -0
@@ -719,6 +719,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 +3 -6
@@ -2216,11 +2216,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 +186 -0
186 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 7/7 iwlwifi: mvm: read the rfkill state and feed it to iwlmei
In reply to Emmanuel GrumbachRemove the corresponding vendor command as well. Read 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
@@ -1147,6 +1147,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; }
@@ -1264,6 +1266,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
@@ -2210,10 +2210,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
@@ -753,6 +753,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
Hi Kalle,
Quoted 9 lines
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 8 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]>
This series is assigned to Luca on patchwork besides this patch and the one with the vendor commands which are assigned to Johannes.
I am a bit confused because you seemed to say you want to look at them, so maybe they should be assigned to you?
Moreover the vendor commands patch is meant to be routed through the drivers' tree.
Thank you.
Quoted 20 lines · Emmanuel
Hi Kalle,
Quoted 9 lines
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 8 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]>
Quoted 6 lines
This series is assigned to Luca on patchwork besides this patch and the one with the vendor commands which are assigned to Johannes.
I am a bit confused because you seemed to say you want to look at them, so maybe they should be assigned to you?
Moreover the vendor commands patch is meant to be routed through the drivers' tree.
Emmanuel, the assignment is done automatically depending on the files changed.
Since Kalle earlier said that he wants to review and apply these patches directly to his tree, I'll assign the entire series to him now.
--
Cheers,
Luca.