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