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.22 2005/06/03 23:23:03 joerg Exp $
37 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
39 * Written by Bill Paul <wpaul@ctr.columbia.edu>
40 * Electrical Engineering Department
41 * Columbia University, New York City
45 * The Aironet 4500/4800 series cards come in PCMCIA, ISA and PCI form.
46 * This driver supports all three device types (PCI devices are supported
47 * through an extra PCI shim: /sys/dev/an/if_an_pci.c). ISA devices can be
48 * supported either using hard-coded IO port/IRQ settings or via Plug
49 * and Play. The 4500 series devices support 1Mbps and 2Mbps data rates.
50 * The 4800 devices support 1, 2, 5.5 and 11Mbps rates.
52 * Like the WaveLAN/IEEE cards, the Aironet NICs are all essentially
53 * PCMCIA devices. The ISA and PCI cards are a combination of a PCMCIA
54 * device and a PCMCIA to ISA or PCMCIA to PCI adapter card. There are
55 * a couple of important differences though:
57 * - Lucent ISA card looks to the host like a PCMCIA controller with
58 * a PCMCIA WaveLAN card inserted. This means that even desktop
59 * machines need to be configured with PCMCIA support in order to
60 * use WaveLAN/IEEE ISA cards. The Aironet cards on the other hand
61 * actually look like normal ISA and PCI devices to the host, so
62 * no PCMCIA controller support is needed
64 * The latter point results in a small gotcha. The Aironet PCMCIA
65 * cards can be configured for one of two operating modes depending
66 * on how the Vpp1 and Vpp2 programming voltages are set when the
67 * card is activated. In order to put the card in proper PCMCIA
68 * operation (where the CIS table is visible and the interface is
69 * programmed for PCMCIA operation), both Vpp1 and Vpp2 have to be
70 * set to 5 volts. FreeBSD by default doesn't set the Vpp voltages,
71 * which leaves the card in ISA/PCI mode, which prevents it from
72 * being activated as an PCMCIA device.
74 * Note that some PCMCIA controller software packages for Windows NT
75 * fail to set the voltages as well.
77 * The Aironet devices can operate in both station mode and access point
78 * mode. Typically, when programmed for station mode, the card can be set
79 * to automatically perform encapsulation/decapsulation of Ethernet II
80 * and 802.3 frames within 802.11 frames so that the host doesn't have
81 * to do it itself. This driver doesn't program the card that way: the
82 * driver handles all of the encapsulation/decapsulation itself.
88 #define ANCACHE /* enable signal strength cache */
91 #include <sys/param.h>
92 #include <sys/systm.h>
93 #include <sys/sockio.h>
95 #include <sys/kernel.h>
97 #include <sys/ucred.h>
98 #include <sys/socket.h>
100 #include <sys/syslog.h>
102 #include <sys/sysctl.h>
103 #include <machine/clock.h> /* for DELAY */
105 #include <sys/module.h>
106 #include <sys/sysctl.h>
108 #include <machine/bus.h>
109 #include <sys/rman.h>
110 #include <machine/resource.h>
111 #include <sys/malloc.h>
114 #include <net/ifq_var.h>
115 #include <net/if_arp.h>
116 #include <net/ethernet.h>
117 #include <net/if_dl.h>
118 #include <net/if_types.h>
119 #include <net/if_media.h>
120 #include <netproto/802_11/ieee80211.h>
121 #include <netproto/802_11/ieee80211_ioctl.h>
124 #include <netinet/in.h>
125 #include <netinet/in_systm.h>
126 #include <netinet/in_var.h>
127 #include <netinet/ip.h>
132 #include <machine/md_var.h>
134 #include "if_aironet_ieee.h"
135 #include "if_anreg.h"
137 /* These are global because we need them in sys/pci/if_an_p.c. */
138 static void an_reset (struct an_softc *);
139 static int an_init_mpi350_desc (struct an_softc *);
140 static int an_ioctl (struct ifnet *, u_long, caddr_t,
142 static void an_init (void *);
143 static int an_init_tx_ring (struct an_softc *);
144 static void an_start (struct ifnet *);
145 static void an_watchdog (struct ifnet *);
146 static void an_rxeof (struct an_softc *);
147 static void an_txeof (struct an_softc *, int);
149 static void an_promisc (struct an_softc *, int);
150 static int an_cmd (struct an_softc *, int, int);
151 static int an_cmd_struct (struct an_softc *, struct an_command *,
153 static int an_read_record (struct an_softc *, struct an_ltv_gen *);
154 static int an_write_record (struct an_softc *, struct an_ltv_gen *);
155 static int an_read_data (struct an_softc *, int,
157 static int an_write_data (struct an_softc *, int,
159 static int an_seek (struct an_softc *, int, int, int);
160 static int an_alloc_nicmem (struct an_softc *, int, int *);
161 static int an_dma_malloc (struct an_softc *, bus_size_t,
162 struct an_dma_alloc *, int);
163 static void an_dma_free (struct an_softc *,
164 struct an_dma_alloc *);
165 static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
166 static void an_stats_update (void *);
167 static void an_setdef (struct an_softc *, struct an_req *);
169 static void an_cache_store (struct an_softc *, struct mbuf *,
173 /* function definitions for use with the Cisco's Linux configuration
177 static int readrids (struct ifnet*, struct aironet_ioctl*);
178 static int writerids (struct ifnet*, struct aironet_ioctl*);
179 static int flashcard (struct ifnet*, struct aironet_ioctl*);
181 static int cmdreset (struct ifnet *);
182 static int setflashmode (struct ifnet *);
183 static int flashgchar (struct ifnet *,int,int);
184 static int flashpchar (struct ifnet *,int,int);
185 static int flashputbuf (struct ifnet *);
186 static int flashrestart (struct ifnet *);
187 static int WaitBusy (struct ifnet *, int);
188 static int unstickbusy (struct ifnet *);
190 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
193 static int an_media_change (struct ifnet *);
194 static void an_media_status (struct ifnet *, struct ifmediareq *);
196 static int an_dump = 0;
197 static int an_cache_mode = 0;
203 static char an_conf[256];
204 static char an_conf_cache[256];
206 DECLARE_DUMMY_MODULE(if_an);
210 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
213 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
222 strcpy(an_conf, "off");
225 strcpy(an_conf, "type");
228 strcpy(an_conf, "dump");
231 snprintf(an_conf, 5, "%x", an_dump);
235 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
237 if (strncmp(an_conf,"off", 3) == 0) {
240 if (strncmp(an_conf,"dump", 4) == 0) {
243 if (strncmp(an_conf,"type", 4) == 0) {
249 if ((*s >= '0') && (*s <= '9')) {
250 r = r * 16 + (*s - '0');
251 } else if ((*s >= 'a') && (*s <= 'f')) {
252 r = r * 16 + (*s - 'a' + 10);
260 printf("Sysctl changed for Aironet driver\n");
265 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
266 0, sizeof(an_conf), sysctl_an_dump, "A", "");
269 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
273 last = an_cache_mode;
275 switch (an_cache_mode) {
277 strcpy(an_conf_cache, "per");
280 strcpy(an_conf_cache, "raw");
283 strcpy(an_conf_cache, "dbm");
287 error = sysctl_handle_string(oidp, an_conf_cache,
288 sizeof(an_conf_cache), req);
290 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
293 if (strncmp(an_conf_cache,"per", 3) == 0) {
296 if (strncmp(an_conf_cache,"raw", 3) == 0) {
303 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
304 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
307 * We probe for an Aironet 4500/4800 card by attempting to
308 * read the default SSID list. On reset, the first entry in
309 * the SSID list will contain the name "tsunami." If we don't
310 * find this, then there's no card present.
316 struct an_softc *sc = device_get_softc(dev);
317 struct an_ltv_ssidlist ssid;
320 bzero((char *)&ssid, sizeof(ssid));
322 error = an_alloc_port(dev, 0, AN_IOSIZ);
326 /* can't do autoprobing */
327 if (rman_get_start(sc->port_res) == -1)
331 * We need to fake up a softc structure long enough
332 * to be able to issue commands and call some of the
335 sc->an_bhandle = rman_get_bushandle(sc->port_res);
336 sc->an_btag = rman_get_bustag(sc->port_res);
338 ssid.an_len = sizeof(ssid);
339 ssid.an_type = AN_RID_SSIDLIST;
341 /* Make sure interrupts are disabled. */
342 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
343 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
345 if_initname(&sc->arpcom.ac_if, device_get_name(dev),
346 device_get_unit(dev));
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_any(dev, SYS_RES_IRQ, &rid,
439 (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 if_printf(&sc->arpcom.ac_if,
592 "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 if_printf(&sc->arpcom.ac_if,
621 "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 if_printf(&sc->arpcom.ac_if,
651 "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, dev, flags)
674 struct ifnet *ifp = &sc->arpcom.ac_if;
677 callout_init(&sc->an_stat_timer);
679 sc->an_associated = 0;
681 sc->an_was_monitor = 0;
682 sc->an_flash_buffer = NULL;
685 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
690 error = an_init_mpi350_desc(sc);
695 /* Load factory config */
696 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
697 device_printf(dev, "failed to load config data\n");
701 /* Read the current configuration */
702 sc->an_config.an_type = AN_RID_GENCONFIG;
703 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
704 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
705 device_printf(dev, "read record failed\n");
709 /* Read the card capabilities */
710 sc->an_caps.an_type = AN_RID_CAPABILITIES;
711 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
712 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
713 device_printf(dev, "read record failed\n");
718 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
719 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
720 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
721 device_printf(dev, "read record failed\n");
726 sc->an_aplist.an_type = AN_RID_APLIST;
727 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
728 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
729 device_printf(dev, "read record failed\n");
734 /* Read the RSSI <-> dBm map */
735 sc->an_have_rssimap = 0;
736 if (sc->an_caps.an_softcaps & 8) {
737 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
738 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
739 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
740 device_printf(dev, "unable to get RSSI <-> dBM map\n");
742 device_printf(dev, "got RSSI <-> dBM map\n");
743 sc->an_have_rssimap = 1;
746 device_printf(dev, "no RSSI <-> dBM map\n");
750 ifp->if_mtu = ETHERMTU;
751 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
752 ifp->if_ioctl = an_ioctl;
753 ifp->if_start = an_start;
754 ifp->if_watchdog = an_watchdog;
755 ifp->if_init = an_init;
756 ifp->if_baudrate = 10000000;
757 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
758 ifq_set_ready(&ifp->if_snd);
760 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
761 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
762 sizeof(AN_DEFAULT_NODENAME) - 1);
764 bzero(sc->an_ssidlist.an_ssid1, sizeof(sc->an_ssidlist.an_ssid1));
765 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_ssid1,
766 sizeof(AN_DEFAULT_NETNAME) - 1);
767 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME);
769 sc->an_config.an_opmode =
770 AN_OPMODE_INFRASTRUCTURE_STATION;
773 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
775 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
776 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
777 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
778 IFM_IEEE80211_ADHOC, 0), 0);
779 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
780 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
781 IFM_IEEE80211_ADHOC, 0), 0);
782 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
783 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
784 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
785 IFM_IEEE80211_ADHOC, 0), 0);
786 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
788 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
789 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
790 IFM_IEEE80211_ADHOC, 0), 0);
791 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
793 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
794 IFM_IEEE80211_ADHOC, 0), 0);
795 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
797 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
801 * Call MI attach routine.
803 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
813 struct ether_header *eh;
814 struct ieee80211_frame *ih;
815 struct an_rxframe rx_frame;
816 struct an_rxframe_802_3 rx_frame_802_3;
818 int len, id, error = 0, i, count = 0;
819 int ieee80211_header_len;
822 struct an_card_rx_desc an_rx_desc;
825 ifp = &sc->arpcom.ac_if;
828 id = CSR_READ_2(sc, AN_RX_FID);
830 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
831 /* read raw 802.11 packet */
832 bpf_buf = sc->buf_802_11;
835 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
842 * skip beacon by default since this increases the
846 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
847 (rx_frame.an_frame_ctl &
848 IEEE80211_FC0_SUBTYPE_BEACON)) {
852 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
853 len = rx_frame.an_rx_payload_len
855 /* Check for insane frame length */
856 if (len > sizeof(sc->buf_802_11)) {
858 "oversized packet received "
859 "(%d, %d)\n", len, MCLBYTES);
864 bcopy((char *)&rx_frame,
865 bpf_buf, sizeof(rx_frame));
867 error = an_read_data(sc, id, sizeof(rx_frame),
868 (caddr_t)bpf_buf+sizeof(rx_frame),
869 rx_frame.an_rx_payload_len);
871 fc1=rx_frame.an_frame_ctl >> 8;
872 ieee80211_header_len =
873 sizeof(struct ieee80211_frame);
874 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
875 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
876 ieee80211_header_len += ETHER_ADDR_LEN;
879 len = rx_frame.an_rx_payload_len
880 + ieee80211_header_len;
881 /* Check for insane frame length */
882 if (len > sizeof(sc->buf_802_11)) {
884 "oversized packet received "
885 "(%d, %d)\n", len, MCLBYTES);
890 ih = (struct ieee80211_frame *)bpf_buf;
892 bcopy((char *)&rx_frame.an_frame_ctl,
893 (char *)ih, ieee80211_header_len);
895 error = an_read_data(sc, id, sizeof(rx_frame) +
897 (caddr_t)ih +ieee80211_header_len,
898 rx_frame.an_rx_payload_len);
900 BPF_TAP(ifp, bpf_buf, len);
902 MGETHDR(m, M_NOWAIT, MT_DATA);
908 if (!(m->m_flags & M_EXT)) {
913 m->m_pkthdr.rcvif = ifp;
914 /* Read Ethernet encapsulated packet */
917 /* Read NIC frame header */
918 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
924 /* Read in the 802_3 frame header */
925 if (an_read_data(sc, id, 0x34,
926 (caddr_t)&rx_frame_802_3,
927 sizeof(rx_frame_802_3))) {
931 if (rx_frame_802_3.an_rx_802_3_status != 0) {
935 /* Check for insane frame length */
936 len = rx_frame_802_3.an_rx_802_3_payload_len;
937 if (len > sizeof(sc->buf_802_11)) {
939 "oversized packet received (%d, %d)\n",
944 m->m_pkthdr.len = m->m_len =
945 rx_frame_802_3.an_rx_802_3_payload_len + 12;
947 eh = mtod(m, struct ether_header *);
949 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
950 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
951 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
952 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
954 /* in mbuf header type is just before payload */
955 error = an_read_data(sc, id, 0x44,
956 (caddr_t)&(eh->ether_type),
957 rx_frame_802_3.an_rx_802_3_payload_len);
967 an_cache_store(sc, m,
968 rx_frame.an_rx_signal_strength,
971 (*ifp->if_input)(ifp, m);
974 } else { /* MPI-350 */
975 for (count = 0; count < AN_MAX_RX_DESC; count++){
976 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
977 ((u_int32_t*)&an_rx_desc)[i]
978 = CSR_MEM_AUX_READ_4(sc,
980 + (count * sizeof(an_rx_desc))
983 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
984 buf = sc->an_rx_buffer[count].an_dma_vaddr;
986 MGETHDR(m, M_NOWAIT, MT_DATA);
992 if (!(m->m_flags & M_EXT)) {
997 m->m_pkthdr.rcvif = ifp;
998 /* Read Ethernet encapsulated packet */
1001 * No ANCACHE support since we just get back
1002 * an Ethernet packet no 802.11 info
1006 /* Read NIC frame header */
1007 bcopy(buf, (caddr_t)&rx_frame,
1011 /* Check for insane frame length */
1012 len = an_rx_desc.an_len + 12;
1013 if (len > MCLBYTES) {
1015 "oversized packet received "
1016 "(%d, %d)\n", len, MCLBYTES);
1021 m->m_pkthdr.len = m->m_len =
1022 an_rx_desc.an_len + 12;
1024 eh = mtod(m, struct ether_header *);
1026 bcopy(buf, (char *)eh,
1033 an_cache_store(sc, m,
1034 rx_frame.an_rx_signal_strength,
1038 (*ifp->if_input)(ifp, m);
1040 an_rx_desc.an_valid = 1;
1041 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1042 an_rx_desc.an_done = 0;
1043 an_rx_desc.an_phys =
1044 sc->an_rx_buffer[count].an_dma_paddr;
1046 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1047 CSR_MEM_AUX_WRITE_4(sc,
1049 + (count * sizeof(an_rx_desc))
1051 ((u_int32_t*)&an_rx_desc)[i]);
1054 if_printf(ifp, "Didn't get valid RX packet "
1057 an_rx_desc.an_valid,
1065 an_txeof(sc, status)
1066 struct an_softc *sc;
1072 ifp = &sc->arpcom.ac_if;
1075 ifp->if_flags &= ~IFF_OACTIVE;
1078 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1080 if (status & AN_EV_TX_EXC) {
1085 for (i = 0; i < AN_TX_RING_CNT; i++) {
1086 if (id == sc->an_rdata.an_tx_ring[i]) {
1087 sc->an_rdata.an_tx_ring[i] = 0;
1092 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1093 } else { /* MPI 350 */
1094 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1095 if (sc->an_rdata.an_tx_prod ==
1096 sc->an_rdata.an_tx_cons)
1097 sc->an_rdata.an_tx_empty = 1;
1104 * We abuse the stats updater to check the current NIC status. This
1105 * is important because we don't want to allow transmissions until
1106 * the NIC has synchronized to the current cell (either as the master
1107 * in an ad-hoc group, or as a station connected to an access point).
1110 an_stats_update(xsc)
1113 struct an_softc *sc;
1120 ifp = &sc->arpcom.ac_if;
1122 sc->an_status.an_type = AN_RID_STATUS;
1123 sc->an_status.an_len = sizeof(struct an_ltv_status);
1124 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1126 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1127 sc->an_associated = 1;
1129 sc->an_associated = 0;
1131 /* Don't do this while we're transmitting */
1132 if (ifp->if_flags & IFF_OACTIVE) {
1133 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1138 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1139 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1140 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1142 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1152 struct an_softc *sc;
1156 sc = (struct an_softc*)xsc;
1161 ifp = &sc->arpcom.ac_if;
1163 /* Disable interrupts. */
1164 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1166 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1167 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
1169 if (status & AN_EV_AWAKE) {
1170 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
1173 if (status & AN_EV_LINKSTAT) {
1174 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1175 == AN_LINKSTAT_ASSOCIATED)
1176 sc->an_associated = 1;
1178 sc->an_associated = 0;
1179 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1182 if (status & AN_EV_RX) {
1184 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1187 if (status & AN_EV_TX) {
1188 an_txeof(sc, status);
1189 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1192 if (status & AN_EV_TX_EXC) {
1193 an_txeof(sc, status);
1194 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1197 if (status & AN_EV_ALLOC)
1198 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1200 /* Re-enable interrupts. */
1201 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1203 if ((ifp->if_flags & IFF_UP) && !ifq_is_empty(&ifp->if_snd))
1210 an_cmd_struct(sc, cmd, reply)
1211 struct an_softc *sc;
1212 struct an_command *cmd;
1213 struct an_reply *reply;
1217 for (i = 0; i != AN_TIMEOUT; i++) {
1218 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1223 if( i == AN_TIMEOUT) {
1228 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1229 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1230 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1231 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1233 for (i = 0; i < AN_TIMEOUT; i++) {
1234 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1239 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1240 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1241 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1242 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1244 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1245 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1247 /* Ack the command */
1248 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1250 if (i == AN_TIMEOUT)
1257 an_cmd(sc, cmd, val)
1258 struct an_softc *sc;
1264 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1265 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1266 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1267 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1269 for (i = 0; i < AN_TIMEOUT; i++) {
1270 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1273 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1274 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1278 for (i = 0; i < AN_TIMEOUT; i++) {
1279 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1280 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1281 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1282 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1283 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1287 /* Ack the command */
1288 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1290 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1291 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1293 if (i == AN_TIMEOUT)
1300 * This reset sequence may look a little strange, but this is the
1301 * most reliable method I've found to really kick the NIC in the
1302 * head and force it to reboot correctly.
1306 struct an_softc *sc;
1311 an_cmd(sc, AN_CMD_ENABLE, 0);
1312 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1313 an_cmd(sc, AN_CMD_NOOP2, 0);
1315 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1316 if_printf(&sc->arpcom.ac_if, "reset failed\n");
1318 an_cmd(sc, AN_CMD_DISABLE, 0);
1324 * Read an LTV record from the NIC.
1327 an_read_record(sc, ltv)
1328 struct an_softc *sc;
1329 struct an_ltv_gen *ltv;
1331 struct an_ltv_gen *an_ltv;
1332 struct an_card_rid_desc an_rid_desc;
1333 struct an_command cmd;
1334 struct an_reply reply;
1339 if (ltv->an_len < 4 || ltv->an_type == 0)
1343 /* Tell the NIC to enter record read mode. */
1344 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1345 if_printf(&sc->arpcom.ac_if, "RID access failed\n");
1349 /* Seek to the record. */
1350 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1351 if_printf(&sc->arpcom.ac_if, "seek to record failed\n");
1356 * Read the length and record type and make sure they
1357 * match what we expect (this verifies that we have enough
1358 * room to hold all of the returned data).
1359 * Length includes type but not length.
1361 len = CSR_READ_2(sc, AN_DATA1);
1362 if (len > (ltv->an_len - 2)) {
1363 if_printf(&sc->arpcom.ac_if,
1364 "record length mismatch -- expected %d, "
1365 "got %d for Rid %x\n",
1366 ltv->an_len - 2, len, ltv->an_type);
1367 len = ltv->an_len - 2;
1369 ltv->an_len = len + 2;
1372 /* Now read the data. */
1373 len -= 2; /* skip the type */
1375 for (i = len; i > 1; i -= 2)
1376 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1378 ptr2 = (u_int8_t *)ptr;
1379 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1381 } else { /* MPI-350 */
1382 an_rid_desc.an_valid = 1;
1383 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1384 an_rid_desc.an_rid = 0;
1385 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1386 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1388 bzero(&cmd, sizeof(cmd));
1389 bzero(&reply, sizeof(reply));
1390 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1391 cmd.an_parm0 = ltv->an_type;
1393 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1394 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1395 ((u_int32_t*)&an_rid_desc)[i]);
1397 if (an_cmd_struct(sc, &cmd, &reply)
1398 || reply.an_status & AN_CMD_QUAL_MASK) {
1399 if_printf(&sc->arpcom.ac_if,
1400 "failed to read RID %x %x %x %x %x, %d\n",
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 if_printf(&sc->arpcom.ac_if,
1504 "failed to write RID 1 %x %x %x %x %x, %d\n",
1514 ptr = (u_int16_t *)buf;
1516 if (reply.an_status & AN_CMD_QUAL_MASK) {
1517 if_printf(&sc->arpcom.ac_if,
1518 "failed to write RID 2 %x %x %x %x %x, %d\n",
1533 an_dump_record(sc, ltv, string)
1534 struct an_softc *sc;
1535 struct an_ltv_gen *ltv;
1544 len = ltv->an_len - 4;
1545 if_printf(&sc->arpcom.ac_if, "RID %4x, Length %4d, Mode %s\n",
1546 ltv->an_type, ltv->an_len - 4, string);
1548 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1549 if_printf(&sc->arpcom.ac_if, "\t");
1550 bzero(buf,sizeof(buf));
1552 ptr2 = (u_int8_t *)<v->an_val;
1553 for (i = len; i > 0; i--) {
1554 printf("%02x ", *ptr2);
1557 if (temp >= ' ' && temp <= '~')
1559 else if (temp >= 'A' && temp <= 'Z')
1563 if (++count == 16) {
1566 if_printf(&sc->arpcom.ac_if, "\t");
1567 bzero(buf,sizeof(buf));
1570 for (; count != 16; count++) {
1573 printf(" %s\n",buf);
1578 an_seek(sc, id, off, chan)
1579 struct an_softc *sc;
1595 if_printf(&sc->arpcom.ac_if, "invalid data path: %x\n", chan);
1599 CSR_WRITE_2(sc, selreg, id);
1600 CSR_WRITE_2(sc, offreg, off);
1602 for (i = 0; i < AN_TIMEOUT; i++) {
1603 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1607 if (i == AN_TIMEOUT)
1614 an_read_data(sc, id, off, buf, len)
1615 struct an_softc *sc;
1625 if (an_seek(sc, id, off, AN_BAP1))
1629 ptr = (u_int16_t *)buf;
1630 for (i = len; i > 1; i -= 2)
1631 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1633 ptr2 = (u_int8_t *)ptr;
1634 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1641 an_write_data(sc, id, off, buf, len)
1642 struct an_softc *sc;
1652 if (an_seek(sc, id, off, AN_BAP0))
1656 ptr = (u_int16_t *)buf;
1657 for (i = len; i > 1; i -= 2)
1658 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1660 ptr2 = (u_int8_t *)ptr;
1661 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1668 * Allocate a region of memory inside the NIC and zero
1672 an_alloc_nicmem(sc, len, id)
1673 struct an_softc *sc;
1679 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1680 if_printf(&sc->arpcom.ac_if,
1681 "failed to allocate %d bytes on NIC\n", len);
1685 for (i = 0; i < AN_TIMEOUT; i++) {
1686 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1690 if (i == AN_TIMEOUT)
1693 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1694 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1696 if (an_seek(sc, *id, 0, AN_BAP0))
1699 for (i = 0; i < len / 2; i++)
1700 CSR_WRITE_2(sc, AN_DATA0, 0);
1707 struct an_softc *sc;
1708 struct an_req *areq;
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 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1724 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
1726 bcopy((char *)cfg, (char *)&sc->an_config,
1727 sizeof(struct an_ltv_genconfig));
1729 case AN_RID_SSIDLIST:
1730 ssid = (struct an_ltv_ssidlist *)areq;
1731 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1732 sizeof(struct an_ltv_ssidlist));
1735 ap = (struct an_ltv_aplist *)areq;
1736 bcopy((char *)ap, (char *)&sc->an_aplist,
1737 sizeof(struct an_ltv_aplist));
1739 case AN_RID_TX_SPEED:
1740 sp = (struct an_ltv_gen *)areq;
1741 sc->an_tx_rate = sp->an_val;
1743 /* Read the current configuration */
1744 sc->an_config.an_type = AN_RID_GENCONFIG;
1745 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1746 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1747 cfg = &sc->an_config;
1749 /* clear other rates and set the only one we want */
1750 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1751 cfg->an_rates[0] = sc->an_tx_rate;
1753 /* Save the new rate */
1754 sc->an_config.an_type = AN_RID_GENCONFIG;
1755 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1757 case AN_RID_WEP_TEMP:
1758 /* Cache the temp keys */
1760 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1761 sizeof(struct an_ltv_key));
1762 case AN_RID_WEP_PERM:
1763 case AN_RID_LEAPUSERNAME:
1764 case AN_RID_LEAPPASSWORD:
1765 /* Disable the MAC. */
1766 an_cmd(sc, AN_CMD_DISABLE, 0);
1769 an_write_record(sc, (struct an_ltv_gen *)areq);
1771 /* Turn the MAC back on. */
1772 an_cmd(sc, AN_CMD_ENABLE, 0);
1775 case AN_RID_MONITOR_MODE:
1776 cfg = (struct an_ltv_genconfig *)areq;
1778 if (ng_ether_detach_p != NULL)
1779 (*ng_ether_detach_p) (ifp);
1780 sc->an_monitor = cfg->an_len;
1782 if (sc->an_monitor & AN_MONITOR) {
1783 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1784 bpfattach(ifp, DLT_AIRONET_HEADER,
1785 sizeof(struct ether_header));
1787 bpfattach(ifp, DLT_IEEE802_11,
1788 sizeof(struct ether_header));
1791 bpfattach(ifp, DLT_EN10MB,
1792 sizeof(struct ether_header));
1793 if (ng_ether_attach_p != NULL)
1794 (*ng_ether_attach_p) (ifp);
1798 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1804 /* Reinitialize the card. */
1812 * Derived from Linux driver to enable promiscious mode.
1816 an_promisc(sc, promisc)
1817 struct an_softc *sc;
1820 if (sc->an_was_monitor)
1823 an_init_mpi350_desc(sc);
1824 if (sc->an_monitor || sc->an_was_monitor)
1827 sc->an_was_monitor = sc->an_monitor;
1828 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1834 an_ioctl(ifp, command, data, cr)
1843 struct an_softc *sc;
1845 struct ieee80211req *ireq;
1846 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1848 struct an_ltv_genconfig *config;
1849 struct an_ltv_key *key;
1850 struct an_ltv_status *status;
1851 struct an_ltv_ssidlist *ssids;
1853 struct aironet_ioctl l_ioctl;
1857 ifr = (struct ifreq *)data;
1858 ireq = (struct ieee80211req *)data;
1860 config = (struct an_ltv_genconfig *)&sc->areq;
1861 key = (struct an_ltv_key *)&sc->areq;
1862 status = (struct an_ltv_status *)&sc->areq;
1863 ssids = (struct an_ltv_ssidlist *)&sc->areq;
1872 if (ifp->if_flags & IFF_UP) {
1873 if (ifp->if_flags & IFF_RUNNING &&
1874 ifp->if_flags & IFF_PROMISC &&
1875 !(sc->an_if_flags & IFF_PROMISC)) {
1877 } else if (ifp->if_flags & IFF_RUNNING &&
1878 !(ifp->if_flags & IFF_PROMISC) &&
1879 sc->an_if_flags & IFF_PROMISC) {
1884 if (ifp->if_flags & IFF_RUNNING)
1887 sc->an_if_flags = ifp->if_flags;
1892 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1896 /* The Aironet has no multicast filter. */
1900 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1904 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1905 error = suser_cred(cr, NULL_CRED_OKAY);
1908 sc->an_sigitems = sc->an_nextitem = 0;
1910 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1911 char *pt = (char *)&sc->areq.an_val;
1912 bcopy((char *)&sc->an_sigitems, (char *)pt,
1915 sc->areq.an_len = sizeof(int) / 2;
1916 bcopy((char *)&sc->an_sigcache, (char *)pt,
1917 sizeof(struct an_sigcache) * sc->an_sigitems);
1918 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1919 sc->an_sigitems) / 2) + 1;
1922 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1926 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1929 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1931 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1934 an_setdef(sc, &sc->areq);
1936 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1937 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1939 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1940 mode = l_ioctl.command;
1942 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1943 error = readrids(ifp, &l_ioctl);
1944 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1945 error = writerids(ifp, &l_ioctl);
1946 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1947 error = flashcard(ifp, &l_ioctl);
1952 /* copy out the updated command info */
1953 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1956 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1957 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1959 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1960 l_ioctl.command = 0;
1962 copyout(&error, l_ioctl.data, sizeof(error));
1966 sc->areq.an_len = sizeof(sc->areq);
1967 /* was that a good idea DJA we are doing a short-cut */
1968 switch (ireq->i_type) {
1969 case IEEE80211_IOC_SSID:
1970 if (ireq->i_val == -1) {
1971 sc->areq.an_type = AN_RID_STATUS;
1972 if (an_read_record(sc,
1973 (struct an_ltv_gen *)&sc->areq)) {
1977 len = status->an_ssidlen;
1978 tmpptr = status->an_ssid;
1979 } else if (ireq->i_val >= 0) {
1980 sc->areq.an_type = AN_RID_SSIDLIST;
1981 if (an_read_record(sc,
1982 (struct an_ltv_gen *)&sc->areq)) {
1986 if (ireq->i_val == 0) {
1987 len = ssids->an_ssid1_len;
1988 tmpptr = ssids->an_ssid1;
1989 } else if (ireq->i_val == 1) {
1990 len = ssids->an_ssid2_len;
1991 tmpptr = ssids->an_ssid2;
1992 } else if (ireq->i_val == 2) {
1993 len = ssids->an_ssid3_len;
1994 tmpptr = ssids->an_ssid3;
2003 if (len > IEEE80211_NWID_LEN) {
2008 bzero(tmpstr, IEEE80211_NWID_LEN);
2009 bcopy(tmpptr, tmpstr, len);
2010 error = copyout(tmpstr, ireq->i_data,
2011 IEEE80211_NWID_LEN);
2013 case IEEE80211_IOC_NUMSSIDS:
2016 case IEEE80211_IOC_WEP:
2017 sc->areq.an_type = AN_RID_ACTUALCFG;
2018 if (an_read_record(sc,
2019 (struct an_ltv_gen *)&sc->areq)) {
2023 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2024 if (config->an_authtype &
2025 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2026 ireq->i_val = IEEE80211_WEP_MIXED;
2028 ireq->i_val = IEEE80211_WEP_ON;
2030 ireq->i_val = IEEE80211_WEP_OFF;
2033 case IEEE80211_IOC_WEPKEY:
2035 * XXX: I'm not entierly convinced this is
2036 * correct, but it's what is implemented in
2037 * ancontrol so it will have to do until we get
2038 * access to actual Cisco code.
2040 if (ireq->i_val < 0 || ireq->i_val > 8) {
2045 if (ireq->i_val < 5) {
2046 sc->areq.an_type = AN_RID_WEP_TEMP;
2047 for (i = 0; i < 5; i++) {
2048 if (an_read_record(sc,
2049 (struct an_ltv_gen *)&sc->areq)) {
2053 if (key->kindex == 0xffff)
2055 if (key->kindex == ireq->i_val)
2057 /* Required to get next entry */
2058 sc->areq.an_type = AN_RID_WEP_PERM;
2063 /* We aren't allowed to read the value of the
2064 * key from the card so we just output zeros
2065 * like we would if we could read the card, but
2066 * denied the user access.
2070 error = copyout(tmpstr, ireq->i_data, len);
2072 case IEEE80211_IOC_NUMWEPKEYS:
2073 ireq->i_val = 9; /* include home key */
2075 case IEEE80211_IOC_WEPTXKEY:
2077 * For some strange reason, you have to read all
2078 * keys before you can read the txkey.
2080 sc->areq.an_type = AN_RID_WEP_TEMP;
2081 for (i = 0; i < 5; i++) {
2082 if (an_read_record(sc,
2083 (struct an_ltv_gen *) &sc->areq)) {
2087 if (key->kindex == 0xffff)
2089 /* Required to get next entry */
2090 sc->areq.an_type = AN_RID_WEP_PERM;
2095 sc->areq.an_type = AN_RID_WEP_PERM;
2096 key->kindex = 0xffff;
2097 if (an_read_record(sc,
2098 (struct an_ltv_gen *)&sc->areq)) {
2102 ireq->i_val = key->mac[0];
2104 * Check for home mode. Map home mode into
2105 * 5th key since that is how it is stored on
2108 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2109 sc->areq.an_type = AN_RID_GENCONFIG;
2110 if (an_read_record(sc,
2111 (struct an_ltv_gen *)&sc->areq)) {
2115 if (config->an_home_product & AN_HOME_NETWORK)
2118 case IEEE80211_IOC_AUTHMODE:
2119 sc->areq.an_type = AN_RID_ACTUALCFG;
2120 if (an_read_record(sc,
2121 (struct an_ltv_gen *)&sc->areq)) {
2125 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2127 ireq->i_val = IEEE80211_AUTH_NONE;
2128 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2130 ireq->i_val = IEEE80211_AUTH_OPEN;
2131 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2132 AN_AUTHTYPE_SHAREDKEY) {
2133 ireq->i_val = IEEE80211_AUTH_SHARED;
2137 case IEEE80211_IOC_STATIONNAME:
2138 sc->areq.an_type = AN_RID_ACTUALCFG;
2139 if (an_read_record(sc,
2140 (struct an_ltv_gen *)&sc->areq)) {
2144 ireq->i_len = sizeof(config->an_nodename);
2145 tmpptr = config->an_nodename;
2146 bzero(tmpstr, IEEE80211_NWID_LEN);
2147 bcopy(tmpptr, tmpstr, ireq->i_len);
2148 error = copyout(tmpstr, ireq->i_data,
2149 IEEE80211_NWID_LEN);
2151 case IEEE80211_IOC_CHANNEL:
2152 sc->areq.an_type = AN_RID_STATUS;
2153 if (an_read_record(sc,
2154 (struct an_ltv_gen *)&sc->areq)) {
2158 ireq->i_val = status->an_cur_channel;
2160 case IEEE80211_IOC_POWERSAVE:
2161 sc->areq.an_type = AN_RID_ACTUALCFG;
2162 if (an_read_record(sc,
2163 (struct an_ltv_gen *)&sc->areq)) {
2167 if (config->an_psave_mode == AN_PSAVE_NONE) {
2168 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2169 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2170 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2171 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2172 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2173 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2174 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2178 case IEEE80211_IOC_POWERSAVESLEEP:
2179 sc->areq.an_type = AN_RID_ACTUALCFG;
2180 if (an_read_record(sc,
2181 (struct an_ltv_gen *)&sc->areq)) {
2185 ireq->i_val = config->an_listen_interval;
2190 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
2192 sc->areq.an_len = sizeof(sc->areq);
2194 * We need a config structure for everything but the WEP
2195 * key management and SSIDs so we get it now so avoid
2196 * duplicating this code every time.
2198 if (ireq->i_type != IEEE80211_IOC_SSID &&
2199 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2200 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2201 sc->areq.an_type = AN_RID_GENCONFIG;
2202 if (an_read_record(sc,
2203 (struct an_ltv_gen *)&sc->areq)) {
2208 switch (ireq->i_type) {
2209 case IEEE80211_IOC_SSID:
2210 sc->areq.an_type = AN_RID_SSIDLIST;
2211 if (an_read_record(sc,
2212 (struct an_ltv_gen *)&sc->areq)) {
2216 if (ireq->i_len > IEEE80211_NWID_LEN) {
2220 switch (ireq->i_val) {
2222 error = copyin(ireq->i_data,
2223 ssids->an_ssid1, ireq->i_len);
2224 ssids->an_ssid1_len = ireq->i_len;
2227 error = copyin(ireq->i_data,
2228 ssids->an_ssid2, ireq->i_len);
2229 ssids->an_ssid2_len = ireq->i_len;
2232 error = copyin(ireq->i_data,
2233 ssids->an_ssid3, ireq->i_len);
2234 ssids->an_ssid3_len = ireq->i_len;
2241 case IEEE80211_IOC_WEP:
2242 switch (ireq->i_val) {
2243 case IEEE80211_WEP_OFF:
2244 config->an_authtype &=
2245 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2246 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2248 case IEEE80211_WEP_ON:
2249 config->an_authtype |=
2250 AN_AUTHTYPE_PRIVACY_IN_USE;
2251 config->an_authtype &=
2252 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2254 case IEEE80211_WEP_MIXED:
2255 config->an_authtype |=
2256 AN_AUTHTYPE_PRIVACY_IN_USE |
2257 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2264 case IEEE80211_IOC_WEPKEY:
2265 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2270 error = copyin(ireq->i_data, tmpstr, 13);
2274 * Map the 9th key into the home mode
2275 * since that is how it is stored on
2278 bzero(&sc->areq, sizeof(struct an_ltv_key));
2279 sc->areq.an_len = sizeof(struct an_ltv_key);
2280 key->mac[0] = 1; /* The others are 0. */
2281 if (ireq->i_val < 4) {
2282 sc->areq.an_type = AN_RID_WEP_TEMP;
2283 key->kindex = ireq->i_val;
2285 sc->areq.an_type = AN_RID_WEP_PERM;
2286 key->kindex = ireq->i_val - 4;
2288 key->klen = ireq->i_len;
2289 bcopy(tmpstr, key->key, key->klen);
2291 case IEEE80211_IOC_WEPTXKEY:
2292 if (ireq->i_val < 0 || ireq->i_val > 4) {
2298 * Map the 5th key into the home mode
2299 * since that is how it is stored on
2302 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2303 sc->areq.an_type = AN_RID_ACTUALCFG;
2304 if (an_read_record(sc,
2305 (struct an_ltv_gen *)&sc->areq)) {
2309 if (ireq->i_val == 4) {
2310 config->an_home_product |= AN_HOME_NETWORK;
2313 config->an_home_product &= ~AN_HOME_NETWORK;
2316 sc->an_config.an_home_product
2317 = config->an_home_product;
2319 /* update configuration */
2322 bzero(&sc->areq, sizeof(struct an_ltv_key));
2323 sc->areq.an_len = sizeof(struct an_ltv_key);
2324 sc->areq.an_type = AN_RID_WEP_PERM;
2325 key->kindex = 0xffff;
2326 key->mac[0] = ireq->i_val;
2328 case IEEE80211_IOC_AUTHMODE:
2329 switch (ireq->i_val) {
2330 case IEEE80211_AUTH_NONE:
2331 config->an_authtype = AN_AUTHTYPE_NONE |
2332 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2334 case IEEE80211_AUTH_OPEN:
2335 config->an_authtype = AN_AUTHTYPE_OPEN |
2336 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2338 case IEEE80211_AUTH_SHARED:
2339 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2340 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2346 case IEEE80211_IOC_STATIONNAME:
2347 if (ireq->i_len > 16) {
2351 bzero(config->an_nodename, 16);
2352 error = copyin(ireq->i_data,
2353 config->an_nodename, ireq->i_len);
2355 case IEEE80211_IOC_CHANNEL:
2357 * The actual range is 1-14, but if you set it
2358 * to 0 you get the default so we let that work
2361 if (ireq->i_val < 0 || ireq->i_val >14) {
2365 config->an_ds_channel = ireq->i_val;
2367 case IEEE80211_IOC_POWERSAVE:
2368 switch (ireq->i_val) {
2369 case IEEE80211_POWERSAVE_OFF:
2370 config->an_psave_mode = AN_PSAVE_NONE;
2372 case IEEE80211_POWERSAVE_CAM:
2373 config->an_psave_mode = AN_PSAVE_CAM;
2375 case IEEE80211_POWERSAVE_PSP:
2376 config->an_psave_mode = AN_PSAVE_PSP;
2378 case IEEE80211_POWERSAVE_PSP_CAM:
2379 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2386 case IEEE80211_IOC_POWERSAVESLEEP:
2387 config->an_listen_interval = ireq->i_val;
2392 an_setdef(sc, &sc->areq);
2395 error = ether_ioctl(ifp, command, data);
2406 struct an_softc *sc;
2415 for (i = 0; i < AN_TX_RING_CNT; i++) {
2416 if (an_alloc_nicmem(sc, 1518 +
2419 sc->an_rdata.an_tx_fids[i] = id;
2420 sc->an_rdata.an_tx_ring[i] = 0;
2424 sc->an_rdata.an_tx_prod = 0;
2425 sc->an_rdata.an_tx_cons = 0;
2426 sc->an_rdata.an_tx_empty = 1;
2435 struct an_softc *sc = xsc;
2436 struct ifnet *ifp = &sc->arpcom.ac_if;
2446 if (ifp->if_flags & IFF_RUNNING)
2449 sc->an_associated = 0;
2451 /* Allocate the TX buffers */
2452 if (an_init_tx_ring(sc)) {
2455 an_init_mpi350_desc(sc);
2456 if (an_init_tx_ring(sc)) {
2457 if_printf(ifp, "tx buffer allocation failed\n");
2463 /* Set our MAC address. */
2464 bcopy((char *)&sc->arpcom.ac_enaddr,
2465 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2467 if (ifp->if_flags & IFF_BROADCAST)
2468 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2470 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2472 if (ifp->if_flags & IFF_MULTICAST)
2473 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2475 if (ifp->if_flags & IFF_PROMISC) {
2476 if (sc->an_monitor & AN_MONITOR) {
2477 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2478 sc->an_config.an_rxmode |=
2479 AN_RXMODE_80211_MONITOR_ANYBSS |
2480 AN_RXMODE_NO_8023_HEADER;
2482 sc->an_config.an_rxmode |=
2483 AN_RXMODE_80211_MONITOR_CURBSS |
2484 AN_RXMODE_NO_8023_HEADER;
2489 if (sc->an_have_rssimap)
2490 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2492 /* Set the ssid list */
2493 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2494 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2495 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2496 if_printf(ifp, "failed to set ssid list\n");
2501 /* Set the AP list */
2502 sc->an_aplist.an_type = AN_RID_APLIST;
2503 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2504 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2505 if_printf(ifp, "failed to set AP list\n");
2510 /* Set the configuration in the NIC */
2511 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2512 sc->an_config.an_type = AN_RID_GENCONFIG;
2513 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2514 if_printf(ifp, "failed to set configuration\n");
2519 /* Enable the MAC */
2520 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2521 if_printf(ifp, "failed to enable MAC\n");
2526 if (ifp->if_flags & IFF_PROMISC)
2527 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2529 /* enable interrupts */
2530 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
2532 ifp->if_flags |= IFF_RUNNING;
2533 ifp->if_flags &= ~IFF_OACTIVE;
2535 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
2545 struct an_softc *sc;
2546 struct mbuf *m0 = NULL;
2547 struct an_txframe_802_3 tx_frame_802_3;
2548 struct ether_header *eh;
2550 unsigned char txcontrol;
2551 struct an_card_tx_desc an_tx_desc;
2560 if (ifp->if_flags & IFF_OACTIVE)
2563 if (!sc->an_associated)
2566 /* We can't send in monitor mode so toss any attempts. */
2567 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2568 ifq_purge(&ifp->if_snd);
2572 idx = sc->an_rdata.an_tx_prod;
2575 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2577 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2578 m0 = ifq_dequeue(&ifp->if_snd);
2582 id = sc->an_rdata.an_tx_fids[idx];
2583 eh = mtod(m0, struct ether_header *);
2585 bcopy((char *)&eh->ether_dhost,
2586 (char *)&tx_frame_802_3.an_tx_dst_addr,
2588 bcopy((char *)&eh->ether_shost,
2589 (char *)&tx_frame_802_3.an_tx_src_addr,
2592 /* minus src/dest mac & type */
2593 tx_frame_802_3.an_tx_802_3_payload_len =
2594 m0->m_pkthdr.len - 12;
2596 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2597 tx_frame_802_3.an_tx_802_3_payload_len,
2598 (caddr_t)&sc->an_txbuf);
2600 txcontrol = AN_TXCTL_8023;
2601 /* write the txcontrol only */
2602 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2606 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2607 sizeof(struct an_txframe_802_3));
2609 /* in mbuf header type is just before payload */
2610 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2611 tx_frame_802_3.an_tx_802_3_payload_len);
2618 sc->an_rdata.an_tx_ring[idx] = id;
2619 if (an_cmd(sc, AN_CMD_TX, id))
2620 if_printf(ifp, "xmit failed\n");
2622 AN_INC(idx, AN_TX_RING_CNT);
2624 } else { /* MPI-350 */
2625 while (sc->an_rdata.an_tx_empty ||
2626 idx != sc->an_rdata.an_tx_cons) {
2627 m0 = ifq_dequeue(&ifp->if_snd);
2631 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2633 eh = mtod(m0, struct ether_header *);
2635 /* DJA optimize this to limit bcopy */
2636 bcopy((char *)&eh->ether_dhost,
2637 (char *)&tx_frame_802_3.an_tx_dst_addr,
2639 bcopy((char *)&eh->ether_shost,
2640 (char *)&tx_frame_802_3.an_tx_src_addr,
2643 /* minus src/dest mac & type */
2644 tx_frame_802_3.an_tx_802_3_payload_len =
2645 m0->m_pkthdr.len - 12;
2647 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2648 tx_frame_802_3.an_tx_802_3_payload_len,
2649 (caddr_t)&sc->an_txbuf);
2651 txcontrol = AN_TXCTL_8023;
2652 /* write the txcontrol only */
2653 bcopy((caddr_t)&txcontrol, &buf[0x08],
2657 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2658 sizeof(struct an_txframe_802_3));
2660 /* in mbuf header type is just before payload */
2661 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2662 tx_frame_802_3.an_tx_802_3_payload_len);
2665 bzero(&an_tx_desc, sizeof(an_tx_desc));
2666 an_tx_desc.an_offset = 0;
2667 an_tx_desc.an_eoc = 1;
2668 an_tx_desc.an_valid = 1;
2669 an_tx_desc.an_len = 0x44 +
2670 tx_frame_802_3.an_tx_802_3_payload_len;
2671 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2672 ptr = (u_int8_t*)&an_tx_desc;
2673 for (i = 0; i < sizeof(an_tx_desc); i++) {
2674 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2683 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2685 AN_INC(idx, AN_MAX_TX_DESC);
2686 sc->an_rdata.an_tx_empty = 0;
2691 ifp->if_flags |= IFF_OACTIVE;
2693 sc->an_rdata.an_tx_prod = idx;
2696 * Set a timeout in case the chip goes out to lunch.
2705 struct an_softc *sc;
2718 ifp = &sc->arpcom.ac_if;
2720 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2721 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2722 an_cmd(sc, AN_CMD_DISABLE, 0);
2724 for (i = 0; i < AN_TX_RING_CNT; i++)
2725 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2727 callout_stop(&sc->an_stat_timer);
2729 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2731 if (sc->an_flash_buffer) {
2732 free(sc->an_flash_buffer, M_DEVBUF);
2733 sc->an_flash_buffer = NULL;
2745 struct an_softc *sc;
2756 if_printf(ifp, "device timeout\n");
2760 an_init_mpi350_desc(sc);
2773 struct an_softc *sc;
2775 sc = device_get_softc(dev);
2785 struct an_softc *sc;
2789 sc = device_get_softc(dev);
2790 ifp = &sc->arpcom.ac_if;
2794 an_init_mpi350_desc(sc);
2797 /* Recovery temporary keys */
2798 for (i = 0; i < 4; i++) {
2799 sc->areq.an_type = AN_RID_WEP_TEMP;
2800 sc->areq.an_len = sizeof(struct an_ltv_key);
2801 bcopy(&sc->an_temp_keys[i],
2802 &sc->areq, sizeof(struct an_ltv_key));
2803 an_setdef(sc, &sc->areq);
2806 if (ifp->if_flags & IFF_UP)
2813 /* Aironet signal strength cache code.
2814 * store signal/noise/quality on per MAC src basis in
2815 * a small fixed cache. The cache wraps if > MAX slots
2816 * used. The cache may be zeroed out to start over.
2817 * Two simple filters exist to reduce computation:
2818 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2819 * to ignore some packets. It defaults to ip only.
2820 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2821 * 2. multicast/broadcast only. This may be used to
2822 * ignore unicast packets and only cache signal strength
2823 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2824 * beacons and not unicast traffic.
2826 * The cache stores (MAC src(index), IP src (major clue), signal,
2829 * No apologies for storing IP src here. It's easy and saves much
2830 * trouble elsewhere. The cache is assumed to be INET dependent,
2831 * although it need not be.
2833 * Note: the Aironet only has a single byte of signal strength value
2834 * in the rx frame header, and it's not scaled to anything sensible.
2835 * This is kind of lame, but it's all we've got.
2838 #ifdef documentation
2840 int an_sigitems; /* number of cached entries */
2841 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2842 int an_nextitem; /* index/# of entries */
2847 /* control variables for cache filtering. Basic idea is
2848 * to reduce cost (e.g., to only Mobile-IP agent beacons
2849 * which are broadcast or multicast). Still you might
2850 * want to measure signal strength anth unicast ping packets
2851 * on a pt. to pt. ant. setup.
2853 /* set true if you want to limit cache items to broadcast/mcast
2854 * only packets (not unicast). Useful for mobile-ip beacons which
2855 * are broadcast/multicast at network layer. Default is all packets
2856 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2858 static int an_cache_mcastonly = 0;
2859 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2860 &an_cache_mcastonly, 0, "");
2862 /* set true if you want to limit cache items to IP packets only
2864 static int an_cache_iponly = 1;
2865 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2866 &an_cache_iponly, 0, "");
2869 * an_cache_store, per rx packet store signal
2870 * strength in MAC (src) indexed cache.
2873 an_cache_store (sc, m, rx_rssi, rx_quality)
2874 struct an_softc *sc;
2877 u_int8_t rx_quality;
2879 struct ether_header *eh = mtod(m, struct ether_header *);
2880 struct ip *ip = NULL;
2882 static int cache_slot = 0; /* use this cache entry */
2883 static int wrapindex = 0; /* next "free" cache entry */
2887 * 2. configurable filter to throw out unicast packets,
2888 * keep multicast only.
2891 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2892 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2893 else if (an_cache_iponly)
2896 /* filter for broadcast/multicast only
2898 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2903 if_printf(&sc->arpcom.ac_if, "q value %x (MSB=0x%x, LSB=0x%x)\n",
2904 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2907 /* do a linear search for a matching MAC address
2908 * in the cache table
2909 * . MAC address is 6 bytes,
2910 * . var w_nextitem holds total number of entries already cached
2912 for (i = 0; i < sc->an_nextitem; i++) {
2913 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2915 * so we already have this entry,
2922 /* did we find a matching mac address?
2923 * if yes, then overwrite a previously existing cache entry
2925 if (i < sc->an_nextitem ) {
2928 /* else, have a new address entry,so
2929 * add this new entry,
2930 * if table full, then we need to replace LRU entry
2934 /* check for space in cache table
2935 * note: an_nextitem also holds number of entries
2936 * added in the cache table
2938 if ( sc->an_nextitem < MAXANCACHE ) {
2939 cache_slot = sc->an_nextitem;
2941 sc->an_sigitems = sc->an_nextitem;
2943 /* no space found, so simply wrap anth wrap index
2944 * and "zap" the next entry
2947 if (wrapindex == MAXANCACHE) {
2950 cache_slot = wrapindex++;
2954 /* invariant: cache_slot now points at some slot
2957 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
2958 log(LOG_ERR, "an_cache_store, bad index: %d of "
2959 "[0..%d], gross cache error\n",
2960 cache_slot, MAXANCACHE);
2964 /* store items in cache
2965 * .ip source address
2970 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2972 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2975 switch (an_cache_mode) {
2977 if (sc->an_have_rssimap) {
2978 sc->an_sigcache[cache_slot].signal =
2979 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
2980 sc->an_sigcache[cache_slot].quality =
2981 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
2983 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
2984 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
2988 if (sc->an_have_rssimap) {
2989 sc->an_sigcache[cache_slot].signal =
2990 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
2991 sc->an_sigcache[cache_slot].quality =
2992 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
2996 if (rx_quality > 100)
2998 sc->an_sigcache[cache_slot].signal = rx_rssi;
2999 sc->an_sigcache[cache_slot].quality = rx_quality;
3003 sc->an_sigcache[cache_slot].signal = rx_rssi;
3004 sc->an_sigcache[cache_slot].quality = rx_quality;
3008 sc->an_sigcache[cache_slot].noise = 0;
3015 an_media_change(ifp)
3018 struct an_softc *sc = ifp->if_softc;
3019 struct an_ltv_genconfig *cfg;
3020 int otype = sc->an_config.an_opmode;
3021 int orate = sc->an_tx_rate;
3023 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3024 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC;
3026 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION;
3028 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
3029 case IFM_IEEE80211_DS1:
3030 sc->an_tx_rate = AN_RATE_1MBPS;
3032 case IFM_IEEE80211_DS2:
3033 sc->an_tx_rate = AN_RATE_2MBPS;
3035 case IFM_IEEE80211_DS5:
3036 sc->an_tx_rate = AN_RATE_5_5MBPS;
3038 case IFM_IEEE80211_DS11:
3039 sc->an_tx_rate = AN_RATE_11MBPS;
3046 if (orate != sc->an_tx_rate) {
3047 /* Read the current configuration */
3048 sc->an_config.an_type = AN_RID_GENCONFIG;
3049 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3050 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3051 cfg = &sc->an_config;
3053 /* clear other rates and set the only one we want */
3054 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3055 cfg->an_rates[0] = sc->an_tx_rate;
3057 /* Save the new rate */
3058 sc->an_config.an_type = AN_RID_GENCONFIG;
3059 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3062 if (otype != sc->an_config.an_opmode ||
3063 orate != sc->an_tx_rate)
3070 an_media_status(ifp, imr)
3072 struct ifmediareq *imr;
3074 struct an_ltv_status status;
3075 struct an_softc *sc = ifp->if_softc;
3077 status.an_len = sizeof(status);
3078 status.an_type = AN_RID_STATUS;
3079 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3080 /* If the status read fails, just lie. */
3081 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3082 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3085 if (sc->an_tx_rate == 0) {
3086 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3087 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3088 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3089 switch (status.an_current_tx_rate) {
3091 imr->ifm_active |= IFM_IEEE80211_DS1;
3094 imr->ifm_active |= IFM_IEEE80211_DS2;
3096 case AN_RATE_5_5MBPS:
3097 imr->ifm_active |= IFM_IEEE80211_DS5;
3099 case AN_RATE_11MBPS:
3100 imr->ifm_active |= IFM_IEEE80211_DS11;
3104 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3107 imr->ifm_status = IFM_AVALID;
3108 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3109 imr->ifm_status |= IFM_ACTIVE;
3112 /********************** Cisco utility support routines *************/
3115 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3120 readrids(ifp, l_ioctl)
3122 struct aironet_ioctl *l_ioctl;
3125 struct an_softc *sc;
3127 switch (l_ioctl->command) {
3129 rid = AN_RID_CAPABILITIES;
3132 rid = AN_RID_GENCONFIG;
3135 rid = AN_RID_SSIDLIST;
3138 rid = AN_RID_APLIST;
3141 rid = AN_RID_DRVNAME;
3144 rid = AN_RID_ENCAPPROTO;
3147 rid = AN_RID_WEP_TEMP;
3150 rid = AN_RID_WEP_PERM;
3153 rid = AN_RID_STATUS;
3156 rid = AN_RID_32BITS_DELTA;
3159 rid = AN_RID_32BITS_CUM;
3166 if (rid == 999) /* Is bad command */
3170 sc->areq.an_len = AN_MAX_DATALEN;
3171 sc->areq.an_type = rid;
3173 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3175 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3177 /* the data contains the length at first */
3178 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3179 sizeof(sc->areq.an_len))) {
3182 /* Just copy the data back */
3183 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3191 writerids(ifp, l_ioctl)
3193 struct aironet_ioctl *l_ioctl;
3195 struct an_softc *sc;
3200 command = l_ioctl->command;
3204 rid = AN_RID_SSIDLIST;
3207 rid = AN_RID_CAPABILITIES;
3210 rid = AN_RID_APLIST;
3213 rid = AN_RID_GENCONFIG;
3216 an_cmd(sc, AN_CMD_ENABLE, 0);
3220 an_cmd(sc, AN_CMD_DISABLE, 0);
3225 * This command merely clears the counts does not actually
3226 * store any data only reads rid. But as it changes the cards
3227 * state, I put it in the writerid routines.
3230 rid = AN_RID_32BITS_DELTACLR;
3232 sc->areq.an_len = AN_MAX_DATALEN;
3233 sc->areq.an_type = rid;
3235 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3236 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3238 /* the data contains the length at first */
3239 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3240 sizeof(sc->areq.an_len))) {
3243 /* Just copy the data */
3244 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3251 rid = AN_RID_WEP_TEMP;
3254 rid = AN_RID_WEP_PERM;
3257 rid = AN_RID_LEAPUSERNAME;
3260 rid = AN_RID_LEAPPASSWORD;
3267 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3269 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3270 sc->areq.an_type = rid;
3272 /* Just copy the data back */
3273 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3276 an_cmd(sc, AN_CMD_DISABLE, 0);
3277 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3278 an_cmd(sc, AN_CMD_ENABLE, 0);
3285 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3289 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3290 #define FLASH_COMMAND 0x7e7e
3291 #define FLASH_SIZE 32 * 1024
3297 struct an_softc *sc = ifp->if_softc;
3299 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3300 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3301 AN_EV_CLR_STUCK_BUSY);
3308 * Wait for busy completion from card wait for delay uSec's Return true for
3309 * success meaning command reg is clear
3317 int statword = 0xffff;
3319 struct an_softc *sc = ifp->if_softc;
3321 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3324 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3326 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3331 return 0 == (AN_CMD_BUSY & statword);
3335 * STEP 1) Disable MAC and do soft reset on card.
3343 struct an_softc *sc = ifp->if_softc;
3347 an_cmd(sc, AN_CMD_DISABLE, 0);
3349 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3350 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3353 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3355 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3358 if (!(status = WaitBusy(ifp, 100))) {
3359 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3366 * STEP 2) Put the card in legendary flash mode
3374 struct an_softc *sc = ifp->if_softc;
3376 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3377 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3378 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3379 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3382 * mdelay(500); // 500ms delay
3387 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3388 printf("Waitbusy hang after setflash mode\n");
3395 * Get a character from the card matching matchbyte Step 3)
3399 flashgchar(ifp, matchbyte, dwelltime)
3405 unsigned char rbyte = 0;
3407 struct an_softc *sc = ifp->if_softc;
3411 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3413 if (dwelltime && !(0x8000 & rchar)) {
3418 rbyte = 0xff & rchar;
3420 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3421 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3425 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3427 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3429 } while (dwelltime > 0);
3434 * Put character to SWS0 wait for dwelltime x 50us for echo .
3438 flashpchar(ifp, byte, dwelltime)
3444 int pollbusy, waittime;
3445 struct an_softc *sc = ifp->if_softc;
3452 waittime = dwelltime;
3455 * Wait for busy bit d15 to go false indicating buffer empty
3458 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3460 if (pollbusy & 0x8000) {
3467 while (waittime >= 0);
3469 /* timeout for busy clear wait */
3471 if (waittime <= 0) {
3472 if_printf(ifp, "flash putchar busywait timeout!\n");
3476 * Port is clear now write byte and wait for it to echo back
3479 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3482 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3483 } while (dwelltime >= 0 && echo != byte);
3486 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3488 return echo == byte;
3492 * Transfer 32k of firmware data from user buffer to our buffer and send to
3500 unsigned short *bufp;
3502 struct an_softc *sc = ifp->if_softc;
3506 bufp = sc->an_flash_buffer;
3509 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3510 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3512 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3513 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3516 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3517 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3518 ((u_int32_t *)bufp)[nwords] & 0xffff);
3522 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3528 * After flashing restart the card.
3536 struct an_softc *sc = ifp->if_softc;
3538 FLASH_DELAY(1024); /* Added 12/7/00 */
3542 FLASH_DELAY(1024); /* Added 12/7/00 */
3547 * Entry point for flash ioclt.
3551 flashcard(ifp, l_ioctl)
3553 struct aironet_ioctl *l_ioctl;
3556 struct an_softc *sc;
3560 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3563 status = l_ioctl->command;
3565 switch (l_ioctl->command) {
3567 return cmdreset(ifp);
3570 if (sc->an_flash_buffer) {
3571 free(sc->an_flash_buffer, M_DEVBUF);
3572 sc->an_flash_buffer = NULL;
3574 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3575 if (sc->an_flash_buffer)
3576 return setflashmode(ifp);
3580 case AIROFLSHGCHR: /* Get char from aux */
3581 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3582 z = *(int *)&sc->areq;
3583 if ((status = flashgchar(ifp, z, 8000)) == 1)
3588 case AIROFLSHPCHR: /* Send char to card. */
3589 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3590 z = *(int *)&sc->areq;
3591 if ((status = flashpchar(ifp, z, 8000)) == -1)
3596 case AIROFLPUTBUF: /* Send 32k to card */
3597 if (l_ioctl->len > FLASH_SIZE) {
3598 if_printf(ifp, "Buffer to big, %x %x\n",
3599 l_ioctl->len, FLASH_SIZE);
3602 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3604 if ((status = flashputbuf(ifp)) != 0)
3610 if ((status = flashrestart(ifp)) != 0) {
3611 if_printf(ifp, "FLASHRESTART returned %d\n", status);