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