1 /* $NetBSD: if_ray.c,v 1.76 2009/09/05 14:44:59 tsutsui Exp $ */
4 * Copyright (c) 2000 Christian E. Hopps
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 THE AUTHOR 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
33 * Driver for the Raylink (Raytheon) / WebGear IEEE 802.11 (FH) WLANs
35 * 2-way communication with the card is through command structures
36 * stored in shared ram. To communicate with the card a free
37 * command structure is filled in and then the card is interrupted.
38 * The card does the same with a different set of command structures.
39 * Only one command can be processed at a time. This is indicated
40 * by the interrupt having not been cleared since it was last set.
41 * The bit is cleared when the command has been processed (although
42 * it may not yet be complete).
44 * This driver was only tested with the Aviator 2.4 wireless
45 * The author didn't have the pro version or raylink to test
48 * N.B. Its unclear yet whether the Aviator 2.4 cards interoperate
49 * with other 802.11 FH 2Mbps cards, since this was also untested.
50 * Given the nature of the buggy build 4 firmware there may be problems.
52 * Authentication added by Steve Weiss <srw@alum.mit.edu> based on
53 * advice from Corey Thomas (author of the Linux RayLink driver).
54 * Authentication is currently limited to adhoc networks, and was
55 * added to support a requirement of the newest Windows drivers for
56 * the RayLink. Tested with Aviator Pro (firmware 5.63) on Win98.
59 #include <sys/cdefs.h>
60 __KERNEL_RCSID(0, "$NetBSD: if_ray.c,v 1.76 2009/09/05 14:44:59 tsutsui Exp $");
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/callout.h>
69 #include <sys/socket.h>
70 #include <sys/ioctl.h>
71 #include <sys/errno.h>
72 #include <sys/device.h>
73 #include <sys/kernel.h>
77 #include <net/if_dl.h>
78 #include <net/if_ether.h>
79 #include <net/if_media.h>
80 #include <net/if_llc.h>
81 #include <net80211/ieee80211.h>
82 #include <net80211/ieee80211_ioctl.h>
83 #include <net/if_media.h>
86 #include <netinet/in.h>
87 #include <netinet/in_systm.h>
88 #include <netinet/in_var.h>
89 #include <netinet/ip.h>
90 #include <netinet/if_inarp.h>
95 #include <net/bpfdesc.h>
100 #include <sys/intr.h>
102 #include <dev/pcmcia/pcmciareg.h>
103 #include <dev/pcmcia/pcmciavar.h>
104 #include <dev/pcmcia/pcmciadevs.h>
106 #include <dev/pcmcia/if_rayreg.h>
110 #ifndef RAY_PID_COUNTRY_CODE_DEFAULT
111 #define RAY_PID_COUNTRY_CODE_DEFAULT RAY_PID_COUNTRY_CODE_USA
114 /* amount of time to poll for non-return of certain command status */
115 #ifndef RAY_CHECK_CCS_TIMEOUT
116 #define RAY_CHECK_CCS_TIMEOUT (hz / 2)
119 /* ammount of time to consider start/join failed */
120 #ifndef RAY_START_TIMEOUT
121 #define RAY_START_TIMEOUT (30 * hz)
125 * if a command cannot execute because device is busy try later
126 * this is also done after interrupts and other command timeouts
127 * so we can use a large value safely.
129 #ifndef RAY_CHECK_SCHED_TIMEOUT
130 #define RAY_CHECK_SCHED_TIMEOUT (hz) /* XXX 5 */
133 #ifndef RAY_MODE_DEFAULT
134 #define RAY_MODE_DEFAULT SC_MODE_ADHOC
138 #define RAY_DEF_NWID "NETWORK_NAME"
142 * The number of times the HW is reset in 30s before disabling.
143 * This is needed because resets take ~2s and currently pcmcia
144 * spins for the reset.
146 #ifndef RAY_MAX_RESETS
147 #define RAY_MAX_RESETS 3
155 struct device sc_dev
;
156 struct ethercom sc_ec
;
157 struct ifmedia sc_media
;
159 struct pcmcia_function
*sc_pf
;
165 struct callout sc_check_ccs_ch
;
166 struct callout sc_check_scheduled_ch
;
167 struct callout sc_reset_resetloop_ch
;
168 struct callout sc_disable_ch
;
169 struct callout sc_start_join_timo_ch
;
171 struct ray_ecf_startup sc_ecf_startup
;
172 struct ray_startup_params_head sc_startup
;
174 struct ray_startup_params_tail_5 u_params_5
;
175 struct ray_startup_params_tail_4 u_params_4
;
178 u_int8_t sc_ccsinuse
[64]; /* ccs in use -- not for tx */
179 u_int sc_txfree
; /* a free count for efficiency */
181 u_int8_t sc_bssid
[ETHER_ADDR_LEN
]; /* current net values */
182 u_int8_t sc_authid
[ETHER_ADDR_LEN
]; /* ID of authenticating
184 struct ieee80211_nwid sc_cnwid
; /* last nwid */
185 struct ieee80211_nwid sc_dnwid
; /* desired nwid */
186 u_int8_t sc_omode
; /* old operating mode SC_MODE_xx */
187 u_int8_t sc_mode
; /* current operating mode SC_MODE_xx */
188 u_int8_t sc_countrycode
; /* current country code */
189 u_int8_t sc_dcountrycode
; /* desired country code */
190 int sc_havenet
; /* true if we have acquired a network */
191 bus_size_t sc_txpad
; /* tib size plus "phy" size */
192 u_int8_t sc_deftxrate
; /* default transfer rate */
194 u_int8_t sc_authstate
; /* authentication state */
196 int sc_promisc
; /* current set value */
197 int sc_running
; /* things we are doing */
198 int sc_scheduled
; /* things we need to do */
199 int sc_timoneed
; /* set if timeout is sched */
200 int sc_timocheck
; /* set if timeout is sched */
201 bus_size_t sc_startccs
; /* ccs of start/join */
202 u_int sc_startcmd
; /* cmd (start | join) */
204 int sc_checkcounters
;
205 u_int64_t sc_rxoverflow
;
206 u_int64_t sc_rxcksum
;
207 u_int64_t sc_rxhcksum
;
210 /* use to return values to the user */
211 struct ray_param_req
*sc_repreq
;
212 struct ray_param_req
*sc_updreq
;
214 bus_space_tag_t sc_memt
;
215 bus_space_handle_t sc_memh
;
218 struct ray_siglev sc_siglevs
[RAY_NSIGLEVRECS
];
221 #define sc_ccrt sc_pf->pf_ccrt
222 #define sc_ccrh sc_pf->pf_ccrh
223 #define sc_ccroff sc_pf->pf_ccr_offset
224 #define sc_startup_4 sc_u.u_params_4
225 #define sc_startup_5 sc_u.u_params_5
226 #define sc_version sc_ecf_startup.e_fw_build_string
227 #define sc_tibsize sc_ecf_startup.e_tib_size
228 #define sc_if sc_ec.ec_if
230 /* modes of operation */
231 #define SC_MODE_ADHOC 0 /* ad-hoc mode */
232 #define SC_MODE_INFRA 1 /* infrastructure mode */
234 /* commands -- priority given to LSB */
235 #define SCP_FIRST 0x0001
236 #define SCP_UPDATESUBCMD 0x0001
237 #define SCP_STARTASSOC 0x0002
238 #define SCP_REPORTPARAMS 0x0004
239 #define SCP_IFSTART 0x0008
241 /* update sub commands -- issues are serialized priority to LSB */
242 #define SCP_UPD_FIRST 0x0100
243 #define SCP_UPD_STARTUP 0x0100
244 #define SCP_UPD_STARTJOIN 0x0200
245 #define SCP_UPD_PROMISC 0x0400
246 #define SCP_UPD_MCAST 0x0800
247 #define SCP_UPD_UPDATEPARAMS 0x1000
248 #define SCP_UPD_SHIFT 8
249 #define SCP_UPD_MASK 0xff00
251 /* these command (a subset of the update set) require timeout checking */
252 #define SCP_TIMOCHECK_CMD_MASK \
253 (SCP_UPD_UPDATEPARAMS | SCP_UPD_STARTUP | SCP_UPD_MCAST | \
258 IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_FH2, IFM_IEEE80211_ADHOC, 0)
260 IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_FH2, 0, 0)
262 typedef void (*ray_cmd_func_t
)(struct ray_softc
*);
264 #define SC_BUILD_5 0x5
265 #define SC_BUILD_4 0x55
268 #define RAY_AUTH_UNAUTH 0
269 #define RAY_AUTH_WAITING 1
270 #define RAY_AUTH_AUTH 2
271 #define RAY_AUTH_NEEDED 3
273 #define OPEN_AUTH_REQUEST 1
274 #define OPEN_AUTH_RESPONSE 2
275 #define BROADCAST_DEAUTH 0xc0
277 static int ray_alloc_ccs(struct ray_softc
*, bus_size_t
*, u_int
, u_int
);
278 static bus_size_t
ray_fill_in_tx_ccs(struct ray_softc
*, size_t,
280 static int ray_validate_config(struct pcmcia_config_entry
*);
281 static void ray_attach(device_t
, device_t
, void *);
282 static ray_cmd_func_t
ray_ccs_done(struct ray_softc
*, bus_size_t
);
283 static void ray_check_ccs(void *);
284 static void ray_check_scheduled(void *);
285 static void ray_cmd_cancel(struct ray_softc
*, int);
286 static void ray_cmd_schedule(struct ray_softc
*, int);
287 static void ray_cmd_ran(struct ray_softc
*, int);
288 static int ray_cmd_is_running(struct ray_softc
*, int);
289 static int ray_cmd_is_scheduled(struct ray_softc
*, int);
290 static void ray_cmd_done(struct ray_softc
*, int);
291 static int ray_detach(device_t
, int);
292 static int ray_activate(device_t
, enum devact
);
293 static void ray_disable(struct ray_softc
*);
294 static void ray_download_params(struct ray_softc
*);
295 static int ray_enable(struct ray_softc
*);
296 static u_int
ray_find_free_tx_ccs(struct ray_softc
*, u_int
);
297 static u_int8_t
ray_free_ccs(struct ray_softc
*, bus_size_t
);
298 static void ray_free_ccs_chain(struct ray_softc
*, u_int
);
299 static void ray_if_start(struct ifnet
*);
300 static void ray_if_stop(struct ifnet
*, int);
301 static int ray_init(struct ray_softc
*);
302 static int ray_intr(void *);
303 static void ray_intr_start(struct ray_softc
*);
304 static int ray_ioctl(struct ifnet
*, u_long
, void *);
305 static int ray_issue_cmd(struct ray_softc
*, bus_size_t
, u_int
);
306 static int ray_match(device_t
, cfdata_t
, void *);
307 static int ray_media_change(struct ifnet
*);
308 static void ray_media_status(struct ifnet
*, struct ifmediareq
*);
309 static ray_cmd_func_t
ray_rccs_intr(struct ray_softc
*, bus_size_t
);
310 static void ray_read_region(struct ray_softc
*, bus_size_t
,void *,size_t);
311 static void ray_recv(struct ray_softc
*, bus_size_t
);
312 static void ray_recv_auth(struct ray_softc
*, struct ieee80211_frame
*);
313 static void ray_report_params(struct ray_softc
*);
314 static void ray_reset(struct ray_softc
*);
315 static void ray_reset_resetloop(void *);
316 static int ray_send_auth(struct ray_softc
*, u_int8_t
*, u_int8_t
);
317 static void ray_set_pending(struct ray_softc
*, u_int
);
318 static int ray_simple_cmd(struct ray_softc
*, u_int
, u_int
);
319 static void ray_start_assoc(struct ray_softc
*);
320 static void ray_start_join_net(struct ray_softc
*);
321 static ray_cmd_func_t
ray_start_join_net_done(struct ray_softc
*,
322 u_int
, bus_size_t
, u_int
);
323 static void ray_start_join_timo(void *);
324 static void ray_stop(struct ray_softc
*);
325 static void ray_update_error_counters(struct ray_softc
*);
326 static void ray_update_mcast(struct ray_softc
*);
327 static ray_cmd_func_t
ray_update_params_done(struct ray_softc
*,
329 static void ray_update_params(struct ray_softc
*);
330 static void ray_update_promisc(struct ray_softc
*);
331 static void ray_update_subcmd(struct ray_softc
*);
332 static int ray_user_report_params(struct ray_softc
*,
333 struct ray_param_req
*);
334 static int ray_user_update_params(struct ray_softc
*,
335 struct ray_param_req
*);
336 static void ray_write_region(struct ray_softc
*,bus_size_t
,void *,size_t);
339 static void ray_update_siglev(struct ray_softc
*, u_int8_t
*, u_int8_t
);
343 static int ray_debug
= 0;
344 static int ray_debug_xmit_sum
= 0;
345 static int ray_debug_dump_desc
= 0;
346 static int ray_debug_dump_rx
= 0;
347 static int ray_debug_dump_tx
= 0;
348 static struct timeval rtv
, tv1
, tv2
, *ttp
, *ltp
;
349 #define RAY_DPRINTF(x) do { if (ray_debug) { \
350 struct timeval *ttmp; \
352 timersub(ttp, ltp, &rtv); \
353 ttmp = ttp; ttp = ltp; ltp = ttmp; \
354 printf("%ld:%ld %ld:%06ld: ", \
355 (long int)ttp->tv_sec, \
356 (long int)ttp->tv_usec, \
357 (long int)rtv.tv_sec, \
358 (long int)rtv.tv_usec); \
361 #define RAY_DPRINTF_XMIT(x) do { if (ray_debug_xmit_sum) { \
362 struct timeval *ttmp; \
364 timersub(ttp, ltp, &rtv); \
365 ttmp = ttp; ttp = ltp; ltp = ttmp; \
366 printf("%ld:%ld %ld:%06ld: ", \
367 (long int)ttp->tv_sec, \
368 (long int)ttp->tv_usec, \
369 (long int)rtv.tv_sec, \
370 (long int)rtv.tv_usec); \
374 #define HEXDF_NOCOMPRESS 0x1
375 #define HEXDF_NOOFFSET 0x2
376 #define HEXDF_NOASCII 0x4
377 void hexdump(const u_int8_t
*, int, int, int, int);
378 static void ray_dump_mbuf(struct ray_softc
*, struct mbuf
*);
380 #else /* !RAY_DEBUG */
382 #define RAY_DPRINTF(x)
383 #define RAY_DPRINTF_XMIT(x)
385 #endif /* !RAY_DEBUG */
388 * macros for writing to various regions in the mapped memory space
391 /* use already mapped ccrt */
392 #define REG_WRITE(sc, off, val) \
393 bus_space_write_1((sc)->sc_ccrt, (sc)->sc_ccrh, ((sc)->sc_ccroff + (off)), (val))
395 #define REG_READ(sc, off) \
396 bus_space_read_1((sc)->sc_ccrt, (sc)->sc_ccrh, ((sc)->sc_ccroff + (off)))
398 #define SRAM_READ_1(sc, off) \
399 ((u_int8_t)bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (off)))
401 #define SRAM_READ_FIELD_1(sc, off, s, f) \
402 SRAM_READ_1(sc, (off) + offsetof(struct s, f))
404 #define SRAM_READ_FIELD_2(sc, off, s, f) \
405 ((((u_int16_t)SRAM_READ_1(sc, (off) + offsetof(struct s, f)) << 8) \
406 |(SRAM_READ_1(sc, (off) + 1 + offsetof(struct s, f)))))
408 #define SRAM_READ_FIELD_N(sc, off, s, f, p, n) \
409 ray_read_region(sc, (off) + offsetof(struct s, f), (p), (n))
411 #define SRAM_WRITE_1(sc, off, val) \
412 bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (off), (val))
414 #define SRAM_WRITE_FIELD_1(sc, off, s, f, v) \
415 SRAM_WRITE_1(sc, (off) + offsetof(struct s, f), (v))
417 #define SRAM_WRITE_FIELD_2(sc, off, s, f, v) do { \
418 SRAM_WRITE_1(sc, (off) + offsetof(struct s, f), (((v) >> 8 ) & 0xff)); \
419 SRAM_WRITE_1(sc, (off) + 1 + offsetof(struct s, f), ((v) & 0xff)); \
422 #define SRAM_WRITE_FIELD_N(sc, off, s, f, p, n) \
423 ray_write_region(sc, (off) + offsetof(struct s, f), (p), (n))
426 * Macros of general usefulness
429 #define M_PULLUP(m, s) do { \
430 if ((m)->m_len < (s)) \
431 (m) = m_pullup((m), (s)); \
434 #define RAY_ECF_READY(sc) (!(REG_READ(sc, RAY_ECFIR) & RAY_ECSIR_IRQ))
435 #define RAY_ECF_START_CMD(sc) REG_WRITE(sc, RAY_ECFIR, RAY_ECSIR_IRQ)
436 #define RAY_GET_INDEX(ccs) (((ccs) - RAY_CCS_BASE) / RAY_CCS_SIZE)
437 #define RAY_GET_CCS(i) (RAY_CCS_BASE + (i) * RAY_CCS_SIZE)
443 static u_int8_t llc_snapid
[6] = { LLC_SNAP_LSAP
, LLC_SNAP_LSAP
, LLC_UI
, };
445 /* based on bit index in SCP_xx */
446 static ray_cmd_func_t ray_cmdtab
[] = {
447 ray_update_subcmd
, /* SCP_UPDATESUBCMD */
448 ray_start_assoc
, /* SCP_STARTASSOC */
449 ray_report_params
, /* SCP_REPORTPARAMS */
450 ray_intr_start
/* SCP_IFSTART */
452 static int ray_ncmdtab
= sizeof(ray_cmdtab
) / sizeof(*ray_cmdtab
);
454 static ray_cmd_func_t ray_subcmdtab
[] = {
455 ray_download_params
, /* SCP_UPD_STARTUP */
456 ray_start_join_net
, /* SCP_UPD_STARTJOIN */
457 ray_update_promisc
, /* SCP_UPD_PROMISC */
458 ray_update_mcast
, /* SCP_UPD_MCAST */
459 ray_update_params
/* SCP_UPD_UPDATEPARAMS */
461 static int ray_nsubcmdtab
= sizeof(ray_subcmdtab
) / sizeof(*ray_subcmdtab
);
463 /* autoconf information */
464 CFATTACH_DECL(ray
, sizeof(struct ray_softc
),
465 ray_match
, ray_attach
, ray_detach
, ray_activate
);
472 ray_match(device_t parent
, cfdata_t match
,
475 struct pcmcia_attach_args
*pa
= aux
;
479 /* initialize timestamp XXX */
485 return (pa
->manufacturer
== PCMCIA_VENDOR_RAYTHEON
486 && pa
->product
== PCMCIA_PRODUCT_RAYTHEON_WLAN
);
490 ray_validate_config(struct pcmcia_config_entry
*cfe
)
492 if (cfe
->iftype
!= PCMCIA_IFTYPE_IO
||
493 cfe
->num_memspace
!= 1 ||
494 cfe
->num_iospace
!= 0 ||
495 cfe
->memspace
[0].length
!= RAY_SRAM_MEM_SIZE
)
501 ray_attach(device_t parent
, device_t self
, void *aux
)
503 struct ray_softc
*sc
= (void *)self
;
504 struct pcmcia_attach_args
*pa
= aux
;
505 struct ifnet
*ifp
= &sc
->sc_if
;
506 struct pcmcia_config_entry
*cfe
;
507 struct ray_ecf_startup
*ep
;
513 error
= pcmcia_function_configure(pa
->pf
, ray_validate_config
);
515 aprint_error_dev(self
, "configure failed, error=%d\n",
521 sc
->sc_memt
= cfe
->memspace
[0].handle
.memt
;
522 sc
->sc_memh
= cfe
->memspace
[0].handle
.memh
;
524 callout_init(&sc
->sc_reset_resetloop_ch
, 0);
525 callout_init(&sc
->sc_disable_ch
, 0);
526 callout_init(&sc
->sc_start_join_timo_ch
, 0);
528 error
= ray_enable(sc
);
532 /* get startup results */
533 ep
= &sc
->sc_ecf_startup
;
534 ray_read_region(sc
, RAY_ECF_TO_HOST_BASE
, ep
,
535 sizeof(sc
->sc_ecf_startup
));
537 /* check to see that card initialized properly */
538 if (ep
->e_status
!= RAY_ECFS_CARD_OK
) {
539 aprint_error_dev(self
, "card failed self test: status %d\n",
540 sc
->sc_ecf_startup
.e_status
);
544 /* check firmware version */
545 if (sc
->sc_version
!= SC_BUILD_4
&& sc
->sc_version
!= SC_BUILD_5
) {
546 aprint_error_dev(self
, "unsupported firmware version %d\n",
547 ep
->e_fw_build_string
);
551 /* clear any interrupt if present */
552 REG_WRITE(sc
, RAY_HCSIR
, 0);
555 * set the parameters that will survive stop/init
557 memset(&sc
->sc_dnwid
, 0, sizeof(sc
->sc_dnwid
));
558 sc
->sc_dnwid
.i_len
= strlen(RAY_DEF_NWID
);
559 if (sc
->sc_dnwid
.i_len
> IEEE80211_NWID_LEN
)
560 sc
->sc_dnwid
.i_len
= IEEE80211_NWID_LEN
;
561 if (sc
->sc_dnwid
.i_len
> 0)
562 memcpy(sc
->sc_dnwid
.i_nwid
, RAY_DEF_NWID
, sc
->sc_dnwid
.i_len
);
563 memcpy(&sc
->sc_cnwid
, &sc
->sc_dnwid
, sizeof(sc
->sc_cnwid
));
564 sc
->sc_omode
= sc
->sc_mode
= RAY_MODE_DEFAULT
;
565 sc
->sc_countrycode
= sc
->sc_dcountrycode
=
566 RAY_PID_COUNTRY_CODE_DEFAULT
;
569 * attach the interface
571 /* The version isn't the most accurate way, but it's easy. */
572 aprint_normal_dev(self
, "firmware version %d\n",
574 if (sc
->sc_version
!= SC_BUILD_4
)
575 aprint_normal_dev(self
, "supported rates %0x:%0x:%0x:%0x:%0x:%0x:%0x:%0x\n",
576 ep
->e_rates
[0], ep
->e_rates
[1],
577 ep
->e_rates
[2], ep
->e_rates
[3], ep
->e_rates
[4],
578 ep
->e_rates
[5], ep
->e_rates
[6], ep
->e_rates
[7]);
579 aprint_normal_dev(self
, "802.11 address %s\n",
580 ether_sprintf(ep
->e_station_addr
));
582 memcpy(ifp
->if_xname
, device_xname(self
), IFNAMSIZ
);
584 ifp
->if_start
= ray_if_start
;
585 ifp
->if_stop
= ray_if_stop
;
586 ifp
->if_ioctl
= ray_ioctl
;
587 ifp
->if_mtu
= ETHERMTU
;
588 ifp
->if_flags
= IFF_BROADCAST
|IFF_SIMPLEX
|IFF_MULTICAST
;
589 IFQ_SET_READY(&ifp
->if_snd
);
592 ether_ifattach(ifp
, ep
->e_station_addr
);
593 /* need enough space for ieee80211_header + (snap or e2) */
595 sizeof(struct ieee80211_frame
) + sizeof(struct ether_header
);
597 ifmedia_init(&sc
->sc_media
, 0, ray_media_change
, ray_media_status
);
598 ifmedia_add(&sc
->sc_media
, IFM_ADHOC
, 0, 0);
599 ifmedia_add(&sc
->sc_media
, IFM_INFRA
, 0, 0);
600 if (sc
->sc_mode
== SC_MODE_ADHOC
)
601 ifmedia_set(&sc
->sc_media
, IFM_ADHOC
);
603 ifmedia_set(&sc
->sc_media
, IFM_INFRA
);
605 if (pmf_device_register(self
, NULL
, NULL
))
606 pmf_class_network_register(self
, ifp
);
608 aprint_error_dev(self
, "couldn't establish power handler\n");
610 /* The attach is successful. */
618 pcmcia_function_unconfigure(pa
->pf
);
622 ray_activate(device_t self
, enum devact act
)
624 struct ray_softc
*sc
= device_private(self
);
625 struct ifnet
*ifp
= &sc
->sc_if
;
627 RAY_DPRINTF(("%s: activate\n", device_xname(self
)));
630 case DVACT_DEACTIVATE
:
639 ray_detach(device_t self
, int flags
)
641 struct ray_softc
*sc
;
644 sc
= device_private(self
);
646 RAY_DPRINTF(("%s: detach\n", device_xname(&sc
->sc_dev
)));
648 if (!sc
->sc_attached
)
651 pmf_device_deregister(self
);
653 if (sc
->sc_if
.if_flags
& IFF_UP
)
656 ifmedia_delete_instance(&sc
->sc_media
, IFM_INST_ANY
);
660 pcmcia_function_unconfigure(sc
->sc_pf
);
666 * start the card running
669 ray_enable(struct ray_softc
*sc
)
673 RAY_DPRINTF(("%s: enable\n", device_xname(&sc
->sc_dev
)));
675 sc
->sc_ih
= pcmcia_intr_establish(sc
->sc_pf
, IPL_NET
,
680 error
= ray_init(sc
);
682 pcmcia_intr_disestablish(sc
->sc_pf
, sc
->sc_ih
);
690 * stop the card running
693 ray_disable(struct ray_softc
*sc
)
695 RAY_DPRINTF(("%s: disable\n", device_xname(&sc
->sc_dev
)));
699 sc
->sc_resetloop
= 0;
700 sc
->sc_rxoverflow
= 0;
706 pcmcia_intr_disestablish(sc
->sc_pf
, sc
->sc_ih
);
712 * start the card running
715 ray_init(struct ray_softc
*sc
)
717 struct ray_ecf_startup
*ep
;
721 RAY_DPRINTF(("%s: init\n", device_xname(&sc
->sc_dev
)));
723 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
))
726 if (pcmcia_function_enable(sc
->sc_pf
))
729 RAY_DPRINTF(("%s: init post-enable\n", device_xname(&sc
->sc_dev
)));
731 /* reset some values */
732 memset(sc
->sc_ccsinuse
, 0, sizeof(sc
->sc_ccsinuse
));
734 memset(sc
->sc_bssid
, 0, sizeof(sc
->sc_bssid
));
735 sc
->sc_deftxrate
= 0;
739 sc
->sc_scheduled
= 0;
741 sc
->sc_txfree
= RAY_CCS_NTX
;
742 sc
->sc_checkcounters
= 0;
743 sc
->sc_authstate
= RAY_AUTH_UNAUTH
;
745 /* get startup results */
746 ep
= &sc
->sc_ecf_startup
;
747 ray_read_region(sc
, RAY_ECF_TO_HOST_BASE
, ep
,
748 sizeof(sc
->sc_ecf_startup
));
750 /* check to see that card initialized properly */
751 if (ep
->e_status
!= RAY_ECFS_CARD_OK
) {
752 pcmcia_function_disable(sc
->sc_pf
);
753 printf("%s: card failed self test: status %d\n",
754 device_xname(&sc
->sc_dev
), sc
->sc_ecf_startup
.e_status
);
758 /* fixup tib size to be correct */
759 if (sc
->sc_version
== SC_BUILD_4
&& sc
->sc_tibsize
== 0x55)
761 sc
->sc_txpad
= sc
->sc_tibsize
;
763 /* set all ccs to be free */
764 ccs
= RAY_GET_CCS(0);
765 for (i
= 0; i
< RAY_CCS_LAST
; ccs
+= RAY_CCS_SIZE
, i
++)
766 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_status
,
767 RAY_CCS_STATUS_FREE
);
769 /* clear the interrupt if present */
770 REG_WRITE(sc
, RAY_HCSIR
, 0);
772 callout_init(&sc
->sc_check_ccs_ch
, 0);
773 callout_init(&sc
->sc_check_scheduled_ch
, 0);
775 /* we are now up and running -- and are busy until download is cplt */
776 sc
->sc_if
.if_flags
|= IFF_RUNNING
| IFF_OACTIVE
;
778 /* set this now so it gets set in the download */
779 if (sc
->sc_if
.if_flags
& IFF_ALLMULTI
)
780 sc
->sc_if
.if_flags
|= IFF_PROMISC
;
781 else if (sc
->sc_if
.if_pcount
== 0)
782 sc
->sc_if
.if_flags
&= ~IFF_PROMISC
;
783 sc
->sc_promisc
= !!(sc
->sc_if
.if_flags
& IFF_PROMISC
);
785 /* call after we mark ourselves running */
786 ray_download_params(sc
);
792 * stop the card running
795 ray_stop(struct ray_softc
*sc
)
797 RAY_DPRINTF(("%s: stop\n", device_xname(&sc
->sc_dev
)));
799 callout_stop(&sc
->sc_check_ccs_ch
);
800 sc
->sc_timocheck
= 0;
802 callout_stop(&sc
->sc_check_scheduled_ch
);
806 sc
->sc_repreq
->r_failcause
= RAY_FAILCAUSE_EDEVSTOP
;
807 wakeup(ray_report_params
);
810 sc
->sc_updreq
->r_failcause
= RAY_FAILCAUSE_EDEVSTOP
;
811 wakeup(ray_update_params
);
814 sc
->sc_if
.if_flags
&= ~IFF_RUNNING
;
815 pcmcia_function_disable(sc
->sc_pf
);
822 ray_reset(struct ray_softc
*sc
)
824 if (++sc
->sc_resetloop
>= RAY_MAX_RESETS
) {
825 if (sc
->sc_resetloop
== RAY_MAX_RESETS
) {
826 aprint_error_dev(&sc
->sc_dev
, "unable to correct, disabling\n");
827 callout_stop(&sc
->sc_reset_resetloop_ch
);
828 callout_reset(&sc
->sc_disable_ch
, 1,
829 (void (*)(void *))ray_disable
, sc
);
832 aprint_error_dev(&sc
->sc_dev
, "unexpected failure resetting hw [%d more]\n",
833 RAY_MAX_RESETS
- sc
->sc_resetloop
);
834 callout_stop(&sc
->sc_reset_resetloop_ch
);
836 callout_reset(&sc
->sc_reset_resetloop_ch
, 30 * hz
,
837 ray_reset_resetloop
, sc
);
842 * return resetloop to zero (enough time has expired to allow user to
843 * disable a whacked interface) the main reason for all this nonesense
844 * is that resets take ~2 seconds and currently the pcmcia code spins
848 ray_reset_resetloop(void *arg
)
850 struct ray_softc
*sc
;
853 sc
->sc_resetloop
= 0;
857 ray_ioctl(struct ifnet
*ifp
, u_long cmd
, void *data
)
859 struct ieee80211_nwid nwid
;
860 struct ray_param_req pr
;
861 struct ray_softc
*sc
;
864 int error
, error2
, s
, i
;
869 ifr
= (struct ifreq
*)data
;
873 RAY_DPRINTF(("%s: ioctl: cmd 0x%lx data 0x%lx\n", ifp
->if_xname
,
877 RAY_DPRINTF(("%s: ioctl: cmd SIOCINITIFADDR\n", ifp
->if_xname
));
878 if ((ifp
->if_flags
& IFF_RUNNING
) == 0)
879 if ((error
= ray_enable(sc
)))
881 ifp
->if_flags
|= IFF_UP
;
882 ifa
= (struct ifaddr
*)data
;
883 switch (ifa
->ifa_addr
->sa_family
) {
886 arp_ifinit(&sc
->sc_if
, ifa
);
894 RAY_DPRINTF(("%s: ioctl: cmd SIOCSIFFLAGS\n", ifp
->if_xname
));
895 if ((error
= ifioctl_common(ifp
, cmd
, data
)) != 0)
897 if (ifp
->if_flags
& IFF_UP
) {
898 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
899 if ((error
= ray_enable(sc
)))
902 ray_update_promisc(sc
);
903 } else if (ifp
->if_flags
& IFF_RUNNING
)
907 RAY_DPRINTF(("%s: ioctl: cmd SIOCADDMULTI\n", ifp
->if_xname
));
909 if (cmd
== SIOCDELMULTI
)
910 RAY_DPRINTF(("%s: ioctl: cmd SIOCDELMULTI\n",
912 if ((error
= ether_ioctl(ifp
, cmd
, data
)) == ENETRESET
) {
913 if (ifp
->if_flags
& IFF_RUNNING
)
914 ray_update_mcast(sc
);
919 RAY_DPRINTF(("%s: ioctl: cmd SIOCSIFMEDIA\n", ifp
->if_xname
));
921 if (cmd
== SIOCGIFMEDIA
)
922 RAY_DPRINTF(("%s: ioctl: cmd SIOCGIFMEDIA\n",
924 error
= ifmedia_ioctl(ifp
, ifr
, &sc
->sc_media
, cmd
);
927 RAY_DPRINTF(("%s: ioctl: cmd SIOCSRAYPARAM\n", ifp
->if_xname
));
928 if ((error
= copyin(ifr
->ifr_data
, &pr
, sizeof(pr
))))
930 /* disallow certain command that have another interface */
931 switch (pr
.r_paramid
) {
932 case RAY_PID_NET_TYPE
: /* through media opt */
933 case RAY_PID_AP_STATUS
: /* unsupported */
934 case RAY_PID_SSID
: /* use SIOC80211[GS]NWID */
935 case RAY_PID_MAC_ADDR
: /* XXX need interface? */
936 case RAY_PID_PROMISC
: /* bpf */
940 error
= ray_user_update_params(sc
, &pr
);
941 error2
= copyout(&pr
, ifr
->ifr_data
, sizeof(pr
));
942 error
= error2
? error2
: error
;
945 RAY_DPRINTF(("%s: ioctl: cmd SIOCGRAYPARAM\n", ifp
->if_xname
));
946 if ((error
= copyin(ifr
->ifr_data
, &pr
, sizeof(pr
))))
948 error
= ray_user_report_params(sc
, &pr
);
949 error2
= copyout(&pr
, ifr
->ifr_data
, sizeof(pr
));
950 error
= error2
? error2
: error
;
953 RAY_DPRINTF(("%s: ioctl: cmd SIOCS80211NWID\n", ifp
->if_xname
));
955 * if later people overwrite thats ok -- the latest version
956 * will always get start/joined even if it was set by
959 if ((error
= copyin(ifr
->ifr_data
, &nwid
, sizeof(nwid
))))
961 if (nwid
.i_len
> IEEE80211_NWID_LEN
) {
965 /* clear trailing garbages */
966 for (i
= nwid
.i_len
; i
< IEEE80211_NWID_LEN
; i
++)
968 if (!memcmp(&sc
->sc_dnwid
, &nwid
, sizeof(nwid
)))
970 memcpy(&sc
->sc_dnwid
, &nwid
, sizeof(nwid
));
971 if (ifp
->if_flags
& IFF_RUNNING
)
972 ray_start_join_net(sc
);
975 RAY_DPRINTF(("%s: ioctl: cmd SIOCG80211NWID\n", ifp
->if_xname
));
976 error
= copyout(&sc
->sc_cnwid
, ifr
->ifr_data
,
977 sizeof(sc
->sc_cnwid
));
981 error
= copyout(sc
->sc_siglevs
, ifr
->ifr_data
,
982 sizeof sc
->sc_siglevs
);
986 RAY_DPRINTF(("%s: ioctl: unknown\n", ifp
->if_xname
));
987 error
= ether_ioctl(ifp
, cmd
, data
);
991 RAY_DPRINTF(("%s: ioctl: returns %d\n", ifp
->if_xname
, error
));
999 * ifnet interface to start transmission on the interface
1002 ray_if_start(struct ifnet
*ifp
)
1004 struct ray_softc
*sc
;
1011 ray_if_stop(struct ifnet
*ifp
, int disable
)
1013 struct ray_softc
*sc
= ifp
->if_softc
;
1019 ray_media_change(struct ifnet
*ifp
)
1021 struct ray_softc
*sc
;
1024 RAY_DPRINTF(("%s: media change cur %d\n", ifp
->if_xname
,
1025 sc
->sc_media
.ifm_cur
->ifm_media
));
1026 if (sc
->sc_media
.ifm_cur
->ifm_media
& IFM_IEEE80211_ADHOC
)
1027 sc
->sc_mode
= SC_MODE_ADHOC
;
1029 sc
->sc_mode
= SC_MODE_INFRA
;
1030 if (sc
->sc_mode
!= sc
->sc_omode
)
1031 ray_start_join_net(sc
);
1036 ray_media_status(struct ifnet
*ifp
, struct ifmediareq
*imr
)
1038 struct ray_softc
*sc
;
1042 RAY_DPRINTF(("%s: media status\n", ifp
->if_xname
));
1044 imr
->ifm_status
= IFM_AVALID
;
1046 imr
->ifm_status
|= IFM_ACTIVE
;
1048 if (sc
->sc_mode
== SC_MODE_ADHOC
)
1049 imr
->ifm_active
= IFM_ADHOC
;
1051 imr
->ifm_active
= IFM_INFRA
;
1055 * called to start from ray_intr. We don't check for pending
1056 * interrupt as a result
1059 ray_intr_start(struct ray_softc
*sc
)
1061 struct ieee80211_frame
*iframe
;
1062 struct ether_header
*eh
;
1063 size_t len
, pktlen
, tmplen
;
1064 bus_size_t bufp
, ebufp
;
1065 struct mbuf
*m0
, *m
;
1067 u_int firsti
, hinti
, previ
, i
, pcount
;
1073 RAY_DPRINTF(("%s: start free %d\n",
1074 ifp
->if_xname
, sc
->sc_txfree
));
1076 ray_cmd_cancel(sc
, SCP_IFSTART
);
1078 if ((ifp
->if_flags
& IFF_RUNNING
) == 0 || !sc
->sc_havenet
)
1081 if (IFQ_IS_EMPTY(&ifp
->if_snd
))
1084 firsti
= i
= previ
= RAY_CCS_LINK_NULL
;
1085 hinti
= RAY_CCS_TX_FIRST
;
1087 if (!RAY_ECF_READY(sc
)) {
1088 ray_cmd_schedule(sc
, SCP_IFSTART
);
1092 /* Check to see if we need to authenticate before sending packets. */
1093 if (sc
->sc_authstate
== RAY_AUTH_NEEDED
) {
1094 RAY_DPRINTF(("%s: Sending auth request.\n", ifp
->if_xname
));
1095 sc
->sc_authstate
= RAY_AUTH_WAITING
;
1096 ray_send_auth(sc
, sc
->sc_authid
, OPEN_AUTH_REQUEST
);
1102 /* if we have no descriptors be done */
1103 if (i
== RAY_CCS_LINK_NULL
) {
1104 i
= ray_find_free_tx_ccs(sc
, hinti
);
1105 if (i
== RAY_CCS_LINK_NULL
) {
1106 RAY_DPRINTF(("%s: no descriptors.\n",
1108 ifp
->if_flags
|= IFF_OACTIVE
;
1113 IFQ_DEQUEUE(&ifp
->if_snd
, m0
);
1115 RAY_DPRINTF(("%s: dry queue.\n", ifp
->if_xname
));
1118 RAY_DPRINTF(("%s: gotmbuf 0x%lx\n", ifp
->if_xname
, (long)m0
));
1119 pktlen
= m0
->m_pkthdr
.len
;
1120 if (pktlen
> ETHER_MAX_LEN
- ETHER_CRC_LEN
) {
1122 "%s: mbuf too long %ld\n", ifp
->if_xname
,
1128 RAY_DPRINTF(("%s: mbuf.m_pkthdr.len %d\n", ifp
->if_xname
,
1131 /* we need the ether_header now for pktlen adjustments */
1132 M_PULLUP(m0
, sizeof(struct ether_header
));
1134 RAY_DPRINTF(( "%s: couldn\'t pullup ether header\n",
1139 RAY_DPRINTF(("%s: got pulled up mbuf 0x%lx\n", ifp
->if_xname
,
1142 /* first peek at the type of packet and figure out what to do */
1143 eh
= mtod(m0
, struct ether_header
*);
1144 et
= ntohs(eh
->ether_type
);
1145 if (ifp
->if_flags
& IFF_LINK0
) {
1146 /* don't support llc for windows compat operation */
1147 if (et
<= ETHERMTU
) {
1152 tmplen
= sizeof(struct ieee80211_frame
);
1153 } else if (et
> ETHERMTU
) {
1154 /* adjust for LLC/SNAP header */
1155 tmplen
= sizeof(struct ieee80211_frame
) - ETHER_ADDR_LEN
;
1159 /* now get our space for the 802.11 frame */
1160 M_PREPEND(m0
, tmplen
, M_DONTWAIT
);
1162 M_PULLUP(m0
, sizeof(struct ether_header
) + tmplen
);
1164 RAY_DPRINTF(("%s: couldn\'t prepend header\n",
1169 /* copy the frame into the mbuf for tapping */
1170 iframe
= mtod(m0
, struct ieee80211_frame
*);
1171 eh
= (struct ether_header
*)((u_int8_t
*)iframe
+ tmplen
);
1173 (IEEE80211_FC0_VERSION_0
| IEEE80211_FC0_TYPE_DATA
);
1174 if (sc
->sc_mode
== SC_MODE_ADHOC
) {
1175 iframe
->i_fc
[1] = IEEE80211_FC1_DIR_NODS
;
1176 memcpy(iframe
->i_addr1
, eh
->ether_dhost
,ETHER_ADDR_LEN
);
1177 memcpy(iframe
->i_addr2
, eh
->ether_shost
,ETHER_ADDR_LEN
);
1178 memcpy(iframe
->i_addr3
, sc
->sc_bssid
, ETHER_ADDR_LEN
);
1180 iframe
->i_fc
[1] = IEEE80211_FC1_DIR_TODS
;
1181 memcpy(iframe
->i_addr1
, sc
->sc_bssid
,ETHER_ADDR_LEN
);
1182 memcpy(iframe
->i_addr2
, eh
->ether_shost
,ETHER_ADDR_LEN
);
1183 memmove(iframe
->i_addr3
,eh
->ether_dhost
,ETHER_ADDR_LEN
);
1185 iframe
->i_dur
[0] = iframe
->i_dur
[1] = 0;
1186 iframe
->i_seq
[0] = iframe
->i_seq
[1] = 0;
1188 /* if not using crummy E2 in 802.11 make it LLC/SNAP */
1189 if ((ifp
->if_flags
& IFF_LINK0
) == 0 && et
> ETHERMTU
)
1190 memcpy(iframe
+ 1, llc_snapid
, sizeof(llc_snapid
));
1192 RAY_DPRINTF(("%s: i %d previ %d\n", ifp
->if_xname
, i
, previ
));
1194 if (firsti
== RAY_CCS_LINK_NULL
)
1197 pktlen
= m0
->m_pkthdr
.len
;
1198 bufp
= ray_fill_in_tx_ccs(sc
, pktlen
, i
, previ
);
1200 i
= RAY_CCS_LINK_NULL
;
1202 RAY_DPRINTF(("%s: bufp 0x%lx new pktlen %d\n",
1203 ifp
->if_xname
, (long)bufp
, (int)pktlen
));
1206 for (m
= m0
; m
; m
= m
->m_next
) {
1207 if ((len
= m
->m_len
) == 0)
1210 "%s: copying mbuf 0x%lx bufp 0x%lx len %d\n",
1211 ifp
->if_xname
, (long)m
, (long)bufp
, (int)len
));
1212 d
= mtod(m
, u_int8_t
*);
1214 if (ebufp
<= RAY_TX_END
)
1215 ray_write_region(sc
, bufp
, d
, len
);
1217 panic("ray_intr_start"); /* XXX */
1219 tmplen
= ebufp
- bufp
;
1221 ray_write_region(sc
, bufp
, d
, tmplen
);
1224 ray_write_region(sc
, bufp
, d
, len
);
1230 if (ifp
->if_flags
& IFF_LINK0
) {
1231 m0
->m_data
+= sizeof(struct ieee80211_frame
);
1232 m0
->m_len
-= sizeof(struct ieee80211_frame
);
1233 m0
->m_pkthdr
.len
-= sizeof(struct ieee80211_frame
);
1235 bpf_mtap(ifp
->if_bpf
, m0
);
1236 if (ifp
->if_flags
& IFF_LINK0
) {
1237 m0
->m_data
-= sizeof(struct ieee80211_frame
);
1238 m0
->m_len
+= sizeof(struct ieee80211_frame
);
1239 m0
->m_pkthdr
.len
+= sizeof(struct ieee80211_frame
);
1245 if (ray_debug
&& ray_debug_dump_tx
)
1246 ray_dump_mbuf(sc
, m0
);
1251 RAY_DPRINTF_XMIT(("%s: sent packet: len %ld\n", device_xname(&sc
->sc_dev
),
1255 if (firsti
== RAY_CCS_LINK_NULL
)
1258 if (!RAY_ECF_READY(sc
)) {
1260 * if this can really happen perhaps we need to save
1261 * the chain and use it later. I think this might
1262 * be a confused state though because we check above
1263 * and don't issue any commands between.
1265 printf("%s: dropping tx packets device busy\n", device_xname(&sc
->sc_dev
));
1266 ray_free_ccs_chain(sc
, firsti
);
1267 ifp
->if_oerrors
+= pcount
;
1272 RAY_DPRINTF(("%s: ray_start issuing %d \n", device_xname(&sc
->sc_dev
), firsti
));
1273 SRAM_WRITE_1(sc
, RAY_SCB_CCSI
, firsti
);
1274 RAY_ECF_START_CMD(sc
);
1276 ifp
->if_opackets
+= pcount
;
1280 * recevice a packet from the card
1283 ray_recv(struct ray_softc
*sc
, bus_size_t ccs
)
1285 struct ieee80211_frame
*frame
;
1286 struct ether_header
*eh
;
1288 size_t pktlen
, fudge
, len
, lenread
= 0;
1289 bus_size_t bufp
, ebufp
, tmp
;
1292 u_int frag
= 0, ni
, i
, issnap
, first
;
1294 #ifdef RAY_DO_SIGLEV
1299 /* have a look if you want to see how the card rx works :) */
1300 if (ray_debug
&& ray_debug_dump_desc
)
1301 hexdump((char *)sc
->sc_memh
+ RAY_RCS_BASE
, 0x400,
1309 * If we're expecting the E2-in-802.11 encapsulation that the
1310 * WebGear Windows driver produces, fudge the packet forward
1311 * in the mbuf by 2 bytes so that the payload after the
1312 * Ethernet header will be aligned. If we end up getting a
1313 * packet that's not of this type, we'll just drop it anyway.
1315 if (ifp
->if_flags
& IFF_LINK0
)
1320 /* it looks like at least with build 4 there is no CRC in length */
1321 first
= RAY_GET_INDEX(ccs
);
1322 pktlen
= SRAM_READ_FIELD_2(sc
, ccs
, ray_cmd_rx
, c_pktlen
);
1323 #ifdef RAY_DO_SIGLEV
1324 siglev
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_rx
, c_siglev
);
1327 RAY_DPRINTF(("%s: recv pktlen %ld frag %d\n", device_xname(&sc
->sc_dev
),
1328 (u_long
)pktlen
, frag
));
1329 RAY_DPRINTF_XMIT(("%s: received packet: len %ld\n", device_xname(&sc
->sc_dev
),
1331 if (pktlen
> MCLBYTES
|| pktlen
< sizeof(*frame
)) {
1332 RAY_DPRINTF(("%s: PKTLEN TOO BIG OR TOO SMALL\n",
1333 device_xname(&sc
->sc_dev
)));
1337 MGETHDR(m
, M_DONTWAIT
, MT_DATA
);
1339 RAY_DPRINTF(("%s: MGETHDR FAILED\n", device_xname(&sc
->sc_dev
)));
1343 if ((pktlen
+ fudge
) > MHLEN
) {
1344 /* XXX should allow chaining? */
1345 MCLGET(m
, M_DONTWAIT
);
1346 if ((m
->m_flags
& M_EXT
) == 0) {
1347 RAY_DPRINTF(("%s: MCLGET FAILED\n", device_xname(&sc
->sc_dev
)));
1354 m
->m_pkthdr
.rcvif
= ifp
;
1355 m
->m_pkthdr
.len
= pktlen
;
1358 d
= mtod(m
, u_int8_t
*);
1360 RAY_DPRINTF(("%s: recv ccs index %d\n", device_xname(&sc
->sc_dev
), first
));
1362 while ((i
= ni
) && i
!= RAY_CCS_LINK_NULL
) {
1363 ccs
= RAY_GET_CCS(i
);
1364 bufp
= SRAM_READ_FIELD_2(sc
, ccs
, ray_cmd_rx
, c_bufp
);
1365 len
= SRAM_READ_FIELD_2(sc
, ccs
, ray_cmd_rx
, c_len
);
1366 /* remove the CRC */
1368 /* at least with build 4 no crc seems to be here */
1372 ni
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_rx
, c_nextfrag
);
1374 "%s: recv frag index %d len %ld bufp 0x%llx ni %d\n",
1375 device_xname(&sc
->sc_dev
), i
, (u_long
)len
, (unsigned long long)bufp
,
1377 if (len
+ lenread
> pktlen
) {
1378 RAY_DPRINTF(("%s: BAD LEN current 0x%lx pktlen 0x%lx\n",
1379 device_xname(&sc
->sc_dev
), (u_long
)(len
+ lenread
),
1386 if (i
< RAY_RCCS_FIRST
) {
1387 printf("ray_recv: bad ccs index 0x%x\n", i
);
1394 if (ebufp
<= RAY_RX_END
)
1395 ray_read_region(sc
, bufp
, d
, len
);
1398 ray_read_region(sc
, bufp
, d
, (tmp
= RAY_RX_END
- bufp
));
1399 ray_read_region(sc
, RAY_RX_BASE
, d
+ tmp
, ebufp
- RAY_RX_END
);
1406 RAY_DPRINTF(("%s: recv frag count %d\n", device_xname(&sc
->sc_dev
), frag
));
1410 while ((i
= ni
) && (i
!= RAY_CCS_LINK_NULL
)) {
1411 ccs
= RAY_GET_CCS(i
);
1412 ni
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_rx
, c_nextfrag
);
1413 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_status
,
1414 RAY_CCS_STATUS_FREE
);
1420 RAY_DPRINTF(("%s: recv got packet pktlen %ld actual %ld\n",
1421 device_xname(&sc
->sc_dev
), (u_long
)pktlen
, (u_long
)lenread
));
1423 if (ray_debug
&& ray_debug_dump_rx
)
1424 ray_dump_mbuf(sc
, m
);
1426 /* receivce the packet */
1427 frame
= mtod(m
, struct ieee80211_frame
*);
1428 fc0
= frame
->i_fc
[0]
1429 & (IEEE80211_FC0_VERSION_MASK
|IEEE80211_FC0_TYPE_MASK
);
1430 if ((fc0
& IEEE80211_FC0_VERSION_MASK
) != IEEE80211_FC0_VERSION_0
) {
1431 RAY_DPRINTF(("%s: pkt not version 0 fc 0x%x\n",
1432 device_xname(&sc
->sc_dev
), fc0
));
1436 if ((fc0
& IEEE80211_FC0_TYPE_MASK
) == IEEE80211_FC0_TYPE_MGT
) {
1437 switch (frame
->i_fc
[0] & IEEE80211_FC0_SUBTYPE_MASK
) {
1438 case IEEE80211_FC0_SUBTYPE_BEACON
:
1439 /* Ignore beacon silently. */
1441 case IEEE80211_FC0_SUBTYPE_AUTH
:
1442 ray_recv_auth(sc
, frame
);
1444 case IEEE80211_FC0_SUBTYPE_DEAUTH
:
1445 sc
->sc_authstate
= RAY_AUTH_UNAUTH
;
1448 RAY_DPRINTF(("%s: mgt packet not supported\n",
1449 device_xname(&sc
->sc_dev
)));
1451 hexdump((const u_int8_t
*)frame
, pktlen
, 16, 4, 0);
1453 RAY_DPRINTF(("\n"));
1458 } else if ((fc0
& IEEE80211_FC0_TYPE_MASK
) != IEEE80211_FC0_TYPE_DATA
) {
1459 RAY_DPRINTF(("%s: pkt not type data fc0 0x%x\n",
1460 device_xname(&sc
->sc_dev
), fc0
));
1465 if (pktlen
< sizeof(*frame
) + sizeof(struct llc
)) {
1466 RAY_DPRINTF(("%s: pkt too small for llc (%ld)\n",
1467 device_xname(&sc
->sc_dev
), (u_long
)pktlen
));
1472 if (!memcmp(frame
+ 1, llc_snapid
, sizeof(llc_snapid
)))
1476 * if user has link0 flag set we allow the weird
1477 * Ethernet2 in 802.11 encapsulation produced by
1478 * the windows driver for the WebGear card
1480 RAY_DPRINTF(("%s: pkt not snap 0\n", device_xname(&sc
->sc_dev
)));
1481 if ((ifp
->if_flags
& IFF_LINK0
) == 0) {
1487 switch (frame
->i_fc
[1] & IEEE80211_FC1_DIR_MASK
) {
1488 case IEEE80211_FC1_DIR_NODS
:
1489 src
= frame
->i_addr2
;
1491 case IEEE80211_FC1_DIR_FROMDS
:
1492 src
= frame
->i_addr3
;
1494 case IEEE80211_FC1_DIR_TODS
:
1495 RAY_DPRINTF(("%s: pkt ap2ap\n", device_xname(&sc
->sc_dev
)));
1499 RAY_DPRINTF(("%s: pkt type unknown\n", device_xname(&sc
->sc_dev
)));
1504 #ifdef RAY_DO_SIGLEV
1505 ray_update_siglev(sc
, src
, siglev
);
1509 * This is a mess.. we should support other LLC frame types
1512 /* create an ether_header over top of the 802.11+SNAP header */
1513 eh
= (struct ether_header
*)((char *)(frame
+ 1) - 6);
1514 memcpy(eh
->ether_shost
, src
, ETHER_ADDR_LEN
);
1515 memcpy(eh
->ether_dhost
, frame
->i_addr1
, ETHER_ADDR_LEN
);
1517 /* this is the weird e2 in 802.11 encapsulation */
1518 eh
= (struct ether_header
*)(frame
+ 1);
1520 m_adj(m
, (char *)eh
- (char *)frame
);
1523 bpf_mtap(ifp
->if_bpf
, m
);
1525 /* XXX doesn't appear to be included m->m_flags |= M_HASFCS; */
1527 (*ifp
->if_input
)(ifp
, m
);
1531 * receive an auth packet
1534 ray_recv_auth(struct ray_softc
*sc
, struct ieee80211_frame
*frame
)
1536 u_int8_t
*var
= (u_int8_t
*)(frame
+ 1);
1538 if (sc
->sc_mode
== SC_MODE_ADHOC
) {
1539 RAY_DPRINTF(("%s: recv auth packet:\n", device_xname(&sc
->sc_dev
)));
1541 hexdump((const u_int8_t
*)frame
, sizeof(*frame
) + 6, 16, 4, 0);
1543 RAY_DPRINTF(("\n"));
1545 if (var
[2] == OPEN_AUTH_REQUEST
) {
1546 RAY_DPRINTF(("%s: Sending authentication response.\n",
1547 device_xname(&sc
->sc_dev
)));
1548 if (ray_send_auth(sc
, frame
->i_addr2
,
1549 OPEN_AUTH_RESPONSE
) == 0) {
1550 sc
->sc_authstate
= RAY_AUTH_NEEDED
;
1551 memcpy(sc
->sc_authid
, frame
->i_addr2
,
1554 } else if (var
[2] == OPEN_AUTH_RESPONSE
) {
1555 RAY_DPRINTF(("%s: Authenticated!\n",
1556 device_xname(&sc
->sc_dev
)));
1557 sc
->sc_authstate
= RAY_AUTH_AUTH
;
1563 * send an auth packet
1566 ray_send_auth(struct ray_softc
*sc
, u_int8_t
*dest
, u_int8_t auth_type
)
1568 u_int8_t packet
[sizeof(struct ieee80211_frame
) + ETHER_ADDR_LEN
], *var
;
1569 struct ieee80211_frame
*frame
;
1573 ccsindex
= ray_find_free_tx_ccs(sc
, RAY_CCS_TX_FIRST
);
1574 if (ccsindex
== RAY_CCS_LINK_NULL
) {
1575 RAY_DPRINTF(("%s: send auth failed -- no free tx slots\n",
1576 device_xname(&sc
->sc_dev
)));
1580 bufp
= ray_fill_in_tx_ccs(sc
, sizeof(packet
), ccsindex
,
1582 frame
= (struct ieee80211_frame
*) packet
;
1583 frame
->i_fc
[0] = IEEE80211_FC0_VERSION_0
| IEEE80211_FC0_SUBTYPE_AUTH
;
1585 memcpy(frame
->i_addr1
, dest
, ETHER_ADDR_LEN
);
1586 memcpy(frame
->i_addr2
, sc
->sc_ecf_startup
.e_station_addr
,
1588 memcpy(frame
->i_addr3
, sc
->sc_bssid
, ETHER_ADDR_LEN
);
1590 var
= (u_int8_t
*)(frame
+ 1);
1591 memset(var
, 0, ETHER_ADDR_LEN
);
1594 ray_write_region(sc
, bufp
, packet
, sizeof(packet
));
1596 SRAM_WRITE_1(sc
, RAY_SCB_CCSI
, ccsindex
);
1597 RAY_ECF_START_CMD(sc
);
1599 RAY_DPRINTF_XMIT(("%s: sent auth packet: len %lu\n",
1600 device_xname(&sc
->sc_dev
), (u_long
) sizeof(packet
)));
1606 * scan for free buffers
1608 * Note: do _not_ try to optimize this away, there is some kind of
1609 * horrible interaction with receiving tx interrupts and they
1610 * have to be done as fast as possible, which means zero processing.
1611 * this took ~ever to figure out, don't make someone do it again!
1614 ray_find_free_tx_ccs(struct ray_softc
*sc
, u_int hint
)
1618 for (i
= hint
; i
<= RAY_CCS_TX_LAST
; i
++) {
1619 stat
= SRAM_READ_FIELD_1(sc
, RAY_GET_CCS(i
), ray_cmd
, c_status
);
1620 if (stat
== RAY_CCS_STATUS_FREE
)
1624 if (hint
== RAY_CCS_TX_FIRST
)
1625 return (RAY_CCS_LINK_NULL
);
1627 for (i
= RAY_CCS_TX_FIRST
; i
< hint
; i
++) {
1628 stat
= SRAM_READ_FIELD_1(sc
, RAY_GET_CCS(i
), ray_cmd
, c_status
);
1629 if (stat
== RAY_CCS_STATUS_FREE
)
1632 return (RAY_CCS_LINK_NULL
);
1636 * allocate, initialize and link in a tx ccs for the given
1637 * page and the current chain values
1640 ray_fill_in_tx_ccs(struct ray_softc
*sc
, size_t pktlen
, u_int i
, u_int pi
)
1642 bus_size_t ccs
, bufp
;
1644 /* pktlen += RAY_TX_PHY_SIZE; */
1645 bufp
= RAY_TX_BASE
+ i
* RAY_TX_BUF_SIZE
;
1646 bufp
+= sc
->sc_txpad
;
1647 ccs
= RAY_GET_CCS(i
);
1648 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_tx
, c_status
, RAY_CCS_STATUS_BUSY
);
1649 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_tx
, c_cmd
, RAY_CMD_TX_REQ
);
1650 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_tx
, c_link
, RAY_CCS_LINK_NULL
);
1651 SRAM_WRITE_FIELD_2(sc
, ccs
, ray_cmd_tx
, c_bufp
, bufp
);
1652 SRAM_WRITE_FIELD_2(sc
, ccs
, ray_cmd_tx
, c_len
, pktlen
);
1653 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_tx
, c_tx_rate
, sc
->sc_deftxrate
);
1654 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_tx
, c_apm_mode
, 0);
1655 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_tx
, c_antenna
, 0);
1658 if (pi
!= RAY_CCS_LINK_NULL
)
1659 SRAM_WRITE_FIELD_1(sc
, RAY_GET_CCS(pi
), ray_cmd_tx
, c_link
, i
);
1661 RAY_DPRINTF(("%s: ray_alloc_tx_ccs bufp 0x%llx idx %u pidx %u\n",
1662 device_xname(&sc
->sc_dev
), (unsigned long long)bufp
, i
, pi
));
1664 return (bufp
+ RAY_TX_PHY_SIZE
);
1668 * an update params command has completed lookup which command and
1671 static ray_cmd_func_t
1672 ray_update_params_done(struct ray_softc
*sc
, bus_size_t ccs
, u_int stat
)
1674 ray_cmd_func_t rcmd
;
1678 RAY_DPRINTF(("%s: ray_update_params_done stat %d\n",
1679 device_xname(&sc
->sc_dev
), stat
));
1681 /* this will get more complex as we add commands */
1682 if (stat
== RAY_CCS_STATUS_FAIL
) {
1683 printf("%s: failed to update a promisc\n", device_xname(&sc
->sc_dev
));
1684 /* XXX should probably reset */
1685 /* rcmd = ray_reset; */
1688 if (sc
->sc_running
& SCP_UPD_PROMISC
) {
1689 ray_cmd_done(sc
, SCP_UPD_PROMISC
);
1690 sc
->sc_promisc
= SRAM_READ_1(sc
, RAY_HOST_TO_ECF_BASE
);
1691 RAY_DPRINTF(("%s: new promisc value %d\n", device_xname(&sc
->sc_dev
),
1693 } else if (sc
->sc_updreq
) {
1694 ray_cmd_done(sc
, SCP_UPD_UPDATEPARAMS
);
1695 /* get the update parameter */
1696 sc
->sc_updreq
->r_failcause
=
1697 SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_update
, c_failcause
);
1699 wakeup(ray_update_params
);
1701 rcmd
= ray_start_join_net
;
1707 * check too see if we have any pending commands.
1710 ray_check_scheduled(void *arg
)
1712 struct ray_softc
*sc
;
1719 "%s: ray_check_scheduled enter schd 0x%x running 0x%x ready %d\n",
1720 device_xname(&sc
->sc_dev
), sc
->sc_scheduled
, sc
->sc_running
, RAY_ECF_READY(sc
)));
1722 if (sc
->sc_timoneed
) {
1723 callout_stop(&sc
->sc_check_scheduled_ch
);
1724 sc
->sc_timoneed
= 0;
1727 /* if update subcmd is running -- clear it in scheduled */
1728 if (sc
->sc_running
& SCP_UPDATESUBCMD
)
1729 sc
->sc_scheduled
&= ~SCP_UPDATESUBCMD
;
1732 for (i
= 0; i
< ray_ncmdtab
; mask
<<= 1, i
++) {
1733 if ((sc
->sc_scheduled
& ~SCP_UPD_MASK
) == 0)
1735 if (!RAY_ECF_READY(sc
))
1737 if (sc
->sc_scheduled
& mask
)
1738 (*ray_cmdtab
[i
])(sc
);
1742 "%s: ray_check_scheduled exit sched 0x%x running 0x%x ready %d\n",
1743 device_xname(&sc
->sc_dev
), sc
->sc_scheduled
, sc
->sc_running
, RAY_ECF_READY(sc
)));
1745 if (sc
->sc_scheduled
& ~SCP_UPD_MASK
)
1746 ray_set_pending(sc
, sc
->sc_scheduled
);
1752 * check for unreported returns
1754 * this routine is coded to only expect one outstanding request for the
1755 * timed out requests at a time, but thats all that can be outstanding
1756 * per hardware limitations
1759 ray_check_ccs(void *arg
)
1762 struct ray_softc
*sc
;
1763 u_int i
, cmd
, stat
= 0;
1770 RAY_DPRINTF(("%s: ray_check_ccs\n", device_xname(&sc
->sc_dev
)));
1772 sc
->sc_timocheck
= 0;
1773 for (i
= RAY_CCS_CMD_FIRST
; i
<= RAY_CCS_CMD_LAST
; i
++) {
1774 if (!sc
->sc_ccsinuse
[i
])
1776 ccs
= RAY_GET_CCS(i
);
1777 cmd
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd
, c_cmd
);
1779 case RAY_CMD_START_PARAMS
:
1780 case RAY_CMD_UPDATE_MCAST
:
1781 case RAY_CMD_UPDATE_PARAMS
:
1782 stat
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd
, c_status
);
1783 RAY_DPRINTF(("%s: check ccs idx %u ccs 0x%llx "
1784 "cmd 0x%x stat %u\n", device_xname(&sc
->sc_dev
), i
,
1785 (unsigned long long)ccs
, cmd
, stat
));
1790 /* see if we got one of the commands we are looking for */
1791 if (i
> RAY_CCS_CMD_LAST
)
1793 else if (stat
== RAY_CCS_STATUS_FREE
) {
1794 stat
= RAY_CCS_STATUS_COMPLETE
;
1795 if ((fp
= ray_ccs_done(sc
, ccs
)))
1797 } else if (stat
!= RAY_CCS_STATUS_BUSY
) {
1798 if (sc
->sc_ccsinuse
[i
] == 1) {
1799 /* give a chance for the interrupt to occur */
1800 sc
->sc_ccsinuse
[i
] = 2;
1801 if (!sc
->sc_timocheck
) {
1802 callout_reset(&sc
->sc_check_ccs_ch
, 1,
1804 sc
->sc_timocheck
= 1;
1806 } else if ((fp
= ray_ccs_done(sc
, ccs
)))
1809 callout_reset(&sc
->sc_check_ccs_ch
, RAY_CHECK_CCS_TIMEOUT
,
1811 sc
->sc_timocheck
= 1;
1817 * read the counters, the card implements the following protocol
1818 * to keep the values from being changed while read: It checks
1819 * the `own' bit and if zero writes the current internal counter
1820 * value, it then sets the `own' bit to 1. If the `own' bit was 1 it
1821 * increments its internal counter. The user thus reads the counter
1822 * if the `own' bit is one and then sets the own bit to 0.
1825 ray_update_error_counters(struct ray_softc
*sc
)
1829 /* try and update the error counters */
1830 csc
= RAY_STATUS_BASE
;
1831 if (SRAM_READ_FIELD_1(sc
, csc
, ray_csc
, csc_mrxo_own
)) {
1832 sc
->sc_rxoverflow
+=
1833 SRAM_READ_FIELD_2(sc
, csc
, ray_csc
, csc_mrx_overflow
);
1834 SRAM_WRITE_FIELD_1(sc
, csc
, ray_csc
, csc_mrxo_own
, 0);
1836 if (SRAM_READ_FIELD_1(sc
, csc
, ray_csc
, csc_mrxc_own
)) {
1838 SRAM_READ_FIELD_2(sc
, csc
, ray_csc
, csc_mrx_overflow
);
1839 SRAM_WRITE_FIELD_1(sc
, csc
, ray_csc
, csc_mrxc_own
, 0);
1841 if (SRAM_READ_FIELD_1(sc
, csc
, ray_csc
, csc_rxhc_own
)) {
1843 SRAM_READ_FIELD_2(sc
, csc
, ray_csc
, csc_rx_hcksum
);
1844 SRAM_WRITE_FIELD_1(sc
, csc
, ray_csc
, csc_rxhc_own
, 0);
1846 sc
->sc_rxnoise
= SRAM_READ_FIELD_1(sc
, csc
, ray_csc
, csc_rx_noise
);
1850 * one of the commands we issued has completed, process.
1852 static ray_cmd_func_t
1853 ray_ccs_done(struct ray_softc
*sc
, bus_size_t ccs
)
1855 ray_cmd_func_t rcmd
;
1858 cmd
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd
, c_cmd
);
1859 stat
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd
, c_status
);
1861 RAY_DPRINTF(("%s: ray_ccs_done idx %llu cmd 0x%x stat %u\n",
1862 device_xname(&sc
->sc_dev
), (unsigned long long)RAY_GET_INDEX(ccs
), cmd
, stat
));
1867 * solicited commands
1869 case RAY_CMD_START_PARAMS
:
1871 ray_cmd_done(sc
, SCP_UPD_STARTUP
);
1873 /* ok to start queueing packets */
1874 sc
->sc_if
.if_flags
&= ~IFF_OACTIVE
;
1876 sc
->sc_omode
= sc
->sc_mode
;
1877 memcpy(&sc
->sc_cnwid
, &sc
->sc_dnwid
, sizeof(sc
->sc_cnwid
));
1879 rcmd
= ray_start_join_net
;
1881 case RAY_CMD_UPDATE_PARAMS
:
1882 rcmd
= ray_update_params_done(sc
, ccs
, stat
);
1884 case RAY_CMD_REPORT_PARAMS
:
1885 /* get the reported parameters */
1886 ray_cmd_done(sc
, SCP_REPORTPARAMS
);
1889 sc
->sc_repreq
->r_failcause
=
1890 SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_report
, c_failcause
);
1891 sc
->sc_repreq
->r_len
=
1892 SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_report
, c_len
);
1893 ray_read_region(sc
, RAY_ECF_TO_HOST_BASE
, sc
->sc_repreq
->r_data
,
1894 sc
->sc_repreq
->r_len
);
1896 wakeup(ray_report_params
);
1898 case RAY_CMD_UPDATE_MCAST
:
1899 ray_cmd_done(sc
, SCP_UPD_MCAST
);
1900 if (stat
== RAY_CCS_STATUS_FAIL
)
1903 case RAY_CMD_START_NET
:
1904 case RAY_CMD_JOIN_NET
:
1905 rcmd
= ray_start_join_net_done(sc
, cmd
, ccs
, stat
);
1907 case RAY_CMD_TX_REQ
:
1908 if (sc
->sc_if
.if_flags
& IFF_OACTIVE
) {
1909 sc
->sc_if
.if_flags
&= ~IFF_OACTIVE
;
1910 /* this may also be a problem */
1911 rcmd
= ray_intr_start
;
1913 /* free it -- no tracking */
1914 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_status
,
1915 RAY_CCS_STATUS_FREE
);
1917 case RAY_CMD_START_ASSOC
:
1918 ray_cmd_done(sc
, SCP_STARTASSOC
);
1919 if (stat
== RAY_CCS_STATUS_FAIL
)
1920 rcmd
= ray_start_join_net
; /* XXX check */
1923 rcmd
= ray_intr_start
;
1926 case RAY_CMD_UPDATE_APM
:
1927 case RAY_CMD_TEST_MEM
:
1928 case RAY_CMD_SHUTDOWN
:
1929 case RAY_CMD_DUMP_MEM
:
1930 case RAY_CMD_START_TIMER
:
1933 printf("%s: intr: unknown command 0x%x\n",
1934 sc
->sc_if
.if_xname
, cmd
);
1937 ray_free_ccs(sc
, ccs
);
1940 * see if needed things can be done now that a command
1943 ray_check_scheduled(sc
);
1949 * an unsolicited interrupt, i.e., the ECF is sending us a command
1951 static ray_cmd_func_t
1952 ray_rccs_intr(struct ray_softc
*sc
, bus_size_t ccs
)
1954 ray_cmd_func_t rcmd
;
1957 cmd
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd
, c_cmd
);
1958 stat
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd
, c_status
);
1960 RAY_DPRINTF(("%s: ray_rccs_intr idx %llu cmd 0x%x stat %u\n",
1961 device_xname(&sc
->sc_dev
), (unsigned long long)RAY_GET_INDEX(ccs
), cmd
, stat
));
1966 * unsolicited commands
1968 case RAY_ECMD_RX_DONE
:
1971 case RAY_ECMD_REJOIN_DONE
:
1972 if (sc
->sc_mode
== SC_MODE_ADHOC
)
1974 /* get the current ssid */
1975 SRAM_READ_FIELD_N(sc
, ccs
, ray_cmd_net
, c_bss_id
,
1976 sc
->sc_bssid
, sizeof(sc
->sc_bssid
));
1977 rcmd
= ray_start_assoc
;
1979 case RAY_ECMD_ROAM_START
:
1980 /* no longer have network */
1983 case RAY_ECMD_JAPAN_CALL_SIGNAL
:
1986 ray_update_error_counters(sc
);
1988 /* this is a bogus return from build 4 don't free 0x55 */
1989 if (sc
->sc_version
== SC_BUILD_4
&& cmd
== 0x55
1990 && RAY_GET_INDEX(ccs
) == 0x55) {
1993 printf("%s: intr: unknown command 0x%x\n",
1994 sc
->sc_if
.if_xname
, cmd
);
1998 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_status
, RAY_CCS_STATUS_FREE
);
2004 * process an interrupt
2009 struct ray_softc
*sc
;
2010 ray_cmd_func_t rcmd
;
2015 RAY_DPRINTF(("%s: ray_intr\n", device_xname(&sc
->sc_dev
)));
2017 if ((++sc
->sc_checkcounters
% 32) == 0)
2018 ray_update_error_counters(sc
);
2022 if (!REG_READ(sc
, RAY_HCSIR
))
2026 i
= SRAM_READ_1(sc
, RAY_SCB_RCCSI
);
2027 if (i
<= RAY_CCS_LAST
)
2028 rcmd
= ray_ccs_done(sc
, RAY_GET_CCS(i
));
2029 else if (i
<= RAY_RCCS_LAST
)
2030 rcmd
= ray_rccs_intr(sc
, RAY_GET_CCS(i
));
2032 printf("%s: intr: bad cmd index %d\n", device_xname(&sc
->sc_dev
), i
);
2039 REG_WRITE(sc
, RAY_HCSIR
, 0);
2041 RAY_DPRINTF(("%s: interrupt handled %d\n", device_xname(&sc
->sc_dev
), count
));
2043 return (count
? 1 : 0);
2048 * Generic CCS handling
2052 * free the chain of descriptors -- used for freeing allocated tx chains
2055 ray_free_ccs_chain(struct ray_softc
*sc
, u_int ni
)
2059 while ((i
= ni
) != RAY_CCS_LINK_NULL
) {
2060 ni
= SRAM_READ_FIELD_1(sc
, RAY_GET_CCS(i
), ray_cmd
, c_link
);
2061 SRAM_WRITE_FIELD_1(sc
, RAY_GET_CCS(i
), ray_cmd
, c_status
,
2062 RAY_CCS_STATUS_FREE
);
2067 * free up a cmd and return the old status
2068 * this routine is only used for commands
2071 ray_free_ccs(struct ray_softc
*sc
, bus_size_t ccs
)
2075 RAY_DPRINTF(("%s: free_ccs idx %llu\n", device_xname(&sc
->sc_dev
),
2076 (unsigned long long)RAY_GET_INDEX(ccs
)));
2078 stat
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd
, c_status
);
2079 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_status
, RAY_CCS_STATUS_FREE
);
2080 if (ccs
<= RAY_GET_CCS(RAY_CCS_LAST
))
2081 sc
->sc_ccsinuse
[RAY_GET_INDEX(ccs
)] = 0;
2087 * returns 1 and in `ccb' the bus offset of the free ccb
2088 * or 0 if none are free
2090 * If `track' is not zero, handles tracking this command
2091 * possibly indicating a callback is needed and setting a timeout
2092 * also if ECF isn't ready we terminate earlier to avoid overhead.
2094 * this routine is only used for commands
2097 ray_alloc_ccs(struct ray_softc
*sc
, bus_size_t
*ccsp
, u_int cmd
, u_int track
)
2102 RAY_DPRINTF(("%s: alloc_ccs cmd %d\n", device_xname(&sc
->sc_dev
), cmd
));
2104 /* for tracked commands, if not ready just set pending */
2105 if (track
&& !RAY_ECF_READY(sc
)) {
2106 ray_cmd_schedule(sc
, track
);
2110 /* first scan our inuse array */
2111 for (i
= RAY_CCS_CMD_FIRST
; i
<= RAY_CCS_CMD_LAST
; i
++) {
2112 /* XXX wonder if we have to probe here to make the card go */
2113 (void)SRAM_READ_FIELD_1(sc
, RAY_GET_CCS(i
), ray_cmd
, c_status
);
2114 if (!sc
->sc_ccsinuse
[i
])
2117 if (i
> RAY_CCS_CMD_LAST
) {
2119 ray_cmd_schedule(sc
, track
);
2122 sc
->sc_ccsinuse
[i
] = 1;
2123 ccs
= RAY_GET_CCS(i
);
2124 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_status
, RAY_CCS_STATUS_BUSY
);
2125 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_cmd
, cmd
);
2126 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd
, c_link
, RAY_CCS_LINK_NULL
);
2134 * this function sets the pending bit for the command given in 'need'
2135 * and schedules a timeout if none is scheduled already. Any command
2136 * that uses the `host to ecf' region must be serialized.
2139 ray_set_pending(struct ray_softc
*sc
, u_int cmdf
)
2141 RAY_DPRINTF(("%s: ray_set_pending 0x%x\n", device_xname(&sc
->sc_dev
), cmdf
));
2143 sc
->sc_scheduled
|= cmdf
;
2144 if (!sc
->sc_timoneed
) {
2145 RAY_DPRINTF(("%s: ray_set_pending new timo\n", device_xname(&sc
->sc_dev
)));
2146 callout_reset(&sc
->sc_check_scheduled_ch
,
2147 RAY_CHECK_SCHED_TIMEOUT
, ray_check_scheduled
, sc
);
2148 sc
->sc_timoneed
= 1;
2153 * schedule the `cmdf' for completion later
2156 ray_cmd_schedule(struct ray_softc
*sc
, int cmdf
)
2160 RAY_DPRINTF(("%s: ray_cmd_schedule 0x%x\n", device_xname(&sc
->sc_dev
), cmdf
));
2163 if ((cmdf
& SCP_UPD_MASK
) == 0)
2164 ray_set_pending(sc
, track
);
2165 else if (ray_cmd_is_running(sc
, SCP_UPDATESUBCMD
)) {
2166 /* don't do timeout mechanism if subcmd already going */
2167 sc
->sc_scheduled
|= cmdf
;
2169 ray_set_pending(sc
, cmdf
| SCP_UPDATESUBCMD
);
2173 * check to see if `cmdf' has been scheduled
2176 ray_cmd_is_scheduled(struct ray_softc
*sc
, int cmdf
)
2178 RAY_DPRINTF(("%s: ray_cmd_is_scheduled 0x%x\n", device_xname(&sc
->sc_dev
), cmdf
));
2180 return ((sc
->sc_scheduled
& cmdf
) ? 1 : 0);
2184 * cancel a scheduled command (not a running one though!)
2187 ray_cmd_cancel(struct ray_softc
*sc
, int cmdf
)
2189 RAY_DPRINTF(("%s: ray_cmd_cancel 0x%x\n", device_xname(&sc
->sc_dev
), cmdf
));
2191 sc
->sc_scheduled
&= ~cmdf
;
2192 if ((cmdf
& SCP_UPD_MASK
) && (sc
->sc_scheduled
& SCP_UPD_MASK
) == 0)
2193 sc
->sc_scheduled
&= ~SCP_UPDATESUBCMD
;
2195 /* if nothing else needed cancel the timer */
2196 if (sc
->sc_scheduled
== 0 && sc
->sc_timoneed
) {
2197 callout_stop(&sc
->sc_check_scheduled_ch
);
2198 sc
->sc_timoneed
= 0;
2203 * called to indicate the 'cmdf' has been issued
2206 ray_cmd_ran(struct ray_softc
*sc
, int cmdf
)
2208 RAY_DPRINTF(("%s: ray_cmd_ran 0x%x\n", device_xname(&sc
->sc_dev
), cmdf
));
2210 if (cmdf
& SCP_UPD_MASK
)
2211 sc
->sc_running
|= cmdf
| SCP_UPDATESUBCMD
;
2213 sc
->sc_running
|= cmdf
;
2215 if ((cmdf
& SCP_TIMOCHECK_CMD_MASK
) && !sc
->sc_timocheck
) {
2216 callout_reset(&sc
->sc_check_ccs_ch
, RAY_CHECK_CCS_TIMEOUT
,
2218 sc
->sc_timocheck
= 1;
2223 * check to see if `cmdf' has been issued
2226 ray_cmd_is_running(struct ray_softc
*sc
, int cmdf
)
2228 RAY_DPRINTF(("%s: ray_cmd_is_running 0x%x\n", device_xname(&sc
->sc_dev
), cmdf
));
2230 return ((sc
->sc_running
& cmdf
) ? 1 : 0);
2234 * the given `cmdf' that was issued has completed
2237 ray_cmd_done(struct ray_softc
*sc
, int cmdf
)
2239 RAY_DPRINTF(("%s: ray_cmd_done 0x%x\n", device_xname(&sc
->sc_dev
), cmdf
));
2241 sc
->sc_running
&= ~cmdf
;
2242 if (cmdf
& SCP_UPD_MASK
) {
2243 sc
->sc_running
&= ~SCP_UPDATESUBCMD
;
2244 if (sc
->sc_scheduled
& SCP_UPD_MASK
)
2245 ray_cmd_schedule(sc
, sc
->sc_scheduled
& SCP_UPD_MASK
);
2247 if ((sc
->sc_running
& SCP_TIMOCHECK_CMD_MASK
) == 0 && sc
->sc_timocheck
){
2248 callout_stop(&sc
->sc_check_ccs_ch
);
2249 sc
->sc_timocheck
= 0;
2255 * only used for commands not tx
2258 ray_issue_cmd(struct ray_softc
*sc
, bus_size_t ccs
, u_int track
)
2262 RAY_DPRINTF(("%s: ray_cmd_issue 0x%x\n", device_xname(&sc
->sc_dev
), track
));
2265 * XXX other drivers did this, but I think
2266 * what we really want to do is just make sure we don't
2267 * get here or that spinning is ok
2270 while (!RAY_ECF_READY(sc
))
2272 ray_free_ccs(sc
, ccs
);
2274 ray_cmd_schedule(sc
, track
);
2278 SRAM_WRITE_1(sc
, RAY_SCB_CCSI
, RAY_GET_INDEX(ccs
));
2279 RAY_ECF_START_CMD(sc
);
2280 ray_cmd_ran(sc
, track
);
2286 * send a simple command if we can
2289 ray_simple_cmd(struct ray_softc
*sc
, u_int cmd
, u_int track
)
2293 return (ray_alloc_ccs(sc
, &ccs
, cmd
, track
) &&
2294 ray_issue_cmd(sc
, ccs
, track
));
2298 * Functions based on CCS commands
2302 * run a update subcommand
2305 ray_update_subcmd(struct ray_softc
*sc
)
2309 RAY_DPRINTF(("%s: ray_update_subcmd\n", device_xname(&sc
->sc_dev
)));
2311 ray_cmd_cancel(sc
, SCP_UPDATESUBCMD
);
2312 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0)
2314 submask
= SCP_UPD_FIRST
;
2315 for (i
= 0; i
< ray_nsubcmdtab
; submask
<<= 1, i
++) {
2316 if ((sc
->sc_scheduled
& SCP_UPD_MASK
) == 0)
2318 /* when done the next command will be scheduled */
2319 if (ray_cmd_is_running(sc
, SCP_UPDATESUBCMD
))
2321 if (!RAY_ECF_READY(sc
))
2324 * give priority to LSB -- e.g., if previous loop rescheduled
2325 * doing this command after calling the function won't catch
2326 * if a later command sets an earlier bit
2328 if (sc
->sc_scheduled
& ((submask
- 1) & SCP_UPD_MASK
))
2330 if (sc
->sc_scheduled
& submask
)
2331 (*ray_subcmdtab
[i
])(sc
);
2336 * report a parameter
2339 ray_report_params(struct ray_softc
*sc
)
2343 ray_cmd_cancel(sc
, SCP_REPORTPARAMS
);
2348 /* do the issue check before equality check */
2349 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0)
2351 else if (ray_cmd_is_running(sc
, SCP_REPORTPARAMS
)) {
2352 ray_cmd_schedule(sc
, SCP_REPORTPARAMS
);
2354 } else if (!ray_alloc_ccs(sc
, &ccs
, RAY_CMD_REPORT_PARAMS
,
2358 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_report
, c_paramid
,
2359 sc
->sc_repreq
->r_paramid
);
2360 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_report
, c_nparam
, 1);
2361 (void)ray_issue_cmd(sc
, ccs
, SCP_REPORTPARAMS
);
2365 * start an association
2368 ray_start_assoc(struct ray_softc
*sc
)
2370 ray_cmd_cancel(sc
, SCP_STARTASSOC
);
2371 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0)
2373 else if (ray_cmd_is_running(sc
, SCP_STARTASSOC
))
2375 (void)ray_simple_cmd(sc
, RAY_CMD_START_ASSOC
, SCP_STARTASSOC
);
2379 * Subcommand functions that use the SCP_UPDATESUBCMD command
2380 * (and are serialized with respect to other update sub commands
2384 * download the startup parameters to the card
2385 * -- no outstanding commands expected
2388 ray_download_params(struct ray_softc
*sc
)
2390 struct ray_startup_params_head
*sp
;
2391 struct ray_startup_params_tail_5
*sp5
;
2392 struct ray_startup_params_tail_4
*sp4
;
2395 RAY_DPRINTF(("%s: init_startup_params\n", device_xname(&sc
->sc_dev
)));
2397 ray_cmd_cancel(sc
, SCP_UPD_STARTUP
);
2399 #define PUT2(p, v) \
2400 do { (p)[0] = ((v >> 8) & 0xff); (p)[1] = (v & 0xff); } while(0)
2402 sp
= &sc
->sc_startup
;
2403 sp4
= &sc
->sc_startup_4
;
2404 sp5
= &sc
->sc_startup_5
;
2405 memset(sp
, 0, sizeof(*sp
));
2406 if (sc
->sc_version
== SC_BUILD_4
)
2407 memset(sp4
, 0, sizeof(*sp4
));
2409 memset(sp5
, 0, sizeof(*sp5
));
2410 /* XXX: Raylink firmware doesn't have length field for ssid */
2411 memcpy(sp
->sp_ssid
, sc
->sc_dnwid
.i_nwid
, sizeof(sp
->sp_ssid
));
2412 sp
->sp_scan_mode
= 0x1;
2413 memcpy(sp
->sp_mac_addr
, sc
->sc_ecf_startup
.e_station_addr
,
2415 PUT2(sp
->sp_frag_thresh
, 0x7fff); /* disabled */
2416 if (sc
->sc_version
== SC_BUILD_4
) {
2419 PUT2(sp
->sp_dwell_time
, 0x200);
2420 PUT2(sp
->sp_beacon_period
, 1);
2423 PUT2(sp
->sp_dwell_time
, 0x400);
2424 PUT2(sp
->sp_beacon_period
, 0);
2427 PUT2(sp
->sp_dwell_time
, 128);
2428 PUT2(sp
->sp_beacon_period
, 256);
2430 sp
->sp_dtim_interval
= 1;
2432 /* these are the documented defaults for build 5/6 */
2433 sp
->sp_max_retry
= 0x1f;
2434 sp
->sp_ack_timo
= 0x86;
2437 /* these were scrounged from the linux driver */
2438 sp
->sp_max_retry
= 0x07;
2440 sp
->sp_ack_timo
= 0xa3;
2443 /* these were divined */
2444 sp
->sp_max_retry
= 0x03;
2446 sp
->sp_ack_timo
= 0xa3;
2450 /* these are the documented defaults for build 5/6 */
2457 if (sc
->sc_version
== SC_BUILD_4
)
2463 PUT2(sp
->sp_rts_thresh
, 0x7fff); /* disabled */
2464 if (sc
->sc_version
== SC_BUILD_4
) {
2465 PUT2(sp
->sp_scan_dwell
, 0xfb1e);
2466 PUT2(sp
->sp_scan_max_dwell
, 0xc75c);
2468 PUT2(sp
->sp_scan_dwell
, 0x4e2);
2469 PUT2(sp
->sp_scan_max_dwell
, 0x38a4);
2471 sp
->sp_assoc_timo
= 0x5;
2472 if (sc
->sc_version
== SC_BUILD_4
) {
2475 sp
->sp_adhoc_scan_cycle
= 0x4;
2476 sp
->sp_infra_scan_cycle
= 0x2;
2477 sp
->sp_infra_super_scan_cycle
= 0x4;
2480 sp
->sp_adhoc_scan_cycle
= 0x8;
2481 sp
->sp_infra_scan_cycle
= 0x1;
2482 sp
->sp_infra_super_scan_cycle
= 0x18;
2485 sp
->sp_adhoc_scan_cycle
= 0x8;
2486 sp
->sp_infra_scan_cycle
= 0x2;
2487 sp
->sp_infra_super_scan_cycle
= 0x8;
2489 sp
->sp_promisc
= sc
->sc_promisc
;
2490 PUT2(sp
->sp_uniq_word
, 0x0cbd);
2491 if (sc
->sc_version
== SC_BUILD_4
) {
2492 /* XXX what is this value anyway..? the std says 50us */
2493 /* XXX sp->sp_slot_time = 0x4e; */
2494 sp
->sp_slot_time
= 0x4e;
2497 sp
->sp_roam_low_snr_thresh
= 0xff;
2500 sp
->sp_roam_low_snr_thresh
= 0x30;
2503 sp
->sp_slot_time
= 0x32;
2504 sp
->sp_roam_low_snr_thresh
= 0xff; /* disabled */
2507 sp
->sp_low_snr_count
= 0xff; /* disabled */
2509 /* divined -- check */
2510 sp
->sp_low_snr_count
= 0x07; /* disabled */
2513 sp
->sp_infra_missed_beacon_count
= 0x2;
2516 sp
->sp_infra_missed_beacon_count
= 0x5;
2518 /* divined -- check, looks fishy */
2519 sp
->sp_infra_missed_beacon_count
= 0x7;
2521 sp
->sp_adhoc_missed_beacon_count
= 0xff;
2522 sp
->sp_country_code
= sc
->sc_dcountrycode
;
2523 sp
->sp_hop_seq
= 0x0b;
2524 if (sc
->sc_version
== SC_BUILD_4
) {
2525 sp
->sp_hop_seq_len
= 0x4e;
2526 sp4
->sp_cw_max
= 0x3f; /* single byte on build 4 */
2527 sp4
->sp_cw_min
= 0x0f; /* single byte on build 4 */
2528 sp4
->sp_noise_filter_gain
= 0x4;
2529 sp4
->sp_noise_limit_offset
= 0x8;
2530 sp4
->sp_rssi_thresh_offset
= 0x28;
2531 sp4
->sp_busy_thresh_offset
= 0x28;
2532 sp4
->sp_sync_thresh
= 0x07;
2533 sp4
->sp_test_mode
= 0x0;
2534 sp4
->sp_test_min_chan
= 0x2;
2535 sp4
->sp_test_max_chan
= 0x2;
2537 sp
->sp_hop_seq_len
= 0x4f;
2538 PUT2(sp5
->sp_cw_max
, 0x3f);
2539 PUT2(sp5
->sp_cw_min
, 0x0f);
2540 sp5
->sp_noise_filter_gain
= 0x4;
2541 sp5
->sp_noise_limit_offset
= 0x8;
2542 sp5
->sp_rssi_thresh_offset
= 0x28;
2543 sp5
->sp_busy_thresh_offset
= 0x28;
2544 sp5
->sp_sync_thresh
= 0x07;
2545 sp5
->sp_test_mode
= 0x0;
2546 sp5
->sp_test_min_chan
= 0x2;
2547 sp5
->sp_test_max_chan
= 0x2;
2549 sp5
->sp_allow_probe_resp
= 0x1;
2551 sp5
->sp_allow_probe_resp
= 0x0;
2553 sp5
->sp_privacy_must_start
= 0x0;
2554 sp5
->sp_privacy_can_join
= 0x0;
2555 sp5
->sp_basic_rate_set
[0] = 0x2;
2556 /* 2 = 1Mbps, 3 = old 2Mbps 4 = 2Mbps */
2559 /* we shouldn't be called with some command pending */
2560 if (!RAY_ECF_READY(sc
))
2561 panic("ray_download_params busy");
2563 /* write the compatible part */
2564 off
= RAY_HOST_TO_ECF_BASE
;
2565 ray_write_region(sc
, off
, sp
, sizeof(sc
->sc_startup
));
2566 off
+= sizeof(sc
->sc_startup
);
2567 if (sc
->sc_version
== SC_BUILD_4
)
2568 ray_write_region(sc
, off
, sp4
, sizeof(*sp4
));
2570 ray_write_region(sc
, off
, sp5
, sizeof(*sp5
));
2571 if (!ray_simple_cmd(sc
, RAY_CMD_START_PARAMS
, SCP_UPD_STARTUP
))
2572 panic("ray_download_params issue");
2576 * start or join a network
2579 ray_start_join_net(struct ray_softc
*sc
)
2581 struct ray_net_params np
;
2585 ray_cmd_cancel(sc
, SCP_UPD_STARTJOIN
);
2586 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0)
2589 /* XXX check we may not want to re-issue */
2590 if (ray_cmd_is_running(sc
, SCP_UPDATESUBCMD
)) {
2591 ray_cmd_schedule(sc
, SCP_UPD_STARTJOIN
);
2595 if (sc
->sc_mode
== SC_MODE_ADHOC
)
2596 cmd
= RAY_CMD_START_NET
;
2598 cmd
= RAY_CMD_JOIN_NET
;
2600 if (!ray_alloc_ccs(sc
, &ccs
, cmd
, SCP_UPD_STARTJOIN
))
2602 sc
->sc_startccs
= ccs
;
2603 sc
->sc_startcmd
= cmd
;
2604 if (!memcmp(&sc
->sc_cnwid
, &sc
->sc_dnwid
, sizeof(sc
->sc_cnwid
))
2605 && sc
->sc_omode
== sc
->sc_mode
)
2606 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_net
, c_upd_param
, 0);
2609 memset(&np
, 0, sizeof(np
));
2610 np
.p_net_type
= sc
->sc_mode
;
2611 memcpy(np
.p_ssid
, sc
->sc_dnwid
.i_nwid
, sizeof(np
.p_ssid
));
2612 ray_write_region(sc
, RAY_HOST_TO_ECF_BASE
, &np
, sizeof(np
));
2613 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_net
, c_upd_param
, 1);
2615 if (ray_issue_cmd(sc
, ccs
, SCP_UPD_STARTJOIN
))
2616 callout_reset(&sc
->sc_start_join_timo_ch
, RAY_START_TIMEOUT
,
2617 ray_start_join_timo
, sc
);
2621 ray_start_join_timo(void *arg
)
2623 struct ray_softc
*sc
;
2627 stat
= SRAM_READ_FIELD_1(sc
, sc
->sc_startccs
, ray_cmd
, c_status
);
2628 ray_start_join_net_done(sc
, sc
->sc_startcmd
, sc
->sc_startccs
, stat
);
2632 * The start/join has completed. Note: we timeout the start
2633 * command because it seems to fail to work at least on the
2634 * build 4 firmware without reporting an error. This actually
2635 * may be a result of not putting the correct params in the
2636 * initial download. If this is a timeout `stat' will be
2639 static ray_cmd_func_t
2640 ray_start_join_net_done(struct ray_softc
*sc
, u_int cmd
, bus_size_t ccs
, u_int stat
)
2643 struct ray_net_params np
;
2645 callout_stop(&sc
->sc_start_join_timo_ch
);
2646 ray_cmd_done(sc
, SCP_UPD_STARTJOIN
);
2648 if (stat
== RAY_CCS_STATUS_FAIL
) {
2649 /* XXX poke ifmedia when it supports this */
2651 return (ray_start_join_net
);
2653 if (stat
== RAY_CCS_STATUS_BUSY
|| stat
== RAY_CCS_STATUS_FREE
) {
2654 /* handle the timeout condition */
2655 callout_reset(&sc
->sc_start_join_timo_ch
, RAY_START_TIMEOUT
,
2656 ray_start_join_timo
, sc
);
2658 /* be safe -- not a lot occurs with no net though */
2659 if (!RAY_ECF_READY(sc
))
2662 /* see if our nwid is up to date */
2663 if (!memcmp(&sc
->sc_cnwid
, &sc
->sc_dnwid
, sizeof(sc
->sc_cnwid
))
2664 && sc
->sc_omode
== sc
->sc_mode
)
2665 SRAM_WRITE_FIELD_1(sc
,ccs
, ray_cmd_net
, c_upd_param
, 0);
2667 memset(&np
, 0, sizeof(np
));
2668 np
.p_net_type
= sc
->sc_mode
;
2669 memcpy(np
.p_ssid
, sc
->sc_dnwid
.i_nwid
,
2671 ray_write_region(sc
, RAY_HOST_TO_ECF_BASE
, &np
,
2673 SRAM_WRITE_FIELD_1(sc
,ccs
, ray_cmd_net
, c_upd_param
, 1);
2676 if (sc
->sc_mode
== SC_MODE_ADHOC
)
2677 cmd
= RAY_CMD_START_NET
;
2679 cmd
= RAY_CMD_JOIN_NET
;
2680 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_net
, c_cmd
,
2681 RAY_CCS_STATUS_BUSY
);
2682 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_net
, c_status
,
2683 RAY_CCS_STATUS_BUSY
);
2685 /* we simply poke the card again issuing the same ccs */
2686 SRAM_WRITE_1(sc
, RAY_SCB_CCSI
, RAY_GET_INDEX(ccs
));
2687 RAY_ECF_START_CMD(sc
);
2688 ray_cmd_ran(sc
, SCP_UPD_STARTJOIN
);
2691 /* get the current ssid */
2692 SRAM_READ_FIELD_N(sc
, ccs
, ray_cmd_net
, c_bss_id
, sc
->sc_bssid
,
2693 sizeof(sc
->sc_bssid
));
2695 sc
->sc_deftxrate
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_net
,c_def_txrate
);
2696 sc
->sc_encrypt
= SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_net
, c_encrypt
);
2698 /* adjust values for buggy build 4 */
2699 if (sc
->sc_deftxrate
== 0x55)
2700 sc
->sc_deftxrate
= RAY_PID_BASIC_RATE_1500K
;
2701 if (sc
->sc_encrypt
== 0x55)
2704 if (SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_net
, c_upd_param
)) {
2705 ray_read_region(sc
, RAY_HOST_TO_ECF_BASE
, &np
, sizeof(np
));
2706 /* XXX: Raylink firmware doesn't have length field for ssid */
2707 for (i
= 0; i
< sizeof(np
.p_ssid
); i
++) {
2708 if (np
.p_ssid
[i
] == '\0')
2711 sc
->sc_cnwid
.i_len
= i
;
2712 memcpy(sc
->sc_cnwid
.i_nwid
, np
.p_ssid
, sizeof(sc
->sc_cnwid
));
2713 sc
->sc_omode
= sc
->sc_mode
;
2714 if (np
.p_net_type
!= sc
->sc_mode
)
2715 return (ray_start_join_net
);
2717 RAY_DPRINTF(("%s: net start/join nwid %.32s bssid %s inited %d\n",
2718 device_xname(&sc
->sc_dev
), sc
->sc_cnwid
.i_nwid
, ether_sprintf(sc
->sc_bssid
),
2719 SRAM_READ_FIELD_1(sc
, ccs
, ray_cmd_net
, c_inited
)));
2721 /* network is now active */
2722 ray_cmd_schedule(sc
, SCP_UPD_MCAST
|SCP_UPD_PROMISC
);
2723 if (cmd
== RAY_CMD_JOIN_NET
)
2724 return (ray_start_assoc
);
2727 return (ray_intr_start
);
2732 * set the card in/out of promiscuous mode
2735 ray_update_promisc(struct ray_softc
*sc
)
2740 ray_cmd_cancel(sc
, SCP_UPD_PROMISC
);
2742 /* do the issue check before equality check */
2743 if (sc
->sc_if
.if_flags
& IFF_ALLMULTI
)
2744 sc
->sc_if
.if_flags
|= IFF_PROMISC
;
2745 else if (sc
->sc_if
.if_pcount
== 0)
2746 sc
->sc_if
.if_flags
&= ~IFF_PROMISC
;
2747 promisc
= !!(sc
->sc_if
.if_flags
& IFF_PROMISC
);
2748 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0)
2750 else if (ray_cmd_is_running(sc
, SCP_UPDATESUBCMD
)) {
2751 ray_cmd_schedule(sc
, SCP_UPD_PROMISC
);
2753 } else if (promisc
== sc
->sc_promisc
)
2755 else if (!ray_alloc_ccs(sc
,&ccs
,RAY_CMD_UPDATE_PARAMS
, SCP_UPD_PROMISC
))
2757 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_update
, c_paramid
, RAY_PID_PROMISC
);
2758 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_update
, c_nparam
, 1);
2759 SRAM_WRITE_1(sc
, RAY_HOST_TO_ECF_BASE
, promisc
);
2760 (void)ray_issue_cmd(sc
, ccs
, SCP_UPD_PROMISC
);
2764 * update the parameter based on what the user passed in
2767 ray_update_params(struct ray_softc
*sc
)
2771 ray_cmd_cancel(sc
, SCP_UPD_UPDATEPARAMS
);
2772 if (!sc
->sc_updreq
) {
2773 /* XXX do we need to wakeup here? */
2777 /* do the issue check before equality check */
2778 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0)
2780 else if (ray_cmd_is_running(sc
, SCP_UPDATESUBCMD
)) {
2781 ray_cmd_schedule(sc
, SCP_UPD_UPDATEPARAMS
);
2783 } else if (!ray_alloc_ccs(sc
, &ccs
, RAY_CMD_UPDATE_PARAMS
,
2784 SCP_UPD_UPDATEPARAMS
))
2787 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_update
, c_paramid
,
2788 sc
->sc_updreq
->r_paramid
);
2789 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_update
, c_nparam
, 1);
2790 ray_write_region(sc
, RAY_HOST_TO_ECF_BASE
, sc
->sc_updreq
->r_data
,
2791 sc
->sc_updreq
->r_len
);
2793 (void)ray_issue_cmd(sc
, ccs
, SCP_UPD_UPDATEPARAMS
);
2797 * set the multicast filter list
2800 ray_update_mcast(struct ray_softc
*sc
)
2803 struct ether_multistep step
;
2804 struct ether_multi
*enm
;
2805 struct ethercom
*ec
;
2810 ray_cmd_cancel(sc
, SCP_UPD_MCAST
);
2812 /* see if we have any ranges */
2813 if ((count
= sc
->sc_ec
.ec_multicnt
) < 17) {
2814 ETHER_FIRST_MULTI(step
, ec
, enm
);
2816 /* see if this is a range */
2817 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
,
2822 ETHER_NEXT_MULTI(step
, enm
);
2826 /* track this stuff even when not running */
2828 sc
->sc_if
.if_flags
|= IFF_ALLMULTI
;
2829 ray_update_promisc(sc
);
2831 } else if (sc
->sc_if
.if_flags
& IFF_ALLMULTI
) {
2832 sc
->sc_if
.if_flags
&= ~IFF_ALLMULTI
;
2833 ray_update_promisc(sc
);
2836 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0)
2838 else if (ray_cmd_is_running(sc
, SCP_UPDATESUBCMD
)) {
2839 ray_cmd_schedule(sc
, SCP_UPD_MCAST
);
2841 } else if (!ray_alloc_ccs(sc
,&ccs
, RAY_CMD_UPDATE_MCAST
, SCP_UPD_MCAST
))
2843 SRAM_WRITE_FIELD_1(sc
, ccs
, ray_cmd_update_mcast
, c_nmcast
, count
);
2844 bufp
= RAY_HOST_TO_ECF_BASE
;
2845 ETHER_FIRST_MULTI(step
, ec
, enm
);
2847 ray_write_region(sc
, bufp
, enm
->enm_addrlo
, ETHER_ADDR_LEN
);
2848 bufp
+= ETHER_ADDR_LEN
;
2849 ETHER_NEXT_MULTI(step
, enm
);
2851 (void)ray_issue_cmd(sc
, ccs
, SCP_UPD_MCAST
);
2855 * User issued commands
2859 * issue an "update params"
2861 * expected to be called in sleepable context -- intended for user stuff
2864 ray_user_update_params(struct ray_softc
*sc
, struct ray_param_req
*pr
)
2868 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0) {
2869 pr
->r_failcause
= RAY_FAILCAUSE_EDEVSTOP
;
2873 /* wait to be able to issue the command */
2875 while (ray_cmd_is_running(sc
, SCP_UPD_UPDATEPARAMS
) ||
2876 ray_cmd_is_scheduled(sc
, SCP_UPD_UPDATEPARAMS
)) {
2877 rv
= tsleep(ray_update_params
, 0|PCATCH
, "cmd in use", 0);
2880 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0) {
2881 pr
->r_failcause
= RAY_FAILCAUSE_EDEVSTOP
;
2886 pr
->r_failcause
= RAY_FAILCAUSE_WAITING
;
2888 ray_cmd_schedule(sc
, SCP_UPD_UPDATEPARAMS
);
2889 ray_check_scheduled(sc
);
2891 while (pr
->r_failcause
== RAY_FAILCAUSE_WAITING
)
2892 (void)tsleep(ray_update_params
, 0, "waiting cmd", 0);
2893 wakeup(ray_update_params
);
2899 * issue a report params
2901 * expected to be called in sleepable context -- intended for user stuff
2904 ray_user_report_params(struct ray_softc
*sc
, struct ray_param_req
*pr
)
2908 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0) {
2909 pr
->r_failcause
= RAY_FAILCAUSE_EDEVSTOP
;
2913 /* wait to be able to issue the command */
2915 while (ray_cmd_is_running(sc
, SCP_REPORTPARAMS
)
2916 || ray_cmd_is_scheduled(sc
, SCP_REPORTPARAMS
)) {
2917 rv
= tsleep(ray_report_params
, 0|PCATCH
, "cmd in use", 0);
2920 if ((sc
->sc_if
.if_flags
& IFF_RUNNING
) == 0) {
2921 pr
->r_failcause
= RAY_FAILCAUSE_EDEVSTOP
;
2926 pr
->r_failcause
= RAY_FAILCAUSE_WAITING
;
2928 ray_cmd_schedule(sc
, SCP_REPORTPARAMS
);
2929 ray_check_scheduled(sc
);
2931 while (pr
->r_failcause
== RAY_FAILCAUSE_WAITING
)
2932 (void)tsleep(ray_report_params
, 0, "waiting cmd", 0);
2933 wakeup(ray_report_params
);
2940 * this is a temporary wrapper around bus_space_read_region_1
2941 * as it seems to mess with gcc. the line numbers get offset
2942 * presumably this is related to the inline asm on i386.
2946 ray_read_region(struct ray_softc
*sc
, bus_size_t off
, void *vp
, size_t c
)
2948 #ifdef RAY_USE_OPTIMIZED_COPY
2954 /* XXX we may be making poor assumptions here but lets hope */
2955 switch ((off
|(bus_addr_t
)p
) & 0x03) {
2958 bus_space_read_region_4(sc
->sc_memt
, sc
->sc_memh
, off
,
2967 *p
= bus_space_read_1(sc
->sc_memt
,sc
->sc_memh
, off
);
2970 *p
= bus_space_read_1(sc
->sc_memt
,sc
->sc_memh
, off
);
2973 *p
= bus_space_read_1(sc
->sc_memt
,sc
->sc_memh
, off
);
2977 if ((n2
= (c
>> 1)))
2978 bus_space_read_region_2(sc
->sc_memt
, sc
->sc_memh
, off
,
2982 *(p
+ c
) = bus_space_read_1(sc
->sc_memt
, sc
->sc_memh
,
2988 bus_space_read_region_1(sc
->sc_memt
, sc
->sc_memh
, off
, p
, c
);
2992 bus_space_read_region_1(sc
->sc_memt
, sc
->sc_memh
, off
, vp
, c
);
2997 * this is a temporary wrapper around bus_space_write_region_1
2998 * as it seems to mess with gcc. the line numbers get offset
2999 * presumably this is related to the inline asm on i386.
3002 ray_write_region(struct ray_softc
*sc
, bus_size_t off
, void *vp
, size_t c
)
3004 #ifdef RAY_USE_OPTIMIZED_COPY
3009 /* XXX we may be making poor assumptions here but lets hope */
3010 switch ((off
|(bus_addr_t
)p
) & 0x03) {
3012 if ((n4
= (c
>> 2))) {
3013 bus_space_write_region_4(sc
->sc_memt
, sc
->sc_memh
, off
,
3022 bus_space_write_1(sc
->sc_memt
,sc
->sc_memh
, off
, *p
);
3025 bus_space_write_1(sc
->sc_memt
,sc
->sc_memh
, off
, *p
);
3028 bus_space_write_1(sc
->sc_memt
,sc
->sc_memh
, off
, *p
);
3032 if ((n2
= (c
>> 1)))
3033 bus_space_write_region_2(sc
->sc_memt
, sc
->sc_memh
, off
,
3037 bus_space_write_1(sc
->sc_memt
, sc
->sc_memh
,
3043 bus_space_write_region_1(sc
->sc_memt
, sc
->sc_memh
, off
, p
, c
);
3047 bus_space_write_region_1(sc
->sc_memt
, sc
->sc_memh
, off
, vp
, c
);
3053 #define PRINTABLE(c) ((c) >= 0x20 && (c) <= 0x7f)
3056 hexdump(const u_int8_t
*d
, int len
, int br
, int div
, int fl
)
3058 int i
, j
, offw
, first
, tlen
, ni
, nj
, sp
;
3062 if (len
&& (fl
& HEXDF_NOOFFSET
) == 0) {
3066 } while (tlen
/= br
);
3069 printf("%0*x: ", offw
, 0);
3070 for (i
= 0; i
< len
; i
++, d
++) {
3071 if (i
&& (i
% br
) == 0) {
3072 if ((fl
& HEXDF_NOASCII
) == 0) {
3075 for (j
= 0; j
< br
; d
++, j
++) {
3076 if (j
&& (j
% sp
) == 0)
3079 printf("%c", (int)*d
);
3085 printf("\n%0*x: ", offw
, i
);
3088 if ((fl
& HEXDF_NOCOMPRESS
) == 0) {
3090 while (len
- i
>= br
) {
3091 if (memcmp(d
, d
- br
, br
))
3101 printf("\n%0*x", offw
, i
);
3105 } else if (i
&& (i
% sp
) == 0)
3107 printf("%02x ", *d
);
3109 if (len
&& (((i
- 1) % br
) || i
== 1)) {
3110 if ((fl
& HEXDF_NOASCII
) == 0) {
3111 i
= i
% br
? i
% br
: br
;
3114 nj
= (div
- j
- 1) % div
;
3115 j
= 3 * ni
+ nj
+ 3;
3116 printf("%*s", j
, "");
3118 for (j
= 0; j
< i
; d
++, j
++) {
3119 if (j
&& (j
% sp
) == 0)
3122 printf("%c", (int)*d
);
3134 ray_dump_mbuf(struct ray_softc
*sc
, struct mbuf
*m
)
3139 printf("%s: pkt dump:", device_xname(&sc
->sc_dev
));
3141 for (; m
; m
= m
->m_next
) {
3142 d
= mtod(m
, u_int8_t
*);
3145 for (; d
< ed
; i
++, d
++) {
3148 else if ((i
% 8) == 0)
3150 printf(" %02x", *d
);
3156 #endif /* RAY_DEBUG */
3158 #ifdef RAY_DO_SIGLEV
3160 ray_update_siglev(struct ray_softc
*sc
, u_int8_t
*src
, u_int8_t siglev
)
3163 struct timeval mint
;
3164 struct ray_siglev
*sl
;
3166 /* try to find host */
3167 for (i
= 0; i
< RAY_NSIGLEVRECS
; i
++) {
3168 sl
= &sc
->sc_siglevs
[i
];
3169 if (memcmp(sl
->rsl_host
, src
, ETHER_ADDR_LEN
) == 0)
3172 /* not found, find oldest slot */
3174 mint
.tv_sec
= LONG_MAX
;
3176 for (i
= 0; i
< RAY_NSIGLEVRECS
; i
++) {
3177 sl
= &sc
->sc_siglevs
[i
];
3178 if (timercmp(&sl
->rsl_time
, &mint
, <)) {
3180 mint
= sl
->rsl_time
;
3183 sl
= &sc
->sc_siglevs
[mini
];
3184 memset(sl
->rsl_siglevs
, 0, RAY_NSIGLEV
);
3185 memcpy(sl
->rsl_host
, src
, ETHER_ADDR_LEN
);
3188 microtime(&sl
->rsl_time
);
3189 memmove(&sl
->rsl_siglevs
[1], sl
->rsl_siglevs
, RAY_NSIGLEV
-1);
3190 sl
->rsl_siglevs
[0] = siglev
;