Module Name: src Committed By: christos Date: Tue Nov 23 04:33:10 UTC 2010
Modified Files: src/sys/dev/ic: wi.c wivar.h src/sys/dev/pci: if_wi_pci.c src/sys/dev/pcmcia: if_wi_pcmcia.c Log Message: split if_wi To generate a diff of this commit: cvs rdiff -u -r1.233 -r1.234 src/sys/dev/ic/wi.c cvs rdiff -u -r1.63 -r1.64 src/sys/dev/ic/wivar.h cvs rdiff -u -r1.50 -r1.51 src/sys/dev/pci/if_wi_pci.c cvs rdiff -u -r1.85 -r1.86 src/sys/dev/pcmcia/if_wi_pcmcia.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/wi.c diff -u src/sys/dev/ic/wi.c:1.233 src/sys/dev/ic/wi.c:1.234 --- src/sys/dev/ic/wi.c:1.233 Mon Apr 5 03:19:37 2010 +++ src/sys/dev/ic/wi.c Mon Nov 22 23:33:09 2010 @@ -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 @@ /* 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 @@ /* 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 @@ 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 @@ &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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ #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 @@ 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 @@ 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 @@ /* 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 @@ 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 @@ } 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 @@ * 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 @@ 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 @@ #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 @@ 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 @@ 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 @@ 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 @@ ++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 @@ /* 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 @@ } 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 @@ 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 @@ 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 @@ } } - 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ #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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; Index: src/sys/dev/ic/wivar.h diff -u src/sys/dev/ic/wivar.h:1.63 src/sys/dev/ic/wivar.h:1.64 --- src/sys/dev/ic/wivar.h:1.63 Sun Jan 17 14:45:06 2010 +++ src/sys/dev/ic/wivar.h Mon Nov 22 23:33:09 2010 @@ -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 @@ * 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 *, Index: src/sys/dev/pci/if_wi_pci.c diff -u src/sys/dev/pci/if_wi_pci.c:1.50 src/sys/dev/pci/if_wi_pci.c:1.51 --- src/sys/dev/pci/if_wi_pci.c:1.50 Thu Nov 26 10:17:10 2009 +++ src/sys/dev/pci/if_wi_pci.c Mon Nov 22 23:33:09 2010 @@ -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 @@ 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 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); - } - - /* reset HFA3842 MAC core */ - if (sc->sc_reset != NULL) - wi_pci_reset(sc); - - return (0); -} + 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; + } -static void -wi_pci_disable(struct wi_softc *sc) -{ - struct wi_pci_softc *psc = (struct wi_pci_softc *)sc; + /* reset HFA3842 MAC core */ + if (sc->sc_reset != NULL) + wi_pci_reset(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 @@ 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 @@ 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 @@ sc->sc_enabled = 1; sc->sc_enable = wi_pci_enable; - sc->sc_disable = wi_pci_disable; sc->sc_iot = iot; sc->sc_ioh = ioh; Index: src/sys/dev/pcmcia/if_wi_pcmcia.c diff -u src/sys/dev/pcmcia/if_wi_pcmcia.c:1.85 src/sys/dev/pcmcia/if_wi_pcmcia.c:1.86 --- src/sys/dev/pcmcia/if_wi_pcmcia.c:1.85 Sat Sep 5 10:44:59 2009 +++ src/sys/dev/pcmcia/if_wi_pcmcia.c Mon Nov 22 23:33:10 2010 @@ -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_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 @@ #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 @@ 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 @@ } 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); - - error = pcmcia_function_enable(pf); - if (error) { - pcmcia_intr_disestablish(pf, sc->sc_ih); - sc->sc_ih = 0; - 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 (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); - } + 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ #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 @@ } 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;