Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 2 | Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 3 | <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 Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 31 | |
| 32 | #include "rt2x00.h" |
| 33 | #include "rt2x00pci.h" |
| 34 | |
| 35 | /* |
Ivo van Doorn | c9c3b1a | 2008-11-10 19:41:40 +0100 | [diff] [blame] | 36 | * Register access. |
| 37 | */ |
| 38 | int rt2x00pci_regbusy_read(struct rt2x00_dev *rt2x00dev, |
| 39 | const unsigned int offset, |
| 40 | const struct rt2x00_field32 field, |
| 41 | u32 *reg) |
| 42 | { |
| 43 | unsigned int i; |
| 44 | |
Alban Browaeys | c70762f | 2009-12-04 23:46:57 +0100 | [diff] [blame] | 45 | if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags)) |
| 46 | return 0; |
| 47 | |
Ivo van Doorn | c9c3b1a | 2008-11-10 19:41:40 +0100 | [diff] [blame] | 48 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 49 | rt2x00pci_register_read(rt2x00dev, offset, reg); |
| 50 | if (!rt2x00_get_field32(*reg, field)) |
| 51 | return 1; |
| 52 | udelay(REGISTER_BUSY_DELAY); |
| 53 | } |
| 54 | |
| 55 | ERROR(rt2x00dev, "Indirect register access failed: " |
| 56 | "offset=0x%.08x, value=0x%.08x\n", offset, *reg); |
| 57 | *reg = ~0; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | EXPORT_SYMBOL_GPL(rt2x00pci_regbusy_read); |
| 62 | |
Helmut Schaa | 1663893 | 2011-03-28 13:29:44 +0200 | [diff] [blame] | 63 | bool rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 64 | { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 65 | struct data_queue *queue = rt2x00dev->rx; |
| 66 | struct queue_entry *entry; |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 67 | struct queue_entry_priv_pci *entry_priv; |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 68 | struct skb_frame_desc *skbdesc; |
Helmut Schaa | 1663893 | 2011-03-28 13:29:44 +0200 | [diff] [blame] | 69 | int max_rx = 16; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 70 | |
Helmut Schaa | 1663893 | 2011-03-28 13:29:44 +0200 | [diff] [blame] | 71 | while (--max_rx) { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 72 | entry = rt2x00queue_get_entry(queue, Q_INDEX); |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 73 | entry_priv = entry->priv_data; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 74 | |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 75 | if (rt2x00dev->ops->lib->get_entry_state(entry)) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 76 | break; |
| 77 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 78 | /* |
| 79 | * Fill in desc fields of the skb descriptor |
| 80 | */ |
| 81 | skbdesc = get_skb_frame_desc(entry->skb); |
| 82 | skbdesc->desc = entry_priv->desc; |
| 83 | skbdesc->desc_len = entry->queue->desc_size; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 84 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 85 | /* |
Ivo van Doorn | 64e7d72 | 2010-12-13 12:36:00 +0100 | [diff] [blame] | 86 | * DMA is already done, notify rt2x00lib that |
| 87 | * it finished successfully. |
| 88 | */ |
| 89 | rt2x00lib_dmastart(entry); |
| 90 | rt2x00lib_dmadone(entry); |
| 91 | |
| 92 | /* |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 93 | * Send the frame to rt2x00lib for further processing. |
| 94 | */ |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 95 | rt2x00lib_rxdone(entry); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 96 | } |
Helmut Schaa | 1663893 | 2011-03-28 13:29:44 +0200 | [diff] [blame] | 97 | |
| 98 | return !max_rx; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 99 | } |
| 100 | EXPORT_SYMBOL_GPL(rt2x00pci_rxdone); |
| 101 | |
Ivo van Doorn | 152a599 | 2011-04-18 15:31:02 +0200 | [diff] [blame] | 102 | void rt2x00pci_flush_queue(struct data_queue *queue, bool drop) |
| 103 | { |
| 104 | unsigned int i; |
| 105 | |
| 106 | for (i = 0; !rt2x00queue_empty(queue) && i < 10; i++) |
| 107 | msleep(10); |
| 108 | } |
| 109 | EXPORT_SYMBOL_GPL(rt2x00pci_flush_queue); |
| 110 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 111 | /* |
| 112 | * Device initialization handlers. |
| 113 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 114 | static int rt2x00pci_alloc_queue_dma(struct rt2x00_dev *rt2x00dev, |
| 115 | struct data_queue *queue) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 116 | { |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 117 | struct queue_entry_priv_pci *entry_priv; |
Ivo van Doorn | 30b3a23 | 2008-02-17 17:33:24 +0100 | [diff] [blame] | 118 | void *addr; |
Ivo van Doorn | 9c9dd2c | 2008-02-10 22:46:52 +0100 | [diff] [blame] | 119 | dma_addr_t dma; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 120 | unsigned int i; |
| 121 | |
| 122 | /* |
| 123 | * Allocate DMA memory for descriptor and buffer. |
| 124 | */ |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 125 | addr = dma_alloc_coherent(rt2x00dev->dev, |
| 126 | queue->limit * queue->desc_size, |
John W. Linville | b923757 | 2010-10-25 10:33:07 -0400 | [diff] [blame] | 127 | &dma, GFP_KERNEL); |
Ivo van Doorn | 30b3a23 | 2008-02-17 17:33:24 +0100 | [diff] [blame] | 128 | if (!addr) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 129 | return -ENOMEM; |
| 130 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 131 | memset(addr, 0, queue->limit * queue->desc_size); |
Ivo van Doorn | 9c9dd2c | 2008-02-10 22:46:52 +0100 | [diff] [blame] | 132 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 133 | /* |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 134 | * Initialize all queue entries to contain valid addresses. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 135 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 136 | for (i = 0; i < queue->limit; i++) { |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 137 | entry_priv = queue->entries[i].priv_data; |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 138 | entry_priv->desc = addr + i * queue->desc_size; |
| 139 | entry_priv->desc_dma = dma + i * queue->desc_size; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 145 | static void rt2x00pci_free_queue_dma(struct rt2x00_dev *rt2x00dev, |
| 146 | struct data_queue *queue) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 147 | { |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 148 | struct queue_entry_priv_pci *entry_priv = |
| 149 | queue->entries[0].priv_data; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 150 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 151 | if (entry_priv->desc) |
| 152 | dma_free_coherent(rt2x00dev->dev, |
| 153 | queue->limit * queue->desc_size, |
| 154 | entry_priv->desc, entry_priv->desc_dma); |
| 155 | entry_priv->desc = NULL; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev) |
| 159 | { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 160 | struct data_queue *queue; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 161 | int status; |
| 162 | |
| 163 | /* |
| 164 | * Allocate DMA |
| 165 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 166 | queue_for_each(rt2x00dev, queue) { |
| 167 | status = rt2x00pci_alloc_queue_dma(rt2x00dev, queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 168 | if (status) |
| 169 | goto exit; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Register interrupt handler. |
| 174 | */ |
Helmut Schaa | e88399b | 2011-01-30 13:20:29 +0100 | [diff] [blame] | 175 | status = request_irq(rt2x00dev->irq, |
| 176 | rt2x00dev->ops->lib->irq_handler, |
| 177 | IRQF_SHARED, rt2x00dev->name, rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 178 | if (status) { |
| 179 | ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n", |
Ivo van Doorn | 440ddada | 2009-03-28 20:51:24 +0100 | [diff] [blame] | 180 | rt2x00dev->irq, status); |
Ivo van Doorn | b30cdfc | 2008-05-05 17:24:03 +0200 | [diff] [blame] | 181 | goto exit; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | return 0; |
| 185 | |
| 186 | exit: |
Ivo van Doorn | b30cdfc | 2008-05-05 17:24:03 +0200 | [diff] [blame] | 187 | queue_for_each(rt2x00dev, queue) |
| 188 | rt2x00pci_free_queue_dma(rt2x00dev, queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 189 | |
| 190 | return status; |
| 191 | } |
| 192 | EXPORT_SYMBOL_GPL(rt2x00pci_initialize); |
| 193 | |
| 194 | void rt2x00pci_uninitialize(struct rt2x00_dev *rt2x00dev) |
| 195 | { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 196 | struct data_queue *queue; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * Free irq line. |
| 200 | */ |
Helmut Schaa | 52a9bd2 | 2010-05-19 08:47:59 +0200 | [diff] [blame] | 201 | free_irq(rt2x00dev->irq, rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Free DMA |
| 205 | */ |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 206 | queue_for_each(rt2x00dev, queue) |
| 207 | rt2x00pci_free_queue_dma(rt2x00dev, queue); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 208 | } |
| 209 | EXPORT_SYMBOL_GPL(rt2x00pci_uninitialize); |
| 210 | |
| 211 | /* |
| 212 | * PCI driver handlers. |
| 213 | */ |
| 214 | static void rt2x00pci_free_reg(struct rt2x00_dev *rt2x00dev) |
| 215 | { |
| 216 | kfree(rt2x00dev->rf); |
| 217 | rt2x00dev->rf = NULL; |
| 218 | |
| 219 | kfree(rt2x00dev->eeprom); |
| 220 | rt2x00dev->eeprom = NULL; |
| 221 | |
Ivo van Doorn | 2179509 | 2008-02-10 22:49:13 +0100 | [diff] [blame] | 222 | if (rt2x00dev->csr.base) { |
| 223 | iounmap(rt2x00dev->csr.base); |
| 224 | rt2x00dev->csr.base = NULL; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | static int rt2x00pci_alloc_reg(struct rt2x00_dev *rt2x00dev) |
| 229 | { |
Gertjan van Wingerde | 14a3bf8 | 2008-06-16 19:55:43 +0200 | [diff] [blame] | 230 | struct pci_dev *pci_dev = to_pci_dev(rt2x00dev->dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 231 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 232 | rt2x00dev->csr.base = pci_ioremap_bar(pci_dev, 0); |
Ivo van Doorn | 2179509 | 2008-02-10 22:49:13 +0100 | [diff] [blame] | 233 | if (!rt2x00dev->csr.base) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 234 | goto exit; |
| 235 | |
| 236 | rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL); |
| 237 | if (!rt2x00dev->eeprom) |
| 238 | goto exit; |
| 239 | |
| 240 | rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL); |
| 241 | if (!rt2x00dev->rf) |
| 242 | goto exit; |
| 243 | |
| 244 | return 0; |
| 245 | |
| 246 | exit: |
| 247 | ERROR_PROBE("Failed to allocate registers.\n"); |
| 248 | |
| 249 | rt2x00pci_free_reg(rt2x00dev); |
| 250 | |
| 251 | return -ENOMEM; |
| 252 | } |
| 253 | |
Gertjan van Wingerde | e01ae27 | 2011-04-18 15:32:13 +0200 | [diff] [blame] | 254 | int rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 255 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 256 | struct ieee80211_hw *hw; |
| 257 | struct rt2x00_dev *rt2x00dev; |
| 258 | int retval; |
| 259 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 260 | retval = pci_enable_device(pci_dev); |
| 261 | if (retval) { |
| 262 | ERROR_PROBE("Enable device failed.\n"); |
Kulikov Vasiliy | 47cb905 | 2010-08-03 19:43:22 +0400 | [diff] [blame] | 263 | return retval; |
| 264 | } |
| 265 | |
| 266 | retval = pci_request_regions(pci_dev, pci_name(pci_dev)); |
| 267 | if (retval) { |
| 268 | ERROR_PROBE("PCI request regions failed.\n"); |
| 269 | goto exit_disable_device; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | pci_set_master(pci_dev); |
| 273 | |
| 274 | if (pci_set_mwi(pci_dev)) |
| 275 | ERROR_PROBE("MWI not available.\n"); |
| 276 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 277 | if (dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32))) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 278 | ERROR_PROBE("PCI DMA not supported.\n"); |
| 279 | retval = -EIO; |
Kulikov Vasiliy | 47cb905 | 2010-08-03 19:43:22 +0400 | [diff] [blame] | 280 | goto exit_release_regions; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw); |
| 284 | if (!hw) { |
| 285 | ERROR_PROBE("Failed to allocate hardware.\n"); |
| 286 | retval = -ENOMEM; |
Kulikov Vasiliy | 47cb905 | 2010-08-03 19:43:22 +0400 | [diff] [blame] | 287 | goto exit_release_regions; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | pci_set_drvdata(pci_dev, hw); |
| 291 | |
| 292 | rt2x00dev = hw->priv; |
Gertjan van Wingerde | 14a3bf8 | 2008-06-16 19:55:43 +0200 | [diff] [blame] | 293 | rt2x00dev->dev = &pci_dev->dev; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 294 | rt2x00dev->ops = ops; |
| 295 | rt2x00dev->hw = hw; |
Ivo van Doorn | 440ddada | 2009-03-28 20:51:24 +0100 | [diff] [blame] | 296 | rt2x00dev->irq = pci_dev->irq; |
| 297 | rt2x00dev->name = pci_name(pci_dev); |
| 298 | |
Hauke Mehrtens | 2cdb9a4 | 2010-12-21 02:01:53 +0100 | [diff] [blame] | 299 | if (pci_is_pcie(pci_dev)) |
Gertjan van Wingerde | 6e1fdd1 | 2010-06-03 10:52:00 +0200 | [diff] [blame] | 300 | rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE); |
| 301 | else |
| 302 | rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI); |
Gertjan van Wingerde | 2015d19 | 2009-11-08 12:30:14 +0100 | [diff] [blame] | 303 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 304 | retval = rt2x00pci_alloc_reg(rt2x00dev); |
| 305 | if (retval) |
| 306 | goto exit_free_device; |
| 307 | |
| 308 | retval = rt2x00lib_probe_dev(rt2x00dev); |
| 309 | if (retval) |
| 310 | goto exit_free_reg; |
| 311 | |
| 312 | return 0; |
| 313 | |
| 314 | exit_free_reg: |
| 315 | rt2x00pci_free_reg(rt2x00dev); |
| 316 | |
| 317 | exit_free_device: |
| 318 | ieee80211_free_hw(hw); |
| 319 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 320 | exit_release_regions: |
| 321 | pci_release_regions(pci_dev); |
| 322 | |
Kulikov Vasiliy | 47cb905 | 2010-08-03 19:43:22 +0400 | [diff] [blame] | 323 | exit_disable_device: |
| 324 | pci_disable_device(pci_dev); |
| 325 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 326 | pci_set_drvdata(pci_dev, NULL); |
| 327 | |
| 328 | return retval; |
| 329 | } |
| 330 | EXPORT_SYMBOL_GPL(rt2x00pci_probe); |
| 331 | |
| 332 | void rt2x00pci_remove(struct pci_dev *pci_dev) |
| 333 | { |
| 334 | struct ieee80211_hw *hw = pci_get_drvdata(pci_dev); |
| 335 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 336 | |
| 337 | /* |
| 338 | * Free all allocated data. |
| 339 | */ |
| 340 | rt2x00lib_remove_dev(rt2x00dev); |
| 341 | rt2x00pci_free_reg(rt2x00dev); |
| 342 | ieee80211_free_hw(hw); |
| 343 | |
| 344 | /* |
| 345 | * Free the PCI device data. |
| 346 | */ |
| 347 | pci_set_drvdata(pci_dev, NULL); |
| 348 | pci_disable_device(pci_dev); |
| 349 | pci_release_regions(pci_dev); |
| 350 | } |
| 351 | EXPORT_SYMBOL_GPL(rt2x00pci_remove); |
| 352 | |
| 353 | #ifdef CONFIG_PM |
| 354 | int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state) |
| 355 | { |
| 356 | struct ieee80211_hw *hw = pci_get_drvdata(pci_dev); |
| 357 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 358 | int retval; |
| 359 | |
| 360 | retval = rt2x00lib_suspend(rt2x00dev, state); |
| 361 | if (retval) |
| 362 | return retval; |
| 363 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 364 | pci_save_state(pci_dev); |
| 365 | pci_disable_device(pci_dev); |
| 366 | return pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state)); |
| 367 | } |
| 368 | EXPORT_SYMBOL_GPL(rt2x00pci_suspend); |
| 369 | |
| 370 | int rt2x00pci_resume(struct pci_dev *pci_dev) |
| 371 | { |
| 372 | struct ieee80211_hw *hw = pci_get_drvdata(pci_dev); |
| 373 | struct rt2x00_dev *rt2x00dev = hw->priv; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 374 | |
| 375 | if (pci_set_power_state(pci_dev, PCI_D0) || |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 376 | pci_enable_device(pci_dev)) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 377 | ERROR(rt2x00dev, "Failed to resume device.\n"); |
| 378 | return -EIO; |
| 379 | } |
| 380 | |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 381 | pci_restore_state(pci_dev); |
Ivo van Doorn | 499a214 | 2009-03-28 20:51:58 +0100 | [diff] [blame] | 382 | return rt2x00lib_resume(rt2x00dev); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 383 | } |
| 384 | EXPORT_SYMBOL_GPL(rt2x00pci_resume); |
| 385 | #endif /* CONFIG_PM */ |
| 386 | |
| 387 | /* |
| 388 | * rt2x00pci module information. |
| 389 | */ |
| 390 | MODULE_AUTHOR(DRV_PROJECT); |
| 391 | MODULE_VERSION(DRV_VERSION); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 392 | MODULE_DESCRIPTION("rt2x00 pci library"); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 393 | MODULE_LICENSE("GPL"); |