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.
33 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
35 * Written by Bill Paul <wpaul@ctr.columbia.edu>
36 * Electrical Engineering Department
37 * Columbia University, New York City
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
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/ctype.h>
92 #include <sys/systm.h>
93 #include <sys/sockio.h>
97 #include <sys/kernel.h>
98 #include <sys/socket.h>
100 #include <sys/syslog.h>
102 #include <sys/sysctl.h>
104 #include <sys/module.h>
106 #include <machine/bus.h>
107 #include <sys/rman.h>
108 #include <sys/lock.h>
109 #include <sys/mutex.h>
110 #include <machine/resource.h>
111 #include <sys/malloc.h>
114 #include <net/if_var.h>
115 #include <net/if_arp.h>
116 #include <net/if_dl.h>
117 #include <net/ethernet.h>
118 #include <net/if_types.h>
119 #include <net/if_media.h>
121 #include <net80211/ieee80211_var.h>
122 #include <net80211/ieee80211_ioctl.h>
125 #include <netinet/in.h>
126 #include <netinet/in_systm.h>
127 #include <netinet/in_var.h>
128 #include <netinet/ip.h>
133 #include <machine/md_var.h>
135 #include <dev/an/if_aironet_ieee.h>
136 #include <dev/an/if_anreg.h>
138 /* These are global because we need them in sys/pci/if_an_p.c. */
139 static void an_reset(struct an_softc *);
140 static int an_init_mpi350_desc(struct an_softc *);
141 static int an_ioctl(struct ifnet *, u_long, caddr_t);
142 static void an_init(void *);
143 static void an_init_locked(struct an_softc *);
144 static int an_init_tx_ring(struct an_softc *);
145 static void an_start(struct ifnet *);
146 static void an_start_locked(struct ifnet *);
147 static void an_watchdog(struct an_softc *);
148 static void an_rxeof(struct an_softc *);
149 static void an_txeof(struct an_softc *, int);
151 static void an_promisc(struct an_softc *, int);
152 static int an_cmd(struct an_softc *, int, int);
153 static int an_cmd_struct(struct an_softc *, struct an_command *,
155 static int an_read_record(struct an_softc *, struct an_ltv_gen *);
156 static int an_write_record(struct an_softc *, struct an_ltv_gen *);
157 static int an_read_data(struct an_softc *, int, int, caddr_t, int);
158 static int an_write_data(struct an_softc *, int, int, caddr_t, 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, struct an_dma_alloc *,
163 static void an_dma_free(struct an_softc *, struct an_dma_alloc *);
164 static void an_dma_malloc_cb(void *, bus_dma_segment_t *, int, int);
165 static void an_stats_update(void *);
166 static void an_setdef(struct an_softc *, struct an_req *);
168 static void an_cache_store(struct an_softc *, struct ether_header *,
169 struct mbuf *, u_int8_t, u_int8_t);
172 /* function definitions for use with the Cisco's Linux configuration
176 static int readrids(struct ifnet*, struct aironet_ioctl*);
177 static int writerids(struct ifnet*, struct aironet_ioctl*);
178 static int flashcard(struct ifnet*, struct aironet_ioctl*);
180 static int cmdreset(struct ifnet *);
181 static int setflashmode(struct ifnet *);
182 static int flashgchar(struct ifnet *,int,int);
183 static int flashpchar(struct ifnet *,int,int);
184 static int flashputbuf(struct ifnet *);
185 static int flashrestart(struct ifnet *);
186 static int WaitBusy(struct ifnet *, int);
187 static int unstickbusy(struct ifnet *);
189 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
192 static int an_media_change (struct ifnet *);
193 static void an_media_status (struct ifnet *, struct ifmediareq *);
195 static int an_dump = 0;
196 static int an_cache_mode = 0;
202 static char an_conf[256];
203 static char an_conf_cache[256];
207 static SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0,
208 "Wireless driver parameters");
210 /* XXX violate ethernet/netgraph callback hooks */
211 extern void (*ng_ether_attach_p)(struct ifnet *ifp);
212 extern void (*ng_ether_detach_p)(struct ifnet *ifp);
215 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
224 strcpy(an_conf, "off");
227 strcpy(an_conf, "type");
230 strcpy(an_conf, "dump");
233 snprintf(an_conf, 5, "%x", an_dump);
237 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
239 if (strncmp(an_conf,"off", 3) == 0) {
242 if (strncmp(an_conf,"dump", 4) == 0) {
245 if (strncmp(an_conf,"type", 4) == 0) {
251 if ((*s >= '0') && (*s <= '9')) {
252 r = r * 16 + (*s - '0');
253 } else if ((*s >= 'a') && (*s <= 'f')) {
254 r = r * 16 + (*s - 'a' + 10);
262 printf("Sysctl changed for Aironet driver\n");
267 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
268 0, sizeof(an_conf), sysctl_an_dump, "A", "");
271 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
275 last = an_cache_mode;
277 switch (an_cache_mode) {
279 strcpy(an_conf_cache, "per");
282 strcpy(an_conf_cache, "raw");
285 strcpy(an_conf_cache, "dbm");
289 error = sysctl_handle_string(oidp, an_conf_cache,
290 sizeof(an_conf_cache), req);
292 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
295 if (strncmp(an_conf_cache,"per", 3) == 0) {
298 if (strncmp(an_conf_cache,"raw", 3) == 0) {
305 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
306 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
309 * Setup the lock for PCI attachment since it skips the an_probe
310 * function. We need to setup the lock in an_probe since some
311 * operations need the lock. So we might as well create the
315 an_pci_probe(device_t dev)
317 struct an_softc *sc = device_get_softc(dev);
319 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
326 * We probe for an Aironet 4500/4800 card by attempting to
327 * read the default SSID list. On reset, the first entry in
328 * the SSID list will contain the name "tsunami." If we don't
329 * find this, then there's no card present.
332 an_probe(device_t dev)
334 struct an_softc *sc = device_get_softc(dev);
335 struct an_ltv_ssidlist_new ssid;
338 bzero((char *)&ssid, sizeof(ssid));
340 error = an_alloc_port(dev, 0, AN_IOSIZ);
344 /* can't do autoprobing */
345 if (rman_get_start(sc->port_res) == -1)
349 * We need to fake up a softc structure long enough
350 * to be able to issue commands and call some of the
353 ssid.an_len = sizeof(ssid);
354 ssid.an_type = AN_RID_SSIDLIST;
356 /* Make sure interrupts are disabled. */
358 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
359 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
362 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
367 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
372 if (an_read_record(sc, (struct an_ltv_gen *)&ssid)) {
377 /* See if the ssid matches what we expect ... but doesn't have to */
378 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID)) {
386 mtx_destroy(&sc->an_mtx);
391 * Allocate a port resource with the given resource id.
394 an_alloc_port(device_t dev, int rid, int size)
396 struct an_softc *sc = device_get_softc(dev);
397 struct resource *res;
399 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
400 0ul, ~0ul, size, RF_ACTIVE);
411 * Allocate a memory resource with the given resource id.
413 int an_alloc_memory(device_t dev, int rid, int size)
415 struct an_softc *sc = device_get_softc(dev);
416 struct resource *res;
418 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
419 0ul, ~0ul, size, RF_ACTIVE);
431 * Allocate a auxilary memory resource with the given resource id.
433 int an_alloc_aux_memory(device_t dev, int rid, int size)
435 struct an_softc *sc = device_get_softc(dev);
436 struct resource *res;
438 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
439 0ul, ~0ul, size, RF_ACTIVE);
441 sc->mem_aux_rid = rid;
442 sc->mem_aux_res = res;
443 sc->mem_aux_used = size;
451 * Allocate an irq resource with the given resource id.
454 an_alloc_irq(device_t dev, int rid, int flags)
456 struct an_softc *sc = device_get_softc(dev);
457 struct resource *res;
459 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
460 (RF_ACTIVE | flags));
471 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
473 bus_addr_t *paddr = (bus_addr_t*) arg;
474 *paddr = segs->ds_addr;
478 * Alloc DMA memory and set the pointer to it
481 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
486 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
490 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
491 BUS_DMA_NOWAIT, &dma->an_dma_map);
495 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
499 mapflags | BUS_DMA_NOWAIT);
503 dma->an_dma_size = size;
507 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
509 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
511 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
512 dma->an_dma_map = NULL;
517 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
519 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
520 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
521 dma->an_dma_vaddr = 0;
522 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
526 * Release all resources
529 an_release_resources(device_t dev)
531 struct an_softc *sc = device_get_softc(dev);
535 bus_release_resource(dev, SYS_RES_IOPORT,
536 sc->port_rid, sc->port_res);
540 bus_release_resource(dev, SYS_RES_MEMORY,
541 sc->mem_rid, sc->mem_res);
544 if (sc->mem_aux_res) {
545 bus_release_resource(dev, SYS_RES_MEMORY,
546 sc->mem_aux_rid, sc->mem_aux_res);
550 bus_release_resource(dev, SYS_RES_IRQ,
551 sc->irq_rid, sc->irq_res);
554 if (sc->an_rid_buffer.an_dma_paddr) {
555 an_dma_free(sc, &sc->an_rid_buffer);
557 for (i = 0; i < AN_MAX_RX_DESC; i++)
558 if (sc->an_rx_buffer[i].an_dma_paddr) {
559 an_dma_free(sc, &sc->an_rx_buffer[i]);
561 for (i = 0; i < AN_MAX_TX_DESC; i++)
562 if (sc->an_tx_buffer[i].an_dma_paddr) {
563 an_dma_free(sc, &sc->an_tx_buffer[i]);
566 bus_dma_tag_destroy(sc->an_dtag);
572 an_init_mpi350_desc(struct an_softc *sc)
574 struct an_command cmd_struct;
575 struct an_reply reply;
576 struct an_card_rid_desc an_rid_desc;
577 struct an_card_rx_desc an_rx_desc;
578 struct an_card_tx_desc an_tx_desc;
582 if(!sc->an_rid_buffer.an_dma_paddr)
583 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
584 &sc->an_rid_buffer, 0);
585 for (i = 0; i < AN_MAX_RX_DESC; i++)
586 if(!sc->an_rx_buffer[i].an_dma_paddr)
587 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
588 &sc->an_rx_buffer[i], 0);
589 for (i = 0; i < AN_MAX_TX_DESC; i++)
590 if(!sc->an_tx_buffer[i].an_dma_paddr)
591 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
592 &sc->an_tx_buffer[i], 0);
595 * Allocate RX descriptor
597 bzero(&reply,sizeof(reply));
598 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
599 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
600 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
601 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
602 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
603 if_printf(sc->an_ifp, "failed to allocate RX descriptor\n");
607 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
608 bzero(&an_rx_desc, sizeof(an_rx_desc));
609 an_rx_desc.an_valid = 1;
610 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
611 an_rx_desc.an_done = 0;
612 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
614 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
615 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
616 + (desc * sizeof(an_rx_desc))
618 ((u_int32_t *)(void *)&an_rx_desc)[i]);
622 * Allocate TX descriptor
625 bzero(&reply,sizeof(reply));
626 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
627 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
628 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
629 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
630 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
631 if_printf(sc->an_ifp, "failed to allocate TX descriptor\n");
635 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
636 bzero(&an_tx_desc, sizeof(an_tx_desc));
637 an_tx_desc.an_offset = 0;
638 an_tx_desc.an_eoc = 0;
639 an_tx_desc.an_valid = 0;
640 an_tx_desc.an_len = 0;
641 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
643 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
644 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
645 + (desc * sizeof(an_tx_desc))
647 ((u_int32_t *)(void *)&an_tx_desc)[i]);
651 * Allocate RID descriptor
654 bzero(&reply,sizeof(reply));
655 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
656 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
657 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
658 cmd_struct.an_parm2 = 1;
659 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
660 if_printf(sc->an_ifp, "failed to allocate host descriptor\n");
664 bzero(&an_rid_desc, sizeof(an_rid_desc));
665 an_rid_desc.an_valid = 1;
666 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
667 an_rid_desc.an_rid = 0;
668 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
670 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
671 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
672 ((u_int32_t *)(void *)&an_rid_desc)[i]);
678 an_attach(struct an_softc *sc, int flags)
685 ifp = sc->an_ifp = if_alloc(IFT_ETHER);
687 device_printf(sc->an_dev, "can not if_alloc()\n");
691 if_initname(ifp, device_get_name(sc->an_dev),
692 device_get_unit(sc->an_dev));
695 sc->an_associated = 0;
697 sc->an_was_monitor = 0;
698 sc->an_flash_buffer = NULL;
704 error = an_init_mpi350_desc(sc);
709 /* Load factory config */
710 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
711 device_printf(sc->an_dev, "failed to load config data\n");
715 /* Read the current configuration */
716 sc->an_config.an_type = AN_RID_GENCONFIG;
717 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
718 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
719 device_printf(sc->an_dev, "read record failed\n");
723 /* Read the card capabilities */
724 sc->an_caps.an_type = AN_RID_CAPABILITIES;
725 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
726 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
727 device_printf(sc->an_dev, "read record failed\n");
732 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
733 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
734 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
735 device_printf(sc->an_dev, "read record failed\n");
740 sc->an_aplist.an_type = AN_RID_APLIST;
741 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
742 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
743 device_printf(sc->an_dev, "read record failed\n");
748 /* Read the RSSI <-> dBm map */
749 sc->an_have_rssimap = 0;
750 if (sc->an_caps.an_softcaps & 8) {
751 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
752 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
753 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
754 device_printf(sc->an_dev,
755 "unable to get RSSI <-> dBM map\n");
757 device_printf(sc->an_dev, "got RSSI <-> dBM map\n");
758 sc->an_have_rssimap = 1;
761 device_printf(sc->an_dev, "no RSSI <-> dBM map\n");
766 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
767 ifp->if_ioctl = an_ioctl;
768 ifp->if_start = an_start;
769 ifp->if_init = an_init;
770 ifp->if_baudrate = 10000000;
771 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
772 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
773 IFQ_SET_READY(&ifp->if_snd);
775 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
776 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
777 sizeof(AN_DEFAULT_NODENAME) - 1);
779 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
780 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
781 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
782 sizeof(AN_DEFAULT_NETNAME) - 1);
783 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
785 sc->an_config.an_opmode =
786 AN_OPMODE_INFRASTRUCTURE_STATION;
789 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
793 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
794 if_printf(ifp, "supported rates: ");
795 #define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
796 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
798 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
799 for (i = 0; i < nrate; i++) {
800 r = sc->an_caps.an_rates[i];
801 mword = ieee80211_rate2media(NULL, r, IEEE80211_MODE_AUTO);
804 printf("%s%d%sMbps", (i != 0 ? " " : ""),
805 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
807 ADD(mword, IFM_IEEE80211_ADHOC);
810 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
815 * Call MI attach routine.
818 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
819 callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0);
824 mtx_destroy(&sc->an_mtx);
831 an_detach(device_t dev)
833 struct an_softc *sc = device_get_softc(dev);
834 struct ifnet *ifp = sc->an_ifp;
837 device_printf(dev,"already unloaded\n");
843 ifmedia_removeall(&sc->an_ifmedia);
844 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
847 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
848 callout_drain(&sc->an_stat_ch);
850 an_release_resources(dev);
851 mtx_destroy(&sc->an_mtx);
856 an_rxeof(struct an_softc *sc)
859 struct ether_header *eh;
860 struct ieee80211_frame *ih;
861 struct an_rxframe rx_frame;
862 struct an_rxframe_802_3 rx_frame_802_3;
864 int len, id, error = 0, i, count = 0;
865 int ieee80211_header_len;
868 struct an_card_rx_desc an_rx_desc;
876 id = CSR_READ_2(sc, AN_RX_FID);
878 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
879 /* read raw 802.11 packet */
880 bpf_buf = sc->buf_802_11;
883 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
890 * skip beacon by default since this increases the
894 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
895 (rx_frame.an_frame_ctl &
896 IEEE80211_FC0_SUBTYPE_BEACON)) {
900 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
901 len = rx_frame.an_rx_payload_len
903 /* Check for insane frame length */
904 if (len > sizeof(sc->buf_802_11)) {
905 if_printf(ifp, "oversized packet "
906 "received (%d, %d)\n",
912 bcopy((char *)&rx_frame,
913 bpf_buf, sizeof(rx_frame));
915 error = an_read_data(sc, id, sizeof(rx_frame),
916 (caddr_t)bpf_buf+sizeof(rx_frame),
917 rx_frame.an_rx_payload_len);
919 fc1=rx_frame.an_frame_ctl >> 8;
920 ieee80211_header_len =
921 sizeof(struct ieee80211_frame);
922 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
923 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
924 ieee80211_header_len += ETHER_ADDR_LEN;
927 len = rx_frame.an_rx_payload_len
928 + ieee80211_header_len;
929 /* Check for insane frame length */
930 if (len > sizeof(sc->buf_802_11)) {
931 if_printf(ifp, "oversized packet "
932 "received (%d, %d)\n",
938 ih = (struct ieee80211_frame *)bpf_buf;
940 bcopy((char *)&rx_frame.an_frame_ctl,
941 (char *)ih, ieee80211_header_len);
943 error = an_read_data(sc, id, sizeof(rx_frame) +
945 (caddr_t)ih +ieee80211_header_len,
946 rx_frame.an_rx_payload_len);
948 /* dump raw 802.11 packet to bpf and skip ip stack */
949 BPF_TAP(ifp, bpf_buf, len);
951 MGETHDR(m, M_NOWAIT, MT_DATA);
957 if (!(m->m_flags & M_EXT)) {
962 m->m_pkthdr.rcvif = ifp;
963 /* Read Ethernet encapsulated packet */
966 /* Read NIC frame header */
967 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
974 /* Read in the 802_3 frame header */
975 if (an_read_data(sc, id, 0x34,
976 (caddr_t)&rx_frame_802_3,
977 sizeof(rx_frame_802_3))) {
982 if (rx_frame_802_3.an_rx_802_3_status != 0) {
987 /* Check for insane frame length */
988 len = rx_frame_802_3.an_rx_802_3_payload_len;
989 if (len > sizeof(sc->buf_802_11)) {
991 if_printf(ifp, "oversized packet "
992 "received (%d, %d)\n",
997 m->m_pkthdr.len = m->m_len =
998 rx_frame_802_3.an_rx_802_3_payload_len + 12;
1000 eh = mtod(m, struct ether_header *);
1002 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
1003 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
1004 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
1005 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
1007 /* in mbuf header type is just before payload */
1008 error = an_read_data(sc, id, 0x44,
1009 (caddr_t)&(eh->ether_type),
1010 rx_frame_802_3.an_rx_802_3_payload_len);
1019 /* Receive packet. */
1021 an_cache_store(sc, eh, m,
1022 rx_frame.an_rx_signal_strength,
1026 (*ifp->if_input)(ifp, m);
1030 } else { /* MPI-350 */
1031 for (count = 0; count < AN_MAX_RX_DESC; count++){
1032 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1033 ((u_int32_t *)(void *)&an_rx_desc)[i]
1034 = CSR_MEM_AUX_READ_4(sc,
1036 + (count * sizeof(an_rx_desc))
1039 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1040 buf = sc->an_rx_buffer[count].an_dma_vaddr;
1042 MGETHDR(m, M_NOWAIT, MT_DATA);
1047 MCLGET(m, M_NOWAIT);
1048 if (!(m->m_flags & M_EXT)) {
1053 m->m_pkthdr.rcvif = ifp;
1054 /* Read Ethernet encapsulated packet */
1057 * No ANCACHE support since we just get back
1058 * an Ethernet packet no 802.11 info
1062 /* Read NIC frame header */
1063 bcopy(buf, (caddr_t)&rx_frame,
1067 /* Check for insane frame length */
1068 len = an_rx_desc.an_len + 12;
1069 if (len > MCLBYTES) {
1071 if_printf(ifp, "oversized packet "
1072 "received (%d, %d)\n",
1078 m->m_pkthdr.len = m->m_len =
1079 an_rx_desc.an_len + 12;
1081 eh = mtod(m, struct ether_header *);
1083 bcopy(buf, (char *)eh,
1088 /* Receive packet. */
1091 an_cache_store(sc, eh, m,
1092 rx_frame.an_rx_signal_strength,
1097 (*ifp->if_input)(ifp, m);
1100 an_rx_desc.an_valid = 1;
1101 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1102 an_rx_desc.an_done = 0;
1103 an_rx_desc.an_phys =
1104 sc->an_rx_buffer[count].an_dma_paddr;
1106 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1107 CSR_MEM_AUX_WRITE_4(sc,
1109 + (count * sizeof(an_rx_desc))
1111 ((u_int32_t *)(void *)&an_rx_desc)[i]);
1114 if_printf(ifp, "Didn't get valid RX packet "
1117 an_rx_desc.an_valid, an_rx_desc.an_len);
1124 an_txeof(struct an_softc *sc, int status)
1133 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1136 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1138 if (status & AN_EV_TX_EXC) {
1143 for (i = 0; i < AN_TX_RING_CNT; i++) {
1144 if (id == sc->an_rdata.an_tx_ring[i]) {
1145 sc->an_rdata.an_tx_ring[i] = 0;
1150 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1151 } else { /* MPI 350 */
1152 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1153 if (!sc->an_rdata.an_tx_empty){
1154 if (status & AN_EV_TX_EXC) {
1158 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1159 if (sc->an_rdata.an_tx_prod ==
1160 sc->an_rdata.an_tx_cons)
1161 sc->an_rdata.an_tx_empty = 1;
1169 * We abuse the stats updater to check the current NIC status. This
1170 * is important because we don't want to allow transmissions until
1171 * the NIC has synchronized to the current cell (either as the master
1172 * in an ad-hoc group, or as a station connected to an access point).
1174 * Note that this function will be called via callout(9) with a lock held.
1177 an_stats_update(void *xsc)
1179 struct an_softc *sc;
1185 if (sc->an_timer > 0 && --sc->an_timer == 0)
1188 sc->an_status.an_type = AN_RID_STATUS;
1189 sc->an_status.an_len = sizeof(struct an_ltv_status);
1190 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status))
1193 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1194 sc->an_associated = 1;
1196 sc->an_associated = 0;
1198 /* Don't do this while we're transmitting */
1199 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
1200 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1204 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1205 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1206 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len))
1209 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1217 struct an_softc *sc;
1221 sc = (struct an_softc*)xsc;
1232 /* Disable interrupts. */
1233 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1235 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1236 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1238 if (status & AN_EV_MIC) {
1239 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1242 if (status & AN_EV_LINKSTAT) {
1243 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1244 == AN_LINKSTAT_ASSOCIATED)
1245 sc->an_associated = 1;
1247 sc->an_associated = 0;
1248 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1251 if (status & AN_EV_RX) {
1253 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1256 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1257 an_txeof(sc, status);
1258 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1261 if (status & AN_EV_TX) {
1262 an_txeof(sc, status);
1263 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1266 if (status & AN_EV_TX_EXC) {
1267 an_txeof(sc, status);
1268 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1271 if (status & AN_EV_ALLOC)
1272 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1274 /* Re-enable interrupts. */
1275 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1277 if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1278 an_start_locked(ifp);
1287 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1288 struct an_reply *reply)
1293 for (i = 0; i != AN_TIMEOUT; i++) {
1294 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1300 if( i == AN_TIMEOUT) {
1305 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1306 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1307 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1308 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1310 for (i = 0; i < AN_TIMEOUT; i++) {
1311 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1316 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1317 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1318 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1319 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1321 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1322 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
1323 AN_EV_CLR_STUCK_BUSY);
1325 /* Ack the command */
1326 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1328 if (i == AN_TIMEOUT)
1335 an_cmd(struct an_softc *sc, int cmd, int val)
1340 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1341 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1342 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1343 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1345 for (i = 0; i < AN_TIMEOUT; i++) {
1346 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1349 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1350 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1354 for (i = 0; i < AN_TIMEOUT; i++) {
1355 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1356 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1357 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1358 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1359 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1363 /* Ack the command */
1364 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1366 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1367 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1369 if (i == AN_TIMEOUT)
1376 * This reset sequence may look a little strange, but this is the
1377 * most reliable method I've found to really kick the NIC in the
1378 * head and force it to reboot correctly.
1381 an_reset(struct an_softc *sc)
1387 an_cmd(sc, AN_CMD_ENABLE, 0);
1388 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1389 an_cmd(sc, AN_CMD_NOOP2, 0);
1391 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1392 device_printf(sc->an_dev, "reset failed\n");
1394 an_cmd(sc, AN_CMD_DISABLE, 0);
1400 * Read an LTV record from the NIC.
1403 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1405 struct an_ltv_gen *an_ltv;
1406 struct an_card_rid_desc an_rid_desc;
1407 struct an_command cmd;
1408 struct an_reply reply;
1415 if (ltv->an_len < 4 || ltv->an_type == 0)
1420 /* Tell the NIC to enter record read mode. */
1421 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1422 if_printf(ifp, "RID access failed\n");
1426 /* Seek to the record. */
1427 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1428 if_printf(ifp, "seek to record failed\n");
1433 * Read the length and record type and make sure they
1434 * match what we expect (this verifies that we have enough
1435 * room to hold all of the returned data).
1436 * Length includes type but not length.
1438 len = CSR_READ_2(sc, AN_DATA1);
1439 if (len > (ltv->an_len - 2)) {
1440 if_printf(ifp, "record length mismatch -- expected %d, "
1441 "got %d for Rid %x\n",
1442 ltv->an_len - 2, len, ltv->an_type);
1443 len = ltv->an_len - 2;
1445 ltv->an_len = len + 2;
1448 /* Now read the data. */
1449 len -= 2; /* skip the type */
1451 for (i = len; i > 1; i -= 2)
1452 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1454 ptr2 = (u_int8_t *)ptr;
1455 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1457 } else { /* MPI-350 */
1458 if (!sc->an_rid_buffer.an_dma_vaddr)
1460 an_rid_desc.an_valid = 1;
1461 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1462 an_rid_desc.an_rid = 0;
1463 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1464 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1466 bzero(&cmd, sizeof(cmd));
1467 bzero(&reply, sizeof(reply));
1468 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1469 cmd.an_parm0 = ltv->an_type;
1471 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1472 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1473 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1475 if (an_cmd_struct(sc, &cmd, &reply)
1476 || reply.an_status & AN_CMD_QUAL_MASK) {
1477 if_printf(ifp, "failed to read RID %x %x %x %x %x, %d\n",
1487 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1488 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1489 an_rid_desc.an_len = an_ltv->an_len;
1492 len = an_rid_desc.an_len;
1493 if (len > (ltv->an_len - 2)) {
1494 if_printf(ifp, "record length mismatch -- expected %d, "
1495 "got %d for Rid %x\n",
1496 ltv->an_len - 2, len, ltv->an_type);
1497 len = ltv->an_len - 2;
1499 ltv->an_len = len + 2;
1501 bcopy(&an_ltv->an_type,
1507 an_dump_record(sc, ltv, "Read");
1513 * Same as read, except we inject data instead of reading it.
1516 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1518 struct an_card_rid_desc an_rid_desc;
1519 struct an_command cmd;
1520 struct an_reply reply;
1527 an_dump_record(sc, ltv, "Write");
1530 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1533 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1537 * Length includes type but not length.
1539 len = ltv->an_len - 2;
1540 CSR_WRITE_2(sc, AN_DATA1, len);
1542 len -= 2; /* skip the type */
1544 for (i = len; i > 1; i -= 2)
1545 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1547 ptr2 = (u_int8_t *)ptr;
1548 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1551 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1556 for (i = 0; i != AN_TIMEOUT; i++) {
1557 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1563 if (i == AN_TIMEOUT) {
1567 an_rid_desc.an_valid = 1;
1568 an_rid_desc.an_len = ltv->an_len - 2;
1569 an_rid_desc.an_rid = ltv->an_type;
1570 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1572 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1573 an_rid_desc.an_len);
1575 bzero(&cmd,sizeof(cmd));
1576 bzero(&reply,sizeof(reply));
1577 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1578 cmd.an_parm0 = ltv->an_type;
1580 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1581 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1582 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1586 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1587 if_printf(sc->an_ifp,
1588 "failed to write RID 1 %x %x %x %x %x, %d\n",
1599 if (reply.an_status & AN_CMD_QUAL_MASK) {
1600 if_printf(sc->an_ifp,
1601 "failed to write RID 2 %x %x %x %x %x, %d\n",
1617 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1625 len = ltv->an_len - 4;
1626 if_printf(sc->an_ifp, "RID %4x, Length %4d, Mode %s\n",
1627 ltv->an_type, ltv->an_len - 4, string);
1629 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1630 if_printf(sc->an_ifp, "\t");
1631 bzero(buf,sizeof(buf));
1633 ptr2 = (u_int8_t *)<v->an_val;
1634 for (i = len; i > 0; i--) {
1635 printf("%02x ", *ptr2);
1642 if (++count == 16) {
1645 if_printf(sc->an_ifp, "\t");
1646 bzero(buf,sizeof(buf));
1649 for (; count != 16; count++) {
1652 printf(" %s\n",buf);
1657 an_seek(struct an_softc *sc, int id, int off, int chan)
1672 if_printf(sc->an_ifp, "invalid data path: %x\n", chan);
1676 CSR_WRITE_2(sc, selreg, id);
1677 CSR_WRITE_2(sc, offreg, off);
1679 for (i = 0; i < AN_TIMEOUT; i++) {
1680 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1684 if (i == AN_TIMEOUT)
1691 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1698 if (an_seek(sc, id, off, AN_BAP1))
1702 ptr = (u_int16_t *)buf;
1703 for (i = len; i > 1; i -= 2)
1704 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1706 ptr2 = (u_int8_t *)ptr;
1707 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1714 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1721 if (an_seek(sc, id, off, AN_BAP0))
1725 ptr = (u_int16_t *)buf;
1726 for (i = len; i > 1; i -= 2)
1727 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1729 ptr2 = (u_int8_t *)ptr;
1730 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1737 * Allocate a region of memory inside the NIC and zero
1741 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1745 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1746 if_printf(sc->an_ifp, "failed to allocate %d bytes on NIC\n",
1751 for (i = 0; i < AN_TIMEOUT; i++) {
1752 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1756 if (i == AN_TIMEOUT)
1759 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1760 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1762 if (an_seek(sc, *id, 0, AN_BAP0))
1765 for (i = 0; i < len / 2; i++)
1766 CSR_WRITE_2(sc, AN_DATA0, 0);
1772 an_setdef(struct an_softc *sc, struct an_req *areq)
1775 struct an_ltv_genconfig *cfg;
1776 struct an_ltv_ssidlist_new *ssid;
1777 struct an_ltv_aplist *ap;
1778 struct an_ltv_gen *sp;
1783 switch (areq->an_type) {
1784 case AN_RID_GENCONFIG:
1785 cfg = (struct an_ltv_genconfig *)areq;
1787 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(sc->an_ifp),
1790 bcopy((char *)cfg, (char *)&sc->an_config,
1791 sizeof(struct an_ltv_genconfig));
1793 case AN_RID_SSIDLIST:
1794 ssid = (struct an_ltv_ssidlist_new *)areq;
1795 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1796 sizeof(struct an_ltv_ssidlist_new));
1799 ap = (struct an_ltv_aplist *)areq;
1800 bcopy((char *)ap, (char *)&sc->an_aplist,
1801 sizeof(struct an_ltv_aplist));
1803 case AN_RID_TX_SPEED:
1804 sp = (struct an_ltv_gen *)areq;
1805 sc->an_tx_rate = sp->an_val;
1807 /* Read the current configuration */
1808 sc->an_config.an_type = AN_RID_GENCONFIG;
1809 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1810 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1811 cfg = &sc->an_config;
1813 /* clear other rates and set the only one we want */
1814 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1815 cfg->an_rates[0] = sc->an_tx_rate;
1817 /* Save the new rate */
1818 sc->an_config.an_type = AN_RID_GENCONFIG;
1819 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1821 case AN_RID_WEP_TEMP:
1822 /* Cache the temp keys */
1824 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1825 sizeof(struct an_ltv_key));
1826 case AN_RID_WEP_PERM:
1827 case AN_RID_LEAPUSERNAME:
1828 case AN_RID_LEAPPASSWORD:
1831 /* Disable the MAC. */
1832 an_cmd(sc, AN_CMD_DISABLE, 0);
1835 an_write_record(sc, (struct an_ltv_gen *)areq);
1837 /* Turn the MAC back on. */
1838 an_cmd(sc, AN_CMD_ENABLE, 0);
1841 case AN_RID_MONITOR_MODE:
1842 cfg = (struct an_ltv_genconfig *)areq;
1844 if (ng_ether_detach_p != NULL)
1845 (*ng_ether_detach_p) (ifp);
1846 sc->an_monitor = cfg->an_len;
1848 if (sc->an_monitor & AN_MONITOR) {
1849 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1850 bpfattach(ifp, DLT_AIRONET_HEADER,
1851 sizeof(struct ether_header));
1853 bpfattach(ifp, DLT_IEEE802_11,
1854 sizeof(struct ether_header));
1857 bpfattach(ifp, DLT_EN10MB,
1858 sizeof(struct ether_header));
1859 if (ng_ether_attach_p != NULL)
1860 (*ng_ether_attach_p) (ifp);
1864 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1869 /* Reinitialize the card. */
1877 * Derived from Linux driver to enable promiscious mode.
1881 an_promisc(struct an_softc *sc, int promisc)
1884 if (sc->an_was_monitor) {
1887 an_init_mpi350_desc(sc);
1889 if (sc->an_monitor || sc->an_was_monitor)
1892 sc->an_was_monitor = sc->an_monitor;
1893 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1899 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1904 struct an_softc *sc;
1906 struct thread *td = curthread;
1907 struct ieee80211req *ireq;
1908 struct ieee80211_channel ch;
1909 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1911 struct an_ltv_genconfig *config;
1912 struct an_ltv_key *key;
1913 struct an_ltv_status *status;
1914 struct an_ltv_ssidlist_new *ssids;
1916 struct aironet_ioctl l_ioctl;
1919 ifr = (struct ifreq *)data;
1920 ireq = (struct ieee80211req *)data;
1922 config = (struct an_ltv_genconfig *)&sc->areq;
1923 key = (struct an_ltv_key *)&sc->areq;
1924 status = (struct an_ltv_status *)&sc->areq;
1925 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1935 if (ifp->if_flags & IFF_UP) {
1936 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1937 ifp->if_flags & IFF_PROMISC &&
1938 !(sc->an_if_flags & IFF_PROMISC)) {
1940 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1941 !(ifp->if_flags & IFF_PROMISC) &&
1942 sc->an_if_flags & IFF_PROMISC) {
1947 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1950 sc->an_if_flags = ifp->if_flags;
1956 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1960 /* The Aironet has no multicast filter. */
1964 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1969 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1970 error = priv_check(td, PRIV_DRIVER);
1973 sc->an_sigitems = sc->an_nextitem = 0;
1975 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1976 char *pt = (char *)&sc->areq.an_val;
1977 bcopy((char *)&sc->an_sigitems, (char *)pt,
1980 sc->areq.an_len = sizeof(int) / 2;
1981 bcopy((char *)&sc->an_sigcache, (char *)pt,
1982 sizeof(struct an_sigcache) * sc->an_sigitems);
1983 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1984 sc->an_sigitems) / 2) + 1;
1987 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1993 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1996 if ((error = priv_check(td, PRIV_DRIVER)))
1999 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
2002 an_setdef(sc, &sc->areq);
2005 case SIOCGPRIVATE_0: /* used by Cisco client utility */
2006 if ((error = priv_check(td, PRIV_DRIVER)))
2008 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2011 mode = l_ioctl.command;
2014 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
2015 error = readrids(ifp, &l_ioctl);
2016 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
2017 error = writerids(ifp, &l_ioctl);
2018 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
2019 error = flashcard(ifp, &l_ioctl);
2025 /* copy out the updated command info */
2026 error = copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
2029 case SIOCGPRIVATE_1: /* used by Cisco client utility */
2030 if ((error = priv_check(td, PRIV_DRIVER)))
2032 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2035 l_ioctl.command = 0;
2037 (void) copyout(&error, l_ioctl.data, sizeof(error));
2041 sc->areq.an_len = sizeof(sc->areq);
2042 /* was that a good idea DJA we are doing a short-cut */
2043 switch (ireq->i_type) {
2044 case IEEE80211_IOC_SSID:
2046 if (ireq->i_val == -1) {
2047 sc->areq.an_type = AN_RID_STATUS;
2048 if (an_read_record(sc,
2049 (struct an_ltv_gen *)&sc->areq)) {
2054 len = status->an_ssidlen;
2055 tmpptr = status->an_ssid;
2056 } else if (ireq->i_val >= 0) {
2057 sc->areq.an_type = AN_RID_SSIDLIST;
2058 if (an_read_record(sc,
2059 (struct an_ltv_gen *)&sc->areq)) {
2064 max = (sc->areq.an_len - 4)
2065 / sizeof(struct an_ltv_ssid_entry);
2066 if ( max > MAX_SSIDS ) {
2067 printf("To many SSIDs only using "
2072 if (ireq->i_val > max) {
2077 len = ssids->an_entry[ireq->i_val].an_len;
2078 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2085 if (len > IEEE80211_NWID_LEN) {
2092 bzero(tmpstr, IEEE80211_NWID_LEN);
2093 bcopy(tmpptr, tmpstr, len);
2094 error = copyout(tmpstr, ireq->i_data,
2095 IEEE80211_NWID_LEN);
2097 case IEEE80211_IOC_NUMSSIDS:
2099 sc->areq.an_len = sizeof(sc->areq);
2100 sc->areq.an_type = AN_RID_SSIDLIST;
2101 if (an_read_record(sc,
2102 (struct an_ltv_gen *)&sc->areq)) {
2107 max = (sc->areq.an_len - 4)
2108 / sizeof(struct an_ltv_ssid_entry);
2110 if ( max > MAX_SSIDS ) {
2111 printf("To many SSIDs only using "
2118 case IEEE80211_IOC_WEP:
2120 sc->areq.an_type = AN_RID_ACTUALCFG;
2121 if (an_read_record(sc,
2122 (struct an_ltv_gen *)&sc->areq)) {
2128 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2129 if (config->an_authtype &
2130 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2131 ireq->i_val = IEEE80211_WEP_MIXED;
2133 ireq->i_val = IEEE80211_WEP_ON;
2135 ireq->i_val = IEEE80211_WEP_OFF;
2138 case IEEE80211_IOC_WEPKEY:
2140 * XXX: I'm not entierly convinced this is
2141 * correct, but it's what is implemented in
2142 * ancontrol so it will have to do until we get
2143 * access to actual Cisco code.
2145 if (ireq->i_val < 0 || ireq->i_val > 8) {
2150 if (ireq->i_val < 5) {
2152 sc->areq.an_type = AN_RID_WEP_TEMP;
2153 for (i = 0; i < 5; i++) {
2154 if (an_read_record(sc,
2155 (struct an_ltv_gen *)&sc->areq)) {
2159 if (key->kindex == 0xffff)
2161 if (key->kindex == ireq->i_val)
2163 /* Required to get next entry */
2164 sc->areq.an_type = AN_RID_WEP_PERM;
2171 /* We aren't allowed to read the value of the
2172 * key from the card so we just output zeros
2173 * like we would if we could read the card, but
2174 * denied the user access.
2178 error = copyout(tmpstr, ireq->i_data, len);
2180 case IEEE80211_IOC_NUMWEPKEYS:
2181 ireq->i_val = 9; /* include home key */
2183 case IEEE80211_IOC_WEPTXKEY:
2185 * For some strange reason, you have to read all
2186 * keys before you can read the txkey.
2189 sc->areq.an_type = AN_RID_WEP_TEMP;
2190 for (i = 0; i < 5; i++) {
2191 if (an_read_record(sc,
2192 (struct an_ltv_gen *) &sc->areq)) {
2196 if (key->kindex == 0xffff) {
2199 /* Required to get next entry */
2200 sc->areq.an_type = AN_RID_WEP_PERM;
2207 sc->areq.an_type = AN_RID_WEP_PERM;
2208 key->kindex = 0xffff;
2209 if (an_read_record(sc,
2210 (struct an_ltv_gen *)&sc->areq)) {
2215 ireq->i_val = key->mac[0];
2217 * Check for home mode. Map home mode into
2218 * 5th key since that is how it is stored on
2221 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2222 sc->areq.an_type = AN_RID_GENCONFIG;
2223 if (an_read_record(sc,
2224 (struct an_ltv_gen *)&sc->areq)) {
2229 if (config->an_home_product & AN_HOME_NETWORK)
2233 case IEEE80211_IOC_AUTHMODE:
2235 sc->areq.an_type = AN_RID_ACTUALCFG;
2236 if (an_read_record(sc,
2237 (struct an_ltv_gen *)&sc->areq)) {
2243 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2245 ireq->i_val = IEEE80211_AUTH_NONE;
2246 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2248 ireq->i_val = IEEE80211_AUTH_OPEN;
2249 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2250 AN_AUTHTYPE_SHAREDKEY) {
2251 ireq->i_val = IEEE80211_AUTH_SHARED;
2255 case IEEE80211_IOC_STATIONNAME:
2257 sc->areq.an_type = AN_RID_ACTUALCFG;
2258 if (an_read_record(sc,
2259 (struct an_ltv_gen *)&sc->areq)) {
2265 ireq->i_len = sizeof(config->an_nodename);
2266 tmpptr = config->an_nodename;
2267 bzero(tmpstr, IEEE80211_NWID_LEN);
2268 bcopy(tmpptr, tmpstr, ireq->i_len);
2269 error = copyout(tmpstr, ireq->i_data,
2270 IEEE80211_NWID_LEN);
2272 case IEEE80211_IOC_CHANNEL:
2274 sc->areq.an_type = AN_RID_STATUS;
2275 if (an_read_record(sc,
2276 (struct an_ltv_gen *)&sc->areq)) {
2282 ireq->i_val = status->an_cur_channel;
2284 case IEEE80211_IOC_CURCHAN:
2286 sc->areq.an_type = AN_RID_STATUS;
2287 if (an_read_record(sc,
2288 (struct an_ltv_gen *)&sc->areq)) {
2294 bzero(&ch, sizeof(ch));
2295 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2297 ch.ic_flags = IEEE80211_CHAN_B;
2298 ch.ic_ieee = status->an_cur_channel;
2299 error = copyout(&ch, ireq->i_data, sizeof(ch));
2301 case IEEE80211_IOC_POWERSAVE:
2303 sc->areq.an_type = AN_RID_ACTUALCFG;
2304 if (an_read_record(sc,
2305 (struct an_ltv_gen *)&sc->areq)) {
2311 if (config->an_psave_mode == AN_PSAVE_NONE) {
2312 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2313 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2314 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2315 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2316 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2317 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2318 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2322 case IEEE80211_IOC_POWERSAVESLEEP:
2324 sc->areq.an_type = AN_RID_ACTUALCFG;
2325 if (an_read_record(sc,
2326 (struct an_ltv_gen *)&sc->areq)) {
2332 ireq->i_val = config->an_listen_interval;
2337 if ((error = priv_check(td, PRIV_NET80211_MANAGE)))
2340 sc->areq.an_len = sizeof(sc->areq);
2342 * We need a config structure for everything but the WEP
2343 * key management and SSIDs so we get it now so avoid
2344 * duplicating this code every time.
2346 if (ireq->i_type != IEEE80211_IOC_SSID &&
2347 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2348 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2349 sc->areq.an_type = AN_RID_GENCONFIG;
2350 if (an_read_record(sc,
2351 (struct an_ltv_gen *)&sc->areq)) {
2357 switch (ireq->i_type) {
2358 case IEEE80211_IOC_SSID:
2359 sc->areq.an_len = sizeof(sc->areq);
2360 sc->areq.an_type = AN_RID_SSIDLIST;
2361 if (an_read_record(sc,
2362 (struct an_ltv_gen *)&sc->areq)) {
2367 if (ireq->i_len > IEEE80211_NWID_LEN) {
2372 max = (sc->areq.an_len - 4)
2373 / sizeof(struct an_ltv_ssid_entry);
2374 if ( max > MAX_SSIDS ) {
2375 printf("To many SSIDs only using "
2380 if (ireq->i_val > max) {
2385 error = copyin(ireq->i_data,
2386 ssids->an_entry[ireq->i_val].an_ssid,
2388 ssids->an_entry[ireq->i_val].an_len
2390 sc->areq.an_len = sizeof(sc->areq);
2391 sc->areq.an_type = AN_RID_SSIDLIST;
2392 an_setdef(sc, &sc->areq);
2397 case IEEE80211_IOC_WEP:
2398 switch (ireq->i_val) {
2399 case IEEE80211_WEP_OFF:
2400 config->an_authtype &=
2401 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2402 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2404 case IEEE80211_WEP_ON:
2405 config->an_authtype |=
2406 AN_AUTHTYPE_PRIVACY_IN_USE;
2407 config->an_authtype &=
2408 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2410 case IEEE80211_WEP_MIXED:
2411 config->an_authtype |=
2412 AN_AUTHTYPE_PRIVACY_IN_USE |
2413 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2419 if (error != EINVAL)
2420 an_setdef(sc, &sc->areq);
2423 case IEEE80211_IOC_WEPKEY:
2424 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2430 error = copyin(ireq->i_data, tmpstr, 13);
2436 * Map the 9th key into the home mode
2437 * since that is how it is stored on
2440 bzero(&sc->areq, sizeof(struct an_ltv_key));
2441 sc->areq.an_len = sizeof(struct an_ltv_key);
2442 key->mac[0] = 1; /* The others are 0. */
2443 if (ireq->i_val < 4) {
2444 sc->areq.an_type = AN_RID_WEP_TEMP;
2445 key->kindex = ireq->i_val;
2447 sc->areq.an_type = AN_RID_WEP_PERM;
2448 key->kindex = ireq->i_val - 4;
2450 key->klen = ireq->i_len;
2451 bcopy(tmpstr, key->key, key->klen);
2452 an_setdef(sc, &sc->areq);
2455 case IEEE80211_IOC_WEPTXKEY:
2456 if (ireq->i_val < 0 || ireq->i_val > 4) {
2463 * Map the 5th key into the home mode
2464 * since that is how it is stored on
2467 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2468 sc->areq.an_type = AN_RID_ACTUALCFG;
2469 if (an_read_record(sc,
2470 (struct an_ltv_gen *)&sc->areq)) {
2475 if (ireq->i_val == 4) {
2476 config->an_home_product |= AN_HOME_NETWORK;
2479 config->an_home_product &= ~AN_HOME_NETWORK;
2482 sc->an_config.an_home_product
2483 = config->an_home_product;
2485 /* update configuration */
2488 bzero(&sc->areq, sizeof(struct an_ltv_key));
2489 sc->areq.an_len = sizeof(struct an_ltv_key);
2490 sc->areq.an_type = AN_RID_WEP_PERM;
2491 key->kindex = 0xffff;
2492 key->mac[0] = ireq->i_val;
2493 an_setdef(sc, &sc->areq);
2496 case IEEE80211_IOC_AUTHMODE:
2497 switch (ireq->i_val) {
2498 case IEEE80211_AUTH_NONE:
2499 config->an_authtype = AN_AUTHTYPE_NONE |
2500 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2502 case IEEE80211_AUTH_OPEN:
2503 config->an_authtype = AN_AUTHTYPE_OPEN |
2504 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2506 case IEEE80211_AUTH_SHARED:
2507 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2508 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2513 if (error != EINVAL) {
2514 an_setdef(sc, &sc->areq);
2518 case IEEE80211_IOC_STATIONNAME:
2519 if (ireq->i_len > 16) {
2524 bzero(config->an_nodename, 16);
2525 error = copyin(ireq->i_data,
2526 config->an_nodename, ireq->i_len);
2527 an_setdef(sc, &sc->areq);
2530 case IEEE80211_IOC_CHANNEL:
2532 * The actual range is 1-14, but if you set it
2533 * to 0 you get the default so we let that work
2536 if (ireq->i_val < 0 || ireq->i_val >14) {
2541 config->an_ds_channel = ireq->i_val;
2542 an_setdef(sc, &sc->areq);
2545 case IEEE80211_IOC_POWERSAVE:
2546 switch (ireq->i_val) {
2547 case IEEE80211_POWERSAVE_OFF:
2548 config->an_psave_mode = AN_PSAVE_NONE;
2550 case IEEE80211_POWERSAVE_CAM:
2551 config->an_psave_mode = AN_PSAVE_CAM;
2553 case IEEE80211_POWERSAVE_PSP:
2554 config->an_psave_mode = AN_PSAVE_PSP;
2556 case IEEE80211_POWERSAVE_PSP_CAM:
2557 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2563 an_setdef(sc, &sc->areq);
2566 case IEEE80211_IOC_POWERSAVESLEEP:
2567 config->an_listen_interval = ireq->i_val;
2568 an_setdef(sc, &sc->areq);
2579 an_setdef(sc, &sc->areq);
2585 error = ether_ioctl(ifp, command, data);
2594 an_init_tx_ring(struct an_softc *sc)
2603 for (i = 0; i < AN_TX_RING_CNT; i++) {
2604 if (an_alloc_nicmem(sc, 1518 +
2607 sc->an_rdata.an_tx_fids[i] = id;
2608 sc->an_rdata.an_tx_ring[i] = 0;
2612 sc->an_rdata.an_tx_prod = 0;
2613 sc->an_rdata.an_tx_cons = 0;
2614 sc->an_rdata.an_tx_empty = 1;
2622 struct an_softc *sc = xsc;
2630 an_init_locked(struct an_softc *sc)
2639 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2642 sc->an_associated = 0;
2644 /* Allocate the TX buffers */
2645 if (an_init_tx_ring(sc)) {
2648 an_init_mpi350_desc(sc);
2649 if (an_init_tx_ring(sc)) {
2650 if_printf(ifp, "tx buffer allocation failed\n");
2655 /* Set our MAC address. */
2656 bcopy((char *)IF_LLADDR(sc->an_ifp),
2657 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2659 if (ifp->if_flags & IFF_BROADCAST)
2660 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2662 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2664 if (ifp->if_flags & IFF_MULTICAST)
2665 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2667 if (ifp->if_flags & IFF_PROMISC) {
2668 if (sc->an_monitor & AN_MONITOR) {
2669 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2670 sc->an_config.an_rxmode |=
2671 AN_RXMODE_80211_MONITOR_ANYBSS |
2672 AN_RXMODE_NO_8023_HEADER;
2674 sc->an_config.an_rxmode |=
2675 AN_RXMODE_80211_MONITOR_CURBSS |
2676 AN_RXMODE_NO_8023_HEADER;
2682 if (sc->an_have_rssimap)
2683 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2686 /* Set the ssid list */
2687 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2688 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2689 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2690 if_printf(ifp, "failed to set ssid list\n");
2694 /* Set the AP list */
2695 sc->an_aplist.an_type = AN_RID_APLIST;
2696 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2697 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2698 if_printf(ifp, "failed to set AP list\n");
2702 /* Set the configuration in the NIC */
2703 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2704 sc->an_config.an_type = AN_RID_GENCONFIG;
2705 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2706 if_printf(ifp, "failed to set configuration\n");
2710 /* Enable the MAC */
2711 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2712 if_printf(ifp, "failed to enable MAC\n");
2716 if (ifp->if_flags & IFF_PROMISC)
2717 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2719 /* enable interrupts */
2720 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2722 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2723 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2725 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2731 an_start(struct ifnet *ifp)
2733 struct an_softc *sc;
2737 an_start_locked(ifp);
2742 an_start_locked(struct ifnet *ifp)
2744 struct an_softc *sc;
2745 struct mbuf *m0 = NULL;
2746 struct an_txframe_802_3 tx_frame_802_3;
2747 struct ether_header *eh;
2749 unsigned char txcontrol;
2750 struct an_card_tx_desc an_tx_desc;
2759 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2762 if (!sc->an_associated)
2765 /* We can't send in monitor mode so toss any attempts. */
2766 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2768 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2776 idx = sc->an_rdata.an_tx_prod;
2779 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2781 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2782 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2786 id = sc->an_rdata.an_tx_fids[idx];
2787 eh = mtod(m0, struct ether_header *);
2789 bcopy((char *)&eh->ether_dhost,
2790 (char *)&tx_frame_802_3.an_tx_dst_addr,
2792 bcopy((char *)&eh->ether_shost,
2793 (char *)&tx_frame_802_3.an_tx_src_addr,
2796 /* minus src/dest mac & type */
2797 tx_frame_802_3.an_tx_802_3_payload_len =
2798 m0->m_pkthdr.len - 12;
2800 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2801 tx_frame_802_3.an_tx_802_3_payload_len,
2802 (caddr_t)&sc->an_txbuf);
2804 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2805 /* write the txcontrol only */
2806 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2810 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2811 sizeof(struct an_txframe_802_3));
2813 /* in mbuf header type is just before payload */
2814 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2815 tx_frame_802_3.an_tx_802_3_payload_len);
2818 * If there's a BPF listner, bounce a copy of
2819 * this frame to him.
2826 sc->an_rdata.an_tx_ring[idx] = id;
2827 if (an_cmd(sc, AN_CMD_TX, id))
2828 if_printf(ifp, "xmit failed\n");
2830 AN_INC(idx, AN_TX_RING_CNT);
2833 * Set a timeout in case the chip goes out to lunch.
2837 } else { /* MPI-350 */
2838 /* Disable interrupts. */
2839 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2841 while (sc->an_rdata.an_tx_empty ||
2842 idx != sc->an_rdata.an_tx_cons) {
2843 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2847 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2849 eh = mtod(m0, struct ether_header *);
2851 /* DJA optimize this to limit bcopy */
2852 bcopy((char *)&eh->ether_dhost,
2853 (char *)&tx_frame_802_3.an_tx_dst_addr,
2855 bcopy((char *)&eh->ether_shost,
2856 (char *)&tx_frame_802_3.an_tx_src_addr,
2859 /* minus src/dest mac & type */
2860 tx_frame_802_3.an_tx_802_3_payload_len =
2861 m0->m_pkthdr.len - 12;
2863 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2864 tx_frame_802_3.an_tx_802_3_payload_len,
2865 (caddr_t)&sc->an_txbuf);
2867 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2868 /* write the txcontrol only */
2869 bcopy((caddr_t)&txcontrol, &buf[0x08],
2873 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2874 sizeof(struct an_txframe_802_3));
2876 /* in mbuf header type is just before payload */
2877 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2878 tx_frame_802_3.an_tx_802_3_payload_len);
2881 bzero(&an_tx_desc, sizeof(an_tx_desc));
2882 an_tx_desc.an_offset = 0;
2883 an_tx_desc.an_eoc = 1;
2884 an_tx_desc.an_valid = 1;
2885 an_tx_desc.an_len = 0x44 +
2886 tx_frame_802_3.an_tx_802_3_payload_len;
2888 = sc->an_tx_buffer[idx].an_dma_paddr;
2889 for (i = sizeof(an_tx_desc) / 4 - 1; i >= 0; i--) {
2890 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2892 + (0 * sizeof(an_tx_desc))
2894 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2898 * If there's a BPF listner, bounce a copy of
2899 * this frame to him.
2905 AN_INC(idx, AN_MAX_TX_DESC);
2906 sc->an_rdata.an_tx_empty = 0;
2907 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2910 * Set a timeout in case the chip goes out to lunch.
2915 /* Re-enable interrupts. */
2916 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2920 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2922 sc->an_rdata.an_tx_prod = idx;
2928 an_stop(struct an_softc *sc)
2940 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2941 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2942 an_cmd(sc, AN_CMD_DISABLE, 0);
2944 for (i = 0; i < AN_TX_RING_CNT; i++)
2945 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2947 callout_stop(&sc->an_stat_ch);
2949 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2951 if (sc->an_flash_buffer) {
2952 free(sc->an_flash_buffer, M_DEVBUF);
2953 sc->an_flash_buffer = NULL;
2958 an_watchdog(struct an_softc *sc)
2968 if_printf(ifp, "device timeout\n");
2972 an_init_mpi350_desc(sc);
2979 an_shutdown(device_t dev)
2981 struct an_softc *sc;
2983 sc = device_get_softc(dev);
2993 an_resume(device_t dev)
2995 struct an_softc *sc;
2999 sc = device_get_softc(dev);
3006 an_init_mpi350_desc(sc);
3009 /* Recovery temporary keys */
3010 for (i = 0; i < 4; i++) {
3011 sc->areq.an_type = AN_RID_WEP_TEMP;
3012 sc->areq.an_len = sizeof(struct an_ltv_key);
3013 bcopy(&sc->an_temp_keys[i],
3014 &sc->areq, sizeof(struct an_ltv_key));
3015 an_setdef(sc, &sc->areq);
3018 if (ifp->if_flags & IFF_UP)
3019 an_start_locked(ifp);
3026 /* Aironet signal strength cache code.
3027 * store signal/noise/quality on per MAC src basis in
3028 * a small fixed cache. The cache wraps if > MAX slots
3029 * used. The cache may be zeroed out to start over.
3030 * Two simple filters exist to reduce computation:
3031 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
3032 * to ignore some packets. It defaults to ip only.
3033 * it could be used to focus on broadcast, non-IP 802.11 beacons.
3034 * 2. multicast/broadcast only. This may be used to
3035 * ignore unicast packets and only cache signal strength
3036 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
3037 * beacons and not unicast traffic.
3039 * The cache stores (MAC src(index), IP src (major clue), signal,
3042 * No apologies for storing IP src here. It's easy and saves much
3043 * trouble elsewhere. The cache is assumed to be INET dependent,
3044 * although it need not be.
3046 * Note: the Aironet only has a single byte of signal strength value
3047 * in the rx frame header, and it's not scaled to anything sensible.
3048 * This is kind of lame, but it's all we've got.
3051 #ifdef documentation
3053 int an_sigitems; /* number of cached entries */
3054 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
3055 int an_nextitem; /* index/# of entries */
3060 /* control variables for cache filtering. Basic idea is
3061 * to reduce cost (e.g., to only Mobile-IP agent beacons
3062 * which are broadcast or multicast). Still you might
3063 * want to measure signal strength anth unicast ping packets
3064 * on a pt. to pt. ant. setup.
3066 /* set true if you want to limit cache items to broadcast/mcast
3067 * only packets (not unicast). Useful for mobile-ip beacons which
3068 * are broadcast/multicast at network layer. Default is all packets
3069 * so ping/unicast anll work say anth pt. to pt. antennae setup.
3071 static int an_cache_mcastonly = 0;
3072 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
3073 &an_cache_mcastonly, 0, "");
3075 /* set true if you want to limit cache items to IP packets only
3077 static int an_cache_iponly = 1;
3078 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
3079 &an_cache_iponly, 0, "");
3082 * an_cache_store, per rx packet store signal
3083 * strength in MAC (src) indexed cache.
3086 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
3087 u_int8_t rx_rssi, u_int8_t rx_quality)
3091 static int cache_slot = 0; /* use this cache entry */
3092 static int wrapindex = 0; /* next "free" cache entry */
3097 * 2. configurable filter to throw out unicast packets,
3098 * keep multicast only.
3101 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
3105 /* filter for ip packets only
3107 if ( an_cache_iponly && !type_ipv4) {
3111 /* filter for broadcast/multicast only
3113 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3118 if_printf(sc->an_ifp, "q value %x (MSB=0x%x, LSB=0x%x) \n",
3119 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3122 /* find the ip header. we want to store the ip_src
3126 ip = mtod(m, struct ip *);
3129 /* do a linear search for a matching MAC address
3130 * in the cache table
3131 * . MAC address is 6 bytes,
3132 * . var w_nextitem holds total number of entries already cached
3134 for (i = 0; i < sc->an_nextitem; i++) {
3135 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3137 * so we already have this entry,
3144 /* did we find a matching mac address?
3145 * if yes, then overwrite a previously existing cache entry
3147 if (i < sc->an_nextitem ) {
3150 /* else, have a new address entry,so
3151 * add this new entry,
3152 * if table full, then we need to replace LRU entry
3156 /* check for space in cache table
3157 * note: an_nextitem also holds number of entries
3158 * added in the cache table
3160 if ( sc->an_nextitem < MAXANCACHE ) {
3161 cache_slot = sc->an_nextitem;
3163 sc->an_sigitems = sc->an_nextitem;
3165 /* no space found, so simply wrap anth wrap index
3166 * and "zap" the next entry
3169 if (wrapindex == MAXANCACHE) {
3172 cache_slot = wrapindex++;
3176 /* invariant: cache_slot now points at some slot
3179 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3180 log(LOG_ERR, "an_cache_store, bad index: %d of "
3181 "[0..%d], gross cache error\n",
3182 cache_slot, MAXANCACHE);
3186 /* store items in cache
3187 * .ip source address
3192 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3194 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3197 switch (an_cache_mode) {
3199 if (sc->an_have_rssimap) {
3200 sc->an_sigcache[cache_slot].signal =
3201 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3202 sc->an_sigcache[cache_slot].quality =
3203 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3205 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3206 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3210 if (sc->an_have_rssimap) {
3211 sc->an_sigcache[cache_slot].signal =
3212 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3213 sc->an_sigcache[cache_slot].quality =
3214 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3218 if (rx_quality > 100)
3220 sc->an_sigcache[cache_slot].signal = rx_rssi;
3221 sc->an_sigcache[cache_slot].quality = rx_quality;
3225 sc->an_sigcache[cache_slot].signal = rx_rssi;
3226 sc->an_sigcache[cache_slot].quality = rx_quality;
3230 sc->an_sigcache[cache_slot].noise = 0;
3237 an_media_change(struct ifnet *ifp)
3239 struct an_softc *sc = ifp->if_softc;
3240 struct an_ltv_genconfig *cfg;
3241 int otype = sc->an_config.an_opmode;
3242 int orate = sc->an_tx_rate;
3245 sc->an_tx_rate = ieee80211_media2rate(
3246 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3247 if (sc->an_tx_rate < 0)
3250 if (orate != sc->an_tx_rate) {
3251 /* Read the current configuration */
3252 sc->an_config.an_type = AN_RID_GENCONFIG;
3253 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3254 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3255 cfg = &sc->an_config;
3257 /* clear other rates and set the only one we want */
3258 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3259 cfg->an_rates[0] = sc->an_tx_rate;
3261 /* Save the new rate */
3262 sc->an_config.an_type = AN_RID_GENCONFIG;
3263 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3266 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3267 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3269 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3271 if (otype != sc->an_config.an_opmode ||
3272 orate != sc->an_tx_rate)
3280 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3282 struct an_ltv_status status;
3283 struct an_softc *sc = ifp->if_softc;
3285 imr->ifm_active = IFM_IEEE80211;
3288 status.an_len = sizeof(status);
3289 status.an_type = AN_RID_STATUS;
3290 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3291 /* If the status read fails, just lie. */
3292 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3293 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3296 if (sc->an_tx_rate == 0) {
3297 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3300 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3301 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3302 imr->ifm_active |= ieee80211_rate2media(NULL,
3303 status.an_current_tx_rate, IEEE80211_MODE_AUTO);
3304 imr->ifm_status = IFM_AVALID;
3305 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3306 imr->ifm_status |= IFM_ACTIVE;
3310 /********************** Cisco utility support routines *************/
3313 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3318 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3321 struct an_softc *sc;
3324 switch (l_ioctl->command) {
3326 rid = AN_RID_CAPABILITIES;
3329 rid = AN_RID_GENCONFIG;
3332 rid = AN_RID_SSIDLIST;
3335 rid = AN_RID_APLIST;
3338 rid = AN_RID_DRVNAME;
3341 rid = AN_RID_ENCAPPROTO;
3344 rid = AN_RID_WEP_TEMP;
3347 rid = AN_RID_WEP_PERM;
3350 rid = AN_RID_STATUS;
3353 rid = AN_RID_32BITS_DELTA;
3356 rid = AN_RID_32BITS_CUM;
3363 if (rid == 999) /* Is bad command */
3367 sc->areq.an_len = AN_MAX_DATALEN;
3368 sc->areq.an_type = rid;
3370 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3372 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3375 /* the data contains the length at first */
3376 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3377 sizeof(sc->areq.an_len))) {
3381 /* Just copy the data back */
3382 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3394 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3396 struct an_softc *sc;
3397 int rid, command, error;
3402 command = l_ioctl->command;
3406 rid = AN_RID_SSIDLIST;
3409 rid = AN_RID_CAPABILITIES;
3412 rid = AN_RID_APLIST;
3415 rid = AN_RID_GENCONFIG;
3418 an_cmd(sc, AN_CMD_ENABLE, 0);
3422 an_cmd(sc, AN_CMD_DISABLE, 0);
3427 * This command merely clears the counts does not actually
3428 * store any data only reads rid. But as it changes the cards
3429 * state, I put it in the writerid routines.
3432 rid = AN_RID_32BITS_DELTACLR;
3434 sc->areq.an_len = AN_MAX_DATALEN;
3435 sc->areq.an_type = rid;
3437 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3438 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3441 /* the data contains the length at first */
3442 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3443 sizeof(sc->areq.an_len));
3448 /* Just copy the data */
3449 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3457 rid = AN_RID_WEP_TEMP;
3460 rid = AN_RID_WEP_PERM;
3463 rid = AN_RID_LEAPUSERNAME;
3466 rid = AN_RID_LEAPPASSWORD;
3473 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3475 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3476 sc->areq.an_type = rid;
3478 /* Just copy the data back */
3480 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3486 an_cmd(sc, AN_CMD_DISABLE, 0);
3487 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3488 an_cmd(sc, AN_CMD_ENABLE, 0);
3495 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3499 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3500 "flash", ((x) / hz) + 1);
3501 #define FLASH_COMMAND 0x7e7e
3502 #define FLASH_SIZE 32 * 1024
3505 unstickbusy(struct ifnet *ifp)
3507 struct an_softc *sc = ifp->if_softc;
3509 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3510 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3511 AN_EV_CLR_STUCK_BUSY);
3518 * Wait for busy completion from card wait for delay uSec's Return true for
3519 * success meaning command reg is clear
3523 WaitBusy(struct ifnet *ifp, int uSec)
3525 int statword = 0xffff;
3527 struct an_softc *sc = ifp->if_softc;
3529 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3530 FLASH_DELAY(sc, 10);
3532 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3534 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3539 return 0 == (AN_CMD_BUSY & statword);
3543 * STEP 1) Disable MAC and do soft reset on card.
3547 cmdreset(struct ifnet *ifp)
3550 struct an_softc *sc = ifp->if_softc;
3555 an_cmd(sc, AN_CMD_DISABLE, 0);
3557 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3558 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3562 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3564 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3567 if (!(status = WaitBusy(ifp, 100))) {
3568 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3577 * STEP 2) Put the card in legendary flash mode
3581 setflashmode(struct ifnet *ifp)
3584 struct an_softc *sc = ifp->if_softc;
3586 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3587 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3588 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3589 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3592 * mdelay(500); // 500ms delay
3595 FLASH_DELAY(sc, 500);
3597 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3598 printf("Waitbusy hang after setflash mode\n");
3605 * Get a character from the card matching matchbyte Step 3)
3609 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3612 unsigned char rbyte = 0;
3614 struct an_softc *sc = ifp->if_softc;
3618 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3620 if (dwelltime && !(0x8000 & rchar)) {
3622 FLASH_DELAY(sc, 10);
3625 rbyte = 0xff & rchar;
3627 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3628 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3632 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3634 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3636 } while (dwelltime > 0);
3641 * Put character to SWS0 wait for dwelltime x 50us for echo .
3645 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3648 int pollbusy, waittime;
3649 struct an_softc *sc = ifp->if_softc;
3656 waittime = dwelltime;
3659 * Wait for busy bit d15 to go false indicating buffer empty
3662 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3664 if (pollbusy & 0x8000) {
3665 FLASH_DELAY(sc, 50);
3671 while (waittime >= 0);
3673 /* timeout for busy clear wait */
3675 if (waittime <= 0) {
3676 if_printf(ifp, "flash putchar busywait timeout!\n");
3680 * Port is clear now write byte and wait for it to echo back
3683 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3684 FLASH_DELAY(sc, 50);
3686 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3687 } while (dwelltime >= 0 && echo != byte);
3690 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3692 return echo == byte;
3696 * Transfer 32k of firmware data from user buffer to our buffer and send to
3701 flashputbuf(struct ifnet *ifp)
3703 unsigned short *bufp;
3705 struct an_softc *sc = ifp->if_softc;
3709 bufp = sc->an_flash_buffer;
3712 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3713 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3715 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3716 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3719 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3720 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3721 ((u_int32_t *)bufp)[nwords] & 0xffff);
3725 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3731 * After flashing restart the card.
3735 flashrestart(struct ifnet *ifp)
3738 struct an_softc *sc = ifp->if_softc;
3740 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3744 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3749 * Entry point for flash ioclt.
3753 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3756 struct an_softc *sc;
3760 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3763 status = l_ioctl->command;
3765 switch (l_ioctl->command) {
3767 return cmdreset(ifp);
3770 if (sc->an_flash_buffer) {
3771 free(sc->an_flash_buffer, M_DEVBUF);
3772 sc->an_flash_buffer = NULL;
3774 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3775 if (sc->an_flash_buffer)
3776 return setflashmode(ifp);
3780 case AIROFLSHGCHR: /* Get char from aux */
3782 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3786 z = *(int *)&sc->areq;
3787 if ((status = flashgchar(ifp, z, 8000)) == 1)
3791 case AIROFLSHPCHR: /* Send char to card. */
3793 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3797 z = *(int *)&sc->areq;
3798 if ((status = flashpchar(ifp, z, 8000)) == -1)
3803 case AIROFLPUTBUF: /* Send 32k to card */
3804 if (l_ioctl->len > FLASH_SIZE) {
3805 if_printf(ifp, "Buffer to big, %x %x\n",
3806 l_ioctl->len, FLASH_SIZE);
3810 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3815 if ((status = flashputbuf(ifp)) != 0)
3821 if ((status = flashrestart(ifp)) != 0) {
3822 if_printf(ifp, "FLASHRESTART returned %d\n", status);