~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/net/wireless/rt2x00/rt2x00pci.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
        Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
 
2
        Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
3
3
        <http://rt2x00.serialmonkey.com>
4
4
 
5
5
        This program is free software; you can redistribute it and/or modify
27
27
#include <linux/kernel.h>
28
28
#include <linux/module.h>
29
29
#include <linux/pci.h>
 
30
#include <linux/slab.h>
30
31
 
31
32
#include "rt2x00.h"
32
33
#include "rt2x00pci.h"
41
42
{
42
43
        unsigned int i;
43
44
 
 
45
        if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
 
46
                return 0;
 
47
 
44
48
        for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
45
49
                rt2x00pci_register_read(rt2x00dev, offset, reg);
46
50
                if (!rt2x00_get_field32(*reg, field))
56
60
}
57
61
EXPORT_SYMBOL_GPL(rt2x00pci_regbusy_read);
58
62
 
59
 
/*
60
 
 * TX data handlers.
61
 
 */
62
 
int rt2x00pci_write_tx_data(struct queue_entry *entry)
63
 
{
64
 
        struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
65
 
        struct queue_entry_priv_pci *entry_priv = entry->priv_data;
66
 
        struct skb_frame_desc *skbdesc;
67
 
 
68
 
        /*
69
 
         * This should not happen, we already checked the entry
70
 
         * was ours. When the hardware disagrees there has been
71
 
         * a queue corruption!
72
 
         */
73
 
        if (unlikely(rt2x00dev->ops->lib->get_entry_state(entry))) {
74
 
                ERROR(rt2x00dev,
75
 
                      "Corrupt queue %d, accessing entry which is not ours.\n"
76
 
                      "Please file bug report to %s.\n",
77
 
                      entry->queue->qid, DRV_PROJECT);
78
 
                return -EINVAL;
79
 
        }
80
 
 
81
 
        /*
82
 
         * Fill in skb descriptor
83
 
         */
84
 
        skbdesc = get_skb_frame_desc(entry->skb);
85
 
        skbdesc->desc = entry_priv->desc;
86
 
        skbdesc->desc_len = entry->queue->desc_size;
87
 
 
88
 
        return 0;
89
 
}
90
 
EXPORT_SYMBOL_GPL(rt2x00pci_write_tx_data);
91
 
 
92
 
/*
93
 
 * TX/RX data handlers.
94
 
 */
95
63
void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev)
96
64
{
97
65
        struct data_queue *queue = rt2x00dev->rx;
114
82
                skbdesc->desc_len = entry->queue->desc_size;
115
83
 
116
84
                /*
 
85
                 * DMA is already done, notify rt2x00lib that
 
86
                 * it finished successfully.
 
87
                 */
 
88
                rt2x00lib_dmastart(entry);
 
89
                rt2x00lib_dmadone(entry);
 
90
 
 
91
                /*
117
92
                 * Send the frame to rt2x00lib for further processing.
118
93
                 */
119
 
                rt2x00lib_rxdone(rt2x00dev, entry);
 
94
                rt2x00lib_rxdone(entry);
120
95
        }
121
96
}
122
97
EXPORT_SYMBOL_GPL(rt2x00pci_rxdone);
137
112
         */
138
113
        addr = dma_alloc_coherent(rt2x00dev->dev,
139
114
                                  queue->limit * queue->desc_size,
140
 
                                  &dma, GFP_KERNEL | GFP_DMA);
 
115
                                  &dma, GFP_KERNEL);
141
116
        if (!addr)
142
117
                return -ENOMEM;
143
118
 
185
160
        /*
186
161
         * Register interrupt handler.
187
162
         */
188
 
        status = request_irq(rt2x00dev->irq, rt2x00dev->ops->lib->irq_handler,
189
 
                             IRQF_SHARED, rt2x00dev->name, rt2x00dev);
 
163
        status = request_threaded_irq(rt2x00dev->irq,
 
164
                                      rt2x00dev->ops->lib->irq_handler,
 
165
                                      rt2x00dev->ops->lib->irq_handler_thread,
 
166
                                      IRQF_SHARED, rt2x00dev->name, rt2x00dev);
190
167
        if (status) {
191
168
                ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n",
192
169
                      rt2x00dev->irq, status);
210
187
        /*
211
188
         * Free irq line.
212
189
         */
213
 
        free_irq(to_pci_dev(rt2x00dev->dev)->irq, rt2x00dev);
 
190
        free_irq(rt2x00dev->irq, rt2x00dev);
214
191
 
215
192
        /*
216
193
         * Free DMA
269
246
        struct ieee80211_hw *hw;
270
247
        struct rt2x00_dev *rt2x00dev;
271
248
        int retval;
272
 
        u16 chip;
 
249
 
 
250
        retval = pci_enable_device(pci_dev);
 
251
        if (retval) {
 
252
                ERROR_PROBE("Enable device failed.\n");
 
253
                return retval;
 
254
        }
273
255
 
274
256
        retval = pci_request_regions(pci_dev, pci_name(pci_dev));
275
257
        if (retval) {
276
258
                ERROR_PROBE("PCI request regions failed.\n");
277
 
                return retval;
278
 
        }
279
 
 
280
 
        retval = pci_enable_device(pci_dev);
281
 
        if (retval) {
282
 
                ERROR_PROBE("Enable device failed.\n");
283
 
                goto exit_release_regions;
 
259
                goto exit_disable_device;
284
260
        }
285
261
 
286
262
        pci_set_master(pci_dev);
291
267
        if (dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32))) {
292
268
                ERROR_PROBE("PCI DMA not supported.\n");
293
269
                retval = -EIO;
294
 
                goto exit_disable_device;
 
270
                goto exit_release_regions;
295
271
        }
296
272
 
297
273
        hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
298
274
        if (!hw) {
299
275
                ERROR_PROBE("Failed to allocate hardware.\n");
300
276
                retval = -ENOMEM;
301
 
                goto exit_disable_device;
 
277
                goto exit_release_regions;
302
278
        }
303
279
 
304
280
        pci_set_drvdata(pci_dev, hw);
310
286
        rt2x00dev->irq = pci_dev->irq;
311
287
        rt2x00dev->name = pci_name(pci_dev);
312
288
 
313
 
        /*
314
 
         * Determine RT chipset by reading PCI header.
315
 
         */
316
 
        pci_read_config_word(pci_dev, PCI_DEVICE_ID, &chip);
317
 
        rt2x00_set_chip_rt(rt2x00dev, chip);
 
289
        if (pci_is_pcie(pci_dev))
 
290
                rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
 
291
        else
 
292
                rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI);
318
293
 
319
294
        retval = rt2x00pci_alloc_reg(rt2x00dev);
320
295
        if (retval)
332
307
exit_free_device:
333
308
        ieee80211_free_hw(hw);
334
309
 
 
310
exit_release_regions:
 
311
        pci_release_regions(pci_dev);
 
312
 
335
313
exit_disable_device:
336
 
        if (retval != -EBUSY)
337
 
                pci_disable_device(pci_dev);
338
 
 
339
 
exit_release_regions:
340
 
        pci_release_regions(pci_dev);
 
314
        pci_disable_device(pci_dev);
341
315
 
342
316
        pci_set_drvdata(pci_dev, NULL);
343
317
 
389
363
        struct rt2x00_dev *rt2x00dev = hw->priv;
390
364
 
391
365
        if (pci_set_power_state(pci_dev, PCI_D0) ||
392
 
            pci_enable_device(pci_dev) ||
393
 
            pci_restore_state(pci_dev)) {
 
366
            pci_enable_device(pci_dev)) {
394
367
                ERROR(rt2x00dev, "Failed to resume device.\n");
395
368
                return -EIO;
396
369
        }
397
370
 
 
371
        pci_restore_state(pci_dev);
398
372
        return rt2x00lib_resume(rt2x00dev);
399
373
}
400
374
EXPORT_SYMBOL_GPL(rt2x00pci_resume);