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.14 2004/07/27 14:06:14 joerg 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_media.h>
122 #include <netproto/802_11/ieee80211.h>
123 #include <netproto/802_11/ieee80211_ioctl.h>
126 #include <netinet/in.h>
127 #include <netinet/in_systm.h>
128 #include <netinet/in_var.h>
129 #include <netinet/ip.h>
134 #include <machine/md_var.h>
136 #include "if_aironet_ieee.h"
137 #include "if_anreg.h"
139 /* These are global because we need them in sys/pci/if_an_p.c. */
140 static void an_reset (struct an_softc *);
141 static int an_init_mpi350_desc (struct an_softc *);
142 static int an_ioctl (struct ifnet *, u_long, caddr_t,
144 static void an_init (void *);
145 static int an_init_tx_ring (struct an_softc *);
146 static void an_start (struct ifnet *);
147 static void an_watchdog (struct ifnet *);
148 static void an_rxeof (struct an_softc *);
149 static void an_txeof (struct an_softc *, int);
151 static void an_promisc (struct an_softc *, int);
152 static int an_cmd (struct an_softc *, int, int);
153 static int an_cmd_struct (struct an_softc *, struct an_command *,
155 static int an_read_record (struct an_softc *, struct an_ltv_gen *);
156 static int an_write_record (struct an_softc *, struct an_ltv_gen *);
157 static int an_read_data (struct an_softc *, int,
159 static int an_write_data (struct an_softc *, int,
161 static int an_seek (struct an_softc *, int, int, int);
162 static int an_alloc_nicmem (struct an_softc *, int, int *);
163 static int an_dma_malloc (struct an_softc *, bus_size_t,
164 struct an_dma_alloc *, int);
165 static void an_dma_free (struct an_softc *,
166 struct an_dma_alloc *);
167 static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
168 static void an_stats_update (void *);
169 static void an_setdef (struct an_softc *, struct an_req *);
171 static void an_cache_store (struct an_softc *, struct mbuf *,
175 /* function definitions for use with the Cisco's Linux configuration
179 static int readrids (struct ifnet*, struct aironet_ioctl*);
180 static int writerids (struct ifnet*, struct aironet_ioctl*);
181 static int flashcard (struct ifnet*, struct aironet_ioctl*);
183 static int cmdreset (struct ifnet *);
184 static int setflashmode (struct ifnet *);
185 static int flashgchar (struct ifnet *,int,int);
186 static int flashpchar (struct ifnet *,int,int);
187 static int flashputbuf (struct ifnet *);
188 static int flashrestart (struct ifnet *);
189 static int WaitBusy (struct ifnet *, int);
190 static int unstickbusy (struct ifnet *);
192 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
195 static int an_media_change (struct ifnet *);
196 static void an_media_status (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];
208 DECLARE_DUMMY_MODULE(if_an);
212 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
215 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
224 strcpy(an_conf, "off");
227 strcpy(an_conf, "type");
230 strcpy(an_conf, "dump");
233 snprintf(an_conf, 5, "%x", an_dump);
237 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
239 if (strncmp(an_conf,"off", 3) == 0) {
242 if (strncmp(an_conf,"dump", 4) == 0) {
245 if (strncmp(an_conf,"type", 4) == 0) {
251 if ((*s >= '0') && (*s <= '9')) {
252 r = r * 16 + (*s - '0');
253 } else if ((*s >= 'a') && (*s <= 'f')) {
254 r = r * 16 + (*s - 'a' + 10);
262 printf("Sysctl changed for Aironet driver\n");
267 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
268 0, sizeof(an_conf), sysctl_an_dump, "A", "");
271 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
275 last = an_cache_mode;
277 switch (an_cache_mode) {
279 strcpy(an_conf_cache, "per");
282 strcpy(an_conf_cache, "raw");
285 strcpy(an_conf_cache, "dbm");
289 error = sysctl_handle_string(oidp, an_conf_cache,
290 sizeof(an_conf_cache), req);
292 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
295 if (strncmp(an_conf_cache,"per", 3) == 0) {
298 if (strncmp(an_conf_cache,"raw", 3) == 0) {
305 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
306 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
309 * We probe for an Aironet 4500/4800 card by attempting to
310 * read the default SSID list. On reset, the first entry in
311 * the SSID list will contain the name "tsunami." If we don't
312 * find this, then there's no card present.
318 struct an_softc *sc = device_get_softc(dev);
319 struct an_ltv_ssidlist ssid;
322 bzero((char *)&ssid, sizeof(ssid));
324 error = an_alloc_port(dev, 0, AN_IOSIZ);
328 /* can't do autoprobing */
329 if (rman_get_start(sc->port_res) == -1)
333 * We need to fake up a softc structure long enough
334 * to be able to issue commands and call some of the
337 sc->an_bhandle = rman_get_bushandle(sc->port_res);
338 sc->an_btag = rman_get_bustag(sc->port_res);
339 sc->an_unit = device_get_unit(dev);
341 ssid.an_len = sizeof(ssid);
342 ssid.an_type = AN_RID_SSIDLIST;
344 /* Make sure interrupts are disabled. */
345 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
346 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
349 /* No need for an_init_mpi350_desc since it will be done in attach */
351 if (an_cmd(sc, AN_CMD_READCFG, 0))
354 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
357 /* See if the ssid matches what we expect ... but doesn't have to */
358 if (strcmp(ssid.an_ssid1, AN_DEF_SSID))
365 * Allocate a port resource with the given resource id.
368 an_alloc_port(dev, rid, size)
373 struct an_softc *sc = device_get_softc(dev);
374 struct resource *res;
376 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
377 0ul, ~0ul, size, RF_ACTIVE);
388 * Allocate a memory resource with the given resource id.
390 int an_alloc_memory(device_t dev, int rid, int size)
392 struct an_softc *sc = device_get_softc(dev);
393 struct resource *res;
395 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
396 0ul, ~0ul, size, RF_ACTIVE);
408 * Allocate a auxilary memory resource with the given resource id.
410 int an_alloc_aux_memory(device_t dev, int rid, int size)
412 struct an_softc *sc = device_get_softc(dev);
413 struct resource *res;
415 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
416 0ul, ~0ul, size, RF_ACTIVE);
418 sc->mem_aux_rid = rid;
419 sc->mem_aux_res = res;
420 sc->mem_aux_used = size;
428 * Allocate an irq resource with the given resource id.
431 an_alloc_irq(dev, rid, flags)
436 struct an_softc *sc = device_get_softc(dev);
437 struct resource *res;
439 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
440 0ul, ~0ul, 1, (RF_ACTIVE | flags));
451 an_dma_malloc_cb(arg, segs, nseg, error)
453 bus_dma_segment_t *segs;
457 bus_addr_t *paddr = (bus_addr_t*) arg;
458 *paddr = segs->ds_addr;
462 * Alloc DMA memory and set the pointer to it
465 an_dma_malloc(sc, size, dma, mapflags)
468 struct an_dma_alloc *dma;
473 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
477 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
478 BUS_DMA_NOWAIT, &dma->an_dma_map);
482 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
486 mapflags | BUS_DMA_NOWAIT);
490 dma->an_dma_size = size;
494 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
496 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
498 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
499 dma->an_dma_map = NULL;
506 struct an_dma_alloc *dma;
508 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
509 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
510 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
514 * Release all resources
517 an_release_resources(dev)
520 struct an_softc *sc = device_get_softc(dev);
524 bus_release_resource(dev, SYS_RES_IOPORT,
525 sc->port_rid, sc->port_res);
529 bus_release_resource(dev, SYS_RES_MEMORY,
530 sc->mem_rid, sc->mem_res);
533 if (sc->mem_aux_res) {
534 bus_release_resource(dev, SYS_RES_MEMORY,
535 sc->mem_aux_rid, sc->mem_aux_res);
539 bus_release_resource(dev, SYS_RES_IRQ,
540 sc->irq_rid, sc->irq_res);
543 if (sc->an_rid_buffer.an_dma_paddr) {
544 an_dma_free(sc, &sc->an_rid_buffer);
546 for (i = 0; i < AN_MAX_RX_DESC; i++)
547 if (sc->an_rx_buffer[i].an_dma_paddr) {
548 an_dma_free(sc, &sc->an_rx_buffer[i]);
550 for (i = 0; i < AN_MAX_TX_DESC; i++)
551 if (sc->an_tx_buffer[i].an_dma_paddr) {
552 an_dma_free(sc, &sc->an_tx_buffer[i]);
555 bus_dma_tag_destroy(sc->an_dtag);
561 an_init_mpi350_desc(sc)
564 struct an_command cmd_struct;
565 struct an_reply reply;
566 struct an_card_rid_desc an_rid_desc;
567 struct an_card_rx_desc an_rx_desc;
568 struct an_card_tx_desc an_tx_desc;
571 if(!sc->an_rid_buffer.an_dma_paddr)
572 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
573 &sc->an_rid_buffer, 0);
574 for (i = 0; i < AN_MAX_RX_DESC; i++)
575 if(!sc->an_rx_buffer[i].an_dma_paddr)
576 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
577 &sc->an_rx_buffer[i], 0);
578 for (i = 0; i < AN_MAX_TX_DESC; i++)
579 if(!sc->an_tx_buffer[i].an_dma_paddr)
580 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
581 &sc->an_tx_buffer[i], 0);
584 * Allocate RX descriptor
586 bzero(&reply,sizeof(reply));
587 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
588 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
589 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
590 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
591 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
592 printf("an%d: failed to allocate RX descriptor\n",
597 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
598 bzero(&an_rx_desc, sizeof(an_rx_desc));
599 an_rx_desc.an_valid = 1;
600 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
601 an_rx_desc.an_done = 0;
602 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
604 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
605 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
606 + (desc * sizeof(an_rx_desc))
608 ((u_int32_t*)&an_rx_desc)[i]);
612 * Allocate TX descriptor
615 bzero(&reply,sizeof(reply));
616 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
617 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
618 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
619 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
620 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
621 printf("an%d: failed to allocate TX descriptor\n",
626 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
627 bzero(&an_tx_desc, sizeof(an_tx_desc));
628 an_tx_desc.an_offset = 0;
629 an_tx_desc.an_eoc = 0;
630 an_tx_desc.an_valid = 0;
631 an_tx_desc.an_len = 0;
632 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
634 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
635 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
636 + (desc * sizeof(an_tx_desc))
638 ((u_int32_t*)&an_tx_desc)[i]);
642 * Allocate RID descriptor
645 bzero(&reply,sizeof(reply));
646 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
647 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
648 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
649 cmd_struct.an_parm2 = 1;
650 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
651 printf("an%d: failed to allocate host descriptor\n",
656 bzero(&an_rid_desc, sizeof(an_rid_desc));
657 an_rid_desc.an_valid = 1;
658 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
659 an_rid_desc.an_rid = 0;
660 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
662 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
663 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
664 ((u_int32_t*)&an_rid_desc)[i]);
670 an_attach(sc, unit, flags)
675 struct ifnet *ifp = &sc->arpcom.ac_if;
679 sc->an_associated = 0;
681 sc->an_was_monitor = 0;
682 sc->an_flash_buffer = NULL;
687 error = an_init_mpi350_desc(sc);
692 /* Load factory config */
693 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
694 printf("an%d: failed to load config data\n", sc->an_unit);
698 /* Read the current configuration */
699 sc->an_config.an_type = AN_RID_GENCONFIG;
700 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
701 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
702 printf("an%d: read record failed\n", sc->an_unit);
706 /* Read the card capabilities */
707 sc->an_caps.an_type = AN_RID_CAPABILITIES;
708 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
709 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
710 printf("an%d: read record failed\n", sc->an_unit);
715 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
716 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
717 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
718 printf("an%d: read record failed\n", sc->an_unit);
723 sc->an_aplist.an_type = AN_RID_APLIST;
724 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
725 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
726 printf("an%d: read record failed\n", sc->an_unit);
731 /* Read the RSSI <-> dBm map */
732 sc->an_have_rssimap = 0;
733 if (sc->an_caps.an_softcaps & 8) {
734 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
735 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
736 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
737 printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
739 printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
740 sc->an_have_rssimap = 1;
743 printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
748 if_initname(ifp, "an", unit);
749 ifp->if_mtu = ETHERMTU;
750 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
751 ifp->if_ioctl = an_ioctl;
752 ifp->if_start = an_start;
753 ifp->if_watchdog = an_watchdog;
754 ifp->if_init = an_init;
755 ifp->if_baudrate = 10000000;
756 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
758 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
759 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
760 sizeof(AN_DEFAULT_NODENAME) - 1);
762 bzero(sc->an_ssidlist.an_ssid1, sizeof(sc->an_ssidlist.an_ssid1));
763 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_ssid1,
764 sizeof(AN_DEFAULT_NETNAME) - 1);
765 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME);
767 sc->an_config.an_opmode =
768 AN_OPMODE_INFRASTRUCTURE_STATION;
771 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
773 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
774 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
775 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
776 IFM_IEEE80211_ADHOC, 0), 0);
777 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
778 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
779 IFM_IEEE80211_ADHOC, 0), 0);
780 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
781 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
782 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
783 IFM_IEEE80211_ADHOC, 0), 0);
784 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
786 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
787 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
788 IFM_IEEE80211_ADHOC, 0), 0);
789 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
791 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
792 IFM_IEEE80211_ADHOC, 0), 0);
793 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
795 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
799 * Call MI attach routine.
801 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
802 callout_handle_init(&sc->an_stat_ch);
812 struct ether_header *eh;
813 struct ieee80211_frame *ih;
814 struct an_rxframe rx_frame;
815 struct an_rxframe_802_3 rx_frame_802_3;
817 int len, id, error = 0, i, count = 0;
818 int ieee80211_header_len;
821 struct an_card_rx_desc an_rx_desc;
824 ifp = &sc->arpcom.ac_if;
827 id = CSR_READ_2(sc, AN_RX_FID);
829 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
830 /* read raw 802.11 packet */
831 bpf_buf = sc->buf_802_11;
834 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
841 * skip beacon by default since this increases the
845 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
846 (rx_frame.an_frame_ctl &
847 IEEE80211_FC0_SUBTYPE_BEACON)) {
851 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
852 len = rx_frame.an_rx_payload_len
854 /* Check for insane frame length */
855 if (len > sizeof(sc->buf_802_11)) {
856 printf("an%d: oversized packet "
857 "received (%d, %d)\n",
858 sc->an_unit, len, MCLBYTES);
863 bcopy((char *)&rx_frame,
864 bpf_buf, sizeof(rx_frame));
866 error = an_read_data(sc, id, sizeof(rx_frame),
867 (caddr_t)bpf_buf+sizeof(rx_frame),
868 rx_frame.an_rx_payload_len);
870 fc1=rx_frame.an_frame_ctl >> 8;
871 ieee80211_header_len =
872 sizeof(struct ieee80211_frame);
873 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
874 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
875 ieee80211_header_len += ETHER_ADDR_LEN;
878 len = rx_frame.an_rx_payload_len
879 + ieee80211_header_len;
880 /* Check for insane frame length */
881 if (len > sizeof(sc->buf_802_11)) {
882 printf("an%d: oversized packet "
883 "received (%d, %d)\n",
884 sc->an_unit, len, MCLBYTES);
889 ih = (struct ieee80211_frame *)bpf_buf;
891 bcopy((char *)&rx_frame.an_frame_ctl,
892 (char *)ih, ieee80211_header_len);
894 error = an_read_data(sc, id, sizeof(rx_frame) +
896 (caddr_t)ih +ieee80211_header_len,
897 rx_frame.an_rx_payload_len);
899 /* dump raw 802.11 packet to bpf and skip ip stack */
900 if (ifp->if_bpf != NULL) {
901 bpf_tap(ifp, bpf_buf, len);
904 MGETHDR(m, M_NOWAIT, MT_DATA);
910 if (!(m->m_flags & M_EXT)) {
915 m->m_pkthdr.rcvif = ifp;
916 /* Read Ethernet encapsulated packet */
919 /* Read NIC frame header */
920 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
926 /* Read in the 802_3 frame header */
927 if (an_read_data(sc, id, 0x34,
928 (caddr_t)&rx_frame_802_3,
929 sizeof(rx_frame_802_3))) {
933 if (rx_frame_802_3.an_rx_802_3_status != 0) {
937 /* Check for insane frame length */
938 len = rx_frame_802_3.an_rx_802_3_payload_len;
939 if (len > sizeof(sc->buf_802_11)) {
940 printf("an%d: oversized packet "
941 "received (%d, %d)\n",
942 sc->an_unit, len, MCLBYTES);
946 m->m_pkthdr.len = m->m_len =
947 rx_frame_802_3.an_rx_802_3_payload_len + 12;
949 eh = mtod(m, struct ether_header *);
951 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
952 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
953 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
954 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
956 /* in mbuf header type is just before payload */
957 error = an_read_data(sc, id, 0x44,
958 (caddr_t)&(eh->ether_type),
959 rx_frame_802_3.an_rx_802_3_payload_len);
969 an_cache_store(sc, m,
970 rx_frame.an_rx_signal_strength,
973 (*ifp->if_input)(ifp, m);
976 } else { /* MPI-350 */
977 for (count = 0; count < AN_MAX_RX_DESC; count++){
978 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
979 ((u_int32_t*)&an_rx_desc)[i]
980 = CSR_MEM_AUX_READ_4(sc,
982 + (count * sizeof(an_rx_desc))
985 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
986 buf = sc->an_rx_buffer[count].an_dma_vaddr;
988 MGETHDR(m, M_NOWAIT, MT_DATA);
994 if (!(m->m_flags & M_EXT)) {
999 m->m_pkthdr.rcvif = ifp;
1000 /* Read Ethernet encapsulated packet */
1003 * No ANCACHE support since we just get back
1004 * an Ethernet packet no 802.11 info
1008 /* Read NIC frame header */
1009 bcopy(buf, (caddr_t)&rx_frame,
1013 /* Check for insane frame length */
1014 len = an_rx_desc.an_len + 12;
1015 if (len > MCLBYTES) {
1016 printf("an%d: oversized packet "
1017 "received (%d, %d)\n",
1018 sc->an_unit, len, MCLBYTES);
1023 m->m_pkthdr.len = m->m_len =
1024 an_rx_desc.an_len + 12;
1026 eh = mtod(m, struct ether_header *);
1028 bcopy(buf, (char *)eh,
1035 an_cache_store(sc, m,
1036 rx_frame.an_rx_signal_strength,
1040 (*ifp->if_input)(ifp, m);
1042 an_rx_desc.an_valid = 1;
1043 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1044 an_rx_desc.an_done = 0;
1045 an_rx_desc.an_phys =
1046 sc->an_rx_buffer[count].an_dma_paddr;
1048 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1049 CSR_MEM_AUX_WRITE_4(sc,
1051 + (count * sizeof(an_rx_desc))
1053 ((u_int32_t*)&an_rx_desc)[i]);
1056 printf("an%d: Didn't get valid RX packet "
1060 an_rx_desc.an_valid, an_rx_desc.an_len);
1067 an_txeof(sc, status)
1068 struct an_softc *sc;
1074 ifp = &sc->arpcom.ac_if;
1077 ifp->if_flags &= ~IFF_OACTIVE;
1080 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1082 if (status & AN_EV_TX_EXC) {
1087 for (i = 0; i < AN_TX_RING_CNT; i++) {
1088 if (id == sc->an_rdata.an_tx_ring[i]) {
1089 sc->an_rdata.an_tx_ring[i] = 0;
1094 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1095 } else { /* MPI 350 */
1096 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1097 if (sc->an_rdata.an_tx_prod ==
1098 sc->an_rdata.an_tx_cons)
1099 sc->an_rdata.an_tx_empty = 1;
1106 * We abuse the stats updater to check the current NIC status. This
1107 * is important because we don't want to allow transmissions until
1108 * the NIC has synchronized to the current cell (either as the master
1109 * in an ad-hoc group, or as a station connected to an access point).
1112 an_stats_update(xsc)
1115 struct an_softc *sc;
1122 ifp = &sc->arpcom.ac_if;
1124 sc->an_status.an_type = AN_RID_STATUS;
1125 sc->an_status.an_len = sizeof(struct an_ltv_status);
1126 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1128 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1129 sc->an_associated = 1;
1131 sc->an_associated = 0;
1133 /* Don't do this while we're transmitting */
1134 if (ifp->if_flags & IFF_OACTIVE) {
1135 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1140 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1141 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1142 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1144 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1154 struct an_softc *sc;
1158 sc = (struct an_softc*)xsc;
1163 ifp = &sc->arpcom.ac_if;
1165 /* Disable interrupts. */
1166 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1168 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1169 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
1171 if (status & AN_EV_AWAKE) {
1172 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
1175 if (status & AN_EV_LINKSTAT) {
1176 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1177 == AN_LINKSTAT_ASSOCIATED)
1178 sc->an_associated = 1;
1180 sc->an_associated = 0;
1181 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1184 if (status & AN_EV_RX) {
1186 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1189 if (status & AN_EV_TX) {
1190 an_txeof(sc, status);
1191 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1194 if (status & AN_EV_TX_EXC) {
1195 an_txeof(sc, status);
1196 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1199 if (status & AN_EV_ALLOC)
1200 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1202 /* Re-enable interrupts. */
1203 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1205 if ((ifp->if_flags & IFF_UP) && (ifp->if_snd.ifq_head != NULL))
1212 an_cmd_struct(sc, cmd, reply)
1213 struct an_softc *sc;
1214 struct an_command *cmd;
1215 struct an_reply *reply;
1219 for (i = 0; i != AN_TIMEOUT; i++) {
1220 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1225 if( i == AN_TIMEOUT) {
1230 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1231 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1232 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1233 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1235 for (i = 0; i < AN_TIMEOUT; i++) {
1236 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1241 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1242 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1243 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1244 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1246 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1247 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1249 /* Ack the command */
1250 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1252 if (i == AN_TIMEOUT)
1259 an_cmd(sc, cmd, val)
1260 struct an_softc *sc;
1266 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1267 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1268 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1269 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1271 for (i = 0; i < AN_TIMEOUT; i++) {
1272 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1275 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1276 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1280 for (i = 0; i < AN_TIMEOUT; i++) {
1281 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1282 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1283 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1284 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1285 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1289 /* Ack the command */
1290 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1292 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1293 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1295 if (i == AN_TIMEOUT)
1302 * This reset sequence may look a little strange, but this is the
1303 * most reliable method I've found to really kick the NIC in the
1304 * head and force it to reboot correctly.
1308 struct an_softc *sc;
1313 an_cmd(sc, AN_CMD_ENABLE, 0);
1314 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1315 an_cmd(sc, AN_CMD_NOOP2, 0);
1317 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1318 printf("an%d: reset failed\n", sc->an_unit);
1320 an_cmd(sc, AN_CMD_DISABLE, 0);
1326 * Read an LTV record from the NIC.
1329 an_read_record(sc, ltv)
1330 struct an_softc *sc;
1331 struct an_ltv_gen *ltv;
1333 struct an_ltv_gen *an_ltv;
1334 struct an_card_rid_desc an_rid_desc;
1335 struct an_command cmd;
1336 struct an_reply reply;
1341 if (ltv->an_len < 4 || ltv->an_type == 0)
1345 /* Tell the NIC to enter record read mode. */
1346 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1347 printf("an%d: RID access failed\n", sc->an_unit);
1351 /* Seek to the record. */
1352 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1353 printf("an%d: seek to record failed\n", sc->an_unit);
1358 * Read the length and record type and make sure they
1359 * match what we expect (this verifies that we have enough
1360 * room to hold all of the returned data).
1361 * Length includes type but not length.
1363 len = CSR_READ_2(sc, AN_DATA1);
1364 if (len > (ltv->an_len - 2)) {
1365 printf("an%d: record length mismatch -- expected %d, "
1366 "got %d for Rid %x\n", sc->an_unit,
1367 ltv->an_len - 2, len, ltv->an_type);
1368 len = ltv->an_len - 2;
1370 ltv->an_len = len + 2;
1373 /* Now read the data. */
1374 len -= 2; /* skip the type */
1376 for (i = len; i > 1; i -= 2)
1377 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1379 ptr2 = (u_int8_t *)ptr;
1380 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1382 } else { /* MPI-350 */
1383 an_rid_desc.an_valid = 1;
1384 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1385 an_rid_desc.an_rid = 0;
1386 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1387 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1389 bzero(&cmd, sizeof(cmd));
1390 bzero(&reply, sizeof(reply));
1391 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1392 cmd.an_parm0 = ltv->an_type;
1394 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1395 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1396 ((u_int32_t*)&an_rid_desc)[i]);
1398 if (an_cmd_struct(sc, &cmd, &reply)
1399 || reply.an_status & AN_CMD_QUAL_MASK) {
1400 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1401 sc->an_unit, ltv->an_type,
1410 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1411 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1412 an_rid_desc.an_len = an_ltv->an_len;
1415 if (an_rid_desc.an_len > 2)
1416 bcopy(&an_ltv->an_type,
1418 an_rid_desc.an_len - 2);
1419 ltv->an_len = an_rid_desc.an_len + 2;
1423 an_dump_record(sc, ltv, "Read");
1429 * Same as read, except we inject data instead of reading it.
1432 an_write_record(sc, ltv)
1433 struct an_softc *sc;
1434 struct an_ltv_gen *ltv;
1436 struct an_card_rid_desc an_rid_desc;
1437 struct an_command cmd;
1438 struct an_reply reply;
1445 an_dump_record(sc, ltv, "Write");
1448 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1451 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1455 * Length includes type but not length.
1457 len = ltv->an_len - 2;
1458 CSR_WRITE_2(sc, AN_DATA1, len);
1460 len -= 2; /* skip the type */
1462 for (i = len; i > 1; i -= 2)
1463 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1465 ptr2 = (u_int8_t *)ptr;
1466 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1469 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1474 for (i = 0; i != AN_TIMEOUT; i++) {
1475 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1481 if (i == AN_TIMEOUT) {
1485 an_rid_desc.an_valid = 1;
1486 an_rid_desc.an_len = ltv->an_len - 2;
1487 an_rid_desc.an_rid = ltv->an_type;
1488 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1490 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1491 an_rid_desc.an_len);
1493 bzero(&cmd,sizeof(cmd));
1494 bzero(&reply,sizeof(reply));
1495 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1496 cmd.an_parm0 = ltv->an_type;
1498 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1499 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1500 ((u_int32_t*)&an_rid_desc)[i]);
1502 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1503 printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
1504 sc->an_unit, ltv->an_type,
1513 ptr = (u_int16_t *)buf;
1515 if (reply.an_status & AN_CMD_QUAL_MASK) {
1516 printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
1517 sc->an_unit, ltv->an_type,
1531 an_dump_record(sc, ltv, string)
1532 struct an_softc *sc;
1533 struct an_ltv_gen *ltv;
1542 len = ltv->an_len - 4;
1543 printf("an%d: RID %4x, Length %4d, Mode %s\n",
1544 sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
1546 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1547 printf("an%d:\t", sc->an_unit);
1548 bzero(buf,sizeof(buf));
1550 ptr2 = (u_int8_t *)<v->an_val;
1551 for (i = len; i > 0; i--) {
1552 printf("%02x ", *ptr2);
1555 if (temp >= ' ' && temp <= '~')
1557 else if (temp >= 'A' && temp <= 'Z')
1561 if (++count == 16) {
1564 printf("an%d:\t", sc->an_unit);
1565 bzero(buf,sizeof(buf));
1568 for (; count != 16; count++) {
1571 printf(" %s\n",buf);
1576 an_seek(sc, id, off, chan)
1577 struct an_softc *sc;
1593 printf("an%d: invalid data path: %x\n", sc->an_unit, chan);
1597 CSR_WRITE_2(sc, selreg, id);
1598 CSR_WRITE_2(sc, offreg, off);
1600 for (i = 0; i < AN_TIMEOUT; i++) {
1601 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1605 if (i == AN_TIMEOUT)
1612 an_read_data(sc, id, off, buf, len)
1613 struct an_softc *sc;
1623 if (an_seek(sc, id, off, AN_BAP1))
1627 ptr = (u_int16_t *)buf;
1628 for (i = len; i > 1; i -= 2)
1629 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1631 ptr2 = (u_int8_t *)ptr;
1632 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1639 an_write_data(sc, id, off, buf, len)
1640 struct an_softc *sc;
1650 if (an_seek(sc, id, off, AN_BAP0))
1654 ptr = (u_int16_t *)buf;
1655 for (i = len; i > 1; i -= 2)
1656 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1658 ptr2 = (u_int8_t *)ptr;
1659 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1666 * Allocate a region of memory inside the NIC and zero
1670 an_alloc_nicmem(sc, len, id)
1671 struct an_softc *sc;
1677 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1678 printf("an%d: failed to allocate %d bytes on NIC\n",
1683 for (i = 0; i < AN_TIMEOUT; i++) {
1684 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1688 if (i == AN_TIMEOUT)
1691 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1692 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1694 if (an_seek(sc, *id, 0, AN_BAP0))
1697 for (i = 0; i < len / 2; i++)
1698 CSR_WRITE_2(sc, AN_DATA0, 0);
1705 struct an_softc *sc;
1706 struct an_req *areq;
1708 struct sockaddr_dl *sdl;
1711 struct an_ltv_genconfig *cfg;
1712 struct an_ltv_ssidlist *ssid;
1713 struct an_ltv_aplist *ap;
1714 struct an_ltv_gen *sp;
1716 ifp = &sc->arpcom.ac_if;
1718 switch (areq->an_type) {
1719 case AN_RID_GENCONFIG:
1720 cfg = (struct an_ltv_genconfig *)areq;
1722 ifa = ifnet_addrs[ifp->if_index - 1];
1723 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1724 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1726 bcopy((char *)&cfg->an_macaddr, LLADDR(sdl), ETHER_ADDR_LEN);
1728 bcopy((char *)cfg, (char *)&sc->an_config,
1729 sizeof(struct an_ltv_genconfig));
1731 case AN_RID_SSIDLIST:
1732 ssid = (struct an_ltv_ssidlist *)areq;
1733 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1734 sizeof(struct an_ltv_ssidlist));
1737 ap = (struct an_ltv_aplist *)areq;
1738 bcopy((char *)ap, (char *)&sc->an_aplist,
1739 sizeof(struct an_ltv_aplist));
1741 case AN_RID_TX_SPEED:
1742 sp = (struct an_ltv_gen *)areq;
1743 sc->an_tx_rate = sp->an_val;
1745 /* Read the current configuration */
1746 sc->an_config.an_type = AN_RID_GENCONFIG;
1747 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1748 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1749 cfg = &sc->an_config;
1751 /* clear other rates and set the only one we want */
1752 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1753 cfg->an_rates[0] = sc->an_tx_rate;
1755 /* Save the new rate */
1756 sc->an_config.an_type = AN_RID_GENCONFIG;
1757 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1759 case AN_RID_WEP_TEMP:
1760 /* Cache the temp keys */
1762 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1763 sizeof(struct an_ltv_key));
1764 case AN_RID_WEP_PERM:
1765 case AN_RID_LEAPUSERNAME:
1766 case AN_RID_LEAPPASSWORD:
1767 /* Disable the MAC. */
1768 an_cmd(sc, AN_CMD_DISABLE, 0);
1771 an_write_record(sc, (struct an_ltv_gen *)areq);
1773 /* Turn the MAC back on. */
1774 an_cmd(sc, AN_CMD_ENABLE, 0);
1777 case AN_RID_MONITOR_MODE:
1778 cfg = (struct an_ltv_genconfig *)areq;
1780 if (ng_ether_detach_p != NULL)
1781 (*ng_ether_detach_p) (ifp);
1782 sc->an_monitor = cfg->an_len;
1784 if (sc->an_monitor & AN_MONITOR) {
1785 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1786 bpfattach(ifp, DLT_AIRONET_HEADER,
1787 sizeof(struct ether_header));
1789 bpfattach(ifp, DLT_IEEE802_11,
1790 sizeof(struct ether_header));
1793 bpfattach(ifp, DLT_EN10MB,
1794 sizeof(struct ether_header));
1795 if (ng_ether_attach_p != NULL)
1796 (*ng_ether_attach_p) (ifp);
1800 printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
1806 /* Reinitialize the card. */
1814 * Derived from Linux driver to enable promiscious mode.
1818 an_promisc(sc, promisc)
1819 struct an_softc *sc;
1822 if (sc->an_was_monitor)
1825 an_init_mpi350_desc(sc);
1826 if (sc->an_monitor || sc->an_was_monitor)
1829 sc->an_was_monitor = sc->an_monitor;
1830 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1836 an_ioctl(ifp, command, data, cr)
1845 struct an_softc *sc;
1847 struct ieee80211req *ireq;
1848 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1850 struct an_ltv_genconfig *config;
1851 struct an_ltv_key *key;
1852 struct an_ltv_status *status;
1853 struct an_ltv_ssidlist *ssids;
1855 struct aironet_ioctl l_ioctl;
1859 ifr = (struct ifreq *)data;
1860 ireq = (struct ieee80211req *)data;
1862 config = (struct an_ltv_genconfig *)&sc->areq;
1863 key = (struct an_ltv_key *)&sc->areq;
1864 status = (struct an_ltv_status *)&sc->areq;
1865 ssids = (struct an_ltv_ssidlist *)&sc->areq;
1876 error = ether_ioctl(ifp, command, data);
1879 if (ifp->if_flags & IFF_UP) {
1880 if (ifp->if_flags & IFF_RUNNING &&
1881 ifp->if_flags & IFF_PROMISC &&
1882 !(sc->an_if_flags & IFF_PROMISC)) {
1884 } else if (ifp->if_flags & IFF_RUNNING &&
1885 !(ifp->if_flags & IFF_PROMISC) &&
1886 sc->an_if_flags & IFF_PROMISC) {
1891 if (ifp->if_flags & IFF_RUNNING)
1894 sc->an_if_flags = ifp->if_flags;
1899 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1903 /* The Aironet has no multicast filter. */
1907 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1911 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1912 error = suser_cred(cr, NULL_CRED_OKAY);
1915 sc->an_sigitems = sc->an_nextitem = 0;
1917 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1918 char *pt = (char *)&sc->areq.an_val;
1919 bcopy((char *)&sc->an_sigitems, (char *)pt,
1922 sc->areq.an_len = sizeof(int) / 2;
1923 bcopy((char *)&sc->an_sigcache, (char *)pt,
1924 sizeof(struct an_sigcache) * sc->an_sigitems);
1925 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1926 sc->an_sigitems) / 2) + 1;
1929 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1933 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1936 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1938 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1941 an_setdef(sc, &sc->areq);
1943 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1944 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1946 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1947 mode = l_ioctl.command;
1949 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1950 error = readrids(ifp, &l_ioctl);
1951 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1952 error = writerids(ifp, &l_ioctl);
1953 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1954 error = flashcard(ifp, &l_ioctl);
1959 /* copy out the updated command info */
1960 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1963 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1964 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1966 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1967 l_ioctl.command = 0;
1969 copyout(&error, l_ioctl.data, sizeof(error));
1973 sc->areq.an_len = sizeof(sc->areq);
1974 /* was that a good idea DJA we are doing a short-cut */
1975 switch (ireq->i_type) {
1976 case IEEE80211_IOC_SSID:
1977 if (ireq->i_val == -1) {
1978 sc->areq.an_type = AN_RID_STATUS;
1979 if (an_read_record(sc,
1980 (struct an_ltv_gen *)&sc->areq)) {
1984 len = status->an_ssidlen;
1985 tmpptr = status->an_ssid;
1986 } else if (ireq->i_val >= 0) {
1987 sc->areq.an_type = AN_RID_SSIDLIST;
1988 if (an_read_record(sc,
1989 (struct an_ltv_gen *)&sc->areq)) {
1993 if (ireq->i_val == 0) {
1994 len = ssids->an_ssid1_len;
1995 tmpptr = ssids->an_ssid1;
1996 } else if (ireq->i_val == 1) {
1997 len = ssids->an_ssid2_len;
1998 tmpptr = ssids->an_ssid2;
1999 } else if (ireq->i_val == 2) {
2000 len = ssids->an_ssid3_len;
2001 tmpptr = ssids->an_ssid3;
2010 if (len > IEEE80211_NWID_LEN) {
2015 bzero(tmpstr, IEEE80211_NWID_LEN);
2016 bcopy(tmpptr, tmpstr, len);
2017 error = copyout(tmpstr, ireq->i_data,
2018 IEEE80211_NWID_LEN);
2020 case IEEE80211_IOC_NUMSSIDS:
2023 case IEEE80211_IOC_WEP:
2024 sc->areq.an_type = AN_RID_ACTUALCFG;
2025 if (an_read_record(sc,
2026 (struct an_ltv_gen *)&sc->areq)) {
2030 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2031 if (config->an_authtype &
2032 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2033 ireq->i_val = IEEE80211_WEP_MIXED;
2035 ireq->i_val = IEEE80211_WEP_ON;
2037 ireq->i_val = IEEE80211_WEP_OFF;
2040 case IEEE80211_IOC_WEPKEY:
2042 * XXX: I'm not entierly convinced this is
2043 * correct, but it's what is implemented in
2044 * ancontrol so it will have to do until we get
2045 * access to actual Cisco code.
2047 if (ireq->i_val < 0 || ireq->i_val > 8) {
2052 if (ireq->i_val < 5) {
2053 sc->areq.an_type = AN_RID_WEP_TEMP;
2054 for (i = 0; i < 5; i++) {
2055 if (an_read_record(sc,
2056 (struct an_ltv_gen *)&sc->areq)) {
2060 if (key->kindex == 0xffff)
2062 if (key->kindex == ireq->i_val)
2064 /* Required to get next entry */
2065 sc->areq.an_type = AN_RID_WEP_PERM;
2070 /* We aren't allowed to read the value of the
2071 * key from the card so we just output zeros
2072 * like we would if we could read the card, but
2073 * denied the user access.
2077 error = copyout(tmpstr, ireq->i_data, len);
2079 case IEEE80211_IOC_NUMWEPKEYS:
2080 ireq->i_val = 9; /* include home key */
2082 case IEEE80211_IOC_WEPTXKEY:
2084 * For some strange reason, you have to read all
2085 * keys before you can read the txkey.
2087 sc->areq.an_type = AN_RID_WEP_TEMP;
2088 for (i = 0; i < 5; i++) {
2089 if (an_read_record(sc,
2090 (struct an_ltv_gen *) &sc->areq)) {
2094 if (key->kindex == 0xffff)
2096 /* Required to get next entry */
2097 sc->areq.an_type = AN_RID_WEP_PERM;
2102 sc->areq.an_type = AN_RID_WEP_PERM;
2103 key->kindex = 0xffff;
2104 if (an_read_record(sc,
2105 (struct an_ltv_gen *)&sc->areq)) {
2109 ireq->i_val = key->mac[0];
2111 * Check for home mode. Map home mode into
2112 * 5th key since that is how it is stored on
2115 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2116 sc->areq.an_type = AN_RID_GENCONFIG;
2117 if (an_read_record(sc,
2118 (struct an_ltv_gen *)&sc->areq)) {
2122 if (config->an_home_product & AN_HOME_NETWORK)
2125 case IEEE80211_IOC_AUTHMODE:
2126 sc->areq.an_type = AN_RID_ACTUALCFG;
2127 if (an_read_record(sc,
2128 (struct an_ltv_gen *)&sc->areq)) {
2132 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2134 ireq->i_val = IEEE80211_AUTH_NONE;
2135 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2137 ireq->i_val = IEEE80211_AUTH_OPEN;
2138 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2139 AN_AUTHTYPE_SHAREDKEY) {
2140 ireq->i_val = IEEE80211_AUTH_SHARED;
2144 case IEEE80211_IOC_STATIONNAME:
2145 sc->areq.an_type = AN_RID_ACTUALCFG;
2146 if (an_read_record(sc,
2147 (struct an_ltv_gen *)&sc->areq)) {
2151 ireq->i_len = sizeof(config->an_nodename);
2152 tmpptr = config->an_nodename;
2153 bzero(tmpstr, IEEE80211_NWID_LEN);
2154 bcopy(tmpptr, tmpstr, ireq->i_len);
2155 error = copyout(tmpstr, ireq->i_data,
2156 IEEE80211_NWID_LEN);
2158 case IEEE80211_IOC_CHANNEL:
2159 sc->areq.an_type = AN_RID_STATUS;
2160 if (an_read_record(sc,
2161 (struct an_ltv_gen *)&sc->areq)) {
2165 ireq->i_val = status->an_cur_channel;
2167 case IEEE80211_IOC_POWERSAVE:
2168 sc->areq.an_type = AN_RID_ACTUALCFG;
2169 if (an_read_record(sc,
2170 (struct an_ltv_gen *)&sc->areq)) {
2174 if (config->an_psave_mode == AN_PSAVE_NONE) {
2175 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2176 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2177 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2178 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2179 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2180 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2181 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2185 case IEEE80211_IOC_POWERSAVESLEEP:
2186 sc->areq.an_type = AN_RID_ACTUALCFG;
2187 if (an_read_record(sc,
2188 (struct an_ltv_gen *)&sc->areq)) {
2192 ireq->i_val = config->an_listen_interval;
2197 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
2199 sc->areq.an_len = sizeof(sc->areq);
2201 * We need a config structure for everything but the WEP
2202 * key management and SSIDs so we get it now so avoid
2203 * duplicating this code every time.
2205 if (ireq->i_type != IEEE80211_IOC_SSID &&
2206 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2207 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2208 sc->areq.an_type = AN_RID_GENCONFIG;
2209 if (an_read_record(sc,
2210 (struct an_ltv_gen *)&sc->areq)) {
2215 switch (ireq->i_type) {
2216 case IEEE80211_IOC_SSID:
2217 sc->areq.an_type = AN_RID_SSIDLIST;
2218 if (an_read_record(sc,
2219 (struct an_ltv_gen *)&sc->areq)) {
2223 if (ireq->i_len > IEEE80211_NWID_LEN) {
2227 switch (ireq->i_val) {
2229 error = copyin(ireq->i_data,
2230 ssids->an_ssid1, ireq->i_len);
2231 ssids->an_ssid1_len = ireq->i_len;
2234 error = copyin(ireq->i_data,
2235 ssids->an_ssid2, ireq->i_len);
2236 ssids->an_ssid2_len = ireq->i_len;
2239 error = copyin(ireq->i_data,
2240 ssids->an_ssid3, ireq->i_len);
2241 ssids->an_ssid3_len = ireq->i_len;
2248 case IEEE80211_IOC_WEP:
2249 switch (ireq->i_val) {
2250 case IEEE80211_WEP_OFF:
2251 config->an_authtype &=
2252 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2253 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2255 case IEEE80211_WEP_ON:
2256 config->an_authtype |=
2257 AN_AUTHTYPE_PRIVACY_IN_USE;
2258 config->an_authtype &=
2259 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2261 case IEEE80211_WEP_MIXED:
2262 config->an_authtype |=
2263 AN_AUTHTYPE_PRIVACY_IN_USE |
2264 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2271 case IEEE80211_IOC_WEPKEY:
2272 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2277 error = copyin(ireq->i_data, tmpstr, 13);
2281 * Map the 9th key into the home mode
2282 * since that is how it is stored on
2285 bzero(&sc->areq, sizeof(struct an_ltv_key));
2286 sc->areq.an_len = sizeof(struct an_ltv_key);
2287 key->mac[0] = 1; /* The others are 0. */
2288 if (ireq->i_val < 4) {
2289 sc->areq.an_type = AN_RID_WEP_TEMP;
2290 key->kindex = ireq->i_val;
2292 sc->areq.an_type = AN_RID_WEP_PERM;
2293 key->kindex = ireq->i_val - 4;
2295 key->klen = ireq->i_len;
2296 bcopy(tmpstr, key->key, key->klen);
2298 case IEEE80211_IOC_WEPTXKEY:
2299 if (ireq->i_val < 0 || ireq->i_val > 4) {
2305 * Map the 5th key into the home mode
2306 * since that is how it is stored on
2309 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2310 sc->areq.an_type = AN_RID_ACTUALCFG;
2311 if (an_read_record(sc,
2312 (struct an_ltv_gen *)&sc->areq)) {
2316 if (ireq->i_val == 4) {
2317 config->an_home_product |= AN_HOME_NETWORK;
2320 config->an_home_product &= ~AN_HOME_NETWORK;
2323 sc->an_config.an_home_product
2324 = config->an_home_product;
2326 /* update configuration */
2329 bzero(&sc->areq, sizeof(struct an_ltv_key));
2330 sc->areq.an_len = sizeof(struct an_ltv_key);
2331 sc->areq.an_type = AN_RID_WEP_PERM;
2332 key->kindex = 0xffff;
2333 key->mac[0] = ireq->i_val;
2335 case IEEE80211_IOC_AUTHMODE:
2336 switch (ireq->i_val) {
2337 case IEEE80211_AUTH_NONE:
2338 config->an_authtype = AN_AUTHTYPE_NONE |
2339 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2341 case IEEE80211_AUTH_OPEN:
2342 config->an_authtype = AN_AUTHTYPE_OPEN |
2343 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2345 case IEEE80211_AUTH_SHARED:
2346 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2347 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2353 case IEEE80211_IOC_STATIONNAME:
2354 if (ireq->i_len > 16) {
2358 bzero(config->an_nodename, 16);
2359 error = copyin(ireq->i_data,
2360 config->an_nodename, ireq->i_len);
2362 case IEEE80211_IOC_CHANNEL:
2364 * The actual range is 1-14, but if you set it
2365 * to 0 you get the default so we let that work
2368 if (ireq->i_val < 0 || ireq->i_val >14) {
2372 config->an_ds_channel = ireq->i_val;
2374 case IEEE80211_IOC_POWERSAVE:
2375 switch (ireq->i_val) {
2376 case IEEE80211_POWERSAVE_OFF:
2377 config->an_psave_mode = AN_PSAVE_NONE;
2379 case IEEE80211_POWERSAVE_CAM:
2380 config->an_psave_mode = AN_PSAVE_CAM;
2382 case IEEE80211_POWERSAVE_PSP:
2383 config->an_psave_mode = AN_PSAVE_PSP;
2385 case IEEE80211_POWERSAVE_PSP_CAM:
2386 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2393 case IEEE80211_IOC_POWERSAVESLEEP:
2394 config->an_listen_interval = ireq->i_val;
2399 an_setdef(sc, &sc->areq);
2413 struct an_softc *sc;
2422 for (i = 0; i < AN_TX_RING_CNT; i++) {
2423 if (an_alloc_nicmem(sc, 1518 +
2426 sc->an_rdata.an_tx_fids[i] = id;
2427 sc->an_rdata.an_tx_ring[i] = 0;
2431 sc->an_rdata.an_tx_prod = 0;
2432 sc->an_rdata.an_tx_cons = 0;
2433 sc->an_rdata.an_tx_empty = 1;
2442 struct an_softc *sc = xsc;
2443 struct ifnet *ifp = &sc->arpcom.ac_if;
2453 if (ifp->if_flags & IFF_RUNNING)
2456 sc->an_associated = 0;
2458 /* Allocate the TX buffers */
2459 if (an_init_tx_ring(sc)) {
2462 an_init_mpi350_desc(sc);
2463 if (an_init_tx_ring(sc)) {
2464 printf("an%d: tx buffer allocation "
2465 "failed\n", sc->an_unit);
2471 /* Set our MAC address. */
2472 bcopy((char *)&sc->arpcom.ac_enaddr,
2473 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2475 if (ifp->if_flags & IFF_BROADCAST)
2476 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2478 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2480 if (ifp->if_flags & IFF_MULTICAST)
2481 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2483 if (ifp->if_flags & IFF_PROMISC) {
2484 if (sc->an_monitor & AN_MONITOR) {
2485 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2486 sc->an_config.an_rxmode |=
2487 AN_RXMODE_80211_MONITOR_ANYBSS |
2488 AN_RXMODE_NO_8023_HEADER;
2490 sc->an_config.an_rxmode |=
2491 AN_RXMODE_80211_MONITOR_CURBSS |
2492 AN_RXMODE_NO_8023_HEADER;
2497 if (sc->an_have_rssimap)
2498 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2500 /* Set the ssid list */
2501 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2502 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2503 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2504 printf("an%d: failed to set ssid list\n", sc->an_unit);
2509 /* Set the AP list */
2510 sc->an_aplist.an_type = AN_RID_APLIST;
2511 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2512 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2513 printf("an%d: failed to set AP list\n", sc->an_unit);
2518 /* Set the configuration in the NIC */
2519 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2520 sc->an_config.an_type = AN_RID_GENCONFIG;
2521 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2522 printf("an%d: failed to set configuration\n", sc->an_unit);
2527 /* Enable the MAC */
2528 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2529 printf("an%d: failed to enable MAC\n", sc->an_unit);
2534 if (ifp->if_flags & IFF_PROMISC)
2535 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2537 /* enable interrupts */
2538 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
2540 ifp->if_flags |= IFF_RUNNING;
2541 ifp->if_flags &= ~IFF_OACTIVE;
2543 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
2553 struct an_softc *sc;
2554 struct mbuf *m0 = NULL;
2555 struct an_txframe_802_3 tx_frame_802_3;
2556 struct ether_header *eh;
2558 unsigned char txcontrol;
2559 struct an_card_tx_desc an_tx_desc;
2568 if (ifp->if_flags & IFF_OACTIVE)
2571 if (!sc->an_associated)
2574 /* We can't send in monitor mode so toss any attempts. */
2575 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2577 IF_DEQUEUE(&ifp->if_snd, m0);
2585 idx = sc->an_rdata.an_tx_prod;
2588 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2590 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2591 IF_DEQUEUE(&ifp->if_snd, m0);
2595 id = sc->an_rdata.an_tx_fids[idx];
2596 eh = mtod(m0, struct ether_header *);
2598 bcopy((char *)&eh->ether_dhost,
2599 (char *)&tx_frame_802_3.an_tx_dst_addr,
2601 bcopy((char *)&eh->ether_shost,
2602 (char *)&tx_frame_802_3.an_tx_src_addr,
2605 /* minus src/dest mac & type */
2606 tx_frame_802_3.an_tx_802_3_payload_len =
2607 m0->m_pkthdr.len - 12;
2609 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2610 tx_frame_802_3.an_tx_802_3_payload_len,
2611 (caddr_t)&sc->an_txbuf);
2613 txcontrol = AN_TXCTL_8023;
2614 /* write the txcontrol only */
2615 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2619 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2620 sizeof(struct an_txframe_802_3));
2622 /* in mbuf header type is just before payload */
2623 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2624 tx_frame_802_3.an_tx_802_3_payload_len);
2627 * If there's a BPF listner, bounce a copy of
2628 * this frame to him.
2636 sc->an_rdata.an_tx_ring[idx] = id;
2637 if (an_cmd(sc, AN_CMD_TX, id))
2638 printf("an%d: xmit failed\n", sc->an_unit);
2640 AN_INC(idx, AN_TX_RING_CNT);
2642 } else { /* MPI-350 */
2643 while (sc->an_rdata.an_tx_empty ||
2644 idx != sc->an_rdata.an_tx_cons) {
2645 IF_DEQUEUE(&ifp->if_snd, m0);
2649 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2651 eh = mtod(m0, struct ether_header *);
2653 /* DJA optimize this to limit bcopy */
2654 bcopy((char *)&eh->ether_dhost,
2655 (char *)&tx_frame_802_3.an_tx_dst_addr,
2657 bcopy((char *)&eh->ether_shost,
2658 (char *)&tx_frame_802_3.an_tx_src_addr,
2661 /* minus src/dest mac & type */
2662 tx_frame_802_3.an_tx_802_3_payload_len =
2663 m0->m_pkthdr.len - 12;
2665 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2666 tx_frame_802_3.an_tx_802_3_payload_len,
2667 (caddr_t)&sc->an_txbuf);
2669 txcontrol = AN_TXCTL_8023;
2670 /* write the txcontrol only */
2671 bcopy((caddr_t)&txcontrol, &buf[0x08],
2675 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2676 sizeof(struct an_txframe_802_3));
2678 /* in mbuf header type is just before payload */
2679 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2680 tx_frame_802_3.an_tx_802_3_payload_len);
2683 bzero(&an_tx_desc, sizeof(an_tx_desc));
2684 an_tx_desc.an_offset = 0;
2685 an_tx_desc.an_eoc = 1;
2686 an_tx_desc.an_valid = 1;
2687 an_tx_desc.an_len = 0x44 +
2688 tx_frame_802_3.an_tx_802_3_payload_len;
2689 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2690 ptr = (u_int8_t*)&an_tx_desc;
2691 for (i = 0; i < sizeof(an_tx_desc); i++) {
2692 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2697 * If there's a BPF listner, bounce a copy of
2698 * this frame to him.
2706 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2708 AN_INC(idx, AN_MAX_TX_DESC);
2709 sc->an_rdata.an_tx_empty = 0;
2714 ifp->if_flags |= IFF_OACTIVE;
2716 sc->an_rdata.an_tx_prod = idx;
2719 * Set a timeout in case the chip goes out to lunch.
2728 struct an_softc *sc;
2741 ifp = &sc->arpcom.ac_if;
2743 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2744 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2745 an_cmd(sc, AN_CMD_DISABLE, 0);
2747 for (i = 0; i < AN_TX_RING_CNT; i++)
2748 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2750 untimeout(an_stats_update, sc, sc->an_stat_ch);
2752 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2754 if (sc->an_flash_buffer) {
2755 free(sc->an_flash_buffer, M_DEVBUF);
2756 sc->an_flash_buffer = NULL;
2768 struct an_softc *sc;
2779 printf("an%d: device timeout\n", sc->an_unit);
2783 an_init_mpi350_desc(sc);
2796 struct an_softc *sc;
2798 sc = device_get_softc(dev);
2808 struct an_softc *sc;
2812 sc = device_get_softc(dev);
2813 ifp = &sc->arpcom.ac_if;
2817 an_init_mpi350_desc(sc);
2820 /* Recovery temporary keys */
2821 for (i = 0; i < 4; i++) {
2822 sc->areq.an_type = AN_RID_WEP_TEMP;
2823 sc->areq.an_len = sizeof(struct an_ltv_key);
2824 bcopy(&sc->an_temp_keys[i],
2825 &sc->areq, sizeof(struct an_ltv_key));
2826 an_setdef(sc, &sc->areq);
2829 if (ifp->if_flags & IFF_UP)
2836 /* Aironet signal strength cache code.
2837 * store signal/noise/quality on per MAC src basis in
2838 * a small fixed cache. The cache wraps if > MAX slots
2839 * used. The cache may be zeroed out to start over.
2840 * Two simple filters exist to reduce computation:
2841 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2842 * to ignore some packets. It defaults to ip only.
2843 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2844 * 2. multicast/broadcast only. This may be used to
2845 * ignore unicast packets and only cache signal strength
2846 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2847 * beacons and not unicast traffic.
2849 * The cache stores (MAC src(index), IP src (major clue), signal,
2852 * No apologies for storing IP src here. It's easy and saves much
2853 * trouble elsewhere. The cache is assumed to be INET dependent,
2854 * although it need not be.
2856 * Note: the Aironet only has a single byte of signal strength value
2857 * in the rx frame header, and it's not scaled to anything sensible.
2858 * This is kind of lame, but it's all we've got.
2861 #ifdef documentation
2863 int an_sigitems; /* number of cached entries */
2864 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2865 int an_nextitem; /* index/# of entries */
2870 /* control variables for cache filtering. Basic idea is
2871 * to reduce cost (e.g., to only Mobile-IP agent beacons
2872 * which are broadcast or multicast). Still you might
2873 * want to measure signal strength anth unicast ping packets
2874 * on a pt. to pt. ant. setup.
2876 /* set true if you want to limit cache items to broadcast/mcast
2877 * only packets (not unicast). Useful for mobile-ip beacons which
2878 * are broadcast/multicast at network layer. Default is all packets
2879 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2881 static int an_cache_mcastonly = 0;
2882 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2883 &an_cache_mcastonly, 0, "");
2885 /* set true if you want to limit cache items to IP packets only
2887 static int an_cache_iponly = 1;
2888 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2889 &an_cache_iponly, 0, "");
2892 * an_cache_store, per rx packet store signal
2893 * strength in MAC (src) indexed cache.
2896 an_cache_store (sc, m, rx_rssi, rx_quality)
2897 struct an_softc *sc;
2900 u_int8_t rx_quality;
2902 struct ether_header *eh = mtod(m, struct ether_header *);
2903 struct ip *ip = NULL;
2905 static int cache_slot = 0; /* use this cache entry */
2906 static int wrapindex = 0; /* next "free" cache entry */
2910 * 2. configurable filter to throw out unicast packets,
2911 * keep multicast only.
2914 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2915 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2916 else if (an_cache_iponly)
2919 /* filter for broadcast/multicast only
2921 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2926 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
2927 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2930 /* do a linear search for a matching MAC address
2931 * in the cache table
2932 * . MAC address is 6 bytes,
2933 * . var w_nextitem holds total number of entries already cached
2935 for (i = 0; i < sc->an_nextitem; i++) {
2936 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2938 * so we already have this entry,
2945 /* did we find a matching mac address?
2946 * if yes, then overwrite a previously existing cache entry
2948 if (i < sc->an_nextitem ) {
2951 /* else, have a new address entry,so
2952 * add this new entry,
2953 * if table full, then we need to replace LRU entry
2957 /* check for space in cache table
2958 * note: an_nextitem also holds number of entries
2959 * added in the cache table
2961 if ( sc->an_nextitem < MAXANCACHE ) {
2962 cache_slot = sc->an_nextitem;
2964 sc->an_sigitems = sc->an_nextitem;
2966 /* no space found, so simply wrap anth wrap index
2967 * and "zap" the next entry
2970 if (wrapindex == MAXANCACHE) {
2973 cache_slot = wrapindex++;
2977 /* invariant: cache_slot now points at some slot
2980 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
2981 log(LOG_ERR, "an_cache_store, bad index: %d of "
2982 "[0..%d], gross cache error\n",
2983 cache_slot, MAXANCACHE);
2987 /* store items in cache
2988 * .ip source address
2993 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2995 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2998 switch (an_cache_mode) {
3000 if (sc->an_have_rssimap) {
3001 sc->an_sigcache[cache_slot].signal =
3002 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3003 sc->an_sigcache[cache_slot].quality =
3004 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3006 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3007 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3011 if (sc->an_have_rssimap) {
3012 sc->an_sigcache[cache_slot].signal =
3013 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3014 sc->an_sigcache[cache_slot].quality =
3015 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3019 if (rx_quality > 100)
3021 sc->an_sigcache[cache_slot].signal = rx_rssi;
3022 sc->an_sigcache[cache_slot].quality = rx_quality;
3026 sc->an_sigcache[cache_slot].signal = rx_rssi;
3027 sc->an_sigcache[cache_slot].quality = rx_quality;
3031 sc->an_sigcache[cache_slot].noise = 0;
3038 an_media_change(ifp)
3041 struct an_softc *sc = ifp->if_softc;
3042 struct an_ltv_genconfig *cfg;
3043 int otype = sc->an_config.an_opmode;
3044 int orate = sc->an_tx_rate;
3046 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3047 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC;
3049 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION;
3051 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
3052 case IFM_IEEE80211_DS1:
3053 sc->an_tx_rate = AN_RATE_1MBPS;
3055 case IFM_IEEE80211_DS2:
3056 sc->an_tx_rate = AN_RATE_2MBPS;
3058 case IFM_IEEE80211_DS5:
3059 sc->an_tx_rate = AN_RATE_5_5MBPS;
3061 case IFM_IEEE80211_DS11:
3062 sc->an_tx_rate = AN_RATE_11MBPS;
3069 if (orate != sc->an_tx_rate) {
3070 /* Read the current configuration */
3071 sc->an_config.an_type = AN_RID_GENCONFIG;
3072 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3073 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3074 cfg = &sc->an_config;
3076 /* clear other rates and set the only one we want */
3077 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3078 cfg->an_rates[0] = sc->an_tx_rate;
3080 /* Save the new rate */
3081 sc->an_config.an_type = AN_RID_GENCONFIG;
3082 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3085 if (otype != sc->an_config.an_opmode ||
3086 orate != sc->an_tx_rate)
3093 an_media_status(ifp, imr)
3095 struct ifmediareq *imr;
3097 struct an_ltv_status status;
3098 struct an_softc *sc = ifp->if_softc;
3100 status.an_len = sizeof(status);
3101 status.an_type = AN_RID_STATUS;
3102 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3103 /* If the status read fails, just lie. */
3104 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3105 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3108 if (sc->an_tx_rate == 0) {
3109 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3110 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3111 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3112 switch (status.an_current_tx_rate) {
3114 imr->ifm_active |= IFM_IEEE80211_DS1;
3117 imr->ifm_active |= IFM_IEEE80211_DS2;
3119 case AN_RATE_5_5MBPS:
3120 imr->ifm_active |= IFM_IEEE80211_DS5;
3122 case AN_RATE_11MBPS:
3123 imr->ifm_active |= IFM_IEEE80211_DS11;
3127 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3130 imr->ifm_status = IFM_AVALID;
3131 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3132 imr->ifm_status |= IFM_ACTIVE;
3135 /********************** Cisco utility support routines *************/
3138 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3143 readrids(ifp, l_ioctl)
3145 struct aironet_ioctl *l_ioctl;
3148 struct an_softc *sc;
3150 switch (l_ioctl->command) {
3152 rid = AN_RID_CAPABILITIES;
3155 rid = AN_RID_GENCONFIG;
3158 rid = AN_RID_SSIDLIST;
3161 rid = AN_RID_APLIST;
3164 rid = AN_RID_DRVNAME;
3167 rid = AN_RID_ENCAPPROTO;
3170 rid = AN_RID_WEP_TEMP;
3173 rid = AN_RID_WEP_PERM;
3176 rid = AN_RID_STATUS;
3179 rid = AN_RID_32BITS_DELTA;
3182 rid = AN_RID_32BITS_CUM;
3189 if (rid == 999) /* Is bad command */
3193 sc->areq.an_len = AN_MAX_DATALEN;
3194 sc->areq.an_type = rid;
3196 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3198 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3200 /* the data contains the length at first */
3201 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3202 sizeof(sc->areq.an_len))) {
3205 /* Just copy the data back */
3206 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3214 writerids(ifp, l_ioctl)
3216 struct aironet_ioctl *l_ioctl;
3218 struct an_softc *sc;
3223 command = l_ioctl->command;
3227 rid = AN_RID_SSIDLIST;
3230 rid = AN_RID_CAPABILITIES;
3233 rid = AN_RID_APLIST;
3236 rid = AN_RID_GENCONFIG;
3239 an_cmd(sc, AN_CMD_ENABLE, 0);
3243 an_cmd(sc, AN_CMD_DISABLE, 0);
3248 * This command merely clears the counts does not actually
3249 * store any data only reads rid. But as it changes the cards
3250 * state, I put it in the writerid routines.
3253 rid = AN_RID_32BITS_DELTACLR;
3255 sc->areq.an_len = AN_MAX_DATALEN;
3256 sc->areq.an_type = rid;
3258 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3259 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3261 /* the data contains the length at first */
3262 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3263 sizeof(sc->areq.an_len))) {
3266 /* Just copy the data */
3267 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3274 rid = AN_RID_WEP_TEMP;
3277 rid = AN_RID_WEP_PERM;
3280 rid = AN_RID_LEAPUSERNAME;
3283 rid = AN_RID_LEAPPASSWORD;
3290 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3292 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3293 sc->areq.an_type = rid;
3295 /* Just copy the data back */
3296 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3299 an_cmd(sc, AN_CMD_DISABLE, 0);
3300 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3301 an_cmd(sc, AN_CMD_ENABLE, 0);
3308 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3312 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3313 #define FLASH_COMMAND 0x7e7e
3314 #define FLASH_SIZE 32 * 1024
3320 struct an_softc *sc = ifp->if_softc;
3322 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3323 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3324 AN_EV_CLR_STUCK_BUSY);
3331 * Wait for busy completion from card wait for delay uSec's Return true for
3332 * success meaning command reg is clear
3340 int statword = 0xffff;
3342 struct an_softc *sc = ifp->if_softc;
3344 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3347 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3349 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3354 return 0 == (AN_CMD_BUSY & statword);
3358 * STEP 1) Disable MAC and do soft reset on card.
3366 struct an_softc *sc = ifp->if_softc;
3370 an_cmd(sc, AN_CMD_DISABLE, 0);
3372 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3373 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3374 sc->an_unit, status);
3377 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3379 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3382 if (!(status = WaitBusy(ifp, 100))) {
3383 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3384 sc->an_unit, status);
3391 * STEP 2) Put the card in legendary flash mode
3399 struct an_softc *sc = ifp->if_softc;
3401 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3402 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3403 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3404 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3407 * mdelay(500); // 500ms delay
3412 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3413 printf("Waitbusy hang after setflash mode\n");
3420 * Get a character from the card matching matchbyte Step 3)
3424 flashgchar(ifp, matchbyte, dwelltime)
3430 unsigned char rbyte = 0;
3432 struct an_softc *sc = ifp->if_softc;
3436 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3438 if (dwelltime && !(0x8000 & rchar)) {
3443 rbyte = 0xff & rchar;
3445 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3446 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3450 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3452 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3454 } while (dwelltime > 0);
3459 * Put character to SWS0 wait for dwelltime x 50us for echo .
3463 flashpchar(ifp, byte, dwelltime)
3469 int pollbusy, waittime;
3470 struct an_softc *sc = ifp->if_softc;
3477 waittime = dwelltime;
3480 * Wait for busy bit d15 to go false indicating buffer empty
3483 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3485 if (pollbusy & 0x8000) {
3492 while (waittime >= 0);
3494 /* timeout for busy clear wait */
3496 if (waittime <= 0) {
3497 printf("an%d: flash putchar busywait timeout! \n",
3502 * Port is clear now write byte and wait for it to echo back
3505 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3508 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3509 } while (dwelltime >= 0 && echo != byte);
3512 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3514 return echo == byte;
3518 * Transfer 32k of firmware data from user buffer to our buffer and send to
3526 unsigned short *bufp;
3528 struct an_softc *sc = ifp->if_softc;
3532 bufp = sc->an_flash_buffer;
3535 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3536 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3538 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3539 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3542 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3543 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3544 ((u_int32_t *)bufp)[nwords] & 0xffff);
3548 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3554 * After flashing restart the card.
3562 struct an_softc *sc = ifp->if_softc;
3564 FLASH_DELAY(1024); /* Added 12/7/00 */
3568 FLASH_DELAY(1024); /* Added 12/7/00 */
3573 * Entry point for flash ioclt.
3577 flashcard(ifp, l_ioctl)
3579 struct aironet_ioctl *l_ioctl;
3582 struct an_softc *sc;
3586 printf("an%d: flashing not supported on MPI 350 yet\n",
3590 status = l_ioctl->command;
3592 switch (l_ioctl->command) {
3594 return cmdreset(ifp);
3597 if (sc->an_flash_buffer) {
3598 free(sc->an_flash_buffer, M_DEVBUF);
3599 sc->an_flash_buffer = NULL;
3601 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3602 if (sc->an_flash_buffer)
3603 return setflashmode(ifp);
3607 case AIROFLSHGCHR: /* Get char from aux */
3608 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3609 z = *(int *)&sc->areq;
3610 if ((status = flashgchar(ifp, z, 8000)) == 1)
3615 case AIROFLSHPCHR: /* Send char to card. */
3616 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3617 z = *(int *)&sc->areq;
3618 if ((status = flashpchar(ifp, z, 8000)) == -1)
3623 case AIROFLPUTBUF: /* Send 32k to card */
3624 if (l_ioctl->len > FLASH_SIZE) {
3625 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3626 l_ioctl->len, FLASH_SIZE);
3629 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3631 if ((status = flashputbuf(ifp)) != 0)
3637 if ((status = flashrestart(ifp)) != 0) {
3638 printf("an%d: FLASHRESTART returned %d\n",
3639 sc->an_unit, status);