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 $
36 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
38 * Written by Bill Paul <wpaul@ctr.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City
44 * The Aironet 4500/4800 series cards come in PCMCIA, ISA and PCI form.
45 * This driver supports all three device types (PCI devices are supported
46 * through an extra PCI shim: /sys/dev/an/if_an_pci.c). ISA devices can be
47 * supported either using hard-coded IO port/IRQ settings or via Plug
48 * and Play. The 4500 series devices support 1Mbps and 2Mbps data rates.
49 * The 4800 devices support 1, 2, 5.5 and 11Mbps rates.
51 * Like the WaveLAN/IEEE cards, the Aironet NICs are all essentially
52 * PCMCIA devices. The ISA and PCI cards are a combination of a PCMCIA
53 * device and a PCMCIA to ISA or PCMCIA to PCI adapter card. There are
54 * a couple of important differences though:
56 * - Lucent ISA card looks to the host like a PCMCIA controller with
57 * a PCMCIA WaveLAN card inserted. This means that even desktop
58 * machines need to be configured with PCMCIA support in order to
59 * use WaveLAN/IEEE ISA cards. The Aironet cards on the other hand
60 * actually look like normal ISA and PCI devices to the host, so
61 * no PCMCIA controller support is needed
63 * The latter point results in a small gotcha. The Aironet PCMCIA
64 * cards can be configured for one of two operating modes depending
65 * on how the Vpp1 and Vpp2 programming voltages are set when the
66 * card is activated. In order to put the card in proper PCMCIA
67 * operation (where the CIS table is visible and the interface is
68 * programmed for PCMCIA operation), both Vpp1 and Vpp2 have to be
69 * set to 5 volts. FreeBSD by default doesn't set the Vpp voltages,
70 * which leaves the card in ISA/PCI mode, which prevents it from
71 * being activated as an PCMCIA device.
73 * Note that some PCMCIA controller software packages for Windows NT
74 * fail to set the voltages as well.
76 * The Aironet devices can operate in both station mode and access point
77 * mode. Typically, when programmed for station mode, the card can be set
78 * to automatically perform encapsulation/decapsulation of Ethernet II
79 * and 802.3 frames within 802.11 frames so that the host doesn't have
80 * to do it itself. This driver doesn't program the card that way: the
81 * driver handles all of the encapsulation/decapsulation itself.
87 #define ANCACHE /* enable signal strength cache */
90 #include <sys/param.h>
91 #include <sys/systm.h>
92 #include <sys/sockio.h>
94 #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>
107 #include <sys/rman.h>
108 #include <sys/malloc.h>
111 #include <net/ifq_var.h>
112 #include <net/if_arp.h>
113 #include <net/ethernet.h>
114 #include <net/if_dl.h>
115 #include <net/if_types.h>
116 #include <net/if_media.h>
117 #include <netproto/802_11/ieee80211.h>
118 #include <netproto/802_11/ieee80211_ioctl.h>
121 #include <netinet/in.h>
122 #include <netinet/in_systm.h>
123 #include <netinet/in_var.h>
124 #include <netinet/ip.h>
129 #include <machine/md_var.h>
131 #include "if_aironet_ieee.h"
132 #include "if_anreg.h"
134 /* These are global because we need them in sys/pci/if_an_p.c. */
135 static void an_reset (struct an_softc *);
136 static int an_init_mpi350_desc (struct an_softc *);
137 static int an_ioctl (struct ifnet *, u_long, caddr_t,
139 static void an_init (void *);
140 static int an_init_tx_ring (struct an_softc *);
141 static void an_start (struct ifnet *, struct ifaltq_subque *);
142 static void an_watchdog (struct ifnet *);
143 static void an_rxeof (struct an_softc *);
144 static void an_txeof (struct an_softc *, int);
146 static void an_promisc (struct an_softc *, int);
147 static int an_cmd (struct an_softc *, int, int);
148 static int an_cmd_struct (struct an_softc *, struct an_command *,
150 static int an_read_record (struct an_softc *, struct an_ltv_gen *);
151 static int an_write_record (struct an_softc *, struct an_ltv_gen *);
152 static int an_read_data (struct an_softc *, int,
154 static int an_write_data (struct an_softc *, int,
156 static int an_seek (struct an_softc *, int, int, int);
157 static int an_alloc_nicmem (struct an_softc *, int, int *);
158 static int an_dma_malloc (struct an_softc *, bus_size_t,
159 struct an_dma_alloc *, int);
160 static void an_dma_free (struct an_softc *,
161 struct an_dma_alloc *);
162 static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
163 static void an_stats_update (void *);
164 static void an_setdef (struct an_softc *, struct an_req *);
166 static void an_cache_store (struct an_softc *, struct mbuf *,
170 /* function definitions for use with the Cisco's Linux configuration
174 static int readrids (struct ifnet*, struct aironet_ioctl*);
175 static int writerids (struct ifnet*, struct aironet_ioctl*);
176 static int flashcard (struct ifnet*, struct aironet_ioctl*);
178 static int cmdreset (struct ifnet *);
179 static int setflashmode (struct ifnet *);
180 static int flashgchar (struct ifnet *,int,int);
181 static int flashpchar (struct ifnet *,int,int);
182 static int flashputbuf (struct ifnet *);
183 static int flashrestart (struct ifnet *);
184 static int WaitBusy (struct ifnet *, int);
185 static int unstickbusy (struct ifnet *);
187 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
190 static int an_media_change (struct ifnet *);
191 static void an_media_status (struct ifnet *, struct ifmediareq *);
193 static int an_dump = 0;
194 static int an_cache_mode = 0;
200 static char an_conf[256];
201 static char an_conf_cache[256];
203 DECLARE_DUMMY_MODULE(if_an);
207 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
210 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
219 strcpy(an_conf, "off");
222 strcpy(an_conf, "type");
225 strcpy(an_conf, "dump");
228 ksnprintf(an_conf, 5, "%x", an_dump);
232 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
234 if (strncmp(an_conf,"off", 3) == 0) {
237 if (strncmp(an_conf,"dump", 4) == 0) {
240 if (strncmp(an_conf,"type", 4) == 0) {
246 if ((*s >= '0') && (*s <= '9')) {
247 r = r * 16 + (*s - '0');
248 } else if ((*s >= 'a') && (*s <= 'f')) {
249 r = r * 16 + (*s - 'a' + 10);
257 kprintf("Sysctl changed for Aironet driver\n");
262 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
263 0, sizeof(an_conf), sysctl_an_dump, "A", "");
266 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
270 switch (an_cache_mode) {
272 strcpy(an_conf_cache, "per");
275 strcpy(an_conf_cache, "raw");
278 strcpy(an_conf_cache, "dbm");
282 error = sysctl_handle_string(oidp, an_conf_cache,
283 sizeof(an_conf_cache), req);
285 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
288 if (strncmp(an_conf_cache,"per", 3) == 0) {
291 if (strncmp(an_conf_cache,"raw", 3) == 0) {
298 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
299 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
302 * We probe for an Aironet 4500/4800 card by attempting to
303 * read the default SSID list. On reset, the first entry in
304 * the SSID list will contain the name "tsunami." If we don't
305 * find this, then there's no card present.
308 an_probe(device_t dev)
310 struct an_softc *sc = device_get_softc(dev);
311 struct an_ltv_ssidlist_new ssid;
314 bzero((char *)&ssid, sizeof(ssid));
316 error = an_alloc_port(dev, 0, AN_IOSIZ);
320 /* can't do autoprobing */
321 if (rman_get_start(sc->port_res) == -1)
325 * We need to fake up a softc structure long enough
326 * to be able to issue commands and call some of the
329 sc->an_bhandle = rman_get_bushandle(sc->port_res);
330 sc->an_btag = rman_get_bustag(sc->port_res);
332 ssid.an_len = sizeof(ssid);
333 ssid.an_type = AN_RID_SSIDLIST;
335 /* Make sure interrupts are disabled. */
337 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
338 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
340 if_initname(&sc->arpcom.ac_if, device_get_name(dev),
341 device_get_unit(dev));
344 if (an_cmd(sc, AN_CMD_READCFG, 0))
347 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
350 /* See if the ssid matches what we expect ... but doesn't have to */
351 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID))
358 * Allocate a port resource with the given resource id.
361 an_alloc_port(device_t dev, int rid, int size)
363 struct an_softc *sc = device_get_softc(dev);
364 struct resource *res;
366 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
367 0ul, ~0ul, size, RF_ACTIVE);
378 * Allocate a memory resource with the given resource id.
381 an_alloc_memory(device_t dev, int rid, int size)
383 struct an_softc *sc = device_get_softc(dev);
384 struct resource *res;
386 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
387 0ul, ~0ul, size, RF_ACTIVE);
399 * Allocate a auxilary memory resource with the given resource id.
402 an_alloc_aux_memory(device_t dev, int rid, int size)
404 struct an_softc *sc = device_get_softc(dev);
405 struct resource *res;
407 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
408 0ul, ~0ul, size, RF_ACTIVE);
410 sc->mem_aux_rid = rid;
411 sc->mem_aux_res = res;
412 sc->mem_aux_used = size;
420 * Allocate an irq resource with the given resource id.
423 an_alloc_irq(device_t dev, int rid, int flags)
425 struct an_softc *sc = device_get_softc(dev);
426 struct resource *res;
428 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
429 (RF_ACTIVE | flags));
440 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
442 bus_addr_t *paddr = (bus_addr_t*) arg;
443 *paddr = segs->ds_addr;
447 * Alloc DMA memory and set the pointer to it
450 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
455 r = bus_dmamap_create(sc->an_dtag, 0, &dma->an_dma_map);
459 r = bus_dmamem_alloc(sc->an_dtag, (void*)&dma->an_dma_vaddr,
460 BUS_DMA_WAITOK, &dma->an_dma_map);
464 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
472 dma->an_dma_size = size;
476 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
478 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
480 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
481 dma->an_dma_map = NULL;
486 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
488 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
489 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
490 dma->an_dma_vaddr = NULL;
491 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
495 * Release all resources
498 an_release_resources(device_t dev)
500 struct an_softc *sc = device_get_softc(dev);
504 bus_release_resource(dev, SYS_RES_IOPORT,
505 sc->port_rid, sc->port_res);
509 bus_release_resource(dev, SYS_RES_MEMORY,
510 sc->mem_rid, sc->mem_res);
513 if (sc->mem_aux_res) {
514 bus_release_resource(dev, SYS_RES_MEMORY,
515 sc->mem_aux_rid, sc->mem_aux_res);
519 bus_release_resource(dev, SYS_RES_IRQ,
520 sc->irq_rid, sc->irq_res);
523 if (sc->an_rid_buffer.an_dma_paddr) {
524 an_dma_free(sc, &sc->an_rid_buffer);
526 for (i = 0; i < AN_MAX_RX_DESC; i++)
527 if (sc->an_rx_buffer[i].an_dma_paddr) {
528 an_dma_free(sc, &sc->an_rx_buffer[i]);
530 for (i = 0; i < AN_MAX_TX_DESC; i++)
531 if (sc->an_tx_buffer[i].an_dma_paddr) {
532 an_dma_free(sc, &sc->an_tx_buffer[i]);
535 bus_dma_tag_destroy(sc->an_dtag);
541 an_init_mpi350_desc(struct an_softc *sc)
543 struct an_command cmd_struct;
544 struct an_reply reply;
545 struct an_card_rid_desc an_rid_desc;
546 struct an_card_rx_desc an_rx_desc;
547 struct an_card_tx_desc an_tx_desc;
550 if(!sc->an_rid_buffer.an_dma_paddr)
551 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
552 &sc->an_rid_buffer, 0);
553 for (i = 0; i < AN_MAX_RX_DESC; i++)
554 if(!sc->an_rx_buffer[i].an_dma_paddr)
555 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
556 &sc->an_rx_buffer[i], 0);
557 for (i = 0; i < AN_MAX_TX_DESC; i++)
558 if(!sc->an_tx_buffer[i].an_dma_paddr)
559 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
560 &sc->an_tx_buffer[i], 0);
563 * Allocate RX descriptor
565 bzero(&reply,sizeof(reply));
566 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
567 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
568 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
569 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
570 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
571 if_printf(&sc->arpcom.ac_if,
572 "failed to allocate RX descriptor\n");
576 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
577 bzero(&an_rx_desc, sizeof(an_rx_desc));
578 an_rx_desc.an_valid = 1;
579 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
580 an_rx_desc.an_done = 0;
581 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
583 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
584 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
585 + (desc * sizeof(an_rx_desc))
587 ((u_int32_t*)(void *)&an_rx_desc)[i]);
591 * Allocate TX descriptor
594 bzero(&reply,sizeof(reply));
595 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
596 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
597 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
598 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
599 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
600 if_printf(&sc->arpcom.ac_if,
601 "failed to allocate TX descriptor\n");
605 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
606 bzero(&an_tx_desc, sizeof(an_tx_desc));
607 an_tx_desc.an_offset = 0;
608 an_tx_desc.an_eoc = 0;
609 an_tx_desc.an_valid = 0;
610 an_tx_desc.an_len = 0;
611 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
613 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
614 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
615 + (desc * sizeof(an_tx_desc))
617 ((u_int32_t*)(void *)&an_tx_desc)[i]);
621 * Allocate RID descriptor
624 bzero(&reply,sizeof(reply));
625 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
626 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
627 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
628 cmd_struct.an_parm2 = 1;
629 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
630 if_printf(&sc->arpcom.ac_if,
631 "failed to allocate host descriptor\n");
635 bzero(&an_rid_desc, sizeof(an_rid_desc));
636 an_rid_desc.an_valid = 1;
637 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
638 an_rid_desc.an_rid = 0;
639 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
641 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
642 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
643 ((u_int32_t*)(void *)&an_rid_desc)[i]);
649 an_attach(struct an_softc *sc, device_t dev, int flags)
651 struct ifnet *ifp = &sc->arpcom.ac_if;
654 callout_init(&sc->an_stat_timer);
655 sc->an_associated = 0;
657 sc->an_was_monitor = 0;
658 sc->an_flash_buffer = NULL;
661 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
666 error = an_init_mpi350_desc(sc);
671 /* Load factory config */
672 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
673 device_printf(dev, "failed to load config data\n");
677 /* Read the current configuration */
678 sc->an_config.an_type = AN_RID_GENCONFIG;
679 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
680 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
681 device_printf(dev, "read record failed\n");
685 /* Read the card capabilities */
686 sc->an_caps.an_type = AN_RID_CAPABILITIES;
687 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
688 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
689 device_printf(dev, "read record failed\n");
694 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
695 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
696 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
697 device_printf(dev, "read record failed\n");
702 sc->an_aplist.an_type = AN_RID_APLIST;
703 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
704 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
705 device_printf(dev, "read record failed\n");
710 /* Read the RSSI <-> dBm map */
711 sc->an_have_rssimap = 0;
712 if (sc->an_caps.an_softcaps & 8) {
713 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
714 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
715 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
716 device_printf(dev, "unable to get RSSI <-> dBM map\n");
718 device_printf(dev, "got RSSI <-> dBM map\n");
719 sc->an_have_rssimap = 1;
722 device_printf(dev, "no RSSI <-> dBM map\n");
726 ifp->if_mtu = ETHERMTU;
727 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
728 ifp->if_ioctl = an_ioctl;
729 ifp->if_start = an_start;
730 ifp->if_watchdog = an_watchdog;
731 ifp->if_init = an_init;
732 ifp->if_baudrate = 10000000;
733 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
734 ifq_set_ready(&ifp->if_snd);
736 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
737 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
738 sizeof(AN_DEFAULT_NODENAME) - 1);
740 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
741 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
742 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
743 sizeof(AN_DEFAULT_NETNAME) - 1);
744 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
746 sc->an_config.an_opmode =
747 AN_OPMODE_INFRASTRUCTURE_STATION;
750 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
752 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
753 #define ADD(m, c) ifmedia_add(&sc->an_ifmedia, (m), (c), NULL)
754 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
755 IFM_IEEE80211_ADHOC, 0), 0);
756 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
757 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
758 IFM_IEEE80211_ADHOC, 0), 0);
759 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
760 if (sc->an_caps.an_rates[2] == AN_RATE_5_5MBPS) {
761 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
762 IFM_IEEE80211_ADHOC, 0), 0);
763 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
765 if (sc->an_caps.an_rates[3] == AN_RATE_11MBPS) {
766 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
767 IFM_IEEE80211_ADHOC, 0), 0);
768 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
770 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
771 IFM_IEEE80211_ADHOC, 0), 0);
772 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
774 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
778 * Call MI attach routine.
780 ether_ifattach(ifp, sc->an_caps.an_oemaddr, NULL);
786 an_detach(device_t dev)
788 struct an_softc *sc = device_get_softc(dev);
789 struct ifnet *ifp = &sc->arpcom.ac_if;
791 lwkt_serialize_enter(ifp->if_serializer);
793 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
794 lwkt_serialize_exit(ifp->if_serializer);
796 ifmedia_removeall(&sc->an_ifmedia);
798 an_release_resources(dev);
803 an_rxeof(struct an_softc *sc)
806 struct ether_header *eh;
807 struct ieee80211_frame *ih;
808 struct an_rxframe rx_frame;
809 struct an_rxframe_802_3 rx_frame_802_3;
811 int len, id, error = 0, i, count = 0;
812 int ieee80211_header_len;
815 struct an_card_rx_desc an_rx_desc;
818 ifp = &sc->arpcom.ac_if;
821 id = CSR_READ_2(sc, AN_RX_FID);
823 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
824 /* read raw 802.11 packet */
825 bpf_buf = sc->buf_802_11;
828 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
830 IFNET_STAT_INC(ifp, ierrors, 1);
835 * skip beacon by default since this increases the
839 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
840 (rx_frame.an_frame_ctl &
841 IEEE80211_FC0_SUBTYPE_BEACON)) {
845 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
846 len = rx_frame.an_rx_payload_len
848 /* Check for insane frame length */
849 if (len > sizeof(sc->buf_802_11)) {
851 "oversized packet received "
852 "(%d, %d)\n", len, MCLBYTES);
853 IFNET_STAT_INC(ifp, ierrors, 1);
857 bcopy((char *)&rx_frame,
858 bpf_buf, sizeof(rx_frame));
860 error = an_read_data(sc, id, sizeof(rx_frame),
861 (caddr_t)bpf_buf+sizeof(rx_frame),
862 rx_frame.an_rx_payload_len);
864 fc1=rx_frame.an_frame_ctl >> 8;
865 ieee80211_header_len =
866 sizeof(struct ieee80211_frame);
867 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
868 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
869 ieee80211_header_len += ETHER_ADDR_LEN;
872 len = rx_frame.an_rx_payload_len
873 + ieee80211_header_len;
874 /* Check for insane frame length */
875 if (len > sizeof(sc->buf_802_11)) {
877 "oversized packet received "
878 "(%d, %d)\n", len, MCLBYTES);
879 IFNET_STAT_INC(ifp, ierrors, 1);
883 ih = (struct ieee80211_frame *)bpf_buf;
885 bcopy((char *)&rx_frame.an_frame_ctl,
886 (char *)ih, ieee80211_header_len);
888 error = an_read_data(sc, id, sizeof(rx_frame) +
890 (caddr_t)ih +ieee80211_header_len,
891 rx_frame.an_rx_payload_len);
893 BPF_TAP(ifp, bpf_buf, len);
895 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
897 IFNET_STAT_INC(ifp, ierrors, 1);
900 m->m_pkthdr.rcvif = ifp;
901 /* Read Ethernet encapsulated packet */
904 /* Read NIC frame header */
905 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
907 IFNET_STAT_INC(ifp, ierrors, 1);
911 /* Read in the 802_3 frame header */
912 if (an_read_data(sc, id, 0x34,
913 (caddr_t)&rx_frame_802_3,
914 sizeof(rx_frame_802_3))) {
915 IFNET_STAT_INC(ifp, ierrors, 1);
918 if (rx_frame_802_3.an_rx_802_3_status != 0) {
919 IFNET_STAT_INC(ifp, ierrors, 1);
922 /* Check for insane frame length */
923 len = rx_frame_802_3.an_rx_802_3_payload_len;
924 if (len > sizeof(sc->buf_802_11)) {
926 "oversized packet received (%d, %d)\n",
928 IFNET_STAT_INC(ifp, ierrors, 1);
931 m->m_pkthdr.len = m->m_len =
932 rx_frame_802_3.an_rx_802_3_payload_len + 12;
934 eh = mtod(m, struct ether_header *);
936 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
937 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
938 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
939 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
941 /* in mbuf header type is just before payload */
942 error = an_read_data(sc, id, 0x44,
943 (caddr_t)&(eh->ether_type),
944 rx_frame_802_3.an_rx_802_3_payload_len);
948 IFNET_STAT_INC(ifp, ierrors, 1);
951 IFNET_STAT_INC(ifp, ipackets, 1);
954 an_cache_store(sc, m,
955 rx_frame.an_rx_signal_strength,
958 ifp->if_input(ifp, m);
961 } else { /* MPI-350 */
962 for (count = 0; count < AN_MAX_RX_DESC; count++){
963 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
964 ((u_int32_t*)(void *)&an_rx_desc)[i]
965 = CSR_MEM_AUX_READ_4(sc,
967 + (count * sizeof(an_rx_desc))
970 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
971 buf = sc->an_rx_buffer[count].an_dma_vaddr;
973 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
975 IFNET_STAT_INC(ifp, ierrors, 1);
978 m->m_pkthdr.rcvif = ifp;
979 /* Read Ethernet encapsulated packet */
982 * No ANCACHE support since we just get back
983 * an Ethernet packet no 802.11 info
987 /* Read NIC frame header */
988 bcopy(buf, (caddr_t)&rx_frame,
992 /* Check for insane frame length */
993 len = an_rx_desc.an_len + 12;
994 if (len > MCLBYTES) {
996 "oversized packet received "
997 "(%d, %d)\n", len, MCLBYTES);
998 IFNET_STAT_INC(ifp, ierrors, 1);
1002 m->m_pkthdr.len = m->m_len =
1003 an_rx_desc.an_len + 12;
1005 eh = mtod(m, struct ether_header *);
1007 bcopy(buf, (char *)eh,
1010 IFNET_STAT_INC(ifp, ipackets, 1);
1014 an_cache_store(sc, m,
1015 rx_frame.an_rx_signal_strength,
1019 ifp->if_input(ifp, m);
1021 an_rx_desc.an_valid = 1;
1022 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1023 an_rx_desc.an_done = 0;
1024 an_rx_desc.an_phys =
1025 sc->an_rx_buffer[count].an_dma_paddr;
1027 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1028 CSR_MEM_AUX_WRITE_4(sc,
1030 + (count * sizeof(an_rx_desc))
1032 ((u_int32_t*)(void *)&an_rx_desc)[i]);
1035 if_printf(ifp, "Didn't get valid RX packet "
1038 an_rx_desc.an_valid,
1046 an_txeof(struct an_softc *sc, int status)
1051 ifp = &sc->arpcom.ac_if;
1054 ifq_clr_oactive(&ifp->if_snd);
1057 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1059 if (status & AN_EV_TX_EXC) {
1060 IFNET_STAT_INC(ifp, oerrors, 1);
1062 IFNET_STAT_INC(ifp, opackets, 1);
1064 for (i = 0; i < AN_TX_RING_CNT; i++) {
1065 if (id == sc->an_rdata.an_tx_ring[i]) {
1066 sc->an_rdata.an_tx_ring[i] = 0;
1071 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1072 } else { /* MPI 350 */
1073 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1074 if (!sc->an_rdata.an_tx_empty){
1075 if (status & AN_EV_TX_EXC) {
1076 IFNET_STAT_INC(ifp, oerrors, 1);
1078 IFNET_STAT_INC(ifp, opackets, 1);
1079 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1080 if (sc->an_rdata.an_tx_prod ==
1081 sc->an_rdata.an_tx_cons)
1082 sc->an_rdata.an_tx_empty = 1;
1088 * We abuse the stats updater to check the current NIC status. This
1089 * is important because we don't want to allow transmissions until
1090 * the NIC has synchronized to the current cell (either as the master
1091 * in an ad-hoc group, or as a station connected to an access point).
1094 an_stats_update(void *xsc)
1096 struct an_softc *sc;
1100 ifp = &sc->arpcom.ac_if;
1102 lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer);
1104 sc->an_status.an_type = AN_RID_STATUS;
1105 sc->an_status.an_len = sizeof(struct an_ltv_status);
1106 an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
1108 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1109 sc->an_associated = 1;
1111 sc->an_associated = 0;
1113 /* Don't do this while we're not transmitting */
1114 if (!ifq_is_oactive(&ifp->if_snd)) {
1115 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1116 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1117 an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
1120 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
1122 lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer);
1128 struct an_softc *sc;
1132 sc = (struct an_softc*)xsc;
1134 ifp = &sc->arpcom.ac_if;
1136 /* Disable interrupts. */
1137 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1139 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1140 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1142 if (status & AN_EV_MIC)
1143 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1145 if (status & AN_EV_LINKSTAT) {
1146 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1147 == AN_LINKSTAT_ASSOCIATED)
1148 sc->an_associated = 1;
1150 sc->an_associated = 0;
1151 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1154 if (status & AN_EV_RX) {
1156 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1159 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1160 an_txeof(sc, status);
1161 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1164 if (status & AN_EV_TX) {
1165 an_txeof(sc, status);
1166 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1169 if (status & AN_EV_TX_EXC) {
1170 an_txeof(sc, status);
1171 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1174 if (status & AN_EV_ALLOC)
1175 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1177 /* Re-enable interrupts. */
1178 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1180 if ((ifp->if_flags & IFF_UP) && !ifq_is_empty(&ifp->if_snd))
1185 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1186 struct an_reply *reply)
1190 for (i = 0; i != AN_TIMEOUT; i++) {
1191 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1196 if( i == AN_TIMEOUT) {
1201 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1202 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1203 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1204 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1206 for (i = 0; i < AN_TIMEOUT; i++) {
1207 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1212 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1213 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1214 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1215 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1217 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1218 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1220 /* Ack the command */
1221 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1223 if (i == AN_TIMEOUT)
1230 an_cmd(struct an_softc *sc, int cmd, int val)
1234 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1235 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1236 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1237 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1239 for (i = 0; i < AN_TIMEOUT; i++) {
1240 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1243 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1244 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1248 for (i = 0; i < AN_TIMEOUT; i++) {
1249 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1250 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1251 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1252 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1253 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1257 /* Ack the command */
1258 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1260 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1261 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1263 if (i == AN_TIMEOUT)
1270 * This reset sequence may look a little strange, but this is the
1271 * most reliable method I've found to really kick the NIC in the
1272 * head and force it to reboot correctly.
1275 an_reset(struct an_softc *sc)
1277 an_cmd(sc, AN_CMD_ENABLE, 0);
1278 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1279 an_cmd(sc, AN_CMD_NOOP2, 0);
1281 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1282 if_printf(&sc->arpcom.ac_if, "reset failed\n");
1284 an_cmd(sc, AN_CMD_DISABLE, 0);
1290 * Read an LTV record from the NIC.
1293 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1295 struct an_ltv_gen *an_ltv;
1296 struct an_card_rid_desc an_rid_desc;
1297 struct an_command cmd;
1298 struct an_reply reply;
1303 if (ltv->an_len < 4 || ltv->an_type == 0)
1307 /* Tell the NIC to enter record read mode. */
1308 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1309 if_printf(&sc->arpcom.ac_if, "RID access failed\n");
1313 /* Seek to the record. */
1314 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1315 if_printf(&sc->arpcom.ac_if, "seek to record failed\n");
1320 * Read the length and record type and make sure they
1321 * match what we expect (this verifies that we have enough
1322 * room to hold all of the returned data).
1323 * Length includes type but not length.
1325 len = CSR_READ_2(sc, AN_DATA1);
1326 if (len > (ltv->an_len - 2)) {
1327 if_printf(&sc->arpcom.ac_if,
1328 "record length mismatch -- expected %d, "
1329 "got %d for Rid %x\n",
1330 ltv->an_len - 2, len, ltv->an_type);
1331 len = ltv->an_len - 2;
1333 ltv->an_len = len + 2;
1336 /* Now read the data. */
1337 len -= 2; /* skip the type */
1339 for (i = len; i > 1; i -= 2)
1340 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1342 ptr2 = (u_int8_t *)ptr;
1343 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1345 } else { /* MPI-350 */
1346 if (sc->an_rid_buffer.an_dma_vaddr == NULL)
1348 an_rid_desc.an_valid = 1;
1349 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1350 an_rid_desc.an_rid = 0;
1351 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1352 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1354 bzero(&cmd, sizeof(cmd));
1355 bzero(&reply, sizeof(reply));
1356 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1357 cmd.an_parm0 = ltv->an_type;
1359 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1360 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1361 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1363 if (an_cmd_struct(sc, &cmd, &reply)
1364 || reply.an_status & AN_CMD_QUAL_MASK) {
1365 if_printf(&sc->arpcom.ac_if,
1366 "failed to read RID %x %x %x %x %x, %d\n",
1376 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1377 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1378 an_rid_desc.an_len = an_ltv->an_len;
1381 len = an_rid_desc.an_len;
1382 if (len > (ltv->an_len - 2)) {
1383 if_printf(&sc->arpcom.ac_if,
1384 "record length mismatch -- expected %d, "
1385 "got %d for Rid %x\n",
1386 ltv->an_len - 2, len, ltv->an_type);
1387 len = ltv->an_len - 2;
1389 ltv->an_len = len + 2;
1391 bcopy(&an_ltv->an_type, <v->an_val, len);
1395 an_dump_record(sc, ltv, "Read");
1401 * Same as read, except we inject data instead of reading it.
1404 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1406 struct an_card_rid_desc an_rid_desc;
1407 struct an_command cmd;
1408 struct an_reply reply;
1414 an_dump_record(sc, ltv, "Write");
1417 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1420 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1424 * Length includes type but not length.
1426 len = ltv->an_len - 2;
1427 CSR_WRITE_2(sc, AN_DATA1, len);
1429 len -= 2; /* skip the type */
1431 for (i = len; i > 1; i -= 2)
1432 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1434 ptr2 = (u_int8_t *)ptr;
1435 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1438 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1443 for (i = 0; i != AN_TIMEOUT; i++) {
1444 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1450 if (i == AN_TIMEOUT) {
1454 an_rid_desc.an_valid = 1;
1455 an_rid_desc.an_len = ltv->an_len - 2;
1456 an_rid_desc.an_rid = ltv->an_type;
1457 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1459 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1460 an_rid_desc.an_len);
1462 bzero(&cmd,sizeof(cmd));
1463 bzero(&reply,sizeof(reply));
1464 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1465 cmd.an_parm0 = ltv->an_type;
1467 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1468 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1469 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1471 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1472 if_printf(&sc->arpcom.ac_if,
1473 "failed to write RID 1 %x %x %x %x %x, %d\n",
1483 if (reply.an_status & AN_CMD_QUAL_MASK) {
1484 if_printf(&sc->arpcom.ac_if,
1485 "failed to write RID 2 %x %x %x %x %x, %d\n",
1500 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1508 len = ltv->an_len - 4;
1509 if_printf(&sc->arpcom.ac_if, "RID %4x, Length %4d, Mode %s\n",
1510 ltv->an_type, ltv->an_len - 4, string);
1512 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1513 if_printf(&sc->arpcom.ac_if, "\t");
1514 bzero(buf,sizeof(buf));
1516 ptr2 = (u_int8_t *)<v->an_val;
1517 for (i = len; i > 0; i--) {
1518 kprintf("%02x ", *ptr2);
1521 if (temp >= ' ' && temp <= '~')
1523 else if (temp >= 'A' && temp <= 'Z')
1527 if (++count == 16) {
1529 kprintf("%s\n",buf);
1530 if_printf(&sc->arpcom.ac_if, "\t");
1531 bzero(buf,sizeof(buf));
1534 for (; count != 16; count++) {
1537 kprintf(" %s\n",buf);
1542 an_seek(struct an_softc *sc, int id, int off, int chan)
1557 if_printf(&sc->arpcom.ac_if, "invalid data path: %x\n", chan);
1561 CSR_WRITE_2(sc, selreg, id);
1562 CSR_WRITE_2(sc, offreg, off);
1564 for (i = 0; i < AN_TIMEOUT; i++) {
1565 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1569 if (i == AN_TIMEOUT)
1576 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1583 if (an_seek(sc, id, off, AN_BAP1))
1587 ptr = (u_int16_t *)buf;
1588 for (i = len; i > 1; i -= 2)
1589 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1591 ptr2 = (u_int8_t *)ptr;
1592 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1599 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1606 if (an_seek(sc, id, off, AN_BAP0))
1610 ptr = (u_int16_t *)buf;
1611 for (i = len; i > 1; i -= 2)
1612 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1614 ptr2 = (u_int8_t *)ptr;
1615 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1622 * Allocate a region of memory inside the NIC and zero
1626 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1630 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1631 if_printf(&sc->arpcom.ac_if,
1632 "failed to allocate %d bytes on NIC\n", len);
1636 for (i = 0; i < AN_TIMEOUT; i++) {
1637 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1641 if (i == AN_TIMEOUT)
1644 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1645 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1647 if (an_seek(sc, *id, 0, AN_BAP0))
1650 for (i = 0; i < len / 2; i++)
1651 CSR_WRITE_2(sc, AN_DATA0, 0);
1657 an_setdef(struct an_softc *sc, struct an_req *areq)
1660 struct an_ltv_genconfig *cfg;
1661 struct an_ltv_ssidlist_new *ssid;
1662 struct an_ltv_aplist *ap;
1663 struct an_ltv_gen *sp;
1665 ifp = &sc->arpcom.ac_if;
1667 switch (areq->an_type) {
1668 case AN_RID_GENCONFIG:
1669 cfg = (struct an_ltv_genconfig *)areq;
1671 bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
1673 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
1675 bcopy((char *)cfg, (char *)&sc->an_config,
1676 sizeof(struct an_ltv_genconfig));
1678 case AN_RID_SSIDLIST:
1679 ssid = (struct an_ltv_ssidlist_new *)areq;
1680 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1681 sizeof(struct an_ltv_ssidlist_new));
1684 ap = (struct an_ltv_aplist *)areq;
1685 bcopy((char *)ap, (char *)&sc->an_aplist,
1686 sizeof(struct an_ltv_aplist));
1688 case AN_RID_TX_SPEED:
1689 sp = (struct an_ltv_gen *)areq;
1690 sc->an_tx_rate = sp->an_val;
1692 /* Read the current configuration */
1693 sc->an_config.an_type = AN_RID_GENCONFIG;
1694 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1695 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1696 cfg = &sc->an_config;
1698 /* clear other rates and set the only one we want */
1699 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1700 cfg->an_rates[0] = sc->an_tx_rate;
1702 /* Save the new rate */
1703 sc->an_config.an_type = AN_RID_GENCONFIG;
1704 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1706 case AN_RID_WEP_TEMP:
1707 /* Cache the temp keys */
1709 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1710 sizeof(struct an_ltv_key));
1711 case AN_RID_WEP_PERM:
1712 case AN_RID_LEAPUSERNAME:
1713 case AN_RID_LEAPPASSWORD:
1716 /* Disable the MAC. */
1717 an_cmd(sc, AN_CMD_DISABLE, 0);
1720 an_write_record(sc, (struct an_ltv_gen *)areq);
1722 /* Turn the MAC back on. */
1723 an_cmd(sc, AN_CMD_ENABLE, 0);
1726 case AN_RID_MONITOR_MODE:
1727 cfg = (struct an_ltv_genconfig *)areq;
1729 if (ng_ether_detach_p != NULL)
1730 (*ng_ether_detach_p) (ifp);
1731 sc->an_monitor = cfg->an_len;
1733 if (sc->an_monitor & AN_MONITOR) {
1734 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1735 bpfattach(ifp, DLT_AIRONET_HEADER,
1736 sizeof(struct ether_header));
1738 bpfattach(ifp, DLT_IEEE802_11,
1739 sizeof(struct ether_header));
1742 bpfattach(ifp, DLT_EN10MB,
1743 sizeof(struct ether_header));
1744 if (ng_ether_attach_p != NULL)
1745 (*ng_ether_attach_p) (ifp);
1749 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1754 /* Reinitialize the card. */
1762 * Derived from Linux driver to enable promiscious mode.
1766 an_promisc(struct an_softc *sc, int promisc)
1768 if (sc->an_was_monitor)
1771 an_init_mpi350_desc(sc);
1772 if (sc->an_monitor || sc->an_was_monitor)
1775 sc->an_was_monitor = sc->an_monitor;
1776 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1782 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
1787 struct an_softc *sc;
1789 struct ieee80211req *ireq;
1790 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1792 struct an_ltv_genconfig *config;
1793 struct an_ltv_key *key;
1794 struct an_ltv_status *status;
1795 struct an_ltv_ssidlist_new *ssids;
1797 struct aironet_ioctl l_ioctl;
1800 ifr = (struct ifreq *)data;
1801 ireq = (struct ieee80211req *)data;
1803 config = (struct an_ltv_genconfig *)&sc->areq;
1804 key = (struct an_ltv_key *)&sc->areq;
1805 status = (struct an_ltv_status *)&sc->areq;
1806 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1810 if (ifp->if_flags & IFF_UP) {
1811 if (ifp->if_flags & IFF_RUNNING &&
1812 ifp->if_flags & IFF_PROMISC &&
1813 !(sc->an_if_flags & IFF_PROMISC)) {
1815 } else if (ifp->if_flags & IFF_RUNNING &&
1816 !(ifp->if_flags & IFF_PROMISC) &&
1817 sc->an_if_flags & IFF_PROMISC) {
1822 if (ifp->if_flags & IFF_RUNNING)
1825 sc->an_if_flags = ifp->if_flags;
1830 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1834 /* The Aironet has no multicast filter. */
1838 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1842 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1843 error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY);
1846 sc->an_sigitems = sc->an_nextitem = 0;
1848 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1849 char *pt = (char *)&sc->areq.an_val;
1850 bcopy((char *)&sc->an_sigitems, (char *)pt,
1853 sc->areq.an_len = sizeof(int) / 2;
1854 bcopy((char *)&sc->an_sigcache, (char *)pt,
1855 sizeof(struct an_sigcache) * sc->an_sigitems);
1856 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1857 sc->an_sigitems) / 2) + 1;
1860 if (an_read_record(sc, (struct an_ltv_gen *)(void *)&sc->areq)) {
1864 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1867 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
1869 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1872 an_setdef(sc, &sc->areq);
1874 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1875 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
1877 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1878 mode = l_ioctl.command;
1880 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1881 error = readrids(ifp, &l_ioctl);
1882 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1883 error = writerids(ifp, &l_ioctl);
1884 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1885 error = flashcard(ifp, &l_ioctl);
1890 /* copy out the updated command info */
1891 copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1894 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1895 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
1897 copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1898 l_ioctl.command = 0;
1900 copyout(&error, l_ioctl.data, sizeof(error));
1904 sc->areq.an_len = sizeof(sc->areq);
1905 /* was that a good idea DJA we are doing a short-cut */
1906 switch (ireq->i_type) {
1907 case IEEE80211_IOC_SSID:
1908 if (ireq->i_val == -1) {
1909 sc->areq.an_type = AN_RID_STATUS;
1910 if (an_read_record(sc,
1911 (struct an_ltv_gen *)(void *)&sc->areq)) {
1915 len = status->an_ssidlen;
1916 tmpptr = status->an_ssid;
1917 } else if (ireq->i_val >= 0) {
1918 sc->areq.an_type = AN_RID_SSIDLIST;
1919 if (an_read_record(sc,
1920 (struct an_ltv_gen *)(void *)&sc->areq)) {
1924 max = (sc->areq.an_len - 4)
1925 / sizeof(struct an_ltv_ssid_entry);
1926 if ( max > MAX_SSIDS ) {
1927 kprintf("To many SSIDs only using "
1932 if (ireq->i_val > max) {
1936 len = ssids->an_entry[ireq->i_val].an_len;
1937 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
1943 if (len > IEEE80211_NWID_LEN) {
1948 bzero(tmpstr, IEEE80211_NWID_LEN);
1949 bcopy(tmpptr, tmpstr, len);
1950 error = copyout(tmpstr, ireq->i_data,
1951 IEEE80211_NWID_LEN);
1953 case IEEE80211_IOC_NUMSSIDS:
1954 sc->areq.an_len = sizeof(sc->areq);
1955 sc->areq.an_type = AN_RID_SSIDLIST;
1956 if (an_read_record(sc,
1957 (struct an_ltv_gen *)(void *)&sc->areq)) {
1961 max = (sc->areq.an_len - 4)
1962 / sizeof(struct an_ltv_ssid_entry);
1963 if (max > MAX_SSIDS) {
1964 kprintf("To many SSIDs only using "
1971 case IEEE80211_IOC_WEP:
1972 sc->areq.an_type = AN_RID_ACTUALCFG;
1973 if (an_read_record(sc,
1974 (struct an_ltv_gen *)(void *)&sc->areq)) {
1978 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
1979 if (config->an_authtype &
1980 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
1981 ireq->i_val = IEEE80211_WEP_MIXED;
1983 ireq->i_val = IEEE80211_WEP_ON;
1985 ireq->i_val = IEEE80211_WEP_OFF;
1988 case IEEE80211_IOC_WEPKEY:
1990 * XXX: I'm not entierly convinced this is
1991 * correct, but it's what is implemented in
1992 * ancontrol so it will have to do until we get
1993 * access to actual Cisco code.
1995 if (ireq->i_val < 0 || ireq->i_val > 8) {
2000 if (ireq->i_val < 5) {
2001 sc->areq.an_type = AN_RID_WEP_TEMP;
2002 for (i = 0; i < 5; i++) {
2003 if (an_read_record(sc,
2004 (struct an_ltv_gen *)(void *)&sc->areq)) {
2008 if (key->kindex == 0xffff)
2010 if (key->kindex == ireq->i_val)
2012 /* Required to get next entry */
2013 sc->areq.an_type = AN_RID_WEP_PERM;
2018 /* We aren't allowed to read the value of the
2019 * key from the card so we just output zeros
2020 * like we would if we could read the card, but
2021 * denied the user access.
2025 error = copyout(tmpstr, ireq->i_data, len);
2027 case IEEE80211_IOC_NUMWEPKEYS:
2028 ireq->i_val = 9; /* include home key */
2030 case IEEE80211_IOC_WEPTXKEY:
2032 * For some strange reason, you have to read all
2033 * keys before you can read the txkey.
2035 sc->areq.an_type = AN_RID_WEP_TEMP;
2036 for (i = 0; i < 5; i++) {
2037 if (an_read_record(sc,
2038 (struct an_ltv_gen *)(void *)&sc->areq)) {
2042 if (key->kindex == 0xffff)
2044 /* Required to get next entry */
2045 sc->areq.an_type = AN_RID_WEP_PERM;
2050 sc->areq.an_type = AN_RID_WEP_PERM;
2051 key->kindex = 0xffff;
2052 if (an_read_record(sc,
2053 (struct an_ltv_gen *)(void *)&sc->areq)) {
2057 ireq->i_val = key->mac[0];
2059 * Check for home mode. Map home mode into
2060 * 5th key since that is how it is stored on
2063 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2064 sc->areq.an_type = AN_RID_GENCONFIG;
2065 if (an_read_record(sc,
2066 (struct an_ltv_gen *)(void *)&sc->areq)) {
2070 if (config->an_home_product & AN_HOME_NETWORK)
2073 case IEEE80211_IOC_AUTHMODE:
2074 sc->areq.an_type = AN_RID_ACTUALCFG;
2075 if (an_read_record(sc,
2076 (struct an_ltv_gen *)(void *)&sc->areq)) {
2080 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2082 ireq->i_val = IEEE80211_AUTH_NONE;
2083 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2085 ireq->i_val = IEEE80211_AUTH_OPEN;
2086 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2087 AN_AUTHTYPE_SHAREDKEY) {
2088 ireq->i_val = IEEE80211_AUTH_SHARED;
2092 case IEEE80211_IOC_STATIONNAME:
2093 sc->areq.an_type = AN_RID_ACTUALCFG;
2094 if (an_read_record(sc,
2095 (struct an_ltv_gen *)(void *)&sc->areq)) {
2099 ireq->i_len = sizeof(config->an_nodename);
2100 tmpptr = config->an_nodename;
2101 bzero(tmpstr, IEEE80211_NWID_LEN);
2102 bcopy(tmpptr, tmpstr, ireq->i_len);
2103 error = copyout(tmpstr, ireq->i_data,
2104 IEEE80211_NWID_LEN);
2106 case IEEE80211_IOC_CHANNEL:
2107 sc->areq.an_type = AN_RID_STATUS;
2108 if (an_read_record(sc,
2109 (struct an_ltv_gen *)(void *)&sc->areq)) {
2113 ireq->i_val = status->an_cur_channel;
2115 case IEEE80211_IOC_POWERSAVE:
2116 sc->areq.an_type = AN_RID_ACTUALCFG;
2117 if (an_read_record(sc,
2118 (struct an_ltv_gen *)(void *)&sc->areq)) {
2122 if (config->an_psave_mode == AN_PSAVE_NONE) {
2123 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2124 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2125 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2126 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2127 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2128 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2129 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2133 case IEEE80211_IOC_POWERSAVESLEEP:
2134 sc->areq.an_type = AN_RID_ACTUALCFG;
2135 if (an_read_record(sc,
2136 (struct an_ltv_gen *)(void *)&sc->areq)) {
2140 ireq->i_val = config->an_listen_interval;
2145 if ((error = priv_check_cred(cr, PRIV_ROOT, NULL_CRED_OKAY)))
2147 sc->areq.an_len = sizeof(sc->areq);
2149 * We need a config structure for everything but the WEP
2150 * key management and SSIDs so we get it now so avoid
2151 * duplicating this code every time.
2153 if (ireq->i_type != IEEE80211_IOC_SSID &&
2154 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2155 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2156 sc->areq.an_type = AN_RID_GENCONFIG;
2157 if (an_read_record(sc,
2158 (struct an_ltv_gen *)(void *)&sc->areq)) {
2163 switch (ireq->i_type) {
2164 case IEEE80211_IOC_SSID:
2165 sc->areq.an_len = sizeof(sc->areq);
2166 sc->areq.an_type = AN_RID_SSIDLIST;
2167 if (an_read_record(sc,
2168 (struct an_ltv_gen *)(void *)&sc->areq)) {
2172 if (ireq->i_len > IEEE80211_NWID_LEN) {
2176 max = (sc->areq.an_len - 4)
2177 / sizeof(struct an_ltv_ssid_entry);
2178 if (max > MAX_SSIDS) {
2179 kprintf("To many SSIDs only using "
2184 if (ireq->i_val > max) {
2188 error = copyin(ireq->i_data,
2189 ssids->an_entry[ireq->i_val].an_ssid,
2191 ssids->an_entry[ireq->i_val].an_len
2196 case IEEE80211_IOC_WEP:
2197 switch (ireq->i_val) {
2198 case IEEE80211_WEP_OFF:
2199 config->an_authtype &=
2200 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2201 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2203 case IEEE80211_WEP_ON:
2204 config->an_authtype |=
2205 AN_AUTHTYPE_PRIVACY_IN_USE;
2206 config->an_authtype &=
2207 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2209 case IEEE80211_WEP_MIXED:
2210 config->an_authtype |=
2211 AN_AUTHTYPE_PRIVACY_IN_USE |
2212 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2219 case IEEE80211_IOC_WEPKEY:
2220 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2225 error = copyin(ireq->i_data, tmpstr, 13);
2229 * Map the 9th key into the home mode
2230 * since that is how it is stored on
2233 bzero(&sc->areq, sizeof(struct an_ltv_key));
2234 sc->areq.an_len = sizeof(struct an_ltv_key);
2235 key->mac[0] = 1; /* The others are 0. */
2236 if (ireq->i_val < 4) {
2237 sc->areq.an_type = AN_RID_WEP_TEMP;
2238 key->kindex = ireq->i_val;
2240 sc->areq.an_type = AN_RID_WEP_PERM;
2241 key->kindex = ireq->i_val - 4;
2243 key->klen = ireq->i_len;
2244 bcopy(tmpstr, key->key, key->klen);
2246 case IEEE80211_IOC_WEPTXKEY:
2247 if (ireq->i_val < 0 || ireq->i_val > 4) {
2253 * Map the 5th key into the home mode
2254 * since that is how it is stored on
2257 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2258 sc->areq.an_type = AN_RID_ACTUALCFG;
2259 if (an_read_record(sc,
2260 (struct an_ltv_gen *)(void *)&sc->areq)) {
2264 if (ireq->i_val == 4) {
2265 config->an_home_product |= AN_HOME_NETWORK;
2268 config->an_home_product &= ~AN_HOME_NETWORK;
2271 sc->an_config.an_home_product
2272 = config->an_home_product;
2274 /* update configuration */
2277 bzero(&sc->areq, sizeof(struct an_ltv_key));
2278 sc->areq.an_len = sizeof(struct an_ltv_key);
2279 sc->areq.an_type = AN_RID_WEP_PERM;
2280 key->kindex = 0xffff;
2281 key->mac[0] = ireq->i_val;
2283 case IEEE80211_IOC_AUTHMODE:
2284 switch (ireq->i_val) {
2285 case IEEE80211_AUTH_NONE:
2286 config->an_authtype = AN_AUTHTYPE_NONE |
2287 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2289 case IEEE80211_AUTH_OPEN:
2290 config->an_authtype = AN_AUTHTYPE_OPEN |
2291 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2293 case IEEE80211_AUTH_SHARED:
2294 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2295 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2301 case IEEE80211_IOC_STATIONNAME:
2302 if (ireq->i_len > 16) {
2306 bzero(config->an_nodename, 16);
2307 error = copyin(ireq->i_data,
2308 config->an_nodename, ireq->i_len);
2310 case IEEE80211_IOC_CHANNEL:
2312 * The actual range is 1-14, but if you set it
2313 * to 0 you get the default so we let that work
2316 if (ireq->i_val < 0 || ireq->i_val >14) {
2320 config->an_ds_channel = ireq->i_val;
2322 case IEEE80211_IOC_POWERSAVE:
2323 switch (ireq->i_val) {
2324 case IEEE80211_POWERSAVE_OFF:
2325 config->an_psave_mode = AN_PSAVE_NONE;
2327 case IEEE80211_POWERSAVE_CAM:
2328 config->an_psave_mode = AN_PSAVE_CAM;
2330 case IEEE80211_POWERSAVE_PSP:
2331 config->an_psave_mode = AN_PSAVE_PSP;
2333 case IEEE80211_POWERSAVE_PSP_CAM:
2334 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2341 case IEEE80211_IOC_POWERSAVESLEEP:
2342 config->an_listen_interval = ireq->i_val;
2347 an_setdef(sc, &sc->areq);
2350 error = ether_ioctl(ifp, command, data);
2358 an_init_tx_ring(struct an_softc *sc)
2364 for (i = 0; i < AN_TX_RING_CNT; i++) {
2365 if (an_alloc_nicmem(sc, 1518 +
2368 sc->an_rdata.an_tx_fids[i] = id;
2369 sc->an_rdata.an_tx_ring[i] = 0;
2373 sc->an_rdata.an_tx_prod = 0;
2374 sc->an_rdata.an_tx_cons = 0;
2375 sc->an_rdata.an_tx_empty = 1;
2383 struct an_softc *sc = xsc;
2384 struct ifnet *ifp = &sc->arpcom.ac_if;
2386 if (ifp->if_flags & IFF_RUNNING)
2389 sc->an_associated = 0;
2391 /* Allocate the TX buffers */
2392 if (an_init_tx_ring(sc)) {
2395 an_init_mpi350_desc(sc);
2396 if (an_init_tx_ring(sc)) {
2397 if_printf(ifp, "tx buffer allocation failed\n");
2402 /* Set our MAC address. */
2403 bcopy((char *)&sc->arpcom.ac_enaddr,
2404 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2406 if (ifp->if_flags & IFF_BROADCAST)
2407 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2409 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2411 if (ifp->if_flags & IFF_MULTICAST)
2412 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2414 if (ifp->if_flags & IFF_PROMISC) {
2415 if (sc->an_monitor & AN_MONITOR) {
2416 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2417 sc->an_config.an_rxmode |=
2418 AN_RXMODE_80211_MONITOR_ANYBSS |
2419 AN_RXMODE_NO_8023_HEADER;
2421 sc->an_config.an_rxmode |=
2422 AN_RXMODE_80211_MONITOR_CURBSS |
2423 AN_RXMODE_NO_8023_HEADER;
2429 if (sc->an_have_rssimap)
2430 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2433 /* Set the ssid list */
2434 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2435 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2436 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2437 if_printf(ifp, "failed to set ssid list\n");
2441 /* Set the AP list */
2442 sc->an_aplist.an_type = AN_RID_APLIST;
2443 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2444 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2445 if_printf(ifp, "failed to set AP list\n");
2449 /* Set the configuration in the NIC */
2450 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2451 sc->an_config.an_type = AN_RID_GENCONFIG;
2452 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2453 if_printf(ifp, "failed to set configuration\n");
2457 /* Enable the MAC */
2458 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2459 if_printf(ifp, "failed to enable MAC\n");
2463 if (ifp->if_flags & IFF_PROMISC)
2464 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2466 /* enable interrupts */
2467 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2469 ifp->if_flags |= IFF_RUNNING;
2470 ifq_clr_oactive(&ifp->if_snd);
2472 callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc);
2476 an_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
2478 struct an_softc *sc;
2479 struct mbuf *m0 = NULL;
2480 struct an_txframe_802_3 tx_frame_802_3;
2481 struct ether_header *eh;
2482 int id, idx, i, ready;
2483 unsigned char txcontrol;
2484 struct an_card_tx_desc an_tx_desc;
2487 ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
2491 if (ifq_is_oactive(&ifp->if_snd))
2494 if (!sc->an_associated) {
2495 ifq_purge(&ifp->if_snd);
2499 /* We can't send in monitor mode so toss any attempts. */
2500 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2501 ifq_purge(&ifp->if_snd);
2506 idx = sc->an_rdata.an_tx_prod;
2509 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2511 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2513 m0 = ifq_dequeue(&ifp->if_snd);
2517 id = sc->an_rdata.an_tx_fids[idx];
2518 eh = mtod(m0, struct ether_header *);
2520 bcopy((char *)&eh->ether_dhost,
2521 (char *)&tx_frame_802_3.an_tx_dst_addr,
2523 bcopy((char *)&eh->ether_shost,
2524 (char *)&tx_frame_802_3.an_tx_src_addr,
2527 /* minus src/dest mac & type */
2528 tx_frame_802_3.an_tx_802_3_payload_len =
2529 m0->m_pkthdr.len - 12;
2531 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2532 tx_frame_802_3.an_tx_802_3_payload_len,
2533 (caddr_t)&sc->an_txbuf);
2535 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2536 /* write the txcontrol only */
2537 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2541 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2542 sizeof(struct an_txframe_802_3));
2544 /* in mbuf header type is just before payload */
2545 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2546 tx_frame_802_3.an_tx_802_3_payload_len);
2553 sc->an_rdata.an_tx_ring[idx] = id;
2554 if (an_cmd(sc, AN_CMD_TX, id))
2555 if_printf(ifp, "xmit failed\n");
2557 AN_INC(idx, AN_TX_RING_CNT);
2560 * Set a timeout in case the chip goes out to lunch.
2564 } else { /* MPI-350 */
2565 /* Disable interrupts. */
2566 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2568 while (sc->an_rdata.an_tx_empty ||
2569 idx != sc->an_rdata.an_tx_cons) {
2571 m0 = ifq_dequeue(&ifp->if_snd);
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 | AN_TXCTL_HW(sc->mpi350);
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 = sizeof(an_tx_desc) / 4 - 1; i >= 0 ; --i) {
2617 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2619 + (0 * sizeof(an_tx_desc))
2621 ((u_int32_t*)(void *)&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 ifq_set_oactive(&ifp->if_snd);
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;
2668 ifq_clr_oactive(&ifp->if_snd);
2670 if (sc->an_flash_buffer) {
2671 kfree(sc->an_flash_buffer, M_DEVBUF);
2672 sc->an_flash_buffer = NULL;
2677 an_watchdog(struct ifnet *ifp)
2679 struct an_softc *sc;
2685 an_init_mpi350_desc(sc);
2688 IFNET_STAT_INC(ifp, oerrors, 1);
2690 if_printf(ifp, "device timeout\n");
2694 an_shutdown(device_t dev)
2696 struct an_softc *sc;
2698 sc = device_get_softc(dev);
2705 an_resume(device_t dev)
2707 struct an_softc *sc = device_get_softc(dev);
2708 struct ifnet *ifp = &sc->arpcom.ac_if;
2711 lwkt_serialize_enter(ifp->if_serializer);
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)
2730 lwkt_serialize_exit(ifp->if_serializer);
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 *)(void *)&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 *)(void *)&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 *)(void *)&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 kprintf("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,
3413 ((u_int16_t *)(void *)bufp)[nwords] & 0xffff);
3416 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3417 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3418 ((u_int32_t *)(void *)bufp)[nwords] & 0xffff);
3422 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3428 * After flashing restart the card.
3432 flashrestart(struct ifnet *ifp)
3435 struct an_softc *sc = ifp->if_softc;
3437 FLASH_DELAY(1024); /* Added 12/7/00 */
3441 FLASH_DELAY(1024); /* Added 12/7/00 */
3446 * Entry point for flash ioclt.
3450 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3453 struct an_softc *sc;
3457 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3460 status = l_ioctl->command;
3462 switch (l_ioctl->command) {
3464 return cmdreset(ifp);
3467 if (sc->an_flash_buffer) {
3468 kfree(sc->an_flash_buffer, M_DEVBUF);
3469 sc->an_flash_buffer = NULL;
3471 sc->an_flash_buffer = kmalloc(FLASH_SIZE, M_DEVBUF, 0);
3472 if (sc->an_flash_buffer)
3473 return setflashmode(ifp);
3477 case AIROFLSHGCHR: /* Get char from aux */
3478 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3479 z = *(int *)(void *)&sc->areq;
3480 if ((status = flashgchar(ifp, z, 8000)) == 1)
3485 case AIROFLSHPCHR: /* Send char to card. */
3486 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3487 z = *(int *)(void *)&sc->areq;
3488 if ((status = flashpchar(ifp, z, 8000)) == -1)
3493 case AIROFLPUTBUF: /* Send 32k to card */
3494 if (l_ioctl->len > FLASH_SIZE) {
3495 if_printf(ifp, "Buffer to big, %x %x\n",
3496 l_ioctl->len, FLASH_SIZE);
3499 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3501 if ((status = flashputbuf(ifp)) != 0)
3507 if ((status = flashrestart(ifp)) != 0) {
3508 if_printf(ifp, "FLASHRESTART returned %d\n", status);