xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/intel/iwlwifi/mvm/offloading.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
4*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun  * Copyright(c) 2015 Intel Deutschland GmbH
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
13*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
14*4882a593Smuzhiyun  * published by the Free Software Foundation.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
17*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
18*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19*4882a593Smuzhiyun  * General Public License for more details.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * The full GNU General Public License is included in this distribution
22*4882a593Smuzhiyun  * in the file called COPYING.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * Contact Information:
25*4882a593Smuzhiyun  *  Intel Linux Wireless <linuxwifi@intel.com>
26*4882a593Smuzhiyun  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * BSD LICENSE
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
31*4882a593Smuzhiyun  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
32*4882a593Smuzhiyun  * Copyright(c) 2015 Intel Deutschland GmbH
33*4882a593Smuzhiyun  * All rights reserved.
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
36*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
37*4882a593Smuzhiyun  * are met:
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  *  * Redistributions of source code must retain the above copyright
40*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
41*4882a593Smuzhiyun  *  * Redistributions in binary form must reproduce the above copyright
42*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
43*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
44*4882a593Smuzhiyun  *    distribution.
45*4882a593Smuzhiyun  *  * Neither the name Intel Corporation nor the names of its
46*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
47*4882a593Smuzhiyun  *    from this software without specific prior written permission.
48*4882a593Smuzhiyun  *
49*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  *****************************************************************************/
62*4882a593Smuzhiyun #include <net/ipv6.h>
63*4882a593Smuzhiyun #include <net/addrconf.h>
64*4882a593Smuzhiyun #include <linux/bitops.h>
65*4882a593Smuzhiyun #include "mvm.h"
66*4882a593Smuzhiyun 
iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta * mvm_ap_sta,struct iwl_wowlan_config_cmd * cmd)67*4882a593Smuzhiyun void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
68*4882a593Smuzhiyun 				struct iwl_wowlan_config_cmd *cmd)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	int i;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	/*
73*4882a593Smuzhiyun 	 * For QoS counters, we store the one to use next, so subtract 0x10
74*4882a593Smuzhiyun 	 * since the uCode will add 0x10 *before* using the value while we
75*4882a593Smuzhiyun 	 * increment after using the value (i.e. store the next value to use).
76*4882a593Smuzhiyun 	 */
77*4882a593Smuzhiyun 	for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
78*4882a593Smuzhiyun 		u16 seq = mvm_ap_sta->tid_data[i].seq_number;
79*4882a593Smuzhiyun 		seq -= 0x10;
80*4882a593Smuzhiyun 		cmd->qos_seq[i] = cpu_to_le16(seq);
81*4882a593Smuzhiyun 	}
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
iwl_mvm_send_proto_offload(struct iwl_mvm * mvm,struct ieee80211_vif * vif,bool disable_offloading,bool offload_ns,u32 cmd_flags)84*4882a593Smuzhiyun int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
85*4882a593Smuzhiyun 			       struct ieee80211_vif *vif,
86*4882a593Smuzhiyun 			       bool disable_offloading,
87*4882a593Smuzhiyun 			       bool offload_ns,
88*4882a593Smuzhiyun 			       u32 cmd_flags)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun 	union {
91*4882a593Smuzhiyun 		struct iwl_proto_offload_cmd_v1 v1;
92*4882a593Smuzhiyun 		struct iwl_proto_offload_cmd_v2 v2;
93*4882a593Smuzhiyun 		struct iwl_proto_offload_cmd_v3_small v3s;
94*4882a593Smuzhiyun 		struct iwl_proto_offload_cmd_v3_large v3l;
95*4882a593Smuzhiyun 	} cmd = {};
96*4882a593Smuzhiyun 	struct iwl_host_cmd hcmd = {
97*4882a593Smuzhiyun 		.id = PROT_OFFLOAD_CONFIG_CMD,
98*4882a593Smuzhiyun 		.flags = cmd_flags,
99*4882a593Smuzhiyun 		.data[0] = &cmd,
100*4882a593Smuzhiyun 		.dataflags[0] = IWL_HCMD_DFL_DUP,
101*4882a593Smuzhiyun 	};
102*4882a593Smuzhiyun 	struct iwl_proto_offload_cmd_common *common;
103*4882a593Smuzhiyun 	u32 enabled = 0, size;
104*4882a593Smuzhiyun 	u32 capa_flags = mvm->fw->ucode_capa.flags;
105*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
106*4882a593Smuzhiyun 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
107*4882a593Smuzhiyun 	int i;
108*4882a593Smuzhiyun 	/*
109*4882a593Smuzhiyun 	 * Skip tentative address when ns offload is enabled to avoid
110*4882a593Smuzhiyun 	 * violating RFC4862.
111*4882a593Smuzhiyun 	 * Keep tentative address when ns offload is disabled so the NS packets
112*4882a593Smuzhiyun 	 * will not be filtered out and will wake up the host.
113*4882a593Smuzhiyun 	 */
114*4882a593Smuzhiyun 	bool skip_tentative = offload_ns;
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL ||
117*4882a593Smuzhiyun 	    capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) {
118*4882a593Smuzhiyun 		struct iwl_ns_config *nsc;
119*4882a593Smuzhiyun 		struct iwl_targ_addr *addrs;
120*4882a593Smuzhiyun 		int n_nsc, n_addrs;
121*4882a593Smuzhiyun 		int c;
122*4882a593Smuzhiyun 		int num_skipped = 0;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 		if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) {
125*4882a593Smuzhiyun 			nsc = cmd.v3s.ns_config;
126*4882a593Smuzhiyun 			n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3S;
127*4882a593Smuzhiyun 			addrs = cmd.v3s.targ_addrs;
128*4882a593Smuzhiyun 			n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3S;
129*4882a593Smuzhiyun 		} else {
130*4882a593Smuzhiyun 			nsc = cmd.v3l.ns_config;
131*4882a593Smuzhiyun 			n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3L;
132*4882a593Smuzhiyun 			addrs = cmd.v3l.targ_addrs;
133*4882a593Smuzhiyun 			n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3L;
134*4882a593Smuzhiyun 		}
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 		/*
137*4882a593Smuzhiyun 		 * For each address we have (and that will fit) fill a target
138*4882a593Smuzhiyun 		 * address struct and combine for NS offload structs with the
139*4882a593Smuzhiyun 		 * solicited node addresses.
140*4882a593Smuzhiyun 		 */
141*4882a593Smuzhiyun 		for (i = 0, c = 0;
142*4882a593Smuzhiyun 		     i < mvmvif->num_target_ipv6_addrs &&
143*4882a593Smuzhiyun 		     i < n_addrs && c < n_nsc; i++) {
144*4882a593Smuzhiyun 			struct in6_addr solicited_addr;
145*4882a593Smuzhiyun 			int j;
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 			if (skip_tentative &&
148*4882a593Smuzhiyun 			    test_bit(i, mvmvif->tentative_addrs)) {
149*4882a593Smuzhiyun 				num_skipped++;
150*4882a593Smuzhiyun 				continue;
151*4882a593Smuzhiyun 			}
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun 			addrconf_addr_solict_mult(&mvmvif->target_ipv6_addrs[i],
154*4882a593Smuzhiyun 						  &solicited_addr);
155*4882a593Smuzhiyun 			for (j = 0; j < c; j++)
156*4882a593Smuzhiyun 				if (ipv6_addr_cmp(&nsc[j].dest_ipv6_addr,
157*4882a593Smuzhiyun 						  &solicited_addr) == 0)
158*4882a593Smuzhiyun 					break;
159*4882a593Smuzhiyun 			if (j == c)
160*4882a593Smuzhiyun 				c++;
161*4882a593Smuzhiyun 			addrs[i].addr = mvmvif->target_ipv6_addrs[i];
162*4882a593Smuzhiyun 			addrs[i].config_num = cpu_to_le32(j);
163*4882a593Smuzhiyun 			nsc[j].dest_ipv6_addr = solicited_addr;
164*4882a593Smuzhiyun 			memcpy(nsc[j].target_mac_addr, vif->addr, ETH_ALEN);
165*4882a593Smuzhiyun 		}
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 		if (mvmvif->num_target_ipv6_addrs - num_skipped)
168*4882a593Smuzhiyun 			enabled |= IWL_D3_PROTO_IPV6_VALID;
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 		if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL)
171*4882a593Smuzhiyun 			cmd.v3s.num_valid_ipv6_addrs =
172*4882a593Smuzhiyun 				cpu_to_le32(i - num_skipped);
173*4882a593Smuzhiyun 		else
174*4882a593Smuzhiyun 			cmd.v3l.num_valid_ipv6_addrs =
175*4882a593Smuzhiyun 				cpu_to_le32(i - num_skipped);
176*4882a593Smuzhiyun 	} else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) {
177*4882a593Smuzhiyun 		bool found = false;
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 		BUILD_BUG_ON(sizeof(cmd.v2.target_ipv6_addr[0]) !=
180*4882a593Smuzhiyun 			     sizeof(mvmvif->target_ipv6_addrs[0]));
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 		for (i = 0; i < min(mvmvif->num_target_ipv6_addrs,
183*4882a593Smuzhiyun 				    IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V2); i++) {
184*4882a593Smuzhiyun 			if (skip_tentative &&
185*4882a593Smuzhiyun 			    test_bit(i, mvmvif->tentative_addrs))
186*4882a593Smuzhiyun 				continue;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 			memcpy(cmd.v2.target_ipv6_addr[i],
189*4882a593Smuzhiyun 			       &mvmvif->target_ipv6_addrs[i],
190*4882a593Smuzhiyun 			       sizeof(cmd.v2.target_ipv6_addr[i]));
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 			found = true;
193*4882a593Smuzhiyun 		}
194*4882a593Smuzhiyun 		if (found) {
195*4882a593Smuzhiyun 			enabled |= IWL_D3_PROTO_IPV6_VALID;
196*4882a593Smuzhiyun 			memcpy(cmd.v2.ndp_mac_addr, vif->addr, ETH_ALEN);
197*4882a593Smuzhiyun 		}
198*4882a593Smuzhiyun 	} else {
199*4882a593Smuzhiyun 		bool found = false;
200*4882a593Smuzhiyun 		BUILD_BUG_ON(sizeof(cmd.v1.target_ipv6_addr[0]) !=
201*4882a593Smuzhiyun 			     sizeof(mvmvif->target_ipv6_addrs[0]));
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 		for (i = 0; i < min(mvmvif->num_target_ipv6_addrs,
204*4882a593Smuzhiyun 				    IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V1); i++) {
205*4882a593Smuzhiyun 			if (skip_tentative &&
206*4882a593Smuzhiyun 			    test_bit(i, mvmvif->tentative_addrs))
207*4882a593Smuzhiyun 				continue;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 			memcpy(cmd.v1.target_ipv6_addr[i],
210*4882a593Smuzhiyun 			       &mvmvif->target_ipv6_addrs[i],
211*4882a593Smuzhiyun 			       sizeof(cmd.v1.target_ipv6_addr[i]));
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 			found = true;
214*4882a593Smuzhiyun 		}
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 		if (found) {
217*4882a593Smuzhiyun 			enabled |= IWL_D3_PROTO_IPV6_VALID;
218*4882a593Smuzhiyun 			memcpy(cmd.v1.ndp_mac_addr, vif->addr, ETH_ALEN);
219*4882a593Smuzhiyun 		}
220*4882a593Smuzhiyun 	}
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	if (offload_ns && (enabled & IWL_D3_PROTO_IPV6_VALID))
223*4882a593Smuzhiyun 		enabled |= IWL_D3_PROTO_OFFLOAD_NS;
224*4882a593Smuzhiyun #endif
225*4882a593Smuzhiyun 	if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) {
226*4882a593Smuzhiyun 		common = &cmd.v3s.common;
227*4882a593Smuzhiyun 		size = sizeof(cmd.v3s);
228*4882a593Smuzhiyun 	} else if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) {
229*4882a593Smuzhiyun 		common = &cmd.v3l.common;
230*4882a593Smuzhiyun 		size = sizeof(cmd.v3l);
231*4882a593Smuzhiyun 	} else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) {
232*4882a593Smuzhiyun 		common = &cmd.v2.common;
233*4882a593Smuzhiyun 		size = sizeof(cmd.v2);
234*4882a593Smuzhiyun 	} else {
235*4882a593Smuzhiyun 		common = &cmd.v1.common;
236*4882a593Smuzhiyun 		size = sizeof(cmd.v1);
237*4882a593Smuzhiyun 	}
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	if (vif->bss_conf.arp_addr_cnt) {
240*4882a593Smuzhiyun 		enabled |= IWL_D3_PROTO_OFFLOAD_ARP | IWL_D3_PROTO_IPV4_VALID;
241*4882a593Smuzhiyun 		common->host_ipv4_addr = vif->bss_conf.arp_addr_list[0];
242*4882a593Smuzhiyun 		memcpy(common->arp_mac_addr, vif->addr, ETH_ALEN);
243*4882a593Smuzhiyun 	}
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 	if (!disable_offloading)
246*4882a593Smuzhiyun 		common->enabled = cpu_to_le32(enabled);
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 	hcmd.len[0] = size;
249*4882a593Smuzhiyun 	return iwl_mvm_send_cmd(mvm, &hcmd);
250*4882a593Smuzhiyun }
251