1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67#include <net/ipv6.h>
68#include <net/addrconf.h>
69#include <linux/bitops.h>
70#include "mvm.h"
71
72void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
73 struct iwl_wowlan_config_cmd *cmd)
74{
75 int i;
76
77
78
79
80
81
82 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
83 u16 seq = mvm_ap_sta->tid_data[i].seq_number;
84 seq -= 0x10;
85 cmd->qos_seq[i] = cpu_to_le16(seq);
86 }
87}
88
89int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
90 struct ieee80211_vif *vif,
91 bool disable_offloading,
92 bool offload_ns,
93 u32 cmd_flags)
94{
95 union {
96 struct iwl_proto_offload_cmd_v1 v1;
97 struct iwl_proto_offload_cmd_v2 v2;
98 struct iwl_proto_offload_cmd_v3_small v3s;
99 struct iwl_proto_offload_cmd_v3_large v3l;
100 } cmd = {};
101 struct iwl_host_cmd hcmd = {
102 .id = PROT_OFFLOAD_CONFIG_CMD,
103 .flags = cmd_flags,
104 .data[0] = &cmd,
105 .dataflags[0] = IWL_HCMD_DFL_DUP,
106 };
107 struct iwl_proto_offload_cmd_common *common;
108 u32 enabled = 0, size;
109 u32 capa_flags = mvm->fw->ucode_capa.flags;
110#if IS_ENABLED(CONFIG_IPV6)
111 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
112 int i;
113
114
115
116
117
118
119 bool skip_tentative = offload_ns;
120
121 if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL ||
122 capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) {
123 struct iwl_ns_config *nsc;
124 struct iwl_targ_addr *addrs;
125 int n_nsc, n_addrs;
126 int c;
127 int num_skipped = 0;
128
129 if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) {
130 nsc = cmd.v3s.ns_config;
131 n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3S;
132 addrs = cmd.v3s.targ_addrs;
133 n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3S;
134 } else {
135 nsc = cmd.v3l.ns_config;
136 n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3L;
137 addrs = cmd.v3l.targ_addrs;
138 n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3L;
139 }
140
141
142
143
144
145
146 for (i = 0, c = 0;
147 i < mvmvif->num_target_ipv6_addrs &&
148 i < n_addrs && c < n_nsc; i++) {
149 struct in6_addr solicited_addr;
150 int j;
151
152 if (skip_tentative &&
153 test_bit(i, mvmvif->tentative_addrs)) {
154 num_skipped++;
155 continue;
156 }
157
158 addrconf_addr_solict_mult(&mvmvif->target_ipv6_addrs[i],
159 &solicited_addr);
160 for (j = 0; j < c; j++)
161 if (ipv6_addr_cmp(&nsc[j].dest_ipv6_addr,
162 &solicited_addr) == 0)
163 break;
164 if (j == c)
165 c++;
166 addrs[i].addr = mvmvif->target_ipv6_addrs[i];
167 addrs[i].config_num = cpu_to_le32(j);
168 nsc[j].dest_ipv6_addr = solicited_addr;
169 memcpy(nsc[j].target_mac_addr, vif->addr, ETH_ALEN);
170 }
171
172 if (mvmvif->num_target_ipv6_addrs - num_skipped)
173 enabled |= IWL_D3_PROTO_IPV6_VALID;
174
175 if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL)
176 cmd.v3s.num_valid_ipv6_addrs =
177 cpu_to_le32(i - num_skipped);
178 else
179 cmd.v3l.num_valid_ipv6_addrs =
180 cpu_to_le32(i - num_skipped);
181 } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) {
182 bool found = false;
183
184 BUILD_BUG_ON(sizeof(cmd.v2.target_ipv6_addr[0]) !=
185 sizeof(mvmvif->target_ipv6_addrs[0]));
186
187 for (i = 0; i < min(mvmvif->num_target_ipv6_addrs,
188 IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V2); i++) {
189 if (skip_tentative &&
190 test_bit(i, mvmvif->tentative_addrs))
191 continue;
192
193 memcpy(cmd.v2.target_ipv6_addr[i],
194 &mvmvif->target_ipv6_addrs[i],
195 sizeof(cmd.v2.target_ipv6_addr[i]));
196
197 found = true;
198 }
199 if (found) {
200 enabled |= IWL_D3_PROTO_IPV6_VALID;
201 memcpy(cmd.v2.ndp_mac_addr, vif->addr, ETH_ALEN);
202 }
203 } else {
204 bool found = false;
205 BUILD_BUG_ON(sizeof(cmd.v1.target_ipv6_addr[0]) !=
206 sizeof(mvmvif->target_ipv6_addrs[0]));
207
208 for (i = 0; i < min(mvmvif->num_target_ipv6_addrs,
209 IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V1); i++) {
210 if (skip_tentative &&
211 test_bit(i, mvmvif->tentative_addrs))
212 continue;
213
214 memcpy(cmd.v1.target_ipv6_addr[i],
215 &mvmvif->target_ipv6_addrs[i],
216 sizeof(cmd.v1.target_ipv6_addr[i]));
217
218 found = true;
219 }
220
221 if (found) {
222 enabled |= IWL_D3_PROTO_IPV6_VALID;
223 memcpy(cmd.v1.ndp_mac_addr, vif->addr, ETH_ALEN);
224 }
225 }
226
227 if (offload_ns && (enabled & IWL_D3_PROTO_IPV6_VALID))
228 enabled |= IWL_D3_PROTO_OFFLOAD_NS;
229#endif
230 if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) {
231 common = &cmd.v3s.common;
232 size = sizeof(cmd.v3s);
233 } else if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) {
234 common = &cmd.v3l.common;
235 size = sizeof(cmd.v3l);
236 } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) {
237 common = &cmd.v2.common;
238 size = sizeof(cmd.v2);
239 } else {
240 common = &cmd.v1.common;
241 size = sizeof(cmd.v1);
242 }
243
244 if (vif->bss_conf.arp_addr_cnt) {
245 enabled |= IWL_D3_PROTO_OFFLOAD_ARP | IWL_D3_PROTO_IPV4_VALID;
246 common->host_ipv4_addr = vif->bss_conf.arp_addr_list[0];
247 memcpy(common->arp_mac_addr, vif->addr, ETH_ALEN);
248 }
249
250 if (!disable_offloading)
251 common->enabled = cpu_to_le32(enabled);
252
253 hcmd.len[0] = size;
254 return iwl_mvm_send_cmd(mvm, &hcmd);
255}
256