xref: /linux/drivers/net/wireless/intel/iwlwifi/mld/scan.h (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2024-2025 Intel Corporation
4  */
5 #ifndef __iwl_mld_scan_h__
6 #define __iwl_mld_scan_h__
7 
8 int iwl_mld_alloc_scan_cmd(struct iwl_mld *mld);
9 
10 int iwl_mld_regular_scan_start(struct iwl_mld *mld, struct ieee80211_vif *vif,
11 			       struct cfg80211_scan_request *req,
12 			       struct ieee80211_scan_ies *ies);
13 
14 void iwl_mld_int_mlo_scan(struct iwl_mld *mld, struct ieee80211_vif *vif);
15 
16 void iwl_mld_handle_scan_iter_complete_notif(struct iwl_mld *mld,
17 					     struct iwl_rx_packet *pkt);
18 
19 int iwl_mld_scan_stop(struct iwl_mld *mld, int type, bool notify);
20 
21 int iwl_mld_sched_scan_start(struct iwl_mld *mld,
22 			     struct ieee80211_vif *vif,
23 			     struct cfg80211_sched_scan_request *req,
24 			     struct ieee80211_scan_ies *ies,
25 			     int type);
26 
27 void iwl_mld_handle_match_found_notif(struct iwl_mld *mld,
28 				      struct iwl_rx_packet *pkt);
29 
30 void iwl_mld_handle_scan_complete_notif(struct iwl_mld *mld,
31 					struct iwl_rx_packet *pkt);
32 
33 int iwl_mld_mac80211_get_survey(struct ieee80211_hw *hw, int idx,
34 				struct survey_info *survey);
35 
36 void iwl_mld_handle_channel_survey_notif(struct iwl_mld *mld,
37 					 struct iwl_rx_packet *pkt);
38 
39 #define WFA_TPC_IE_LEN 9
40 
iwl_mld_scan_max_template_size(void)41 static inline int iwl_mld_scan_max_template_size(void)
42 {
43 #define MAC_HDR_LEN 24
44 #define DS_IE_LEN 3
45 #define SSID_IE_LEN 2
46 
47 /* driver create the 802.11 header, WFA TPC IE, DS parameter and SSID IE */
48 #define DRIVER_TOTAL_IES_LEN \
49 	(MAC_HDR_LEN + WFA_TPC_IE_LEN + DS_IE_LEN + SSID_IE_LEN)
50 
51 	BUILD_BUG_ON(SCAN_OFFLOAD_PROBE_REQ_SIZE < DRIVER_TOTAL_IES_LEN);
52 
53 	return SCAN_OFFLOAD_PROBE_REQ_SIZE - DRIVER_TOTAL_IES_LEN;
54 }
55 
56 void iwl_mld_report_scan_aborted(struct iwl_mld *mld);
57 
58 enum iwl_mld_scan_status {
59 	IWL_MLD_SCAN_NONE		= 0,
60 	IWL_MLD_SCAN_REGULAR		= BIT(0),
61 	IWL_MLD_SCAN_SCHED		= BIT(1),
62 	IWL_MLD_SCAN_NETDETECT		= BIT(2),
63 	IWL_MLD_SCAN_INT_MLO		= BIT(3),
64 };
65 
66 /* enum iwl_mld_pass_all_sched_results_states - Defines the states for
67  * handling/passing scheduled scan results to mac80211
68  * @SCHED_SCAN_PASS_ALL_STATE_DISABLED: Don't pass all scan results, only when
69  *	a match found.
70  * @SCHED_SCAN_PASS_ALL_STATE_ENABLED: Pass all scan results is enabled
71  *	(no filtering).
72  * @SCHED_SCAN_PASS_ALL_STATE_FOUND: A scan result is found, pass it on the
73  *	next scan iteration complete notification.
74  */
75 enum iwl_mld_pass_all_sched_results_states {
76 	SCHED_SCAN_PASS_ALL_STATE_DISABLED,
77 	SCHED_SCAN_PASS_ALL_STATE_ENABLED,
78 	SCHED_SCAN_PASS_ALL_STATE_FOUND,
79 };
80 
81 /**
82  * enum iwl_mld_traffic_load - Levels of traffic load
83  *
84  * @IWL_MLD_TRAFFIC_LOW: low traffic load
85  * @IWL_MLD_TRAFFIC_MEDIUM: medium traffic load
86  * @IWL_MLD_TRAFFIC_HIGH: high traffic load
87  */
88 enum iwl_mld_traffic_load {
89 	IWL_MLD_TRAFFIC_LOW,
90 	IWL_MLD_TRAFFIC_MEDIUM,
91 	IWL_MLD_TRAFFIC_HIGH,
92 };
93 
94 /**
95  * struct iwl_mld_scan - Scan data
96  * @status: scan status, a combination of %enum iwl_mld_scan_status,
97  *	reflects the %scan.uid_status array.
98  * @uid_status: array to track the scan status per uid.
99  * @start_tsf: start time of last scan in TSF of the link that requested
100  *	the scan.
101  * @last_ebs_failed: true if the last EBS (Energy Based Scan) failed.
102  * @pass_all_sched_res: see %enum iwl_mld_pass_all_sched_results_states.
103  * @fw_link_id: the current (regular) scan fw link id, used by scan
104  *	complete notif.
105  * @traffic_load: traffic load related data
106  * @traffic_load.last_stats_ts_usec: The timestamp of the last statistics
107  *	notification, used to calculate the elapsed time between two
108  *	notifications and determine the traffic load
109  * @traffic_load.status: The current traffic load status, see
110  *	&enum iwl_mld_traffic_load
111  * @cmd_size: size of %cmd.
112  * @cmd: pointer to scan cmd buffer (allocated once in op mode start).
113  * @last_6ghz_passive_jiffies: stores the last 6GHz passive scan time
114  *	in jiffies.
115  * @last_start_time_jiffies: stores the last start time in jiffies
116  *	(interface up/reset/resume).
117  * @last_mlo_scan_time: start time of the last MLO scan in nanoseconds since
118  *	boot.
119  */
120 struct iwl_mld_scan {
121 	/* Add here fields that need clean up on restart */
122 	struct_group(zeroed_on_hw_restart,
123 		unsigned int status;
124 		u32 uid_status[IWL_MAX_UMAC_SCANS];
125 		u64 start_tsf;
126 		bool last_ebs_failed;
127 		enum iwl_mld_pass_all_sched_results_states pass_all_sched_res;
128 		u8 fw_link_id;
129 		struct {
130 			u32 last_stats_ts_usec;
131 			enum iwl_mld_traffic_load status;
132 		} traffic_load;
133 	);
134 	/* And here fields that survive a fw restart */
135 	size_t cmd_size;
136 	void *cmd;
137 	unsigned long last_6ghz_passive_jiffies;
138 	unsigned long last_start_time_jiffies;
139 	u64 last_mlo_scan_time;
140 };
141 
142 /**
143  * struct iwl_mld_survey_channel - per-channel survey information
144  *
145  * Driver version of &struct survey_info with just the data we want to report.
146  *
147  * @time: time in ms the radio was on the channel
148  * @time_busy: time in ms the channel was sensed busy
149  * @noise: channel noise in dBm
150  */
151 struct iwl_mld_survey_channel {
152 	u32 time;
153 	u32 time_busy;
154 	s8 noise;
155 };
156 
157 /**
158  * struct iwl_mld_survey - survey information
159  *
160  * Survey information for all available channels.
161  *
162  * @bands: per-band array for per-channel survey data, points into @channels
163  * @n_channels: Number of @channels entries that are allocated
164  * @channels: per-channel information
165  */
166 struct iwl_mld_survey {
167 	struct iwl_mld_survey_channel *bands[NUM_NL80211_BANDS];
168 
169 	int n_channels;
170 	struct iwl_mld_survey_channel channels[] __counted_by(n_channels);
171 };
172 
173 #endif /* __iwl_mld_scan_h__ */
174