xref: /xnu-8019.80.24/bsd/skywalk/channel/os_channel_event.h (revision a325d9c4a84054e40bbe985afedcb50ab80993ea)
1 /*
2  * Copyright (c) 2019 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #ifndef _SKYWALK_OS_CHANNEL_EVENT_H_
30 #define _SKYWALK_OS_CHANNEL_EVENT_H_
31 
32 #ifdef PRIVATE
33 #include <stdint.h>
34 #include <mach/vm_types.h>
35 
36 typedef enum {
37 	CHANNEL_EVENT_PACKET_TRANSMIT_STATUS = 1,
38 #if defined(LIBSYSCALL_INTERFACE) || defined(BSD_KERNEL_PRIVATE)
39 	CHANNEL_EVENT_MIN    = CHANNEL_EVENT_PACKET_TRANSMIT_STATUS,
40 	CHANNEL_EVENT_MAX    = CHANNEL_EVENT_PACKET_TRANSMIT_STATUS,
41 #endif /* LIBSYSCALL_INTERFACE || BSD_KERNEL_PRIVATE */
42 } os_channel_event_type_t;
43 
44 typedef enum {
45 	CHANNEL_EVENT_SUCCESS = 0,
46 	CHANNEL_EVENT_PKT_TRANSMIT_STATUS_ERR_FLUSH = 1,
47 	CHANNEL_EVENT_PKT_TRANSMIT_STATUS_ERR_RETRY_FAILED = 2,
48 } os_channel_event_error_t;
49 
50 typedef struct os_channel_event_packet_transmit_status {
51 	packet_id_t    packet_id;
52 	int32_t        packet_status;
53 } os_channel_event_packet_transmit_status_t;
54 
55 #ifndef KERNEL
56 /*
57  * opaque handles
58  */
59 typedef uint64_t             os_channel_event_handle_t;
60 typedef mach_vm_address_t    os_channel_event_t;
61 
62 struct os_channel_event_data {
63 	os_channel_event_type_t    event_type;
64 	boolean_t                  event_more;
65 	uint16_t                   event_data_length;
66 	uint8_t                    *event_data;
67 };
68 
69 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
70 extern int
71 os_channel_event_get_next_event(const os_channel_event_handle_t event_handle,
72     const os_channel_event_t prev_event, os_channel_event_t *event);
73 extern int os_channel_event_get_event_data(const os_channel_event_t, struct os_channel_event_data *);
74 #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
75 #endif /* KERNEL */
76 
77 #if defined(LIBSYSCALL_INTERFACE) || defined(BSD_KERNEL_PRIVATE)
78 /*
79  * The metadata object is placed at the front of every batch of events.
80  */
81 struct __kern_channel_event_metadata {
82 	os_channel_event_type_t    emd_etype;
83 	uint32_t                   emd_nevents;
84 };
85 #define __KERN_CHANNEL_EVENT_OFFSET    \
86     (sizeof(struct __kern_channel_event_metadata))
87 
88 struct __kern_channel_event {
89 	os_channel_event_type_t    ev_type;
90 	uint32_t                   ev_flags;
91 	uint16_t                   _reserved;
92 	uint16_t                   ev_dlen;
93 	uint8_t                    ev_data[];
94 };
95 
96 /* event_flags */
97 #define CHANNEL_EVENT_FLAG_MORE_EVENT    0x1
98 
99 /* convenience macro */
100 #define CHANNEL_EVENT_TX_STATUS_LEN    (sizeof(struct __kern_channel_event) + \
101     sizeof(os_channel_event_packet_transmit_status_t))
102 #endif /* LIBSYSCALL_INTERFACE || BSD_KERNEL_PRIVATE */
103 
104 #if defined(BSD_KERNEL_PRIVATE)
105 __BEGIN_DECLS
106 extern errno_t kern_channel_event_transmit_status(const kern_packet_t,
107     const ifnet_t);
108 extern void kern_channel_event_notify(struct __kern_channel_ring *);
109 extern int kern_channel_event_sync(struct __kern_channel_ring *, struct proc *,
110     uint32_t);
111 __END_DECLS
112 #endif /* BSD_KERNEL_PRIVATE */
113 
114 #endif /* PRIVATE */
115 #endif /* !_SKYWALK_OS_CHANNEL_EVENT_H_ */
116