mac80211_hwsim: fix unregistration
[safe/jmp/linux-2.6] / drivers / net / wireless / b43legacy / dma.c
index 33cc256..2f90fb9 100644 (file)
@@ -393,13 +393,13 @@ dma_addr_t map_descbuffer(struct b43legacy_dmaring *ring,
        dma_addr_t dmaaddr;
 
        if (tx)
-               dmaaddr = dma_map_single(ring->dev->dev->dma_dev,
-                                        buf, len,
-                                        DMA_TO_DEVICE);
+               dmaaddr = ssb_dma_map_single(ring->dev->dev,
+                                            buf, len,
+                                            DMA_TO_DEVICE);
        else
-               dmaaddr = dma_map_single(ring->dev->dev->dma_dev,
-                                        buf, len,
-                                        DMA_FROM_DEVICE);
+               dmaaddr = ssb_dma_map_single(ring->dev->dev,
+                                            buf, len,
+                                            DMA_FROM_DEVICE);
 
        return dmaaddr;
 }
@@ -411,13 +411,13 @@ void unmap_descbuffer(struct b43legacy_dmaring *ring,
                      int tx)
 {
        if (tx)
-               dma_unmap_single(ring->dev->dev->dma_dev,
-                                addr, len,
-                                DMA_TO_DEVICE);
+               ssb_dma_unmap_single(ring->dev->dev,
+                                    addr, len,
+                                    DMA_TO_DEVICE);
        else
-               dma_unmap_single(ring->dev->dev->dma_dev,
-                                addr, len,
-                                DMA_FROM_DEVICE);
+               ssb_dma_unmap_single(ring->dev->dev,
+                                    addr, len,
+                                    DMA_FROM_DEVICE);
 }
 
 static inline
@@ -427,8 +427,8 @@ void sync_descbuffer_for_cpu(struct b43legacy_dmaring *ring,
 {
        B43legacy_WARN_ON(ring->tx);
 
-       dma_sync_single_for_cpu(ring->dev->dev->dma_dev,
-                               addr, len, DMA_FROM_DEVICE);
+       ssb_dma_sync_single_for_cpu(ring->dev->dev,
+                                   addr, len, DMA_FROM_DEVICE);
 }
 
 static inline
@@ -438,8 +438,8 @@ void sync_descbuffer_for_device(struct b43legacy_dmaring *ring,
 {
        B43legacy_WARN_ON(ring->tx);
 
-       dma_sync_single_for_device(ring->dev->dev->dma_dev,
-                                  addr, len, DMA_FROM_DEVICE);
+       ssb_dma_sync_single_for_device(ring->dev->dev,
+                                      addr, len, DMA_FROM_DEVICE);
 }
 
 static inline
@@ -458,10 +458,11 @@ void free_descriptor_buffer(struct b43legacy_dmaring *ring,
 
 static int alloc_ringmemory(struct b43legacy_dmaring *ring)
 {
-       struct device *dma_dev = ring->dev->dev->dma_dev;
-
-       ring->descbase = dma_alloc_coherent(dma_dev, B43legacy_DMA_RINGMEMSIZE,
-                                           &(ring->dmabase), GFP_KERNEL);
+       /* GFP flags must match the flags in free_ringmemory()! */
+       ring->descbase = ssb_dma_alloc_consistent(ring->dev->dev,
+                                                 B43legacy_DMA_RINGMEMSIZE,
+                                                 &(ring->dmabase),
+                                                 GFP_KERNEL);
        if (!ring->descbase) {
                b43legacyerr(ring->dev->wl, "DMA ringmemory allocation"
                             " failed\n");
@@ -474,10 +475,8 @@ static int alloc_ringmemory(struct b43legacy_dmaring *ring)
 
 static void free_ringmemory(struct b43legacy_dmaring *ring)
 {
-       struct device *dma_dev = ring->dev->dev->dma_dev;
-
-       dma_free_coherent(dma_dev, B43legacy_DMA_RINGMEMSIZE,
-                         ring->descbase, ring->dmabase);
+       ssb_dma_free_consistent(ring->dev->dev, B43legacy_DMA_RINGMEMSIZE,
+                               ring->descbase, ring->dmabase, GFP_KERNEL);
 }
 
 /* Reset the RX DMA channel */
@@ -589,7 +588,7 @@ static bool b43legacy_dma_mapping_error(struct b43legacy_dmaring *ring,
                                         size_t buffersize,
                                         bool dma_to_device)
 {
-       if (unlikely(dma_mapping_error(addr)))
+       if (unlikely(ssb_dma_mapping_error(ring->dev->dev, addr)))
                return 1;
 
        switch (ring->type) {
@@ -847,7 +846,7 @@ static u64 supported_dma_mask(struct b43legacy_wldev *dev)
 
        tmp = b43legacy_read32(dev, SSB_TMSHIGH);
        if (tmp & SSB_TMSHIGH_DMA64)
-               return DMA_64BIT_MASK;
+               return DMA_BIT_MASK(64);
        mmio_base = b43legacy_dmacontroller_base(0, 0);
        b43legacy_write32(dev,
                        mmio_base + B43legacy_DMA32_TXCTL,
@@ -855,9 +854,21 @@ static u64 supported_dma_mask(struct b43legacy_wldev *dev)
        tmp = b43legacy_read32(dev, mmio_base +
                               B43legacy_DMA32_TXCTL);
        if (tmp & B43legacy_DMA32_TXADDREXT_MASK)
-               return DMA_32BIT_MASK;
+               return DMA_BIT_MASK(32);
 
-       return DMA_30BIT_MASK;
+       return DMA_BIT_MASK(30);
+}
+
+static enum b43legacy_dmatype dma_mask_to_engine_type(u64 dmamask)
+{
+       if (dmamask == DMA_BIT_MASK(30))
+               return B43legacy_DMA_30BIT;
+       if (dmamask == DMA_BIT_MASK(32))
+               return B43legacy_DMA_32BIT;
+       if (dmamask == DMA_BIT_MASK(64))
+               return B43legacy_DMA_64BIT;
+       B43legacy_WARN_ON(1);
+       return B43legacy_DMA_30BIT;
 }
 
 /* Main initialization function. */
@@ -876,6 +887,7 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev,
        if (!ring)
                goto out;
        ring->type = type;
+       ring->dev = dev;
 
        nr_slots = B43legacy_RXRING_SLOTS;
        if (for_tx)
@@ -893,9 +905,9 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev,
                        goto err_kfree_meta;
 
                /* test for ability to dma to txhdr_cache */
-               dma_test = dma_map_single(dev->dev->dma_dev, ring->txhdr_cache,
-                                         sizeof(struct b43legacy_txhdr_fw3),
-                                         DMA_TO_DEVICE);
+               dma_test = ssb_dma_map_single(dev->dev, ring->txhdr_cache,
+                                             sizeof(struct b43legacy_txhdr_fw3),
+                                             DMA_TO_DEVICE);
 
                if (b43legacy_dma_mapping_error(ring, dma_test,
                                        sizeof(struct b43legacy_txhdr_fw3), 1)) {
@@ -907,7 +919,7 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev,
                        if (!ring->txhdr_cache)
                                goto err_kfree_meta;
 
-                       dma_test = dma_map_single(dev->dev->dma_dev,
+                       dma_test = ssb_dma_map_single(dev->dev,
                                        ring->txhdr_cache,
                                        sizeof(struct b43legacy_txhdr_fw3),
                                        DMA_TO_DEVICE);
@@ -917,12 +929,11 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev,
                                goto err_kfree_txhdr_cache;
                }
 
-               dma_unmap_single(dev->dev->dma_dev,
-                                dma_test, sizeof(struct b43legacy_txhdr_fw3),
-                                DMA_TO_DEVICE);
+               ssb_dma_unmap_single(dev->dev, dma_test,
+                                    sizeof(struct b43legacy_txhdr_fw3),
+                                    DMA_TO_DEVICE);
        }
 
-       ring->dev = dev;
        ring->nr_slots = nr_slots;
        ring->mmio_base = b43legacy_dmacontroller_base(type, controller_index);
        ring->index = controller_index;
@@ -1019,6 +1030,43 @@ void b43legacy_dma_free(struct b43legacy_wldev *dev)
        dma->tx_ring0 = NULL;
 }
 
+static int b43legacy_dma_set_mask(struct b43legacy_wldev *dev, u64 mask)
+{
+       u64 orig_mask = mask;
+       bool fallback = 0;
+       int err;
+
+       /* Try to set the DMA mask. If it fails, try falling back to a
+        * lower mask, as we can always also support a lower one. */
+       while (1) {
+               err = ssb_dma_set_mask(dev->dev, mask);
+               if (!err)
+                       break;
+               if (mask == DMA_BIT_MASK(64)) {
+                       mask = DMA_BIT_MASK(32);
+                       fallback = 1;
+                       continue;
+               }
+               if (mask == DMA_BIT_MASK(32)) {
+                       mask = DMA_BIT_MASK(30);
+                       fallback = 1;
+                       continue;
+               }
+               b43legacyerr(dev->wl, "The machine/kernel does not support "
+                      "the required %u-bit DMA mask\n",
+                      (unsigned int)dma_mask_to_engine_type(orig_mask));
+               return -EOPNOTSUPP;
+       }
+       if (fallback) {
+               b43legacyinfo(dev->wl, "DMA mask fallback from %u-bit to %u-"
+                       "bit\n",
+                       (unsigned int)dma_mask_to_engine_type(orig_mask),
+                       (unsigned int)dma_mask_to_engine_type(mask));
+       }
+
+       return 0;
+}
+
 int b43legacy_dma_init(struct b43legacy_wldev *dev)
 {
        struct b43legacy_dma *dma = &dev->dma;
@@ -1028,21 +1076,8 @@ int b43legacy_dma_init(struct b43legacy_wldev *dev)
        enum b43legacy_dmatype type;
 
        dmamask = supported_dma_mask(dev);
-       switch (dmamask) {
-       default:
-               B43legacy_WARN_ON(1);
-       case DMA_30BIT_MASK:
-               type = B43legacy_DMA_30BIT;
-               break;
-       case DMA_32BIT_MASK:
-               type = B43legacy_DMA_32BIT;
-               break;
-       case DMA_64BIT_MASK:
-               type = B43legacy_DMA_64BIT;
-               break;
-       }
-
-       err = ssb_dma_set_mask(dev->dev, dmamask);
+       type = dma_mask_to_engine_type(dmamask);
+       err = b43legacy_dma_set_mask(dev, dmamask);
        if (err) {
 #ifdef CONFIG_B43LEGACY_PIO
                b43legacywarn(dev->wl, "DMA for this device not supported. "
@@ -1376,6 +1411,7 @@ void b43legacy_dma_handle_txstatus(struct b43legacy_wldev *dev,
        struct b43legacy_dmaring *ring;
        struct b43legacy_dmadesc_generic *desc;
        struct b43legacy_dmadesc_meta *meta;
+       int retry_limit;
        int slot;
 
        ring = parse_cookie(dev, status->cookie, &slot);
@@ -1402,25 +1438,42 @@ void b43legacy_dma_handle_txstatus(struct b43legacy_wldev *dev,
                        struct ieee80211_tx_info *info;
                        BUG_ON(!meta->skb);
                        info = IEEE80211_SKB_CB(meta->skb);
-                       /* Call back to inform the ieee80211 subsystem about the
-                        * status of the transmission.
-                        * Some fields of txstat are already filled in dma_tx().
-                        */
 
-                       memset(&info->status, 0, sizeof(info->status));
+                       /* preserve the confiured retry limit before clearing the status
+                        * The xmit function has overwritten the rc's value with the actual
+                        * retry limit done by the hardware */
+                       retry_limit = info->status.rates[0].count;
+                       ieee80211_tx_info_clear_status(info);
 
-                       if (status->acked) {
+                       if (status->acked)
                                info->flags |= IEEE80211_TX_STAT_ACK;
+
+                       if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
+                               /*
+                                * If the short retries (RTS, not data frame) have exceeded
+                                * the limit, the hw will not have tried the selected rate,
+                                * but will have used the fallback rate instead.
+                                * Don't let the rate control count attempts for the selected
+                                * rate in this case, otherwise the statistics will be off.
+                                */
+                               info->status.rates[0].count = 0;
+                               info->status.rates[1].count = status->frame_count;
                        } else {
-                               if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
-                                        info->status.excessive_retries = 1;
+                               if (status->frame_count > retry_limit) {
+                                       info->status.rates[0].count = retry_limit;
+                                       info->status.rates[1].count = status->frame_count -
+                                                       retry_limit;
+
+                               } else {
+                                       info->status.rates[0].count = status->frame_count;
+                                       info->status.rates[1].idx = -1;
+                               }
                        }
-                       if (status->frame_count == 0) {
-                               /* The frame was not transmitted at all. */
-                               info->status.retry_count = 0;
-                       } else
-                               info->status.retry_count = status->frame_count
-                                                          - 1;
+
+                       /* Call back to inform the ieee80211 subsystem about the
+                        * status of the transmission.
+                        * Some fields of txstat are already filled in dma_tx().
+                        */
                        ieee80211_tx_status_irqsafe(dev->wl->hw, meta->skb);
                        /* skb is freed by ieee80211_tx_status_irqsafe() */
                        meta->skb = NULL;