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