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 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_ip.h"
29 #include "nx_packet.h"
30
31 #ifdef FEATURE_NX_IPV6
32 #include "nx_ipv6.h"
33 #endif
34
35
36 /**************************************************************************/
37 /* */
38 /* FUNCTION RELEASE */
39 /* */
40 /* _nx_packet_transmit_release PORTABLE C */
41 /* 6.1 */
42 /* AUTHOR */
43 /* */
44 /* Yuxin Zhou, Microsoft Corporation */
45 /* */
46 /* DESCRIPTION */
47 /* */
48 /* This function releases a transmitted packet chain back to the */
49 /* appropriate packet pool. If the packet is a TCP packet, it is */
50 /* simply marked as completed. The actual release is deferred to */
51 /* the TCP component. */
52 /* */
53 /* INPUT */
54 /* */
55 /* packet_ptr Pointer of packet to release */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* status Completion status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _nx_packet_release Release packet back to pool */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application Code */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
74 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* */
77 /**************************************************************************/
_nx_packet_transmit_release(NX_PACKET * packet_ptr)78 UINT _nx_packet_transmit_release(NX_PACKET *packet_ptr)
79 {
80
81 TX_INTERRUPT_SAVE_AREA
82
83 UINT status;
84
85
86 /* If trace is enabled, insert this event into the trace buffer. */
87 NX_TRACE_IN_LINE_INSERT(NX_TRACE_PACKET_TRANSMIT_RELEASE, packet_ptr, packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next, (packet_ptr -> nx_packet_pool_owner) -> nx_packet_pool_available, 0, NX_TRACE_PACKET_EVENTS, 0, 0);
88
89 /* Disable interrupts temporarily. */
90 TX_DISABLE
91
92 /* Add debug information. */
93 NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
94
95 /* Determine if the packet is a queued TCP data packet. Such packets cannot be released
96 immediately, since they may need to be resent. */
97 /*lint -e{923} suppress cast of ULONG to pointer. */
98 if ((packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_ALLOCATED)) &&
99 (packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_FREE)))
100 {
101
102 /* Yes, this is indeed a TCP packet. Just mark this with the NX_DRIVER_TX_DONE
103 value to let the TCP layer know it is no longer queued up. */
104 /*lint -e{923} suppress cast of ULONG to pointer. */
105 packet_ptr -> nx_packet_queue_next = (NX_PACKET *)NX_DRIVER_TX_DONE;
106
107 /* Remove the IP header and adjust the length. */
108 packet_ptr -> nx_packet_prepend_ptr += packet_ptr -> nx_packet_ip_header_length;
109 packet_ptr -> nx_packet_length -= packet_ptr -> nx_packet_ip_header_length;
110
111 /* Reset the IP header length. */
112 packet_ptr -> nx_packet_ip_header_length = 0;
113
114 /* Restore interrupts. */
115 TX_RESTORE
116
117 /* Return success. */
118 status = NX_SUCCESS;
119 }
120 else
121 {
122
123 /* Restore interrupts. */
124 TX_RESTORE
125
126 /* Call the actual packet release function. */
127 status = _nx_packet_release(packet_ptr);
128 }
129
130 /* Return completion status. */
131 return(status);
132 }
133
134