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>
105 #include <sys/sysctl.h>
107 #include <machine/bus.h>
108 #include <sys/rman.h>
109 #include <sys/lock.h>
110 #include <sys/mutex.h>
111 #include <machine/resource.h>
112 #include <sys/malloc.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 int an_init_tx_ring(struct an_softc *);
144 static void an_start(struct ifnet *);
145 static void an_watchdog(struct ifnet *);
146 static void an_rxeof(struct an_softc *);
147 static void an_txeof(struct an_softc *, int);
149 static void an_promisc(struct an_softc *, int);
150 static int an_cmd(struct an_softc *, int, int);
151 static int an_cmd_struct(struct an_softc *, struct an_command *,
153 static int an_read_record(struct an_softc *, struct an_ltv_gen *);
154 static int an_write_record(struct an_softc *, struct an_ltv_gen *);
155 static int an_read_data(struct an_softc *, int, int, caddr_t, int);
156 static int an_write_data(struct an_softc *, int, int, caddr_t, int);
157 static int an_seek(struct an_softc *, int, int, int);
158 static int an_alloc_nicmem(struct an_softc *, int, int *);
159 static int an_dma_malloc(struct an_softc *, bus_size_t, struct an_dma_alloc *,
161 static void an_dma_free(struct an_softc *, struct an_dma_alloc *);
162 static void an_dma_malloc_cb(void *, bus_dma_segment_t *, int, int);
163 static void an_stats_update(void *);
164 static void an_setdef(struct an_softc *, struct an_req *);
166 static void an_cache_store(struct an_softc *, struct ether_header *,
167 struct mbuf *, u_int8_t, u_int8_t);
170 /* function definitions for use with the Cisco's Linux configuration
174 static int readrids(struct ifnet*, struct aironet_ioctl*);
175 static int writerids(struct ifnet*, struct aironet_ioctl*);
176 static int flashcard(struct ifnet*, struct aironet_ioctl*);
178 static int cmdreset(struct ifnet *);
179 static int setflashmode(struct ifnet *);
180 static int flashgchar(struct ifnet *,int,int);
181 static int flashpchar(struct ifnet *,int,int);
182 static int flashputbuf(struct ifnet *);
183 static int flashrestart(struct ifnet *);
184 static int WaitBusy(struct ifnet *, int);
185 static int unstickbusy(struct ifnet *);
187 static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
190 static int an_media_change (struct ifnet *);
191 static void an_media_status (struct ifnet *, struct ifmediareq *);
193 static int an_dump = 0;
194 static int an_cache_mode = 0;
200 static char an_conf[256];
201 static char an_conf_cache[256];
205 SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
207 /* XXX violate ethernet/netgraph callback hooks */
208 extern void (*ng_ether_attach_p)(struct ifnet *ifp);
209 extern void (*ng_ether_detach_p)(struct ifnet *ifp);
212 sysctl_an_dump(SYSCTL_HANDLER_ARGS)
221 strcpy(an_conf, "off");
224 strcpy(an_conf, "type");
227 strcpy(an_conf, "dump");
230 snprintf(an_conf, 5, "%x", an_dump);
234 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
236 if (strncmp(an_conf,"off", 3) == 0) {
239 if (strncmp(an_conf,"dump", 4) == 0) {
242 if (strncmp(an_conf,"type", 4) == 0) {
248 if ((*s >= '0') && (*s <= '9')) {
249 r = r * 16 + (*s - '0');
250 } else if ((*s >= 'a') && (*s <= 'f')) {
251 r = r * 16 + (*s - 'a' + 10);
259 printf("Sysctl changed for Aironet driver\n");
264 SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
265 0, sizeof(an_conf), sysctl_an_dump, "A", "");
268 sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
272 last = an_cache_mode;
274 switch (an_cache_mode) {
276 strcpy(an_conf_cache, "per");
279 strcpy(an_conf_cache, "raw");
282 strcpy(an_conf_cache, "dbm");
286 error = sysctl_handle_string(oidp, an_conf_cache,
287 sizeof(an_conf_cache), req);
289 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
292 if (strncmp(an_conf_cache,"per", 3) == 0) {
295 if (strncmp(an_conf_cache,"raw", 3) == 0) {
302 SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
303 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
306 * Setup the lock for PCI attachment since it skips the an_probe
307 * function. We need to setup the lock in an_probe since some
308 * operations need the lock. So we might as well create the
312 an_pci_probe(device_t dev)
314 struct an_softc *sc = device_get_softc(dev);
316 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
317 MTX_DEF | MTX_RECURSE);
323 * We probe for an Aironet 4500/4800 card by attempting to
324 * read the default SSID list. On reset, the first entry in
325 * the SSID list will contain the name "tsunami." If we don't
326 * find this, then there's no card present.
329 an_probe(device_t dev)
331 struct an_softc *sc = device_get_softc(dev);
332 struct an_ltv_ssidlist_new ssid;
335 bzero((char *)&ssid, sizeof(ssid));
337 error = an_alloc_port(dev, 0, AN_IOSIZ);
341 /* can't do autoprobing */
342 if (rman_get_start(sc->port_res) == -1)
346 * We need to fake up a softc structure long enough
347 * to be able to issue commands and call some of the
350 sc->an_bhandle = rman_get_bushandle(sc->port_res);
351 sc->an_btag = rman_get_bustag(sc->port_res);
352 sc->an_unit = device_get_unit(dev);
354 ssid.an_len = sizeof(ssid);
355 ssid.an_type = AN_RID_SSIDLIST;
357 /* Make sure interrupts are disabled. */
359 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
360 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
362 mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
363 MTX_DEF | MTX_RECURSE);
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 printf("an%d: failed to allocate RX descriptor\n",
608 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
609 bzero(&an_rx_desc, sizeof(an_rx_desc));
610 an_rx_desc.an_valid = 1;
611 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
612 an_rx_desc.an_done = 0;
613 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
615 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
616 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
617 + (desc * sizeof(an_rx_desc))
619 ((u_int32_t *)(void *)&an_rx_desc)[i]);
623 * Allocate TX descriptor
626 bzero(&reply,sizeof(reply));
627 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
628 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
629 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
630 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
631 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
632 printf("an%d: failed to allocate TX descriptor\n",
637 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
638 bzero(&an_tx_desc, sizeof(an_tx_desc));
639 an_tx_desc.an_offset = 0;
640 an_tx_desc.an_eoc = 0;
641 an_tx_desc.an_valid = 0;
642 an_tx_desc.an_len = 0;
643 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
645 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
646 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
647 + (desc * sizeof(an_tx_desc))
649 ((u_int32_t *)(void *)&an_tx_desc)[i]);
653 * Allocate RID descriptor
656 bzero(&reply,sizeof(reply));
657 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
658 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
659 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
660 cmd_struct.an_parm2 = 1;
661 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
662 printf("an%d: failed to allocate host descriptor\n",
667 bzero(&an_rid_desc, sizeof(an_rid_desc));
668 an_rid_desc.an_valid = 1;
669 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
670 an_rid_desc.an_rid = 0;
671 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
673 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
674 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
675 ((u_int32_t *)(void *)&an_rid_desc)[i]);
681 an_attach(struct an_softc *sc, int unit, int flags)
688 ifp = sc->an_ifp = if_alloc(IFT_ETHER);
690 printf("an%d: can not if_alloc()\n", sc->an_unit);
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 printf("an%d: failed to load config data\n", sc->an_unit);
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 printf("an%d: read record failed\n", sc->an_unit);
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 printf("an%d: read record failed\n", sc->an_unit);
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 printf("an%d: read record failed\n", sc->an_unit);
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 printf("an%d: read record failed\n", sc->an_unit);
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 printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
756 printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
757 sc->an_have_rssimap = 1;
760 printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
767 if_initname(ifp, device_get_name(sc->an_dev),
768 device_get_unit(sc->an_dev));
769 ifp->if_mtu = ETHERMTU;
770 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
771 ifp->if_ioctl = an_ioctl;
772 ifp->if_start = an_start;
773 ifp->if_watchdog = an_watchdog;
774 ifp->if_init = an_init;
775 ifp->if_baudrate = 10000000;
776 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
777 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
778 IFQ_SET_READY(&ifp->if_snd);
780 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
781 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
782 sizeof(AN_DEFAULT_NODENAME) - 1);
784 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
785 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
786 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
787 sizeof(AN_DEFAULT_NETNAME) - 1);
788 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
790 sc->an_config.an_opmode =
791 AN_OPMODE_INFRASTRUCTURE_STATION;
794 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
798 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
799 if_printf(ifp, "supported rates: ");
800 #define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
801 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
803 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
804 for (i = 0; i < nrate; i++) {
805 r = sc->an_caps.an_rates[i];
806 mword = ieee80211_rate2media(NULL, r, IEEE80211_T_DS);
809 printf("%s%d%sMbps", (i != 0 ? " " : ""),
810 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
812 ADD(mword, IFM_IEEE80211_ADHOC);
815 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
820 * Call MI attach routine.
823 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
824 callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0);
829 mtx_destroy(&sc->an_mtx);
836 an_detach(device_t dev)
838 struct an_softc *sc = device_get_softc(dev);
839 struct ifnet *ifp = sc->an_ifp;
842 device_printf(dev,"already unloaded\n");
848 ifmedia_removeall(&sc->an_ifmedia);
849 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
852 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
853 callout_drain(&sc->an_stat_ch);
855 an_release_resources(dev);
856 mtx_destroy(&sc->an_mtx);
861 an_rxeof(struct an_softc *sc)
864 struct ether_header *eh;
865 struct ieee80211_frame *ih;
866 struct an_rxframe rx_frame;
867 struct an_rxframe_802_3 rx_frame_802_3;
869 int len, id, error = 0, i, count = 0;
870 int ieee80211_header_len;
873 struct an_card_rx_desc an_rx_desc;
881 id = CSR_READ_2(sc, AN_RX_FID);
883 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
884 /* read raw 802.11 packet */
885 bpf_buf = sc->buf_802_11;
888 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
895 * skip beacon by default since this increases the
899 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
900 (rx_frame.an_frame_ctl &
901 IEEE80211_FC0_SUBTYPE_BEACON)) {
905 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
906 len = rx_frame.an_rx_payload_len
908 /* Check for insane frame length */
909 if (len > sizeof(sc->buf_802_11)) {
910 printf("an%d: oversized packet "
911 "received (%d, %d)\n",
912 sc->an_unit, len, MCLBYTES);
917 bcopy((char *)&rx_frame,
918 bpf_buf, sizeof(rx_frame));
920 error = an_read_data(sc, id, sizeof(rx_frame),
921 (caddr_t)bpf_buf+sizeof(rx_frame),
922 rx_frame.an_rx_payload_len);
924 fc1=rx_frame.an_frame_ctl >> 8;
925 ieee80211_header_len =
926 sizeof(struct ieee80211_frame);
927 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
928 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
929 ieee80211_header_len += ETHER_ADDR_LEN;
932 len = rx_frame.an_rx_payload_len
933 + ieee80211_header_len;
934 /* Check for insane frame length */
935 if (len > sizeof(sc->buf_802_11)) {
936 printf("an%d: oversized packet "
937 "received (%d, %d)\n",
938 sc->an_unit, len, MCLBYTES);
943 ih = (struct ieee80211_frame *)bpf_buf;
945 bcopy((char *)&rx_frame.an_frame_ctl,
946 (char *)ih, ieee80211_header_len);
948 error = an_read_data(sc, id, sizeof(rx_frame) +
950 (caddr_t)ih +ieee80211_header_len,
951 rx_frame.an_rx_payload_len);
953 /* dump raw 802.11 packet to bpf and skip ip stack */
954 BPF_TAP(ifp, bpf_buf, len);
956 MGETHDR(m, M_DONTWAIT, MT_DATA);
961 MCLGET(m, M_DONTWAIT);
962 if (!(m->m_flags & M_EXT)) {
967 m->m_pkthdr.rcvif = ifp;
968 /* Read Ethernet encapsulated packet */
971 /* Read NIC frame header */
972 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
979 /* Read in the 802_3 frame header */
980 if (an_read_data(sc, id, 0x34,
981 (caddr_t)&rx_frame_802_3,
982 sizeof(rx_frame_802_3))) {
987 if (rx_frame_802_3.an_rx_802_3_status != 0) {
992 /* Check for insane frame length */
993 len = rx_frame_802_3.an_rx_802_3_payload_len;
994 if (len > sizeof(sc->buf_802_11)) {
996 printf("an%d: oversized packet "
997 "received (%d, %d)\n",
998 sc->an_unit, len, MCLBYTES);
1002 m->m_pkthdr.len = m->m_len =
1003 rx_frame_802_3.an_rx_802_3_payload_len + 12;
1005 eh = mtod(m, struct ether_header *);
1007 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
1008 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
1009 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
1010 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
1012 /* in mbuf header type is just before payload */
1013 error = an_read_data(sc, id, 0x44,
1014 (caddr_t)&(eh->ether_type),
1015 rx_frame_802_3.an_rx_802_3_payload_len);
1024 /* Receive packet. */
1026 an_cache_store(sc, eh, m,
1027 rx_frame.an_rx_signal_strength,
1031 (*ifp->if_input)(ifp, m);
1035 } else { /* MPI-350 */
1036 for (count = 0; count < AN_MAX_RX_DESC; count++){
1037 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1038 ((u_int32_t *)(void *)&an_rx_desc)[i]
1039 = CSR_MEM_AUX_READ_4(sc,
1041 + (count * sizeof(an_rx_desc))
1044 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1045 buf = sc->an_rx_buffer[count].an_dma_vaddr;
1047 MGETHDR(m, M_DONTWAIT, MT_DATA);
1052 MCLGET(m, M_DONTWAIT);
1053 if (!(m->m_flags & M_EXT)) {
1058 m->m_pkthdr.rcvif = ifp;
1059 /* Read Ethernet encapsulated packet */
1062 * No ANCACHE support since we just get back
1063 * an Ethernet packet no 802.11 info
1067 /* Read NIC frame header */
1068 bcopy(buf, (caddr_t)&rx_frame,
1072 /* Check for insane frame length */
1073 len = an_rx_desc.an_len + 12;
1074 if (len > MCLBYTES) {
1076 printf("an%d: oversized packet "
1077 "received (%d, %d)\n",
1078 sc->an_unit, len, MCLBYTES);
1083 m->m_pkthdr.len = m->m_len =
1084 an_rx_desc.an_len + 12;
1086 eh = mtod(m, struct ether_header *);
1088 bcopy(buf, (char *)eh,
1093 /* Receive packet. */
1096 an_cache_store(sc, eh, m,
1097 rx_frame.an_rx_signal_strength,
1102 (*ifp->if_input)(ifp, m);
1105 an_rx_desc.an_valid = 1;
1106 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1107 an_rx_desc.an_done = 0;
1108 an_rx_desc.an_phys =
1109 sc->an_rx_buffer[count].an_dma_paddr;
1111 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1112 CSR_MEM_AUX_WRITE_4(sc,
1114 + (count * sizeof(an_rx_desc))
1116 ((u_int32_t *)(void *)&an_rx_desc)[i]);
1119 printf("an%d: Didn't get valid RX packet "
1123 an_rx_desc.an_valid, an_rx_desc.an_len);
1130 an_txeof(struct an_softc *sc, int status)
1139 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1142 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1144 if (status & AN_EV_TX_EXC) {
1149 for (i = 0; i < AN_TX_RING_CNT; i++) {
1150 if (id == sc->an_rdata.an_tx_ring[i]) {
1151 sc->an_rdata.an_tx_ring[i] = 0;
1156 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1157 } else { /* MPI 350 */
1158 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1159 if (!sc->an_rdata.an_tx_empty){
1160 if (status & AN_EV_TX_EXC) {
1164 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1165 if (sc->an_rdata.an_tx_prod ==
1166 sc->an_rdata.an_tx_cons)
1167 sc->an_rdata.an_tx_empty = 1;
1175 * We abuse the stats updater to check the current NIC status. This
1176 * is important because we don't want to allow transmissions until
1177 * the NIC has synchronized to the current cell (either as the master
1178 * in an ad-hoc group, or as a station connected to an access point).
1180 * Note that this function will be called via callout(9) with a lock held.
1183 an_stats_update(void *xsc)
1185 struct an_softc *sc;
1192 sc->an_status.an_type = AN_RID_STATUS;
1193 sc->an_status.an_len = sizeof(struct an_ltv_status);
1194 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status))
1197 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1198 sc->an_associated = 1;
1200 sc->an_associated = 0;
1202 /* Don't do this while we're transmitting */
1203 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
1204 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1208 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1209 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1210 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len))
1213 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1221 struct an_softc *sc;
1225 sc = (struct an_softc*)xsc;
1236 /* Disable interrupts. */
1237 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1239 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1240 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1242 if (status & AN_EV_MIC) {
1243 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1246 if (status & AN_EV_LINKSTAT) {
1247 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1248 == AN_LINKSTAT_ASSOCIATED)
1249 sc->an_associated = 1;
1251 sc->an_associated = 0;
1252 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1255 if (status & AN_EV_RX) {
1257 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1260 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1261 an_txeof(sc, status);
1262 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1265 if (status & AN_EV_TX) {
1266 an_txeof(sc, status);
1267 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1270 if (status & AN_EV_TX_EXC) {
1271 an_txeof(sc, status);
1272 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1275 if (status & AN_EV_ALLOC)
1276 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1278 /* Re-enable interrupts. */
1279 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1281 if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1291 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1292 struct an_reply *reply)
1297 for (i = 0; i != AN_TIMEOUT; i++) {
1298 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1304 if( i == AN_TIMEOUT) {
1309 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1310 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1311 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1312 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1314 for (i = 0; i < AN_TIMEOUT; i++) {
1315 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1320 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1321 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1322 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1323 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1325 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1326 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
1327 AN_EV_CLR_STUCK_BUSY);
1329 /* Ack the command */
1330 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1332 if (i == AN_TIMEOUT)
1339 an_cmd(struct an_softc *sc, int cmd, int val)
1344 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1345 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1346 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1347 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1349 for (i = 0; i < AN_TIMEOUT; i++) {
1350 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1353 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1354 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1358 for (i = 0; i < AN_TIMEOUT; i++) {
1359 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1360 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1361 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1362 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1363 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1367 /* Ack the command */
1368 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1370 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1371 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1373 if (i == AN_TIMEOUT)
1380 * This reset sequence may look a little strange, but this is the
1381 * most reliable method I've found to really kick the NIC in the
1382 * head and force it to reboot correctly.
1385 an_reset(struct an_softc *sc)
1391 an_cmd(sc, AN_CMD_ENABLE, 0);
1392 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1393 an_cmd(sc, AN_CMD_NOOP2, 0);
1395 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1396 printf("an%d: reset failed\n", sc->an_unit);
1398 an_cmd(sc, AN_CMD_DISABLE, 0);
1404 * Read an LTV record from the NIC.
1407 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1409 struct an_ltv_gen *an_ltv;
1410 struct an_card_rid_desc an_rid_desc;
1411 struct an_command cmd;
1412 struct an_reply reply;
1418 if (ltv->an_len < 4 || ltv->an_type == 0)
1422 /* Tell the NIC to enter record read mode. */
1423 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1424 printf("an%d: RID access failed\n", sc->an_unit);
1428 /* Seek to the record. */
1429 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1430 printf("an%d: seek to record failed\n", sc->an_unit);
1435 * Read the length and record type and make sure they
1436 * match what we expect (this verifies that we have enough
1437 * room to hold all of the returned data).
1438 * Length includes type but not length.
1440 len = CSR_READ_2(sc, AN_DATA1);
1441 if (len > (ltv->an_len - 2)) {
1442 printf("an%d: record length mismatch -- expected %d, "
1443 "got %d for Rid %x\n", sc->an_unit,
1444 ltv->an_len - 2, len, ltv->an_type);
1445 len = ltv->an_len - 2;
1447 ltv->an_len = len + 2;
1450 /* Now read the data. */
1451 len -= 2; /* skip the type */
1453 for (i = len; i > 1; i -= 2)
1454 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1456 ptr2 = (u_int8_t *)ptr;
1457 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1459 } else { /* MPI-350 */
1460 if (!sc->an_rid_buffer.an_dma_vaddr)
1462 an_rid_desc.an_valid = 1;
1463 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1464 an_rid_desc.an_rid = 0;
1465 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1466 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1468 bzero(&cmd, sizeof(cmd));
1469 bzero(&reply, sizeof(reply));
1470 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1471 cmd.an_parm0 = ltv->an_type;
1473 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1474 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1475 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1477 if (an_cmd_struct(sc, &cmd, &reply)
1478 || reply.an_status & AN_CMD_QUAL_MASK) {
1479 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1480 sc->an_unit, ltv->an_type,
1489 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1490 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1491 an_rid_desc.an_len = an_ltv->an_len;
1494 len = an_rid_desc.an_len;
1495 if (len > (ltv->an_len - 2)) {
1496 printf("an%d: record length mismatch -- expected %d, "
1497 "got %d for Rid %x\n", sc->an_unit,
1498 ltv->an_len - 2, len, ltv->an_type);
1499 len = ltv->an_len - 2;
1501 ltv->an_len = len + 2;
1503 bcopy(&an_ltv->an_type,
1509 an_dump_record(sc, ltv, "Read");
1515 * Same as read, except we inject data instead of reading it.
1518 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1520 struct an_card_rid_desc an_rid_desc;
1521 struct an_command cmd;
1522 struct an_reply reply;
1529 an_dump_record(sc, ltv, "Write");
1532 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1535 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1539 * Length includes type but not length.
1541 len = ltv->an_len - 2;
1542 CSR_WRITE_2(sc, AN_DATA1, len);
1544 len -= 2; /* skip the type */
1546 for (i = len; i > 1; i -= 2)
1547 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1549 ptr2 = (u_int8_t *)ptr;
1550 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1553 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1558 for (i = 0; i != AN_TIMEOUT; i++) {
1559 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1565 if (i == AN_TIMEOUT) {
1569 an_rid_desc.an_valid = 1;
1570 an_rid_desc.an_len = ltv->an_len - 2;
1571 an_rid_desc.an_rid = ltv->an_type;
1572 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1574 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1575 an_rid_desc.an_len);
1577 bzero(&cmd,sizeof(cmd));
1578 bzero(&reply,sizeof(reply));
1579 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1580 cmd.an_parm0 = ltv->an_type;
1582 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1583 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1584 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1588 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1589 printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
1590 sc->an_unit, ltv->an_type,
1600 if (reply.an_status & AN_CMD_QUAL_MASK) {
1601 printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
1602 sc->an_unit, ltv->an_type,
1617 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1625 len = ltv->an_len - 4;
1626 printf("an%d: RID %4x, Length %4d, Mode %s\n",
1627 sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
1629 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1630 printf("an%d:\t", sc->an_unit);
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 printf("an%d:\t", sc->an_unit);
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 printf("an%d: invalid data path: %x\n", sc->an_unit, 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 printf("an%d: 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:
1833 /* Disable the MAC. */
1834 an_cmd(sc, AN_CMD_DISABLE, 0);
1837 an_write_record(sc, (struct an_ltv_gen *)areq);
1839 /* Turn the MAC back on. */
1840 an_cmd(sc, AN_CMD_ENABLE, 0);
1843 case AN_RID_MONITOR_MODE:
1844 cfg = (struct an_ltv_genconfig *)areq;
1846 if (ng_ether_detach_p != NULL)
1847 (*ng_ether_detach_p) (ifp);
1848 sc->an_monitor = cfg->an_len;
1850 if (sc->an_monitor & AN_MONITOR) {
1851 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1852 bpfattach(ifp, DLT_AIRONET_HEADER,
1853 sizeof(struct ether_header));
1855 bpfattach(ifp, DLT_IEEE802_11,
1856 sizeof(struct ether_header));
1859 bpfattach(ifp, DLT_EN10MB,
1860 sizeof(struct ether_header));
1861 if (ng_ether_attach_p != NULL)
1862 (*ng_ether_attach_p) (ifp);
1866 printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
1871 /* Reinitialize the card. */
1872 if (ifp->if_flags) {
1882 * Derived from Linux driver to enable promiscious mode.
1886 an_promisc(struct an_softc *sc, int promisc)
1889 if (sc->an_was_monitor) {
1892 an_init_mpi350_desc(sc);
1894 if (sc->an_monitor || sc->an_was_monitor) {
1900 sc->an_was_monitor = sc->an_monitor;
1901 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1907 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1912 struct an_softc *sc;
1914 struct thread *td = curthread;
1915 struct ieee80211req *ireq;
1916 struct ieee80211_channel ch;
1917 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1919 struct an_ltv_genconfig *config;
1920 struct an_ltv_key *key;
1921 struct an_ltv_status *status;
1922 struct an_ltv_ssidlist_new *ssids;
1924 struct aironet_ioctl l_ioctl;
1927 ifr = (struct ifreq *)data;
1928 ireq = (struct ieee80211req *)data;
1930 config = (struct an_ltv_genconfig *)&sc->areq;
1931 key = (struct an_ltv_key *)&sc->areq;
1932 status = (struct an_ltv_status *)&sc->areq;
1933 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1943 if (ifp->if_flags & IFF_UP) {
1944 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1945 ifp->if_flags & IFF_PROMISC &&
1946 !(sc->an_if_flags & IFF_PROMISC)) {
1948 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1949 !(ifp->if_flags & IFF_PROMISC) &&
1950 sc->an_if_flags & IFF_PROMISC) {
1958 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1965 sc->an_if_flags = ifp->if_flags;
1970 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1974 /* The Aironet has no multicast filter. */
1978 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1983 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1984 error = priv_check(td, PRIV_DRIVER);
1987 sc->an_sigitems = sc->an_nextitem = 0;
1989 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1990 char *pt = (char *)&sc->areq.an_val;
1991 bcopy((char *)&sc->an_sigitems, (char *)pt,
1994 sc->areq.an_len = sizeof(int) / 2;
1995 bcopy((char *)&sc->an_sigcache, (char *)pt,
1996 sizeof(struct an_sigcache) * sc->an_sigitems);
1997 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1998 sc->an_sigitems) / 2) + 1;
2001 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
2007 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
2010 if ((error = priv_check(td, PRIV_DRIVER)))
2013 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
2016 an_setdef(sc, &sc->areq);
2019 case SIOCGPRIVATE_0: /* used by Cisco client utility */
2020 if ((error = priv_check(td, PRIV_DRIVER)))
2022 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2025 mode = l_ioctl.command;
2028 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
2029 error = readrids(ifp, &l_ioctl);
2030 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
2031 error = writerids(ifp, &l_ioctl);
2032 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
2033 error = flashcard(ifp, &l_ioctl);
2039 /* copy out the updated command info */
2040 error = copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
2043 case SIOCGPRIVATE_1: /* used by Cisco client utility */
2044 if ((error = priv_check(td, PRIV_DRIVER)))
2046 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
2049 l_ioctl.command = 0;
2051 (void) copyout(&error, l_ioctl.data, sizeof(error));
2055 sc->areq.an_len = sizeof(sc->areq);
2056 /* was that a good idea DJA we are doing a short-cut */
2057 switch (ireq->i_type) {
2058 case IEEE80211_IOC_SSID:
2060 if (ireq->i_val == -1) {
2061 sc->areq.an_type = AN_RID_STATUS;
2062 if (an_read_record(sc,
2063 (struct an_ltv_gen *)&sc->areq)) {
2068 len = status->an_ssidlen;
2069 tmpptr = status->an_ssid;
2070 } else if (ireq->i_val >= 0) {
2071 sc->areq.an_type = AN_RID_SSIDLIST;
2072 if (an_read_record(sc,
2073 (struct an_ltv_gen *)&sc->areq)) {
2078 max = (sc->areq.an_len - 4)
2079 / sizeof(struct an_ltv_ssid_entry);
2080 if ( max > MAX_SSIDS ) {
2081 printf("To many SSIDs only using "
2086 if (ireq->i_val > max) {
2091 len = ssids->an_entry[ireq->i_val].an_len;
2092 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2099 if (len > IEEE80211_NWID_LEN) {
2106 bzero(tmpstr, IEEE80211_NWID_LEN);
2107 bcopy(tmpptr, tmpstr, len);
2108 error = copyout(tmpstr, ireq->i_data,
2109 IEEE80211_NWID_LEN);
2111 case IEEE80211_IOC_NUMSSIDS:
2113 sc->areq.an_len = sizeof(sc->areq);
2114 sc->areq.an_type = AN_RID_SSIDLIST;
2115 if (an_read_record(sc,
2116 (struct an_ltv_gen *)&sc->areq)) {
2121 max = (sc->areq.an_len - 4)
2122 / sizeof(struct an_ltv_ssid_entry);
2124 if ( max > MAX_SSIDS ) {
2125 printf("To many SSIDs only using "
2132 case IEEE80211_IOC_WEP:
2134 sc->areq.an_type = AN_RID_ACTUALCFG;
2135 if (an_read_record(sc,
2136 (struct an_ltv_gen *)&sc->areq)) {
2142 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2143 if (config->an_authtype &
2144 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2145 ireq->i_val = IEEE80211_WEP_MIXED;
2147 ireq->i_val = IEEE80211_WEP_ON;
2149 ireq->i_val = IEEE80211_WEP_OFF;
2152 case IEEE80211_IOC_WEPKEY:
2154 * XXX: I'm not entierly convinced this is
2155 * correct, but it's what is implemented in
2156 * ancontrol so it will have to do until we get
2157 * access to actual Cisco code.
2159 if (ireq->i_val < 0 || ireq->i_val > 8) {
2164 if (ireq->i_val < 5) {
2166 sc->areq.an_type = AN_RID_WEP_TEMP;
2167 for (i = 0; i < 5; i++) {
2168 if (an_read_record(sc,
2169 (struct an_ltv_gen *)&sc->areq)) {
2173 if (key->kindex == 0xffff)
2175 if (key->kindex == ireq->i_val)
2177 /* Required to get next entry */
2178 sc->areq.an_type = AN_RID_WEP_PERM;
2185 /* We aren't allowed to read the value of the
2186 * key from the card so we just output zeros
2187 * like we would if we could read the card, but
2188 * denied the user access.
2192 error = copyout(tmpstr, ireq->i_data, len);
2194 case IEEE80211_IOC_NUMWEPKEYS:
2195 ireq->i_val = 9; /* include home key */
2197 case IEEE80211_IOC_WEPTXKEY:
2199 * For some strange reason, you have to read all
2200 * keys before you can read the txkey.
2203 sc->areq.an_type = AN_RID_WEP_TEMP;
2204 for (i = 0; i < 5; i++) {
2205 if (an_read_record(sc,
2206 (struct an_ltv_gen *) &sc->areq)) {
2210 if (key->kindex == 0xffff) {
2213 /* Required to get next entry */
2214 sc->areq.an_type = AN_RID_WEP_PERM;
2221 sc->areq.an_type = AN_RID_WEP_PERM;
2222 key->kindex = 0xffff;
2223 if (an_read_record(sc,
2224 (struct an_ltv_gen *)&sc->areq)) {
2229 ireq->i_val = key->mac[0];
2231 * Check for home mode. Map home mode into
2232 * 5th key since that is how it is stored on
2235 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2236 sc->areq.an_type = AN_RID_GENCONFIG;
2237 if (an_read_record(sc,
2238 (struct an_ltv_gen *)&sc->areq)) {
2243 if (config->an_home_product & AN_HOME_NETWORK)
2247 case IEEE80211_IOC_AUTHMODE:
2249 sc->areq.an_type = AN_RID_ACTUALCFG;
2250 if (an_read_record(sc,
2251 (struct an_ltv_gen *)&sc->areq)) {
2257 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2259 ireq->i_val = IEEE80211_AUTH_NONE;
2260 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2262 ireq->i_val = IEEE80211_AUTH_OPEN;
2263 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2264 AN_AUTHTYPE_SHAREDKEY) {
2265 ireq->i_val = IEEE80211_AUTH_SHARED;
2269 case IEEE80211_IOC_STATIONNAME:
2271 sc->areq.an_type = AN_RID_ACTUALCFG;
2272 if (an_read_record(sc,
2273 (struct an_ltv_gen *)&sc->areq)) {
2279 ireq->i_len = sizeof(config->an_nodename);
2280 tmpptr = config->an_nodename;
2281 bzero(tmpstr, IEEE80211_NWID_LEN);
2282 bcopy(tmpptr, tmpstr, ireq->i_len);
2283 error = copyout(tmpstr, ireq->i_data,
2284 IEEE80211_NWID_LEN);
2286 case IEEE80211_IOC_CHANNEL:
2288 sc->areq.an_type = AN_RID_STATUS;
2289 if (an_read_record(sc,
2290 (struct an_ltv_gen *)&sc->areq)) {
2296 ireq->i_val = status->an_cur_channel;
2298 case IEEE80211_IOC_CURCHAN:
2300 sc->areq.an_type = AN_RID_STATUS;
2301 if (an_read_record(sc,
2302 (struct an_ltv_gen *)&sc->areq)) {
2308 bzero(&ch, sizeof(ch));
2309 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2311 ch.ic_flags = IEEE80211_CHAN_B;
2312 ch.ic_ieee = status->an_cur_channel;
2313 error = copyout(&ch, ireq->i_data, sizeof(ch));
2315 case IEEE80211_IOC_POWERSAVE:
2317 sc->areq.an_type = AN_RID_ACTUALCFG;
2318 if (an_read_record(sc,
2319 (struct an_ltv_gen *)&sc->areq)) {
2325 if (config->an_psave_mode == AN_PSAVE_NONE) {
2326 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2327 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2328 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2329 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2330 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2331 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2332 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2336 case IEEE80211_IOC_POWERSAVESLEEP:
2338 sc->areq.an_type = AN_RID_ACTUALCFG;
2339 if (an_read_record(sc,
2340 (struct an_ltv_gen *)&sc->areq)) {
2346 ireq->i_val = config->an_listen_interval;
2351 if ((error = priv_check(td, PRIV_NET80211_MANAGE)))
2354 sc->areq.an_len = sizeof(sc->areq);
2356 * We need a config structure for everything but the WEP
2357 * key management and SSIDs so we get it now so avoid
2358 * duplicating this code every time.
2360 if (ireq->i_type != IEEE80211_IOC_SSID &&
2361 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2362 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2363 sc->areq.an_type = AN_RID_GENCONFIG;
2364 if (an_read_record(sc,
2365 (struct an_ltv_gen *)&sc->areq)) {
2371 switch (ireq->i_type) {
2372 case IEEE80211_IOC_SSID:
2373 sc->areq.an_len = sizeof(sc->areq);
2374 sc->areq.an_type = AN_RID_SSIDLIST;
2375 if (an_read_record(sc,
2376 (struct an_ltv_gen *)&sc->areq)) {
2381 if (ireq->i_len > IEEE80211_NWID_LEN) {
2386 max = (sc->areq.an_len - 4)
2387 / sizeof(struct an_ltv_ssid_entry);
2388 if ( max > MAX_SSIDS ) {
2389 printf("To many SSIDs only using "
2394 if (ireq->i_val > max) {
2399 error = copyin(ireq->i_data,
2400 ssids->an_entry[ireq->i_val].an_ssid,
2402 ssids->an_entry[ireq->i_val].an_len
2404 sc->areq.an_len = sizeof(sc->areq);
2405 sc->areq.an_type = AN_RID_SSIDLIST;
2406 an_setdef(sc, &sc->areq);
2411 case IEEE80211_IOC_WEP:
2412 switch (ireq->i_val) {
2413 case IEEE80211_WEP_OFF:
2414 config->an_authtype &=
2415 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2416 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2418 case IEEE80211_WEP_ON:
2419 config->an_authtype |=
2420 AN_AUTHTYPE_PRIVACY_IN_USE;
2421 config->an_authtype &=
2422 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2424 case IEEE80211_WEP_MIXED:
2425 config->an_authtype |=
2426 AN_AUTHTYPE_PRIVACY_IN_USE |
2427 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2433 if (error != EINVAL)
2434 an_setdef(sc, &sc->areq);
2437 case IEEE80211_IOC_WEPKEY:
2438 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2444 error = copyin(ireq->i_data, tmpstr, 13);
2450 * Map the 9th key into the home mode
2451 * since that is how it is stored on
2454 bzero(&sc->areq, sizeof(struct an_ltv_key));
2455 sc->areq.an_len = sizeof(struct an_ltv_key);
2456 key->mac[0] = 1; /* The others are 0. */
2457 if (ireq->i_val < 4) {
2458 sc->areq.an_type = AN_RID_WEP_TEMP;
2459 key->kindex = ireq->i_val;
2461 sc->areq.an_type = AN_RID_WEP_PERM;
2462 key->kindex = ireq->i_val - 4;
2464 key->klen = ireq->i_len;
2465 bcopy(tmpstr, key->key, key->klen);
2466 an_setdef(sc, &sc->areq);
2469 case IEEE80211_IOC_WEPTXKEY:
2470 if (ireq->i_val < 0 || ireq->i_val > 4) {
2477 * Map the 5th key into the home mode
2478 * since that is how it is stored on
2481 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2482 sc->areq.an_type = AN_RID_ACTUALCFG;
2483 if (an_read_record(sc,
2484 (struct an_ltv_gen *)&sc->areq)) {
2490 if (ireq->i_val == 4) {
2491 config->an_home_product |= AN_HOME_NETWORK;
2494 config->an_home_product &= ~AN_HOME_NETWORK;
2497 sc->an_config.an_home_product
2498 = config->an_home_product;
2500 /* update configuration */
2503 bzero(&sc->areq, sizeof(struct an_ltv_key));
2505 sc->areq.an_len = sizeof(struct an_ltv_key);
2506 sc->areq.an_type = AN_RID_WEP_PERM;
2507 key->kindex = 0xffff;
2508 key->mac[0] = ireq->i_val;
2509 an_setdef(sc, &sc->areq);
2512 case IEEE80211_IOC_AUTHMODE:
2513 switch (ireq->i_val) {
2514 case IEEE80211_AUTH_NONE:
2515 config->an_authtype = AN_AUTHTYPE_NONE |
2516 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2518 case IEEE80211_AUTH_OPEN:
2519 config->an_authtype = AN_AUTHTYPE_OPEN |
2520 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2522 case IEEE80211_AUTH_SHARED:
2523 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2524 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2529 if (error != EINVAL) {
2530 an_setdef(sc, &sc->areq);
2534 case IEEE80211_IOC_STATIONNAME:
2535 if (ireq->i_len > 16) {
2540 bzero(config->an_nodename, 16);
2541 error = copyin(ireq->i_data,
2542 config->an_nodename, ireq->i_len);
2543 an_setdef(sc, &sc->areq);
2546 case IEEE80211_IOC_CHANNEL:
2548 * The actual range is 1-14, but if you set it
2549 * to 0 you get the default so we let that work
2552 if (ireq->i_val < 0 || ireq->i_val >14) {
2557 config->an_ds_channel = ireq->i_val;
2558 an_setdef(sc, &sc->areq);
2561 case IEEE80211_IOC_POWERSAVE:
2562 switch (ireq->i_val) {
2563 case IEEE80211_POWERSAVE_OFF:
2564 config->an_psave_mode = AN_PSAVE_NONE;
2566 case IEEE80211_POWERSAVE_CAM:
2567 config->an_psave_mode = AN_PSAVE_CAM;
2569 case IEEE80211_POWERSAVE_PSP:
2570 config->an_psave_mode = AN_PSAVE_PSP;
2572 case IEEE80211_POWERSAVE_PSP_CAM:
2573 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2579 an_setdef(sc, &sc->areq);
2582 case IEEE80211_IOC_POWERSAVESLEEP:
2583 config->an_listen_interval = ireq->i_val;
2584 an_setdef(sc, &sc->areq);
2592 an_setdef(sc, &sc->areq);
2598 error = ether_ioctl(ifp, command, data);
2607 an_init_tx_ring(struct an_softc *sc)
2616 for (i = 0; i < AN_TX_RING_CNT; i++) {
2617 if (an_alloc_nicmem(sc, 1518 +
2620 sc->an_rdata.an_tx_fids[i] = id;
2621 sc->an_rdata.an_tx_ring[i] = 0;
2625 sc->an_rdata.an_tx_prod = 0;
2626 sc->an_rdata.an_tx_cons = 0;
2627 sc->an_rdata.an_tx_empty = 1;
2635 struct an_softc *sc = xsc;
2636 struct ifnet *ifp = sc->an_ifp;
2645 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2648 sc->an_associated = 0;
2650 /* Allocate the TX buffers */
2651 if (an_init_tx_ring(sc)) {
2654 an_init_mpi350_desc(sc);
2655 if (an_init_tx_ring(sc)) {
2656 printf("an%d: tx buffer allocation "
2657 "failed\n", sc->an_unit);
2663 /* Set our MAC address. */
2664 bcopy((char *)IF_LLADDR(sc->an_ifp),
2665 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2667 if (ifp->if_flags & IFF_BROADCAST)
2668 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2670 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2672 if (ifp->if_flags & IFF_MULTICAST)
2673 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2675 if (ifp->if_flags & IFF_PROMISC) {
2676 if (sc->an_monitor & AN_MONITOR) {
2677 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2678 sc->an_config.an_rxmode |=
2679 AN_RXMODE_80211_MONITOR_ANYBSS |
2680 AN_RXMODE_NO_8023_HEADER;
2682 sc->an_config.an_rxmode |=
2683 AN_RXMODE_80211_MONITOR_CURBSS |
2684 AN_RXMODE_NO_8023_HEADER;
2690 if (sc->an_have_rssimap)
2691 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2694 /* Set the ssid list */
2695 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2696 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2697 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2698 printf("an%d: failed to set ssid list\n", sc->an_unit);
2703 /* Set the AP list */
2704 sc->an_aplist.an_type = AN_RID_APLIST;
2705 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2706 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2707 printf("an%d: failed to set AP list\n", sc->an_unit);
2712 /* Set the configuration in the NIC */
2713 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2714 sc->an_config.an_type = AN_RID_GENCONFIG;
2715 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2716 printf("an%d: failed to set configuration\n", sc->an_unit);
2721 /* Enable the MAC */
2722 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2723 printf("an%d: failed to enable MAC\n", sc->an_unit);
2728 if (ifp->if_flags & IFF_PROMISC)
2729 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2731 /* enable interrupts */
2732 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2734 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2735 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2737 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2744 an_start(struct ifnet *ifp)
2746 struct an_softc *sc;
2747 struct mbuf *m0 = NULL;
2748 struct an_txframe_802_3 tx_frame_802_3;
2749 struct ether_header *eh;
2751 unsigned char txcontrol;
2752 struct an_card_tx_desc an_tx_desc;
2760 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2763 if (!sc->an_associated)
2766 /* We can't send in monitor mode so toss any attempts. */
2767 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2769 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2777 idx = sc->an_rdata.an_tx_prod;
2781 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2783 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2784 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2788 id = sc->an_rdata.an_tx_fids[idx];
2789 eh = mtod(m0, struct ether_header *);
2791 bcopy((char *)&eh->ether_dhost,
2792 (char *)&tx_frame_802_3.an_tx_dst_addr,
2794 bcopy((char *)&eh->ether_shost,
2795 (char *)&tx_frame_802_3.an_tx_src_addr,
2798 /* minus src/dest mac & type */
2799 tx_frame_802_3.an_tx_802_3_payload_len =
2800 m0->m_pkthdr.len - 12;
2802 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2803 tx_frame_802_3.an_tx_802_3_payload_len,
2804 (caddr_t)&sc->an_txbuf);
2806 txcontrol = AN_TXCTL_8023;
2807 /* write the txcontrol only */
2808 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2812 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2813 sizeof(struct an_txframe_802_3));
2815 /* in mbuf header type is just before payload */
2816 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2817 tx_frame_802_3.an_tx_802_3_payload_len);
2820 * If there's a BPF listner, bounce a copy of
2821 * this frame to him.
2828 sc->an_rdata.an_tx_ring[idx] = id;
2829 if (an_cmd(sc, AN_CMD_TX, id))
2830 printf("an%d: xmit failed\n", sc->an_unit);
2832 AN_INC(idx, AN_TX_RING_CNT);
2835 * Set a timeout in case the chip goes out to lunch.
2839 } else { /* MPI-350 */
2840 /* Disable interrupts. */
2841 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2843 while (sc->an_rdata.an_tx_empty ||
2844 idx != sc->an_rdata.an_tx_cons) {
2845 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2849 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2851 eh = mtod(m0, struct ether_header *);
2853 /* DJA optimize this to limit bcopy */
2854 bcopy((char *)&eh->ether_dhost,
2855 (char *)&tx_frame_802_3.an_tx_dst_addr,
2857 bcopy((char *)&eh->ether_shost,
2858 (char *)&tx_frame_802_3.an_tx_src_addr,
2861 /* minus src/dest mac & type */
2862 tx_frame_802_3.an_tx_802_3_payload_len =
2863 m0->m_pkthdr.len - 12;
2865 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2866 tx_frame_802_3.an_tx_802_3_payload_len,
2867 (caddr_t)&sc->an_txbuf);
2869 txcontrol = AN_TXCTL_8023;
2870 /* write the txcontrol only */
2871 bcopy((caddr_t)&txcontrol, &buf[0x08],
2875 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2876 sizeof(struct an_txframe_802_3));
2878 /* in mbuf header type is just before payload */
2879 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2880 tx_frame_802_3.an_tx_802_3_payload_len);
2883 bzero(&an_tx_desc, sizeof(an_tx_desc));
2884 an_tx_desc.an_offset = 0;
2885 an_tx_desc.an_eoc = 1;
2886 an_tx_desc.an_valid = 1;
2887 an_tx_desc.an_len = 0x44 +
2888 tx_frame_802_3.an_tx_802_3_payload_len;
2890 = sc->an_tx_buffer[idx].an_dma_paddr;
2891 for (i = 0; i < sizeof(an_tx_desc) / 4 ; i++) {
2892 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2894 + (0 * sizeof(an_tx_desc))
2896 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2900 * If there's a BPF listner, bounce a copy of
2901 * this frame to him.
2907 AN_INC(idx, AN_MAX_TX_DESC);
2908 sc->an_rdata.an_tx_empty = 0;
2909 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2912 * Set a timeout in case the chip goes out to lunch.
2917 /* Re-enable interrupts. */
2918 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2923 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2925 sc->an_rdata.an_tx_prod = idx;
2931 an_stop(struct an_softc *sc)
2945 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2946 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2947 an_cmd(sc, AN_CMD_DISABLE, 0);
2949 for (i = 0; i < AN_TX_RING_CNT; i++)
2950 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2952 callout_stop(&sc->an_stat_ch);
2954 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2956 if (sc->an_flash_buffer) {
2957 free(sc->an_flash_buffer, M_DEVBUF);
2958 sc->an_flash_buffer = NULL;
2967 an_watchdog(struct ifnet *ifp)
2969 struct an_softc *sc;
2979 printf("an%d: device timeout\n", sc->an_unit);
2983 an_init_mpi350_desc(sc);
2993 an_shutdown(device_t dev)
2995 struct an_softc *sc;
2997 sc = device_get_softc(dev);
3005 an_resume(device_t dev)
3007 struct an_softc *sc;
3011 sc = device_get_softc(dev);
3018 an_init_mpi350_desc(sc);
3021 /* Recovery temporary keys */
3022 for (i = 0; i < 4; i++) {
3023 sc->areq.an_type = AN_RID_WEP_TEMP;
3024 sc->areq.an_len = sizeof(struct an_ltv_key);
3025 bcopy(&sc->an_temp_keys[i],
3026 &sc->areq, sizeof(struct an_ltv_key));
3027 an_setdef(sc, &sc->areq);
3030 if (ifp->if_flags & IFF_UP)
3038 /* Aironet signal strength cache code.
3039 * store signal/noise/quality on per MAC src basis in
3040 * a small fixed cache. The cache wraps if > MAX slots
3041 * used. The cache may be zeroed out to start over.
3042 * Two simple filters exist to reduce computation:
3043 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
3044 * to ignore some packets. It defaults to ip only.
3045 * it could be used to focus on broadcast, non-IP 802.11 beacons.
3046 * 2. multicast/broadcast only. This may be used to
3047 * ignore unicast packets and only cache signal strength
3048 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
3049 * beacons and not unicast traffic.
3051 * The cache stores (MAC src(index), IP src (major clue), signal,
3054 * No apologies for storing IP src here. It's easy and saves much
3055 * trouble elsewhere. The cache is assumed to be INET dependent,
3056 * although it need not be.
3058 * Note: the Aironet only has a single byte of signal strength value
3059 * in the rx frame header, and it's not scaled to anything sensible.
3060 * This is kind of lame, but it's all we've got.
3063 #ifdef documentation
3065 int an_sigitems; /* number of cached entries */
3066 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
3067 int an_nextitem; /* index/# of entries */
3072 /* control variables for cache filtering. Basic idea is
3073 * to reduce cost (e.g., to only Mobile-IP agent beacons
3074 * which are broadcast or multicast). Still you might
3075 * want to measure signal strength anth unicast ping packets
3076 * on a pt. to pt. ant. setup.
3078 /* set true if you want to limit cache items to broadcast/mcast
3079 * only packets (not unicast). Useful for mobile-ip beacons which
3080 * are broadcast/multicast at network layer. Default is all packets
3081 * so ping/unicast anll work say anth pt. to pt. antennae setup.
3083 static int an_cache_mcastonly = 0;
3084 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
3085 &an_cache_mcastonly, 0, "");
3087 /* set true if you want to limit cache items to IP packets only
3089 static int an_cache_iponly = 1;
3090 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
3091 &an_cache_iponly, 0, "");
3094 * an_cache_store, per rx packet store signal
3095 * strength in MAC (src) indexed cache.
3098 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
3099 u_int8_t rx_rssi, u_int8_t rx_quality)
3103 static int cache_slot = 0; /* use this cache entry */
3104 static int wrapindex = 0; /* next "free" cache entry */
3109 * 2. configurable filter to throw out unicast packets,
3110 * keep multicast only.
3113 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
3117 /* filter for ip packets only
3119 if ( an_cache_iponly && !type_ipv4) {
3123 /* filter for broadcast/multicast only
3125 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3130 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
3131 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3134 /* find the ip header. we want to store the ip_src
3138 ip = mtod(m, struct ip *);
3141 /* do a linear search for a matching MAC address
3142 * in the cache table
3143 * . MAC address is 6 bytes,
3144 * . var w_nextitem holds total number of entries already cached
3146 for (i = 0; i < sc->an_nextitem; i++) {
3147 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3149 * so we already have this entry,
3156 /* did we find a matching mac address?
3157 * if yes, then overwrite a previously existing cache entry
3159 if (i < sc->an_nextitem ) {
3162 /* else, have a new address entry,so
3163 * add this new entry,
3164 * if table full, then we need to replace LRU entry
3168 /* check for space in cache table
3169 * note: an_nextitem also holds number of entries
3170 * added in the cache table
3172 if ( sc->an_nextitem < MAXANCACHE ) {
3173 cache_slot = sc->an_nextitem;
3175 sc->an_sigitems = sc->an_nextitem;
3177 /* no space found, so simply wrap anth wrap index
3178 * and "zap" the next entry
3181 if (wrapindex == MAXANCACHE) {
3184 cache_slot = wrapindex++;
3188 /* invariant: cache_slot now points at some slot
3191 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3192 log(LOG_ERR, "an_cache_store, bad index: %d of "
3193 "[0..%d], gross cache error\n",
3194 cache_slot, MAXANCACHE);
3198 /* store items in cache
3199 * .ip source address
3204 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3206 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3209 switch (an_cache_mode) {
3211 if (sc->an_have_rssimap) {
3212 sc->an_sigcache[cache_slot].signal =
3213 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3214 sc->an_sigcache[cache_slot].quality =
3215 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3217 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3218 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3222 if (sc->an_have_rssimap) {
3223 sc->an_sigcache[cache_slot].signal =
3224 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3225 sc->an_sigcache[cache_slot].quality =
3226 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3230 if (rx_quality > 100)
3232 sc->an_sigcache[cache_slot].signal = rx_rssi;
3233 sc->an_sigcache[cache_slot].quality = rx_quality;
3237 sc->an_sigcache[cache_slot].signal = rx_rssi;
3238 sc->an_sigcache[cache_slot].quality = rx_quality;
3242 sc->an_sigcache[cache_slot].noise = 0;
3249 an_media_change(struct ifnet *ifp)
3251 struct an_softc *sc = ifp->if_softc;
3252 struct an_ltv_genconfig *cfg;
3253 int otype = sc->an_config.an_opmode;
3254 int orate = sc->an_tx_rate;
3256 sc->an_tx_rate = ieee80211_media2rate(
3257 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3258 if (sc->an_tx_rate < 0)
3262 if (orate != sc->an_tx_rate) {
3263 /* Read the current configuration */
3264 sc->an_config.an_type = AN_RID_GENCONFIG;
3265 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3266 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3267 cfg = &sc->an_config;
3269 /* clear other rates and set the only one we want */
3270 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3271 cfg->an_rates[0] = sc->an_tx_rate;
3273 /* Save the new rate */
3274 sc->an_config.an_type = AN_RID_GENCONFIG;
3275 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3278 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3279 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3281 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3284 if (otype != sc->an_config.an_opmode ||
3285 orate != sc->an_tx_rate)
3292 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3294 struct an_ltv_status status;
3295 struct an_softc *sc = ifp->if_softc;
3297 imr->ifm_active = IFM_IEEE80211;
3300 status.an_len = sizeof(status);
3301 status.an_type = AN_RID_STATUS;
3302 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3303 /* If the status read fails, just lie. */
3304 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3305 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3309 if (sc->an_tx_rate == 0) {
3310 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3313 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3314 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3315 imr->ifm_active |= ieee80211_rate2media(NULL,
3316 status.an_current_tx_rate, IEEE80211_T_DS);
3317 imr->ifm_status = IFM_AVALID;
3318 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3319 imr->ifm_status |= IFM_ACTIVE;
3322 /********************** Cisco utility support routines *************/
3325 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3330 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3333 struct an_softc *sc;
3336 switch (l_ioctl->command) {
3338 rid = AN_RID_CAPABILITIES;
3341 rid = AN_RID_GENCONFIG;
3344 rid = AN_RID_SSIDLIST;
3347 rid = AN_RID_APLIST;
3350 rid = AN_RID_DRVNAME;
3353 rid = AN_RID_ENCAPPROTO;
3356 rid = AN_RID_WEP_TEMP;
3359 rid = AN_RID_WEP_PERM;
3362 rid = AN_RID_STATUS;
3365 rid = AN_RID_32BITS_DELTA;
3368 rid = AN_RID_32BITS_CUM;
3375 if (rid == 999) /* Is bad command */
3379 sc->areq.an_len = AN_MAX_DATALEN;
3380 sc->areq.an_type = rid;
3382 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3384 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3387 /* the data contains the length at first */
3388 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3389 sizeof(sc->areq.an_len))) {
3393 /* Just copy the data back */
3394 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3406 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3408 struct an_softc *sc;
3409 int rid, command, error;
3414 command = l_ioctl->command;
3418 rid = AN_RID_SSIDLIST;
3421 rid = AN_RID_CAPABILITIES;
3424 rid = AN_RID_APLIST;
3427 rid = AN_RID_GENCONFIG;
3430 an_cmd(sc, AN_CMD_ENABLE, 0);
3434 an_cmd(sc, AN_CMD_DISABLE, 0);
3439 * This command merely clears the counts does not actually
3440 * store any data only reads rid. But as it changes the cards
3441 * state, I put it in the writerid routines.
3444 rid = AN_RID_32BITS_DELTACLR;
3446 sc->areq.an_len = AN_MAX_DATALEN;
3447 sc->areq.an_type = rid;
3449 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3450 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3453 /* the data contains the length at first */
3454 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3455 sizeof(sc->areq.an_len));
3460 /* Just copy the data */
3461 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3469 rid = AN_RID_WEP_TEMP;
3472 rid = AN_RID_WEP_PERM;
3475 rid = AN_RID_LEAPUSERNAME;
3478 rid = AN_RID_LEAPPASSWORD;
3485 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3487 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3488 sc->areq.an_type = rid;
3490 /* Just copy the data back */
3492 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3498 an_cmd(sc, AN_CMD_DISABLE, 0);
3499 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3500 an_cmd(sc, AN_CMD_ENABLE, 0);
3507 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3511 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3512 "flash", ((x) / hz) + 1);
3513 #define FLASH_COMMAND 0x7e7e
3514 #define FLASH_SIZE 32 * 1024
3517 unstickbusy(struct ifnet *ifp)
3519 struct an_softc *sc = ifp->if_softc;
3521 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3522 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3523 AN_EV_CLR_STUCK_BUSY);
3530 * Wait for busy completion from card wait for delay uSec's Return true for
3531 * success meaning command reg is clear
3535 WaitBusy(struct ifnet *ifp, int uSec)
3537 int statword = 0xffff;
3539 struct an_softc *sc = ifp->if_softc;
3541 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3542 FLASH_DELAY(sc, 10);
3544 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3546 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3551 return 0 == (AN_CMD_BUSY & statword);
3555 * STEP 1) Disable MAC and do soft reset on card.
3559 cmdreset(struct ifnet *ifp)
3562 struct an_softc *sc = ifp->if_softc;
3567 an_cmd(sc, AN_CMD_DISABLE, 0);
3569 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3570 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3571 sc->an_unit, status);
3575 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3577 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3580 if (!(status = WaitBusy(ifp, 100))) {
3581 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3582 sc->an_unit, status);
3591 * STEP 2) Put the card in legendary flash mode
3595 setflashmode(struct ifnet *ifp)
3598 struct an_softc *sc = ifp->if_softc;
3600 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3601 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3602 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3603 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3606 * mdelay(500); // 500ms delay
3609 FLASH_DELAY(sc, 500);
3611 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3612 printf("Waitbusy hang after setflash mode\n");
3619 * Get a character from the card matching matchbyte Step 3)
3623 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3626 unsigned char rbyte = 0;
3628 struct an_softc *sc = ifp->if_softc;
3632 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3634 if (dwelltime && !(0x8000 & rchar)) {
3636 FLASH_DELAY(sc, 10);
3639 rbyte = 0xff & rchar;
3641 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3642 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3646 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3648 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3650 } while (dwelltime > 0);
3655 * Put character to SWS0 wait for dwelltime x 50us for echo .
3659 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3662 int pollbusy, waittime;
3663 struct an_softc *sc = ifp->if_softc;
3670 waittime = dwelltime;
3673 * Wait for busy bit d15 to go false indicating buffer empty
3676 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3678 if (pollbusy & 0x8000) {
3679 FLASH_DELAY(sc, 50);
3685 while (waittime >= 0);
3687 /* timeout for busy clear wait */
3689 if (waittime <= 0) {
3690 printf("an%d: flash putchar busywait timeout! \n",
3695 * Port is clear now write byte and wait for it to echo back
3698 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3699 FLASH_DELAY(sc, 50);
3701 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3702 } while (dwelltime >= 0 && echo != byte);
3705 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3707 return echo == byte;
3711 * Transfer 32k of firmware data from user buffer to our buffer and send to
3716 flashputbuf(struct ifnet *ifp)
3718 unsigned short *bufp;
3720 struct an_softc *sc = ifp->if_softc;
3724 bufp = sc->an_flash_buffer;
3727 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3728 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3730 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3731 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3734 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3735 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3736 ((u_int32_t *)bufp)[nwords] & 0xffff);
3740 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3746 * After flashing restart the card.
3750 flashrestart(struct ifnet *ifp)
3753 struct an_softc *sc = ifp->if_softc;
3755 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3761 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3766 * Entry point for flash ioclt.
3770 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3773 struct an_softc *sc;
3777 printf("an%d: flashing not supported on MPI 350 yet\n",
3781 status = l_ioctl->command;
3783 switch (l_ioctl->command) {
3785 return cmdreset(ifp);
3788 if (sc->an_flash_buffer) {
3789 free(sc->an_flash_buffer, M_DEVBUF);
3790 sc->an_flash_buffer = NULL;
3792 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3793 if (sc->an_flash_buffer)
3794 return setflashmode(ifp);
3798 case AIROFLSHGCHR: /* Get char from aux */
3800 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3804 z = *(int *)&sc->areq;
3805 if ((status = flashgchar(ifp, z, 8000)) == 1)
3809 case AIROFLSHPCHR: /* Send char to card. */
3811 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3815 z = *(int *)&sc->areq;
3816 if ((status = flashpchar(ifp, z, 8000)) == -1)
3821 case AIROFLPUTBUF: /* Send 32k to card */
3822 if (l_ioctl->len > FLASH_SIZE) {
3823 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3824 l_ioctl->len, FLASH_SIZE);
3828 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3833 if ((status = flashputbuf(ifp)) != 0)
3839 if ((status = flashrestart(ifp)) != 0) {
3840 printf("an%d: FLASHRESTART returned %d\n",
3841 sc->an_unit, status);