binding.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. * Copyright(c) 2016 Intel Deutschland GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <linuxwifi@intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2016 Intel Deutschland GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <net/mac80211.h>
  66. #include "fw-api.h"
  67. #include "mvm.h"
  68. struct iwl_mvm_iface_iterator_data {
  69. struct ieee80211_vif *ignore_vif;
  70. int idx;
  71. struct iwl_mvm_phy_ctxt *phyctxt;
  72. u16 ids[MAX_MACS_IN_BINDING];
  73. u16 colors[MAX_MACS_IN_BINDING];
  74. };
  75. static int iwl_mvm_binding_cmd(struct iwl_mvm *mvm, u32 action,
  76. struct iwl_mvm_iface_iterator_data *data)
  77. {
  78. struct iwl_binding_cmd cmd;
  79. struct iwl_mvm_phy_ctxt *phyctxt = data->phyctxt;
  80. int i, ret;
  81. u32 status;
  82. int size;
  83. memset(&cmd, 0, sizeof(cmd));
  84. if (fw_has_capa(&mvm->fw->ucode_capa,
  85. IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT)) {
  86. size = sizeof(cmd);
  87. if (phyctxt->channel->band == NL80211_BAND_2GHZ ||
  88. !iwl_mvm_is_cdb_supported(mvm))
  89. cmd.lmac_id = cpu_to_le32(IWL_LMAC_24G_INDEX);
  90. else
  91. cmd.lmac_id = cpu_to_le32(IWL_LMAC_5G_INDEX);
  92. } else {
  93. size = IWL_BINDING_CMD_SIZE_V1;
  94. }
  95. cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
  96. phyctxt->color));
  97. cmd.action = cpu_to_le32(action);
  98. cmd.phy = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
  99. phyctxt->color));
  100. for (i = 0; i < MAX_MACS_IN_BINDING; i++)
  101. cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
  102. for (i = 0; i < data->idx; i++)
  103. cmd.macs[i] = cpu_to_le32(FW_CMD_ID_AND_COLOR(data->ids[i],
  104. data->colors[i]));
  105. status = 0;
  106. ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
  107. size, &cmd, &status);
  108. if (ret) {
  109. IWL_ERR(mvm, "Failed to send binding (action:%d): %d\n",
  110. action, ret);
  111. return ret;
  112. }
  113. if (status) {
  114. IWL_ERR(mvm, "Binding command failed: %u\n", status);
  115. ret = -EIO;
  116. }
  117. return ret;
  118. }
  119. static void iwl_mvm_iface_iterator(void *_data, u8 *mac,
  120. struct ieee80211_vif *vif)
  121. {
  122. struct iwl_mvm_iface_iterator_data *data = _data;
  123. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  124. if (vif == data->ignore_vif)
  125. return;
  126. if (mvmvif->phy_ctxt != data->phyctxt)
  127. return;
  128. if (WARN_ON_ONCE(data->idx >= MAX_MACS_IN_BINDING))
  129. return;
  130. data->ids[data->idx] = mvmvif->id;
  131. data->colors[data->idx] = mvmvif->color;
  132. data->idx++;
  133. }
  134. static int iwl_mvm_binding_update(struct iwl_mvm *mvm,
  135. struct ieee80211_vif *vif,
  136. struct iwl_mvm_phy_ctxt *phyctxt,
  137. bool add)
  138. {
  139. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  140. struct iwl_mvm_iface_iterator_data data = {
  141. .ignore_vif = vif,
  142. .phyctxt = phyctxt,
  143. };
  144. u32 action = FW_CTXT_ACTION_MODIFY;
  145. lockdep_assert_held(&mvm->mutex);
  146. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  147. IEEE80211_IFACE_ITER_NORMAL,
  148. iwl_mvm_iface_iterator,
  149. &data);
  150. /*
  151. * If there are no other interfaces yet we
  152. * need to create a new binding.
  153. */
  154. if (data.idx == 0) {
  155. if (add)
  156. action = FW_CTXT_ACTION_ADD;
  157. else
  158. action = FW_CTXT_ACTION_REMOVE;
  159. }
  160. if (add) {
  161. if (WARN_ON_ONCE(data.idx >= MAX_MACS_IN_BINDING))
  162. return -EINVAL;
  163. data.ids[data.idx] = mvmvif->id;
  164. data.colors[data.idx] = mvmvif->color;
  165. data.idx++;
  166. }
  167. return iwl_mvm_binding_cmd(mvm, action, &data);
  168. }
  169. int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  170. {
  171. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  172. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  173. return -EINVAL;
  174. /*
  175. * Update SF - Disable if needed. if this fails, SF might still be on
  176. * while many macs are bound, which is forbidden - so fail the binding.
  177. */
  178. if (iwl_mvm_sf_update(mvm, vif, false))
  179. return -EINVAL;
  180. return iwl_mvm_binding_update(mvm, vif, mvmvif->phy_ctxt, true);
  181. }
  182. int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  183. {
  184. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  185. int ret;
  186. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  187. return -EINVAL;
  188. ret = iwl_mvm_binding_update(mvm, vif, mvmvif->phy_ctxt, false);
  189. if (!ret)
  190. if (iwl_mvm_sf_update(mvm, vif, true))
  191. IWL_ERR(mvm, "Failed to update SF state\n");
  192. return ret;
  193. }