Sync 802.11 support with FreeBSD6:
[dragonfly.git] / sys / dev / netif / ray / if_rayvar.h
1 /*
2  * Copyright (C) 2000
3  * Dr. Duncan McLennan Barclay, dmlb@ragnet.demon.co.uk.
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the author nor the names of any co-contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY DUNCAN BARCLAY AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL DUNCAN BARCLAY OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $FreeBSD: src/sys/dev/ray/if_rayvar.h,v 1.12.2.4 2001/08/14 22:54:07 dmlb Exp $
32  * $DragonFly: src/sys/dev/netif/ray/Attic/if_rayvar.h,v 1.5 2006/05/18 13:51:45 sephe Exp $
33  *
34  */
35
36 /*
37  * Network parameters, used twice in softc to store what we want and what
38  * we have.
39  *
40  * The current parameters are ONLY valid in a function called from the runq
41  * and should not be accessed directly from ioctls.
42  */
43 struct ray_nw_param {
44     struct ray_cmd_net  p_1;
45     struct ray_net_params \
46                         p_2;
47     u_int8_t            np_ap_status;
48     int                 np_promisc;     /* Promiscious mode status      */
49     int                 np_framing;     /* Packet framing types         */
50     int                 np_auth;        /* Authentication status        */
51     int                 np_havenet;     /* True if we have a network    */
52 };
53 #define np_upd_param    p_1.c_upd_param
54 #define np_bss_id       p_1.c_bss_id
55 #define np_inited       p_1.c_inited
56 #define np_def_txrate   p_1.c_def_txrate
57 #define np_encrypt      p_1.c_encrypt
58 #define np_net_type     p_2.p_net_type
59 #define np_ssid         p_2.p_ssid
60 #define np_priv_start   p_2.p_privacy_must_start
61 #define np_priv_join    p_2.p_privacy_can_join
62
63 /*
64  * One of these structures per allocated device
65  */
66 struct ray_softc {
67
68     device_t dev;                       /* Device */
69     struct arpcom       arpcom;         /* Ethernet common              */
70     struct callout      tx_timer;       /* Handle for tx timer  */
71     struct callout      com_timer;      /* Handle for command timer     */
72
73     bus_space_tag_t     am_bst;         /* Bus space tag for attribute memory */
74     bus_space_handle_t  am_bsh;         /* Bus space handle for attribute mem */
75     int                 am_rid;         /* Resource id for attribute memory */
76     struct resource*    am_res;         /* Resource for attribute memory */
77     bus_space_tag_t     cm_bst;         /* Bus space tag for common memory */
78     bus_space_handle_t  cm_bsh;         /* Bus space handle for common memory */
79     int                 cm_rid;         /* Resource id for common memory */
80     struct resource*    cm_res;         /* Resource for common memory */
81     int                 irq_rid;        /* Resource id for irq */
82     struct resource*    irq_res;        /* Resource for irq */
83     void *              irq_handle;     /* Handle for irq handler */
84
85     u_int8_t            sc_ccsinuse[64];/* ccss' in use -- not for tx   */
86     u_char              sc_gone;        /* 1 = Card bailed out          */
87
88     struct ray_ecf_startup_v5
89                         sc_ecf_startup; /* Startup info from card       */
90
91     TAILQ_HEAD(ray_comq, ray_comq_entry) 
92                         sc_comq;        /* Command queue                */
93
94     struct ray_nw_param sc_c;           /* current network params       */
95     struct ray_nw_param sc_d;           /* desired network params       */
96
97     int                 sc_checkcounters;
98     u_int64_t           sc_rxoverflow;  /* Number of rx overflows       */
99     u_int64_t           sc_rxcksum;     /* Number of checksum errors    */
100     u_int64_t           sc_rxhcksum;    /* Number of header checksum errors */
101     u_int8_t            sc_rxnoise;     /* Average receiver level       */
102     struct ray_siglev   sc_siglevs[RAY_NSIGLEVRECS]; /* Antenna/levels  */
103 };
104
105 #define sc_station_addr sc_ecf_startup.e_station_addr
106 #define sc_version      sc_ecf_startup.e_fw_build_string
107 #define sc_tibsize      sc_ecf_startup.e_tibsize
108
109 /*
110  * Command queue definitions
111  */
112 typedef void (*ray_comqfn_t)(struct ray_softc *sc, struct ray_comq_entry *com);
113 MALLOC_DECLARE(M_RAYCOM);
114 MALLOC_DEFINE(M_RAYCOM, "raycom", "Raylink command queue entry");
115 struct ray_comq_entry {
116         TAILQ_ENTRY(ray_comq_entry) c_chain;    /* Tail queue.          */
117         ray_comqfn_t    c_function;             /* Function to call */
118         int             c_flags;                /* Flags                */
119         u_int8_t        c_retval;               /* Return value         */
120         void            *c_wakeup;              /* Sleeping on this     */
121         size_t          c_ccs;                  /* CCS structure        */
122         struct ray_nw_param
123                         c_desired;              /* network settings     */
124         struct ray_param_req
125                         *c_pr;                  /* MIB report/update    */
126         char            *c_mesg;
127 };
128
129 /*
130  * Macro's and constants
131  */
132 static int mib_info[RAY_MIB_MAX+1][3] = RAY_MIB_INFO;
133
134 /* Indirections for reading/writing memory - from NetBSD/if_ray.c */
135 #ifndef offsetof
136 #define offsetof(type, member) \
137     ((size_t)(&((type *)0)->member))
138 #endif /* offsetof */
139
140 #define ATTR_READ_1(sc, off) \
141     ((u_int8_t)bus_space_read_1((sc)->am_bst, (sc)->am_bsh, (off)))
142
143 #define ATTR_WRITE_1(sc, off, val) \
144     bus_space_write_1((sc)->am_bst, (sc)->am_bsh, (off), (val))
145
146 #define SRAM_READ_1(sc, off) \
147     ((u_int8_t)bus_space_read_1((sc)->cm_bst, (sc)->cm_bsh, (off)))
148
149 #define SRAM_READ_REGION(sc, off, p, n) \
150     bus_space_read_region_1((sc)->cm_bst, (sc)->cm_bsh, (off), (void *)(p), (n))
151
152 #define SRAM_READ_FIELD_1(sc, off, s, f) \
153     SRAM_READ_1((sc), (off) + offsetof(struct s, f))
154
155 #define SRAM_READ_FIELD_2(sc, off, s, f)                        \
156     ((((u_int16_t)SRAM_READ_1((sc), (off) + offsetof(struct s, f)) << 8) \
157     |(SRAM_READ_1((sc), (off) + 1 + offsetof(struct s, f)))))
158
159 #define SRAM_READ_FIELD_N(sc, off, s, f, p, n)  \
160     SRAM_READ_REGION((sc), (off) + offsetof(struct s, f), (p), (n))
161
162 #define SRAM_WRITE_1(sc, off, val)      \
163     bus_space_write_1((sc)->cm_bst, (sc)->cm_bsh, (off), (val))
164
165 #define SRAM_WRITE_REGION(sc, off, p, n) \
166     bus_space_write_region_1((sc)->cm_bst, (sc)->cm_bsh, (off), (void *)(p), (n))
167
168 #define SRAM_WRITE_FIELD_1(sc, off, s, f, v)    \
169     SRAM_WRITE_1((sc), (off) + offsetof(struct s, f), (v))
170
171 #define SRAM_WRITE_FIELD_2(sc, off, s, f, v) do {       \
172     SRAM_WRITE_1((sc), (off) + offsetof(struct s, f), (((v) >> 8 ) & 0xff)); \
173     SRAM_WRITE_1((sc), (off) + 1 + offsetof(struct s, f), ((v) & 0xff)); \
174 } while (0)
175
176 #define SRAM_WRITE_FIELD_N(sc, off, s, f, p, n) \
177     SRAM_WRITE_REGION((sc), (off) + offsetof(struct s, f), (p), (n))
178
179 /* Framing types */
180 /* XXX maybe better as part of the if structure? */
181 #define RAY_FRAMING_ENCAPSULATION       0
182 #define RAY_FRAMING_TRANSLATION         1
183
184 /* Authentication states */
185 #define RAY_AUTH_UNAUTH         0
186 #define RAY_AUTH_WAITING        1
187 #define RAY_AUTH_AUTH           2
188 #define RAY_AUTH_NEEDED         3
189
190 /* Flags for runq entries */
191 #define RAY_COM_FWOK            0x0001          /* Wakeup on completion */
192 #define RAY_COM_FRUNNING        0x0002          /* This one running     */
193 #define RAY_COM_FCOMPLETED      0x0004          /* This one completed   */
194 #define RAY_COM_FWAIT           0x0008          /* Do not run the queue */
195 #define RAY_COM_FCHKRUNNING     0x0010          /* Check IFF_RUNNING    */
196 #define RAY_COM_FDETACHED       0x0020          /* Card is gone         */
197 #define RAY_COM_FWOKEN          0x0040          /* Woken by detach      */
198 #define RAY_COM_FLAGS_PRINTFB   \
199         "\020"                  \
200         "\001WOK"               \
201         "\002RUNNING"           \
202         "\003COMPLETED"         \
203         "\004WAIT"              \
204         "\005CHKRUNNING"        \
205         "\006DETACHED"
206
207 #define RAY_COM_NEEDS_TIMO(cmd) (               \
208          (cmd == RAY_CMD_DOWNLOAD_PARAMS) ||    \
209          (cmd == RAY_CMD_UPDATE_PARAMS) ||      \
210          (cmd == RAY_CMD_UPDATE_MCAST)          \
211         )
212
213 #ifndef RAY_COM_TIMEOUT
214 #define RAY_COM_TIMEOUT         (hz / 2)
215 #endif
216
217 #ifndef RAY_RESET_TIMEOUT
218 #define RAY_RESET_TIMEOUT       (10 * hz)
219 #endif
220
221 #ifndef RAY_TX_TIMEOUT
222 #define RAY_TX_TIMEOUT          (hz / 2)
223 #endif
224
225 #define RAY_CCS_FREE(sc, ccs) \
226     SRAM_WRITE_FIELD_1((sc), (ccs), ray_cmd, c_status, RAY_CCS_STATUS_FREE)
227
228 #define RAY_ECF_READY(sc) \
229     (!(ATTR_READ_1((sc), RAY_ECFIR) & RAY_ECFIR_IRQ))
230
231 #define RAY_ECF_START_CMD(sc)   ATTR_WRITE_1((sc), RAY_ECFIR, RAY_ECFIR_IRQ)
232
233 #define RAY_HCS_CLEAR_INTR(sc)  ATTR_WRITE_1((sc), RAY_HCSIR, 0)
234
235 #define RAY_HCS_INTR(sc)        (ATTR_READ_1((sc), RAY_HCSIR) & RAY_HCSIR_IRQ)
236
237 #define RAY_PANIC(sc, fmt, args...) do {                                \
238     panic("ray%d: %s(%d) " fmt "\n", device_get_unit((sc)->dev),        \
239         __func__ , __LINE__ , ##args);                          \
240 } while (0)
241
242 #define RAY_PRINTF(sc, fmt, args...) do {                               \
243     device_printf((sc)->dev, "%s(%d) " fmt "\n",                        \
244         __func__ , __LINE__ , ##args);                          \
245 } while (0)
246
247 #define RAY_COM_MALLOC(function, flags) \
248     ray_com_malloc((function), (flags), __STRING(function));
249
250 #define RAY_COM_FREE(com, ncom) do {                                    \
251     int i;                                                              \
252     for (i = 0; i < ncom; i++)                                          \
253             FREE(com[i], M_RAYCOM);                                     \
254 } while (0)
255
256 /*
257  * This macro handles adding commands to the runq and quickly
258  * getting away when the card is detached. The macro returns
259  * from the current function with ENXIO.
260  */
261 #define RAY_COM_RUNQ(sc, com, ncom, mesg, error) do {                   \
262     (error) = ray_com_runq_add((sc), (com), (ncom), (mesg));            \
263     if ((error) == ENXIO) {                                             \
264             RAY_COM_FREE((com), (ncom));                                \
265             return (error);                                             \
266     } else if ((error) && ((error) != ENXIO))                           \
267             RAY_PRINTF(sc, "got error from runq 0x%x", (error));        \
268 } while (0)
269
270 /*
271  * There are a number of entry points into the ray_init_xxx routines.
272  * These can be classed into two types: a) those that happen as a result
273  * of a change to the cards operating parameters (e.g. BSSID change), and
274  * b) those that happen as a result of a change to the interface parameters
275  * (e.g. a change to the IP address). The second set of entries need not
276  * send a command to the card when the card is IFF_RUNNING. The
277  * RAY_COM_FCHKRUNNING flags indicates when the RUNNING flag should be
278  * checked, and this macro does the necessary check and command abort.
279  */
280 #define RAY_COM_CHKRUNNING(sc, com, ifp) do {                           \
281     if (((com)->c_flags & RAY_COM_FCHKRUNNING) &&                       \
282         ((ifp)->if_flags & IFF_RUNNING)) {                              \
283             ray_com_runq_done(sc);                                      \
284             return;                                                     \
285 } } while (0)
286     
287     
288
289 #define RAY_COM_INIT(com, function, flags)      \
290     ray_com_init((com), (function), (flags), __STRING(function));
291
292 #ifndef RAY_COM_CHECK
293 #define RAY_COM_CHECK(sc, com)
294 #endif /* RAY_COM_CHECK */
295
296 #ifndef RAY_MBUF_DUMP
297 #define RAY_MBUF_DUMP(sc, mask, m, s)
298 #endif /* RAY_MBUF_DUMP */
299
300 #ifndef RAY_RECERR
301 #define RAY_RECERR(sc, fmt, args...) do {                               \
302     struct ifnet *ifp = &(sc)->arpcom.ac_if;                            \
303     if (ifp->if_flags & IFF_DEBUG) {                                    \
304             device_printf((sc)->dev, "%s(%d) " fmt "\n",                \
305                 __func__ , __LINE__ , ##args);                  \
306 } } while (0)
307 #endif /* RAY_RECERR */
308
309 /* XXX this should be in CCSERR but don't work - probably need to use ##ifp->(iferrcounter)++;                                          \*/
310 #ifndef RAY_CCSERR
311 #define RAY_CCSERR(sc, status, iferrcounter) do {                       \
312     struct ifnet *ifp = &(sc)->arpcom.ac_if;                            \
313     char *ss[] = RAY_CCS_STATUS_STRINGS;                                \
314     if ((status) != RAY_CCS_STATUS_COMPLETE) {                          \
315         if (ifp->if_flags & IFF_DEBUG) {                                \
316             device_printf((sc)->dev,                                    \
317                 "%s(%d) ECF command completed with status %s\n",        \
318                 __func__ , __LINE__ , ss[(status)]);            \
319 } } } while (0)
320 #endif /* RAY_CCSERR */
321
322 #ifndef RAY_MAP_CM
323 #define RAY_MAP_CM(sc)
324 #endif /* RAY_MAP_CM */
325
326 /*
327  * Management information element payloads
328  */
329 union ieee80211_information {
330         char    ssid[IEEE80211_NWID_LEN+1];
331         struct rates {
332                 uint8_t *p;
333         } rates;
334         struct fh {
335                 uint16_t        dwell;
336                 uint8_t         set;
337                 uint8_t         pattern;
338                 uint8_t         index;
339         } fh;
340         struct ds {
341                 uint8_t         channel;
342         } ds;
343         struct cf {
344                 uint8_t         count;
345                 uint8_t         period;
346                 uint8_t         maxdur[2];
347                 uint8_t         dur[2];
348         } cf;
349         struct tim {
350                 uint8_t         count;
351                 uint8_t         period;
352                 uint8_t         bitctl;
353                 /* uint8_t      pvt[251]; The driver needs to use this. */
354         } tim;
355         struct ibss {
356                 uint16_t        atim;
357         } ibss;
358         struct challenge {
359                 uint8_t         *p;
360                 uint8_t         len;
361         } challenge;
362 };