blob: 70a3d135f64ec22fee19567322dc549771f34327 [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 */
37int rt2x00pci_write_tx_data(struct rt2x00_dev *rt2x00dev,
Johannes Berge039fa42008-05-15 12:55:29 +020038 struct data_queue *queue, struct sk_buff *skb)
Ivo van Doorn95ea3622007-09-25 17:57:13 -070039{
Ivo van Doorn181d6902008-02-05 16:42:23 -050040 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
Ivo van Doornb8be63f2008-05-10 13:46:03 +020041 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -050042 struct skb_frame_desc *skbdesc;
Ivo van Doorn7050ec82008-05-10 13:46:13 +020043 struct txentry_desc txdesc;
Ivo van Doorn95ea3622007-09-25 17:57:13 -070044 u32 word;
45
Ivo van Doorn181d6902008-02-05 16:42:23 -050046 if (rt2x00queue_full(queue))
Ivo van Doorn95ea3622007-09-25 17:57:13 -070047 return -EINVAL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -070048
Ivo van Doornb8be63f2008-05-10 13:46:03 +020049 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070050
51 if (rt2x00_get_field32(word, TXD_ENTRY_OWNER_NIC) ||
52 rt2x00_get_field32(word, TXD_ENTRY_VALID)) {
53 ERROR(rt2x00dev,
54 "Arrived at non-free entry in the non-full queue %d.\n"
55 "Please file bug report to %s.\n",
Ivo van Doorne58c6ac2008-04-21 19:00:47 +020056 entry->queue->qid, DRV_PROJECT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070057 return -EINVAL;
58 }
59
Ivo van Doorn08992f72008-01-24 01:56:25 -080060 /*
Ivo van Doorn7050ec82008-05-10 13:46:13 +020061 * Copy all TX descriptor information into txdesc,
62 * after that we are free to use the skb->cb array
63 * for our information.
64 */
65 entry->skb = skb;
Johannes Berge039fa42008-05-15 12:55:29 +020066 rt2x00queue_create_tx_descriptor(entry, &txdesc);
Ivo van Doorn7050ec82008-05-10 13:46:13 +020067
68 /*
Ivo van Doorn08992f72008-01-24 01:56:25 -080069 * Fill in skb descriptor
70 */
Ivo van Doorn181d6902008-02-05 16:42:23 -050071 skbdesc = get_skb_frame_desc(skb);
Johannes Berge039fa42008-05-15 12:55:29 +020072 memset(skbdesc, 0, sizeof(*skbdesc));
Ivo van Doorn181d6902008-02-05 16:42:23 -050073 skbdesc->data = skb->data;
Ivo van Doorn647d0ca2008-02-10 22:51:21 +010074 skbdesc->data_len = skb->len;
Ivo van Doornb8be63f2008-05-10 13:46:03 +020075 skbdesc->desc = entry_priv->desc;
Ivo van Doorn181d6902008-02-05 16:42:23 -050076 skbdesc->desc_len = queue->desc_size;
77 skbdesc->entry = entry;
Ivo van Doorn08992f72008-01-24 01:56:25 -080078
Ivo van Doornb8be63f2008-05-10 13:46:03 +020079 memcpy(entry_priv->data, skb->data, skb->len);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070080
Ivo van Doorn7050ec82008-05-10 13:46:13 +020081 rt2x00queue_write_tx_descriptor(entry, &txdesc);
Ivo van Doorn181d6902008-02-05 16:42:23 -050082 rt2x00queue_index_inc(queue, Q_INDEX);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070083
Ivo van Doorn95ea3622007-09-25 17:57:13 -070084 return 0;
85}
86EXPORT_SYMBOL_GPL(rt2x00pci_write_tx_data);
87
88/*
Ivo van Doorn3957ccb2007-11-12 15:02:40 +010089 * TX/RX data handlers.
Ivo van Doorn95ea3622007-09-25 17:57:13 -070090 */
91void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev)
92{
Ivo van Doorn181d6902008-02-05 16:42:23 -050093 struct data_queue *queue = rt2x00dev->rx;
94 struct queue_entry *entry;
Ivo van Doornb8be63f2008-05-10 13:46:03 +020095 struct queue_entry_priv_pci *entry_priv;
Ivo van Doornc5d0dc52008-01-06 23:40:27 +010096 struct ieee80211_hdr *hdr;
Ivo van Doorn181d6902008-02-05 16:42:23 -050097 struct skb_frame_desc *skbdesc;
98 struct rxdone_entry_desc rxdesc;
Ivo van Doornc5d0dc52008-01-06 23:40:27 +010099 int header_size;
100 int align;
Johannes Berg4150c572007-09-17 01:29:23 -0400101 u32 word;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700102
103 while (1) {
Ivo van Doorn181d6902008-02-05 16:42:23 -0500104 entry = rt2x00queue_get_entry(queue, Q_INDEX);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200105 entry_priv = entry->priv_data;
106 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700107
Johannes Berg4150c572007-09-17 01:29:23 -0400108 if (rt2x00_get_field32(word, RXD_ENTRY_OWNER_NIC))
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700109 break;
110
Ivo van Doorn181d6902008-02-05 16:42:23 -0500111 memset(&rxdesc, 0, sizeof(rxdesc));
112 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700113
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200114 hdr = (struct ieee80211_hdr *)entry_priv->data;
Ivo van Doornc5d0dc52008-01-06 23:40:27 +0100115 header_size =
116 ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
117
118 /*
119 * The data behind the ieee80211 header must be
120 * aligned on a 4 byte boundary.
121 */
Ivo van Doornd101f642008-01-11 20:53:07 +0100122 align = header_size % 4;
Ivo van Doornc5d0dc52008-01-06 23:40:27 +0100123
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700124 /*
125 * Allocate the sk_buffer, initialize it and copy
126 * all data into it.
127 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500128 entry->skb = dev_alloc_skb(rxdesc.size + align);
129 if (!entry->skb)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700130 return;
131
Ivo van Doorn181d6902008-02-05 16:42:23 -0500132 skb_reserve(entry->skb, align);
133 memcpy(skb_put(entry->skb, rxdesc.size),
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200134 entry_priv->data, rxdesc.size);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700135
136 /*
Ivo van Doorn08992f72008-01-24 01:56:25 -0800137 * Fill in skb descriptor
138 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500139 skbdesc = get_skb_frame_desc(entry->skb);
140 memset(skbdesc, 0, sizeof(*skbdesc));
141 skbdesc->data = entry->skb->data;
Ivo van Doorn647d0ca2008-02-10 22:51:21 +0100142 skbdesc->data_len = entry->skb->len;
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200143 skbdesc->desc = entry_priv->desc;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500144 skbdesc->desc_len = queue->desc_size;
Ivo van Doorn08992f72008-01-24 01:56:25 -0800145 skbdesc->entry = entry;
146
147 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700148 * Send the frame to rt2x00lib for further processing.
149 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500150 rt2x00lib_rxdone(entry, &rxdesc);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700151
Ivo van Doorn181d6902008-02-05 16:42:23 -0500152 if (test_bit(DEVICE_ENABLED_RADIO, &queue->rt2x00dev->flags)) {
Johannes Berg4150c572007-09-17 01:29:23 -0400153 rt2x00_set_field32(&word, RXD_ENTRY_OWNER_NIC, 1);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200154 rt2x00_desc_write(entry_priv->desc, 0, word);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700155 }
156
Ivo van Doorn181d6902008-02-05 16:42:23 -0500157 rt2x00queue_index_inc(queue, Q_INDEX);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700158 }
159}
160EXPORT_SYMBOL_GPL(rt2x00pci_rxdone);
161
Ivo van Doorn181d6902008-02-05 16:42:23 -0500162void rt2x00pci_txdone(struct rt2x00_dev *rt2x00dev, struct queue_entry *entry,
163 struct txdone_entry_desc *txdesc)
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100164{
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200165 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
Johannes Berge039fa42008-05-15 12:55:29 +0200166 enum data_queue_qid qid = skb_get_queue_mapping(entry->skb);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100167 u32 word;
168
Ivo van Doorn181d6902008-02-05 16:42:23 -0500169 rt2x00lib_txdone(entry, txdesc);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100170
171 /*
172 * Make this entry available for reuse.
173 */
174 entry->flags = 0;
175
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200176 rt2x00_desc_read(entry_priv->desc, 0, &word);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100177 rt2x00_set_field32(&word, TXD_ENTRY_OWNER_NIC, 0);
178 rt2x00_set_field32(&word, TXD_ENTRY_VALID, 0);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200179 rt2x00_desc_write(entry_priv->desc, 0, word);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100180
Ivo van Doorn181d6902008-02-05 16:42:23 -0500181 rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100182
183 /*
Ivo van Doorn181d6902008-02-05 16:42:23 -0500184 * If the data queue was full before the txdone handler
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100185 * we must make sure the packet queue in the mac80211 stack
186 * is reenabled when the txdone handler has finished.
187 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500188 if (!rt2x00queue_full(entry->queue))
Johannes Berge039fa42008-05-15 12:55:29 +0200189 ieee80211_wake_queue(rt2x00dev->hw, qid);
Ivo van Doorn3957ccb2007-11-12 15:02:40 +0100190
191}
192EXPORT_SYMBOL_GPL(rt2x00pci_txdone);
193
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700194/*
195 * Device initialization handlers.
196 */
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100197#define desc_size(__queue) \
198({ \
199 ((__queue)->limit * (__queue)->desc_size);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700200})
201
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100202#define data_size(__queue) \
203({ \
204 ((__queue)->limit * (__queue)->data_size);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700205})
206
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100207#define dma_size(__queue) \
208({ \
209 data_size(__queue) + desc_size(__queue);\
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700210})
211
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100212#define desc_offset(__queue, __base, __i) \
213({ \
214 (__base) + data_size(__queue) + \
215 ((__i) * (__queue)->desc_size); \
216})
217
218#define data_offset(__queue, __base, __i) \
219({ \
220 (__base) + \
221 ((__i) * (__queue)->data_size); \
Ivo van Doorn181d6902008-02-05 16:42:23 -0500222})
223
224static int rt2x00pci_alloc_queue_dma(struct rt2x00_dev *rt2x00dev,
225 struct data_queue *queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700226{
Ivo van Doorn181d6902008-02-05 16:42:23 -0500227 struct pci_dev *pci_dev = rt2x00dev_pci(rt2x00dev);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200228 struct queue_entry_priv_pci *entry_priv;
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100229 void *addr;
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100230 dma_addr_t dma;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700231 unsigned int i;
232
233 /*
234 * Allocate DMA memory for descriptor and buffer.
235 */
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100236 addr = pci_alloc_consistent(pci_dev, dma_size(queue), &dma);
237 if (!addr)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700238 return -ENOMEM;
239
Ivo van Doorn30b3a232008-02-17 17:33:24 +0100240 memset(addr, 0, dma_size(queue));
Ivo van Doorn9c9dd2c2008-02-10 22:46:52 +0100241
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700242 /*
Ivo van Doorn181d6902008-02-05 16:42:23 -0500243 * Initialize all queue entries to contain valid addresses.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700244 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500245 for (i = 0; i < queue->limit; i++) {
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200246 entry_priv = queue->entries[i].priv_data;
247 entry_priv->desc = desc_offset(queue, addr, i);
248 entry_priv->desc_dma = desc_offset(queue, dma, i);
249 entry_priv->data = data_offset(queue, addr, i);
250 entry_priv->data_dma = data_offset(queue, dma, i);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700251 }
252
253 return 0;
254}
255
Ivo van Doorn181d6902008-02-05 16:42:23 -0500256static void rt2x00pci_free_queue_dma(struct rt2x00_dev *rt2x00dev,
257 struct data_queue *queue)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700258{
Ivo van Doorn181d6902008-02-05 16:42:23 -0500259 struct pci_dev *pci_dev = rt2x00dev_pci(rt2x00dev);
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200260 struct queue_entry_priv_pci *entry_priv =
261 queue->entries[0].priv_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500262
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200263 if (entry_priv->data)
Ivo van Doorn181d6902008-02-05 16:42:23 -0500264 pci_free_consistent(pci_dev, dma_size(queue),
Ivo van Doornb8be63f2008-05-10 13:46:03 +0200265 entry_priv->data, entry_priv->data_dma);
266 entry_priv->data = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700267}
268
269int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev)
270{
271 struct pci_dev *pci_dev = rt2x00dev_pci(rt2x00dev);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500272 struct data_queue *queue;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700273 int status;
274
275 /*
276 * Allocate DMA
277 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500278 queue_for_each(rt2x00dev, queue) {
279 status = rt2x00pci_alloc_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700280 if (status)
281 goto exit;
282 }
283
284 /*
285 * Register interrupt handler.
286 */
287 status = request_irq(pci_dev->irq, rt2x00dev->ops->lib->irq_handler,
288 IRQF_SHARED, pci_name(pci_dev), rt2x00dev);
289 if (status) {
290 ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n",
291 pci_dev->irq, status);
Ivo van Doornb30cdfc2008-05-05 17:24:03 +0200292 goto exit;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700293 }
294
295 return 0;
296
297exit:
Ivo van Doornb30cdfc2008-05-05 17:24:03 +0200298 queue_for_each(rt2x00dev, queue)
299 rt2x00pci_free_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700300
301 return status;
302}
303EXPORT_SYMBOL_GPL(rt2x00pci_initialize);
304
305void rt2x00pci_uninitialize(struct rt2x00_dev *rt2x00dev)
306{
Ivo van Doorn181d6902008-02-05 16:42:23 -0500307 struct data_queue *queue;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700308
309 /*
310 * Free irq line.
311 */
312 free_irq(rt2x00dev_pci(rt2x00dev)->irq, rt2x00dev);
313
314 /*
315 * Free DMA
316 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500317 queue_for_each(rt2x00dev, queue)
318 rt2x00pci_free_queue_dma(rt2x00dev, queue);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700319}
320EXPORT_SYMBOL_GPL(rt2x00pci_uninitialize);
321
322/*
323 * PCI driver handlers.
324 */
325static void rt2x00pci_free_reg(struct rt2x00_dev *rt2x00dev)
326{
327 kfree(rt2x00dev->rf);
328 rt2x00dev->rf = NULL;
329
330 kfree(rt2x00dev->eeprom);
331 rt2x00dev->eeprom = NULL;
332
Ivo van Doorn21795092008-02-10 22:49:13 +0100333 if (rt2x00dev->csr.base) {
334 iounmap(rt2x00dev->csr.base);
335 rt2x00dev->csr.base = NULL;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700336 }
337}
338
339static int rt2x00pci_alloc_reg(struct rt2x00_dev *rt2x00dev)
340{
341 struct pci_dev *pci_dev = rt2x00dev_pci(rt2x00dev);
342
Ivo van Doorn21795092008-02-10 22:49:13 +0100343 rt2x00dev->csr.base = ioremap(pci_resource_start(pci_dev, 0),
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700344 pci_resource_len(pci_dev, 0));
Ivo van Doorn21795092008-02-10 22:49:13 +0100345 if (!rt2x00dev->csr.base)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700346 goto exit;
347
348 rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
349 if (!rt2x00dev->eeprom)
350 goto exit;
351
352 rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
353 if (!rt2x00dev->rf)
354 goto exit;
355
356 return 0;
357
358exit:
359 ERROR_PROBE("Failed to allocate registers.\n");
360
361 rt2x00pci_free_reg(rt2x00dev);
362
363 return -ENOMEM;
364}
365
366int rt2x00pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
367{
368 struct rt2x00_ops *ops = (struct rt2x00_ops *)id->driver_data;
369 struct ieee80211_hw *hw;
370 struct rt2x00_dev *rt2x00dev;
371 int retval;
372
373 retval = pci_request_regions(pci_dev, pci_name(pci_dev));
374 if (retval) {
375 ERROR_PROBE("PCI request regions failed.\n");
376 return retval;
377 }
378
379 retval = pci_enable_device(pci_dev);
380 if (retval) {
381 ERROR_PROBE("Enable device failed.\n");
382 goto exit_release_regions;
383 }
384
385 pci_set_master(pci_dev);
386
387 if (pci_set_mwi(pci_dev))
388 ERROR_PROBE("MWI not available.\n");
389
390 if (pci_set_dma_mask(pci_dev, DMA_64BIT_MASK) &&
391 pci_set_dma_mask(pci_dev, DMA_32BIT_MASK)) {
392 ERROR_PROBE("PCI DMA not supported.\n");
393 retval = -EIO;
394 goto exit_disable_device;
395 }
396
397 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
398 if (!hw) {
399 ERROR_PROBE("Failed to allocate hardware.\n");
400 retval = -ENOMEM;
401 goto exit_disable_device;
402 }
403
404 pci_set_drvdata(pci_dev, hw);
405
406 rt2x00dev = hw->priv;
407 rt2x00dev->dev = pci_dev;
408 rt2x00dev->ops = ops;
409 rt2x00dev->hw = hw;
410
411 retval = rt2x00pci_alloc_reg(rt2x00dev);
412 if (retval)
413 goto exit_free_device;
414
415 retval = rt2x00lib_probe_dev(rt2x00dev);
416 if (retval)
417 goto exit_free_reg;
418
419 return 0;
420
421exit_free_reg:
422 rt2x00pci_free_reg(rt2x00dev);
423
424exit_free_device:
425 ieee80211_free_hw(hw);
426
427exit_disable_device:
428 if (retval != -EBUSY)
429 pci_disable_device(pci_dev);
430
431exit_release_regions:
432 pci_release_regions(pci_dev);
433
434 pci_set_drvdata(pci_dev, NULL);
435
436 return retval;
437}
438EXPORT_SYMBOL_GPL(rt2x00pci_probe);
439
440void rt2x00pci_remove(struct pci_dev *pci_dev)
441{
442 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
443 struct rt2x00_dev *rt2x00dev = hw->priv;
444
445 /*
446 * Free all allocated data.
447 */
448 rt2x00lib_remove_dev(rt2x00dev);
449 rt2x00pci_free_reg(rt2x00dev);
450 ieee80211_free_hw(hw);
451
452 /*
453 * Free the PCI device data.
454 */
455 pci_set_drvdata(pci_dev, NULL);
456 pci_disable_device(pci_dev);
457 pci_release_regions(pci_dev);
458}
459EXPORT_SYMBOL_GPL(rt2x00pci_remove);
460
461#ifdef CONFIG_PM
462int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state)
463{
464 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
465 struct rt2x00_dev *rt2x00dev = hw->priv;
466 int retval;
467
468 retval = rt2x00lib_suspend(rt2x00dev, state);
469 if (retval)
470 return retval;
471
472 rt2x00pci_free_reg(rt2x00dev);
473
474 pci_save_state(pci_dev);
475 pci_disable_device(pci_dev);
476 return pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
477}
478EXPORT_SYMBOL_GPL(rt2x00pci_suspend);
479
480int rt2x00pci_resume(struct pci_dev *pci_dev)
481{
482 struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
483 struct rt2x00_dev *rt2x00dev = hw->priv;
484 int retval;
485
486 if (pci_set_power_state(pci_dev, PCI_D0) ||
487 pci_enable_device(pci_dev) ||
488 pci_restore_state(pci_dev)) {
489 ERROR(rt2x00dev, "Failed to resume device.\n");
490 return -EIO;
491 }
492
493 retval = rt2x00pci_alloc_reg(rt2x00dev);
494 if (retval)
495 return retval;
496
497 retval = rt2x00lib_resume(rt2x00dev);
498 if (retval)
499 goto exit_free_reg;
500
501 return 0;
502
503exit_free_reg:
504 rt2x00pci_free_reg(rt2x00dev);
505
506 return retval;
507}
508EXPORT_SYMBOL_GPL(rt2x00pci_resume);
509#endif /* CONFIG_PM */
510
511/*
512 * rt2x00pci module information.
513 */
514MODULE_AUTHOR(DRV_PROJECT);
515MODULE_VERSION(DRV_VERSION);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500516MODULE_DESCRIPTION("rt2x00 pci library");
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700517MODULE_LICENSE("GPL");