blob: d6138389a5d0bf7aabdc23d112c397d44b7088b2 [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 */
77void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev)
78{
Ivo van Doorn181d6902008-02-05 16:42:23 -050079 struct data_queue *queue = rt2x00dev->rx;
80 struct queue_entry *entry;
Ivo van Doornb8be63f2008-05-10 13:46:03 +020081 struct queue_entry_priv_pci *entry_priv;
Ivo van Doorn181d6902008-02-05 16:42:23 -050082 struct skb_frame_desc *skbdesc;
83 struct rxdone_entry_desc rxdesc;
Johannes Berg4150c572007-09-17 01:29:23 -040084 u32 word;
Ivo van Doorn95ea3622007-09-25 17:57:13 -070085
86 while (1) {
Ivo van Doorn181d6902008-02-05 16:42:23 -050087 entry = rt2x00queue_get_entry(queue, Q_INDEX);
Ivo van Doornb8be63f2008-05-10 13:46:03 +020088 entry_priv = entry->priv_data;
89 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070090
Johannes Berg4150c572007-09-17 01:29:23 -040091 if (rt2x00_get_field32(word, RXD_ENTRY_OWNER_NIC))
Ivo van Doorn95ea3622007-09-25 17:57:13 -070092 break;
93
Ivo van Doorn181d6902008-02-05 16:42:23 -050094 memset(&rxdesc, 0, sizeof(rxdesc));
95 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070096
Ivo van Doornc5d0dc52008-01-06 23:40:27 +010097 /*
Gertjan van Wingerde239c2492008-06-06 22:54:12 +020098 * Allocate the sk_buffer and copy all data into it.
Ivo van Doornc5d0dc52008-01-06 23:40:27 +010099 */
Gertjan van Wingerde239c2492008-06-06 22:54:12 +0200100 entry->skb = rt2x00queue_alloc_rxskb(queue);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500101 if (!entry->skb)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700102 return;
103
Gertjan van Wingerde239c2492008-06-06 22:54:12 +0200104 memcpy(entry->skb->data, entry_priv->data, rxdesc.size);
105 skb_trim(entry->skb, rxdesc.size);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700106
107 /*
Ivo van Doorn08992f72008-01-24 01:56:25 -0800108 * Fill in skb descriptor
109 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500110 skbdesc = get_skb_frame_desc(entry->skb);
111 memset(skbdesc, 0, sizeof(*skbdesc));
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200112 skbdesc->desc = entry_priv->desc;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500113 skbdesc->desc_len = queue->desc_size;
Ivo van Doorn08992f72008-01-24 01:56:25 -0800114 skbdesc->entry = entry;
115
116 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700117 * Send the frame to rt2x00lib for further processing.
118 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500119 rt2x00lib_rxdone(entry, &rxdesc);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700120
Ivo van Doorn181d6902008-02-05 16:42:23 -0500121 if (test_bit(DEVICE_ENABLED_RADIO, &queue->rt2x00dev->flags)) {
Johannes Berg4150c572007-09-17 01:29:23 -0400122 rt2x00_set_field32(&word, RXD_ENTRY_OWNER_NIC, 1);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200123 rt2x00_desc_write(entry_priv->desc, 0, word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700124 }
125
Ivo van Doorn181d6902008-02-05 16:42:23 -0500126 rt2x00queue_index_inc(queue, Q_INDEX);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700127 }
128}
129EXPORT_SYMBOL_GPL(rt2x00pci_rxdone);
130
Ivo van Doorn181d6902008-02-05 16:42:23 -0500131void rt2x00pci_txdone(struct rt2x00_dev *rt2x00dev, struct queue_entry *entry,
132 struct txdone_entry_desc *txdesc)
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100133{
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200134 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
Johannes Berge039fa42008-05-15 12:55:29 +0200135 enum data_queue_qid qid = skb_get_queue_mapping(entry->skb);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100136 u32 word;
137
Ivo van Doorn181d6902008-02-05 16:42:23 -0500138 rt2x00lib_txdone(entry, txdesc);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100139
140 /*
141 * Make this entry available for reuse.
142 */
143 entry->flags = 0;
144
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200145 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100146 rt2x00_set_field32(&word, TXD_ENTRY_OWNER_NIC, 0);
147 rt2x00_set_field32(&word, TXD_ENTRY_VALID, 0);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200148 rt2x00_desc_write(entry_priv->desc, 0, word);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100149
Ivo van Doorn6db37862008-06-06 22:50:28 +0200150 __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500151 rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100152
153 /*
Ivo van Doornb8697672008-06-06 22:53:14 +0200154 * If the data queue was below the threshold before the txdone
155 * handler we must make sure the packet queue in the mac80211 stack
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100156 * is reenabled when the txdone handler has finished.
157 */
Ivo van Doornb8697672008-06-06 22:53:14 +0200158 if (!rt2x00queue_threshold(entry->queue))
Johannes Berge039fa42008-05-15 12:55:29 +0200159 ieee80211_wake_queue(rt2x00dev->hw, qid);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100160
161}
162EXPORT_SYMBOL_GPL(rt2x00pci_txdone);
163
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700164/*
165 * Device initialization handlers.
166 */
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100167#define desc_size(__queue) \
168({ \
169 ((__queue)->limit * (__queue)->desc_size);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700170})
171
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100172#define data_size(__queue) \
173({ \
174 ((__queue)->limit * (__queue)->data_size);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700175})
176
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100177#define dma_size(__queue) \
178({ \
179 data_size(__queue) + desc_size(__queue);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700180})
181
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100182#define desc_offset(__queue, __base, __i) \
183({ \
184 (__base) + data_size(__queue) + \
185 ((__i) * (__queue)->desc_size); \
186})
187
188#define data_offset(__queue, __base, __i) \
189({ \
190 (__base) + \
191 ((__i) * (__queue)->data_size); \
Ivo van Doorn181d6902008-02-05 16:42:23 -0500192})
193
194static int rt2x00pci_alloc_queue_dma(struct rt2x00_dev *rt2x00dev,
195 struct data_queue *queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700196{
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200197 struct queue_entry_priv_pci *entry_priv;
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100198 void *addr;
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100199 dma_addr_t dma;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700200 unsigned int i;
201
202 /*
203 * Allocate DMA memory for descriptor and buffer.
204 */
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200205 addr = dma_alloc_coherent(rt2x00dev->dev, dma_size(queue), &dma,
206 GFP_KERNEL | GFP_DMA);
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100207 if (!addr)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700208 return -ENOMEM;
209
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100210 memset(addr, 0, dma_size(queue));
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100211
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700212 /*
Ivo van Doorn181d6902008-02-05 16:42:23 -0500213 * Initialize all queue entries to contain valid addresses.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700214 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500215 for (i = 0; i < queue->limit; i++) {
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200216 entry_priv = queue->entries[i].priv_data;
217 entry_priv->desc = desc_offset(queue, addr, i);
218 entry_priv->desc_dma = desc_offset(queue, dma, i);
219 entry_priv->data = data_offset(queue, addr, i);
220 entry_priv->data_dma = data_offset(queue, dma, i);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700221 }
222
223 return 0;
224}
225
Ivo van Doorn181d6902008-02-05 16:42:23 -0500226static void rt2x00pci_free_queue_dma(struct rt2x00_dev *rt2x00dev,
227 struct data_queue *queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700228{
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200229 struct queue_entry_priv_pci *entry_priv =
230 queue->entries[0].priv_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500231
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200232 if (entry_priv->data)
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200233 dma_free_coherent(rt2x00dev->dev, dma_size(queue),
234 entry_priv->data, entry_priv->data_dma);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200235 entry_priv->data = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700236}
237
238int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev)
239{
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200240 struct pci_dev *pci_dev = to_pci_dev(rt2x00dev->dev);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500241 struct data_queue *queue;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700242 int status;
243
244 /*
245 * Allocate DMA
246 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500247 queue_for_each(rt2x00dev, queue) {
248 status = rt2x00pci_alloc_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700249 if (status)
250 goto exit;
251 }
252
253 /*
254 * Register interrupt handler.
255 */
256 status = request_irq(pci_dev->irq, rt2x00dev->ops->lib->irq_handler,
257 IRQF_SHARED, pci_name(pci_dev), rt2x00dev);
258 if (status) {
259 ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n",
260 pci_dev->irq, status);
Ivo van Doornb30cdfc2008-05-05 17:24:03 +0200261 goto exit;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700262 }
263
264 return 0;
265
266exit:
Ivo van Doornb30cdfc2008-05-05 17:24:03 +0200267 queue_for_each(rt2x00dev, queue)
268 rt2x00pci_free_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700269
270 return status;
271}
272EXPORT_SYMBOL_GPL(rt2x00pci_initialize);
273
274void rt2x00pci_uninitialize(struct rt2x00_dev *rt2x00dev)
275{
Ivo van Doorn181d6902008-02-05 16:42:23 -0500276 struct data_queue *queue;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700277
278 /*
279 * Free irq line.
280 */
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200281 free_irq(to_pci_dev(rt2x00dev->dev)->irq, rt2x00dev);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700282
283 /*
284 * Free DMA
285 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500286 queue_for_each(rt2x00dev, queue)
287 rt2x00pci_free_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700288}
289EXPORT_SYMBOL_GPL(rt2x00pci_uninitialize);
290
291/*
292 * PCI driver handlers.
293 */
294static void rt2x00pci_free_reg(struct rt2x00_dev *rt2x00dev)
295{
296 kfree(rt2x00dev->rf);
297 rt2x00dev->rf = NULL;
298
299 kfree(rt2x00dev->eeprom);
300 rt2x00dev->eeprom = NULL;
301
Ivo van Doorn21795092008-02-10 22:49:13 +0100302 if (rt2x00dev->csr.base) {
303 iounmap(rt2x00dev->csr.base);
304 rt2x00dev->csr.base = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700305 }
306}
307
308static int rt2x00pci_alloc_reg(struct rt2x00_dev *rt2x00dev)
309{
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200310 struct pci_dev *pci_dev = to_pci_dev(rt2x00dev->dev);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700311
Ivo van Doorn21795092008-02-10 22:49:13 +0100312 rt2x00dev->csr.base = ioremap(pci_resource_start(pci_dev, 0),
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700313 pci_resource_len(pci_dev, 0));
Ivo van Doorn21795092008-02-10 22:49:13 +0100314 if (!rt2x00dev->csr.base)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700315 goto exit;
316
317 rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
318 if (!rt2x00dev->eeprom)
319 goto exit;
320
321 rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
322 if (!rt2x00dev->rf)
323 goto exit;
324
325 return 0;
326
327exit:
328 ERROR_PROBE("Failed to allocate registers.\n");
329
330 rt2x00pci_free_reg(rt2x00dev);
331
332 return -ENOMEM;
333}
334
335int rt2x00pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
336{
337 struct rt2x00_ops *ops = (struct rt2x00_ops *)id->driver_data;
338 struct ieee80211_hw *hw;
339 struct rt2x00_dev *rt2x00dev;
340 int retval;
341
342 retval = pci_request_regions(pci_dev, pci_name(pci_dev));
343 if (retval) {
344 ERROR_PROBE("PCI request regions failed.\n");
345 return retval;
346 }
347
348 retval = pci_enable_device(pci_dev);
349 if (retval) {
350 ERROR_PROBE("Enable device failed.\n");
351 goto exit_release_regions;
352 }
353
354 pci_set_master(pci_dev);
355
356 if (pci_set_mwi(pci_dev))
357 ERROR_PROBE("MWI not available.\n");
358
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200359 if (dma_set_mask(&pci_dev->dev, DMA_32BIT_MASK)) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700360 ERROR_PROBE("PCI DMA not supported.\n");
361 retval = -EIO;
362 goto exit_disable_device;
363 }
364
365 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
366 if (!hw) {
367 ERROR_PROBE("Failed to allocate hardware.\n");
368 retval = -ENOMEM;
369 goto exit_disable_device;
370 }
371
372 pci_set_drvdata(pci_dev, hw);
373
374 rt2x00dev = hw->priv;
Gertjan van Wingerde14a3bf82008-06-16 19:55:43 +0200375 rt2x00dev->dev = &pci_dev->dev;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700376 rt2x00dev->ops = ops;
377 rt2x00dev->hw = hw;
378
379 retval = rt2x00pci_alloc_reg(rt2x00dev);
380 if (retval)
381 goto exit_free_device;
382
383 retval = rt2x00lib_probe_dev(rt2x00dev);
384 if (retval)
385 goto exit_free_reg;
386
387 return 0;
388
389exit_free_reg:
390 rt2x00pci_free_reg(rt2x00dev);
391
392exit_free_device:
393 ieee80211_free_hw(hw);
394
395exit_disable_device:
396 if (retval != -EBUSY)
397 pci_disable_device(pci_dev);
398
399exit_release_regions:
400 pci_release_regions(pci_dev);
401
402 pci_set_drvdata(pci_dev, NULL);
403
404 return retval;
405}
406EXPORT_SYMBOL_GPL(rt2x00pci_probe);
407
408void rt2x00pci_remove(struct pci_dev *pci_dev)
409{
410 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
411 struct rt2x00_dev *rt2x00dev = hw->priv;
412
413 /*
414 * Free all allocated data.
415 */
416 rt2x00lib_remove_dev(rt2x00dev);
417 rt2x00pci_free_reg(rt2x00dev);
418 ieee80211_free_hw(hw);
419
420 /*
421 * Free the PCI device data.
422 */
423 pci_set_drvdata(pci_dev, NULL);
424 pci_disable_device(pci_dev);
425 pci_release_regions(pci_dev);
426}
427EXPORT_SYMBOL_GPL(rt2x00pci_remove);
428
429#ifdef CONFIG_PM
430int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state)
431{
432 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
433 struct rt2x00_dev *rt2x00dev = hw->priv;
434 int retval;
435
436 retval = rt2x00lib_suspend(rt2x00dev, state);
437 if (retval)
438 return retval;
439
440 rt2x00pci_free_reg(rt2x00dev);
441
442 pci_save_state(pci_dev);
443 pci_disable_device(pci_dev);
444 return pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
445}
446EXPORT_SYMBOL_GPL(rt2x00pci_suspend);
447
448int rt2x00pci_resume(struct pci_dev *pci_dev)
449{
450 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
451 struct rt2x00_dev *rt2x00dev = hw->priv;
452 int retval;
453
454 if (pci_set_power_state(pci_dev, PCI_D0) ||
455 pci_enable_device(pci_dev) ||
456 pci_restore_state(pci_dev)) {
457 ERROR(rt2x00dev, "Failed to resume device.\n");
458 return -EIO;
459 }
460
461 retval = rt2x00pci_alloc_reg(rt2x00dev);
462 if (retval)
463 return retval;
464
465 retval = rt2x00lib_resume(rt2x00dev);
466 if (retval)
467 goto exit_free_reg;
468
469 return 0;
470
471exit_free_reg:
472 rt2x00pci_free_reg(rt2x00dev);
473
474 return retval;
475}
476EXPORT_SYMBOL_GPL(rt2x00pci_resume);
477#endif /* CONFIG_PM */
478
479/*
480 * rt2x00pci module information.
481 */
482MODULE_AUTHOR(DRV_PROJECT);
483MODULE_VERSION(DRV_VERSION);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500484MODULE_DESCRIPTION("rt2x00 pci library");
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700485MODULE_LICENSE("GPL");