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