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