binding.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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/mac80211.h>
  64. #include "fw-api.h"
  65. #include "mvm.h"
  66. struct iwl_mvm_iface_iterator_data {
  67. struct ieee80211_vif *ignore_vif;
  68. int idx;
  69. struct iwl_mvm_phy_ctxt *phyctxt;
  70. u16 ids[MAX_MACS_IN_BINDING];
  71. u16 colors[MAX_MACS_IN_BINDING];
  72. };
  73. static int iwl_mvm_binding_cmd(struct iwl_mvm *mvm, u32 action,
  74. struct iwl_mvm_iface_iterator_data *data)
  75. {
  76. struct iwl_binding_cmd cmd;
  77. struct iwl_mvm_phy_ctxt *phyctxt = data->phyctxt;
  78. int i, ret;
  79. u32 status;
  80. memset(&cmd, 0, sizeof(cmd));
  81. cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
  82. phyctxt->color));
  83. cmd.action = cpu_to_le32(action);
  84. cmd.phy = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
  85. phyctxt->color));
  86. for (i = 0; i < MAX_MACS_IN_BINDING; i++)
  87. cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
  88. for (i = 0; i < data->idx; i++)
  89. cmd.macs[i] = cpu_to_le32(FW_CMD_ID_AND_COLOR(data->ids[i],
  90. data->colors[i]));
  91. status = 0;
  92. ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
  93. sizeof(cmd), &cmd, &status);
  94. if (ret) {
  95. IWL_ERR(mvm, "Failed to send binding (action:%d): %d\n",
  96. action, ret);
  97. return ret;
  98. }
  99. if (status) {
  100. IWL_ERR(mvm, "Binding command failed: %u\n", status);
  101. ret = -EIO;
  102. }
  103. return ret;
  104. }
  105. static void iwl_mvm_iface_iterator(void *_data, u8 *mac,
  106. struct ieee80211_vif *vif)
  107. {
  108. struct iwl_mvm_iface_iterator_data *data = _data;
  109. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  110. if (vif == data->ignore_vif)
  111. return;
  112. if (mvmvif->phy_ctxt != data->phyctxt)
  113. return;
  114. if (WARN_ON_ONCE(data->idx >= MAX_MACS_IN_BINDING))
  115. return;
  116. data->ids[data->idx] = mvmvif->id;
  117. data->colors[data->idx] = mvmvif->color;
  118. data->idx++;
  119. }
  120. static int iwl_mvm_binding_update(struct iwl_mvm *mvm,
  121. struct ieee80211_vif *vif,
  122. struct iwl_mvm_phy_ctxt *phyctxt,
  123. bool add)
  124. {
  125. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  126. struct iwl_mvm_iface_iterator_data data = {
  127. .ignore_vif = vif,
  128. .phyctxt = phyctxt,
  129. };
  130. u32 action = FW_CTXT_ACTION_MODIFY;
  131. lockdep_assert_held(&mvm->mutex);
  132. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  133. IEEE80211_IFACE_ITER_NORMAL,
  134. iwl_mvm_iface_iterator,
  135. &data);
  136. /*
  137. * If there are no other interfaces yet we
  138. * need to create a new binding.
  139. */
  140. if (data.idx == 0) {
  141. if (add)
  142. action = FW_CTXT_ACTION_ADD;
  143. else
  144. action = FW_CTXT_ACTION_REMOVE;
  145. }
  146. if (add) {
  147. if (WARN_ON_ONCE(data.idx >= MAX_MACS_IN_BINDING))
  148. return -EINVAL;
  149. data.ids[data.idx] = mvmvif->id;
  150. data.colors[data.idx] = mvmvif->color;
  151. data.idx++;
  152. }
  153. return iwl_mvm_binding_cmd(mvm, action, &data);
  154. }
  155. int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  156. {
  157. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  158. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  159. return -EINVAL;
  160. /*
  161. * Update SF - Disable if needed. if this fails, SF might still be on
  162. * while many macs are bound, which is forbidden - so fail the binding.
  163. */
  164. if (iwl_mvm_sf_update(mvm, vif, false))
  165. return -EINVAL;
  166. return iwl_mvm_binding_update(mvm, vif, mvmvif->phy_ctxt, true);
  167. }
  168. int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  169. {
  170. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  171. int ret;
  172. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  173. return -EINVAL;
  174. ret = iwl_mvm_binding_update(mvm, vif, mvmvif->phy_ctxt, false);
  175. if (!ret)
  176. if (iwl_mvm_sf_update(mvm, vif, true))
  177. IWL_ERR(mvm, "Failed to update SF state\n");
  178. return ret;
  179. }