2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/dev/an/if_an.c,v 1.2.2.13 2003/02/11 03:32:48 ambrisko Exp $
36 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
38 * Written by Bill Paul <wpaul@ctr.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City
44 * The Aironet 4500/4800 series cards come in PCMCIA, ISA and PCI form.
45 * This driver supports all three device types (PCI devices are supported
46 * through an extra PCI shim: /sys/dev/an/if_an_pci.c). ISA devices can be
47 * supported either using hard-coded IO port/IRQ settings or via Plug
48 * and Play. The 4500 series devices support 1Mbps and 2Mbps data rates.
49 * The 4800 devices support 1, 2, 5.5 and 11Mbps rates.
51 * Like the WaveLAN/IEEE cards, the Aironet NICs are all essentially
52 * PCMCIA devices. The ISA and PCI cards are a combination of a PCMCIA
53 * device and a PCMCIA to ISA or PCMCIA to PCI adapter card. There are
54 * a couple of important differences though:
56 * - Lucent ISA card looks to the host like a PCMCIA controller with
57 * a PCMCIA WaveLAN card inserted. This means that even desktop
58 * machines need to be configured with PCMCIA support in order to
59 * use WaveLAN/IEEE ISA cards. The Aironet cards on the other hand
60 * actually look like normal ISA and PCI devices to the host, so
61 * no PCMCIA controller support is needed
63 * The latter point results in a small gotcha. The Aironet PCMCIA
64 * cards can be configured for one of two operating modes depending
65 * on how the Vpp1 and Vpp2 programming voltages are set when the
66 * card is activated. In order to put the card in proper PCMCIA
67 * operation (where the CIS table is visible and the interface is
68 * programmed for PCMCIA operation), both Vpp1 and Vpp2 have to be
69 * set to 5 volts. FreeBSD by default doesn't set the Vpp voltages,
70 * which leaves the card in ISA/PCI mode, which prevents it from
71 * being activated as an PCMCIA device.
73 * Note that some PCMCIA controller software packages for Windows NT
74 * fail to set the voltages as well.
76 * The Aironet devices can operate in both station mode and access point
77 * mode. Typically, when programmed for station mode, the card can be set
78 * to automatically perform encapsulation/decapsulation of Ethernet II
79 * and 802.3 frames within 802.11 frames so that the host doesn't have
80 * to do it itself. This driver doesn't program the card that way: the
81 * driver handles all of the encapsulation/decapsulation itself.
87 #define ANCACHE /* enable signal strength cache */
90 #include <sys/param.h>
91 #include <sys/systm.h>
92 #include <sys/sockio.h>
94 #include <sys/kernel.h>
97 #include <sys/ucred.h>
98 #include <sys/socket.h>
100 #include <sys/syslog.h>
102 #include <sys/sysctl.h>
103 #include <sys/thread2.h>
105 #include <sys/module.h>
106 #include <sys/sysctl.h>
108 #include <sys/rman.h>
109 #include <sys/malloc.h>
112 #include <net/ifq_var.h>
113 #include <net/if_arp.h>
114 #include <net/ethernet.h>
115 #include <net/if_dl.h>
116 #include <net/if_types.h>
117 #include <net/if_media.h>
118 #include <netproto/802_11/ieee80211.h>
119 #include <netproto/802_11/ieee80211_ioctl.h>
122 #include <netinet/in.h>
123 #include <netinet/in_systm.h>
124 #include <netinet/in_var.h>
125 #include <netinet/ip.h>
130 #include <machine/md_var.h>
132 #include "if_aironet_ieee.h"
133 #include "if_anreg.h"
135 /* These are global because we need them in sys/pci/if_an_p.c. */
136 static void an_reset (struct an_softc *);
137 static int an_init_mpi350_desc (struct an_softc *);
138 static int an_ioctl (struct ifnet *, u_long, caddr_t,
140 static void an_init (void *);
141 static int an_init_tx_ring (struct an_softc *);
142 static void an_start (struct ifnet *, struct ifaltq_subque *);
143 static void an_watchdog (struct ifnet *);
144 static void an_rxeof (struct an_softc *);
145 static void an_txeof (struct an_softc *, int);
147 static void an_promisc (struct an_softc *, int);
148 static int an_cmd (struct an_softc *, int, int);
149 static int an_cmd_struct (struct an_softc *, struct an_command *,
151 static int an_read_record (struct an_softc *, struct an_ltv_gen *);
152 static int an_write_record (struct an_softc *, struct an_ltv_gen *);
153 static int an_read_data (struct an_softc *, int,
155 static int an_write_data (struct an_softc *, int,
157 static int an_seek (struct an_softc *, int, int, int);
158 static int an_alloc_nicmem (struct an_softc *, int, int *);
159 static int an_dma_malloc (struct an_softc *, bus_size_t,
160 struct an_dma_alloc *, int);
161 static void an_dma_free (struct an_softc *,
162 struct an_dma_alloc *);
163 static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
164 static void an_stats_update (void *);
165 static void an_setdef (struct an_softc *, struct an_req *);
167 static void an_cache_store (struct an_softc *, struct mbuf *,
171 /* function definitions for use with the Cisco's Linux configuration
175 static int readrids (struct ifnet*, struct aironet_ioctl*);
176 static int writerids (struct ifnet*, struct aironet_ioctl*);
177 static int flashcard (struct ifnet*, struct aironet_ioctl*);
179 static int cmdreset (struct ifnet *);
180 static int setflashmode (struct ifnet *);
181 static int flashgchar (struct ifnet *,int,int);
182 static int flashpchar (struct ifnet *,int,int);
183 static int flashputbuf (struct ifnet *);
184 static int flashrestart (struct ifnet *);
185 static int WaitBusy (struct ifnet *, int);
186 static int unstickbusy (struct ifnet *);
188 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
191 static int an_media_change (struct ifnet *);
192 static void an_media_status (struct ifnet *, struct ifmediareq *);
194 static int an_dump = 0;
195 static int an_cache_mode = 0;
201 static char an_conf[256];
202 static char an_conf_cache[256];
204 DECLARE_DUMMY_MODULE(if_an);
208 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
211 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
220 strcpy(an_conf, "off");
223 strcpy(an_conf, "type");
226 strcpy(an_conf, "dump");
229 ksnprintf(an_conf, 5, "%x", an_dump);
233 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
235 if (strncmp(an_conf,"off", 3) == 0) {
238 if (strncmp(an_conf,"dump", 4) == 0) {
241 if (strncmp(an_conf,"type", 4) == 0) {
247 if ((*s >= '0') && (*s <= '9')) {
248 r = r * 16 + (*s - '0');
249 } else if ((*s >= 'a') && (*s <= 'f')) {
250 r = r * 16 + (*s - 'a' + 10);
258 kprintf("Sysctl changed for Aironet driver\n");
263 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
264 0, sizeof(an_conf), sysctl_an_dump, "A", "");
267 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
271 switch (an_cache_mode) {
273 strcpy(an_conf_cache, "per");
276 strcpy(an_conf_cache, "raw");
279 strcpy(an_conf_cache, "dbm");
283 error = sysctl_handle_string(oidp, an_conf_cache,
284 sizeof(an_conf_cache), req);
286 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
289 if (strncmp(an_conf_cache,"per", 3) == 0) {
292 if (strncmp(an_conf_cache,"raw", 3) == 0) {
299 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
300 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
303 * We probe for an Aironet 4500/4800 card by attempting to
304 * read the default SSID list. On reset, the first entry in
305 * the SSID list will contain the name "tsunami." If we don't
306 * find this, then there's no card present.
309 an_probe(device_t dev)
311 struct an_softc *sc = device_get_softc(dev);
312 struct an_ltv_ssidlist_new ssid;
315 bzero((char *)&ssid, sizeof(ssid));
317 error = an_alloc_port(dev, 0, AN_IOSIZ);
321 /* can't do autoprobing */
322 if (rman_get_start(sc->port_res) == -1)
326 * We need to fake up a softc structure long enough
327 * to be able to issue commands and call some of the
330 sc->an_bhandle = rman_get_bushandle(sc->port_res);
331 sc->an_btag = rman_get_bustag(sc->port_res);
333 ssid.an_len = sizeof(ssid);
334 ssid.an_type = AN_RID_SSIDLIST;
336 /* Make sure interrupts are disabled. */
338 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
339 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
341 if_initname(&sc->arpcom.ac_if, device_get_name(dev),
342 device_get_unit(dev));
345 if (an_cmd(sc, AN_CMD_READCFG, 0))
348 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
351 /* See if the ssid matches what we expect ... but doesn't have to */
352 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID))
359 * Allocate a port resource with the given resource id.
362 an_alloc_port(device_t dev, int rid, int size)
364 struct an_softc *sc = device_get_softc(dev);
365 struct resource *res;
367 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
368 0ul, ~0ul, size, RF_ACTIVE);
379 * Allocate a memory resource with the given resource id.
382 an_alloc_memory(device_t dev, int rid, int size)
384 struct an_softc *sc = device_get_softc(dev);
385 struct resource *res;
387 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
388 0ul, ~0ul, size, RF_ACTIVE);
400 * Allocate a auxilary memory resource with the given resource id.
403 an_alloc_aux_memory(device_t dev, int rid, int size)
405 struct an_softc *sc = device_get_softc(dev);
406 struct resource *res;
408 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
409 0ul, ~0ul, size, RF_ACTIVE);
411 sc->mem_aux_rid = rid;
412 sc->mem_aux_res = res;
413 sc->mem_aux_used = size;
421 * Allocate an irq resource with the given resource id.
424 an_alloc_irq(device_t dev, int rid, int flags)
426 struct an_softc *sc = device_get_softc(dev);
427 struct resource *res;
429 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
430 (RF_ACTIVE | flags));
441 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
443 bus_addr_t *paddr = (bus_addr_t*) arg;
444 *paddr = segs->ds_addr;
448 * Alloc DMA memory and set the pointer to it
451 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
456 r = bus_dmamap_create(sc->an_dtag, 0, &dma->an_dma_map);
460 r = bus_dmamem_alloc(sc->an_dtag, (void*)&dma->an_dma_vaddr,
461 BUS_DMA_WAITOK, &dma->an_dma_map);
465 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
473 dma->an_dma_size = size;
477 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
479 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
481 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
482 dma->an_dma_map = NULL;
487 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
489 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
490 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
491 dma->an_dma_vaddr = NULL;
492 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
496 * Release all resources
499 an_release_resources(device_t dev)
501 struct an_softc *sc = device_get_softc(dev);
505 bus_release_resource(dev, SYS_RES_IOPORT,
506 sc->port_rid, sc->port_res);
510 bus_release_resource(dev, SYS_RES_MEMORY,
511 sc->mem_rid, sc->mem_res);
514 if (sc->mem_aux_res) {
515 bus_release_resource(dev, SYS_RES_MEMORY,
516 sc->mem_aux_rid, sc->mem_aux_res);
520 bus_release_resource(dev, SYS_RES_IRQ,
521 sc->irq_rid, sc->irq_res);
524 if (sc->an_rid_buffer.an_dma_paddr) {
525 an_dma_free(sc, &sc->an_rid_buffer);
527 for (i = 0; i < AN_MAX_RX_DESC; i++)
528 if (sc->an_rx_buffer[i].an_dma_paddr) {
529 an_dma_free(sc, &sc->an_rx_buffer[i]);
531 for (i = 0; i < AN_MAX_TX_DESC; i++)
532 if (sc->an_tx_buffer[i].an_dma_paddr) {
533 an_dma_free(sc, &sc->an_tx_buffer[i]);
536 bus_dma_tag_destroy(sc->an_dtag);
542 an_init_mpi350_desc(struct an_softc *sc)
544 struct an_command cmd_struct;
545 struct an_reply reply;
546 struct an_card_rid_desc an_rid_desc;
547 struct an_card_rx_desc an_rx_desc;
548 struct an_card_tx_desc an_tx_desc;
551 if(!sc->an_rid_buffer.an_dma_paddr)
552 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
553 &sc->an_rid_buffer, 0);
554 for (i = 0; i < AN_MAX_RX_DESC; i++)
555 if(!sc->an_rx_buffer[i].an_dma_paddr)
556 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
557 &sc->an_rx_buffer[i], 0);
558 for (i = 0; i < AN_MAX_TX_DESC; i++)
559 if(!sc->an_tx_buffer[i].an_dma_paddr)
560 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
561 &sc->an_tx_buffer[i], 0);
564 * Allocate RX descriptor
566 bzero(&reply,sizeof(reply));
567 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
568 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
569 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
570 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
571 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
572 if_printf(&sc->arpcom.ac_if,
573 "failed to allocate RX descriptor\n");
577 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
578 bzero(&an_rx_desc, sizeof(an_rx_desc));
579 an_rx_desc.an_valid = 1;
580 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
581 an_rx_desc.an_done = 0;
582 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
584 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
585 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
586 + (desc * sizeof(an_rx_desc))
588 ((u_int32_t*)(void *)&an_rx_desc)[i]);
592 * Allocate TX descriptor
595 bzero(&reply,sizeof(reply));
596 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
597 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
598 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
599 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
600 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
601 if_printf(&sc->arpcom.ac_if,
602 "failed to allocate TX descriptor\n");
606 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
607 bzero(&an_tx_desc, sizeof(an_tx_desc));
608 an_tx_desc.an_offset = 0;
609 an_tx_desc.an_eoc = 0;
610 an_tx_desc.an_valid = 0;
611 an_tx_desc.an_len = 0;
612 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
614 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
615 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
616 + (desc * sizeof(an_tx_desc))
618 ((u_int32_t*)(void *)&an_tx_desc)[i]);
622 * Allocate RID descriptor
625 bzero(&reply,sizeof(reply));
626 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
627 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
628 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
629 cmd_struct.an_parm2 = 1;
630 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
631 if_printf(&sc->arpcom.ac_if,
632 "failed to allocate host descriptor\n");
636 bzero(&an_rid_desc, sizeof(an_rid_desc));
637 an_rid_desc.an_valid = 1;
638 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
639 an_rid_desc.an_rid = 0;
640 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
642 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
643 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
644 ((u_int32_t*)(void *)&an_rid_desc)[i]);
650 an_attach(struct an_softc *sc, device_t dev, int flags)
652 struct ifnet *ifp = &sc->arpcom.ac_if;
655 callout_init(&sc->an_stat_timer);
656 sc->an_associated = 0;
658 sc->an_was_monitor = 0;
659 sc->an_flash_buffer = NULL;
662 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
667 error = an_init_mpi350_desc(sc);
672 /* Load factory config */
673 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
674 device_printf(dev, "failed to load config data\n");
678 /* Read the current configuration */
679 sc->an_config.an_type = AN_RID_GENCONFIG;
680 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
681 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
682 device_printf(dev, "read record failed\n");
686 /* Read the card capabilities */
687 sc->an_caps.an_type = AN_RID_CAPABILITIES;
688 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
689 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
690 device_printf(dev, "read record failed\n");
695 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
696 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
697 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
698 device_printf(dev, "read record failed\n");
703 sc->an_aplist.an_type = AN_RID_APLIST;
704 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
705 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
706 device_printf(dev, "read record failed\n");
711 /* Read the RSSI <-> dBm map */
712 sc->an_have_rssimap = 0;
713 if (sc->an_caps.an_softcaps & 8) {
714 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
715 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
716 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
717 device_printf(dev, "unable to get RSSI <-> dBM map\n");
719 device_printf(dev, "got RSSI <-> dBM map\n");
720 sc->an_have_rssimap = 1;
723 device_printf(dev, "no RSSI <-> dBM map\n");
727 ifp->if_mtu = ETHERMTU;
728 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
729 ifp->if_ioctl = an_ioctl;
730 ifp->if_start = an_start;
731 ifp->if_watchdog = an_watchdog;
732 ifp->if_init = an_init;
733 ifp->if_baudrate = 10000000;
734 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
735 ifq_set_ready(&ifp->if_snd);
737 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
738 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
739 sizeof(AN_DEFAULT_NODENAME) - 1);
741 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
742 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
743 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
744 sizeof(AN_DEFAULT_NETNAME) - 1);
745 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
747 sc->an_config.an_opmode =
748 AN_OPMODE_INFRASTRUCTURE_STATION;
751 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
753 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
754 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
755 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
756 IFM_IEEE80211_ADHOC, 0), 0);
757 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
758 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
759 IFM_IEEE80211_ADHOC, 0), 0);
760 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
761 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
762 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
763 IFM_IEEE80211_ADHOC, 0), 0);
764 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
766 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
767 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
768 IFM_IEEE80211_ADHOC, 0), 0);
769 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
771 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
772 IFM_IEEE80211_ADHOC, 0), 0);
773 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
775 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
779 * Call MI attach routine.
781 ether_ifattach(ifp, sc->an_caps.an_oemaddr, NULL);
787 an_detach(device_t dev)
789 struct an_softc *sc = device_get_softc(dev);
790 struct ifnet *ifp = &sc->arpcom.ac_if;
792 lwkt_serialize_enter(ifp->if_serializer);
794 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
795 lwkt_serialize_exit(ifp->if_serializer);
797 ifmedia_removeall(&sc->an_ifmedia);
799 an_release_resources(dev);
804 an_rxeof(struct an_softc *sc)
807 struct ether_header *eh;
808 struct ieee80211_frame *ih;
809 struct an_rxframe rx_frame;
810 struct an_rxframe_802_3 rx_frame_802_3;
812 int len, id, error = 0, i, count = 0;
813 int ieee80211_header_len;
816 struct an_card_rx_desc an_rx_desc;
819 ifp = &sc->arpcom.ac_if;
822 id = CSR_READ_2(sc, AN_RX_FID);
824 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
825 /* read raw 802.11 packet */
826 bpf_buf = sc->buf_802_11;
829 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
831 IFNET_STAT_INC(ifp, ierrors, 1);
836 * skip beacon by default since this increases the
840 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
841 (rx_frame.an_frame_ctl &
842 IEEE80211_FC0_SUBTYPE_BEACON)) {
846 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
847 len = rx_frame.an_rx_payload_len
849 /* Check for insane frame length */
850 if (len > sizeof(sc->buf_802_11)) {
852 "oversized packet received "
853 "(%d, %d)\n", len, MCLBYTES);
854 IFNET_STAT_INC(ifp, ierrors, 1);
858 bcopy((char *)&rx_frame,
859 bpf_buf, sizeof(rx_frame));
861 error = an_read_data(sc, id, sizeof(rx_frame),
862 (caddr_t)bpf_buf+sizeof(rx_frame),
863 rx_frame.an_rx_payload_len);
865 fc1=rx_frame.an_frame_ctl >> 8;
866 ieee80211_header_len =
867 sizeof(struct ieee80211_frame);
868 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
869 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
870 ieee80211_header_len += ETHER_ADDR_LEN;
873 len = rx_frame.an_rx_payload_len
874 + ieee80211_header_len;
875 /* Check for insane frame length */
876 if (len > sizeof(sc->buf_802_11)) {
878 "oversized packet received "
879 "(%d, %d)\n", len, MCLBYTES);
880 IFNET_STAT_INC(ifp, ierrors, 1);
884 ih = (struct ieee80211_frame *)bpf_buf;
886 bcopy((char *)&rx_frame.an_frame_ctl,
887 (char *)ih, ieee80211_header_len);
889 error = an_read_data(sc, id, sizeof(rx_frame) +
891 (caddr_t)ih +ieee80211_header_len,
892 rx_frame.an_rx_payload_len);
894 BPF_TAP(ifp, bpf_buf, len);
896 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
898 IFNET_STAT_INC(ifp, ierrors, 1);
901 m->m_pkthdr.rcvif = ifp;
902 /* Read Ethernet encapsulated packet */
905 /* Read NIC frame header */
906 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
908 IFNET_STAT_INC(ifp, ierrors, 1);
912 /* Read in the 802_3 frame header */
913 if (an_read_data(sc, id, 0x34,
914 (caddr_t)&rx_frame_802_3,
915 sizeof(rx_frame_802_3))) {
916 IFNET_STAT_INC(ifp, ierrors, 1);
919 if (rx_frame_802_3.an_rx_802_3_status != 0) {
920 IFNET_STAT_INC(ifp, ierrors, 1);
923 /* Check for insane frame length */
924 len = rx_frame_802_3.an_rx_802_3_payload_len;
925 if (len > sizeof(sc->buf_802_11)) {
927 "oversized packet received (%d, %d)\n",
929 IFNET_STAT_INC(ifp, ierrors, 1);
932 m->m_pkthdr.len = m->m_len =
933 rx_frame_802_3.an_rx_802_3_payload_len + 12;
935 eh = mtod(m, struct ether_header *);
937 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
938 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
939 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
940 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
942 /* in mbuf header type is just before payload */
943 error = an_read_data(sc, id, 0x44,
944 (caddr_t)&(eh->ether_type),
945 rx_frame_802_3.an_rx_802_3_payload_len);
949 IFNET_STAT_INC(ifp, ierrors, 1);
952 IFNET_STAT_INC(ifp, ipackets, 1);
955 an_cache_store(sc, m,
956 rx_frame.an_rx_signal_strength,
959 ifp->if_input(ifp, m);
962 } else { /* MPI-350 */
963 for (count = 0; count < AN_MAX_RX_DESC; count++){
964 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
965 ((u_int32_t*)(void *)&an_rx_desc)[i]
966 = CSR_MEM_AUX_READ_4(sc,
968 + (count * sizeof(an_rx_desc))
971 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
972 buf = sc->an_rx_buffer[count].an_dma_vaddr;
974 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
976 IFNET_STAT_INC(ifp, ierrors, 1);
979 m->m_pkthdr.rcvif = ifp;
980 /* Read Ethernet encapsulated packet */
983 * No ANCACHE support since we just get back
984 * an Ethernet packet no 802.11 info
988 /* Read NIC frame header */
989 bcopy(buf, (caddr_t)&rx_frame,
993 /* Check for insane frame length */
994 len = an_rx_desc.an_len + 12;
995 if (len > MCLBYTES) {
997 "oversized packet received "
998 "(%d, %d)\n", len, MCLBYTES);
999 IFNET_STAT_INC(ifp, ierrors, 1);
1003 m->m_pkthdr.len = m->m_len =
1004 an_rx_desc.an_len + 12;
1006 eh = mtod(m, struct ether_header *);
1008 bcopy(buf, (char *)eh,
1011 IFNET_STAT_INC(ifp, ipackets, 1);
1015 an_cache_store(sc, m,
1016 rx_frame.an_rx_signal_strength,
1020 ifp->if_input(ifp, m);
1022 an_rx_desc.an_valid = 1;
1023 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1024 an_rx_desc.an_done = 0;
1025 an_rx_desc.an_phys =
1026 sc->an_rx_buffer[count].an_dma_paddr;
1028 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1029 CSR_MEM_AUX_WRITE_4(sc,
1031 + (count * sizeof(an_rx_desc))
1033 ((u_int32_t*)(void *)&an_rx_desc)[i]);
1036 if_printf(ifp, "Didn't get valid RX packet "
1039 an_rx_desc.an_valid,
1047 an_txeof(struct an_softc *sc, int status)
1052 ifp = &sc->arpcom.ac_if;
1055 ifq_clr_oactive(&ifp->if_snd);
1058 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1060 if (status & AN_EV_TX_EXC) {
1061 IFNET_STAT_INC(ifp, oerrors, 1);
1063 IFNET_STAT_INC(ifp, opackets, 1);
1065 for (i = 0; i < AN_TX_RING_CNT; i++) {
1066 if (id == sc->an_rdata.an_tx_ring[i]) {
1067 sc->an_rdata.an_tx_ring[i] = 0;
1072 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1073 } else { /* MPI 350 */
1074 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1075 if (!sc->an_rdata.an_tx_empty){
1076 if (status & AN_EV_TX_EXC) {
1077 IFNET_STAT_INC(ifp, oerrors, 1);
1079 IFNET_STAT_INC(ifp, opackets, 1);
1080 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1081 if (sc->an_rdata.an_tx_prod ==
1082 sc->an_rdata.an_tx_cons)
1083 sc->an_rdata.an_tx_empty = 1;
1089 * We abuse the stats updater to check the current NIC status. This
1090 * is important because we don't want to allow transmissions until
1091 * the NIC has synchronized to the current cell (either as the master
1092 * in an ad-hoc group, or as a station connected to an access point).
1095 an_stats_update(void *xsc)
1097 struct an_softc *sc;
1101 ifp = &sc->arpcom.ac_if;
1103 lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer);
1105 sc->an_status.an_type = AN_RID_STATUS;
1106 sc->an_status.an_len = sizeof(struct an_ltv_status);
1107 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1109 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1110 sc->an_associated = 1;
1112 sc->an_associated = 0;
1114 /* Don't do this while we're not transmitting */
1115 if (!ifq_is_oactive(&ifp->if_snd)) {
1116 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1117 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1118 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1121 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1123 lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer);
1129 struct an_softc *sc;
1133 sc = (struct an_softc*)xsc;
1135 ifp = &sc->arpcom.ac_if;
1137 /* Disable interrupts. */
1138 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1140 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1141 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1143 if (status & AN_EV_MIC)
1144 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1146 if (status & AN_EV_LINKSTAT) {
1147 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1148 == AN_LINKSTAT_ASSOCIATED)
1149 sc->an_associated = 1;
1151 sc->an_associated = 0;
1152 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1155 if (status & AN_EV_RX) {
1157 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1160 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1161 an_txeof(sc, status);
1162 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1165 if (status & AN_EV_TX) {
1166 an_txeof(sc, status);
1167 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1170 if (status & AN_EV_TX_EXC) {
1171 an_txeof(sc, status);
1172 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1175 if (status & AN_EV_ALLOC)
1176 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1178 /* Re-enable interrupts. */
1179 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1181 if ((ifp->if_flags & IFF_UP) && !ifq_is_empty(&ifp->if_snd))
1186 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1187 struct an_reply *reply)
1191 for (i = 0; i != AN_TIMEOUT; i++) {
1192 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1197 if( i == AN_TIMEOUT) {
1202 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1203 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1204 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1205 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1207 for (i = 0; i < AN_TIMEOUT; i++) {
1208 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1213 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1214 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1215 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1216 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1218 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1219 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1221 /* Ack the command */
1222 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1224 if (i == AN_TIMEOUT)
1231 an_cmd(struct an_softc *sc, int cmd, int val)
1235 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1236 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1237 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1238 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1240 for (i = 0; i < AN_TIMEOUT; i++) {
1241 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1244 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1245 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1249 for (i = 0; i < AN_TIMEOUT; i++) {
1250 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1251 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1252 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1253 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1254 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1258 /* Ack the command */
1259 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1261 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1262 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1264 if (i == AN_TIMEOUT)
1271 * This reset sequence may look a little strange, but this is the
1272 * most reliable method I've found to really kick the NIC in the
1273 * head and force it to reboot correctly.
1276 an_reset(struct an_softc *sc)
1278 an_cmd(sc, AN_CMD_ENABLE, 0);
1279 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1280 an_cmd(sc, AN_CMD_NOOP2, 0);
1282 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1283 if_printf(&sc->arpcom.ac_if, "reset failed\n");
1285 an_cmd(sc, AN_CMD_DISABLE, 0);
1291 * Read an LTV record from the NIC.
1294 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1296 struct an_ltv_gen *an_ltv;
1297 struct an_card_rid_desc an_rid_desc;
1298 struct an_command cmd;
1299 struct an_reply reply;
1304 if (ltv->an_len < 4 || ltv->an_type == 0)
1308 /* Tell the NIC to enter record read mode. */
1309 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1310 if_printf(&sc->arpcom.ac_if, "RID access failed\n");
1314 /* Seek to the record. */
1315 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1316 if_printf(&sc->arpcom.ac_if, "seek to record failed\n");
1321 * Read the length and record type and make sure they
1322 * match what we expect (this verifies that we have enough
1323 * room to hold all of the returned data).
1324 * Length includes type but not length.
1326 len = CSR_READ_2(sc, AN_DATA1);
1327 if (len > (ltv->an_len - 2)) {
1328 if_printf(&sc->arpcom.ac_if,
1329 "record length mismatch -- expected %d, "
1330 "got %d for Rid %x\n",
1331 ltv->an_len - 2, len, ltv->an_type);
1332 len = ltv->an_len - 2;
1334 ltv->an_len = len + 2;
1337 /* Now read the data. */
1338 len -= 2; /* skip the type */
1340 for (i = len; i > 1; i -= 2)
1341 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1343 ptr2 = (u_int8_t *)ptr;
1344 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1346 } else { /* MPI-350 */
1347 if (sc->an_rid_buffer.an_dma_vaddr == NULL)
1349 an_rid_desc.an_valid = 1;
1350 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1351 an_rid_desc.an_rid = 0;
1352 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1353 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1355 bzero(&cmd, sizeof(cmd));
1356 bzero(&reply, sizeof(reply));
1357 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1358 cmd.an_parm0 = ltv->an_type;
1360 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1361 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1362 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1364 if (an_cmd_struct(sc, &cmd, &reply)
1365 || reply.an_status & AN_CMD_QUAL_MASK) {
1366 if_printf(&sc->arpcom.ac_if,
1367 "failed to read RID %x %x %x %x %x, %d\n",
1377 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1378 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1379 an_rid_desc.an_len = an_ltv->an_len;
1382 len = an_rid_desc.an_len;
1383 if (len > (ltv->an_len - 2)) {
1384 if_printf(&sc->arpcom.ac_if,
1385 "record length mismatch -- expected %d, "
1386 "got %d for Rid %x\n",
1387 ltv->an_len - 2, len, ltv->an_type);
1388 len = ltv->an_len - 2;
1390 ltv->an_len = len + 2;
1392 bcopy(&an_ltv->an_type, <v->an_val, len);
1396 an_dump_record(sc, ltv, "Read");
1402 * Same as read, except we inject data instead of reading it.
1405 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1407 struct an_card_rid_desc an_rid_desc;
1408 struct an_command cmd;
1409 struct an_reply reply;
1415 an_dump_record(sc, ltv, "Write");
1418 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1421 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1425 * Length includes type but not length.
1427 len = ltv->an_len - 2;
1428 CSR_WRITE_2(sc, AN_DATA1, len);
1430 len -= 2; /* skip the type */
1432 for (i = len; i > 1; i -= 2)
1433 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1435 ptr2 = (u_int8_t *)ptr;
1436 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1439 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1444 for (i = 0; i != AN_TIMEOUT; i++) {
1445 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1451 if (i == AN_TIMEOUT) {
1455 an_rid_desc.an_valid = 1;
1456 an_rid_desc.an_len = ltv->an_len - 2;
1457 an_rid_desc.an_rid = ltv->an_type;
1458 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1460 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1461 an_rid_desc.an_len);
1463 bzero(&cmd,sizeof(cmd));
1464 bzero(&reply,sizeof(reply));
1465 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1466 cmd.an_parm0 = ltv->an_type;
1468 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1469 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1470 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1472 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1473 if_printf(&sc->arpcom.ac_if,
1474 "failed to write RID 1 %x %x %x %x %x, %d\n",
1484 if (reply.an_status & AN_CMD_QUAL_MASK) {
1485 if_printf(&sc->arpcom.ac_if,
1486 "failed to write RID 2 %x %x %x %x %x, %d\n",
1501 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1509 len = ltv->an_len - 4;
1510 if_printf(&sc->arpcom.ac_if, "RID %4x, Length %4d, Mode %s\n",
1511 ltv->an_type, ltv->an_len - 4, string);
1513 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1514 if_printf(&sc->arpcom.ac_if, "\t");
1515 bzero(buf,sizeof(buf));
1517 ptr2 = (u_int8_t *)<v->an_val;
1518 for (i = len; i > 0; i--) {
1519 kprintf("%02x ", *ptr2);
1522 if (temp >= ' ' && temp <= '~')
1524 else if (temp >= 'A' && temp <= 'Z')
1528 if (++count == 16) {
1530 kprintf("%s\n",buf);
1531 if_printf(&sc->arpcom.ac_if, "\t");
1532 bzero(buf,sizeof(buf));
1535 for (; count != 16; count++) {
1538 kprintf(" %s\n",buf);
1543 an_seek(struct an_softc *sc, int id, int off, int chan)
1558 if_printf(&sc->arpcom.ac_if, "invalid data path: %x\n", chan);
1562 CSR_WRITE_2(sc, selreg, id);
1563 CSR_WRITE_2(sc, offreg, off);
1565 for (i = 0; i < AN_TIMEOUT; i++) {
1566 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1570 if (i == AN_TIMEOUT)
1577 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1584 if (an_seek(sc, id, off, AN_BAP1))
1588 ptr = (u_int16_t *)buf;
1589 for (i = len; i > 1; i -= 2)
1590 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1592 ptr2 = (u_int8_t *)ptr;
1593 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1600 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1607 if (an_seek(sc, id, off, AN_BAP0))
1611 ptr = (u_int16_t *)buf;
1612 for (i = len; i > 1; i -= 2)
1613 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1615 ptr2 = (u_int8_t *)ptr;
1616 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1623 * Allocate a region of memory inside the NIC and zero
1627 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1631 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1632 if_printf(&sc->arpcom.ac_if,
1633 "failed to allocate %d bytes on NIC\n", len);
1637 for (i = 0; i < AN_TIMEOUT; i++) {
1638 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1642 if (i == AN_TIMEOUT)
1645 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1646 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1648 if (an_seek(sc, *id, 0, AN_BAP0))
1651 for (i = 0; i < len / 2; i++)
1652 CSR_WRITE_2(sc, AN_DATA0, 0);
1658 an_setdef(struct an_softc *sc, struct an_req *areq)
1661 struct an_ltv_genconfig *cfg;
1662 struct an_ltv_ssidlist_new *ssid;
1663 struct an_ltv_aplist *ap;
1664 struct an_ltv_gen *sp;
1666 ifp = &sc->arpcom.ac_if;
1668 switch (areq->an_type) {
1669 case AN_RID_GENCONFIG:
1670 cfg = (struct an_ltv_genconfig *)areq;
1672 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1674 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
1676 bcopy((char *)cfg, (char *)&sc->an_config,
1677 sizeof(struct an_ltv_genconfig));
1679 case AN_RID_SSIDLIST:
1680 ssid = (struct an_ltv_ssidlist_new *)areq;
1681 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1682 sizeof(struct an_ltv_ssidlist_new));
1685 ap = (struct an_ltv_aplist *)areq;
1686 bcopy((char *)ap, (char *)&sc->an_aplist,
1687 sizeof(struct an_ltv_aplist));
1689 case AN_RID_TX_SPEED:
1690 sp = (struct an_ltv_gen *)areq;
1691 sc->an_tx_rate = sp->an_val;
1693 /* Read the current configuration */
1694 sc->an_config.an_type = AN_RID_GENCONFIG;
1695 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1696 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1697 cfg = &sc->an_config;
1699 /* clear other rates and set the only one we want */
1700 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1701 cfg->an_rates[0] = sc->an_tx_rate;
1703 /* Save the new rate */
1704 sc->an_config.an_type = AN_RID_GENCONFIG;
1705 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1707 case AN_RID_WEP_TEMP:
1708 /* Cache the temp keys */
1710 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1711 sizeof(struct an_ltv_key));
1712 case AN_RID_WEP_PERM:
1713 case AN_RID_LEAPUSERNAME:
1714 case AN_RID_LEAPPASSWORD:
1717 /* Disable the MAC. */
1718 an_cmd(sc, AN_CMD_DISABLE, 0);
1721 an_write_record(sc, (struct an_ltv_gen *)areq);
1723 /* Turn the MAC back on. */
1724 an_cmd(sc, AN_CMD_ENABLE, 0);
1727 case AN_RID_MONITOR_MODE:
1728 cfg = (struct an_ltv_genconfig *)areq;
1730 if (ng_ether_detach_p != NULL)
1731 (*ng_ether_detach_p) (ifp);
1732 sc->an_monitor = cfg->an_len;
1734 if (sc->an_monitor & AN_MONITOR) {
1735 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1736 bpfattach(ifp, DLT_AIRONET_HEADER,
1737 sizeof(struct ether_header));
1739 bpfattach(ifp, DLT_IEEE802_11,
1740 sizeof(struct ether_header));
1743 bpfattach(ifp, DLT_EN10MB,
1744 sizeof(struct ether_header));
1745 if (ng_ether_attach_p != NULL)
1746 (*ng_ether_attach_p) (ifp);
1750 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1755 /* Reinitialize the card. */
1763 * Derived from Linux driver to enable promiscious mode.
1767 an_promisc(struct an_softc *sc, int promisc)
1769 if (sc->an_was_monitor)
1772 an_init_mpi350_desc(sc);
1773 if (sc->an_monitor || sc->an_was_monitor)
1776 sc->an_was_monitor = sc->an_monitor;
1777 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1783 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
1788 struct an_softc *sc;
1790 struct ieee80211req *ireq;
1791 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1793 struct an_ltv_genconfig *config;
1794 struct an_ltv_key *key;
1795 struct an_ltv_status *status;
1796 struct an_ltv_ssidlist_new *ssids;
1798 struct aironet_ioctl l_ioctl;
1801 ifr = (struct ifreq *)data;
1802 ireq = (struct ieee80211req *)data;
1804 config = (struct an_ltv_genconfig *)&sc->areq;
1805 key = (struct an_ltv_key *)&sc->areq;
1806 status = (struct an_ltv_status *)&sc->areq;
1807 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1811 if (ifp->if_flags & IFF_UP) {
1812 if (ifp->if_flags & IFF_RUNNING &&
1813 ifp->if_flags & IFF_PROMISC &&
1814 !(sc->an_if_flags & IFF_PROMISC)) {
1816 } else if (ifp->if_flags & IFF_RUNNING &&
1817 !(ifp->if_flags & IFF_PROMISC) &&
1818 sc->an_if_flags & IFF_PROMISC) {
1823 if (ifp->if_flags & IFF_RUNNING)
1826 sc->an_if_flags = ifp->if_flags;
1831 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1835 /* The Aironet has no multicast filter. */
1839 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1843 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1844 error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY);
1847 sc->an_sigitems = sc->an_nextitem = 0;
1849 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1850 char *pt = (char *)&sc->areq.an_val;
1851 bcopy((char *)&sc->an_sigitems, (char *)pt,
1854 sc->areq.an_len = sizeof(int) / 2;
1855 bcopy((char *)&sc->an_sigcache, (char *)pt,
1856 sizeof(struct an_sigcache) * sc->an_sigitems);
1857 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1858 sc->an_sigitems) / 2) + 1;
1861 if (an_read_record(sc, (struct an_ltv_gen *)(void *)&sc->areq)) {
1865 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1868 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
1870 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1873 an_setdef(sc, &sc->areq);
1875 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1876 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
1878 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1879 mode = l_ioctl.command;
1881 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1882 error = readrids(ifp, &l_ioctl);
1883 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1884 error = writerids(ifp, &l_ioctl);
1885 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1886 error = flashcard(ifp, &l_ioctl);
1891 /* copy out the updated command info */
1892 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1895 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1896 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
1898 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1899 l_ioctl.command = 0;
1901 copyout(&error, l_ioctl.data, sizeof(error));
1905 sc->areq.an_len = sizeof(sc->areq);
1906 /* was that a good idea DJA we are doing a short-cut */
1907 switch (ireq->i_type) {
1908 case IEEE80211_IOC_SSID:
1909 if (ireq->i_val == -1) {
1910 sc->areq.an_type = AN_RID_STATUS;
1911 if (an_read_record(sc,
1912 (struct an_ltv_gen *)(void *)&sc->areq)) {
1916 len = status->an_ssidlen;
1917 tmpptr = status->an_ssid;
1918 } else if (ireq->i_val >= 0) {
1919 sc->areq.an_type = AN_RID_SSIDLIST;
1920 if (an_read_record(sc,
1921 (struct an_ltv_gen *)(void *)&sc->areq)) {
1925 max = (sc->areq.an_len - 4)
1926 / sizeof(struct an_ltv_ssid_entry);
1927 if ( max > MAX_SSIDS ) {
1928 kprintf("To many SSIDs only using "
1933 if (ireq->i_val > max) {
1937 len = ssids->an_entry[ireq->i_val].an_len;
1938 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
1944 if (len > IEEE80211_NWID_LEN) {
1949 bzero(tmpstr, IEEE80211_NWID_LEN);
1950 bcopy(tmpptr, tmpstr, len);
1951 error = copyout(tmpstr, ireq->i_data,
1952 IEEE80211_NWID_LEN);
1954 case IEEE80211_IOC_NUMSSIDS:
1955 sc->areq.an_len = sizeof(sc->areq);
1956 sc->areq.an_type = AN_RID_SSIDLIST;
1957 if (an_read_record(sc,
1958 (struct an_ltv_gen *)(void *)&sc->areq)) {
1962 max = (sc->areq.an_len - 4)
1963 / sizeof(struct an_ltv_ssid_entry);
1964 if (max > MAX_SSIDS) {
1965 kprintf("To many SSIDs only using "
1972 case IEEE80211_IOC_WEP:
1973 sc->areq.an_type = AN_RID_ACTUALCFG;
1974 if (an_read_record(sc,
1975 (struct an_ltv_gen *)(void *)&sc->areq)) {
1979 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
1980 if (config->an_authtype &
1981 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
1982 ireq->i_val = IEEE80211_WEP_MIXED;
1984 ireq->i_val = IEEE80211_WEP_ON;
1986 ireq->i_val = IEEE80211_WEP_OFF;
1989 case IEEE80211_IOC_WEPKEY:
1991 * XXX: I'm not entierly convinced this is
1992 * correct, but it's what is implemented in
1993 * ancontrol so it will have to do until we get
1994 * access to actual Cisco code.
1996 if (ireq->i_val < 0 || ireq->i_val > 8) {
2001 if (ireq->i_val < 5) {
2002 sc->areq.an_type = AN_RID_WEP_TEMP;
2003 for (i = 0; i < 5; i++) {
2004 if (an_read_record(sc,
2005 (struct an_ltv_gen *)(void *)&sc->areq)) {
2009 if (key->kindex == 0xffff)
2011 if (key->kindex == ireq->i_val)
2013 /* Required to get next entry */
2014 sc->areq.an_type = AN_RID_WEP_PERM;
2019 /* We aren't allowed to read the value of the
2020 * key from the card so we just output zeros
2021 * like we would if we could read the card, but
2022 * denied the user access.
2026 error = copyout(tmpstr, ireq->i_data, len);
2028 case IEEE80211_IOC_NUMWEPKEYS:
2029 ireq->i_val = 9; /* include home key */
2031 case IEEE80211_IOC_WEPTXKEY:
2033 * For some strange reason, you have to read all
2034 * keys before you can read the txkey.
2036 sc->areq.an_type = AN_RID_WEP_TEMP;
2037 for (i = 0; i < 5; i++) {
2038 if (an_read_record(sc,
2039 (struct an_ltv_gen *)(void *)&sc->areq)) {
2043 if (key->kindex == 0xffff)
2045 /* Required to get next entry */
2046 sc->areq.an_type = AN_RID_WEP_PERM;
2051 sc->areq.an_type = AN_RID_WEP_PERM;
2052 key->kindex = 0xffff;
2053 if (an_read_record(sc,
2054 (struct an_ltv_gen *)(void *)&sc->areq)) {
2058 ireq->i_val = key->mac[0];
2060 * Check for home mode. Map home mode into
2061 * 5th key since that is how it is stored on
2064 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2065 sc->areq.an_type = AN_RID_GENCONFIG;
2066 if (an_read_record(sc,
2067 (struct an_ltv_gen *)(void *)&sc->areq)) {
2071 if (config->an_home_product & AN_HOME_NETWORK)
2074 case IEEE80211_IOC_AUTHMODE:
2075 sc->areq.an_type = AN_RID_ACTUALCFG;
2076 if (an_read_record(sc,
2077 (struct an_ltv_gen *)(void *)&sc->areq)) {
2081 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2083 ireq->i_val = IEEE80211_AUTH_NONE;
2084 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2086 ireq->i_val = IEEE80211_AUTH_OPEN;
2087 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2088 AN_AUTHTYPE_SHAREDKEY) {
2089 ireq->i_val = IEEE80211_AUTH_SHARED;
2093 case IEEE80211_IOC_STATIONNAME:
2094 sc->areq.an_type = AN_RID_ACTUALCFG;
2095 if (an_read_record(sc,
2096 (struct an_ltv_gen *)(void *)&sc->areq)) {
2100 ireq->i_len = sizeof(config->an_nodename);
2101 tmpptr = config->an_nodename;
2102 bzero(tmpstr, IEEE80211_NWID_LEN);
2103 bcopy(tmpptr, tmpstr, ireq->i_len);
2104 error = copyout(tmpstr, ireq->i_data,
2105 IEEE80211_NWID_LEN);
2107 case IEEE80211_IOC_CHANNEL:
2108 sc->areq.an_type = AN_RID_STATUS;
2109 if (an_read_record(sc,
2110 (struct an_ltv_gen *)(void *)&sc->areq)) {
2114 ireq->i_val = status->an_cur_channel;
2116 case IEEE80211_IOC_POWERSAVE:
2117 sc->areq.an_type = AN_RID_ACTUALCFG;
2118 if (an_read_record(sc,
2119 (struct an_ltv_gen *)(void *)&sc->areq)) {
2123 if (config->an_psave_mode == AN_PSAVE_NONE) {
2124 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2125 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2126 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2127 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2128 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2129 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2130 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2134 case IEEE80211_IOC_POWERSAVESLEEP:
2135 sc->areq.an_type = AN_RID_ACTUALCFG;
2136 if (an_read_record(sc,
2137 (struct an_ltv_gen *)(void *)&sc->areq)) {
2141 ireq->i_val = config->an_listen_interval;
2146 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
2148 sc->areq.an_len = sizeof(sc->areq);
2150 * We need a config structure for everything but the WEP
2151 * key management and SSIDs so we get it now so avoid
2152 * duplicating this code every time.
2154 if (ireq->i_type != IEEE80211_IOC_SSID &&
2155 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2156 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2157 sc->areq.an_type = AN_RID_GENCONFIG;
2158 if (an_read_record(sc,
2159 (struct an_ltv_gen *)(void *)&sc->areq)) {
2164 switch (ireq->i_type) {
2165 case IEEE80211_IOC_SSID:
2166 sc->areq.an_len = sizeof(sc->areq);
2167 sc->areq.an_type = AN_RID_SSIDLIST;
2168 if (an_read_record(sc,
2169 (struct an_ltv_gen *)(void *)&sc->areq)) {
2173 if (ireq->i_len > IEEE80211_NWID_LEN) {
2177 max = (sc->areq.an_len - 4)
2178 / sizeof(struct an_ltv_ssid_entry);
2179 if (max > MAX_SSIDS) {
2180 kprintf("To many SSIDs only using "
2185 if (ireq->i_val > max) {
2189 error = copyin(ireq->i_data,
2190 ssids->an_entry[ireq->i_val].an_ssid,
2192 ssids->an_entry[ireq->i_val].an_len
2197 case IEEE80211_IOC_WEP:
2198 switch (ireq->i_val) {
2199 case IEEE80211_WEP_OFF:
2200 config->an_authtype &=
2201 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2202 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2204 case IEEE80211_WEP_ON:
2205 config->an_authtype |=
2206 AN_AUTHTYPE_PRIVACY_IN_USE;
2207 config->an_authtype &=
2208 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2210 case IEEE80211_WEP_MIXED:
2211 config->an_authtype |=
2212 AN_AUTHTYPE_PRIVACY_IN_USE |
2213 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2220 case IEEE80211_IOC_WEPKEY:
2221 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2226 error = copyin(ireq->i_data, tmpstr, 13);
2230 * Map the 9th key into the home mode
2231 * since that is how it is stored on
2234 bzero(&sc->areq, sizeof(struct an_ltv_key));
2235 sc->areq.an_len = sizeof(struct an_ltv_key);
2236 key->mac[0] = 1; /* The others are 0. */
2237 if (ireq->i_val < 4) {
2238 sc->areq.an_type = AN_RID_WEP_TEMP;
2239 key->kindex = ireq->i_val;
2241 sc->areq.an_type = AN_RID_WEP_PERM;
2242 key->kindex = ireq->i_val - 4;
2244 key->klen = ireq->i_len;
2245 bcopy(tmpstr, key->key, key->klen);
2247 case IEEE80211_IOC_WEPTXKEY:
2248 if (ireq->i_val < 0 || ireq->i_val > 4) {
2254 * Map the 5th key into the home mode
2255 * since that is how it is stored on
2258 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2259 sc->areq.an_type = AN_RID_ACTUALCFG;
2260 if (an_read_record(sc,
2261 (struct an_ltv_gen *)(void *)&sc->areq)) {
2265 if (ireq->i_val == 4) {
2266 config->an_home_product |= AN_HOME_NETWORK;
2269 config->an_home_product &= ~AN_HOME_NETWORK;
2272 sc->an_config.an_home_product
2273 = config->an_home_product;
2275 /* update configuration */
2278 bzero(&sc->areq, sizeof(struct an_ltv_key));
2279 sc->areq.an_len = sizeof(struct an_ltv_key);
2280 sc->areq.an_type = AN_RID_WEP_PERM;
2281 key->kindex = 0xffff;
2282 key->mac[0] = ireq->i_val;
2284 case IEEE80211_IOC_AUTHMODE:
2285 switch (ireq->i_val) {
2286 case IEEE80211_AUTH_NONE:
2287 config->an_authtype = AN_AUTHTYPE_NONE |
2288 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2290 case IEEE80211_AUTH_OPEN:
2291 config->an_authtype = AN_AUTHTYPE_OPEN |
2292 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2294 case IEEE80211_AUTH_SHARED:
2295 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2296 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2302 case IEEE80211_IOC_STATIONNAME:
2303 if (ireq->i_len > 16) {
2307 bzero(config->an_nodename, 16);
2308 error = copyin(ireq->i_data,
2309 config->an_nodename, ireq->i_len);
2311 case IEEE80211_IOC_CHANNEL:
2313 * The actual range is 1-14, but if you set it
2314 * to 0 you get the default so we let that work
2317 if (ireq->i_val < 0 || ireq->i_val >14) {
2321 config->an_ds_channel = ireq->i_val;
2323 case IEEE80211_IOC_POWERSAVE:
2324 switch (ireq->i_val) {
2325 case IEEE80211_POWERSAVE_OFF:
2326 config->an_psave_mode = AN_PSAVE_NONE;
2328 case IEEE80211_POWERSAVE_CAM:
2329 config->an_psave_mode = AN_PSAVE_CAM;
2331 case IEEE80211_POWERSAVE_PSP:
2332 config->an_psave_mode = AN_PSAVE_PSP;
2334 case IEEE80211_POWERSAVE_PSP_CAM:
2335 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2342 case IEEE80211_IOC_POWERSAVESLEEP:
2343 config->an_listen_interval = ireq->i_val;
2348 an_setdef(sc, &sc->areq);
2351 error = ether_ioctl(ifp, command, data);
2359 an_init_tx_ring(struct an_softc *sc)
2365 for (i = 0; i < AN_TX_RING_CNT; i++) {
2366 if (an_alloc_nicmem(sc, 1518 +
2369 sc->an_rdata.an_tx_fids[i] = id;
2370 sc->an_rdata.an_tx_ring[i] = 0;
2374 sc->an_rdata.an_tx_prod = 0;
2375 sc->an_rdata.an_tx_cons = 0;
2376 sc->an_rdata.an_tx_empty = 1;
2384 struct an_softc *sc = xsc;
2385 struct ifnet *ifp = &sc->arpcom.ac_if;
2387 if (ifp->if_flags & IFF_RUNNING)
2390 sc->an_associated = 0;
2392 /* Allocate the TX buffers */
2393 if (an_init_tx_ring(sc)) {
2396 an_init_mpi350_desc(sc);
2397 if (an_init_tx_ring(sc)) {
2398 if_printf(ifp, "tx buffer allocation failed\n");
2403 /* Set our MAC address. */
2404 bcopy((char *)&sc->arpcom.ac_enaddr,
2405 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2407 if (ifp->if_flags & IFF_BROADCAST)
2408 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2410 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2412 if (ifp->if_flags & IFF_MULTICAST)
2413 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2415 if (ifp->if_flags & IFF_PROMISC) {
2416 if (sc->an_monitor & AN_MONITOR) {
2417 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2418 sc->an_config.an_rxmode |=
2419 AN_RXMODE_80211_MONITOR_ANYBSS |
2420 AN_RXMODE_NO_8023_HEADER;
2422 sc->an_config.an_rxmode |=
2423 AN_RXMODE_80211_MONITOR_CURBSS |
2424 AN_RXMODE_NO_8023_HEADER;
2430 if (sc->an_have_rssimap)
2431 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2434 /* Set the ssid list */
2435 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2436 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2437 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2438 if_printf(ifp, "failed to set ssid list\n");
2442 /* Set the AP list */
2443 sc->an_aplist.an_type = AN_RID_APLIST;
2444 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2445 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2446 if_printf(ifp, "failed to set AP list\n");
2450 /* Set the configuration in the NIC */
2451 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2452 sc->an_config.an_type = AN_RID_GENCONFIG;
2453 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2454 if_printf(ifp, "failed to set configuration\n");
2458 /* Enable the MAC */
2459 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2460 if_printf(ifp, "failed to enable MAC\n");
2464 if (ifp->if_flags & IFF_PROMISC)
2465 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2467 /* enable interrupts */
2468 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2470 ifp->if_flags |= IFF_RUNNING;
2471 ifq_clr_oactive(&ifp->if_snd);
2473 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
2477 an_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
2479 struct an_softc *sc;
2480 struct mbuf *m0 = NULL;
2481 struct an_txframe_802_3 tx_frame_802_3;
2482 struct ether_header *eh;
2483 int id, idx, i, ready;
2484 unsigned char txcontrol;
2485 struct an_card_tx_desc an_tx_desc;
2488 ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
2492 if (ifq_is_oactive(&ifp->if_snd))
2495 if (!sc->an_associated) {
2496 ifq_purge(&ifp->if_snd);
2500 /* We can't send in monitor mode so toss any attempts. */
2501 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2502 ifq_purge(&ifp->if_snd);
2507 idx = sc->an_rdata.an_tx_prod;
2510 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2512 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2514 m0 = ifq_dequeue(&ifp->if_snd, NULL);
2518 id = sc->an_rdata.an_tx_fids[idx];
2519 eh = mtod(m0, struct ether_header *);
2521 bcopy((char *)&eh->ether_dhost,
2522 (char *)&tx_frame_802_3.an_tx_dst_addr,
2524 bcopy((char *)&eh->ether_shost,
2525 (char *)&tx_frame_802_3.an_tx_src_addr,
2528 /* minus src/dest mac & type */
2529 tx_frame_802_3.an_tx_802_3_payload_len =
2530 m0->m_pkthdr.len - 12;
2532 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2533 tx_frame_802_3.an_tx_802_3_payload_len,
2534 (caddr_t)&sc->an_txbuf);
2536 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2537 /* write the txcontrol only */
2538 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2542 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2543 sizeof(struct an_txframe_802_3));
2545 /* in mbuf header type is just before payload */
2546 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2547 tx_frame_802_3.an_tx_802_3_payload_len);
2554 sc->an_rdata.an_tx_ring[idx] = id;
2555 if (an_cmd(sc, AN_CMD_TX, id))
2556 if_printf(ifp, "xmit failed\n");
2558 AN_INC(idx, AN_TX_RING_CNT);
2561 * Set a timeout in case the chip goes out to lunch.
2565 } else { /* MPI-350 */
2566 /* Disable interrupts. */
2567 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2569 while (sc->an_rdata.an_tx_empty ||
2570 idx != sc->an_rdata.an_tx_cons) {
2572 m0 = ifq_dequeue(&ifp->if_snd, NULL);
2576 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2578 eh = mtod(m0, struct ether_header *);
2580 /* DJA optimize this to limit bcopy */
2581 bcopy((char *)&eh->ether_dhost,
2582 (char *)&tx_frame_802_3.an_tx_dst_addr,
2584 bcopy((char *)&eh->ether_shost,
2585 (char *)&tx_frame_802_3.an_tx_src_addr,
2588 /* minus src/dest mac & type */
2589 tx_frame_802_3.an_tx_802_3_payload_len =
2590 m0->m_pkthdr.len - 12;
2592 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2593 tx_frame_802_3.an_tx_802_3_payload_len,
2594 (caddr_t)&sc->an_txbuf);
2596 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2597 /* write the txcontrol only */
2598 bcopy((caddr_t)&txcontrol, &buf[0x08],
2602 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2603 sizeof(struct an_txframe_802_3));
2605 /* in mbuf header type is just before payload */
2606 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2607 tx_frame_802_3.an_tx_802_3_payload_len);
2610 bzero(&an_tx_desc, sizeof(an_tx_desc));
2611 an_tx_desc.an_offset = 0;
2612 an_tx_desc.an_eoc = 1;
2613 an_tx_desc.an_valid = 1;
2614 an_tx_desc.an_len = 0x44 +
2615 tx_frame_802_3.an_tx_802_3_payload_len;
2616 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2617 for (i = sizeof(an_tx_desc) / 4 - 1; i >= 0 ; --i) {
2618 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2620 + (0 * sizeof(an_tx_desc))
2622 ((u_int32_t*)(void *)&an_tx_desc)[i]);
2630 AN_INC(idx, AN_MAX_TX_DESC);
2631 sc->an_rdata.an_tx_empty = 0;
2633 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2636 * Set a timeout in case the chip goes out to lunch.
2641 /* Re-enable interrupts. */
2642 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2646 ifq_set_oactive(&ifp->if_snd);
2648 sc->an_rdata.an_tx_prod = idx;
2652 an_stop(struct an_softc *sc)
2657 ifp = &sc->arpcom.ac_if;
2659 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2660 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2661 an_cmd(sc, AN_CMD_DISABLE, 0);
2663 for (i = 0; i < AN_TX_RING_CNT; i++)
2664 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2666 callout_stop(&sc->an_stat_timer);
2668 ifp->if_flags &= ~IFF_RUNNING;
2669 ifq_clr_oactive(&ifp->if_snd);
2671 if (sc->an_flash_buffer) {
2672 kfree(sc->an_flash_buffer, M_DEVBUF);
2673 sc->an_flash_buffer = NULL;
2678 an_watchdog(struct ifnet *ifp)
2680 struct an_softc *sc;
2686 an_init_mpi350_desc(sc);
2689 IFNET_STAT_INC(ifp, oerrors, 1);
2691 if_printf(ifp, "device timeout\n");
2695 an_shutdown(device_t dev)
2697 struct an_softc *sc;
2699 sc = device_get_softc(dev);
2706 an_resume(device_t dev)
2708 struct an_softc *sc = device_get_softc(dev);
2709 struct ifnet *ifp = &sc->arpcom.ac_if;
2712 lwkt_serialize_enter(ifp->if_serializer);
2716 an_init_mpi350_desc(sc);
2719 /* Recovery temporary keys */
2720 for (i = 0; i < 4; i++) {
2721 sc->areq.an_type = AN_RID_WEP_TEMP;
2722 sc->areq.an_len = sizeof(struct an_ltv_key);
2723 bcopy(&sc->an_temp_keys[i],
2724 &sc->areq, sizeof(struct an_ltv_key));
2725 an_setdef(sc, &sc->areq);
2728 if (ifp->if_flags & IFF_UP)
2731 lwkt_serialize_exit(ifp->if_serializer);
2735 /* Aironet signal strength cache code.
2736 * store signal/noise/quality on per MAC src basis in
2737 * a small fixed cache. The cache wraps if > MAX slots
2738 * used. The cache may be zeroed out to start over.
2739 * Two simple filters exist to reduce computation:
2740 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2741 * to ignore some packets. It defaults to ip only.
2742 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2743 * 2. multicast/broadcast only. This may be used to
2744 * ignore unicast packets and only cache signal strength
2745 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2746 * beacons and not unicast traffic.
2748 * The cache stores (MAC src(index), IP src (major clue), signal,
2751 * No apologies for storing IP src here. It's easy and saves much
2752 * trouble elsewhere. The cache is assumed to be INET dependent,
2753 * although it need not be.
2755 * Note: the Aironet only has a single byte of signal strength value
2756 * in the rx frame header, and it's not scaled to anything sensible.
2757 * This is kind of lame, but it's all we've got.
2760 #ifdef documentation
2762 int an_sigitems; /* number of cached entries */
2763 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2764 int an_nextitem; /* index/# of entries */
2769 /* control variables for cache filtering. Basic idea is
2770 * to reduce cost (e.g., to only Mobile-IP agent beacons
2771 * which are broadcast or multicast). Still you might
2772 * want to measure signal strength anth unicast ping packets
2773 * on a pt. to pt. ant. setup.
2775 /* set true if you want to limit cache items to broadcast/mcast
2776 * only packets (not unicast). Useful for mobile-ip beacons which
2777 * are broadcast/multicast at network layer. Default is all packets
2778 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2780 static int an_cache_mcastonly = 0;
2781 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2782 &an_cache_mcastonly, 0, "");
2784 /* set true if you want to limit cache items to IP packets only
2786 static int an_cache_iponly = 1;
2787 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2788 &an_cache_iponly, 0, "");
2791 * an_cache_store, per rx packet store signal
2792 * strength in MAC (src) indexed cache.
2795 an_cache_store (struct an_softc *sc, struct mbuf *m, u_int8_t rx_rssi,
2796 u_int8_t rx_quality)
2798 struct ether_header *eh = mtod(m, struct ether_header *);
2799 struct ip *ip = NULL;
2801 static int cache_slot = 0; /* use this cache entry */
2802 static int wrapindex = 0; /* next "free" cache entry */
2806 * 2. configurable filter to throw out unicast packets,
2807 * keep multicast only.
2810 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2811 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2812 else if (an_cache_iponly)
2815 /* filter for broadcast/multicast only
2817 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2822 if_printf(&sc->arpcom.ac_if, "q value %x (MSB=0x%x, LSB=0x%x)\n",
2823 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2826 /* do a linear search for a matching MAC address
2827 * in the cache table
2828 * . MAC address is 6 bytes,
2829 * . var w_nextitem holds total number of entries already cached
2831 for (i = 0; i < sc->an_nextitem; i++) {
2832 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2834 * so we already have this entry,
2841 /* did we find a matching mac address?
2842 * if yes, then overwrite a previously existing cache entry
2844 if (i < sc->an_nextitem ) {
2847 /* else, have a new address entry,so
2848 * add this new entry,
2849 * if table full, then we need to replace LRU entry
2853 /* check for space in cache table
2854 * note: an_nextitem also holds number of entries
2855 * added in the cache table
2857 if ( sc->an_nextitem < MAXANCACHE ) {
2858 cache_slot = sc->an_nextitem;
2860 sc->an_sigitems = sc->an_nextitem;
2862 /* no space found, so simply wrap anth wrap index
2863 * and "zap" the next entry
2866 if (wrapindex == MAXANCACHE) {
2869 cache_slot = wrapindex++;
2873 /* invariant: cache_slot now points at some slot
2876 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
2877 log(LOG_ERR, "an_cache_store, bad index: %d of "
2878 "[0..%d], gross cache error\n",
2879 cache_slot, MAXANCACHE);
2883 /* store items in cache
2884 * .ip source address
2889 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2891 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2894 switch (an_cache_mode) {
2896 if (sc->an_have_rssimap) {
2897 sc->an_sigcache[cache_slot].signal =
2898 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
2899 sc->an_sigcache[cache_slot].quality =
2900 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
2902 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
2903 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
2907 if (sc->an_have_rssimap) {
2908 sc->an_sigcache[cache_slot].signal =
2909 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
2910 sc->an_sigcache[cache_slot].quality =
2911 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
2915 if (rx_quality > 100)
2917 sc->an_sigcache[cache_slot].signal = rx_rssi;
2918 sc->an_sigcache[cache_slot].quality = rx_quality;
2922 sc->an_sigcache[cache_slot].signal = rx_rssi;
2923 sc->an_sigcache[cache_slot].quality = rx_quality;
2927 sc->an_sigcache[cache_slot].noise = 0;
2934 an_media_change(struct ifnet *ifp)
2936 struct an_softc *sc = ifp->if_softc;
2937 struct an_ltv_genconfig *cfg;
2938 int otype = sc->an_config.an_opmode;
2939 int orate = sc->an_tx_rate;
2941 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
2942 case IFM_IEEE80211_DS1:
2943 sc->an_tx_rate = AN_RATE_1MBPS;
2945 case IFM_IEEE80211_DS2:
2946 sc->an_tx_rate = AN_RATE_2MBPS;
2948 case IFM_IEEE80211_DS5:
2949 sc->an_tx_rate = AN_RATE_5_5MBPS;
2951 case IFM_IEEE80211_DS11:
2952 sc->an_tx_rate = AN_RATE_11MBPS;
2959 if (orate != sc->an_tx_rate) {
2960 /* Read the current configuration */
2961 sc->an_config.an_type = AN_RID_GENCONFIG;
2962 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2963 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
2964 cfg = &sc->an_config;
2966 /* clear other rates and set the only one we want */
2967 bzero(cfg->an_rates, sizeof(cfg->an_rates));
2968 cfg->an_rates[0] = sc->an_tx_rate;
2970 /* Save the new rate */
2971 sc->an_config.an_type = AN_RID_GENCONFIG;
2972 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2975 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
2976 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
2978 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
2980 if (otype != sc->an_config.an_opmode ||
2981 orate != sc->an_tx_rate)
2988 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
2990 struct an_ltv_status status;
2991 struct an_softc *sc = ifp->if_softc;
2993 status.an_len = sizeof(status);
2994 status.an_type = AN_RID_STATUS;
2995 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
2996 /* If the status read fails, just lie. */
2997 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
2998 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3001 if (sc->an_tx_rate == 0) {
3002 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3003 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3004 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3005 switch (status.an_current_tx_rate) {
3007 imr->ifm_active |= IFM_IEEE80211_DS1;
3010 imr->ifm_active |= IFM_IEEE80211_DS2;
3012 case AN_RATE_5_5MBPS:
3013 imr->ifm_active |= IFM_IEEE80211_DS5;
3015 case AN_RATE_11MBPS:
3016 imr->ifm_active |= IFM_IEEE80211_DS11;
3020 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3023 imr->ifm_status = IFM_AVALID;
3024 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3025 imr->ifm_status |= IFM_ACTIVE;
3028 /********************** Cisco utility support routines *************/
3031 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3036 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3039 struct an_softc *sc;
3041 switch (l_ioctl->command) {
3043 rid = AN_RID_CAPABILITIES;
3046 rid = AN_RID_GENCONFIG;
3049 rid = AN_RID_SSIDLIST;
3052 rid = AN_RID_APLIST;
3055 rid = AN_RID_DRVNAME;
3058 rid = AN_RID_ENCAPPROTO;
3061 rid = AN_RID_WEP_TEMP;
3064 rid = AN_RID_WEP_PERM;
3067 rid = AN_RID_STATUS;
3070 rid = AN_RID_32BITS_DELTA;
3073 rid = AN_RID_32BITS_CUM;
3080 if (rid == 999) /* Is bad command */
3084 sc->areq.an_len = AN_MAX_DATALEN;
3085 sc->areq.an_type = rid;
3087 an_read_record(sc, (struct an_ltv_gen *)(void *)&sc->areq);
3089 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3091 /* the data contains the length at first */
3092 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3093 sizeof(sc->areq.an_len))) {
3096 /* Just copy the data back */
3097 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3105 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3107 struct an_softc *sc;
3112 command = l_ioctl->command;
3116 rid = AN_RID_SSIDLIST;
3119 rid = AN_RID_CAPABILITIES;
3122 rid = AN_RID_APLIST;
3125 rid = AN_RID_GENCONFIG;
3128 an_cmd(sc, AN_CMD_ENABLE, 0);
3132 an_cmd(sc, AN_CMD_DISABLE, 0);
3137 * This command merely clears the counts does not actually
3138 * store any data only reads rid. But as it changes the cards
3139 * state, I put it in the writerid routines.
3142 rid = AN_RID_32BITS_DELTACLR;
3144 sc->areq.an_len = AN_MAX_DATALEN;
3145 sc->areq.an_type = rid;
3147 an_read_record(sc, (struct an_ltv_gen *)(void *)&sc->areq);
3148 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3150 /* the data contains the length at first */
3151 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3152 sizeof(sc->areq.an_len))) {
3155 /* Just copy the data */
3156 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3163 rid = AN_RID_WEP_TEMP;
3166 rid = AN_RID_WEP_PERM;
3169 rid = AN_RID_LEAPUSERNAME;
3172 rid = AN_RID_LEAPPASSWORD;
3179 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3181 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3182 sc->areq.an_type = rid;
3184 /* Just copy the data back */
3185 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3188 an_cmd(sc, AN_CMD_DISABLE, 0);
3189 an_write_record(sc, (struct an_ltv_gen *)(void *)&sc->areq);
3190 an_cmd(sc, AN_CMD_ENABLE, 0);
3197 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3201 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3202 #define FLASH_COMMAND 0x7e7e
3203 #define FLASH_SIZE 32 * 1024
3206 unstickbusy(struct ifnet *ifp)
3208 struct an_softc *sc = ifp->if_softc;
3210 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3211 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3212 AN_EV_CLR_STUCK_BUSY);
3219 * Wait for busy completion from card wait for delay uSec's Return true for
3220 * success meaning command reg is clear
3224 WaitBusy(struct ifnet *ifp, int uSec)
3226 int statword = 0xffff;
3228 struct an_softc *sc = ifp->if_softc;
3230 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3233 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3235 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3240 return 0 == (AN_CMD_BUSY & statword);
3244 * STEP 1) Disable MAC and do soft reset on card.
3248 cmdreset(struct ifnet *ifp)
3251 struct an_softc *sc = ifp->if_softc;
3255 an_cmd(sc, AN_CMD_DISABLE, 0);
3257 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3258 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3261 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3263 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3266 if (!(status = WaitBusy(ifp, 100))) {
3267 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3274 * STEP 2) Put the card in legendary flash mode
3278 setflashmode(struct ifnet *ifp)
3281 struct an_softc *sc = ifp->if_softc;
3283 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3284 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3285 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3286 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3289 * mdelay(500); // 500ms delay
3294 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3295 kprintf("Waitbusy hang after setflash mode\n");
3302 * Get a character from the card matching matchbyte Step 3)
3306 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3309 unsigned char rbyte = 0;
3311 struct an_softc *sc = ifp->if_softc;
3315 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3317 if (dwelltime && !(0x8000 & rchar)) {
3322 rbyte = 0xff & rchar;
3324 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3325 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3329 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3331 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3333 } while (dwelltime > 0);
3338 * Put character to SWS0 wait for dwelltime x 50us for echo .
3342 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3345 int pollbusy, waittime;
3346 struct an_softc *sc = ifp->if_softc;
3353 waittime = dwelltime;
3356 * Wait for busy bit d15 to go false indicating buffer empty
3359 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3361 if (pollbusy & 0x8000) {
3368 while (waittime >= 0);
3370 /* timeout for busy clear wait */
3372 if (waittime <= 0) {
3373 if_printf(ifp, "flash putchar busywait timeout!\n");
3377 * Port is clear now write byte and wait for it to echo back
3380 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3383 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3384 } while (dwelltime >= 0 && echo != byte);
3387 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3389 return echo == byte;
3393 * Transfer 32k of firmware data from user buffer to our buffer and send to
3398 flashputbuf(struct ifnet *ifp)
3400 unsigned short *bufp;
3402 struct an_softc *sc = ifp->if_softc;
3406 bufp = sc->an_flash_buffer;
3409 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3410 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3412 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3413 CSR_WRITE_2(sc, AN_AUX_DATA,
3414 ((u_int16_t *)(void *)bufp)[nwords] & 0xffff);
3417 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3418 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3419 ((u_int32_t *)(void *)bufp)[nwords] & 0xffff);
3423 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3429 * After flashing restart the card.
3433 flashrestart(struct ifnet *ifp)
3436 struct an_softc *sc = ifp->if_softc;
3438 FLASH_DELAY(1024); /* Added 12/7/00 */
3442 FLASH_DELAY(1024); /* Added 12/7/00 */
3447 * Entry point for flash ioclt.
3451 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3454 struct an_softc *sc;
3458 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3461 status = l_ioctl->command;
3463 switch (l_ioctl->command) {
3465 return cmdreset(ifp);
3468 if (sc->an_flash_buffer) {
3469 kfree(sc->an_flash_buffer, M_DEVBUF);
3470 sc->an_flash_buffer = NULL;
3472 sc->an_flash_buffer = kmalloc(FLASH_SIZE, M_DEVBUF, 0);
3473 if (sc->an_flash_buffer)
3474 return setflashmode(ifp);
3478 case AIROFLSHGCHR: /* Get char from aux */
3479 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3480 z = *(int *)(void *)&sc->areq;
3481 if ((status = flashgchar(ifp, z, 8000)) == 1)
3486 case AIROFLSHPCHR: /* Send char to card. */
3487 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3488 z = *(int *)(void *)&sc->areq;
3489 if ((status = flashpchar(ifp, z, 8000)) == -1)
3494 case AIROFLPUTBUF: /* Send 32k to card */
3495 if (l_ioctl->len > FLASH_SIZE) {
3496 if_printf(ifp, "Buffer to big, %x %x\n",
3497 l_ioctl->len, FLASH_SIZE);
3500 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3502 if ((status = flashputbuf(ifp)) != 0)
3508 if ((status = flashrestart(ifp)) != 0) {
3509 if_printf(ifp, "FLASHRESTART returned %d\n", status);