124a8d46aSMatthew Dillon /* $OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $ */ 224a8d46aSMatthew Dillon /* $FreeBSD$ */ 324a8d46aSMatthew Dillon 424a8d46aSMatthew Dillon /* 524a8d46aSMatthew Dillon * Copyright (c) 2014 genua mbh <info@genua.de> 624a8d46aSMatthew Dillon * Copyright (c) 2014 Fixup Software Ltd. 724a8d46aSMatthew Dillon * 824a8d46aSMatthew Dillon * Permission to use, copy, modify, and distribute this software for any 924a8d46aSMatthew Dillon * purpose with or without fee is hereby granted, provided that the above 1024a8d46aSMatthew Dillon * copyright notice and this permission notice appear in all copies. 1124a8d46aSMatthew Dillon * 1224a8d46aSMatthew Dillon * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1324a8d46aSMatthew Dillon * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1424a8d46aSMatthew Dillon * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1524a8d46aSMatthew Dillon * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1624a8d46aSMatthew Dillon * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1724a8d46aSMatthew Dillon * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1824a8d46aSMatthew Dillon * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1924a8d46aSMatthew Dillon */ 2024a8d46aSMatthew Dillon 2124a8d46aSMatthew Dillon /*- 2224a8d46aSMatthew Dillon * Based on BSD-licensed source modules in the Linux iwlwifi driver, 2324a8d46aSMatthew Dillon * which were used as the reference documentation for this implementation. 2424a8d46aSMatthew Dillon * 2524a8d46aSMatthew Dillon * Driver version we are currently based off of is 2624a8d46aSMatthew Dillon * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd) 2724a8d46aSMatthew Dillon * 2824a8d46aSMatthew Dillon *********************************************************************** 2924a8d46aSMatthew Dillon * 3024a8d46aSMatthew Dillon * This file is provided under a dual BSD/GPLv2 license. When using or 3124a8d46aSMatthew Dillon * redistributing this file, you may do so under either license. 3224a8d46aSMatthew Dillon * 3324a8d46aSMatthew Dillon * GPL LICENSE SUMMARY 3424a8d46aSMatthew Dillon * 3524a8d46aSMatthew Dillon * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved. 3624a8d46aSMatthew Dillon * 3724a8d46aSMatthew Dillon * This program is free software; you can redistribute it and/or modify 3824a8d46aSMatthew Dillon * it under the terms of version 2 of the GNU General Public License as 3924a8d46aSMatthew Dillon * published by the Free Software Foundation. 4024a8d46aSMatthew Dillon * 4124a8d46aSMatthew Dillon * This program is distributed in the hope that it will be useful, but 4224a8d46aSMatthew Dillon * WITHOUT ANY WARRANTY; without even the implied warranty of 4324a8d46aSMatthew Dillon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 4424a8d46aSMatthew Dillon * General Public License for more details. 4524a8d46aSMatthew Dillon * 4624a8d46aSMatthew Dillon * You should have received a copy of the GNU General Public License 4724a8d46aSMatthew Dillon * along with this program; if not, write to the Free Software 4824a8d46aSMatthew Dillon * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 4924a8d46aSMatthew Dillon * USA 5024a8d46aSMatthew Dillon * 5124a8d46aSMatthew Dillon * The full GNU General Public License is included in this distribution 5224a8d46aSMatthew Dillon * in the file called COPYING. 5324a8d46aSMatthew Dillon * 5424a8d46aSMatthew Dillon * Contact Information: 5524a8d46aSMatthew Dillon * Intel Linux Wireless <ilw@linux.intel.com> 5624a8d46aSMatthew Dillon * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 5724a8d46aSMatthew Dillon * 5824a8d46aSMatthew Dillon * 5924a8d46aSMatthew Dillon * BSD LICENSE 6024a8d46aSMatthew Dillon * 6124a8d46aSMatthew Dillon * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved. 6224a8d46aSMatthew Dillon * All rights reserved. 6324a8d46aSMatthew Dillon * 6424a8d46aSMatthew Dillon * Redistribution and use in source and binary forms, with or without 6524a8d46aSMatthew Dillon * modification, are permitted provided that the following conditions 6624a8d46aSMatthew Dillon * are met: 6724a8d46aSMatthew Dillon * 6824a8d46aSMatthew Dillon * * Redistributions of source code must retain the above copyright 6924a8d46aSMatthew Dillon * notice, this list of conditions and the following disclaimer. 7024a8d46aSMatthew Dillon * * Redistributions in binary form must reproduce the above copyright 7124a8d46aSMatthew Dillon * notice, this list of conditions and the following disclaimer in 7224a8d46aSMatthew Dillon * the documentation and/or other materials provided with the 7324a8d46aSMatthew Dillon * distribution. 7424a8d46aSMatthew Dillon * * Neither the name Intel Corporation nor the names of its 7524a8d46aSMatthew Dillon * contributors may be used to endorse or promote products derived 7624a8d46aSMatthew Dillon * from this software without specific prior written permission. 7724a8d46aSMatthew Dillon * 7824a8d46aSMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7924a8d46aSMatthew Dillon * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8024a8d46aSMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8124a8d46aSMatthew Dillon * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 8224a8d46aSMatthew Dillon * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 8324a8d46aSMatthew Dillon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 8424a8d46aSMatthew Dillon * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 8524a8d46aSMatthew Dillon * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 8624a8d46aSMatthew Dillon * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 8724a8d46aSMatthew Dillon * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 8824a8d46aSMatthew Dillon * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 8924a8d46aSMatthew Dillon */ 9024a8d46aSMatthew Dillon 9124a8d46aSMatthew Dillon /*- 9224a8d46aSMatthew Dillon * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr> 9324a8d46aSMatthew Dillon * 9424a8d46aSMatthew Dillon * Permission to use, copy, modify, and distribute this software for any 9524a8d46aSMatthew Dillon * purpose with or without fee is hereby granted, provided that the above 9624a8d46aSMatthew Dillon * copyright notice and this permission notice appear in all copies. 9724a8d46aSMatthew Dillon * 9824a8d46aSMatthew Dillon * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9924a8d46aSMatthew Dillon * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10024a8d46aSMatthew Dillon * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10124a8d46aSMatthew Dillon * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 10224a8d46aSMatthew Dillon * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 10324a8d46aSMatthew Dillon * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 10424a8d46aSMatthew Dillon * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 10524a8d46aSMatthew Dillon */ 10624a8d46aSMatthew Dillon #ifndef __IF_IWM_UTIL_H__ 10724a8d46aSMatthew Dillon #define __IF_IWM_UTIL_H__ 10824a8d46aSMatthew Dillon 10924a8d46aSMatthew Dillon extern int iwm_send_cmd(struct iwm_softc *sc, struct iwm_host_cmd *hcmd); 11024a8d46aSMatthew Dillon extern int iwm_mvm_send_cmd_pdu(struct iwm_softc *sc, uint8_t id, 11124a8d46aSMatthew Dillon uint32_t flags, uint16_t len, const void *data); 11224a8d46aSMatthew Dillon 11324a8d46aSMatthew Dillon extern int iwm_mvm_send_cmd_status(struct iwm_softc *sc, 11424a8d46aSMatthew Dillon struct iwm_host_cmd *cmd, uint32_t *status); 11524a8d46aSMatthew Dillon extern int iwm_mvm_send_cmd_pdu_status(struct iwm_softc *sc, uint8_t id, 11624a8d46aSMatthew Dillon uint16_t len, const void *data, uint32_t *status); 11724a8d46aSMatthew Dillon extern void iwm_free_resp(struct iwm_softc *sc, struct iwm_host_cmd *hcmd); 11824a8d46aSMatthew Dillon 11983a1185eSImre Vadász extern int iwm_dma_contig_alloc(bus_dma_tag_t tag, struct iwm_dma_info *dma, 12083a1185eSImre Vadász bus_size_t size, bus_size_t alignment); 12183a1185eSImre Vadász extern void iwm_dma_contig_free(struct iwm_dma_info *); 12283a1185eSImre Vadász 123*3b7fc5aaSImre Vadász extern boolean_t iwm_mvm_rx_diversity_allowed(struct iwm_softc *sc); 124*3b7fc5aaSImre Vadász 125ab1d3efcSImre Vadász extern uint8_t iwm_ridx2rate(struct ieee80211_rateset *rs, int ridx); 126ab1d3efcSImre Vadász 127cbb82693SImre Vadász static inline uint8_t 128cbb82693SImre Vadász iwm_mvm_get_valid_tx_ant(struct iwm_softc *sc) 129cbb82693SImre Vadász { 130cbb82693SImre Vadász return sc->nvm_data && sc->nvm_data->valid_tx_ant ? 131cbb82693SImre Vadász sc->sc_fw.valid_tx_ant & sc->nvm_data->valid_tx_ant : 132cbb82693SImre Vadász sc->sc_fw.valid_tx_ant; 133cbb82693SImre Vadász } 134cbb82693SImre Vadász 135cbb82693SImre Vadász static inline uint8_t 136cbb82693SImre Vadász iwm_mvm_get_valid_rx_ant(struct iwm_softc *sc) 137cbb82693SImre Vadász { 138cbb82693SImre Vadász return sc->nvm_data && sc->nvm_data->valid_rx_ant ? 139cbb82693SImre Vadász sc->sc_fw.valid_rx_ant & sc->nvm_data->valid_rx_ant : 140cbb82693SImre Vadász sc->sc_fw.valid_rx_ant; 141cbb82693SImre Vadász } 142cbb82693SImre Vadász 143cbb82693SImre Vadász static inline uint32_t 144cbb82693SImre Vadász iwm_mvm_get_phy_config(struct iwm_softc *sc) 145cbb82693SImre Vadász { 146cbb82693SImre Vadász uint32_t phy_config = ~(IWM_FW_PHY_CFG_TX_CHAIN | 147cbb82693SImre Vadász IWM_FW_PHY_CFG_RX_CHAIN); 148cbb82693SImre Vadász uint32_t valid_rx_ant = iwm_mvm_get_valid_rx_ant(sc); 149cbb82693SImre Vadász uint32_t valid_tx_ant = iwm_mvm_get_valid_tx_ant(sc); 150cbb82693SImre Vadász 151cbb82693SImre Vadász phy_config |= valid_tx_ant << IWM_FW_PHY_CFG_TX_CHAIN_POS | 152cbb82693SImre Vadász valid_rx_ant << IWM_FW_PHY_CFG_RX_CHAIN_POS; 153cbb82693SImre Vadász 154cbb82693SImre Vadász return sc->sc_fw.phy_config & phy_config; 155cbb82693SImre Vadász } 156edfc8a07SImre Vadász 15724a8d46aSMatthew Dillon #endif /* __IF_IWM_UTIL_H__ */ 158