1371e4fccSRoman Gushchin // SPDX-License-Identifier: GPL-2.0 2371e4fccSRoman Gushchin #ifndef __NETCNT_COMMON_H 3371e4fccSRoman Gushchin #define __NETCNT_COMMON_H 4371e4fccSRoman Gushchin 5371e4fccSRoman Gushchin #include <linux/types.h> 6371e4fccSRoman Gushchin 7371e4fccSRoman Gushchin #define MAX_PERCPU_PACKETS 32 8371e4fccSRoman Gushchin 933b57e0cSStanislav Fomichev /* sizeof(struct bpf_local_storage_elem): 1033b57e0cSStanislav Fomichev * 11*80a61190SIlya Leoshkevich * It is about 128 bytes on x86_64 and 512 bytes on s390x, but allocate more to 12*80a61190SIlya Leoshkevich * account for possible layout changes, different architectures, etc. 1333b57e0cSStanislav Fomichev * The kernel will wrap up to PAGE_SIZE internally anyway. 1433b57e0cSStanislav Fomichev */ 15*80a61190SIlya Leoshkevich #define SIZEOF_BPF_LOCAL_STORAGE_ELEM 768 1633b57e0cSStanislav Fomichev 1733b57e0cSStanislav Fomichev /* Try to estimate kernel's BPF_LOCAL_STORAGE_MAX_VALUE_SIZE: */ 1833b57e0cSStanislav Fomichev #define BPF_LOCAL_STORAGE_MAX_VALUE_SIZE (0xFFFF - \ 1933b57e0cSStanislav Fomichev SIZEOF_BPF_LOCAL_STORAGE_ELEM) 2033b57e0cSStanislav Fomichev 2133b57e0cSStanislav Fomichev #define PCPU_MIN_UNIT_SIZE 32768 2233b57e0cSStanislav Fomichev 2333b57e0cSStanislav Fomichev union percpu_net_cnt { 2433b57e0cSStanislav Fomichev struct { 25371e4fccSRoman Gushchin __u64 packets; 26371e4fccSRoman Gushchin __u64 bytes; 27371e4fccSRoman Gushchin 28371e4fccSRoman Gushchin __u64 prev_ts; 29371e4fccSRoman Gushchin 30371e4fccSRoman Gushchin __u64 prev_packets; 31371e4fccSRoman Gushchin __u64 prev_bytes; 32371e4fccSRoman Gushchin }; 3333b57e0cSStanislav Fomichev __u8 data[PCPU_MIN_UNIT_SIZE]; 3433b57e0cSStanislav Fomichev }; 35371e4fccSRoman Gushchin 3633b57e0cSStanislav Fomichev union net_cnt { 3733b57e0cSStanislav Fomichev struct { 38371e4fccSRoman Gushchin __u64 packets; 39371e4fccSRoman Gushchin __u64 bytes; 40371e4fccSRoman Gushchin }; 4133b57e0cSStanislav Fomichev __u8 data[BPF_LOCAL_STORAGE_MAX_VALUE_SIZE]; 4233b57e0cSStanislav Fomichev }; 43371e4fccSRoman Gushchin 44371e4fccSRoman Gushchin #endif 45