diff options
Diffstat (limited to 'drivers/net/wireless/iwlwifi/mvm/offloading.c')
-rw-r--r-- | drivers/net/wireless/iwlwifi/mvm/offloading.c | 214 |
1 files changed, 214 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..9ec5a5991e3a --- /dev/null +++ b/drivers/net/wireless/iwlwifi/mvm/offloading.c | |||
@@ -0,0 +1,214 @@ | |||
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, struct ieee80211_vif *vif) | ||
85 | { | ||
86 | union { | ||
87 | struct iwl_proto_offload_cmd_v1 v1; | ||
88 | struct iwl_proto_offload_cmd_v2 v2; | ||
89 | struct iwl_proto_offload_cmd_v3_small v3s; | ||
90 | struct iwl_proto_offload_cmd_v3_large v3l; | ||
91 | } cmd = {}; | ||
92 | struct iwl_host_cmd hcmd = { | ||
93 | .id = PROT_OFFLOAD_CONFIG_CMD, | ||
94 | .flags = CMD_SYNC, | ||
95 | .data[0] = &cmd, | ||
96 | .dataflags[0] = IWL_HCMD_DFL_DUP, | ||
97 | }; | ||
98 | struct iwl_proto_offload_cmd_common *common; | ||
99 | u32 enabled = 0, size; | ||
100 | u32 capa_flags = mvm->fw->ucode_capa.flags; | ||
101 | #if IS_ENABLED(CONFIG_IPV6) | ||
102 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | ||
103 | int i; | ||
104 | |||
105 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL || | ||
106 | capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) { | ||
107 | struct iwl_ns_config *nsc; | ||
108 | struct iwl_targ_addr *addrs; | ||
109 | int n_nsc, n_addrs; | ||
110 | int c; | ||
111 | |||
112 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) { | ||
113 | nsc = cmd.v3s.ns_config; | ||
114 | n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3S; | ||
115 | addrs = cmd.v3s.targ_addrs; | ||
116 | n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3S; | ||
117 | } else { | ||
118 | nsc = cmd.v3l.ns_config; | ||
119 | n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3L; | ||
120 | addrs = cmd.v3l.targ_addrs; | ||
121 | n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3L; | ||
122 | } | ||
123 | |||
124 | if (mvmvif->num_target_ipv6_addrs) | ||
125 | enabled |= IWL_D3_PROTO_OFFLOAD_NS; | ||
126 | |||
127 | /* | ||
128 | * For each address we have (and that will fit) fill a target | ||
129 | * address struct and combine for NS offload structs with the | ||
130 | * solicited node addresses. | ||
131 | */ | ||
132 | for (i = 0, c = 0; | ||
133 | i < mvmvif->num_target_ipv6_addrs && | ||
134 | i < n_addrs && c < n_nsc; i++) { | ||
135 | struct in6_addr solicited_addr; | ||
136 | int j; | ||
137 | |||
138 | addrconf_addr_solict_mult(&mvmvif->target_ipv6_addrs[i], | ||
139 | &solicited_addr); | ||
140 | for (j = 0; j < c; j++) | ||
141 | if (ipv6_addr_cmp(&nsc[j].dest_ipv6_addr, | ||
142 | &solicited_addr) == 0) | ||
143 | break; | ||
144 | if (j == c) | ||
145 | c++; | ||
146 | addrs[i].addr = mvmvif->target_ipv6_addrs[i]; | ||
147 | addrs[i].config_num = cpu_to_le32(j); | ||
148 | nsc[j].dest_ipv6_addr = solicited_addr; | ||
149 | memcpy(nsc[j].target_mac_addr, vif->addr, ETH_ALEN); | ||
150 | } | ||
151 | |||
152 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) | ||
153 | cmd.v3s.num_valid_ipv6_addrs = cpu_to_le32(i); | ||
154 | else | ||
155 | cmd.v3l.num_valid_ipv6_addrs = cpu_to_le32(i); | ||
156 | } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) { | ||
157 | if (mvmvif->num_target_ipv6_addrs) { | ||
158 | enabled |= IWL_D3_PROTO_OFFLOAD_NS; | ||
159 | memcpy(cmd.v2.ndp_mac_addr, vif->addr, ETH_ALEN); | ||
160 | } | ||
161 | |||
162 | BUILD_BUG_ON(sizeof(cmd.v2.target_ipv6_addr[0]) != | ||
163 | sizeof(mvmvif->target_ipv6_addrs[0])); | ||
164 | |||
165 | for (i = 0; i < min(mvmvif->num_target_ipv6_addrs, | ||
166 | IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V2); i++) | ||
167 | memcpy(cmd.v2.target_ipv6_addr[i], | ||
168 | &mvmvif->target_ipv6_addrs[i], | ||
169 | sizeof(cmd.v2.target_ipv6_addr[i])); | ||
170 | } else { | ||
171 | if (mvmvif->num_target_ipv6_addrs) { | ||
172 | enabled |= IWL_D3_PROTO_OFFLOAD_NS; | ||
173 | memcpy(cmd.v1.ndp_mac_addr, vif->addr, ETH_ALEN); | ||
174 | } | ||
175 | |||
176 | BUILD_BUG_ON(sizeof(cmd.v1.target_ipv6_addr[0]) != | ||
177 | sizeof(mvmvif->target_ipv6_addrs[0])); | ||
178 | |||
179 | for (i = 0; i < min(mvmvif->num_target_ipv6_addrs, | ||
180 | IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V1); i++) | ||
181 | memcpy(cmd.v1.target_ipv6_addr[i], | ||
182 | &mvmvif->target_ipv6_addrs[i], | ||
183 | sizeof(cmd.v1.target_ipv6_addr[i])); | ||
184 | } | ||
185 | #endif | ||
186 | |||
187 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) { | ||
188 | common = &cmd.v3s.common; | ||
189 | size = sizeof(cmd.v3s); | ||
190 | } else if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) { | ||
191 | common = &cmd.v3l.common; | ||
192 | size = sizeof(cmd.v3l); | ||
193 | } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) { | ||
194 | common = &cmd.v2.common; | ||
195 | size = sizeof(cmd.v2); | ||
196 | } else { | ||
197 | common = &cmd.v1.common; | ||
198 | size = sizeof(cmd.v1); | ||
199 | } | ||
200 | |||
201 | if (vif->bss_conf.arp_addr_cnt) { | ||
202 | enabled |= IWL_D3_PROTO_OFFLOAD_ARP; | ||
203 | common->host_ipv4_addr = vif->bss_conf.arp_addr_list[0]; | ||
204 | memcpy(common->arp_mac_addr, vif->addr, ETH_ALEN); | ||
205 | } | ||
206 | |||
207 | if (!enabled) | ||
208 | return 0; | ||
209 | |||
210 | common->enabled = cpu_to_le32(enabled); | ||
211 | |||
212 | hcmd.len[0] = size; | ||
213 | return iwl_mvm_send_cmd(mvm, &hcmd); | ||
214 | } | ||