This source file includes following definitions.
- _ef4_writeq
- _ef4_readq
- _ef4_writed
- _ef4_readd
- ef4_writeo
- ef4_sram_writeq
- ef4_writed
- ef4_reado
- ef4_sram_readq
- ef4_readd
- ef4_writeo_table
- ef4_reado_table
- _ef4_writeo_page
- _ef4_writed_page
- _ef4_writed_page_locked
1
2
3
4
5
6
7
8 #ifndef EF4_IO_H
9 #define EF4_IO_H
10
11 #include <linux/io.h>
12 #include <linux/spinlock.h>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 #if BITS_PER_LONG == 64
63 #define EF4_USE_QWORD_IO 1
64 #endif
65
66 #ifdef EF4_USE_QWORD_IO
67 static inline void _ef4_writeq(struct ef4_nic *efx, __le64 value,
68 unsigned int reg)
69 {
70 __raw_writeq((__force u64)value, efx->membase + reg);
71 }
72 static inline __le64 _ef4_readq(struct ef4_nic *efx, unsigned int reg)
73 {
74 return (__force __le64)__raw_readq(efx->membase + reg);
75 }
76 #endif
77
78 static inline void _ef4_writed(struct ef4_nic *efx, __le32 value,
79 unsigned int reg)
80 {
81 __raw_writel((__force u32)value, efx->membase + reg);
82 }
83 static inline __le32 _ef4_readd(struct ef4_nic *efx, unsigned int reg)
84 {
85 return (__force __le32)__raw_readl(efx->membase + reg);
86 }
87
88
89 static inline void ef4_writeo(struct ef4_nic *efx, const ef4_oword_t *value,
90 unsigned int reg)
91 {
92 unsigned long flags __attribute__ ((unused));
93
94 netif_vdbg(efx, hw, efx->net_dev,
95 "writing register %x with " EF4_OWORD_FMT "\n", reg,
96 EF4_OWORD_VAL(*value));
97
98 spin_lock_irqsave(&efx->biu_lock, flags);
99 #ifdef EF4_USE_QWORD_IO
100 _ef4_writeq(efx, value->u64[0], reg + 0);
101 _ef4_writeq(efx, value->u64[1], reg + 8);
102 #else
103 _ef4_writed(efx, value->u32[0], reg + 0);
104 _ef4_writed(efx, value->u32[1], reg + 4);
105 _ef4_writed(efx, value->u32[2], reg + 8);
106 _ef4_writed(efx, value->u32[3], reg + 12);
107 #endif
108 spin_unlock_irqrestore(&efx->biu_lock, flags);
109 }
110
111
112 static inline void ef4_sram_writeq(struct ef4_nic *efx, void __iomem *membase,
113 const ef4_qword_t *value, unsigned int index)
114 {
115 unsigned int addr = index * sizeof(*value);
116 unsigned long flags __attribute__ ((unused));
117
118 netif_vdbg(efx, hw, efx->net_dev,
119 "writing SRAM address %x with " EF4_QWORD_FMT "\n",
120 addr, EF4_QWORD_VAL(*value));
121
122 spin_lock_irqsave(&efx->biu_lock, flags);
123 #ifdef EF4_USE_QWORD_IO
124 __raw_writeq((__force u64)value->u64[0], membase + addr);
125 #else
126 __raw_writel((__force u32)value->u32[0], membase + addr);
127 __raw_writel((__force u32)value->u32[1], membase + addr + 4);
128 #endif
129 spin_unlock_irqrestore(&efx->biu_lock, flags);
130 }
131
132
133 static inline void ef4_writed(struct ef4_nic *efx, const ef4_dword_t *value,
134 unsigned int reg)
135 {
136 netif_vdbg(efx, hw, efx->net_dev,
137 "writing register %x with "EF4_DWORD_FMT"\n",
138 reg, EF4_DWORD_VAL(*value));
139
140
141 _ef4_writed(efx, value->u32[0], reg);
142 }
143
144
145 static inline void ef4_reado(struct ef4_nic *efx, ef4_oword_t *value,
146 unsigned int reg)
147 {
148 unsigned long flags __attribute__ ((unused));
149
150 spin_lock_irqsave(&efx->biu_lock, flags);
151 value->u32[0] = _ef4_readd(efx, reg + 0);
152 value->u32[1] = _ef4_readd(efx, reg + 4);
153 value->u32[2] = _ef4_readd(efx, reg + 8);
154 value->u32[3] = _ef4_readd(efx, reg + 12);
155 spin_unlock_irqrestore(&efx->biu_lock, flags);
156
157 netif_vdbg(efx, hw, efx->net_dev,
158 "read from register %x, got " EF4_OWORD_FMT "\n", reg,
159 EF4_OWORD_VAL(*value));
160 }
161
162
163 static inline void ef4_sram_readq(struct ef4_nic *efx, void __iomem *membase,
164 ef4_qword_t *value, unsigned int index)
165 {
166 unsigned int addr = index * sizeof(*value);
167 unsigned long flags __attribute__ ((unused));
168
169 spin_lock_irqsave(&efx->biu_lock, flags);
170 #ifdef EF4_USE_QWORD_IO
171 value->u64[0] = (__force __le64)__raw_readq(membase + addr);
172 #else
173 value->u32[0] = (__force __le32)__raw_readl(membase + addr);
174 value->u32[1] = (__force __le32)__raw_readl(membase + addr + 4);
175 #endif
176 spin_unlock_irqrestore(&efx->biu_lock, flags);
177
178 netif_vdbg(efx, hw, efx->net_dev,
179 "read from SRAM address %x, got "EF4_QWORD_FMT"\n",
180 addr, EF4_QWORD_VAL(*value));
181 }
182
183
184 static inline void ef4_readd(struct ef4_nic *efx, ef4_dword_t *value,
185 unsigned int reg)
186 {
187 value->u32[0] = _ef4_readd(efx, reg);
188 netif_vdbg(efx, hw, efx->net_dev,
189 "read from register %x, got "EF4_DWORD_FMT"\n",
190 reg, EF4_DWORD_VAL(*value));
191 }
192
193
194 static inline void
195 ef4_writeo_table(struct ef4_nic *efx, const ef4_oword_t *value,
196 unsigned int reg, unsigned int index)
197 {
198 ef4_writeo(efx, value, reg + index * sizeof(ef4_oword_t));
199 }
200
201
202 static inline void ef4_reado_table(struct ef4_nic *efx, ef4_oword_t *value,
203 unsigned int reg, unsigned int index)
204 {
205 ef4_reado(efx, value, reg + index * sizeof(ef4_oword_t));
206 }
207
208
209 #define EF4_VI_PAGE_SIZE 0x2000
210
211
212 #define EF4_PAGED_REG(page, reg) \
213 ((page) * EF4_VI_PAGE_SIZE + (reg))
214
215
216 static inline void _ef4_writeo_page(struct ef4_nic *efx, ef4_oword_t *value,
217 unsigned int reg, unsigned int page)
218 {
219 reg = EF4_PAGED_REG(page, reg);
220
221 netif_vdbg(efx, hw, efx->net_dev,
222 "writing register %x with " EF4_OWORD_FMT "\n", reg,
223 EF4_OWORD_VAL(*value));
224
225 #ifdef EF4_USE_QWORD_IO
226 _ef4_writeq(efx, value->u64[0], reg + 0);
227 _ef4_writeq(efx, value->u64[1], reg + 8);
228 #else
229 _ef4_writed(efx, value->u32[0], reg + 0);
230 _ef4_writed(efx, value->u32[1], reg + 4);
231 _ef4_writed(efx, value->u32[2], reg + 8);
232 _ef4_writed(efx, value->u32[3], reg + 12);
233 #endif
234 }
235 #define ef4_writeo_page(efx, value, reg, page) \
236 _ef4_writeo_page(efx, value, \
237 reg + \
238 BUILD_BUG_ON_ZERO((reg) != 0x830 && (reg) != 0xa10), \
239 page)
240
241
242
243
244 static inline void
245 _ef4_writed_page(struct ef4_nic *efx, const ef4_dword_t *value,
246 unsigned int reg, unsigned int page)
247 {
248 ef4_writed(efx, value, EF4_PAGED_REG(page, reg));
249 }
250 #define ef4_writed_page(efx, value, reg, page) \
251 _ef4_writed_page(efx, value, \
252 reg + \
253 BUILD_BUG_ON_ZERO((reg) != 0x400 && \
254 (reg) != 0x420 && \
255 (reg) != 0x830 && \
256 (reg) != 0x83c && \
257 (reg) != 0xa18 && \
258 (reg) != 0xa1c), \
259 page)
260
261
262
263
264
265 static inline void _ef4_writed_page_locked(struct ef4_nic *efx,
266 const ef4_dword_t *value,
267 unsigned int reg,
268 unsigned int page)
269 {
270 unsigned long flags __attribute__ ((unused));
271
272 if (page == 0) {
273 spin_lock_irqsave(&efx->biu_lock, flags);
274 ef4_writed(efx, value, EF4_PAGED_REG(page, reg));
275 spin_unlock_irqrestore(&efx->biu_lock, flags);
276 } else {
277 ef4_writed(efx, value, EF4_PAGED_REG(page, reg));
278 }
279 }
280 #define ef4_writed_page_locked(efx, value, reg, page) \
281 _ef4_writed_page_locked(efx, value, \
282 reg + BUILD_BUG_ON_ZERO((reg) != 0x420), \
283 page)
284
285 #endif