xref: /dpdk/drivers/net/nfp/nfpcore/nfp_cpp.h (revision d80e42cce4c7017ed8c99dabb8ae444a492acc1c)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Netronome Systems, Inc.
3  * All rights reserved.
4  */
5 
6 #ifndef __NFP_CPP_H__
7 #define __NFP_CPP_H__
8 
9 #include "nfp-common/nfp_platform.h"
10 #include "nfp-common/nfp_resid.h"
11 
12 struct nfp_cpp_mutex;
13 
14 /*
15  * NFP CPP handle
16  */
17 struct nfp_cpp {
18 	uint32_t model;
19 	uint32_t interface;
20 	uint8_t *serial;
21 	int serial_len;
22 	void *priv;
23 
24 	/* Mutex cache */
25 	struct nfp_cpp_mutex *mutex_cache;
26 	const struct nfp_cpp_operations *op;
27 
28 	/*
29 	 * NFP-6xxx originating island IMB CPP Address Translation. CPP Target
30 	 * ID is index into array. Values are obtained at runtime from local
31 	 * island XPB CSRs.
32 	 */
33 	uint32_t imb_cat_table[16];
34 
35 	int driver_lock_needed;
36 };
37 
38 /*
39  * NFP CPP device area handle
40  */
41 struct nfp_cpp_area {
42 	struct nfp_cpp *cpp;
43 	char *name;
44 	unsigned long long offset;
45 	unsigned long size;
46 	/* Here follows the 'priv' part of nfp_cpp_area. */
47 };
48 
49 /*
50  * NFP CPP operations structure
51  */
52 struct nfp_cpp_operations {
53 	/* Size of priv area in struct nfp_cpp_area */
54 	size_t area_priv_size;
55 
56 	/* Instance an NFP CPP */
57 	int (*init)(struct nfp_cpp *cpp, const char *devname);
58 
59 	/*
60 	 * Free the bus.
61 	 * Called only once, during nfp_cpp_unregister()
62 	 */
63 	void (*free)(struct nfp_cpp *cpp);
64 
65 	/*
66 	 * Initialize a new NFP CPP area
67 	 * NOTE: This is _not_ serialized
68 	 */
69 	int (*area_init)(struct nfp_cpp_area *area,
70 			 uint32_t dest,
71 			 unsigned long long address,
72 			 unsigned long size);
73 	/*
74 	 * Clean up a NFP CPP area before it is freed
75 	 * NOTE: This is _not_ serialized
76 	 */
77 	void (*area_cleanup)(struct nfp_cpp_area *area);
78 
79 	/*
80 	 * Acquire resources for a NFP CPP area
81 	 * Serialized
82 	 */
83 	int (*area_acquire)(struct nfp_cpp_area *area);
84 	/*
85 	 * Release resources for a NFP CPP area
86 	 * Serialized
87 	 */
88 	void (*area_release)(struct nfp_cpp_area *area);
89 	/*
90 	 * Return a void IO pointer to a NFP CPP area
91 	 * NOTE: This is _not_ serialized
92 	 */
93 
94 	void *(*area_iomem)(struct nfp_cpp_area *area);
95 
96 	void *(*area_mapped)(struct nfp_cpp_area *area);
97 	/*
98 	 * Perform a read from a NFP CPP area
99 	 * Serialized
100 	 */
101 	int (*area_read)(struct nfp_cpp_area *area,
102 			 void *kernel_vaddr,
103 			 unsigned long offset,
104 			 unsigned int length);
105 	/*
106 	 * Perform a write to a NFP CPP area
107 	 * Serialized
108 	 */
109 	int (*area_write)(struct nfp_cpp_area *area,
110 			  const void *kernel_vaddr,
111 			  unsigned long offset,
112 			  unsigned int length);
113 };
114 
115 /*
116  * This should be the only external function the transport
117  * module supplies
118  */
119 const struct nfp_cpp_operations *nfp_cpp_transport_operations(void);
120 
121 /*
122  * Set the model id
123  *
124  * @param   cpp     NFP CPP operations structure
125  * @param   model   Model ID
126  */
127 void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model);
128 
129 /*
130  * Set the private instance owned data of a nfp_cpp struct
131  *
132  * @param   cpp     NFP CPP operations structure
133  * @param   interface Interface ID
134  */
135 void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface);
136 
137 /*
138  * Set the private instance owned data of a nfp_cpp struct
139  *
140  * @param   cpp     NFP CPP operations structure
141  * @param   serial  NFP serial byte array
142  * @param   len     Length of the serial byte array
143  */
144 int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial,
145 		       size_t serial_len);
146 
147 /*
148  * Set the private data of the nfp_cpp instance
149  *
150  * @param   cpp NFP CPP operations structure
151  * @return      Opaque device pointer
152  */
153 void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv);
154 
155 /*
156  * Return the private data of the nfp_cpp instance
157  *
158  * @param   cpp NFP CPP operations structure
159  * @return      Opaque device pointer
160  */
161 void *nfp_cpp_priv(struct nfp_cpp *cpp);
162 
163 /*
164  * Get the privately allocated portion of a NFP CPP area handle
165  *
166  * @param   cpp_area    NFP CPP area handle
167  * @return          Pointer to the private area, or NULL on failure
168  */
169 void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area);
170 
171 uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp);
172 
173 /*
174  * NFP CPP core interface for CPP clients.
175  */
176 
177 /*
178  * Open a NFP CPP handle to a CPP device
179  *
180  * @param[in]	id	0-based ID for the CPP interface to use
181  *
182  * @return NFP CPP handle, or NULL on failure (and set errno accordingly).
183  */
184 struct nfp_cpp *nfp_cpp_from_device_name(const char *devname,
185 					 int driver_lock_needed);
186 
187 /*
188  * Free a NFP CPP handle
189  *
190  * @param[in]	cpp	NFP CPP handle
191  */
192 void nfp_cpp_free(struct nfp_cpp *cpp);
193 
194 #define NFP_CPP_MODEL_INVALID   0xffffffff
195 
196 /*
197  * NFP_CPP_MODEL_CHIP_of - retrieve the chip ID from the model ID
198  *
199  * The chip ID is a 16-bit BCD+A-F encoding for the chip type.
200  *
201  * @param[in]   model   NFP CPP model id
202  * @return      NFP CPP chip id
203  */
204 #define NFP_CPP_MODEL_CHIP_of(model)        (((model) >> 16) & 0xffff)
205 
206 /*
207  * NFP_CPP_MODEL_IS_6000 - Check for the NFP6000 family of devices
208  *
209  * NOTE: The NFP4000 series is considered as a NFP6000 series variant.
210  *
211  * @param[in]	model	NFP CPP model id
212  * @return		true if model is in the NFP6000 family, false otherwise.
213  */
214 #define NFP_CPP_MODEL_IS_6000(model)		     \
215 		((NFP_CPP_MODEL_CHIP_of(model) >= 0x4000) && \
216 		(NFP_CPP_MODEL_CHIP_of(model) < 0x7000))
217 
218 /*
219  * nfp_cpp_model - Retrieve the Model ID of the NFP
220  *
221  * @param[in]	cpp	NFP CPP handle
222  * @return		NFP CPP Model ID
223  */
224 uint32_t nfp_cpp_model(struct nfp_cpp *cpp);
225 
226 /*
227  * NFP Interface types - logical interface for this CPP connection 4 bits are
228  * reserved for interface type.
229  */
230 #define NFP_CPP_INTERFACE_TYPE_INVALID		0x0
231 #define NFP_CPP_INTERFACE_TYPE_PCI		0x1
232 #define NFP_CPP_INTERFACE_TYPE_ARM		0x2
233 #define NFP_CPP_INTERFACE_TYPE_RPC		0x3
234 #define NFP_CPP_INTERFACE_TYPE_ILA		0x4
235 
236 /*
237  * Construct a 16-bit NFP Interface ID
238  *
239  * Interface IDs consists of 4 bits of interface type, 4 bits of unit
240  * identifier, and 8 bits of channel identifier.
241  *
242  * The NFP Interface ID is used in the implementation of NFP CPP API mutexes,
243  * which use the MU Atomic CompareAndWrite operation - hence the limit to 16
244  * bits to be able to use the NFP Interface ID as a lock owner.
245  *
246  * @param[in]	type	NFP Interface Type
247  * @param[in]	unit	Unit identifier for the interface type
248  * @param[in]	channel	Channel identifier for the interface unit
249  * @return		Interface ID
250  */
251 #define NFP_CPP_INTERFACE(type, unit, channel)	\
252 	((((type) & 0xf) << 12) | \
253 	 (((unit) & 0xf) <<  8) | \
254 	 (((channel) & 0xff) << 0))
255 
256 /*
257  * Get the interface type of a NFP Interface ID
258  * @param[in]	interface	NFP Interface ID
259  * @return			NFP Interface ID's type
260  */
261 #define NFP_CPP_INTERFACE_TYPE_of(interface)	(((interface) >> 12) & 0xf)
262 
263 /*
264  * Get the interface unit of a NFP Interface ID
265  * @param[in]	interface	NFP Interface ID
266  * @return			NFP Interface ID's unit
267  */
268 #define NFP_CPP_INTERFACE_UNIT_of(interface)	(((interface) >>  8) & 0xf)
269 
270 /*
271  * Get the interface channel of a NFP Interface ID
272  * @param[in]	interface	NFP Interface ID
273  * @return			NFP Interface ID's channel
274  */
275 #define NFP_CPP_INTERFACE_CHANNEL_of(interface)	(((interface) >>  0) & 0xff)
276 
277 /*
278  * Retrieve the Interface ID of the NFP
279  * @param[in]	cpp	NFP CPP handle
280  * @return		NFP CPP Interface ID
281  */
282 uint16_t nfp_cpp_interface(struct nfp_cpp *cpp);
283 
284 /*
285  * Retrieve the NFP Serial Number (unique per NFP)
286  * @param[in]	cpp	NFP CPP handle
287  * @param[out]	serial	Pointer to reference the serial number array
288  *
289  * @return	size of the NFP6000 serial number, in bytes
290  */
291 int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial);
292 
293 /*
294  * Allocate a NFP CPP area handle, as an offset into a CPP ID
295  * @param[in]	cpp	NFP CPP handle
296  * @param[in]	cpp_id	NFP CPP ID
297  * @param[in]	address	Offset into the NFP CPP ID address space
298  * @param[in]	size	Size of the area to reserve
299  *
300  * @return NFP CPP handle, or NULL on failure (and set errno accordingly).
301  */
302 struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id,
303 					unsigned long long address,
304 					unsigned long size);
305 
306 /*
307  * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner
308  * @param[in]	cpp	NFP CPP handle
309  * @param[in]	cpp_id	NFP CPP ID
310  * @param[in]	name	Name of owner of the area
311  * @param[in]	address	Offset into the NFP CPP ID address space
312  * @param[in]	size	Size of the area to reserve
313  *
314  * @return NFP CPP handle, or NULL on failure (and set errno accordingly).
315  */
316 struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp,
317 						  uint32_t cpp_id,
318 						  const char *name,
319 						  unsigned long long address,
320 						  unsigned long size);
321 
322 /*
323  * Free an allocated NFP CPP area handle
324  * @param[in]	area	NFP CPP area handle
325  */
326 void nfp_cpp_area_free(struct nfp_cpp_area *area);
327 
328 /*
329  * Acquire the resources needed to access the NFP CPP area handle
330  *
331  * @param[in]	area	NFP CPP area handle
332  *
333  * @return 0 on success, -1 on failure (and set errno accordingly).
334  */
335 int nfp_cpp_area_acquire(struct nfp_cpp_area *area);
336 
337 /*
338  * Release the resources needed to access the NFP CPP area handle
339  *
340  * @param[in]	area	NFP CPP area handle
341  */
342 void nfp_cpp_area_release(struct nfp_cpp_area *area);
343 
344 /*
345  * Allocate, then acquire the resources needed to access the NFP CPP area handle
346  * @param[in]	cpp	NFP CPP handle
347  * @param[in]	cpp_id	NFP CPP ID
348  * @param[in]	address	Offset into the NFP CPP ID address space
349  * @param[in]	size	Size of the area to reserve
350  *
351  * @return NFP CPP handle, or NULL on failure (and set errno accordingly).
352  */
353 struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp,
354 						uint32_t cpp_id,
355 						unsigned long long address,
356 						unsigned long size);
357 
358 /*
359  * Release the resources, then free the NFP CPP area handle
360  * @param[in]	area	NFP CPP area handle
361  */
362 void nfp_cpp_area_release_free(struct nfp_cpp_area *area);
363 
364 uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, int domain, int target,
365 			   uint64_t addr, unsigned long size,
366 			   struct nfp_cpp_area **area);
367 /*
368  * Return an IO pointer to the beginning of the NFP CPP area handle. The area
369  * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation.
370  *
371  * @param[in]	area	NFP CPP area handle
372  *
373  * @return Pointer to IO memory, or NULL on failure (and set errno accordingly).
374  */
375 void *nfp_cpp_area_mapped(struct nfp_cpp_area *area);
376 
377 /*
378  * Read from a NFP CPP area handle into a buffer. The area must be acquired with
379  * 'nfp_cpp_area_acquire()' before calling this operation.
380  *
381  * @param[in]	area	NFP CPP area handle
382  * @param[in]	offset	Offset into the area
383  * @param[in]	buffer	Location of buffer to receive the data
384  * @param[in]	length	Length of the data to read
385  *
386  * @return bytes read on success, -1 on failure (and set errno accordingly).
387  *
388  */
389 int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset,
390 		      void *buffer, size_t length);
391 
392 /*
393  * Write to a NFP CPP area handle from a buffer. The area must be acquired with
394  * 'nfp_cpp_area_acquire()' before calling this operation.
395  *
396  * @param[in]	area	NFP CPP area handle
397  * @param[in]	offset	Offset into the area
398  * @param[in]	buffer	Location of buffer that holds the data
399  * @param[in]	length	Length of the data to read
400  *
401  * @return bytes written on success, -1 on failure (and set errno accordingly).
402  */
403 int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset,
404 		       const void *buffer, size_t length);
405 
406 /*
407  * nfp_cpp_area_iomem() - get IOMEM region for CPP area
408  * @area:       CPP area handle
409  *
410  * Returns an iomem pointer for use with readl()/writel() style operations.
411  *
412  * NOTE: Area must have been locked down with an 'acquire'.
413  *
414  * Return: pointer to the area, or NULL
415  */
416 void *nfp_cpp_area_iomem(struct nfp_cpp_area *area);
417 
418 /*
419  * Verify that IO can be performed on an offset in an area
420  *
421  * @param[in]	area	NFP CPP area handle
422  * @param[in]	offset	Offset into the area
423  * @param[in]	size	Size of region to validate
424  *
425  * @return 0 on success, -1 on failure (and set errno accordingly).
426  */
427 int nfp_cpp_area_check_range(struct nfp_cpp_area *area,
428 			     unsigned long long offset, unsigned long size);
429 
430 /*
431  * Get the NFP CPP handle that is the parent of a NFP CPP area handle
432  *
433  * @param	cpp_area	NFP CPP area handle
434  * @return			NFP CPP handle
435  */
436 struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area);
437 
438 /*
439  * Get the name passed during allocation of the NFP CPP area handle
440  *
441  * @param	cpp_area	NFP CPP area handle
442  * @return			Pointer to the area's name
443  */
444 const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area);
445 
446 /*
447  * Read a block of data from a NFP CPP ID
448  *
449  * @param[in]	cpp	NFP CPP handle
450  * @param[in]	cpp_id	NFP CPP ID
451  * @param[in]	address	Offset into the NFP CPP ID address space
452  * @param[in]	kernel_vaddr	Buffer to copy read data to
453  * @param[in]	length	Size of the area to reserve
454  *
455  * @return bytes read on success, -1 on failure (and set errno accordingly).
456  */
457 int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id,
458 		 unsigned long long address, void *kernel_vaddr, size_t length);
459 
460 /*
461  * Write a block of data to a NFP CPP ID
462  *
463  * @param[in]	cpp	NFP CPP handle
464  * @param[in]	cpp_id	NFP CPP ID
465  * @param[in]	address	Offset into the NFP CPP ID address space
466  * @param[in]	kernel_vaddr	Buffer to copy write data from
467  * @param[in]	length	Size of the area to reserve
468  *
469  * @return bytes written on success, -1 on failure (and set errno accordingly).
470  */
471 int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id,
472 		  unsigned long long address, const void *kernel_vaddr,
473 		  size_t length);
474 
475 
476 
477 /*
478  * Fill a NFP CPP area handle and offset with a value
479  *
480  * @param[in]	area	NFP CPP area handle
481  * @param[in]	offset	Offset into the NFP CPP ID address space
482  * @param[in]	value	32-bit value to fill area with
483  * @param[in]	length	Size of the area to reserve
484  *
485  * @return bytes written on success, -1 on failure (and set errno accordingly).
486  */
487 int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset,
488 		      uint32_t value, size_t length);
489 
490 /*
491  * Read a single 32-bit value from a NFP CPP area handle
492  *
493  * @param area		NFP CPP area handle
494  * @param offset	offset into NFP CPP area handle
495  * @param value		output value
496  *
497  * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this
498  * operation.
499  *
500  * NOTE: offset must be 32-bit aligned.
501  *
502  * @return 0 on success, or -1 on error (and set errno accordingly).
503  */
504 int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset,
505 		       uint32_t *value);
506 
507 /*
508  * Write a single 32-bit value to a NFP CPP area handle
509  *
510  * @param area		NFP CPP area handle
511  * @param offset	offset into NFP CPP area handle
512  * @param value		value to write
513  *
514  * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this
515  * operation.
516  *
517  * NOTE: offset must be 32-bit aligned.
518  *
519  * @return 0 on success, or -1 on error (and set errno accordingly).
520  */
521 int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset,
522 			uint32_t value);
523 
524 /*
525  * Read a single 64-bit value from a NFP CPP area handle
526  *
527  * @param area		NFP CPP area handle
528  * @param offset	offset into NFP CPP area handle
529  * @param value		output value
530  *
531  * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this
532  * operation.
533  *
534  * NOTE: offset must be 64-bit aligned.
535  *
536  * @return 0 on success, or -1 on error (and set errno accordingly).
537  */
538 int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset,
539 		       uint64_t *value);
540 
541 /*
542  * Write a single 64-bit value to a NFP CPP area handle
543  *
544  * @param area		NFP CPP area handle
545  * @param offset	offset into NFP CPP area handle
546  * @param value		value to write
547  *
548  * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this
549  * operation.
550  *
551  * NOTE: offset must be 64-bit aligned.
552  *
553  * @return 0 on success, or -1 on error (and set errno accordingly).
554  */
555 int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset,
556 			uint64_t value);
557 
558 /*
559  * Write a single 32-bit value on the XPB bus
560  *
561  * @param cpp           NFP CPP device handle
562  * @param xpb_tgt	XPB target and address
563  * @param value         value to write
564  *
565  * @return 0 on success, or -1 on failure (and set errno accordingly).
566  */
567 int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value);
568 
569 /*
570  * Read a single 32-bit value from the XPB bus
571  *
572  * @param cpp           NFP CPP device handle
573  * @param xpb_tgt	XPB target and address
574  * @param value         output value
575  *
576  * @return 0 on success, or -1 on failure (and set errno accordingly).
577  */
578 int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value);
579 
580 /*
581  * Modify bits of a 32-bit value from the XPB bus
582  *
583  * @param cpp           NFP CPP device handle
584  * @param xpb_tgt       XPB target and address
585  * @param mask          mask of bits to alter
586  * @param value         value to modify
587  *
588  * @return 0 on success, or -1 on failure (and set errno accordingly).
589  */
590 int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask,
591 		    uint32_t value);
592 
593 /*
594  * Modify bits of a 32-bit value from the XPB bus
595  *
596  * @param cpp           NFP CPP device handle
597  * @param xpb_tgt       XPB target and address
598  * @param mask          mask of bits to alter
599  * @param value         value to monitor for
600  * @param timeout_us    maximum number of us to wait (-1 for forever)
601  *
602  * @return >= 0 on success, or -1 on failure (and set errno accordingly).
603  */
604 int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask,
605 		   uint32_t value, int timeout_us);
606 
607 /*
608  * Read a 32-bit word from a NFP CPP ID
609  *
610  * @param cpp           NFP CPP handle
611  * @param cpp_id        NFP CPP ID
612  * @param address       offset into the NFP CPP ID address space
613  * @param value         output value
614  *
615  * @return 0 on success, or -1 on failure (and set errno accordingly).
616  */
617 int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id,
618 		  unsigned long long address, uint32_t *value);
619 
620 /*
621  * Write a 32-bit value to a NFP CPP ID
622  *
623  * @param cpp           NFP CPP handle
624  * @param cpp_id        NFP CPP ID
625  * @param address       offset into the NFP CPP ID address space
626  * @param value         value to write
627  *
628  * @return 0 on success, or -1 on failure (and set errno accordingly).
629  *
630  */
631 int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id,
632 		   unsigned long long address, uint32_t value);
633 
634 /*
635  * Read a 64-bit work from a NFP CPP ID
636  *
637  * @param cpp           NFP CPP handle
638  * @param cpp_id        NFP CPP ID
639  * @param address       offset into the NFP CPP ID address space
640  * @param value         output value
641  *
642  * @return 0 on success, or -1 on failure (and set errno accordingly).
643  */
644 int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id,
645 		  unsigned long long address, uint64_t *value);
646 
647 /*
648  * Write a 64-bit value to a NFP CPP ID
649  *
650  * @param cpp           NFP CPP handle
651  * @param cpp_id        NFP CPP ID
652  * @param address       offset into the NFP CPP ID address space
653  * @param value         value to write
654  *
655  * @return 0 on success, or -1 on failure (and set errno accordingly).
656  */
657 int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id,
658 		   unsigned long long address, uint64_t value);
659 
660 /*
661  * Initialize a mutex location
662 
663  * The CPP target:address must point to a 64-bit aligned location, and will
664  * initialize 64 bits of data at the location.
665  *
666  * This creates the initial mutex state, as locked by this nfp_cpp_interface().
667  *
668  * This function should only be called when setting up the initial lock state
669  * upon boot-up of the system.
670  *
671  * @param cpp		NFP CPP handle
672  * @param target	NFP CPP target ID
673  * @param address	Offset into the address space of the NFP CPP target ID
674  * @param key_id	Unique 32-bit value for this mutex
675  *
676  * @return 0 on success, or -1 on failure (and set errno accordingly).
677  */
678 int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target,
679 		       unsigned long long address, uint32_t key_id);
680 
681 /*
682  * Create a mutex handle from an address controlled by a MU Atomic engine
683  *
684  * The CPP target:address must point to a 64-bit aligned location, and reserve
685  * 64 bits of data at the location for use by the handle.
686  *
687  * Only target/address pairs that point to entities that support the MU Atomic
688  * Engine's CmpAndSwap32 command are supported.
689  *
690  * @param cpp		NFP CPP handle
691  * @param target	NFP CPP target ID
692  * @param address	Offset into the address space of the NFP CPP target ID
693  * @param key_id	32-bit unique key (must match the key at this location)
694  *
695  * @return		A non-NULL struct nfp_cpp_mutex * on success, NULL on
696  *                      failure.
697  */
698 struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target,
699 					  unsigned long long address,
700 					  uint32_t key_id);
701 
702 /*
703  * Get the NFP CPP handle the mutex was created with
704  *
705  * @param   mutex   NFP mutex handle
706  * @return          NFP CPP handle
707  */
708 struct nfp_cpp *nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex);
709 
710 /*
711  * Get the mutex key
712  *
713  * @param   mutex   NFP mutex handle
714  * @return          Mutex key
715  */
716 uint32_t nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex);
717 
718 /*
719  * Get the mutex owner
720  *
721  * @param   mutex   NFP mutex handle
722  * @return          Interface ID of the mutex owner
723  *
724  * NOTE: This is for debug purposes ONLY - the owner may change at any time,
725  * unless it has been locked by this NFP CPP handle.
726  */
727 uint16_t nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex);
728 
729 /*
730  * Get the mutex target
731  *
732  * @param   mutex   NFP mutex handle
733  * @return          Mutex CPP target (ie NFP_CPP_TARGET_MU)
734  */
735 int nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex);
736 
737 /*
738  * Get the mutex address
739  *
740  * @param   mutex   NFP mutex handle
741  * @return          Mutex CPP address
742  */
743 uint64_t nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex);
744 
745 /*
746  * Free a mutex handle - does not alter the lock state
747  *
748  * @param mutex		NFP CPP Mutex handle
749  */
750 void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex);
751 
752 /*
753  * Lock a mutex handle, using the NFP MU Atomic Engine
754  *
755  * @param mutex		NFP CPP Mutex handle
756  *
757  * @return 0 on success, or -1 on failure (and set errno accordingly).
758  */
759 int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex);
760 
761 /*
762  * Unlock a mutex handle, using the NFP MU Atomic Engine
763  *
764  * @param mutex		NFP CPP Mutex handle
765  *
766  * @return 0 on success, or -1 on failure (and set errno accordingly).
767  */
768 int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex);
769 
770 /*
771  * Attempt to lock a mutex handle, using the NFP MU Atomic Engine
772  *
773  * @param mutex		NFP CPP Mutex handle
774  * @return		0 if the lock succeeded, -1 on failure (and errno set
775  *			appropriately).
776  */
777 int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex);
778 
779 #endif /* !__NFP_CPP_H__ */
780