xref: /linux/drivers/infiniband/hw/efa/efa_ah_cache.h (revision 21bd0802cd3f58b656065f1be236694c40588c3a)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
2 /*
3  * Copyright 2026 Amazon.com, Inc. or its affiliates. All rights reserved.
4  */
5 
6 #ifndef _EFA_AH_CACHE_H_
7 #define _EFA_AH_CACHE_H_
8 
9 #include <linux/refcount.h>
10 #include <linux/rhashtable.h>
11 
12 #define EFA_AH_GID_SIZE 16
13 
14 struct efa_ah_cache_key {
15 	u8 gid[EFA_AH_GID_SIZE];
16 	u16 pd;
17 };
18 
19 struct efa_ah_cache_entry {
20 	struct efa_ah_cache_key key;
21 	u16 ah;
22 	unsigned int usecnt;
23 	refcount_t refcount;
24 	struct rhash_head linkage;
25 	struct mutex lock; /* Serializes device commands per cache entry */
26 };
27 
28 struct efa_ah_cache {
29 	struct rhashtable hashtable;
30 	struct mutex lock; /* Protects AH cache hashtable */
31 };
32 
33 int efa_ah_cache_init(struct efa_ah_cache *ah_cache);
34 void efa_ah_cache_destroy(struct efa_ah_cache *ah_cache);
35 struct efa_ah_cache_entry *efa_ah_cache_get(struct efa_ah_cache *ah_cache, u16 pd, u8 *gid);
36 struct efa_ah_cache_entry *efa_ah_cache_lookup(struct efa_ah_cache *ah_cache, u16 pd, u8 *gid);
37 void efa_ah_cache_put(struct efa_ah_cache *ah_cache, struct efa_ah_cache_entry *entry);
38 
39 #endif /* _EFA_AH_CACHE_H_ */
40