Commit 62a62049 authored by Linus Torvalds's avatar Linus Torvalds

Merge bk://ppc.bkbits.net/for-linus-ppc

into penguin.transmeta.com:/home/penguin/torvalds/repositories/kernel/linux
parents 67fa9ad1 4ee819e6
...@@ -18,7 +18,7 @@ export-objs := mca.o mtrr.o msr.o cpuid.o microcode.o i386_ksyms.o time.o ...@@ -18,7 +18,7 @@ export-objs := mca.o mtrr.o msr.o cpuid.o microcode.o i386_ksyms.o time.o
obj-y := process.o semaphore.o signal.o entry.o traps.o irq.o vm86.o \ obj-y := process.o semaphore.o signal.o entry.o traps.o irq.o vm86.o \
ptrace.o i8259.o ioport.o ldt.o setup.o time.o sys_i386.o \ ptrace.o i8259.o ioport.o ldt.o setup.o time.o sys_i386.o \
i386_ksyms.o i387.o bluesmoke.o dmi_scan.o \ pci-dma.o i386_ksyms.o i387.o bluesmoke.o dmi_scan.o \
bootflag.o bootflag.o
obj-$(CONFIG_MCA) += mca.o obj-$(CONFIG_MCA) += mca.o
......
O_TARGET := pci.o O_TARGET := pci.o
obj-y := dma.o i386.o obj-y := i386.o
ifdef CONFIG_VISWS ifdef CONFIG_VISWS
obj-y += visws.o obj-y += visws.o
......
...@@ -192,8 +192,7 @@ asmlinkage int sunos_brk(unsigned long brk) ...@@ -192,8 +192,7 @@ asmlinkage int sunos_brk(unsigned long brk)
* simple, it hopefully works in most obvious cases.. Easy to * simple, it hopefully works in most obvious cases.. Easy to
* fool it, but this should catch most mistakes. * fool it, but this should catch most mistakes.
*/ */
freepages = atomic_read(&buffermem_pages) >> PAGE_SHIFT; freepages = get_page_cache_size();
freepages += get_page_cache_size();
freepages >>= 1; freepages >>= 1;
freepages += nr_free_pages(); freepages += nr_free_pages();
freepages += nr_swap_pages; freepages += nr_swap_pages;
......
# $Id: Makefile,v 1.70 2002/02/09 19:49:30 davem Exp $ # $Id: Makefile,v 1.70 2002/02/09 19:49:30 davem Exp $
# Makefile for the linux kernel. # Makefile for the linux kernel.
# #
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here
# unless it's something special (ie not a .c file).
#
# Note 2! The CFLAGS definitions are now in the main makefile...
SH = $(CONFIG_SHELL) SH = $(CONFIG_SHELL)
.S.s: USE_STANDARD_AS_RULE := true
$(CPP) $(AFLAGS) -ansi $< -o $*.s EXTRA_AFLAGS := -ansi
.S.o:
$(CC) $(AFLAGS) -ansi -c $< -o $*.o
all: kernel.o head.o init_task.o all: kernel.o head.o init_task.o
......
...@@ -181,7 +181,7 @@ extern void rs_init(void); ...@@ -181,7 +181,7 @@ extern void rs_init(void);
extern void clock_probe(void); extern void clock_probe(void);
extern void power_init(void); extern void power_init(void);
void __init pcibios_init(void) static void __init pcibios_init(void)
{ {
pci_controller_probe(); pci_controller_probe();
if (pci_controller_root == NULL) if (pci_controller_root == NULL)
...@@ -199,6 +199,8 @@ void __init pcibios_init(void) ...@@ -199,6 +199,8 @@ void __init pcibios_init(void)
power_init(); power_init();
} }
subsys_initcall(pcibios_init);
struct pci_fixup pcibios_fixups[] = { struct pci_fixup pcibios_fixups[] = {
{ 0 } { 0 }
}; };
......
...@@ -411,6 +411,7 @@ void do_rt_sigreturn(struct pt_regs *regs) ...@@ -411,6 +411,7 @@ void do_rt_sigreturn(struct pt_regs *regs)
struct rt_signal_frame *sf; struct rt_signal_frame *sf;
unsigned long tpc, tnpc, tstate; unsigned long tpc, tnpc, tstate;
__siginfo_fpu_t *fpu_save; __siginfo_fpu_t *fpu_save;
mm_segment_t old_fs;
sigset_t set; sigset_t set;
stack_t st; stack_t st;
int err; int err;
...@@ -455,7 +456,10 @@ void do_rt_sigreturn(struct pt_regs *regs) ...@@ -455,7 +456,10 @@ void do_rt_sigreturn(struct pt_regs *regs)
/* It is more difficult to avoid calling this function than to /* It is more difficult to avoid calling this function than to
call it and ignore errors. */ call it and ignore errors. */
old_fs = get_fs();
set_fs(KERNEL_DS);
do_sigaltstack(&st, NULL, (unsigned long)sf); do_sigaltstack(&st, NULL, (unsigned long)sf);
set_fs(old_fs);
sigdelsetmask(&set, ~_BLOCKABLE); sigdelsetmask(&set, ~_BLOCKABLE);
spin_lock_irq(&current->sigmask_lock); spin_lock_irq(&current->sigmask_lock);
......
...@@ -396,6 +396,7 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs) ...@@ -396,6 +396,7 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
struct rt_signal_frame32 *sf; struct rt_signal_frame32 *sf;
unsigned int psr; unsigned int psr;
unsigned pc, npc, fpu_save; unsigned pc, npc, fpu_save;
mm_segment_t old_fs;
sigset_t set; sigset_t set;
sigset_t32 seta; sigset_t32 seta;
stack_t st; stack_t st;
...@@ -453,7 +454,10 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs) ...@@ -453,7 +454,10 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
/* It is more difficult to avoid calling this function than to /* It is more difficult to avoid calling this function than to
call it and ignore errors. */ call it and ignore errors. */
old_fs = get_fs();
set_fs(KERNEL_DS);
do_sigaltstack(&st, NULL, (unsigned long)sf); do_sigaltstack(&st, NULL, (unsigned long)sf);
set_fs(old_fs);
switch (_NSIG_WORDS) { switch (_NSIG_WORDS) {
case 4: set.sig[3] = seta.sig[6] + (((long)seta.sig[7]) << 32); case 4: set.sig[3] = seta.sig[6] + (((long)seta.sig[7]) << 32);
...@@ -1031,6 +1035,7 @@ svr4_getcontext(svr4_ucontext_t *uc, struct pt_regs *regs) ...@@ -1031,6 +1035,7 @@ svr4_getcontext(svr4_ucontext_t *uc, struct pt_regs *regs)
asmlinkage int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs) asmlinkage int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs)
{ {
svr4_gregset_t *gr; svr4_gregset_t *gr;
mm_segment_t old_fs;
u32 pc, npc, psr; u32 pc, npc, psr;
sigset_t set; sigset_t set;
svr4_sigset_t setv; svr4_sigset_t setv;
...@@ -1086,7 +1091,10 @@ asmlinkage int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs) ...@@ -1086,7 +1091,10 @@ asmlinkage int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs)
/* It is more difficult to avoid calling this function than to /* It is more difficult to avoid calling this function than to
call it and ignore errors. */ call it and ignore errors. */
old_fs = get_fs();
set_fs(KERNEL_DS);
do_sigaltstack(&st, NULL, regs->u_regs[UREG_I6]); do_sigaltstack(&st, NULL, regs->u_regs[UREG_I6]);
set_fs(old_fs);
sigdelsetmask(&set, ~_BLOCKABLE); sigdelsetmask(&set, ~_BLOCKABLE);
spin_lock_irq(&current->sigmask_lock); spin_lock_irq(&current->sigmask_lock);
......
...@@ -156,8 +156,7 @@ asmlinkage int sunos_brk(u32 baddr) ...@@ -156,8 +156,7 @@ asmlinkage int sunos_brk(u32 baddr)
* simple, it hopefully works in most obvious cases.. Easy to * simple, it hopefully works in most obvious cases.. Easy to
* fool it, but this should catch most mistakes. * fool it, but this should catch most mistakes.
*/ */
freepages = atomic_read(&buffermem_pages) >> PAGE_SHIFT; freepages = get_page_cache_size();
freepages += get_page_cache_size();
freepages >>= 1; freepages >>= 1;
freepages += nr_free_pages(); freepages += nr_free_pages();
freepages += nr_swap_pages; freepages += nr_swap_pages;
......
...@@ -2,13 +2,8 @@ ...@@ -2,13 +2,8 @@
# Makefile for Sparc64 library files.. # Makefile for Sparc64 library files..
# #
.S.s: USE_STANDARD_AS_RULE := true
$(CPP) $(AFLAGS) -ansi $< -o $*.s EXTRA_AFLAGS := -ansi
.S.o:
$(CC) $(AFLAGS) -ansi -c $< -o $*.o
CFLAGS := $(CFLAGS)
L_TARGET = lib.a L_TARGET = lib.a
obj-y := PeeCeeI.o blockops.o debuglocks.o strlen.o strncmp.o \ obj-y := PeeCeeI.o blockops.o debuglocks.o strlen.o strncmp.o \
......
# $Id: Makefile,v 1.8 2000/12/14 22:57:25 davem Exp $ # $Id: Makefile,v 1.8 2000/12/14 22:57:25 davem Exp $
# Makefile for the linux Sparc64-specific parts of the memory manager. # Makefile for the linux Sparc64-specific parts of the memory manager.
# #
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here
# unless it's something special (ie not a .c file).
#
# Note 2! The CFLAGS definition is now in the main makefile...
.S.s:
$(CPP) $(AFLAGS) -ansi $< -o $*.s
.S.o: USE_STANDARD_AS_RULE := true
$(CC) $(AFLAGS) -ansi -c $< -o $*.o EXTRA_AFLAGS := -ansi
O_TARGET := mm.o O_TARGET := mm.o
obj-y := ultra.o fault.o init.o generic.o extable.o modutil.o obj-y := ultra.o fault.o init.o generic.o extable.o modutil.o
......
...@@ -1704,7 +1704,7 @@ void __init mem_init(void) ...@@ -1704,7 +1704,7 @@ void __init mem_init(void)
max_mapnr = last_valid_pfn - pfn_base; max_mapnr = last_valid_pfn - pfn_base;
high_memory = __va(last_valid_pfn << PAGE_SHIFT); high_memory = __va(last_valid_pfn << PAGE_SHIFT);
num_physpages = free_all_bootmem() - 1; totalram_pages = num_physpages = free_all_bootmem() - 1;
/* /*
* Set up the zero page, mark it reserved, so that page count * Set up the zero page, mark it reserved, so that page count
...@@ -1737,6 +1737,7 @@ void __init mem_init(void) ...@@ -1737,6 +1737,7 @@ void __init mem_init(void)
addr += alias_base; addr += alias_base;
free_pgd_fast((pgd_t *)addr); free_pgd_fast((pgd_t *)addr);
num_physpages++; num_physpages++;
totalram_pages++;
} }
#endif #endif
...@@ -1773,6 +1774,7 @@ void free_initmem (void) ...@@ -1773,6 +1774,7 @@ void free_initmem (void)
set_page_count(p, 1); set_page_count(p, 1);
__free_page(p); __free_page(p);
num_physpages++; num_physpages++;
totalram_pages++;
} }
} }
...@@ -1788,6 +1790,7 @@ void free_initrd_mem(unsigned long start, unsigned long end) ...@@ -1788,6 +1790,7 @@ void free_initrd_mem(unsigned long start, unsigned long end)
set_page_count(p, 1); set_page_count(p, 1);
__free_page(p); __free_page(p);
num_physpages++; num_physpages++;
totalram_pages++;
} }
} }
#endif #endif
...@@ -2,22 +2,14 @@ ...@@ -2,22 +2,14 @@
# Makefile for the Sun Boot PROM interface library under # Makefile for the Sun Boot PROM interface library under
# Linux. # Linux.
# #
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here USE_STANDARD_AS_RULE := true
# unless it's something special (ie not a .c file). EXTRA_AFLAGS := -ansi
#
# Note 2! The CFLAGS definitions are now in the main makefile...
L_TARGET = promlib.a L_TARGET = promlib.a
obj-y := bootstr.o devops.o init.o memory.o misc.o \ obj-y := bootstr.o devops.o init.o memory.o misc.o \
tree.o console.o printf.o p1275.o map.o tree.o console.o printf.o p1275.o map.o
.S.s:
$(CPP) $(AFLAGS) -ansi $< -o $*.s
.S.o:
$(CC) $(AFLAGS) -ansi -c $< -o $*.o
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
%.o: %.c %.o: %.c
......
...@@ -2,16 +2,13 @@ ...@@ -2,16 +2,13 @@
# Makefile for the Solaris binary emulation. # Makefile for the Solaris binary emulation.
# #
USE_STANDARD_AS_RULE := true
EXTRA_AFLAGS := -ansi
ifeq ($(CONFIG_SOLARIS_EMUL),m) ifeq ($(CONFIG_SOLARIS_EMUL),m)
CPPFLAGS = $(MODFLAGS) EXTRA_AFLAGS += $(MODFLAGS)
endif endif
.S.s:
$(CPP) $(AFLAGS) $(CPPFLAGS) -ansi $< -o $*.s
.S.o:
$(CC) $(AFLAGS) $(CPPFLAGS) -ansi -c $< -o $*.o
solaris-objs := entry64.o fs.o misc.o signal.o systbl.o socket.o \ solaris-objs := entry64.o fs.o misc.o signal.o systbl.o socket.o \
ioctl.o ipc.o socksys.o timod.o ioctl.o ipc.o socksys.o timod.o
......
...@@ -3273,6 +3273,368 @@ static void serverworks_agp_enable(u32 mode) ...@@ -3273,6 +3273,368 @@ static void serverworks_agp_enable(u32 mode)
* AGP devices and collect their data. * AGP devices and collect their data.
*/ */
#ifdef CONFIG_AGP_HP_ZX1
#ifndef log2
#define log2(x) ffz(~(x))
#endif
#define HP_ZX1_IOVA_BASE GB(1UL)
#define HP_ZX1_IOVA_SIZE GB(1UL)
#define HP_ZX1_GART_SIZE (HP_ZX1_IOVA_SIZE / 2)
#define HP_ZX1_SBA_IOMMU_COOKIE 0x0000badbadc0ffeeUL
#define HP_ZX1_PDIR_VALID_BIT 0x8000000000000000UL
#define HP_ZX1_IOVA_TO_PDIR(va) ((va - hp_private.iova_base) >> \
hp_private.io_tlb_shift)
static aper_size_info_fixed hp_zx1_sizes[] =
{
{0, 0, 0}, /* filled in by hp_zx1_fetch_size() */
};
static gatt_mask hp_zx1_masks[] =
{
{HP_ZX1_PDIR_VALID_BIT, 0}
};
static struct _hp_private {
struct pci_dev *ioc;
volatile u8 *registers;
u64 *io_pdir; // PDIR for entire IOVA
u64 *gatt; // PDIR just for GART (subset of above)
u64 gatt_entries;
u64 iova_base;
u64 gart_base;
u64 gart_size;
u64 io_pdir_size;
int io_pdir_owner; // do we own it, or share it with sba_iommu?
int io_page_size;
int io_tlb_shift;
int io_tlb_ps; // IOC ps config
int io_pages_per_kpage;
} hp_private;
static int __init hp_zx1_ioc_shared(void)
{
struct _hp_private *hp = &hp_private;
printk(KERN_INFO PFX "HP ZX1 IOC: IOPDIR shared with sba_iommu\n");
/*
* IOC already configured by sba_iommu module; just use
* its setup. We assume:
* - IOVA space is 1Gb in size
* - first 512Mb is IOMMU, second 512Mb is GART
*/
hp->io_tlb_ps = INREG64(hp->registers, HP_ZX1_TCNFG);
switch (hp->io_tlb_ps) {
case 0: hp->io_tlb_shift = 12; break;
case 1: hp->io_tlb_shift = 13; break;
case 2: hp->io_tlb_shift = 14; break;
case 3: hp->io_tlb_shift = 16; break;
default:
printk(KERN_ERR PFX "Invalid IOTLB page size "
"configuration 0x%x\n", hp->io_tlb_ps);
hp->gatt = 0;
hp->gatt_entries = 0;
return -ENODEV;
}
hp->io_page_size = 1 << hp->io_tlb_shift;
hp->io_pages_per_kpage = PAGE_SIZE / hp->io_page_size;
hp->iova_base = INREG64(hp->registers, HP_ZX1_IBASE) & ~0x1;
hp->gart_base = hp->iova_base + HP_ZX1_IOVA_SIZE - HP_ZX1_GART_SIZE;
hp->gart_size = HP_ZX1_GART_SIZE;
hp->gatt_entries = hp->gart_size / hp->io_page_size;
hp->io_pdir = phys_to_virt(INREG64(hp->registers, HP_ZX1_PDIR_BASE));
hp->gatt = &hp->io_pdir[HP_ZX1_IOVA_TO_PDIR(hp->gart_base)];
if (hp->gatt[0] != HP_ZX1_SBA_IOMMU_COOKIE) {
hp->gatt = 0;
hp->gatt_entries = 0;
printk(KERN_ERR PFX "No reserved IO PDIR entry found; "
"GART disabled\n");
return -ENODEV;
}
return 0;
}
static int __init hp_zx1_ioc_owner(u8 ioc_rev)
{
struct _hp_private *hp = &hp_private;
printk(KERN_INFO PFX "HP ZX1 IOC: IOPDIR dedicated to GART\n");
/*
* Select an IOV page size no larger than system page size.
*/
if (PAGE_SIZE >= KB(64)) {
hp->io_tlb_shift = 16;
hp->io_tlb_ps = 3;
} else if (PAGE_SIZE >= KB(16)) {
hp->io_tlb_shift = 14;
hp->io_tlb_ps = 2;
} else if (PAGE_SIZE >= KB(8)) {
hp->io_tlb_shift = 13;
hp->io_tlb_ps = 1;
} else {
hp->io_tlb_shift = 12;
hp->io_tlb_ps = 0;
}
hp->io_page_size = 1 << hp->io_tlb_shift;
hp->io_pages_per_kpage = PAGE_SIZE / hp->io_page_size;
hp->iova_base = HP_ZX1_IOVA_BASE;
hp->gart_size = HP_ZX1_GART_SIZE;
hp->gart_base = hp->iova_base + HP_ZX1_IOVA_SIZE - hp->gart_size;
hp->gatt_entries = hp->gart_size / hp->io_page_size;
hp->io_pdir_size = (HP_ZX1_IOVA_SIZE / hp->io_page_size) * sizeof(u64);
return 0;
}
static int __init hp_zx1_ioc_init(void)
{
struct _hp_private *hp = &hp_private;
struct pci_dev *ioc;
int i;
u8 ioc_rev;
ioc = pci_find_device(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_ZX1_IOC, NULL);
if (!ioc) {
printk(KERN_ERR PFX "Detected HP ZX1 AGP bridge but no IOC\n");
return -ENODEV;
}
hp->ioc = ioc;
pci_read_config_byte(ioc, PCI_REVISION_ID, &ioc_rev);
for (i = 0; i < PCI_NUM_RESOURCES; i++) {
if (pci_resource_flags(ioc, i) == IORESOURCE_MEM) {
hp->registers = (u8 *) ioremap(pci_resource_start(ioc,
i),
pci_resource_len(ioc, i));
break;
}
}
if (!hp->registers) {
printk(KERN_ERR PFX "Detected HP ZX1 AGP bridge but no CSRs\n");
return -ENODEV;
}
/*
* If the IOTLB is currently disabled, we can take it over.
* Otherwise, we have to share with sba_iommu.
*/
hp->io_pdir_owner = (INREG64(hp->registers, HP_ZX1_IBASE) & 0x1) == 0;
if (hp->io_pdir_owner)
return hp_zx1_ioc_owner(ioc_rev);
return hp_zx1_ioc_shared();
}
static int hp_zx1_fetch_size(void)
{
int size;
size = hp_private.gart_size / MB(1);
hp_zx1_sizes[0].size = size;
agp_bridge.current_size = (void *) &hp_zx1_sizes[0];
return size;
}
static int hp_zx1_configure(void)
{
struct _hp_private *hp = &hp_private;
agp_bridge.gart_bus_addr = hp->gart_base;
agp_bridge.capndx = pci_find_capability(agp_bridge.dev, PCI_CAP_ID_AGP);
pci_read_config_dword(agp_bridge.dev,
agp_bridge.capndx + PCI_AGP_STATUS, &agp_bridge.mode);
if (hp->io_pdir_owner) {
OUTREG64(hp->registers, HP_ZX1_PDIR_BASE,
virt_to_phys(hp->io_pdir));
OUTREG64(hp->registers, HP_ZX1_TCNFG, hp->io_tlb_ps);
OUTREG64(hp->registers, HP_ZX1_IMASK, ~(HP_ZX1_IOVA_SIZE - 1));
OUTREG64(hp->registers, HP_ZX1_IBASE, hp->iova_base | 0x1);
OUTREG64(hp->registers, HP_ZX1_PCOM,
hp->iova_base | log2(HP_ZX1_IOVA_SIZE));
INREG64(hp->registers, HP_ZX1_PCOM);
}
return 0;
}
static void hp_zx1_cleanup(void)
{
struct _hp_private *hp = &hp_private;
if (hp->io_pdir_owner)
OUTREG64(hp->registers, HP_ZX1_IBASE, 0);
iounmap((void *) hp->registers);
}
static void hp_zx1_tlbflush(agp_memory * mem)
{
struct _hp_private *hp = &hp_private;
OUTREG64(hp->registers, HP_ZX1_PCOM,
hp->gart_base | log2(hp->gart_size));
INREG64(hp->registers, HP_ZX1_PCOM);
}
static int hp_zx1_create_gatt_table(void)
{
struct _hp_private *hp = &hp_private;
int i;
if (hp->io_pdir_owner) {
hp->io_pdir = (u64 *) __get_free_pages(GFP_KERNEL,
get_order(hp->io_pdir_size));
if (!hp->io_pdir) {
printk(KERN_ERR PFX "Couldn't allocate contiguous "
"memory for I/O PDIR\n");
hp->gatt = 0;
hp->gatt_entries = 0;
return -ENOMEM;
}
memset(hp->io_pdir, 0, hp->io_pdir_size);
hp->gatt = &hp->io_pdir[HP_ZX1_IOVA_TO_PDIR(hp->gart_base)];
}
for (i = 0; i < hp->gatt_entries; i++) {
hp->gatt[i] = (unsigned long) agp_bridge.scratch_page;
}
return 0;
}
static int hp_zx1_free_gatt_table(void)
{
struct _hp_private *hp = &hp_private;
if (hp->io_pdir_owner)
free_pages((unsigned long) hp->io_pdir,
get_order(hp->io_pdir_size));
else
hp->gatt[0] = HP_ZX1_SBA_IOMMU_COOKIE;
return 0;
}
static int hp_zx1_insert_memory(agp_memory * mem, off_t pg_start, int type)
{
struct _hp_private *hp = &hp_private;
int i, k;
off_t j, io_pg_start;
int io_pg_count;
if (type != 0 || mem->type != 0) {
return -EINVAL;
}
io_pg_start = hp->io_pages_per_kpage * pg_start;
io_pg_count = hp->io_pages_per_kpage * mem->page_count;
if ((io_pg_start + io_pg_count) > hp->gatt_entries) {
return -EINVAL;
}
j = io_pg_start;
while (j < (io_pg_start + io_pg_count)) {
if (hp->gatt[j]) {
return -EBUSY;
}
j++;
}
if (mem->is_flushed == FALSE) {
CACHE_FLUSH();
mem->is_flushed = TRUE;
}
for (i = 0, j = io_pg_start; i < mem->page_count; i++) {
unsigned long paddr;
paddr = mem->memory[i];
for (k = 0;
k < hp->io_pages_per_kpage;
k++, j++, paddr += hp->io_page_size) {
hp->gatt[j] = agp_bridge.mask_memory(paddr, type);
}
}
agp_bridge.tlb_flush(mem);
return 0;
}
static int hp_zx1_remove_memory(agp_memory * mem, off_t pg_start, int type)
{
struct _hp_private *hp = &hp_private;
int i, io_pg_start, io_pg_count;
if (type != 0 || mem->type != 0) {
return -EINVAL;
}
io_pg_start = hp->io_pages_per_kpage * pg_start;
io_pg_count = hp->io_pages_per_kpage * mem->page_count;
for (i = io_pg_start; i < io_pg_count + io_pg_start; i++) {
hp->gatt[i] = agp_bridge.scratch_page;
}
agp_bridge.tlb_flush(mem);
return 0;
}
static unsigned long hp_zx1_mask_memory(unsigned long addr, int type)
{
return HP_ZX1_PDIR_VALID_BIT | addr;
}
static unsigned long hp_zx1_unmask_memory(unsigned long addr)
{
return addr & ~(HP_ZX1_PDIR_VALID_BIT);
}
static int __init hp_zx1_setup (struct pci_dev *pdev)
{
agp_bridge.masks = hp_zx1_masks;
agp_bridge.num_of_masks = 1;
agp_bridge.dev_private_data = NULL;
agp_bridge.size_type = FIXED_APER_SIZE;
agp_bridge.needs_scratch_page = FALSE;
agp_bridge.configure = hp_zx1_configure;
agp_bridge.fetch_size = hp_zx1_fetch_size;
agp_bridge.cleanup = hp_zx1_cleanup;
agp_bridge.tlb_flush = hp_zx1_tlbflush;
agp_bridge.mask_memory = hp_zx1_mask_memory;
agp_bridge.unmask_memory = hp_zx1_unmask_memory;
agp_bridge.agp_enable = agp_generic_agp_enable;
agp_bridge.cache_flush = global_cache_flush;
agp_bridge.create_gatt_table = hp_zx1_create_gatt_table;
agp_bridge.free_gatt_table = hp_zx1_free_gatt_table;
agp_bridge.insert_memory = hp_zx1_insert_memory;
agp_bridge.remove_memory = hp_zx1_remove_memory;
agp_bridge.alloc_by_type = agp_generic_alloc_by_type;
agp_bridge.free_by_type = agp_generic_free_by_type;
agp_bridge.agp_alloc_page = agp_generic_alloc_page;
agp_bridge.agp_destroy_page = agp_generic_destroy_page;
agp_bridge.cant_use_aperture = 1;
return hp_zx1_ioc_init();
(void) pdev; /* unused */
}
#endif /* CONFIG_AGP_HP_ZX1 */
pci_for_each_dev(device) { pci_for_each_dev(device) {
cap_ptr = pci_find_capability(device, PCI_CAP_ID_AGP); cap_ptr = pci_find_capability(device, PCI_CAP_ID_AGP);
...@@ -4087,6 +4449,15 @@ intel_850_setup }, ...@@ -4087,6 +4449,15 @@ intel_850_setup },
via_generic_setup }, via_generic_setup },
#endif /* CONFIG_AGP_VIA */ #endif /* CONFIG_AGP_VIA */
#ifdef CONFIG_AGP_HP_ZX1
{ PCI_DEVICE_ID_HP_ZX1_LBA,
PCI_VENDOR_ID_HP,
HP_ZX1,
"HP",
"ZX1",
hp_zx1_setup },
#endif
#ifdef CONFIG_AGP_HP_ZX1 #ifdef CONFIG_AGP_HP_ZX1
{ PCI_DEVICE_ID_HP_ZX1_LBA, { PCI_DEVICE_ID_HP_ZX1_LBA,
PCI_VENDOR_ID_HP, PCI_VENDOR_ID_HP,
...@@ -4320,6 +4691,23 @@ static int __init agp_find_supported_device(void) ...@@ -4320,6 +4691,23 @@ static int __init agp_find_supported_device(void)
#endif /* CONFIG_AGP_SWORKS */ #endif /* CONFIG_AGP_SWORKS */
#ifdef CONFIG_AGP_HP_ZX1
if (dev->vendor == PCI_VENDOR_ID_HP) {
do {
/* ZX1 LBAs can be either PCI or AGP bridges */
if (pci_find_capability(dev, PCI_CAP_ID_AGP)) {
printk(KERN_INFO PFX "Detected HP ZX1 AGP "
"chipset at %s\n", dev->slot_name);
agp_bridge.type = HP_ZX1;
agp_bridge.dev = dev;
return hp_zx1_setup(dev);
}
dev = pci_find_class(PCI_CLASS_BRIDGE_HOST << 8, dev);
} while (dev);
return -ENODEV;
}
#endif /* CONFIG_AGP_HP_ZX1 */
#ifdef CONFIG_AGP_HP_ZX1 #ifdef CONFIG_AGP_HP_ZX1
if (dev->vendor == PCI_VENDOR_ID_HP) { if (dev->vendor == PCI_VENDOR_ID_HP) {
do { do {
......
...@@ -317,6 +317,8 @@ drm_agp_head_t *DRM(agp_init)(void) ...@@ -317,6 +317,8 @@ drm_agp_head_t *DRM(agp_init)(void)
break; break;
#endif #endif
case HP_ZX1: head->chipset = "HP ZX1"; break;
default: head->chipset = "Unknown"; break; default: head->chipset = "Unknown"; break;
} }
#if LINUX_VERSION_CODE <= 0x020408 #if LINUX_VERSION_CODE <= 0x020408
......
...@@ -2692,7 +2692,7 @@ ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr, ...@@ -2692,7 +2692,7 @@ ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr,
flagsize &= ~BD_FLG_COAL_NOW; flagsize &= ~BD_FLG_COAL_NOW;
#endif #endif
if (!ACE_IS_TIGON_I(ap)) { if (ACE_IS_TIGON_I(ap)) {
writel(addr >> 32, &desc->addr.addrhi); writel(addr >> 32, &desc->addr.addrhi);
writel(addr & 0xffffffff, &desc->addr.addrlo); writel(addr & 0xffffffff, &desc->addr.addrlo);
writel(flagsize, &desc->flagsize); writel(flagsize, &desc->flagsize);
......
...@@ -1211,7 +1211,7 @@ static int tg3_fiber_aneg_smachine(struct tg3 *tp, ...@@ -1211,7 +1211,7 @@ static int tg3_fiber_aneg_smachine(struct tg3 *tp,
if (ap->rxconfig & ANEG_CFG_FD) if (ap->rxconfig & ANEG_CFG_FD)
ap->flags |= MR_LP_ADV_FULL_DUPLEX; ap->flags |= MR_LP_ADV_FULL_DUPLEX;
if (ap->rxconfig & ANEG_CFG_HD) if (ap->rxconfig & ANEG_CFG_HD)
ap->flags |= MR_LP_ADV_FULL_DUPLEX; ap->flags |= MR_LP_ADV_HALF_DUPLEX;
if (ap->rxconfig & ANEG_CFG_PS1) if (ap->rxconfig & ANEG_CFG_PS1)
ap->flags |= MR_LP_ADV_SYM_PAUSE; ap->flags |= MR_LP_ADV_SYM_PAUSE;
if (ap->rxconfig & ANEG_CFG_PS2) if (ap->rxconfig & ANEG_CFG_PS2)
......
...@@ -29,7 +29,7 @@ obj-$(CONFIG_ALPHA) += setup-bus.o setup-irq.o ...@@ -29,7 +29,7 @@ obj-$(CONFIG_ALPHA) += setup-bus.o setup-irq.o
obj-$(CONFIG_ARM) += setup-bus.o setup-irq.o obj-$(CONFIG_ARM) += setup-bus.o setup-irq.o
obj-$(CONFIG_PARISC) += setup-bus.o obj-$(CONFIG_PARISC) += setup-bus.o
obj-$(CONFIG_SUPERH) += setup-bus.o setup-irq.o obj-$(CONFIG_SUPERH) += setup-bus.o setup-irq.o
obj-$(CONFIG_ALL_PPC) += setup-bus.o obj-$(CONFIG_PPC32) += setup-irq.o
obj-$(CONFIG_DDB5476) += setup-bus.o obj-$(CONFIG_DDB5476) += setup-bus.o
obj-$(CONFIG_SGI_IP27) += setup-irq.o obj-$(CONFIG_SGI_IP27) += setup-irq.o
......
...@@ -129,7 +129,7 @@ static void sd_rw_intr(Scsi_Cmnd * SCpnt); ...@@ -129,7 +129,7 @@ static void sd_rw_intr(Scsi_Cmnd * SCpnt);
static Scsi_Disk * sd_get_sdisk(int index); static Scsi_Disk * sd_get_sdisk(int index);
#if defined(CONFIG_PPC) #if defined(CONFIG_PPC32)
/** /**
* sd_find_target - find kdev_t of first scsi disk that matches * sd_find_target - find kdev_t of first scsi disk that matches
* given host and scsi_id. * given host and scsi_id.
...@@ -149,7 +149,7 @@ sd_find_target(void *hp, int scsi_id) ...@@ -149,7 +149,7 @@ sd_find_target(void *hp, int scsi_id)
{ {
Scsi_Disk *sdkp; Scsi_Disk *sdkp;
Scsi_Device *sdp; Scsi_Device *sdp;
Scsi_Host *shp = hp; struct Scsi_Host *shp = hp;
int dsk_nr; int dsk_nr;
unsigned long iflags; unsigned long iflags;
...@@ -162,7 +162,7 @@ sd_find_target(void *hp, int scsi_id) ...@@ -162,7 +162,7 @@ sd_find_target(void *hp, int scsi_id)
sdp = sdkp->device; sdp = sdkp->device;
if (sdp && (sdp->host == shp) && (sdp->id == scsi_id)) { if (sdp && (sdp->host == shp) && (sdp->id == scsi_id)) {
read_unlock_irqrestore(&sd_dsk_arr_lock, iflags); read_unlock_irqrestore(&sd_dsk_arr_lock, iflags);
return MKDEV_SD(k); return MKDEV_SD(dsk_nr);
} }
} }
read_unlock_irqrestore(&sd_dsk_arr_lock, iflags); read_unlock_irqrestore(&sd_dsk_arr_lock, iflags);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/devfs_fs_kernel.h> #include <linux/devfs_fs_kernel.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/init.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
/* Version Information */ /* Version Information */
......
...@@ -38,60 +38,74 @@ static void redo_inode_mask(struct inode *inode) ...@@ -38,60 +38,74 @@ static void redo_inode_mask(struct inode *inode)
inode->i_dnotify_mask = new_mask; inode->i_dnotify_mask = new_mask;
} }
void dnotify_flush(struct file *filp, fl_owner_t id)
{
struct dnotify_struct *dn;
struct dnotify_struct **prev;
struct inode *inode;
inode = filp->f_dentry->d_inode;
if (!S_ISDIR(inode->i_mode))
return;
write_lock(&dn_lock);
prev = &inode->i_dnotify;
while ((dn = *prev) != NULL) {
if ((dn->dn_owner == id) && (dn->dn_filp == filp)) {
*prev = dn->dn_next;
redo_inode_mask(inode);
kmem_cache_free(dn_cache, dn);
break;
}
prev = &dn->dn_next;
}
write_unlock(&dn_lock);
}
int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
{ {
struct dnotify_struct *dn = NULL; struct dnotify_struct *dn;
struct dnotify_struct *odn; struct dnotify_struct *odn;
struct dnotify_struct **prev; struct dnotify_struct **prev;
struct inode *inode; struct inode *inode;
int turning_off = (arg & ~DN_MULTISHOT) == 0; fl_owner_t id = current->files;
if (!turning_off && !dir_notify_enable) if ((arg & ~DN_MULTISHOT) == 0) {
dnotify_flush(filp, id);
return 0;
}
if (!dir_notify_enable)
return -EINVAL; return -EINVAL;
inode = filp->f_dentry->d_inode; inode = filp->f_dentry->d_inode;
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
return -ENOTDIR; return -ENOTDIR;
if (!turning_off) { dn = kmem_cache_alloc(dn_cache, SLAB_KERNEL);
dn = kmem_cache_alloc(dn_cache, SLAB_KERNEL); if (dn == NULL)
if (dn == NULL) return -ENOMEM;
return -ENOMEM;
}
write_lock(&dn_lock); write_lock(&dn_lock);
prev = &inode->i_dnotify; prev = &inode->i_dnotify;
for (odn = *prev; odn != NULL; prev = &odn->dn_next, odn = *prev) while ((odn = *prev) != NULL) {
if ((odn->dn_owner == current->files) && (odn->dn_filp == filp)) if ((odn->dn_owner == id) && (odn->dn_filp == filp)) {
break; odn->dn_fd = fd;
if (odn != NULL) { odn->dn_mask |= arg;
if (turning_off) { inode->i_dnotify_mask |= arg & ~DN_MULTISHOT;
*prev = odn->dn_next; kmem_cache_free(dn_cache, dn);
redo_inode_mask(inode); goto out;
dn = odn;
goto out_free;
} }
odn->dn_fd = fd; prev = &odn->dn_next;
odn->dn_mask |= arg;
inode->i_dnotify_mask |= arg & ~DN_MULTISHOT;
goto out_free;
} }
if (turning_off)
goto out;
filp->f_owner.pid = current->pid; filp->f_owner.pid = current->pid;
filp->f_owner.uid = current->uid; filp->f_owner.uid = current->uid;
filp->f_owner.euid = current->euid; filp->f_owner.euid = current->euid;
dn->dn_magic = DNOTIFY_MAGIC;
dn->dn_mask = arg; dn->dn_mask = arg;
dn->dn_fd = fd; dn->dn_fd = fd;
dn->dn_filp = filp; dn->dn_filp = filp;
dn->dn_owner = current->files; dn->dn_owner = id;
inode->i_dnotify_mask |= arg & ~DN_MULTISHOT; inode->i_dnotify_mask |= arg & ~DN_MULTISHOT;
dn->dn_next = inode->i_dnotify; dn->dn_next = inode->i_dnotify;
inode->i_dnotify = dn; inode->i_dnotify = dn;
out: out:
write_unlock(&dn_lock); write_unlock(&dn_lock);
return 0; return 0;
out_free:
kmem_cache_free(dn_cache, dn);
goto out;
} }
void __inode_dir_notify(struct inode *inode, unsigned long event) void __inode_dir_notify(struct inode *inode, unsigned long event)
...@@ -104,11 +118,6 @@ void __inode_dir_notify(struct inode *inode, unsigned long event) ...@@ -104,11 +118,6 @@ void __inode_dir_notify(struct inode *inode, unsigned long event)
write_lock(&dn_lock); write_lock(&dn_lock);
prev = &inode->i_dnotify; prev = &inode->i_dnotify;
while ((dn = *prev) != NULL) { while ((dn = *prev) != NULL) {
if (dn->dn_magic != DNOTIFY_MAGIC) {
printk(KERN_ERR "__inode_dir_notify: bad magic "
"number in dnotify_struct!\n");
goto out;
}
if ((dn->dn_mask & event) == 0) { if ((dn->dn_mask & event) == 0) {
prev = &dn->dn_next; prev = &dn->dn_next;
continue; continue;
......
...@@ -1385,6 +1385,35 @@ int lmLogClose(struct super_block *sb, log_t * log) ...@@ -1385,6 +1385,35 @@ int lmLogClose(struct super_block *sb, log_t * log)
} }
/*
* NAME: lmLogWait()
*
* FUNCTION: wait for all outstanding log records to be written to disk
*/
void lmLogWait(log_t *log)
{
int i;
jFYI(1, ("lmLogWait: log:0x%p\n", log));
if (log->cqueue.head || !list_empty(&log->synclist)) {
/*
* If there was very recent activity, we may need to wait
* for the lazycommit thread to catch up
*/
for (i = 0; i < 800; i++) { /* Too much? */
current->state = TASK_INTERRUPTIBLE;
schedule_timeout(HZ / 4);
if ((log->cqueue.head == NULL) &&
list_empty(&log->synclist))
break;
}
}
assert(log->cqueue.head == NULL);
assert(list_empty(&log->synclist));
}
/* /*
* NAME: lmLogShutdown() * NAME: lmLogShutdown()
* *
...@@ -1411,23 +1440,7 @@ static int lmLogShutdown(log_t * log) ...@@ -1411,23 +1440,7 @@ static int lmLogShutdown(log_t * log)
jFYI(1, ("lmLogShutdown: log:0x%p\n", log)); jFYI(1, ("lmLogShutdown: log:0x%p\n", log));
if (log->cqueue.head || !list_empty(&log->synclist)) { lmLogWait(log);
/*
* If there was very recent activity, we may need to wait
* for the lazycommit thread to catch up
*/
int i;
for (i = 0; i < 800; i++) { /* Too much? */
current->state = TASK_INTERRUPTIBLE;
schedule_timeout(HZ / 4);
if ((log->cqueue.head == NULL) &&
list_empty(&log->synclist))
break;
}
}
assert(log->cqueue.head == NULL);
assert(list_empty(&log->synclist));
/* /*
* We need to make sure all of the "written" metapages * We need to make sure all of the "written" metapages
......
...@@ -489,6 +489,7 @@ typedef struct logsyncblk { ...@@ -489,6 +489,7 @@ typedef struct logsyncblk {
} }
extern int lmLogOpen(struct super_block *sb, log_t ** log); extern int lmLogOpen(struct super_block *sb, log_t ** log);
extern void lmLogWait(log_t * log);
extern int lmLogClose(struct super_block *sb, log_t * log); extern int lmLogClose(struct super_block *sb, log_t * log);
extern int lmLogSync(log_t * log, int nosyncwait); extern int lmLogSync(log_t * log, int nosyncwait);
extern int lmLogQuiesce(log_t * log); extern int lmLogQuiesce(log_t * log);
......
...@@ -64,15 +64,11 @@ int jfs_umount(struct super_block *sb) ...@@ -64,15 +64,11 @@ int jfs_umount(struct super_block *sb)
* *
* if mounted read-write and log based recovery was enabled * if mounted read-write and log based recovery was enabled
*/ */
if ((log = sbi->log)) { if ((log = sbi->log))
/* /*
* close log: * Wait for outstanding transactions to be written to log:
*
* remove file system from log active file system list.
*/ */
log = sbi->log; lmLogWait(log);
rc = lmLogClose(sb, log);
}
/* /*
* close fileset inode allocation map (aka fileset inode) * close fileset inode allocation map (aka fileset inode)
...@@ -112,6 +108,14 @@ int jfs_umount(struct super_block *sb) ...@@ -112,6 +108,14 @@ int jfs_umount(struct super_block *sb)
diFreeSpecial(ipbmap); diFreeSpecial(ipbmap);
sbi->ipimap = NULL; sbi->ipimap = NULL;
/*
* Make sure all metadata makes it to disk before we mark
* the superblock as clean
*/
filemap_fdatawait(sbi->direct_inode->i_mapping);
filemap_fdatawrite(sbi->direct_inode->i_mapping);
filemap_fdatawait(sbi->direct_inode->i_mapping);
/* /*
* ensure all file system file pages are propagated to their * ensure all file system file pages are propagated to their
* home blocks on disk (and their in-memory buffer pages are * home blocks on disk (and their in-memory buffer pages are
...@@ -120,10 +124,16 @@ int jfs_umount(struct super_block *sb) ...@@ -120,10 +124,16 @@ int jfs_umount(struct super_block *sb)
* consistent state) and log superblock active file system * consistent state) and log superblock active file system
* list (to signify skip logredo()). * list (to signify skip logredo()).
*/ */
if (log) /* log = NULL if read-only mount */ if (log) { /* log = NULL if read-only mount */
rc = updateSuper(sb, FM_CLEAN); rc = updateSuper(sb, FM_CLEAN);
/*
* close log:
*
* remove file system from log active file system list.
*/
rc = lmLogClose(sb, log);
}
jFYI(0, (" UnMount JFS Complete: %d\n", rc)); jFYI(0, (" UnMount JFS Complete: %d\n", rc));
return rc; return rc;
} }
...@@ -132,8 +142,9 @@ int jfs_umount(struct super_block *sb) ...@@ -132,8 +142,9 @@ int jfs_umount(struct super_block *sb)
int jfs_umount_rw(struct super_block *sb) int jfs_umount_rw(struct super_block *sb)
{ {
struct jfs_sb_info *sbi = JFS_SBI(sb); struct jfs_sb_info *sbi = JFS_SBI(sb);
log_t *log = sbi->log;
if (!sbi->log) if (!log)
return 0; return 0;
/* /*
...@@ -141,13 +152,19 @@ int jfs_umount_rw(struct super_block *sb) ...@@ -141,13 +152,19 @@ int jfs_umount_rw(struct super_block *sb)
* *
* remove file system from log active file system list. * remove file system from log active file system list.
*/ */
lmLogClose(sb, sbi->log); lmLogWait(log);
/*
* Make sure all metadata makes it to disk
*/
dbSync(sbi->ipbmap); dbSync(sbi->ipbmap);
diSync(sbi->ipimap); diSync(sbi->ipimap);
filemap_fdatawait(sbi->direct_inode->i_mapping);
filemap_fdatawrite(sbi->direct_inode->i_mapping);
filemap_fdatawait(sbi->direct_inode->i_mapping);
sbi->log = 0; updateSuper(sb, FM_CLEAN);
sbi->log = NULL;
return updateSuper(sb, FM_CLEAN); return lmLogClose(sb, log);
} }
...@@ -196,7 +196,7 @@ nfs_list_add_request(struct nfs_page *req, struct list_head *head) ...@@ -196,7 +196,7 @@ nfs_list_add_request(struct nfs_page *req, struct list_head *head)
BUG(); BUG();
} }
#endif #endif
for (pos = head->prev; pos != head; pos = pos->prev) { list_for_each_prev(pos, head) {
struct nfs_page *p = nfs_list_entry(pos); struct nfs_page *p = nfs_list_entry(pos);
if (page_index(p->wb_page) < pg_idx) if (page_index(p->wb_page) < pg_idx)
break; break;
......
...@@ -835,7 +835,7 @@ int filp_close(struct file *filp, fl_owner_t id) ...@@ -835,7 +835,7 @@ int filp_close(struct file *filp, fl_owner_t id)
retval = filp->f_op->flush(filp); retval = filp->f_op->flush(filp);
unlock_kernel(); unlock_kernel();
} }
fcntl_dirnotify(0, filp, 0); dnotify_flush(filp, id);
locks_remove_posix(filp, id); locks_remove_posix(filp, id);
fput(filp); fput(filp);
return retval; return retval;
......
...@@ -24,11 +24,12 @@ ...@@ -24,11 +24,12 @@
#define TI_FLAG_BYTE_WSAVED 5 #define TI_FLAG_BYTE_WSAVED 5
#define TI_FLAG_WSAVED_SHIFT 16 #define TI_FLAG_WSAVED_SHIFT 16
#include <asm/page.h>
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <asm/ptrace.h> #include <asm/ptrace.h>
#include <asm/types.h> #include <asm/types.h>
#include <asm/page.h>
struct task_struct; struct task_struct;
struct exec_domain; struct exec_domain;
......
...@@ -75,7 +75,8 @@ enum chipset_type { ...@@ -75,7 +75,8 @@ enum chipset_type {
ALI_GENERIC, ALI_GENERIC,
SVWRKS_HE, SVWRKS_HE,
SVWRKS_LE, SVWRKS_LE,
SVWRKS_GENERIC SVWRKS_GENERIC,
HP_ZX1,
}; };
typedef struct _agp_version { typedef struct _agp_version {
......
/* /*
* Directory notification for Linux * Directory notification for Linux
* *
* Copyright 2000 (C) Stephen Rothwell * Copyright (C) 2000,2002 Stephen Rothwell
*/ */
#include <linux/fs.h> #include <linux/fs.h>
struct dnotify_struct { struct dnotify_struct {
struct dnotify_struct * dn_next; struct dnotify_struct * dn_next;
int dn_magic;
unsigned long dn_mask; /* Events to be notified unsigned long dn_mask; /* Events to be notified
see linux/fcntl.h */ see linux/fcntl.h */
int dn_fd; int dn_fd;
...@@ -16,9 +15,8 @@ struct dnotify_struct { ...@@ -16,9 +15,8 @@ struct dnotify_struct {
fl_owner_t dn_owner; fl_owner_t dn_owner;
}; };
#define DNOTIFY_MAGIC 0x444E4F54
extern void __inode_dir_notify(struct inode *, unsigned long); extern void __inode_dir_notify(struct inode *, unsigned long);
extern void dnotify_flush(struct file *filp, fl_owner_t id);
extern int fcntl_dirnotify(int, struct file *, unsigned long); extern int fcntl_dirnotify(int, struct file *, unsigned long);
static inline void inode_dir_notify(struct inode *inode, unsigned long event) static inline void inode_dir_notify(struct inode *inode, unsigned long event)
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#define _FP_FRAC_NEGP_1(X) ((_FP_WS_TYPE)X##_f < 0) #define _FP_FRAC_NEGP_1(X) ((_FP_WS_TYPE)X##_f < 0)
#define _FP_FRAC_ZEROP_1(X) (X##_f == 0) #define _FP_FRAC_ZEROP_1(X) (X##_f == 0)
#define _FP_FRAC_OVERP_1(fs,X) (X##_f & _FP_OVERFLOW_##fs) #define _FP_FRAC_OVERP_1(fs,X) (X##_f & _FP_OVERFLOW_##fs)
#define _FP_FRAC_CLEAR_OVERP_1(fs,X) (X##_f &= ~_FP_OVERFLOW_##fs)
#define _FP_FRAC_EQ_1(X, Y) (X##_f == Y##_f) #define _FP_FRAC_EQ_1(X, Y) (X##_f == Y##_f)
#define _FP_FRAC_GE_1(X, Y) (X##_f >= Y##_f) #define _FP_FRAC_GE_1(X, Y) (X##_f >= Y##_f)
#define _FP_FRAC_GT_1(X, Y) (X##_f > Y##_f) #define _FP_FRAC_GT_1(X, Y) (X##_f > Y##_f)
......
...@@ -114,6 +114,7 @@ ...@@ -114,6 +114,7 @@
#define _FP_FRAC_NEGP_2(X) ((_FP_WS_TYPE)X##_f1 < 0) #define _FP_FRAC_NEGP_2(X) ((_FP_WS_TYPE)X##_f1 < 0)
#define _FP_FRAC_ZEROP_2(X) ((X##_f1 | X##_f0) == 0) #define _FP_FRAC_ZEROP_2(X) ((X##_f1 | X##_f0) == 0)
#define _FP_FRAC_OVERP_2(fs,X) (_FP_FRAC_HIGH_##fs(X) & _FP_OVERFLOW_##fs) #define _FP_FRAC_OVERP_2(fs,X) (_FP_FRAC_HIGH_##fs(X) & _FP_OVERFLOW_##fs)
#define _FP_FRAC_CLEAR_OVERP_2(fs,X) (_FP_FRAC_HIGH_##fs(X) &= ~_FP_OVERFLOW_##fs)
#define _FP_FRAC_EQ_2(X, Y) (X##_f1 == Y##_f1 && X##_f0 == Y##_f0) #define _FP_FRAC_EQ_2(X, Y) (X##_f1 == Y##_f1 && X##_f0 == Y##_f0)
#define _FP_FRAC_GT_2(X, Y) \ #define _FP_FRAC_GT_2(X, Y) \
(X##_f1 > Y##_f1 || (X##_f1 == Y##_f1 && X##_f0 > Y##_f0)) (X##_f1 > Y##_f1 || (X##_f1 == Y##_f1 && X##_f0 > Y##_f0))
......
...@@ -132,6 +132,7 @@ ...@@ -132,6 +132,7 @@
#define _FP_FRAC_ZEROP_4(X) ((X##_f[0] | X##_f[1] | X##_f[2] | X##_f[3]) == 0) #define _FP_FRAC_ZEROP_4(X) ((X##_f[0] | X##_f[1] | X##_f[2] | X##_f[3]) == 0)
#define _FP_FRAC_NEGP_4(X) ((_FP_WS_TYPE)X##_f[3] < 0) #define _FP_FRAC_NEGP_4(X) ((_FP_WS_TYPE)X##_f[3] < 0)
#define _FP_FRAC_OVERP_4(fs,X) (_FP_FRAC_HIGH_##fs(X) & _FP_OVERFLOW_##fs) #define _FP_FRAC_OVERP_4(fs,X) (_FP_FRAC_HIGH_##fs(X) & _FP_OVERFLOW_##fs)
#define _FP_FRAC_CLEAR_OVERP_4(fs,X) (_FP_FRAC_HIGH_##fs(X) &= ~_FP_OVERFLOW_##fs)
#define _FP_FRAC_EQ_4(X,Y) \ #define _FP_FRAC_EQ_4(X,Y) \
(X##_f[0] == Y##_f[0] && X##_f[1] == Y##_f[1] \ (X##_f[0] == Y##_f[0] && X##_f[1] == Y##_f[1] \
......
...@@ -97,11 +97,10 @@ do { \ ...@@ -97,11 +97,10 @@ do { \
_FP_ROUND(wc, X); \ _FP_ROUND(wc, X); \
if (_FP_FRAC_OVERP_##wc(fs, X)) \ if (_FP_FRAC_OVERP_##wc(fs, X)) \
{ \ { \
_FP_FRAC_SRL_##wc(X, (_FP_WORKBITS+1)); \ _FP_FRAC_CLEAR_OVERP_##wc(fs, X); \
X##_e++; \ X##_e++; \
} \ } \
else \ _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
_FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
if (X##_e >= _FP_EXPMAX_##fs) \ if (X##_e >= _FP_EXPMAX_##fs) \
{ \ { \
/* overflow */ \ /* overflow */ \
...@@ -780,9 +779,8 @@ do { \ ...@@ -780,9 +779,8 @@ do { \
X##_e -= (_FP_W_TYPE_SIZE - rsize); \ X##_e -= (_FP_W_TYPE_SIZE - rsize); \
X##_e = rsize - X##_e - 1; \ X##_e = rsize - X##_e - 1; \
\ \
r &= ~((rtype)1 << X##_e); \
if (_FP_FRACBITS_##fs < rsize && _FP_WFRACBITS_##fs < X##_e) \ if (_FP_FRACBITS_##fs < rsize && _FP_WFRACBITS_##fs < X##_e) \
__FP_FRAC_SRS_1(r, (X##_e - _FP_WFRACBITS_##fs), rsize); \ __FP_FRAC_SRS_1(r, (X##_e - _FP_WFRACBITS_##fs + 1), rsize); \
_FP_FRAC_DISASSEMBLE_##wc(X, ((unsigned rtype)r), rsize); \ _FP_FRAC_DISASSEMBLE_##wc(X, ((unsigned rtype)r), rsize); \
if ((_FP_WFRACBITS_##fs - X##_e - 1) > 0) \ if ((_FP_WFRACBITS_##fs - X##_e - 1) > 0) \
_FP_FRAC_SLL_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 1)); \ _FP_FRAC_SLL_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 1)); \
......
...@@ -110,6 +110,10 @@ struct rt_cache_stat ...@@ -110,6 +110,10 @@ struct rt_cache_stat
unsigned int out_hit; unsigned int out_hit;
unsigned int out_slow_tot; unsigned int out_slow_tot;
unsigned int out_slow_mc; unsigned int out_slow_mc;
unsigned int gc_total;
unsigned int gc_ignored;
unsigned int gc_goal_miss;
unsigned int gc_dst_overflow;
} ____cacheline_aligned_in_smp; } ____cacheline_aligned_in_smp;
extern struct ip_rt_acct *ip_rt_acct; extern struct ip_rt_acct *ip_rt_acct;
......
...@@ -387,6 +387,9 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk) ...@@ -387,6 +387,9 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
if (!mm_init(mm)) if (!mm_init(mm))
goto fail_nomem; goto fail_nomem;
if (init_new_context(tsk,mm))
goto free_pt;
down_write(&oldmm->mmap_sem); down_write(&oldmm->mmap_sem);
retval = dup_mmap(mm); retval = dup_mmap(mm);
up_write(&oldmm->mmap_sem); up_write(&oldmm->mmap_sem);
...@@ -394,9 +397,6 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk) ...@@ -394,9 +397,6 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
if (retval) if (retval)
goto free_pt; goto free_pt;
if (init_new_context(tsk,mm))
goto free_pt;
good_mm: good_mm:
tsk->mm = mm; tsk->mm = mm;
tsk->active_mm = mm; tsk->active_mm = mm;
......
...@@ -160,6 +160,7 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, in ...@@ -160,6 +160,7 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, in
put_page(page); put_page(page);
len -= bytes; len -= bytes;
buf += bytes; buf += bytes;
addr += bytes;
} }
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
mmput(mm); mmput(mm);
......
...@@ -839,7 +839,10 @@ kmem_cache_create (const char *name, size_t size, size_t offset, ...@@ -839,7 +839,10 @@ kmem_cache_create (const char *name, size_t size, size_t offset,
down(&cache_chain_sem); down(&cache_chain_sem);
{ {
struct list_head *p; struct list_head *p;
mm_segment_t old_fs;
old_fs = get_fs();
set_fs(KERNEL_DS);
list_for_each(p, &cache_chain) { list_for_each(p, &cache_chain) {
kmem_cache_t *pc = list_entry(p, kmem_cache_t, next); kmem_cache_t *pc = list_entry(p, kmem_cache_t, next);
char tmp; char tmp;
...@@ -857,6 +860,7 @@ kmem_cache_create (const char *name, size_t size, size_t offset, ...@@ -857,6 +860,7 @@ kmem_cache_create (const char *name, size_t size, size_t offset,
BUG(); BUG();
} }
} }
set_fs(old_fs);
} }
/* There is no reason to lock our new cache before we /* There is no reason to lock our new cache before we
...@@ -1965,8 +1969,13 @@ static int s_show(struct seq_file *m, void *p) ...@@ -1965,8 +1969,13 @@ static int s_show(struct seq_file *m, void *p)
name = cachep->name; name = cachep->name;
{ {
char tmp; char tmp;
mm_segment_t old_fs;
old_fs = get_fs();
set_fs(KERNEL_DS);
if (__get_user(tmp, name)) if (__get_user(tmp, name))
name = "broken"; name = "broken";
set_fs(old_fs);
} }
seq_printf(m, "%-17s %6lu %6lu %6u %4lu %4lu %4u", seq_printf(m, "%-17s %6lu %6lu %6u %4lu %4lu %4u",
......
...@@ -1088,7 +1088,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -1088,7 +1088,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
swap_list_unlock(); swap_list_unlock();
if (swap_map) if (swap_map)
vfree(swap_map); vfree(swap_map);
if (swap_file) if (swap_file && !IS_ERR(swap_file))
filp_close(swap_file, NULL); filp_close(swap_file, NULL);
out: out:
if (swap_header) if (swap_header)
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* Specify, after how many clock ticks (intel: 100 per second) the queue * Specify, after how many clock ticks (intel: 100 per second) the queue
* should be flushed even if it is not full yet. * should be flushed even if it is not full yet.
* *
* ipt_ULOG.c,v 1.15 2002/01/18 21:33:19 laforge Exp * ipt_ULOG.c,v 1.18 2002/04/16 07:33:00 laforge Exp
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -339,10 +339,28 @@ static int __init init(void) ...@@ -339,10 +339,28 @@ static int __init init(void)
static void __exit fini(void) static void __exit fini(void)
{ {
ulog_buff_t *ub;
int i;
DEBUGP("ipt_ULOG: cleanup_module\n"); DEBUGP("ipt_ULOG: cleanup_module\n");
ipt_unregister_target(&ipt_ulog_reg); ipt_unregister_target(&ipt_ulog_reg);
sock_release(nflognl->socket); sock_release(nflognl->socket);
/* remove pending timers and free allocated skb's */
for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
ub = &ulog_buffers[i];
if (timer_pending(&ub->timer)) {
DEBUGP("timer was pending, deleting\n");
del_timer(&ub->timer);
}
if (ub->skb) {
kfree_skb(ub->skb);
ub->skb = NULL;
}
}
} }
module_init(init); module_init(init);
......
...@@ -286,7 +286,7 @@ static int rt_cache_stat_get_info(char *buffer, char **start, off_t offset, int ...@@ -286,7 +286,7 @@ static int rt_cache_stat_get_info(char *buffer, char **start, off_t offset, int
for (lcpu = 0; lcpu < smp_num_cpus; lcpu++) { for (lcpu = 0; lcpu < smp_num_cpus; lcpu++) {
i = cpu_logical_map(lcpu); i = cpu_logical_map(lcpu);
len += sprintf(buffer+len, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", len += sprintf(buffer+len, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x \n",
dst_entries, dst_entries,
rt_cache_stat[i].in_hit, rt_cache_stat[i].in_hit,
rt_cache_stat[i].in_slow_tot, rt_cache_stat[i].in_slow_tot,
...@@ -298,7 +298,13 @@ static int rt_cache_stat_get_info(char *buffer, char **start, off_t offset, int ...@@ -298,7 +298,13 @@ static int rt_cache_stat_get_info(char *buffer, char **start, off_t offset, int
rt_cache_stat[i].out_hit, rt_cache_stat[i].out_hit,
rt_cache_stat[i].out_slow_tot, rt_cache_stat[i].out_slow_tot,
rt_cache_stat[i].out_slow_mc rt_cache_stat[i].out_slow_mc,
rt_cache_stat[i].gc_total,
rt_cache_stat[i].gc_ignored,
rt_cache_stat[i].gc_goal_miss,
rt_cache_stat[i].gc_dst_overflow
); );
} }
len -= offset; len -= offset;
...@@ -499,9 +505,14 @@ static int rt_garbage_collect(void) ...@@ -499,9 +505,14 @@ static int rt_garbage_collect(void)
* Garbage collection is pretty expensive, * Garbage collection is pretty expensive,
* do not make it too frequently. * do not make it too frequently.
*/ */
rt_cache_stat[smp_processor_id()].gc_total++;
if (now - last_gc < ip_rt_gc_min_interval && if (now - last_gc < ip_rt_gc_min_interval &&
atomic_read(&ipv4_dst_ops.entries) < ip_rt_max_size) atomic_read(&ipv4_dst_ops.entries) < ip_rt_max_size) {
rt_cache_stat[smp_processor_id()].gc_ignored++;
goto out; goto out;
}
/* Calculate number of entries, which we want to expire now. */ /* Calculate number of entries, which we want to expire now. */
goal = atomic_read(&ipv4_dst_ops.entries) - goal = atomic_read(&ipv4_dst_ops.entries) -
...@@ -567,6 +578,8 @@ static int rt_garbage_collect(void) ...@@ -567,6 +578,8 @@ static int rt_garbage_collect(void)
We will not spin here for long time in any case. We will not spin here for long time in any case.
*/ */
rt_cache_stat[smp_processor_id()].gc_goal_miss++;
if (expire == 0) if (expire == 0)
break; break;
...@@ -584,6 +597,7 @@ static int rt_garbage_collect(void) ...@@ -584,6 +597,7 @@ static int rt_garbage_collect(void)
goto out; goto out;
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_WARNING "dst cache overflow\n"); printk(KERN_WARNING "dst cache overflow\n");
rt_cache_stat[smp_processor_id()].gc_dst_overflow++;
return 1; return 1;
work_done: work_done:
......
...@@ -204,7 +204,7 @@ ...@@ -204,7 +204,7 @@
* Andi Kleen : Make poll agree with SIGIO * Andi Kleen : Make poll agree with SIGIO
* Salvatore Sanfilippo : Support SO_LINGER with linger == 1 and * Salvatore Sanfilippo : Support SO_LINGER with linger == 1 and
* lingertime == 0 (RFC 793 ABORT Call) * lingertime == 0 (RFC 793 ABORT Call)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version * as published by the Free Software Foundation; either version
...@@ -261,7 +261,7 @@ ...@@ -261,7 +261,7 @@
int sysctl_tcp_fin_timeout = TCP_FIN_TIMEOUT; int sysctl_tcp_fin_timeout = TCP_FIN_TIMEOUT;
struct tcp_mib tcp_statistics[NR_CPUS*2]; struct tcp_mib tcp_statistics[NR_CPUS * 2];
kmem_cache_t *tcp_openreq_cachep; kmem_cache_t *tcp_openreq_cachep;
kmem_cache_t *tcp_bucket_cachep; kmem_cache_t *tcp_bucket_cachep;
...@@ -270,8 +270,8 @@ kmem_cache_t *tcp_timewait_cachep; ...@@ -270,8 +270,8 @@ kmem_cache_t *tcp_timewait_cachep;
atomic_t tcp_orphan_count = ATOMIC_INIT(0); atomic_t tcp_orphan_count = ATOMIC_INIT(0);
int sysctl_tcp_mem[3]; int sysctl_tcp_mem[3];
int sysctl_tcp_wmem[3] = { 4*1024, 16*1024, 128*1024 }; int sysctl_tcp_wmem[3] = { 4 * 1024, 16 * 1024, 128 * 1024 };
int sysctl_tcp_rmem[3] = { 4*1024, 87380, 87380*2 }; int sysctl_tcp_rmem[3] = { 4 * 1024, 87380, 87380 * 2 };
atomic_t tcp_memory_allocated; /* Current allocated memory. */ atomic_t tcp_memory_allocated; /* Current allocated memory. */
atomic_t tcp_sockets_allocated; /* Current number of TCP sockets. */ atomic_t tcp_sockets_allocated; /* Current number of TCP sockets. */
...@@ -282,13 +282,13 @@ atomic_t tcp_sockets_allocated; /* Current number of TCP sockets. */ ...@@ -282,13 +282,13 @@ atomic_t tcp_sockets_allocated; /* Current number of TCP sockets. */
* is strict, actions are advisory and have some latency. */ * is strict, actions are advisory and have some latency. */
int tcp_memory_pressure; int tcp_memory_pressure;
#define TCP_PAGES(amt) (((amt)+TCP_MEM_QUANTUM-1)/TCP_MEM_QUANTUM) #define TCP_PAGES(amt) (((amt) + TCP_MEM_QUANTUM - 1) / TCP_MEM_QUANTUM)
int tcp_mem_schedule(struct sock *sk, int size, int kind) int tcp_mem_schedule(struct sock *sk, int size, int kind)
{ {
int amt = TCP_PAGES(size); int amt = TCP_PAGES(size);
sk->forward_alloc += amt*TCP_MEM_QUANTUM; sk->forward_alloc += amt * TCP_MEM_QUANTUM;
atomic_add(amt, &tcp_memory_allocated); atomic_add(amt, &tcp_memory_allocated);
/* Under limit. */ /* Under limit. */
...@@ -317,25 +317,26 @@ int tcp_mem_schedule(struct sock *sk, int size, int kind) ...@@ -317,25 +317,26 @@ int tcp_mem_schedule(struct sock *sk, int size, int kind)
} }
if (!tcp_memory_pressure || if (!tcp_memory_pressure ||
sysctl_tcp_mem[2] > atomic_read(&tcp_sockets_allocated) sysctl_tcp_mem[2] > atomic_read(&tcp_sockets_allocated) *
* TCP_PAGES(sk->wmem_queued+atomic_read(&sk->rmem_alloc)+ TCP_PAGES(sk->wmem_queued +
sk->forward_alloc)) atomic_read(&sk->rmem_alloc) +
sk->forward_alloc))
return 1; return 1;
suppress_allocation: suppress_allocation:
if (kind == 0) { if (!kind) {
tcp_moderate_sndbuf(sk); tcp_moderate_sndbuf(sk);
/* Fail only if socket is _under_ its sndbuf. /* Fail only if socket is _under_ its sndbuf.
* In this case we cannot block, so that we have to fail. * In this case we cannot block, so that we have to fail.
*/ */
if (sk->wmem_queued+size >= sk->sndbuf) if (sk->wmem_queued + size >= sk->sndbuf)
return 1; return 1;
} }
/* Alas. Undo changes. */ /* Alas. Undo changes. */
sk->forward_alloc -= amt*TCP_MEM_QUANTUM; sk->forward_alloc -= amt * TCP_MEM_QUANTUM;
atomic_sub(amt, &tcp_memory_allocated); atomic_sub(amt, &tcp_memory_allocated);
return 0; return 0;
} }
...@@ -343,8 +344,9 @@ int tcp_mem_schedule(struct sock *sk, int size, int kind) ...@@ -343,8 +344,9 @@ int tcp_mem_schedule(struct sock *sk, int size, int kind)
void __tcp_mem_reclaim(struct sock *sk) void __tcp_mem_reclaim(struct sock *sk)
{ {
if (sk->forward_alloc >= TCP_MEM_QUANTUM) { if (sk->forward_alloc >= TCP_MEM_QUANTUM) {
atomic_sub(sk->forward_alloc/TCP_MEM_QUANTUM, &tcp_memory_allocated); atomic_sub(sk->forward_alloc / TCP_MEM_QUANTUM,
sk->forward_alloc &= (TCP_MEM_QUANTUM-1); &tcp_memory_allocated);
sk->forward_alloc &= TCP_MEM_QUANTUM - 1;
if (tcp_memory_pressure && if (tcp_memory_pressure &&
atomic_read(&tcp_memory_allocated) < sysctl_tcp_mem[0]) atomic_read(&tcp_memory_allocated) < sysctl_tcp_mem[0])
tcp_memory_pressure = 0; tcp_memory_pressure = 0;
...@@ -362,7 +364,8 @@ void tcp_rfree(struct sk_buff *skb) ...@@ -362,7 +364,8 @@ void tcp_rfree(struct sk_buff *skb)
/* /*
* LISTEN is a special case for poll.. * LISTEN is a special case for poll..
*/ */
static __inline__ unsigned int tcp_listen_poll(struct sock *sk, poll_table *wait) static __inline__ unsigned int tcp_listen_poll(struct sock *sk,
poll_table *wait)
{ {
return tcp_sk(sk)->accept_queue ? (POLLIN | POLLRDNORM) : 0; return tcp_sk(sk)->accept_queue ? (POLLIN | POLLRDNORM) : 0;
} }
...@@ -374,7 +377,7 @@ static __inline__ unsigned int tcp_listen_poll(struct sock *sk, poll_table *wait ...@@ -374,7 +377,7 @@ static __inline__ unsigned int tcp_listen_poll(struct sock *sk, poll_table *wait
* take care of normal races (between the test and the event) and we don't * take care of normal races (between the test and the event) and we don't
* go look at any of the socket buffers directly. * go look at any of the socket buffers directly.
*/ */
unsigned int tcp_poll(struct file * file, struct socket *sock, poll_table *wait) unsigned int tcp_poll(struct file *file, struct socket *sock, poll_table *wait)
{ {
unsigned int mask; unsigned int mask;
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
...@@ -426,13 +429,13 @@ unsigned int tcp_poll(struct file * file, struct socket *sock, poll_table *wait) ...@@ -426,13 +429,13 @@ unsigned int tcp_poll(struct file * file, struct socket *sock, poll_table *wait)
mask |= POLLIN | POLLRDNORM; mask |= POLLIN | POLLRDNORM;
/* Connected? */ /* Connected? */
if ((1 << sk->state) & ~(TCPF_SYN_SENT|TCPF_SYN_RECV)) { if ((1 << sk->state) & ~(TCPF_SYN_SENT | TCPF_SYN_RECV)) {
/* Potential race condition. If read of tp below will /* Potential race condition. If read of tp below will
* escape above sk->state, we can be illegally awaken * escape above sk->state, we can be illegally awaken
* in SYN_* states. */ * in SYN_* states. */
if ((tp->rcv_nxt != tp->copied_seq) && if ((tp->rcv_nxt != tp->copied_seq) &&
(tp->urg_seq != tp->copied_seq || (tp->urg_seq != tp->copied_seq ||
tp->rcv_nxt != tp->copied_seq+1 || tp->rcv_nxt != tp->copied_seq + 1 ||
sk->urginline || !tp->urg_data)) sk->urginline || !tp->urg_data))
mask |= POLLIN | POLLRDNORM; mask |= POLLIN | POLLRDNORM;
...@@ -471,7 +474,7 @@ void tcp_write_space(struct sock *sk) ...@@ -471,7 +474,7 @@ void tcp_write_space(struct sock *sk)
if (sk->sleep && waitqueue_active(sk->sleep)) if (sk->sleep && waitqueue_active(sk->sleep))
wake_up_interruptible(sk->sleep); wake_up_interruptible(sk->sleep);
if (sock->fasync_list && !(sk->shutdown&SEND_SHUTDOWN)) if (sock->fasync_list && !(sk->shutdown & SEND_SHUTDOWN))
sock_wake_async(sock, 2, POLL_OUT); sock_wake_async(sock, 2, POLL_OUT);
} }
} }
...@@ -481,42 +484,41 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg) ...@@ -481,42 +484,41 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
int answ; int answ;
switch(cmd) { switch (cmd) {
case SIOCINQ: case SIOCINQ:
if (sk->state == TCP_LISTEN) if (sk->state == TCP_LISTEN)
return(-EINVAL); return -EINVAL;
lock_sock(sk); lock_sock(sk);
if ((1<<sk->state) & (TCPF_SYN_SENT|TCPF_SYN_RECV)) if ((1 << sk->state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
answ = 0; answ = 0;
else if (sk->urginline || !tp->urg_data || else if (sk->urginline || !tp->urg_data ||
before(tp->urg_seq,tp->copied_seq) || before(tp->urg_seq, tp->copied_seq) ||
!before(tp->urg_seq,tp->rcv_nxt)) { !before(tp->urg_seq, tp->rcv_nxt)) {
answ = tp->rcv_nxt - tp->copied_seq; answ = tp->rcv_nxt - tp->copied_seq;
/* Subtract 1, if FIN is in queue. */ /* Subtract 1, if FIN is in queue. */
if (answ && !skb_queue_empty(&sk->receive_queue)) if (answ && !skb_queue_empty(&sk->receive_queue))
answ -= ((struct sk_buff*)sk->receive_queue.prev)->h.th->fin; answ -=
((struct sk_buff*)sk->receive_queue.prev)->h.th->fin;
} else } else
answ = tp->urg_seq - tp->copied_seq; answ = tp->urg_seq - tp->copied_seq;
release_sock(sk); release_sock(sk);
break; break;
case SIOCATMARK: case SIOCATMARK:
{ answ = tp->urg_data && tp->urg_seq == tp->copied_seq;
answ = tp->urg_data && tp->urg_seq == tp->copied_seq; break;
break;
}
case SIOCOUTQ: case SIOCOUTQ:
if (sk->state == TCP_LISTEN) if (sk->state == TCP_LISTEN)
return(-EINVAL); return -EINVAL;
if ((1<<sk->state) & (TCPF_SYN_SENT|TCPF_SYN_RECV)) if ((1 << sk->state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
answ = 0; answ = 0;
else else
answ = tp->write_seq - tp->snd_una; answ = tp->write_seq - tp->snd_una;
break; break;
default: default:
return(-ENOIOCTLCMD); return -ENOIOCTLCMD;
}; };
return put_user(answ, (int *)arg); return put_user(answ, (int *)arg);
...@@ -541,7 +543,7 @@ int tcp_listen_start(struct sock *sk) ...@@ -541,7 +543,7 @@ int tcp_listen_start(struct sock *sk)
memset(lopt, 0, sizeof(struct tcp_listen_opt)); memset(lopt, 0, sizeof(struct tcp_listen_opt));
for (lopt->max_qlen_log = 6; ; lopt->max_qlen_log++) for (lopt->max_qlen_log = 6; ; lopt->max_qlen_log++)
if ((1<<lopt->max_qlen_log) >= sysctl_max_syn_backlog) if ((1 << lopt->max_qlen_log) >= sysctl_max_syn_backlog)
break; break;
write_lock_bh(&tp->syn_wait_lock); write_lock_bh(&tp->syn_wait_lock);
...@@ -588,12 +590,12 @@ static void tcp_listen_stop (struct sock *sk) ...@@ -588,12 +590,12 @@ static void tcp_listen_stop (struct sock *sk)
/* make all the listen_opt local to us */ /* make all the listen_opt local to us */
write_lock_bh(&tp->syn_wait_lock); write_lock_bh(&tp->syn_wait_lock);
tp->listen_opt =NULL; tp->listen_opt = NULL;
write_unlock_bh(&tp->syn_wait_lock); write_unlock_bh(&tp->syn_wait_lock);
tp->accept_queue = tp->accept_queue_tail = NULL; tp->accept_queue = tp->accept_queue_tail = NULL;
if (lopt->qlen) { if (lopt->qlen) {
for (i=0; i<TCP_SYNQ_HSIZE; i++) { for (i = 0; i < TCP_SYNQ_HSIZE; i++) {
while ((req = lopt->syn_table[i]) != NULL) { while ((req = lopt->syn_table[i]) != NULL) {
lopt->syn_table[i] = req->dl_next; lopt->syn_table[i] = req->dl_next;
lopt->qlen--; lopt->qlen--;
...@@ -601,7 +603,7 @@ static void tcp_listen_stop (struct sock *sk) ...@@ -601,7 +603,7 @@ static void tcp_listen_stop (struct sock *sk)
/* Following specs, it would be better either to send FIN /* Following specs, it would be better either to send FIN
* (and enter FIN-WAIT-1, it is normal close) * (and enter FIN-WAIT-1, it is normal close)
* or to send active reset (abort). * or to send active reset (abort).
* Certainly, it is pretty dangerous while synflood, but it is * Certainly, it is pretty dangerous while synflood, but it is
* bad justification for our negligence 8) * bad justification for our negligence 8)
* To be honest, we are not able to make either * To be honest, we are not able to make either
...@@ -610,18 +612,18 @@ static void tcp_listen_stop (struct sock *sk) ...@@ -610,18 +612,18 @@ static void tcp_listen_stop (struct sock *sk)
} }
} }
} }
BUG_TRAP(lopt->qlen == 0); BUG_TRAP(!lopt->qlen);
kfree(lopt); kfree(lopt);
while ((req=acc_req) != NULL) { while ((req = acc_req) != NULL) {
struct sock *child = req->sk; struct sock *child = req->sk;
acc_req = req->dl_next; acc_req = req->dl_next;
local_bh_disable(); local_bh_disable();
bh_lock_sock(child); bh_lock_sock(child);
BUG_TRAP(child->lock.users==0); BUG_TRAP(!child->lock.users);
sock_hold(child); sock_hold(child);
tcp_disconnect(child, O_NONBLOCK); tcp_disconnect(child, O_NONBLOCK);
...@@ -639,7 +641,7 @@ static void tcp_listen_stop (struct sock *sk) ...@@ -639,7 +641,7 @@ static void tcp_listen_stop (struct sock *sk)
tcp_acceptq_removed(sk); tcp_acceptq_removed(sk);
tcp_openreq_fastfree(req); tcp_openreq_fastfree(req);
} }
BUG_TRAP(sk->ack_backlog == 0); BUG_TRAP(!sk->ack_backlog);
} }
/* /*
...@@ -647,21 +649,20 @@ static void tcp_listen_stop (struct sock *sk) ...@@ -647,21 +649,20 @@ static void tcp_listen_stop (struct sock *sk)
* *
* Note: Must be called with the socket locked. * Note: Must be called with the socket locked.
*/ */
static int wait_for_tcp_connect(struct sock * sk, int flags, long *timeo_p) static int wait_for_tcp_connect(struct sock *sk, int flags, long *timeo_p)
{ {
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
struct task_struct *tsk = current; struct task_struct *tsk = current;
DECLARE_WAITQUEUE(wait, tsk); DECLARE_WAITQUEUE(wait, tsk);
while((1 << sk->state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) { while ((1 << sk->state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
if(sk->err) if (sk->err)
return sock_error(sk); return sock_error(sk);
if((1 << sk->state) & if ((1 << sk->state) & ~(TCPF_SYN_SENT | TCPF_SYN_RECV))
~(TCPF_SYN_SENT | TCPF_SYN_RECV))
return -EPIPE; return -EPIPE;
if(!*timeo_p) if (!*timeo_p)
return -EAGAIN; return -EAGAIN;
if(signal_pending(tsk)) if (signal_pending(tsk))
return sock_intr_errno(*timeo_p); return sock_intr_errno(*timeo_p);
__set_task_state(tsk, TASK_INTERRUPTIBLE); __set_task_state(tsk, TASK_INTERRUPTIBLE);
...@@ -687,7 +688,7 @@ static inline int tcp_memory_free(struct sock *sk) ...@@ -687,7 +688,7 @@ static inline int tcp_memory_free(struct sock *sk)
/* /*
* Wait for more memory for a socket * Wait for more memory for a socket
*/ */
static int wait_for_tcp_memory(struct sock * sk, long *timeo) static int wait_for_tcp_memory(struct sock *sk, long *timeo)
{ {
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
int err = 0; int err = 0;
...@@ -696,7 +697,7 @@ static int wait_for_tcp_memory(struct sock * sk, long *timeo) ...@@ -696,7 +697,7 @@ static int wait_for_tcp_memory(struct sock * sk, long *timeo)
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
if (tcp_memory_free(sk)) if (tcp_memory_free(sk))
current_timeo = vm_wait = (net_random()%(HZ/5))+2; current_timeo = vm_wait = (net_random() % (HZ / 5)) + 2;
add_wait_queue(sk->sleep, &wait); add_wait_queue(sk->sleep, &wait);
for (;;) { for (;;) {
...@@ -748,27 +749,28 @@ static int wait_for_tcp_memory(struct sock * sk, long *timeo) ...@@ -748,27 +749,28 @@ static int wait_for_tcp_memory(struct sock * sk, long *timeo)
goto out; goto out;
} }
ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size_t psize, int flags); ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset,
size_t psize, int flags);
static inline int static inline int can_coalesce(struct sk_buff *skb, int i, struct page *page,
can_coalesce(struct sk_buff *skb, int i, struct page *page, int off) int off)
{ {
if (i) { if (i) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1];
return page == frag->page && return page == frag->page &&
off == frag->page_offset+frag->size; off == frag->page_offset + frag->size;
} }
return 0; return 0;
} }
static inline void static inline void fill_page_desc(struct sk_buff *skb, int i,
fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size) struct page *page, int off, int size)
{ {
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
frag->page = page; frag->page = page;
frag->page_offset = off; frag->page_offset = off;
frag->size = size; frag->size = size;
skb_shinfo(skb)->nr_frags = i+1; skb_shinfo(skb)->nr_frags = i + 1;
} }
static inline void tcp_mark_push(struct tcp_opt *tp, struct sk_buff *skb) static inline void tcp_mark_push(struct tcp_opt *tp, struct sk_buff *skb)
...@@ -779,11 +781,11 @@ static inline void tcp_mark_push(struct tcp_opt *tp, struct sk_buff *skb) ...@@ -779,11 +781,11 @@ static inline void tcp_mark_push(struct tcp_opt *tp, struct sk_buff *skb)
static inline int forced_push(struct tcp_opt *tp) static inline int forced_push(struct tcp_opt *tp)
{ {
return after(tp->write_seq, tp->pushed_seq + (tp->max_window>>1)); return after(tp->write_seq, tp->pushed_seq + (tp->max_window >> 1));
} }
static inline void static inline void skb_entail(struct sock *sk, struct tcp_opt *tp,
skb_entail(struct sock *sk, struct tcp_opt *tp, struct sk_buff *skb) struct sk_buff *skb)
{ {
skb->csum = 0; skb->csum = 0;
TCP_SKB_CB(skb)->seq = tp->write_seq; TCP_SKB_CB(skb)->seq = tp->write_seq;
...@@ -792,12 +794,12 @@ skb_entail(struct sock *sk, struct tcp_opt *tp, struct sk_buff *skb) ...@@ -792,12 +794,12 @@ skb_entail(struct sock *sk, struct tcp_opt *tp, struct sk_buff *skb)
TCP_SKB_CB(skb)->sacked = 0; TCP_SKB_CB(skb)->sacked = 0;
__skb_queue_tail(&sk->write_queue, skb); __skb_queue_tail(&sk->write_queue, skb);
tcp_charge_skb(sk, skb); tcp_charge_skb(sk, skb);
if (tp->send_head == NULL) if (!tp->send_head)
tp->send_head = skb; tp->send_head = skb;
} }
static inline void static inline void tcp_mark_urg(struct tcp_opt *tp, int flags,
tcp_mark_urg(struct tcp_opt *tp, int flags, struct sk_buff *skb) struct sk_buff *skb)
{ {
if (flags & MSG_OOB) { if (flags & MSG_OOB) {
tp->urg_mode = 1; tp->urg_mode = 1;
...@@ -806,15 +808,16 @@ tcp_mark_urg(struct tcp_opt *tp, int flags, struct sk_buff *skb) ...@@ -806,15 +808,16 @@ tcp_mark_urg(struct tcp_opt *tp, int flags, struct sk_buff *skb)
} }
} }
static inline void static inline void tcp_push(struct sock *sk, struct tcp_opt *tp, int flags,
tcp_push(struct sock *sk, struct tcp_opt *tp, int flags, int mss_now, int nonagle) int mss_now, int nonagle)
{ {
if (tp->send_head) { if (tp->send_head) {
struct sk_buff *skb = sk->write_queue.prev; struct sk_buff *skb = sk->write_queue.prev;
if (!(flags&MSG_MORE) || forced_push(tp)) if (!(flags & MSG_MORE) || forced_push(tp))
tcp_mark_push(tp, skb); tcp_mark_push(tp, skb);
tcp_mark_urg(tp, flags, skb); tcp_mark_urg(tp, flags, skb);
__tcp_push_pending_frames(sk, tp, mss_now, (flags&MSG_MORE) ? 2 : nonagle); __tcp_push_pending_frames(sk, tp, mss_now,
(flags & MSG_MORE) ? 2 : nonagle);
} }
} }
...@@ -822,22 +825,23 @@ static int tcp_error(struct sock *sk, int flags, int err) ...@@ -822,22 +825,23 @@ static int tcp_error(struct sock *sk, int flags, int err)
{ {
if (err == -EPIPE) if (err == -EPIPE)
err = sock_error(sk) ? : -EPIPE; err = sock_error(sk) ? : -EPIPE;
if (err == -EPIPE && !(flags&MSG_NOSIGNAL)) if (err == -EPIPE && !(flags & MSG_NOSIGNAL))
send_sig(SIGPIPE, current, 0); send_sig(SIGPIPE, current, 0);
return err; return err;
} }
ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size_t psize, int flags) ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset,
size_t psize, int flags)
{ {
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
int mss_now; int mss_now;
int err; int err;
ssize_t copied; ssize_t copied;
long timeo = sock_sndtimeo(sk, flags&MSG_DONTWAIT); long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
/* Wait for a connection to finish. */ /* Wait for a connection to finish. */
if ((1 << sk->state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) if ((1 << sk->state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT))
if((err = wait_for_tcp_connect(sk, 0, &timeo)) != 0) if ((err = wait_for_tcp_connect(sk, 0, &timeo)) != 0)
goto out_err; goto out_err;
clear_bit(SOCK_ASYNC_NOSPACE, &sk->socket->flags); clear_bit(SOCK_ASYNC_NOSPACE, &sk->socket->flags);
...@@ -851,20 +855,19 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size ...@@ -851,20 +855,19 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size
while (psize > 0) { while (psize > 0) {
struct sk_buff *skb = sk->write_queue.prev; struct sk_buff *skb = sk->write_queue.prev;
int offset, size, copy, i; struct page *page = pages[poffset / PAGE_SIZE];
struct page *page; int copy, i;
int offset = poffset % PAGE_SIZE;
page = pages[poffset/PAGE_SIZE]; int size = min_t(size_t, psize, PAGE_SIZE - offset);
offset = poffset % PAGE_SIZE;
size = min_t(size_t, psize, PAGE_SIZE-offset);
if (tp->send_head==NULL || (copy = mss_now - skb->len) <= 0) { if (!tp->send_head || (copy = mss_now - skb->len) <= 0) {
new_segment: new_segment:
if (!tcp_memory_free(sk)) if (!tcp_memory_free(sk))
goto wait_for_sndbuf; goto wait_for_sndbuf;
skb = tcp_alloc_pskb(sk, 0, tp->mss_cache, sk->allocation); skb = tcp_alloc_pskb(sk, 0, tp->mss_cache,
if (skb == NULL) sk->allocation);
if (!skb)
goto wait_for_memory; goto wait_for_memory;
skb_entail(sk, tp, skb); skb_entail(sk, tp, skb);
...@@ -876,7 +879,7 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size ...@@ -876,7 +879,7 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size
i = skb_shinfo(skb)->nr_frags; i = skb_shinfo(skb)->nr_frags;
if (can_coalesce(skb, i, page, offset)) { if (can_coalesce(skb, i, page, offset)) {
skb_shinfo(skb)->frags[i-1].size += copy; skb_shinfo(skb)->frags[i - 1].size += copy;
} else if (i < MAX_SKB_FRAGS) { } else if (i < MAX_SKB_FRAGS) {
get_page(page); get_page(page);
fill_page_desc(skb, i, page, offset, copy); fill_page_desc(skb, i, page, offset, copy);
...@@ -899,7 +902,7 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size ...@@ -899,7 +902,7 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size
if (!(psize -= copy)) if (!(psize -= copy))
goto out; goto out;
if (skb->len != mss_now || (flags&MSG_OOB)) if (skb->len != mss_now || (flags & MSG_OOB))
continue; continue;
if (forced_push(tp)) { if (forced_push(tp)) {
...@@ -913,7 +916,7 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size ...@@ -913,7 +916,7 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size
set_bit(SOCK_NOSPACE, &sk->socket->flags); set_bit(SOCK_NOSPACE, &sk->socket->flags);
wait_for_memory: wait_for_memory:
if (copied) if (copied)
tcp_push(sk, tp, flags&~MSG_MORE, mss_now, 1); tcp_push(sk, tp, flags & ~MSG_MORE, mss_now, 1);
if ((err = wait_for_tcp_memory(sk, &timeo)) != 0) if ((err = wait_for_tcp_memory(sk, &timeo)) != 0)
goto do_error; goto do_error;
...@@ -933,14 +936,15 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size ...@@ -933,14 +936,15 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size
return tcp_error(sk, flags, err); return tcp_error(sk, flags, err);
} }
ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags) ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset,
size_t size, int flags)
{ {
ssize_t res; ssize_t res;
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
#define TCP_ZC_CSUM_FLAGS (NETIF_F_IP_CSUM|NETIF_F_NO_CSUM|NETIF_F_HW_CSUM) #define TCP_ZC_CSUM_FLAGS (NETIF_F_IP_CSUM | NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)
if (!(sk->route_caps & NETIF_F_SG) || if (!(sk->route_caps & NETIF_F_SG) ||
!(sk->route_caps & TCP_ZC_CSUM_FLAGS)) !(sk->route_caps & TCP_ZC_CSUM_FLAGS))
return sock_no_sendpage(sock, page, offset, size, flags); return sock_no_sendpage(sock, page, offset, size, flags);
...@@ -957,14 +961,14 @@ ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, size_t ...@@ -957,14 +961,14 @@ ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, size_t
#define TCP_PAGE(sk) (tcp_sk(sk)->sndmsg_page) #define TCP_PAGE(sk) (tcp_sk(sk)->sndmsg_page)
#define TCP_OFF(sk) (tcp_sk(sk)->sndmsg_off) #define TCP_OFF(sk) (tcp_sk(sk)->sndmsg_off)
static inline int static inline int tcp_copy_to_page(struct sock *sk, char *from,
tcp_copy_to_page(struct sock *sk, char *from, struct sk_buff *skb, struct sk_buff *skb, struct page *page,
struct page *page, int off, int copy) int off, int copy)
{ {
int err = 0; int err = 0;
unsigned int csum; unsigned int csum;
csum = csum_and_copy_from_user(from, page_address(page)+off, csum = csum_and_copy_from_user(from, page_address(page) + off,
copy, 0, &err); copy, 0, &err);
if (!err) { if (!err) {
if (skb->ip_summed == CHECKSUM_NONE) if (skb->ip_summed == CHECKSUM_NONE)
...@@ -978,8 +982,7 @@ tcp_copy_to_page(struct sock *sk, char *from, struct sk_buff *skb, ...@@ -978,8 +982,7 @@ tcp_copy_to_page(struct sock *sk, char *from, struct sk_buff *skb,
return err; return err;
} }
static inline int static inline int skb_add_data(struct sk_buff *skb, char *from, int copy)
skb_add_data(struct sk_buff *skb, char *from, int copy)
{ {
int err = 0; int err = 0;
unsigned int csum; unsigned int csum;
...@@ -1000,10 +1003,11 @@ static inline int select_size(struct sock *sk, struct tcp_opt *tp) ...@@ -1000,10 +1003,11 @@ static inline int select_size(struct sock *sk, struct tcp_opt *tp)
{ {
int tmp = tp->mss_cache; int tmp = tp->mss_cache;
if (sk->route_caps&NETIF_F_SG) { if (sk->route_caps & NETIF_F_SG) {
int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER); int pgbreak = SKB_MAX_HEAD(MAX_TCP_HEADER);
if (tmp >= pgbreak && tmp <= pgbreak + (MAX_SKB_FRAGS-1)*PAGE_SIZE) if (tmp >= pgbreak &&
tmp <= pgbreak + (MAX_SKB_FRAGS - 1) * PAGE_SIZE)
tmp = pgbreak; tmp = pgbreak;
} }
return tmp; return tmp;
...@@ -1023,11 +1027,11 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1023,11 +1027,11 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
TCP_CHECK_TIMER(sk); TCP_CHECK_TIMER(sk);
flags = msg->msg_flags; flags = msg->msg_flags;
timeo = sock_sndtimeo(sk, flags&MSG_DONTWAIT); timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
/* Wait for a connection to finish. */ /* Wait for a connection to finish. */
if ((1 << sk->state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) if ((1 << sk->state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT))
if((err = wait_for_tcp_connect(sk, flags, &timeo)) != 0) if ((err = wait_for_tcp_connect(sk, flags, &timeo)) != 0)
goto out_err; goto out_err;
/* This should be in poll */ /* This should be in poll */
...@@ -1041,21 +1045,21 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1041,21 +1045,21 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
copied = 0; copied = 0;
err = -EPIPE; err = -EPIPE;
if (sk->err || (sk->shutdown&SEND_SHUTDOWN)) if (sk->err || (sk->shutdown & SEND_SHUTDOWN))
goto do_error; goto do_error;
while (--iovlen >= 0) { while (--iovlen >= 0) {
int seglen=iov->iov_len; int seglen = iov->iov_len;
unsigned char * from=iov->iov_base; unsigned char *from = iov->iov_base;
iov++; iov++;
while (seglen > 0) { while (seglen > 0) {
int copy; int copy;
skb = sk->write_queue.prev; skb = sk->write_queue.prev;
if (tp->send_head == NULL || if (!tp->send_head ||
(copy = mss_now - skb->len) <= 0) { (copy = mss_now - skb->len) <= 0) {
new_segment: new_segment:
...@@ -1065,8 +1069,9 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1065,8 +1069,9 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
if (!tcp_memory_free(sk)) if (!tcp_memory_free(sk))
goto wait_for_sndbuf; goto wait_for_sndbuf;
skb = tcp_alloc_pskb(sk, select_size(sk, tp), 0, sk->allocation); skb = tcp_alloc_pskb(sk, select_size(sk, tp),
if (skb == NULL) 0, sk->allocation);
if (!skb)
goto wait_for_memory; goto wait_for_memory;
skb_entail(sk, tp, skb); skb_entail(sk, tp, skb);
...@@ -1090,22 +1095,26 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1090,22 +1095,26 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
struct page *page = TCP_PAGE(sk); struct page *page = TCP_PAGE(sk);
int off = TCP_OFF(sk); int off = TCP_OFF(sk);
if (can_coalesce(skb, i, page, off) && off != PAGE_SIZE) { if (can_coalesce(skb, i, page, off) &&
/* We can extend the last page fragment. */ off != PAGE_SIZE) {
/* We can extend the last page
* fragment. */
merge = 1; merge = 1;
} else if (i == MAX_SKB_FRAGS || } else if (i == MAX_SKB_FRAGS ||
(i == 0 && !(sk->route_caps&NETIF_F_SG))) { (!i &&
!(sk->route_caps & NETIF_F_SG))) {
/* Need to add new fragment and cannot /* Need to add new fragment and cannot
* do this because interface is non-SG, * do this because interface is non-SG,
* or because all the page slots are busy. * or because all the page slots are
*/ * busy. */
tcp_mark_push(tp, skb); tcp_mark_push(tp, skb);
goto new_segment; goto new_segment;
} else if (page) { } else if (page) {
/* If page is cached, align /* If page is cached, align
* offset to L1 cache boundary * offset to L1 cache boundary
*/ */
off = (off+L1_CACHE_BYTES-1)&~(L1_CACHE_BYTES-1); off = (off + L1_CACHE_BYTES - 1) &
~(L1_CACHE_BYTES - 1);
if (off == PAGE_SIZE) { if (off == PAGE_SIZE) {
put_page(page); put_page(page);
TCP_PAGE(sk) = page = NULL; TCP_PAGE(sk) = page = NULL;
...@@ -1114,21 +1123,23 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1114,21 +1123,23 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
if (!page) { if (!page) {
/* Allocate new cache page. */ /* Allocate new cache page. */
if (!(page=tcp_alloc_page(sk))) if (!(page = tcp_alloc_page(sk)))
goto wait_for_memory; goto wait_for_memory;
off = 0; off = 0;
} }
if (copy > PAGE_SIZE-off) if (copy > PAGE_SIZE - off)
copy = PAGE_SIZE-off; copy = PAGE_SIZE - off;
/* Time to copy data. We are close to the end! */ /* Time to copy data. We are close to
err = tcp_copy_to_page(sk, from, skb, page, off, copy); * the end! */
err = tcp_copy_to_page(sk, from, skb, page,
off, copy);
if (err) { if (err) {
/* If this page was new, give it to the /* If this page was new, give it to the
* socket so it does not get leaked. * socket so it does not get leaked.
*/ */
if (TCP_PAGE(sk) == NULL) { if (!TCP_PAGE(sk)) {
TCP_PAGE(sk) = page; TCP_PAGE(sk) = page;
TCP_OFF(sk) = 0; TCP_OFF(sk) = 0;
} }
...@@ -1137,7 +1148,8 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1137,7 +1148,8 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
/* Update the skb. */ /* Update the skb. */
if (merge) { if (merge) {
skb_shinfo(skb)->frags[i-1].size += copy; skb_shinfo(skb)->frags[i - 1].size +=
copy;
} else { } else {
fill_page_desc(skb, i, page, off, copy); fill_page_desc(skb, i, page, off, copy);
if (TCP_PAGE(sk)) { if (TCP_PAGE(sk)) {
...@@ -1148,7 +1160,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1148,7 +1160,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
} }
} }
TCP_OFF(sk) = off+copy; TCP_OFF(sk) = off + copy;
} }
if (!copied) if (!copied)
...@@ -1161,7 +1173,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1161,7 +1173,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
copied += copy; copied += copy;
seglen -= copy; seglen -= copy;
if (skb->len != mss_now || (flags&MSG_OOB)) if (skb->len != mss_now || (flags & MSG_OOB))
continue; continue;
if (forced_push(tp)) { if (forced_push(tp)) {
...@@ -1175,7 +1187,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1175,7 +1187,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
set_bit(SOCK_NOSPACE, &sk->socket->flags); set_bit(SOCK_NOSPACE, &sk->socket->flags);
wait_for_memory: wait_for_memory:
if (copied) if (copied)
tcp_push(sk, tp, flags&~MSG_MORE, mss_now, 1); tcp_push(sk, tp, flags & ~MSG_MORE, mss_now, 1);
if ((err = wait_for_tcp_memory(sk, &timeo)) != 0) if ((err = wait_for_tcp_memory(sk, &timeo)) != 0)
goto do_error; goto do_error;
...@@ -1192,7 +1204,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1192,7 +1204,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
return copied; return copied;
do_fault: do_fault:
if (skb->len == 0) { if (!skb->len) {
if (tp->send_head == skb) if (tp->send_head == skb)
tp->send_head = NULL; tp->send_head = NULL;
__skb_unlink(skb, skb->list); __skb_unlink(skb, skb->list);
...@@ -1214,8 +1226,8 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size) ...@@ -1214,8 +1226,8 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size)
* this, no blocking and very strange errors 8) * this, no blocking and very strange errors 8)
*/ */
static int tcp_recv_urg(struct sock * sk, long timeo, static int tcp_recv_urg(struct sock *sk, long timeo,
struct msghdr *msg, int len, int flags, struct msghdr *msg, int len, int flags,
int *addr_len) int *addr_len)
{ {
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
...@@ -1224,25 +1236,25 @@ static int tcp_recv_urg(struct sock * sk, long timeo, ...@@ -1224,25 +1236,25 @@ static int tcp_recv_urg(struct sock * sk, long timeo,
if (sk->urginline || !tp->urg_data || tp->urg_data == TCP_URG_READ) if (sk->urginline || !tp->urg_data || tp->urg_data == TCP_URG_READ)
return -EINVAL; /* Yes this is right ! */ return -EINVAL; /* Yes this is right ! */
if (sk->state==TCP_CLOSE && !sk->done) if (sk->state == TCP_CLOSE && !sk->done)
return -ENOTCONN; return -ENOTCONN;
if (tp->urg_data & TCP_URG_VALID) { if (tp->urg_data & TCP_URG_VALID) {
int err = 0; int err = 0;
char c = tp->urg_data; char c = tp->urg_data;
if (!(flags & MSG_PEEK)) if (!(flags & MSG_PEEK))
tp->urg_data = TCP_URG_READ; tp->urg_data = TCP_URG_READ;
/* Read urgent data. */ /* Read urgent data. */
msg->msg_flags|=MSG_OOB; msg->msg_flags |= MSG_OOB;
if(len>0) { if (len > 0) {
if (!(flags & MSG_TRUNC)) if (!(flags & MSG_TRUNC))
err = memcpy_toiovec(msg->msg_iov, &c, 1); err = memcpy_toiovec(msg->msg_iov, &c, 1);
len = 1; len = 1;
} else } else
msg->msg_flags|=MSG_TRUNC; msg->msg_flags |= MSG_TRUNC;
return err ? -EFAULT : len; return err ? -EFAULT : len;
} }
...@@ -1265,7 +1277,7 @@ static int tcp_recv_urg(struct sock * sk, long timeo, ...@@ -1265,7 +1277,7 @@ static int tcp_recv_urg(struct sock * sk, long timeo,
* socket locked so that the sk_buff queue operation is ok. * socket locked so that the sk_buff queue operation is ok.
*/ */
static inline void tcp_eat_skb(struct sock *sk, struct sk_buff * skb) static inline void tcp_eat_skb(struct sock *sk, struct sk_buff *skb)
{ {
__skb_unlink(skb, &sk->receive_queue); __skb_unlink(skb, &sk->receive_queue);
__kfree_skb(skb); __kfree_skb(skb);
...@@ -1285,35 +1297,33 @@ static void cleanup_rbuf(struct sock *sk, int copied) ...@@ -1285,35 +1297,33 @@ static void cleanup_rbuf(struct sock *sk, int copied)
#if TCP_DEBUG #if TCP_DEBUG
struct sk_buff *skb = skb_peek(&sk->receive_queue); struct sk_buff *skb = skb_peek(&sk->receive_queue);
BUG_TRAP(skb==NULL || before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq)); BUG_TRAP(!skb || before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq));
#endif #endif
if (tcp_ack_scheduled(tp)) { if (tcp_ack_scheduled(tp)) {
/* Delayed ACKs frequently hit locked sockets during bulk receive. */ /* Delayed ACKs frequently hit locked sockets during bulk
if (tp->ack.blocked * receive. */
if (tp->ack.blocked ||
/* Once-per-two-segments ACK was not sent by tcp_input.c */ /* Once-per-two-segments ACK was not sent by tcp_input.c */
|| tp->rcv_nxt - tp->rcv_wup > tp->ack.rcv_mss tp->rcv_nxt - tp->rcv_wup > tp->ack.rcv_mss ||
/* /*
* If this read emptied read buffer, we send ACK, if * If this read emptied read buffer, we send ACK, if
* connection is not bidirectional, user drained * connection is not bidirectional, user drained
* receive buffer and there was a small segment * receive buffer and there was a small segment
* in queue. * in queue.
*/ */
|| (copied > 0 && (copied > 0 && (tp->ack.pending & TCP_ACK_PUSHED) &&
(tp->ack.pending&TCP_ACK_PUSHED) && !tp->ack.pingpong && !atomic_read(&sk->rmem_alloc)))
!tp->ack.pingpong &&
atomic_read(&sk->rmem_alloc) == 0)) {
time_to_ack = 1; time_to_ack = 1;
}
} }
/* We send an ACK if we can now advertise a non-zero window /* We send an ACK if we can now advertise a non-zero window
* which has been raised "significantly". * which has been raised "significantly".
* *
* Even if window raised up to infinity, do not send window open ACK * Even if window raised up to infinity, do not send window open ACK
* in states, where we will not receive more. It is useless. * in states, where we will not receive more. It is useless.
*/ */
if(copied > 0 && !time_to_ack && !(sk->shutdown&RCV_SHUTDOWN)) { if (copied > 0 && !time_to_ack && !(sk->shutdown & RCV_SHUTDOWN)) {
__u32 rcv_window_now = tcp_receive_window(tp); __u32 rcv_window_now = tcp_receive_window(tp);
/* Optimize, __tcp_select_window() is not cheap. */ /* Optimize, __tcp_select_window() is not cheap. */
...@@ -1325,7 +1335,7 @@ static void cleanup_rbuf(struct sock *sk, int copied) ...@@ -1325,7 +1335,7 @@ static void cleanup_rbuf(struct sock *sk, int copied)
* We can advertise it now, if it is not less than current one. * We can advertise it now, if it is not less than current one.
* "Lots" means "at least twice" here. * "Lots" means "at least twice" here.
*/ */
if(new_window && new_window >= 2*rcv_window_now) if (new_window && new_window >= 2 * rcv_window_now)
time_to_ack = 1; time_to_ack = 1;
} }
} }
...@@ -1366,9 +1376,11 @@ static void tcp_prequeue_process(struct sock *sk) ...@@ -1366,9 +1376,11 @@ static void tcp_prequeue_process(struct sock *sk)
struct sk_buff *skb; struct sk_buff *skb;
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
net_statistics[smp_processor_id()*2+1].TCPPrequeued += skb_queue_len(&tp->ucopy.prequeue); net_statistics[smp_processor_id() * 2 + 1].TCPPrequeued +=
skb_queue_len(&tp->ucopy.prequeue);
/* RX process wants to run with disabled BHs, though it is not necessary */ /* RX process wants to run with disabled BHs, though it is not
* necessary */
local_bh_disable(); local_bh_disable();
while ((skb = __skb_dequeue(&tp->ucopy.prequeue)) != NULL) while ((skb = __skb_dequeue(&tp->ucopy.prequeue)) != NULL)
sk->backlog_rcv(sk, skb); sk->backlog_rcv(sk, skb);
...@@ -1378,8 +1390,7 @@ static void tcp_prequeue_process(struct sock *sk) ...@@ -1378,8 +1390,7 @@ static void tcp_prequeue_process(struct sock *sk)
tp->ucopy.memory = 0; tp->ucopy.memory = 0;
} }
static inline static inline struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
{ {
struct sk_buff *skb; struct sk_buff *skb;
u32 offset; u32 offset;
...@@ -1457,13 +1468,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, ...@@ -1457,13 +1468,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
} }
/* /*
* This routine copies from a sock struct into the user buffer. * This routine copies from a sock struct into the user buffer.
* *
* Technical note: in 2.3 we work on _locked_ socket, so that * Technical note: in 2.3 we work on _locked_ socket, so that
* tricks with *seq access order and skb->users are not required. * tricks with *seq access order and skb->users are not required.
* Probably, code can be easily improved even more. * Probably, code can be easily improved even more.
*/ */
int tcp_recvmsg(struct sock *sk, struct msghdr *msg, int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
int len, int nonblock, int flags, int *addr_len) int len, int nonblock, int flags, int *addr_len)
{ {
...@@ -1500,7 +1511,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1500,7 +1511,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
target = sock_rcvlowat(sk, flags & MSG_WAITALL, len); target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
do { do {
struct sk_buff * skb; struct sk_buff *skb;
u32 offset; u32 offset;
/* Are we at urgent data? Stop if we have read anything. */ /* Are we at urgent data? Stop if we have read anything. */
...@@ -1525,12 +1536,12 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1525,12 +1536,12 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
if (!skb) if (!skb)
break; break;
/* Now that we have two receive queues this /* Now that we have two receive queues this
* shouldn't happen. * shouldn't happen.
*/ */
if (before(*seq, TCP_SKB_CB(skb)->seq)) { if (before(*seq, TCP_SKB_CB(skb)->seq)) {
printk(KERN_INFO "recvmsg bug: copied %X seq %X\n", printk(KERN_INFO "recvmsg bug: copied %X "
*seq, TCP_SKB_CB(skb)->seq); "seq %X\n", *seq, TCP_SKB_CB(skb)->seq);
break; break;
} }
offset = *seq - TCP_SKB_CB(skb)->seq; offset = *seq - TCP_SKB_CB(skb)->seq;
...@@ -1540,13 +1551,13 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1540,13 +1551,13 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
goto found_ok_skb; goto found_ok_skb;
if (skb->h.th->fin) if (skb->h.th->fin)
goto found_fin_ok; goto found_fin_ok;
BUG_TRAP(flags&MSG_PEEK); BUG_TRAP(flags & MSG_PEEK);
skb = skb->next; skb = skb->next;
} while (skb != (struct sk_buff *)&sk->receive_queue); } while (skb != (struct sk_buff *)&sk->receive_queue);
/* Well, if we have backlog, try to process it now yet. */ /* Well, if we have backlog, try to process it now yet. */
if (copied >= target && sk->backlog.tail == NULL) if (copied >= target && !sk->backlog.tail)
break; break;
if (copied) { if (copied) {
...@@ -1589,7 +1600,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1589,7 +1600,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
if (tp->ucopy.task == user_recv) { if (tp->ucopy.task == user_recv) {
/* Install new reader */ /* Install new reader */
if (user_recv == NULL && !(flags&(MSG_TRUNC|MSG_PEEK))) { if (!user_recv && !(flags & (MSG_TRUNC | MSG_PEEK))) {
user_recv = current; user_recv = current;
tp->ucopy.task = user_recv; tp->ucopy.task = user_recv;
tp->ucopy.iov = msg->msg_iov; tp->ucopy.iov = msg->msg_iov;
...@@ -1597,7 +1608,8 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1597,7 +1608,8 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
tp->ucopy.len = len; tp->ucopy.len = len;
BUG_TRAP(tp->copied_seq == tp->rcv_nxt || (flags&(MSG_PEEK|MSG_TRUNC))); BUG_TRAP(tp->copied_seq == tp->rcv_nxt ||
(flags & (MSG_PEEK | MSG_TRUNC)));
/* Ugly... If prequeue is not empty, we have to /* Ugly... If prequeue is not empty, we have to
* process it before releasing socket, otherwise * process it before releasing socket, otherwise
...@@ -1613,7 +1625,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1613,7 +1625,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
* *
* Each queue can be processed only if the next ones * Each queue can be processed only if the next ones
* are empty. At this point we have empty receive_queue. * are empty. At this point we have empty receive_queue.
* But prequeue _can_ be not empty after second iteration, * But prequeue _can_ be not empty after 2nd iteration,
* when we jumped to start of loop because backlog * when we jumped to start of loop because backlog
* processing added something to receive_queue. * processing added something to receive_queue.
* We cannot release_sock(), because backlog contains * We cannot release_sock(), because backlog contains
...@@ -1645,7 +1657,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1645,7 +1657,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
/* __ Restore normal policy in scheduler __ */ /* __ Restore normal policy in scheduler __ */
if ((chunk = len - tp->ucopy.len) != 0) { if ((chunk = len - tp->ucopy.len) != 0) {
net_statistics[smp_processor_id()*2+1].TCPDirectCopyFromBacklog += chunk; net_statistics[smp_processor_id() * 2 + 1].TCPDirectCopyFromBacklog += chunk;
len -= chunk; len -= chunk;
copied += chunk; copied += chunk;
} }
...@@ -1656,7 +1668,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1656,7 +1668,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
tcp_prequeue_process(sk); tcp_prequeue_process(sk);
if ((chunk = len - tp->ucopy.len) != 0) { if ((chunk = len - tp->ucopy.len) != 0) {
net_statistics[smp_processor_id()*2+1].TCPDirectCopyFromPrequeue += chunk; net_statistics[smp_processor_id() * 2 + 1].TCPDirectCopyFromPrequeue += chunk;
len -= chunk; len -= chunk;
copied += chunk; copied += chunk;
} }
...@@ -1687,8 +1699,9 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1687,8 +1699,9 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
} }
} }
if (!(flags&MSG_TRUNC)) { if (!(flags & MSG_TRUNC)) {
err = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, used); err = skb_copy_datagram_iovec(skb, offset,
msg->msg_iov, used);
if (err) { if (err) {
/* Exception. Bailout! */ /* Exception. Bailout! */
if (!copied) if (!copied)
...@@ -1702,7 +1715,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1702,7 +1715,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
len -= used; len -= used;
skip_copy: skip_copy:
if (tp->urg_data && after(tp->copied_seq,tp->urg_seq)) { if (tp->urg_data && after(tp->copied_seq, tp->urg_seq)) {
tp->urg_data = 0; tp->urg_data = 0;
tcp_fast_path_check(sk, tp); tcp_fast_path_check(sk, tp);
} }
...@@ -1732,7 +1745,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, ...@@ -1732,7 +1745,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg,
tcp_prequeue_process(sk); tcp_prequeue_process(sk);
if (copied > 0 && (chunk = len - tp->ucopy.len) != 0) { if (copied > 0 && (chunk = len - tp->ucopy.len) != 0) {
net_statistics[smp_processor_id()*2+1].TCPDirectCopyFromPrequeue += chunk; net_statistics[smp_processor_id() * 2 + 1].TCPDirectCopyFromPrequeue += chunk;
len -= chunk; len -= chunk;
copied += chunk; copied += chunk;
} }
...@@ -1788,12 +1801,12 @@ static unsigned char new_state[16] = { ...@@ -1788,12 +1801,12 @@ static unsigned char new_state[16] = {
static int tcp_close_state(struct sock *sk) static int tcp_close_state(struct sock *sk)
{ {
int next = (int) new_state[sk->state]; int next = (int)new_state[sk->state];
int ns = (next & TCP_STATE_MASK); int ns = next & TCP_STATE_MASK;
tcp_set_state(sk, ns); tcp_set_state(sk, ns);
return (next & TCP_ACTION_FIN); return next & TCP_ACTION_FIN;
} }
/* /*
...@@ -1812,7 +1825,8 @@ void tcp_shutdown(struct sock *sk, int how) ...@@ -1812,7 +1825,8 @@ void tcp_shutdown(struct sock *sk, int how)
/* If we've already sent a FIN, or it's a closed state, skip this. */ /* If we've already sent a FIN, or it's a closed state, skip this. */
if ((1 << sk->state) & if ((1 << sk->state) &
(TCPF_ESTABLISHED|TCPF_SYN_SENT|TCPF_SYN_RECV|TCPF_CLOSE_WAIT)) { (TCPF_ESTABLISHED | TCPF_SYN_SENT |
TCPF_SYN_RECV | TCPF_CLOSE_WAIT)) {
/* Clear out any half completed packets. FIN if needed. */ /* Clear out any half completed packets. FIN if needed. */
if (tcp_close_state(sk)) if (tcp_close_state(sk))
tcp_send_fin(sk); tcp_send_fin(sk);
...@@ -1824,9 +1838,10 @@ void tcp_shutdown(struct sock *sk, int how) ...@@ -1824,9 +1838,10 @@ void tcp_shutdown(struct sock *sk, int how)
* Return 1 if we still have things to send in our buffers. * Return 1 if we still have things to send in our buffers.
*/ */
static inline int closing(struct sock * sk) static inline int closing(struct sock *sk)
{ {
return ((1 << sk->state) & (TCPF_FIN_WAIT1|TCPF_CLOSING|TCPF_LAST_ACK)); return (1 << sk->state) &
(TCPF_FIN_WAIT1 | TCPF_CLOSING | TCPF_LAST_ACK);
} }
static __inline__ void tcp_kill_sk_queues(struct sock *sk) static __inline__ void tcp_kill_sk_queues(struct sock *sk)
...@@ -1843,8 +1858,8 @@ static __inline__ void tcp_kill_sk_queues(struct sock *sk) ...@@ -1843,8 +1858,8 @@ static __inline__ void tcp_kill_sk_queues(struct sock *sk)
/* Account for returned memory. */ /* Account for returned memory. */
tcp_mem_reclaim(sk); tcp_mem_reclaim(sk);
BUG_TRAP(sk->wmem_queued == 0); BUG_TRAP(!sk->wmem_queued);
BUG_TRAP(sk->forward_alloc == 0); BUG_TRAP(!sk->forward_alloc);
/* It is _impossible_ for the backlog to contain anything /* It is _impossible_ for the backlog to contain anything
* when we get here. All user references to this socket * when we get here. All user references to this socket
...@@ -1860,11 +1875,11 @@ static __inline__ void tcp_kill_sk_queues(struct sock *sk) ...@@ -1860,11 +1875,11 @@ static __inline__ void tcp_kill_sk_queues(struct sock *sk)
*/ */
void tcp_destroy_sock(struct sock *sk) void tcp_destroy_sock(struct sock *sk)
{ {
BUG_TRAP(sk->state==TCP_CLOSE); BUG_TRAP(sk->state == TCP_CLOSE);
BUG_TRAP(sk->dead); BUG_TRAP(sk->dead);
/* It cannot be in hash table! */ /* It cannot be in hash table! */
BUG_TRAP(sk->pprev==NULL); BUG_TRAP(!sk->pprev);
/* If it has not 0 inet_sk(sk)->num, it must be bound */ /* If it has not 0 inet_sk(sk)->num, it must be bound */
BUG_TRAP(!inet_sk(sk)->num || sk->prev); BUG_TRAP(!inet_sk(sk)->num || sk->prev);
...@@ -1883,7 +1898,8 @@ void tcp_destroy_sock(struct sock *sk) ...@@ -1883,7 +1898,8 @@ void tcp_destroy_sock(struct sock *sk)
#ifdef INET_REFCNT_DEBUG #ifdef INET_REFCNT_DEBUG
if (atomic_read(&sk->refcnt) != 1) { if (atomic_read(&sk->refcnt) != 1) {
printk(KERN_DEBUG "Destruction TCP %p delayed, c=%d\n", sk, atomic_read(&sk->refcnt)); printk(KERN_DEBUG "Destruction TCP %p delayed, c=%d\n",
sk, atomic_read(&sk->refcnt));
} }
#endif #endif
...@@ -1899,7 +1915,7 @@ void tcp_close(struct sock *sk, long timeout) ...@@ -1899,7 +1915,7 @@ void tcp_close(struct sock *sk, long timeout)
lock_sock(sk); lock_sock(sk);
sk->shutdown = SHUTDOWN_MASK; sk->shutdown = SHUTDOWN_MASK;
if(sk->state == TCP_LISTEN) { if (sk->state == TCP_LISTEN) {
tcp_set_state(sk, TCP_CLOSE); tcp_set_state(sk, TCP_CLOSE);
/* Special case. */ /* Special case. */
...@@ -1912,8 +1928,9 @@ void tcp_close(struct sock *sk, long timeout) ...@@ -1912,8 +1928,9 @@ void tcp_close(struct sock *sk, long timeout)
* descriptor close, not protocol-sourced closes, because the * descriptor close, not protocol-sourced closes, because the
* reader process may not have drained the data yet! * reader process may not have drained the data yet!
*/ */
while((skb=__skb_dequeue(&sk->receive_queue))!=NULL) { while ((skb = __skb_dequeue(&sk->receive_queue)) != NULL) {
u32 len = TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq - skb->h.th->fin; u32 len = TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq -
skb->h.th->fin;
data_was_unread += len; data_was_unread += len;
__kfree_skb(skb); __kfree_skb(skb);
} }
...@@ -1929,12 +1946,12 @@ void tcp_close(struct sock *sk, long timeout) ...@@ -1929,12 +1946,12 @@ void tcp_close(struct sock *sk, long timeout)
* the FTP client, wheee... Note: timeout is always zero * the FTP client, wheee... Note: timeout is always zero
* in such a case. * in such a case.
*/ */
if(data_was_unread != 0) { if (data_was_unread) {
/* Unread data was tossed, zap the connection. */ /* Unread data was tossed, zap the connection. */
NET_INC_STATS_USER(TCPAbortOnClose); NET_INC_STATS_USER(TCPAbortOnClose);
tcp_set_state(sk, TCP_CLOSE); tcp_set_state(sk, TCP_CLOSE);
tcp_send_active_reset(sk, GFP_KERNEL); tcp_send_active_reset(sk, GFP_KERNEL);
} else if (sk->linger && sk->lingertime==0) { } else if (sk->linger && !sk->lingertime) {
/* Check zero linger _after_ checking for unread data. */ /* Check zero linger _after_ checking for unread data. */
sk->prot->disconnect(sk, 0); sk->prot->disconnect(sk, 0);
NET_INC_STATS_USER(TCPAbortOnData); NET_INC_STATS_USER(TCPAbortOnData);
...@@ -1996,7 +2013,7 @@ void tcp_close(struct sock *sk, long timeout) ...@@ -1996,7 +2013,7 @@ void tcp_close(struct sock *sk, long timeout)
*/ */
local_bh_disable(); local_bh_disable();
bh_lock_sock(sk); bh_lock_sock(sk);
BUG_TRAP(sk->lock.users==0); BUG_TRAP(!sk->lock.users);
sock_hold(sk); sock_hold(sk);
sock_orphan(sk); sock_orphan(sk);
...@@ -2039,7 +2056,8 @@ void tcp_close(struct sock *sk, long timeout) ...@@ -2039,7 +2056,8 @@ void tcp_close(struct sock *sk, long timeout)
(sk->wmem_queued > SOCK_MIN_SNDBUF && (sk->wmem_queued > SOCK_MIN_SNDBUF &&
atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])) { atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])) {
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_INFO "TCP: too many of orphaned sockets\n"); printk(KERN_INFO "TCP: too many of orphaned "
"sockets\n");
tcp_set_state(sk, TCP_CLOSE); tcp_set_state(sk, TCP_CLOSE);
tcp_send_active_reset(sk, GFP_ATOMIC); tcp_send_active_reset(sk, GFP_ATOMIC);
NET_INC_STATS_BH(TCPAbortOnMemory); NET_INC_STATS_BH(TCPAbortOnMemory);
...@@ -2061,9 +2079,9 @@ void tcp_close(struct sock *sk, long timeout) ...@@ -2061,9 +2079,9 @@ void tcp_close(struct sock *sk, long timeout)
extern __inline__ int tcp_need_reset(int state) extern __inline__ int tcp_need_reset(int state)
{ {
return ((1 << state) & return (1 << state) &
(TCPF_ESTABLISHED|TCPF_CLOSE_WAIT|TCPF_FIN_WAIT1| (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT | TCPF_FIN_WAIT1 |
TCPF_FIN_WAIT2|TCPF_SYN_RECV)); TCPF_FIN_WAIT2 | TCPF_SYN_RECV);
} }
int tcp_disconnect(struct sock *sk, int flags) int tcp_disconnect(struct sock *sk, int flags)
...@@ -2082,7 +2100,7 @@ int tcp_disconnect(struct sock *sk, int flags) ...@@ -2082,7 +2100,7 @@ int tcp_disconnect(struct sock *sk, int flags)
tcp_listen_stop(sk); tcp_listen_stop(sk);
} else if (tcp_need_reset(old_state) || } else if (tcp_need_reset(old_state) ||
(tp->snd_nxt != tp->write_seq && (tp->snd_nxt != tp->write_seq &&
(1<<old_state)&(TCPF_CLOSING|TCPF_LAST_ACK))) { (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK))) {
/* The last check adjusts for discrepance of Linux wrt. RFC /* The last check adjusts for discrepance of Linux wrt. RFC
* states * states
*/ */
...@@ -2093,12 +2111,12 @@ int tcp_disconnect(struct sock *sk, int flags) ...@@ -2093,12 +2111,12 @@ int tcp_disconnect(struct sock *sk, int flags)
tcp_clear_xmit_timers(sk); tcp_clear_xmit_timers(sk);
__skb_queue_purge(&sk->receive_queue); __skb_queue_purge(&sk->receive_queue);
tcp_writequeue_purge(sk); tcp_writequeue_purge(sk);
__skb_queue_purge(&tp->out_of_order_queue); __skb_queue_purge(&tp->out_of_order_queue);
inet->dport = 0; inet->dport = 0;
if (!(sk->userlocks&SOCK_BINDADDR_LOCK)) { if (!(sk->userlocks & SOCK_BINDADDR_LOCK)) {
inet->rcv_saddr = inet->saddr = 0; inet->rcv_saddr = inet->saddr = 0;
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
if (sk->family == PF_INET6) { if (sk->family == PF_INET6) {
...@@ -2113,7 +2131,7 @@ int tcp_disconnect(struct sock *sk, int flags) ...@@ -2113,7 +2131,7 @@ int tcp_disconnect(struct sock *sk, int flags)
sk->shutdown = 0; sk->shutdown = 0;
sk->done = 0; sk->done = 0;
tp->srtt = 0; tp->srtt = 0;
if ((tp->write_seq += tp->max_window+2) == 0) if ((tp->write_seq += tp->max_window + 2) == 0)
tp->write_seq = 1; tp->write_seq = 1;
tp->backoff = 0; tp->backoff = 0;
tp->snd_cwnd = 2; tp->snd_cwnd = 2;
...@@ -2139,7 +2157,7 @@ int tcp_disconnect(struct sock *sk, int flags) ...@@ -2139,7 +2157,7 @@ int tcp_disconnect(struct sock *sk, int flags)
* Wait for an incoming connection, avoid race * Wait for an incoming connection, avoid race
* conditions. This must be called with the socket locked. * conditions. This must be called with the socket locked.
*/ */
static int wait_for_connect(struct sock * sk, long timeo) static int wait_for_connect(struct sock *sk, long timeo)
{ {
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
...@@ -2163,7 +2181,7 @@ static int wait_for_connect(struct sock * sk, long timeo) ...@@ -2163,7 +2181,7 @@ static int wait_for_connect(struct sock * sk, long timeo)
for (;;) { for (;;) {
current->state = TASK_INTERRUPTIBLE; current->state = TASK_INTERRUPTIBLE;
release_sock(sk); release_sock(sk);
if (tp->accept_queue == NULL) if (!tp->accept_queue)
timeo = schedule_timeout(timeo); timeo = schedule_timeout(timeo);
lock_sock(sk); lock_sock(sk);
err = 0; err = 0;
...@@ -2195,7 +2213,7 @@ struct sock *tcp_accept(struct sock *sk, int flags, int *err) ...@@ -2195,7 +2213,7 @@ struct sock *tcp_accept(struct sock *sk, int flags, int *err)
struct sock *newsk; struct sock *newsk;
int error; int error;
lock_sock(sk); lock_sock(sk);
/* We need to make sure that this socket is listening, /* We need to make sure that this socket is listening,
* and that it has something pending. * and that it has something pending.
...@@ -2231,15 +2249,14 @@ struct sock *tcp_accept(struct sock *sk, int flags, int *err) ...@@ -2231,15 +2249,14 @@ struct sock *tcp_accept(struct sock *sk, int flags, int *err)
out: out:
release_sock(sk); release_sock(sk);
*err = error; *err = error;
return NULL; return NULL;
} }
/* /*
* Socket option code for TCP. * Socket option code for TCP.
*/ */
int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
int optlen) int optlen)
{ {
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
...@@ -2247,10 +2264,10 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2247,10 +2264,10 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
int err = 0; int err = 0;
if (level != SOL_TCP) if (level != SOL_TCP)
return tp->af_specific->setsockopt(sk, level, optname, return tp->af_specific->setsockopt(sk, level, optname,
optval, optlen); optval, optlen);
if(optlen<sizeof(int)) if (optlen < sizeof(int))
return -EINVAL; return -EINVAL;
if (get_user(val, (int *)optval)) if (get_user(val, (int *)optval))
...@@ -2258,13 +2275,12 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2258,13 +2275,12 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
lock_sock(sk); lock_sock(sk);
switch(optname) { switch (optname) {
case TCP_MAXSEG: case TCP_MAXSEG:
/* values greater than interface MTU won't take effect. however at /* Values greater than interface MTU won't take effect. However
* the point when this call is done we typically don't yet know * at the point when this call is done we typically don't yet
* which interface is going to be used * know which interface is going to be used */
*/ if (val < 8 || val > MAX_TCP_WINDOW) {
if(val < 8 || val > MAX_TCP_WINDOW) {
err = -EINVAL; err = -EINVAL;
break; break;
} }
...@@ -2279,7 +2295,7 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2279,7 +2295,7 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
err = -EINVAL; err = -EINVAL;
break; break;
} }
tp->nonagle = (val == 0) ? 0 : 1; tp->nonagle = !val ? 0 : 1;
if (val) if (val)
tcp_push_pending_frames(sk, tp); tcp_push_pending_frames(sk, tp);
break; break;
...@@ -2308,13 +2324,14 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2308,13 +2324,14 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
tcp_push_pending_frames(sk, tp); tcp_push_pending_frames(sk, tp);
} }
break; break;
case TCP_KEEPIDLE: case TCP_KEEPIDLE:
if (val < 1 || val > MAX_TCP_KEEPIDLE) if (val < 1 || val > MAX_TCP_KEEPIDLE)
err = -EINVAL; err = -EINVAL;
else { else {
tp->keepalive_time = val * HZ; tp->keepalive_time = val * HZ;
if (sk->keepopen && !((1<<sk->state)&(TCPF_CLOSE|TCPF_LISTEN))) { if (sk->keepopen &&
!((1 << sk->state) & (TCPF_CLOSE | TCPF_LISTEN))) {
__u32 elapsed = tcp_time_stamp - tp->rcv_tstamp; __u32 elapsed = tcp_time_stamp - tp->rcv_tstamp;
if (tp->keepalive_time > elapsed) if (tp->keepalive_time > elapsed)
elapsed = tp->keepalive_time - elapsed; elapsed = tp->keepalive_time - elapsed;
...@@ -2346,33 +2363,35 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2346,33 +2363,35 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
case TCP_LINGER2: case TCP_LINGER2:
if (val < 0) if (val < 0)
tp->linger2 = -1; tp->linger2 = -1;
else if (val > sysctl_tcp_fin_timeout/HZ) else if (val > sysctl_tcp_fin_timeout / HZ)
tp->linger2 = 0; tp->linger2 = 0;
else else
tp->linger2 = val*HZ; tp->linger2 = val * HZ;
break; break;
case TCP_DEFER_ACCEPT: case TCP_DEFER_ACCEPT:
tp->defer_accept = 0; tp->defer_accept = 0;
if (val > 0) { if (val > 0) {
/* Translate value in seconds to number of retransmits */ /* Translate value in seconds to number of
while (tp->defer_accept < 32 && val > ((TCP_TIMEOUT_INIT/HZ)<<tp->defer_accept)) * retransmits */
while (tp->defer_accept < 32 &&
val > ((TCP_TIMEOUT_INIT / HZ) <<
tp->defer_accept))
tp->defer_accept++; tp->defer_accept++;
tp->defer_accept++; tp->defer_accept++;
} }
break; break;
case TCP_WINDOW_CLAMP: case TCP_WINDOW_CLAMP:
if (val==0) { if (!val) {
if (sk->state != TCP_CLOSE) { if (sk->state != TCP_CLOSE) {
err = -EINVAL; err = -EINVAL;
break; break;
} }
tp->window_clamp = 0; tp->window_clamp = 0;
} else { } else
tp->window_clamp = val<SOCK_MIN_RCVBUF/2 ? tp->window_clamp = val < SOCK_MIN_RCVBUF / 2 ?
SOCK_MIN_RCVBUF/2 : val; SOCK_MIN_RCVBUF / 2 : val;
}
break; break;
case TCP_QUICKACK: case TCP_QUICKACK:
...@@ -2380,7 +2399,8 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2380,7 +2399,8 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char *optval,
tp->ack.pingpong = 1; tp->ack.pingpong = 1;
} else { } else {
tp->ack.pingpong = 0; tp->ack.pingpong = 0;
if ((1<<sk->state)&(TCPF_ESTABLISHED|TCPF_CLOSE_WAIT) && if ((1 << sk->state) &
(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT) &&
tcp_ack_scheduled(tp)) { tcp_ack_scheduled(tp)) {
tp->ack.pending |= TCP_ACK_PUSHED; tp->ack.pending |= TCP_ACK_PUSHED;
cleanup_rbuf(sk, 1); cleanup_rbuf(sk, 1);
...@@ -2404,22 +2424,22 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2404,22 +2424,22 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval,
struct tcp_opt *tp = tcp_sk(sk); struct tcp_opt *tp = tcp_sk(sk);
int val, len; int val, len;
if(level != SOL_TCP) if (level != SOL_TCP)
return tp->af_specific->getsockopt(sk, level, optname, return tp->af_specific->getsockopt(sk, level, optname,
optval, optlen); optval, optlen);
if(get_user(len,optlen)) if (get_user(len, optlen))
return -EFAULT; return -EFAULT;
len = min_t(unsigned int, len, sizeof(int)); len = min_t(unsigned int, len, sizeof(int));
if(len < 0) if (len < 0)
return -EINVAL; return -EINVAL;
switch(optname) { switch (optname) {
case TCP_MAXSEG: case TCP_MAXSEG:
val = tp->mss_cache; val = tp->mss_cache;
if (val == 0 && ((1<<sk->state)&(TCPF_CLOSE|TCPF_LISTEN))) if (!val && ((1 << sk->state) & (TCPF_CLOSE | TCPF_LISTEN)))
val = tp->user_mss; val = tp->user_mss;
break; break;
case TCP_NODELAY: case TCP_NODELAY:
...@@ -2429,10 +2449,10 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2429,10 +2449,10 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval,
val = (tp->nonagle == 2); val = (tp->nonagle == 2);
break; break;
case TCP_KEEPIDLE: case TCP_KEEPIDLE:
val = (tp->keepalive_time ? : sysctl_tcp_keepalive_time)/HZ; val = (tp->keepalive_time ? : sysctl_tcp_keepalive_time) / HZ;
break; break;
case TCP_KEEPINTVL: case TCP_KEEPINTVL:
val = (tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl)/HZ; val = (tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl) / HZ;
break; break;
case TCP_KEEPCNT: case TCP_KEEPCNT:
val = tp->keepalive_probes ? : sysctl_tcp_keepalive_probes; val = tp->keepalive_probes ? : sysctl_tcp_keepalive_probes;
...@@ -2443,20 +2463,20 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2443,20 +2463,20 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval,
case TCP_LINGER2: case TCP_LINGER2:
val = tp->linger2; val = tp->linger2;
if (val >= 0) if (val >= 0)
val = (val ? : sysctl_tcp_fin_timeout)/HZ; val = (val ? : sysctl_tcp_fin_timeout) / HZ;
break; break;
case TCP_DEFER_ACCEPT: case TCP_DEFER_ACCEPT:
val = tp->defer_accept == 0 ? 0 : ((TCP_TIMEOUT_INIT/HZ)<<(tp->defer_accept-1)); val = !tp->defer_accept ? 0 : ((TCP_TIMEOUT_INIT / HZ) <<
(tp->defer_accept - 1));
break; break;
case TCP_WINDOW_CLAMP: case TCP_WINDOW_CLAMP:
val = tp->window_clamp; val = tp->window_clamp;
break; break;
case TCP_INFO: case TCP_INFO: {
{
struct tcp_info info; struct tcp_info info;
u32 now = tcp_time_stamp; u32 now = tcp_time_stamp;
if(get_user(len,optlen)) if (get_user(len, optlen))
return -EFAULT; return -EFAULT;
info.tcpi_state = sk->state; info.tcpi_state = sk->state;
info.tcpi_ca_state = tp->ca_state; info.tcpi_ca_state = tp->ca_state;
...@@ -2476,11 +2496,11 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2476,11 +2496,11 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval,
info.tcpi_snd_wscale = 0; info.tcpi_snd_wscale = 0;
info.tcpi_rcv_wscale = 0; info.tcpi_rcv_wscale = 0;
} }
if (tp->ecn_flags&TCP_ECN_OK) if (tp->ecn_flags & TCP_ECN_OK)
info.tcpi_options |= TCPI_OPT_ECN; info.tcpi_options |= TCPI_OPT_ECN;
info.tcpi_rto = (1000000*tp->rto)/HZ; info.tcpi_rto = (1000000 * tp->rto) / HZ;
info.tcpi_ato = (1000000*tp->ack.ato)/HZ; info.tcpi_ato = (1000000 * tp->ack.ato) / HZ;
info.tcpi_snd_mss = tp->mss_cache; info.tcpi_snd_mss = tp->mss_cache;
info.tcpi_rcv_mss = tp->ack.rcv_mss; info.tcpi_rcv_mss = tp->ack.rcv_mss;
...@@ -2490,24 +2510,25 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2490,24 +2510,25 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval,
info.tcpi_retrans = tp->retrans_out; info.tcpi_retrans = tp->retrans_out;
info.tcpi_fackets = tp->fackets_out; info.tcpi_fackets = tp->fackets_out;
info.tcpi_last_data_sent = ((now - tp->lsndtime)*1000)/HZ; info.tcpi_last_data_sent = ((now - tp->lsndtime) * 1000) / HZ;
info.tcpi_last_ack_sent = 0; info.tcpi_last_ack_sent = 0;
info.tcpi_last_data_recv = ((now - tp->ack.lrcvtime)*1000)/HZ; info.tcpi_last_data_recv = ((now -
info.tcpi_last_ack_recv = ((now - tp->rcv_tstamp)*1000)/HZ; tp->ack.lrcvtime) * 1000) / HZ;
info.tcpi_last_ack_recv = ((now - tp->rcv_tstamp) * 1000) / HZ;
info.tcpi_pmtu = tp->pmtu_cookie; info.tcpi_pmtu = tp->pmtu_cookie;
info.tcpi_rcv_ssthresh = tp->rcv_ssthresh; info.tcpi_rcv_ssthresh = tp->rcv_ssthresh;
info.tcpi_rtt = ((1000000*tp->srtt)/HZ)>>3; info.tcpi_rtt = ((1000000 * tp->srtt) / HZ) >> 3;
info.tcpi_rttvar = ((1000000*tp->mdev)/HZ)>>2; info.tcpi_rttvar = ((1000000 * tp->mdev) / HZ) >> 2;
info.tcpi_snd_ssthresh = tp->snd_ssthresh; info.tcpi_snd_ssthresh = tp->snd_ssthresh;
info.tcpi_snd_cwnd = tp->snd_cwnd; info.tcpi_snd_cwnd = tp->snd_cwnd;
info.tcpi_advmss = tp->advmss; info.tcpi_advmss = tp->advmss;
info.tcpi_reordering = tp->reordering; info.tcpi_reordering = tp->reordering;
len = min_t(unsigned int, len, sizeof(info)); len = min_t(unsigned int, len, sizeof(info));
if(put_user(len, optlen)) if (put_user(len, optlen))
return -EFAULT; return -EFAULT;
if(copy_to_user(optval, &info,len)) if (copy_to_user(optval, &info, len))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -2518,11 +2539,11 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval, ...@@ -2518,11 +2539,11 @@ int tcp_getsockopt(struct sock *sk, int level, int optname, char *optval,
return -ENOPROTOOPT; return -ENOPROTOOPT;
}; };
if(put_user(len, optlen)) if (put_user(len, optlen))
return -EFAULT; return -EFAULT;
if(copy_to_user(optval, &val,len)) if (copy_to_user(optval, &val, len))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -2535,7 +2556,7 @@ void __init tcp_init(void) ...@@ -2535,7 +2556,7 @@ void __init tcp_init(void)
unsigned long goal; unsigned long goal;
int order, i; int order, i;
if(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)) if (sizeof(struct tcp_skb_cb) > sizeof(skb->cb))
__skb_cb_too_small_for_tcp(sizeof(struct tcp_skb_cb), __skb_cb_too_small_for_tcp(sizeof(struct tcp_skb_cb),
sizeof(skb->cb)); sizeof(skb->cb));
...@@ -2543,21 +2564,21 @@ void __init tcp_init(void) ...@@ -2543,21 +2564,21 @@ void __init tcp_init(void)
sizeof(struct open_request), sizeof(struct open_request),
0, SLAB_HWCACHE_ALIGN, 0, SLAB_HWCACHE_ALIGN,
NULL, NULL); NULL, NULL);
if(!tcp_openreq_cachep) if (!tcp_openreq_cachep)
panic("tcp_init: Cannot alloc open_request cache."); panic("tcp_init: Cannot alloc open_request cache.");
tcp_bucket_cachep = kmem_cache_create("tcp_bind_bucket", tcp_bucket_cachep = kmem_cache_create("tcp_bind_bucket",
sizeof(struct tcp_bind_bucket), sizeof(struct tcp_bind_bucket),
0, SLAB_HWCACHE_ALIGN, 0, SLAB_HWCACHE_ALIGN,
NULL, NULL); NULL, NULL);
if(!tcp_bucket_cachep) if (!tcp_bucket_cachep)
panic("tcp_init: Cannot alloc tcp_bind_bucket cache."); panic("tcp_init: Cannot alloc tcp_bind_bucket cache.");
tcp_timewait_cachep = kmem_cache_create("tcp_tw_bucket", tcp_timewait_cachep = kmem_cache_create("tcp_tw_bucket",
sizeof(struct tcp_tw_bucket), sizeof(struct tcp_tw_bucket),
0, SLAB_HWCACHE_ALIGN, 0, SLAB_HWCACHE_ALIGN,
NULL, NULL); NULL, NULL);
if(!tcp_timewait_cachep) if (!tcp_timewait_cachep)
panic("tcp_init: Cannot alloc tcp_tw_bucket cache."); panic("tcp_init: Cannot alloc tcp_tw_bucket cache.");
/* Size and allocate the main established and bind bucket /* Size and allocate the main established and bind bucket
...@@ -2570,21 +2591,21 @@ void __init tcp_init(void) ...@@ -2570,21 +2591,21 @@ void __init tcp_init(void)
else else
goal = num_physpages >> (23 - PAGE_SHIFT); goal = num_physpages >> (23 - PAGE_SHIFT);
for(order = 0; (1UL << order) < goal; order++) for (order = 0; (1UL << order) < goal; order++)
; ;
do { do {
tcp_ehash_size = (1UL << order) * PAGE_SIZE / tcp_ehash_size = (1UL << order) * PAGE_SIZE /
sizeof(struct tcp_ehash_bucket); sizeof(struct tcp_ehash_bucket);
tcp_ehash_size >>= 1; tcp_ehash_size >>= 1;
while (tcp_ehash_size & (tcp_ehash_size-1)) while (tcp_ehash_size & (tcp_ehash_size - 1))
tcp_ehash_size--; tcp_ehash_size--;
tcp_ehash = (struct tcp_ehash_bucket *) tcp_ehash = (struct tcp_ehash_bucket *)
__get_free_pages(GFP_ATOMIC, order); __get_free_pages(GFP_ATOMIC, order);
} while (tcp_ehash == NULL && --order > 0); } while (!tcp_ehash && --order > 0);
if (!tcp_ehash) if (!tcp_ehash)
panic("Failed to allocate TCP established hash table\n"); panic("Failed to allocate TCP established hash table\n");
for (i = 0; i < (tcp_ehash_size<<1); i++) { for (i = 0; i < (tcp_ehash_size << 1); i++) {
tcp_ehash[i].lock = RW_LOCK_UNLOCKED; tcp_ehash[i].lock = RW_LOCK_UNLOCKED;
tcp_ehash[i].chain = NULL; tcp_ehash[i].chain = NULL;
} }
...@@ -2596,7 +2617,7 @@ void __init tcp_init(void) ...@@ -2596,7 +2617,7 @@ void __init tcp_init(void)
continue; continue;
tcp_bhash = (struct tcp_bind_hashbucket *) tcp_bhash = (struct tcp_bind_hashbucket *)
__get_free_pages(GFP_ATOMIC, order); __get_free_pages(GFP_ATOMIC, order);
} while (tcp_bhash == NULL && --order >= 0); } while (!tcp_bhash && --order >= 0);
if (!tcp_bhash) if (!tcp_bhash)
panic("Failed to allocate TCP bind hash table\n"); panic("Failed to allocate TCP bind hash table\n");
...@@ -2612,33 +2633,34 @@ void __init tcp_init(void) ...@@ -2612,33 +2633,34 @@ void __init tcp_init(void)
sysctl_local_port_range[0] = 32768; sysctl_local_port_range[0] = 32768;
sysctl_local_port_range[1] = 61000; sysctl_local_port_range[1] = 61000;
sysctl_tcp_max_tw_buckets = 180000; sysctl_tcp_max_tw_buckets = 180000;
sysctl_tcp_max_orphans = 4096<<(order-4); sysctl_tcp_max_orphans = 4096 << (order - 4);
sysctl_max_syn_backlog = 1024; sysctl_max_syn_backlog = 1024;
} else if (order < 3) { } else if (order < 3) {
sysctl_local_port_range[0] = 1024*(3-order); sysctl_local_port_range[0] = 1024 * (3 - order);
sysctl_tcp_max_tw_buckets >>= (3-order); sysctl_tcp_max_tw_buckets >>= (3 - order);
sysctl_tcp_max_orphans >>= (3-order); sysctl_tcp_max_orphans >>= (3 - order);
sysctl_max_syn_backlog = 128; sysctl_max_syn_backlog = 128;
} }
tcp_port_rover = sysctl_local_port_range[0] - 1; tcp_port_rover = sysctl_local_port_range[0] - 1;
sysctl_tcp_mem[0] = 768<<order; sysctl_tcp_mem[0] = 768 << order;
sysctl_tcp_mem[1] = 1024<<order; sysctl_tcp_mem[1] = 1024 << order;
sysctl_tcp_mem[2] = 1536<<order; sysctl_tcp_mem[2] = 1536 << order;
if (sysctl_tcp_mem[2] - sysctl_tcp_mem[1] > 512) if (sysctl_tcp_mem[2] - sysctl_tcp_mem[1] > 512)
sysctl_tcp_mem[1] = sysctl_tcp_mem[2] - 512; sysctl_tcp_mem[1] = sysctl_tcp_mem[2] - 512;
if (sysctl_tcp_mem[1] - sysctl_tcp_mem[0] > 512) if (sysctl_tcp_mem[1] - sysctl_tcp_mem[0] > 512)
sysctl_tcp_mem[0] = sysctl_tcp_mem[1] - 512; sysctl_tcp_mem[0] = sysctl_tcp_mem[1] - 512;
if (order < 3) { if (order < 3) {
sysctl_tcp_wmem[2] = 64*1024; sysctl_tcp_wmem[2] = 64 * 1024;
sysctl_tcp_rmem[0] = PAGE_SIZE; sysctl_tcp_rmem[0] = PAGE_SIZE;
sysctl_tcp_rmem[1] = 43689; sysctl_tcp_rmem[1] = 43689;
sysctl_tcp_rmem[2] = 2*43689; sysctl_tcp_rmem[2] = 2 * 43689;
} }
printk(KERN_INFO "TCP: Hash tables configured (established %d bind %d)\n", printk(KERN_INFO "TCP: Hash tables configured "
tcp_ehash_size<<1, tcp_bhash_size); "(established %d bind %d)\n",
tcp_ehash_size << 1, tcp_bhash_size);
tcpdiag_init(); tcpdiag_init();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment