1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2007 Marvell Semiconductor, Inc. 5 * Copyright (c) 2007 Sam Leffler, Errno Consulting 6 * Copyright (c) 2008 Weongyo Jeong <weongyo@freebsd.org> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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. 19 * 20 * NO WARRANTY 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. 32 */ 33 34 #ifndef _DEV_MALOHAL_H 35 #define _DEV_MALOHAL_H 36 37 #define MALO_NUM_TX_QUEUES 1 38 #define MALO_MAX_TXWCB_QUEUES MALO_NUM_TX_QUEUES 39 40 /* size of f/w command buffer */ 41 #define MALO_CMDBUF_SIZE 0x4000 42 43 #define MALO_FW_CHECK_USECS (5 * 1000) /* 5ms */ 44 #define MALO_FW_MAX_NUM_CHECKS 200 45 46 /* 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 overridden by the driver (e.g. for 50 * a different regdomain and/or tx power setup). 51 */ 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]; 56 }; 57 58 /* 59 * Get Hardware/Firmware capabilities. 60 */ 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 */ 69 uint8_t macaddr[6]; 70 uint16_t regioncode; /* EEPROM region code */ 71 uint16_t num_antenna; /* Number of antenna used */ 72 uint32_t fw_releasenum; /* firmware release number */ 73 uint32_t wcbbase0; 74 uint32_t rxdesc_read; 75 uint32_t rxdesc_write; 76 uint32_t ul_fw_awakecookie; 77 uint32_t wcbbase[4]; 78 }; 79 80 /* 81 * Supply tx/rx dma-related settings to the firmware. 82 */ 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 */ 86 uint32_t rxdesc_read; 87 uint32_t rxdesc_write; 88 uint32_t wcbbase[4]; 89 }; 90 91 /* 92 * Get Hardware Statistics. 93 * 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). 97 * 98 * XXX low/up cases. 99 */ 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 113 in some way */ 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 */ 131 }; 132 133 /* 134 * Set Antenna Configuration (legacy operation). 135 * 136 * The RX antenna can be selected using the bitmask 137 * ant (bit 0 = antenna 1, bit 1 = antenna 2, etc.) 138 * (diversity?XXX) 139 */ 140 enum malo_hal_antenna { 141 MHA_ANTENNATYPE_RX = 1, 142 MHA_ANTENNATYPE_TX = 2, 143 }; 144 145 /* 146 * Set Radio Configuration. 147 * 148 * onoff != 0 turns radio on; otherwise off. 149 * if radio is enabled, the preamble is set too. 150 */ 151 enum malo_hal_preamble { 152 MHP_LONG_PREAMBLE = 1, 153 MHP_SHORT_PREAMBLE = 3, 154 MHP_AUTO_PREAMBLE = 5, 155 }; 156 157 struct malo_hal_channel_flags { 158 uint32_t freqband : 6, 159 #define MALO_FREQ_BAND_2DOT4GHZ 0x1 160 : 26; /* reserved */ 161 }; 162 163 struct malo_hal_channel { 164 uint32_t channel; 165 struct malo_hal_channel_flags flags; 166 }; 167 168 struct malo_hal_txrate { 169 uint8_t mcastrate; /* rate for multicast frames */ 170 uint8_t mgtrate; /* rate for management frames */ 171 struct { 172 uint8_t trycount; /* try this many times */ 173 uint8_t rate; /* use this tx rate */ 174 } rateseries[4]; /* rate series */ 175 }; 176 177 struct malo_hal { 178 device_t mh_dev; 179 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 */ 183 int mh_flags; 184 #define MHF_CALDATA 0x0001 /* cal data retrieved */ 185 #define MHF_FWHANG 0x0002 /* fw appears hung */ 186 187 char mh_mtxname[12]; 188 struct mtx mh_mtx; 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 */ 193 194 struct malo_hal_caldata mh_caldata; 195 196 int mh_debug; 197 #define MALO_HAL_DEBUG_SENDCMD 0x00000001 198 #define MALO_HAL_DEBUG_CMDDONE 0x00000002 199 #define MALO_HAL_DEBUG_IGNHANG 0X00000004 200 }; 201 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) 205 206 struct malo_hal *malo_hal_attach(device_t, uint16_t, 207 bus_space_handle_t, bus_space_tag_t, 208 bus_dma_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[IEEE80211_ADDR_LEN], 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[]); 233 234 #endif 235