Skip to contentSkip to conversation

mei: bus: add client dma interface

PATCH Superseded Emmanuel Grumbach 3 participants 27 messages Aug 11, 2021 – Nov 12, 2021

Subsystems (4)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 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
index 935acc6bbf3c..7a325572ad1d 100644
@@ -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
index 96f4e59c32a5..0e90591235a6 100644
@@ -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
index dfd60c916da0..b46077b17114 100644
@@ -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
index 07f5ef8fc456..8c8d46ba33bf 100644
@@ -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
#1 lore raw

PATCH v6 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.
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

---
 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  |  471 +++++
 drivers/net/wireless/intel/iwlwifi/mei/main.c | 1872 +++++++++++++++++
 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, 3677 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
index 1085afbefba8..629aaa26a230 100644
@@ -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
index d86918d162aa..dab41f0fdea7 100644
@@ -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
new file mode 100644
index 000000000000..fd3c14e3b74c
@@ -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
new file mode 100644
index 000000000000..7f0a2e4de0f4
@@ -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 +471 -0

471 lines not on this page · raw message

drivers/net/wireless/intel/iwlwifi/mei/main.c new file +1872 -0

1,872 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

191 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
new file mode 100644
index 000000000000..47ac32ef9f69

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.

#2 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 95 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.
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.

Quoted 5 lines

In this patch, I only add the iwlmei driver. Integration with iwlwifi will be implemented in the next one.

Comments for main.c:

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1

Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +1 -0
@@ -0,0 +1,1872 @@
+// SPDX-License-Identifier: GPL-2.0

Someconsistency with the license within iwlwifi would be nice, I see that elsewhere in iwlwifi GPL-2.0-only is used instead of GPL-2.0:

grep -rh SPDX * | sort | uniq --count

      4 # SPDX-License-Identifier: GPL-2.0
      6 // SPDX-License-Identifier: GPL-2.0
      1 # SPDX-License-Identifier: GPL-2.0-only
     15 /* SPDX-License-Identifier: GPL-2.0-only */
     22 // SPDX-License-Identifier: GPL-2.0-only
     73 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
     62 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause

drivers/net/wireless/intel/iwlwifi/mei/main.c line 38

Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +9 -0
+/*
+ * Since iwlwifi calls iwlmei without any context, hold a pointer to the
+ * mei_cl_device structure here.
+ * Define a mutex that will synchronize all the flows between iwlwifi and
+ * iwlmei.
+ */
+static struct mei_cl_device *iwl_mei_global_cldev;
+static DEFINE_MUTEX(iwl_mei_mutex);
+static unsigned long iwl_mei_status;

static non-const variables are frowned upon in upstream. What if there are multiple iwlwifi devices attached to the same host, how would this work then?

Quoted 20 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +20 -0
+/**
+ * iwl_mei_cache - cache for the parameters from iwlwifi
+ * @ops: Callbacks to iwlwifi.
+ * @netdev: The netdev that will be used to transmit / receive packets.
+ * @conn_info: The connection info message triggered by iwlwifi's association.
+ * @power_limit: pointer to an array of 10 elements (le16) represents the power
+ *	restrictions per chain.
+ * @rf_kill: rf kill state.
+ * @mcc: MCC info
+ * @mac_address: interface MAC address.
+ * @nvm_address: NVM MAC address.
+ * @priv: A pointer to iwlwifi.
+ *
+ * This used to cache the configurations coming from iwlwifi's way. The data
+ * is cached here so that we can buffer the configuration even if we don't have
+ * a bind from the mei bus and hence, on iwl_mei structure.
+ */
+static struct {
+	const struct iwl_mei_ops *ops;
+	struct net_device __rcu *netdev;

drivers/net/wireless/intel/iwlwifi/mei/main.c line 196

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +10 -0
+	const struct iwl_sap_notif_connection_info *conn_info;
+	const __le16 *power_limit;
+	u32 rf_kill;
+	u16 mcc;
+	u8 mac_address[6];
+	u8 nvm_address[6];
+	void *priv;
+} iwl_mei_cache = {
+	.rf_kill = SAP_HW_RFKILL_DEASSERTED | SAP_SW_RFKILL_DEASSERTED
+};

Same here, this is also static but non-const.

Quoted 38 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +38 -0
+static void iwl_mei_handle_sap_data(struct mei_cl_device *cldev,
+				    const u8 *q_head, u32 q_sz,
+				    u32 rd, u32 wr, ssize_t valid_rx_sz,
+				    struct sk_buff_head *tx_skbs)
+{
+	struct iwl_sap_hdr hdr;
+	struct net_device *netdev =
+		rcu_dereference_protected(iwl_mei_cache.netdev,
+					  lockdep_is_held(&iwl_mei_mutex));
+
+	if (!netdev)
+		return;
+
+	while (valid_rx_sz >= sizeof(hdr)) {
+		struct ethhdr *ethhdr;
+		unsigned char *data;
+		struct sk_buff *skb;
+		u16 len;
+
+		iwl_mei_read_from_q(q_head, q_sz, &rd, wr, &hdr, sizeof(hdr));
+		valid_rx_sz -= sizeof(hdr);
+		len = le16_to_cpu(hdr.len);
+
+		if (valid_rx_sz < len) {
+			dev_err(&cldev->dev,
+				"Data queue is corrupted: valid data len %zd, len %d\n",
+				valid_rx_sz, len);
+			break;
+		}
+
+		if (len < sizeof(*ethhdr)) {
+			dev_err(&cldev->dev,
+				"Data len is smaller than an ethernet header? len = %d\n",
+				len);
+		}
+
+		valid_rx_sz -= len;
+

drivers/net/wireless/intel/iwlwifi/mei/main.c line 991

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +10 -0
+		if (le16_to_cpu(hdr.type) != SAP_MSG_DATA_PACKET) {
+			dev_err(&cldev->dev, "Unsupported Rx data: type %d, len %d\n",
+				le16_to_cpu(hdr.type), len);
+			continue;
+		}
+
+		/* We need enough room for the WiFi header + SNAP + IV */
+		skb = netdev_alloc_skb(netdev, len + 26 + 8 + 8);
+
+		skb_reserve(skb, 26 + 8 + 8);

No magic numbers, please.

Quoted 28 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +28 -0
+static void iwl_mei_remove(struct mei_cl_device *cldev)
+{
+	struct iwl_mei *mei = mei_cldev_get_drvdata(cldev);
+	int i;
+
+	/*
+	 * We are being removed while the bus is active, it means we are
+	 * going to suspend/ shutdown, so the NIC will disappear.
+	 */
+	if (mei_cldev_enabled(cldev) && iwl_mei_cache.ops)
+		iwl_mei_cache.ops->nic_stolen(iwl_mei_cache.priv);
+
+	if (rcu_access_pointer(iwl_mei_cache.netdev)) {
+		struct net_device *dev;
+
+		/*
+		 * If we are suspending and the wifi driver hasn't removed it's netdev
+		 * yet, do it now. In any case, don't change the cache.netdev pointer.
+		 */
+		dev = rcu_dereference_protected(iwl_mei_cache.netdev,
+						lockdep_is_held(&iwl_mei_mutex));
+
+		rtnl_lock();
+		netdev_rx_handler_unregister(dev);
+		rtnl_unlock();
+	}
+
+	mutex_lock(&iwl_mei_mutex);

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1779

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +10 -0
+
+	/*
+	 * Tell CSME that we are going down so that it won't access the
+	 * memory anymore, make sure this message goes through immediately.
+	 */
+	mei->csa_throttled = false;
+	iwl_mei_send_sap_msg(mei->cldev,
+			     SAP_MSG_NOTIF_HOST_GOES_DOWN);
+
+	for (i = 0; i < 10; i++) {

Same here, a magic number.

Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +4 -0
+		if (!iwl_mei_host_to_me_data_pending(mei))
+			break;
+
+		msleep(5);

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1793

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +10 -0
+	}
+
+	/*
+	 * If we couldn't make sure that CSME saw the HOST_GOES_DOWN message,
+	 * it means that it will probably keep reading memory that we are going
+	 * to unmap and free, expect IOMMU error messages.
+	 */
+	if (i == 10)
+		dev_err(&mei->cldev->dev,
+			"Couldn't get ACK from CSME on HOST_GOES_DOWN message\n");

And here.

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1858

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +6 -0
+static struct mei_cl_device_id iwl_mei_tbl[] = {
+	{ KBUILD_MODNAME, MEI_WLAN_UUID, MEI_CL_VERSION_ANY},
+
+	/* required last entry */
+	{ }
+};

This can be const, right?

Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +4 -0
+
+/*
+ * Do not export the device table because this module is loaded by
+ * iwlwifi's dependency.

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1872

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +10 -0
+ */
+
+static struct mei_cl_driver iwl_mei_cl_driver = {
+	.id_table = iwl_mei_tbl,
+	.name = KBUILD_MODNAME,
+	.probe = iwl_mei_probe,
+	.remove = iwl_mei_remove,
+};
+
+module_mei_cl_driver(iwl_mei_cl_driver);

Not sure iwl_mei_cl_driver can be const or not, most probably not. But please do check.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Hi Kalle,

Thanks for your time!

Quoted 106 lines · Kalle Valo
Quoted 95 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.
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.

Quoted 5 lines

In this patch, I only add the iwlmei driver. Integration with iwlwifi will be implemented in the next one.

Comments for main.c:

Quoted 7 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1

Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +1 -0
@@ -0,0 +1,1872 @@
+// SPDX-License-Identifier: GPL-2.0

Someconsistency with the license within iwlwifi would be nice, I see that elsewhere in iwlwifi GPL-2.0-only is used instead of GPL-2.0:

I'll check. Thanks.

Quoted 10 lines

grep -rh SPDX * | sort | uniq --count

      4 # SPDX-License-Identifier: GPL-2.0
      6 // SPDX-License-Identifier: GPL-2.0
      1 # SPDX-License-Identifier: GPL-2.0-only
     15 /* SPDX-License-Identifier: GPL-2.0-only */
     22 // SPDX-License-Identifier: GPL-2.0-only
     73 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
     62 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
Quoted 13 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 38

Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +9 -0
+/*
+ * Since iwlwifi calls iwlmei without any context, hold a pointer to the
+ * mei_cl_device structure here.
+ * Define a mutex that will synchronize all the flows between iwlwifi and
+ * iwlmei.
+ */
+static struct mei_cl_device *iwl_mei_global_cldev;
+static DEFINE_MUTEX(iwl_mei_mutex);
+static unsigned long iwl_mei_status;

static non-const variables are frowned upon in upstream. What if there are multiple iwlwifi devices attached to the same host, how would this work then?

iwlwifi is *not* a singleton, while iwlmei is and must be. IIRC, this is mentioned
explicitly in a comment in code.
iwlmei's instance is connected to the CSME firmware which is a singleton in the system (one single chipset).

Quoted 25 lines
Quoted 25 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +24 -0
+/**
+ * iwl_mei_cache - cache for the parameters from iwlwifi
+ * @ops: Callbacks to iwlwifi.
+ * @netdev: The netdev that will be used to transmit / receive packets.
+ * @conn_info: The connection info message triggered by iwlwifi's association.
+ * @power_limit: pointer to an array of 10 elements (le16) represents the power
+ *   restrictions per chain.
+ * @rf_kill: rf kill state.
+ * @mcc: MCC info
+ * @mac_address: interface MAC address.
+ * @nvm_address: NVM MAC address.
+ * @priv: A pointer to iwlwifi.
+ *
+ * This used to cache the configurations coming from iwlwifi's way. The data
+ * is cached here so that we can buffer the configuration even if we don't have
+ * a bind from the mei bus and hence, on iwl_mei structure.
+ */
+static struct {
+     const struct iwl_mei_ops *ops;
+     struct net_device __rcu *netdev;
+     const struct iwl_sap_notif_connection_info *conn_info;
+     const __le16 *power_limit;
+     u32 rf_kill;
+     u16 mcc;
Quoted 8 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 196

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +6 -0
+     u8 mac_address[6];
+     u8 nvm_address[6];
+     void *priv;
+} iwl_mei_cache = {
+     .rf_kill = SAP_HW_RFKILL_DEASSERTED | SAP_SW_RFKILL_DEASSERTED
+};

Same here, this is also static but non-const.

Same answer.

Quoted 43 lines
Quoted 43 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +42 -0
+static void iwl_mei_handle_sap_data(struct mei_cl_device *cldev,
+                                 const u8 *q_head, u32 q_sz,
+                                 u32 rd, u32 wr, ssize_t valid_rx_sz,
+                                 struct sk_buff_head *tx_skbs)
+{
+     struct iwl_sap_hdr hdr;
+     struct net_device *netdev =
+             rcu_dereference_protected(iwl_mei_cache.netdev,
+                                       lockdep_is_held(&iwl_mei_mutex));
+
+     if (!netdev)
+             return;
+
+     while (valid_rx_sz >= sizeof(hdr)) {
+             struct ethhdr *ethhdr;
+             unsigned char *data;
+             struct sk_buff *skb;
+             u16 len;
+
+             iwl_mei_read_from_q(q_head, q_sz, &rd, wr, &hdr, sizeof(hdr));
+             valid_rx_sz -= sizeof(hdr);
+             len = le16_to_cpu(hdr.len);
+
+             if (valid_rx_sz < len) {
+                     dev_err(&cldev->dev,
+                             "Data queue is corrupted: valid data len %zd, len %d\n",
+                             valid_rx_sz, len);
+                     break;
+             }
+
+             if (len < sizeof(*ethhdr)) {
+                     dev_err(&cldev->dev,
+                             "Data len is smaller than an ethernet header? len = %d\n",
+                             len);
+             }
+
+             valid_rx_sz -= len;
+
+             if (le16_to_cpu(hdr.type) != SAP_MSG_DATA_PACKET) {
+                     dev_err(&cldev->dev, "Unsupported Rx data: type %d, len %d\n",
+                             le16_to_cpu(hdr.type), len);
+                     continue;
Quoted 8 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 991

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +6 -0
+             }
+
+             /* We need enough room for the WiFi header + SNAP + IV */
+             skb = netdev_alloc_skb(netdev, len + 26 + 8 + 8);
+
+             skb_reserve(skb, 26 + 8 + 8);

No magic numbers, please.

It is explained right above: 26 is the Wifi header etc... But you're right, I'll use defines instead.

Quoted 33 lines
Quoted 33 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +32 -0
+static void iwl_mei_remove(struct mei_cl_device *cldev)
+{
+     struct iwl_mei *mei = mei_cldev_get_drvdata(cldev);
+     int i;
+
+     /*
+      * We are being removed while the bus is active, it means we are
+      * going to suspend/ shutdown, so the NIC will disappear.
+      */
+     if (mei_cldev_enabled(cldev) && iwl_mei_cache.ops)
+             iwl_mei_cache.ops->nic_stolen(iwl_mei_cache.priv);
+
+     if (rcu_access_pointer(iwl_mei_cache.netdev)) {
+             struct net_device *dev;
+
+             /*
+              * If we are suspending and the wifi driver hasn't removed it's netdev
+              * yet, do it now. In any case, don't change the cache.netdev pointer.
+              */
+             dev = rcu_dereference_protected(iwl_mei_cache.netdev,
+                                             lockdep_is_held(&iwl_mei_mutex));
+
+             rtnl_lock();
+             netdev_rx_handler_unregister(dev);
+             rtnl_unlock();
+     }
+
+     mutex_lock(&iwl_mei_mutex);
+
+     /*
+      * Tell CSME that we are going down so that it won't access the
+      * memory anymore, make sure this message goes through immediately.
Quoted 8 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1779

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +6 -0
+      */
+     mei->csa_throttled = false;
+     iwl_mei_send_sap_msg(mei->cldev,
+                          SAP_MSG_NOTIF_HOST_GOES_DOWN);
+
+     for (i = 0; i < 10; i++) {

Same here, a magic number.

It is just a heuristic. I can add a define. Sure.

Quoted 18 lines
Quoted 5 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +4 -0
+             if (!iwl_mei_host_to_me_data_pending(mei))
+                     break;
+
+             msleep(5);

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1793

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +10 -0
+     }
+
+     /*
+      * If we couldn't make sure that CSME saw the HOST_GOES_DOWN message,
+      * it means that it will probably keep reading memory that we are going
+      * to unmap and free, expect IOMMU error messages.
+      */
+     if (i == 10)
+             dev_err(&mei->cldev->dev,
+                     "Couldn't get ACK from CSME on HOST_GOES_DOWN message\n");

And here.

Quoted 8 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1858

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +6 -0
+static struct mei_cl_device_id iwl_mei_tbl[] = {
+     { KBUILD_MODNAME, MEI_WLAN_UUID, MEI_CL_VERSION_ANY},
+
+     /* required last entry */
+     { }
+};

This can be const, right?

Yep. Thanks!

Quoted 10 lines
Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +9 -0
+
+/*
+ * Do not export the device table because this module is loaded by
+ * iwlwifi's dependency.
+ */
+
+static struct mei_cl_driver iwl_mei_cl_driver = {
+     .id_table = iwl_mei_tbl,
+     .name = KBUILD_MODNAME,
Quoted 8 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1872

Quoted 5 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +5 -0
+     .probe = iwl_mei_probe,
+     .remove = iwl_mei_remove,
+};
+
+module_mei_cl_driver(iwl_mei_cl_driver);

Not sure iwl_mei_cl_driver can be const or not, most probably not. But please do check.

I will.

Quoted 5 lines

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

#4 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +9 -0
+
+/*
+ * Do not export the device table because this module is loaded by
+ * iwlwifi's dependency.
+ */
+
+static struct mei_cl_driver iwl_mei_cl_driver = {
+     .id_table = iwl_mei_tbl,
+     .name = KBUILD_MODNAME,
Quoted 8 lines

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1872

Quoted 5 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +5 -0
+     .probe = iwl_mei_probe,
+     .remove = iwl_mei_remove,
+};
+
+module_mei_cl_driver(iwl_mei_cl_driver);

Not sure iwl_mei_cl_driver can be const or not, most probably not. But please do check.

Quoted 1 line

I will.

I can't :(

#5 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 18 lines · Emmanuel Grumbach
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +4 -0
+
+/*
+ * Do not export the device table because this module is loaded by
+ * iwlwifi's dependency.

drivers/net/wireless/intel/iwlwifi/mei/main.c line 1872

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mei/main.c new file +10 -0
+ */
+
+static struct mei_cl_driver iwl_mei_cl_driver = {
+     .id_table = iwl_mei_tbl,
+     .name = KBUILD_MODNAME,
+     .probe = iwl_mei_probe,
+     .remove = iwl_mei_remove,
+};
+
+module_mei_cl_driver(iwl_mei_cl_driver);

Not sure iwl_mei_cl_driver can be const or not, most probably not. But please do check.

Quoted 3 lines
Quoted 1 line

I will.

I can't :(

Ok, thanks for checking.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#6 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

In reply to Emmanuel Grumbach
Quoted 12 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.
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

[...]

Quoted 7 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +1 -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

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 105

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +10 -0
+	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.

I don't understand the last sentence, please elaborate. Are you saying that enabling CONFIG_IWLMEI will break wi-fi in some cases?

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 110

Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +4 -0
+	  For more information see
+	  <https://software.intel.com/en-us/manageability/>
+
+	  If unsure, say N.

IMHO the help text still contains too much Intel jargon to be really understandable by everyone. I think the commit log pretty well summarises what this is all about:

"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."

Somehow including that information to the Kconfig help text would be very helpful to everyone.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#7 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 24 lines · Kalle Valo
Quoted 12 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.
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

[...]

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +0 -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.
 
Quoted 14 lines

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 105

Quoted 11 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +11 -0
+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.

I don't understand the last sentence, please elaborate. Are you saying that enabling CONFIG_IWLMEI will break wi-fi in some cases?

Since we don't support all the devices (yet), and we haven't integrated it with all our devices, then yes, it shouldn't be enabled unless you know exactly what platform this kernel runs on. This is basically a warning for distros not to enable this kernel option (just as many others that are specific to a certain use case). The plan is to add support for more and more devices so that we will be able to remove this comment and be confident that it can be enabled on generic platforms as well.

Quoted 10 lines

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 110

Quoted 5 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +4 -0
+       For more information see
+       <https://software.intel.com/en-us/manageability/>
+
+       If unsure, say N.

IMHO the help text still contains too much Intel jargon to be really understandable by everyone. I think the commit log pretty well summarises what this is all about:

Quoted 7 lines

"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."

Somehow including that information to the Kconfig help text would be very helpful to everyone.

I'll try.

Thanks!

Quoted 5 lines

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

#8 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 40 lines · Emmanuel Grumbach
Quoted 24 lines · Kalle Valo
Quoted 12 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.
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

[...]

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +0 -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.
 
Quoted 14 lines

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 105

Quoted 11 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +11 -0
+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.

I don't understand the last sentence, please elaborate. Are you saying that enabling CONFIG_IWLMEI will break wi-fi in some cases?

Quoted 3 lines

Since we don't support all the devices (yet), and we haven't integrated it with all our devices, then yes, it shouldn't be enabled unless you know exactly what platform this kernel runs on.

So if I'm understanding correctly, enabling CONFIG_IWLMEI will break existing iwlwifi setups? Or am I missing something?

If that's the case when we have a major problem as that would be a regression. A kconfig option is not a free pass to do all sort of crazy stuff, and especially it cannot break already working hardware. That would be considered as a regression and we have a strong rule for regressions.

Quoted 5 lines

This is basically a warning for distros not to enable this kernel option (just as many others that are specific to a certain use case). The plan is to add support for more and more devices so that we will be able to remove this comment and be confident that it can be enabled on generic platforms as well.

I barely missed the warning and I consider myself as an extra careful person, I can only imagine how many regular users will enable this option without thinking twice. And people can use allmodconfig etc as well.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#9 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 43 lines
Quoted 40 lines · Emmanuel Grumbach
Quoted 38 lines · Kalle Valo
Quoted 12 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.
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

[...]

Quoted 7 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +1 -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

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 105

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +10 -0
+     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.

I don't understand the last sentence, please elaborate. Are you saying that enabling CONFIG_IWLMEI will break wi-fi in some cases?

Quoted 6 lines
Quoted 3 lines

Since we don't support all the devices (yet), and we haven't integrated it with all our devices, then yes, it shouldn't be enabled unless you know exactly what platform this kernel runs on.

So if I'm understanding correctly, enabling CONFIG_IWLMEI will break existing iwlwifi setups? Or am I missing something?

Ok, I'll share more details.
The coexistence between iwlwifi and CSME has never really been taken care of. CSME is a feature meant for enterprise and those systems typically run Windows which is why the Windows driver has had this feature for years but not Linux.
iwlmei will not do anything if you don't have CSME configured to use the WLAN device. Someone needs to actively configure CSME to use WLAN for this to happen. Very few systems have this configuration.

Now the question is what happens today (without iwlmei) when CSME is configured to use WLAN compared to what happens with iwlmei, or in other words, do we have a "regression"?

Today: there is some mechanism that allows iwlwifi to tell CSME not to touch the device. This mechanism is not very well tested because only Linux uses it and the assumption in Linux has almost always been that CSME is not configured on systems that run Linux.

with iwlmei: we will be using the same interface as windows towards CSME which is a well tested interface and we will be able to use the features that CSME provides

Why the warning then?
The integration with CSME has been done on 9260 only and not on newer devices. We do have plans to add support for more devices but the current code doesn't support
them.

What will happen if a user enables iwlmei on a system that has a post-9260 device and
CSME configured to use WLAN?
Most probably, it'll work, but this has not been tested yet

This configuration is far from the default and considered illegal by Intel at this point
I know that a user can always do something stupid, but he can likewise disable mac80211
and complain that his wifi doesn't work.

My suggestion is to add a WARNING (or an dev_err print) in iwlwifi if we detect this situation
so that it'll be very easy to catch this problem in the configuration.

The only way to prevent this situation would be to know what device the user has from iwlmei
in the mei bus enumeration but this is unfortunately not possible.

I hope that made things clearer.
I know all this is confusing, many pieces of details that I hoped I wouldn't have to bore you with :)

Quoted 20 lines

If that's the case when we have a major problem as that would be a regression. A kconfig option is not a free pass to do all sort of crazy stuff, and especially it cannot break already working hardware. That would be considered as a regression and we have a strong rule for regressions.

Quoted 5 lines

This is basically a warning for distros not to enable this kernel option (just as many others that are specific to a certain use case). The plan is to add support for more and more devices so that we will be able to remove this comment and be confident that it can be enabled on generic platforms as well.

I barely missed the warning and I consider myself as an extra careful person, I can only imagine how many regular users will enable this option without thinking twice. And people can use allmodconfig etc as well.

#10 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 50 lines · Emmanuel Grumbach
Quoted 43 lines
Quoted 40 lines · Emmanuel Grumbach
Quoted 38 lines · Kalle Valo
Quoted 12 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.
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

[...]

Quoted 7 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +1 -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

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 105

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +10 -0
+     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.

I don't understand the last sentence, please elaborate. Are you saying that enabling CONFIG_IWLMEI will break wi-fi in some cases?

Quoted 6 lines
Quoted 3 lines

Since we don't support all the devices (yet), and we haven't integrated it with all our devices, then yes, it shouldn't be enabled unless you know exactly what platform this kernel runs on.

So if I'm understanding correctly, enabling CONFIG_IWLMEI will break existing iwlwifi setups? Or am I missing something?

Quoted 8 lines

Ok, I'll share more details.
The coexistence between iwlwifi and CSME has never really been taken care of. CSME is a feature meant for enterprise and those systems typically run Windows which is why the Windows driver has had this feature for years but not Linux.
iwlmei will not do anything if you don't have CSME configured to use the WLAN device. Someone needs to actively configure CSME to use WLAN for this to happen. Very few systems have this configuration.

So in a case when CSME/AMT WLAN (or whatever the feature under discussion is called) is disabled in the BIOS and CONFIG_IWLMEI is enabled in the kernel build, iwlwifi will work as before? This is the most important part for me, we must not break people's network access when they upgrade the kernel.

Quoted 13 lines

Now the question is what happens today (without iwlmei) when CSME is configured to use WLAN compared to what happens with iwlmei, or in other words, do we have a "regression"?

Today: there is some mechanism that allows iwlwifi to tell CSME not to touch the device. This mechanism is not very well tested because only Linux uses it and the assumption in Linux has almost always been that CSME is not configured on systems that run Linux.

with iwlmei: we will be using the same interface as windows towards CSME which is a well tested interface and we will be able to use the features that CSME provides

Quoted 7 lines

Why the warning then? The integration with CSME has been done on 9260 only and not on newer devices. We do have plans to add support for more devices but the current code doesn't support them.

What will happen if a user enables iwlmei on a system that has a post-9260 device and CSME configured to use WLAN? Most probably, it'll work, but this has not been tested yet

I hope you are printing an understandable info message when CSME is enabled so that the situation is easy to notice and debug.

Quoted 4 lines

This configuration is far from the default and considered illegal by Intel at this point I know that a user can always do something stupid, but he can likewise disable mac80211 and complain that his wifi doesn't work.

A user cannot compile iwlwifi unless mac80211 is enabled and likewise iwlwifi module won't load unless mac80211 is loaded first. So we do have checks for a lot of stuff.

Quoted 3 lines

My suggestion is to add a WARNING (or an dev_err print) in iwlwifi if we detect this situation so that it'll be very easy to catch this problem in the configuration.

Heh, exactly what I was thinking above.

Quoted 6 lines

The only way to prevent this situation would be to know what device the user has from iwlmei in the mei bus enumeration but this is unfortunately not possible.

I hope that made things clearer. I know all this is confusing, many pieces of details that I hoped I wouldn't have to bore you with :)

It would have been a lot easier and faster to mention all this in the commit logs from the beginning. Dumping me patches without commit logs and no clear explanation is not really building confidence for me.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#11 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 62 lines · Kalle Valo
Quoted 50 lines · Emmanuel Grumbach
Quoted 43 lines
Quoted 40 lines · Emmanuel Grumbach
Quoted 38 lines · Kalle Valo
Quoted 12 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.
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

[...]

Quoted 7 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +1 -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

drivers/net/wireless/intel/iwlwifi/Kconfig config IWLWIFI_BCAST_FILTERING · line 105

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/Kconfig +10 -0
+     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.

I don't understand the last sentence, please elaborate. Are you saying that enabling CONFIG_IWLMEI will break wi-fi in some cases?

Quoted 6 lines
Quoted 3 lines

Since we don't support all the devices (yet), and we haven't integrated it with all our devices, then yes, it shouldn't be enabled unless you know exactly what platform this kernel runs on.

So if I'm understanding correctly, enabling CONFIG_IWLMEI will break existing iwlwifi setups? Or am I missing something?

Quoted 8 lines

Ok, I'll share more details.
The coexistence between iwlwifi and CSME has never really been taken care of. CSME is a feature meant for enterprise and those systems typically run Windows which is why the Windows driver has had this feature for years but not Linux.
iwlmei will not do anything if you don't have CSME configured to use the WLAN device. Someone needs to actively configure CSME to use WLAN for this to happen. Very few systems have this configuration.

Quoted 5 lines

So in a case when CSME/AMT WLAN (or whatever the feature under discussion is called) is disabled in the BIOS and CONFIG_IWLMEI is enabled in the kernel build, iwlwifi will work as before? This is the most important part for me, we must not break people's network access when they upgrade the kernel.

Yes.
We need another fix that is not in v7 for a bug we found in our testing, but when the user doesn't use AMT, nothing will happen even if IWLMEI is compiled.

Quoted 34 lines
Quoted 14 lines

Now the question is what happens today (without iwlmei) when CSME is configured to use WLAN compared to what happens with iwlmei, or in other words, do we have a "regression"?

Today: there is some mechanism that allows iwlwifi to tell CSME not to touch the device. This mechanism is not very well tested because only Linux uses it and the assumption in Linux has almost always been that CSME is not configured on systems that run Linux.

with iwlmei: we will be using the same interface as windows towards CSME which is a well tested interface and we will be able to use the features that CSME provides

Quoted 7 lines

Why the warning then? The integration with CSME has been done on 9260 only and not on newer devices. We do have plans to add support for more devices but the current code doesn't support them.

What will happen if a user enables iwlmei on a system that has a post-9260 device and CSME configured to use WLAN? Most probably, it'll work, but this has not been tested yet

I hope you are printing an understandable info message when CSME is enabled so that the situation is easy to notice and debug.

Quoted 4 lines

This configuration is far from the default and considered illegal by Intel at this point I know that a user can always do something stupid, but he can likewise disable mac80211 and complain that his wifi doesn't work.

A user cannot compile iwlwifi unless mac80211 is enabled and likewise iwlwifi module won't load unless mac80211 is loaded first. So we do have checks for a lot of stuff.

Quoted 5 lines
Quoted 3 lines

My suggestion is to add a WARNING (or an dev_err print) in iwlwifi if we detect this situation so that it'll be very easy to catch this problem in the configuration.

Heh, exactly what I was thinking above.

No problem. I'll do that.
Our testing teams are right now working on testing more devices.

Quoted 5 lines
Quoted 5 lines

The only way to prevent this situation would be to know what device the user has from iwlmei in the mei bus enumeration but this is unfortunately not possible.

Quoted 7 lines
Quoted 2 lines

I hope that made things clearer. I know all this is confusing, many pieces of details that I hoped I wouldn't have to bore you with :)

It would have been a lot easier and faster to mention all this in the commit logs from the beginning. Dumping me patches without commit logs and no clear explanation is not really building confidence for me.

I understand. There are loads of details and I didn't really want to bother you with all of them, I guess I now know that you are the type of person who want the details and I'll be clearer the next time.

Practically speaking, I owe you a v8 with the WARNING I mentioned plus the bugfix
I talked about.

Do you want it now or you want me to wait for more comments?

#12 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 16 lines · Emmanuel Grumbach
Quoted 15 lines · Kalle Valo
Quoted 11 lines · Emmanuel Grumbach
Quoted 2 lines

So if I'm understanding correctly, enabling CONFIG_IWLMEI will break existing iwlwifi setups? Or am I missing something?

Ok, I'll share more details.
The coexistence between iwlwifi and CSME has never really been taken care of. CSME is a feature meant for enterprise and those systems typically run Windows which is why the Windows driver has had this feature for years but not Linux.
iwlmei will not do anything if you don't have CSME configured to use the WLAN device. Someone needs to actively configure CSME to use WLAN for this to happen. Very few systems have this configuration.

Quoted 7 lines
Quoted 5 lines

So in a case when CSME/AMT WLAN (or whatever the feature under discussion is called) is disabled in the BIOS and CONFIG_IWLMEI is enabled in the kernel build, iwlwifi will work as before? This is the most important part for me, we must not break people's network access when they upgrade the kernel.

Yes.

Very good, this is most important for me.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

The only way to prevent this situation would be to know what device the user has from iwlmei in the mei bus enumeration but this is unfortunately not possible.

I hope that made things clearer. I know all this is confusing, many pieces of details that I hoped I wouldn't have to bore you with :)

Quoted 8 lines
Quoted 4 lines

It would have been a lot easier and faster to mention all this in the commit logs from the beginning. Dumping me patches without commit logs and no clear explanation is not really building confidence for me.

I understand. There are loads of details and I didn't really want to bother you with all of them, I guess I now know that you are the type of person who want the details and I'll be clearer the next time.

It's really comes down to trusting the patches, if I don't even understand what the patches do I will have a hard time trusting them.

Quoted 4 lines

Practically speaking, I owe you a v8 with the WARNING I mentioned plus the bugfix I talked about.

Do you want it now or you want me to wait for more comments?

I'm not planning to review v7 anymore, so please do submit v8.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#13 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

In reply to Emmanuel Grumbach
Quoted 95 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.
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.

Quoted 5 lines

In this patch, I only add the iwlmei driver. Integration with iwlwifi will be implemented in the next one.

s-o-b missing from Ayala, same problem also in other patches in this patchset.

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#when-to-use-acked-by-cc-and-co-developed-by

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#14 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 101 lines · Kalle Valo
Quoted 98 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.
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.

Quoted 8 lines
Quoted 2 lines

s-o-b missing from Ayala, same problem also in other patches in this patchset.

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#when-to-use-acked-by-cc-and-co-developed-by

I fixed all the comments and pushed to a branch in our tree to get a 0-day run on it.
One question though: there is currently a (small) diff between iwlwifi-next and wireless-driver-next that makes this series conflict. This is because of a fix that was applied on wireless-drivers-next directly and Luca hasn't merged your tree back to his yet.
I can send v7 on either code base you like.
I think 0-day tests iwlwifi patches against iwlwifi-next but I am not sure. Luca is on vacation until next week.

Any option you'll choose will be fine by me. Just let me know.

#15 lore raw

Re: [PATCH v6 2/7] iwlwifi: mei: add the driver to allow cooperation with CSME

Quoted 122 lines · Emmanuel Grumbach
Quoted 101 lines · Kalle Valo
Quoted 98 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.
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.

Quoted 8 lines
Quoted 2 lines

s-o-b missing from Ayala, same problem also in other patches in this patchset.

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#when-to-use-acked-by-cc-and-co-developed-by

I fixed all the comments and pushed to a branch in our tree to get a 0-day run on it.
One question though: there is currently a (small) diff between iwlwifi-next and wireless-driver-next that makes this series conflict. This is because of a fix that was applied on wireless-drivers-next directly and Luca hasn't merged your tree back to his yet.
I can send v7 on either code base you like.
I think 0-day tests iwlwifi patches against iwlwifi-next but I am not sure. Luca is on vacation until next week.

Quoted 1 line

Any option you'll choose will be fine by me. Just let me know.

The build was successful and I tested the changes, they work. Did you plan to apply this before the merge window? If yes, I'll rebase on top of your -next tree and send v7.

#16 lore raw

PATCH v6 3/7 iwlwifi: mei: add debugfs hooks

In reply to Emmanuel Grumbach

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).

---
 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
index fb154a424fd6..f1998e2132ba 100644
@@ -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;
 };
 
 /**
@@ -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);
Signature · 1 line
2.25.1
#17 lore raw

PATCH v6 4/7 iwlwifi: integrate with iwlmei

In reply to Emmanuel Grumbach

iwlmei 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
index 850648ebd61c..4c2817c94d05 100644
@@ -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
index e1f5a9741850..e01f7751cf11 100644
@@ -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
index 0199d7a5a648..942c6f3f8d3f 100644
@@ -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
index 38fd5886af2d..36ccfa302406 100644
@@ -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
index 32b4d1935788..e34b82b2a288 100644
@@ -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
index 0a13c2bda2ee..5965defc37e8 100644
@@ -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
index 16baee3d52ae..863c10e602d5 100644
@@ -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
index bee6b4574226..86a8448ce86a 100644
@@ -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
#18 lore raw

Re: [PATCH v6 4/7] iwlwifi: integrate with iwlmei

Quoted 26 lines · Emmanuel Grumbach

iwlmei 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.

[...]

Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +0 -0
@@ -1932,6 +1952,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);
 

drivers/net/wireless/intel/iwlwifi/mvm/mvm.h void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm); · line 1964

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +10 -0
+#ifdef CONFIG_IWLMVM_VENDOR_CMDS
+
+/* vendor commands */
+void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm);
+
+#else // IWLMVM_VENDOR_CMDS
+
+static inline void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm) {}
+
+#endif // IWLMVM_VENDOR_CMDS

Shouldn't this be in patch 6?

And no C++ style comments, please.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#19 lore raw

PATCH v6 5/7 nl80211: vendor-cmd: add Intel vendor commands for iwlmei usage

In reply to Emmanuel Grumbach

iwlmei 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
new file mode 100644
index 000000000000..0bf177b84fd9
@@ -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
#20 lore raw

Re: [PATCH v6 5/7] nl80211: vendor-cmd: add Intel vendor commands for iwlmei usage

Quoted 17 lines · Emmanuel Grumbach

iwlmei 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.

[...]

Quoted 18 lines
include/uapi/linux/nl80211-vnd-intel.h new file +15 -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.

include/uapi/linux/nl80211-vnd-intel.h line 25

Quoted 10 lines
include/uapi/linux/nl80211-vnd-intel.h new file +10 -0
+ * @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,
+};

If I were trying to implement a user space application based on the documentation in nl80211-vnd-intel.h I would not get far. For example, how is IWL_MVM_VENDOR_CMD_HOST_GET_OWNERSHIP supposed to be used? The documentation just repeats what the command already implies.

You had some good info in the commit log, I recommend at least copying the most important part to the .h file.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#21 lore raw

Re: [PATCH v6 5/7] nl80211: vendor-cmd: add Intel vendor commands for iwlmei usage

Quoted 54 lines
Quoted 17 lines

iwlmei 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.

[...]

Quoted 18 lines
include/uapi/linux/nl80211-vnd-intel.h new file +15 -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.

include/uapi/linux/nl80211-vnd-intel.h line 25

Quoted 10 lines
include/uapi/linux/nl80211-vnd-intel.h new file +10 -0
+ * @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,
+};

If I were trying to implement a user space application based on the documentation in nl80211-vnd-intel.h I would not get far. For example, how is IWL_MVM_VENDOR_CMD_HOST_GET_OWNERSHIP supposed to be used? The documentation just repeats what the command already implies.

Quoted 2 lines

You had some good info in the commit log, I recommend at least copying the most important part to the .h file.

Ok, this patch has already been merged by Johannes, but I'll add a new patch to add more info.

#22 lore raw

PATCH v6 6/7 iwlwifi: mvm: add vendor commands needed for iwlmei

In reply to Emmanuel Grumbach

Add 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

---
 .../net/wireless/intel/iwlwifi/mvm/Makefile   |   1 +
 .../net/wireless/intel/iwlwifi/mvm/mac80211.c |   2 +
 drivers/net/wireless/intel/iwlwifi/mvm/mvm.h  |  15 +-
 .../wireless/intel/iwlwifi/mvm/vendor-cmd.c   | 176 ++++++++++++++++++
 4 files changed, 185 insertions(+), 9 deletions(-)
 create mode 100644 drivers/net/wireless/intel/iwlwifi/mvm/vendor-cmd.c
drivers/net/wireless/intel/iwlwifi/mvm/Makefile +1 -0
index 75fc2d935e5d..11e814b7cad0 100644
@@ -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
index 6c446dbb04bc..463af179f439 100644
@@ -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 +6 -9
index e5b369e5874a..402851ba9565 100644
@@ -1952,16 +1952,16 @@ 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);
 
-#ifdef CONFIG_IWLMVM_VENDOR_CMDS
+#if IS_ENABLED(CONFIG_IWLMEI)
 
 /* vendor commands */
 void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm);
 
-#else // IWLMVM_VENDOR_CMDS
+#else // CONFIG_IWLMEI
 
 static inline void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm) {}
 
-#endif // IWLMVM_VENDOR_CMDS
+#endif // CONFIG_IWLMEI
 
 /* Location Aware Regulatory */
 struct iwl_mcc_update_resp *
@@ -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 +176 -0

176 lines not on this page · raw message

Signature · 1 line
2.25.1
#23 lore raw

Re: [PATCH v6 6/7] iwlwifi: mvm: add vendor commands needed for iwlmei

Quoted 9 lines · Emmanuel Grumbach

Add 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

[...]

Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +1 -1
@@ -1952,16 +1952,16 @@ 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);
 
-#ifdef CONFIG_IWLMVM_VENDOR_CMDS
+#if IS_ENABLED(CONFIG_IWLMEI)
 

drivers/net/wireless/intel/iwlwifi/mvm/mvm.h void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm); · line 1964

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +2 -2
 /* vendor commands */
 void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm);
 
-#else // IWLMVM_VENDOR_CMDS
+#else // CONFIG_IWLMEI
 
 static inline void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm) {}
 
-#endif // IWLMVM_VENDOR_CMDS
+#endif // CONFIG_IWLMEI

No C++ style comments, please.

Quoted 36 lines
drivers/net/wireless/intel/iwlwifi/mvm/vendor-cmd.c new file +33 -0
@@ -0,0 +1,176 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2012-2014, 2018-2021 Intel Corporation
+ * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
+ * Copyright (C) 2016-2017 Intel Deutschland GmbH
+ */
+#include "mvm.h"
+#include <linux/nl80211-vnd-intel.h>
+
+static const struct nla_policy
+iwl_mvm_vendor_attr_policy[NUM_IWL_MVM_VENDOR_ATTR] = {
+	[IWL_MVM_VENDOR_ATTR_ROAMING_FORBIDDEN] = { .type = NLA_U8 },
+	[IWL_MVM_VENDOR_ATTR_AUTH_MODE] = { .type = NLA_U32 },
+	[IWL_MVM_VENDOR_ATTR_CHANNEL_NUM] = { .type = NLA_U8 },
+	[IWL_MVM_VENDOR_ATTR_SSID] = { .type = NLA_BINARY,
+				       .len = IEEE80211_MAX_SSID_LEN },
+	[IWL_MVM_VENDOR_ATTR_BAND] = { .type = NLA_U8 },
+	[IWL_MVM_VENDOR_ATTR_COLLOC_CHANNEL] = { .type = NLA_U8 },
+	[IWL_MVM_VENDOR_ATTR_COLLOC_ADDR] = { .type = NLA_BINARY, .len = ETH_ALEN },
+};
+
+__maybe_unused static struct nlattr **
+iwl_mvm_parse_vendor_data(const void *data, int data_len)
+{
+	struct nlattr **tb;
+	int err;
+
+	if (!data)
+		return ERR_PTR(-EINVAL);
+
+	tb = kcalloc(MAX_IWL_MVM_VENDOR_ATTR + 1, sizeof(*tb), GFP_KERNEL);
+	if (!tb)
+		return ERR_PTR(-ENOMEM);

drivers/net/wireless/intel/iwlwifi/mvm/vendor-cmd.c line 43

Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mvm/vendor-cmd.c new file +10 -0
+
+	err = nla_parse(tb, MAX_IWL_MVM_VENDOR_ATTR, data, data_len,
+			iwl_mvm_vendor_attr_policy, NULL);
+	if (err) {
+		kfree(tb);
+		return ERR_PTR(err);
+	}
+
+	return tb;
+}

I was wondering why you had __maybe_unused but when noticed you are not really using this function anywhere. So why not just remove it?

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#24 lore raw

PATCH v6 7/7 iwlwifi: mvm: read the rfkill state and feed it to iwlmei

In reply to Emmanuel Grumbach

Remove 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
index 463af179f439..48d3253a3f50 100644
@@ -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
index 402851ba9565..d33ff9ab71b0 100644
@@ -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
index 9898e1a72c7c..98ea986d75f5 100644
@@ -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
#25 lore raw

Re: [PATCH v6 7/7] iwlwifi: mvm: read the rfkill state and feed it to iwlmei

Quoted 1 line · Emmanuel Grumbach

Remove the corresponding vendor command as well.

What vendor command? I don't get it.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#26 lore raw

Re: [PATCH v6 7/7] iwlwifi: mvm: read the rfkill state and feed it to iwlmei

Emmanuel Grumbach
[email protected]

Quoted 7 lines · Kalle Valo
Quoted 1 line · Emmanuel Grumbach

Remove the corresponding vendor command as well.

What vendor command? I don't get it.

Compared to a previous version that I sent... Sorry, this was confusing. I'll change the commit message.
This commit message was relevant for our internal tree, but not suitable for the upstream code base.
Will change.