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 * We probe for an Aironet 4500/4800 card by attempting to
308 * read the default SSID list. On reset, the first entry in
309 * the SSID list will contain the name "tsunami." If we don't
310 * find this, then there's no card present.
313 an_probe(device_t dev)
315 struct an_softc *sc = device_get_softc(dev);
316 struct an_ltv_ssidlist_new ssid;
319 bzero((char *)&ssid, sizeof(ssid));
321 error = an_alloc_port(dev, 0, AN_IOSIZ);
325 /* can't do autoprobing */
326 if (rman_get_start(sc->port_res) == -1)
330 * We need to fake up a softc structure long enough
331 * to be able to issue commands and call some of the
334 ssid.an_len = sizeof(ssid);
335 ssid.an_type = AN_RID_SSIDLIST;
337 /* Make sure interrupts are disabled. */
339 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
340 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
343 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
348 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
353 if (an_read_record(sc, (struct an_ltv_gen *)&ssid)) {
358 /* See if the ssid matches what we expect ... but doesn't have to */
359 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID)) {
367 mtx_destroy(&sc->an_mtx);
372 * Allocate a port resource with the given resource id.
375 an_alloc_port(device_t dev, int rid, int size)
377 struct an_softc *sc = device_get_softc(dev);
378 struct resource *res;
380 res = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT, &rid,
392 * Allocate a memory resource with the given resource id.
394 int an_alloc_memory(device_t dev, int rid, int size)
396 struct an_softc *sc = device_get_softc(dev);
397 struct resource *res;
399 res = bus_alloc_resource_anywhere(dev, SYS_RES_MEMORY, &rid,
412 * Allocate a auxiliary memory resource with the given resource id.
414 int an_alloc_aux_memory(device_t dev, int rid, int size)
416 struct an_softc *sc = device_get_softc(dev);
417 struct resource *res;
419 res = bus_alloc_resource_anywhere(dev, SYS_RES_MEMORY, &rid,
422 sc->mem_aux_rid = rid;
423 sc->mem_aux_res = res;
424 sc->mem_aux_used = size;
432 * Allocate an irq resource with the given resource id.
435 an_alloc_irq(device_t dev, int rid, int flags)
437 struct an_softc *sc = device_get_softc(dev);
438 struct resource *res;
440 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
441 (RF_ACTIVE | flags));
452 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
454 bus_addr_t *paddr = (bus_addr_t*) arg;
455 *paddr = segs->ds_addr;
459 * Alloc DMA memory and set the pointer to it
462 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
467 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
468 BUS_DMA_NOWAIT, &dma->an_dma_map);
472 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
476 mapflags | BUS_DMA_NOWAIT);
480 dma->an_dma_size = size;
484 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
486 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
491 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
493 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
494 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
495 dma->an_dma_vaddr = 0;
499 * Release all resources
502 an_release_resources(device_t dev)
504 struct an_softc *sc = device_get_softc(dev);
508 bus_release_resource(dev, SYS_RES_IOPORT,
509 sc->port_rid, sc->port_res);
513 bus_release_resource(dev, SYS_RES_MEMORY,
514 sc->mem_rid, sc->mem_res);
517 if (sc->mem_aux_res) {
518 bus_release_resource(dev, SYS_RES_MEMORY,
519 sc->mem_aux_rid, sc->mem_aux_res);
523 bus_release_resource(dev, SYS_RES_IRQ,
524 sc->irq_rid, sc->irq_res);
527 if (sc->an_rid_buffer.an_dma_paddr) {
528 an_dma_free(sc, &sc->an_rid_buffer);
530 for (i = 0; i < AN_MAX_RX_DESC; i++)
531 if (sc->an_rx_buffer[i].an_dma_paddr) {
532 an_dma_free(sc, &sc->an_rx_buffer[i]);
534 for (i = 0; i < AN_MAX_TX_DESC; i++)
535 if (sc->an_tx_buffer[i].an_dma_paddr) {
536 an_dma_free(sc, &sc->an_tx_buffer[i]);
539 bus_dma_tag_destroy(sc->an_dtag);
545 an_init_mpi350_desc(struct an_softc *sc)
547 struct an_command cmd_struct;
548 struct an_reply reply;
549 struct an_card_rid_desc an_rid_desc;
550 struct an_card_rx_desc an_rx_desc;
551 struct an_card_tx_desc an_tx_desc;
555 if(!sc->an_rid_buffer.an_dma_paddr)
556 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
557 &sc->an_rid_buffer, 0);
558 for (i = 0; i < AN_MAX_RX_DESC; i++)
559 if(!sc->an_rx_buffer[i].an_dma_paddr)
560 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
561 &sc->an_rx_buffer[i], 0);
562 for (i = 0; i < AN_MAX_TX_DESC; i++)
563 if(!sc->an_tx_buffer[i].an_dma_paddr)
564 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
565 &sc->an_tx_buffer[i], 0);
568 * Allocate RX descriptor
570 bzero(&reply,sizeof(reply));
571 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
572 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
573 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
574 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
575 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
576 if_printf(sc->an_ifp, "failed to allocate RX descriptor\n");
580 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
581 bzero(&an_rx_desc, sizeof(an_rx_desc));
582 an_rx_desc.an_valid = 1;
583 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
584 an_rx_desc.an_done = 0;
585 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
587 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
588 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
589 + (desc * sizeof(an_rx_desc))
591 ((u_int32_t *)(void *)&an_rx_desc)[i]);
595 * Allocate TX descriptor
598 bzero(&reply,sizeof(reply));
599 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
600 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
601 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
602 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
603 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
604 if_printf(sc->an_ifp, "failed to allocate TX descriptor\n");
608 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
609 bzero(&an_tx_desc, sizeof(an_tx_desc));
610 an_tx_desc.an_offset = 0;
611 an_tx_desc.an_eoc = 0;
612 an_tx_desc.an_valid = 0;
613 an_tx_desc.an_len = 0;
614 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
616 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
617 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
618 + (desc * sizeof(an_tx_desc))
620 ((u_int32_t *)(void *)&an_tx_desc)[i]);
624 * Allocate RID descriptor
627 bzero(&reply,sizeof(reply));
628 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
629 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
630 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
631 cmd_struct.an_parm2 = 1;
632 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
633 if_printf(sc->an_ifp, "failed to allocate host descriptor\n");
637 bzero(&an_rid_desc, sizeof(an_rid_desc));
638 an_rid_desc.an_valid = 1;
639 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
640 an_rid_desc.an_rid = 0;
641 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
643 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
644 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
645 ((u_int32_t *)(void *)&an_rid_desc)[i]);
651 an_attach(struct an_softc *sc, int flags)
658 ifp = sc->an_ifp = if_alloc(IFT_ETHER);
660 device_printf(sc->an_dev, "can not if_alloc()\n");
664 if_initname(ifp, device_get_name(sc->an_dev),
665 device_get_unit(sc->an_dev));
668 sc->an_associated = 0;
670 sc->an_was_monitor = 0;
671 sc->an_flash_buffer = NULL;
677 error = an_init_mpi350_desc(sc);
682 /* Load factory config */
683 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
684 device_printf(sc->an_dev, "failed to load config data\n");
688 /* Read the current configuration */
689 sc->an_config.an_type = AN_RID_GENCONFIG;
690 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
691 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
692 device_printf(sc->an_dev, "read record failed\n");
696 /* Read the card capabilities */
697 sc->an_caps.an_type = AN_RID_CAPABILITIES;
698 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
699 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
700 device_printf(sc->an_dev, "read record failed\n");
705 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
706 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
707 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
708 device_printf(sc->an_dev, "read record failed\n");
713 sc->an_aplist.an_type = AN_RID_APLIST;
714 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
715 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
716 device_printf(sc->an_dev, "read record failed\n");
721 /* Read the RSSI <-> dBm map */
722 sc->an_have_rssimap = 0;
723 if (sc->an_caps.an_softcaps & 8) {
724 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
725 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
726 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
727 device_printf(sc->an_dev,
728 "unable to get RSSI <-> dBM map\n");
730 device_printf(sc->an_dev, "got RSSI <-> dBM map\n");
731 sc->an_have_rssimap = 1;
734 device_printf(sc->an_dev, "no RSSI <-> dBM map\n");
739 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
740 ifp->if_ioctl = an_ioctl;
741 ifp->if_start = an_start;
742 ifp->if_init = an_init;
743 ifp->if_baudrate = 10000000;
744 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
745 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
746 IFQ_SET_READY(&ifp->if_snd);
748 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
749 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
750 sizeof(AN_DEFAULT_NODENAME) - 1);
752 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
753 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
754 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
755 sizeof(AN_DEFAULT_NETNAME) - 1);
756 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
758 sc->an_config.an_opmode =
759 AN_OPMODE_INFRASTRUCTURE_STATION;
762 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
766 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
767 if_printf(ifp, "supported rates: ");
768 #define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
769 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
771 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
772 for (i = 0; i < nrate; i++) {
773 r = sc->an_caps.an_rates[i];
774 mword = ieee80211_rate2media(NULL, r, IEEE80211_MODE_AUTO);
777 printf("%s%d%sMbps", (i != 0 ? " " : ""),
778 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
780 ADD(mword, IFM_IEEE80211_ADHOC);
783 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
788 * Call MI attach routine.
791 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
792 callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0);
797 mtx_destroy(&sc->an_mtx);
804 an_detach(device_t dev)
806 struct an_softc *sc = device_get_softc(dev);
807 struct ifnet *ifp = sc->an_ifp;
810 device_printf(dev,"already unloaded\n");
816 ifmedia_removeall(&sc->an_ifmedia);
817 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
820 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
821 callout_drain(&sc->an_stat_ch);
823 an_release_resources(dev);
824 mtx_destroy(&sc->an_mtx);
829 an_rxeof(struct an_softc *sc)
832 struct ether_header *eh;
833 struct ieee80211_frame *ih;
834 struct an_rxframe rx_frame;
835 struct an_rxframe_802_3 rx_frame_802_3;
837 int len, id, error = 0, i, count = 0;
838 int ieee80211_header_len;
841 struct an_card_rx_desc an_rx_desc;
849 id = CSR_READ_2(sc, AN_RX_FID);
851 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
852 /* read raw 802.11 packet */
853 bpf_buf = sc->buf_802_11;
856 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
858 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
863 * skip beacon by default since this increases the
867 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
868 (rx_frame.an_frame_ctl &
869 IEEE80211_FC0_SUBTYPE_BEACON)) {
873 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
874 len = rx_frame.an_rx_payload_len
876 /* Check for insane frame length */
877 if (len > sizeof(sc->buf_802_11)) {
878 if_printf(ifp, "oversized packet "
879 "received (%d, %d)\n",
881 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
885 bcopy((char *)&rx_frame,
886 bpf_buf, sizeof(rx_frame));
888 error = an_read_data(sc, id, sizeof(rx_frame),
889 (caddr_t)bpf_buf+sizeof(rx_frame),
890 rx_frame.an_rx_payload_len);
892 fc1=rx_frame.an_frame_ctl >> 8;
893 ieee80211_header_len =
894 sizeof(struct ieee80211_frame);
895 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
896 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
897 ieee80211_header_len += ETHER_ADDR_LEN;
900 len = rx_frame.an_rx_payload_len
901 + ieee80211_header_len;
902 /* Check for insane frame length */
903 if (len > sizeof(sc->buf_802_11)) {
904 if_printf(ifp, "oversized packet "
905 "received (%d, %d)\n",
907 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
911 ih = (struct ieee80211_frame *)bpf_buf;
913 bcopy((char *)&rx_frame.an_frame_ctl,
914 (char *)ih, ieee80211_header_len);
916 error = an_read_data(sc, id, sizeof(rx_frame) +
918 (caddr_t)ih +ieee80211_header_len,
919 rx_frame.an_rx_payload_len);
921 /* dump raw 802.11 packet to bpf and skip ip stack */
922 BPF_TAP(ifp, bpf_buf, len);
924 MGETHDR(m, M_NOWAIT, MT_DATA);
926 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
929 if (!(MCLGET(m, M_NOWAIT))) {
931 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
934 m->m_pkthdr.rcvif = ifp;
935 /* Read Ethernet encapsulated packet */
938 /* Read NIC frame header */
939 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
942 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
946 /* Read in the 802_3 frame header */
947 if (an_read_data(sc, id, 0x34,
948 (caddr_t)&rx_frame_802_3,
949 sizeof(rx_frame_802_3))) {
951 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
954 if (rx_frame_802_3.an_rx_802_3_status != 0) {
956 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
959 /* Check for insane frame length */
960 len = rx_frame_802_3.an_rx_802_3_payload_len;
961 if (len > sizeof(sc->buf_802_11)) {
963 if_printf(ifp, "oversized packet "
964 "received (%d, %d)\n",
966 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
969 m->m_pkthdr.len = m->m_len =
970 rx_frame_802_3.an_rx_802_3_payload_len + 12;
972 eh = mtod(m, struct ether_header *);
974 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
975 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
976 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
977 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
979 /* in mbuf header type is just before payload */
980 error = an_read_data(sc, id, 0x44,
981 (caddr_t)&(eh->ether_type),
982 rx_frame_802_3.an_rx_802_3_payload_len);
986 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
989 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
991 /* Receive packet. */
993 an_cache_store(sc, eh, m,
994 rx_frame.an_rx_signal_strength,
998 (*ifp->if_input)(ifp, m);
1002 } else { /* MPI-350 */
1003 for (count = 0; count < AN_MAX_RX_DESC; count++){
1004 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1005 ((u_int32_t *)(void *)&an_rx_desc)[i]
1006 = CSR_MEM_AUX_READ_4(sc,
1008 + (count * sizeof(an_rx_desc))
1011 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1012 buf = sc->an_rx_buffer[count].an_dma_vaddr;
1014 MGETHDR(m, M_NOWAIT, MT_DATA);
1016 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1019 if (!(MCLGET(m, M_NOWAIT))) {
1021 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1024 m->m_pkthdr.rcvif = ifp;
1025 /* Read Ethernet encapsulated packet */
1028 * No ANCACHE support since we just get back
1029 * an Ethernet packet no 802.11 info
1033 /* Read NIC frame header */
1034 bcopy(buf, (caddr_t)&rx_frame,
1038 /* Check for insane frame length */
1039 len = an_rx_desc.an_len + 12;
1040 if (len > MCLBYTES) {
1042 if_printf(ifp, "oversized packet "
1043 "received (%d, %d)\n",
1045 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1049 m->m_pkthdr.len = m->m_len =
1050 an_rx_desc.an_len + 12;
1052 eh = mtod(m, struct ether_header *);
1054 bcopy(buf, (char *)eh,
1057 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
1059 /* Receive packet. */
1062 an_cache_store(sc, eh, m,
1063 rx_frame.an_rx_signal_strength,
1068 (*ifp->if_input)(ifp, m);
1071 an_rx_desc.an_valid = 1;
1072 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1073 an_rx_desc.an_done = 0;
1074 an_rx_desc.an_phys =
1075 sc->an_rx_buffer[count].an_dma_paddr;
1077 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1078 CSR_MEM_AUX_WRITE_4(sc,
1080 + (count * sizeof(an_rx_desc))
1082 ((u_int32_t *)(void *)&an_rx_desc)[i]);
1085 if_printf(ifp, "Didn't get valid RX packet "
1088 an_rx_desc.an_valid, an_rx_desc.an_len);
1095 an_txeof(struct an_softc *sc, int status)
1104 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1107 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1109 if (status & AN_EV_TX_EXC) {
1110 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1112 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1114 for (i = 0; i < AN_TX_RING_CNT; i++) {
1115 if (id == sc->an_rdata.an_tx_ring[i]) {
1116 sc->an_rdata.an_tx_ring[i] = 0;
1121 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1122 } else { /* MPI 350 */
1123 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1124 if (!sc->an_rdata.an_tx_empty){
1125 if (status & AN_EV_TX_EXC) {
1126 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1128 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1129 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1130 if (sc->an_rdata.an_tx_prod ==
1131 sc->an_rdata.an_tx_cons)
1132 sc->an_rdata.an_tx_empty = 1;
1140 * We abuse the stats updater to check the current NIC status. This
1141 * is important because we don't want to allow transmissions until
1142 * the NIC has synchronized to the current cell (either as the master
1143 * in an ad-hoc group, or as a station connected to an access point).
1145 * Note that this function will be called via callout(9) with a lock held.
1148 an_stats_update(void *xsc)
1150 struct an_softc *sc;
1156 if (sc->an_timer > 0 && --sc->an_timer == 0)
1159 sc->an_status.an_type = AN_RID_STATUS;
1160 sc->an_status.an_len = sizeof(struct an_ltv_status);
1161 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status))
1164 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1165 sc->an_associated = 1;
1167 sc->an_associated = 0;
1169 /* Don't do this while we're transmitting */
1170 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
1171 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1175 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1176 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1177 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len))
1180 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1188 struct an_softc *sc;
1192 sc = (struct an_softc*)xsc;
1203 /* Disable interrupts. */
1204 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1206 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1207 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1209 if (status & AN_EV_MIC) {
1210 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1213 if (status & AN_EV_LINKSTAT) {
1214 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1215 == AN_LINKSTAT_ASSOCIATED)
1216 sc->an_associated = 1;
1218 sc->an_associated = 0;
1219 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1222 if (status & AN_EV_RX) {
1224 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1227 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1228 an_txeof(sc, status);
1229 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1232 if (status & AN_EV_TX) {
1233 an_txeof(sc, status);
1234 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1237 if (status & AN_EV_TX_EXC) {
1238 an_txeof(sc, status);
1239 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1242 if (status & AN_EV_ALLOC)
1243 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1245 /* Re-enable interrupts. */
1246 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1248 if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1249 an_start_locked(ifp);
1258 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1259 struct an_reply *reply)
1264 for (i = 0; i != AN_TIMEOUT; i++) {
1265 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1271 if( i == AN_TIMEOUT) {
1276 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1277 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1278 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1279 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1281 for (i = 0; i < AN_TIMEOUT; i++) {
1282 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1287 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1288 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1289 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1290 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1292 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1293 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
1294 AN_EV_CLR_STUCK_BUSY);
1296 /* Ack the command */
1297 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1299 if (i == AN_TIMEOUT)
1306 an_cmd(struct an_softc *sc, int cmd, int val)
1311 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1312 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1313 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1314 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1316 for (i = 0; i < AN_TIMEOUT; i++) {
1317 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1320 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1321 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1325 for (i = 0; i < AN_TIMEOUT; i++) {
1326 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1327 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1328 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1329 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1330 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1334 /* Ack the command */
1335 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1337 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1338 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1340 if (i == AN_TIMEOUT)
1347 * This reset sequence may look a little strange, but this is the
1348 * most reliable method I've found to really kick the NIC in the
1349 * head and force it to reboot correctly.
1352 an_reset(struct an_softc *sc)
1358 an_cmd(sc, AN_CMD_ENABLE, 0);
1359 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1360 an_cmd(sc, AN_CMD_NOOP2, 0);
1362 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1363 device_printf(sc->an_dev, "reset failed\n");
1365 an_cmd(sc, AN_CMD_DISABLE, 0);
1371 * Read an LTV record from the NIC.
1374 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1376 struct an_ltv_gen *an_ltv;
1377 struct an_card_rid_desc an_rid_desc;
1378 struct an_command cmd;
1379 struct an_reply reply;
1386 if (ltv->an_len < 4 || ltv->an_type == 0)
1391 /* Tell the NIC to enter record read mode. */
1392 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1393 if_printf(ifp, "RID access failed\n");
1397 /* Seek to the record. */
1398 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1399 if_printf(ifp, "seek to record failed\n");
1404 * Read the length and record type and make sure they
1405 * match what we expect (this verifies that we have enough
1406 * room to hold all of the returned data).
1407 * Length includes type but not length.
1409 len = CSR_READ_2(sc, AN_DATA1);
1410 if (len > (ltv->an_len - 2)) {
1411 if_printf(ifp, "record length mismatch -- expected %d, "
1412 "got %d for Rid %x\n",
1413 ltv->an_len - 2, len, ltv->an_type);
1414 len = ltv->an_len - 2;
1416 ltv->an_len = len + 2;
1419 /* Now read the data. */
1420 len -= 2; /* skip the type */
1422 for (i = len; i > 1; i -= 2)
1423 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1425 ptr2 = (u_int8_t *)ptr;
1426 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1428 } else { /* MPI-350 */
1429 if (!sc->an_rid_buffer.an_dma_vaddr)
1431 an_rid_desc.an_valid = 1;
1432 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1433 an_rid_desc.an_rid = 0;
1434 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1435 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1437 bzero(&cmd, sizeof(cmd));
1438 bzero(&reply, sizeof(reply));
1439 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1440 cmd.an_parm0 = ltv->an_type;
1442 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1443 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1444 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1446 if (an_cmd_struct(sc, &cmd, &reply)
1447 || reply.an_status & AN_CMD_QUAL_MASK) {
1448 if_printf(ifp, "failed to read RID %x %x %x %x %x, %d\n",
1458 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1459 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1460 an_rid_desc.an_len = an_ltv->an_len;
1463 len = an_rid_desc.an_len;
1464 if (len > (ltv->an_len - 2)) {
1465 if_printf(ifp, "record length mismatch -- expected %d, "
1466 "got %d for Rid %x\n",
1467 ltv->an_len - 2, len, ltv->an_type);
1468 len = ltv->an_len - 2;
1470 ltv->an_len = len + 2;
1472 bcopy(&an_ltv->an_type,
1478 an_dump_record(sc, ltv, "Read");
1484 * Same as read, except we inject data instead of reading it.
1487 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1489 struct an_card_rid_desc an_rid_desc;
1490 struct an_command cmd;
1491 struct an_reply reply;
1498 an_dump_record(sc, ltv, "Write");
1501 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1504 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1508 * Length includes type but not length.
1510 len = ltv->an_len - 2;
1511 CSR_WRITE_2(sc, AN_DATA1, len);
1513 len -= 2; /* skip the type */
1515 for (i = len; i > 1; i -= 2)
1516 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1518 ptr2 = (u_int8_t *)ptr;
1519 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1522 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1527 for (i = 0; i != AN_TIMEOUT; i++) {
1528 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1534 if (i == AN_TIMEOUT) {
1538 an_rid_desc.an_valid = 1;
1539 an_rid_desc.an_len = ltv->an_len - 2;
1540 an_rid_desc.an_rid = ltv->an_type;
1541 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1543 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1544 an_rid_desc.an_len);
1546 bzero(&cmd,sizeof(cmd));
1547 bzero(&reply,sizeof(reply));
1548 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1549 cmd.an_parm0 = ltv->an_type;
1551 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1552 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1553 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1557 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1558 if_printf(sc->an_ifp,
1559 "failed to write RID 1 %x %x %x %x %x, %d\n",
1570 if (reply.an_status & AN_CMD_QUAL_MASK) {
1571 if_printf(sc->an_ifp,
1572 "failed to write RID 2 %x %x %x %x %x, %d\n",
1588 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1596 len = ltv->an_len - 4;
1597 if_printf(sc->an_ifp, "RID %4x, Length %4d, Mode %s\n",
1598 ltv->an_type, ltv->an_len - 4, string);
1600 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1601 if_printf(sc->an_ifp, "\t");
1602 bzero(buf,sizeof(buf));
1604 ptr2 = (u_int8_t *)<v->an_val;
1605 for (i = len; i > 0; i--) {
1606 printf("%02x ", *ptr2);
1613 if (++count == 16) {
1616 if_printf(sc->an_ifp, "\t");
1617 bzero(buf,sizeof(buf));
1620 for (; count != 16; count++) {
1623 printf(" %s\n",buf);
1628 an_seek(struct an_softc *sc, int id, int off, int chan)
1643 if_printf(sc->an_ifp, "invalid data path: %x\n", chan);
1647 CSR_WRITE_2(sc, selreg, id);
1648 CSR_WRITE_2(sc, offreg, off);
1650 for (i = 0; i < AN_TIMEOUT; i++) {
1651 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1655 if (i == AN_TIMEOUT)
1662 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1669 if (an_seek(sc, id, off, AN_BAP1))
1673 ptr = (u_int16_t *)buf;
1674 for (i = len; i > 1; i -= 2)
1675 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1677 ptr2 = (u_int8_t *)ptr;
1678 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1685 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1692 if (an_seek(sc, id, off, AN_BAP0))
1696 ptr = (u_int16_t *)buf;
1697 for (i = len; i > 1; i -= 2)
1698 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1700 ptr2 = (u_int8_t *)ptr;
1701 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1708 * Allocate a region of memory inside the NIC and zero
1712 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1716 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1717 if_printf(sc->an_ifp, "failed to allocate %d bytes on NIC\n",
1722 for (i = 0; i < AN_TIMEOUT; i++) {
1723 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1727 if (i == AN_TIMEOUT)
1730 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1731 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1733 if (an_seek(sc, *id, 0, AN_BAP0))
1736 for (i = 0; i < len / 2; i++)
1737 CSR_WRITE_2(sc, AN_DATA0, 0);
1743 an_setdef(struct an_softc *sc, struct an_req *areq)
1746 struct an_ltv_genconfig *cfg;
1747 struct an_ltv_ssidlist_new *ssid;
1748 struct an_ltv_aplist *ap;
1749 struct an_ltv_gen *sp;
1754 switch (areq->an_type) {
1755 case AN_RID_GENCONFIG:
1756 cfg = (struct an_ltv_genconfig *)areq;
1758 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(sc->an_ifp),
1761 bcopy((char *)cfg, (char *)&sc->an_config,
1762 sizeof(struct an_ltv_genconfig));
1764 case AN_RID_SSIDLIST:
1765 ssid = (struct an_ltv_ssidlist_new *)areq;
1766 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1767 sizeof(struct an_ltv_ssidlist_new));
1770 ap = (struct an_ltv_aplist *)areq;
1771 bcopy((char *)ap, (char *)&sc->an_aplist,
1772 sizeof(struct an_ltv_aplist));
1774 case AN_RID_TX_SPEED:
1775 sp = (struct an_ltv_gen *)areq;
1776 sc->an_tx_rate = sp->an_val;
1778 /* Read the current configuration */
1779 sc->an_config.an_type = AN_RID_GENCONFIG;
1780 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1781 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1782 cfg = &sc->an_config;
1784 /* clear other rates and set the only one we want */
1785 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1786 cfg->an_rates[0] = sc->an_tx_rate;
1788 /* Save the new rate */
1789 sc->an_config.an_type = AN_RID_GENCONFIG;
1790 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1792 case AN_RID_WEP_TEMP:
1793 /* Cache the temp keys */
1795 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1796 sizeof(struct an_ltv_key));
1797 case AN_RID_WEP_PERM:
1798 case AN_RID_LEAPUSERNAME:
1799 case AN_RID_LEAPPASSWORD:
1802 /* Disable the MAC. */
1803 an_cmd(sc, AN_CMD_DISABLE, 0);
1806 an_write_record(sc, (struct an_ltv_gen *)areq);
1808 /* Turn the MAC back on. */
1809 an_cmd(sc, AN_CMD_ENABLE, 0);
1812 case AN_RID_MONITOR_MODE:
1813 cfg = (struct an_ltv_genconfig *)areq;
1815 if (ng_ether_detach_p != NULL)
1816 (*ng_ether_detach_p) (ifp);
1817 sc->an_monitor = cfg->an_len;
1819 if (sc->an_monitor & AN_MONITOR) {
1820 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1821 bpfattach(ifp, DLT_AIRONET_HEADER,
1822 sizeof(struct ether_header));
1824 bpfattach(ifp, DLT_IEEE802_11,
1825 sizeof(struct ether_header));
1828 bpfattach(ifp, DLT_EN10MB,
1829 sizeof(struct ether_header));
1830 if (ng_ether_attach_p != NULL)
1831 (*ng_ether_attach_p) (ifp);
1835 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1840 /* Reinitialize the card. */
1848 * Derived from Linux driver to enable promiscious mode.
1852 an_promisc(struct an_softc *sc, int promisc)
1855 if (sc->an_was_monitor) {
1858 an_init_mpi350_desc(sc);
1860 if (sc->an_monitor || sc->an_was_monitor)
1863 sc->an_was_monitor = sc->an_monitor;
1864 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1870 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1875 struct an_softc *sc;
1877 struct thread *td = curthread;
1878 struct ieee80211req *ireq;
1879 struct ieee80211_channel ch;
1880 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1882 struct an_ltv_genconfig *config;
1883 struct an_ltv_key *key;
1884 struct an_ltv_status *status;
1885 struct an_ltv_ssidlist_new *ssids;
1887 struct aironet_ioctl l_ioctl;
1890 ifr = (struct ifreq *)data;
1891 ireq = (struct ieee80211req *)data;
1893 config = (struct an_ltv_genconfig *)&sc->areq;
1894 key = (struct an_ltv_key *)&sc->areq;
1895 status = (struct an_ltv_status *)&sc->areq;
1896 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1906 if (ifp->if_flags & IFF_UP) {
1907 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1908 ifp->if_flags & IFF_PROMISC &&
1909 !(sc->an_if_flags & IFF_PROMISC)) {
1911 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1912 !(ifp->if_flags & IFF_PROMISC) &&
1913 sc->an_if_flags & IFF_PROMISC) {
1918 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1921 sc->an_if_flags = ifp->if_flags;
1927 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1931 /* The Aironet has no multicast filter. */
1935 error = copyin(ifr_data_get_ptr(ifr), &sc->areq,
1941 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1942 error = priv_check(td, PRIV_DRIVER);
1945 sc->an_sigitems = sc->an_nextitem = 0;
1947 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1948 char *pt = (char *)&sc->areq.an_val;
1949 bcopy((char *)&sc->an_sigitems, (char *)pt,
1952 sc->areq.an_len = sizeof(int) / 2;
1953 bcopy((char *)&sc->an_sigcache, (char *)pt,
1954 sizeof(struct an_sigcache) * sc->an_sigitems);
1955 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1956 sc->an_sigitems) / 2) + 1;
1959 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1965 error = copyout(&sc->areq, ifr_data_get_ptr(ifr),
1969 if ((error = priv_check(td, PRIV_DRIVER)))
1972 error = copyin(ifr_data_get_ptr(ifr), &sc->areq,
1976 an_setdef(sc, &sc->areq);
1979 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1980 if ((error = priv_check(td, PRIV_DRIVER)))
1982 error = copyin(ifr_data_get_ptr(ifr), &l_ioctl,
1986 mode = l_ioctl.command;
1989 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1990 error = readrids(ifp, &l_ioctl);
1991 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1992 error = writerids(ifp, &l_ioctl);
1993 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1994 error = flashcard(ifp, &l_ioctl);
2000 /* copy out the updated command info */
2001 error = copyout(&l_ioctl, ifr_data_get_ptr(ifr),
2005 case SIOCGPRIVATE_1: /* used by Cisco client utility */
2006 if ((error = priv_check(td, PRIV_DRIVER)))
2008 error = copyin(ifr_data_get_ptr(ifr), &l_ioctl,
2012 l_ioctl.command = 0;
2014 (void) copyout(&error, l_ioctl.data, sizeof(error));
2018 sc->areq.an_len = sizeof(sc->areq);
2019 /* was that a good idea DJA we are doing a short-cut */
2020 switch (ireq->i_type) {
2021 case IEEE80211_IOC_SSID:
2023 if (ireq->i_val == -1) {
2024 sc->areq.an_type = AN_RID_STATUS;
2025 if (an_read_record(sc,
2026 (struct an_ltv_gen *)&sc->areq)) {
2031 len = status->an_ssidlen;
2032 tmpptr = status->an_ssid;
2033 } else if (ireq->i_val >= 0) {
2034 sc->areq.an_type = AN_RID_SSIDLIST;
2035 if (an_read_record(sc,
2036 (struct an_ltv_gen *)&sc->areq)) {
2041 max = (sc->areq.an_len - 4)
2042 / sizeof(struct an_ltv_ssid_entry);
2043 if ( max > MAX_SSIDS ) {
2044 printf("To many SSIDs only using "
2049 if (ireq->i_val > max) {
2054 len = ssids->an_entry[ireq->i_val].an_len;
2055 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2062 if (len > IEEE80211_NWID_LEN) {
2069 bzero(tmpstr, IEEE80211_NWID_LEN);
2070 bcopy(tmpptr, tmpstr, len);
2071 error = copyout(tmpstr, ireq->i_data,
2072 IEEE80211_NWID_LEN);
2074 case IEEE80211_IOC_NUMSSIDS:
2076 sc->areq.an_len = sizeof(sc->areq);
2077 sc->areq.an_type = AN_RID_SSIDLIST;
2078 if (an_read_record(sc,
2079 (struct an_ltv_gen *)&sc->areq)) {
2084 max = (sc->areq.an_len - 4)
2085 / sizeof(struct an_ltv_ssid_entry);
2087 if ( max > MAX_SSIDS ) {
2088 printf("To many SSIDs only using "
2095 case IEEE80211_IOC_WEP:
2097 sc->areq.an_type = AN_RID_ACTUALCFG;
2098 if (an_read_record(sc,
2099 (struct an_ltv_gen *)&sc->areq)) {
2105 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2106 if (config->an_authtype &
2107 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2108 ireq->i_val = IEEE80211_WEP_MIXED;
2110 ireq->i_val = IEEE80211_WEP_ON;
2112 ireq->i_val = IEEE80211_WEP_OFF;
2115 case IEEE80211_IOC_WEPKEY:
2117 * XXX: I'm not entierly convinced this is
2118 * correct, but it's what is implemented in
2119 * ancontrol so it will have to do until we get
2120 * access to actual Cisco code.
2122 if (ireq->i_val < 0 || ireq->i_val > 8) {
2127 if (ireq->i_val < 5) {
2129 sc->areq.an_type = AN_RID_WEP_TEMP;
2130 for (i = 0; i < 5; i++) {
2131 if (an_read_record(sc,
2132 (struct an_ltv_gen *)&sc->areq)) {
2136 if (key->kindex == 0xffff)
2138 if (key->kindex == ireq->i_val)
2140 /* Required to get next entry */
2141 sc->areq.an_type = AN_RID_WEP_PERM;
2148 /* We aren't allowed to read the value of the
2149 * key from the card so we just output zeros
2150 * like we would if we could read the card, but
2151 * denied the user access.
2155 error = copyout(tmpstr, ireq->i_data, len);
2157 case IEEE80211_IOC_NUMWEPKEYS:
2158 ireq->i_val = 9; /* include home key */
2160 case IEEE80211_IOC_WEPTXKEY:
2162 * For some strange reason, you have to read all
2163 * keys before you can read the txkey.
2166 sc->areq.an_type = AN_RID_WEP_TEMP;
2167 for (i = 0; i < 5; i++) {
2168 if (an_read_record(sc,
2169 (struct an_ltv_gen *) &sc->areq)) {
2173 if (key->kindex == 0xffff) {
2176 /* Required to get next entry */
2177 sc->areq.an_type = AN_RID_WEP_PERM;
2184 sc->areq.an_type = AN_RID_WEP_PERM;
2185 key->kindex = 0xffff;
2186 if (an_read_record(sc,
2187 (struct an_ltv_gen *)&sc->areq)) {
2192 ireq->i_val = key->mac[0];
2194 * Check for home mode. Map home mode into
2195 * 5th key since that is how it is stored on
2198 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2199 sc->areq.an_type = AN_RID_GENCONFIG;
2200 if (an_read_record(sc,
2201 (struct an_ltv_gen *)&sc->areq)) {
2206 if (config->an_home_product & AN_HOME_NETWORK)
2210 case IEEE80211_IOC_AUTHMODE:
2212 sc->areq.an_type = AN_RID_ACTUALCFG;
2213 if (an_read_record(sc,
2214 (struct an_ltv_gen *)&sc->areq)) {
2220 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2222 ireq->i_val = IEEE80211_AUTH_NONE;
2223 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2225 ireq->i_val = IEEE80211_AUTH_OPEN;
2226 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2227 AN_AUTHTYPE_SHAREDKEY) {
2228 ireq->i_val = IEEE80211_AUTH_SHARED;
2232 case IEEE80211_IOC_STATIONNAME:
2234 sc->areq.an_type = AN_RID_ACTUALCFG;
2235 if (an_read_record(sc,
2236 (struct an_ltv_gen *)&sc->areq)) {
2242 ireq->i_len = sizeof(config->an_nodename);
2243 tmpptr = config->an_nodename;
2244 bzero(tmpstr, IEEE80211_NWID_LEN);
2245 bcopy(tmpptr, tmpstr, ireq->i_len);
2246 error = copyout(tmpstr, ireq->i_data,
2247 IEEE80211_NWID_LEN);
2249 case IEEE80211_IOC_CHANNEL:
2251 sc->areq.an_type = AN_RID_STATUS;
2252 if (an_read_record(sc,
2253 (struct an_ltv_gen *)&sc->areq)) {
2259 ireq->i_val = status->an_cur_channel;
2261 case IEEE80211_IOC_CURCHAN:
2263 sc->areq.an_type = AN_RID_STATUS;
2264 if (an_read_record(sc,
2265 (struct an_ltv_gen *)&sc->areq)) {
2271 bzero(&ch, sizeof(ch));
2272 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2274 ch.ic_flags = IEEE80211_CHAN_B;
2275 ch.ic_ieee = status->an_cur_channel;
2276 error = copyout(&ch, ireq->i_data, sizeof(ch));
2278 case IEEE80211_IOC_POWERSAVE:
2280 sc->areq.an_type = AN_RID_ACTUALCFG;
2281 if (an_read_record(sc,
2282 (struct an_ltv_gen *)&sc->areq)) {
2288 if (config->an_psave_mode == AN_PSAVE_NONE) {
2289 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2290 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2291 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2292 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2293 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2294 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2295 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2299 case IEEE80211_IOC_POWERSAVESLEEP:
2301 sc->areq.an_type = AN_RID_ACTUALCFG;
2302 if (an_read_record(sc,
2303 (struct an_ltv_gen *)&sc->areq)) {
2309 ireq->i_val = config->an_listen_interval;
2314 if ((error = priv_check(td, PRIV_NET80211_MANAGE)))
2317 sc->areq.an_len = sizeof(sc->areq);
2319 * We need a config structure for everything but the WEP
2320 * key management and SSIDs so we get it now so avoid
2321 * duplicating this code every time.
2323 if (ireq->i_type != IEEE80211_IOC_SSID &&
2324 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2325 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2326 sc->areq.an_type = AN_RID_GENCONFIG;
2327 if (an_read_record(sc,
2328 (struct an_ltv_gen *)&sc->areq)) {
2334 switch (ireq->i_type) {
2335 case IEEE80211_IOC_SSID:
2336 sc->areq.an_len = sizeof(sc->areq);
2337 sc->areq.an_type = AN_RID_SSIDLIST;
2338 if (an_read_record(sc,
2339 (struct an_ltv_gen *)&sc->areq)) {
2344 if (ireq->i_len > IEEE80211_NWID_LEN) {
2349 max = (sc->areq.an_len - 4)
2350 / sizeof(struct an_ltv_ssid_entry);
2351 if ( max > MAX_SSIDS ) {
2352 printf("To many SSIDs only using "
2357 if (ireq->i_val > max) {
2362 error = copyin(ireq->i_data,
2363 ssids->an_entry[ireq->i_val].an_ssid,
2365 ssids->an_entry[ireq->i_val].an_len
2367 sc->areq.an_len = sizeof(sc->areq);
2368 sc->areq.an_type = AN_RID_SSIDLIST;
2369 an_setdef(sc, &sc->areq);
2374 case IEEE80211_IOC_WEP:
2375 switch (ireq->i_val) {
2376 case IEEE80211_WEP_OFF:
2377 config->an_authtype &=
2378 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2379 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2381 case IEEE80211_WEP_ON:
2382 config->an_authtype |=
2383 AN_AUTHTYPE_PRIVACY_IN_USE;
2384 config->an_authtype &=
2385 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2387 case IEEE80211_WEP_MIXED:
2388 config->an_authtype |=
2389 AN_AUTHTYPE_PRIVACY_IN_USE |
2390 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2396 if (error != EINVAL)
2397 an_setdef(sc, &sc->areq);
2400 case IEEE80211_IOC_WEPKEY:
2401 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2407 error = copyin(ireq->i_data, tmpstr, 13);
2413 * Map the 9th key into the home mode
2414 * since that is how it is stored on
2417 bzero(&sc->areq, sizeof(struct an_ltv_key));
2418 sc->areq.an_len = sizeof(struct an_ltv_key);
2419 key->mac[0] = 1; /* The others are 0. */
2420 if (ireq->i_val < 4) {
2421 sc->areq.an_type = AN_RID_WEP_TEMP;
2422 key->kindex = ireq->i_val;
2424 sc->areq.an_type = AN_RID_WEP_PERM;
2425 key->kindex = ireq->i_val - 4;
2427 key->klen = ireq->i_len;
2428 bcopy(tmpstr, key->key, key->klen);
2429 an_setdef(sc, &sc->areq);
2432 case IEEE80211_IOC_WEPTXKEY:
2433 if (ireq->i_val < 0 || ireq->i_val > 4) {
2440 * Map the 5th key into the home mode
2441 * since that is how it is stored on
2444 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2445 sc->areq.an_type = AN_RID_ACTUALCFG;
2446 if (an_read_record(sc,
2447 (struct an_ltv_gen *)&sc->areq)) {
2452 if (ireq->i_val == 4) {
2453 config->an_home_product |= AN_HOME_NETWORK;
2456 config->an_home_product &= ~AN_HOME_NETWORK;
2459 sc->an_config.an_home_product
2460 = config->an_home_product;
2462 /* update configuration */
2465 bzero(&sc->areq, sizeof(struct an_ltv_key));
2466 sc->areq.an_len = sizeof(struct an_ltv_key);
2467 sc->areq.an_type = AN_RID_WEP_PERM;
2468 key->kindex = 0xffff;
2469 key->mac[0] = ireq->i_val;
2470 an_setdef(sc, &sc->areq);
2473 case IEEE80211_IOC_AUTHMODE:
2474 switch (ireq->i_val) {
2475 case IEEE80211_AUTH_NONE:
2476 config->an_authtype = AN_AUTHTYPE_NONE |
2477 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2479 case IEEE80211_AUTH_OPEN:
2480 config->an_authtype = AN_AUTHTYPE_OPEN |
2481 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2483 case IEEE80211_AUTH_SHARED:
2484 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2485 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2490 if (error != EINVAL) {
2491 an_setdef(sc, &sc->areq);
2495 case IEEE80211_IOC_STATIONNAME:
2496 if (ireq->i_len > 16) {
2501 bzero(config->an_nodename, 16);
2502 error = copyin(ireq->i_data,
2503 config->an_nodename, ireq->i_len);
2504 an_setdef(sc, &sc->areq);
2507 case IEEE80211_IOC_CHANNEL:
2509 * The actual range is 1-14, but if you set it
2510 * to 0 you get the default so we let that work
2513 if (ireq->i_val < 0 || ireq->i_val >14) {
2518 config->an_ds_channel = ireq->i_val;
2519 an_setdef(sc, &sc->areq);
2522 case IEEE80211_IOC_POWERSAVE:
2523 switch (ireq->i_val) {
2524 case IEEE80211_POWERSAVE_OFF:
2525 config->an_psave_mode = AN_PSAVE_NONE;
2527 case IEEE80211_POWERSAVE_CAM:
2528 config->an_psave_mode = AN_PSAVE_CAM;
2530 case IEEE80211_POWERSAVE_PSP:
2531 config->an_psave_mode = AN_PSAVE_PSP;
2533 case IEEE80211_POWERSAVE_PSP_CAM:
2534 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2540 an_setdef(sc, &sc->areq);
2543 case IEEE80211_IOC_POWERSAVESLEEP:
2544 config->an_listen_interval = ireq->i_val;
2545 an_setdef(sc, &sc->areq);
2556 an_setdef(sc, &sc->areq);
2562 error = ether_ioctl(ifp, command, data);
2571 an_init_tx_ring(struct an_softc *sc)
2580 for (i = 0; i < AN_TX_RING_CNT; i++) {
2581 if (an_alloc_nicmem(sc, 1518 +
2584 sc->an_rdata.an_tx_fids[i] = id;
2585 sc->an_rdata.an_tx_ring[i] = 0;
2589 sc->an_rdata.an_tx_prod = 0;
2590 sc->an_rdata.an_tx_cons = 0;
2591 sc->an_rdata.an_tx_empty = 1;
2599 struct an_softc *sc = xsc;
2607 an_init_locked(struct an_softc *sc)
2616 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2619 sc->an_associated = 0;
2621 /* Allocate the TX buffers */
2622 if (an_init_tx_ring(sc)) {
2625 an_init_mpi350_desc(sc);
2626 if (an_init_tx_ring(sc)) {
2627 if_printf(ifp, "tx buffer allocation failed\n");
2632 /* Set our MAC address. */
2633 bcopy((char *)IF_LLADDR(sc->an_ifp),
2634 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2636 if (ifp->if_flags & IFF_BROADCAST)
2637 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2639 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2641 if (ifp->if_flags & IFF_MULTICAST)
2642 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2644 if (ifp->if_flags & IFF_PROMISC) {
2645 if (sc->an_monitor & AN_MONITOR) {
2646 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2647 sc->an_config.an_rxmode |=
2648 AN_RXMODE_80211_MONITOR_ANYBSS |
2649 AN_RXMODE_NO_8023_HEADER;
2651 sc->an_config.an_rxmode |=
2652 AN_RXMODE_80211_MONITOR_CURBSS |
2653 AN_RXMODE_NO_8023_HEADER;
2659 if (sc->an_have_rssimap)
2660 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2663 /* Set the ssid list */
2664 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2665 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2666 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2667 if_printf(ifp, "failed to set ssid list\n");
2671 /* Set the AP list */
2672 sc->an_aplist.an_type = AN_RID_APLIST;
2673 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2674 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2675 if_printf(ifp, "failed to set AP list\n");
2679 /* Set the configuration in the NIC */
2680 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2681 sc->an_config.an_type = AN_RID_GENCONFIG;
2682 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2683 if_printf(ifp, "failed to set configuration\n");
2687 /* Enable the MAC */
2688 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2689 if_printf(ifp, "failed to enable MAC\n");
2693 if (ifp->if_flags & IFF_PROMISC)
2694 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2696 /* enable interrupts */
2697 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2699 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2700 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2702 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2708 an_start(struct ifnet *ifp)
2710 struct an_softc *sc;
2714 an_start_locked(ifp);
2719 an_start_locked(struct ifnet *ifp)
2721 struct an_softc *sc;
2722 struct mbuf *m0 = NULL;
2723 struct an_txframe_802_3 tx_frame_802_3;
2724 struct ether_header *eh;
2726 unsigned char txcontrol;
2727 struct an_card_tx_desc an_tx_desc;
2736 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2739 if (!sc->an_associated)
2742 /* We can't send in monitor mode so toss any attempts. */
2743 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2745 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2753 idx = sc->an_rdata.an_tx_prod;
2756 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2758 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2759 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2763 id = sc->an_rdata.an_tx_fids[idx];
2764 eh = mtod(m0, struct ether_header *);
2766 bcopy((char *)&eh->ether_dhost,
2767 (char *)&tx_frame_802_3.an_tx_dst_addr,
2769 bcopy((char *)&eh->ether_shost,
2770 (char *)&tx_frame_802_3.an_tx_src_addr,
2773 /* minus src/dest mac & type */
2774 tx_frame_802_3.an_tx_802_3_payload_len =
2775 m0->m_pkthdr.len - 12;
2777 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2778 tx_frame_802_3.an_tx_802_3_payload_len,
2779 (caddr_t)&sc->an_txbuf);
2781 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2782 /* write the txcontrol only */
2783 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2787 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2788 sizeof(struct an_txframe_802_3));
2790 /* in mbuf header type is just before payload */
2791 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2792 tx_frame_802_3.an_tx_802_3_payload_len);
2795 * If there's a BPF listner, bounce a copy of
2796 * this frame to him.
2803 sc->an_rdata.an_tx_ring[idx] = id;
2804 if (an_cmd(sc, AN_CMD_TX, id))
2805 if_printf(ifp, "xmit failed\n");
2807 AN_INC(idx, AN_TX_RING_CNT);
2810 * Set a timeout in case the chip goes out to lunch.
2814 } else { /* MPI-350 */
2815 /* Disable interrupts. */
2816 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2818 while (sc->an_rdata.an_tx_empty ||
2819 idx != sc->an_rdata.an_tx_cons) {
2820 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2824 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2826 eh = mtod(m0, struct ether_header *);
2828 /* DJA optimize this to limit bcopy */
2829 bcopy((char *)&eh->ether_dhost,
2830 (char *)&tx_frame_802_3.an_tx_dst_addr,
2832 bcopy((char *)&eh->ether_shost,
2833 (char *)&tx_frame_802_3.an_tx_src_addr,
2836 /* minus src/dest mac & type */
2837 tx_frame_802_3.an_tx_802_3_payload_len =
2838 m0->m_pkthdr.len - 12;
2840 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2841 tx_frame_802_3.an_tx_802_3_payload_len,
2842 (caddr_t)&sc->an_txbuf);
2844 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2845 /* write the txcontrol only */
2846 bcopy((caddr_t)&txcontrol, &buf[0x08],
2850 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2851 sizeof(struct an_txframe_802_3));
2853 /* in mbuf header type is just before payload */
2854 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2855 tx_frame_802_3.an_tx_802_3_payload_len);
2858 bzero(&an_tx_desc, sizeof(an_tx_desc));
2859 an_tx_desc.an_offset = 0;
2860 an_tx_desc.an_eoc = 1;
2861 an_tx_desc.an_valid = 1;
2862 an_tx_desc.an_len = 0x44 +
2863 tx_frame_802_3.an_tx_802_3_payload_len;
2865 = sc->an_tx_buffer[idx].an_dma_paddr;
2866 for (i = sizeof(an_tx_desc) / 4 - 1; i >= 0; i--) {
2867 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2869 + (0 * sizeof(an_tx_desc))
2871 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2875 * If there's a BPF listner, bounce a copy of
2876 * this frame to him.
2882 AN_INC(idx, AN_MAX_TX_DESC);
2883 sc->an_rdata.an_tx_empty = 0;
2884 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2887 * Set a timeout in case the chip goes out to lunch.
2892 /* Re-enable interrupts. */
2893 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2897 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2899 sc->an_rdata.an_tx_prod = idx;
2905 an_stop(struct an_softc *sc)
2917 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2918 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2919 an_cmd(sc, AN_CMD_DISABLE, 0);
2921 for (i = 0; i < AN_TX_RING_CNT; i++)
2922 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2924 callout_stop(&sc->an_stat_ch);
2926 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2928 if (sc->an_flash_buffer) {
2929 free(sc->an_flash_buffer, M_DEVBUF);
2930 sc->an_flash_buffer = NULL;
2935 an_watchdog(struct an_softc *sc)
2945 if_printf(ifp, "device timeout\n");
2949 an_init_mpi350_desc(sc);
2952 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2956 an_shutdown(device_t dev)
2958 struct an_softc *sc;
2960 sc = device_get_softc(dev);
2970 an_resume(device_t dev)
2972 struct an_softc *sc;
2976 sc = device_get_softc(dev);
2983 an_init_mpi350_desc(sc);
2986 /* Recovery temporary keys */
2987 for (i = 0; i < 4; i++) {
2988 sc->areq.an_type = AN_RID_WEP_TEMP;
2989 sc->areq.an_len = sizeof(struct an_ltv_key);
2990 bcopy(&sc->an_temp_keys[i],
2991 &sc->areq, sizeof(struct an_ltv_key));
2992 an_setdef(sc, &sc->areq);
2995 if (ifp->if_flags & IFF_UP)
2996 an_start_locked(ifp);
3003 /* Aironet signal strength cache code.
3004 * store signal/noise/quality on per MAC src basis in
3005 * a small fixed cache. The cache wraps if > MAX slots
3006 * used. The cache may be zeroed out to start over.
3007 * Two simple filters exist to reduce computation:
3008 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
3009 * to ignore some packets. It defaults to ip only.
3010 * it could be used to focus on broadcast, non-IP 802.11 beacons.
3011 * 2. multicast/broadcast only. This may be used to
3012 * ignore unicast packets and only cache signal strength
3013 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
3014 * beacons and not unicast traffic.
3016 * The cache stores (MAC src(index), IP src (major clue), signal,
3019 * No apologies for storing IP src here. It's easy and saves much
3020 * trouble elsewhere. The cache is assumed to be INET dependent,
3021 * although it need not be.
3023 * Note: the Aironet only has a single byte of signal strength value
3024 * in the rx frame header, and it's not scaled to anything sensible.
3025 * This is kind of lame, but it's all we've got.
3028 #ifdef documentation
3030 int an_sigitems; /* number of cached entries */
3031 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
3032 int an_nextitem; /* index/# of entries */
3037 /* control variables for cache filtering. Basic idea is
3038 * to reduce cost (e.g., to only Mobile-IP agent beacons
3039 * which are broadcast or multicast). Still you might
3040 * want to measure signal strength anth unicast ping packets
3041 * on a pt. to pt. ant. setup.
3043 /* set true if you want to limit cache items to broadcast/mcast
3044 * only packets (not unicast). Useful for mobile-ip beacons which
3045 * are broadcast/multicast at network layer. Default is all packets
3046 * so ping/unicast anll work say anth pt. to pt. antennae setup.
3048 static int an_cache_mcastonly = 0;
3049 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
3050 &an_cache_mcastonly, 0, "");
3052 /* set true if you want to limit cache items to IP packets only
3054 static int an_cache_iponly = 1;
3055 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
3056 &an_cache_iponly, 0, "");
3059 * an_cache_store, per rx packet store signal
3060 * strength in MAC (src) indexed cache.
3063 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
3064 u_int8_t rx_rssi, u_int8_t rx_quality)
3066 struct ip *ip = NULL;
3068 static int cache_slot = 0; /* use this cache entry */
3069 static int wrapindex = 0; /* next "free" cache entry */
3074 * 2. configurable filter to throw out unicast packets,
3075 * keep multicast only.
3078 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
3082 /* filter for ip packets only
3084 if ( an_cache_iponly && !type_ipv4) {
3088 /* filter for broadcast/multicast only
3090 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3095 if_printf(sc->an_ifp, "q value %x (MSB=0x%x, LSB=0x%x) \n",
3096 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3099 /* find the ip header. we want to store the ip_src
3103 ip = mtod(m, struct ip *);
3106 /* do a linear search for a matching MAC address
3107 * in the cache table
3108 * . MAC address is 6 bytes,
3109 * . var w_nextitem holds total number of entries already cached
3111 for (i = 0; i < sc->an_nextitem; i++) {
3112 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3114 * so we already have this entry,
3121 /* did we find a matching mac address?
3122 * if yes, then overwrite a previously existing cache entry
3124 if (i < sc->an_nextitem ) {
3127 /* else, have a new address entry,so
3128 * add this new entry,
3129 * if table full, then we need to replace LRU entry
3133 /* check for space in cache table
3134 * note: an_nextitem also holds number of entries
3135 * added in the cache table
3137 if ( sc->an_nextitem < MAXANCACHE ) {
3138 cache_slot = sc->an_nextitem;
3140 sc->an_sigitems = sc->an_nextitem;
3142 /* no space found, so simply wrap anth wrap index
3143 * and "zap" the next entry
3146 if (wrapindex == MAXANCACHE) {
3149 cache_slot = wrapindex++;
3153 /* invariant: cache_slot now points at some slot
3156 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3157 log(LOG_ERR, "an_cache_store, bad index: %d of "
3158 "[0..%d], gross cache error\n",
3159 cache_slot, MAXANCACHE);
3163 /* store items in cache
3164 * .ip source address
3169 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3171 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3174 switch (an_cache_mode) {
3176 if (sc->an_have_rssimap) {
3177 sc->an_sigcache[cache_slot].signal =
3178 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3179 sc->an_sigcache[cache_slot].quality =
3180 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3182 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3183 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3187 if (sc->an_have_rssimap) {
3188 sc->an_sigcache[cache_slot].signal =
3189 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3190 sc->an_sigcache[cache_slot].quality =
3191 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3195 if (rx_quality > 100)
3197 sc->an_sigcache[cache_slot].signal = rx_rssi;
3198 sc->an_sigcache[cache_slot].quality = rx_quality;
3202 sc->an_sigcache[cache_slot].signal = rx_rssi;
3203 sc->an_sigcache[cache_slot].quality = rx_quality;
3207 sc->an_sigcache[cache_slot].noise = 0;
3214 an_media_change(struct ifnet *ifp)
3216 struct an_softc *sc = ifp->if_softc;
3217 struct an_ltv_genconfig *cfg;
3218 int otype = sc->an_config.an_opmode;
3219 int orate = sc->an_tx_rate;
3222 sc->an_tx_rate = ieee80211_media2rate(
3223 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3224 if (sc->an_tx_rate < 0)
3227 if (orate != sc->an_tx_rate) {
3228 /* Read the current configuration */
3229 sc->an_config.an_type = AN_RID_GENCONFIG;
3230 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3231 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3232 cfg = &sc->an_config;
3234 /* clear other rates and set the only one we want */
3235 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3236 cfg->an_rates[0] = sc->an_tx_rate;
3238 /* Save the new rate */
3239 sc->an_config.an_type = AN_RID_GENCONFIG;
3240 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3243 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3244 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3246 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3248 if (otype != sc->an_config.an_opmode ||
3249 orate != sc->an_tx_rate)
3257 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3259 struct an_ltv_status status;
3260 struct an_softc *sc = ifp->if_softc;
3262 imr->ifm_active = IFM_IEEE80211;
3265 status.an_len = sizeof(status);
3266 status.an_type = AN_RID_STATUS;
3267 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3268 /* If the status read fails, just lie. */
3269 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3270 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3273 if (sc->an_tx_rate == 0) {
3274 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3277 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3278 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3279 imr->ifm_active |= ieee80211_rate2media(NULL,
3280 status.an_current_tx_rate, IEEE80211_MODE_AUTO);
3281 imr->ifm_status = IFM_AVALID;
3282 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3283 imr->ifm_status |= IFM_ACTIVE;
3287 /********************** Cisco utility support routines *************/
3290 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3295 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3298 struct an_softc *sc;
3301 switch (l_ioctl->command) {
3303 rid = AN_RID_CAPABILITIES;
3306 rid = AN_RID_GENCONFIG;
3309 rid = AN_RID_SSIDLIST;
3312 rid = AN_RID_APLIST;
3315 rid = AN_RID_DRVNAME;
3318 rid = AN_RID_ENCAPPROTO;
3321 rid = AN_RID_WEP_TEMP;
3324 rid = AN_RID_WEP_PERM;
3327 rid = AN_RID_STATUS;
3330 rid = AN_RID_32BITS_DELTA;
3333 rid = AN_RID_32BITS_CUM;
3340 if (rid == 999) /* Is bad command */
3344 sc->areq.an_len = AN_MAX_DATALEN;
3345 sc->areq.an_type = rid;
3347 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3349 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3352 /* the data contains the length at first */
3353 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3354 sizeof(sc->areq.an_len))) {
3358 /* Just copy the data back */
3359 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3371 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3373 struct an_softc *sc;
3374 int rid, command, error;
3379 command = l_ioctl->command;
3383 rid = AN_RID_SSIDLIST;
3386 rid = AN_RID_CAPABILITIES;
3389 rid = AN_RID_APLIST;
3392 rid = AN_RID_GENCONFIG;
3395 an_cmd(sc, AN_CMD_ENABLE, 0);
3399 an_cmd(sc, AN_CMD_DISABLE, 0);
3404 * This command merely clears the counts does not actually
3405 * store any data only reads rid. But as it changes the cards
3406 * state, I put it in the writerid routines.
3409 rid = AN_RID_32BITS_DELTACLR;
3411 sc->areq.an_len = AN_MAX_DATALEN;
3412 sc->areq.an_type = rid;
3414 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3415 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3418 /* the data contains the length at first */
3419 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3420 sizeof(sc->areq.an_len));
3425 /* Just copy the data */
3426 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3434 rid = AN_RID_WEP_TEMP;
3437 rid = AN_RID_WEP_PERM;
3440 rid = AN_RID_LEAPUSERNAME;
3443 rid = AN_RID_LEAPPASSWORD;
3450 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3452 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3453 sc->areq.an_type = rid;
3455 /* Just copy the data back */
3457 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3463 an_cmd(sc, AN_CMD_DISABLE, 0);
3464 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3465 an_cmd(sc, AN_CMD_ENABLE, 0);
3472 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3476 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3477 "flash", ((x) / hz) + 1);
3478 #define FLASH_COMMAND 0x7e7e
3479 #define FLASH_SIZE 32 * 1024
3482 unstickbusy(struct ifnet *ifp)
3484 struct an_softc *sc = ifp->if_softc;
3486 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3487 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3488 AN_EV_CLR_STUCK_BUSY);
3495 * Wait for busy completion from card wait for delay uSec's Return true for
3496 * success meaning command reg is clear
3500 WaitBusy(struct ifnet *ifp, int uSec)
3502 int statword = 0xffff;
3504 struct an_softc *sc = ifp->if_softc;
3506 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3507 FLASH_DELAY(sc, 10);
3509 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3511 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3516 return 0 == (AN_CMD_BUSY & statword);
3520 * STEP 1) Disable MAC and do soft reset on card.
3524 cmdreset(struct ifnet *ifp)
3527 struct an_softc *sc = ifp->if_softc;
3532 an_cmd(sc, AN_CMD_DISABLE, 0);
3534 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3535 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3539 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3541 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3544 if (!(status = WaitBusy(ifp, 100))) {
3545 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3554 * STEP 2) Put the card in legendary flash mode
3558 setflashmode(struct ifnet *ifp)
3561 struct an_softc *sc = ifp->if_softc;
3563 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3564 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3565 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3566 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3569 * mdelay(500); // 500ms delay
3572 FLASH_DELAY(sc, 500);
3574 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3575 printf("Waitbusy hang after setflash mode\n");
3582 * Get a character from the card matching matchbyte Step 3)
3586 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3589 unsigned char rbyte = 0;
3591 struct an_softc *sc = ifp->if_softc;
3595 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3597 if (dwelltime && !(0x8000 & rchar)) {
3599 FLASH_DELAY(sc, 10);
3602 rbyte = 0xff & rchar;
3604 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3605 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3609 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3611 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3613 } while (dwelltime > 0);
3618 * Put character to SWS0 wait for dwelltime x 50us for echo .
3622 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3625 int pollbusy, waittime;
3626 struct an_softc *sc = ifp->if_softc;
3633 waittime = dwelltime;
3636 * Wait for busy bit d15 to go false indicating buffer empty
3639 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3641 if (pollbusy & 0x8000) {
3642 FLASH_DELAY(sc, 50);
3648 while (waittime >= 0);
3650 /* timeout for busy clear wait */
3652 if (waittime <= 0) {
3653 if_printf(ifp, "flash putchar busywait timeout!\n");
3657 * Port is clear now write byte and wait for it to echo back
3660 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3661 FLASH_DELAY(sc, 50);
3663 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3664 } while (dwelltime >= 0 && echo != byte);
3667 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3669 return echo == byte;
3673 * Transfer 32k of firmware data from user buffer to our buffer and send to
3678 flashputbuf(struct ifnet *ifp)
3680 unsigned short *bufp;
3682 struct an_softc *sc = ifp->if_softc;
3686 bufp = sc->an_flash_buffer;
3689 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3690 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3692 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3693 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3696 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3697 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3698 ((u_int32_t *)bufp)[nwords] & 0xffff);
3702 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3708 * After flashing restart the card.
3712 flashrestart(struct ifnet *ifp)
3715 struct an_softc *sc = ifp->if_softc;
3717 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3721 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3726 * Entry point for flash ioclt.
3730 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3733 struct an_softc *sc;
3737 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3740 status = l_ioctl->command;
3742 switch (l_ioctl->command) {
3744 return cmdreset(ifp);
3747 if (sc->an_flash_buffer) {
3748 free(sc->an_flash_buffer, M_DEVBUF);
3749 sc->an_flash_buffer = NULL;
3751 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3752 if (sc->an_flash_buffer)
3753 return setflashmode(ifp);
3757 case AIROFLSHGCHR: /* Get char from aux */
3758 if (l_ioctl->len > sizeof(sc->areq)) {
3762 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3766 z = *(int *)&sc->areq;
3767 if ((status = flashgchar(ifp, z, 8000)) == 1)
3771 case AIROFLSHPCHR: /* Send char to card. */
3772 if (l_ioctl->len > sizeof(sc->areq)) {
3776 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3780 z = *(int *)&sc->areq;
3781 if ((status = flashpchar(ifp, z, 8000)) == -1)
3786 case AIROFLPUTBUF: /* Send 32k to card */
3787 if (l_ioctl->len > FLASH_SIZE) {
3788 if_printf(ifp, "Buffer to big, %x %x\n",
3789 l_ioctl->len, FLASH_SIZE);
3793 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3798 if ((status = flashputbuf(ifp)) != 0)
3804 if ((status = flashrestart(ifp)) != 0) {
3805 if_printf(ifp, "FLASHRESTART returned %d\n", status);