1ee55925eSAdrian Chadd /* $OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $ */
2ee55925eSAdrian Chadd
3ee55925eSAdrian Chadd /*
4ee55925eSAdrian Chadd * Copyright (c) 2014 genua mbh <info@genua.de>
5ee55925eSAdrian Chadd * Copyright (c) 2014 Fixup Software Ltd.
6ee55925eSAdrian Chadd *
7ee55925eSAdrian Chadd * Permission to use, copy, modify, and distribute this software for any
8ee55925eSAdrian Chadd * purpose with or without fee is hereby granted, provided that the above
9ee55925eSAdrian Chadd * copyright notice and this permission notice appear in all copies.
10ee55925eSAdrian Chadd *
11ee55925eSAdrian Chadd * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12ee55925eSAdrian Chadd * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13ee55925eSAdrian Chadd * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14ee55925eSAdrian Chadd * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15ee55925eSAdrian Chadd * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16ee55925eSAdrian Chadd * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17ee55925eSAdrian Chadd * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18ee55925eSAdrian Chadd */
19ee55925eSAdrian Chadd
20ee55925eSAdrian Chadd /*-
21ee55925eSAdrian Chadd * Based on BSD-licensed source modules in the Linux iwlwifi driver,
22ee55925eSAdrian Chadd * which were used as the reference documentation for this implementation.
23ee55925eSAdrian Chadd *
24ee55925eSAdrian Chadd * Driver version we are currently based off of is
25ee55925eSAdrian Chadd * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd)
26ee55925eSAdrian Chadd *
27ee55925eSAdrian Chadd ***********************************************************************
28ee55925eSAdrian Chadd *
29ee55925eSAdrian Chadd * This file is provided under a dual BSD/GPLv2 license. When using or
30ee55925eSAdrian Chadd * redistributing this file, you may do so under either license.
31ee55925eSAdrian Chadd *
32ee55925eSAdrian Chadd * GPL LICENSE SUMMARY
33ee55925eSAdrian Chadd *
34ee55925eSAdrian Chadd * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
35ee55925eSAdrian Chadd *
36ee55925eSAdrian Chadd * This program is free software; you can redistribute it and/or modify
37ee55925eSAdrian Chadd * it under the terms of version 2 of the GNU General Public License as
38ee55925eSAdrian Chadd * published by the Free Software Foundation.
39ee55925eSAdrian Chadd *
40ee55925eSAdrian Chadd * This program is distributed in the hope that it will be useful, but
41ee55925eSAdrian Chadd * WITHOUT ANY WARRANTY; without even the implied warranty of
42ee55925eSAdrian Chadd * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43ee55925eSAdrian Chadd * General Public License for more details.
44ee55925eSAdrian Chadd *
45ee55925eSAdrian Chadd * You should have received a copy of the GNU General Public License
46ee55925eSAdrian Chadd * along with this program; if not, write to the Free Software
47ee55925eSAdrian Chadd * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
48ee55925eSAdrian Chadd * USA
49ee55925eSAdrian Chadd *
50ee55925eSAdrian Chadd * The full GNU General Public License is included in this distribution
51ee55925eSAdrian Chadd * in the file called COPYING.
52ee55925eSAdrian Chadd *
53ee55925eSAdrian Chadd * Contact Information:
54ee55925eSAdrian Chadd * Intel Linux Wireless <ilw@linux.intel.com>
55ee55925eSAdrian Chadd * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
56ee55925eSAdrian Chadd *
57ee55925eSAdrian Chadd *
58ee55925eSAdrian Chadd * BSD LICENSE
59ee55925eSAdrian Chadd *
60ee55925eSAdrian Chadd * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
61ee55925eSAdrian Chadd * All rights reserved.
62ee55925eSAdrian Chadd *
63ee55925eSAdrian Chadd * Redistribution and use in source and binary forms, with or without
64ee55925eSAdrian Chadd * modification, are permitted provided that the following conditions
65ee55925eSAdrian Chadd * are met:
66ee55925eSAdrian Chadd *
67ee55925eSAdrian Chadd * * Redistributions of source code must retain the above copyright
68ee55925eSAdrian Chadd * notice, this list of conditions and the following disclaimer.
69ee55925eSAdrian Chadd * * Redistributions in binary form must reproduce the above copyright
70ee55925eSAdrian Chadd * notice, this list of conditions and the following disclaimer in
71ee55925eSAdrian Chadd * the documentation and/or other materials provided with the
72ee55925eSAdrian Chadd * distribution.
73ee55925eSAdrian Chadd * * Neither the name Intel Corporation nor the names of its
74ee55925eSAdrian Chadd * contributors may be used to endorse or promote products derived
75ee55925eSAdrian Chadd * from this software without specific prior written permission.
76ee55925eSAdrian Chadd *
77ee55925eSAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
78ee55925eSAdrian Chadd * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
79ee55925eSAdrian Chadd * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
80ee55925eSAdrian Chadd * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
81ee55925eSAdrian Chadd * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
82ee55925eSAdrian Chadd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
83ee55925eSAdrian Chadd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84ee55925eSAdrian Chadd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85ee55925eSAdrian Chadd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86ee55925eSAdrian Chadd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
87ee55925eSAdrian Chadd * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88ee55925eSAdrian Chadd */
89ee55925eSAdrian Chadd #include <sys/cdefs.h>
90616201d1SAdrian Chadd #include "opt_wlan.h"
91616201d1SAdrian Chadd #include "opt_iwm.h"
92616201d1SAdrian Chadd
93ee55925eSAdrian Chadd #include <sys/param.h>
94ee55925eSAdrian Chadd #include <sys/bus.h>
95ee55925eSAdrian Chadd #include <sys/endian.h>
96ee55925eSAdrian Chadd #include <sys/firmware.h>
97ee55925eSAdrian Chadd #include <sys/kernel.h>
98ee55925eSAdrian Chadd #include <sys/malloc.h>
99ee55925eSAdrian Chadd #include <sys/mbuf.h>
100ee55925eSAdrian Chadd #include <sys/mutex.h>
101ee55925eSAdrian Chadd #include <sys/module.h>
102ee55925eSAdrian Chadd #include <sys/proc.h>
103ee55925eSAdrian Chadd #include <sys/rman.h>
104ee55925eSAdrian Chadd #include <sys/socket.h>
105ee55925eSAdrian Chadd #include <sys/sockio.h>
106ee55925eSAdrian Chadd #include <sys/sysctl.h>
107ee55925eSAdrian Chadd #include <sys/linker.h>
108ee55925eSAdrian Chadd
109ee55925eSAdrian Chadd #include <machine/endian.h>
110ee55925eSAdrian Chadd #include <machine/bus.h>
111ee55925eSAdrian Chadd
112ee55925eSAdrian Chadd #include <net/bpf.h>
113ee55925eSAdrian Chadd
114ee55925eSAdrian Chadd #include <net/if.h>
115ee55925eSAdrian Chadd #include <net/if_var.h>
116ee55925eSAdrian Chadd #include <net/if_arp.h>
117ee55925eSAdrian Chadd #include <net/ethernet.h>
118ee55925eSAdrian Chadd #include <net/if_dl.h>
119ee55925eSAdrian Chadd #include <net/if_media.h>
120ee55925eSAdrian Chadd #include <net/if_types.h>
121ee55925eSAdrian Chadd
122ee55925eSAdrian Chadd #include <netinet/in.h>
123ee55925eSAdrian Chadd #include <netinet/in_systm.h>
124ee55925eSAdrian Chadd #include <netinet/if_ether.h>
125ee55925eSAdrian Chadd #include <netinet/ip.h>
126ee55925eSAdrian Chadd
127ee55925eSAdrian Chadd #include <net80211/ieee80211_var.h>
128ee55925eSAdrian Chadd #include <net80211/ieee80211_regdomain.h>
129ee55925eSAdrian Chadd #include <net80211/ieee80211_ratectl.h>
130ee55925eSAdrian Chadd #include <net80211/ieee80211_radiotap.h>
131ee55925eSAdrian Chadd
132ee55925eSAdrian Chadd #include <dev/iwm/if_iwmreg.h>
133ee55925eSAdrian Chadd #include <dev/iwm/if_iwmvar.h>
134ee55925eSAdrian Chadd #include <dev/iwm/if_iwm_debug.h>
135ee55925eSAdrian Chadd #include <dev/iwm/if_iwm_util.h>
136ee55925eSAdrian Chadd #include <dev/iwm/if_iwm_led.h>
137ee55925eSAdrian Chadd
138ee55925eSAdrian Chadd /* Set led register on */
139ee55925eSAdrian Chadd void
iwm_led_enable(struct iwm_softc * sc)140*e7065dd1SMark Johnston iwm_led_enable(struct iwm_softc *sc)
141ee55925eSAdrian Chadd {
142ee55925eSAdrian Chadd IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_ON);
143ee55925eSAdrian Chadd }
144ee55925eSAdrian Chadd
145ee55925eSAdrian Chadd /* Set led register off */
146ee55925eSAdrian Chadd void
iwm_led_disable(struct iwm_softc * sc)147*e7065dd1SMark Johnston iwm_led_disable(struct iwm_softc *sc)
148ee55925eSAdrian Chadd {
149ee55925eSAdrian Chadd IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_OFF);
150ee55925eSAdrian Chadd }
151ee55925eSAdrian Chadd
1526a5bc1d1SSean Bruno static int
iwm_led_is_enabled(struct iwm_softc * sc)153*e7065dd1SMark Johnston iwm_led_is_enabled(struct iwm_softc *sc)
154ee55925eSAdrian Chadd {
155ee55925eSAdrian Chadd return (IWM_READ(sc, IWM_CSR_LED_REG) == IWM_CSR_LED_REG_TURN_ON);
156ee55925eSAdrian Chadd }
157ee55925eSAdrian Chadd
1586a5bc1d1SSean Bruno static void
iwm_led_blink_timeout(void * arg)159ee55925eSAdrian Chadd iwm_led_blink_timeout(void *arg)
160ee55925eSAdrian Chadd {
161ee55925eSAdrian Chadd struct iwm_softc *sc = arg;
162ee55925eSAdrian Chadd
163569556b6SKyle Evans if (sc->sc_attached == 0)
164569556b6SKyle Evans return;
165569556b6SKyle Evans
166*e7065dd1SMark Johnston if (iwm_led_is_enabled(sc))
167*e7065dd1SMark Johnston iwm_led_disable(sc);
168ee55925eSAdrian Chadd else
169*e7065dd1SMark Johnston iwm_led_enable(sc);
170ee55925eSAdrian Chadd
171ee55925eSAdrian Chadd callout_reset(&sc->sc_led_blink_to, (200 * hz) / 1000,
172ee55925eSAdrian Chadd iwm_led_blink_timeout, sc);
173ee55925eSAdrian Chadd }
174ee55925eSAdrian Chadd
175ee55925eSAdrian Chadd void
iwm_led_blink_start(struct iwm_softc * sc)176ee55925eSAdrian Chadd iwm_led_blink_start(struct iwm_softc *sc)
177ee55925eSAdrian Chadd {
178ee55925eSAdrian Chadd callout_reset(&sc->sc_led_blink_to, 0, iwm_led_blink_timeout, sc);
179ee55925eSAdrian Chadd }
180ee55925eSAdrian Chadd
181ee55925eSAdrian Chadd void
iwm_led_blink_stop(struct iwm_softc * sc)182ee55925eSAdrian Chadd iwm_led_blink_stop(struct iwm_softc *sc)
183ee55925eSAdrian Chadd {
1846a5bc1d1SSean Bruno callout_stop(&sc->sc_led_blink_to);
185*e7065dd1SMark Johnston iwm_led_disable(sc);
186ee55925eSAdrian Chadd }
187