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 /**   System Management (System)                                          */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SOURCE_CODE
23 
24 
25 /* Locate NetX system data in this file.  */
26 
27 #define NX_SYSTEM_INIT
28 
29 
30 /* Include necessary system files.  */
31 
32 #include "nx_api.h"
33 #include "nx_system.h"
34 #include "nx_packet.h"
35 #include "nx_arp.h"
36 #include "nx_rarp.h"
37 #include "nx_ip.h"
38 #include "nx_udp.h"
39 #include "nx_icmp.h"
40 #include "nx_igmp.h"
41 #include "nx_tcp.h"
42 
43 #ifdef FEATURE_NX_IPV6
44 #include "nx_nd_cache.h"
45 #endif /* FEATURE_NX_IPV6 */
46 
47 /**************************************************************************/
48 /*                                                                        */
49 /*  FUNCTION                                               RELEASE        */
50 /*                                                                        */
51 /*    _nx_system_initialize                               PORTABLE C      */
52 /*                                                           6.1          */
53 /*  AUTHOR                                                                */
54 /*                                                                        */
55 /*    Yuxin Zhou, Microsoft Corporation                                   */
56 /*                                                                        */
57 /*  DESCRIPTION                                                           */
58 /*                                                                        */
59 /*    This function initializes the various components and system data    */
60 /*    structures.                                                         */
61 /*                                                                        */
62 /*  INPUT                                                                 */
63 /*                                                                        */
64 /*    pool_start                            Packet pool starting address  */
65 /*    pool_size                             Packet pool size in bytes     */
66 /*                                                                        */
67 /*  OUTPUT                                                                */
68 /*                                                                        */
69 /*    None                                                                */
70 /*                                                                        */
71 /*  CALLS                                                                 */
72 /*                                                                        */
73 /*    _nx_packet_pool_initialize            Initialize Packet Pool        */
74 /*                                            component                   */
75 /*    _nx_ip_initialize                     Initialize IP component       */
76 /*    _nx_tcp_initialize                    Initialize TCP component      */
77 /*                                                                        */
78 /*  CALLED BY                                                             */
79 /*                                                                        */
80 /*    Application                                                         */
81 /*                                                                        */
82 /*  RELEASE HISTORY                                                       */
83 /*                                                                        */
84 /*    DATE              NAME                      DESCRIPTION             */
85 /*                                                                        */
86 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
87 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
88 /*                                            resulting in version 6.1    */
89 /*                                                                        */
90 /**************************************************************************/
_nx_system_initialize(VOID)91 VOID  _nx_system_initialize(VOID)
92 {
93 
94     /* Check whether or not system has been initialized? */
95     if (_nx_system_build_options_1 | _nx_system_build_options_2 |
96         _nx_system_build_options_3 | _nx_system_build_options_4 | _nx_system_build_options_5)
97     {
98 
99         /* Yes it is. Just return. */
100         return;
101     }
102 
103     /* If trace is enabled, insert this event into the trace buffer.  */
104     NX_TRACE_IN_LINE_INSERT(NX_TRACE_SYSTEM_INITIALIZE, 0, 0, 0, 0, NX_TRACE_INTERNAL_EVENTS, 0, 0);
105 
106     /* Call the packet pool initialization component for NetX.  */
107     _nx_packet_pool_initialize();
108 
109     /* Call the IP component initialization.  */
110     _nx_ip_initialize();
111 
112     /* Call the TCP component initialization.  */
113     /*lint -e{522} suppress lack of side-effects.  */
114     _nx_tcp_initialize();
115 
116     /* Setup the build options variables.  */
117     _nx_system_build_options_1 = 0
118 #ifdef NX_LITTLE_ENDIAN
119         | (((ULONG)1) << 31)
120 #endif
121 #ifdef NX_DISABLE_ARP_AUTO_ENTRY
122         | (((ULONG)1) << 30)
123 #endif
124 #ifdef NX_ENABLE_TCP_KEEPALIVE
125         | (((ULONG)1) << 29)
126 #endif
127 #ifdef NX_TCP_IMMEDIATE_ACK
128         | (((ULONG)1) << 28)
129 #endif
130 #ifdef NX_DRIVER_DEFERRED_PROCESSING
131         | (((ULONG)1) << 27)
132 #endif
133 #ifdef NX_DISABLE_FRAGMENTATION
134         | (((ULONG)1) << 26)
135 #endif
136 #ifdef NX_DISABLE_IP_RX_CHECKSUM
137         | (((ULONG)1) << 25)
138 #endif
139 #ifdef NX_DISABLE_IP_TX_CHECKSUM
140         | (((ULONG)1) << 24)
141 #endif
142 #ifdef NX_DISABLE_TCP_RX_CHECKSUM
143         | (((ULONG)1) << 23)
144 #endif
145 #ifdef NX_DISABLE_TCP_TX_CHECKSUM
146         | (((ULONG)1) << 22)
147 #endif
148 #ifdef NX_DISABLE_RESET_DISCONNECT
149         | (((ULONG)1) << 21)
150 #endif
151 #ifdef NX_DISABLE_RX_SIZE_CHECKING
152         | (((ULONG)1) << 20)
153 #endif
154 #ifdef NX_DISABLE_ARP_INFO
155         | (((ULONG)1) << 19)
156 #endif
157 #ifdef NX_DISABLE_IP_INFO
158         | (((ULONG)1) << 18)
159 #endif
160 #ifdef NX_DISABLE_ICMP_INFO
161         | (((ULONG)1) << 17)
162 #endif
163 #ifdef NX_DISABLE_IGMP_INFO
164         | (((ULONG)1) << 16)
165 #endif
166 #ifdef NX_DISABLE_PACKET_INFO
167         | (((ULONG)1) << 15)
168 #endif
169 #ifdef NX_DISABLE_RARP_INFO
170         | (((ULONG)1) << 14)
171 #endif
172 #ifdef NX_DISABLE_TCP_INFO
173         | (((ULONG)1) << 13)
174 #endif
175 #ifdef NX_DISABLE_UDP_INFO
176         | (((ULONG)1) << 12)
177 #endif
178     ;
179 
180 
181     /* Add the retry shift value to the options.  */
182 #if (NX_TCP_RETRY_SHIFT > 0xF)
183     _nx_system_build_options_1 |=  0xF;
184 #else
185     _nx_system_build_options_1 |=  NX_TCP_RETRY_SHIFT;
186 #endif
187 
188 #if (NX_IP_PERIODIC_RATE > 0xFFFFUL)
189     _nx_system_build_options_2 =  ((ULONG)0xFFFF0000);
190 #else
191     _nx_system_build_options_2 =  ((ULONG)NX_IP_PERIODIC_RATE) << 16;
192 #endif
193 
194 #if (NX_ARP_EXPIRATION_RATE > 0xFF)
195     _nx_system_build_options_2 |=  ((ULONG)0xFF) << 8;
196 #else
197     _nx_system_build_options_2 |=  ((ULONG)NX_ARP_EXPIRATION_RATE) << 8;
198 #endif
199 #if (NX_ARP_UPDATE_RATE > 0xFF)
200     _nx_system_build_options_2 |=  ((ULONG)0xFF);
201 #else
202     _nx_system_build_options_2 |=  ((ULONG)NX_ARP_UPDATE_RATE);
203 #endif
204 
205     /* Setup third option word.  */
206 #if (NX_TCP_ACK_TIMER_RATE > 0xFF)
207     _nx_system_build_options_3 =  ((ULONG)0xFF000000);
208 #else
209     _nx_system_build_options_3 =  ((ULONG)NX_TCP_ACK_TIMER_RATE) << 24;
210 #endif
211 #if (NX_TCP_FAST_TIMER_RATE > 0xFF)
212     _nx_system_build_options_3 |=  ((ULONG)0xFF) << 16;
213 #else
214     _nx_system_build_options_3 |=  ((ULONG)NX_TCP_FAST_TIMER_RATE) << 16;
215 #endif
216 #if (NX_TCP_TRANSMIT_TIMER_RATE > 0xFF)
217     _nx_system_build_options_3 |=  ((ULONG)0xFF) << 8;
218 #else
219     _nx_system_build_options_3 |=  ((ULONG)NX_TCP_TRANSMIT_TIMER_RATE) << 8;
220 #endif
221 #if (NX_TCP_KEEPALIVE_RETRY > 0xFF)
222     _nx_system_build_options_3 |=  ((ULONG)0xFF);
223 #else
224     _nx_system_build_options_3 |=  ((ULONG)NX_TCP_KEEPALIVE_RETRY);
225 #endif
226 
227     /* Setup the fourth option word.  */
228 #if (NX_TCP_KEEPALIVE_INITIAL > 0xFFFFUL)
229     _nx_system_build_options_4 =  ((ULONG)0xFFFF0000);
230 #else
231     _nx_system_build_options_4 =  ((ULONG)NX_TCP_KEEPALIVE_INITIAL) << 16;
232 #endif
233 #if (NX_ARP_MAXIMUM_RETRIES > 0xFF)
234     _nx_system_build_options_4 |=  ((ULONG)0xFF) << 8;
235 #else
236     _nx_system_build_options_4 |=  ((ULONG)NX_ARP_MAXIMUM_RETRIES) << 8;
237 #endif
238 #if (NX_ARP_MAX_QUEUE_DEPTH > 0xF)
239     _nx_system_build_options_4 |=  ((ULONG)0xF) << 4;
240 #else
241     _nx_system_build_options_4 |=  ((ULONG)NX_ARP_MAX_QUEUE_DEPTH) << 4;
242 #endif
243 #if (NX_TCP_KEEPALIVE_RETRIES > 0xF)
244     _nx_system_build_options_4 |=  ((ULONG)0xF);
245 #else
246     _nx_system_build_options_4 |=  ((ULONG)NX_TCP_KEEPALIVE_RETRIES);
247 #endif
248 
249     /* Setup the fifth option word.  */
250 #if (NX_MAX_MULTICAST_GROUPS > 0xFF)
251     _nx_system_build_options_5 =  ((ULONG)0xFF000000);
252 #else
253     _nx_system_build_options_5 =  ((ULONG)NX_MAX_MULTICAST_GROUPS) << 24;
254 #endif
255 #if (NX_MAX_LISTEN_REQUESTS > 0xFF)
256     _nx_system_build_options_5 |=  ((ULONG)0xFF) << 16;
257 #else
258     _nx_system_build_options_5 |=  ((ULONG)NX_MAX_LISTEN_REQUESTS) << 16;
259 #endif
260 #if (NX_TCP_MAXIMUM_RETRIES > 0xFF)
261     _nx_system_build_options_5 |=  ((ULONG)0xFF) << 8;
262 #else
263     _nx_system_build_options_5 |=  ((ULONG)NX_TCP_MAXIMUM_RETRIES) << 8;
264 #endif
265 #if (NX_TCP_MAXIMUM_TX_QUEUE > 0xFF)
266     _nx_system_build_options_5 |=  ((ULONG)0xFF);
267 #else
268     _nx_system_build_options_5 |=  ((ULONG)NX_TCP_MAXIMUM_TX_QUEUE);
269 #endif
270 }
271 
272