49532ea9b066641a550b1fb6a8372e0bab18e8ba
[dragonfly.git] / sys / dev / netif / ral / rt2661var.h
1 /*      $FreeBSD: head/sys/dev/ral/rt2661var.h 192468 2009-05-20 20:00:40Z sam $        */
2
3 /*-
4  * Copyright (c) 2005
5  *      Damien Bergamini <damien.bergamini@free.fr>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19
20 struct rt2661_rx_radiotap_header {
21         struct ieee80211_radiotap_header wr_ihdr;
22         uint64_t        wr_tsf;
23         uint8_t         wr_flags;
24         uint8_t         wr_rate;
25         uint16_t        wr_chan_freq;
26         uint16_t        wr_chan_flags;
27         int8_t          wr_antsignal;
28         int8_t          wr_antnoise;
29 } __packed;
30
31 #define RT2661_RX_RADIOTAP_PRESENT                                      \
32         ((1 << IEEE80211_RADIOTAP_TSFT) |                               \
33          (1 << IEEE80211_RADIOTAP_FLAGS) |                              \
34          (1 << IEEE80211_RADIOTAP_RATE) |                               \
35          (1 << IEEE80211_RADIOTAP_CHANNEL) |                            \
36          (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |                      \
37          (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
38
39 struct rt2661_tx_radiotap_header {
40         struct ieee80211_radiotap_header wt_ihdr;
41         uint8_t         wt_flags;
42         uint8_t         wt_rate;
43         uint16_t        wt_chan_freq;
44         uint16_t        wt_chan_flags;
45 } __packed;
46
47 #define RT2661_TX_RADIOTAP_PRESENT                                      \
48         ((1 << IEEE80211_RADIOTAP_FLAGS) |                              \
49          (1 << IEEE80211_RADIOTAP_RATE) |                               \
50          (1 << IEEE80211_RADIOTAP_CHANNEL))
51
52 struct rt2661_tx_data {
53         bus_dmamap_t            map;
54         struct mbuf             *m;
55         struct ieee80211_node   *ni;
56         uint8_t                 rix;
57         int8_t                  rssi;
58 };
59
60 struct rt2661_tx_ring {
61         bus_dma_tag_t           desc_dmat;
62         bus_dma_tag_t           data_dmat;
63         bus_dmamap_t            desc_map;
64         bus_addr_t              physaddr;
65         struct rt2661_tx_desc   *desc;
66         struct rt2661_tx_data   *data;
67         int                     count;
68         int                     queued;
69         int                     cur;
70         int                     next;
71         int                     stat;
72 };
73
74 struct rt2661_rx_data {
75         bus_dmamap_t    map;
76         struct mbuf     *m;
77 };
78
79 struct rt2661_rx_ring {
80         bus_dma_tag_t           desc_dmat;
81         bus_dma_tag_t           data_dmat;
82         bus_dmamap_t            desc_map;
83         bus_addr_t              physaddr;
84         struct rt2661_rx_desc   *desc;
85         struct rt2661_rx_data   *data;
86         int                     count;
87         int                     cur;
88         int                     next;
89 };
90
91 struct rt2661_vap {
92         struct ieee80211vap     ral_vap;
93
94         int                     (*ral_newstate)(struct ieee80211vap *,
95                                     enum ieee80211_state, int);
96 };
97 #define RT2661_VAP(vap)         ((struct rt2661_vap *)(vap))
98
99 struct rt2661_softc {
100         struct arpcom                   arpcom;
101         struct ifnet                    *sc_ifp;
102         device_t                        sc_dev;
103         bus_space_tag_t                 sc_st;
104         bus_space_handle_t              sc_sh;
105
106         struct lock                     sc_lock;
107
108         struct callout                  watchdog_ch;
109
110         int                             sc_tx_timer;
111         int                             sc_invalid;
112         int                             sc_debug;
113 /*
114  * The same in both up to here
115  * ------------------------------------------------
116  */
117         
118         int                             sc_flags;
119 #define RAL_FW_LOADED           0x1
120 #define RAL_INPUT_RUNNING       0x2
121         int                             sc_id;
122         struct ieee80211_channel        *sc_curchan;
123
124         uint8_t                         rf_rev;
125
126         uint8_t                         rfprog;
127         uint8_t                         rffreq;
128
129         struct rt2661_tx_ring           txq[4];
130         struct rt2661_tx_ring           mgtq;
131         struct rt2661_rx_ring           rxq;
132
133         uint32_t                        rf_regs[4];
134         int8_t                          txpow[38];
135
136         struct {
137                 uint8_t reg;
138                 uint8_t val;
139         }                               bbp_prom[16];
140
141         int                             hw_radio;
142         int                             rx_ant;
143         int                             tx_ant;
144         int                             nb_ant;
145         int                             ext_2ghz_lna;
146         int                             ext_5ghz_lna;
147         int                             rssi_2ghz_corr;
148         int                             rssi_5ghz_corr;
149
150         uint8_t                         bbp18;
151         uint8_t                         bbp21;
152         uint8_t                         bbp22;
153         uint8_t                         bbp16;
154         uint8_t                         bbp17;
155         uint8_t                         bbp64;
156
157         int                             dwelltime;
158
159         struct rt2661_rx_radiotap_header sc_rxtap;
160         int                             sc_rxtap_len;
161         struct rt2661_tx_radiotap_header sc_txtap;
162         int                             sc_txtap_len;
163
164         struct sysctl_ctx_list  sc_sysctl_ctx;
165 };
166
167 int     rt2661_attach(device_t, int);
168 int     rt2661_detach(void *);
169 void    rt2661_shutdown(void *);
170 void    rt2661_suspend(void *);
171 void    rt2661_resume(void *);
172 void    rt2661_intr(void *);
173
174 #define RAL_LOCK()    lwkt_gettoken(&wlan_token)
175 #define RAL_LOCK_ASSERT()   ASSERT_LWKT_TOKEN_HELD(&wlan_token)
176 #define RAL_UNLOCK()     lwkt_reltoken(&wlan_token)