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_arp.h>
115 #include <net/if_dl.h>
116 #include <net/ethernet.h>
117 #include <net/if_types.h>
118 #include <net/if_media.h>
120 #include <net80211/ieee80211_var.h>
121 #include <net80211/ieee80211_ioctl.h>
124 #include <netinet/in.h>
125 #include <netinet/in_systm.h>
126 #include <netinet/in_var.h>
127 #include <netinet/ip.h>
132 #include <machine/md_var.h>
134 #include <dev/an/if_aironet_ieee.h>
135 #include <dev/an/if_anreg.h>
137 /* These are global because we need them in sys/pci/if_an_p.c. */
138 static void an_reset(struct an_softc *);
139 static int an_init_mpi350_desc(struct an_softc *);
140 static int an_ioctl(struct ifnet *, u_long, caddr_t);
141 static void an_init(void *);
142 static void an_init_locked(struct an_softc *);
143 static int an_init_tx_ring(struct an_softc *);
144 static void an_start(struct ifnet *);
145 static void an_start_locked(struct ifnet *);
146 static void an_watchdog(struct an_softc *);
147 static void an_rxeof(struct an_softc *);
148 static void an_txeof(struct an_softc *, int);
150 static void an_promisc(struct an_softc *, int);
151 static int an_cmd(struct an_softc *, int, int);
152 static int an_cmd_struct(struct an_softc *, struct an_command *,
154 static int an_read_record(struct an_softc *, struct an_ltv_gen *);
155 static int an_write_record(struct an_softc *, struct an_ltv_gen *);
156 static int an_read_data(struct an_softc *, int, int, caddr_t, int);
157 static int an_write_data(struct an_softc *, int, int, caddr_t, int);
158 static int an_seek(struct an_softc *, int, int, int);
159 static int an_alloc_nicmem(struct an_softc *, int, int *);
160 static int an_dma_malloc(struct an_softc *, bus_size_t, struct an_dma_alloc *,
162 static void an_dma_free(struct an_softc *, struct an_dma_alloc *);
163 static void an_dma_malloc_cb(void *, bus_dma_segment_t *, int, int);
164 static void an_stats_update(void *);
165 static void an_setdef(struct an_softc *, struct an_req *);
167 static void an_cache_store(struct an_softc *, struct ether_header *,
168 struct mbuf *, u_int8_t, u_int8_t);
171 /* function definitions for use with the Cisco's Linux configuration
175 static int readrids(struct ifnet*, struct aironet_ioctl*);
176 static int writerids(struct ifnet*, struct aironet_ioctl*);
177 static int flashcard(struct ifnet*, struct aironet_ioctl*);
179 static int cmdreset(struct ifnet *);
180 static int setflashmode(struct ifnet *);
181 static int flashgchar(struct ifnet *,int,int);
182 static int flashpchar(struct ifnet *,int,int);
183 static int flashputbuf(struct ifnet *);
184 static int flashrestart(struct ifnet *);
185 static int WaitBusy(struct ifnet *, int);
186 static int unstickbusy(struct ifnet *);
188 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
191 static int an_media_change (struct ifnet *);
192 static void an_media_status (struct ifnet *, struct ifmediareq *);
194 static int an_dump = 0;
195 static int an_cache_mode = 0;
201 static char an_conf[256];
202 static char an_conf_cache[256];
206 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
208 /* XXX violate ethernet/netgraph callback hooks */
209 extern void (*ng_ether_attach_p)(struct ifnet *ifp);
210 extern void (*ng_ether_detach_p)(struct ifnet *ifp);
213 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
222 strcpy(an_conf, "off");
225 strcpy(an_conf, "type");
228 strcpy(an_conf, "dump");
231 snprintf(an_conf, 5, "%x", an_dump);
235 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
237 if (strncmp(an_conf,"off", 3) == 0) {
240 if (strncmp(an_conf,"dump", 4) == 0) {
243 if (strncmp(an_conf,"type", 4) == 0) {
249 if ((*s >= '0') && (*s <= '9')) {
250 r = r * 16 + (*s - '0');
251 } else if ((*s >= 'a') && (*s <= 'f')) {
252 r = r * 16 + (*s - 'a' + 10);
260 printf("Sysctl changed for Aironet driver\n");
265 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
266 0, sizeof(an_conf), sysctl_an_dump, "A", "");
269 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
273 last = an_cache_mode;
275 switch (an_cache_mode) {
277 strcpy(an_conf_cache, "per");
280 strcpy(an_conf_cache, "raw");
283 strcpy(an_conf_cache, "dbm");
287 error = sysctl_handle_string(oidp, an_conf_cache,
288 sizeof(an_conf_cache), req);
290 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
293 if (strncmp(an_conf_cache,"per", 3) == 0) {
296 if (strncmp(an_conf_cache,"raw", 3) == 0) {
303 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
304 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
307 * Setup the lock for PCI attachment since it skips the an_probe
308 * function. We need to setup the lock in an_probe since some
309 * operations need the lock. So we might as well create the
313 an_pci_probe(device_t dev)
315 struct an_softc *sc = device_get_softc(dev);
317 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
324 * We probe for an Aironet 4500/4800 card by attempting to
325 * read the default SSID list. On reset, the first entry in
326 * the SSID list will contain the name "tsunami." If we don't
327 * find this, then there's no card present.
330 an_probe(device_t dev)
332 struct an_softc *sc = device_get_softc(dev);
333 struct an_ltv_ssidlist_new ssid;
336 bzero((char *)&ssid, sizeof(ssid));
338 error = an_alloc_port(dev, 0, AN_IOSIZ);
342 /* can't do autoprobing */
343 if (rman_get_start(sc->port_res) == -1)
347 * We need to fake up a softc structure long enough
348 * to be able to issue commands and call some of the
351 ssid.an_len = sizeof(ssid);
352 ssid.an_type = AN_RID_SSIDLIST;
354 /* Make sure interrupts are disabled. */
356 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
357 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
359 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
364 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
369 if (an_read_record(sc, (struct an_ltv_gen *)&ssid)) {
374 /* See if the ssid matches what we expect ... but doesn't have to */
375 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID)) {
383 mtx_destroy(&sc->an_mtx);
388 * Allocate a port resource with the given resource id.
391 an_alloc_port(device_t dev, int rid, int size)
393 struct an_softc *sc = device_get_softc(dev);
394 struct resource *res;
396 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
397 0ul, ~0ul, size, RF_ACTIVE);
408 * Allocate a memory resource with the given resource id.
410 int an_alloc_memory(device_t dev, int rid, int size)
412 struct an_softc *sc = device_get_softc(dev);
413 struct resource *res;
415 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
416 0ul, ~0ul, size, RF_ACTIVE);
428 * Allocate a auxilary memory resource with the given resource id.
430 int an_alloc_aux_memory(device_t dev, int rid, int size)
432 struct an_softc *sc = device_get_softc(dev);
433 struct resource *res;
435 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
436 0ul, ~0ul, size, RF_ACTIVE);
438 sc->mem_aux_rid = rid;
439 sc->mem_aux_res = res;
440 sc->mem_aux_used = size;
448 * Allocate an irq resource with the given resource id.
451 an_alloc_irq(device_t dev, int rid, int flags)
453 struct an_softc *sc = device_get_softc(dev);
454 struct resource *res;
456 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
457 (RF_ACTIVE | flags));
468 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
470 bus_addr_t *paddr = (bus_addr_t*) arg;
471 *paddr = segs->ds_addr;
475 * Alloc DMA memory and set the pointer to it
478 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
483 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
487 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
488 BUS_DMA_NOWAIT, &dma->an_dma_map);
492 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
496 mapflags | BUS_DMA_NOWAIT);
500 dma->an_dma_size = size;
504 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
506 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
508 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
509 dma->an_dma_map = NULL;
514 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
516 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
517 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
518 dma->an_dma_vaddr = 0;
519 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
523 * Release all resources
526 an_release_resources(device_t dev)
528 struct an_softc *sc = device_get_softc(dev);
532 bus_release_resource(dev, SYS_RES_IOPORT,
533 sc->port_rid, sc->port_res);
537 bus_release_resource(dev, SYS_RES_MEMORY,
538 sc->mem_rid, sc->mem_res);
541 if (sc->mem_aux_res) {
542 bus_release_resource(dev, SYS_RES_MEMORY,
543 sc->mem_aux_rid, sc->mem_aux_res);
547 bus_release_resource(dev, SYS_RES_IRQ,
548 sc->irq_rid, sc->irq_res);
551 if (sc->an_rid_buffer.an_dma_paddr) {
552 an_dma_free(sc, &sc->an_rid_buffer);
554 for (i = 0; i < AN_MAX_RX_DESC; i++)
555 if (sc->an_rx_buffer[i].an_dma_paddr) {
556 an_dma_free(sc, &sc->an_rx_buffer[i]);
558 for (i = 0; i < AN_MAX_TX_DESC; i++)
559 if (sc->an_tx_buffer[i].an_dma_paddr) {
560 an_dma_free(sc, &sc->an_tx_buffer[i]);
563 bus_dma_tag_destroy(sc->an_dtag);
569 an_init_mpi350_desc(struct an_softc *sc)
571 struct an_command cmd_struct;
572 struct an_reply reply;
573 struct an_card_rid_desc an_rid_desc;
574 struct an_card_rx_desc an_rx_desc;
575 struct an_card_tx_desc an_tx_desc;
579 if(!sc->an_rid_buffer.an_dma_paddr)
580 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
581 &sc->an_rid_buffer, 0);
582 for (i = 0; i < AN_MAX_RX_DESC; i++)
583 if(!sc->an_rx_buffer[i].an_dma_paddr)
584 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
585 &sc->an_rx_buffer[i], 0);
586 for (i = 0; i < AN_MAX_TX_DESC; i++)
587 if(!sc->an_tx_buffer[i].an_dma_paddr)
588 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
589 &sc->an_tx_buffer[i], 0);
592 * Allocate RX descriptor
594 bzero(&reply,sizeof(reply));
595 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
596 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
597 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
598 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
599 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
600 if_printf(sc->an_ifp, "failed to allocate RX descriptor\n");
604 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
605 bzero(&an_rx_desc, sizeof(an_rx_desc));
606 an_rx_desc.an_valid = 1;
607 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
608 an_rx_desc.an_done = 0;
609 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
611 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
612 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
613 + (desc * sizeof(an_rx_desc))
615 ((u_int32_t *)(void *)&an_rx_desc)[i]);
619 * Allocate TX descriptor
622 bzero(&reply,sizeof(reply));
623 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
624 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
625 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
626 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
627 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
628 if_printf(sc->an_ifp, "failed to allocate TX descriptor\n");
632 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
633 bzero(&an_tx_desc, sizeof(an_tx_desc));
634 an_tx_desc.an_offset = 0;
635 an_tx_desc.an_eoc = 0;
636 an_tx_desc.an_valid = 0;
637 an_tx_desc.an_len = 0;
638 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
640 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
641 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
642 + (desc * sizeof(an_tx_desc))
644 ((u_int32_t *)(void *)&an_tx_desc)[i]);
648 * Allocate RID descriptor
651 bzero(&reply,sizeof(reply));
652 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
653 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
654 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
655 cmd_struct.an_parm2 = 1;
656 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
657 if_printf(sc->an_ifp, "failed to allocate host descriptor\n");
661 bzero(&an_rid_desc, sizeof(an_rid_desc));
662 an_rid_desc.an_valid = 1;
663 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
664 an_rid_desc.an_rid = 0;
665 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
667 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
668 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
669 ((u_int32_t *)(void *)&an_rid_desc)[i]);
675 an_attach(struct an_softc *sc, int flags)
682 ifp = sc->an_ifp = if_alloc(IFT_ETHER);
684 device_printf(sc->an_dev, "can not if_alloc()\n");
689 sc->an_associated = 0;
691 sc->an_was_monitor = 0;
692 sc->an_flash_buffer = NULL;
698 error = an_init_mpi350_desc(sc);
703 /* Load factory config */
704 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
705 device_printf(sc->an_dev, "failed to load config data\n");
709 /* Read the current configuration */
710 sc->an_config.an_type = AN_RID_GENCONFIG;
711 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
712 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
713 device_printf(sc->an_dev, "read record failed\n");
717 /* Read the card capabilities */
718 sc->an_caps.an_type = AN_RID_CAPABILITIES;
719 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
720 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
721 device_printf(sc->an_dev, "read record failed\n");
726 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
727 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
728 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
729 device_printf(sc->an_dev, "read record failed\n");
734 sc->an_aplist.an_type = AN_RID_APLIST;
735 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
736 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
737 device_printf(sc->an_dev, "read record failed\n");
742 /* Read the RSSI <-> dBm map */
743 sc->an_have_rssimap = 0;
744 if (sc->an_caps.an_softcaps & 8) {
745 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
746 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
747 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
748 device_printf(sc->an_dev,
749 "unable to get RSSI <-> dBM map\n");
751 device_printf(sc->an_dev, "got RSSI <-> dBM map\n");
752 sc->an_have_rssimap = 1;
755 device_printf(sc->an_dev, "no RSSI <-> dBM map\n");
761 if_initname(ifp, device_get_name(sc->an_dev),
762 device_get_unit(sc->an_dev));
763 ifp->if_mtu = ETHERMTU;
764 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
765 ifp->if_ioctl = an_ioctl;
766 ifp->if_start = an_start;
767 ifp->if_init = an_init;
768 ifp->if_baudrate = 10000000;
769 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
770 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
771 IFQ_SET_READY(&ifp->if_snd);
773 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
774 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
775 sizeof(AN_DEFAULT_NODENAME) - 1);
777 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
778 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
779 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
780 sizeof(AN_DEFAULT_NETNAME) - 1);
781 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
783 sc->an_config.an_opmode =
784 AN_OPMODE_INFRASTRUCTURE_STATION;
787 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
791 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
792 if_printf(ifp, "supported rates: ");
793 #define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
794 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
796 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
797 for (i = 0; i < nrate; i++) {
798 r = sc->an_caps.an_rates[i];
799 mword = ieee80211_rate2media(NULL, r, IEEE80211_T_DS);
802 printf("%s%d%sMbps", (i != 0 ? " " : ""),
803 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
805 ADD(mword, IFM_IEEE80211_ADHOC);
808 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
813 * Call MI attach routine.
816 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
817 callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0);
822 mtx_destroy(&sc->an_mtx);
829 an_detach(device_t dev)
831 struct an_softc *sc = device_get_softc(dev);
832 struct ifnet *ifp = sc->an_ifp;
835 device_printf(dev,"already unloaded\n");
841 ifmedia_removeall(&sc->an_ifmedia);
842 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
845 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
846 callout_drain(&sc->an_stat_ch);
848 an_release_resources(dev);
849 mtx_destroy(&sc->an_mtx);
854 an_rxeof(struct an_softc *sc)
857 struct ether_header *eh;
858 struct ieee80211_frame *ih;
859 struct an_rxframe rx_frame;
860 struct an_rxframe_802_3 rx_frame_802_3;
862 int len, id, error = 0, i, count = 0;
863 int ieee80211_header_len;
866 struct an_card_rx_desc an_rx_desc;
874 id = CSR_READ_2(sc, AN_RX_FID);
876 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
877 /* read raw 802.11 packet */
878 bpf_buf = sc->buf_802_11;
881 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
888 * skip beacon by default since this increases the
892 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
893 (rx_frame.an_frame_ctl &
894 IEEE80211_FC0_SUBTYPE_BEACON)) {
898 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
899 len = rx_frame.an_rx_payload_len
901 /* Check for insane frame length */
902 if (len > sizeof(sc->buf_802_11)) {
903 if_printf(ifp, "oversized packet "
904 "received (%d, %d)\n",
910 bcopy((char *)&rx_frame,
911 bpf_buf, sizeof(rx_frame));
913 error = an_read_data(sc, id, sizeof(rx_frame),
914 (caddr_t)bpf_buf+sizeof(rx_frame),
915 rx_frame.an_rx_payload_len);
917 fc1=rx_frame.an_frame_ctl >> 8;
918 ieee80211_header_len =
919 sizeof(struct ieee80211_frame);
920 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
921 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
922 ieee80211_header_len += ETHER_ADDR_LEN;
925 len = rx_frame.an_rx_payload_len
926 + ieee80211_header_len;
927 /* Check for insane frame length */
928 if (len > sizeof(sc->buf_802_11)) {
929 if_printf(ifp, "oversized packet "
930 "received (%d, %d)\n",
936 ih = (struct ieee80211_frame *)bpf_buf;
938 bcopy((char *)&rx_frame.an_frame_ctl,
939 (char *)ih, ieee80211_header_len);
941 error = an_read_data(sc, id, sizeof(rx_frame) +
943 (caddr_t)ih +ieee80211_header_len,
944 rx_frame.an_rx_payload_len);
946 /* dump raw 802.11 packet to bpf and skip ip stack */
947 BPF_TAP(ifp, bpf_buf, len);
949 MGETHDR(m, M_DONTWAIT, MT_DATA);
954 MCLGET(m, M_DONTWAIT);
955 if (!(m->m_flags & M_EXT)) {
960 m->m_pkthdr.rcvif = ifp;
961 /* Read Ethernet encapsulated packet */
964 /* Read NIC frame header */
965 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
972 /* Read in the 802_3 frame header */
973 if (an_read_data(sc, id, 0x34,
974 (caddr_t)&rx_frame_802_3,
975 sizeof(rx_frame_802_3))) {
980 if (rx_frame_802_3.an_rx_802_3_status != 0) {
985 /* Check for insane frame length */
986 len = rx_frame_802_3.an_rx_802_3_payload_len;
987 if (len > sizeof(sc->buf_802_11)) {
989 if_printf(ifp, "oversized packet "
990 "received (%d, %d)\n",
995 m->m_pkthdr.len = m->m_len =
996 rx_frame_802_3.an_rx_802_3_payload_len + 12;
998 eh = mtod(m, struct ether_header *);
1000 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
1001 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
1002 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
1003 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
1005 /* in mbuf header type is just before payload */
1006 error = an_read_data(sc, id, 0x44,
1007 (caddr_t)&(eh->ether_type),
1008 rx_frame_802_3.an_rx_802_3_payload_len);
1017 /* Receive packet. */
1019 an_cache_store(sc, eh, m,
1020 rx_frame.an_rx_signal_strength,
1024 (*ifp->if_input)(ifp, m);
1028 } else { /* MPI-350 */
1029 for (count = 0; count < AN_MAX_RX_DESC; count++){
1030 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1031 ((u_int32_t *)(void *)&an_rx_desc)[i]
1032 = CSR_MEM_AUX_READ_4(sc,
1034 + (count * sizeof(an_rx_desc))
1037 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1038 buf = sc->an_rx_buffer[count].an_dma_vaddr;
1040 MGETHDR(m, M_DONTWAIT, MT_DATA);
1045 MCLGET(m, M_DONTWAIT);
1046 if (!(m->m_flags & M_EXT)) {
1051 m->m_pkthdr.rcvif = ifp;
1052 /* Read Ethernet encapsulated packet */
1055 * No ANCACHE support since we just get back
1056 * an Ethernet packet no 802.11 info
1060 /* Read NIC frame header */
1061 bcopy(buf, (caddr_t)&rx_frame,
1065 /* Check for insane frame length */
1066 len = an_rx_desc.an_len + 12;
1067 if (len > MCLBYTES) {
1069 if_printf(ifp, "oversized packet "
1070 "received (%d, %d)\n",
1076 m->m_pkthdr.len = m->m_len =
1077 an_rx_desc.an_len + 12;
1079 eh = mtod(m, struct ether_header *);
1081 bcopy(buf, (char *)eh,
1086 /* Receive packet. */
1089 an_cache_store(sc, eh, m,
1090 rx_frame.an_rx_signal_strength,
1095 (*ifp->if_input)(ifp, m);
1098 an_rx_desc.an_valid = 1;
1099 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1100 an_rx_desc.an_done = 0;
1101 an_rx_desc.an_phys =
1102 sc->an_rx_buffer[count].an_dma_paddr;
1104 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1105 CSR_MEM_AUX_WRITE_4(sc,
1107 + (count * sizeof(an_rx_desc))
1109 ((u_int32_t *)(void *)&an_rx_desc)[i]);
1112 if_printf(ifp, "Didn't get valid RX packet "
1115 an_rx_desc.an_valid, an_rx_desc.an_len);
1122 an_txeof(struct an_softc *sc, int status)
1131 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1134 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1136 if (status & AN_EV_TX_EXC) {
1141 for (i = 0; i < AN_TX_RING_CNT; i++) {
1142 if (id == sc->an_rdata.an_tx_ring[i]) {
1143 sc->an_rdata.an_tx_ring[i] = 0;
1148 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1149 } else { /* MPI 350 */
1150 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1151 if (!sc->an_rdata.an_tx_empty){
1152 if (status & AN_EV_TX_EXC) {
1156 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1157 if (sc->an_rdata.an_tx_prod ==
1158 sc->an_rdata.an_tx_cons)
1159 sc->an_rdata.an_tx_empty = 1;
1167 * We abuse the stats updater to check the current NIC status. This
1168 * is important because we don't want to allow transmissions until
1169 * the NIC has synchronized to the current cell (either as the master
1170 * in an ad-hoc group, or as a station connected to an access point).
1172 * Note that this function will be called via callout(9) with a lock held.
1175 an_stats_update(void *xsc)
1177 struct an_softc *sc;
1183 if (sc->an_timer > 0 && --sc->an_timer == 0)
1186 sc->an_status.an_type = AN_RID_STATUS;
1187 sc->an_status.an_len = sizeof(struct an_ltv_status);
1188 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status))
1191 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1192 sc->an_associated = 1;
1194 sc->an_associated = 0;
1196 /* Don't do this while we're transmitting */
1197 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
1198 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1202 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1203 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1204 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len))
1207 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1215 struct an_softc *sc;
1219 sc = (struct an_softc*)xsc;
1230 /* Disable interrupts. */
1231 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1233 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1234 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1236 if (status & AN_EV_MIC) {
1237 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1240 if (status & AN_EV_LINKSTAT) {
1241 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1242 == AN_LINKSTAT_ASSOCIATED)
1243 sc->an_associated = 1;
1245 sc->an_associated = 0;
1246 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1249 if (status & AN_EV_RX) {
1251 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1254 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1255 an_txeof(sc, status);
1256 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1259 if (status & AN_EV_TX) {
1260 an_txeof(sc, status);
1261 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1264 if (status & AN_EV_TX_EXC) {
1265 an_txeof(sc, status);
1266 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1269 if (status & AN_EV_ALLOC)
1270 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1272 /* Re-enable interrupts. */
1273 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1275 if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1276 an_start_locked(ifp);
1285 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1286 struct an_reply *reply)
1291 for (i = 0; i != AN_TIMEOUT; i++) {
1292 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1298 if( i == AN_TIMEOUT) {
1303 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1304 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1305 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1306 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1308 for (i = 0; i < AN_TIMEOUT; i++) {
1309 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1314 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1315 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1316 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1317 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1319 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1320 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
1321 AN_EV_CLR_STUCK_BUSY);
1323 /* Ack the command */
1324 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1326 if (i == AN_TIMEOUT)
1333 an_cmd(struct an_softc *sc, int cmd, int val)
1338 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1339 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1340 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1341 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1343 for (i = 0; i < AN_TIMEOUT; i++) {
1344 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1347 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1348 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1352 for (i = 0; i < AN_TIMEOUT; i++) {
1353 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1354 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1355 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1356 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1357 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1361 /* Ack the command */
1362 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1364 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1365 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1367 if (i == AN_TIMEOUT)
1374 * This reset sequence may look a little strange, but this is the
1375 * most reliable method I've found to really kick the NIC in the
1376 * head and force it to reboot correctly.
1379 an_reset(struct an_softc *sc)
1385 an_cmd(sc, AN_CMD_ENABLE, 0);
1386 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1387 an_cmd(sc, AN_CMD_NOOP2, 0);
1389 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1390 if_printf(sc->an_ifp, "reset failed\n");
1392 an_cmd(sc, AN_CMD_DISABLE, 0);
1398 * Read an LTV record from the NIC.
1401 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1403 struct an_ltv_gen *an_ltv;
1404 struct an_card_rid_desc an_rid_desc;
1405 struct an_command cmd;
1406 struct an_reply reply;
1413 if (ltv->an_len < 4 || ltv->an_type == 0)
1418 /* Tell the NIC to enter record read mode. */
1419 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1420 if_printf(ifp, "RID access failed\n");
1424 /* Seek to the record. */
1425 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1426 if_printf(ifp, "seek to record failed\n");
1431 * Read the length and record type and make sure they
1432 * match what we expect (this verifies that we have enough
1433 * room to hold all of the returned data).
1434 * Length includes type but not length.
1436 len = CSR_READ_2(sc, AN_DATA1);
1437 if (len > (ltv->an_len - 2)) {
1438 if_printf(ifp, "record length mismatch -- expected %d, "
1439 "got %d for Rid %x\n",
1440 ltv->an_len - 2, len, ltv->an_type);
1441 len = ltv->an_len - 2;
1443 ltv->an_len = len + 2;
1446 /* Now read the data. */
1447 len -= 2; /* skip the type */
1449 for (i = len; i > 1; i -= 2)
1450 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1452 ptr2 = (u_int8_t *)ptr;
1453 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1455 } else { /* MPI-350 */
1456 if (!sc->an_rid_buffer.an_dma_vaddr)
1458 an_rid_desc.an_valid = 1;
1459 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1460 an_rid_desc.an_rid = 0;
1461 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1462 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1464 bzero(&cmd, sizeof(cmd));
1465 bzero(&reply, sizeof(reply));
1466 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1467 cmd.an_parm0 = ltv->an_type;
1469 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1470 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1471 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1473 if (an_cmd_struct(sc, &cmd, &reply)
1474 || reply.an_status & AN_CMD_QUAL_MASK) {
1475 if_printf(ifp, "failed to read RID %x %x %x %x %x, %d\n",
1485 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1486 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1487 an_rid_desc.an_len = an_ltv->an_len;
1490 len = an_rid_desc.an_len;
1491 if (len > (ltv->an_len - 2)) {
1492 if_printf(ifp, "record length mismatch -- expected %d, "
1493 "got %d for Rid %x\n",
1494 ltv->an_len - 2, len, ltv->an_type);
1495 len = ltv->an_len - 2;
1497 ltv->an_len = len + 2;
1499 bcopy(&an_ltv->an_type,
1505 an_dump_record(sc, ltv, "Read");
1511 * Same as read, except we inject data instead of reading it.
1514 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1516 struct an_card_rid_desc an_rid_desc;
1517 struct an_command cmd;
1518 struct an_reply reply;
1525 an_dump_record(sc, ltv, "Write");
1528 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1531 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1535 * Length includes type but not length.
1537 len = ltv->an_len - 2;
1538 CSR_WRITE_2(sc, AN_DATA1, len);
1540 len -= 2; /* skip the type */
1542 for (i = len; i > 1; i -= 2)
1543 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1545 ptr2 = (u_int8_t *)ptr;
1546 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1549 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1554 for (i = 0; i != AN_TIMEOUT; i++) {
1555 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1561 if (i == AN_TIMEOUT) {
1565 an_rid_desc.an_valid = 1;
1566 an_rid_desc.an_len = ltv->an_len - 2;
1567 an_rid_desc.an_rid = ltv->an_type;
1568 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1570 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1571 an_rid_desc.an_len);
1573 bzero(&cmd,sizeof(cmd));
1574 bzero(&reply,sizeof(reply));
1575 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1576 cmd.an_parm0 = ltv->an_type;
1578 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1579 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1580 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1584 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1585 if_printf(sc->an_ifp,
1586 "failed to write RID 1 %x %x %x %x %x, %d\n",
1597 if (reply.an_status & AN_CMD_QUAL_MASK) {
1598 if_printf(sc->an_ifp,
1599 "failed to write RID 2 %x %x %x %x %x, %d\n",
1615 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1623 len = ltv->an_len - 4;
1624 if_printf(sc->an_ifp, "RID %4x, Length %4d, Mode %s\n",
1625 ltv->an_type, ltv->an_len - 4, string);
1627 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1628 if_printf(sc->an_ifp, "\t");
1629 bzero(buf,sizeof(buf));
1631 ptr2 = (u_int8_t *)<v->an_val;
1632 for (i = len; i > 0; i--) {
1633 printf("%02x ", *ptr2);
1640 if (++count == 16) {
1643 if_printf(sc->an_ifp, "\t");
1644 bzero(buf,sizeof(buf));
1647 for (; count != 16; count++) {
1650 printf(" %s\n",buf);
1655 an_seek(struct an_softc *sc, int id, int off, int chan)
1670 if_printf(sc->an_ifp, "invalid data path: %x\n", chan);
1674 CSR_WRITE_2(sc, selreg, id);
1675 CSR_WRITE_2(sc, offreg, off);
1677 for (i = 0; i < AN_TIMEOUT; i++) {
1678 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1682 if (i == AN_TIMEOUT)
1689 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1696 if (an_seek(sc, id, off, AN_BAP1))
1700 ptr = (u_int16_t *)buf;
1701 for (i = len; i > 1; i -= 2)
1702 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1704 ptr2 = (u_int8_t *)ptr;
1705 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1712 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1719 if (an_seek(sc, id, off, AN_BAP0))
1723 ptr = (u_int16_t *)buf;
1724 for (i = len; i > 1; i -= 2)
1725 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1727 ptr2 = (u_int8_t *)ptr;
1728 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1735 * Allocate a region of memory inside the NIC and zero
1739 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1743 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1744 if_printf(sc->an_ifp, "failed to allocate %d bytes on NIC\n",
1749 for (i = 0; i < AN_TIMEOUT; i++) {
1750 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1754 if (i == AN_TIMEOUT)
1757 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1758 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1760 if (an_seek(sc, *id, 0, AN_BAP0))
1763 for (i = 0; i < len / 2; i++)
1764 CSR_WRITE_2(sc, AN_DATA0, 0);
1770 an_setdef(struct an_softc *sc, struct an_req *areq)
1773 struct an_ltv_genconfig *cfg;
1774 struct an_ltv_ssidlist_new *ssid;
1775 struct an_ltv_aplist *ap;
1776 struct an_ltv_gen *sp;
1781 switch (areq->an_type) {
1782 case AN_RID_GENCONFIG:
1783 cfg = (struct an_ltv_genconfig *)areq;
1785 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(sc->an_ifp),
1788 bcopy((char *)cfg, (char *)&sc->an_config,
1789 sizeof(struct an_ltv_genconfig));
1791 case AN_RID_SSIDLIST:
1792 ssid = (struct an_ltv_ssidlist_new *)areq;
1793 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1794 sizeof(struct an_ltv_ssidlist_new));
1797 ap = (struct an_ltv_aplist *)areq;
1798 bcopy((char *)ap, (char *)&sc->an_aplist,
1799 sizeof(struct an_ltv_aplist));
1801 case AN_RID_TX_SPEED:
1802 sp = (struct an_ltv_gen *)areq;
1803 sc->an_tx_rate = sp->an_val;
1805 /* Read the current configuration */
1806 sc->an_config.an_type = AN_RID_GENCONFIG;
1807 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1808 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1809 cfg = &sc->an_config;
1811 /* clear other rates and set the only one we want */
1812 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1813 cfg->an_rates[0] = sc->an_tx_rate;
1815 /* Save the new rate */
1816 sc->an_config.an_type = AN_RID_GENCONFIG;
1817 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1819 case AN_RID_WEP_TEMP:
1820 /* Cache the temp keys */
1822 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1823 sizeof(struct an_ltv_key));
1824 case AN_RID_WEP_PERM:
1825 case AN_RID_LEAPUSERNAME:
1826 case AN_RID_LEAPPASSWORD:
1829 /* Disable the MAC. */
1830 an_cmd(sc, AN_CMD_DISABLE, 0);
1833 an_write_record(sc, (struct an_ltv_gen *)areq);
1835 /* Turn the MAC back on. */
1836 an_cmd(sc, AN_CMD_ENABLE, 0);
1839 case AN_RID_MONITOR_MODE:
1840 cfg = (struct an_ltv_genconfig *)areq;
1842 if (ng_ether_detach_p != NULL)
1843 (*ng_ether_detach_p) (ifp);
1844 sc->an_monitor = cfg->an_len;
1846 if (sc->an_monitor & AN_MONITOR) {
1847 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1848 bpfattach(ifp, DLT_AIRONET_HEADER,
1849 sizeof(struct ether_header));
1851 bpfattach(ifp, DLT_IEEE802_11,
1852 sizeof(struct ether_header));
1855 bpfattach(ifp, DLT_EN10MB,
1856 sizeof(struct ether_header));
1857 if (ng_ether_attach_p != NULL)
1858 (*ng_ether_attach_p) (ifp);
1862 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1867 /* Reinitialize the card. */
1875 * Derived from Linux driver to enable promiscious mode.
1879 an_promisc(struct an_softc *sc, int promisc)
1882 if (sc->an_was_monitor) {
1885 an_init_mpi350_desc(sc);
1887 if (sc->an_monitor || sc->an_was_monitor)
1890 sc->an_was_monitor = sc->an_monitor;
1891 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1897 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1902 struct an_softc *sc;
1904 struct thread *td = curthread;
1905 struct ieee80211req *ireq;
1906 struct ieee80211_channel ch;
1907 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1909 struct an_ltv_genconfig *config;
1910 struct an_ltv_key *key;
1911 struct an_ltv_status *status;
1912 struct an_ltv_ssidlist_new *ssids;
1914 struct aironet_ioctl l_ioctl;
1917 ifr = (struct ifreq *)data;
1918 ireq = (struct ieee80211req *)data;
1920 config = (struct an_ltv_genconfig *)&sc->areq;
1921 key = (struct an_ltv_key *)&sc->areq;
1922 status = (struct an_ltv_status *)&sc->areq;
1923 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1933 if (ifp->if_flags & IFF_UP) {
1934 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1935 ifp->if_flags & IFF_PROMISC &&
1936 !(sc->an_if_flags & IFF_PROMISC)) {
1938 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1939 !(ifp->if_flags & IFF_PROMISC) &&
1940 sc->an_if_flags & IFF_PROMISC) {
1945 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1948 sc->an_if_flags = ifp->if_flags;
1954 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1958 /* The Aironet has no multicast filter. */
1962 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1967 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1968 error = priv_check(td, PRIV_DRIVER);
1971 sc->an_sigitems = sc->an_nextitem = 0;
1973 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1974 char *pt = (char *)&sc->areq.an_val;
1975 bcopy((char *)&sc->an_sigitems, (char *)pt,
1978 sc->areq.an_len = sizeof(int) / 2;
1979 bcopy((char *)&sc->an_sigcache, (char *)pt,
1980 sizeof(struct an_sigcache) * sc->an_sigitems);
1981 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1982 sc->an_sigitems) / 2) + 1;
1985 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1991 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1994 if ((error = priv_check(td, PRIV_DRIVER)))
1997 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
2000 an_setdef(sc, &sc->areq);
2003 case SIOCGPRIVATE_0: /* used by Cisco client utility */
2004 if ((error = priv_check(td, PRIV_DRIVER)))
2006 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2009 mode = l_ioctl.command;
2012 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
2013 error = readrids(ifp, &l_ioctl);
2014 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
2015 error = writerids(ifp, &l_ioctl);
2016 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
2017 error = flashcard(ifp, &l_ioctl);
2023 /* copy out the updated command info */
2024 error = copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
2027 case SIOCGPRIVATE_1: /* used by Cisco client utility */
2028 if ((error = priv_check(td, PRIV_DRIVER)))
2030 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2033 l_ioctl.command = 0;
2035 (void) copyout(&error, l_ioctl.data, sizeof(error));
2039 sc->areq.an_len = sizeof(sc->areq);
2040 /* was that a good idea DJA we are doing a short-cut */
2041 switch (ireq->i_type) {
2042 case IEEE80211_IOC_SSID:
2044 if (ireq->i_val == -1) {
2045 sc->areq.an_type = AN_RID_STATUS;
2046 if (an_read_record(sc,
2047 (struct an_ltv_gen *)&sc->areq)) {
2052 len = status->an_ssidlen;
2053 tmpptr = status->an_ssid;
2054 } else if (ireq->i_val >= 0) {
2055 sc->areq.an_type = AN_RID_SSIDLIST;
2056 if (an_read_record(sc,
2057 (struct an_ltv_gen *)&sc->areq)) {
2062 max = (sc->areq.an_len - 4)
2063 / sizeof(struct an_ltv_ssid_entry);
2064 if ( max > MAX_SSIDS ) {
2065 printf("To many SSIDs only using "
2070 if (ireq->i_val > max) {
2075 len = ssids->an_entry[ireq->i_val].an_len;
2076 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2083 if (len > IEEE80211_NWID_LEN) {
2090 bzero(tmpstr, IEEE80211_NWID_LEN);
2091 bcopy(tmpptr, tmpstr, len);
2092 error = copyout(tmpstr, ireq->i_data,
2093 IEEE80211_NWID_LEN);
2095 case IEEE80211_IOC_NUMSSIDS:
2097 sc->areq.an_len = sizeof(sc->areq);
2098 sc->areq.an_type = AN_RID_SSIDLIST;
2099 if (an_read_record(sc,
2100 (struct an_ltv_gen *)&sc->areq)) {
2105 max = (sc->areq.an_len - 4)
2106 / sizeof(struct an_ltv_ssid_entry);
2108 if ( max > MAX_SSIDS ) {
2109 printf("To many SSIDs only using "
2116 case IEEE80211_IOC_WEP:
2118 sc->areq.an_type = AN_RID_ACTUALCFG;
2119 if (an_read_record(sc,
2120 (struct an_ltv_gen *)&sc->areq)) {
2126 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2127 if (config->an_authtype &
2128 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2129 ireq->i_val = IEEE80211_WEP_MIXED;
2131 ireq->i_val = IEEE80211_WEP_ON;
2133 ireq->i_val = IEEE80211_WEP_OFF;
2136 case IEEE80211_IOC_WEPKEY:
2138 * XXX: I'm not entierly convinced this is
2139 * correct, but it's what is implemented in
2140 * ancontrol so it will have to do until we get
2141 * access to actual Cisco code.
2143 if (ireq->i_val < 0 || ireq->i_val > 8) {
2148 if (ireq->i_val < 5) {
2150 sc->areq.an_type = AN_RID_WEP_TEMP;
2151 for (i = 0; i < 5; i++) {
2152 if (an_read_record(sc,
2153 (struct an_ltv_gen *)&sc->areq)) {
2157 if (key->kindex == 0xffff)
2159 if (key->kindex == ireq->i_val)
2161 /* Required to get next entry */
2162 sc->areq.an_type = AN_RID_WEP_PERM;
2169 /* We aren't allowed to read the value of the
2170 * key from the card so we just output zeros
2171 * like we would if we could read the card, but
2172 * denied the user access.
2176 error = copyout(tmpstr, ireq->i_data, len);
2178 case IEEE80211_IOC_NUMWEPKEYS:
2179 ireq->i_val = 9; /* include home key */
2181 case IEEE80211_IOC_WEPTXKEY:
2183 * For some strange reason, you have to read all
2184 * keys before you can read the txkey.
2187 sc->areq.an_type = AN_RID_WEP_TEMP;
2188 for (i = 0; i < 5; i++) {
2189 if (an_read_record(sc,
2190 (struct an_ltv_gen *) &sc->areq)) {
2194 if (key->kindex == 0xffff) {
2197 /* Required to get next entry */
2198 sc->areq.an_type = AN_RID_WEP_PERM;
2205 sc->areq.an_type = AN_RID_WEP_PERM;
2206 key->kindex = 0xffff;
2207 if (an_read_record(sc,
2208 (struct an_ltv_gen *)&sc->areq)) {
2213 ireq->i_val = key->mac[0];
2215 * Check for home mode. Map home mode into
2216 * 5th key since that is how it is stored on
2219 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2220 sc->areq.an_type = AN_RID_GENCONFIG;
2221 if (an_read_record(sc,
2222 (struct an_ltv_gen *)&sc->areq)) {
2227 if (config->an_home_product & AN_HOME_NETWORK)
2231 case IEEE80211_IOC_AUTHMODE:
2233 sc->areq.an_type = AN_RID_ACTUALCFG;
2234 if (an_read_record(sc,
2235 (struct an_ltv_gen *)&sc->areq)) {
2241 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2243 ireq->i_val = IEEE80211_AUTH_NONE;
2244 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2246 ireq->i_val = IEEE80211_AUTH_OPEN;
2247 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2248 AN_AUTHTYPE_SHAREDKEY) {
2249 ireq->i_val = IEEE80211_AUTH_SHARED;
2253 case IEEE80211_IOC_STATIONNAME:
2255 sc->areq.an_type = AN_RID_ACTUALCFG;
2256 if (an_read_record(sc,
2257 (struct an_ltv_gen *)&sc->areq)) {
2263 ireq->i_len = sizeof(config->an_nodename);
2264 tmpptr = config->an_nodename;
2265 bzero(tmpstr, IEEE80211_NWID_LEN);
2266 bcopy(tmpptr, tmpstr, ireq->i_len);
2267 error = copyout(tmpstr, ireq->i_data,
2268 IEEE80211_NWID_LEN);
2270 case IEEE80211_IOC_CHANNEL:
2272 sc->areq.an_type = AN_RID_STATUS;
2273 if (an_read_record(sc,
2274 (struct an_ltv_gen *)&sc->areq)) {
2280 ireq->i_val = status->an_cur_channel;
2282 case IEEE80211_IOC_CURCHAN:
2284 sc->areq.an_type = AN_RID_STATUS;
2285 if (an_read_record(sc,
2286 (struct an_ltv_gen *)&sc->areq)) {
2292 bzero(&ch, sizeof(ch));
2293 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2295 ch.ic_flags = IEEE80211_CHAN_B;
2296 ch.ic_ieee = status->an_cur_channel;
2297 error = copyout(&ch, ireq->i_data, sizeof(ch));
2299 case IEEE80211_IOC_POWERSAVE:
2301 sc->areq.an_type = AN_RID_ACTUALCFG;
2302 if (an_read_record(sc,
2303 (struct an_ltv_gen *)&sc->areq)) {
2309 if (config->an_psave_mode == AN_PSAVE_NONE) {
2310 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2311 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2312 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2313 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2314 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2315 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2316 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2320 case IEEE80211_IOC_POWERSAVESLEEP:
2322 sc->areq.an_type = AN_RID_ACTUALCFG;
2323 if (an_read_record(sc,
2324 (struct an_ltv_gen *)&sc->areq)) {
2330 ireq->i_val = config->an_listen_interval;
2335 if ((error = priv_check(td, PRIV_NET80211_MANAGE)))
2338 sc->areq.an_len = sizeof(sc->areq);
2340 * We need a config structure for everything but the WEP
2341 * key management and SSIDs so we get it now so avoid
2342 * duplicating this code every time.
2344 if (ireq->i_type != IEEE80211_IOC_SSID &&
2345 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2346 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2347 sc->areq.an_type = AN_RID_GENCONFIG;
2348 if (an_read_record(sc,
2349 (struct an_ltv_gen *)&sc->areq)) {
2355 switch (ireq->i_type) {
2356 case IEEE80211_IOC_SSID:
2357 sc->areq.an_len = sizeof(sc->areq);
2358 sc->areq.an_type = AN_RID_SSIDLIST;
2359 if (an_read_record(sc,
2360 (struct an_ltv_gen *)&sc->areq)) {
2365 if (ireq->i_len > IEEE80211_NWID_LEN) {
2370 max = (sc->areq.an_len - 4)
2371 / sizeof(struct an_ltv_ssid_entry);
2372 if ( max > MAX_SSIDS ) {
2373 printf("To many SSIDs only using "
2378 if (ireq->i_val > max) {
2383 error = copyin(ireq->i_data,
2384 ssids->an_entry[ireq->i_val].an_ssid,
2386 ssids->an_entry[ireq->i_val].an_len
2388 sc->areq.an_len = sizeof(sc->areq);
2389 sc->areq.an_type = AN_RID_SSIDLIST;
2390 an_setdef(sc, &sc->areq);
2395 case IEEE80211_IOC_WEP:
2396 switch (ireq->i_val) {
2397 case IEEE80211_WEP_OFF:
2398 config->an_authtype &=
2399 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2400 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2402 case IEEE80211_WEP_ON:
2403 config->an_authtype |=
2404 AN_AUTHTYPE_PRIVACY_IN_USE;
2405 config->an_authtype &=
2406 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2408 case IEEE80211_WEP_MIXED:
2409 config->an_authtype |=
2410 AN_AUTHTYPE_PRIVACY_IN_USE |
2411 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2417 if (error != EINVAL)
2418 an_setdef(sc, &sc->areq);
2421 case IEEE80211_IOC_WEPKEY:
2422 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2428 error = copyin(ireq->i_data, tmpstr, 13);
2434 * Map the 9th key into the home mode
2435 * since that is how it is stored on
2438 bzero(&sc->areq, sizeof(struct an_ltv_key));
2439 sc->areq.an_len = sizeof(struct an_ltv_key);
2440 key->mac[0] = 1; /* The others are 0. */
2441 if (ireq->i_val < 4) {
2442 sc->areq.an_type = AN_RID_WEP_TEMP;
2443 key->kindex = ireq->i_val;
2445 sc->areq.an_type = AN_RID_WEP_PERM;
2446 key->kindex = ireq->i_val - 4;
2448 key->klen = ireq->i_len;
2449 bcopy(tmpstr, key->key, key->klen);
2450 an_setdef(sc, &sc->areq);
2453 case IEEE80211_IOC_WEPTXKEY:
2454 if (ireq->i_val < 0 || ireq->i_val > 4) {
2461 * Map the 5th key into the home mode
2462 * since that is how it is stored on
2465 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2466 sc->areq.an_type = AN_RID_ACTUALCFG;
2467 if (an_read_record(sc,
2468 (struct an_ltv_gen *)&sc->areq)) {
2473 if (ireq->i_val == 4) {
2474 config->an_home_product |= AN_HOME_NETWORK;
2477 config->an_home_product &= ~AN_HOME_NETWORK;
2480 sc->an_config.an_home_product
2481 = config->an_home_product;
2483 /* update configuration */
2486 bzero(&sc->areq, sizeof(struct an_ltv_key));
2487 sc->areq.an_len = sizeof(struct an_ltv_key);
2488 sc->areq.an_type = AN_RID_WEP_PERM;
2489 key->kindex = 0xffff;
2490 key->mac[0] = ireq->i_val;
2491 an_setdef(sc, &sc->areq);
2494 case IEEE80211_IOC_AUTHMODE:
2495 switch (ireq->i_val) {
2496 case IEEE80211_AUTH_NONE:
2497 config->an_authtype = AN_AUTHTYPE_NONE |
2498 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2500 case IEEE80211_AUTH_OPEN:
2501 config->an_authtype = AN_AUTHTYPE_OPEN |
2502 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2504 case IEEE80211_AUTH_SHARED:
2505 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2506 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2511 if (error != EINVAL) {
2512 an_setdef(sc, &sc->areq);
2516 case IEEE80211_IOC_STATIONNAME:
2517 if (ireq->i_len > 16) {
2522 bzero(config->an_nodename, 16);
2523 error = copyin(ireq->i_data,
2524 config->an_nodename, ireq->i_len);
2525 an_setdef(sc, &sc->areq);
2528 case IEEE80211_IOC_CHANNEL:
2530 * The actual range is 1-14, but if you set it
2531 * to 0 you get the default so we let that work
2534 if (ireq->i_val < 0 || ireq->i_val >14) {
2539 config->an_ds_channel = ireq->i_val;
2540 an_setdef(sc, &sc->areq);
2543 case IEEE80211_IOC_POWERSAVE:
2544 switch (ireq->i_val) {
2545 case IEEE80211_POWERSAVE_OFF:
2546 config->an_psave_mode = AN_PSAVE_NONE;
2548 case IEEE80211_POWERSAVE_CAM:
2549 config->an_psave_mode = AN_PSAVE_CAM;
2551 case IEEE80211_POWERSAVE_PSP:
2552 config->an_psave_mode = AN_PSAVE_PSP;
2554 case IEEE80211_POWERSAVE_PSP_CAM:
2555 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2561 an_setdef(sc, &sc->areq);
2564 case IEEE80211_IOC_POWERSAVESLEEP:
2565 config->an_listen_interval = ireq->i_val;
2566 an_setdef(sc, &sc->areq);
2577 an_setdef(sc, &sc->areq);
2583 error = ether_ioctl(ifp, command, data);
2592 an_init_tx_ring(struct an_softc *sc)
2601 for (i = 0; i < AN_TX_RING_CNT; i++) {
2602 if (an_alloc_nicmem(sc, 1518 +
2605 sc->an_rdata.an_tx_fids[i] = id;
2606 sc->an_rdata.an_tx_ring[i] = 0;
2610 sc->an_rdata.an_tx_prod = 0;
2611 sc->an_rdata.an_tx_cons = 0;
2612 sc->an_rdata.an_tx_empty = 1;
2620 struct an_softc *sc = xsc;
2628 an_init_locked(struct an_softc *sc)
2637 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2640 sc->an_associated = 0;
2642 /* Allocate the TX buffers */
2643 if (an_init_tx_ring(sc)) {
2646 an_init_mpi350_desc(sc);
2647 if (an_init_tx_ring(sc)) {
2648 if_printf(ifp, "tx buffer allocation failed\n");
2653 /* Set our MAC address. */
2654 bcopy((char *)IF_LLADDR(sc->an_ifp),
2655 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2657 if (ifp->if_flags & IFF_BROADCAST)
2658 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2660 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2662 if (ifp->if_flags & IFF_MULTICAST)
2663 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2665 if (ifp->if_flags & IFF_PROMISC) {
2666 if (sc->an_monitor & AN_MONITOR) {
2667 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2668 sc->an_config.an_rxmode |=
2669 AN_RXMODE_80211_MONITOR_ANYBSS |
2670 AN_RXMODE_NO_8023_HEADER;
2672 sc->an_config.an_rxmode |=
2673 AN_RXMODE_80211_MONITOR_CURBSS |
2674 AN_RXMODE_NO_8023_HEADER;
2680 if (sc->an_have_rssimap)
2681 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2684 /* Set the ssid list */
2685 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2686 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2687 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2688 if_printf(ifp, "failed to set ssid list\n");
2692 /* Set the AP list */
2693 sc->an_aplist.an_type = AN_RID_APLIST;
2694 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2695 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2696 if_printf(ifp, "failed to set AP list\n");
2700 /* Set the configuration in the NIC */
2701 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2702 sc->an_config.an_type = AN_RID_GENCONFIG;
2703 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2704 if_printf(ifp, "failed to set configuration\n");
2708 /* Enable the MAC */
2709 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2710 if_printf(ifp, "failed to enable MAC\n");
2714 if (ifp->if_flags & IFF_PROMISC)
2715 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2717 /* enable interrupts */
2718 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2720 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2721 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2723 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2729 an_start(struct ifnet *ifp)
2731 struct an_softc *sc;
2735 an_start_locked(ifp);
2740 an_start_locked(struct ifnet *ifp)
2742 struct an_softc *sc;
2743 struct mbuf *m0 = NULL;
2744 struct an_txframe_802_3 tx_frame_802_3;
2745 struct ether_header *eh;
2747 unsigned char txcontrol;
2748 struct an_card_tx_desc an_tx_desc;
2757 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2760 if (!sc->an_associated)
2763 /* We can't send in monitor mode so toss any attempts. */
2764 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2766 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2774 idx = sc->an_rdata.an_tx_prod;
2777 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2779 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2780 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2784 id = sc->an_rdata.an_tx_fids[idx];
2785 eh = mtod(m0, struct ether_header *);
2787 bcopy((char *)&eh->ether_dhost,
2788 (char *)&tx_frame_802_3.an_tx_dst_addr,
2790 bcopy((char *)&eh->ether_shost,
2791 (char *)&tx_frame_802_3.an_tx_src_addr,
2794 /* minus src/dest mac & type */
2795 tx_frame_802_3.an_tx_802_3_payload_len =
2796 m0->m_pkthdr.len - 12;
2798 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2799 tx_frame_802_3.an_tx_802_3_payload_len,
2800 (caddr_t)&sc->an_txbuf);
2802 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2803 /* write the txcontrol only */
2804 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2808 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2809 sizeof(struct an_txframe_802_3));
2811 /* in mbuf header type is just before payload */
2812 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2813 tx_frame_802_3.an_tx_802_3_payload_len);
2816 * If there's a BPF listner, bounce a copy of
2817 * this frame to him.
2824 sc->an_rdata.an_tx_ring[idx] = id;
2825 if (an_cmd(sc, AN_CMD_TX, id))
2826 if_printf(ifp, "xmit failed\n");
2828 AN_INC(idx, AN_TX_RING_CNT);
2831 * Set a timeout in case the chip goes out to lunch.
2835 } else { /* MPI-350 */
2836 /* Disable interrupts. */
2837 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2839 while (sc->an_rdata.an_tx_empty ||
2840 idx != sc->an_rdata.an_tx_cons) {
2841 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2845 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2847 eh = mtod(m0, struct ether_header *);
2849 /* DJA optimize this to limit bcopy */
2850 bcopy((char *)&eh->ether_dhost,
2851 (char *)&tx_frame_802_3.an_tx_dst_addr,
2853 bcopy((char *)&eh->ether_shost,
2854 (char *)&tx_frame_802_3.an_tx_src_addr,
2857 /* minus src/dest mac & type */
2858 tx_frame_802_3.an_tx_802_3_payload_len =
2859 m0->m_pkthdr.len - 12;
2861 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2862 tx_frame_802_3.an_tx_802_3_payload_len,
2863 (caddr_t)&sc->an_txbuf);
2865 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2866 /* write the txcontrol only */
2867 bcopy((caddr_t)&txcontrol, &buf[0x08],
2871 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2872 sizeof(struct an_txframe_802_3));
2874 /* in mbuf header type is just before payload */
2875 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2876 tx_frame_802_3.an_tx_802_3_payload_len);
2879 bzero(&an_tx_desc, sizeof(an_tx_desc));
2880 an_tx_desc.an_offset = 0;
2881 an_tx_desc.an_eoc = 1;
2882 an_tx_desc.an_valid = 1;
2883 an_tx_desc.an_len = 0x44 +
2884 tx_frame_802_3.an_tx_802_3_payload_len;
2886 = sc->an_tx_buffer[idx].an_dma_paddr;
2887 for (i = sizeof(an_tx_desc) / 4 - 1; i >= 0; i--) {
2888 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2890 + (0 * sizeof(an_tx_desc))
2892 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2896 * If there's a BPF listner, bounce a copy of
2897 * this frame to him.
2903 AN_INC(idx, AN_MAX_TX_DESC);
2904 sc->an_rdata.an_tx_empty = 0;
2905 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2908 * Set a timeout in case the chip goes out to lunch.
2913 /* Re-enable interrupts. */
2914 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2918 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2920 sc->an_rdata.an_tx_prod = idx;
2926 an_stop(struct an_softc *sc)
2938 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2939 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2940 an_cmd(sc, AN_CMD_DISABLE, 0);
2942 for (i = 0; i < AN_TX_RING_CNT; i++)
2943 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2945 callout_stop(&sc->an_stat_ch);
2947 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2949 if (sc->an_flash_buffer) {
2950 free(sc->an_flash_buffer, M_DEVBUF);
2951 sc->an_flash_buffer = NULL;
2956 an_watchdog(struct an_softc *sc)
2966 if_printf(ifp, "device timeout\n");
2970 an_init_mpi350_desc(sc);
2977 an_shutdown(device_t dev)
2979 struct an_softc *sc;
2981 sc = device_get_softc(dev);
2991 an_resume(device_t dev)
2993 struct an_softc *sc;
2997 sc = device_get_softc(dev);
3004 an_init_mpi350_desc(sc);
3007 /* Recovery temporary keys */
3008 for (i = 0; i < 4; i++) {
3009 sc->areq.an_type = AN_RID_WEP_TEMP;
3010 sc->areq.an_len = sizeof(struct an_ltv_key);
3011 bcopy(&sc->an_temp_keys[i],
3012 &sc->areq, sizeof(struct an_ltv_key));
3013 an_setdef(sc, &sc->areq);
3016 if (ifp->if_flags & IFF_UP)
3017 an_start_locked(ifp);
3024 /* Aironet signal strength cache code.
3025 * store signal/noise/quality on per MAC src basis in
3026 * a small fixed cache. The cache wraps if > MAX slots
3027 * used. The cache may be zeroed out to start over.
3028 * Two simple filters exist to reduce computation:
3029 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
3030 * to ignore some packets. It defaults to ip only.
3031 * it could be used to focus on broadcast, non-IP 802.11 beacons.
3032 * 2. multicast/broadcast only. This may be used to
3033 * ignore unicast packets and only cache signal strength
3034 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
3035 * beacons and not unicast traffic.
3037 * The cache stores (MAC src(index), IP src (major clue), signal,
3040 * No apologies for storing IP src here. It's easy and saves much
3041 * trouble elsewhere. The cache is assumed to be INET dependent,
3042 * although it need not be.
3044 * Note: the Aironet only has a single byte of signal strength value
3045 * in the rx frame header, and it's not scaled to anything sensible.
3046 * This is kind of lame, but it's all we've got.
3049 #ifdef documentation
3051 int an_sigitems; /* number of cached entries */
3052 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
3053 int an_nextitem; /* index/# of entries */
3058 /* control variables for cache filtering. Basic idea is
3059 * to reduce cost (e.g., to only Mobile-IP agent beacons
3060 * which are broadcast or multicast). Still you might
3061 * want to measure signal strength anth unicast ping packets
3062 * on a pt. to pt. ant. setup.
3064 /* set true if you want to limit cache items to broadcast/mcast
3065 * only packets (not unicast). Useful for mobile-ip beacons which
3066 * are broadcast/multicast at network layer. Default is all packets
3067 * so ping/unicast anll work say anth pt. to pt. antennae setup.
3069 static int an_cache_mcastonly = 0;
3070 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
3071 &an_cache_mcastonly, 0, "");
3073 /* set true if you want to limit cache items to IP packets only
3075 static int an_cache_iponly = 1;
3076 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
3077 &an_cache_iponly, 0, "");
3080 * an_cache_store, per rx packet store signal
3081 * strength in MAC (src) indexed cache.
3084 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
3085 u_int8_t rx_rssi, u_int8_t rx_quality)
3089 static int cache_slot = 0; /* use this cache entry */
3090 static int wrapindex = 0; /* next "free" cache entry */
3095 * 2. configurable filter to throw out unicast packets,
3096 * keep multicast only.
3099 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
3103 /* filter for ip packets only
3105 if ( an_cache_iponly && !type_ipv4) {
3109 /* filter for broadcast/multicast only
3111 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3116 if_printf(sc->an_ifp, "q value %x (MSB=0x%x, LSB=0x%x) \n",
3117 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3120 /* find the ip header. we want to store the ip_src
3124 ip = mtod(m, struct ip *);
3127 /* do a linear search for a matching MAC address
3128 * in the cache table
3129 * . MAC address is 6 bytes,
3130 * . var w_nextitem holds total number of entries already cached
3132 for (i = 0; i < sc->an_nextitem; i++) {
3133 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3135 * so we already have this entry,
3142 /* did we find a matching mac address?
3143 * if yes, then overwrite a previously existing cache entry
3145 if (i < sc->an_nextitem ) {
3148 /* else, have a new address entry,so
3149 * add this new entry,
3150 * if table full, then we need to replace LRU entry
3154 /* check for space in cache table
3155 * note: an_nextitem also holds number of entries
3156 * added in the cache table
3158 if ( sc->an_nextitem < MAXANCACHE ) {
3159 cache_slot = sc->an_nextitem;
3161 sc->an_sigitems = sc->an_nextitem;
3163 /* no space found, so simply wrap anth wrap index
3164 * and "zap" the next entry
3167 if (wrapindex == MAXANCACHE) {
3170 cache_slot = wrapindex++;
3174 /* invariant: cache_slot now points at some slot
3177 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3178 log(LOG_ERR, "an_cache_store, bad index: %d of "
3179 "[0..%d], gross cache error\n",
3180 cache_slot, MAXANCACHE);
3184 /* store items in cache
3185 * .ip source address
3190 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3192 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3195 switch (an_cache_mode) {
3197 if (sc->an_have_rssimap) {
3198 sc->an_sigcache[cache_slot].signal =
3199 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3200 sc->an_sigcache[cache_slot].quality =
3201 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3203 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3204 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3208 if (sc->an_have_rssimap) {
3209 sc->an_sigcache[cache_slot].signal =
3210 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3211 sc->an_sigcache[cache_slot].quality =
3212 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3216 if (rx_quality > 100)
3218 sc->an_sigcache[cache_slot].signal = rx_rssi;
3219 sc->an_sigcache[cache_slot].quality = rx_quality;
3223 sc->an_sigcache[cache_slot].signal = rx_rssi;
3224 sc->an_sigcache[cache_slot].quality = rx_quality;
3228 sc->an_sigcache[cache_slot].noise = 0;
3235 an_media_change(struct ifnet *ifp)
3237 struct an_softc *sc = ifp->if_softc;
3238 struct an_ltv_genconfig *cfg;
3239 int otype = sc->an_config.an_opmode;
3240 int orate = sc->an_tx_rate;
3243 sc->an_tx_rate = ieee80211_media2rate(
3244 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3245 if (sc->an_tx_rate < 0)
3248 if (orate != sc->an_tx_rate) {
3249 /* Read the current configuration */
3250 sc->an_config.an_type = AN_RID_GENCONFIG;
3251 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3252 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3253 cfg = &sc->an_config;
3255 /* clear other rates and set the only one we want */
3256 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3257 cfg->an_rates[0] = sc->an_tx_rate;
3259 /* Save the new rate */
3260 sc->an_config.an_type = AN_RID_GENCONFIG;
3261 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3264 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3265 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3267 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3269 if (otype != sc->an_config.an_opmode ||
3270 orate != sc->an_tx_rate)
3278 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3280 struct an_ltv_status status;
3281 struct an_softc *sc = ifp->if_softc;
3283 imr->ifm_active = IFM_IEEE80211;
3286 status.an_len = sizeof(status);
3287 status.an_type = AN_RID_STATUS;
3288 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3289 /* If the status read fails, just lie. */
3290 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3291 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3294 if (sc->an_tx_rate == 0) {
3295 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3298 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3299 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3300 imr->ifm_active |= ieee80211_rate2media(NULL,
3301 status.an_current_tx_rate, IEEE80211_T_DS);
3302 imr->ifm_status = IFM_AVALID;
3303 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3304 imr->ifm_status |= IFM_ACTIVE;
3308 /********************** Cisco utility support routines *************/
3311 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3316 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3319 struct an_softc *sc;
3322 switch (l_ioctl->command) {
3324 rid = AN_RID_CAPABILITIES;
3327 rid = AN_RID_GENCONFIG;
3330 rid = AN_RID_SSIDLIST;
3333 rid = AN_RID_APLIST;
3336 rid = AN_RID_DRVNAME;
3339 rid = AN_RID_ENCAPPROTO;
3342 rid = AN_RID_WEP_TEMP;
3345 rid = AN_RID_WEP_PERM;
3348 rid = AN_RID_STATUS;
3351 rid = AN_RID_32BITS_DELTA;
3354 rid = AN_RID_32BITS_CUM;
3361 if (rid == 999) /* Is bad command */
3365 sc->areq.an_len = AN_MAX_DATALEN;
3366 sc->areq.an_type = rid;
3368 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3370 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3373 /* the data contains the length at first */
3374 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3375 sizeof(sc->areq.an_len))) {
3379 /* Just copy the data back */
3380 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3392 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3394 struct an_softc *sc;
3395 int rid, command, error;
3400 command = l_ioctl->command;
3404 rid = AN_RID_SSIDLIST;
3407 rid = AN_RID_CAPABILITIES;
3410 rid = AN_RID_APLIST;
3413 rid = AN_RID_GENCONFIG;
3416 an_cmd(sc, AN_CMD_ENABLE, 0);
3420 an_cmd(sc, AN_CMD_DISABLE, 0);
3425 * This command merely clears the counts does not actually
3426 * store any data only reads rid. But as it changes the cards
3427 * state, I put it in the writerid routines.
3430 rid = AN_RID_32BITS_DELTACLR;
3432 sc->areq.an_len = AN_MAX_DATALEN;
3433 sc->areq.an_type = rid;
3435 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3436 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3439 /* the data contains the length at first */
3440 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3441 sizeof(sc->areq.an_len));
3446 /* Just copy the data */
3447 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3455 rid = AN_RID_WEP_TEMP;
3458 rid = AN_RID_WEP_PERM;
3461 rid = AN_RID_LEAPUSERNAME;
3464 rid = AN_RID_LEAPPASSWORD;
3471 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3473 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3474 sc->areq.an_type = rid;
3476 /* Just copy the data back */
3478 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3484 an_cmd(sc, AN_CMD_DISABLE, 0);
3485 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3486 an_cmd(sc, AN_CMD_ENABLE, 0);
3493 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3497 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3498 "flash", ((x) / hz) + 1);
3499 #define FLASH_COMMAND 0x7e7e
3500 #define FLASH_SIZE 32 * 1024
3503 unstickbusy(struct ifnet *ifp)
3505 struct an_softc *sc = ifp->if_softc;
3507 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3508 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3509 AN_EV_CLR_STUCK_BUSY);
3516 * Wait for busy completion from card wait for delay uSec's Return true for
3517 * success meaning command reg is clear
3521 WaitBusy(struct ifnet *ifp, int uSec)
3523 int statword = 0xffff;
3525 struct an_softc *sc = ifp->if_softc;
3527 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3528 FLASH_DELAY(sc, 10);
3530 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3532 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3537 return 0 == (AN_CMD_BUSY & statword);
3541 * STEP 1) Disable MAC and do soft reset on card.
3545 cmdreset(struct ifnet *ifp)
3548 struct an_softc *sc = ifp->if_softc;
3553 an_cmd(sc, AN_CMD_DISABLE, 0);
3555 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3556 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3560 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3562 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3565 if (!(status = WaitBusy(ifp, 100))) {
3566 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3575 * STEP 2) Put the card in legendary flash mode
3579 setflashmode(struct ifnet *ifp)
3582 struct an_softc *sc = ifp->if_softc;
3584 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3585 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3586 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3587 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3590 * mdelay(500); // 500ms delay
3593 FLASH_DELAY(sc, 500);
3595 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3596 printf("Waitbusy hang after setflash mode\n");
3603 * Get a character from the card matching matchbyte Step 3)
3607 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3610 unsigned char rbyte = 0;
3612 struct an_softc *sc = ifp->if_softc;
3616 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3618 if (dwelltime && !(0x8000 & rchar)) {
3620 FLASH_DELAY(sc, 10);
3623 rbyte = 0xff & rchar;
3625 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3626 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3630 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3632 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3634 } while (dwelltime > 0);
3639 * Put character to SWS0 wait for dwelltime x 50us for echo .
3643 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3646 int pollbusy, waittime;
3647 struct an_softc *sc = ifp->if_softc;
3654 waittime = dwelltime;
3657 * Wait for busy bit d15 to go false indicating buffer empty
3660 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3662 if (pollbusy & 0x8000) {
3663 FLASH_DELAY(sc, 50);
3669 while (waittime >= 0);
3671 /* timeout for busy clear wait */
3673 if (waittime <= 0) {
3674 if_printf(ifp, "flash putchar busywait timeout!\n");
3678 * Port is clear now write byte and wait for it to echo back
3681 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3682 FLASH_DELAY(sc, 50);
3684 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3685 } while (dwelltime >= 0 && echo != byte);
3688 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3690 return echo == byte;
3694 * Transfer 32k of firmware data from user buffer to our buffer and send to
3699 flashputbuf(struct ifnet *ifp)
3701 unsigned short *bufp;
3703 struct an_softc *sc = ifp->if_softc;
3707 bufp = sc->an_flash_buffer;
3710 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3711 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3713 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3714 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3717 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3718 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3719 ((u_int32_t *)bufp)[nwords] & 0xffff);
3723 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3729 * After flashing restart the card.
3733 flashrestart(struct ifnet *ifp)
3736 struct an_softc *sc = ifp->if_softc;
3738 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3742 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3747 * Entry point for flash ioclt.
3751 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3754 struct an_softc *sc;
3758 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3761 status = l_ioctl->command;
3763 switch (l_ioctl->command) {
3765 return cmdreset(ifp);
3768 if (sc->an_flash_buffer) {
3769 free(sc->an_flash_buffer, M_DEVBUF);
3770 sc->an_flash_buffer = NULL;
3772 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3773 if (sc->an_flash_buffer)
3774 return setflashmode(ifp);
3778 case AIROFLSHGCHR: /* Get char from aux */
3780 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3784 z = *(int *)&sc->areq;
3785 if ((status = flashgchar(ifp, z, 8000)) == 1)
3789 case AIROFLSHPCHR: /* Send char to card. */
3791 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3795 z = *(int *)&sc->areq;
3796 if ((status = flashpchar(ifp, z, 8000)) == -1)
3801 case AIROFLPUTBUF: /* Send 32k to card */
3802 if (l_ioctl->len > FLASH_SIZE) {
3803 if_printf(ifp, "Buffer to big, %x %x\n",
3804 l_ioctl->len, FLASH_SIZE);
3808 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3813 if ((status = flashputbuf(ifp)) != 0)
3819 if ((status = flashrestart(ifp)) != 0) {
3820 if_printf(ifp, "FLASHRESTART returned %d\n", status);