Changeset 9

Show
Ignore:
Timestamp:
03/15/03 19:30:25 (6 years ago)
Author:
sam
Message:

Replicated Change 28 by sam@borg_greg on 2003/02/20 17:26:54<<<

checkpoint where ath_pci compiles and loads

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cvs-import/trunk/driver/Makefile

    r3 r9  
    33# Makefile for the Atheros WLAN driver. 
    44# 
     5DESTDIR= 
     6 
     7VERSION=        2.4.20 
    58 
    69# 
     
    1316ATH_HAL=../ath_hal 
    1417# 
     18# Path to the 802.11 include files 
     19# 
     20WLAN=   ../wlan 
     21# 
    1522# Path to the Linux kernel include files. 
    1623# 
    17 LINUX=  ../../linux-2.4.20/include 
     24LINUX=  ../../linux-${VERSION}/include 
    1825 
    1926SRCS=   ah_osdep.c if_ath.c if_ath_cs.c if_ath_pci.c 
    2027 
    21 OBJS_COMMON=    ah_osdep.o if_ath.o ${ATH_HAL}/hal.o 
    22 OBJS_CS=        ${OBJS_COMMON} if_ath_cs.o 
    23 OBJS_PCI=       ${OBJS_COMMON} if_ath_pci.o 
     28OBJS_COMMON=    ah_osdep.o if_ath.o 
     29OBJS_CS=        ${OBJS_COMMON} ${ATH_HAL}/hal.o if_ath_cs.o ${WLAN}/wlan.o 
     30OBJS_PCI=       ${OBJS_COMMON} ${ATH_HAL}/hal.o if_ath_pci.o ${WLAN}/wlan.o 
     31OBJS=           ${OBJS_COMMON} if_ath_cs.o if_ath_pci.o 
    2432 
    25 CFLAGS= -I. -I${ATH_HAL} -I${HAL} -I${LINUX} \ 
    26         -D_BUILD_STANDALONE_ -D__KERNEL__ -g -O 
     33CFLAGS= -I. -I${ATH_HAL} -I${HAL} -I${WLAN} -I${LINUX} \ 
     34        -D_BUILD_STANDALONE_ -D__KERNEL__ -DMODULE -g -O 
    2735 
    28 all:    ath_cs.o ath_pci.o 
     36#ALL=   ath_cs.o ath_pci.o 
     37ALL=    ath_pci.o 
     38 
     39all:    ${ALL} 
     40 
     41install: all 
     42        cp ${ALL} ${DESTDIR}/lib/modules/${VERSION}/net 
    2943 
    3044ath_cs.o: ${OBJS_CS} Makefile 
  • cvs-import/trunk/driver/if_ath.c

    r3 r9  
    3030 * Driver for the Atheros Wireless LAN controller. 
    3131 */ 
    32 #include "opt_inet.h" 
    33 #define NBPFILTER       1 
    34  
    35 #include <sys/param.h> 
    36 #include <sys/systm.h>  
    37 #include <sys/sysctl.h> 
    38 #include <sys/mbuf.h>    
    39 #include <sys/malloc.h> 
    40 #include <sys/lock.h> 
    41 #include <sys/mutex.h> 
    42 #include <sys/kernel.h> 
    43 #include <sys/socket.h> 
    44 #include <sys/sockio.h> 
    45 #include <sys/errno.h> 
    46 #include <sys/callout.h> 
    47 #include <sys/bus.h> 
    48 #include <sys/endian.h> 
    49  
    50 #include <machine/bus.h> 
    51   
    52 #include <net/if.h> 
    53 #include <net/if_dl.h> 
    54 #include <net/if_media.h> 
    55 #include <net/ethernet.h> 
    56 #include <net/if_llc.h> 
    57 #include <net/if_ieee80211.h> 
    58  
    59 #if NBPFILTER > 0  
    60 #include <net/bpf.h> 
    61 #endif  
    62  
    63 #ifdef INET 
    64 #include <netinet/in.h>  
    65 #include <netinet/if_ether.h> 
    66 #endif 
     32#include <linux/config.h> 
     33#include <linux/version.h> 
     34#include <linux/module.h> 
     35#include <linux/init.h> 
     36#include <linux/skbuff.h> 
     37#include <linux/netdevice.h> 
     38#include <linux/random.h> 
     39#include <linux/pci.h> 
     40#include <linux/delay.h> 
     41 
     42#include <asm/uaccess.h> 
    6743 
    6844#define AR_DEBUG 
    69 #include <dev/ath/if_athvar.h> 
    70 #include <contrib/dev/ath/ah_desc.h> 
    71  
    72 #ifndef M_DONTWAIT 
    73 #define M_DONTWAIT      0               /* XXX temporary workaround */ 
    74 #endif 
    75  
    76 /* NetBSD->FreeBSD portability shims */ 
    77 #define IF_POLL(ifq, m)         ((m) = (ifq)->ifq_head) 
    78 #define IFQ_POLL(ifq, m)        IF_POLL((ifq), (m)) 
    79 #define IFQ_DEQUEUE(ifq, m)     IF_DEQUEUE((ifq), (m)) 
     45#include "if_athvar.h" 
     46#include "if_ethersubr.h"               /* for ETHER_IS_MULTICAST */ 
     47#include "ah_desc.h" 
    8048 
    8149/* unalligned little endian access */      
     
    8856          (((u_int8_t *)(p))[2] << 16) | (((u_int8_t *)(p))[3] << 24))) 
    8957 
    90 static void     ath_init(void *); 
    91 static void     ath_stop(struct ifnet *, int); 
    92 static void     ath_start(struct ifnet *); 
    93 static void     ath_watchdog(struct ifnet *); 
    94 static int      ath_ioctl(struct ifnet *, u_long, caddr_t); 
    95 static int      ath_media_change(struct ifnet *ifp); 
    96 static void     ath_media_status(struct ifnet *ifp, struct ifmediareq *imr); 
    97 static void     ath_mode_init(struct ath_softc *); 
     58/* Bit map related macros. */ 
     59#define setbit(a,i)     ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 
     60#define clrbit(a,i)     ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 
     61#define isset(a,i)      ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 
     62#define isclr(a,i)      (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 
     63 
     64static int      ath_init(struct net_device *); 
     65static int      ath_stop(struct net_device *); 
     66static void     ath_start(struct net_device *); 
     67static void     ath_watchdog(struct net_device *); 
     68static int      ath_ioctl(struct net_device *, struct ifreq *, int); 
     69static int      ath_media_change(struct net_device *); 
     70static void     ath_media_status(struct net_device *, struct ifmediareq *); 
     71static void     ath_mode_init(struct net_device *); 
    9872static int      ath_beacon_alloc(struct ath_softc *, struct ieee80211_node *); 
    9973static void     ath_beacon_int(struct ath_softc *); 
     
    10478static int      ath_rxbuf_init(struct ath_softc *, struct ath_buf *); 
    10579static void     ath_rx_int(struct ath_softc *); 
     80static int      ath_hardstart(struct sk_buff *, struct net_device *); 
    10681static int      ath_tx_start(struct ath_softc *, struct ieee80211_node *, 
    107                              struct ath_buf *, struct mbuf *); 
     82                             struct ath_buf *, struct sk_buff *); 
    10883static void     ath_tx_int(struct ath_softc *); 
    10984static HAL_CHANNEL *ath_chan_find(struct ath_softc *, u_int); 
     
    11287static void     ath_stoprecv(struct ath_softc *); 
    11388static int      ath_startrecv(struct ath_softc *); 
    114 static void     ath_next_scan(void *); 
    115 static void     ath_calibrate(void *); 
     89static void     ath_next_scan(unsigned long); 
     90static void     ath_calibrate(unsigned long); 
    11691static int      ath_newstate(void *, enum ieee80211_state); 
    11792static void     ath_rate_ctl(struct ath_softc *, struct ieee80211_node *); 
     93static struct net_device_stats *ath_getstats(struct net_device *); 
    11894 
    11995#ifdef AR_DEBUG 
    12096int     ath_debug = 2;          /*XXX*/ 
    121 SYSCTL_INT(_debug, OID_AUTO, ath, CTLFLAG_RW, &ath_debug, 
    122             0, "Atheros driver debugging printfs"); 
    123 #define IFF_DUMPPKTS(_ifp) \ 
    124         (ath_debug || \ 
    125             ((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2)) 
     97#define IFF_DUMPPKTS(_ic)       (ath_debug || netif_msg_dumppkts(_ic)) 
    12698static  void ath_printrxbuf(struct ath_buf *bf); 
    12799static  void ath_printtxbuf(struct ath_buf *bf); 
    128100#else 
    129 #define IFF_DUMPPKTS(_ifp) \ 
    130         (((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2)) 
     101#define IFF_DUMPPKTS(_ic)       netif_msg_dumppkts(_ic) 
    131102#endif 
    132103 
     
    145116 
    146117int 
    147 ath_attach(u_int16_t devid, struct ath_softc *sc) 
    148 
     118ath_attach(uint16_t devid, struct net_device *dev) 
     119
     120        struct ath_softc *sc = dev->priv; 
    149121        struct ieee80211com *ic = &sc->sc_ic; 
    150         struct ifnet *ifp = &ic->ic_if; 
    151122        struct ath_hal *ah; 
    152123        int i, error = 0; 
     
    155126        HAL_STATUS status; 
    156127 
    157         DPRINTF(("ath_attach: devid 0x%x\n", devid)); 
    158  
    159         /* set these up early for if_printf use */ 
    160         ifp->if_unit = device_get_unit(sc->sc_dev); 
    161         ifp->if_name = "ath"; 
    162  
    163         ah = ath_hal_attach(devid, sc, sc->sc_st, sc->sc_sh, &status); 
     128        DPRINTF(("ath_attach: unit %d devid 0x%x\n", sc->sc_unit, devid)); 
     129 
     130        spin_lock_init(&sc->sc_lock); 
     131        skb_queue_head_init(&sc->sc_sndq); 
     132 
     133        ah = ath_hal_attach(devid, sc, 0, (void *) dev->mem_start, &status); 
    164134        if (ah == NULL) { 
    165                 if_printf(ifp, "unable to attach hardware; HAL status %u\n", 
    166                         status); 
     135                printk(KERN_ERR "%s: unable to attach hardware; HAL status %u\n", 
     136                        dev->name, status); 
    167137                error = ENXIO; 
    168138                goto bad; 
     
    177147                CTRY_DEFAULT, MODE_SELECT_11A, 1)) { 
    178148#endif 
    179                 if_printf(ifp, "unable to initialize channel list\n"); 
     149                printk(KERN_ERR "%s: unable to initialize channel list\n", 
     150                        dev->name); 
    180151                error = EINVAL; 
    181152                goto bad; 
     
    186157        error = ath_desc_alloc(sc); 
    187158        if (error != 0) { 
    188                 if_printf(ifp, "failed to allocate descriptors: %d\n", error); 
     159                printk("%s: failed to allocate descriptors: %d\n", 
     160                        dev->name, error); 
    189161                goto bad; 
    190162        } 
    191         callout_init(&sc->sc_scan_ch, 0); 
    192         callout_init(&sc->sc_cal_ch, 0); 
    193  
    194         ifp->if_softc = sc; 
    195         ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; 
    196         ifp->if_start = ath_start; 
    197         ifp->if_watchdog = ath_watchdog; 
    198         ifp->if_ioctl = ath_ioctl; 
    199         ifp->if_init = ath_init; 
     163        init_timer(&sc->sc_scan_ch); 
     164        sc->sc_scan_ch.function = ath_next_scan; 
     165        sc->sc_scan_ch.data = (unsigned long) sc; 
     166        init_timer(&sc->sc_cal_ch); 
     167        sc->sc_cal_ch.function = ath_calibrate; 
     168        sc->sc_cal_ch.data = (unsigned long) sc; 
     169 
    200170#if 0 
    201         ifp->if_stop = ath_stop; 
     171        dev->features |= NETIF_F_SG;           /* scatter/gather supported */ 
    202172#endif 
    203         ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 
    204  
    205         ic->ic_softc = sc; 
     173        dev->open = ath_init; 
     174        dev->hard_start_xmit = ath_hardstart; 
     175        dev->stop = ath_stop; 
     176        dev->get_stats = ath_getstats; 
     177        dev->set_multicast_list = ath_mode_init; 
     178        dev->do_ioctl = ath_ioctl; 
     179 
    206180        ic->ic_newstate = ath_newstate; 
    207181        ic->ic_phytype = IEEE80211_T_OFDM; 
     
    247221        } 
    248222 
    249         if_printf(ifp, "802.11 address: %s\n", ether_sprintf(ic->ic_myaddr)); 
     223        printk("%s: 802.11 address: %s\n", dev->name, 
     224                ether_sprintf(ic->ic_myaddr)); 
    250225 
    251226        /* call MI attach routine. */ 
    252         ieee80211_ifattach(ifp); 
     227        ieee80211_ifattach(dev); 
    253228 
    254229        ifmedia_init(&sc->sc_media, 0, ath_media_change, ath_media_status); 
     
    262237            IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, IFM_IEEE80211_HOSTAP, 0), 
    263238            0, NULL); 
    264         ath_media_status(ifp, &imr); 
     239        ath_media_status(dev, &imr); 
    265240        ifmedia_set(&sc->sc_media, imr.ifm_active); 
    266241 
     
    276251 
    277252int 
    278 ath_detach(struct ath_softc *sc
    279 { 
    280         struct ifnet *ifp = &sc->sc_ic.ic_if
     253ath_detach(struct net_device *dev
     254{ 
     255        struct ath_softc *sc = dev->priv
    281256 
    282257        DPRINTF(("ath_detach: sc_attached %u\n", sc->sc_attached)); 
     
    284259        if (sc->sc_attached) { 
    285260                sc->sc_invalid = 1; 
    286                 ath_stop(ifp, 1); 
     261                ath_stop(dev); 
    287262                ath_desc_free(sc); 
    288263                ath_hal_detach(sc->sc_ah); 
    289264                ifmedia_removeall(&sc->sc_media); 
    290                 ieee80211_ifdetach(ifp); 
    291 #ifdef __NetBSD__ 
    292                 if_detach(ifp); 
    293 #endif 
     265                ieee80211_ifdetach(dev); 
    294266        } 
    295267        ATH_UNLOCK(sc); 
     
    297269} 
    298270 
    299 #ifdef __NetBSD__ 
    300 int 
    301 ath_activate(struct device *self, enum devact act) 
    302 { 
    303         struct ath_softc *sc = (struct ath_softc *)self; 
    304         struct ifnet *ifp = &sc->sc_ic.ic_if; 
    305         int error = 0; 
    306  
    307         ATH_LOCK(sc); 
    308         switch (act) { 
    309         case DVACT_ACTIVATE: 
    310                 error = EOPNOTSUPP; 
    311                 break; 
    312         case DVACT_DEACTIVATE: 
    313                 sc->sc_invalid = 1; 
    314                 if_deactivate(ifp); 
    315                 break; 
    316         } 
    317         ATH_UNLOCK(sc); 
    318         return error; 
    319 } 
    320 #endif /* __NetBSD__ */ 
    321  
    322271void 
    323 ath_suspend(struct ath_softc *sc
    324 { 
    325         struct ifnet *ifp = &sc->sc_ic.ic_if
     272ath_suspend(struct net_device *dev
     273{ 
     274        struct ath_softc *sc = dev->priv
    326275 
    327276        DPRINTF(("ath_suspend: sc_attached %u\n", sc->sc_attached)); 
    328277        if (sc->sc_attached) { 
    329278                ATH_LOCK(sc); 
    330                 ath_stop(ifp, 1); 
     279                ath_stop(dev); 
    331280                ATH_UNLOCK(sc); 
    332281        } 
     
    334283 
    335284void 
    336 ath_resume(struct ath_softc *sc
    337 { 
    338         struct ifnet *ifp = &sc->sc_ic.ic_if
     285ath_resume(struct net_device *dev
     286{ 
     287        struct ath_softc *sc = dev->priv
    339288 
    340289        DPRINTF(("ath_resume: sc_attached %u\n", sc->sc_attached)); 
    341290        if (sc->sc_attached) { 
    342291                ATH_LOCK(sc); 
    343                 if (ifp->if_flags & IFF_UP) 
    344                         ath_init(ifp); 
     292                if (dev->flags & IFF_UP) 
     293                        ath_init(dev); 
    345294                ATH_UNLOCK(sc); 
    346295        } 
     
    348297 
    349298void 
    350 ath_shutdown(struct ath_softc *sc
    351 { 
    352         struct ifnet *ifp = &sc->sc_ic.ic_if
     299ath_shutdown(struct net_device *dev
     300{ 
     301        struct ath_softc *sc = dev->priv
    353302 
    354303        DPRINTF(("ath_shutdown: sc_attached %u\n", sc->sc_attached)); 
    355304        if (sc->sc_attached) 
    356                 ath_stop(ifp, 1); 
     305                ath_stop(dev); 
    357306} 
    358307 
     
    361310{ 
    362311        struct net_device *dev = dev_id; 
    363         local_info_t *local = dev->priv; 
    364  
    365         struct ath_softc *sc = arg; 
     312        struct ath_softc *sc = dev->priv; 
    366313        struct ieee80211com *ic = &sc->sc_ic; 
    367         struct ifnet *ifp = &ic->ic_if; 
    368314        struct ath_hal *ah = sc->sc_ah; 
    369315        HAL_INT status; 
    370  
    371         if (local->func->card_present && !local->func->card_present(local)) { 
    372                 printk(KERN_DEBUG "%s: interrupt, but device not OK\n", 
    373                         dev->name); 
    374                 return; 
    375         } 
    376316 
    377317        ATH_LOCK(sc); 
     
    380320                DPRINTF2(("ath_intr: status 0x%x\n", status)); 
    381321                if (status & HAL_INT_FATAL) { 
    382                         if_printf(ifp, "hardware error (0x%x); resetting\n", 
    383                                 status); 
     322                        printk("%s: hardware error (0x%x); resetting\n", 
     323                                dev->name, status); 
    384324                        ath_hal_dumpstate(ah);  /*XXX*/ 
    385                         ath_init(ifp); 
     325                        ath_init(dev); 
    386326                        continue; 
    387327                } 
    388328                if (status & HAL_INT_RXORN) { 
    389                         if_printf(ifp, "rx FIFO overrun (0x%x); resetting\n", 
    390                                 status); 
     329                        printk("%s: rx FIFO overrun (0x%x); resetting\n", 
     330                                dev->name, status); 
    391331                        ath_hal_dumpstate(ah);  /*XXX*/ 
    392                         ath_init(ifp); 
     332                        ath_init(dev); 
    393333                        continue; 
    394334                } 
     
    413353                        if (ic->ic_opmode == IEEE80211_M_STA && 
    414354                            ic->ic_state == IEEE80211_S_RUN) 
    415                                 ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1); 
     355                                ieee80211_new_state(dev, IEEE80211_S_SCAN, -1); 
    416356                } 
    417357#endif 
     
    436376                else 
    437377                        /* XXX return value */ 
    438                         ath_hal_keyset(ah, i, k); 
    439         } 
    440 } 
    441  
    442 static void 
    443 ath_init(void *arg
    444 { 
    445         struct ath_softc *sc = (struct ath_softc *) arg
     378                        ath_hal_keyset(ah, i, (const HAL_KEYVAL *) k); 
     379        } 
     380} 
     381 
     382static int 
     383ath_init(struct net_device *dev
     384{ 
     385        struct ath_softc *sc = dev->priv
    446386        struct ieee80211com *ic = &sc->sc_ic; 
    447         struct ifnet *ifp = &ic->ic_if; 
    448387        struct ieee80211_node *ni = &ic->ic_bss; 
    449388        struct ath_hal *ah = sc->sc_ah; 
     
    452391 
    453392        ATH_LOCK(sc); 
    454         DPRINTF(("ath_init: enabled=%d\n", sc->sc_enabled)); 
    455         if (!sc->sc_enabled) { 
    456                 if (sc->sc_enable) 
    457                         (*sc->sc_enable)(sc); 
    458                 sc->sc_enabled = 1; 
    459         } else { 
    460                 ath_stop(ifp, 0); 
    461         } 
     393        DPRINTF(("ath_init\n")); 
     394 
    462395        ic->ic_state = IEEE80211_S_INIT; 
    463396 
     
    470403         */ 
    471404        if (!ath_hal_reset(ah, ic->ic_opmode, sc->sc_cur_chan, AH_FALSE, &status)) { 
    472                 if_printf(ifp, "unable to reset hardware; HAL status %u\n", 
    473                         status); 
     405                printk("%s: unable to reset hardware; HAL status %u\n", 
     406                        dev->name, status); 
    474407                ATH_UNLOCK(sc); 
    475408                return; 
     
    485418                ath_initkeytable(sc); 
    486419        if (ath_startrecv(sc) != 0) { 
    487                 if_printf(ifp, "unable to start recv logic\n"); 
     420                printk("%s: unable to start recv logic\n", dev->name); 
    488421                ATH_UNLOCK(sc); 
    489422                return; 
     
    500433        ath_hal_intrset(ah, val | HAL_INT_GLOBAL); 
    501434 
    502         ifp->if_flags |= IFF_RUNNING; 
    503         ifp->if_flags &= ~IFF_OACTIVE
     435        dev->flags |= IFF_RUNNING; 
     436        netif_start_queue(dev)
    504437 
    505438        /* 
     
    530463                ic->ic_flags |= IEEE80211_F_SIBSS; 
    531464                ic->ic_state = IEEE80211_S_SCAN;        /*XXX*/ 
    532                 ieee80211_new_state(&ic->ic_if, IEEE80211_S_RUN, -1); 
     465                ieee80211_new_state(dev, IEEE80211_S_RUN, -1); 
    533466        } else { 
    534467                HAL_CHANNEL *c = sc->sc_cur_chan; 
    535468                ni->ni_chan = ath_hal_ghz2ieee(c->channel, c->channelFlags); 
    536                 ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1); 
     469                ieee80211_new_state(dev, IEEE80211_S_SCAN, -1); 
    537470        } 
    538471        ATH_UNLOCK(sc); 
    539 
    540  
    541 static void 
    542 ath_stop(struct ifnet *ifp, int disable) 
    543 
    544         struct ath_softc *sc = ifp->if_softc; 
     472 
     473        return 0; 
     474
     475 
     476static int 
     477ath_stop(struct net_device *dev) 
     478
     479        struct ath_softc *sc = dev->priv; 
    545480        struct ath_hal *ah = sc->sc_ah; 
    546481        struct ath_buf *bf; 
    547482 
    548483        ATH_LOCK(sc); 
    549         if (!sc->sc_enabled) { 
    550                 ATH_UNLOCK(sc); 
    551                 return; 
    552         } 
    553         DPRINTF(("ath_stop(%d): sc_invalid %u\n", disable, sc->sc_invalid)); 
    554  
    555         ieee80211_new_state(ifp, IEEE80211_S_INIT, -1); 
     484        DPRINTF(("ath_stop: sc_invalid %u\n", sc->sc_invalid)); 
     485 
     486        ieee80211_new_state(dev, IEEE80211_S_INIT, -1); 
    556487        if (!sc->sc_invalid) { 
    557488                /*  
     
    561492                ath_draintxq(sc);               /* clear pending tx frames */ 
    562493                ath_stoprecv(sc);               /* turn off frame recv */ 
    563                 if (disable) 
    564                         ath_hal_setpower(ah, PM_FULL_SLEEP, 0); 
     494                ath_hal_setpower(ah, PM_FULL_SLEEP, 0); 
    565495        } 
    566496        ath_beacon_free(sc); 
    567497        sc->sc_txlink = sc->sc_rxlink = NULL; 
    568         ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE); 
    569         ifp->if_timer = 0; 
     498        dev->flags &= ~IFF_RUNNING; 
     499        sc->sc_oactive = 0; 
     500        sc->sc_ic.ic_timer = 0; 
    570501        sc->sc_tx_timer = 0; 
    571         IF_DRAIN(&ifp->if_snd); 
     502        skb_queue_purge(&sc->sc_sndq); 
    572503 
    573504        /* free transmit queue */ 
    574505        while ((bf = TAILQ_FIRST(&sc->sc_txq)) != NULL) { 
    575                 bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); 
    576                 m_freem(bf->bf_m); 
    577                 bf->bf_m = NULL; 
     506                pci_unmap_single(sc->sc_pci_dev, 
     507                        bf->bf_daddr, bf->bf_skb->len, PCI_DMA_FROMDEVICE); 
     508                dev_kfree_skb(bf->bf_skb); 
     509                bf->bf_skb = NULL; 
    578510                bf->bf_node = NULL; 
    579511                TAILQ_REMOVE(&sc->sc_txq, bf, bf_list); 
    580512                TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list); 
    581513        } 
    582  
    583         if (disable) { 
    584                 if (sc->sc_disable) 
    585                         (*sc->sc_disable)(sc); 
    586                 sc->sc_enabled = 0; 
    587         } 
    588514        ATH_UNLOCK(sc); 
     515 
     516        return 0; 
     517} 
     518 
     519/* 
     520 * Accept packets from above; we queue them and kick the common 
     521 * start code.  This is very un-Linux like but insures any management 
     522 * frames get priority w/o totally mangling the existing logic. 
     523 */ 
     524static int 
     525ath_hardstart(struct sk_buff *skb, struct net_device *dev) 
     526{ 
     527        struct ath_softc *sc = dev->priv; 
     528 
     529        ATH_LOCK(sc); 
     530        skb_queue_tail(&sc->sc_sndq, skb); 
     531        if (!sc->sc_oactive) 
     532                ath_start(dev); 
     533        ATH_UNLOCK(sc); 
    589534} 
    590535 
    591536static void 
    592 ath_start(struct ifnet *ifp
    593 { 
    594         struct ath_softc *sc = ifp->if_softc
     537ath_start(struct net_device *dev
     538{ 
     539        struct ath_softc *sc = dev->priv
    595540        struct ath_hal *ah = sc->sc_ah; 
    596541        struct ieee80211com *ic = &sc->sc_ic; 
    597542        struct ieee80211_node *ni; 
    598543        struct ath_buf *bf; 
    599         struct mbuf *m
     544        struct sk_buff *skb
    600545        struct ieee80211_frame *wh; 
    601546 
    602547        ATH_LOCK(sc); 
    603         if (!sc->sc_enabled || sc->sc_invalid) { 
     548        if (sc->sc_invalid) { 
    604549                ATH_UNLOCK(sc); 
    605550                return; 
     
    614559                 * have priority over normal data frames. 
    615560                 */ 
    616                 IF_POLL(&ic->ic_mgtq, m); 
    617                 if (m != NULL) { 
     561                skb = skb_peek(&ic->ic_mgtq); 
     562                if (skb != NULL) { 
    618563                        if (bf == NULL) { 
    619564                                DPRINTF(("ath_start: out of xmit buffers (mgtq)\n")); 
    620                                 ifp->if_flags |= IFF_OACTIVE
     565                                sc->sc_oactive = 0
    621566                                break; 
    622567                        } 
    623                         IF_DEQUEUE(&ic->ic_mgtq, m); 
    624                         wh = mtod(m, struct ieee80211_frame *)
     568                        skb = skb_dequeue(&ic->ic_mgtq); 
     569                        wh = (struct ieee80211_frame *) skb->data
    625570                        if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == 
    626571                            IEEE80211_FC0_SUBTYPE_PROBE_RESP) { 
     
    633578                                tsf += 100; 
    634579                                tstamp = (u_int32_t *)&wh[1]; 
    635                                 tstamp[0] = htole32(tsf & 0xffffffff); 
    636                                 tstamp[1] = htole32(tsf >> 32); 
     580                                tstamp[0] = cpu_to_le32(tsf & 0xffffffff); 
     581                                tstamp[1] = cpu_to_le32(tsf >> 32); 
    637582                        } 
    638583                } else { 
     
    645590                                break; 
    646591                        } 
    647                         IFQ_POLL(&ifp->if_snd, m); 
    648                         if (m == NULL) 
     592                        skb = skb_peek(&sc->sc_sndq); 
     593                        if (skb == NULL) 
    649594                                break; 
    650595                        if (bf == NULL) { 
    651596                                DPRINTF(("ath_start: out of xmit buffers (data)\n")); 
    652                                 ifp->if_flags |= IFF_OACTIVE
     597                                sc->sc_oactive = 1
    653598                                break; 
    654599                        } 
    655                         IFQ_DEQUEUE(&ifp->if_snd, m); 
    656                         ifp->if_opackets++; 
    657 #if NBPFILTER > 0 
    658                         BPF_MTAP(ifp, m); 
    659 #endif 
     600                        skb = skb_dequeue(&sc->sc_sndq); 
     601                        ic->ic_stats.tx_packets++; 
    660602                        /* 
    661603                         * Encapsulate the packet in prep for transmission. 
    662604                         */ 
    663                         m = ieee80211_encap(ifp, m); 
    664                         if (m == NULL) { 
     605                        skb = ieee80211_encap(dev, skb); 
     606                        if (skb == NULL) { 
    665607                                DPRINTF(("ath_start: encapsulation failure\n")); 
    666608                                sc->sc_stats.ast_tx_encap++; 
    667                                 ifp->if_oerrors++; 
     609                                ic->ic_stats.tx_errors++; 
    668610                                continue; 
    669611                        } 
    670                         wh = mtod(m, struct ieee80211_frame *)
     612                        wh = (struct ieee80211_frame *) skb->data
    671613                        if (ic->ic_flags & IEEE80211_F_WEPON) 
    672614                                wh->i_fc[1] |= IEEE80211_FC1_WEP; 
     
    679621                    (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == 
    680622                    IEEE80211_FC0_TYPE_DATA) { 
    681                         m_freem(m); 
     623                        dev_kfree_skb(skb); 
    682624                        sc->sc_stats.ast_tx_nonode++; 
    683                         ifp->if_oerrors++; 
     625                        ic->ic_stats.tx_errors++; 
    684626                        continue; 
    685627                } 
     
    695637                 */ 
    696638 
    697                 if (IFF_DUMPPKTS(ifp)) 
    698                         ieee80211_dump_pkt(mtod(m, u_int8_t *), m->m_len, 
     639                if (IFF_DUMPPKTS(ic)) 
     640                        ieee80211_dump_pkt(skb->data, skb->len, 
    699641                            ni->ni_rates[ni->ni_txrate] & IEEE80211_RATE_VAL, 
    700642                            -1); 
    701643 
    702                 if (ath_tx_start(sc, ni, bf, m)) { 
    703                         ifp->if_oerrors++; 
     644                if (ath_tx_start(sc, ni, bf, skb)) { 
     645                        ic->ic_stats.tx_errors++; 
    704646                        continue; 
    705647                } 
    706648 
    707649                sc->sc_tx_timer = 5; 
    708                 ifp->if_timer = 1; 
     650                ic->ic_timer = 1; 
    709651        } 
    710652        ATH_UNLOCK(sc); 
     
    712654 
    713655static void 
    714 ath_watchdog(struct ifnet *ifp) 
    715 
    716         struct ath_softc *sc = ifp->if_softc; 
     656ath_watchdog(struct net_device *dev) 
     657
     658        struct ath_softc *sc = dev->priv; 
     659        struct ieee80211com *ic = &sc->sc_ic; 
    717660        struct ieee80211_node *ni; 
    718661 
    719662        ATH_LOCK(sc); 
    720         ifp->if_timer = 0; 
    721         if (!sc->sc_enabled || sc->sc_invalid) { 
     663        ic->ic_timer = 0; 
     664        if (sc->sc_invalid) { 
    722665                ATH_UNLOCK(sc); 
    723666                return; 
     
    725668        if (sc->sc_tx_timer) { 
    726669                if (--sc->sc_tx_timer == 0) { 
    727                         if_printf(ifp, "device timeout\n"); 
     670                        printk("%s: device timeout\n", dev->name); 
    728671                        ath_hal_dumpstate(sc->sc_ah);   /*XXX*/ 
    729                         ath_init(ifp); 
    730                         ifp->if_oerrors++; 
     672                        ath_init(dev); 
     673                        ic->ic_stats.tx_errors++; 
    731674                        sc->sc_stats.ast_watchdog++; 
    732675                        ATH_UNLOCK(sc); 
    733676                        return; 
    734677                } 
    735                 ifp->if_timer = 1; 
     678                ic->ic_timer = 1; 
    736679        } 
    737680        if (sc->sc_ic.ic_opmode == IEEE80211_M_STA) 
     
    742685                } 
    743686        } 
    744         ieee80211_watchdog(ifp); 
     687        ieee80211_watchdog(dev); 
    745688        ATH_UNLOCK(sc); 
    746689} 
    747690 
    748691static int 
    749 ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 
    750 
    751         struct ath_softc *sc = ifp->if_softc; 
    752         struct ifreq *ifr = (struct ifreq *)data; 
     692ath_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 
     693
     694        struct ath_softc *sc = dev->priv; 
    753695        int error = 0; 
    754696 
    755697        ATH_LOCK(sc); 
    756698        switch (cmd) { 
    757         case SIOCSIFFLAGS: 
    758                 if (ifp->if_flags & IFF_UP) { 
    759                         if (sc->sc_enabled) { 
    760                                 /* 
    761                                  * To avoid rescanning another access point, 
    762                                  * do not call ath_init() here.  Instead, 
    763                                  * only reflect promisc mode settings. 
    764                                  */ 
    765                                 ath_mode_init(sc); 
    766                         } else 
    767                                 ath_init(ifp);          /* XXX lose error */ 
    768                 } else if (sc->sc_enabled) 
    769                         ath_stop(ifp, 1); 
    770                 break; 
    771699        case SIOCSIFMEDIA: 
    772700        case SIOCGIFMEDIA: 
    773                 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd); 
    774                 break; 
    775         case SIOCADDMULTI: 
    776         case SIOCDELMULTI: 
    777                 /* 
    778                  * The upper layer has already installed/removed 
    779                  * the multicast address(es), just recalculate the 
    780                  * multicast filter for the card. 
    781                  */ 
    782                 if (sc->sc_enabled) 
    783                         ath_mode_init(sc); 
    784                 break; 
    785         case SIOCGATHSTATS: 
    786                 copyout(&sc->sc_stats, ifr->ifr_data, sizeof (sc->sc_stats)); 
     701                error = ifmedia_ioctl(dev, ifr, &sc->sc_media, cmd); 
    787702                break; 
    788703        default: 
    789                 error = ieee80211_ioctl(ifp, cmd, data); 
     704                /* XXX ifr vs data */ 
     705                error = ieee80211_ioctl(dev, cmd, (caddr_t) ifr); 
    790706                break; 
    791707        } 
    792708        if (error == ENETRESET) { 
    793                 if (sc->sc_enabled) 
    794                         ath_init(ifp);                  /* XXX lose error */ 
     709                ath_init(dev);                  /* XXX lose error */ 
    795710                error = 0; 
    796711        } 
     
    800715 
    801716static int 
    802 ath_media_change(struct ifnet *ifp
    803 { 
    804         struct ath_softc *sc = ifp->if_softc
     717ath_media_change(struct net_device *dev
     718{ 
     719        struct ath_softc *sc = dev->priv
    805720        struct ieee80211com *ic = &sc->sc_ic; 
    806721        struct ifmedia_entry *ime; 
     
    826741                ic->ic_flags &= ~IEEE80211_F_IBSSON; 
    827742        } 
    828         if (sc->sc_enabled) 
    829                 ath_init(ifp);                  /* XXX lose error */ 
     743        ath_init(dev);                  /* XXX lose error */ 
    830744        return error; 
    831745} 
    832746 
    833747static void 
    834 ath_media_status(struct ifnet *ifp, struct ifmediareq *imr) 
    835 { 
    836         struct ath_softc *sc = ifp->if_softc
     748ath_media_status(struct net_device *dev, struct ifmediareq *imr) 
     749{ 
     750        struct ath_softc *sc = dev->priv
    837751        struct ieee80211_node *ni = NULL; 
    838752 
    839753        imr->ifm_status = IFM_AVALID; 
    840754        imr->ifm_active = IFM_IEEE80211; 
    841         if (sc->sc_enabled) { 
    842                 if (sc->sc_ic.ic_state == IEEE80211_S_RUN) 
    843                         imr->ifm_status |= IFM_ACTIVE; 
    844                 imr->ifm_active |= IFM_AUTO; 
    845         } 
     755        if (sc->sc_ic.ic_state == IEEE80211_S_RUN) 
     756                imr->ifm_status |= IFM_ACTIVE; 
     757        imr->ifm_active |= IFM_AUTO; 
    846758        switch (sc->sc_ic.ic_opmode) { 
    847759        case IEEE80211_M_STA: 
     
    908820 
    909821static void 
    910 ath_mode_init(struct ath_softc *sc) 
    911 
     822ath_mode_init(struct net_device *dev) 
     823
     824        struct ath_softc *sc = dev->priv; 
    912825        struct ieee80211com *ic = &sc->sc_ic; 
    913826        struct ath_hal *ah = sc->sc_ah; 
    914         struct ifnet *ifp = &ic->ic_if; 
    915827        u_int32_t rfilt, mfilt[2], val; 
    916828        u_int8_t pos; 
    917         struct ifmultiaddr *ifma
     829        struct dev_mc_list *mc
    918830 
    919831        /* configure operational mode */ 
     
    922834        /* receive filter */ 
    923835        rfilt = HAL_RX_FILTER_UCAST | HAL_RX_FILTER_BCAST | HAL_RX_FILTER_MCAST; 
    924         if (ic->ic_opmode != IEEE80211_M_HOSTAP && 
    925             (ifp->if_flags & IFF_PROMISC)) 
     836        if (ic->ic_opmode != IEEE80211_M_HO