xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8189fs/os_dep/linux/rtw_rhashtable.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 
16 #include <drv_types.h>
17 
18 #if defined(CONFIG_RTW_WDS) || defined(CONFIG_RTW_MESH) /* for now, only promised for kernel versions we support mesh */
19 
rtw_rhashtable_walk_enter(rtw_rhashtable * ht,rtw_rhashtable_iter * iter)20 int rtw_rhashtable_walk_enter(rtw_rhashtable *ht, rtw_rhashtable_iter *iter)
21 {
22 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
23 	rhashtable_walk_enter((ht), (iter));
24 	return 0;
25 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
26 	return rhashtable_walk_init((ht), (iter), GFP_ATOMIC);
27 #else
28 	/* kernel >= 4.4.0 rhashtable_walk_init use GFP_KERNEL to alloc, spin_lock for assignment */
29 	iter->ht = ht;
30 	iter->p = NULL;
31 	iter->slot = 0;
32 	iter->skip = 0;
33 
34 	iter->walker = kmalloc(sizeof(*iter->walker), GFP_ATOMIC);
35 	if (!iter->walker)
36 		return -ENOMEM;
37 
38 	spin_lock(&ht->lock);
39 	iter->walker->tbl =
40 		rcu_dereference_protected(ht->tbl, lockdep_is_held(&ht->lock));
41 	list_add(&iter->walker->list, &iter->walker->tbl->walkers);
42 	spin_unlock(&ht->lock);
43 
44 	return 0;
45 #endif
46 }
47 
48 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
49 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0))
50 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
is_vmalloc_addr(const void * x)51 static inline int is_vmalloc_addr(const void *x)
52 {
53 #ifdef CONFIG_MMU
54 	unsigned long addr = (unsigned long)x;
55 
56 	return addr >= VMALLOC_START && addr < VMALLOC_END;
57 #else
58 	return 0;
59 #endif
60 }
61 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)) */
62 
kvfree(const void * addr)63 void kvfree(const void *addr)
64 {
65 	if (is_vmalloc_addr(addr))
66 		vfree(addr);
67 	else
68 		kfree(addr);
69 }
70 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)) */
71 
72 #include "rhashtable.c"
73 
74 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)) */
75 
76 #endif /* defined(CONFIG_RTW_WDS) || defined(CONFIG_RTW_MESH) */
77 
78