diff --git a/net/igmp/Kconfig b/net/igmp/Kconfig index 59787fe0df..62a02808a0 100644 --- a/net/igmp/Kconfig +++ b/net/igmp/Kconfig @@ -3,8 +3,6 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -menu "IGMPv2 Client Support" - config NET_IGMP bool "IGMPv2 client support" default n @@ -14,12 +12,4 @@ config NET_IGMP if NET_IGMP -config PREALLOC_IGMPGROUPS - int "Number of pre-allocated IGMP groups" - default 4 - ---help--- - Pre-allocated IGMP groups are used only if needed from interrupt - level group created (by the IGMP server). Default: 4. - endif # NET_IGMP -endmenu # IGMPv2 Client Support diff --git a/net/igmp/igmp.h b/net/igmp/igmp.h index bf46fe1897..4850bd511e 100644 --- a/net/igmp/igmp.h +++ b/net/igmp/igmp.h @@ -123,7 +123,6 @@ EXTERN in_addr_t g_ipv4_allrouters; * Public Function Prototypes ****************************************************************************/ -/* Defined in igmp_init.c ***************************************************/ /**************************************************************************** * Name: igmp_initialize * @@ -145,42 +144,22 @@ void igmp_initialize(void); void igmp_devinit(FAR struct net_driver_s *dev); -/* Defined in igmp_input.c **************************************************/ /**************************************************************************** * Name: igmp_input * * Description: * An IGMP packet has been received. * - * NOTE: This is most likely executing from an interrupt handler. - * ****************************************************************************/ void igmp_input(struct net_driver_s *dev); -/* Defined in igmp_group.c **************************************************/ -/**************************************************************************** - * Name: igmp_grpinit - * - * Description: - * One-time initialization of group data. - * - * Assumptions: - * Called only during early boot phases (pre-multitasking). - * - ****************************************************************************/ - -void igmp_grpinit(void); - /**************************************************************************** * Name: igmp_grpalloc * * Description: * Allocate a new group from heap memory. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev, @@ -192,9 +171,6 @@ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev, * Description: * Find an existing group. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev, @@ -207,9 +183,6 @@ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev, * Find an existing group. If not found, create a new group for the * address. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ FAR struct igmp_group_s *igmp_grpallocfind(FAR struct net_driver_s *dev, @@ -221,24 +194,17 @@ FAR struct igmp_group_s *igmp_grpallocfind(FAR struct net_driver_s *dev, * Description: * Release a previously allocated group. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ void igmp_grpfree(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group); -/* Defined in igmp_msg.c ****************************************************/ /**************************************************************************** * Name: igmp_schedmsg * * Description: * Schedule a message to be send at the next driver polling interval. * - * Assumptions: - * This function may be called in most any context. - * ****************************************************************************/ void igmp_schedmsg(FAR struct igmp_group_s *group, uint8_t msgid); @@ -250,15 +216,10 @@ void igmp_schedmsg(FAR struct igmp_group_s *group, uint8_t msgid); * Schedule a message to be send at the next driver polling interval and * block, waiting for the message to be sent. * - * Assumptions: - * This function cannot be called from an interrupt handler (if you try it, - * net_lockedwait will assert). - * ****************************************************************************/ void igmp_waitmsg(FAR struct igmp_group_s *group, uint8_t msgid); -/* Defined in igmp_poll.c ***************************************************/ /**************************************************************************** * Name: igmp_poll * @@ -269,15 +230,10 @@ void igmp_waitmsg(FAR struct igmp_group_s *group, uint8_t msgid); * Returned Value: * Returns a non-zero value if a IGP message is sent. * - * Assumptions: - * This function is called from the driver polling logic... probably within - * an interrupt handler. - * ****************************************************************************/ void igmp_poll(FAR struct net_driver_s *dev); -/* Defined in igmp_send.c ***************************************************/ /**************************************************************************** * Name: igmp_send * @@ -302,7 +258,6 @@ void igmp_poll(FAR struct net_driver_s *dev); void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group, FAR in_addr_t *dest); -/* Defined in igmp_join.c ***************************************************/ /**************************************************************************** * Name: igmp_joingroup * @@ -321,15 +276,11 @@ void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group, * as if a Group-Specific Query was received for that group, and set a * timer appropriately)." * - * Assumptions: - * This function cannot be called from interrupt handling logic! - * ****************************************************************************/ int igmp_joingroup(FAR struct net_driver_s *dev, FAR const struct in_addr *grpaddr); -/* Defined in igmp_leave.c **************************************************/ /**************************************************************************** * Name: igmp_leavegroup * @@ -353,24 +304,17 @@ int igmp_joingroup(FAR struct net_driver_s *dev, * has left the group, but it does no harm to address the message to the * group." * - * Assumptions: - * This function cannot be called from interrupt handling logic! - * ****************************************************************************/ int igmp_leavegroup(FAR struct net_driver_s *dev, FAR const struct in_addr *grpaddr); -/* Defined in igmp_timer.c **************************************************/ /**************************************************************************** * Name: igmp_startticks and igmp_starttimer * * Description: * Start the IGMP timer with differing time units (ticks or deciseconds). * - * Assumptions: - * This function may be called from most any context. - * ****************************************************************************/ void igmp_startticks(FAR struct igmp_group_s *group, unsigned int ticks); @@ -384,15 +328,13 @@ void igmp_starttimer(FAR struct igmp_group_s *group, uint8_t decisecs); * value. If maxticks > ticks-remaining, then (1) cancel the timer (to * avoid race conditions) and return true. * - * Assumptions: - * This function may be called from most any context. If true is returned - * then the caller must call igmp_startticks() to restart the timer + * If true is returned then the caller must call igmp_startticks() to + * restart the timer * ****************************************************************************/ bool igmp_cmptimer(FAR struct igmp_group_s *group, int maxticks); -/* Defined in igmp_mcastmac *************************************************/ /**************************************************************************** * Name: igmp_addmcastmac * diff --git a/net/igmp/igmp_group.c b/net/igmp/igmp_group.c index a1fe865eb5..74039fb578 100644 --- a/net/igmp/igmp_group.c +++ b/net/igmp/igmp_group.c @@ -75,10 +75,6 @@ # error "IGMP for IPv6 not supported" #endif -#ifndef CONFIG_PREALLOC_IGMPGROUPS -# define CONFIG_PREALLOC_IGMPGROUPS 4 -#endif - /* Debug ********************************************************************/ #undef IGMP_GRPDEBUG /* Define to enable detailed IGMP group debug */ @@ -105,108 +101,16 @@ # endif #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* kmm_malloc() cannot be called from an interrupt handler. To work around this, - * a small number of IGMP groups are preallocated just for use in interrupt - * handling logic. - */ - -#if CONFIG_PREALLOC_IGMPGROUPS > 0 -static struct igmp_group_s g_preallocgrps[CONFIG_PREALLOC_IGMPGROUPS]; -static FAR sq_queue_t g_freelist; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: igmp_grpheapalloc - * - * Description: - * Allocate a new group from heap memory. - * - * Assumptions: - * Calls kmm_malloc and so cannot be called from an interrupt handler. - * - ****************************************************************************/ - -static inline FAR struct igmp_group_s *igmp_grpheapalloc(void) -{ - return (FAR struct igmp_group_s *)kmm_zalloc(sizeof(struct igmp_group_s)); -} - -/**************************************************************************** - * Name: igmp_grpprealloc - * - * Description: - * Allocate a new group from the pre-allocated groups. - * - * Assumptions: - * This function should only be called from an interrupt handler (or with - * interrupts disabled). - * - ****************************************************************************/ - -#if CONFIG_PREALLOC_IGMPGROUPS > 0 -static inline FAR struct igmp_group_s *igmp_grpprealloc(void) -{ - FAR struct igmp_group_s *group = - (FAR struct igmp_group_s *)sq_remfirst(&g_freelist); - - if (group) - { - memset(group, 0, sizeof(struct igmp_group_s)); - group->flags = IGMP_PREALLOCATED; - } - - return group; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: igmp_grpinit - * - * Description: - * One-time initialization of group data. - * - * Assumptions: - * Called only during early boot phases (pre-multitasking). - * - ****************************************************************************/ - -void igmp_grpinit(void) -{ - FAR struct igmp_group_s *group; - int i; - - grpinfo("Initializing\n"); - -#if CONFIG_PREALLOC_IGMPGROUPS > 0 - for (i = 0; i < CONFIG_PREALLOC_IGMPGROUPS; i++) - { - group = &g_preallocgrps[i]; - sq_addfirst((FAR sq_entry_t *)group, &g_freelist); - } -#endif -} - /**************************************************************************** * Name: igmp_grpalloc * * Description: * Allocate a new group from heap memory. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev, @@ -215,27 +119,13 @@ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group; ninfo("addr: %08x dev: %p\n", *addr, dev); - if (up_interrupt_context()) - { -#if CONFIG_PREALLOC_IGMPGROUPS > 0 - grpinfo("Use a pre-allocated group entry\n"); - group = igmp_grpprealloc(); -#else - grperr("ERROR: Cannot allocate from interrupt handler\n"); - group = NULL; -#endif - } - else - { - grpinfo("Allocate from the heap\n"); - group = igmp_grpheapalloc(); - } + group = (FAR struct igmp_group_s *)kmm_zalloc(sizeof(struct igmp_group_s)); grpinfo("group: %p\n", group); /* Check if we successfully allocated a group structure */ - if (group) + if (group != NULL) { /* Initialize the non-zero elements of the group structure */ @@ -272,9 +162,6 @@ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev, * Description: * Find an existing group. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev, @@ -284,10 +171,6 @@ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev, grpinfo("Searching for addr %08x\n", (int)*addr); - /* We must disable interrupts because we don't which context we were - * called from. - */ - net_lock(); for (group = (FAR struct igmp_group_s *)dev->grplist.head; group; @@ -312,9 +195,6 @@ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev, * Find an existing group. If not found, create a new group for the * address. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ FAR struct igmp_group_s *igmp_grpallocfind(FAR struct net_driver_s *dev, @@ -338,9 +218,6 @@ FAR struct igmp_group_s *igmp_grpallocfind(FAR struct net_driver_s *dev, * Description: * Release a previously allocated group. * - * Assumptions: - * May be called from either user or interrupt level processing. - * ****************************************************************************/ void igmp_grpfree(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group) @@ -364,28 +241,12 @@ void igmp_grpfree(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group) wd_delete(group->wdog); - /* Then release the group structure resources. Check first if this is one - * of the pre-allocated group structures that we will retain in a free list. - */ + /* Then release the group structure resources. */ -#if CONFIG_PREALLOC_IGMPGROUPS > 0 - if (IS_PREALLOCATED(group->flags)) - { - grpinfo("Put back on free list\n"); - sq_addlast((FAR sq_entry_t *)group, &g_freelist); - net_unlock(); - } - else -#endif - { - /* No.. deallocate the group structure. Use sched_kfree() just in case - * this function is executing within an interrupt handler. - */ - - net_unlock(); - grpinfo("Call sched_kfree()\n"); - sched_kfree(group); - } + net_unlock(); + grpinfo("Call sched_kfree()\n"); + sched_kfree(group); } #endif /* CONFIG_NET_IGMP */ + diff --git a/net/igmp/igmp_initialize.c b/net/igmp/igmp_initialize.c index 84dd6f34c1..89ad5ccfef 100644 --- a/net/igmp/igmp_initialize.c +++ b/net/igmp/igmp_initialize.c @@ -88,10 +88,6 @@ void igmp_initialize(void) net_ipaddr(g_ipv4_allrouters, 224, 0, 0, 2); net_ipaddr(g_ipv4_allsystems, 224, 0, 0, 1); - - /* Initialize the group allocation logic */ - - igmp_grpinit(); } /**************************************************************************** diff --git a/net/igmp/igmp_input.c b/net/igmp/igmp_input.c index d89569b509..a5c19b8030 100644 --- a/net/igmp/igmp_input.c +++ b/net/igmp/igmp_input.c @@ -106,7 +106,7 @@ * | < current timer) | * +-------------------+ * - * NOTE: This is most likely executing from an interrupt handler. + * NOTE: The network must be locked. * ****************************************************************************/ diff --git a/net/igmp/igmp_join.c b/net/igmp/igmp_join.c index c72ebe3f0a..51fb4eb25b 100644 --- a/net/igmp/igmp_join.c +++ b/net/igmp/igmp_join.c @@ -111,9 +111,6 @@ * | < current timer) | * +-------------------+ * - * Assumptions: - * This function cannot be called from interrupt handling logic! - * ****************************************************************************/ int igmp_joingroup(struct net_driver_s *dev, FAR const struct in_addr *grpaddr) diff --git a/net/igmp/igmp_leave.c b/net/igmp/igmp_leave.c index 2b7ee654b3..85d6d9a403 100644 --- a/net/igmp/igmp_leave.c +++ b/net/igmp/igmp_leave.c @@ -119,9 +119,6 @@ * | < current timer) | * +-------------------+ * - * Assumptions: - * This function cannot be called from interrupt handling logic! - * ****************************************************************************/ int igmp_leavegroup(struct net_driver_s *dev, FAR const struct in_addr *grpaddr) diff --git a/net/igmp/igmp_msg.c b/net/igmp/igmp_msg.c index 0b5065f3ec..0f8b1fb9c5 100644 --- a/net/igmp/igmp_msg.c +++ b/net/igmp/igmp_msg.c @@ -88,10 +88,6 @@ void igmp_schedmsg(FAR struct igmp_group_s *group, uint8_t msgid) * Schedule a message to be send at the next driver polling interval and * block, waiting for the message to be sent. * - * Assumptions: - * This function cannot be called from an interrupt handler (if you try it, - * net_lockedwait will assert). - * ****************************************************************************/ void igmp_waitmsg(FAR struct igmp_group_s *group, uint8_t msgid) diff --git a/net/igmp/igmp_poll.c b/net/igmp/igmp_poll.c index 0fe705868f..80462d2574 100644 --- a/net/igmp/igmp_poll.c +++ b/net/igmp/igmp_poll.c @@ -70,8 +70,7 @@ * Returns a non-zero value if an IGMP message is sent. * * Assumptions: - * This function is called from the driver polling logic... probably within - * an interrupt handler. + * This function ust be called with the network locked. * ****************************************************************************/ @@ -134,8 +133,7 @@ static inline void igmp_sched_send(FAR struct net_driver_s *dev, * Returns a non-zero value if a IGP message is sent. * * Assumptions: - * This function is called from the driver polling logic... probably within - * an interrupt handler. + * This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/igmp/igmp_timer.c b/net/igmp/igmp_timer.c index 9019376a4e..e989039282 100644 --- a/net/igmp/igmp_timer.c +++ b/net/igmp/igmp_timer.c @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -196,13 +197,14 @@ void igmp_starttimer(FAR struct igmp_group_s *group, uint8_t decisecs) bool igmp_cmptimer(FAR struct igmp_group_s *group, int maxticks) { + irqstate_t flags; int remaining; /* Disable interrupts so that there is no race condition with the actual * timer expiration. */ - net_lock(); + flags = enter_critical_section(); /* Get the timer remaining on the watchdog. A time of <= zero means that * the watchdog was never started. @@ -221,11 +223,11 @@ bool igmp_cmptimer(FAR struct igmp_group_s *group, int maxticks) /* Cancel the watchdog timer and return true */ wd_cancel(group->wdog); - net_unlock(); + leave_critical_section(flags); return true; } - net_unlock(); + leave_critical_section(flags); return false; } diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index cf8ceb618d..17bae962fe 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -62,7 +62,7 @@ struct accept_s { FAR struct socket *acpt_sock; /* The accepting socket */ - sem_t acpt_sem; /* Wait for interrupt event */ + sem_t acpt_sem; /* Wait for driver event */ FAR struct sockaddr *acpt_addr; /* Return connection address */ FAR socklen_t *acpt_addrlen; /* Return length of address */ FAR struct tcp_conn_s *acpt_newconn; /* The accepted connection */ @@ -148,7 +148,7 @@ static inline void accept_tcpsender(FAR struct socket *psock, * Name: accept_eventhandler * * Description: - * Receive interrupt level callbacks when connections occur + * Receive event callbacks when connections occur * * Parameters: * listener The connection structure of the listener @@ -270,9 +270,9 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, /* Perform the TCP accept operation */ - /* Initialize the state structure. This is done with interrupts - * disabled because we don't want anything to happen until we - * are ready. + /* Initialize the state structure. This is done with the network + * locked because we don't want anything to happen until we are + * ready. */ state.acpt_sock = psock; @@ -293,10 +293,8 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, conn->accept_private = (FAR void *)&state; conn->accept = accept_eventhandler; - /* Wait for the send to complete or an error to occur: NOTES: (1) - * net_lockedwait will also terminate if a signal is received, (2) - * interrupts may be disabled! They will be re-enabled while the - * task sleeps and automatically re-enabled when the task restarts. + /* Wait for the send to complete or an error to occur: NOTES: + * net_lockedwait will also terminate if a signal is received. */ ret = net_lockedwait(&state.acpt_sem); @@ -315,7 +313,7 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr, DEBUGASSERT(ret < 0); } - /* Make sure that no further interrupts are processed */ + /* Make sure that no further events are processed */ conn->accept_private = NULL; conn->accept = NULL; diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index c3fd08e3a6..dcc16927b9 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -67,7 +67,7 @@ * Assumptions: * - The caller has checked that TCP_NEWDATA is set in flags and that is no * other handler available to process the incoming data. - * - This function is called at the interrupt level with interrupts disabled. + * - This function must be called with the network locked. * ****************************************************************************/ @@ -139,7 +139,7 @@ tcp_data_event(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, * Inform the application holding the TCP socket of a change in state. * * Assumptions: - * This function is called at the interrupt level with interrupts disabled. + * This function must be called with the network locked. * ****************************************************************************/ @@ -225,7 +225,7 @@ uint16_t tcp_callback(FAR struct net_driver_s *dev, * Assumptions: * - The caller has checked that TCP_NEWDATA is set in flags and that is no * other handler available to process the incoming data. - * - This function is called at the interrupt level with interrupts disabled. + * - This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 1dd2f269d5..6e81a5c182 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -312,7 +312,7 @@ static int tcp_selectport(uint8_t domain, FAR const union ip_addr_u *ipaddr, * connection to be used with the provided TCP/IP header * * Assumptions: - * This function is called from network logic at interrupt level + * This function is called from network logic with the nework locked. * ****************************************************************************/ @@ -379,8 +379,8 @@ static inline FAR struct tcp_conn_s * * connection to be used with the provided TCP/IP header * * Assumptions: - * This function is called from network logic at interrupt level - * + * This function is called from network logic with the nework locked. +4 * ****************************************************************************/ #ifdef CONFIG_NET_IPv6 @@ -611,8 +611,8 @@ void tcp_initialize(void) * Description: * Find a free TCP/IP connection structure and allocate it * for use. This is normally something done by the implementation of the - * socket() API but is also called from the interrupt level when a TCP - * packet is received while "listening" + * socket() API but is also called from the even procressing lock when a + * TCP packet is received while "listening" * ****************************************************************************/ @@ -620,9 +620,9 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain) { FAR struct tcp_conn_s *conn; - /* Because this routine is called from both interrupt level and - * and from user level, we have not option but to disable interrupts - * while accessing g_free_tcp_connections[]; + /* Because this routine is called from both event processing (with the + * network locked) and and from user level. Make sure that the network + * locked in any cased while accessing g_free_tcp_connections[]; */ net_lock(); @@ -737,8 +737,8 @@ void tcp_free(FAR struct tcp_conn_s *conn) FAR struct tcp_wrbuffer_s *wrbuffer; #endif - /* Because g_free_tcp_connections is accessed from user level and interrupt - * level, code, it is necessary to keep interrupts disabled during this + /* Because g_free_tcp_connections is accessed from user level and event + * processing logic, it is necessary to keep the newtork locked during this * operation. */ @@ -819,7 +819,7 @@ void tcp_free(FAR struct tcp_conn_s *conn) * connection to be used with the provided TCP/IP header * * Assumptions: - * This function is called from network logic at interrupt level + * This function is called from network logic with the nework locked. * ****************************************************************************/ @@ -852,8 +852,7 @@ FAR struct tcp_conn_s *tcp_active(FAR struct net_driver_s *dev, * Traverse the list of active TCP connections * * Assumptions: - * This function is called from network logic at interrupt level (or with - * interrupts disabled). + * This function is called from network logic with the nework locked. * ****************************************************************************/ @@ -873,12 +872,12 @@ FAR struct tcp_conn_s *tcp_nextconn(FAR struct tcp_conn_s *conn) * Name: tcp_alloc_accept * * Description: - * Called when driver interrupt processing matches the incoming packet + * Called when driver event processing matches the incoming packet * with a connection in LISTEN. In that case, this function will create * a new connection and initialize it to send a SYNACK in return. * * Assumptions: - * This function is called from network logic at interrupt level + * This function is called from network logic with the nework locked. * ****************************************************************************/ diff --git a/net/tcp/tcp_connect.c b/net/tcp/tcp_connect.c index 842c4de2bd..e4f4d1351c 100644 --- a/net/tcp/tcp_connect.c +++ b/net/tcp/tcp_connect.c @@ -362,10 +362,8 @@ int psock_tcp_connect(FAR struct socket *psock, if (ret >= 0) { /* Wait for either the connect to complete or for an error/timeout - * to occur. NOTES: (1) net_lockedwait will also terminate if a signal - * is received, (2) interrupts may be disabled! They will be re- - * enabled while the task sleeps and automatically re-disabled - * when the task restarts. + * to occur. NOTES: net_lockedwait will also terminate if a signal + * is received. */ ret = net_lockedwait(&state.tc_sem); diff --git a/net/tcp/tcp_listen.c b/net/tcp/tcp_listen.c index 8b3b686137..0f9f1af920 100644 --- a/net/tcp/tcp_listen.c +++ b/net/tcp/tcp_listen.c @@ -73,7 +73,7 @@ static FAR struct tcp_conn_s *tcp_listenports[CONFIG_NET_MAX_LISTENPORTS]; * Return the connection listener for connections on this port (if any) * * Assumptions: - * Called at interrupt level + * This function is called from network logic with the nework locked. * ****************************************************************************/ @@ -183,8 +183,8 @@ int tcp_listen(FAR struct tcp_conn_s *conn) int ndx; int ret; - /* This must be done with interrupts disabled because the listener table - * is accessed from interrupt level as well. + /* This must be done with network locked because the listener table + * is accessed from event processing logic as well. */ net_lock(); @@ -237,7 +237,7 @@ int tcp_listen(FAR struct tcp_conn_s *conn) * Return true is there is a listener for the specified port * * Assumptions: - * Called at interrupt level + * This function is called from network logic with the nework locked. * ****************************************************************************/ @@ -270,9 +270,9 @@ int tcp_accept_connection(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *listener; int ret = ERROR; - /* The interrupt logic has already allocated and initialized a TCP - * connection -- now check there if is an application in place to accept the - * connection. + /* The event processing logic has already allocated and initialized a TCP + * connection -- now check there if is an application in place to accept + * the connection. */ #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) diff --git a/net/tcp/tcp_netpoll.c b/net/tcp/tcp_netpoll.c index 7715c7225b..a12be6efee 100644 --- a/net/tcp/tcp_netpoll.c +++ b/net/tcp/tcp_netpoll.c @@ -77,7 +77,7 @@ struct tcp_poll_s * the device interface layer. * * Parameters: - * dev The structure of the network driver that caused the interrupt + * dev The structure of the network driver that caused the event * conn The connection structure associated with the socket * flags Set of events describing why the callback was invoked * diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index b15e132955..7f797f2c34 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -216,7 +216,7 @@ static inline void psock_lost_connection(FAR struct socket *psock, * nothing. * * Parameters: - * dev - The structure of the network driver that caused the interrupt + * dev - The structure of the network driver that caused the event * psock - Socket state structure * * Returned Value: @@ -324,11 +324,11 @@ static inline bool psock_send_addrchck(FAR struct tcp_conn_s *conn) * Name: psock_send_eventhandler * * Description: - * This function is called from the interrupt level to perform the actual - * send operation when polled by the lower, device interfacing layer. + * This function is called to perform the actual send operation when + * polled by the lower, device interfacing layer. * * Parameters: - * dev The structure of the network driver that caused the interrupt + * dev The structure of the network driver that caused the event * conn The connection structure associated with the socket * flags Set of events describing why the callback was invoked * @@ -674,7 +674,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev, } /* Check if the outgoing packet is available (it may have been claimed - * by a sendto interrupt serving a different thread). + * by a sendto event serving a different thread). */ if (dev->d_sndlen > 0) @@ -1139,9 +1139,6 @@ errout: * -ENOTCONN * The socket is not connected. * - * Assumptions: - * Not running at the interrupt level - * ****************************************************************************/ int psock_tcp_cansend(FAR struct socket *psock) diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index bd24069e85..006429d7a6 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -92,7 +92,7 @@ ****************************************************************************/ /* This structure holds the state of the send operation until it can be - * operated upon from the interrupt level. + * operated upon when the TX poll event occurs. */ struct send_s @@ -167,7 +167,7 @@ static inline int send_timeout(FAR struct send_s *pstate) * nothing. * * Parameters: - * dev - The structure of the network driver that caused the interrupt + * dev - The structure of the network driver that caused the event * pstate - sendto state structure * * Returned Value: @@ -275,11 +275,11 @@ static inline bool psock_send_addrchck(FAR struct tcp_conn_s *conn) * Name: tcpsend_eventhandler * * Description: - * This function is called from the interrupt level to perform the actual - * send operation when polled by the lower, device interfacing layer. + * This function is called to perform the actual send operation when + * polled by the lower, device interfacing layer. * * Parameters: - * dev The structure of the network driver that caused the interrupt + * dev The structure of the network driver that caused the event * conn The connection structure associated with the socket * flags Set of events describing why the callback was invoked * @@ -406,7 +406,7 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev, } /* Check if the outgoing packet is available (it may have been claimed - * by a sendto interrupt serving a different thread). + * by a sendto event serving a different thread). */ #if 0 /* We can't really support multiple senders on the same TCP socket */ @@ -780,9 +780,9 @@ ssize_t psock_tcp_send(FAR struct socket *psock, /* Perform the TCP send operation */ - /* Initialize the state structure. This is done with interrupts - * disabled because we don't want anything to happen until we - * are ready. + /* Initialize the state structure. This is done with the network + * locked because we don't want anything to happen until we are + * ready. */ net_lock(); @@ -832,15 +832,13 @@ ssize_t psock_tcp_send(FAR struct socket *psock, send_txnotify(psock, conn); - /* Wait for the send to complete or an error to occur: NOTES: (1) - * net_lockedwait will also terminate if a signal is received, (2) interrupts - * may be disabled! They will be re-enabled while the task sleeps and - * automatically re-enabled when the task restarts. + /* Wait for the send to complete or an error to occur: NOTES: + * net_lockedwait will also terminate if a signal is received. */ ret = net_lockedwait(&state.snd_sem); - /* Make sure that no further interrupts are processed */ + /* Make sure that no further events are processed */ tcp_callback_free(conn, state.snd_cb); } diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c index da2108c99d..9e90d85bb6 100644 --- a/net/tcp/tcp_sendfile.c +++ b/net/tcp/tcp_sendfile.c @@ -90,7 +90,7 @@ ****************************************************************************/ /* This structure holds the state of the send operation until it can be - * operated upon from the interrupt level. + * operated upon from the driver poll event. */ struct sendfile_s @@ -311,11 +311,11 @@ static inline bool sendfile_addrcheck(FAR struct tcp_conn_s *conn) * Name: sendfile_eventhandler * * Description: - * This function is called from the interrupt level to perform the actual - * send operation when polled by the lower, device interfacing layer. + * This function is called to perform the actual send operation when + * polled by the lower, device interfacing layer. * * Parameters: - * dev The structure of the network driver that caused the interrupt + * dev The structure of the network driver that caused the event * conn The connection structure associated with the socket * flags Set of events describing why the callback was invoked * @@ -609,9 +609,9 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile, psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND); - /* Initialize the state structure. This is done with interrupts - * disabled because we don't want anything to happen until we - * are ready. + /* Initialize the state structure. This is done with the network + * locked because we don't want anything to happen until we are + * ready. */ net_lock(); diff --git a/net/tcp/tcp_seqno.c b/net/tcp/tcp_seqno.c index e3c6a75c05..042fb7ad55 100644 --- a/net/tcp/tcp_seqno.c +++ b/net/tcp/tcp_seqno.c @@ -70,7 +70,8 @@ static uint32_t g_tcpsequence; * Set the TCP/IP sequence number * * Assumptions: - * This function may called from the interrupt level + * This function must be called with the network locked if seqno refers + * to a shared, global resource. * ****************************************************************************/ @@ -91,7 +92,8 @@ void tcp_setsequence(FAR uint8_t *seqno, uint32_t value) * Get the TCP/IP sequence number * * Assumptions: - * This function may called from the interrupt level + * This function must be called with the network locked if seqno refers + * to a shared, global resource. * ****************************************************************************/ @@ -115,7 +117,8 @@ uint32_t tcp_getsequence(FAR uint8_t *seqno) * Add the length to get the next TCP sequence number. * * Assumptions: - * This function may called from the interrupt level + * This function must be called with the network locked if seqno refers + * to a shared, global resource. * ****************************************************************************/ @@ -132,7 +135,8 @@ uint32_t tcp_addsequence(FAR uint8_t *seqno, uint16_t len) * established. * * Assumptions: - * This function may called from the interrupt level + * This function must be called with the network locked if seqno refers + * to a shared, global resource. * ****************************************************************************/ @@ -148,7 +152,7 @@ void tcp_initsequence(FAR uint8_t *seqno) * Increment the TCP/IP sequence number * * Assumptions: - * This function is called from the interrupt level + * This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c index 2a4b7c65ca..3947d5294e 100644 --- a/net/tcp/tcp_wrbuffer.c +++ b/net/tcp/tcp_wrbuffer.c @@ -177,7 +177,7 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void) * buffered data. * * Assumptions: - * Called from interrupt level with interrupts disabled. + * This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index 6a763f79bc..c35db56bdd 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -296,7 +296,7 @@ net_dataevent(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn, * OK if packet has been processed, otherwise ERROR. * * Assumptions: - * This function is called at the interrupt level with interrupts disabled. + * This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index 0407f67e24..35099f4776 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -125,8 +125,10 @@ static inline void _udp_semtake(FAR sem_t *sem) * Name: udp_find_conn() * * Description: - * Find the UDP connection that uses this local port number. Called only - * from user user level code, but with interrupts disabled. + * Find the UDP connection that uses this local port number. + * + * Assumptions: + * This function must be called with the network locked. * ****************************************************************************/ @@ -245,7 +247,7 @@ static uint16_t udp_select_port(uint8_t domain, FAR union ip_binding_u *u) * used within the provided UDP header * * Assumptions: - * This function is called from network logic at interrupt level + * This function must be called with the network locked. * ****************************************************************************/ @@ -337,7 +339,7 @@ static inline FAR struct udp_conn_s * * used within the provided UDP header * * Assumptions: - * This function is called from network logic at interrupt level + * This function must be called with the network locked. * ****************************************************************************/ @@ -465,9 +467,7 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain) { FAR struct udp_conn_s *conn; - /* The free list is only accessed from user, non-interrupt level and - * is protected by a semaphore (that behaves like a mutex). - */ + /* The free list is protected by a semaphore (that behaves like a mutex). */ _udp_semtake(&g_free_sem); conn = (FAR struct udp_conn_s *)dq_remfirst(&g_free_udp_connections); @@ -501,9 +501,7 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain) void udp_free(FAR struct udp_conn_s *conn) { - /* The free list is only accessed from user, non-interrupt level and - * is protected by a semaphore (that behaves like a mutex). - */ + /* The free list is protected by a semaphore (that behaves like a mutex). */ DEBUGASSERT(conn->crefs == 0); @@ -534,7 +532,7 @@ void udp_free(FAR struct udp_conn_s *conn) * connection to be used within the provided UDP header * * Assumptions: - * This function is called from network logic at interrupt level + * This function must be called with the network locked. * ****************************************************************************/ @@ -567,8 +565,7 @@ FAR struct udp_conn_s *udp_active(FAR struct net_driver_s *dev, * Traverse the list of allocated UDP connections * * Assumptions: - * This function is called from network logic at interrupt level (or with - * interrupts disabled). + * This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/udp/udp_netpoll.c b/net/udp/udp_netpoll.c index 3f74901e60..20fdf58787 100644 --- a/net/udp/udp_netpoll.c +++ b/net/udp/udp_netpoll.c @@ -72,11 +72,11 @@ struct udp_poll_s * Name: udp_poll_eventhandler * * Description: - * This function is called from the interrupt level to perform the actual - * UDP receive operation via by the device interface layer. + * This function is called to perform the actual UDP receive operation + * via the device interface layer. * * Parameters: - * dev The structure of the network driver that caused the interrupt + * dev The structure of the network driver that caused the event * conn The connection structure associated with the socket * flags Set of events describing why the callback was invoked * @@ -84,7 +84,7 @@ struct udp_poll_s * None * * Assumptions: - * The network is locked + * This function must be called with the network locked. * ****************************************************************************/ diff --git a/net/udp/udp_psock_sendto.c b/net/udp/udp_psock_sendto.c index d29277c091..4a8eb83b2a 100644 --- a/net/udp/udp_psock_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -163,14 +163,14 @@ static inline int send_timeout(FAR struct sendto_s *pstate) * nothing. * * Parameters: - * dev - The structure of the network driver that caused the interrupt + * dev - The structure of the network driver that caused the event * pstate - sendto state structure * * Returned Value: * None * * Assumptions: - * The network is locked + * This function must be called with the network locked. * ****************************************************************************/ @@ -203,11 +203,11 @@ static inline void sendto_ipselect(FAR struct net_driver_s *dev, * Name: sendto_eventhandler * * Description: - * This function is called from the interrupt level to perform the actual - * send operation when polled by the lower, device interfacing layer. + * This function is called to perform the actual send operation when + * polled by the lower, device interfacing layer. * * Parameters: - * dev The structure of the network driver that caused the interrupt + * dev The structure of the network driver that caused the event * conn An instance of the UDP connection structure cast to void * * pvpriv An instance of struct sendto_s cast to void* * flags Set of events describing why the callback was invoked @@ -216,7 +216,7 @@ static inline void sendto_ipselect(FAR struct net_driver_s *dev, * Modified value of the input flags * * Assumptions: - * The network is locked + * This function must be called with the network locked. * ****************************************************************************/ @@ -242,7 +242,7 @@ static uint16_t sendto_eventhandler(FAR struct net_driver_s *dev, } /* Check if the outgoing packet is available. It may have been claimed - * by a sendto interrupt serving a different thread -OR- if the output + * by a sendto event serving a different thread -OR- if the output * buffer currently contains unprocessed incoming data. In these cases * we will just have to wait for the next polling cycle. */ @@ -385,9 +385,9 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND); - /* Initialize the state structure. This is done with interrupts - * disabled because we don't want anything to happen until we - * are ready. + /* Initialize the state structure. This is done with the network + * locked because we don't want anything to happen until we are + * ready. */ net_lock(); @@ -456,15 +456,14 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, netdev_txnotify_dev(dev); - /* Wait for either the receive to complete or for an error/timeout to occur. - * NOTES: (1) net_lockedwait will also terminate if a signal is received, (2) - * interrupts may be disabled! They will be re-enabled while the task sleeps - * and automatically re-enabled when the task restarts. + /* Wait for either the receive to complete or for an error/timeout to + * occur. NOTES: net_lockedwait will also terminate if a signal + * is received. */ net_lockedwait(&state.st_sem); - /* Make sure that no further interrupts are processed */ + /* Make sure that no further events are processed */ udp_callback_free(dev, conn, state.st_cb); }