blob: e7e3a459b66a6b8196f0626fcb03ae332019e999 [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
Ivo van Doorn811aa9c2008-02-03 15:42:53 +01002 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
Ivo van Doorn95ea3622007-09-25 17:57:13 -07003 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2x00pci
23 Abstract: rt2x00 generic pci device routines.
24 */
25
Ivo van Doorn95ea3622007-09-25 17:57:13 -070026#include <linux/dma-mapping.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/pci.h>
30
31#include "rt2x00.h"
32#include "rt2x00pci.h"
33
34/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -070035 * TX data handlers.
36 */
Ivo van Doorn6db37862008-06-06 22:50:28 +020037int rt2x00pci_write_tx_data(struct queue_entry *entry)
Ivo van Doorn95ea3622007-09-25 17:57:13 -070038{
Ivo van Doornb8be63f2008-05-10 13:46:03 +020039 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -050040 struct skb_frame_desc *skbdesc;
Ivo van Doorn95ea3622007-09-25 17:57:13 -070041 u32 word;
42
Ivo van Doornb8be63f2008-05-10 13:46:03 +020043 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070044
Ivo van Doorn6db37862008-06-06 22:50:28 +020045 /*
46 * This should not happen, we already checked the entry
47 * was ours. When the hardware disagrees there has been
48 * a queue corruption!
49 */
50 if (unlikely(rt2x00_get_field32(word, TXD_ENTRY_OWNER_NIC) ||
51 rt2x00_get_field32(word, TXD_ENTRY_VALID))) {
52 ERROR(entry->queue->rt2x00dev,
53 "Corrupt queue %d, accessing entry which is not ours.\n"
Ivo van Doorn95ea3622007-09-25 17:57:13 -070054 "Please file bug report to %s.\n",
Ivo van Doorne58c6ac2008-04-21 19:00:47 +020055 entry->queue->qid, DRV_PROJECT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070056 return -EINVAL;
57 }
58
Ivo van Doorn08992f72008-01-24 01:56:25 -080059 /*
60 * Fill in skb descriptor
61 */
Ivo van Doorn6db37862008-06-06 22:50:28 +020062 skbdesc = get_skb_frame_desc(entry->skb);
Johannes Berge039fa42008-05-15 12:55:29 +020063 memset(skbdesc, 0, sizeof(*skbdesc));
Ivo van Doornb8be63f2008-05-10 13:46:03 +020064 skbdesc->desc = entry_priv->desc;
Ivo van Doorn6db37862008-06-06 22:50:28 +020065 skbdesc->desc_len = entry->queue->desc_size;
Ivo van Doorn181d6902008-02-05 16:42:23 -050066 skbdesc->entry = entry;
Ivo van Doorn08992f72008-01-24 01:56:25 -080067
Ivo van Doorn6db37862008-06-06 22:50:28 +020068 memcpy(entry_priv->data, entry->skb->data, entry->skb->len);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070069
Ivo van Doorn95ea3622007-09-25 17:57:13 -070070 return 0;
71}
72EXPORT_SYMBOL_GPL(rt2x00pci_write_tx_data);
73
74/*
Ivo van Doorn3957ccb2007-11-12 15:02:40 +010075 * TX/RX data handlers.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070076 */
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +020077static void rt2x00pci_rxdone_entry(struct rt2x00_dev *rt2x00dev,
78 struct queue_entry *entry)
79{
80 struct sk_buff *skb;
81 struct skb_frame_desc *skbdesc;
82 struct rxdone_entry_desc rxdesc;
83 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
84
85 /*
86 * Allocate a new sk_buffer. If no new buffer available, drop the
87 * received frame and reuse the existing buffer.
88 */
89 skb = rt2x00queue_alloc_skb(entry->queue);
90 if (!skb)
91 return;
92
93 /*
94 * Extract the RXD details.
95 */
96 memset(&rxdesc, 0, sizeof(rxdesc));
97 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
98
99 /*
100 * Copy the received data to the entries' skb.
101 */
102 memcpy(entry->skb->data, entry_priv->data, rxdesc.size);
103 skb_trim(entry->skb, rxdesc.size);
104
105 /*
106 * Fill in skb descriptor
107 */
108 skbdesc = get_skb_frame_desc(entry->skb);
109 memset(skbdesc, 0, sizeof(*skbdesc));
110 skbdesc->desc = entry_priv->desc;
111 skbdesc->desc_len = entry->queue->desc_size;
112 skbdesc->entry = entry;
113
114 /*
115 * Send the frame to rt2x00lib for further processing.
116 */
117 rt2x00lib_rxdone(entry, &rxdesc);
118
119 /*
120 * Replace the entries' skb with the newly allocated one.
121 */
122 entry->skb = skb;
123}
124
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700125void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev)
126{
Ivo van Doorn181d6902008-02-05 16:42:23 -0500127 struct data_queue *queue = rt2x00dev->rx;
128 struct queue_entry *entry;
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200129 struct queue_entry_priv_pci *entry_priv;
Johannes Berg4150c572007-09-17 01:29:23 -0400130 u32 word;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700131
132 while (1) {
Ivo van Doorn181d6902008-02-05 16:42:23 -0500133 entry = rt2x00queue_get_entry(queue, Q_INDEX);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200134 entry_priv = entry->priv_data;
135 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700136
Johannes Berg4150c572007-09-17 01:29:23 -0400137 if (rt2x00_get_field32(word, RXD_ENTRY_OWNER_NIC))
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700138 break;
139
Gertjan van Wingerde30caa6e2008-06-16 19:56:08 +0200140 rt2x00pci_rxdone_entry(rt2x00dev, entry);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700141
Ivo van Doorn181d6902008-02-05 16:42:23 -0500142 if (test_bit(DEVICE_ENABLED_RADIO, &queue->rt2x00dev->flags)) {
Johannes Berg4150c572007-09-17 01:29:23 -0400143 rt2x00_set_field32(&word, RXD_ENTRY_OWNER_NIC, 1);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200144 rt2x00_desc_write(entry_priv->desc, 0, word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700145 }
146
Ivo van Doorn181d6902008-02-05 16:42:23 -0500147 rt2x00queue_index_inc(queue, Q_INDEX);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700148 }
149}
150EXPORT_SYMBOL_GPL(rt2x00pci_rxdone);
151
Ivo van Doorn181d6902008-02-05 16:42:23 -0500152void rt2x00pci_txdone(struct rt2x00_dev *rt2x00dev, struct queue_entry *entry,
153 struct txdone_entry_desc *txdesc)
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100154{
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200155 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
Johannes Berge039fa42008-05-15 12:55:29 +0200156 enum data_queue_qid qid = skb_get_queue_mapping(entry->skb);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100157 u32 word;
158
Ivo van Doorn181d6902008-02-05 16:42:23 -0500159 rt2x00lib_txdone(entry, txdesc);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100160
161 /*
162 * Make this entry available for reuse.
163 */
164 entry->flags = 0;
165
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200166 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100167 rt2x00_set_field32(&word, TXD_ENTRY_OWNER_NIC, 0);
168 rt2x00_set_field32(&word, TXD_ENTRY_VALID, 0);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200169 rt2x00_desc_write(entry_priv->desc, 0, word);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100170
Ivo van Doorn6db37862008-06-06 22:50:28 +0200171 __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500172 rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100173
174 /*
Ivo van Doornb8697672008-06-06 22:53:14 +0200175 * If the data queue was below the threshold before the txdone
176 * handler we must make sure the packet queue in the mac80211 stack
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100177 * is reenabled when the txdone handler has finished.
178 */
Ivo van Doornb8697672008-06-06 22:53:14 +0200179 if (!rt2x00queue_threshold(entry->queue))
Johannes Berge039fa42008-05-15 12:55:29 +0200180 ieee80211_wake_queue(rt2x00dev->hw, qid);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100181
182}
183EXPORT_SYMBOL_GPL(rt2x00pci_txdone);
184
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700185/*
186 * Device initialization handlers.
187 */
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100188#define desc_size(__queue) \
189({ \
190 ((__queue)->limit * (__queue)->desc_size);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700191})
192
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100193#define data_size(__queue) \
194({ \
195 ((__queue)->limit * (__queue)->data_size);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700196})
197
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100198#define dma_size(__queue) \
199({ \
200 data_size(__queue) + desc_size(__queue);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700201})
202
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100203#define desc_offset(__queue, __base, __i) \
204({ \
205 (__base) + data_size(__queue) + \
206 ((__i) * (__queue)->desc_size); \
207})
208
209#define data_offset(__queue, __base, __i) \
210({ \
211 (__base) + \
212 ((__i) * (__queue)->data_size); \
Ivo van Doorn181d6902008-02-05 16:42:23 -0500213})
214
215static int rt2x00pci_alloc_queue_dma(struct rt2x00_dev *rt2x00dev,
216 struct data_queue *queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700217{
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200218 struct queue_entry_priv_pci *entry_priv;
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100219 void *addr;
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100220 dma_addr_t dma;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700221 unsigned int i;
222
223 /*
224 * Allocate DMA memory for descriptor and buffer.
225 */
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200226 addr = dma_alloc_coherent(rt2x00dev->dev, dma_size(queue), &dma,
227 GFP_KERNEL | GFP_DMA);
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100228 if (!addr)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700229 return -ENOMEM;
230
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100231 memset(addr, 0, dma_size(queue));
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100232
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700233 /*
Ivo van Doorn181d6902008-02-05 16:42:23 -0500234 * Initialize all queue entries to contain valid addresses.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700235 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500236 for (i = 0; i < queue->limit; i++) {
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200237 entry_priv = queue->entries[i].priv_data;
238 entry_priv->desc = desc_offset(queue, addr, i);
239 entry_priv->desc_dma = desc_offset(queue, dma, i);
240 entry_priv->data = data_offset(queue, addr, i);
241 entry_priv->data_dma = data_offset(queue, dma, i);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700242 }
243
244 return 0;
245}
246
Ivo van Doorn181d6902008-02-05 16:42:23 -0500247static void rt2x00pci_free_queue_dma(struct rt2x00_dev *rt2x00dev,
248 struct data_queue *queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700249{
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200250 struct queue_entry_priv_pci *entry_priv =
251 queue->entries[0].priv_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500252
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200253 if (entry_priv->data)
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200254 dma_free_coherent(rt2x00dev->dev, dma_size(queue),
255 entry_priv->data, entry_priv->data_dma);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200256 entry_priv->data = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700257}
258
259int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev)
260{
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200261 struct pci_dev *pci_dev = to_pci_dev(rt2x00dev->dev);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500262 struct data_queue *queue;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700263 int status;
264
265 /*
266 * Allocate DMA
267 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500268 queue_for_each(rt2x00dev, queue) {
269 status = rt2x00pci_alloc_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700270 if (status)
271 goto exit;
272 }
273
274 /*
275 * Register interrupt handler.
276 */
277 status = request_irq(pci_dev->irq, rt2x00dev->ops->lib->irq_handler,
278 IRQF_SHARED, pci_name(pci_dev), rt2x00dev);
279 if (status) {
280 ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n",
281 pci_dev->irq, status);
Ivo van Doornb30cdfc2008-05-05 17:24:03 +0200282 goto exit;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700283 }
284
285 return 0;
286
287exit:
Ivo van Doornb30cdfc2008-05-05 17:24:03 +0200288 queue_for_each(rt2x00dev, queue)
289 rt2x00pci_free_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700290
291 return status;
292}
293EXPORT_SYMBOL_GPL(rt2x00pci_initialize);
294
295void rt2x00pci_uninitialize(struct rt2x00_dev *rt2x00dev)
296{
Ivo van Doorn181d6902008-02-05 16:42:23 -0500297 struct data_queue *queue;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700298
299 /*
300 * Free irq line.
301 */
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200302 free_irq(to_pci_dev(rt2x00dev->dev)->irq, rt2x00dev);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700303
304 /*
305 * Free DMA
306 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500307 queue_for_each(rt2x00dev, queue)
308 rt2x00pci_free_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700309}
310EXPORT_SYMBOL_GPL(rt2x00pci_uninitialize);
311
312/*
313 * PCI driver handlers.
314 */
315static void rt2x00pci_free_reg(struct rt2x00_dev *rt2x00dev)
316{
317 kfree(rt2x00dev->rf);
318 rt2x00dev->rf = NULL;
319
320 kfree(rt2x00dev->eeprom);
321 rt2x00dev->eeprom = NULL;
322
Ivo van Doorn21795092008-02-10 22:49:13 +0100323 if (rt2x00dev->csr.base) {
324 iounmap(rt2x00dev->csr.base);
325 rt2x00dev->csr.base = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700326 }
327}
328
329static int rt2x00pci_alloc_reg(struct rt2x00_dev *rt2x00dev)
330{
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200331 struct pci_dev *pci_dev = to_pci_dev(rt2x00dev->dev);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700332
Ivo van Doorn21795092008-02-10 22:49:13 +0100333 rt2x00dev->csr.base = ioremap(pci_resource_start(pci_dev, 0),
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700334 pci_resource_len(pci_dev, 0));
Ivo van Doorn21795092008-02-10 22:49:13 +0100335 if (!rt2x00dev->csr.base)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700336 goto exit;
337
338 rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
339 if (!rt2x00dev->eeprom)
340 goto exit;
341
342 rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
343 if (!rt2x00dev->rf)
344 goto exit;
345
346 return 0;
347
348exit:
349 ERROR_PROBE("Failed to allocate registers.\n");
350
351 rt2x00pci_free_reg(rt2x00dev);
352
353 return -ENOMEM;
354}
355
356int rt2x00pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
357{
358 struct rt2x00_ops *ops = (struct rt2x00_ops *)id->driver_data;
359 struct ieee80211_hw *hw;
360 struct rt2x00_dev *rt2x00dev;
361 int retval;
362
363 retval = pci_request_regions(pci_dev, pci_name(pci_dev));
364 if (retval) {
365 ERROR_PROBE("PCI request regions failed.\n");
366 return retval;
367 }
368
369 retval = pci_enable_device(pci_dev);
370 if (retval) {
371 ERROR_PROBE("Enable device failed.\n");
372 goto exit_release_regions;
373 }
374
375 pci_set_master(pci_dev);
376
377 if (pci_set_mwi(pci_dev))
378 ERROR_PROBE("MWI not available.\n");
379
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200380 if (dma_set_mask(&pci_dev->dev, DMA_32BIT_MASK)) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700381 ERROR_PROBE("PCI DMA not supported.\n");
382 retval = -EIO;
383 goto exit_disable_device;
384 }
385
386 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
387 if (!hw) {
388 ERROR_PROBE("Failed to allocate hardware.\n");
389 retval = -ENOMEM;
390 goto exit_disable_device;
391 }
392
393 pci_set_drvdata(pci_dev, hw);
394
395 rt2x00dev = hw->priv;
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200396 rt2x00dev->dev = &pci_dev->dev;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700397 rt2x00dev->ops = ops;
398 rt2x00dev->hw = hw;
399
400 retval = rt2x00pci_alloc_reg(rt2x00dev);
401 if (retval)
402 goto exit_free_device;
403
404 retval = rt2x00lib_probe_dev(rt2x00dev);
405 if (retval)
406 goto exit_free_reg;
407
408 return 0;
409
410exit_free_reg:
411 rt2x00pci_free_reg(rt2x00dev);
412
413exit_free_device:
414 ieee80211_free_hw(hw);
415
416exit_disable_device:
417 if (retval != -EBUSY)
418 pci_disable_device(pci_dev);
419
420exit_release_regions:
421 pci_release_regions(pci_dev);
422
423 pci_set_drvdata(pci_dev, NULL);
424
425 return retval;
426}
427EXPORT_SYMBOL_GPL(rt2x00pci_probe);
428
429void rt2x00pci_remove(struct pci_dev *pci_dev)
430{
431 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
432 struct rt2x00_dev *rt2x00dev = hw->priv;
433
434 /*
435 * Free all allocated data.
436 */
437 rt2x00lib_remove_dev(rt2x00dev);
438 rt2x00pci_free_reg(rt2x00dev);
439 ieee80211_free_hw(hw);
440
441 /*
442 * Free the PCI device data.
443 */
444 pci_set_drvdata(pci_dev, NULL);
445 pci_disable_device(pci_dev);
446 pci_release_regions(pci_dev);
447}
448EXPORT_SYMBOL_GPL(rt2x00pci_remove);
449
450#ifdef CONFIG_PM
451int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state)
452{
453 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
454 struct rt2x00_dev *rt2x00dev = hw->priv;
455 int retval;
456
457 retval = rt2x00lib_suspend(rt2x00dev, state);
458 if (retval)
459 return retval;
460
461 rt2x00pci_free_reg(rt2x00dev);
462
463 pci_save_state(pci_dev);
464 pci_disable_device(pci_dev);
465 return pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
466}
467EXPORT_SYMBOL_GPL(rt2x00pci_suspend);
468
469int rt2x00pci_resume(struct pci_dev *pci_dev)
470{
471 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
472 struct rt2x00_dev *rt2x00dev = hw->priv;
473 int retval;
474
475 if (pci_set_power_state(pci_dev, PCI_D0) ||
476 pci_enable_device(pci_dev) ||
477 pci_restore_state(pci_dev)) {
478 ERROR(rt2x00dev, "Failed to resume device.\n");
479 return -EIO;
480 }
481
482 retval = rt2x00pci_alloc_reg(rt2x00dev);
483 if (retval)
484 return retval;
485
486 retval = rt2x00lib_resume(rt2x00dev);
487 if (retval)
488 goto exit_free_reg;
489
490 return 0;
491
492exit_free_reg:
493 rt2x00pci_free_reg(rt2x00dev);
494
495 return retval;
496}
497EXPORT_SYMBOL_GPL(rt2x00pci_resume);
498#endif /* CONFIG_PM */
499
500/*
501 * rt2x00pci module information.
502 */
503MODULE_AUTHOR(DRV_PROJECT);
504MODULE_VERSION(DRV_VERSION);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500505MODULE_DESCRIPTION("rt2x00 pci library");
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700506MODULE_LICENSE("GPL");