Index: trunk/kernel/devices/dev_nic.h
===================================================================
--- trunk/kernel/devices/dev_nic.h	(revision 674)
+++ trunk/kernel/devices/dev_nic.h	(revision 683)
@@ -99,5 +99,5 @@
  *
  * - GET_KEY      : get channel index from remote IP address and port 
- * - SET_RUN      : activate/desactivate one channel
+ * - SET_RUN      : activate/desactivate one channel (both directions)
  * - GET_INSTRU   : get one instrumentation counter value
  * - CLEAR_INSTRU : reset all instrumentation counters
@@ -140,10 +140,4 @@
 #define PROTOCOL_TCP           0x06
 
-#define TCP_ISS_CLIENT         0x10000      // initial sequence number for TCP client
-#define TCP_ISS_SERVER         0x20000      // initial sequence number for TCP server
-#define TCP_MAX_WINDOW         0xFFFFF      // initial TCP send window
-
-#define PAYLOAD_MAX_LEN        1500         // max length for an UDP packet / TCP segment
-
 #define TCP_FLAG_FIN           0x01
 #define TCP_FLAG_SYN           0x02
@@ -152,6 +146,4 @@
 #define TCP_FLAG_ACK           0x10
 #define TCP_FLAG_URG           0x20
-
-#define TCP_RETRANSMISSION_TIMEOUT  10000000
 
 /*****************************************************************************************
@@ -192,5 +184,5 @@
  *   in the server thread descriptor, to access the NIC_RX & NIC_TX packet queues.
  *   The buffer is always a 2K bytes kernel buffer, containing an Ethernet packet.
- * - The next 4 synchronous commands are used by the client th, and stored in the 
+ * - The next 4 synchronous commands are used by the client thread, and stored in the 
  *   client thread descriptor, to directly access the NIC registers. 
  ****************************************************************************************/
@@ -212,6 +204,6 @@
     xptr_t      dev_xp;       /*! extended pointer on NIC chdev descriptor              */
     nic_cmd_t   type;         /*! command type                                          */
-    uint8_t   * buffer;       /*! local pointer on kernel buffer                        */  
-    uint32_t    length;       /*! number of bytes in buffer                             */
+    uint8_t   * buffer;       /*! local pointer on kernel buffer (when READ / WRITE)    */  
+    uint32_t    length;       /*! number of bytes in buffer (when READ / WRITE )        */
     uint32_t    status;       /*! return value (depends on command type)                */
     uint32_t    error;        /*! return an error from the hardware (0 if no error)     */
@@ -282,23 +274,23 @@
  * This TX server thread is created by the dev_nic_init() function.
  * It build and send UDP packets or TCP segments for all clients threads registered in
- * the NIC_TX[channel] chdev. The command types are (CONNECT / SEND / CLOSE), and the
- * priority between clients is round-robin. It takes into account the request registered
- * by the RX server thread in the R2T queue associated to the involved socket.
- * When a command is completed, it unblocks the client thread. For a SEND command, the 
- * last byte must have been sent for an UDP socket, and it must have been acknowledged
- * for a TCP socket.
- * When the TX client threads queue is empty, it blocks on THREAD_BLOCKED_CLIENT
- * condition and deschedules. It is re-activated by a client thread registering a command.
+ * the NIC_TX[channel] chdev. The command types are (CONNECT / ACCEPT / CLOSE / SEND).
+ * It takes into account the request registered by the RX server thread in the R2T queues.
+ * The loop on registered sockets implements a round-robin priority between sockets.
+ * When no registered socket is active, it blocks on the THREAD_BLOCKED_CLIENT condition
+ * and deschedules. It is re-activated by a client thread registering a command.
  * When the NIC_TX packet queue is full, it blocks on the THREAD_BLOCKED_ISR condition
  * and deschedules. It is reactivated by the NIC_TX DMA engine.
  ******************************************************************************************
  * Implementation note:
- * It execute an infinite loop in which it takes the lock protecting the clients list
- * to build a "kleenex" list of currently registered clients.
- * For each client registered in this "kleenex" list, it takes the lock protecting the
- * socket state, build one packet/segment in a local 2K bytes kernel buffer, calls the 
- * transport layer to add the UDP/TCP header, calls the IP layer to add the IP header, 
+ * At each iteration in the infinite loop, it takes the lock protecting the registered
+ * client sockets queue to find one active socket (tx_valid or r2t_valid flags set).
+ * For each registered socket, it takes the lock protecting the socket state, and 
+ * exit the scan when an active socket has been found, without releasing the socket state.
+ * When the scan is completed, it release the lock protecting the queue, before handling
+ * the found active socket. The socket lock is released only when the requested packet
+ * has been build, and the active socket state has been updated.
+ * To handle a socket request, it calls the transport layer to build the UDP packet or
+ * TCP segment in a local 2K bytes kernel buffer, calls the IP layer to add the IP header, 
  * calls the ETH layer to add the ETH header, and moves the packet to the NIC_TX_QUEUE.
- * Finally, it updates the socket state, and release the socket lock.
  ******************************************************************************************
  * @ chdev    : [in] local pointer on one local NIC_TX[channel] chdev descriptor.
@@ -331,15 +323,14 @@
 
 /******************************************************************************************
- * This function displays all the fields of an ETH/IP/TCP segment or ETH/IP/UDP packet. 
- ******************************************************************************************
- * @ is_tx   : [in] sent packet if true / received packet if false.
+ * This debug function can be called by the dev_nic_tx_server() function to display
+ * on TXT0 the header of a TX [ETH/IP/TCP] segment or [ETH/IP/UDP] packet. 
+ ******************************************************************************************
  * @ pid     : [in] process identifier.
- * @ trdid   : [in] thread identifier.
+ * @ fdid    : [in] socket identifier.
  * @ cycle   : [in] date (number of cycles).
  * @ buf     : [in] local pointer on kernel buffer containing the packet.
  *****************************************************************************************/
-void dev_nic_packet_display( bool_t    is_tx,
-                             pid_t     pid,
-                             trdid_t   trdid,
+void dev_nic_packet_display( pid_t     pid,
+                             uint32_t  fdid,
                              uint32_t  cycle,
                              uint8_t * buf );
