xref: /linux/include/net/netmem.h (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  *	Network memory
4  *
5  *	Author:	Mina Almasry <almasrymina@google.com>
6  */
7 
8 #ifndef _NET_NETMEM_H
9 #define _NET_NETMEM_H
10 
11 /**
12  * typedef netmem_ref - a nonexistent type marking a reference to generic
13  * network memory.
14  *
15  * A netmem_ref currently is always a reference to a struct page. This
16  * abstraction is introduced so support for new memory types can be added.
17  *
18  * Use the supplied helpers to obtain the underlying memory pointer and fields.
19  */
20 typedef unsigned long __bitwise netmem_ref;
21 
22 /* This conversion fails (returns NULL) if the netmem_ref is not struct page
23  * backed.
24  *
25  * Currently struct page is the only possible netmem, and this helper never
26  * fails.
27  */
28 static inline struct page *netmem_to_page(netmem_ref netmem)
29 {
30 	return (__force struct page *)netmem;
31 }
32 
33 /* Converting from page to netmem is always safe, because a page can always be
34  * a netmem.
35  */
36 static inline netmem_ref page_to_netmem(struct page *page)
37 {
38 	return (__force netmem_ref)page;
39 }
40 
41 #endif /* _NET_NETMEM_H */
42