10SN/A/* $OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $ */ 26073SN/A 30SN/A/* 40SN/A * Copyright (c) 2014 genua mbh <info@genua.de> 50SN/A * Copyright (c) 2014 Fixup Software Ltd. 60SN/A * 72362SN/A * Permission to use, copy, modify, and distribute this software for any 80SN/A * purpose with or without fee is hereby granted, provided that the above 92362SN/A * copyright notice and this permission notice appear in all copies. 100SN/A * 110SN/A * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 120SN/A * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 130SN/A * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 140SN/A * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 150SN/A * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 160SN/A * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 170SN/A * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 180SN/A */ 190SN/A 200SN/A/*- 212362SN/A * Based on BSD-licensed source modules in the Linux iwlwifi driver, 222362SN/A * which were used as the reference documentation for this implementation. 232362SN/A * 240SN/A * Driver version we are currently based off of is 250SN/A * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd) 260SN/A * 270SN/A *********************************************************************** 280SN/A * 290SN/A * This file is provided under a dual BSD/GPLv2 license. When using or 300SN/A * redistributing this file, you may do so under either license. 310SN/A * 320SN/A * GPL LICENSE SUMMARY 330SN/A * 340SN/A * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved. 350SN/A * 360SN/A * This program is free software; you can redistribute it and/or modify 373771SN/A * it under the terms of version 2 of the GNU General Public License as 380SN/A * published by the Free Software Foundation. 390SN/A * 400SN/A * This program is distributed in the hope that it will be useful, but 410SN/A * WITHOUT ANY WARRANTY; without even the implied warranty of 420SN/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 430SN/A * General Public License for more details. 445288SN/A * 450SN/A * You should have received a copy of the GNU General Public License 460SN/A * along with this program; if not, write to the Free Software 470SN/A * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 480SN/A * USA 490SN/A * 500SN/A * The full GNU General Public License is included in this distribution 510SN/A * in the file called COPYING. 520SN/A * 530SN/A * Contact Information: 540SN/A * Intel Linux Wireless <ilw@linux.intel.com> 550SN/A * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 560SN/A * 570SN/A * 580SN/A * BSD LICENSE 590SN/A * 600SN/A * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved. 610SN/A * All rights reserved. 620SN/A * 630SN/A * Redistribution and use in source and binary forms, with or without 640SN/A * modification, are permitted provided that the following conditions 650SN/A * are met: 660SN/A * 670SN/A * * Redistributions of source code must retain the above copyright 680SN/A * notice, this list of conditions and the following disclaimer. 690SN/A * * Redistributions in binary form must reproduce the above copyright 700SN/A * notice, this list of conditions and the following disclaimer in 710SN/A * the documentation and/or other materials provided with the 720SN/A * distribution. 730SN/A * * Neither the name Intel Corporation nor the names of its 740SN/A * contributors may be used to endorse or promote products derived 753323SN/A * from this software without specific prior written permission. 760SN/A * 770SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 780SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 790SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 800SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 820SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 830SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 840SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 850SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 860SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 870SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 880SN/A */ 890SN/A#include <sys/cdefs.h> 900SN/A__FBSDID("$FreeBSD: stable/11/sys/dev/iwm/if_iwm_led.c 330455 2018-03-05 08:05:30Z eadler $"); 910SN/A 920SN/A#include "opt_wlan.h" 930SN/A#include "opt_iwm.h" 940SN/A 950SN/A#include <sys/param.h> 960SN/A#include <sys/bus.h> 970SN/A#include <sys/endian.h> 980SN/A#include <sys/firmware.h> 995288SN/A#include <sys/kernel.h> 1000SN/A#include <sys/malloc.h> 1010SN/A#include <sys/mbuf.h> 1020SN/A#include <sys/mutex.h> 1030SN/A#include <sys/module.h> 1040SN/A#include <sys/proc.h> 1050SN/A#include <sys/rman.h> 1060SN/A#include <sys/socket.h> 1070SN/A#include <sys/sockio.h> 1080SN/A#include <sys/sysctl.h> 1090SN/A#include <sys/linker.h> 1100SN/A 1113758SN/A#include <machine/endian.h> 1120SN/A#include <machine/bus.h> 1130SN/A 1140SN/A#include <net/bpf.h> 1150SN/A 1160SN/A#include <net/if.h> 1170SN/A#include <net/if_var.h> 1180SN/A#include <net/if_arp.h> 1190SN/A#include <net/ethernet.h> 1200SN/A#include <net/if_dl.h> 1210SN/A#include <net/if_media.h> 1220SN/A#include <net/if_types.h> 1230SN/A 1240SN/A#include <netinet/in.h> 1250SN/A#include <netinet/in_systm.h> 12612546Savstepan#include <netinet/if_ether.h> 1270SN/A#include <netinet/ip.h> 12812546Savstepan 1290SN/A#include <net80211/ieee80211_var.h> 1300SN/A#include <net80211/ieee80211_regdomain.h> 1310SN/A#include <net80211/ieee80211_ratectl.h> 1320SN/A#include <net80211/ieee80211_radiotap.h> 1330SN/A 1340SN/A#include <dev/iwm/if_iwmreg.h> 13512546Savstepan#include <dev/iwm/if_iwmvar.h> 1360SN/A#include <dev/iwm/if_iwm_debug.h> 1370SN/A#include <dev/iwm/if_iwm_util.h> 13812546Savstepan#include <dev/iwm/if_iwm_led.h> 1390SN/A 1400SN/A/* Set led register on */ 1410SN/Avoid 1420SN/Aiwm_mvm_led_enable(struct iwm_softc *sc) 1435288SN/A{ 1440SN/A IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_ON); 1450SN/A} 1460SN/A 1475288SN/A/* Set led register off */ 1480SN/Avoid 1490SN/Aiwm_mvm_led_disable(struct iwm_softc *sc) 1500SN/A{ 1510SN/A IWM_WRITE(sc, IWM_CSR_LED_REG, IWM_CSR_LED_REG_TURN_OFF); 1520SN/A} 1530SN/A 1540SN/Astatic int 1550SN/Aiwm_mvm_led_is_enabled(struct iwm_softc *sc) 15612546Savstepan{ 1570SN/A return (IWM_READ(sc, IWM_CSR_LED_REG) == IWM_CSR_LED_REG_TURN_ON); 15812546Savstepan} 1590SN/A 1600SN/Astatic void 1610SN/Aiwm_led_blink_timeout(void *arg) 1620SN/A{ 1630SN/A struct iwm_softc *sc = arg; 1645288SN/A 1650SN/A if (iwm_mvm_led_is_enabled(sc)) 1660SN/A iwm_mvm_led_disable(sc); 1670SN/A else 1680SN/A iwm_mvm_led_enable(sc); 1690SN/A 1700SN/A callout_reset(&sc->sc_led_blink_to, (200 * hz) / 1000, 1710SN/A iwm_led_blink_timeout, sc); 17212546Savstepan} 1730SN/A 1740SN/Avoid 1750SN/Aiwm_led_blink_start(struct iwm_softc *sc) 1760SN/A{ 1775288SN/A callout_reset(&sc->sc_led_blink_to, 0, iwm_led_blink_timeout, sc); 1780SN/A} 1790SN/A 1800SN/Avoid 1810SN/Aiwm_led_blink_stop(struct iwm_softc *sc) 1825288SN/A{ 1830SN/A callout_stop(&sc->sc_led_blink_to); 1840SN/A iwm_mvm_led_disable(sc); 1850SN/A} 1860SN/A