## Automatically generated incremental diff
## From:   linux-2.2.17-pre8
## To:     linux-2.2.17-pre9
## Robot:  $Id: make-incremental-diff,v 1.8 2001/12/04 06:05:04 hpa Exp $

diff -urN linux-2.2.17-pre8/Makefile linux/Makefile
--- linux-2.2.17-pre8/Makefile	Mon Dec  3 22:07:47 2001
+++ linux/Makefile	Mon Dec  3 22:07:59 2001
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 2
 SUBLEVEL = 17
-EXTRAVERSION = pre8
+EXTRAVERSION = pre9
 
 ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
 
diff -urN linux-2.2.17-pre8/drivers/char/dtlk.c linux/drivers/char/dtlk.c
--- linux-2.2.17-pre8/drivers/char/dtlk.c	Fri Apr 16 08:20:23 1999
+++ linux/drivers/char/dtlk.c	Mon Dec  3 22:07:59 2001
@@ -272,14 +272,14 @@
 	}
 	/* there are no exception conditions */
 
-	if (mask == 0 && !dtlk_timer_active) {
+	{
 		/* not ready just yet.  There won't be any interrupts,
 		   so we set a timer instead. */
 		dtlk_timer_active = 1;
 		dtlk_timer.expires = jiffies + HZ / 100;
 		add_timer(&dtlk_timer);
 	}
-	return 0;
+	return mask;
 }
 
 static void dtlk_stop_timer()
@@ -295,11 +295,6 @@
 
 	wake_up_interruptible(&dtlk_process_list);
 
-	if (dtlk_timer_active) {
-		del_timer(&dtlk_timer);
-		dtlk_timer.expires = jiffies + HZ / 100;
-		add_timer(&dtlk_timer);
-	}
 }
 
 static int dtlk_ioctl(struct inode *inode,
diff -urN linux-2.2.17-pre8/drivers/char/misc.c linux/drivers/char/misc.c
--- linux-2.2.17-pre8/drivers/char/misc.c	Wed Jun  7 14:26:42 2000
+++ linux/drivers/char/misc.c	Mon Dec  3 22:07:59 2001
@@ -85,6 +85,7 @@
 extern void hfmodem_init(void);
 extern int pc110pad_init(void);
 extern int pmu_device_init(void);
+extern int tosh_init(void);
 
 static int misc_read_proc(char *buf, char **start, off_t offset,
 			  int len, int *eof, void *private)
@@ -277,6 +278,9 @@
 #endif
 #ifdef CONFIG_SGI
 	streamable_init ();
+#endif
+#ifdef CONFIG_TOSHIBA
+	tosh_init();
 #endif
 	if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
 		printk("unable to get major %d for misc devices\n",
diff -urN linux-2.2.17-pre8/drivers/net/eepro.c linux/drivers/net/eepro.c
--- linux-2.2.17-pre8/drivers/net/eepro.c	Wed Jun  7 14:26:43 2000
+++ linux/drivers/net/eepro.c	Mon Dec  3 22:07:59 2001
@@ -97,7 +97,7 @@
 */
 
 static const char *version =
-	"eepro.c: v0.12a 04/26/2000 aris@conectiva.com.br\n";
+	"eepro.c: v0.12b 04/26/2000 aris@conectiva.com.br\n";
 
 #include <linux/module.h>
 
@@ -523,6 +523,20 @@
 /* ack for tx int */
 #define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
 
+/* a complete sel reset */
+#define eepro_complete_selreset(ioaddr) { 	eepro_dis_int(ioaddr);\
+						lp->stats.tx_errors++;\
+						eepro_sel_reset(ioaddr);\
+						lp->tx_end = \
+							(XMT_LOWER_LIMIT << 8);\
+						lp->tx_start = lp->tx_end;\
+						lp->tx_last = 0;\
+						dev->trans_start = jiffies;\
+						netif_wake_queue(dev);\
+						eepro_en_int(ioaddr);\
+						eepro_en_rx(ioaddr);\
+					}
+
 /* Check for a network adaptor of this type, and return '0' if one exists.
    If dev->base_addr == 0, probe all likely locations.
    If dev->base_addr == 1, always return failure.
@@ -1574,9 +1588,6 @@
 	if (net_debug > 5)
 		printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
 
-	/* clear all interrupts */
-	eepro_clear_int(ioaddr);
-	
 	/* Set the read pointer to the start of the RCV */
 	outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
 	
@@ -1655,9 +1666,6 @@
 
 	if (net_debug > 5)
 		printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
-
-	/* enable tx/rx interrupts */
-	eepro_en_int(ioaddr);
 }
 
 static void
@@ -1754,6 +1762,12 @@
 		}
 		boguscount--;
 	}
+	/* if it reached here then it's probable that the adapter won't
+	 * interrupt again for tx. in other words: tx timeout what will take
+	 * a lot of time to happen, so we'll do a complete selreset.
+	 */
+	if (!boguscount)
+		eepro_complete_selreset(ioaddr);
 }
 
 #ifdef MODULE
diff -urN linux-2.2.17-pre8/drivers/scsi/sg.c linux/drivers/scsi/sg.c
--- linux-2.2.17-pre8/drivers/scsi/sg.c	Wed Jun  7 14:26:43 2000
+++ linux/drivers/scsi/sg.c	Mon Dec  3 22:07:59 2001
@@ -16,8 +16,8 @@
  *
  *  Borrows code from st driver. Thanks to Alessandro Rubini's "dd" book.
  */
- static char * sg_version_str = "Version: 2.1.38 (20000527)";
- static int sg_version_num = 20138; /* 2 digits for each component */
+ static char * sg_version_str = "Version: 2.1.39 (20000626)";
+ static int sg_version_num = 20139; /* 2 digits for each component */
 /*
  *  D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au), notes:
  *      - scsi logging is available via SCSI_LOG_TIMEOUT macros. First
@@ -1376,9 +1376,9 @@
     Sg_scatter_hold * req_schp = &srp->data;
     Sg_scatter_hold * rsv_schp = &sfp->reserve;
 
+    srp->res_used = 1;
     SCSI_LOG_TIMEOUT(4, printk("sg_link_reserve: size=%d\n", size)); 
-    /* round request up to next highest SG_SECTOR_SZ byte boundary */
-    size = (size + SG_SECTOR_MSK) & (~SG_SECTOR_MSK);
+    size = (size + 1) & (~1);   /* round to even for aha1542 */
     if (rsv_schp->use_sg > 0) {
         int k, num;
         int rem = size;
@@ -1387,22 +1387,26 @@
         for (k = 0; k < rsv_schp->use_sg; ++k, ++sclp) {
             num = (int)sclp->length;
             if (rem <= num) {
-                sfp->save_scat_len = num;
-                sclp->length = (unsigned)rem;
+                if (0 == k) {
+                    req_schp->use_sg = 0;
+                    req_schp->buffer = sclp->address;
+                }
+                else {
+                    sfp->save_scat_len = num;
+                    sclp->length = (unsigned)rem;
+                    req_schp->use_sg = k + 1;
+                    req_schp->sglist_len = rsv_schp->sglist_len;
+                    req_schp->buffer = rsv_schp->buffer;
+                }
+                req_schp->bufflen = size;
+                req_schp->mem_src = rsv_schp->mem_src;
+                req_schp->b_malloc_len = rsv_schp->b_malloc_len;
                 break;
             }
             else
                 rem -= num;
         }
-        if (k < rsv_schp->use_sg) {
-            req_schp->use_sg = k + 1;   /* adjust scatter list length */
-            req_schp->bufflen = size;
-            req_schp->sglist_len = rsv_schp->sglist_len;
-            req_schp->buffer = rsv_schp->buffer;
-            req_schp->mem_src = rsv_schp->mem_src;
-            req_schp->b_malloc_len = rsv_schp->b_malloc_len;
-        }
-        else
+        if (k >= rsv_schp->use_sg)
             SCSI_LOG_TIMEOUT(1, printk("sg_link_reserve: BAD size\n")); 
     }
     else {
@@ -1410,10 +1414,8 @@
         req_schp->bufflen = size;
         req_schp->buffer = rsv_schp->buffer;
         req_schp->mem_src = rsv_schp->mem_src;
-        req_schp->use_sg = rsv_schp->use_sg;
         req_schp->b_malloc_len = rsv_schp->b_malloc_len;
     }
-    srp->res_used = 1;
 }
 
 static void sg_unlink_reserve(Sg_fd * sfp, Sg_request * srp)
@@ -1423,7 +1425,7 @@
 
     SCSI_LOG_TIMEOUT(4, printk("sg_unlink_reserve: req->use_sg=%d\n",
                                (int)req_schp->use_sg)); 
-    if (rsv_schp->use_sg > 0) {
+    if ((rsv_schp->use_sg > 0) && (req_schp->use_sg > 0)) {
         struct scatterlist * sclp = (struct scatterlist *)rsv_schp->buffer;
 
         if (sfp->save_scat_len > 0) 
diff -urN linux-2.2.17-pre8/drivers/sound/cs46xx.c linux/drivers/sound/cs46xx.c
--- linux-2.2.17-pre8/drivers/sound/cs46xx.c	Mon Dec  3 22:07:48 2001
+++ linux/drivers/sound/cs46xx.c	Mon Dec  3 22:07:59 2001
@@ -2143,7 +2143,7 @@
 	 *  generating bit clock (so we don't try to start the PLL without an
 	 *  input clock).
 	 */
-	mdelay(1);
+	mdelay(5);		/* 1 should be enough ?? */
 
 	/*
 	 *  Set the serial port timing configuration, so that
@@ -2168,7 +2168,7 @@
 	/*
          *  Wait until the PLL has stabilized.
 	 */
-	mdelay(1);
+	mdelay(5);		/* Again 1 should be enough ?? */
 
 	/*
 	 *  Turn on clocking of the core so that we can setup the serial ports.
@@ -2194,6 +2194,9 @@
 	cs461x_pokeBA0(card, BA0_SERC2, SERC2_SI1F_AC97 | SERC1_SO1EN);
 	cs461x_pokeBA0(card, BA0_SERMC1, SERMC1_PTC_AC97 | SERMC1_MSPE);
 
+
+	mdelay(5);		/* Shouldnt be needed ?? */
+	
 	/*
 	 * Wait for the card ready signal from the AC97 card.
 	 */
@@ -2214,7 +2217,7 @@
 	 */
 	if (!(cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_CRDY)) {
 		printk(KERN_WARNING "cs461x: create - never read card ready from AC'97\n");
-		printk(KERN_WARNING "cs461x: it is not probably bug, try to use CS4236 driver\n");
+		printk(KERN_WARNING "cs461x: it is probably not a bug, try using the CS4232 driver\n");
 		return -EIO;
 	}
 
@@ -2297,6 +2300,8 @@
 	if (cs_ac97_init(card) <= 0)
 		return -EIO;
 		
+	mdelay(5);		/* Do we need this ?? */
+	
 	cs461x_powerup_adc(card);
 	cs461x_powerup_dac(card);
 
diff -urN linux-2.2.17-pre8/drivers/video/fbcon.c linux/drivers/video/fbcon.c
--- linux-2.2.17-pre8/drivers/video/fbcon.c	Wed Aug 25 17:29:49 1999
+++ linux/drivers/video/fbcon.c	Mon Dec  3 22:08:00 2001
@@ -526,7 +526,7 @@
     	q = (unsigned short *)(conp->vc_origin + conp->vc_size_row * old_rows);
     	step = logo_lines * old_cols;
     	for (r = q - logo_lines * old_cols; r < q; r++)
-    	    if (*r != conp->vc_video_erase_char)
+    	    if (scr_readw(r) != conp->vc_video_erase_char)
     	    	break;
 	if (r != q && nr_rows >= old_rows + logo_lines) {
     	    save = kmalloc(logo_lines * nr_cols * 2, GFP_KERNEL);
diff -urN linux-2.2.17-pre8/drivers/video/matroxfb.c linux/drivers/video/matroxfb.c
--- linux-2.2.17-pre8/drivers/video/matroxfb.c	Tue Jan  4 10:12:22 2000
+++ linux/drivers/video/matroxfb.c	Mon Dec  3 22:08:00 2001
@@ -4693,7 +4693,12 @@
 	}
 	display->var = *var;
 	/* cmap */
+#ifdef __alpha__
+	display->screen_base = vaddr_va(ACCESS_FBINFO(video.vbase)) + ydstorg
+		+ dense_mem(vaddr_va(ACCESS_FBINFO(video.vbase)));
+#else
 	display->screen_base = vaddr_va(ACCESS_FBINFO(video.vbase)) + ydstorg;
+#endif
 	display->visual = visual;
 	display->ypanstep = 1;
 	display->ywrapstep = 0;
diff -urN linux-2.2.17-pre8/drivers/video/pm2fb.c linux/drivers/video/pm2fb.c
--- linux-2.2.17-pre8/drivers/video/pm2fb.c	Tue Jan  4 10:12:22 2000
+++ linux/drivers/video/pm2fb.c	Mon Dec  3 22:08:00 2001
@@ -1272,7 +1272,13 @@
 }
 
 static struct display_switch pm2_cfb8 = {
-	fbcon_cfb8_setup, pm2fb_pp_bmove, pm2fb_clear8,
+	fbcon_cfb8_setup, pm2fb_pp_bmove,
+#ifdef __alpha__
+	/* No idea why, but pm2fb_clear8 does not always work on Alpha. */
+	fbcon_cfb8_clear,
+#else
+	pm2fb_clear8,
+#endif
 	fbcon_cfb8_putc, fbcon_cfb8_putcs, fbcon_cfb8_revc,
 	pm2fb_cursor, pm2fb_set_font,
 	pm2fb_clear_margins8,
@@ -1769,7 +1775,11 @@
 
 	save_flags(flags);
 	cli();
+#ifdef __alpha__
+	disp->screen_base=i->regions.v_fb + dense_mem(i->regions.v_fb);
+#else
 	disp->screen_base=i->regions.v_fb;
+#endif
 	switch (depth=((struct pm2fb_par* )par)->depth) {
 #ifdef FBCON_HAS_CFB8
 		case 8:
diff -urN linux-2.2.17-pre8/include/linux/telephony.h linux/include/linux/telephony.h
--- linux-2.2.17-pre8/include/linux/telephony.h	Mon Dec  3 22:07:48 2001
+++ linux/include/linux/telephony.h	Mon Dec  3 22:08:00 2001
@@ -14,7 +14,7 @@
  *    Authors:       Ed Okerson, <eokerson@quicknet.net>
  *                   Greg Herlein, <gherlein@quicknet.net>
  *
- *    Contributors:  Alan Cox, <acox@redhat.com>
+ *    Contributors:  Alan Cox, <alan@redhat.com>
  *                   David W. Erhart, <derhart@quicknet.net>
  *
  * Version:       0.1.0 - December 19, 1999
diff -urN linux-2.2.17-pre8/include/scsi/sg.h linux/include/scsi/sg.h
--- linux-2.2.17-pre8/include/scsi/sg.h	Wed Jun  7 14:26:44 2000
+++ linux/include/scsi/sg.h	Mon Dec  3 22:08:00 2001
@@ -11,10 +11,12 @@
 2.x extensions to driver:
 *       Copyright (C) 1998 - 2000 Douglas Gilbert
 
-    Version: 2.1.38 (20000527)
+    Version: 2.1.39 (20000626)
     This version for 2.2.x series kernels
     D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au)
 
+    Changes since 2.1.38 (20000527)
+        - more scatter gather fine tuning for sym53c416
     Changes since 2.1.37 (20000504)
         - fine tune state machine to stop read() race
         - switch to numeric device description (e.g. sg0 instead of sga)
diff -urN linux-2.2.17-pre8/net/ipv4/af_inet.c linux/net/ipv4/af_inet.c
--- linux-2.2.17-pre8/net/ipv4/af_inet.c	Wed May  3 17:16:53 2000
+++ linux/net/ipv4/af_inet.c	Mon Dec  3 22:08:00 2001
@@ -281,7 +281,8 @@
 	struct sock *sk = sock->sk;
 	unsigned char old_state;
 
-	if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM)
+	if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM ||
+	    !((1<<sk->state)&(TCPF_CLOSE|TCPF_LISTEN)))
 		return(-EINVAL);
 
 	if ((unsigned) backlog == 0)	/* BSDism */
@@ -699,9 +700,6 @@
 	sk2->socket = newsock;
 	newsk->socket = NULL;
 
-	if (flags & O_NONBLOCK)
-		goto do_half_success;
-
 	if(sk2->state == TCP_ESTABLISHED)
 		goto do_full_success;
 	if(sk2->err > 0)
@@ -713,10 +711,6 @@
 	destroy_sock(newsk);
 	newsock->state = SS_CONNECTED;
 	return 0;
-
-do_half_success:
-	destroy_sock(newsk);
-	return(0);
 
 do_connect_err:
 	err = sock_error(sk2);
diff -urN linux-2.2.17-pre8/net/ipv4/tcp_input.c linux/net/ipv4/tcp_input.c
--- linux-2.2.17-pre8/net/ipv4/tcp_input.c	Wed Jun  7 14:26:44 2000
+++ linux/net/ipv4/tcp_input.c	Mon Dec  3 22:08:00 2001
@@ -448,9 +448,6 @@
  */
 static __inline__ int tcp_fast_parse_options(struct sock *sk, struct tcphdr *th, struct tcp_opt *tp)
 {
-	/* If we didn't send out any options ignore them all. */
-	if (tp->tcp_header_len == sizeof(struct tcphdr))
-		return 0;
 	if (th->doff == sizeof(struct tcphdr)>>2) {
 		tp->saw_tstamp = 0;
 		return 0;
@@ -780,6 +777,7 @@
 		   u32 ack_seq, u32 ack, int len)
 {
 	struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
+	u32 nwin = ntohs(th->window) << tp->snd_wscale;
 	int flag = 0;
 	u32 seq = 0;
 	u32 seq_rtt = 0;
@@ -810,20 +808,21 @@
 	 * snd_wl{1,2} are used to prevent unordered
 	 * segments from shrinking the window 
 	 */
-	if (before(tp->snd_wl1, ack_seq) ||
-	    (tp->snd_wl1 == ack_seq && !after(tp->snd_wl2, ack))) {
-		u32 nwin = ntohs(th->window) << tp->snd_wscale;
-
-		if ((tp->snd_wl2 != ack) || (nwin > tp->snd_wnd)) {
-			flag |= FLAG_WIN_UPDATE;
-			tp->snd_wnd = nwin;
-
-			tp->snd_wl1 = ack_seq;
-			tp->snd_wl2 = ack;
-
-			if (nwin > tp->max_window)
-				tp->max_window = nwin;
-		}
+	if (after(ack_seq, tp->snd_wl1) ||
+	    (tp->snd_wl1 == ack_seq &&
+	     (after(ack, tp->snd_wl2) ||
+	      (tp->snd_wl2 == ack && nwin > tp->snd_wnd)))) {
+		flag |= FLAG_WIN_UPDATE;
+		tp->snd_wl1 = ack_seq;
+		tp->snd_wl2 = ack;
+		tp->snd_wnd = nwin;
+
+		if (nwin > tp->max_window)
+			tp->max_window = nwin;
+	} else if (after(ack, tp->snd_una)) {
+		/* Bad case. Window update is not accepted.
+		 * We will lockup. Break RFC to survive. */
+		tp->snd_wnd -= min(ack-tp->snd_una, tp->snd_wnd);
 	}
 
 	/* We passed data and got it acked, remove any soft error
diff -urN linux-2.2.17-pre8/net/ipv4/tcp_ipv4.c linux/net/ipv4/tcp_ipv4.c
--- linux-2.2.17-pre8/net/ipv4/tcp_ipv4.c	Mon Dec  3 22:07:49 2001
+++ linux/net/ipv4/tcp_ipv4.c	Mon Dec  3 22:08:00 2001
@@ -327,6 +327,11 @@
 {
 	struct sock **skp;
 
+	if (sk->pprev) {
+		printk("tcp_v4_hash: bug, socket state is %d\n", sk->state);
+		*(int *)0 = 0;
+	}
+
 	if(sk->state == TCP_LISTEN)
 		skp = &tcp_listening_hash[tcp_sk_listen_hashfn(sk)];
 	else
@@ -1366,6 +1371,8 @@
 
 		memcpy(newsk, sk, sizeof(*newsk));
 		newsk->sklist_next = NULL;
+		newsk->next = NULL;
+		newsk->pprev = NULL;
 		newsk->state = TCP_SYN_RECV;
 
 		/* Clone the TCP header template */
@@ -1571,24 +1578,28 @@
 	return NULL;
 }
 
-static void tcp_v4_rst_req(struct sock *sk, struct sk_buff *skb)
+static struct sock *tcp_v4_rst_req(struct sock *sk, struct sk_buff *skb)
 {
 	struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
 	struct open_request *req, *prev;
 
 	req = tcp_v4_search_req(tp,skb->nh.iph, skb->h.th, &prev);
 	if (!req)
-		return;
+		return NULL;
 	/* Sequence number check required by RFC793 */
 	if (before(TCP_SKB_CB(skb)->seq, req->rcv_isn) ||
 	    after(TCP_SKB_CB(skb)->seq, req->rcv_isn+1))
-		return;
+		return NULL;
+	if (req->sk)
+		return req->sk;
+
 	tcp_synq_unlink(tp, req, prev);
-	(req->sk ? sk->ack_backlog : tp->syn_backlog)--;
+	tp->syn_backlog--;
 	req->class->destructor(req);
 	tcp_openreq_free(req); 
 
 	net_statistics.EmbryonicRsts++;
+	return NULL;
 }
 
 /* Check for embryonic sockets (open_requests) We check packets with
@@ -1602,10 +1613,8 @@
 	u32 flg = ((u32 *)th)[3]; 
 
 	/* Check for RST */
-	if (flg & __constant_htonl(0x00040000)) {
-		tcp_v4_rst_req(sk, skb);
-		return NULL;
-	}
+	if (flg & __constant_htonl(0x00040000))
+		return tcp_v4_rst_req(sk, skb);
 
 	/* Check for SYN|ACK */
 	if (flg & __constant_htonl(0x00120000)) {
diff -urN linux-2.2.17-pre8/net/ipv4/tcp_output.c linux/net/ipv4/tcp_output.c
--- linux-2.2.17-pre8/net/ipv4/tcp_output.c	Wed Jun  7 14:26:44 2000
+++ linux/net/ipv4/tcp_output.c	Mon Dec  3 22:08:00 2001
@@ -63,6 +63,31 @@
 		tp->send_head = NULL;
 }
 
+static __inline__ u32 tcp_acceptable_seq(struct sock *sk)
+{
+	struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
+	struct sk_buff *skb;
+	u32 snd_nxt;
+
+	if (!before(tp->snd_una+tp->snd_wnd, tp->snd_nxt))
+		return tp->snd_nxt;
+
+	/* Umm... No better choice. The case is marginal, no hurry. */
+	skb = skb_peek(&sk->write_queue);
+
+	snd_nxt = tp->snd_una;
+	while((skb != NULL) &&
+	      (skb != tp->send_head) &&
+	      (skb != (struct sk_buff *)&sk->write_queue)) {
+		if (after(TCP_SKB_CB(skb)->end_seq, tp->snd_una+tp->snd_wnd))
+			break;
+		snd_nxt = TCP_SKB_CB(skb)->end_seq;
+		skb = skb->next;
+	}
+
+	return snd_nxt;
+}
+
 /* This routine actually transmits TCP packets queued in by
  * tcp_do_sendmsg().  This is used by both the initial
  * transmission and possible later retransmissions.
@@ -802,7 +827,7 @@
 	TCP_SKB_CB(skb)->urg_ptr = 0;
 
 	/* Send it off. */
-	TCP_SKB_CB(skb)->seq = tp->write_seq;
+	TCP_SKB_CB(skb)->seq = tcp_acceptable_seq(sk);
 	TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq;
 	TCP_SKB_CB(skb)->when = tcp_time_stamp;
 	tcp_transmit_skb(sk, skb);
@@ -1066,7 +1091,7 @@
 		TCP_SKB_CB(buff)->urg_ptr = 0;
 
 		/* Send it off, this clears delayed acks for us. */
-		TCP_SKB_CB(buff)->seq = TCP_SKB_CB(buff)->end_seq = tp->snd_nxt;
+		TCP_SKB_CB(buff)->seq = TCP_SKB_CB(buff)->end_seq = tcp_acceptable_seq(sk);
 		TCP_SKB_CB(buff)->when = tcp_time_stamp;
 		tcp_transmit_skb(sk, buff);
 	}
@@ -1091,15 +1116,15 @@
 		      TCPF_LAST_ACK|TCPF_CLOSING))
 			return;
 
-		if (before(tp->snd_nxt, tp->snd_una + tp->snd_wnd) &&
-		    ((skb = tp->send_head) != NULL)) {
+		if ((skb = tp->send_head) != NULL &&
+		    before(TCP_SKB_CB(skb)->seq, tp->snd_una+tp->snd_wnd)) {
 			unsigned long win_size;
 
 			/* We are probing the opening of a window
 			 * but the window size is != 0
 			 * must have been a result SWS avoidance ( sender )
 			 */
-			win_size = tp->snd_wnd - (tp->snd_nxt - tp->snd_una);
+			win_size = tp->snd_una+tp->snd_wnd - TCP_SKB_CB(skb)->seq;
 			if (win_size < TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq) {
 				if (tcp_fragment(sk, skb, win_size))
 					return; /* Let a retransmit get it. */
@@ -1129,7 +1154,7 @@
 			 * end to send an ack.  Don't queue or clone SKB, just
 			 * send it.
 			 */
-			TCP_SKB_CB(skb)->seq = tp->snd_nxt - 1;
+			TCP_SKB_CB(skb)->seq = tp->snd_una - 1;
 			TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq;
 			TCP_SKB_CB(skb)->when = tcp_time_stamp;
 			tcp_transmit_skb(sk, skb);
