1 /*
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, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /*
20 	Module: rt2x00mmio
21 	Abstract: Data structures for the rt2x00mmio module.
22  */
23 
24 #ifndef RT2X00MMIO_H
25 #define RT2X00MMIO_H
26 
27 #include <linux/io.h>
28 
29 /*
30  * Register access.
31  */
32 static inline u32 rt2x00mmio_register_read(struct rt2x00_dev *rt2x00dev,
33 					   const unsigned int offset)
34 {
35 	return readl(rt2x00dev->csr.base + offset);
36 }
37 
38 static inline void rt2x00mmio_register_multiread(struct rt2x00_dev *rt2x00dev,
39 						 const unsigned int offset,
40 						 void *value, const u32 length)
41 {
42 	memcpy_fromio(value, rt2x00dev->csr.base + offset, length);
43 }
44 
45 static inline void rt2x00mmio_register_write(struct rt2x00_dev *rt2x00dev,
46 					     const unsigned int offset,
47 					     u32 value)
48 {
49 	writel(value, rt2x00dev->csr.base + offset);
50 }
51 
52 static inline void rt2x00mmio_register_multiwrite(struct rt2x00_dev *rt2x00dev,
53 						  const unsigned int offset,
54 						  const void *value,
55 						  const u32 length)
56 {
57 	__iowrite32_copy(rt2x00dev->csr.base + offset, value, length >> 2);
58 }
59 
60 /**
61  * rt2x00mmio_regbusy_read - Read from register with busy check
62  * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
63  * @offset: Register offset
64  * @field: Field to check if register is busy
65  * @reg: Pointer to where register contents should be stored
66  *
67  * This function will read the given register, and checks if the
68  * register is busy. If it is, it will sleep for a couple of
69  * microseconds before reading the register again. If the register
70  * is not read after a certain timeout, this function will return
71  * FALSE.
72  */
73 int rt2x00mmio_regbusy_read(struct rt2x00_dev *rt2x00dev,
74 			    const unsigned int offset,
75 			    const struct rt2x00_field32 field,
76 			    u32 *reg);
77 
78 /**
79  * struct queue_entry_priv_mmio: Per entry PCI specific information
80  *
81  * @desc: Pointer to device descriptor
82  * @desc_dma: DMA pointer to &desc.
83  * @data: Pointer to device's entry memory.
84  * @data_dma: DMA pointer to &data.
85  */
86 struct queue_entry_priv_mmio {
87 	__le32 *desc;
88 	dma_addr_t desc_dma;
89 };
90 
91 /**
92  * rt2x00mmio_rxdone - Handle RX done events
93  * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
94  *
95  * Returns true if there are still rx frames pending and false if all
96  * pending rx frames were processed.
97  */
98 bool rt2x00mmio_rxdone(struct rt2x00_dev *rt2x00dev);
99 
100 /**
101  * rt2x00mmio_flush_queue - Flush data queue
102  * @queue: Data queue to stop
103  * @drop: True to drop all pending frames.
104  *
105  * This will wait for a maximum of 100ms, waiting for the queues
106  * to become empty.
107  */
108 void rt2x00mmio_flush_queue(struct data_queue *queue, bool drop);
109 
110 /*
111  * Device initialization handlers.
112  */
113 int rt2x00mmio_initialize(struct rt2x00_dev *rt2x00dev);
114 void rt2x00mmio_uninitialize(struct rt2x00_dev *rt2x00dev);
115 
116 #endif /* RT2X00MMIO_H */
117