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.18 2005/02/21 18:40:36 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>
96 #include <sys/kernel.h>
98 #include <sys/ucred.h>
99 #include <sys/socket.h>
101 #include <sys/syslog.h>
103 #include <sys/sysctl.h>
104 #include <machine/clock.h> /* for DELAY */
106 #include <sys/module.h>
107 #include <sys/sysctl.h>
109 #include <machine/bus.h>
110 #include <sys/rman.h>
111 #include <machine/resource.h>
112 #include <sys/malloc.h>
115 #include <net/ifq_var.h>
116 #include <net/if_arp.h>
117 #include <net/ethernet.h>
118 #include <net/if_dl.h>
119 #include <net/if_types.h>
120 #include <net/if_media.h>
121 #include <netproto/802_11/ieee80211.h>
122 #include <netproto/802_11/ieee80211_ioctl.h>
125 #include <netinet/in.h>
126 #include <netinet/in_systm.h>
127 #include <netinet/in_var.h>
128 #include <netinet/ip.h>
133 #include <machine/md_var.h>
135 #include "if_aironet_ieee.h"
136 #include "if_anreg.h"
138 /* These are global because we need them in sys/pci/if_an_p.c. */
139 static void an_reset (struct an_softc *);
140 static int an_init_mpi350_desc (struct an_softc *);
141 static int an_ioctl (struct ifnet *, u_long, caddr_t,
143 static void an_init (void *);
144 static int an_init_tx_ring (struct an_softc *);
145 static void an_start (struct ifnet *);
146 static void an_watchdog (struct ifnet *);
147 static void an_rxeof (struct an_softc *);
148 static void an_txeof (struct an_softc *, int);
150 static void an_promisc (struct an_softc *, int);
151 static int an_cmd (struct an_softc *, int, int);
152 static int an_cmd_struct (struct an_softc *, struct an_command *,
154 static int an_read_record (struct an_softc *, struct an_ltv_gen *);
155 static int an_write_record (struct an_softc *, struct an_ltv_gen *);
156 static int an_read_data (struct an_softc *, int,
158 static int an_write_data (struct an_softc *, int,
160 static int an_seek (struct an_softc *, int, int, int);
161 static int an_alloc_nicmem (struct an_softc *, int, int *);
162 static int an_dma_malloc (struct an_softc *, bus_size_t,
163 struct an_dma_alloc *, int);
164 static void an_dma_free (struct an_softc *,
165 struct an_dma_alloc *);
166 static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
167 static void an_stats_update (void *);
168 static void an_setdef (struct an_softc *, struct an_req *);
170 static void an_cache_store (struct an_softc *, struct mbuf *,
174 /* function definitions for use with the Cisco's Linux configuration
178 static int readrids (struct ifnet*, struct aironet_ioctl*);
179 static int writerids (struct ifnet*, struct aironet_ioctl*);
180 static int flashcard (struct ifnet*, struct aironet_ioctl*);
182 static int cmdreset (struct ifnet *);
183 static int setflashmode (struct ifnet *);
184 static int flashgchar (struct ifnet *,int,int);
185 static int flashpchar (struct ifnet *,int,int);
186 static int flashputbuf (struct ifnet *);
187 static int flashrestart (struct ifnet *);
188 static int WaitBusy (struct ifnet *, int);
189 static int unstickbusy (struct ifnet *);
191 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
194 static int an_media_change (struct ifnet *);
195 static void an_media_status (struct ifnet *, struct ifmediareq *);
197 static int an_dump = 0;
198 static int an_cache_mode = 0;
204 static char an_conf[256];
205 static char an_conf_cache[256];
207 DECLARE_DUMMY_MODULE(if_an);
211 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
214 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
223 strcpy(an_conf, "off");
226 strcpy(an_conf, "type");
229 strcpy(an_conf, "dump");
232 snprintf(an_conf, 5, "%x", an_dump);
236 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
238 if (strncmp(an_conf,"off", 3) == 0) {
241 if (strncmp(an_conf,"dump", 4) == 0) {
244 if (strncmp(an_conf,"type", 4) == 0) {
250 if ((*s >= '0') && (*s <= '9')) {
251 r = r * 16 + (*s - '0');
252 } else if ((*s >= 'a') && (*s <= 'f')) {
253 r = r * 16 + (*s - 'a' + 10);
261 printf("Sysctl changed for Aironet driver\n");
266 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
267 0, sizeof(an_conf), sysctl_an_dump, "A", "");
270 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
274 last = an_cache_mode;
276 switch (an_cache_mode) {
278 strcpy(an_conf_cache, "per");
281 strcpy(an_conf_cache, "raw");
284 strcpy(an_conf_cache, "dbm");
288 error = sysctl_handle_string(oidp, an_conf_cache,
289 sizeof(an_conf_cache), req);
291 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
294 if (strncmp(an_conf_cache,"per", 3) == 0) {
297 if (strncmp(an_conf_cache,"raw", 3) == 0) {
304 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
305 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
308 * We probe for an Aironet 4500/4800 card by attempting to
309 * read the default SSID list. On reset, the first entry in
310 * the SSID list will contain the name "tsunami." If we don't
311 * find this, then there's no card present.
317 struct an_softc *sc = device_get_softc(dev);
318 struct an_ltv_ssidlist ssid;
321 bzero((char *)&ssid, sizeof(ssid));
323 error = an_alloc_port(dev, 0, AN_IOSIZ);
327 /* can't do autoprobing */
328 if (rman_get_start(sc->port_res) == -1)
332 * We need to fake up a softc structure long enough
333 * to be able to issue commands and call some of the
336 sc->an_bhandle = rman_get_bushandle(sc->port_res);
337 sc->an_btag = rman_get_bustag(sc->port_res);
338 sc->an_unit = device_get_unit(dev);
340 ssid.an_len = sizeof(ssid);
341 ssid.an_type = AN_RID_SSIDLIST;
343 /* Make sure interrupts are disabled. */
344 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
345 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
348 /* No need for an_init_mpi350_desc since it will be done in attach */
350 if (an_cmd(sc, AN_CMD_READCFG, 0))
353 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
356 /* See if the ssid matches what we expect ... but doesn't have to */
357 if (strcmp(ssid.an_ssid1, AN_DEF_SSID))
364 * Allocate a port resource with the given resource id.
367 an_alloc_port(dev, rid, size)
372 struct an_softc *sc = device_get_softc(dev);
373 struct resource *res;
375 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
376 0ul, ~0ul, size, RF_ACTIVE);
387 * Allocate a memory resource with the given resource id.
389 int an_alloc_memory(device_t dev, int rid, int size)
391 struct an_softc *sc = device_get_softc(dev);
392 struct resource *res;
394 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
395 0ul, ~0ul, size, RF_ACTIVE);
407 * Allocate a auxilary memory resource with the given resource id.
409 int an_alloc_aux_memory(device_t dev, int rid, int size)
411 struct an_softc *sc = device_get_softc(dev);
412 struct resource *res;
414 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
415 0ul, ~0ul, size, RF_ACTIVE);
417 sc->mem_aux_rid = rid;
418 sc->mem_aux_res = res;
419 sc->mem_aux_used = size;
427 * Allocate an irq resource with the given resource id.
430 an_alloc_irq(dev, rid, flags)
435 struct an_softc *sc = device_get_softc(dev);
436 struct resource *res;
438 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
439 0ul, ~0ul, 1, (RF_ACTIVE | flags));
450 an_dma_malloc_cb(arg, segs, nseg, error)
452 bus_dma_segment_t *segs;
456 bus_addr_t *paddr = (bus_addr_t*) arg;
457 *paddr = segs->ds_addr;
461 * Alloc DMA memory and set the pointer to it
464 an_dma_malloc(sc, size, dma, mapflags)
467 struct an_dma_alloc *dma;
472 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
476 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
477 BUS_DMA_NOWAIT, &dma->an_dma_map);
481 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
485 mapflags | BUS_DMA_NOWAIT);
489 dma->an_dma_size = size;
493 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
495 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
497 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
498 dma->an_dma_map = NULL;
505 struct an_dma_alloc *dma;
507 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
508 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
509 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
513 * Release all resources
516 an_release_resources(dev)
519 struct an_softc *sc = device_get_softc(dev);
523 bus_release_resource(dev, SYS_RES_IOPORT,
524 sc->port_rid, sc->port_res);
528 bus_release_resource(dev, SYS_RES_MEMORY,
529 sc->mem_rid, sc->mem_res);
532 if (sc->mem_aux_res) {
533 bus_release_resource(dev, SYS_RES_MEMORY,
534 sc->mem_aux_rid, sc->mem_aux_res);
538 bus_release_resource(dev, SYS_RES_IRQ,
539 sc->irq_rid, sc->irq_res);
542 if (sc->an_rid_buffer.an_dma_paddr) {
543 an_dma_free(sc, &sc->an_rid_buffer);
545 for (i = 0; i < AN_MAX_RX_DESC; i++)
546 if (sc->an_rx_buffer[i].an_dma_paddr) {
547 an_dma_free(sc, &sc->an_rx_buffer[i]);
549 for (i = 0; i < AN_MAX_TX_DESC; i++)
550 if (sc->an_tx_buffer[i].an_dma_paddr) {
551 an_dma_free(sc, &sc->an_tx_buffer[i]);
554 bus_dma_tag_destroy(sc->an_dtag);
560 an_init_mpi350_desc(sc)
563 struct an_command cmd_struct;
564 struct an_reply reply;
565 struct an_card_rid_desc an_rid_desc;
566 struct an_card_rx_desc an_rx_desc;
567 struct an_card_tx_desc an_tx_desc;
570 if(!sc->an_rid_buffer.an_dma_paddr)
571 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
572 &sc->an_rid_buffer, 0);
573 for (i = 0; i < AN_MAX_RX_DESC; i++)
574 if(!sc->an_rx_buffer[i].an_dma_paddr)
575 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
576 &sc->an_rx_buffer[i], 0);
577 for (i = 0; i < AN_MAX_TX_DESC; i++)
578 if(!sc->an_tx_buffer[i].an_dma_paddr)
579 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
580 &sc->an_tx_buffer[i], 0);
583 * Allocate RX descriptor
585 bzero(&reply,sizeof(reply));
586 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
587 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
588 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
589 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
590 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
591 printf("an%d: failed to allocate RX descriptor\n",
596 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
597 bzero(&an_rx_desc, sizeof(an_rx_desc));
598 an_rx_desc.an_valid = 1;
599 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
600 an_rx_desc.an_done = 0;
601 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
603 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
604 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
605 + (desc * sizeof(an_rx_desc))
607 ((u_int32_t*)&an_rx_desc)[i]);
611 * Allocate TX descriptor
614 bzero(&reply,sizeof(reply));
615 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
616 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
617 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
618 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
619 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
620 printf("an%d: failed to allocate TX descriptor\n",
625 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
626 bzero(&an_tx_desc, sizeof(an_tx_desc));
627 an_tx_desc.an_offset = 0;
628 an_tx_desc.an_eoc = 0;
629 an_tx_desc.an_valid = 0;
630 an_tx_desc.an_len = 0;
631 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
633 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
634 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
635 + (desc * sizeof(an_tx_desc))
637 ((u_int32_t*)&an_tx_desc)[i]);
641 * Allocate RID descriptor
644 bzero(&reply,sizeof(reply));
645 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
646 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
647 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
648 cmd_struct.an_parm2 = 1;
649 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
650 printf("an%d: failed to allocate host descriptor\n",
655 bzero(&an_rid_desc, sizeof(an_rid_desc));
656 an_rid_desc.an_valid = 1;
657 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
658 an_rid_desc.an_rid = 0;
659 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
661 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
662 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
663 ((u_int32_t*)&an_rid_desc)[i]);
669 an_attach(sc, unit, flags)
674 struct ifnet *ifp = &sc->arpcom.ac_if;
677 callout_init(&sc->an_stat_timer);
679 sc->an_associated = 0;
681 sc->an_was_monitor = 0;
682 sc->an_flash_buffer = NULL;
687 error = an_init_mpi350_desc(sc);
692 /* Load factory config */
693 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
694 printf("an%d: failed to load config data\n", sc->an_unit);
698 /* Read the current configuration */
699 sc->an_config.an_type = AN_RID_GENCONFIG;
700 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
701 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
702 printf("an%d: read record failed\n", sc->an_unit);
706 /* Read the card capabilities */
707 sc->an_caps.an_type = AN_RID_CAPABILITIES;
708 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
709 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
710 printf("an%d: read record failed\n", sc->an_unit);
715 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
716 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
717 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
718 printf("an%d: read record failed\n", sc->an_unit);
723 sc->an_aplist.an_type = AN_RID_APLIST;
724 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
725 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
726 printf("an%d: read record failed\n", sc->an_unit);
731 /* Read the RSSI <-> dBm map */
732 sc->an_have_rssimap = 0;
733 if (sc->an_caps.an_softcaps & 8) {
734 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
735 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
736 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
737 printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
739 printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
740 sc->an_have_rssimap = 1;
743 printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
748 if_initname(ifp, "an", unit);
749 ifp->if_mtu = ETHERMTU;
750 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
751 ifp->if_ioctl = an_ioctl;
752 ifp->if_start = an_start;
753 ifp->if_watchdog = an_watchdog;
754 ifp->if_init = an_init;
755 ifp->if_baudrate = 10000000;
756 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
757 ifq_set_ready(&ifp->if_snd);
759 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
760 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
761 sizeof(AN_DEFAULT_NODENAME) - 1);
763 bzero(sc->an_ssidlist.an_ssid1, sizeof(sc->an_ssidlist.an_ssid1));
764 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_ssid1,
765 sizeof(AN_DEFAULT_NETNAME) - 1);
766 sc->an_ssidlist.an_ssid1_len = strlen(AN_DEFAULT_NETNAME);
768 sc->an_config.an_opmode =
769 AN_OPMODE_INFRASTRUCTURE_STATION;
772 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
774 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
775 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
776 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
777 IFM_IEEE80211_ADHOC, 0), 0);
778 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
779 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
780 IFM_IEEE80211_ADHOC, 0), 0);
781 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
782 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
783 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
784 IFM_IEEE80211_ADHOC, 0), 0);
785 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
787 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
788 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
789 IFM_IEEE80211_ADHOC, 0), 0);
790 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
792 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
793 IFM_IEEE80211_ADHOC, 0), 0);
794 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
796 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
800 * Call MI attach routine.
802 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
812 struct ether_header *eh;
813 struct ieee80211_frame *ih;
814 struct an_rxframe rx_frame;
815 struct an_rxframe_802_3 rx_frame_802_3;
817 int len, id, error = 0, i, count = 0;
818 int ieee80211_header_len;
821 struct an_card_rx_desc an_rx_desc;
824 ifp = &sc->arpcom.ac_if;
827 id = CSR_READ_2(sc, AN_RX_FID);
829 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
830 /* read raw 802.11 packet */
831 bpf_buf = sc->buf_802_11;
834 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
841 * skip beacon by default since this increases the
845 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
846 (rx_frame.an_frame_ctl &
847 IEEE80211_FC0_SUBTYPE_BEACON)) {
851 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
852 len = rx_frame.an_rx_payload_len
854 /* Check for insane frame length */
855 if (len > sizeof(sc->buf_802_11)) {
856 printf("an%d: oversized packet "
857 "received (%d, %d)\n",
858 sc->an_unit, len, MCLBYTES);
863 bcopy((char *)&rx_frame,
864 bpf_buf, sizeof(rx_frame));
866 error = an_read_data(sc, id, sizeof(rx_frame),
867 (caddr_t)bpf_buf+sizeof(rx_frame),
868 rx_frame.an_rx_payload_len);
870 fc1=rx_frame.an_frame_ctl >> 8;
871 ieee80211_header_len =
872 sizeof(struct ieee80211_frame);
873 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
874 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
875 ieee80211_header_len += ETHER_ADDR_LEN;
878 len = rx_frame.an_rx_payload_len
879 + ieee80211_header_len;
880 /* Check for insane frame length */
881 if (len > sizeof(sc->buf_802_11)) {
882 printf("an%d: oversized packet "
883 "received (%d, %d)\n",
884 sc->an_unit, len, MCLBYTES);
889 ih = (struct ieee80211_frame *)bpf_buf;
891 bcopy((char *)&rx_frame.an_frame_ctl,
892 (char *)ih, ieee80211_header_len);
894 error = an_read_data(sc, id, sizeof(rx_frame) +
896 (caddr_t)ih +ieee80211_header_len,
897 rx_frame.an_rx_payload_len);
899 BPF_TAP(ifp, bpf_buf, len);
901 MGETHDR(m, M_NOWAIT, MT_DATA);
907 if (!(m->m_flags & M_EXT)) {
912 m->m_pkthdr.rcvif = ifp;
913 /* Read Ethernet encapsulated packet */
916 /* Read NIC frame header */
917 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
923 /* Read in the 802_3 frame header */
924 if (an_read_data(sc, id, 0x34,
925 (caddr_t)&rx_frame_802_3,
926 sizeof(rx_frame_802_3))) {
930 if (rx_frame_802_3.an_rx_802_3_status != 0) {
934 /* Check for insane frame length */
935 len = rx_frame_802_3.an_rx_802_3_payload_len;
936 if (len > sizeof(sc->buf_802_11)) {
937 printf("an%d: oversized packet "
938 "received (%d, %d)\n",
939 sc->an_unit, len, MCLBYTES);
943 m->m_pkthdr.len = m->m_len =
944 rx_frame_802_3.an_rx_802_3_payload_len + 12;
946 eh = mtod(m, struct ether_header *);
948 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
949 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
950 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
951 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
953 /* in mbuf header type is just before payload */
954 error = an_read_data(sc, id, 0x44,
955 (caddr_t)&(eh->ether_type),
956 rx_frame_802_3.an_rx_802_3_payload_len);
966 an_cache_store(sc, m,
967 rx_frame.an_rx_signal_strength,
970 (*ifp->if_input)(ifp, m);
973 } else { /* MPI-350 */
974 for (count = 0; count < AN_MAX_RX_DESC; count++){
975 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
976 ((u_int32_t*)&an_rx_desc)[i]
977 = CSR_MEM_AUX_READ_4(sc,
979 + (count * sizeof(an_rx_desc))
982 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
983 buf = sc->an_rx_buffer[count].an_dma_vaddr;
985 MGETHDR(m, M_NOWAIT, MT_DATA);
991 if (!(m->m_flags & M_EXT)) {
996 m->m_pkthdr.rcvif = ifp;
997 /* Read Ethernet encapsulated packet */
1000 * No ANCACHE support since we just get back
1001 * an Ethernet packet no 802.11 info
1005 /* Read NIC frame header */
1006 bcopy(buf, (caddr_t)&rx_frame,
1010 /* Check for insane frame length */
1011 len = an_rx_desc.an_len + 12;
1012 if (len > MCLBYTES) {
1013 printf("an%d: oversized packet "
1014 "received (%d, %d)\n",
1015 sc->an_unit, len, MCLBYTES);
1020 m->m_pkthdr.len = m->m_len =
1021 an_rx_desc.an_len + 12;
1023 eh = mtod(m, struct ether_header *);
1025 bcopy(buf, (char *)eh,
1032 an_cache_store(sc, m,
1033 rx_frame.an_rx_signal_strength,
1037 (*ifp->if_input)(ifp, m);
1039 an_rx_desc.an_valid = 1;
1040 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1041 an_rx_desc.an_done = 0;
1042 an_rx_desc.an_phys =
1043 sc->an_rx_buffer[count].an_dma_paddr;
1045 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1046 CSR_MEM_AUX_WRITE_4(sc,
1048 + (count * sizeof(an_rx_desc))
1050 ((u_int32_t*)&an_rx_desc)[i]);
1053 printf("an%d: Didn't get valid RX packet "
1057 an_rx_desc.an_valid, an_rx_desc.an_len);
1064 an_txeof(sc, status)
1065 struct an_softc *sc;
1071 ifp = &sc->arpcom.ac_if;
1074 ifp->if_flags &= ~IFF_OACTIVE;
1077 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1079 if (status & AN_EV_TX_EXC) {
1084 for (i = 0; i < AN_TX_RING_CNT; i++) {
1085 if (id == sc->an_rdata.an_tx_ring[i]) {
1086 sc->an_rdata.an_tx_ring[i] = 0;
1091 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1092 } else { /* MPI 350 */
1093 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1094 if (sc->an_rdata.an_tx_prod ==
1095 sc->an_rdata.an_tx_cons)
1096 sc->an_rdata.an_tx_empty = 1;
1103 * We abuse the stats updater to check the current NIC status. This
1104 * is important because we don't want to allow transmissions until
1105 * the NIC has synchronized to the current cell (either as the master
1106 * in an ad-hoc group, or as a station connected to an access point).
1109 an_stats_update(xsc)
1112 struct an_softc *sc;
1119 ifp = &sc->arpcom.ac_if;
1121 sc->an_status.an_type = AN_RID_STATUS;
1122 sc->an_status.an_len = sizeof(struct an_ltv_status);
1123 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1125 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1126 sc->an_associated = 1;
1128 sc->an_associated = 0;
1130 /* Don't do this while we're transmitting */
1131 if (ifp->if_flags & IFF_OACTIVE) {
1132 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1137 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1138 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1139 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1141 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1151 struct an_softc *sc;
1155 sc = (struct an_softc*)xsc;
1160 ifp = &sc->arpcom.ac_if;
1162 /* Disable interrupts. */
1163 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1165 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1166 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
1168 if (status & AN_EV_AWAKE) {
1169 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
1172 if (status & AN_EV_LINKSTAT) {
1173 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1174 == AN_LINKSTAT_ASSOCIATED)
1175 sc->an_associated = 1;
1177 sc->an_associated = 0;
1178 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1181 if (status & AN_EV_RX) {
1183 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1186 if (status & AN_EV_TX) {
1187 an_txeof(sc, status);
1188 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1191 if (status & AN_EV_TX_EXC) {
1192 an_txeof(sc, status);
1193 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1196 if (status & AN_EV_ALLOC)
1197 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1199 /* Re-enable interrupts. */
1200 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1202 if ((ifp->if_flags & IFF_UP) && !ifq_is_empty(&ifp->if_snd))
1209 an_cmd_struct(sc, cmd, reply)
1210 struct an_softc *sc;
1211 struct an_command *cmd;
1212 struct an_reply *reply;
1216 for (i = 0; i != AN_TIMEOUT; i++) {
1217 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1222 if( i == AN_TIMEOUT) {
1227 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1228 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1229 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1230 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1232 for (i = 0; i < AN_TIMEOUT; i++) {
1233 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1238 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1239 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1240 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1241 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1243 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1244 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1246 /* Ack the command */
1247 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1249 if (i == AN_TIMEOUT)
1256 an_cmd(sc, cmd, val)
1257 struct an_softc *sc;
1263 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1264 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1265 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1266 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1268 for (i = 0; i < AN_TIMEOUT; i++) {
1269 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1272 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1273 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1277 for (i = 0; i < AN_TIMEOUT; i++) {
1278 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1279 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1280 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1281 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1282 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1286 /* Ack the command */
1287 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1289 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1290 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1292 if (i == AN_TIMEOUT)
1299 * This reset sequence may look a little strange, but this is the
1300 * most reliable method I've found to really kick the NIC in the
1301 * head and force it to reboot correctly.
1305 struct an_softc *sc;
1310 an_cmd(sc, AN_CMD_ENABLE, 0);
1311 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1312 an_cmd(sc, AN_CMD_NOOP2, 0);
1314 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1315 printf("an%d: reset failed\n", sc->an_unit);
1317 an_cmd(sc, AN_CMD_DISABLE, 0);
1323 * Read an LTV record from the NIC.
1326 an_read_record(sc, ltv)
1327 struct an_softc *sc;
1328 struct an_ltv_gen *ltv;
1330 struct an_ltv_gen *an_ltv;
1331 struct an_card_rid_desc an_rid_desc;
1332 struct an_command cmd;
1333 struct an_reply reply;
1338 if (ltv->an_len < 4 || ltv->an_type == 0)
1342 /* Tell the NIC to enter record read mode. */
1343 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1344 printf("an%d: RID access failed\n", sc->an_unit);
1348 /* Seek to the record. */
1349 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1350 printf("an%d: seek to record failed\n", sc->an_unit);
1355 * Read the length and record type and make sure they
1356 * match what we expect (this verifies that we have enough
1357 * room to hold all of the returned data).
1358 * Length includes type but not length.
1360 len = CSR_READ_2(sc, AN_DATA1);
1361 if (len > (ltv->an_len - 2)) {
1362 printf("an%d: record length mismatch -- expected %d, "
1363 "got %d for Rid %x\n", sc->an_unit,
1364 ltv->an_len - 2, len, ltv->an_type);
1365 len = ltv->an_len - 2;
1367 ltv->an_len = len + 2;
1370 /* Now read the data. */
1371 len -= 2; /* skip the type */
1373 for (i = len; i > 1; i -= 2)
1374 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1376 ptr2 = (u_int8_t *)ptr;
1377 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1379 } else { /* MPI-350 */
1380 an_rid_desc.an_valid = 1;
1381 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1382 an_rid_desc.an_rid = 0;
1383 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1384 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1386 bzero(&cmd, sizeof(cmd));
1387 bzero(&reply, sizeof(reply));
1388 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1389 cmd.an_parm0 = ltv->an_type;
1391 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1392 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1393 ((u_int32_t*)&an_rid_desc)[i]);
1395 if (an_cmd_struct(sc, &cmd, &reply)
1396 || reply.an_status & AN_CMD_QUAL_MASK) {
1397 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1398 sc->an_unit, ltv->an_type,
1407 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1408 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1409 an_rid_desc.an_len = an_ltv->an_len;
1412 if (an_rid_desc.an_len > 2)
1413 bcopy(&an_ltv->an_type,
1415 an_rid_desc.an_len - 2);
1416 ltv->an_len = an_rid_desc.an_len + 2;
1420 an_dump_record(sc, ltv, "Read");
1426 * Same as read, except we inject data instead of reading it.
1429 an_write_record(sc, ltv)
1430 struct an_softc *sc;
1431 struct an_ltv_gen *ltv;
1433 struct an_card_rid_desc an_rid_desc;
1434 struct an_command cmd;
1435 struct an_reply reply;
1442 an_dump_record(sc, ltv, "Write");
1445 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1448 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1452 * Length includes type but not length.
1454 len = ltv->an_len - 2;
1455 CSR_WRITE_2(sc, AN_DATA1, len);
1457 len -= 2; /* skip the type */
1459 for (i = len; i > 1; i -= 2)
1460 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1462 ptr2 = (u_int8_t *)ptr;
1463 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1466 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1471 for (i = 0; i != AN_TIMEOUT; i++) {
1472 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1478 if (i == AN_TIMEOUT) {
1482 an_rid_desc.an_valid = 1;
1483 an_rid_desc.an_len = ltv->an_len - 2;
1484 an_rid_desc.an_rid = ltv->an_type;
1485 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1487 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1488 an_rid_desc.an_len);
1490 bzero(&cmd,sizeof(cmd));
1491 bzero(&reply,sizeof(reply));
1492 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1493 cmd.an_parm0 = ltv->an_type;
1495 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1496 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1497 ((u_int32_t*)&an_rid_desc)[i]);
1499 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1500 printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
1501 sc->an_unit, ltv->an_type,
1510 ptr = (u_int16_t *)buf;
1512 if (reply.an_status & AN_CMD_QUAL_MASK) {
1513 printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
1514 sc->an_unit, ltv->an_type,
1528 an_dump_record(sc, ltv, string)
1529 struct an_softc *sc;
1530 struct an_ltv_gen *ltv;
1539 len = ltv->an_len - 4;
1540 printf("an%d: RID %4x, Length %4d, Mode %s\n",
1541 sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
1543 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1544 printf("an%d:\t", sc->an_unit);
1545 bzero(buf,sizeof(buf));
1547 ptr2 = (u_int8_t *)<v->an_val;
1548 for (i = len; i > 0; i--) {
1549 printf("%02x ", *ptr2);
1552 if (temp >= ' ' && temp <= '~')
1554 else if (temp >= 'A' && temp <= 'Z')
1558 if (++count == 16) {
1561 printf("an%d:\t", sc->an_unit);
1562 bzero(buf,sizeof(buf));
1565 for (; count != 16; count++) {
1568 printf(" %s\n",buf);
1573 an_seek(sc, id, off, chan)
1574 struct an_softc *sc;
1590 printf("an%d: invalid data path: %x\n", sc->an_unit, chan);
1594 CSR_WRITE_2(sc, selreg, id);
1595 CSR_WRITE_2(sc, offreg, off);
1597 for (i = 0; i < AN_TIMEOUT; i++) {
1598 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1602 if (i == AN_TIMEOUT)
1609 an_read_data(sc, id, off, buf, len)
1610 struct an_softc *sc;
1620 if (an_seek(sc, id, off, AN_BAP1))
1624 ptr = (u_int16_t *)buf;
1625 for (i = len; i > 1; i -= 2)
1626 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1628 ptr2 = (u_int8_t *)ptr;
1629 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1636 an_write_data(sc, id, off, buf, len)
1637 struct an_softc *sc;
1647 if (an_seek(sc, id, off, AN_BAP0))
1651 ptr = (u_int16_t *)buf;
1652 for (i = len; i > 1; i -= 2)
1653 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1655 ptr2 = (u_int8_t *)ptr;
1656 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1663 * Allocate a region of memory inside the NIC and zero
1667 an_alloc_nicmem(sc, len, id)
1668 struct an_softc *sc;
1674 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1675 printf("an%d: failed to allocate %d bytes on NIC\n",
1680 for (i = 0; i < AN_TIMEOUT; i++) {
1681 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1685 if (i == AN_TIMEOUT)
1688 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1689 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1691 if (an_seek(sc, *id, 0, AN_BAP0))
1694 for (i = 0; i < len / 2; i++)
1695 CSR_WRITE_2(sc, AN_DATA0, 0);
1702 struct an_softc *sc;
1703 struct an_req *areq;
1705 struct sockaddr_dl *sdl;
1708 struct an_ltv_genconfig *cfg;
1709 struct an_ltv_ssidlist *ssid;
1710 struct an_ltv_aplist *ap;
1711 struct an_ltv_gen *sp;
1713 ifp = &sc->arpcom.ac_if;
1715 switch (areq->an_type) {
1716 case AN_RID_GENCONFIG:
1717 cfg = (struct an_ltv_genconfig *)areq;
1719 ifa = ifnet_addrs[ifp->if_index - 1];
1720 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1721 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1723 bcopy((char *)&cfg->an_macaddr, LLADDR(sdl), ETHER_ADDR_LEN);
1725 bcopy((char *)cfg, (char *)&sc->an_config,
1726 sizeof(struct an_ltv_genconfig));
1728 case AN_RID_SSIDLIST:
1729 ssid = (struct an_ltv_ssidlist *)areq;
1730 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1731 sizeof(struct an_ltv_ssidlist));
1734 ap = (struct an_ltv_aplist *)areq;
1735 bcopy((char *)ap, (char *)&sc->an_aplist,
1736 sizeof(struct an_ltv_aplist));
1738 case AN_RID_TX_SPEED:
1739 sp = (struct an_ltv_gen *)areq;
1740 sc->an_tx_rate = sp->an_val;
1742 /* Read the current configuration */
1743 sc->an_config.an_type = AN_RID_GENCONFIG;
1744 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1745 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1746 cfg = &sc->an_config;
1748 /* clear other rates and set the only one we want */
1749 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1750 cfg->an_rates[0] = sc->an_tx_rate;
1752 /* Save the new rate */
1753 sc->an_config.an_type = AN_RID_GENCONFIG;
1754 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1756 case AN_RID_WEP_TEMP:
1757 /* Cache the temp keys */
1759 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1760 sizeof(struct an_ltv_key));
1761 case AN_RID_WEP_PERM:
1762 case AN_RID_LEAPUSERNAME:
1763 case AN_RID_LEAPPASSWORD:
1764 /* Disable the MAC. */
1765 an_cmd(sc, AN_CMD_DISABLE, 0);
1768 an_write_record(sc, (struct an_ltv_gen *)areq);
1770 /* Turn the MAC back on. */
1771 an_cmd(sc, AN_CMD_ENABLE, 0);
1774 case AN_RID_MONITOR_MODE:
1775 cfg = (struct an_ltv_genconfig *)areq;
1777 if (ng_ether_detach_p != NULL)
1778 (*ng_ether_detach_p) (ifp);
1779 sc->an_monitor = cfg->an_len;
1781 if (sc->an_monitor & AN_MONITOR) {
1782 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1783 bpfattach(ifp, DLT_AIRONET_HEADER,
1784 sizeof(struct ether_header));
1786 bpfattach(ifp, DLT_IEEE802_11,
1787 sizeof(struct ether_header));
1790 bpfattach(ifp, DLT_EN10MB,
1791 sizeof(struct ether_header));
1792 if (ng_ether_attach_p != NULL)
1793 (*ng_ether_attach_p) (ifp);
1797 printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
1803 /* Reinitialize the card. */
1811 * Derived from Linux driver to enable promiscious mode.
1815 an_promisc(sc, promisc)
1816 struct an_softc *sc;
1819 if (sc->an_was_monitor)
1822 an_init_mpi350_desc(sc);
1823 if (sc->an_monitor || sc->an_was_monitor)
1826 sc->an_was_monitor = sc->an_monitor;
1827 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1833 an_ioctl(ifp, command, data, cr)
1842 struct an_softc *sc;
1844 struct ieee80211req *ireq;
1845 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1847 struct an_ltv_genconfig *config;
1848 struct an_ltv_key *key;
1849 struct an_ltv_status *status;
1850 struct an_ltv_ssidlist *ssids;
1852 struct aironet_ioctl l_ioctl;
1856 ifr = (struct ifreq *)data;
1857 ireq = (struct ieee80211req *)data;
1859 config = (struct an_ltv_genconfig *)&sc->areq;
1860 key = (struct an_ltv_key *)&sc->areq;
1861 status = (struct an_ltv_status *)&sc->areq;
1862 ssids = (struct an_ltv_ssidlist *)&sc->areq;
1873 error = ether_ioctl(ifp, command, data);
1876 if (ifp->if_flags & IFF_UP) {
1877 if (ifp->if_flags & IFF_RUNNING &&
1878 ifp->if_flags & IFF_PROMISC &&
1879 !(sc->an_if_flags & IFF_PROMISC)) {
1881 } else if (ifp->if_flags & IFF_RUNNING &&
1882 !(ifp->if_flags & IFF_PROMISC) &&
1883 sc->an_if_flags & IFF_PROMISC) {
1888 if (ifp->if_flags & IFF_RUNNING)
1891 sc->an_if_flags = ifp->if_flags;
1896 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1900 /* The Aironet has no multicast filter. */
1904 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1908 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1909 error = suser_cred(cr, NULL_CRED_OKAY);
1912 sc->an_sigitems = sc->an_nextitem = 0;
1914 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1915 char *pt = (char *)&sc->areq.an_val;
1916 bcopy((char *)&sc->an_sigitems, (char *)pt,
1919 sc->areq.an_len = sizeof(int) / 2;
1920 bcopy((char *)&sc->an_sigcache, (char *)pt,
1921 sizeof(struct an_sigcache) * sc->an_sigitems);
1922 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1923 sc->an_sigitems) / 2) + 1;
1926 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1930 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1933 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1935 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1938 an_setdef(sc, &sc->areq);
1940 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1941 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1943 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1944 mode = l_ioctl.command;
1946 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1947 error = readrids(ifp, &l_ioctl);
1948 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1949 error = writerids(ifp, &l_ioctl);
1950 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1951 error = flashcard(ifp, &l_ioctl);
1956 /* copy out the updated command info */
1957 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1960 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1961 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1963 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1964 l_ioctl.command = 0;
1966 copyout(&error, l_ioctl.data, sizeof(error));
1970 sc->areq.an_len = sizeof(sc->areq);
1971 /* was that a good idea DJA we are doing a short-cut */
1972 switch (ireq->i_type) {
1973 case IEEE80211_IOC_SSID:
1974 if (ireq->i_val == -1) {
1975 sc->areq.an_type = AN_RID_STATUS;
1976 if (an_read_record(sc,
1977 (struct an_ltv_gen *)&sc->areq)) {
1981 len = status->an_ssidlen;
1982 tmpptr = status->an_ssid;
1983 } else if (ireq->i_val >= 0) {
1984 sc->areq.an_type = AN_RID_SSIDLIST;
1985 if (an_read_record(sc,
1986 (struct an_ltv_gen *)&sc->areq)) {
1990 if (ireq->i_val == 0) {
1991 len = ssids->an_ssid1_len;
1992 tmpptr = ssids->an_ssid1;
1993 } else if (ireq->i_val == 1) {
1994 len = ssids->an_ssid2_len;
1995 tmpptr = ssids->an_ssid2;
1996 } else if (ireq->i_val == 2) {
1997 len = ssids->an_ssid3_len;
1998 tmpptr = ssids->an_ssid3;
2007 if (len > IEEE80211_NWID_LEN) {
2012 bzero(tmpstr, IEEE80211_NWID_LEN);
2013 bcopy(tmpptr, tmpstr, len);
2014 error = copyout(tmpstr, ireq->i_data,
2015 IEEE80211_NWID_LEN);
2017 case IEEE80211_IOC_NUMSSIDS:
2020 case IEEE80211_IOC_WEP:
2021 sc->areq.an_type = AN_RID_ACTUALCFG;
2022 if (an_read_record(sc,
2023 (struct an_ltv_gen *)&sc->areq)) {
2027 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2028 if (config->an_authtype &
2029 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2030 ireq->i_val = IEEE80211_WEP_MIXED;
2032 ireq->i_val = IEEE80211_WEP_ON;
2034 ireq->i_val = IEEE80211_WEP_OFF;
2037 case IEEE80211_IOC_WEPKEY:
2039 * XXX: I'm not entierly convinced this is
2040 * correct, but it's what is implemented in
2041 * ancontrol so it will have to do until we get
2042 * access to actual Cisco code.
2044 if (ireq->i_val < 0 || ireq->i_val > 8) {
2049 if (ireq->i_val < 5) {
2050 sc->areq.an_type = AN_RID_WEP_TEMP;
2051 for (i = 0; i < 5; i++) {
2052 if (an_read_record(sc,
2053 (struct an_ltv_gen *)&sc->areq)) {
2057 if (key->kindex == 0xffff)
2059 if (key->kindex == ireq->i_val)
2061 /* Required to get next entry */
2062 sc->areq.an_type = AN_RID_WEP_PERM;
2067 /* We aren't allowed to read the value of the
2068 * key from the card so we just output zeros
2069 * like we would if we could read the card, but
2070 * denied the user access.
2074 error = copyout(tmpstr, ireq->i_data, len);
2076 case IEEE80211_IOC_NUMWEPKEYS:
2077 ireq->i_val = 9; /* include home key */
2079 case IEEE80211_IOC_WEPTXKEY:
2081 * For some strange reason, you have to read all
2082 * keys before you can read the txkey.
2084 sc->areq.an_type = AN_RID_WEP_TEMP;
2085 for (i = 0; i < 5; i++) {
2086 if (an_read_record(sc,
2087 (struct an_ltv_gen *) &sc->areq)) {
2091 if (key->kindex == 0xffff)
2093 /* Required to get next entry */
2094 sc->areq.an_type = AN_RID_WEP_PERM;
2099 sc->areq.an_type = AN_RID_WEP_PERM;
2100 key->kindex = 0xffff;
2101 if (an_read_record(sc,
2102 (struct an_ltv_gen *)&sc->areq)) {
2106 ireq->i_val = key->mac[0];
2108 * Check for home mode. Map home mode into
2109 * 5th key since that is how it is stored on
2112 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2113 sc->areq.an_type = AN_RID_GENCONFIG;
2114 if (an_read_record(sc,
2115 (struct an_ltv_gen *)&sc->areq)) {
2119 if (config->an_home_product & AN_HOME_NETWORK)
2122 case IEEE80211_IOC_AUTHMODE:
2123 sc->areq.an_type = AN_RID_ACTUALCFG;
2124 if (an_read_record(sc,
2125 (struct an_ltv_gen *)&sc->areq)) {
2129 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2131 ireq->i_val = IEEE80211_AUTH_NONE;
2132 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2134 ireq->i_val = IEEE80211_AUTH_OPEN;
2135 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2136 AN_AUTHTYPE_SHAREDKEY) {
2137 ireq->i_val = IEEE80211_AUTH_SHARED;
2141 case IEEE80211_IOC_STATIONNAME:
2142 sc->areq.an_type = AN_RID_ACTUALCFG;
2143 if (an_read_record(sc,
2144 (struct an_ltv_gen *)&sc->areq)) {
2148 ireq->i_len = sizeof(config->an_nodename);
2149 tmpptr = config->an_nodename;
2150 bzero(tmpstr, IEEE80211_NWID_LEN);
2151 bcopy(tmpptr, tmpstr, ireq->i_len);
2152 error = copyout(tmpstr, ireq->i_data,
2153 IEEE80211_NWID_LEN);
2155 case IEEE80211_IOC_CHANNEL:
2156 sc->areq.an_type = AN_RID_STATUS;
2157 if (an_read_record(sc,
2158 (struct an_ltv_gen *)&sc->areq)) {
2162 ireq->i_val = status->an_cur_channel;
2164 case IEEE80211_IOC_POWERSAVE:
2165 sc->areq.an_type = AN_RID_ACTUALCFG;
2166 if (an_read_record(sc,
2167 (struct an_ltv_gen *)&sc->areq)) {
2171 if (config->an_psave_mode == AN_PSAVE_NONE) {
2172 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2173 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2174 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2175 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2176 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2177 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2178 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2182 case IEEE80211_IOC_POWERSAVESLEEP:
2183 sc->areq.an_type = AN_RID_ACTUALCFG;
2184 if (an_read_record(sc,
2185 (struct an_ltv_gen *)&sc->areq)) {
2189 ireq->i_val = config->an_listen_interval;
2194 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
2196 sc->areq.an_len = sizeof(sc->areq);
2198 * We need a config structure for everything but the WEP
2199 * key management and SSIDs so we get it now so avoid
2200 * duplicating this code every time.
2202 if (ireq->i_type != IEEE80211_IOC_SSID &&
2203 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2204 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2205 sc->areq.an_type = AN_RID_GENCONFIG;
2206 if (an_read_record(sc,
2207 (struct an_ltv_gen *)&sc->areq)) {
2212 switch (ireq->i_type) {
2213 case IEEE80211_IOC_SSID:
2214 sc->areq.an_type = AN_RID_SSIDLIST;
2215 if (an_read_record(sc,
2216 (struct an_ltv_gen *)&sc->areq)) {
2220 if (ireq->i_len > IEEE80211_NWID_LEN) {
2224 switch (ireq->i_val) {
2226 error = copyin(ireq->i_data,
2227 ssids->an_ssid1, ireq->i_len);
2228 ssids->an_ssid1_len = ireq->i_len;
2231 error = copyin(ireq->i_data,
2232 ssids->an_ssid2, ireq->i_len);
2233 ssids->an_ssid2_len = ireq->i_len;
2236 error = copyin(ireq->i_data,
2237 ssids->an_ssid3, ireq->i_len);
2238 ssids->an_ssid3_len = ireq->i_len;
2245 case IEEE80211_IOC_WEP:
2246 switch (ireq->i_val) {
2247 case IEEE80211_WEP_OFF:
2248 config->an_authtype &=
2249 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2250 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2252 case IEEE80211_WEP_ON:
2253 config->an_authtype |=
2254 AN_AUTHTYPE_PRIVACY_IN_USE;
2255 config->an_authtype &=
2256 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2258 case IEEE80211_WEP_MIXED:
2259 config->an_authtype |=
2260 AN_AUTHTYPE_PRIVACY_IN_USE |
2261 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2268 case IEEE80211_IOC_WEPKEY:
2269 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2274 error = copyin(ireq->i_data, tmpstr, 13);
2278 * Map the 9th key into the home mode
2279 * since that is how it is stored on
2282 bzero(&sc->areq, sizeof(struct an_ltv_key));
2283 sc->areq.an_len = sizeof(struct an_ltv_key);
2284 key->mac[0] = 1; /* The others are 0. */
2285 if (ireq->i_val < 4) {
2286 sc->areq.an_type = AN_RID_WEP_TEMP;
2287 key->kindex = ireq->i_val;
2289 sc->areq.an_type = AN_RID_WEP_PERM;
2290 key->kindex = ireq->i_val - 4;
2292 key->klen = ireq->i_len;
2293 bcopy(tmpstr, key->key, key->klen);
2295 case IEEE80211_IOC_WEPTXKEY:
2296 if (ireq->i_val < 0 || ireq->i_val > 4) {
2302 * Map the 5th key into the home mode
2303 * since that is how it is stored on
2306 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2307 sc->areq.an_type = AN_RID_ACTUALCFG;
2308 if (an_read_record(sc,
2309 (struct an_ltv_gen *)&sc->areq)) {
2313 if (ireq->i_val == 4) {
2314 config->an_home_product |= AN_HOME_NETWORK;
2317 config->an_home_product &= ~AN_HOME_NETWORK;
2320 sc->an_config.an_home_product
2321 = config->an_home_product;
2323 /* update configuration */
2326 bzero(&sc->areq, sizeof(struct an_ltv_key));
2327 sc->areq.an_len = sizeof(struct an_ltv_key);
2328 sc->areq.an_type = AN_RID_WEP_PERM;
2329 key->kindex = 0xffff;
2330 key->mac[0] = ireq->i_val;
2332 case IEEE80211_IOC_AUTHMODE:
2333 switch (ireq->i_val) {
2334 case IEEE80211_AUTH_NONE:
2335 config->an_authtype = AN_AUTHTYPE_NONE |
2336 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2338 case IEEE80211_AUTH_OPEN:
2339 config->an_authtype = AN_AUTHTYPE_OPEN |
2340 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2342 case IEEE80211_AUTH_SHARED:
2343 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2344 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2350 case IEEE80211_IOC_STATIONNAME:
2351 if (ireq->i_len > 16) {
2355 bzero(config->an_nodename, 16);
2356 error = copyin(ireq->i_data,
2357 config->an_nodename, ireq->i_len);
2359 case IEEE80211_IOC_CHANNEL:
2361 * The actual range is 1-14, but if you set it
2362 * to 0 you get the default so we let that work
2365 if (ireq->i_val < 0 || ireq->i_val >14) {
2369 config->an_ds_channel = ireq->i_val;
2371 case IEEE80211_IOC_POWERSAVE:
2372 switch (ireq->i_val) {
2373 case IEEE80211_POWERSAVE_OFF:
2374 config->an_psave_mode = AN_PSAVE_NONE;
2376 case IEEE80211_POWERSAVE_CAM:
2377 config->an_psave_mode = AN_PSAVE_CAM;
2379 case IEEE80211_POWERSAVE_PSP:
2380 config->an_psave_mode = AN_PSAVE_PSP;
2382 case IEEE80211_POWERSAVE_PSP_CAM:
2383 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2390 case IEEE80211_IOC_POWERSAVESLEEP:
2391 config->an_listen_interval = ireq->i_val;
2396 an_setdef(sc, &sc->areq);
2410 struct an_softc *sc;
2419 for (i = 0; i < AN_TX_RING_CNT; i++) {
2420 if (an_alloc_nicmem(sc, 1518 +
2423 sc->an_rdata.an_tx_fids[i] = id;
2424 sc->an_rdata.an_tx_ring[i] = 0;
2428 sc->an_rdata.an_tx_prod = 0;
2429 sc->an_rdata.an_tx_cons = 0;
2430 sc->an_rdata.an_tx_empty = 1;
2439 struct an_softc *sc = xsc;
2440 struct ifnet *ifp = &sc->arpcom.ac_if;
2450 if (ifp->if_flags & IFF_RUNNING)
2453 sc->an_associated = 0;
2455 /* Allocate the TX buffers */
2456 if (an_init_tx_ring(sc)) {
2459 an_init_mpi350_desc(sc);
2460 if (an_init_tx_ring(sc)) {
2461 printf("an%d: tx buffer allocation "
2462 "failed\n", sc->an_unit);
2468 /* Set our MAC address. */
2469 bcopy((char *)&sc->arpcom.ac_enaddr,
2470 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2472 if (ifp->if_flags & IFF_BROADCAST)
2473 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2475 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2477 if (ifp->if_flags & IFF_MULTICAST)
2478 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2480 if (ifp->if_flags & IFF_PROMISC) {
2481 if (sc->an_monitor & AN_MONITOR) {
2482 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2483 sc->an_config.an_rxmode |=
2484 AN_RXMODE_80211_MONITOR_ANYBSS |
2485 AN_RXMODE_NO_8023_HEADER;
2487 sc->an_config.an_rxmode |=
2488 AN_RXMODE_80211_MONITOR_CURBSS |
2489 AN_RXMODE_NO_8023_HEADER;
2494 if (sc->an_have_rssimap)
2495 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2497 /* Set the ssid list */
2498 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2499 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2500 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2501 printf("an%d: failed to set ssid list\n", sc->an_unit);
2506 /* Set the AP list */
2507 sc->an_aplist.an_type = AN_RID_APLIST;
2508 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2509 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2510 printf("an%d: failed to set AP list\n", sc->an_unit);
2515 /* Set the configuration in the NIC */
2516 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2517 sc->an_config.an_type = AN_RID_GENCONFIG;
2518 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2519 printf("an%d: failed to set configuration\n", sc->an_unit);
2524 /* Enable the MAC */
2525 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2526 printf("an%d: failed to enable MAC\n", sc->an_unit);
2531 if (ifp->if_flags & IFF_PROMISC)
2532 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2534 /* enable interrupts */
2535 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
2537 ifp->if_flags |= IFF_RUNNING;
2538 ifp->if_flags &= ~IFF_OACTIVE;
2540 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
2550 struct an_softc *sc;
2551 struct mbuf *m0 = NULL;
2552 struct an_txframe_802_3 tx_frame_802_3;
2553 struct ether_header *eh;
2555 unsigned char txcontrol;
2556 struct an_card_tx_desc an_tx_desc;
2565 if (ifp->if_flags & IFF_OACTIVE)
2568 if (!sc->an_associated)
2571 /* We can't send in monitor mode so toss any attempts. */
2572 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2573 ifq_purge(&ifp->if_snd);
2577 idx = sc->an_rdata.an_tx_prod;
2580 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2582 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2583 m0 = ifq_dequeue(&ifp->if_snd);
2587 id = sc->an_rdata.an_tx_fids[idx];
2588 eh = mtod(m0, struct ether_header *);
2590 bcopy((char *)&eh->ether_dhost,
2591 (char *)&tx_frame_802_3.an_tx_dst_addr,
2593 bcopy((char *)&eh->ether_shost,
2594 (char *)&tx_frame_802_3.an_tx_src_addr,
2597 /* minus src/dest mac & type */
2598 tx_frame_802_3.an_tx_802_3_payload_len =
2599 m0->m_pkthdr.len - 12;
2601 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2602 tx_frame_802_3.an_tx_802_3_payload_len,
2603 (caddr_t)&sc->an_txbuf);
2605 txcontrol = AN_TXCTL_8023;
2606 /* write the txcontrol only */
2607 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2611 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2612 sizeof(struct an_txframe_802_3));
2614 /* in mbuf header type is just before payload */
2615 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2616 tx_frame_802_3.an_tx_802_3_payload_len);
2623 sc->an_rdata.an_tx_ring[idx] = id;
2624 if (an_cmd(sc, AN_CMD_TX, id))
2625 printf("an%d: xmit failed\n", sc->an_unit);
2627 AN_INC(idx, AN_TX_RING_CNT);
2629 } else { /* MPI-350 */
2630 while (sc->an_rdata.an_tx_empty ||
2631 idx != sc->an_rdata.an_tx_cons) {
2632 m0 = ifq_dequeue(&ifp->if_snd);
2636 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2638 eh = mtod(m0, struct ether_header *);
2640 /* DJA optimize this to limit bcopy */
2641 bcopy((char *)&eh->ether_dhost,
2642 (char *)&tx_frame_802_3.an_tx_dst_addr,
2644 bcopy((char *)&eh->ether_shost,
2645 (char *)&tx_frame_802_3.an_tx_src_addr,
2648 /* minus src/dest mac & type */
2649 tx_frame_802_3.an_tx_802_3_payload_len =
2650 m0->m_pkthdr.len - 12;
2652 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2653 tx_frame_802_3.an_tx_802_3_payload_len,
2654 (caddr_t)&sc->an_txbuf);
2656 txcontrol = AN_TXCTL_8023;
2657 /* write the txcontrol only */
2658 bcopy((caddr_t)&txcontrol, &buf[0x08],
2662 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2663 sizeof(struct an_txframe_802_3));
2665 /* in mbuf header type is just before payload */
2666 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2667 tx_frame_802_3.an_tx_802_3_payload_len);
2670 bzero(&an_tx_desc, sizeof(an_tx_desc));
2671 an_tx_desc.an_offset = 0;
2672 an_tx_desc.an_eoc = 1;
2673 an_tx_desc.an_valid = 1;
2674 an_tx_desc.an_len = 0x44 +
2675 tx_frame_802_3.an_tx_802_3_payload_len;
2676 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2677 ptr = (u_int8_t*)&an_tx_desc;
2678 for (i = 0; i < sizeof(an_tx_desc); i++) {
2679 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2688 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2690 AN_INC(idx, AN_MAX_TX_DESC);
2691 sc->an_rdata.an_tx_empty = 0;
2696 ifp->if_flags |= IFF_OACTIVE;
2698 sc->an_rdata.an_tx_prod = idx;
2701 * Set a timeout in case the chip goes out to lunch.
2710 struct an_softc *sc;
2723 ifp = &sc->arpcom.ac_if;
2725 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2726 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2727 an_cmd(sc, AN_CMD_DISABLE, 0);
2729 for (i = 0; i < AN_TX_RING_CNT; i++)
2730 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2732 callout_stop(&sc->an_stat_timer);
2734 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2736 if (sc->an_flash_buffer) {
2737 free(sc->an_flash_buffer, M_DEVBUF);
2738 sc->an_flash_buffer = NULL;
2750 struct an_softc *sc;
2761 printf("an%d: device timeout\n", sc->an_unit);
2765 an_init_mpi350_desc(sc);
2778 struct an_softc *sc;
2780 sc = device_get_softc(dev);
2790 struct an_softc *sc;
2794 sc = device_get_softc(dev);
2795 ifp = &sc->arpcom.ac_if;
2799 an_init_mpi350_desc(sc);
2802 /* Recovery temporary keys */
2803 for (i = 0; i < 4; i++) {
2804 sc->areq.an_type = AN_RID_WEP_TEMP;
2805 sc->areq.an_len = sizeof(struct an_ltv_key);
2806 bcopy(&sc->an_temp_keys[i],
2807 &sc->areq, sizeof(struct an_ltv_key));
2808 an_setdef(sc, &sc->areq);
2811 if (ifp->if_flags & IFF_UP)
2818 /* Aironet signal strength cache code.
2819 * store signal/noise/quality on per MAC src basis in
2820 * a small fixed cache. The cache wraps if > MAX slots
2821 * used. The cache may be zeroed out to start over.
2822 * Two simple filters exist to reduce computation:
2823 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2824 * to ignore some packets. It defaults to ip only.
2825 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2826 * 2. multicast/broadcast only. This may be used to
2827 * ignore unicast packets and only cache signal strength
2828 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2829 * beacons and not unicast traffic.
2831 * The cache stores (MAC src(index), IP src (major clue), signal,
2834 * No apologies for storing IP src here. It's easy and saves much
2835 * trouble elsewhere. The cache is assumed to be INET dependent,
2836 * although it need not be.
2838 * Note: the Aironet only has a single byte of signal strength value
2839 * in the rx frame header, and it's not scaled to anything sensible.
2840 * This is kind of lame, but it's all we've got.
2843 #ifdef documentation
2845 int an_sigitems; /* number of cached entries */
2846 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2847 int an_nextitem; /* index/# of entries */
2852 /* control variables for cache filtering. Basic idea is
2853 * to reduce cost (e.g., to only Mobile-IP agent beacons
2854 * which are broadcast or multicast). Still you might
2855 * want to measure signal strength anth unicast ping packets
2856 * on a pt. to pt. ant. setup.
2858 /* set true if you want to limit cache items to broadcast/mcast
2859 * only packets (not unicast). Useful for mobile-ip beacons which
2860 * are broadcast/multicast at network layer. Default is all packets
2861 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2863 static int an_cache_mcastonly = 0;
2864 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2865 &an_cache_mcastonly, 0, "");
2867 /* set true if you want to limit cache items to IP packets only
2869 static int an_cache_iponly = 1;
2870 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2871 &an_cache_iponly, 0, "");
2874 * an_cache_store, per rx packet store signal
2875 * strength in MAC (src) indexed cache.
2878 an_cache_store (sc, m, rx_rssi, rx_quality)
2879 struct an_softc *sc;
2882 u_int8_t rx_quality;
2884 struct ether_header *eh = mtod(m, struct ether_header *);
2885 struct ip *ip = NULL;
2887 static int cache_slot = 0; /* use this cache entry */
2888 static int wrapindex = 0; /* next "free" cache entry */
2892 * 2. configurable filter to throw out unicast packets,
2893 * keep multicast only.
2896 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2897 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2898 else if (an_cache_iponly)
2901 /* filter for broadcast/multicast only
2903 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2908 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
2909 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2912 /* do a linear search for a matching MAC address
2913 * in the cache table
2914 * . MAC address is 6 bytes,
2915 * . var w_nextitem holds total number of entries already cached
2917 for (i = 0; i < sc->an_nextitem; i++) {
2918 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2920 * so we already have this entry,
2927 /* did we find a matching mac address?
2928 * if yes, then overwrite a previously existing cache entry
2930 if (i < sc->an_nextitem ) {
2933 /* else, have a new address entry,so
2934 * add this new entry,
2935 * if table full, then we need to replace LRU entry
2939 /* check for space in cache table
2940 * note: an_nextitem also holds number of entries
2941 * added in the cache table
2943 if ( sc->an_nextitem < MAXANCACHE ) {
2944 cache_slot = sc->an_nextitem;
2946 sc->an_sigitems = sc->an_nextitem;
2948 /* no space found, so simply wrap anth wrap index
2949 * and "zap" the next entry
2952 if (wrapindex == MAXANCACHE) {
2955 cache_slot = wrapindex++;
2959 /* invariant: cache_slot now points at some slot
2962 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
2963 log(LOG_ERR, "an_cache_store, bad index: %d of "
2964 "[0..%d], gross cache error\n",
2965 cache_slot, MAXANCACHE);
2969 /* store items in cache
2970 * .ip source address
2975 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2977 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2980 switch (an_cache_mode) {
2982 if (sc->an_have_rssimap) {
2983 sc->an_sigcache[cache_slot].signal =
2984 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
2985 sc->an_sigcache[cache_slot].quality =
2986 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
2988 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
2989 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
2993 if (sc->an_have_rssimap) {
2994 sc->an_sigcache[cache_slot].signal =
2995 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
2996 sc->an_sigcache[cache_slot].quality =
2997 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3001 if (rx_quality > 100)
3003 sc->an_sigcache[cache_slot].signal = rx_rssi;
3004 sc->an_sigcache[cache_slot].quality = rx_quality;
3008 sc->an_sigcache[cache_slot].signal = rx_rssi;
3009 sc->an_sigcache[cache_slot].quality = rx_quality;
3013 sc->an_sigcache[cache_slot].noise = 0;
3020 an_media_change(ifp)
3023 struct an_softc *sc = ifp->if_softc;
3024 struct an_ltv_genconfig *cfg;
3025 int otype = sc->an_config.an_opmode;
3026 int orate = sc->an_tx_rate;
3028 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3029 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC;
3031 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION;
3033 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
3034 case IFM_IEEE80211_DS1:
3035 sc->an_tx_rate = AN_RATE_1MBPS;
3037 case IFM_IEEE80211_DS2:
3038 sc->an_tx_rate = AN_RATE_2MBPS;
3040 case IFM_IEEE80211_DS5:
3041 sc->an_tx_rate = AN_RATE_5_5MBPS;
3043 case IFM_IEEE80211_DS11:
3044 sc->an_tx_rate = AN_RATE_11MBPS;
3051 if (orate != sc->an_tx_rate) {
3052 /* Read the current configuration */
3053 sc->an_config.an_type = AN_RID_GENCONFIG;
3054 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3055 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3056 cfg = &sc->an_config;
3058 /* clear other rates and set the only one we want */
3059 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3060 cfg->an_rates[0] = sc->an_tx_rate;
3062 /* Save the new rate */
3063 sc->an_config.an_type = AN_RID_GENCONFIG;
3064 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3067 if (otype != sc->an_config.an_opmode ||
3068 orate != sc->an_tx_rate)
3075 an_media_status(ifp, imr)
3077 struct ifmediareq *imr;
3079 struct an_ltv_status status;
3080 struct an_softc *sc = ifp->if_softc;
3082 status.an_len = sizeof(status);
3083 status.an_type = AN_RID_STATUS;
3084 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3085 /* If the status read fails, just lie. */
3086 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3087 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3090 if (sc->an_tx_rate == 0) {
3091 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3092 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3093 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3094 switch (status.an_current_tx_rate) {
3096 imr->ifm_active |= IFM_IEEE80211_DS1;
3099 imr->ifm_active |= IFM_IEEE80211_DS2;
3101 case AN_RATE_5_5MBPS:
3102 imr->ifm_active |= IFM_IEEE80211_DS5;
3104 case AN_RATE_11MBPS:
3105 imr->ifm_active |= IFM_IEEE80211_DS11;
3109 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3112 imr->ifm_status = IFM_AVALID;
3113 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3114 imr->ifm_status |= IFM_ACTIVE;
3117 /********************** Cisco utility support routines *************/
3120 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3125 readrids(ifp, l_ioctl)
3127 struct aironet_ioctl *l_ioctl;
3130 struct an_softc *sc;
3132 switch (l_ioctl->command) {
3134 rid = AN_RID_CAPABILITIES;
3137 rid = AN_RID_GENCONFIG;
3140 rid = AN_RID_SSIDLIST;
3143 rid = AN_RID_APLIST;
3146 rid = AN_RID_DRVNAME;
3149 rid = AN_RID_ENCAPPROTO;
3152 rid = AN_RID_WEP_TEMP;
3155 rid = AN_RID_WEP_PERM;
3158 rid = AN_RID_STATUS;
3161 rid = AN_RID_32BITS_DELTA;
3164 rid = AN_RID_32BITS_CUM;
3171 if (rid == 999) /* Is bad command */
3175 sc->areq.an_len = AN_MAX_DATALEN;
3176 sc->areq.an_type = rid;
3178 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3180 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3182 /* the data contains the length at first */
3183 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3184 sizeof(sc->areq.an_len))) {
3187 /* Just copy the data back */
3188 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3196 writerids(ifp, l_ioctl)
3198 struct aironet_ioctl *l_ioctl;
3200 struct an_softc *sc;
3205 command = l_ioctl->command;
3209 rid = AN_RID_SSIDLIST;
3212 rid = AN_RID_CAPABILITIES;
3215 rid = AN_RID_APLIST;
3218 rid = AN_RID_GENCONFIG;
3221 an_cmd(sc, AN_CMD_ENABLE, 0);
3225 an_cmd(sc, AN_CMD_DISABLE, 0);
3230 * This command merely clears the counts does not actually
3231 * store any data only reads rid. But as it changes the cards
3232 * state, I put it in the writerid routines.
3235 rid = AN_RID_32BITS_DELTACLR;
3237 sc->areq.an_len = AN_MAX_DATALEN;
3238 sc->areq.an_type = rid;
3240 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3241 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3243 /* the data contains the length at first */
3244 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3245 sizeof(sc->areq.an_len))) {
3248 /* Just copy the data */
3249 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3256 rid = AN_RID_WEP_TEMP;
3259 rid = AN_RID_WEP_PERM;
3262 rid = AN_RID_LEAPUSERNAME;
3265 rid = AN_RID_LEAPPASSWORD;
3272 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3274 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3275 sc->areq.an_type = rid;
3277 /* Just copy the data back */
3278 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3281 an_cmd(sc, AN_CMD_DISABLE, 0);
3282 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3283 an_cmd(sc, AN_CMD_ENABLE, 0);
3290 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3294 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3295 #define FLASH_COMMAND 0x7e7e
3296 #define FLASH_SIZE 32 * 1024
3302 struct an_softc *sc = ifp->if_softc;
3304 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3305 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3306 AN_EV_CLR_STUCK_BUSY);
3313 * Wait for busy completion from card wait for delay uSec's Return true for
3314 * success meaning command reg is clear
3322 int statword = 0xffff;
3324 struct an_softc *sc = ifp->if_softc;
3326 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3329 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3331 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3336 return 0 == (AN_CMD_BUSY & statword);
3340 * STEP 1) Disable MAC and do soft reset on card.
3348 struct an_softc *sc = ifp->if_softc;
3352 an_cmd(sc, AN_CMD_DISABLE, 0);
3354 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3355 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3356 sc->an_unit, 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 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3366 sc->an_unit, status);
3373 * STEP 2) Put the card in legendary flash mode
3381 struct an_softc *sc = ifp->if_softc;
3383 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3384 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3385 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3386 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3389 * mdelay(500); // 500ms delay
3394 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3395 printf("Waitbusy hang after setflash mode\n");
3402 * Get a character from the card matching matchbyte Step 3)
3406 flashgchar(ifp, matchbyte, dwelltime)
3412 unsigned char rbyte = 0;
3414 struct an_softc *sc = ifp->if_softc;
3418 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3420 if (dwelltime && !(0x8000 & rchar)) {
3425 rbyte = 0xff & rchar;
3427 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3428 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3432 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3434 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3436 } while (dwelltime > 0);
3441 * Put character to SWS0 wait for dwelltime x 50us for echo .
3445 flashpchar(ifp, byte, dwelltime)
3451 int pollbusy, waittime;
3452 struct an_softc *sc = ifp->if_softc;
3459 waittime = dwelltime;
3462 * Wait for busy bit d15 to go false indicating buffer empty
3465 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3467 if (pollbusy & 0x8000) {
3474 while (waittime >= 0);
3476 /* timeout for busy clear wait */
3478 if (waittime <= 0) {
3479 printf("an%d: flash putchar busywait timeout! \n",
3484 * Port is clear now write byte and wait for it to echo back
3487 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3490 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3491 } while (dwelltime >= 0 && echo != byte);
3494 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3496 return echo == byte;
3500 * Transfer 32k of firmware data from user buffer to our buffer and send to
3508 unsigned short *bufp;
3510 struct an_softc *sc = ifp->if_softc;
3514 bufp = sc->an_flash_buffer;
3517 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3518 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3520 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3521 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3524 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3525 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3526 ((u_int32_t *)bufp)[nwords] & 0xffff);
3530 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3536 * After flashing restart the card.
3544 struct an_softc *sc = ifp->if_softc;
3546 FLASH_DELAY(1024); /* Added 12/7/00 */
3550 FLASH_DELAY(1024); /* Added 12/7/00 */
3555 * Entry point for flash ioclt.
3559 flashcard(ifp, l_ioctl)
3561 struct aironet_ioctl *l_ioctl;
3564 struct an_softc *sc;
3568 printf("an%d: flashing not supported on MPI 350 yet\n",
3572 status = l_ioctl->command;
3574 switch (l_ioctl->command) {
3576 return cmdreset(ifp);
3579 if (sc->an_flash_buffer) {
3580 free(sc->an_flash_buffer, M_DEVBUF);
3581 sc->an_flash_buffer = NULL;
3583 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3584 if (sc->an_flash_buffer)
3585 return setflashmode(ifp);
3589 case AIROFLSHGCHR: /* Get char from aux */
3590 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3591 z = *(int *)&sc->areq;
3592 if ((status = flashgchar(ifp, z, 8000)) == 1)
3597 case AIROFLSHPCHR: /* Send char to card. */
3598 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3599 z = *(int *)&sc->areq;
3600 if ((status = flashpchar(ifp, z, 8000)) == -1)
3605 case AIROFLPUTBUF: /* Send 32k to card */
3606 if (l_ioctl->len > FLASH_SIZE) {
3607 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3608 l_ioctl->len, FLASH_SIZE);
3611 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3613 if ((status = flashputbuf(ifp)) != 0)
3619 if ((status = flashrestart(ifp)) != 0) {
3620 printf("an%d: FLASHRESTART returned %d\n",
3621 sc->an_unit, status);