2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 1997, 1998, 1999
5 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
37 * Written by Bill Paul <wpaul@ctr.columbia.edu>
38 * Electrical Engineering Department
39 * Columbia University, New York City
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
46 * The Aironet 4500/4800 series cards come in PCMCIA, ISA and PCI form.
47 * This driver supports all three device types (PCI devices are supported
48 * through an extra PCI shim: /sys/dev/an/if_an_pci.c). ISA devices can be
49 * supported either using hard-coded IO port/IRQ settings or via Plug
50 * and Play. The 4500 series devices support 1Mbps and 2Mbps data rates.
51 * The 4800 devices support 1, 2, 5.5 and 11Mbps rates.
53 * Like the WaveLAN/IEEE cards, the Aironet NICs are all essentially
54 * PCMCIA devices. The ISA and PCI cards are a combination of a PCMCIA
55 * device and a PCMCIA to ISA or PCMCIA to PCI adapter card. There are
56 * a couple of important differences though:
58 * - Lucent ISA card looks to the host like a PCMCIA controller with
59 * a PCMCIA WaveLAN card inserted. This means that even desktop
60 * machines need to be configured with PCMCIA support in order to
61 * use WaveLAN/IEEE ISA cards. The Aironet cards on the other hand
62 * actually look like normal ISA and PCI devices to the host, so
63 * no PCMCIA controller support is needed
65 * The latter point results in a small gotcha. The Aironet PCMCIA
66 * cards can be configured for one of two operating modes depending
67 * on how the Vpp1 and Vpp2 programming voltages are set when the
68 * card is activated. In order to put the card in proper PCMCIA
69 * operation (where the CIS table is visible and the interface is
70 * programmed for PCMCIA operation), both Vpp1 and Vpp2 have to be
71 * set to 5 volts. FreeBSD by default doesn't set the Vpp voltages,
72 * which leaves the card in ISA/PCI mode, which prevents it from
73 * being activated as an PCMCIA device.
75 * Note that some PCMCIA controller software packages for Windows NT
76 * fail to set the voltages as well.
78 * The Aironet devices can operate in both station mode and access point
79 * mode. Typically, when programmed for station mode, the card can be set
80 * to automatically perform encapsulation/decapsulation of Ethernet II
81 * and 802.3 frames within 802.11 frames so that the host doesn't have
82 * to do it itself. This driver doesn't program the card that way: the
83 * driver handles all of the encapsulation/decapsulation itself.
89 #define ANCACHE /* enable signal strength cache */
92 #include <sys/param.h>
93 #include <sys/ctype.h>
94 #include <sys/systm.h>
95 #include <sys/sockio.h>
99 #include <sys/kernel.h>
100 #include <sys/socket.h>
102 #include <sys/syslog.h>
104 #include <sys/sysctl.h>
106 #include <sys/module.h>
108 #include <machine/bus.h>
109 #include <sys/rman.h>
110 #include <sys/lock.h>
111 #include <sys/mutex.h>
112 #include <machine/resource.h>
113 #include <sys/malloc.h>
116 #include <net/if_var.h>
117 #include <net/if_arp.h>
118 #include <net/if_dl.h>
119 #include <net/ethernet.h>
120 #include <net/if_types.h>
121 #include <net/if_media.h>
123 #include <net80211/ieee80211_var.h>
124 #include <net80211/ieee80211_ioctl.h>
127 #include <netinet/in.h>
128 #include <netinet/in_systm.h>
129 #include <netinet/in_var.h>
130 #include <netinet/ip.h>
135 #include <machine/md_var.h>
137 #include <dev/an/if_aironet_ieee.h>
138 #include <dev/an/if_anreg.h>
140 /* These are global because we need them in sys/pci/if_an_p.c. */
141 static void an_reset(struct an_softc *);
142 static int an_init_mpi350_desc(struct an_softc *);
143 static int an_ioctl(struct ifnet *, u_long, caddr_t);
144 static void an_init(void *);
145 static void an_init_locked(struct an_softc *);
146 static int an_init_tx_ring(struct an_softc *);
147 static void an_start(struct ifnet *);
148 static void an_start_locked(struct ifnet *);
149 static void an_watchdog(struct an_softc *);
150 static void an_rxeof(struct an_softc *);
151 static void an_txeof(struct an_softc *, int);
153 static void an_promisc(struct an_softc *, int);
154 static int an_cmd(struct an_softc *, int, int);
155 static int an_cmd_struct(struct an_softc *, struct an_command *,
157 static int an_read_record(struct an_softc *, struct an_ltv_gen *);
158 static int an_write_record(struct an_softc *, struct an_ltv_gen *);
159 static int an_read_data(struct an_softc *, int, int, caddr_t, int);
160 static int an_write_data(struct an_softc *, int, int, caddr_t, int);
161 static int an_seek(struct an_softc *, int, int, int);
162 static int an_alloc_nicmem(struct an_softc *, int, int *);
163 static int an_dma_malloc(struct an_softc *, bus_size_t, struct an_dma_alloc *,
165 static void an_dma_free(struct an_softc *, struct an_dma_alloc *);
166 static void an_dma_malloc_cb(void *, bus_dma_segment_t *, int, int);
167 static void an_stats_update(void *);
168 static void an_setdef(struct an_softc *, struct an_req *);
170 static void an_cache_store(struct an_softc *, struct ether_header *,
171 struct mbuf *, u_int8_t, u_int8_t);
174 /* function definitions for use with the Cisco's Linux configuration
178 static int readrids(struct ifnet*, struct aironet_ioctl*);
179 static int writerids(struct ifnet*, struct aironet_ioctl*);
180 static int flashcard(struct ifnet*, struct aironet_ioctl*);
182 static int cmdreset(struct ifnet *);
183 static int setflashmode(struct ifnet *);
184 static int flashgchar(struct ifnet *,int,int);
185 static int flashpchar(struct ifnet *,int,int);
186 static int flashputbuf(struct ifnet *);
187 static int flashrestart(struct ifnet *);
188 static int WaitBusy(struct ifnet *, int);
189 static int unstickbusy(struct ifnet *);
191 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
194 static int an_media_change (struct ifnet *);
195 static void an_media_status (struct ifnet *, struct ifmediareq *);
197 static int an_dump = 0;
198 static int an_cache_mode = 0;
204 static char an_conf[256];
205 static char an_conf_cache[256];
209 static SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
210 "Wireless driver parameters");
212 /* XXX violate ethernet/netgraph callback hooks */
213 extern void (*ng_ether_attach_p)(struct ifnet *ifp);
214 extern void (*ng_ether_detach_p)(struct ifnet *ifp);
217 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
226 strcpy(an_conf, "off");
229 strcpy(an_conf, "type");
232 strcpy(an_conf, "dump");
235 snprintf(an_conf, 5, "%x", an_dump);
239 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
241 if (strncmp(an_conf,"off", 3) == 0) {
244 if (strncmp(an_conf,"dump", 4) == 0) {
247 if (strncmp(an_conf,"type", 4) == 0) {
253 if ((*s >= '0') && (*s <= '9')) {
254 r = r * 16 + (*s - '0');
255 } else if ((*s >= 'a') && (*s <= 'f')) {
256 r = r * 16 + (*s - 'a' + 10);
264 printf("Sysctl changed for Aironet driver\n");
269 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump,
270 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 0, sizeof(an_conf),
275 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
279 switch (an_cache_mode) {
281 strcpy(an_conf_cache, "per");
284 strcpy(an_conf_cache, "raw");
287 strcpy(an_conf_cache, "dbm");
291 error = sysctl_handle_string(oidp, an_conf_cache,
292 sizeof(an_conf_cache), req);
294 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
297 if (strncmp(an_conf_cache,"per", 3) == 0) {
300 if (strncmp(an_conf_cache,"raw", 3) == 0) {
307 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode,
308 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 0, sizeof(an_conf_cache),
309 sysctl_an_cache_mode, "A",
313 * We probe for an Aironet 4500/4800 card by attempting to
314 * read the default SSID list. On reset, the first entry in
315 * the SSID list will contain the name "tsunami." If we don't
316 * find this, then there's no card present.
319 an_probe(device_t dev)
321 struct an_softc *sc = device_get_softc(dev);
322 struct an_ltv_ssidlist_new ssid;
325 bzero((char *)&ssid, sizeof(ssid));
327 error = an_alloc_port(dev, 0, AN_IOSIZ);
331 /* can't do autoprobing */
332 if (rman_get_start(sc->port_res) == -1)
336 * We need to fake up a softc structure long enough
337 * to be able to issue commands and call some of the
340 ssid.an_len = sizeof(ssid);
341 ssid.an_type = AN_RID_SSIDLIST;
343 /* Make sure interrupts are disabled. */
345 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
346 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
349 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
354 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
359 if (an_read_record(sc, (struct an_ltv_gen *)&ssid)) {
364 /* See if the ssid matches what we expect ... but doesn't have to */
365 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID)) {
373 mtx_destroy(&sc->an_mtx);
378 * Allocate a port resource with the given resource id.
381 an_alloc_port(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_anywhere(dev, SYS_RES_IOPORT, &rid,
398 * Allocate a memory resource with the given resource id.
400 int an_alloc_memory(device_t dev, int rid, int size)
402 struct an_softc *sc = device_get_softc(dev);
403 struct resource *res;
405 res = bus_alloc_resource_anywhere(dev, SYS_RES_MEMORY, &rid,
418 * Allocate a auxiliary memory resource with the given resource id.
420 int an_alloc_aux_memory(device_t dev, int rid, int size)
422 struct an_softc *sc = device_get_softc(dev);
423 struct resource *res;
425 res = bus_alloc_resource_anywhere(dev, SYS_RES_MEMORY, &rid,
428 sc->mem_aux_rid = rid;
429 sc->mem_aux_res = res;
430 sc->mem_aux_used = size;
438 * Allocate an irq resource with the given resource id.
441 an_alloc_irq(device_t dev, int rid, int flags)
443 struct an_softc *sc = device_get_softc(dev);
444 struct resource *res;
446 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
447 (RF_ACTIVE | flags));
458 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
460 bus_addr_t *paddr = (bus_addr_t*) arg;
461 *paddr = segs->ds_addr;
465 * Alloc DMA memory and set the pointer to it
468 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
473 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
474 BUS_DMA_NOWAIT, &dma->an_dma_map);
478 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
482 mapflags | BUS_DMA_NOWAIT);
486 dma->an_dma_size = size;
490 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
492 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
497 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
499 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
500 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
501 dma->an_dma_vaddr = 0;
505 * Release all resources
508 an_release_resources(device_t dev)
510 struct an_softc *sc = device_get_softc(dev);
514 bus_release_resource(dev, SYS_RES_IOPORT,
515 sc->port_rid, sc->port_res);
519 bus_release_resource(dev, SYS_RES_MEMORY,
520 sc->mem_rid, sc->mem_res);
523 if (sc->mem_aux_res) {
524 bus_release_resource(dev, SYS_RES_MEMORY,
525 sc->mem_aux_rid, sc->mem_aux_res);
529 bus_release_resource(dev, SYS_RES_IRQ,
530 sc->irq_rid, sc->irq_res);
533 if (sc->an_rid_buffer.an_dma_paddr) {
534 an_dma_free(sc, &sc->an_rid_buffer);
536 for (i = 0; i < AN_MAX_RX_DESC; i++)
537 if (sc->an_rx_buffer[i].an_dma_paddr) {
538 an_dma_free(sc, &sc->an_rx_buffer[i]);
540 for (i = 0; i < AN_MAX_TX_DESC; i++)
541 if (sc->an_tx_buffer[i].an_dma_paddr) {
542 an_dma_free(sc, &sc->an_tx_buffer[i]);
545 bus_dma_tag_destroy(sc->an_dtag);
551 an_init_mpi350_desc(struct an_softc *sc)
553 struct an_command cmd_struct;
554 struct an_reply reply;
555 struct an_card_rid_desc an_rid_desc;
556 struct an_card_rx_desc an_rx_desc;
557 struct an_card_tx_desc an_tx_desc;
561 if(!sc->an_rid_buffer.an_dma_paddr)
562 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
563 &sc->an_rid_buffer, 0);
564 for (i = 0; i < AN_MAX_RX_DESC; i++)
565 if(!sc->an_rx_buffer[i].an_dma_paddr)
566 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
567 &sc->an_rx_buffer[i], 0);
568 for (i = 0; i < AN_MAX_TX_DESC; i++)
569 if(!sc->an_tx_buffer[i].an_dma_paddr)
570 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
571 &sc->an_tx_buffer[i], 0);
574 * Allocate RX descriptor
576 bzero(&reply,sizeof(reply));
577 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
578 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
579 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
580 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
581 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
582 if_printf(sc->an_ifp, "failed to allocate RX descriptor\n");
586 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
587 bzero(&an_rx_desc, sizeof(an_rx_desc));
588 an_rx_desc.an_valid = 1;
589 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
590 an_rx_desc.an_done = 0;
591 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
593 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
594 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
595 + (desc * sizeof(an_rx_desc))
597 ((u_int32_t *)(void *)&an_rx_desc)[i]);
601 * Allocate TX descriptor
604 bzero(&reply,sizeof(reply));
605 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
606 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
607 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
608 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
609 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
610 if_printf(sc->an_ifp, "failed to allocate TX descriptor\n");
614 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
615 bzero(&an_tx_desc, sizeof(an_tx_desc));
616 an_tx_desc.an_offset = 0;
617 an_tx_desc.an_eoc = 0;
618 an_tx_desc.an_valid = 0;
619 an_tx_desc.an_len = 0;
620 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
622 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
623 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
624 + (desc * sizeof(an_tx_desc))
626 ((u_int32_t *)(void *)&an_tx_desc)[i]);
630 * Allocate RID descriptor
633 bzero(&reply,sizeof(reply));
634 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
635 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
636 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
637 cmd_struct.an_parm2 = 1;
638 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
639 if_printf(sc->an_ifp, "failed to allocate host descriptor\n");
643 bzero(&an_rid_desc, sizeof(an_rid_desc));
644 an_rid_desc.an_valid = 1;
645 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
646 an_rid_desc.an_rid = 0;
647 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
649 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
650 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
651 ((u_int32_t *)(void *)&an_rid_desc)[i]);
657 an_attach(struct an_softc *sc, int flags)
664 ifp = sc->an_ifp = if_alloc(IFT_ETHER);
666 device_printf(sc->an_dev, "can not if_alloc()\n");
670 if_initname(ifp, device_get_name(sc->an_dev),
671 device_get_unit(sc->an_dev));
674 sc->an_associated = 0;
676 sc->an_was_monitor = 0;
677 sc->an_flash_buffer = NULL;
683 error = an_init_mpi350_desc(sc);
688 /* Load factory config */
689 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
690 device_printf(sc->an_dev, "failed to load config data\n");
694 /* Read the current configuration */
695 sc->an_config.an_type = AN_RID_GENCONFIG;
696 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
697 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
698 device_printf(sc->an_dev, "read record failed\n");
702 /* Read the card capabilities */
703 sc->an_caps.an_type = AN_RID_CAPABILITIES;
704 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
705 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
706 device_printf(sc->an_dev, "read record failed\n");
711 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
712 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
713 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
714 device_printf(sc->an_dev, "read record failed\n");
719 sc->an_aplist.an_type = AN_RID_APLIST;
720 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
721 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
722 device_printf(sc->an_dev, "read record failed\n");
727 /* Read the RSSI <-> dBm map */
728 sc->an_have_rssimap = 0;
729 if (sc->an_caps.an_softcaps & 8) {
730 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
731 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
732 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
733 device_printf(sc->an_dev,
734 "unable to get RSSI <-> dBM map\n");
736 device_printf(sc->an_dev, "got RSSI <-> dBM map\n");
737 sc->an_have_rssimap = 1;
740 device_printf(sc->an_dev, "no RSSI <-> dBM map\n");
745 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
746 ifp->if_ioctl = an_ioctl;
747 ifp->if_start = an_start;
748 ifp->if_init = an_init;
749 ifp->if_baudrate = 10000000;
750 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
751 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
752 IFQ_SET_READY(&ifp->if_snd);
754 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
755 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
756 sizeof(AN_DEFAULT_NODENAME) - 1);
758 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
759 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
760 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
761 sizeof(AN_DEFAULT_NETNAME) - 1);
762 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
764 sc->an_config.an_opmode =
765 AN_OPMODE_INFRASTRUCTURE_STATION;
768 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
772 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
773 if_printf(ifp, "supported rates: ");
774 #define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
775 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
777 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
778 for (i = 0; i < nrate; i++) {
779 r = sc->an_caps.an_rates[i];
780 mword = ieee80211_rate2media(NULL, r, IEEE80211_MODE_AUTO);
783 printf("%s%d%sMbps", (i != 0 ? " " : ""),
784 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
786 ADD(mword, IFM_IEEE80211_ADHOC);
789 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
794 * Call MI attach routine.
797 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
798 callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0);
803 mtx_destroy(&sc->an_mtx);
810 an_detach(device_t dev)
812 struct an_softc *sc = device_get_softc(dev);
813 struct ifnet *ifp = sc->an_ifp;
816 device_printf(dev,"already unloaded\n");
822 ifmedia_removeall(&sc->an_ifmedia);
823 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
826 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
827 callout_drain(&sc->an_stat_ch);
829 an_release_resources(dev);
830 mtx_destroy(&sc->an_mtx);
835 an_rxeof(struct an_softc *sc)
838 struct ether_header *eh;
839 struct ieee80211_frame *ih;
840 struct an_rxframe rx_frame;
841 struct an_rxframe_802_3 rx_frame_802_3;
843 int len, id, error = 0, i, count = 0;
844 int ieee80211_header_len;
847 struct an_card_rx_desc an_rx_desc;
855 id = CSR_READ_2(sc, AN_RX_FID);
857 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
858 /* read raw 802.11 packet */
859 bpf_buf = sc->buf_802_11;
862 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
864 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
869 * skip beacon by default since this increases the
873 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
874 (rx_frame.an_frame_ctl &
875 IEEE80211_FC0_SUBTYPE_BEACON)) {
879 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
880 len = rx_frame.an_rx_payload_len
882 /* Check for insane frame length */
883 if (len > sizeof(sc->buf_802_11)) {
884 if_printf(ifp, "oversized packet "
885 "received (%d, %d)\n",
887 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
891 bcopy((char *)&rx_frame,
892 bpf_buf, sizeof(rx_frame));
894 error = an_read_data(sc, id, sizeof(rx_frame),
895 (caddr_t)bpf_buf+sizeof(rx_frame),
896 rx_frame.an_rx_payload_len);
898 fc1=rx_frame.an_frame_ctl >> 8;
899 ieee80211_header_len =
900 sizeof(struct ieee80211_frame);
901 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
902 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
903 ieee80211_header_len += ETHER_ADDR_LEN;
906 len = rx_frame.an_rx_payload_len
907 + ieee80211_header_len;
908 /* Check for insane frame length */
909 if (len > sizeof(sc->buf_802_11)) {
910 if_printf(ifp, "oversized packet "
911 "received (%d, %d)\n",
913 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
917 ih = (struct ieee80211_frame *)bpf_buf;
919 bcopy((char *)&rx_frame.an_frame_ctl,
920 (char *)ih, ieee80211_header_len);
922 error = an_read_data(sc, id, sizeof(rx_frame) +
924 (caddr_t)ih +ieee80211_header_len,
925 rx_frame.an_rx_payload_len);
927 /* dump raw 802.11 packet to bpf and skip ip stack */
928 BPF_TAP(ifp, bpf_buf, len);
930 MGETHDR(m, M_NOWAIT, MT_DATA);
932 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
935 if (!(MCLGET(m, M_NOWAIT))) {
937 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
940 m->m_pkthdr.rcvif = ifp;
941 /* Read Ethernet encapsulated packet */
944 /* Read NIC frame header */
945 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
948 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
952 /* Read in the 802_3 frame header */
953 if (an_read_data(sc, id, 0x34,
954 (caddr_t)&rx_frame_802_3,
955 sizeof(rx_frame_802_3))) {
957 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
960 if (rx_frame_802_3.an_rx_802_3_status != 0) {
962 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
965 /* Check for insane frame length */
966 len = rx_frame_802_3.an_rx_802_3_payload_len;
967 if (len > sizeof(sc->buf_802_11)) {
969 if_printf(ifp, "oversized packet "
970 "received (%d, %d)\n",
972 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
975 m->m_pkthdr.len = m->m_len =
976 rx_frame_802_3.an_rx_802_3_payload_len + 12;
978 eh = mtod(m, struct ether_header *);
980 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
981 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
982 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
983 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
985 /* in mbuf header type is just before payload */
986 error = an_read_data(sc, id, 0x44,
987 (caddr_t)&(eh->ether_type),
988 rx_frame_802_3.an_rx_802_3_payload_len);
992 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
995 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
997 /* Receive packet. */
999 an_cache_store(sc, eh, m,
1000 rx_frame.an_rx_signal_strength,
1004 (*ifp->if_input)(ifp, m);
1008 } else { /* MPI-350 */
1009 for (count = 0; count < AN_MAX_RX_DESC; count++){
1010 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1011 ((u_int32_t *)(void *)&an_rx_desc)[i]
1012 = CSR_MEM_AUX_READ_4(sc,
1014 + (count * sizeof(an_rx_desc))
1017 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1018 buf = sc->an_rx_buffer[count].an_dma_vaddr;
1020 MGETHDR(m, M_NOWAIT, MT_DATA);
1022 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1025 if (!(MCLGET(m, M_NOWAIT))) {
1027 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1030 m->m_pkthdr.rcvif = ifp;
1031 /* Read Ethernet encapsulated packet */
1034 * No ANCACHE support since we just get back
1035 * an Ethernet packet no 802.11 info
1039 /* Read NIC frame header */
1040 bcopy(buf, (caddr_t)&rx_frame,
1044 /* Check for insane frame length */
1045 len = an_rx_desc.an_len + 12;
1046 if (len > MCLBYTES) {
1048 if_printf(ifp, "oversized packet "
1049 "received (%d, %d)\n",
1051 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1055 m->m_pkthdr.len = m->m_len =
1056 an_rx_desc.an_len + 12;
1058 eh = mtod(m, struct ether_header *);
1060 bcopy(buf, (char *)eh,
1063 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
1065 /* Receive packet. */
1068 an_cache_store(sc, eh, m,
1069 rx_frame.an_rx_signal_strength,
1074 (*ifp->if_input)(ifp, m);
1077 an_rx_desc.an_valid = 1;
1078 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1079 an_rx_desc.an_done = 0;
1080 an_rx_desc.an_phys =
1081 sc->an_rx_buffer[count].an_dma_paddr;
1083 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1084 CSR_MEM_AUX_WRITE_4(sc,
1086 + (count * sizeof(an_rx_desc))
1088 ((u_int32_t *)(void *)&an_rx_desc)[i]);
1091 if_printf(ifp, "Didn't get valid RX packet "
1094 an_rx_desc.an_valid, an_rx_desc.an_len);
1101 an_txeof(struct an_softc *sc, int status)
1110 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1113 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1115 if (status & AN_EV_TX_EXC) {
1116 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1118 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1120 for (i = 0; i < AN_TX_RING_CNT; i++) {
1121 if (id == sc->an_rdata.an_tx_ring[i]) {
1122 sc->an_rdata.an_tx_ring[i] = 0;
1127 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1128 } else { /* MPI 350 */
1129 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1130 if (!sc->an_rdata.an_tx_empty){
1131 if (status & AN_EV_TX_EXC) {
1132 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1134 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1135 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1136 if (sc->an_rdata.an_tx_prod ==
1137 sc->an_rdata.an_tx_cons)
1138 sc->an_rdata.an_tx_empty = 1;
1146 * We abuse the stats updater to check the current NIC status. This
1147 * is important because we don't want to allow transmissions until
1148 * the NIC has synchronized to the current cell (either as the master
1149 * in an ad-hoc group, or as a station connected to an access point).
1151 * Note that this function will be called via callout(9) with a lock held.
1154 an_stats_update(void *xsc)
1156 struct an_softc *sc;
1162 if (sc->an_timer > 0 && --sc->an_timer == 0)
1165 sc->an_status.an_type = AN_RID_STATUS;
1166 sc->an_status.an_len = sizeof(struct an_ltv_status);
1167 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status))
1170 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1171 sc->an_associated = 1;
1173 sc->an_associated = 0;
1175 /* Don't do this while we're transmitting */
1176 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
1177 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1181 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1182 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1183 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len))
1186 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1194 struct an_softc *sc;
1198 sc = (struct an_softc*)xsc;
1209 /* Disable interrupts. */
1210 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1212 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1213 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1215 if (status & AN_EV_MIC) {
1216 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1219 if (status & AN_EV_LINKSTAT) {
1220 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1221 == AN_LINKSTAT_ASSOCIATED)
1222 sc->an_associated = 1;
1224 sc->an_associated = 0;
1225 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1228 if (status & AN_EV_RX) {
1230 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1233 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1234 an_txeof(sc, status);
1235 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1238 if (status & AN_EV_TX) {
1239 an_txeof(sc, status);
1240 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1243 if (status & AN_EV_TX_EXC) {
1244 an_txeof(sc, status);
1245 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1248 if (status & AN_EV_ALLOC)
1249 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1251 /* Re-enable interrupts. */
1252 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1254 if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1255 an_start_locked(ifp);
1263 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1264 struct an_reply *reply)
1269 for (i = 0; i != AN_TIMEOUT; i++) {
1270 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1276 if( i == AN_TIMEOUT) {
1281 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1282 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1283 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1284 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1286 for (i = 0; i < AN_TIMEOUT; i++) {
1287 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1292 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1293 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1294 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1295 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1297 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1298 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
1299 AN_EV_CLR_STUCK_BUSY);
1301 /* Ack the command */
1302 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1304 if (i == AN_TIMEOUT)
1311 an_cmd(struct an_softc *sc, int cmd, int val)
1316 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1317 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1318 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1319 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1321 for (i = 0; i < AN_TIMEOUT; i++) {
1322 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1325 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1326 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1330 for (i = 0; i < AN_TIMEOUT; i++) {
1331 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1332 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1333 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1334 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1335 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1339 /* Ack the command */
1340 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1342 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1343 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1345 if (i == AN_TIMEOUT)
1352 * This reset sequence may look a little strange, but this is the
1353 * most reliable method I've found to really kick the NIC in the
1354 * head and force it to reboot correctly.
1357 an_reset(struct an_softc *sc)
1363 an_cmd(sc, AN_CMD_ENABLE, 0);
1364 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1365 an_cmd(sc, AN_CMD_NOOP2, 0);
1367 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1368 device_printf(sc->an_dev, "reset failed\n");
1370 an_cmd(sc, AN_CMD_DISABLE, 0);
1376 * Read an LTV record from the NIC.
1379 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1381 struct an_ltv_gen *an_ltv;
1382 struct an_card_rid_desc an_rid_desc;
1383 struct an_command cmd;
1384 struct an_reply reply;
1391 if (ltv->an_len < 4 || ltv->an_type == 0)
1396 /* Tell the NIC to enter record read mode. */
1397 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1398 if_printf(ifp, "RID access failed\n");
1402 /* Seek to the record. */
1403 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1404 if_printf(ifp, "seek to record failed\n");
1409 * Read the length and record type and make sure they
1410 * match what we expect (this verifies that we have enough
1411 * room to hold all of the returned data).
1412 * Length includes type but not length.
1414 len = CSR_READ_2(sc, AN_DATA1);
1415 if (len > (ltv->an_len - 2)) {
1416 if_printf(ifp, "record length mismatch -- expected %d, "
1417 "got %d for Rid %x\n",
1418 ltv->an_len - 2, len, ltv->an_type);
1419 len = ltv->an_len - 2;
1421 ltv->an_len = len + 2;
1424 /* Now read the data. */
1425 len -= 2; /* skip the type */
1427 for (i = len; i > 1; i -= 2)
1428 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1430 ptr2 = (u_int8_t *)ptr;
1431 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1433 } else { /* MPI-350 */
1434 if (!sc->an_rid_buffer.an_dma_vaddr)
1436 an_rid_desc.an_valid = 1;
1437 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1438 an_rid_desc.an_rid = 0;
1439 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1440 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1442 bzero(&cmd, sizeof(cmd));
1443 bzero(&reply, sizeof(reply));
1444 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1445 cmd.an_parm0 = ltv->an_type;
1447 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1448 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1449 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1451 if (an_cmd_struct(sc, &cmd, &reply)
1452 || reply.an_status & AN_CMD_QUAL_MASK) {
1453 if_printf(ifp, "failed to read RID %x %x %x %x %x, %d\n",
1463 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1464 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1465 an_rid_desc.an_len = an_ltv->an_len;
1468 len = an_rid_desc.an_len;
1469 if (len > (ltv->an_len - 2)) {
1470 if_printf(ifp, "record length mismatch -- expected %d, "
1471 "got %d for Rid %x\n",
1472 ltv->an_len - 2, len, ltv->an_type);
1473 len = ltv->an_len - 2;
1475 ltv->an_len = len + 2;
1477 bcopy(&an_ltv->an_type,
1483 an_dump_record(sc, ltv, "Read");
1489 * Same as read, except we inject data instead of reading it.
1492 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1494 struct an_card_rid_desc an_rid_desc;
1495 struct an_command cmd;
1496 struct an_reply reply;
1503 an_dump_record(sc, ltv, "Write");
1506 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1509 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1513 * Length includes type but not length.
1515 len = ltv->an_len - 2;
1516 CSR_WRITE_2(sc, AN_DATA1, len);
1518 len -= 2; /* skip the type */
1520 for (i = len; i > 1; i -= 2)
1521 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1523 ptr2 = (u_int8_t *)ptr;
1524 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1527 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1532 for (i = 0; i != AN_TIMEOUT; i++) {
1533 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1539 if (i == AN_TIMEOUT) {
1543 an_rid_desc.an_valid = 1;
1544 an_rid_desc.an_len = ltv->an_len - 2;
1545 an_rid_desc.an_rid = ltv->an_type;
1546 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1548 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1549 an_rid_desc.an_len);
1551 bzero(&cmd,sizeof(cmd));
1552 bzero(&reply,sizeof(reply));
1553 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1554 cmd.an_parm0 = ltv->an_type;
1556 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1557 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1558 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1562 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1563 if_printf(sc->an_ifp,
1564 "failed to write RID 1 %x %x %x %x %x, %d\n",
1574 if (reply.an_status & AN_CMD_QUAL_MASK) {
1575 if_printf(sc->an_ifp,
1576 "failed to write RID 2 %x %x %x %x %x, %d\n",
1592 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1600 len = ltv->an_len - 4;
1601 if_printf(sc->an_ifp, "RID %4x, Length %4d, Mode %s\n",
1602 ltv->an_type, ltv->an_len - 4, string);
1604 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1605 if_printf(sc->an_ifp, "\t");
1606 bzero(buf,sizeof(buf));
1608 ptr2 = (u_int8_t *)<v->an_val;
1609 for (i = len; i > 0; i--) {
1610 printf("%02x ", *ptr2);
1617 if (++count == 16) {
1620 if_printf(sc->an_ifp, "\t");
1621 bzero(buf,sizeof(buf));
1624 for (; count != 16; count++) {
1627 printf(" %s\n",buf);
1632 an_seek(struct an_softc *sc, int id, int off, int chan)
1647 if_printf(sc->an_ifp, "invalid data path: %x\n", chan);
1651 CSR_WRITE_2(sc, selreg, id);
1652 CSR_WRITE_2(sc, offreg, off);
1654 for (i = 0; i < AN_TIMEOUT; i++) {
1655 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1659 if (i == AN_TIMEOUT)
1666 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1673 if (an_seek(sc, id, off, AN_BAP1))
1677 ptr = (u_int16_t *)buf;
1678 for (i = len; i > 1; i -= 2)
1679 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1681 ptr2 = (u_int8_t *)ptr;
1682 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1689 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1696 if (an_seek(sc, id, off, AN_BAP0))
1700 ptr = (u_int16_t *)buf;
1701 for (i = len; i > 1; i -= 2)
1702 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1704 ptr2 = (u_int8_t *)ptr;
1705 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1712 * Allocate a region of memory inside the NIC and zero
1716 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1720 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1721 if_printf(sc->an_ifp, "failed to allocate %d bytes on NIC\n",
1726 for (i = 0; i < AN_TIMEOUT; i++) {
1727 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1731 if (i == AN_TIMEOUT)
1734 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1735 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1737 if (an_seek(sc, *id, 0, AN_BAP0))
1740 for (i = 0; i < len / 2; i++)
1741 CSR_WRITE_2(sc, AN_DATA0, 0);
1747 an_setdef(struct an_softc *sc, struct an_req *areq)
1750 struct an_ltv_genconfig *cfg;
1751 struct an_ltv_ssidlist_new *ssid;
1752 struct an_ltv_aplist *ap;
1753 struct an_ltv_gen *sp;
1758 switch (areq->an_type) {
1759 case AN_RID_GENCONFIG:
1760 cfg = (struct an_ltv_genconfig *)areq;
1762 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(sc->an_ifp),
1765 bcopy((char *)cfg, (char *)&sc->an_config,
1766 sizeof(struct an_ltv_genconfig));
1768 case AN_RID_SSIDLIST:
1769 ssid = (struct an_ltv_ssidlist_new *)areq;
1770 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1771 sizeof(struct an_ltv_ssidlist_new));
1774 ap = (struct an_ltv_aplist *)areq;
1775 bcopy((char *)ap, (char *)&sc->an_aplist,
1776 sizeof(struct an_ltv_aplist));
1778 case AN_RID_TX_SPEED:
1779 sp = (struct an_ltv_gen *)areq;
1780 sc->an_tx_rate = sp->an_val;
1782 /* Read the current configuration */
1783 sc->an_config.an_type = AN_RID_GENCONFIG;
1784 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1785 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1786 cfg = &sc->an_config;
1788 /* clear other rates and set the only one we want */
1789 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1790 cfg->an_rates[0] = sc->an_tx_rate;
1792 /* Save the new rate */
1793 sc->an_config.an_type = AN_RID_GENCONFIG;
1794 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1796 case AN_RID_WEP_TEMP:
1797 /* Cache the temp keys */
1799 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1800 sizeof(struct an_ltv_key));
1801 case AN_RID_WEP_PERM:
1802 case AN_RID_LEAPUSERNAME:
1803 case AN_RID_LEAPPASSWORD:
1806 /* Disable the MAC. */
1807 an_cmd(sc, AN_CMD_DISABLE, 0);
1810 an_write_record(sc, (struct an_ltv_gen *)areq);
1812 /* Turn the MAC back on. */
1813 an_cmd(sc, AN_CMD_ENABLE, 0);
1816 case AN_RID_MONITOR_MODE:
1817 cfg = (struct an_ltv_genconfig *)areq;
1819 if (ng_ether_detach_p != NULL)
1820 (*ng_ether_detach_p) (ifp);
1821 sc->an_monitor = cfg->an_len;
1823 if (sc->an_monitor & AN_MONITOR) {
1824 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1825 bpfattach(ifp, DLT_AIRONET_HEADER,
1826 sizeof(struct ether_header));
1828 bpfattach(ifp, DLT_IEEE802_11,
1829 sizeof(struct ether_header));
1832 bpfattach(ifp, DLT_EN10MB,
1833 sizeof(struct ether_header));
1834 if (ng_ether_attach_p != NULL)
1835 (*ng_ether_attach_p) (ifp);
1839 if_printf(ifp, "unknown RID: %x\n", areq->an_type);
1843 /* Reinitialize the card. */
1851 * Derived from Linux driver to enable promiscious mode.
1855 an_promisc(struct an_softc *sc, int promisc)
1858 if (sc->an_was_monitor) {
1861 an_init_mpi350_desc(sc);
1863 if (sc->an_monitor || sc->an_was_monitor)
1866 sc->an_was_monitor = sc->an_monitor;
1867 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1873 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1878 struct an_softc *sc;
1879 struct an_req *areq;
1881 struct thread *td = curthread;
1882 struct ieee80211req *ireq;
1883 struct ieee80211_channel ch;
1884 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1886 struct an_ltv_genconfig *config;
1887 struct an_ltv_key *key;
1888 struct an_ltv_status *status;
1889 struct an_ltv_ssidlist_new *ssids;
1891 struct aironet_ioctl l_ioctl;
1894 ifr = (struct ifreq *)data;
1895 ireq = (struct ieee80211req *)data;
1897 config = (struct an_ltv_genconfig *)&sc->areq;
1898 key = (struct an_ltv_key *)&sc->areq;
1899 status = (struct an_ltv_status *)&sc->areq;
1900 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1910 if (ifp->if_flags & IFF_UP) {
1911 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1912 ifp->if_flags & IFF_PROMISC &&
1913 !(sc->an_if_flags & IFF_PROMISC)) {
1915 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1916 !(ifp->if_flags & IFF_PROMISC) &&
1917 sc->an_if_flags & IFF_PROMISC) {
1922 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1925 sc->an_if_flags = ifp->if_flags;
1931 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1935 /* The Aironet has no multicast filter. */
1939 error = priv_check(td, PRIV_DRIVER);
1942 areq = malloc(sizeof(*areq), M_TEMP, M_WAITOK);
1943 error = copyin(ifr_data_get_ptr(ifr), areq, sizeof(*areq));
1949 memcpy(&sc->areq, areq, sizeof(sc->areq));
1951 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1952 sc->an_sigitems = sc->an_nextitem = 0;
1955 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1956 char *pt = (char *)&sc->areq.an_val;
1957 bcopy((char *)&sc->an_sigitems, (char *)pt,
1960 sc->areq.an_len = sizeof(int) / 2;
1961 bcopy((char *)&sc->an_sigcache, (char *)pt,
1962 sizeof(struct an_sigcache) * sc->an_sigitems);
1963 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1964 sc->an_sigitems) / 2) + 1;
1967 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1973 memcpy(areq, &sc->areq, sizeof(*areq));
1975 error = copyout(areq, ifr_data_get_ptr(ifr), sizeof(*areq));
1979 if ((error = priv_check(td, PRIV_DRIVER)))
1982 error = copyin(ifr_data_get_ptr(ifr), &sc->areq,
1986 an_setdef(sc, &sc->areq);
1989 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1990 if ((error = priv_check(td, PRIV_DRIVER)))
1992 error = copyin(ifr_data_get_ptr(ifr), &l_ioctl,
1996 mode = l_ioctl.command;
1999 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
2000 error = readrids(ifp, &l_ioctl);
2001 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
2002 error = writerids(ifp, &l_ioctl);
2003 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
2004 error = flashcard(ifp, &l_ioctl);
2010 /* copy out the updated command info */
2011 error = copyout(&l_ioctl, ifr_data_get_ptr(ifr),
2015 case SIOCGPRIVATE_1: /* used by Cisco client utility */
2016 if ((error = priv_check(td, PRIV_DRIVER)))
2018 error = copyin(ifr_data_get_ptr(ifr), &l_ioctl,
2022 l_ioctl.command = 0;
2024 (void) copyout(&error, l_ioctl.data, sizeof(error));
2028 sc->areq.an_len = sizeof(sc->areq);
2029 /* was that a good idea DJA we are doing a short-cut */
2030 switch (ireq->i_type) {
2031 case IEEE80211_IOC_SSID:
2033 if (ireq->i_val == -1) {
2034 sc->areq.an_type = AN_RID_STATUS;
2035 if (an_read_record(sc,
2036 (struct an_ltv_gen *)&sc->areq)) {
2041 len = status->an_ssidlen;
2042 tmpptr = status->an_ssid;
2043 } else if (ireq->i_val >= 0) {
2044 sc->areq.an_type = AN_RID_SSIDLIST;
2045 if (an_read_record(sc,
2046 (struct an_ltv_gen *)&sc->areq)) {
2051 max = (sc->areq.an_len - 4)
2052 / sizeof(struct an_ltv_ssid_entry);
2053 if ( max > MAX_SSIDS ) {
2054 printf("To many SSIDs only using "
2059 if (ireq->i_val > max) {
2064 len = ssids->an_entry[ireq->i_val].an_len;
2065 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2072 if (len > IEEE80211_NWID_LEN) {
2079 bzero(tmpstr, IEEE80211_NWID_LEN);
2080 bcopy(tmpptr, tmpstr, len);
2081 error = copyout(tmpstr, ireq->i_data,
2082 IEEE80211_NWID_LEN);
2084 case IEEE80211_IOC_NUMSSIDS:
2086 sc->areq.an_len = sizeof(sc->areq);
2087 sc->areq.an_type = AN_RID_SSIDLIST;
2088 if (an_read_record(sc,
2089 (struct an_ltv_gen *)&sc->areq)) {
2094 max = (sc->areq.an_len - 4)
2095 / sizeof(struct an_ltv_ssid_entry);
2097 if ( max > MAX_SSIDS ) {
2098 printf("To many SSIDs only using "
2105 case IEEE80211_IOC_WEP:
2107 sc->areq.an_type = AN_RID_ACTUALCFG;
2108 if (an_read_record(sc,
2109 (struct an_ltv_gen *)&sc->areq)) {
2115 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2116 if (config->an_authtype &
2117 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2118 ireq->i_val = IEEE80211_WEP_MIXED;
2120 ireq->i_val = IEEE80211_WEP_ON;
2122 ireq->i_val = IEEE80211_WEP_OFF;
2125 case IEEE80211_IOC_WEPKEY:
2127 * XXX: I'm not entierly convinced this is
2128 * correct, but it's what is implemented in
2129 * ancontrol so it will have to do until we get
2130 * access to actual Cisco code.
2132 if (ireq->i_val < 0 || ireq->i_val > 8) {
2137 if (ireq->i_val < 5) {
2139 sc->areq.an_type = AN_RID_WEP_TEMP;
2140 for (i = 0; i < 5; i++) {
2141 if (an_read_record(sc,
2142 (struct an_ltv_gen *)&sc->areq)) {
2146 if (key->kindex == 0xffff)
2148 if (key->kindex == ireq->i_val)
2150 /* Required to get next entry */
2151 sc->areq.an_type = AN_RID_WEP_PERM;
2158 /* We aren't allowed to read the value of the
2159 * key from the card so we just output zeros
2160 * like we would if we could read the card, but
2161 * denied the user access.
2165 error = copyout(tmpstr, ireq->i_data, len);
2167 case IEEE80211_IOC_NUMWEPKEYS:
2168 ireq->i_val = 9; /* include home key */
2170 case IEEE80211_IOC_WEPTXKEY:
2172 * For some strange reason, you have to read all
2173 * keys before you can read the txkey.
2176 sc->areq.an_type = AN_RID_WEP_TEMP;
2177 for (i = 0; i < 5; i++) {
2178 if (an_read_record(sc,
2179 (struct an_ltv_gen *) &sc->areq)) {
2183 if (key->kindex == 0xffff) {
2186 /* Required to get next entry */
2187 sc->areq.an_type = AN_RID_WEP_PERM;
2194 sc->areq.an_type = AN_RID_WEP_PERM;
2195 key->kindex = 0xffff;
2196 if (an_read_record(sc,
2197 (struct an_ltv_gen *)&sc->areq)) {
2202 ireq->i_val = key->mac[0];
2204 * Check for home mode. Map home mode into
2205 * 5th key since that is how it is stored on
2208 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2209 sc->areq.an_type = AN_RID_GENCONFIG;
2210 if (an_read_record(sc,
2211 (struct an_ltv_gen *)&sc->areq)) {
2216 if (config->an_home_product & AN_HOME_NETWORK)
2220 case IEEE80211_IOC_AUTHMODE:
2222 sc->areq.an_type = AN_RID_ACTUALCFG;
2223 if (an_read_record(sc,
2224 (struct an_ltv_gen *)&sc->areq)) {
2230 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2232 ireq->i_val = IEEE80211_AUTH_NONE;
2233 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2235 ireq->i_val = IEEE80211_AUTH_OPEN;
2236 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2237 AN_AUTHTYPE_SHAREDKEY) {
2238 ireq->i_val = IEEE80211_AUTH_SHARED;
2242 case IEEE80211_IOC_STATIONNAME:
2244 sc->areq.an_type = AN_RID_ACTUALCFG;
2245 if (an_read_record(sc,
2246 (struct an_ltv_gen *)&sc->areq)) {
2252 ireq->i_len = sizeof(config->an_nodename);
2253 tmpptr = config->an_nodename;
2254 bzero(tmpstr, IEEE80211_NWID_LEN);
2255 bcopy(tmpptr, tmpstr, ireq->i_len);
2256 error = copyout(tmpstr, ireq->i_data,
2257 IEEE80211_NWID_LEN);
2259 case IEEE80211_IOC_CHANNEL:
2261 sc->areq.an_type = AN_RID_STATUS;
2262 if (an_read_record(sc,
2263 (struct an_ltv_gen *)&sc->areq)) {
2269 ireq->i_val = status->an_cur_channel;
2271 case IEEE80211_IOC_CURCHAN:
2273 sc->areq.an_type = AN_RID_STATUS;
2274 if (an_read_record(sc,
2275 (struct an_ltv_gen *)&sc->areq)) {
2281 bzero(&ch, sizeof(ch));
2282 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2284 ch.ic_flags = IEEE80211_CHAN_B;
2285 ch.ic_ieee = status->an_cur_channel;
2286 error = copyout(&ch, ireq->i_data, sizeof(ch));
2288 case IEEE80211_IOC_POWERSAVE:
2290 sc->areq.an_type = AN_RID_ACTUALCFG;
2291 if (an_read_record(sc,
2292 (struct an_ltv_gen *)&sc->areq)) {
2298 if (config->an_psave_mode == AN_PSAVE_NONE) {
2299 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2300 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2301 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2302 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2303 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2304 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2305 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2309 case IEEE80211_IOC_POWERSAVESLEEP:
2311 sc->areq.an_type = AN_RID_ACTUALCFG;
2312 if (an_read_record(sc,
2313 (struct an_ltv_gen *)&sc->areq)) {
2319 ireq->i_val = config->an_listen_interval;
2324 if ((error = priv_check(td, PRIV_NET80211_VAP_MANAGE)))
2327 sc->areq.an_len = sizeof(sc->areq);
2329 * We need a config structure for everything but the WEP
2330 * key management and SSIDs so we get it now so avoid
2331 * duplicating this code every time.
2333 if (ireq->i_type != IEEE80211_IOC_SSID &&
2334 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2335 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2336 sc->areq.an_type = AN_RID_GENCONFIG;
2337 if (an_read_record(sc,
2338 (struct an_ltv_gen *)&sc->areq)) {
2344 switch (ireq->i_type) {
2345 case IEEE80211_IOC_SSID:
2346 sc->areq.an_len = sizeof(sc->areq);
2347 sc->areq.an_type = AN_RID_SSIDLIST;
2348 if (an_read_record(sc,
2349 (struct an_ltv_gen *)&sc->areq)) {
2354 if (ireq->i_len > IEEE80211_NWID_LEN) {
2359 max = (sc->areq.an_len - 4)
2360 / sizeof(struct an_ltv_ssid_entry);
2361 if ( max > MAX_SSIDS ) {
2362 printf("To many SSIDs only using "
2367 if (ireq->i_val > max) {
2372 error = copyin(ireq->i_data,
2373 ssids->an_entry[ireq->i_val].an_ssid,
2375 ssids->an_entry[ireq->i_val].an_len
2377 sc->areq.an_len = sizeof(sc->areq);
2378 sc->areq.an_type = AN_RID_SSIDLIST;
2379 an_setdef(sc, &sc->areq);
2384 case IEEE80211_IOC_WEP:
2385 switch (ireq->i_val) {
2386 case IEEE80211_WEP_OFF:
2387 config->an_authtype &=
2388 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2389 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2391 case IEEE80211_WEP_ON:
2392 config->an_authtype |=
2393 AN_AUTHTYPE_PRIVACY_IN_USE;
2394 config->an_authtype &=
2395 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2397 case IEEE80211_WEP_MIXED:
2398 config->an_authtype |=
2399 AN_AUTHTYPE_PRIVACY_IN_USE |
2400 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2406 if (error != EINVAL)
2407 an_setdef(sc, &sc->areq);
2410 case IEEE80211_IOC_WEPKEY:
2411 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2417 error = copyin(ireq->i_data, tmpstr, 13);
2423 * Map the 9th key into the home mode
2424 * since that is how it is stored on
2427 bzero(&sc->areq, sizeof(struct an_ltv_key));
2428 sc->areq.an_len = sizeof(struct an_ltv_key);
2429 key->mac[0] = 1; /* The others are 0. */
2430 if (ireq->i_val < 4) {
2431 sc->areq.an_type = AN_RID_WEP_TEMP;
2432 key->kindex = ireq->i_val;
2434 sc->areq.an_type = AN_RID_WEP_PERM;
2435 key->kindex = ireq->i_val - 4;
2437 key->klen = ireq->i_len;
2438 bcopy(tmpstr, key->key, key->klen);
2439 an_setdef(sc, &sc->areq);
2442 case IEEE80211_IOC_WEPTXKEY:
2443 if (ireq->i_val < 0 || ireq->i_val > 4) {
2450 * Map the 5th key into the home mode
2451 * since that is how it is stored on
2454 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2455 sc->areq.an_type = AN_RID_ACTUALCFG;
2456 if (an_read_record(sc,
2457 (struct an_ltv_gen *)&sc->areq)) {
2462 if (ireq->i_val == 4) {
2463 config->an_home_product |= AN_HOME_NETWORK;
2466 config->an_home_product &= ~AN_HOME_NETWORK;
2469 sc->an_config.an_home_product
2470 = config->an_home_product;
2472 /* update configuration */
2475 bzero(&sc->areq, sizeof(struct an_ltv_key));
2476 sc->areq.an_len = sizeof(struct an_ltv_key);
2477 sc->areq.an_type = AN_RID_WEP_PERM;
2478 key->kindex = 0xffff;
2479 key->mac[0] = ireq->i_val;
2480 an_setdef(sc, &sc->areq);
2483 case IEEE80211_IOC_AUTHMODE:
2484 switch (ireq->i_val) {
2485 case IEEE80211_AUTH_NONE:
2486 config->an_authtype = AN_AUTHTYPE_NONE |
2487 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2489 case IEEE80211_AUTH_OPEN:
2490 config->an_authtype = AN_AUTHTYPE_OPEN |
2491 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2493 case IEEE80211_AUTH_SHARED:
2494 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2495 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2500 if (error != EINVAL) {
2501 an_setdef(sc, &sc->areq);
2505 case IEEE80211_IOC_STATIONNAME:
2506 if (ireq->i_len > 16) {
2511 bzero(config->an_nodename, 16);
2512 error = copyin(ireq->i_data,
2513 config->an_nodename, ireq->i_len);
2514 an_setdef(sc, &sc->areq);
2517 case IEEE80211_IOC_CHANNEL:
2519 * The actual range is 1-14, but if you set it
2520 * to 0 you get the default so we let that work
2523 if (ireq->i_val < 0 || ireq->i_val >14) {
2528 config->an_ds_channel = ireq->i_val;
2529 an_setdef(sc, &sc->areq);
2532 case IEEE80211_IOC_POWERSAVE:
2533 switch (ireq->i_val) {
2534 case IEEE80211_POWERSAVE_OFF:
2535 config->an_psave_mode = AN_PSAVE_NONE;
2537 case IEEE80211_POWERSAVE_CAM:
2538 config->an_psave_mode = AN_PSAVE_CAM;
2540 case IEEE80211_POWERSAVE_PSP:
2541 config->an_psave_mode = AN_PSAVE_PSP;
2543 case IEEE80211_POWERSAVE_PSP_CAM:
2544 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2550 an_setdef(sc, &sc->areq);
2553 case IEEE80211_IOC_POWERSAVESLEEP:
2554 config->an_listen_interval = ireq->i_val;
2555 an_setdef(sc, &sc->areq);
2566 an_setdef(sc, &sc->areq);
2572 error = ether_ioctl(ifp, command, data);
2581 an_init_tx_ring(struct an_softc *sc)
2590 for (i = 0; i < AN_TX_RING_CNT; i++) {
2591 if (an_alloc_nicmem(sc, 1518 +
2594 sc->an_rdata.an_tx_fids[i] = id;
2595 sc->an_rdata.an_tx_ring[i] = 0;
2599 sc->an_rdata.an_tx_prod = 0;
2600 sc->an_rdata.an_tx_cons = 0;
2601 sc->an_rdata.an_tx_empty = 1;
2609 struct an_softc *sc = xsc;
2617 an_init_locked(struct an_softc *sc)
2626 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2629 sc->an_associated = 0;
2631 /* Allocate the TX buffers */
2632 if (an_init_tx_ring(sc)) {
2635 an_init_mpi350_desc(sc);
2636 if (an_init_tx_ring(sc)) {
2637 if_printf(ifp, "tx buffer allocation failed\n");
2642 /* Set our MAC address. */
2643 bcopy((char *)IF_LLADDR(sc->an_ifp),
2644 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2646 if (ifp->if_flags & IFF_BROADCAST)
2647 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2649 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2651 if (ifp->if_flags & IFF_MULTICAST)
2652 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2654 if (ifp->if_flags & IFF_PROMISC) {
2655 if (sc->an_monitor & AN_MONITOR) {
2656 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2657 sc->an_config.an_rxmode |=
2658 AN_RXMODE_80211_MONITOR_ANYBSS |
2659 AN_RXMODE_NO_8023_HEADER;
2661 sc->an_config.an_rxmode |=
2662 AN_RXMODE_80211_MONITOR_CURBSS |
2663 AN_RXMODE_NO_8023_HEADER;
2669 if (sc->an_have_rssimap)
2670 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2673 /* Set the ssid list */
2674 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2675 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2676 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2677 if_printf(ifp, "failed to set ssid list\n");
2681 /* Set the AP list */
2682 sc->an_aplist.an_type = AN_RID_APLIST;
2683 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2684 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2685 if_printf(ifp, "failed to set AP list\n");
2689 /* Set the configuration in the NIC */
2690 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2691 sc->an_config.an_type = AN_RID_GENCONFIG;
2692 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2693 if_printf(ifp, "failed to set configuration\n");
2697 /* Enable the MAC */
2698 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2699 if_printf(ifp, "failed to enable MAC\n");
2703 if (ifp->if_flags & IFF_PROMISC)
2704 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2706 /* enable interrupts */
2707 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2709 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2710 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2712 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2718 an_start(struct ifnet *ifp)
2720 struct an_softc *sc;
2724 an_start_locked(ifp);
2729 an_start_locked(struct ifnet *ifp)
2731 struct an_softc *sc;
2732 struct mbuf *m0 = NULL;
2733 struct an_txframe_802_3 tx_frame_802_3;
2734 struct ether_header *eh;
2736 unsigned char txcontrol;
2737 struct an_card_tx_desc an_tx_desc;
2746 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2749 if (!sc->an_associated)
2752 /* We can't send in monitor mode so toss any attempts. */
2753 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2755 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2763 idx = sc->an_rdata.an_tx_prod;
2766 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2768 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2769 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2773 id = sc->an_rdata.an_tx_fids[idx];
2774 eh = mtod(m0, struct ether_header *);
2776 bcopy((char *)&eh->ether_dhost,
2777 (char *)&tx_frame_802_3.an_tx_dst_addr,
2779 bcopy((char *)&eh->ether_shost,
2780 (char *)&tx_frame_802_3.an_tx_src_addr,
2783 /* minus src/dest mac & type */
2784 tx_frame_802_3.an_tx_802_3_payload_len =
2785 m0->m_pkthdr.len - 12;
2787 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2788 tx_frame_802_3.an_tx_802_3_payload_len,
2789 (caddr_t)&sc->an_txbuf);
2791 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2792 /* write the txcontrol only */
2793 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2797 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2798 sizeof(struct an_txframe_802_3));
2800 /* in mbuf header type is just before payload */
2801 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2802 tx_frame_802_3.an_tx_802_3_payload_len);
2805 * If there's a BPF listner, bounce a copy of
2806 * this frame to him.
2813 sc->an_rdata.an_tx_ring[idx] = id;
2814 if (an_cmd(sc, AN_CMD_TX, id))
2815 if_printf(ifp, "xmit failed\n");
2817 AN_INC(idx, AN_TX_RING_CNT);
2820 * Set a timeout in case the chip goes out to lunch.
2824 } else { /* MPI-350 */
2825 /* Disable interrupts. */
2826 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2828 while (sc->an_rdata.an_tx_empty ||
2829 idx != sc->an_rdata.an_tx_cons) {
2830 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2834 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2836 eh = mtod(m0, struct ether_header *);
2838 /* DJA optimize this to limit bcopy */
2839 bcopy((char *)&eh->ether_dhost,
2840 (char *)&tx_frame_802_3.an_tx_dst_addr,
2842 bcopy((char *)&eh->ether_shost,
2843 (char *)&tx_frame_802_3.an_tx_src_addr,
2846 /* minus src/dest mac & type */
2847 tx_frame_802_3.an_tx_802_3_payload_len =
2848 m0->m_pkthdr.len - 12;
2850 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2851 tx_frame_802_3.an_tx_802_3_payload_len,
2852 (caddr_t)&sc->an_txbuf);
2854 txcontrol = AN_TXCTL_8023 | AN_TXCTL_HW(sc->mpi350);
2855 /* write the txcontrol only */
2856 bcopy((caddr_t)&txcontrol, &buf[0x08],
2860 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2861 sizeof(struct an_txframe_802_3));
2863 /* in mbuf header type is just before payload */
2864 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2865 tx_frame_802_3.an_tx_802_3_payload_len);
2867 bzero(&an_tx_desc, sizeof(an_tx_desc));
2868 an_tx_desc.an_offset = 0;
2869 an_tx_desc.an_eoc = 1;
2870 an_tx_desc.an_valid = 1;
2871 an_tx_desc.an_len = 0x44 +
2872 tx_frame_802_3.an_tx_802_3_payload_len;
2874 = sc->an_tx_buffer[idx].an_dma_paddr;
2875 for (i = sizeof(an_tx_desc) / 4 - 1; i >= 0; i--) {
2876 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2878 + (0 * sizeof(an_tx_desc))
2880 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2884 * If there's a BPF listner, bounce a copy of
2885 * this frame to him.
2891 AN_INC(idx, AN_MAX_TX_DESC);
2892 sc->an_rdata.an_tx_empty = 0;
2893 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2896 * Set a timeout in case the chip goes out to lunch.
2901 /* Re-enable interrupts. */
2902 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2906 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2908 sc->an_rdata.an_tx_prod = idx;
2914 an_stop(struct an_softc *sc)
2926 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2927 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2928 an_cmd(sc, AN_CMD_DISABLE, 0);
2930 for (i = 0; i < AN_TX_RING_CNT; i++)
2931 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2933 callout_stop(&sc->an_stat_ch);
2935 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2937 if (sc->an_flash_buffer) {
2938 free(sc->an_flash_buffer, M_DEVBUF);
2939 sc->an_flash_buffer = NULL;
2944 an_watchdog(struct an_softc *sc)
2954 if_printf(ifp, "device timeout\n");
2958 an_init_mpi350_desc(sc);
2961 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2965 an_shutdown(device_t dev)
2967 struct an_softc *sc;
2969 sc = device_get_softc(dev);
2979 an_resume(device_t dev)
2981 struct an_softc *sc;
2985 sc = device_get_softc(dev);
2992 an_init_mpi350_desc(sc);
2995 /* Recovery temporary keys */
2996 for (i = 0; i < 4; i++) {
2997 sc->areq.an_type = AN_RID_WEP_TEMP;
2998 sc->areq.an_len = sizeof(struct an_ltv_key);
2999 bcopy(&sc->an_temp_keys[i],
3000 &sc->areq, sizeof(struct an_ltv_key));
3001 an_setdef(sc, &sc->areq);
3004 if (ifp->if_flags & IFF_UP)
3005 an_start_locked(ifp);
3012 /* Aironet signal strength cache code.
3013 * store signal/noise/quality on per MAC src basis in
3014 * a small fixed cache. The cache wraps if > MAX slots
3015 * used. The cache may be zeroed out to start over.
3016 * Two simple filters exist to reduce computation:
3017 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
3018 * to ignore some packets. It defaults to ip only.
3019 * it could be used to focus on broadcast, non-IP 802.11 beacons.
3020 * 2. multicast/broadcast only. This may be used to
3021 * ignore unicast packets and only cache signal strength
3022 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
3023 * beacons and not unicast traffic.
3025 * The cache stores (MAC src(index), IP src (major clue), signal,
3028 * No apologies for storing IP src here. It's easy and saves much
3029 * trouble elsewhere. The cache is assumed to be INET dependent,
3030 * although it need not be.
3032 * Note: the Aironet only has a single byte of signal strength value
3033 * in the rx frame header, and it's not scaled to anything sensible.
3034 * This is kind of lame, but it's all we've got.
3037 #ifdef documentation
3039 int an_sigitems; /* number of cached entries */
3040 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
3041 int an_nextitem; /* index/# of entries */
3045 /* control variables for cache filtering. Basic idea is
3046 * to reduce cost (e.g., to only Mobile-IP agent beacons
3047 * which are broadcast or multicast). Still you might
3048 * want to measure signal strength anth unicast ping packets
3049 * on a pt. to pt. ant. setup.
3051 /* set true if you want to limit cache items to broadcast/mcast
3052 * only packets (not unicast). Useful for mobile-ip beacons which
3053 * are broadcast/multicast at network layer. Default is all packets
3054 * so ping/unicast anll work say anth pt. to pt. antennae setup.
3056 static int an_cache_mcastonly = 0;
3057 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
3058 &an_cache_mcastonly, 0, "");
3060 /* set true if you want to limit cache items to IP packets only
3062 static int an_cache_iponly = 1;
3063 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
3064 &an_cache_iponly, 0, "");
3067 * an_cache_store, per rx packet store signal
3068 * strength in MAC (src) indexed cache.
3071 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
3072 u_int8_t rx_rssi, u_int8_t rx_quality)
3074 struct ip *ip = NULL;
3076 static int cache_slot = 0; /* use this cache entry */
3077 static int wrapindex = 0; /* next "free" cache entry */
3082 * 2. configurable filter to throw out unicast packets,
3083 * keep multicast only.
3086 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
3090 /* filter for ip packets only
3092 if ( an_cache_iponly && !type_ipv4) {
3096 /* filter for broadcast/multicast only
3098 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3103 if_printf(sc->an_ifp, "q value %x (MSB=0x%x, LSB=0x%x) \n",
3104 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3107 /* find the ip header. we want to store the ip_src
3111 ip = mtod(m, struct ip *);
3114 /* do a linear search for a matching MAC address
3115 * in the cache table
3116 * . MAC address is 6 bytes,
3117 * . var w_nextitem holds total number of entries already cached
3119 for (i = 0; i < sc->an_nextitem; i++) {
3120 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3122 * so we already have this entry,
3129 /* did we find a matching mac address?
3130 * if yes, then overwrite a previously existing cache entry
3132 if (i < sc->an_nextitem ) {
3135 /* else, have a new address entry,so
3136 * add this new entry,
3137 * if table full, then we need to replace LRU entry
3140 /* check for space in cache table
3141 * note: an_nextitem also holds number of entries
3142 * added in the cache table
3144 if ( sc->an_nextitem < MAXANCACHE ) {
3145 cache_slot = sc->an_nextitem;
3147 sc->an_sigitems = sc->an_nextitem;
3149 /* no space found, so simply wrap anth wrap index
3150 * and "zap" the next entry
3153 if (wrapindex == MAXANCACHE) {
3156 cache_slot = wrapindex++;
3160 /* invariant: cache_slot now points at some slot
3163 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3164 log(LOG_ERR, "an_cache_store, bad index: %d of "
3165 "[0..%d], gross cache error\n",
3166 cache_slot, MAXANCACHE);
3170 /* store items in cache
3171 * .ip source address
3176 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3178 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3180 switch (an_cache_mode) {
3182 if (sc->an_have_rssimap) {
3183 sc->an_sigcache[cache_slot].signal =
3184 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3185 sc->an_sigcache[cache_slot].quality =
3186 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3188 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3189 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3193 if (sc->an_have_rssimap) {
3194 sc->an_sigcache[cache_slot].signal =
3195 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3196 sc->an_sigcache[cache_slot].quality =
3197 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3201 if (rx_quality > 100)
3203 sc->an_sigcache[cache_slot].signal = rx_rssi;
3204 sc->an_sigcache[cache_slot].quality = rx_quality;
3208 sc->an_sigcache[cache_slot].signal = rx_rssi;
3209 sc->an_sigcache[cache_slot].quality = rx_quality;
3213 sc->an_sigcache[cache_slot].noise = 0;
3220 an_media_change(struct ifnet *ifp)
3222 struct an_softc *sc = ifp->if_softc;
3223 struct an_ltv_genconfig *cfg;
3224 int otype = sc->an_config.an_opmode;
3225 int orate = sc->an_tx_rate;
3228 sc->an_tx_rate = ieee80211_media2rate(
3229 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3230 if (sc->an_tx_rate < 0)
3233 if (orate != sc->an_tx_rate) {
3234 /* Read the current configuration */
3235 sc->an_config.an_type = AN_RID_GENCONFIG;
3236 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3237 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3238 cfg = &sc->an_config;
3240 /* clear other rates and set the only one we want */
3241 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3242 cfg->an_rates[0] = sc->an_tx_rate;
3244 /* Save the new rate */
3245 sc->an_config.an_type = AN_RID_GENCONFIG;
3246 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3249 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3250 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3252 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3254 if (otype != sc->an_config.an_opmode ||
3255 orate != sc->an_tx_rate)
3263 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3265 struct an_ltv_status status;
3266 struct an_softc *sc = ifp->if_softc;
3268 imr->ifm_active = IFM_IEEE80211;
3271 status.an_len = sizeof(status);
3272 status.an_type = AN_RID_STATUS;
3273 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3274 /* If the status read fails, just lie. */
3275 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3276 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3279 if (sc->an_tx_rate == 0) {
3280 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3283 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3284 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3285 imr->ifm_active |= ieee80211_rate2media(NULL,
3286 status.an_current_tx_rate, IEEE80211_MODE_AUTO);
3287 imr->ifm_status = IFM_AVALID;
3288 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3289 imr->ifm_status |= IFM_ACTIVE;
3293 /********************** Cisco utility support routines *************/
3296 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3301 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3304 struct an_softc *sc;
3307 switch (l_ioctl->command) {
3309 rid = AN_RID_CAPABILITIES;
3312 rid = AN_RID_GENCONFIG;
3315 rid = AN_RID_SSIDLIST;
3318 rid = AN_RID_APLIST;
3321 rid = AN_RID_DRVNAME;
3324 rid = AN_RID_ENCAPPROTO;
3327 rid = AN_RID_WEP_TEMP;
3330 rid = AN_RID_WEP_PERM;
3333 rid = AN_RID_STATUS;
3336 rid = AN_RID_32BITS_DELTA;
3339 rid = AN_RID_32BITS_CUM;
3346 if (rid == 999) /* Is bad command */
3350 sc->areq.an_len = AN_MAX_DATALEN;
3351 sc->areq.an_type = rid;
3353 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3355 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3358 /* the data contains the length at first */
3359 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3360 sizeof(sc->areq.an_len))) {
3364 /* Just copy the data back */
3365 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3377 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3379 struct an_softc *sc;
3380 int rid, command, error;
3385 command = l_ioctl->command;
3389 rid = AN_RID_SSIDLIST;
3392 rid = AN_RID_CAPABILITIES;
3395 rid = AN_RID_APLIST;
3398 rid = AN_RID_GENCONFIG;
3401 an_cmd(sc, AN_CMD_ENABLE, 0);
3405 an_cmd(sc, AN_CMD_DISABLE, 0);
3410 * This command merely clears the counts does not actually
3411 * store any data only reads rid. But as it changes the cards
3412 * state, I put it in the writerid routines.
3415 rid = AN_RID_32BITS_DELTACLR;
3417 sc->areq.an_len = AN_MAX_DATALEN;
3418 sc->areq.an_type = rid;
3420 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3421 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3424 /* the data contains the length at first */
3425 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3426 sizeof(sc->areq.an_len));
3431 /* Just copy the data */
3432 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3440 rid = AN_RID_WEP_TEMP;
3443 rid = AN_RID_WEP_PERM;
3446 rid = AN_RID_LEAPUSERNAME;
3449 rid = AN_RID_LEAPPASSWORD;
3456 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3458 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3459 sc->areq.an_type = rid;
3461 /* Just copy the data back */
3463 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3469 an_cmd(sc, AN_CMD_DISABLE, 0);
3470 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3471 an_cmd(sc, AN_CMD_ENABLE, 0);
3478 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3482 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3483 "flash", ((x) / hz) + 1);
3484 #define FLASH_COMMAND 0x7e7e
3485 #define FLASH_SIZE 32 * 1024
3488 unstickbusy(struct ifnet *ifp)
3490 struct an_softc *sc = ifp->if_softc;
3492 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3493 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3494 AN_EV_CLR_STUCK_BUSY);
3501 * Wait for busy completion from card wait for delay uSec's Return true for
3502 * success meaning command reg is clear
3506 WaitBusy(struct ifnet *ifp, int uSec)
3508 int statword = 0xffff;
3510 struct an_softc *sc = ifp->if_softc;
3512 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3513 FLASH_DELAY(sc, 10);
3515 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3517 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3522 return 0 == (AN_CMD_BUSY & statword);
3526 * STEP 1) Disable MAC and do soft reset on card.
3530 cmdreset(struct ifnet *ifp)
3533 struct an_softc *sc = ifp->if_softc;
3538 an_cmd(sc, AN_CMD_DISABLE, 0);
3540 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3541 if_printf(ifp, "Waitbusy hang b4 RESET =%d\n", status);
3545 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3547 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3549 if (!(status = WaitBusy(ifp, 100))) {
3550 if_printf(ifp, "Waitbusy hang AFTER RESET =%d\n", status);
3559 * STEP 2) Put the card in legendary flash mode
3563 setflashmode(struct ifnet *ifp)
3566 struct an_softc *sc = ifp->if_softc;
3568 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3569 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3570 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3571 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3574 * mdelay(500); // 500ms delay
3577 FLASH_DELAY(sc, 500);
3579 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3580 printf("Waitbusy hang after setflash mode\n");
3587 * Get a character from the card matching matchbyte Step 3)
3591 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3594 unsigned char rbyte = 0;
3596 struct an_softc *sc = ifp->if_softc;
3599 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3601 if (dwelltime && !(0x8000 & rchar)) {
3603 FLASH_DELAY(sc, 10);
3606 rbyte = 0xff & rchar;
3608 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3609 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3613 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3615 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3617 } while (dwelltime > 0);
3622 * Put character to SWS0 wait for dwelltime x 50us for echo .
3626 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3629 int pollbusy, waittime;
3630 struct an_softc *sc = ifp->if_softc;
3637 waittime = dwelltime;
3640 * Wait for busy bit d15 to go false indicating buffer empty
3643 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3645 if (pollbusy & 0x8000) {
3646 FLASH_DELAY(sc, 50);
3652 while (waittime >= 0);
3654 /* timeout for busy clear wait */
3656 if (waittime <= 0) {
3657 if_printf(ifp, "flash putchar busywait timeout!\n");
3661 * Port is clear now write byte and wait for it to echo back
3664 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3665 FLASH_DELAY(sc, 50);
3667 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3668 } while (dwelltime >= 0 && echo != byte);
3670 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3672 return echo == byte;
3676 * Transfer 32k of firmware data from user buffer to our buffer and send to
3681 flashputbuf(struct ifnet *ifp)
3683 unsigned short *bufp;
3685 struct an_softc *sc = ifp->if_softc;
3689 bufp = sc->an_flash_buffer;
3692 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3693 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3695 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3696 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3699 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3700 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3701 ((u_int32_t *)bufp)[nwords] & 0xffff);
3705 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3711 * After flashing restart the card.
3715 flashrestart(struct ifnet *ifp)
3718 struct an_softc *sc = ifp->if_softc;
3720 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3724 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3729 * Entry point for flash ioclt.
3733 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3736 struct an_softc *sc;
3740 if_printf(ifp, "flashing not supported on MPI 350 yet\n");
3743 status = l_ioctl->command;
3745 switch (l_ioctl->command) {
3747 return cmdreset(ifp);
3750 if (sc->an_flash_buffer) {
3751 free(sc->an_flash_buffer, M_DEVBUF);
3752 sc->an_flash_buffer = NULL;
3754 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3755 if (sc->an_flash_buffer)
3756 return setflashmode(ifp);
3760 case AIROFLSHGCHR: /* Get char from aux */
3761 if (l_ioctl->len > sizeof(sc->areq)) {
3765 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3769 z = *(int *)&sc->areq;
3770 if ((status = flashgchar(ifp, z, 8000)) == 1)
3774 case AIROFLSHPCHR: /* Send char to card. */
3775 if (l_ioctl->len > sizeof(sc->areq)) {
3779 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3783 z = *(int *)&sc->areq;
3784 if ((status = flashpchar(ifp, z, 8000)) == -1)
3789 case AIROFLPUTBUF: /* Send 32k to card */
3790 if (l_ioctl->len > FLASH_SIZE) {
3791 if_printf(ifp, "Buffer to big, %x %x\n",
3792 l_ioctl->len, FLASH_SIZE);
3796 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3801 if ((status = flashputbuf(ifp)) != 0)
3807 if ((status = flashrestart(ifp)) != 0) {
3808 if_printf(ifp, "FLASHRESTART returned %d\n", status);