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 /**   Internet Protocol (IP)                                              */
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 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_ip_packet_deferred_receive                      PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function receives a packet from the link driver (usually the   */
44 /*    link driver's input ISR) and places it in the deferred receive      */
45 /*    packet queue.  This moves the minimal receive packet processing     */
46 /*    from the ISR to the IP helper thread.                               */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    ip_ptr                                Pointer to IP control block   */
51 /*    packet_ptr                            Pointer to packet to send     */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    tx_event_flags_set                    Set events for IP thread      */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application I/O Driver                                              */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
70 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_nx_ip_packet_deferred_receive(NX_IP * ip_ptr,NX_PACKET * packet_ptr)74 VOID  _nx_ip_packet_deferred_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
75 {
76 
77 TX_INTERRUPT_SAVE_AREA
78 
79 
80     /* Disable interrupts.  */
81     TX_DISABLE
82 
83     /* Add debug information. */
84     NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
85 
86     /* Check to see if the deferred processing queue is empty.  */
87     if (ip_ptr -> nx_ip_deferred_received_packet_head)
88     {
89 
90         /* Not empty, just place the packet at the end of the queue.  */
91         (ip_ptr -> nx_ip_deferred_received_packet_tail) -> nx_packet_queue_next =  packet_ptr;
92         packet_ptr -> nx_packet_queue_next =  NX_NULL;
93         ip_ptr -> nx_ip_deferred_received_packet_tail =  packet_ptr;
94 
95         /* Restore interrupts.  */
96         TX_RESTORE
97     }
98     else
99     {
100 
101         /* Empty deferred receive processing queue.  Just setup the head pointers and
102            set the event flags to ensure the IP helper thread looks at the deferred processing
103            queue.  */
104         ip_ptr -> nx_ip_deferred_received_packet_head =  packet_ptr;
105         ip_ptr -> nx_ip_deferred_received_packet_tail =  packet_ptr;
106         packet_ptr -> nx_packet_queue_next =             NX_NULL;
107 
108         /* Restore interrupts.  */
109         TX_RESTORE
110 
111         /* Wakeup IP helper thread to process the IP deferred receive.  */
112         tx_event_flags_set(&(ip_ptr -> nx_ip_events), NX_IP_RECEIVE_EVENT, TX_OR);
113     }
114 }
115 
116