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.31 2005/07/28 16:56:37 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 <sys/thread2.h>
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_new 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. */
343 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
344 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
346 if_initname(&sc->arpcom.ac_if, device_get_name(dev),
347 device_get_unit(dev));
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_entry[0].an_ssid, 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, 0, &dma->an_dma_map);
476 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
477 BUS_DMA_WAITOK, &dma->an_dma_map);
481 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
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 dma->an_dma_vaddr = NULL;
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 if_printf(&sc->arpcom.ac_if,
593 "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 if_printf(&sc->arpcom.ac_if,
622 "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 if_printf(&sc->arpcom.ac_if,
652 "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, dev, flags)
675 struct ifnet *ifp = &sc->arpcom.ac_if;
678 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_new);
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_entry[0].an_ssid,
765 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
766 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
767 sizeof(AN_DEFAULT_NETNAME) - 1);
768 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
770 sc->an_config.an_opmode =
771 AN_OPMODE_INFRASTRUCTURE_STATION;
774 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
776 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
777 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
778 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
779 IFM_IEEE80211_ADHOC, 0), 0);
780 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
781 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
782 IFM_IEEE80211_ADHOC, 0), 0);
783 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
784 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
785 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
786 IFM_IEEE80211_ADHOC, 0), 0);
787 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
789 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
790 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
791 IFM_IEEE80211_ADHOC, 0), 0);
792 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
794 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
795 IFM_IEEE80211_ADHOC, 0), 0);
796 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
798 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
802 * Call MI attach routine.
804 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
810 an_detach(device_t dev)
812 struct an_softc *sc = device_get_softc(dev);
813 struct ifnet *ifp = &sc->arpcom.ac_if;
817 ifmedia_removeall(&sc->an_ifmedia);
819 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
822 an_release_resources(dev);
831 struct ether_header *eh;
832 struct ieee80211_frame *ih;
833 struct an_rxframe rx_frame;
834 struct an_rxframe_802_3 rx_frame_802_3;
836 int len, id, error = 0, i, count = 0;
837 int ieee80211_header_len;
840 struct an_card_rx_desc an_rx_desc;
843 ifp = &sc->arpcom.ac_if;
846 id = CSR_READ_2(sc, AN_RX_FID);
848 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
849 /* read raw 802.11 packet */
850 bpf_buf = sc->buf_802_11;
853 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
860 * skip beacon by default since this increases the
864 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
865 (rx_frame.an_frame_ctl &
866 IEEE80211_FC0_SUBTYPE_BEACON)) {
870 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
871 len = rx_frame.an_rx_payload_len
873 /* Check for insane frame length */
874 if (len > sizeof(sc->buf_802_11)) {
876 "oversized packet received "
877 "(%d, %d)\n", len, MCLBYTES);
882 bcopy((char *)&rx_frame,
883 bpf_buf, sizeof(rx_frame));
885 error = an_read_data(sc, id, sizeof(rx_frame),
886 (caddr_t)bpf_buf+sizeof(rx_frame),
887 rx_frame.an_rx_payload_len);
889 fc1=rx_frame.an_frame_ctl >> 8;
890 ieee80211_header_len =
891 sizeof(struct ieee80211_frame);
892 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
893 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
894 ieee80211_header_len += ETHER_ADDR_LEN;
897 len = rx_frame.an_rx_payload_len
898 + ieee80211_header_len;
899 /* Check for insane frame length */
900 if (len > sizeof(sc->buf_802_11)) {
902 "oversized packet received "
903 "(%d, %d)\n", len, MCLBYTES);
908 ih = (struct ieee80211_frame *)bpf_buf;
910 bcopy((char *)&rx_frame.an_frame_ctl,
911 (char *)ih, ieee80211_header_len);
913 error = an_read_data(sc, id, sizeof(rx_frame) +
915 (caddr_t)ih +ieee80211_header_len,
916 rx_frame.an_rx_payload_len);
918 BPF_TAP(ifp, bpf_buf, len);
920 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
925 m->m_pkthdr.rcvif = ifp;
926 /* Read Ethernet encapsulated packet */
929 /* Read NIC frame header */
930 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
936 /* Read in the 802_3 frame header */
937 if (an_read_data(sc, id, 0x34,
938 (caddr_t)&rx_frame_802_3,
939 sizeof(rx_frame_802_3))) {
943 if (rx_frame_802_3.an_rx_802_3_status != 0) {
947 /* Check for insane frame length */
948 len = rx_frame_802_3.an_rx_802_3_payload_len;
949 if (len > sizeof(sc->buf_802_11)) {
951 "oversized packet received (%d, %d)\n",
956 m->m_pkthdr.len = m->m_len =
957 rx_frame_802_3.an_rx_802_3_payload_len + 12;
959 eh = mtod(m, struct ether_header *);
961 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
962 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
963 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
964 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
966 /* in mbuf header type is just before payload */
967 error = an_read_data(sc, id, 0x44,
968 (caddr_t)&(eh->ether_type),
969 rx_frame_802_3.an_rx_802_3_payload_len);
979 an_cache_store(sc, m,
980 rx_frame.an_rx_signal_strength,
983 (*ifp->if_input)(ifp, m);
986 } else { /* MPI-350 */
987 for (count = 0; count < AN_MAX_RX_DESC; count++){
988 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
989 ((u_int32_t*)&an_rx_desc)[i]
990 = CSR_MEM_AUX_READ_4(sc,
992 + (count * sizeof(an_rx_desc))
995 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
996 buf = sc->an_rx_buffer[count].an_dma_vaddr;
998 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
1003 m->m_pkthdr.rcvif = ifp;
1004 /* Read Ethernet encapsulated packet */
1007 * No ANCACHE support since we just get back
1008 * an Ethernet packet no 802.11 info
1012 /* Read NIC frame header */
1013 bcopy(buf, (caddr_t)&rx_frame,
1017 /* Check for insane frame length */
1018 len = an_rx_desc.an_len + 12;
1019 if (len > MCLBYTES) {
1021 "oversized packet received "
1022 "(%d, %d)\n", len, MCLBYTES);
1027 m->m_pkthdr.len = m->m_len =
1028 an_rx_desc.an_len + 12;
1030 eh = mtod(m, struct ether_header *);
1032 bcopy(buf, (char *)eh,
1039 an_cache_store(sc, m,
1040 rx_frame.an_rx_signal_strength,
1044 (*ifp->if_input)(ifp, m);
1046 an_rx_desc.an_valid = 1;
1047 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1048 an_rx_desc.an_done = 0;
1049 an_rx_desc.an_phys =
1050 sc->an_rx_buffer[count].an_dma_paddr;
1052 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1053 CSR_MEM_AUX_WRITE_4(sc,
1055 + (count * sizeof(an_rx_desc))
1057 ((u_int32_t*)&an_rx_desc)[i]);
1060 if_printf(ifp, "Didn't get valid RX packet "
1063 an_rx_desc.an_valid,
1071 an_txeof(sc, status)
1072 struct an_softc *sc;
1078 ifp = &sc->arpcom.ac_if;
1081 ifp->if_flags &= ~IFF_OACTIVE;
1084 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1086 if (status & AN_EV_TX_EXC) {
1091 for (i = 0; i < AN_TX_RING_CNT; i++) {
1092 if (id == sc->an_rdata.an_tx_ring[i]) {
1093 sc->an_rdata.an_tx_ring[i] = 0;
1098 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1099 } else { /* MPI 350 */
1100 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1101 if (!sc->an_rdata.an_tx_empty){
1102 if (status & AN_EV_TX_EXC) {
1106 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1107 if (sc->an_rdata.an_tx_prod ==
1108 sc->an_rdata.an_tx_cons)
1109 sc->an_rdata.an_tx_empty = 1;
1115 * We abuse the stats updater to check the current NIC status. This
1116 * is important because we don't want to allow transmissions until
1117 * the NIC has synchronized to the current cell (either as the master
1118 * in an ad-hoc group, or as a station connected to an access point).
1121 an_stats_update(xsc)
1124 struct an_softc *sc;
1128 ifp = &sc->arpcom.ac_if;
1132 sc->an_status.an_type = AN_RID_STATUS;
1133 sc->an_status.an_len = sizeof(struct an_ltv_status);
1134 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1136 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1137 sc->an_associated = 1;
1139 sc->an_associated = 0;
1141 /* Don't do this while we're not transmitting */
1142 if ((ifp->if_flags & IFF_OACTIVE) == 0) {
1143 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1144 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1145 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1148 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1157 struct an_softc *sc;
1161 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(sc->mpi350));
1171 if (status & AN_EV_MIC)
1172 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1174 if (status & AN_EV_LINKSTAT) {
1175 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1176 == AN_LINKSTAT_ASSOCIATED)
1177 sc->an_associated = 1;
1179 sc->an_associated = 0;
1180 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1183 if (status & AN_EV_RX) {
1185 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1188 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1189 an_txeof(sc, status);
1190 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1193 if (status & AN_EV_TX) {
1194 an_txeof(sc, status);
1195 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1198 if (status & AN_EV_TX_EXC) {
1199 an_txeof(sc, status);
1200 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1203 if (status & AN_EV_ALLOC)
1204 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1206 /* Re-enable interrupts. */
1207 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1209 if ((ifp->if_flags & IFF_UP) && !ifq_is_empty(&ifp->if_snd))
1216 an_cmd_struct(sc, cmd, reply)
1217 struct an_softc *sc;
1218 struct an_command *cmd;
1219 struct an_reply *reply;
1223 for (i = 0; i != AN_TIMEOUT; i++) {
1224 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1229 if( i == AN_TIMEOUT) {
1234 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1235 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1236 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1237 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1239 for (i = 0; i < AN_TIMEOUT; i++) {
1240 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1245 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1246 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1247 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1248 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1250 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1251 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1253 /* Ack the command */
1254 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1256 if (i == AN_TIMEOUT)
1263 an_cmd(sc, cmd, val)
1264 struct an_softc *sc;
1270 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1271 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1272 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1273 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1275 for (i = 0; i < AN_TIMEOUT; i++) {
1276 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1279 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1280 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1284 for (i = 0; i < AN_TIMEOUT; i++) {
1285 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1286 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1287 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1288 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1289 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1293 /* Ack the command */
1294 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1296 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1297 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1299 if (i == AN_TIMEOUT)
1306 * This reset sequence may look a little strange, but this is the
1307 * most reliable method I've found to really kick the NIC in the
1308 * head and force it to reboot correctly.
1312 struct an_softc *sc;
1314 an_cmd(sc, AN_CMD_ENABLE, 0);
1315 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1316 an_cmd(sc, AN_CMD_NOOP2, 0);
1318 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1319 if_printf(&sc->arpcom.ac_if, "reset failed\n");
1321 an_cmd(sc, AN_CMD_DISABLE, 0);
1327 * Read an LTV record from the NIC.
1330 an_read_record(sc, ltv)
1331 struct an_softc *sc;
1332 struct an_ltv_gen *ltv;
1334 struct an_ltv_gen *an_ltv;
1335 struct an_card_rid_desc an_rid_desc;
1336 struct an_command cmd;
1337 struct an_reply reply;
1342 if (ltv->an_len < 4 || ltv->an_type == 0)
1346 /* Tell the NIC to enter record read mode. */
1347 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1348 if_printf(&sc->arpcom.ac_if, "RID access failed\n");
1352 /* Seek to the record. */
1353 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1354 if_printf(&sc->arpcom.ac_if, "seek to record failed\n");
1359 * Read the length and record type and make sure they
1360 * match what we expect (this verifies that we have enough
1361 * room to hold all of the returned data).
1362 * Length includes type but not length.
1364 len = CSR_READ_2(sc, AN_DATA1);
1365 if (len > (ltv->an_len - 2)) {
1366 if_printf(&sc->arpcom.ac_if,
1367 "record length mismatch -- expected %d, "
1368 "got %d for Rid %x\n",
1369 ltv->an_len - 2, len, ltv->an_type);
1370 len = ltv->an_len - 2;
1372 ltv->an_len = len + 2;
1375 /* Now read the data. */
1376 len -= 2; /* skip the type */
1378 for (i = len; i > 1; i -= 2)
1379 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1381 ptr2 = (u_int8_t *)ptr;
1382 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1384 } else { /* MPI-350 */
1385 if (sc->an_rid_buffer.an_dma_vaddr == NULL)
1387 an_rid_desc.an_valid = 1;
1388 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1389 an_rid_desc.an_rid = 0;
1390 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1391 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1393 bzero(&cmd, sizeof(cmd));
1394 bzero(&reply, sizeof(reply));
1395 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1396 cmd.an_parm0 = ltv->an_type;
1398 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1399 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1400 ((u_int32_t*)&an_rid_desc)[i]);
1402 if (an_cmd_struct(sc, &cmd, &reply)
1403 || reply.an_status & AN_CMD_QUAL_MASK) {
1404 if_printf(&sc->arpcom.ac_if,
1405 "failed to read RID %x %x %x %x %x, %d\n",
1415 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1416 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1417 an_rid_desc.an_len = an_ltv->an_len;
1420 len = an_rid_desc.an_len;
1421 if (len > (ltv->an_len - 2)) {
1422 if_printf(&sc->arpcom.ac_if,
1423 "record length mismatch -- expected %d, "
1424 "got %d for Rid %x\n",
1425 ltv->an_len - 2, len, ltv->an_type);
1426 len = ltv->an_len - 2;
1428 ltv->an_len = len + 2;
1430 bcopy(&an_ltv->an_type, <v->an_val, len);
1434 an_dump_record(sc, ltv, "Read");
1440 * Same as read, except we inject data instead of reading it.
1443 an_write_record(sc, ltv)
1444 struct an_softc *sc;
1445 struct an_ltv_gen *ltv;
1447 struct an_card_rid_desc an_rid_desc;
1448 struct an_command cmd;
1449 struct an_reply reply;
1456 an_dump_record(sc, ltv, "Write");
1459 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1462 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1466 * Length includes type but not length.
1468 len = ltv->an_len - 2;
1469 CSR_WRITE_2(sc, AN_DATA1, len);
1471 len -= 2; /* skip the type */
1473 for (i = len; i > 1; i -= 2)
1474 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1476 ptr2 = (u_int8_t *)ptr;
1477 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1480 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1485 for (i = 0; i != AN_TIMEOUT; i++) {
1486 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1492 if (i == AN_TIMEOUT) {
1496 an_rid_desc.an_valid = 1;
1497 an_rid_desc.an_len = ltv->an_len - 2;
1498 an_rid_desc.an_rid = ltv->an_type;
1499 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1501 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1502 an_rid_desc.an_len);
1504 bzero(&cmd,sizeof(cmd));
1505 bzero(&reply,sizeof(reply));
1506 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1507 cmd.an_parm0 = ltv->an_type;
1509 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1510 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1511 ((u_int32_t*)&an_rid_desc)[i]);
1513 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1514 if_printf(&sc->arpcom.ac_if,
1515 "failed to write RID 1 %x %x %x %x %x, %d\n",
1525 ptr = (u_int16_t *)buf;
1527 if (reply.an_status & AN_CMD_QUAL_MASK) {
1528 if_printf(&sc->arpcom.ac_if,
1529 "failed to write RID 2 %x %x %x %x %x, %d\n",
1544 an_dump_record(sc, ltv, string)
1545 struct an_softc *sc;
1546 struct an_ltv_gen *ltv;
1555 len = ltv->an_len - 4;
1556 if_printf(&sc->arpcom.ac_if, "RID %4x, Length %4d, Mode %s\n",
1557 ltv->an_type, ltv->an_len - 4, string);
1559 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1560 if_printf(&sc->arpcom.ac_if, "\t");
1561 bzero(buf,sizeof(buf));
1563 ptr2 = (u_int8_t *)<v->an_val;
1564 for (i = len; i > 0; i--) {
1565 printf("%02x ", *ptr2);
1568 if (temp >= ' ' && temp <= '~')
1570 else if (temp >= 'A' && temp <= 'Z')
1574 if (++count == 16) {
1577 if_printf(&sc->arpcom.ac_if, "\t");
1578 bzero(buf,sizeof(buf));
1581 for (; count != 16; count++) {
1584 printf(" %s\n",buf);
1589 an_seek(sc, id, off, chan)
1590 struct an_softc *sc;
1606 if_printf(&sc->arpcom.ac_if, "invalid data path: %x\n", chan);
1610 CSR_WRITE_2(sc, selreg, id);
1611 CSR_WRITE_2(sc, offreg, off);
1613 for (i = 0; i < AN_TIMEOUT; i++) {
1614 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1618 if (i == AN_TIMEOUT)
1625 an_read_data(sc, id, off, buf, len)
1626 struct an_softc *sc;
1636 if (an_seek(sc, id, off, AN_BAP1))
1640 ptr = (u_int16_t *)buf;
1641 for (i = len; i > 1; i -= 2)
1642 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1644 ptr2 = (u_int8_t *)ptr;
1645 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1652 an_write_data(sc, id, off, buf, len)
1653 struct an_softc *sc;
1663 if (an_seek(sc, id, off, AN_BAP0))
1667 ptr = (u_int16_t *)buf;
1668 for (i = len; i > 1; i -= 2)
1669 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1671 ptr2 = (u_int8_t *)ptr;
1672 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1679 * Allocate a region of memory inside the NIC and zero
1683 an_alloc_nicmem(sc, len, id)
1684 struct an_softc *sc;
1690 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1691 if_printf(&sc->arpcom.ac_if,
1692 "failed to allocate %d bytes on NIC\n", len);
1696 for (i = 0; i < AN_TIMEOUT; i++) {
1697 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1701 if (i == AN_TIMEOUT)
1704 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1705 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1707 if (an_seek(sc, *id, 0, AN_BAP0))
1710 for (i = 0; i < len / 2; i++)
1711 CSR_WRITE_2(sc, AN_DATA0, 0);
1718 struct an_softc *sc;
1719 struct an_req *areq;
1722 struct an_ltv_genconfig *cfg;
1723 struct an_ltv_ssidlist_new *ssid;
1724 struct an_ltv_aplist *ap;
1725 struct an_ltv_gen *sp;
1727 ifp = &sc->arpcom.ac_if;
1729 switch (areq->an_type) {
1730 case AN_RID_GENCONFIG:
1731 cfg = (struct an_ltv_genconfig *)areq;
1733 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1735 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
1737 bcopy((char *)cfg, (char *)&sc->an_config,
1738 sizeof(struct an_ltv_genconfig));
1740 case AN_RID_SSIDLIST:
1741 ssid = (struct an_ltv_ssidlist_new *)areq;
1742 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1743 sizeof(struct an_ltv_ssidlist_new));
1746 ap = (struct an_ltv_aplist *)areq;
1747 bcopy((char *)ap, (char *)&sc->an_aplist,
1748 sizeof(struct an_ltv_aplist));
1750 case AN_RID_TX_SPEED:
1751 sp = (struct an_ltv_gen *)areq;
1752 sc->an_tx_rate = sp->an_val;
1754 /* Read the current configuration */
1755 sc->an_config.an_type = AN_RID_GENCONFIG;
1756 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1757 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1758 cfg = &sc->an_config;
1760 /* clear other rates and set the only one we want */
1761 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1762 cfg->an_rates[0] = sc->an_tx_rate;
1764 /* Save the new rate */
1765 sc->an_config.an_type = AN_RID_GENCONFIG;
1766 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1768 case AN_RID_WEP_TEMP:
1769 /* Cache the temp keys */
1771 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1772 sizeof(struct an_ltv_key));
1773 case AN_RID_WEP_PERM:
1774 case AN_RID_LEAPUSERNAME:
1775 case AN_RID_LEAPPASSWORD:
1778 /* Disable the MAC. */
1779 an_cmd(sc, AN_CMD_DISABLE, 0);
1782 an_write_record(sc, (struct an_ltv_gen *)areq);
1784 /* Turn the MAC back on. */
1785 an_cmd(sc, AN_CMD_ENABLE, 0);
1788 case AN_RID_MONITOR_MODE:
1789 cfg = (struct an_ltv_genconfig *)areq;
1791 if (ng_ether_detach_p != NULL)
1792 (*ng_ether_detach_p) (ifp);
1793 sc->an_monitor = cfg->an_len;
1795 if (sc->an_monitor & AN_MONITOR) {
1796 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1797 bpfattach(ifp, DLT_AIRONET_HEADER,
1798 sizeof(struct ether_header));
1800 bpfattach(ifp, DLT_IEEE802_11,
1801 sizeof(struct ether_header));
1804 bpfattach(ifp, DLT_EN10MB,
1805 sizeof(struct ether_header));
1806 if (ng_ether_attach_p != NULL)
1807 (*ng_ether_attach_p) (ifp);
1811 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1817 /* Reinitialize the card. */
1825 * Derived from Linux driver to enable promiscious mode.
1829 an_promisc(sc, promisc)
1830 struct an_softc *sc;
1833 if (sc->an_was_monitor)
1836 an_init_mpi350_desc(sc);
1837 if (sc->an_monitor || sc->an_was_monitor)
1840 sc->an_was_monitor = sc->an_monitor;
1841 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1847 an_ioctl(ifp, command, data, cr)
1856 struct an_softc *sc;
1858 struct ieee80211req *ireq;
1859 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1861 struct an_ltv_genconfig *config;
1862 struct an_ltv_key *key;
1863 struct an_ltv_status *status;
1864 struct an_ltv_ssidlist_new *ssids;
1866 struct aironet_ioctl l_ioctl;
1869 ifr = (struct ifreq *)data;
1870 ireq = (struct ieee80211req *)data;
1874 config = (struct an_ltv_genconfig *)&sc->areq;
1875 key = (struct an_ltv_key *)&sc->areq;
1876 status = (struct an_ltv_status *)&sc->areq;
1877 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1881 if (ifp->if_flags & IFF_UP) {
1882 if (ifp->if_flags & IFF_RUNNING &&
1883 ifp->if_flags & IFF_PROMISC &&
1884 !(sc->an_if_flags & IFF_PROMISC)) {
1886 } else if (ifp->if_flags & IFF_RUNNING &&
1887 !(ifp->if_flags & IFF_PROMISC) &&
1888 sc->an_if_flags & IFF_PROMISC) {
1893 if (ifp->if_flags & IFF_RUNNING)
1896 sc->an_if_flags = ifp->if_flags;
1901 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1905 /* The Aironet has no multicast filter. */
1909 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1913 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1914 error = suser_cred(cr, NULL_CRED_OKAY);
1917 sc->an_sigitems = sc->an_nextitem = 0;
1919 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1920 char *pt = (char *)&sc->areq.an_val;
1921 bcopy((char *)&sc->an_sigitems, (char *)pt,
1924 sc->areq.an_len = sizeof(int) / 2;
1925 bcopy((char *)&sc->an_sigcache, (char *)pt,
1926 sizeof(struct an_sigcache) * sc->an_sigitems);
1927 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1928 sc->an_sigitems) / 2) + 1;
1931 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1935 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1938 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1940 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1943 an_setdef(sc, &sc->areq);
1945 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1946 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1948 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1949 mode = l_ioctl.command;
1951 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1952 error = readrids(ifp, &l_ioctl);
1953 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1954 error = writerids(ifp, &l_ioctl);
1955 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1956 error = flashcard(ifp, &l_ioctl);
1961 /* copy out the updated command info */
1962 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1965 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1966 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1968 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1969 l_ioctl.command = 0;
1971 copyout(&error, l_ioctl.data, sizeof(error));
1975 sc->areq.an_len = sizeof(sc->areq);
1976 /* was that a good idea DJA we are doing a short-cut */
1977 switch (ireq->i_type) {
1978 case IEEE80211_IOC_SSID:
1979 if (ireq->i_val == -1) {
1980 sc->areq.an_type = AN_RID_STATUS;
1981 if (an_read_record(sc,
1982 (struct an_ltv_gen *)&sc->areq)) {
1986 len = status->an_ssidlen;
1987 tmpptr = status->an_ssid;
1988 } else if (ireq->i_val >= 0) {
1989 sc->areq.an_type = AN_RID_SSIDLIST;
1990 if (an_read_record(sc,
1991 (struct an_ltv_gen *)&sc->areq)) {
1995 max = (sc->areq.an_len - 4)
1996 / sizeof(struct an_ltv_ssid_entry);
1997 if ( max > MAX_SSIDS ) {
1998 printf("To many SSIDs only using "
2003 if (ireq->i_val > max) {
2007 len = ssids->an_entry[ireq->i_val].an_len;
2008 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2014 if (len > IEEE80211_NWID_LEN) {
2019 bzero(tmpstr, IEEE80211_NWID_LEN);
2020 bcopy(tmpptr, tmpstr, len);
2021 error = copyout(tmpstr, ireq->i_data,
2022 IEEE80211_NWID_LEN);
2024 case IEEE80211_IOC_NUMSSIDS:
2025 sc->areq.an_len = sizeof(sc->areq);
2026 sc->areq.an_type = AN_RID_SSIDLIST;
2027 if (an_read_record(sc,
2028 (struct an_ltv_gen *)&sc->areq)) {
2032 max = (sc->areq.an_len - 4)
2033 / sizeof(struct an_ltv_ssid_entry);
2034 if (max > MAX_SSIDS) {
2035 printf("To many SSIDs only using "
2042 case IEEE80211_IOC_WEP:
2043 sc->areq.an_type = AN_RID_ACTUALCFG;
2044 if (an_read_record(sc,
2045 (struct an_ltv_gen *)&sc->areq)) {
2049 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2050 if (config->an_authtype &
2051 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2052 ireq->i_val = IEEE80211_WEP_MIXED;
2054 ireq->i_val = IEEE80211_WEP_ON;
2056 ireq->i_val = IEEE80211_WEP_OFF;
2059 case IEEE80211_IOC_WEPKEY:
2061 * XXX: I'm not entierly convinced this is
2062 * correct, but it's what is implemented in
2063 * ancontrol so it will have to do until we get
2064 * access to actual Cisco code.
2066 if (ireq->i_val < 0 || ireq->i_val > 8) {
2071 if (ireq->i_val < 5) {
2072 sc->areq.an_type = AN_RID_WEP_TEMP;
2073 for (i = 0; i < 5; i++) {
2074 if (an_read_record(sc,
2075 (struct an_ltv_gen *)&sc->areq)) {
2079 if (key->kindex == 0xffff)
2081 if (key->kindex == ireq->i_val)
2083 /* Required to get next entry */
2084 sc->areq.an_type = AN_RID_WEP_PERM;
2089 /* We aren't allowed to read the value of the
2090 * key from the card so we just output zeros
2091 * like we would if we could read the card, but
2092 * denied the user access.
2096 error = copyout(tmpstr, ireq->i_data, len);
2098 case IEEE80211_IOC_NUMWEPKEYS:
2099 ireq->i_val = 9; /* include home key */
2101 case IEEE80211_IOC_WEPTXKEY:
2103 * For some strange reason, you have to read all
2104 * keys before you can read the txkey.
2106 sc->areq.an_type = AN_RID_WEP_TEMP;
2107 for (i = 0; i < 5; i++) {
2108 if (an_read_record(sc,
2109 (struct an_ltv_gen *) &sc->areq)) {
2113 if (key->kindex == 0xffff)
2115 /* Required to get next entry */
2116 sc->areq.an_type = AN_RID_WEP_PERM;
2121 sc->areq.an_type = AN_RID_WEP_PERM;
2122 key->kindex = 0xffff;
2123 if (an_read_record(sc,
2124 (struct an_ltv_gen *)&sc->areq)) {
2128 ireq->i_val = key->mac[0];
2130 * Check for home mode. Map home mode into
2131 * 5th key since that is how it is stored on
2134 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2135 sc->areq.an_type = AN_RID_GENCONFIG;
2136 if (an_read_record(sc,
2137 (struct an_ltv_gen *)&sc->areq)) {
2141 if (config->an_home_product & AN_HOME_NETWORK)
2144 case IEEE80211_IOC_AUTHMODE:
2145 sc->areq.an_type = AN_RID_ACTUALCFG;
2146 if (an_read_record(sc,
2147 (struct an_ltv_gen *)&sc->areq)) {
2151 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2153 ireq->i_val = IEEE80211_AUTH_NONE;
2154 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2156 ireq->i_val = IEEE80211_AUTH_OPEN;
2157 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2158 AN_AUTHTYPE_SHAREDKEY) {
2159 ireq->i_val = IEEE80211_AUTH_SHARED;
2163 case IEEE80211_IOC_STATIONNAME:
2164 sc->areq.an_type = AN_RID_ACTUALCFG;
2165 if (an_read_record(sc,
2166 (struct an_ltv_gen *)&sc->areq)) {
2170 ireq->i_len = sizeof(config->an_nodename);
2171 tmpptr = config->an_nodename;
2172 bzero(tmpstr, IEEE80211_NWID_LEN);
2173 bcopy(tmpptr, tmpstr, ireq->i_len);
2174 error = copyout(tmpstr, ireq->i_data,
2175 IEEE80211_NWID_LEN);
2177 case IEEE80211_IOC_CHANNEL:
2178 sc->areq.an_type = AN_RID_STATUS;
2179 if (an_read_record(sc,
2180 (struct an_ltv_gen *)&sc->areq)) {
2184 ireq->i_val = status->an_cur_channel;
2186 case IEEE80211_IOC_POWERSAVE:
2187 sc->areq.an_type = AN_RID_ACTUALCFG;
2188 if (an_read_record(sc,
2189 (struct an_ltv_gen *)&sc->areq)) {
2193 if (config->an_psave_mode == AN_PSAVE_NONE) {
2194 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2195 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2196 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2197 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2198 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2199 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2200 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2204 case IEEE80211_IOC_POWERSAVESLEEP:
2205 sc->areq.an_type = AN_RID_ACTUALCFG;
2206 if (an_read_record(sc,
2207 (struct an_ltv_gen *)&sc->areq)) {
2211 ireq->i_val = config->an_listen_interval;
2216 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
2218 sc->areq.an_len = sizeof(sc->areq);
2220 * We need a config structure for everything but the WEP
2221 * key management and SSIDs so we get it now so avoid
2222 * duplicating this code every time.
2224 if (ireq->i_type != IEEE80211_IOC_SSID &&
2225 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2226 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2227 sc->areq.an_type = AN_RID_GENCONFIG;
2228 if (an_read_record(sc,
2229 (struct an_ltv_gen *)&sc->areq)) {
2234 switch (ireq->i_type) {
2235 case IEEE80211_IOC_SSID:
2236 sc->areq.an_len = sizeof(sc->areq);
2237 sc->areq.an_type = AN_RID_SSIDLIST;
2238 if (an_read_record(sc,
2239 (struct an_ltv_gen *)&sc->areq)) {
2243 if (ireq->i_len > IEEE80211_NWID_LEN) {
2247 max = (sc->areq.an_len - 4)
2248 / sizeof(struct an_ltv_ssid_entry);
2249 if (max > MAX_SSIDS) {
2250 printf("To many SSIDs only using "
2255 if (ireq->i_val > max) {
2259 error = copyin(ireq->i_data,
2260 ssids->an_entry[ireq->i_val].an_ssid,
2262 ssids->an_entry[ireq->i_val].an_len
2267 case IEEE80211_IOC_WEP:
2268 switch (ireq->i_val) {
2269 case IEEE80211_WEP_OFF:
2270 config->an_authtype &=
2271 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2272 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2274 case IEEE80211_WEP_ON:
2275 config->an_authtype |=
2276 AN_AUTHTYPE_PRIVACY_IN_USE;
2277 config->an_authtype &=
2278 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2280 case IEEE80211_WEP_MIXED:
2281 config->an_authtype |=
2282 AN_AUTHTYPE_PRIVACY_IN_USE |
2283 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2290 case IEEE80211_IOC_WEPKEY:
2291 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2296 error = copyin(ireq->i_data, tmpstr, 13);
2300 * Map the 9th key into the home mode
2301 * since that is how it is stored on
2304 bzero(&sc->areq, sizeof(struct an_ltv_key));
2305 sc->areq.an_len = sizeof(struct an_ltv_key);
2306 key->mac[0] = 1; /* The others are 0. */
2307 if (ireq->i_val < 4) {
2308 sc->areq.an_type = AN_RID_WEP_TEMP;
2309 key->kindex = ireq->i_val;
2311 sc->areq.an_type = AN_RID_WEP_PERM;
2312 key->kindex = ireq->i_val - 4;
2314 key->klen = ireq->i_len;
2315 bcopy(tmpstr, key->key, key->klen);
2317 case IEEE80211_IOC_WEPTXKEY:
2318 if (ireq->i_val < 0 || ireq->i_val > 4) {
2324 * Map the 5th key into the home mode
2325 * since that is how it is stored on
2328 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2329 sc->areq.an_type = AN_RID_ACTUALCFG;
2330 if (an_read_record(sc,
2331 (struct an_ltv_gen *)&sc->areq)) {
2335 if (ireq->i_val == 4) {
2336 config->an_home_product |= AN_HOME_NETWORK;
2339 config->an_home_product &= ~AN_HOME_NETWORK;
2342 sc->an_config.an_home_product
2343 = config->an_home_product;
2345 /* update configuration */
2348 bzero(&sc->areq, sizeof(struct an_ltv_key));
2349 sc->areq.an_len = sizeof(struct an_ltv_key);
2350 sc->areq.an_type = AN_RID_WEP_PERM;
2351 key->kindex = 0xffff;
2352 key->mac[0] = ireq->i_val;
2354 case IEEE80211_IOC_AUTHMODE:
2355 switch (ireq->i_val) {
2356 case IEEE80211_AUTH_NONE:
2357 config->an_authtype = AN_AUTHTYPE_NONE |
2358 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2360 case IEEE80211_AUTH_OPEN:
2361 config->an_authtype = AN_AUTHTYPE_OPEN |
2362 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2364 case IEEE80211_AUTH_SHARED:
2365 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2366 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2372 case IEEE80211_IOC_STATIONNAME:
2373 if (ireq->i_len > 16) {
2377 bzero(config->an_nodename, 16);
2378 error = copyin(ireq->i_data,
2379 config->an_nodename, ireq->i_len);
2381 case IEEE80211_IOC_CHANNEL:
2383 * The actual range is 1-14, but if you set it
2384 * to 0 you get the default so we let that work
2387 if (ireq->i_val < 0 || ireq->i_val >14) {
2391 config->an_ds_channel = ireq->i_val;
2393 case IEEE80211_IOC_POWERSAVE:
2394 switch (ireq->i_val) {
2395 case IEEE80211_POWERSAVE_OFF:
2396 config->an_psave_mode = AN_PSAVE_NONE;
2398 case IEEE80211_POWERSAVE_CAM:
2399 config->an_psave_mode = AN_PSAVE_CAM;
2401 case IEEE80211_POWERSAVE_PSP:
2402 config->an_psave_mode = AN_PSAVE_PSP;
2404 case IEEE80211_POWERSAVE_PSP_CAM:
2405 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2412 case IEEE80211_IOC_POWERSAVESLEEP:
2413 config->an_listen_interval = ireq->i_val;
2418 an_setdef(sc, &sc->areq);
2421 error = ether_ioctl(ifp, command, data);
2432 struct an_softc *sc;
2438 for (i = 0; i < AN_TX_RING_CNT; i++) {
2439 if (an_alloc_nicmem(sc, 1518 +
2442 sc->an_rdata.an_tx_fids[i] = id;
2443 sc->an_rdata.an_tx_ring[i] = 0;
2447 sc->an_rdata.an_tx_prod = 0;
2448 sc->an_rdata.an_tx_cons = 0;
2449 sc->an_rdata.an_tx_empty = 1;
2458 struct an_softc *sc = xsc;
2459 struct ifnet *ifp = &sc->arpcom.ac_if;
2462 if (ifp->if_flags & IFF_RUNNING)
2465 sc->an_associated = 0;
2467 /* Allocate the TX buffers */
2468 if (an_init_tx_ring(sc)) {
2471 an_init_mpi350_desc(sc);
2472 if (an_init_tx_ring(sc)) {
2474 if_printf(ifp, "tx buffer allocation failed\n");
2479 /* Set our MAC address. */
2480 bcopy((char *)&sc->arpcom.ac_enaddr,
2481 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2483 if (ifp->if_flags & IFF_BROADCAST)
2484 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2486 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2488 if (ifp->if_flags & IFF_MULTICAST)
2489 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2491 if (ifp->if_flags & IFF_PROMISC) {
2492 if (sc->an_monitor & AN_MONITOR) {
2493 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2494 sc->an_config.an_rxmode |=
2495 AN_RXMODE_80211_MONITOR_ANYBSS |
2496 AN_RXMODE_NO_8023_HEADER;
2498 sc->an_config.an_rxmode |=
2499 AN_RXMODE_80211_MONITOR_CURBSS |
2500 AN_RXMODE_NO_8023_HEADER;
2505 if (sc->an_have_rssimap)
2506 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2508 /* Set the ssid list */
2509 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2510 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2511 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2513 if_printf(ifp, "failed to set ssid list\n");
2517 /* Set the AP list */
2518 sc->an_aplist.an_type = AN_RID_APLIST;
2519 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2520 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2522 if_printf(ifp, "failed to set AP list\n");
2526 /* Set the configuration in the NIC */
2527 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2528 sc->an_config.an_type = AN_RID_GENCONFIG;
2529 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2531 if_printf(ifp, "failed to set configuration\n");
2535 /* Enable the MAC */
2536 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2538 if_printf(ifp, "failed to enable MAC\n");
2542 if (ifp->if_flags & IFF_PROMISC)
2543 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2545 /* enable interrupts */
2546 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2548 ifp->if_flags |= IFF_RUNNING;
2549 ifp->if_flags &= ~IFF_OACTIVE;
2551 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
2560 struct an_softc *sc;
2561 struct mbuf *m0 = NULL;
2562 struct an_txframe_802_3 tx_frame_802_3;
2563 struct ether_header *eh;
2565 unsigned char txcontrol;
2566 struct an_card_tx_desc an_tx_desc;
2571 if (ifp->if_flags & IFF_OACTIVE)
2574 if (!sc->an_associated)
2577 /* We can't send in monitor mode so toss any attempts. */
2578 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2579 ifq_purge(&ifp->if_snd);
2583 idx = sc->an_rdata.an_tx_prod;
2586 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2588 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2589 m0 = ifq_dequeue(&ifp->if_snd);
2593 id = sc->an_rdata.an_tx_fids[idx];
2594 eh = mtod(m0, struct ether_header *);
2596 bcopy((char *)&eh->ether_dhost,
2597 (char *)&tx_frame_802_3.an_tx_dst_addr,
2599 bcopy((char *)&eh->ether_shost,
2600 (char *)&tx_frame_802_3.an_tx_src_addr,
2603 /* minus src/dest mac & type */
2604 tx_frame_802_3.an_tx_802_3_payload_len =
2605 m0->m_pkthdr.len - 12;
2607 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2608 tx_frame_802_3.an_tx_802_3_payload_len,
2609 (caddr_t)&sc->an_txbuf);
2611 txcontrol = AN_TXCTL_8023;
2612 /* write the txcontrol only */
2613 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2617 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2618 sizeof(struct an_txframe_802_3));
2620 /* in mbuf header type is just before payload */
2621 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2622 tx_frame_802_3.an_tx_802_3_payload_len);
2629 sc->an_rdata.an_tx_ring[idx] = id;
2630 if (an_cmd(sc, AN_CMD_TX, id))
2631 if_printf(ifp, "xmit failed\n");
2633 AN_INC(idx, AN_TX_RING_CNT);
2636 * Set a timeout in case the chip goes out to lunch.
2640 } else { /* MPI-350 */
2641 /* Disable interrupts. */
2642 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2644 while (sc->an_rdata.an_tx_empty ||
2645 idx != sc->an_rdata.an_tx_cons) {
2646 m0 = ifq_dequeue(&ifp->if_snd);
2650 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2652 eh = mtod(m0, struct ether_header *);
2654 /* DJA optimize this to limit bcopy */
2655 bcopy((char *)&eh->ether_dhost,
2656 (char *)&tx_frame_802_3.an_tx_dst_addr,
2658 bcopy((char *)&eh->ether_shost,
2659 (char *)&tx_frame_802_3.an_tx_src_addr,
2662 /* minus src/dest mac & type */
2663 tx_frame_802_3.an_tx_802_3_payload_len =
2664 m0->m_pkthdr.len - 12;
2666 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2667 tx_frame_802_3.an_tx_802_3_payload_len,
2668 (caddr_t)&sc->an_txbuf);
2670 txcontrol = AN_TXCTL_8023;
2671 /* write the txcontrol only */
2672 bcopy((caddr_t)&txcontrol, &buf[0x08],
2676 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2677 sizeof(struct an_txframe_802_3));
2679 /* in mbuf header type is just before payload */
2680 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2681 tx_frame_802_3.an_tx_802_3_payload_len);
2684 bzero(&an_tx_desc, sizeof(an_tx_desc));
2685 an_tx_desc.an_offset = 0;
2686 an_tx_desc.an_eoc = 1;
2687 an_tx_desc.an_valid = 1;
2688 an_tx_desc.an_len = 0x44 +
2689 tx_frame_802_3.an_tx_802_3_payload_len;
2690 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2691 for (i = 0; i < sizeof(an_tx_desc) / 4 ; i++) {
2692 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2694 + (0 * sizeof(an_tx_desc))
2696 ((u_int32_t*)&an_tx_desc)[i]);
2704 AN_INC(idx, AN_MAX_TX_DESC);
2705 sc->an_rdata.an_tx_empty = 0;
2707 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2710 * Set a timeout in case the chip goes out to lunch.
2715 /* Re-enable interrupts. */
2716 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2720 ifp->if_flags |= IFF_OACTIVE;
2722 sc->an_rdata.an_tx_prod = idx;
2727 struct an_softc *sc;
2732 ifp = &sc->arpcom.ac_if;
2736 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2737 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2738 an_cmd(sc, AN_CMD_DISABLE, 0);
2740 for (i = 0; i < AN_TX_RING_CNT; i++)
2741 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2743 callout_stop(&sc->an_stat_timer);
2745 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2747 if (sc->an_flash_buffer) {
2748 free(sc->an_flash_buffer, M_DEVBUF);
2749 sc->an_flash_buffer = NULL;
2759 struct an_softc *sc;
2766 an_init_mpi350_desc(sc);
2772 if_printf(ifp, "device timeout\n");
2779 struct an_softc *sc;
2781 sc = device_get_softc(dev);
2791 struct an_softc *sc;
2795 sc = device_get_softc(dev);
2796 ifp = &sc->arpcom.ac_if;
2800 an_init_mpi350_desc(sc);
2803 /* Recovery temporary keys */
2804 for (i = 0; i < 4; i++) {
2805 sc->areq.an_type = AN_RID_WEP_TEMP;
2806 sc->areq.an_len = sizeof(struct an_ltv_key);
2807 bcopy(&sc->an_temp_keys[i],
2808 &sc->areq, sizeof(struct an_ltv_key));
2809 an_setdef(sc, &sc->areq);
2812 if (ifp->if_flags & IFF_UP)
2819 /* Aironet signal strength cache code.
2820 * store signal/noise/quality on per MAC src basis in
2821 * a small fixed cache. The cache wraps if > MAX slots
2822 * used. The cache may be zeroed out to start over.
2823 * Two simple filters exist to reduce computation:
2824 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2825 * to ignore some packets. It defaults to ip only.
2826 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2827 * 2. multicast/broadcast only. This may be used to
2828 * ignore unicast packets and only cache signal strength
2829 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2830 * beacons and not unicast traffic.
2832 * The cache stores (MAC src(index), IP src (major clue), signal,
2835 * No apologies for storing IP src here. It's easy and saves much
2836 * trouble elsewhere. The cache is assumed to be INET dependent,
2837 * although it need not be.
2839 * Note: the Aironet only has a single byte of signal strength value
2840 * in the rx frame header, and it's not scaled to anything sensible.
2841 * This is kind of lame, but it's all we've got.
2844 #ifdef documentation
2846 int an_sigitems; /* number of cached entries */
2847 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2848 int an_nextitem; /* index/# of entries */
2853 /* control variables for cache filtering. Basic idea is
2854 * to reduce cost (e.g., to only Mobile-IP agent beacons
2855 * which are broadcast or multicast). Still you might
2856 * want to measure signal strength anth unicast ping packets
2857 * on a pt. to pt. ant. setup.
2859 /* set true if you want to limit cache items to broadcast/mcast
2860 * only packets (not unicast). Useful for mobile-ip beacons which
2861 * are broadcast/multicast at network layer. Default is all packets
2862 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2864 static int an_cache_mcastonly = 0;
2865 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2866 &an_cache_mcastonly, 0, "");
2868 /* set true if you want to limit cache items to IP packets only
2870 static int an_cache_iponly = 1;
2871 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2872 &an_cache_iponly, 0, "");
2875 * an_cache_store, per rx packet store signal
2876 * strength in MAC (src) indexed cache.
2879 an_cache_store (sc, m, rx_rssi, rx_quality)
2880 struct an_softc *sc;
2883 u_int8_t rx_quality;
2885 struct ether_header *eh = mtod(m, struct ether_header *);
2886 struct ip *ip = NULL;
2888 static int cache_slot = 0; /* use this cache entry */
2889 static int wrapindex = 0; /* next "free" cache entry */
2893 * 2. configurable filter to throw out unicast packets,
2894 * keep multicast only.
2897 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2898 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2899 else if (an_cache_iponly)
2902 /* filter for broadcast/multicast only
2904 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2909 if_printf(&sc->arpcom.ac_if, "q value %x (MSB=0x%x, LSB=0x%x)\n",
2910 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2913 /* do a linear search for a matching MAC address
2914 * in the cache table
2915 * . MAC address is 6 bytes,
2916 * . var w_nextitem holds total number of entries already cached
2918 for (i = 0; i < sc->an_nextitem; i++) {
2919 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2921 * so we already have this entry,
2928 /* did we find a matching mac address?
2929 * if yes, then overwrite a previously existing cache entry
2931 if (i < sc->an_nextitem ) {
2934 /* else, have a new address entry,so
2935 * add this new entry,
2936 * if table full, then we need to replace LRU entry
2940 /* check for space in cache table
2941 * note: an_nextitem also holds number of entries
2942 * added in the cache table
2944 if ( sc->an_nextitem < MAXANCACHE ) {
2945 cache_slot = sc->an_nextitem;
2947 sc->an_sigitems = sc->an_nextitem;
2949 /* no space found, so simply wrap anth wrap index
2950 * and "zap" the next entry
2953 if (wrapindex == MAXANCACHE) {
2956 cache_slot = wrapindex++;
2960 /* invariant: cache_slot now points at some slot
2963 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
2964 log(LOG_ERR, "an_cache_store, bad index: %d of "
2965 "[0..%d], gross cache error\n",
2966 cache_slot, MAXANCACHE);
2970 /* store items in cache
2971 * .ip source address
2976 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2978 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2981 switch (an_cache_mode) {
2983 if (sc->an_have_rssimap) {
2984 sc->an_sigcache[cache_slot].signal =
2985 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
2986 sc->an_sigcache[cache_slot].quality =
2987 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
2989 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
2990 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
2994 if (sc->an_have_rssimap) {
2995 sc->an_sigcache[cache_slot].signal =
2996 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
2997 sc->an_sigcache[cache_slot].quality =
2998 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3002 if (rx_quality > 100)
3004 sc->an_sigcache[cache_slot].signal = rx_rssi;
3005 sc->an_sigcache[cache_slot].quality = rx_quality;
3009 sc->an_sigcache[cache_slot].signal = rx_rssi;
3010 sc->an_sigcache[cache_slot].quality = rx_quality;
3014 sc->an_sigcache[cache_slot].noise = 0;
3021 an_media_change(ifp)
3024 struct an_softc *sc = ifp->if_softc;
3025 struct an_ltv_genconfig *cfg;
3026 int otype = sc->an_config.an_opmode;
3027 int orate = sc->an_tx_rate;
3029 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
3030 case IFM_IEEE80211_DS1:
3031 sc->an_tx_rate = AN_RATE_1MBPS;
3033 case IFM_IEEE80211_DS2:
3034 sc->an_tx_rate = AN_RATE_2MBPS;
3036 case IFM_IEEE80211_DS5:
3037 sc->an_tx_rate = AN_RATE_5_5MBPS;
3039 case IFM_IEEE80211_DS11:
3040 sc->an_tx_rate = AN_RATE_11MBPS;
3047 if (orate != sc->an_tx_rate) {
3048 /* Read the current configuration */
3049 sc->an_config.an_type = AN_RID_GENCONFIG;
3050 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3051 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3052 cfg = &sc->an_config;
3054 /* clear other rates and set the only one we want */
3055 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3056 cfg->an_rates[0] = sc->an_tx_rate;
3058 /* Save the new rate */
3059 sc->an_config.an_type = AN_RID_GENCONFIG;
3060 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3063 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3064 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3066 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3068 if (otype != sc->an_config.an_opmode ||
3069 orate != sc->an_tx_rate)
3076 an_media_status(ifp, imr)
3078 struct ifmediareq *imr;
3080 struct an_ltv_status status;
3081 struct an_softc *sc = ifp->if_softc;
3083 status.an_len = sizeof(status);
3084 status.an_type = AN_RID_STATUS;
3085 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3086 /* If the status read fails, just lie. */
3087 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3088 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3091 if (sc->an_tx_rate == 0) {
3092 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3093 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3094 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3095 switch (status.an_current_tx_rate) {
3097 imr->ifm_active |= IFM_IEEE80211_DS1;
3100 imr->ifm_active |= IFM_IEEE80211_DS2;
3102 case AN_RATE_5_5MBPS:
3103 imr->ifm_active |= IFM_IEEE80211_DS5;
3105 case AN_RATE_11MBPS:
3106 imr->ifm_active |= IFM_IEEE80211_DS11;
3110 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3113 imr->ifm_status = IFM_AVALID;
3114 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3115 imr->ifm_status |= IFM_ACTIVE;
3118 /********************** Cisco utility support routines *************/
3121 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3126 readrids(ifp, l_ioctl)
3128 struct aironet_ioctl *l_ioctl;
3131 struct an_softc *sc;
3133 switch (l_ioctl->command) {
3135 rid = AN_RID_CAPABILITIES;
3138 rid = AN_RID_GENCONFIG;
3141 rid = AN_RID_SSIDLIST;
3144 rid = AN_RID_APLIST;
3147 rid = AN_RID_DRVNAME;
3150 rid = AN_RID_ENCAPPROTO;
3153 rid = AN_RID_WEP_TEMP;
3156 rid = AN_RID_WEP_PERM;
3159 rid = AN_RID_STATUS;
3162 rid = AN_RID_32BITS_DELTA;
3165 rid = AN_RID_32BITS_CUM;
3172 if (rid == 999) /* Is bad command */
3176 sc->areq.an_len = AN_MAX_DATALEN;
3177 sc->areq.an_type = rid;
3179 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3181 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3183 /* the data contains the length at first */
3184 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3185 sizeof(sc->areq.an_len))) {
3188 /* Just copy the data back */
3189 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3197 writerids(ifp, l_ioctl)
3199 struct aironet_ioctl *l_ioctl;
3201 struct an_softc *sc;
3206 command = l_ioctl->command;
3210 rid = AN_RID_SSIDLIST;
3213 rid = AN_RID_CAPABILITIES;
3216 rid = AN_RID_APLIST;
3219 rid = AN_RID_GENCONFIG;
3222 an_cmd(sc, AN_CMD_ENABLE, 0);
3226 an_cmd(sc, AN_CMD_DISABLE, 0);
3231 * This command merely clears the counts does not actually
3232 * store any data only reads rid. But as it changes the cards
3233 * state, I put it in the writerid routines.
3236 rid = AN_RID_32BITS_DELTACLR;
3238 sc->areq.an_len = AN_MAX_DATALEN;
3239 sc->areq.an_type = rid;
3241 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3242 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3244 /* the data contains the length at first */
3245 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3246 sizeof(sc->areq.an_len))) {
3249 /* Just copy the data */
3250 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3257 rid = AN_RID_WEP_TEMP;
3260 rid = AN_RID_WEP_PERM;
3263 rid = AN_RID_LEAPUSERNAME;
3266 rid = AN_RID_LEAPPASSWORD;
3273 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3275 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3276 sc->areq.an_type = rid;
3278 /* Just copy the data back */
3279 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3282 an_cmd(sc, AN_CMD_DISABLE, 0);
3283 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3284 an_cmd(sc, AN_CMD_ENABLE, 0);
3291 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3295 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3296 #define FLASH_COMMAND 0x7e7e
3297 #define FLASH_SIZE 32 * 1024
3303 struct an_softc *sc = ifp->if_softc;
3305 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3306 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3307 AN_EV_CLR_STUCK_BUSY);
3314 * Wait for busy completion from card wait for delay uSec's Return true for
3315 * success meaning command reg is clear
3323 int statword = 0xffff;
3325 struct an_softc *sc = ifp->if_softc;
3327 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3330 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3332 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3337 return 0 == (AN_CMD_BUSY & statword);
3341 * STEP 1) Disable MAC and do soft reset on card.
3349 struct an_softc *sc = ifp->if_softc;
3353 an_cmd(sc, AN_CMD_DISABLE, 0);
3355 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3356 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3359 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3361 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3364 if (!(status = WaitBusy(ifp, 100))) {
3365 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3372 * STEP 2) Put the card in legendary flash mode
3380 struct an_softc *sc = ifp->if_softc;
3382 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3383 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3384 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3385 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3388 * mdelay(500); // 500ms delay
3393 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3394 printf("Waitbusy hang after setflash mode\n");
3401 * Get a character from the card matching matchbyte Step 3)
3405 flashgchar(ifp, matchbyte, dwelltime)
3411 unsigned char rbyte = 0;
3413 struct an_softc *sc = ifp->if_softc;
3417 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3419 if (dwelltime && !(0x8000 & rchar)) {
3424 rbyte = 0xff & rchar;
3426 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3427 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3431 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3433 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3435 } while (dwelltime > 0);
3440 * Put character to SWS0 wait for dwelltime x 50us for echo .
3444 flashpchar(ifp, byte, dwelltime)
3450 int pollbusy, waittime;
3451 struct an_softc *sc = ifp->if_softc;
3458 waittime = dwelltime;
3461 * Wait for busy bit d15 to go false indicating buffer empty
3464 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3466 if (pollbusy & 0x8000) {
3473 while (waittime >= 0);
3475 /* timeout for busy clear wait */
3477 if (waittime <= 0) {
3478 if_printf(ifp, "flash putchar busywait timeout!\n");
3482 * Port is clear now write byte and wait for it to echo back
3485 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3488 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3489 } while (dwelltime >= 0 && echo != byte);
3492 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3494 return echo == byte;
3498 * Transfer 32k of firmware data from user buffer to our buffer and send to
3506 unsigned short *bufp;
3508 struct an_softc *sc = ifp->if_softc;
3512 bufp = sc->an_flash_buffer;
3515 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3516 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3518 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3519 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3522 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3523 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3524 ((u_int32_t *)bufp)[nwords] & 0xffff);
3528 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3534 * After flashing restart the card.
3542 struct an_softc *sc = ifp->if_softc;
3544 FLASH_DELAY(1024); /* Added 12/7/00 */
3548 FLASH_DELAY(1024); /* Added 12/7/00 */
3553 * Entry point for flash ioclt.
3557 flashcard(ifp, l_ioctl)
3559 struct aironet_ioctl *l_ioctl;
3562 struct an_softc *sc;
3566 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3569 status = l_ioctl->command;
3571 switch (l_ioctl->command) {
3573 return cmdreset(ifp);
3576 if (sc->an_flash_buffer) {
3577 free(sc->an_flash_buffer, M_DEVBUF);
3578 sc->an_flash_buffer = NULL;
3580 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3581 if (sc->an_flash_buffer)
3582 return setflashmode(ifp);
3586 case AIROFLSHGCHR: /* Get char from aux */
3587 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3588 z = *(int *)&sc->areq;
3589 if ((status = flashgchar(ifp, z, 8000)) == 1)
3594 case AIROFLSHPCHR: /* Send char to card. */
3595 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3596 z = *(int *)&sc->areq;
3597 if ((status = flashpchar(ifp, z, 8000)) == -1)
3602 case AIROFLPUTBUF: /* Send 32k to card */
3603 if (l_ioctl->len > FLASH_SIZE) {
3604 if_printf(ifp, "Buffer to big, %x %x\n",
3605 l_ioctl->len, FLASH_SIZE);
3608 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3610 if ((status = flashputbuf(ifp)) != 0)
3616 if ((status = flashrestart(ifp)) != 0) {
3617 if_printf(ifp, "FLASHRESTART returned %d\n", status);