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_packet.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_packet_pool_info_get                            PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function retrieves information about the specified packet      */
44 /*    pool.                                                               */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    pool_ptr                              Pool to get information from  */
49 /*    total_packets                         Destination for total packets */
50 /*    free_packets                          Destination for free packets  */
51 /*    empty_pool_requests                   Destination for empty requests*/
52 /*    empty_pool_suspensions                Destination for empty         */
53 /*                                            suspensions                 */
54 /*    invalid_packet_releases               Destination for invalid packet*/
55 /*                                            release requests            */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    status                                Completion status             */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    None                                                                */
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_pool_info_get(NX_PACKET_POOL * pool_ptr,ULONG * total_packets,ULONG * free_packets,ULONG * empty_pool_requests,ULONG * empty_pool_suspensions,ULONG * invalid_packet_releases)78 UINT  _nx_packet_pool_info_get(NX_PACKET_POOL *pool_ptr, ULONG *total_packets, ULONG *free_packets,
79                                ULONG *empty_pool_requests, ULONG *empty_pool_suspensions,
80                                ULONG *invalid_packet_releases)
81 {
82 TX_INTERRUPT_SAVE_AREA
83 
84 
85     /* Disable interrupts to get packet pool information.  */
86     TX_DISABLE
87 
88     /* Determine if pool total packets is wanted.  */
89     if (total_packets)
90     {
91 
92         /* Return the number of total packets in this pool.  */
93         *total_packets =  pool_ptr -> nx_packet_pool_total;
94     }
95 
96     /* Determine if pool free packets is wanted.  */
97     if (free_packets)
98     {
99 
100         /* Return the number of free packets in this pool.  */
101         *free_packets =  pool_ptr -> nx_packet_pool_available;
102     }
103 
104     /* Determine if empty pool requests is wanted.  */
105     if (empty_pool_requests)
106     {
107 
108         /* Return the number of empty pool requests made in this pool.  */
109         *empty_pool_requests =  pool_ptr -> nx_packet_pool_empty_requests;
110     }
111 
112     /* Determine if empty pool suspensions is wanted.  */
113     if (empty_pool_suspensions)
114     {
115 
116         /* Return the number of empty pool suspensions made in this pool.  */
117         *empty_pool_suspensions =  pool_ptr -> nx_packet_pool_empty_suspensions;
118     }
119 
120     /* Determine if invalid packet releases is wanted.  */
121     if (invalid_packet_releases)
122     {
123 
124         /* Return the number of invalid packet releases made in this pool.  */
125         *invalid_packet_releases =  pool_ptr -> nx_packet_pool_invalid_releases;
126     }
127 
128     /* Restore interrupts.  */
129     TX_RESTORE
130 
131     /* If trace is enabled, insert this event into the trace buffer.  */
132     NX_TRACE_IN_LINE_INSERT(NX_TRACE_PACKET_POOL_INFO_GET, pool_ptr, pool_ptr -> nx_packet_pool_total, pool_ptr -> nx_packet_pool_available, pool_ptr -> nx_packet_pool_empty_requests, NX_TRACE_PACKET_EVENTS, 0, 0);
133 
134     /* Return completion status.  */
135     return(NX_SUCCESS);
136 }
137 
138