xref: /freebsd/sys/dev/iwm/if_iwm_util.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1d4886179SRui Paulo /*	$OpenBSD: if_iwm.c,v 1.39 2015/03/23 00:35:19 jsg Exp $	*/
2d4886179SRui Paulo 
3d4886179SRui Paulo /*
4d4886179SRui Paulo  * Copyright (c) 2014 genua mbh <info@genua.de>
5d4886179SRui Paulo  * Copyright (c) 2014 Fixup Software Ltd.
6d4886179SRui Paulo  *
7d4886179SRui Paulo  * Permission to use, copy, modify, and distribute this software for any
8d4886179SRui Paulo  * purpose with or without fee is hereby granted, provided that the above
9d4886179SRui Paulo  * copyright notice and this permission notice appear in all copies.
10d4886179SRui Paulo  *
11d4886179SRui Paulo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12d4886179SRui Paulo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13d4886179SRui Paulo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14d4886179SRui Paulo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15d4886179SRui Paulo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16d4886179SRui Paulo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17d4886179SRui Paulo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18d4886179SRui Paulo  */
19d4886179SRui Paulo 
20d4886179SRui Paulo /*-
21d4886179SRui Paulo  * Based on BSD-licensed source modules in the Linux iwlwifi driver,
22d4886179SRui Paulo  * which were used as the reference documentation for this implementation.
23d4886179SRui Paulo  *
24d4886179SRui Paulo  * Driver version we are currently based off of is
25d4886179SRui Paulo  * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd)
26d4886179SRui Paulo  *
27d4886179SRui Paulo  ***********************************************************************
28d4886179SRui Paulo  *
29d4886179SRui Paulo  * This file is provided under a dual BSD/GPLv2 license.  When using or
30d4886179SRui Paulo  * redistributing this file, you may do so under either license.
31d4886179SRui Paulo  *
32d4886179SRui Paulo  * GPL LICENSE SUMMARY
33d4886179SRui Paulo  *
34d4886179SRui Paulo  * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
35d4886179SRui Paulo  *
36d4886179SRui Paulo  * This program is free software; you can redistribute it and/or modify
37d4886179SRui Paulo  * it under the terms of version 2 of the GNU General Public License as
38d4886179SRui Paulo  * published by the Free Software Foundation.
39d4886179SRui Paulo  *
40d4886179SRui Paulo  * This program is distributed in the hope that it will be useful, but
41d4886179SRui Paulo  * WITHOUT ANY WARRANTY; without even the implied warranty of
42d4886179SRui Paulo  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43d4886179SRui Paulo  * General Public License for more details.
44d4886179SRui Paulo  *
45d4886179SRui Paulo  * You should have received a copy of the GNU General Public License
46d4886179SRui Paulo  * along with this program; if not, write to the Free Software
47d4886179SRui Paulo  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
48d4886179SRui Paulo  * USA
49d4886179SRui Paulo  *
50d4886179SRui Paulo  * The full GNU General Public License is included in this distribution
51d4886179SRui Paulo  * in the file called COPYING.
52d4886179SRui Paulo  *
53d4886179SRui Paulo  * Contact Information:
54d4886179SRui Paulo  *  Intel Linux Wireless <ilw@linux.intel.com>
55d4886179SRui Paulo  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
56d4886179SRui Paulo  *
57d4886179SRui Paulo  *
58d4886179SRui Paulo  * BSD LICENSE
59d4886179SRui Paulo  *
60d4886179SRui Paulo  * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
61d4886179SRui Paulo  * All rights reserved.
62d4886179SRui Paulo  *
63d4886179SRui Paulo  * Redistribution and use in source and binary forms, with or without
64d4886179SRui Paulo  * modification, are permitted provided that the following conditions
65d4886179SRui Paulo  * are met:
66d4886179SRui Paulo  *
67d4886179SRui Paulo  *  * Redistributions of source code must retain the above copyright
68d4886179SRui Paulo  *    notice, this list of conditions and the following disclaimer.
69d4886179SRui Paulo  *  * Redistributions in binary form must reproduce the above copyright
70d4886179SRui Paulo  *    notice, this list of conditions and the following disclaimer in
71d4886179SRui Paulo  *    the documentation and/or other materials provided with the
72d4886179SRui Paulo  *    distribution.
73d4886179SRui Paulo  *  * Neither the name Intel Corporation nor the names of its
74d4886179SRui Paulo  *    contributors may be used to endorse or promote products derived
75d4886179SRui Paulo  *    from this software without specific prior written permission.
76d4886179SRui Paulo  *
77d4886179SRui Paulo  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
78d4886179SRui Paulo  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
79d4886179SRui Paulo  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
80d4886179SRui Paulo  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
81d4886179SRui Paulo  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
82d4886179SRui Paulo  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
83d4886179SRui Paulo  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84d4886179SRui Paulo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85d4886179SRui Paulo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86d4886179SRui Paulo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
87d4886179SRui Paulo  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88d4886179SRui Paulo  */
89d4886179SRui Paulo 
90d4886179SRui Paulo /*-
91d4886179SRui Paulo  * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr>
92d4886179SRui Paulo  *
93d4886179SRui Paulo  * Permission to use, copy, modify, and distribute this software for any
94d4886179SRui Paulo  * purpose with or without fee is hereby granted, provided that the above
95d4886179SRui Paulo  * copyright notice and this permission notice appear in all copies.
96d4886179SRui Paulo  *
97d4886179SRui Paulo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
98d4886179SRui Paulo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
99d4886179SRui Paulo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
100d4886179SRui Paulo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
101d4886179SRui Paulo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
102d4886179SRui Paulo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
103d4886179SRui Paulo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
104d4886179SRui Paulo  */
105d4886179SRui Paulo #ifndef	__IF_IWM_UTIL_H__
106d4886179SRui Paulo #define	__IF_IWM_UTIL_H__
107d4886179SRui Paulo 
108d4886179SRui Paulo extern	int iwm_send_cmd(struct iwm_softc *sc, struct iwm_host_cmd *hcmd);
109*e7065dd1SMark Johnston extern	int iwm_send_cmd_pdu(struct iwm_softc *sc, uint32_t id,
110d4886179SRui Paulo 	    uint32_t flags, uint16_t len, const void *data);
111d4886179SRui Paulo 
112*e7065dd1SMark Johnston extern	int iwm_send_cmd_status(struct iwm_softc *sc,
113d4886179SRui Paulo 	    struct iwm_host_cmd *cmd, uint32_t *status);
114*e7065dd1SMark Johnston extern	int iwm_send_cmd_pdu_status(struct iwm_softc *sc, uint32_t id,
115d4886179SRui Paulo 	uint16_t len, const void *data, uint32_t *status);
116d4886179SRui Paulo extern	void iwm_free_resp(struct iwm_softc *sc, struct iwm_host_cmd *hcmd);
117d4886179SRui Paulo 
118b28a6ab3SAdrian Chadd extern	int iwm_dma_contig_alloc(bus_dma_tag_t tag, struct iwm_dma_info *dma,
119b28a6ab3SAdrian Chadd 				 bus_size_t size, bus_size_t alignment);
120b28a6ab3SAdrian Chadd extern	void iwm_dma_contig_free(struct iwm_dma_info *);
121b28a6ab3SAdrian Chadd 
122*e7065dd1SMark Johnston extern	int iwm_send_lq_cmd(struct iwm_softc *sc, struct iwm_lq_cmd *lq,
123f55c604bSAdrian Chadd 				boolean_t init);
124f55c604bSAdrian Chadd 
125*e7065dd1SMark Johnston extern	boolean_t iwm_rx_diversity_allowed(struct iwm_softc *sc);
126c44c4d8dSAdrian Chadd 
1276c3c5259SAdrian Chadd extern	uint8_t iwm_ridx2rate(struct ieee80211_rateset *rs, int ridx);
128f48f6960SAdrian Chadd extern	int iwm_enable_txq(struct iwm_softc *sc, int sta_id, int qid, int fifo);
129*e7065dd1SMark Johnston extern	int iwm_flush_tx_path(struct iwm_softc *sc, uint32_t tfd_msk,
130f48f6960SAdrian Chadd 				  uint32_t flags);
1316c3c5259SAdrian Chadd 
1322a2476b3SAdrian Chadd static inline uint8_t
iwm_get_valid_tx_ant(struct iwm_softc * sc)133*e7065dd1SMark Johnston iwm_get_valid_tx_ant(struct iwm_softc *sc)
1342a2476b3SAdrian Chadd {
1352a2476b3SAdrian Chadd 	return sc->nvm_data && sc->nvm_data->valid_tx_ant ?
1362a2476b3SAdrian Chadd 	       sc->sc_fw.valid_tx_ant & sc->nvm_data->valid_tx_ant :
1372a2476b3SAdrian Chadd 	       sc->sc_fw.valid_tx_ant;
1382a2476b3SAdrian Chadd }
1392a2476b3SAdrian Chadd 
1402a2476b3SAdrian Chadd static inline uint8_t
iwm_get_valid_rx_ant(struct iwm_softc * sc)141*e7065dd1SMark Johnston iwm_get_valid_rx_ant(struct iwm_softc *sc)
1422a2476b3SAdrian Chadd {
1432a2476b3SAdrian Chadd 	return sc->nvm_data && sc->nvm_data->valid_rx_ant ?
1442a2476b3SAdrian Chadd 	       sc->sc_fw.valid_rx_ant & sc->nvm_data->valid_rx_ant :
1452a2476b3SAdrian Chadd 	       sc->sc_fw.valid_rx_ant;
1462a2476b3SAdrian Chadd }
1472a2476b3SAdrian Chadd 
1482a2476b3SAdrian Chadd static inline uint32_t
iwm_get_phy_config(struct iwm_softc * sc)149*e7065dd1SMark Johnston iwm_get_phy_config(struct iwm_softc *sc)
1502a2476b3SAdrian Chadd {
1512a2476b3SAdrian Chadd 	uint32_t phy_config = ~(IWM_FW_PHY_CFG_TX_CHAIN |
1522a2476b3SAdrian Chadd 				IWM_FW_PHY_CFG_RX_CHAIN);
153*e7065dd1SMark Johnston 	uint32_t valid_rx_ant = iwm_get_valid_rx_ant(sc);
154*e7065dd1SMark Johnston 	uint32_t valid_tx_ant = iwm_get_valid_tx_ant(sc);
1552a2476b3SAdrian Chadd 
1562a2476b3SAdrian Chadd 	phy_config |= valid_tx_ant << IWM_FW_PHY_CFG_TX_CHAIN_POS |
1572a2476b3SAdrian Chadd 		      valid_rx_ant << IWM_FW_PHY_CFG_RX_CHAIN_POS;
1582a2476b3SAdrian Chadd 
1592a2476b3SAdrian Chadd 	return sc->sc_fw.phy_config & phy_config;
1602a2476b3SAdrian Chadd }
1616a5bc1d1SSean Bruno 
162d4886179SRui Paulo #endif	/* __IF_IWM_UTIL_H__ */
163