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 $
36 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
38 * Written by Bill Paul <wpaul@ctr.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City
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/systm.h>
92 #include <sys/sockio.h>
95 #include <sys/kernel.h>
97 #include <sys/ucred.h>
98 #include <sys/socket.h>
100 #include <sys/syslog.h>
102 #include <sys/sysctl.h>
103 #include <machine/clock.h> /* for DELAY */
105 #include <sys/module.h>
106 #include <sys/sysctl.h>
108 #include <machine/bus.h>
109 #include <sys/rman.h>
110 #include <machine/resource.h>
111 #include <sys/malloc.h>
114 #include <net/if_arp.h>
115 #include <net/ethernet.h>
116 #include <net/if_dl.h>
117 #include <net/if_types.h>
118 #include <net/if_ieee80211.h>
119 #include <net/if_media.h>
122 #include <netinet/in.h>
123 #include <netinet/in_systm.h>
124 #include <netinet/in_var.h>
125 #include <netinet/ip.h>
130 #include <machine/md_var.h>
132 #include <dev/an/if_aironet_ieee.h>
133 #include <dev/an/if_anreg.h>
136 static const char rcsid[] =
137 "$FreeBSD: src/sys/dev/an/if_an.c,v 1.2.2.13 2003/02/11 03:32:48 ambrisko Exp $";
140 /* These are global because we need them in sys/pci/if_an_p.c. */
141 static void an_reset __P((struct an_softc *));
142 static int __P(an_init_mpi350_desc (struct an_softc *));
143 static int an_ioctl __P((struct ifnet *, u_long, caddr_t));
144 static void an_init __P((void *));
145 static int an_init_tx_ring __P((struct an_softc *));
146 static void an_start __P((struct ifnet *));
147 static void an_watchdog __P((struct ifnet *));
148 static void an_rxeof __P((struct an_softc *));
149 static void an_txeof __P((struct an_softc *, int));
151 static void an_promisc __P((struct an_softc *, int));
152 static int an_cmd __P((struct an_softc *, int, int));
153 static int an_cmd_struct __P((struct an_softc *, struct an_command *,
155 static int an_read_record __P((struct an_softc *, struct an_ltv_gen *));
156 static int an_write_record __P((struct an_softc *, struct an_ltv_gen *));
157 static int an_read_data __P((struct an_softc *, int,
159 static int an_write_data __P((struct an_softc *, int,
161 static int an_seek __P((struct an_softc *, int, int, int));
162 static int an_alloc_nicmem __P((struct an_softc *, int, int *));
163 static int an_dma_malloc __P((struct an_softc *, bus_size_t,
164 struct an_dma_alloc *, int));
165 static void an_dma_free __P((struct an_softc *,
166 struct an_dma_alloc *));
167 static void an_dma_malloc_cb __P((void *, bus_dma_segment_t *, int, int));
168 static void an_stats_update __P((void *));
169 static void an_setdef __P((struct an_softc *, struct an_req *));
171 static void an_cache_store __P((struct an_softc *, struct ether_header *,
172 struct mbuf *, u_int8_t, u_int8_t));
175 /* function definitions for use with the Cisco's Linux configuration
179 static int readrids __P((struct ifnet*, struct aironet_ioctl*));
180 static int writerids __P((struct ifnet*, struct aironet_ioctl*));
181 static int flashcard __P((struct ifnet*, struct aironet_ioctl*));
183 static int cmdreset __P((struct ifnet *));
184 static int setflashmode __P((struct ifnet *));
185 static int flashgchar __P((struct ifnet *,int,int));
186 static int flashpchar __P((struct ifnet *,int,int));
187 static int flashputbuf __P((struct ifnet *));
188 static int flashrestart __P((struct ifnet *));
189 static int WaitBusy __P((struct ifnet *, int));
190 static int unstickbusy __P((struct ifnet *));
192 static void an_dump_record __P((struct an_softc *,struct an_ltv_gen *,
195 static int an_media_change __P((struct ifnet *));
196 static void an_media_status __P((struct ifnet *, struct ifmediareq *));
198 static int an_dump = 0;
199 static int an_cache_mode = 0;
205 static char an_conf[256];
206 static char an_conf_cache[256];
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 ifp->if_unit = sc->an_unit = unit;
754 ifp->if_mtu = ETHERMTU;
755 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
756 ifp->if_ioctl = an_ioctl;
757 ifp->if_output = ether_output;
758 ifp->if_start = an_start;
759 ifp->if_watchdog = an_watchdog;
760 ifp->if_init = an_init;
761 ifp->if_baudrate = 10000000;
762 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
764 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
765 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
766 sizeof(AN_DEFAULT_NODENAME) - 1);
768 bzero(sc->an_ssidlist.an_ssid1, sizeof(sc->an_ssidlist.an_ssid1));
769 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_ssid1,
770 sizeof(AN_DEFAULT_NETNAME) - 1);
771 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME);
773 sc->an_config.an_opmode =
774 AN_OPMODE_INFRASTRUCTURE_STATION;
777 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
779 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
780 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
781 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
782 IFM_IEEE80211_ADHOC, 0), 0);
783 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
784 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
785 IFM_IEEE80211_ADHOC, 0), 0);
786 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
787 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
788 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
789 IFM_IEEE80211_ADHOC, 0), 0);
790 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
792 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
793 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
794 IFM_IEEE80211_ADHOC, 0), 0);
795 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
797 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
798 IFM_IEEE80211_ADHOC, 0), 0);
799 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
801 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
805 * Call MI attach routine.
807 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
808 callout_handle_init(&sc->an_stat_ch);
818 struct ether_header *eh;
819 struct ieee80211_frame *ih;
820 struct an_rxframe rx_frame;
821 struct an_rxframe_802_3 rx_frame_802_3;
823 int len, id, error = 0, i, count = 0;
824 int ieee80211_header_len;
827 struct an_card_rx_desc an_rx_desc;
830 ifp = &sc->arpcom.ac_if;
833 id = CSR_READ_2(sc, AN_RX_FID);
835 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
836 /* read raw 802.11 packet */
837 bpf_buf = sc->buf_802_11;
840 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
847 * skip beacon by default since this increases the
851 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
852 (rx_frame.an_frame_ctl &
853 IEEE80211_FC0_SUBTYPE_BEACON)) {
857 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
858 len = rx_frame.an_rx_payload_len
860 /* Check for insane frame length */
861 if (len > sizeof(sc->buf_802_11)) {
862 printf("an%d: oversized packet "
863 "received (%d, %d)\n",
864 sc->an_unit, len, MCLBYTES);
869 bcopy((char *)&rx_frame,
870 bpf_buf, sizeof(rx_frame));
872 error = an_read_data(sc, id, sizeof(rx_frame),
873 (caddr_t)bpf_buf+sizeof(rx_frame),
874 rx_frame.an_rx_payload_len);
876 fc1=rx_frame.an_frame_ctl >> 8;
877 ieee80211_header_len =
878 sizeof(struct ieee80211_frame);
879 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
880 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
881 ieee80211_header_len += ETHER_ADDR_LEN;
884 len = rx_frame.an_rx_payload_len
885 + ieee80211_header_len;
886 /* Check for insane frame length */
887 if (len > sizeof(sc->buf_802_11)) {
888 printf("an%d: oversized packet "
889 "received (%d, %d)\n",
890 sc->an_unit, len, MCLBYTES);
895 ih = (struct ieee80211_frame *)bpf_buf;
897 bcopy((char *)&rx_frame.an_frame_ctl,
898 (char *)ih, ieee80211_header_len);
900 error = an_read_data(sc, id, sizeof(rx_frame) +
902 (caddr_t)ih +ieee80211_header_len,
903 rx_frame.an_rx_payload_len);
905 /* dump raw 802.11 packet to bpf and skip ip stack */
906 if (ifp->if_bpf != NULL) {
907 bpf_tap(ifp, bpf_buf, len);
910 MGETHDR(m, M_NOWAIT, MT_DATA);
916 if (!(m->m_flags & M_EXT)) {
921 m->m_pkthdr.rcvif = ifp;
922 /* Read Ethernet encapsulated packet */
925 /* Read NIC frame header */
926 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
932 /* Read in the 802_3 frame header */
933 if (an_read_data(sc, id, 0x34,
934 (caddr_t)&rx_frame_802_3,
935 sizeof(rx_frame_802_3))) {
939 if (rx_frame_802_3.an_rx_802_3_status != 0) {
943 /* Check for insane frame length */
944 len = rx_frame_802_3.an_rx_802_3_payload_len;
945 if (len > sizeof(sc->buf_802_11)) {
946 printf("an%d: oversized packet "
947 "received (%d, %d)\n",
948 sc->an_unit, len, MCLBYTES);
952 m->m_pkthdr.len = m->m_len =
953 rx_frame_802_3.an_rx_802_3_payload_len + 12;
955 eh = mtod(m, struct ether_header *);
957 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
958 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
959 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
960 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
962 /* in mbuf header type is just before payload */
963 error = an_read_data(sc, id, 0x44,
964 (caddr_t)&(eh->ether_type),
965 rx_frame_802_3.an_rx_802_3_payload_len);
974 /* Receive packet. */
975 m_adj(m, sizeof(struct ether_header));
977 an_cache_store(sc, eh, m,
978 rx_frame.an_rx_signal_strength,
981 ether_input(ifp, eh, m);
984 } else { /* MPI-350 */
985 for (count = 0; count < AN_MAX_RX_DESC; count++){
986 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
987 ((u_int32_t*)&an_rx_desc)[i]
988 = CSR_MEM_AUX_READ_4(sc,
990 + (count * sizeof(an_rx_desc))
993 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
994 buf = sc->an_rx_buffer[count].an_dma_vaddr;
996 MGETHDR(m, M_NOWAIT, MT_DATA);
1001 MCLGET(m, M_NOWAIT);
1002 if (!(m->m_flags & M_EXT)) {
1007 m->m_pkthdr.rcvif = ifp;
1008 /* Read Ethernet encapsulated packet */
1011 * No ANCACHE support since we just get back
1012 * an Ethernet packet no 802.11 info
1016 /* Read NIC frame header */
1017 bcopy(buf, (caddr_t)&rx_frame,
1021 /* Check for insane frame length */
1022 len = an_rx_desc.an_len + 12;
1023 if (len > MCLBYTES) {
1024 printf("an%d: oversized packet "
1025 "received (%d, %d)\n",
1026 sc->an_unit, len, MCLBYTES);
1031 m->m_pkthdr.len = m->m_len =
1032 an_rx_desc.an_len + 12;
1034 eh = mtod(m, struct ether_header *);
1036 bcopy(buf, (char *)eh,
1041 /* Receive packet. */
1042 m_adj(m, sizeof(struct ether_header));
1045 an_cache_store(sc, eh, m,
1046 rx_frame.an_rx_signal_strength,
1050 ether_input(ifp, eh, m);
1052 an_rx_desc.an_valid = 1;
1053 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1054 an_rx_desc.an_done = 0;
1055 an_rx_desc.an_phys =
1056 sc->an_rx_buffer[count].an_dma_paddr;
1058 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1059 CSR_MEM_AUX_WRITE_4(sc,
1061 + (count * sizeof(an_rx_desc))
1063 ((u_int32_t*)&an_rx_desc)[i]);
1066 printf("an%d: Didn't get valid RX packet "
1070 an_rx_desc.an_valid, an_rx_desc.an_len);
1077 an_txeof(sc, status)
1078 struct an_softc *sc;
1084 ifp = &sc->arpcom.ac_if;
1087 ifp->if_flags &= ~IFF_OACTIVE;
1090 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1092 if (status & AN_EV_TX_EXC) {
1097 for (i = 0; i < AN_TX_RING_CNT; i++) {
1098 if (id == sc->an_rdata.an_tx_ring[i]) {
1099 sc->an_rdata.an_tx_ring[i] = 0;
1104 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1105 } else { /* MPI 350 */
1106 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1107 if (sc->an_rdata.an_tx_prod ==
1108 sc->an_rdata.an_tx_cons)
1109 sc->an_rdata.an_tx_empty = 1;
1116 * We abuse the stats updater to check the current NIC status. This
1117 * is important because we don't want to allow transmissions until
1118 * the NIC has synchronized to the current cell (either as the master
1119 * in an ad-hoc group, or as a station connected to an access point).
1122 an_stats_update(xsc)
1125 struct an_softc *sc;
1132 ifp = &sc->arpcom.ac_if;
1134 sc->an_status.an_type = AN_RID_STATUS;
1135 sc->an_status.an_len = sizeof(struct an_ltv_status);
1136 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1138 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1139 sc->an_associated = 1;
1141 sc->an_associated = 0;
1143 /* Don't do this while we're transmitting */
1144 if (ifp->if_flags & IFF_OACTIVE) {
1145 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1150 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1151 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1152 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1154 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1164 struct an_softc *sc;
1168 sc = (struct an_softc*)xsc;
1173 ifp = &sc->arpcom.ac_if;
1175 /* Disable interrupts. */
1176 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1178 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1179 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
1181 if (status & AN_EV_AWAKE) {
1182 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
1185 if (status & AN_EV_LINKSTAT) {
1186 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1187 == AN_LINKSTAT_ASSOCIATED)
1188 sc->an_associated = 1;
1190 sc->an_associated = 0;
1191 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1194 if (status & AN_EV_RX) {
1196 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1199 if (status & AN_EV_TX) {
1200 an_txeof(sc, status);
1201 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1204 if (status & AN_EV_TX_EXC) {
1205 an_txeof(sc, status);
1206 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1209 if (status & AN_EV_ALLOC)
1210 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1212 /* Re-enable interrupts. */
1213 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1215 if ((ifp->if_flags & IFF_UP) && (ifp->if_snd.ifq_head != NULL))
1222 an_cmd_struct(sc, cmd, reply)
1223 struct an_softc *sc;
1224 struct an_command *cmd;
1225 struct an_reply *reply;
1229 for (i = 0; i != AN_TIMEOUT; i++) {
1230 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1235 if( i == AN_TIMEOUT) {
1240 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1241 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1242 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1243 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1245 for (i = 0; i < AN_TIMEOUT; i++) {
1246 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1251 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1252 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1253 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1254 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1256 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1257 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1259 /* Ack the command */
1260 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1262 if (i == AN_TIMEOUT)
1269 an_cmd(sc, cmd, val)
1270 struct an_softc *sc;
1276 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1277 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1278 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1279 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1281 for (i = 0; i < AN_TIMEOUT; i++) {
1282 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1285 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1286 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1290 for (i = 0; i < AN_TIMEOUT; i++) {
1291 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1292 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1293 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1294 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1295 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1299 /* Ack the command */
1300 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1302 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1303 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1305 if (i == AN_TIMEOUT)
1312 * This reset sequence may look a little strange, but this is the
1313 * most reliable method I've found to really kick the NIC in the
1314 * head and force it to reboot correctly.
1318 struct an_softc *sc;
1323 an_cmd(sc, AN_CMD_ENABLE, 0);
1324 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1325 an_cmd(sc, AN_CMD_NOOP2, 0);
1327 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1328 printf("an%d: reset failed\n", sc->an_unit);
1330 an_cmd(sc, AN_CMD_DISABLE, 0);
1336 * Read an LTV record from the NIC.
1339 an_read_record(sc, ltv)
1340 struct an_softc *sc;
1341 struct an_ltv_gen *ltv;
1343 struct an_ltv_gen *an_ltv;
1344 struct an_card_rid_desc an_rid_desc;
1345 struct an_command cmd;
1346 struct an_reply reply;
1351 if (ltv->an_len < 4 || ltv->an_type == 0)
1355 /* Tell the NIC to enter record read mode. */
1356 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1357 printf("an%d: RID access failed\n", sc->an_unit);
1361 /* Seek to the record. */
1362 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1363 printf("an%d: seek to record failed\n", sc->an_unit);
1368 * Read the length and record type and make sure they
1369 * match what we expect (this verifies that we have enough
1370 * room to hold all of the returned data).
1371 * Length includes type but not length.
1373 len = CSR_READ_2(sc, AN_DATA1);
1374 if (len > (ltv->an_len - 2)) {
1375 printf("an%d: record length mismatch -- expected %d, "
1376 "got %d for Rid %x\n", sc->an_unit,
1377 ltv->an_len - 2, len, ltv->an_type);
1378 len = ltv->an_len - 2;
1380 ltv->an_len = len + 2;
1383 /* Now read the data. */
1384 len -= 2; /* skip the type */
1386 for (i = len; i > 1; i -= 2)
1387 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1389 ptr2 = (u_int8_t *)ptr;
1390 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1392 } else { /* MPI-350 */
1393 an_rid_desc.an_valid = 1;
1394 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1395 an_rid_desc.an_rid = 0;
1396 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1397 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1399 bzero(&cmd, sizeof(cmd));
1400 bzero(&reply, sizeof(reply));
1401 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1402 cmd.an_parm0 = ltv->an_type;
1404 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1405 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1406 ((u_int32_t*)&an_rid_desc)[i]);
1408 if (an_cmd_struct(sc, &cmd, &reply)
1409 || reply.an_status & AN_CMD_QUAL_MASK) {
1410 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1411 sc->an_unit, ltv->an_type,
1420 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1421 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1422 an_rid_desc.an_len = an_ltv->an_len;
1425 if (an_rid_desc.an_len > 2)
1426 bcopy(&an_ltv->an_type,
1428 an_rid_desc.an_len - 2);
1429 ltv->an_len = an_rid_desc.an_len + 2;
1433 an_dump_record(sc, ltv, "Read");
1439 * Same as read, except we inject data instead of reading it.
1442 an_write_record(sc, ltv)
1443 struct an_softc *sc;
1444 struct an_ltv_gen *ltv;
1446 struct an_card_rid_desc an_rid_desc;
1447 struct an_command cmd;
1448 struct an_reply reply;
1455 an_dump_record(sc, ltv, "Write");
1458 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1461 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1465 * Length includes type but not length.
1467 len = ltv->an_len - 2;
1468 CSR_WRITE_2(sc, AN_DATA1, len);
1470 len -= 2; /* skip the type */
1472 for (i = len; i > 1; i -= 2)
1473 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1475 ptr2 = (u_int8_t *)ptr;
1476 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1479 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1484 for (i = 0; i != AN_TIMEOUT; i++) {
1485 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1491 if (i == AN_TIMEOUT) {
1495 an_rid_desc.an_valid = 1;
1496 an_rid_desc.an_len = ltv->an_len - 2;
1497 an_rid_desc.an_rid = ltv->an_type;
1498 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1500 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1501 an_rid_desc.an_len);
1503 bzero(&cmd,sizeof(cmd));
1504 bzero(&reply,sizeof(reply));
1505 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1506 cmd.an_parm0 = ltv->an_type;
1508 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1509 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1510 ((u_int32_t*)&an_rid_desc)[i]);
1512 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1513 printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
1514 sc->an_unit, ltv->an_type,
1523 ptr = (u_int16_t *)buf;
1525 if (reply.an_status & AN_CMD_QUAL_MASK) {
1526 printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
1527 sc->an_unit, ltv->an_type,
1541 an_dump_record(sc, ltv, string)
1542 struct an_softc *sc;
1543 struct an_ltv_gen *ltv;
1552 len = ltv->an_len - 4;
1553 printf("an%d: RID %4x, Length %4d, Mode %s\n",
1554 sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
1556 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1557 printf("an%d:\t", sc->an_unit);
1558 bzero(buf,sizeof(buf));
1560 ptr2 = (u_int8_t *)<v->an_val;
1561 for (i = len; i > 0; i--) {
1562 printf("%02x ", *ptr2);
1565 if (temp >= ' ' && temp <= '~')
1567 else if (temp >= 'A' && temp <= 'Z')
1571 if (++count == 16) {
1574 printf("an%d:\t", sc->an_unit);
1575 bzero(buf,sizeof(buf));
1578 for (; count != 16; count++) {
1581 printf(" %s\n",buf);
1586 an_seek(sc, id, off, chan)
1587 struct an_softc *sc;
1603 printf("an%d: invalid data path: %x\n", sc->an_unit, chan);
1607 CSR_WRITE_2(sc, selreg, id);
1608 CSR_WRITE_2(sc, offreg, off);
1610 for (i = 0; i < AN_TIMEOUT; i++) {
1611 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1615 if (i == AN_TIMEOUT)
1622 an_read_data(sc, id, off, buf, len)
1623 struct an_softc *sc;
1633 if (an_seek(sc, id, off, AN_BAP1))
1637 ptr = (u_int16_t *)buf;
1638 for (i = len; i > 1; i -= 2)
1639 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1641 ptr2 = (u_int8_t *)ptr;
1642 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1649 an_write_data(sc, id, off, buf, len)
1650 struct an_softc *sc;
1660 if (an_seek(sc, id, off, AN_BAP0))
1664 ptr = (u_int16_t *)buf;
1665 for (i = len; i > 1; i -= 2)
1666 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1668 ptr2 = (u_int8_t *)ptr;
1669 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1676 * Allocate a region of memory inside the NIC and zero
1680 an_alloc_nicmem(sc, len, id)
1681 struct an_softc *sc;
1687 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1688 printf("an%d: failed to allocate %d bytes on NIC\n",
1693 for (i = 0; i < AN_TIMEOUT; i++) {
1694 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1698 if (i == AN_TIMEOUT)
1701 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1702 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1704 if (an_seek(sc, *id, 0, AN_BAP0))
1707 for (i = 0; i < len / 2; i++)
1708 CSR_WRITE_2(sc, AN_DATA0, 0);
1715 struct an_softc *sc;
1716 struct an_req *areq;
1718 struct sockaddr_dl *sdl;
1721 struct an_ltv_genconfig *cfg;
1722 struct an_ltv_ssidlist *ssid;
1723 struct an_ltv_aplist *ap;
1724 struct an_ltv_gen *sp;
1726 ifp = &sc->arpcom.ac_if;
1728 switch (areq->an_type) {
1729 case AN_RID_GENCONFIG:
1730 cfg = (struct an_ltv_genconfig *)areq;
1732 ifa = ifnet_addrs[ifp->if_index - 1];
1733 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1734 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1736 bcopy((char *)&cfg->an_macaddr, LLADDR(sdl), ETHER_ADDR_LEN);
1738 bcopy((char *)cfg, (char *)&sc->an_config,
1739 sizeof(struct an_ltv_genconfig));
1741 case AN_RID_SSIDLIST:
1742 ssid = (struct an_ltv_ssidlist *)areq;
1743 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1744 sizeof(struct an_ltv_ssidlist));
1747 ap = (struct an_ltv_aplist *)areq;
1748 bcopy((char *)ap, (char *)&sc->an_aplist,
1749 sizeof(struct an_ltv_aplist));
1751 case AN_RID_TX_SPEED:
1752 sp = (struct an_ltv_gen *)areq;
1753 sc->an_tx_rate = sp->an_val;
1755 /* Read the current configuration */
1756 sc->an_config.an_type = AN_RID_GENCONFIG;
1757 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1758 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1759 cfg = &sc->an_config;
1761 /* clear other rates and set the only one we want */
1762 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1763 cfg->an_rates[0] = sc->an_tx_rate;
1765 /* Save the new rate */
1766 sc->an_config.an_type = AN_RID_GENCONFIG;
1767 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1769 case AN_RID_WEP_TEMP:
1770 /* Cache the temp keys */
1772 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1773 sizeof(struct an_ltv_key));
1774 case AN_RID_WEP_PERM:
1775 case AN_RID_LEAPUSERNAME:
1776 case AN_RID_LEAPPASSWORD:
1777 /* Disable the MAC. */
1778 an_cmd(sc, AN_CMD_DISABLE, 0);
1781 an_write_record(sc, (struct an_ltv_gen *)areq);
1783 /* Turn the MAC back on. */
1784 an_cmd(sc, AN_CMD_ENABLE, 0);
1787 case AN_RID_MONITOR_MODE:
1788 cfg = (struct an_ltv_genconfig *)areq;
1790 if (ng_ether_detach_p != NULL)
1791 (*ng_ether_detach_p) (ifp);
1792 sc->an_monitor = cfg->an_len;
1794 if (sc->an_monitor & AN_MONITOR) {
1795 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1796 bpfattach(ifp, DLT_AIRONET_HEADER,
1797 sizeof(struct ether_header));
1799 bpfattach(ifp, DLT_IEEE802_11,
1800 sizeof(struct ether_header));
1803 bpfattach(ifp, DLT_EN10MB,
1804 sizeof(struct ether_header));
1805 if (ng_ether_attach_p != NULL)
1806 (*ng_ether_attach_p) (ifp);
1810 printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
1816 /* Reinitialize the card. */
1824 * Derived from Linux driver to enable promiscious mode.
1828 an_promisc(sc, promisc)
1829 struct an_softc *sc;
1832 if (sc->an_was_monitor)
1835 an_init_mpi350_desc(sc);
1836 if (sc->an_monitor || sc->an_was_monitor)
1839 sc->an_was_monitor = sc->an_monitor;
1840 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1846 an_ioctl(ifp, command, data)
1854 struct an_softc *sc;
1856 struct proc *p = curproc;
1857 struct ieee80211req *ireq;
1858 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1860 struct an_ltv_genconfig *config;
1861 struct an_ltv_key *key;
1862 struct an_ltv_status *status;
1863 struct an_ltv_ssidlist *ssids;
1865 struct aironet_ioctl l_ioctl;
1869 ifr = (struct ifreq *)data;
1870 ireq = (struct ieee80211req *)data;
1872 config = (struct an_ltv_genconfig *)&sc->areq;
1873 key = (struct an_ltv_key *)&sc->areq;
1874 status = (struct an_ltv_status *)&sc->areq;
1875 ssids = (struct an_ltv_ssidlist *)&sc->areq;
1886 error = ether_ioctl(ifp, command, data);
1889 if (ifp->if_flags & IFF_UP) {
1890 if (ifp->if_flags & IFF_RUNNING &&
1891 ifp->if_flags & IFF_PROMISC &&
1892 !(sc->an_if_flags & IFF_PROMISC)) {
1894 } else if (ifp->if_flags & IFF_RUNNING &&
1895 !(ifp->if_flags & IFF_PROMISC) &&
1896 sc->an_if_flags & IFF_PROMISC) {
1901 if (ifp->if_flags & IFF_RUNNING)
1904 sc->an_if_flags = ifp->if_flags;
1909 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1913 /* The Aironet has no multicast filter. */
1917 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1921 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1925 sc->an_sigitems = sc->an_nextitem = 0;
1927 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1928 char *pt = (char *)&sc->areq.an_val;
1929 bcopy((char *)&sc->an_sigitems, (char *)pt,
1932 sc->areq.an_len = sizeof(int) / 2;
1933 bcopy((char *)&sc->an_sigcache, (char *)pt,
1934 sizeof(struct an_sigcache) * sc->an_sigitems);
1935 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1936 sc->an_sigitems) / 2) + 1;
1939 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1943 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1946 if ((error = suser(p)))
1948 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1951 an_setdef(sc, &sc->areq);
1953 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1954 if ((error = suser(p)))
1956 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1957 mode = l_ioctl.command;
1959 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1960 error = readrids(ifp, &l_ioctl);
1961 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1962 error = writerids(ifp, &l_ioctl);
1963 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1964 error = flashcard(ifp, &l_ioctl);
1969 /* copy out the updated command info */
1970 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1973 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1974 if ((error = suser(p)))
1976 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1977 l_ioctl.command = 0;
1979 copyout(&error, l_ioctl.data, sizeof(error));
1983 sc->areq.an_len = sizeof(sc->areq);
1984 /* was that a good idea DJA we are doing a short-cut */
1985 switch (ireq->i_type) {
1986 case IEEE80211_IOC_SSID:
1987 if (ireq->i_val == -1) {
1988 sc->areq.an_type = AN_RID_STATUS;
1989 if (an_read_record(sc,
1990 (struct an_ltv_gen *)&sc->areq)) {
1994 len = status->an_ssidlen;
1995 tmpptr = status->an_ssid;
1996 } else if (ireq->i_val >= 0) {
1997 sc->areq.an_type = AN_RID_SSIDLIST;
1998 if (an_read_record(sc,
1999 (struct an_ltv_gen *)&sc->areq)) {
2003 if (ireq->i_val == 0) {
2004 len = ssids->an_ssid1_len;
2005 tmpptr = ssids->an_ssid1;
2006 } else if (ireq->i_val == 1) {
2007 len = ssids->an_ssid2_len;
2008 tmpptr = ssids->an_ssid2;
2009 } else if (ireq->i_val == 2) {
2010 len = ssids->an_ssid3_len;
2011 tmpptr = ssids->an_ssid3;
2020 if (len > IEEE80211_NWID_LEN) {
2025 bzero(tmpstr, IEEE80211_NWID_LEN);
2026 bcopy(tmpptr, tmpstr, len);
2027 error = copyout(tmpstr, ireq->i_data,
2028 IEEE80211_NWID_LEN);
2030 case IEEE80211_IOC_NUMSSIDS:
2033 case IEEE80211_IOC_WEP:
2034 sc->areq.an_type = AN_RID_ACTUALCFG;
2035 if (an_read_record(sc,
2036 (struct an_ltv_gen *)&sc->areq)) {
2040 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2041 if (config->an_authtype &
2042 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2043 ireq->i_val = IEEE80211_WEP_MIXED;
2045 ireq->i_val = IEEE80211_WEP_ON;
2047 ireq->i_val = IEEE80211_WEP_OFF;
2050 case IEEE80211_IOC_WEPKEY:
2052 * XXX: I'm not entierly convinced this is
2053 * correct, but it's what is implemented in
2054 * ancontrol so it will have to do until we get
2055 * access to actual Cisco code.
2057 if (ireq->i_val < 0 || ireq->i_val > 8) {
2062 if (ireq->i_val < 5) {
2063 sc->areq.an_type = AN_RID_WEP_TEMP;
2064 for (i = 0; i < 5; i++) {
2065 if (an_read_record(sc,
2066 (struct an_ltv_gen *)&sc->areq)) {
2070 if (key->kindex == 0xffff)
2072 if (key->kindex == ireq->i_val)
2074 /* Required to get next entry */
2075 sc->areq.an_type = AN_RID_WEP_PERM;
2080 /* We aren't allowed to read the value of the
2081 * key from the card so we just output zeros
2082 * like we would if we could read the card, but
2083 * denied the user access.
2087 error = copyout(tmpstr, ireq->i_data, len);
2089 case IEEE80211_IOC_NUMWEPKEYS:
2090 ireq->i_val = 9; /* include home key */
2092 case IEEE80211_IOC_WEPTXKEY:
2094 * For some strange reason, you have to read all
2095 * keys before you can read the txkey.
2097 sc->areq.an_type = AN_RID_WEP_TEMP;
2098 for (i = 0; i < 5; i++) {
2099 if (an_read_record(sc,
2100 (struct an_ltv_gen *) &sc->areq)) {
2104 if (key->kindex == 0xffff)
2106 /* Required to get next entry */
2107 sc->areq.an_type = AN_RID_WEP_PERM;
2112 sc->areq.an_type = AN_RID_WEP_PERM;
2113 key->kindex = 0xffff;
2114 if (an_read_record(sc,
2115 (struct an_ltv_gen *)&sc->areq)) {
2119 ireq->i_val = key->mac[0];
2121 * Check for home mode. Map home mode into
2122 * 5th key since that is how it is stored on
2125 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2126 sc->areq.an_type = AN_RID_GENCONFIG;
2127 if (an_read_record(sc,
2128 (struct an_ltv_gen *)&sc->areq)) {
2132 if (config->an_home_product & AN_HOME_NETWORK)
2135 case IEEE80211_IOC_AUTHMODE:
2136 sc->areq.an_type = AN_RID_ACTUALCFG;
2137 if (an_read_record(sc,
2138 (struct an_ltv_gen *)&sc->areq)) {
2142 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2144 ireq->i_val = IEEE80211_AUTH_NONE;
2145 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2147 ireq->i_val = IEEE80211_AUTH_OPEN;
2148 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2149 AN_AUTHTYPE_SHAREDKEY) {
2150 ireq->i_val = IEEE80211_AUTH_SHARED;
2154 case IEEE80211_IOC_STATIONNAME:
2155 sc->areq.an_type = AN_RID_ACTUALCFG;
2156 if (an_read_record(sc,
2157 (struct an_ltv_gen *)&sc->areq)) {
2161 ireq->i_len = sizeof(config->an_nodename);
2162 tmpptr = config->an_nodename;
2163 bzero(tmpstr, IEEE80211_NWID_LEN);
2164 bcopy(tmpptr, tmpstr, ireq->i_len);
2165 error = copyout(tmpstr, ireq->i_data,
2166 IEEE80211_NWID_LEN);
2168 case IEEE80211_IOC_CHANNEL:
2169 sc->areq.an_type = AN_RID_STATUS;
2170 if (an_read_record(sc,
2171 (struct an_ltv_gen *)&sc->areq)) {
2175 ireq->i_val = status->an_cur_channel;
2177 case IEEE80211_IOC_POWERSAVE:
2178 sc->areq.an_type = AN_RID_ACTUALCFG;
2179 if (an_read_record(sc,
2180 (struct an_ltv_gen *)&sc->areq)) {
2184 if (config->an_psave_mode == AN_PSAVE_NONE) {
2185 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2186 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2187 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2188 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2189 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2190 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2191 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2195 case IEEE80211_IOC_POWERSAVESLEEP:
2196 sc->areq.an_type = AN_RID_ACTUALCFG;
2197 if (an_read_record(sc,
2198 (struct an_ltv_gen *)&sc->areq)) {
2202 ireq->i_val = config->an_listen_interval;
2207 if ((error = suser(p)))
2209 sc->areq.an_len = sizeof(sc->areq);
2211 * We need a config structure for everything but the WEP
2212 * key management and SSIDs so we get it now so avoid
2213 * duplicating this code every time.
2215 if (ireq->i_type != IEEE80211_IOC_SSID &&
2216 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2217 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2218 sc->areq.an_type = AN_RID_GENCONFIG;
2219 if (an_read_record(sc,
2220 (struct an_ltv_gen *)&sc->areq)) {
2225 switch (ireq->i_type) {
2226 case IEEE80211_IOC_SSID:
2227 sc->areq.an_type = AN_RID_SSIDLIST;
2228 if (an_read_record(sc,
2229 (struct an_ltv_gen *)&sc->areq)) {
2233 if (ireq->i_len > IEEE80211_NWID_LEN) {
2237 switch (ireq->i_val) {
2239 error = copyin(ireq->i_data,
2240 ssids->an_ssid1, ireq->i_len);
2241 ssids->an_ssid1_len = ireq->i_len;
2244 error = copyin(ireq->i_data,
2245 ssids->an_ssid2, ireq->i_len);
2246 ssids->an_ssid2_len = ireq->i_len;
2249 error = copyin(ireq->i_data,
2250 ssids->an_ssid3, ireq->i_len);
2251 ssids->an_ssid3_len = ireq->i_len;
2258 case IEEE80211_IOC_WEP:
2259 switch (ireq->i_val) {
2260 case IEEE80211_WEP_OFF:
2261 config->an_authtype &=
2262 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2263 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2265 case IEEE80211_WEP_ON:
2266 config->an_authtype |=
2267 AN_AUTHTYPE_PRIVACY_IN_USE;
2268 config->an_authtype &=
2269 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2271 case IEEE80211_WEP_MIXED:
2272 config->an_authtype |=
2273 AN_AUTHTYPE_PRIVACY_IN_USE |
2274 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2281 case IEEE80211_IOC_WEPKEY:
2282 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2287 error = copyin(ireq->i_data, tmpstr, 13);
2291 * Map the 9th key into the home mode
2292 * since that is how it is stored on
2295 bzero(&sc->areq, sizeof(struct an_ltv_key));
2296 sc->areq.an_len = sizeof(struct an_ltv_key);
2297 key->mac[0] = 1; /* The others are 0. */
2298 if (ireq->i_val < 4) {
2299 sc->areq.an_type = AN_RID_WEP_TEMP;
2300 key->kindex = ireq->i_val;
2302 sc->areq.an_type = AN_RID_WEP_PERM;
2303 key->kindex = ireq->i_val - 4;
2305 key->klen = ireq->i_len;
2306 bcopy(tmpstr, key->key, key->klen);
2308 case IEEE80211_IOC_WEPTXKEY:
2309 if (ireq->i_val < 0 || ireq->i_val > 4) {
2315 * Map the 5th key into the home mode
2316 * since that is how it is stored on
2319 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2320 sc->areq.an_type = AN_RID_ACTUALCFG;
2321 if (an_read_record(sc,
2322 (struct an_ltv_gen *)&sc->areq)) {
2326 if (ireq->i_val == 4) {
2327 config->an_home_product |= AN_HOME_NETWORK;
2330 config->an_home_product &= ~AN_HOME_NETWORK;
2333 sc->an_config.an_home_product
2334 = config->an_home_product;
2336 /* update configuration */
2339 bzero(&sc->areq, sizeof(struct an_ltv_key));
2340 sc->areq.an_len = sizeof(struct an_ltv_key);
2341 sc->areq.an_type = AN_RID_WEP_PERM;
2342 key->kindex = 0xffff;
2343 key->mac[0] = ireq->i_val;
2345 case IEEE80211_IOC_AUTHMODE:
2346 switch (ireq->i_val) {
2347 case IEEE80211_AUTH_NONE:
2348 config->an_authtype = AN_AUTHTYPE_NONE |
2349 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2351 case IEEE80211_AUTH_OPEN:
2352 config->an_authtype = AN_AUTHTYPE_OPEN |
2353 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2355 case IEEE80211_AUTH_SHARED:
2356 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2357 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2363 case IEEE80211_IOC_STATIONNAME:
2364 if (ireq->i_len > 16) {
2368 bzero(config->an_nodename, 16);
2369 error = copyin(ireq->i_data,
2370 config->an_nodename, ireq->i_len);
2372 case IEEE80211_IOC_CHANNEL:
2374 * The actual range is 1-14, but if you set it
2375 * to 0 you get the default so we let that work
2378 if (ireq->i_val < 0 || ireq->i_val >14) {
2382 config->an_ds_channel = ireq->i_val;
2384 case IEEE80211_IOC_POWERSAVE:
2385 switch (ireq->i_val) {
2386 case IEEE80211_POWERSAVE_OFF:
2387 config->an_psave_mode = AN_PSAVE_NONE;
2389 case IEEE80211_POWERSAVE_CAM:
2390 config->an_psave_mode = AN_PSAVE_CAM;
2392 case IEEE80211_POWERSAVE_PSP:
2393 config->an_psave_mode = AN_PSAVE_PSP;
2395 case IEEE80211_POWERSAVE_PSP_CAM:
2396 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2403 case IEEE80211_IOC_POWERSAVESLEEP:
2404 config->an_listen_interval = ireq->i_val;
2409 an_setdef(sc, &sc->areq);
2423 struct an_softc *sc;
2432 for (i = 0; i < AN_TX_RING_CNT; i++) {
2433 if (an_alloc_nicmem(sc, 1518 +
2436 sc->an_rdata.an_tx_fids[i] = id;
2437 sc->an_rdata.an_tx_ring[i] = 0;
2441 sc->an_rdata.an_tx_prod = 0;
2442 sc->an_rdata.an_tx_cons = 0;
2443 sc->an_rdata.an_tx_empty = 1;
2452 struct an_softc *sc = xsc;
2453 struct ifnet *ifp = &sc->arpcom.ac_if;
2463 if (ifp->if_flags & IFF_RUNNING)
2466 sc->an_associated = 0;
2468 /* Allocate the TX buffers */
2469 if (an_init_tx_ring(sc)) {
2472 an_init_mpi350_desc(sc);
2473 if (an_init_tx_ring(sc)) {
2474 printf("an%d: tx buffer allocation "
2475 "failed\n", sc->an_unit);
2481 /* Set our MAC address. */
2482 bcopy((char *)&sc->arpcom.ac_enaddr,
2483 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2485 if (ifp->if_flags & IFF_BROADCAST)
2486 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2488 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2490 if (ifp->if_flags & IFF_MULTICAST)
2491 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2493 if (ifp->if_flags & IFF_PROMISC) {
2494 if (sc->an_monitor & AN_MONITOR) {
2495 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2496 sc->an_config.an_rxmode |=
2497 AN_RXMODE_80211_MONITOR_ANYBSS |
2498 AN_RXMODE_NO_8023_HEADER;
2500 sc->an_config.an_rxmode |=
2501 AN_RXMODE_80211_MONITOR_CURBSS |
2502 AN_RXMODE_NO_8023_HEADER;
2507 if (sc->an_have_rssimap)
2508 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2510 /* Set the ssid list */
2511 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2512 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2513 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2514 printf("an%d: failed to set ssid list\n", sc->an_unit);
2519 /* Set the AP list */
2520 sc->an_aplist.an_type = AN_RID_APLIST;
2521 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2522 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2523 printf("an%d: failed to set AP list\n", sc->an_unit);
2528 /* Set the configuration in the NIC */
2529 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2530 sc->an_config.an_type = AN_RID_GENCONFIG;
2531 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2532 printf("an%d: failed to set configuration\n", sc->an_unit);
2537 /* Enable the MAC */
2538 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2539 printf("an%d: failed to enable MAC\n", sc->an_unit);
2544 if (ifp->if_flags & IFF_PROMISC)
2545 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2547 /* enable interrupts */
2548 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
2550 ifp->if_flags |= IFF_RUNNING;
2551 ifp->if_flags &= ~IFF_OACTIVE;
2553 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
2563 struct an_softc *sc;
2564 struct mbuf *m0 = NULL;
2565 struct an_txframe_802_3 tx_frame_802_3;
2566 struct ether_header *eh;
2568 unsigned char txcontrol;
2569 struct an_card_tx_desc an_tx_desc;
2578 if (ifp->if_flags & IFF_OACTIVE)
2581 if (!sc->an_associated)
2584 /* We can't send in monitor mode so toss any attempts. */
2585 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2587 IF_DEQUEUE(&ifp->if_snd, m0);
2595 idx = sc->an_rdata.an_tx_prod;
2598 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2600 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2601 IF_DEQUEUE(&ifp->if_snd, m0);
2605 id = sc->an_rdata.an_tx_fids[idx];
2606 eh = mtod(m0, struct ether_header *);
2608 bcopy((char *)&eh->ether_dhost,
2609 (char *)&tx_frame_802_3.an_tx_dst_addr,
2611 bcopy((char *)&eh->ether_shost,
2612 (char *)&tx_frame_802_3.an_tx_src_addr,
2615 /* minus src/dest mac & type */
2616 tx_frame_802_3.an_tx_802_3_payload_len =
2617 m0->m_pkthdr.len - 12;
2619 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2620 tx_frame_802_3.an_tx_802_3_payload_len,
2621 (caddr_t)&sc->an_txbuf);
2623 txcontrol = AN_TXCTL_8023;
2624 /* write the txcontrol only */
2625 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2629 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2630 sizeof(struct an_txframe_802_3));
2632 /* in mbuf header type is just before payload */
2633 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2634 tx_frame_802_3.an_tx_802_3_payload_len);
2637 * If there's a BPF listner, bounce a copy of
2638 * this frame to him.
2646 sc->an_rdata.an_tx_ring[idx] = id;
2647 if (an_cmd(sc, AN_CMD_TX, id))
2648 printf("an%d: xmit failed\n", sc->an_unit);
2650 AN_INC(idx, AN_TX_RING_CNT);
2652 } else { /* MPI-350 */
2653 while (sc->an_rdata.an_tx_empty ||
2654 idx != sc->an_rdata.an_tx_cons) {
2655 IF_DEQUEUE(&ifp->if_snd, m0);
2659 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2661 eh = mtod(m0, struct ether_header *);
2663 /* DJA optimize this to limit bcopy */
2664 bcopy((char *)&eh->ether_dhost,
2665 (char *)&tx_frame_802_3.an_tx_dst_addr,
2667 bcopy((char *)&eh->ether_shost,
2668 (char *)&tx_frame_802_3.an_tx_src_addr,
2671 /* minus src/dest mac & type */
2672 tx_frame_802_3.an_tx_802_3_payload_len =
2673 m0->m_pkthdr.len - 12;
2675 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2676 tx_frame_802_3.an_tx_802_3_payload_len,
2677 (caddr_t)&sc->an_txbuf);
2679 txcontrol = AN_TXCTL_8023;
2680 /* write the txcontrol only */
2681 bcopy((caddr_t)&txcontrol, &buf[0x08],
2685 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2686 sizeof(struct an_txframe_802_3));
2688 /* in mbuf header type is just before payload */
2689 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2690 tx_frame_802_3.an_tx_802_3_payload_len);
2693 bzero(&an_tx_desc, sizeof(an_tx_desc));
2694 an_tx_desc.an_offset = 0;
2695 an_tx_desc.an_eoc = 1;
2696 an_tx_desc.an_valid = 1;
2697 an_tx_desc.an_len = 0x44 +
2698 tx_frame_802_3.an_tx_802_3_payload_len;
2699 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2700 ptr = (u_int8_t*)&an_tx_desc;
2701 for (i = 0; i < sizeof(an_tx_desc); i++) {
2702 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2707 * If there's a BPF listner, bounce a copy of
2708 * this frame to him.
2716 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2718 AN_INC(idx, AN_MAX_TX_DESC);
2719 sc->an_rdata.an_tx_empty = 0;
2724 ifp->if_flags |= IFF_OACTIVE;
2726 sc->an_rdata.an_tx_prod = idx;
2729 * Set a timeout in case the chip goes out to lunch.
2738 struct an_softc *sc;
2751 ifp = &sc->arpcom.ac_if;
2753 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2754 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2755 an_cmd(sc, AN_CMD_DISABLE, 0);
2757 for (i = 0; i < AN_TX_RING_CNT; i++)
2758 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2760 untimeout(an_stats_update, sc, sc->an_stat_ch);
2762 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2764 if (sc->an_flash_buffer) {
2765 free(sc->an_flash_buffer, M_DEVBUF);
2766 sc->an_flash_buffer = NULL;
2778 struct an_softc *sc;
2789 printf("an%d: device timeout\n", sc->an_unit);
2793 an_init_mpi350_desc(sc);
2806 struct an_softc *sc;
2808 sc = device_get_softc(dev);
2818 struct an_softc *sc;
2822 sc = device_get_softc(dev);
2823 ifp = &sc->arpcom.ac_if;
2827 an_init_mpi350_desc(sc);
2830 /* Recovery temporary keys */
2831 for (i = 0; i < 4; i++) {
2832 sc->areq.an_type = AN_RID_WEP_TEMP;
2833 sc->areq.an_len = sizeof(struct an_ltv_key);
2834 bcopy(&sc->an_temp_keys[i],
2835 &sc->areq, sizeof(struct an_ltv_key));
2836 an_setdef(sc, &sc->areq);
2839 if (ifp->if_flags & IFF_UP)
2846 /* Aironet signal strength cache code.
2847 * store signal/noise/quality on per MAC src basis in
2848 * a small fixed cache. The cache wraps if > MAX slots
2849 * used. The cache may be zeroed out to start over.
2850 * Two simple filters exist to reduce computation:
2851 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2852 * to ignore some packets. It defaults to ip only.
2853 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2854 * 2. multicast/broadcast only. This may be used to
2855 * ignore unicast packets and only cache signal strength
2856 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2857 * beacons and not unicast traffic.
2859 * The cache stores (MAC src(index), IP src (major clue), signal,
2862 * No apologies for storing IP src here. It's easy and saves much
2863 * trouble elsewhere. The cache is assumed to be INET dependent,
2864 * although it need not be.
2866 * Note: the Aironet only has a single byte of signal strength value
2867 * in the rx frame header, and it's not scaled to anything sensible.
2868 * This is kind of lame, but it's all we've got.
2871 #ifdef documentation
2873 int an_sigitems; /* number of cached entries */
2874 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2875 int an_nextitem; /* index/# of entries */
2880 /* control variables for cache filtering. Basic idea is
2881 * to reduce cost (e.g., to only Mobile-IP agent beacons
2882 * which are broadcast or multicast). Still you might
2883 * want to measure signal strength anth unicast ping packets
2884 * on a pt. to pt. ant. setup.
2886 /* set true if you want to limit cache items to broadcast/mcast
2887 * only packets (not unicast). Useful for mobile-ip beacons which
2888 * are broadcast/multicast at network layer. Default is all packets
2889 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2891 static int an_cache_mcastonly = 0;
2892 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2893 &an_cache_mcastonly, 0, "");
2895 /* set true if you want to limit cache items to IP packets only
2897 static int an_cache_iponly = 1;
2898 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2899 &an_cache_iponly, 0, "");
2902 * an_cache_store, per rx packet store signal
2903 * strength in MAC (src) indexed cache.
2906 an_cache_store (sc, eh, m, rx_rssi, rx_quality)
2907 struct an_softc *sc;
2908 struct ether_header *eh;
2911 u_int8_t rx_quality;
2915 static int cache_slot = 0; /* use this cache entry */
2916 static int wrapindex = 0; /* next "free" cache entry */
2921 * 2. configurable filter to throw out unicast packets,
2922 * keep multicast only.
2925 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
2929 /* filter for ip packets only
2931 if ( an_cache_iponly && !type_ipv4) {
2935 /* filter for broadcast/multicast only
2937 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2942 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
2943 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2946 /* find the ip header. we want to store the ip_src
2950 ip = mtod(m, struct ip *);
2953 /* do a linear search for a matching MAC address
2954 * in the cache table
2955 * . MAC address is 6 bytes,
2956 * . var w_nextitem holds total number of entries already cached
2958 for (i = 0; i < sc->an_nextitem; i++) {
2959 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2961 * so we already have this entry,
2968 /* did we find a matching mac address?
2969 * if yes, then overwrite a previously existing cache entry
2971 if (i < sc->an_nextitem ) {
2974 /* else, have a new address entry,so
2975 * add this new entry,
2976 * if table full, then we need to replace LRU entry
2980 /* check for space in cache table
2981 * note: an_nextitem also holds number of entries
2982 * added in the cache table
2984 if ( sc->an_nextitem < MAXANCACHE ) {
2985 cache_slot = sc->an_nextitem;
2987 sc->an_sigitems = sc->an_nextitem;
2989 /* no space found, so simply wrap anth wrap index
2990 * and "zap" the next entry
2993 if (wrapindex == MAXANCACHE) {
2996 cache_slot = wrapindex++;
3000 /* invariant: cache_slot now points at some slot
3003 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3004 log(LOG_ERR, "an_cache_store, bad index: %d of "
3005 "[0..%d], gross cache error\n",
3006 cache_slot, MAXANCACHE);
3010 /* store items in cache
3011 * .ip source address
3016 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3018 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3021 switch (an_cache_mode) {
3023 if (sc->an_have_rssimap) {
3024 sc->an_sigcache[cache_slot].signal =
3025 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3026 sc->an_sigcache[cache_slot].quality =
3027 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3029 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3030 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3034 if (sc->an_have_rssimap) {
3035 sc->an_sigcache[cache_slot].signal =
3036 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3037 sc->an_sigcache[cache_slot].quality =
3038 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3042 if (rx_quality > 100)
3044 sc->an_sigcache[cache_slot].signal = rx_rssi;
3045 sc->an_sigcache[cache_slot].quality = rx_quality;
3049 sc->an_sigcache[cache_slot].signal = rx_rssi;
3050 sc->an_sigcache[cache_slot].quality = rx_quality;
3054 sc->an_sigcache[cache_slot].noise = 0;
3061 an_media_change(ifp)
3064 struct an_softc *sc = ifp->if_softc;
3065 struct an_ltv_genconfig *cfg;
3066 int otype = sc->an_config.an_opmode;
3067 int orate = sc->an_tx_rate;
3069 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3070 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC;
3072 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION;
3074 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
3075 case IFM_IEEE80211_DS1:
3076 sc->an_tx_rate = AN_RATE_1MBPS;
3078 case IFM_IEEE80211_DS2:
3079 sc->an_tx_rate = AN_RATE_2MBPS;
3081 case IFM_IEEE80211_DS5:
3082 sc->an_tx_rate = AN_RATE_5_5MBPS;
3084 case IFM_IEEE80211_DS11:
3085 sc->an_tx_rate = AN_RATE_11MBPS;
3092 if (orate != sc->an_tx_rate) {
3093 /* Read the current configuration */
3094 sc->an_config.an_type = AN_RID_GENCONFIG;
3095 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3096 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3097 cfg = &sc->an_config;
3099 /* clear other rates and set the only one we want */
3100 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3101 cfg->an_rates[0] = sc->an_tx_rate;
3103 /* Save the new rate */
3104 sc->an_config.an_type = AN_RID_GENCONFIG;
3105 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3108 if (otype != sc->an_config.an_opmode ||
3109 orate != sc->an_tx_rate)
3116 an_media_status(ifp, imr)
3118 struct ifmediareq *imr;
3120 struct an_ltv_status status;
3121 struct an_softc *sc = ifp->if_softc;
3123 status.an_len = sizeof(status);
3124 status.an_type = AN_RID_STATUS;
3125 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3126 /* If the status read fails, just lie. */
3127 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3128 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3131 if (sc->an_tx_rate == 0) {
3132 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3133 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3134 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3135 switch (status.an_current_tx_rate) {
3137 imr->ifm_active |= IFM_IEEE80211_DS1;
3140 imr->ifm_active |= IFM_IEEE80211_DS2;
3142 case AN_RATE_5_5MBPS:
3143 imr->ifm_active |= IFM_IEEE80211_DS5;
3145 case AN_RATE_11MBPS:
3146 imr->ifm_active |= IFM_IEEE80211_DS11;
3150 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3153 imr->ifm_status = IFM_AVALID;
3154 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3155 imr->ifm_status |= IFM_ACTIVE;
3158 /********************** Cisco utility support routines *************/
3161 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3166 readrids(ifp, l_ioctl)
3168 struct aironet_ioctl *l_ioctl;
3171 struct an_softc *sc;
3173 switch (l_ioctl->command) {
3175 rid = AN_RID_CAPABILITIES;
3178 rid = AN_RID_GENCONFIG;
3181 rid = AN_RID_SSIDLIST;
3184 rid = AN_RID_APLIST;
3187 rid = AN_RID_DRVNAME;
3190 rid = AN_RID_ENCAPPROTO;
3193 rid = AN_RID_WEP_TEMP;
3196 rid = AN_RID_WEP_PERM;
3199 rid = AN_RID_STATUS;
3202 rid = AN_RID_32BITS_DELTA;
3205 rid = AN_RID_32BITS_CUM;
3212 if (rid == 999) /* Is bad command */
3216 sc->areq.an_len = AN_MAX_DATALEN;
3217 sc->areq.an_type = rid;
3219 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3221 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3223 /* the data contains the length at first */
3224 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3225 sizeof(sc->areq.an_len))) {
3228 /* Just copy the data back */
3229 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3237 writerids(ifp, l_ioctl)
3239 struct aironet_ioctl *l_ioctl;
3241 struct an_softc *sc;
3246 command = l_ioctl->command;
3250 rid = AN_RID_SSIDLIST;
3253 rid = AN_RID_CAPABILITIES;
3256 rid = AN_RID_APLIST;
3259 rid = AN_RID_GENCONFIG;
3262 an_cmd(sc, AN_CMD_ENABLE, 0);
3266 an_cmd(sc, AN_CMD_DISABLE, 0);
3271 * This command merely clears the counts does not actually
3272 * store any data only reads rid. But as it changes the cards
3273 * state, I put it in the writerid routines.
3276 rid = AN_RID_32BITS_DELTACLR;
3278 sc->areq.an_len = AN_MAX_DATALEN;
3279 sc->areq.an_type = rid;
3281 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3282 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3284 /* the data contains the length at first */
3285 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3286 sizeof(sc->areq.an_len))) {
3289 /* Just copy the data */
3290 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3297 rid = AN_RID_WEP_TEMP;
3300 rid = AN_RID_WEP_PERM;
3303 rid = AN_RID_LEAPUSERNAME;
3306 rid = AN_RID_LEAPPASSWORD;
3313 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3315 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3316 sc->areq.an_type = rid;
3318 /* Just copy the data back */
3319 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3322 an_cmd(sc, AN_CMD_DISABLE, 0);
3323 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3324 an_cmd(sc, AN_CMD_ENABLE, 0);
3331 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3335 #define FLASH_DELAY(x) tsleep(ifp, PZERO, "flash", ((x) / hz) + 1);
3336 #define FLASH_COMMAND 0x7e7e
3337 #define FLASH_SIZE 32 * 1024
3343 struct an_softc *sc = ifp->if_softc;
3345 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3346 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3347 AN_EV_CLR_STUCK_BUSY);
3354 * Wait for busy completion from card wait for delay uSec's Return true for
3355 * success meaning command reg is clear
3363 int statword = 0xffff;
3365 struct an_softc *sc = ifp->if_softc;
3367 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3370 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3372 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3377 return 0 == (AN_CMD_BUSY & statword);
3381 * STEP 1) Disable MAC and do soft reset on card.
3389 struct an_softc *sc = ifp->if_softc;
3393 an_cmd(sc, AN_CMD_DISABLE, 0);
3395 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3396 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3397 sc->an_unit, status);
3400 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3402 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3405 if (!(status = WaitBusy(ifp, 100))) {
3406 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3407 sc->an_unit, status);
3414 * STEP 2) Put the card in legendary flash mode
3422 struct an_softc *sc = ifp->if_softc;
3424 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3425 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3426 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3427 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3430 * mdelay(500); // 500ms delay
3435 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3436 printf("Waitbusy hang after setflash mode\n");
3443 * Get a character from the card matching matchbyte Step 3)
3447 flashgchar(ifp, matchbyte, dwelltime)
3453 unsigned char rbyte = 0;
3455 struct an_softc *sc = ifp->if_softc;
3459 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3461 if (dwelltime && !(0x8000 & rchar)) {
3466 rbyte = 0xff & rchar;
3468 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3469 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3473 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3475 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3477 } while (dwelltime > 0);
3482 * Put character to SWS0 wait for dwelltime x 50us for echo .
3486 flashpchar(ifp, byte, dwelltime)
3492 int pollbusy, waittime;
3493 struct an_softc *sc = ifp->if_softc;
3500 waittime = dwelltime;
3503 * Wait for busy bit d15 to go false indicating buffer empty
3506 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3508 if (pollbusy & 0x8000) {
3515 while (waittime >= 0);
3517 /* timeout for busy clear wait */
3519 if (waittime <= 0) {
3520 printf("an%d: flash putchar busywait timeout! \n",
3525 * Port is clear now write byte and wait for it to echo back
3528 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3531 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3532 } while (dwelltime >= 0 && echo != byte);
3535 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3537 return echo == byte;
3541 * Transfer 32k of firmware data from user buffer to our buffer and send to
3549 unsigned short *bufp;
3551 struct an_softc *sc = ifp->if_softc;
3555 bufp = sc->an_flash_buffer;
3558 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3559 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3561 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3562 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3565 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3566 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3567 ((u_int32_t *)bufp)[nwords] & 0xffff);
3571 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3577 * After flashing restart the card.
3585 struct an_softc *sc = ifp->if_softc;
3587 FLASH_DELAY(1024); /* Added 12/7/00 */
3591 FLASH_DELAY(1024); /* Added 12/7/00 */
3596 * Entry point for flash ioclt.
3600 flashcard(ifp, l_ioctl)
3602 struct aironet_ioctl *l_ioctl;
3605 struct an_softc *sc;
3609 printf("an%d: flashing not supported on MPI 350 yet\n",
3613 status = l_ioctl->command;
3615 switch (l_ioctl->command) {
3617 return cmdreset(ifp);
3620 if (sc->an_flash_buffer) {
3621 free(sc->an_flash_buffer, M_DEVBUF);
3622 sc->an_flash_buffer = NULL;
3624 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3625 if (sc->an_flash_buffer)
3626 return setflashmode(ifp);
3630 case AIROFLSHGCHR: /* Get char from aux */
3631 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3632 z = *(int *)&sc->areq;
3633 if ((status = flashgchar(ifp, z, 8000)) == 1)
3638 case AIROFLSHPCHR: /* Send char to card. */
3639 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3640 z = *(int *)&sc->areq;
3641 if ((status = flashpchar(ifp, z, 8000)) == -1)
3646 case AIROFLPUTBUF: /* Send 32k to card */
3647 if (l_ioctl->len > FLASH_SIZE) {
3648 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3649 l_ioctl->len, FLASH_SIZE);
3652 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3654 if ((status = flashputbuf(ifp)) != 0)
3660 if ((status = flashrestart(ifp)) != 0) {
3661 printf("an%d: FLASHRESTART returned %d\n",
3662 sc->an_unit, status);