2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2007 Marvell Semiconductor, Inc.
5 * Copyright (c) 2007 Sam Leffler, Errno Consulting
6 * Copyright (c) 2008 Weongyo Jeong <weongyo@freebsd.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17 * redistribution must be conditioned upon including a substantially
18 * similar Disclaimer requirement for further binary redistribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
26 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGES.
36 #ifndef _DEV_MALOHAL_H
37 #define _DEV_MALOHAL_H
39 #define MALO_NUM_TX_QUEUES 1
40 #define MALO_MAX_TXWCB_QUEUES MALO_NUM_TX_QUEUES
42 /* size of f/w command buffer */
43 #define MALO_CMDBUF_SIZE 0x4000
45 #define MALO_FW_CHECK_USECS (5 * 1000) /* 5ms */
46 #define MALO_FW_MAX_NUM_CHECKS 200
49 * Calibration data builtin to the firmware. The firmware image
50 * has a single set of calibration tables that we retrieve right
51 * after download. This can be overriden by the driver (e.g. for
52 * a different regdomain and/or tx power setup).
54 struct malo_hal_caldata {
55 /* pt is short for `power target'. */
56 #define MALO_PWTAGETRATETABLE20M (14 * 4)
57 uint8_t pt_ratetable_20m[MALO_PWTAGETRATETABLE20M];
61 * Get Hardware/Firmware capabilities.
63 struct malo_hal_hwspec {
64 uint8_t hwversion; /* version of the HW */
65 uint8_t hostinterface; /* host interface */
66 uint16_t maxnum_wcb; /* max # of WCB FW handles */
67 /* max # of mcast addresses FW handles*/
68 uint16_t maxnum_mcaddr;
69 uint16_t maxnum_tx_wcb; /* max # of tx descs per WCB */
70 /* MAC address programmed in HW */
72 uint16_t regioncode; /* EEPROM region code */
73 uint16_t num_antenna; /* Number of antenna used */
74 uint32_t fw_releasenum; /* firmware release number */
77 uint32_t rxdesc_write;
78 uint32_t ul_fw_awakecookie;
83 * Supply tx/rx dma-related settings to the firmware.
85 struct malo_hal_txrxdma {
86 uint32_t maxnum_wcb; /* max # of WCB FW handles */
87 uint32_t maxnum_txwcb; /* max # of tx descs per WCB */
89 uint32_t rxdesc_write;
94 * Get Hardware Statistics.
96 * Items marked with ! are deprecated and not ever updated. In
97 * some cases this is because work has been moved to the host (e.g.
98 * rx defragmentation).
102 struct malo_hal_hwstats {
103 uint32_t TxRetrySuccesses; /* tx success w/ 1 retry */
104 uint32_t TxMultipleRetrySuccesses;/* tx success w/ >1 retry */
105 uint32_t TxFailures; /* tx fail due to no ACK */
106 uint32_t RTSSuccesses; /* CTS rx'd for RTS */
107 uint32_t RTSFailures; /* CTS not rx'd for RTS */
108 uint32_t AckFailures; /* same as TxFailures */
109 uint32_t RxDuplicateFrames; /* rx discard for dup seqno */
110 uint32_t FCSErrorCount; /* rx discard for bad FCS */
111 uint32_t TxWatchDogTimeouts; /* MAC tx hang (f/w recovery) */
112 uint32_t RxOverflows; /* no f/w buffer for rx data */
113 uint32_t RxFragErrors; /* !rx fail due to defrag */
114 uint32_t RxMemErrors; /* out of mem or desc corrupted
116 uint32_t RxPointerErrors; /* MAC internal ptr problem */
117 uint32_t TxUnderflows; /* !tx underflow on dma */
118 uint32_t TxDone; /* MAC tx ops completed
119 (possibly w/ error) */
120 uint32_t TxDoneBufTryPut; /* ! */
121 uint32_t TxDoneBufPut; /* same as TxDone */
122 uint32_t Wait4TxBuf; /* !no f/w buf avail when
123 supplied a tx descriptor */
124 uint32_t TxAttempts; /* tx descriptors processed */
125 uint32_t TxSuccesses; /* tx attempts successful */
126 uint32_t TxFragments; /* tx with fragmentation */
127 uint32_t TxMulticasts; /* tx multicast frames */
128 uint32_t RxNonCtlPkts; /* rx non-control frames */
129 uint32_t RxMulticasts; /* rx multicast frames */
130 uint32_t RxUndecryptableFrames; /* rx failed due to crypto */
131 uint32_t RxICVErrors; /* rx failed due to ICV check */
132 uint32_t RxExcludedFrames; /* rx discarded, e.g. bssid */
136 * Set Antenna Configuration (legacy operation).
138 * The RX antenna can be selected using the bitmask
139 * ant (bit 0 = antenna 1, bit 1 = antenna 2, etc.)
142 enum malo_hal_antenna {
143 MHA_ANTENNATYPE_RX = 1,
144 MHA_ANTENNATYPE_TX = 2,
148 * Set Radio Configuration.
150 * onoff != 0 turns radio on; otherwise off.
151 * if radio is enabled, the preamble is set too.
153 enum malo_hal_preamble {
154 MHP_LONG_PREAMBLE = 1,
155 MHP_SHORT_PREAMBLE = 3,
156 MHP_AUTO_PREAMBLE = 5,
159 struct malo_hal_channel_flags {
160 uint32_t freqband : 6,
161 #define MALO_FREQ_BAND_2DOT4GHZ 0x1
165 struct malo_hal_channel {
167 struct malo_hal_channel_flags flags;
170 struct malo_hal_txrate {
171 uint8_t mcastrate; /* rate for multicast frames */
172 uint8_t mgtrate; /* rate for management frames */
174 uint8_t trycount; /* try this many times */
175 uint8_t rate; /* use this tx rate */
176 } rateseries[4]; /* rate series */
182 bus_space_handle_t mh_ioh; /* BAR 1 copied from softc */
183 bus_space_tag_t mh_iot;
184 uint32_t mh_imask; /* interrupt mask */
186 #define MHF_CALDATA 0x0001 /* cal data retrieved */
187 #define MHF_FWHANG 0x0002 /* fw appears hung */
191 bus_dma_tag_t mh_dmat; /* bus DMA tag for cmd buffer */
192 bus_dmamap_t mh_dmamap; /* DMA map for cmd buffer */
193 uint16_t *mh_cmdbuf; /* f/w cmd buffer */
194 bus_addr_t mh_cmdaddr; /* physaddr of cmd buffer */
196 struct malo_hal_caldata mh_caldata;
199 #define MALO_HAL_DEBUG_SENDCMD 0x00000001
200 #define MALO_HAL_DEBUG_CMDDONE 0x00000002
201 #define MALO_HAL_DEBUG_IGNHANG 0X00000004
204 #define MALO_HAL_LOCK(mh) mtx_lock(&mh->mh_mtx)
205 #define MALO_HAL_LOCK_ASSERT(mh) mtx_assert(&mh->mh_mtx, MA_OWNED)
206 #define MALO_HAL_UNLOCK(mh) mtx_unlock(&mh->mh_mtx)
208 struct malo_hal *malo_hal_attach(device_t, uint16_t,
209 bus_space_handle_t, bus_space_tag_t,
211 int malo_hal_fwload(struct malo_hal *, char *, char *);
212 int malo_hal_gethwspecs(struct malo_hal *,
213 struct malo_hal_hwspec *);
214 void malo_hal_detach(struct malo_hal *);
215 void malo_hal_intrset(struct malo_hal *, uint32_t);
216 int malo_hal_setantenna(struct malo_hal *,
217 enum malo_hal_antenna, int);
218 int malo_hal_setradio(struct malo_hal *, int,
219 enum malo_hal_preamble);
220 int malo_hal_setchannel(struct malo_hal *,
221 const struct malo_hal_channel *);
222 int malo_hal_setmaxtxpwr(struct malo_hal *, uint16_t);
223 int malo_hal_settxpower(struct malo_hal *, const struct malo_hal_channel *);
224 int malo_hal_setpromisc(struct malo_hal *, int);
225 int malo_hal_setassocid(struct malo_hal *,
226 const uint8_t[], uint16_t);
227 void malo_hal_txstart(struct malo_hal *, int);
228 void malo_hal_getisr(struct malo_hal *, uint32_t *);
229 void malo_hal_cmddone(struct malo_hal *);
230 int malo_hal_prescan(struct malo_hal *);
231 int malo_hal_postscan(struct malo_hal *, uint8_t *, uint8_t);
232 int malo_hal_set_slot(struct malo_hal *, int);
233 int malo_hal_set_rate(struct malo_hal *, uint16_t, uint8_t);
234 int malo_hal_setmcast(struct malo_hal *, int, const uint8_t[]);