Both ath5k_hw and ath5k_softc represent one instance of the hardware.
This duplication is historical and is not needed anymore.

Keep the name "ath5k_hw" for the merged structure and "ah" for the
variable pointing to it.  "ath5k_hw" is shorter than "ath5k_softc", more
descriptive and more widely used.

Put the combined structure to ath5k.h where the old ath5k_softc used to
be. Move some code from base.h to ath5k.h as needed.

Remove memory allocation for struct ath5k_hw and the corresponding error
handling.  Merge iobase and ah_iobase fields.

This patch should be applied after running following commands in the
ath5k directory:

sed -i '
s/\<ath5k_softc\>/ath5k_hw/g
s/\<sc\>/ah/g
s/\<ah->ah\>/ah/g
s/\<ah->ah_sc\>/ah/g
/struct ath5k_hw \*ah = ah;/d
s/struct ath5k_hw \*ah, struct ath5k_hw \*ah/struct ath5k_hw *ah/
/^\tah = ah;/d
s/(ah, ah)/(ah)/g
/struct ath5k_hw;$/{N;s/struct ath5k_hw;\nstruct ath5k_hw;/struct ath5k_hw;/}
s/ ah / sc /
' $i *.[ch]
sed -i '/{$/{N;s/{\n$/{/}' rfkill.c

Signed-off-by: Pavel Roskin <[email protected]>
---
 drivers/net/wireless/ath/ath5k/ath5k.h |  201 +++++++++++++++++++++++++++++++-
 drivers/net/wireless/ath/ath5k/base.c  |   14 --
 drivers/net/wireless/ath/ath5k/base.h  |  196 -------------------------------
 3 files changed, 193 insertions(+), 218 deletions(-)

diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h 
b/drivers/net/wireless/ath/ath5k/ath5k.h
index fe8c8cb..a87150f 100644
--- a/drivers/net/wireless/ath/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath/ath5k/ath5k.h
@@ -26,6 +26,7 @@
 #include <linux/io.h>
 #include <linux/types.h>
 #include <linux/average.h>
+#include <linux/leds.h>
 #include <net/mac80211.h>
 
 /* RX/TX descriptor hw structs
@@ -36,7 +37,9 @@
  * TODO: Make a more generic struct (eg. add more stuff to ath5k_capabilities)
  * and clean up common bits, then introduce set/get functions in eeprom.c */
 #include "eeprom.h"
+#include "debug.h"
 #include "../ath.h"
+#include "ani.h"
 
 /* PCI IDs */
 #define PCI_DEVICE_ID_ATHEROS_AR5210           0x0007 /* AR5210 */
@@ -538,6 +541,27 @@ enum ath5k_tx_queue_id {
 #define AR5K_TXQ_FLAG_COMPRESSION_ENABLE       0x2000  /* Enable hw 
compression -not implemented-*/
 
 /*
+ * Data transmit queue state.  One of these exists for each
+ * hardware transmit queue.  Packets sent to us from above
+ * are assigned to queues based on their priority.  Not all
+ * devices support a complete set of hardware transmit queues.
+ * For those devices the array sc_ac2q will map multiple
+ * priorities to fewer hardware queues (typically all to one
+ * hardware queue).
+ */
+struct ath5k_txq {
+       unsigned int            qnum;   /* hardware q number */
+       u32                     *link;  /* link ptr in last TX desc */
+       struct list_head        q;      /* transmit queue */
+       spinlock_t              lock;   /* lock on q and link */
+       bool                    setup;
+       int                     txq_len; /* number of queued buffers */
+       int                     txq_max; /* max allowed num of queued buffers */
+       bool                    txq_poll_mark;
+       unsigned int            txq_stuck;      /* informational counter */
+};
+
+/*
  * A struct to hold tx queue's parameters
  */
 struct ath5k_txq_info {
@@ -1027,9 +1051,66 @@ struct ath5k_avg_val {
        int avg_weight;
 };
 
-/***************************************\
-  HARDWARE ABSTRACTION LAYER STRUCTURE
-\***************************************/
+#define ATH5K_LED_MAX_NAME_LEN 31
+
+/*
+ * State for LED triggers
+ */
+struct ath5k_led {
+       char name[ATH5K_LED_MAX_NAME_LEN + 1];  /* name of the LED in sysfs */
+       struct ath5k_hw *ah;                    /* driver state */
+       struct led_classdev led_dev;            /* led classdev */
+};
+
+/* Rfkill */
+struct ath5k_rfkill {
+       /* GPIO PIN for rfkill */
+       u16 gpio;
+       /* polarity of rfkill GPIO PIN */
+       bool polarity;
+       /* RFKILL toggle tasklet */
+       struct tasklet_struct toggleq;
+};
+
+/* statistics */
+struct ath5k_statistics {
+       /* antenna use */
+       unsigned int antenna_rx[5];     /* frames count per antenna RX */
+       unsigned int antenna_tx[5];     /* frames count per antenna TX */
+
+       /* frame errors */
+       unsigned int rx_all_count;      /* all RX frames, including errors */
+       unsigned int tx_all_count;      /* all TX frames, including errors */
+       unsigned int rx_bytes_count;    /* all RX bytes, including errored pkts
+                                        * and the MAC headers for each packet
+                                        */
+       unsigned int tx_bytes_count;    /* all TX bytes, including errored pkts
+                                        * and the MAC headers and padding for
+                                        * each packet.
+                                        */
+       unsigned int rxerr_crc;
+       unsigned int rxerr_phy;
+       unsigned int rxerr_phy_code[32];
+       unsigned int rxerr_fifo;
+       unsigned int rxerr_decrypt;
+       unsigned int rxerr_mic;
+       unsigned int rxerr_proc;
+       unsigned int rxerr_jumbo;
+       unsigned int txerr_retry;
+       unsigned int txerr_fifo;
+       unsigned int txerr_filt;
+
+       /* MIB counters */
+       unsigned int ack_fail;
+       unsigned int rts_fail;
+       unsigned int rts_ok;
+       unsigned int fcs_error;
+       unsigned int beacons;
+
+       unsigned int mib_intr;
+       unsigned int rxorn_intr;
+       unsigned int rxeol_intr;
+};
 
 /*
  * Misc defines
@@ -1038,12 +1119,114 @@ struct ath5k_avg_val {
 #define AR5K_MAX_GPIO          10
 #define AR5K_MAX_RF_BANKS      8
 
-/* TODO: Clean up and merge with ath5k_hw */
+#if CHAN_DEBUG
+#define ATH_CHAN_MAX   (26 + 26 + 26 + 200 + 200)
+#else
+#define ATH_CHAN_MAX   (14 + 14 + 14 + 252 + 20)
+#endif
+
+#define        ATH_RXBUF       40              /* number of RX buffers */
+#define        ATH_TXBUF       200             /* number of TX buffers */
+#define ATH_BCBUF      4               /* number of beacon buffers */
+#define ATH5K_TXQ_LEN_MAX      (ATH_TXBUF / 4)         /* bufs per queue */
+#define ATH5K_TXQ_LEN_LOW      (ATH5K_TXQ_LEN_MAX / 2) /* low mark */
+
+/* Driver state associated with an instance of a device */
 struct ath5k_hw {
        struct ath_common       common;
 
-       struct ath5k_hw *ah_sc;
-       void __iomem            *ah_iobase;
+       struct pci_dev          *pdev;
+       struct device           *dev;           /* for dma mapping */
+       int irq;
+       u16 devid;
+       void __iomem            *iobase;        /* address of the device */
+       struct mutex            lock;           /* dev-level lock */
+       struct ieee80211_hw     *hw;            /* IEEE 802.11 common */
+       struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
+       struct ieee80211_channel channels[ATH_CHAN_MAX];
+       struct ieee80211_rate   rates[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
+       s8                      rate_idx[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
+       enum nl80211_iftype     opmode;
+
+#ifdef CONFIG_ATH5K_DEBUG
+       struct ath5k_dbg_info   debug;          /* debug info */
+#endif /* CONFIG_ATH5K_DEBUG */
+
+       struct ath5k_buf        *bufptr;        /* allocated buffer ptr */
+       struct ath5k_desc       *desc;          /* TX/RX descriptors */
+       dma_addr_t              desc_daddr;     /* DMA (physical) address */
+       size_t                  desc_len;       /* size of TX/RX descriptors */
+
+       DECLARE_BITMAP(status, 6);
+#define ATH_STAT_INVALID       0               /* disable hardware accesses */
+#define ATH_STAT_MRRETRY       1               /* multi-rate retry support */
+#define ATH_STAT_PROMISC       2
+#define ATH_STAT_LEDSOFT       3               /* enable LED gpio status */
+#define ATH_STAT_STARTED       4               /* opened & irqs enabled */
+#define ATH_STAT_2G_DISABLED   5               /* multiband radio without 2G */
+
+       unsigned int            filter_flags;   /* HW flags, AR5K_RX_FILTER_* */
+       struct ieee80211_channel *curchan;      /* current h/w channel */
+
+       u16                     nvifs;
+
+       enum ath5k_int          imask;          /* interrupt mask copy */
+
+       spinlock_t              irqlock;
+       bool                    rx_pending;     /* rx tasklet pending */
+       bool                    tx_pending;     /* tx tasklet pending */
+
+       u8                      lladdr[ETH_ALEN];
+       u8                      bssidmask[ETH_ALEN];
+
+       unsigned int            led_pin,        /* GPIO pin for driving LED */
+                               led_on;         /* pin setting for LED on */
+
+       struct work_struct      reset_work;     /* deferred chip reset */
+
+       unsigned int            rxbufsize;      /* rx size based on mtu */
+       struct list_head        rxbuf;          /* receive buffer */
+       spinlock_t              rxbuflock;
+       u32                     *rxlink;        /* link ptr in last RX desc */
+       struct tasklet_struct   rxtq;           /* rx intr tasklet */
+       struct ath5k_led        rx_led;         /* rx led */
+
+       struct list_head        txbuf;          /* transmit buffer */
+       spinlock_t              txbuflock;
+       unsigned int            txbuf_len;      /* buf count in txbuf list */
+       struct ath5k_txq        txqs[AR5K_NUM_TX_QUEUES];       /* tx queues */
+       struct tasklet_struct   txtq;           /* tx intr tasklet */
+       struct ath5k_led        tx_led;         /* tx led */
+
+       struct ath5k_rfkill     rf_kill;
+
+       struct tasklet_struct   calib;          /* calibration tasklet */
+
+       spinlock_t              block;          /* protects beacon */
+       struct tasklet_struct   beacontq;       /* beacon intr tasklet */
+       struct list_head        bcbuf;          /* beacon buffer */
+       struct ieee80211_vif    *bslot[ATH_BCBUF];
+       u16                     num_ap_vifs;
+       u16                     num_adhoc_vifs;
+       unsigned int            bhalq,          /* SW q for outgoing beacons */
+                               bmisscount,     /* missed beacon transmits */
+                               bintval,        /* beacon interval in TU */
+                               bsent;
+       unsigned int            nexttbtt;       /* next beacon time in TU */
+       struct ath5k_txq        *cabq;          /* content after beacon */
+
+       int                     power_level;    /* Requested tx power in dBm */
+       bool                    assoc;          /* associate state */
+       bool                    enable_beacon;  /* true if beacons are on */
+
+       struct ath5k_statistics stats;
+
+       struct ath5k_ani_state  ani_state;
+       struct tasklet_struct   ani_tasklet;    /* ANI calibration */
+
+       struct delayed_work     tx_complete_work;
+
+       struct survey_info      survey;         /* collected survey info */
 
        enum ath5k_int          ah_imr;
 
@@ -1384,7 +1567,7 @@ static inline void __iomem *ath5k_ahb_reg(struct ath5k_hw 
*ah, u16 reg)
            (ah->ah_mac_srev >= AR5K_SREV_AR2315_R6)))
                return AR5K_AR2315_PCI_BASE + reg;
 
-       return ah->ah_iobase + reg;
+       return ah->iobase + reg;
 }
 
 static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
@@ -1401,12 +1584,12 @@ static inline void ath5k_hw_reg_write(struct ath5k_hw 
*ah, u32 val, u16 reg)
 
 static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
 {
-       return ioread32(ah->ah_iobase + reg);
+       return ioread32(ah->iobase + reg);
 }
 
 static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
 {
-       iowrite32(val, ah->ah_iobase + reg);
+       iowrite32(val, ah->iobase + reg);
 }
 
 #endif
diff --git a/drivers/net/wireless/ath/ath5k/base.c 
b/drivers/net/wireless/ath/ath5k/base.c
index c4b688c..20e4ef4 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -2391,15 +2391,6 @@ ath5k_init_softc(struct ath5k_hw *ah, const struct 
ath_bus_ops *bus_ops)
                goto err;
        }
 
-       /* If we passed the test, malloc an ath5k_hw struct */
-       ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
-       if (!ah) {
-               ret = -ENOMEM;
-               ATH5K_ERR(ah, "out of memory\n");
-               goto err_irq;
-       }
-
-       ah->ah_iobase = ah->iobase;
        common = ath5k_hw_common(ah);
        common->ops = &ath5k_common_ops;
        common->bus_ops = bus_ops;
@@ -2420,7 +2411,7 @@ ath5k_init_softc(struct ath5k_hw *ah, const struct 
ath_bus_ops *bus_ops)
        /* Initialize device */
        ret = ath5k_hw_init(ah);
        if (ret)
-               goto err_free_ah;
+               goto err_irq;
 
        /* set up multi-rate retry capabilities */
        if (ah->ah_version == AR5K_AR5212) {
@@ -2492,8 +2483,6 @@ ath5k_init_softc(struct ath5k_hw *ah, const struct 
ath_bus_ops *bus_ops)
        return 0;
 err_ah:
        ath5k_hw_deinit(ah);
-err_free_ah:
-       kfree(ah);
 err_irq:
        free_irq(ah->irq, ah);
 err:
@@ -2940,7 +2929,6 @@ ath5k_deinit_softc(struct ath5k_hw *ah)
         * state and potentially want to use them.
         */
        ath5k_hw_deinit(ah);
-       kfree(ah);
        free_irq(ah->irq, ah);
 }
 
diff --git a/drivers/net/wireless/ath/ath5k/base.h 
b/drivers/net/wireless/ath/ath5k/base.h
index 870bebf..aa8aafc 100644
--- a/drivers/net/wireless/ath/ath5k/base.h
+++ b/drivers/net/wireless/ath/ath5k/base.h
@@ -45,23 +45,13 @@
 #include <linux/list.h>
 #include <linux/wireless.h>
 #include <linux/if_ether.h>
-#include <linux/leds.h>
 #include <linux/rfkill.h>
 #include <linux/workqueue.h>
 
 #include "ath5k.h"
-#include "debug.h"
-#include "ani.h"
-
 #include "../regd.h"
 #include "../ath.h"
 
-#define        ATH_RXBUF       40              /* number of RX buffers */
-#define        ATH_TXBUF       200             /* number of TX buffers */
-#define ATH_BCBUF      4               /* number of beacon buffers */
-#define ATH5K_TXQ_LEN_MAX      (ATH_TXBUF / 4)         /* bufs per queue */
-#define ATH5K_TXQ_LEN_LOW      (ATH5K_TXQ_LEN_MAX / 2) /* low mark */
-
 struct ath5k_buf {
        struct list_head        list;
        struct ath5k_desc       *desc;  /* virtual addr of desc */
@@ -70,94 +60,6 @@ struct ath5k_buf {
        dma_addr_t              skbaddr;/* physical addr of skb data */
 };
 
-/*
- * Data transmit queue state.  One of these exists for each
- * hardware transmit queue.  Packets sent to us from above
- * are assigned to queues based on their priority.  Not all
- * devices support a complete set of hardware transmit queues.
- * For those devices the array sc_ac2q will map multiple
- * priorities to fewer hardware queues (typically all to one
- * hardware queue).
- */
-struct ath5k_txq {
-       unsigned int            qnum;   /* hardware q number */
-       u32                     *link;  /* link ptr in last TX desc */
-       struct list_head        q;      /* transmit queue */
-       spinlock_t              lock;   /* lock on q and link */
-       bool                    setup;
-       int                     txq_len; /* number of queued buffers */
-       int                     txq_max; /* max allowed num of queued buffers */
-       bool                    txq_poll_mark;
-       unsigned int            txq_stuck;      /* informational counter */
-};
-
-#define ATH5K_LED_MAX_NAME_LEN 31
-
-/*
- * State for LED triggers
- */
-struct ath5k_led {
-       char name[ATH5K_LED_MAX_NAME_LEN + 1];  /* name of the LED in sysfs */
-       struct ath5k_hw *ah;                    /* driver state */
-       struct led_classdev led_dev;            /* led classdev */
-};
-
-/* Rfkill */
-struct ath5k_rfkill {
-       /* GPIO PIN for rfkill */
-       u16 gpio;
-       /* polarity of rfkill GPIO PIN */
-       bool polarity;
-       /* RFKILL toggle tasklet */
-       struct tasklet_struct toggleq;
-};
-
-/* statistics */
-struct ath5k_statistics {
-       /* antenna use */
-       unsigned int antenna_rx[5];     /* frames count per antenna RX */
-       unsigned int antenna_tx[5];     /* frames count per antenna TX */
-
-       /* frame errors */
-       unsigned int rx_all_count;      /* all RX frames, including errors */
-       unsigned int tx_all_count;      /* all TX frames, including errors */
-       unsigned int rx_bytes_count;    /* all RX bytes, including errored pkts
-                                        * and the MAC headers for each packet
-                                        */
-       unsigned int tx_bytes_count;    /* all TX bytes, including errored pkts
-                                        * and the MAC headers and padding for
-                                        * each packet.
-                                        */
-       unsigned int rxerr_crc;
-       unsigned int rxerr_phy;
-       unsigned int rxerr_phy_code[32];
-       unsigned int rxerr_fifo;
-       unsigned int rxerr_decrypt;
-       unsigned int rxerr_mic;
-       unsigned int rxerr_proc;
-       unsigned int rxerr_jumbo;
-       unsigned int txerr_retry;
-       unsigned int txerr_fifo;
-       unsigned int txerr_filt;
-
-       /* MIB counters */
-       unsigned int ack_fail;
-       unsigned int rts_fail;
-       unsigned int rts_ok;
-       unsigned int fcs_error;
-       unsigned int beacons;
-
-       unsigned int mib_intr;
-       unsigned int rxorn_intr;
-       unsigned int rxeol_intr;
-};
-
-#if CHAN_DEBUG
-#define ATH_CHAN_MAX   (26 + 26 + 26 + 200 + 200)
-#else
-#define ATH_CHAN_MAX   (14 + 14 + 14 + 252 + 20)
-#endif
-
 struct ath5k_vif {
        bool                    assoc; /* are we associated or not */
        enum nl80211_iftype     opmode;
@@ -166,104 +68,6 @@ struct ath5k_vif {
        u8                      lladdr[ETH_ALEN];
 };
 
-/* Software Carrier, keeps track of the driver state
- * associated with an instance of a device */
-struct ath5k_hw {
-       struct pci_dev          *pdev;
-       struct device           *dev;           /* for dma mapping */
-       int irq;
-       u16 devid;
-       void __iomem            *iobase;        /* address of the device */
-       struct mutex            lock;           /* dev-level lock */
-       struct ieee80211_hw     *hw;            /* IEEE 802.11 common */
-       struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
-       struct ieee80211_channel channels[ATH_CHAN_MAX];
-       struct ieee80211_rate   rates[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
-       s8                      rate_idx[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
-       enum nl80211_iftype     opmode;
-       struct ath5k_hw         *ah;            /* Atheros HW */
-
-#ifdef CONFIG_ATH5K_DEBUG
-       struct ath5k_dbg_info   debug;          /* debug info */
-#endif /* CONFIG_ATH5K_DEBUG */
-
-       struct ath5k_buf        *bufptr;        /* allocated buffer ptr */
-       struct ath5k_desc       *desc;          /* TX/RX descriptors */
-       dma_addr_t              desc_daddr;     /* DMA (physical) address */
-       size_t                  desc_len;       /* size of TX/RX descriptors */
-
-       DECLARE_BITMAP(status, 6);
-#define ATH_STAT_INVALID       0               /* disable hardware accesses */
-#define ATH_STAT_MRRETRY       1               /* multi-rate retry support */
-#define ATH_STAT_PROMISC       2
-#define ATH_STAT_LEDSOFT       3               /* enable LED gpio status */
-#define ATH_STAT_STARTED       4               /* opened & irqs enabled */
-#define ATH_STAT_2G_DISABLED   5               /* multiband radio without 2G */
-
-       unsigned int            filter_flags;   /* HW flags, AR5K_RX_FILTER_* */
-       struct ieee80211_channel *curchan;      /* current h/w channel */
-
-       u16                     nvifs;
-
-       enum ath5k_int          imask;          /* interrupt mask copy */
-
-       spinlock_t              irqlock;
-       bool                    rx_pending;     /* rx tasklet pending */
-       bool                    tx_pending;     /* tx tasklet pending */
-
-       u8                      lladdr[ETH_ALEN];
-       u8                      bssidmask[ETH_ALEN];
-
-       unsigned int            led_pin,        /* GPIO pin for driving LED */
-                               led_on;         /* pin setting for LED on */
-
-       struct work_struct      reset_work;     /* deferred chip reset */
-
-       unsigned int            rxbufsize;      /* rx size based on mtu */
-       struct list_head        rxbuf;          /* receive buffer */
-       spinlock_t              rxbuflock;
-       u32                     *rxlink;        /* link ptr in last RX desc */
-       struct tasklet_struct   rxtq;           /* rx intr tasklet */
-       struct ath5k_led        rx_led;         /* rx led */
-
-       struct list_head        txbuf;          /* transmit buffer */
-       spinlock_t              txbuflock;
-       unsigned int            txbuf_len;      /* buf count in txbuf list */
-       struct ath5k_txq        txqs[AR5K_NUM_TX_QUEUES];       /* tx queues */
-       struct tasklet_struct   txtq;           /* tx intr tasklet */
-       struct ath5k_led        tx_led;         /* tx led */
-
-       struct ath5k_rfkill     rf_kill;
-
-       struct tasklet_struct   calib;          /* calibration tasklet */
-
-       spinlock_t              block;          /* protects beacon */
-       struct tasklet_struct   beacontq;       /* beacon intr tasklet */
-       struct list_head        bcbuf;          /* beacon buffer */
-       struct ieee80211_vif    *bslot[ATH_BCBUF];
-       u16                     num_ap_vifs;
-       u16                     num_adhoc_vifs;
-       unsigned int            bhalq,          /* SW q for outgoing beacons */
-                               bmisscount,     /* missed beacon transmits */
-                               bintval,        /* beacon interval in TU */
-                               bsent;
-       unsigned int            nexttbtt;       /* next beacon time in TU */
-       struct ath5k_txq        *cabq;          /* content after beacon */
-
-       int                     power_level;    /* Requested tx power in dBm */
-       bool                    assoc;          /* associate state */
-       bool                    enable_beacon;  /* true if beacons are on */
-
-       struct ath5k_statistics stats;
-
-       struct ath5k_ani_state  ani_state;
-       struct tasklet_struct   ani_tasklet;    /* ANI calibration */
-
-       struct delayed_work     tx_complete_work;
-
-       struct survey_info      survey;         /* collected survey info */
-};
-
 struct ath5k_vif_iter_data {
        const u8        *hw_macaddr;
        u8              mask[ETH_ALEN];
_______________________________________________
ath5k-devel mailing list
[email protected]
https://lists.ath5k.org/mailman/listinfo/ath5k-devel

Reply via email to