b43legacy: use frame control helpers
[safe/jmp/linux-2.6] / drivers / net / wireless / airo.c
index 32019fb..73d66a8 100644 (file)
@@ -1148,7 +1148,6 @@ static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
 static void airo_networks_free(struct airo_info *ai);
 
 struct airo_info {
-       struct net_device_stats stats;
        struct net_device             *dev;
        struct list_head              dev_list;
        /* Note, we can have MAX_FIDS outstanding.  FIDs are 16-bits, so we
@@ -1924,7 +1923,7 @@ static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
        if (npacks >= MAXTXQ - 1) {
                netif_stop_queue (dev);
                if (npacks > MAXTXQ) {
-                       ai->stats.tx_fifo_errors++;
+                       dev->stats.tx_fifo_errors++;
                        return 1;
                }
                skb_queue_tail (&ai->txq, skb);
@@ -2044,13 +2043,13 @@ static void get_tx_error(struct airo_info *ai, s32 fid)
                bap_read(ai, &status, 2, BAP0);
        }
        if (le16_to_cpu(status) & 2) /* Too many retries */
-               ai->stats.tx_aborted_errors++;
+               ai->dev->stats.tx_aborted_errors++;
        if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
-               ai->stats.tx_heartbeat_errors++;
+               ai->dev->stats.tx_heartbeat_errors++;
        if (le16_to_cpu(status) & 8) /* Aid fail */
                { }
        if (le16_to_cpu(status) & 0x10) /* MAC disabled */
-               ai->stats.tx_carrier_errors++;
+               ai->dev->stats.tx_carrier_errors++;
        if (le16_to_cpu(status) & 0x20) /* Association lost */
                { }
        /* We produce a TXDROP event only for retry or lifetime
@@ -2102,7 +2101,7 @@ static void airo_end_xmit(struct net_device *dev) {
                for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
        } else {
                priv->fids[fid] &= 0xffff;
-               priv->stats.tx_window_errors++;
+               dev->stats.tx_window_errors++;
        }
        if (i < MAX_FIDS / 2)
                netif_wake_queue(dev);
@@ -2128,7 +2127,7 @@ static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
                netif_stop_queue(dev);
 
                if (i == MAX_FIDS / 2) {
-                       priv->stats.tx_fifo_errors++;
+                       dev->stats.tx_fifo_errors++;
                        return 1;
                }
        }
@@ -2167,7 +2166,7 @@ static void airo_end_xmit11(struct net_device *dev) {
                for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
        } else {
                priv->fids[fid] &= 0xffff;
-               priv->stats.tx_window_errors++;
+               dev->stats.tx_window_errors++;
        }
        if (i < MAX_FIDS)
                netif_wake_queue(dev);
@@ -2199,7 +2198,7 @@ static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
                netif_stop_queue(dev);
 
                if (i == MAX_FIDS) {
-                       priv->stats.tx_fifo_errors++;
+                       dev->stats.tx_fifo_errors++;
                        return 1;
                }
        }
@@ -2219,8 +2218,9 @@ static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
        return 0;
 }
 
-static void airo_read_stats(struct airo_info *ai)
+static void airo_read_stats(struct net_device *dev)
 {
+       struct airo_info *ai = dev->priv;
        StatsRid stats_rid;
        __le32 *vals = stats_rid.vals;
 
@@ -2232,23 +2232,24 @@ static void airo_read_stats(struct airo_info *ai)
        readStatsRid(ai, &stats_rid, RID_STATS, 0);
        up(&ai->sem);
 
-       ai->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) +
+       dev->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) +
                               le32_to_cpu(vals[45]);
-       ai->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) +
+       dev->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) +
                               le32_to_cpu(vals[41]);
-       ai->stats.rx_bytes = le32_to_cpu(vals[92]);
-       ai->stats.tx_bytes = le32_to_cpu(vals[91]);
-       ai->stats.rx_errors = le32_to_cpu(vals[0]) + le32_to_cpu(vals[2]) +
+       dev->stats.rx_bytes = le32_to_cpu(vals[92]);
+       dev->stats.tx_bytes = le32_to_cpu(vals[91]);
+       dev->stats.rx_errors = le32_to_cpu(vals[0]) + le32_to_cpu(vals[2]) +
                              le32_to_cpu(vals[3]) + le32_to_cpu(vals[4]);
-       ai->stats.tx_errors = le32_to_cpu(vals[42]) + ai->stats.tx_fifo_errors;
-       ai->stats.multicast = le32_to_cpu(vals[43]);
-       ai->stats.collisions = le32_to_cpu(vals[89]);
+       dev->stats.tx_errors = le32_to_cpu(vals[42]) +
+                             dev->stats.tx_fifo_errors;
+       dev->stats.multicast = le32_to_cpu(vals[43]);
+       dev->stats.collisions = le32_to_cpu(vals[89]);
 
        /* detailed rx_errors: */
-       ai->stats.rx_length_errors = le32_to_cpu(vals[3]);
-       ai->stats.rx_crc_errors = le32_to_cpu(vals[4]);
-       ai->stats.rx_frame_errors = le32_to_cpu(vals[2]);
-       ai->stats.rx_fifo_errors = le32_to_cpu(vals[0]);
+       dev->stats.rx_length_errors = le32_to_cpu(vals[3]);
+       dev->stats.rx_crc_errors = le32_to_cpu(vals[4]);
+       dev->stats.rx_frame_errors = le32_to_cpu(vals[2]);
+       dev->stats.rx_fifo_errors = le32_to_cpu(vals[0]);
 }
 
 static struct net_device_stats *airo_get_stats(struct net_device *dev)
@@ -2261,10 +2262,10 @@ static struct net_device_stats *airo_get_stats(struct net_device *dev)
                        set_bit(JOB_STATS, &local->jobs);
                        wake_up_interruptible(&local->thr_wait);
                } else
-                       airo_read_stats(local);
+                       airo_read_stats(dev);
        }
 
-       return &local->stats;
+       return &dev->stats;
 }
 
 static void airo_set_promisc(struct airo_info *ai) {
@@ -3093,7 +3094,7 @@ static int airo_thread(void *data) {
                else if (test_bit(JOB_XMIT11, &ai->jobs))
                        airo_end_xmit11(dev);
                else if (test_bit(JOB_STATS, &ai->jobs))
-                       airo_read_stats(ai);
+                       airo_read_stats(dev);
                else if (test_bit(JOB_WSTATS, &ai->jobs))
                        airo_read_wireless_stats(ai);
                else if (test_bit(JOB_PROMISC, &ai->jobs))
@@ -3289,7 +3290,7 @@ static irqreturn_t airo_interrupt(int irq, void *dev_id)
 
                        skb = dev_alloc_skb( len + hdrlen + 2 + 2 );
                        if ( !skb ) {
-                               apriv->stats.rx_dropped++;
+                               dev->stats.rx_dropped++;
                                goto badrx;
                        }
                        skb_reserve(skb, 2); /* This way the IP header is aligned */
@@ -3557,7 +3558,7 @@ static void mpi_receive_802_3(struct airo_info *ai)
 
                skb = dev_alloc_skb(len);
                if (!skb) {
-                       ai->stats.rx_dropped++;
+                       ai->dev->stats.rx_dropped++;
                        goto badrx;
                }
                buffer = skb_put(skb,len);
@@ -3650,7 +3651,7 @@ void mpi_receive_802_11 (struct airo_info *ai)
 
        skb = dev_alloc_skb( len + hdrlen + 2 );
        if ( !skb ) {
-               ai->stats.rx_dropped++;
+               ai->dev->stats.rx_dropped++;
                goto badrx;
        }
        buffer = (u16*)skb_put (skb, len + hdrlen);
@@ -4560,22 +4561,13 @@ static ssize_t proc_read( struct file *file,
                          size_t len,
                          loff_t *offset )
 {
-       loff_t pos = *offset;
-       struct proc_data *priv = (struct proc_data*)file->private_data;
+       struct proc_data *priv = file->private_data;
 
        if (!priv->rbuffer)
                return -EINVAL;
 
-       if (pos < 0)
-               return -EINVAL;
-       if (pos >= priv->readlen)
-               return 0;
-       if (len > priv->readlen - pos)
-               len = priv->readlen - pos;
-       if (copy_to_user(buffer, priv->rbuffer + pos, len))
-               return -EFAULT;
-       *offset = pos + len;
-       return len;
+       return simple_read_from_buffer(buffer, len, offset, priv->rbuffer,
+                                       priv->readlen);
 }
 
 /*
@@ -7164,6 +7156,7 @@ out:
  * format that the Wireless Tools will understand - Jean II
  */
 static inline char *airo_translate_scan(struct net_device *dev,
+                                       struct iw_request_info *info,
                                        char *current_ev,
                                        char *end_buf,
                                        BSSListRid *bss)
@@ -7180,7 +7173,8 @@ static inline char *airo_translate_scan(struct net_device *dev,
        iwe.cmd = SIOCGIWAP;
        iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
        memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
-       current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
+       current_ev = iwe_stream_add_event(info, current_ev, end_buf,
+                                         &iwe, IW_EV_ADDR_LEN);
 
        /* Other entries will be displayed in the order we give them */
 
@@ -7190,7 +7184,8 @@ static inline char *airo_translate_scan(struct net_device *dev,
                iwe.u.data.length = 32;
        iwe.cmd = SIOCGIWESSID;
        iwe.u.data.flags = 1;
-       current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
+       current_ev = iwe_stream_add_point(info, current_ev, end_buf,
+                                         &iwe, bss->ssid);
 
        /* Add mode */
        iwe.cmd = SIOCGIWMODE;
@@ -7200,7 +7195,8 @@ static inline char *airo_translate_scan(struct net_device *dev,
                        iwe.u.mode = IW_MODE_MASTER;
                else
                        iwe.u.mode = IW_MODE_ADHOC;
-               current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
+               current_ev = iwe_stream_add_event(info, current_ev, end_buf,
+                                                 &iwe, IW_EV_UINT_LEN);
        }
 
        /* Add frequency */
@@ -7211,7 +7207,8 @@ static inline char *airo_translate_scan(struct net_device *dev,
         */
        iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
        iwe.u.freq.e = 1;
-       current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
+       current_ev = iwe_stream_add_event(info, current_ev, end_buf,
+                                         &iwe, IW_EV_FREQ_LEN);
 
        dBm = le16_to_cpu(bss->dBm);
 
@@ -7231,7 +7228,8 @@ static inline char *airo_translate_scan(struct net_device *dev,
                                | IW_QUAL_DBM;
        }
        iwe.u.qual.noise = ai->wstats.qual.noise;
-       current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
+       current_ev = iwe_stream_add_event(info, current_ev, end_buf,
+                                         &iwe, IW_EV_QUAL_LEN);
 
        /* Add encryption capability */
        iwe.cmd = SIOCGIWENCODE;
@@ -7240,11 +7238,12 @@ static inline char *airo_translate_scan(struct net_device *dev,
        else
                iwe.u.data.flags = IW_ENCODE_DISABLED;
        iwe.u.data.length = 0;
-       current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
+       current_ev = iwe_stream_add_point(info, current_ev, end_buf,
+                                         &iwe, bss->ssid);
 
        /* Rate : stuffing multiple values in a single event require a bit
         * more of magic - Jean II */
-       current_val = current_ev + IW_EV_LCP_LEN;
+       current_val = current_ev + iwe_stream_lcp_len(info);
 
        iwe.cmd = SIOCGIWRATE;
        /* Those two flags are ignored... */
@@ -7257,10 +7256,12 @@ static inline char *airo_translate_scan(struct net_device *dev,
                /* Bit rate given in 500 kb/s units (+ 0x80) */
                iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
                /* Add new value to event */
-               current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
+               current_val = iwe_stream_add_value(info, current_ev,
+                                                  current_val, end_buf,
+                                                  &iwe, IW_EV_PARAM_LEN);
        }
        /* Check if we added any event */
-       if((current_val - current_ev) > IW_EV_LCP_LEN)
+       if ((current_val - current_ev) > iwe_stream_lcp_len(info))
                current_ev = current_val;
 
        /* Beacon interval */
@@ -7269,7 +7270,8 @@ static inline char *airo_translate_scan(struct net_device *dev,
                iwe.cmd = IWEVCUSTOM;
                sprintf(buf, "bcn_int=%d", bss->beaconInterval);
                iwe.u.data.length = strlen(buf);
-               current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, buf);
+               current_ev = iwe_stream_add_point(info, current_ev, end_buf,
+                                                 &iwe, buf);
                kfree(buf);
        }
 
@@ -7303,8 +7305,10 @@ static inline char *airo_translate_scan(struct net_device *dev,
                                        iwe.cmd = IWEVGENIE;
                                        iwe.u.data.length = min(info_element->len + 2,
                                                                  MAX_WPA_IE_LEN);
-                                       current_ev = iwe_stream_add_point(current_ev, end_buf,
-                                                       &iwe, (char *) info_element);
+                                       current_ev = iwe_stream_add_point(
+                                                       info, current_ev,
+                                                       end_buf, &iwe,
+                                                       (char *) info_element);
                                }
                                break;
 
@@ -7312,8 +7316,9 @@ static inline char *airo_translate_scan(struct net_device *dev,
                                iwe.cmd = IWEVGENIE;
                                iwe.u.data.length = min(info_element->len + 2,
                                                          MAX_WPA_IE_LEN);
-                               current_ev = iwe_stream_add_point(current_ev, end_buf,
-                                               &iwe, (char *) info_element);
+                               current_ev = iwe_stream_add_point(
+                                       info, current_ev, end_buf,
+                                       &iwe, (char *) info_element);
                                break;
 
                        default:
@@ -7352,7 +7357,7 @@ static int airo_get_scan(struct net_device *dev,
 
        list_for_each_entry (net, &ai->network_list, list) {
                /* Translate to WE format this entry */
-               current_ev = airo_translate_scan(dev, current_ev,
+               current_ev = airo_translate_scan(dev, info, current_ev,
                                                 extra + dwrq->length,
                                                 &net->bss);