This source file includes following definitions.
- NFP_CPP_ID_TARGET_of
- NFP_CPP_ID_TOKEN_of
- NFP_CPP_ID_ACTION_of
- NFP_CPP_ID_ISLAND_of
- nfp_cppcore_pcie_unit
1
2
3
4
5
6
7
8
9
10 #ifndef __NFP_CPP_H__
11 #define __NFP_CPP_H__
12
13 #include <linux/ctype.h>
14 #include <linux/types.h>
15 #include <linux/sizes.h>
16
17 #ifndef NFP_SUBSYS
18 #define NFP_SUBSYS "nfp"
19 #endif
20
21 #define nfp_err(cpp, fmt, args...) \
22 dev_err(nfp_cpp_device(cpp)->parent, NFP_SUBSYS ": " fmt, ## args)
23 #define nfp_warn(cpp, fmt, args...) \
24 dev_warn(nfp_cpp_device(cpp)->parent, NFP_SUBSYS ": " fmt, ## args)
25 #define nfp_info(cpp, fmt, args...) \
26 dev_info(nfp_cpp_device(cpp)->parent, NFP_SUBSYS ": " fmt, ## args)
27 #define nfp_dbg(cpp, fmt, args...) \
28 dev_dbg(nfp_cpp_device(cpp)->parent, NFP_SUBSYS ": " fmt, ## args)
29 #define nfp_printk(level, cpp, fmt, args...) \
30 dev_printk(level, nfp_cpp_device(cpp)->parent, \
31 NFP_SUBSYS ": " fmt, ## args)
32
33 #define PCI_64BIT_BAR_COUNT 3
34
35
36
37 #define PCI_DEVICE_ID_NETRONOME_NFP3800 0x3800
38
39 #define NFP_CPP_NUM_TARGETS 16
40
41 #define NFP_CPP_SAFE_AREA_SIZE SZ_2M
42
43
44 #define NFP_MUTEX_WAIT_FIRST_WARN 15
45 #define NFP_MUTEX_WAIT_NEXT_WARN 5
46 #define NFP_MUTEX_WAIT_ERROR 60
47
48 struct device;
49
50 struct nfp_cpp_area;
51 struct nfp_cpp;
52 struct resource;
53
54
55
56
57
58
59
60
61
62
63 #define NFP_CPP_ACTION_RW 32
64
65 #define NFP_CPP_TARGET_ID_MASK 0x1f
66
67 #define NFP_CPP_ATOMIC_RD(target, island) \
68 NFP_CPP_ISLAND_ID((target), 3, 0, (island))
69 #define NFP_CPP_ATOMIC_WR(target, island) \
70 NFP_CPP_ISLAND_ID((target), 4, 0, (island))
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 #define NFP_CPP_ID(target, action, token) \
86 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
87 (((action) & 0xff) << 8))
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 #define NFP_CPP_ISLAND_ID(target, action, token, island) \
104 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
105 (((action) & 0xff) << 8) | (((island) & 0xff) << 0))
106
107
108
109
110
111
112
113 static inline u8 NFP_CPP_ID_TARGET_of(u32 id)
114 {
115 return (id >> 24) & NFP_CPP_TARGET_ID_MASK;
116 }
117
118
119
120
121
122
123 static inline u8 NFP_CPP_ID_TOKEN_of(u32 id)
124 {
125 return (id >> 16) & 0xff;
126 }
127
128
129
130
131
132
133
134 static inline u8 NFP_CPP_ID_ACTION_of(u32 id)
135 {
136 return (id >> 8) & 0xff;
137 }
138
139
140
141
142
143
144
145 static inline u8 NFP_CPP_ID_ISLAND_of(u32 id)
146 {
147 return (id >> 0) & 0xff;
148 }
149
150
151
152
153 #define NFP_CPP_INTERFACE_TYPE_INVALID 0x0
154 #define NFP_CPP_INTERFACE_TYPE_PCI 0x1
155 #define NFP_CPP_INTERFACE_TYPE_ARM 0x2
156 #define NFP_CPP_INTERFACE_TYPE_RPC 0x3
157 #define NFP_CPP_INTERFACE_TYPE_ILA 0x4
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175 #define NFP_CPP_INTERFACE(type, unit, channel) \
176 ((((type) & 0xf) << 12) | \
177 (((unit) & 0xf) << 8) | \
178 (((channel) & 0xff) << 0))
179
180
181
182
183
184
185 #define NFP_CPP_INTERFACE_TYPE_of(interface) (((interface) >> 12) & 0xf)
186
187
188
189
190
191
192 #define NFP_CPP_INTERFACE_UNIT_of(interface) (((interface) >> 8) & 0xf)
193
194
195
196
197
198
199 #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff)
200
201
202 void nfp_cpp_free(struct nfp_cpp *cpp);
203 u32 nfp_cpp_model(struct nfp_cpp *cpp);
204 u16 nfp_cpp_interface(struct nfp_cpp *cpp);
205 int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial);
206 unsigned int nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp);
207
208 struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp,
209 u32 cpp_id,
210 const char *name,
211 unsigned long long address,
212 unsigned long size);
213 struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, u32 cpp_id,
214 unsigned long long address,
215 unsigned long size);
216 struct nfp_cpp_area *
217 nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, const char *name, u32 cpp_id,
218 unsigned long long address, unsigned long size);
219 void nfp_cpp_area_free(struct nfp_cpp_area *area);
220 int nfp_cpp_area_acquire(struct nfp_cpp_area *area);
221 int nfp_cpp_area_acquire_nonblocking(struct nfp_cpp_area *area);
222 void nfp_cpp_area_release(struct nfp_cpp_area *area);
223 void nfp_cpp_area_release_free(struct nfp_cpp_area *area);
224 int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset,
225 void *buffer, size_t length);
226 int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset,
227 const void *buffer, size_t length);
228 size_t nfp_cpp_area_size(struct nfp_cpp_area *area);
229 const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area);
230 void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area);
231 struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area);
232 struct resource *nfp_cpp_area_resource(struct nfp_cpp_area *area);
233 phys_addr_t nfp_cpp_area_phys(struct nfp_cpp_area *area);
234 void __iomem *nfp_cpp_area_iomem(struct nfp_cpp_area *area);
235
236 int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset,
237 u32 *value);
238 int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset,
239 u32 value);
240 int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset,
241 u64 *value);
242 int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset,
243 u64 value);
244 int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset,
245 u32 value, size_t length);
246
247 int nfp_xpb_readl(struct nfp_cpp *cpp, u32 xpb_tgt, u32 *value);
248 int nfp_xpb_writel(struct nfp_cpp *cpp, u32 xpb_tgt, u32 value);
249 int nfp_xpb_writelm(struct nfp_cpp *cpp, u32 xpb_tgt, u32 mask, u32 value);
250
251
252 int nfp_cpp_read(struct nfp_cpp *cpp, u32 cpp_id,
253 unsigned long long address, void *kernel_vaddr, size_t length);
254 int nfp_cpp_write(struct nfp_cpp *cpp, u32 cpp_id,
255 unsigned long long address, const void *kernel_vaddr,
256 size_t length);
257 int nfp_cpp_readl(struct nfp_cpp *cpp, u32 cpp_id,
258 unsigned long long address, u32 *value);
259 int nfp_cpp_writel(struct nfp_cpp *cpp, u32 cpp_id,
260 unsigned long long address, u32 value);
261 int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id,
262 unsigned long long address, u64 *value);
263 int nfp_cpp_writeq(struct nfp_cpp *cpp, u32 cpp_id,
264 unsigned long long address, u64 value);
265
266 u8 __iomem *
267 nfp_cpp_map_area(struct nfp_cpp *cpp, const char *name, u32 cpp_id, u64 addr,
268 unsigned long size, struct nfp_cpp_area **area);
269
270 struct nfp_cpp_mutex;
271
272 int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target,
273 unsigned long long address, u32 key_id);
274 struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target,
275 unsigned long long address,
276 u32 key_id);
277 void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex);
278 int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex);
279 int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex);
280 int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex);
281 int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target,
282 unsigned long long address);
283
284
285
286
287
288
289
290 static inline u8 nfp_cppcore_pcie_unit(struct nfp_cpp *cpp)
291 {
292 return NFP_CPP_INTERFACE_UNIT_of(nfp_cpp_interface(cpp));
293 }
294
295 struct nfp_cpp_explicit;
296
297 struct nfp_cpp_explicit_command {
298 u32 cpp_id;
299 u16 data_ref;
300 u8 data_master;
301 u8 len;
302 u8 byte_mask;
303 u8 signal_master;
304 u8 signal_ref;
305 u8 posted;
306 u8 siga;
307 u8 sigb;
308 s8 siga_mode;
309 s8 sigb_mode;
310 };
311
312 #define NFP_SERIAL_LEN 6
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338 struct nfp_cpp_operations {
339 size_t area_priv_size;
340 struct module *owner;
341
342 int (*init)(struct nfp_cpp *cpp);
343 void (*free)(struct nfp_cpp *cpp);
344
345 int (*read_serial)(struct device *dev, u8 *serial);
346 int (*get_interface)(struct device *dev);
347
348 int (*area_init)(struct nfp_cpp_area *area,
349 u32 dest, unsigned long long address,
350 unsigned long size);
351 void (*area_cleanup)(struct nfp_cpp_area *area);
352 int (*area_acquire)(struct nfp_cpp_area *area);
353 void (*area_release)(struct nfp_cpp_area *area);
354 struct resource *(*area_resource)(struct nfp_cpp_area *area);
355 phys_addr_t (*area_phys)(struct nfp_cpp_area *area);
356 void __iomem *(*area_iomem)(struct nfp_cpp_area *area);
357 int (*area_read)(struct nfp_cpp_area *area, void *kernel_vaddr,
358 unsigned long offset, unsigned int length);
359 int (*area_write)(struct nfp_cpp_area *area, const void *kernel_vaddr,
360 unsigned long offset, unsigned int length);
361
362 size_t explicit_priv_size;
363 int (*explicit_acquire)(struct nfp_cpp_explicit *expl);
364 void (*explicit_release)(struct nfp_cpp_explicit *expl);
365 int (*explicit_put)(struct nfp_cpp_explicit *expl,
366 const void *buff, size_t len);
367 int (*explicit_get)(struct nfp_cpp_explicit *expl,
368 void *buff, size_t len);
369 int (*explicit_do)(struct nfp_cpp_explicit *expl,
370 const struct nfp_cpp_explicit_command *cmd,
371 u64 address);
372 };
373
374 struct nfp_cpp *
375 nfp_cpp_from_operations(const struct nfp_cpp_operations *ops,
376 struct device *parent, void *priv);
377 void *nfp_cpp_priv(struct nfp_cpp *priv);
378
379 int nfp_cpp_area_cache_add(struct nfp_cpp *cpp, size_t size);
380
381
382
383
384
385
386
387
388 #define NFP_CPP_INTERFACE_CHANNEL_PEROPENER 255
389 struct device *nfp_cpp_device(struct nfp_cpp *cpp);
390
391
392
393 #define NFP_SIGNAL_MASK_A BIT(0)
394 #define NFP_SIGNAL_MASK_B BIT(1)
395
396 enum nfp_cpp_explicit_signal_mode {
397 NFP_SIGNAL_NONE = 0,
398 NFP_SIGNAL_PUSH = 1,
399 NFP_SIGNAL_PUSH_OPTIONAL = -1,
400 NFP_SIGNAL_PULL = 2,
401 NFP_SIGNAL_PULL_OPTIONAL = -2,
402 };
403
404 struct nfp_cpp_explicit *nfp_cpp_explicit_acquire(struct nfp_cpp *cpp);
405 int nfp_cpp_explicit_set_target(struct nfp_cpp_explicit *expl, u32 cpp_id,
406 u8 len, u8 mask);
407 int nfp_cpp_explicit_set_data(struct nfp_cpp_explicit *expl,
408 u8 data_master, u16 data_ref);
409 int nfp_cpp_explicit_set_signal(struct nfp_cpp_explicit *expl,
410 u8 signal_master, u8 signal_ref);
411 int nfp_cpp_explicit_set_posted(struct nfp_cpp_explicit *expl, int posted,
412 u8 siga,
413 enum nfp_cpp_explicit_signal_mode siga_mode,
414 u8 sigb,
415 enum nfp_cpp_explicit_signal_mode sigb_mode);
416 int nfp_cpp_explicit_put(struct nfp_cpp_explicit *expl,
417 const void *buff, size_t len);
418 int nfp_cpp_explicit_do(struct nfp_cpp_explicit *expl, u64 address);
419 int nfp_cpp_explicit_get(struct nfp_cpp_explicit *expl, void *buff, size_t len);
420 void nfp_cpp_explicit_release(struct nfp_cpp_explicit *expl);
421 struct nfp_cpp *nfp_cpp_explicit_cpp(struct nfp_cpp_explicit *expl);
422 void *nfp_cpp_explicit_priv(struct nfp_cpp_explicit *cpp_explicit);
423
424
425
426 int nfp_cpp_model_autodetect(struct nfp_cpp *cpp, u32 *model);
427
428 int nfp_cpp_explicit_read(struct nfp_cpp *cpp, u32 cpp_id,
429 u64 addr, void *buff, size_t len,
430 int width_read);
431
432 int nfp_cpp_explicit_write(struct nfp_cpp *cpp, u32 cpp_id,
433 u64 addr, const void *buff, size_t len,
434 int width_write);
435
436 #endif