| 1 |
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
| 2 |
/* |
| 3 |
* Copyright (C) 2024-2025 Intel Corporation |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "mld.h" |
| 7 |
#include "notif.h" |
| 8 |
#include "scan.h" |
| 9 |
#include "iface.h" |
| 10 |
#include "mlo.h" |
| 11 |
#include "iwl-trans.h" |
| 12 |
#include "fw/file.h" |
| 13 |
#include "fw/dbg.h" |
| 14 |
#include "fw/api/cmdhdr.h" |
| 15 |
#include "fw/api/mac-cfg.h" |
| 16 |
#include "session-protect.h" |
| 17 |
#include "fw/api/time-event.h" |
| 18 |
#include "fw/api/tx.h" |
| 19 |
#include "fw/api/rs.h" |
| 20 |
#include "fw/api/offload.h" |
| 21 |
#include "fw/api/stats.h" |
| 22 |
#include "fw/api/rfi.h" |
| 23 |
#include "fw/api/coex.h" |
| 24 |
|
| 25 |
#include "mcc.h" |
| 26 |
#include "link.h" |
| 27 |
#include "tx.h" |
| 28 |
#include "rx.h" |
| 29 |
#include "tlc.h" |
| 30 |
#include "agg.h" |
| 31 |
#include "mac80211.h" |
| 32 |
#include "thermal.h" |
| 33 |
#include "roc.h" |
| 34 |
#include "stats.h" |
| 35 |
#include "coex.h" |
| 36 |
#include "time_sync.h" |
| 37 |
#include "ftm-initiator.h" |
| 38 |
|
| 39 |
/* Please use this in an increasing order of the versions */ |
| 40 |
#define CMD_VER_ENTRY(_ver, _struct) \ |
| 41 |
{ .size = sizeof(struct _struct), .ver = _ver }, |
| 42 |
#define CMD_VERSIONS(name, ...) \ |
| 43 |
static const struct iwl_notif_struct_size \ |
| 44 |
iwl_notif_struct_sizes_##name[] = { __VA_ARGS__ }; |
| 45 |
|
| 46 |
#define RX_HANDLER_NO_OBJECT(_grp, _cmd, _name, _context) \ |
| 47 |
{.cmd_id = WIDE_ID(_grp, _cmd), \ |
| 48 |
.context = _context, \ |
| 49 |
.fn = iwl_mld_handle_##_name, \ |
| 50 |
.sizes = iwl_notif_struct_sizes_##_name, \ |
| 51 |
.n_sizes = ARRAY_SIZE(iwl_notif_struct_sizes_##_name), \ |
| 52 |
}, |
| 53 |
|
| 54 |
/* Use this for Rx handlers that do not need notification validation */ |
| 55 |
#define RX_HANDLER_NO_VAL(_grp, _cmd, _name, _context) \ |
| 56 |
{.cmd_id = WIDE_ID(_grp, _cmd), \ |
| 57 |
.context = _context, \ |
| 58 |
.fn = iwl_mld_handle_##_name, \ |
| 59 |
}, |
| 60 |
|
| 61 |
#define RX_HANDLER_VAL_FN(_grp, _cmd, _name, _context) \ |
| 62 |
{ .cmd_id = WIDE_ID(_grp, _cmd), \ |
| 63 |
.context = _context, \ |
| 64 |
.fn = iwl_mld_handle_##_name, \ |
| 65 |
.val_fn = iwl_mld_validate_##_name, \ |
| 66 |
}, |
| 67 |
|
| 68 |
#define DEFINE_SIMPLE_CANCELLATION(name, notif_struct, id_member) \ |
| 69 |
static bool iwl_mld_cancel_##name##_notif(struct iwl_mld *mld, \ |
| 70 |
struct iwl_rx_packet *pkt, \ |
| 71 |
u32 obj_id) \ |
| 72 |
{ \ |
| 73 |
const struct notif_struct *notif = (const void *)pkt->data; \ |
| 74 |
\ |
| 75 |
return obj_id == _Generic((notif)->id_member, \ |
| 76 |
__le32: le32_to_cpu((notif)->id_member), \ |
| 77 |
__le16: le16_to_cpu((notif)->id_member), \ |
| 78 |
u8: (notif)->id_member); \ |
| 79 |
} |
| 80 |
|
| 81 |
/* Currently only defined for the RX_HANDLER_SIZES options. Use this for |
| 82 |
* notifications that belong to a specific object, and that should be |
| 83 |
* canceled when the object is removed |
| 84 |
*/ |
| 85 |
#define RX_HANDLER_OF_OBJ(_grp, _cmd, _name, _obj_type) \ |
| 86 |
{.cmd_id = WIDE_ID(_grp, _cmd), \ |
| 87 |
/* Only async handlers can be canceled */ \ |
| 88 |
.context = RX_HANDLER_ASYNC, \ |
| 89 |
.fn = iwl_mld_handle_##_name, \ |
| 90 |
.sizes = iwl_notif_struct_sizes_##_name, \ |
| 91 |
.n_sizes = ARRAY_SIZE(iwl_notif_struct_sizes_##_name), \ |
| 92 |
.obj_type = IWL_MLD_OBJECT_TYPE_##_obj_type, \ |
| 93 |
.cancel = iwl_mld_cancel_##_name, \ |
| 94 |
}, |
| 95 |
|
| 96 |
#define RX_HANDLER_OF_LINK(_grp, _cmd, _name) \ |
| 97 |
RX_HANDLER_OF_OBJ(_grp, _cmd, _name, LINK) \ |
| 98 |
|
| 99 |
#define RX_HANDLER_OF_VIF(_grp, _cmd, _name) \ |
| 100 |
RX_HANDLER_OF_OBJ(_grp, _cmd, _name, VIF) \ |
| 101 |
|
| 102 |
#define RX_HANDLER_OF_STA(_grp, _cmd, _name) \ |
| 103 |
RX_HANDLER_OF_OBJ(_grp, _cmd, _name, STA) \ |
| 104 |
|
| 105 |
#define RX_HANDLER_OF_ROC(_grp, _cmd, _name) \ |
| 106 |
RX_HANDLER_OF_OBJ(_grp, _cmd, _name, ROC) |
| 107 |
|
| 108 |
#define RX_HANDLER_OF_SCAN(_grp, _cmd, _name) \ |
| 109 |
RX_HANDLER_OF_OBJ(_grp, _cmd, _name, SCAN) |
| 110 |
|
| 111 |
#define RX_HANDLER_OF_FTM_REQ(_grp, _cmd, _name) \ |
| 112 |
RX_HANDLER_OF_OBJ(_grp, _cmd, _name, FTM_REQ) |
| 113 |
|
| 114 |
#define RX_HANDLER_OF_NAN(_grp, _cmd, _name) \ |
| 115 |
RX_HANDLER_OF_OBJ(_grp, _cmd, _name, NAN) |
| 116 |
|
| 117 |
static void iwl_mld_handle_mfuart_notif(struct iwl_mld *mld, |
| 118 |
struct iwl_rx_packet *pkt) |
| 119 |
{ |
| 120 |
struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data; |
| 121 |
|
| 122 |
IWL_DEBUG_INFO(mld, |
| 123 |
"MFUART: installed ver: 0x%08x, external ver: 0x%08x\n", |
| 124 |
le32_to_cpu(mfuart_notif->installed_ver), |
| 125 |
le32_to_cpu(mfuart_notif->external_ver)); |
| 126 |
IWL_DEBUG_INFO(mld, |
| 127 |
"MFUART: status: 0x%08x, duration: 0x%08x image size: 0x%08x\n", |
| 128 |
le32_to_cpu(mfuart_notif->status), |
| 129 |
le32_to_cpu(mfuart_notif->duration), |
| 130 |
le32_to_cpu(mfuart_notif->image_size)); |
| 131 |
} |
| 132 |
|
| 133 |
static void iwl_mld_mu_mimo_iface_iterator(void *_data, u8 *mac, |
| 134 |
struct ieee80211_vif *vif) |
| 135 |
{ |
| 136 |
struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 137 |
unsigned int link_id = 0; |
| 138 |
|
| 139 |
if (WARN(hweight16(vif->active_links) > 1, |
| 140 |
"no support for this notif while in EMLSR 0x%x\n", |
| 141 |
vif->active_links)) |
| 142 |
return; |
| 143 |
|
| 144 |
if (ieee80211_vif_is_mld(vif)) { |
| 145 |
link_id = __ffs(vif->active_links); |
| 146 |
bss_conf = link_conf_dereference_check(vif, link_id); |
| 147 |
} |
| 148 |
|
| 149 |
if (!WARN_ON(!bss_conf) && bss_conf->mu_mimo_owner) { |
| 150 |
const struct iwl_mu_group_mgmt_notif *notif = _data; |
| 151 |
|
| 152 |
BUILD_BUG_ON(sizeof(notif->membership_status) != |
| 153 |
WLAN_MEMBERSHIP_LEN); |
| 154 |
BUILD_BUG_ON(sizeof(notif->user_position) != |
| 155 |
WLAN_USER_POSITION_LEN); |
| 156 |
|
| 157 |
/* MU-MIMO Group Id action frame is little endian. We treat |
| 158 |
* the data received from firmware as if it came from the |
| 159 |
* action frame, so no conversion is needed. |
| 160 |
*/ |
| 161 |
ieee80211_update_mu_groups(vif, link_id, |
| 162 |
(u8 *)¬if->membership_status, |
| 163 |
(u8 *)¬if->user_position); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
/* This handler is called in SYNC mode because it needs to be serialized with |
| 168 |
* Rx as specified in ieee80211_update_mu_groups()'s documentation. |
| 169 |
*/ |
| 170 |
static void iwl_mld_handle_mu_mimo_grp_notif(struct iwl_mld *mld, |
| 171 |
struct iwl_rx_packet *pkt) |
| 172 |
{ |
| 173 |
struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; |
| 174 |
|
| 175 |
ieee80211_iterate_active_interfaces_atomic(mld->hw, |
| 176 |
IEEE80211_IFACE_ITER_NORMAL, |
| 177 |
iwl_mld_mu_mimo_iface_iterator, |
| 178 |
notif); |
| 179 |
} |
| 180 |
|
| 181 |
static void |
| 182 |
iwl_mld_handle_channel_switch_start_notif(struct iwl_mld *mld, |
| 183 |
struct iwl_rx_packet *pkt) |
| 184 |
{ |
| 185 |
struct iwl_channel_switch_start_notif *notif = (void *)pkt->data; |
| 186 |
u32 link_id = le32_to_cpu(notif->link_id); |
| 187 |
struct ieee80211_bss_conf *link_conf = |
| 188 |
iwl_mld_fw_id_to_link_conf(mld, link_id); |
| 189 |
struct ieee80211_vif *vif; |
| 190 |
|
| 191 |
if (WARN_ON(!link_conf)) |
| 192 |
return; |
| 193 |
|
| 194 |
vif = link_conf->vif; |
| 195 |
|
| 196 |
IWL_DEBUG_INFO(mld, |
| 197 |
"CSA Start Notification with vif type: %d, link_id: %d\n", |
| 198 |
vif->type, |
| 199 |
link_conf->link_id); |
| 200 |
|
| 201 |
switch (vif->type) { |
| 202 |
case NL80211_IFTYPE_AP: |
| 203 |
/* We don't support canceling a CSA as it was advertised |
| 204 |
* by the AP itself |
| 205 |
*/ |
| 206 |
if (!link_conf->csa_active) |
| 207 |
return; |
| 208 |
|
| 209 |
ieee80211_csa_finish(vif, link_conf->link_id); |
| 210 |
break; |
| 211 |
case NL80211_IFTYPE_STATION: |
| 212 |
if (!link_conf->csa_active) { |
| 213 |
/* Either unexpected cs notif or mac80211 chose to |
| 214 |
* ignore, for example in channel switch to same channel |
| 215 |
*/ |
| 216 |
struct iwl_cancel_channel_switch_cmd cmd = { |
| 217 |
.id = cpu_to_le32(link_id), |
| 218 |
}; |
| 219 |
|
| 220 |
if (iwl_mld_send_cmd_pdu(mld, |
| 221 |
WIDE_ID(MAC_CONF_GROUP, |
| 222 |
CANCEL_CHANNEL_SWITCH_CMD), |
| 223 |
&cmd)) |
| 224 |
IWL_ERR(mld, |
| 225 |
"Failed to cancel the channel switch\n"); |
| 226 |
return; |
| 227 |
} |
| 228 |
|
| 229 |
ieee80211_chswitch_done(vif, true, link_conf->link_id); |
| 230 |
break; |
| 231 |
|
| 232 |
default: |
| 233 |
WARN(1, "CSA on invalid vif type: %d", vif->type); |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
static void |
| 238 |
iwl_mld_handle_channel_switch_error_notif(struct iwl_mld *mld, |
| 239 |
struct iwl_rx_packet *pkt) |
| 240 |
{ |
| 241 |
struct iwl_channel_switch_error_notif *notif = (void *)pkt->data; |
| 242 |
struct ieee80211_bss_conf *link_conf; |
| 243 |
struct ieee80211_vif *vif; |
| 244 |
u32 link_id = le32_to_cpu(notif->link_id); |
| 245 |
u32 csa_err_mask = le32_to_cpu(notif->csa_err_mask); |
| 246 |
|
| 247 |
link_conf = iwl_mld_fw_id_to_link_conf(mld, link_id); |
| 248 |
if (WARN_ON(!link_conf)) |
| 249 |
return; |
| 250 |
|
| 251 |
vif = link_conf->vif; |
| 252 |
|
| 253 |
IWL_DEBUG_INFO(mld, "FW reports CSA error: id=%u, csa_err_mask=%u\n", |
| 254 |
link_id, csa_err_mask); |
| 255 |
|
| 256 |
if (csa_err_mask & (CS_ERR_COUNT_ERROR | |
| 257 |
CS_ERR_LONG_DELAY_AFTER_CS | |
| 258 |
CS_ERR_TX_BLOCK_TIMER_EXPIRED)) |
| 259 |
ieee80211_channel_switch_disconnect(vif); |
| 260 |
} |
| 261 |
|
| 262 |
static void iwl_mld_handle_beacon_notification(struct iwl_mld *mld, |
| 263 |
struct iwl_rx_packet *pkt) |
| 264 |
{ |
| 265 |
struct iwl_extended_beacon_notif *beacon = (void *)pkt->data; |
| 266 |
|
| 267 |
mld->ibss_manager = !!beacon->ibss_mgr_status; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* DOC: Notification versioning |
| 272 |
* |
| 273 |
* The firmware's notifications change from time to time. In order to |
| 274 |
* differentiate between different versions of the same notification, the |
| 275 |
* firmware advertises the version of each notification. |
| 276 |
* Here are listed all the notifications that are supported. Several versions |
| 277 |
* of the same notification can be allowed at the same time: |
| 278 |
* |
| 279 |
* CMD_VERSION(my_multi_version_notif, |
| 280 |
* CMD_VER_ENTRY(1, iwl_my_multi_version_notif_ver1) |
| 281 |
* CMD_VER_ENTRY(2, iwl_my_multi_version_notif_ver2) |
| 282 |
* |
| 283 |
* etc... |
| 284 |
* |
| 285 |
* The driver will enforce that the notification coming from the firmware |
| 286 |
* has its version listed here and it'll also enforce that the firmware sent |
| 287 |
* at least enough bytes to cover the structure listed in the CMD_VER_ENTRY. |
| 288 |
*/ |
| 289 |
|
| 290 |
CMD_VERSIONS(scan_start_notif, |
| 291 |
CMD_VER_ENTRY(1, iwl_umac_scan_start)) |
| 292 |
CMD_VERSIONS(scan_complete_notif, |
| 293 |
CMD_VER_ENTRY(1, iwl_umac_scan_complete)) |
| 294 |
CMD_VERSIONS(scan_iter_complete_notif, |
| 295 |
CMD_VER_ENTRY(2, iwl_umac_scan_iter_complete_notif)) |
| 296 |
CMD_VERSIONS(channel_survey_notif, |
| 297 |
CMD_VER_ENTRY(1, iwl_umac_scan_channel_survey_notif)) |
| 298 |
CMD_VERSIONS(mfuart_notif, |
| 299 |
CMD_VER_ENTRY(2, iwl_mfuart_load_notif)) |
| 300 |
CMD_VERSIONS(update_mcc, |
| 301 |
CMD_VER_ENTRY(1, iwl_mcc_chub_notif)) |
| 302 |
CMD_VERSIONS(session_prot_notif, |
| 303 |
CMD_VER_ENTRY(3, iwl_session_prot_notif)) |
| 304 |
CMD_VERSIONS(missed_beacon_notif, |
| 305 |
CMD_VER_ENTRY(5, iwl_missed_beacons_notif)) |
| 306 |
CMD_VERSIONS(tx_resp_notif, |
| 307 |
CMD_VER_ENTRY(8, iwl_tx_resp) |
| 308 |
CMD_VER_ENTRY(9, iwl_tx_resp)) |
| 309 |
CMD_VERSIONS(compressed_ba_notif, |
| 310 |
CMD_VER_ENTRY(5, iwl_compressed_ba_notif) |
| 311 |
CMD_VER_ENTRY(6, iwl_compressed_ba_notif) |
| 312 |
CMD_VER_ENTRY(7, iwl_compressed_ba_notif)) |
| 313 |
CMD_VERSIONS(tlc_notif, |
| 314 |
CMD_VER_ENTRY(3, iwl_tlc_update_notif) |
| 315 |
CMD_VER_ENTRY(4, iwl_tlc_update_notif)) |
| 316 |
CMD_VERSIONS(mu_mimo_grp_notif, |
| 317 |
CMD_VER_ENTRY(1, iwl_mu_group_mgmt_notif)) |
| 318 |
CMD_VERSIONS(channel_switch_start_notif, |
| 319 |
CMD_VER_ENTRY(3, iwl_channel_switch_start_notif)) |
| 320 |
CMD_VERSIONS(channel_switch_error_notif, |
| 321 |
CMD_VER_ENTRY(2, iwl_channel_switch_error_notif)) |
| 322 |
CMD_VERSIONS(ct_kill_notif, |
| 323 |
CMD_VER_ENTRY(2, ct_kill_notif)) |
| 324 |
CMD_VERSIONS(temp_notif, |
| 325 |
CMD_VER_ENTRY(2, iwl_dts_measurement_notif)) |
| 326 |
CMD_VERSIONS(roc_notif, |
| 327 |
CMD_VER_ENTRY(1, iwl_roc_notif)) |
| 328 |
CMD_VERSIONS(probe_resp_data_notif, |
| 329 |
CMD_VER_ENTRY(1, iwl_probe_resp_data_notif)) |
| 330 |
CMD_VERSIONS(datapath_monitor_notif, |
| 331 |
CMD_VER_ENTRY(1, iwl_datapath_monitor_notif)) |
| 332 |
CMD_VERSIONS(stats_oper_notif, |
| 333 |
CMD_VER_ENTRY(3, iwl_system_statistics_notif_oper)) |
| 334 |
CMD_VERSIONS(stats_oper_part1_notif, |
| 335 |
CMD_VER_ENTRY(4, iwl_system_statistics_part1_notif_oper)) |
| 336 |
CMD_VERSIONS(bt_coex_notif, |
| 337 |
CMD_VER_ENTRY(1, iwl_bt_coex_profile_notif)) |
| 338 |
CMD_VERSIONS(beacon_notification, |
| 339 |
CMD_VER_ENTRY(6, iwl_extended_beacon_notif)) |
| 340 |
CMD_VERSIONS(emlsr_mode_notif, |
| 341 |
CMD_VER_ENTRY(2, iwl_esr_mode_notif)) |
| 342 |
CMD_VERSIONS(emlsr_trans_fail_notif, |
| 343 |
CMD_VER_ENTRY(1, iwl_esr_trans_fail_notif)) |
| 344 |
CMD_VERSIONS(uapsd_misbehaving_ap_notif, |
| 345 |
CMD_VER_ENTRY(1, iwl_uapsd_misbehaving_ap_notif)) |
| 346 |
CMD_VERSIONS(time_msmt_notif, |
| 347 |
CMD_VER_ENTRY(1, iwl_time_msmt_notify)) |
| 348 |
CMD_VERSIONS(time_sync_confirm_notif, |
| 349 |
CMD_VER_ENTRY(1, iwl_time_msmt_cfm_notify)) |
| 350 |
CMD_VERSIONS(ftm_resp_notif, CMD_VER_ENTRY(10, iwl_tof_range_rsp_ntfy)) |
| 351 |
CMD_VERSIONS(beacon_filter_notif, CMD_VER_ENTRY(2, iwl_beacon_filter_notif)) |
| 352 |
CMD_VERSIONS(nan_cluster_notif, CMD_VER_ENTRY(1, iwl_nan_cluster_notif)) |
| 353 |
CMD_VERSIONS(nan_dw_end_notif, CMD_VER_ENTRY(1, iwl_nan_dw_end_notif)) |
| 354 |
|
| 355 |
DEFINE_SIMPLE_CANCELLATION(session_prot, iwl_session_prot_notif, mac_link_id) |
| 356 |
DEFINE_SIMPLE_CANCELLATION(tlc, iwl_tlc_update_notif, sta_id) |
| 357 |
DEFINE_SIMPLE_CANCELLATION(channel_switch_start, |
| 358 |
iwl_channel_switch_start_notif, link_id) |
| 359 |
DEFINE_SIMPLE_CANCELLATION(channel_switch_error, |
| 360 |
iwl_channel_switch_error_notif, link_id) |
| 361 |
DEFINE_SIMPLE_CANCELLATION(datapath_monitor, iwl_datapath_monitor_notif, |
| 362 |
link_id) |
| 363 |
DEFINE_SIMPLE_CANCELLATION(roc, iwl_roc_notif, activity) |
| 364 |
DEFINE_SIMPLE_CANCELLATION(scan_complete, iwl_umac_scan_complete, uid) |
| 365 |
DEFINE_SIMPLE_CANCELLATION(scan_start, iwl_umac_scan_start, uid) |
| 366 |
DEFINE_SIMPLE_CANCELLATION(probe_resp_data, iwl_probe_resp_data_notif, |
| 367 |
mac_id) |
| 368 |
DEFINE_SIMPLE_CANCELLATION(uapsd_misbehaving_ap, iwl_uapsd_misbehaving_ap_notif, |
| 369 |
mac_id) |
| 370 |
DEFINE_SIMPLE_CANCELLATION(ftm_resp, iwl_tof_range_rsp_ntfy, request_id) |
| 371 |
DEFINE_SIMPLE_CANCELLATION(beacon_filter, iwl_beacon_filter_notif, link_id) |
| 372 |
|
| 373 |
/** |
| 374 |
* DOC: Handlers for fw notifications |
| 375 |
* |
| 376 |
* Here are listed the notifications IDs (including the group ID), the handler |
| 377 |
* of the notification and how it should be called: |
| 378 |
* |
| 379 |
* - RX_HANDLER_SYNC: will be called as part of the Rx path |
| 380 |
* - RX_HANDLER_ASYNC: will be handled in a working with the wiphy_lock held |
| 381 |
* |
| 382 |
* This means that if the firmware sends two notifications A and B in that |
| 383 |
* order and notification A is RX_HANDLER_ASYNC and notification is |
| 384 |
* RX_HANDLER_SYNC, the handler of B will likely be called before the handler |
| 385 |
* of A. |
| 386 |
* |
| 387 |
* This list should be in order of frequency for performance purposes. |
| 388 |
* The handler can be one from two contexts, see &iwl_rx_handler_context |
| 389 |
* |
| 390 |
* A handler can declare that it relies on a specific object in which case it |
| 391 |
* can be cancelled in case the object is deleted. In order to use this |
| 392 |
* mechanism, a cancellation function is needed. The cancellation function must |
| 393 |
* receive an object id (the index of that object in the firmware) and a |
| 394 |
* notification payload. It'll return true if that specific notification should |
| 395 |
* be cancelled upon the obliteration of the specific instance of the object. |
| 396 |
* |
| 397 |
* DEFINE_SIMPLE_CANCELLATION allows to easily create a cancellation function |
| 398 |
* that wills simply return true if a given object id matches the object id in |
| 399 |
* the firmware notification. |
| 400 |
*/ |
| 401 |
|
| 402 |
VISIBLE_IF_IWLWIFI_KUNIT |
| 403 |
const struct iwl_rx_handler iwl_mld_rx_handlers[] = { |
| 404 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, TX_CMD, tx_resp_notif, |
| 405 |
RX_HANDLER_SYNC) |
| 406 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, BA_NOTIF, compressed_ba_notif, |
| 407 |
RX_HANDLER_SYNC) |
| 408 |
RX_HANDLER_OF_SCAN(LEGACY_GROUP, SCAN_START_NOTIFICATION_UMAC, |
| 409 |
scan_start_notif) |
| 410 |
RX_HANDLER_OF_SCAN(LEGACY_GROUP, SCAN_COMPLETE_UMAC, |
| 411 |
scan_complete_notif) |
| 412 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, SCAN_ITERATION_COMPLETE_UMAC, |
| 413 |
scan_iter_complete_notif, |
| 414 |
RX_HANDLER_SYNC) |
| 415 |
RX_HANDLER_NO_VAL(LEGACY_GROUP, MATCH_FOUND_NOTIFICATION, |
| 416 |
match_found_notif, RX_HANDLER_SYNC) |
| 417 |
|
| 418 |
RX_HANDLER_NO_OBJECT(SCAN_GROUP, CHANNEL_SURVEY_NOTIF, |
| 419 |
channel_survey_notif, |
| 420 |
RX_HANDLER_ASYNC) |
| 421 |
|
| 422 |
RX_HANDLER_NO_OBJECT(STATISTICS_GROUP, STATISTICS_OPER_NOTIF, |
| 423 |
stats_oper_notif, RX_HANDLER_ASYNC) |
| 424 |
RX_HANDLER_NO_OBJECT(STATISTICS_GROUP, STATISTICS_OPER_PART1_NOTIF, |
| 425 |
stats_oper_part1_notif, RX_HANDLER_ASYNC) |
| 426 |
|
| 427 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, MFUART_LOAD_NOTIFICATION, |
| 428 |
mfuart_notif, RX_HANDLER_SYNC) |
| 429 |
|
| 430 |
RX_HANDLER_NO_OBJECT(PHY_OPS_GROUP, DTS_MEASUREMENT_NOTIF_WIDE, |
| 431 |
temp_notif, RX_HANDLER_ASYNC) |
| 432 |
RX_HANDLER_OF_LINK(MAC_CONF_GROUP, SESSION_PROTECTION_NOTIF, |
| 433 |
session_prot_notif) |
| 434 |
RX_HANDLER_OF_LINK(MAC_CONF_GROUP, MISSED_BEACONS_NOTIF, |
| 435 |
missed_beacon_notif) |
| 436 |
RX_HANDLER_OF_STA(DATA_PATH_GROUP, TLC_MNG_UPDATE_NOTIF, tlc_notif) |
| 437 |
RX_HANDLER_OF_LINK(MAC_CONF_GROUP, CHANNEL_SWITCH_START_NOTIF, |
| 438 |
channel_switch_start_notif) |
| 439 |
RX_HANDLER_OF_LINK(MAC_CONF_GROUP, CHANNEL_SWITCH_ERROR_NOTIF, |
| 440 |
channel_switch_error_notif) |
| 441 |
RX_HANDLER_OF_ROC(MAC_CONF_GROUP, ROC_NOTIF, roc_notif) |
| 442 |
RX_HANDLER_NO_OBJECT(DATA_PATH_GROUP, MU_GROUP_MGMT_NOTIF, |
| 443 |
mu_mimo_grp_notif, RX_HANDLER_SYNC) |
| 444 |
RX_HANDLER_OF_VIF(MAC_CONF_GROUP, PROBE_RESPONSE_DATA_NOTIF, |
| 445 |
probe_resp_data_notif) |
| 446 |
RX_HANDLER_NO_OBJECT(PHY_OPS_GROUP, CT_KILL_NOTIFICATION, |
| 447 |
ct_kill_notif, RX_HANDLER_ASYNC) |
| 448 |
RX_HANDLER_OF_LINK(DATA_PATH_GROUP, MONITOR_NOTIF, |
| 449 |
datapath_monitor_notif) |
| 450 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, MCC_CHUB_UPDATE_CMD, update_mcc, |
| 451 |
RX_HANDLER_ASYNC) |
| 452 |
RX_HANDLER_NO_OBJECT(BT_COEX_GROUP, PROFILE_NOTIF, |
| 453 |
bt_coex_notif, RX_HANDLER_ASYNC) |
| 454 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, BEACON_NOTIFICATION, |
| 455 |
beacon_notification, RX_HANDLER_ASYNC) |
| 456 |
RX_HANDLER_NO_OBJECT(DATA_PATH_GROUP, ESR_MODE_NOTIF, |
| 457 |
emlsr_mode_notif, RX_HANDLER_ASYNC) |
| 458 |
RX_HANDLER_NO_OBJECT(MAC_CONF_GROUP, EMLSR_TRANS_FAIL_NOTIF, |
| 459 |
emlsr_trans_fail_notif, RX_HANDLER_ASYNC) |
| 460 |
RX_HANDLER_OF_VIF(LEGACY_GROUP, PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION, |
| 461 |
uapsd_misbehaving_ap_notif) |
| 462 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, |
| 463 |
WNM_80211V_TIMING_MEASUREMENT_NOTIFICATION, |
| 464 |
time_msmt_notif, RX_HANDLER_SYNC) |
| 465 |
RX_HANDLER_NO_OBJECT(LEGACY_GROUP, |
| 466 |
WNM_80211V_TIMING_MEASUREMENT_CONFIRM_NOTIFICATION, |
| 467 |
time_sync_confirm_notif, RX_HANDLER_ASYNC) |
| 468 |
RX_HANDLER_OF_LINK(DATA_PATH_GROUP, BEACON_FILTER_IN_NOTIF, |
| 469 |
beacon_filter_notif) |
| 470 |
RX_HANDLER_OF_FTM_REQ(LOCATION_GROUP, TOF_RANGE_RESPONSE_NOTIF, |
| 471 |
ftm_resp_notif) |
| 472 |
RX_HANDLER_OF_NAN(MAC_CONF_GROUP, NAN_JOINED_CLUSTER_NOTIF, |
| 473 |
nan_cluster_notif) |
| 474 |
RX_HANDLER_OF_NAN(MAC_CONF_GROUP, NAN_DW_END_NOTIF, |
| 475 |
nan_dw_end_notif) |
| 476 |
}; |
| 477 |
EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mld_rx_handlers); |
| 478 |
|
| 479 |
#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS) |
| 480 |
const unsigned int iwl_mld_rx_handlers_num = ARRAY_SIZE(iwl_mld_rx_handlers); |
| 481 |
EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mld_rx_handlers_num); |
| 482 |
#endif |
| 483 |
|
| 484 |
static bool |
| 485 |
iwl_mld_notif_is_valid(struct iwl_mld *mld, struct iwl_rx_packet *pkt, |
| 486 |
const struct iwl_rx_handler *handler) |
| 487 |
{ |
| 488 |
unsigned int size = iwl_rx_packet_payload_len(pkt); |
| 489 |
size_t notif_ver; |
| 490 |
|
| 491 |
/* If n_sizes == 0, it indicates that a validation function may be used |
| 492 |
* or that no validation is required. |
| 493 |
*/ |
| 494 |
if (!handler->n_sizes) { |
| 495 |
if (handler->val_fn) |
| 496 |
return handler->val_fn(mld, pkt); |
| 497 |
return true; |
| 498 |
} |
| 499 |
|
| 500 |
notif_ver = iwl_fw_lookup_notif_ver(mld->fw, |
| 501 |
iwl_cmd_groupid(handler->cmd_id), |
| 502 |
iwl_cmd_opcode(handler->cmd_id), |
| 503 |
IWL_FW_CMD_VER_UNKNOWN); |
| 504 |
|
| 505 |
for (int i = 0; i < handler->n_sizes; i++) { |
| 506 |
if (handler->sizes[i].ver != notif_ver) |
| 507 |
continue; |
| 508 |
|
| 509 |
if (IWL_FW_CHECK(mld, size < handler->sizes[i].size, |
| 510 |
"unexpected notification 0x%04x size %d, need %d\n", |
| 511 |
handler->cmd_id, size, handler->sizes[i].size)) |
| 512 |
return false; |
| 513 |
return true; |
| 514 |
} |
| 515 |
|
| 516 |
IWL_FW_CHECK_FAILED(mld, |
| 517 |
"notif 0x%04x ver %zu missing expected size, use version %u size\n", |
| 518 |
handler->cmd_id, notif_ver, |
| 519 |
handler->sizes[handler->n_sizes - 1].ver); |
| 520 |
|
| 521 |
return size < handler->sizes[handler->n_sizes - 1].size; |
| 522 |
} |
| 523 |
|
| 524 |
struct iwl_async_handler_entry { |
| 525 |
struct list_head list; |
| 526 |
struct iwl_rx_cmd_buffer rxb; |
| 527 |
const struct iwl_rx_handler *rx_h; |
| 528 |
}; |
| 529 |
|
| 530 |
static void |
| 531 |
iwl_mld_log_async_handler_op(struct iwl_mld *mld, const char *op, |
| 532 |
struct iwl_rx_cmd_buffer *rxb) |
| 533 |
{ |
| 534 |
struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 535 |
|
| 536 |
IWL_DEBUG_HC(mld, |
| 537 |
"%s async handler for notif %s (%.2x.%2x, seq 0x%x)\n", |
| 538 |
op, iwl_get_cmd_string(mld->trans, |
| 539 |
WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd)), |
| 540 |
pkt->hdr.group_id, pkt->hdr.cmd, |
| 541 |
le16_to_cpu(pkt->hdr.sequence)); |
| 542 |
} |
| 543 |
|
| 544 |
static void iwl_mld_rx_notif(struct iwl_mld *mld, |
| 545 |
struct iwl_rx_cmd_buffer *rxb, |
| 546 |
struct iwl_rx_packet *pkt) |
| 547 |
{ |
| 548 |
union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt }; |
| 549 |
|
| 550 |
for (int i = 0; i < ARRAY_SIZE(iwl_mld_rx_handlers); i++) { |
| 551 |
const struct iwl_rx_handler *rx_h = &iwl_mld_rx_handlers[i]; |
| 552 |
struct iwl_async_handler_entry *entry; |
| 553 |
|
| 554 |
if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd)) |
| 555 |
continue; |
| 556 |
|
| 557 |
if (!iwl_mld_notif_is_valid(mld, pkt, rx_h)) |
| 558 |
return; |
| 559 |
|
| 560 |
if (rx_h->context == RX_HANDLER_SYNC) { |
| 561 |
rx_h->fn(mld, pkt); |
| 562 |
break; |
| 563 |
} |
| 564 |
|
| 565 |
entry = kzalloc_obj(*entry, GFP_ATOMIC); |
| 566 |
/* we can't do much... */ |
| 567 |
if (!entry) |
| 568 |
return; |
| 569 |
|
| 570 |
/* Set the async handler entry */ |
| 571 |
entry->rxb._page = rxb_steal_page(rxb); |
| 572 |
entry->rxb._offset = rxb->_offset; |
| 573 |
entry->rxb._rx_page_order = rxb->_rx_page_order; |
| 574 |
|
| 575 |
entry->rx_h = rx_h; |
| 576 |
|
| 577 |
/* Add it to the list and queue the work */ |
| 578 |
spin_lock(&mld->async_handlers_lock); |
| 579 |
list_add_tail(&entry->list, &mld->async_handlers_list); |
| 580 |
spin_unlock(&mld->async_handlers_lock); |
| 581 |
|
| 582 |
wiphy_work_queue(mld->hw->wiphy, |
| 583 |
&mld->async_handlers_wk); |
| 584 |
|
| 585 |
iwl_mld_log_async_handler_op(mld, "Queued", rxb); |
| 586 |
break; |
| 587 |
} |
| 588 |
|
| 589 |
iwl_notification_wait_notify(&mld->notif_wait, pkt); |
| 590 |
iwl_dbg_tlv_time_point(&mld->fwrt, |
| 591 |
IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF, &tp_data); |
| 592 |
} |
| 593 |
|
| 594 |
void iwl_mld_rx(struct iwl_op_mode *op_mode, struct napi_struct *napi, |
| 595 |
struct iwl_rx_cmd_buffer *rxb) |
| 596 |
{ |
| 597 |
struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 598 |
struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode); |
| 599 |
u16 cmd_id = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd); |
| 600 |
|
| 601 |
if (likely(cmd_id == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))) |
| 602 |
iwl_mld_rx_mpdu(mld, napi, rxb, 0); |
| 603 |
else if (cmd_id == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE)) |
| 604 |
iwl_mld_handle_frame_release_notif(mld, napi, pkt, 0); |
| 605 |
else if (cmd_id == WIDE_ID(LEGACY_GROUP, BAR_FRAME_RELEASE)) |
| 606 |
iwl_mld_handle_bar_frame_release_notif(mld, napi, pkt, 0); |
| 607 |
else if (unlikely(cmd_id == WIDE_ID(DATA_PATH_GROUP, |
| 608 |
RX_QUEUES_NOTIFICATION))) |
| 609 |
iwl_mld_handle_rx_queues_sync_notif(mld, napi, pkt, 0); |
| 610 |
else if (cmd_id == WIDE_ID(DATA_PATH_GROUP, PHY_AIR_SNIFFER_NOTIF)) |
| 611 |
iwl_mld_handle_phy_air_sniffer_notif(mld, napi, pkt); |
| 612 |
else |
| 613 |
iwl_mld_rx_notif(mld, rxb, pkt); |
| 614 |
} |
| 615 |
|
| 616 |
void iwl_mld_rx_rss(struct iwl_op_mode *op_mode, struct napi_struct *napi, |
| 617 |
struct iwl_rx_cmd_buffer *rxb, unsigned int queue) |
| 618 |
{ |
| 619 |
struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 620 |
struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode); |
| 621 |
u16 cmd_id = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd); |
| 622 |
|
| 623 |
if (unlikely(queue >= mld->trans->info.num_rxqs)) |
| 624 |
return; |
| 625 |
|
| 626 |
if (likely(cmd_id == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))) |
| 627 |
iwl_mld_rx_mpdu(mld, napi, rxb, queue); |
| 628 |
else if (unlikely(cmd_id == WIDE_ID(DATA_PATH_GROUP, |
| 629 |
RX_QUEUES_NOTIFICATION))) |
| 630 |
iwl_mld_handle_rx_queues_sync_notif(mld, napi, pkt, queue); |
| 631 |
else if (unlikely(cmd_id == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE))) |
| 632 |
iwl_mld_handle_frame_release_notif(mld, napi, pkt, queue); |
| 633 |
} |
| 634 |
|
| 635 |
void iwl_mld_delete_handlers(struct iwl_mld *mld, const u16 *cmds, int n_cmds) |
| 636 |
{ |
| 637 |
struct iwl_async_handler_entry *entry, *tmp; |
| 638 |
|
| 639 |
spin_lock_bh(&mld->async_handlers_lock); |
| 640 |
list_for_each_entry_safe(entry, tmp, &mld->async_handlers_list, list) { |
| 641 |
bool match = false; |
| 642 |
|
| 643 |
for (int i = 0; i < n_cmds; i++) { |
| 644 |
if (entry->rx_h->cmd_id == cmds[i]) { |
| 645 |
match = true; |
| 646 |
break; |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
if (!match) |
| 651 |
continue; |
| 652 |
|
| 653 |
iwl_mld_log_async_handler_op(mld, "Delete", &entry->rxb); |
| 654 |
iwl_free_rxb(&entry->rxb); |
| 655 |
list_del(&entry->list); |
| 656 |
kfree(entry); |
| 657 |
} |
| 658 |
spin_unlock_bh(&mld->async_handlers_lock); |
| 659 |
} |
| 660 |
|
| 661 |
void iwl_mld_async_handlers_wk(struct wiphy *wiphy, struct wiphy_work *wk) |
| 662 |
{ |
| 663 |
struct iwl_mld *mld = |
| 664 |
container_of(wk, struct iwl_mld, async_handlers_wk); |
| 665 |
struct iwl_async_handler_entry *entry, *tmp; |
| 666 |
LIST_HEAD(local_list); |
| 667 |
|
| 668 |
/* Sync with Rx path with a lock. Remove all the entries from this |
| 669 |
* list, add them to a local one (lock free), and then handle them. |
| 670 |
*/ |
| 671 |
spin_lock_bh(&mld->async_handlers_lock); |
| 672 |
list_splice_init(&mld->async_handlers_list, &local_list); |
| 673 |
spin_unlock_bh(&mld->async_handlers_lock); |
| 674 |
|
| 675 |
list_for_each_entry_safe(entry, tmp, &local_list, list) { |
| 676 |
iwl_mld_log_async_handler_op(mld, "Handle", &entry->rxb); |
| 677 |
entry->rx_h->fn(mld, rxb_addr(&entry->rxb)); |
| 678 |
iwl_free_rxb(&entry->rxb); |
| 679 |
list_del(&entry->list); |
| 680 |
kfree(entry); |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
void iwl_mld_cancel_async_notifications(struct iwl_mld *mld) |
| 685 |
{ |
| 686 |
struct iwl_async_handler_entry *entry, *tmp; |
| 687 |
|
| 688 |
lockdep_assert_wiphy(mld->wiphy); |
| 689 |
|
| 690 |
wiphy_work_cancel(mld->wiphy, &mld->async_handlers_wk); |
| 691 |
|
| 692 |
spin_lock_bh(&mld->async_handlers_lock); |
| 693 |
list_for_each_entry_safe(entry, tmp, &mld->async_handlers_list, list) { |
| 694 |
iwl_mld_log_async_handler_op(mld, "Purged", &entry->rxb); |
| 695 |
iwl_free_rxb(&entry->rxb); |
| 696 |
list_del(&entry->list); |
| 697 |
kfree(entry); |
| 698 |
} |
| 699 |
spin_unlock_bh(&mld->async_handlers_lock); |
| 700 |
} |
| 701 |
|
| 702 |
void iwl_mld_cancel_notifications_of_object(struct iwl_mld *mld, |
| 703 |
enum iwl_mld_object_type obj_type, |
| 704 |
u32 obj_id) |
| 705 |
{ |
| 706 |
struct iwl_async_handler_entry *entry, *tmp; |
| 707 |
LIST_HEAD(cancel_list); |
| 708 |
|
| 709 |
lockdep_assert_wiphy(mld->wiphy); |
| 710 |
|
| 711 |
if (WARN_ON(obj_type == IWL_MLD_OBJECT_TYPE_NONE)) |
| 712 |
return; |
| 713 |
|
| 714 |
/* Sync with RX path and remove matching entries from the async list */ |
| 715 |
spin_lock_bh(&mld->async_handlers_lock); |
| 716 |
list_for_each_entry_safe(entry, tmp, &mld->async_handlers_list, list) { |
| 717 |
const struct iwl_rx_handler *rx_h = entry->rx_h; |
| 718 |
|
| 719 |
if (rx_h->obj_type != obj_type || WARN_ON(!rx_h->cancel)) |
| 720 |
continue; |
| 721 |
|
| 722 |
if (rx_h->cancel(mld, rxb_addr(&entry->rxb), obj_id)) { |
| 723 |
iwl_mld_log_async_handler_op(mld, "Cancel", &entry->rxb); |
| 724 |
list_del(&entry->list); |
| 725 |
list_add_tail(&entry->list, &cancel_list); |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
spin_unlock_bh(&mld->async_handlers_lock); |
| 730 |
|
| 731 |
/* Free the matching entries outside of the spinlock */ |
| 732 |
list_for_each_entry_safe(entry, tmp, &cancel_list, list) { |
| 733 |
iwl_free_rxb(&entry->rxb); |
| 734 |
list_del(&entry->list); |
| 735 |
kfree(entry); |
| 736 |
} |
| 737 |
} |