atwvar.h revision 1.10
1/* $NetBSD: atwvar.h,v 1.10 2004/07/15 06:06:53 dyoung Exp $ */ 2 3/* 4 * Copyright (c) 2003, 2004 The NetBSD Foundation, Inc. All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by David Young. 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 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the NetBSD 20 * Foundation, Inc. and its contributors. 21 * 4. Neither the name of the author nor the names of any co-contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY David Young AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL David Young 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 35 * THE POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#ifndef _DEV_IC_ATWVAR_H_ 39#define _DEV_IC_ATWVAR_H_ 40 41#include <sys/queue.h> 42#include <sys/callout.h> 43#include <sys/time.h> 44 45/* 46 * Some misc. statics, useful for debugging. 47 */ 48struct atw_stats { 49 u_long ts_tx_tuf; /* transmit underflow errors */ 50 u_long ts_tx_tro; /* transmit jabber timeouts */ 51 u_long ts_tx_trt; /* retry count exceeded */ 52 u_long ts_tx_tlt; /* lifetime exceeded */ 53 u_long ts_tx_sofbr; /* packet size mismatch */ 54}; 55 56/* 57 * Transmit descriptor list size. This is arbitrary, but allocate 58 * enough descriptors for 64 pending transmissions and 16 segments 59 * per packet. Since a descriptor holds 2 buffer addresses, that's 60 * 8 descriptors per packet. This MUST work out to a power of 2. 61 */ 62#define ATW_NTXSEGS 16 63 64#define ATW_TXQUEUELEN 64 65#define ATW_NTXDESC (ATW_TXQUEUELEN * ATW_NTXSEGS) 66#define ATW_NTXDESC_MASK (ATW_NTXDESC - 1) 67#define ATW_NEXTTX(x) ((x + 1) & ATW_NTXDESC_MASK) 68 69/* 70 * Receive descriptor list size. We have one Rx buffer per incoming 71 * packet, so this logic is a little simpler. 72 */ 73#define ATW_NRXDESC 64 74#define ATW_NRXDESC_MASK (ATW_NRXDESC - 1) 75#define ATW_NEXTRX(x) ((x + 1) & ATW_NRXDESC_MASK) 76 77/* 78 * Control structures are DMA'd to the ADM8211 chip. We allocate them in 79 * a single clump that maps to a single DMA segment to make several things 80 * easier. 81 */ 82struct atw_control_data { 83 /* 84 * The transmit descriptors. 85 */ 86 struct atw_txdesc acd_txdescs[ATW_NTXDESC]; 87 88 /* 89 * The receive descriptors. 90 */ 91 struct atw_rxdesc acd_rxdescs[ATW_NRXDESC]; 92}; 93 94#define ATW_CDOFF(x) offsetof(struct atw_control_data, x) 95#define ATW_CDTXOFF(x) ATW_CDOFF(acd_txdescs[(x)]) 96#define ATW_CDRXOFF(x) ATW_CDOFF(acd_rxdescs[(x)]) 97/* 98 * Software state for transmit jobs. 99 */ 100struct atw_txsoft { 101 struct mbuf *txs_mbuf; /* head of our mbuf chain */ 102 bus_dmamap_t txs_dmamap; /* our DMA map */ 103 int txs_firstdesc; /* first descriptor in packet */ 104 int txs_lastdesc; /* last descriptor in packet */ 105 int txs_ndescs; /* number of descriptors */ 106 SIMPLEQ_ENTRY(atw_txsoft) txs_q; 107}; 108 109SIMPLEQ_HEAD(atw_txsq, atw_txsoft); 110 111/* 112 * Software state for receive jobs. 113 */ 114struct atw_rxsoft { 115 struct mbuf *rxs_mbuf; /* head of our mbuf chain */ 116 bus_dmamap_t rxs_dmamap; /* our DMA map */ 117}; 118 119/* 120 * Table which describes the transmit threshold mode. We generally 121 * start at index 0. Whenever we get a transmit underrun, we increment 122 * our index, falling back if we encounter the NULL terminator. 123 */ 124struct atw_txthresh_tab { 125 u_int32_t txth_opmode; /* OPMODE bits */ 126 const char *txth_name; /* name of mode */ 127}; 128 129#define ATW_TXTHRESH_TAB_LO_RATE { \ 130 { ATW_NAR_TR_L64, "64 bytes" }, \ 131 { ATW_NAR_TR_L160, "160 bytes" }, \ 132 { ATW_NAR_TR_L192, "192 bytes" }, \ 133 { ATW_NAR_SF, "store and forward" }, \ 134 { 0, NULL }, \ 135} 136 137#define ATW_TXTHRESH_TAB_HI_RATE { \ 138 { ATW_NAR_TR_H96, "96 bytes" }, \ 139 { ATW_NAR_TR_H288, "288 bytes" }, \ 140 { ATW_NAR_TR_H544, "544 bytes" }, \ 141 { ATW_NAR_SF, "store and forward" }, \ 142 { 0, NULL }, \ 143} 144 145enum atw_rftype { ATW_RFTYPE_INTERSIL = 0, ATW_RFTYPE_RFMD = 1, 146 ATW_RFTYPE_MARVEL = 2 }; 147 148enum atw_bbptype { ATW_BBPTYPE_INTERSIL = 0, ATW_BBPTYPE_RFMD = 1, 149 ATW_BBPTYPE_MARVEL = 2, ATW_C_BBPTYPE_RFMD = 5 }; 150 151/* Radio capture format for ADMtek. */ 152 153#define ATW_RX_RADIOTAP_PRESENT \ 154 ((1 << IEEE80211_RADIOTAP_FLAGS) | (1 << IEEE80211_RADIOTAP_RATE) | \ 155 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 156 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)) 157 158struct atw_rx_radiotap_header { 159 struct ieee80211_radiotap_header ar_ihdr; 160 u_int8_t ar_flags; 161 u_int8_t ar_rate; 162 u_int16_t ar_chan_freq; 163 u_int16_t ar_chan_flags; 164 u_int8_t ar_antsignal; 165} __attribute__((__packed__)); 166 167#define ATW_TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 168 (1 << IEEE80211_RADIOTAP_RATE) | \ 169 (1 << IEEE80211_RADIOTAP_CHANNEL)) 170 171struct atw_tx_radiotap_header { 172 struct ieee80211_radiotap_header at_ihdr; 173 u_int8_t at_flags; 174 u_int8_t at_rate; 175 u_int16_t at_chan_freq; 176 u_int16_t at_chan_flags; 177} __attribute__((__packed__)); 178 179struct atw_softc { 180 struct device sc_dev; 181 struct ieee80211com sc_ic; 182 int (*sc_enable)(struct atw_softc *); 183 void (*sc_disable)(struct atw_softc *); 184 void (*sc_power)(struct atw_softc *, int); 185 int (*sc_newstate)(struct ieee80211com *, 186 enum ieee80211_state, int); 187 void (*sc_recv_mgmt)(struct ieee80211com *, 188 struct mbuf *, struct ieee80211_node *, 189 int, int, u_int32_t); 190 struct ieee80211_node *(*sc_node_alloc)(struct ieee80211com *); 191 void (*sc_node_free)(struct ieee80211com *, 192 struct ieee80211_node *); 193 194 struct atw_stats sc_stats; /* debugging stats */ 195 196 int sc_tx_timer; 197 int sc_rescan_timer; 198 199 bus_space_tag_t sc_st; /* bus space tag */ 200 bus_space_handle_t sc_sh; /* bus space handle */ 201 bus_dma_tag_t sc_dmat; /* bus dma tag */ 202 void *sc_sdhook; /* shutdown hook */ 203 void *sc_powerhook; /* power management hook */ 204 u_int32_t sc_cacheline; /* cache line size */ 205 u_int32_t sc_maxburst; /* maximum burst length */ 206 207 const struct atw_txthresh_tab *sc_txth; 208 int sc_txthresh; /* current tx threshold */ 209 210 u_int sc_cur_chan; /* current channel */ 211 212 int sc_flags; 213 214 u_int16_t *sc_srom; 215 u_int16_t sc_sromsz; 216 217 caddr_t sc_radiobpf; 218 219 bus_dma_segment_t sc_cdseg; /* control data memory */ 220 int sc_cdnseg; /* number of segments */ 221 bus_dmamap_t sc_cddmamap; /* control data DMA map */ 222#define sc_cddma sc_cddmamap->dm_segs[0].ds_addr 223 224 /* 225 * Software state for transmit and receive descriptors. 226 */ 227 struct atw_txsoft sc_txsoft[ATW_TXQUEUELEN]; 228 struct atw_rxsoft sc_rxsoft[ATW_NRXDESC]; 229 230 /* 231 * Control data structures. 232 */ 233 struct atw_control_data *sc_control_data; 234#define sc_txdescs sc_control_data->acd_txdescs 235#define sc_rxdescs sc_control_data->acd_rxdescs 236#define sc_setup_desc sc_control_data->acd_setup_desc 237 238 int sc_txfree; /* number of free Tx descriptors */ 239 int sc_txnext; /* next ready Tx descriptor */ 240 int sc_ntxsegs; /* number of transmit segs per pkt */ 241 242 struct atw_txsq sc_txfreeq; /* free Tx descsofts */ 243 struct atw_txsq sc_txdirtyq; /* dirty Tx descsofts */ 244 245 int sc_rxptr; /* next ready RX descriptor/descsoft */ 246 247 u_int32_t sc_busmode; /* copy of ATW_PAR */ 248 u_int32_t sc_opmode; /* copy of ATW_NAR */ 249 u_int32_t sc_inten; /* copy of ATW_IER */ 250 u_int32_t sc_wepctl; /* copy of ATW_WEPCTL */ 251 252 u_int32_t sc_rxint_mask; /* mask of Rx interrupts we want */ 253 u_int32_t sc_txint_mask; /* mask of Tx interrupts we want */ 254 u_int32_t sc_linkint_mask;/* link-state interrupts mask */ 255 256 /* interrupt acknowledge hook */ 257 void (*sc_intr_ack)(struct atw_softc *); 258 259 enum atw_rftype sc_rftype; 260 enum atw_bbptype sc_bbptype; 261 u_int32_t sc_synctl_rd; 262 u_int32_t sc_synctl_wr; 263 u_int32_t sc_bbpctl_rd; 264 u_int32_t sc_bbpctl_wr; 265 266 void (*sc_recv_beacon)(struct ieee80211com *, struct mbuf *, 267 int, u_int32_t); 268 void (*sc_recv_prresp)(struct ieee80211com *, struct mbuf *, 269 int, u_int32_t); 270 271 /* ADM8211 state variables. */ 272 u_int8_t sc_sram[ATW_SRAM_SIZE]; 273 u_int8_t sc_bssid[IEEE80211_ADDR_LEN]; 274 275 struct timeval sc_last_beacon; 276 struct callout sc_scan_ch; 277 union { 278 struct atw_rx_radiotap_header tap; 279 u_int8_t pad[64]; 280 } sc_rxtapu; 281 union { 282 struct atw_tx_radiotap_header tap; 283 u_int8_t pad[64]; 284 } sc_txtapu; 285}; 286 287#define sc_rxtap sc_rxtapu.tap 288#define sc_txtap sc_txtapu.tap 289 290#define sc_if sc_ic.ic_if 291 292/* XXX this is fragile. try not to introduce any u_int32_t's. */ 293struct atw_frame { 294/*00*/ u_int8_t atw_dst[IEEE80211_ADDR_LEN]; 295/*06*/ u_int8_t atw_rate; /* TX rate in 100Kbps */ 296/*07*/ u_int8_t atw_service; /* 0 */ 297/*08*/ u_int16_t atw_paylen; /* payload length */ 298/*0a*/ u_int8_t atw_fc[2]; /* 802.11 Frame 299 * Control 300 */ 301 /* 802.11 PLCP Length for first & last fragment */ 302/*0c*/ u_int16_t atw_tail_plcplen; 303/*0e*/ u_int16_t atw_head_plcplen; 304 /* 802.11 Duration for first & last fragment */ 305/*10*/ u_int16_t atw_tail_dur; 306/*12*/ u_int16_t atw_head_dur; 307/*14*/ u_int8_t atw_addr4[IEEE80211_ADDR_LEN]; 308 union { 309 struct { 310/*1a*/ u_int16_t hdrctl; /*transmission control*/ 311/*1c*/ u_int16_t fragthr;/* fragmentation threshold 312 * [0:11], zero [12:15]. 313 */ 314/*1e*/ u_int8_t fragnum;/* fragment number [4:7], 315 * zero [0:3]. 316 */ 317/*1f*/ u_int8_t rtylmt; /* retry limit */ 318/*20*/ u_int8_t wepkey0[4];/* ??? */ 319/*24*/ u_int8_t wepkey1[4];/* ??? */ 320/*28*/ u_int8_t wepkey2[4];/* ??? */ 321/*2c*/ u_int8_t wepkey3[4];/* ??? */ 322/*30*/ u_int8_t keyid; 323/*31*/ u_int8_t reserved0[7]; 324 } s1; 325 struct { 326 u_int8_t pad[6]; 327 struct ieee80211_frame ihdr; 328 } s2; 329 } u; 330} __attribute__((__packed__)); 331 332#define atw_hdrctl u.s1.hdrctl 333#define atw_fragthr u.s1.fragthr 334#define atw_fragnum u.s1.fragnum 335#define atw_rtylmt u.s1.rtylmt 336#define atw_keyid u.s1.keyid 337#define atw_ihdr u.s2.ihdr 338 339#define ATW_HDRCTL_SHORT_PREAMBLE BIT(0) /* use short preamble */ 340#define ATW_HDRCTL_RTSCTS BIT(4) /* send RTS */ 341#define ATW_HDRCTL_WEP BIT(5) 342#define ATW_HDRCTL_UNKNOWN1 BIT(15) /* MAC adds FCS? */ 343#define ATW_HDRCTL_UNKNOWN2 BIT(8) 344 345#define ATW_FRAGTHR_FRAGTHR_MASK BITS(0, 11) 346#define ATW_FRAGNUM_FRAGNUM_MASK BITS(4, 7) 347 348/* Values for sc_flags. */ 349#define ATWF_MRL 0x00000010 /* memory read line okay */ 350#define ATWF_MRM 0x00000020 /* memory read multi okay */ 351#define ATWF_MWI 0x00000040 /* memory write inval okay */ 352#define ATWF_SHORT_PREAMBLE 0x00000080 /* short preamble enabled */ 353#define ATWF_RTSCTS 0x00000100 /* RTS/CTS enabled */ 354#define ATWF_ATTACHED 0x00000800 /* attach has succeeded */ 355#define ATWF_ENABLED 0x00001000 /* chip is enabled */ 356 357#define ATW_IS_ENABLED(sc) ((sc)->sc_flags & ATWF_ENABLED) 358 359#define ATW_CDTXADDR(sc, x) ((sc)->sc_cddma + ATW_CDTXOFF((x))) 360#define ATW_CDRXADDR(sc, x) ((sc)->sc_cddma + ATW_CDRXOFF((x))) 361 362#define ATW_CDTXSYNC(sc, x, n, ops) \ 363do { \ 364 int __x, __n; \ 365 \ 366 __x = (x); \ 367 __n = (n); \ 368 \ 369 /* If it will wrap around, sync to the end of the ring. */ \ 370 if ((__x + __n) > ATW_NTXDESC) { \ 371 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ 372 ATW_CDTXOFF(__x), sizeof(struct atw_txdesc) * \ 373 (ATW_NTXDESC - __x), (ops)); \ 374 __n -= (ATW_NTXDESC - __x); \ 375 __x = 0; \ 376 } \ 377 \ 378 /* Now sync whatever is left. */ \ 379 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ 380 ATW_CDTXOFF(__x), sizeof(struct atw_txdesc) * __n, (ops)); \ 381} while (0) 382 383#define ATW_CDRXSYNC(sc, x, ops) \ 384 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ 385 ATW_CDRXOFF((x)), sizeof(struct atw_rxdesc), (ops)) 386 387/* 388 * Note we rely on MCLBYTES being a power of two. Because the `length' 389 * field is only 11 bits, we must subtract 1 from the length to avoid 390 * having it truncated to 0! 391 * 392 * Apparently we have to set ATW_RXSTAT_SQL to make the ADM8211 tell 393 * us RSSI. 394 */ 395#define ATW_INIT_RXDESC(sc, x) \ 396do { \ 397 struct atw_rxsoft *__rxs = &sc->sc_rxsoft[(x)]; \ 398 struct atw_rxdesc *__rxd = &sc->sc_rxdescs[(x)]; \ 399 struct mbuf *__m = __rxs->rxs_mbuf; \ 400 \ 401 __m->m_data = __m->m_ext.ext_buf; \ 402 __rxd->ar_buf1 = \ 403 htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr); \ 404 __rxd->ar_buf2 = /* for descriptor chaining */ \ 405 htole32(ATW_CDRXADDR((sc), ATW_NEXTRX((x)))); \ 406 __rxd->ar_ctl = \ 407 htole32(LSHIFT(((__m->m_ext.ext_size - 1) & ~0x3U), \ 408 ATW_RXCTL_RBS1_MASK) | \ 409 0 /* ATW_RXCTL_RCH */ | \ 410 ((x) == (ATW_NRXDESC - 1) ? ATW_RXCTL_RER : 0)); \ 411 __rxd->ar_stat = \ 412 htole32(ATW_RXSTAT_OWN|ATW_RXSTAT_SQL|ATW_RXSTAT_FS| \ 413 ATW_RXSTAT_LS); \ 414 ATW_CDRXSYNC((sc), (x), \ 415 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \ 416} while (0) 417 418/* country codes from ADM8211 SROM */ 419#define ATW_COUNTRY_FCC 0 /* USA 1-11 */ 420#define ATW_COUNTRY_IC 1 /* Canada 1-11 */ 421#define ATW_COUNTRY_ETSI 2 /* European Union (?) 1-13 */ 422#define ATW_COUNTRY_SPAIN 3 /* 10-11 */ 423#define ATW_COUNTRY_FRANCE 4 /* 10-13 */ 424#define ATW_COUNTRY_MKK 5 /* Japan: 14 */ 425#define ATW_COUNTRY_MKK2 6 /* Japan: 1-14 */ 426 427/* One Time Unit (TU) is 1Kus = 1024 microseconds. */ 428#define IEEE80211_DUR_TU 1024 429 430/* IEEE 802.11b durations for DSSS PHY in microseconds */ 431#define IEEE80211_DUR_DS_LONG_PREAMBLE 144 432#define IEEE80211_DUR_DS_SHORT_PREAMBLE 72 433#define IEEE80211_DUR_DS_FAST_PLCPHDR 24 434#define IEEE80211_DUR_DS_SLOW_PLCPHDR 48 435#define IEEE80211_DUR_DS_SLOW_ACK 112 436#define IEEE80211_DUR_DS_FAST_ACK 56 437#define IEEE80211_DUR_DS_SLOW_CTS 112 438#define IEEE80211_DUR_DS_FAST_CTS 56 439#define IEEE80211_DUR_DS_SLOT 20 440#define IEEE80211_DUR_DS_SIFS 10 441#define IEEE80211_DUR_DS_PIFS (IEEE80211_DUR_DS_SIFS + IEEE80211_DUR_DS_SLOT) 442#define IEEE80211_DUR_DS_DIFS (IEEE80211_DUR_DS_SIFS + \ 443 2 * IEEE80211_DUR_DS_SLOT) 444#define IEEE80211_DUR_DS_EIFS (IEEE80211_DUR_DS_SIFS + \ 445 IEEE80211_DUR_DS_SLOW_ACK + \ 446 IEEE80211_DUR_DS_LONG_PREAMBLE + \ 447 IEEE80211_DUR_DS_SLOW_PLCPHDR + \ 448 IEEE80211_DUR_DIFS) 449 450/* 451 * register space access macros 452 */ 453#define ATW_READ(sc, reg) \ 454 bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (reg)) 455 456#define ATW_WRITE(sc, reg, val) \ 457 bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val)) 458 459#define ATW_SET(sc, reg, mask) \ 460 ATW_WRITE((sc), (reg), ATW_READ((sc), (reg)) | (mask)) 461 462#define ATW_CLR(sc, reg, mask) \ 463 ATW_WRITE((sc), (reg), ATW_READ((sc), (reg)) & ~(mask)) 464 465#define ATW_ISSET(sc, reg, mask) \ 466 (ATW_READ((sc), (reg)) & (mask)) 467 468void atw_attach(struct atw_softc *); 469int atw_detach(struct atw_softc *); 470int atw_activate(struct device *, enum devact); 471int atw_intr(void *arg); 472void atw_power(int, void *); 473void atw_shutdown(void *); 474 475#endif /* _DEV_IC_ATWVAR_H_ */ 476