xref: /dflybsd-src/sys/dev/netif/iwm/if_iwm_led.c (revision 6acbba79fd1a245dc4f49a6e542db4c015d39b8e)
122380cddSImre Vadász /*	$OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $	*/
222380cddSImre Vadász 
322380cddSImre Vadász /*
422380cddSImre Vadász  * Copyright (c) 2014 genua mbh <info@genua.de>
522380cddSImre Vadász  * Copyright (c) 2014 Fixup Software Ltd.
622380cddSImre Vadász  *
722380cddSImre Vadász  * Permission to use, copy, modify, and distribute this software for any
822380cddSImre Vadász  * purpose with or without fee is hereby granted, provided that the above
922380cddSImre Vadász  * copyright notice and this permission notice appear in all copies.
1022380cddSImre Vadász  *
1122380cddSImre Vadász  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1222380cddSImre Vadász  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1322380cddSImre Vadász  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1422380cddSImre Vadász  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1522380cddSImre Vadász  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1622380cddSImre Vadász  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1722380cddSImre Vadász  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1822380cddSImre Vadász  */
1922380cddSImre Vadász 
2022380cddSImre Vadász /*-
2122380cddSImre Vadász  * Based on BSD-licensed source modules in the Linux iwlwifi driver,
2222380cddSImre Vadász  * which were used as the reference documentation for this implementation.
2322380cddSImre Vadász  *
2422380cddSImre Vadász  * Driver version we are currently based off of is
2522380cddSImre Vadász  * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd)
2622380cddSImre Vadász  *
2722380cddSImre Vadász  ***********************************************************************
2822380cddSImre Vadász  *
2922380cddSImre Vadász  * This file is provided under a dual BSD/GPLv2 license.  When using or
3022380cddSImre Vadász  * redistributing this file, you may do so under either license.
3122380cddSImre Vadász  *
3222380cddSImre Vadász  * GPL LICENSE SUMMARY
3322380cddSImre Vadász  *
3422380cddSImre Vadász  * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
3522380cddSImre Vadász  *
3622380cddSImre Vadász  * This program is free software; you can redistribute it and/or modify
3722380cddSImre Vadász  * it under the terms of version 2 of the GNU General Public License as
3822380cddSImre Vadász  * published by the Free Software Foundation.
3922380cddSImre Vadász  *
4022380cddSImre Vadász  * This program is distributed in the hope that it will be useful, but
4122380cddSImre Vadász  * WITHOUT ANY WARRANTY; without even the implied warranty of
4222380cddSImre Vadász  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4322380cddSImre Vadász  * General Public License for more details.
4422380cddSImre Vadász  *
4522380cddSImre Vadász  * You should have received a copy of the GNU General Public License
4622380cddSImre Vadász  * along with this program; if not, write to the Free Software
4722380cddSImre Vadász  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
4822380cddSImre Vadász  * USA
4922380cddSImre Vadász  *
5022380cddSImre Vadász  * The full GNU General Public License is included in this distribution
5122380cddSImre Vadász  * in the file called COPYING.
5222380cddSImre Vadász  *
5322380cddSImre Vadász  * Contact Information:
5422380cddSImre Vadász  *  Intel Linux Wireless <ilw@linux.intel.com>
5522380cddSImre Vadász  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
5622380cddSImre Vadász  *
5722380cddSImre Vadász  *
5822380cddSImre Vadász  * BSD LICENSE
5922380cddSImre Vadász  *
6022380cddSImre Vadász  * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
6122380cddSImre Vadász  * All rights reserved.
6222380cddSImre Vadász  *
6322380cddSImre Vadász  * Redistribution and use in source and binary forms, with or without
6422380cddSImre Vadász  * modification, are permitted provided that the following conditions
6522380cddSImre Vadász  * are met:
6622380cddSImre Vadász  *
6722380cddSImre Vadász  *  * Redistributions of source code must retain the above copyright
6822380cddSImre Vadász  *    notice, this list of conditions and the following disclaimer.
6922380cddSImre Vadász  *  * Redistributions in binary form must reproduce the above copyright
7022380cddSImre Vadász  *    notice, this list of conditions and the following disclaimer in
7122380cddSImre Vadász  *    the documentation and/or other materials provided with the
7222380cddSImre Vadász  *    distribution.
7322380cddSImre Vadász  *  * Neither the name Intel Corporation nor the names of its
7422380cddSImre Vadász  *    contributors may be used to endorse or promote products derived
7522380cddSImre Vadász  *    from this software without specific prior written permission.
7622380cddSImre Vadász  *
7722380cddSImre Vadász  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7822380cddSImre Vadász  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7922380cddSImre Vadász  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8022380cddSImre Vadász  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8122380cddSImre Vadász  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8222380cddSImre Vadász  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
8322380cddSImre Vadász  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
8422380cddSImre Vadász  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8522380cddSImre Vadász  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8622380cddSImre Vadász  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
8722380cddSImre Vadász  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8822380cddSImre Vadász  */
8922380cddSImre Vadász #include <sys/param.h>
9022380cddSImre Vadász #include <sys/bus.h>
9122380cddSImre Vadász #include <sys/endian.h>
9222380cddSImre Vadász #include <sys/firmware.h>
9322380cddSImre Vadász #include <sys/kernel.h>
9422380cddSImre Vadász #include <sys/malloc.h>
9522380cddSImre Vadász #include <sys/mbuf.h>
9622380cddSImre Vadász #include <sys/rman.h>
9722380cddSImre Vadász #include <sys/sysctl.h>
9822380cddSImre Vadász #include <sys/linker.h>
9922380cddSImre Vadász 
10022380cddSImre Vadász #include <machine/endian.h>
10122380cddSImre Vadász 
10222380cddSImre Vadász #include <net/bpf.h>
10322380cddSImre Vadász 
10422380cddSImre Vadász #include <net/if.h>
10522380cddSImre Vadász #include <net/if_var.h>
10622380cddSImre Vadász #include <net/if_arp.h>
10722380cddSImre Vadász #include <net/ethernet.h>
10822380cddSImre Vadász #include <net/if_dl.h>
10922380cddSImre Vadász #include <net/if_media.h>
11022380cddSImre Vadász #include <net/if_types.h>
11122380cddSImre Vadász 
11222380cddSImre Vadász #include <netinet/in.h>
11322380cddSImre Vadász #include <netinet/in_systm.h>
11422380cddSImre Vadász #include <netinet/if_ether.h>
11522380cddSImre Vadász #include <netinet/ip.h>
11622380cddSImre Vadász 
11722380cddSImre Vadász #include <netproto/802_11/ieee80211_var.h>
11822380cddSImre Vadász #include <netproto/802_11/ieee80211_regdomain.h>
11922380cddSImre Vadász #include <netproto/802_11/ieee80211_ratectl.h>
12022380cddSImre Vadász #include <netproto/802_11/ieee80211_radiotap.h>
12122380cddSImre Vadász 
12222380cddSImre Vadász #include "if_iwmreg.h"
12322380cddSImre Vadász #include "if_iwmvar.h"
12422380cddSImre Vadász #include "if_iwm_debug.h"
12522380cddSImre Vadász #include "if_iwm_util.h"
12622380cddSImre Vadász #include "if_iwm_led.h"
12722380cddSImre Vadász 
12822380cddSImre Vadász /* Set led register on */
12922380cddSImre Vadász void
iwm_led_enable(struct iwm_softc * sc)130*6acbba79SMatthew Dillon iwm_led_enable(struct iwm_softc *sc)
13122380cddSImre Vadász {
13222380cddSImre Vadász 	IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_ON);
13322380cddSImre Vadász }
13422380cddSImre Vadász 
13522380cddSImre Vadász /* Set led register off */
13622380cddSImre Vadász void
iwm_led_disable(struct iwm_softc * sc)137*6acbba79SMatthew Dillon iwm_led_disable(struct iwm_softc *sc)
13822380cddSImre Vadász {
13922380cddSImre Vadász 	IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_OFF);
14022380cddSImre Vadász }
14122380cddSImre Vadász 
142309538b1SImre Vadász static int
iwm_led_is_enabled(struct iwm_softc * sc)143*6acbba79SMatthew Dillon iwm_led_is_enabled(struct iwm_softc *sc)
14422380cddSImre Vadász {
14522380cddSImre Vadász 	return (IWM_READ(sc, IWM_CSR_LED_REG) == IWM_CSR_LED_REG_TURN_ON);
14622380cddSImre Vadász }
14722380cddSImre Vadász 
148309538b1SImre Vadász static void
iwm_led_blink_timeout(void * arg)14922380cddSImre Vadász iwm_led_blink_timeout(void *arg)
15022380cddSImre Vadász {
15122380cddSImre Vadász 	struct iwm_softc *sc = arg;
15222380cddSImre Vadász 
153ba3b4ff9SImre Vadász 	if (sc->sc_attached == 0)
154ba3b4ff9SImre Vadász 		return;
155ba3b4ff9SImre Vadász 
156*6acbba79SMatthew Dillon 	if (iwm_led_is_enabled(sc))
157*6acbba79SMatthew Dillon 		iwm_led_disable(sc);
15822380cddSImre Vadász 	else
159*6acbba79SMatthew Dillon 		iwm_led_enable(sc);
16022380cddSImre Vadász 
16122380cddSImre Vadász 	callout_reset(&sc->sc_led_blink_to, (200 * hz) / 1000,
16222380cddSImre Vadász 	    iwm_led_blink_timeout, sc);
16322380cddSImre Vadász }
16422380cddSImre Vadász 
16522380cddSImre Vadász void
iwm_led_blink_start(struct iwm_softc * sc)16622380cddSImre Vadász iwm_led_blink_start(struct iwm_softc *sc)
16722380cddSImre Vadász {
16822380cddSImre Vadász 	callout_reset(&sc->sc_led_blink_to, 0, iwm_led_blink_timeout, sc);
16922380cddSImre Vadász }
17022380cddSImre Vadász 
17122380cddSImre Vadász void
iwm_led_blink_stop(struct iwm_softc * sc)17222380cddSImre Vadász iwm_led_blink_stop(struct iwm_softc *sc)
17322380cddSImre Vadász {
174*6acbba79SMatthew Dillon 	callout_stop(&sc->sc_led_blink_to);
175*6acbba79SMatthew Dillon 	iwm_led_disable(sc);
17622380cddSImre Vadász }
177