xref: /linux/drivers/net/wireless/intel/iwlwifi/mld/tests/utils.h (revision 1a9239bb4253f9076b5b4b2a1a4e8d7defd77a95)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2024-2025 Intel Corporation
4  */
5 
6 #ifndef __iwl_mld_kunit_utils_h__
7 #define __iwl_mld_kunit_utils_h__
8 
9 #include <net/mac80211.h>
10 #include <kunit/test-bug.h>
11 
12 struct iwl_mld;
13 
14 int iwlmld_kunit_test_init(struct kunit *test);
15 
16 struct iwl_mld_kunit_link {
17 	u8 id;
18 	enum nl80211_band band;
19 	enum nl80211_chan_width bandwidth;
20 };
21 
22 enum nl80211_iftype;
23 
24 struct ieee80211_vif *iwlmld_kunit_add_vif(bool mlo, enum nl80211_iftype type);
25 
26 struct ieee80211_bss_conf *
27 iwlmld_kunit_add_link(struct ieee80211_vif *vif, int link_id);
28 
29 #define KUNIT_ALLOC_AND_ASSERT_SIZE(test, ptr, size)			\
30 do {									\
31 	(ptr) = kunit_kzalloc((test), (size), GFP_KERNEL);		\
32 	KUNIT_ASSERT_NOT_NULL((test), (ptr));				\
33 } while (0)
34 
35 #define KUNIT_ALLOC_AND_ASSERT(test, ptr)				\
36 	KUNIT_ALLOC_AND_ASSERT_SIZE(test, ptr, sizeof(*(ptr)))
37 
38 #define CHANNEL(_name, _band, _freq)				\
39 static struct ieee80211_channel _name = {			\
40 	.band = (_band),					\
41 	.center_freq = (_freq),					\
42 	.hw_value = (_freq),					\
43 }
44 
45 #define CHANDEF(_name, _channel, _freq1, _width)		\
46 __maybe_unused static struct cfg80211_chan_def _name = {	\
47 	.chan = &(_channel),					\
48 	.center_freq1 = (_freq1),				\
49 	.width = (_width),					\
50 }
51 
52 CHANNEL(chan_2ghz, NL80211_BAND_2GHZ, 2412);
53 CHANNEL(chan_5ghz, NL80211_BAND_5GHZ, 5200);
54 CHANNEL(chan_6ghz, NL80211_BAND_6GHZ, 6115);
55 /* Feel free to add more */
56 
57 CHANDEF(chandef_2ghz, chan_2ghz, 2412, NL80211_CHAN_WIDTH_20);
58 CHANDEF(chandef_5ghz, chan_5ghz, 5200, NL80211_CHAN_WIDTH_40);
59 CHANDEF(chandef_6ghz, chan_6ghz, 6115, NL80211_CHAN_WIDTH_160);
60 /* Feel free to add more */
61 
62 //struct cfg80211_chan_def;
63 
64 struct ieee80211_chanctx_conf *
65 iwlmld_kunit_add_chanctx_from_def(struct cfg80211_chan_def *def);
66 
67 static inline struct ieee80211_chanctx_conf *
iwlmld_kunit_add_chanctx(enum nl80211_band band,enum nl80211_chan_width width)68 iwlmld_kunit_add_chanctx(enum nl80211_band band, enum nl80211_chan_width width)
69 {
70 	struct cfg80211_chan_def chandef;
71 
72 	switch (band) {
73 	case NL80211_BAND_2GHZ:
74 		chandef = chandef_2ghz;
75 		break;
76 	case NL80211_BAND_5GHZ:
77 		chandef = chandef_5ghz;
78 		break;
79 	default:
80 	case NL80211_BAND_6GHZ:
81 		chandef = chandef_6ghz;
82 		break;
83 	}
84 
85 	chandef.width = width;
86 
87 	return iwlmld_kunit_add_chanctx_from_def(&chandef);
88 }
89 
90 void iwlmld_kunit_assign_chanctx_to_link(struct ieee80211_vif *vif,
91 					 struct ieee80211_bss_conf *link,
92 					 struct ieee80211_chanctx_conf *ctx);
93 
94 /* Allocate a sta, initialize it and move it to the wanted state */
95 struct ieee80211_sta *iwlmld_kunit_setup_sta(struct ieee80211_vif *vif,
96 					     enum ieee80211_sta_state state,
97 					     int link_id);
98 
99 struct ieee80211_vif *
100 iwlmld_kunit_setup_mlo_assoc(u16 valid_links,
101 			     struct iwl_mld_kunit_link *assoc_link);
102 
103 struct ieee80211_vif *
104 iwlmld_kunit_setup_non_mlo_assoc(struct iwl_mld_kunit_link *assoc_link);
105 
106 struct iwl_rx_packet *
107 _iwl_mld_kunit_create_pkt(const void *notif, size_t notif_sz);
108 
109 #define iwl_mld_kunit_create_pkt(_notif)	\
110 	_iwl_mld_kunit_create_pkt(&(_notif), sizeof(_notif))
111 
112 struct ieee80211_vif *
113 iwlmld_kunit_assoc_emlsr(struct iwl_mld_kunit_link *link1,
114 			 struct iwl_mld_kunit_link *link2);
115 
116 struct element *iwlmld_kunit_gen_element(u8 id, const void *data, size_t len);
117 
118 /**
119  * iwlmld_kunit_get_phy_of_link - Get the phy of a link
120  *
121  * @vif: The vif to get the phy from.
122  * @link_id: The id of the link to get the phy for.
123  *
124  * given a vif and link id, return the phy pointer of that link.
125  * This assumes that the link exists, and that it had a chanctx
126  * assigned.
127  * If this is not the case, the test will fail.
128  *
129  * Return: phy pointer.
130  */
131 struct iwl_mld_phy *iwlmld_kunit_get_phy_of_link(struct ieee80211_vif *vif,
132 						 u8 link_id);
133 
134 #endif /* __iwl_mld_kunit_utils_h__ */
135