2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Sepherosa Ziehau <sepherosa@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
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 MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sys/dev/netif/bwi/if_bwivar.h,v 1.2 2007/09/15 09:59:29 sephe Exp $
40 #define BWI_ALIGN 0x1000
41 #define BWI_RING_ALIGN BWI_ALIGN
42 #define BWI_BUS_SPACE_MAXADDR 0x3fffffff
44 #define BWI_TX_NRING 6
45 #define BWI_TXRX_NRING 6
46 #define BWI_TX_NDESC 128
47 #define BWI_RX_NDESC 64
48 #define BWI_TXSTATS_NDESC 64
49 #define BWI_TX_NSPRDESC 2
50 #define BWI_TX_DATA_RING 1
52 /* XXX Onoe/Sample/AMRR probably need different configuration */
55 #define BWI_SHRETRY_FB 3
56 #define BWI_LGRETRY_FB 2
58 #define BWI_NOISE_FLOOR -95 /* TODO: noise floor calc */
60 #define CSR_READ_4(sc, reg) \
61 bus_space_read_4((sc)->sc_mem_bt, (sc)->sc_mem_bh, (reg))
62 #define CSR_READ_2(sc, reg) \
63 bus_space_read_2((sc)->sc_mem_bt, (sc)->sc_mem_bh, (reg))
65 #define CSR_WRITE_4(sc, reg, val) \
66 bus_space_write_4((sc)->sc_mem_bt, (sc)->sc_mem_bh, (reg), (val))
67 #define CSR_WRITE_2(sc, reg, val) \
68 bus_space_write_2((sc)->sc_mem_bt, (sc)->sc_mem_bh, (reg), (val))
70 #define CSR_SETBITS_4(sc, reg, bits) \
71 CSR_WRITE_4((sc), (reg), CSR_READ_4((sc), (reg)) | (bits))
72 #define CSR_SETBITS_2(sc, reg, bits) \
73 CSR_WRITE_2((sc), (reg), CSR_READ_2((sc), (reg)) | (bits))
75 #define CSR_FILT_SETBITS_4(sc, reg, filt, bits) \
76 CSR_WRITE_4((sc), (reg), (CSR_READ_4((sc), (reg)) & (filt)) | (bits))
77 #define CSR_FILT_SETBITS_2(sc, reg, filt, bits) \
78 CSR_WRITE_2((sc), (reg), (CSR_READ_2((sc), (reg)) & (filt)) | (bits))
80 #define CSR_CLRBITS_4(sc, reg, bits) \
81 CSR_WRITE_4((sc), (reg), CSR_READ_4((sc), (reg)) & ~(bits))
82 #define CSR_CLRBITS_2(sc, reg, bits) \
83 CSR_WRITE_2((sc), (reg), CSR_READ_2((sc), (reg)) & ~(bits))
87 #define DPRINTF(sc, fmt, ...) if_printf(&sc->sc_ic.ic_if, fmt, __VA_ARGS__)
89 #define DPRINTF(sc, fmt, ...) ((void)0)
95 uint32_t addr
; /* BWI_DESC32_A_ */
98 #define BWI_DESC32_A_FUNC_TXRX 0x1
99 #define BWI_DESC32_A_FUNC_MASK __BITS(31, 30)
100 #define BWI_DESC32_A_ADDR_MASK __BITS(29, 0)
102 #define BWI_DESC32_C_BUFLEN_MASK __BITS(12, 0)
103 #define BWI_DESC32_C_ADDRHI_MASK __BITS(17, 16)
104 #define BWI_DESC32_C_EOR __BIT(28)
105 #define BWI_DESC32_C_INTR __BIT(29)
106 #define BWI_DESC32_C_FRAME_END __BIT(30)
107 #define BWI_DESC32_C_FRAME_START __BIT(31)
117 struct bwi_rxbuf_hdr
{
119 uint16_t rxh_buflen
; /* exclude bwi_rxbuf_hdr */
121 uint16_t rxh_flags1
; /* BWI_RXH_F1_ */
124 uint16_t rxh_phyinfo
; /* BWI_RXH_PHYINFO_ */
125 uint16_t rxh_flags3
; /* BWI_RXH_F3_ */
126 uint16_t rxh_flags2
; /* BWI_RXH_F2_ */
128 uint8_t rxh_pad3
[14]; /* Padded to 30bytes */
131 #define BWI_RXH_F1_BCM2053_RSSI __BIT(14)
132 #define BWI_RXH_F1_OFDM __BIT(0)
134 #define BWI_RXH_F2_TYPE2FRAME __BIT(2)
136 #define BWI_RXH_F3_BCM2050_RSSI __BIT(10)
138 #define BWI_RXH_PHYINFO_LNAGAIN __BITS(15, 14)
140 struct bwi_txbuf_hdr
{
142 uint32_t txh_mac_ctrl
; /* BWI_TXH_MAC_C_ */
144 uint16_t txh_unknown1
;
145 uint16_t txh_phy_ctrl
; /* BWI_TXH_PHY_C_ */
147 uint8_t txh_addr1
[IEEE80211_ADDR_LEN
];
148 uint16_t txh_unknown2
;
149 uint8_t txh_rts_fb_plcp
[4];
150 uint16_t txh_rts_fb_duration
;
151 uint8_t txh_fb_plcp
[4];
152 uint16_t txh_fb_duration
;
154 uint16_t txh_id
; /* BWI_TXH_ID_ */
155 uint16_t txh_unknown3
;
156 uint8_t txh_rts_plcp
[6];
157 uint8_t txh_rts_fc
[2];
158 uint16_t txh_rts_duration
;
159 uint8_t txh_rts_ra
[IEEE80211_ADDR_LEN
];
160 uint8_t txh_rts_ta
[IEEE80211_ADDR_LEN
];
165 #define BWI_TXH_ID_RING_MASK __BITS(15, 13)
166 #define BWI_TXH_ID_IDX_MASK __BITS(12, 0)
168 #define BWI_TXH_PHY_C_OFDM __BIT(0)
169 #define BWI_TXH_PHY_C_SHPREAMBLE __BIT(4)
170 #define BWI_TXH_PHY_C_ANTMODE_MASK __BITS(9, 8)
172 #define BWI_TXH_MAC_C_ACK __BIT(0)
173 #define BWI_TXH_MAC_C_FIRST_FRAG __BIT(3)
174 #define BWI_TXH_MAC_C_HWSEQ __BIT(4)
175 #define BWI_TXH_MAC_C_FB_OFDM __BIT(8)
182 uint8_t txs_retry_cnt
;
185 uint16_t txs_unknown
;
186 uint8_t txs_pad3
[2]; /* Padded to 16bytes */
189 struct bwi_ring_data
{
190 uint32_t rdata_txrx_ctrl
;
191 bus_dmamap_t rdata_dmap
;
192 bus_addr_t rdata_paddr
;
197 struct mbuf
*tb_mbuf
;
198 bus_dmamap_t tb_dmap
;
200 struct ieee80211_node
*tb_ni
;
204 struct bwi_txbuf_data
{
205 struct bwi_txbuf tbd_buf
[BWI_TX_NDESC
];
211 struct mbuf
*rb_mbuf
;
213 bus_dmamap_t rb_dmap
;
216 struct bwi_rxbuf_data
{
217 struct bwi_rxbuf rbd_buf
[BWI_RX_NDESC
];
218 bus_dmamap_t rbd_tmp_dmap
;
222 struct bwi_txstats_data
{
223 bus_dma_tag_t stats_ring_dtag
;
224 bus_dmamap_t stats_ring_dmap
;
225 bus_addr_t stats_ring_paddr
;
228 bus_dma_tag_t stats_dtag
;
229 bus_dmamap_t stats_dmap
;
230 bus_addr_t stats_paddr
;
231 struct bwi_txstats
*stats
;
233 uint32_t stats_ctrl_base
;
239 uint8_t fw_type
; /* BWI_FW_T_ */
240 uint8_t fw_gen
; /* BWI_FW_GEN */
243 #define fw_iv_cnt fw_size
246 #define BWI_FWHDR_SZ sizeof(struct bwi_fwhdr)
248 #define BWI_FW_T_UCODE 'u'
249 #define BWI_FW_T_PCM 'p'
250 #define BWI_FW_T_IV 'i'
252 #define BWI_FW_GEN_1 1
254 #define BWI_FW_VERSION3 3
255 #define BWI_FW_VERSION4 4
256 #define BWI_FW_VERSION3_REVMAX 0x128
258 #define BWI_FW_PATH "bwi/v%d/"
259 #define BWI_FW_UCODE_PATH BWI_FW_PATH "ucode%d.fw"
260 #define BWI_FW_PCM_PATH BWI_FW_PATH "pcm%d.fw"
261 #define BWI_FW_IV_PATH BWI_FW_PATH "b0g0initvals%d.fw"
262 #define BWI_FW_IV_EXT_PATH BWI_FW_PATH "b0g0bsinitvals%d.fw"
273 #define BWI_FW_IV_OFS_MASK __BITS(14, 0)
274 #define BWI_FW_IV_IS_32BIT __BIT(15)
276 enum bwi_clock_mode
{
283 uint32_t rw_flags
; /* BWI_REGWIN_F_ */
284 uint16_t rw_type
; /* BWI_REGWIN_T_ */
289 #define BWI_REGWIN_F_EXIST 0x1
291 #define BWI_CREATE_REGWIN(rw, id, type, rev) \
293 (rw)->rw_flags = BWI_REGWIN_F_EXIST; \
294 (rw)->rw_type = (type); \
295 (rw)->rw_id = (id); \
296 (rw)->rw_rev = (rev); \
299 #define BWI_REGWIN_EXIST(rw) ((rw)->rw_flags & BWI_REGWIN_F_EXIST)
300 #define BWI_GPIO_REGWIN(sc) \
301 (BWI_REGWIN_EXIST(&(sc)->sc_com_regwin) ? \
302 &(sc)->sc_com_regwin : &(sc)->sc_bus_regwin)
307 enum ieee80211_phymode phy_mode
;
311 uint32_t phy_flags
; /* BWI_PHY_F_ */
312 uint16_t phy_tbl_ctrl
;
313 uint16_t phy_tbl_data_lo
;
314 uint16_t phy_tbl_data_hi
;
316 void (*phy_init
)(struct bwi_mac
*);
319 #define BWI_PHY_F_CALIBRATED 0x1
320 #define BWI_PHY_F_LINKED 0x2
321 #define BWI_CLEAR_PHY_FLAGS (BWI_PHY_F_CALIBRATED)
323 /* TX power control */
325 uint16_t bbp_atten
; /* BBP attenuation: 4bits */
326 uint16_t rf_atten
; /* RF attenuation */
327 uint16_t tp_ctrl1
; /* ??: 3bits */
328 uint16_t tp_ctrl2
; /* ??: 4bits */
331 #define BWI_RF_ATTEN_FACTOR 4
332 #define BWI_RF_ATTEN_MAX0 9
333 #define BWI_RF_ATTEN_MAX1 31
334 #define BWI_BBP_ATTEN_MAX 11
335 #define BWI_TPCTL1_MAX 7
343 uint16_t rf_type
; /* BWI_RF_T_ */
347 uint32_t rf_flags
; /* BWI_RF_F_ */
349 #define BWI_RFLO_MAX 56
350 struct bwi_rf_lo rf_lo
[BWI_RFLO_MAX
];
351 uint8_t rf_lo_used
[8];
353 #define BWI_INVALID_NRSSI -1000
354 int16_t rf_nrssi
[2]; /* Narrow RSSI */
355 int32_t rf_nrssi_slope
;
357 #define BWI_NRSSI_TBLSZ 64
358 int8_t rf_nrssi_table
[BWI_NRSSI_TBLSZ
];
360 uint16_t rf_lo_gain
; /* loopback gain */
361 uint16_t rf_rx_gain
; /* TRSW RX gain */
363 uint16_t rf_calib
; /* RF calibration value */
364 u_int rf_curchan
; /* current channel */
368 void (*rf_off
)(struct bwi_mac
*);
369 void (*rf_on
)(struct bwi_mac
*);
371 void (*rf_set_nrssi_thr
)(struct bwi_mac
*);
372 void (*rf_calc_nrssi_slope
)(struct bwi_mac
*);
375 const struct bwi_rxbuf_hdr
*);
377 #define BWI_TSSI_MAX 64
378 int8_t rf_txpower_map0
[BWI_TSSI_MAX
];
379 /* Indexed by TSSI */
382 int8_t rf_txpower_map
[BWI_TSSI_MAX
];
387 int rf_txpower_max
; /* dBm */
389 int rf_ant_mode
; /* BWI_ANT_MODE_ */
392 #define BWI_RF_F_INITED 0x1
393 #define BWI_RF_F_ON 0x2
394 #define BWI_RF_CLEAR_FLAGS (BWI_RF_F_INITED)
396 #define BWI_ANT_MODE_0 0
397 #define BWI_ANT_MODE_1 1
398 #define BWI_ANT_MODE_UNKN 2
399 #define BWI_ANT_MODE_AUTO 3
405 struct bwi_regwin mac_regwin
; /* MUST be first field */
406 #define mac_rw_flags mac_regwin.rw_flags
407 #define mac_type mac_regwin.rw_type
408 #define mac_id mac_regwin.rw_id
409 #define mac_rev mac_regwin.rw_rev
411 struct bwi_softc
*mac_sc
;
413 struct bwi_phy mac_phy
; /* PHY I/F */
414 struct bwi_rf mac_rf
; /* RF I/F */
416 struct bwi_tpctl mac_tpctl
; /* TX power control */
417 uint32_t mac_flags
; /* BWI_MAC_F_ */
419 struct fw_image
*mac_ucode
;
420 struct fw_image
*mac_pcm
;
421 struct fw_image
*mac_iv
;
422 struct fw_image
*mac_iv_ext
;
425 #define BWI_MAC_F_BSWAP 0x1
426 #define BWI_MAC_F_TPCTL_INITED 0x2
427 #define BWI_MAC_F_HAS_TXSTATS 0x4
428 #define BWI_MAC_F_INITED 0x8
429 #define BWI_MAC_F_ENABLED 0x10
430 #define BWI_MAC_F_LOCKED 0x20 /* for debug */
431 #define BWI_MAC_F_TPCTL_ERROR 0x40
433 #define BWI_CREATE_MAC(mac, sc, id, rev) \
435 BWI_CREATE_REGWIN(&(mac)->mac_regwin, \
439 (mac)->mac_sc = (sc); \
442 #define BWI_MAC_MAX 2
445 BWI_BUS_SPACE_30BIT
= 1,
451 struct ieee80211com sc_ic
;
452 uint32_t sc_flags
; /* BWI_F_ */
455 uint32_t sc_cap
; /* BWI_CAP_ */
456 uint16_t sc_bbp_id
; /* BWI_BBPID_ */
460 uint8_t sc_pci_revid
;
461 uint16_t sc_pci_subvid
;
462 uint16_t sc_pci_subdid
;
464 uint16_t sc_card_flags
; /* BWI_CARD_F_ */
465 uint16_t sc_pwron_delay
;
469 struct resource
*sc_irq_res
;
473 struct resource
*sc_mem_res
;
474 bus_space_tag_t sc_mem_bt
;
475 bus_space_handle_t sc_mem_bh
;
477 struct callout sc_scan_ch
;
478 struct callout sc_calib_ch
;
480 struct bwi_regwin
*sc_cur_regwin
;
481 struct bwi_regwin sc_com_regwin
;
482 struct bwi_regwin sc_bus_regwin
;
485 struct bwi_mac sc_mac
[BWI_MAC_MAX
];
487 enum bwi_bus_space sc_bus_space
;
488 bus_dma_tag_t sc_parent_dtag
;
490 bus_dma_tag_t sc_buf_dtag
;
491 struct bwi_txbuf_data sc_tx_bdata
[BWI_TX_NRING
];
492 struct bwi_rxbuf_data sc_rx_bdata
;
494 bus_dma_tag_t sc_txring_dtag
;
495 struct bwi_ring_data sc_tx_rdata
[BWI_TX_NRING
];
496 bus_dma_tag_t sc_rxring_dtag
;
497 struct bwi_ring_data sc_rx_rdata
;
499 struct bwi_txstats_data
*sc_txstats
;
504 (struct ieee80211com
*,
505 enum ieee80211_state
, int);
507 int (*sc_init_tx_ring
)(struct bwi_softc
*, int);
508 void (*sc_free_tx_ring
)(struct bwi_softc
*, int);
510 int (*sc_init_rx_ring
)(struct bwi_softc
*);
511 void (*sc_free_rx_ring
)(struct bwi_softc
*);
513 int (*sc_init_txstats
)(struct bwi_softc
*);
514 void (*sc_free_txstats
)(struct bwi_softc
*);
516 void (*sc_setup_rxdesc
)
517 (struct bwi_softc
*, int, bus_addr_t
, int);
518 void (*sc_rxeof
)(struct bwi_softc
*);
520 void (*sc_setup_txdesc
)
521 (struct bwi_softc
*, struct bwi_ring_data
*,
522 int, bus_addr_t
, int);
524 (struct bwi_softc
*, uint32_t, int);
526 void (*sc_txeof_status
)(struct bwi_softc
*);
528 /* Sysctl variables */
529 int sc_fw_version
; /* BWI_FW_VERSION[34] */
530 int sc_dwell_time
; /* milliseconds */
533 #define BWI_F_BUS_INITED 0x1
534 #define BWI_F_PROMISC 0x2
536 uint16_t bwi_read_sprom(struct bwi_softc
*, uint16_t);
537 int bwi_regwin_switch(struct bwi_softc
*, struct bwi_regwin
*,
538 struct bwi_regwin
**);
539 int bwi_regwin_is_enabled(struct bwi_softc
*, struct bwi_regwin
*);
540 void bwi_regwin_enable(struct bwi_softc
*, struct bwi_regwin
*,
542 void bwi_regwin_disable(struct bwi_softc
*, struct bwi_regwin
*,
544 int bwi_bus_init(struct bwi_softc
*, struct bwi_mac
*);
545 uint8_t bwi_rate2plcp(uint8_t); /* XXX belongs to 802.11 */
547 #define abs(a) __builtin_abs(a)
549 #endif /* !_IF_BWIVAR_H */