| 1 | /* SPDX-License-Identifier: BSD-2-Clause */cxx . . $ `<file>/src/thread.h`/ |
| 2 | /* |
| 3 | * Copyright (C) 2020-2024 Linutronix GmbH |
| 4 | * Author Kurt Kanzenbach <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | #ifndef _THREAD_H_ |
| 8 | #define _THREAD_H_cxx . . $ `src/thread.h:8:9`! |
| 9 | |
| 10 | #include <pthread.h> |
| 11 | #include <stdbool.h> |
| 12 | #include <stddef.h> |
| 13 | #include <stdint.h> |
| 14 | |
| 15 | #include <sys/socket.h> |
| 16 | #include <sys/types.h> |
| 17 | |
| 18 | #include <linux/if_ether.h> |
| 19 | |
| 20 | #include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 21 | #include "xdp.h"cxx . . $ `<file>/src/xdp.h`/ |
| 22 | |
| 23 | #define MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`! XDP_FRAME_SIZEcxx . . $ `src/xdp.h:34:9`! |
| 24 | |
| 25 | static inline unsigned char *frame_idxcxx . . $ frame_idx(9d0786fb5198b4b4).(unsigned char *frame_data, int idx) |
| 26 | { |
| 27 | return frame_data + idx * MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!; |
| 28 | } |
| 29 | |
| 30 | struct ring_buffercxx . . $ ring_buffer#; |
| 31 | struct xdp_socketcxx . . $ xdp_socket#; |
| 32 | struct security_contextcxx . . $ security_context#; |
| 33 | struct packet_contextcxx . . $ packet_context#; |
| 34 | |
| 35 | struct thread_contextcxx . . $ thread_context# { |
| 36 | /* Task related */ |
| 37 | pthread_tcxx . . $ pthread_t# rx_task_idcxx . . $ thread_context#rx_task_id.; /* Receiver Thread */ |
| 38 | uint64_tcxx . . $ uint64_t# rx_sequence_countercxx . . $ thread_context#rx_sequence_counter.; /* Rx cycle counter */ |
| 39 | pthread_tcxx . . $ pthread_t# tx_task_idcxx . . $ thread_context#tx_task_id.; /* Sender Thread */ |
| 40 | pthread_tcxx . . $ pthread_t# tx_gen_task_idcxx . . $ thread_context#tx_gen_task_id.; /* Sender generation thread */ |
| 41 | volatile int stopcxx . . $ thread_context#stop.; /* Done? */ |
| 42 | |
| 43 | /* RAW socket related */ |
| 44 | int socket_fdcxx . . $ thread_context#socket_fd.; /* Shared RAW socket */ |
| 45 | unsigned char *tx_frame_datacxx . . $ thread_context#tx_frame_data.; /* Tx frame data */ |
| 46 | unsigned char *rx_frame_datacxx . . $ thread_context#rx_frame_data.; /* Rx frame data */ |
| 47 | unsigned char sourcecxx . . $ thread_context#source.[ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!]; /* Source MAC Address */ |
| 48 | struct sockaddr_storagecxx . . $ sockaddr_storage# destinationcxx . . $ thread_context#destination.; /* Where to send L3 frames to */ |
| 49 | struct ring_buffercxx . . $ ring_buffer# *mirror_buffercxx . . $ thread_context#mirror_buffer.; /* Rx frames to be mirrored */ |
| 50 | struct packet_contextcxx . . $ packet_context# *packet_contextcxx . . $ thread_context#packet_context.; /* Packet Tx/Rx context */ |
| 51 | |
| 52 | /* XDP socket related */ |
| 53 | struct xdp_socketcxx . . $ xdp_socket# *xskcxx . . $ thread_context#xsk.; /* XDP socket reference */ |
| 54 | unsigned int received_framescxx . . $ thread_context#received_frames.; /* Amount of frames received within cycle */ |
| 55 | pthread_mutex_tcxx . . $ pthread_mutex_t# xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.; /* Protect concurrent access to Xsk */ |
| 56 | |
| 57 | /* Data flow related */ |
| 58 | struct thread_contextcxx . . $ thread_context# *nextcxx . . $ thread_context#next.; /* Pointer to next traffic class */ |
| 59 | pthread_mutex_tcxx . . $ pthread_mutex_t# data_mutexcxx . . $ thread_context#data_mutex.; /* Mutex to protect frame data */ |
| 60 | pthread_cond_tcxx . . $ pthread_cond_t# data_cond_varcxx . . $ thread_context#data_cond_var.; /* Cond var to signal Tx thread */ |
| 61 | size_t num_frames_availablecxx . . $ thread_context#num_frames_available.; /* How many frames are ready to be sent? */ |
| 62 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_firstcxx . . $ thread_context#is_first.; /* Is this the first active traffic class? */ |
| 63 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_lastcxx . . $ thread_context#is_last.; /* Is this the last active traffic class? */ |
| 64 | |
| 65 | /* Security related */ |
| 66 | struct security_contextcxx . . $ security_context# *tx_security_contextcxx . . $ thread_context#tx_security_context.; /* Tx context for Auth and Crypt */ |
| 67 | struct security_contextcxx . . $ security_context# *rx_security_contextcxx . . $ thread_context#rx_security_context.; /* Rx context for Auth and Crypt */ |
| 68 | unsigned char *payload_patterncxx . . $ thread_context#payload_pattern.; /* Frame payload pattern used for AE */ |
| 69 | size_t payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length.; /* Length of payload pattern */ |
| 70 | |
| 71 | /* Traffic class related */ |
| 72 | struct traffic_class_configcxx . . $ traffic_class_config# *confcxx . . $ thread_context#conf.; /* Pointer to traffic class configuration */ |
| 73 | enum stat_frame_typecxx . . $ stat_frame_type# frame_typecxx . . $ thread_context#frame_type.; /* Frame type */ |
| 74 | const char *traffic_classcxx . . $ thread_context#traffic_class.; /* Traffic class string */ |
| 75 | uint32_tcxx . . $ uint32_t# meta_data_offsetcxx . . $ thread_context#meta_data_offset.; /* Where is the MetaData in the frame? */ |
| 76 | uint16_tcxx . . $ uint16_t# frame_idcxx . . $ thread_context#frame_id.; /* What's the Profinet frame id */ |
| 77 | int (*create_socketcxx . . $ thread_context#create_socket.)(void); /* Function to create socket */ |
| 78 | |
| 79 | /* Workload related */ |
| 80 | struct workload_configcxx . . $ workload_config# *workloadcxx . . $ thread_context#workload.; |
| 81 | }; |
| 82 | |
| 83 | enum pn_thread_typecxx . . $ pn_thread_type# { |
| 84 | TSN_HIGH_THREADcxx . . $ TSN_HIGH_THREAD. = 0, |
| 85 | TSN_LOW_THREADcxx . . $ TSN_LOW_THREAD., |
| 86 | RTC_THREADcxx . . $ RTC_THREAD., |
| 87 | RTA_THREADcxx . . $ RTA_THREAD., |
| 88 | DCP_THREADcxx . . $ DCP_THREAD., |
| 89 | LLDP_THREADcxx . . $ LLDP_THREAD., |
| 90 | UDP_HIGH_THREADcxx . . $ UDP_HIGH_THREAD., |
| 91 | UDP_LOW_THREADcxx . . $ UDP_LOW_THREAD., |
| 92 | NUM_PN_THREAD_TYPEScxx . . $ NUM_PN_THREAD_TYPES., |
| 93 | }; |
| 94 | |
| 95 | int create_rt_threadcxx . . $ create_rt_thread(670ec5a211ade64c).(pthread_tcxx . . $ pthread_t# *task_id, const char *thread_name, int priority, int cpu_core, |
| 96 | void *(*thread_routine)(void *), void *data); |
| 97 | void init_mutexcxx . . $ init_mutex(4f83bfebf4bb9c8b).(pthread_mutex_tcxx . . $ pthread_mutex_t# *mutex); |
| 98 | void init_condition_variablecxx . . $ init_condition_variable(23b56462c1e1452f).(pthread_cond_tcxx . . $ pthread_cond_t# *cond_var); |
| 99 | int link_pn_threadscxx . . $ link_pn_threads(8542e1c024f3ff56).(struct thread_contextcxx . . $ thread_context# *pn_threads); |
| 100 | |
| 101 | #endif /* _THREAD_H_ */ |