offloading.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
  67. struct iwl_wowlan_config_cmd_v2 *cmd)
  68. {
  69. int i;
  70. /*
  71. * For QoS counters, we store the one to use next, so subtract 0x10
  72. * since the uCode will add 0x10 *before* using the value while we
  73. * increment after using the value (i.e. store the next value to use).
  74. */
  75. for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
  76. u16 seq = mvm_ap_sta->tid_data[i].seq_number;
  77. seq -= 0x10;
  78. cmd->qos_seq[i] = cpu_to_le16(seq);
  79. }
  80. }
  81. int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
  82. struct ieee80211_vif *vif,
  83. bool disable_offloading,
  84. u32 cmd_flags)
  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_flags,
  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. if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL ||
  105. capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) {
  106. struct iwl_ns_config *nsc;
  107. struct iwl_targ_addr *addrs;
  108. int n_nsc, n_addrs;
  109. int c;
  110. if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) {
  111. nsc = cmd.v3s.ns_config;
  112. n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3S;
  113. addrs = cmd.v3s.targ_addrs;
  114. n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3S;
  115. } else {
  116. nsc = cmd.v3l.ns_config;
  117. n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3L;
  118. addrs = cmd.v3l.targ_addrs;
  119. n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3L;
  120. }
  121. if (mvmvif->num_target_ipv6_addrs)
  122. enabled |= IWL_D3_PROTO_OFFLOAD_NS;
  123. /*
  124. * For each address we have (and that will fit) fill a target
  125. * address struct and combine for NS offload structs with the
  126. * solicited node addresses.
  127. */
  128. for (i = 0, c = 0;
  129. i < mvmvif->num_target_ipv6_addrs &&
  130. i < n_addrs && c < n_nsc; i++) {
  131. struct in6_addr solicited_addr;
  132. int j;
  133. addrconf_addr_solict_mult(&mvmvif->target_ipv6_addrs[i],
  134. &solicited_addr);
  135. for (j = 0; j < c; j++)
  136. if (ipv6_addr_cmp(&nsc[j].dest_ipv6_addr,
  137. &solicited_addr) == 0)
  138. break;
  139. if (j == c)
  140. c++;
  141. addrs[i].addr = mvmvif->target_ipv6_addrs[i];
  142. addrs[i].config_num = cpu_to_le32(j);
  143. nsc[j].dest_ipv6_addr = solicited_addr;
  144. memcpy(nsc[j].target_mac_addr, vif->addr, ETH_ALEN);
  145. }
  146. if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL)
  147. cmd.v3s.num_valid_ipv6_addrs = cpu_to_le32(i);
  148. else
  149. cmd.v3l.num_valid_ipv6_addrs = cpu_to_le32(i);
  150. } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) {
  151. if (mvmvif->num_target_ipv6_addrs) {
  152. enabled |= IWL_D3_PROTO_OFFLOAD_NS;
  153. memcpy(cmd.v2.ndp_mac_addr, vif->addr, ETH_ALEN);
  154. }
  155. BUILD_BUG_ON(sizeof(cmd.v2.target_ipv6_addr[0]) !=
  156. sizeof(mvmvif->target_ipv6_addrs[0]));
  157. for (i = 0; i < min(mvmvif->num_target_ipv6_addrs,
  158. IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V2); i++)
  159. memcpy(cmd.v2.target_ipv6_addr[i],
  160. &mvmvif->target_ipv6_addrs[i],
  161. sizeof(cmd.v2.target_ipv6_addr[i]));
  162. } else {
  163. if (mvmvif->num_target_ipv6_addrs) {
  164. enabled |= IWL_D3_PROTO_OFFLOAD_NS;
  165. memcpy(cmd.v1.ndp_mac_addr, vif->addr, ETH_ALEN);
  166. }
  167. BUILD_BUG_ON(sizeof(cmd.v1.target_ipv6_addr[0]) !=
  168. sizeof(mvmvif->target_ipv6_addrs[0]));
  169. for (i = 0; i < min(mvmvif->num_target_ipv6_addrs,
  170. IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V1); i++)
  171. memcpy(cmd.v1.target_ipv6_addr[i],
  172. &mvmvif->target_ipv6_addrs[i],
  173. sizeof(cmd.v1.target_ipv6_addr[i]));
  174. }
  175. #endif
  176. if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) {
  177. common = &cmd.v3s.common;
  178. size = sizeof(cmd.v3s);
  179. } else if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) {
  180. common = &cmd.v3l.common;
  181. size = sizeof(cmd.v3l);
  182. } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) {
  183. common = &cmd.v2.common;
  184. size = sizeof(cmd.v2);
  185. } else {
  186. common = &cmd.v1.common;
  187. size = sizeof(cmd.v1);
  188. }
  189. if (vif->bss_conf.arp_addr_cnt) {
  190. enabled |= IWL_D3_PROTO_OFFLOAD_ARP;
  191. common->host_ipv4_addr = vif->bss_conf.arp_addr_list[0];
  192. memcpy(common->arp_mac_addr, vif->addr, ETH_ALEN);
  193. }
  194. if (!disable_offloading)
  195. common->enabled = cpu_to_le32(enabled);
  196. hcmd.len[0] = size;
  197. return iwl_mvm_send_cmd(mvm, &hcmd);
  198. }