blob: b0396ca0e6b03471676eff150b2e0e3c04f8053a [file] [log] [blame]
Gabor Juhos69a2bac2013-03-29 15:52:27 +01001/*
2 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
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: rt2x00mmio
23 Abstract: Data structures for the rt2x00mmio module.
24 */
25
26#ifndef RT2X00MMIO_H
27#define RT2X00MMIO_H
28
29#include <linux/io.h>
30
31/*
32 * Register access.
33 */
Gabor Juhos58959bd2013-04-05 08:27:00 +020034static inline void rt2x00mmio_register_read(struct rt2x00_dev *rt2x00dev,
35 const unsigned int offset,
36 u32 *value)
Gabor Juhos69a2bac2013-03-29 15:52:27 +010037{
38 *value = readl(rt2x00dev->csr.base + offset);
39}
Gabor Juhos58959bd2013-04-05 08:27:00 +020040#define rt2x00pci_register_read rt2x00mmio_register_read
Gabor Juhos69a2bac2013-03-29 15:52:27 +010041
Gabor Juhos58959bd2013-04-05 08:27:00 +020042static inline void rt2x00mmio_register_multiread(struct rt2x00_dev *rt2x00dev,
43 const unsigned int offset,
44 void *value, const u32 length)
Gabor Juhos69a2bac2013-03-29 15:52:27 +010045{
46 memcpy_fromio(value, rt2x00dev->csr.base + offset, length);
47}
Gabor Juhos58959bd2013-04-05 08:27:00 +020048#define rt2x00pci_register_multiread rt2x00mmio_register_multiread
Gabor Juhos69a2bac2013-03-29 15:52:27 +010049
Gabor Juhos58959bd2013-04-05 08:27:00 +020050static inline void rt2x00mmio_register_write(struct rt2x00_dev *rt2x00dev,
51 const unsigned int offset,
52 u32 value)
Gabor Juhos69a2bac2013-03-29 15:52:27 +010053{
54 writel(value, rt2x00dev->csr.base + offset);
55}
Gabor Juhos58959bd2013-04-05 08:27:00 +020056#define rt2x00pci_register_write rt2x00mmio_register_write
Gabor Juhos69a2bac2013-03-29 15:52:27 +010057
Gabor Juhos58959bd2013-04-05 08:27:00 +020058static inline void rt2x00mmio_register_multiwrite(struct rt2x00_dev *rt2x00dev,
59 const unsigned int offset,
60 const void *value,
61 const u32 length)
Gabor Juhos69a2bac2013-03-29 15:52:27 +010062{
63 __iowrite32_copy(rt2x00dev->csr.base + offset, value, length >> 2);
64}
Gabor Juhos58959bd2013-04-05 08:27:00 +020065#define rt2x00pci_register_multiwrite rt2x00mmio_register_multiwrite
Gabor Juhos69a2bac2013-03-29 15:52:27 +010066
67/**
Gabor Juhos58959bd2013-04-05 08:27:00 +020068 * rt2x00mmio_regbusy_read - Read from register with busy check
Gabor Juhos69a2bac2013-03-29 15:52:27 +010069 * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
70 * @offset: Register offset
71 * @field: Field to check if register is busy
72 * @reg: Pointer to where register contents should be stored
73 *
74 * This function will read the given register, and checks if the
75 * register is busy. If it is, it will sleep for a couple of
76 * microseconds before reading the register again. If the register
77 * is not read after a certain timeout, this function will return
78 * FALSE.
79 */
Gabor Juhos58959bd2013-04-05 08:27:00 +020080int rt2x00mmio_regbusy_read(struct rt2x00_dev *rt2x00dev,
81 const unsigned int offset,
82 const struct rt2x00_field32 field,
83 u32 *reg);
84#define rt2x00pci_regbusy_read rt2x00mmio_regbusy_read
Gabor Juhos69a2bac2013-03-29 15:52:27 +010085
86/**
Gabor Juhos58959bd2013-04-05 08:27:00 +020087 * struct queue_entry_priv_mmio: Per entry PCI specific information
Gabor Juhos69a2bac2013-03-29 15:52:27 +010088 *
89 * @desc: Pointer to device descriptor
90 * @desc_dma: DMA pointer to &desc.
91 * @data: Pointer to device's entry memory.
92 * @data_dma: DMA pointer to &data.
93 */
Gabor Juhos58959bd2013-04-05 08:27:00 +020094struct queue_entry_priv_mmio {
Gabor Juhos69a2bac2013-03-29 15:52:27 +010095 __le32 *desc;
96 dma_addr_t desc_dma;
97};
Gabor Juhos58959bd2013-04-05 08:27:00 +020098#define queue_entry_priv_pci queue_entry_priv_mmio
Gabor Juhos69a2bac2013-03-29 15:52:27 +010099
100/**
Gabor Juhos58959bd2013-04-05 08:27:00 +0200101 * rt2x00mmio_rxdone - Handle RX done events
Gabor Juhos69a2bac2013-03-29 15:52:27 +0100102 * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
103 *
104 * Returns true if there are still rx frames pending and false if all
105 * pending rx frames were processed.
106 */
Gabor Juhos58959bd2013-04-05 08:27:00 +0200107bool rt2x00mmio_rxdone(struct rt2x00_dev *rt2x00dev);
108#define rt2x00pci_rxdone rt2x00mmio_rxdone
Gabor Juhos69a2bac2013-03-29 15:52:27 +0100109
110/**
Gabor Juhos58959bd2013-04-05 08:27:00 +0200111 * rt2x00mmio_flush_queue - Flush data queue
Gabor Juhos69a2bac2013-03-29 15:52:27 +0100112 * @queue: Data queue to stop
113 * @drop: True to drop all pending frames.
114 *
115 * This will wait for a maximum of 100ms, waiting for the queues
116 * to become empty.
117 */
Gabor Juhos58959bd2013-04-05 08:27:00 +0200118void rt2x00mmio_flush_queue(struct data_queue *queue, bool drop);
119#define rt2x00pci_flush_queue rt2x00mmio_flush_queue
Gabor Juhos69a2bac2013-03-29 15:52:27 +0100120
121/*
122 * Device initialization handlers.
123 */
Gabor Juhos58959bd2013-04-05 08:27:00 +0200124int rt2x00mmio_initialize(struct rt2x00_dev *rt2x00dev);
125#define rt2x00pci_initialize rt2x00mmio_initialize
126
127void rt2x00mmio_uninitialize(struct rt2x00_dev *rt2x00dev);
128#define rt2x00pci_uninitialize rt2x00mmio_uninitialize
Gabor Juhos69a2bac2013-03-29 15:52:27 +0100129
130#endif /* RT2X00MMIO_H */