1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef _wlc_pub_h_
18 #define _wlc_pub_h_
19 
20 #define	WLC_NUMRATES	16	/* max # of rates in a rateset */
21 #define	MAXMULTILIST	32	/* max # multicast addresses */
22 #define	D11_PHY_HDR_LEN	6	/* Phy header length - 6 bytes */
23 
24 /* phy types */
25 #define	PHY_TYPE_A	0	/* Phy type A */
26 #define	PHY_TYPE_G	2	/* Phy type G */
27 #define	PHY_TYPE_N	4	/* Phy type N */
28 #define	PHY_TYPE_LP	5	/* Phy type Low Power A/B/G */
29 #define	PHY_TYPE_SSN	6	/* Phy type Single Stream N */
30 #define	PHY_TYPE_LCN	8	/* Phy type Single Stream N */
31 #define	PHY_TYPE_LCNXN	9	/* Phy type 2-stream N */
32 #define	PHY_TYPE_HT	7	/* Phy type 3-Stream N */
33 
34 /* bw */
35 #define WLC_10_MHZ	10	/* 10Mhz nphy channel bandwidth */
36 #define WLC_20_MHZ	20	/* 20Mhz nphy channel bandwidth */
37 #define WLC_40_MHZ	40	/* 40Mhz nphy channel bandwidth */
38 
39 #define CHSPEC_WLC_BW(chanspec)	(CHSPEC_IS40(chanspec) ? WLC_40_MHZ : \
40 				 CHSPEC_IS20(chanspec) ? WLC_20_MHZ : \
41 							 WLC_10_MHZ)
42 
43 #define	WLC_RSSI_MINVAL		-200	/* Low value, e.g. for forcing roam */
44 #define	WLC_RSSI_NO_SIGNAL	-91	/* NDIS RSSI link quality cutoffs */
45 #define	WLC_RSSI_VERY_LOW	-80	/* Very low quality cutoffs */
46 #define	WLC_RSSI_LOW		-70	/* Low quality cutoffs */
47 #define	WLC_RSSI_GOOD		-68	/* Good quality cutoffs */
48 #define	WLC_RSSI_VERY_GOOD	-58	/* Very good quality cutoffs */
49 #define	WLC_RSSI_EXCELLENT	-57	/* Excellent quality cutoffs */
50 
51 #define WLC_PHYTYPE(_x) (_x)	/* macro to perform WLC PHY -> D11 PHY TYPE, currently 1:1 */
52 
53 #define MA_WINDOW_SZ		8	/* moving average window size */
54 
55 #define WLC_SNR_INVALID		0	/* invalid SNR value */
56 
57 /* a large TX Power as an init value to factor out of min() calculations,
58  * keep low enough to fit in an s8, units are .25 dBm
59  */
60 #define WLC_TXPWR_MAX		(127)	/* ~32 dBm = 1,500 mW */
61 
62 /* legacy rx Antenna diversity for SISO rates */
63 #define	ANT_RX_DIV_FORCE_0		0	/* Use antenna 0 */
64 #define	ANT_RX_DIV_FORCE_1		1	/* Use antenna 1 */
65 #define	ANT_RX_DIV_START_1		2	/* Choose starting with 1 */
66 #define	ANT_RX_DIV_START_0		3	/* Choose starting with 0 */
67 #define	ANT_RX_DIV_ENABLE		3	/* APHY bbConfig Enable RX Diversity */
68 #define ANT_RX_DIV_DEF		ANT_RX_DIV_START_0	/* default antdiv setting */
69 
70 /* legacy rx Antenna diversity for SISO rates */
71 #define ANT_TX_FORCE_0		0	/* Tx on antenna 0, "legacy term Main" */
72 #define ANT_TX_FORCE_1		1	/* Tx on antenna 1, "legacy term Aux" */
73 #define ANT_TX_LAST_RX		3	/* Tx on phy's last good Rx antenna */
74 #define ANT_TX_DEF			3	/* driver's default tx antenna setting */
75 
76 #define TXCORE_POLICY_ALL	0x1	/* use all available core for transmit */
77 
78 /* Tx Chain values */
79 #define TXCHAIN_DEF		0x1	/* def bitmap of txchain */
80 #define TXCHAIN_DEF_NPHY	0x3	/* default bitmap of tx chains for nphy */
81 #define TXCHAIN_DEF_HTPHY	0x7	/* default bitmap of tx chains for nphy */
82 #define RXCHAIN_DEF		0x1	/* def bitmap of rxchain */
83 #define RXCHAIN_DEF_NPHY	0x3	/* default bitmap of rx chains for nphy */
84 #define RXCHAIN_DEF_HTPHY	0x7	/* default bitmap of rx chains for nphy */
85 #define ANTSWITCH_NONE		0	/* no antenna switch */
86 #define ANTSWITCH_TYPE_1	1	/* antenna switch on 4321CB2, 2of3 */
87 #define ANTSWITCH_TYPE_2	2	/* antenna switch on 4321MPCI, 2of3 */
88 #define ANTSWITCH_TYPE_3	3	/* antenna switch on 4322, 2of3 */
89 
90 #define RXBUFSZ		PKTBUFSZ
91 #ifndef AIDMAPSZ
92 #define AIDMAPSZ	(roundup(MAXSCB, NBBY)/NBBY)	/* aid bitmap size in bytes */
93 #endif				/* AIDMAPSZ */
94 
95 typedef struct wlc_tunables {
96 	int ntxd;		/* size of tx descriptor table */
97 	int nrxd;		/* size of rx descriptor table */
98 	int rxbufsz;		/* size of rx buffers to post */
99 	int nrxbufpost;		/* # of rx buffers to post */
100 	int maxscb;		/* # of SCBs supported */
101 	int ampdunummpdu;	/* max number of mpdu in an ampdu */
102 	int maxpktcb;		/* max # of packet callbacks */
103 	int maxucodebss;	/* max # of BSS handled in ucode bcn/prb */
104 	int maxucodebss4;	/* max # of BSS handled in sw bcn/prb */
105 	int maxbss;		/* max # of bss info elements in scan list */
106 	int datahiwat;		/* data msg txq hiwat mark */
107 	int ampdudatahiwat;	/* AMPDU msg txq hiwat mark */
108 	int rxbnd;		/* max # of rx bufs to process before deferring to dpc */
109 	int txsbnd;		/* max # tx status to process in wlc_txstatus() */
110 	int memreserved;	/* memory reserved for BMAC's USB dma rx */
111 } wlc_tunables_t;
112 
113 typedef struct wlc_rateset {
114 	uint count;		/* number of rates in rates[] */
115 	u8 rates[WLC_NUMRATES];	/* rates in 500kbps units w/hi bit set if basic */
116 	u8 htphy_membership;	/* HT PHY Membership */
117 	u8 mcs[MCSSET_LEN];	/* supported mcs index bit map */
118 } wlc_rateset_t;
119 
120 struct rsn_parms {
121 	u8 flags;		/* misc booleans (e.g., supported) */
122 	u8 multicast;	/* multicast cipher */
123 	u8 ucount;		/* count of unicast ciphers */
124 	u8 unicast[4];	/* unicast ciphers */
125 	u8 acount;		/* count of auth modes */
126 	u8 auth[4];		/* Authentication modes */
127 	u8 PAD[4];		/* padding for future growth */
128 };
129 
130 /*
131  * buffer length needed for wlc_format_ssid
132  * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
133  */
134 #define SSID_FMT_BUF_LEN	((4 * IEEE80211_MAX_SSID_LEN) + 1)
135 
136 #define RSN_FLAGS_SUPPORTED		0x1	/* Flag for rsn_params */
137 #define RSN_FLAGS_PREAUTH		0x2	/* Flag for WPA2 rsn_params */
138 
139 /* All the HT-specific default advertised capabilities (including AMPDU)
140  * should be grouped here at one place
141  */
142 #define AMPDU_DEF_MPDU_DENSITY	6	/* default mpdu density (110 ==> 4us) */
143 
144 /* defaults for the HT (MIMO) bss */
145 #define HT_CAP	(IEEE80211_HT_CAP_SM_PS |\
146 	IEEE80211_HT_CAP_SUP_WIDTH_20_40 | IEEE80211_HT_CAP_GRN_FLD |\
147 	IEEE80211_HT_CAP_MAX_AMSDU | IEEE80211_HT_CAP_DSSSCCK40)
148 
149 /* wlc internal bss_info, wl external one is in wlioctl.h */
150 typedef struct wlc_bss_info {
151 	u8 BSSID[ETH_ALEN];	/* network BSSID */
152 	u16 flags;		/* flags for internal attributes */
153 	u8 SSID_len;		/* the length of SSID */
154 	u8 SSID[32];		/* SSID string */
155 	s16 RSSI;		/* receive signal strength (in dBm) */
156 	s16 SNR;		/* receive signal SNR in dB */
157 	u16 beacon_period;	/* units are Kusec */
158 	u16 atim_window;	/* units are Kusec */
159 	chanspec_t chanspec;	/* Channel num, bw, ctrl_sb and band */
160 	s8 infra;		/* 0=IBSS, 1=infrastructure, 2=unknown */
161 	wlc_rateset_t rateset;	/* supported rates */
162 	u8 dtim_period;	/* DTIM period */
163 	s8 phy_noise;		/* noise right after tx (in dBm) */
164 	u16 capability;	/* Capability information */
165 	u8 wme_qosinfo;	/* QoS Info from WME IE; valid if WLC_BSS_WME flag set */
166 	struct rsn_parms wpa;
167 	struct rsn_parms wpa2;
168 	u16 qbss_load_aac;	/* qbss load available admission capacity */
169 	/* qbss_load_chan_free <- (0xff - channel_utilization of qbss_load_ie_t) */
170 	u8 qbss_load_chan_free;	/* indicates how free the channel is */
171 	u8 mcipher;		/* multicast cipher */
172 	u8 wpacfg;		/* wpa config index */
173 } wlc_bss_info_t;
174 
175 /* forward declarations */
176 struct wlc_if;
177 
178 /* wlc_ioctl error codes */
179 #define WLC_ENOIOCTL	1	/* No such Ioctl */
180 #define WLC_EINVAL	2	/* Invalid value */
181 #define WLC_ETOOSMALL	3	/* Value too small */
182 #define WLC_ETOOBIG	4	/* Value too big */
183 #define WLC_ERANGE	5	/* Out of range */
184 #define WLC_EDOWN	6	/* Down */
185 #define WLC_EUP		7	/* Up */
186 #define WLC_ENOMEM	8	/* No Memory */
187 #define WLC_EBUSY	9	/* Busy */
188 
189 /* IOVar flags for common error checks */
190 #define IOVF_MFG	(1<<3)	/* flag for mfgtest iovars */
191 #define IOVF_WHL	(1<<4)	/* value must be whole (0-max) */
192 #define IOVF_NTRL	(1<<5)	/* value must be natural (1-max) */
193 
194 #define IOVF_SET_UP	(1<<6)	/* set requires driver be up */
195 #define IOVF_SET_DOWN	(1<<7)	/* set requires driver be down */
196 #define IOVF_SET_CLK	(1<<8)	/* set requires core clock */
197 #define IOVF_SET_BAND	(1<<9)	/* set requires fixed band */
198 
199 #define IOVF_GET_UP	(1<<10)	/* get requires driver be up */
200 #define IOVF_GET_DOWN	(1<<11)	/* get requires driver be down */
201 #define IOVF_GET_CLK	(1<<12)	/* get requires core clock */
202 #define IOVF_GET_BAND	(1<<13)	/* get requires fixed band */
203 #define IOVF_OPEN_ALLOW	(1<<14)	/* set allowed iovar for opensrc */
204 
205 /* watchdog down and dump callback function proto's */
206 typedef int (*watchdog_fn_t) (void *handle);
207 typedef int (*down_fn_t) (void *handle);
208 typedef int (*dump_fn_t) (void *handle, struct bcmstrbuf *b);
209 
210 /* IOVar handler
211  *
212  * handle - a pointer value registered with the function
213  * vi - iovar_info that was looked up
214  * actionid - action ID, calculated by IOV_GVAL() and IOV_SVAL() based on varid.
215  * name - the actual iovar name
216  * params/plen - parameters and length for a get, input only.
217  * arg/len - buffer and length for value to be set or retrieved, input or output.
218  * vsize - value size, valid for integer type only.
219  * wlcif - interface context (wlc_if pointer)
220  *
221  * All pointers may point into the same buffer.
222  */
223 typedef int (*iovar_fn_t) (void *handle, const bcm_iovar_t *vi,
224 			   u32 actionid, const char *name, void *params,
225 			   uint plen, void *arg, int alen, int vsize,
226 			   struct wlc_if *wlcif);
227 
228 #define MAC80211_PROMISC_BCNS	(1 << 0)
229 #define MAC80211_SCAN		(1 << 1)
230 
231 /*
232  * Public portion of "common" os-independent state structure.
233  * The wlc handle points at this.
234  */
235 struct wlc_pub {
236 	void *wlc;
237 
238 	struct ieee80211_hw *ieee_hw;
239 	struct scb *global_scb;
240 	scb_ampdu_t *global_ampdu;
241 	uint mac80211_state;
242 	uint unit;		/* device instance number */
243 	uint corerev;		/* core revision */
244 	si_t *sih;		/* SB handle (cookie for siutils calls) */
245 	char *vars;		/* "environment" name=value */
246 	bool up;		/* interface up and running */
247 	bool hw_off;		/* HW is off */
248 	wlc_tunables_t *tunables;	/* tunables: ntxd, nrxd, maxscb, etc. */
249 	bool hw_up;		/* one time hw up/down(from boot or hibernation) */
250 	bool _piomode;		/* true if pio mode *//* BMAC_NOTE: NEED In both */
251 	uint _nbands;		/* # bands supported */
252 	uint now;		/* # elapsed seconds */
253 
254 	bool promisc;		/* promiscuous destination address */
255 	bool delayed_down;	/* down delayed */
256 	bool _ap;		/* AP mode enabled */
257 	bool _apsta;		/* simultaneous AP/STA mode enabled */
258 	bool _assoc_recreate;	/* association recreation on up transitions */
259 	int _wme;		/* WME QoS mode */
260 	u8 _mbss;		/* MBSS mode on */
261 	bool allmulti;		/* enable all multicasts */
262 	bool associated;	/* true:part of [I]BSS, false: not */
263 	/* (union of stas_associated, aps_associated) */
264 	bool phytest_on;	/* whether a PHY test is running */
265 	bool bf_preempt_4306;	/* True to enable 'darwin' mode */
266 	bool _ampdu;		/* ampdu enabled or not */
267 	bool _cac;		/* 802.11e CAC enabled */
268 	u8 _n_enab;		/* bitmap of 11N + HT support */
269 	bool _n_reqd;		/* N support required for clients */
270 
271 	s8 _coex;		/* 20/40 MHz BSS Management AUTO, ENAB, DISABLE */
272 	bool _priofc;		/* Priority-based flowcontrol */
273 
274 	u8 cur_etheraddr[ETH_ALEN];	/* our local ethernet address */
275 
276 	u8 *multicast;	/* ptr to list of multicast addresses */
277 	uint nmulticast;	/* # enabled multicast addresses */
278 
279 	u32 wlfeatureflag;	/* Flags to control sw features from registry */
280 	int psq_pkts_total;	/* total num of ps pkts */
281 
282 	u16 txmaxpkts;	/* max number of large pkts allowed to be pending */
283 
284 	/* s/w decryption counters */
285 	u32 swdecrypt;	/* s/w decrypt attempts */
286 
287 	int bcmerror;		/* last bcm error */
288 
289 	mbool radio_disabled;	/* bit vector for radio disabled reasons */
290 	bool radio_active;	/* radio on/off state */
291 	u16 roam_time_thresh;	/* Max. # secs. of not hearing beacons
292 					 * before roaming.
293 					 */
294 	bool align_wd_tbtt;	/* Align watchdog with tbtt indication
295 				 * handling. This flag is cleared by default
296 				 * and is set by per port code explicitly and
297 				 * you need to make sure the OSL_SYSUPTIME()
298 				 * is implemented properly in osl of that port
299 				 * when it enables this Power Save feature.
300 				 */
301 
302 	u16 boardrev;	/* version # of particular board */
303 	u8 sromrev;		/* version # of the srom */
304 	char srom_ccode[WLC_CNTRY_BUF_SZ];	/* Country Code in SROM */
305 	u32 boardflags;	/* Board specific flags from srom */
306 	u32 boardflags2;	/* More board flags if sromrev >= 4 */
307 	bool tempsense_disable;	/* disable periodic tempsense check */
308 
309 	bool _lmac;		/* lmac module included and enabled */
310 	bool _lmacproto;	/* lmac protocol module included and enabled */
311 	bool phy_11ncapable;	/* the PHY/HW is capable of 802.11N */
312 	bool _ampdumac;		/* mac assist ampdu enabled or not */
313 
314 	struct wl_cnt *_cnt;	/* low-level counters in driver */
315 };
316 
317 /* wl_monitor rx status per packet */
318 typedef struct wl_rxsts {
319 	uint pkterror;		/* error flags per pkt */
320 	uint phytype;		/* 802.11 A/B/G ... */
321 	uint channel;		/* channel */
322 	uint datarate;		/* rate in 500kbps */
323 	uint antenna;		/* antenna pkts received on */
324 	uint pktlength;		/* pkt length minus bcm phy hdr */
325 	u32 mactime;		/* time stamp from mac, count per 1us */
326 	uint sq;		/* signal quality */
327 	s32 signal;		/* in dbm */
328 	s32 noise;		/* in dbm */
329 	uint preamble;		/* Unknown, short, long */
330 	uint encoding;		/* Unknown, CCK, PBCC, OFDM */
331 	uint nfrmtype;		/* special 802.11n frames(AMPDU, AMSDU) */
332 	struct wl_if *wlif;	/* wl interface */
333 } wl_rxsts_t;
334 
335 /* status per error RX pkt */
336 #define WL_RXS_CRC_ERROR		0x00000001	/* CRC Error in packet */
337 #define WL_RXS_RUNT_ERROR		0x00000002	/* Runt packet */
338 #define WL_RXS_ALIGN_ERROR		0x00000004	/* Misaligned packet */
339 #define WL_RXS_OVERSIZE_ERROR		0x00000008	/* packet bigger than RX_LENGTH (usually 1518) */
340 #define WL_RXS_WEP_ICV_ERROR		0x00000010	/* Integrity Check Value error */
341 #define WL_RXS_WEP_ENCRYPTED		0x00000020	/* Encrypted with WEP */
342 #define WL_RXS_PLCP_SHORT		0x00000040	/* Short PLCP error */
343 #define WL_RXS_DECRYPT_ERR		0x00000080	/* Decryption error */
344 #define WL_RXS_OTHER_ERR		0x80000000	/* Other errors */
345 
346 /* phy type */
347 #define WL_RXS_PHY_A			0x00000000	/* A phy type */
348 #define WL_RXS_PHY_B			0x00000001	/* B phy type */
349 #define WL_RXS_PHY_G			0x00000002	/* G phy type */
350 #define WL_RXS_PHY_N			0x00000004	/* N phy type */
351 
352 /* encoding */
353 #define WL_RXS_ENCODING_CCK		0x00000000	/* CCK encoding */
354 #define WL_RXS_ENCODING_OFDM		0x00000001	/* OFDM encoding */
355 
356 /* preamble */
357 #define WL_RXS_UNUSED_STUB		0x0	/* stub to match with wlc_ethereal.h */
358 #define WL_RXS_PREAMBLE_SHORT		0x00000001	/* Short preamble */
359 #define WL_RXS_PREAMBLE_LONG		0x00000002	/* Long preamble */
360 #define WL_RXS_PREAMBLE_MIMO_MM		0x00000003	/* MIMO mixed mode preamble */
361 #define WL_RXS_PREAMBLE_MIMO_GF		0x00000004	/* MIMO green field preamble */
362 
363 #define WL_RXS_NFRM_AMPDU_FIRST		0x00000001	/* first MPDU in A-MPDU */
364 #define WL_RXS_NFRM_AMPDU_SUB		0x00000002	/* subsequent MPDU(s) in A-MPDU */
365 #define WL_RXS_NFRM_AMSDU_FIRST		0x00000004	/* first MSDU in A-MSDU */
366 #define WL_RXS_NFRM_AMSDU_SUB		0x00000008	/* subsequent MSDU(s) in A-MSDU */
367 
368 /* forward declare and use the struct notation so we don't have to
369  * have it defined if not necessary.
370  */
371 struct wlc_info;
372 struct wlc_hw_info;
373 struct wlc_bsscfg;
374 struct wlc_if;
375 
376 /***********************************************
377  * Feature-related macros to optimize out code *
378  * *********************************************
379  */
380 
381 /* AP Support (versus STA) */
382 #define	AP_ENAB(pub)	(0)
383 
384 /* Macro to check if APSTA mode enabled */
385 #define APSTA_ENAB(pub)	(0)
386 
387 /* Some useful combinations */
388 #define STA_ONLY(pub)	(!AP_ENAB(pub))
389 #define AP_ONLY(pub)	(AP_ENAB(pub) && !APSTA_ENAB(pub))
390 
391 #define ENAB_1x1	0x01
392 #define ENAB_2x2	0x02
393 #define ENAB_3x3	0x04
394 #define ENAB_4x4	0x08
395 #define SUPPORT_11N	(ENAB_1x1|ENAB_2x2)
396 #define SUPPORT_HT	(ENAB_1x1|ENAB_2x2|ENAB_3x3)
397 /* WL11N Support */
398 #if ((defined(NCONF) && (NCONF != 0)) || (defined(LCNCONF) && (LCNCONF != 0)) || \
399 	(defined(HTCONF) && (HTCONF != 0)) || (defined(SSLPNCONF) && (SSLPNCONF != 0)))
400 #define N_ENAB(pub) ((pub)->_n_enab & SUPPORT_11N)
401 #define N_REQD(pub) ((pub)->_n_reqd)
402 #else
403 #define N_ENAB(pub)	0
404 #define N_REQD(pub)	0
405 #endif
406 
407 #if (defined(HTCONF) && (HTCONF != 0))
408 #define HT_ENAB(pub) (((pub)->_n_enab & SUPPORT_HT) == SUPPORT_HT)
409 #else
410 #define HT_ENAB(pub) 0
411 #endif
412 
413 #define AMPDU_AGG_HOST	1
414 #define AMPDU_ENAB(pub) ((pub)->_ampdu)
415 
416 #define EDCF_ENAB(pub) (WME_ENAB(pub))
417 #define QOS_ENAB(pub) (WME_ENAB(pub) || N_ENAB(pub))
418 
419 #define MONITOR_ENAB(wlc)	((wlc)->monitor)
420 
421 #define PROMISC_ENAB(wlc)	((wlc)->promisc)
422 
423 #define	WLC_PREC_COUNT		16	/* Max precedence level implemented */
424 
425 /* pri is priority encoded in the packet. This maps the Packet priority to
426  * enqueue precedence as defined in wlc_prec_map
427  */
428 extern const u8 wlc_prio2prec_map[];
429 #define WLC_PRIO_TO_PREC(pri)	wlc_prio2prec_map[(pri) & 7]
430 
431 /* This maps priority to one precedence higher - Used by PS-Poll response packets to
432  * simulate enqueue-at-head operation, but still maintain the order on the queue
433  */
434 #define WLC_PRIO_TO_HI_PREC(pri)	min(WLC_PRIO_TO_PREC(pri) + 1, WLC_PREC_COUNT - 1)
435 
436 extern const u8 wme_fifo2ac[];
437 #define WME_PRIO2AC(prio)	wme_fifo2ac[prio2fifo[(prio)]]
438 
439 /* Mask to describe all precedence levels */
440 #define WLC_PREC_BMP_ALL		MAXBITVAL(WLC_PREC_COUNT)
441 
442 /* Define a bitmap of precedences comprised by each AC */
443 #define WLC_PREC_BMP_AC_BE	(NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_BE)) |	\
444 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_BE)) |	\
445 				NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_EE)) |	\
446 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_EE)))
447 #define WLC_PREC_BMP_AC_BK	(NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_BK)) |	\
448 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_BK)) |	\
449 				NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_NONE)) |	\
450 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_NONE)))
451 #define WLC_PREC_BMP_AC_VI	(NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_CL)) |	\
452 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_CL)) |	\
453 				NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_VI)) |	\
454 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_VI)))
455 #define WLC_PREC_BMP_AC_VO	(NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_VO)) |	\
456 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_VO)) |	\
457 				NBITVAL(WLC_PRIO_TO_PREC(PRIO_8021D_NC)) |	\
458 				NBITVAL(WLC_PRIO_TO_HI_PREC(PRIO_8021D_NC)))
459 
460 /* WME Support */
461 #define WME_ENAB(pub) ((pub)->_wme != OFF)
462 #define WME_AUTO(wlc) ((wlc)->pub->_wme == AUTO)
463 
464 #define WLC_USE_COREFLAGS	0xffffffff	/* invalid core flags, use the saved coreflags */
465 
466 
467 /* network protection config */
468 #define	WLC_PROT_G_SPEC		1	/* SPEC g protection */
469 #define	WLC_PROT_G_OVR		2	/* SPEC g prot override */
470 #define	WLC_PROT_G_USER		3	/* gmode specified by user */
471 #define	WLC_PROT_OVERLAP	4	/* overlap */
472 #define	WLC_PROT_N_USER		10	/* nmode specified by user */
473 #define	WLC_PROT_N_CFG		11	/* n protection */
474 #define	WLC_PROT_N_CFG_OVR	12	/* n protection override */
475 #define	WLC_PROT_N_NONGF	13	/* non-GF protection */
476 #define	WLC_PROT_N_NONGF_OVR	14	/* non-GF protection override */
477 #define	WLC_PROT_N_PAM_OVR	15	/* n preamble override */
478 #define	WLC_PROT_N_OBSS		16	/* non-HT OBSS present */
479 
480 /* common functions for every port */
481 extern void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit,
482 			bool piomode, void *regsva, uint bustype, void *btparam,
483 			uint *perr);
484 extern uint wlc_detach(struct wlc_info *wlc);
485 extern int wlc_up(struct wlc_info *wlc);
486 extern uint wlc_down(struct wlc_info *wlc);
487 
488 extern int wlc_set(struct wlc_info *wlc, int cmd, int arg);
489 extern int wlc_get(struct wlc_info *wlc, int cmd, int *arg);
490 extern int wlc_iovar_getint(struct wlc_info *wlc, const char *name, int *arg);
491 extern int wlc_iovar_setint(struct wlc_info *wlc, const char *name, int arg);
492 extern bool wlc_chipmatch(u16 vendor, u16 device);
493 extern void wlc_init(struct wlc_info *wlc);
494 extern void wlc_reset(struct wlc_info *wlc);
495 
496 extern void wlc_intrson(struct wlc_info *wlc);
497 extern u32 wlc_intrsoff(struct wlc_info *wlc);
498 extern void wlc_intrsrestore(struct wlc_info *wlc, u32 macintmask);
499 extern bool wlc_intrsupd(struct wlc_info *wlc);
500 extern bool wlc_isr(struct wlc_info *wlc, bool *wantdpc);
501 extern bool wlc_dpc(struct wlc_info *wlc, bool bounded);
502 extern bool wlc_send80211_raw(struct wlc_info *wlc, struct wlc_if *wlcif,
503 			      void *p, uint ac);
504 extern bool wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
505 				 struct ieee80211_hw *hw);
506 extern int wlc_iovar_op(struct wlc_info *wlc, const char *name, void *params,
507 			int p_len, void *arg, int len, bool set,
508 			struct wlc_if *wlcif);
509 extern int wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
510 		     struct wlc_if *wlcif);
511 /* helper functions */
512 extern void wlc_statsupd(struct wlc_info *wlc);
513 extern void wlc_protection_upd(struct wlc_info *wlc, uint idx, int val);
514 extern int wlc_get_header_len(void);
515 extern void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc);
516 extern void wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
517 			      const u8 *addr);
518 extern void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg,
519 			      bool suspend);
520 
521 extern struct wlc_pub *wlc_pub(void *wlc);
522 
523 /* common functions for every port */
524 extern int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw);
525 extern int wlc_bmac_up_finish(struct wlc_hw_info *wlc_hw);
526 extern int wlc_bmac_down_prep(struct wlc_hw_info *wlc_hw);
527 extern int wlc_bmac_down_finish(struct wlc_hw_info *wlc_hw);
528 
529 extern u32 wlc_reg_read(struct wlc_info *wlc, void *r, uint size);
530 extern void wlc_reg_write(struct wlc_info *wlc, void *r, u32 v, uint size);
531 extern void wlc_corereset(struct wlc_info *wlc, u32 flags);
532 extern void wlc_mhf(struct wlc_info *wlc, u8 idx, u16 mask, u16 val,
533 		    int bands);
534 extern u16 wlc_mhf_get(struct wlc_info *wlc, u8 idx, int bands);
535 extern u32 wlc_delta_txfunfl(struct wlc_info *wlc, int fifo);
536 extern void wlc_rate_lookup_init(struct wlc_info *wlc, wlc_rateset_t *rateset);
537 extern void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs);
538 
539 struct ieee80211_sta;
540 extern void wlc_ampdu_flush(struct wlc_info *wlc, struct ieee80211_sta *sta,
541 			    u16 tid);
542 
543 /* wlc_phy.c helper functions */
544 extern void wlc_set_ps_ctrl(struct wlc_info *wlc);
545 extern void wlc_mctrl(struct wlc_info *wlc, u32 mask, u32 val);
546 extern void wlc_scb_ratesel_init_all(struct wlc_info *wlc);
547 
548 /* ioctl */
549 extern int wlc_iovar_gets8(struct wlc_info *wlc, const char *name,
550 			     s8 *arg);
551 extern int wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi,
552 			   void *arg,
553 			   int len, bool set);
554 
555 extern int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
556 			       const char *name, void *hdl, iovar_fn_t iovar_fn,
557 			       watchdog_fn_t watchdog_fn, down_fn_t down_fn);
558 extern int wlc_module_unregister(struct wlc_pub *pub, const char *name,
559 				 void *hdl);
560 extern void wlc_suspend_mac_and_wait(struct wlc_info *wlc);
561 extern void wlc_enable_mac(struct wlc_info *wlc);
562 extern void wlc_associate_upd(struct wlc_info *wlc, bool state);
563 extern void wlc_scan_start(struct wlc_info *wlc);
564 extern void wlc_scan_stop(struct wlc_info *wlc);
565 
wlc_iovar_getuint(struct wlc_info * wlc,const char * name,uint * arg)566 static inline int wlc_iovar_getuint(struct wlc_info *wlc, const char *name,
567 				    uint *arg)
568 {
569 	return wlc_iovar_getint(wlc, name, (int *)arg);
570 }
571 
wlc_iovar_getu8(struct wlc_info * wlc,const char * name,u8 * arg)572 static inline int wlc_iovar_getu8(struct wlc_info *wlc, const char *name,
573 				     u8 *arg)
574 {
575 	return wlc_iovar_gets8(wlc, name, (s8 *) arg);
576 }
577 
wlc_iovar_setuint(struct wlc_info * wlc,const char * name,uint arg)578 static inline int wlc_iovar_setuint(struct wlc_info *wlc, const char *name,
579 				    uint arg)
580 {
581 	return wlc_iovar_setint(wlc, name, (int)arg);
582 }
583 
584 #if defined(BCMDBG)
585 extern int wlc_iocregchk(struct wlc_info *wlc, uint band);
586 #endif
587 #if defined(BCMDBG)
588 extern int wlc_iocpichk(struct wlc_info *wlc, uint phytype);
589 #endif
590 
591 /* helper functions */
592 extern bool wlc_check_radio_disabled(struct wlc_info *wlc);
593 extern bool wlc_radio_monitor_stop(struct wlc_info *wlc);
594 
595 #if defined(BCMDBG)
596 extern int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len);
597 #endif
598 
599 #define	MAXBANDS		2	/* Maximum #of bands */
600 /* bandstate array indices */
601 #define BAND_2G_INDEX		0	/* wlc->bandstate[x] index */
602 #define BAND_5G_INDEX		1	/* wlc->bandstate[x] index */
603 
604 #define BAND_2G_NAME		"2.4G"
605 #define BAND_5G_NAME		"5G"
606 
607 /* BMAC RPC: 7 u32 params: pkttotlen, fifo, commit, fid, txpktpend, pktflag, rpc_id */
608 #define WLC_RPCTX_PARAMS		32
609 
610 #endif				/* _wlc_pub_h_ */
611