Ignore:
Timestamp:
Jan 13, 2021, 12:36:17 AM (3 years ago)
Author:
alain
Message:

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_nic.h

    r674 r683  
    9999 *
    100100 * - GET_KEY      : get channel index from remote IP address and port
    101  * - SET_RUN      : activate/desactivate one channel
     101 * - SET_RUN      : activate/desactivate one channel (both directions)
    102102 * - GET_INSTRU   : get one instrumentation counter value
    103103 * - CLEAR_INSTRU : reset all instrumentation counters
     
    140140#define PROTOCOL_TCP           0x06
    141141
    142 #define TCP_ISS_CLIENT         0x10000      // initial sequence number for TCP client
    143 #define TCP_ISS_SERVER         0x20000      // initial sequence number for TCP server
    144 #define TCP_MAX_WINDOW         0xFFFFF      // initial TCP send window
    145 
    146 #define PAYLOAD_MAX_LEN        1500         // max length for an UDP packet / TCP segment
    147 
    148142#define TCP_FLAG_FIN           0x01
    149143#define TCP_FLAG_SYN           0x02
     
    152146#define TCP_FLAG_ACK           0x10
    153147#define TCP_FLAG_URG           0x20
    154 
    155 #define TCP_RETRANSMISSION_TIMEOUT  10000000
    156148
    157149/*****************************************************************************************
     
    192184 *   in the server thread descriptor, to access the NIC_RX & NIC_TX packet queues.
    193185 *   The buffer is always a 2K bytes kernel buffer, containing an Ethernet packet.
    194  * - The next 4 synchronous commands are used by the client th, and stored in the
     186 * - The next 4 synchronous commands are used by the client thread, and stored in the
    195187 *   client thread descriptor, to directly access the NIC registers.
    196188 ****************************************************************************************/
     
    212204    xptr_t      dev_xp;       /*! extended pointer on NIC chdev descriptor              */
    213205    nic_cmd_t   type;         /*! command type                                          */
    214     uint8_t   * buffer;       /*! local pointer on kernel buffer                        */ 
    215     uint32_t    length;       /*! number of bytes in buffer                             */
     206    uint8_t   * buffer;       /*! local pointer on kernel buffer (when READ / WRITE)    */ 
     207    uint32_t    length;       /*! number of bytes in buffer (when READ / WRITE )        */
    216208    uint32_t    status;       /*! return value (depends on command type)                */
    217209    uint32_t    error;        /*! return an error from the hardware (0 if no error)     */
     
    282274 * This TX server thread is created by the dev_nic_init() function.
    283275 * It build and send UDP packets or TCP segments for all clients threads registered in
    284  * the NIC_TX[channel] chdev. The command types are (CONNECT / SEND / CLOSE), and the
    285  * priority between clients is round-robin. It takes into account the request registered
    286  * by the RX server thread in the R2T queue associated to the involved socket.
    287  * When a command is completed, it unblocks the client thread. For a SEND command, the
    288  * last byte must have been sent for an UDP socket, and it must have been acknowledged
    289  * for a TCP socket.
    290  * When the TX client threads queue is empty, it blocks on THREAD_BLOCKED_CLIENT
    291  * condition and deschedules. It is re-activated by a client thread registering a command.
     276 * the NIC_TX[channel] chdev. The command types are (CONNECT / ACCEPT / CLOSE / SEND).
     277 * It takes into account the request registered by the RX server thread in the R2T queues.
     278 * The loop on registered sockets implements a round-robin priority between sockets.
     279 * When no registered socket is active, it blocks on the THREAD_BLOCKED_CLIENT condition
     280 * and deschedules. It is re-activated by a client thread registering a command.
    292281 * When the NIC_TX packet queue is full, it blocks on the THREAD_BLOCKED_ISR condition
    293282 * and deschedules. It is reactivated by the NIC_TX DMA engine.
    294283 ******************************************************************************************
    295284 * Implementation note:
    296  * It execute an infinite loop in which it takes the lock protecting the clients list
    297  * to build a "kleenex" list of currently registered clients.
    298  * For each client registered in this "kleenex" list, it takes the lock protecting the
    299  * socket state, build one packet/segment in a local 2K bytes kernel buffer, calls the
    300  * transport layer to add the UDP/TCP header, calls the IP layer to add the IP header,
     285 * At each iteration in the infinite loop, it takes the lock protecting the registered
     286 * client sockets queue to find one active socket (tx_valid or r2t_valid flags set).
     287 * For each registered socket, it takes the lock protecting the socket state, and
     288 * exit the scan when an active socket has been found, without releasing the socket state.
     289 * When the scan is completed, it release the lock protecting the queue, before handling
     290 * the found active socket. The socket lock is released only when the requested packet
     291 * has been build, and the active socket state has been updated.
     292 * To handle a socket request, it calls the transport layer to build the UDP packet or
     293 * TCP segment in a local 2K bytes kernel buffer, calls the IP layer to add the IP header,
    301294 * calls the ETH layer to add the ETH header, and moves the packet to the NIC_TX_QUEUE.
    302  * Finally, it updates the socket state, and release the socket lock.
    303295 ******************************************************************************************
    304296 * @ chdev    : [in] local pointer on one local NIC_TX[channel] chdev descriptor.
     
    331323
    332324/******************************************************************************************
    333  * This function displays all the fields of an ETH/IP/TCP segment or ETH/IP/UDP packet.
    334  ******************************************************************************************
    335  * @ is_tx   : [in] sent packet if true / received packet if false.
     325 * This debug function can be called by the dev_nic_tx_server() function to display
     326 * on TXT0 the header of a TX [ETH/IP/TCP] segment or [ETH/IP/UDP] packet.
     327 ******************************************************************************************
    336328 * @ pid     : [in] process identifier.
    337  * @ trdid   : [in] thread identifier.
     329 * @ fdid    : [in] socket identifier.
    338330 * @ cycle   : [in] date (number of cycles).
    339331 * @ buf     : [in] local pointer on kernel buffer containing the packet.
    340332 *****************************************************************************************/
    341 void dev_nic_packet_display( bool_t    is_tx,
    342                              pid_t     pid,
    343                              trdid_t   trdid,
     333void dev_nic_packet_display( pid_t     pid,
     334                             uint32_t  fdid,
    344335                             uint32_t  cycle,
    345336                             uint8_t * buf );
Note: See TracChangeset for help on using the changeset viewer.