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 * We probe for an Aironet 4500/4800 card by attempting to
307 * read the default SSID list. On reset, the first entry in
308 * the SSID list will contain the name "tsunami." If we don't
309 * find this, then there's no card present.
312 an_probe(device_t dev)
314 struct an_softc *sc = device_get_softc(dev);
315 struct an_ltv_ssidlist_new ssid;
318 bzero((char *)&ssid, sizeof(ssid));
320 error = an_alloc_port(dev, 0, AN_IOSIZ);
324 /* can't do autoprobing */
325 if (rman_get_start(sc->port_res) == -1)
329 * We need to fake up a softc structure long enough
330 * to be able to issue commands and call some of the
333 sc->an_bhandle = rman_get_bushandle(sc->port_res);
334 sc->an_btag = rman_get_bustag(sc->port_res);
335 sc->an_unit = device_get_unit(dev);
337 ssid.an_len = sizeof(ssid);
338 ssid.an_type = AN_RID_SSIDLIST;
340 /* Make sure interrupts are disabled. */
342 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
343 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
347 if (an_cmd(sc, AN_CMD_READCFG, 0))
350 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
353 /* See if the ssid matches what we expect ... but doesn't have to */
354 if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID))
361 * Allocate a port resource with the given resource id.
364 an_alloc_port(device_t dev, int rid, int size)
366 struct an_softc *sc = device_get_softc(dev);
367 struct resource *res;
369 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
370 0ul, ~0ul, size, RF_ACTIVE);
381 * Allocate a memory resource with the given resource id.
383 int an_alloc_memory(device_t dev, int rid, int size)
385 struct an_softc *sc = device_get_softc(dev);
386 struct resource *res;
388 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
389 0ul, ~0ul, size, RF_ACTIVE);
401 * Allocate a auxilary memory resource with the given resource id.
403 int an_alloc_aux_memory(device_t dev, int rid, int size)
405 struct an_softc *sc = device_get_softc(dev);
406 struct resource *res;
408 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
409 0ul, ~0ul, size, RF_ACTIVE);
411 sc->mem_aux_rid = rid;
412 sc->mem_aux_res = res;
413 sc->mem_aux_used = size;
421 * Allocate an irq resource with the given resource id.
424 an_alloc_irq(device_t dev, int rid, int flags)
426 struct an_softc *sc = device_get_softc(dev);
427 struct resource *res;
429 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
430 (RF_ACTIVE | flags));
441 an_dma_malloc_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
443 bus_addr_t *paddr = (bus_addr_t*) arg;
444 *paddr = segs->ds_addr;
448 * Alloc DMA memory and set the pointer to it
451 an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
456 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
460 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
461 BUS_DMA_NOWAIT, &dma->an_dma_map);
465 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
469 mapflags | BUS_DMA_NOWAIT);
473 dma->an_dma_size = size;
477 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
479 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
481 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
482 dma->an_dma_map = NULL;
487 an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
489 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
490 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
491 dma->an_dma_vaddr = 0;
492 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
496 * Release all resources
499 an_release_resources(device_t dev)
501 struct an_softc *sc = device_get_softc(dev);
505 bus_release_resource(dev, SYS_RES_IOPORT,
506 sc->port_rid, sc->port_res);
510 bus_release_resource(dev, SYS_RES_MEMORY,
511 sc->mem_rid, sc->mem_res);
514 if (sc->mem_aux_res) {
515 bus_release_resource(dev, SYS_RES_MEMORY,
516 sc->mem_aux_rid, sc->mem_aux_res);
520 bus_release_resource(dev, SYS_RES_IRQ,
521 sc->irq_rid, sc->irq_res);
524 if (sc->an_rid_buffer.an_dma_paddr) {
525 an_dma_free(sc, &sc->an_rid_buffer);
527 for (i = 0; i < AN_MAX_RX_DESC; i++)
528 if (sc->an_rx_buffer[i].an_dma_paddr) {
529 an_dma_free(sc, &sc->an_rx_buffer[i]);
531 for (i = 0; i < AN_MAX_TX_DESC; i++)
532 if (sc->an_tx_buffer[i].an_dma_paddr) {
533 an_dma_free(sc, &sc->an_tx_buffer[i]);
536 bus_dma_tag_destroy(sc->an_dtag);
542 an_init_mpi350_desc(struct an_softc *sc)
544 struct an_command cmd_struct;
545 struct an_reply reply;
546 struct an_card_rid_desc an_rid_desc;
547 struct an_card_rx_desc an_rx_desc;
548 struct an_card_tx_desc an_tx_desc;
551 if(!sc->an_rid_buffer.an_dma_paddr)
552 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
553 &sc->an_rid_buffer, 0);
554 for (i = 0; i < AN_MAX_RX_DESC; i++)
555 if(!sc->an_rx_buffer[i].an_dma_paddr)
556 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
557 &sc->an_rx_buffer[i], 0);
558 for (i = 0; i < AN_MAX_TX_DESC; i++)
559 if(!sc->an_tx_buffer[i].an_dma_paddr)
560 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
561 &sc->an_tx_buffer[i], 0);
564 * Allocate RX descriptor
566 bzero(&reply,sizeof(reply));
567 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
568 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
569 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
570 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
571 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
572 printf("an%d: failed to allocate RX descriptor\n",
577 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
578 bzero(&an_rx_desc, sizeof(an_rx_desc));
579 an_rx_desc.an_valid = 1;
580 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
581 an_rx_desc.an_done = 0;
582 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
584 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
585 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
586 + (desc * sizeof(an_rx_desc))
588 ((u_int32_t *)(void *)&an_rx_desc)[i]);
592 * Allocate TX descriptor
595 bzero(&reply,sizeof(reply));
596 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
597 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
598 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
599 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
600 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
601 printf("an%d: failed to allocate TX descriptor\n",
606 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
607 bzero(&an_tx_desc, sizeof(an_tx_desc));
608 an_tx_desc.an_offset = 0;
609 an_tx_desc.an_eoc = 0;
610 an_tx_desc.an_valid = 0;
611 an_tx_desc.an_len = 0;
612 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
614 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
615 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
616 + (desc * sizeof(an_tx_desc))
618 ((u_int32_t *)(void *)&an_tx_desc)[i]);
622 * Allocate RID descriptor
625 bzero(&reply,sizeof(reply));
626 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
627 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
628 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
629 cmd_struct.an_parm2 = 1;
630 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
631 printf("an%d: failed to allocate host descriptor\n",
636 bzero(&an_rid_desc, sizeof(an_rid_desc));
637 an_rid_desc.an_valid = 1;
638 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
639 an_rid_desc.an_rid = 0;
640 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
642 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
643 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
644 ((u_int32_t *)(void *)&an_rid_desc)[i]);
650 an_attach(struct an_softc *sc, int unit, int flags)
657 mtx_init(&sc->an_mtx, device_get_nameunit(sc->an_dev), MTX_NETWORK_LOCK,
658 MTX_DEF | MTX_RECURSE);
659 ifp = sc->an_ifp = if_alloc(IFT_ETHER);
661 printf("an%d: can not if_alloc()\n", sc->an_unit);
666 sc->an_associated = 0;
668 sc->an_was_monitor = 0;
669 sc->an_flash_buffer = NULL;
674 error = an_init_mpi350_desc(sc);
679 /* Load factory config */
680 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
681 printf("an%d: failed to load config data\n", sc->an_unit);
685 /* Read the current configuration */
686 sc->an_config.an_type = AN_RID_GENCONFIG;
687 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
688 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
689 printf("an%d: read record failed\n", sc->an_unit);
693 /* Read the card capabilities */
694 sc->an_caps.an_type = AN_RID_CAPABILITIES;
695 sc->an_caps.an_len = sizeof(struct an_ltv_caps);
696 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
697 printf("an%d: read record failed\n", sc->an_unit);
702 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
703 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
704 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
705 printf("an%d: read record failed\n", sc->an_unit);
710 sc->an_aplist.an_type = AN_RID_APLIST;
711 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
712 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
713 printf("an%d: read record failed\n", sc->an_unit);
718 /* Read the RSSI <-> dBm map */
719 sc->an_have_rssimap = 0;
720 if (sc->an_caps.an_softcaps & 8) {
721 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
722 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
723 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
724 printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
726 printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
727 sc->an_have_rssimap = 1;
730 printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
736 if_initname(ifp, device_get_name(sc->an_dev),
737 device_get_unit(sc->an_dev));
738 ifp->if_mtu = ETHERMTU;
739 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
740 ifp->if_ioctl = an_ioctl;
741 ifp->if_start = an_start;
742 ifp->if_watchdog = an_watchdog;
743 ifp->if_init = an_init;
744 ifp->if_baudrate = 10000000;
745 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
746 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
747 IFQ_SET_READY(&ifp->if_snd);
749 bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
750 bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
751 sizeof(AN_DEFAULT_NODENAME) - 1);
753 bzero(sc->an_ssidlist.an_entry[0].an_ssid,
754 sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
755 bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
756 sizeof(AN_DEFAULT_NETNAME) - 1);
757 sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
759 sc->an_config.an_opmode =
760 AN_OPMODE_INFRASTRUCTURE_STATION;
763 bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
767 ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
768 if_printf(ifp, "supported rates: ");
769 #define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
770 IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
772 ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
773 for (i = 0; i < nrate; i++) {
774 r = sc->an_caps.an_rates[i];
775 mword = ieee80211_rate2media(NULL, r, IEEE80211_T_DS);
778 printf("%s%d%sMbps", (i != 0 ? " " : ""),
779 (r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
781 ADD(mword, IFM_IEEE80211_ADHOC);
784 ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
789 * Call MI attach routine.
792 ether_ifattach(ifp, sc->an_caps.an_oemaddr);
793 callout_init_mtx(&sc->an_stat_ch, &sc->an_mtx, 0);
797 mtx_destroy(&sc->an_mtx);
804 an_detach(device_t dev)
806 struct an_softc *sc = device_get_softc(dev);
807 struct ifnet *ifp = sc->an_ifp;
810 device_printf(dev,"already unloaded\n");
816 ifmedia_removeall(&sc->an_ifmedia);
817 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
820 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
821 callout_drain(&sc->an_stat_ch);
823 an_release_resources(dev);
824 mtx_destroy(&sc->an_mtx);
829 an_rxeof(struct an_softc *sc)
832 struct ether_header *eh;
833 struct ieee80211_frame *ih;
834 struct an_rxframe rx_frame;
835 struct an_rxframe_802_3 rx_frame_802_3;
837 int len, id, error = 0, i, count = 0;
838 int ieee80211_header_len;
841 struct an_card_rx_desc an_rx_desc;
849 id = CSR_READ_2(sc, AN_RX_FID);
851 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
852 /* read raw 802.11 packet */
853 bpf_buf = sc->buf_802_11;
856 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
863 * skip beacon by default since this increases the
867 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
868 (rx_frame.an_frame_ctl &
869 IEEE80211_FC0_SUBTYPE_BEACON)) {
873 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
874 len = rx_frame.an_rx_payload_len
876 /* Check for insane frame length */
877 if (len > sizeof(sc->buf_802_11)) {
878 printf("an%d: oversized packet "
879 "received (%d, %d)\n",
880 sc->an_unit, len, MCLBYTES);
885 bcopy((char *)&rx_frame,
886 bpf_buf, sizeof(rx_frame));
888 error = an_read_data(sc, id, sizeof(rx_frame),
889 (caddr_t)bpf_buf+sizeof(rx_frame),
890 rx_frame.an_rx_payload_len);
892 fc1=rx_frame.an_frame_ctl >> 8;
893 ieee80211_header_len =
894 sizeof(struct ieee80211_frame);
895 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
896 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
897 ieee80211_header_len += ETHER_ADDR_LEN;
900 len = rx_frame.an_rx_payload_len
901 + ieee80211_header_len;
902 /* Check for insane frame length */
903 if (len > sizeof(sc->buf_802_11)) {
904 printf("an%d: oversized packet "
905 "received (%d, %d)\n",
906 sc->an_unit, len, MCLBYTES);
911 ih = (struct ieee80211_frame *)bpf_buf;
913 bcopy((char *)&rx_frame.an_frame_ctl,
914 (char *)ih, ieee80211_header_len);
916 error = an_read_data(sc, id, sizeof(rx_frame) +
918 (caddr_t)ih +ieee80211_header_len,
919 rx_frame.an_rx_payload_len);
921 /* dump raw 802.11 packet to bpf and skip ip stack */
922 BPF_TAP(ifp, bpf_buf, len);
924 MGETHDR(m, M_DONTWAIT, MT_DATA);
929 MCLGET(m, M_DONTWAIT);
930 if (!(m->m_flags & M_EXT)) {
935 m->m_pkthdr.rcvif = ifp;
936 /* Read Ethernet encapsulated packet */
939 /* Read NIC frame header */
940 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
947 /* Read in the 802_3 frame header */
948 if (an_read_data(sc, id, 0x34,
949 (caddr_t)&rx_frame_802_3,
950 sizeof(rx_frame_802_3))) {
955 if (rx_frame_802_3.an_rx_802_3_status != 0) {
960 /* Check for insane frame length */
961 len = rx_frame_802_3.an_rx_802_3_payload_len;
962 if (len > sizeof(sc->buf_802_11)) {
964 printf("an%d: oversized packet "
965 "received (%d, %d)\n",
966 sc->an_unit, len, MCLBYTES);
970 m->m_pkthdr.len = m->m_len =
971 rx_frame_802_3.an_rx_802_3_payload_len + 12;
973 eh = mtod(m, struct ether_header *);
975 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
976 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
977 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
978 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
980 /* in mbuf header type is just before payload */
981 error = an_read_data(sc, id, 0x44,
982 (caddr_t)&(eh->ether_type),
983 rx_frame_802_3.an_rx_802_3_payload_len);
992 /* Receive packet. */
994 an_cache_store(sc, eh, m,
995 rx_frame.an_rx_signal_strength,
999 (*ifp->if_input)(ifp, m);
1003 } else { /* MPI-350 */
1004 for (count = 0; count < AN_MAX_RX_DESC; count++){
1005 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1006 ((u_int32_t *)(void *)&an_rx_desc)[i]
1007 = CSR_MEM_AUX_READ_4(sc,
1009 + (count * sizeof(an_rx_desc))
1012 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1013 buf = sc->an_rx_buffer[count].an_dma_vaddr;
1015 MGETHDR(m, M_DONTWAIT, MT_DATA);
1020 MCLGET(m, M_DONTWAIT);
1021 if (!(m->m_flags & M_EXT)) {
1026 m->m_pkthdr.rcvif = ifp;
1027 /* Read Ethernet encapsulated packet */
1030 * No ANCACHE support since we just get back
1031 * an Ethernet packet no 802.11 info
1035 /* Read NIC frame header */
1036 bcopy(buf, (caddr_t)&rx_frame,
1040 /* Check for insane frame length */
1041 len = an_rx_desc.an_len + 12;
1042 if (len > MCLBYTES) {
1044 printf("an%d: oversized packet "
1045 "received (%d, %d)\n",
1046 sc->an_unit, len, MCLBYTES);
1051 m->m_pkthdr.len = m->m_len =
1052 an_rx_desc.an_len + 12;
1054 eh = mtod(m, struct ether_header *);
1056 bcopy(buf, (char *)eh,
1061 /* Receive packet. */
1064 an_cache_store(sc, eh, m,
1065 rx_frame.an_rx_signal_strength,
1070 (*ifp->if_input)(ifp, m);
1073 an_rx_desc.an_valid = 1;
1074 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1075 an_rx_desc.an_done = 0;
1076 an_rx_desc.an_phys =
1077 sc->an_rx_buffer[count].an_dma_paddr;
1079 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1080 CSR_MEM_AUX_WRITE_4(sc,
1082 + (count * sizeof(an_rx_desc))
1084 ((u_int32_t *)(void *)&an_rx_desc)[i]);
1087 printf("an%d: Didn't get valid RX packet "
1091 an_rx_desc.an_valid, an_rx_desc.an_len);
1098 an_txeof(struct an_softc *sc, int status)
1106 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1109 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1111 if (status & AN_EV_TX_EXC) {
1116 for (i = 0; i < AN_TX_RING_CNT; i++) {
1117 if (id == sc->an_rdata.an_tx_ring[i]) {
1118 sc->an_rdata.an_tx_ring[i] = 0;
1123 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1124 } else { /* MPI 350 */
1125 id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
1126 if (!sc->an_rdata.an_tx_empty){
1127 if (status & AN_EV_TX_EXC) {
1131 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1132 if (sc->an_rdata.an_tx_prod ==
1133 sc->an_rdata.an_tx_cons)
1134 sc->an_rdata.an_tx_empty = 1;
1142 * We abuse the stats updater to check the current NIC status. This
1143 * is important because we don't want to allow transmissions until
1144 * the NIC has synchronized to the current cell (either as the master
1145 * in an ad-hoc group, or as a station connected to an access point).
1147 * Note that this function will be called via callout(9) with a lock held.
1150 an_stats_update(void *xsc)
1152 struct an_softc *sc;
1159 sc->an_status.an_type = AN_RID_STATUS;
1160 sc->an_status.an_len = sizeof(struct an_ltv_status);
1161 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_status))
1164 if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
1165 sc->an_associated = 1;
1167 sc->an_associated = 0;
1169 /* Don't do this while we're transmitting */
1170 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
1171 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1175 sc->an_stats.an_len = sizeof(struct an_ltv_stats);
1176 sc->an_stats.an_type = AN_RID_32BITS_CUM;
1177 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len))
1180 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
1188 struct an_softc *sc;
1192 sc = (struct an_softc*)xsc;
1203 /* Disable interrupts. */
1204 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
1206 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1207 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
1209 if (status & AN_EV_MIC) {
1210 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
1213 if (status & AN_EV_LINKSTAT) {
1214 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1215 == AN_LINKSTAT_ASSOCIATED)
1216 sc->an_associated = 1;
1218 sc->an_associated = 0;
1219 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
1222 if (status & AN_EV_RX) {
1224 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
1227 if (sc->mpi350 && status & AN_EV_TX_CPY) {
1228 an_txeof(sc, status);
1229 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_CPY);
1232 if (status & AN_EV_TX) {
1233 an_txeof(sc, status);
1234 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
1237 if (status & AN_EV_TX_EXC) {
1238 an_txeof(sc, status);
1239 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
1242 if (status & AN_EV_ALLOC)
1243 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1245 /* Re-enable interrupts. */
1246 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
1248 if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1258 an_cmd_struct(struct an_softc *sc, struct an_command *cmd,
1259 struct an_reply *reply)
1263 for (i = 0; i != AN_TIMEOUT; i++) {
1264 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1270 if( i == AN_TIMEOUT) {
1275 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1276 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1277 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1278 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1280 for (i = 0; i < AN_TIMEOUT; i++) {
1281 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1286 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1287 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1288 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1289 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1291 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1292 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
1293 AN_EV_CLR_STUCK_BUSY);
1295 /* Ack the command */
1296 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1298 if (i == AN_TIMEOUT)
1305 an_cmd(struct an_softc *sc, int cmd, int val)
1309 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1310 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1311 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1312 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1314 for (i = 0; i < AN_TIMEOUT; i++) {
1315 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1318 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1319 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
1323 for (i = 0; i < AN_TIMEOUT; i++) {
1324 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1325 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1326 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1327 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1328 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1332 /* Ack the command */
1333 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1335 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1336 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1338 if (i == AN_TIMEOUT)
1345 * This reset sequence may look a little strange, but this is the
1346 * most reliable method I've found to really kick the NIC in the
1347 * head and force it to reboot correctly.
1350 an_reset(struct an_softc *sc)
1355 an_cmd(sc, AN_CMD_ENABLE, 0);
1356 an_cmd(sc, AN_CMD_FW_RESTART, 0);
1357 an_cmd(sc, AN_CMD_NOOP2, 0);
1359 if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
1360 printf("an%d: reset failed\n", sc->an_unit);
1362 an_cmd(sc, AN_CMD_DISABLE, 0);
1368 * Read an LTV record from the NIC.
1371 an_read_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1373 struct an_ltv_gen *an_ltv;
1374 struct an_card_rid_desc an_rid_desc;
1375 struct an_command cmd;
1376 struct an_reply reply;
1381 if (ltv->an_len < 4 || ltv->an_type == 0)
1385 /* Tell the NIC to enter record read mode. */
1386 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1387 printf("an%d: RID access failed\n", sc->an_unit);
1391 /* Seek to the record. */
1392 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1393 printf("an%d: seek to record failed\n", sc->an_unit);
1398 * Read the length and record type and make sure they
1399 * match what we expect (this verifies that we have enough
1400 * room to hold all of the returned data).
1401 * Length includes type but not length.
1403 len = CSR_READ_2(sc, AN_DATA1);
1404 if (len > (ltv->an_len - 2)) {
1405 printf("an%d: record length mismatch -- expected %d, "
1406 "got %d for Rid %x\n", sc->an_unit,
1407 ltv->an_len - 2, len, ltv->an_type);
1408 len = ltv->an_len - 2;
1410 ltv->an_len = len + 2;
1413 /* Now read the data. */
1414 len -= 2; /* skip the type */
1416 for (i = len; i > 1; i -= 2)
1417 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1419 ptr2 = (u_int8_t *)ptr;
1420 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1422 } else { /* MPI-350 */
1423 if (!sc->an_rid_buffer.an_dma_vaddr)
1425 an_rid_desc.an_valid = 1;
1426 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1427 an_rid_desc.an_rid = 0;
1428 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1429 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1431 bzero(&cmd, sizeof(cmd));
1432 bzero(&reply, sizeof(reply));
1433 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1434 cmd.an_parm0 = ltv->an_type;
1436 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1437 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1438 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1440 if (an_cmd_struct(sc, &cmd, &reply)
1441 || reply.an_status & AN_CMD_QUAL_MASK) {
1442 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1443 sc->an_unit, ltv->an_type,
1452 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1453 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1454 an_rid_desc.an_len = an_ltv->an_len;
1457 len = an_rid_desc.an_len;
1458 if (len > (ltv->an_len - 2)) {
1459 printf("an%d: record length mismatch -- expected %d, "
1460 "got %d for Rid %x\n", sc->an_unit,
1461 ltv->an_len - 2, len, ltv->an_type);
1462 len = ltv->an_len - 2;
1464 ltv->an_len = len + 2;
1466 bcopy(&an_ltv->an_type,
1472 an_dump_record(sc, ltv, "Read");
1478 * Same as read, except we inject data instead of reading it.
1481 an_write_record(struct an_softc *sc, struct an_ltv_gen *ltv)
1483 struct an_card_rid_desc an_rid_desc;
1484 struct an_command cmd;
1485 struct an_reply reply;
1491 an_dump_record(sc, ltv, "Write");
1494 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1497 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1501 * Length includes type but not length.
1503 len = ltv->an_len - 2;
1504 CSR_WRITE_2(sc, AN_DATA1, len);
1506 len -= 2; /* skip the type */
1508 for (i = len; i > 1; i -= 2)
1509 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1511 ptr2 = (u_int8_t *)ptr;
1512 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1515 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1520 for (i = 0; i != AN_TIMEOUT; i++) {
1521 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
1527 if (i == AN_TIMEOUT) {
1531 an_rid_desc.an_valid = 1;
1532 an_rid_desc.an_len = ltv->an_len - 2;
1533 an_rid_desc.an_rid = ltv->an_type;
1534 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1536 bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
1537 an_rid_desc.an_len);
1539 bzero(&cmd,sizeof(cmd));
1540 bzero(&reply,sizeof(reply));
1541 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1542 cmd.an_parm0 = ltv->an_type;
1544 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1545 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1546 ((u_int32_t *)(void *)&an_rid_desc)[i]);
1550 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1551 printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
1552 sc->an_unit, ltv->an_type,
1562 if (reply.an_status & AN_CMD_QUAL_MASK) {
1563 printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
1564 sc->an_unit, ltv->an_type,
1579 an_dump_record(struct an_softc *sc, struct an_ltv_gen *ltv, char *string)
1587 len = ltv->an_len - 4;
1588 printf("an%d: RID %4x, Length %4d, Mode %s\n",
1589 sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
1591 if (an_dump == 1 || (an_dump == ltv->an_type)) {
1592 printf("an%d:\t", sc->an_unit);
1593 bzero(buf,sizeof(buf));
1595 ptr2 = (u_int8_t *)<v->an_val;
1596 for (i = len; i > 0; i--) {
1597 printf("%02x ", *ptr2);
1604 if (++count == 16) {
1607 printf("an%d:\t", sc->an_unit);
1608 bzero(buf,sizeof(buf));
1611 for (; count != 16; count++) {
1614 printf(" %s\n",buf);
1619 an_seek(struct an_softc *sc, int id, int off, int chan)
1634 printf("an%d: invalid data path: %x\n", sc->an_unit, chan);
1638 CSR_WRITE_2(sc, selreg, id);
1639 CSR_WRITE_2(sc, offreg, off);
1641 for (i = 0; i < AN_TIMEOUT; i++) {
1642 if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
1646 if (i == AN_TIMEOUT)
1653 an_read_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1660 if (an_seek(sc, id, off, AN_BAP1))
1664 ptr = (u_int16_t *)buf;
1665 for (i = len; i > 1; i -= 2)
1666 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1668 ptr2 = (u_int8_t *)ptr;
1669 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1676 an_write_data(struct an_softc *sc, int id, int off, caddr_t buf, int len)
1683 if (an_seek(sc, id, off, AN_BAP0))
1687 ptr = (u_int16_t *)buf;
1688 for (i = len; i > 1; i -= 2)
1689 CSR_WRITE_2(sc, AN_DATA0, *ptr++);
1691 ptr2 = (u_int8_t *)ptr;
1692 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1699 * Allocate a region of memory inside the NIC and zero
1703 an_alloc_nicmem(struct an_softc *sc, int len, int *id)
1707 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1708 printf("an%d: failed to allocate %d bytes on NIC\n",
1713 for (i = 0; i < AN_TIMEOUT; i++) {
1714 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1718 if (i == AN_TIMEOUT)
1721 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1722 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1724 if (an_seek(sc, *id, 0, AN_BAP0))
1727 for (i = 0; i < len / 2; i++)
1728 CSR_WRITE_2(sc, AN_DATA0, 0);
1734 an_setdef(struct an_softc *sc, struct an_req *areq)
1737 struct an_ltv_genconfig *cfg;
1738 struct an_ltv_ssidlist_new *ssid;
1739 struct an_ltv_aplist *ap;
1740 struct an_ltv_gen *sp;
1744 switch (areq->an_type) {
1745 case AN_RID_GENCONFIG:
1746 cfg = (struct an_ltv_genconfig *)areq;
1748 bcopy((char *)&cfg->an_macaddr, IF_LLADDR(sc->an_ifp),
1751 bcopy((char *)cfg, (char *)&sc->an_config,
1752 sizeof(struct an_ltv_genconfig));
1754 case AN_RID_SSIDLIST:
1755 ssid = (struct an_ltv_ssidlist_new *)areq;
1756 bcopy((char *)ssid, (char *)&sc->an_ssidlist,
1757 sizeof(struct an_ltv_ssidlist_new));
1760 ap = (struct an_ltv_aplist *)areq;
1761 bcopy((char *)ap, (char *)&sc->an_aplist,
1762 sizeof(struct an_ltv_aplist));
1764 case AN_RID_TX_SPEED:
1765 sp = (struct an_ltv_gen *)areq;
1766 sc->an_tx_rate = sp->an_val;
1768 /* Read the current configuration */
1769 sc->an_config.an_type = AN_RID_GENCONFIG;
1770 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1771 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
1772 cfg = &sc->an_config;
1774 /* clear other rates and set the only one we want */
1775 bzero(cfg->an_rates, sizeof(cfg->an_rates));
1776 cfg->an_rates[0] = sc->an_tx_rate;
1778 /* Save the new rate */
1779 sc->an_config.an_type = AN_RID_GENCONFIG;
1780 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
1782 case AN_RID_WEP_TEMP:
1783 /* Cache the temp keys */
1785 &sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
1786 sizeof(struct an_ltv_key));
1787 case AN_RID_WEP_PERM:
1788 case AN_RID_LEAPUSERNAME:
1789 case AN_RID_LEAPPASSWORD:
1792 /* Disable the MAC. */
1793 an_cmd(sc, AN_CMD_DISABLE, 0);
1796 an_write_record(sc, (struct an_ltv_gen *)areq);
1798 /* Turn the MAC back on. */
1799 an_cmd(sc, AN_CMD_ENABLE, 0);
1802 case AN_RID_MONITOR_MODE:
1803 cfg = (struct an_ltv_genconfig *)areq;
1805 if (ng_ether_detach_p != NULL)
1806 (*ng_ether_detach_p) (ifp);
1807 sc->an_monitor = cfg->an_len;
1809 if (sc->an_monitor & AN_MONITOR) {
1810 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
1811 bpfattach(ifp, DLT_AIRONET_HEADER,
1812 sizeof(struct ether_header));
1814 bpfattach(ifp, DLT_IEEE802_11,
1815 sizeof(struct ether_header));
1818 bpfattach(ifp, DLT_EN10MB,
1819 sizeof(struct ether_header));
1820 if (ng_ether_attach_p != NULL)
1821 (*ng_ether_attach_p) (ifp);
1825 printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
1830 /* Reinitialize the card. */
1838 * Derived from Linux driver to enable promiscious mode.
1842 an_promisc(struct an_softc *sc, int promisc)
1844 if (sc->an_was_monitor) {
1847 an_init_mpi350_desc(sc);
1849 if (sc->an_monitor || sc->an_was_monitor)
1852 sc->an_was_monitor = sc->an_monitor;
1853 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1859 an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1864 struct an_softc *sc;
1866 struct thread *td = curthread;
1867 struct ieee80211req *ireq;
1868 struct ieee80211_channel ch;
1869 u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
1871 struct an_ltv_genconfig *config;
1872 struct an_ltv_key *key;
1873 struct an_ltv_status *status;
1874 struct an_ltv_ssidlist_new *ssids;
1876 struct aironet_ioctl l_ioctl;
1880 ifr = (struct ifreq *)data;
1881 ireq = (struct ieee80211req *)data;
1883 config = (struct an_ltv_genconfig *)&sc->areq;
1884 key = (struct an_ltv_key *)&sc->areq;
1885 status = (struct an_ltv_status *)&sc->areq;
1886 ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
1895 if (ifp->if_flags & IFF_UP) {
1896 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1897 ifp->if_flags & IFF_PROMISC &&
1898 !(sc->an_if_flags & IFF_PROMISC)) {
1900 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
1901 !(ifp->if_flags & IFF_PROMISC) &&
1902 sc->an_if_flags & IFF_PROMISC) {
1907 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1910 sc->an_if_flags = ifp->if_flags;
1915 error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
1919 /* The Aironet has no multicast filter. */
1924 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1929 if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
1930 error = priv_check(td, PRIV_DRIVER);
1933 sc->an_sigitems = sc->an_nextitem = 0;
1935 } else if (sc->areq.an_type == AN_RID_READ_CACHE) {
1936 char *pt = (char *)&sc->areq.an_val;
1937 bcopy((char *)&sc->an_sigitems, (char *)pt,
1940 sc->areq.an_len = sizeof(int) / 2;
1941 bcopy((char *)&sc->an_sigcache, (char *)pt,
1942 sizeof(struct an_sigcache) * sc->an_sigitems);
1943 sc->areq.an_len += ((sizeof(struct an_sigcache) *
1944 sc->an_sigitems) / 2) + 1;
1947 if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
1952 error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
1956 if ((error = priv_check(td, PRIV_DRIVER)))
1959 error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
1963 an_setdef(sc, &sc->areq);
1965 case SIOCGPRIVATE_0: /* used by Cisco client utility */
1966 if ((error = priv_check(td, PRIV_DRIVER)))
1969 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1973 mode = l_ioctl.command;
1975 if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
1976 error = readrids(ifp, &l_ioctl);
1977 } else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
1978 error = writerids(ifp, &l_ioctl);
1979 } else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
1980 error = flashcard(ifp, &l_ioctl);
1985 /* copy out the updated command info */
1987 error = copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
1991 case SIOCGPRIVATE_1: /* used by Cisco client utility */
1992 if ((error = priv_check(td, PRIV_DRIVER)))
1995 error = copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
1999 l_ioctl.command = 0;
2002 (void) copyout(&error, l_ioctl.data, sizeof(error));
2007 sc->areq.an_len = sizeof(sc->areq);
2008 /* was that a good idea DJA we are doing a short-cut */
2009 switch (ireq->i_type) {
2010 case IEEE80211_IOC_SSID:
2011 if (ireq->i_val == -1) {
2012 sc->areq.an_type = AN_RID_STATUS;
2013 if (an_read_record(sc,
2014 (struct an_ltv_gen *)&sc->areq)) {
2018 len = status->an_ssidlen;
2019 tmpptr = status->an_ssid;
2020 } else if (ireq->i_val >= 0) {
2021 sc->areq.an_type = AN_RID_SSIDLIST;
2022 if (an_read_record(sc,
2023 (struct an_ltv_gen *)&sc->areq)) {
2027 max = (sc->areq.an_len - 4)
2028 / sizeof(struct an_ltv_ssid_entry);
2029 if ( max > MAX_SSIDS ) {
2030 printf("To many SSIDs only using "
2035 if (ireq->i_val > max) {
2039 len = ssids->an_entry[ireq->i_val].an_len;
2040 tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
2046 if (len > IEEE80211_NWID_LEN) {
2051 bzero(tmpstr, IEEE80211_NWID_LEN);
2052 bcopy(tmpptr, tmpstr, len);
2054 error = copyout(tmpstr, ireq->i_data,
2055 IEEE80211_NWID_LEN);
2058 case IEEE80211_IOC_NUMSSIDS:
2059 sc->areq.an_len = sizeof(sc->areq);
2060 sc->areq.an_type = AN_RID_SSIDLIST;
2061 if (an_read_record(sc,
2062 (struct an_ltv_gen *)&sc->areq)) {
2066 max = (sc->areq.an_len - 4)
2067 / sizeof(struct an_ltv_ssid_entry);
2068 if ( max > MAX_SSIDS ) {
2069 printf("To many SSIDs only using "
2076 case IEEE80211_IOC_WEP:
2077 sc->areq.an_type = AN_RID_ACTUALCFG;
2078 if (an_read_record(sc,
2079 (struct an_ltv_gen *)&sc->areq)) {
2083 if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
2084 if (config->an_authtype &
2085 AN_AUTHTYPE_ALLOW_UNENCRYPTED)
2086 ireq->i_val = IEEE80211_WEP_MIXED;
2088 ireq->i_val = IEEE80211_WEP_ON;
2090 ireq->i_val = IEEE80211_WEP_OFF;
2093 case IEEE80211_IOC_WEPKEY:
2095 * XXX: I'm not entierly convinced this is
2096 * correct, but it's what is implemented in
2097 * ancontrol so it will have to do until we get
2098 * access to actual Cisco code.
2100 if (ireq->i_val < 0 || ireq->i_val > 8) {
2105 if (ireq->i_val < 5) {
2106 sc->areq.an_type = AN_RID_WEP_TEMP;
2107 for (i = 0; i < 5; i++) {
2108 if (an_read_record(sc,
2109 (struct an_ltv_gen *)&sc->areq)) {
2113 if (key->kindex == 0xffff)
2115 if (key->kindex == ireq->i_val)
2117 /* Required to get next entry */
2118 sc->areq.an_type = AN_RID_WEP_PERM;
2123 /* We aren't allowed to read the value of the
2124 * key from the card so we just output zeros
2125 * like we would if we could read the card, but
2126 * denied the user access.
2131 error = copyout(tmpstr, ireq->i_data, len);
2134 case IEEE80211_IOC_NUMWEPKEYS:
2135 ireq->i_val = 9; /* include home key */
2137 case IEEE80211_IOC_WEPTXKEY:
2139 * For some strange reason, you have to read all
2140 * keys before you can read the txkey.
2142 sc->areq.an_type = AN_RID_WEP_TEMP;
2143 for (i = 0; i < 5; i++) {
2144 if (an_read_record(sc,
2145 (struct an_ltv_gen *) &sc->areq)) {
2149 if (key->kindex == 0xffff)
2151 /* Required to get next entry */
2152 sc->areq.an_type = AN_RID_WEP_PERM;
2157 sc->areq.an_type = AN_RID_WEP_PERM;
2158 key->kindex = 0xffff;
2159 if (an_read_record(sc,
2160 (struct an_ltv_gen *)&sc->areq)) {
2164 ireq->i_val = key->mac[0];
2166 * Check for home mode. Map home mode into
2167 * 5th key since that is how it is stored on
2170 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2171 sc->areq.an_type = AN_RID_GENCONFIG;
2172 if (an_read_record(sc,
2173 (struct an_ltv_gen *)&sc->areq)) {
2177 if (config->an_home_product & AN_HOME_NETWORK)
2180 case IEEE80211_IOC_AUTHMODE:
2181 sc->areq.an_type = AN_RID_ACTUALCFG;
2182 if (an_read_record(sc,
2183 (struct an_ltv_gen *)&sc->areq)) {
2187 if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2189 ireq->i_val = IEEE80211_AUTH_NONE;
2190 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2192 ireq->i_val = IEEE80211_AUTH_OPEN;
2193 } else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
2194 AN_AUTHTYPE_SHAREDKEY) {
2195 ireq->i_val = IEEE80211_AUTH_SHARED;
2199 case IEEE80211_IOC_STATIONNAME:
2200 sc->areq.an_type = AN_RID_ACTUALCFG;
2201 if (an_read_record(sc,
2202 (struct an_ltv_gen *)&sc->areq)) {
2206 ireq->i_len = sizeof(config->an_nodename);
2207 tmpptr = config->an_nodename;
2208 bzero(tmpstr, IEEE80211_NWID_LEN);
2209 bcopy(tmpptr, tmpstr, ireq->i_len);
2211 error = copyout(tmpstr, ireq->i_data,
2212 IEEE80211_NWID_LEN);
2215 case IEEE80211_IOC_CHANNEL:
2216 sc->areq.an_type = AN_RID_STATUS;
2217 if (an_read_record(sc,
2218 (struct an_ltv_gen *)&sc->areq)) {
2222 ireq->i_val = status->an_cur_channel;
2224 case IEEE80211_IOC_CURCHAN:
2225 sc->areq.an_type = AN_RID_STATUS;
2226 if (an_read_record(sc,
2227 (struct an_ltv_gen *)&sc->areq)) {
2231 bzero(&ch, sizeof(ch));
2232 ch.ic_freq = ieee80211_ieee2mhz(status->an_cur_channel,
2234 ch.ic_flags = IEEE80211_CHAN_B;
2235 ch.ic_ieee = status->an_cur_channel;
2237 error = copyout(&ch, ireq->i_data, sizeof(ch));
2240 case IEEE80211_IOC_POWERSAVE:
2241 sc->areq.an_type = AN_RID_ACTUALCFG;
2242 if (an_read_record(sc,
2243 (struct an_ltv_gen *)&sc->areq)) {
2247 if (config->an_psave_mode == AN_PSAVE_NONE) {
2248 ireq->i_val = IEEE80211_POWERSAVE_OFF;
2249 } else if (config->an_psave_mode == AN_PSAVE_CAM) {
2250 ireq->i_val = IEEE80211_POWERSAVE_CAM;
2251 } else if (config->an_psave_mode == AN_PSAVE_PSP) {
2252 ireq->i_val = IEEE80211_POWERSAVE_PSP;
2253 } else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
2254 ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
2258 case IEEE80211_IOC_POWERSAVESLEEP:
2259 sc->areq.an_type = AN_RID_ACTUALCFG;
2260 if (an_read_record(sc,
2261 (struct an_ltv_gen *)&sc->areq)) {
2265 ireq->i_val = config->an_listen_interval;
2270 if ((error = priv_check(td, PRIV_NET80211_MANAGE)))
2272 sc->areq.an_len = sizeof(sc->areq);
2274 * We need a config structure for everything but the WEP
2275 * key management and SSIDs so we get it now so avoid
2276 * duplicating this code every time.
2278 if (ireq->i_type != IEEE80211_IOC_SSID &&
2279 ireq->i_type != IEEE80211_IOC_WEPKEY &&
2280 ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
2281 sc->areq.an_type = AN_RID_GENCONFIG;
2282 if (an_read_record(sc,
2283 (struct an_ltv_gen *)&sc->areq)) {
2288 switch (ireq->i_type) {
2289 case IEEE80211_IOC_SSID:
2290 sc->areq.an_len = sizeof(sc->areq);
2291 sc->areq.an_type = AN_RID_SSIDLIST;
2292 if (an_read_record(sc,
2293 (struct an_ltv_gen *)&sc->areq)) {
2297 if (ireq->i_len > IEEE80211_NWID_LEN) {
2301 max = (sc->areq.an_len - 4)
2302 / sizeof(struct an_ltv_ssid_entry);
2303 if ( max > MAX_SSIDS ) {
2304 printf("To many SSIDs only using "
2309 if (ireq->i_val > max) {
2314 error = copyin(ireq->i_data,
2315 ssids->an_entry[ireq->i_val].an_ssid,
2318 ssids->an_entry[ireq->i_val].an_len
2323 case IEEE80211_IOC_WEP:
2324 switch (ireq->i_val) {
2325 case IEEE80211_WEP_OFF:
2326 config->an_authtype &=
2327 ~(AN_AUTHTYPE_PRIVACY_IN_USE |
2328 AN_AUTHTYPE_ALLOW_UNENCRYPTED);
2330 case IEEE80211_WEP_ON:
2331 config->an_authtype |=
2332 AN_AUTHTYPE_PRIVACY_IN_USE;
2333 config->an_authtype &=
2334 ~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2336 case IEEE80211_WEP_MIXED:
2337 config->an_authtype |=
2338 AN_AUTHTYPE_PRIVACY_IN_USE |
2339 AN_AUTHTYPE_ALLOW_UNENCRYPTED;
2346 case IEEE80211_IOC_WEPKEY:
2347 if (ireq->i_val < 0 || ireq->i_val > 8 ||
2353 error = copyin(ireq->i_data, tmpstr, 13);
2358 * Map the 9th key into the home mode
2359 * since that is how it is stored on
2362 bzero(&sc->areq, sizeof(struct an_ltv_key));
2363 sc->areq.an_len = sizeof(struct an_ltv_key);
2364 key->mac[0] = 1; /* The others are 0. */
2365 if (ireq->i_val < 4) {
2366 sc->areq.an_type = AN_RID_WEP_TEMP;
2367 key->kindex = ireq->i_val;
2369 sc->areq.an_type = AN_RID_WEP_PERM;
2370 key->kindex = ireq->i_val - 4;
2372 key->klen = ireq->i_len;
2373 bcopy(tmpstr, key->key, key->klen);
2375 case IEEE80211_IOC_WEPTXKEY:
2376 if (ireq->i_val < 0 || ireq->i_val > 4) {
2382 * Map the 5th key into the home mode
2383 * since that is how it is stored on
2386 sc->areq.an_len = sizeof(struct an_ltv_genconfig);
2387 sc->areq.an_type = AN_RID_ACTUALCFG;
2388 if (an_read_record(sc,
2389 (struct an_ltv_gen *)&sc->areq)) {
2393 if (ireq->i_val == 4) {
2394 config->an_home_product |= AN_HOME_NETWORK;
2397 config->an_home_product &= ~AN_HOME_NETWORK;
2400 sc->an_config.an_home_product
2401 = config->an_home_product;
2403 /* update configuration */
2406 bzero(&sc->areq, sizeof(struct an_ltv_key));
2407 sc->areq.an_len = sizeof(struct an_ltv_key);
2408 sc->areq.an_type = AN_RID_WEP_PERM;
2409 key->kindex = 0xffff;
2410 key->mac[0] = ireq->i_val;
2412 case IEEE80211_IOC_AUTHMODE:
2413 switch (ireq->i_val) {
2414 case IEEE80211_AUTH_NONE:
2415 config->an_authtype = AN_AUTHTYPE_NONE |
2416 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2418 case IEEE80211_AUTH_OPEN:
2419 config->an_authtype = AN_AUTHTYPE_OPEN |
2420 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2422 case IEEE80211_AUTH_SHARED:
2423 config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
2424 (config->an_authtype & ~AN_AUTHTYPE_MASK);
2430 case IEEE80211_IOC_STATIONNAME:
2431 if (ireq->i_len > 16) {
2435 bzero(config->an_nodename, 16);
2437 error = copyin(ireq->i_data,
2438 config->an_nodename, ireq->i_len);
2441 case IEEE80211_IOC_CHANNEL:
2443 * The actual range is 1-14, but if you set it
2444 * to 0 you get the default so we let that work
2447 if (ireq->i_val < 0 || ireq->i_val >14) {
2451 config->an_ds_channel = ireq->i_val;
2453 case IEEE80211_IOC_POWERSAVE:
2454 switch (ireq->i_val) {
2455 case IEEE80211_POWERSAVE_OFF:
2456 config->an_psave_mode = AN_PSAVE_NONE;
2458 case IEEE80211_POWERSAVE_CAM:
2459 config->an_psave_mode = AN_PSAVE_CAM;
2461 case IEEE80211_POWERSAVE_PSP:
2462 config->an_psave_mode = AN_PSAVE_PSP;
2464 case IEEE80211_POWERSAVE_PSP_CAM:
2465 config->an_psave_mode = AN_PSAVE_PSP_CAM;
2472 case IEEE80211_IOC_POWERSAVESLEEP:
2473 config->an_listen_interval = ireq->i_val;
2478 an_setdef(sc, &sc->areq);
2482 error = ether_ioctl(ifp, command, data);
2493 an_init_tx_ring(struct an_softc *sc)
2502 for (i = 0; i < AN_TX_RING_CNT; i++) {
2503 if (an_alloc_nicmem(sc, 1518 +
2506 sc->an_rdata.an_tx_fids[i] = id;
2507 sc->an_rdata.an_tx_ring[i] = 0;
2511 sc->an_rdata.an_tx_prod = 0;
2512 sc->an_rdata.an_tx_cons = 0;
2513 sc->an_rdata.an_tx_empty = 1;
2521 struct an_softc *sc = xsc;
2522 struct ifnet *ifp = sc->an_ifp;
2531 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2534 sc->an_associated = 0;
2536 /* Allocate the TX buffers */
2537 if (an_init_tx_ring(sc)) {
2540 an_init_mpi350_desc(sc);
2541 if (an_init_tx_ring(sc)) {
2542 printf("an%d: tx buffer allocation "
2543 "failed\n", sc->an_unit);
2549 /* Set our MAC address. */
2550 bcopy((char *)IF_LLADDR(sc->an_ifp),
2551 (char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
2553 if (ifp->if_flags & IFF_BROADCAST)
2554 sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
2556 sc->an_config.an_rxmode = AN_RXMODE_ADDR;
2558 if (ifp->if_flags & IFF_MULTICAST)
2559 sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
2561 if (ifp->if_flags & IFF_PROMISC) {
2562 if (sc->an_monitor & AN_MONITOR) {
2563 if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
2564 sc->an_config.an_rxmode |=
2565 AN_RXMODE_80211_MONITOR_ANYBSS |
2566 AN_RXMODE_NO_8023_HEADER;
2568 sc->an_config.an_rxmode |=
2569 AN_RXMODE_80211_MONITOR_CURBSS |
2570 AN_RXMODE_NO_8023_HEADER;
2575 if (sc->an_have_rssimap)
2576 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2578 /* Set the ssid list */
2579 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2580 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
2581 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2582 printf("an%d: failed to set ssid list\n", sc->an_unit);
2587 /* Set the AP list */
2588 sc->an_aplist.an_type = AN_RID_APLIST;
2589 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
2590 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
2591 printf("an%d: failed to set AP list\n", sc->an_unit);
2596 /* Set the configuration in the NIC */
2597 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
2598 sc->an_config.an_type = AN_RID_GENCONFIG;
2599 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
2600 printf("an%d: failed to set configuration\n", sc->an_unit);
2605 /* Enable the MAC */
2606 if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
2607 printf("an%d: failed to enable MAC\n", sc->an_unit);
2612 if (ifp->if_flags & IFF_PROMISC)
2613 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2615 /* enable interrupts */
2616 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2618 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2619 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2621 callout_reset(&sc->an_stat_ch, hz, an_stats_update, sc);
2628 an_start(struct ifnet *ifp)
2630 struct an_softc *sc;
2631 struct mbuf *m0 = NULL;
2632 struct an_txframe_802_3 tx_frame_802_3;
2633 struct ether_header *eh;
2635 unsigned char txcontrol;
2636 struct an_card_tx_desc an_tx_desc;
2644 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
2647 if (!sc->an_associated)
2650 /* We can't send in monitor mode so toss any attempts. */
2651 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
2653 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2661 idx = sc->an_rdata.an_tx_prod;
2664 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
2666 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2667 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2671 id = sc->an_rdata.an_tx_fids[idx];
2672 eh = mtod(m0, struct ether_header *);
2674 bcopy((char *)&eh->ether_dhost,
2675 (char *)&tx_frame_802_3.an_tx_dst_addr,
2677 bcopy((char *)&eh->ether_shost,
2678 (char *)&tx_frame_802_3.an_tx_src_addr,
2681 /* minus src/dest mac & type */
2682 tx_frame_802_3.an_tx_802_3_payload_len =
2683 m0->m_pkthdr.len - 12;
2685 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2686 tx_frame_802_3.an_tx_802_3_payload_len,
2687 (caddr_t)&sc->an_txbuf);
2689 txcontrol = AN_TXCTL_8023;
2690 /* write the txcontrol only */
2691 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2695 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2696 sizeof(struct an_txframe_802_3));
2698 /* in mbuf header type is just before payload */
2699 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2700 tx_frame_802_3.an_tx_802_3_payload_len);
2703 * If there's a BPF listner, bounce a copy of
2704 * this frame to him.
2711 sc->an_rdata.an_tx_ring[idx] = id;
2712 if (an_cmd(sc, AN_CMD_TX, id))
2713 printf("an%d: xmit failed\n", sc->an_unit);
2715 AN_INC(idx, AN_TX_RING_CNT);
2718 * Set a timeout in case the chip goes out to lunch.
2722 } else { /* MPI-350 */
2723 /* Disable interrupts. */
2724 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2726 while (sc->an_rdata.an_tx_empty ||
2727 idx != sc->an_rdata.an_tx_cons) {
2728 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
2732 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2734 eh = mtod(m0, struct ether_header *);
2736 /* DJA optimize this to limit bcopy */
2737 bcopy((char *)&eh->ether_dhost,
2738 (char *)&tx_frame_802_3.an_tx_dst_addr,
2740 bcopy((char *)&eh->ether_shost,
2741 (char *)&tx_frame_802_3.an_tx_src_addr,
2744 /* minus src/dest mac & type */
2745 tx_frame_802_3.an_tx_802_3_payload_len =
2746 m0->m_pkthdr.len - 12;
2748 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2749 tx_frame_802_3.an_tx_802_3_payload_len,
2750 (caddr_t)&sc->an_txbuf);
2752 txcontrol = AN_TXCTL_8023;
2753 /* write the txcontrol only */
2754 bcopy((caddr_t)&txcontrol, &buf[0x08],
2758 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2759 sizeof(struct an_txframe_802_3));
2761 /* in mbuf header type is just before payload */
2762 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2763 tx_frame_802_3.an_tx_802_3_payload_len);
2766 bzero(&an_tx_desc, sizeof(an_tx_desc));
2767 an_tx_desc.an_offset = 0;
2768 an_tx_desc.an_eoc = 1;
2769 an_tx_desc.an_valid = 1;
2770 an_tx_desc.an_len = 0x44 +
2771 tx_frame_802_3.an_tx_802_3_payload_len;
2773 = sc->an_tx_buffer[idx].an_dma_paddr;
2774 for (i = 0; i < sizeof(an_tx_desc) / 4 ; i++) {
2775 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
2777 + (0 * sizeof(an_tx_desc))
2779 ((u_int32_t *)(void *)&an_tx_desc)[i]);
2783 * If there's a BPF listner, bounce a copy of
2784 * this frame to him.
2790 AN_INC(idx, AN_MAX_TX_DESC);
2791 sc->an_rdata.an_tx_empty = 0;
2792 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2795 * Set a timeout in case the chip goes out to lunch.
2800 /* Re-enable interrupts. */
2801 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
2805 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2807 sc->an_rdata.an_tx_prod = idx;
2813 an_stop(struct an_softc *sc)
2827 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2828 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2829 an_cmd(sc, AN_CMD_DISABLE, 0);
2831 for (i = 0; i < AN_TX_RING_CNT; i++)
2832 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2834 callout_stop(&sc->an_stat_ch);
2836 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING|IFF_DRV_OACTIVE);
2838 if (sc->an_flash_buffer) {
2839 free(sc->an_flash_buffer, M_DEVBUF);
2840 sc->an_flash_buffer = NULL;
2849 an_watchdog(struct ifnet *ifp)
2851 struct an_softc *sc;
2861 printf("an%d: device timeout\n", sc->an_unit);
2865 an_init_mpi350_desc(sc);
2875 an_shutdown(device_t dev)
2877 struct an_softc *sc;
2879 sc = device_get_softc(dev);
2887 an_resume(device_t dev)
2889 struct an_softc *sc;
2893 sc = device_get_softc(dev);
2900 an_init_mpi350_desc(sc);
2903 /* Recovery temporary keys */
2904 for (i = 0; i < 4; i++) {
2905 sc->areq.an_type = AN_RID_WEP_TEMP;
2906 sc->areq.an_len = sizeof(struct an_ltv_key);
2907 bcopy(&sc->an_temp_keys[i],
2908 &sc->areq, sizeof(struct an_ltv_key));
2909 an_setdef(sc, &sc->areq);
2912 if (ifp->if_flags & IFF_UP)
2920 /* Aironet signal strength cache code.
2921 * store signal/noise/quality on per MAC src basis in
2922 * a small fixed cache. The cache wraps if > MAX slots
2923 * used. The cache may be zeroed out to start over.
2924 * Two simple filters exist to reduce computation:
2925 * 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
2926 * to ignore some packets. It defaults to ip only.
2927 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2928 * 2. multicast/broadcast only. This may be used to
2929 * ignore unicast packets and only cache signal strength
2930 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2931 * beacons and not unicast traffic.
2933 * The cache stores (MAC src(index), IP src (major clue), signal,
2936 * No apologies for storing IP src here. It's easy and saves much
2937 * trouble elsewhere. The cache is assumed to be INET dependent,
2938 * although it need not be.
2940 * Note: the Aironet only has a single byte of signal strength value
2941 * in the rx frame header, and it's not scaled to anything sensible.
2942 * This is kind of lame, but it's all we've got.
2945 #ifdef documentation
2947 int an_sigitems; /* number of cached entries */
2948 struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
2949 int an_nextitem; /* index/# of entries */
2954 /* control variables for cache filtering. Basic idea is
2955 * to reduce cost (e.g., to only Mobile-IP agent beacons
2956 * which are broadcast or multicast). Still you might
2957 * want to measure signal strength anth unicast ping packets
2958 * on a pt. to pt. ant. setup.
2960 /* set true if you want to limit cache items to broadcast/mcast
2961 * only packets (not unicast). Useful for mobile-ip beacons which
2962 * are broadcast/multicast at network layer. Default is all packets
2963 * so ping/unicast anll work say anth pt. to pt. antennae setup.
2965 static int an_cache_mcastonly = 0;
2966 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
2967 &an_cache_mcastonly, 0, "");
2969 /* set true if you want to limit cache items to IP packets only
2971 static int an_cache_iponly = 1;
2972 SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2973 &an_cache_iponly, 0, "");
2976 * an_cache_store, per rx packet store signal
2977 * strength in MAC (src) indexed cache.
2980 an_cache_store(struct an_softc *sc, struct ether_header *eh, struct mbuf *m,
2981 u_int8_t rx_rssi, u_int8_t rx_quality)
2985 static int cache_slot = 0; /* use this cache entry */
2986 static int wrapindex = 0; /* next "free" cache entry */
2991 * 2. configurable filter to throw out unicast packets,
2992 * keep multicast only.
2995 if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
2999 /* filter for ip packets only
3001 if ( an_cache_iponly && !type_ipv4) {
3005 /* filter for broadcast/multicast only
3007 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
3012 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
3013 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
3016 /* find the ip header. we want to store the ip_src
3020 ip = mtod(m, struct ip *);
3023 /* do a linear search for a matching MAC address
3024 * in the cache table
3025 * . MAC address is 6 bytes,
3026 * . var w_nextitem holds total number of entries already cached
3028 for (i = 0; i < sc->an_nextitem; i++) {
3029 if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
3031 * so we already have this entry,
3038 /* did we find a matching mac address?
3039 * if yes, then overwrite a previously existing cache entry
3041 if (i < sc->an_nextitem ) {
3044 /* else, have a new address entry,so
3045 * add this new entry,
3046 * if table full, then we need to replace LRU entry
3050 /* check for space in cache table
3051 * note: an_nextitem also holds number of entries
3052 * added in the cache table
3054 if ( sc->an_nextitem < MAXANCACHE ) {
3055 cache_slot = sc->an_nextitem;
3057 sc->an_sigitems = sc->an_nextitem;
3059 /* no space found, so simply wrap anth wrap index
3060 * and "zap" the next entry
3063 if (wrapindex == MAXANCACHE) {
3066 cache_slot = wrapindex++;
3070 /* invariant: cache_slot now points at some slot
3073 if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
3074 log(LOG_ERR, "an_cache_store, bad index: %d of "
3075 "[0..%d], gross cache error\n",
3076 cache_slot, MAXANCACHE);
3080 /* store items in cache
3081 * .ip source address
3086 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
3088 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
3091 switch (an_cache_mode) {
3093 if (sc->an_have_rssimap) {
3094 sc->an_sigcache[cache_slot].signal =
3095 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3096 sc->an_sigcache[cache_slot].quality =
3097 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3099 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3100 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3104 if (sc->an_have_rssimap) {
3105 sc->an_sigcache[cache_slot].signal =
3106 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3107 sc->an_sigcache[cache_slot].quality =
3108 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3112 if (rx_quality > 100)
3114 sc->an_sigcache[cache_slot].signal = rx_rssi;
3115 sc->an_sigcache[cache_slot].quality = rx_quality;
3119 sc->an_sigcache[cache_slot].signal = rx_rssi;
3120 sc->an_sigcache[cache_slot].quality = rx_quality;
3124 sc->an_sigcache[cache_slot].noise = 0;
3131 an_media_change(struct ifnet *ifp)
3133 struct an_softc *sc = ifp->if_softc;
3134 struct an_ltv_genconfig *cfg;
3135 int otype = sc->an_config.an_opmode;
3136 int orate = sc->an_tx_rate;
3138 sc->an_tx_rate = ieee80211_media2rate(
3139 IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
3140 if (sc->an_tx_rate < 0)
3143 if (orate != sc->an_tx_rate) {
3144 /* Read the current configuration */
3145 sc->an_config.an_type = AN_RID_GENCONFIG;
3146 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3147 an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
3148 cfg = &sc->an_config;
3150 /* clear other rates and set the only one we want */
3151 bzero(cfg->an_rates, sizeof(cfg->an_rates));
3152 cfg->an_rates[0] = sc->an_tx_rate;
3154 /* Save the new rate */
3155 sc->an_config.an_type = AN_RID_GENCONFIG;
3156 sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
3159 if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
3160 sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
3162 sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
3164 if (otype != sc->an_config.an_opmode ||
3165 orate != sc->an_tx_rate)
3172 an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
3174 struct an_ltv_status status;
3175 struct an_softc *sc = ifp->if_softc;
3177 imr->ifm_active = IFM_IEEE80211;
3179 status.an_len = sizeof(status);
3180 status.an_type = AN_RID_STATUS;
3181 if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
3182 /* If the status read fails, just lie. */
3183 imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
3184 imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
3187 if (sc->an_tx_rate == 0) {
3188 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
3191 if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
3192 imr->ifm_active |= IFM_IEEE80211_ADHOC;
3193 imr->ifm_active |= ieee80211_rate2media(NULL,
3194 status.an_current_tx_rate, IEEE80211_T_DS);
3195 imr->ifm_status = IFM_AVALID;
3196 if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
3197 imr->ifm_status |= IFM_ACTIVE;
3200 /********************** Cisco utility support routines *************/
3203 * ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
3208 readrids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3211 struct an_softc *sc;
3214 switch (l_ioctl->command) {
3216 rid = AN_RID_CAPABILITIES;
3219 rid = AN_RID_GENCONFIG;
3222 rid = AN_RID_SSIDLIST;
3225 rid = AN_RID_APLIST;
3228 rid = AN_RID_DRVNAME;
3231 rid = AN_RID_ENCAPPROTO;
3234 rid = AN_RID_WEP_TEMP;
3237 rid = AN_RID_WEP_PERM;
3240 rid = AN_RID_STATUS;
3243 rid = AN_RID_32BITS_DELTA;
3246 rid = AN_RID_32BITS_CUM;
3253 if (rid == 999) /* Is bad command */
3257 sc->areq.an_len = AN_MAX_DATALEN;
3258 sc->areq.an_type = rid;
3260 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3262 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3265 /* the data contains the length at first */
3266 if (copyout(&(sc->areq.an_len), l_ioctl->data,
3267 sizeof(sc->areq.an_len))) {
3271 /* Just copy the data back */
3272 if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3284 writerids(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3286 struct an_softc *sc;
3287 int rid, command, error;
3291 command = l_ioctl->command;
3295 rid = AN_RID_SSIDLIST;
3298 rid = AN_RID_CAPABILITIES;
3301 rid = AN_RID_APLIST;
3304 rid = AN_RID_GENCONFIG;
3307 an_cmd(sc, AN_CMD_ENABLE, 0);
3311 an_cmd(sc, AN_CMD_DISABLE, 0);
3316 * This command merely clears the counts does not actually
3317 * store any data only reads rid. But as it changes the cards
3318 * state, I put it in the writerid routines.
3321 rid = AN_RID_32BITS_DELTACLR;
3323 sc->areq.an_len = AN_MAX_DATALEN;
3324 sc->areq.an_type = rid;
3326 an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
3327 l_ioctl->len = sc->areq.an_len - 4; /* just data */
3330 /* the data contains the length at first */
3331 error = copyout(&(sc->areq.an_len), l_ioctl->data,
3332 sizeof(sc->areq.an_len));
3337 /* Just copy the data */
3338 error = copyout(&(sc->areq.an_val), l_ioctl->data + 2,
3346 rid = AN_RID_WEP_TEMP;
3349 rid = AN_RID_WEP_PERM;
3352 rid = AN_RID_LEAPUSERNAME;
3355 rid = AN_RID_LEAPPASSWORD;
3362 if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
3364 sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
3365 sc->areq.an_type = rid;
3367 /* Just copy the data back */
3369 error = copyin((l_ioctl->data) + 2, &sc->areq.an_val,
3375 an_cmd(sc, AN_CMD_DISABLE, 0);
3376 an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
3377 an_cmd(sc, AN_CMD_ENABLE, 0);
3384 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3388 #define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
3389 "flash", ((x) / hz) + 1);
3390 #define FLASH_COMMAND 0x7e7e
3391 #define FLASH_SIZE 32 * 1024
3394 unstickbusy(struct ifnet *ifp)
3396 struct an_softc *sc = ifp->if_softc;
3398 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3399 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3400 AN_EV_CLR_STUCK_BUSY);
3407 * Wait for busy completion from card wait for delay uSec's Return true for
3408 * success meaning command reg is clear
3412 WaitBusy(struct ifnet *ifp, int uSec)
3414 int statword = 0xffff;
3416 struct an_softc *sc = ifp->if_softc;
3418 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3419 FLASH_DELAY(sc, 10);
3421 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
3423 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3428 return 0 == (AN_CMD_BUSY & statword);
3432 * STEP 1) Disable MAC and do soft reset on card.
3436 cmdreset(struct ifnet *ifp)
3439 struct an_softc *sc = ifp->if_softc;
3443 an_cmd(sc, AN_CMD_DISABLE, 0);
3445 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3446 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3447 sc->an_unit, status);
3450 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
3452 FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
3455 if (!(status = WaitBusy(ifp, 100))) {
3456 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3457 sc->an_unit, status);
3464 * STEP 2) Put the card in legendary flash mode
3468 setflashmode(struct ifnet *ifp)
3471 struct an_softc *sc = ifp->if_softc;
3473 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3474 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3475 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3476 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
3479 * mdelay(500); // 500ms delay
3482 FLASH_DELAY(sc, 500);
3484 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
3485 printf("Waitbusy hang after setflash mode\n");
3492 * Get a character from the card matching matchbyte Step 3)
3496 flashgchar(struct ifnet *ifp, int matchbyte, int dwelltime)
3499 unsigned char rbyte = 0;
3501 struct an_softc *sc = ifp->if_softc;
3505 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3507 if (dwelltime && !(0x8000 & rchar)) {
3509 FLASH_DELAY(sc, 10);
3512 rbyte = 0xff & rchar;
3514 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3515 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3519 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3521 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3523 } while (dwelltime > 0);
3528 * Put character to SWS0 wait for dwelltime x 50us for echo .
3532 flashpchar(struct ifnet *ifp, int byte, int dwelltime)
3535 int pollbusy, waittime;
3536 struct an_softc *sc = ifp->if_softc;
3543 waittime = dwelltime;
3546 * Wait for busy bit d15 to go false indicating buffer empty
3549 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
3551 if (pollbusy & 0x8000) {
3552 FLASH_DELAY(sc, 50);
3558 while (waittime >= 0);
3560 /* timeout for busy clear wait */
3562 if (waittime <= 0) {
3563 printf("an%d: flash putchar busywait timeout! \n",
3568 * Port is clear now write byte and wait for it to echo back
3571 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
3572 FLASH_DELAY(sc, 50);
3574 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
3575 } while (dwelltime >= 0 && echo != byte);
3578 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
3580 return echo == byte;
3584 * Transfer 32k of firmware data from user buffer to our buffer and send to
3589 flashputbuf(struct ifnet *ifp)
3591 unsigned short *bufp;
3593 struct an_softc *sc = ifp->if_softc;
3597 bufp = sc->an_flash_buffer;
3600 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3601 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3603 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3604 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3607 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3608 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3609 ((u_int32_t *)bufp)[nwords] & 0xffff);
3613 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
3619 * After flashing restart the card.
3623 flashrestart(struct ifnet *ifp)
3626 struct an_softc *sc = ifp->if_softc;
3628 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3632 FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
3637 * Entry point for flash ioclt.
3641 flashcard(struct ifnet *ifp, struct aironet_ioctl *l_ioctl)
3644 struct an_softc *sc;
3648 printf("an%d: flashing not supported on MPI 350 yet\n",
3652 status = l_ioctl->command;
3654 switch (l_ioctl->command) {
3656 return cmdreset(ifp);
3659 if (sc->an_flash_buffer) {
3660 free(sc->an_flash_buffer, M_DEVBUF);
3661 sc->an_flash_buffer = NULL;
3663 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3664 if (sc->an_flash_buffer)
3665 return setflashmode(ifp);
3669 case AIROFLSHGCHR: /* Get char from aux */
3671 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3675 z = *(int *)&sc->areq;
3676 if ((status = flashgchar(ifp, z, 8000)) == 1)
3680 case AIROFLSHPCHR: /* Send char to card. */
3682 status = copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3686 z = *(int *)&sc->areq;
3687 if ((status = flashpchar(ifp, z, 8000)) == -1)
3692 case AIROFLPUTBUF: /* Send 32k to card */
3693 if (l_ioctl->len > FLASH_SIZE) {
3694 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3695 l_ioctl->len, FLASH_SIZE);
3699 status = copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
3704 if ((status = flashputbuf(ifp)) != 0)
3710 if ((status = flashrestart(ifp)) != 0) {
3711 printf("an%d: FLASHRESTART returned %d\n",
3712 sc->an_unit, status);