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.36 2005/12/31 14:07:58 sephe 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.
313 an_probe(device_t dev)
315 struct an_softc *sc = device_get_softc(dev);
316 struct an_ltv_ssidlist_new ssid;
319 bzero((char *)&ssid, sizeof(ssid));
321 error = an_alloc_port(dev, 0, AN_IOSIZ);
325 /* can't do autoprobing */
326 if (rman_get_start(sc->port_res) == -1)
330 * We need to fake up a softc structure long enough
331 * to be able to issue commands and call some of the
334 sc->an_bhandle = rman_get_bushandle(sc->port_res);
335 sc->an_btag = rman_get_bustag(sc->port_res);
337 ssid.an_len = sizeof(ssid);
338 ssid.an_type = AN_RID_SSIDLIST;
340 /* 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));
349 if (an_cmd(sc, AN_CMD_READCFG, 0))
352 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
355 /* See if the ssid matches what we expect ... but doesn't have to */
356 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID))
363 * Allocate a port resource with the given resource id.
366 an_alloc_port(device_t dev, int rid, int size)
368 struct an_softc *sc = device_get_softc(dev);
369 struct resource *res;
371 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
372 0ul, ~0ul, size, RF_ACTIVE);
383 * Allocate a memory resource with the given resource id.
386 an_alloc_memory(device_t dev, int rid, int size)
388 struct an_softc *sc = device_get_softc(dev);
389 struct resource *res;
391 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
392 0ul, ~0ul, size, RF_ACTIVE);
404 * Allocate a auxilary memory resource with the given resource id.
406 int an_alloc_aux_memory(device_t dev, int rid, int size)
408 struct an_softc *sc = device_get_softc(dev);
409 struct resource *res;
411 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
412 0ul, ~0ul, size, RF_ACTIVE);
414 sc->mem_aux_rid = rid;
415 sc->mem_aux_res = res;
416 sc->mem_aux_used = size;
424 * Allocate an irq resource with the given resource id.
427 an_alloc_irq(device_t dev, int rid, int flags)
429 struct an_softc *sc = device_get_softc(dev);
430 struct resource *res;
432 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
433 (RF_ACTIVE | flags));
444 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
446 bus_addr_t *paddr = (bus_addr_t*) arg;
447 *paddr = segs->ds_addr;
451 * Alloc DMA memory and set the pointer to it
454 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
459 r = bus_dmamap_create(sc->an_dtag, 0, &dma->an_dma_map);
463 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
464 BUS_DMA_WAITOK, &dma->an_dma_map);
468 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
476 dma->an_dma_size = size;
480 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
482 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
484 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
485 dma->an_dma_map = NULL;
490 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
492 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
493 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
494 dma->an_dma_vaddr = NULL;
495 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
499 * Release all resources
502 an_release_resources(device_t dev)
504 struct an_softc *sc = device_get_softc(dev);
508 bus_release_resource(dev, SYS_RES_IOPORT,
509 sc->port_rid, sc->port_res);
513 bus_release_resource(dev, SYS_RES_MEMORY,
514 sc->mem_rid, sc->mem_res);
517 if (sc->mem_aux_res) {
518 bus_release_resource(dev, SYS_RES_MEMORY,
519 sc->mem_aux_rid, sc->mem_aux_res);
523 bus_release_resource(dev, SYS_RES_IRQ,
524 sc->irq_rid, sc->irq_res);
527 if (sc->an_rid_buffer.an_dma_paddr) {
528 an_dma_free(sc, &sc->an_rid_buffer);
530 for (i = 0; i < AN_MAX_RX_DESC; i++)
531 if (sc->an_rx_buffer[i].an_dma_paddr) {
532 an_dma_free(sc, &sc->an_rx_buffer[i]);
534 for (i = 0; i < AN_MAX_TX_DESC; i++)
535 if (sc->an_tx_buffer[i].an_dma_paddr) {
536 an_dma_free(sc, &sc->an_tx_buffer[i]);
539 bus_dma_tag_destroy(sc->an_dtag);
545 an_init_mpi350_desc(struct an_softc *sc)
547 struct an_command cmd_struct;
548 struct an_reply reply;
549 struct an_card_rid_desc an_rid_desc;
550 struct an_card_rx_desc an_rx_desc;
551 struct an_card_tx_desc an_tx_desc;
554 if(!sc->an_rid_buffer.an_dma_paddr)
555 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
556 &sc->an_rid_buffer, 0);
557 for (i = 0; i < AN_MAX_RX_DESC; i++)
558 if(!sc->an_rx_buffer[i].an_dma_paddr)
559 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
560 &sc->an_rx_buffer[i], 0);
561 for (i = 0; i < AN_MAX_TX_DESC; i++)
562 if(!sc->an_tx_buffer[i].an_dma_paddr)
563 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
564 &sc->an_tx_buffer[i], 0);
567 * Allocate RX descriptor
569 bzero(&reply,sizeof(reply));
570 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
571 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
572 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
573 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
574 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
575 if_printf(&sc->arpcom.ac_if,
576 "failed to allocate RX descriptor\n");
580 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
581 bzero(&an_rx_desc, sizeof(an_rx_desc));
582 an_rx_desc.an_valid = 1;
583 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
584 an_rx_desc.an_done = 0;
585 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
587 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
588 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
589 + (desc * sizeof(an_rx_desc))
591 ((u_int32_t*)&an_rx_desc)[i]);
595 * Allocate TX descriptor
598 bzero(&reply,sizeof(reply));
599 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
600 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
601 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
602 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
603 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
604 if_printf(&sc->arpcom.ac_if,
605 "failed to allocate TX descriptor\n");
609 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
610 bzero(&an_tx_desc, sizeof(an_tx_desc));
611 an_tx_desc.an_offset = 0;
612 an_tx_desc.an_eoc = 0;
613 an_tx_desc.an_valid = 0;
614 an_tx_desc.an_len = 0;
615 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
617 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
618 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
619 + (desc * sizeof(an_tx_desc))
621 ((u_int32_t*)&an_tx_desc)[i]);
625 * Allocate RID descriptor
628 bzero(&reply,sizeof(reply));
629 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
630 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
631 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
632 cmd_struct.an_parm2 = 1;
633 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
634 if_printf(&sc->arpcom.ac_if,
635 "failed to allocate host descriptor\n");
639 bzero(&an_rid_desc, sizeof(an_rid_desc));
640 an_rid_desc.an_valid = 1;
641 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
642 an_rid_desc.an_rid = 0;
643 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
645 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
646 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
647 ((u_int32_t*)&an_rid_desc)[i]);
653 an_attach(struct an_softc *sc, device_t dev, int flags)
655 struct ifnet *ifp = &sc->arpcom.ac_if;
658 callout_init(&sc->an_stat_timer);
659 sc->an_associated = 0;
661 sc->an_was_monitor = 0;
662 sc->an_flash_buffer = NULL;
665 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
670 error = an_init_mpi350_desc(sc);
675 /* Load factory config */
676 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
677 device_printf(dev, "failed to load config data\n");
681 /* Read the current configuration */
682 sc->an_config.an_type = AN_RID_GENCONFIG;
683 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
684 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
685 device_printf(dev, "read record failed\n");
689 /* Read the card capabilities */
690 sc->an_caps.an_type = AN_RID_CAPABILITIES;
691 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
692 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
693 device_printf(dev, "read record failed\n");
698 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
699 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
700 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
701 device_printf(dev, "read record failed\n");
706 sc->an_aplist.an_type = AN_RID_APLIST;
707 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
708 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
709 device_printf(dev, "read record failed\n");
714 /* Read the RSSI <-> dBm map */
715 sc->an_have_rssimap = 0;
716 if (sc->an_caps.an_softcaps & 8) {
717 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
718 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
719 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
720 device_printf(dev, "unable to get RSSI <-> dBM map\n");
722 device_printf(dev, "got RSSI <-> dBM map\n");
723 sc->an_have_rssimap = 1;
726 device_printf(dev, "no RSSI <-> dBM map\n");
730 ifp->if_mtu = ETHERMTU;
731 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
732 ifp->if_ioctl = an_ioctl;
733 ifp->if_start = an_start;
734 ifp->if_watchdog = an_watchdog;
735 ifp->if_init = an_init;
736 ifp->if_baudrate = 10000000;
737 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
738 ifq_set_ready(&ifp->if_snd);
740 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
741 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
742 sizeof(AN_DEFAULT_NODENAME) - 1);
744 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
745 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
746 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
747 sizeof(AN_DEFAULT_NETNAME) - 1);
748 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
750 sc->an_config.an_opmode =
751 AN_OPMODE_INFRASTRUCTURE_STATION;
754 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
756 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
757 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
758 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
759 IFM_IEEE80211_ADHOC, 0), 0);
760 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
761 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
762 IFM_IEEE80211_ADHOC, 0), 0);
763 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
764 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
765 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
766 IFM_IEEE80211_ADHOC, 0), 0);
767 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
769 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
770 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
771 IFM_IEEE80211_ADHOC, 0), 0);
772 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
774 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
775 IFM_IEEE80211_ADHOC, 0), 0);
776 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
778 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
782 * Call MI attach routine.
784 ether_ifattach(ifp, sc->an_caps.an_oemaddr, NULL);
790 an_detach(device_t dev)
792 struct an_softc *sc = device_get_softc(dev);
793 struct ifnet *ifp = &sc->arpcom.ac_if;
795 lwkt_serialize_enter(ifp->if_serializer);
797 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
798 lwkt_serialize_exit(ifp->if_serializer);
800 ifmedia_removeall(&sc->an_ifmedia);
802 an_release_resources(dev);
807 an_rxeof(struct an_softc *sc)
810 struct ether_header *eh;
811 struct ieee80211_frame *ih;
812 struct an_rxframe rx_frame;
813 struct an_rxframe_802_3 rx_frame_802_3;
815 int len, id, error = 0, i, count = 0;
816 int ieee80211_header_len;
819 struct an_card_rx_desc an_rx_desc;
822 ifp = &sc->arpcom.ac_if;
825 id = CSR_READ_2(sc, AN_RX_FID);
827 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
828 /* read raw 802.11 packet */
829 bpf_buf = sc->buf_802_11;
832 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
839 * skip beacon by default since this increases the
843 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
844 (rx_frame.an_frame_ctl &
845 IEEE80211_FC0_SUBTYPE_BEACON)) {
849 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
850 len = rx_frame.an_rx_payload_len
852 /* Check for insane frame length */
853 if (len > sizeof(sc->buf_802_11)) {
855 "oversized packet received "
856 "(%d, %d)\n", len, MCLBYTES);
861 bcopy((char *)&rx_frame,
862 bpf_buf, sizeof(rx_frame));
864 error = an_read_data(sc, id, sizeof(rx_frame),
865 (caddr_t)bpf_buf+sizeof(rx_frame),
866 rx_frame.an_rx_payload_len);
868 fc1=rx_frame.an_frame_ctl >> 8;
869 ieee80211_header_len =
870 sizeof(struct ieee80211_frame);
871 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
872 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
873 ieee80211_header_len += ETHER_ADDR_LEN;
876 len = rx_frame.an_rx_payload_len
877 + ieee80211_header_len;
878 /* Check for insane frame length */
879 if (len > sizeof(sc->buf_802_11)) {
881 "oversized packet received "
882 "(%d, %d)\n", len, MCLBYTES);
887 ih = (struct ieee80211_frame *)bpf_buf;
889 bcopy((char *)&rx_frame.an_frame_ctl,
890 (char *)ih, ieee80211_header_len);
892 error = an_read_data(sc, id, sizeof(rx_frame) +
894 (caddr_t)ih +ieee80211_header_len,
895 rx_frame.an_rx_payload_len);
897 BPF_TAP(ifp, bpf_buf, len);
899 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
904 m->m_pkthdr.rcvif = ifp;
905 /* Read Ethernet encapsulated packet */
908 /* Read NIC frame header */
909 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
915 /* Read in the 802_3 frame header */
916 if (an_read_data(sc, id, 0x34,
917 (caddr_t)&rx_frame_802_3,
918 sizeof(rx_frame_802_3))) {
922 if (rx_frame_802_3.an_rx_802_3_status != 0) {
926 /* Check for insane frame length */
927 len = rx_frame_802_3.an_rx_802_3_payload_len;
928 if (len > sizeof(sc->buf_802_11)) {
930 "oversized packet received (%d, %d)\n",
935 m->m_pkthdr.len = m->m_len =
936 rx_frame_802_3.an_rx_802_3_payload_len + 12;
938 eh = mtod(m, struct ether_header *);
940 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
941 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
942 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
943 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
945 /* in mbuf header type is just before payload */
946 error = an_read_data(sc, id, 0x44,
947 (caddr_t)&(eh->ether_type),
948 rx_frame_802_3.an_rx_802_3_payload_len);
958 an_cache_store(sc, m,
959 rx_frame.an_rx_signal_strength,
962 ifp->if_input(ifp, m);
965 } else { /* MPI-350 */
966 for (count = 0; count < AN_MAX_RX_DESC; count++){
967 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
968 ((u_int32_t*)&an_rx_desc)[i]
969 = CSR_MEM_AUX_READ_4(sc,
971 + (count * sizeof(an_rx_desc))
974 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
975 buf = sc->an_rx_buffer[count].an_dma_vaddr;
977 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
982 m->m_pkthdr.rcvif = ifp;
983 /* Read Ethernet encapsulated packet */
986 * No ANCACHE support since we just get back
987 * an Ethernet packet no 802.11 info
991 /* Read NIC frame header */
992 bcopy(buf, (caddr_t)&rx_frame,
996 /* Check for insane frame length */
997 len = an_rx_desc.an_len + 12;
998 if (len > MCLBYTES) {
1000 "oversized packet received "
1001 "(%d, %d)\n", len, MCLBYTES);
1006 m->m_pkthdr.len = m->m_len =
1007 an_rx_desc.an_len + 12;
1009 eh = mtod(m, struct ether_header *);
1011 bcopy(buf, (char *)eh,
1018 an_cache_store(sc, m,
1019 rx_frame.an_rx_signal_strength,
1023 ifp->if_input(ifp, m);
1025 an_rx_desc.an_valid = 1;
1026 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1027 an_rx_desc.an_done = 0;
1028 an_rx_desc.an_phys =
1029 sc->an_rx_buffer[count].an_dma_paddr;
1031 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1032 CSR_MEM_AUX_WRITE_4(sc,
1034 + (count * sizeof(an_rx_desc))
1036 ((u_int32_t*)&an_rx_desc)[i]);
1039 if_printf(ifp, "Didn't get valid RX packet "
1042 an_rx_desc.an_valid,
1050 an_txeof(struct an_softc *sc, int status)
1055 ifp = &sc->arpcom.ac_if;
1058 ifp->if_flags &= ~IFF_OACTIVE;
1061 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1063 if (status & AN_EV_TX_EXC) {
1068 for (i = 0; i < AN_TX_RING_CNT; i++) {
1069 if (id == sc->an_rdata.an_tx_ring[i]) {
1070 sc->an_rdata.an_tx_ring[i] = 0;
1075 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1076 } else { /* MPI 350 */
1077 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1078 if (!sc->an_rdata.an_tx_empty){
1079 if (status & AN_EV_TX_EXC) {
1083 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1084 if (sc->an_rdata.an_tx_prod ==
1085 sc->an_rdata.an_tx_cons)
1086 sc->an_rdata.an_tx_empty = 1;
1092 * We abuse the stats updater to check the current NIC status. This
1093 * is important because we don't want to allow transmissions until
1094 * the NIC has synchronized to the current cell (either as the master
1095 * in an ad-hoc group, or as a station connected to an access point).
1098 an_stats_update(void *xsc)
1100 struct an_softc *sc;
1104 ifp = &sc->arpcom.ac_if;
1106 lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer);
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);
1126 lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer);
1132 struct an_softc *sc;
1136 sc = (struct an_softc*)xsc;
1138 ifp = &sc->arpcom.ac_if;
1140 /* Disable interrupts. */
1141 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1143 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1144 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1146 if (status & AN_EV_MIC)
1147 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1149 if (status & AN_EV_LINKSTAT) {
1150 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1151 == AN_LINKSTAT_ASSOCIATED)
1152 sc->an_associated = 1;
1154 sc->an_associated = 0;
1155 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1158 if (status & AN_EV_RX) {
1160 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1163 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1164 an_txeof(sc, status);
1165 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1168 if (status & AN_EV_TX) {
1169 an_txeof(sc, status);
1170 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1173 if (status & AN_EV_TX_EXC) {
1174 an_txeof(sc, status);
1175 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1178 if (status & AN_EV_ALLOC)
1179 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1181 /* Re-enable interrupts. */
1182 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1184 if ((ifp->if_flags & IFF_UP) && !ifq_is_empty(&ifp->if_snd))
1191 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1192 struct an_reply *reply)
1196 for (i = 0; i != AN_TIMEOUT; i++) {
1197 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1202 if( i == AN_TIMEOUT) {
1207 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1208 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1209 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1210 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1212 for (i = 0; i < AN_TIMEOUT; i++) {
1213 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1218 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1219 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1220 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1221 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1223 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1224 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1226 /* Ack the command */
1227 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1229 if (i == AN_TIMEOUT)
1236 an_cmd(struct an_softc *sc, int cmd, int val)
1240 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1241 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1242 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1243 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1245 for (i = 0; i < AN_TIMEOUT; i++) {
1246 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1249 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1250 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1254 for (i = 0; i < AN_TIMEOUT; i++) {
1255 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1256 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1257 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1258 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1259 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1263 /* Ack the command */
1264 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1266 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1267 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1269 if (i == AN_TIMEOUT)
1276 * This reset sequence may look a little strange, but this is the
1277 * most reliable method I've found to really kick the NIC in the
1278 * head and force it to reboot correctly.
1281 an_reset(struct an_softc *sc)
1283 an_cmd(sc, AN_CMD_ENABLE, 0);
1284 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1285 an_cmd(sc, AN_CMD_NOOP2, 0);
1287 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1288 if_printf(&sc->arpcom.ac_if, "reset failed\n");
1290 an_cmd(sc, AN_CMD_DISABLE, 0);
1296 * Read an LTV record from the NIC.
1299 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1301 struct an_ltv_gen *an_ltv;
1302 struct an_card_rid_desc an_rid_desc;
1303 struct an_command cmd;
1304 struct an_reply reply;
1309 if (ltv->an_len < 4 || ltv->an_type == 0)
1313 /* Tell the NIC to enter record read mode. */
1314 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1315 if_printf(&sc->arpcom.ac_if, "RID access failed\n");
1319 /* Seek to the record. */
1320 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1321 if_printf(&sc->arpcom.ac_if, "seek to record failed\n");
1326 * Read the length and record type and make sure they
1327 * match what we expect (this verifies that we have enough
1328 * room to hold all of the returned data).
1329 * Length includes type but not length.
1331 len = CSR_READ_2(sc, AN_DATA1);
1332 if (len > (ltv->an_len - 2)) {
1333 if_printf(&sc->arpcom.ac_if,
1334 "record length mismatch -- expected %d, "
1335 "got %d for Rid %x\n",
1336 ltv->an_len - 2, len, ltv->an_type);
1337 len = ltv->an_len - 2;
1339 ltv->an_len = len + 2;
1342 /* Now read the data. */
1343 len -= 2; /* skip the type */
1345 for (i = len; i > 1; i -= 2)
1346 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1348 ptr2 = (u_int8_t *)ptr;
1349 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1351 } else { /* MPI-350 */
1352 if (sc->an_rid_buffer.an_dma_vaddr == NULL)
1354 an_rid_desc.an_valid = 1;
1355 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1356 an_rid_desc.an_rid = 0;
1357 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1358 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1360 bzero(&cmd, sizeof(cmd));
1361 bzero(&reply, sizeof(reply));
1362 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1363 cmd.an_parm0 = ltv->an_type;
1365 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1366 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1367 ((u_int32_t*)&an_rid_desc)[i]);
1369 if (an_cmd_struct(sc, &cmd, &reply)
1370 || reply.an_status & AN_CMD_QUAL_MASK) {
1371 if_printf(&sc->arpcom.ac_if,
1372 "failed to read RID %x %x %x %x %x, %d\n",
1382 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1383 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1384 an_rid_desc.an_len = an_ltv->an_len;
1387 len = an_rid_desc.an_len;
1388 if (len > (ltv->an_len - 2)) {
1389 if_printf(&sc->arpcom.ac_if,
1390 "record length mismatch -- expected %d, "
1391 "got %d for Rid %x\n",
1392 ltv->an_len - 2, len, ltv->an_type);
1393 len = ltv->an_len - 2;
1395 ltv->an_len = len + 2;
1397 bcopy(&an_ltv->an_type, <v->an_val, len);
1401 an_dump_record(sc, ltv, "Read");
1407 * Same as read, except we inject data instead of reading it.
1410 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1412 struct an_card_rid_desc an_rid_desc;
1413 struct an_command cmd;
1414 struct an_reply reply;
1421 an_dump_record(sc, ltv, "Write");
1424 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1427 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1431 * Length includes type but not length.
1433 len = ltv->an_len - 2;
1434 CSR_WRITE_2(sc, AN_DATA1, len);
1436 len -= 2; /* skip the type */
1438 for (i = len; i > 1; i -= 2)
1439 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1441 ptr2 = (u_int8_t *)ptr;
1442 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1445 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1450 for (i = 0; i != AN_TIMEOUT; i++) {
1451 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1457 if (i == AN_TIMEOUT) {
1461 an_rid_desc.an_valid = 1;
1462 an_rid_desc.an_len = ltv->an_len - 2;
1463 an_rid_desc.an_rid = ltv->an_type;
1464 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1466 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1467 an_rid_desc.an_len);
1469 bzero(&cmd,sizeof(cmd));
1470 bzero(&reply,sizeof(reply));
1471 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1472 cmd.an_parm0 = ltv->an_type;
1474 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1475 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1476 ((u_int32_t*)&an_rid_desc)[i]);
1478 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1479 if_printf(&sc->arpcom.ac_if,
1480 "failed to write RID 1 %x %x %x %x %x, %d\n",
1490 ptr = (u_int16_t *)buf;
1492 if (reply.an_status & AN_CMD_QUAL_MASK) {
1493 if_printf(&sc->arpcom.ac_if,
1494 "failed to write RID 2 %x %x %x %x %x, %d\n",
1509 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1517 len = ltv->an_len - 4;
1518 if_printf(&sc->arpcom.ac_if, "RID %4x, Length %4d, Mode %s\n",
1519 ltv->an_type, ltv->an_len - 4, string);
1521 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1522 if_printf(&sc->arpcom.ac_if, "\t");
1523 bzero(buf,sizeof(buf));
1525 ptr2 = (u_int8_t *)<v->an_val;
1526 for (i = len; i > 0; i--) {
1527 printf("%02x ", *ptr2);
1530 if (temp >= ' ' && temp <= '~')
1532 else if (temp >= 'A' && temp <= 'Z')
1536 if (++count == 16) {
1539 if_printf(&sc->arpcom.ac_if, "\t");
1540 bzero(buf,sizeof(buf));
1543 for (; count != 16; count++) {
1546 printf(" %s\n",buf);
1551 an_seek(struct an_softc *sc, int id, int off, int chan)
1566 if_printf(&sc->arpcom.ac_if, "invalid data path: %x\n", chan);
1570 CSR_WRITE_2(sc, selreg, id);
1571 CSR_WRITE_2(sc, offreg, off);
1573 for (i = 0; i < AN_TIMEOUT; i++) {
1574 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1578 if (i == AN_TIMEOUT)
1585 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1592 if (an_seek(sc, id, off, AN_BAP1))
1596 ptr = (u_int16_t *)buf;
1597 for (i = len; i > 1; i -= 2)
1598 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1600 ptr2 = (u_int8_t *)ptr;
1601 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1608 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1615 if (an_seek(sc, id, off, AN_BAP0))
1619 ptr = (u_int16_t *)buf;
1620 for (i = len; i > 1; i -= 2)
1621 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1623 ptr2 = (u_int8_t *)ptr;
1624 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1631 * Allocate a region of memory inside the NIC and zero
1635 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1639 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1640 if_printf(&sc->arpcom.ac_if,
1641 "failed to allocate %d bytes on NIC\n", len);
1645 for (i = 0; i < AN_TIMEOUT; i++) {
1646 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1650 if (i == AN_TIMEOUT)
1653 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1654 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1656 if (an_seek(sc, *id, 0, AN_BAP0))
1659 for (i = 0; i < len / 2; i++)
1660 CSR_WRITE_2(sc, AN_DATA0, 0);
1666 an_setdef(struct an_softc *sc, struct an_req *areq)
1669 struct an_ltv_genconfig *cfg;
1670 struct an_ltv_ssidlist_new *ssid;
1671 struct an_ltv_aplist *ap;
1672 struct an_ltv_gen *sp;
1674 ifp = &sc->arpcom.ac_if;
1676 switch (areq->an_type) {
1677 case AN_RID_GENCONFIG:
1678 cfg = (struct an_ltv_genconfig *)areq;
1680 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1682 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
1684 bcopy((char *)cfg, (char *)&sc->an_config,
1685 sizeof(struct an_ltv_genconfig));
1687 case AN_RID_SSIDLIST:
1688 ssid = (struct an_ltv_ssidlist_new *)areq;
1689 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1690 sizeof(struct an_ltv_ssidlist_new));
1693 ap = (struct an_ltv_aplist *)areq;
1694 bcopy((char *)ap, (char *)&sc->an_aplist,
1695 sizeof(struct an_ltv_aplist));
1697 case AN_RID_TX_SPEED:
1698 sp = (struct an_ltv_gen *)areq;
1699 sc->an_tx_rate = sp->an_val;
1701 /* Read the current configuration */
1702 sc->an_config.an_type = AN_RID_GENCONFIG;
1703 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1704 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1705 cfg = &sc->an_config;
1707 /* clear other rates and set the only one we want */
1708 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1709 cfg->an_rates[0] = sc->an_tx_rate;
1711 /* Save the new rate */
1712 sc->an_config.an_type = AN_RID_GENCONFIG;
1713 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1715 case AN_RID_WEP_TEMP:
1716 /* Cache the temp keys */
1718 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1719 sizeof(struct an_ltv_key));
1720 case AN_RID_WEP_PERM:
1721 case AN_RID_LEAPUSERNAME:
1722 case AN_RID_LEAPPASSWORD:
1725 /* Disable the MAC. */
1726 an_cmd(sc, AN_CMD_DISABLE, 0);
1729 an_write_record(sc, (struct an_ltv_gen *)areq);
1731 /* Turn the MAC back on. */
1732 an_cmd(sc, AN_CMD_ENABLE, 0);
1735 case AN_RID_MONITOR_MODE:
1736 cfg = (struct an_ltv_genconfig *)areq;
1738 if (ng_ether_detach_p != NULL)
1739 (*ng_ether_detach_p) (ifp);
1740 sc->an_monitor = cfg->an_len;
1742 if (sc->an_monitor & AN_MONITOR) {
1743 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1744 bpfattach(ifp, DLT_AIRONET_HEADER,
1745 sizeof(struct ether_header));
1747 bpfattach(ifp, DLT_IEEE802_11,
1748 sizeof(struct ether_header));
1751 bpfattach(ifp, DLT_EN10MB,
1752 sizeof(struct ether_header));
1753 if (ng_ether_attach_p != NULL)
1754 (*ng_ether_attach_p) (ifp);
1758 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1763 /* Reinitialize the card. */
1771 * Derived from Linux driver to enable promiscious mode.
1775 an_promisc(struct an_softc *sc, int promisc)
1777 if (sc->an_was_monitor)
1780 an_init_mpi350_desc(sc);
1781 if (sc->an_monitor || sc->an_was_monitor)
1784 sc->an_was_monitor = sc->an_monitor;
1785 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1791 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
1796 struct an_softc *sc;
1798 struct ieee80211req *ireq;
1799 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1801 struct an_ltv_genconfig *config;
1802 struct an_ltv_key *key;
1803 struct an_ltv_status *status;
1804 struct an_ltv_ssidlist_new *ssids;
1806 struct aironet_ioctl l_ioctl;
1809 ifr = (struct ifreq *)data;
1810 ireq = (struct ieee80211req *)data;
1812 config = (struct an_ltv_genconfig *)&sc->areq;
1813 key = (struct an_ltv_key *)&sc->areq;
1814 status = (struct an_ltv_status *)&sc->areq;
1815 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1819 if (ifp->if_flags & IFF_UP) {
1820 if (ifp->if_flags & IFF_RUNNING &&
1821 ifp->if_flags & IFF_PROMISC &&
1822 !(sc->an_if_flags & IFF_PROMISC)) {
1824 } else if (ifp->if_flags & IFF_RUNNING &&
1825 !(ifp->if_flags & IFF_PROMISC) &&
1826 sc->an_if_flags & IFF_PROMISC) {
1831 if (ifp->if_flags & IFF_RUNNING)
1834 sc->an_if_flags = ifp->if_flags;
1839 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1843 /* The Aironet has no multicast filter. */
1847 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1851 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1852 error = suser_cred(cr, NULL_CRED_OKAY);
1855 sc->an_sigitems = sc->an_nextitem = 0;
1857 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1858 char *pt = (char *)&sc->areq.an_val;
1859 bcopy((char *)&sc->an_sigitems, (char *)pt,
1862 sc->areq.an_len = sizeof(int) / 2;
1863 bcopy((char *)&sc->an_sigcache, (char *)pt,
1864 sizeof(struct an_sigcache) * sc->an_sigitems);
1865 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1866 sc->an_sigitems) / 2) + 1;
1869 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1873 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1876 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1878 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1881 an_setdef(sc, &sc->areq);
1883 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1884 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1886 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1887 mode = l_ioctl.command;
1889 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1890 error = readrids(ifp, &l_ioctl);
1891 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1892 error = writerids(ifp, &l_ioctl);
1893 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1894 error = flashcard(ifp, &l_ioctl);
1899 /* copy out the updated command info */
1900 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1903 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1904 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1906 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1907 l_ioctl.command = 0;
1909 copyout(&error, l_ioctl.data, sizeof(error));
1913 sc->areq.an_len = sizeof(sc->areq);
1914 /* was that a good idea DJA we are doing a short-cut */
1915 switch (ireq->i_type) {
1916 case IEEE80211_IOC_SSID:
1917 if (ireq->i_val == -1) {
1918 sc->areq.an_type = AN_RID_STATUS;
1919 if (an_read_record(sc,
1920 (struct an_ltv_gen *)&sc->areq)) {
1924 len = status->an_ssidlen;
1925 tmpptr = status->an_ssid;
1926 } else if (ireq->i_val >= 0) {
1927 sc->areq.an_type = AN_RID_SSIDLIST;
1928 if (an_read_record(sc,
1929 (struct an_ltv_gen *)&sc->areq)) {
1933 max = (sc->areq.an_len - 4)
1934 / sizeof(struct an_ltv_ssid_entry);
1935 if ( max > MAX_SSIDS ) {
1936 printf("To many SSIDs only using "
1941 if (ireq->i_val > max) {
1945 len = ssids->an_entry[ireq->i_val].an_len;
1946 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
1952 if (len > IEEE80211_NWID_LEN) {
1957 bzero(tmpstr, IEEE80211_NWID_LEN);
1958 bcopy(tmpptr, tmpstr, len);
1959 error = copyout(tmpstr, ireq->i_data,
1960 IEEE80211_NWID_LEN);
1962 case IEEE80211_IOC_NUMSSIDS:
1963 sc->areq.an_len = sizeof(sc->areq);
1964 sc->areq.an_type = AN_RID_SSIDLIST;
1965 if (an_read_record(sc,
1966 (struct an_ltv_gen *)&sc->areq)) {
1970 max = (sc->areq.an_len - 4)
1971 / sizeof(struct an_ltv_ssid_entry);
1972 if (max > MAX_SSIDS) {
1973 printf("To many SSIDs only using "
1980 case IEEE80211_IOC_WEP:
1981 sc->areq.an_type = AN_RID_ACTUALCFG;
1982 if (an_read_record(sc,
1983 (struct an_ltv_gen *)&sc->areq)) {
1987 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
1988 if (config->an_authtype &
1989 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
1990 ireq->i_val = IEEE80211_WEP_MIXED;
1992 ireq->i_val = IEEE80211_WEP_ON;
1994 ireq->i_val = IEEE80211_WEP_OFF;
1997 case IEEE80211_IOC_WEPKEY:
1999 * XXX: I'm not entierly convinced this is
2000 * correct, but it's what is implemented in
2001 * ancontrol so it will have to do until we get
2002 * access to actual Cisco code.
2004 if (ireq->i_val < 0 || ireq->i_val > 8) {
2009 if (ireq->i_val < 5) {
2010 sc->areq.an_type = AN_RID_WEP_TEMP;
2011 for (i = 0; i < 5; i++) {
2012 if (an_read_record(sc,
2013 (struct an_ltv_gen *)&sc->areq)) {
2017 if (key->kindex == 0xffff)
2019 if (key->kindex == ireq->i_val)
2021 /* Required to get next entry */
2022 sc->areq.an_type = AN_RID_WEP_PERM;
2027 /* We aren't allowed to read the value of the
2028 * key from the card so we just output zeros
2029 * like we would if we could read the card, but
2030 * denied the user access.
2034 error = copyout(tmpstr, ireq->i_data, len);
2036 case IEEE80211_IOC_NUMWEPKEYS:
2037 ireq->i_val = 9; /* include home key */
2039 case IEEE80211_IOC_WEPTXKEY:
2041 * For some strange reason, you have to read all
2042 * keys before you can read the txkey.
2044 sc->areq.an_type = AN_RID_WEP_TEMP;
2045 for (i = 0; i < 5; i++) {
2046 if (an_read_record(sc,
2047 (struct an_ltv_gen *) &sc->areq)) {
2051 if (key->kindex == 0xffff)
2053 /* Required to get next entry */
2054 sc->areq.an_type = AN_RID_WEP_PERM;
2059 sc->areq.an_type = AN_RID_WEP_PERM;
2060 key->kindex = 0xffff;
2061 if (an_read_record(sc,
2062 (struct an_ltv_gen *)&sc->areq)) {
2066 ireq->i_val = key->mac[0];
2068 * Check for home mode. Map home mode into
2069 * 5th key since that is how it is stored on
2072 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2073 sc->areq.an_type = AN_RID_GENCONFIG;
2074 if (an_read_record(sc,
2075 (struct an_ltv_gen *)&sc->areq)) {
2079 if (config->an_home_product & AN_HOME_NETWORK)
2082 case IEEE80211_IOC_AUTHMODE:
2083 sc->areq.an_type = AN_RID_ACTUALCFG;
2084 if (an_read_record(sc,
2085 (struct an_ltv_gen *)&sc->areq)) {
2089 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2091 ireq->i_val = IEEE80211_AUTH_NONE;
2092 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2094 ireq->i_val = IEEE80211_AUTH_OPEN;
2095 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2096 AN_AUTHTYPE_SHAREDKEY) {
2097 ireq->i_val = IEEE80211_AUTH_SHARED;
2101 case IEEE80211_IOC_STATIONNAME:
2102 sc->areq.an_type = AN_RID_ACTUALCFG;
2103 if (an_read_record(sc,
2104 (struct an_ltv_gen *)&sc->areq)) {
2108 ireq->i_len = sizeof(config->an_nodename);
2109 tmpptr = config->an_nodename;
2110 bzero(tmpstr, IEEE80211_NWID_LEN);
2111 bcopy(tmpptr, tmpstr, ireq->i_len);
2112 error = copyout(tmpstr, ireq->i_data,
2113 IEEE80211_NWID_LEN);
2115 case IEEE80211_IOC_CHANNEL:
2116 sc->areq.an_type = AN_RID_STATUS;
2117 if (an_read_record(sc,
2118 (struct an_ltv_gen *)&sc->areq)) {
2122 ireq->i_val = status->an_cur_channel;
2124 case IEEE80211_IOC_POWERSAVE:
2125 sc->areq.an_type = AN_RID_ACTUALCFG;
2126 if (an_read_record(sc,
2127 (struct an_ltv_gen *)&sc->areq)) {
2131 if (config->an_psave_mode == AN_PSAVE_NONE) {
2132 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2133 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2134 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2135 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2136 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2137 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2138 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2142 case IEEE80211_IOC_POWERSAVESLEEP:
2143 sc->areq.an_type = AN_RID_ACTUALCFG;
2144 if (an_read_record(sc,
2145 (struct an_ltv_gen *)&sc->areq)) {
2149 ireq->i_val = config->an_listen_interval;
2154 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
2156 sc->areq.an_len = sizeof(sc->areq);
2158 * We need a config structure for everything but the WEP
2159 * key management and SSIDs so we get it now so avoid
2160 * duplicating this code every time.
2162 if (ireq->i_type != IEEE80211_IOC_SSID &&
2163 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2164 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2165 sc->areq.an_type = AN_RID_GENCONFIG;
2166 if (an_read_record(sc,
2167 (struct an_ltv_gen *)&sc->areq)) {
2172 switch (ireq->i_type) {
2173 case IEEE80211_IOC_SSID:
2174 sc->areq.an_len = sizeof(sc->areq);
2175 sc->areq.an_type = AN_RID_SSIDLIST;
2176 if (an_read_record(sc,
2177 (struct an_ltv_gen *)&sc->areq)) {
2181 if (ireq->i_len > IEEE80211_NWID_LEN) {
2185 max = (sc->areq.an_len - 4)
2186 / sizeof(struct an_ltv_ssid_entry);
2187 if (max > MAX_SSIDS) {
2188 printf("To many SSIDs only using "
2193 if (ireq->i_val > max) {
2197 error = copyin(ireq->i_data,
2198 ssids->an_entry[ireq->i_val].an_ssid,
2200 ssids->an_entry[ireq->i_val].an_len
2205 case IEEE80211_IOC_WEP:
2206 switch (ireq->i_val) {
2207 case IEEE80211_WEP_OFF:
2208 config->an_authtype &=
2209 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2210 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2212 case IEEE80211_WEP_ON:
2213 config->an_authtype |=
2214 AN_AUTHTYPE_PRIVACY_IN_USE;
2215 config->an_authtype &=
2216 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2218 case IEEE80211_WEP_MIXED:
2219 config->an_authtype |=
2220 AN_AUTHTYPE_PRIVACY_IN_USE |
2221 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2228 case IEEE80211_IOC_WEPKEY:
2229 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2234 error = copyin(ireq->i_data, tmpstr, 13);
2238 * Map the 9th key into the home mode
2239 * since that is how it is stored on
2242 bzero(&sc->areq, sizeof(struct an_ltv_key));
2243 sc->areq.an_len = sizeof(struct an_ltv_key);
2244 key->mac[0] = 1; /* The others are 0. */
2245 if (ireq->i_val < 4) {
2246 sc->areq.an_type = AN_RID_WEP_TEMP;
2247 key->kindex = ireq->i_val;
2249 sc->areq.an_type = AN_RID_WEP_PERM;
2250 key->kindex = ireq->i_val - 4;
2252 key->klen = ireq->i_len;
2253 bcopy(tmpstr, key->key, key->klen);
2255 case IEEE80211_IOC_WEPTXKEY:
2256 if (ireq->i_val < 0 || ireq->i_val > 4) {
2262 * Map the 5th key into the home mode
2263 * since that is how it is stored on
2266 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2267 sc->areq.an_type = AN_RID_ACTUALCFG;
2268 if (an_read_record(sc,
2269 (struct an_ltv_gen *)&sc->areq)) {
2273 if (ireq->i_val == 4) {
2274 config->an_home_product |= AN_HOME_NETWORK;
2277 config->an_home_product &= ~AN_HOME_NETWORK;
2280 sc->an_config.an_home_product
2281 = config->an_home_product;
2283 /* update configuration */
2286 bzero(&sc->areq, sizeof(struct an_ltv_key));
2287 sc->areq.an_len = sizeof(struct an_ltv_key);
2288 sc->areq.an_type = AN_RID_WEP_PERM;
2289 key->kindex = 0xffff;
2290 key->mac[0] = ireq->i_val;
2292 case IEEE80211_IOC_AUTHMODE:
2293 switch (ireq->i_val) {
2294 case IEEE80211_AUTH_NONE:
2295 config->an_authtype = AN_AUTHTYPE_NONE |
2296 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2298 case IEEE80211_AUTH_OPEN:
2299 config->an_authtype = AN_AUTHTYPE_OPEN |
2300 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2302 case IEEE80211_AUTH_SHARED:
2303 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2304 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2310 case IEEE80211_IOC_STATIONNAME:
2311 if (ireq->i_len > 16) {
2315 bzero(config->an_nodename, 16);
2316 error = copyin(ireq->i_data,
2317 config->an_nodename, ireq->i_len);
2319 case IEEE80211_IOC_CHANNEL:
2321 * The actual range is 1-14, but if you set it
2322 * to 0 you get the default so we let that work
2325 if (ireq->i_val < 0 || ireq->i_val >14) {
2329 config->an_ds_channel = ireq->i_val;
2331 case IEEE80211_IOC_POWERSAVE:
2332 switch (ireq->i_val) {
2333 case IEEE80211_POWERSAVE_OFF:
2334 config->an_psave_mode = AN_PSAVE_NONE;
2336 case IEEE80211_POWERSAVE_CAM:
2337 config->an_psave_mode = AN_PSAVE_CAM;
2339 case IEEE80211_POWERSAVE_PSP:
2340 config->an_psave_mode = AN_PSAVE_PSP;
2342 case IEEE80211_POWERSAVE_PSP_CAM:
2343 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2350 case IEEE80211_IOC_POWERSAVESLEEP:
2351 config->an_listen_interval = ireq->i_val;
2356 an_setdef(sc, &sc->areq);
2359 error = ether_ioctl(ifp, command, data);
2367 an_init_tx_ring(struct an_softc *sc)
2373 for (i = 0; i < AN_TX_RING_CNT; i++) {
2374 if (an_alloc_nicmem(sc, 1518 +
2377 sc->an_rdata.an_tx_fids[i] = id;
2378 sc->an_rdata.an_tx_ring[i] = 0;
2382 sc->an_rdata.an_tx_prod = 0;
2383 sc->an_rdata.an_tx_cons = 0;
2384 sc->an_rdata.an_tx_empty = 1;
2392 struct an_softc *sc = xsc;
2393 struct ifnet *ifp = &sc->arpcom.ac_if;
2395 if (ifp->if_flags & IFF_RUNNING)
2398 sc->an_associated = 0;
2400 /* Allocate the TX buffers */
2401 if (an_init_tx_ring(sc)) {
2404 an_init_mpi350_desc(sc);
2405 if (an_init_tx_ring(sc)) {
2406 if_printf(ifp, "tx buffer allocation failed\n");
2411 /* Set our MAC address. */
2412 bcopy((char *)&sc->arpcom.ac_enaddr,
2413 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2415 if (ifp->if_flags & IFF_BROADCAST)
2416 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2418 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2420 if (ifp->if_flags & IFF_MULTICAST)
2421 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2423 if (ifp->if_flags & IFF_PROMISC) {
2424 if (sc->an_monitor & AN_MONITOR) {
2425 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2426 sc->an_config.an_rxmode |=
2427 AN_RXMODE_80211_MONITOR_ANYBSS |
2428 AN_RXMODE_NO_8023_HEADER;
2430 sc->an_config.an_rxmode |=
2431 AN_RXMODE_80211_MONITOR_CURBSS |
2432 AN_RXMODE_NO_8023_HEADER;
2437 if (sc->an_have_rssimap)
2438 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2440 /* Set the ssid list */
2441 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2442 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2443 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2444 if_printf(ifp, "failed to set ssid list\n");
2448 /* Set the AP list */
2449 sc->an_aplist.an_type = AN_RID_APLIST;
2450 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2451 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2452 if_printf(ifp, "failed to set AP list\n");
2456 /* Set the configuration in the NIC */
2457 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2458 sc->an_config.an_type = AN_RID_GENCONFIG;
2459 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2460 if_printf(ifp, "failed to set configuration\n");
2464 /* Enable the MAC */
2465 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2466 if_printf(ifp, "failed to enable MAC\n");
2470 if (ifp->if_flags & IFF_PROMISC)
2471 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2473 /* enable interrupts */
2474 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2476 ifp->if_flags |= IFF_RUNNING;
2477 ifp->if_flags &= ~IFF_OACTIVE;
2479 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
2483 an_start(struct ifnet *ifp)
2485 struct an_softc *sc;
2486 struct mbuf *m0 = NULL;
2487 struct an_txframe_802_3 tx_frame_802_3;
2488 struct ether_header *eh;
2490 unsigned char txcontrol;
2491 struct an_card_tx_desc an_tx_desc;
2496 if (ifp->if_flags & IFF_OACTIVE)
2499 if (!sc->an_associated)
2502 /* We can't send in monitor mode so toss any attempts. */
2503 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2504 ifq_purge(&ifp->if_snd);
2508 idx = sc->an_rdata.an_tx_prod;
2511 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2513 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2514 m0 = ifq_dequeue(&ifp->if_snd, NULL);
2518 id = sc->an_rdata.an_tx_fids[idx];
2519 eh = mtod(m0, struct ether_header *);
2521 bcopy((char *)&eh->ether_dhost,
2522 (char *)&tx_frame_802_3.an_tx_dst_addr,
2524 bcopy((char *)&eh->ether_shost,
2525 (char *)&tx_frame_802_3.an_tx_src_addr,
2528 /* minus src/dest mac & type */
2529 tx_frame_802_3.an_tx_802_3_payload_len =
2530 m0->m_pkthdr.len - 12;
2532 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2533 tx_frame_802_3.an_tx_802_3_payload_len,
2534 (caddr_t)&sc->an_txbuf);
2536 txcontrol = AN_TXCTL_8023;
2537 /* write the txcontrol only */
2538 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2542 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2543 sizeof(struct an_txframe_802_3));
2545 /* in mbuf header type is just before payload */
2546 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2547 tx_frame_802_3.an_tx_802_3_payload_len);
2554 sc->an_rdata.an_tx_ring[idx] = id;
2555 if (an_cmd(sc, AN_CMD_TX, id))
2556 if_printf(ifp, "xmit failed\n");
2558 AN_INC(idx, AN_TX_RING_CNT);
2561 * Set a timeout in case the chip goes out to lunch.
2565 } else { /* MPI-350 */
2566 /* Disable interrupts. */
2567 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2569 while (sc->an_rdata.an_tx_empty ||
2570 idx != sc->an_rdata.an_tx_cons) {
2571 m0 = ifq_dequeue(&ifp->if_snd, NULL);
2575 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2577 eh = mtod(m0, struct ether_header *);
2579 /* DJA optimize this to limit bcopy */
2580 bcopy((char *)&eh->ether_dhost,
2581 (char *)&tx_frame_802_3.an_tx_dst_addr,
2583 bcopy((char *)&eh->ether_shost,
2584 (char *)&tx_frame_802_3.an_tx_src_addr,
2587 /* minus src/dest mac & type */
2588 tx_frame_802_3.an_tx_802_3_payload_len =
2589 m0->m_pkthdr.len - 12;
2591 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2592 tx_frame_802_3.an_tx_802_3_payload_len,
2593 (caddr_t)&sc->an_txbuf);
2595 txcontrol = AN_TXCTL_8023;
2596 /* write the txcontrol only */
2597 bcopy((caddr_t)&txcontrol, &buf[0x08],
2601 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2602 sizeof(struct an_txframe_802_3));
2604 /* in mbuf header type is just before payload */
2605 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2606 tx_frame_802_3.an_tx_802_3_payload_len);
2609 bzero(&an_tx_desc, sizeof(an_tx_desc));
2610 an_tx_desc.an_offset = 0;
2611 an_tx_desc.an_eoc = 1;
2612 an_tx_desc.an_valid = 1;
2613 an_tx_desc.an_len = 0x44 +
2614 tx_frame_802_3.an_tx_802_3_payload_len;
2615 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2616 for (i = 0; i < sizeof(an_tx_desc) / 4 ; i++) {
2617 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2619 + (0 * sizeof(an_tx_desc))
2621 ((u_int32_t*)&an_tx_desc)[i]);
2629 AN_INC(idx, AN_MAX_TX_DESC);
2630 sc->an_rdata.an_tx_empty = 0;
2632 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2635 * Set a timeout in case the chip goes out to lunch.
2640 /* Re-enable interrupts. */
2641 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2645 ifp->if_flags |= IFF_OACTIVE;
2647 sc->an_rdata.an_tx_prod = idx;
2651 an_stop(struct an_softc *sc)
2656 ifp = &sc->arpcom.ac_if;
2658 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2659 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2660 an_cmd(sc, AN_CMD_DISABLE, 0);
2662 for (i = 0; i < AN_TX_RING_CNT; i++)
2663 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2665 callout_stop(&sc->an_stat_timer);
2667 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2669 if (sc->an_flash_buffer) {
2670 free(sc->an_flash_buffer, M_DEVBUF);
2671 sc->an_flash_buffer = NULL;
2676 an_watchdog(struct ifnet *ifp)
2678 struct an_softc *sc;
2684 an_init_mpi350_desc(sc);
2689 if_printf(ifp, "device timeout\n");
2693 an_shutdown(device_t dev)
2695 struct an_softc *sc;
2697 sc = device_get_softc(dev);
2704 an_resume(device_t dev)
2706 struct an_softc *sc;
2710 sc = device_get_softc(dev);
2711 ifp = &sc->arpcom.ac_if;
2715 an_init_mpi350_desc(sc);
2718 /* Recovery temporary keys */
2719 for (i = 0; i < 4; i++) {
2720 sc->areq.an_type = AN_RID_WEP_TEMP;
2721 sc->areq.an_len = sizeof(struct an_ltv_key);
2722 bcopy(&sc->an_temp_keys[i],
2723 &sc->areq, sizeof(struct an_ltv_key));
2724 an_setdef(sc, &sc->areq);
2727 if (ifp->if_flags & IFF_UP)
2734 /* Aironet signal strength cache code.
2735 * store signal/noise/quality on per MAC src basis in
2736 * a small fixed cache. The cache wraps if > MAX slots
2737 * used. The cache may be zeroed out to start over.
2738 * Two simple filters exist to reduce computation:
2739 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2740 * to ignore some packets. It defaults to ip only.
2741 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2742 * 2. multicast/broadcast only. This may be used to
2743 * ignore unicast packets and only cache signal strength
2744 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2745 * beacons and not unicast traffic.
2747 * The cache stores (MAC src(index), IP src (major clue), signal,
2750 * No apologies for storing IP src here. It's easy and saves much
2751 * trouble elsewhere. The cache is assumed to be INET dependent,
2752 * although it need not be.
2754 * Note: the Aironet only has a single byte of signal strength value
2755 * in the rx frame header, and it's not scaled to anything sensible.
2756 * This is kind of lame, but it's all we've got.
2759 #ifdef documentation
2761 int an_sigitems; /* number of cached entries */
2762 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2763 int an_nextitem; /* index/# of entries */
2768 /* control variables for cache filtering. Basic idea is
2769 * to reduce cost (e.g., to only Mobile-IP agent beacons
2770 * which are broadcast or multicast). Still you might
2771 * want to measure signal strength anth unicast ping packets
2772 * on a pt. to pt. ant. setup.
2774 /* set true if you want to limit cache items to broadcast/mcast
2775 * only packets (not unicast). Useful for mobile-ip beacons which
2776 * are broadcast/multicast at network layer. Default is all packets
2777 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2779 static int an_cache_mcastonly = 0;
2780 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2781 &an_cache_mcastonly, 0, "");
2783 /* set true if you want to limit cache items to IP packets only
2785 static int an_cache_iponly = 1;
2786 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2787 &an_cache_iponly, 0, "");
2790 * an_cache_store, per rx packet store signal
2791 * strength in MAC (src) indexed cache.
2794 an_cache_store (struct an_softc *sc, struct mbuf *m, u_int8_t rx_rssi,
2795 u_int8_t rx_quality)
2797 struct ether_header *eh = mtod(m, struct ether_header *);
2798 struct ip *ip = NULL;
2800 static int cache_slot = 0; /* use this cache entry */
2801 static int wrapindex = 0; /* next "free" cache entry */
2805 * 2. configurable filter to throw out unicast packets,
2806 * keep multicast only.
2809 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2810 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2811 else if (an_cache_iponly)
2814 /* filter for broadcast/multicast only
2816 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2821 if_printf(&sc->arpcom.ac_if, "q value %x (MSB=0x%x, LSB=0x%x)\n",
2822 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2825 /* do a linear search for a matching MAC address
2826 * in the cache table
2827 * . MAC address is 6 bytes,
2828 * . var w_nextitem holds total number of entries already cached
2830 for (i = 0; i < sc->an_nextitem; i++) {
2831 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
2833 * so we already have this entry,
2840 /* did we find a matching mac address?
2841 * if yes, then overwrite a previously existing cache entry
2843 if (i < sc->an_nextitem ) {
2846 /* else, have a new address entry,so
2847 * add this new entry,
2848 * if table full, then we need to replace LRU entry
2852 /* check for space in cache table
2853 * note: an_nextitem also holds number of entries
2854 * added in the cache table
2856 if ( sc->an_nextitem < MAXANCACHE ) {
2857 cache_slot = sc->an_nextitem;
2859 sc->an_sigitems = sc->an_nextitem;
2861 /* no space found, so simply wrap anth wrap index
2862 * and "zap" the next entry
2865 if (wrapindex == MAXANCACHE) {
2868 cache_slot = wrapindex++;
2872 /* invariant: cache_slot now points at some slot
2875 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
2876 log(LOG_ERR, "an_cache_store, bad index: %d of "
2877 "[0..%d], gross cache error\n",
2878 cache_slot, MAXANCACHE);
2882 /* store items in cache
2883 * .ip source address
2888 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2890 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2893 switch (an_cache_mode) {
2895 if (sc->an_have_rssimap) {
2896 sc->an_sigcache[cache_slot].signal =
2897 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
2898 sc->an_sigcache[cache_slot].quality =
2899 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
2901 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
2902 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
2906 if (sc->an_have_rssimap) {
2907 sc->an_sigcache[cache_slot].signal =
2908 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
2909 sc->an_sigcache[cache_slot].quality =
2910 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
2914 if (rx_quality > 100)
2916 sc->an_sigcache[cache_slot].signal = rx_rssi;
2917 sc->an_sigcache[cache_slot].quality = rx_quality;
2921 sc->an_sigcache[cache_slot].signal = rx_rssi;
2922 sc->an_sigcache[cache_slot].quality = rx_quality;
2926 sc->an_sigcache[cache_slot].noise = 0;
2933 an_media_change(struct ifnet *ifp)
2935 struct an_softc *sc = ifp->if_softc;
2936 struct an_ltv_genconfig *cfg;
2937 int otype = sc->an_config.an_opmode;
2938 int orate = sc->an_tx_rate;
2940 switch (IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media)) {
2941 case IFM_IEEE80211_DS1:
2942 sc->an_tx_rate = AN_RATE_1MBPS;
2944 case IFM_IEEE80211_DS2:
2945 sc->an_tx_rate = AN_RATE_2MBPS;
2947 case IFM_IEEE80211_DS5:
2948 sc->an_tx_rate = AN_RATE_5_5MBPS;
2950 case IFM_IEEE80211_DS11:
2951 sc->an_tx_rate = AN_RATE_11MBPS;
2958 if (orate != sc->an_tx_rate) {
2959 /* Read the current configuration */
2960 sc->an_config.an_type = AN_RID_GENCONFIG;
2961 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2962 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
2963 cfg = &sc->an_config;
2965 /* clear other rates and set the only one we want */
2966 bzero(cfg->an_rates, sizeof(cfg->an_rates));
2967 cfg->an_rates[0] = sc->an_tx_rate;
2969 /* Save the new rate */
2970 sc->an_config.an_type = AN_RID_GENCONFIG;
2971 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2974 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
2975 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
2977 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
2979 if (otype != sc->an_config.an_opmode ||
2980 orate != sc->an_tx_rate)
2987 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
2989 struct an_ltv_status status;
2990 struct an_softc *sc = ifp->if_softc;
2992 status.an_len = sizeof(status);
2993 status.an_type = AN_RID_STATUS;
2994 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
2995 /* If the status read fails, just lie. */
2996 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
2997 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3000 if (sc->an_tx_rate == 0) {
3001 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3002 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3003 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3004 switch (status.an_current_tx_rate) {
3006 imr->ifm_active |= IFM_IEEE80211_DS1;
3009 imr->ifm_active |= IFM_IEEE80211_DS2;
3011 case AN_RATE_5_5MBPS:
3012 imr->ifm_active |= IFM_IEEE80211_DS5;
3014 case AN_RATE_11MBPS:
3015 imr->ifm_active |= IFM_IEEE80211_DS11;
3019 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3022 imr->ifm_status = IFM_AVALID;
3023 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3024 imr->ifm_status |= IFM_ACTIVE;
3027 /********************** Cisco utility support routines *************/
3030 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3035 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3038 struct an_softc *sc;
3040 switch (l_ioctl->command) {
3042 rid = AN_RID_CAPABILITIES;
3045 rid = AN_RID_GENCONFIG;
3048 rid = AN_RID_SSIDLIST;
3051 rid = AN_RID_APLIST;
3054 rid = AN_RID_DRVNAME;
3057 rid = AN_RID_ENCAPPROTO;
3060 rid = AN_RID_WEP_TEMP;
3063 rid = AN_RID_WEP_PERM;
3066 rid = AN_RID_STATUS;
3069 rid = AN_RID_32BITS_DELTA;
3072 rid = AN_RID_32BITS_CUM;
3079 if (rid == 999) /* Is bad command */
3083 sc->areq.an_len = AN_MAX_DATALEN;
3084 sc->areq.an_type = rid;
3086 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3088 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3090 /* the data contains the length at first */
3091 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3092 sizeof(sc->areq.an_len))) {
3095 /* Just copy the data back */
3096 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3104 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3106 struct an_softc *sc;
3111 command = l_ioctl->command;
3115 rid = AN_RID_SSIDLIST;
3118 rid = AN_RID_CAPABILITIES;
3121 rid = AN_RID_APLIST;
3124 rid = AN_RID_GENCONFIG;
3127 an_cmd(sc, AN_CMD_ENABLE, 0);
3131 an_cmd(sc, AN_CMD_DISABLE, 0);
3136 * This command merely clears the counts does not actually
3137 * store any data only reads rid. But as it changes the cards
3138 * state, I put it in the writerid routines.
3141 rid = AN_RID_32BITS_DELTACLR;
3143 sc->areq.an_len = AN_MAX_DATALEN;
3144 sc->areq.an_type = rid;
3146 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3147 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3149 /* the data contains the length at first */
3150 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3151 sizeof(sc->areq.an_len))) {
3154 /* Just copy the data */
3155 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3162 rid = AN_RID_WEP_TEMP;
3165 rid = AN_RID_WEP_PERM;
3168 rid = AN_RID_LEAPUSERNAME;
3171 rid = AN_RID_LEAPPASSWORD;
3178 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3180 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3181 sc->areq.an_type = rid;
3183 /* Just copy the data back */
3184 copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3187 an_cmd(sc, AN_CMD_DISABLE, 0);
3188 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3189 an_cmd(sc, AN_CMD_ENABLE, 0);
3196 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3200 #define FLASH_DELAY(x) tsleep(ifp, 0, "flash", ((x) / hz) + 1);
3201 #define FLASH_COMMAND 0x7e7e
3202 #define FLASH_SIZE 32 * 1024
3205 unstickbusy(struct ifnet *ifp)
3207 struct an_softc *sc = ifp->if_softc;
3209 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3210 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3211 AN_EV_CLR_STUCK_BUSY);
3218 * Wait for busy completion from card wait for delay uSec's Return true for
3219 * success meaning command reg is clear
3223 WaitBusy(struct ifnet *ifp, int uSec)
3225 int statword = 0xffff;
3227 struct an_softc *sc = ifp->if_softc;
3229 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3232 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3234 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3239 return 0 == (AN_CMD_BUSY & statword);
3243 * STEP 1) Disable MAC and do soft reset on card.
3247 cmdreset(struct ifnet *ifp)
3250 struct an_softc *sc = ifp->if_softc;
3254 an_cmd(sc, AN_CMD_DISABLE, 0);
3256 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3257 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3260 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3262 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3265 if (!(status = WaitBusy(ifp, 100))) {
3266 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3273 * STEP 2) Put the card in legendary flash mode
3277 setflashmode(struct ifnet *ifp)
3280 struct an_softc *sc = ifp->if_softc;
3282 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3283 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3284 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3285 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3288 * mdelay(500); // 500ms delay
3293 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3294 printf("Waitbusy hang after setflash mode\n");
3301 * Get a character from the card matching matchbyte Step 3)
3305 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3308 unsigned char rbyte = 0;
3310 struct an_softc *sc = ifp->if_softc;
3314 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3316 if (dwelltime && !(0x8000 & rchar)) {
3321 rbyte = 0xff & rchar;
3323 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3324 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3328 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3330 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3332 } while (dwelltime > 0);
3337 * Put character to SWS0 wait for dwelltime x 50us for echo .
3341 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3344 int pollbusy, waittime;
3345 struct an_softc *sc = ifp->if_softc;
3352 waittime = dwelltime;
3355 * Wait for busy bit d15 to go false indicating buffer empty
3358 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3360 if (pollbusy & 0x8000) {
3367 while (waittime >= 0);
3369 /* timeout for busy clear wait */
3371 if (waittime <= 0) {
3372 if_printf(ifp, "flash putchar busywait timeout!\n");
3376 * Port is clear now write byte and wait for it to echo back
3379 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3382 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3383 } while (dwelltime >= 0 && echo != byte);
3386 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3388 return echo == byte;
3392 * Transfer 32k of firmware data from user buffer to our buffer and send to
3397 flashputbuf(struct ifnet *ifp)
3399 unsigned short *bufp;
3401 struct an_softc *sc = ifp->if_softc;
3405 bufp = sc->an_flash_buffer;
3408 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3409 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3411 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3412 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3415 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3416 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3417 ((u_int32_t *)bufp)[nwords] & 0xffff);
3421 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3427 * After flashing restart the card.
3431 flashrestart(struct ifnet *ifp)
3434 struct an_softc *sc = ifp->if_softc;
3436 FLASH_DELAY(1024); /* Added 12/7/00 */
3440 FLASH_DELAY(1024); /* Added 12/7/00 */
3445 * Entry point for flash ioclt.
3449 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3452 struct an_softc *sc;
3456 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3459 status = l_ioctl->command;
3461 switch (l_ioctl->command) {
3463 return cmdreset(ifp);
3466 if (sc->an_flash_buffer) {
3467 free(sc->an_flash_buffer, M_DEVBUF);
3468 sc->an_flash_buffer = NULL;
3470 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, 0);
3471 if (sc->an_flash_buffer)
3472 return setflashmode(ifp);
3476 case AIROFLSHGCHR: /* Get char from aux */
3477 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3478 z = *(int *)&sc->areq;
3479 if ((status = flashgchar(ifp, z, 8000)) == 1)
3484 case AIROFLSHPCHR: /* Send char to card. */
3485 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3486 z = *(int *)&sc->areq;
3487 if ((status = flashpchar(ifp, z, 8000)) == -1)
3492 case AIROFLPUTBUF: /* Send 32k to card */
3493 if (l_ioctl->len > FLASH_SIZE) {
3494 if_printf(ifp, "Buffer to big, %x %x\n",
3495 l_ioctl->len, FLASH_SIZE);
3498 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3500 if ((status = flashputbuf(ifp)) != 0)
3506 if ((status = flashrestart(ifp)) != 0) {
3507 if_printf(ifp, "FLASHRESTART returned %d\n", status);