1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 #ifndef _DEV_IC_ATWVAR_H_
40 #define _DEV_IC_ATWVAR_H_
41
42 #include <sys/queue.h>
43 #include <sys/time.h>
44 #include <sys/timeout.h>
45
46
47
48
49 struct atw_stats {
50 u_long ts_tx_tuf;
51 u_long ts_tx_tro;
52 u_long ts_tx_trt;
53 u_long ts_tx_tlt;
54 u_long ts_tx_sofbr;
55 };
56
57
58
59
60
61
62
63 #define ATW_NTXSEGS 16
64
65 #define ATW_TXQUEUELEN 64
66 #define ATW_NTXDESC (ATW_TXQUEUELEN * ATW_NTXSEGS)
67 #define ATW_NTXDESC_MASK (ATW_NTXDESC - 1)
68 #define ATW_NEXTTX(x) ((x + 1) & ATW_NTXDESC_MASK)
69
70
71
72
73
74 #define ATW_NRXDESC 64
75 #define ATW_NRXDESC_MASK (ATW_NRXDESC - 1)
76 #define ATW_NEXTRX(x) ((x + 1) & ATW_NRXDESC_MASK)
77
78
79
80
81
82
83 struct atw_control_data {
84
85
86
87 struct atw_txdesc acd_txdescs[ATW_NTXDESC];
88
89
90
91
92 struct atw_rxdesc acd_rxdescs[ATW_NRXDESC];
93 };
94
95 #define ATW_CDOFF(x) offsetof(struct atw_control_data, x)
96 #define ATW_CDTXOFF(x) ATW_CDOFF(acd_txdescs[(x)])
97 #define ATW_CDRXOFF(x) ATW_CDOFF(acd_rxdescs[(x)])
98
99 struct atw_duration {
100 uint16_t d_rts_dur;
101 uint16_t d_data_dur;
102 uint16_t d_plcp_len;
103 uint8_t d_residue;
104 };
105
106
107
108
109 struct atw_txsoft {
110 struct mbuf *txs_mbuf;
111 bus_dmamap_t txs_dmamap;
112 int txs_firstdesc;
113 int txs_lastdesc;
114 int txs_ndescs;
115 struct atw_duration txs_d0;
116 struct atw_duration txs_dn;
117 SIMPLEQ_ENTRY(atw_txsoft) txs_q;
118 };
119
120 SIMPLEQ_HEAD(atw_txsq, atw_txsoft);
121
122
123
124
125 struct atw_rxsoft {
126 struct mbuf *rxs_mbuf;
127 bus_dmamap_t rxs_dmamap;
128 };
129
130
131
132
133
134
135 struct atw_txthresh_tab {
136 u_int32_t txth_opmode;
137 const char *txth_name;
138 };
139
140 #define ATW_TXTHRESH_TAB_LO_RATE { \
141 { ATW_NAR_TR_L64, "64 bytes" }, \
142 { ATW_NAR_TR_L160, "160 bytes" }, \
143 { ATW_NAR_TR_L192, "192 bytes" }, \
144 { ATW_NAR_SF, "store and forward" }, \
145 { 0, NULL }, \
146 }
147
148 #define ATW_TXTHRESH_TAB_HI_RATE { \
149 { ATW_NAR_TR_H96, "96 bytes" }, \
150 { ATW_NAR_TR_H288, "288 bytes" }, \
151 { ATW_NAR_TR_H544, "544 bytes" }, \
152 { ATW_NAR_SF, "store and forward" }, \
153 { 0, NULL }, \
154 }
155
156 enum atw_rftype { ATW_RFTYPE_INTERSIL = 0, ATW_RFTYPE_RFMD = 1,
157 ATW_RFTYPE_MARVEL = 2 };
158
159 enum atw_bbptype { ATW_BBPTYPE_INTERSIL = 0, ATW_BBPTYPE_RFMD = 1,
160 ATW_BBPTYPE_MARVEL = 2, ATW_C_BBPTYPE_RFMD = 5 };
161
162
163
164 #define ATW_RX_RADIOTAP_PRESENT \
165 ((1 << IEEE80211_RADIOTAP_FLAGS) | (1 << IEEE80211_RADIOTAP_RATE) | \
166 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
167 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
168
169 struct atw_rx_radiotap_header {
170 struct ieee80211_radiotap_header ar_ihdr;
171 u_int8_t ar_flags;
172 u_int8_t ar_rate;
173 u_int16_t ar_chan_freq;
174 u_int16_t ar_chan_flags;
175 u_int8_t ar_antsignal;
176 } __packed;
177
178 #define ATW_TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_FLAGS) | \
179 (1 << IEEE80211_RADIOTAP_RATE) | \
180 (1 << IEEE80211_RADIOTAP_CHANNEL))
181
182 struct atw_tx_radiotap_header {
183 struct ieee80211_radiotap_header at_ihdr;
184 u_int8_t at_flags;
185 u_int8_t at_rate;
186 u_int16_t at_chan_freq;
187 u_int16_t at_chan_flags;
188 } __packed;
189
190 enum atw_revision {
191 ATW_REVISION_AB = 0x11,
192 ATW_REVISION_AF = 0x15,
193 ATW_REVISION_BA = 0x20,
194 ATW_REVISION_CA = 0x30
195 };
196
197 struct atw_softc {
198 struct device sc_dev;
199 struct ieee80211com sc_ic;
200 int (*sc_enable)(struct atw_softc *);
201 void (*sc_disable)(struct atw_softc *);
202 void (*sc_power)(struct atw_softc *, int);
203 int (*sc_newstate)(struct ieee80211com *,
204 enum ieee80211_state, int);
205 void (*sc_recv_mgmt)(struct ieee80211com *,
206 struct mbuf *, struct ieee80211_node *,
207 int, int, u_int32_t);
208 struct ieee80211_node *(*sc_node_alloc)(struct ieee80211com *);
209 void (*sc_node_free)(struct ieee80211com *,
210 struct ieee80211_node *);
211
212 struct atw_stats sc_stats;
213
214 int sc_tx_timer;
215 int sc_rescan_timer;
216
217 bus_space_tag_t sc_st;
218 bus_space_handle_t sc_sh;
219 bus_dma_tag_t sc_dmat;
220 void *sc_sdhook;
221 void *sc_powerhook;
222 u_int32_t sc_cacheline;
223 u_int32_t sc_maxburst;
224
225 const struct atw_txthresh_tab *sc_txth;
226 int sc_txthresh;
227
228 u_int sc_cur_chan;
229
230 int sc_flags;
231
232 u_int16_t *sc_srom;
233 u_int16_t sc_sromsz;
234
235 caddr_t sc_radiobpf;
236
237 bus_dma_segment_t sc_cdseg;
238 int sc_cdnseg;
239 bus_dmamap_t sc_cddmamap;
240 #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
241
242
243
244
245 struct atw_txsoft sc_txsoft[ATW_TXQUEUELEN];
246 struct atw_rxsoft sc_rxsoft[ATW_NRXDESC];
247
248
249
250
251 struct atw_control_data *sc_control_data;
252 #define sc_txdescs sc_control_data->acd_txdescs
253 #define sc_rxdescs sc_control_data->acd_rxdescs
254 #define sc_setup_desc sc_control_data->acd_setup_desc
255
256 int sc_txfree;
257 int sc_txnext;
258 int sc_ntxsegs;
259
260 struct atw_txsq sc_txfreeq;
261 struct atw_txsq sc_txdirtyq;
262
263 int sc_rxptr;
264
265 u_int32_t sc_busmode;
266 u_int32_t sc_opmode;
267 u_int32_t sc_inten;
268 u_int32_t sc_wepctl;
269
270 u_int32_t sc_rxint_mask;
271 u_int32_t sc_txint_mask;
272 u_int32_t sc_linkint_mask;
273
274 enum atw_rftype sc_rftype;
275 enum atw_bbptype sc_bbptype;
276 u_int32_t sc_synctl_rd;
277 u_int32_t sc_synctl_wr;
278 u_int32_t sc_bbpctl_rd;
279 u_int32_t sc_bbpctl_wr;
280
281 void (*sc_recv_beacon)(struct ieee80211com *, struct mbuf *,
282 int, u_int32_t);
283 void (*sc_recv_prresp)(struct ieee80211com *, struct mbuf *,
284 int, u_int32_t);
285
286
287 u_int8_t sc_sram[ATW_SRAM_MAXSIZE];
288 u_int sc_sramlen;
289 u_int8_t sc_bssid[IEEE80211_ADDR_LEN];
290 u_int8_t sc_rev;
291 u_int8_t sc_rf3000_options1;
292 u_int8_t sc_rf3000_options2;
293
294 struct timeval sc_last_beacon;
295 struct timeout sc_scan_to;
296 union {
297 struct atw_rx_radiotap_header tap;
298 u_int8_t pad[64];
299 } sc_rxtapu;
300 union {
301 struct atw_tx_radiotap_header tap;
302 u_int8_t pad[64];
303 } sc_txtapu;
304 };
305
306 #define sc_rxtap sc_rxtapu.tap
307 #define sc_txtap sc_txtapu.tap
308
309 #define sc_if sc_ic.ic_if
310
311
312 struct atw_frame {
313 u_int8_t atw_dst[IEEE80211_ADDR_LEN];
314 u_int8_t atw_rate;
315 u_int8_t atw_service;
316 u_int16_t atw_paylen;
317 u_int8_t atw_fc[2];
318
319
320
321 u_int16_t atw_tail_plcplen;
322 u_int16_t atw_head_plcplen;
323
324 u_int16_t atw_tail_dur;
325 u_int16_t atw_head_dur;
326 u_int8_t atw_addr4[IEEE80211_ADDR_LEN];
327 union {
328 struct {
329 u_int16_t hdrctl;
330 u_int16_t fragthr;
331
332
333 u_int8_t fragnum;
334
335
336 u_int8_t rtylmt;
337 u_int8_t wepkey0[4];
338 u_int8_t wepkey1[4];
339 u_int8_t wepkey2[4];
340 u_int8_t wepkey3[4];
341 u_int8_t keyid;
342 u_int8_t reserved0[7];
343 } s1;
344 struct {
345 u_int8_t pad[6];
346 struct ieee80211_frame ihdr;
347 } s2;
348 } u;
349 } __attribute__((__packed__));
350
351 #define atw_hdrctl u.s1.hdrctl
352 #define atw_fragthr u.s1.fragthr
353 #define atw_fragnum u.s1.fragnum
354 #define atw_rtylmt u.s1.rtylmt
355 #define atw_keyid u.s1.keyid
356 #define atw_ihdr u.s2.ihdr
357
358 #define ATW_HDRCTL_SHORT_PREAMBLE BIT(0)
359 #define ATW_HDRCTL_RTSCTS BIT(4)
360 #define ATW_HDRCTL_WEP BIT(5)
361 #define ATW_HDRCTL_UNKNOWN1 BIT(15)
362 #define ATW_HDRCTL_UNKNOWN2 BIT(8)
363
364 #define ATW_FRAGTHR_FRAGTHR_MASK BITS(0, 11)
365 #define ATW_FRAGNUM_FRAGNUM_MASK BITS(4, 7)
366
367
368 #define ATWF_MRL 0x00000010
369 #define ATWF_MRM 0x00000020
370 #define ATWF_MWI 0x00000040
371 #define ATWF_SHORT_PREAMBLE 0x00000080
372 #define ATWF_RTSCTS 0x00000100
373 #define ATWF_ATTACHED 0x00000800
374 #define ATWF_ENABLED 0x00001000
375
376 #define ATW_IS_ENABLED(sc) ((sc)->sc_flags & ATWF_ENABLED)
377
378 #define ATW_CDTXADDR(sc, x) ((sc)->sc_cddma + ATW_CDTXOFF((x)))
379 #define ATW_CDRXADDR(sc, x) ((sc)->sc_cddma + ATW_CDRXOFF((x)))
380
381 #define ATW_CDTXSYNC(sc, x, n, ops) \
382 do { \
383 int __x, __n; \
384 \
385 __x = (x); \
386 __n = (n); \
387 \
388 \
389 if ((__x + __n) > ATW_NTXDESC) { \
390 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
391 ATW_CDTXOFF(__x), sizeof(struct atw_txdesc) * \
392 (ATW_NTXDESC - __x), (ops)); \
393 __n -= (ATW_NTXDESC - __x); \
394 __x = 0; \
395 } \
396 \
397 \
398 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
399 ATW_CDTXOFF(__x), sizeof(struct atw_txdesc) * __n, (ops)); \
400 } while (0)
401
402 #define ATW_CDRXSYNC(sc, x, ops) \
403 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
404 ATW_CDRXOFF((x)), sizeof(struct atw_rxdesc), (ops))
405
406
407
408
409
410
411 #define ATW_INIT_RXDESC(sc, x) \
412 do { \
413 struct atw_rxsoft *__rxs = &sc->sc_rxsoft[(x)]; \
414 struct atw_rxdesc *__rxd = &sc->sc_rxdescs[(x)]; \
415 struct mbuf *__m = __rxs->rxs_mbuf; \
416 \
417 __rxd->ar_buf1 = \
418 htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr); \
419 __rxd->ar_buf2 = \
420 htole32(ATW_CDRXADDR((sc), ATW_NEXTRX((x)))); \
421 __rxd->ar_ctl = \
422 htole32(LSHIFT(((__m->m_ext.ext_size - 1) & ~0x3U), \
423 ATW_RXCTL_RBS1_MASK) | \
424 0 | \
425 ((x) == (ATW_NRXDESC - 1) ? ATW_RXCTL_RER : 0)); \
426 __rxd->ar_stat = htole32(ATW_RXSTAT_OWN); \
427 \
428 ATW_CDRXSYNC((sc), (x), \
429 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
430 } while (0)
431
432
433 #define ATW_COUNTRY_FCC 0
434 #define ATW_COUNTRY_IC 1
435 #define ATW_COUNTRY_ETSI 2
436 #define ATW_COUNTRY_SPAIN 3
437 #define ATW_COUNTRY_FRANCE 4
438 #define ATW_COUNTRY_MKK 5
439 #define ATW_COUNTRY_MKK2 6
440
441
442
443
444 #define ATW_READ(sc, reg) \
445 bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (reg))
446
447 #define ATW_WRITE(sc, reg, val) \
448 bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
449
450 #define ATW_SET(sc, reg, mask) \
451 ATW_WRITE((sc), (reg), ATW_READ((sc), (reg)) | (mask))
452
453 #define ATW_CLR(sc, reg, mask) \
454 ATW_WRITE((sc), (reg), ATW_READ((sc), (reg)) & ~(mask))
455
456 #define ATW_ISSET(sc, reg, mask) \
457 (ATW_READ((sc), (reg)) & (mask))
458
459 void atw_attach(struct atw_softc *);
460 int atw_detach(struct atw_softc *);
461 int atw_activate(struct device *, enum devact);
462 int atw_intr(void *arg);
463 int atw_enable(struct atw_softc *);
464 void atw_power(int, void *);
465 void atw_shutdown(void *);
466
467 #endif