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.26 2005/06/11 04:26:53 hsu 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 ssid;
320 bzero((char *)&ssid, sizeof(ssid));
322 error = an_alloc_port(dev, 0, AN_IOSIZ);
326 /* can't do autoprobing */
327 if (rman_get_start(sc->port_res) == -1)
331 * We need to fake up a softc structure long enough
332 * to be able to issue commands and call some of the
335 sc->an_bhandle = rman_get_bushandle(sc->port_res);
336 sc->an_btag = rman_get_bustag(sc->port_res);
338 ssid.an_len = sizeof(ssid);
339 ssid.an_type = AN_RID_SSIDLIST;
341 /* Make sure interrupts are disabled. */
342 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
343 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
345 if_initname(&sc->arpcom.ac_if, device_get_name(dev),
346 device_get_unit(dev));
348 /* No need for an_init_mpi350_desc since it will be done in attach */
350 if (an_cmd(sc, AN_CMD_READCFG, 0))
353 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
356 /* See if the ssid matches what we expect ... but doesn't have to */
357 if (strcmp(ssid.an_ssid1, AN_DEF_SSID))
364 * Allocate a port resource with the given resource id.
367 an_alloc_port(dev, rid, size)
372 struct an_softc *sc = device_get_softc(dev);
373 struct resource *res;
375 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
376 0ul, ~0ul, size, RF_ACTIVE);
387 * Allocate a memory resource with the given resource id.
389 int an_alloc_memory(device_t dev, int rid, int size)
391 struct an_softc *sc = device_get_softc(dev);
392 struct resource *res;
394 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
395 0ul, ~0ul, size, RF_ACTIVE);
407 * Allocate a auxilary memory resource with the given resource id.
409 int an_alloc_aux_memory(device_t dev, int rid, int size)
411 struct an_softc *sc = device_get_softc(dev);
412 struct resource *res;
414 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
415 0ul, ~0ul, size, RF_ACTIVE);
417 sc->mem_aux_rid = rid;
418 sc->mem_aux_res = res;
419 sc->mem_aux_used = size;
427 * Allocate an irq resource with the given resource id.
430 an_alloc_irq(dev, rid, flags)
435 struct an_softc *sc = device_get_softc(dev);
436 struct resource *res;
438 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
439 (RF_ACTIVE | flags));
450 an_dma_malloc_cb(arg, segs, nseg, error)
452 bus_dma_segment_t *segs;
456 bus_addr_t *paddr = (bus_addr_t*) arg;
457 *paddr = segs->ds_addr;
461 * Alloc DMA memory and set the pointer to it
464 an_dma_malloc(sc, size, dma, mapflags)
467 struct an_dma_alloc *dma;
472 r = bus_dmamap_create(sc->an_dtag, 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 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
513 * Release all resources
516 an_release_resources(dev)
519 struct an_softc *sc = device_get_softc(dev);
523 bus_release_resource(dev, SYS_RES_IOPORT,
524 sc->port_rid, sc->port_res);
528 bus_release_resource(dev, SYS_RES_MEMORY,
529 sc->mem_rid, sc->mem_res);
532 if (sc->mem_aux_res) {
533 bus_release_resource(dev, SYS_RES_MEMORY,
534 sc->mem_aux_rid, sc->mem_aux_res);
538 bus_release_resource(dev, SYS_RES_IRQ,
539 sc->irq_rid, sc->irq_res);
542 if (sc->an_rid_buffer.an_dma_paddr) {
543 an_dma_free(sc, &sc->an_rid_buffer);
545 for (i = 0; i < AN_MAX_RX_DESC; i++)
546 if (sc->an_rx_buffer[i].an_dma_paddr) {
547 an_dma_free(sc, &sc->an_rx_buffer[i]);
549 for (i = 0; i < AN_MAX_TX_DESC; i++)
550 if (sc->an_tx_buffer[i].an_dma_paddr) {
551 an_dma_free(sc, &sc->an_tx_buffer[i]);
554 bus_dma_tag_destroy(sc->an_dtag);
560 an_init_mpi350_desc(sc)
563 struct an_command cmd_struct;
564 struct an_reply reply;
565 struct an_card_rid_desc an_rid_desc;
566 struct an_card_rx_desc an_rx_desc;
567 struct an_card_tx_desc an_tx_desc;
570 if(!sc->an_rid_buffer.an_dma_paddr)
571 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
572 &sc->an_rid_buffer, 0);
573 for (i = 0; i < AN_MAX_RX_DESC; i++)
574 if(!sc->an_rx_buffer[i].an_dma_paddr)
575 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
576 &sc->an_rx_buffer[i], 0);
577 for (i = 0; i < AN_MAX_TX_DESC; i++)
578 if(!sc->an_tx_buffer[i].an_dma_paddr)
579 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
580 &sc->an_tx_buffer[i], 0);
583 * Allocate RX descriptor
585 bzero(&reply,sizeof(reply));
586 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
587 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
588 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
589 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
590 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
591 if_printf(&sc->arpcom.ac_if,
592 "failed to allocate RX descriptor\n");
596 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
597 bzero(&an_rx_desc, sizeof(an_rx_desc));
598 an_rx_desc.an_valid = 1;
599 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
600 an_rx_desc.an_done = 0;
601 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
603 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
604 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
605 + (desc * sizeof(an_rx_desc))
607 ((u_int32_t*)&an_rx_desc)[i]);
611 * Allocate TX descriptor
614 bzero(&reply,sizeof(reply));
615 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
616 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
617 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
618 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
619 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
620 if_printf(&sc->arpcom.ac_if,
621 "failed to allocate TX descriptor\n");
625 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
626 bzero(&an_tx_desc, sizeof(an_tx_desc));
627 an_tx_desc.an_offset = 0;
628 an_tx_desc.an_eoc = 0;
629 an_tx_desc.an_valid = 0;
630 an_tx_desc.an_len = 0;
631 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
633 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
634 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
635 + (desc * sizeof(an_tx_desc))
637 ((u_int32_t*)&an_tx_desc)[i]);
641 * Allocate RID descriptor
644 bzero(&reply,sizeof(reply));
645 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
646 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
647 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
648 cmd_struct.an_parm2 = 1;
649 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
650 if_printf(&sc->arpcom.ac_if,
651 "failed to allocate host descriptor\n");
655 bzero(&an_rid_desc, sizeof(an_rid_desc));
656 an_rid_desc.an_valid = 1;
657 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
658 an_rid_desc.an_rid = 0;
659 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
661 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
662 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
663 ((u_int32_t*)&an_rid_desc)[i]);
669 an_attach(sc, dev, flags)
674 struct ifnet *ifp = &sc->arpcom.ac_if;
677 callout_init(&sc->an_stat_timer);
678 sc->an_associated = 0;
680 sc->an_was_monitor = 0;
681 sc->an_flash_buffer = NULL;
684 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
689 error = an_init_mpi350_desc(sc);
694 /* Load factory config */
695 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
696 device_printf(dev, "failed to load config data\n");
700 /* Read the current configuration */
701 sc->an_config.an_type = AN_RID_GENCONFIG;
702 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
703 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
704 device_printf(dev, "read record failed\n");
708 /* Read the card capabilities */
709 sc->an_caps.an_type = AN_RID_CAPABILITIES;
710 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
711 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
712 device_printf(dev, "read record failed\n");
717 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
718 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
719 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
720 device_printf(dev, "read record failed\n");
725 sc->an_aplist.an_type = AN_RID_APLIST;
726 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
727 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
728 device_printf(dev, "read record failed\n");
733 /* Read the RSSI <-> dBm map */
734 sc->an_have_rssimap = 0;
735 if (sc->an_caps.an_softcaps & 8) {
736 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
737 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
738 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
739 device_printf(dev, "unable to get RSSI <-> dBM map\n");
741 device_printf(dev, "got RSSI <-> dBM map\n");
742 sc->an_have_rssimap = 1;
745 device_printf(dev, "no RSSI <-> dBM map\n");
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)) {
857 "oversized packet received "
858 "(%d, %d)\n", 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)) {
883 "oversized packet received "
884 "(%d, %d)\n", 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 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
906 m->m_pkthdr.rcvif = ifp;
907 /* Read Ethernet encapsulated packet */
910 /* Read NIC frame header */
911 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
917 /* Read in the 802_3 frame header */
918 if (an_read_data(sc, id, 0x34,
919 (caddr_t)&rx_frame_802_3,
920 sizeof(rx_frame_802_3))) {
924 if (rx_frame_802_3.an_rx_802_3_status != 0) {
928 /* Check for insane frame length */
929 len = rx_frame_802_3.an_rx_802_3_payload_len;
930 if (len > sizeof(sc->buf_802_11)) {
932 "oversized packet received (%d, %d)\n",
937 m->m_pkthdr.len = m->m_len =
938 rx_frame_802_3.an_rx_802_3_payload_len + 12;
940 eh = mtod(m, struct ether_header *);
942 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
943 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
944 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
945 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
947 /* in mbuf header type is just before payload */
948 error = an_read_data(sc, id, 0x44,
949 (caddr_t)&(eh->ether_type),
950 rx_frame_802_3.an_rx_802_3_payload_len);
960 an_cache_store(sc, m,
961 rx_frame.an_rx_signal_strength,
964 (*ifp->if_input)(ifp, m);
967 } else { /* MPI-350 */
968 for (count = 0; count < AN_MAX_RX_DESC; count++){
969 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
970 ((u_int32_t*)&an_rx_desc)[i]
971 = CSR_MEM_AUX_READ_4(sc,
973 + (count * sizeof(an_rx_desc))
976 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
977 buf = sc->an_rx_buffer[count].an_dma_vaddr;
979 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
984 m->m_pkthdr.rcvif = ifp;
985 /* Read Ethernet encapsulated packet */
988 * No ANCACHE support since we just get back
989 * an Ethernet packet no 802.11 info
993 /* Read NIC frame header */
994 bcopy(buf, (caddr_t)&rx_frame,
998 /* Check for insane frame length */
999 len = an_rx_desc.an_len + 12;
1000 if (len > MCLBYTES) {
1002 "oversized packet received "
1003 "(%d, %d)\n", len, MCLBYTES);
1008 m->m_pkthdr.len = m->m_len =
1009 an_rx_desc.an_len + 12;
1011 eh = mtod(m, struct ether_header *);
1013 bcopy(buf, (char *)eh,
1020 an_cache_store(sc, m,
1021 rx_frame.an_rx_signal_strength,
1025 (*ifp->if_input)(ifp, m);
1027 an_rx_desc.an_valid = 1;
1028 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1029 an_rx_desc.an_done = 0;
1030 an_rx_desc.an_phys =
1031 sc->an_rx_buffer[count].an_dma_paddr;
1033 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1034 CSR_MEM_AUX_WRITE_4(sc,
1036 + (count * sizeof(an_rx_desc))
1038 ((u_int32_t*)&an_rx_desc)[i]);
1041 if_printf(ifp, "Didn't get valid RX packet "
1044 an_rx_desc.an_valid,
1052 an_txeof(sc, status)
1053 struct an_softc *sc;
1059 ifp = &sc->arpcom.ac_if;
1062 ifp->if_flags &= ~IFF_OACTIVE;
1065 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1067 if (status & AN_EV_TX_EXC) {
1072 for (i = 0; i < AN_TX_RING_CNT; i++) {
1073 if (id == sc->an_rdata.an_tx_ring[i]) {
1074 sc->an_rdata.an_tx_ring[i] = 0;
1079 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1080 } else { /* MPI 350 */
1081 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1082 if (sc->an_rdata.an_tx_prod ==
1083 sc->an_rdata.an_tx_cons)
1084 sc->an_rdata.an_tx_empty = 1;
1091 * We abuse the stats updater to check the current NIC status. This
1092 * is important because we don't want to allow transmissions until
1093 * the NIC has synchronized to the current cell (either as the master
1094 * in an ad-hoc group, or as a station connected to an access point).
1097 an_stats_update(xsc)
1100 struct an_softc *sc;
1104 ifp = &sc->arpcom.ac_if;
1108 sc->an_status.an_type = AN_RID_STATUS;
1109 sc->an_status.an_len = sizeof(struct an_ltv_status);
1110 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1112 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1113 sc->an_associated = 1;
1115 sc->an_associated = 0;
1117 /* Don't do this while we're not transmitting */
1118 if ((ifp->if_flags & IFF_OACTIVE) == 0) {
1119 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1120 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1121 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1124 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1133 struct an_softc *sc;
1137 sc = (struct an_softc*)xsc;
1139 ifp = &sc->arpcom.ac_if;
1141 /* Disable interrupts. */
1142 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1144 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1145 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
1147 if (status & AN_EV_AWAKE) {
1148 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
1151 if (status & AN_EV_LINKSTAT) {
1152 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1153 == AN_LINKSTAT_ASSOCIATED)
1154 sc->an_associated = 1;
1156 sc->an_associated = 0;
1157 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1160 if (status & AN_EV_RX) {
1162 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1165 if (status & AN_EV_TX) {
1166 an_txeof(sc, status);
1167 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1170 if (status & AN_EV_TX_EXC) {
1171 an_txeof(sc, status);
1172 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1175 if (status & AN_EV_ALLOC)
1176 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1178 /* Re-enable interrupts. */
1179 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1181 if ((ifp->if_flags & IFF_UP) && !ifq_is_empty(&ifp->if_snd))
1188 an_cmd_struct(sc, cmd, reply)
1189 struct an_softc *sc;
1190 struct an_command *cmd;
1191 struct an_reply *reply;
1195 for (i = 0; i != AN_TIMEOUT; i++) {
1196 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1201 if( i == AN_TIMEOUT) {
1206 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1207 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1208 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1209 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1211 for (i = 0; i < AN_TIMEOUT; i++) {
1212 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1217 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1218 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1219 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1220 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1222 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1223 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1225 /* Ack the command */
1226 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1228 if (i == AN_TIMEOUT)
1235 an_cmd(sc, cmd, val)
1236 struct an_softc *sc;
1242 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1243 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1244 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1245 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1247 for (i = 0; i < AN_TIMEOUT; i++) {
1248 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1251 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1252 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1256 for (i = 0; i < AN_TIMEOUT; i++) {
1257 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1258 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1259 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1260 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1261 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1265 /* Ack the command */
1266 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1268 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1269 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1271 if (i == AN_TIMEOUT)
1278 * This reset sequence may look a little strange, but this is the
1279 * most reliable method I've found to really kick the NIC in the
1280 * head and force it to reboot correctly.
1284 struct an_softc *sc;
1286 an_cmd(sc, AN_CMD_ENABLE, 0);
1287 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1288 an_cmd(sc, AN_CMD_NOOP2, 0);
1290 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1291 if_printf(&sc->arpcom.ac_if, "reset failed\n");
1293 an_cmd(sc, AN_CMD_DISABLE, 0);
1299 * Read an LTV record from the NIC.
1302 an_read_record(sc, ltv)
1303 struct an_softc *sc;
1304 struct an_ltv_gen *ltv;
1306 struct an_ltv_gen *an_ltv;
1307 struct an_card_rid_desc an_rid_desc;
1308 struct an_command cmd;
1309 struct an_reply reply;
1314 if (ltv->an_len < 4 || ltv->an_type == 0)
1318 /* Tell the NIC to enter record read mode. */
1319 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1320 if_printf(&sc->arpcom.ac_if, "RID access failed\n");
1324 /* Seek to the record. */
1325 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1326 if_printf(&sc->arpcom.ac_if, "seek to record failed\n");
1331 * Read the length and record type and make sure they
1332 * match what we expect (this verifies that we have enough
1333 * room to hold all of the returned data).
1334 * Length includes type but not length.
1336 len = CSR_READ_2(sc, AN_DATA1);
1337 if (len > (ltv->an_len - 2)) {
1338 if_printf(&sc->arpcom.ac_if,
1339 "record length mismatch -- expected %d, "
1340 "got %d for Rid %x\n",
1341 ltv->an_len - 2, len, ltv->an_type);
1342 len = ltv->an_len - 2;
1344 ltv->an_len = len + 2;
1347 /* Now read the data. */
1348 len -= 2; /* skip the type */
1350 for (i = len; i > 1; i -= 2)
1351 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1353 ptr2 = (u_int8_t *)ptr;
1354 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1356 } else { /* MPI-350 */
1357 an_rid_desc.an_valid = 1;
1358 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1359 an_rid_desc.an_rid = 0;
1360 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1361 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1363 bzero(&cmd, sizeof(cmd));
1364 bzero(&reply, sizeof(reply));
1365 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1366 cmd.an_parm0 = ltv->an_type;
1368 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1369 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1370 ((u_int32_t*)&an_rid_desc)[i]);
1372 if (an_cmd_struct(sc, &cmd, &reply)
1373 || reply.an_status & AN_CMD_QUAL_MASK) {
1374 if_printf(&sc->arpcom.ac_if,
1375 "failed to read RID %x %x %x %x %x, %d\n",
1385 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1386 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1387 an_rid_desc.an_len = an_ltv->an_len;
1390 if (an_rid_desc.an_len > 2)
1391 bcopy(&an_ltv->an_type,
1393 an_rid_desc.an_len - 2);
1394 ltv->an_len = an_rid_desc.an_len + 2;
1398 an_dump_record(sc, ltv, "Read");
1404 * Same as read, except we inject data instead of reading it.
1407 an_write_record(sc, ltv)
1408 struct an_softc *sc;
1409 struct an_ltv_gen *ltv;
1411 struct an_card_rid_desc an_rid_desc;
1412 struct an_command cmd;
1413 struct an_reply reply;
1420 an_dump_record(sc, ltv, "Write");
1423 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1426 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1430 * Length includes type but not length.
1432 len = ltv->an_len - 2;
1433 CSR_WRITE_2(sc, AN_DATA1, len);
1435 len -= 2; /* skip the type */
1437 for (i = len; i > 1; i -= 2)
1438 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1440 ptr2 = (u_int8_t *)ptr;
1441 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1444 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1449 for (i = 0; i != AN_TIMEOUT; i++) {
1450 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1456 if (i == AN_TIMEOUT) {
1460 an_rid_desc.an_valid = 1;
1461 an_rid_desc.an_len = ltv->an_len - 2;
1462 an_rid_desc.an_rid = ltv->an_type;
1463 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1465 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1466 an_rid_desc.an_len);
1468 bzero(&cmd,sizeof(cmd));
1469 bzero(&reply,sizeof(reply));
1470 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1471 cmd.an_parm0 = ltv->an_type;
1473 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1474 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1475 ((u_int32_t*)&an_rid_desc)[i]);
1477 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1478 if_printf(&sc->arpcom.ac_if,
1479 "failed to write RID 1 %x %x %x %x %x, %d\n",
1489 ptr = (u_int16_t *)buf;
1491 if (reply.an_status & AN_CMD_QUAL_MASK) {
1492 if_printf(&sc->arpcom.ac_if,
1493 "failed to write RID 2 %x %x %x %x %x, %d\n",
1508 an_dump_record(sc, ltv, string)
1509 struct an_softc *sc;
1510 struct an_ltv_gen *ltv;
1519 len = ltv->an_len - 4;
1520 if_printf(&sc->arpcom.ac_if, "RID %4x, Length %4d, Mode %s\n",
1521 ltv->an_type, ltv->an_len - 4, string);
1523 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1524 if_printf(&sc->arpcom.ac_if, "\t");
1525 bzero(buf,sizeof(buf));
1527 ptr2 = (u_int8_t *)<v->an_val;
1528 for (i = len; i > 0; i--) {
1529 printf("%02x ", *ptr2);
1532 if (temp >= ' ' && temp <= '~')
1534 else if (temp >= 'A' && temp <= 'Z')
1538 if (++count == 16) {
1541 if_printf(&sc->arpcom.ac_if, "\t");
1542 bzero(buf,sizeof(buf));
1545 for (; count != 16; count++) {
1548 printf(" %s\n",buf);
1553 an_seek(sc, id, off, chan)
1554 struct an_softc *sc;
1570 if_printf(&sc->arpcom.ac_if, "invalid data path: %x\n", chan);
1574 CSR_WRITE_2(sc, selreg, id);
1575 CSR_WRITE_2(sc, offreg, off);
1577 for (i = 0; i < AN_TIMEOUT; i++) {
1578 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1582 if (i == AN_TIMEOUT)
1589 an_read_data(sc, id, off, buf, len)
1590 struct an_softc *sc;
1600 if (an_seek(sc, id, off, AN_BAP1))
1604 ptr = (u_int16_t *)buf;
1605 for (i = len; i > 1; i -= 2)
1606 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1608 ptr2 = (u_int8_t *)ptr;
1609 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1616 an_write_data(sc, id, off, buf, len)
1617 struct an_softc *sc;
1627 if (an_seek(sc, id, off, AN_BAP0))
1631 ptr = (u_int16_t *)buf;
1632 for (i = len; i > 1; i -= 2)
1633 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1635 ptr2 = (u_int8_t *)ptr;
1636 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1643 * Allocate a region of memory inside the NIC and zero
1647 an_alloc_nicmem(sc, len, id)
1648 struct an_softc *sc;
1654 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1655 if_printf(&sc->arpcom.ac_if,
1656 "failed to allocate %d bytes on NIC\n", len);
1660 for (i = 0; i < AN_TIMEOUT; i++) {
1661 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1665 if (i == AN_TIMEOUT)
1668 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1669 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1671 if (an_seek(sc, *id, 0, AN_BAP0))
1674 for (i = 0; i < len / 2; i++)
1675 CSR_WRITE_2(sc, AN_DATA0, 0);
1682 struct an_softc *sc;
1683 struct an_req *areq;
1686 struct an_ltv_genconfig *cfg;
1687 struct an_ltv_ssidlist *ssid;
1688 struct an_ltv_aplist *ap;
1689 struct an_ltv_gen *sp;
1691 ifp = &sc->arpcom.ac_if;
1693 switch (areq->an_type) {
1694 case AN_RID_GENCONFIG:
1695 cfg = (struct an_ltv_genconfig *)areq;
1697 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1699 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
1701 bcopy((char *)cfg, (char *)&sc->an_config,
1702 sizeof(struct an_ltv_genconfig));
1704 case AN_RID_SSIDLIST:
1705 ssid = (struct an_ltv_ssidlist *)areq;
1706 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1707 sizeof(struct an_ltv_ssidlist));
1710 ap = (struct an_ltv_aplist *)areq;
1711 bcopy((char *)ap, (char *)&sc->an_aplist,
1712 sizeof(struct an_ltv_aplist));
1714 case AN_RID_TX_SPEED:
1715 sp = (struct an_ltv_gen *)areq;
1716 sc->an_tx_rate = sp->an_val;
1718 /* Read the current configuration */
1719 sc->an_config.an_type = AN_RID_GENCONFIG;
1720 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1721 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1722 cfg = &sc->an_config;
1724 /* clear other rates and set the only one we want */
1725 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1726 cfg->an_rates[0] = sc->an_tx_rate;
1728 /* Save the new rate */
1729 sc->an_config.an_type = AN_RID_GENCONFIG;
1730 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1732 case AN_RID_WEP_TEMP:
1733 /* Cache the temp keys */
1735 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1736 sizeof(struct an_ltv_key));
1737 case AN_RID_WEP_PERM:
1738 case AN_RID_LEAPUSERNAME:
1739 case AN_RID_LEAPPASSWORD:
1740 /* Disable the MAC. */
1741 an_cmd(sc, AN_CMD_DISABLE, 0);
1744 an_write_record(sc, (struct an_ltv_gen *)areq);
1746 /* Turn the MAC back on. */
1747 an_cmd(sc, AN_CMD_ENABLE, 0);
1750 case AN_RID_MONITOR_MODE:
1751 cfg = (struct an_ltv_genconfig *)areq;
1753 if (ng_ether_detach_p != NULL)
1754 (*ng_ether_detach_p) (ifp);
1755 sc->an_monitor = cfg->an_len;
1757 if (sc->an_monitor & AN_MONITOR) {
1758 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1759 bpfattach(ifp, DLT_AIRONET_HEADER,
1760 sizeof(struct ether_header));
1762 bpfattach(ifp, DLT_IEEE802_11,
1763 sizeof(struct ether_header));
1766 bpfattach(ifp, DLT_EN10MB,
1767 sizeof(struct ether_header));
1768 if (ng_ether_attach_p != NULL)
1769 (*ng_ether_attach_p) (ifp);
1773 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1779 /* Reinitialize the card. */
1787 * Derived from Linux driver to enable promiscious mode.
1791 an_promisc(sc, promisc)
1792 struct an_softc *sc;
1795 if (sc->an_was_monitor)
1798 an_init_mpi350_desc(sc);
1799 if (sc->an_monitor || sc->an_was_monitor)
1802 sc->an_was_monitor = sc->an_monitor;
1803 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1809 an_ioctl(ifp, command, data, cr)
1818 struct an_softc *sc;
1820 struct ieee80211req *ireq;
1821 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1823 struct an_ltv_genconfig *config;
1824 struct an_ltv_key *key;
1825 struct an_ltv_status *status;
1826 struct an_ltv_ssidlist *ssids;
1828 struct aironet_ioctl l_ioctl;
1831 ifr = (struct ifreq *)data;
1832 ireq = (struct ieee80211req *)data;
1836 config = (struct an_ltv_genconfig *)&sc->areq;
1837 key = (struct an_ltv_key *)&sc->areq;
1838 status = (struct an_ltv_status *)&sc->areq;
1839 ssids = (struct an_ltv_ssidlist *)&sc->areq;
1843 if (ifp->if_flags & IFF_UP) {
1844 if (ifp->if_flags & IFF_RUNNING &&
1845 ifp->if_flags & IFF_PROMISC &&
1846 !(sc->an_if_flags & IFF_PROMISC)) {
1848 } else if (ifp->if_flags & IFF_RUNNING &&
1849 !(ifp->if_flags & IFF_PROMISC) &&
1850 sc->an_if_flags & IFF_PROMISC) {
1855 if (ifp->if_flags & IFF_RUNNING)
1858 sc->an_if_flags = ifp->if_flags;
1863 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1867 /* The Aironet has no multicast filter. */
1871 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1875 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1876 error = suser_cred(cr, NULL_CRED_OKAY);
1879 sc->an_sigitems = sc->an_nextitem = 0;
1881 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1882 char *pt = (char *)&sc->areq.an_val;
1883 bcopy((char *)&sc->an_sigitems, (char *)pt,
1886 sc->areq.an_len = sizeof(int) / 2;
1887 bcopy((char *)&sc->an_sigcache, (char *)pt,
1888 sizeof(struct an_sigcache) * sc->an_sigitems);
1889 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1890 sc->an_sigitems) / 2) + 1;
1893 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1897 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1900 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1902 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1905 an_setdef(sc, &sc->areq);
1907 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1908 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1910 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1911 mode = l_ioctl.command;
1913 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1914 error = readrids(ifp, &l_ioctl);
1915 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1916 error = writerids(ifp, &l_ioctl);
1917 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1918 error = flashcard(ifp, &l_ioctl);
1923 /* copy out the updated command info */
1924 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1927 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1928 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1930 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1931 l_ioctl.command = 0;
1933 copyout(&error, l_ioctl.data, sizeof(error));
1937 sc->areq.an_len = sizeof(sc->areq);
1938 /* was that a good idea DJA we are doing a short-cut */
1939 switch (ireq->i_type) {
1940 case IEEE80211_IOC_SSID:
1941 if (ireq->i_val == -1) {
1942 sc->areq.an_type = AN_RID_STATUS;
1943 if (an_read_record(sc,
1944 (struct an_ltv_gen *)&sc->areq)) {
1948 len = status->an_ssidlen;
1949 tmpptr = status->an_ssid;
1950 } else if (ireq->i_val >= 0) {
1951 sc->areq.an_type = AN_RID_SSIDLIST;
1952 if (an_read_record(sc,
1953 (struct an_ltv_gen *)&sc->areq)) {
1957 if (ireq->i_val == 0) {
1958 len = ssids->an_ssid1_len;
1959 tmpptr = ssids->an_ssid1;
1960 } else if (ireq->i_val == 1) {
1961 len = ssids->an_ssid2_len;
1962 tmpptr = ssids->an_ssid2;
1963 } else if (ireq->i_val == 2) {
1964 len = ssids->an_ssid3_len;
1965 tmpptr = ssids->an_ssid3;
1974 if (len > IEEE80211_NWID_LEN) {
1979 bzero(tmpstr, IEEE80211_NWID_LEN);
1980 bcopy(tmpptr, tmpstr, len);
1981 error = copyout(tmpstr, ireq->i_data,
1982 IEEE80211_NWID_LEN);
1984 case IEEE80211_IOC_NUMSSIDS:
1987 case IEEE80211_IOC_WEP:
1988 sc->areq.an_type = AN_RID_ACTUALCFG;
1989 if (an_read_record(sc,
1990 (struct an_ltv_gen *)&sc->areq)) {
1994 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
1995 if (config->an_authtype &
1996 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
1997 ireq->i_val = IEEE80211_WEP_MIXED;
1999 ireq->i_val = IEEE80211_WEP_ON;
2001 ireq->i_val = IEEE80211_WEP_OFF;
2004 case IEEE80211_IOC_WEPKEY:
2006 * XXX: I'm not entierly convinced this is
2007 * correct, but it's what is implemented in
2008 * ancontrol so it will have to do until we get
2009 * access to actual Cisco code.
2011 if (ireq->i_val < 0 || ireq->i_val > 8) {
2016 if (ireq->i_val < 5) {
2017 sc->areq.an_type = AN_RID_WEP_TEMP;
2018 for (i = 0; i < 5; i++) {
2019 if (an_read_record(sc,
2020 (struct an_ltv_gen *)&sc->areq)) {
2024 if (key->kindex == 0xffff)
2026 if (key->kindex == ireq->i_val)
2028 /* Required to get next entry */
2029 sc->areq.an_type = AN_RID_WEP_PERM;
2034 /* We aren't allowed to read the value of the
2035 * key from the card so we just output zeros
2036 * like we would if we could read the card, but
2037 * denied the user access.
2041 error = copyout(tmpstr, ireq->i_data, len);
2043 case IEEE80211_IOC_NUMWEPKEYS:
2044 ireq->i_val = 9; /* include home key */
2046 case IEEE80211_IOC_WEPTXKEY:
2048 * For some strange reason, you have to read all
2049 * keys before you can read the txkey.
2051 sc->areq.an_type = AN_RID_WEP_TEMP;
2052 for (i = 0; i < 5; i++) {
2053 if (an_read_record(sc,
2054 (struct an_ltv_gen *) &sc->areq)) {
2058 if (key->kindex == 0xffff)
2060 /* Required to get next entry */
2061 sc->areq.an_type = AN_RID_WEP_PERM;
2066 sc->areq.an_type = AN_RID_WEP_PERM;
2067 key->kindex = 0xffff;
2068 if (an_read_record(sc,
2069 (struct an_ltv_gen *)&sc->areq)) {
2073 ireq->i_val = key->mac[0];
2075 * Check for home mode. Map home mode into
2076 * 5th key since that is how it is stored on
2079 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2080 sc->areq.an_type = AN_RID_GENCONFIG;
2081 if (an_read_record(sc,
2082 (struct an_ltv_gen *)&sc->areq)) {
2086 if (config->an_home_product & AN_HOME_NETWORK)
2089 case IEEE80211_IOC_AUTHMODE:
2090 sc->areq.an_type = AN_RID_ACTUALCFG;
2091 if (an_read_record(sc,
2092 (struct an_ltv_gen *)&sc->areq)) {
2096 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2098 ireq->i_val = IEEE80211_AUTH_NONE;
2099 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2101 ireq->i_val = IEEE80211_AUTH_OPEN;
2102 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2103 AN_AUTHTYPE_SHAREDKEY) {
2104 ireq->i_val = IEEE80211_AUTH_SHARED;
2108 case IEEE80211_IOC_STATIONNAME:
2109 sc->areq.an_type = AN_RID_ACTUALCFG;
2110 if (an_read_record(sc,
2111 (struct an_ltv_gen *)&sc->areq)) {
2115 ireq->i_len = sizeof(config->an_nodename);
2116 tmpptr = config->an_nodename;
2117 bzero(tmpstr, IEEE80211_NWID_LEN);
2118 bcopy(tmpptr, tmpstr, ireq->i_len);
2119 error = copyout(tmpstr, ireq->i_data,
2120 IEEE80211_NWID_LEN);
2122 case IEEE80211_IOC_CHANNEL:
2123 sc->areq.an_type = AN_RID_STATUS;
2124 if (an_read_record(sc,
2125 (struct an_ltv_gen *)&sc->areq)) {
2129 ireq->i_val = status->an_cur_channel;
2131 case IEEE80211_IOC_POWERSAVE:
2132 sc->areq.an_type = AN_RID_ACTUALCFG;
2133 if (an_read_record(sc,
2134 (struct an_ltv_gen *)&sc->areq)) {
2138 if (config->an_psave_mode == AN_PSAVE_NONE) {
2139 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2140 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2141 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2142 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2143 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2144 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2145 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2149 case IEEE80211_IOC_POWERSAVESLEEP:
2150 sc->areq.an_type = AN_RID_ACTUALCFG;
2151 if (an_read_record(sc,
2152 (struct an_ltv_gen *)&sc->areq)) {
2156 ireq->i_val = config->an_listen_interval;
2161 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
2163 sc->areq.an_len = sizeof(sc->areq);
2165 * We need a config structure for everything but the WEP
2166 * key management and SSIDs so we get it now so avoid
2167 * duplicating this code every time.
2169 if (ireq->i_type != IEEE80211_IOC_SSID &&
2170 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2171 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2172 sc->areq.an_type = AN_RID_GENCONFIG;
2173 if (an_read_record(sc,
2174 (struct an_ltv_gen *)&sc->areq)) {
2179 switch (ireq->i_type) {
2180 case IEEE80211_IOC_SSID:
2181 sc->areq.an_type = AN_RID_SSIDLIST;
2182 if (an_read_record(sc,
2183 (struct an_ltv_gen *)&sc->areq)) {
2187 if (ireq->i_len > IEEE80211_NWID_LEN) {
2191 switch (ireq->i_val) {
2193 error = copyin(ireq->i_data,
2194 ssids->an_ssid1, ireq->i_len);
2195 ssids->an_ssid1_len = ireq->i_len;
2198 error = copyin(ireq->i_data,
2199 ssids->an_ssid2, ireq->i_len);
2200 ssids->an_ssid2_len = ireq->i_len;
2203 error = copyin(ireq->i_data,
2204 ssids->an_ssid3, ireq->i_len);
2205 ssids->an_ssid3_len = ireq->i_len;
2212 case IEEE80211_IOC_WEP:
2213 switch (ireq->i_val) {
2214 case IEEE80211_WEP_OFF:
2215 config->an_authtype &=
2216 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2217 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2219 case IEEE80211_WEP_ON:
2220 config->an_authtype |=
2221 AN_AUTHTYPE_PRIVACY_IN_USE;
2222 config->an_authtype &=
2223 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2225 case IEEE80211_WEP_MIXED:
2226 config->an_authtype |=
2227 AN_AUTHTYPE_PRIVACY_IN_USE |
2228 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2235 case IEEE80211_IOC_WEPKEY:
2236 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2241 error = copyin(ireq->i_data, tmpstr, 13);
2245 * Map the 9th key into the home mode
2246 * since that is how it is stored on
2249 bzero(&sc->areq, sizeof(struct an_ltv_key));
2250 sc->areq.an_len = sizeof(struct an_ltv_key);
2251 key->mac[0] = 1; /* The others are 0. */
2252 if (ireq->i_val < 4) {
2253 sc->areq.an_type = AN_RID_WEP_TEMP;
2254 key->kindex = ireq->i_val;
2256 sc->areq.an_type = AN_RID_WEP_PERM;
2257 key->kindex = ireq->i_val - 4;
2259 key->klen = ireq->i_len;
2260 bcopy(tmpstr, key->key, key->klen);
2262 case IEEE80211_IOC_WEPTXKEY:
2263 if (ireq->i_val < 0 || ireq->i_val > 4) {
2269 * Map the 5th key into the home mode
2270 * since that is how it is stored on
2273 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2274 sc->areq.an_type = AN_RID_ACTUALCFG;
2275 if (an_read_record(sc,
2276 (struct an_ltv_gen *)&sc->areq)) {
2280 if (ireq->i_val == 4) {
2281 config->an_home_product |= AN_HOME_NETWORK;
2284 config->an_home_product &= ~AN_HOME_NETWORK;
2287 sc->an_config.an_home_product
2288 = config->an_home_product;
2290 /* update configuration */
2293 bzero(&sc->areq, sizeof(struct an_ltv_key));
2294 sc->areq.an_len = sizeof(struct an_ltv_key);
2295 sc->areq.an_type = AN_RID_WEP_PERM;
2296 key->kindex = 0xffff;
2297 key->mac[0] = ireq->i_val;
2299 case IEEE80211_IOC_AUTHMODE:
2300 switch (ireq->i_val) {
2301 case IEEE80211_AUTH_NONE:
2302 config->an_authtype = AN_AUTHTYPE_NONE |
2303 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2305 case IEEE80211_AUTH_OPEN:
2306 config->an_authtype = AN_AUTHTYPE_OPEN |
2307 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2309 case IEEE80211_AUTH_SHARED:
2310 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2311 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2317 case IEEE80211_IOC_STATIONNAME:
2318 if (ireq->i_len > 16) {
2322 bzero(config->an_nodename, 16);
2323 error = copyin(ireq->i_data,
2324 config->an_nodename, ireq->i_len);
2326 case IEEE80211_IOC_CHANNEL:
2328 * The actual range is 1-14, but if you set it
2329 * to 0 you get the default so we let that work
2332 if (ireq->i_val < 0 || ireq->i_val >14) {
2336 config->an_ds_channel = ireq->i_val;
2338 case IEEE80211_IOC_POWERSAVE:
2339 switch (ireq->i_val) {
2340 case IEEE80211_POWERSAVE_OFF:
2341 config->an_psave_mode = AN_PSAVE_NONE;
2343 case IEEE80211_POWERSAVE_CAM:
2344 config->an_psave_mode = AN_PSAVE_CAM;
2346 case IEEE80211_POWERSAVE_PSP:
2347 config->an_psave_mode = AN_PSAVE_PSP;
2349 case IEEE80211_POWERSAVE_PSP_CAM:
2350 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2357 case IEEE80211_IOC_POWERSAVESLEEP:
2358 config->an_listen_interval = ireq->i_val;
2363 an_setdef(sc, &sc->areq);
2366 error = ether_ioctl(ifp, command, data);
2377 struct an_softc *sc;
2383 for (i = 0; i < AN_TX_RING_CNT; i++) {
2384 if (an_alloc_nicmem(sc, 1518 +
2387 sc->an_rdata.an_tx_fids[i] = id;
2388 sc->an_rdata.an_tx_ring[i] = 0;
2392 sc->an_rdata.an_tx_prod = 0;
2393 sc->an_rdata.an_tx_cons = 0;
2394 sc->an_rdata.an_tx_empty = 1;
2403 struct an_softc *sc = xsc;
2404 struct ifnet *ifp = &sc->arpcom.ac_if;
2407 if (ifp->if_flags & IFF_RUNNING)
2410 sc->an_associated = 0;
2412 /* Allocate the TX buffers */
2413 if (an_init_tx_ring(sc)) {
2416 an_init_mpi350_desc(sc);
2417 if (an_init_tx_ring(sc)) {
2419 if_printf(ifp, "tx buffer allocation failed\n");
2424 /* Set our MAC address. */
2425 bcopy((char *)&sc->arpcom.ac_enaddr,
2426 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2428 if (ifp->if_flags & IFF_BROADCAST)
2429 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2431 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2433 if (ifp->if_flags & IFF_MULTICAST)
2434 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2436 if (ifp->if_flags & IFF_PROMISC) {
2437 if (sc->an_monitor & AN_MONITOR) {
2438 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2439 sc->an_config.an_rxmode |=
2440 AN_RXMODE_80211_MONITOR_ANYBSS |
2441 AN_RXMODE_NO_8023_HEADER;
2443 sc->an_config.an_rxmode |=
2444 AN_RXMODE_80211_MONITOR_CURBSS |
2445 AN_RXMODE_NO_8023_HEADER;
2450 if (sc->an_have_rssimap)
2451 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2453 /* Set the ssid list */
2454 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2455 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2456 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2458 if_printf(ifp, "failed to set ssid list\n");
2462 /* Set the AP list */
2463 sc->an_aplist.an_type = AN_RID_APLIST;
2464 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2465 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2467 if_printf(ifp, "failed to set AP list\n");
2471 /* Set the configuration in the NIC */
2472 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2473 sc->an_config.an_type = AN_RID_GENCONFIG;
2474 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2476 if_printf(ifp, "failed to set configuration\n");
2480 /* Enable the MAC */
2481 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2483 if_printf(ifp, "failed to enable MAC\n");
2487 if (ifp->if_flags & IFF_PROMISC)
2488 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2490 /* enable interrupts */
2491 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
2493 ifp->if_flags |= IFF_RUNNING;
2494 ifp->if_flags &= ~IFF_OACTIVE;
2496 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
2505 struct an_softc *sc;
2506 struct mbuf *m0 = NULL;
2507 struct an_txframe_802_3 tx_frame_802_3;
2508 struct ether_header *eh;
2510 unsigned char txcontrol;
2511 struct an_card_tx_desc an_tx_desc;
2517 if (ifp->if_flags & IFF_OACTIVE)
2520 if (!sc->an_associated)
2523 /* We can't send in monitor mode so toss any attempts. */
2524 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2525 ifq_purge(&ifp->if_snd);
2529 idx = sc->an_rdata.an_tx_prod;
2532 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2534 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2535 m0 = ifq_dequeue(&ifp->if_snd);
2539 id = sc->an_rdata.an_tx_fids[idx];
2540 eh = mtod(m0, struct ether_header *);
2542 bcopy((char *)&eh->ether_dhost,
2543 (char *)&tx_frame_802_3.an_tx_dst_addr,
2545 bcopy((char *)&eh->ether_shost,
2546 (char *)&tx_frame_802_3.an_tx_src_addr,
2549 /* minus src/dest mac & type */
2550 tx_frame_802_3.an_tx_802_3_payload_len =
2551 m0->m_pkthdr.len - 12;
2553 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2554 tx_frame_802_3.an_tx_802_3_payload_len,
2555 (caddr_t)&sc->an_txbuf);
2557 txcontrol = AN_TXCTL_8023;
2558 /* write the txcontrol only */
2559 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2563 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2564 sizeof(struct an_txframe_802_3));
2566 /* in mbuf header type is just before payload */
2567 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2568 tx_frame_802_3.an_tx_802_3_payload_len);
2575 sc->an_rdata.an_tx_ring[idx] = id;
2576 if (an_cmd(sc, AN_CMD_TX, id))
2577 if_printf(ifp, "xmit failed\n");
2579 AN_INC(idx, AN_TX_RING_CNT);
2581 } else { /* MPI-350 */
2582 while (sc->an_rdata.an_tx_empty ||
2583 idx != sc->an_rdata.an_tx_cons) {
2584 m0 = ifq_dequeue(&ifp->if_snd);
2588 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2590 eh = mtod(m0, struct ether_header *);
2592 /* DJA optimize this to limit bcopy */
2593 bcopy((char *)&eh->ether_dhost,
2594 (char *)&tx_frame_802_3.an_tx_dst_addr,
2596 bcopy((char *)&eh->ether_shost,
2597 (char *)&tx_frame_802_3.an_tx_src_addr,
2600 /* minus src/dest mac & type */
2601 tx_frame_802_3.an_tx_802_3_payload_len =
2602 m0->m_pkthdr.len - 12;
2604 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2605 tx_frame_802_3.an_tx_802_3_payload_len,
2606 (caddr_t)&sc->an_txbuf);
2608 txcontrol = AN_TXCTL_8023;
2609 /* write the txcontrol only */
2610 bcopy((caddr_t)&txcontrol, &buf[0x08],
2614 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2615 sizeof(struct an_txframe_802_3));
2617 /* in mbuf header type is just before payload */
2618 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2619 tx_frame_802_3.an_tx_802_3_payload_len);
2622 bzero(&an_tx_desc, sizeof(an_tx_desc));
2623 an_tx_desc.an_offset = 0;
2624 an_tx_desc.an_eoc = 1;
2625 an_tx_desc.an_valid = 1;
2626 an_tx_desc.an_len = 0x44 +
2627 tx_frame_802_3.an_tx_802_3_payload_len;
2628 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2629 ptr = (u_int8_t*)&an_tx_desc;
2630 for (i = 0; i < sizeof(an_tx_desc); i++) {
2631 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2640 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2642 AN_INC(idx, AN_MAX_TX_DESC);
2643 sc->an_rdata.an_tx_empty = 0;
2648 ifp->if_flags |= IFF_OACTIVE;
2650 sc->an_rdata.an_tx_prod = idx;
2653 * Set a timeout in case the chip goes out to lunch.
2662 struct an_softc *sc;
2667 ifp = &sc->arpcom.ac_if;
2671 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2672 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2673 an_cmd(sc, AN_CMD_DISABLE, 0);
2675 for (i = 0; i < AN_TX_RING_CNT; i++)
2676 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2678 callout_stop(&sc->an_stat_timer);
2680 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2682 if (sc->an_flash_buffer) {
2683 free(sc->an_flash_buffer, M_DEVBUF);
2684 sc->an_flash_buffer = NULL;
2694 struct an_softc *sc;
2701 an_init_mpi350_desc(sc);
2707 if_printf(ifp, "device timeout\n");
2714 struct an_softc *sc;
2716 sc = device_get_softc(dev);
2726 struct an_softc *sc;
2730 sc = device_get_softc(dev);
2731 ifp = &sc->arpcom.ac_if;
2735 an_init_mpi350_desc(sc);
2738 /* Recovery temporary keys */
2739 for (i = 0; i < 4; i++) {
2740 sc->areq.an_type = AN_RID_WEP_TEMP;
2741 sc->areq.an_len = sizeof(struct an_ltv_key);
2742 bcopy(&sc->an_temp_keys[i],
2743 &sc->areq, sizeof(struct an_ltv_key));
2744 an_setdef(sc, &sc->areq);
2747 if (ifp->if_flags & IFF_UP)
2754 /* Aironet signal strength cache code.
2755 * store signal/noise/quality on per MAC src basis in
2756 * a small fixed cache. The cache wraps if > MAX slots
2757 * used. The cache may be zeroed out to start over.
2758 * Two simple filters exist to reduce computation:
2759 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2760 * to ignore some packets. It defaults to ip only.
2761 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2762 * 2. multicast/broadcast only. This may be used to
2763 * ignore unicast packets and only cache signal strength
2764 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2765 * beacons and not unicast traffic.
2767 * The cache stores (MAC src(index), IP src (major clue), signal,
2770 * No apologies for storing IP src here. It's easy and saves much
2771 * trouble elsewhere. The cache is assumed to be INET dependent,
2772 * although it need not be.
2774 * Note: the Aironet only has a single byte of signal strength value
2775 * in the rx frame header, and it's not scaled to anything sensible.
2776 * This is kind of lame, but it's all we've got.
2779 #ifdef documentation
2781 int an_sigitems; /* number of cached entries */
2782 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2783 int an_nextitem; /* index/# of entries */
2788 /* control variables for cache filtering. Basic idea is
2789 * to reduce cost (e.g., to only Mobile-IP agent beacons
2790 * which are broadcast or multicast). Still you might
2791 * want to measure signal strength anth unicast ping packets
2792 * on a pt. to pt. ant. setup.
2794 /* set true if you want to limit cache items to broadcast/mcast
2795 * only packets (not unicast). Useful for mobile-ip beacons which
2796 * are broadcast/multicast at network layer. Default is all packets
2797 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2799 static int an_cache_mcastonly = 0;
2800 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2801 &an_cache_mcastonly, 0, "");
2803 /* set true if you want to limit cache items to IP packets only
2805 static int an_cache_iponly = 1;
2806 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2807 &an_cache_iponly, 0, "");
2810 * an_cache_store, per rx packet store signal
2811 * strength in MAC (src) indexed cache.
2814 an_cache_store (sc, m, rx_rssi, rx_quality)
2815 struct an_softc *sc;
2818 u_int8_t rx_quality;
2820 struct ether_header *eh = mtod(m, struct ether_header *);
2821 struct ip *ip = NULL;
2823 static int cache_slot = 0; /* use this cache entry */
2824 static int wrapindex = 0; /* next "free" cache entry */
2828 * 2. configurable filter to throw out unicast packets,
2829 * keep multicast only.
2832 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2833 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2834 else if (an_cache_iponly)
2837 /* filter for broadcast/multicast only
2839 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2844 if_printf(&sc->arpcom.ac_if, "q value %x (MSB=0x%x, LSB=0x%x)\n",
2845 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2848 /* do a linear search for a matching MAC address
2849 * in the cache table
2850 * . MAC address is 6 bytes,
2851 * . var w_nextitem holds total number of entries already cached
2853 for (i = 0; i < sc->an_nextitem; i++) {
2854 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2856 * so we already have this entry,
2863 /* did we find a matching mac address?
2864 * if yes, then overwrite a previously existing cache entry
2866 if (i < sc->an_nextitem ) {
2869 /* else, have a new address entry,so
2870 * add this new entry,
2871 * if table full, then we need to replace LRU entry
2875 /* check for space in cache table
2876 * note: an_nextitem also holds number of entries
2877 * added in the cache table
2879 if ( sc->an_nextitem < MAXANCACHE ) {
2880 cache_slot = sc->an_nextitem;
2882 sc->an_sigitems = sc->an_nextitem;
2884 /* no space found, so simply wrap anth wrap index
2885 * and "zap" the next entry
2888 if (wrapindex == MAXANCACHE) {
2891 cache_slot = wrapindex++;
2895 /* invariant: cache_slot now points at some slot
2898 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
2899 log(LOG_ERR, "an_cache_store, bad index: %d of "
2900 "[0..%d], gross cache error\n",
2901 cache_slot, MAXANCACHE);
2905 /* store items in cache
2906 * .ip source address
2911 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2913 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2916 switch (an_cache_mode) {
2918 if (sc->an_have_rssimap) {
2919 sc->an_sigcache[cache_slot].signal =
2920 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
2921 sc->an_sigcache[cache_slot].quality =
2922 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
2924 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
2925 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
2929 if (sc->an_have_rssimap) {
2930 sc->an_sigcache[cache_slot].signal =
2931 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
2932 sc->an_sigcache[cache_slot].quality =
2933 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
2937 if (rx_quality > 100)
2939 sc->an_sigcache[cache_slot].signal = rx_rssi;
2940 sc->an_sigcache[cache_slot].quality = rx_quality;
2944 sc->an_sigcache[cache_slot].signal = rx_rssi;
2945 sc->an_sigcache[cache_slot].quality = rx_quality;
2949 sc->an_sigcache[cache_slot].noise = 0;
2956 an_media_change(ifp)
2959 struct an_softc *sc = ifp->if_softc;
2960 struct an_ltv_genconfig *cfg;
2961 int otype = sc->an_config.an_opmode;
2962 int orate = sc->an_tx_rate;
2964 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
2965 sc->an_config.an_opmode = AN_OPMODE_IBSS_ADHOC;
2967 sc->an_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION;
2969 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
2970 case IFM_IEEE80211_DS1:
2971 sc->an_tx_rate = AN_RATE_1MBPS;
2973 case IFM_IEEE80211_DS2:
2974 sc->an_tx_rate = AN_RATE_2MBPS;
2976 case IFM_IEEE80211_DS5:
2977 sc->an_tx_rate = AN_RATE_5_5MBPS;
2979 case IFM_IEEE80211_DS11:
2980 sc->an_tx_rate = AN_RATE_11MBPS;
2987 if (orate != sc->an_tx_rate) {
2988 /* Read the current configuration */
2989 sc->an_config.an_type = AN_RID_GENCONFIG;
2990 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2991 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
2992 cfg = &sc->an_config;
2994 /* clear other rates and set the only one we want */
2995 bzero(cfg->an_rates, sizeof(cfg->an_rates));
2996 cfg->an_rates[0] = sc->an_tx_rate;
2998 /* Save the new rate */
2999 sc->an_config.an_type = AN_RID_GENCONFIG;
3000 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3003 if (otype != sc->an_config.an_opmode ||
3004 orate != sc->an_tx_rate)
3011 an_media_status(ifp, imr)
3013 struct ifmediareq *imr;
3015 struct an_ltv_status status;
3016 struct an_softc *sc = ifp->if_softc;
3018 status.an_len = sizeof(status);
3019 status.an_type = AN_RID_STATUS;
3020 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3021 /* If the status read fails, just lie. */
3022 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3023 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3026 if (sc->an_tx_rate == 0) {
3027 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3028 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3029 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3030 switch (status.an_current_tx_rate) {
3032 imr->ifm_active |= IFM_IEEE80211_DS1;
3035 imr->ifm_active |= IFM_IEEE80211_DS2;
3037 case AN_RATE_5_5MBPS:
3038 imr->ifm_active |= IFM_IEEE80211_DS5;
3040 case AN_RATE_11MBPS:
3041 imr->ifm_active |= IFM_IEEE80211_DS11;
3045 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3048 imr->ifm_status = IFM_AVALID;
3049 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3050 imr->ifm_status |= IFM_ACTIVE;
3053 /********************** Cisco utility support routines *************/
3056 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3061 readrids(ifp, l_ioctl)
3063 struct aironet_ioctl *l_ioctl;
3066 struct an_softc *sc;
3068 switch (l_ioctl->command) {
3070 rid = AN_RID_CAPABILITIES;
3073 rid = AN_RID_GENCONFIG;
3076 rid = AN_RID_SSIDLIST;
3079 rid = AN_RID_APLIST;
3082 rid = AN_RID_DRVNAME;
3085 rid = AN_RID_ENCAPPROTO;
3088 rid = AN_RID_WEP_TEMP;
3091 rid = AN_RID_WEP_PERM;
3094 rid = AN_RID_STATUS;
3097 rid = AN_RID_32BITS_DELTA;
3100 rid = AN_RID_32BITS_CUM;
3107 if (rid == 999) /* Is bad command */
3111 sc->areq.an_len = AN_MAX_DATALEN;
3112 sc->areq.an_type = rid;
3114 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3116 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3118 /* the data contains the length at first */
3119 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3120 sizeof(sc->areq.an_len))) {
3123 /* Just copy the data back */
3124 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3132 writerids(ifp, l_ioctl)
3134 struct aironet_ioctl *l_ioctl;
3136 struct an_softc *sc;
3141 command = l_ioctl->command;
3145 rid = AN_RID_SSIDLIST;
3148 rid = AN_RID_CAPABILITIES;
3151 rid = AN_RID_APLIST;
3154 rid = AN_RID_GENCONFIG;
3157 an_cmd(sc, AN_CMD_ENABLE, 0);
3161 an_cmd(sc, AN_CMD_DISABLE, 0);
3166 * This command merely clears the counts does not actually
3167 * store any data only reads rid. But as it changes the cards
3168 * state, I put it in the writerid routines.
3171 rid = AN_RID_32BITS_DELTACLR;
3173 sc->areq.an_len = AN_MAX_DATALEN;
3174 sc->areq.an_type = rid;
3176 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3177 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3179 /* the data contains the length at first */
3180 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3181 sizeof(sc->areq.an_len))) {
3184 /* Just copy the data */
3185 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3192 rid = AN_RID_WEP_TEMP;
3195 rid = AN_RID_WEP_PERM;
3198 rid = AN_RID_LEAPUSERNAME;
3201 rid = AN_RID_LEAPPASSWORD;
3208 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3210 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3211 sc->areq.an_type = rid;
3213 /* Just copy the data back */
3214 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3217 an_cmd(sc, AN_CMD_DISABLE, 0);
3218 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3219 an_cmd(sc, AN_CMD_ENABLE, 0);
3226 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3230 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3231 #define FLASH_COMMAND 0x7e7e
3232 #define FLASH_SIZE 32 * 1024
3238 struct an_softc *sc = ifp->if_softc;
3240 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3241 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3242 AN_EV_CLR_STUCK_BUSY);
3249 * Wait for busy completion from card wait for delay uSec's Return true for
3250 * success meaning command reg is clear
3258 int statword = 0xffff;
3260 struct an_softc *sc = ifp->if_softc;
3262 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3265 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3267 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3272 return 0 == (AN_CMD_BUSY & statword);
3276 * STEP 1) Disable MAC and do soft reset on card.
3284 struct an_softc *sc = ifp->if_softc;
3288 an_cmd(sc, AN_CMD_DISABLE, 0);
3290 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3291 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3294 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3296 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3299 if (!(status = WaitBusy(ifp, 100))) {
3300 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3307 * STEP 2) Put the card in legendary flash mode
3315 struct an_softc *sc = ifp->if_softc;
3317 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3318 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3319 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3320 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3323 * mdelay(500); // 500ms delay
3328 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3329 printf("Waitbusy hang after setflash mode\n");
3336 * Get a character from the card matching matchbyte Step 3)
3340 flashgchar(ifp, matchbyte, dwelltime)
3346 unsigned char rbyte = 0;
3348 struct an_softc *sc = ifp->if_softc;
3352 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3354 if (dwelltime && !(0x8000 & rchar)) {
3359 rbyte = 0xff & rchar;
3361 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3362 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3366 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3368 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3370 } while (dwelltime > 0);
3375 * Put character to SWS0 wait for dwelltime x 50us for echo .
3379 flashpchar(ifp, byte, dwelltime)
3385 int pollbusy, waittime;
3386 struct an_softc *sc = ifp->if_softc;
3393 waittime = dwelltime;
3396 * Wait for busy bit d15 to go false indicating buffer empty
3399 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3401 if (pollbusy & 0x8000) {
3408 while (waittime >= 0);
3410 /* timeout for busy clear wait */
3412 if (waittime <= 0) {
3413 if_printf(ifp, "flash putchar busywait timeout!\n");
3417 * Port is clear now write byte and wait for it to echo back
3420 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3423 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3424 } while (dwelltime >= 0 && echo != byte);
3427 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3429 return echo == byte;
3433 * Transfer 32k of firmware data from user buffer to our buffer and send to
3441 unsigned short *bufp;
3443 struct an_softc *sc = ifp->if_softc;
3447 bufp = sc->an_flash_buffer;
3450 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3451 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3453 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3454 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3457 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3458 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3459 ((u_int32_t *)bufp)[nwords] & 0xffff);
3463 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3469 * After flashing restart the card.
3477 struct an_softc *sc = ifp->if_softc;
3479 FLASH_DELAY(1024); /* Added 12/7/00 */
3483 FLASH_DELAY(1024); /* Added 12/7/00 */
3488 * Entry point for flash ioclt.
3492 flashcard(ifp, l_ioctl)
3494 struct aironet_ioctl *l_ioctl;
3497 struct an_softc *sc;
3501 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3504 status = l_ioctl->command;
3506 switch (l_ioctl->command) {
3508 return cmdreset(ifp);
3511 if (sc->an_flash_buffer) {
3512 free(sc->an_flash_buffer, M_DEVBUF);
3513 sc->an_flash_buffer = NULL;
3515 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3516 if (sc->an_flash_buffer)
3517 return setflashmode(ifp);
3521 case AIROFLSHGCHR: /* Get char from aux */
3522 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3523 z = *(int *)&sc->areq;
3524 if ((status = flashgchar(ifp, z, 8000)) == 1)
3529 case AIROFLSHPCHR: /* Send char to card. */
3530 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3531 z = *(int *)&sc->areq;
3532 if ((status = flashpchar(ifp, z, 8000)) == -1)
3537 case AIROFLPUTBUF: /* Send 32k to card */
3538 if (l_ioctl->len > FLASH_SIZE) {
3539 if_printf(ifp, "Buffer to big, %x %x\n",
3540 l_ioctl->len, FLASH_SIZE);
3543 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3545 if ((status = flashputbuf(ifp)) != 0)
3551 if ((status = flashrestart(ifp)) != 0) {
3552 if_printf(ifp, "FLASHRESTART returned %d\n", status);