xref: /freebsd/sys/netinet/tcp_stacks/tailq_hash.h (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 #ifndef __tailq_hash__
2 #define __tailq_hash__
3 
4 /* Must be powers of 2 */
5 #define MAX_HASH_ENTRIES 128
6 #define SEQ_BUCKET_SIZE 262144
7 /*
8  * The max seq range that can be stored is
9  * 64 x 262144 or 16Meg. We have one extra slot
10  * for fall-over but must keep it so we never have
11  * wrap in hashing over valid other entries.
12  */
13 #define MAX_ALLOWED_SEQ_RANGE (SEQ_BUCKET_SIZE * (MAX_HASH_ENTRIES-1))
14 
15 struct tailq_hash {
16 	struct rack_head ht[MAX_HASH_ENTRIES];
17 	uint32_t min;
18 	uint32_t max;
19 	uint32_t count;
20 };
21 
22 struct rack_sendmap *
23 tqhash_min(struct tailq_hash *hs);
24 
25 struct rack_sendmap *
26 tqhash_max(struct tailq_hash *hs);
27 
28 int
29 tqhash_empty(struct tailq_hash *hs);
30 
31 struct rack_sendmap *
32 tqhash_find(struct tailq_hash *hs, uint32_t seq);
33 
34 struct rack_sendmap *
35 tqhash_next(struct tailq_hash *hs, struct rack_sendmap *rsm);
36 
37 struct rack_sendmap *
38 tqhash_prev(struct tailq_hash *hs, struct rack_sendmap *rsm);
39 
40 #define REMOVE_TYPE_CUMACK	1	/* Cumack moved */
41 #define REMOVE_TYPE_MERGE	2	/* Merging two blocks */
42 #define REMOVE_TYPE_FINI	3	/* The connection is over */
43 
44 void
45 tqhash_remove(struct tailq_hash *hs, struct rack_sendmap *rsm, int type);
46 
47 int
48 tqhash_insert(struct tailq_hash *hs, struct rack_sendmap *rsm);
49 
50 void
51 tqhash_init(struct tailq_hash *hs);
52 
53 int
54 tqhash_trim(struct tailq_hash *hs, uint32_t th_ack);
55 
56 
57 #define	TQHASH_FOREACH(var, head) \
58 	for ((var) = tqhash_min((head));		\
59 	     (var);					\
60 	     (var) = tqhash_next((head), (var)))
61 
62 #define TQHASH_FOREACH_FROM(var, head, fvar)					\
63 	for ((var) = ((fvar) ? (fvar) : tqhash_min((head)));		\
64 	    (var);							\
65 	     (var) = tqhash_next((head), (var)))
66 
67 #define	TQHASH_FOREACH_REVERSE_FROM(var, head)		\
68 	for ((var) = ((var) ? (var) : tqhash_max((head)));		\
69 	    (var);							\
70 	    (var) = tqhash_prev((head), (var)))
71 
72 
73 #endif
74