split if_wi

This commit is contained in:
christos 2010-11-23 04:33:09 +00:00
parent a69630cac3
commit d50ed4470e
4 changed files with 136 additions and 137 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wi.c,v 1.233 2010/04/05 07:19:37 joerg Exp $ */
/* $NetBSD: wi.c,v 1.234 2010/11/23 04:33:09 christos Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@ -99,7 +99,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.233 2010/04/05 07:19:37 joerg Exp $");
__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.234 2010/11/23 04:33:09 christos Exp $");
#define WI_HERMES_AUTOINC_WAR /* Work around data write autoinc bug. */
#define WI_HERMES_STATS_WAR /* Work around stats counter bug. */
@ -405,7 +405,7 @@ wi_attach(struct wi_softc *sc, const u_int8_t *macaddr)
/* Read NIC identification */
wi_read_nicid(sc);
memcpy(ifp->if_xname, device_xname(&sc->sc_dev), IFNAMSIZ);
memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
ifp->if_softc = sc;
ifp->if_start = wi_start;
ifp->if_ioctl = wi_ioctl;
@ -426,7 +426,7 @@ wi_attach(struct wi_softc *sc, const u_int8_t *macaddr)
/* Find available channel */
if (wi_read_xrid(sc, WI_RID_CHANNEL_LIST, &chanavail,
sizeof(chanavail)) != 0) {
aprint_normal_dev(&sc->sc_dev, "using default channel list\n");
aprint_normal_dev(sc->sc_dev, "using default channel list\n");
chanavail = htole16(0x1fff); /* assume 1-13 */
}
for (chan = 16; chan > 0; chan--) {
@ -445,7 +445,7 @@ wi_attach(struct wi_softc *sc, const u_int8_t *macaddr)
ic->ic_ibss_chan = &ic->ic_channels[chan];
}
if (ic->ic_ibss_chan == NULL) {
aprint_error_dev(&sc->sc_dev, "no available channel\n");
aprint_error_dev(sc->sc_dev, "no available channel\n");
return 1;
}
@ -526,7 +526,7 @@ wi_attach(struct wi_softc *sc, const u_int8_t *macaddr)
&ratebuf.rates[0], nrate);
ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates = nrate;
} else {
aprint_error_dev(&sc->sc_dev, "no supported rate list\n");
aprint_error_dev(sc->sc_dev, "no supported rate list\n");
return 1;
}
@ -621,7 +621,7 @@ wi_intr(void *arg)
u_int16_t status;
if (sc->sc_enabled == 0 ||
!device_is_active(&sc->sc_dev) ||
!device_is_active(sc->sc_dev) ||
(ifp->if_flags & IFF_RUNNING) == 0)
return 0;
@ -730,7 +730,7 @@ wi_init(struct ifnet *ifp)
DPRINTF(("wi_init: enabled %d\n", sc->sc_enabled));
wasenabled = sc->sc_enabled;
if (!sc->sc_enabled) {
if ((error = (*sc->sc_enable)(sc)) != 0)
if ((error = (*sc->sc_enable)(sc->sc_dev, 1)) != 0)
goto out;
sc->sc_enabled = 1;
} else
@ -878,7 +878,8 @@ wi_init(struct ifnet *ifp)
error = wi_alloc_fid(sc, sc->sc_buflen,
&sc->sc_txd[i].d_fid);
if (error) {
aprint_error_dev(&sc->sc_dev, "tx buffer allocation failed\n");
aprint_error_dev(sc->sc_dev,
"tx buffer allocation failed\n");
goto out;
}
DPRINTF2(("wi_init: txbuf %d allocated %x\n", i,
@ -930,7 +931,7 @@ wi_init(struct ifnet *ifp)
out:
if (error) {
printf("%s: interface not running\n", device_xname(&sc->sc_dev));
printf("%s: interface not running\n", device_xname(sc->sc_dev));
wi_stop(ifp, 0);
}
DPRINTF(("wi_init: return %d\n", error));
@ -988,8 +989,7 @@ wi_stop(struct ifnet *ifp, int disable)
ifp->if_timer = 0;
if (disable) {
if (sc->sc_disable)
(*sc->sc_disable)(sc);
(*sc->sc_enable)(sc->sc_dev, 0);
sc->sc_enabled = 0;
}
splx(s);
@ -1191,7 +1191,7 @@ wi_start(struct ifnet *ifp)
off = sizeof(frmhdr);
if (wi_write_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) != 0 ||
wi_mwrite_bap(sc, fid, off, m0, m0->m_pkthdr.len) != 0) {
aprint_error_dev(&sc->sc_dev, "%s write fid %x failed\n",
aprint_error_dev(sc->sc_dev, "%s write fid %x failed\n",
__func__, fid);
ifp->if_oerrors++;
m_freem(m0);
@ -1204,13 +1204,13 @@ wi_start(struct ifnet *ifp)
#ifdef DIAGNOSTIC
if (cur != sc->sc_txstart)
printf("%s: ring is desynchronized\n",
device_xname(&sc->sc_dev));
device_xname(sc->sc_dev));
#endif
wi_push_packet(sc);
} else {
#ifdef WI_RING_DEBUG
printf("%s: queue %04x, alloc %d queue %d start %d alloced %d queued %d started %d\n",
device_xname(&sc->sc_dev), fid,
device_xname(sc->sc_dev), fid,
sc->sc_txalloc, sc->sc_txqueue, sc->sc_txstart,
sc->sc_txalloced, sc->sc_txqueued, sc->sc_txstarted);
#endif
@ -1245,7 +1245,7 @@ wi_reset(struct wi_softc *sc)
break;
}
if (error) {
aprint_error_dev(&sc->sc_dev, "init failed\n");
aprint_error_dev(sc->sc_dev, "init failed\n");
return error;
}
CSR_WRITE_2(sc, WI_INT_EN, 0);
@ -1297,7 +1297,7 @@ wi_ioctl(struct ifnet *ifp, u_long cmd, void *data)
struct ifreq *ifr = (struct ifreq *)data;
int s, error = 0;
if (!device_is_active(&sc->sc_dev))
if (!device_is_active(sc->sc_dev))
return ENXIO;
s = splnet();
@ -1537,7 +1537,7 @@ wi_rx_intr(struct wi_softc *sc)
/* First read in the frame header */
if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr))) {
aprint_error_dev(&sc->sc_dev, "%s read fid %x failed\n",
aprint_error_dev(sc->sc_dev, "%s read fid %x failed\n",
__func__, fid);
ifp->if_ierrors++;
return;
@ -1655,7 +1655,7 @@ wi_tx_ex_intr(struct wi_softc *sc)
fid = CSR_READ_2(sc, WI_TX_CMP_FID);
/* Read in the frame header */
if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) != 0) {
aprint_error_dev(&sc->sc_dev, "%s read fid %x failed\n",
aprint_error_dev(sc->sc_dev, "%s read fid %x failed\n",
__func__, fid);
wi_rssdescs_reset(ic, &sc->sc_rssd, &sc->sc_rssdfree,
&sc->sc_txpending);
@ -1663,8 +1663,8 @@ wi_tx_ex_intr(struct wi_softc *sc)
}
if (frmhdr.wi_tx_idx >= WI_NTXRSS) {
printf("%s: %s bad idx %02x\n",
device_xname(&sc->sc_dev), __func__, frmhdr.wi_tx_idx);
aprint_error_dev(sc->sc_dev, "%s bad idx %02x\n",
__func__, frmhdr.wi_tx_idx);
wi_rssdescs_reset(ic, &sc->sc_rssd, &sc->sc_rssdfree,
&sc->sc_txpending);
goto out;
@ -1678,7 +1678,7 @@ wi_tx_ex_intr(struct wi_softc *sc)
* as an output error.
*/
if (ppsratecheck(&lasttxerror, &curtxeps, wi_txerate)) {
aprint_error_dev(&sc->sc_dev, "tx failed");
aprint_error_dev(sc->sc_dev, "tx failed");
if (status & WI_TXSTAT_RET_ERR)
printf(", retry limit exceeded");
if (status & WI_TXSTAT_AGED_ERR)
@ -1703,13 +1703,13 @@ wi_tx_ex_intr(struct wi_softc *sc)
id->id_node = NULL;
if (ni == NULL) {
aprint_error_dev(&sc->sc_dev, "%s null node, rssdesc %02x\n",
aprint_error_dev(sc->sc_dev, "%s null node, rssdesc %02x\n",
__func__, frmhdr.wi_tx_idx);
goto out;
}
if (sc->sc_txpending[id->id_rateidx]-- == 0) {
aprint_error_dev(&sc->sc_dev, "%s txpending[%i] wraparound",
aprint_error_dev(sc->sc_dev, "%s txpending[%i] wraparound",
__func__, id->id_rateidx);
sc->sc_txpending[id->id_rateidx] = 0;
}
@ -1731,7 +1731,7 @@ wi_txalloc_intr(struct wi_softc *sc)
#ifdef DIAGNOSTIC
if (sc->sc_txstarted == 0) {
printf("%s: spurious alloc %x != %x, alloc %d queue %d start %d alloced %d queued %d started %d\n",
device_xname(&sc->sc_dev), fid, sc->sc_txd[cur].d_fid, cur,
device_xname(sc->sc_dev), fid, sc->sc_txd[cur].d_fid, cur,
sc->sc_txqueue, sc->sc_txstart, sc->sc_txalloced, sc->sc_txqueued, sc->sc_txstarted);
return;
}
@ -1742,7 +1742,7 @@ wi_txalloc_intr(struct wi_softc *sc)
sc->sc_txalloc = (cur + 1) % WI_NTXBUF;
#ifdef WI_RING_DEBUG
printf("%s: alloc %04x, alloc %d queue %d start %d alloced %d queued %d started %d\n",
device_xname(&sc->sc_dev), fid,
device_xname(sc->sc_dev), fid,
sc->sc_txalloc, sc->sc_txqueue, sc->sc_txstart,
sc->sc_txalloced, sc->sc_txqueued, sc->sc_txstarted);
#endif
@ -1768,7 +1768,7 @@ wi_cmd_intr(struct wi_softc *sc)
ifp->if_flags &= ~IFF_OACTIVE;
#ifdef WI_RING_DEBUG
printf("%s: cmd , alloc %d queue %d start %d alloced %d queued %d started %d\n",
device_xname(&sc->sc_dev),
device_xname(sc->sc_dev),
sc->sc_txalloc, sc->sc_txqueue, sc->sc_txstart,
sc->sc_txalloced, sc->sc_txqueued, sc->sc_txstarted);
#endif
@ -1788,7 +1788,7 @@ wi_push_packet(struct wi_softc *sc)
KASSERT(sc->sc_txcmds == 0);
if (wi_cmd_start(sc, WI_CMD_TX | WI_RECLAIM, fid, 0, 0)) {
aprint_error_dev(&sc->sc_dev, "xmit failed\n");
aprint_error_dev(sc->sc_dev, "xmit failed\n");
/* XXX ring might have a hole */
}
@ -1798,14 +1798,14 @@ wi_push_packet(struct wi_softc *sc)
++sc->sc_txstarted;
#ifdef DIAGNOSTIC
if (sc->sc_txstarted > WI_NTXBUF)
aprint_error_dev(&sc->sc_dev, "too many buffers started\n");
aprint_error_dev(sc->sc_dev, "too many buffers started\n");
#endif
sc->sc_txstart = (cur + 1) % WI_NTXBUF;
sc->sc_tx_timer = 5;
ifp->if_timer = 1;
#ifdef WI_RING_DEBUG
printf("%s: push %04x, alloc %d queue %d start %d alloced %d queued %d started %d\n",
device_xname(&sc->sc_dev), fid,
device_xname(sc->sc_dev), fid,
sc->sc_txalloc, sc->sc_txqueue, sc->sc_txstart,
sc->sc_txalloced, sc->sc_txqueued, sc->sc_txstarted);
#endif
@ -1826,7 +1826,7 @@ wi_tx_intr(struct wi_softc *sc)
/* Read in the frame header */
if (wi_read_bap(sc, fid, offsetof(struct wi_frame, wi_tx_swsup2),
&frmhdr.wi_tx_swsup2, 2) != 0) {
aprint_error_dev(&sc->sc_dev, "%s read fid %x failed\n",
aprint_error_dev(sc->sc_dev, "%s read fid %x failed\n",
__func__, fid);
wi_rssdescs_reset(ic, &sc->sc_rssd, &sc->sc_rssdfree,
&sc->sc_txpending);
@ -1834,7 +1834,7 @@ wi_tx_intr(struct wi_softc *sc)
}
if (frmhdr.wi_tx_idx >= WI_NTXRSS) {
aprint_error_dev(&sc->sc_dev, "%s bad idx %02x\n",
aprint_error_dev(sc->sc_dev, "%s bad idx %02x\n",
__func__, frmhdr.wi_tx_idx);
wi_rssdescs_reset(ic, &sc->sc_rssd, &sc->sc_rssdfree,
&sc->sc_txpending);
@ -1849,13 +1849,13 @@ wi_tx_intr(struct wi_softc *sc)
id->id_node = NULL;
if (ni == NULL) {
aprint_error_dev(&sc->sc_dev, "%s null node, rssdesc %02x\n",
aprint_error_dev(sc->sc_dev, "%s null node, rssdesc %02x\n",
__func__, frmhdr.wi_tx_idx);
goto out;
}
if (sc->sc_txpending[id->id_rateidx]-- == 0) {
aprint_error_dev(&sc->sc_dev, "%s txpending[%i] wraparound",
aprint_error_dev(sc->sc_dev, "%s txpending[%i] wraparound",
__func__, id->id_rateidx);
sc->sc_txpending[id->id_rateidx] = 0;
}
@ -1994,7 +1994,7 @@ wi_read_nicid(struct wi_softc *sc)
memset(ver, 0, sizeof(ver));
len = sizeof(ver);
wi_read_rid(sc, WI_RID_CARD_ID, ver, &len);
printf("%s: using ", device_xname(&sc->sc_dev));
printf("%s: using ", device_xname(sc->sc_dev));
DPRINTF2(("wi_read_nicid: CARD_ID: %x %x %x %x\n", le16toh(ver[0]), le16toh(ver[1]), le16toh(ver[2]), le16toh(ver[3])));
sc->sc_firmware_type = WI_NOTYPE;
@ -2047,7 +2047,7 @@ DPRINTF2(("wi_read_nicid: CARD_ID: %x %x %x %x\n", le16toh(ver[0]), le16toh(ver[
}
}
printf("\n%s: %s Firmware: ", device_xname(&sc->sc_dev),
printf("\n%s: %s Firmware: ", device_xname(sc->sc_dev),
sc->sc_firmware_type == WI_LUCENT ? "Lucent" :
(sc->sc_firmware_type == WI_SYMBOL ? "Symbol" : "Intersil"));
if (sc->sc_firmware_type != WI_LUCENT) /* XXX */
@ -2632,7 +2632,7 @@ wi_cmd_start(struct wi_softc *sc, int cmd, int val0, int val1, int val2)
DELAY(1000); /* 1 m sec */
}
if (i == 0) {
aprint_error_dev(&sc->sc_dev, "wi_cmd: busy bit won't clear.\n");
aprint_error_dev(sc->sc_dev, "wi_cmd: busy bit won't clear.\n");
return(ETIMEDOUT);
}
#ifdef WI_HISTOGRAM
@ -2643,7 +2643,7 @@ wi_cmd_start(struct wi_softc *sc, int cmd, int val0, int val1, int val2)
if (++hist1count == 1000) {
hist1count = 0;
printf("%s: hist1: %d %d %d %d %d %d %d %d %d %d %d\n",
device_xname(&sc->sc_dev),
device_xname(sc->sc_dev),
hist1[0], hist1[1], hist1[2], hist1[3], hist1[4],
hist1[5], hist1[6], hist1[7], hist1[8], hist1[9],
hist1[10]);
@ -2730,7 +2730,7 @@ wi_cmd_wait(struct wi_softc *sc, int cmd, int val0)
if (++hist2count == 1000) {
hist2count = 0;
printf("%s: hist2: %d %d %d %d %d %d %d %d %d %d %d\n",
device_xname(&sc->sc_dev),
device_xname(sc->sc_dev),
hist2[0], hist2[1], hist2[2], hist2[3], hist2[4],
hist2[5], hist2[6], hist2[7], hist2[8], hist2[9],
hist2[10]);
@ -2740,7 +2740,8 @@ wi_cmd_wait(struct wi_softc *sc, int cmd, int val0)
status = CSR_READ_2(sc, WI_STATUS);
if (i == WI_TIMEOUT) {
aprint_error_dev(&sc->sc_dev, "command timed out, cmd=0x%x, arg=0x%x\n",
aprint_error_dev(sc->sc_dev,
"command timed out, cmd=0x%x, arg=0x%x\n",
cmd, val0);
return ETIMEDOUT;
}
@ -2748,7 +2749,8 @@ wi_cmd_wait(struct wi_softc *sc, int cmd, int val0)
CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD);
if (status & WI_STAT_CMD_RESULT) {
aprint_error_dev(&sc->sc_dev, "command failed, cmd=0x%x, arg=0x%x\n",
aprint_error_dev(sc->sc_dev,
"command failed, cmd=0x%x, arg=0x%x\n",
cmd, val0);
return EIO;
}
@ -2772,7 +2774,8 @@ wi_seek_bap(struct wi_softc *sc, int id, int off)
if ((status & WI_OFF_BUSY) == 0)
break;
if (i == WI_TIMEOUT) {
aprint_error_dev(&sc->sc_dev, "timeout in wi_seek to %x/%x\n",
aprint_error_dev(sc->sc_dev,
"timeout in wi_seek to %x/%x\n",
id, off);
sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
return ETIMEDOUT;
@ -2789,7 +2792,7 @@ wi_seek_bap(struct wi_softc *sc, int id, int off)
if (++hist4count == 2500) {
hist4count = 0;
printf("%s: hist4: %d %d %d %d %d %d %d %d %d %d %d\n",
device_xname(&sc->sc_dev),
device_xname(sc->sc_dev),
hist4[0], hist4[1], hist4[2], hist4[3], hist4[4],
hist4[5], hist4[6], hist4[7], hist4[8], hist4[9],
hist4[10]);
@ -2797,7 +2800,7 @@ wi_seek_bap(struct wi_softc *sc, int id, int off)
#endif
if (status & WI_OFF_ERR) {
printf("%s: failed in wi_seek to %x/%x\n",
device_xname(&sc->sc_dev), id, off);
device_xname(sc->sc_dev), id, off);
sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
return EIO;
}
@ -2863,7 +2866,8 @@ wi_write_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
if (CSR_READ_2(sc, WI_DATA0) != 0x1234 ||
CSR_READ_2(sc, WI_DATA0) != 0x5678) {
aprint_error_dev(&sc->sc_dev, "detect auto increment bug, try again\n");
aprint_error_dev(sc->sc_dev,
"detect auto increment bug, try again\n");
goto again;
}
}
@ -2904,7 +2908,7 @@ wi_alloc_fid(struct wi_softc *sc, int len, int *idp)
int i;
if (wi_cmd(sc, WI_CMD_ALLOC_MEM, len, 0, 0)) {
aprint_error_dev(&sc->sc_dev, "failed to allocate %d bytes on NIC\n", len);
aprint_error_dev(sc->sc_dev, "failed to allocate %d bytes on NIC\n", len);
return ENOMEM;
}
@ -2914,7 +2918,7 @@ wi_alloc_fid(struct wi_softc *sc, int len, int *idp)
DELAY(1);
}
if (i == WI_TIMEOUT) {
aprint_error_dev(&sc->sc_dev, "timeout in alloc\n");
aprint_error_dev(sc->sc_dev, "timeout in alloc\n");
return ETIMEDOUT;
}
*idp = CSR_READ_2(sc, WI_ALLOC_FID);
@ -2940,13 +2944,14 @@ wi_read_rid(struct wi_softc *sc, int rid, void *buf, int *buflenp)
if (le16toh(ltbuf[0]) == 0)
return EOPNOTSUPP;
if (le16toh(ltbuf[1]) != rid) {
aprint_error_dev(&sc->sc_dev, "record read mismatch, rid=%x, got=%x\n",
aprint_error_dev(sc->sc_dev,
"record read mismatch, rid=%x, got=%x\n",
rid, le16toh(ltbuf[1]));
return EIO;
}
len = (le16toh(ltbuf[0]) - 1) * 2; /* already got rid */
if (*buflenp < len) {
aprint_error_dev(&sc->sc_dev, "record buffer is too small, "
aprint_error_dev(sc->sc_dev, "record buffer is too small, "
"rid=%x, size=%d, len=%d\n",
rid, *buflenp, len);
return ENOSPC;
@ -3067,8 +3072,8 @@ wi_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
IEEE80211_ADDR_COPY(ni->ni_macaddr, &bssid);
wi_read_xrid(sc, WI_RID_CURRENT_CHAN, &val, sizeof(val));
if (!isset(ic->ic_chan_avail, le16toh(val)))
panic("%s: invalid channel %d\n", device_xname(&sc->sc_dev),
le16toh(val));
panic("%s: invalid channel %d\n",
device_xname(sc->sc_dev), le16toh(val));
ni->ni_chan = &ic->ic_channels[le16toh(val)];
if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
@ -3183,7 +3188,8 @@ wi_scan_result(struct wi_softc *sc, int fid, int cnt)
szbuf = sizeof(struct wi_scan_data);
break;
default:
aprint_error_dev(&sc->sc_dev, "wi_scan_result: unknown firmware type %u\n",
aprint_error_dev(sc->sc_dev,
"wi_scan_result: unknown firmware type %u\n",
sc->sc_firmware_type);
naps = 0;
goto done;

View File

@ -1,4 +1,4 @@
/* $NetBSD: wivar.h,v 1.63 2010/01/17 19:45:06 pooka Exp $ */
/* $NetBSD: wivar.h,v 1.64 2010/11/23 04:33:09 christos Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@ -74,13 +74,12 @@ typedef SLIST_HEAD(,wi_rssdesc) wi_rssdescq_t;
* Oslo IETF plenary meeting.
*/
struct wi_softc {
struct device sc_dev;
device_t sc_dev;
struct ethercom sc_ec;
struct ieee80211com sc_ic;
u_int32_t sc_ic_flags; /* backup of ic->ic_flags */
void *sc_ih; /* interrupt handler */
int (*sc_enable)(struct wi_softc *);
void (*sc_disable)(struct wi_softc *);
int (*sc_enable)(device_t, int);
void (*sc_reset)(struct wi_softc *);
int (*sc_newstate)(struct ieee80211com *,

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_wi_pci.c,v 1.50 2009/11/26 15:17:10 njoly Exp $ */
/* $NetBSD: if_wi_pci.c,v 1.51 2010/11/23 04:33:09 christos Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_wi_pci.c,v 1.50 2009/11/26 15:17:10 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_wi_pci.c,v 1.51 2010/11/23 04:33:09 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -90,14 +90,13 @@ struct wi_pci_softc {
static int wi_pci_match(device_t, cfdata_t, void *);
static void wi_pci_attach(device_t, device_t, void *);
static int wi_pci_enable(struct wi_softc *);
static void wi_pci_disable(struct wi_softc *);
static int wi_pci_enable(device_t, int);
static void wi_pci_reset(struct wi_softc *);
static const struct wi_pci_product
*wi_pci_lookup(struct pci_attach_args *);
CFATTACH_DECL(wi_pci, sizeof(struct wi_pci_softc),
CFATTACH_DECL_NEW(wi_pci, sizeof(struct wi_pci_softc),
wi_pci_match, wi_pci_attach, NULL, NULL);
static const struct wi_pci_product {
@ -128,31 +127,28 @@ static const struct wi_pci_product {
};
static int
wi_pci_enable(struct wi_softc *sc)
wi_pci_enable(device_t self, int onoff)
{
struct wi_pci_softc *psc = (struct wi_pci_softc *)sc;
struct wi_pci_softc *psc = device_pivate(self);
struct wi_softc *sc = &psc->sc_wi;
/* establish the interrupt. */
sc->sc_ih = pci_intr_establish(psc->psc_pc,
psc->psc_ih, IPL_NET, wi_intr, sc);
if (sc->sc_ih == NULL) {
aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt\n");
return (EIO);
}
if (onoff) {
/* establish the interrupt. */
sc->sc_ih = pci_intr_establish(psc->psc_pc,
psc->psc_ih, IPL_NET, wi_intr, sc);
if (sc->sc_ih == NULL) {
aprint_error_dev(sc->sc_dev,
"couldn't establish interrupt\n");
return EIO;
}
/* reset HFA3842 MAC core */
if (sc->sc_reset != NULL)
wi_pci_reset(sc);
/* reset HFA3842 MAC core */
if (sc->sc_reset != NULL)
wi_pci_reset(sc);
return (0);
}
static void
wi_pci_disable(struct wi_softc *sc)
{
struct wi_pci_softc *psc = (struct wi_pci_softc *)sc;
pci_intr_disestablish(psc->psc_pc, sc->sc_ih);
} else
pci_intr_disestablish(psc->psc_pc, sc->sc_ih);
return 0;
}
static void
@ -175,14 +171,14 @@ wi_pci_reset(struct wi_softc *sc)
break;
if (i < 0) {
printf("%s: PCI reset timed out\n", device_xname(&sc->sc_dev));
printf("%s: PCI reset timed out\n", device_xname(sc->sc_dev));
} else if (sc->sc_if.if_flags & IFF_DEBUG) {
usecs = (200000 - i) * 10;
secs = usecs / 1000000;
usecs %= 1000000;
printf("%s: PCI reset in %d.%06d seconds\n",
device_xname(&sc->sc_dev), secs, usecs);
device_xname(sc->sc_dev), secs, usecs);
}
return;
@ -224,6 +220,7 @@ wi_pci_attach(device_t parent, device_t self, void *aux)
bus_space_tag_t memt, iot, plxt, tmdt;
bus_space_handle_t memh, ioh, plxh, tmdh;
sc->sc_dev = self;
psc->psc_pc = pc;
psc->psc_pcitag = pa->pa_tag;
@ -303,7 +300,6 @@ wi_pci_attach(device_t parent, device_t self, void *aux)
sc->sc_enabled = 1;
sc->sc_enable = wi_pci_enable;
sc->sc_disable = wi_pci_disable;
sc->sc_iot = iot;
sc->sc_ioh = ioh;

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_wi_pcmcia.c,v 1.85 2009/09/05 14:44:59 tsutsui Exp $ */
/* $NetBSD: if_wi_pcmcia.c,v 1.86 2010/11/23 04:33:10 christos Exp $ */
/*-
* Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_wi_pcmcia.c,v 1.85 2009/09/05 14:44:59 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_wi_pcmcia.c,v 1.86 2010/11/23 04:33:10 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -78,8 +78,7 @@ static int wi_pcmcia_match(device_t, cfdata_t, void *);
static int wi_pcmcia_validate_config(struct pcmcia_config_entry *);
static void wi_pcmcia_attach(device_t, device_t, void *);
static int wi_pcmcia_detach(device_t, int);
static int wi_pcmcia_enable(struct wi_softc *);
static void wi_pcmcia_disable(struct wi_softc *);
static int wi_pcmcia_enable(device_t, int);
#if WI_PCMCIA_SPECTRUM24T_FW
/* support to download firmware for symbol CF card */
@ -98,7 +97,7 @@ struct wi_pcmcia_softc {
#define WI_PCMCIA_ATTACHED 3
};
CFATTACH_DECL(wi_pcmcia, sizeof(struct wi_pcmcia_softc),
CFATTACH_DECL_NEW(wi_pcmcia, sizeof(struct wi_pcmcia_softc),
wi_pcmcia_match, wi_pcmcia_attach, wi_pcmcia_detach, wi_activate);
static const struct pcmcia_product wi_pcmcia_products[] = {
@ -251,8 +250,7 @@ static const size_t wi_pcmcia_nproducts =
sizeof(wi_pcmcia_products) / sizeof(wi_pcmcia_products[0]);
static int
wi_pcmcia_match(device_t parent, cfdata_t match,
void *aux)
wi_pcmcia_match(device_t parent, cfdata_t match, void *aux)
{
struct pcmcia_attach_args *pa = aux;
@ -263,51 +261,50 @@ wi_pcmcia_match(device_t parent, cfdata_t match,
}
static int
wi_pcmcia_enable(struct wi_softc *sc)
wi_pcmcia_enable(device_t self, int onoff)
{
struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)sc;
struct wi_pcmcia_softc *psc = device_private(self);
struct wi_softc *sc = &psc->sc_wi;
struct pcmcia_function *pf = psc->sc_pf;
int error;
/* establish the interrupt. */
sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, wi_intr, sc);
if (!sc->sc_ih)
return (EIO);
if (onoff) {
/* establish the interrupt. */
sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, wi_intr, sc);
if (!sc->sc_ih)
return EIO;
error = pcmcia_function_enable(pf);
if (error) {
pcmcia_intr_disestablish(pf, sc->sc_ih);
sc->sc_ih = 0;
return (EIO);
}
if (psc->sc_symbol_cf) {
#if WI_PCMCIA_SPECTRUM24T_FW
if (wi_pcmcia_load_firm(sc,
spectrum24t_primsym, sizeof(spectrum24t_primsym),
spectrum24t_secsym, sizeof(spectrum24t_secsym))) {
aprint_error_dev(&sc->sc_dev, "couldn't load firmware\n");
wi_pcmcia_disable(sc);
return (EIO);
error = pcmcia_function_enable(pf);
if (error) {
pcmcia_intr_disestablish(pf, sc->sc_ih);
sc->sc_ih = 0;
return EIO;
}
if (psc->sc_symbol_cf) {
#if WI_PCMCIA_SPECTRUM24T_FW
if (wi_pcmcia_load_firm(sc,
spectrum24t_primsym, sizeof(spectrum24t_primsym),
spectrum24t_secsym, sizeof(spectrum24t_secsym))) {
aprint_error_dev(sc->sc_dev,
"couldn't load firmware\n");
wi_pcmcia_enable(self, 0);
return EIO;
}
#else
aprint_error_dev(&sc->sc_dev, "firmware load not configured\n");
return EIO;
aprint_error_dev(sc->sc_dev,
"firmware load not configured\n");
return EIO;
#endif
}
DELAY(1000);
} else {
pcmcia_function_disable(psc->sc_pf);
pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
sc->sc_ih = 0;
}
DELAY(1000);
return (0);
}
static void
wi_pcmcia_disable(struct wi_softc *sc)
{
struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)sc;
pcmcia_function_disable(psc->sc_pf);
pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
sc->sc_ih = 0;
return 0;
}
static int
@ -322,10 +319,9 @@ wi_pcmcia_validate_config(struct pcmcia_config_entry *cfe)
}
static void
wi_pcmcia_attach(struct device *parent, device_t self,
void *aux)
wi_pcmcia_attach(device_t parent, device_t self, void *aux)
{
struct wi_pcmcia_softc *psc = (void *)self;
struct wi_pcmcia_softc *psc = device_private(self);
struct wi_softc *sc = &psc->sc_wi;
struct pcmcia_attach_args *pa = aux;
struct pcmcia_config_entry *cfe;
@ -334,6 +330,7 @@ wi_pcmcia_attach(struct device *parent, device_t self,
aprint_naive("\n");
sc->sc_dev = self;
psc->sc_pf = pa->pf;
error = pcmcia_function_configure(pa->pf, wi_pcmcia_validate_config);
@ -360,13 +357,12 @@ wi_pcmcia_attach(struct device *parent, device_t self,
CSR_READ_2(sc, WI_COR) == WI_COR_IOMODE)
psc->sc_symbol_cf = 1;
error = wi_pcmcia_enable(sc);
error = wi_pcmcia_enable(self, 1);
if (error)
goto fail;
sc->sc_pci = 0;
sc->sc_enable = wi_pcmcia_enable;
sc->sc_disable = wi_pcmcia_disable;
printf("%s:", device_xname(self));
@ -381,12 +377,12 @@ wi_pcmcia_attach(struct device *parent, device_t self,
else
aprint_error_dev(self, "couldn't establish power handler\n");
wi_pcmcia_disable(sc);
wi_pcmcia_enable(self, 0);
psc->sc_state = WI_PCMCIA_ATTACHED;
return;
fail2:
wi_pcmcia_disable(sc);
wi_pcmcia_enable(self, 0);
fail:
pcmcia_function_unconfigure(pa->pf);
}
@ -394,7 +390,7 @@ fail:
static int
wi_pcmcia_detach(device_t self, int flags)
{
struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)self;
struct wi_pcmcia_softc *psc = device_private(self);
int error;
if (psc->sc_state != WI_PCMCIA_ATTACHED)
@ -422,7 +418,8 @@ wi_pcmcia_detach(device_t self, int flags)
#if WI_PCMCIA_SPECTRUM24T_FW
static int
wi_pcmcia_load_firm(struct wi_softc *sc, const void *primsym, int primlen, const void *secsym, int seclen)
wi_pcmcia_load_firm(struct wi_softc *sc, const void *primsym, int primlen,
const void *secsym, int seclen)
{
u_int8_t ebuf[256];
int i;
@ -469,7 +466,8 @@ wi_pcmcia_load_firm(struct wi_softc *sc, const void *primsym, int primlen, const
}
static int
wi_pcmcia_write_firm(struct wi_softc *sc, const void *buf, int buflen, const void *ebuf, int ebuflen)
wi_pcmcia_write_firm(struct wi_softc *sc, const void *buf, int buflen,
const void *ebuf, int ebuflen)
{
const u_int8_t *p, *ep, *q, *eq;
char *endp;