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.11 2004/03/23 22:18:58 hsu 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,
143 static void an_init (void *);
144 static int an_init_tx_ring (struct an_softc *);
145 static void an_start (struct ifnet *);
146 static void an_watchdog (struct ifnet *);
147 static void an_rxeof (struct an_softc *);
148 static void an_txeof (struct an_softc *, int);
150 static void an_promisc (struct an_softc *, int);
151 static int an_cmd (struct an_softc *, int, int);
152 static int an_cmd_struct (struct an_softc *, struct an_command *,
154 static int an_read_record (struct an_softc *, struct an_ltv_gen *);
155 static int an_write_record (struct an_softc *, struct an_ltv_gen *);
156 static int an_read_data (struct an_softc *, int,
158 static int an_write_data (struct an_softc *, int,
160 static int an_seek (struct an_softc *, int, int, int);
161 static int an_alloc_nicmem (struct an_softc *, int, int *);
162 static int an_dma_malloc (struct an_softc *, bus_size_t,
163 struct an_dma_alloc *, int);
164 static void an_dma_free (struct an_softc *,
165 struct an_dma_alloc *);
166 static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
167 static void an_stats_update (void *);
168 static void an_setdef (struct an_softc *, struct an_req *);
170 static void an_cache_store (struct an_softc *, struct ether_header *,
171 struct mbuf *, u_int8_t, u_int8_t);
174 /* function definitions for use with the Cisco's Linux configuration
178 static int readrids (struct ifnet*, struct aironet_ioctl*);
179 static int writerids (struct ifnet*, struct aironet_ioctl*);
180 static int flashcard (struct ifnet*, struct aironet_ioctl*);
182 static int cmdreset (struct ifnet *);
183 static int setflashmode (struct ifnet *);
184 static int flashgchar (struct ifnet *,int,int);
185 static int flashpchar (struct ifnet *,int,int);
186 static int flashputbuf (struct ifnet *);
187 static int flashrestart (struct ifnet *);
188 static int WaitBusy (struct ifnet *, int);
189 static int unstickbusy (struct ifnet *);
191 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
194 static int an_media_change (struct ifnet *);
195 static void an_media_status (struct ifnet *, struct ifmediareq *);
197 static int an_dump = 0;
198 static int an_cache_mode = 0;
204 static char an_conf[256];
205 static char an_conf_cache[256];
207 DECLARE_DUMMY_MODULE(if_an);
211 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
214 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
223 strcpy(an_conf, "off");
226 strcpy(an_conf, "type");
229 strcpy(an_conf, "dump");
232 snprintf(an_conf, 5, "%x", an_dump);
236 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
238 if (strncmp(an_conf,"off", 3) == 0) {
241 if (strncmp(an_conf,"dump", 4) == 0) {
244 if (strncmp(an_conf,"type", 4) == 0) {
250 if ((*s >= '0') && (*s <= '9')) {
251 r = r * 16 + (*s - '0');
252 } else if ((*s >= 'a') && (*s <= 'f')) {
253 r = r * 16 + (*s - 'a' + 10);
261 printf("Sysctl changed for Aironet driver\n");
266 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
267 0, sizeof(an_conf), sysctl_an_dump, "A", "");
270 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
274 last = an_cache_mode;
276 switch (an_cache_mode) {
278 strcpy(an_conf_cache, "per");
281 strcpy(an_conf_cache, "raw");
284 strcpy(an_conf_cache, "dbm");
288 error = sysctl_handle_string(oidp, an_conf_cache,
289 sizeof(an_conf_cache), req);
291 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
294 if (strncmp(an_conf_cache,"per", 3) == 0) {
297 if (strncmp(an_conf_cache,"raw", 3) == 0) {
304 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
305 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
308 * We probe for an Aironet 4500/4800 card by attempting to
309 * read the default SSID list. On reset, the first entry in
310 * the SSID list will contain the name "tsunami." If we don't
311 * find this, then there's no card present.
317 struct an_softc *sc = device_get_softc(dev);
318 struct an_ltv_ssidlist ssid;
321 bzero((char *)&ssid, sizeof(ssid));
323 error = an_alloc_port(dev, 0, AN_IOSIZ);
327 /* can't do autoprobing */
328 if (rman_get_start(sc->port_res) == -1)
332 * We need to fake up a softc structure long enough
333 * to be able to issue commands and call some of the
336 sc->an_bhandle = rman_get_bushandle(sc->port_res);
337 sc->an_btag = rman_get_bustag(sc->port_res);
338 sc->an_unit = device_get_unit(dev);
340 ssid.an_len = sizeof(ssid);
341 ssid.an_type = AN_RID_SSIDLIST;
343 /* Make sure interrupts are disabled. */
344 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
345 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
348 /* No need for an_init_mpi350_desc since it will be done in attach */
350 if (an_cmd(sc, AN_CMD_READCFG, 0))
353 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
356 /* See if the ssid matches what we expect ... but doesn't have to */
357 if (strcmp(ssid.an_ssid1, AN_DEF_SSID))
364 * Allocate a port resource with the given resource id.
367 an_alloc_port(dev, rid, size)
372 struct an_softc *sc = device_get_softc(dev);
373 struct resource *res;
375 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
376 0ul, ~0ul, size, RF_ACTIVE);
387 * Allocate a memory resource with the given resource id.
389 int an_alloc_memory(device_t dev, int rid, int size)
391 struct an_softc *sc = device_get_softc(dev);
392 struct resource *res;
394 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
395 0ul, ~0ul, size, RF_ACTIVE);
407 * Allocate a auxilary memory resource with the given resource id.
409 int an_alloc_aux_memory(device_t dev, int rid, int size)
411 struct an_softc *sc = device_get_softc(dev);
412 struct resource *res;
414 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
415 0ul, ~0ul, size, RF_ACTIVE);
417 sc->mem_aux_rid = rid;
418 sc->mem_aux_res = res;
419 sc->mem_aux_used = size;
427 * Allocate an irq resource with the given resource id.
430 an_alloc_irq(dev, rid, flags)
435 struct an_softc *sc = device_get_softc(dev);
436 struct resource *res;
438 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
439 0ul, ~0ul, 1, (RF_ACTIVE | flags));
450 an_dma_malloc_cb(arg, segs, nseg, error)
452 bus_dma_segment_t *segs;
456 bus_addr_t *paddr = (bus_addr_t*) arg;
457 *paddr = segs->ds_addr;
461 * Alloc DMA memory and set the pointer to it
464 an_dma_malloc(sc, size, dma, mapflags)
467 struct an_dma_alloc *dma;
472 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
476 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
477 BUS_DMA_NOWAIT, &dma->an_dma_map);
481 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
485 mapflags | BUS_DMA_NOWAIT);
489 dma->an_dma_size = size;
493 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
495 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
497 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
498 dma->an_dma_map = NULL;
505 struct an_dma_alloc *dma;
507 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
508 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
509 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
513 * Release all resources
516 an_release_resources(dev)
519 struct an_softc *sc = device_get_softc(dev);
523 bus_release_resource(dev, SYS_RES_IOPORT,
524 sc->port_rid, sc->port_res);
528 bus_release_resource(dev, SYS_RES_MEMORY,
529 sc->mem_rid, sc->mem_res);
532 if (sc->mem_aux_res) {
533 bus_release_resource(dev, SYS_RES_MEMORY,
534 sc->mem_aux_rid, sc->mem_aux_res);
538 bus_release_resource(dev, SYS_RES_IRQ,
539 sc->irq_rid, sc->irq_res);
542 if (sc->an_rid_buffer.an_dma_paddr) {
543 an_dma_free(sc, &sc->an_rid_buffer);
545 for (i = 0; i < AN_MAX_RX_DESC; i++)
546 if (sc->an_rx_buffer[i].an_dma_paddr) {
547 an_dma_free(sc, &sc->an_rx_buffer[i]);
549 for (i = 0; i < AN_MAX_TX_DESC; i++)
550 if (sc->an_tx_buffer[i].an_dma_paddr) {
551 an_dma_free(sc, &sc->an_tx_buffer[i]);
554 bus_dma_tag_destroy(sc->an_dtag);
560 an_init_mpi350_desc(sc)
563 struct an_command cmd_struct;
564 struct an_reply reply;
565 struct an_card_rid_desc an_rid_desc;
566 struct an_card_rx_desc an_rx_desc;
567 struct an_card_tx_desc an_tx_desc;
570 if(!sc->an_rid_buffer.an_dma_paddr)
571 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
572 &sc->an_rid_buffer, 0);
573 for (i = 0; i < AN_MAX_RX_DESC; i++)
574 if(!sc->an_rx_buffer[i].an_dma_paddr)
575 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
576 &sc->an_rx_buffer[i], 0);
577 for (i = 0; i < AN_MAX_TX_DESC; i++)
578 if(!sc->an_tx_buffer[i].an_dma_paddr)
579 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
580 &sc->an_tx_buffer[i], 0);
583 * Allocate RX descriptor
585 bzero(&reply,sizeof(reply));
586 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
587 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
588 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
589 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
590 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
591 printf("an%d: failed to allocate RX descriptor\n",
596 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
597 bzero(&an_rx_desc, sizeof(an_rx_desc));
598 an_rx_desc.an_valid = 1;
599 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
600 an_rx_desc.an_done = 0;
601 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
603 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
604 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
605 + (desc * sizeof(an_rx_desc))
607 ((u_int32_t*)&an_rx_desc)[i]);
611 * Allocate TX descriptor
614 bzero(&reply,sizeof(reply));
615 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
616 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
617 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
618 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
619 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
620 printf("an%d: failed to allocate TX descriptor\n",
625 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
626 bzero(&an_tx_desc, sizeof(an_tx_desc));
627 an_tx_desc.an_offset = 0;
628 an_tx_desc.an_eoc = 0;
629 an_tx_desc.an_valid = 0;
630 an_tx_desc.an_len = 0;
631 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
633 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
634 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
635 + (desc * sizeof(an_tx_desc))
637 ((u_int32_t*)&an_tx_desc)[i]);
641 * Allocate RID descriptor
644 bzero(&reply,sizeof(reply));
645 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
646 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
647 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
648 cmd_struct.an_parm2 = 1;
649 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
650 printf("an%d: failed to allocate host descriptor\n",
655 bzero(&an_rid_desc, sizeof(an_rid_desc));
656 an_rid_desc.an_valid = 1;
657 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
658 an_rid_desc.an_rid = 0;
659 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
661 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
662 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
663 ((u_int32_t*)&an_rid_desc)[i]);
669 an_attach(sc, unit, flags)
674 struct ifnet *ifp = &sc->arpcom.ac_if;
678 sc->an_associated = 0;
680 sc->an_was_monitor = 0;
681 sc->an_flash_buffer = NULL;
686 error = an_init_mpi350_desc(sc);
691 /* Load factory config */
692 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
693 printf("an%d: failed to load config data\n", sc->an_unit);
697 /* Read the current configuration */
698 sc->an_config.an_type = AN_RID_GENCONFIG;
699 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
700 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
701 printf("an%d: read record failed\n", sc->an_unit);
705 /* Read the card capabilities */
706 sc->an_caps.an_type = AN_RID_CAPABILITIES;
707 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
708 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
709 printf("an%d: read record failed\n", sc->an_unit);
714 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
715 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
716 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
717 printf("an%d: read record failed\n", sc->an_unit);
722 sc->an_aplist.an_type = AN_RID_APLIST;
723 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
724 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
725 printf("an%d: read record failed\n", sc->an_unit);
730 /* Read the RSSI <-> dBm map */
731 sc->an_have_rssimap = 0;
732 if (sc->an_caps.an_softcaps & 8) {
733 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
734 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
735 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
736 printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
738 printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
739 sc->an_have_rssimap = 1;
742 printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
746 printf("an%d: Ethernet address: %6D\n", sc->an_unit,
747 sc->arpcom.ac_enaddr, ":");
750 if_initname(ifp, "an", unit);
751 ifp->if_mtu = ETHERMTU;
752 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
753 ifp->if_ioctl = an_ioctl;
754 ifp->if_output = ether_output;
755 ifp->if_start = an_start;
756 ifp->if_watchdog = an_watchdog;
757 ifp->if_init = an_init;
758 ifp->if_baudrate = 10000000;
759 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
761 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
762 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
763 sizeof(AN_DEFAULT_NODENAME) - 1);
765 bzero(sc->an_ssidlist.an_ssid1, sizeof(sc->an_ssidlist.an_ssid1));
766 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_ssid1,
767 sizeof(AN_DEFAULT_NETNAME) - 1);
768 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME);
770 sc->an_config.an_opmode =
771 AN_OPMODE_INFRASTRUCTURE_STATION;
774 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
776 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
777 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
778 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
779 IFM_IEEE80211_ADHOC, 0), 0);
780 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
781 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
782 IFM_IEEE80211_ADHOC, 0), 0);
783 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
784 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
785 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
786 IFM_IEEE80211_ADHOC, 0), 0);
787 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
789 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
790 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
791 IFM_IEEE80211_ADHOC, 0), 0);
792 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
794 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
795 IFM_IEEE80211_ADHOC, 0), 0);
796 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
798 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
802 * Call MI attach routine.
804 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
805 callout_handle_init(&sc->an_stat_ch);
815 struct ether_header *eh;
816 struct ieee80211_frame *ih;
817 struct an_rxframe rx_frame;
818 struct an_rxframe_802_3 rx_frame_802_3;
820 int len, id, error = 0, i, count = 0;
821 int ieee80211_header_len;
824 struct an_card_rx_desc an_rx_desc;
827 ifp = &sc->arpcom.ac_if;
830 id = CSR_READ_2(sc, AN_RX_FID);
832 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
833 /* read raw 802.11 packet */
834 bpf_buf = sc->buf_802_11;
837 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
844 * skip beacon by default since this increases the
848 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
849 (rx_frame.an_frame_ctl &
850 IEEE80211_FC0_SUBTYPE_BEACON)) {
854 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
855 len = rx_frame.an_rx_payload_len
857 /* Check for insane frame length */
858 if (len > sizeof(sc->buf_802_11)) {
859 printf("an%d: oversized packet "
860 "received (%d, %d)\n",
861 sc->an_unit, len, MCLBYTES);
866 bcopy((char *)&rx_frame,
867 bpf_buf, sizeof(rx_frame));
869 error = an_read_data(sc, id, sizeof(rx_frame),
870 (caddr_t)bpf_buf+sizeof(rx_frame),
871 rx_frame.an_rx_payload_len);
873 fc1=rx_frame.an_frame_ctl >> 8;
874 ieee80211_header_len =
875 sizeof(struct ieee80211_frame);
876 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
877 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
878 ieee80211_header_len += ETHER_ADDR_LEN;
881 len = rx_frame.an_rx_payload_len
882 + ieee80211_header_len;
883 /* Check for insane frame length */
884 if (len > sizeof(sc->buf_802_11)) {
885 printf("an%d: oversized packet "
886 "received (%d, %d)\n",
887 sc->an_unit, len, MCLBYTES);
892 ih = (struct ieee80211_frame *)bpf_buf;
894 bcopy((char *)&rx_frame.an_frame_ctl,
895 (char *)ih, ieee80211_header_len);
897 error = an_read_data(sc, id, sizeof(rx_frame) +
899 (caddr_t)ih +ieee80211_header_len,
900 rx_frame.an_rx_payload_len);
902 /* dump raw 802.11 packet to bpf and skip ip stack */
903 if (ifp->if_bpf != NULL) {
904 bpf_tap(ifp, bpf_buf, len);
907 MGETHDR(m, M_NOWAIT, MT_DATA);
913 if (!(m->m_flags & M_EXT)) {
918 m->m_pkthdr.rcvif = ifp;
919 /* Read Ethernet encapsulated packet */
922 /* Read NIC frame header */
923 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
929 /* Read in the 802_3 frame header */
930 if (an_read_data(sc, id, 0x34,
931 (caddr_t)&rx_frame_802_3,
932 sizeof(rx_frame_802_3))) {
936 if (rx_frame_802_3.an_rx_802_3_status != 0) {
940 /* Check for insane frame length */
941 len = rx_frame_802_3.an_rx_802_3_payload_len;
942 if (len > sizeof(sc->buf_802_11)) {
943 printf("an%d: oversized packet "
944 "received (%d, %d)\n",
945 sc->an_unit, len, MCLBYTES);
949 m->m_pkthdr.len = m->m_len =
950 rx_frame_802_3.an_rx_802_3_payload_len + 12;
952 eh = mtod(m, struct ether_header *);
954 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
955 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
956 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
957 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
959 /* in mbuf header type is just before payload */
960 error = an_read_data(sc, id, 0x44,
961 (caddr_t)&(eh->ether_type),
962 rx_frame_802_3.an_rx_802_3_payload_len);
971 /* Receive packet. */
972 m_adj(m, sizeof(struct ether_header));
974 an_cache_store(sc, eh, m,
975 rx_frame.an_rx_signal_strength,
978 ether_input(ifp, eh, m);
981 } else { /* MPI-350 */
982 for (count = 0; count < AN_MAX_RX_DESC; count++){
983 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
984 ((u_int32_t*)&an_rx_desc)[i]
985 = CSR_MEM_AUX_READ_4(sc,
987 + (count * sizeof(an_rx_desc))
990 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
991 buf = sc->an_rx_buffer[count].an_dma_vaddr;
993 MGETHDR(m, M_NOWAIT, MT_DATA);
999 if (!(m->m_flags & M_EXT)) {
1004 m->m_pkthdr.rcvif = ifp;
1005 /* Read Ethernet encapsulated packet */
1008 * No ANCACHE support since we just get back
1009 * an Ethernet packet no 802.11 info
1013 /* Read NIC frame header */
1014 bcopy(buf, (caddr_t)&rx_frame,
1018 /* Check for insane frame length */
1019 len = an_rx_desc.an_len + 12;
1020 if (len > MCLBYTES) {
1021 printf("an%d: oversized packet "
1022 "received (%d, %d)\n",
1023 sc->an_unit, len, MCLBYTES);
1028 m->m_pkthdr.len = m->m_len =
1029 an_rx_desc.an_len + 12;
1031 eh = mtod(m, struct ether_header *);
1033 bcopy(buf, (char *)eh,
1038 /* Receive packet. */
1039 m_adj(m, sizeof(struct ether_header));
1042 an_cache_store(sc, eh, m,
1043 rx_frame.an_rx_signal_strength,
1047 ether_input(ifp, eh, m);
1049 an_rx_desc.an_valid = 1;
1050 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1051 an_rx_desc.an_done = 0;
1052 an_rx_desc.an_phys =
1053 sc->an_rx_buffer[count].an_dma_paddr;
1055 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1056 CSR_MEM_AUX_WRITE_4(sc,
1058 + (count * sizeof(an_rx_desc))
1060 ((u_int32_t*)&an_rx_desc)[i]);
1063 printf("an%d: Didn't get valid RX packet "
1067 an_rx_desc.an_valid, an_rx_desc.an_len);
1074 an_txeof(sc, status)
1075 struct an_softc *sc;
1081 ifp = &sc->arpcom.ac_if;
1084 ifp->if_flags &= ~IFF_OACTIVE;
1087 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1089 if (status & AN_EV_TX_EXC) {
1094 for (i = 0; i < AN_TX_RING_CNT; i++) {
1095 if (id == sc->an_rdata.an_tx_ring[i]) {
1096 sc->an_rdata.an_tx_ring[i] = 0;
1101 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1102 } else { /* MPI 350 */
1103 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1104 if (sc->an_rdata.an_tx_prod ==
1105 sc->an_rdata.an_tx_cons)
1106 sc->an_rdata.an_tx_empty = 1;
1113 * We abuse the stats updater to check the current NIC status. This
1114 * is important because we don't want to allow transmissions until
1115 * the NIC has synchronized to the current cell (either as the master
1116 * in an ad-hoc group, or as a station connected to an access point).
1119 an_stats_update(xsc)
1122 struct an_softc *sc;
1129 ifp = &sc->arpcom.ac_if;
1131 sc->an_status.an_type = AN_RID_STATUS;
1132 sc->an_status.an_len = sizeof(struct an_ltv_status);
1133 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1135 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1136 sc->an_associated = 1;
1138 sc->an_associated = 0;
1140 /* Don't do this while we're transmitting */
1141 if (ifp->if_flags & IFF_OACTIVE) {
1142 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1147 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1148 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1149 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1151 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1161 struct an_softc *sc;
1165 sc = (struct an_softc*)xsc;
1170 ifp = &sc->arpcom.ac_if;
1172 /* Disable interrupts. */
1173 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1175 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1176 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
1178 if (status & AN_EV_AWAKE) {
1179 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
1182 if (status & AN_EV_LINKSTAT) {
1183 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1184 == AN_LINKSTAT_ASSOCIATED)
1185 sc->an_associated = 1;
1187 sc->an_associated = 0;
1188 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1191 if (status & AN_EV_RX) {
1193 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1196 if (status & AN_EV_TX) {
1197 an_txeof(sc, status);
1198 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1201 if (status & AN_EV_TX_EXC) {
1202 an_txeof(sc, status);
1203 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1206 if (status & AN_EV_ALLOC)
1207 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1209 /* Re-enable interrupts. */
1210 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1212 if ((ifp->if_flags & IFF_UP) && (ifp->if_snd.ifq_head != NULL))
1219 an_cmd_struct(sc, cmd, reply)
1220 struct an_softc *sc;
1221 struct an_command *cmd;
1222 struct an_reply *reply;
1226 for (i = 0; i != AN_TIMEOUT; i++) {
1227 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1232 if( i == AN_TIMEOUT) {
1237 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1238 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1239 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1240 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1242 for (i = 0; i < AN_TIMEOUT; i++) {
1243 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1248 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1249 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1250 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1251 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1253 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1254 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1256 /* Ack the command */
1257 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1259 if (i == AN_TIMEOUT)
1266 an_cmd(sc, cmd, val)
1267 struct an_softc *sc;
1273 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1274 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1275 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1276 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1278 for (i = 0; i < AN_TIMEOUT; i++) {
1279 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1282 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1283 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1287 for (i = 0; i < AN_TIMEOUT; i++) {
1288 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1289 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1290 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1291 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1292 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1296 /* Ack the command */
1297 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1299 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1300 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1302 if (i == AN_TIMEOUT)
1309 * This reset sequence may look a little strange, but this is the
1310 * most reliable method I've found to really kick the NIC in the
1311 * head and force it to reboot correctly.
1315 struct an_softc *sc;
1320 an_cmd(sc, AN_CMD_ENABLE, 0);
1321 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1322 an_cmd(sc, AN_CMD_NOOP2, 0);
1324 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1325 printf("an%d: reset failed\n", sc->an_unit);
1327 an_cmd(sc, AN_CMD_DISABLE, 0);
1333 * Read an LTV record from the NIC.
1336 an_read_record(sc, ltv)
1337 struct an_softc *sc;
1338 struct an_ltv_gen *ltv;
1340 struct an_ltv_gen *an_ltv;
1341 struct an_card_rid_desc an_rid_desc;
1342 struct an_command cmd;
1343 struct an_reply reply;
1348 if (ltv->an_len < 4 || ltv->an_type == 0)
1352 /* Tell the NIC to enter record read mode. */
1353 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1354 printf("an%d: RID access failed\n", sc->an_unit);
1358 /* Seek to the record. */
1359 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1360 printf("an%d: seek to record failed\n", sc->an_unit);
1365 * Read the length and record type and make sure they
1366 * match what we expect (this verifies that we have enough
1367 * room to hold all of the returned data).
1368 * Length includes type but not length.
1370 len = CSR_READ_2(sc, AN_DATA1);
1371 if (len > (ltv->an_len - 2)) {
1372 printf("an%d: record length mismatch -- expected %d, "
1373 "got %d for Rid %x\n", sc->an_unit,
1374 ltv->an_len - 2, len, ltv->an_type);
1375 len = ltv->an_len - 2;
1377 ltv->an_len = len + 2;
1380 /* Now read the data. */
1381 len -= 2; /* skip the type */
1383 for (i = len; i > 1; i -= 2)
1384 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1386 ptr2 = (u_int8_t *)ptr;
1387 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1389 } else { /* MPI-350 */
1390 an_rid_desc.an_valid = 1;
1391 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1392 an_rid_desc.an_rid = 0;
1393 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1394 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1396 bzero(&cmd, sizeof(cmd));
1397 bzero(&reply, sizeof(reply));
1398 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1399 cmd.an_parm0 = ltv->an_type;
1401 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1402 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1403 ((u_int32_t*)&an_rid_desc)[i]);
1405 if (an_cmd_struct(sc, &cmd, &reply)
1406 || reply.an_status & AN_CMD_QUAL_MASK) {
1407 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1408 sc->an_unit, ltv->an_type,
1417 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1418 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1419 an_rid_desc.an_len = an_ltv->an_len;
1422 if (an_rid_desc.an_len > 2)
1423 bcopy(&an_ltv->an_type,
1425 an_rid_desc.an_len - 2);
1426 ltv->an_len = an_rid_desc.an_len + 2;
1430 an_dump_record(sc, ltv, "Read");
1436 * Same as read, except we inject data instead of reading it.
1439 an_write_record(sc, ltv)
1440 struct an_softc *sc;
1441 struct an_ltv_gen *ltv;
1443 struct an_card_rid_desc an_rid_desc;
1444 struct an_command cmd;
1445 struct an_reply reply;
1452 an_dump_record(sc, ltv, "Write");
1455 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1458 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1462 * Length includes type but not length.
1464 len = ltv->an_len - 2;
1465 CSR_WRITE_2(sc, AN_DATA1, len);
1467 len -= 2; /* skip the type */
1469 for (i = len; i > 1; i -= 2)
1470 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1472 ptr2 = (u_int8_t *)ptr;
1473 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1476 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1481 for (i = 0; i != AN_TIMEOUT; i++) {
1482 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1488 if (i == AN_TIMEOUT) {
1492 an_rid_desc.an_valid = 1;
1493 an_rid_desc.an_len = ltv->an_len - 2;
1494 an_rid_desc.an_rid = ltv->an_type;
1495 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1497 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1498 an_rid_desc.an_len);
1500 bzero(&cmd,sizeof(cmd));
1501 bzero(&reply,sizeof(reply));
1502 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1503 cmd.an_parm0 = ltv->an_type;
1505 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1506 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1507 ((u_int32_t*)&an_rid_desc)[i]);
1509 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1510 printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
1511 sc->an_unit, ltv->an_type,
1520 ptr = (u_int16_t *)buf;
1522 if (reply.an_status & AN_CMD_QUAL_MASK) {
1523 printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
1524 sc->an_unit, ltv->an_type,
1538 an_dump_record(sc, ltv, string)
1539 struct an_softc *sc;
1540 struct an_ltv_gen *ltv;
1549 len = ltv->an_len - 4;
1550 printf("an%d: RID %4x, Length %4d, Mode %s\n",
1551 sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
1553 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1554 printf("an%d:\t", sc->an_unit);
1555 bzero(buf,sizeof(buf));
1557 ptr2 = (u_int8_t *)<v->an_val;
1558 for (i = len; i > 0; i--) {
1559 printf("%02x ", *ptr2);
1562 if (temp >= ' ' && temp <= '~')
1564 else if (temp >= 'A' && temp <= 'Z')
1568 if (++count == 16) {
1571 printf("an%d:\t", sc->an_unit);
1572 bzero(buf,sizeof(buf));
1575 for (; count != 16; count++) {
1578 printf(" %s\n",buf);
1583 an_seek(sc, id, off, chan)
1584 struct an_softc *sc;
1600 printf("an%d: invalid data path: %x\n", sc->an_unit, chan);
1604 CSR_WRITE_2(sc, selreg, id);
1605 CSR_WRITE_2(sc, offreg, off);
1607 for (i = 0; i < AN_TIMEOUT; i++) {
1608 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1612 if (i == AN_TIMEOUT)
1619 an_read_data(sc, id, off, buf, len)
1620 struct an_softc *sc;
1630 if (an_seek(sc, id, off, AN_BAP1))
1634 ptr = (u_int16_t *)buf;
1635 for (i = len; i > 1; i -= 2)
1636 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1638 ptr2 = (u_int8_t *)ptr;
1639 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1646 an_write_data(sc, id, off, buf, len)
1647 struct an_softc *sc;
1657 if (an_seek(sc, id, off, AN_BAP0))
1661 ptr = (u_int16_t *)buf;
1662 for (i = len; i > 1; i -= 2)
1663 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1665 ptr2 = (u_int8_t *)ptr;
1666 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1673 * Allocate a region of memory inside the NIC and zero
1677 an_alloc_nicmem(sc, len, id)
1678 struct an_softc *sc;
1684 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1685 printf("an%d: failed to allocate %d bytes on NIC\n",
1690 for (i = 0; i < AN_TIMEOUT; i++) {
1691 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1695 if (i == AN_TIMEOUT)
1698 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1699 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1701 if (an_seek(sc, *id, 0, AN_BAP0))
1704 for (i = 0; i < len / 2; i++)
1705 CSR_WRITE_2(sc, AN_DATA0, 0);
1712 struct an_softc *sc;
1713 struct an_req *areq;
1715 struct sockaddr_dl *sdl;
1718 struct an_ltv_genconfig *cfg;
1719 struct an_ltv_ssidlist *ssid;
1720 struct an_ltv_aplist *ap;
1721 struct an_ltv_gen *sp;
1723 ifp = &sc->arpcom.ac_if;
1725 switch (areq->an_type) {
1726 case AN_RID_GENCONFIG:
1727 cfg = (struct an_ltv_genconfig *)areq;
1729 ifa = ifnet_addrs[ifp->if_index - 1];
1730 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1731 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1733 bcopy((char *)&cfg->an_macaddr, LLADDR(sdl), ETHER_ADDR_LEN);
1735 bcopy((char *)cfg, (char *)&sc->an_config,
1736 sizeof(struct an_ltv_genconfig));
1738 case AN_RID_SSIDLIST:
1739 ssid = (struct an_ltv_ssidlist *)areq;
1740 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1741 sizeof(struct an_ltv_ssidlist));
1744 ap = (struct an_ltv_aplist *)areq;
1745 bcopy((char *)ap, (char *)&sc->an_aplist,
1746 sizeof(struct an_ltv_aplist));
1748 case AN_RID_TX_SPEED:
1749 sp = (struct an_ltv_gen *)areq;
1750 sc->an_tx_rate = sp->an_val;
1752 /* Read the current configuration */
1753 sc->an_config.an_type = AN_RID_GENCONFIG;
1754 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1755 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1756 cfg = &sc->an_config;
1758 /* clear other rates and set the only one we want */
1759 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1760 cfg->an_rates[0] = sc->an_tx_rate;
1762 /* Save the new rate */
1763 sc->an_config.an_type = AN_RID_GENCONFIG;
1764 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1766 case AN_RID_WEP_TEMP:
1767 /* Cache the temp keys */
1769 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1770 sizeof(struct an_ltv_key));
1771 case AN_RID_WEP_PERM:
1772 case AN_RID_LEAPUSERNAME:
1773 case AN_RID_LEAPPASSWORD:
1774 /* Disable the MAC. */
1775 an_cmd(sc, AN_CMD_DISABLE, 0);
1778 an_write_record(sc, (struct an_ltv_gen *)areq);
1780 /* Turn the MAC back on. */
1781 an_cmd(sc, AN_CMD_ENABLE, 0);
1784 case AN_RID_MONITOR_MODE:
1785 cfg = (struct an_ltv_genconfig *)areq;
1787 if (ng_ether_detach_p != NULL)
1788 (*ng_ether_detach_p) (ifp);
1789 sc->an_monitor = cfg->an_len;
1791 if (sc->an_monitor & AN_MONITOR) {
1792 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1793 bpfattach(ifp, DLT_AIRONET_HEADER,
1794 sizeof(struct ether_header));
1796 bpfattach(ifp, DLT_IEEE802_11,
1797 sizeof(struct ether_header));
1800 bpfattach(ifp, DLT_EN10MB,
1801 sizeof(struct ether_header));
1802 if (ng_ether_attach_p != NULL)
1803 (*ng_ether_attach_p) (ifp);
1807 printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
1813 /* Reinitialize the card. */
1821 * Derived from Linux driver to enable promiscious mode.
1825 an_promisc(sc, promisc)
1826 struct an_softc *sc;
1829 if (sc->an_was_monitor)
1832 an_init_mpi350_desc(sc);
1833 if (sc->an_monitor || sc->an_was_monitor)
1836 sc->an_was_monitor = sc->an_monitor;
1837 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1843 an_ioctl(ifp, command, data, cr)
1852 struct an_softc *sc;
1854 struct ieee80211req *ireq;
1855 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1857 struct an_ltv_genconfig *config;
1858 struct an_ltv_key *key;
1859 struct an_ltv_status *status;
1860 struct an_ltv_ssidlist *ssids;
1862 struct aironet_ioctl l_ioctl;
1866 ifr = (struct ifreq *)data;
1867 ireq = (struct ieee80211req *)data;
1869 config = (struct an_ltv_genconfig *)&sc->areq;
1870 key = (struct an_ltv_key *)&sc->areq;
1871 status = (struct an_ltv_status *)&sc->areq;
1872 ssids = (struct an_ltv_ssidlist *)&sc->areq;
1883 error = ether_ioctl(ifp, command, data);
1886 if (ifp->if_flags & IFF_UP) {
1887 if (ifp->if_flags & IFF_RUNNING &&
1888 ifp->if_flags & IFF_PROMISC &&
1889 !(sc->an_if_flags & IFF_PROMISC)) {
1891 } else if (ifp->if_flags & IFF_RUNNING &&
1892 !(ifp->if_flags & IFF_PROMISC) &&
1893 sc->an_if_flags & IFF_PROMISC) {
1898 if (ifp->if_flags & IFF_RUNNING)
1901 sc->an_if_flags = ifp->if_flags;
1906 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1910 /* The Aironet has no multicast filter. */
1914 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1918 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1919 error = suser_cred(cr, NULL_CRED_OKAY);
1922 sc->an_sigitems = sc->an_nextitem = 0;
1924 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1925 char *pt = (char *)&sc->areq.an_val;
1926 bcopy((char *)&sc->an_sigitems, (char *)pt,
1929 sc->areq.an_len = sizeof(int) / 2;
1930 bcopy((char *)&sc->an_sigcache, (char *)pt,
1931 sizeof(struct an_sigcache) * sc->an_sigitems);
1932 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1933 sc->an_sigitems) / 2) + 1;
1936 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1940 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1943 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1945 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1948 an_setdef(sc, &sc->areq);
1950 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1951 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1953 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1954 mode = l_ioctl.command;
1956 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1957 error = readrids(ifp, &l_ioctl);
1958 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1959 error = writerids(ifp, &l_ioctl);
1960 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1961 error = flashcard(ifp, &l_ioctl);
1966 /* copy out the updated command info */
1967 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1970 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1971 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1973 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1974 l_ioctl.command = 0;
1976 copyout(&error, l_ioctl.data, sizeof(error));
1980 sc->areq.an_len = sizeof(sc->areq);
1981 /* was that a good idea DJA we are doing a short-cut */
1982 switch (ireq->i_type) {
1983 case IEEE80211_IOC_SSID:
1984 if (ireq->i_val == -1) {
1985 sc->areq.an_type = AN_RID_STATUS;
1986 if (an_read_record(sc,
1987 (struct an_ltv_gen *)&sc->areq)) {
1991 len = status->an_ssidlen;
1992 tmpptr = status->an_ssid;
1993 } else if (ireq->i_val >= 0) {
1994 sc->areq.an_type = AN_RID_SSIDLIST;
1995 if (an_read_record(sc,
1996 (struct an_ltv_gen *)&sc->areq)) {
2000 if (ireq->i_val == 0) {
2001 len = ssids->an_ssid1_len;
2002 tmpptr = ssids->an_ssid1;
2003 } else if (ireq->i_val == 1) {
2004 len = ssids->an_ssid2_len;
2005 tmpptr = ssids->an_ssid2;
2006 } else if (ireq->i_val == 2) {
2007 len = ssids->an_ssid3_len;
2008 tmpptr = ssids->an_ssid3;
2017 if (len > IEEE80211_NWID_LEN) {
2022 bzero(tmpstr, IEEE80211_NWID_LEN);
2023 bcopy(tmpptr, tmpstr, len);
2024 error = copyout(tmpstr, ireq->i_data,
2025 IEEE80211_NWID_LEN);
2027 case IEEE80211_IOC_NUMSSIDS:
2030 case IEEE80211_IOC_WEP:
2031 sc->areq.an_type = AN_RID_ACTUALCFG;
2032 if (an_read_record(sc,
2033 (struct an_ltv_gen *)&sc->areq)) {
2037 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2038 if (config->an_authtype &
2039 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2040 ireq->i_val = IEEE80211_WEP_MIXED;
2042 ireq->i_val = IEEE80211_WEP_ON;
2044 ireq->i_val = IEEE80211_WEP_OFF;
2047 case IEEE80211_IOC_WEPKEY:
2049 * XXX: I'm not entierly convinced this is
2050 * correct, but it's what is implemented in
2051 * ancontrol so it will have to do until we get
2052 * access to actual Cisco code.
2054 if (ireq->i_val < 0 || ireq->i_val > 8) {
2059 if (ireq->i_val < 5) {
2060 sc->areq.an_type = AN_RID_WEP_TEMP;
2061 for (i = 0; i < 5; i++) {
2062 if (an_read_record(sc,
2063 (struct an_ltv_gen *)&sc->areq)) {
2067 if (key->kindex == 0xffff)
2069 if (key->kindex == ireq->i_val)
2071 /* Required to get next entry */
2072 sc->areq.an_type = AN_RID_WEP_PERM;
2077 /* We aren't allowed to read the value of the
2078 * key from the card so we just output zeros
2079 * like we would if we could read the card, but
2080 * denied the user access.
2084 error = copyout(tmpstr, ireq->i_data, len);
2086 case IEEE80211_IOC_NUMWEPKEYS:
2087 ireq->i_val = 9; /* include home key */
2089 case IEEE80211_IOC_WEPTXKEY:
2091 * For some strange reason, you have to read all
2092 * keys before you can read the txkey.
2094 sc->areq.an_type = AN_RID_WEP_TEMP;
2095 for (i = 0; i < 5; i++) {
2096 if (an_read_record(sc,
2097 (struct an_ltv_gen *) &sc->areq)) {
2101 if (key->kindex == 0xffff)
2103 /* Required to get next entry */
2104 sc->areq.an_type = AN_RID_WEP_PERM;
2109 sc->areq.an_type = AN_RID_WEP_PERM;
2110 key->kindex = 0xffff;
2111 if (an_read_record(sc,
2112 (struct an_ltv_gen *)&sc->areq)) {
2116 ireq->i_val = key->mac[0];
2118 * Check for home mode. Map home mode into
2119 * 5th key since that is how it is stored on
2122 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2123 sc->areq.an_type = AN_RID_GENCONFIG;
2124 if (an_read_record(sc,
2125 (struct an_ltv_gen *)&sc->areq)) {
2129 if (config->an_home_product & AN_HOME_NETWORK)
2132 case IEEE80211_IOC_AUTHMODE:
2133 sc->areq.an_type = AN_RID_ACTUALCFG;
2134 if (an_read_record(sc,
2135 (struct an_ltv_gen *)&sc->areq)) {
2139 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2141 ireq->i_val = IEEE80211_AUTH_NONE;
2142 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2144 ireq->i_val = IEEE80211_AUTH_OPEN;
2145 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2146 AN_AUTHTYPE_SHAREDKEY) {
2147 ireq->i_val = IEEE80211_AUTH_SHARED;
2151 case IEEE80211_IOC_STATIONNAME:
2152 sc->areq.an_type = AN_RID_ACTUALCFG;
2153 if (an_read_record(sc,
2154 (struct an_ltv_gen *)&sc->areq)) {
2158 ireq->i_len = sizeof(config->an_nodename);
2159 tmpptr = config->an_nodename;
2160 bzero(tmpstr, IEEE80211_NWID_LEN);
2161 bcopy(tmpptr, tmpstr, ireq->i_len);
2162 error = copyout(tmpstr, ireq->i_data,
2163 IEEE80211_NWID_LEN);
2165 case IEEE80211_IOC_CHANNEL:
2166 sc->areq.an_type = AN_RID_STATUS;
2167 if (an_read_record(sc,
2168 (struct an_ltv_gen *)&sc->areq)) {
2172 ireq->i_val = status->an_cur_channel;
2174 case IEEE80211_IOC_POWERSAVE:
2175 sc->areq.an_type = AN_RID_ACTUALCFG;
2176 if (an_read_record(sc,
2177 (struct an_ltv_gen *)&sc->areq)) {
2181 if (config->an_psave_mode == AN_PSAVE_NONE) {
2182 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2183 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2184 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2185 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2186 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2187 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2188 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2192 case IEEE80211_IOC_POWERSAVESLEEP:
2193 sc->areq.an_type = AN_RID_ACTUALCFG;
2194 if (an_read_record(sc,
2195 (struct an_ltv_gen *)&sc->areq)) {
2199 ireq->i_val = config->an_listen_interval;
2204 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
2206 sc->areq.an_len = sizeof(sc->areq);
2208 * We need a config structure for everything but the WEP
2209 * key management and SSIDs so we get it now so avoid
2210 * duplicating this code every time.
2212 if (ireq->i_type != IEEE80211_IOC_SSID &&
2213 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2214 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2215 sc->areq.an_type = AN_RID_GENCONFIG;
2216 if (an_read_record(sc,
2217 (struct an_ltv_gen *)&sc->areq)) {
2222 switch (ireq->i_type) {
2223 case IEEE80211_IOC_SSID:
2224 sc->areq.an_type = AN_RID_SSIDLIST;
2225 if (an_read_record(sc,
2226 (struct an_ltv_gen *)&sc->areq)) {
2230 if (ireq->i_len > IEEE80211_NWID_LEN) {
2234 switch (ireq->i_val) {
2236 error = copyin(ireq->i_data,
2237 ssids->an_ssid1, ireq->i_len);
2238 ssids->an_ssid1_len = ireq->i_len;
2241 error = copyin(ireq->i_data,
2242 ssids->an_ssid2, ireq->i_len);
2243 ssids->an_ssid2_len = ireq->i_len;
2246 error = copyin(ireq->i_data,
2247 ssids->an_ssid3, ireq->i_len);
2248 ssids->an_ssid3_len = ireq->i_len;
2255 case IEEE80211_IOC_WEP:
2256 switch (ireq->i_val) {
2257 case IEEE80211_WEP_OFF:
2258 config->an_authtype &=
2259 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2260 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2262 case IEEE80211_WEP_ON:
2263 config->an_authtype |=
2264 AN_AUTHTYPE_PRIVACY_IN_USE;
2265 config->an_authtype &=
2266 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2268 case IEEE80211_WEP_MIXED:
2269 config->an_authtype |=
2270 AN_AUTHTYPE_PRIVACY_IN_USE |
2271 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2278 case IEEE80211_IOC_WEPKEY:
2279 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2284 error = copyin(ireq->i_data, tmpstr, 13);
2288 * Map the 9th key into the home mode
2289 * since that is how it is stored on
2292 bzero(&sc->areq, sizeof(struct an_ltv_key));
2293 sc->areq.an_len = sizeof(struct an_ltv_key);
2294 key->mac[0] = 1; /* The others are 0. */
2295 if (ireq->i_val < 4) {
2296 sc->areq.an_type = AN_RID_WEP_TEMP;
2297 key->kindex = ireq->i_val;
2299 sc->areq.an_type = AN_RID_WEP_PERM;
2300 key->kindex = ireq->i_val - 4;
2302 key->klen = ireq->i_len;
2303 bcopy(tmpstr, key->key, key->klen);
2305 case IEEE80211_IOC_WEPTXKEY:
2306 if (ireq->i_val < 0 || ireq->i_val > 4) {
2312 * Map the 5th key into the home mode
2313 * since that is how it is stored on
2316 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2317 sc->areq.an_type = AN_RID_ACTUALCFG;
2318 if (an_read_record(sc,
2319 (struct an_ltv_gen *)&sc->areq)) {
2323 if (ireq->i_val == 4) {
2324 config->an_home_product |= AN_HOME_NETWORK;
2327 config->an_home_product &= ~AN_HOME_NETWORK;
2330 sc->an_config.an_home_product
2331 = config->an_home_product;
2333 /* update configuration */
2336 bzero(&sc->areq, sizeof(struct an_ltv_key));
2337 sc->areq.an_len = sizeof(struct an_ltv_key);
2338 sc->areq.an_type = AN_RID_WEP_PERM;
2339 key->kindex = 0xffff;
2340 key->mac[0] = ireq->i_val;
2342 case IEEE80211_IOC_AUTHMODE:
2343 switch (ireq->i_val) {
2344 case IEEE80211_AUTH_NONE:
2345 config->an_authtype = AN_AUTHTYPE_NONE |
2346 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2348 case IEEE80211_AUTH_OPEN:
2349 config->an_authtype = AN_AUTHTYPE_OPEN |
2350 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2352 case IEEE80211_AUTH_SHARED:
2353 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2354 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2360 case IEEE80211_IOC_STATIONNAME:
2361 if (ireq->i_len > 16) {
2365 bzero(config->an_nodename, 16);
2366 error = copyin(ireq->i_data,
2367 config->an_nodename, ireq->i_len);
2369 case IEEE80211_IOC_CHANNEL:
2371 * The actual range is 1-14, but if you set it
2372 * to 0 you get the default so we let that work
2375 if (ireq->i_val < 0 || ireq->i_val >14) {
2379 config->an_ds_channel = ireq->i_val;
2381 case IEEE80211_IOC_POWERSAVE:
2382 switch (ireq->i_val) {
2383 case IEEE80211_POWERSAVE_OFF:
2384 config->an_psave_mode = AN_PSAVE_NONE;
2386 case IEEE80211_POWERSAVE_CAM:
2387 config->an_psave_mode = AN_PSAVE_CAM;
2389 case IEEE80211_POWERSAVE_PSP:
2390 config->an_psave_mode = AN_PSAVE_PSP;
2392 case IEEE80211_POWERSAVE_PSP_CAM:
2393 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2400 case IEEE80211_IOC_POWERSAVESLEEP:
2401 config->an_listen_interval = ireq->i_val;
2406 an_setdef(sc, &sc->areq);
2420 struct an_softc *sc;
2429 for (i = 0; i < AN_TX_RING_CNT; i++) {
2430 if (an_alloc_nicmem(sc, 1518 +
2433 sc->an_rdata.an_tx_fids[i] = id;
2434 sc->an_rdata.an_tx_ring[i] = 0;
2438 sc->an_rdata.an_tx_prod = 0;
2439 sc->an_rdata.an_tx_cons = 0;
2440 sc->an_rdata.an_tx_empty = 1;
2449 struct an_softc *sc = xsc;
2450 struct ifnet *ifp = &sc->arpcom.ac_if;
2460 if (ifp->if_flags & IFF_RUNNING)
2463 sc->an_associated = 0;
2465 /* Allocate the TX buffers */
2466 if (an_init_tx_ring(sc)) {
2469 an_init_mpi350_desc(sc);
2470 if (an_init_tx_ring(sc)) {
2471 printf("an%d: tx buffer allocation "
2472 "failed\n", sc->an_unit);
2478 /* Set our MAC address. */
2479 bcopy((char *)&sc->arpcom.ac_enaddr,
2480 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2482 if (ifp->if_flags & IFF_BROADCAST)
2483 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2485 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2487 if (ifp->if_flags & IFF_MULTICAST)
2488 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2490 if (ifp->if_flags & IFF_PROMISC) {
2491 if (sc->an_monitor & AN_MONITOR) {
2492 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2493 sc->an_config.an_rxmode |=
2494 AN_RXMODE_80211_MONITOR_ANYBSS |
2495 AN_RXMODE_NO_8023_HEADER;
2497 sc->an_config.an_rxmode |=
2498 AN_RXMODE_80211_MONITOR_CURBSS |
2499 AN_RXMODE_NO_8023_HEADER;
2504 if (sc->an_have_rssimap)
2505 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2507 /* Set the ssid list */
2508 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2509 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2510 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2511 printf("an%d: failed to set ssid list\n", sc->an_unit);
2516 /* Set the AP list */
2517 sc->an_aplist.an_type = AN_RID_APLIST;
2518 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2519 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2520 printf("an%d: failed to set AP list\n", sc->an_unit);
2525 /* Set the configuration in the NIC */
2526 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2527 sc->an_config.an_type = AN_RID_GENCONFIG;
2528 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2529 printf("an%d: failed to set configuration\n", sc->an_unit);
2534 /* Enable the MAC */
2535 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2536 printf("an%d: failed to enable MAC\n", sc->an_unit);
2541 if (ifp->if_flags & IFF_PROMISC)
2542 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2544 /* enable interrupts */
2545 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
2547 ifp->if_flags |= IFF_RUNNING;
2548 ifp->if_flags &= ~IFF_OACTIVE;
2550 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
2560 struct an_softc *sc;
2561 struct mbuf *m0 = NULL;
2562 struct an_txframe_802_3 tx_frame_802_3;
2563 struct ether_header *eh;
2565 unsigned char txcontrol;
2566 struct an_card_tx_desc an_tx_desc;
2575 if (ifp->if_flags & IFF_OACTIVE)
2578 if (!sc->an_associated)
2581 /* We can't send in monitor mode so toss any attempts. */
2582 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2584 IF_DEQUEUE(&ifp->if_snd, m0);
2592 idx = sc->an_rdata.an_tx_prod;
2595 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2597 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2598 IF_DEQUEUE(&ifp->if_snd, m0);
2602 id = sc->an_rdata.an_tx_fids[idx];
2603 eh = mtod(m0, struct ether_header *);
2605 bcopy((char *)&eh->ether_dhost,
2606 (char *)&tx_frame_802_3.an_tx_dst_addr,
2608 bcopy((char *)&eh->ether_shost,
2609 (char *)&tx_frame_802_3.an_tx_src_addr,
2612 /* minus src/dest mac & type */
2613 tx_frame_802_3.an_tx_802_3_payload_len =
2614 m0->m_pkthdr.len - 12;
2616 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2617 tx_frame_802_3.an_tx_802_3_payload_len,
2618 (caddr_t)&sc->an_txbuf);
2620 txcontrol = AN_TXCTL_8023;
2621 /* write the txcontrol only */
2622 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2626 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2627 sizeof(struct an_txframe_802_3));
2629 /* in mbuf header type is just before payload */
2630 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2631 tx_frame_802_3.an_tx_802_3_payload_len);
2634 * If there's a BPF listner, bounce a copy of
2635 * this frame to him.
2643 sc->an_rdata.an_tx_ring[idx] = id;
2644 if (an_cmd(sc, AN_CMD_TX, id))
2645 printf("an%d: xmit failed\n", sc->an_unit);
2647 AN_INC(idx, AN_TX_RING_CNT);
2649 } else { /* MPI-350 */
2650 while (sc->an_rdata.an_tx_empty ||
2651 idx != sc->an_rdata.an_tx_cons) {
2652 IF_DEQUEUE(&ifp->if_snd, m0);
2656 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2658 eh = mtod(m0, struct ether_header *);
2660 /* DJA optimize this to limit bcopy */
2661 bcopy((char *)&eh->ether_dhost,
2662 (char *)&tx_frame_802_3.an_tx_dst_addr,
2664 bcopy((char *)&eh->ether_shost,
2665 (char *)&tx_frame_802_3.an_tx_src_addr,
2668 /* minus src/dest mac & type */
2669 tx_frame_802_3.an_tx_802_3_payload_len =
2670 m0->m_pkthdr.len - 12;
2672 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2673 tx_frame_802_3.an_tx_802_3_payload_len,
2674 (caddr_t)&sc->an_txbuf);
2676 txcontrol = AN_TXCTL_8023;
2677 /* write the txcontrol only */
2678 bcopy((caddr_t)&txcontrol, &buf[0x08],
2682 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2683 sizeof(struct an_txframe_802_3));
2685 /* in mbuf header type is just before payload */
2686 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2687 tx_frame_802_3.an_tx_802_3_payload_len);
2690 bzero(&an_tx_desc, sizeof(an_tx_desc));
2691 an_tx_desc.an_offset = 0;
2692 an_tx_desc.an_eoc = 1;
2693 an_tx_desc.an_valid = 1;
2694 an_tx_desc.an_len = 0x44 +
2695 tx_frame_802_3.an_tx_802_3_payload_len;
2696 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2697 ptr = (u_int8_t*)&an_tx_desc;
2698 for (i = 0; i < sizeof(an_tx_desc); i++) {
2699 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2704 * If there's a BPF listner, bounce a copy of
2705 * this frame to him.
2713 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2715 AN_INC(idx, AN_MAX_TX_DESC);
2716 sc->an_rdata.an_tx_empty = 0;
2721 ifp->if_flags |= IFF_OACTIVE;
2723 sc->an_rdata.an_tx_prod = idx;
2726 * Set a timeout in case the chip goes out to lunch.
2735 struct an_softc *sc;
2748 ifp = &sc->arpcom.ac_if;
2750 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2751 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2752 an_cmd(sc, AN_CMD_DISABLE, 0);
2754 for (i = 0; i < AN_TX_RING_CNT; i++)
2755 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2757 untimeout(an_stats_update, sc, sc->an_stat_ch);
2759 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2761 if (sc->an_flash_buffer) {
2762 free(sc->an_flash_buffer, M_DEVBUF);
2763 sc->an_flash_buffer = NULL;
2775 struct an_softc *sc;
2786 printf("an%d: device timeout\n", sc->an_unit);
2790 an_init_mpi350_desc(sc);
2803 struct an_softc *sc;
2805 sc = device_get_softc(dev);
2815 struct an_softc *sc;
2819 sc = device_get_softc(dev);
2820 ifp = &sc->arpcom.ac_if;
2824 an_init_mpi350_desc(sc);
2827 /* Recovery temporary keys */
2828 for (i = 0; i < 4; i++) {
2829 sc->areq.an_type = AN_RID_WEP_TEMP;
2830 sc->areq.an_len = sizeof(struct an_ltv_key);
2831 bcopy(&sc->an_temp_keys[i],
2832 &sc->areq, sizeof(struct an_ltv_key));
2833 an_setdef(sc, &sc->areq);
2836 if (ifp->if_flags & IFF_UP)
2843 /* Aironet signal strength cache code.
2844 * store signal/noise/quality on per MAC src basis in
2845 * a small fixed cache. The cache wraps if > MAX slots
2846 * used. The cache may be zeroed out to start over.
2847 * Two simple filters exist to reduce computation:
2848 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2849 * to ignore some packets. It defaults to ip only.
2850 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2851 * 2. multicast/broadcast only. This may be used to
2852 * ignore unicast packets and only cache signal strength
2853 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2854 * beacons and not unicast traffic.
2856 * The cache stores (MAC src(index), IP src (major clue), signal,
2859 * No apologies for storing IP src here. It's easy and saves much
2860 * trouble elsewhere. The cache is assumed to be INET dependent,
2861 * although it need not be.
2863 * Note: the Aironet only has a single byte of signal strength value
2864 * in the rx frame header, and it's not scaled to anything sensible.
2865 * This is kind of lame, but it's all we've got.
2868 #ifdef documentation
2870 int an_sigitems; /* number of cached entries */
2871 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2872 int an_nextitem; /* index/# of entries */
2877 /* control variables for cache filtering. Basic idea is
2878 * to reduce cost (e.g., to only Mobile-IP agent beacons
2879 * which are broadcast or multicast). Still you might
2880 * want to measure signal strength anth unicast ping packets
2881 * on a pt. to pt. ant. setup.
2883 /* set true if you want to limit cache items to broadcast/mcast
2884 * only packets (not unicast). Useful for mobile-ip beacons which
2885 * are broadcast/multicast at network layer. Default is all packets
2886 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2888 static int an_cache_mcastonly = 0;
2889 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2890 &an_cache_mcastonly, 0, "");
2892 /* set true if you want to limit cache items to IP packets only
2894 static int an_cache_iponly = 1;
2895 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2896 &an_cache_iponly, 0, "");
2899 * an_cache_store, per rx packet store signal
2900 * strength in MAC (src) indexed cache.
2903 an_cache_store (sc, eh, m, rx_rssi, rx_quality)
2904 struct an_softc *sc;
2905 struct ether_header *eh;
2908 u_int8_t rx_quality;
2912 static int cache_slot = 0; /* use this cache entry */
2913 static int wrapindex = 0; /* next "free" cache entry */
2918 * 2. configurable filter to throw out unicast packets,
2919 * keep multicast only.
2922 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
2926 /* filter for ip packets only
2928 if ( an_cache_iponly && !type_ipv4) {
2932 /* filter for broadcast/multicast only
2934 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2939 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
2940 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2943 /* find the ip header. we want to store the ip_src
2947 ip = mtod(m, struct ip *);
2950 /* do a linear search for a matching MAC address
2951 * in the cache table
2952 * . MAC address is 6 bytes,
2953 * . var w_nextitem holds total number of entries already cached
2955 for (i = 0; i < sc->an_nextitem; i++) {
2956 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2958 * so we already have this entry,
2965 /* did we find a matching mac address?
2966 * if yes, then overwrite a previously existing cache entry
2968 if (i < sc->an_nextitem ) {
2971 /* else, have a new address entry,so
2972 * add this new entry,
2973 * if table full, then we need to replace LRU entry
2977 /* check for space in cache table
2978 * note: an_nextitem also holds number of entries
2979 * added in the cache table
2981 if ( sc->an_nextitem < MAXANCACHE ) {
2982 cache_slot = sc->an_nextitem;
2984 sc->an_sigitems = sc->an_nextitem;
2986 /* no space found, so simply wrap anth wrap index
2987 * and "zap" the next entry
2990 if (wrapindex == MAXANCACHE) {
2993 cache_slot = wrapindex++;
2997 /* invariant: cache_slot now points at some slot
3000 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3001 log(LOG_ERR, "an_cache_store, bad index: %d of "
3002 "[0..%d], gross cache error\n",
3003 cache_slot, MAXANCACHE);
3007 /* store items in cache
3008 * .ip source address
3013 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3015 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3018 switch (an_cache_mode) {
3020 if (sc->an_have_rssimap) {
3021 sc->an_sigcache[cache_slot].signal =
3022 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3023 sc->an_sigcache[cache_slot].quality =
3024 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3026 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3027 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3031 if (sc->an_have_rssimap) {
3032 sc->an_sigcache[cache_slot].signal =
3033 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3034 sc->an_sigcache[cache_slot].quality =
3035 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3039 if (rx_quality > 100)
3041 sc->an_sigcache[cache_slot].signal = rx_rssi;
3042 sc->an_sigcache[cache_slot].quality = rx_quality;
3046 sc->an_sigcache[cache_slot].signal = rx_rssi;
3047 sc->an_sigcache[cache_slot].quality = rx_quality;
3051 sc->an_sigcache[cache_slot].noise = 0;
3058 an_media_change(ifp)
3061 struct an_softc *sc = ifp->if_softc;
3062 struct an_ltv_genconfig *cfg;
3063 int otype = sc->an_config.an_opmode;
3064 int orate = sc->an_tx_rate;
3066 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3067 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC;
3069 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION;
3071 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
3072 case IFM_IEEE80211_DS1:
3073 sc->an_tx_rate = AN_RATE_1MBPS;
3075 case IFM_IEEE80211_DS2:
3076 sc->an_tx_rate = AN_RATE_2MBPS;
3078 case IFM_IEEE80211_DS5:
3079 sc->an_tx_rate = AN_RATE_5_5MBPS;
3081 case IFM_IEEE80211_DS11:
3082 sc->an_tx_rate = AN_RATE_11MBPS;
3089 if (orate != sc->an_tx_rate) {
3090 /* Read the current configuration */
3091 sc->an_config.an_type = AN_RID_GENCONFIG;
3092 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3093 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3094 cfg = &sc->an_config;
3096 /* clear other rates and set the only one we want */
3097 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3098 cfg->an_rates[0] = sc->an_tx_rate;
3100 /* Save the new rate */
3101 sc->an_config.an_type = AN_RID_GENCONFIG;
3102 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3105 if (otype != sc->an_config.an_opmode ||
3106 orate != sc->an_tx_rate)
3113 an_media_status(ifp, imr)
3115 struct ifmediareq *imr;
3117 struct an_ltv_status status;
3118 struct an_softc *sc = ifp->if_softc;
3120 status.an_len = sizeof(status);
3121 status.an_type = AN_RID_STATUS;
3122 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3123 /* If the status read fails, just lie. */
3124 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3125 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3128 if (sc->an_tx_rate == 0) {
3129 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3130 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3131 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3132 switch (status.an_current_tx_rate) {
3134 imr->ifm_active |= IFM_IEEE80211_DS1;
3137 imr->ifm_active |= IFM_IEEE80211_DS2;
3139 case AN_RATE_5_5MBPS:
3140 imr->ifm_active |= IFM_IEEE80211_DS5;
3142 case AN_RATE_11MBPS:
3143 imr->ifm_active |= IFM_IEEE80211_DS11;
3147 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3150 imr->ifm_status = IFM_AVALID;
3151 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3152 imr->ifm_status |= IFM_ACTIVE;
3155 /********************** Cisco utility support routines *************/
3158 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3163 readrids(ifp, l_ioctl)
3165 struct aironet_ioctl *l_ioctl;
3168 struct an_softc *sc;
3170 switch (l_ioctl->command) {
3172 rid = AN_RID_CAPABILITIES;
3175 rid = AN_RID_GENCONFIG;
3178 rid = AN_RID_SSIDLIST;
3181 rid = AN_RID_APLIST;
3184 rid = AN_RID_DRVNAME;
3187 rid = AN_RID_ENCAPPROTO;
3190 rid = AN_RID_WEP_TEMP;
3193 rid = AN_RID_WEP_PERM;
3196 rid = AN_RID_STATUS;
3199 rid = AN_RID_32BITS_DELTA;
3202 rid = AN_RID_32BITS_CUM;
3209 if (rid == 999) /* Is bad command */
3213 sc->areq.an_len = AN_MAX_DATALEN;
3214 sc->areq.an_type = rid;
3216 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3218 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3220 /* the data contains the length at first */
3221 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3222 sizeof(sc->areq.an_len))) {
3225 /* Just copy the data back */
3226 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3234 writerids(ifp, l_ioctl)
3236 struct aironet_ioctl *l_ioctl;
3238 struct an_softc *sc;
3243 command = l_ioctl->command;
3247 rid = AN_RID_SSIDLIST;
3250 rid = AN_RID_CAPABILITIES;
3253 rid = AN_RID_APLIST;
3256 rid = AN_RID_GENCONFIG;
3259 an_cmd(sc, AN_CMD_ENABLE, 0);
3263 an_cmd(sc, AN_CMD_DISABLE, 0);
3268 * This command merely clears the counts does not actually
3269 * store any data only reads rid. But as it changes the cards
3270 * state, I put it in the writerid routines.
3273 rid = AN_RID_32BITS_DELTACLR;
3275 sc->areq.an_len = AN_MAX_DATALEN;
3276 sc->areq.an_type = rid;
3278 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3279 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3281 /* the data contains the length at first */
3282 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3283 sizeof(sc->areq.an_len))) {
3286 /* Just copy the data */
3287 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3294 rid = AN_RID_WEP_TEMP;
3297 rid = AN_RID_WEP_PERM;
3300 rid = AN_RID_LEAPUSERNAME;
3303 rid = AN_RID_LEAPPASSWORD;
3310 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3312 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3313 sc->areq.an_type = rid;
3315 /* Just copy the data back */
3316 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3319 an_cmd(sc, AN_CMD_DISABLE, 0);
3320 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3321 an_cmd(sc, AN_CMD_ENABLE, 0);
3328 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3332 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3333 #define FLASH_COMMAND 0x7e7e
3334 #define FLASH_SIZE 32 * 1024
3340 struct an_softc *sc = ifp->if_softc;
3342 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3343 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3344 AN_EV_CLR_STUCK_BUSY);
3351 * Wait for busy completion from card wait for delay uSec's Return true for
3352 * success meaning command reg is clear
3360 int statword = 0xffff;
3362 struct an_softc *sc = ifp->if_softc;
3364 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3367 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3369 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3374 return 0 == (AN_CMD_BUSY & statword);
3378 * STEP 1) Disable MAC and do soft reset on card.
3386 struct an_softc *sc = ifp->if_softc;
3390 an_cmd(sc, AN_CMD_DISABLE, 0);
3392 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3393 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3394 sc->an_unit, status);
3397 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3399 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3402 if (!(status = WaitBusy(ifp, 100))) {
3403 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3404 sc->an_unit, status);
3411 * STEP 2) Put the card in legendary flash mode
3419 struct an_softc *sc = ifp->if_softc;
3421 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3422 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3423 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3424 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3427 * mdelay(500); // 500ms delay
3432 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3433 printf("Waitbusy hang after setflash mode\n");
3440 * Get a character from the card matching matchbyte Step 3)
3444 flashgchar(ifp, matchbyte, dwelltime)
3450 unsigned char rbyte = 0;
3452 struct an_softc *sc = ifp->if_softc;
3456 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3458 if (dwelltime && !(0x8000 & rchar)) {
3463 rbyte = 0xff & rchar;
3465 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3466 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3470 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3472 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3474 } while (dwelltime > 0);
3479 * Put character to SWS0 wait for dwelltime x 50us for echo .
3483 flashpchar(ifp, byte, dwelltime)
3489 int pollbusy, waittime;
3490 struct an_softc *sc = ifp->if_softc;
3497 waittime = dwelltime;
3500 * Wait for busy bit d15 to go false indicating buffer empty
3503 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3505 if (pollbusy & 0x8000) {
3512 while (waittime >= 0);
3514 /* timeout for busy clear wait */
3516 if (waittime <= 0) {
3517 printf("an%d: flash putchar busywait timeout! \n",
3522 * Port is clear now write byte and wait for it to echo back
3525 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3528 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3529 } while (dwelltime >= 0 && echo != byte);
3532 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3534 return echo == byte;
3538 * Transfer 32k of firmware data from user buffer to our buffer and send to
3546 unsigned short *bufp;
3548 struct an_softc *sc = ifp->if_softc;
3552 bufp = sc->an_flash_buffer;
3555 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3556 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3558 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3559 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3562 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3563 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3564 ((u_int32_t *)bufp)[nwords] & 0xffff);
3568 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3574 * After flashing restart the card.
3582 struct an_softc *sc = ifp->if_softc;
3584 FLASH_DELAY(1024); /* Added 12/7/00 */
3588 FLASH_DELAY(1024); /* Added 12/7/00 */
3593 * Entry point for flash ioclt.
3597 flashcard(ifp, l_ioctl)
3599 struct aironet_ioctl *l_ioctl;
3602 struct an_softc *sc;
3606 printf("an%d: flashing not supported on MPI 350 yet\n",
3610 status = l_ioctl->command;
3612 switch (l_ioctl->command) {
3614 return cmdreset(ifp);
3617 if (sc->an_flash_buffer) {
3618 free(sc->an_flash_buffer, M_DEVBUF);
3619 sc->an_flash_buffer = NULL;
3621 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3622 if (sc->an_flash_buffer)
3623 return setflashmode(ifp);
3627 case AIROFLSHGCHR: /* Get char from aux */
3628 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3629 z = *(int *)&sc->areq;
3630 if ((status = flashgchar(ifp, z, 8000)) == 1)
3635 case AIROFLSHPCHR: /* Send char to card. */
3636 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3637 z = *(int *)&sc->areq;
3638 if ((status = flashpchar(ifp, z, 8000)) == -1)
3643 case AIROFLPUTBUF: /* Send 32k to card */
3644 if (l_ioctl->len > FLASH_SIZE) {
3645 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3646 l_ioctl->len, FLASH_SIZE);
3649 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3651 if ((status = flashputbuf(ifp)) != 0)
3657 if ((status = flashrestart(ifp)) != 0) {
3658 printf("an%d: FLASHRESTART returned %d\n",
3659 sc->an_unit, status);