Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * ibumad BPF sample kernel side
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * modify it under the terms of version 2 of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * License as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Copyright(c) 2018 Ira Weiny, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define KBUILD_MODNAME "ibumad_count_pkts_by_class"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <uapi/linux/bpf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <bpf/bpf_helpers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct bpf_map_def SEC("maps") read_count = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	.type        = BPF_MAP_TYPE_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	.key_size    = sizeof(u32), /* class; u32 required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	.value_size  = sizeof(u64), /* count of mads read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	.max_entries = 256, /* Room for all Classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) struct bpf_map_def SEC("maps") write_count = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	.type        = BPF_MAP_TYPE_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	.key_size    = sizeof(u32), /* class; u32 required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.value_size  = sizeof(u64), /* count of mads written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.max_entries = 256, /* Room for all Classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #ifndef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #undef bpf_printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define bpf_printk(fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /* Taken from the current format defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * include/trace/events/ib_umad.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * /sys/kernel/debug/tracing/events/ib_umad/ib_umad_read/format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * /sys/kernel/debug/tracing/events/ib_umad/ib_umad_write/format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) struct ib_umad_rw_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u64 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u8 port_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u8 sl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u8 path_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u8 grh_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u32 timeout_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u32 retires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u32 qpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u32 qkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u8 gid_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u8 hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u16 lid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u16 attr_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u16 pkey_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u8 base_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u8 mgmt_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u8 class_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	u8 method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u32 flow_label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u16 mad_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u16 class_specific;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	u32 attr_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u64 tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u8 gid[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	u32 dev_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u8 traffic_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) SEC("tracepoint/ib_umad/ib_umad_read_recv")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) int on_ib_umad_read_recv(struct ib_umad_rw_args *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u64 zero = 0, *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	u8 class = ctx->mgmt_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	bpf_printk("ib_umad read recv : class 0x%x\n", class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	val = bpf_map_lookup_elem(&read_count, &class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		bpf_map_update_elem(&read_count, &class, &zero, BPF_NOEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		val = bpf_map_lookup_elem(&read_count, &class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	(*val) += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) SEC("tracepoint/ib_umad/ib_umad_read_send")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) int on_ib_umad_read_send(struct ib_umad_rw_args *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	u64 zero = 0, *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	u8 class = ctx->mgmt_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	bpf_printk("ib_umad read send : class 0x%x\n", class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	val = bpf_map_lookup_elem(&read_count, &class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (!val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		bpf_map_update_elem(&read_count, &class, &zero, BPF_NOEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		val = bpf_map_lookup_elem(&read_count, &class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	(*val) += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) SEC("tracepoint/ib_umad/ib_umad_write")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int on_ib_umad_write(struct ib_umad_rw_args *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	u64 zero = 0, *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	u8 class = ctx->mgmt_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	bpf_printk("ib_umad write : class 0x%x\n", class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	val = bpf_map_lookup_elem(&write_count, &class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		bpf_map_update_elem(&write_count, &class, &zero, BPF_NOEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		val = bpf_map_lookup_elem(&write_count, &class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	(*val) += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) char _license[] SEC("license") = "GPL";