1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Component                                                        */
16 /**                                                                       */
17 /**   Packet Pool Management (Packet)                                     */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  COMPONENT DEFINITION                                   RELEASE        */
26 /*                                                                        */
27 /*    nx_packet.h                                         PORTABLE C      */
28 /*                                                           6.4.0        */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    Yuxin Zhou, Microsoft Corporation                                   */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file defines the NetX packet memory management component,      */
36 /*    including all data types and external references.  It is assumed    */
37 /*    that nx_api.h and nx_port.h have already been included.             */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
44 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
45 /*                                            resulting in version 6.1    */
46 /*  10-15-2021     Yuxin Zhou               Modified comment(s), included */
47 /*                                            necessary header file,      */
48 /*                                            resulting in version 6.1.9  */
49 /*  12-31-2023     Yajun Xia                Modified comment(s),          */
50 /*                                            supported VLAN,             */
51 /*                                            resulting in version 6.4.0  */
52 /*                                                                        */
53 /**************************************************************************/
54 
55 #ifndef NX_PAC_H
56 #define NX_PAC_H
57 
58 #include "nx_api.h"
59 
60 
61 #define NX_PACKET_POOL_ID           ((ULONG)0x5041434B)
62 
63 
64 /* Define constants for packet free, allocated, enqueued, and driver transmit done.
65    These will be used in the nx_packet_tcp_queue_next field to indicate the state of
66    the packet.  */
67 
68 #define NX_PACKET_FREE              ((ALIGN_TYPE)0xFFFFFFFF) /* Packet is available and in the pool  */
69 #define NX_PACKET_ALLOCATED         ((ALIGN_TYPE)0xAAAAAAAA) /* Packet has been allocated            */
70 #define NX_PACKET_ENQUEUED          ((ALIGN_TYPE)0xEEEEEEEE) /* Packet is the tail of TCP queue.     */
71                                                              /* A value that is none of the above    */
72                                                              /*   also indicates the packet is in a  */
73                                                              /*   TCP queue                          */
74 
75 /* Define the constant for driver done and receive packet is available. These will be
76    used in the nx_packet_queue_next field to indicate the state of a TCP packet.  */
77 
78 #define NX_DRIVER_TX_DONE           ((ALIGN_TYPE)0xDDDDDDDD) /* Driver has sent the TCP packet       */
79 #define NX_PACKET_READY             ((ALIGN_TYPE)0xBBBBBBBB) /* Packet is ready for retrieval        */
80 
81 
82 #ifdef NX_ENABLE_PACKET_DEBUG_INFO
83 /* Define strings for packet debug information. */
84 #define NX_PACKET_ARP_WAITING_QUEUE "ARP waiting queue"
85 #define NX_PACKET_ND_WAITING_QUEUE  "ND waiting queue"
86 #define NX_PACKET_TCP_LISTEN_QUEUE  "TCP listen queue"
87 #define NX_PACKET_TCP_RECEIVE_QUEUE "TCP receive queue"
88 #define NX_PACKET_UDP_RECEIVE_QUEUE "UDP receive queue"
89 #define NX_PACKET_IP_FRAGMENT_QUEUE "IP fragment queue"
90 #endif /* NX_ENABLE_PACKET_DEBUG_INFO */
91 
92 
93 /* Define packet pool management function prototypes.  */
94 
95 UINT _nx_packet_allocate(NX_PACKET_POOL *pool_ptr,  NX_PACKET **packet_ptr,
96                          ULONG packet_type, ULONG wait_option);
97 UINT _nx_packet_copy(NX_PACKET *packet_ptr, NX_PACKET **new_packet_ptr,
98                      NX_PACKET_POOL *pool_ptr, ULONG wait_option);
99 UINT _nx_packet_data_append(NX_PACKET *packet_ptr, VOID *data_start, ULONG data_size,
100                             NX_PACKET_POOL *pool_ptr, ULONG wait_option);
101 UINT _nx_packet_data_extract_offset(NX_PACKET *packet_ptr, ULONG offset, VOID *buffer_start, ULONG buffer_length, ULONG *bytes_copied);
102 UINT _nx_packet_data_retrieve(NX_PACKET *packet_ptr, VOID *buffer_start, ULONG *bytes_copied);
103 UINT _nx_packet_data_adjust(NX_PACKET *packet_ptr, ULONG header_size);
104 #ifdef NX_ENABLE_PACKET_DEBUG_INFO
105 UINT _nx_packet_debug_info_get(NX_PACKET_POOL *pool_ptr, UINT packet_index, NX_PACKET **packet_pptr,
106                                ULONG *packet_status, CHAR **thread_info, CHAR **file_info, ULONG *line);
107 #endif /* NX_ENABLE_PACKET_DEBUG_INFO */
108 UINT _nx_packet_length_get(NX_PACKET *packet_ptr, ULONG *length);
109 UINT _nx_packet_pool_create(NX_PACKET_POOL *pool_ptr, CHAR *name, ULONG payload_size,
110                             VOID *memory_ptr, ULONG memory_size);
111 UINT _nx_packet_pool_delete(NX_PACKET_POOL *pool_ptr);
112 UINT _nx_packet_pool_info_get(NX_PACKET_POOL *pool_ptr, ULONG *total_packets, ULONG *free_packets,
113                               ULONG *empty_pool_requests, ULONG *empty_pool_suspensions,
114                               ULONG *invalid_packet_releases);
115 UINT _nx_packet_release(NX_PACKET *packet_ptr);
116 UINT _nx_packet_transmit_release(NX_PACKET *packet_ptr);
117 VOID _nx_packet_pool_cleanup(TX_THREAD *thread_ptr NX_CLEANUP_PARAMETER);
118 VOID _nx_packet_pool_initialize(VOID);
119 UINT _nx_packet_pool_low_watermark_set(NX_PACKET_POOL *pool_ptr, ULONG low_watermark);
120 
121 UINT _nx_packet_vlan_priority_set(NX_PACKET *packet_ptr, UINT vlan_priority);
122 
123 /* Define error checking shells for API services.  These are only referenced by the
124    application.  */
125 
126 UINT _nxe_packet_allocate(NX_PACKET_POOL *pool_ptr,  NX_PACKET **packet_ptr,
127                           ULONG packet_type, ULONG wait_option);
128 UINT _nxe_packet_copy(NX_PACKET *packet_ptr, NX_PACKET **new_packet_ptr,
129                       NX_PACKET_POOL *pool_ptr, ULONG wait_option);
130 UINT _nxe_packet_data_append(NX_PACKET *packet_ptr, VOID *data_start, ULONG data_size,
131                              NX_PACKET_POOL *pool_ptr, ULONG wait_option);
132 UINT _nxe_packet_data_extract_offset(NX_PACKET *packet_ptr, ULONG offset, VOID *buffer_start, ULONG buffer_length, ULONG *bytes_copied);
133 UINT _nxe_packet_data_retrieve(NX_PACKET *packet_ptr, VOID *buffer_start, ULONG *bytes_copied);
134 UINT _nxe_packet_length_get(NX_PACKET *packet_ptr, ULONG *length);
135 UINT _nxe_packet_pool_create(NX_PACKET_POOL *pool_ptr, CHAR *name, ULONG payload_size,
136                              VOID *memory_ptr, ULONG memory_size, UINT pool_control_block_size);
137 UINT _nxe_packet_pool_delete(NX_PACKET_POOL *pool_ptr);
138 UINT _nxe_packet_pool_info_get(NX_PACKET_POOL *pool_ptr, ULONG *total_packets, ULONG *free_packets,
139                                ULONG *empty_pool_requests, ULONG *empty_pool_suspensions,
140                                ULONG *invalid_packet_releases);
141 UINT _nxe_packet_release(NX_PACKET **packet_ptr_ptr);
142 UINT _nxe_packet_transmit_release(NX_PACKET **packet_ptr_ptr);
143 UINT _nxe_packet_pool_low_watermark_set(NX_PACKET_POOL *pool_ptr, ULONG low_watermark);
144 
145 UINT _nxe_packet_vlan_priority_set(NX_PACKET *packet_ptr, UINT vlan_priority);
146 
147 /* Packet pool management component data declarations follow.  */
148 
149 /* Determine if the initialization function of this component is including
150    this file.  If so, make the data definitions really happen.  Otherwise,
151    make them extern so other functions in the component can access them.  */
152 
153 /*lint -e767 suppress different definitions.  */
154 #ifdef NX_PACKET_POOL_INIT
155 #define PACKET_POOL_DECLARE
156 #else
157 #define PACKET_POOL_DECLARE extern
158 #endif
159 /*lint +e767 enable checking for different definitions.  */
160 
161 
162 /* Define the head pointer of the created packet pool list.  */
163 
164 PACKET_POOL_DECLARE  NX_PACKET_POOL     *_nx_packet_pool_created_ptr;
165 
166 
167 /* Define the variable that holds the number of created packet pools.  */
168 
169 PACKET_POOL_DECLARE  ULONG _nx_packet_pool_created_count;
170 
171 
172 #endif
173 
174