xref: /openbmc/linux/drivers/net/wireless/intel/iwlwifi/mei/iwl-mei.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
19ad28ba1STom Rix /* SPDX-License-Identifier: GPL-2.0-only */
22da4366fSEmmanuel Grumbach /*
3*22b68fc6SAvraham Stern  * Copyright (C) 2021 - 2022 Intel Corporation
42da4366fSEmmanuel Grumbach  */
52da4366fSEmmanuel Grumbach 
62da4366fSEmmanuel Grumbach #ifndef __iwl_mei_h__
72da4366fSEmmanuel Grumbach #define __iwl_mei_h__
82da4366fSEmmanuel Grumbach 
92da4366fSEmmanuel Grumbach #include <linux/if_ether.h>
102da4366fSEmmanuel Grumbach #include <linux/skbuff.h>
112da4366fSEmmanuel Grumbach #include <linux/ieee80211.h>
122da4366fSEmmanuel Grumbach 
132da4366fSEmmanuel Grumbach /**
142da4366fSEmmanuel Grumbach  * DOC: Introduction
152da4366fSEmmanuel Grumbach  *
169ad28ba1STom Rix  * iwlmei is the kernel module that is in charge of the communication between
172da4366fSEmmanuel Grumbach  * the iwlwifi driver and the CSME firmware's WLAN driver. This communication
182da4366fSEmmanuel Grumbach  * uses the SAP protocol defined in another file.
192da4366fSEmmanuel Grumbach  * iwlwifi can request or release ownership on the WiFi device through iwlmei.
202da4366fSEmmanuel Grumbach  * iwlmei may notify iwlwifi about certain events: what filter iwlwifi should
212da4366fSEmmanuel Grumbach  * use to passthrough inbound packets to the CSME firmware for example. iwlmei
222da4366fSEmmanuel Grumbach  * may also use iwlwifi to send traffic. This means that we need communication
232da4366fSEmmanuel Grumbach  * from iwlmei to iwlwifi and the other way around.
242da4366fSEmmanuel Grumbach  */
252da4366fSEmmanuel Grumbach 
262da4366fSEmmanuel Grumbach /**
272da4366fSEmmanuel Grumbach  * DOC: Life cycle
282da4366fSEmmanuel Grumbach  *
292da4366fSEmmanuel Grumbach  * iwlmei exports symbols that are needed by iwlwifi so that iwlmei will always
302da4366fSEmmanuel Grumbach  * be loaded when iwlwifi is alive. iwlwifi registers itself to iwlmei and
312da4366fSEmmanuel Grumbach  * provides the pointers to the functions that iwlmei calls whenever needed.
322da4366fSEmmanuel Grumbach  * iwlwifi calls iwlmei through direct and context-free function calls.
332da4366fSEmmanuel Grumbach  * It is assumed that only one device is accessible to the CSME firmware and
342da4366fSEmmanuel Grumbach  * under the scope of iwlmei so that it is valid not to have any context passed
352da4366fSEmmanuel Grumbach  * to iwlmei's functions.
362da4366fSEmmanuel Grumbach  *
372da4366fSEmmanuel Grumbach  * There are cases in which iwlmei can't access the CSME firmware, because the
382da4366fSEmmanuel Grumbach  * CSME firmware is undergoing a reset, or the mei bus decided to unbind the
392da4366fSEmmanuel Grumbach  * device. In those cases, iwlmei will need not to send requests over the mei
402da4366fSEmmanuel Grumbach  * bus. Instead, it needs to cache the requests from iwlwifi and fulfill them
412da4366fSEmmanuel Grumbach  * when the mei bus is available again.
422da4366fSEmmanuel Grumbach  *
432da4366fSEmmanuel Grumbach  * iwlmei can call iwlwifi as long as iwlwifi is registered to iwlmei. When
442da4366fSEmmanuel Grumbach  * iwlwifi goes down (the PCI device is unbound, or the iwlwifi is unloaded)
452da4366fSEmmanuel Grumbach  * iwlwifi needs to unregister from iwlmei.
462da4366fSEmmanuel Grumbach  */
472da4366fSEmmanuel Grumbach 
482da4366fSEmmanuel Grumbach /**
492da4366fSEmmanuel Grumbach  * DOC: Memory layout
502da4366fSEmmanuel Grumbach  *
512da4366fSEmmanuel Grumbach  * Since iwlwifi calls iwlmei without any context, iwlmei needs to hold a
522da4366fSEmmanuel Grumbach  * global pointer to its data (which is in the mei client device's private
532da4366fSEmmanuel Grumbach  * data area). If there was no bind on the mei bus, this pointer is NULL and
542da4366fSEmmanuel Grumbach  * iwlmei knows not access to the CSME firmware upon requests from iwlwifi.
552da4366fSEmmanuel Grumbach  *
562da4366fSEmmanuel Grumbach  * iwlmei needs to cache requests from iwlwifi when there is no mei client
572da4366fSEmmanuel Grumbach  * device available (when iwlmei has been removed from the mei bus). In this
582da4366fSEmmanuel Grumbach  * case, all iwlmei's data that resides in the mei client device's private data
592da4366fSEmmanuel Grumbach  * area is unavailable. For this specific case, a separate caching area is
602da4366fSEmmanuel Grumbach  * needed.
612da4366fSEmmanuel Grumbach  */
622da4366fSEmmanuel Grumbach 
632da4366fSEmmanuel Grumbach /**
642da4366fSEmmanuel Grumbach  * DOC: Concurrency
652da4366fSEmmanuel Grumbach  *
662da4366fSEmmanuel Grumbach  * iwlwifi can call iwlmei at any time. iwlmei will take care to synchronize
672da4366fSEmmanuel Grumbach  * the calls from iwlwifi with its internal flows. iwlwifi must not call iwlmei
682da4366fSEmmanuel Grumbach  * in flows that cannot sleep. Moreover, iwlwifi must not call iwlmei in flows
692da4366fSEmmanuel Grumbach  * that originated from iwlmei.
702da4366fSEmmanuel Grumbach  */
712da4366fSEmmanuel Grumbach 
722da4366fSEmmanuel Grumbach /**
732da4366fSEmmanuel Grumbach  * DOC: Probe and remove from mei bus driver
742da4366fSEmmanuel Grumbach  *
752da4366fSEmmanuel Grumbach  * When the mei bus driver enumerates its devices, it calls the iwlmei's probe
762da4366fSEmmanuel Grumbach  * function which will send the %SAP_ME_MSG_START message. The probe completes
772da4366fSEmmanuel Grumbach  * before the response (%SAP_ME_MSG_START_OK) is received. This response will
782da4366fSEmmanuel Grumbach  * be handle by the Rx path. Once it arrives, the connection to the CSME
792da4366fSEmmanuel Grumbach  * firmware is considered established and iwlwifi's requests can be treated
802da4366fSEmmanuel Grumbach  * against the CSME firmware.
812da4366fSEmmanuel Grumbach  *
822da4366fSEmmanuel Grumbach  * When the mei bus driver removes the device, iwlmei loses all the data that
832da4366fSEmmanuel Grumbach  * was attached to the mei client device. It clears the global pointer to the
842da4366fSEmmanuel Grumbach  * mei client device since it is not available anymore. This will cause all the
852da4366fSEmmanuel Grumbach  * requests coming from iwlwifi to be cached. This flow takes the global mutex
862da4366fSEmmanuel Grumbach  * to be synchronized with all the requests coming from iwlwifi.
872da4366fSEmmanuel Grumbach  */
882da4366fSEmmanuel Grumbach 
892da4366fSEmmanuel Grumbach /**
902da4366fSEmmanuel Grumbach  * DOC: Driver load when CSME owns the device
912da4366fSEmmanuel Grumbach  *
922da4366fSEmmanuel Grumbach  * When the driver (iwlwifi) is loaded while CSME owns the device,
932da4366fSEmmanuel Grumbach  * it'll ask CSME to release the device through HW registers. CSME
942da4366fSEmmanuel Grumbach  * will release the device only in the case that there is no connection
952da4366fSEmmanuel Grumbach  * through the mei bus. If there is a mei bus connection, CSME will refuse
962da4366fSEmmanuel Grumbach  * to release the ownership on the device through the HW registers. In that
972da4366fSEmmanuel Grumbach  * case, iwlwifi must first request ownership using the SAP protocol.
982da4366fSEmmanuel Grumbach  *
992da4366fSEmmanuel Grumbach  * Once iwlwifi will request ownership through the SAP protocol, CSME will
1002da4366fSEmmanuel Grumbach  * grant the ownership on the device through the HW registers as well.
1012da4366fSEmmanuel Grumbach  * In order to request ownership over SAP, we first need to have an interface
1022da4366fSEmmanuel Grumbach  * which means that we need to register to mac80211.
1032da4366fSEmmanuel Grumbach  * This can't happen before we get the NVM that contains all the capabilities
1042da4366fSEmmanuel Grumbach  * of the device. Reading the NVM usually requires the load the firmware, but
1052da4366fSEmmanuel Grumbach  * this is impossible as long as we don't have ownership on the device.
1062da4366fSEmmanuel Grumbach  * In order to solve this chicken and egg problem, the host driver can get
1072da4366fSEmmanuel Grumbach  * the NVM through CSME which owns the device. It can send
1082da4366fSEmmanuel Grumbach  * %SAP_MSG_NOTIF_GET_NVM, which will be replied by %SAP_MSG_NOTIF_NVM with
1092da4366fSEmmanuel Grumbach  * the NVM's content that the host driver needs.
1102da4366fSEmmanuel Grumbach  */
1112da4366fSEmmanuel Grumbach 
1122da4366fSEmmanuel Grumbach /**
1132da4366fSEmmanuel Grumbach  * DOC: CSME behavior regarding the ownership requests
1142da4366fSEmmanuel Grumbach  *
1152da4366fSEmmanuel Grumbach  * The ownership requests from the host can come in two different ways:
1162da4366fSEmmanuel Grumbach  *  - the HW registers in iwl_pcie_set_hw_ready
1172da4366fSEmmanuel Grumbach  *  - using the Software Arbitration Protocol (SAP)
1182da4366fSEmmanuel Grumbach  *
1192da4366fSEmmanuel Grumbach  * The host can ask CSME who owns the device with %SAP_MSG_NOTIF_WHO_OWNS_NIC,
1202da4366fSEmmanuel Grumbach  * and it can request ownership with %SAP_MSG_NOTIF_HOST_ASKS_FOR_NIC_OWNERSHIP.
1212da4366fSEmmanuel Grumbach  * The host will first use %SAP_MSG_NOTIF_WHO_OWNS_NIC to know what state
1222da4366fSEmmanuel Grumbach  * CSME is in. In case CSME thinks it owns the device, the host can ask for
1232da4366fSEmmanuel Grumbach  * ownership with %SAP_MSG_NOTIF_HOST_ASKS_FOR_NIC_OWNERSHIP.
1242da4366fSEmmanuel Grumbach  *
1252da4366fSEmmanuel Grumbach  * Here the table that describes CSME's behavior upon ownership request:
1262da4366fSEmmanuel Grumbach  *
1272da4366fSEmmanuel Grumbach  * +-------------------+------------+--------------+-----------------------------+------------+
1282da4366fSEmmanuel Grumbach  * | State             | HW reg bit | Reply for    | Event                       | HW reg bit |
1292da4366fSEmmanuel Grumbach  * |                   | before     | WHO_OWNS_NIC |                             | after      |
1302da4366fSEmmanuel Grumbach  * +===================+============+==============+=============================+============+
1312da4366fSEmmanuel Grumbach  * | WiAMT not         | 0          | Host         | HW register or              | 0          |
1322da4366fSEmmanuel Grumbach  * | operational       | Host owner |              | HOST_ASKS_FOR_NIC_OWNERSHIP | Host owner |
1332da4366fSEmmanuel Grumbach  * +-------------------+------------+--------------+-----------------------------+------------+
1342da4366fSEmmanuel Grumbach  * | Operational &     | 1          | N/A          | HW register                 | 0          |
1352da4366fSEmmanuel Grumbach  * | SAP down &        | CSME owner |              |                             | Host owner |
1362da4366fSEmmanuel Grumbach  * | no session active |            |              |                             |            |
1372da4366fSEmmanuel Grumbach  * +-------------------+------------+--------------+-----------------------------+------------+
1382da4366fSEmmanuel Grumbach  * | Operational &     | 1          | CSME         | HW register                 | 1          |
1392da4366fSEmmanuel Grumbach  * | SAP up            | CSME owner |              |                             | CSME owner |
1402da4366fSEmmanuel Grumbach  * +-------------------+------------+--------------+-----------------------------+------------+
1412da4366fSEmmanuel Grumbach  * | Operational &     | 1          | CSME         | HOST_ASKS_FOR_NIC_OWNERSHIP | 0          |
1422da4366fSEmmanuel Grumbach  * | SAP up            | CSME owner |              |                             | Host owner |
1432da4366fSEmmanuel Grumbach  * +-------------------+------------+--------------+-----------------------------+------------+
1442da4366fSEmmanuel Grumbach  */
1452da4366fSEmmanuel Grumbach 
1462da4366fSEmmanuel Grumbach /**
1472da4366fSEmmanuel Grumbach  * DOC: Driver load when CSME is associated and a session is active
1482da4366fSEmmanuel Grumbach  *
1492da4366fSEmmanuel Grumbach  * A "session" is active when CSME is associated to an access point and the
1502da4366fSEmmanuel Grumbach  * link is used to attach a remote driver or to control the system remotely.
1512da4366fSEmmanuel Grumbach  * When a session is active, we want to make sure it won't disconnect when we
1522da4366fSEmmanuel Grumbach  * take ownership on the device.
1532da4366fSEmmanuel Grumbach  * In this case, the driver can get the device, but it'll need to make
1542da4366fSEmmanuel Grumbach  * sure that it'll connect to the exact same AP (same BSSID).
1552da4366fSEmmanuel Grumbach  * In order to do so, CSME will send the connection parameters through
1562da4366fSEmmanuel Grumbach  * SAP and then the host can check if it can connect to this same AP.
1572da4366fSEmmanuel Grumbach  * If yes, it can request ownership through SAP and connect quickly without
1582da4366fSEmmanuel Grumbach  * scanning all the channels, but just probing the AP on the channel that
1592da4366fSEmmanuel Grumbach  * CSME was connected to.
1602da4366fSEmmanuel Grumbach  * In order to signal this specific scenario to iwlwifi, iwlmei will
1612da4366fSEmmanuel Grumbach  * immediately require iwlwifi to report RF-Kill to the network stack. This
1622da4366fSEmmanuel Grumbach  * RF-Kill will prevent the stack from getting the device, and it has a reason
1632da4366fSEmmanuel Grumbach  * that tells the userspace that the device is in RF-Kill because it is not
1642da4366fSEmmanuel Grumbach  * owned by the host. Once the userspace has configured the right profile,
1652da4366fSEmmanuel Grumbach  * it'll be able to let iwlmei know that it can request ownership over SAP
1662da4366fSEmmanuel Grumbach  * which will remove the RF-Kill, and finally allow the host to connect.
1672da4366fSEmmanuel Grumbach  * The host has then 3 seconds to connect (including DHCP). Had the host
1682da4366fSEmmanuel Grumbach  * failed to connect within those 3 seconds, CSME will take the device back.
1692da4366fSEmmanuel Grumbach  */
1702da4366fSEmmanuel Grumbach 
1712da4366fSEmmanuel Grumbach /**
1722da4366fSEmmanuel Grumbach  * DOC: Datapath
1732da4366fSEmmanuel Grumbach  *
1742da4366fSEmmanuel Grumbach  * CSME can transmit packets, through the netdev that it gets from the wifi
1752da4366fSEmmanuel Grumbach  * driver. It'll send packet in the 802.3 format and simply call
1762da4366fSEmmanuel Grumbach  * dev_queue_xmit.
1772da4366fSEmmanuel Grumbach  *
1782da4366fSEmmanuel Grumbach  * For Rx, iwlmei registers a Rx handler that it attaches to the netdev. iwlmei
1792da4366fSEmmanuel Grumbach  * may catch packets and send them to CSME, it can then either drop them so
1802da4366fSEmmanuel Grumbach  * that they are invisible to user space, or let them go the user space.
1812da4366fSEmmanuel Grumbach  *
1822da4366fSEmmanuel Grumbach  * Packets transmitted by the user space do not need to be forwarded to CSME
1832da4366fSEmmanuel Grumbach  * with the exception of the DHCP request. In order to know what IP is used
1842da4366fSEmmanuel Grumbach  * by the user space, CSME needs to get the DHCP request. See
1852da4366fSEmmanuel Grumbach  * iwl_mei_tx_copy_to_csme().
1862da4366fSEmmanuel Grumbach  */
1872da4366fSEmmanuel Grumbach 
1882da4366fSEmmanuel Grumbach /**
1892da4366fSEmmanuel Grumbach  * enum iwl_mei_nvm_caps - capabilities for MEI NVM
1902da4366fSEmmanuel Grumbach  * @MEI_NVM_CAPS_LARI_SUPPORT: Lari is supported
1912da4366fSEmmanuel Grumbach  * @MEI_NVM_CAPS_11AX_SUPPORT: 11AX is supported
1922da4366fSEmmanuel Grumbach  */
1932da4366fSEmmanuel Grumbach enum iwl_mei_nvm_caps {
1942da4366fSEmmanuel Grumbach 	MEI_NVM_CAPS_LARI_SUPPORT	= BIT(0),
1952da4366fSEmmanuel Grumbach 	MEI_NVM_CAPS_11AX_SUPPORT	= BIT(1),
1962da4366fSEmmanuel Grumbach };
1972da4366fSEmmanuel Grumbach 
1982da4366fSEmmanuel Grumbach /**
1992da4366fSEmmanuel Grumbach  * struct iwl_mei_nvm - used to pass the NVM from CSME
2002da4366fSEmmanuel Grumbach  * @hw_addr: The MAC address
2012da4366fSEmmanuel Grumbach  * @n_hw_addrs: The number of MAC addresses
2022da4366fSEmmanuel Grumbach  * @reserved: For alignment.
2032da4366fSEmmanuel Grumbach  * @radio_cfg: The radio configuration.
2042da4366fSEmmanuel Grumbach  * @caps: See &enum iwl_mei_nvm_caps.
2052da4366fSEmmanuel Grumbach  * @nvm_version: The version of the NVM.
2062da4366fSEmmanuel Grumbach  * @channels: The data for each channel.
2072da4366fSEmmanuel Grumbach  *
2082da4366fSEmmanuel Grumbach  * If a field is added, it must correspond to the SAP structure.
2092da4366fSEmmanuel Grumbach  */
2102da4366fSEmmanuel Grumbach struct iwl_mei_nvm {
2112da4366fSEmmanuel Grumbach 	u8 hw_addr[ETH_ALEN];
2122da4366fSEmmanuel Grumbach 	u8 n_hw_addrs;
2132da4366fSEmmanuel Grumbach 	u8 reserved;
2142da4366fSEmmanuel Grumbach 	u32 radio_cfg;
2152da4366fSEmmanuel Grumbach 	u32 caps;
2162da4366fSEmmanuel Grumbach 	u32 nvm_version;
2172da4366fSEmmanuel Grumbach 	u32 channels[110];
2182da4366fSEmmanuel Grumbach };
2192da4366fSEmmanuel Grumbach 
2202da4366fSEmmanuel Grumbach /**
2212da4366fSEmmanuel Grumbach  * enum iwl_mei_pairwise_cipher - cipher for UCAST key
2222da4366fSEmmanuel Grumbach  * @IWL_MEI_CIPHER_NONE: none
223e5d3a64eSAvraham Stern  * @IWL_MEI_CIPHER_TKIP: tkip
2242da4366fSEmmanuel Grumbach  * @IWL_MEI_CIPHER_CCMP: ccmp
2252da4366fSEmmanuel Grumbach  * @IWL_MEI_CIPHER_GCMP: gcmp
2262da4366fSEmmanuel Grumbach  * @IWL_MEI_CIPHER_GCMP_256: gcmp 256
2272da4366fSEmmanuel Grumbach  *
2282da4366fSEmmanuel Grumbach  * Note that those values are dictated by the CSME firmware API (see sap.h)
2292da4366fSEmmanuel Grumbach  */
2302da4366fSEmmanuel Grumbach enum iwl_mei_pairwise_cipher {
2312da4366fSEmmanuel Grumbach 	IWL_MEI_CIPHER_NONE	= 0,
232e5d3a64eSAvraham Stern 	IWL_MEI_CIPHER_TKIP	= 2,
2332da4366fSEmmanuel Grumbach 	IWL_MEI_CIPHER_CCMP	= 4,
2342da4366fSEmmanuel Grumbach 	IWL_MEI_CIPHER_GCMP	= 8,
2352da4366fSEmmanuel Grumbach 	IWL_MEI_CIPHER_GCMP_256 = 9,
2362da4366fSEmmanuel Grumbach };
2372da4366fSEmmanuel Grumbach 
2382da4366fSEmmanuel Grumbach /**
2392da4366fSEmmanuel Grumbach  * enum iwl_mei_akm_auth - a combination of AKM and AUTH method
2402da4366fSEmmanuel Grumbach  * @IWL_MEI_AKM_AUTH_OPEN: No encryption
2412da4366fSEmmanuel Grumbach  * @IWL_MEI_AKM_AUTH_RSNA: 1X profile
2422da4366fSEmmanuel Grumbach  * @IWL_MEI_AKM_AUTH_RSNA_PSK: PSK profile
2432da4366fSEmmanuel Grumbach  * @IWL_MEI_AKM_AUTH_SAE: SAE profile
2442da4366fSEmmanuel Grumbach  *
2452da4366fSEmmanuel Grumbach  * Note that those values are dictated by the CSME firmware API (see sap.h)
2462da4366fSEmmanuel Grumbach  */
2472da4366fSEmmanuel Grumbach enum iwl_mei_akm_auth {
2482da4366fSEmmanuel Grumbach 	IWL_MEI_AKM_AUTH_OPEN		= 0,
2492da4366fSEmmanuel Grumbach 	IWL_MEI_AKM_AUTH_RSNA		= 6,
2502da4366fSEmmanuel Grumbach 	IWL_MEI_AKM_AUTH_RSNA_PSK	= 7,
2512da4366fSEmmanuel Grumbach 	IWL_MEI_AKM_AUTH_SAE		= 9,
2522da4366fSEmmanuel Grumbach };
2532da4366fSEmmanuel Grumbach 
2542da4366fSEmmanuel Grumbach /**
2552da4366fSEmmanuel Grumbach  * struct iwl_mei_conn_info - connection info
2562da4366fSEmmanuel Grumbach  * @lp_state: link protection state
2572da4366fSEmmanuel Grumbach  * @auth_mode: authentication mode
2582da4366fSEmmanuel Grumbach  * @ssid_len: the length of SSID
2592da4366fSEmmanuel Grumbach  * @ssid: the SSID
2602da4366fSEmmanuel Grumbach  * @pairwise_cipher: the cipher used for unicast packets
2612da4366fSEmmanuel Grumbach  * @channel: the associated channel
2622da4366fSEmmanuel Grumbach  * @band: the associated band
2632da4366fSEmmanuel Grumbach  * @bssid: the BSSID
2642da4366fSEmmanuel Grumbach  */
2652da4366fSEmmanuel Grumbach struct iwl_mei_conn_info {
2662da4366fSEmmanuel Grumbach 	u8 lp_state;
2672da4366fSEmmanuel Grumbach 	u8 auth_mode;
2682da4366fSEmmanuel Grumbach 	u8 ssid_len;
2692da4366fSEmmanuel Grumbach 	u8 channel;
2702da4366fSEmmanuel Grumbach 	u8 band;
2712da4366fSEmmanuel Grumbach 	u8 pairwise_cipher;
2722da4366fSEmmanuel Grumbach 	u8 bssid[ETH_ALEN];
2732da4366fSEmmanuel Grumbach 	u8 ssid[IEEE80211_MAX_SSID_LEN];
2742da4366fSEmmanuel Grumbach };
2752da4366fSEmmanuel Grumbach 
2762da4366fSEmmanuel Grumbach /**
2772da4366fSEmmanuel Grumbach  * struct iwl_mei_colloc_info - collocated AP info
2782da4366fSEmmanuel Grumbach  * @channel: the channel of the collocated AP
2792da4366fSEmmanuel Grumbach  * @bssid: the BSSID of the collocated AP
2802da4366fSEmmanuel Grumbach  */
2812da4366fSEmmanuel Grumbach struct iwl_mei_colloc_info {
2822da4366fSEmmanuel Grumbach 	u8 channel;
2832da4366fSEmmanuel Grumbach 	u8 bssid[ETH_ALEN];
2842da4366fSEmmanuel Grumbach };
2852da4366fSEmmanuel Grumbach 
2862da4366fSEmmanuel Grumbach /*
2872da4366fSEmmanuel Grumbach  * struct iwl_mei_ops - driver's operations called by iwlmei
2882da4366fSEmmanuel Grumbach  * Operations will not be called more than once concurrently.
2892da4366fSEmmanuel Grumbach  * It's not allowed to call iwlmei functions from this context.
2902da4366fSEmmanuel Grumbach  *
2912da4366fSEmmanuel Grumbach  * @me_conn_status: provide information about CSME's current connection.
2922da4366fSEmmanuel Grumbach  * @rfkill: called when the wifi driver should report a change in the rfkill
2932da4366fSEmmanuel Grumbach  *	status.
2942da4366fSEmmanuel Grumbach  * @roaming_forbidden: indicates whether roaming is forbidden.
2952da4366fSEmmanuel Grumbach  * @sap_connected: indicate that SAP is now connected. Will be called in case
2962da4366fSEmmanuel Grumbach  *	the wifi driver registered to iwlmei before SAP connection succeeded or
2972da4366fSEmmanuel Grumbach  *	when the SAP connection is re-established.
2982da4366fSEmmanuel Grumbach  * @nic_stolen: this means that device is no longer available. The device can
2992da4366fSEmmanuel Grumbach  *	still be used until the callback returns.
3002da4366fSEmmanuel Grumbach  */
3012da4366fSEmmanuel Grumbach struct iwl_mei_ops {
3022da4366fSEmmanuel Grumbach 	void (*me_conn_status)(void *priv,
3032da4366fSEmmanuel Grumbach 			       const struct iwl_mei_conn_info *conn_info);
304*22b68fc6SAvraham Stern 	void (*rfkill)(void *priv, bool blocked, bool csme_taking_ownership);
3052da4366fSEmmanuel Grumbach 	void (*roaming_forbidden)(void *priv, bool forbidden);
3062da4366fSEmmanuel Grumbach 	void (*sap_connected)(void *priv);
3072da4366fSEmmanuel Grumbach 	void (*nic_stolen)(void *priv);
3082da4366fSEmmanuel Grumbach };
3092da4366fSEmmanuel Grumbach 
3102da4366fSEmmanuel Grumbach #if IS_ENABLED(CONFIG_IWLMEI)
3112da4366fSEmmanuel Grumbach 
3122da4366fSEmmanuel Grumbach /**
3132da4366fSEmmanuel Grumbach  * iwl_mei_is_connected() - is the connection to the CSME firmware established?
3142da4366fSEmmanuel Grumbach  *
3152da4366fSEmmanuel Grumbach  * Return: true if we have a SAP connection
3162da4366fSEmmanuel Grumbach  */
3172da4366fSEmmanuel Grumbach bool iwl_mei_is_connected(void);
3182da4366fSEmmanuel Grumbach 
3192da4366fSEmmanuel Grumbach /**
3202da4366fSEmmanuel Grumbach  * iwl_mei_get_nvm() - returns the NVM for the device
3212da4366fSEmmanuel Grumbach  *
3222da4366fSEmmanuel Grumbach  * It is the caller's responsibility to free the memory returned
3232da4366fSEmmanuel Grumbach  * by this function.
3242da4366fSEmmanuel Grumbach  * This function blocks (sleeps) until the NVM is ready.
3252da4366fSEmmanuel Grumbach  *
3262da4366fSEmmanuel Grumbach  * Return: the NVM as received from CSME
3272da4366fSEmmanuel Grumbach  */
3282da4366fSEmmanuel Grumbach struct iwl_mei_nvm *iwl_mei_get_nvm(void);
3292da4366fSEmmanuel Grumbach 
3302da4366fSEmmanuel Grumbach /**
3312da4366fSEmmanuel Grumbach  * iwl_mei_get_ownership() - request ownership
3322da4366fSEmmanuel Grumbach  *
3332da4366fSEmmanuel Grumbach  * This function blocks until ownership is granted or timeout expired.
3342da4366fSEmmanuel Grumbach  *
3352da4366fSEmmanuel Grumbach  * Return: 0 in case we could get ownership on the device
3362da4366fSEmmanuel Grumbach  */
3372da4366fSEmmanuel Grumbach int iwl_mei_get_ownership(void);
3382da4366fSEmmanuel Grumbach 
3392da4366fSEmmanuel Grumbach /**
3402da4366fSEmmanuel Grumbach  * iwl_mei_set_rfkill_state() - set SW and HW RF kill states
3412da4366fSEmmanuel Grumbach  * @hw_rfkill: HW RF kill state.
3422da4366fSEmmanuel Grumbach  * @sw_rfkill: SW RF kill state.
3432da4366fSEmmanuel Grumbach  *
3442da4366fSEmmanuel Grumbach  * This function must be called when SW RF kill is issued by the user.
3452da4366fSEmmanuel Grumbach  */
3462da4366fSEmmanuel Grumbach void iwl_mei_set_rfkill_state(bool hw_rfkill, bool sw_rfkill);
3472da4366fSEmmanuel Grumbach 
3482da4366fSEmmanuel Grumbach /**
3492da4366fSEmmanuel Grumbach  * iwl_mei_set_nic_info() - set mac address
3502da4366fSEmmanuel Grumbach  * @mac_address: mac address to set
3519ad28ba1STom Rix  * @nvm_address: NVM mac address to set
3522da4366fSEmmanuel Grumbach  *
3532da4366fSEmmanuel Grumbach  * This function must be called upon mac address change.
3542da4366fSEmmanuel Grumbach  */
3552da4366fSEmmanuel Grumbach void iwl_mei_set_nic_info(const u8 *mac_address, const u8 *nvm_address);
3562da4366fSEmmanuel Grumbach 
3572da4366fSEmmanuel Grumbach /**
3582da4366fSEmmanuel Grumbach  * iwl_mei_set_country_code() - set new country code
3592da4366fSEmmanuel Grumbach  * @mcc: the new applied MCC
3602da4366fSEmmanuel Grumbach  *
3612da4366fSEmmanuel Grumbach  * This function must be called upon country code update
3622da4366fSEmmanuel Grumbach  */
3632da4366fSEmmanuel Grumbach void iwl_mei_set_country_code(u16 mcc);
3642da4366fSEmmanuel Grumbach 
3652da4366fSEmmanuel Grumbach /**
3662da4366fSEmmanuel Grumbach  * iwl_mei_set_power_limit() - set TX power limit
3672da4366fSEmmanuel Grumbach  * @power_limit: pointer to an array of 10 elements (le16) represents the power
3682da4366fSEmmanuel Grumbach  * restrictions per chain.
3692da4366fSEmmanuel Grumbach  *
3702da4366fSEmmanuel Grumbach  * This function must be called upon power restrictions change
3712da4366fSEmmanuel Grumbach  */
3722da4366fSEmmanuel Grumbach void iwl_mei_set_power_limit(const __le16 *power_limit);
3732da4366fSEmmanuel Grumbach 
3742da4366fSEmmanuel Grumbach /**
3752da4366fSEmmanuel Grumbach  * iwl_mei_register() - register the wifi driver to iwlmei
3762da4366fSEmmanuel Grumbach  * @priv: a pointer to the wifi driver's context. Cannot be NULL.
3772da4366fSEmmanuel Grumbach  * @ops: the ops structure.
3782da4366fSEmmanuel Grumbach  *
3792da4366fSEmmanuel Grumbach  * Return: 0 unless something went wrong. It is illegal to call any
3802da4366fSEmmanuel Grumbach  * other API function before this function is called and succeeds.
3812da4366fSEmmanuel Grumbach  *
3822da4366fSEmmanuel Grumbach  * Only one wifi driver instance (wifi device instance really)
3832da4366fSEmmanuel Grumbach  * can register at a time.
3842da4366fSEmmanuel Grumbach  */
3852da4366fSEmmanuel Grumbach int iwl_mei_register(void *priv, const struct iwl_mei_ops *ops);
3862da4366fSEmmanuel Grumbach 
3872da4366fSEmmanuel Grumbach /**
3882da4366fSEmmanuel Grumbach  * iwl_mei_start_unregister() - unregister the wifi driver from iwlmei
3892da4366fSEmmanuel Grumbach  *
3902da4366fSEmmanuel Grumbach  * From this point on, iwlmei will not used the callbacks provided by
3912da4366fSEmmanuel Grumbach  * the driver, but the device is still usable.
3922da4366fSEmmanuel Grumbach  */
3932da4366fSEmmanuel Grumbach void iwl_mei_start_unregister(void);
3942da4366fSEmmanuel Grumbach 
3952da4366fSEmmanuel Grumbach /**
3962da4366fSEmmanuel Grumbach  * iwl_mei_unregister_complete() - complete the unregistration
3972da4366fSEmmanuel Grumbach  *
3982da4366fSEmmanuel Grumbach  * Must be called after iwl_mei_start_unregister. When this function returns,
3992da4366fSEmmanuel Grumbach  * the device is owned by CSME.
4002da4366fSEmmanuel Grumbach  */
4012da4366fSEmmanuel Grumbach void iwl_mei_unregister_complete(void);
4022da4366fSEmmanuel Grumbach 
4032da4366fSEmmanuel Grumbach /**
4042da4366fSEmmanuel Grumbach  * iwl_mei_set_netdev() - sets the netdev for Tx / Rx.
4052da4366fSEmmanuel Grumbach  * @netdev: the net_device
4062da4366fSEmmanuel Grumbach  *
4072da4366fSEmmanuel Grumbach  * The caller should set the netdev to a non-NULL value when the
4082da4366fSEmmanuel Grumbach  * interface is added. Packets might be sent to the driver immediately
4092da4366fSEmmanuel Grumbach  * afterwards.
4102da4366fSEmmanuel Grumbach  * The caller should set the netdev to NULL when the interface is removed.
4112da4366fSEmmanuel Grumbach  * This function will call synchronize_net() after setting the netdev to NULL.
4122da4366fSEmmanuel Grumbach  * Only when this function returns, can the caller assume that iwlmei will
4132da4366fSEmmanuel Grumbach  * no longer inject packets into the netdev's Tx path.
4142da4366fSEmmanuel Grumbach  *
4152da4366fSEmmanuel Grumbach  * Context: This function can sleep and assumes rtnl_lock is taken.
4162da4366fSEmmanuel Grumbach  * The netdev must be set to NULL before iwl_mei_start_unregister() is called.
4172da4366fSEmmanuel Grumbach  */
4182da4366fSEmmanuel Grumbach void iwl_mei_set_netdev(struct net_device *netdev);
4192da4366fSEmmanuel Grumbach 
4202da4366fSEmmanuel Grumbach /**
4212da4366fSEmmanuel Grumbach  * iwl_mei_tx_copy_to_csme() - must be called for each packet sent by
4222da4366fSEmmanuel Grumbach  * the wifi driver.
4232da4366fSEmmanuel Grumbach  * @skb: the skb sent
4242da4366fSEmmanuel Grumbach  * @ivlen: the size of the IV that needs to be skipped after the MAC and
4252da4366fSEmmanuel Grumbach  *	before the SNAP header.
4262da4366fSEmmanuel Grumbach  *
4272da4366fSEmmanuel Grumbach  * This function doesn't take any lock, it simply tries to catch DHCP
4282da4366fSEmmanuel Grumbach  * packets sent by the wifi driver. If the packet is a DHCP packet, it
4292da4366fSEmmanuel Grumbach  * will send it to CSME. This function must not be called for virtual
4302da4366fSEmmanuel Grumbach  * interfaces that are not monitored by CSME, meaning it must be called
4312da4366fSEmmanuel Grumbach  * only for packets transmitted by the netdevice that was registered
4322da4366fSEmmanuel Grumbach  * with iwl_mei_set_netdev().
4332da4366fSEmmanuel Grumbach  */
4342da4366fSEmmanuel Grumbach void iwl_mei_tx_copy_to_csme(struct sk_buff *skb, unsigned int ivlen);
4352da4366fSEmmanuel Grumbach 
4362da4366fSEmmanuel Grumbach /**
4372da4366fSEmmanuel Grumbach  * iwl_mei_host_associated() - must be called when iwlwifi associated.
4382da4366fSEmmanuel Grumbach  * @conn_info: pointer to the connection info structure.
4392da4366fSEmmanuel Grumbach  * @colloc_info: pointer to the collocated AP info. This is relevant only in
4402da4366fSEmmanuel Grumbach  *	case of UHB associated AP, otherwise set to NULL.
4412da4366fSEmmanuel Grumbach  */
4422da4366fSEmmanuel Grumbach void iwl_mei_host_associated(const struct iwl_mei_conn_info *conn_info,
4432da4366fSEmmanuel Grumbach 			     const struct iwl_mei_colloc_info *colloc_info);
4442da4366fSEmmanuel Grumbach 
4452da4366fSEmmanuel Grumbach /**
4462da4366fSEmmanuel Grumbach  * iwl_mei_host_disassociated() - must be called when iwlwifi disassociated.
4472da4366fSEmmanuel Grumbach  */
4482da4366fSEmmanuel Grumbach void iwl_mei_host_disassociated(void);
4492da4366fSEmmanuel Grumbach 
4502da4366fSEmmanuel Grumbach /**
4515aa7ce31SAvraham Stern  * iwl_mei_device_state() - must be called when the device changes up/down state
4525aa7ce31SAvraham Stern  * @up: true if the device is up, false otherwise.
4532da4366fSEmmanuel Grumbach  */
4545aa7ce31SAvraham Stern void iwl_mei_device_state(bool up);
4552da4366fSEmmanuel Grumbach 
456733eb54fSAvraham Stern /**
457733eb54fSAvraham Stern  * iwl_mei_pldr_req() - must be called before loading the fw
458733eb54fSAvraham Stern  *
459733eb54fSAvraham Stern  * Return: 0 if the PLDR flow was successful and the fw can be loaded, negative
460733eb54fSAvraham Stern  *	value otherwise.
461733eb54fSAvraham Stern  */
462733eb54fSAvraham Stern int iwl_mei_pldr_req(void);
463733eb54fSAvraham Stern 
464733eb54fSAvraham Stern /**
465733eb54fSAvraham Stern  * iwl_mei_alive_notif() - must be called when alive notificaiton is received
466733eb54fSAvraham Stern  * @success: true if received alive notification, false if waiting for the
467733eb54fSAvraham Stern  *	notificaiton timed out.
468733eb54fSAvraham Stern  */
469733eb54fSAvraham Stern void iwl_mei_alive_notif(bool success);
470733eb54fSAvraham Stern 
4712da4366fSEmmanuel Grumbach #else
4722da4366fSEmmanuel Grumbach 
iwl_mei_is_connected(void)4732da4366fSEmmanuel Grumbach static inline bool iwl_mei_is_connected(void)
4742da4366fSEmmanuel Grumbach { return false; }
4752da4366fSEmmanuel Grumbach 
iwl_mei_get_nvm(void)4762da4366fSEmmanuel Grumbach static inline struct iwl_mei_nvm *iwl_mei_get_nvm(void)
4772da4366fSEmmanuel Grumbach { return NULL; }
4782da4366fSEmmanuel Grumbach 
iwl_mei_get_ownership(void)4792da4366fSEmmanuel Grumbach static inline int iwl_mei_get_ownership(void)
4802da4366fSEmmanuel Grumbach { return 0; }
4812da4366fSEmmanuel Grumbach 
iwl_mei_set_rfkill_state(bool hw_rfkill,bool sw_rfkill)4822da4366fSEmmanuel Grumbach static inline void iwl_mei_set_rfkill_state(bool hw_rfkill, bool sw_rfkill)
4832da4366fSEmmanuel Grumbach {}
4842da4366fSEmmanuel Grumbach 
iwl_mei_set_nic_info(const u8 * mac_address,const u8 * nvm_address)4852da4366fSEmmanuel Grumbach static inline void iwl_mei_set_nic_info(const u8 *mac_address, const u8 *nvm_address)
4862da4366fSEmmanuel Grumbach {}
4872da4366fSEmmanuel Grumbach 
iwl_mei_set_country_code(u16 mcc)4882da4366fSEmmanuel Grumbach static inline void iwl_mei_set_country_code(u16 mcc)
4892da4366fSEmmanuel Grumbach {}
4902da4366fSEmmanuel Grumbach 
iwl_mei_set_power_limit(__le16 * power_limit)4912da4366fSEmmanuel Grumbach static inline void iwl_mei_set_power_limit(__le16 *power_limit)
4922da4366fSEmmanuel Grumbach {}
4932da4366fSEmmanuel Grumbach 
iwl_mei_register(void * priv,const struct iwl_mei_ops * ops)4942da4366fSEmmanuel Grumbach static inline int iwl_mei_register(void *priv,
4952da4366fSEmmanuel Grumbach 				   const struct iwl_mei_ops *ops)
4962da4366fSEmmanuel Grumbach { return 0; }
4972da4366fSEmmanuel Grumbach 
iwl_mei_start_unregister(void)4982da4366fSEmmanuel Grumbach static inline void iwl_mei_start_unregister(void)
4992da4366fSEmmanuel Grumbach {}
5002da4366fSEmmanuel Grumbach 
iwl_mei_unregister_complete(void)5012da4366fSEmmanuel Grumbach static inline void iwl_mei_unregister_complete(void)
5022da4366fSEmmanuel Grumbach {}
5032da4366fSEmmanuel Grumbach 
iwl_mei_set_netdev(struct net_device * netdev)5042da4366fSEmmanuel Grumbach static inline void iwl_mei_set_netdev(struct net_device *netdev)
5052da4366fSEmmanuel Grumbach {}
5062da4366fSEmmanuel Grumbach 
iwl_mei_tx_copy_to_csme(struct sk_buff * skb,unsigned int ivlen)5072da4366fSEmmanuel Grumbach static inline void iwl_mei_tx_copy_to_csme(struct sk_buff *skb,
5082da4366fSEmmanuel Grumbach 					   unsigned int ivlen)
5092da4366fSEmmanuel Grumbach {}
5102da4366fSEmmanuel Grumbach 
iwl_mei_host_associated(const struct iwl_mei_conn_info * conn_info,const struct iwl_mei_colloc_info * colloc_info)5112da4366fSEmmanuel Grumbach static inline void iwl_mei_host_associated(const struct iwl_mei_conn_info *conn_info,
5122da4366fSEmmanuel Grumbach 					   const struct iwl_mei_colloc_info *colloc_info)
5132da4366fSEmmanuel Grumbach {}
5142da4366fSEmmanuel Grumbach 
iwl_mei_host_disassociated(void)5152da4366fSEmmanuel Grumbach static inline void iwl_mei_host_disassociated(void)
5162da4366fSEmmanuel Grumbach {}
5172da4366fSEmmanuel Grumbach 
iwl_mei_device_state(bool up)5185aa7ce31SAvraham Stern static inline void iwl_mei_device_state(bool up)
5192da4366fSEmmanuel Grumbach {}
5202da4366fSEmmanuel Grumbach 
iwl_mei_pldr_req(void)521733eb54fSAvraham Stern static inline int iwl_mei_pldr_req(void)
522733eb54fSAvraham Stern { return 0; }
523733eb54fSAvraham Stern 
iwl_mei_alive_notif(bool success)524733eb54fSAvraham Stern static inline void iwl_mei_alive_notif(bool success)
525733eb54fSAvraham Stern {}
526733eb54fSAvraham Stern 
5272da4366fSEmmanuel Grumbach #endif /* CONFIG_IWLMEI */
5282da4366fSEmmanuel Grumbach 
5292da4366fSEmmanuel Grumbach #endif /* __iwl_mei_h__ */
530