1286441Srpaulo/* $OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $ */ 2286441Srpaulo/* $FreeBSD: stable/11/sys/dev/iwm/if_iwm_util.h 330225 2018-03-01 06:56:34Z eadler $ */ 3286441Srpaulo 4286441Srpaulo/* 5286441Srpaulo * Copyright (c) 2014 genua mbh <info@genua.de> 6286441Srpaulo * Copyright (c) 2014 Fixup Software Ltd. 7286441Srpaulo * 8286441Srpaulo * Permission to use, copy, modify, and distribute this software for any 9286441Srpaulo * purpose with or without fee is hereby granted, provided that the above 10286441Srpaulo * copyright notice and this permission notice appear in all copies. 11286441Srpaulo * 12286441Srpaulo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13286441Srpaulo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14286441Srpaulo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15286441Srpaulo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16286441Srpaulo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17286441Srpaulo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18286441Srpaulo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19286441Srpaulo */ 20286441Srpaulo 21286441Srpaulo/*- 22286441Srpaulo * Based on BSD-licensed source modules in the Linux iwlwifi driver, 23286441Srpaulo * which were used as the reference documentation for this implementation. 24286441Srpaulo * 25286441Srpaulo * Driver version we are currently based off of is 26286441Srpaulo * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd) 27286441Srpaulo * 28286441Srpaulo *********************************************************************** 29286441Srpaulo * 30286441Srpaulo * This file is provided under a dual BSD/GPLv2 license. When using or 31286441Srpaulo * redistributing this file, you may do so under either license. 32286441Srpaulo * 33286441Srpaulo * GPL LICENSE SUMMARY 34286441Srpaulo * 35286441Srpaulo * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved. 36286441Srpaulo * 37286441Srpaulo * This program is free software; you can redistribute it and/or modify 38286441Srpaulo * it under the terms of version 2 of the GNU General Public License as 39286441Srpaulo * published by the Free Software Foundation. 40286441Srpaulo * 41286441Srpaulo * This program is distributed in the hope that it will be useful, but 42286441Srpaulo * WITHOUT ANY WARRANTY; without even the implied warranty of 43286441Srpaulo * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 44286441Srpaulo * General Public License for more details. 45286441Srpaulo * 46286441Srpaulo * You should have received a copy of the GNU General Public License 47286441Srpaulo * along with this program; if not, write to the Free Software 48286441Srpaulo * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 49286441Srpaulo * USA 50286441Srpaulo * 51286441Srpaulo * The full GNU General Public License is included in this distribution 52286441Srpaulo * in the file called COPYING. 53286441Srpaulo * 54286441Srpaulo * Contact Information: 55286441Srpaulo * Intel Linux Wireless <ilw@linux.intel.com> 56286441Srpaulo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 57286441Srpaulo * 58286441Srpaulo * 59286441Srpaulo * BSD LICENSE 60286441Srpaulo * 61286441Srpaulo * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved. 62286441Srpaulo * All rights reserved. 63286441Srpaulo * 64286441Srpaulo * Redistribution and use in source and binary forms, with or without 65286441Srpaulo * modification, are permitted provided that the following conditions 66286441Srpaulo * are met: 67286441Srpaulo * 68286441Srpaulo * * Redistributions of source code must retain the above copyright 69286441Srpaulo * notice, this list of conditions and the following disclaimer. 70286441Srpaulo * * Redistributions in binary form must reproduce the above copyright 71286441Srpaulo * notice, this list of conditions and the following disclaimer in 72286441Srpaulo * the documentation and/or other materials provided with the 73286441Srpaulo * distribution. 74286441Srpaulo * * Neither the name Intel Corporation nor the names of its 75286441Srpaulo * contributors may be used to endorse or promote products derived 76286441Srpaulo * from this software without specific prior written permission. 77286441Srpaulo * 78286441Srpaulo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 79286441Srpaulo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 80286441Srpaulo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 81286441Srpaulo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 82286441Srpaulo * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 83286441Srpaulo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 84286441Srpaulo * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 85286441Srpaulo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 86286441Srpaulo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 87286441Srpaulo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 88286441Srpaulo * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 89286441Srpaulo */ 90286441Srpaulo 91286441Srpaulo/*- 92286441Srpaulo * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr> 93286441Srpaulo * 94286441Srpaulo * Permission to use, copy, modify, and distribute this software for any 95286441Srpaulo * purpose with or without fee is hereby granted, provided that the above 96286441Srpaulo * copyright notice and this permission notice appear in all copies. 97286441Srpaulo * 98286441Srpaulo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 99286441Srpaulo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 100286441Srpaulo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 101286441Srpaulo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 102286441Srpaulo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 103286441Srpaulo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 104286441Srpaulo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 105286441Srpaulo */ 106286441Srpaulo#ifndef __IF_IWM_UTIL_H__ 107286441Srpaulo#define __IF_IWM_UTIL_H__ 108286441Srpaulo 109286441Srpauloextern int iwm_send_cmd(struct iwm_softc *sc, struct iwm_host_cmd *hcmd); 110330215Seadlerextern int iwm_mvm_send_cmd_pdu(struct iwm_softc *sc, uint32_t id, 111286441Srpaulo uint32_t flags, uint16_t len, const void *data); 112286441Srpaulo 113286441Srpauloextern int iwm_mvm_send_cmd_status(struct iwm_softc *sc, 114286441Srpaulo struct iwm_host_cmd *cmd, uint32_t *status); 115330215Seadlerextern int iwm_mvm_send_cmd_pdu_status(struct iwm_softc *sc, uint32_t id, 116286441Srpaulo uint16_t len, const void *data, uint32_t *status); 117286441Srpauloextern void iwm_free_resp(struct iwm_softc *sc, struct iwm_host_cmd *hcmd); 118286441Srpaulo 119330191Seadlerextern int iwm_dma_contig_alloc(bus_dma_tag_t tag, struct iwm_dma_info *dma, 120330191Seadler bus_size_t size, bus_size_t alignment); 121330191Seadlerextern void iwm_dma_contig_free(struct iwm_dma_info *); 122330191Seadler 123330225Seadlerextern int iwm_mvm_send_lq_cmd(struct iwm_softc *sc, struct iwm_lq_cmd *lq, 124330225Seadler boolean_t init); 125330225Seadler 126330202Seadlerextern boolean_t iwm_mvm_rx_diversity_allowed(struct iwm_softc *sc); 127330202Seadler 128330198Seadlerextern uint8_t iwm_ridx2rate(struct ieee80211_rateset *rs, int ridx); 129330210Seadlerextern int iwm_enable_txq(struct iwm_softc *sc, int sta_id, int qid, int fifo); 130330210Seadlerextern int iwm_mvm_flush_tx_path(struct iwm_softc *sc, uint32_t tfd_msk, 131330210Seadler uint32_t flags); 132330198Seadler 133330167Seadlerstatic inline uint8_t 134330167Seadleriwm_mvm_get_valid_tx_ant(struct iwm_softc *sc) 135330167Seadler{ 136330167Seadler return sc->nvm_data && sc->nvm_data->valid_tx_ant ? 137330167Seadler sc->sc_fw.valid_tx_ant & sc->nvm_data->valid_tx_ant : 138330167Seadler sc->sc_fw.valid_tx_ant; 139330167Seadler} 140303628Ssbruno 141330167Seadlerstatic inline uint8_t 142330167Seadleriwm_mvm_get_valid_rx_ant(struct iwm_softc *sc) 143330167Seadler{ 144330167Seadler return sc->nvm_data && sc->nvm_data->valid_rx_ant ? 145330167Seadler sc->sc_fw.valid_rx_ant & sc->nvm_data->valid_rx_ant : 146330167Seadler sc->sc_fw.valid_rx_ant; 147330167Seadler} 148330167Seadler 149330167Seadlerstatic inline uint32_t 150330167Seadleriwm_mvm_get_phy_config(struct iwm_softc *sc) 151330167Seadler{ 152330167Seadler uint32_t phy_config = ~(IWM_FW_PHY_CFG_TX_CHAIN | 153330167Seadler IWM_FW_PHY_CFG_RX_CHAIN); 154330167Seadler uint32_t valid_rx_ant = iwm_mvm_get_valid_rx_ant(sc); 155330167Seadler uint32_t valid_tx_ant = iwm_mvm_get_valid_tx_ant(sc); 156330167Seadler 157330167Seadler phy_config |= valid_tx_ant << IWM_FW_PHY_CFG_TX_CHAIN_POS | 158330167Seadler valid_rx_ant << IWM_FW_PHY_CFG_RX_CHAIN_POS; 159330167Seadler 160330167Seadler return sc->sc_fw.phy_config & phy_config; 161330167Seadler} 162330167Seadler 163286441Srpaulo#endif /* __IF_IWM_UTIL_H__ */ 164