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->ifr_data, &sc->areq, sizeof(sc->areq));
1940 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1941 error = priv_check(td, PRIV_DRIVER);
1944 sc->an_sigitems = sc->an_nextitem = 0;
1946 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1947 char *pt = (char *)&sc->areq.an_val;
1948 bcopy((char *)&sc->an_sigitems, (char *)pt,
1951 sc->areq.an_len = sizeof(int) / 2;
1952 bcopy((char *)&sc->an_sigcache, (char *)pt,
1953 sizeof(struct an_sigcache) * sc->an_sigitems);
1954 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1955 sc->an_sigitems) / 2) + 1;
1958 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1964 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1967 if ((error = priv_check(td, PRIV_DRIVER)))
1970 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1973 an_setdef(sc, &sc->areq);
1976 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1977 if ((error = priv_check(td, PRIV_DRIVER)))
1979 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1982 mode = l_ioctl.command;
1985 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1986 error = readrids(ifp, &l_ioctl);
1987 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1988 error = writerids(ifp, &l_ioctl);
1989 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1990 error = flashcard(ifp, &l_ioctl);
1996 /* copy out the updated command info */
1997 error = copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
2000 case SIOCGPRIVATE_1: /* used by Cisco client utility */
2001 if ((error = priv_check(td, PRIV_DRIVER)))
2003 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2006 l_ioctl.command = 0;
2008 (void) copyout(&error, l_ioctl.data, sizeof(error));
2012 sc->areq.an_len = sizeof(sc->areq);
2013 /* was that a good idea DJA we are doing a short-cut */
2014 switch (ireq->i_type) {
2015 case IEEE80211_IOC_SSID:
2017 if (ireq->i_val == -1) {
2018 sc->areq.an_type = AN_RID_STATUS;
2019 if (an_read_record(sc,
2020 (struct an_ltv_gen *)&sc->areq)) {
2025 len = status->an_ssidlen;
2026 tmpptr = status->an_ssid;
2027 } else if (ireq->i_val >= 0) {
2028 sc->areq.an_type = AN_RID_SSIDLIST;
2029 if (an_read_record(sc,
2030 (struct an_ltv_gen *)&sc->areq)) {
2035 max = (sc->areq.an_len - 4)
2036 / sizeof(struct an_ltv_ssid_entry);
2037 if ( max > MAX_SSIDS ) {
2038 printf("To many SSIDs only using "
2043 if (ireq->i_val > max) {
2048 len = ssids->an_entry[ireq->i_val].an_len;
2049 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2056 if (len > IEEE80211_NWID_LEN) {
2063 bzero(tmpstr, IEEE80211_NWID_LEN);
2064 bcopy(tmpptr, tmpstr, len);
2065 error = copyout(tmpstr, ireq->i_data,
2066 IEEE80211_NWID_LEN);
2068 case IEEE80211_IOC_NUMSSIDS:
2070 sc->areq.an_len = sizeof(sc->areq);
2071 sc->areq.an_type = AN_RID_SSIDLIST;
2072 if (an_read_record(sc,
2073 (struct an_ltv_gen *)&sc->areq)) {
2078 max = (sc->areq.an_len - 4)
2079 / sizeof(struct an_ltv_ssid_entry);
2081 if ( max > MAX_SSIDS ) {
2082 printf("To many SSIDs only using "
2089 case IEEE80211_IOC_WEP:
2091 sc->areq.an_type = AN_RID_ACTUALCFG;
2092 if (an_read_record(sc,
2093 (struct an_ltv_gen *)&sc->areq)) {
2099 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2100 if (config->an_authtype &
2101 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2102 ireq->i_val = IEEE80211_WEP_MIXED;
2104 ireq->i_val = IEEE80211_WEP_ON;
2106 ireq->i_val = IEEE80211_WEP_OFF;
2109 case IEEE80211_IOC_WEPKEY:
2111 * XXX: I'm not entierly convinced this is
2112 * correct, but it's what is implemented in
2113 * ancontrol so it will have to do until we get
2114 * access to actual Cisco code.
2116 if (ireq->i_val < 0 || ireq->i_val > 8) {
2121 if (ireq->i_val < 5) {
2123 sc->areq.an_type = AN_RID_WEP_TEMP;
2124 for (i = 0; i < 5; i++) {
2125 if (an_read_record(sc,
2126 (struct an_ltv_gen *)&sc->areq)) {
2130 if (key->kindex == 0xffff)
2132 if (key->kindex == ireq->i_val)
2134 /* Required to get next entry */
2135 sc->areq.an_type = AN_RID_WEP_PERM;
2142 /* We aren't allowed to read the value of the
2143 * key from the card so we just output zeros
2144 * like we would if we could read the card, but
2145 * denied the user access.
2149 error = copyout(tmpstr, ireq->i_data, len);
2151 case IEEE80211_IOC_NUMWEPKEYS:
2152 ireq->i_val = 9; /* include home key */
2154 case IEEE80211_IOC_WEPTXKEY:
2156 * For some strange reason, you have to read all
2157 * keys before you can read the txkey.
2160 sc->areq.an_type = AN_RID_WEP_TEMP;
2161 for (i = 0; i < 5; i++) {
2162 if (an_read_record(sc,
2163 (struct an_ltv_gen *) &sc->areq)) {
2167 if (key->kindex == 0xffff) {
2170 /* Required to get next entry */
2171 sc->areq.an_type = AN_RID_WEP_PERM;
2178 sc->areq.an_type = AN_RID_WEP_PERM;
2179 key->kindex = 0xffff;
2180 if (an_read_record(sc,
2181 (struct an_ltv_gen *)&sc->areq)) {
2186 ireq->i_val = key->mac[0];
2188 * Check for home mode. Map home mode into
2189 * 5th key since that is how it is stored on
2192 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2193 sc->areq.an_type = AN_RID_GENCONFIG;
2194 if (an_read_record(sc,
2195 (struct an_ltv_gen *)&sc->areq)) {
2200 if (config->an_home_product & AN_HOME_NETWORK)
2204 case IEEE80211_IOC_AUTHMODE:
2206 sc->areq.an_type = AN_RID_ACTUALCFG;
2207 if (an_read_record(sc,
2208 (struct an_ltv_gen *)&sc->areq)) {
2214 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2216 ireq->i_val = IEEE80211_AUTH_NONE;
2217 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2219 ireq->i_val = IEEE80211_AUTH_OPEN;
2220 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2221 AN_AUTHTYPE_SHAREDKEY) {
2222 ireq->i_val = IEEE80211_AUTH_SHARED;
2226 case IEEE80211_IOC_STATIONNAME:
2228 sc->areq.an_type = AN_RID_ACTUALCFG;
2229 if (an_read_record(sc,
2230 (struct an_ltv_gen *)&sc->areq)) {
2236 ireq->i_len = sizeof(config->an_nodename);
2237 tmpptr = config->an_nodename;
2238 bzero(tmpstr, IEEE80211_NWID_LEN);
2239 bcopy(tmpptr, tmpstr, ireq->i_len);
2240 error = copyout(tmpstr, ireq->i_data,
2241 IEEE80211_NWID_LEN);
2243 case IEEE80211_IOC_CHANNEL:
2245 sc->areq.an_type = AN_RID_STATUS;
2246 if (an_read_record(sc,
2247 (struct an_ltv_gen *)&sc->areq)) {
2253 ireq->i_val = status->an_cur_channel;
2255 case IEEE80211_IOC_CURCHAN:
2257 sc->areq.an_type = AN_RID_STATUS;
2258 if (an_read_record(sc,
2259 (struct an_ltv_gen *)&sc->areq)) {
2265 bzero(&ch, sizeof(ch));
2266 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2268 ch.ic_flags = IEEE80211_CHAN_B;
2269 ch.ic_ieee = status->an_cur_channel;
2270 error = copyout(&ch, ireq->i_data, sizeof(ch));
2272 case IEEE80211_IOC_POWERSAVE:
2274 sc->areq.an_type = AN_RID_ACTUALCFG;
2275 if (an_read_record(sc,
2276 (struct an_ltv_gen *)&sc->areq)) {
2282 if (config->an_psave_mode == AN_PSAVE_NONE) {
2283 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2284 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2285 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2286 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2287 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2288 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2289 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2293 case IEEE80211_IOC_POWERSAVESLEEP:
2295 sc->areq.an_type = AN_RID_ACTUALCFG;
2296 if (an_read_record(sc,
2297 (struct an_ltv_gen *)&sc->areq)) {
2303 ireq->i_val = config->an_listen_interval;
2308 if ((error = priv_check(td, PRIV_NET80211_MANAGE)))
2311 sc->areq.an_len = sizeof(sc->areq);
2313 * We need a config structure for everything but the WEP
2314 * key management and SSIDs so we get it now so avoid
2315 * duplicating this code every time.
2317 if (ireq->i_type != IEEE80211_IOC_SSID &&
2318 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2319 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2320 sc->areq.an_type = AN_RID_GENCONFIG;
2321 if (an_read_record(sc,
2322 (struct an_ltv_gen *)&sc->areq)) {
2328 switch (ireq->i_type) {
2329 case IEEE80211_IOC_SSID:
2330 sc->areq.an_len = sizeof(sc->areq);
2331 sc->areq.an_type = AN_RID_SSIDLIST;
2332 if (an_read_record(sc,
2333 (struct an_ltv_gen *)&sc->areq)) {
2338 if (ireq->i_len > IEEE80211_NWID_LEN) {
2343 max = (sc->areq.an_len - 4)
2344 / sizeof(struct an_ltv_ssid_entry);
2345 if ( max > MAX_SSIDS ) {
2346 printf("To many SSIDs only using "
2351 if (ireq->i_val > max) {
2356 error = copyin(ireq->i_data,
2357 ssids->an_entry[ireq->i_val].an_ssid,
2359 ssids->an_entry[ireq->i_val].an_len
2361 sc->areq.an_len = sizeof(sc->areq);
2362 sc->areq.an_type = AN_RID_SSIDLIST;
2363 an_setdef(sc, &sc->areq);
2368 case IEEE80211_IOC_WEP:
2369 switch (ireq->i_val) {
2370 case IEEE80211_WEP_OFF:
2371 config->an_authtype &=
2372 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2373 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2375 case IEEE80211_WEP_ON:
2376 config->an_authtype |=
2377 AN_AUTHTYPE_PRIVACY_IN_USE;
2378 config->an_authtype &=
2379 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2381 case IEEE80211_WEP_MIXED:
2382 config->an_authtype |=
2383 AN_AUTHTYPE_PRIVACY_IN_USE |
2384 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2390 if (error != EINVAL)
2391 an_setdef(sc, &sc->areq);
2394 case IEEE80211_IOC_WEPKEY:
2395 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2401 error = copyin(ireq->i_data, tmpstr, 13);
2407 * Map the 9th key into the home mode
2408 * since that is how it is stored on
2411 bzero(&sc->areq, sizeof(struct an_ltv_key));
2412 sc->areq.an_len = sizeof(struct an_ltv_key);
2413 key->mac[0] = 1; /* The others are 0. */
2414 if (ireq->i_val < 4) {
2415 sc->areq.an_type = AN_RID_WEP_TEMP;
2416 key->kindex = ireq->i_val;
2418 sc->areq.an_type = AN_RID_WEP_PERM;
2419 key->kindex = ireq->i_val - 4;
2421 key->klen = ireq->i_len;
2422 bcopy(tmpstr, key->key, key->klen);
2423 an_setdef(sc, &sc->areq);
2426 case IEEE80211_IOC_WEPTXKEY:
2427 if (ireq->i_val < 0 || ireq->i_val > 4) {
2434 * Map the 5th key into the home mode
2435 * since that is how it is stored on
2438 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2439 sc->areq.an_type = AN_RID_ACTUALCFG;
2440 if (an_read_record(sc,
2441 (struct an_ltv_gen *)&sc->areq)) {
2446 if (ireq->i_val == 4) {
2447 config->an_home_product |= AN_HOME_NETWORK;
2450 config->an_home_product &= ~AN_HOME_NETWORK;
2453 sc->an_config.an_home_product
2454 = config->an_home_product;
2456 /* update configuration */
2459 bzero(&sc->areq, sizeof(struct an_ltv_key));
2460 sc->areq.an_len = sizeof(struct an_ltv_key);
2461 sc->areq.an_type = AN_RID_WEP_PERM;
2462 key->kindex = 0xffff;
2463 key->mac[0] = ireq->i_val;
2464 an_setdef(sc, &sc->areq);
2467 case IEEE80211_IOC_AUTHMODE:
2468 switch (ireq->i_val) {
2469 case IEEE80211_AUTH_NONE:
2470 config->an_authtype = AN_AUTHTYPE_NONE |
2471 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2473 case IEEE80211_AUTH_OPEN:
2474 config->an_authtype = AN_AUTHTYPE_OPEN |
2475 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2477 case IEEE80211_AUTH_SHARED:
2478 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2479 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2484 if (error != EINVAL) {
2485 an_setdef(sc, &sc->areq);
2489 case IEEE80211_IOC_STATIONNAME:
2490 if (ireq->i_len > 16) {
2495 bzero(config->an_nodename, 16);
2496 error = copyin(ireq->i_data,
2497 config->an_nodename, ireq->i_len);
2498 an_setdef(sc, &sc->areq);
2501 case IEEE80211_IOC_CHANNEL:
2503 * The actual range is 1-14, but if you set it
2504 * to 0 you get the default so we let that work
2507 if (ireq->i_val < 0 || ireq->i_val >14) {
2512 config->an_ds_channel = ireq->i_val;
2513 an_setdef(sc, &sc->areq);
2516 case IEEE80211_IOC_POWERSAVE:
2517 switch (ireq->i_val) {
2518 case IEEE80211_POWERSAVE_OFF:
2519 config->an_psave_mode = AN_PSAVE_NONE;
2521 case IEEE80211_POWERSAVE_CAM:
2522 config->an_psave_mode = AN_PSAVE_CAM;
2524 case IEEE80211_POWERSAVE_PSP:
2525 config->an_psave_mode = AN_PSAVE_PSP;
2527 case IEEE80211_POWERSAVE_PSP_CAM:
2528 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2534 an_setdef(sc, &sc->areq);
2537 case IEEE80211_IOC_POWERSAVESLEEP:
2538 config->an_listen_interval = ireq->i_val;
2539 an_setdef(sc, &sc->areq);
2550 an_setdef(sc, &sc->areq);
2556 error = ether_ioctl(ifp, command, data);
2565 an_init_tx_ring(struct an_softc *sc)
2574 for (i = 0; i < AN_TX_RING_CNT; i++) {
2575 if (an_alloc_nicmem(sc, 1518 +
2578 sc->an_rdata.an_tx_fids[i] = id;
2579 sc->an_rdata.an_tx_ring[i] = 0;
2583 sc->an_rdata.an_tx_prod = 0;
2584 sc->an_rdata.an_tx_cons = 0;
2585 sc->an_rdata.an_tx_empty = 1;
2593 struct an_softc *sc = xsc;
2601 an_init_locked(struct an_softc *sc)
2610 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2613 sc->an_associated = 0;
2615 /* Allocate the TX buffers */
2616 if (an_init_tx_ring(sc)) {
2619 an_init_mpi350_desc(sc);
2620 if (an_init_tx_ring(sc)) {
2621 if_printf(ifp, "tx buffer allocation failed\n");
2626 /* Set our MAC address. */
2627 bcopy((char *)IF_LLADDR(sc->an_ifp),
2628 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2630 if (ifp->if_flags & IFF_BROADCAST)
2631 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2633 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2635 if (ifp->if_flags & IFF_MULTICAST)
2636 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2638 if (ifp->if_flags & IFF_PROMISC) {
2639 if (sc->an_monitor & AN_MONITOR) {
2640 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2641 sc->an_config.an_rxmode |=
2642 AN_RXMODE_80211_MONITOR_ANYBSS |
2643 AN_RXMODE_NO_8023_HEADER;
2645 sc->an_config.an_rxmode |=
2646 AN_RXMODE_80211_MONITOR_CURBSS |
2647 AN_RXMODE_NO_8023_HEADER;
2653 if (sc->an_have_rssimap)
2654 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2657 /* Set the ssid list */
2658 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2659 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2660 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2661 if_printf(ifp, "failed to set ssid list\n");
2665 /* Set the AP list */
2666 sc->an_aplist.an_type = AN_RID_APLIST;
2667 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2668 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2669 if_printf(ifp, "failed to set AP list\n");
2673 /* Set the configuration in the NIC */
2674 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2675 sc->an_config.an_type = AN_RID_GENCONFIG;
2676 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2677 if_printf(ifp, "failed to set configuration\n");
2681 /* Enable the MAC */
2682 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2683 if_printf(ifp, "failed to enable MAC\n");
2687 if (ifp->if_flags & IFF_PROMISC)
2688 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2690 /* enable interrupts */
2691 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2693 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2694 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2696 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2702 an_start(struct ifnet *ifp)
2704 struct an_softc *sc;
2708 an_start_locked(ifp);
2713 an_start_locked(struct ifnet *ifp)
2715 struct an_softc *sc;
2716 struct mbuf *m0 = NULL;
2717 struct an_txframe_802_3 tx_frame_802_3;
2718 struct ether_header *eh;
2720 unsigned char txcontrol;
2721 struct an_card_tx_desc an_tx_desc;
2730 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2733 if (!sc->an_associated)
2736 /* We can't send in monitor mode so toss any attempts. */
2737 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2739 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2747 idx = sc->an_rdata.an_tx_prod;
2750 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2752 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2753 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2757 id = sc->an_rdata.an_tx_fids[idx];
2758 eh = mtod(m0, struct ether_header *);
2760 bcopy((char *)&eh->ether_dhost,
2761 (char *)&tx_frame_802_3.an_tx_dst_addr,
2763 bcopy((char *)&eh->ether_shost,
2764 (char *)&tx_frame_802_3.an_tx_src_addr,
2767 /* minus src/dest mac & type */
2768 tx_frame_802_3.an_tx_802_3_payload_len =
2769 m0->m_pkthdr.len - 12;
2771 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2772 tx_frame_802_3.an_tx_802_3_payload_len,
2773 (caddr_t)&sc->an_txbuf);
2775 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2776 /* write the txcontrol only */
2777 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2781 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2782 sizeof(struct an_txframe_802_3));
2784 /* in mbuf header type is just before payload */
2785 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2786 tx_frame_802_3.an_tx_802_3_payload_len);
2789 * If there's a BPF listner, bounce a copy of
2790 * this frame to him.
2797 sc->an_rdata.an_tx_ring[idx] = id;
2798 if (an_cmd(sc, AN_CMD_TX, id))
2799 if_printf(ifp, "xmit failed\n");
2801 AN_INC(idx, AN_TX_RING_CNT);
2804 * Set a timeout in case the chip goes out to lunch.
2808 } else { /* MPI-350 */
2809 /* Disable interrupts. */
2810 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2812 while (sc->an_rdata.an_tx_empty ||
2813 idx != sc->an_rdata.an_tx_cons) {
2814 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2818 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2820 eh = mtod(m0, struct ether_header *);
2822 /* DJA optimize this to limit bcopy */
2823 bcopy((char *)&eh->ether_dhost,
2824 (char *)&tx_frame_802_3.an_tx_dst_addr,
2826 bcopy((char *)&eh->ether_shost,
2827 (char *)&tx_frame_802_3.an_tx_src_addr,
2830 /* minus src/dest mac & type */
2831 tx_frame_802_3.an_tx_802_3_payload_len =
2832 m0->m_pkthdr.len - 12;
2834 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2835 tx_frame_802_3.an_tx_802_3_payload_len,
2836 (caddr_t)&sc->an_txbuf);
2838 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2839 /* write the txcontrol only */
2840 bcopy((caddr_t)&txcontrol, &buf[0x08],
2844 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2845 sizeof(struct an_txframe_802_3));
2847 /* in mbuf header type is just before payload */
2848 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2849 tx_frame_802_3.an_tx_802_3_payload_len);
2852 bzero(&an_tx_desc, sizeof(an_tx_desc));
2853 an_tx_desc.an_offset = 0;
2854 an_tx_desc.an_eoc = 1;
2855 an_tx_desc.an_valid = 1;
2856 an_tx_desc.an_len = 0x44 +
2857 tx_frame_802_3.an_tx_802_3_payload_len;
2859 = sc->an_tx_buffer[idx].an_dma_paddr;
2860 for (i = sizeof(an_tx_desc) / 4 - 1; i >= 0; i--) {
2861 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2863 + (0 * sizeof(an_tx_desc))
2865 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2869 * If there's a BPF listner, bounce a copy of
2870 * this frame to him.
2876 AN_INC(idx, AN_MAX_TX_DESC);
2877 sc->an_rdata.an_tx_empty = 0;
2878 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2881 * Set a timeout in case the chip goes out to lunch.
2886 /* Re-enable interrupts. */
2887 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2891 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2893 sc->an_rdata.an_tx_prod = idx;
2899 an_stop(struct an_softc *sc)
2911 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2912 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2913 an_cmd(sc, AN_CMD_DISABLE, 0);
2915 for (i = 0; i < AN_TX_RING_CNT; i++)
2916 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2918 callout_stop(&sc->an_stat_ch);
2920 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2922 if (sc->an_flash_buffer) {
2923 free(sc->an_flash_buffer, M_DEVBUF);
2924 sc->an_flash_buffer = NULL;
2929 an_watchdog(struct an_softc *sc)
2939 if_printf(ifp, "device timeout\n");
2943 an_init_mpi350_desc(sc);
2946 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2950 an_shutdown(device_t dev)
2952 struct an_softc *sc;
2954 sc = device_get_softc(dev);
2964 an_resume(device_t dev)
2966 struct an_softc *sc;
2970 sc = device_get_softc(dev);
2977 an_init_mpi350_desc(sc);
2980 /* Recovery temporary keys */
2981 for (i = 0; i < 4; i++) {
2982 sc->areq.an_type = AN_RID_WEP_TEMP;
2983 sc->areq.an_len = sizeof(struct an_ltv_key);
2984 bcopy(&sc->an_temp_keys[i],
2985 &sc->areq, sizeof(struct an_ltv_key));
2986 an_setdef(sc, &sc->areq);
2989 if (ifp->if_flags & IFF_UP)
2990 an_start_locked(ifp);
2997 /* Aironet signal strength cache code.
2998 * store signal/noise/quality on per MAC src basis in
2999 * a small fixed cache. The cache wraps if > MAX slots
3000 * used. The cache may be zeroed out to start over.
3001 * Two simple filters exist to reduce computation:
3002 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
3003 * to ignore some packets. It defaults to ip only.
3004 * it could be used to focus on broadcast, non-IP 802.11 beacons.
3005 * 2. multicast/broadcast only. This may be used to
3006 * ignore unicast packets and only cache signal strength
3007 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
3008 * beacons and not unicast traffic.
3010 * The cache stores (MAC src(index), IP src (major clue), signal,
3013 * No apologies for storing IP src here. It's easy and saves much
3014 * trouble elsewhere. The cache is assumed to be INET dependent,
3015 * although it need not be.
3017 * Note: the Aironet only has a single byte of signal strength value
3018 * in the rx frame header, and it's not scaled to anything sensible.
3019 * This is kind of lame, but it's all we've got.
3022 #ifdef documentation
3024 int an_sigitems; /* number of cached entries */
3025 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
3026 int an_nextitem; /* index/# of entries */
3031 /* control variables for cache filtering. Basic idea is
3032 * to reduce cost (e.g., to only Mobile-IP agent beacons
3033 * which are broadcast or multicast). Still you might
3034 * want to measure signal strength anth unicast ping packets
3035 * on a pt. to pt. ant. setup.
3037 /* set true if you want to limit cache items to broadcast/mcast
3038 * only packets (not unicast). Useful for mobile-ip beacons which
3039 * are broadcast/multicast at network layer. Default is all packets
3040 * so ping/unicast anll work say anth pt. to pt. antennae setup.
3042 static int an_cache_mcastonly = 0;
3043 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
3044 &an_cache_mcastonly, 0, "");
3046 /* set true if you want to limit cache items to IP packets only
3048 static int an_cache_iponly = 1;
3049 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
3050 &an_cache_iponly, 0, "");
3053 * an_cache_store, per rx packet store signal
3054 * strength in MAC (src) indexed cache.
3057 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
3058 u_int8_t rx_rssi, u_int8_t rx_quality)
3060 struct ip *ip = NULL;
3062 static int cache_slot = 0; /* use this cache entry */
3063 static int wrapindex = 0; /* next "free" cache entry */
3068 * 2. configurable filter to throw out unicast packets,
3069 * keep multicast only.
3072 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
3076 /* filter for ip packets only
3078 if ( an_cache_iponly && !type_ipv4) {
3082 /* filter for broadcast/multicast only
3084 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3089 if_printf(sc->an_ifp, "q value %x (MSB=0x%x, LSB=0x%x) \n",
3090 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3093 /* find the ip header. we want to store the ip_src
3097 ip = mtod(m, struct ip *);
3100 /* do a linear search for a matching MAC address
3101 * in the cache table
3102 * . MAC address is 6 bytes,
3103 * . var w_nextitem holds total number of entries already cached
3105 for (i = 0; i < sc->an_nextitem; i++) {
3106 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3108 * so we already have this entry,
3115 /* did we find a matching mac address?
3116 * if yes, then overwrite a previously existing cache entry
3118 if (i < sc->an_nextitem ) {
3121 /* else, have a new address entry,so
3122 * add this new entry,
3123 * if table full, then we need to replace LRU entry
3127 /* check for space in cache table
3128 * note: an_nextitem also holds number of entries
3129 * added in the cache table
3131 if ( sc->an_nextitem < MAXANCACHE ) {
3132 cache_slot = sc->an_nextitem;
3134 sc->an_sigitems = sc->an_nextitem;
3136 /* no space found, so simply wrap anth wrap index
3137 * and "zap" the next entry
3140 if (wrapindex == MAXANCACHE) {
3143 cache_slot = wrapindex++;
3147 /* invariant: cache_slot now points at some slot
3150 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3151 log(LOG_ERR, "an_cache_store, bad index: %d of "
3152 "[0..%d], gross cache error\n",
3153 cache_slot, MAXANCACHE);
3157 /* store items in cache
3158 * .ip source address
3163 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3165 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3168 switch (an_cache_mode) {
3170 if (sc->an_have_rssimap) {
3171 sc->an_sigcache[cache_slot].signal =
3172 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3173 sc->an_sigcache[cache_slot].quality =
3174 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3176 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3177 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3181 if (sc->an_have_rssimap) {
3182 sc->an_sigcache[cache_slot].signal =
3183 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3184 sc->an_sigcache[cache_slot].quality =
3185 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3189 if (rx_quality > 100)
3191 sc->an_sigcache[cache_slot].signal = rx_rssi;
3192 sc->an_sigcache[cache_slot].quality = rx_quality;
3196 sc->an_sigcache[cache_slot].signal = rx_rssi;
3197 sc->an_sigcache[cache_slot].quality = rx_quality;
3201 sc->an_sigcache[cache_slot].noise = 0;
3208 an_media_change(struct ifnet *ifp)
3210 struct an_softc *sc = ifp->if_softc;
3211 struct an_ltv_genconfig *cfg;
3212 int otype = sc->an_config.an_opmode;
3213 int orate = sc->an_tx_rate;
3216 sc->an_tx_rate = ieee80211_media2rate(
3217 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3218 if (sc->an_tx_rate < 0)
3221 if (orate != sc->an_tx_rate) {
3222 /* Read the current configuration */
3223 sc->an_config.an_type = AN_RID_GENCONFIG;
3224 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3225 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3226 cfg = &sc->an_config;
3228 /* clear other rates and set the only one we want */
3229 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3230 cfg->an_rates[0] = sc->an_tx_rate;
3232 /* Save the new rate */
3233 sc->an_config.an_type = AN_RID_GENCONFIG;
3234 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3237 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3238 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3240 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3242 if (otype != sc->an_config.an_opmode ||
3243 orate != sc->an_tx_rate)
3251 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3253 struct an_ltv_status status;
3254 struct an_softc *sc = ifp->if_softc;
3256 imr->ifm_active = IFM_IEEE80211;
3259 status.an_len = sizeof(status);
3260 status.an_type = AN_RID_STATUS;
3261 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3262 /* If the status read fails, just lie. */
3263 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3264 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3267 if (sc->an_tx_rate == 0) {
3268 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3271 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3272 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3273 imr->ifm_active |= ieee80211_rate2media(NULL,
3274 status.an_current_tx_rate, IEEE80211_MODE_AUTO);
3275 imr->ifm_status = IFM_AVALID;
3276 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3277 imr->ifm_status |= IFM_ACTIVE;
3281 /********************** Cisco utility support routines *************/
3284 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3289 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3292 struct an_softc *sc;
3295 switch (l_ioctl->command) {
3297 rid = AN_RID_CAPABILITIES;
3300 rid = AN_RID_GENCONFIG;
3303 rid = AN_RID_SSIDLIST;
3306 rid = AN_RID_APLIST;
3309 rid = AN_RID_DRVNAME;
3312 rid = AN_RID_ENCAPPROTO;
3315 rid = AN_RID_WEP_TEMP;
3318 rid = AN_RID_WEP_PERM;
3321 rid = AN_RID_STATUS;
3324 rid = AN_RID_32BITS_DELTA;
3327 rid = AN_RID_32BITS_CUM;
3334 if (rid == 999) /* Is bad command */
3338 sc->areq.an_len = AN_MAX_DATALEN;
3339 sc->areq.an_type = rid;
3341 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3343 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3346 /* the data contains the length at first */
3347 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3348 sizeof(sc->areq.an_len))) {
3352 /* Just copy the data back */
3353 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3365 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3367 struct an_softc *sc;
3368 int rid, command, error;
3373 command = l_ioctl->command;
3377 rid = AN_RID_SSIDLIST;
3380 rid = AN_RID_CAPABILITIES;
3383 rid = AN_RID_APLIST;
3386 rid = AN_RID_GENCONFIG;
3389 an_cmd(sc, AN_CMD_ENABLE, 0);
3393 an_cmd(sc, AN_CMD_DISABLE, 0);
3398 * This command merely clears the counts does not actually
3399 * store any data only reads rid. But as it changes the cards
3400 * state, I put it in the writerid routines.
3403 rid = AN_RID_32BITS_DELTACLR;
3405 sc->areq.an_len = AN_MAX_DATALEN;
3406 sc->areq.an_type = rid;
3408 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3409 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3412 /* the data contains the length at first */
3413 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3414 sizeof(sc->areq.an_len));
3419 /* Just copy the data */
3420 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3428 rid = AN_RID_WEP_TEMP;
3431 rid = AN_RID_WEP_PERM;
3434 rid = AN_RID_LEAPUSERNAME;
3437 rid = AN_RID_LEAPPASSWORD;
3444 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3446 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3447 sc->areq.an_type = rid;
3449 /* Just copy the data back */
3451 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3457 an_cmd(sc, AN_CMD_DISABLE, 0);
3458 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3459 an_cmd(sc, AN_CMD_ENABLE, 0);
3466 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3470 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3471 "flash", ((x) / hz) + 1);
3472 #define FLASH_COMMAND 0x7e7e
3473 #define FLASH_SIZE 32 * 1024
3476 unstickbusy(struct ifnet *ifp)
3478 struct an_softc *sc = ifp->if_softc;
3480 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3481 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3482 AN_EV_CLR_STUCK_BUSY);
3489 * Wait for busy completion from card wait for delay uSec's Return true for
3490 * success meaning command reg is clear
3494 WaitBusy(struct ifnet *ifp, int uSec)
3496 int statword = 0xffff;
3498 struct an_softc *sc = ifp->if_softc;
3500 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3501 FLASH_DELAY(sc, 10);
3503 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3505 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3510 return 0 == (AN_CMD_BUSY & statword);
3514 * STEP 1) Disable MAC and do soft reset on card.
3518 cmdreset(struct ifnet *ifp)
3521 struct an_softc *sc = ifp->if_softc;
3526 an_cmd(sc, AN_CMD_DISABLE, 0);
3528 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3529 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3533 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3535 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3538 if (!(status = WaitBusy(ifp, 100))) {
3539 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3548 * STEP 2) Put the card in legendary flash mode
3552 setflashmode(struct ifnet *ifp)
3555 struct an_softc *sc = ifp->if_softc;
3557 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3558 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3559 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3560 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3563 * mdelay(500); // 500ms delay
3566 FLASH_DELAY(sc, 500);
3568 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3569 printf("Waitbusy hang after setflash mode\n");
3576 * Get a character from the card matching matchbyte Step 3)
3580 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3583 unsigned char rbyte = 0;
3585 struct an_softc *sc = ifp->if_softc;
3589 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3591 if (dwelltime && !(0x8000 & rchar)) {
3593 FLASH_DELAY(sc, 10);
3596 rbyte = 0xff & rchar;
3598 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3599 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3603 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3605 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3607 } while (dwelltime > 0);
3612 * Put character to SWS0 wait for dwelltime x 50us for echo .
3616 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3619 int pollbusy, waittime;
3620 struct an_softc *sc = ifp->if_softc;
3627 waittime = dwelltime;
3630 * Wait for busy bit d15 to go false indicating buffer empty
3633 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3635 if (pollbusy & 0x8000) {
3636 FLASH_DELAY(sc, 50);
3642 while (waittime >= 0);
3644 /* timeout for busy clear wait */
3646 if (waittime <= 0) {
3647 if_printf(ifp, "flash putchar busywait timeout!\n");
3651 * Port is clear now write byte and wait for it to echo back
3654 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3655 FLASH_DELAY(sc, 50);
3657 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3658 } while (dwelltime >= 0 && echo != byte);
3661 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3663 return echo == byte;
3667 * Transfer 32k of firmware data from user buffer to our buffer and send to
3672 flashputbuf(struct ifnet *ifp)
3674 unsigned short *bufp;
3676 struct an_softc *sc = ifp->if_softc;
3680 bufp = sc->an_flash_buffer;
3683 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3684 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3686 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3687 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3690 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3691 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3692 ((u_int32_t *)bufp)[nwords] & 0xffff);
3696 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3702 * After flashing restart the card.
3706 flashrestart(struct ifnet *ifp)
3709 struct an_softc *sc = ifp->if_softc;
3711 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3715 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3720 * Entry point for flash ioclt.
3724 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3727 struct an_softc *sc;
3731 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3734 status = l_ioctl->command;
3736 switch (l_ioctl->command) {
3738 return cmdreset(ifp);
3741 if (sc->an_flash_buffer) {
3742 free(sc->an_flash_buffer, M_DEVBUF);
3743 sc->an_flash_buffer = NULL;
3745 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3746 if (sc->an_flash_buffer)
3747 return setflashmode(ifp);
3751 case AIROFLSHGCHR: /* Get char from aux */
3752 if (l_ioctl->len > sizeof(sc->areq)) {
3756 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3760 z = *(int *)&sc->areq;
3761 if ((status = flashgchar(ifp, z, 8000)) == 1)
3765 case AIROFLSHPCHR: /* Send char to card. */
3766 if (l_ioctl->len > sizeof(sc->areq)) {
3770 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3774 z = *(int *)&sc->areq;
3775 if ((status = flashpchar(ifp, z, 8000)) == -1)
3780 case AIROFLPUTBUF: /* Send 32k to card */
3781 if (l_ioctl->len > FLASH_SIZE) {
3782 if_printf(ifp, "Buffer to big, %x %x\n",
3783 l_ioctl->len, FLASH_SIZE);
3787 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3792 if ((status = flashputbuf(ifp)) != 0)
3798 if ((status = flashrestart(ifp)) != 0) {
3799 if_printf(ifp, "FLASHRESTART returned %d\n", status);