From f16ef74977e51e1bfc7a625dd18b98b02158e0e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Imre=20Vad=C3=A1sz?= Date: Sun, 16 Oct 2016 20:55:13 +0200 Subject: [PATCH] if_iwm - Partly sync if_iwm_binding.c to Linux iwlwifi code. * Store macid and color values in struct iwm_vap, to avoid hardcoded constants a bit. * Add iwm_mvm_binding_remove_vif() function (will be used in disconnecting from an access point without resetting the whole device). * Not adding code from Linux iwlwifi yet, to handle one PHY context to be bound to several VAPs/virtual-interfaces, it's definitely not needed in the near future. Taken-From: Linux iwlwifi --- sys/dev/netif/iwm/if_iwm.c | 11 ++-- sys/dev/netif/iwm/if_iwm_binding.c | 118 ++++++++++++++++++++++------------ sys/dev/netif/iwm/if_iwm_binding.h | 4 +- sys/dev/netif/iwm/if_iwm_mac_ctxt.c | 5 +- sys/dev/netif/iwm/if_iwm_power.c | 5 +- sys/dev/netif/iwm/if_iwm_time_event.c | 8 +-- sys/dev/netif/iwm/if_iwm_time_event.h | 2 +- sys/dev/netif/iwm/if_iwmvar.h | 3 + 8 files changed, 100 insertions(+), 56 deletions(-) diff --git a/sys/dev/netif/iwm/if_iwm.c b/sys/dev/netif/iwm/if_iwm.c index d12d5e6898..6486275626 100644 --- a/sys/dev/netif/iwm/if_iwm.c +++ b/sys/dev/netif/iwm/if_iwm.c @@ -4157,7 +4157,7 @@ iwm_auth(struct ieee80211vap *vap, struct iwm_softc *sc) } iv->phy_ctxt = &sc->sc_phyctxt[0]; - if ((error = iwm_mvm_binding_update(sc, iv)) != 0) { + if ((error = iwm_mvm_binding_add_vif(sc, iv)) != 0) { device_printf(sc->sc_dev, "%s: binding update cmd\n", __func__); goto out; @@ -4206,7 +4206,7 @@ iwm_auth(struct ieee80211vap *vap, struct iwm_softc *sc) */ /* XXX duration is in units of TU, not MS */ duration = IWM_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; - iwm_mvm_protect_session(sc, in, duration, 500 /* XXX magic number */); + iwm_mvm_protect_session(sc, iv, duration, 500 /* XXX magic number */); DELAY(100); error = 0; @@ -4251,7 +4251,7 @@ iwm_release(struct iwm_softc *sc, struct iwm_node *in) * iwm_mvm_rm_sta(sc, in); * iwm_mvm_update_quotas(sc, NULL); * iwm_mvm_mac_ctxt_changed(sc, in); - * iwm_mvm_binding_remove_vif(sc, in); + * iwm_mvm_binding_remove_vif(sc, IWM_VAP(in->in_ni.ni_vap)); * iwm_mvm_mac_ctxt_remove(sc, in); * * However, that freezes the device not matter which permutations @@ -4300,7 +4300,7 @@ iwm_release(struct iwm_softc *sc, struct iwm_node *in) device_printf(sc->sc_dev, "mac ctxt change fail 2 %d\n", error); return error; } - iwm_mvm_binding_remove_vif(sc, in); + iwm_mvm_binding_remove_vif(sc, IWM_VAP(in->in_ni.ni_vap)); iwm_mvm_mac_ctxt_remove(sc, in); @@ -6336,6 +6336,9 @@ iwm_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit, ivp->iv_newstate = vap->iv_newstate; vap->iv_newstate = iwm_newstate; + ivp->id = IWM_DEFAULT_MACID; + ivp->color = IWM_DEFAULT_COLOR; + ieee80211_ratectl_init(vap); /* Complete setup. */ ieee80211_vap_attach(vap, iwm_media_change, ieee80211_media_status, diff --git a/sys/dev/netif/iwm/if_iwm_binding.c b/sys/dev/netif/iwm/if_iwm_binding.c index cb80a63fa1..6578e76031 100644 --- a/sys/dev/netif/iwm/if_iwm_binding.c +++ b/sys/dev/netif/iwm/if_iwm_binding.c @@ -31,7 +31,7 @@ * * GPL LICENSE SUMMARY * - * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved. + * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as @@ -51,13 +51,12 @@ * in the file called COPYING. * * Contact Information: - * Intel Linux Wireless + * Intel Linux Wireless * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 * - * * BSD LICENSE * - * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved. + * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -87,24 +86,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/*- - * Copyright (c) 2007-2010 Damien Bergamini - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -#include -__FBSDID("$FreeBSD$"); - #include #include #include @@ -146,11 +127,21 @@ __FBSDID("$FreeBSD$"); #include "if_iwm_util.h" #include "if_iwm_binding.h" -int -iwm_mvm_binding_cmd(struct iwm_softc *sc, struct iwm_vap *ivp, uint32_t action) +struct iwm_mvm_iface_iterator_data { + int idx; + + struct iwm_mvm_phy_ctxt *phyctxt; + + uint16_t ids[IWM_MAX_MACS_IN_BINDING]; + int16_t colors[IWM_MAX_MACS_IN_BINDING]; +}; + +static int +iwm_mvm_binding_cmd(struct iwm_softc *sc, uint32_t action, + struct iwm_mvm_iface_iterator_data *data) { struct iwm_binding_cmd cmd; - struct iwm_mvm_phy_ctxt *phyctxt = ivp->phy_ctxt; + struct iwm_mvm_phy_ctxt *phyctxt = data->phyctxt; int i, ret; uint32_t status; @@ -161,41 +152,88 @@ iwm_mvm_binding_cmd(struct iwm_softc *sc, struct iwm_vap *ivp, uint32_t action) cmd.action = htole32(action); cmd.phy = htole32(IWM_FW_CMD_ID_AND_COLOR(phyctxt->id, phyctxt->color)); - cmd.macs[0] = htole32(IWM_FW_CMD_ID_AND_COLOR(IWM_DEFAULT_MACID, - IWM_DEFAULT_COLOR)); - /* We use MACID 0 here.. */ - for (i = 1; i < IWM_MAX_MACS_IN_BINDING; i++) + for (i = 0; i < IWM_MAX_MACS_IN_BINDING; i++) cmd.macs[i] = htole32(IWM_FW_CTXT_INVALID); + for (i = 0; i < data->idx; i++) + cmd.macs[i] = htole32(IWM_FW_CMD_ID_AND_COLOR(data->ids[i], + data->colors[i])); status = 0; ret = iwm_mvm_send_cmd_pdu_status(sc, IWM_BINDING_CONTEXT_CMD, sizeof(cmd), &cmd, &status); if (ret) { - IWM_DPRINTF(sc, IWM_DEBUG_CMD | IWM_DEBUG_RESET, - "%s: Failed to send binding (action:%d): %d\n", - __func__, action, ret); + device_printf(sc->sc_dev, + "Failed to send binding (action:%d): %d\n", action, ret); return ret; } if (status) { - IWM_DPRINTF(sc, IWM_DEBUG_CMD | IWM_DEBUG_RESET, - "%s: Binding command failed: %u\n", - __func__, - status); + device_printf(sc->sc_dev, + "Binding command failed: %u\n", status); ret = EIO; } return ret; } -int -iwm_mvm_binding_update(struct iwm_softc *sc, struct iwm_vap *ivp) +static int +iwm_mvm_binding_update(struct iwm_softc *sc, struct iwm_vap *ivp, + struct iwm_mvm_phy_ctxt *phyctxt, boolean_t add) { - return iwm_mvm_binding_cmd(sc, ivp, IWM_FW_CTXT_ACTION_MODIFY); + struct iwm_mvm_iface_iterator_data data = { + .phyctxt = phyctxt, + }; + uint32_t action; + + if (add) + action = IWM_FW_CTXT_ACTION_ADD; + else + action = IWM_FW_CTXT_ACTION_REMOVE; + + if (add) { + data.ids[0] = ivp->id; + data.colors[0] = ivp->color; + data.idx++; + } + + return iwm_mvm_binding_cmd(sc, action, &data); } int iwm_mvm_binding_add_vif(struct iwm_softc *sc, struct iwm_vap *ivp) { - return iwm_mvm_binding_cmd(sc, ivp, IWM_FW_CTXT_ACTION_ADD); + if (!ivp->phy_ctxt) + return EINVAL; + +#ifdef notyet + /* + * Update SF - Disable if needed. if this fails, SF might still be on + * while many macs are bound, which is forbidden - so fail the binding. + */ + if (iwm_mvm_sf_update(sc, ivp, FALSE)) + return EINVAL; +#endif + + return iwm_mvm_binding_update(sc, ivp, ivp->phy_ctxt, TRUE); +} + +int +iwm_mvm_binding_remove_vif(struct iwm_softc *sc, struct iwm_vap *ivp) +{ + int ret; + + if (!ivp->phy_ctxt) + return EINVAL; + + ret = iwm_mvm_binding_update(sc, ivp, ivp->phy_ctxt, FALSE); + +#ifdef notyet + if (!ret) { + if (iwm_mvm_sf_update(sc, ivp, TRUE)) + device_printf(sc->sc_dev, + "Failed to update SF state\n"); + } +#endif + + return ret; } diff --git a/sys/dev/netif/iwm/if_iwm_binding.h b/sys/dev/netif/iwm/if_iwm_binding.h index 1aa8760cfa..3a44492d03 100644 --- a/sys/dev/netif/iwm/if_iwm_binding.h +++ b/sys/dev/netif/iwm/if_iwm_binding.h @@ -105,9 +105,7 @@ #ifndef __IF_IWM_BINDING_H__ #define __IF_IWM_BINDING_H__ -extern int iwm_mvm_binding_cmd(struct iwm_softc *sc, struct iwm_vap *ivp, - uint32_t action); -extern int iwm_mvm_binding_update(struct iwm_softc *sc, struct iwm_vap *ivp); extern int iwm_mvm_binding_add_vif(struct iwm_softc *sc, struct iwm_vap *ivp); +extern int iwm_mvm_binding_remove_vif(struct iwm_softc *sc, struct iwm_vap *ivp); #endif /* __IF_IWM_BINDING_H__ */ diff --git a/sys/dev/netif/iwm/if_iwm_mac_ctxt.c b/sys/dev/netif/iwm/if_iwm_mac_ctxt.c index 671d1fd853..a6ad21c778 100644 --- a/sys/dev/netif/iwm/if_iwm_mac_ctxt.c +++ b/sys/dev/netif/iwm/if_iwm_mac_ctxt.c @@ -237,6 +237,7 @@ iwm_mvm_mac_ctxt_cmd_common(struct iwm_softc *sc, struct iwm_node *in, struct ieee80211com *ic = &sc->sc_ic; struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); struct ieee80211_node *ni = vap->iv_bss; + struct iwm_vap *ivp = IWM_VAP(vap); int cck_ack_rates, ofdm_ack_rates; int i; int is2ghz; @@ -248,8 +249,8 @@ iwm_mvm_mac_ctxt_cmd_common(struct iwm_softc *sc, struct iwm_node *in, * These are both functions of the vap, not of the node. * So, for now, hard-code both to 0 (default). */ - cmd->id_and_color = htole32(IWM_FW_CMD_ID_AND_COLOR(IWM_DEFAULT_MACID, - IWM_DEFAULT_COLOR)); + cmd->id_and_color = htole32(IWM_FW_CMD_ID_AND_COLOR(ivp->id, + ivp->color)); cmd->action = htole32(action); cmd->mac_type = htole32(IWM_FW_MAC_TYPE_BSS_STA); diff --git a/sys/dev/netif/iwm/if_iwm_power.c b/sys/dev/netif/iwm/if_iwm_power.c index a0258897f3..a9e3097ccd 100644 --- a/sys/dev/netif/iwm/if_iwm_power.c +++ b/sys/dev/netif/iwm/if_iwm_power.c @@ -271,9 +271,10 @@ iwm_mvm_power_build_cmd(struct iwm_softc *sc, struct iwm_node *in, int keep_alive; struct ieee80211com *ic = &sc->sc_ic; struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); + struct iwm_vap *ivp = IWM_VAP(vap); - cmd->id_and_color = htole32(IWM_FW_CMD_ID_AND_COLOR(IWM_DEFAULT_MACID, - IWM_DEFAULT_COLOR)); + cmd->id_and_color = htole32(IWM_FW_CMD_ID_AND_COLOR(ivp->id, + ivp->color)); dtimper = vap->iv_dtim_period ?: 1; /* diff --git a/sys/dev/netif/iwm/if_iwm_time_event.c b/sys/dev/netif/iwm/if_iwm_time_event.c index 4f82925854..c6b159dba5 100644 --- a/sys/dev/netif/iwm/if_iwm_time_event.c +++ b/sys/dev/netif/iwm/if_iwm_time_event.c @@ -155,7 +155,7 @@ __FBSDID("$FreeBSD$"); #define IWM_MVM_ROC_TE_TYPE_MGMT_TX IWM_TE_P2P_CLIENT_ASSOC static int -iwm_mvm_time_event_send_add(struct iwm_softc *sc, struct iwm_node *in, +iwm_mvm_time_event_send_add(struct iwm_softc *sc, struct iwm_vap *ivp, void *te_data, struct iwm_time_event_cmd *te_cmd) { int ret; @@ -175,14 +175,14 @@ iwm_mvm_time_event_send_add(struct iwm_softc *sc, struct iwm_node *in, } void -iwm_mvm_protect_session(struct iwm_softc *sc, struct iwm_node *in, +iwm_mvm_protect_session(struct iwm_softc *sc, struct iwm_vap *ivp, uint32_t duration, uint32_t max_delay) { struct iwm_time_event_cmd time_cmd = {}; time_cmd.action = htole32(IWM_FW_CTXT_ACTION_ADD); time_cmd.id_and_color = - htole32(IWM_FW_CMD_ID_AND_COLOR(IWM_DEFAULT_MACID, IWM_DEFAULT_COLOR)); + htole32(IWM_FW_CMD_ID_AND_COLOR(ivp->id, ivp->color)); time_cmd.id = htole32(IWM_TE_BSS_STA_AGGRESSIVE_ASSOC); time_cmd.apply_time = htole32(0); @@ -197,5 +197,5 @@ iwm_mvm_protect_session(struct iwm_softc *sc, struct iwm_node *in, IWM_TE_V2_NOTIF_HOST_EVENT_END | IWM_T2_V2_START_IMMEDIATELY); - iwm_mvm_time_event_send_add(sc, in, /*te_data*/NULL, &time_cmd); + iwm_mvm_time_event_send_add(sc, ivp, /*te_data*/NULL, &time_cmd); } diff --git a/sys/dev/netif/iwm/if_iwm_time_event.h b/sys/dev/netif/iwm/if_iwm_time_event.h index 015652ece3..4c741428e1 100644 --- a/sys/dev/netif/iwm/if_iwm_time_event.h +++ b/sys/dev/netif/iwm/if_iwm_time_event.h @@ -107,7 +107,7 @@ #ifndef __IF_IWM_TIME_EVENT_H__ #define __IF_IWM_TIME_EVENT_H__ -extern void iwm_mvm_protect_session(struct iwm_softc *sc, struct iwm_node *in, +extern void iwm_mvm_protect_session(struct iwm_softc *sc, struct iwm_vap *ivp, uint32_t duration, uint32_t max_delay); #endif /* __IF_IWM_TIME_EVENT_H__ */ diff --git a/sys/dev/netif/iwm/if_iwmvar.h b/sys/dev/netif/iwm/if_iwmvar.h index 970a6729ca..a383ed5e0e 100644 --- a/sys/dev/netif/iwm/if_iwmvar.h +++ b/sys/dev/netif/iwm/if_iwmvar.h @@ -375,6 +375,9 @@ struct iwm_vap { enum ieee80211_state, int); struct iwm_mvm_phy_ctxt *phy_ctxt; + + uint16_t id; + uint16_t color; }; #define IWM_VAP(_vap) ((struct iwm_vap *)(_vap)) -- 2.11.4.GIT