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 static inline int netmem_ref_count(netmem_ref netmem) 42 { 43 return page_ref_count(netmem_to_page(netmem)); 44 } 45 46 static inline unsigned long netmem_to_pfn(netmem_ref netmem) 47 { 48 return page_to_pfn(netmem_to_page(netmem)); 49 } 50 51 static inline netmem_ref netmem_compound_head(netmem_ref netmem) 52 { 53 return page_to_netmem(compound_head(netmem_to_page(netmem))); 54 } 55 56 #endif /* _NET_NETMEM_H */ 57