xref: /freebsd/sys/dev/malo/if_malohal.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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  * $FreeBSD$
34  */
35 
36 #ifndef _DEV_MALOHAL_H
37 #define _DEV_MALOHAL_H
38 
39 #define MALO_NUM_TX_QUEUES			1
40 #define MALO_MAX_TXWCB_QUEUES			MALO_NUM_TX_QUEUES
41 
42 /* size of f/w command buffer */
43 #define	MALO_CMDBUF_SIZE			0x4000
44 
45 #define MALO_FW_CHECK_USECS			(5 * 1000)	/* 5ms */
46 #define MALO_FW_MAX_NUM_CHECKS			200
47 
48 /*
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 overridden by the driver (e.g. for
52  * a different regdomain and/or tx power setup).
53  */
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];
58 };
59 
60 /*
61  * Get Hardware/Firmware capabilities.
62  */
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 */
71 	uint8_t		macaddr[6];
72 	uint16_t	regioncode;		/* EEPROM region code */
73 	uint16_t	num_antenna;	/* Number of antenna used */
74 	uint32_t	fw_releasenum;	/* firmware release number */
75 	uint32_t	wcbbase0;
76 	uint32_t	rxdesc_read;
77 	uint32_t	rxdesc_write;
78 	uint32_t	ul_fw_awakecookie;
79 	uint32_t	wcbbase[4];
80 };
81 
82 /*
83  * Supply tx/rx dma-related settings to the firmware.
84  */
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 */
88 	uint32_t	rxdesc_read;
89 	uint32_t	rxdesc_write;
90 	uint32_t	wcbbase[4];
91 };
92 
93 /*
94  * Get Hardware Statistics.
95  *
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).
99  *
100  * XXX low/up cases.
101  */
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
115 						   in some way */
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 */
133 };
134 
135 /*
136  * Set Antenna Configuration (legacy operation).
137  *
138  * The RX antenna can be selected using the bitmask
139  * ant (bit 0 = antenna 1, bit 1 = antenna 2, etc.)
140  * (diversity?XXX)
141  */
142 enum malo_hal_antenna {
143 	MHA_ANTENNATYPE_RX	= 1,
144 	MHA_ANTENNATYPE_TX	= 2,
145 };
146 
147 /*
148  * Set Radio Configuration.
149  *
150  * onoff != 0 turns radio on; otherwise off.
151  * if radio is enabled, the preamble is set too.
152  */
153 enum malo_hal_preamble {
154 	MHP_LONG_PREAMBLE	= 1,
155 	MHP_SHORT_PREAMBLE	= 3,
156 	MHP_AUTO_PREAMBLE	= 5,
157 };
158 
159 struct malo_hal_channel_flags {
160 	uint32_t		freqband : 6,
161 #define MALO_FREQ_BAND_2DOT4GHZ	0x1
162 				: 26;		/* reserved */
163 };
164 
165 struct malo_hal_channel {
166 	uint32_t		channel;
167 	struct malo_hal_channel_flags flags;
168 };
169 
170 struct malo_hal_txrate {
171 	uint8_t			mcastrate;	/* rate for multicast frames */
172 	uint8_t			mgtrate;	/* rate for management frames */
173 	struct {
174 		uint8_t		trycount;	/* try this many times */
175 		uint8_t		rate;		/* use this tx rate */
176 	} rateseries[4];			/* rate series */
177 };
178 
179 struct malo_hal {
180 	device_t		mh_dev;
181 
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 */
185 	int			mh_flags;
186 #define	MHF_CALDATA		0x0001		/* cal data retrieved */
187 #define	MHF_FWHANG		0x0002		/* fw appears hung */
188 
189 	char			mh_mtxname[12];
190 	struct mtx		mh_mtx;
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 */
195 
196 	struct malo_hal_caldata	mh_caldata;
197 
198 	int			mh_debug;
199 #define MALO_HAL_DEBUG_SENDCMD	0x00000001
200 #define MALO_HAL_DEBUG_CMDDONE	0x00000002
201 #define MALO_HAL_DEBUG_IGNHANG	0X00000004
202 };
203 
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)
207 
208 struct malo_hal *malo_hal_attach(device_t, uint16_t,
209 	    bus_space_handle_t, bus_space_tag_t,
210 	    bus_dma_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[IEEE80211_ADDR_LEN], 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[]);
235 
236 #endif
237