1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
8 #include <rte_prefetch.h>
9 #include <rte_mempool.h>
12 * This file defines common macros and structs
15 #define TIME_IN_RESET_COUNT 5
17 /* Default command timeout in seconds */
18 #define DEFAULT_COMMAND_TIMEOUT 4
20 #define CPT_COUNT_THOLD 32
21 #define CPT_TIMER_THOLD 0x3F
23 #define MOD_INC(i, l) ((i) == (l - 1) ? (i) = 0 : (i)++)
25 struct cpt_qp_meta_info {
26 struct rte_mempool *pool;
32 * Pending queue structure
35 struct pending_queue {
36 /** Array of pending requests */
38 /** Tail of queue to be used for enqueue */
40 /** Head of queue to be used for dequeue */
44 struct cpt_request_info {
45 /** Data path fields */
47 volatile uint64_t *completion_addr;
48 volatile uint64_t *alternate_caddr;
58 /** Control path fields */
63 static __rte_always_inline void
64 pending_queue_push(struct pending_queue *q, void *rid, unsigned int off,
67 /* NOTE: no free space check, but it is expected that one is made */
68 q->rid_queue[(q->tail + off) & (qsize - 1)] = rid;
71 static __rte_always_inline void
72 pending_queue_commit(struct pending_queue *q, unsigned int cnt,
73 const unsigned int qsize)
75 /* Ensure ordering between setting the entry and updating the tail */
76 rte_atomic_thread_fence(__ATOMIC_RELEASE);
78 q->tail = (q->tail + cnt) & (qsize - 1);
81 static __rte_always_inline void
82 pending_queue_pop(struct pending_queue *q, const int qsize)
84 /* NOTE: no empty check, but it is expected that one is made prior */
86 q->head = (q->head + 1) & (qsize - 1);
89 static __rte_always_inline void
90 pending_queue_peek(struct pending_queue *q, void **rid, const int qsize,
94 /* NOTE: no empty check, but it is expected that one is made */
96 *rid = q->rid_queue[q->head];
98 if (likely(prefetch_next)) {
99 next_rid = q->rid_queue[(q->head + 1) & (qsize - 1)];
100 rte_prefetch_non_temporal((void *)next_rid);
104 static __rte_always_inline unsigned int
105 pending_queue_level(struct pending_queue *q, const int qsize)
107 return (q->tail - q->head) & (qsize - 1);
110 static __rte_always_inline unsigned int
111 pending_queue_free_slots(struct pending_queue *q, const int qsize,
112 const int reserved_slots)
116 free_slots = qsize - pending_queue_level(q, qsize);
118 /* Use only use qsize - 1 */
119 free_slots -= 1 + reserved_slots;
121 if (unlikely(free_slots < 0))
127 #endif /* _CPT_COMMON_H_ */