Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_IWLMEI) += iwlmei.o
iwlmei-y += main.o
iwlmei-y += net.o
iwlmei-$(CONFIG_IWLWIFI_DEVICE_TRACING) += trace.o
CFLAGS_trace.o := -I$(src)
ccflags-y += -I $(src)/../
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2021 Intel Corporation
*/
#ifndef __IWLMEI_INTERNAL_H_
#define __IWLMEI_INTERNAL_H_
#include <uapi/linux/if_ether.h>
#include <linux/netdevice.h>
#include "sap.h"
rx_handler_result_t iwl_mei_rx_filter(struct sk_buff *skb,
const struct iwl_sap_oob_filters *filters,
bool *pass_to_csme);
void iwl_mei_add_data_to_ring(struct sk_buff *skb, bool cb_tx);
#endif /* __IWLMEI_INTERNAL_H_ */
@@ -0,0 +1,542 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2021-2024 Intel Corporation
*/
#ifndef __iwl_mei_h__
#define __iwl_mei_h__
#include <linux/if_ether.h>
#include <linux/skbuff.h>
#include <linux/ieee80211.h>
/**
* DOC: Introduction
*
* iwlmei is the kernel module that is in charge of the communication between
* the iwlwifi driver and the CSME firmware's WLAN driver. This communication
* uses the SAP protocol defined in another file.
* iwlwifi can request or release ownership on the WiFi device through iwlmei.
* iwlmei may notify iwlwifi about certain events: what filter iwlwifi should
* use to passthrough inbound packets to the CSME firmware for example. iwlmei
* may also use iwlwifi to send traffic. This means that we need communication
* from iwlmei to iwlwifi and the other way around.
*/
/**
* DOC: Life cycle
*
* iwlmei exports symbols that are needed by iwlwifi so that iwlmei will always
* be loaded when iwlwifi is alive. iwlwifi registers itself to iwlmei and
* provides the pointers to the functions that iwlmei calls whenever needed.
* iwlwifi calls iwlmei through direct and context-free function calls.
* It is assumed that only one device is accessible to the CSME firmware and
* under the scope of iwlmei so that it is valid not to have any context passed
* to iwlmei's functions.
*
* There are cases in which iwlmei can't access the CSME firmware, because the
* CSME firmware is undergoing a reset, or the mei bus decided to unbind the
* device. In those cases, iwlmei will need not to send requests over the mei
* bus. Instead, it needs to cache the requests from iwlwifi and fulfill them
* when the mei bus is available again.
*
* iwlmei can call iwlwifi as long as iwlwifi is registered to iwlmei. When
* iwlwifi goes down (the PCI device is unbound, or the iwlwifi is unloaded)
* iwlwifi needs to unregister from iwlmei.
*/
/**
* DOC: Memory layout
*
* Since iwlwifi calls iwlmei without any context, iwlmei needs to hold a
* global pointer to its data (which is in the mei client device's private
* data area). If there was no bind on the mei bus, this pointer is NULL and
* iwlmei knows not access to the CSME firmware upon requests from iwlwifi.
*
* iwlmei needs to cache requests from iwlwifi when there is no mei client
* device available (when iwlmei has been removed from the mei bus). In this
* case, all iwlmei's data that resides in the mei client device's private data
* area is unavailable. For this specific case, a separate caching area is
* needed.
*/
/**
* DOC: Concurrency
*
* iwlwifi can call iwlmei at any time. iwlmei will take care to synchronize
* the calls from iwlwifi with its internal flows. iwlwifi must not call iwlmei
* in flows that cannot sleep. Moreover, iwlwifi must not call iwlmei in flows
* that originated from iwlmei.
*/
/**
* DOC: Probe and remove from mei bus driver
*
* When the mei bus driver enumerates its devices, it calls the iwlmei's probe
* function which will send the %SAP_ME_MSG_START message. The probe completes
* before the response (%SAP_ME_MSG_START_OK) is received. This response will
* be handle by the Rx path. Once it arrives, the connection to the CSME
* firmware is considered established and iwlwifi's requests can be treated
* against the CSME firmware.
*
* When the mei bus driver removes the device, iwlmei loses all the data that
* was attached to the mei client device. It clears the global pointer to the
* mei client device since it is not available anymore. This will cause all the
* requests coming from iwlwifi to be cached. This flow takes the global mutex
* to be synchronized with all the requests coming from iwlwifi.
*/
/**
* DOC: Driver load when CSME owns the device
*
* When the driver (iwlwifi) is loaded while CSME owns the device,
* it'll ask CSME to release the device through HW registers. CSME
* will release the device only in the case that there is no connection
* through the mei bus. If there is a mei bus connection, CSME will refuse
* to release the ownership on the device through the HW registers. In that
* case, iwlwifi must first request ownership using the SAP protocol.
*
* Once iwlwifi will request ownership through the SAP protocol, CSME will
* grant the ownership on the device through the HW registers as well.
* In order to request ownership over SAP, we first need to have an interface
* which means that we need to register to mac80211.
* This can't happen before we get the NVM that contains all the capabilities
* of the device. Reading the NVM usually requires the load the firmware, but
* this is impossible as long as we don't have ownership on the device.
* In order to solve this chicken and egg problem, the host driver can get
* the NVM through CSME which owns the device. It can send
* %SAP_MSG_NOTIF_GET_NVM, which will be replied by %SAP_MSG_NOTIF_NVM with
* the NVM's content that the host driver needs.
*/
/**
* DOC: CSME behavior regarding the ownership requests
*
* The ownership requests from the host can come in two different ways:
* - the HW registers in iwl_pcie_set_hw_ready
* - using the Software Arbitration Protocol (SAP)
*
* The host can ask CSME who owns the device with %SAP_MSG_NOTIF_WHO_OWNS_NIC,
* and it can request ownership with %SAP_MSG_NOTIF_HOST_ASKS_FOR_NIC_OWNERSHIP.
* The host will first use %SAP_MSG_NOTIF_WHO_OWNS_NIC to know what state
* CSME is in. In case CSME thinks it owns the device, the host can ask for
* ownership with %SAP_MSG_NOTIF_HOST_ASKS_FOR_NIC_OWNERSHIP.
*
* Here the table that describes CSME's behavior upon ownership request:
*
* +-------------------+------------+--------------+-----------------------------+------------+
* | State | HW reg bit | Reply for | Event | HW reg bit |
* | | before | WHO_OWNS_NIC | | after |
* +===================+============+==============+=============================+============+
* | WiAMT not | 0 | Host | HW register or | 0 |
* | operational | Host owner | | HOST_ASKS_FOR_NIC_OWNERSHIP | Host owner |
* +-------------------+------------+--------------+-----------------------------+------------+
* | Operational & | 1 | N/A | HW register | 0 |
* | SAP down & | CSME owner | | | Host owner |
* | no session active | | | | |
* +-------------------+------------+--------------+-----------------------------+------------+
* | Operational & | 1 | CSME | HW register | 1 |
* | SAP up | CSME owner | | | CSME owner |
* +-------------------+------------+--------------+-----------------------------+------------+
* | Operational & | 1 | CSME | HOST_ASKS_FOR_NIC_OWNERSHIP | 0 |
* | SAP up | CSME owner | | | Host owner |
* +-------------------+------------+--------------+-----------------------------+------------+
*/
/**
* DOC: Driver load when CSME is associated and a session is active
*
* A "session" is active when CSME is associated to an access point and the
* link is used to attach a remote driver or to control the system remotely.
* When a session is active, we want to make sure it won't disconnect when we
* take ownership on the device.
* In this case, the driver can get the device, but it'll need to make
* sure that it'll connect to the exact same AP (same BSSID).
* In order to do so, CSME will send the connection parameters through
* SAP and then the host can check if it can connect to this same AP.
* If yes, it can request ownership through SAP and connect quickly without
* scanning all the channels, but just probing the AP on the channel that
* CSME was connected to.
* In order to signal this specific scenario to iwlwifi, iwlmei will
* immediately require iwlwifi to report RF-Kill to the network stack. This
* RF-Kill will prevent the stack from getting the device, and it has a reason
* that tells the userspace that the device is in RF-Kill because it is not
* owned by the host. Once the userspace has configured the right profile,
* it'll be able to let iwlmei know that it can request ownership over SAP
* which will remove the RF-Kill, and finally allow the host to connect.
* The host has then 3 seconds to connect (including DHCP). Had the host
* failed to connect within those 3 seconds, CSME will take the device back.
*/
/**
* DOC: Datapath
*
* CSME can transmit packets, through the netdev that it gets from the wifi
* driver. It'll send packet in the 802.3 format and simply call
* dev_queue_xmit.
*
* For Rx, iwlmei registers a Rx handler that it attaches to the netdev. iwlmei
* may catch packets and send them to CSME, it can then either drop them so
* that they are invisible to user space, or let them go the user space.
*
* Packets transmitted by the user space do not need to be forwarded to CSME
* with the exception of the DHCP request. In order to know what IP is used
* by the user space, CSME needs to get the DHCP request. See
* iwl_mei_tx_copy_to_csme().
*/
/**
* enum iwl_mei_nvm_caps - capabilities for MEI NVM
* @MEI_NVM_CAPS_LARI_SUPPORT: Lari is supported
* @MEI_NVM_CAPS_11AX_SUPPORT: 11AX is supported
*/
enum iwl_mei_nvm_caps {
MEI_NVM_CAPS_LARI_SUPPORT = BIT(0),
MEI_NVM_CAPS_11AX_SUPPORT = BIT(1),
};
/**
* struct iwl_mei_nvm - used to pass the NVM from CSME
* @hw_addr: The MAC address
* @n_hw_addrs: The number of MAC addresses
* @reserved: For alignment.
* @radio_cfg: The radio configuration.
* @caps: See &enum iwl_mei_nvm_caps.
* @nvm_version: The version of the NVM.
* @channels: The data for each channel.
*
* If a field is added, it must correspond to the SAP structure.
*/
struct iwl_mei_nvm {
u8 hw_addr[ETH_ALEN];
u8 n_hw_addrs;
u8 reserved;
u32 radio_cfg;
u32 caps;
u32 nvm_version;
u32 channels[110];
};
/**
* enum iwl_mei_pairwise_cipher - cipher for UCAST key
* @IWL_MEI_CIPHER_NONE: none
* @IWL_MEI_CIPHER_TKIP: tkip
* @IWL_MEI_CIPHER_CCMP: ccmp
* @IWL_MEI_CIPHER_GCMP: gcmp
* @IWL_MEI_CIPHER_GCMP_256: gcmp 256
*
* Note that those values are dictated by the CSME firmware API (see sap.h)
*/
enum iwl_mei_pairwise_cipher {
IWL_MEI_CIPHER_NONE = 0,
IWL_MEI_CIPHER_TKIP = 2,
IWL_MEI_CIPHER_CCMP = 4,
IWL_MEI_CIPHER_GCMP = 8,
IWL_MEI_CIPHER_GCMP_256 = 9,
};
/**
* enum iwl_mei_akm_auth - a combination of AKM and AUTH method
* @IWL_MEI_AKM_AUTH_OPEN: No encryption
* @IWL_MEI_AKM_AUTH_RSNA: 1X profile
* @IWL_MEI_AKM_AUTH_RSNA_PSK: PSK profile
* @IWL_MEI_AKM_AUTH_SAE: SAE profile
*
* Note that those values are dictated by the CSME firmware API (see sap.h)
*/
enum iwl_mei_akm_auth {
IWL_MEI_AKM_AUTH_OPEN = 0,
IWL_MEI_AKM_AUTH_RSNA = 6,
IWL_MEI_AKM_AUTH_RSNA_PSK = 7,
IWL_MEI_AKM_AUTH_SAE = 9,
};
/**
* struct iwl_mei_conn_info - connection info
* @lp_state: link protection state
* @auth_mode: authentication mode
* @ssid_len: the length of SSID
* @ssid: the SSID
* @pairwise_cipher: the cipher used for unicast packets
* @channel: the associated channel
* @band: the associated band
* @bssid: the BSSID
*/
struct iwl_mei_conn_info {
u8 lp_state;
u8 auth_mode;
u8 ssid_len;
u8 channel;
u8 band;
u8 pairwise_cipher;
u8 bssid[ETH_ALEN];
u8 ssid[IEEE80211_MAX_SSID_LEN];
};
/**
* struct iwl_mei_colloc_info - collocated AP info
* @channel: the channel of the collocated AP
* @bssid: the BSSID of the collocated AP
*/
struct iwl_mei_colloc_info {
u8 channel;
u8 bssid[ETH_ALEN];
};
/**
* enum iwl_mei_sap_version - SAP version
* @IWL_MEI_SAP_VERSION_3: SAP version 3
* @IWL_MEI_SAP_VERSION_4: SAP version 4
*/
enum iwl_mei_sap_version {
IWL_MEI_SAP_VERSION_3 = 3,
IWL_MEI_SAP_VERSION_4 = 4,
};
/*
* struct iwl_mei_ops - driver's operations called by iwlmei
* Operations will not be called more than once concurrently.
* It's not allowed to call iwlmei functions from this context.
*
* @me_conn_status: provide information about CSME's current connection.
* @rfkill: called when the wifi driver should report a change in the rfkill
* status.
* @roaming_forbidden: indicates whether roaming is forbidden.
* @sap_connected: indicate that SAP is now connected. Will be called in case
* the wifi driver registered to iwlmei before SAP connection succeeded or
* when the SAP connection is re-established.
* @nic_stolen: this means that device is no longer available. The device can
* still be used until the callback returns.
*/
struct iwl_mei_ops {
void (*me_conn_status)(void *priv,
const struct iwl_mei_conn_info *conn_info);
void (*rfkill)(void *priv, bool blocked, bool csme_taking_ownership);
void (*roaming_forbidden)(void *priv, bool forbidden);
void (*sap_connected)(void *priv);
void (*nic_stolen)(void *priv);
};
#if IS_ENABLED(CONFIG_IWLMEI)
/**
* iwl_mei_is_connected() - is the connection to the CSME firmware established?
*
* Return: true if we have a SAP connection
*/
bool iwl_mei_is_connected(void);
/**
* iwl_mei_get_nvm() - returns the NVM for the device
*
* It is the caller's responsibility to free the memory returned
* by this function.
* This function blocks (sleeps) until the NVM is ready.
*
* Return: the NVM as received from CSME
*/
struct iwl_mei_nvm *iwl_mei_get_nvm(void);
/**
* iwl_mei_get_ownership() - request ownership
*
* This function blocks until ownership is granted or timeout expired.
*
* Return: 0 in case we could get ownership on the device
*/
int iwl_mei_get_ownership(void);
/**
* iwl_mei_set_rfkill_state() - set SW and HW RF kill states
* @hw_rfkill: HW RF kill state.
* @sw_rfkill: SW RF kill state.
*
* This function must be called when SW RF kill is issued by the user.
*/
void iwl_mei_set_rfkill_state(bool hw_rfkill, bool sw_rfkill);
/**
* iwl_mei_set_nic_info() - set mac address
* @mac_address: mac address to set
* @nvm_address: NVM mac address to set
*
* This function must be called upon mac address change.
*/
void iwl_mei_set_nic_info(const u8 *mac_address, const u8 *nvm_address);
/**
* iwl_mei_set_country_code() - set new country code
* @mcc: the new applied MCC
*
* This function must be called upon country code update
*/
void iwl_mei_set_country_code(u16 mcc);
/**
* iwl_mei_set_power_limit() - set TX power limit
* @power_limit: pointer to an array of 10 elements (le16) represents the power
* restrictions per chain.
*
* This function must be called upon power restrictions change
*/
void iwl_mei_set_power_limit(const __le16 *power_limit);
/**
* iwl_mei_register() - register the wifi driver to iwlmei
* @priv: a pointer to the wifi driver's context. Cannot be NULL.
* @ops: the ops structure.
*
* Return: 0 unless something went wrong. It is illegal to call any
* other API function before this function is called and succeeds.
*
* Only one wifi driver instance (wifi device instance really)
* can register at a time.
*/
int iwl_mei_register(void *priv, const struct iwl_mei_ops *ops);
/**
* iwl_mei_start_unregister() - unregister the wifi driver from iwlmei
*
* From this point on, iwlmei will not used the callbacks provided by
* the driver, but the device is still usable.
*/
void iwl_mei_start_unregister(void);
/**
* iwl_mei_unregister_complete() - complete the unregistration
*
* Must be called after iwl_mei_start_unregister. When this function returns,
* the device is owned by CSME.
*/
void iwl_mei_unregister_complete(void);
/**
* iwl_mei_set_netdev() - sets the netdev for Tx / Rx.
* @netdev: the net_device
*
* The caller should set the netdev to a non-NULL value when the
* interface is added. Packets might be sent to the driver immediately
* afterwards.
* The caller should set the netdev to NULL when the interface is removed.
* This function will call synchronize_net() after setting the netdev to NULL.
* Only when this function returns, can the caller assume that iwlmei will
* no longer inject packets into the netdev's Tx path.
*
* Context: This function can sleep and assumes rtnl_lock is taken.
* The netdev must be set to NULL before iwl_mei_start_unregister() is called.
*/
void iwl_mei_set_netdev(struct net_device *netdev);
/**
* iwl_mei_tx_copy_to_csme() - must be called for each packet sent by
* the wifi driver.
* @skb: the skb sent
* @ivlen: the size of the IV that needs to be skipped after the MAC and
* before the SNAP header.
*
* This function doesn't take any lock, it simply tries to catch DHCP
* packets sent by the wifi driver. If the packet is a DHCP packet, it
* will send it to CSME. This function must not be called for virtual
* interfaces that are not monitored by CSME, meaning it must be called
* only for packets transmitted by the netdevice that was registered
* with iwl_mei_set_netdev().
*/
void iwl_mei_tx_copy_to_csme(struct sk_buff *skb, unsigned int ivlen);
/**
* iwl_mei_host_associated() - must be called when iwlwifi associated.
* @conn_info: pointer to the connection info structure.
* @colloc_info: pointer to the collocated AP info. This is relevant only in
* case of UHB associated AP, otherwise set to NULL.
*/
void iwl_mei_host_associated(const struct iwl_mei_conn_info *conn_info,
const struct iwl_mei_colloc_info *colloc_info);
/**
* iwl_mei_host_disassociated() - must be called when iwlwifi disassociated.
*/
void iwl_mei_host_disassociated(void);
/**
* iwl_mei_device_state() - must be called when the device changes up/down state
* @up: true if the device is up, false otherwise.
*/
void iwl_mei_device_state(bool up);
/**
* iwl_mei_pldr_req() - must be called before loading the fw
*
* Requests from the ME that it releases its potential bus access to
* the WiFi NIC so that the device can safely undergo product reset.
*
* Return: 0 if the request was successful and the device can be
* reset, a negative error value otherwise
*/
int iwl_mei_pldr_req(void);
/**
* iwl_mei_alive_notif() - must be called when alive notificaiton is received
* @success: true if received alive notification, false if waiting for the
* notificaiton timed out.
*/
void iwl_mei_alive_notif(bool success);
#else
static inline bool iwl_mei_is_connected(void)
{ return false; }
static inline struct iwl_mei_nvm *iwl_mei_get_nvm(void)
{ return NULL; }
static inline int iwl_mei_get_ownership(void)
{ return 0; }
static inline void iwl_mei_set_rfkill_state(bool hw_rfkill, bool sw_rfkill)
{}
static inline void iwl_mei_set_nic_info(const u8 *mac_address, const u8 *nvm_address)
{}
static inline void iwl_mei_set_country_code(u16 mcc)
{}
static inline void iwl_mei_set_power_limit(const __le16 *power_limit)
{}
static inline int iwl_mei_register(void *priv,
const struct iwl_mei_ops *ops)
{ return -EOPNOTSUPP; }
static inline void iwl_mei_start_unregister(void)
{}
static inline void iwl_mei_unregister_complete(void)
{}
static inline void iwl_mei_set_netdev(struct net_device *netdev)
{}
static inline void iwl_mei_tx_copy_to_csme(struct sk_buff *skb,
unsigned int ivlen)
{}
static inline void iwl_mei_host_associated(const struct iwl_mei_conn_info *conn_info,
const struct iwl_mei_colloc_info *colloc_info)
{}
static inline void iwl_mei_host_disassociated(void)
{}
static inline void iwl_mei_device_state(bool up)
{}
static inline int iwl_mei_pldr_req(void)
{ return 0; }
static inline void iwl_mei_alive_notif(bool success)
{}
#endif /* CONFIG_IWLMEI */
#endif /* __iwl_mei_h__ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,412 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2021-2022 Intel Corporation
*/
#include <uapi/linux/if_ether.h>
#include <uapi/linux/if_arp.h>
#include <uapi/linux/icmp.h>
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/ieee80211.h>
#include <net/cfg80211.h>
#include <net/ip.h>
#include <linux/if_arp.h>
#include <linux/icmp.h>
#include <linux/udp.h>
#include <linux/ip.h>
#include <linux/mm.h>
#include "internal.h"
#include "sap.h"
#include "iwl-mei.h"
/*
* Returns true if further filtering should be stopped. Only in that case
* pass_to_csme and rx_handler_res are set. Otherwise, next level of filters
* should be checked.
*/
static bool iwl_mei_rx_filter_eth(const struct ethhdr *ethhdr,
const struct iwl_sap_oob_filters *filters,
bool *pass_to_csme,
rx_handler_result_t *rx_handler_res)
{
const struct iwl_sap_eth_filter *filt;
/* This filter is not relevant for UCAST packet */
if (!is_multicast_ether_addr(ethhdr->h_dest) ||
is_broadcast_ether_addr(ethhdr->h_dest))
return false;
for (filt = &filters->eth_filters[0];
filt < &filters->eth_filters[0] + ARRAY_SIZE(filters->eth_filters);
filt++) {
/* Assume there are no enabled filter after a disabled one */
if (!(filt->flags & SAP_ETH_FILTER_ENABLED))
break;
if (compare_ether_header(filt->mac_address, ethhdr->h_dest))
continue;
/* Packet needs to reach the host's stack */
if (filt->flags & SAP_ETH_FILTER_COPY)
*rx_handler_res = RX_HANDLER_PASS;
else
*rx_handler_res = RX_HANDLER_CONSUMED;
/* We have an authoritative answer, stop filtering */
if (filt->flags & SAP_ETH_FILTER_STOP) {
*pass_to_csme = true;
return true;
}
return false;
}
/* MCAST frames that don't match layer 2 filters are not sent to ME */
*pass_to_csme = false;
return true;
}
/*
* Returns true iff the frame should be passed to CSME in which case
* rx_handler_res is set.
*/
static bool iwl_mei_rx_filter_arp(struct sk_buff *skb,
const struct iwl_sap_oob_filters *filters,
rx_handler_result_t *rx_handler_res)
{
const struct iwl_sap_ipv4_filter *filt = &filters->ipv4_filter;
const struct arphdr *arp;
const __be32 *target_ip;
u32 flags = le32_to_cpu(filt->flags);
if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
return false;
arp = arp_hdr(skb);
/* Handle only IPv4 over ethernet ARP frames */
if (arp->ar_hrd != htons(ARPHRD_ETHER) ||
arp->ar_pro != htons(ETH_P_IP))
return false;
/*
* After the ARP header, we have:
* src MAC address - 6 bytes
* src IP address - 4 bytes
* target MAC addess - 6 bytes
*/
target_ip = (const void *)((const u8 *)(arp + 1) +
ETH_ALEN + sizeof(__be32) + ETH_ALEN);
/*
* ARP request is forwarded to ME only if IP address match in the
* ARP request's target ip field.
*/
if (arp->ar_op == htons(ARPOP_REQUEST) &&
(filt->flags & cpu_to_le32(SAP_IPV4_FILTER_ARP_REQ_PASS)) &&
(filt->ipv4_addr == 0 || filt->ipv4_addr == *target_ip)) {
if (flags & SAP_IPV4_FILTER_ARP_REQ_COPY)
*rx_handler_res = RX_HANDLER_PASS;
else
*rx_handler_res = RX_HANDLER_CONSUMED;
return true;
}
/* ARP reply is always forwarded to ME regardless of the IP */
if (flags & SAP_IPV4_FILTER_ARP_RESP_PASS &&
arp->ar_op == htons(ARPOP_REPLY)) {
if (flags & SAP_IPV4_FILTER_ARP_RESP_COPY)
*rx_handler_res = RX_HANDLER_PASS;
else
*rx_handler_res = RX_HANDLER_CONSUMED;
return true;
}
return false;
}
static bool
iwl_mei_rx_filter_tcp_udp(struct sk_buff *skb, bool ip_match,
const struct iwl_sap_oob_filters *filters,
rx_handler_result_t *rx_handler_res)
{
const struct iwl_sap_flex_filter *filt;
for (filt = &filters->flex_filters[0];
filt < &filters->flex_filters[0] + ARRAY_SIZE(filters->flex_filters);
filt++) {
if (!(filt->flags & SAP_FLEX_FILTER_ENABLED))
break;
/*
* We are required to have a match on the IP level and we didn't
* have such match.
*/
if ((filt->flags &
(SAP_FLEX_FILTER_IPV4 | SAP_FLEX_FILTER_IPV6)) &&
!ip_match)
continue;
if ((filt->flags & SAP_FLEX_FILTER_UDP) &&
ip_hdr(skb)->protocol != IPPROTO_UDP)
continue;
if ((filt->flags & SAP_FLEX_FILTER_TCP) &&
ip_hdr(skb)->protocol != IPPROTO_TCP)
continue;
/*
* We must have either a TCP header or a UDP header, both
* starts with a source port and then a destination port.
* Both are big endian words.
* Use a UDP header and that will work for TCP as well.
*/
if ((filt->src_port && filt->src_port != udp_hdr(skb)->source) ||
(filt->dst_port && filt->dst_port != udp_hdr(skb)->dest))
continue;
if (filt->flags & SAP_FLEX_FILTER_COPY)
*rx_handler_res = RX_HANDLER_PASS;
else
*rx_handler_res = RX_HANDLER_CONSUMED;
return true;
}
return false;
}
static bool iwl_mei_rx_filter_ipv4(struct sk_buff *skb,
const struct iwl_sap_oob_filters *filters,
rx_handler_result_t *rx_handler_res)
{
const struct iwl_sap_ipv4_filter *filt = &filters->ipv4_filter;
const struct iphdr *iphdr;
unsigned int iphdrlen;
bool match;
if (!pskb_may_pull(skb, skb_network_offset(skb) + sizeof(*iphdr)) ||
!pskb_may_pull(skb, skb_network_offset(skb) + ip_hdrlen(skb)))
return false;
iphdrlen = ip_hdrlen(skb);
iphdr = ip_hdr(skb);
match = !filters->ipv4_filter.ipv4_addr ||
filters->ipv4_filter.ipv4_addr == iphdr->daddr;
skb_set_transport_header(skb, skb_network_offset(skb) + iphdrlen);
switch (ip_hdr(skb)->protocol) {
case IPPROTO_UDP:
case IPPROTO_TCP:
/*
* UDP header is shorter than TCP header and we look at the first bytes
* of the header anyway (see below).
* If we have a truncated TCP packet, let CSME handle this.
*/
if (!pskb_may_pull(skb, skb_transport_offset(skb) +
sizeof(struct udphdr)))
return false;
return iwl_mei_rx_filter_tcp_udp(skb, match,
filters, rx_handler_res);
case IPPROTO_ICMP: {
struct icmphdr *icmp;
if (!pskb_may_pull(skb, skb_transport_offset(skb) + sizeof(*icmp)))
return false;
icmp = icmp_hdr(skb);
/*
* Don't pass echo requests to ME even if it wants it as we
* want the host to answer.
*/
if ((filt->flags & cpu_to_le32(SAP_IPV4_FILTER_ICMP_PASS)) &&
match && (icmp->type != ICMP_ECHO || icmp->code != 0)) {
if (filt->flags & cpu_to_le32(SAP_IPV4_FILTER_ICMP_COPY))
*rx_handler_res = RX_HANDLER_PASS;
else
*rx_handler_res = RX_HANDLER_CONSUMED;
return true;
}
break;
}
case IPPROTO_ICMPV6:
/* TODO: Should we have the same ICMP request logic here too? */
if ((filters->icmpv6_flags & cpu_to_le32(SAP_ICMPV6_FILTER_ENABLED) &&
match)) {
if (filters->icmpv6_flags &
cpu_to_le32(SAP_ICMPV6_FILTER_COPY))
*rx_handler_res = RX_HANDLER_PASS;
else
*rx_handler_res = RX_HANDLER_CONSUMED;
return true;
}
break;
default:
return false;
}
return false;
}
static bool iwl_mei_rx_filter_ipv6(struct sk_buff *skb,
const struct iwl_sap_oob_filters *filters,
rx_handler_result_t *rx_handler_res)
{
*rx_handler_res = RX_HANDLER_PASS;
/* TODO */
return false;
}
static rx_handler_result_t
iwl_mei_rx_pass_to_csme(struct sk_buff *skb,
const struct iwl_sap_oob_filters *filters,
bool *pass_to_csme)
{
const struct ethhdr *ethhdr = (void *)skb_mac_header(skb);
rx_handler_result_t rx_handler_res = RX_HANDLER_PASS;
bool (*filt_handler)(struct sk_buff *skb,
const struct iwl_sap_oob_filters *filters,
rx_handler_result_t *rx_handler_res);
/*
* skb->data points the IP header / ARP header and the ETH header
* is in the headroom.
*/
skb_reset_network_header(skb);
/*
* MCAST IP packets sent by us are received again here without
* an ETH header. Drop them here.
*/
if (!skb_mac_offset(skb))
return RX_HANDLER_PASS;
if (skb_headroom(skb) < sizeof(*ethhdr))
return RX_HANDLER_PASS;
if (iwl_mei_rx_filter_eth(ethhdr, filters,
pass_to_csme, &rx_handler_res))
return rx_handler_res;
switch (skb->protocol) {
case htons(ETH_P_IP):
filt_handler = iwl_mei_rx_filter_ipv4;
break;
case htons(ETH_P_ARP):
filt_handler = iwl_mei_rx_filter_arp;
break;
case htons(ETH_P_IPV6):
filt_handler = iwl_mei_rx_filter_ipv6;
break;
default:
*pass_to_csme = false;
return rx_handler_res;
}
*pass_to_csme = filt_handler(skb, filters, &rx_handler_res);
return rx_handler_res;
}
rx_handler_result_t iwl_mei_rx_filter(struct sk_buff *orig_skb,
const struct iwl_sap_oob_filters *filters,
bool *pass_to_csme)
{
rx_handler_result_t ret;
struct sk_buff *skb;
ret = iwl_mei_rx_pass_to_csme(orig_skb, filters, pass_to_csme);
if (!*pass_to_csme)
return RX_HANDLER_PASS;
if (ret == RX_HANDLER_PASS) {
skb = skb_copy(orig_skb, GFP_ATOMIC);
if (!skb)
return RX_HANDLER_PASS;
} else {
skb = orig_skb;
}
/* CSME wants the MAC header as well, push it back */
skb_push(skb, skb->data - skb_mac_header(skb));
/*
* Add the packet that CSME wants to get to the ring. Don't send the
* Check Shared Area HECI message since this is not possible from the
* Rx context. The caller will schedule a worker to do just that.
*/
iwl_mei_add_data_to_ring(skb, false);
/*
* In case we drop the packet, don't free it, the caller will do that
* for us
*/
if (ret == RX_HANDLER_PASS)
dev_kfree_skb(skb);
return ret;
}
#define DHCP_SERVER_PORT 67
#define DHCP_CLIENT_PORT 68
void iwl_mei_tx_copy_to_csme(struct sk_buff *origskb, unsigned int ivlen)
{
struct ieee80211_hdr *hdr;
struct sk_buff *skb;
struct ethhdr ethhdr;
struct ethhdr *eth;
/* Catch DHCP packets */
if (origskb->protocol != htons(ETH_P_IP) ||
ip_hdr(origskb)->protocol != IPPROTO_UDP ||
udp_hdr(origskb)->source != htons(DHCP_CLIENT_PORT) ||
udp_hdr(origskb)->dest != htons(DHCP_SERVER_PORT))
return;
/*
* We could be a bit less aggressive here and not copy everything, but
* this is very rare anyway, do don't bother much.
*/
skb = skb_copy(origskb, GFP_ATOMIC);
if (!skb)
return;
skb->protocol = origskb->protocol;
hdr = (void *)skb->data;
memcpy(ethhdr.h_dest, ieee80211_get_DA(hdr), ETH_ALEN);
memcpy(ethhdr.h_source, ieee80211_get_SA(hdr), ETH_ALEN);
/*
* Remove the ieee80211 header + IV + SNAP but leave the ethertype
* We still have enough headroom for the sap header.
*/
pskb_pull(skb, ieee80211_hdrlen(hdr->frame_control) + ivlen + 6);
eth = skb_push(skb, sizeof(ethhdr.h_dest) + sizeof(ethhdr.h_source));
memcpy(eth, &ethhdr, sizeof(ethhdr.h_dest) + sizeof(ethhdr.h_source));
iwl_mei_add_data_to_ring(skb, true);
dev_kfree_skb(skb);
}
EXPORT_SYMBOL_GPL(iwl_mei_tx_copy_to_csme);
@@ -0,0 +1,784 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2021 - 2022, 2025 Intel Corporation
*/
#ifndef __sap_h__
#define __sap_h__
#include "mei/iwl-mei.h"
/**
* DOC: Introduction
*
* SAP is the protocol used by the Intel Wireless driver (iwlwifi)
* and the wireless driver implemented in the CSME firmware.
* It allows to do several things:
* 1) Decide who is the owner of the device: CSME or the host
* 2) When the host is the owner of the device, CSME can still
* send and receive packets through iwlwifi.
*
* The protocol uses the ME interface (mei driver) to send
* messages to the CSME firmware. Those messages have a header
* &struct iwl_sap_me_msg_hdr and this header is followed
* by a payload.
*
* Since this messaging system cannot support high amounts of
* traffic, iwlwifi and the CSME firmware's WLAN driver have an
* additional communication pipe to exchange information. The body
* of the message is copied to a shared area and the message that
* goes over the ME interface just signals the other side
* that a new message is waiting in the shared area. The ME
* interface is used only for signaling and not to transfer
* the payload.
*
* This shared area of memory is DMA'able mapped to be
* writable by both the CSME firmware and iwlwifi. It is
* mapped to address space of the device that controls the ME
* interface's DMA engine. Any data that iwlwifi needs to
* send to the CSME firmware needs to be copied to there.
*/
/**
* DOC: Initial Handshake
*
* Once we get a link to the CMSE's WLAN driver we start the handshake
* to establish the shared memory that will allow the communication between
* the CSME's WLAN driver and the host.
*
* 1) Host sends %SAP_ME_MSG_START message with the physical address
* of the shared area.
* 2) CSME replies with %SAP_ME_MSG_START_OK which includes the versions
* protocol versions supported by CSME.
*/
/**
* DOC: Host and driver state messages
*
* In order to let CSME know about the host state and the host driver state,
* the host sends messages that let CSME know about the host's state.
* When the host driver is loaded, the host sends %SAP_MSG_NOTIF_WIFIDR_UP.
* When the host driver is unloaded, the host sends %SAP_MSG_NOTIF_WIFIDR_DOWN.
* When the iwlmei is unloaded, %SAP_MSG_NOTIF_HOST_GOES_DOWN is sent to let
* CSME know not to access the shared memory anymore since it'll be freed.
*
* CSME will reply to SAP_MSG_NOTIF_WIFIDR_UP by
* %SAP_MSG_NOTIF_AMT_STATE to let the host driver whether CSME can use the
* WiFi device or not followed by %SAP_MSG_NOTIF_CSME_CONN_STATUS to inform
* the host driver on the connection state of CSME.
*
* When host is associated to an AP, it must send %SAP_MSG_NOTIF_HOST_LINK_UP
* and when it disconnect from the AP, it must send
* %SAP_MSG_NOTIF_HOST_LINK_DOWN.
*/
/**
* DOC: Ownership
*
* The device can be controlled either by the CSME firmware or
* by the host driver: iwlwifi. There is a negotiation between
* those two entities to determine who controls (or owns) the
* device. Since the CSME can control the device even when the
* OS is not working or even missing, the CSME can request the
* device if it comes to the conclusion that the OS's host driver
* is not operational. This is why the host driver needs to
* signal CSME that it is up and running. If the driver is
* unloaded, it'll signal CSME that it is going down so that
* CSME can take ownership.
*/
/**
* DOC: Ownership transfer
*
* When the host driver needs the device, it'll send the
* %SAP_MSG_NOTIF_HOST_ASKS_FOR_NIC_OWNERSHIP that will be replied by
* %SAP_MSG_NOTIF_CSME_REPLY_TO_HOST_OWNERSHIP_REQ which will let the
* host know whether the ownership is granted or no. If the ownership is
* granted, the hosts sends %SAP_MSG_NOTIF_HOST_OWNERSHIP_CONFIRMED.
*
* When CSME requests ownership, it'll send the
* %SAP_MSG_NOTIF_CSME_TAKING_OWNERSHIP and give some time to host to stop
* accessing the device. The host needs to send
* %SAP_MSG_NOTIF_CSME_OWNERSHIP_CONFIRMED to confirm that it won't access
* the device anymore. If the host failed to send this message fast enough,
* CSME will take ownership on the device anyway.
* When CSME is willing to release the ownership, it'll send
* %SAP_MSG_NOTIF_CSME_CAN_RELEASE_OWNERSHIP.
*/
/**
* DOC: Data messages
*
* Data messages must be sent and receives on a separate queue in the shared
* memory. Almost all the data messages use the %SAP_MSG_DATA_PACKET for both
* packets sent by CSME to the host to be sent to the AP or for packets
* received from the AP and sent by the host to CSME.
* CSME sends filters to the host to let the host what inbound packets it must
* send to CSME. Those filters are received by the host as a
* %SAP_MSG_NOTIF_CSME_FILTERS command.
* The only outbound packets that must be sent to CSME are the DHCP packets.
* Those packets must use the %SAP_MSG_CB_DATA_PACKET message.
*/
/**
* enum iwl_sap_me_msg_id - the ID of the ME message
* @SAP_ME_MSG_START: See &struct iwl_sap_me_msg_start.
* @SAP_ME_MSG_START_OK: See &struct iwl_sap_me_msg_start_ok.
* @SAP_ME_MSG_CHECK_SHARED_AREA: This message has no payload.
*/
enum iwl_sap_me_msg_id {
SAP_ME_MSG_START = 1,
SAP_ME_MSG_START_OK,
SAP_ME_MSG_CHECK_SHARED_AREA,
};
/**
* struct iwl_sap_me_msg_hdr - the header of the ME message
* @type: the type of the message, see &enum iwl_sap_me_msg_id.
* @seq_num: a sequence number used for debug only.
* @len: the length of the message.
*/
struct iwl_sap_me_msg_hdr {
__le32 type;
__le32 seq_num;
__le32 len;
} __packed;
/**
* struct iwl_sap_me_msg_start - used for the %SAP_ME_MSG_START message
* @hdr: See &struct iwl_sap_me_msg_hdr.
* @shared_mem: physical address of SAP shared memory area.
* @init_data_seq_num: seq_num of the first data packet HOST -> CSME.
* @init_notif_seq_num: seq_num of the first notification HOST -> CSME.
* @supported_versions: The host sends to the CSME a zero-terminated array
* of versions its supports.
*
* This message is sent by the host to CSME and will responded by the
* %SAP_ME_MSG_START_OK message.
*/
struct iwl_sap_me_msg_start {
struct iwl_sap_me_msg_hdr hdr;
__le64 shared_mem;
__le16 init_data_seq_num;
__le16 init_notif_seq_num;
u8 supported_versions[64];
} __packed;
/**
* struct iwl_sap_me_msg_start_ok - used for the %SAP_ME_MSG_START_OK
* @hdr: See &struct iwl_sap_me_msg_hdr
* @init_data_seq_num: Not used.
* @init_notif_seq_num: Not used
* @supported_version: The version that will be used.
* @reserved: For alignment.
*
* This message is sent by CSME to the host in response to the
* %SAP_ME_MSG_START message.
*/
struct iwl_sap_me_msg_start_ok {
struct iwl_sap_me_msg_hdr hdr;
__le16 init_data_seq_num;
__le16 init_notif_seq_num;
u8 supported_version;
u8 reserved[3];
} __packed;
/**
* enum iwl_sap_msg - SAP messages
* @SAP_MSG_NOTIF_BOTH_WAYS_MIN: Not used.
* @SAP_MSG_NOTIF_PING: No payload. Solicitate a response message (check-alive).
* @SAP_MSG_NOTIF_PONG: No payload. The response message.
* @SAP_MSG_NOTIF_BOTH_WAYS_MAX: Not used.
*
* @SAP_MSG_NOTIF_FROM_CSME_MIN: Not used.
* @SAP_MSG_NOTIF_CSME_FILTERS: TODO
* @SAP_MSG_NOTIF_AMT_STATE: Payload is a DW. Any non-zero value means
* that CSME is enabled.
* @SAP_MSG_NOTIF_CSME_REPLY_TO_HOST_OWNERSHIP_REQ: Payload is a DW. 0 means
* the host will not get ownership. Any other value means the host is
* the owner.
* @SAP_MSG_NOTIF_CSME_TAKING_OWNERSHIP: No payload.
* @SAP_MSG_NOTIF_TRIGGER_IP_REFRESH: No payload.
* @SAP_MSG_NOTIF_CSME_CAN_RELEASE_OWNERSHIP: No payload.
* @SAP_MSG_NOTIF_NIC_OWNER: Payload is a DW. See &enum iwl_sap_nic_owner.
* @SAP_MSG_NOTIF_CSME_CONN_STATUS: See &struct iwl_sap_notif_conn_status.
* @SAP_MSG_NOTIF_NVM: See &struct iwl_sap_nvm.
* @SAP_MSG_NOTIF_PLDR_ACK: See &struct iwl_sap_pldr_ack_data.
* @SAP_MSG_NOTIF_FROM_CSME_MAX: Not used.
*
* @SAP_MSG_NOTIF_FROM_HOST_MIN: Not used.
* @SAP_MSG_NOTIF_BAND_SELECTION: TODO
* @SAP_MSG_NOTIF_RADIO_STATE: Payload is a DW.
* See &enum iwl_sap_radio_state_bitmap.
* @SAP_MSG_NOTIF_NIC_INFO: See &struct iwl_sap_notif_host_nic_info.
* @SAP_MSG_NOTIF_HOST_ASKS_FOR_NIC_OWNERSHIP: No payload.
* @SAP_MSG_NOTIF_HOST_SUSPENDS: Payload is a DW. Bitmap described in
* &enum iwl_sap_notif_host_suspends_bitmap.
* @SAP_MSG_NOTIF_HOST_RESUMES: Payload is a DW. 0 or 1. 1 says that
* the CSME should re-initialize the init control block.
* @SAP_MSG_NOTIF_HOST_GOES_DOWN: No payload.
* @SAP_MSG_NOTIF_CSME_OWNERSHIP_CONFIRMED: No payload.
* @SAP_MSG_NOTIF_COUNTRY_CODE: See &struct iwl_sap_notif_country_code.
* @SAP_MSG_NOTIF_HOST_LINK_UP: See &struct iwl_sap_notif_host_link_up.
* @SAP_MSG_NOTIF_HOST_LINK_DOWN: See &struct iwl_sap_notif_host_link_down.
* @SAP_MSG_NOTIF_WHO_OWNS_NIC: No payload.
* @SAP_MSG_NOTIF_WIFIDR_DOWN: No payload.
* @SAP_MSG_NOTIF_WIFIDR_UP: No payload.
* @SAP_MSG_NOTIF_HOST_OWNERSHIP_CONFIRMED: No payload.
* @SAP_MSG_NOTIF_SAR_LIMITS: See &struct iwl_sap_notif_sar_limits.
* @SAP_MSG_NOTIF_GET_NVM: No payload. Triggers %SAP_MSG_NOTIF_NVM.
* @SAP_MSG_NOTIF_PLDR: See &struct iwl_sap_pldr_data.
* @SAP_MSG_NOTIF_PLDR_END: See &struct iwl_sap_pldr_end_data.
* @SAP_MSG_NOTIF_FROM_HOST_MAX: Not used.
*
* @SAP_MSG_DATA_MIN: Not used.
* @SAP_MSG_DATA_PACKET: Packets that passed the filters defined by
* %SAP_MSG_NOTIF_CSME_FILTERS. The payload is &struct iwl_sap_hdr with
* the payload of the packet immediately afterwards.
* @SAP_MSG_CB_DATA_PACKET: Indicates to CSME that we transmitted a specific
* packet. Used only for DHCP transmitted packets. See
* &struct iwl_sap_cb_data.
* @SAP_MSG_DATA_MAX: Not used.
*/
enum iwl_sap_msg {
SAP_MSG_NOTIF_BOTH_WAYS_MIN = 0,
SAP_MSG_NOTIF_PING = 1,
SAP_MSG_NOTIF_PONG = 2,
SAP_MSG_NOTIF_BOTH_WAYS_MAX,
SAP_MSG_NOTIF_FROM_CSME_MIN = 500,
SAP_MSG_NOTIF_CSME_FILTERS = SAP_MSG_NOTIF_FROM_CSME_MIN,
/* 501 is deprecated */
SAP_MSG_NOTIF_AMT_STATE = 502,
SAP_MSG_NOTIF_CSME_REPLY_TO_HOST_OWNERSHIP_REQ = 503,
SAP_MSG_NOTIF_CSME_TAKING_OWNERSHIP = 504,
SAP_MSG_NOTIF_TRIGGER_IP_REFRESH = 505,
SAP_MSG_NOTIF_CSME_CAN_RELEASE_OWNERSHIP = 506,
/* 507 is deprecated */
/* 508 is deprecated */
/* 509 is deprecated */
/* 510 is deprecated */
SAP_MSG_NOTIF_NIC_OWNER = 511,
SAP_MSG_NOTIF_CSME_CONN_STATUS = 512,
SAP_MSG_NOTIF_NVM = 513,
/* 514 - 517 not supported */
SAP_MSG_NOTIF_PLDR_ACK = 518,
SAP_MSG_NOTIF_FROM_CSME_MAX,
SAP_MSG_NOTIF_FROM_HOST_MIN = 1000,
SAP_MSG_NOTIF_BAND_SELECTION = SAP_MSG_NOTIF_FROM_HOST_MIN,
SAP_MSG_NOTIF_RADIO_STATE = 1001,
SAP_MSG_NOTIF_NIC_INFO = 1002,
SAP_MSG_NOTIF_HOST_ASKS_FOR_NIC_OWNERSHIP = 1003,
SAP_MSG_NOTIF_HOST_SUSPENDS = 1004,
SAP_MSG_NOTIF_HOST_RESUMES = 1005,
SAP_MSG_NOTIF_HOST_GOES_DOWN = 1006,
SAP_MSG_NOTIF_CSME_OWNERSHIP_CONFIRMED = 1007,
SAP_MSG_NOTIF_COUNTRY_CODE = 1008,
SAP_MSG_NOTIF_HOST_LINK_UP = 1009,
SAP_MSG_NOTIF_HOST_LINK_DOWN = 1010,
SAP_MSG_NOTIF_WHO_OWNS_NIC = 1011,
SAP_MSG_NOTIF_WIFIDR_DOWN = 1012,
SAP_MSG_NOTIF_WIFIDR_UP = 1013,
/* 1014 is deprecated */
SAP_MSG_NOTIF_HOST_OWNERSHIP_CONFIRMED = 1015,
SAP_MSG_NOTIF_SAR_LIMITS = 1016,
SAP_MSG_NOTIF_GET_NVM = 1017,
/* 1018 - 1023 not supported */
SAP_MSG_NOTIF_PLDR = 1024,
SAP_MSG_NOTIF_PLDR_END = 1025,
SAP_MSG_NOTIF_FROM_HOST_MAX,
SAP_MSG_DATA_MIN = 2000,
SAP_MSG_DATA_PACKET = SAP_MSG_DATA_MIN,
SAP_MSG_CB_DATA_PACKET = 2001,
SAP_MSG_DATA_MAX,
};
/**
* struct iwl_sap_hdr - prefixes any SAP message
* @type: See &enum iwl_sap_msg.
* @len: The length of the message (header not included).
* @seq_num: For debug.
*/
struct iwl_sap_hdr {
__le16 type;
__le16 len;
__le32 seq_num;
};
/**
* struct iwl_sap_msg_dw - suits any DW long SAP message
* @hdr: The SAP header
* @val: The value of the DW.
*/
struct iwl_sap_msg_dw {
struct iwl_sap_hdr hdr;
__le32 val;
};
/**
* enum iwl_sap_nic_owner - used by %SAP_MSG_NOTIF_NIC_OWNER
* @SAP_NIC_OWNER_UNKNOWN: Not used.
* @SAP_NIC_OWNER_HOST: The host owns the NIC.
* @SAP_NIC_OWNER_ME: CSME owns the NIC.
*/
enum iwl_sap_nic_owner {
SAP_NIC_OWNER_UNKNOWN,
SAP_NIC_OWNER_HOST,
SAP_NIC_OWNER_ME,
};
enum iwl_sap_wifi_auth_type {
SAP_WIFI_AUTH_TYPE_OPEN = IWL_MEI_AKM_AUTH_OPEN,
SAP_WIFI_AUTH_TYPE_RSNA = IWL_MEI_AKM_AUTH_RSNA,
SAP_WIFI_AUTH_TYPE_RSNA_PSK = IWL_MEI_AKM_AUTH_RSNA_PSK,
SAP_WIFI_AUTH_TYPE_SAE = IWL_MEI_AKM_AUTH_SAE,
SAP_WIFI_AUTH_TYPE_MAX,
};
/**
* enum iwl_sap_wifi_cipher_alg - MEI WiFi cipher algorithm IDs
* @SAP_WIFI_CIPHER_ALG_NONE: No encryption
* @SAP_WIFI_CIPHER_ALG_TKIP: TKIPO
* @SAP_WIFI_CIPHER_ALG_CCMP: CCMP
* @SAP_WIFI_CIPHER_ALG_GCMP: GCMP-128
* @SAP_WIFI_CIPHER_ALG_GCMP_256: GCMP-256
*/
enum iwl_sap_wifi_cipher_alg {
SAP_WIFI_CIPHER_ALG_NONE = IWL_MEI_CIPHER_NONE,
SAP_WIFI_CIPHER_ALG_TKIP = IWL_MEI_CIPHER_TKIP,
SAP_WIFI_CIPHER_ALG_CCMP = IWL_MEI_CIPHER_CCMP,
SAP_WIFI_CIPHER_ALG_GCMP = IWL_MEI_CIPHER_GCMP,
SAP_WIFI_CIPHER_ALG_GCMP_256 = IWL_MEI_CIPHER_GCMP_256,
};
/**
* struct iwl_sap_notif_connection_info - nested in other structures
* @ssid_len: The length of the SSID.
* @ssid: The SSID.
* @auth_mode: The authentication mode. See &enum iwl_sap_wifi_auth_type.
* @pairwise_cipher: The cipher used for unicast packets.
* See &enum iwl_sap_wifi_cipher_alg.
* @channel: The channel on which we are associated.
* @band: The band on which we are associated.
* @reserved: For alignment.
* @bssid: The BSSID.
* @reserved1: For alignment.
*/
struct iwl_sap_notif_connection_info {
__le32 ssid_len;
u8 ssid[32];
__le32 auth_mode;
__le32 pairwise_cipher;
u8 channel;
u8 band;
__le16 reserved;
u8 bssid[6];
__le16 reserved1;
} __packed;
/**
* enum iwl_sap_scan_request - for the scan_request field
* @SCAN_REQUEST_FILTERING: Filtering is requested.
* @SCAN_REQUEST_FAST: Fast scan is requested.
*/
enum iwl_sap_scan_request {
SCAN_REQUEST_FILTERING = 1 << 0,
SCAN_REQUEST_FAST = 1 << 1,
};
/**
* struct iwl_sap_notif_conn_status - payload of %SAP_MSG_NOTIF_CSME_CONN_STATUS
* @hdr: The SAP header
* @link_prot_state: Non-zero if link protection is active.
* @scan_request: See &enum iwl_sap_scan_request.
* @conn_info: Information about the connection.
*/
struct iwl_sap_notif_conn_status {
struct iwl_sap_hdr hdr;
__le32 link_prot_state;
__le32 scan_request;
struct iwl_sap_notif_connection_info conn_info;
} __packed;
/**
* enum iwl_sap_radio_state_bitmap - used for %SAP_MSG_NOTIF_RADIO_STATE
* @SAP_SW_RFKILL_DEASSERTED: If set, SW RfKill is de-asserted
* @SAP_HW_RFKILL_DEASSERTED: If set, HW RfKill is de-asserted
*
* If both bits are set, then the radio is on.
*/
enum iwl_sap_radio_state_bitmap {
SAP_SW_RFKILL_DEASSERTED = 1 << 0,
SAP_HW_RFKILL_DEASSERTED = 1 << 1,
};
/**
* enum iwl_sap_notif_host_suspends_bitmap - used for %SAP_MSG_NOTIF_HOST_SUSPENDS
* @SAP_OFFER_NIC: TBD
* @SAP_FILTER_CONFIGURED: TBD
* @SAP_NLO_CONFIGURED: TBD
* @SAP_HOST_OWNS_NIC: TBD
* @SAP_LINK_PROTECTED: TBD
*/
enum iwl_sap_notif_host_suspends_bitmap {
SAP_OFFER_NIC = 1 << 0,
SAP_FILTER_CONFIGURED = 1 << 1,
SAP_NLO_CONFIGURED = 1 << 2,
SAP_HOST_OWNS_NIC = 1 << 3,
SAP_LINK_PROTECTED = 1 << 4,
};
/**
* struct iwl_sap_notif_country_code - payload of %SAP_MSG_NOTIF_COUNTRY_CODE
* @hdr: The SAP header
* @mcc: The country code.
* @source_id: TBD
* @reserved: For alignment.
* @diff_time: TBD
*/
struct iwl_sap_notif_country_code {
struct iwl_sap_hdr hdr;
__le16 mcc;
u8 source_id;
u8 reserved;
__le32 diff_time;
} __packed;
/**
* struct iwl_sap_notif_host_link_up - payload of %SAP_MSG_NOTIF_HOST_LINK_UP
* @hdr: The SAP header
* @conn_info: Information about the connection.
* @colloc_channel: The collocated channel
* @colloc_band: The band of the collocated channel.
* @reserved: For alignment.
* @colloc_bssid: The collocated BSSID.
* @reserved1: For alignment.
*/
struct iwl_sap_notif_host_link_up {
struct iwl_sap_hdr hdr;
struct iwl_sap_notif_connection_info conn_info;
u8 colloc_channel;
u8 colloc_band;
__le16 reserved;
u8 colloc_bssid[6];
__le16 reserved1;
} __packed;
/**
* enum iwl_sap_notif_link_down_type - used in &struct iwl_sap_notif_host_link_down
* @HOST_LINK_DOWN_TYPE_NONE: TBD
* @HOST_LINK_DOWN_TYPE_TEMPORARY: TBD
* @HOST_LINK_DOWN_TYPE_LONG: TBD
*/
enum iwl_sap_notif_link_down_type {
HOST_LINK_DOWN_TYPE_NONE,
HOST_LINK_DOWN_TYPE_TEMPORARY,
HOST_LINK_DOWN_TYPE_LONG,
};
/**
* struct iwl_sap_notif_host_link_down - payload for %SAP_MSG_NOTIF_HOST_LINK_DOWN
* @hdr: The SAP header
* @type: See &enum iwl_sap_notif_link_down_type.
* @reserved: For alignment.
* @reason_valid: If 0, ignore the next field.
* @reason: The reason of the disconnection.
*/
struct iwl_sap_notif_host_link_down {
struct iwl_sap_hdr hdr;
u8 type;
u8 reserved[2];
u8 reason_valid;
__le32 reason;
} __packed;
/**
* struct iwl_sap_notif_host_nic_info - payload for %SAP_MSG_NOTIF_NIC_INFO
* @hdr: The SAP header
* @mac_address: The MAC address as configured to the interface.
* @nvm_address: The MAC address as configured in the NVM.
*/
struct iwl_sap_notif_host_nic_info {
struct iwl_sap_hdr hdr;
u8 mac_address[6];
u8 nvm_address[6];
} __packed;
/**
* struct iwl_sap_notif_dw - payload is a dw
* @hdr: The SAP header.
* @dw: The payload.
*/
struct iwl_sap_notif_dw {
struct iwl_sap_hdr hdr;
__le32 dw;
} __packed;
/**
* struct iwl_sap_notif_sar_limits - payload for %SAP_MSG_NOTIF_SAR_LIMITS
* @hdr: The SAP header
* @sar_chain_info_table: Tx power limits.
*/
struct iwl_sap_notif_sar_limits {
struct iwl_sap_hdr hdr;
__le16 sar_chain_info_table[2][5];
} __packed;
/**
* enum iwl_sap_nvm_caps - capabilities for NVM SAP
* @SAP_NVM_CAPS_LARI_SUPPORT: Lari is supported
* @SAP_NVM_CAPS_11AX_SUPPORT: 11AX is supported
*/
enum iwl_sap_nvm_caps {
SAP_NVM_CAPS_LARI_SUPPORT = BIT(0),
SAP_NVM_CAPS_11AX_SUPPORT = BIT(1),
};
/**
* struct iwl_sap_nvm - payload for %SAP_MSG_NOTIF_NVM
* @hdr: The SAP header.
* @hw_addr: The MAC address
* @n_hw_addrs: The number of MAC addresses
* @reserved: For alignment.
* @radio_cfg: The radio configuration.
* @caps: See &enum iwl_sap_nvm_caps.
* @nvm_version: The version of the NVM.
* @channels: The data for each channel.
*/
struct iwl_sap_nvm {
struct iwl_sap_hdr hdr;
u8 hw_addr[6];
u8 n_hw_addrs;
u8 reserved;
__le32 radio_cfg;
__le32 caps;
__le32 nvm_version;
__le32 channels[110];
} __packed;
/**
* enum iwl_sap_eth_filter_flags - used in &struct iwl_sap_eth_filter
* @SAP_ETH_FILTER_STOP: Do not process further filters.
* @SAP_ETH_FILTER_COPY: Copy the packet to the CSME.
* @SAP_ETH_FILTER_ENABLED: If false, the filter should be ignored.
*/
enum iwl_sap_eth_filter_flags {
SAP_ETH_FILTER_STOP = BIT(0),
SAP_ETH_FILTER_COPY = BIT(1),
SAP_ETH_FILTER_ENABLED = BIT(2),
};
/**
* struct iwl_sap_eth_filter - a L2 filter
* @mac_address: Address to filter.
* @flags: See &enum iwl_sap_eth_filter_flags.
*/
struct iwl_sap_eth_filter {
u8 mac_address[6];
u8 flags;
} __packed;
/**
* enum iwl_sap_flex_filter_flags - used in &struct iwl_sap_flex_filter
* @SAP_FLEX_FILTER_COPY: Pass UDP / TCP packets to CSME.
* @SAP_FLEX_FILTER_ENABLED: If false, the filter should be ignored.
* @SAP_FLEX_FILTER_IPV4: Filter requires match on the IP address as well.
* @SAP_FLEX_FILTER_IPV6: Filter requires match on the IP address as well.
* @SAP_FLEX_FILTER_TCP: Filter should be applied on TCP packets.
* @SAP_FLEX_FILTER_UDP: Filter should be applied on UDP packets.
*/
enum iwl_sap_flex_filter_flags {
SAP_FLEX_FILTER_COPY = BIT(0),
SAP_FLEX_FILTER_ENABLED = BIT(1),
SAP_FLEX_FILTER_IPV6 = BIT(2),
SAP_FLEX_FILTER_IPV4 = BIT(3),
SAP_FLEX_FILTER_TCP = BIT(4),
SAP_FLEX_FILTER_UDP = BIT(5),
};
/**
* struct iwl_sap_flex_filter - filter configuration
* @src_port: Source port in network format.
* @dst_port: Destination port in network format.
* @flags: Flags and protocol, see &enum iwl_sap_flex_filter_flags.
* @reserved: For alignment.
*/
struct iwl_sap_flex_filter {
__be16 src_port;
__be16 dst_port;
u8 flags;
u8 reserved;
} __packed;
/**
* enum iwl_sap_ipv4_filter_flags - used in &struct iwl_sap_ipv4_filter
* @SAP_IPV4_FILTER_ICMP_PASS: Pass ICMP packets to CSME.
* @SAP_IPV4_FILTER_ICMP_COPY: Pass ICMP packets to host.
* @SAP_IPV4_FILTER_ARP_REQ_PASS: Pass ARP requests to CSME.
* @SAP_IPV4_FILTER_ARP_REQ_COPY: Pass ARP requests to host.
* @SAP_IPV4_FILTER_ARP_RESP_PASS: Pass ARP responses to CSME.
* @SAP_IPV4_FILTER_ARP_RESP_COPY: Pass ARP responses to host.
*/
enum iwl_sap_ipv4_filter_flags {
SAP_IPV4_FILTER_ICMP_PASS = BIT(0),
SAP_IPV4_FILTER_ICMP_COPY = BIT(1),
SAP_IPV4_FILTER_ARP_REQ_PASS = BIT(2),
SAP_IPV4_FILTER_ARP_REQ_COPY = BIT(3),
SAP_IPV4_FILTER_ARP_RESP_PASS = BIT(4),
SAP_IPV4_FILTER_ARP_RESP_COPY = BIT(5),
};
/**
* struct iwl_sap_ipv4_filter - IPv4 filter configuration
* @ipv4_addr: The IP address to filer.
* @flags: See &enum iwl_sap_ipv4_filter_flags.
*/
struct iwl_sap_ipv4_filter {
__be32 ipv4_addr;
__le32 flags;
} __packed;
/**
* enum iwl_sap_ipv6_filter_flags - IPv6 filter flags
* @SAP_IPV6_ADDR_FILTER_COPY: Pass packets to the host.
* @SAP_IPV6_ADDR_FILTER_ENABLED: If false, the filter should be ignored.
*/
enum iwl_sap_ipv6_filter_flags {
SAP_IPV6_ADDR_FILTER_COPY = BIT(0),
SAP_IPV6_ADDR_FILTER_ENABLED = BIT(1),
};
/**
* struct iwl_sap_ipv6_filter - IPv6 filter configuration
* @addr_lo24: Lowest 24 bits of the IPv6 address.
* @flags: See &enum iwl_sap_ipv6_filter_flags.
*/
struct iwl_sap_ipv6_filter {
u8 addr_lo24[3];
u8 flags;
} __packed;
/**
* enum iwl_sap_icmpv6_filter_flags - ICMPv6 filter flags
* @SAP_ICMPV6_FILTER_ENABLED: If false, the filter should be ignored.
* @SAP_ICMPV6_FILTER_COPY: Pass packets to the host.
*/
enum iwl_sap_icmpv6_filter_flags {
SAP_ICMPV6_FILTER_ENABLED = BIT(0),
SAP_ICMPV6_FILTER_COPY = BIT(1),
};
/**
* enum iwl_sap_vlan_filter_flags - VLAN filter flags
* @SAP_VLAN_FILTER_VLAN_ID_MSK: VLAN ID
* @SAP_VLAN_FILTER_ENABLED: If false, the filter should be ignored.
*/
enum iwl_sap_vlan_filter_flags {
SAP_VLAN_FILTER_VLAN_ID_MSK = 0x0FFF,
SAP_VLAN_FILTER_ENABLED = BIT(15),
};
/**
* struct iwl_sap_oob_filters - Out of band filters (for RX only)
* @flex_filters: Array of &struct iwl_sap_flex_filter.
* @icmpv6_flags: See &enum iwl_sap_icmpv6_filter_flags.
* @ipv6_filters: Array of &struct iwl_sap_ipv6_filter.
* @eth_filters: Array of &struct iwl_sap_eth_filter.
* @reserved: For alignment.
* @ipv4_filter: &struct iwl_sap_ipv4_filter.
* @vlan: See &enum iwl_sap_vlan_filter_flags.
*/
struct iwl_sap_oob_filters {
struct iwl_sap_flex_filter flex_filters[14];
__le32 icmpv6_flags;
struct iwl_sap_ipv6_filter ipv6_filters[4];
struct iwl_sap_eth_filter eth_filters[5];
u8 reserved;
struct iwl_sap_ipv4_filter ipv4_filter;
__le16 vlan[4];
} __packed;
/**
* struct iwl_sap_csme_filters - payload of %SAP_MSG_NOTIF_CSME_FILTERS
* @hdr: The SAP header.
* @mode: Not used.
* @mac_address: Not used.
* @reserved: For alignment.
* @cbfilters: Not used.
* @filters: Out of band filters.
*/
struct iwl_sap_csme_filters {
struct iwl_sap_hdr hdr;
__le32 mode;
u8 mac_address[6];
__le16 reserved;
u8 cbfilters[1728];
struct iwl_sap_oob_filters filters;
} __packed;
#define CB_TX_DHCP_FILT_IDX 30
/**
* struct iwl_sap_cb_data - header to be added for transmitted packets.
* @hdr: The SAP header.
* @reserved: Not used.
* @to_me_filt_status: The filter that matches. Bit %CB_TX_DHCP_FILT_IDX should
* be set for DHCP (the only packet that uses this header).
* @reserved2: Not used.
* @data_len: The length of the payload.
* @payload: The payload of the transmitted packet.
*/
struct iwl_sap_cb_data {
struct iwl_sap_hdr hdr;
__le32 reserved[7];
__le32 to_me_filt_status;
__le32 reserved2;
__le32 data_len;
u8 payload[];
};
/**
* struct iwl_sap_pldr_data - payload of %SAP_MSG_NOTIF_PLDR
* @hdr: The SAP header.
* @version: SAP message version
*/
struct iwl_sap_pldr_data {
struct iwl_sap_hdr hdr;
__le32 version;
} __packed;
/**
* enum iwl_sap_pldr_status - product reset status
* @SAP_PLDR_STATUS_SUCCESS: PLDR started/ended successfully
* @SAP_PLDR_STATUS_FAILURE: PLDR failed to start/end
*/
enum iwl_sap_pldr_status {
SAP_PLDR_STATUS_SUCCESS = 0,
SAP_PLDR_STATUS_FAILURE = 1,
};
/*
* struct iwl_sap_pldr_end_data - payload of %SAP_MSG_NOTIF_PLDR_END
* @hdr: The SAP header.
* @version: SAP message version
* @status: PLDR end status
*/
struct iwl_sap_pldr_end_data {
struct iwl_sap_hdr hdr;
__le32 version;
__le32 status;
} __packed;
/*
* struct iwl_sap_pldr_ack_data - payload of %SAP_MSG_NOTIF_PLDR_ACK
* @version: SAP message version
* @status: CSME accept/refuse to the PLDR request
*/
struct iwl_sap_pldr_ack_data {
struct iwl_sap_hdr hdr;
__le32 version;
__le32 status;
} __packed;
#endif /* __sap_h__ */
@@ -0,0 +1,82 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright(c) 2021 Intel Corporation
*/
#if !defined(CONFIG_IWLWIFI_DEVICE_TRACING)
#define trace_iwlmei_sap_data(...)
#else
#if !defined(__IWLWIFI_DEVICE_TRACE_IWLWIFI_SAP_DATA) || defined(TRACE_HEADER_MULTI_READ)
#ifndef __IWLWIFI_DEVICE_TRACE_IWLWIFI_SAP_DATA
enum iwl_sap_data_trace_type {
IWL_SAP_RX_DATA_TO_AIR,
IWL_SAP_TX_DATA_FROM_AIR,
IWL_SAP_RX_DATA_DROPPED_FROM_AIR,
IWL_SAP_TX_DHCP,
};
static inline size_t
iwlmei_sap_data_offset(enum iwl_sap_data_trace_type trace_type)
{
switch (trace_type) {
case IWL_SAP_RX_DATA_TO_AIR:
return 0;
case IWL_SAP_TX_DATA_FROM_AIR:
case IWL_SAP_RX_DATA_DROPPED_FROM_AIR:
return sizeof(struct iwl_sap_hdr);
case IWL_SAP_TX_DHCP:
return sizeof(struct iwl_sap_cb_data);
default:
WARN_ON_ONCE(1);
}
return 0;
}
#endif
#define __IWLWIFI_DEVICE_TRACE_IWLWIFI_SAP_DATA
#include <linux/tracepoint.h>
#include <linux/skbuff.h>
#include "sap.h"
#undef TRACE_SYSTEM
#define TRACE_SYSTEM iwlmei_sap_data
TRACE_EVENT(iwlmei_sap_data,
TP_PROTO(const struct sk_buff *skb,
enum iwl_sap_data_trace_type trace_type),
TP_ARGS(skb, trace_type),
TP_STRUCT__entry(
__dynamic_array(u8, data,
skb->len - iwlmei_sap_data_offset(trace_type))
__field(u32, trace_type)
),
TP_fast_assign(
size_t offset = iwlmei_sap_data_offset(trace_type);
__entry->trace_type = trace_type;
skb_copy_bits(skb, offset, __get_dynamic_array(data),
skb->len - offset);
),
TP_printk("sap_data:trace_type %d len %d",
__entry->trace_type, __get_dynamic_array_len(data))
);
/*
* If you add something here, add a stub in case
* !defined(CONFIG_IWLWIFI_DEVICE_TRACING)
*/
#endif /* __IWLWIFI_DEVICE_TRACE_IWLWIFI_SAP_DATA */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH .
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE trace-data
#include <trace/define_trace.h>
#endif /* CONFIG_IWLWIFI_DEVICE_TRACING */
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2021 Intel Corporation
*/
#include <linux/module.h>
/* sparse doesn't like tracepoint macros */
#ifndef __CHECKER__
#define CREATE_TRACE_POINTS
#include "trace.h"
#include "trace-data.h"
#endif /* __CHECKER__ */
@@ -0,0 +1,76 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright(c) 2021 Intel Corporation
*/
#if !defined(CONFIG_IWLWIFI_DEVICE_TRACING)
#define trace_iwlmei_sap_cmd(...)
#define trace_iwlmei_me_msg(...)
#else
#if !defined(__IWLWIFI_DEVICE_TRACE_IWLWIFI_SAP_CMD) || defined(TRACE_HEADER_MULTI_READ)
#define __IWLWIFI_DEVICE_TRACE_IWLWIFI_SAP_CMD
#include <linux/tracepoint.h>
#undef TRACE_SYSTEM
#define TRACE_SYSTEM iwlmei_sap_cmd
#include "mei/sap.h"
TRACE_EVENT(iwlmei_sap_cmd,
TP_PROTO(const struct iwl_sap_hdr *sap_cmd, bool tx),
TP_ARGS(sap_cmd, tx),
TP_STRUCT__entry(
__dynamic_array(u8, cmd,
le16_to_cpu(sap_cmd->len) + sizeof(*sap_cmd))
__field(u8, tx)
__field(u16, type)
__field(u16, len)
__field(u32, seq)
),
TP_fast_assign(
memcpy(__get_dynamic_array(cmd), sap_cmd,
le16_to_cpu(sap_cmd->len) + sizeof(*sap_cmd));
__entry->tx = tx;
__entry->type = le16_to_cpu(sap_cmd->type);
__entry->len = le16_to_cpu(sap_cmd->len);
__entry->seq = le32_to_cpu(sap_cmd->seq_num);
),
TP_printk("sap_cmd %s: type %d len %d seq %d", __entry->tx ? "Tx" : "Rx",
__entry->type, __entry->len, __entry->seq)
);
TRACE_EVENT(iwlmei_me_msg,
TP_PROTO(const struct iwl_sap_me_msg_hdr *hdr, bool tx),
TP_ARGS(hdr, tx),
TP_STRUCT__entry(
__field(u8, type)
__field(u8, tx)
__field(u32, seq_num)
),
TP_fast_assign(
__entry->type = le32_to_cpu(hdr->type);
__entry->seq_num = le32_to_cpu(hdr->seq_num);
__entry->tx = tx;
),
TP_printk("ME message: %s: type %d seq %d", __entry->tx ? "Tx" : "Rx",
__entry->type, __entry->seq_num)
);
/*
* If you add something here, add a stub in case
* !defined(CONFIG_IWLWIFI_DEVICE_TRACING)
*/
#endif /* __IWLWIFI_DEVICE_TRACE_IWLWIFI_SAP_CMD */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH .
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE trace
#include <trace/define_trace.h>
#endif /* CONFIG_IWLWIFI_DEVICE_TRACING */