treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / ralink / rt2x00 / rt2x00mmio.c
blob93f76acf3dc7df8433125c52b6db27f3eea9f7e1
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
4 <http://rt2x00.serialmonkey.com>
6 */
8 /*
9 Module: rt2x00mmio
10 Abstract: rt2x00 generic mmio device routines.
13 #include <linux/dma-mapping.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
18 #include "rt2x00.h"
19 #include "rt2x00mmio.h"
22 * Register access.
24 int rt2x00mmio_regbusy_read(struct rt2x00_dev *rt2x00dev,
25 const unsigned int offset,
26 const struct rt2x00_field32 field,
27 u32 *reg)
29 unsigned int i;
31 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
32 return 0;
34 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
35 *reg = rt2x00mmio_register_read(rt2x00dev, offset);
36 if (!rt2x00_get_field32(*reg, field))
37 return 1;
38 udelay(REGISTER_BUSY_DELAY);
41 printk_once(KERN_ERR "%s() Indirect register access failed: "
42 "offset=0x%.08x, value=0x%.08x\n", __func__, offset, *reg);
43 *reg = ~0;
45 return 0;
47 EXPORT_SYMBOL_GPL(rt2x00mmio_regbusy_read);
49 bool rt2x00mmio_rxdone(struct rt2x00_dev *rt2x00dev)
51 struct data_queue *queue = rt2x00dev->rx;
52 struct queue_entry *entry;
53 struct queue_entry_priv_mmio *entry_priv;
54 struct skb_frame_desc *skbdesc;
55 int max_rx = 16;
57 while (--max_rx) {
58 entry = rt2x00queue_get_entry(queue, Q_INDEX);
59 entry_priv = entry->priv_data;
61 if (rt2x00dev->ops->lib->get_entry_state(entry))
62 break;
65 * Fill in desc fields of the skb descriptor
67 skbdesc = get_skb_frame_desc(entry->skb);
68 skbdesc->desc = entry_priv->desc;
69 skbdesc->desc_len = entry->queue->desc_size;
72 * DMA is already done, notify rt2x00lib that
73 * it finished successfully.
75 rt2x00lib_dmastart(entry);
76 rt2x00lib_dmadone(entry);
79 * Send the frame to rt2x00lib for further processing.
81 rt2x00lib_rxdone(entry, GFP_ATOMIC);
84 return !max_rx;
86 EXPORT_SYMBOL_GPL(rt2x00mmio_rxdone);
88 void rt2x00mmio_flush_queue(struct data_queue *queue, bool drop)
90 unsigned int i;
92 for (i = 0; !rt2x00queue_empty(queue) && i < 10; i++)
93 msleep(50);
95 EXPORT_SYMBOL_GPL(rt2x00mmio_flush_queue);
98 * Device initialization handlers.
100 static int rt2x00mmio_alloc_queue_dma(struct rt2x00_dev *rt2x00dev,
101 struct data_queue *queue)
103 struct queue_entry_priv_mmio *entry_priv;
104 void *addr;
105 dma_addr_t dma;
106 unsigned int i;
109 * Allocate DMA memory for descriptor and buffer.
111 addr = dma_alloc_coherent(rt2x00dev->dev,
112 queue->limit * queue->desc_size, &dma,
113 GFP_KERNEL);
114 if (!addr)
115 return -ENOMEM;
118 * Initialize all queue entries to contain valid addresses.
120 for (i = 0; i < queue->limit; i++) {
121 entry_priv = queue->entries[i].priv_data;
122 entry_priv->desc = addr + i * queue->desc_size;
123 entry_priv->desc_dma = dma + i * queue->desc_size;
126 return 0;
129 static void rt2x00mmio_free_queue_dma(struct rt2x00_dev *rt2x00dev,
130 struct data_queue *queue)
132 struct queue_entry_priv_mmio *entry_priv =
133 queue->entries[0].priv_data;
135 if (entry_priv->desc)
136 dma_free_coherent(rt2x00dev->dev,
137 queue->limit * queue->desc_size,
138 entry_priv->desc, entry_priv->desc_dma);
139 entry_priv->desc = NULL;
142 int rt2x00mmio_initialize(struct rt2x00_dev *rt2x00dev)
144 struct data_queue *queue;
145 int status;
148 * Allocate DMA
150 queue_for_each(rt2x00dev, queue) {
151 status = rt2x00mmio_alloc_queue_dma(rt2x00dev, queue);
152 if (status)
153 goto exit;
157 * Register interrupt handler.
159 status = request_irq(rt2x00dev->irq,
160 rt2x00dev->ops->lib->irq_handler,
161 IRQF_SHARED, rt2x00dev->name, rt2x00dev);
162 if (status) {
163 rt2x00_err(rt2x00dev, "IRQ %d allocation failed (error %d)\n",
164 rt2x00dev->irq, status);
165 goto exit;
168 return 0;
170 exit:
171 queue_for_each(rt2x00dev, queue)
172 rt2x00mmio_free_queue_dma(rt2x00dev, queue);
174 return status;
176 EXPORT_SYMBOL_GPL(rt2x00mmio_initialize);
178 void rt2x00mmio_uninitialize(struct rt2x00_dev *rt2x00dev)
180 struct data_queue *queue;
183 * Free irq line.
185 free_irq(rt2x00dev->irq, rt2x00dev);
188 * Free DMA
190 queue_for_each(rt2x00dev, queue)
191 rt2x00mmio_free_queue_dma(rt2x00dev, queue);
193 EXPORT_SYMBOL_GPL(rt2x00mmio_uninitialize);
196 * rt2x00mmio module information.
198 MODULE_AUTHOR(DRV_PROJECT);
199 MODULE_VERSION(DRV_VERSION);
200 MODULE_DESCRIPTION("rt2x00 mmio library");
201 MODULE_LICENSE("GPL");