Index: uspace/srv/net/tl/tcp/conn.c
===================================================================
--- uspace/srv/net/tl/tcp/conn.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/conn.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file TCP connection processing and state machine
  */
 
@@ -53,4 +53,10 @@
 static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg);
 
+/** Create new segment structure.
+ *
+ * @param lsock		Local socket (will be deeply copied)
+ * @param fsock		Foreign socket (will be deeply copied)
+ * @return		New segment or NULL
+ */
 tcp_conn_t *tcp_conn_new(tcp_sock_t *lsock, tcp_sock_t *fsock)
 {
@@ -85,4 +91,8 @@
 }
 
+/** Enlist connection.
+ *
+ * Add connection to the connection map.
+ */
 void tcp_conn_add(tcp_conn_t *conn)
 {
@@ -90,4 +100,9 @@
 }
 
+/** Synchronize connection.
+ *
+ * This is the first step of an active connection attempt,
+ * sends out SYN and sets up ISS and SND.xxx.
+ */
 void tcp_conn_sync(tcp_conn_t *conn)
 {
@@ -101,4 +116,9 @@
 }
 
+/** Compare two sockets.
+ *
+ * Two sockets are equal if the address is equal and the port number
+ * is equal.
+ */
 static bool tcp_socket_equal(tcp_sock_t *a, tcp_sock_t *b)
 {
@@ -117,4 +137,5 @@
 }
 
+/** Match socket with pattern. */
 static bool tcp_sockpair_match(tcp_sockpair_t *sp, tcp_sockpair_t *pattern)
 {
@@ -130,4 +151,12 @@
 }
 
+/** Find connection structure for specified socket pair.
+ *
+ * A connection is uniquely identified by a socket pair. Look up our
+ * connection map and return connection structure based on socket pair.
+ *
+ * @param sp	Socket pair
+ * @return	Connection structure or NULL if not found.
+ */
 tcp_conn_t *tcp_conn_find(tcp_sockpair_t *sp)
 {
@@ -144,4 +173,9 @@
 }
 
+/** Segment arrived in Listen state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ */
 static void tcp_conn_sa_listen(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -196,4 +230,9 @@
 }
 
+/** Segment arrived in Syn-Sent state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ */
 static void tcp_conn_sa_syn_sent(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -248,4 +287,11 @@
 }
 
+/** Segment arrived in state where segments are processed in sequence order.
+ *
+ * Queue segment in incoming segments queue for processing.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ */
 static void tcp_conn_sa_queue(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -269,4 +315,11 @@
 }
 
+/** Process segment RST field.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_rst(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -275,4 +328,11 @@
 }
 
+/** Process segment security and precedence fields.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_sp(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -281,4 +341,11 @@
 }
 
+/** Process segment SYN field.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_syn(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -287,4 +354,11 @@
 }
 
+/** Process segment ACK field in Syn-Received state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_sr(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -307,4 +381,11 @@
 }
 
+/** Process segment ACK field in Established state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_est(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -344,4 +425,11 @@
 }
 
+/** Process segment ACK field in Fin-Wait-1 state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_fw1(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -353,4 +441,11 @@
 }
 
+/** Process segment ACK field in Fin-Wait-2 state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_fw2(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -362,4 +457,11 @@
 }
 
+/** Process segment ACK field in Close-Wait state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_cw(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -368,4 +470,11 @@
 }
 
+/** Process segment ACK field in Closing state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_cls(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -377,4 +486,11 @@
 }
 
+/** Process segment ACK field in Last-Ack state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_la(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -386,4 +502,11 @@
 }
 
+/** Process segment ACK field in Time-Wait state.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack_tw(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -392,4 +515,11 @@
 }
 
+/** Process segment ACK field.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_ack(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -428,4 +558,11 @@
 }
 
+/** Process segment URG field.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_urg(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -433,5 +570,11 @@
 }
 
-/** Process segment text. */
+/** Process segment text.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_text(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -502,4 +645,11 @@
 }
 
+/** Process segment FIN field.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ * @return		cp_done if we are done with this segment, cp_continue
+ *			if not
+ */
 static cproc_t tcp_conn_seg_proc_fin(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -512,4 +662,7 @@
  * of sequence number. This processes one segment taken from the
  * connection incoming segments queue.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
  */
 static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg)
@@ -552,4 +705,9 @@
 }
 
+/** Segment arrived on a connection.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ */
 void tcp_conn_segment_arrived(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -576,4 +734,9 @@
 }
 
+/** Trim segment to the receive window.
+ *
+ * @param conn		Connection
+ * @param seg		Segment
+ */
 void tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg)
 {
@@ -584,4 +747,11 @@
 }
 
+/** Handle unexpected segment received on a socket pair.
+ *
+ * We reply with an RST unless the received segment has RST.
+ *
+ * @param sp		Socket pair which received the segment
+ * @param seg		Unexpected segment
+ */
 void tcp_unexpected_segment(tcp_sockpair_t *sp, tcp_segment_t *seg)
 {
@@ -592,4 +762,11 @@
 }
 
+/** Compute flipped socket pair for response.
+ *
+ * Flipped socket pair has local and foreign sockes exchanged.
+ *
+ * @param sp		Socket pair
+ * @param fsp		Place to store flipped socket pair
+ */
 void tcp_sockpair_flipped(tcp_sockpair_t *sp, tcp_sockpair_t *fsp)
 {
@@ -598,5 +775,9 @@
 }
 
-/** Send RST in response to an incoming segment. */
+/** Send RST in response to an incoming segment.
+ *
+ * @param sp		Socket pair which received the segment
+ * @param seg		Incoming segment
+ */
 void tcp_reply_rst(tcp_sockpair_t *sp, tcp_segment_t *seg)
 {
Index: uspace/srv/net/tl/tcp/conn.h
===================================================================
--- uspace/srv/net/tl/tcp/conn.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/conn.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file TCP connections
+/** @file TCP connection processing and state machine
  */
 
Index: uspace/srv/net/tl/tcp/header.c
===================================================================
--- uspace/srv/net/tl/tcp/header.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/header.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file TCP header encoding and decoding
  */
 
Index: uspace/srv/net/tl/tcp/header.h
===================================================================
--- uspace/srv/net/tl/tcp/header.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/header.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,7 +30,5 @@
  * @{
  */
-/** @file TCP header definitions
- *
- * Based on IETF RFC 793
+/** @file TCP header encoding and decoding
  */
 
Index: uspace/srv/net/tl/tcp/iqueue.c
===================================================================
--- uspace/srv/net/tl/tcp/iqueue.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/iqueue.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,7 @@
 
 /**
- * @file
+ * @file Connection incoming segments queue
+ *
+ * Segments are sorted in order of their sequence number.
  */
 
@@ -44,4 +46,9 @@
 #include "tcp_type.h"
 
+/** Initialize incoming segments queue.
+ *
+ * @param iqueue	Incoming queue
+ * @param conn		Connection the queue is associated with
+ */
 void tcp_iqueue_init(tcp_iqueue_t *iqueue, tcp_conn_t *conn)
 {
@@ -50,4 +57,9 @@
 }
 
+/** Insert segment into incoming queue.
+ *
+ * @param iqueue	Incoming queue
+ * @param seg		Segment
+ */
 void tcp_iqueue_insert_seg(tcp_iqueue_t *iqueue, tcp_segment_t *seg)
 {
@@ -67,4 +79,13 @@
 }
 
+/** Get next ready segment from incoming queue.
+ *
+ * Return the segment with the earliest sequence number if it is ready.
+ * A segment is ready if its SEG.SEQ is earlier or equal to RCV.NXT.
+ *
+ * @param iqueue	Incoming queue
+ * @param seg		Place to store pointer to segment
+ * @return		EOK on success, ENOENT if no segment is ready
+ */
 int tcp_iqueue_get_ready_seg(tcp_iqueue_t *iqueue, tcp_segment_t **seg)
 {
Index: uspace/srv/net/tl/tcp/rqueue.c
===================================================================
--- uspace/srv/net/tl/tcp/rqueue.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/rqueue.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file Global segment receive queue
  */
 
@@ -40,4 +40,5 @@
 #include <stdlib.h>
 #include <thread.h>
+#include "conn.h"
 #include "rqueue.h"
 #include "state.h"
@@ -46,4 +47,5 @@
 static prodcons_t rqueue;
 
+/** Initialize segment receive queue. */
 void tcp_rqueue_init(void)
 {
@@ -54,4 +56,7 @@
  *
  * This is for testing purposes only.
+ *
+ * @param sp	Socket pair, oriented for transmission
+ * @param seg	Segment
  */
 void tcp_rqueue_bounce_seg(tcp_sockpair_t *sp, tcp_segment_t *seg)
@@ -62,10 +67,14 @@
 
 	/* Reverse the identification */
-	rident.local = sp->foreign;
-	rident.foreign = sp->local;
+	tcp_sockpair_flipped(sp, &rident);
 
 	tcp_rqueue_insert_seg(&rident, seg);
 }
 
+/** Insert segment into receive queue.
+ *
+ * @param sp	Socket pair, oriented for reception
+ * @param seg	Segment
+ */
 void tcp_rqueue_insert_seg(tcp_sockpair_t *sp, tcp_segment_t *seg)
 {
@@ -85,4 +94,5 @@
 }
 
+/** Receive queue handler thread. */
 static void tcp_rqueue_thread(void *arg)
 {
@@ -100,4 +110,5 @@
 }
 
+/** Start receive queue handler thread. */
 void tcp_rqueue_thread_start(void)
 {
Index: uspace/srv/net/tl/tcp/rqueue.h
===================================================================
--- uspace/srv/net/tl/tcp/rqueue.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/rqueue.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file Global segment reception queue
+/** @file Global segment receive queue
  */
 
Index: uspace/srv/net/tl/tcp/segment.c
===================================================================
--- uspace/srv/net/tl/tcp/segment.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/segment.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file Segment processing
  */
 
@@ -41,4 +41,5 @@
 #include "tcp_type.h"
 
+/** Alocate new segment structure. */
 tcp_segment_t *tcp_segment_new(void)
 {
@@ -46,4 +47,5 @@
 }
 
+/** Delete segment. */
 void tcp_segment_delete(tcp_segment_t *seg)
 {
@@ -51,5 +53,8 @@
 }
 
-/** Create a control segment. */
+/** Create a control segment.
+ *
+  * @return	Control segment
+ */
 tcp_segment_t *tcp_segment_make_ctrl(tcp_control_t ctrl)
 {
@@ -66,4 +71,9 @@
 }
 
+/** Create an RST segment.
+ *
+ * @param seg	Segment we are replying to
+ * @return	RST segment
+ */
 tcp_segment_t *tcp_segment_make_rst(tcp_segment_t *seg)
 {
@@ -80,8 +90,13 @@
 }
 
-/** Trim segment to the specified interval.
+/** Trim segment from left and right by the specified amount.
  *
- * Trim any text or control whose sequence number is outside of [lo, hi)
- * interval.
+ * Trim any text or control to remove the specified amount of sequence
+ * numbers from the left (lower sequence numbers) and right side
+ * (higher sequence numbers) of the segment.
+ *
+ * @param seg		Segment, will be modified in place
+ * @param left		Amount of sequence numbers to trim from the left
+ * @param right		Amount of sequence numbers to trim from the right
  */
 void tcp_segment_trim(tcp_segment_t *seg, uint32_t left, uint32_t right)
@@ -134,4 +149,11 @@
 /** Copy out text data from segment.
  *
+ * Data is copied from the beginning of the segment text up to @a size bytes.
+ * @a size must not be greater than the size of the segment text, but
+ * it can be less.
+ *
+ * @param seg	Segment
+ * @param buf	Destination buffer
+ * @param size	Size of destination buffer
  */
 void tcp_segment_text_copy(tcp_segment_t *seg, void *buf, size_t size)
@@ -141,5 +163,9 @@
 }
 
-/** Return number of bytes in segment text. */
+/** Return number of bytes in segment text.
+ *
+ * @param seg	Segment
+ * @return	Number of bytes in segment text
+ */
 size_t tcp_segment_text_size(tcp_segment_t *seg)
 {
Index: uspace/srv/net/tl/tcp/segment.h
===================================================================
--- uspace/srv/net/tl/tcp/segment.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/segment.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file
+/** @file Segment processing
  */
 
Index: uspace/srv/net/tl/tcp/seq_no.c
===================================================================
--- uspace/srv/net/tl/tcp/seq_no.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/seq_no.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file Sequence number computations
  */
 
Index: uspace/srv/net/tl/tcp/seq_no.h
===================================================================
--- uspace/srv/net/tl/tcp/seq_no.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/seq_no.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file TCP sequence numbers
+/** @file Sequence number computations
  */
 
Index: uspace/srv/net/tl/tcp/state.c
===================================================================
--- uspace/srv/net/tl/tcp/state.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/state.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file TCP entry points (close to those defined in the RFC)
  */
 
Index: uspace/srv/net/tl/tcp/state.h
===================================================================
--- uspace/srv/net/tl/tcp/state.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/state.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file TCP state machine
+/** @file TCP entry points (close to those defined in the RFC)
  */
 
Index: uspace/srv/net/tl/tcp/tcp_type.h
===================================================================
--- uspace/srv/net/tl/tcp/tcp_type.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/tcp_type.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file
+/** @file TCP type definitions
  */
 
Index: uspace/srv/net/tl/tcp/test.c
===================================================================
--- uspace/srv/net/tl/tcp/test.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/test.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file Internal TCP test
  */
 
Index: uspace/srv/net/tl/tcp/test.h
===================================================================
--- uspace/srv/net/tl/tcp/test.h	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/test.h	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file
+/** @file Internal TCP test
  */
 
Index: uspace/srv/net/tl/tcp/tqueue.c
===================================================================
--- uspace/srv/net/tl/tcp/tqueue.c	(revision 0093ab6197b0d433bdcee794c4f447e8c8343015)
+++ uspace/srv/net/tl/tcp/tqueue.c	(revision 032bbe7a596e67983f2f901811ef9dd4defcd985)
@@ -32,5 +32,5 @@
 
 /**
- * @file
+ * @file TCP transmission queue
  */
 
