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