2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/dev/an/if_an.c,v 1.2.2.13 2003/02/11 03:32:48 ambrisko Exp $
33 * $DragonFly: src/sys/dev/netif/an/if_an.c,v 1.9 2004/01/06 01:40:46 dillon Exp $
35 * $FreeBSD: src/sys/dev/an/if_an.c,v 1.2.2.13 2003/02/11 03:32:48 ambrisko Exp $
39 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
41 * Written by Bill Paul <wpaul@ctr.columbia.edu>
42 * Electrical Engineering Department
43 * Columbia University, New York City
47 * The Aironet 4500/4800 series cards come in PCMCIA, ISA and PCI form.
48 * This driver supports all three device types (PCI devices are supported
49 * through an extra PCI shim: /sys/dev/an/if_an_pci.c). ISA devices can be
50 * supported either using hard-coded IO port/IRQ settings or via Plug
51 * and Play. The 4500 series devices support 1Mbps and 2Mbps data rates.
52 * The 4800 devices support 1, 2, 5.5 and 11Mbps rates.
54 * Like the WaveLAN/IEEE cards, the Aironet NICs are all essentially
55 * PCMCIA devices. The ISA and PCI cards are a combination of a PCMCIA
56 * device and a PCMCIA to ISA or PCMCIA to PCI adapter card. There are
57 * a couple of important differences though:
59 * - Lucent ISA card looks to the host like a PCMCIA controller with
60 * a PCMCIA WaveLAN card inserted. This means that even desktop
61 * machines need to be configured with PCMCIA support in order to
62 * use WaveLAN/IEEE ISA cards. The Aironet cards on the other hand
63 * actually look like normal ISA and PCI devices to the host, so
64 * no PCMCIA controller support is needed
66 * The latter point results in a small gotcha. The Aironet PCMCIA
67 * cards can be configured for one of two operating modes depending
68 * on how the Vpp1 and Vpp2 programming voltages are set when the
69 * card is activated. In order to put the card in proper PCMCIA
70 * operation (where the CIS table is visible and the interface is
71 * programmed for PCMCIA operation), both Vpp1 and Vpp2 have to be
72 * set to 5 volts. FreeBSD by default doesn't set the Vpp voltages,
73 * which leaves the card in ISA/PCI mode, which prevents it from
74 * being activated as an PCMCIA device.
76 * Note that some PCMCIA controller software packages for Windows NT
77 * fail to set the voltages as well.
79 * The Aironet devices can operate in both station mode and access point
80 * mode. Typically, when programmed for station mode, the card can be set
81 * to automatically perform encapsulation/decapsulation of Ethernet II
82 * and 802.3 frames within 802.11 frames so that the host doesn't have
83 * to do it itself. This driver doesn't program the card that way: the
84 * driver handles all of the encapsulation/decapsulation itself.
90 #define ANCACHE /* enable signal strength cache */
93 #include <sys/param.h>
94 #include <sys/systm.h>
95 #include <sys/sockio.h>
98 #include <sys/kernel.h>
100 #include <sys/ucred.h>
101 #include <sys/socket.h>
103 #include <sys/syslog.h>
105 #include <sys/sysctl.h>
106 #include <machine/clock.h> /* for DELAY */
108 #include <sys/module.h>
109 #include <sys/sysctl.h>
111 #include <machine/bus.h>
112 #include <sys/rman.h>
113 #include <machine/resource.h>
114 #include <sys/malloc.h>
117 #include <net/if_arp.h>
118 #include <net/ethernet.h>
119 #include <net/if_dl.h>
120 #include <net/if_types.h>
121 #include <net/if_ieee80211.h>
122 #include <net/if_media.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 "if_aironet_ieee.h"
136 #include "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 int an_init_tx_ring (struct an_softc *);
144 static void an_start (struct ifnet *);
145 static void an_watchdog (struct ifnet *);
146 static void an_rxeof (struct an_softc *);
147 static void an_txeof (struct an_softc *, int);
149 static void an_promisc (struct an_softc *, int);
150 static int an_cmd (struct an_softc *, int, int);
151 static int an_cmd_struct (struct an_softc *, struct an_command *,
153 static int an_read_record (struct an_softc *, struct an_ltv_gen *);
154 static int an_write_record (struct an_softc *, struct an_ltv_gen *);
155 static int an_read_data (struct an_softc *, int,
157 static int an_write_data (struct an_softc *, 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,
162 struct an_dma_alloc *, int);
163 static void an_dma_free (struct an_softc *,
164 struct an_dma_alloc *);
165 static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
166 static void an_stats_update (void *);
167 static void an_setdef (struct an_softc *, struct an_req *);
169 static void an_cache_store (struct an_softc *, struct ether_header *,
170 struct mbuf *, u_int8_t, u_int8_t);
173 /* function definitions for use with the Cisco's Linux configuration
177 static int readrids (struct ifnet*, struct aironet_ioctl*);
178 static int writerids (struct ifnet*, struct aironet_ioctl*);
179 static int flashcard (struct ifnet*, struct aironet_ioctl*);
181 static int cmdreset (struct ifnet *);
182 static int setflashmode (struct ifnet *);
183 static int flashgchar (struct ifnet *,int,int);
184 static int flashpchar (struct ifnet *,int,int);
185 static int flashputbuf (struct ifnet *);
186 static int flashrestart (struct ifnet *);
187 static int WaitBusy (struct ifnet *, int);
188 static int unstickbusy (struct ifnet *);
190 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
193 static int an_media_change (struct ifnet *);
194 static void an_media_status (struct ifnet *, struct ifmediareq *);
196 static int an_dump = 0;
197 static int an_cache_mode = 0;
203 static char an_conf[256];
204 static char an_conf_cache[256];
206 DECLARE_DUMMY_MODULE(if_an);
210 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
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 * 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.
316 struct an_softc *sc = device_get_softc(dev);
317 struct an_ltv_ssidlist ssid;
320 bzero((char *)&ssid, sizeof(ssid));
322 error = an_alloc_port(dev, 0, AN_IOSIZ);
326 /* can't do autoprobing */
327 if (rman_get_start(sc->port_res) == -1)
331 * We need to fake up a softc structure long enough
332 * to be able to issue commands and call some of the
335 sc->an_bhandle = rman_get_bushandle(sc->port_res);
336 sc->an_btag = rman_get_bustag(sc->port_res);
337 sc->an_unit = device_get_unit(dev);
339 ssid.an_len = sizeof(ssid);
340 ssid.an_type = AN_RID_SSIDLIST;
342 /* Make sure interrupts are disabled. */
343 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
344 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
347 /* No need for an_init_mpi350_desc since it will be done in attach */
349 if (an_cmd(sc, AN_CMD_READCFG, 0))
352 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
355 /* See if the ssid matches what we expect ... but doesn't have to */
356 if (strcmp(ssid.an_ssid1, AN_DEF_SSID))
363 * Allocate a port resource with the given resource id.
366 an_alloc_port(dev, rid, size)
371 struct an_softc *sc = device_get_softc(dev);
372 struct resource *res;
374 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
375 0ul, ~0ul, size, RF_ACTIVE);
386 * Allocate a memory resource with the given resource id.
388 int an_alloc_memory(device_t dev, int rid, int size)
390 struct an_softc *sc = device_get_softc(dev);
391 struct resource *res;
393 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
394 0ul, ~0ul, size, RF_ACTIVE);
406 * Allocate a auxilary memory resource with the given resource id.
408 int an_alloc_aux_memory(device_t dev, int rid, int size)
410 struct an_softc *sc = device_get_softc(dev);
411 struct resource *res;
413 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
414 0ul, ~0ul, size, RF_ACTIVE);
416 sc->mem_aux_rid = rid;
417 sc->mem_aux_res = res;
418 sc->mem_aux_used = size;
426 * Allocate an irq resource with the given resource id.
429 an_alloc_irq(dev, rid, flags)
434 struct an_softc *sc = device_get_softc(dev);
435 struct resource *res;
437 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
438 0ul, ~0ul, 1, (RF_ACTIVE | flags));
449 an_dma_malloc_cb(arg, segs, nseg, error)
451 bus_dma_segment_t *segs;
455 bus_addr_t *paddr = (bus_addr_t*) arg;
456 *paddr = segs->ds_addr;
460 * Alloc DMA memory and set the pointer to it
463 an_dma_malloc(sc, size, dma, mapflags)
466 struct an_dma_alloc *dma;
471 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
475 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
476 BUS_DMA_NOWAIT, &dma->an_dma_map);
480 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
484 mapflags | BUS_DMA_NOWAIT);
488 dma->an_dma_size = size;
492 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);
496 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
497 dma->an_dma_map = NULL;
504 struct an_dma_alloc *dma;
506 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
507 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);
512 * Release all resources
515 an_release_resources(dev)
518 struct an_softc *sc = device_get_softc(dev);
522 bus_release_resource(dev, SYS_RES_IOPORT,
523 sc->port_rid, sc->port_res);
527 bus_release_resource(dev, SYS_RES_MEMORY,
528 sc->mem_rid, sc->mem_res);
531 if (sc->mem_aux_res) {
532 bus_release_resource(dev, SYS_RES_MEMORY,
533 sc->mem_aux_rid, sc->mem_aux_res);
537 bus_release_resource(dev, SYS_RES_IRQ,
538 sc->irq_rid, sc->irq_res);
541 if (sc->an_rid_buffer.an_dma_paddr) {
542 an_dma_free(sc, &sc->an_rid_buffer);
544 for (i = 0; i < AN_MAX_RX_DESC; i++)
545 if (sc->an_rx_buffer[i].an_dma_paddr) {
546 an_dma_free(sc, &sc->an_rx_buffer[i]);
548 for (i = 0; i < AN_MAX_TX_DESC; i++)
549 if (sc->an_tx_buffer[i].an_dma_paddr) {
550 an_dma_free(sc, &sc->an_tx_buffer[i]);
553 bus_dma_tag_destroy(sc->an_dtag);
559 an_init_mpi350_desc(sc)
562 struct an_command cmd_struct;
563 struct an_reply reply;
564 struct an_card_rid_desc an_rid_desc;
565 struct an_card_rx_desc an_rx_desc;
566 struct an_card_tx_desc an_tx_desc;
569 if(!sc->an_rid_buffer.an_dma_paddr)
570 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
571 &sc->an_rid_buffer, 0);
572 for (i = 0; i < AN_MAX_RX_DESC; i++)
573 if(!sc->an_rx_buffer[i].an_dma_paddr)
574 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
575 &sc->an_rx_buffer[i], 0);
576 for (i = 0; i < AN_MAX_TX_DESC; i++)
577 if(!sc->an_tx_buffer[i].an_dma_paddr)
578 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
579 &sc->an_tx_buffer[i], 0);
582 * Allocate RX descriptor
584 bzero(&reply,sizeof(reply));
585 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
586 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
587 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
588 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
589 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
590 printf("an%d: failed to allocate RX descriptor\n",
595 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
596 bzero(&an_rx_desc, sizeof(an_rx_desc));
597 an_rx_desc.an_valid = 1;
598 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
599 an_rx_desc.an_done = 0;
600 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
602 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
603 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
604 + (desc * sizeof(an_rx_desc))
606 ((u_int32_t*)&an_rx_desc)[i]);
610 * Allocate TX descriptor
613 bzero(&reply,sizeof(reply));
614 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
615 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
616 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
617 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
618 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
619 printf("an%d: failed to allocate TX descriptor\n",
624 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
625 bzero(&an_tx_desc, sizeof(an_tx_desc));
626 an_tx_desc.an_offset = 0;
627 an_tx_desc.an_eoc = 0;
628 an_tx_desc.an_valid = 0;
629 an_tx_desc.an_len = 0;
630 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
632 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
633 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
634 + (desc * sizeof(an_tx_desc))
636 ((u_int32_t*)&an_tx_desc)[i]);
640 * Allocate RID descriptor
643 bzero(&reply,sizeof(reply));
644 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
645 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
646 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
647 cmd_struct.an_parm2 = 1;
648 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
649 printf("an%d: failed to allocate host descriptor\n",
654 bzero(&an_rid_desc, sizeof(an_rid_desc));
655 an_rid_desc.an_valid = 1;
656 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
657 an_rid_desc.an_rid = 0;
658 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
660 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
661 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
662 ((u_int32_t*)&an_rid_desc)[i]);
668 an_attach(sc, unit, flags)
673 struct ifnet *ifp = &sc->arpcom.ac_if;
677 sc->an_associated = 0;
679 sc->an_was_monitor = 0;
680 sc->an_flash_buffer = NULL;
685 error = an_init_mpi350_desc(sc);
690 /* Load factory config */
691 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
692 printf("an%d: failed to load config data\n", sc->an_unit);
696 /* Read the current configuration */
697 sc->an_config.an_type = AN_RID_GENCONFIG;
698 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
699 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
700 printf("an%d: read record failed\n", sc->an_unit);
704 /* Read the card capabilities */
705 sc->an_caps.an_type = AN_RID_CAPABILITIES;
706 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
707 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
708 printf("an%d: read record failed\n", sc->an_unit);
713 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
714 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
715 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
716 printf("an%d: read record failed\n", sc->an_unit);
721 sc->an_aplist.an_type = AN_RID_APLIST;
722 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
723 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
724 printf("an%d: read record failed\n", sc->an_unit);
729 /* Read the RSSI <-> dBm map */
730 sc->an_have_rssimap = 0;
731 if (sc->an_caps.an_softcaps & 8) {
732 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
733 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
734 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
735 printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
737 printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
738 sc->an_have_rssimap = 1;
741 printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
745 bcopy((char *)&sc->an_caps.an_oemaddr,
746 (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
748 printf("an%d: Ethernet address: %6D\n", sc->an_unit,
749 sc->arpcom.ac_enaddr, ":");
752 if_initname(ifp, "an", unit);
753 ifp->if_mtu = ETHERMTU;
754 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
755 ifp->if_ioctl = an_ioctl;
756 ifp->if_output = ether_output;
757 ifp->if_start = an_start;
758 ifp->if_watchdog = an_watchdog;
759 ifp->if_init = an_init;
760 ifp->if_baudrate = 10000000;
761 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
763 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
764 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
765 sizeof(AN_DEFAULT_NODENAME) - 1);
767 bzero(sc->an_ssidlist.an_ssid1, sizeof(sc->an_ssidlist.an_ssid1));
768 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_ssid1,
769 sizeof(AN_DEFAULT_NETNAME) - 1);
770 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME);
772 sc->an_config.an_opmode =
773 AN_OPMODE_INFRASTRUCTURE_STATION;
776 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
778 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
779 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
780 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
781 IFM_IEEE80211_ADHOC, 0), 0);
782 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
783 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
784 IFM_IEEE80211_ADHOC, 0), 0);
785 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
786 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
787 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
788 IFM_IEEE80211_ADHOC, 0), 0);
789 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
791 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
792 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
793 IFM_IEEE80211_ADHOC, 0), 0);
794 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
796 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
797 IFM_IEEE80211_ADHOC, 0), 0);
798 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
800 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
804 * Call MI attach routine.
806 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
807 callout_handle_init(&sc->an_stat_ch);
817 struct ether_header *eh;
818 struct ieee80211_frame *ih;
819 struct an_rxframe rx_frame;
820 struct an_rxframe_802_3 rx_frame_802_3;
822 int len, id, error = 0, i, count = 0;
823 int ieee80211_header_len;
826 struct an_card_rx_desc an_rx_desc;
829 ifp = &sc->arpcom.ac_if;
832 id = CSR_READ_2(sc, AN_RX_FID);
834 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
835 /* read raw 802.11 packet */
836 bpf_buf = sc->buf_802_11;
839 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
846 * skip beacon by default since this increases the
850 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
851 (rx_frame.an_frame_ctl &
852 IEEE80211_FC0_SUBTYPE_BEACON)) {
856 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
857 len = rx_frame.an_rx_payload_len
859 /* Check for insane frame length */
860 if (len > sizeof(sc->buf_802_11)) {
861 printf("an%d: oversized packet "
862 "received (%d, %d)\n",
863 sc->an_unit, len, MCLBYTES);
868 bcopy((char *)&rx_frame,
869 bpf_buf, sizeof(rx_frame));
871 error = an_read_data(sc, id, sizeof(rx_frame),
872 (caddr_t)bpf_buf+sizeof(rx_frame),
873 rx_frame.an_rx_payload_len);
875 fc1=rx_frame.an_frame_ctl >> 8;
876 ieee80211_header_len =
877 sizeof(struct ieee80211_frame);
878 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
879 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
880 ieee80211_header_len += ETHER_ADDR_LEN;
883 len = rx_frame.an_rx_payload_len
884 + ieee80211_header_len;
885 /* Check for insane frame length */
886 if (len > sizeof(sc->buf_802_11)) {
887 printf("an%d: oversized packet "
888 "received (%d, %d)\n",
889 sc->an_unit, len, MCLBYTES);
894 ih = (struct ieee80211_frame *)bpf_buf;
896 bcopy((char *)&rx_frame.an_frame_ctl,
897 (char *)ih, ieee80211_header_len);
899 error = an_read_data(sc, id, sizeof(rx_frame) +
901 (caddr_t)ih +ieee80211_header_len,
902 rx_frame.an_rx_payload_len);
904 /* dump raw 802.11 packet to bpf and skip ip stack */
905 if (ifp->if_bpf != NULL) {
906 bpf_tap(ifp, bpf_buf, len);
909 MGETHDR(m, M_NOWAIT, MT_DATA);
915 if (!(m->m_flags & M_EXT)) {
920 m->m_pkthdr.rcvif = ifp;
921 /* Read Ethernet encapsulated packet */
924 /* Read NIC frame header */
925 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
931 /* Read in the 802_3 frame header */
932 if (an_read_data(sc, id, 0x34,
933 (caddr_t)&rx_frame_802_3,
934 sizeof(rx_frame_802_3))) {
938 if (rx_frame_802_3.an_rx_802_3_status != 0) {
942 /* Check for insane frame length */
943 len = rx_frame_802_3.an_rx_802_3_payload_len;
944 if (len > sizeof(sc->buf_802_11)) {
945 printf("an%d: oversized packet "
946 "received (%d, %d)\n",
947 sc->an_unit, len, MCLBYTES);
951 m->m_pkthdr.len = m->m_len =
952 rx_frame_802_3.an_rx_802_3_payload_len + 12;
954 eh = mtod(m, struct ether_header *);
956 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
957 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
958 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
959 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
961 /* in mbuf header type is just before payload */
962 error = an_read_data(sc, id, 0x44,
963 (caddr_t)&(eh->ether_type),
964 rx_frame_802_3.an_rx_802_3_payload_len);
973 /* Receive packet. */
974 m_adj(m, sizeof(struct ether_header));
976 an_cache_store(sc, eh, m,
977 rx_frame.an_rx_signal_strength,
980 ether_input(ifp, eh, m);
983 } else { /* MPI-350 */
984 for (count = 0; count < AN_MAX_RX_DESC; count++){
985 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
986 ((u_int32_t*)&an_rx_desc)[i]
987 = CSR_MEM_AUX_READ_4(sc,
989 + (count * sizeof(an_rx_desc))
992 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
993 buf = sc->an_rx_buffer[count].an_dma_vaddr;
995 MGETHDR(m, M_NOWAIT, MT_DATA);
1000 MCLGET(m, M_NOWAIT);
1001 if (!(m->m_flags & M_EXT)) {
1006 m->m_pkthdr.rcvif = ifp;
1007 /* Read Ethernet encapsulated packet */
1010 * No ANCACHE support since we just get back
1011 * an Ethernet packet no 802.11 info
1015 /* Read NIC frame header */
1016 bcopy(buf, (caddr_t)&rx_frame,
1020 /* Check for insane frame length */
1021 len = an_rx_desc.an_len + 12;
1022 if (len > MCLBYTES) {
1023 printf("an%d: oversized packet "
1024 "received (%d, %d)\n",
1025 sc->an_unit, len, MCLBYTES);
1030 m->m_pkthdr.len = m->m_len =
1031 an_rx_desc.an_len + 12;
1033 eh = mtod(m, struct ether_header *);
1035 bcopy(buf, (char *)eh,
1040 /* Receive packet. */
1041 m_adj(m, sizeof(struct ether_header));
1044 an_cache_store(sc, eh, m,
1045 rx_frame.an_rx_signal_strength,
1049 ether_input(ifp, eh, m);
1051 an_rx_desc.an_valid = 1;
1052 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1053 an_rx_desc.an_done = 0;
1054 an_rx_desc.an_phys =
1055 sc->an_rx_buffer[count].an_dma_paddr;
1057 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1058 CSR_MEM_AUX_WRITE_4(sc,
1060 + (count * sizeof(an_rx_desc))
1062 ((u_int32_t*)&an_rx_desc)[i]);
1065 printf("an%d: Didn't get valid RX packet "
1069 an_rx_desc.an_valid, an_rx_desc.an_len);
1076 an_txeof(sc, status)
1077 struct an_softc *sc;
1083 ifp = &sc->arpcom.ac_if;
1086 ifp->if_flags &= ~IFF_OACTIVE;
1089 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1091 if (status & AN_EV_TX_EXC) {
1096 for (i = 0; i < AN_TX_RING_CNT; i++) {
1097 if (id == sc->an_rdata.an_tx_ring[i]) {
1098 sc->an_rdata.an_tx_ring[i] = 0;
1103 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1104 } else { /* MPI 350 */
1105 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1106 if (sc->an_rdata.an_tx_prod ==
1107 sc->an_rdata.an_tx_cons)
1108 sc->an_rdata.an_tx_empty = 1;
1115 * We abuse the stats updater to check the current NIC status. This
1116 * is important because we don't want to allow transmissions until
1117 * the NIC has synchronized to the current cell (either as the master
1118 * in an ad-hoc group, or as a station connected to an access point).
1121 an_stats_update(xsc)
1124 struct an_softc *sc;
1131 ifp = &sc->arpcom.ac_if;
1133 sc->an_status.an_type = AN_RID_STATUS;
1134 sc->an_status.an_len = sizeof(struct an_ltv_status);
1135 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1137 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1138 sc->an_associated = 1;
1140 sc->an_associated = 0;
1142 /* Don't do this while we're transmitting */
1143 if (ifp->if_flags & IFF_OACTIVE) {
1144 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1149 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1150 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1151 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1153 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1163 struct an_softc *sc;
1167 sc = (struct an_softc*)xsc;
1172 ifp = &sc->arpcom.ac_if;
1174 /* Disable interrupts. */
1175 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1177 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1178 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
1180 if (status & AN_EV_AWAKE) {
1181 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
1184 if (status & AN_EV_LINKSTAT) {
1185 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1186 == AN_LINKSTAT_ASSOCIATED)
1187 sc->an_associated = 1;
1189 sc->an_associated = 0;
1190 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1193 if (status & AN_EV_RX) {
1195 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1198 if (status & AN_EV_TX) {
1199 an_txeof(sc, status);
1200 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1203 if (status & AN_EV_TX_EXC) {
1204 an_txeof(sc, status);
1205 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1208 if (status & AN_EV_ALLOC)
1209 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1211 /* Re-enable interrupts. */
1212 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1214 if ((ifp->if_flags & IFF_UP) && (ifp->if_snd.ifq_head != NULL))
1221 an_cmd_struct(sc, cmd, reply)
1222 struct an_softc *sc;
1223 struct an_command *cmd;
1224 struct an_reply *reply;
1228 for (i = 0; i != AN_TIMEOUT; i++) {
1229 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1234 if( i == AN_TIMEOUT) {
1239 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1240 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1241 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1242 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1244 for (i = 0; i < AN_TIMEOUT; i++) {
1245 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1250 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1251 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1252 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1253 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1255 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1256 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1258 /* Ack the command */
1259 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1261 if (i == AN_TIMEOUT)
1268 an_cmd(sc, cmd, val)
1269 struct an_softc *sc;
1275 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1276 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1277 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1278 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1280 for (i = 0; i < AN_TIMEOUT; i++) {
1281 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1284 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1285 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1289 for (i = 0; i < AN_TIMEOUT; i++) {
1290 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1291 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1292 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1293 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1294 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1298 /* Ack the command */
1299 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1301 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1302 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1304 if (i == AN_TIMEOUT)
1311 * This reset sequence may look a little strange, but this is the
1312 * most reliable method I've found to really kick the NIC in the
1313 * head and force it to reboot correctly.
1317 struct an_softc *sc;
1322 an_cmd(sc, AN_CMD_ENABLE, 0);
1323 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1324 an_cmd(sc, AN_CMD_NOOP2, 0);
1326 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1327 printf("an%d: reset failed\n", sc->an_unit);
1329 an_cmd(sc, AN_CMD_DISABLE, 0);
1335 * Read an LTV record from the NIC.
1338 an_read_record(sc, ltv)
1339 struct an_softc *sc;
1340 struct an_ltv_gen *ltv;
1342 struct an_ltv_gen *an_ltv;
1343 struct an_card_rid_desc an_rid_desc;
1344 struct an_command cmd;
1345 struct an_reply reply;
1350 if (ltv->an_len < 4 || ltv->an_type == 0)
1354 /* Tell the NIC to enter record read mode. */
1355 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1356 printf("an%d: RID access failed\n", sc->an_unit);
1360 /* Seek to the record. */
1361 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1362 printf("an%d: seek to record failed\n", sc->an_unit);
1367 * Read the length and record type and make sure they
1368 * match what we expect (this verifies that we have enough
1369 * room to hold all of the returned data).
1370 * Length includes type but not length.
1372 len = CSR_READ_2(sc, AN_DATA1);
1373 if (len > (ltv->an_len - 2)) {
1374 printf("an%d: record length mismatch -- expected %d, "
1375 "got %d for Rid %x\n", sc->an_unit,
1376 ltv->an_len - 2, len, ltv->an_type);
1377 len = ltv->an_len - 2;
1379 ltv->an_len = len + 2;
1382 /* Now read the data. */
1383 len -= 2; /* skip the type */
1385 for (i = len; i > 1; i -= 2)
1386 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1388 ptr2 = (u_int8_t *)ptr;
1389 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1391 } else { /* MPI-350 */
1392 an_rid_desc.an_valid = 1;
1393 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1394 an_rid_desc.an_rid = 0;
1395 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1396 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1398 bzero(&cmd, sizeof(cmd));
1399 bzero(&reply, sizeof(reply));
1400 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1401 cmd.an_parm0 = ltv->an_type;
1403 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1404 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1405 ((u_int32_t*)&an_rid_desc)[i]);
1407 if (an_cmd_struct(sc, &cmd, &reply)
1408 || reply.an_status & AN_CMD_QUAL_MASK) {
1409 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1410 sc->an_unit, ltv->an_type,
1419 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1420 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1421 an_rid_desc.an_len = an_ltv->an_len;
1424 if (an_rid_desc.an_len > 2)
1425 bcopy(&an_ltv->an_type,
1427 an_rid_desc.an_len - 2);
1428 ltv->an_len = an_rid_desc.an_len + 2;
1432 an_dump_record(sc, ltv, "Read");
1438 * Same as read, except we inject data instead of reading it.
1441 an_write_record(sc, ltv)
1442 struct an_softc *sc;
1443 struct an_ltv_gen *ltv;
1445 struct an_card_rid_desc an_rid_desc;
1446 struct an_command cmd;
1447 struct an_reply reply;
1454 an_dump_record(sc, ltv, "Write");
1457 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1460 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1464 * Length includes type but not length.
1466 len = ltv->an_len - 2;
1467 CSR_WRITE_2(sc, AN_DATA1, len);
1469 len -= 2; /* skip the type */
1471 for (i = len; i > 1; i -= 2)
1472 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1474 ptr2 = (u_int8_t *)ptr;
1475 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1478 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1483 for (i = 0; i != AN_TIMEOUT; i++) {
1484 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1490 if (i == AN_TIMEOUT) {
1494 an_rid_desc.an_valid = 1;
1495 an_rid_desc.an_len = ltv->an_len - 2;
1496 an_rid_desc.an_rid = ltv->an_type;
1497 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1499 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1500 an_rid_desc.an_len);
1502 bzero(&cmd,sizeof(cmd));
1503 bzero(&reply,sizeof(reply));
1504 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1505 cmd.an_parm0 = ltv->an_type;
1507 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1508 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1509 ((u_int32_t*)&an_rid_desc)[i]);
1511 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1512 printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
1513 sc->an_unit, ltv->an_type,
1522 ptr = (u_int16_t *)buf;
1524 if (reply.an_status & AN_CMD_QUAL_MASK) {
1525 printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
1526 sc->an_unit, ltv->an_type,
1540 an_dump_record(sc, ltv, string)
1541 struct an_softc *sc;
1542 struct an_ltv_gen *ltv;
1551 len = ltv->an_len - 4;
1552 printf("an%d: RID %4x, Length %4d, Mode %s\n",
1553 sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
1555 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1556 printf("an%d:\t", sc->an_unit);
1557 bzero(buf,sizeof(buf));
1559 ptr2 = (u_int8_t *)<v->an_val;
1560 for (i = len; i > 0; i--) {
1561 printf("%02x ", *ptr2);
1564 if (temp >= ' ' && temp <= '~')
1566 else if (temp >= 'A' && temp <= 'Z')
1570 if (++count == 16) {
1573 printf("an%d:\t", sc->an_unit);
1574 bzero(buf,sizeof(buf));
1577 for (; count != 16; count++) {
1580 printf(" %s\n",buf);
1585 an_seek(sc, id, off, chan)
1586 struct an_softc *sc;
1602 printf("an%d: invalid data path: %x\n", sc->an_unit, chan);
1606 CSR_WRITE_2(sc, selreg, id);
1607 CSR_WRITE_2(sc, offreg, off);
1609 for (i = 0; i < AN_TIMEOUT; i++) {
1610 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1614 if (i == AN_TIMEOUT)
1621 an_read_data(sc, id, off, buf, len)
1622 struct an_softc *sc;
1632 if (an_seek(sc, id, off, AN_BAP1))
1636 ptr = (u_int16_t *)buf;
1637 for (i = len; i > 1; i -= 2)
1638 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1640 ptr2 = (u_int8_t *)ptr;
1641 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1648 an_write_data(sc, id, off, buf, len)
1649 struct an_softc *sc;
1659 if (an_seek(sc, id, off, AN_BAP0))
1663 ptr = (u_int16_t *)buf;
1664 for (i = len; i > 1; i -= 2)
1665 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1667 ptr2 = (u_int8_t *)ptr;
1668 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1675 * Allocate a region of memory inside the NIC and zero
1679 an_alloc_nicmem(sc, len, id)
1680 struct an_softc *sc;
1686 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1687 printf("an%d: failed to allocate %d bytes on NIC\n",
1692 for (i = 0; i < AN_TIMEOUT; i++) {
1693 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1697 if (i == AN_TIMEOUT)
1700 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1701 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1703 if (an_seek(sc, *id, 0, AN_BAP0))
1706 for (i = 0; i < len / 2; i++)
1707 CSR_WRITE_2(sc, AN_DATA0, 0);
1714 struct an_softc *sc;
1715 struct an_req *areq;
1717 struct sockaddr_dl *sdl;
1720 struct an_ltv_genconfig *cfg;
1721 struct an_ltv_ssidlist *ssid;
1722 struct an_ltv_aplist *ap;
1723 struct an_ltv_gen *sp;
1725 ifp = &sc->arpcom.ac_if;
1727 switch (areq->an_type) {
1728 case AN_RID_GENCONFIG:
1729 cfg = (struct an_ltv_genconfig *)areq;
1731 ifa = ifnet_addrs[ifp->if_index - 1];
1732 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1733 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1735 bcopy((char *)&cfg->an_macaddr, LLADDR(sdl), ETHER_ADDR_LEN);
1737 bcopy((char *)cfg, (char *)&sc->an_config,
1738 sizeof(struct an_ltv_genconfig));
1740 case AN_RID_SSIDLIST:
1741 ssid = (struct an_ltv_ssidlist *)areq;
1742 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1743 sizeof(struct an_ltv_ssidlist));
1746 ap = (struct an_ltv_aplist *)areq;
1747 bcopy((char *)ap, (char *)&sc->an_aplist,
1748 sizeof(struct an_ltv_aplist));
1750 case AN_RID_TX_SPEED:
1751 sp = (struct an_ltv_gen *)areq;
1752 sc->an_tx_rate = sp->an_val;
1754 /* Read the current configuration */
1755 sc->an_config.an_type = AN_RID_GENCONFIG;
1756 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1757 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1758 cfg = &sc->an_config;
1760 /* clear other rates and set the only one we want */
1761 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1762 cfg->an_rates[0] = sc->an_tx_rate;
1764 /* Save the new rate */
1765 sc->an_config.an_type = AN_RID_GENCONFIG;
1766 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1768 case AN_RID_WEP_TEMP:
1769 /* Cache the temp keys */
1771 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1772 sizeof(struct an_ltv_key));
1773 case AN_RID_WEP_PERM:
1774 case AN_RID_LEAPUSERNAME:
1775 case AN_RID_LEAPPASSWORD:
1776 /* Disable the MAC. */
1777 an_cmd(sc, AN_CMD_DISABLE, 0);
1780 an_write_record(sc, (struct an_ltv_gen *)areq);
1782 /* Turn the MAC back on. */
1783 an_cmd(sc, AN_CMD_ENABLE, 0);
1786 case AN_RID_MONITOR_MODE:
1787 cfg = (struct an_ltv_genconfig *)areq;
1789 if (ng_ether_detach_p != NULL)
1790 (*ng_ether_detach_p) (ifp);
1791 sc->an_monitor = cfg->an_len;
1793 if (sc->an_monitor & AN_MONITOR) {
1794 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1795 bpfattach(ifp, DLT_AIRONET_HEADER,
1796 sizeof(struct ether_header));
1798 bpfattach(ifp, DLT_IEEE802_11,
1799 sizeof(struct ether_header));
1802 bpfattach(ifp, DLT_EN10MB,
1803 sizeof(struct ether_header));
1804 if (ng_ether_attach_p != NULL)
1805 (*ng_ether_attach_p) (ifp);
1809 printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
1815 /* Reinitialize the card. */
1823 * Derived from Linux driver to enable promiscious mode.
1827 an_promisc(sc, promisc)
1828 struct an_softc *sc;
1831 if (sc->an_was_monitor)
1834 an_init_mpi350_desc(sc);
1835 if (sc->an_monitor || sc->an_was_monitor)
1838 sc->an_was_monitor = sc->an_monitor;
1839 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1845 an_ioctl(ifp, command, data)
1853 struct an_softc *sc;
1855 struct thread *td = curthread;
1856 struct ieee80211req *ireq;
1857 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1859 struct an_ltv_genconfig *config;
1860 struct an_ltv_key *key;
1861 struct an_ltv_status *status;
1862 struct an_ltv_ssidlist *ssids;
1864 struct aironet_ioctl l_ioctl;
1868 ifr = (struct ifreq *)data;
1869 ireq = (struct ieee80211req *)data;
1871 config = (struct an_ltv_genconfig *)&sc->areq;
1872 key = (struct an_ltv_key *)&sc->areq;
1873 status = (struct an_ltv_status *)&sc->areq;
1874 ssids = (struct an_ltv_ssidlist *)&sc->areq;
1885 error = ether_ioctl(ifp, command, data);
1888 if (ifp->if_flags & IFF_UP) {
1889 if (ifp->if_flags & IFF_RUNNING &&
1890 ifp->if_flags & IFF_PROMISC &&
1891 !(sc->an_if_flags & IFF_PROMISC)) {
1893 } else if (ifp->if_flags & IFF_RUNNING &&
1894 !(ifp->if_flags & IFF_PROMISC) &&
1895 sc->an_if_flags & IFF_PROMISC) {
1900 if (ifp->if_flags & IFF_RUNNING)
1903 sc->an_if_flags = ifp->if_flags;
1908 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1912 /* The Aironet has no multicast filter. */
1916 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1920 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1924 sc->an_sigitems = sc->an_nextitem = 0;
1926 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1927 char *pt = (char *)&sc->areq.an_val;
1928 bcopy((char *)&sc->an_sigitems, (char *)pt,
1931 sc->areq.an_len = sizeof(int) / 2;
1932 bcopy((char *)&sc->an_sigcache, (char *)pt,
1933 sizeof(struct an_sigcache) * sc->an_sigitems);
1934 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1935 sc->an_sigitems) / 2) + 1;
1938 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1942 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1945 if ((error = suser(td)))
1947 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1950 an_setdef(sc, &sc->areq);
1952 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1953 if ((error = suser(td)))
1955 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1956 mode = l_ioctl.command;
1958 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1959 error = readrids(ifp, &l_ioctl);
1960 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1961 error = writerids(ifp, &l_ioctl);
1962 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1963 error = flashcard(ifp, &l_ioctl);
1968 /* copy out the updated command info */
1969 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1972 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1973 if ((error = suser(td)))
1975 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1976 l_ioctl.command = 0;
1978 copyout(&error, l_ioctl.data, sizeof(error));
1982 sc->areq.an_len = sizeof(sc->areq);
1983 /* was that a good idea DJA we are doing a short-cut */
1984 switch (ireq->i_type) {
1985 case IEEE80211_IOC_SSID:
1986 if (ireq->i_val == -1) {
1987 sc->areq.an_type = AN_RID_STATUS;
1988 if (an_read_record(sc,
1989 (struct an_ltv_gen *)&sc->areq)) {
1993 len = status->an_ssidlen;
1994 tmpptr = status->an_ssid;
1995 } else if (ireq->i_val >= 0) {
1996 sc->areq.an_type = AN_RID_SSIDLIST;
1997 if (an_read_record(sc,
1998 (struct an_ltv_gen *)&sc->areq)) {
2002 if (ireq->i_val == 0) {
2003 len = ssids->an_ssid1_len;
2004 tmpptr = ssids->an_ssid1;
2005 } else if (ireq->i_val == 1) {
2006 len = ssids->an_ssid2_len;
2007 tmpptr = ssids->an_ssid2;
2008 } else if (ireq->i_val == 2) {
2009 len = ssids->an_ssid3_len;
2010 tmpptr = ssids->an_ssid3;
2019 if (len > IEEE80211_NWID_LEN) {
2024 bzero(tmpstr, IEEE80211_NWID_LEN);
2025 bcopy(tmpptr, tmpstr, len);
2026 error = copyout(tmpstr, ireq->i_data,
2027 IEEE80211_NWID_LEN);
2029 case IEEE80211_IOC_NUMSSIDS:
2032 case IEEE80211_IOC_WEP:
2033 sc->areq.an_type = AN_RID_ACTUALCFG;
2034 if (an_read_record(sc,
2035 (struct an_ltv_gen *)&sc->areq)) {
2039 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2040 if (config->an_authtype &
2041 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2042 ireq->i_val = IEEE80211_WEP_MIXED;
2044 ireq->i_val = IEEE80211_WEP_ON;
2046 ireq->i_val = IEEE80211_WEP_OFF;
2049 case IEEE80211_IOC_WEPKEY:
2051 * XXX: I'm not entierly convinced this is
2052 * correct, but it's what is implemented in
2053 * ancontrol so it will have to do until we get
2054 * access to actual Cisco code.
2056 if (ireq->i_val < 0 || ireq->i_val > 8) {
2061 if (ireq->i_val < 5) {
2062 sc->areq.an_type = AN_RID_WEP_TEMP;
2063 for (i = 0; i < 5; i++) {
2064 if (an_read_record(sc,
2065 (struct an_ltv_gen *)&sc->areq)) {
2069 if (key->kindex == 0xffff)
2071 if (key->kindex == ireq->i_val)
2073 /* Required to get next entry */
2074 sc->areq.an_type = AN_RID_WEP_PERM;
2079 /* We aren't allowed to read the value of the
2080 * key from the card so we just output zeros
2081 * like we would if we could read the card, but
2082 * denied the user access.
2086 error = copyout(tmpstr, ireq->i_data, len);
2088 case IEEE80211_IOC_NUMWEPKEYS:
2089 ireq->i_val = 9; /* include home key */
2091 case IEEE80211_IOC_WEPTXKEY:
2093 * For some strange reason, you have to read all
2094 * keys before you can read the txkey.
2096 sc->areq.an_type = AN_RID_WEP_TEMP;
2097 for (i = 0; i < 5; i++) {
2098 if (an_read_record(sc,
2099 (struct an_ltv_gen *) &sc->areq)) {
2103 if (key->kindex == 0xffff)
2105 /* Required to get next entry */
2106 sc->areq.an_type = AN_RID_WEP_PERM;
2111 sc->areq.an_type = AN_RID_WEP_PERM;
2112 key->kindex = 0xffff;
2113 if (an_read_record(sc,
2114 (struct an_ltv_gen *)&sc->areq)) {
2118 ireq->i_val = key->mac[0];
2120 * Check for home mode. Map home mode into
2121 * 5th key since that is how it is stored on
2124 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2125 sc->areq.an_type = AN_RID_GENCONFIG;
2126 if (an_read_record(sc,
2127 (struct an_ltv_gen *)&sc->areq)) {
2131 if (config->an_home_product & AN_HOME_NETWORK)
2134 case IEEE80211_IOC_AUTHMODE:
2135 sc->areq.an_type = AN_RID_ACTUALCFG;
2136 if (an_read_record(sc,
2137 (struct an_ltv_gen *)&sc->areq)) {
2141 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2143 ireq->i_val = IEEE80211_AUTH_NONE;
2144 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2146 ireq->i_val = IEEE80211_AUTH_OPEN;
2147 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2148 AN_AUTHTYPE_SHAREDKEY) {
2149 ireq->i_val = IEEE80211_AUTH_SHARED;
2153 case IEEE80211_IOC_STATIONNAME:
2154 sc->areq.an_type = AN_RID_ACTUALCFG;
2155 if (an_read_record(sc,
2156 (struct an_ltv_gen *)&sc->areq)) {
2160 ireq->i_len = sizeof(config->an_nodename);
2161 tmpptr = config->an_nodename;
2162 bzero(tmpstr, IEEE80211_NWID_LEN);
2163 bcopy(tmpptr, tmpstr, ireq->i_len);
2164 error = copyout(tmpstr, ireq->i_data,
2165 IEEE80211_NWID_LEN);
2167 case IEEE80211_IOC_CHANNEL:
2168 sc->areq.an_type = AN_RID_STATUS;
2169 if (an_read_record(sc,
2170 (struct an_ltv_gen *)&sc->areq)) {
2174 ireq->i_val = status->an_cur_channel;
2176 case IEEE80211_IOC_POWERSAVE:
2177 sc->areq.an_type = AN_RID_ACTUALCFG;
2178 if (an_read_record(sc,
2179 (struct an_ltv_gen *)&sc->areq)) {
2183 if (config->an_psave_mode == AN_PSAVE_NONE) {
2184 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2185 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2186 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2187 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2188 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2189 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2190 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2194 case IEEE80211_IOC_POWERSAVESLEEP:
2195 sc->areq.an_type = AN_RID_ACTUALCFG;
2196 if (an_read_record(sc,
2197 (struct an_ltv_gen *)&sc->areq)) {
2201 ireq->i_val = config->an_listen_interval;
2206 if ((error = suser(td)))
2208 sc->areq.an_len = sizeof(sc->areq);
2210 * We need a config structure for everything but the WEP
2211 * key management and SSIDs so we get it now so avoid
2212 * duplicating this code every time.
2214 if (ireq->i_type != IEEE80211_IOC_SSID &&
2215 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2216 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2217 sc->areq.an_type = AN_RID_GENCONFIG;
2218 if (an_read_record(sc,
2219 (struct an_ltv_gen *)&sc->areq)) {
2224 switch (ireq->i_type) {
2225 case IEEE80211_IOC_SSID:
2226 sc->areq.an_type = AN_RID_SSIDLIST;
2227 if (an_read_record(sc,
2228 (struct an_ltv_gen *)&sc->areq)) {
2232 if (ireq->i_len > IEEE80211_NWID_LEN) {
2236 switch (ireq->i_val) {
2238 error = copyin(ireq->i_data,
2239 ssids->an_ssid1, ireq->i_len);
2240 ssids->an_ssid1_len = ireq->i_len;
2243 error = copyin(ireq->i_data,
2244 ssids->an_ssid2, ireq->i_len);
2245 ssids->an_ssid2_len = ireq->i_len;
2248 error = copyin(ireq->i_data,
2249 ssids->an_ssid3, ireq->i_len);
2250 ssids->an_ssid3_len = ireq->i_len;
2257 case IEEE80211_IOC_WEP:
2258 switch (ireq->i_val) {
2259 case IEEE80211_WEP_OFF:
2260 config->an_authtype &=
2261 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2262 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2264 case IEEE80211_WEP_ON:
2265 config->an_authtype |=
2266 AN_AUTHTYPE_PRIVACY_IN_USE;
2267 config->an_authtype &=
2268 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2270 case IEEE80211_WEP_MIXED:
2271 config->an_authtype |=
2272 AN_AUTHTYPE_PRIVACY_IN_USE |
2273 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2280 case IEEE80211_IOC_WEPKEY:
2281 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2286 error = copyin(ireq->i_data, tmpstr, 13);
2290 * Map the 9th key into the home mode
2291 * since that is how it is stored on
2294 bzero(&sc->areq, sizeof(struct an_ltv_key));
2295 sc->areq.an_len = sizeof(struct an_ltv_key);
2296 key->mac[0] = 1; /* The others are 0. */
2297 if (ireq->i_val < 4) {
2298 sc->areq.an_type = AN_RID_WEP_TEMP;
2299 key->kindex = ireq->i_val;
2301 sc->areq.an_type = AN_RID_WEP_PERM;
2302 key->kindex = ireq->i_val - 4;
2304 key->klen = ireq->i_len;
2305 bcopy(tmpstr, key->key, key->klen);
2307 case IEEE80211_IOC_WEPTXKEY:
2308 if (ireq->i_val < 0 || ireq->i_val > 4) {
2314 * Map the 5th key into the home mode
2315 * since that is how it is stored on
2318 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2319 sc->areq.an_type = AN_RID_ACTUALCFG;
2320 if (an_read_record(sc,
2321 (struct an_ltv_gen *)&sc->areq)) {
2325 if (ireq->i_val == 4) {
2326 config->an_home_product |= AN_HOME_NETWORK;
2329 config->an_home_product &= ~AN_HOME_NETWORK;
2332 sc->an_config.an_home_product
2333 = config->an_home_product;
2335 /* update configuration */
2338 bzero(&sc->areq, sizeof(struct an_ltv_key));
2339 sc->areq.an_len = sizeof(struct an_ltv_key);
2340 sc->areq.an_type = AN_RID_WEP_PERM;
2341 key->kindex = 0xffff;
2342 key->mac[0] = ireq->i_val;
2344 case IEEE80211_IOC_AUTHMODE:
2345 switch (ireq->i_val) {
2346 case IEEE80211_AUTH_NONE:
2347 config->an_authtype = AN_AUTHTYPE_NONE |
2348 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2350 case IEEE80211_AUTH_OPEN:
2351 config->an_authtype = AN_AUTHTYPE_OPEN |
2352 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2354 case IEEE80211_AUTH_SHARED:
2355 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2356 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2362 case IEEE80211_IOC_STATIONNAME:
2363 if (ireq->i_len > 16) {
2367 bzero(config->an_nodename, 16);
2368 error = copyin(ireq->i_data,
2369 config->an_nodename, ireq->i_len);
2371 case IEEE80211_IOC_CHANNEL:
2373 * The actual range is 1-14, but if you set it
2374 * to 0 you get the default so we let that work
2377 if (ireq->i_val < 0 || ireq->i_val >14) {
2381 config->an_ds_channel = ireq->i_val;
2383 case IEEE80211_IOC_POWERSAVE:
2384 switch (ireq->i_val) {
2385 case IEEE80211_POWERSAVE_OFF:
2386 config->an_psave_mode = AN_PSAVE_NONE;
2388 case IEEE80211_POWERSAVE_CAM:
2389 config->an_psave_mode = AN_PSAVE_CAM;
2391 case IEEE80211_POWERSAVE_PSP:
2392 config->an_psave_mode = AN_PSAVE_PSP;
2394 case IEEE80211_POWERSAVE_PSP_CAM:
2395 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2402 case IEEE80211_IOC_POWERSAVESLEEP:
2403 config->an_listen_interval = ireq->i_val;
2408 an_setdef(sc, &sc->areq);
2422 struct an_softc *sc;
2431 for (i = 0; i < AN_TX_RING_CNT; i++) {
2432 if (an_alloc_nicmem(sc, 1518 +
2435 sc->an_rdata.an_tx_fids[i] = id;
2436 sc->an_rdata.an_tx_ring[i] = 0;
2440 sc->an_rdata.an_tx_prod = 0;
2441 sc->an_rdata.an_tx_cons = 0;
2442 sc->an_rdata.an_tx_empty = 1;
2451 struct an_softc *sc = xsc;
2452 struct ifnet *ifp = &sc->arpcom.ac_if;
2462 if (ifp->if_flags & IFF_RUNNING)
2465 sc->an_associated = 0;
2467 /* Allocate the TX buffers */
2468 if (an_init_tx_ring(sc)) {
2471 an_init_mpi350_desc(sc);
2472 if (an_init_tx_ring(sc)) {
2473 printf("an%d: tx buffer allocation "
2474 "failed\n", sc->an_unit);
2480 /* Set our MAC address. */
2481 bcopy((char *)&sc->arpcom.ac_enaddr,
2482 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2484 if (ifp->if_flags & IFF_BROADCAST)
2485 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2487 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2489 if (ifp->if_flags & IFF_MULTICAST)
2490 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2492 if (ifp->if_flags & IFF_PROMISC) {
2493 if (sc->an_monitor & AN_MONITOR) {
2494 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2495 sc->an_config.an_rxmode |=
2496 AN_RXMODE_80211_MONITOR_ANYBSS |
2497 AN_RXMODE_NO_8023_HEADER;
2499 sc->an_config.an_rxmode |=
2500 AN_RXMODE_80211_MONITOR_CURBSS |
2501 AN_RXMODE_NO_8023_HEADER;
2506 if (sc->an_have_rssimap)
2507 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2509 /* Set the ssid list */
2510 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2511 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2512 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2513 printf("an%d: failed to set ssid list\n", sc->an_unit);
2518 /* Set the AP list */
2519 sc->an_aplist.an_type = AN_RID_APLIST;
2520 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2521 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2522 printf("an%d: failed to set AP list\n", sc->an_unit);
2527 /* Set the configuration in the NIC */
2528 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2529 sc->an_config.an_type = AN_RID_GENCONFIG;
2530 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2531 printf("an%d: failed to set configuration\n", sc->an_unit);
2536 /* Enable the MAC */
2537 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2538 printf("an%d: failed to enable MAC\n", sc->an_unit);
2543 if (ifp->if_flags & IFF_PROMISC)
2544 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2546 /* enable interrupts */
2547 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
2549 ifp->if_flags |= IFF_RUNNING;
2550 ifp->if_flags &= ~IFF_OACTIVE;
2552 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
2562 struct an_softc *sc;
2563 struct mbuf *m0 = NULL;
2564 struct an_txframe_802_3 tx_frame_802_3;
2565 struct ether_header *eh;
2567 unsigned char txcontrol;
2568 struct an_card_tx_desc an_tx_desc;
2577 if (ifp->if_flags & IFF_OACTIVE)
2580 if (!sc->an_associated)
2583 /* We can't send in monitor mode so toss any attempts. */
2584 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2586 IF_DEQUEUE(&ifp->if_snd, m0);
2594 idx = sc->an_rdata.an_tx_prod;
2597 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2599 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2600 IF_DEQUEUE(&ifp->if_snd, m0);
2604 id = sc->an_rdata.an_tx_fids[idx];
2605 eh = mtod(m0, struct ether_header *);
2607 bcopy((char *)&eh->ether_dhost,
2608 (char *)&tx_frame_802_3.an_tx_dst_addr,
2610 bcopy((char *)&eh->ether_shost,
2611 (char *)&tx_frame_802_3.an_tx_src_addr,
2614 /* minus src/dest mac & type */
2615 tx_frame_802_3.an_tx_802_3_payload_len =
2616 m0->m_pkthdr.len - 12;
2618 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2619 tx_frame_802_3.an_tx_802_3_payload_len,
2620 (caddr_t)&sc->an_txbuf);
2622 txcontrol = AN_TXCTL_8023;
2623 /* write the txcontrol only */
2624 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2628 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2629 sizeof(struct an_txframe_802_3));
2631 /* in mbuf header type is just before payload */
2632 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2633 tx_frame_802_3.an_tx_802_3_payload_len);
2636 * If there's a BPF listner, bounce a copy of
2637 * this frame to him.
2645 sc->an_rdata.an_tx_ring[idx] = id;
2646 if (an_cmd(sc, AN_CMD_TX, id))
2647 printf("an%d: xmit failed\n", sc->an_unit);
2649 AN_INC(idx, AN_TX_RING_CNT);
2651 } else { /* MPI-350 */
2652 while (sc->an_rdata.an_tx_empty ||
2653 idx != sc->an_rdata.an_tx_cons) {
2654 IF_DEQUEUE(&ifp->if_snd, m0);
2658 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2660 eh = mtod(m0, struct ether_header *);
2662 /* DJA optimize this to limit bcopy */
2663 bcopy((char *)&eh->ether_dhost,
2664 (char *)&tx_frame_802_3.an_tx_dst_addr,
2666 bcopy((char *)&eh->ether_shost,
2667 (char *)&tx_frame_802_3.an_tx_src_addr,
2670 /* minus src/dest mac & type */
2671 tx_frame_802_3.an_tx_802_3_payload_len =
2672 m0->m_pkthdr.len - 12;
2674 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2675 tx_frame_802_3.an_tx_802_3_payload_len,
2676 (caddr_t)&sc->an_txbuf);
2678 txcontrol = AN_TXCTL_8023;
2679 /* write the txcontrol only */
2680 bcopy((caddr_t)&txcontrol, &buf[0x08],
2684 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2685 sizeof(struct an_txframe_802_3));
2687 /* in mbuf header type is just before payload */
2688 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2689 tx_frame_802_3.an_tx_802_3_payload_len);
2692 bzero(&an_tx_desc, sizeof(an_tx_desc));
2693 an_tx_desc.an_offset = 0;
2694 an_tx_desc.an_eoc = 1;
2695 an_tx_desc.an_valid = 1;
2696 an_tx_desc.an_len = 0x44 +
2697 tx_frame_802_3.an_tx_802_3_payload_len;
2698 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2699 ptr = (u_int8_t*)&an_tx_desc;
2700 for (i = 0; i < sizeof(an_tx_desc); i++) {
2701 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2706 * If there's a BPF listner, bounce a copy of
2707 * this frame to him.
2715 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2717 AN_INC(idx, AN_MAX_TX_DESC);
2718 sc->an_rdata.an_tx_empty = 0;
2723 ifp->if_flags |= IFF_OACTIVE;
2725 sc->an_rdata.an_tx_prod = idx;
2728 * Set a timeout in case the chip goes out to lunch.
2737 struct an_softc *sc;
2750 ifp = &sc->arpcom.ac_if;
2752 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2753 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2754 an_cmd(sc, AN_CMD_DISABLE, 0);
2756 for (i = 0; i < AN_TX_RING_CNT; i++)
2757 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2759 untimeout(an_stats_update, sc, sc->an_stat_ch);
2761 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2763 if (sc->an_flash_buffer) {
2764 free(sc->an_flash_buffer, M_DEVBUF);
2765 sc->an_flash_buffer = NULL;
2777 struct an_softc *sc;
2788 printf("an%d: device timeout\n", sc->an_unit);
2792 an_init_mpi350_desc(sc);
2805 struct an_softc *sc;
2807 sc = device_get_softc(dev);
2817 struct an_softc *sc;
2821 sc = device_get_softc(dev);
2822 ifp = &sc->arpcom.ac_if;
2826 an_init_mpi350_desc(sc);
2829 /* Recovery temporary keys */
2830 for (i = 0; i < 4; i++) {
2831 sc->areq.an_type = AN_RID_WEP_TEMP;
2832 sc->areq.an_len = sizeof(struct an_ltv_key);
2833 bcopy(&sc->an_temp_keys[i],
2834 &sc->areq, sizeof(struct an_ltv_key));
2835 an_setdef(sc, &sc->areq);
2838 if (ifp->if_flags & IFF_UP)
2845 /* Aironet signal strength cache code.
2846 * store signal/noise/quality on per MAC src basis in
2847 * a small fixed cache. The cache wraps if > MAX slots
2848 * used. The cache may be zeroed out to start over.
2849 * Two simple filters exist to reduce computation:
2850 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2851 * to ignore some packets. It defaults to ip only.
2852 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2853 * 2. multicast/broadcast only. This may be used to
2854 * ignore unicast packets and only cache signal strength
2855 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2856 * beacons and not unicast traffic.
2858 * The cache stores (MAC src(index), IP src (major clue), signal,
2861 * No apologies for storing IP src here. It's easy and saves much
2862 * trouble elsewhere. The cache is assumed to be INET dependent,
2863 * although it need not be.
2865 * Note: the Aironet only has a single byte of signal strength value
2866 * in the rx frame header, and it's not scaled to anything sensible.
2867 * This is kind of lame, but it's all we've got.
2870 #ifdef documentation
2872 int an_sigitems; /* number of cached entries */
2873 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2874 int an_nextitem; /* index/# of entries */
2879 /* control variables for cache filtering. Basic idea is
2880 * to reduce cost (e.g., to only Mobile-IP agent beacons
2881 * which are broadcast or multicast). Still you might
2882 * want to measure signal strength anth unicast ping packets
2883 * on a pt. to pt. ant. setup.
2885 /* set true if you want to limit cache items to broadcast/mcast
2886 * only packets (not unicast). Useful for mobile-ip beacons which
2887 * are broadcast/multicast at network layer. Default is all packets
2888 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2890 static int an_cache_mcastonly = 0;
2891 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2892 &an_cache_mcastonly, 0, "");
2894 /* set true if you want to limit cache items to IP packets only
2896 static int an_cache_iponly = 1;
2897 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2898 &an_cache_iponly, 0, "");
2901 * an_cache_store, per rx packet store signal
2902 * strength in MAC (src) indexed cache.
2905 an_cache_store (sc, eh, m, rx_rssi, rx_quality)
2906 struct an_softc *sc;
2907 struct ether_header *eh;
2910 u_int8_t rx_quality;
2914 static int cache_slot = 0; /* use this cache entry */
2915 static int wrapindex = 0; /* next "free" cache entry */
2920 * 2. configurable filter to throw out unicast packets,
2921 * keep multicast only.
2924 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
2928 /* filter for ip packets only
2930 if ( an_cache_iponly && !type_ipv4) {
2934 /* filter for broadcast/multicast only
2936 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2941 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
2942 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2945 /* find the ip header. we want to store the ip_src
2949 ip = mtod(m, struct ip *);
2952 /* do a linear search for a matching MAC address
2953 * in the cache table
2954 * . MAC address is 6 bytes,
2955 * . var w_nextitem holds total number of entries already cached
2957 for (i = 0; i < sc->an_nextitem; i++) {
2958 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2960 * so we already have this entry,
2967 /* did we find a matching mac address?
2968 * if yes, then overwrite a previously existing cache entry
2970 if (i < sc->an_nextitem ) {
2973 /* else, have a new address entry,so
2974 * add this new entry,
2975 * if table full, then we need to replace LRU entry
2979 /* check for space in cache table
2980 * note: an_nextitem also holds number of entries
2981 * added in the cache table
2983 if ( sc->an_nextitem < MAXANCACHE ) {
2984 cache_slot = sc->an_nextitem;
2986 sc->an_sigitems = sc->an_nextitem;
2988 /* no space found, so simply wrap anth wrap index
2989 * and "zap" the next entry
2992 if (wrapindex == MAXANCACHE) {
2995 cache_slot = wrapindex++;
2999 /* invariant: cache_slot now points at some slot
3002 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3003 log(LOG_ERR, "an_cache_store, bad index: %d of "
3004 "[0..%d], gross cache error\n",
3005 cache_slot, MAXANCACHE);
3009 /* store items in cache
3010 * .ip source address
3015 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3017 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3020 switch (an_cache_mode) {
3022 if (sc->an_have_rssimap) {
3023 sc->an_sigcache[cache_slot].signal =
3024 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3025 sc->an_sigcache[cache_slot].quality =
3026 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3028 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3029 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3033 if (sc->an_have_rssimap) {
3034 sc->an_sigcache[cache_slot].signal =
3035 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3036 sc->an_sigcache[cache_slot].quality =
3037 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3041 if (rx_quality > 100)
3043 sc->an_sigcache[cache_slot].signal = rx_rssi;
3044 sc->an_sigcache[cache_slot].quality = rx_quality;
3048 sc->an_sigcache[cache_slot].signal = rx_rssi;
3049 sc->an_sigcache[cache_slot].quality = rx_quality;
3053 sc->an_sigcache[cache_slot].noise = 0;
3060 an_media_change(ifp)
3063 struct an_softc *sc = ifp->if_softc;
3064 struct an_ltv_genconfig *cfg;
3065 int otype = sc->an_config.an_opmode;
3066 int orate = sc->an_tx_rate;
3068 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3069 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC;
3071 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION;
3073 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
3074 case IFM_IEEE80211_DS1:
3075 sc->an_tx_rate = AN_RATE_1MBPS;
3077 case IFM_IEEE80211_DS2:
3078 sc->an_tx_rate = AN_RATE_2MBPS;
3080 case IFM_IEEE80211_DS5:
3081 sc->an_tx_rate = AN_RATE_5_5MBPS;
3083 case IFM_IEEE80211_DS11:
3084 sc->an_tx_rate = AN_RATE_11MBPS;
3091 if (orate != sc->an_tx_rate) {
3092 /* Read the current configuration */
3093 sc->an_config.an_type = AN_RID_GENCONFIG;
3094 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3095 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3096 cfg = &sc->an_config;
3098 /* clear other rates and set the only one we want */
3099 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3100 cfg->an_rates[0] = sc->an_tx_rate;
3102 /* Save the new rate */
3103 sc->an_config.an_type = AN_RID_GENCONFIG;
3104 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3107 if (otype != sc->an_config.an_opmode ||
3108 orate != sc->an_tx_rate)
3115 an_media_status(ifp, imr)
3117 struct ifmediareq *imr;
3119 struct an_ltv_status status;
3120 struct an_softc *sc = ifp->if_softc;
3122 status.an_len = sizeof(status);
3123 status.an_type = AN_RID_STATUS;
3124 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3125 /* If the status read fails, just lie. */
3126 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3127 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3130 if (sc->an_tx_rate == 0) {
3131 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3132 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3133 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3134 switch (status.an_current_tx_rate) {
3136 imr->ifm_active |= IFM_IEEE80211_DS1;
3139 imr->ifm_active |= IFM_IEEE80211_DS2;
3141 case AN_RATE_5_5MBPS:
3142 imr->ifm_active |= IFM_IEEE80211_DS5;
3144 case AN_RATE_11MBPS:
3145 imr->ifm_active |= IFM_IEEE80211_DS11;
3149 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3152 imr->ifm_status = IFM_AVALID;
3153 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3154 imr->ifm_status |= IFM_ACTIVE;
3157 /********************** Cisco utility support routines *************/
3160 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3165 readrids(ifp, l_ioctl)
3167 struct aironet_ioctl *l_ioctl;
3170 struct an_softc *sc;
3172 switch (l_ioctl->command) {
3174 rid = AN_RID_CAPABILITIES;
3177 rid = AN_RID_GENCONFIG;
3180 rid = AN_RID_SSIDLIST;
3183 rid = AN_RID_APLIST;
3186 rid = AN_RID_DRVNAME;
3189 rid = AN_RID_ENCAPPROTO;
3192 rid = AN_RID_WEP_TEMP;
3195 rid = AN_RID_WEP_PERM;
3198 rid = AN_RID_STATUS;
3201 rid = AN_RID_32BITS_DELTA;
3204 rid = AN_RID_32BITS_CUM;
3211 if (rid == 999) /* Is bad command */
3215 sc->areq.an_len = AN_MAX_DATALEN;
3216 sc->areq.an_type = rid;
3218 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3220 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3222 /* the data contains the length at first */
3223 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3224 sizeof(sc->areq.an_len))) {
3227 /* Just copy the data back */
3228 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3236 writerids(ifp, l_ioctl)
3238 struct aironet_ioctl *l_ioctl;
3240 struct an_softc *sc;
3245 command = l_ioctl->command;
3249 rid = AN_RID_SSIDLIST;
3252 rid = AN_RID_CAPABILITIES;
3255 rid = AN_RID_APLIST;
3258 rid = AN_RID_GENCONFIG;
3261 an_cmd(sc, AN_CMD_ENABLE, 0);
3265 an_cmd(sc, AN_CMD_DISABLE, 0);
3270 * This command merely clears the counts does not actually
3271 * store any data only reads rid. But as it changes the cards
3272 * state, I put it in the writerid routines.
3275 rid = AN_RID_32BITS_DELTACLR;
3277 sc->areq.an_len = AN_MAX_DATALEN;
3278 sc->areq.an_type = rid;
3280 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3281 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3283 /* the data contains the length at first */
3284 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3285 sizeof(sc->areq.an_len))) {
3288 /* Just copy the data */
3289 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3296 rid = AN_RID_WEP_TEMP;
3299 rid = AN_RID_WEP_PERM;
3302 rid = AN_RID_LEAPUSERNAME;
3305 rid = AN_RID_LEAPPASSWORD;
3312 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3314 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3315 sc->areq.an_type = rid;
3317 /* Just copy the data back */
3318 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3321 an_cmd(sc, AN_CMD_DISABLE, 0);
3322 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3323 an_cmd(sc, AN_CMD_ENABLE, 0);
3330 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3334 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3335 #define FLASH_COMMAND 0x7e7e
3336 #define FLASH_SIZE 32 * 1024
3342 struct an_softc *sc = ifp->if_softc;
3344 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3345 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3346 AN_EV_CLR_STUCK_BUSY);
3353 * Wait for busy completion from card wait for delay uSec's Return true for
3354 * success meaning command reg is clear
3362 int statword = 0xffff;
3364 struct an_softc *sc = ifp->if_softc;
3366 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3369 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3371 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3376 return 0 == (AN_CMD_BUSY & statword);
3380 * STEP 1) Disable MAC and do soft reset on card.
3388 struct an_softc *sc = ifp->if_softc;
3392 an_cmd(sc, AN_CMD_DISABLE, 0);
3394 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3395 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3396 sc->an_unit, status);
3399 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3401 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3404 if (!(status = WaitBusy(ifp, 100))) {
3405 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3406 sc->an_unit, status);
3413 * STEP 2) Put the card in legendary flash mode
3421 struct an_softc *sc = ifp->if_softc;
3423 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3424 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3425 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3426 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3429 * mdelay(500); // 500ms delay
3434 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3435 printf("Waitbusy hang after setflash mode\n");
3442 * Get a character from the card matching matchbyte Step 3)
3446 flashgchar(ifp, matchbyte, dwelltime)
3452 unsigned char rbyte = 0;
3454 struct an_softc *sc = ifp->if_softc;
3458 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3460 if (dwelltime && !(0x8000 & rchar)) {
3465 rbyte = 0xff & rchar;
3467 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3468 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3472 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3474 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3476 } while (dwelltime > 0);
3481 * Put character to SWS0 wait for dwelltime x 50us for echo .
3485 flashpchar(ifp, byte, dwelltime)
3491 int pollbusy, waittime;
3492 struct an_softc *sc = ifp->if_softc;
3499 waittime = dwelltime;
3502 * Wait for busy bit d15 to go false indicating buffer empty
3505 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3507 if (pollbusy & 0x8000) {
3514 while (waittime >= 0);
3516 /* timeout for busy clear wait */
3518 if (waittime <= 0) {
3519 printf("an%d: flash putchar busywait timeout! \n",
3524 * Port is clear now write byte and wait for it to echo back
3527 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3530 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3531 } while (dwelltime >= 0 && echo != byte);
3534 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3536 return echo == byte;
3540 * Transfer 32k of firmware data from user buffer to our buffer and send to
3548 unsigned short *bufp;
3550 struct an_softc *sc = ifp->if_softc;
3554 bufp = sc->an_flash_buffer;
3557 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3558 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3560 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3561 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3564 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3565 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3566 ((u_int32_t *)bufp)[nwords] & 0xffff);
3570 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3576 * After flashing restart the card.
3584 struct an_softc *sc = ifp->if_softc;
3586 FLASH_DELAY(1024); /* Added 12/7/00 */
3590 FLASH_DELAY(1024); /* Added 12/7/00 */
3595 * Entry point for flash ioclt.
3599 flashcard(ifp, l_ioctl)
3601 struct aironet_ioctl *l_ioctl;
3604 struct an_softc *sc;
3608 printf("an%d: flashing not supported on MPI 350 yet\n",
3612 status = l_ioctl->command;
3614 switch (l_ioctl->command) {
3616 return cmdreset(ifp);
3619 if (sc->an_flash_buffer) {
3620 free(sc->an_flash_buffer, M_DEVBUF);
3621 sc->an_flash_buffer = NULL;
3623 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3624 if (sc->an_flash_buffer)
3625 return setflashmode(ifp);
3629 case AIROFLSHGCHR: /* Get char from aux */
3630 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3631 z = *(int *)&sc->areq;
3632 if ((status = flashgchar(ifp, z, 8000)) == 1)
3637 case AIROFLSHPCHR: /* Send char to card. */
3638 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3639 z = *(int *)&sc->areq;
3640 if ((status = flashpchar(ifp, z, 8000)) == -1)
3645 case AIROFLPUTBUF: /* Send 32k to card */
3646 if (l_ioctl->len > FLASH_SIZE) {
3647 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3648 l_ioctl->len, FLASH_SIZE);
3651 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3653 if ((status = flashputbuf(ifp)) != 0)
3659 if ((status = flashrestart(ifp)) != 0) {
3660 printf("an%d: FLASHRESTART returned %d\n",
3661 sc->an_unit, status);