1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4 
5 #ifndef _OTX2_EP_ENQDEQ_H_
6 #define _OTX2_EP_ENQDEQ_H_
7 
8 #include <rte_byteorder.h>
9 #include "otx2_ep_rawdev.h"
10 
11 #define SDP_IQ_SEND_FAILED      (-1)
12 #define SDP_IQ_SEND_SUCCESS     (0)
13 
14 #define SDP_OQ_RECV_FAILED      (-1)
15 #define SDP_OQ_RECV_SUCCESS     (0)
16 
17 static inline uint64_t
sdp_endian_swap_8B(uint64_t _d)18 sdp_endian_swap_8B(uint64_t _d)
19 {
20 	return ((((((uint64_t)(_d)) >>  0) & (uint64_t)0xff) << 56) |
21 		(((((uint64_t)(_d)) >>  8) & (uint64_t)0xff) << 48) |
22 		(((((uint64_t)(_d)) >> 16) & (uint64_t)0xff) << 40) |
23 		(((((uint64_t)(_d)) >> 24) & (uint64_t)0xff) << 32) |
24 		(((((uint64_t)(_d)) >> 32) & (uint64_t)0xff) << 24) |
25 		(((((uint64_t)(_d)) >> 40) & (uint64_t)0xff) << 16) |
26 		(((((uint64_t)(_d)) >> 48) & (uint64_t)0xff) <<  8) |
27 		(((((uint64_t)(_d)) >> 56) & (uint64_t)0xff) <<  0));
28 }
29 
30 static inline void
sdp_swap_8B_data(uint64_t * data,uint32_t blocks)31 sdp_swap_8B_data(uint64_t *data, uint32_t blocks)
32 {
33 	/* Swap 8B blocks */
34 	while (blocks) {
35 		*data = sdp_endian_swap_8B(*data);
36 		blocks--;
37 		data++;
38 	}
39 }
40 
41 static inline uint32_t
sdp_incr_index(uint32_t index,uint32_t count,uint32_t max)42 sdp_incr_index(uint32_t index, uint32_t count, uint32_t max)
43 {
44 	if ((index + count) >= max)
45 		index = index + count - max;
46 	else
47 		index += count;
48 
49 	return index;
50 }
51 
52 #endif /* _OTX2_EP_ENQDEQ_H_ */
53