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.
33 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
35 * Written by Bill Paul <wpaul@ctr.columbia.edu>
36 * Electrical Engineering Department
37 * Columbia University, New York City
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
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/ctype.h>
92 #include <sys/systm.h>
93 #include <sys/sockio.h>
97 #include <sys/kernel.h>
98 #include <sys/socket.h>
100 #include <sys/syslog.h>
102 #include <sys/sysctl.h>
104 #include <sys/module.h>
106 #include <machine/bus.h>
107 #include <sys/rman.h>
108 #include <sys/lock.h>
109 #include <sys/mutex.h>
110 #include <machine/resource.h>
111 #include <sys/malloc.h>
114 #include <net/if_var.h>
115 #include <net/if_arp.h>
116 #include <net/if_dl.h>
117 #include <net/ethernet.h>
118 #include <net/if_types.h>
119 #include <net/if_media.h>
121 #include <net80211/ieee80211_var.h>
122 #include <net80211/ieee80211_ioctl.h>
125 #include <netinet/in.h>
126 #include <netinet/in_systm.h>
127 #include <netinet/in_var.h>
128 #include <netinet/ip.h>
133 #include <machine/md_var.h>
135 #include <dev/an/if_aironet_ieee.h>
136 #include <dev/an/if_anreg.h>
138 /* These are global because we need them in sys/pci/if_an_p.c. */
139 static void an_reset(struct an_softc *);
140 static int an_init_mpi350_desc(struct an_softc *);
141 static int an_ioctl(struct ifnet *, u_long, caddr_t);
142 static void an_init(void *);
143 static void an_init_locked(struct an_softc *);
144 static int an_init_tx_ring(struct an_softc *);
145 static void an_start(struct ifnet *);
146 static void an_start_locked(struct ifnet *);
147 static void an_watchdog(struct an_softc *);
148 static void an_rxeof(struct an_softc *);
149 static void an_txeof(struct an_softc *, int);
151 static void an_promisc(struct an_softc *, int);
152 static int an_cmd(struct an_softc *, int, int);
153 static int an_cmd_struct(struct an_softc *, struct an_command *,
155 static int an_read_record(struct an_softc *, struct an_ltv_gen *);
156 static int an_write_record(struct an_softc *, struct an_ltv_gen *);
157 static int an_read_data(struct an_softc *, int, int, caddr_t, int);
158 static int an_write_data(struct an_softc *, int, int, caddr_t, int);
159 static int an_seek(struct an_softc *, int, int, int);
160 static int an_alloc_nicmem(struct an_softc *, int, int *);
161 static int an_dma_malloc(struct an_softc *, bus_size_t, struct an_dma_alloc *,
163 static void an_dma_free(struct an_softc *, struct an_dma_alloc *);
164 static void an_dma_malloc_cb(void *, bus_dma_segment_t *, int, int);
165 static void an_stats_update(void *);
166 static void an_setdef(struct an_softc *, struct an_req *);
168 static void an_cache_store(struct an_softc *, struct ether_header *,
169 struct mbuf *, u_int8_t, u_int8_t);
172 /* function definitions for use with the Cisco's Linux configuration
176 static int readrids(struct ifnet*, struct aironet_ioctl*);
177 static int writerids(struct ifnet*, struct aironet_ioctl*);
178 static int flashcard(struct ifnet*, struct aironet_ioctl*);
180 static int cmdreset(struct ifnet *);
181 static int setflashmode(struct ifnet *);
182 static int flashgchar(struct ifnet *,int,int);
183 static int flashpchar(struct ifnet *,int,int);
184 static int flashputbuf(struct ifnet *);
185 static int flashrestart(struct ifnet *);
186 static int WaitBusy(struct ifnet *, int);
187 static int unstickbusy(struct ifnet *);
189 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
192 static int an_media_change (struct ifnet *);
193 static void an_media_status (struct ifnet *, struct ifmediareq *);
195 static int an_dump = 0;
196 static int an_cache_mode = 0;
202 static char an_conf[256];
203 static char an_conf_cache[256];
207 static SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0,
208 "Wireless driver parameters");
210 /* XXX violate ethernet/netgraph callback hooks */
211 extern void (*ng_ether_attach_p)(struct ifnet *ifp);
212 extern void (*ng_ether_detach_p)(struct ifnet *ifp);
215 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
224 strcpy(an_conf, "off");
227 strcpy(an_conf, "type");
230 strcpy(an_conf, "dump");
233 snprintf(an_conf, 5, "%x", an_dump);
237 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
239 if (strncmp(an_conf,"off", 3) == 0) {
242 if (strncmp(an_conf,"dump", 4) == 0) {
245 if (strncmp(an_conf,"type", 4) == 0) {
251 if ((*s >= '0') && (*s <= '9')) {
252 r = r * 16 + (*s - '0');
253 } else if ((*s >= 'a') && (*s <= 'f')) {
254 r = r * 16 + (*s - 'a' + 10);
262 printf("Sysctl changed for Aironet driver\n");
267 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
268 0, sizeof(an_conf), sysctl_an_dump, "A", "");
271 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
275 switch (an_cache_mode) {
277 strcpy(an_conf_cache, "per");
280 strcpy(an_conf_cache, "raw");
283 strcpy(an_conf_cache, "dbm");
287 error = sysctl_handle_string(oidp, an_conf_cache,
288 sizeof(an_conf_cache), req);
290 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
293 if (strncmp(an_conf_cache,"per", 3) == 0) {
296 if (strncmp(an_conf_cache,"raw", 3) == 0) {
303 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
304 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
307 * Setup the lock for PCI attachment since it skips the an_probe
308 * function. We need to setup the lock in an_probe since some
309 * operations need the lock. So we might as well create the
313 an_pci_probe(device_t dev)
315 struct an_softc *sc = device_get_softc(dev);
317 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
324 * We probe for an Aironet 4500/4800 card by attempting to
325 * read the default SSID list. On reset, the first entry in
326 * the SSID list will contain the name "tsunami." If we don't
327 * find this, then there's no card present.
330 an_probe(device_t dev)
332 struct an_softc *sc = device_get_softc(dev);
333 struct an_ltv_ssidlist_new ssid;
336 bzero((char *)&ssid, sizeof(ssid));
338 error = an_alloc_port(dev, 0, AN_IOSIZ);
342 /* can't do autoprobing */
343 if (rman_get_start(sc->port_res) == -1)
347 * We need to fake up a softc structure long enough
348 * to be able to issue commands and call some of the
351 ssid.an_len = sizeof(ssid);
352 ssid.an_type = AN_RID_SSIDLIST;
354 /* Make sure interrupts are disabled. */
356 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
357 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
360 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
365 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
370 if (an_read_record(sc, (struct an_ltv_gen *)&ssid)) {
375 /* See if the ssid matches what we expect ... but doesn't have to */
376 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID)) {
384 mtx_destroy(&sc->an_mtx);
389 * Allocate a port resource with the given resource id.
392 an_alloc_port(device_t dev, int rid, int size)
394 struct an_softc *sc = device_get_softc(dev);
395 struct resource *res;
397 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
398 0ul, ~0ul, size, RF_ACTIVE);
409 * Allocate a memory resource with the given resource id.
411 int an_alloc_memory(device_t dev, int rid, int size)
413 struct an_softc *sc = device_get_softc(dev);
414 struct resource *res;
416 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
417 0ul, ~0ul, size, RF_ACTIVE);
429 * Allocate a auxilary memory resource with the given resource id.
431 int an_alloc_aux_memory(device_t dev, int rid, int size)
433 struct an_softc *sc = device_get_softc(dev);
434 struct resource *res;
436 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
437 0ul, ~0ul, size, RF_ACTIVE);
439 sc->mem_aux_rid = rid;
440 sc->mem_aux_res = res;
441 sc->mem_aux_used = size;
449 * Allocate an irq resource with the given resource id.
452 an_alloc_irq(device_t dev, int rid, int flags)
454 struct an_softc *sc = device_get_softc(dev);
455 struct resource *res;
457 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
458 (RF_ACTIVE | flags));
469 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
471 bus_addr_t *paddr = (bus_addr_t*) arg;
472 *paddr = segs->ds_addr;
476 * Alloc DMA memory and set the pointer to it
479 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
484 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
485 BUS_DMA_NOWAIT, &dma->an_dma_map);
489 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
493 mapflags | BUS_DMA_NOWAIT);
497 dma->an_dma_size = size;
501 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
503 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
508 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
510 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
511 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
512 dma->an_dma_vaddr = 0;
516 * Release all resources
519 an_release_resources(device_t dev)
521 struct an_softc *sc = device_get_softc(dev);
525 bus_release_resource(dev, SYS_RES_IOPORT,
526 sc->port_rid, sc->port_res);
530 bus_release_resource(dev, SYS_RES_MEMORY,
531 sc->mem_rid, sc->mem_res);
534 if (sc->mem_aux_res) {
535 bus_release_resource(dev, SYS_RES_MEMORY,
536 sc->mem_aux_rid, sc->mem_aux_res);
540 bus_release_resource(dev, SYS_RES_IRQ,
541 sc->irq_rid, sc->irq_res);
544 if (sc->an_rid_buffer.an_dma_paddr) {
545 an_dma_free(sc, &sc->an_rid_buffer);
547 for (i = 0; i < AN_MAX_RX_DESC; i++)
548 if (sc->an_rx_buffer[i].an_dma_paddr) {
549 an_dma_free(sc, &sc->an_rx_buffer[i]);
551 for (i = 0; i < AN_MAX_TX_DESC; i++)
552 if (sc->an_tx_buffer[i].an_dma_paddr) {
553 an_dma_free(sc, &sc->an_tx_buffer[i]);
556 bus_dma_tag_destroy(sc->an_dtag);
562 an_init_mpi350_desc(struct an_softc *sc)
564 struct an_command cmd_struct;
565 struct an_reply reply;
566 struct an_card_rid_desc an_rid_desc;
567 struct an_card_rx_desc an_rx_desc;
568 struct an_card_tx_desc an_tx_desc;
572 if(!sc->an_rid_buffer.an_dma_paddr)
573 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
574 &sc->an_rid_buffer, 0);
575 for (i = 0; i < AN_MAX_RX_DESC; i++)
576 if(!sc->an_rx_buffer[i].an_dma_paddr)
577 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
578 &sc->an_rx_buffer[i], 0);
579 for (i = 0; i < AN_MAX_TX_DESC; i++)
580 if(!sc->an_tx_buffer[i].an_dma_paddr)
581 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
582 &sc->an_tx_buffer[i], 0);
585 * Allocate RX descriptor
587 bzero(&reply,sizeof(reply));
588 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
589 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
590 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
591 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
592 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
593 if_printf(sc->an_ifp, "failed to allocate RX descriptor\n");
597 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
598 bzero(&an_rx_desc, sizeof(an_rx_desc));
599 an_rx_desc.an_valid = 1;
600 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
601 an_rx_desc.an_done = 0;
602 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
604 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
605 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
606 + (desc * sizeof(an_rx_desc))
608 ((u_int32_t *)(void *)&an_rx_desc)[i]);
612 * Allocate TX descriptor
615 bzero(&reply,sizeof(reply));
616 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
617 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
618 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
619 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
620 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
621 if_printf(sc->an_ifp, "failed to allocate TX descriptor\n");
625 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
626 bzero(&an_tx_desc, sizeof(an_tx_desc));
627 an_tx_desc.an_offset = 0;
628 an_tx_desc.an_eoc = 0;
629 an_tx_desc.an_valid = 0;
630 an_tx_desc.an_len = 0;
631 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
633 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
634 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
635 + (desc * sizeof(an_tx_desc))
637 ((u_int32_t *)(void *)&an_tx_desc)[i]);
641 * Allocate RID descriptor
644 bzero(&reply,sizeof(reply));
645 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
646 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
647 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
648 cmd_struct.an_parm2 = 1;
649 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
650 if_printf(sc->an_ifp, "failed to allocate host descriptor\n");
654 bzero(&an_rid_desc, sizeof(an_rid_desc));
655 an_rid_desc.an_valid = 1;
656 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
657 an_rid_desc.an_rid = 0;
658 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
660 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
661 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
662 ((u_int32_t *)(void *)&an_rid_desc)[i]);
668 an_attach(struct an_softc *sc, int flags)
675 ifp = sc->an_ifp = if_alloc(IFT_ETHER);
677 device_printf(sc->an_dev, "can not if_alloc()\n");
681 if_initname(ifp, device_get_name(sc->an_dev),
682 device_get_unit(sc->an_dev));
685 sc->an_associated = 0;
687 sc->an_was_monitor = 0;
688 sc->an_flash_buffer = NULL;
694 error = an_init_mpi350_desc(sc);
699 /* Load factory config */
700 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
701 device_printf(sc->an_dev, "failed to load config data\n");
705 /* Read the current configuration */
706 sc->an_config.an_type = AN_RID_GENCONFIG;
707 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
708 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
709 device_printf(sc->an_dev, "read record failed\n");
713 /* Read the card capabilities */
714 sc->an_caps.an_type = AN_RID_CAPABILITIES;
715 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
716 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
717 device_printf(sc->an_dev, "read record failed\n");
722 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
723 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
724 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
725 device_printf(sc->an_dev, "read record failed\n");
730 sc->an_aplist.an_type = AN_RID_APLIST;
731 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
732 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
733 device_printf(sc->an_dev, "read record failed\n");
738 /* Read the RSSI <-> dBm map */
739 sc->an_have_rssimap = 0;
740 if (sc->an_caps.an_softcaps & 8) {
741 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
742 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
743 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
744 device_printf(sc->an_dev,
745 "unable to get RSSI <-> dBM map\n");
747 device_printf(sc->an_dev, "got RSSI <-> dBM map\n");
748 sc->an_have_rssimap = 1;
751 device_printf(sc->an_dev, "no RSSI <-> dBM map\n");
756 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
757 ifp->if_ioctl = an_ioctl;
758 ifp->if_start = an_start;
759 ifp->if_init = an_init;
760 ifp->if_baudrate = 10000000;
761 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
762 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
763 IFQ_SET_READY(&ifp->if_snd);
765 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
766 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
767 sizeof(AN_DEFAULT_NODENAME) - 1);
769 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
770 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
771 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
772 sizeof(AN_DEFAULT_NETNAME) - 1);
773 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
775 sc->an_config.an_opmode =
776 AN_OPMODE_INFRASTRUCTURE_STATION;
779 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
783 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
784 if_printf(ifp, "supported rates: ");
785 #define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
786 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
788 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
789 for (i = 0; i < nrate; i++) {
790 r = sc->an_caps.an_rates[i];
791 mword = ieee80211_rate2media(NULL, r, IEEE80211_MODE_AUTO);
794 printf("%s%d%sMbps", (i != 0 ? " " : ""),
795 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
797 ADD(mword, IFM_IEEE80211_ADHOC);
800 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
805 * Call MI attach routine.
808 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
809 callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0);
814 mtx_destroy(&sc->an_mtx);
821 an_detach(device_t dev)
823 struct an_softc *sc = device_get_softc(dev);
824 struct ifnet *ifp = sc->an_ifp;
827 device_printf(dev,"already unloaded\n");
833 ifmedia_removeall(&sc->an_ifmedia);
834 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
837 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
838 callout_drain(&sc->an_stat_ch);
840 an_release_resources(dev);
841 mtx_destroy(&sc->an_mtx);
846 an_rxeof(struct an_softc *sc)
849 struct ether_header *eh;
850 struct ieee80211_frame *ih;
851 struct an_rxframe rx_frame;
852 struct an_rxframe_802_3 rx_frame_802_3;
854 int len, id, error = 0, i, count = 0;
855 int ieee80211_header_len;
858 struct an_card_rx_desc an_rx_desc;
866 id = CSR_READ_2(sc, AN_RX_FID);
868 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
869 /* read raw 802.11 packet */
870 bpf_buf = sc->buf_802_11;
873 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
875 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
880 * skip beacon by default since this increases the
884 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
885 (rx_frame.an_frame_ctl &
886 IEEE80211_FC0_SUBTYPE_BEACON)) {
890 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
891 len = rx_frame.an_rx_payload_len
893 /* Check for insane frame length */
894 if (len > sizeof(sc->buf_802_11)) {
895 if_printf(ifp, "oversized packet "
896 "received (%d, %d)\n",
898 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
902 bcopy((char *)&rx_frame,
903 bpf_buf, sizeof(rx_frame));
905 error = an_read_data(sc, id, sizeof(rx_frame),
906 (caddr_t)bpf_buf+sizeof(rx_frame),
907 rx_frame.an_rx_payload_len);
909 fc1=rx_frame.an_frame_ctl >> 8;
910 ieee80211_header_len =
911 sizeof(struct ieee80211_frame);
912 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
913 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
914 ieee80211_header_len += ETHER_ADDR_LEN;
917 len = rx_frame.an_rx_payload_len
918 + ieee80211_header_len;
919 /* Check for insane frame length */
920 if (len > sizeof(sc->buf_802_11)) {
921 if_printf(ifp, "oversized packet "
922 "received (%d, %d)\n",
924 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
928 ih = (struct ieee80211_frame *)bpf_buf;
930 bcopy((char *)&rx_frame.an_frame_ctl,
931 (char *)ih, ieee80211_header_len);
933 error = an_read_data(sc, id, sizeof(rx_frame) +
935 (caddr_t)ih +ieee80211_header_len,
936 rx_frame.an_rx_payload_len);
938 /* dump raw 802.11 packet to bpf and skip ip stack */
939 BPF_TAP(ifp, bpf_buf, len);
941 MGETHDR(m, M_NOWAIT, MT_DATA);
943 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
947 if (!(m->m_flags & M_EXT)) {
949 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
952 m->m_pkthdr.rcvif = ifp;
953 /* Read Ethernet encapsulated packet */
956 /* Read NIC frame header */
957 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
960 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
964 /* Read in the 802_3 frame header */
965 if (an_read_data(sc, id, 0x34,
966 (caddr_t)&rx_frame_802_3,
967 sizeof(rx_frame_802_3))) {
969 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
972 if (rx_frame_802_3.an_rx_802_3_status != 0) {
974 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
977 /* Check for insane frame length */
978 len = rx_frame_802_3.an_rx_802_3_payload_len;
979 if (len > sizeof(sc->buf_802_11)) {
981 if_printf(ifp, "oversized packet "
982 "received (%d, %d)\n",
984 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
987 m->m_pkthdr.len = m->m_len =
988 rx_frame_802_3.an_rx_802_3_payload_len + 12;
990 eh = mtod(m, struct ether_header *);
992 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
993 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
994 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
995 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
997 /* in mbuf header type is just before payload */
998 error = an_read_data(sc, id, 0x44,
999 (caddr_t)&(eh->ether_type),
1000 rx_frame_802_3.an_rx_802_3_payload_len);
1004 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1007 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
1009 /* Receive packet. */
1011 an_cache_store(sc, eh, m,
1012 rx_frame.an_rx_signal_strength,
1016 (*ifp->if_input)(ifp, m);
1020 } else { /* MPI-350 */
1021 for (count = 0; count < AN_MAX_RX_DESC; count++){
1022 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1023 ((u_int32_t *)(void *)&an_rx_desc)[i]
1024 = CSR_MEM_AUX_READ_4(sc,
1026 + (count * sizeof(an_rx_desc))
1029 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1030 buf = sc->an_rx_buffer[count].an_dma_vaddr;
1032 MGETHDR(m, M_NOWAIT, MT_DATA);
1034 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1037 MCLGET(m, M_NOWAIT);
1038 if (!(m->m_flags & M_EXT)) {
1040 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1043 m->m_pkthdr.rcvif = ifp;
1044 /* Read Ethernet encapsulated packet */
1047 * No ANCACHE support since we just get back
1048 * an Ethernet packet no 802.11 info
1052 /* Read NIC frame header */
1053 bcopy(buf, (caddr_t)&rx_frame,
1057 /* Check for insane frame length */
1058 len = an_rx_desc.an_len + 12;
1059 if (len > MCLBYTES) {
1061 if_printf(ifp, "oversized packet "
1062 "received (%d, %d)\n",
1064 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1068 m->m_pkthdr.len = m->m_len =
1069 an_rx_desc.an_len + 12;
1071 eh = mtod(m, struct ether_header *);
1073 bcopy(buf, (char *)eh,
1076 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
1078 /* Receive packet. */
1081 an_cache_store(sc, eh, m,
1082 rx_frame.an_rx_signal_strength,
1087 (*ifp->if_input)(ifp, m);
1090 an_rx_desc.an_valid = 1;
1091 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1092 an_rx_desc.an_done = 0;
1093 an_rx_desc.an_phys =
1094 sc->an_rx_buffer[count].an_dma_paddr;
1096 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1097 CSR_MEM_AUX_WRITE_4(sc,
1099 + (count * sizeof(an_rx_desc))
1101 ((u_int32_t *)(void *)&an_rx_desc)[i]);
1104 if_printf(ifp, "Didn't get valid RX packet "
1107 an_rx_desc.an_valid, an_rx_desc.an_len);
1114 an_txeof(struct an_softc *sc, int status)
1123 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1126 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1128 if (status & AN_EV_TX_EXC) {
1129 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1131 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1133 for (i = 0; i < AN_TX_RING_CNT; i++) {
1134 if (id == sc->an_rdata.an_tx_ring[i]) {
1135 sc->an_rdata.an_tx_ring[i] = 0;
1140 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1141 } else { /* MPI 350 */
1142 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1143 if (!sc->an_rdata.an_tx_empty){
1144 if (status & AN_EV_TX_EXC) {
1145 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1147 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1148 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1149 if (sc->an_rdata.an_tx_prod ==
1150 sc->an_rdata.an_tx_cons)
1151 sc->an_rdata.an_tx_empty = 1;
1159 * We abuse the stats updater to check the current NIC status. This
1160 * is important because we don't want to allow transmissions until
1161 * the NIC has synchronized to the current cell (either as the master
1162 * in an ad-hoc group, or as a station connected to an access point).
1164 * Note that this function will be called via callout(9) with a lock held.
1167 an_stats_update(void *xsc)
1169 struct an_softc *sc;
1175 if (sc->an_timer > 0 && --sc->an_timer == 0)
1178 sc->an_status.an_type = AN_RID_STATUS;
1179 sc->an_status.an_len = sizeof(struct an_ltv_status);
1180 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status))
1183 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1184 sc->an_associated = 1;
1186 sc->an_associated = 0;
1188 /* Don't do this while we're transmitting */
1189 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
1190 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1194 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1195 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1196 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len))
1199 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1207 struct an_softc *sc;
1211 sc = (struct an_softc*)xsc;
1222 /* Disable interrupts. */
1223 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1225 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1226 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1228 if (status & AN_EV_MIC) {
1229 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1232 if (status & AN_EV_LINKSTAT) {
1233 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1234 == AN_LINKSTAT_ASSOCIATED)
1235 sc->an_associated = 1;
1237 sc->an_associated = 0;
1238 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1241 if (status & AN_EV_RX) {
1243 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1246 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1247 an_txeof(sc, status);
1248 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1251 if (status & AN_EV_TX) {
1252 an_txeof(sc, status);
1253 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1256 if (status & AN_EV_TX_EXC) {
1257 an_txeof(sc, status);
1258 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1261 if (status & AN_EV_ALLOC)
1262 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1264 /* Re-enable interrupts. */
1265 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1267 if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1268 an_start_locked(ifp);
1277 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1278 struct an_reply *reply)
1283 for (i = 0; i != AN_TIMEOUT; i++) {
1284 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1290 if( i == AN_TIMEOUT) {
1295 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1296 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1297 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1298 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1300 for (i = 0; i < AN_TIMEOUT; i++) {
1301 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1306 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1307 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1308 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1309 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1311 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1312 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
1313 AN_EV_CLR_STUCK_BUSY);
1315 /* Ack the command */
1316 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1318 if (i == AN_TIMEOUT)
1325 an_cmd(struct an_softc *sc, int cmd, int val)
1330 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1331 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1332 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1333 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1335 for (i = 0; i < AN_TIMEOUT; i++) {
1336 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1339 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1340 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1344 for (i = 0; i < AN_TIMEOUT; i++) {
1345 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1346 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1347 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1348 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1349 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1353 /* Ack the command */
1354 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1356 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1357 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1359 if (i == AN_TIMEOUT)
1366 * This reset sequence may look a little strange, but this is the
1367 * most reliable method I've found to really kick the NIC in the
1368 * head and force it to reboot correctly.
1371 an_reset(struct an_softc *sc)
1377 an_cmd(sc, AN_CMD_ENABLE, 0);
1378 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1379 an_cmd(sc, AN_CMD_NOOP2, 0);
1381 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1382 device_printf(sc->an_dev, "reset failed\n");
1384 an_cmd(sc, AN_CMD_DISABLE, 0);
1390 * Read an LTV record from the NIC.
1393 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1395 struct an_ltv_gen *an_ltv;
1396 struct an_card_rid_desc an_rid_desc;
1397 struct an_command cmd;
1398 struct an_reply reply;
1405 if (ltv->an_len < 4 || ltv->an_type == 0)
1410 /* Tell the NIC to enter record read mode. */
1411 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1412 if_printf(ifp, "RID access failed\n");
1416 /* Seek to the record. */
1417 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1418 if_printf(ifp, "seek to record failed\n");
1423 * Read the length and record type and make sure they
1424 * match what we expect (this verifies that we have enough
1425 * room to hold all of the returned data).
1426 * Length includes type but not length.
1428 len = CSR_READ_2(sc, AN_DATA1);
1429 if (len > (ltv->an_len - 2)) {
1430 if_printf(ifp, "record length mismatch -- expected %d, "
1431 "got %d for Rid %x\n",
1432 ltv->an_len - 2, len, ltv->an_type);
1433 len = ltv->an_len - 2;
1435 ltv->an_len = len + 2;
1438 /* Now read the data. */
1439 len -= 2; /* skip the type */
1441 for (i = len; i > 1; i -= 2)
1442 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1444 ptr2 = (u_int8_t *)ptr;
1445 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1447 } else { /* MPI-350 */
1448 if (!sc->an_rid_buffer.an_dma_vaddr)
1450 an_rid_desc.an_valid = 1;
1451 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1452 an_rid_desc.an_rid = 0;
1453 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1454 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1456 bzero(&cmd, sizeof(cmd));
1457 bzero(&reply, sizeof(reply));
1458 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1459 cmd.an_parm0 = ltv->an_type;
1461 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1462 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1463 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1465 if (an_cmd_struct(sc, &cmd, &reply)
1466 || reply.an_status & AN_CMD_QUAL_MASK) {
1467 if_printf(ifp, "failed to read RID %x %x %x %x %x, %d\n",
1477 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1478 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1479 an_rid_desc.an_len = an_ltv->an_len;
1482 len = an_rid_desc.an_len;
1483 if (len > (ltv->an_len - 2)) {
1484 if_printf(ifp, "record length mismatch -- expected %d, "
1485 "got %d for Rid %x\n",
1486 ltv->an_len - 2, len, ltv->an_type);
1487 len = ltv->an_len - 2;
1489 ltv->an_len = len + 2;
1491 bcopy(&an_ltv->an_type,
1497 an_dump_record(sc, ltv, "Read");
1503 * Same as read, except we inject data instead of reading it.
1506 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1508 struct an_card_rid_desc an_rid_desc;
1509 struct an_command cmd;
1510 struct an_reply reply;
1517 an_dump_record(sc, ltv, "Write");
1520 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1523 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1527 * Length includes type but not length.
1529 len = ltv->an_len - 2;
1530 CSR_WRITE_2(sc, AN_DATA1, len);
1532 len -= 2; /* skip the type */
1534 for (i = len; i > 1; i -= 2)
1535 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1537 ptr2 = (u_int8_t *)ptr;
1538 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1541 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1546 for (i = 0; i != AN_TIMEOUT; i++) {
1547 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1553 if (i == AN_TIMEOUT) {
1557 an_rid_desc.an_valid = 1;
1558 an_rid_desc.an_len = ltv->an_len - 2;
1559 an_rid_desc.an_rid = ltv->an_type;
1560 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1562 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1563 an_rid_desc.an_len);
1565 bzero(&cmd,sizeof(cmd));
1566 bzero(&reply,sizeof(reply));
1567 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1568 cmd.an_parm0 = ltv->an_type;
1570 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1571 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1572 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1576 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1577 if_printf(sc->an_ifp,
1578 "failed to write RID 1 %x %x %x %x %x, %d\n",
1589 if (reply.an_status & AN_CMD_QUAL_MASK) {
1590 if_printf(sc->an_ifp,
1591 "failed to write RID 2 %x %x %x %x %x, %d\n",
1607 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1615 len = ltv->an_len - 4;
1616 if_printf(sc->an_ifp, "RID %4x, Length %4d, Mode %s\n",
1617 ltv->an_type, ltv->an_len - 4, string);
1619 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1620 if_printf(sc->an_ifp, "\t");
1621 bzero(buf,sizeof(buf));
1623 ptr2 = (u_int8_t *)<v->an_val;
1624 for (i = len; i > 0; i--) {
1625 printf("%02x ", *ptr2);
1632 if (++count == 16) {
1635 if_printf(sc->an_ifp, "\t");
1636 bzero(buf,sizeof(buf));
1639 for (; count != 16; count++) {
1642 printf(" %s\n",buf);
1647 an_seek(struct an_softc *sc, int id, int off, int chan)
1662 if_printf(sc->an_ifp, "invalid data path: %x\n", chan);
1666 CSR_WRITE_2(sc, selreg, id);
1667 CSR_WRITE_2(sc, offreg, off);
1669 for (i = 0; i < AN_TIMEOUT; i++) {
1670 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1674 if (i == AN_TIMEOUT)
1681 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1688 if (an_seek(sc, id, off, AN_BAP1))
1692 ptr = (u_int16_t *)buf;
1693 for (i = len; i > 1; i -= 2)
1694 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1696 ptr2 = (u_int8_t *)ptr;
1697 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1704 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1711 if (an_seek(sc, id, off, AN_BAP0))
1715 ptr = (u_int16_t *)buf;
1716 for (i = len; i > 1; i -= 2)
1717 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1719 ptr2 = (u_int8_t *)ptr;
1720 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1727 * Allocate a region of memory inside the NIC and zero
1731 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1735 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1736 if_printf(sc->an_ifp, "failed to allocate %d bytes on NIC\n",
1741 for (i = 0; i < AN_TIMEOUT; i++) {
1742 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1746 if (i == AN_TIMEOUT)
1749 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1750 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1752 if (an_seek(sc, *id, 0, AN_BAP0))
1755 for (i = 0; i < len / 2; i++)
1756 CSR_WRITE_2(sc, AN_DATA0, 0);
1762 an_setdef(struct an_softc *sc, struct an_req *areq)
1765 struct an_ltv_genconfig *cfg;
1766 struct an_ltv_ssidlist_new *ssid;
1767 struct an_ltv_aplist *ap;
1768 struct an_ltv_gen *sp;
1773 switch (areq->an_type) {
1774 case AN_RID_GENCONFIG:
1775 cfg = (struct an_ltv_genconfig *)areq;
1777 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(sc->an_ifp),
1780 bcopy((char *)cfg, (char *)&sc->an_config,
1781 sizeof(struct an_ltv_genconfig));
1783 case AN_RID_SSIDLIST:
1784 ssid = (struct an_ltv_ssidlist_new *)areq;
1785 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1786 sizeof(struct an_ltv_ssidlist_new));
1789 ap = (struct an_ltv_aplist *)areq;
1790 bcopy((char *)ap, (char *)&sc->an_aplist,
1791 sizeof(struct an_ltv_aplist));
1793 case AN_RID_TX_SPEED:
1794 sp = (struct an_ltv_gen *)areq;
1795 sc->an_tx_rate = sp->an_val;
1797 /* Read the current configuration */
1798 sc->an_config.an_type = AN_RID_GENCONFIG;
1799 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1800 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1801 cfg = &sc->an_config;
1803 /* clear other rates and set the only one we want */
1804 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1805 cfg->an_rates[0] = sc->an_tx_rate;
1807 /* Save the new rate */
1808 sc->an_config.an_type = AN_RID_GENCONFIG;
1809 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1811 case AN_RID_WEP_TEMP:
1812 /* Cache the temp keys */
1814 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1815 sizeof(struct an_ltv_key));
1816 case AN_RID_WEP_PERM:
1817 case AN_RID_LEAPUSERNAME:
1818 case AN_RID_LEAPPASSWORD:
1821 /* Disable the MAC. */
1822 an_cmd(sc, AN_CMD_DISABLE, 0);
1825 an_write_record(sc, (struct an_ltv_gen *)areq);
1827 /* Turn the MAC back on. */
1828 an_cmd(sc, AN_CMD_ENABLE, 0);
1831 case AN_RID_MONITOR_MODE:
1832 cfg = (struct an_ltv_genconfig *)areq;
1834 if (ng_ether_detach_p != NULL)
1835 (*ng_ether_detach_p) (ifp);
1836 sc->an_monitor = cfg->an_len;
1838 if (sc->an_monitor & AN_MONITOR) {
1839 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1840 bpfattach(ifp, DLT_AIRONET_HEADER,
1841 sizeof(struct ether_header));
1843 bpfattach(ifp, DLT_IEEE802_11,
1844 sizeof(struct ether_header));
1847 bpfattach(ifp, DLT_EN10MB,
1848 sizeof(struct ether_header));
1849 if (ng_ether_attach_p != NULL)
1850 (*ng_ether_attach_p) (ifp);
1854 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1859 /* Reinitialize the card. */
1867 * Derived from Linux driver to enable promiscious mode.
1871 an_promisc(struct an_softc *sc, int promisc)
1874 if (sc->an_was_monitor) {
1877 an_init_mpi350_desc(sc);
1879 if (sc->an_monitor || sc->an_was_monitor)
1882 sc->an_was_monitor = sc->an_monitor;
1883 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1889 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1894 struct an_softc *sc;
1896 struct thread *td = curthread;
1897 struct ieee80211req *ireq;
1898 struct ieee80211_channel ch;
1899 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1901 struct an_ltv_genconfig *config;
1902 struct an_ltv_key *key;
1903 struct an_ltv_status *status;
1904 struct an_ltv_ssidlist_new *ssids;
1906 struct aironet_ioctl l_ioctl;
1909 ifr = (struct ifreq *)data;
1910 ireq = (struct ieee80211req *)data;
1912 config = (struct an_ltv_genconfig *)&sc->areq;
1913 key = (struct an_ltv_key *)&sc->areq;
1914 status = (struct an_ltv_status *)&sc->areq;
1915 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1925 if (ifp->if_flags & IFF_UP) {
1926 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1927 ifp->if_flags & IFF_PROMISC &&
1928 !(sc->an_if_flags & IFF_PROMISC)) {
1930 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1931 !(ifp->if_flags & IFF_PROMISC) &&
1932 sc->an_if_flags & IFF_PROMISC) {
1937 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1940 sc->an_if_flags = ifp->if_flags;
1946 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1950 /* The Aironet has no multicast filter. */
1954 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1959 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1960 error = priv_check(td, PRIV_DRIVER);
1963 sc->an_sigitems = sc->an_nextitem = 0;
1965 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1966 char *pt = (char *)&sc->areq.an_val;
1967 bcopy((char *)&sc->an_sigitems, (char *)pt,
1970 sc->areq.an_len = sizeof(int) / 2;
1971 bcopy((char *)&sc->an_sigcache, (char *)pt,
1972 sizeof(struct an_sigcache) * sc->an_sigitems);
1973 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1974 sc->an_sigitems) / 2) + 1;
1977 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1983 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1986 if ((error = priv_check(td, PRIV_DRIVER)))
1989 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1992 an_setdef(sc, &sc->areq);
1995 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1996 if ((error = priv_check(td, PRIV_DRIVER)))
1998 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2001 mode = l_ioctl.command;
2004 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
2005 error = readrids(ifp, &l_ioctl);
2006 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
2007 error = writerids(ifp, &l_ioctl);
2008 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
2009 error = flashcard(ifp, &l_ioctl);
2015 /* copy out the updated command info */
2016 error = copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
2019 case SIOCGPRIVATE_1: /* used by Cisco client utility */
2020 if ((error = priv_check(td, PRIV_DRIVER)))
2022 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2025 l_ioctl.command = 0;
2027 (void) copyout(&error, l_ioctl.data, sizeof(error));
2031 sc->areq.an_len = sizeof(sc->areq);
2032 /* was that a good idea DJA we are doing a short-cut */
2033 switch (ireq->i_type) {
2034 case IEEE80211_IOC_SSID:
2036 if (ireq->i_val == -1) {
2037 sc->areq.an_type = AN_RID_STATUS;
2038 if (an_read_record(sc,
2039 (struct an_ltv_gen *)&sc->areq)) {
2044 len = status->an_ssidlen;
2045 tmpptr = status->an_ssid;
2046 } else if (ireq->i_val >= 0) {
2047 sc->areq.an_type = AN_RID_SSIDLIST;
2048 if (an_read_record(sc,
2049 (struct an_ltv_gen *)&sc->areq)) {
2054 max = (sc->areq.an_len - 4)
2055 / sizeof(struct an_ltv_ssid_entry);
2056 if ( max > MAX_SSIDS ) {
2057 printf("To many SSIDs only using "
2062 if (ireq->i_val > max) {
2067 len = ssids->an_entry[ireq->i_val].an_len;
2068 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2075 if (len > IEEE80211_NWID_LEN) {
2082 bzero(tmpstr, IEEE80211_NWID_LEN);
2083 bcopy(tmpptr, tmpstr, len);
2084 error = copyout(tmpstr, ireq->i_data,
2085 IEEE80211_NWID_LEN);
2087 case IEEE80211_IOC_NUMSSIDS:
2089 sc->areq.an_len = sizeof(sc->areq);
2090 sc->areq.an_type = AN_RID_SSIDLIST;
2091 if (an_read_record(sc,
2092 (struct an_ltv_gen *)&sc->areq)) {
2097 max = (sc->areq.an_len - 4)
2098 / sizeof(struct an_ltv_ssid_entry);
2100 if ( max > MAX_SSIDS ) {
2101 printf("To many SSIDs only using "
2108 case IEEE80211_IOC_WEP:
2110 sc->areq.an_type = AN_RID_ACTUALCFG;
2111 if (an_read_record(sc,
2112 (struct an_ltv_gen *)&sc->areq)) {
2118 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2119 if (config->an_authtype &
2120 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2121 ireq->i_val = IEEE80211_WEP_MIXED;
2123 ireq->i_val = IEEE80211_WEP_ON;
2125 ireq->i_val = IEEE80211_WEP_OFF;
2128 case IEEE80211_IOC_WEPKEY:
2130 * XXX: I'm not entierly convinced this is
2131 * correct, but it's what is implemented in
2132 * ancontrol so it will have to do until we get
2133 * access to actual Cisco code.
2135 if (ireq->i_val < 0 || ireq->i_val > 8) {
2140 if (ireq->i_val < 5) {
2142 sc->areq.an_type = AN_RID_WEP_TEMP;
2143 for (i = 0; i < 5; i++) {
2144 if (an_read_record(sc,
2145 (struct an_ltv_gen *)&sc->areq)) {
2149 if (key->kindex == 0xffff)
2151 if (key->kindex == ireq->i_val)
2153 /* Required to get next entry */
2154 sc->areq.an_type = AN_RID_WEP_PERM;
2161 /* We aren't allowed to read the value of the
2162 * key from the card so we just output zeros
2163 * like we would if we could read the card, but
2164 * denied the user access.
2168 error = copyout(tmpstr, ireq->i_data, len);
2170 case IEEE80211_IOC_NUMWEPKEYS:
2171 ireq->i_val = 9; /* include home key */
2173 case IEEE80211_IOC_WEPTXKEY:
2175 * For some strange reason, you have to read all
2176 * keys before you can read the txkey.
2179 sc->areq.an_type = AN_RID_WEP_TEMP;
2180 for (i = 0; i < 5; i++) {
2181 if (an_read_record(sc,
2182 (struct an_ltv_gen *) &sc->areq)) {
2186 if (key->kindex == 0xffff) {
2189 /* Required to get next entry */
2190 sc->areq.an_type = AN_RID_WEP_PERM;
2197 sc->areq.an_type = AN_RID_WEP_PERM;
2198 key->kindex = 0xffff;
2199 if (an_read_record(sc,
2200 (struct an_ltv_gen *)&sc->areq)) {
2205 ireq->i_val = key->mac[0];
2207 * Check for home mode. Map home mode into
2208 * 5th key since that is how it is stored on
2211 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2212 sc->areq.an_type = AN_RID_GENCONFIG;
2213 if (an_read_record(sc,
2214 (struct an_ltv_gen *)&sc->areq)) {
2219 if (config->an_home_product & AN_HOME_NETWORK)
2223 case IEEE80211_IOC_AUTHMODE:
2225 sc->areq.an_type = AN_RID_ACTUALCFG;
2226 if (an_read_record(sc,
2227 (struct an_ltv_gen *)&sc->areq)) {
2233 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2235 ireq->i_val = IEEE80211_AUTH_NONE;
2236 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2238 ireq->i_val = IEEE80211_AUTH_OPEN;
2239 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2240 AN_AUTHTYPE_SHAREDKEY) {
2241 ireq->i_val = IEEE80211_AUTH_SHARED;
2245 case IEEE80211_IOC_STATIONNAME:
2247 sc->areq.an_type = AN_RID_ACTUALCFG;
2248 if (an_read_record(sc,
2249 (struct an_ltv_gen *)&sc->areq)) {
2255 ireq->i_len = sizeof(config->an_nodename);
2256 tmpptr = config->an_nodename;
2257 bzero(tmpstr, IEEE80211_NWID_LEN);
2258 bcopy(tmpptr, tmpstr, ireq->i_len);
2259 error = copyout(tmpstr, ireq->i_data,
2260 IEEE80211_NWID_LEN);
2262 case IEEE80211_IOC_CHANNEL:
2264 sc->areq.an_type = AN_RID_STATUS;
2265 if (an_read_record(sc,
2266 (struct an_ltv_gen *)&sc->areq)) {
2272 ireq->i_val = status->an_cur_channel;
2274 case IEEE80211_IOC_CURCHAN:
2276 sc->areq.an_type = AN_RID_STATUS;
2277 if (an_read_record(sc,
2278 (struct an_ltv_gen *)&sc->areq)) {
2284 bzero(&ch, sizeof(ch));
2285 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2287 ch.ic_flags = IEEE80211_CHAN_B;
2288 ch.ic_ieee = status->an_cur_channel;
2289 error = copyout(&ch, ireq->i_data, sizeof(ch));
2291 case IEEE80211_IOC_POWERSAVE:
2293 sc->areq.an_type = AN_RID_ACTUALCFG;
2294 if (an_read_record(sc,
2295 (struct an_ltv_gen *)&sc->areq)) {
2301 if (config->an_psave_mode == AN_PSAVE_NONE) {
2302 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2303 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2304 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2305 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2306 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2307 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2308 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2312 case IEEE80211_IOC_POWERSAVESLEEP:
2314 sc->areq.an_type = AN_RID_ACTUALCFG;
2315 if (an_read_record(sc,
2316 (struct an_ltv_gen *)&sc->areq)) {
2322 ireq->i_val = config->an_listen_interval;
2327 if ((error = priv_check(td, PRIV_NET80211_MANAGE)))
2330 sc->areq.an_len = sizeof(sc->areq);
2332 * We need a config structure for everything but the WEP
2333 * key management and SSIDs so we get it now so avoid
2334 * duplicating this code every time.
2336 if (ireq->i_type != IEEE80211_IOC_SSID &&
2337 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2338 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2339 sc->areq.an_type = AN_RID_GENCONFIG;
2340 if (an_read_record(sc,
2341 (struct an_ltv_gen *)&sc->areq)) {
2347 switch (ireq->i_type) {
2348 case IEEE80211_IOC_SSID:
2349 sc->areq.an_len = sizeof(sc->areq);
2350 sc->areq.an_type = AN_RID_SSIDLIST;
2351 if (an_read_record(sc,
2352 (struct an_ltv_gen *)&sc->areq)) {
2357 if (ireq->i_len > IEEE80211_NWID_LEN) {
2362 max = (sc->areq.an_len - 4)
2363 / sizeof(struct an_ltv_ssid_entry);
2364 if ( max > MAX_SSIDS ) {
2365 printf("To many SSIDs only using "
2370 if (ireq->i_val > max) {
2375 error = copyin(ireq->i_data,
2376 ssids->an_entry[ireq->i_val].an_ssid,
2378 ssids->an_entry[ireq->i_val].an_len
2380 sc->areq.an_len = sizeof(sc->areq);
2381 sc->areq.an_type = AN_RID_SSIDLIST;
2382 an_setdef(sc, &sc->areq);
2387 case IEEE80211_IOC_WEP:
2388 switch (ireq->i_val) {
2389 case IEEE80211_WEP_OFF:
2390 config->an_authtype &=
2391 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2392 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2394 case IEEE80211_WEP_ON:
2395 config->an_authtype |=
2396 AN_AUTHTYPE_PRIVACY_IN_USE;
2397 config->an_authtype &=
2398 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2400 case IEEE80211_WEP_MIXED:
2401 config->an_authtype |=
2402 AN_AUTHTYPE_PRIVACY_IN_USE |
2403 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2409 if (error != EINVAL)
2410 an_setdef(sc, &sc->areq);
2413 case IEEE80211_IOC_WEPKEY:
2414 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2420 error = copyin(ireq->i_data, tmpstr, 13);
2426 * Map the 9th key into the home mode
2427 * since that is how it is stored on
2430 bzero(&sc->areq, sizeof(struct an_ltv_key));
2431 sc->areq.an_len = sizeof(struct an_ltv_key);
2432 key->mac[0] = 1; /* The others are 0. */
2433 if (ireq->i_val < 4) {
2434 sc->areq.an_type = AN_RID_WEP_TEMP;
2435 key->kindex = ireq->i_val;
2437 sc->areq.an_type = AN_RID_WEP_PERM;
2438 key->kindex = ireq->i_val - 4;
2440 key->klen = ireq->i_len;
2441 bcopy(tmpstr, key->key, key->klen);
2442 an_setdef(sc, &sc->areq);
2445 case IEEE80211_IOC_WEPTXKEY:
2446 if (ireq->i_val < 0 || ireq->i_val > 4) {
2453 * Map the 5th key into the home mode
2454 * since that is how it is stored on
2457 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2458 sc->areq.an_type = AN_RID_ACTUALCFG;
2459 if (an_read_record(sc,
2460 (struct an_ltv_gen *)&sc->areq)) {
2465 if (ireq->i_val == 4) {
2466 config->an_home_product |= AN_HOME_NETWORK;
2469 config->an_home_product &= ~AN_HOME_NETWORK;
2472 sc->an_config.an_home_product
2473 = config->an_home_product;
2475 /* update configuration */
2478 bzero(&sc->areq, sizeof(struct an_ltv_key));
2479 sc->areq.an_len = sizeof(struct an_ltv_key);
2480 sc->areq.an_type = AN_RID_WEP_PERM;
2481 key->kindex = 0xffff;
2482 key->mac[0] = ireq->i_val;
2483 an_setdef(sc, &sc->areq);
2486 case IEEE80211_IOC_AUTHMODE:
2487 switch (ireq->i_val) {
2488 case IEEE80211_AUTH_NONE:
2489 config->an_authtype = AN_AUTHTYPE_NONE |
2490 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2492 case IEEE80211_AUTH_OPEN:
2493 config->an_authtype = AN_AUTHTYPE_OPEN |
2494 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2496 case IEEE80211_AUTH_SHARED:
2497 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2498 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2503 if (error != EINVAL) {
2504 an_setdef(sc, &sc->areq);
2508 case IEEE80211_IOC_STATIONNAME:
2509 if (ireq->i_len > 16) {
2514 bzero(config->an_nodename, 16);
2515 error = copyin(ireq->i_data,
2516 config->an_nodename, ireq->i_len);
2517 an_setdef(sc, &sc->areq);
2520 case IEEE80211_IOC_CHANNEL:
2522 * The actual range is 1-14, but if you set it
2523 * to 0 you get the default so we let that work
2526 if (ireq->i_val < 0 || ireq->i_val >14) {
2531 config->an_ds_channel = ireq->i_val;
2532 an_setdef(sc, &sc->areq);
2535 case IEEE80211_IOC_POWERSAVE:
2536 switch (ireq->i_val) {
2537 case IEEE80211_POWERSAVE_OFF:
2538 config->an_psave_mode = AN_PSAVE_NONE;
2540 case IEEE80211_POWERSAVE_CAM:
2541 config->an_psave_mode = AN_PSAVE_CAM;
2543 case IEEE80211_POWERSAVE_PSP:
2544 config->an_psave_mode = AN_PSAVE_PSP;
2546 case IEEE80211_POWERSAVE_PSP_CAM:
2547 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2553 an_setdef(sc, &sc->areq);
2556 case IEEE80211_IOC_POWERSAVESLEEP:
2557 config->an_listen_interval = ireq->i_val;
2558 an_setdef(sc, &sc->areq);
2569 an_setdef(sc, &sc->areq);
2575 error = ether_ioctl(ifp, command, data);
2584 an_init_tx_ring(struct an_softc *sc)
2593 for (i = 0; i < AN_TX_RING_CNT; i++) {
2594 if (an_alloc_nicmem(sc, 1518 +
2597 sc->an_rdata.an_tx_fids[i] = id;
2598 sc->an_rdata.an_tx_ring[i] = 0;
2602 sc->an_rdata.an_tx_prod = 0;
2603 sc->an_rdata.an_tx_cons = 0;
2604 sc->an_rdata.an_tx_empty = 1;
2612 struct an_softc *sc = xsc;
2620 an_init_locked(struct an_softc *sc)
2629 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2632 sc->an_associated = 0;
2634 /* Allocate the TX buffers */
2635 if (an_init_tx_ring(sc)) {
2638 an_init_mpi350_desc(sc);
2639 if (an_init_tx_ring(sc)) {
2640 if_printf(ifp, "tx buffer allocation failed\n");
2645 /* Set our MAC address. */
2646 bcopy((char *)IF_LLADDR(sc->an_ifp),
2647 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2649 if (ifp->if_flags & IFF_BROADCAST)
2650 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2652 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2654 if (ifp->if_flags & IFF_MULTICAST)
2655 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2657 if (ifp->if_flags & IFF_PROMISC) {
2658 if (sc->an_monitor & AN_MONITOR) {
2659 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2660 sc->an_config.an_rxmode |=
2661 AN_RXMODE_80211_MONITOR_ANYBSS |
2662 AN_RXMODE_NO_8023_HEADER;
2664 sc->an_config.an_rxmode |=
2665 AN_RXMODE_80211_MONITOR_CURBSS |
2666 AN_RXMODE_NO_8023_HEADER;
2672 if (sc->an_have_rssimap)
2673 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2676 /* Set the ssid list */
2677 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2678 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2679 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2680 if_printf(ifp, "failed to set ssid list\n");
2684 /* Set the AP list */
2685 sc->an_aplist.an_type = AN_RID_APLIST;
2686 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2687 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2688 if_printf(ifp, "failed to set AP list\n");
2692 /* Set the configuration in the NIC */
2693 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2694 sc->an_config.an_type = AN_RID_GENCONFIG;
2695 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2696 if_printf(ifp, "failed to set configuration\n");
2700 /* Enable the MAC */
2701 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2702 if_printf(ifp, "failed to enable MAC\n");
2706 if (ifp->if_flags & IFF_PROMISC)
2707 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2709 /* enable interrupts */
2710 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2712 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2713 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2715 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2721 an_start(struct ifnet *ifp)
2723 struct an_softc *sc;
2727 an_start_locked(ifp);
2732 an_start_locked(struct ifnet *ifp)
2734 struct an_softc *sc;
2735 struct mbuf *m0 = NULL;
2736 struct an_txframe_802_3 tx_frame_802_3;
2737 struct ether_header *eh;
2739 unsigned char txcontrol;
2740 struct an_card_tx_desc an_tx_desc;
2749 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2752 if (!sc->an_associated)
2755 /* We can't send in monitor mode so toss any attempts. */
2756 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2758 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2766 idx = sc->an_rdata.an_tx_prod;
2769 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2771 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2772 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2776 id = sc->an_rdata.an_tx_fids[idx];
2777 eh = mtod(m0, struct ether_header *);
2779 bcopy((char *)&eh->ether_dhost,
2780 (char *)&tx_frame_802_3.an_tx_dst_addr,
2782 bcopy((char *)&eh->ether_shost,
2783 (char *)&tx_frame_802_3.an_tx_src_addr,
2786 /* minus src/dest mac & type */
2787 tx_frame_802_3.an_tx_802_3_payload_len =
2788 m0->m_pkthdr.len - 12;
2790 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2791 tx_frame_802_3.an_tx_802_3_payload_len,
2792 (caddr_t)&sc->an_txbuf);
2794 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2795 /* write the txcontrol only */
2796 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2800 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2801 sizeof(struct an_txframe_802_3));
2803 /* in mbuf header type is just before payload */
2804 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2805 tx_frame_802_3.an_tx_802_3_payload_len);
2808 * If there's a BPF listner, bounce a copy of
2809 * this frame to him.
2816 sc->an_rdata.an_tx_ring[idx] = id;
2817 if (an_cmd(sc, AN_CMD_TX, id))
2818 if_printf(ifp, "xmit failed\n");
2820 AN_INC(idx, AN_TX_RING_CNT);
2823 * Set a timeout in case the chip goes out to lunch.
2827 } else { /* MPI-350 */
2828 /* Disable interrupts. */
2829 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2831 while (sc->an_rdata.an_tx_empty ||
2832 idx != sc->an_rdata.an_tx_cons) {
2833 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2837 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2839 eh = mtod(m0, struct ether_header *);
2841 /* DJA optimize this to limit bcopy */
2842 bcopy((char *)&eh->ether_dhost,
2843 (char *)&tx_frame_802_3.an_tx_dst_addr,
2845 bcopy((char *)&eh->ether_shost,
2846 (char *)&tx_frame_802_3.an_tx_src_addr,
2849 /* minus src/dest mac & type */
2850 tx_frame_802_3.an_tx_802_3_payload_len =
2851 m0->m_pkthdr.len - 12;
2853 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2854 tx_frame_802_3.an_tx_802_3_payload_len,
2855 (caddr_t)&sc->an_txbuf);
2857 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2858 /* write the txcontrol only */
2859 bcopy((caddr_t)&txcontrol, &buf[0x08],
2863 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2864 sizeof(struct an_txframe_802_3));
2866 /* in mbuf header type is just before payload */
2867 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2868 tx_frame_802_3.an_tx_802_3_payload_len);
2871 bzero(&an_tx_desc, sizeof(an_tx_desc));
2872 an_tx_desc.an_offset = 0;
2873 an_tx_desc.an_eoc = 1;
2874 an_tx_desc.an_valid = 1;
2875 an_tx_desc.an_len = 0x44 +
2876 tx_frame_802_3.an_tx_802_3_payload_len;
2878 = sc->an_tx_buffer[idx].an_dma_paddr;
2879 for (i = sizeof(an_tx_desc) / 4 - 1; i >= 0; i--) {
2880 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2882 + (0 * sizeof(an_tx_desc))
2884 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2888 * If there's a BPF listner, bounce a copy of
2889 * this frame to him.
2895 AN_INC(idx, AN_MAX_TX_DESC);
2896 sc->an_rdata.an_tx_empty = 0;
2897 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2900 * Set a timeout in case the chip goes out to lunch.
2905 /* Re-enable interrupts. */
2906 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2910 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2912 sc->an_rdata.an_tx_prod = idx;
2918 an_stop(struct an_softc *sc)
2930 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2931 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2932 an_cmd(sc, AN_CMD_DISABLE, 0);
2934 for (i = 0; i < AN_TX_RING_CNT; i++)
2935 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2937 callout_stop(&sc->an_stat_ch);
2939 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2941 if (sc->an_flash_buffer) {
2942 free(sc->an_flash_buffer, M_DEVBUF);
2943 sc->an_flash_buffer = NULL;
2948 an_watchdog(struct an_softc *sc)
2958 if_printf(ifp, "device timeout\n");
2962 an_init_mpi350_desc(sc);
2965 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2969 an_shutdown(device_t dev)
2971 struct an_softc *sc;
2973 sc = device_get_softc(dev);
2983 an_resume(device_t dev)
2985 struct an_softc *sc;
2989 sc = device_get_softc(dev);
2996 an_init_mpi350_desc(sc);
2999 /* Recovery temporary keys */
3000 for (i = 0; i < 4; i++) {
3001 sc->areq.an_type = AN_RID_WEP_TEMP;
3002 sc->areq.an_len = sizeof(struct an_ltv_key);
3003 bcopy(&sc->an_temp_keys[i],
3004 &sc->areq, sizeof(struct an_ltv_key));
3005 an_setdef(sc, &sc->areq);
3008 if (ifp->if_flags & IFF_UP)
3009 an_start_locked(ifp);
3016 /* Aironet signal strength cache code.
3017 * store signal/noise/quality on per MAC src basis in
3018 * a small fixed cache. The cache wraps if > MAX slots
3019 * used. The cache may be zeroed out to start over.
3020 * Two simple filters exist to reduce computation:
3021 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
3022 * to ignore some packets. It defaults to ip only.
3023 * it could be used to focus on broadcast, non-IP 802.11 beacons.
3024 * 2. multicast/broadcast only. This may be used to
3025 * ignore unicast packets and only cache signal strength
3026 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
3027 * beacons and not unicast traffic.
3029 * The cache stores (MAC src(index), IP src (major clue), signal,
3032 * No apologies for storing IP src here. It's easy and saves much
3033 * trouble elsewhere. The cache is assumed to be INET dependent,
3034 * although it need not be.
3036 * Note: the Aironet only has a single byte of signal strength value
3037 * in the rx frame header, and it's not scaled to anything sensible.
3038 * This is kind of lame, but it's all we've got.
3041 #ifdef documentation
3043 int an_sigitems; /* number of cached entries */
3044 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
3045 int an_nextitem; /* index/# of entries */
3050 /* control variables for cache filtering. Basic idea is
3051 * to reduce cost (e.g., to only Mobile-IP agent beacons
3052 * which are broadcast or multicast). Still you might
3053 * want to measure signal strength anth unicast ping packets
3054 * on a pt. to pt. ant. setup.
3056 /* set true if you want to limit cache items to broadcast/mcast
3057 * only packets (not unicast). Useful for mobile-ip beacons which
3058 * are broadcast/multicast at network layer. Default is all packets
3059 * so ping/unicast anll work say anth pt. to pt. antennae setup.
3061 static int an_cache_mcastonly = 0;
3062 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
3063 &an_cache_mcastonly, 0, "");
3065 /* set true if you want to limit cache items to IP packets only
3067 static int an_cache_iponly = 1;
3068 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
3069 &an_cache_iponly, 0, "");
3072 * an_cache_store, per rx packet store signal
3073 * strength in MAC (src) indexed cache.
3076 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
3077 u_int8_t rx_rssi, u_int8_t rx_quality)
3081 static int cache_slot = 0; /* use this cache entry */
3082 static int wrapindex = 0; /* next "free" cache entry */
3087 * 2. configurable filter to throw out unicast packets,
3088 * keep multicast only.
3091 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
3095 /* filter for ip packets only
3097 if ( an_cache_iponly && !type_ipv4) {
3101 /* filter for broadcast/multicast only
3103 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3108 if_printf(sc->an_ifp, "q value %x (MSB=0x%x, LSB=0x%x) \n",
3109 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3112 /* find the ip header. we want to store the ip_src
3116 ip = mtod(m, struct ip *);
3119 /* do a linear search for a matching MAC address
3120 * in the cache table
3121 * . MAC address is 6 bytes,
3122 * . var w_nextitem holds total number of entries already cached
3124 for (i = 0; i < sc->an_nextitem; i++) {
3125 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3127 * so we already have this entry,
3134 /* did we find a matching mac address?
3135 * if yes, then overwrite a previously existing cache entry
3137 if (i < sc->an_nextitem ) {
3140 /* else, have a new address entry,so
3141 * add this new entry,
3142 * if table full, then we need to replace LRU entry
3146 /* check for space in cache table
3147 * note: an_nextitem also holds number of entries
3148 * added in the cache table
3150 if ( sc->an_nextitem < MAXANCACHE ) {
3151 cache_slot = sc->an_nextitem;
3153 sc->an_sigitems = sc->an_nextitem;
3155 /* no space found, so simply wrap anth wrap index
3156 * and "zap" the next entry
3159 if (wrapindex == MAXANCACHE) {
3162 cache_slot = wrapindex++;
3166 /* invariant: cache_slot now points at some slot
3169 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3170 log(LOG_ERR, "an_cache_store, bad index: %d of "
3171 "[0..%d], gross cache error\n",
3172 cache_slot, MAXANCACHE);
3176 /* store items in cache
3177 * .ip source address
3182 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3184 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3187 switch (an_cache_mode) {
3189 if (sc->an_have_rssimap) {
3190 sc->an_sigcache[cache_slot].signal =
3191 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3192 sc->an_sigcache[cache_slot].quality =
3193 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3195 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3196 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3200 if (sc->an_have_rssimap) {
3201 sc->an_sigcache[cache_slot].signal =
3202 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3203 sc->an_sigcache[cache_slot].quality =
3204 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3208 if (rx_quality > 100)
3210 sc->an_sigcache[cache_slot].signal = rx_rssi;
3211 sc->an_sigcache[cache_slot].quality = rx_quality;
3215 sc->an_sigcache[cache_slot].signal = rx_rssi;
3216 sc->an_sigcache[cache_slot].quality = rx_quality;
3220 sc->an_sigcache[cache_slot].noise = 0;
3227 an_media_change(struct ifnet *ifp)
3229 struct an_softc *sc = ifp->if_softc;
3230 struct an_ltv_genconfig *cfg;
3231 int otype = sc->an_config.an_opmode;
3232 int orate = sc->an_tx_rate;
3235 sc->an_tx_rate = ieee80211_media2rate(
3236 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3237 if (sc->an_tx_rate < 0)
3240 if (orate != sc->an_tx_rate) {
3241 /* Read the current configuration */
3242 sc->an_config.an_type = AN_RID_GENCONFIG;
3243 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3244 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3245 cfg = &sc->an_config;
3247 /* clear other rates and set the only one we want */
3248 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3249 cfg->an_rates[0] = sc->an_tx_rate;
3251 /* Save the new rate */
3252 sc->an_config.an_type = AN_RID_GENCONFIG;
3253 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3256 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3257 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3259 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3261 if (otype != sc->an_config.an_opmode ||
3262 orate != sc->an_tx_rate)
3270 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3272 struct an_ltv_status status;
3273 struct an_softc *sc = ifp->if_softc;
3275 imr->ifm_active = IFM_IEEE80211;
3278 status.an_len = sizeof(status);
3279 status.an_type = AN_RID_STATUS;
3280 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3281 /* If the status read fails, just lie. */
3282 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3283 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3286 if (sc->an_tx_rate == 0) {
3287 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3290 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3291 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3292 imr->ifm_active |= ieee80211_rate2media(NULL,
3293 status.an_current_tx_rate, IEEE80211_MODE_AUTO);
3294 imr->ifm_status = IFM_AVALID;
3295 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3296 imr->ifm_status |= IFM_ACTIVE;
3300 /********************** Cisco utility support routines *************/
3303 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3308 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3311 struct an_softc *sc;
3314 switch (l_ioctl->command) {
3316 rid = AN_RID_CAPABILITIES;
3319 rid = AN_RID_GENCONFIG;
3322 rid = AN_RID_SSIDLIST;
3325 rid = AN_RID_APLIST;
3328 rid = AN_RID_DRVNAME;
3331 rid = AN_RID_ENCAPPROTO;
3334 rid = AN_RID_WEP_TEMP;
3337 rid = AN_RID_WEP_PERM;
3340 rid = AN_RID_STATUS;
3343 rid = AN_RID_32BITS_DELTA;
3346 rid = AN_RID_32BITS_CUM;
3353 if (rid == 999) /* Is bad command */
3357 sc->areq.an_len = AN_MAX_DATALEN;
3358 sc->areq.an_type = rid;
3360 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3362 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3365 /* the data contains the length at first */
3366 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3367 sizeof(sc->areq.an_len))) {
3371 /* Just copy the data back */
3372 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3384 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3386 struct an_softc *sc;
3387 int rid, command, error;
3392 command = l_ioctl->command;
3396 rid = AN_RID_SSIDLIST;
3399 rid = AN_RID_CAPABILITIES;
3402 rid = AN_RID_APLIST;
3405 rid = AN_RID_GENCONFIG;
3408 an_cmd(sc, AN_CMD_ENABLE, 0);
3412 an_cmd(sc, AN_CMD_DISABLE, 0);
3417 * This command merely clears the counts does not actually
3418 * store any data only reads rid. But as it changes the cards
3419 * state, I put it in the writerid routines.
3422 rid = AN_RID_32BITS_DELTACLR;
3424 sc->areq.an_len = AN_MAX_DATALEN;
3425 sc->areq.an_type = rid;
3427 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3428 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3431 /* the data contains the length at first */
3432 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3433 sizeof(sc->areq.an_len));
3438 /* Just copy the data */
3439 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3447 rid = AN_RID_WEP_TEMP;
3450 rid = AN_RID_WEP_PERM;
3453 rid = AN_RID_LEAPUSERNAME;
3456 rid = AN_RID_LEAPPASSWORD;
3463 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3465 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3466 sc->areq.an_type = rid;
3468 /* Just copy the data back */
3470 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3476 an_cmd(sc, AN_CMD_DISABLE, 0);
3477 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3478 an_cmd(sc, AN_CMD_ENABLE, 0);
3485 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3489 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3490 "flash", ((x) / hz) + 1);
3491 #define FLASH_COMMAND 0x7e7e
3492 #define FLASH_SIZE 32 * 1024
3495 unstickbusy(struct ifnet *ifp)
3497 struct an_softc *sc = ifp->if_softc;
3499 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3500 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3501 AN_EV_CLR_STUCK_BUSY);
3508 * Wait for busy completion from card wait for delay uSec's Return true for
3509 * success meaning command reg is clear
3513 WaitBusy(struct ifnet *ifp, int uSec)
3515 int statword = 0xffff;
3517 struct an_softc *sc = ifp->if_softc;
3519 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3520 FLASH_DELAY(sc, 10);
3522 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3524 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3529 return 0 == (AN_CMD_BUSY & statword);
3533 * STEP 1) Disable MAC and do soft reset on card.
3537 cmdreset(struct ifnet *ifp)
3540 struct an_softc *sc = ifp->if_softc;
3545 an_cmd(sc, AN_CMD_DISABLE, 0);
3547 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3548 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3552 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3554 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3557 if (!(status = WaitBusy(ifp, 100))) {
3558 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3567 * STEP 2) Put the card in legendary flash mode
3571 setflashmode(struct ifnet *ifp)
3574 struct an_softc *sc = ifp->if_softc;
3576 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3577 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3578 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3579 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3582 * mdelay(500); // 500ms delay
3585 FLASH_DELAY(sc, 500);
3587 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3588 printf("Waitbusy hang after setflash mode\n");
3595 * Get a character from the card matching matchbyte Step 3)
3599 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3602 unsigned char rbyte = 0;
3604 struct an_softc *sc = ifp->if_softc;
3608 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3610 if (dwelltime && !(0x8000 & rchar)) {
3612 FLASH_DELAY(sc, 10);
3615 rbyte = 0xff & rchar;
3617 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3618 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3622 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3624 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3626 } while (dwelltime > 0);
3631 * Put character to SWS0 wait for dwelltime x 50us for echo .
3635 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3638 int pollbusy, waittime;
3639 struct an_softc *sc = ifp->if_softc;
3646 waittime = dwelltime;
3649 * Wait for busy bit d15 to go false indicating buffer empty
3652 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3654 if (pollbusy & 0x8000) {
3655 FLASH_DELAY(sc, 50);
3661 while (waittime >= 0);
3663 /* timeout for busy clear wait */
3665 if (waittime <= 0) {
3666 if_printf(ifp, "flash putchar busywait timeout!\n");
3670 * Port is clear now write byte and wait for it to echo back
3673 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3674 FLASH_DELAY(sc, 50);
3676 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3677 } while (dwelltime >= 0 && echo != byte);
3680 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3682 return echo == byte;
3686 * Transfer 32k of firmware data from user buffer to our buffer and send to
3691 flashputbuf(struct ifnet *ifp)
3693 unsigned short *bufp;
3695 struct an_softc *sc = ifp->if_softc;
3699 bufp = sc->an_flash_buffer;
3702 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3703 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3705 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3706 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3709 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3710 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3711 ((u_int32_t *)bufp)[nwords] & 0xffff);
3715 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3721 * After flashing restart the card.
3725 flashrestart(struct ifnet *ifp)
3728 struct an_softc *sc = ifp->if_softc;
3730 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3734 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3739 * Entry point for flash ioclt.
3743 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3746 struct an_softc *sc;
3750 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3753 status = l_ioctl->command;
3755 switch (l_ioctl->command) {
3757 return cmdreset(ifp);
3760 if (sc->an_flash_buffer) {
3761 free(sc->an_flash_buffer, M_DEVBUF);
3762 sc->an_flash_buffer = NULL;
3764 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3765 if (sc->an_flash_buffer)
3766 return setflashmode(ifp);
3770 case AIROFLSHGCHR: /* Get char from aux */
3772 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3776 z = *(int *)&sc->areq;
3777 if ((status = flashgchar(ifp, z, 8000)) == 1)
3781 case AIROFLSHPCHR: /* Send char to card. */
3783 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3787 z = *(int *)&sc->areq;
3788 if ((status = flashpchar(ifp, z, 8000)) == -1)
3793 case AIROFLPUTBUF: /* Send 32k to card */
3794 if (l_ioctl->len > FLASH_SIZE) {
3795 if_printf(ifp, "Buffer to big, %x %x\n",
3796 l_ioctl->len, FLASH_SIZE);
3800 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3805 if ((status = flashputbuf(ifp)) != 0)
3811 if ((status = flashrestart(ifp)) != 0) {
3812 if_printf(ifp, "FLASHRESTART returned %d\n", status);