1289842Ssjg/*	$OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $	*/
2246149Ssjg
3246149Ssjg/*
4246149Ssjg * Copyright (c) 2014 genua mbh <info@genua.de>
5246149Ssjg * Copyright (c) 2014 Fixup Software Ltd.
6246149Ssjg *
7246149Ssjg * Permission to use, copy, modify, and distribute this software for any
8246149Ssjg * purpose with or without fee is hereby granted, provided that the above
9246149Ssjg * copyright notice and this permission notice appear in all copies.
10246149Ssjg *
11246149Ssjg * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12246149Ssjg * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13246149Ssjg * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14246149Ssjg * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15246149Ssjg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16246149Ssjg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17246149Ssjg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18246149Ssjg */
19246149Ssjg
20246149Ssjg/*-
21246149Ssjg * Based on BSD-licensed source modules in the Linux iwlwifi driver,
22246149Ssjg * which were used as the reference documentation for this implementation.
23246149Ssjg *
24246149Ssjg * Driver version we are currently based off of is
25246149Ssjg * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd)
26246149Ssjg *
27246149Ssjg ***********************************************************************
28246149Ssjg *
29246149Ssjg * This file is provided under a dual BSD/GPLv2 license.  When using or
30246149Ssjg * redistributing this file, you may do so under either license.
31246149Ssjg *
32246149Ssjg * GPL LICENSE SUMMARY
33246149Ssjg *
34246149Ssjg * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
35246149Ssjg *
36246149Ssjg * This program is free software; you can redistribute it and/or modify
37246149Ssjg * it under the terms of version 2 of the GNU General Public License as
38246149Ssjg * published by the Free Software Foundation.
39246149Ssjg *
40246149Ssjg * This program is distributed in the hope that it will be useful, but
41246149Ssjg * WITHOUT ANY WARRANTY; without even the implied warranty of
42246149Ssjg * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43246149Ssjg * General Public License for more details.
44246149Ssjg *
45246149Ssjg * You should have received a copy of the GNU General Public License
46246149Ssjg * along with this program; if not, write to the Free Software
47246149Ssjg * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
48246149Ssjg * USA
49246149Ssjg *
50289842Ssjg * The full GNU General Public License is included in this distribution
51289842Ssjg * in the file called COPYING.
52289842Ssjg *
53289842Ssjg * Contact Information:
54246149Ssjg *  Intel Linux Wireless <ilw@linux.intel.com>
55246149Ssjg * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
56246149Ssjg *
57246149Ssjg *
58246149Ssjg * BSD LICENSE
59289842Ssjg *
60246149Ssjg * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
61289842Ssjg * All rights reserved.
62289842Ssjg *
63246149Ssjg * Redistribution and use in source and binary forms, with or without
64289842Ssjg * modification, are permitted provided that the following conditions
65289842Ssjg * 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#include <sys/cdefs.h>
90__FBSDID("$FreeBSD: releng/11.0/sys/dev/iwm/if_iwm_led.c 303628 2016-08-01 17:51:35Z sbruno $");
91
92#include <sys/param.h>
93#include <sys/bus.h>
94#include <sys/endian.h>
95#include <sys/firmware.h>
96#include <sys/kernel.h>
97#include <sys/malloc.h>
98#include <sys/mbuf.h>
99#include <sys/mutex.h>
100#include <sys/module.h>
101#include <sys/proc.h>
102#include <sys/rman.h>
103#include <sys/socket.h>
104#include <sys/sockio.h>
105#include <sys/sysctl.h>
106#include <sys/linker.h>
107
108#include <machine/endian.h>
109#include <machine/bus.h>
110
111#include <net/bpf.h>
112
113#include <net/if.h>
114#include <net/if_var.h>
115#include <net/if_arp.h>
116#include <net/ethernet.h>
117#include <net/if_dl.h>
118#include <net/if_media.h>
119#include <net/if_types.h>
120
121#include <netinet/in.h>
122#include <netinet/in_systm.h>
123#include <netinet/if_ether.h>
124#include <netinet/ip.h>
125
126#include <net80211/ieee80211_var.h>
127#include <net80211/ieee80211_regdomain.h>
128#include <net80211/ieee80211_ratectl.h>
129#include <net80211/ieee80211_radiotap.h>
130
131#include <dev/iwm/if_iwmreg.h>
132#include <dev/iwm/if_iwmvar.h>
133#include <dev/iwm/if_iwm_debug.h>
134#include <dev/iwm/if_iwm_util.h>
135#include <dev/iwm/if_iwm_led.h>
136
137/* Set led register on */
138void
139iwm_mvm_led_enable(struct iwm_softc *sc)
140{
141	IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_ON);
142}
143
144/* Set led register off */
145void
146iwm_mvm_led_disable(struct iwm_softc *sc)
147{
148	IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_OFF);
149}
150
151static int
152iwm_mvm_led_is_enabled(struct iwm_softc *sc)
153{
154	return (IWM_READ(sc, IWM_CSR_LED_REG) == IWM_CSR_LED_REG_TURN_ON);
155}
156
157static void
158iwm_led_blink_timeout(void *arg)
159{
160	struct iwm_softc *sc = arg;
161
162	if (iwm_mvm_led_is_enabled(sc))
163		iwm_mvm_led_disable(sc);
164	else
165		iwm_mvm_led_enable(sc);
166
167	callout_reset(&sc->sc_led_blink_to, (200 * hz) / 1000,
168	    iwm_led_blink_timeout, sc);
169}
170
171void
172iwm_led_blink_start(struct iwm_softc *sc)
173{
174	callout_reset(&sc->sc_led_blink_to, 0, iwm_led_blink_timeout, sc);
175}
176
177void
178iwm_led_blink_stop(struct iwm_softc *sc)
179{
180	callout_stop(&sc->sc_led_blink_to);
181	iwm_mvm_led_disable(sc);
182}
183