2000-01-14 20:41:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997, 1998, 1999
|
|
|
|
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
|
|
|
|
*
|
|
|
|
* Written by Bill Paul <wpaul@ctr.columbia.edu>
|
|
|
|
* Electrical Engineering Department
|
|
|
|
* Columbia University, New York City
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
/*
|
2001-11-11 11:20:09 +00:00
|
|
|
* The Aironet 4500/4800 series cards come in PCMCIA, ISA and PCI form.
|
2000-01-14 20:41:03 +00:00
|
|
|
* This driver supports all three device types (PCI devices are supported
|
2002-07-27 21:28:40 +00:00
|
|
|
* through an extra PCI shim: /sys/dev/an/if_an_pci.c). ISA devices can be
|
2000-01-14 20:41:03 +00:00
|
|
|
* supported either using hard-coded IO port/IRQ settings or via Plug
|
|
|
|
* and Play. The 4500 series devices support 1Mbps and 2Mbps data rates.
|
|
|
|
* The 4800 devices support 1, 2, 5.5 and 11Mbps rates.
|
|
|
|
*
|
|
|
|
* Like the WaveLAN/IEEE cards, the Aironet NICs are all essentially
|
|
|
|
* PCMCIA devices. The ISA and PCI cards are a combination of a PCMCIA
|
|
|
|
* device and a PCMCIA to ISA or PCMCIA to PCI adapter card. There are
|
|
|
|
* a couple of important differences though:
|
|
|
|
*
|
|
|
|
* - Lucent ISA card looks to the host like a PCMCIA controller with
|
|
|
|
* a PCMCIA WaveLAN card inserted. This means that even desktop
|
|
|
|
* machines need to be configured with PCMCIA support in order to
|
|
|
|
* use WaveLAN/IEEE ISA cards. The Aironet cards on the other hand
|
|
|
|
* actually look like normal ISA and PCI devices to the host, so
|
|
|
|
* no PCMCIA controller support is needed
|
|
|
|
*
|
|
|
|
* The latter point results in a small gotcha. The Aironet PCMCIA
|
|
|
|
* cards can be configured for one of two operating modes depending
|
|
|
|
* on how the Vpp1 and Vpp2 programming voltages are set when the
|
|
|
|
* card is activated. In order to put the card in proper PCMCIA
|
|
|
|
* operation (where the CIS table is visible and the interface is
|
|
|
|
* programmed for PCMCIA operation), both Vpp1 and Vpp2 have to be
|
|
|
|
* set to 5 volts. FreeBSD by default doesn't set the Vpp voltages,
|
|
|
|
* which leaves the card in ISA/PCI mode, which prevents it from
|
2001-11-15 06:17:05 +00:00
|
|
|
* being activated as an PCMCIA device.
|
2000-01-14 20:41:03 +00:00
|
|
|
*
|
|
|
|
* Note that some PCMCIA controller software packages for Windows NT
|
|
|
|
* fail to set the voltages as well.
|
2001-09-10 02:36:18 +00:00
|
|
|
*
|
2000-01-14 20:41:03 +00:00
|
|
|
* The Aironet devices can operate in both station mode and access point
|
|
|
|
* mode. Typically, when programmed for station mode, the card can be set
|
|
|
|
* to automatically perform encapsulation/decapsulation of Ethernet II
|
|
|
|
* and 802.3 frames within 802.11 frames so that the host doesn't have
|
|
|
|
* to do it itself. This driver doesn't program the card that way: the
|
|
|
|
* driver handles all of the encapsulation/decapsulation itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_inet.h"
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#define ANCACHE /* enable signal strength cache */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
2001-09-12 08:38:13 +00:00
|
|
|
#include <sys/proc.h>
|
2000-01-14 20:41:03 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#ifdef ANCACHE
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#endif
|
2002-12-29 19:22:07 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <machine/clock.h> /* for DELAY */
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
#include <sys/module.h>
|
2001-09-10 02:05:10 +00:00
|
|
|
#include <sys/sysctl.h>
|
2000-01-14 20:41:03 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
2001-10-11 17:52:20 +00:00
|
|
|
#include <sys/lock.h>
|
2000-10-20 07:58:15 +00:00
|
|
|
#include <sys/mutex.h>
|
2000-01-14 20:41:03 +00:00
|
|
|
#include <machine/resource.h>
|
2002-12-29 19:22:07 +00:00
|
|
|
#include <sys/malloc.h>
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
2001-05-26 09:27:08 +00:00
|
|
|
#include <net/if_media.h>
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2003-06-28 06:17:26 +00:00
|
|
|
#include <net80211/ieee80211_var.h>
|
|
|
|
#include <net80211/ieee80211_ioctl.h>
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
|
|
|
|
#include <dev/an/if_aironet_ieee.h>
|
|
|
|
#include <dev/an/if_anreg.h>
|
|
|
|
|
|
|
|
/* These are global because we need them in sys/pci/if_an_p.c. */
|
2002-03-20 02:08:01 +00:00
|
|
|
static void an_reset (struct an_softc *);
|
2002-12-29 19:22:07 +00:00
|
|
|
static int an_init_mpi350_desc (struct an_softc *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static int an_ioctl (struct ifnet *, u_long, caddr_t);
|
|
|
|
static void an_init (void *);
|
|
|
|
static int an_init_tx_ring (struct an_softc *);
|
|
|
|
static void an_start (struct ifnet *);
|
|
|
|
static void an_watchdog (struct ifnet *);
|
|
|
|
static void an_rxeof (struct an_softc *);
|
|
|
|
static void an_txeof (struct an_softc *, int);
|
|
|
|
|
|
|
|
static void an_promisc (struct an_softc *, int);
|
|
|
|
static int an_cmd (struct an_softc *, int, int);
|
2002-12-29 19:22:07 +00:00
|
|
|
static int an_cmd_struct (struct an_softc *, struct an_command *,
|
|
|
|
struct an_reply *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static int an_read_record (struct an_softc *, struct an_ltv_gen *);
|
|
|
|
static int an_write_record (struct an_softc *, struct an_ltv_gen *);
|
|
|
|
static int an_read_data (struct an_softc *, int, int, caddr_t, int);
|
|
|
|
static int an_write_data (struct an_softc *, int, int, caddr_t, int);
|
|
|
|
static int an_seek (struct an_softc *, int, int, int);
|
|
|
|
static int an_alloc_nicmem (struct an_softc *, int, int *);
|
2002-12-29 19:22:07 +00:00
|
|
|
static int an_dma_malloc (struct an_softc *, bus_size_t,
|
|
|
|
struct an_dma_alloc *, int);
|
|
|
|
static void an_dma_free (struct an_softc *, struct an_dma_alloc *);
|
|
|
|
static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void an_stats_update (void *);
|
|
|
|
static void an_setdef (struct an_softc *, struct an_req *);
|
2000-01-14 20:41:03 +00:00
|
|
|
#ifdef ANCACHE
|
2002-03-20 02:08:01 +00:00
|
|
|
static void an_cache_store (struct an_softc *, struct ether_header *,
|
2002-12-29 19:22:07 +00:00
|
|
|
struct mbuf *, u_int8_t, u_int8_t);
|
2000-01-14 20:41:03 +00:00
|
|
|
#endif
|
|
|
|
|
2001-12-31 22:01:44 +00:00
|
|
|
/* function definitions for use with the Cisco's Linux configuration
|
|
|
|
utilities
|
|
|
|
*/
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int readrids(struct ifnet*, struct aironet_ioctl*);
|
|
|
|
static int writerids(struct ifnet*, struct aironet_ioctl*);
|
|
|
|
static int flashcard(struct ifnet*, struct aironet_ioctl*);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int cmdreset(struct ifnet *);
|
|
|
|
static int setflashmode(struct ifnet *);
|
|
|
|
static int flashgchar(struct ifnet *,int,int);
|
|
|
|
static int flashpchar(struct ifnet *,int,int);
|
|
|
|
static int flashputbuf(struct ifnet *);
|
|
|
|
static int flashrestart(struct ifnet *);
|
|
|
|
static int WaitBusy(struct ifnet *, int);
|
|
|
|
static int unstickbusy(struct ifnet *);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
|
|
|
|
char *);
|
2001-06-22 23:35:24 +00:00
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int an_media_change (struct ifnet *);
|
|
|
|
static void an_media_status (struct ifnet *, struct ifmediareq *);
|
2001-05-26 09:27:08 +00:00
|
|
|
|
2001-06-22 23:35:24 +00:00
|
|
|
static int an_dump = 0;
|
2002-12-29 19:22:07 +00:00
|
|
|
static int an_cache_mode = 0;
|
|
|
|
|
|
|
|
#define DBM 0
|
|
|
|
#define PERCENT 1
|
|
|
|
#define RAW 2
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2001-09-10 02:05:10 +00:00
|
|
|
static char an_conf[256];
|
2002-12-29 19:22:07 +00:00
|
|
|
static char an_conf_cache[256];
|
2001-09-10 02:05:10 +00:00
|
|
|
|
|
|
|
/* sysctl vars */
|
2002-12-29 19:22:07 +00:00
|
|
|
|
2003-02-08 04:41:17 +00:00
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, an, CTLFLAG_RD, 0, "Wireless driver parameters");
|
2001-09-10 02:05:10 +00:00
|
|
|
|
2002-11-14 23:54:55 +00:00
|
|
|
/* XXX violate ethernet/netgraph callback hooks */
|
|
|
|
extern void (*ng_ether_attach_p)(struct ifnet *ifp);
|
|
|
|
extern void (*ng_ether_detach_p)(struct ifnet *ifp);
|
|
|
|
|
2001-09-10 02:05:10 +00:00
|
|
|
static int
|
|
|
|
sysctl_an_dump(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, r, last;
|
|
|
|
char *s = an_conf;
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2001-09-10 02:05:10 +00:00
|
|
|
last = an_dump;
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
switch (an_dump) {
|
2001-09-10 02:05:10 +00:00
|
|
|
case 0:
|
2002-12-29 19:22:07 +00:00
|
|
|
strcpy(an_conf, "off");
|
2001-09-10 02:05:10 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2002-12-29 19:22:07 +00:00
|
|
|
strcpy(an_conf, "type");
|
2001-09-10 02:05:10 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2002-12-29 19:22:07 +00:00
|
|
|
strcpy(an_conf, "dump");
|
2001-09-10 02:05:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(an_conf, 5, "%x", an_dump);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (strncmp(an_conf,"off", 3) == 0) {
|
2001-09-10 02:05:10 +00:00
|
|
|
an_dump = 0;
|
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
if (strncmp(an_conf,"dump", 4) == 0) {
|
2001-09-10 02:05:10 +00:00
|
|
|
an_dump = 1;
|
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
if (strncmp(an_conf,"type", 4) == 0) {
|
2001-09-10 02:05:10 +00:00
|
|
|
an_dump = 2;
|
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
if (*s == 'f') {
|
2001-09-10 02:05:10 +00:00
|
|
|
r = 0;
|
2001-09-10 02:36:18 +00:00
|
|
|
for (;;s++) {
|
|
|
|
if ((*s >= '0') && (*s <= '9')) {
|
2001-09-10 02:05:10 +00:00
|
|
|
r = r * 16 + (*s - '0');
|
2001-09-10 02:36:18 +00:00
|
|
|
} else if ((*s >= 'a') && (*s <= 'f')) {
|
2001-09-10 02:05:10 +00:00
|
|
|
r = r * 16 + (*s - 'a' + 10);
|
2001-09-10 02:36:18 +00:00
|
|
|
} else {
|
|
|
|
break;
|
2001-09-10 02:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
an_dump = r;
|
|
|
|
}
|
|
|
|
if (an_dump != last)
|
|
|
|
printf("Sysctl changed for Aironet driver\n");
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-02-08 04:41:17 +00:00
|
|
|
SYSCTL_PROC(_hw_an, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
|
2001-09-10 02:05:10 +00:00
|
|
|
0, sizeof(an_conf), sysctl_an_dump, "A", "");
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
static int
|
|
|
|
sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, last;
|
|
|
|
|
|
|
|
last = an_cache_mode;
|
|
|
|
|
|
|
|
switch (an_cache_mode) {
|
|
|
|
case 1:
|
|
|
|
strcpy(an_conf_cache, "per");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strcpy(an_conf_cache, "raw");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(an_conf_cache, "dbm");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = sysctl_handle_string(oidp, an_conf_cache,
|
|
|
|
sizeof(an_conf_cache), req);
|
|
|
|
|
|
|
|
if (strncmp(an_conf_cache,"dbm", 3) == 0) {
|
|
|
|
an_cache_mode = 0;
|
|
|
|
}
|
|
|
|
if (strncmp(an_conf_cache,"per", 3) == 0) {
|
|
|
|
an_cache_mode = 1;
|
|
|
|
}
|
|
|
|
if (strncmp(an_conf_cache,"raw", 3) == 0) {
|
|
|
|
an_cache_mode = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-02-08 04:41:17 +00:00
|
|
|
SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
|
2002-12-29 19:22:07 +00:00
|
|
|
0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
/*
|
2000-01-14 20:41:03 +00:00
|
|
|
* We probe for an Aironet 4500/4800 card by attempting to
|
|
|
|
* read the default SSID list. On reset, the first entry in
|
|
|
|
* the SSID list will contain the name "tsunami." If we don't
|
|
|
|
* find this, then there's no card present.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
int
|
|
|
|
an_probe(dev)
|
2000-01-14 20:41:03 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct an_softc *sc = device_get_softc(dev);
|
2003-08-20 03:46:05 +00:00
|
|
|
struct an_ltv_ssidlist_new ssid;
|
2000-01-14 20:41:03 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
bzero((char *)&ssid, sizeof(ssid));
|
|
|
|
|
|
|
|
error = an_alloc_port(dev, 0, AN_IOSIZ);
|
2001-06-22 23:35:24 +00:00
|
|
|
if (error != 0)
|
2000-01-14 20:41:03 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* can't do autoprobing */
|
|
|
|
if (rman_get_start(sc->port_res) == -1)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to fake up a softc structure long enough
|
|
|
|
* to be able to issue commands and call some of the
|
|
|
|
* other routines.
|
|
|
|
*/
|
2000-01-16 06:41:49 +00:00
|
|
|
sc->an_bhandle = rman_get_bushandle(sc->port_res);
|
2000-01-14 20:41:03 +00:00
|
|
|
sc->an_btag = rman_get_bustag(sc->port_res);
|
|
|
|
sc->an_unit = device_get_unit(dev);
|
|
|
|
|
|
|
|
ssid.an_len = sizeof(ssid);
|
|
|
|
ssid.an_type = AN_RID_SSIDLIST;
|
|
|
|
|
|
|
|
/* Make sure interrupts are disabled. */
|
2003-08-20 03:46:05 +00:00
|
|
|
sc->mpi350 = 0;
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
an_reset(sc);
|
|
|
|
|
|
|
|
if (an_cmd(sc, AN_CMD_READCFG, 0))
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
|
|
|
|
return(0);
|
|
|
|
|
2000-11-13 23:04:16 +00:00
|
|
|
/* See if the ssid matches what we expect ... but doesn't have to */
|
2003-08-20 03:46:05 +00:00
|
|
|
if (strcmp(ssid.an_entry[0].an_ssid, AN_DEF_SSID))
|
2000-01-14 20:41:03 +00:00
|
|
|
return(0);
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
return(AN_IOSIZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a port resource with the given resource id.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
an_alloc_port(dev, rid, size)
|
|
|
|
device_t dev;
|
|
|
|
int rid;
|
|
|
|
int size;
|
|
|
|
{
|
|
|
|
struct an_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
|
|
|
|
0ul, ~0ul, size, RF_ACTIVE);
|
|
|
|
if (res) {
|
|
|
|
sc->port_rid = rid;
|
|
|
|
sc->port_res = res;
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/*
|
|
|
|
* Allocate a memory resource with the given resource id.
|
|
|
|
*/
|
|
|
|
int an_alloc_memory(device_t dev, int rid, int size)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
|
|
|
|
0ul, ~0ul, size, RF_ACTIVE);
|
|
|
|
if (res) {
|
|
|
|
sc->mem_rid = rid;
|
|
|
|
sc->mem_res = res;
|
|
|
|
sc->mem_used = size;
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a auxilary memory resource with the given resource id.
|
|
|
|
*/
|
|
|
|
int an_alloc_aux_memory(device_t dev, int rid, int size)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
|
|
|
|
0ul, ~0ul, size, RF_ACTIVE);
|
|
|
|
if (res) {
|
|
|
|
sc->mem_aux_rid = rid;
|
|
|
|
sc->mem_aux_res = res;
|
|
|
|
sc->mem_aux_used = size;
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
/*
|
|
|
|
* Allocate an irq resource with the given resource id.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
an_alloc_irq(dev, rid, flags)
|
|
|
|
device_t dev;
|
|
|
|
int rid;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct an_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
2004-03-17 17:50:55 +00:00
|
|
|
res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
|
|
|
(RF_ACTIVE | flags));
|
2000-01-14 20:41:03 +00:00
|
|
|
if (res) {
|
|
|
|
sc->irq_rid = rid;
|
|
|
|
sc->irq_res = res;
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
static void
|
|
|
|
an_dma_malloc_cb(arg, segs, nseg, error)
|
|
|
|
void *arg;
|
|
|
|
bus_dma_segment_t *segs;
|
|
|
|
int nseg;
|
|
|
|
int error;
|
|
|
|
{
|
|
|
|
bus_addr_t *paddr = (bus_addr_t*) arg;
|
|
|
|
*paddr = segs->ds_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Alloc DMA memory and set the pointer to it
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
an_dma_malloc(sc, size, dma, mapflags)
|
|
|
|
struct an_softc *sc;
|
|
|
|
bus_size_t size;
|
|
|
|
struct an_dma_alloc *dma;
|
|
|
|
int mapflags;
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
|
|
|
|
if (r != 0)
|
|
|
|
goto fail_0;
|
|
|
|
|
|
|
|
r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
|
|
|
|
BUS_DMA_NOWAIT, &dma->an_dma_map);
|
|
|
|
if (r != 0)
|
|
|
|
goto fail_1;
|
|
|
|
|
|
|
|
r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
|
|
|
|
size,
|
|
|
|
an_dma_malloc_cb,
|
|
|
|
&dma->an_dma_paddr,
|
|
|
|
mapflags | BUS_DMA_NOWAIT);
|
|
|
|
if (r != 0)
|
|
|
|
goto fail_2;
|
|
|
|
|
|
|
|
dma->an_dma_size = size;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
fail_2:
|
|
|
|
bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
|
|
|
|
fail_1:
|
|
|
|
bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
|
|
|
|
fail_0:
|
|
|
|
bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
|
|
|
|
dma->an_dma_map = NULL;
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
an_dma_free(sc, dma)
|
|
|
|
struct an_softc *sc;
|
|
|
|
struct an_dma_alloc *dma;
|
|
|
|
{
|
|
|
|
bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
|
|
|
|
bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
|
2003-12-30 01:07:12 +00:00
|
|
|
dma->an_dma_vaddr = 0;
|
2002-12-29 19:22:07 +00:00
|
|
|
bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
|
|
|
|
}
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
/*
|
|
|
|
* Release all resources
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
an_release_resources(dev)
|
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct an_softc *sc = device_get_softc(dev);
|
2002-12-29 19:22:07 +00:00
|
|
|
int i;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
if (sc->port_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT,
|
|
|
|
sc->port_rid, sc->port_res);
|
|
|
|
sc->port_res = 0;
|
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->mem_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
sc->mem_rid, sc->mem_res);
|
|
|
|
sc->mem_res = 0;
|
|
|
|
}
|
|
|
|
if (sc->mem_aux_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
sc->mem_aux_rid, sc->mem_aux_res);
|
|
|
|
sc->mem_aux_res = 0;
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
if (sc->irq_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
|
|
|
sc->irq_rid, sc->irq_res);
|
|
|
|
sc->irq_res = 0;
|
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->an_rid_buffer.an_dma_paddr) {
|
|
|
|
an_dma_free(sc, &sc->an_rid_buffer);
|
|
|
|
}
|
|
|
|
for (i = 0; i < AN_MAX_RX_DESC; i++)
|
|
|
|
if (sc->an_rx_buffer[i].an_dma_paddr) {
|
|
|
|
an_dma_free(sc, &sc->an_rx_buffer[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < AN_MAX_TX_DESC; i++)
|
|
|
|
if (sc->an_tx_buffer[i].an_dma_paddr) {
|
|
|
|
an_dma_free(sc, &sc->an_tx_buffer[i]);
|
|
|
|
}
|
|
|
|
if (sc->an_dtag) {
|
|
|
|
bus_dma_tag_destroy(sc->an_dtag);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
an_init_mpi350_desc(sc)
|
|
|
|
struct an_softc *sc;
|
|
|
|
{
|
|
|
|
struct an_command cmd_struct;
|
|
|
|
struct an_reply reply;
|
|
|
|
struct an_card_rid_desc an_rid_desc;
|
|
|
|
struct an_card_rx_desc an_rx_desc;
|
|
|
|
struct an_card_tx_desc an_tx_desc;
|
|
|
|
int i, desc;
|
|
|
|
|
|
|
|
if(!sc->an_rid_buffer.an_dma_paddr)
|
|
|
|
an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
|
|
|
|
&sc->an_rid_buffer, 0);
|
|
|
|
for (i = 0; i < AN_MAX_RX_DESC; i++)
|
|
|
|
if(!sc->an_rx_buffer[i].an_dma_paddr)
|
|
|
|
an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
|
|
|
|
&sc->an_rx_buffer[i], 0);
|
|
|
|
for (i = 0; i < AN_MAX_TX_DESC; i++)
|
|
|
|
if(!sc->an_tx_buffer[i].an_dma_paddr)
|
|
|
|
an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
|
|
|
|
&sc->an_tx_buffer[i], 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate RX descriptor
|
|
|
|
*/
|
|
|
|
bzero(&reply,sizeof(reply));
|
|
|
|
cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
|
|
|
|
cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
|
|
|
|
cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
|
|
|
|
cmd_struct.an_parm2 = AN_MAX_RX_DESC;
|
|
|
|
if (an_cmd_struct(sc, &cmd_struct, &reply)) {
|
|
|
|
printf("an%d: failed to allocate RX descriptor\n",
|
|
|
|
sc->an_unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
|
|
|
|
bzero(&an_rx_desc, sizeof(an_rx_desc));
|
|
|
|
an_rx_desc.an_valid = 1;
|
|
|
|
an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
|
|
|
|
an_rx_desc.an_done = 0;
|
|
|
|
an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
|
|
|
|
+ (desc * sizeof(an_rx_desc))
|
|
|
|
+ (i * 4),
|
|
|
|
((u_int32_t*)&an_rx_desc)[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate TX descriptor
|
|
|
|
*/
|
|
|
|
|
|
|
|
bzero(&reply,sizeof(reply));
|
|
|
|
cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
|
|
|
|
cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
|
|
|
|
cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
|
|
|
|
cmd_struct.an_parm2 = AN_MAX_TX_DESC;
|
|
|
|
if (an_cmd_struct(sc, &cmd_struct, &reply)) {
|
|
|
|
printf("an%d: failed to allocate TX descriptor\n",
|
|
|
|
sc->an_unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
|
|
|
|
bzero(&an_tx_desc, sizeof(an_tx_desc));
|
|
|
|
an_tx_desc.an_offset = 0;
|
|
|
|
an_tx_desc.an_eoc = 0;
|
|
|
|
an_tx_desc.an_valid = 0;
|
|
|
|
an_tx_desc.an_len = 0;
|
|
|
|
an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
|
|
|
|
+ (desc * sizeof(an_tx_desc))
|
|
|
|
+ (i * 4),
|
|
|
|
((u_int32_t*)&an_tx_desc)[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate RID descriptor
|
|
|
|
*/
|
|
|
|
|
|
|
|
bzero(&reply,sizeof(reply));
|
|
|
|
cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
|
|
|
|
cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
|
|
|
|
cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
|
|
|
|
cmd_struct.an_parm2 = 1;
|
|
|
|
if (an_cmd_struct(sc, &cmd_struct, &reply)) {
|
|
|
|
printf("an%d: failed to allocate host descriptor\n",
|
|
|
|
sc->an_unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(&an_rid_desc, sizeof(an_rid_desc));
|
|
|
|
an_rid_desc.an_valid = 1;
|
|
|
|
an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
|
|
|
|
an_rid_desc.an_rid = 0;
|
|
|
|
an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
|
|
|
|
((u_int32_t*)&an_rid_desc)[i]);
|
|
|
|
|
|
|
|
return(0);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
int
|
|
|
|
an_attach(sc, unit, flags)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int unit;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->arpcom.ac_if;
|
2003-04-10 05:12:45 +00:00
|
|
|
int error = EIO;
|
2003-02-02 22:49:31 +00:00
|
|
|
int i, nrate, mword;
|
|
|
|
u_int8_t r;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&sc->an_mtx, device_get_nameunit(sc->an_dev), MTX_NETWORK_LOCK,
|
|
|
|
MTX_DEF | MTX_RECURSE);
|
2000-10-13 21:58:36 +00:00
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
sc->an_gone = 0;
|
|
|
|
sc->an_associated = 0;
|
2001-09-10 02:05:10 +00:00
|
|
|
sc->an_monitor = 0;
|
|
|
|
sc->an_was_monitor = 0;
|
2002-12-29 19:22:07 +00:00
|
|
|
sc->an_flash_buffer = NULL;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
/* Reset the NIC. */
|
|
|
|
an_reset(sc);
|
2003-01-30 15:01:17 +00:00
|
|
|
if (sc->mpi350) {
|
2002-12-29 19:22:07 +00:00
|
|
|
error = an_init_mpi350_desc(sc);
|
|
|
|
if (error)
|
2003-04-10 05:12:45 +00:00
|
|
|
goto fail;
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
/* Load factory config */
|
|
|
|
if (an_cmd(sc, AN_CMD_READCFG, 0)) {
|
|
|
|
printf("an%d: failed to load config data\n", sc->an_unit);
|
2003-04-10 05:12:45 +00:00
|
|
|
goto fail;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the current configuration */
|
|
|
|
sc->an_config.an_type = AN_RID_GENCONFIG;
|
|
|
|
sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
|
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
|
|
|
|
printf("an%d: read record failed\n", sc->an_unit);
|
2003-04-10 05:12:45 +00:00
|
|
|
goto fail;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the card capabilities */
|
|
|
|
sc->an_caps.an_type = AN_RID_CAPABILITIES;
|
|
|
|
sc->an_caps.an_len = sizeof(struct an_ltv_caps);
|
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_caps)) {
|
|
|
|
printf("an%d: read record failed\n", sc->an_unit);
|
2003-04-10 05:12:45 +00:00
|
|
|
goto fail;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read ssid list */
|
|
|
|
sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
|
2003-08-20 03:46:05 +00:00
|
|
|
sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
|
2000-01-14 20:41:03 +00:00
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
|
|
|
|
printf("an%d: read record failed\n", sc->an_unit);
|
2003-04-10 05:12:45 +00:00
|
|
|
goto fail;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read AP list */
|
|
|
|
sc->an_aplist.an_type = AN_RID_APLIST;
|
|
|
|
sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
|
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
|
|
|
|
printf("an%d: read record failed\n", sc->an_unit);
|
2003-04-10 05:12:45 +00:00
|
|
|
goto fail;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
#ifdef ANCACHE
|
|
|
|
/* Read the RSSI <-> dBm map */
|
|
|
|
sc->an_have_rssimap = 0;
|
|
|
|
if (sc->an_caps.an_softcaps & 8) {
|
|
|
|
sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
|
|
|
|
sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
|
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
|
|
|
|
printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
|
|
|
|
} else {
|
|
|
|
printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
|
|
|
|
sc->an_have_rssimap = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
bcopy((char *)&sc->an_caps.an_oemaddr,
|
|
|
|
(char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
ifp->if_softc = sc;
|
2003-10-31 18:32:15 +00:00
|
|
|
sc->an_unit = unit;
|
|
|
|
if_initname(ifp, device_get_name(sc->an_dev),
|
|
|
|
device_get_unit(sc->an_dev));
|
2000-01-14 20:41:03 +00:00
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = an_ioctl;
|
|
|
|
ifp->if_start = an_start;
|
|
|
|
ifp->if_watchdog = an_watchdog;
|
|
|
|
ifp->if_init = an_init;
|
|
|
|
ifp->if_baudrate = 10000000;
|
2004-08-01 23:58:04 +00:00
|
|
|
IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
|
|
|
|
ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
|
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
bzero(sc->an_config.an_nodename, sizeof(sc->an_config.an_nodename));
|
|
|
|
bcopy(AN_DEFAULT_NODENAME, sc->an_config.an_nodename,
|
|
|
|
sizeof(AN_DEFAULT_NODENAME) - 1);
|
|
|
|
|
2003-08-20 03:46:05 +00:00
|
|
|
bzero(sc->an_ssidlist.an_entry[0].an_ssid,
|
|
|
|
sizeof(sc->an_ssidlist.an_entry[0].an_ssid));
|
|
|
|
bcopy(AN_DEFAULT_NETNAME, sc->an_ssidlist.an_entry[0].an_ssid,
|
2000-01-14 20:41:03 +00:00
|
|
|
sizeof(AN_DEFAULT_NETNAME) - 1);
|
2003-08-20 03:46:05 +00:00
|
|
|
sc->an_ssidlist.an_entry[0].an_len = strlen(AN_DEFAULT_NETNAME);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
sc->an_config.an_opmode =
|
2001-03-12 06:13:39 +00:00
|
|
|
AN_OPMODE_INFRASTRUCTURE_STATION;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
sc->an_tx_rate = 0;
|
|
|
|
bzero((char *)&sc->an_stats, sizeof(sc->an_stats));
|
|
|
|
|
2003-02-02 22:49:31 +00:00
|
|
|
nrate = 8;
|
|
|
|
|
2001-05-26 09:27:08 +00:00
|
|
|
ifmedia_init(&sc->an_ifmedia, 0, an_media_change, an_media_status);
|
2003-02-02 22:49:31 +00:00
|
|
|
if_printf(ifp, "supported rates: ");
|
|
|
|
#define ADD(s, o) ifmedia_add(&sc->an_ifmedia, \
|
|
|
|
IFM_MAKEWORD(IFM_IEEE80211, (s), (o), 0), 0, NULL)
|
|
|
|
ADD(IFM_AUTO, 0);
|
|
|
|
ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
|
|
|
|
for (i = 0; i < nrate; i++) {
|
|
|
|
r = sc->an_caps.an_rates[i];
|
2003-06-28 06:17:26 +00:00
|
|
|
mword = ieee80211_rate2media(NULL, r, IEEE80211_T_DS);
|
2003-02-02 22:49:31 +00:00
|
|
|
if (mword == 0)
|
|
|
|
continue;
|
|
|
|
printf("%s%d%sMbps", (i != 0 ? " " : ""),
|
|
|
|
(r & IEEE80211_RATE_VAL) / 2, ((r & 0x1) != 0 ? ".5" : ""));
|
|
|
|
ADD(mword, 0);
|
|
|
|
ADD(mword, IFM_IEEE80211_ADHOC);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
ifmedia_set(&sc->an_ifmedia, IFM_MAKEWORD(IFM_IEEE80211,
|
|
|
|
IFM_AUTO, 0, 0));
|
|
|
|
#undef ADD
|
2001-05-26 09:27:08 +00:00
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
/*
|
2000-07-13 22:54:34 +00:00
|
|
|
* Call MI attach routine.
|
2000-01-14 20:41:03 +00:00
|
|
|
*/
|
2002-11-14 23:54:55 +00:00
|
|
|
ether_ifattach(ifp, sc->arpcom.ac_enaddr);
|
2000-01-14 20:41:03 +00:00
|
|
|
callout_handle_init(&sc->an_stat_ch);
|
|
|
|
|
|
|
|
return(0);
|
2003-04-10 05:12:45 +00:00
|
|
|
fail:;
|
|
|
|
mtx_destroy(&sc->an_mtx);
|
|
|
|
return(error);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
2003-12-30 01:07:12 +00:00
|
|
|
int
|
|
|
|
an_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = device_get_softc(dev);
|
|
|
|
struct ifnet *ifp = &sc->arpcom.ac_if;
|
|
|
|
|
|
|
|
if (sc->an_gone) {
|
|
|
|
device_printf(dev,"already unloaded\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
AN_LOCK(sc);
|
|
|
|
an_stop(sc);
|
|
|
|
ifmedia_removeall(&sc->an_ifmedia);
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
ether_ifdetach(ifp);
|
|
|
|
sc->an_gone = 1;
|
|
|
|
AN_UNLOCK(sc);
|
|
|
|
bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
|
|
|
|
an_release_resources(dev);
|
|
|
|
mtx_destroy(&sc->an_mtx);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
2001-09-10 02:05:10 +00:00
|
|
|
an_rxeof(sc)
|
|
|
|
struct an_softc *sc;
|
2000-01-14 20:41:03 +00:00
|
|
|
{
|
2001-09-10 02:05:10 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ether_header *eh;
|
|
|
|
struct ieee80211_frame *ih;
|
|
|
|
struct an_rxframe rx_frame;
|
|
|
|
struct an_rxframe_802_3 rx_frame_802_3;
|
|
|
|
struct mbuf *m;
|
2002-12-29 19:22:07 +00:00
|
|
|
int len, id, error = 0, i, count = 0;
|
|
|
|
int ieee80211_header_len;
|
|
|
|
u_char *bpf_buf;
|
|
|
|
u_short fc1;
|
|
|
|
struct an_card_rx_desc an_rx_desc;
|
|
|
|
u_int8_t *buf;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2003-11-14 19:00:32 +00:00
|
|
|
AN_LOCK_ASSERT(sc);
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!sc->mpi350) {
|
|
|
|
id = CSR_READ_2(sc, AN_RX_FID);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
|
|
|
|
/* read raw 802.11 packet */
|
|
|
|
bpf_buf = sc->buf_802_11;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* read header */
|
|
|
|
if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
|
|
|
|
sizeof(rx_frame))) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/*
|
|
|
|
* skip beacon by default since this increases the
|
|
|
|
* system load a lot
|
|
|
|
*/
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
|
|
|
|
(rx_frame.an_frame_ctl &
|
|
|
|
IEEE80211_FC0_SUBTYPE_BEACON)) {
|
2001-09-10 02:05:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
|
|
|
|
len = rx_frame.an_rx_payload_len
|
|
|
|
+ sizeof(rx_frame);
|
|
|
|
/* Check for insane frame length */
|
|
|
|
if (len > sizeof(sc->buf_802_11)) {
|
|
|
|
printf("an%d: oversized packet "
|
|
|
|
"received (%d, %d)\n",
|
|
|
|
sc->an_unit, len, MCLBYTES);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy((char *)&rx_frame,
|
|
|
|
bpf_buf, sizeof(rx_frame));
|
|
|
|
|
|
|
|
error = an_read_data(sc, id, sizeof(rx_frame),
|
|
|
|
(caddr_t)bpf_buf+sizeof(rx_frame),
|
|
|
|
rx_frame.an_rx_payload_len);
|
|
|
|
} else {
|
|
|
|
fc1=rx_frame.an_frame_ctl >> 8;
|
|
|
|
ieee80211_header_len =
|
|
|
|
sizeof(struct ieee80211_frame);
|
|
|
|
if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
|
|
|
|
(fc1 & IEEE80211_FC1_DIR_FROMDS)) {
|
|
|
|
ieee80211_header_len += ETHER_ADDR_LEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = rx_frame.an_rx_payload_len
|
|
|
|
+ ieee80211_header_len;
|
|
|
|
/* Check for insane frame length */
|
|
|
|
if (len > sizeof(sc->buf_802_11)) {
|
|
|
|
printf("an%d: oversized packet "
|
|
|
|
"received (%d, %d)\n",
|
|
|
|
sc->an_unit, len, MCLBYTES);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ih = (struct ieee80211_frame *)bpf_buf;
|
|
|
|
|
|
|
|
bcopy((char *)&rx_frame.an_frame_ctl,
|
|
|
|
(char *)ih, ieee80211_header_len);
|
2001-09-10 02:05:10 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
error = an_read_data(sc, id, sizeof(rx_frame) +
|
|
|
|
rx_frame.an_gaplen,
|
|
|
|
(caddr_t)ih +ieee80211_header_len,
|
|
|
|
rx_frame.an_rx_payload_len);
|
|
|
|
}
|
|
|
|
/* dump raw 802.11 packet to bpf and skip ip stack */
|
|
|
|
BPF_TAP(ifp, bpf_buf, len);
|
2001-09-10 02:36:18 +00:00
|
|
|
} else {
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!(m->m_flags & M_EXT)) {
|
|
|
|
m_freem(m);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
2001-09-10 02:05:10 +00:00
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
/* Read Ethernet encapsulated packet */
|
2001-09-10 02:05:10 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
#ifdef ANCACHE
|
|
|
|
/* Read NIC frame header */
|
|
|
|
if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
|
|
|
|
sizeof(rx_frame))) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Read in the 802_3 frame header */
|
|
|
|
if (an_read_data(sc, id, 0x34,
|
|
|
|
(caddr_t)&rx_frame_802_3,
|
|
|
|
sizeof(rx_frame_802_3))) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (rx_frame_802_3.an_rx_802_3_status != 0) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
2001-09-10 02:05:10 +00:00
|
|
|
/* Check for insane frame length */
|
2002-12-29 19:22:07 +00:00
|
|
|
len = rx_frame_802_3.an_rx_802_3_payload_len;
|
2001-09-10 02:05:10 +00:00
|
|
|
if (len > sizeof(sc->buf_802_11)) {
|
2002-12-29 19:22:07 +00:00
|
|
|
printf("an%d: oversized packet "
|
|
|
|
"received (%d, %d)\n",
|
2001-09-10 02:05:10 +00:00
|
|
|
sc->an_unit, len, MCLBYTES);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
m->m_pkthdr.len = m->m_len =
|
|
|
|
rx_frame_802_3.an_rx_802_3_payload_len + 12;
|
2001-09-10 02:05:10 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
eh = mtod(m, struct ether_header *);
|
2001-09-10 02:05:10 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
|
|
|
|
(char *)&eh->ether_dhost, ETHER_ADDR_LEN);
|
|
|
|
bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
|
|
|
|
(char *)&eh->ether_shost, ETHER_ADDR_LEN);
|
2001-09-10 02:05:10 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* in mbuf header type is just before payload */
|
|
|
|
error = an_read_data(sc, id, 0x44,
|
|
|
|
(caddr_t)&(eh->ether_type),
|
|
|
|
rx_frame_802_3.an_rx_802_3_payload_len);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
m_freem(m);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifp->if_ipackets++;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* Receive packet. */
|
2000-01-14 20:41:03 +00:00
|
|
|
#ifdef ANCACHE
|
2002-12-29 19:22:07 +00:00
|
|
|
an_cache_store(sc, eh, m,
|
2003-02-02 22:49:31 +00:00
|
|
|
rx_frame.an_rx_signal_strength,
|
|
|
|
rx_frame.an_rsvd0);
|
2000-01-14 20:41:03 +00:00
|
|
|
#endif
|
2003-11-14 19:00:32 +00:00
|
|
|
AN_UNLOCK(sc);
|
2002-12-29 19:22:07 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2003-11-14 19:00:32 +00:00
|
|
|
AN_LOCK(sc);
|
2001-09-10 02:05:10 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
} else { /* MPI-350 */
|
|
|
|
for (count = 0; count < AN_MAX_RX_DESC; count++){
|
|
|
|
for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
|
|
|
|
((u_int32_t*)&an_rx_desc)[i]
|
|
|
|
= CSR_MEM_AUX_READ_4(sc,
|
|
|
|
AN_RX_DESC_OFFSET
|
|
|
|
+ (count * sizeof(an_rx_desc))
|
|
|
|
+ (i * 4));
|
|
|
|
|
|
|
|
if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
|
|
|
|
buf = sc->an_rx_buffer[count].an_dma_vaddr;
|
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!(m->m_flags & M_EXT)) {
|
|
|
|
m_freem(m);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
/* Read Ethernet encapsulated packet */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No ANCACHE support since we just get back
|
|
|
|
* an Ethernet packet no 802.11 info
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
#ifdef ANCACHE
|
|
|
|
/* Read NIC frame header */
|
|
|
|
bcopy(buf, (caddr_t)&rx_frame,
|
|
|
|
sizeof(rx_frame));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
/* Check for insane frame length */
|
|
|
|
len = an_rx_desc.an_len + 12;
|
|
|
|
if (len > MCLBYTES) {
|
|
|
|
printf("an%d: oversized packet "
|
|
|
|
"received (%d, %d)\n",
|
|
|
|
sc->an_unit, len, MCLBYTES);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
m->m_pkthdr.len = m->m_len =
|
|
|
|
an_rx_desc.an_len + 12;
|
|
|
|
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
|
|
|
|
bcopy(buf, (char *)eh,
|
|
|
|
m->m_pkthdr.len);
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
|
|
|
/* Receive packet. */
|
|
|
|
#if 0
|
2000-01-14 20:41:03 +00:00
|
|
|
#ifdef ANCACHE
|
2002-12-29 19:22:07 +00:00
|
|
|
an_cache_store(sc, eh, m,
|
2003-02-02 22:49:31 +00:00
|
|
|
rx_frame.an_rx_signal_strength,
|
|
|
|
rx_frame.an_rsvd0);
|
2002-12-29 19:22:07 +00:00
|
|
|
#endif
|
2000-01-14 20:41:03 +00:00
|
|
|
#endif
|
2002-12-29 19:22:07 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
|
|
|
|
an_rx_desc.an_valid = 1;
|
|
|
|
an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
|
|
|
|
an_rx_desc.an_done = 0;
|
|
|
|
an_rx_desc.an_phys =
|
|
|
|
sc->an_rx_buffer[count].an_dma_paddr;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc,
|
|
|
|
AN_RX_DESC_OFFSET
|
|
|
|
+ (count * sizeof(an_rx_desc))
|
|
|
|
+ (i * 4),
|
|
|
|
((u_int32_t*)&an_rx_desc)[i]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
printf("an%d: Didn't get valid RX packet "
|
|
|
|
"%x %x %d\n",
|
|
|
|
sc->an_unit,
|
|
|
|
an_rx_desc.an_done,
|
|
|
|
an_rx_desc.an_valid, an_rx_desc.an_len);
|
|
|
|
}
|
|
|
|
}
|
2001-09-10 02:05:10 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_txeof(sc, status)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int status;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
2001-06-22 23:35:24 +00:00
|
|
|
int id, i;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!sc->mpi350) {
|
2003-08-20 03:46:05 +00:00
|
|
|
id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (status & AN_EV_TX_EXC) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
} else
|
|
|
|
ifp->if_opackets++;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
for (i = 0; i < AN_TX_RING_CNT; i++) {
|
|
|
|
if (id == sc->an_rdata.an_tx_ring[i]) {
|
|
|
|
sc->an_rdata.an_tx_ring[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-22 23:35:24 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
|
|
|
|
} else { /* MPI 350 */
|
2003-08-20 03:46:05 +00:00
|
|
|
id = CSR_READ_2(sc, AN_TX_CMP_FID(sc->mpi350));
|
|
|
|
if (!sc->an_rdata.an_tx_empty){
|
|
|
|
if (status & AN_EV_TX_EXC) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
} else
|
|
|
|
ifp->if_opackets++;
|
|
|
|
AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
|
|
|
|
if (sc->an_rdata.an_tx_prod ==
|
|
|
|
sc->an_rdata.an_tx_cons)
|
|
|
|
sc->an_rdata.an_tx_empty = 1;
|
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We abuse the stats updater to check the current NIC status. This
|
|
|
|
* is important because we don't want to allow transmissions until
|
|
|
|
* the NIC has synchronized to the current cell (either as the master
|
|
|
|
* in an ad-hoc group, or as a station connected to an access point).
|
|
|
|
*/
|
2002-09-28 17:15:38 +00:00
|
|
|
static void
|
2001-09-10 02:36:18 +00:00
|
|
|
an_stats_update(xsc)
|
2000-01-14 20:41:03 +00:00
|
|
|
void *xsc;
|
|
|
|
{
|
|
|
|
struct an_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
sc = xsc;
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_LOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
|
|
|
sc->an_status.an_type = AN_RID_STATUS;
|
|
|
|
sc->an_status.an_len = sizeof(struct an_ltv_status);
|
|
|
|
an_read_record(sc, (struct an_ltv_gen *)&sc->an_status);
|
|
|
|
|
|
|
|
if (sc->an_status.an_opmode & AN_STATUS_OPMODE_IN_SYNC)
|
|
|
|
sc->an_associated = 1;
|
|
|
|
else
|
|
|
|
sc->an_associated = 0;
|
|
|
|
|
|
|
|
/* Don't do this while we're transmitting */
|
|
|
|
if (ifp->if_flags & IFF_OACTIVE) {
|
|
|
|
sc->an_stat_ch = timeout(an_stats_update, sc, hz);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->an_stats.an_len = sizeof(struct an_ltv_stats);
|
|
|
|
sc->an_stats.an_type = AN_RID_32BITS_CUM;
|
|
|
|
an_read_record(sc, (struct an_ltv_gen *)&sc->an_stats.an_len);
|
|
|
|
|
|
|
|
sc->an_stat_ch = timeout(an_stats_update, sc, hz);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
void
|
|
|
|
an_intr(xsc)
|
2000-01-14 20:41:03 +00:00
|
|
|
void *xsc;
|
|
|
|
{
|
|
|
|
struct an_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_int16_t status;
|
|
|
|
|
|
|
|
sc = (struct an_softc*)xsc;
|
|
|
|
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_LOCK(sc);
|
|
|
|
|
|
|
|
if (sc->an_gone) {
|
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
2000-10-13 21:58:36 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
|
|
|
/* Disable interrupts. */
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
|
2003-08-20 03:46:05 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS(sc->mpi350));
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2003-08-20 03:46:05 +00:00
|
|
|
if (status & AN_EV_MIC) {
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_MIC);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status & AN_EV_LINKSTAT) {
|
2002-12-29 19:22:07 +00:00
|
|
|
if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
|
|
|
|
== AN_LINKSTAT_ASSOCIATED)
|
2000-01-14 20:41:03 +00:00
|
|
|
sc->an_associated = 1;
|
|
|
|
else
|
|
|
|
sc->an_associated = 0;
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status & AN_EV_RX) {
|
|
|
|
an_rxeof(sc);
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
2003-08-20 03:46:05 +00:00
|
|
|
if (sc->mpi350 && status & AN_EV_TX_CPY) {
|
|
|
|
an_txeof(sc, status);
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
|
|
|
|
AN_EV_TX_CPY);
|
|
|
|
}
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
if (status & AN_EV_TX) {
|
|
|
|
an_txeof(sc, status);
|
2003-08-20 03:46:05 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
|
|
|
|
AN_EV_TX);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status & AN_EV_TX_EXC) {
|
|
|
|
an_txeof(sc, status);
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status & AN_EV_ALLOC)
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
/* Re-enable interrupts. */
|
2003-08-20 03:46:05 +00:00
|
|
|
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2004-08-01 23:58:04 +00:00
|
|
|
if ((ifp->if_flags & IFF_UP) && !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
2000-01-14 20:41:03 +00:00
|
|
|
an_start(ifp);
|
|
|
|
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
an_cmd_struct(sc, cmd, reply)
|
|
|
|
struct an_softc *sc;
|
|
|
|
struct an_command *cmd;
|
|
|
|
struct an_reply *reply;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i != AN_TIMEOUT; i++) {
|
|
|
|
if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
|
2003-02-08 04:41:17 +00:00
|
|
|
DELAY(1000);
|
2003-01-30 15:01:17 +00:00
|
|
|
} else
|
2002-12-29 19:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-08-20 03:46:05 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if( i == AN_TIMEOUT) {
|
|
|
|
printf("BUSY\n");
|
|
|
|
return(ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
|
|
|
|
CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
|
|
|
|
CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
|
|
|
|
CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
|
|
|
|
|
|
|
|
for (i = 0; i < AN_TIMEOUT; i++) {
|
|
|
|
if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
|
|
|
|
break;
|
2003-02-08 04:41:17 +00:00
|
|
|
DELAY(1000);
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
|
|
|
|
reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
|
|
|
|
reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
|
|
|
|
reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
|
|
|
|
|
|
|
|
if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
|
2003-08-20 03:46:05 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
|
|
|
|
AN_EV_CLR_STUCK_BUSY);
|
2002-12-29 19:22:07 +00:00
|
|
|
|
|
|
|
/* Ack the command */
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
|
|
|
|
|
|
|
|
if (i == AN_TIMEOUT)
|
|
|
|
return(ETIMEDOUT);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_cmd(sc, cmd, val)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int cmd;
|
|
|
|
int val;
|
|
|
|
{
|
|
|
|
int i, s = 0;
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
|
|
|
|
CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
|
|
|
|
CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
|
|
|
|
CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
for (i = 0; i < AN_TIMEOUT; i++) {
|
2002-12-29 19:22:07 +00:00
|
|
|
if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
|
|
|
else {
|
2002-12-29 19:22:07 +00:00
|
|
|
if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
|
|
|
|
CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < AN_TIMEOUT; i++) {
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_READ_2(sc, AN_RESP0(sc->mpi350));
|
|
|
|
CSR_READ_2(sc, AN_RESP1(sc->mpi350));
|
|
|
|
CSR_READ_2(sc, AN_RESP2(sc->mpi350));
|
|
|
|
s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
|
2000-01-14 20:41:03 +00:00
|
|
|
if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ack the command */
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
if (i == AN_TIMEOUT)
|
|
|
|
return(ETIMEDOUT);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This reset sequence may look a little strange, but this is the
|
|
|
|
* most reliable method I've found to really kick the NIC in the
|
|
|
|
* head and force it to reboot correctly.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_reset(sc)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
{
|
|
|
|
if (sc->an_gone)
|
|
|
|
return;
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
an_cmd(sc, AN_CMD_ENABLE, 0);
|
|
|
|
an_cmd(sc, AN_CMD_FW_RESTART, 0);
|
|
|
|
an_cmd(sc, AN_CMD_NOOP2, 0);
|
|
|
|
|
|
|
|
if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
|
|
|
|
printf("an%d: reset failed\n", sc->an_unit);
|
|
|
|
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read an LTV record from the NIC.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_read_record(sc, ltv)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
struct an_ltv_gen *ltv;
|
|
|
|
{
|
2002-12-29 19:22:07 +00:00
|
|
|
struct an_ltv_gen *an_ltv;
|
|
|
|
struct an_card_rid_desc an_rid_desc;
|
|
|
|
struct an_command cmd;
|
|
|
|
struct an_reply reply;
|
2000-01-14 20:41:03 +00:00
|
|
|
u_int16_t *ptr;
|
2001-06-22 23:35:24 +00:00
|
|
|
u_int8_t *ptr2;
|
2000-01-14 20:41:03 +00:00
|
|
|
int i, len;
|
|
|
|
|
2001-06-22 23:35:24 +00:00
|
|
|
if (ltv->an_len < 4 || ltv->an_type == 0)
|
2000-01-14 20:41:03 +00:00
|
|
|
return(EINVAL);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!sc->mpi350){
|
|
|
|
/* Tell the NIC to enter record read mode. */
|
|
|
|
if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
|
|
|
|
printf("an%d: RID access failed\n", sc->an_unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* Seek to the record. */
|
|
|
|
if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
|
|
|
|
printf("an%d: seek to record failed\n", sc->an_unit);
|
|
|
|
return(EIO);
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/*
|
|
|
|
* Read the length and record type and make sure they
|
|
|
|
* match what we expect (this verifies that we have enough
|
|
|
|
* room to hold all of the returned data).
|
|
|
|
* Length includes type but not length.
|
|
|
|
*/
|
|
|
|
len = CSR_READ_2(sc, AN_DATA1);
|
|
|
|
if (len > (ltv->an_len - 2)) {
|
|
|
|
printf("an%d: record length mismatch -- expected %d, "
|
|
|
|
"got %d for Rid %x\n", sc->an_unit,
|
|
|
|
ltv->an_len - 2, len, ltv->an_type);
|
|
|
|
len = ltv->an_len - 2;
|
|
|
|
} else {
|
|
|
|
ltv->an_len = len + 2;
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* Now read the data. */
|
|
|
|
len -= 2; /* skip the type */
|
|
|
|
ptr = <v->an_val;
|
|
|
|
for (i = len; i > 1; i -= 2)
|
|
|
|
*ptr++ = CSR_READ_2(sc, AN_DATA1);
|
|
|
|
if (i) {
|
|
|
|
ptr2 = (u_int8_t *)ptr;
|
|
|
|
*ptr2 = CSR_READ_1(sc, AN_DATA1);
|
|
|
|
}
|
|
|
|
} else { /* MPI-350 */
|
2003-12-30 01:07:12 +00:00
|
|
|
if (!sc->an_rid_buffer.an_dma_vaddr)
|
|
|
|
return(EIO);
|
2002-12-29 19:22:07 +00:00
|
|
|
an_rid_desc.an_valid = 1;
|
|
|
|
an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
|
|
|
|
an_rid_desc.an_rid = 0;
|
|
|
|
an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
|
|
|
|
bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
|
|
|
|
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
|
|
|
bzero(&reply, sizeof(reply));
|
|
|
|
cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
|
|
|
|
cmd.an_parm0 = ltv->an_type;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
|
|
|
|
((u_int32_t*)&an_rid_desc)[i]);
|
|
|
|
|
|
|
|
if (an_cmd_struct(sc, &cmd, &reply)
|
|
|
|
|| reply.an_status & AN_CMD_QUAL_MASK) {
|
|
|
|
printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
|
|
|
|
sc->an_unit, ltv->an_type,
|
|
|
|
reply.an_status,
|
|
|
|
reply.an_resp0,
|
|
|
|
reply.an_resp1,
|
|
|
|
reply.an_resp2,
|
|
|
|
i);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
|
|
|
|
if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
|
|
|
|
an_rid_desc.an_len = an_ltv->an_len;
|
|
|
|
}
|
|
|
|
|
2003-12-30 01:07:12 +00:00
|
|
|
len = an_rid_desc.an_len;
|
|
|
|
if (len > (ltv->an_len - 2)) {
|
|
|
|
printf("an%d: record length mismatch -- expected %d, "
|
|
|
|
"got %d for Rid %x\n", sc->an_unit,
|
|
|
|
ltv->an_len - 2, len, ltv->an_type);
|
|
|
|
len = ltv->an_len - 2;
|
|
|
|
} else {
|
|
|
|
ltv->an_len = len + 2;
|
|
|
|
}
|
|
|
|
bcopy(&an_ltv->an_type,
|
|
|
|
<v->an_val,
|
|
|
|
len);
|
2001-06-22 23:35:24 +00:00
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
|
2001-06-22 23:35:24 +00:00
|
|
|
if (an_dump)
|
|
|
|
an_dump_record(sc, ltv, "Read");
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Same as read, except we inject data instead of reading it.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_write_record(sc, ltv)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
struct an_ltv_gen *ltv;
|
|
|
|
{
|
2002-12-29 19:22:07 +00:00
|
|
|
struct an_card_rid_desc an_rid_desc;
|
|
|
|
struct an_command cmd;
|
|
|
|
struct an_reply reply;
|
|
|
|
char *buf;
|
2000-01-14 20:41:03 +00:00
|
|
|
u_int16_t *ptr;
|
2001-06-22 23:35:24 +00:00
|
|
|
u_int8_t *ptr2;
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
if (an_dump)
|
|
|
|
an_dump_record(sc, ltv, "Write");
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!sc->mpi350){
|
|
|
|
if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
|
|
|
|
return(EIO);
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
|
|
|
|
return(EIO);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/*
|
|
|
|
* Length includes type but not length.
|
|
|
|
*/
|
|
|
|
len = ltv->an_len - 2;
|
|
|
|
CSR_WRITE_2(sc, AN_DATA1, len);
|
|
|
|
|
|
|
|
len -= 2; /* skip the type */
|
|
|
|
ptr = <v->an_val;
|
|
|
|
for (i = len; i > 1; i -= 2)
|
|
|
|
CSR_WRITE_2(sc, AN_DATA1, *ptr++);
|
|
|
|
if (i) {
|
|
|
|
ptr2 = (u_int8_t *)ptr;
|
|
|
|
CSR_WRITE_1(sc, AN_DATA0, *ptr2);
|
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
|
|
|
|
return(EIO);
|
2003-01-30 15:01:17 +00:00
|
|
|
} else {
|
|
|
|
/* MPI-350 */
|
2002-12-29 19:22:07 +00:00
|
|
|
|
|
|
|
for (i = 0; i != AN_TIMEOUT; i++) {
|
2003-01-30 15:01:17 +00:00
|
|
|
if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350))
|
|
|
|
& AN_CMD_BUSY) {
|
2002-12-29 19:22:07 +00:00
|
|
|
DELAY(10);
|
2003-01-30 15:01:17 +00:00
|
|
|
} else
|
2002-12-29 19:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == AN_TIMEOUT) {
|
|
|
|
printf("BUSY\n");
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
an_rid_desc.an_valid = 1;
|
|
|
|
an_rid_desc.an_len = ltv->an_len - 2;
|
|
|
|
an_rid_desc.an_rid = ltv->an_type;
|
|
|
|
an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
|
|
|
|
|
|
|
|
bcopy(<v->an_type, sc->an_rid_buffer.an_dma_vaddr,
|
|
|
|
an_rid_desc.an_len);
|
|
|
|
|
|
|
|
bzero(&cmd,sizeof(cmd));
|
|
|
|
bzero(&reply,sizeof(reply));
|
|
|
|
cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
|
|
|
|
cmd.an_parm0 = ltv->an_type;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
|
|
|
|
((u_int32_t*)&an_rid_desc)[i]);
|
|
|
|
|
2003-02-08 04:41:17 +00:00
|
|
|
DELAY(100000);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if ((i = an_cmd_struct(sc, &cmd, &reply))) {
|
2003-02-08 04:41:17 +00:00
|
|
|
printf("an%d: failed to write RID 1 %x %x %x %x %x, %d\n",
|
2003-01-30 15:01:17 +00:00
|
|
|
sc->an_unit, ltv->an_type,
|
|
|
|
reply.an_status,
|
|
|
|
reply.an_resp0,
|
|
|
|
reply.an_resp1,
|
|
|
|
reply.an_resp2,
|
|
|
|
i);
|
|
|
|
return(EIO);
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (u_int16_t *)buf;
|
|
|
|
|
|
|
|
if (reply.an_status & AN_CMD_QUAL_MASK) {
|
2003-02-08 04:41:17 +00:00
|
|
|
printf("an%d: failed to write RID 2 %x %x %x %x %x, %d\n",
|
2003-01-30 15:01:17 +00:00
|
|
|
sc->an_unit, ltv->an_type,
|
|
|
|
reply.an_status,
|
|
|
|
reply.an_resp0,
|
|
|
|
reply.an_resp1,
|
|
|
|
reply.an_resp2,
|
|
|
|
i);
|
2002-12-29 19:22:07 +00:00
|
|
|
return(EIO);
|
|
|
|
}
|
2003-02-08 04:41:17 +00:00
|
|
|
DELAY(100000);
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_dump_record(sc, ltv, string)
|
2001-06-22 23:35:24 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
struct an_ltv_gen *ltv;
|
|
|
|
char *string;
|
|
|
|
{
|
|
|
|
u_int8_t *ptr2;
|
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
int count = 0;
|
|
|
|
char buf[17], temp;
|
|
|
|
|
|
|
|
len = ltv->an_len - 4;
|
2001-09-10 02:36:18 +00:00
|
|
|
printf("an%d: RID %4x, Length %4d, Mode %s\n",
|
2001-06-22 23:35:24 +00:00
|
|
|
sc->an_unit, ltv->an_type, ltv->an_len - 4, string);
|
|
|
|
|
|
|
|
if (an_dump == 1 || (an_dump == ltv->an_type)) {
|
|
|
|
printf("an%d:\t", sc->an_unit);
|
|
|
|
bzero(buf,sizeof(buf));
|
|
|
|
|
|
|
|
ptr2 = (u_int8_t *)<v->an_val;
|
|
|
|
for (i = len; i > 0; i--) {
|
|
|
|
printf("%02x ", *ptr2);
|
|
|
|
|
|
|
|
temp = *ptr2++;
|
|
|
|
if (temp >= ' ' && temp <= '~')
|
|
|
|
buf[count] = temp;
|
|
|
|
else if (temp >= 'A' && temp <= 'Z')
|
|
|
|
buf[count] = temp;
|
|
|
|
else
|
|
|
|
buf[count] = '.';
|
|
|
|
if (++count == 16) {
|
|
|
|
count = 0;
|
|
|
|
printf("%s\n",buf);
|
|
|
|
printf("an%d:\t", sc->an_unit);
|
|
|
|
bzero(buf,sizeof(buf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (; count != 16; count++) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf(" %s\n",buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_seek(sc, id, off, chan)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int id, off, chan;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int selreg, offreg;
|
|
|
|
|
|
|
|
switch (chan) {
|
|
|
|
case AN_BAP0:
|
|
|
|
selreg = AN_SEL0;
|
|
|
|
offreg = AN_OFF0;
|
|
|
|
break;
|
|
|
|
case AN_BAP1:
|
|
|
|
selreg = AN_SEL1;
|
|
|
|
offreg = AN_OFF1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("an%d: invalid data path: %x\n", sc->an_unit, chan);
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
CSR_WRITE_2(sc, selreg, id);
|
|
|
|
CSR_WRITE_2(sc, offreg, off);
|
|
|
|
|
|
|
|
for (i = 0; i < AN_TIMEOUT; i++) {
|
|
|
|
if (!(CSR_READ_2(sc, offreg) & (AN_OFF_BUSY|AN_OFF_ERR)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == AN_TIMEOUT)
|
|
|
|
return(ETIMEDOUT);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_read_data(sc, id, off, buf, len)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int id, off;
|
|
|
|
caddr_t buf;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_int16_t *ptr;
|
|
|
|
u_int8_t *ptr2;
|
|
|
|
|
|
|
|
if (off != -1) {
|
|
|
|
if (an_seek(sc, id, off, AN_BAP1))
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (u_int16_t *)buf;
|
2001-06-22 23:35:24 +00:00
|
|
|
for (i = len; i > 1; i -= 2)
|
|
|
|
*ptr++ = CSR_READ_2(sc, AN_DATA1);
|
|
|
|
if (i) {
|
|
|
|
ptr2 = (u_int8_t *)ptr;
|
|
|
|
*ptr2 = CSR_READ_1(sc, AN_DATA1);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_write_data(sc, id, off, buf, len)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int id, off;
|
|
|
|
caddr_t buf;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_int16_t *ptr;
|
|
|
|
u_int8_t *ptr2;
|
|
|
|
|
|
|
|
if (off != -1) {
|
|
|
|
if (an_seek(sc, id, off, AN_BAP0))
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (u_int16_t *)buf;
|
2001-06-22 23:35:24 +00:00
|
|
|
for (i = len; i > 1; i -= 2)
|
|
|
|
CSR_WRITE_2(sc, AN_DATA0, *ptr++);
|
|
|
|
if (i) {
|
|
|
|
ptr2 = (u_int8_t *)ptr;
|
|
|
|
CSR_WRITE_1(sc, AN_DATA0, *ptr2);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a region of memory inside the NIC and zero
|
|
|
|
* it out.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_alloc_nicmem(sc, len, id)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int len;
|
|
|
|
int *id;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
|
|
|
|
printf("an%d: failed to allocate %d bytes on NIC\n",
|
|
|
|
sc->an_unit, len);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < AN_TIMEOUT; i++) {
|
2002-12-29 19:22:07 +00:00
|
|
|
if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == AN_TIMEOUT)
|
|
|
|
return(ETIMEDOUT);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
|
2000-01-14 20:41:03 +00:00
|
|
|
*id = CSR_READ_2(sc, AN_ALLOC_FID);
|
|
|
|
|
|
|
|
if (an_seek(sc, *id, 0, AN_BAP0))
|
|
|
|
return(EIO);
|
|
|
|
|
|
|
|
for (i = 0; i < len / 2; i++)
|
|
|
|
CSR_WRITE_2(sc, AN_DATA0, 0);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_setdef(sc, areq)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
struct an_req *areq;
|
|
|
|
{
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct an_ltv_genconfig *cfg;
|
2003-08-20 03:46:05 +00:00
|
|
|
struct an_ltv_ssidlist_new *ssid;
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_ltv_aplist *ap;
|
|
|
|
struct an_ltv_gen *sp;
|
|
|
|
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
|
|
|
switch (areq->an_type) {
|
|
|
|
case AN_RID_GENCONFIG:
|
|
|
|
cfg = (struct an_ltv_genconfig *)areq;
|
|
|
|
|
2001-09-06 02:40:43 +00:00
|
|
|
ifa = ifaddr_byindex(ifp->if_index);
|
2000-01-14 20:41:03 +00:00
|
|
|
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
|
|
|
bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
bcopy((char *)&cfg->an_macaddr, LLADDR(sdl), ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
bcopy((char *)cfg, (char *)&sc->an_config,
|
|
|
|
sizeof(struct an_ltv_genconfig));
|
|
|
|
break;
|
|
|
|
case AN_RID_SSIDLIST:
|
2003-08-20 03:46:05 +00:00
|
|
|
ssid = (struct an_ltv_ssidlist_new *)areq;
|
2000-01-14 20:41:03 +00:00
|
|
|
bcopy((char *)ssid, (char *)&sc->an_ssidlist,
|
2003-08-20 03:46:05 +00:00
|
|
|
sizeof(struct an_ltv_ssidlist_new));
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
|
|
|
case AN_RID_APLIST:
|
|
|
|
ap = (struct an_ltv_aplist *)areq;
|
|
|
|
bcopy((char *)ap, (char *)&sc->an_aplist,
|
|
|
|
sizeof(struct an_ltv_aplist));
|
|
|
|
break;
|
|
|
|
case AN_RID_TX_SPEED:
|
|
|
|
sp = (struct an_ltv_gen *)areq;
|
|
|
|
sc->an_tx_rate = sp->an_val;
|
2003-02-02 22:49:31 +00:00
|
|
|
|
|
|
|
/* Read the current configuration */
|
|
|
|
sc->an_config.an_type = AN_RID_GENCONFIG;
|
|
|
|
sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
|
|
|
|
an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
|
|
|
|
cfg = &sc->an_config;
|
|
|
|
|
|
|
|
/* clear other rates and set the only one we want */
|
|
|
|
bzero(cfg->an_rates, sizeof(cfg->an_rates));
|
|
|
|
cfg->an_rates[0] = sc->an_tx_rate;
|
|
|
|
|
|
|
|
/* Save the new rate */
|
|
|
|
sc->an_config.an_type = AN_RID_GENCONFIG;
|
|
|
|
sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
|
2000-11-13 23:04:16 +00:00
|
|
|
break;
|
|
|
|
case AN_RID_WEP_TEMP:
|
2003-02-08 04:41:17 +00:00
|
|
|
/* Cache the temp keys */
|
|
|
|
bcopy(areq,
|
|
|
|
&sc->an_temp_keys[((struct an_ltv_key *)areq)->kindex],
|
|
|
|
sizeof(struct an_ltv_key));
|
2000-11-13 23:04:16 +00:00
|
|
|
case AN_RID_WEP_PERM:
|
2001-12-31 22:01:44 +00:00
|
|
|
case AN_RID_LEAPUSERNAME:
|
|
|
|
case AN_RID_LEAPPASSWORD:
|
2003-08-20 03:46:05 +00:00
|
|
|
an_init(sc);
|
|
|
|
|
2000-11-13 23:04:16 +00:00
|
|
|
/* Disable the MAC. */
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2001-09-10 02:05:10 +00:00
|
|
|
/* Write the key */
|
2000-11-13 23:04:16 +00:00
|
|
|
an_write_record(sc, (struct an_ltv_gen *)areq);
|
2001-09-10 02:36:18 +00:00
|
|
|
|
|
|
|
/* Turn the MAC back on. */
|
2000-11-13 23:04:16 +00:00
|
|
|
an_cmd(sc, AN_CMD_ENABLE, 0);
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2001-09-10 02:05:10 +00:00
|
|
|
break;
|
|
|
|
case AN_RID_MONITOR_MODE:
|
|
|
|
cfg = (struct an_ltv_genconfig *)areq;
|
|
|
|
bpfdetach(ifp);
|
|
|
|
if (ng_ether_detach_p != NULL)
|
|
|
|
(*ng_ether_detach_p) (ifp);
|
|
|
|
sc->an_monitor = cfg->an_len;
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
if (sc->an_monitor & AN_MONITOR) {
|
|
|
|
if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
|
|
|
|
bpfattach(ifp, DLT_AIRONET_HEADER,
|
2001-09-10 02:05:10 +00:00
|
|
|
sizeof(struct ether_header));
|
|
|
|
} else {
|
2001-09-10 02:36:18 +00:00
|
|
|
bpfattach(ifp, DLT_IEEE802_11,
|
2001-09-10 02:05:10 +00:00
|
|
|
sizeof(struct ether_header));
|
|
|
|
}
|
|
|
|
} else {
|
2001-09-10 02:36:18 +00:00
|
|
|
bpfattach(ifp, DLT_EN10MB,
|
2001-09-10 02:05:10 +00:00
|
|
|
sizeof(struct ether_header));
|
|
|
|
if (ng_ether_attach_p != NULL)
|
|
|
|
(*ng_ether_attach_p) (ifp);
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("an%d: unknown RID: %x\n", sc->an_unit, areq->an_type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Reinitialize the card. */
|
2001-03-23 17:46:32 +00:00
|
|
|
if (ifp->if_flags)
|
2000-01-14 20:41:03 +00:00
|
|
|
an_init(sc);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-10 02:05:10 +00:00
|
|
|
* Derived from Linux driver to enable promiscious mode.
|
2000-01-14 20:41:03 +00:00
|
|
|
*/
|
2001-09-10 02:05:10 +00:00
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_promisc(sc, promisc)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
int promisc;
|
|
|
|
{
|
2001-09-10 02:36:18 +00:00
|
|
|
if (sc->an_was_monitor)
|
2001-09-10 02:05:10 +00:00
|
|
|
an_reset(sc);
|
2003-06-01 09:27:33 +00:00
|
|
|
/* XXX: indentation bug or braces bug ? */
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->mpi350)
|
|
|
|
an_init_mpi350_desc(sc);
|
2001-09-10 02:36:18 +00:00
|
|
|
if (sc->an_monitor || sc->an_was_monitor)
|
2001-09-10 02:05:10 +00:00
|
|
|
an_init(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2001-09-10 02:05:10 +00:00
|
|
|
sc->an_was_monitor = sc->an_monitor;
|
|
|
|
an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_ioctl(ifp, command, data)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
u_long command;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
2000-10-13 21:58:36 +00:00
|
|
|
int error = 0;
|
2001-05-26 09:27:08 +00:00
|
|
|
int len;
|
2003-08-20 03:46:05 +00:00
|
|
|
int i, max;
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
struct ifreq *ifr;
|
2002-04-01 21:31:13 +00:00
|
|
|
struct thread *td = curthread;
|
2001-05-26 09:27:08 +00:00
|
|
|
struct ieee80211req *ireq;
|
|
|
|
u_int8_t tmpstr[IEEE80211_NWID_LEN*2];
|
|
|
|
u_int8_t *tmpptr;
|
|
|
|
struct an_ltv_genconfig *config;
|
|
|
|
struct an_ltv_key *key;
|
|
|
|
struct an_ltv_status *status;
|
2003-08-20 03:46:05 +00:00
|
|
|
struct an_ltv_ssidlist_new *ssids;
|
2001-12-31 22:01:44 +00:00
|
|
|
int mode;
|
|
|
|
struct aironet_ioctl l_ioctl;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_LOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
ifr = (struct ifreq *)data;
|
2001-05-26 09:27:08 +00:00
|
|
|
ireq = (struct ieee80211req *)data;
|
|
|
|
|
2001-12-31 22:12:42 +00:00
|
|
|
config = (struct an_ltv_genconfig *)&sc->areq;
|
|
|
|
key = (struct an_ltv_key *)&sc->areq;
|
|
|
|
status = (struct an_ltv_status *)&sc->areq;
|
2003-08-20 03:46:05 +00:00
|
|
|
ssids = (struct an_ltv_ssidlist_new *)&sc->areq;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2000-08-08 23:53:11 +00:00
|
|
|
if (sc->an_gone) {
|
2000-06-18 23:40:09 +00:00
|
|
|
error = ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
switch (command) {
|
2000-01-14 20:41:03 +00:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
|
|
if (ifp->if_flags & IFF_RUNNING &&
|
|
|
|
ifp->if_flags & IFF_PROMISC &&
|
|
|
|
!(sc->an_if_flags & IFF_PROMISC)) {
|
|
|
|
an_promisc(sc, 1);
|
|
|
|
} else if (ifp->if_flags & IFF_RUNNING &&
|
|
|
|
!(ifp->if_flags & IFF_PROMISC) &&
|
|
|
|
sc->an_if_flags & IFF_PROMISC) {
|
|
|
|
an_promisc(sc, 0);
|
|
|
|
} else
|
|
|
|
an_init(sc);
|
|
|
|
} else {
|
|
|
|
if (ifp->if_flags & IFF_RUNNING)
|
|
|
|
an_stop(sc);
|
|
|
|
}
|
|
|
|
sc->an_if_flags = ifp->if_flags;
|
|
|
|
error = 0;
|
|
|
|
break;
|
2001-05-26 09:27:08 +00:00
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->an_ifmedia, command);
|
|
|
|
break;
|
2000-01-14 20:41:03 +00:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
/* The Aironet has no multicast filter. */
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCGAIRONET:
|
2001-12-31 22:12:42 +00:00
|
|
|
error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
|
2001-06-22 23:35:24 +00:00
|
|
|
if (error != 0)
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
|
|
|
#ifdef ANCACHE
|
2001-12-31 22:12:42 +00:00
|
|
|
if (sc->areq.an_type == AN_RID_ZERO_CACHE) {
|
2002-12-24 14:46:01 +00:00
|
|
|
error = suser(td);
|
|
|
|
if (error)
|
|
|
|
break;
|
2000-01-14 20:41:03 +00:00
|
|
|
sc->an_sigitems = sc->an_nextitem = 0;
|
|
|
|
break;
|
2001-12-31 22:12:42 +00:00
|
|
|
} else if (sc->areq.an_type == AN_RID_READ_CACHE) {
|
|
|
|
char *pt = (char *)&sc->areq.an_val;
|
2000-01-14 20:41:03 +00:00
|
|
|
bcopy((char *)&sc->an_sigitems, (char *)pt,
|
|
|
|
sizeof(int));
|
|
|
|
pt += sizeof(int);
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = sizeof(int) / 2;
|
2000-01-14 20:41:03 +00:00
|
|
|
bcopy((char *)&sc->an_sigcache, (char *)pt,
|
|
|
|
sizeof(struct an_sigcache) * sc->an_sigitems);
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len += ((sizeof(struct an_sigcache) *
|
2000-01-14 20:41:03 +00:00
|
|
|
sc->an_sigitems) / 2) + 1;
|
|
|
|
} else
|
|
|
|
#endif
|
2001-12-31 22:12:42 +00:00
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&sc->areq)) {
|
2000-01-14 20:41:03 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2001-12-31 22:12:42 +00:00
|
|
|
error = copyout(&sc->areq, ifr->ifr_data, sizeof(sc->areq));
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
|
|
|
case SIOCSAIRONET:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)))
|
2000-08-08 23:53:11 +00:00
|
|
|
goto out;
|
2001-12-31 22:12:42 +00:00
|
|
|
error = copyin(ifr->ifr_data, &sc->areq, sizeof(sc->areq));
|
2001-06-22 23:35:24 +00:00
|
|
|
if (error != 0)
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
2001-12-31 22:12:42 +00:00
|
|
|
an_setdef(sc, &sc->areq);
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
2001-12-31 22:01:44 +00:00
|
|
|
case SIOCGPRIVATE_0: /* used by Cisco client utility */
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)))
|
2002-03-14 20:56:41 +00:00
|
|
|
goto out;
|
2001-12-31 22:01:44 +00:00
|
|
|
copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
|
|
|
|
mode = l_ioctl.command;
|
|
|
|
|
|
|
|
if (mode >= AIROGCAP && mode <= AIROGSTATSD32) {
|
|
|
|
error = readrids(ifp, &l_ioctl);
|
2003-01-30 15:01:17 +00:00
|
|
|
} else if (mode >= AIROPCAP && mode <= AIROPLEAPUSR) {
|
2001-12-31 22:01:44 +00:00
|
|
|
error = writerids(ifp, &l_ioctl);
|
2003-01-30 15:01:17 +00:00
|
|
|
} else if (mode >= AIROFLSHRST && mode <= AIRORESTART) {
|
2001-12-31 22:01:44 +00:00
|
|
|
error = flashcard(ifp, &l_ioctl);
|
2003-01-30 15:01:17 +00:00
|
|
|
} else {
|
2001-12-31 22:01:44 +00:00
|
|
|
error =-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy out the updated command info */
|
|
|
|
copyout(&l_ioctl, ifr->ifr_data, sizeof(l_ioctl));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SIOCGPRIVATE_1: /* used by Cisco client utility */
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)))
|
2002-03-14 20:56:41 +00:00
|
|
|
goto out;
|
2001-12-31 22:01:44 +00:00
|
|
|
copyin(ifr->ifr_data, &l_ioctl, sizeof(l_ioctl));
|
|
|
|
l_ioctl.command = 0;
|
|
|
|
error = AIROMAGIC;
|
|
|
|
copyout(&error, l_ioctl.data, sizeof(error));
|
|
|
|
error = 0;
|
|
|
|
break;
|
2001-05-26 09:27:08 +00:00
|
|
|
case SIOCG80211:
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = sizeof(sc->areq);
|
2001-12-31 22:01:44 +00:00
|
|
|
/* was that a good idea DJA we are doing a short-cut */
|
2001-09-10 02:36:18 +00:00
|
|
|
switch (ireq->i_type) {
|
2001-05-26 09:27:08 +00:00
|
|
|
case IEEE80211_IOC_SSID:
|
2001-06-22 23:35:24 +00:00
|
|
|
if (ireq->i_val == -1) {
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_STATUS;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
len = status->an_ssidlen;
|
|
|
|
tmpptr = status->an_ssid;
|
2001-06-22 23:35:24 +00:00
|
|
|
} else if (ireq->i_val >= 0) {
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_SSIDLIST;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2003-08-20 03:46:05 +00:00
|
|
|
max = (sc->areq.an_len - 4)
|
|
|
|
/ sizeof(struct an_ltv_ssid_entry);
|
|
|
|
if ( max > MAX_SSIDS ) {
|
|
|
|
printf("To many SSIDs only using "
|
|
|
|
"%d of %d\n",
|
|
|
|
MAX_SSIDS, max);
|
|
|
|
max = MAX_SSIDS;
|
|
|
|
}
|
|
|
|
if (ireq->i_val > max) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
2003-08-20 03:46:05 +00:00
|
|
|
} else {
|
|
|
|
len = ssids->an_entry[ireq->i_val].an_len;
|
|
|
|
tmpptr = ssids->an_entry[ireq->i_val].an_ssid;
|
2001-05-26 09:27:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-22 23:35:24 +00:00
|
|
|
if (len > IEEE80211_NWID_LEN) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ireq->i_len = len;
|
|
|
|
bzero(tmpstr, IEEE80211_NWID_LEN);
|
|
|
|
bcopy(tmpptr, tmpstr, len);
|
|
|
|
error = copyout(tmpstr, ireq->i_data,
|
|
|
|
IEEE80211_NWID_LEN);
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_NUMSSIDS:
|
2003-08-20 03:46:05 +00:00
|
|
|
sc->areq.an_len = sizeof(sc->areq);
|
|
|
|
sc->areq.an_type = AN_RID_SSIDLIST;
|
|
|
|
if (an_read_record(sc,
|
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
max = (sc->areq.an_len - 4)
|
|
|
|
/ sizeof(struct an_ltv_ssid_entry);
|
|
|
|
if ( max > MAX_SSIDS ) {
|
|
|
|
printf("To many SSIDs only using "
|
|
|
|
"%d of %d\n",
|
|
|
|
MAX_SSIDS, max);
|
|
|
|
max = MAX_SSIDS;
|
|
|
|
}
|
|
|
|
ireq->i_val = max;
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_WEP:
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_ACTUALCFG;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-22 23:35:24 +00:00
|
|
|
if (config->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) {
|
|
|
|
if (config->an_authtype &
|
2001-05-26 09:27:08 +00:00
|
|
|
AN_AUTHTYPE_ALLOW_UNENCRYPTED)
|
|
|
|
ireq->i_val = IEEE80211_WEP_MIXED;
|
|
|
|
else
|
|
|
|
ireq->i_val = IEEE80211_WEP_ON;
|
|
|
|
} else {
|
|
|
|
ireq->i_val = IEEE80211_WEP_OFF;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_WEPKEY:
|
|
|
|
/*
|
|
|
|
* XXX: I'm not entierly convinced this is
|
|
|
|
* correct, but it's what is implemented in
|
|
|
|
* ancontrol so it will have to do until we get
|
|
|
|
* access to actual Cisco code.
|
|
|
|
*/
|
2001-12-31 22:01:44 +00:00
|
|
|
if (ireq->i_val < 0 || ireq->i_val > 8) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
len = 0;
|
2001-12-31 22:01:44 +00:00
|
|
|
if (ireq->i_val < 5) {
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_WEP_TEMP;
|
2001-06-22 23:35:24 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-22 23:35:24 +00:00
|
|
|
if (key->kindex == 0xffff)
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
2001-06-22 23:35:24 +00:00
|
|
|
if (key->kindex == ireq->i_val)
|
|
|
|
len = key->klen;
|
2001-05-26 09:27:08 +00:00
|
|
|
/* Required to get next entry */
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_WEP_PERM;
|
2001-05-26 09:27:08 +00:00
|
|
|
}
|
2001-06-22 23:35:24 +00:00
|
|
|
if (error != 0)
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* We aren't allowed to read the value of the
|
|
|
|
* key from the card so we just output zeros
|
|
|
|
* like we would if we could read the card, but
|
|
|
|
* denied the user access.
|
|
|
|
*/
|
|
|
|
bzero(tmpstr, len);
|
|
|
|
ireq->i_len = len;
|
|
|
|
error = copyout(tmpstr, ireq->i_data, len);
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_NUMWEPKEYS:
|
2001-12-31 22:01:44 +00:00
|
|
|
ireq->i_val = 9; /* include home key */
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_WEPTXKEY:
|
2001-06-22 23:35:24 +00:00
|
|
|
/*
|
|
|
|
* For some strange reason, you have to read all
|
|
|
|
* keys before you can read the txkey.
|
|
|
|
*/
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_WEP_TEMP;
|
2001-06-22 23:35:24 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *) &sc->areq)) {
|
2001-06-22 23:35:24 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (key->kindex == 0xffff)
|
|
|
|
break;
|
|
|
|
/* Required to get next entry */
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_WEP_PERM;
|
2001-06-22 23:35:24 +00:00
|
|
|
}
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_WEP_PERM;
|
2001-05-26 09:27:08 +00:00
|
|
|
key->kindex = 0xffff;
|
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ireq->i_val = key->mac[0];
|
2001-12-31 22:01:44 +00:00
|
|
|
/*
|
|
|
|
* Check for home mode. Map home mode into
|
|
|
|
* 5th key since that is how it is stored on
|
|
|
|
* the card
|
|
|
|
*/
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = sizeof(struct an_ltv_genconfig);
|
|
|
|
sc->areq.an_type = AN_RID_GENCONFIG;
|
2001-12-31 22:01:44 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-12-31 22:01:44 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (config->an_home_product & AN_HOME_NETWORK)
|
|
|
|
ireq->i_val = 4;
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_AUTHMODE:
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_ACTUALCFG;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
|
|
|
|
AN_AUTHTYPE_NONE) {
|
|
|
|
ireq->i_val = IEEE80211_AUTH_NONE;
|
|
|
|
} else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
|
|
|
|
AN_AUTHTYPE_OPEN) {
|
|
|
|
ireq->i_val = IEEE80211_AUTH_OPEN;
|
|
|
|
} else if ((config->an_authtype & AN_AUTHTYPE_MASK) ==
|
|
|
|
AN_AUTHTYPE_SHAREDKEY) {
|
|
|
|
ireq->i_val = IEEE80211_AUTH_SHARED;
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_STATIONNAME:
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_ACTUALCFG;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ireq->i_len = sizeof(config->an_nodename);
|
|
|
|
tmpptr = config->an_nodename;
|
|
|
|
bzero(tmpstr, IEEE80211_NWID_LEN);
|
|
|
|
bcopy(tmpptr, tmpstr, ireq->i_len);
|
|
|
|
error = copyout(tmpstr, ireq->i_data,
|
|
|
|
IEEE80211_NWID_LEN);
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_CHANNEL:
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_STATUS;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ireq->i_val = status->an_cur_channel;
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_POWERSAVE:
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_ACTUALCFG;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-22 23:35:24 +00:00
|
|
|
if (config->an_psave_mode == AN_PSAVE_NONE) {
|
2001-05-26 09:27:08 +00:00
|
|
|
ireq->i_val = IEEE80211_POWERSAVE_OFF;
|
2001-06-22 23:35:24 +00:00
|
|
|
} else if (config->an_psave_mode == AN_PSAVE_CAM) {
|
2001-05-26 09:27:08 +00:00
|
|
|
ireq->i_val = IEEE80211_POWERSAVE_CAM;
|
2001-06-22 23:35:24 +00:00
|
|
|
} else if (config->an_psave_mode == AN_PSAVE_PSP) {
|
2001-05-26 09:27:08 +00:00
|
|
|
ireq->i_val = IEEE80211_POWERSAVE_PSP;
|
2001-06-22 23:35:24 +00:00
|
|
|
} else if (config->an_psave_mode == AN_PSAVE_PSP_CAM) {
|
2001-05-26 09:27:08 +00:00
|
|
|
ireq->i_val = IEEE80211_POWERSAVE_PSP_CAM;
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_POWERSAVESLEEP:
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_ACTUALCFG;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ireq->i_val = config->an_listen_interval;
|
|
|
|
break;
|
2001-09-10 02:36:18 +00:00
|
|
|
}
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
|
|
|
case SIOCS80211:
|
2002-04-01 21:31:13 +00:00
|
|
|
if ((error = suser(td)))
|
2001-05-26 09:27:08 +00:00
|
|
|
goto out;
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = sizeof(sc->areq);
|
2001-05-26 09:27:08 +00:00
|
|
|
/*
|
|
|
|
* We need a config structure for everything but the WEP
|
|
|
|
* key management and SSIDs so we get it now so avoid
|
|
|
|
* duplicating this code every time.
|
|
|
|
*/
|
|
|
|
if (ireq->i_type != IEEE80211_IOC_SSID &&
|
|
|
|
ireq->i_type != IEEE80211_IOC_WEPKEY &&
|
|
|
|
ireq->i_type != IEEE80211_IOC_WEPTXKEY) {
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_GENCONFIG;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
switch (ireq->i_type) {
|
2001-05-26 09:27:08 +00:00
|
|
|
case IEEE80211_IOC_SSID:
|
2003-08-20 03:46:05 +00:00
|
|
|
sc->areq.an_len = sizeof(sc->areq);
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_SSIDLIST;
|
2001-05-26 09:27:08 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-22 23:35:24 +00:00
|
|
|
if (ireq->i_len > IEEE80211_NWID_LEN) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2003-08-20 03:46:05 +00:00
|
|
|
max = (sc->areq.an_len - 4)
|
|
|
|
/ sizeof(struct an_ltv_ssid_entry);
|
|
|
|
if ( max > MAX_SSIDS ) {
|
|
|
|
printf("To many SSIDs only using "
|
|
|
|
"%d of %d\n",
|
|
|
|
MAX_SSIDS, max);
|
|
|
|
max = MAX_SSIDS;
|
|
|
|
}
|
|
|
|
if (ireq->i_val > max) {
|
|
|
|
error = EINVAL;
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
2003-08-20 03:46:05 +00:00
|
|
|
} else {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = copyin(ireq->i_data,
|
2003-08-20 03:46:05 +00:00
|
|
|
ssids->an_entry[ireq->i_val].an_ssid,
|
|
|
|
ireq->i_len);
|
|
|
|
ssids->an_entry[ireq->i_val].an_len
|
|
|
|
= ireq->i_len;
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_WEP:
|
|
|
|
switch (ireq->i_val) {
|
|
|
|
case IEEE80211_WEP_OFF:
|
|
|
|
config->an_authtype &=
|
|
|
|
~(AN_AUTHTYPE_PRIVACY_IN_USE |
|
|
|
|
AN_AUTHTYPE_ALLOW_UNENCRYPTED);
|
|
|
|
break;
|
|
|
|
case IEEE80211_WEP_ON:
|
|
|
|
config->an_authtype |=
|
|
|
|
AN_AUTHTYPE_PRIVACY_IN_USE;
|
|
|
|
config->an_authtype &=
|
|
|
|
~AN_AUTHTYPE_ALLOW_UNENCRYPTED;
|
|
|
|
break;
|
|
|
|
case IEEE80211_WEP_MIXED:
|
|
|
|
config->an_authtype |=
|
|
|
|
AN_AUTHTYPE_PRIVACY_IN_USE |
|
|
|
|
AN_AUTHTYPE_ALLOW_UNENCRYPTED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_WEPKEY:
|
2003-02-08 04:41:17 +00:00
|
|
|
if (ireq->i_val < 0 || ireq->i_val > 8 ||
|
2001-05-26 09:27:08 +00:00
|
|
|
ireq->i_len > 13) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = copyin(ireq->i_data, tmpstr, 13);
|
2001-06-22 23:35:24 +00:00
|
|
|
if (error != 0)
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
2003-02-08 04:41:17 +00:00
|
|
|
/*
|
|
|
|
* Map the 9th key into the home mode
|
|
|
|
* since that is how it is stored on
|
|
|
|
* the card
|
|
|
|
*/
|
2001-12-31 22:12:42 +00:00
|
|
|
bzero(&sc->areq, sizeof(struct an_ltv_key));
|
|
|
|
sc->areq.an_len = sizeof(struct an_ltv_key);
|
2001-05-26 09:27:08 +00:00
|
|
|
key->mac[0] = 1; /* The others are 0. */
|
2003-02-08 04:41:17 +00:00
|
|
|
if (ireq->i_val < 4) {
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_WEP_TEMP;
|
2003-02-08 04:41:17 +00:00
|
|
|
key->kindex = ireq->i_val;
|
|
|
|
} else {
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_type = AN_RID_WEP_PERM;
|
2003-02-08 04:41:17 +00:00
|
|
|
key->kindex = ireq->i_val - 4;
|
|
|
|
}
|
2001-05-26 09:27:08 +00:00
|
|
|
key->klen = ireq->i_len;
|
|
|
|
bcopy(tmpstr, key->key, key->klen);
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_WEPTXKEY:
|
2003-02-08 04:41:17 +00:00
|
|
|
if (ireq->i_val < 0 || ireq->i_val > 4) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-31 22:01:44 +00:00
|
|
|
/*
|
|
|
|
* Map the 5th key into the home mode
|
|
|
|
* since that is how it is stored on
|
|
|
|
* the card
|
|
|
|
*/
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = sizeof(struct an_ltv_genconfig);
|
|
|
|
sc->areq.an_type = AN_RID_ACTUALCFG;
|
2001-12-31 22:01:44 +00:00
|
|
|
if (an_read_record(sc,
|
2001-12-31 22:12:42 +00:00
|
|
|
(struct an_ltv_gen *)&sc->areq)) {
|
2001-12-31 22:01:44 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ireq->i_val == 4) {
|
|
|
|
config->an_home_product |= AN_HOME_NETWORK;
|
|
|
|
ireq->i_val = 0;
|
|
|
|
} else {
|
|
|
|
config->an_home_product &= ~AN_HOME_NETWORK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->an_config.an_home_product
|
|
|
|
= config->an_home_product;
|
2003-02-08 04:41:17 +00:00
|
|
|
|
|
|
|
/* update configuration */
|
|
|
|
an_init(sc);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2001-12-31 22:12:42 +00:00
|
|
|
bzero(&sc->areq, sizeof(struct an_ltv_key));
|
|
|
|
sc->areq.an_len = sizeof(struct an_ltv_key);
|
|
|
|
sc->areq.an_type = AN_RID_WEP_PERM;
|
2001-05-26 09:27:08 +00:00
|
|
|
key->kindex = 0xffff;
|
|
|
|
key->mac[0] = ireq->i_val;
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_AUTHMODE:
|
|
|
|
switch (ireq->i_val) {
|
|
|
|
case IEEE80211_AUTH_NONE:
|
|
|
|
config->an_authtype = AN_AUTHTYPE_NONE |
|
|
|
|
(config->an_authtype & ~AN_AUTHTYPE_MASK);
|
|
|
|
break;
|
|
|
|
case IEEE80211_AUTH_OPEN:
|
|
|
|
config->an_authtype = AN_AUTHTYPE_OPEN |
|
|
|
|
(config->an_authtype & ~AN_AUTHTYPE_MASK);
|
|
|
|
break;
|
|
|
|
case IEEE80211_AUTH_SHARED:
|
|
|
|
config->an_authtype = AN_AUTHTYPE_SHAREDKEY |
|
|
|
|
(config->an_authtype & ~AN_AUTHTYPE_MASK);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_STATIONNAME:
|
2001-06-22 23:35:24 +00:00
|
|
|
if (ireq->i_len > 16) {
|
2001-05-26 09:27:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bzero(config->an_nodename, 16);
|
|
|
|
error = copyin(ireq->i_data,
|
|
|
|
config->an_nodename, ireq->i_len);
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_CHANNEL:
|
|
|
|
/*
|
|
|
|
* The actual range is 1-14, but if you set it
|
|
|
|
* to 0 you get the default so we let that work
|
|
|
|
* too.
|
|
|
|
*/
|
|
|
|
if (ireq->i_val < 0 || ireq->i_val >14) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
config->an_ds_channel = ireq->i_val;
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_POWERSAVE:
|
|
|
|
switch (ireq->i_val) {
|
|
|
|
case IEEE80211_POWERSAVE_OFF:
|
|
|
|
config->an_psave_mode = AN_PSAVE_NONE;
|
|
|
|
break;
|
|
|
|
case IEEE80211_POWERSAVE_CAM:
|
|
|
|
config->an_psave_mode = AN_PSAVE_CAM;
|
|
|
|
break;
|
|
|
|
case IEEE80211_POWERSAVE_PSP:
|
|
|
|
config->an_psave_mode = AN_PSAVE_PSP;
|
|
|
|
break;
|
|
|
|
case IEEE80211_POWERSAVE_PSP_CAM:
|
|
|
|
config->an_psave_mode = AN_PSAVE_PSP_CAM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE80211_IOC_POWERSAVESLEEP:
|
|
|
|
config->an_listen_interval = ireq->i_val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error)
|
2001-12-31 22:12:42 +00:00
|
|
|
an_setdef(sc, &sc->areq);
|
2001-05-26 09:27:08 +00:00
|
|
|
break;
|
2000-01-14 20:41:03 +00:00
|
|
|
default:
|
2002-11-14 23:54:55 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
2000-01-14 20:41:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-06-18 23:40:09 +00:00
|
|
|
out:
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2001-06-22 23:35:24 +00:00
|
|
|
return(error != 0);
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_init_tx_ring(sc)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
if (sc->an_gone)
|
|
|
|
return (0);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!sc->mpi350) {
|
|
|
|
for (i = 0; i < AN_TX_RING_CNT; i++) {
|
|
|
|
if (an_alloc_nicmem(sc, 1518 +
|
|
|
|
0x44, &id))
|
|
|
|
return(ENOMEM);
|
|
|
|
sc->an_rdata.an_tx_fids[i] = id;
|
|
|
|
sc->an_rdata.an_tx_ring[i] = 0;
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->an_rdata.an_tx_prod = 0;
|
|
|
|
sc->an_rdata.an_tx_cons = 0;
|
2002-12-29 19:22:07 +00:00
|
|
|
sc->an_rdata.an_tx_empty = 1;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_init(xsc)
|
2000-01-14 20:41:03 +00:00
|
|
|
void *xsc;
|
|
|
|
{
|
|
|
|
struct an_softc *sc = xsc;
|
|
|
|
struct ifnet *ifp = &sc->arpcom.ac_if;
|
|
|
|
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_LOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2000-10-13 21:58:36 +00:00
|
|
|
if (sc->an_gone) {
|
|
|
|
AN_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_RUNNING)
|
|
|
|
an_stop(sc);
|
|
|
|
|
|
|
|
sc->an_associated = 0;
|
|
|
|
|
|
|
|
/* Allocate the TX buffers */
|
|
|
|
if (an_init_tx_ring(sc)) {
|
|
|
|
an_reset(sc);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->mpi350)
|
|
|
|
an_init_mpi350_desc(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
if (an_init_tx_ring(sc)) {
|
|
|
|
printf("an%d: tx buffer allocation "
|
|
|
|
"failed\n", sc->an_unit);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set our MAC address. */
|
|
|
|
bcopy((char *)&sc->arpcom.ac_enaddr,
|
|
|
|
(char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST)
|
|
|
|
sc->an_config.an_rxmode = AN_RXMODE_BC_ADDR;
|
|
|
|
else
|
|
|
|
sc->an_config.an_rxmode = AN_RXMODE_ADDR;
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_MULTICAST)
|
|
|
|
sc->an_config.an_rxmode = AN_RXMODE_BC_MC_ADDR;
|
|
|
|
|
2001-09-10 02:05:10 +00:00
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
if (sc->an_monitor & AN_MONITOR) {
|
|
|
|
if (sc->an_monitor & AN_MONITOR_ANY_BSS) {
|
|
|
|
sc->an_config.an_rxmode |=
|
|
|
|
AN_RXMODE_80211_MONITOR_ANYBSS |
|
|
|
|
AN_RXMODE_NO_8023_HEADER;
|
|
|
|
} else {
|
|
|
|
sc->an_config.an_rxmode |=
|
|
|
|
AN_RXMODE_80211_MONITOR_CURBSS |
|
|
|
|
AN_RXMODE_NO_8023_HEADER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->an_have_rssimap)
|
|
|
|
sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
/* Set the ssid list */
|
|
|
|
sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
|
2003-08-20 03:46:05 +00:00
|
|
|
sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new);
|
2000-01-14 20:41:03 +00:00
|
|
|
if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
|
|
|
|
printf("an%d: failed to set ssid list\n", sc->an_unit);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the AP list */
|
|
|
|
sc->an_aplist.an_type = AN_RID_APLIST;
|
|
|
|
sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
|
|
|
|
if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
|
|
|
|
printf("an%d: failed to set AP list\n", sc->an_unit);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the configuration in the NIC */
|
|
|
|
sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
|
|
|
|
sc->an_config.an_type = AN_RID_GENCONFIG;
|
|
|
|
if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) {
|
|
|
|
printf("an%d: failed to set configuration\n", sc->an_unit);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable the MAC */
|
|
|
|
if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
|
|
|
|
printf("an%d: failed to enable MAC\n", sc->an_unit);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-23 17:46:32 +00:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
/* enable interrupts */
|
2003-08-20 03:46:05 +00:00
|
|
|
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
sc->an_stat_ch = timeout(an_stats_update, sc, hz);
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_start(ifp)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct an_softc *sc;
|
|
|
|
struct mbuf *m0 = NULL;
|
|
|
|
struct an_txframe_802_3 tx_frame_802_3;
|
|
|
|
struct ether_header *eh;
|
2002-12-29 19:22:07 +00:00
|
|
|
int id, idx, i;
|
2000-01-14 20:41:03 +00:00
|
|
|
unsigned char txcontrol;
|
2002-12-29 19:22:07 +00:00
|
|
|
struct an_card_tx_desc an_tx_desc;
|
|
|
|
u_int8_t *buf;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (sc->an_gone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_OACTIVE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sc->an_associated)
|
|
|
|
return;
|
|
|
|
|
2002-02-20 18:23:59 +00:00
|
|
|
/* We can't send in monitor mode so toss any attempts. */
|
2001-09-10 02:05:10 +00:00
|
|
|
if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
|
2001-09-10 02:36:18 +00:00
|
|
|
for (;;) {
|
2004-08-01 23:58:04 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
|
2001-09-10 02:05:10 +00:00
|
|
|
if (m0 == NULL)
|
|
|
|
break;
|
2002-02-20 18:23:59 +00:00
|
|
|
m_freem(m0);
|
2001-09-10 02:05:10 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
idx = sc->an_rdata.an_tx_prod;
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!sc->mpi350) {
|
|
|
|
bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
|
|
|
|
|
|
|
|
while (sc->an_rdata.an_tx_ring[idx] == 0) {
|
2004-08-01 23:58:04 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (m0 == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
id = sc->an_rdata.an_tx_fids[idx];
|
|
|
|
eh = mtod(m0, struct ether_header *);
|
|
|
|
|
|
|
|
bcopy((char *)&eh->ether_dhost,
|
|
|
|
(char *)&tx_frame_802_3.an_tx_dst_addr,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
bcopy((char *)&eh->ether_shost,
|
|
|
|
(char *)&tx_frame_802_3.an_tx_src_addr,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
/* minus src/dest mac & type */
|
|
|
|
tx_frame_802_3.an_tx_802_3_payload_len =
|
|
|
|
m0->m_pkthdr.len - 12;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
m_copydata(m0, sizeof(struct ether_header) - 2 ,
|
|
|
|
tx_frame_802_3.an_tx_802_3_payload_len,
|
|
|
|
(caddr_t)&sc->an_txbuf);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
txcontrol = AN_TXCTL_8023;
|
|
|
|
/* write the txcontrol only */
|
|
|
|
an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
|
|
|
|
sizeof(txcontrol));
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* 802_3 header */
|
|
|
|
an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
|
|
|
|
sizeof(struct an_txframe_802_3));
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* in mbuf header type is just before payload */
|
|
|
|
an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
|
|
|
|
tx_frame_802_3.an_tx_802_3_payload_len);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/*
|
|
|
|
* If there's a BPF listner, bounce a copy of
|
|
|
|
* this frame to him.
|
|
|
|
*/
|
|
|
|
BPF_MTAP(ifp, m0);
|
|
|
|
|
|
|
|
m_freem(m0);
|
|
|
|
m0 = NULL;
|
|
|
|
|
|
|
|
sc->an_rdata.an_tx_ring[idx] = id;
|
|
|
|
if (an_cmd(sc, AN_CMD_TX, id))
|
|
|
|
printf("an%d: xmit failed\n", sc->an_unit);
|
|
|
|
|
|
|
|
AN_INC(idx, AN_TX_RING_CNT);
|
2003-08-20 03:46:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a timeout in case the chip goes out to lunch.
|
|
|
|
*/
|
|
|
|
ifp->if_timer = 5;
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
|
|
|
} else { /* MPI-350 */
|
2004-06-17 02:19:11 +00:00
|
|
|
/* Disable interrupts. */
|
|
|
|
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
while (sc->an_rdata.an_tx_empty ||
|
|
|
|
idx != sc->an_rdata.an_tx_cons) {
|
2004-08-01 23:58:04 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (m0 == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf = sc->an_tx_buffer[idx].an_dma_vaddr;
|
|
|
|
|
|
|
|
eh = mtod(m0, struct ether_header *);
|
|
|
|
|
|
|
|
/* DJA optimize this to limit bcopy */
|
|
|
|
bcopy((char *)&eh->ether_dhost,
|
|
|
|
(char *)&tx_frame_802_3.an_tx_dst_addr,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
bcopy((char *)&eh->ether_shost,
|
|
|
|
(char *)&tx_frame_802_3.an_tx_src_addr,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
/* minus src/dest mac & type */
|
|
|
|
tx_frame_802_3.an_tx_802_3_payload_len =
|
|
|
|
m0->m_pkthdr.len - 12;
|
|
|
|
|
|
|
|
m_copydata(m0, sizeof(struct ether_header) - 2 ,
|
|
|
|
tx_frame_802_3.an_tx_802_3_payload_len,
|
|
|
|
(caddr_t)&sc->an_txbuf);
|
|
|
|
|
|
|
|
txcontrol = AN_TXCTL_8023;
|
|
|
|
/* write the txcontrol only */
|
|
|
|
bcopy((caddr_t)&txcontrol, &buf[0x08],
|
2000-01-14 20:41:03 +00:00
|
|
|
sizeof(txcontrol));
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* 802_3 header */
|
|
|
|
bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
|
2000-01-14 20:41:03 +00:00
|
|
|
sizeof(struct an_txframe_802_3));
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/* in mbuf header type is just before payload */
|
|
|
|
bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
|
|
|
|
tx_frame_802_3.an_tx_802_3_payload_len);
|
|
|
|
|
|
|
|
|
|
|
|
bzero(&an_tx_desc, sizeof(an_tx_desc));
|
|
|
|
an_tx_desc.an_offset = 0;
|
|
|
|
an_tx_desc.an_eoc = 1;
|
|
|
|
an_tx_desc.an_valid = 1;
|
|
|
|
an_tx_desc.an_len = 0x44 +
|
2003-08-20 03:46:05 +00:00
|
|
|
tx_frame_802_3.an_tx_802_3_payload_len;
|
|
|
|
an_tx_desc.an_phys
|
|
|
|
= sc->an_tx_buffer[idx].an_dma_paddr;
|
|
|
|
for (i = 0; i < sizeof(an_tx_desc) / 4 ; i++) {
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
|
|
|
|
/* zero for now */
|
|
|
|
+ (0 * sizeof(an_tx_desc))
|
|
|
|
+ (i * 4),
|
|
|
|
((u_int32_t*)&an_tx_desc)[i]);
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
/*
|
|
|
|
* If there's a BPF listner, bounce a copy of
|
|
|
|
* this frame to him.
|
|
|
|
*/
|
|
|
|
BPF_MTAP(ifp, m0);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
m_freem(m0);
|
|
|
|
m0 = NULL;
|
|
|
|
AN_INC(idx, AN_MAX_TX_DESC);
|
|
|
|
sc->an_rdata.an_tx_empty = 0;
|
2003-08-20 03:46:05 +00:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a timeout in case the chip goes out to lunch.
|
|
|
|
*/
|
|
|
|
ifp->if_timer = 5;
|
2002-12-29 19:22:07 +00:00
|
|
|
}
|
2004-06-17 02:19:11 +00:00
|
|
|
|
|
|
|
/* Re-enable interrupts. */
|
|
|
|
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS(sc->mpi350));
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m0 != NULL)
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
sc->an_rdata.an_tx_prod = idx;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
void
|
|
|
|
an_stop(sc)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int i;
|
|
|
|
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_LOCK(sc);
|
|
|
|
|
|
|
|
if (sc->an_gone) {
|
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
2000-10-13 21:58:36 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
|
|
|
an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
|
2000-01-14 20:41:03 +00:00
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < AN_TX_RING_CNT; i++)
|
|
|
|
an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
|
|
|
|
|
|
|
|
untimeout(an_stats_update, sc, sc->an_stat_ch);
|
|
|
|
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->an_flash_buffer) {
|
|
|
|
free(sc->an_flash_buffer, M_DEVBUF);
|
|
|
|
sc->an_flash_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_watchdog(ifp)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct an_softc *sc;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_LOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2000-10-13 21:58:36 +00:00
|
|
|
if (sc->an_gone) {
|
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
2000-10-13 21:58:36 +00:00
|
|
|
}
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
printf("an%d: device timeout\n", sc->an_unit);
|
|
|
|
|
|
|
|
an_reset(sc);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->mpi350)
|
|
|
|
an_init_mpi350_desc(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
an_init(sc);
|
|
|
|
|
|
|
|
ifp->if_oerrors++;
|
2000-10-13 21:58:36 +00:00
|
|
|
AN_UNLOCK(sc);
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
void
|
|
|
|
an_shutdown(dev)
|
2000-01-14 20:41:03 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct an_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
an_stop(sc);
|
2003-02-08 04:41:17 +00:00
|
|
|
sc->an_gone = 1;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-05 03:37:42 +00:00
|
|
|
void
|
|
|
|
an_resume(dev)
|
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct an_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
2003-02-08 04:41:17 +00:00
|
|
|
int i;
|
|
|
|
|
2003-02-05 03:37:42 +00:00
|
|
|
sc = device_get_softc(dev);
|
2003-02-08 04:41:17 +00:00
|
|
|
AN_LOCK(sc);
|
2003-02-05 03:37:42 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
2003-02-08 04:41:17 +00:00
|
|
|
sc->an_gone = 0;
|
2003-02-05 03:37:42 +00:00
|
|
|
an_reset(sc);
|
|
|
|
if (sc->mpi350)
|
|
|
|
an_init_mpi350_desc(sc);
|
|
|
|
an_init(sc);
|
|
|
|
|
2003-02-08 04:41:17 +00:00
|
|
|
/* Recovery temporary keys */
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
sc->areq.an_type = AN_RID_WEP_TEMP;
|
|
|
|
sc->areq.an_len = sizeof(struct an_ltv_key);
|
|
|
|
bcopy(&sc->an_temp_keys[i],
|
|
|
|
&sc->areq, sizeof(struct an_ltv_key));
|
|
|
|
an_setdef(sc, &sc->areq);
|
|
|
|
}
|
|
|
|
|
2003-02-05 03:37:42 +00:00
|
|
|
if (ifp->if_flags & IFF_UP)
|
|
|
|
an_start(ifp);
|
2003-02-08 04:41:17 +00:00
|
|
|
AN_UNLOCK(sc);
|
2003-02-05 03:37:42 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-14 20:41:03 +00:00
|
|
|
#ifdef ANCACHE
|
|
|
|
/* Aironet signal strength cache code.
|
|
|
|
* store signal/noise/quality on per MAC src basis in
|
|
|
|
* a small fixed cache. The cache wraps if > MAX slots
|
|
|
|
* used. The cache may be zeroed out to start over.
|
|
|
|
* Two simple filters exist to reduce computation:
|
2001-12-31 22:01:44 +00:00
|
|
|
* 1. ip only (literally 0x800, ETHERTYPE_IP) which may be used
|
2000-01-14 20:41:03 +00:00
|
|
|
* to ignore some packets. It defaults to ip only.
|
|
|
|
* it could be used to focus on broadcast, non-IP 802.11 beacons.
|
|
|
|
* 2. multicast/broadcast only. This may be used to
|
|
|
|
* ignore unicast packets and only cache signal strength
|
|
|
|
* for multicast/broadcast packets (beacons); e.g., Mobile-IP
|
|
|
|
* beacons and not unicast traffic.
|
|
|
|
*
|
|
|
|
* The cache stores (MAC src(index), IP src (major clue), signal,
|
|
|
|
* quality, noise)
|
|
|
|
*
|
|
|
|
* No apologies for storing IP src here. It's easy and saves much
|
2001-09-10 02:36:18 +00:00
|
|
|
* trouble elsewhere. The cache is assumed to be INET dependent,
|
2000-01-14 20:41:03 +00:00
|
|
|
* although it need not be.
|
|
|
|
*
|
|
|
|
* Note: the Aironet only has a single byte of signal strength value
|
|
|
|
* in the rx frame header, and it's not scaled to anything sensible.
|
|
|
|
* This is kind of lame, but it's all we've got.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef documentation
|
|
|
|
|
|
|
|
int an_sigitems; /* number of cached entries */
|
|
|
|
struct an_sigcache an_sigcache[MAXANCACHE]; /* array of cache entries */
|
|
|
|
int an_nextitem; /* index/# of entries */
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* control variables for cache filtering. Basic idea is
|
|
|
|
* to reduce cost (e.g., to only Mobile-IP agent beacons
|
|
|
|
* which are broadcast or multicast). Still you might
|
|
|
|
* want to measure signal strength anth unicast ping packets
|
|
|
|
* on a pt. to pt. ant. setup.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
/* set true if you want to limit cache items to broadcast/mcast
|
2000-01-14 20:41:03 +00:00
|
|
|
* only packets (not unicast). Useful for mobile-ip beacons which
|
|
|
|
* are broadcast/multicast at network layer. Default is all packets
|
|
|
|
* so ping/unicast anll work say anth pt. to pt. antennae setup.
|
|
|
|
*/
|
|
|
|
static int an_cache_mcastonly = 0;
|
2003-02-08 04:41:17 +00:00
|
|
|
SYSCTL_INT(_hw_an, OID_AUTO, an_cache_mcastonly, CTLFLAG_RW,
|
2000-01-14 20:41:03 +00:00
|
|
|
&an_cache_mcastonly, 0, "");
|
|
|
|
|
|
|
|
/* set true if you want to limit cache items to IP packets only
|
|
|
|
*/
|
|
|
|
static int an_cache_iponly = 1;
|
2003-02-08 04:41:17 +00:00
|
|
|
SYSCTL_INT(_hw_an, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
|
2000-01-14 20:41:03 +00:00
|
|
|
&an_cache_iponly, 0, "");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* an_cache_store, per rx packet store signal
|
|
|
|
* strength in MAC (src) indexed cache.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
2002-12-29 19:22:07 +00:00
|
|
|
an_cache_store (sc, eh, m, rx_rssi, rx_quality)
|
2000-01-14 20:41:03 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
struct ether_header *eh;
|
|
|
|
struct mbuf *m;
|
2002-12-29 19:22:07 +00:00
|
|
|
u_int8_t rx_rssi;
|
|
|
|
u_int8_t rx_quality;
|
2000-01-14 20:41:03 +00:00
|
|
|
{
|
2001-09-10 02:36:18 +00:00
|
|
|
struct ip *ip = 0;
|
2000-01-14 20:41:03 +00:00
|
|
|
int i;
|
|
|
|
static int cache_slot = 0; /* use this cache entry */
|
|
|
|
static int wrapindex = 0; /* next "free" cache entry */
|
2001-12-31 22:01:44 +00:00
|
|
|
int type_ipv4 = 0;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
/* filters:
|
|
|
|
* 1. ip only
|
|
|
|
* 2. configurable filter to throw out unicast packets,
|
|
|
|
* keep multicast only.
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
|
2001-12-31 22:01:44 +00:00
|
|
|
if ((ntohs(eh->ether_type) == ETHERTYPE_IP)) {
|
|
|
|
type_ipv4 = 1;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
/* filter for ip packets only
|
2000-01-14 20:41:03 +00:00
|
|
|
*/
|
2001-12-31 22:01:44 +00:00
|
|
|
if ( an_cache_iponly && !type_ipv4) {
|
2000-01-14 20:41:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* filter for broadcast/multicast only
|
|
|
|
*/
|
|
|
|
if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SIGDEBUG
|
|
|
|
printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
|
2002-12-29 19:22:07 +00:00
|
|
|
rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
|
2000-01-14 20:41:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* find the ip header. we want to store the ip_src
|
2001-09-10 02:36:18 +00:00
|
|
|
* address.
|
2000-01-14 20:41:03 +00:00
|
|
|
*/
|
2001-12-31 22:01:44 +00:00
|
|
|
if (type_ipv4) {
|
2000-01-14 20:41:03 +00:00
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
}
|
2001-09-10 02:36:18 +00:00
|
|
|
|
|
|
|
/* do a linear search for a matching MAC address
|
2000-01-14 20:41:03 +00:00
|
|
|
* in the cache table
|
|
|
|
* . MAC address is 6 bytes,
|
|
|
|
* . var w_nextitem holds total number of entries already cached
|
|
|
|
*/
|
2001-06-22 23:35:24 +00:00
|
|
|
for (i = 0; i < sc->an_nextitem; i++) {
|
2000-01-14 20:41:03 +00:00
|
|
|
if (! bcmp(eh->ether_shost , sc->an_sigcache[i].macsrc, 6 )) {
|
|
|
|
/* Match!,
|
|
|
|
* so we already have this entry,
|
|
|
|
* update the data
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
break;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* did we find a matching mac address?
|
|
|
|
* if yes, then overwrite a previously existing cache entry
|
|
|
|
*/
|
|
|
|
if (i < sc->an_nextitem ) {
|
2001-09-10 02:36:18 +00:00
|
|
|
cache_slot = i;
|
2000-01-14 20:41:03 +00:00
|
|
|
}
|
|
|
|
/* else, have a new address entry,so
|
|
|
|
* add this new entry,
|
|
|
|
* if table full, then we need to replace LRU entry
|
|
|
|
*/
|
2001-09-10 02:36:18 +00:00
|
|
|
else {
|
2000-01-14 20:41:03 +00:00
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
/* check for space in cache table
|
2000-01-14 20:41:03 +00:00
|
|
|
* note: an_nextitem also holds number of entries
|
2001-09-10 02:36:18 +00:00
|
|
|
* added in the cache table
|
2000-01-14 20:41:03 +00:00
|
|
|
*/
|
|
|
|
if ( sc->an_nextitem < MAXANCACHE ) {
|
|
|
|
cache_slot = sc->an_nextitem;
|
2001-09-10 02:36:18 +00:00
|
|
|
sc->an_nextitem++;
|
2000-01-14 20:41:03 +00:00
|
|
|
sc->an_sigitems = sc->an_nextitem;
|
|
|
|
}
|
|
|
|
/* no space found, so simply wrap anth wrap index
|
|
|
|
* and "zap" the next entry
|
|
|
|
*/
|
|
|
|
else {
|
|
|
|
if (wrapindex == MAXANCACHE) {
|
|
|
|
wrapindex = 0;
|
|
|
|
}
|
|
|
|
cache_slot = wrapindex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* invariant: cache_slot now points at some slot
|
|
|
|
* in cache.
|
|
|
|
*/
|
|
|
|
if (cache_slot < 0 || cache_slot >= MAXANCACHE) {
|
|
|
|
log(LOG_ERR, "an_cache_store, bad index: %d of "
|
|
|
|
"[0..%d], gross cache error\n",
|
|
|
|
cache_slot, MAXANCACHE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store items in cache
|
|
|
|
* .ip source address
|
|
|
|
* .mac src
|
|
|
|
* .signal, etc.
|
|
|
|
*/
|
2001-12-31 22:01:44 +00:00
|
|
|
if (type_ipv4) {
|
2000-01-14 20:41:03 +00:00
|
|
|
sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
|
|
|
|
}
|
|
|
|
bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
|
|
|
|
switch (an_cache_mode) {
|
|
|
|
case DBM:
|
|
|
|
if (sc->an_have_rssimap) {
|
|
|
|
sc->an_sigcache[cache_slot].signal =
|
|
|
|
- sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
|
|
|
|
sc->an_sigcache[cache_slot].quality =
|
|
|
|
- sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
|
|
|
|
} else {
|
|
|
|
sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
|
|
|
|
sc->an_sigcache[cache_slot].quality = rx_quality - 100;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PERCENT:
|
|
|
|
if (sc->an_have_rssimap) {
|
|
|
|
sc->an_sigcache[cache_slot].signal =
|
|
|
|
sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
|
|
|
|
sc->an_sigcache[cache_slot].quality =
|
|
|
|
sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
|
|
|
|
} else {
|
|
|
|
if (rx_rssi > 100)
|
|
|
|
rx_rssi = 100;
|
|
|
|
if (rx_quality > 100)
|
|
|
|
rx_quality = 100;
|
|
|
|
sc->an_sigcache[cache_slot].signal = rx_rssi;
|
|
|
|
sc->an_sigcache[cache_slot].quality = rx_quality;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RAW:
|
|
|
|
sc->an_sigcache[cache_slot].signal = rx_rssi;
|
|
|
|
sc->an_sigcache[cache_slot].quality = rx_quality;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->an_sigcache[cache_slot].noise = 0;
|
2000-01-14 20:41:03 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2001-05-26 09:27:08 +00:00
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static int
|
|
|
|
an_media_change(ifp)
|
2001-05-26 09:27:08 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
2003-02-02 22:49:31 +00:00
|
|
|
struct an_ltv_genconfig *cfg;
|
2001-05-26 09:27:08 +00:00
|
|
|
int otype = sc->an_config.an_opmode;
|
|
|
|
int orate = sc->an_tx_rate;
|
|
|
|
|
2003-06-28 06:17:26 +00:00
|
|
|
sc->an_tx_rate = ieee80211_media2rate(
|
|
|
|
IFM_SUBTYPE(sc->an_ifmedia.ifm_cur->ifm_media));
|
2003-08-20 03:46:05 +00:00
|
|
|
if (sc->an_tx_rate < 0)
|
|
|
|
sc->an_tx_rate = 0;
|
2003-02-02 22:49:31 +00:00
|
|
|
|
|
|
|
if (orate != sc->an_tx_rate) {
|
|
|
|
/* Read the current configuration */
|
|
|
|
sc->an_config.an_type = AN_RID_GENCONFIG;
|
|
|
|
sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
|
|
|
|
an_read_record(sc, (struct an_ltv_gen *)&sc->an_config);
|
|
|
|
cfg = &sc->an_config;
|
|
|
|
|
|
|
|
/* clear other rates and set the only one we want */
|
|
|
|
bzero(cfg->an_rates, sizeof(cfg->an_rates));
|
|
|
|
cfg->an_rates[0] = sc->an_tx_rate;
|
|
|
|
|
|
|
|
/* Save the new rate */
|
|
|
|
sc->an_config.an_type = AN_RID_GENCONFIG;
|
|
|
|
sc->an_config.an_len = sizeof(struct an_ltv_genconfig);
|
2001-05-26 09:27:08 +00:00
|
|
|
}
|
|
|
|
|
2003-08-20 03:46:05 +00:00
|
|
|
if ((sc->an_ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_ADHOC) != 0)
|
|
|
|
sc->an_config.an_opmode &= ~AN_OPMODE_INFRASTRUCTURE_STATION;
|
|
|
|
else
|
|
|
|
sc->an_config.an_opmode |= AN_OPMODE_INFRASTRUCTURE_STATION;
|
|
|
|
|
2003-02-08 04:41:17 +00:00
|
|
|
if (otype != sc->an_config.an_opmode ||
|
|
|
|
orate != sc->an_tx_rate)
|
2001-05-26 09:27:08 +00:00
|
|
|
an_init(sc);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2001-09-10 02:36:18 +00:00
|
|
|
static void
|
|
|
|
an_media_status(ifp, imr)
|
2001-05-26 09:27:08 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmediareq *imr;
|
|
|
|
{
|
|
|
|
struct an_ltv_status status;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
2003-02-02 22:49:31 +00:00
|
|
|
imr->ifm_active = IFM_IEEE80211;
|
|
|
|
|
2001-05-26 09:27:08 +00:00
|
|
|
status.an_len = sizeof(status);
|
|
|
|
status.an_type = AN_RID_STATUS;
|
|
|
|
if (an_read_record(sc, (struct an_ltv_gen *)&status)) {
|
|
|
|
/* If the status read fails, just lie. */
|
|
|
|
imr->ifm_active = sc->an_ifmedia.ifm_cur->ifm_media;
|
|
|
|
imr->ifm_status = IFM_AVALID|IFM_ACTIVE;
|
|
|
|
}
|
|
|
|
|
2001-06-22 23:35:24 +00:00
|
|
|
if (sc->an_tx_rate == 0) {
|
2001-05-26 09:27:08 +00:00
|
|
|
imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
|
|
|
|
}
|
|
|
|
|
2003-02-02 22:49:31 +00:00
|
|
|
if (sc->an_config.an_opmode == AN_OPMODE_IBSS_ADHOC)
|
|
|
|
imr->ifm_active |= IFM_IEEE80211_ADHOC;
|
2003-06-28 06:17:26 +00:00
|
|
|
imr->ifm_active |= ieee80211_rate2media(NULL,
|
|
|
|
status.an_current_tx_rate, IEEE80211_T_DS);
|
2001-05-26 09:27:08 +00:00
|
|
|
imr->ifm_status = IFM_AVALID;
|
2002-02-26 05:43:05 +00:00
|
|
|
if (status.an_opmode & AN_STATUS_OPMODE_ASSOCIATED)
|
2001-05-26 09:27:08 +00:00
|
|
|
imr->ifm_status |= IFM_ACTIVE;
|
|
|
|
}
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
/********************** Cisco utility support routines *************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ReadRids & WriteRids derived from Cisco driver additions to Ben Reed's
|
|
|
|
* Linux driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
readrids(ifp, l_ioctl)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct aironet_ioctl *l_ioctl;
|
|
|
|
{
|
2001-12-31 22:12:42 +00:00
|
|
|
unsigned short rid;
|
2001-12-31 22:01:44 +00:00
|
|
|
struct an_softc *sc;
|
|
|
|
|
|
|
|
switch (l_ioctl->command) {
|
|
|
|
case AIROGCAP:
|
|
|
|
rid = AN_RID_CAPABILITIES;
|
|
|
|
break;
|
|
|
|
case AIROGCFG:
|
|
|
|
rid = AN_RID_GENCONFIG;
|
|
|
|
break;
|
|
|
|
case AIROGSLIST:
|
|
|
|
rid = AN_RID_SSIDLIST;
|
|
|
|
break;
|
|
|
|
case AIROGVLIST:
|
|
|
|
rid = AN_RID_APLIST;
|
|
|
|
break;
|
|
|
|
case AIROGDRVNAM:
|
|
|
|
rid = AN_RID_DRVNAME;
|
|
|
|
break;
|
|
|
|
case AIROGEHTENC:
|
|
|
|
rid = AN_RID_ENCAPPROTO;
|
|
|
|
break;
|
|
|
|
case AIROGWEPKTMP:
|
|
|
|
rid = AN_RID_WEP_TEMP;
|
|
|
|
break;
|
|
|
|
case AIROGWEPKNV:
|
|
|
|
rid = AN_RID_WEP_PERM;
|
|
|
|
break;
|
|
|
|
case AIROGSTAT:
|
|
|
|
rid = AN_RID_STATUS;
|
|
|
|
break;
|
|
|
|
case AIROGSTATSD32:
|
|
|
|
rid = AN_RID_32BITS_DELTA;
|
|
|
|
break;
|
|
|
|
case AIROGSTATSC32:
|
|
|
|
rid = AN_RID_32BITS_CUM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rid = 999;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rid == 999) /* Is bad command */
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = AN_MAX_DATALEN;
|
|
|
|
sc->areq.an_type = rid;
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2001-12-31 22:12:42 +00:00
|
|
|
an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2001-12-31 22:12:42 +00:00
|
|
|
l_ioctl->len = sc->areq.an_len - 4; /* just data */
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
/* the data contains the length at first */
|
2001-12-31 22:12:42 +00:00
|
|
|
if (copyout(&(sc->areq.an_len), l_ioctl->data,
|
|
|
|
sizeof(sc->areq.an_len))) {
|
2001-12-31 22:01:44 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
/* Just copy the data back */
|
2001-12-31 22:12:42 +00:00
|
|
|
if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
|
2001-12-31 22:01:44 +00:00
|
|
|
l_ioctl->len)) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
writerids(ifp, l_ioctl)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct aironet_ioctl *l_ioctl;
|
|
|
|
{
|
|
|
|
struct an_softc *sc;
|
|
|
|
int rid, command;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
rid = 0;
|
|
|
|
command = l_ioctl->command;
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case AIROPSIDS:
|
|
|
|
rid = AN_RID_SSIDLIST;
|
|
|
|
break;
|
|
|
|
case AIROPCAP:
|
|
|
|
rid = AN_RID_CAPABILITIES;
|
|
|
|
break;
|
|
|
|
case AIROPAPLIST:
|
|
|
|
rid = AN_RID_APLIST;
|
|
|
|
break;
|
|
|
|
case AIROPCFG:
|
|
|
|
rid = AN_RID_GENCONFIG;
|
|
|
|
break;
|
|
|
|
case AIROPMACON:
|
|
|
|
an_cmd(sc, AN_CMD_ENABLE, 0);
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case AIROPMACOFF:
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case AIROPSTCLR:
|
|
|
|
/*
|
|
|
|
* This command merely clears the counts does not actually
|
|
|
|
* store any data only reads rid. But as it changes the cards
|
|
|
|
* state, I put it in the writerid routines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
rid = AN_RID_32BITS_DELTACLR;
|
|
|
|
sc = ifp->if_softc;
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = AN_MAX_DATALEN;
|
|
|
|
sc->areq.an_type = rid;
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2001-12-31 22:12:42 +00:00
|
|
|
an_read_record(sc, (struct an_ltv_gen *)&sc->areq);
|
|
|
|
l_ioctl->len = sc->areq.an_len - 4; /* just data */
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
/* the data contains the length at first */
|
2001-12-31 22:12:42 +00:00
|
|
|
if (copyout(&(sc->areq.an_len), l_ioctl->data,
|
|
|
|
sizeof(sc->areq.an_len))) {
|
2001-12-31 22:01:44 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
/* Just copy the data */
|
2001-12-31 22:12:42 +00:00
|
|
|
if (copyout(&(sc->areq.an_val), l_ioctl->data + 2,
|
2001-12-31 22:01:44 +00:00
|
|
|
l_ioctl->len)) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case AIROPWEPKEY:
|
|
|
|
rid = AN_RID_WEP_TEMP;
|
|
|
|
break;
|
|
|
|
case AIROPWEPKEYNV:
|
|
|
|
rid = AN_RID_WEP_PERM;
|
|
|
|
break;
|
|
|
|
case AIROPLEAPUSR:
|
|
|
|
rid = AN_RID_LEAPUSERNAME;
|
|
|
|
break;
|
|
|
|
case AIROPLEAPPWD:
|
|
|
|
rid = AN_RID_LEAPPASSWORD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rid) {
|
2001-12-31 22:12:42 +00:00
|
|
|
if (l_ioctl->len > sizeof(sc->areq.an_val) + 4)
|
2001-12-31 22:01:44 +00:00
|
|
|
return -EINVAL;
|
2001-12-31 22:12:42 +00:00
|
|
|
sc->areq.an_len = l_ioctl->len + 4; /* add type & length */
|
|
|
|
sc->areq.an_type = rid;
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
/* Just copy the data back */
|
2001-12-31 22:12:42 +00:00
|
|
|
copyin((l_ioctl->data) + 2, &sc->areq.an_val,
|
2001-12-31 22:01:44 +00:00
|
|
|
l_ioctl->len);
|
|
|
|
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
2001-12-31 22:12:42 +00:00
|
|
|
an_write_record(sc, (struct an_ltv_gen *)&sc->areq);
|
2001-12-31 22:01:44 +00:00
|
|
|
an_cmd(sc, AN_CMD_ENABLE, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General Flash utilities derived from Cisco driver additions to Ben Reed's
|
|
|
|
* Linux driver
|
|
|
|
*/
|
|
|
|
|
2003-12-30 01:07:12 +00:00
|
|
|
#define FLASH_DELAY(_sc, x) msleep(ifp, &(_sc)->an_mtx, PZERO, \
|
|
|
|
"flash", ((x) / hz) + 1);
|
2002-12-29 19:22:07 +00:00
|
|
|
#define FLASH_COMMAND 0x7e7e
|
|
|
|
#define FLASH_SIZE 32 * 1024
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
unstickbusy(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
|
|
|
|
AN_EV_CLR_STUCK_BUSY);
|
2001-12-31 22:01:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for busy completion from card wait for delay uSec's Return true for
|
|
|
|
* success meaning command reg is clear
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
WaitBusy(ifp, uSec)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int uSec;
|
|
|
|
{
|
|
|
|
int statword = 0xffff;
|
|
|
|
int delay = 0;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 10);
|
2001-12-31 22:01:44 +00:00
|
|
|
delay += 10;
|
2002-12-29 19:22:07 +00:00
|
|
|
statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
if ((AN_CMD_BUSY & statword) && (delay % 200)) {
|
|
|
|
unstickbusy(ifp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0 == (AN_CMD_BUSY & statword);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STEP 1) Disable MAC and do soft reset on card.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
cmdreset(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
an_stop(sc);
|
|
|
|
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
|
2001-12-31 22:01:44 +00:00
|
|
|
printf("an%d: Waitbusy hang b4 RESET =%d\n",
|
|
|
|
sc->an_unit, status);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 1000); /* WAS 600 12/7/00 */
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!(status = WaitBusy(ifp, 100))) {
|
|
|
|
printf("an%d: Waitbusy hang AFTER RESET =%d\n",
|
|
|
|
sc->an_unit, status);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STEP 2) Put the card in legendary flash mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
setflashmode(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
|
|
|
|
CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
|
|
|
|
CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
|
|
|
|
CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mdelay(500); // 500ms delay
|
|
|
|
*/
|
|
|
|
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 500);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
|
2001-12-31 22:01:44 +00:00
|
|
|
printf("Waitbusy hang after setflash mode\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a character from the card matching matchbyte Step 3)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
flashgchar(ifp, matchbyte, dwelltime)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int matchbyte;
|
|
|
|
int dwelltime;
|
|
|
|
{
|
|
|
|
int rchar;
|
|
|
|
unsigned char rbyte = 0;
|
|
|
|
int success = -1;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
2002-12-29 19:22:07 +00:00
|
|
|
rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
if (dwelltime && !(0x8000 & rchar)) {
|
|
|
|
dwelltime -= 10;
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 10);
|
2001-12-31 22:01:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rbyte = 0xff & rchar;
|
|
|
|
|
|
|
|
if ((rbyte == matchbyte) && (0x8000 & rchar)) {
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
|
2001-12-31 22:01:44 +00:00
|
|
|
success = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
|
|
|
|
break;
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
} while (dwelltime > 0);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put character to SWS0 wait for dwelltime x 50us for echo .
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
flashpchar(ifp, byte, dwelltime)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int byte;
|
|
|
|
int dwelltime;
|
|
|
|
{
|
|
|
|
int echo;
|
|
|
|
int pollbusy, waittime;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
byte |= 0x8000;
|
|
|
|
|
|
|
|
if (dwelltime == 0)
|
|
|
|
dwelltime = 200;
|
|
|
|
|
|
|
|
waittime = dwelltime;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for busy bit d15 to go false indicating buffer empty
|
|
|
|
*/
|
|
|
|
do {
|
2002-12-29 19:22:07 +00:00
|
|
|
pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
if (pollbusy & 0x8000) {
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 50);
|
2001-12-31 22:01:44 +00:00
|
|
|
waittime -= 50;
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (waittime >= 0);
|
|
|
|
|
|
|
|
/* timeout for busy clear wait */
|
|
|
|
|
|
|
|
if (waittime <= 0) {
|
|
|
|
printf("an%d: flash putchar busywait timeout! \n",
|
|
|
|
sc->an_unit);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Port is clear now write byte and wait for it to echo back
|
|
|
|
*/
|
|
|
|
do {
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 50);
|
2001-12-31 22:01:44 +00:00
|
|
|
dwelltime -= 50;
|
2002-12-29 19:22:07 +00:00
|
|
|
echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
|
2001-12-31 22:01:44 +00:00
|
|
|
} while (dwelltime >= 0 && echo != byte);
|
|
|
|
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
return echo == byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer 32k of firmware data from user buffer to our buffer and send to
|
|
|
|
* the card
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
flashputbuf(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
unsigned short *bufp;
|
|
|
|
int nwords;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
/* Write stuff */
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
bufp = sc->an_flash_buffer;
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
if (!sc->mpi350) {
|
|
|
|
CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
|
|
|
|
CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
|
|
|
|
CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
|
|
|
|
CSR_MEM_AUX_WRITE_4(sc, 0x8000,
|
|
|
|
((u_int32_t *)bufp)[nwords] & 0xffff);
|
|
|
|
}
|
2001-12-31 22:01:44 +00:00
|
|
|
}
|
|
|
|
|
2002-12-29 19:22:07 +00:00
|
|
|
CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* After flashing restart the card.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
flashrestart(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
an_init(sc);
|
|
|
|
|
2003-08-20 05:52:48 +00:00
|
|
|
FLASH_DELAY(sc, 1024); /* Added 12/7/00 */
|
2001-12-31 22:01:44 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Entry point for flash ioclt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
flashcard(ifp, l_ioctl)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct aironet_ioctl *l_ioctl;
|
|
|
|
{
|
|
|
|
int z = 0, status;
|
2001-12-31 22:12:42 +00:00
|
|
|
struct an_softc *sc;
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->mpi350) {
|
|
|
|
printf("an%d: flashing not supported on MPI 350 yet\n",
|
|
|
|
sc->an_unit);
|
|
|
|
return(-1);
|
|
|
|
}
|
2001-12-31 22:01:44 +00:00
|
|
|
status = l_ioctl->command;
|
|
|
|
|
|
|
|
switch (l_ioctl->command) {
|
|
|
|
case AIROFLSHRST:
|
|
|
|
return cmdreset(ifp);
|
|
|
|
break;
|
|
|
|
case AIROFLSHSTFL:
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->an_flash_buffer) {
|
|
|
|
free(sc->an_flash_buffer, M_DEVBUF);
|
|
|
|
sc->an_flash_buffer = NULL;
|
|
|
|
}
|
2003-02-19 05:47:46 +00:00
|
|
|
sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
|
2002-12-29 19:22:07 +00:00
|
|
|
if (sc->an_flash_buffer)
|
|
|
|
return setflashmode(ifp);
|
|
|
|
else
|
|
|
|
return ENOBUFS;
|
2001-12-31 22:01:44 +00:00
|
|
|
break;
|
|
|
|
case AIROFLSHGCHR: /* Get char from aux */
|
2001-12-31 22:12:42 +00:00
|
|
|
copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
|
|
|
|
z = *(int *)&sc->areq;
|
2001-12-31 22:01:44 +00:00
|
|
|
if ((status = flashgchar(ifp, z, 8000)) == 1)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case AIROFLSHPCHR: /* Send char to card. */
|
2001-12-31 22:12:42 +00:00
|
|
|
copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
|
|
|
|
z = *(int *)&sc->areq;
|
2001-12-31 22:01:44 +00:00
|
|
|
if ((status = flashpchar(ifp, z, 8000)) == -1)
|
|
|
|
return -EIO;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case AIROFLPUTBUF: /* Send 32k to card */
|
2002-12-29 19:22:07 +00:00
|
|
|
if (l_ioctl->len > FLASH_SIZE) {
|
|
|
|
printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
|
|
|
|
l_ioctl->len, FLASH_SIZE);
|
2001-12-31 22:01:44 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2002-12-29 19:22:07 +00:00
|
|
|
copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
|
2001-12-31 22:01:44 +00:00
|
|
|
|
|
|
|
if ((status = flashputbuf(ifp)) != 0)
|
|
|
|
return -EIO;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case AIRORESTART:
|
|
|
|
if ((status = flashrestart(ifp)) != 0) {
|
|
|
|
printf("an%d: FLASHRESTART returned %d\n",
|
|
|
|
sc->an_unit, status);
|
|
|
|
return -EIO;
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|