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
48struct device;
49
50struct nfp_cpp_area;
51struct nfp_cpp;
52struct 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
113static 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
123static inline u8 NFP_CPP_ID_TOKEN_of(u32 id)
124{
125 return (id >> 16) & 0xff;
126}
127
128
129
130
131
132
133
134static inline u8 NFP_CPP_ID_ACTION_of(u32 id)
135{
136 return (id >> 8) & 0xff;
137}
138
139
140
141
142
143
144
145static 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
202void nfp_cpp_free(struct nfp_cpp *cpp);
203u32 nfp_cpp_model(struct nfp_cpp *cpp);
204u16 nfp_cpp_interface(struct nfp_cpp *cpp);
205int nfp_cpp_serial(struct nfp_cpp *cpp, const u8 **serial);
206unsigned int nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp);
207
208struct 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);
213struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, u32 cpp_id,
214 unsigned long long address,
215 unsigned long size);
216struct nfp_cpp_area *
217nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, const char *name, u32 cpp_id,
218 unsigned long long address, unsigned long size);
219void nfp_cpp_area_free(struct nfp_cpp_area *area);
220int nfp_cpp_area_acquire(struct nfp_cpp_area *area);
221int nfp_cpp_area_acquire_nonblocking(struct nfp_cpp_area *area);
222void nfp_cpp_area_release(struct nfp_cpp_area *area);
223void nfp_cpp_area_release_free(struct nfp_cpp_area *area);
224int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset,
225 void *buffer, size_t length);
226int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset,
227 const void *buffer, size_t length);
228size_t nfp_cpp_area_size(struct nfp_cpp_area *area);
229const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area);
230void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area);
231struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area);
232struct resource *nfp_cpp_area_resource(struct nfp_cpp_area *area);
233phys_addr_t nfp_cpp_area_phys(struct nfp_cpp_area *area);
234void __iomem *nfp_cpp_area_iomem(struct nfp_cpp_area *area);
235
236int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset,
237 u32 *value);
238int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset,
239 u32 value);
240int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset,
241 u64 *value);
242int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset,
243 u64 value);
244int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset,
245 u32 value, size_t length);
246
247int nfp_xpb_readl(struct nfp_cpp *cpp, u32 xpb_tgt, u32 *value);
248int nfp_xpb_writel(struct nfp_cpp *cpp, u32 xpb_tgt, u32 value);
249int nfp_xpb_writelm(struct nfp_cpp *cpp, u32 xpb_tgt, u32 mask, u32 value);
250
251
252int nfp_cpp_read(struct nfp_cpp *cpp, u32 cpp_id,
253 unsigned long long address, void *kernel_vaddr, size_t length);
254int nfp_cpp_write(struct nfp_cpp *cpp, u32 cpp_id,
255 unsigned long long address, const void *kernel_vaddr,
256 size_t length);
257int nfp_cpp_readl(struct nfp_cpp *cpp, u32 cpp_id,
258 unsigned long long address, u32 *value);
259int nfp_cpp_writel(struct nfp_cpp *cpp, u32 cpp_id,
260 unsigned long long address, u32 value);
261int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id,
262 unsigned long long address, u64 *value);
263int nfp_cpp_writeq(struct nfp_cpp *cpp, u32 cpp_id,
264 unsigned long long address, u64 value);
265
266u8 __iomem *
267nfp_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
270struct nfp_cpp_mutex;
271
272int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target,
273 unsigned long long address, u32 key_id);
274struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target,
275 unsigned long long address,
276 u32 key_id);
277void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex);
278int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex);
279int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex);
280int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex);
281int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target,
282 unsigned long long address);
283
284
285
286
287
288
289
290static inline u8 nfp_cppcore_pcie_unit(struct nfp_cpp *cpp)
291{
292 return NFP_CPP_INTERFACE_UNIT_of(nfp_cpp_interface(cpp));
293}
294
295struct nfp_cpp_explicit;
296
297struct 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
338struct 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
374struct nfp_cpp *
375nfp_cpp_from_operations(const struct nfp_cpp_operations *ops,
376 struct device *parent, void *priv);
377void *nfp_cpp_priv(struct nfp_cpp *priv);
378
379int 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
389struct 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
396enum 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
404struct nfp_cpp_explicit *nfp_cpp_explicit_acquire(struct nfp_cpp *cpp);
405int nfp_cpp_explicit_set_target(struct nfp_cpp_explicit *expl, u32 cpp_id,
406 u8 len, u8 mask);
407int nfp_cpp_explicit_set_data(struct nfp_cpp_explicit *expl,
408 u8 data_master, u16 data_ref);
409int nfp_cpp_explicit_set_signal(struct nfp_cpp_explicit *expl,
410 u8 signal_master, u8 signal_ref);
411int 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);
416int nfp_cpp_explicit_put(struct nfp_cpp_explicit *expl,
417 const void *buff, size_t len);
418int nfp_cpp_explicit_do(struct nfp_cpp_explicit *expl, u64 address);
419int nfp_cpp_explicit_get(struct nfp_cpp_explicit *expl, void *buff, size_t len);
420void nfp_cpp_explicit_release(struct nfp_cpp_explicit *expl);
421struct nfp_cpp *nfp_cpp_explicit_cpp(struct nfp_cpp_explicit *expl);
422void *nfp_cpp_explicit_priv(struct nfp_cpp_explicit *cpp_explicit);
423
424
425
426int nfp_cpp_model_autodetect(struct nfp_cpp *cpp, u32 *model);
427
428int nfp_cpp_explicit_read(struct nfp_cpp *cpp, u32 cpp_id,
429 u64 addr, void *buff, size_t len,
430 int width_read);
431
432int 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
437