xref: /illumos-gate/usr/src/uts/common/io/qede/qede_list.h (revision 14b24e2b79293068c8e016a69ef1d872fb5e2fd5)
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, v.1,  (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 
22 /*
23 * Copyright 2014-2017 Cavium, Inc.
24 * The contents of this file are subject to the terms of the Common Development
25 * and Distribution License, v.1,  (the "License").
26 
27 * You may not use this file except in compliance with the License.
28 
29 * You can obtain a copy of the License at available
30 * at http://opensource.org/licenses/CDDL-1.0
31 
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 */
35 
36 #ifndef _QEDE_LIST_H
37 #define _QEDE_LIST_H
38 
39 typedef struct qede_list_s {
40 	struct qede_list_s *next;
41 	struct qede_list_s *prev;
42 }qede_list_t;
43 
44 typedef struct qede_mem_list_entry {
45 	void *buf;
46 	size_t			size;
47 	qede_list_t	 	mem_entry;
48 } qede_mem_list_entry_t;
49 
50 typedef struct qede_mem_list {
51 	qede_list_t	 	mem_list_head;
52 	kmutex_t		mem_list_lock;
53 } qede_mem_list_t;
54 
55 typedef	struct phys_mem_entry {
56 	qede_list_t 		list_entry;
57 	ddi_dma_handle_t 	dma_handle;
58 	ddi_acc_handle_t 	dma_acc_handle;
59 	size_t 			size;
60 	void *virt_addr;
61 	void *paddr;
62 } qede_phys_mem_entry_t;
63 
64 typedef struct qede_phys_mem_list {
65 	qede_list_t		head;
66 	kmutex_t		lock;
67 } qede_phys_mem_list_t;
68 
69 typedef struct qede_mcast_list_entry {
70 	qede_list_t       mclist_entry;
71 	u8 *mac;
72 } qede_mcast_list_entry_t;
73 
74 typedef struct qede_mcast_list {
75 	qede_list_t       head;
76 } qede_mcast_list_t;
77 
78 typedef qede_list_t osal_list_t;
79 typedef qede_list_t osal_list_entry_t;
80 
81 /*
82  * Linked list helpers
83  */
84 static inline void
QEDE_INIT_LIST_HEAD(qede_list_t * list)85 QEDE_INIT_LIST_HEAD(qede_list_t *list)
86 {
87 	list->next = list;
88 	list->prev = list;
89 }
90 
91 #define	OSAL_LIST_INIT(_list_) QEDE_INIT_LIST_HEAD(_list_)
92 
93 static inline void
qede_list_add(qede_list_t * new,qede_list_t * prev,qede_list_t * next)94 qede_list_add(qede_list_t *new,
95     qede_list_t *prev,
96     qede_list_t *next)
97 {
98 	next->prev = new;
99 	new->next = next;
100 	new->prev = prev;
101 	prev->next = new;
102 }
103 
104 static inline bool
qede_list_empty(qede_list_t * entry)105 qede_list_empty(qede_list_t *entry)
106 {
107 	return (entry->next == entry);
108 }
109 
110 static inline void
qede_list_del(qede_list_t * prev,qede_list_t * next)111 qede_list_del(qede_list_t *prev, qede_list_t *next)
112 {
113 	next->prev = prev;
114 	prev->next = next;
115 }
116 
117 static inline void
QEDE_LIST_ADD(qede_list_t * new,qede_list_t * head)118 QEDE_LIST_ADD(qede_list_t *new, qede_list_t *head)
119 {
120 	qede_list_add(new, head, head->next);
121 }
122 
123 static inline void
QEDE_LIST_ADD_TAIL(qede_list_t * new,qede_list_t * head)124 QEDE_LIST_ADD_TAIL(qede_list_t *new, qede_list_t *head)
125 {
126 	qede_list_add(new, head->prev, head);
127 }
128 
129 static inline void
QEDE_LIST_REMOVE(qede_list_t * entry,qede_list_t * head)130 QEDE_LIST_REMOVE(qede_list_t *entry, qede_list_t *head)
131 {
132 	qede_list_del(entry->prev, entry->next);
133 }
134 
135 static inline void
list_splice(const qede_list_t * list,qede_list_t * prev,qede_list_t * next)136 list_splice(const qede_list_t *list,
137     qede_list_t *prev,
138     qede_list_t *next)
139 {
140 	qede_list_t *first = list->next;
141 	qede_list_t *last = list->prev;
142 
143 	first->prev = prev;
144 	prev->next = first;
145 
146 	last->next = next;
147 	next->prev = last;
148 }
149 
150 static inline void
qede_list_splice(qede_list_t * list,qede_list_t * head)151 qede_list_splice(qede_list_t *list,
152     qede_list_t *head)
153 {
154 	if (!qede_list_empty(list)) {
155 		list_splice(list, head, head->next);
156 	}
157 }
158 
159 static inline void
qede_list_splice_tail(qede_list_t * list,qede_list_t * head)160 qede_list_splice_tail(qede_list_t *list,
161     qede_list_t *head)
162 {
163 	if (!qede_list_empty(list)) {
164 		list_splice(list, head->prev, head);
165 	}
166 }
167 
168 #define	QEDE_LIST_IS_EMPTY		qede_list_empty
169 #define	QEDE_LIST_SPLICE		qede_list_splice
170 #define	QEDE_LIST_SPLICE_TAIL		qede_list_splice_tail
171 #define	QEDE_LIST_ENTRY			qede_list_entry
172 #define QEDE_LIST_FIRST_ENTRY		OSAL_LIST_FIRST_ENTRY
173 #define	QEDE_LIST_EMPTY			OSAL_LIST_IS_EMPTY
174 #define	QEDE_LIST_FOR_EACH_ENTRY(_entry_, _list_, _type_, _member_) \
175 	OSAL_LIST_FOR_EACH_ENTRY(_entry_, _list_, _member_, _type_)
176 #define	QEDE_LIST_FOR_EACH_ENTRY_SAFE	OSAL_LIST_FOR_EACH_ENTRY_SAFE
177 
178 #endif  /* !_QEDE_LIST_H */
179 
180