xref: /dragonfly/sys/dev/netif/iwm/if_iwm_mac_ctxt.c (revision d3e43a7a)
1 /*	$OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $	*/
2 
3 /*
4  * Copyright (c) 2014 genua mbh <info@genua.de>
5  * Copyright (c) 2014 Fixup Software Ltd.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /*-
21  * Based on BSD-licensed source modules in the Linux iwlwifi driver,
22  * which were used as the reference documentation for this implementation.
23  *
24  * Driver version we are currently based off of is
25  * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd)
26  *
27  ***********************************************************************
28  *
29  * This file is provided under a dual BSD/GPLv2 license.  When using or
30  * redistributing this file, you may do so under either license.
31  *
32  * GPL LICENSE SUMMARY
33  *
34  * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
35  *
36  * This program is free software; you can redistribute it and/or modify
37  * it under the terms of version 2 of the GNU General Public License as
38  * published by the Free Software Foundation.
39  *
40  * This program is distributed in the hope that it will be useful, but
41  * WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43  * General Public License for more details.
44  *
45  * You should have received a copy of the GNU General Public License
46  * along with this program; if not, write to the Free Software
47  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
48  * USA
49  *
50  * The full GNU General Public License is included in this distribution
51  * in the file called COPYING.
52  *
53  * Contact Information:
54  *  Intel Linux Wireless <ilw@linux.intel.com>
55  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
56  *
57  *
58  * BSD LICENSE
59  *
60  * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
61  * All rights reserved.
62  *
63  * Redistribution and use in source and binary forms, with or without
64  * modification, are permitted provided that the following conditions
65  * are met:
66  *
67  *  * Redistributions of source code must retain the above copyright
68  *    notice, this list of conditions and the following disclaimer.
69  *  * Redistributions in binary form must reproduce the above copyright
70  *    notice, this list of conditions and the following disclaimer in
71  *    the documentation and/or other materials provided with the
72  *    distribution.
73  *  * Neither the name Intel Corporation nor the names of its
74  *    contributors may be used to endorse or promote products derived
75  *    from this software without specific prior written permission.
76  *
77  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
78  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
79  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
80  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
81  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
82  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
83  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
87  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88  */
89 
90 /*-
91  * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr>
92  *
93  * Permission to use, copy, modify, and distribute this software for any
94  * purpose with or without fee is hereby granted, provided that the above
95  * copyright notice and this permission notice appear in all copies.
96  *
97  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
98  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
99  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
100  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
101  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
102  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
103  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
104  */
105 #include <sys/cdefs.h>
106 __FBSDID("$FreeBSD$");
107 
108 #include <sys/param.h>
109 #include <sys/bus.h>
110 #include <sys/endian.h>
111 #include <sys/firmware.h>
112 #include <sys/kernel.h>
113 #include <sys/malloc.h>
114 #include <sys/mbuf.h>
115 #include <sys/mutex.h>
116 #include <sys/module.h>
117 #include <sys/proc.h>
118 #include <sys/rman.h>
119 #include <sys/socket.h>
120 #include <sys/sockio.h>
121 #include <sys/sysctl.h>
122 #include <sys/linker.h>
123 
124 #include <machine/endian.h>
125 
126 #include <bus/pci/pcivar.h>
127 #include <bus/pci/pcireg.h>
128 
129 #include <net/bpf.h>
130 
131 #include <net/if.h>
132 #include <net/if_var.h>
133 #include <net/if_arp.h>
134 #include <net/ethernet.h>
135 #include <net/if_dl.h>
136 #include <net/if_media.h>
137 #include <net/if_types.h>
138 #include <net/ifq_var.h>
139 
140 #include <netinet/in.h>
141 #include <netinet/in_systm.h>
142 #include <netinet/if_ether.h>
143 #include <netinet/ip.h>
144 
145 #include <netproto/802_11/ieee80211_var.h>
146 #include <netproto/802_11/ieee80211_regdomain.h>
147 #include <netproto/802_11/ieee80211_ratectl.h>
148 #include <netproto/802_11/ieee80211_radiotap.h>
149 
150 #include "if_iwmreg.h"
151 #include "if_iwmvar.h"
152 #include "if_iwm_debug.h"
153 #include "if_iwm_util.h"
154 #include "if_iwm_mac_ctxt.h"
155 
156 static void
157 iwm_mvm_ack_rates(struct iwm_softc *sc, int is2ghz,
158 	int *cck_rates, int *ofdm_rates)
159 {
160 	int lowest_present_ofdm = 100;
161 	int lowest_present_cck = 100;
162 	uint8_t cck = 0;
163 	uint8_t ofdm = 0;
164 	int i;
165 
166 	if (is2ghz) {
167 		for (i = 0; i <= IWM_LAST_CCK_RATE; i++) {
168 			cck |= (1 << i);
169 			if (lowest_present_cck > i)
170 				lowest_present_cck = i;
171 		}
172 	}
173 	for (i = IWM_FIRST_OFDM_RATE; i <= IWM_LAST_NON_HT_RATE; i++) {
174 		int adj = i - IWM_FIRST_OFDM_RATE;
175 		ofdm |= (1 << adj);
176 		if (lowest_present_ofdm > i)
177 			lowest_present_ofdm = i;
178 	}
179 
180 	/*
181 	 * Now we've got the basic rates as bitmaps in the ofdm and cck
182 	 * variables. This isn't sufficient though, as there might not
183 	 * be all the right rates in the bitmap. E.g. if the only basic
184 	 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
185 	 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
186 	 *
187 	 *    [...] a STA responding to a received frame shall transmit
188 	 *    its Control Response frame [...] at the highest rate in the
189 	 *    BSSBasicRateSet parameter that is less than or equal to the
190 	 *    rate of the immediately previous frame in the frame exchange
191 	 *    sequence ([...]) and that is of the same modulation class
192 	 *    ([...]) as the received frame. If no rate contained in the
193 	 *    BSSBasicRateSet parameter meets these conditions, then the
194 	 *    control frame sent in response to a received frame shall be
195 	 *    transmitted at the highest mandatory rate of the PHY that is
196 	 *    less than or equal to the rate of the received frame, and
197 	 *    that is of the same modulation class as the received frame.
198 	 *
199 	 * As a consequence, we need to add all mandatory rates that are
200 	 * lower than all of the basic rates to these bitmaps.
201 	 */
202 
203 	if (IWM_RATE_24M_INDEX < lowest_present_ofdm)
204 		ofdm |= IWM_RATE_BIT_MSK(24) >> IWM_FIRST_OFDM_RATE;
205 	if (IWM_RATE_12M_INDEX < lowest_present_ofdm)
206 		ofdm |= IWM_RATE_BIT_MSK(12) >> IWM_FIRST_OFDM_RATE;
207 	/* 6M already there or needed so always add */
208 	ofdm |= IWM_RATE_BIT_MSK(6) >> IWM_FIRST_OFDM_RATE;
209 
210 	/*
211 	 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
212 	 * Note, however:
213 	 *  - if no CCK rates are basic, it must be ERP since there must
214 	 *    be some basic rates at all, so they're OFDM => ERP PHY
215 	 *    (or we're in 5 GHz, and the cck bitmap will never be used)
216 	 *  - if 11M is a basic rate, it must be ERP as well, so add 5.5M
217 	 *  - if 5.5M is basic, 1M and 2M are mandatory
218 	 *  - if 2M is basic, 1M is mandatory
219 	 *  - if 1M is basic, that's the only valid ACK rate.
220 	 * As a consequence, it's not as complicated as it sounds, just add
221 	 * any lower rates to the ACK rate bitmap.
222 	 */
223 	if (IWM_RATE_11M_INDEX < lowest_present_cck)
224 		cck |= IWM_RATE_BIT_MSK(11) >> IWM_FIRST_CCK_RATE;
225 	if (IWM_RATE_5M_INDEX < lowest_present_cck)
226 		cck |= IWM_RATE_BIT_MSK(5) >> IWM_FIRST_CCK_RATE;
227 	if (IWM_RATE_2M_INDEX < lowest_present_cck)
228 		cck |= IWM_RATE_BIT_MSK(2) >> IWM_FIRST_CCK_RATE;
229 	/* 1M already there or needed so always add */
230 	cck |= IWM_RATE_BIT_MSK(1) >> IWM_FIRST_CCK_RATE;
231 
232 	*cck_rates = cck;
233 	*ofdm_rates = ofdm;
234 }
235 
236 static void
237 iwm_mvm_mac_ctxt_cmd_common(struct iwm_softc *sc, struct iwm_node *in,
238 	struct iwm_mac_ctx_cmd *cmd, uint32_t action)
239 {
240 	struct ieee80211com *ic = sc->sc_ic;
241 	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
242 	struct ieee80211_node *ni = vap->iv_bss;
243 	int cck_ack_rates, ofdm_ack_rates;
244 	int i;
245 	int is2ghz;
246 
247 	/*
248 	 * id is the MAC address ID - something to do with MAC filtering.
249 	 * color - not sure.
250 	 *
251 	 * These are both functions of the vap, not of the node.
252 	 * So, for now, hard-code both to 0 (default).
253 	 */
254 	cmd->id_and_color = htole32(IWM_FW_CMD_ID_AND_COLOR(IWM_DEFAULT_MACID,
255 	    IWM_DEFAULT_COLOR));
256 	cmd->action = htole32(action);
257 
258 	cmd->mac_type = htole32(IWM_FW_MAC_TYPE_BSS_STA);
259 
260 	/*
261 	 * The TSF ID is one of four TSF tracking resources in the firmware.
262 	 * Read the iwlwifi/mvm code for more details.
263 	 *
264 	 * For now, just hard-code it to TSF tracking ID 0; we only support
265 	 * a single STA mode VAP.
266 	 *
267 	 * It's per-vap, not per-node.
268 	 */
269 	cmd->tsf_id = htole32(IWM_DEFAULT_TSFID);
270 
271 	IEEE80211_ADDR_COPY(cmd->node_addr, sc->sc_bssid);
272 
273 	/*
274 	 * XXX should we error out if in_assoc is 1 and ni == NULL?
275 	 */
276 	if (in->in_assoc) {
277 		IEEE80211_ADDR_COPY(cmd->bssid_addr, ni->ni_bssid);
278 	} else {
279 		/* eth broadcast address */
280 		memset(cmd->bssid_addr, 0xff, sizeof(cmd->bssid_addr));
281 	}
282 
283 	/*
284 	 * Default to 2ghz if no node information is given.
285 	 */
286 	if (in) {
287 		is2ghz = !! IEEE80211_IS_CHAN_2GHZ(in->in_ni.ni_chan);
288 	} else {
289 		is2ghz = 1;
290 	}
291 	iwm_mvm_ack_rates(sc, is2ghz, &cck_ack_rates, &ofdm_ack_rates);
292 	cmd->cck_rates = htole32(cck_ack_rates);
293 	cmd->ofdm_rates = htole32(ofdm_ack_rates);
294 
295 	cmd->cck_short_preamble
296 	    = htole32((ic->ic_flags & IEEE80211_F_SHPREAMBLE)
297 	      ? IWM_MAC_FLG_SHORT_PREAMBLE : 0);
298 	cmd->short_slot
299 	    = htole32((ic->ic_flags & IEEE80211_F_SHSLOT)
300 	      ? IWM_MAC_FLG_SHORT_SLOT : 0);
301 
302 	/* XXX TODO: set wme parameters; also handle getting updated wme parameters */
303 	for (i = 0; i < IWM_AC_NUM+1; i++) {
304 		int txf = i;
305 
306 		cmd->ac[txf].cw_min = htole16(0x0f);
307 		cmd->ac[txf].cw_max = htole16(0x3f);
308 		cmd->ac[txf].aifsn = 1;
309 		cmd->ac[txf].fifos_mask = (1 << txf);
310 		cmd->ac[txf].edca_txop = 0;
311 	}
312 
313 	if (ic->ic_flags & IEEE80211_F_USEPROT)
314 		cmd->protection_flags |= htole32(IWM_MAC_PROT_FLG_TGG_PROTECT);
315 
316 	cmd->filter_flags = htole32(IWM_MAC_FILTER_ACCEPT_GRP);
317 }
318 
319 static int
320 iwm_mvm_mac_ctxt_send_cmd(struct iwm_softc *sc, struct iwm_mac_ctx_cmd *cmd)
321 {
322 	int ret = iwm_mvm_send_cmd_pdu(sc, IWM_MAC_CONTEXT_CMD, IWM_CMD_SYNC,
323 				       sizeof(*cmd), cmd);
324 	if (ret)
325 		device_printf(sc->sc_dev,
326 		    "%s: Failed to send MAC context (action:%d): %d\n",
327 		    __func__, le32toh(cmd->action), ret);
328 	return ret;
329 }
330 
331 /*
332  * Fill the specific data for mac context of type station or p2p client
333  */
334 static void
335 iwm_mvm_mac_ctxt_cmd_fill_sta(struct iwm_softc *sc, struct iwm_node *in,
336 	struct iwm_mac_data_sta *ctxt_sta, int force_assoc_off)
337 {
338 	struct ieee80211_node *ni = &in->in_ni;
339 	unsigned dtim_period, dtim_count;
340 	struct ieee80211com *ic = sc->sc_ic;
341 	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
342 
343 	/* will this work? */
344 	dtim_period = vap->iv_dtim_period;
345 	dtim_count = vap->iv_dtim_count;
346 	IWM_DPRINTF(sc, IWM_DEBUG_RESET | IWM_DEBUG_BEACON | IWM_DEBUG_CMD,
347 	    "%s: force_assoc_off=%d\n", __func__, force_assoc_off);
348 	IWM_DPRINTF(sc, IWM_DEBUG_RESET | IWM_DEBUG_BEACON | IWM_DEBUG_CMD,
349 	    "DTIM: period=%d count=%d\n", dtim_period, dtim_count);
350 	IWM_DPRINTF(sc, IWM_DEBUG_RESET | IWM_DEBUG_BEACON | IWM_DEBUG_CMD,
351 	    "BEACON: tsf: %llu, ni_intval=%d\n",
352 	    (unsigned long long) le64toh(ni->ni_tstamp.tsf),
353 	    ni->ni_intval);
354 
355 	/* We need the dtim_period to set the MAC as associated */
356 	if (in->in_assoc && dtim_period && !force_assoc_off) {
357 		uint64_t tsf;
358 		uint32_t dtim_offs;
359 
360 		/*
361 		 * The DTIM count counts down, so when it is N that means N
362 		 * more beacon intervals happen until the DTIM TBTT. Therefore
363 		 * add this to the current time. If that ends up being in the
364 		 * future, the firmware will handle it.
365 		 *
366 		 * Also note that the system_timestamp (which we get here as
367 		 * "sync_device_ts") and TSF timestamp aren't at exactly the
368 		 * same offset in the frame -- the TSF is at the first symbol
369 		 * of the TSF, the system timestamp is at signal acquisition
370 		 * time. This means there's an offset between them of at most
371 		 * a few hundred microseconds (24 * 8 bits + PLCP time gives
372 		 * 384us in the longest case), this is currently not relevant
373 		 * as the firmware wakes up around 2ms before the TBTT.
374 		 */
375 		dtim_offs = dtim_count * ni->ni_intval;
376 		/* convert TU to usecs */
377 		dtim_offs *= 1024;
378 
379 		/*
380 		 * net80211: TSF is in 802.11 order, so convert up to local
381 		 * ordering before we manipulate things.
382 		 */
383 		tsf = le64toh(ni->ni_tstamp.tsf);
384 
385 		ctxt_sta->dtim_tsf = htole64(tsf + dtim_offs);
386 		ctxt_sta->dtim_time = htole32(tsf + dtim_offs);
387 
388 		IWM_DPRINTF(sc, IWM_DEBUG_RESET | IWM_DEBUG_BEACON | IWM_DEBUG_CMD,
389 		    "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
390 		    (long long)le64toh(ctxt_sta->dtim_tsf),
391 		    le32toh(ctxt_sta->dtim_time), dtim_offs);
392 
393 		ctxt_sta->is_assoc = htole32(1);
394 	} else {
395 		ctxt_sta->is_assoc = htole32(0);
396 	}
397 
398 	IWM_DPRINTF(sc, IWM_DEBUG_RESET | IWM_DEBUG_CMD | IWM_DEBUG_BEACON,
399 	    "%s: ni_intval: %d, bi_reciprocal: %d, dtim_interval: %d, dtim_reciprocal: %d\n",
400 	    __func__,
401 	    ni->ni_intval,
402 	    iwm_mvm_reciprocal(ni->ni_intval),
403 	    ni->ni_intval * dtim_period,
404 	    iwm_mvm_reciprocal(ni->ni_intval * dtim_period));
405 
406 	ctxt_sta->bi = htole32(ni->ni_intval);
407 	ctxt_sta->bi_reciprocal = htole32(iwm_mvm_reciprocal(ni->ni_intval));
408 	ctxt_sta->dtim_interval = htole32(ni->ni_intval * dtim_period);
409 	ctxt_sta->dtim_reciprocal =
410 	    htole32(iwm_mvm_reciprocal(ni->ni_intval * dtim_period));
411 
412 	/* 10 = CONN_MAX_LISTEN_INTERVAL */
413 	ctxt_sta->listen_interval = htole32(10);
414 	IWM_DPRINTF(sc, IWM_DEBUG_RESET | IWM_DEBUG_CMD | IWM_DEBUG_BEACON,
415 	    "%s: associd=%d\n", __func__, IEEE80211_AID(ni->ni_associd));
416 	ctxt_sta->assoc_id = htole32(IEEE80211_AID(ni->ni_associd));
417 }
418 
419 static int
420 iwm_mvm_mac_ctxt_cmd_station(struct iwm_softc *sc, struct ieee80211vap *vap,
421 	uint32_t action)
422 {
423 	struct ieee80211_node *ni = vap->iv_bss;
424 	struct iwm_node *in = (struct iwm_node *) ni;
425 	struct iwm_mac_ctx_cmd cmd;
426 
427 	IWM_DPRINTF(sc, IWM_DEBUG_RESET,
428 	    "%s: called; action=%d\n", __func__, action);
429 
430 	memset(&cmd, 0, sizeof(cmd));
431 
432 	/* Fill the common data for all mac context types */
433 	iwm_mvm_mac_ctxt_cmd_common(sc, in, &cmd, action);
434 
435 	/* Allow beacons to pass through as long as we are not associated,or we
436 	 * do not have dtim period information */
437 	if (!in->in_assoc || !vap->iv_dtim_period)
438 		cmd.filter_flags |= htole32(IWM_MAC_FILTER_IN_BEACON);
439 	else
440 		cmd.filter_flags &= ~htole32(IWM_MAC_FILTER_IN_BEACON);
441 
442 	/* Fill the data specific for station mode */
443 	iwm_mvm_mac_ctxt_cmd_fill_sta(sc, in,
444 	    &cmd.sta, action == IWM_FW_CTXT_ACTION_ADD);
445 
446 	return iwm_mvm_mac_ctxt_send_cmd(sc, &cmd);
447 }
448 
449 static int
450 iwm_mvm_mac_ctx_send(struct iwm_softc *sc, struct ieee80211vap *vap,
451     uint32_t action)
452 {
453 	int ret;
454 
455 	ret = iwm_mvm_mac_ctxt_cmd_station(sc, vap, action);
456 	if (ret)
457 		return (ret);
458 
459 	return (0);
460 }
461 
462 int
463 iwm_mvm_mac_ctxt_add(struct iwm_softc *sc, struct ieee80211vap *vap)
464 {
465 	struct iwm_vap *iv = IWM_VAP(vap);
466 	int ret;
467 
468 	if (iv->is_uploaded != 0) {
469 		device_printf(sc->sc_dev, "%s: called; uploaded != 0\n",
470 		    __func__);
471 		return (EIO);
472 	}
473 
474 	ret = iwm_mvm_mac_ctx_send(sc, vap, IWM_FW_CTXT_ACTION_ADD);
475 	if (ret)
476 		return (ret);
477 	iv->is_uploaded = 1;
478 	return (0);
479 }
480 
481 int
482 iwm_mvm_mac_ctxt_changed(struct iwm_softc *sc, struct ieee80211vap *vap)
483 {
484 	struct iwm_vap *iv = IWM_VAP(vap);
485 	int ret;
486 
487 	if (iv->is_uploaded == 0) {
488 		device_printf(sc->sc_dev, "%s: called; uploaded = 0\n",
489 		    __func__);
490 		return (EIO);
491 	}
492 	ret = iwm_mvm_mac_ctx_send(sc, vap, IWM_FW_CTXT_ACTION_MODIFY);
493 	if (ret)
494 		return (ret);
495 	return (0);
496 }
497 
498 #if 0
499 static int
500 iwm_mvm_mac_ctxt_remove(struct iwm_softc *sc, struct iwm_node *in)
501 {
502 	struct iwm_mac_ctx_cmd cmd;
503 	int ret;
504 
505 	if (!in->in_uploaded) {
506 		device_printf(sc->sc_dev,
507 		    "attempt to remove !uploaded node %p", in);
508 		return EIO;
509 	}
510 
511 	memset(&cmd, 0, sizeof(cmd));
512 
513 	cmd.id_and_color = htole32(IWM_FW_CMD_ID_AND_COLOR(IWM_DEFAULT_MACID,
514 	    IWM_DEFAULT_COLOR));
515 	cmd.action = htole32(IWM_FW_CTXT_ACTION_REMOVE);
516 
517 	ret = iwm_mvm_send_cmd_pdu(sc,
518 	    IWM_MAC_CONTEXT_CMD, IWM_CMD_SYNC, sizeof(cmd), &cmd);
519 	if (ret) {
520 		device_printf(sc->sc_dev,
521 		    "Failed to remove MAC context: %d\n", ret);
522 		return ret;
523 	}
524 	in->in_uploaded = 0;
525 
526 	return 0;
527 }
528 #endif
529