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 /* net_iov */ 12 13 struct net_iov { 14 struct dmabuf_genpool_chunk_owner *owner; 15 }; 16 17 /* netmem */ 18 19 /** 20 * typedef netmem_ref - a nonexistent type marking a reference to generic 21 * network memory. 22 * 23 * A netmem_ref currently is always a reference to a struct page. This 24 * abstraction is introduced so support for new memory types can be added. 25 * 26 * Use the supplied helpers to obtain the underlying memory pointer and fields. 27 */ 28 typedef unsigned long __bitwise netmem_ref; 29 30 /* This conversion fails (returns NULL) if the netmem_ref is not struct page 31 * backed. 32 * 33 * Currently struct page is the only possible netmem, and this helper never 34 * fails. 35 */ 36 static inline struct page *netmem_to_page(netmem_ref netmem) 37 { 38 return (__force struct page *)netmem; 39 } 40 41 /* Converting from page to netmem is always safe, because a page can always be 42 * a netmem. 43 */ 44 static inline netmem_ref page_to_netmem(struct page *page) 45 { 46 return (__force netmem_ref)page; 47 } 48 49 static inline int netmem_ref_count(netmem_ref netmem) 50 { 51 return page_ref_count(netmem_to_page(netmem)); 52 } 53 54 static inline unsigned long netmem_to_pfn(netmem_ref netmem) 55 { 56 return page_to_pfn(netmem_to_page(netmem)); 57 } 58 59 static inline netmem_ref netmem_compound_head(netmem_ref netmem) 60 { 61 return page_to_netmem(compound_head(netmem_to_page(netmem))); 62 } 63 64 #endif /* _NET_NETMEM_H */ 65