1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef __NETMEM_PRIV_H 4 #define __NETMEM_PRIV_H 5 netmem_get_pp_magic(netmem_ref netmem)6static inline unsigned long netmem_get_pp_magic(netmem_ref netmem) 7 { 8 return __netmem_clear_lsb(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; 9 } 10 netmem_or_pp_magic(netmem_ref netmem,unsigned long pp_magic)11static inline void netmem_or_pp_magic(netmem_ref netmem, unsigned long pp_magic) 12 { 13 __netmem_clear_lsb(netmem)->pp_magic |= pp_magic; 14 } 15 netmem_clear_pp_magic(netmem_ref netmem)16static inline void netmem_clear_pp_magic(netmem_ref netmem) 17 { 18 WARN_ON_ONCE(__netmem_clear_lsb(netmem)->pp_magic & PP_DMA_INDEX_MASK); 19 20 __netmem_clear_lsb(netmem)->pp_magic = 0; 21 } 22 netmem_is_pp(netmem_ref netmem)23static inline bool netmem_is_pp(netmem_ref netmem) 24 { 25 return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; 26 } 27 netmem_set_pp(netmem_ref netmem,struct page_pool * pool)28static inline void netmem_set_pp(netmem_ref netmem, struct page_pool *pool) 29 { 30 __netmem_clear_lsb(netmem)->pp = pool; 31 } 32 netmem_set_dma_addr(netmem_ref netmem,unsigned long dma_addr)33static inline void netmem_set_dma_addr(netmem_ref netmem, 34 unsigned long dma_addr) 35 { 36 __netmem_clear_lsb(netmem)->dma_addr = dma_addr; 37 } 38 netmem_get_dma_index(netmem_ref netmem)39static inline unsigned long netmem_get_dma_index(netmem_ref netmem) 40 { 41 unsigned long magic; 42 43 if (WARN_ON_ONCE(netmem_is_net_iov(netmem))) 44 return 0; 45 46 magic = __netmem_clear_lsb(netmem)->pp_magic; 47 48 return (magic & PP_DMA_INDEX_MASK) >> PP_DMA_INDEX_SHIFT; 49 } 50 netmem_set_dma_index(netmem_ref netmem,unsigned long id)51static inline void netmem_set_dma_index(netmem_ref netmem, 52 unsigned long id) 53 { 54 unsigned long magic; 55 56 if (WARN_ON_ONCE(netmem_is_net_iov(netmem))) 57 return; 58 59 magic = netmem_get_pp_magic(netmem) | (id << PP_DMA_INDEX_SHIFT); 60 __netmem_clear_lsb(netmem)->pp_magic = magic; 61 } 62 #endif 63